]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.39.1-201106132135.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.39.1-201106132135.patch
CommitLineData
19ace194
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-06-13 17:19:07.000000000 -0400
201@@ -409,7 +409,7 @@ SYSCALL_DEFINE2(osf_getdomainname, char
202 return -EFAULT;
203
204 len = namelen;
205- if (namelen > 32)
206+ if (len > 32)
207 len = 32;
208
209 down_read(&uts_sem);
210@@ -594,7 +594,7 @@ SYSCALL_DEFINE3(osf_sysinfo, int, comman
211 down_read(&uts_sem);
212 res = sysinfo_table[offset];
213 len = strlen(res)+1;
214- if (len > count)
215+ if ((unsigned long)len > (unsigned long)count)
216 len = count;
217 if (copy_to_user(buf, res, len))
218 err = -EFAULT;
219@@ -649,7 +649,7 @@ SYSCALL_DEFINE5(osf_getsysinfo, unsigned
220 return 1;
221
222 case GSI_GET_HWRPB:
223- if (nbytes < sizeof(*hwrpb))
224+ if (nbytes > sizeof(*hwrpb))
225 return -EINVAL;
226 if (copy_to_user(buffer, hwrpb, nbytes) != 0)
227 return -EFAULT;
228@@ -1008,6 +1008,7 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, i
229 {
230 struct rusage r;
231 long ret, err;
232+ unsigned int status = 0;
233 mm_segment_t old_fs;
234
235 if (!ur)
236@@ -1016,13 +1017,15 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, i
237 old_fs = get_fs();
238
239 set_fs (KERNEL_DS);
240- ret = sys_wait4(pid, ustatus, options, (struct rusage __user *) &r);
241+ ret = sys_wait4(pid, (unsigned int __user *) &status, options,
242+ (struct rusage __user *) &r);
243 set_fs (old_fs);
244
245 if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
246 return -EFAULT;
247
248 err = 0;
249+ err |= put_user(status, ustatus);
250 err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
251 err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
252 err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
253@@ -1142,7 +1145,7 @@ arch_get_unmapped_area_1(unsigned long a
254 /* At this point: (!vma || addr < vma->vm_end). */
255 if (limit - len < addr)
256 return -ENOMEM;
257- if (!vma || addr + len <= vma->vm_start)
258+ if (check_heap_stack_gap(vma, addr, len))
259 return addr;
260 addr = vma->vm_end;
261 vma = vma->vm_next;
262@@ -1178,6 +1181,10 @@ arch_get_unmapped_area(struct file *filp
263 merely specific addresses, but regions of memory -- perhaps
264 this feature should be incorporated into all ports? */
265
266+#ifdef CONFIG_PAX_RANDMMAP
267+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
268+#endif
269+
270 if (addr) {
271 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
272 if (addr != (unsigned long) -ENOMEM)
273@@ -1185,8 +1192,8 @@ arch_get_unmapped_area(struct file *filp
274 }
275
276 /* Next, try allocating at TASK_UNMAPPED_BASE. */
277- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
278- len, limit);
279+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
280+
281 if (addr != (unsigned long) -ENOMEM)
282 return addr;
283
284diff -urNp linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c
285--- linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c 2011-05-19 00:06:34.000000000 -0400
286+++ linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c 2011-05-22 19:36:30.000000000 -0400
287@@ -950,7 +950,7 @@ static int alpha_pci_set_mask(struct dev
288 return 0;
289 }
290
291-struct dma_map_ops alpha_pci_ops = {
292+const struct dma_map_ops alpha_pci_ops = {
293 .alloc_coherent = alpha_pci_alloc_coherent,
294 .free_coherent = alpha_pci_free_coherent,
295 .map_page = alpha_pci_map_page,
296@@ -962,5 +962,5 @@ struct dma_map_ops alpha_pci_ops = {
297 .set_dma_mask = alpha_pci_set_mask,
298 };
299
300-struct dma_map_ops *dma_ops = &alpha_pci_ops;
301+const struct dma_map_ops *dma_ops = &alpha_pci_ops;
302 EXPORT_SYMBOL(dma_ops);
303diff -urNp linux-2.6.39.1/arch/alpha/kernel/pci-noop.c linux-2.6.39.1/arch/alpha/kernel/pci-noop.c
304--- linux-2.6.39.1/arch/alpha/kernel/pci-noop.c 2011-05-19 00:06:34.000000000 -0400
305+++ linux-2.6.39.1/arch/alpha/kernel/pci-noop.c 2011-05-22 19:36:30.000000000 -0400
306@@ -173,7 +173,7 @@ static int alpha_noop_set_mask(struct de
307 return 0;
308 }
309
310-struct dma_map_ops alpha_noop_ops = {
311+const struct dma_map_ops alpha_noop_ops = {
312 .alloc_coherent = alpha_noop_alloc_coherent,
313 .free_coherent = alpha_noop_free_coherent,
314 .map_page = alpha_noop_map_page,
315@@ -183,7 +183,7 @@ struct dma_map_ops alpha_noop_ops = {
316 .set_dma_mask = alpha_noop_set_mask,
317 };
318
319-struct dma_map_ops *dma_ops = &alpha_noop_ops;
320+const struct dma_map_ops *dma_ops = &alpha_noop_ops;
321 EXPORT_SYMBOL(dma_ops);
322
323 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
324diff -urNp linux-2.6.39.1/arch/alpha/kernel/proto.h linux-2.6.39.1/arch/alpha/kernel/proto.h
325--- linux-2.6.39.1/arch/alpha/kernel/proto.h 2011-05-19 00:06:34.000000000 -0400
326+++ linux-2.6.39.1/arch/alpha/kernel/proto.h 2011-05-22 19:36:30.000000000 -0400
327@@ -17,14 +17,14 @@ struct pci_dev;
328 struct pci_controller;
329
330 /* core_apecs.c */
331-extern struct pci_ops apecs_pci_ops;
332+extern const struct pci_ops apecs_pci_ops;
333 extern void apecs_init_arch(void);
334 extern void apecs_pci_clr_err(void);
335 extern void apecs_machine_check(unsigned long vector, unsigned long la_ptr);
336 extern void apecs_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
337
338 /* core_cia.c */
339-extern struct pci_ops cia_pci_ops;
340+extern const struct pci_ops cia_pci_ops;
341 extern void cia_init_pci(void);
342 extern void cia_init_arch(void);
343 extern void pyxis_init_arch(void);
344@@ -33,19 +33,19 @@ extern void cia_machine_check(unsigned l
345 extern void cia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
346
347 /* core_irongate.c */
348-extern struct pci_ops irongate_pci_ops;
349+extern const struct pci_ops irongate_pci_ops;
350 extern int irongate_pci_clr_err(void);
351 extern void irongate_init_arch(void);
352 #define irongate_pci_tbi ((void *)0)
353
354 /* core_lca.c */
355-extern struct pci_ops lca_pci_ops;
356+extern const struct pci_ops lca_pci_ops;
357 extern void lca_init_arch(void);
358 extern void lca_machine_check(unsigned long vector, unsigned long la_ptr);
359 extern void lca_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
360
361 /* core_marvel.c */
362-extern struct pci_ops marvel_pci_ops;
363+extern const struct pci_ops marvel_pci_ops;
364 extern void marvel_init_arch(void);
365 extern void marvel_kill_arch(int);
366 extern void marvel_machine_check(unsigned long, unsigned long);
367@@ -60,14 +60,14 @@ struct io7 *marvel_next_io7(struct io7 *
368 void io7_clear_errors(struct io7 *io7);
369
370 /* core_mcpcia.c */
371-extern struct pci_ops mcpcia_pci_ops;
372+extern const struct pci_ops mcpcia_pci_ops;
373 extern void mcpcia_init_arch(void);
374 extern void mcpcia_init_hoses(void);
375 extern void mcpcia_machine_check(unsigned long vector, unsigned long la_ptr);
376 extern void mcpcia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
377
378 /* core_polaris.c */
379-extern struct pci_ops polaris_pci_ops;
380+extern const struct pci_ops polaris_pci_ops;
381 extern int polaris_read_config_dword(struct pci_dev *, int, u32 *);
382 extern int polaris_write_config_dword(struct pci_dev *, int, u32);
383 extern void polaris_init_arch(void);
384@@ -75,14 +75,14 @@ extern void polaris_machine_check(unsign
385 #define polaris_pci_tbi ((void *)0)
386
387 /* core_t2.c */
388-extern struct pci_ops t2_pci_ops;
389+extern const struct pci_ops t2_pci_ops;
390 extern void t2_init_arch(void);
391 extern void t2_kill_arch(int);
392 extern void t2_machine_check(unsigned long vector, unsigned long la_ptr);
393 extern void t2_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
394
395 /* core_titan.c */
396-extern struct pci_ops titan_pci_ops;
397+extern const struct pci_ops titan_pci_ops;
398 extern void titan_init_arch(void);
399 extern void titan_kill_arch(int);
400 extern void titan_machine_check(unsigned long, unsigned long);
401@@ -90,14 +90,14 @@ extern void titan_pci_tbi(struct pci_con
402 extern struct _alpha_agp_info *titan_agp_info(void);
403
404 /* core_tsunami.c */
405-extern struct pci_ops tsunami_pci_ops;
406+extern const struct pci_ops tsunami_pci_ops;
407 extern void tsunami_init_arch(void);
408 extern void tsunami_kill_arch(int);
409 extern void tsunami_machine_check(unsigned long vector, unsigned long la_ptr);
410 extern void tsunami_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
411
412 /* core_wildfire.c */
413-extern struct pci_ops wildfire_pci_ops;
414+extern const struct pci_ops wildfire_pci_ops;
415 extern void wildfire_init_arch(void);
416 extern void wildfire_kill_arch(int);
417 extern void wildfire_machine_check(unsigned long vector, unsigned long la_ptr);
418diff -urNp linux-2.6.39.1/arch/alpha/mm/fault.c linux-2.6.39.1/arch/alpha/mm/fault.c
419--- linux-2.6.39.1/arch/alpha/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
420+++ linux-2.6.39.1/arch/alpha/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
421@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
422 __reload_thread(pcb);
423 }
424
425+#ifdef CONFIG_PAX_PAGEEXEC
426+/*
427+ * PaX: decide what to do with offenders (regs->pc = fault address)
428+ *
429+ * returns 1 when task should be killed
430+ * 2 when patched PLT trampoline was detected
431+ * 3 when unpatched PLT trampoline was detected
432+ */
433+static int pax_handle_fetch_fault(struct pt_regs *regs)
434+{
435+
436+#ifdef CONFIG_PAX_EMUPLT
437+ int err;
438+
439+ do { /* PaX: patched PLT emulation #1 */
440+ unsigned int ldah, ldq, jmp;
441+
442+ err = get_user(ldah, (unsigned int *)regs->pc);
443+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
444+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
445+
446+ if (err)
447+ break;
448+
449+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
450+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
451+ jmp == 0x6BFB0000U)
452+ {
453+ unsigned long r27, addr;
454+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
455+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
456+
457+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
458+ err = get_user(r27, (unsigned long *)addr);
459+ if (err)
460+ break;
461+
462+ regs->r27 = r27;
463+ regs->pc = r27;
464+ return 2;
465+ }
466+ } while (0);
467+
468+ do { /* PaX: patched PLT emulation #2 */
469+ unsigned int ldah, lda, br;
470+
471+ err = get_user(ldah, (unsigned int *)regs->pc);
472+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
473+ err |= get_user(br, (unsigned int *)(regs->pc+8));
474+
475+ if (err)
476+ break;
477+
478+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
479+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
480+ (br & 0xFFE00000U) == 0xC3E00000U)
481+ {
482+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
483+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
484+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
485+
486+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
487+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
488+ return 2;
489+ }
490+ } while (0);
491+
492+ do { /* PaX: unpatched PLT emulation */
493+ unsigned int br;
494+
495+ err = get_user(br, (unsigned int *)regs->pc);
496+
497+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
498+ unsigned int br2, ldq, nop, jmp;
499+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
500+
501+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
502+ err = get_user(br2, (unsigned int *)addr);
503+ err |= get_user(ldq, (unsigned int *)(addr+4));
504+ err |= get_user(nop, (unsigned int *)(addr+8));
505+ err |= get_user(jmp, (unsigned int *)(addr+12));
506+ err |= get_user(resolver, (unsigned long *)(addr+16));
507+
508+ if (err)
509+ break;
510+
511+ if (br2 == 0xC3600000U &&
512+ ldq == 0xA77B000CU &&
513+ nop == 0x47FF041FU &&
514+ jmp == 0x6B7B0000U)
515+ {
516+ regs->r28 = regs->pc+4;
517+ regs->r27 = addr+16;
518+ regs->pc = resolver;
519+ return 3;
520+ }
521+ }
522+ } while (0);
523+#endif
524+
525+ return 1;
526+}
527+
528+void pax_report_insns(void *pc, void *sp)
529+{
530+ unsigned long i;
531+
532+ printk(KERN_ERR "PAX: bytes at PC: ");
533+ for (i = 0; i < 5; i++) {
534+ unsigned int c;
535+ if (get_user(c, (unsigned int *)pc+i))
536+ printk(KERN_CONT "???????? ");
537+ else
538+ printk(KERN_CONT "%08x ", c);
539+ }
540+ printk("\n");
541+}
542+#endif
543
544 /*
545 * This routine handles page faults. It determines the address,
546@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
547 good_area:
548 si_code = SEGV_ACCERR;
549 if (cause < 0) {
550- if (!(vma->vm_flags & VM_EXEC))
551+ if (!(vma->vm_flags & VM_EXEC)) {
552+
553+#ifdef CONFIG_PAX_PAGEEXEC
554+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
555+ goto bad_area;
556+
557+ up_read(&mm->mmap_sem);
558+ switch (pax_handle_fetch_fault(regs)) {
559+
560+#ifdef CONFIG_PAX_EMUPLT
561+ case 2:
562+ case 3:
563+ return;
564+#endif
565+
566+ }
567+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
568+ do_group_exit(SIGKILL);
569+#else
570 goto bad_area;
571+#endif
572+
573+ }
574 } else if (!cause) {
575 /* Allow reads even for write-only mappings */
576 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
577diff -urNp linux-2.6.39.1/arch/arm/common/it8152.c linux-2.6.39.1/arch/arm/common/it8152.c
578--- linux-2.6.39.1/arch/arm/common/it8152.c 2011-05-19 00:06:34.000000000 -0400
579+++ linux-2.6.39.1/arch/arm/common/it8152.c 2011-05-22 19:36:30.000000000 -0400
580@@ -221,7 +221,7 @@ static int it8152_pci_write_config(struc
581 return PCIBIOS_SUCCESSFUL;
582 }
583
584-static struct pci_ops it8152_ops = {
585+static const struct pci_ops it8152_ops = {
586 .read = it8152_pci_read_config,
587 .write = it8152_pci_write_config,
588 };
589diff -urNp linux-2.6.39.1/arch/arm/common/via82c505.c linux-2.6.39.1/arch/arm/common/via82c505.c
590--- linux-2.6.39.1/arch/arm/common/via82c505.c 2011-05-19 00:06:34.000000000 -0400
591+++ linux-2.6.39.1/arch/arm/common/via82c505.c 2011-05-22 19:36:30.000000000 -0400
592@@ -52,7 +52,7 @@ via82c505_write_config(struct pci_bus *b
593 return PCIBIOS_SUCCESSFUL;
594 }
595
596-static struct pci_ops via82c505_ops = {
597+static const struct pci_ops via82c505_ops = {
598 .read = via82c505_read_config,
599 .write = via82c505_write_config,
600 };
601diff -urNp linux-2.6.39.1/arch/arm/include/asm/cacheflush.h linux-2.6.39.1/arch/arm/include/asm/cacheflush.h
602--- linux-2.6.39.1/arch/arm/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
603+++ linux-2.6.39.1/arch/arm/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
604@@ -115,7 +115,7 @@ struct cpu_cache_fns {
605 */
606 #ifdef MULTI_CACHE
607
608-extern struct cpu_cache_fns cpu_cache;
609+extern const struct cpu_cache_fns cpu_cache;
610
611 #define __cpuc_flush_icache_all cpu_cache.flush_icache_all
612 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
613diff -urNp linux-2.6.39.1/arch/arm/include/asm/elf.h linux-2.6.39.1/arch/arm/include/asm/elf.h
614--- linux-2.6.39.1/arch/arm/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
615+++ linux-2.6.39.1/arch/arm/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
616@@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t
617 the loader. We need to make sure that it is out of the way of the program
618 that it will "exec", and that there is sufficient room for the brk. */
619
620-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
621+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
622+
623+#ifdef CONFIG_PAX_ASLR
624+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
625+
626+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
627+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
628+#endif
629
630 /* When the program starts, a1 contains a pointer to a function to be
631 registered with atexit, as per the SVR4 ABI. A value of 0 means we
632@@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t
633 extern void elf_set_personality(const struct elf32_hdr *);
634 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
635
636-struct mm_struct;
637-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
638-#define arch_randomize_brk arch_randomize_brk
639-
640 extern int vectors_user_mapping(void);
641 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
642 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
643diff -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
644--- linux-2.6.39.1/arch/arm/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
645+++ linux-2.6.39.1/arch/arm/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
646@@ -21,6 +21,7 @@ enum km_type {
647 KM_L1_CACHE,
648 KM_L2_CACHE,
649 KM_KDB,
650+ KM_CLEARPAGE,
651 KM_TYPE_NR
652 };
653
654diff -urNp linux-2.6.39.1/arch/arm/include/asm/outercache.h linux-2.6.39.1/arch/arm/include/asm/outercache.h
655--- linux-2.6.39.1/arch/arm/include/asm/outercache.h 2011-05-19 00:06:34.000000000 -0400
656+++ linux-2.6.39.1/arch/arm/include/asm/outercache.h 2011-05-22 19:36:30.000000000 -0400
657@@ -38,7 +38,7 @@ struct outer_cache_fns {
658
659 #ifdef CONFIG_OUTER_CACHE
660
661-extern struct outer_cache_fns outer_cache;
662+extern const struct outer_cache_fns outer_cache;
663
664 static inline void outer_inv_range(phys_addr_t start, phys_addr_t end)
665 {
666diff -urNp linux-2.6.39.1/arch/arm/include/asm/page.h linux-2.6.39.1/arch/arm/include/asm/page.h
667--- linux-2.6.39.1/arch/arm/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
668+++ linux-2.6.39.1/arch/arm/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
669@@ -126,7 +126,7 @@ struct cpu_user_fns {
670 };
671
672 #ifdef MULTI_USER
673-extern struct cpu_user_fns cpu_user;
674+extern const struct cpu_user_fns cpu_user;
675
676 #define __cpu_clear_user_highpage cpu_user.cpu_clear_user_highpage
677 #define __cpu_copy_user_highpage cpu_user.cpu_copy_user_highpage
678diff -urNp linux-2.6.39.1/arch/arm/include/asm/uaccess.h linux-2.6.39.1/arch/arm/include/asm/uaccess.h
679--- linux-2.6.39.1/arch/arm/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
680+++ linux-2.6.39.1/arch/arm/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
681@@ -403,6 +403,9 @@ extern unsigned long __must_check __strn
682
683 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
684 {
685+ if ((long)n < 0)
686+ return n;
687+
688 if (access_ok(VERIFY_READ, from, n))
689 n = __copy_from_user(to, from, n);
690 else /* security hole - plug it */
691@@ -412,6 +415,9 @@ static inline unsigned long __must_check
692
693 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
694 {
695+ if ((long)n < 0)
696+ return n;
697+
698 if (access_ok(VERIFY_WRITE, to, n))
699 n = __copy_to_user(to, from, n);
700 return n;
701diff -urNp linux-2.6.39.1/arch/arm/kernel/kgdb.c linux-2.6.39.1/arch/arm/kernel/kgdb.c
702--- linux-2.6.39.1/arch/arm/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
703+++ linux-2.6.39.1/arch/arm/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
704@@ -246,7 +246,7 @@ void kgdb_arch_exit(void)
705 * and we handle the normal undef case within the do_undefinstr
706 * handler.
707 */
708-struct kgdb_arch arch_kgdb_ops = {
709+const struct kgdb_arch arch_kgdb_ops = {
710 #ifndef __ARMEB__
711 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
712 #else /* ! __ARMEB__ */
713diff -urNp linux-2.6.39.1/arch/arm/kernel/process.c linux-2.6.39.1/arch/arm/kernel/process.c
714--- linux-2.6.39.1/arch/arm/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
715+++ linux-2.6.39.1/arch/arm/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
716@@ -28,7 +28,6 @@
717 #include <linux/tick.h>
718 #include <linux/utsname.h>
719 #include <linux/uaccess.h>
720-#include <linux/random.h>
721 #include <linux/hw_breakpoint.h>
722
723 #include <asm/cacheflush.h>
724@@ -479,12 +478,6 @@ unsigned long get_wchan(struct task_stru
725 return 0;
726 }
727
728-unsigned long arch_randomize_brk(struct mm_struct *mm)
729-{
730- unsigned long range_end = mm->brk + 0x02000000;
731- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
732-}
733-
734 #ifdef CONFIG_MMU
735 /*
736 * The vectors page is always readable from user space for the
737diff -urNp linux-2.6.39.1/arch/arm/kernel/traps.c linux-2.6.39.1/arch/arm/kernel/traps.c
738--- linux-2.6.39.1/arch/arm/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
739+++ linux-2.6.39.1/arch/arm/kernel/traps.c 2011-06-13 21:30:34.000000000 -0400
740@@ -258,6 +258,8 @@ static int __die(const char *str, int er
741
742 static DEFINE_SPINLOCK(die_lock);
743
744+extern void gr_handle_kernel_exploit(void);
745+
746 /*
747 * This function is protected against re-entrancy.
748 */
749@@ -285,6 +287,9 @@ void die(const char *str, struct pt_regs
750 panic("Fatal exception in interrupt");
751 if (panic_on_oops)
752 panic("Fatal exception");
753+
754+ gr_handle_kernel_exploit();
755+
756 if (ret != NOTIFY_STOP)
757 do_exit(SIGSEGV);
758 }
759diff -urNp linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c
760--- linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c 2011-05-19 00:06:34.000000000 -0400
761+++ linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c 2011-05-22 19:36:30.000000000 -0400
762@@ -162,7 +162,7 @@ static int cns3xxx_pci_setup(int nr, str
763 return 1;
764 }
765
766-static struct pci_ops cns3xxx_pcie_ops = {
767+static const struct pci_ops cns3xxx_pcie_ops = {
768 .read = cns3xxx_pci_read_config,
769 .write = cns3xxx_pci_write_config,
770 };
771diff -urNp linux-2.6.39.1/arch/arm/mach-dove/pcie.c linux-2.6.39.1/arch/arm/mach-dove/pcie.c
772--- linux-2.6.39.1/arch/arm/mach-dove/pcie.c 2011-05-19 00:06:34.000000000 -0400
773+++ linux-2.6.39.1/arch/arm/mach-dove/pcie.c 2011-05-22 19:36:30.000000000 -0400
774@@ -155,7 +155,7 @@ static int pcie_wr_conf(struct pci_bus *
775 return ret;
776 }
777
778-static struct pci_ops pcie_ops = {
779+static const struct pci_ops pcie_ops = {
780 .read = pcie_rd_conf,
781 .write = pcie_wr_conf,
782 };
783diff -urNp linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c
784--- linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c 2011-05-19 00:06:34.000000000 -0400
785+++ linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c 2011-05-22 19:36:30.000000000 -0400
786@@ -129,7 +129,7 @@ dc21285_write_config(struct pci_bus *bus
787 return PCIBIOS_SUCCESSFUL;
788 }
789
790-static struct pci_ops dc21285_ops = {
791+static const struct pci_ops dc21285_ops = {
792 .read = dc21285_read_config,
793 .write = dc21285_write_config,
794 };
795diff -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
796--- linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c 2011-05-19 00:06:34.000000000 -0400
797+++ linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c 2011-05-22 19:36:30.000000000 -0400
798@@ -340,7 +340,7 @@ static int v3_write_config(struct pci_bu
799 return PCIBIOS_SUCCESSFUL;
800 }
801
802-static struct pci_ops pci_v3_ops = {
803+static const struct pci_ops pci_v3_ops = {
804 .read = v3_read_config,
805 .write = v3_write_config,
806 };
807diff -urNp linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c
808--- linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c 2011-05-19 00:06:34.000000000 -0400
809+++ linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c 2011-05-22 19:36:30.000000000 -0400
810@@ -324,7 +324,7 @@ iop13xx_atux_write_config(struct pci_bus
811 return PCIBIOS_SUCCESSFUL;
812 }
813
814-static struct pci_ops iop13xx_atux_ops = {
815+static const struct pci_ops iop13xx_atux_ops = {
816 .read = iop13xx_atux_read_config,
817 .write = iop13xx_atux_write_config,
818 };
819@@ -471,7 +471,7 @@ iop13xx_atue_write_config(struct pci_bus
820 return PCIBIOS_SUCCESSFUL;
821 }
822
823-static struct pci_ops iop13xx_atue_ops = {
824+static const struct pci_ops iop13xx_atue_ops = {
825 .read = iop13xx_atue_read_config,
826 .write = iop13xx_atue_write_config,
827 };
828diff -urNp linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c
829--- linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c 2011-05-19 00:06:34.000000000 -0400
830+++ linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c 2011-05-22 19:36:30.000000000 -0400
831@@ -137,7 +137,7 @@ static int enp2611_pci_write_config(stru
832 return PCIBIOS_DEVICE_NOT_FOUND;
833 }
834
835-static struct pci_ops enp2611_pci_ops = {
836+static const struct pci_ops enp2611_pci_ops = {
837 .read = enp2611_pci_read_config,
838 .write = enp2611_pci_write_config
839 };
840diff -urNp linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c
841--- linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c 2011-05-19 00:06:34.000000000 -0400
842+++ linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c 2011-05-22 19:36:30.000000000 -0400
843@@ -125,7 +125,7 @@ int ixp2000_pci_write_config(struct pci_
844 }
845
846
847-static struct pci_ops ixp2000_pci_ops = {
848+static const struct pci_ops ixp2000_pci_ops = {
849 .read = ixp2000_pci_read_config,
850 .write = ixp2000_pci_write_config
851 };
852diff -urNp linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c
853--- linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c 2011-05-19 00:06:34.000000000 -0400
854+++ linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c 2011-05-22 19:36:30.000000000 -0400
855@@ -136,7 +136,7 @@ static int ixp23xx_pci_write_config(stru
856 return PCIBIOS_SUCCESSFUL;
857 }
858
859-struct pci_ops ixp23xx_pci_ops = {
860+const struct pci_ops ixp23xx_pci_ops = {
861 .read = ixp23xx_pci_read_config,
862 .write = ixp23xx_pci_write_config,
863 };
864diff -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
865--- linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c 2011-05-19 00:06:34.000000000 -0400
866+++ linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c 2011-05-22 19:36:30.000000000 -0400
867@@ -283,7 +283,7 @@ static int ixp4xx_pci_write_config(struc
868 return PCIBIOS_SUCCESSFUL;
869 }
870
871-struct pci_ops ixp4xx_ops = {
872+const struct pci_ops ixp4xx_ops = {
873 .read = ixp4xx_pci_read_config,
874 .write = ixp4xx_pci_write_config,
875 };
876diff -urNp linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c
877--- linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c 2011-05-19 00:06:34.000000000 -0400
878+++ linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c 2011-05-22 19:36:30.000000000 -0400
879@@ -111,7 +111,7 @@ static int pcie_wr_conf(struct pci_bus *
880 return ret;
881 }
882
883-static struct pci_ops pcie_ops = {
884+static const struct pci_ops pcie_ops = {
885 .read = pcie_rd_conf,
886 .write = pcie_wr_conf,
887 };
888diff -urNp linux-2.6.39.1/arch/arm/mach-ks8695/pci.c linux-2.6.39.1/arch/arm/mach-ks8695/pci.c
889--- linux-2.6.39.1/arch/arm/mach-ks8695/pci.c 2011-05-19 00:06:34.000000000 -0400
890+++ linux-2.6.39.1/arch/arm/mach-ks8695/pci.c 2011-05-22 19:36:30.000000000 -0400
891@@ -136,7 +136,7 @@ static void ks8695_local_writeconfig(int
892 __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
893 }
894
895-static struct pci_ops ks8695_pci_ops = {
896+static const struct pci_ops ks8695_pci_ops = {
897 .read = ks8695_pci_readconfig,
898 .write = ks8695_pci_writeconfig,
899 };
900diff -urNp linux-2.6.39.1/arch/arm/mach-mmp/clock.c linux-2.6.39.1/arch/arm/mach-mmp/clock.c
901--- linux-2.6.39.1/arch/arm/mach-mmp/clock.c 2011-05-19 00:06:34.000000000 -0400
902+++ linux-2.6.39.1/arch/arm/mach-mmp/clock.c 2011-05-22 19:36:30.000000000 -0400
903@@ -29,7 +29,7 @@ static void apbc_clk_disable(struct clk
904 __raw_writel(0, clk->clk_rst);
905 }
906
907-struct clkops apbc_clk_ops = {
908+const struct clkops apbc_clk_ops = {
909 .enable = apbc_clk_enable,
910 .disable = apbc_clk_disable,
911 };
912@@ -44,7 +44,7 @@ static void apmu_clk_disable(struct clk
913 __raw_writel(0, clk->clk_rst);
914 }
915
916-struct clkops apmu_clk_ops = {
917+const struct clkops apmu_clk_ops = {
918 .enable = apmu_clk_enable,
919 .disable = apmu_clk_disable,
920 };
921diff -urNp linux-2.6.39.1/arch/arm/mach-msm/iommu.c linux-2.6.39.1/arch/arm/mach-msm/iommu.c
922--- linux-2.6.39.1/arch/arm/mach-msm/iommu.c 2011-05-19 00:06:34.000000000 -0400
923+++ linux-2.6.39.1/arch/arm/mach-msm/iommu.c 2011-05-22 19:36:30.000000000 -0400
924@@ -669,7 +669,7 @@ fail:
925 return 0;
926 }
927
928-static struct iommu_ops msm_iommu_ops = {
929+static const struct iommu_ops msm_iommu_ops = {
930 .domain_init = msm_iommu_domain_init,
931 .domain_destroy = msm_iommu_domain_destroy,
932 .attach_dev = msm_iommu_attach_dev,
933diff -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
934--- linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c 2011-05-19 00:06:34.000000000 -0400
935+++ linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c 2011-05-22 19:36:30.000000000 -0400
936@@ -48,6 +48,7 @@ static ssize_t last_radio_log_read(struc
937 }
938
939 static struct file_operations last_radio_log_fops = {
940+ /* cannot be const, see msm_init_last_radio_log */
941 .read = last_radio_log_read,
942 .llseek = default_llseek,
943 };
944diff -urNp linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c
945--- linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c 2011-05-19 00:06:34.000000000 -0400
946+++ linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c 2011-05-22 19:36:30.000000000 -0400
947@@ -222,7 +222,7 @@ static int pcie_wr_conf(struct pci_bus *
948 return ret;
949 }
950
951-static struct pci_ops pcie_ops = {
952+static const struct pci_ops pcie_ops = {
953 .read = pcie_rd_conf,
954 .write = pcie_wr_conf,
955 };
956diff -urNp linux-2.6.39.1/arch/arm/mach-orion5x/pci.c linux-2.6.39.1/arch/arm/mach-orion5x/pci.c
957--- linux-2.6.39.1/arch/arm/mach-orion5x/pci.c 2011-05-19 00:06:34.000000000 -0400
958+++ linux-2.6.39.1/arch/arm/mach-orion5x/pci.c 2011-05-22 19:36:30.000000000 -0400
959@@ -130,7 +130,7 @@ static int pcie_wr_conf(struct pci_bus *
960 return ret;
961 }
962
963-static struct pci_ops pcie_ops = {
964+static const struct pci_ops pcie_ops = {
965 .read = pcie_rd_conf,
966 .write = pcie_wr_conf,
967 };
968@@ -368,7 +368,7 @@ static int orion5x_pci_wr_conf(struct pc
969 PCI_FUNC(devfn), where, size, val);
970 }
971
972-static struct pci_ops pci_ops = {
973+static const struct pci_ops pci_ops = {
974 .read = orion5x_pci_rd_conf,
975 .write = orion5x_pci_wr_conf,
976 };
977diff -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
978--- linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-19 00:06:34.000000000 -0400
979+++ linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-22 19:36:30.000000000 -0400
980@@ -117,7 +117,7 @@ static int nanoengine_write_config(struc
981 return PCIBIOS_SUCCESSFUL;
982 }
983
984-static struct pci_ops pci_nano_ops = {
985+static const struct pci_ops pci_nano_ops = {
986 .read = nanoengine_read_config,
987 .write = nanoengine_write_config,
988 };
989diff -urNp linux-2.6.39.1/arch/arm/mach-tegra/pcie.c linux-2.6.39.1/arch/arm/mach-tegra/pcie.c
990--- linux-2.6.39.1/arch/arm/mach-tegra/pcie.c 2011-05-19 00:06:34.000000000 -0400
991+++ linux-2.6.39.1/arch/arm/mach-tegra/pcie.c 2011-05-22 19:36:30.000000000 -0400
992@@ -336,7 +336,7 @@ static int tegra_pcie_write_conf(struct
993 return PCIBIOS_SUCCESSFUL;
994 }
995
996-static struct pci_ops tegra_pcie_ops = {
997+static const struct pci_ops tegra_pcie_ops = {
998 .read = tegra_pcie_read_conf,
999 .write = tegra_pcie_write_conf,
1000 };
1001diff -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
1002--- linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c 2011-05-19 00:06:34.000000000 -0400
1003+++ linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c 2011-05-22 19:41:32.000000000 -0400
1004@@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct dev
1005 return sprintf(buf, "0x%X\n", mbox_value);
1006 }
1007
1008-static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1009+static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1010
1011 static int mbox_show(struct seq_file *s, void *data)
1012 {
1013diff -urNp linux-2.6.39.1/arch/arm/mach-versatile/pci.c linux-2.6.39.1/arch/arm/mach-versatile/pci.c
1014--- linux-2.6.39.1/arch/arm/mach-versatile/pci.c 2011-05-19 00:06:34.000000000 -0400
1015+++ linux-2.6.39.1/arch/arm/mach-versatile/pci.c 2011-05-22 19:36:30.000000000 -0400
1016@@ -165,7 +165,7 @@ static int versatile_write_config(struct
1017 return PCIBIOS_SUCCESSFUL;
1018 }
1019
1020-static struct pci_ops pci_versatile_ops = {
1021+static const struct pci_ops pci_versatile_ops = {
1022 .read = versatile_read_config,
1023 .write = versatile_write_config,
1024 };
1025diff -urNp linux-2.6.39.1/arch/arm/mm/fault.c linux-2.6.39.1/arch/arm/mm/fault.c
1026--- linux-2.6.39.1/arch/arm/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1027+++ linux-2.6.39.1/arch/arm/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1028@@ -182,6 +182,13 @@ __do_user_fault(struct task_struct *tsk,
1029 }
1030 #endif
1031
1032+#ifdef CONFIG_PAX_PAGEEXEC
1033+ if (fsr & FSR_LNX_PF) {
1034+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1035+ do_group_exit(SIGKILL);
1036+ }
1037+#endif
1038+
1039 tsk->thread.address = addr;
1040 tsk->thread.error_code = fsr;
1041 tsk->thread.trap_no = 14;
1042@@ -379,6 +386,33 @@ do_page_fault(unsigned long addr, unsign
1043 }
1044 #endif /* CONFIG_MMU */
1045
1046+#ifdef CONFIG_PAX_PAGEEXEC
1047+void pax_report_insns(void *pc, void *sp)
1048+{
1049+ long i;
1050+
1051+ printk(KERN_ERR "PAX: bytes at PC: ");
1052+ for (i = 0; i < 20; i++) {
1053+ unsigned char c;
1054+ if (get_user(c, (__force unsigned char __user *)pc+i))
1055+ printk(KERN_CONT "?? ");
1056+ else
1057+ printk(KERN_CONT "%02x ", c);
1058+ }
1059+ printk("\n");
1060+
1061+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1062+ for (i = -1; i < 20; i++) {
1063+ unsigned long c;
1064+ if (get_user(c, (__force unsigned long __user *)sp+i))
1065+ printk(KERN_CONT "???????? ");
1066+ else
1067+ printk(KERN_CONT "%08lx ", c);
1068+ }
1069+ printk("\n");
1070+}
1071+#endif
1072+
1073 /*
1074 * First Level Translation Fault Handler
1075 *
1076diff -urNp linux-2.6.39.1/arch/arm/mm/mmap.c linux-2.6.39.1/arch/arm/mm/mmap.c
1077--- linux-2.6.39.1/arch/arm/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
1078+++ linux-2.6.39.1/arch/arm/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
1079@@ -65,6 +65,10 @@ arch_get_unmapped_area(struct file *filp
1080 if (len > TASK_SIZE)
1081 return -ENOMEM;
1082
1083+#ifdef CONFIG_PAX_RANDMMAP
1084+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1085+#endif
1086+
1087 if (addr) {
1088 if (do_align)
1089 addr = COLOUR_ALIGN(addr, pgoff);
1090@@ -72,15 +76,14 @@ arch_get_unmapped_area(struct file *filp
1091 addr = PAGE_ALIGN(addr);
1092
1093 vma = find_vma(mm, addr);
1094- if (TASK_SIZE - len >= addr &&
1095- (!vma || addr + len <= vma->vm_start))
1096+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1097 return addr;
1098 }
1099 if (len > mm->cached_hole_size) {
1100- start_addr = addr = mm->free_area_cache;
1101+ start_addr = addr = mm->free_area_cache;
1102 } else {
1103- start_addr = addr = TASK_UNMAPPED_BASE;
1104- mm->cached_hole_size = 0;
1105+ start_addr = addr = mm->mmap_base;
1106+ mm->cached_hole_size = 0;
1107 }
1108 /* 8 bits of randomness in 20 address space bits */
1109 if ((current->flags & PF_RANDOMIZE) &&
1110@@ -100,14 +103,14 @@ full_search:
1111 * Start a new search - just in case we missed
1112 * some holes.
1113 */
1114- if (start_addr != TASK_UNMAPPED_BASE) {
1115- start_addr = addr = TASK_UNMAPPED_BASE;
1116+ if (start_addr != mm->mmap_base) {
1117+ start_addr = addr = mm->mmap_base;
1118 mm->cached_hole_size = 0;
1119 goto full_search;
1120 }
1121 return -ENOMEM;
1122 }
1123- if (!vma || addr + len <= vma->vm_start) {
1124+ if (check_heap_stack_gap(vma, addr, len)) {
1125 /*
1126 * Remember the place where we stopped the search:
1127 */
1128diff -urNp linux-2.6.39.1/arch/arm/plat-iop/pci.c linux-2.6.39.1/arch/arm/plat-iop/pci.c
1129--- linux-2.6.39.1/arch/arm/plat-iop/pci.c 2011-05-19 00:06:34.000000000 -0400
1130+++ linux-2.6.39.1/arch/arm/plat-iop/pci.c 2011-05-22 19:36:30.000000000 -0400
1131@@ -161,7 +161,7 @@ iop3xx_write_config(struct pci_bus *bus,
1132 return PCIBIOS_SUCCESSFUL;
1133 }
1134
1135-static struct pci_ops iop3xx_ops = {
1136+static const struct pci_ops iop3xx_ops = {
1137 .read = iop3xx_read_config,
1138 .write = iop3xx_write_config,
1139 };
1140diff -urNp linux-2.6.39.1/arch/avr32/include/asm/elf.h linux-2.6.39.1/arch/avr32/include/asm/elf.h
1141--- linux-2.6.39.1/arch/avr32/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1142+++ linux-2.6.39.1/arch/avr32/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1143@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpreg
1144 the loader. We need to make sure that it is out of the way of the program
1145 that it will "exec", and that there is sufficient room for the brk. */
1146
1147-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1148+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1149
1150+#ifdef CONFIG_PAX_ASLR
1151+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1152+
1153+#define PAX_DELTA_MMAP_LEN 15
1154+#define PAX_DELTA_STACK_LEN 15
1155+#endif
1156
1157 /* This yields a mask that user programs can use to figure out what
1158 instruction set this CPU supports. This could be done in user space,
1159diff -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
1160--- linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1161+++ linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1162@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1163 D(11) KM_IRQ1,
1164 D(12) KM_SOFTIRQ0,
1165 D(13) KM_SOFTIRQ1,
1166-D(14) KM_TYPE_NR
1167+D(14) KM_CLEARPAGE,
1168+D(15) KM_TYPE_NR
1169 };
1170
1171 #undef D
1172diff -urNp linux-2.6.39.1/arch/avr32/mm/fault.c linux-2.6.39.1/arch/avr32/mm/fault.c
1173--- linux-2.6.39.1/arch/avr32/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1174+++ linux-2.6.39.1/arch/avr32/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1175@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
1176
1177 int exception_trace = 1;
1178
1179+#ifdef CONFIG_PAX_PAGEEXEC
1180+void pax_report_insns(void *pc, void *sp)
1181+{
1182+ unsigned long i;
1183+
1184+ printk(KERN_ERR "PAX: bytes at PC: ");
1185+ for (i = 0; i < 20; i++) {
1186+ unsigned char c;
1187+ if (get_user(c, (unsigned char *)pc+i))
1188+ printk(KERN_CONT "???????? ");
1189+ else
1190+ printk(KERN_CONT "%02x ", c);
1191+ }
1192+ printk("\n");
1193+}
1194+#endif
1195+
1196 /*
1197 * This routine handles page faults. It determines the address and the
1198 * problem, and then passes it off to one of the appropriate routines.
1199@@ -156,6 +173,16 @@ bad_area:
1200 up_read(&mm->mmap_sem);
1201
1202 if (user_mode(regs)) {
1203+
1204+#ifdef CONFIG_PAX_PAGEEXEC
1205+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1206+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1207+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1208+ do_group_exit(SIGKILL);
1209+ }
1210+ }
1211+#endif
1212+
1213 if (exception_trace && printk_ratelimit())
1214 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1215 "sp %08lx ecr %lu\n",
1216diff -urNp linux-2.6.39.1/arch/blackfin/kernel/kgdb.c linux-2.6.39.1/arch/blackfin/kernel/kgdb.c
1217--- linux-2.6.39.1/arch/blackfin/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1218+++ linux-2.6.39.1/arch/blackfin/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1219@@ -420,7 +420,7 @@ int kgdb_arch_handle_exception(int vecto
1220 return -1; /* this means that we do not want to exit from the handler */
1221 }
1222
1223-struct kgdb_arch arch_kgdb_ops = {
1224+const struct kgdb_arch arch_kgdb_ops = {
1225 .gdb_bpt_instr = {0xa1},
1226 .flags = KGDB_HW_BREAKPOINT,
1227 .set_hw_breakpoint = bfin_set_hw_break,
1228diff -urNp linux-2.6.39.1/arch/blackfin/mm/maccess.c linux-2.6.39.1/arch/blackfin/mm/maccess.c
1229--- linux-2.6.39.1/arch/blackfin/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
1230+++ linux-2.6.39.1/arch/blackfin/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
1231@@ -16,7 +16,7 @@ static int validate_memory_access_addres
1232 return bfin_mem_access_type(addr, size);
1233 }
1234
1235-long probe_kernel_read(void *dst, void *src, size_t size)
1236+long probe_kernel_read(void *dst, const void *src, size_t size)
1237 {
1238 unsigned long lsrc = (unsigned long)src;
1239 int mem_type;
1240@@ -55,7 +55,7 @@ long probe_kernel_read(void *dst, void *
1241 return -EFAULT;
1242 }
1243
1244-long probe_kernel_write(void *dst, void *src, size_t size)
1245+long probe_kernel_write(void *dst, const void *src, size_t size)
1246 {
1247 unsigned long ldst = (unsigned long)dst;
1248 int mem_type;
1249diff -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
1250--- linux-2.6.39.1/arch/frv/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1251+++ linux-2.6.39.1/arch/frv/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1252@@ -23,6 +23,7 @@ enum km_type {
1253 KM_IRQ1,
1254 KM_SOFTIRQ0,
1255 KM_SOFTIRQ1,
1256+ KM_CLEARPAGE,
1257 KM_TYPE_NR
1258 };
1259
1260diff -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
1261--- linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h 2011-05-19 00:06:34.000000000 -0400
1262+++ linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h 2011-05-22 19:36:30.000000000 -0400
1263@@ -34,7 +34,7 @@ void pcibios_resource_survey(void);
1264
1265 extern int __nongpreldata pcibios_last_bus;
1266 extern struct pci_bus *__nongpreldata pci_root_bus;
1267-extern struct pci_ops *__nongpreldata pci_root_ops;
1268+extern const struct pci_ops *__nongpreldata pci_root_ops;
1269
1270 /* pci-irq.c */
1271 extern unsigned int pcibios_irq_mask;
1272diff -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
1273--- linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-19 00:06:34.000000000 -0400
1274+++ linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-22 19:36:30.000000000 -0400
1275@@ -27,7 +27,7 @@ unsigned int __nongpreldata pci_probe =
1276
1277 int __nongpreldata pcibios_last_bus = -1;
1278 struct pci_bus *__nongpreldata pci_root_bus;
1279-struct pci_ops *__nongpreldata pci_root_ops;
1280+const struct pci_ops *__nongpreldata pci_root_ops;
1281
1282 /*
1283 * The accessible PCI window does not cover the entire CPU address space, but
1284@@ -169,7 +169,7 @@ static int pci_frv_write_config(struct p
1285 return PCIBIOS_SUCCESSFUL;
1286 }
1287
1288-static struct pci_ops pci_direct_frv = {
1289+static const struct pci_ops pci_direct_frv = {
1290 pci_frv_read_config,
1291 pci_frv_write_config,
1292 };
1293@@ -356,7 +356,7 @@ void __init pcibios_fixup_bus(struct pci
1294
1295 int __init pcibios_init(void)
1296 {
1297- struct pci_ops *dir = NULL;
1298+ const struct pci_ops *dir = NULL;
1299
1300 if (!mb93090_mb00_detected)
1301 return -ENXIO;
1302diff -urNp linux-2.6.39.1/arch/frv/mm/elf-fdpic.c linux-2.6.39.1/arch/frv/mm/elf-fdpic.c
1303--- linux-2.6.39.1/arch/frv/mm/elf-fdpic.c 2011-05-19 00:06:34.000000000 -0400
1304+++ linux-2.6.39.1/arch/frv/mm/elf-fdpic.c 2011-05-22 19:36:30.000000000 -0400
1305@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
1306 if (addr) {
1307 addr = PAGE_ALIGN(addr);
1308 vma = find_vma(current->mm, addr);
1309- if (TASK_SIZE - len >= addr &&
1310- (!vma || addr + len <= vma->vm_start))
1311+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1312 goto success;
1313 }
1314
1315@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
1316 for (; vma; vma = vma->vm_next) {
1317 if (addr > limit)
1318 break;
1319- if (addr + len <= vma->vm_start)
1320+ if (check_heap_stack_gap(vma, addr, len))
1321 goto success;
1322 addr = vma->vm_end;
1323 }
1324@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
1325 for (; vma; vma = vma->vm_next) {
1326 if (addr > limit)
1327 break;
1328- if (addr + len <= vma->vm_start)
1329+ if (check_heap_stack_gap(vma, addr, len))
1330 goto success;
1331 addr = vma->vm_end;
1332 }
1333diff -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
1334--- linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c 2011-05-19 00:06:34.000000000 -0400
1335+++ linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c 2011-05-22 19:36:30.000000000 -0400
1336@@ -17,7 +17,7 @@
1337 #include <linux/swiotlb.h>
1338 #include <asm/machvec.h>
1339
1340-extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1341+extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1342
1343 /* swiotlb declarations & definitions: */
1344 extern int swiotlb_late_init_with_default_size (size_t size);
1345@@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
1346 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1347 }
1348
1349-struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1350+const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1351 {
1352 if (use_swiotlb(dev))
1353 return &swiotlb_dma_ops;
1354diff -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
1355--- linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c 2011-05-19 00:06:34.000000000 -0400
1356+++ linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c 2011-05-22 19:36:30.000000000 -0400
1357@@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
1358 },
1359 };
1360
1361-extern struct dma_map_ops swiotlb_dma_ops;
1362+extern const struct dma_map_ops swiotlb_dma_ops;
1363
1364 static int __init
1365 sba_init(void)
1366@@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1367
1368 __setup("sbapagesize=",sba_page_override);
1369
1370-struct dma_map_ops sba_dma_ops = {
1371+const struct dma_map_ops sba_dma_ops = {
1372 .alloc_coherent = sba_alloc_coherent,
1373 .free_coherent = sba_free_coherent,
1374 .map_page = sba_map_page,
1375diff -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
1376--- linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1377+++ linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1378@@ -14,7 +14,7 @@
1379
1380 #define DMA_ERROR_CODE 0
1381
1382-extern struct dma_map_ops *dma_ops;
1383+extern const struct dma_map_ops *dma_ops;
1384 extern struct ia64_machine_vector ia64_mv;
1385 extern void set_iommu_machvec(void);
1386
1387@@ -26,7 +26,7 @@ extern void machvec_dma_sync_sg(struct d
1388 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1389 dma_addr_t *daddr, gfp_t gfp)
1390 {
1391- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1392+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1393 void *caddr;
1394
1395 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1396@@ -37,7 +37,7 @@ static inline void *dma_alloc_coherent(s
1397 static inline void dma_free_coherent(struct device *dev, size_t size,
1398 void *caddr, dma_addr_t daddr)
1399 {
1400- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1401+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1402 debug_dma_free_coherent(dev, size, caddr, daddr);
1403 ops->free_coherent(dev, size, caddr, daddr);
1404 }
1405@@ -51,13 +51,13 @@ static inline void dma_free_coherent(str
1406
1407 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1408 {
1409- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1410+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1411 return ops->mapping_error(dev, daddr);
1412 }
1413
1414 static inline int dma_supported(struct device *dev, u64 mask)
1415 {
1416- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1417+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1418 return ops->dma_supported(dev, mask);
1419 }
1420
1421diff -urNp linux-2.6.39.1/arch/ia64/include/asm/elf.h linux-2.6.39.1/arch/ia64/include/asm/elf.h
1422--- linux-2.6.39.1/arch/ia64/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1423+++ linux-2.6.39.1/arch/ia64/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1424@@ -42,6 +42,13 @@
1425 */
1426 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1427
1428+#ifdef CONFIG_PAX_ASLR
1429+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1430+
1431+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1432+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1433+#endif
1434+
1435 #define PT_IA_64_UNWIND 0x70000001
1436
1437 /* IA-64 relocations: */
1438diff -urNp linux-2.6.39.1/arch/ia64/include/asm/machvec.h linux-2.6.39.1/arch/ia64/include/asm/machvec.h
1439--- linux-2.6.39.1/arch/ia64/include/asm/machvec.h 2011-05-19 00:06:34.000000000 -0400
1440+++ linux-2.6.39.1/arch/ia64/include/asm/machvec.h 2011-05-22 19:36:30.000000000 -0400
1441@@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1442 /* DMA-mapping interface: */
1443 typedef void ia64_mv_dma_init (void);
1444 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1445-typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1446+typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1447
1448 /*
1449 * WARNING: The legacy I/O space is _architected_. Platforms are
1450@@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1451 # endif /* CONFIG_IA64_GENERIC */
1452
1453 extern void swiotlb_dma_init(void);
1454-extern struct dma_map_ops *dma_get_ops(struct device *);
1455+extern const struct dma_map_ops *dma_get_ops(struct device *);
1456
1457 /*
1458 * Define default versions so we can extend machvec for new platforms without having
1459diff -urNp linux-2.6.39.1/arch/ia64/include/asm/pgtable.h linux-2.6.39.1/arch/ia64/include/asm/pgtable.h
1460--- linux-2.6.39.1/arch/ia64/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
1461+++ linux-2.6.39.1/arch/ia64/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
1462@@ -12,7 +12,7 @@
1463 * David Mosberger-Tang <davidm@hpl.hp.com>
1464 */
1465
1466-
1467+#include <linux/const.h>
1468 #include <asm/mman.h>
1469 #include <asm/page.h>
1470 #include <asm/processor.h>
1471@@ -143,6 +143,17 @@
1472 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1473 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1474 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1475+
1476+#ifdef CONFIG_PAX_PAGEEXEC
1477+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1478+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1479+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1480+#else
1481+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1482+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1483+# define PAGE_COPY_NOEXEC PAGE_COPY
1484+#endif
1485+
1486 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1487 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1488 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1489diff -urNp linux-2.6.39.1/arch/ia64/include/asm/spinlock.h linux-2.6.39.1/arch/ia64/include/asm/spinlock.h
1490--- linux-2.6.39.1/arch/ia64/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
1491+++ linux-2.6.39.1/arch/ia64/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
1492@@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1493 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1494
1495 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1496- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1497+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1498 }
1499
1500 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1501diff -urNp linux-2.6.39.1/arch/ia64/include/asm/uaccess.h linux-2.6.39.1/arch/ia64/include/asm/uaccess.h
1502--- linux-2.6.39.1/arch/ia64/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
1503+++ linux-2.6.39.1/arch/ia64/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
1504@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1505 const void *__cu_from = (from); \
1506 long __cu_len = (n); \
1507 \
1508- if (__access_ok(__cu_to, __cu_len, get_fs())) \
1509+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1510 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1511 __cu_len; \
1512 })
1513@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1514 long __cu_len = (n); \
1515 \
1516 __chk_user_ptr(__cu_from); \
1517- if (__access_ok(__cu_from, __cu_len, get_fs())) \
1518+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1519 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1520 __cu_len; \
1521 })
1522diff -urNp linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c
1523--- linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c 2011-05-19 00:06:34.000000000 -0400
1524+++ linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c 2011-05-22 19:36:30.000000000 -0400
1525@@ -3,7 +3,7 @@
1526 /* Set this to 1 if there is a HW IOMMU in the system */
1527 int iommu_detected __read_mostly;
1528
1529-struct dma_map_ops *dma_ops;
1530+const struct dma_map_ops *dma_ops;
1531 EXPORT_SYMBOL(dma_ops);
1532
1533 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1534@@ -16,7 +16,7 @@ static int __init dma_init(void)
1535 }
1536 fs_initcall(dma_init);
1537
1538-struct dma_map_ops *dma_get_ops(struct device *dev)
1539+const struct dma_map_ops *dma_get_ops(struct device *dev)
1540 {
1541 return dma_ops;
1542 }
1543diff -urNp linux-2.6.39.1/arch/ia64/kernel/module.c linux-2.6.39.1/arch/ia64/kernel/module.c
1544--- linux-2.6.39.1/arch/ia64/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
1545+++ linux-2.6.39.1/arch/ia64/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
1546@@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1547 void
1548 module_free (struct module *mod, void *module_region)
1549 {
1550- if (mod && mod->arch.init_unw_table &&
1551- module_region == mod->module_init) {
1552+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1553 unw_remove_unwind_table(mod->arch.init_unw_table);
1554 mod->arch.init_unw_table = NULL;
1555 }
1556@@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1557 }
1558
1559 static inline int
1560+in_init_rx (const struct module *mod, uint64_t addr)
1561+{
1562+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1563+}
1564+
1565+static inline int
1566+in_init_rw (const struct module *mod, uint64_t addr)
1567+{
1568+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1569+}
1570+
1571+static inline int
1572 in_init (const struct module *mod, uint64_t addr)
1573 {
1574- return addr - (uint64_t) mod->module_init < mod->init_size;
1575+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1576+}
1577+
1578+static inline int
1579+in_core_rx (const struct module *mod, uint64_t addr)
1580+{
1581+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1582+}
1583+
1584+static inline int
1585+in_core_rw (const struct module *mod, uint64_t addr)
1586+{
1587+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1588 }
1589
1590 static inline int
1591 in_core (const struct module *mod, uint64_t addr)
1592 {
1593- return addr - (uint64_t) mod->module_core < mod->core_size;
1594+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1595 }
1596
1597 static inline int
1598@@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1599 break;
1600
1601 case RV_BDREL:
1602- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1603+ if (in_init_rx(mod, val))
1604+ val -= (uint64_t) mod->module_init_rx;
1605+ else if (in_init_rw(mod, val))
1606+ val -= (uint64_t) mod->module_init_rw;
1607+ else if (in_core_rx(mod, val))
1608+ val -= (uint64_t) mod->module_core_rx;
1609+ else if (in_core_rw(mod, val))
1610+ val -= (uint64_t) mod->module_core_rw;
1611 break;
1612
1613 case RV_LTV:
1614@@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1615 * addresses have been selected...
1616 */
1617 uint64_t gp;
1618- if (mod->core_size > MAX_LTOFF)
1619+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1620 /*
1621 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1622 * at the end of the module.
1623 */
1624- gp = mod->core_size - MAX_LTOFF / 2;
1625+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1626 else
1627- gp = mod->core_size / 2;
1628- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1629+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1630+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1631 mod->arch.gp = gp;
1632 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1633 }
1634diff -urNp linux-2.6.39.1/arch/ia64/kernel/pci-dma.c linux-2.6.39.1/arch/ia64/kernel/pci-dma.c
1635--- linux-2.6.39.1/arch/ia64/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
1636+++ linux-2.6.39.1/arch/ia64/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
1637@@ -43,7 +43,7 @@ struct device fallback_dev = {
1638 .dma_mask = &fallback_dev.coherent_dma_mask,
1639 };
1640
1641-extern struct dma_map_ops intel_dma_ops;
1642+extern const struct dma_map_ops intel_dma_ops;
1643
1644 static int __init pci_iommu_init(void)
1645 {
1646diff -urNp linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c
1647--- linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
1648+++ linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
1649@@ -22,7 +22,7 @@ static void *ia64_swiotlb_alloc_coherent
1650 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1651 }
1652
1653-struct dma_map_ops swiotlb_dma_ops = {
1654+const struct dma_map_ops swiotlb_dma_ops = {
1655 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1656 .free_coherent = swiotlb_free_coherent,
1657 .map_page = swiotlb_map_page,
1658diff -urNp linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c
1659--- linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c 2011-05-19 00:06:34.000000000 -0400
1660+++ linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c 2011-05-22 19:36:30.000000000 -0400
1661@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1662 if (REGION_NUMBER(addr) == RGN_HPAGE)
1663 addr = 0;
1664 #endif
1665+
1666+#ifdef CONFIG_PAX_RANDMMAP
1667+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1668+ addr = mm->free_area_cache;
1669+ else
1670+#endif
1671+
1672 if (!addr)
1673 addr = mm->free_area_cache;
1674
1675@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1676 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1677 /* At this point: (!vma || addr < vma->vm_end). */
1678 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1679- if (start_addr != TASK_UNMAPPED_BASE) {
1680+ if (start_addr != mm->mmap_base) {
1681 /* Start a new search --- just in case we missed some holes. */
1682- addr = TASK_UNMAPPED_BASE;
1683+ addr = mm->mmap_base;
1684 goto full_search;
1685 }
1686 return -ENOMEM;
1687 }
1688- if (!vma || addr + len <= vma->vm_start) {
1689+ if (check_heap_stack_gap(vma, addr, len)) {
1690 /* Remember the address where we stopped this search: */
1691 mm->free_area_cache = addr + len;
1692 return addr;
1693diff -urNp linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S
1694--- linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
1695+++ linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
1696@@ -199,7 +199,7 @@ SECTIONS {
1697 /* Per-cpu data: */
1698 . = ALIGN(PERCPU_PAGE_SIZE);
1699 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1700- __phys_per_cpu_start = __per_cpu_load;
1701+ __phys_per_cpu_start = per_cpu_load;
1702 /*
1703 * ensure percpu data fits
1704 * into percpu page size
1705diff -urNp linux-2.6.39.1/arch/ia64/mm/fault.c linux-2.6.39.1/arch/ia64/mm/fault.c
1706--- linux-2.6.39.1/arch/ia64/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1707+++ linux-2.6.39.1/arch/ia64/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1708@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1709 return pte_present(pte);
1710 }
1711
1712+#ifdef CONFIG_PAX_PAGEEXEC
1713+void pax_report_insns(void *pc, void *sp)
1714+{
1715+ unsigned long i;
1716+
1717+ printk(KERN_ERR "PAX: bytes at PC: ");
1718+ for (i = 0; i < 8; i++) {
1719+ unsigned int c;
1720+ if (get_user(c, (unsigned int *)pc+i))
1721+ printk(KERN_CONT "???????? ");
1722+ else
1723+ printk(KERN_CONT "%08x ", c);
1724+ }
1725+ printk("\n");
1726+}
1727+#endif
1728+
1729 void __kprobes
1730 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1731 {
1732@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1733 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1734 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1735
1736- if ((vma->vm_flags & mask) != mask)
1737+ if ((vma->vm_flags & mask) != mask) {
1738+
1739+#ifdef CONFIG_PAX_PAGEEXEC
1740+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1741+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1742+ goto bad_area;
1743+
1744+ up_read(&mm->mmap_sem);
1745+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1746+ do_group_exit(SIGKILL);
1747+ }
1748+#endif
1749+
1750 goto bad_area;
1751
1752+ }
1753+
1754 /*
1755 * If for any reason at all we couldn't handle the fault, make
1756 * sure we exit gracefully rather than endlessly redo the
1757diff -urNp linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c
1758--- linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
1759+++ linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
1760@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(
1761 /* At this point: (!vmm || addr < vmm->vm_end). */
1762 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1763 return -ENOMEM;
1764- if (!vmm || (addr + len) <= vmm->vm_start)
1765+ if (check_heap_stack_gap(vmm, addr, len))
1766 return addr;
1767 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1768 }
1769diff -urNp linux-2.6.39.1/arch/ia64/mm/init.c linux-2.6.39.1/arch/ia64/mm/init.c
1770--- linux-2.6.39.1/arch/ia64/mm/init.c 2011-05-19 00:06:34.000000000 -0400
1771+++ linux-2.6.39.1/arch/ia64/mm/init.c 2011-05-22 19:36:30.000000000 -0400
1772@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1773 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1774 vma->vm_end = vma->vm_start + PAGE_SIZE;
1775 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1776+
1777+#ifdef CONFIG_PAX_PAGEEXEC
1778+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1779+ vma->vm_flags &= ~VM_EXEC;
1780+
1781+#ifdef CONFIG_PAX_MPROTECT
1782+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
1783+ vma->vm_flags &= ~VM_MAYEXEC;
1784+#endif
1785+
1786+ }
1787+#endif
1788+
1789 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1790 down_write(&current->mm->mmap_sem);
1791 if (insert_vm_struct(current->mm, vma)) {
1792diff -urNp linux-2.6.39.1/arch/ia64/pci/pci.c linux-2.6.39.1/arch/ia64/pci/pci.c
1793--- linux-2.6.39.1/arch/ia64/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
1794+++ linux-2.6.39.1/arch/ia64/pci/pci.c 2011-05-22 19:36:30.000000000 -0400
1795@@ -109,7 +109,7 @@ static int pci_write(struct pci_bus *bus
1796 devfn, where, size, value);
1797 }
1798
1799-struct pci_ops pci_root_ops = {
1800+const struct pci_ops pci_root_ops = {
1801 .read = pci_read,
1802 .write = pci_write,
1803 };
1804diff -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
1805--- linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c 2011-05-19 00:06:34.000000000 -0400
1806+++ linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c 2011-05-22 19:36:30.000000000 -0400
1807@@ -465,7 +465,7 @@ int sn_pci_legacy_write(struct pci_bus *
1808 return ret;
1809 }
1810
1811-static struct dma_map_ops sn_dma_ops = {
1812+static const struct dma_map_ops sn_dma_ops = {
1813 .alloc_coherent = sn_dma_alloc_coherent,
1814 .free_coherent = sn_dma_free_coherent,
1815 .map_page = sn_dma_map_page,
1816diff -urNp linux-2.6.39.1/arch/m32r/lib/usercopy.c linux-2.6.39.1/arch/m32r/lib/usercopy.c
1817--- linux-2.6.39.1/arch/m32r/lib/usercopy.c 2011-05-19 00:06:34.000000000 -0400
1818+++ linux-2.6.39.1/arch/m32r/lib/usercopy.c 2011-05-22 19:36:30.000000000 -0400
1819@@ -14,6 +14,9 @@
1820 unsigned long
1821 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1822 {
1823+ if ((long)n < 0)
1824+ return n;
1825+
1826 prefetch(from);
1827 if (access_ok(VERIFY_WRITE, to, n))
1828 __copy_user(to,from,n);
1829@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1830 unsigned long
1831 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1832 {
1833+ if ((long)n < 0)
1834+ return n;
1835+
1836 prefetchw(to);
1837 if (access_ok(VERIFY_READ, from, n))
1838 __copy_user_zeroing(to,from,n);
1839diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/device.h linux-2.6.39.1/arch/microblaze/include/asm/device.h
1840--- linux-2.6.39.1/arch/microblaze/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1841+++ linux-2.6.39.1/arch/microblaze/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
1842@@ -13,7 +13,7 @@ struct device_node;
1843
1844 struct dev_archdata {
1845 /* DMA operations on that device */
1846- struct dma_map_ops *dma_ops;
1847+ const struct dma_map_ops *dma_ops;
1848 void *dma_data;
1849 };
1850
1851diff -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
1852--- linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1853+++ linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1854@@ -43,14 +43,14 @@ static inline unsigned long device_to_ma
1855 return 0xfffffffful;
1856 }
1857
1858-extern struct dma_map_ops *dma_ops;
1859+extern const struct dma_map_ops *dma_ops;
1860
1861 /*
1862 * Available generic sets of operations
1863 */
1864-extern struct dma_map_ops dma_direct_ops;
1865+extern const struct dma_map_ops dma_direct_ops;
1866
1867-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1868+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1869 {
1870 /* We don't handle the NULL dev case for ISA for now. We could
1871 * do it via an out of line call but it is not needed for now. The
1872@@ -63,14 +63,14 @@ static inline struct dma_map_ops *get_dm
1873 return dev->archdata.dma_ops;
1874 }
1875
1876-static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
1877+static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
1878 {
1879 dev->archdata.dma_ops = ops;
1880 }
1881
1882 static inline int dma_supported(struct device *dev, u64 mask)
1883 {
1884- struct dma_map_ops *ops = get_dma_ops(dev);
1885+ const struct dma_map_ops *ops = get_dma_ops(dev);
1886
1887 if (unlikely(!ops))
1888 return 0;
1889@@ -81,7 +81,7 @@ static inline int dma_supported(struct d
1890
1891 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1892 {
1893- struct dma_map_ops *ops = get_dma_ops(dev);
1894+ const struct dma_map_ops *ops = get_dma_ops(dev);
1895
1896 if (unlikely(ops == NULL))
1897 return -EIO;
1898@@ -97,7 +97,7 @@ static inline int dma_set_mask(struct de
1899
1900 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1901 {
1902- struct dma_map_ops *ops = get_dma_ops(dev);
1903+ const struct dma_map_ops *ops = get_dma_ops(dev);
1904 if (ops->mapping_error)
1905 return ops->mapping_error(dev, dma_addr);
1906
1907@@ -110,7 +110,7 @@ static inline int dma_mapping_error(stru
1908 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1909 dma_addr_t *dma_handle, gfp_t flag)
1910 {
1911- struct dma_map_ops *ops = get_dma_ops(dev);
1912+ const struct dma_map_ops *ops = get_dma_ops(dev);
1913 void *memory;
1914
1915 BUG_ON(!ops);
1916@@ -124,7 +124,7 @@ static inline void *dma_alloc_coherent(s
1917 static inline void dma_free_coherent(struct device *dev, size_t size,
1918 void *cpu_addr, dma_addr_t dma_handle)
1919 {
1920- struct dma_map_ops *ops = get_dma_ops(dev);
1921+ const struct dma_map_ops *ops = get_dma_ops(dev);
1922
1923 BUG_ON(!ops);
1924 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
1925diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/pci.h linux-2.6.39.1/arch/microblaze/include/asm/pci.h
1926--- linux-2.6.39.1/arch/microblaze/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
1927+++ linux-2.6.39.1/arch/microblaze/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
1928@@ -54,8 +54,8 @@ static inline void pcibios_penalize_isa_
1929 }
1930
1931 #ifdef CONFIG_PCI
1932-extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
1933-extern struct dma_map_ops *get_pci_dma_ops(void);
1934+extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
1935+extern const struct dma_map_ops *get_pci_dma_ops(void);
1936 #else /* CONFIG_PCI */
1937 #define set_pci_dma_ops(d)
1938 #define get_pci_dma_ops() NULL
1939diff -urNp linux-2.6.39.1/arch/microblaze/kernel/dma.c linux-2.6.39.1/arch/microblaze/kernel/dma.c
1940--- linux-2.6.39.1/arch/microblaze/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
1941+++ linux-2.6.39.1/arch/microblaze/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
1942@@ -134,7 +134,7 @@ static inline void dma_direct_unmap_page
1943 __dma_sync_page(dma_address, 0 , size, direction);
1944 }
1945
1946-struct dma_map_ops dma_direct_ops = {
1947+const struct dma_map_ops dma_direct_ops = {
1948 .alloc_coherent = dma_direct_alloc_coherent,
1949 .free_coherent = dma_direct_free_coherent,
1950 .map_sg = dma_direct_map_sg,
1951diff -urNp linux-2.6.39.1/arch/microblaze/kernel/kgdb.c linux-2.6.39.1/arch/microblaze/kernel/kgdb.c
1952--- linux-2.6.39.1/arch/microblaze/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1953+++ linux-2.6.39.1/arch/microblaze/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1954@@ -141,7 +141,7 @@ void kgdb_arch_exit(void)
1955 /*
1956 * Global data
1957 */
1958-struct kgdb_arch arch_kgdb_ops = {
1959+const struct kgdb_arch arch_kgdb_ops = {
1960 #ifdef __MICROBLAZEEL__
1961 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
1962 #else
1963diff -urNp linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c
1964--- linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
1965+++ linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
1966@@ -140,7 +140,7 @@ indirect_write_config(struct pci_bus *bu
1967 return PCIBIOS_SUCCESSFUL;
1968 }
1969
1970-static struct pci_ops indirect_pci_ops = {
1971+static const struct pci_ops indirect_pci_ops = {
1972 .read = indirect_read_config,
1973 .write = indirect_write_config,
1974 };
1975diff -urNp linux-2.6.39.1/arch/microblaze/pci/pci-common.c linux-2.6.39.1/arch/microblaze/pci/pci-common.c
1976--- linux-2.6.39.1/arch/microblaze/pci/pci-common.c 2011-05-19 00:06:34.000000000 -0400
1977+++ linux-2.6.39.1/arch/microblaze/pci/pci-common.c 2011-05-22 19:36:30.000000000 -0400
1978@@ -48,14 +48,14 @@ resource_size_t isa_mem_base;
1979 /* Default PCI flags is 0 on ppc32, modified at boot on ppc64 */
1980 unsigned int pci_flags;
1981
1982-static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1983+static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1984
1985-void set_pci_dma_ops(struct dma_map_ops *dma_ops)
1986+void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
1987 {
1988 pci_dma_ops = dma_ops;
1989 }
1990
1991-struct dma_map_ops *get_pci_dma_ops(void)
1992+const struct dma_map_ops *get_pci_dma_ops(void)
1993 {
1994 return pci_dma_ops;
1995 }
1996@@ -1583,7 +1583,7 @@ null_write_config(struct pci_bus *bus, u
1997 return PCIBIOS_DEVICE_NOT_FOUND;
1998 }
1999
2000-static struct pci_ops null_pci_ops = {
2001+static const struct pci_ops null_pci_ops = {
2002 .read = null_read_config,
2003 .write = null_write_config,
2004 };
2005diff -urNp linux-2.6.39.1/arch/mips/alchemy/common/pci.c linux-2.6.39.1/arch/mips/alchemy/common/pci.c
2006--- linux-2.6.39.1/arch/mips/alchemy/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2007+++ linux-2.6.39.1/arch/mips/alchemy/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2008@@ -51,7 +51,7 @@ static struct resource pci_mem_resource
2009 .flags = IORESOURCE_MEM
2010 };
2011
2012-extern struct pci_ops au1x_pci_ops;
2013+extern const struct pci_ops au1x_pci_ops;
2014
2015 static struct pci_controller au1x_controller = {
2016 .pci_ops = &au1x_pci_ops,
2017diff -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
2018--- linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c 2011-05-19 00:06:34.000000000 -0400
2019+++ linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c 2011-05-22 19:36:30.000000000 -0400
2020@@ -202,7 +202,7 @@ static phys_addr_t octeon_unity_dma_to_p
2021 }
2022
2023 struct octeon_dma_map_ops {
2024- struct dma_map_ops dma_map_ops;
2025+ const struct dma_map_ops dma_map_ops;
2026 dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
2027 phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
2028 };
2029@@ -324,7 +324,7 @@ static struct octeon_dma_map_ops _octeon
2030 },
2031 };
2032
2033-struct dma_map_ops *octeon_pci_dma_map_ops;
2034+const struct dma_map_ops *octeon_pci_dma_map_ops;
2035
2036 void __init octeon_pci_dma_init(void)
2037 {
2038diff -urNp linux-2.6.39.1/arch/mips/cobalt/pci.c linux-2.6.39.1/arch/mips/cobalt/pci.c
2039--- linux-2.6.39.1/arch/mips/cobalt/pci.c 2011-05-19 00:06:34.000000000 -0400
2040+++ linux-2.6.39.1/arch/mips/cobalt/pci.c 2011-05-22 19:36:30.000000000 -0400
2041@@ -14,7 +14,7 @@
2042
2043 #include <asm/gt64120.h>
2044
2045-extern struct pci_ops gt64xxx_pci0_ops;
2046+extern const struct pci_ops gt64xxx_pci0_ops;
2047
2048 static struct resource cobalt_mem_resource = {
2049 .start = GT_DEF_PCI0_MEM0_BASE,
2050diff -urNp linux-2.6.39.1/arch/mips/include/asm/device.h linux-2.6.39.1/arch/mips/include/asm/device.h
2051--- linux-2.6.39.1/arch/mips/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
2052+++ linux-2.6.39.1/arch/mips/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
2053@@ -10,7 +10,7 @@ struct dma_map_ops;
2054
2055 struct dev_archdata {
2056 /* DMA operations on that device */
2057- struct dma_map_ops *dma_ops;
2058+ const struct dma_map_ops *dma_ops;
2059 };
2060
2061 struct pdev_archdata {
2062diff -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
2063--- linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
2064+++ linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
2065@@ -9,9 +9,9 @@
2066 #include <dma-coherence.h>
2067 #endif
2068
2069-extern struct dma_map_ops *mips_dma_map_ops;
2070+extern const struct dma_map_ops *mips_dma_map_ops;
2071
2072-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2073+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2074 {
2075 if (dev && dev->archdata.dma_ops)
2076 return dev->archdata.dma_ops;
2077@@ -33,13 +33,13 @@ static inline void dma_mark_clean(void *
2078
2079 static inline int dma_supported(struct device *dev, u64 mask)
2080 {
2081- struct dma_map_ops *ops = get_dma_ops(dev);
2082+ const struct dma_map_ops *ops = get_dma_ops(dev);
2083 return ops->dma_supported(dev, mask);
2084 }
2085
2086 static inline int dma_mapping_error(struct device *dev, u64 mask)
2087 {
2088- struct dma_map_ops *ops = get_dma_ops(dev);
2089+ const struct dma_map_ops *ops = get_dma_ops(dev);
2090 return ops->mapping_error(dev, mask);
2091 }
2092
2093@@ -61,7 +61,7 @@ static inline void *dma_alloc_coherent(s
2094 dma_addr_t *dma_handle, gfp_t gfp)
2095 {
2096 void *ret;
2097- struct dma_map_ops *ops = get_dma_ops(dev);
2098+ const struct dma_map_ops *ops = get_dma_ops(dev);
2099
2100 ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
2101
2102@@ -73,7 +73,7 @@ static inline void *dma_alloc_coherent(s
2103 static inline void dma_free_coherent(struct device *dev, size_t size,
2104 void *vaddr, dma_addr_t dma_handle)
2105 {
2106- struct dma_map_ops *ops = get_dma_ops(dev);
2107+ const struct dma_map_ops *ops = get_dma_ops(dev);
2108
2109 ops->free_coherent(dev, size, vaddr, dma_handle);
2110
2111diff -urNp linux-2.6.39.1/arch/mips/include/asm/elf.h linux-2.6.39.1/arch/mips/include/asm/elf.h
2112--- linux-2.6.39.1/arch/mips/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2113+++ linux-2.6.39.1/arch/mips/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2114@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2115 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2116 #endif
2117
2118+#ifdef CONFIG_PAX_ASLR
2119+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2120+
2121+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2122+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2123+#endif
2124+
2125 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2126 struct linux_binprm;
2127 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2128 int uses_interp);
2129
2130-struct mm_struct;
2131-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2132-#define arch_randomize_brk arch_randomize_brk
2133-
2134 #endif /* _ASM_ELF_H */
2135diff -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
2136--- linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-19 00:06:34.000000000 -0400
2137+++ linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-22 19:36:30.000000000 -0400
2138@@ -66,7 +66,7 @@ dma_addr_t phys_to_dma(struct device *de
2139 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
2140
2141 struct dma_map_ops;
2142-extern struct dma_map_ops *octeon_pci_dma_map_ops;
2143+extern const struct dma_map_ops *octeon_pci_dma_map_ops;
2144 extern char *octeon_swiotlb;
2145
2146 #endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
2147diff -urNp linux-2.6.39.1/arch/mips/include/asm/page.h linux-2.6.39.1/arch/mips/include/asm/page.h
2148--- linux-2.6.39.1/arch/mips/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
2149+++ linux-2.6.39.1/arch/mips/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
2150@@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
2151 #ifdef CONFIG_CPU_MIPS32
2152 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2153 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2154- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2155+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2156 #else
2157 typedef struct { unsigned long long pte; } pte_t;
2158 #define pte_val(x) ((x).pte)
2159diff -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
2160--- linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h 2011-05-19 00:06:34.000000000 -0400
2161+++ linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h 2011-05-22 19:36:30.000000000 -0400
2162@@ -849,6 +849,6 @@ struct bridge_controller {
2163 extern void register_bridge_irq(unsigned int irq);
2164 extern int request_bridge_irq(struct bridge_controller *bc);
2165
2166-extern struct pci_ops bridge_pci_ops;
2167+extern const struct pci_ops bridge_pci_ops;
2168
2169 #endif /* _ASM_PCI_BRIDGE_H */
2170diff -urNp linux-2.6.39.1/arch/mips/include/asm/system.h linux-2.6.39.1/arch/mips/include/asm/system.h
2171--- linux-2.6.39.1/arch/mips/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
2172+++ linux-2.6.39.1/arch/mips/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
2173@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2174 */
2175 #define __ARCH_WANT_UNLOCKED_CTXSW
2176
2177-extern unsigned long arch_align_stack(unsigned long sp);
2178+#define arch_align_stack(x) ((x) & ~0xfUL)
2179
2180 #endif /* _ASM_SYSTEM_H */
2181diff -urNp linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c
2182--- linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c 2011-05-19 00:06:34.000000000 -0400
2183+++ linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c 2011-05-22 19:36:30.000000000 -0400
2184@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2185 #undef ELF_ET_DYN_BASE
2186 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2187
2188+#ifdef CONFIG_PAX_ASLR
2189+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2190+
2191+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2192+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2193+#endif
2194+
2195 #include <asm/processor.h>
2196 #include <linux/module.h>
2197 #include <linux/elfcore.h>
2198diff -urNp linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c
2199--- linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c 2011-05-19 00:06:34.000000000 -0400
2200+++ linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c 2011-05-22 19:36:30.000000000 -0400
2201@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2202 #undef ELF_ET_DYN_BASE
2203 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2204
2205+#ifdef CONFIG_PAX_ASLR
2206+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2207+
2208+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2209+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2210+#endif
2211+
2212 #include <asm/processor.h>
2213
2214 /*
2215diff -urNp linux-2.6.39.1/arch/mips/kernel/kgdb.c linux-2.6.39.1/arch/mips/kernel/kgdb.c
2216--- linux-2.6.39.1/arch/mips/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
2217+++ linux-2.6.39.1/arch/mips/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
2218@@ -351,7 +351,7 @@ int kgdb_arch_handle_exception(int vecto
2219 return -1;
2220 }
2221
2222-struct kgdb_arch arch_kgdb_ops;
2223+struct kgdb_arch arch_kgdb_ops; /* cannot be const, see kgdb_arch_init */
2224
2225 /*
2226 * We use kgdb_early_setup so that functions we need to call now don't
2227diff -urNp linux-2.6.39.1/arch/mips/kernel/process.c linux-2.6.39.1/arch/mips/kernel/process.c
2228--- linux-2.6.39.1/arch/mips/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
2229+++ linux-2.6.39.1/arch/mips/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
2230@@ -473,15 +473,3 @@ unsigned long get_wchan(struct task_stru
2231 out:
2232 return pc;
2233 }
2234-
2235-/*
2236- * Don't forget that the stack pointer must be aligned on a 8 bytes
2237- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2238- */
2239-unsigned long arch_align_stack(unsigned long sp)
2240-{
2241- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2242- sp -= get_random_int() & ~PAGE_MASK;
2243-
2244- return sp & ALMASK;
2245-}
2246diff -urNp linux-2.6.39.1/arch/mips/kernel/syscall.c linux-2.6.39.1/arch/mips/kernel/syscall.c
2247--- linux-2.6.39.1/arch/mips/kernel/syscall.c 2011-05-19 00:06:34.000000000 -0400
2248+++ linux-2.6.39.1/arch/mips/kernel/syscall.c 2011-05-22 19:36:30.000000000 -0400
2249@@ -108,14 +108,18 @@ unsigned long arch_get_unmapped_area(str
2250 do_color_align = 0;
2251 if (filp || (flags & MAP_SHARED))
2252 do_color_align = 1;
2253+
2254+#ifdef CONFIG_PAX_RANDMMAP
2255+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2256+#endif
2257+
2258 if (addr) {
2259 if (do_color_align)
2260 addr = COLOUR_ALIGN(addr, pgoff);
2261 else
2262 addr = PAGE_ALIGN(addr);
2263 vmm = find_vma(current->mm, addr);
2264- if (task_size - len >= addr &&
2265- (!vmm || addr + len <= vmm->vm_start))
2266+ if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2267 return addr;
2268 }
2269 addr = current->mm->mmap_base;
2270@@ -128,7 +132,7 @@ unsigned long arch_get_unmapped_area(str
2271 /* At this point: (!vmm || addr < vmm->vm_end). */
2272 if (task_size - len < addr)
2273 return -ENOMEM;
2274- if (!vmm || addr + len <= vmm->vm_start)
2275+ if (check_heap_stack_gap(vmm, addr, len))
2276 return addr;
2277 addr = vmm->vm_end;
2278 if (do_color_align)
2279@@ -154,33 +158,6 @@ void arch_pick_mmap_layout(struct mm_str
2280 mm->unmap_area = arch_unmap_area;
2281 }
2282
2283-static inline unsigned long brk_rnd(void)
2284-{
2285- unsigned long rnd = get_random_int();
2286-
2287- rnd = rnd << PAGE_SHIFT;
2288- /* 8MB for 32bit, 256MB for 64bit */
2289- if (TASK_IS_32BIT_ADDR)
2290- rnd = rnd & 0x7ffffful;
2291- else
2292- rnd = rnd & 0xffffffful;
2293-
2294- return rnd;
2295-}
2296-
2297-unsigned long arch_randomize_brk(struct mm_struct *mm)
2298-{
2299- unsigned long base = mm->brk;
2300- unsigned long ret;
2301-
2302- ret = PAGE_ALIGN(base + brk_rnd());
2303-
2304- if (ret < mm->brk)
2305- return mm->brk;
2306-
2307- return ret;
2308-}
2309-
2310 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
2311 unsigned long, prot, unsigned long, flags, unsigned long,
2312 fd, off_t, offset)
2313diff -urNp linux-2.6.39.1/arch/mips/mm/dma-default.c linux-2.6.39.1/arch/mips/mm/dma-default.c
2314--- linux-2.6.39.1/arch/mips/mm/dma-default.c 2011-05-19 00:06:34.000000000 -0400
2315+++ linux-2.6.39.1/arch/mips/mm/dma-default.c 2011-05-22 19:36:30.000000000 -0400
2316@@ -300,7 +300,7 @@ void dma_cache_sync(struct device *dev,
2317
2318 EXPORT_SYMBOL(dma_cache_sync);
2319
2320-static struct dma_map_ops mips_default_dma_map_ops = {
2321+static const struct dma_map_ops mips_default_dma_map_ops = {
2322 .alloc_coherent = mips_dma_alloc_coherent,
2323 .free_coherent = mips_dma_free_coherent,
2324 .map_page = mips_dma_map_page,
2325@@ -315,7 +315,7 @@ static struct dma_map_ops mips_default_d
2326 .dma_supported = mips_dma_supported
2327 };
2328
2329-struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2330+const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2331 EXPORT_SYMBOL(mips_dma_map_ops);
2332
2333 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
2334diff -urNp linux-2.6.39.1/arch/mips/mm/fault.c linux-2.6.39.1/arch/mips/mm/fault.c
2335--- linux-2.6.39.1/arch/mips/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
2336+++ linux-2.6.39.1/arch/mips/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
2337@@ -28,6 +28,23 @@
2338 #include <asm/highmem.h> /* For VMALLOC_END */
2339 #include <linux/kdebug.h>
2340
2341+#ifdef CONFIG_PAX_PAGEEXEC
2342+void pax_report_insns(void *pc, void *sp)
2343+{
2344+ unsigned long i;
2345+
2346+ printk(KERN_ERR "PAX: bytes at PC: ");
2347+ for (i = 0; i < 5; i++) {
2348+ unsigned int c;
2349+ if (get_user(c, (unsigned int *)pc+i))
2350+ printk(KERN_CONT "???????? ");
2351+ else
2352+ printk(KERN_CONT "%08x ", c);
2353+ }
2354+ printk("\n");
2355+}
2356+#endif
2357+
2358 /*
2359 * This routine handles page faults. It determines the address,
2360 * and the problem, and then passes it off to one of the appropriate
2361diff -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
2362--- linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c 2011-05-19 00:06:34.000000000 -0400
2363+++ linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c 2011-05-22 19:36:30.000000000 -0400
2364@@ -64,9 +64,9 @@ static struct resource msc_io_resource =
2365 .flags = IORESOURCE_IO,
2366 };
2367
2368-extern struct pci_ops bonito64_pci_ops;
2369-extern struct pci_ops gt64xxx_pci0_ops;
2370-extern struct pci_ops msc_pci_ops;
2371+extern const struct pci_ops bonito64_pci_ops;
2372+extern const struct pci_ops gt64xxx_pci0_ops;
2373+extern const struct pci_ops msc_pci_ops;
2374
2375 static struct pci_controller bonito64_controller = {
2376 .pci_ops = &bonito64_pci_ops,
2377diff -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
2378--- linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2379+++ linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2380@@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2381 .flags = IORESOURCE_MEM
2382 };
2383
2384-extern struct pci_ops pnx8550_pci_ops;
2385+extern const struct pci_ops pnx8550_pci_ops;
2386
2387 static struct pci_controller pnx8550_controller = {
2388 .pci_ops = &pnx8550_pci_ops,
2389diff -urNp linux-2.6.39.1/arch/mips/pci/ops-au1000.c linux-2.6.39.1/arch/mips/pci/ops-au1000.c
2390--- linux-2.6.39.1/arch/mips/pci/ops-au1000.c 2011-05-19 00:06:34.000000000 -0400
2391+++ linux-2.6.39.1/arch/mips/pci/ops-au1000.c 2011-05-22 19:36:30.000000000 -0400
2392@@ -302,7 +302,7 @@ static int config_write(struct pci_bus *
2393 }
2394 }
2395
2396-struct pci_ops au1x_pci_ops = {
2397+const struct pci_ops au1x_pci_ops = {
2398 config_read,
2399 config_write
2400 };
2401diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c
2402--- linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c 2011-05-19 00:06:34.000000000 -0400
2403+++ linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c 2011-05-22 19:36:30.000000000 -0400
2404@@ -173,7 +173,7 @@ static int bcm63xx_pci_write(struct pci_
2405 where, size, val);
2406 }
2407
2408-struct pci_ops bcm63xx_pci_ops = {
2409+const struct pci_ops bcm63xx_pci_ops = {
2410 .read = bcm63xx_pci_read,
2411 .write = bcm63xx_pci_write
2412 };
2413@@ -402,7 +402,7 @@ static int bcm63xx_cb_write(struct pci_b
2414 return PCIBIOS_DEVICE_NOT_FOUND;
2415 }
2416
2417-struct pci_ops bcm63xx_cb_ops = {
2418+const struct pci_ops bcm63xx_cb_ops = {
2419 .read = bcm63xx_cb_read,
2420 .write = bcm63xx_cb_write,
2421 };
2422diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bonito64.c linux-2.6.39.1/arch/mips/pci/ops-bonito64.c
2423--- linux-2.6.39.1/arch/mips/pci/ops-bonito64.c 2011-05-19 00:06:34.000000000 -0400
2424+++ linux-2.6.39.1/arch/mips/pci/ops-bonito64.c 2011-05-22 19:36:30.000000000 -0400
2425@@ -155,7 +155,7 @@ static int bonito64_pcibios_write(struct
2426 return PCIBIOS_SUCCESSFUL;
2427 }
2428
2429-struct pci_ops bonito64_pci_ops = {
2430+const struct pci_ops bonito64_pci_ops = {
2431 .read = bonito64_pcibios_read,
2432 .write = bonito64_pcibios_write
2433 };
2434diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bridge.c linux-2.6.39.1/arch/mips/pci/ops-bridge.c
2435--- linux-2.6.39.1/arch/mips/pci/ops-bridge.c 2011-05-19 00:06:34.000000000 -0400
2436+++ linux-2.6.39.1/arch/mips/pci/ops-bridge.c 2011-05-22 19:36:30.000000000 -0400
2437@@ -316,7 +316,7 @@ static int pci_write_config(struct pci_b
2438 return pci_conf0_write_config(bus, devfn, where, size, value);
2439 }
2440
2441-struct pci_ops bridge_pci_ops = {
2442+const struct pci_ops bridge_pci_ops = {
2443 .read = pci_read_config,
2444 .write = pci_write_config,
2445 };
2446diff -urNp linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c
2447--- linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2448+++ linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2449@@ -176,7 +176,7 @@ static int pci_config_write(struct pci_b
2450 return PCIBIOS_SUCCESSFUL;
2451 }
2452
2453-struct pci_ops emma2rh_pci_ops = {
2454+const struct pci_ops emma2rh_pci_ops = {
2455 .read = pci_config_read,
2456 .write = pci_config_write,
2457 };
2458diff -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
2459--- linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-19 00:06:34.000000000 -0400
2460+++ linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-22 19:36:30.000000000 -0400
2461@@ -146,7 +146,7 @@ static int gt64xxx_pci0_pcibios_write(st
2462 return PCIBIOS_SUCCESSFUL;
2463 }
2464
2465-struct pci_ops gt64xxx_pci0_ops = {
2466+const struct pci_ops gt64xxx_pci0_ops = {
2467 .read = gt64xxx_pci0_pcibios_read,
2468 .write = gt64xxx_pci0_pcibios_write
2469 };
2470diff -urNp linux-2.6.39.1/arch/mips/pci/ops-loongson2.c linux-2.6.39.1/arch/mips/pci/ops-loongson2.c
2471--- linux-2.6.39.1/arch/mips/pci/ops-loongson2.c 2011-05-19 00:06:34.000000000 -0400
2472+++ linux-2.6.39.1/arch/mips/pci/ops-loongson2.c 2011-05-22 19:36:30.000000000 -0400
2473@@ -174,7 +174,7 @@ static int loongson_pcibios_write(struct
2474 return PCIBIOS_SUCCESSFUL;
2475 }
2476
2477-struct pci_ops loongson_pci_ops = {
2478+const struct pci_ops loongson_pci_ops = {
2479 .read = loongson_pcibios_read,
2480 .write = loongson_pcibios_write
2481 };
2482diff -urNp linux-2.6.39.1/arch/mips/pci/ops-mace.c linux-2.6.39.1/arch/mips/pci/ops-mace.c
2483--- linux-2.6.39.1/arch/mips/pci/ops-mace.c 2011-05-19 00:06:34.000000000 -0400
2484+++ linux-2.6.39.1/arch/mips/pci/ops-mace.c 2011-05-22 19:36:30.000000000 -0400
2485@@ -96,7 +96,7 @@ mace_pci_write_config(struct pci_bus *bu
2486 return PCIBIOS_SUCCESSFUL;
2487 }
2488
2489-struct pci_ops mace_pci_ops = {
2490+const struct pci_ops mace_pci_ops = {
2491 .read = mace_pci_read_config,
2492 .write = mace_pci_write_config,
2493 };
2494diff -urNp linux-2.6.39.1/arch/mips/pci/ops-msc.c linux-2.6.39.1/arch/mips/pci/ops-msc.c
2495--- linux-2.6.39.1/arch/mips/pci/ops-msc.c 2011-05-19 00:06:34.000000000 -0400
2496+++ linux-2.6.39.1/arch/mips/pci/ops-msc.c 2011-05-22 19:36:30.000000000 -0400
2497@@ -142,7 +142,7 @@ static int msc_pcibios_write(struct pci_
2498 return PCIBIOS_SUCCESSFUL;
2499 }
2500
2501-struct pci_ops msc_pci_ops = {
2502+const struct pci_ops msc_pci_ops = {
2503 .read = msc_pcibios_read,
2504 .write = msc_pcibios_write
2505 };
2506diff -urNp linux-2.6.39.1/arch/mips/pci/ops-nile4.c linux-2.6.39.1/arch/mips/pci/ops-nile4.c
2507--- linux-2.6.39.1/arch/mips/pci/ops-nile4.c 2011-05-19 00:06:34.000000000 -0400
2508+++ linux-2.6.39.1/arch/mips/pci/ops-nile4.c 2011-05-22 19:36:30.000000000 -0400
2509@@ -141,7 +141,7 @@ static int nile4_pcibios_write(struct pc
2510 return PCIBIOS_SUCCESSFUL;
2511 }
2512
2513-struct pci_ops nile4_pci_ops = {
2514+const struct pci_ops nile4_pci_ops = {
2515 .read = nile4_pcibios_read,
2516 .write = nile4_pcibios_write,
2517 };
2518diff -urNp linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c
2519--- linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
2520+++ linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c 2011-05-22 19:36:30.000000000 -0400
2521@@ -904,7 +904,7 @@ msp_pcibios_write_config(struct pci_bus
2522 * write - function for Linux to generate PCI Configuration writes.
2523 *
2524 ****************************************************************************/
2525-struct pci_ops msp_pci_ops = {
2526+const struct pci_ops msp_pci_ops = {
2527 .read = msp_pcibios_read_config,
2528 .write = msp_pcibios_write_config
2529 };
2530diff -urNp linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c
2531--- linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c 2011-05-19 00:06:34.000000000 -0400
2532+++ linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c 2011-05-22 19:36:30.000000000 -0400
2533@@ -276,7 +276,7 @@ static int config_write(struct pci_bus *
2534 }
2535 }
2536
2537-struct pci_ops pnx8550_pci_ops = {
2538+const struct pci_ops pnx8550_pci_ops = {
2539 config_read,
2540 config_write
2541 };
2542diff -urNp linux-2.6.39.1/arch/mips/pci/ops-rc32434.c linux-2.6.39.1/arch/mips/pci/ops-rc32434.c
2543--- linux-2.6.39.1/arch/mips/pci/ops-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2544+++ linux-2.6.39.1/arch/mips/pci/ops-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2545@@ -201,7 +201,7 @@ static int pci_config_write(struct pci_b
2546 }
2547 }
2548
2549-struct pci_ops rc32434_pci_ops = {
2550+const struct pci_ops rc32434_pci_ops = {
2551 .read = pci_config_read,
2552 .write = pci_config_write,
2553 };
2554diff -urNp linux-2.6.39.1/arch/mips/pci/ops-sni.c linux-2.6.39.1/arch/mips/pci/ops-sni.c
2555--- linux-2.6.39.1/arch/mips/pci/ops-sni.c 2011-05-19 00:06:34.000000000 -0400
2556+++ linux-2.6.39.1/arch/mips/pci/ops-sni.c 2011-05-22 19:36:30.000000000 -0400
2557@@ -83,7 +83,7 @@ static int pcimt_write(struct pci_bus *b
2558 return 0;
2559 }
2560
2561-struct pci_ops sni_pcimt_ops = {
2562+const struct pci_ops sni_pcimt_ops = {
2563 .read = pcimt_read,
2564 .write = pcimt_write,
2565 };
2566@@ -158,7 +158,7 @@ static int pcit_write(struct pci_bus *bu
2567 }
2568
2569
2570-struct pci_ops sni_pcit_ops = {
2571+const struct pci_ops sni_pcit_ops = {
2572 .read = pcit_read,
2573 .write = pcit_write,
2574 };
2575diff -urNp linux-2.6.39.1/arch/mips/pci/ops-titan.c linux-2.6.39.1/arch/mips/pci/ops-titan.c
2576--- linux-2.6.39.1/arch/mips/pci/ops-titan.c 2011-05-19 00:06:34.000000000 -0400
2577+++ linux-2.6.39.1/arch/mips/pci/ops-titan.c 2011-05-22 19:36:30.000000000 -0400
2578@@ -105,7 +105,7 @@ static int titan_write_config(struct pci
2579 /*
2580 * Titan PCI structure
2581 */
2582-struct pci_ops titan_pci_ops = {
2583+const struct pci_ops titan_pci_ops = {
2584 titan_read_config,
2585 titan_write_config,
2586 };
2587diff -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
2588--- linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c 2011-05-19 00:06:34.000000000 -0400
2589+++ linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c 2011-05-22 19:36:30.000000000 -0400
2590@@ -118,7 +118,7 @@ static int titan_ht_config_write(struct
2591 return PCIBIOS_SUCCESSFUL;
2592 }
2593
2594-struct pci_ops titan_ht_pci_ops = {
2595+const struct pci_ops titan_ht_pci_ops = {
2596 .read = titan_ht_config_read,
2597 .write = titan_ht_config_write,
2598 };
2599diff -urNp linux-2.6.39.1/arch/mips/pci/ops-tx3927.c linux-2.6.39.1/arch/mips/pci/ops-tx3927.c
2600--- linux-2.6.39.1/arch/mips/pci/ops-tx3927.c 2011-05-19 00:06:34.000000000 -0400
2601+++ linux-2.6.39.1/arch/mips/pci/ops-tx3927.c 2011-05-22 19:36:30.000000000 -0400
2602@@ -121,7 +121,7 @@ static int tx3927_pci_write_config(struc
2603 return check_abort();
2604 }
2605
2606-static struct pci_ops tx3927_pci_ops = {
2607+static const struct pci_ops tx3927_pci_ops = {
2608 .read = tx3927_pci_read_config,
2609 .write = tx3927_pci_write_config,
2610 };
2611diff -urNp linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c
2612--- linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2613+++ linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2614@@ -120,7 +120,7 @@ static int pci_config_write(struct pci_b
2615 return PCIBIOS_SUCCESSFUL;
2616 }
2617
2618-struct pci_ops vr41xx_pci_ops = {
2619+const struct pci_ops vr41xx_pci_ops = {
2620 .read = pci_config_read,
2621 .write = pci_config_write,
2622 };
2623diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c
2624--- linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c 2011-05-19 00:06:34.000000000 -0400
2625+++ linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c 2011-05-22 19:36:30.000000000 -0400
2626@@ -171,7 +171,7 @@ static int bcm1480_pcibios_write(struct
2627 return PCIBIOS_SUCCESSFUL;
2628 }
2629
2630-struct pci_ops bcm1480_pci_ops = {
2631+const struct pci_ops bcm1480_pci_ops = {
2632 bcm1480_pcibios_read,
2633 bcm1480_pcibios_write,
2634 };
2635diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c
2636--- linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c 2011-05-19 00:06:34.000000000 -0400
2637+++ linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c 2011-05-22 19:36:30.000000000 -0400
2638@@ -166,7 +166,7 @@ static int bcm1480ht_pcibios_get_busno(v
2639 return 0;
2640 }
2641
2642-struct pci_ops bcm1480ht_pci_ops = {
2643+const struct pci_ops bcm1480ht_pci_ops = {
2644 .read = bcm1480ht_pcibios_read,
2645 .write = bcm1480ht_pcibios_write,
2646 };
2647diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h
2648--- linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h 2011-05-19 00:06:34.000000000 -0400
2649+++ linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h 2011-05-22 19:36:30.000000000 -0400
2650@@ -16,8 +16,8 @@
2651 /*
2652 * defined in ops-bcm63xx.c
2653 */
2654-extern struct pci_ops bcm63xx_pci_ops;
2655-extern struct pci_ops bcm63xx_cb_ops;
2656+extern const struct pci_ops bcm63xx_pci_ops;
2657+extern const struct pci_ops bcm63xx_cb_ops;
2658
2659 /*
2660 * defined in pci-bcm63xx.c
2661diff -urNp linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c
2662--- linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2663+++ linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2664@@ -43,7 +43,7 @@ static struct resource pci_mem_resource
2665 .flags = IORESOURCE_MEM,
2666 };
2667
2668-extern struct pci_ops emma2rh_pci_ops;
2669+extern const struct pci_ops emma2rh_pci_ops;
2670
2671 static struct pci_controller emma2rh_pci_controller = {
2672 .pci_ops = &emma2rh_pci_ops,
2673diff -urNp linux-2.6.39.1/arch/mips/pci/pcie-octeon.c linux-2.6.39.1/arch/mips/pci/pcie-octeon.c
2674--- linux-2.6.39.1/arch/mips/pci/pcie-octeon.c 2011-05-19 00:06:34.000000000 -0400
2675+++ linux-2.6.39.1/arch/mips/pci/pcie-octeon.c 2011-05-22 19:36:30.000000000 -0400
2676@@ -1237,7 +1237,7 @@ static int octeon_pcie1_write_config(str
2677 return octeon_pcie_write_config(1, bus, devfn, reg, size, val);
2678 }
2679
2680-static struct pci_ops octeon_pcie0_ops = {
2681+static const struct pci_ops octeon_pcie0_ops = {
2682 octeon_pcie0_read_config,
2683 octeon_pcie0_write_config,
2684 };
2685@@ -1258,7 +1258,7 @@ static struct pci_controller octeon_pcie
2686 .io_resource = &octeon_pcie0_io_resource,
2687 };
2688
2689-static struct pci_ops octeon_pcie1_ops = {
2690+static const struct pci_ops octeon_pcie1_ops = {
2691 octeon_pcie1_read_config,
2692 octeon_pcie1_write_config,
2693 };
2694diff -urNp linux-2.6.39.1/arch/mips/pci/pci-ip27.c linux-2.6.39.1/arch/mips/pci/pci-ip27.c
2695--- linux-2.6.39.1/arch/mips/pci/pci-ip27.c 2011-05-19 00:06:34.000000000 -0400
2696+++ linux-2.6.39.1/arch/mips/pci/pci-ip27.c 2011-05-22 19:36:30.000000000 -0400
2697@@ -39,7 +39,7 @@ static struct bridge_controller bridges[
2698 struct bridge_controller *irq_to_bridge[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2699 int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2700
2701-extern struct pci_ops bridge_pci_ops;
2702+extern const struct pci_ops bridge_pci_ops;
2703
2704 int __cpuinit bridge_probe(nasid_t nasid, int widget_id, int masterwid)
2705 {
2706diff -urNp linux-2.6.39.1/arch/mips/pci/pci-ip32.c linux-2.6.39.1/arch/mips/pci/pci-ip32.c
2707--- linux-2.6.39.1/arch/mips/pci/pci-ip32.c 2011-05-19 00:06:34.000000000 -0400
2708+++ linux-2.6.39.1/arch/mips/pci/pci-ip32.c 2011-05-22 19:36:30.000000000 -0400
2709@@ -82,7 +82,7 @@ static irqreturn_t macepci_error(int irq
2710 }
2711
2712
2713-extern struct pci_ops mace_pci_ops;
2714+extern const struct pci_ops mace_pci_ops;
2715 #ifdef CONFIG_64BIT
2716 static struct resource mace_pci_mem_resource = {
2717 .name = "SGI O2 PCI MEM",
2718diff -urNp linux-2.6.39.1/arch/mips/pci/pci-lasat.c linux-2.6.39.1/arch/mips/pci/pci-lasat.c
2719--- linux-2.6.39.1/arch/mips/pci/pci-lasat.c 2011-05-19 00:06:34.000000000 -0400
2720+++ linux-2.6.39.1/arch/mips/pci/pci-lasat.c 2011-05-22 19:36:30.000000000 -0400
2721@@ -14,8 +14,8 @@
2722
2723 #include <irq.h>
2724
2725-extern struct pci_ops nile4_pci_ops;
2726-extern struct pci_ops gt64xxx_pci0_ops;
2727+extern const struct pci_ops nile4_pci_ops;
2728+extern const struct pci_ops gt64xxx_pci0_ops;
2729 static struct resource lasat_pci_mem_resource = {
2730 .name = "LASAT PCI MEM",
2731 .start = 0x18000000,
2732diff -urNp linux-2.6.39.1/arch/mips/pci/pci-octeon.c linux-2.6.39.1/arch/mips/pci/pci-octeon.c
2733--- linux-2.6.39.1/arch/mips/pci/pci-octeon.c 2011-05-19 00:06:34.000000000 -0400
2734+++ linux-2.6.39.1/arch/mips/pci/pci-octeon.c 2011-05-22 19:36:30.000000000 -0400
2735@@ -334,7 +334,7 @@ static int octeon_write_config(struct pc
2736 }
2737
2738
2739-static struct pci_ops octeon_pci_ops = {
2740+static const struct pci_ops octeon_pci_ops = {
2741 octeon_read_config,
2742 octeon_write_config,
2743 };
2744diff -urNp linux-2.6.39.1/arch/mips/pci/pci-rc32434.c linux-2.6.39.1/arch/mips/pci/pci-rc32434.c
2745--- linux-2.6.39.1/arch/mips/pci/pci-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2746+++ linux-2.6.39.1/arch/mips/pci/pci-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2747@@ -75,7 +75,7 @@ static struct resource rc32434_res_pci_i
2748 .flags = IORESOURCE_IO,
2749 };
2750
2751-extern struct pci_ops rc32434_pci_ops;
2752+extern const struct pci_ops rc32434_pci_ops;
2753
2754 #define PCI_MEM1_START PCI_ADDR_START
2755 #define PCI_MEM1_END (PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1)
2756diff -urNp linux-2.6.39.1/arch/mips/pci/pci-sb1250.c linux-2.6.39.1/arch/mips/pci/pci-sb1250.c
2757--- linux-2.6.39.1/arch/mips/pci/pci-sb1250.c 2011-05-19 00:06:34.000000000 -0400
2758+++ linux-2.6.39.1/arch/mips/pci/pci-sb1250.c 2011-05-22 19:36:30.000000000 -0400
2759@@ -181,7 +181,7 @@ static int sb1250_pcibios_write(struct p
2760 return PCIBIOS_SUCCESSFUL;
2761 }
2762
2763-struct pci_ops sb1250_pci_ops = {
2764+const struct pci_ops sb1250_pci_ops = {
2765 .read = sb1250_pcibios_read,
2766 .write = sb1250_pcibios_write,
2767 };
2768diff -urNp linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c
2769--- linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2770+++ linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2771@@ -36,7 +36,7 @@
2772
2773 #include "pci-vr41xx.h"
2774
2775-extern struct pci_ops vr41xx_pci_ops;
2776+extern const struct pci_ops vr41xx_pci_ops;
2777
2778 static void __iomem *pciu_base;
2779
2780diff -urNp linux-2.6.39.1/arch/mips/pci/pci-yosemite.c linux-2.6.39.1/arch/mips/pci/pci-yosemite.c
2781--- linux-2.6.39.1/arch/mips/pci/pci-yosemite.c 2011-05-19 00:06:34.000000000 -0400
2782+++ linux-2.6.39.1/arch/mips/pci/pci-yosemite.c 2011-05-22 19:36:30.000000000 -0400
2783@@ -11,7 +11,7 @@
2784 #include <linux/pci.h>
2785 #include <asm/titan_dep.h>
2786
2787-extern struct pci_ops titan_pci_ops;
2788+extern const struct pci_ops titan_pci_ops;
2789
2790 static struct resource py_mem_resource = {
2791 .start = 0xe0000000UL,
2792diff -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
2793--- linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-19 00:06:34.000000000 -0400
2794+++ linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-22 19:36:30.000000000 -0400
2795@@ -366,7 +366,7 @@ resource_size_t pcibios_align_resource(v
2796 return start;
2797 }
2798
2799-struct pci_ops titan_pci_ops = {
2800+const struct pci_ops titan_pci_ops = {
2801 titan_ht_config_read_byte,
2802 titan_ht_config_read_word,
2803 titan_ht_config_read_dword,
2804diff -urNp linux-2.6.39.1/arch/mips/pnx8550/common/pci.c linux-2.6.39.1/arch/mips/pnx8550/common/pci.c
2805--- linux-2.6.39.1/arch/mips/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2806+++ linux-2.6.39.1/arch/mips/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2807@@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2808 .flags = IORESOURCE_MEM
2809 };
2810
2811-extern struct pci_ops pnx8550_pci_ops;
2812+extern const struct pci_ops pnx8550_pci_ops;
2813
2814 static struct pci_controller pnx8550_controller = {
2815 .pci_ops = &pnx8550_pci_ops,
2816diff -urNp linux-2.6.39.1/arch/mips/sni/pcimt.c linux-2.6.39.1/arch/mips/sni/pcimt.c
2817--- linux-2.6.39.1/arch/mips/sni/pcimt.c 2011-05-19 00:06:34.000000000 -0400
2818+++ linux-2.6.39.1/arch/mips/sni/pcimt.c 2011-05-22 19:36:30.000000000 -0400
2819@@ -183,7 +183,7 @@ static void __init sni_pcimt_resource_in
2820 request_resource(&sni_mem_resource, pcimt_mem_resources + i);
2821 }
2822
2823-extern struct pci_ops sni_pcimt_ops;
2824+extern const struct pci_ops sni_pcimt_ops;
2825
2826 static struct pci_controller sni_controller = {
2827 .pci_ops = &sni_pcimt_ops,
2828diff -urNp linux-2.6.39.1/arch/mips/sni/pcit.c linux-2.6.39.1/arch/mips/sni/pcit.c
2829--- linux-2.6.39.1/arch/mips/sni/pcit.c 2011-05-19 00:06:34.000000000 -0400
2830+++ linux-2.6.39.1/arch/mips/sni/pcit.c 2011-05-22 19:36:30.000000000 -0400
2831@@ -145,7 +145,7 @@ static void __init sni_pcit_resource_ini
2832 }
2833
2834
2835-extern struct pci_ops sni_pcit_ops;
2836+extern const struct pci_ops sni_pcit_ops;
2837
2838 static struct pci_controller sni_pcit_controller = {
2839 .pci_ops = &sni_pcit_ops,
2840diff -urNp linux-2.6.39.1/arch/mips/wrppmc/pci.c linux-2.6.39.1/arch/mips/wrppmc/pci.c
2841--- linux-2.6.39.1/arch/mips/wrppmc/pci.c 2011-05-19 00:06:34.000000000 -0400
2842+++ linux-2.6.39.1/arch/mips/wrppmc/pci.c 2011-05-22 19:36:30.000000000 -0400
2843@@ -14,7 +14,7 @@
2844
2845 #include <asm/gt64120.h>
2846
2847-extern struct pci_ops gt64xxx_pci0_ops;
2848+extern const struct pci_ops gt64xxx_pci0_ops;
2849
2850 static struct resource pci0_io_resource = {
2851 .name = "pci_0 io",
2852diff -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
2853--- linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-19 00:06:34.000000000 -0400
2854+++ linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-22 19:36:30.000000000 -0400
2855@@ -39,7 +39,7 @@ extern void pcibios_resource_survey(void
2856
2857 extern int pcibios_last_bus;
2858 extern struct pci_bus *pci_root_bus;
2859-extern struct pci_ops *pci_root_ops;
2860+extern const struct pci_ops *pci_root_ops;
2861
2862 extern struct irq_routing_table *pcibios_get_irq_routing_table(void);
2863 extern int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
2864diff -urNp linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c
2865--- linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c 2011-05-19 00:06:34.000000000 -0400
2866+++ linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c 2011-05-22 19:36:30.000000000 -0400
2867@@ -24,7 +24,7 @@ unsigned int pci_probe = 1;
2868
2869 int pcibios_last_bus = -1;
2870 struct pci_bus *pci_root_bus;
2871-struct pci_ops *pci_root_ops;
2872+const struct pci_ops *pci_root_ops;
2873
2874 /*
2875 * The accessible PCI window does not cover the entire CPU address space, but
2876@@ -274,7 +274,7 @@ static int pci_ampci_write_config(struct
2877 }
2878 }
2879
2880-static struct pci_ops pci_direct_ampci = {
2881+static const struct pci_ops pci_direct_ampci = {
2882 pci_ampci_read_config,
2883 pci_ampci_write_config,
2884 };
2885@@ -289,7 +289,7 @@ static struct pci_ops pci_direct_ampci =
2886 * This should be close to trivial, but it isn't, because there are buggy
2887 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
2888 */
2889-static int __init pci_sanity_check(struct pci_ops *o)
2890+static int __init pci_sanity_check(const struct pci_ops *o)
2891 {
2892 struct pci_bus bus; /* Fake bus and device */
2893 u32 x;
2894diff -urNp linux-2.6.39.1/arch/parisc/include/asm/elf.h linux-2.6.39.1/arch/parisc/include/asm/elf.h
2895--- linux-2.6.39.1/arch/parisc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2896+++ linux-2.6.39.1/arch/parisc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2897@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration..
2898
2899 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2900
2901+#ifdef CONFIG_PAX_ASLR
2902+#define PAX_ELF_ET_DYN_BASE 0x10000UL
2903+
2904+#define PAX_DELTA_MMAP_LEN 16
2905+#define PAX_DELTA_STACK_LEN 16
2906+#endif
2907+
2908 /* This yields a mask that user programs can use to figure out what
2909 instruction set this CPU supports. This could be done in user space,
2910 but it's not easy, and we've already done it here. */
2911diff -urNp linux-2.6.39.1/arch/parisc/include/asm/pgtable.h linux-2.6.39.1/arch/parisc/include/asm/pgtable.h
2912--- linux-2.6.39.1/arch/parisc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
2913+++ linux-2.6.39.1/arch/parisc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
2914@@ -207,6 +207,17 @@ struct vm_area_struct;
2915 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2916 #define PAGE_COPY PAGE_EXECREAD
2917 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2918+
2919+#ifdef CONFIG_PAX_PAGEEXEC
2920+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2921+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2922+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2923+#else
2924+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2925+# define PAGE_COPY_NOEXEC PAGE_COPY
2926+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2927+#endif
2928+
2929 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2930 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2931 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2932diff -urNp linux-2.6.39.1/arch/parisc/kernel/module.c linux-2.6.39.1/arch/parisc/kernel/module.c
2933--- linux-2.6.39.1/arch/parisc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
2934+++ linux-2.6.39.1/arch/parisc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
2935@@ -96,16 +96,38 @@
2936
2937 /* three functions to determine where in the module core
2938 * or init pieces the location is */
2939+static inline int in_init_rx(struct module *me, void *loc)
2940+{
2941+ return (loc >= me->module_init_rx &&
2942+ loc < (me->module_init_rx + me->init_size_rx));
2943+}
2944+
2945+static inline int in_init_rw(struct module *me, void *loc)
2946+{
2947+ return (loc >= me->module_init_rw &&
2948+ loc < (me->module_init_rw + me->init_size_rw));
2949+}
2950+
2951 static inline int in_init(struct module *me, void *loc)
2952 {
2953- return (loc >= me->module_init &&
2954- loc <= (me->module_init + me->init_size));
2955+ return in_init_rx(me, loc) || in_init_rw(me, loc);
2956+}
2957+
2958+static inline int in_core_rx(struct module *me, void *loc)
2959+{
2960+ return (loc >= me->module_core_rx &&
2961+ loc < (me->module_core_rx + me->core_size_rx));
2962+}
2963+
2964+static inline int in_core_rw(struct module *me, void *loc)
2965+{
2966+ return (loc >= me->module_core_rw &&
2967+ loc < (me->module_core_rw + me->core_size_rw));
2968 }
2969
2970 static inline int in_core(struct module *me, void *loc)
2971 {
2972- return (loc >= me->module_core &&
2973- loc <= (me->module_core + me->core_size));
2974+ return in_core_rx(me, loc) || in_core_rw(me, loc);
2975 }
2976
2977 static inline int in_local(struct module *me, void *loc)
2978@@ -365,13 +387,13 @@ int module_frob_arch_sections(CONST Elf_
2979 }
2980
2981 /* align things a bit */
2982- me->core_size = ALIGN(me->core_size, 16);
2983- me->arch.got_offset = me->core_size;
2984- me->core_size += gots * sizeof(struct got_entry);
2985-
2986- me->core_size = ALIGN(me->core_size, 16);
2987- me->arch.fdesc_offset = me->core_size;
2988- me->core_size += fdescs * sizeof(Elf_Fdesc);
2989+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
2990+ me->arch.got_offset = me->core_size_rw;
2991+ me->core_size_rw += gots * sizeof(struct got_entry);
2992+
2993+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
2994+ me->arch.fdesc_offset = me->core_size_rw;
2995+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2996
2997 me->arch.got_max = gots;
2998 me->arch.fdesc_max = fdescs;
2999@@ -389,7 +411,7 @@ static Elf64_Word get_got(struct module
3000
3001 BUG_ON(value == 0);
3002
3003- got = me->module_core + me->arch.got_offset;
3004+ got = me->module_core_rw + me->arch.got_offset;
3005 for (i = 0; got[i].addr; i++)
3006 if (got[i].addr == value)
3007 goto out;
3008@@ -407,7 +429,7 @@ static Elf64_Word get_got(struct module
3009 #ifdef CONFIG_64BIT
3010 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3011 {
3012- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3013+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3014
3015 if (!value) {
3016 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3017@@ -425,7 +447,7 @@ static Elf_Addr get_fdesc(struct module
3018
3019 /* Create new one */
3020 fdesc->addr = value;
3021- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3022+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3023 return (Elf_Addr)fdesc;
3024 }
3025 #endif /* CONFIG_64BIT */
3026@@ -849,7 +871,7 @@ register_unwind_table(struct module *me,
3027
3028 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3029 end = table + sechdrs[me->arch.unwind_section].sh_size;
3030- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3031+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3032
3033 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3034 me->arch.unwind_section, table, end, gp);
3035diff -urNp linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c
3036--- linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c 2011-05-19 00:06:34.000000000 -0400
3037+++ linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c 2011-05-22 19:36:30.000000000 -0400
3038@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
3039 /* At this point: (!vma || addr < vma->vm_end). */
3040 if (TASK_SIZE - len < addr)
3041 return -ENOMEM;
3042- if (!vma || addr + len <= vma->vm_start)
3043+ if (check_heap_stack_gap(vma, addr, len))
3044 return addr;
3045 addr = vma->vm_end;
3046 }
3047@@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
3048 /* At this point: (!vma || addr < vma->vm_end). */
3049 if (TASK_SIZE - len < addr)
3050 return -ENOMEM;
3051- if (!vma || addr + len <= vma->vm_start)
3052+ if (check_heap_stack_gap(vma, addr, len))
3053 return addr;
3054 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3055 if (addr < vma->vm_end) /* handle wraparound */
3056@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
3057 if (flags & MAP_FIXED)
3058 return addr;
3059 if (!addr)
3060- addr = TASK_UNMAPPED_BASE;
3061+ addr = current->mm->mmap_base;
3062
3063 if (filp) {
3064 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3065diff -urNp linux-2.6.39.1/arch/parisc/kernel/traps.c linux-2.6.39.1/arch/parisc/kernel/traps.c
3066--- linux-2.6.39.1/arch/parisc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
3067+++ linux-2.6.39.1/arch/parisc/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
3068@@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
3069
3070 down_read(&current->mm->mmap_sem);
3071 vma = find_vma(current->mm,regs->iaoq[0]);
3072- if (vma && (regs->iaoq[0] >= vma->vm_start)
3073- && (vma->vm_flags & VM_EXEC)) {
3074-
3075+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3076 fault_address = regs->iaoq[0];
3077 fault_space = regs->iasq[0];
3078
3079diff -urNp linux-2.6.39.1/arch/parisc/mm/fault.c linux-2.6.39.1/arch/parisc/mm/fault.c
3080--- linux-2.6.39.1/arch/parisc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
3081+++ linux-2.6.39.1/arch/parisc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
3082@@ -15,6 +15,7 @@
3083 #include <linux/sched.h>
3084 #include <linux/interrupt.h>
3085 #include <linux/module.h>
3086+#include <linux/unistd.h>
3087
3088 #include <asm/uaccess.h>
3089 #include <asm/traps.h>
3090@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
3091 static unsigned long
3092 parisc_acctyp(unsigned long code, unsigned int inst)
3093 {
3094- if (code == 6 || code == 16)
3095+ if (code == 6 || code == 7 || code == 16)
3096 return VM_EXEC;
3097
3098 switch (inst & 0xf0000000) {
3099@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
3100 }
3101 #endif
3102
3103+#ifdef CONFIG_PAX_PAGEEXEC
3104+/*
3105+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3106+ *
3107+ * returns 1 when task should be killed
3108+ * 2 when rt_sigreturn trampoline was detected
3109+ * 3 when unpatched PLT trampoline was detected
3110+ */
3111+static int pax_handle_fetch_fault(struct pt_regs *regs)
3112+{
3113+
3114+#ifdef CONFIG_PAX_EMUPLT
3115+ int err;
3116+
3117+ do { /* PaX: unpatched PLT emulation */
3118+ unsigned int bl, depwi;
3119+
3120+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3121+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3122+
3123+ if (err)
3124+ break;
3125+
3126+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3127+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3128+
3129+ err = get_user(ldw, (unsigned int *)addr);
3130+ err |= get_user(bv, (unsigned int *)(addr+4));
3131+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3132+
3133+ if (err)
3134+ break;
3135+
3136+ if (ldw == 0x0E801096U &&
3137+ bv == 0xEAC0C000U &&
3138+ ldw2 == 0x0E881095U)
3139+ {
3140+ unsigned int resolver, map;
3141+
3142+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3143+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3144+ if (err)
3145+ break;
3146+
3147+ regs->gr[20] = instruction_pointer(regs)+8;
3148+ regs->gr[21] = map;
3149+ regs->gr[22] = resolver;
3150+ regs->iaoq[0] = resolver | 3UL;
3151+ regs->iaoq[1] = regs->iaoq[0] + 4;
3152+ return 3;
3153+ }
3154+ }
3155+ } while (0);
3156+#endif
3157+
3158+#ifdef CONFIG_PAX_EMUTRAMP
3159+
3160+#ifndef CONFIG_PAX_EMUSIGRT
3161+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3162+ return 1;
3163+#endif
3164+
3165+ do { /* PaX: rt_sigreturn emulation */
3166+ unsigned int ldi1, ldi2, bel, nop;
3167+
3168+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3169+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3170+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3171+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3172+
3173+ if (err)
3174+ break;
3175+
3176+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3177+ ldi2 == 0x3414015AU &&
3178+ bel == 0xE4008200U &&
3179+ nop == 0x08000240U)
3180+ {
3181+ regs->gr[25] = (ldi1 & 2) >> 1;
3182+ regs->gr[20] = __NR_rt_sigreturn;
3183+ regs->gr[31] = regs->iaoq[1] + 16;
3184+ regs->sr[0] = regs->iasq[1];
3185+ regs->iaoq[0] = 0x100UL;
3186+ regs->iaoq[1] = regs->iaoq[0] + 4;
3187+ regs->iasq[0] = regs->sr[2];
3188+ regs->iasq[1] = regs->sr[2];
3189+ return 2;
3190+ }
3191+ } while (0);
3192+#endif
3193+
3194+ return 1;
3195+}
3196+
3197+void pax_report_insns(void *pc, void *sp)
3198+{
3199+ unsigned long i;
3200+
3201+ printk(KERN_ERR "PAX: bytes at PC: ");
3202+ for (i = 0; i < 5; i++) {
3203+ unsigned int c;
3204+ if (get_user(c, (unsigned int *)pc+i))
3205+ printk(KERN_CONT "???????? ");
3206+ else
3207+ printk(KERN_CONT "%08x ", c);
3208+ }
3209+ printk("\n");
3210+}
3211+#endif
3212+
3213 int fixup_exception(struct pt_regs *regs)
3214 {
3215 const struct exception_table_entry *fix;
3216@@ -192,8 +303,33 @@ good_area:
3217
3218 acc_type = parisc_acctyp(code,regs->iir);
3219
3220- if ((vma->vm_flags & acc_type) != acc_type)
3221+ if ((vma->vm_flags & acc_type) != acc_type) {
3222+
3223+#ifdef CONFIG_PAX_PAGEEXEC
3224+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3225+ (address & ~3UL) == instruction_pointer(regs))
3226+ {
3227+ up_read(&mm->mmap_sem);
3228+ switch (pax_handle_fetch_fault(regs)) {
3229+
3230+#ifdef CONFIG_PAX_EMUPLT
3231+ case 3:
3232+ return;
3233+#endif
3234+
3235+#ifdef CONFIG_PAX_EMUTRAMP
3236+ case 2:
3237+ return;
3238+#endif
3239+
3240+ }
3241+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3242+ do_group_exit(SIGKILL);
3243+ }
3244+#endif
3245+
3246 goto bad_area;
3247+ }
3248
3249 /*
3250 * If for any reason at all we couldn't handle the fault, make
3251diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/device.h linux-2.6.39.1/arch/powerpc/include/asm/device.h
3252--- linux-2.6.39.1/arch/powerpc/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
3253+++ linux-2.6.39.1/arch/powerpc/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
3254@@ -17,7 +17,7 @@ struct device_node;
3255 */
3256 struct dev_archdata {
3257 /* DMA operations on that device */
3258- struct dma_map_ops *dma_ops;
3259+ const struct dma_map_ops *dma_ops;
3260
3261 /*
3262 * When an iommu is in use, dma_data is used as a ptr to the base of the
3263diff -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
3264--- linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3265+++ linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
3266@@ -67,12 +67,13 @@ static inline unsigned long device_to_ma
3267 /*
3268 * Available generic sets of operations
3269 */
3270+/* cannot be const */
3271 #ifdef CONFIG_PPC64
3272-extern struct dma_map_ops dma_iommu_ops;
3273+extern const struct dma_map_ops dma_iommu_ops;
3274 #endif
3275-extern struct dma_map_ops dma_direct_ops;
3276+extern const struct dma_map_ops dma_direct_ops;
3277
3278-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3279+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3280 {
3281 /* We don't handle the NULL dev case for ISA for now. We could
3282 * do it via an out of line call but it is not needed for now. The
3283@@ -85,7 +86,7 @@ static inline struct dma_map_ops *get_dm
3284 return dev->archdata.dma_ops;
3285 }
3286
3287-static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
3288+static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
3289 {
3290 dev->archdata.dma_ops = ops;
3291 }
3292@@ -119,7 +120,7 @@ static inline void set_dma_offset(struct
3293
3294 static inline int dma_supported(struct device *dev, u64 mask)
3295 {
3296- struct dma_map_ops *dma_ops = get_dma_ops(dev);
3297+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3298
3299 if (unlikely(dma_ops == NULL))
3300 return 0;
3301@@ -133,7 +134,7 @@ extern int dma_set_mask(struct device *d
3302 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3303 dma_addr_t *dma_handle, gfp_t flag)
3304 {
3305- struct dma_map_ops *dma_ops = get_dma_ops(dev);
3306+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3307 void *cpu_addr;
3308
3309 BUG_ON(!dma_ops);
3310@@ -148,7 +149,7 @@ static inline void *dma_alloc_coherent(s
3311 static inline void dma_free_coherent(struct device *dev, size_t size,
3312 void *cpu_addr, dma_addr_t dma_handle)
3313 {
3314- struct dma_map_ops *dma_ops = get_dma_ops(dev);
3315+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3316
3317 BUG_ON(!dma_ops);
3318
3319@@ -159,7 +160,7 @@ static inline void dma_free_coherent(str
3320
3321 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
3322 {
3323- struct dma_map_ops *dma_ops = get_dma_ops(dev);
3324+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3325
3326 if (dma_ops->mapping_error)
3327 return dma_ops->mapping_error(dev, dma_addr);
3328diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/elf.h linux-2.6.39.1/arch/powerpc/include/asm/elf.h
3329--- linux-2.6.39.1/arch/powerpc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
3330+++ linux-2.6.39.1/arch/powerpc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
3331@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
3332 the loader. We need to make sure that it is out of the way of the program
3333 that it will "exec", and that there is sufficient room for the brk. */
3334
3335-extern unsigned long randomize_et_dyn(unsigned long base);
3336-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3337+#define ELF_ET_DYN_BASE (0x20000000)
3338+
3339+#ifdef CONFIG_PAX_ASLR
3340+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3341+
3342+#ifdef __powerpc64__
3343+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3344+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3345+#else
3346+#define PAX_DELTA_MMAP_LEN 15
3347+#define PAX_DELTA_STACK_LEN 15
3348+#endif
3349+#endif
3350
3351 /*
3352 * Our registers are always unsigned longs, whether we're a 32 bit
3353@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(s
3354 (0x7ff >> (PAGE_SHIFT - 12)) : \
3355 (0x3ffff >> (PAGE_SHIFT - 12)))
3356
3357-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3358-#define arch_randomize_brk arch_randomize_brk
3359-
3360 #endif /* __KERNEL__ */
3361
3362 /*
3363diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/iommu.h linux-2.6.39.1/arch/powerpc/include/asm/iommu.h
3364--- linux-2.6.39.1/arch/powerpc/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
3365+++ linux-2.6.39.1/arch/powerpc/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
3366@@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
3367 extern void iommu_init_early_dart(void);
3368 extern void iommu_init_early_pasemi(void);
3369
3370+/* dma-iommu.c */
3371+extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
3372+
3373 #ifdef CONFIG_PCI
3374 extern void pci_iommu_init(void);
3375 extern void pci_direct_iommu_init(void);
3376diff -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
3377--- linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
3378+++ linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
3379@@ -27,6 +27,7 @@ enum km_type {
3380 KM_PPC_SYNC_PAGE,
3381 KM_PPC_SYNC_ICACHE,
3382 KM_KDB,
3383+ KM_CLEARPAGE,
3384 KM_TYPE_NR
3385 };
3386
3387diff -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
3388--- linux-2.6.39.1/arch/powerpc/include/asm/page_64.h 2011-05-19 00:06:34.000000000 -0400
3389+++ linux-2.6.39.1/arch/powerpc/include/asm/page_64.h 2011-05-22 19:36:30.000000000 -0400
3390@@ -172,15 +172,18 @@ do { \
3391 * stack by default, so in the absence of a PT_GNU_STACK program header
3392 * we turn execute permission off.
3393 */
3394-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3395- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3396+#define VM_STACK_DEFAULT_FLAGS32 \
3397+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3398+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3399
3400 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3401 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3402
3403+#ifndef CONFIG_PAX_PAGEEXEC
3404 #define VM_STACK_DEFAULT_FLAGS \
3405 (is_32bit_task() ? \
3406 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3407+#endif
3408
3409 #include <asm-generic/getorder.h>
3410
3411diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/page.h linux-2.6.39.1/arch/powerpc/include/asm/page.h
3412--- linux-2.6.39.1/arch/powerpc/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
3413+++ linux-2.6.39.1/arch/powerpc/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
3414@@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
3415 * and needs to be executable. This means the whole heap ends
3416 * up being executable.
3417 */
3418-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3419- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3420+#define VM_DATA_DEFAULT_FLAGS32 \
3421+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3422+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3423
3424 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3425 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3426@@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
3427 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3428 #endif
3429
3430+#define ktla_ktva(addr) (addr)
3431+#define ktva_ktla(addr) (addr)
3432+
3433 #ifndef __ASSEMBLY__
3434
3435 #undef STRICT_MM_TYPECHECKS
3436diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pci.h linux-2.6.39.1/arch/powerpc/include/asm/pci.h
3437--- linux-2.6.39.1/arch/powerpc/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
3438+++ linux-2.6.39.1/arch/powerpc/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
3439@@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
3440 }
3441
3442 #ifdef CONFIG_PCI
3443-extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
3444-extern struct dma_map_ops *get_pci_dma_ops(void);
3445+extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
3446+extern const struct dma_map_ops *get_pci_dma_ops(void);
3447 #else /* CONFIG_PCI */
3448 #define set_pci_dma_ops(d)
3449 #define get_pci_dma_ops() NULL
3450diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h
3451--- linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
3452+++ linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
3453@@ -2,6 +2,7 @@
3454 #define _ASM_POWERPC_PGTABLE_H
3455 #ifdef __KERNEL__
3456
3457+#include <linux/const.h>
3458 #ifndef __ASSEMBLY__
3459 #include <asm/processor.h> /* For TASK_SIZE */
3460 #include <asm/mmu.h>
3461diff -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
3462--- linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h 2011-05-19 00:06:34.000000000 -0400
3463+++ linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h 2011-05-22 19:36:30.000000000 -0400
3464@@ -21,6 +21,7 @@
3465 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3466 #define _PAGE_USER 0x004 /* usermode access allowed */
3467 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3468+#define _PAGE_EXEC _PAGE_GUARDED
3469 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3470 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3471 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3472diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/reg.h linux-2.6.39.1/arch/powerpc/include/asm/reg.h
3473--- linux-2.6.39.1/arch/powerpc/include/asm/reg.h 2011-05-19 00:06:34.000000000 -0400
3474+++ linux-2.6.39.1/arch/powerpc/include/asm/reg.h 2011-05-22 19:36:30.000000000 -0400
3475@@ -201,6 +201,7 @@
3476 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3477 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3478 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3479+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3480 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3481 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3482 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3483diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h
3484--- linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h 2011-05-19 00:06:34.000000000 -0400
3485+++ linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h 2011-05-22 19:36:30.000000000 -0400
3486@@ -13,7 +13,7 @@
3487
3488 #include <linux/swiotlb.h>
3489
3490-extern struct dma_map_ops swiotlb_dma_ops;
3491+extern const struct dma_map_ops swiotlb_dma_ops;
3492
3493 static inline void dma_mark_clean(void *addr, size_t size) {}
3494
3495diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/system.h linux-2.6.39.1/arch/powerpc/include/asm/system.h
3496--- linux-2.6.39.1/arch/powerpc/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
3497+++ linux-2.6.39.1/arch/powerpc/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
3498@@ -533,7 +533,7 @@ __cmpxchg_local(volatile void *ptr, unsi
3499 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3500 #endif
3501
3502-extern unsigned long arch_align_stack(unsigned long sp);
3503+#define arch_align_stack(x) ((x) & ~0xfUL)
3504
3505 /* Used in very early kernel initialization. */
3506 extern unsigned long reloc_offset(void);
3507diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h
3508--- linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
3509+++ linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
3510@@ -13,6 +13,8 @@
3511 #define VERIFY_READ 0
3512 #define VERIFY_WRITE 1
3513
3514+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3515+
3516 /*
3517 * The fs value determines whether argument validity checking should be
3518 * performed or not. If get_fs() == USER_DS, checking is performed, with
3519@@ -327,52 +329,6 @@ do { \
3520 extern unsigned long __copy_tofrom_user(void __user *to,
3521 const void __user *from, unsigned long size);
3522
3523-#ifndef __powerpc64__
3524-
3525-static inline unsigned long copy_from_user(void *to,
3526- const void __user *from, unsigned long n)
3527-{
3528- unsigned long over;
3529-
3530- if (access_ok(VERIFY_READ, from, n))
3531- return __copy_tofrom_user((__force void __user *)to, from, n);
3532- if ((unsigned long)from < TASK_SIZE) {
3533- over = (unsigned long)from + n - TASK_SIZE;
3534- return __copy_tofrom_user((__force void __user *)to, from,
3535- n - over) + over;
3536- }
3537- return n;
3538-}
3539-
3540-static inline unsigned long copy_to_user(void __user *to,
3541- const void *from, unsigned long n)
3542-{
3543- unsigned long over;
3544-
3545- if (access_ok(VERIFY_WRITE, to, n))
3546- return __copy_tofrom_user(to, (__force void __user *)from, n);
3547- if ((unsigned long)to < TASK_SIZE) {
3548- over = (unsigned long)to + n - TASK_SIZE;
3549- return __copy_tofrom_user(to, (__force void __user *)from,
3550- n - over) + over;
3551- }
3552- return n;
3553-}
3554-
3555-#else /* __powerpc64__ */
3556-
3557-#define __copy_in_user(to, from, size) \
3558- __copy_tofrom_user((to), (from), (size))
3559-
3560-extern unsigned long copy_from_user(void *to, const void __user *from,
3561- unsigned long n);
3562-extern unsigned long copy_to_user(void __user *to, const void *from,
3563- unsigned long n);
3564-extern unsigned long copy_in_user(void __user *to, const void __user *from,
3565- unsigned long n);
3566-
3567-#endif /* __powerpc64__ */
3568-
3569 static inline unsigned long __copy_from_user_inatomic(void *to,
3570 const void __user *from, unsigned long n)
3571 {
3572@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
3573 if (ret == 0)
3574 return 0;
3575 }
3576+
3577+ if (!__builtin_constant_p(n))
3578+ check_object_size(to, n, false);
3579+
3580 return __copy_tofrom_user((__force void __user *)to, from, n);
3581 }
3582
3583@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
3584 if (ret == 0)
3585 return 0;
3586 }
3587+
3588+ if (!__builtin_constant_p(n))
3589+ check_object_size(from, n, true);
3590+
3591 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3592 }
3593
3594@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
3595 return __copy_to_user_inatomic(to, from, size);
3596 }
3597
3598+#ifndef __powerpc64__
3599+
3600+static inline unsigned long __must_check copy_from_user(void *to,
3601+ const void __user *from, unsigned long n)
3602+{
3603+ unsigned long over;
3604+
3605+ if ((long)n < 0)
3606+ return n;
3607+
3608+ if (access_ok(VERIFY_READ, from, n)) {
3609+ if (!__builtin_constant_p(n))
3610+ check_object_size(to, n, false);
3611+ return __copy_tofrom_user((__force void __user *)to, from, n);
3612+ }
3613+ if ((unsigned long)from < TASK_SIZE) {
3614+ over = (unsigned long)from + n - TASK_SIZE;
3615+ if (!__builtin_constant_p(n - over))
3616+ check_object_size(to, n - over, false);
3617+ return __copy_tofrom_user((__force void __user *)to, from,
3618+ n - over) + over;
3619+ }
3620+ return n;
3621+}
3622+
3623+static inline unsigned long __must_check copy_to_user(void __user *to,
3624+ const void *from, unsigned long n)
3625+{
3626+ unsigned long over;
3627+
3628+ if ((long)n < 0)
3629+ return n;
3630+
3631+ if (access_ok(VERIFY_WRITE, to, n)) {
3632+ if (!__builtin_constant_p(n))
3633+ check_object_size(from, n, true);
3634+ return __copy_tofrom_user(to, (__force void __user *)from, n);
3635+ }
3636+ if ((unsigned long)to < TASK_SIZE) {
3637+ over = (unsigned long)to + n - TASK_SIZE;
3638+ if (!__builtin_constant_p(n))
3639+ check_object_size(from, n - over, true);
3640+ return __copy_tofrom_user(to, (__force void __user *)from,
3641+ n - over) + over;
3642+ }
3643+ return n;
3644+}
3645+
3646+#else /* __powerpc64__ */
3647+
3648+#define __copy_in_user(to, from, size) \
3649+ __copy_tofrom_user((to), (from), (size))
3650+
3651+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3652+{
3653+ if ((long)n < 0 || n > INT_MAX)
3654+ return n;
3655+
3656+ if (!__builtin_constant_p(n))
3657+ check_object_size(to, n, false);
3658+
3659+ if (likely(access_ok(VERIFY_READ, from, n)))
3660+ n = __copy_from_user(to, from, n);
3661+ else
3662+ memset(to, 0, n);
3663+ return n;
3664+}
3665+
3666+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3667+{
3668+ if ((long)n < 0 || n > INT_MAX)
3669+ return n;
3670+
3671+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
3672+ if (!__builtin_constant_p(n))
3673+ check_object_size(from, n, true);
3674+ n = __copy_to_user(to, from, n);
3675+ }
3676+ return n;
3677+}
3678+
3679+extern unsigned long copy_in_user(void __user *to, const void __user *from,
3680+ unsigned long n);
3681+
3682+#endif /* __powerpc64__ */
3683+
3684 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3685
3686 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3687diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma.c linux-2.6.39.1/arch/powerpc/kernel/dma.c
3688--- linux-2.6.39.1/arch/powerpc/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
3689+++ linux-2.6.39.1/arch/powerpc/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
3690@@ -136,7 +136,7 @@ static inline void dma_direct_sync_singl
3691 }
3692 #endif
3693
3694-struct dma_map_ops dma_direct_ops = {
3695+const struct dma_map_ops dma_direct_ops = {
3696 .alloc_coherent = dma_direct_alloc_coherent,
3697 .free_coherent = dma_direct_free_coherent,
3698 .map_sg = dma_direct_map_sg,
3699@@ -157,7 +157,7 @@ EXPORT_SYMBOL(dma_direct_ops);
3700
3701 int dma_set_mask(struct device *dev, u64 dma_mask)
3702 {
3703- struct dma_map_ops *dma_ops = get_dma_ops(dev);
3704+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3705
3706 if (ppc_md.dma_set_mask)
3707 return ppc_md.dma_set_mask(dev, dma_mask);
3708diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c
3709--- linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c 2011-05-19 00:06:34.000000000 -0400
3710+++ linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c 2011-05-22 19:36:30.000000000 -0400
3711@@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
3712 }
3713
3714 /* We support DMA to/from any memory page via the iommu */
3715-static int dma_iommu_dma_supported(struct device *dev, u64 mask)
3716+int dma_iommu_dma_supported(struct device *dev, u64 mask)
3717 {
3718 struct iommu_table *tbl = get_iommu_table_base(dev);
3719
3720@@ -90,7 +90,7 @@ static int dma_iommu_dma_supported(struc
3721 return 1;
3722 }
3723
3724-struct dma_map_ops dma_iommu_ops = {
3725+struct dma_map_ops dma_iommu_ops = { /* cannot be const, see arch/powerpc/platforms/cell/iommu.c */
3726 .alloc_coherent = dma_iommu_alloc_coherent,
3727 .free_coherent = dma_iommu_free_coherent,
3728 .map_sg = dma_iommu_map_sg,
3729diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c
3730--- linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
3731+++ linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
3732@@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
3733 * map_page, and unmap_page on highmem, use normal dma_ops
3734 * for everything else.
3735 */
3736-struct dma_map_ops swiotlb_dma_ops = {
3737+const struct dma_map_ops swiotlb_dma_ops = {
3738 .alloc_coherent = dma_direct_alloc_coherent,
3739 .free_coherent = dma_direct_free_coherent,
3740 .map_sg = swiotlb_map_sg_attrs,
3741diff -urNp linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S
3742--- linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S 2011-05-19 00:06:34.000000000 -0400
3743+++ linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S 2011-05-22 19:36:30.000000000 -0400
3744@@ -495,6 +495,7 @@ storage_fault_common:
3745 std r14,_DAR(r1)
3746 std r15,_DSISR(r1)
3747 addi r3,r1,STACK_FRAME_OVERHEAD
3748+ bl .save_nvgprs
3749 mr r4,r14
3750 mr r5,r15
3751 ld r14,PACA_EXGEN+EX_R14(r13)
3752@@ -504,8 +505,7 @@ storage_fault_common:
3753 cmpdi r3,0
3754 bne- 1f
3755 b .ret_from_except_lite
3756-1: bl .save_nvgprs
3757- mr r5,r3
3758+1: mr r5,r3
3759 addi r3,r1,STACK_FRAME_OVERHEAD
3760 ld r4,_DAR(r1)
3761 bl .bad_page_fault
3762diff -urNp linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S
3763--- linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S 2011-05-19 00:06:34.000000000 -0400
3764+++ linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S 2011-05-22 19:36:30.000000000 -0400
3765@@ -848,10 +848,10 @@ handle_page_fault:
3766 11: ld r4,_DAR(r1)
3767 ld r5,_DSISR(r1)
3768 addi r3,r1,STACK_FRAME_OVERHEAD
3769+ bl .save_nvgprs
3770 bl .do_page_fault
3771 cmpdi r3,0
3772 beq+ 13f
3773- bl .save_nvgprs
3774 mr r5,r3
3775 addi r3,r1,STACK_FRAME_OVERHEAD
3776 lwz r4,_DAR(r1)
3777diff -urNp linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c
3778--- linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c 2011-05-19 00:06:34.000000000 -0400
3779+++ linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c 2011-05-22 19:36:30.000000000 -0400
3780@@ -128,7 +128,7 @@ static int ibmebus_dma_supported(struct
3781 return 1;
3782 }
3783
3784-static struct dma_map_ops ibmebus_dma_ops = {
3785+static const struct dma_map_ops ibmebus_dma_ops = {
3786 .alloc_coherent = ibmebus_alloc_coherent,
3787 .free_coherent = ibmebus_free_coherent,
3788 .map_sg = ibmebus_map_sg,
3789diff -urNp linux-2.6.39.1/arch/powerpc/kernel/kgdb.c linux-2.6.39.1/arch/powerpc/kernel/kgdb.c
3790--- linux-2.6.39.1/arch/powerpc/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
3791+++ linux-2.6.39.1/arch/powerpc/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
3792@@ -422,7 +422,7 @@ int kgdb_arch_handle_exception(int vecto
3793 /*
3794 * Global data
3795 */
3796-struct kgdb_arch arch_kgdb_ops = {
3797+const struct kgdb_arch arch_kgdb_ops = {
3798 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
3799 };
3800
3801diff -urNp linux-2.6.39.1/arch/powerpc/kernel/module_32.c linux-2.6.39.1/arch/powerpc/kernel/module_32.c
3802--- linux-2.6.39.1/arch/powerpc/kernel/module_32.c 2011-05-19 00:06:34.000000000 -0400
3803+++ linux-2.6.39.1/arch/powerpc/kernel/module_32.c 2011-05-22 19:36:30.000000000 -0400
3804@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3805 me->arch.core_plt_section = i;
3806 }
3807 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3808- printk("Module doesn't contain .plt or .init.plt sections.\n");
3809+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3810 return -ENOEXEC;
3811 }
3812
3813@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
3814
3815 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3816 /* Init, or core PLT? */
3817- if (location >= mod->module_core
3818- && location < mod->module_core + mod->core_size)
3819+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3820+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3821 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3822- else
3823+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3824+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3825 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3826+ else {
3827+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3828+ return ~0UL;
3829+ }
3830
3831 /* Find this entry, or if that fails, the next avail. entry */
3832 while (entry->jump[0]) {
3833diff -urNp linux-2.6.39.1/arch/powerpc/kernel/module.c linux-2.6.39.1/arch/powerpc/kernel/module.c
3834--- linux-2.6.39.1/arch/powerpc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
3835+++ linux-2.6.39.1/arch/powerpc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
3836@@ -31,11 +31,24 @@
3837
3838 LIST_HEAD(module_bug_list);
3839
3840+#ifdef CONFIG_PAX_KERNEXEC
3841 void *module_alloc(unsigned long size)
3842 {
3843 if (size == 0)
3844 return NULL;
3845
3846+ return vmalloc(size);
3847+}
3848+
3849+void *module_alloc_exec(unsigned long size)
3850+#else
3851+void *module_alloc(unsigned long size)
3852+#endif
3853+
3854+{
3855+ if (size == 0)
3856+ return NULL;
3857+
3858 return vmalloc_exec(size);
3859 }
3860
3861@@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
3862 vfree(module_region);
3863 }
3864
3865+#ifdef CONFIG_PAX_KERNEXEC
3866+void module_free_exec(struct module *mod, void *module_region)
3867+{
3868+ module_free(mod, module_region);
3869+}
3870+#endif
3871+
3872 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3873 const Elf_Shdr *sechdrs,
3874 const char *name)
3875diff -urNp linux-2.6.39.1/arch/powerpc/kernel/pci-common.c linux-2.6.39.1/arch/powerpc/kernel/pci-common.c
3876--- linux-2.6.39.1/arch/powerpc/kernel/pci-common.c 2011-05-19 00:06:34.000000000 -0400
3877+++ linux-2.6.39.1/arch/powerpc/kernel/pci-common.c 2011-05-22 19:36:30.000000000 -0400
3878@@ -53,14 +53,14 @@ resource_size_t isa_mem_base;
3879 unsigned int ppc_pci_flags = 0;
3880
3881
3882-static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3883+static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3884
3885-void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3886+void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3887 {
3888 pci_dma_ops = dma_ops;
3889 }
3890
3891-struct dma_map_ops *get_pci_dma_ops(void)
3892+const struct dma_map_ops *get_pci_dma_ops(void)
3893 {
3894 return pci_dma_ops;
3895 }
3896@@ -1639,7 +1639,7 @@ null_write_config(struct pci_bus *bus, u
3897 return PCIBIOS_DEVICE_NOT_FOUND;
3898 }
3899
3900-static struct pci_ops null_pci_ops =
3901+static const struct pci_ops null_pci_ops =
3902 {
3903 .read = null_read_config,
3904 .write = null_write_config,
3905diff -urNp linux-2.6.39.1/arch/powerpc/kernel/process.c linux-2.6.39.1/arch/powerpc/kernel/process.c
3906--- linux-2.6.39.1/arch/powerpc/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
3907+++ linux-2.6.39.1/arch/powerpc/kernel/process.c 2011-05-22 19:41:32.000000000 -0400
3908@@ -655,8 +655,8 @@ void show_regs(struct pt_regs * regs)
3909 * Lookup NIP late so we have the best change of getting the
3910 * above info out without failing
3911 */
3912- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3913- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3914+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3915+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3916 #endif
3917 show_stack(current, (unsigned long *) regs->gpr[1]);
3918 if (!user_mode(regs))
3919@@ -1146,10 +1146,10 @@ void show_stack(struct task_struct *tsk,
3920 newsp = stack[0];
3921 ip = stack[STACK_FRAME_LR_SAVE];
3922 if (!firstframe || ip != lr) {
3923- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3924+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3925 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3926 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3927- printk(" (%pS)",
3928+ printk(" (%pA)",
3929 (void *)current->ret_stack[curr_frame].ret);
3930 curr_frame--;
3931 }
3932@@ -1169,7 +1169,7 @@ void show_stack(struct task_struct *tsk,
3933 struct pt_regs *regs = (struct pt_regs *)
3934 (sp + STACK_FRAME_OVERHEAD);
3935 lr = regs->link;
3936- printk("--- Exception: %lx at %pS\n LR = %pS\n",
3937+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
3938 regs->trap, (void *)regs->nip, (void *)lr);
3939 firstframe = 1;
3940 }
3941@@ -1244,58 +1244,3 @@ void thread_info_cache_init(void)
3942 }
3943
3944 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3945-
3946-unsigned long arch_align_stack(unsigned long sp)
3947-{
3948- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3949- sp -= get_random_int() & ~PAGE_MASK;
3950- return sp & ~0xf;
3951-}
3952-
3953-static inline unsigned long brk_rnd(void)
3954-{
3955- unsigned long rnd = 0;
3956-
3957- /* 8MB for 32bit, 1GB for 64bit */
3958- if (is_32bit_task())
3959- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3960- else
3961- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3962-
3963- return rnd << PAGE_SHIFT;
3964-}
3965-
3966-unsigned long arch_randomize_brk(struct mm_struct *mm)
3967-{
3968- unsigned long base = mm->brk;
3969- unsigned long ret;
3970-
3971-#ifdef CONFIG_PPC_STD_MMU_64
3972- /*
3973- * If we are using 1TB segments and we are allowed to randomise
3974- * the heap, we can put it above 1TB so it is backed by a 1TB
3975- * segment. Otherwise the heap will be in the bottom 1TB
3976- * which always uses 256MB segments and this may result in a
3977- * performance penalty.
3978- */
3979- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3980- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3981-#endif
3982-
3983- ret = PAGE_ALIGN(base + brk_rnd());
3984-
3985- if (ret < mm->brk)
3986- return mm->brk;
3987-
3988- return ret;
3989-}
3990-
3991-unsigned long randomize_et_dyn(unsigned long base)
3992-{
3993- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3994-
3995- if (ret < base)
3996- return base;
3997-
3998- return ret;
3999-}
4000diff -urNp linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c
4001--- linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c 2011-05-19 00:06:34.000000000 -0400
4002+++ linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c 2011-05-22 19:36:30.000000000 -0400
4003@@ -149,7 +149,7 @@ static int rtas_pci_write_config(struct
4004 return PCIBIOS_DEVICE_NOT_FOUND;
4005 }
4006
4007-static struct pci_ops rtas_pci_ops = {
4008+static const struct pci_ops rtas_pci_ops = {
4009 .read = rtas_pci_read_config,
4010 .write = rtas_pci_write_config,
4011 };
4012diff -urNp linux-2.6.39.1/arch/powerpc/kernel/signal_32.c linux-2.6.39.1/arch/powerpc/kernel/signal_32.c
4013--- linux-2.6.39.1/arch/powerpc/kernel/signal_32.c 2011-05-19 00:06:34.000000000 -0400
4014+++ linux-2.6.39.1/arch/powerpc/kernel/signal_32.c 2011-05-22 19:36:30.000000000 -0400
4015@@ -858,7 +858,7 @@ int handle_rt_signal32(unsigned long sig
4016 /* Save user registers on the stack */
4017 frame = &rt_sf->uc.uc_mcontext;
4018 addr = frame;
4019- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4020+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4021 if (save_user_regs(regs, frame, 0, 1))
4022 goto badframe;
4023 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4024diff -urNp linux-2.6.39.1/arch/powerpc/kernel/signal_64.c linux-2.6.39.1/arch/powerpc/kernel/signal_64.c
4025--- linux-2.6.39.1/arch/powerpc/kernel/signal_64.c 2011-05-19 00:06:34.000000000 -0400
4026+++ linux-2.6.39.1/arch/powerpc/kernel/signal_64.c 2011-05-22 19:36:30.000000000 -0400
4027@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
4028 current->thread.fpscr.val = 0;
4029
4030 /* Set up to return from userspace. */
4031- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4032+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4033 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4034 } else {
4035 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4036diff -urNp linux-2.6.39.1/arch/powerpc/kernel/traps.c linux-2.6.39.1/arch/powerpc/kernel/traps.c
4037--- linux-2.6.39.1/arch/powerpc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
4038+++ linux-2.6.39.1/arch/powerpc/kernel/traps.c 2011-06-13 21:33:04.000000000 -0400
4039@@ -96,6 +96,8 @@ static void pmac_backlight_unblank(void)
4040 static inline void pmac_backlight_unblank(void) { }
4041 #endif
4042
4043+extern void gr_handle_kernel_exploit(void);
4044+
4045 int die(const char *str, struct pt_regs *regs, long err)
4046 {
4047 static struct {
4048@@ -170,6 +172,8 @@ int die(const char *str, struct pt_regs
4049 if (panic_on_oops)
4050 panic("Fatal exception");
4051
4052+ gr_handle_kernel_exploit();
4053+
4054 oops_exit();
4055 do_exit(err);
4056
4057diff -urNp linux-2.6.39.1/arch/powerpc/kernel/vdso.c linux-2.6.39.1/arch/powerpc/kernel/vdso.c
4058--- linux-2.6.39.1/arch/powerpc/kernel/vdso.c 2011-05-19 00:06:34.000000000 -0400
4059+++ linux-2.6.39.1/arch/powerpc/kernel/vdso.c 2011-05-22 19:36:30.000000000 -0400
4060@@ -36,6 +36,7 @@
4061 #include <asm/firmware.h>
4062 #include <asm/vdso.h>
4063 #include <asm/vdso_datapage.h>
4064+#include <asm/mman.h>
4065
4066 #include "setup.h"
4067
4068@@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
4069 vdso_base = VDSO32_MBASE;
4070 #endif
4071
4072- current->mm->context.vdso_base = 0;
4073+ current->mm->context.vdso_base = ~0UL;
4074
4075 /* vDSO has a problem and was disabled, just don't "enable" it for the
4076 * process
4077@@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
4078 vdso_base = get_unmapped_area(NULL, vdso_base,
4079 (vdso_pages << PAGE_SHIFT) +
4080 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4081- 0, 0);
4082+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4083 if (IS_ERR_VALUE(vdso_base)) {
4084 rc = vdso_base;
4085 goto fail_mmapsem;
4086diff -urNp linux-2.6.39.1/arch/powerpc/kernel/vio.c linux-2.6.39.1/arch/powerpc/kernel/vio.c
4087--- linux-2.6.39.1/arch/powerpc/kernel/vio.c 2011-05-19 00:06:34.000000000 -0400
4088+++ linux-2.6.39.1/arch/powerpc/kernel/vio.c 2011-05-22 19:36:30.000000000 -0400
4089@@ -605,11 +605,12 @@ static int vio_dma_iommu_dma_supported(s
4090 return dma_iommu_ops.dma_supported(dev, mask);
4091 }
4092
4093-struct dma_map_ops vio_dma_mapping_ops = {
4094+const struct dma_map_ops vio_dma_mapping_ops = {
4095 .alloc_coherent = vio_dma_iommu_alloc_coherent,
4096 .free_coherent = vio_dma_iommu_free_coherent,
4097 .map_sg = vio_dma_iommu_map_sg,
4098 .unmap_sg = vio_dma_iommu_unmap_sg,
4099+ .dma_supported = dma_iommu_dma_supported,
4100 .map_page = vio_dma_iommu_map_page,
4101 .unmap_page = vio_dma_iommu_unmap_page,
4102 .dma_supported = vio_dma_iommu_dma_supported,
4103diff -urNp linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c
4104--- linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
4105+++ linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
4106@@ -9,22 +9,6 @@
4107 #include <linux/module.h>
4108 #include <asm/uaccess.h>
4109
4110-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4111-{
4112- if (likely(access_ok(VERIFY_READ, from, n)))
4113- n = __copy_from_user(to, from, n);
4114- else
4115- memset(to, 0, n);
4116- return n;
4117-}
4118-
4119-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4120-{
4121- if (likely(access_ok(VERIFY_WRITE, to, n)))
4122- n = __copy_to_user(to, from, n);
4123- return n;
4124-}
4125-
4126 unsigned long copy_in_user(void __user *to, const void __user *from,
4127 unsigned long n)
4128 {
4129@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
4130 return n;
4131 }
4132
4133-EXPORT_SYMBOL(copy_from_user);
4134-EXPORT_SYMBOL(copy_to_user);
4135 EXPORT_SYMBOL(copy_in_user);
4136
4137diff -urNp linux-2.6.39.1/arch/powerpc/mm/fault.c linux-2.6.39.1/arch/powerpc/mm/fault.c
4138--- linux-2.6.39.1/arch/powerpc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
4139+++ linux-2.6.39.1/arch/powerpc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
4140@@ -31,6 +31,10 @@
4141 #include <linux/kdebug.h>
4142 #include <linux/perf_event.h>
4143 #include <linux/magic.h>
4144+#include <linux/slab.h>
4145+#include <linux/pagemap.h>
4146+#include <linux/compiler.h>
4147+#include <linux/unistd.h>
4148
4149 #include <asm/firmware.h>
4150 #include <asm/page.h>
4151@@ -42,6 +46,7 @@
4152 #include <asm/tlbflush.h>
4153 #include <asm/siginfo.h>
4154 #include <mm/mmu_decl.h>
4155+#include <asm/ptrace.h>
4156
4157 #ifdef CONFIG_KPROBES
4158 static inline int notify_page_fault(struct pt_regs *regs)
4159@@ -65,6 +70,33 @@ static inline int notify_page_fault(stru
4160 }
4161 #endif
4162
4163+#ifdef CONFIG_PAX_PAGEEXEC
4164+/*
4165+ * PaX: decide what to do with offenders (regs->nip = fault address)
4166+ *
4167+ * returns 1 when task should be killed
4168+ */
4169+static int pax_handle_fetch_fault(struct pt_regs *regs)
4170+{
4171+ return 1;
4172+}
4173+
4174+void pax_report_insns(void *pc, void *sp)
4175+{
4176+ unsigned long i;
4177+
4178+ printk(KERN_ERR "PAX: bytes at PC: ");
4179+ for (i = 0; i < 5; i++) {
4180+ unsigned int c;
4181+ if (get_user(c, (unsigned int __user *)pc+i))
4182+ printk(KERN_CONT "???????? ");
4183+ else
4184+ printk(KERN_CONT "%08x ", c);
4185+ }
4186+ printk("\n");
4187+}
4188+#endif
4189+
4190 /*
4191 * Check whether the instruction at regs->nip is a store using
4192 * an update addressing form which will update r1.
4193@@ -135,7 +167,7 @@ int __kprobes do_page_fault(struct pt_re
4194 * indicate errors in DSISR but can validly be set in SRR1.
4195 */
4196 if (trap == 0x400)
4197- error_code &= 0x48200000;
4198+ error_code &= 0x58200000;
4199 else
4200 is_write = error_code & DSISR_ISSTORE;
4201 #else
4202@@ -258,7 +290,7 @@ good_area:
4203 * "undefined". Of those that can be set, this is the only
4204 * one which seems bad.
4205 */
4206- if (error_code & 0x10000000)
4207+ if (error_code & DSISR_GUARDED)
4208 /* Guarded storage error. */
4209 goto bad_area;
4210 #endif /* CONFIG_8xx */
4211@@ -273,7 +305,7 @@ good_area:
4212 * processors use the same I/D cache coherency mechanism
4213 * as embedded.
4214 */
4215- if (error_code & DSISR_PROTFAULT)
4216+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4217 goto bad_area;
4218 #endif /* CONFIG_PPC_STD_MMU */
4219
4220@@ -342,6 +374,23 @@ bad_area:
4221 bad_area_nosemaphore:
4222 /* User mode accesses cause a SIGSEGV */
4223 if (user_mode(regs)) {
4224+
4225+#ifdef CONFIG_PAX_PAGEEXEC
4226+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4227+#ifdef CONFIG_PPC_STD_MMU
4228+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4229+#else
4230+ if (is_exec && regs->nip == address) {
4231+#endif
4232+ switch (pax_handle_fetch_fault(regs)) {
4233+ }
4234+
4235+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4236+ do_group_exit(SIGKILL);
4237+ }
4238+ }
4239+#endif
4240+
4241 _exception(SIGSEGV, regs, code, address);
4242 return 0;
4243 }
4244diff -urNp linux-2.6.39.1/arch/powerpc/mm/mmap_64.c linux-2.6.39.1/arch/powerpc/mm/mmap_64.c
4245--- linux-2.6.39.1/arch/powerpc/mm/mmap_64.c 2011-05-19 00:06:34.000000000 -0400
4246+++ linux-2.6.39.1/arch/powerpc/mm/mmap_64.c 2011-05-22 19:36:30.000000000 -0400
4247@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
4248 */
4249 if (mmap_is_legacy()) {
4250 mm->mmap_base = TASK_UNMAPPED_BASE;
4251+
4252+#ifdef CONFIG_PAX_RANDMMAP
4253+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4254+ mm->mmap_base += mm->delta_mmap;
4255+#endif
4256+
4257 mm->get_unmapped_area = arch_get_unmapped_area;
4258 mm->unmap_area = arch_unmap_area;
4259 } else {
4260 mm->mmap_base = mmap_base();
4261+
4262+#ifdef CONFIG_PAX_RANDMMAP
4263+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4264+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4265+#endif
4266+
4267 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4268 mm->unmap_area = arch_unmap_area_topdown;
4269 }
4270diff -urNp linux-2.6.39.1/arch/powerpc/mm/slice.c linux-2.6.39.1/arch/powerpc/mm/slice.c
4271--- linux-2.6.39.1/arch/powerpc/mm/slice.c 2011-05-19 00:06:34.000000000 -0400
4272+++ linux-2.6.39.1/arch/powerpc/mm/slice.c 2011-05-22 19:36:30.000000000 -0400
4273@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
4274 if ((mm->task_size - len) < addr)
4275 return 0;
4276 vma = find_vma(mm, addr);
4277- return (!vma || (addr + len) <= vma->vm_start);
4278+ return check_heap_stack_gap(vma, addr, len);
4279 }
4280
4281 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4282@@ -256,7 +256,7 @@ full_search:
4283 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4284 continue;
4285 }
4286- if (!vma || addr + len <= vma->vm_start) {
4287+ if (check_heap_stack_gap(vma, addr, len)) {
4288 /*
4289 * Remember the place where we stopped the search:
4290 */
4291@@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
4292 }
4293 }
4294
4295- addr = mm->mmap_base;
4296- while (addr > len) {
4297+ if (mm->mmap_base < len)
4298+ addr = -ENOMEM;
4299+ else
4300+ addr = mm->mmap_base - len;
4301+
4302+ while (!IS_ERR_VALUE(addr)) {
4303 /* Go down by chunk size */
4304- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4305+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4306
4307 /* Check for hit with different page size */
4308 mask = slice_range_to_mask(addr, len);
4309@@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
4310 * return with success:
4311 */
4312 vma = find_vma(mm, addr);
4313- if (!vma || (addr + len) <= vma->vm_start) {
4314+ if (check_heap_stack_gap(vma, addr, len)) {
4315 /* remember the address as a hint for next time */
4316 if (use_cache)
4317 mm->free_area_cache = addr;
4318@@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
4319 mm->cached_hole_size = vma->vm_start - addr;
4320
4321 /* try just below the current vma->vm_start */
4322- addr = vma->vm_start;
4323+ addr = skip_heap_stack_gap(vma, len);
4324 }
4325
4326 /*
4327@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
4328 if (fixed && addr > (mm->task_size - len))
4329 return -EINVAL;
4330
4331+#ifdef CONFIG_PAX_RANDMMAP
4332+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4333+ addr = 0;
4334+#endif
4335+
4336 /* If hint, make sure it matches our alignment restrictions */
4337 if (!fixed && addr) {
4338 addr = _ALIGN_UP(addr, 1ul << pshift);
4339diff -urNp linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c
4340--- linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c 2011-05-19 00:06:34.000000000 -0400
4341+++ linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c 2011-05-22 19:36:30.000000000 -0400
4342@@ -60,7 +60,7 @@ static int rtas_write_config(struct pci_
4343 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
4344 }
4345
4346-static struct pci_ops rtas_pci_ops = {
4347+static const struct pci_ops rtas_pci_ops = {
4348 .read = rtas_read_config,
4349 .write = rtas_write_config,
4350 };
4351diff -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
4352--- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-19 00:06:34.000000000 -0400
4353+++ linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-22 19:36:30.000000000 -0400
4354@@ -234,7 +234,7 @@ static int celleb_fake_pci_write_config(
4355 return PCIBIOS_SUCCESSFUL;
4356 }
4357
4358-static struct pci_ops celleb_fake_pci_ops = {
4359+static const struct pci_ops celleb_fake_pci_ops = {
4360 .read = celleb_fake_pci_read_config,
4361 .write = celleb_fake_pci_write_config,
4362 };
4363diff -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
4364--- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-19 00:06:34.000000000 -0400
4365+++ linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-22 19:36:30.000000000 -0400
4366@@ -245,7 +245,7 @@ static int celleb_epci_write_config(stru
4367 return celleb_epci_check_abort(hose, addr);
4368 }
4369
4370-struct pci_ops celleb_epci_ops = {
4371+const struct pci_ops celleb_epci_ops = {
4372 .read = celleb_epci_read_config,
4373 .write = celleb_epci_write_config,
4374 };
4375diff -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
4376--- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-19 00:06:34.000000000 -0400
4377+++ linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-22 19:36:30.000000000 -0400
4378@@ -399,7 +399,7 @@ static int scc_pciex_write_config(struct
4379 return PCIBIOS_SUCCESSFUL;
4380 }
4381
4382-static struct pci_ops scc_pciex_pci_ops = {
4383+static const struct pci_ops scc_pciex_pci_ops = {
4384 scc_pciex_read_config,
4385 scc_pciex_write_config,
4386 };
4387diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c
4388--- linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c 2011-05-19 00:06:34.000000000 -0400
4389+++ linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c 2011-05-22 19:36:30.000000000 -0400
4390@@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
4391
4392 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
4393
4394-struct dma_map_ops dma_iommu_fixed_ops = {
4395+const struct dma_map_ops dma_iommu_fixed_ops = {
4396 .alloc_coherent = dma_fixed_alloc_coherent,
4397 .free_coherent = dma_fixed_free_coherent,
4398 .map_sg = dma_fixed_map_sg,
4399diff -urNp linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c
4400--- linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c 2011-05-19 00:06:34.000000000 -0400
4401+++ linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c 2011-05-22 19:36:30.000000000 -0400
4402@@ -84,7 +84,7 @@ int gg2_write_config(struct pci_bus *bus
4403 return PCIBIOS_SUCCESSFUL;
4404 }
4405
4406-static struct pci_ops gg2_pci_ops =
4407+static const struct pci_ops gg2_pci_ops =
4408 {
4409 .read = gg2_read_config,
4410 .write = gg2_write_config,
4411@@ -122,7 +122,7 @@ int rtas_write_config(struct pci_bus *bu
4412 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
4413 }
4414
4415-static struct pci_ops rtas_pci_ops =
4416+static const struct pci_ops rtas_pci_ops =
4417 {
4418 .read = rtas_read_config,
4419 .write = rtas_write_config,
4420diff -urNp linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c
4421--- linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c 2011-05-19 00:06:34.000000000 -0400
4422+++ linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c 2011-05-22 19:36:30.000000000 -0400
4423@@ -533,7 +533,7 @@ static int iSeries_pci_write_config(stru
4424 return 0;
4425 }
4426
4427-static struct pci_ops iSeries_pci_ops = {
4428+static const struct pci_ops iSeries_pci_ops = {
4429 .read = iSeries_pci_read_config,
4430 .write = iSeries_pci_write_config
4431 };
4432diff -urNp linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c
4433--- linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c 2011-05-19 00:06:34.000000000 -0400
4434+++ linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c 2011-05-22 19:36:30.000000000 -0400
4435@@ -180,7 +180,7 @@ static int u3_agp_write_config(struct pc
4436 return PCIBIOS_SUCCESSFUL;
4437 }
4438
4439-static struct pci_ops u3_agp_pci_ops =
4440+static const struct pci_ops u3_agp_pci_ops =
4441 {
4442 .read = u3_agp_read_config,
4443 .write = u3_agp_write_config,
4444@@ -276,7 +276,7 @@ static int u3_ht_write_config(struct pci
4445 return PCIBIOS_SUCCESSFUL;
4446 }
4447
4448-static struct pci_ops u3_ht_pci_ops =
4449+static const struct pci_ops u3_ht_pci_ops =
4450 {
4451 .read = u3_ht_read_config,
4452 .write = u3_ht_write_config,
4453@@ -381,7 +381,7 @@ static int u4_pcie_write_config(struct p
4454 return PCIBIOS_SUCCESSFUL;
4455 }
4456
4457-static struct pci_ops u4_pcie_pci_ops =
4458+static const struct pci_ops u4_pcie_pci_ops =
4459 {
4460 .read = u4_pcie_read_config,
4461 .write = u4_pcie_write_config,
4462diff -urNp linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c
4463--- linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c 2011-05-19 00:06:34.000000000 -0400
4464+++ linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c 2011-05-22 19:36:30.000000000 -0400
4465@@ -176,7 +176,7 @@ static int pa_pxp_write_config(struct pc
4466 return PCIBIOS_SUCCESSFUL;
4467 }
4468
4469-static struct pci_ops pa_pxp_ops = {
4470+static const struct pci_ops pa_pxp_ops = {
4471 .read = pa_pxp_read_config,
4472 .write = pa_pxp_write_config,
4473 };
4474diff -urNp linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c
4475--- linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c 2011-05-19 00:06:34.000000000 -0400
4476+++ linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c 2011-05-22 19:36:30.000000000 -0400
4477@@ -218,7 +218,7 @@ static int macrisc_write_config(struct p
4478 return PCIBIOS_SUCCESSFUL;
4479 }
4480
4481-static struct pci_ops macrisc_pci_ops =
4482+static const struct pci_ops macrisc_pci_ops =
4483 {
4484 .read = macrisc_read_config,
4485 .write = macrisc_write_config,
4486@@ -273,7 +273,7 @@ chaos_write_config(struct pci_bus *bus,
4487 return macrisc_write_config(bus, devfn, offset, len, val);
4488 }
4489
4490-static struct pci_ops chaos_pci_ops =
4491+static const struct pci_ops chaos_pci_ops =
4492 {
4493 .read = chaos_read_config,
4494 .write = chaos_write_config,
4495diff -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
4496--- linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c 2011-05-19 00:06:34.000000000 -0400
4497+++ linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c 2011-05-22 19:36:30.000000000 -0400
4498@@ -695,7 +695,7 @@ static int ps3_dma_supported(struct devi
4499 return mask >= DMA_BIT_MASK(32);
4500 }
4501
4502-static struct dma_map_ops ps3_sb_dma_ops = {
4503+static const struct dma_map_ops ps3_sb_dma_ops = {
4504 .alloc_coherent = ps3_alloc_coherent,
4505 .free_coherent = ps3_free_coherent,
4506 .map_sg = ps3_sb_map_sg,
4507@@ -705,7 +705,7 @@ static struct dma_map_ops ps3_sb_dma_ops
4508 .unmap_page = ps3_unmap_page,
4509 };
4510
4511-static struct dma_map_ops ps3_ioc0_dma_ops = {
4512+static const struct dma_map_ops ps3_ioc0_dma_ops = {
4513 .alloc_coherent = ps3_alloc_coherent,
4514 .free_coherent = ps3_free_coherent,
4515 .map_sg = ps3_ioc0_map_sg,
4516diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c
4517--- linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c 2011-05-19 00:06:34.000000000 -0400
4518+++ linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c 2011-05-22 19:36:30.000000000 -0400
4519@@ -573,7 +573,7 @@ static int mpc83xx_pcie_write_config(str
4520 return PCIBIOS_SUCCESSFUL;
4521 }
4522
4523-static struct pci_ops mpc83xx_pcie_ops = {
4524+static const struct pci_ops mpc83xx_pcie_ops = {
4525 .read = mpc83xx_pcie_read_config,
4526 .write = mpc83xx_pcie_write_config,
4527 };
4528diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c
4529--- linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
4530+++ linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
4531@@ -148,7 +148,7 @@ indirect_write_config(struct pci_bus *bu
4532 return PCIBIOS_SUCCESSFUL;
4533 }
4534
4535-static struct pci_ops indirect_pci_ops =
4536+static const struct pci_ops indirect_pci_ops =
4537 {
4538 .read = indirect_read_config,
4539 .write = indirect_write_config,
4540diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c
4541--- linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-19 00:06:34.000000000 -0400
4542+++ linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-22 19:36:30.000000000 -0400
4543@@ -1514,7 +1514,7 @@ static int ppc4xx_pciex_write_config(str
4544 return PCIBIOS_SUCCESSFUL;
4545 }
4546
4547-static struct pci_ops ppc4xx_pciex_pci_ops =
4548+static const struct pci_ops ppc4xx_pciex_pci_ops =
4549 {
4550 .read = ppc4xx_pciex_read_config,
4551 .write = ppc4xx_pciex_write_config,
4552diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c
4553--- linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c 2011-05-19 00:06:34.000000000 -0400
4554+++ linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c 2011-05-22 19:36:30.000000000 -0400
4555@@ -190,7 +190,7 @@ void tsi108_clear_pci_cfg_error(void)
4556 tsi108_clear_pci_error(tsi108_pci_cfg_phys);
4557 }
4558
4559-static struct pci_ops tsi108_direct_pci_ops = {
4560+static const struct pci_ops tsi108_direct_pci_ops = {
4561 .read = tsi108_direct_read_config,
4562 .write = tsi108_direct_write_config,
4563 };
4564diff -urNp linux-2.6.39.1/arch/s390/include/asm/elf.h linux-2.6.39.1/arch/s390/include/asm/elf.h
4565--- linux-2.6.39.1/arch/s390/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
4566+++ linux-2.6.39.1/arch/s390/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
4567@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4568 the loader. We need to make sure that it is out of the way of the program
4569 that it will "exec", and that there is sufficient room for the brk. */
4570
4571-extern unsigned long randomize_et_dyn(unsigned long base);
4572-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4573+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4574+
4575+#ifdef CONFIG_PAX_ASLR
4576+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4577+
4578+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4579+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4580+#endif
4581
4582 /* This yields a mask that user programs can use to figure out what
4583 instruction set this CPU supports. */
4584@@ -222,7 +228,4 @@ struct linux_binprm;
4585 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4586 int arch_setup_additional_pages(struct linux_binprm *, int);
4587
4588-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4589-#define arch_randomize_brk arch_randomize_brk
4590-
4591 #endif
4592diff -urNp linux-2.6.39.1/arch/s390/include/asm/system.h linux-2.6.39.1/arch/s390/include/asm/system.h
4593--- linux-2.6.39.1/arch/s390/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4594+++ linux-2.6.39.1/arch/s390/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4595@@ -255,7 +255,7 @@ extern void (*_machine_restart)(char *co
4596 extern void (*_machine_halt)(void);
4597 extern void (*_machine_power_off)(void);
4598
4599-extern unsigned long arch_align_stack(unsigned long sp);
4600+#define arch_align_stack(x) ((x) & ~0xfUL)
4601
4602 static inline int tprot(unsigned long addr)
4603 {
4604diff -urNp linux-2.6.39.1/arch/s390/include/asm/uaccess.h linux-2.6.39.1/arch/s390/include/asm/uaccess.h
4605--- linux-2.6.39.1/arch/s390/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
4606+++ linux-2.6.39.1/arch/s390/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
4607@@ -234,6 +234,10 @@ static inline unsigned long __must_check
4608 copy_to_user(void __user *to, const void *from, unsigned long n)
4609 {
4610 might_fault();
4611+
4612+ if ((long)n < 0)
4613+ return n;
4614+
4615 if (access_ok(VERIFY_WRITE, to, n))
4616 n = __copy_to_user(to, from, n);
4617 return n;
4618@@ -259,6 +263,9 @@ copy_to_user(void __user *to, const void
4619 static inline unsigned long __must_check
4620 __copy_from_user(void *to, const void __user *from, unsigned long n)
4621 {
4622+ if ((long)n < 0)
4623+ return n;
4624+
4625 if (__builtin_constant_p(n) && (n <= 256))
4626 return uaccess.copy_from_user_small(n, from, to);
4627 else
4628@@ -293,6 +300,10 @@ copy_from_user(void *to, const void __us
4629 unsigned int sz = __compiletime_object_size(to);
4630
4631 might_fault();
4632+
4633+ if ((long)n < 0)
4634+ return n;
4635+
4636 if (unlikely(sz != -1 && sz < n)) {
4637 copy_from_user_overflow();
4638 return n;
4639diff -urNp linux-2.6.39.1/arch/s390/Kconfig linux-2.6.39.1/arch/s390/Kconfig
4640--- linux-2.6.39.1/arch/s390/Kconfig 2011-05-19 00:06:34.000000000 -0400
4641+++ linux-2.6.39.1/arch/s390/Kconfig 2011-05-22 19:36:30.000000000 -0400
4642@@ -234,11 +234,9 @@ config S390_EXEC_PROTECT
4643 prompt "Data execute protection"
4644 help
4645 This option allows to enable a buffer overflow protection for user
4646- space programs and it also selects the addressing mode option above.
4647- The kernel parameter noexec=on will enable this feature and also
4648- switch the addressing modes, default is disabled. Enabling this (via
4649- kernel parameter) on machines earlier than IBM System z9 this will
4650- reduce system performance.
4651+ space programs.
4652+ Enabling this (via kernel parameter) on machines earlier than IBM
4653+ System z9 this will reduce system performance.
4654
4655 comment "Code generation options"
4656
4657diff -urNp linux-2.6.39.1/arch/s390/kernel/module.c linux-2.6.39.1/arch/s390/kernel/module.c
4658--- linux-2.6.39.1/arch/s390/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
4659+++ linux-2.6.39.1/arch/s390/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
4660@@ -168,11 +168,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
4661
4662 /* Increase core size by size of got & plt and set start
4663 offsets for got and plt. */
4664- me->core_size = ALIGN(me->core_size, 4);
4665- me->arch.got_offset = me->core_size;
4666- me->core_size += me->arch.got_size;
4667- me->arch.plt_offset = me->core_size;
4668- me->core_size += me->arch.plt_size;
4669+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4670+ me->arch.got_offset = me->core_size_rw;
4671+ me->core_size_rw += me->arch.got_size;
4672+ me->arch.plt_offset = me->core_size_rx;
4673+ me->core_size_rx += me->arch.plt_size;
4674 return 0;
4675 }
4676
4677@@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4678 if (info->got_initialized == 0) {
4679 Elf_Addr *gotent;
4680
4681- gotent = me->module_core + me->arch.got_offset +
4682+ gotent = me->module_core_rw + me->arch.got_offset +
4683 info->got_offset;
4684 *gotent = val;
4685 info->got_initialized = 1;
4686@@ -282,7 +282,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4687 else if (r_type == R_390_GOTENT ||
4688 r_type == R_390_GOTPLTENT)
4689 *(unsigned int *) loc =
4690- (val + (Elf_Addr) me->module_core - loc) >> 1;
4691+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4692 else if (r_type == R_390_GOT64 ||
4693 r_type == R_390_GOTPLT64)
4694 *(unsigned long *) loc = val;
4695@@ -296,7 +296,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4696 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4697 if (info->plt_initialized == 0) {
4698 unsigned int *ip;
4699- ip = me->module_core + me->arch.plt_offset +
4700+ ip = me->module_core_rx + me->arch.plt_offset +
4701 info->plt_offset;
4702 #ifndef CONFIG_64BIT
4703 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4704@@ -321,7 +321,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4705 val - loc + 0xffffUL < 0x1ffffeUL) ||
4706 (r_type == R_390_PLT32DBL &&
4707 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4708- val = (Elf_Addr) me->module_core +
4709+ val = (Elf_Addr) me->module_core_rx +
4710 me->arch.plt_offset +
4711 info->plt_offset;
4712 val += rela->r_addend - loc;
4713@@ -343,7 +343,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4714 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4715 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4716 val = val + rela->r_addend -
4717- ((Elf_Addr) me->module_core + me->arch.got_offset);
4718+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4719 if (r_type == R_390_GOTOFF16)
4720 *(unsigned short *) loc = val;
4721 else if (r_type == R_390_GOTOFF32)
4722@@ -353,7 +353,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4723 break;
4724 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4725 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4726- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4727+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4728 rela->r_addend - loc;
4729 if (r_type == R_390_GOTPC)
4730 *(unsigned int *) loc = val;
4731diff -urNp linux-2.6.39.1/arch/s390/kernel/process.c linux-2.6.39.1/arch/s390/kernel/process.c
4732--- linux-2.6.39.1/arch/s390/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4733+++ linux-2.6.39.1/arch/s390/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4734@@ -334,39 +334,3 @@ unsigned long get_wchan(struct task_stru
4735 }
4736 return 0;
4737 }
4738-
4739-unsigned long arch_align_stack(unsigned long sp)
4740-{
4741- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4742- sp -= get_random_int() & ~PAGE_MASK;
4743- return sp & ~0xf;
4744-}
4745-
4746-static inline unsigned long brk_rnd(void)
4747-{
4748- /* 8MB for 32bit, 1GB for 64bit */
4749- if (is_32bit_task())
4750- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4751- else
4752- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4753-}
4754-
4755-unsigned long arch_randomize_brk(struct mm_struct *mm)
4756-{
4757- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4758-
4759- if (ret < mm->brk)
4760- return mm->brk;
4761- return ret;
4762-}
4763-
4764-unsigned long randomize_et_dyn(unsigned long base)
4765-{
4766- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4767-
4768- if (!(current->flags & PF_RANDOMIZE))
4769- return base;
4770- if (ret < base)
4771- return base;
4772- return ret;
4773-}
4774diff -urNp linux-2.6.39.1/arch/s390/kernel/setup.c linux-2.6.39.1/arch/s390/kernel/setup.c
4775--- linux-2.6.39.1/arch/s390/kernel/setup.c 2011-05-19 00:06:34.000000000 -0400
4776+++ linux-2.6.39.1/arch/s390/kernel/setup.c 2011-05-22 19:36:30.000000000 -0400
4777@@ -271,7 +271,7 @@ static int __init early_parse_mem(char *
4778 }
4779 early_param("mem", early_parse_mem);
4780
4781-unsigned int user_mode = HOME_SPACE_MODE;
4782+unsigned int user_mode = SECONDARY_SPACE_MODE;
4783 EXPORT_SYMBOL_GPL(user_mode);
4784
4785 static int set_amode_and_uaccess(unsigned long user_amode,
4786@@ -300,17 +300,6 @@ static int set_amode_and_uaccess(unsigne
4787 }
4788 }
4789
4790-/*
4791- * Switch kernel/user addressing modes?
4792- */
4793-static int __init early_parse_switch_amode(char *p)
4794-{
4795- if (user_mode != SECONDARY_SPACE_MODE)
4796- user_mode = PRIMARY_SPACE_MODE;
4797- return 0;
4798-}
4799-early_param("switch_amode", early_parse_switch_amode);
4800-
4801 static int __init early_parse_user_mode(char *p)
4802 {
4803 if (p && strcmp(p, "primary") == 0)
4804@@ -327,20 +316,6 @@ static int __init early_parse_user_mode(
4805 }
4806 early_param("user_mode", early_parse_user_mode);
4807
4808-#ifdef CONFIG_S390_EXEC_PROTECT
4809-/*
4810- * Enable execute protection?
4811- */
4812-static int __init early_parse_noexec(char *p)
4813-{
4814- if (!strncmp(p, "off", 3))
4815- return 0;
4816- user_mode = SECONDARY_SPACE_MODE;
4817- return 0;
4818-}
4819-early_param("noexec", early_parse_noexec);
4820-#endif /* CONFIG_S390_EXEC_PROTECT */
4821-
4822 static void setup_addressing_mode(void)
4823 {
4824 if (user_mode == SECONDARY_SPACE_MODE) {
4825diff -urNp linux-2.6.39.1/arch/s390/mm/maccess.c linux-2.6.39.1/arch/s390/mm/maccess.c
4826--- linux-2.6.39.1/arch/s390/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
4827+++ linux-2.6.39.1/arch/s390/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
4828@@ -45,7 +45,7 @@ static long probe_kernel_write_odd(void
4829 return rc ? rc : count;
4830 }
4831
4832-long probe_kernel_write(void *dst, void *src, size_t size)
4833+long probe_kernel_write(void *dst, const void *src, size_t size)
4834 {
4835 long copied = 0;
4836
4837diff -urNp linux-2.6.39.1/arch/s390/mm/mmap.c linux-2.6.39.1/arch/s390/mm/mmap.c
4838--- linux-2.6.39.1/arch/s390/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4839+++ linux-2.6.39.1/arch/s390/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
4840@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_str
4841 */
4842 if (mmap_is_legacy()) {
4843 mm->mmap_base = TASK_UNMAPPED_BASE;
4844+
4845+#ifdef CONFIG_PAX_RANDMMAP
4846+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4847+ mm->mmap_base += mm->delta_mmap;
4848+#endif
4849+
4850 mm->get_unmapped_area = arch_get_unmapped_area;
4851 mm->unmap_area = arch_unmap_area;
4852 } else {
4853 mm->mmap_base = mmap_base();
4854+
4855+#ifdef CONFIG_PAX_RANDMMAP
4856+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4857+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4858+#endif
4859+
4860 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4861 mm->unmap_area = arch_unmap_area_topdown;
4862 }
4863@@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_str
4864 */
4865 if (mmap_is_legacy()) {
4866 mm->mmap_base = TASK_UNMAPPED_BASE;
4867+
4868+#ifdef CONFIG_PAX_RANDMMAP
4869+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4870+ mm->mmap_base += mm->delta_mmap;
4871+#endif
4872+
4873 mm->get_unmapped_area = s390_get_unmapped_area;
4874 mm->unmap_area = arch_unmap_area;
4875 } else {
4876 mm->mmap_base = mmap_base();
4877+
4878+#ifdef CONFIG_PAX_RANDMMAP
4879+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4880+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4881+#endif
4882+
4883 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4884 mm->unmap_area = arch_unmap_area_topdown;
4885 }
4886diff -urNp linux-2.6.39.1/arch/score/include/asm/system.h linux-2.6.39.1/arch/score/include/asm/system.h
4887--- linux-2.6.39.1/arch/score/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4888+++ linux-2.6.39.1/arch/score/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4889@@ -17,7 +17,7 @@ do { \
4890 #define finish_arch_switch(prev) do {} while (0)
4891
4892 typedef void (*vi_handler_t)(void);
4893-extern unsigned long arch_align_stack(unsigned long sp);
4894+#define arch_align_stack(x) (x)
4895
4896 #define mb() barrier()
4897 #define rmb() barrier()
4898diff -urNp linux-2.6.39.1/arch/score/kernel/process.c linux-2.6.39.1/arch/score/kernel/process.c
4899--- linux-2.6.39.1/arch/score/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4900+++ linux-2.6.39.1/arch/score/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4901@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
4902
4903 return task_pt_regs(task)->cp0_epc;
4904 }
4905-
4906-unsigned long arch_align_stack(unsigned long sp)
4907-{
4908- return sp;
4909-}
4910diff -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
4911--- linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-19 00:06:34.000000000 -0400
4912+++ linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-22 19:36:30.000000000 -0400
4913@@ -76,7 +76,7 @@ static int gapspci_write(struct pci_bus
4914 return PCIBIOS_SUCCESSFUL;
4915 }
4916
4917-struct pci_ops gapspci_pci_ops = {
4918+const struct pci_ops gapspci_pci_ops = {
4919 .read = gapspci_read,
4920 .write = gapspci_write,
4921 };
4922diff -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
4923--- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c 2011-05-19 00:06:34.000000000 -0400
4924+++ linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c 2011-05-22 19:36:30.000000000 -0400
4925@@ -96,7 +96,7 @@ static int sh4_pci_write(struct pci_bus
4926 return PCIBIOS_SUCCESSFUL;
4927 }
4928
4929-struct pci_ops sh4_pci_ops = {
4930+const struct pci_ops sh4_pci_ops = {
4931 .read = sh4_pci_read,
4932 .write = sh4_pci_write,
4933 };
4934diff -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
4935--- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c 2011-05-19 00:06:34.000000000 -0400
4936+++ linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c 2011-05-22 19:36:30.000000000 -0400
4937@@ -62,7 +62,7 @@ static int sh5pci_write(struct pci_bus *
4938 return PCIBIOS_SUCCESSFUL;
4939 }
4940
4941-struct pci_ops sh5_pci_ops = {
4942+const struct pci_ops sh5_pci_ops = {
4943 .read = sh5pci_read,
4944 .write = sh5pci_write,
4945 };
4946diff -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
4947--- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4948+++ linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4949@@ -165,7 +165,7 @@ out:
4950 return ret;
4951 }
4952
4953-struct pci_ops sh7786_pci_ops = {
4954+const struct pci_ops sh7786_pci_ops = {
4955 .read = sh7786_pcie_read,
4956 .write = sh7786_pcie_write,
4957 };
4958diff -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
4959--- linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4960+++ linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4961@@ -109,7 +109,7 @@ static struct resource sh7786_pci2_resou
4962 },
4963 };
4964
4965-extern struct pci_ops sh7786_pci_ops;
4966+extern const struct pci_ops sh7786_pci_ops;
4967
4968 #define DEFINE_CONTROLLER(start, idx) \
4969 { \
4970diff -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
4971--- linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h 2011-05-19 00:06:34.000000000 -0400
4972+++ linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h 2011-05-22 19:36:30.000000000 -0400
4973@@ -161,7 +161,7 @@
4974 #define SH4_PCIPDR 0x220 /* Port IO Data Register */
4975
4976 /* arch/sh/kernel/drivers/pci/ops-sh4.c */
4977-extern struct pci_ops sh4_pci_ops;
4978+extern const struct pci_ops sh4_pci_ops;
4979 int pci_fixup_pcic(struct pci_channel *chan);
4980
4981 struct sh4_pci_address_space {
4982diff -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
4983--- linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h 2011-05-19 00:06:34.000000000 -0400
4984+++ linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h 2011-05-22 19:36:30.000000000 -0400
4985@@ -105,6 +105,6 @@ extern unsigned long pcicr_virt;
4986 #define PCISH5_MEM_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4987 #define PCISH5_IO_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4988
4989-extern struct pci_ops sh5_pci_ops;
4990+extern const struct pci_ops sh5_pci_ops;
4991
4992 #endif /* __PCI_SH5_H */
4993diff -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
4994--- linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
4995+++ linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
4996@@ -1,10 +1,10 @@
4997 #ifndef __ASM_SH_DMA_MAPPING_H
4998 #define __ASM_SH_DMA_MAPPING_H
4999
5000-extern struct dma_map_ops *dma_ops;
5001+extern const struct dma_map_ops *dma_ops;
5002 extern void no_iommu_init(void);
5003
5004-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
5005+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
5006 {
5007 return dma_ops;
5008 }
5009@@ -14,7 +14,7 @@ static inline struct dma_map_ops *get_dm
5010
5011 static inline int dma_supported(struct device *dev, u64 mask)
5012 {
5013- struct dma_map_ops *ops = get_dma_ops(dev);
5014+ const struct dma_map_ops *ops = get_dma_ops(dev);
5015
5016 if (ops->dma_supported)
5017 return ops->dma_supported(dev, mask);
5018@@ -24,7 +24,7 @@ static inline int dma_supported(struct d
5019
5020 static inline int dma_set_mask(struct device *dev, u64 mask)
5021 {
5022- struct dma_map_ops *ops = get_dma_ops(dev);
5023+ const struct dma_map_ops *ops = get_dma_ops(dev);
5024
5025 if (!dev->dma_mask || !dma_supported(dev, mask))
5026 return -EIO;
5027@@ -44,7 +44,7 @@ void dma_cache_sync(struct device *dev,
5028
5029 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
5030 {
5031- struct dma_map_ops *ops = get_dma_ops(dev);
5032+ const struct dma_map_ops *ops = get_dma_ops(dev);
5033
5034 if (ops->mapping_error)
5035 return ops->mapping_error(dev, dma_addr);
5036@@ -55,7 +55,7 @@ static inline int dma_mapping_error(stru
5037 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
5038 dma_addr_t *dma_handle, gfp_t gfp)
5039 {
5040- struct dma_map_ops *ops = get_dma_ops(dev);
5041+ const struct dma_map_ops *ops = get_dma_ops(dev);
5042 void *memory;
5043
5044 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
5045@@ -72,7 +72,7 @@ static inline void *dma_alloc_coherent(s
5046 static inline void dma_free_coherent(struct device *dev, size_t size,
5047 void *vaddr, dma_addr_t dma_handle)
5048 {
5049- struct dma_map_ops *ops = get_dma_ops(dev);
5050+ const struct dma_map_ops *ops = get_dma_ops(dev);
5051
5052 if (dma_release_from_coherent(dev, get_order(size), vaddr))
5053 return;
5054diff -urNp linux-2.6.39.1/arch/sh/kernel/dma-nommu.c linux-2.6.39.1/arch/sh/kernel/dma-nommu.c
5055--- linux-2.6.39.1/arch/sh/kernel/dma-nommu.c 2011-05-19 00:06:34.000000000 -0400
5056+++ linux-2.6.39.1/arch/sh/kernel/dma-nommu.c 2011-05-22 19:36:30.000000000 -0400
5057@@ -62,7 +62,7 @@ static void nommu_sync_sg(struct device
5058 }
5059 #endif
5060
5061-struct dma_map_ops nommu_dma_ops = {
5062+const struct dma_map_ops nommu_dma_ops = {
5063 .alloc_coherent = dma_generic_alloc_coherent,
5064 .free_coherent = dma_generic_free_coherent,
5065 .map_page = nommu_map_page,
5066diff -urNp linux-2.6.39.1/arch/sh/kernel/kgdb.c linux-2.6.39.1/arch/sh/kernel/kgdb.c
5067--- linux-2.6.39.1/arch/sh/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
5068+++ linux-2.6.39.1/arch/sh/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
5069@@ -319,7 +319,7 @@ void kgdb_arch_exit(void)
5070 unregister_die_notifier(&kgdb_notifier);
5071 }
5072
5073-struct kgdb_arch arch_kgdb_ops = {
5074+const struct kgdb_arch arch_kgdb_ops = {
5075 /* Breakpoint instruction: trapa #0x3c */
5076 #ifdef CONFIG_CPU_LITTLE_ENDIAN
5077 .gdb_bpt_instr = { 0x3c, 0xc3 },
5078diff -urNp linux-2.6.39.1/arch/sh/mm/consistent.c linux-2.6.39.1/arch/sh/mm/consistent.c
5079--- linux-2.6.39.1/arch/sh/mm/consistent.c 2011-05-19 00:06:34.000000000 -0400
5080+++ linux-2.6.39.1/arch/sh/mm/consistent.c 2011-05-22 19:36:30.000000000 -0400
5081@@ -22,7 +22,7 @@
5082
5083 #define PREALLOC_DMA_DEBUG_ENTRIES 4096
5084
5085-struct dma_map_ops *dma_ops;
5086+const struct dma_map_ops *dma_ops;
5087 EXPORT_SYMBOL(dma_ops);
5088
5089 static int __init dma_init(void)
5090diff -urNp linux-2.6.39.1/arch/sh/mm/mmap.c linux-2.6.39.1/arch/sh/mm/mmap.c
5091--- linux-2.6.39.1/arch/sh/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
5092+++ linux-2.6.39.1/arch/sh/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
5093@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
5094 addr = PAGE_ALIGN(addr);
5095
5096 vma = find_vma(mm, addr);
5097- if (TASK_SIZE - len >= addr &&
5098- (!vma || addr + len <= vma->vm_start))
5099+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5100 return addr;
5101 }
5102
5103@@ -106,7 +105,7 @@ full_search:
5104 }
5105 return -ENOMEM;
5106 }
5107- if (likely(!vma || addr + len <= vma->vm_start)) {
5108+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5109 /*
5110 * Remember the place where we stopped the search:
5111 */
5112@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
5113 addr = PAGE_ALIGN(addr);
5114
5115 vma = find_vma(mm, addr);
5116- if (TASK_SIZE - len >= addr &&
5117- (!vma || addr + len <= vma->vm_start))
5118+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5119 return addr;
5120 }
5121
5122@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
5123 /* make sure it can fit in the remaining address space */
5124 if (likely(addr > len)) {
5125 vma = find_vma(mm, addr-len);
5126- if (!vma || addr <= vma->vm_start) {
5127+ if (check_heap_stack_gap(vma, addr - len, len)) {
5128 /* remember the address as a hint for next time */
5129 return (mm->free_area_cache = addr-len);
5130 }
5131@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
5132 if (unlikely(mm->mmap_base < len))
5133 goto bottomup;
5134
5135- addr = mm->mmap_base-len;
5136- if (do_colour_align)
5137- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5138+ addr = mm->mmap_base - len;
5139
5140 do {
5141+ if (do_colour_align)
5142+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5143 /*
5144 * Lookup failure means no vma is above this address,
5145 * else if new region fits below vma->vm_start,
5146 * return with success:
5147 */
5148 vma = find_vma(mm, addr);
5149- if (likely(!vma || addr+len <= vma->vm_start)) {
5150+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5151 /* remember the address as a hint for next time */
5152 return (mm->free_area_cache = addr);
5153 }
5154@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
5155 mm->cached_hole_size = vma->vm_start - addr;
5156
5157 /* try just below the current vma->vm_start */
5158- addr = vma->vm_start-len;
5159- if (do_colour_align)
5160- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5161- } while (likely(len < vma->vm_start));
5162+ addr = skip_heap_stack_gap(vma, len);
5163+ } while (!IS_ERR_VALUE(addr));
5164
5165 bottomup:
5166 /*
5167diff -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
5168--- linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h 2011-05-19 00:06:34.000000000 -0400
5169+++ linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h 2011-05-22 19:36:30.000000000 -0400
5170@@ -14,18 +14,40 @@
5171 #define ATOMIC64_INIT(i) { (i) }
5172
5173 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5174+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5175+{
5176+ return v->counter;
5177+}
5178 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5179+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5180+{
5181+ return v->counter;
5182+}
5183
5184 #define atomic_set(v, i) (((v)->counter) = i)
5185+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5186+{
5187+ v->counter = i;
5188+}
5189 #define atomic64_set(v, i) (((v)->counter) = i)
5190+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5191+{
5192+ v->counter = i;
5193+}
5194
5195 extern void atomic_add(int, atomic_t *);
5196+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5197 extern void atomic64_add(long, atomic64_t *);
5198+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5199 extern void atomic_sub(int, atomic_t *);
5200+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5201 extern void atomic64_sub(long, atomic64_t *);
5202+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5203
5204 extern int atomic_add_ret(int, atomic_t *);
5205+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5206 extern long atomic64_add_ret(long, atomic64_t *);
5207+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5208 extern int atomic_sub_ret(int, atomic_t *);
5209 extern long atomic64_sub_ret(long, atomic64_t *);
5210
5211@@ -33,12 +55,24 @@ extern long atomic64_sub_ret(long, atomi
5212 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5213
5214 #define atomic_inc_return(v) atomic_add_ret(1, v)
5215+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5216+{
5217+ return atomic_add_ret_unchecked(1, v);
5218+}
5219 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5220+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5221+{
5222+ return atomic64_add_ret_unchecked(1, v);
5223+}
5224
5225 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5226 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5227
5228 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5229+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5230+{
5231+ return atomic_add_ret_unchecked(i, v);
5232+}
5233 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5234
5235 /*
5236@@ -50,6 +84,7 @@ extern long atomic64_sub_ret(long, atomi
5237 * other cases.
5238 */
5239 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5240+#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
5241 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5242
5243 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5244@@ -59,30 +94,59 @@ extern long atomic64_sub_ret(long, atomi
5245 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5246
5247 #define atomic_inc(v) atomic_add(1, v)
5248+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5249+{
5250+ atomic_add_unchecked(1, v);
5251+}
5252 #define atomic64_inc(v) atomic64_add(1, v)
5253+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5254+{
5255+ atomic64_add_unchecked(1, v);
5256+}
5257
5258 #define atomic_dec(v) atomic_sub(1, v)
5259+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5260+{
5261+ atomic_sub_unchecked(1, v);
5262+}
5263 #define atomic64_dec(v) atomic64_sub(1, v)
5264+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5265+{
5266+ atomic64_sub_unchecked(1, v);
5267+}
5268
5269 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5270 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5271
5272 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5273+#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5275+#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
5276
5277 static inline int atomic_add_unless(atomic_t *v, int a, int u)
5278 {
5279- int c, old;
5280+ int c, old, new;
5281 c = atomic_read(v);
5282 for (;;) {
5283- if (unlikely(c == (u)))
5284+ if (unlikely(c == u))
5285 break;
5286- old = atomic_cmpxchg((v), c, c + (a));
5287+
5288+ asm volatile("addcc %2, %0, %0\n"
5289+
5290+#ifdef CONFIG_PAX_REFCOUNT
5291+ "tvs %%icc, 6\n"
5292+#endif
5293+
5294+ : "=r" (new)
5295+ : "0" (c), "ir" (a)
5296+ : "cc");
5297+
5298+ old = atomic_cmpxchg(v, c, new);
5299 if (likely(old == c))
5300 break;
5301 c = old;
5302 }
5303- return c != (u);
5304+ return c != u;
5305 }
5306
5307 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
5308@@ -93,17 +157,28 @@ static inline int atomic_add_unless(atom
5309
5310 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5311 {
5312- long c, old;
5313+ long c, old, new;
5314 c = atomic64_read(v);
5315 for (;;) {
5316- if (unlikely(c == (u)))
5317+ if (unlikely(c == u))
5318 break;
5319- old = atomic64_cmpxchg((v), c, c + (a));
5320+
5321+ asm volatile("addcc %2, %0, %0\n"
5322+
5323+#ifdef CONFIG_PAX_REFCOUNT
5324+ "tvs %%xcc, 6\n"
5325+#endif
5326+
5327+ : "=r" (new)
5328+ : "0" (c), "ir" (a)
5329+ : "cc");
5330+
5331+ old = atomic64_cmpxchg(v, c, new);
5332 if (likely(old == c))
5333 break;
5334 c = old;
5335 }
5336- return c != (u);
5337+ return c != u;
5338 }
5339
5340 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5341diff -urNp linux-2.6.39.1/arch/sparc/include/asm/cache.h linux-2.6.39.1/arch/sparc/include/asm/cache.h
5342--- linux-2.6.39.1/arch/sparc/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
5343+++ linux-2.6.39.1/arch/sparc/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
5344@@ -10,7 +10,7 @@
5345 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5346
5347 #define L1_CACHE_SHIFT 5
5348-#define L1_CACHE_BYTES 32
5349+#define L1_CACHE_BYTES 32U
5350
5351 #ifdef CONFIG_SPARC32
5352 #define SMP_CACHE_BYTES_SHIFT 5
5353diff -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
5354--- linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
5355+++ linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
5356@@ -12,10 +12,10 @@ extern int dma_supported(struct device *
5357 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
5358 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
5359
5360-extern struct dma_map_ops *dma_ops, pci32_dma_ops;
5361+extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
5362 extern struct bus_type pci_bus_type;
5363
5364-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
5365+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
5366 {
5367 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
5368 if (dev->bus == &pci_bus_type)
5369@@ -29,7 +29,7 @@ static inline struct dma_map_ops *get_dm
5370 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
5371 dma_addr_t *dma_handle, gfp_t flag)
5372 {
5373- struct dma_map_ops *ops = get_dma_ops(dev);
5374+ const struct dma_map_ops *ops = get_dma_ops(dev);
5375 void *cpu_addr;
5376
5377 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
5378@@ -40,7 +40,7 @@ static inline void *dma_alloc_coherent(s
5379 static inline void dma_free_coherent(struct device *dev, size_t size,
5380 void *cpu_addr, dma_addr_t dma_handle)
5381 {
5382- struct dma_map_ops *ops = get_dma_ops(dev);
5383+ const struct dma_map_ops *ops = get_dma_ops(dev);
5384
5385 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
5386 ops->free_coherent(dev, size, cpu_addr, dma_handle);
5387diff -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
5388--- linux-2.6.39.1/arch/sparc/include/asm/elf_32.h 2011-05-19 00:06:34.000000000 -0400
5389+++ linux-2.6.39.1/arch/sparc/include/asm/elf_32.h 2011-05-22 19:36:30.000000000 -0400
5390@@ -114,6 +114,13 @@ typedef struct {
5391
5392 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5393
5394+#ifdef CONFIG_PAX_ASLR
5395+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5396+
5397+#define PAX_DELTA_MMAP_LEN 16
5398+#define PAX_DELTA_STACK_LEN 16
5399+#endif
5400+
5401 /* This yields a mask that user programs can use to figure out what
5402 instruction set this cpu supports. This can NOT be done in userspace
5403 on Sparc. */
5404diff -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
5405--- linux-2.6.39.1/arch/sparc/include/asm/elf_64.h 2011-05-19 00:06:34.000000000 -0400
5406+++ linux-2.6.39.1/arch/sparc/include/asm/elf_64.h 2011-05-22 19:36:30.000000000 -0400
5407@@ -162,6 +162,12 @@ typedef struct {
5408 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5409 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5410
5411+#ifdef CONFIG_PAX_ASLR
5412+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5413+
5414+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5415+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5416+#endif
5417
5418 /* This yields a mask that user programs can use to figure out what
5419 instruction set this cpu supports. */
5420diff -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
5421--- linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
5422+++ linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
5423@@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5424 BTFIXUPDEF_INT(page_none)
5425 BTFIXUPDEF_INT(page_copy)
5426 BTFIXUPDEF_INT(page_readonly)
5427+
5428+#ifdef CONFIG_PAX_PAGEEXEC
5429+BTFIXUPDEF_INT(page_shared_noexec)
5430+BTFIXUPDEF_INT(page_copy_noexec)
5431+BTFIXUPDEF_INT(page_readonly_noexec)
5432+#endif
5433+
5434 BTFIXUPDEF_INT(page_kernel)
5435
5436 #define PMD_SHIFT SUN4C_PMD_SHIFT
5437@@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
5438 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5439 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5440
5441+#ifdef CONFIG_PAX_PAGEEXEC
5442+extern pgprot_t PAGE_SHARED_NOEXEC;
5443+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5444+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5445+#else
5446+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5447+# define PAGE_COPY_NOEXEC PAGE_COPY
5448+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5449+#endif
5450+
5451 extern unsigned long page_kernel;
5452
5453 #ifdef MODULE
5454diff -urNp linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h
5455--- linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h 2011-05-19 00:06:34.000000000 -0400
5456+++ linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h 2011-05-22 19:36:30.000000000 -0400
5457@@ -115,6 +115,13 @@
5458 SRMMU_EXEC | SRMMU_REF)
5459 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5460 SRMMU_EXEC | SRMMU_REF)
5461+
5462+#ifdef CONFIG_PAX_PAGEEXEC
5463+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5464+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5465+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5466+#endif
5467+
5468 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5469 SRMMU_DIRTY | SRMMU_REF)
5470
5471diff -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
5472--- linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h 2011-05-19 00:06:34.000000000 -0400
5473+++ linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h 2011-05-22 19:36:30.000000000 -0400
5474@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(
5475
5476 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5477
5478-static void inline arch_read_lock(arch_rwlock_t *lock)
5479+static inline void arch_read_lock(arch_rwlock_t *lock)
5480 {
5481 unsigned long tmp1, tmp2;
5482
5483 __asm__ __volatile__ (
5484 "1: ldsw [%2], %0\n"
5485 " brlz,pn %0, 2f\n"
5486-"4: add %0, 1, %1\n"
5487+"4: addcc %0, 1, %1\n"
5488+
5489+#ifdef CONFIG_PAX_REFCOUNT
5490+" tvs %%icc, 6\n"
5491+#endif
5492+
5493 " cas [%2], %0, %1\n"
5494 " cmp %0, %1\n"
5495 " bne,pn %%icc, 1b\n"
5496@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_r
5497 " .previous"
5498 : "=&r" (tmp1), "=&r" (tmp2)
5499 : "r" (lock)
5500- : "memory");
5501+ : "memory", "cc");
5502 }
5503
5504-static int inline arch_read_trylock(arch_rwlock_t *lock)
5505+static inline int arch_read_trylock(arch_rwlock_t *lock)
5506 {
5507 int tmp1, tmp2;
5508
5509@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch
5510 "1: ldsw [%2], %0\n"
5511 " brlz,a,pn %0, 2f\n"
5512 " mov 0, %0\n"
5513-" add %0, 1, %1\n"
5514+" addcc %0, 1, %1\n"
5515+
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+" tvs %%icc, 6\n"
5518+#endif
5519+
5520 " cas [%2], %0, %1\n"
5521 " cmp %0, %1\n"
5522 " bne,pn %%icc, 1b\n"
5523@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch
5524 return tmp1;
5525 }
5526
5527-static void inline arch_read_unlock(arch_rwlock_t *lock)
5528+static inline void arch_read_unlock(arch_rwlock_t *lock)
5529 {
5530 unsigned long tmp1, tmp2;
5531
5532 __asm__ __volatile__(
5533 "1: lduw [%2], %0\n"
5534-" sub %0, 1, %1\n"
5535+" subcc %0, 1, %1\n"
5536+
5537+#ifdef CONFIG_PAX_REFCOUNT
5538+" tvs %%icc, 6\n"
5539+#endif
5540+
5541 " cas [%2], %0, %1\n"
5542 " cmp %0, %1\n"
5543 " bne,pn %%xcc, 1b\n"
5544@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch
5545 : "memory");
5546 }
5547
5548-static void inline arch_write_lock(arch_rwlock_t *lock)
5549+static inline void arch_write_lock(arch_rwlock_t *lock)
5550 {
5551 unsigned long mask, tmp1, tmp2;
5552
5553@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_
5554 : "memory");
5555 }
5556
5557-static void inline arch_write_unlock(arch_rwlock_t *lock)
5558+static inline void arch_write_unlock(arch_rwlock_t *lock)
5559 {
5560 __asm__ __volatile__(
5561 " stw %%g0, [%0]"
5562@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arc
5563 : "memory");
5564 }
5565
5566-static int inline arch_write_trylock(arch_rwlock_t *lock)
5567+static inline int arch_write_trylock(arch_rwlock_t *lock)
5568 {
5569 unsigned long mask, tmp1, tmp2, result;
5570
5571diff -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
5572--- linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h 2011-05-19 00:06:34.000000000 -0400
5573+++ linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h 2011-06-03 01:14:03.000000000 -0400
5574@@ -50,6 +50,8 @@ struct thread_info {
5575 unsigned long w_saved;
5576
5577 struct restart_block restart_block;
5578+
5579+ unsigned long lowest_stack;
5580 };
5581
5582 /*
5583diff -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
5584--- linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h 2011-05-19 00:06:34.000000000 -0400
5585+++ linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h 2011-06-03 01:14:21.000000000 -0400
5586@@ -63,6 +63,8 @@ struct thread_info {
5587 struct pt_regs *kern_una_regs;
5588 unsigned int kern_una_insn;
5589
5590+ unsigned long lowest_stack;
5591+
5592 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5593 };
5594
5595diff -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
5596--- linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
5597+++ linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
5598@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
5599
5600 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5601 {
5602- if (n && __access_ok((unsigned long) to, n))
5603+ if ((long)n < 0)
5604+ return n;
5605+
5606+ if (n && __access_ok((unsigned long) to, n)) {
5607+ if (!__builtin_constant_p(n))
5608+ check_object_size(from, n, true);
5609 return __copy_user(to, (__force void __user *) from, n);
5610- else
5611+ } else
5612 return n;
5613 }
5614
5615 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5616 {
5617+ if ((long)n < 0)
5618+ return n;
5619+
5620+ if (!__builtin_constant_p(n))
5621+ check_object_size(from, n, true);
5622+
5623 return __copy_user(to, (__force void __user *) from, n);
5624 }
5625
5626 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5627 {
5628- if (n && __access_ok((unsigned long) from, n))
5629+ if ((long)n < 0)
5630+ return n;
5631+
5632+ if (n && __access_ok((unsigned long) from, n)) {
5633+ if (!__builtin_constant_p(n))
5634+ check_object_size(to, n, false);
5635 return __copy_user((__force void __user *) to, from, n);
5636- else
5637+ } else
5638 return n;
5639 }
5640
5641 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5642 {
5643+ if ((long)n < 0)
5644+ return n;
5645+
5646 return __copy_user((__force void __user *) to, from, n);
5647 }
5648
5649diff -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
5650--- linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
5651+++ linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
5652@@ -10,6 +10,7 @@
5653 #include <linux/compiler.h>
5654 #include <linux/string.h>
5655 #include <linux/thread_info.h>
5656+#include <linux/kernel.h>
5657 #include <asm/asi.h>
5658 #include <asm/system.h>
5659 #include <asm/spitfire.h>
5660@@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
5661 static inline unsigned long __must_check
5662 copy_from_user(void *to, const void __user *from, unsigned long size)
5663 {
5664- unsigned long ret = ___copy_from_user(to, from, size);
5665+ unsigned long ret;
5666
5667+ if ((long)size < 0 || size > INT_MAX)
5668+ return size;
5669+
5670+ if (!__builtin_constant_p(size))
5671+ check_object_size(to, size, false);
5672+
5673+ ret = ___copy_from_user(to, from, size);
5674 if (unlikely(ret))
5675 ret = copy_from_user_fixup(to, from, size);
5676
5677@@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
5678 static inline unsigned long __must_check
5679 copy_to_user(void __user *to, const void *from, unsigned long size)
5680 {
5681- unsigned long ret = ___copy_to_user(to, from, size);
5682+ unsigned long ret;
5683+
5684+ if ((long)size < 0 || size > INT_MAX)
5685+ return size;
5686+
5687+ if (!__builtin_constant_p(size))
5688+ check_object_size(from, size, true);
5689
5690+ ret = ___copy_to_user(to, from, size);
5691 if (unlikely(ret))
5692 ret = copy_to_user_fixup(to, from, size);
5693 return ret;
5694diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess.h linux-2.6.39.1/arch/sparc/include/asm/uaccess.h
5695--- linux-2.6.39.1/arch/sparc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
5696+++ linux-2.6.39.1/arch/sparc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
5697@@ -1,5 +1,13 @@
5698 #ifndef ___ASM_SPARC_UACCESS_H
5699 #define ___ASM_SPARC_UACCESS_H
5700+
5701+#ifdef __KERNEL__
5702+#ifndef __ASSEMBLY__
5703+#include <linux/types.h>
5704+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5705+#endif
5706+#endif
5707+
5708 #if defined(__sparc__) && defined(__arch64__)
5709 #include <asm/uaccess_64.h>
5710 #else
5711diff -urNp linux-2.6.39.1/arch/sparc/kernel/iommu.c linux-2.6.39.1/arch/sparc/kernel/iommu.c
5712--- linux-2.6.39.1/arch/sparc/kernel/iommu.c 2011-05-19 00:06:34.000000000 -0400
5713+++ linux-2.6.39.1/arch/sparc/kernel/iommu.c 2011-05-22 19:36:30.000000000 -0400
5714@@ -824,7 +824,7 @@ static void dma_4u_sync_sg_for_cpu(struc
5715 spin_unlock_irqrestore(&iommu->lock, flags);
5716 }
5717
5718-static struct dma_map_ops sun4u_dma_ops = {
5719+static const struct dma_map_ops sun4u_dma_ops = {
5720 .alloc_coherent = dma_4u_alloc_coherent,
5721 .free_coherent = dma_4u_free_coherent,
5722 .map_page = dma_4u_map_page,
5723@@ -835,7 +835,7 @@ static struct dma_map_ops sun4u_dma_ops
5724 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
5725 };
5726
5727-struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5728+const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5729 EXPORT_SYMBOL(dma_ops);
5730
5731 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
5732diff -urNp linux-2.6.39.1/arch/sparc/kernel/ioport.c linux-2.6.39.1/arch/sparc/kernel/ioport.c
5733--- linux-2.6.39.1/arch/sparc/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
5734+++ linux-2.6.39.1/arch/sparc/kernel/ioport.c 2011-05-22 19:36:30.000000000 -0400
5735@@ -402,7 +402,7 @@ static void sbus_sync_sg_for_device(stru
5736 BUG();
5737 }
5738
5739-struct dma_map_ops sbus_dma_ops = {
5740+const struct dma_map_ops sbus_dma_ops = {
5741 .alloc_coherent = sbus_alloc_coherent,
5742 .free_coherent = sbus_free_coherent,
5743 .map_page = sbus_map_page,
5744@@ -653,7 +653,7 @@ static void pci32_sync_sg_for_device(str
5745 }
5746 }
5747
5748-struct dma_map_ops pci32_dma_ops = {
5749+const struct dma_map_ops pci32_dma_ops = {
5750 .alloc_coherent = pci32_alloc_coherent,
5751 .free_coherent = pci32_free_coherent,
5752 .map_page = pci32_map_page,
5753diff -urNp linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c
5754--- linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c 2011-05-19 00:06:34.000000000 -0400
5755+++ linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c 2011-05-22 19:36:30.000000000 -0400
5756@@ -164,7 +164,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5757 regs->npc = regs->pc + 4;
5758 }
5759
5760-struct kgdb_arch arch_kgdb_ops = {
5761+const struct kgdb_arch arch_kgdb_ops = {
5762 /* Breakpoint instruction: ta 0x7d */
5763 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
5764 };
5765diff -urNp linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c
5766--- linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c 2011-05-19 00:06:34.000000000 -0400
5767+++ linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c 2011-05-22 19:36:30.000000000 -0400
5768@@ -187,7 +187,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5769 regs->tnpc = regs->tpc + 4;
5770 }
5771
5772-struct kgdb_arch arch_kgdb_ops = {
5773+const struct kgdb_arch arch_kgdb_ops = {
5774 /* Breakpoint instruction: ta 0x72 */
5775 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
5776 };
5777diff -urNp linux-2.6.39.1/arch/sparc/kernel/Makefile linux-2.6.39.1/arch/sparc/kernel/Makefile
5778--- linux-2.6.39.1/arch/sparc/kernel/Makefile 2011-05-19 00:06:34.000000000 -0400
5779+++ linux-2.6.39.1/arch/sparc/kernel/Makefile 2011-05-22 19:36:30.000000000 -0400
5780@@ -3,7 +3,7 @@
5781 #
5782
5783 asflags-y := -ansi
5784-ccflags-y := -Werror
5785+#ccflags-y := -Werror
5786
5787 extra-y := head_$(BITS).o
5788 extra-y += init_task.o
5789diff -urNp linux-2.6.39.1/arch/sparc/kernel/pcic.c linux-2.6.39.1/arch/sparc/kernel/pcic.c
5790--- linux-2.6.39.1/arch/sparc/kernel/pcic.c 2011-05-19 00:06:34.000000000 -0400
5791+++ linux-2.6.39.1/arch/sparc/kernel/pcic.c 2011-05-22 19:36:30.000000000 -0400
5792@@ -268,7 +268,7 @@ static int pcic_write_config(struct pci_
5793 return -EINVAL;
5794 }
5795
5796-static struct pci_ops pcic_ops = {
5797+static const struct pci_ops pcic_ops = {
5798 .read = pcic_read_config,
5799 .write = pcic_write_config,
5800 };
5801diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_common.c linux-2.6.39.1/arch/sparc/kernel/pci_common.c
5802--- linux-2.6.39.1/arch/sparc/kernel/pci_common.c 2011-05-19 00:06:34.000000000 -0400
5803+++ linux-2.6.39.1/arch/sparc/kernel/pci_common.c 2011-05-22 19:36:30.000000000 -0400
5804@@ -249,7 +249,7 @@ static int sun4u_write_pci_cfg(struct pc
5805 return PCIBIOS_SUCCESSFUL;
5806 }
5807
5808-struct pci_ops sun4u_pci_ops = {
5809+const struct pci_ops sun4u_pci_ops = {
5810 .read = sun4u_read_pci_cfg,
5811 .write = sun4u_write_pci_cfg,
5812 };
5813@@ -310,7 +310,7 @@ static int sun4v_write_pci_cfg(struct pc
5814 return PCIBIOS_SUCCESSFUL;
5815 }
5816
5817-struct pci_ops sun4v_pci_ops = {
5818+const struct pci_ops sun4v_pci_ops = {
5819 .read = sun4v_read_pci_cfg,
5820 .write = sun4v_write_pci_cfg,
5821 };
5822diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_impl.h linux-2.6.39.1/arch/sparc/kernel/pci_impl.h
5823--- linux-2.6.39.1/arch/sparc/kernel/pci_impl.h 2011-05-19 00:06:34.000000000 -0400
5824+++ linux-2.6.39.1/arch/sparc/kernel/pci_impl.h 2011-05-22 19:36:30.000000000 -0400
5825@@ -175,8 +175,8 @@ extern void pci_config_write8(u8 *addr,
5826 extern void pci_config_write16(u16 *addr, u16 val);
5827 extern void pci_config_write32(u32 *addr, u32 val);
5828
5829-extern struct pci_ops sun4u_pci_ops;
5830-extern struct pci_ops sun4v_pci_ops;
5831+extern const struct pci_ops sun4u_pci_ops;
5832+extern const struct pci_ops sun4v_pci_ops;
5833
5834 extern volatile int pci_poke_in_progress;
5835 extern volatile int pci_poke_cpu;
5836diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c
5837--- linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c 2011-05-19 00:06:34.000000000 -0400
5838+++ linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c 2011-05-22 19:36:30.000000000 -0400
5839@@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
5840 spin_unlock_irqrestore(&iommu->lock, flags);
5841 }
5842
5843-static struct dma_map_ops sun4v_dma_ops = {
5844+static const struct dma_map_ops sun4v_dma_ops = {
5845 .alloc_coherent = dma_4v_alloc_coherent,
5846 .free_coherent = dma_4v_free_coherent,
5847 .map_page = dma_4v_map_page,
5848diff -urNp linux-2.6.39.1/arch/sparc/kernel/process_32.c linux-2.6.39.1/arch/sparc/kernel/process_32.c
5849--- linux-2.6.39.1/arch/sparc/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
5850+++ linux-2.6.39.1/arch/sparc/kernel/process_32.c 2011-05-22 19:41:32.000000000 -0400
5851@@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
5852 rw->ins[4], rw->ins[5],
5853 rw->ins[6],
5854 rw->ins[7]);
5855- printk("%pS\n", (void *) rw->ins[7]);
5856+ printk("%pA\n", (void *) rw->ins[7]);
5857 rw = (struct reg_window32 *) rw->ins[6];
5858 }
5859 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5860@@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
5861
5862 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5863 r->psr, r->pc, r->npc, r->y, print_tainted());
5864- printk("PC: <%pS>\n", (void *) r->pc);
5865+ printk("PC: <%pA>\n", (void *) r->pc);
5866 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5867 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5868 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5869 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5870 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5871 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5872- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5873+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5874
5875 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5876 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5877@@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
5878 rw = (struct reg_window32 *) fp;
5879 pc = rw->ins[7];
5880 printk("[%08lx : ", pc);
5881- printk("%pS ] ", (void *) pc);
5882+ printk("%pA ] ", (void *) pc);
5883 fp = rw->ins[6];
5884 } while (++count < 16);
5885 printk("\n");
5886diff -urNp linux-2.6.39.1/arch/sparc/kernel/process_64.c linux-2.6.39.1/arch/sparc/kernel/process_64.c
5887--- linux-2.6.39.1/arch/sparc/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
5888+++ linux-2.6.39.1/arch/sparc/kernel/process_64.c 2011-05-22 19:41:32.000000000 -0400
5889@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
5890 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5891 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5892 if (regs->tstate & TSTATE_PRIV)
5893- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5894+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5895 }
5896
5897 void show_regs(struct pt_regs *regs)
5898 {
5899 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5900 regs->tpc, regs->tnpc, regs->y, print_tainted());
5901- printk("TPC: <%pS>\n", (void *) regs->tpc);
5902+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5903 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5904 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5905 regs->u_regs[3]);
5906@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5907 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5908 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5909 regs->u_regs[15]);
5910- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5911+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5912 show_regwindow(regs);
5913 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5914 }
5915@@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
5916 ((tp && tp->task) ? tp->task->pid : -1));
5917
5918 if (gp->tstate & TSTATE_PRIV) {
5919- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5920+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5921 (void *) gp->tpc,
5922 (void *) gp->o7,
5923 (void *) gp->i7,
5924diff -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
5925--- linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c 2011-05-19 00:06:34.000000000 -0400
5926+++ linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c 2011-05-22 19:36:30.000000000 -0400
5927@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
5928 if (ARCH_SUN4C && len > 0x20000000)
5929 return -ENOMEM;
5930 if (!addr)
5931- addr = TASK_UNMAPPED_BASE;
5932+ addr = current->mm->mmap_base;
5933
5934 if (flags & MAP_SHARED)
5935 addr = COLOUR_ALIGN(addr);
5936@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
5937 }
5938 if (TASK_SIZE - PAGE_SIZE - len < addr)
5939 return -ENOMEM;
5940- if (!vmm || addr + len <= vmm->vm_start)
5941+ if (check_heap_stack_gap(vmm, addr, len))
5942 return addr;
5943 addr = vmm->vm_end;
5944 if (flags & MAP_SHARED)
5945diff -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
5946--- linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c 2011-05-19 00:06:34.000000000 -0400
5947+++ linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c 2011-05-22 19:36:30.000000000 -0400
5948@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
5949 /* We do not accept a shared mapping if it would violate
5950 * cache aliasing constraints.
5951 */
5952- if ((flags & MAP_SHARED) &&
5953+ if ((filp || (flags & MAP_SHARED)) &&
5954 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5955 return -EINVAL;
5956 return addr;
5957@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
5958 if (filp || (flags & MAP_SHARED))
5959 do_color_align = 1;
5960
5961+#ifdef CONFIG_PAX_RANDMMAP
5962+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5963+#endif
5964+
5965 if (addr) {
5966 if (do_color_align)
5967 addr = COLOUR_ALIGN(addr, pgoff);
5968@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
5969 addr = PAGE_ALIGN(addr);
5970
5971 vma = find_vma(mm, addr);
5972- if (task_size - len >= addr &&
5973- (!vma || addr + len <= vma->vm_start))
5974+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5975 return addr;
5976 }
5977
5978 if (len > mm->cached_hole_size) {
5979- start_addr = addr = mm->free_area_cache;
5980+ start_addr = addr = mm->free_area_cache;
5981 } else {
5982- start_addr = addr = TASK_UNMAPPED_BASE;
5983+ start_addr = addr = mm->mmap_base;
5984 mm->cached_hole_size = 0;
5985 }
5986
5987@@ -174,14 +177,14 @@ full_search:
5988 vma = find_vma(mm, VA_EXCLUDE_END);
5989 }
5990 if (unlikely(task_size < addr)) {
5991- if (start_addr != TASK_UNMAPPED_BASE) {
5992- start_addr = addr = TASK_UNMAPPED_BASE;
5993+ if (start_addr != mm->mmap_base) {
5994+ start_addr = addr = mm->mmap_base;
5995 mm->cached_hole_size = 0;
5996 goto full_search;
5997 }
5998 return -ENOMEM;
5999 }
6000- if (likely(!vma || addr + len <= vma->vm_start)) {
6001+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6002 /*
6003 * Remember the place where we stopped the search:
6004 */
6005@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
6006 /* We do not accept a shared mapping if it would violate
6007 * cache aliasing constraints.
6008 */
6009- if ((flags & MAP_SHARED) &&
6010+ if ((filp || (flags & MAP_SHARED)) &&
6011 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6012 return -EINVAL;
6013 return addr;
6014@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
6015 addr = PAGE_ALIGN(addr);
6016
6017 vma = find_vma(mm, addr);
6018- if (task_size - len >= addr &&
6019- (!vma || addr + len <= vma->vm_start))
6020+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6021 return addr;
6022 }
6023
6024@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
6025 /* make sure it can fit in the remaining address space */
6026 if (likely(addr > len)) {
6027 vma = find_vma(mm, addr-len);
6028- if (!vma || addr <= vma->vm_start) {
6029+ if (check_heap_stack_gap(vma, addr - len, len)) {
6030 /* remember the address as a hint for next time */
6031 return (mm->free_area_cache = addr-len);
6032 }
6033@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct fi
6034 if (unlikely(mm->mmap_base < len))
6035 goto bottomup;
6036
6037- addr = mm->mmap_base-len;
6038- if (do_color_align)
6039- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6040+ addr = mm->mmap_base - len;
6041
6042 do {
6043+ if (do_color_align)
6044+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6045 /*
6046 * Lookup failure means no vma is above this address,
6047 * else if new region fits below vma->vm_start,
6048 * return with success:
6049 */
6050 vma = find_vma(mm, addr);
6051- if (likely(!vma || addr+len <= vma->vm_start)) {
6052+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6053 /* remember the address as a hint for next time */
6054 return (mm->free_area_cache = addr);
6055 }
6056@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct fi
6057 mm->cached_hole_size = vma->vm_start - addr;
6058
6059 /* try just below the current vma->vm_start */
6060- addr = vma->vm_start-len;
6061- if (do_color_align)
6062- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6063- } while (likely(len < vma->vm_start));
6064+ addr = skip_heap_stack_gap(vma, len);
6065+ } while (!IS_ERR_VALUE(addr));
6066
6067 bottomup:
6068 /*
6069@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_str
6070 gap == RLIM_INFINITY ||
6071 sysctl_legacy_va_layout) {
6072 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6073+
6074+#ifdef CONFIG_PAX_RANDMMAP
6075+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6076+ mm->mmap_base += mm->delta_mmap;
6077+#endif
6078+
6079 mm->get_unmapped_area = arch_get_unmapped_area;
6080 mm->unmap_area = arch_unmap_area;
6081 } else {
6082@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_str
6083 gap = (task_size / 6 * 5);
6084
6085 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6086+
6087+#ifdef CONFIG_PAX_RANDMMAP
6088+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6089+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6090+#endif
6091+
6092 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6093 mm->unmap_area = arch_unmap_area_topdown;
6094 }
6095diff -urNp linux-2.6.39.1/arch/sparc/kernel/traps_32.c linux-2.6.39.1/arch/sparc/kernel/traps_32.c
6096--- linux-2.6.39.1/arch/sparc/kernel/traps_32.c 2011-05-19 00:06:34.000000000 -0400
6097+++ linux-2.6.39.1/arch/sparc/kernel/traps_32.c 2011-06-13 21:29:23.000000000 -0400
6098@@ -44,6 +44,8 @@ static void instruction_dump(unsigned lo
6099 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6100 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6101
6102+extern void gr_handle_kernel_exploit(void);
6103+
6104 void die_if_kernel(char *str, struct pt_regs *regs)
6105 {
6106 static int die_counter;
6107@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_
6108 count++ < 30 &&
6109 (((unsigned long) rw) >= PAGE_OFFSET) &&
6110 !(((unsigned long) rw) & 0x7)) {
6111- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6112+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6113 (void *) rw->ins[7]);
6114 rw = (struct reg_window32 *)rw->ins[6];
6115 }
6116 }
6117 printk("Instruction DUMP:");
6118 instruction_dump ((unsigned long *) regs->pc);
6119- if(regs->psr & PSR_PS)
6120+ if(regs->psr & PSR_PS) {
6121+ gr_handle_kernel_exploit();
6122 do_exit(SIGKILL);
6123+ }
6124 do_exit(SIGSEGV);
6125 }
6126
6127diff -urNp linux-2.6.39.1/arch/sparc/kernel/traps_64.c linux-2.6.39.1/arch/sparc/kernel/traps_64.c
6128--- linux-2.6.39.1/arch/sparc/kernel/traps_64.c 2011-05-19 00:06:34.000000000 -0400
6129+++ linux-2.6.39.1/arch/sparc/kernel/traps_64.c 2011-06-13 21:28:54.000000000 -0400
6130@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
6131 i + 1,
6132 p->trapstack[i].tstate, p->trapstack[i].tpc,
6133 p->trapstack[i].tnpc, p->trapstack[i].tt);
6134- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6135+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6136 }
6137 }
6138
6139@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
6140
6141 lvl -= 0x100;
6142 if (regs->tstate & TSTATE_PRIV) {
6143+
6144+#ifdef CONFIG_PAX_REFCOUNT
6145+ if (lvl == 6)
6146+ pax_report_refcount_overflow(regs);
6147+#endif
6148+
6149 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6150 die_if_kernel(buffer, regs);
6151 }
6152@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
6153 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6154 {
6155 char buffer[32];
6156-
6157+
6158 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6159 0, lvl, SIGTRAP) == NOTIFY_STOP)
6160 return;
6161
6162+#ifdef CONFIG_PAX_REFCOUNT
6163+ if (lvl == 6)
6164+ pax_report_refcount_overflow(regs);
6165+#endif
6166+
6167 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6168
6169 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6170@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
6171 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6172 printk("%s" "ERROR(%d): ",
6173 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6174- printk("TPC<%pS>\n", (void *) regs->tpc);
6175+ printk("TPC<%pA>\n", (void *) regs->tpc);
6176 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6177 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6178 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6179@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
6180 smp_processor_id(),
6181 (type & 0x1) ? 'I' : 'D',
6182 regs->tpc);
6183- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6184+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6185 panic("Irrecoverable Cheetah+ parity error.");
6186 }
6187
6188@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
6189 smp_processor_id(),
6190 (type & 0x1) ? 'I' : 'D',
6191 regs->tpc);
6192- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6193+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6194 }
6195
6196 struct sun4v_error_entry {
6197@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
6198
6199 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6200 regs->tpc, tl);
6201- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6202+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6203 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6204- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6205+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6206 (void *) regs->u_regs[UREG_I7]);
6207 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6208 "pte[%lx] error[%lx]\n",
6209@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
6210
6211 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6212 regs->tpc, tl);
6213- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6214+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6215 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6216- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6217+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6218 (void *) regs->u_regs[UREG_I7]);
6219 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6220 "pte[%lx] error[%lx]\n",
6221@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk,
6222 fp = (unsigned long)sf->fp + STACK_BIAS;
6223 }
6224
6225- printk(" [%016lx] %pS\n", pc, (void *) pc);
6226+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6227 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6228 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6229 int index = tsk->curr_ret_stack;
6230 if (tsk->ret_stack && index >= graph) {
6231 pc = tsk->ret_stack[index - graph].ret;
6232- printk(" [%016lx] %pS\n", pc, (void *) pc);
6233+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6234 graph++;
6235 }
6236 }
6237@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_
6238 return (struct reg_window *) (fp + STACK_BIAS);
6239 }
6240
6241+extern void gr_handle_kernel_exploit(void);
6242+
6243 void die_if_kernel(char *str, struct pt_regs *regs)
6244 {
6245 static int die_counter;
6246@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_
6247 while (rw &&
6248 count++ < 30 &&
6249 kstack_valid(tp, (unsigned long) rw)) {
6250- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6251+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6252 (void *) rw->ins[7]);
6253
6254 rw = kernel_stack_up(rw);
6255@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_
6256 }
6257 user_instruction_dump ((unsigned int __user *) regs->tpc);
6258 }
6259- if (regs->tstate & TSTATE_PRIV)
6260+ if (regs->tstate & TSTATE_PRIV) {
6261+ gr_handle_kernel_exploit();
6262 do_exit(SIGKILL);
6263+ }
6264 do_exit(SIGSEGV);
6265 }
6266 EXPORT_SYMBOL(die_if_kernel);
6267diff -urNp linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c
6268--- linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c 2011-05-19 00:06:34.000000000 -0400
6269+++ linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c 2011-05-22 19:41:32.000000000 -0400
6270@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs
6271 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6272
6273 if (__ratelimit(&ratelimit)) {
6274- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6275+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6276 regs->tpc, (void *) regs->tpc);
6277 }
6278 }
6279diff -urNp linux-2.6.39.1/arch/sparc/lib/atomic_64.S linux-2.6.39.1/arch/sparc/lib/atomic_64.S
6280--- linux-2.6.39.1/arch/sparc/lib/atomic_64.S 2011-05-19 00:06:34.000000000 -0400
6281+++ linux-2.6.39.1/arch/sparc/lib/atomic_64.S 2011-05-22 19:36:30.000000000 -0400
6282@@ -18,7 +18,12 @@
6283 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6284 BACKOFF_SETUP(%o2)
6285 1: lduw [%o1], %g1
6286- add %g1, %o0, %g7
6287+ addcc %g1, %o0, %g7
6288+
6289+#ifdef CONFIG_PAX_REFCOUNT
6290+ tvs %icc, 6
6291+#endif
6292+
6293 cas [%o1], %g1, %g7
6294 cmp %g1, %g7
6295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6296@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
6297 2: BACKOFF_SPIN(%o2, %o3, 1b)
6298 .size atomic_add, .-atomic_add
6299
6300+ .globl atomic_add_unchecked
6301+ .type atomic_add_unchecked,#function
6302+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6303+ BACKOFF_SETUP(%o2)
6304+1: lduw [%o1], %g1
6305+ add %g1, %o0, %g7
6306+ cas [%o1], %g1, %g7
6307+ cmp %g1, %g7
6308+ bne,pn %icc, 2f
6309+ nop
6310+ retl
6311+ nop
6312+2: BACKOFF_SPIN(%o2, %o3, 1b)
6313+ .size atomic_add_unchecked, .-atomic_add_unchecked
6314+
6315 .globl atomic_sub
6316 .type atomic_sub,#function
6317 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6318 BACKOFF_SETUP(%o2)
6319 1: lduw [%o1], %g1
6320- sub %g1, %o0, %g7
6321+ subcc %g1, %o0, %g7
6322+
6323+#ifdef CONFIG_PAX_REFCOUNT
6324+ tvs %icc, 6
6325+#endif
6326+
6327 cas [%o1], %g1, %g7
6328 cmp %g1, %g7
6329 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6330@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
6331 2: BACKOFF_SPIN(%o2, %o3, 1b)
6332 .size atomic_sub, .-atomic_sub
6333
6334+ .globl atomic_sub_unchecked
6335+ .type atomic_sub_unchecked,#function
6336+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6337+ BACKOFF_SETUP(%o2)
6338+1: lduw [%o1], %g1
6339+ sub %g1, %o0, %g7
6340+ cas [%o1], %g1, %g7
6341+ cmp %g1, %g7
6342+ bne,pn %icc, 2f
6343+ nop
6344+ retl
6345+ nop
6346+2: BACKOFF_SPIN(%o2, %o3, 1b)
6347+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6348+
6349 .globl atomic_add_ret
6350 .type atomic_add_ret,#function
6351 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6352 BACKOFF_SETUP(%o2)
6353 1: lduw [%o1], %g1
6354- add %g1, %o0, %g7
6355+ addcc %g1, %o0, %g7
6356+
6357+#ifdef CONFIG_PAX_REFCOUNT
6358+ tvs %icc, 6
6359+#endif
6360+
6361 cas [%o1], %g1, %g7
6362 cmp %g1, %g7
6363 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6364@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
6365 2: BACKOFF_SPIN(%o2, %o3, 1b)
6366 .size atomic_add_ret, .-atomic_add_ret
6367
6368+ .globl atomic_add_ret_unchecked
6369+ .type atomic_add_ret_unchecked,#function
6370+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6371+ BACKOFF_SETUP(%o2)
6372+1: lduw [%o1], %g1
6373+ addcc %g1, %o0, %g7
6374+ cas [%o1], %g1, %g7
6375+ cmp %g1, %g7
6376+ bne,pn %icc, 2f
6377+ add %g7, %o0, %g7
6378+ sra %g7, 0, %o0
6379+ retl
6380+ nop
6381+2: BACKOFF_SPIN(%o2, %o3, 1b)
6382+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6383+
6384 .globl atomic_sub_ret
6385 .type atomic_sub_ret,#function
6386 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6387 BACKOFF_SETUP(%o2)
6388 1: lduw [%o1], %g1
6389- sub %g1, %o0, %g7
6390+ subcc %g1, %o0, %g7
6391+
6392+#ifdef CONFIG_PAX_REFCOUNT
6393+ tvs %icc, 6
6394+#endif
6395+
6396 cas [%o1], %g1, %g7
6397 cmp %g1, %g7
6398 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6399@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
6400 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403- add %g1, %o0, %g7
6404+ addcc %g1, %o0, %g7
6405+
6406+#ifdef CONFIG_PAX_REFCOUNT
6407+ tvs %xcc, 6
6408+#endif
6409+
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 .size atomic64_add, .-atomic64_add
6416
6417+ .globl atomic64_add_unchecked
6418+ .type atomic64_add_unchecked,#function
6419+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6420+ BACKOFF_SETUP(%o2)
6421+1: ldx [%o1], %g1
6422+ addcc %g1, %o0, %g7
6423+ casx [%o1], %g1, %g7
6424+ cmp %g1, %g7
6425+ bne,pn %xcc, 2f
6426+ nop
6427+ retl
6428+ nop
6429+2: BACKOFF_SPIN(%o2, %o3, 1b)
6430+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6431+
6432 .globl atomic64_sub
6433 .type atomic64_sub,#function
6434 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6435 BACKOFF_SETUP(%o2)
6436 1: ldx [%o1], %g1
6437- sub %g1, %o0, %g7
6438+ subcc %g1, %o0, %g7
6439+
6440+#ifdef CONFIG_PAX_REFCOUNT
6441+ tvs %xcc, 6
6442+#endif
6443+
6444 casx [%o1], %g1, %g7
6445 cmp %g1, %g7
6446 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6447@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
6448 2: BACKOFF_SPIN(%o2, %o3, 1b)
6449 .size atomic64_sub, .-atomic64_sub
6450
6451+ .globl atomic64_sub_unchecked
6452+ .type atomic64_sub_unchecked,#function
6453+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6454+ BACKOFF_SETUP(%o2)
6455+1: ldx [%o1], %g1
6456+ subcc %g1, %o0, %g7
6457+ casx [%o1], %g1, %g7
6458+ cmp %g1, %g7
6459+ bne,pn %xcc, 2f
6460+ nop
6461+ retl
6462+ nop
6463+2: BACKOFF_SPIN(%o2, %o3, 1b)
6464+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6465+
6466 .globl atomic64_add_ret
6467 .type atomic64_add_ret,#function
6468 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6469 BACKOFF_SETUP(%o2)
6470 1: ldx [%o1], %g1
6471- add %g1, %o0, %g7
6472+ addcc %g1, %o0, %g7
6473+
6474+#ifdef CONFIG_PAX_REFCOUNT
6475+ tvs %xcc, 6
6476+#endif
6477+
6478 casx [%o1], %g1, %g7
6479 cmp %g1, %g7
6480 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6481@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
6482 2: BACKOFF_SPIN(%o2, %o3, 1b)
6483 .size atomic64_add_ret, .-atomic64_add_ret
6484
6485+ .globl atomic64_add_ret_unchecked
6486+ .type atomic64_add_ret_unchecked,#function
6487+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6488+ BACKOFF_SETUP(%o2)
6489+1: ldx [%o1], %g1
6490+ addcc %g1, %o0, %g7
6491+ casx [%o1], %g1, %g7
6492+ cmp %g1, %g7
6493+ bne,pn %xcc, 2f
6494+ add %g7, %o0, %g7
6495+ mov %g7, %o0
6496+ retl
6497+ nop
6498+2: BACKOFF_SPIN(%o2, %o3, 1b)
6499+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6500+
6501 .globl atomic64_sub_ret
6502 .type atomic64_sub_ret,#function
6503 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6504 BACKOFF_SETUP(%o2)
6505 1: ldx [%o1], %g1
6506- sub %g1, %o0, %g7
6507+ subcc %g1, %o0, %g7
6508+
6509+#ifdef CONFIG_PAX_REFCOUNT
6510+ tvs %xcc, 6
6511+#endif
6512+
6513 casx [%o1], %g1, %g7
6514 cmp %g1, %g7
6515 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6516diff -urNp linux-2.6.39.1/arch/sparc/lib/ksyms.c linux-2.6.39.1/arch/sparc/lib/ksyms.c
6517--- linux-2.6.39.1/arch/sparc/lib/ksyms.c 2011-05-19 00:06:34.000000000 -0400
6518+++ linux-2.6.39.1/arch/sparc/lib/ksyms.c 2011-05-22 19:36:30.000000000 -0400
6519@@ -142,12 +142,17 @@ EXPORT_SYMBOL(__downgrade_write);
6520
6521 /* Atomic counter implementation. */
6522 EXPORT_SYMBOL(atomic_add);
6523+EXPORT_SYMBOL(atomic_add_unchecked);
6524 EXPORT_SYMBOL(atomic_add_ret);
6525 EXPORT_SYMBOL(atomic_sub);
6526+EXPORT_SYMBOL(atomic_sub_unchecked);
6527 EXPORT_SYMBOL(atomic_sub_ret);
6528 EXPORT_SYMBOL(atomic64_add);
6529+EXPORT_SYMBOL(atomic64_add_unchecked);
6530 EXPORT_SYMBOL(atomic64_add_ret);
6531+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6532 EXPORT_SYMBOL(atomic64_sub);
6533+EXPORT_SYMBOL(atomic64_sub_unchecked);
6534 EXPORT_SYMBOL(atomic64_sub_ret);
6535
6536 /* Atomic bit operations. */
6537diff -urNp linux-2.6.39.1/arch/sparc/lib/Makefile linux-2.6.39.1/arch/sparc/lib/Makefile
6538--- linux-2.6.39.1/arch/sparc/lib/Makefile 2011-05-19 00:06:34.000000000 -0400
6539+++ linux-2.6.39.1/arch/sparc/lib/Makefile 2011-05-22 19:36:30.000000000 -0400
6540@@ -2,7 +2,7 @@
6541 #
6542
6543 asflags-y := -ansi -DST_DIV0=0x02
6544-ccflags-y := -Werror
6545+#ccflags-y := -Werror
6546
6547 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6548 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6549diff -urNp linux-2.6.39.1/arch/sparc/Makefile linux-2.6.39.1/arch/sparc/Makefile
6550--- linux-2.6.39.1/arch/sparc/Makefile 2011-05-19 00:06:34.000000000 -0400
6551+++ linux-2.6.39.1/arch/sparc/Makefile 2011-05-22 19:41:32.000000000 -0400
6552@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
6553 # Export what is needed by arch/sparc/boot/Makefile
6554 export VMLINUX_INIT VMLINUX_MAIN
6555 VMLINUX_INIT := $(head-y) $(init-y)
6556-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
6557+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
6558 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
6559 VMLINUX_MAIN += $(drivers-y) $(net-y)
6560
6561diff -urNp linux-2.6.39.1/arch/sparc/mm/fault_32.c linux-2.6.39.1/arch/sparc/mm/fault_32.c
6562--- linux-2.6.39.1/arch/sparc/mm/fault_32.c 2011-05-19 00:06:34.000000000 -0400
6563+++ linux-2.6.39.1/arch/sparc/mm/fault_32.c 2011-05-22 19:36:30.000000000 -0400
6564@@ -22,6 +22,9 @@
6565 #include <linux/interrupt.h>
6566 #include <linux/module.h>
6567 #include <linux/kdebug.h>
6568+#include <linux/slab.h>
6569+#include <linux/pagemap.h>
6570+#include <linux/compiler.h>
6571
6572 #include <asm/system.h>
6573 #include <asm/page.h>
6574@@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
6575 return safe_compute_effective_address(regs, insn);
6576 }
6577
6578+#ifdef CONFIG_PAX_PAGEEXEC
6579+#ifdef CONFIG_PAX_DLRESOLVE
6580+static void pax_emuplt_close(struct vm_area_struct *vma)
6581+{
6582+ vma->vm_mm->call_dl_resolve = 0UL;
6583+}
6584+
6585+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6586+{
6587+ unsigned int *kaddr;
6588+
6589+ vmf->page = alloc_page(GFP_HIGHUSER);
6590+ if (!vmf->page)
6591+ return VM_FAULT_OOM;
6592+
6593+ kaddr = kmap(vmf->page);
6594+ memset(kaddr, 0, PAGE_SIZE);
6595+ kaddr[0] = 0x9DE3BFA8U; /* save */
6596+ flush_dcache_page(vmf->page);
6597+ kunmap(vmf->page);
6598+ return VM_FAULT_MAJOR;
6599+}
6600+
6601+static const struct vm_operations_struct pax_vm_ops = {
6602+ .close = pax_emuplt_close,
6603+ .fault = pax_emuplt_fault
6604+};
6605+
6606+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6607+{
6608+ int ret;
6609+
6610+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6611+ vma->vm_mm = current->mm;
6612+ vma->vm_start = addr;
6613+ vma->vm_end = addr + PAGE_SIZE;
6614+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6615+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6616+ vma->vm_ops = &pax_vm_ops;
6617+
6618+ ret = insert_vm_struct(current->mm, vma);
6619+ if (ret)
6620+ return ret;
6621+
6622+ ++current->mm->total_vm;
6623+ return 0;
6624+}
6625+#endif
6626+
6627+/*
6628+ * PaX: decide what to do with offenders (regs->pc = fault address)
6629+ *
6630+ * returns 1 when task should be killed
6631+ * 2 when patched PLT trampoline was detected
6632+ * 3 when unpatched PLT trampoline was detected
6633+ */
6634+static int pax_handle_fetch_fault(struct pt_regs *regs)
6635+{
6636+
6637+#ifdef CONFIG_PAX_EMUPLT
6638+ int err;
6639+
6640+ do { /* PaX: patched PLT emulation #1 */
6641+ unsigned int sethi1, sethi2, jmpl;
6642+
6643+ err = get_user(sethi1, (unsigned int *)regs->pc);
6644+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6645+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6646+
6647+ if (err)
6648+ break;
6649+
6650+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6651+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6652+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6653+ {
6654+ unsigned int addr;
6655+
6656+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6657+ addr = regs->u_regs[UREG_G1];
6658+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6659+ regs->pc = addr;
6660+ regs->npc = addr+4;
6661+ return 2;
6662+ }
6663+ } while (0);
6664+
6665+ { /* PaX: patched PLT emulation #2 */
6666+ unsigned int ba;
6667+
6668+ err = get_user(ba, (unsigned int *)regs->pc);
6669+
6670+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6671+ unsigned int addr;
6672+
6673+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6674+ regs->pc = addr;
6675+ regs->npc = addr+4;
6676+ return 2;
6677+ }
6678+ }
6679+
6680+ do { /* PaX: patched PLT emulation #3 */
6681+ unsigned int sethi, jmpl, nop;
6682+
6683+ err = get_user(sethi, (unsigned int *)regs->pc);
6684+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6685+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6686+
6687+ if (err)
6688+ break;
6689+
6690+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6691+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6692+ nop == 0x01000000U)
6693+ {
6694+ unsigned int addr;
6695+
6696+ addr = (sethi & 0x003FFFFFU) << 10;
6697+ regs->u_regs[UREG_G1] = addr;
6698+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6699+ regs->pc = addr;
6700+ regs->npc = addr+4;
6701+ return 2;
6702+ }
6703+ } while (0);
6704+
6705+ do { /* PaX: unpatched PLT emulation step 1 */
6706+ unsigned int sethi, ba, nop;
6707+
6708+ err = get_user(sethi, (unsigned int *)regs->pc);
6709+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6710+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6711+
6712+ if (err)
6713+ break;
6714+
6715+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6716+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6717+ nop == 0x01000000U)
6718+ {
6719+ unsigned int addr, save, call;
6720+
6721+ if ((ba & 0xFFC00000U) == 0x30800000U)
6722+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6723+ else
6724+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6725+
6726+ err = get_user(save, (unsigned int *)addr);
6727+ err |= get_user(call, (unsigned int *)(addr+4));
6728+ err |= get_user(nop, (unsigned int *)(addr+8));
6729+ if (err)
6730+ break;
6731+
6732+#ifdef CONFIG_PAX_DLRESOLVE
6733+ if (save == 0x9DE3BFA8U &&
6734+ (call & 0xC0000000U) == 0x40000000U &&
6735+ nop == 0x01000000U)
6736+ {
6737+ struct vm_area_struct *vma;
6738+ unsigned long call_dl_resolve;
6739+
6740+ down_read(&current->mm->mmap_sem);
6741+ call_dl_resolve = current->mm->call_dl_resolve;
6742+ up_read(&current->mm->mmap_sem);
6743+ if (likely(call_dl_resolve))
6744+ goto emulate;
6745+
6746+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6747+
6748+ down_write(&current->mm->mmap_sem);
6749+ if (current->mm->call_dl_resolve) {
6750+ call_dl_resolve = current->mm->call_dl_resolve;
6751+ up_write(&current->mm->mmap_sem);
6752+ if (vma)
6753+ kmem_cache_free(vm_area_cachep, vma);
6754+ goto emulate;
6755+ }
6756+
6757+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6758+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6759+ up_write(&current->mm->mmap_sem);
6760+ if (vma)
6761+ kmem_cache_free(vm_area_cachep, vma);
6762+ return 1;
6763+ }
6764+
6765+ if (pax_insert_vma(vma, call_dl_resolve)) {
6766+ up_write(&current->mm->mmap_sem);
6767+ kmem_cache_free(vm_area_cachep, vma);
6768+ return 1;
6769+ }
6770+
6771+ current->mm->call_dl_resolve = call_dl_resolve;
6772+ up_write(&current->mm->mmap_sem);
6773+
6774+emulate:
6775+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6776+ regs->pc = call_dl_resolve;
6777+ regs->npc = addr+4;
6778+ return 3;
6779+ }
6780+#endif
6781+
6782+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6783+ if ((save & 0xFFC00000U) == 0x05000000U &&
6784+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6785+ nop == 0x01000000U)
6786+ {
6787+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6788+ regs->u_regs[UREG_G2] = addr + 4;
6789+ addr = (save & 0x003FFFFFU) << 10;
6790+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6791+ regs->pc = addr;
6792+ regs->npc = addr+4;
6793+ return 3;
6794+ }
6795+ }
6796+ } while (0);
6797+
6798+ do { /* PaX: unpatched PLT emulation step 2 */
6799+ unsigned int save, call, nop;
6800+
6801+ err = get_user(save, (unsigned int *)(regs->pc-4));
6802+ err |= get_user(call, (unsigned int *)regs->pc);
6803+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6804+ if (err)
6805+ break;
6806+
6807+ if (save == 0x9DE3BFA8U &&
6808+ (call & 0xC0000000U) == 0x40000000U &&
6809+ nop == 0x01000000U)
6810+ {
6811+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6812+
6813+ regs->u_regs[UREG_RETPC] = regs->pc;
6814+ regs->pc = dl_resolve;
6815+ regs->npc = dl_resolve+4;
6816+ return 3;
6817+ }
6818+ } while (0);
6819+#endif
6820+
6821+ return 1;
6822+}
6823+
6824+void pax_report_insns(void *pc, void *sp)
6825+{
6826+ unsigned long i;
6827+
6828+ printk(KERN_ERR "PAX: bytes at PC: ");
6829+ for (i = 0; i < 8; i++) {
6830+ unsigned int c;
6831+ if (get_user(c, (unsigned int *)pc+i))
6832+ printk(KERN_CONT "???????? ");
6833+ else
6834+ printk(KERN_CONT "%08x ", c);
6835+ }
6836+ printk("\n");
6837+}
6838+#endif
6839+
6840 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6841 int text_fault)
6842 {
6843@@ -281,6 +546,24 @@ good_area:
6844 if(!(vma->vm_flags & VM_WRITE))
6845 goto bad_area;
6846 } else {
6847+
6848+#ifdef CONFIG_PAX_PAGEEXEC
6849+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6850+ up_read(&mm->mmap_sem);
6851+ switch (pax_handle_fetch_fault(regs)) {
6852+
6853+#ifdef CONFIG_PAX_EMUPLT
6854+ case 2:
6855+ case 3:
6856+ return;
6857+#endif
6858+
6859+ }
6860+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6861+ do_group_exit(SIGKILL);
6862+ }
6863+#endif
6864+
6865 /* Allow reads even for write-only mappings */
6866 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6867 goto bad_area;
6868diff -urNp linux-2.6.39.1/arch/sparc/mm/fault_64.c linux-2.6.39.1/arch/sparc/mm/fault_64.c
6869--- linux-2.6.39.1/arch/sparc/mm/fault_64.c 2011-05-19 00:06:34.000000000 -0400
6870+++ linux-2.6.39.1/arch/sparc/mm/fault_64.c 2011-05-22 19:41:32.000000000 -0400
6871@@ -21,6 +21,9 @@
6872 #include <linux/kprobes.h>
6873 #include <linux/kdebug.h>
6874 #include <linux/percpu.h>
6875+#include <linux/slab.h>
6876+#include <linux/pagemap.h>
6877+#include <linux/compiler.h>
6878
6879 #include <asm/page.h>
6880 #include <asm/pgtable.h>
6881@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
6882 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6883 regs->tpc);
6884 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6885- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6886+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6887 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6888 dump_stack();
6889 unhandled_fault(regs->tpc, current, regs);
6890@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
6891 show_regs(regs);
6892 }
6893
6894+#ifdef CONFIG_PAX_PAGEEXEC
6895+#ifdef CONFIG_PAX_DLRESOLVE
6896+static void pax_emuplt_close(struct vm_area_struct *vma)
6897+{
6898+ vma->vm_mm->call_dl_resolve = 0UL;
6899+}
6900+
6901+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6902+{
6903+ unsigned int *kaddr;
6904+
6905+ vmf->page = alloc_page(GFP_HIGHUSER);
6906+ if (!vmf->page)
6907+ return VM_FAULT_OOM;
6908+
6909+ kaddr = kmap(vmf->page);
6910+ memset(kaddr, 0, PAGE_SIZE);
6911+ kaddr[0] = 0x9DE3BFA8U; /* save */
6912+ flush_dcache_page(vmf->page);
6913+ kunmap(vmf->page);
6914+ return VM_FAULT_MAJOR;
6915+}
6916+
6917+static const struct vm_operations_struct pax_vm_ops = {
6918+ .close = pax_emuplt_close,
6919+ .fault = pax_emuplt_fault
6920+};
6921+
6922+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6923+{
6924+ int ret;
6925+
6926+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6927+ vma->vm_mm = current->mm;
6928+ vma->vm_start = addr;
6929+ vma->vm_end = addr + PAGE_SIZE;
6930+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6931+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6932+ vma->vm_ops = &pax_vm_ops;
6933+
6934+ ret = insert_vm_struct(current->mm, vma);
6935+ if (ret)
6936+ return ret;
6937+
6938+ ++current->mm->total_vm;
6939+ return 0;
6940+}
6941+#endif
6942+
6943+/*
6944+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6945+ *
6946+ * returns 1 when task should be killed
6947+ * 2 when patched PLT trampoline was detected
6948+ * 3 when unpatched PLT trampoline was detected
6949+ */
6950+static int pax_handle_fetch_fault(struct pt_regs *regs)
6951+{
6952+
6953+#ifdef CONFIG_PAX_EMUPLT
6954+ int err;
6955+
6956+ do { /* PaX: patched PLT emulation #1 */
6957+ unsigned int sethi1, sethi2, jmpl;
6958+
6959+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6960+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6961+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6962+
6963+ if (err)
6964+ break;
6965+
6966+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6967+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6968+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6969+ {
6970+ unsigned long addr;
6971+
6972+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6973+ addr = regs->u_regs[UREG_G1];
6974+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6975+
6976+ if (test_thread_flag(TIF_32BIT))
6977+ addr &= 0xFFFFFFFFUL;
6978+
6979+ regs->tpc = addr;
6980+ regs->tnpc = addr+4;
6981+ return 2;
6982+ }
6983+ } while (0);
6984+
6985+ { /* PaX: patched PLT emulation #2 */
6986+ unsigned int ba;
6987+
6988+ err = get_user(ba, (unsigned int *)regs->tpc);
6989+
6990+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6991+ unsigned long addr;
6992+
6993+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6994+
6995+ if (test_thread_flag(TIF_32BIT))
6996+ addr &= 0xFFFFFFFFUL;
6997+
6998+ regs->tpc = addr;
6999+ regs->tnpc = addr+4;
7000+ return 2;
7001+ }
7002+ }
7003+
7004+ do { /* PaX: patched PLT emulation #3 */
7005+ unsigned int sethi, jmpl, nop;
7006+
7007+ err = get_user(sethi, (unsigned int *)regs->tpc);
7008+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
7009+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7010+
7011+ if (err)
7012+ break;
7013+
7014+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7015+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
7016+ nop == 0x01000000U)
7017+ {
7018+ unsigned long addr;
7019+
7020+ addr = (sethi & 0x003FFFFFU) << 10;
7021+ regs->u_regs[UREG_G1] = addr;
7022+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7023+
7024+ if (test_thread_flag(TIF_32BIT))
7025+ addr &= 0xFFFFFFFFUL;
7026+
7027+ regs->tpc = addr;
7028+ regs->tnpc = addr+4;
7029+ return 2;
7030+ }
7031+ } while (0);
7032+
7033+ do { /* PaX: patched PLT emulation #4 */
7034+ unsigned int sethi, mov1, call, mov2;
7035+
7036+ err = get_user(sethi, (unsigned int *)regs->tpc);
7037+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7038+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7039+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7040+
7041+ if (err)
7042+ break;
7043+
7044+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7045+ mov1 == 0x8210000FU &&
7046+ (call & 0xC0000000U) == 0x40000000U &&
7047+ mov2 == 0x9E100001U)
7048+ {
7049+ unsigned long addr;
7050+
7051+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7052+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7053+
7054+ if (test_thread_flag(TIF_32BIT))
7055+ addr &= 0xFFFFFFFFUL;
7056+
7057+ regs->tpc = addr;
7058+ regs->tnpc = addr+4;
7059+ return 2;
7060+ }
7061+ } while (0);
7062+
7063+ do { /* PaX: patched PLT emulation #5 */
7064+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7065+
7066+ err = get_user(sethi, (unsigned int *)regs->tpc);
7067+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7068+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7069+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7070+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7071+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7072+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7073+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7074+
7075+ if (err)
7076+ break;
7077+
7078+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7079+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7080+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7081+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7082+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7083+ sllx == 0x83287020U &&
7084+ jmpl == 0x81C04005U &&
7085+ nop == 0x01000000U)
7086+ {
7087+ unsigned long addr;
7088+
7089+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7090+ regs->u_regs[UREG_G1] <<= 32;
7091+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7092+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7093+ regs->tpc = addr;
7094+ regs->tnpc = addr+4;
7095+ return 2;
7096+ }
7097+ } while (0);
7098+
7099+ do { /* PaX: patched PLT emulation #6 */
7100+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7101+
7102+ err = get_user(sethi, (unsigned int *)regs->tpc);
7103+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7104+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7105+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7106+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7107+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7108+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7109+
7110+ if (err)
7111+ break;
7112+
7113+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7114+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7115+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7116+ sllx == 0x83287020U &&
7117+ (or & 0xFFFFE000U) == 0x8A116000U &&
7118+ jmpl == 0x81C04005U &&
7119+ nop == 0x01000000U)
7120+ {
7121+ unsigned long addr;
7122+
7123+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7124+ regs->u_regs[UREG_G1] <<= 32;
7125+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7126+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7127+ regs->tpc = addr;
7128+ regs->tnpc = addr+4;
7129+ return 2;
7130+ }
7131+ } while (0);
7132+
7133+ do { /* PaX: unpatched PLT emulation step 1 */
7134+ unsigned int sethi, ba, nop;
7135+
7136+ err = get_user(sethi, (unsigned int *)regs->tpc);
7137+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7138+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7139+
7140+ if (err)
7141+ break;
7142+
7143+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7144+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7145+ nop == 0x01000000U)
7146+ {
7147+ unsigned long addr;
7148+ unsigned int save, call;
7149+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7150+
7151+ if ((ba & 0xFFC00000U) == 0x30800000U)
7152+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7153+ else
7154+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7155+
7156+ if (test_thread_flag(TIF_32BIT))
7157+ addr &= 0xFFFFFFFFUL;
7158+
7159+ err = get_user(save, (unsigned int *)addr);
7160+ err |= get_user(call, (unsigned int *)(addr+4));
7161+ err |= get_user(nop, (unsigned int *)(addr+8));
7162+ if (err)
7163+ break;
7164+
7165+#ifdef CONFIG_PAX_DLRESOLVE
7166+ if (save == 0x9DE3BFA8U &&
7167+ (call & 0xC0000000U) == 0x40000000U &&
7168+ nop == 0x01000000U)
7169+ {
7170+ struct vm_area_struct *vma;
7171+ unsigned long call_dl_resolve;
7172+
7173+ down_read(&current->mm->mmap_sem);
7174+ call_dl_resolve = current->mm->call_dl_resolve;
7175+ up_read(&current->mm->mmap_sem);
7176+ if (likely(call_dl_resolve))
7177+ goto emulate;
7178+
7179+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7180+
7181+ down_write(&current->mm->mmap_sem);
7182+ if (current->mm->call_dl_resolve) {
7183+ call_dl_resolve = current->mm->call_dl_resolve;
7184+ up_write(&current->mm->mmap_sem);
7185+ if (vma)
7186+ kmem_cache_free(vm_area_cachep, vma);
7187+ goto emulate;
7188+ }
7189+
7190+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7191+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7192+ up_write(&current->mm->mmap_sem);
7193+ if (vma)
7194+ kmem_cache_free(vm_area_cachep, vma);
7195+ return 1;
7196+ }
7197+
7198+ if (pax_insert_vma(vma, call_dl_resolve)) {
7199+ up_write(&current->mm->mmap_sem);
7200+ kmem_cache_free(vm_area_cachep, vma);
7201+ return 1;
7202+ }
7203+
7204+ current->mm->call_dl_resolve = call_dl_resolve;
7205+ up_write(&current->mm->mmap_sem);
7206+
7207+emulate:
7208+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7209+ regs->tpc = call_dl_resolve;
7210+ regs->tnpc = addr+4;
7211+ return 3;
7212+ }
7213+#endif
7214+
7215+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7216+ if ((save & 0xFFC00000U) == 0x05000000U &&
7217+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7218+ nop == 0x01000000U)
7219+ {
7220+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7221+ regs->u_regs[UREG_G2] = addr + 4;
7222+ addr = (save & 0x003FFFFFU) << 10;
7223+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7224+
7225+ if (test_thread_flag(TIF_32BIT))
7226+ addr &= 0xFFFFFFFFUL;
7227+
7228+ regs->tpc = addr;
7229+ regs->tnpc = addr+4;
7230+ return 3;
7231+ }
7232+
7233+ /* PaX: 64-bit PLT stub */
7234+ err = get_user(sethi1, (unsigned int *)addr);
7235+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7236+ err |= get_user(or1, (unsigned int *)(addr+8));
7237+ err |= get_user(or2, (unsigned int *)(addr+12));
7238+ err |= get_user(sllx, (unsigned int *)(addr+16));
7239+ err |= get_user(add, (unsigned int *)(addr+20));
7240+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7241+ err |= get_user(nop, (unsigned int *)(addr+28));
7242+ if (err)
7243+ break;
7244+
7245+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7246+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7247+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7248+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7249+ sllx == 0x89293020U &&
7250+ add == 0x8A010005U &&
7251+ jmpl == 0x89C14000U &&
7252+ nop == 0x01000000U)
7253+ {
7254+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7255+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7256+ regs->u_regs[UREG_G4] <<= 32;
7257+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7258+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7259+ regs->u_regs[UREG_G4] = addr + 24;
7260+ addr = regs->u_regs[UREG_G5];
7261+ regs->tpc = addr;
7262+ regs->tnpc = addr+4;
7263+ return 3;
7264+ }
7265+ }
7266+ } while (0);
7267+
7268+#ifdef CONFIG_PAX_DLRESOLVE
7269+ do { /* PaX: unpatched PLT emulation step 2 */
7270+ unsigned int save, call, nop;
7271+
7272+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7273+ err |= get_user(call, (unsigned int *)regs->tpc);
7274+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7275+ if (err)
7276+ break;
7277+
7278+ if (save == 0x9DE3BFA8U &&
7279+ (call & 0xC0000000U) == 0x40000000U &&
7280+ nop == 0x01000000U)
7281+ {
7282+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7283+
7284+ if (test_thread_flag(TIF_32BIT))
7285+ dl_resolve &= 0xFFFFFFFFUL;
7286+
7287+ regs->u_regs[UREG_RETPC] = regs->tpc;
7288+ regs->tpc = dl_resolve;
7289+ regs->tnpc = dl_resolve+4;
7290+ return 3;
7291+ }
7292+ } while (0);
7293+#endif
7294+
7295+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7296+ unsigned int sethi, ba, nop;
7297+
7298+ err = get_user(sethi, (unsigned int *)regs->tpc);
7299+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7300+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7301+
7302+ if (err)
7303+ break;
7304+
7305+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7306+ (ba & 0xFFF00000U) == 0x30600000U &&
7307+ nop == 0x01000000U)
7308+ {
7309+ unsigned long addr;
7310+
7311+ addr = (sethi & 0x003FFFFFU) << 10;
7312+ regs->u_regs[UREG_G1] = addr;
7313+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7314+
7315+ if (test_thread_flag(TIF_32BIT))
7316+ addr &= 0xFFFFFFFFUL;
7317+
7318+ regs->tpc = addr;
7319+ regs->tnpc = addr+4;
7320+ return 2;
7321+ }
7322+ } while (0);
7323+
7324+#endif
7325+
7326+ return 1;
7327+}
7328+
7329+void pax_report_insns(void *pc, void *sp)
7330+{
7331+ unsigned long i;
7332+
7333+ printk(KERN_ERR "PAX: bytes at PC: ");
7334+ for (i = 0; i < 8; i++) {
7335+ unsigned int c;
7336+ if (get_user(c, (unsigned int *)pc+i))
7337+ printk(KERN_CONT "???????? ");
7338+ else
7339+ printk(KERN_CONT "%08x ", c);
7340+ }
7341+ printk("\n");
7342+}
7343+#endif
7344+
7345 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7346 {
7347 struct mm_struct *mm = current->mm;
7348@@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
7349 if (!vma)
7350 goto bad_area;
7351
7352+#ifdef CONFIG_PAX_PAGEEXEC
7353+ /* PaX: detect ITLB misses on non-exec pages */
7354+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7355+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7356+ {
7357+ if (address != regs->tpc)
7358+ goto good_area;
7359+
7360+ up_read(&mm->mmap_sem);
7361+ switch (pax_handle_fetch_fault(regs)) {
7362+
7363+#ifdef CONFIG_PAX_EMUPLT
7364+ case 2:
7365+ case 3:
7366+ return;
7367+#endif
7368+
7369+ }
7370+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7371+ do_group_exit(SIGKILL);
7372+ }
7373+#endif
7374+
7375 /* Pure DTLB misses do not tell us whether the fault causing
7376 * load/store/atomic was a write or not, it only says that there
7377 * was no match. So in such a case we (carefully) read the
7378diff -urNp linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c
7379--- linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
7380+++ linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
7381@@ -68,7 +68,7 @@ full_search:
7382 }
7383 return -ENOMEM;
7384 }
7385- if (likely(!vma || addr + len <= vma->vm_start)) {
7386+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7387 /*
7388 * Remember the place where we stopped the search:
7389 */
7390@@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
7391 /* make sure it can fit in the remaining address space */
7392 if (likely(addr > len)) {
7393 vma = find_vma(mm, addr-len);
7394- if (!vma || addr <= vma->vm_start) {
7395+ if (check_heap_stack_gap(vma, addr - len, len)) {
7396 /* remember the address as a hint for next time */
7397 return (mm->free_area_cache = addr-len);
7398 }
7399@@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct
7400 if (unlikely(mm->mmap_base < len))
7401 goto bottomup;
7402
7403- addr = (mm->mmap_base-len) & HPAGE_MASK;
7404+ addr = mm->mmap_base - len;
7405
7406 do {
7407+ addr &= HPAGE_MASK;
7408 /*
7409 * Lookup failure means no vma is above this address,
7410 * else if new region fits below vma->vm_start,
7411 * return with success:
7412 */
7413 vma = find_vma(mm, addr);
7414- if (likely(!vma || addr+len <= vma->vm_start)) {
7415+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7416 /* remember the address as a hint for next time */
7417 return (mm->free_area_cache = addr);
7418 }
7419@@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct
7420 mm->cached_hole_size = vma->vm_start - addr;
7421
7422 /* try just below the current vma->vm_start */
7423- addr = (vma->vm_start-len) & HPAGE_MASK;
7424- } while (likely(len < vma->vm_start));
7425+ addr = skip_heap_stack_gap(vma, len);
7426+ } while (!IS_ERR_VALUE(addr));
7427
7428 bottomup:
7429 /*
7430@@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *f
7431 if (addr) {
7432 addr = ALIGN(addr, HPAGE_SIZE);
7433 vma = find_vma(mm, addr);
7434- if (task_size - len >= addr &&
7435- (!vma || addr + len <= vma->vm_start))
7436+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7437 return addr;
7438 }
7439 if (mm->get_unmapped_area == arch_get_unmapped_area)
7440diff -urNp linux-2.6.39.1/arch/sparc/mm/init_32.c linux-2.6.39.1/arch/sparc/mm/init_32.c
7441--- linux-2.6.39.1/arch/sparc/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
7442+++ linux-2.6.39.1/arch/sparc/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
7443@@ -318,6 +318,9 @@ extern void device_scan(void);
7444 pgprot_t PAGE_SHARED __read_mostly;
7445 EXPORT_SYMBOL(PAGE_SHARED);
7446
7447+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7448+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7449+
7450 void __init paging_init(void)
7451 {
7452 switch(sparc_cpu_model) {
7453@@ -346,17 +349,17 @@ void __init paging_init(void)
7454
7455 /* Initialize the protection map with non-constant, MMU dependent values. */
7456 protection_map[0] = PAGE_NONE;
7457- protection_map[1] = PAGE_READONLY;
7458- protection_map[2] = PAGE_COPY;
7459- protection_map[3] = PAGE_COPY;
7460+ protection_map[1] = PAGE_READONLY_NOEXEC;
7461+ protection_map[2] = PAGE_COPY_NOEXEC;
7462+ protection_map[3] = PAGE_COPY_NOEXEC;
7463 protection_map[4] = PAGE_READONLY;
7464 protection_map[5] = PAGE_READONLY;
7465 protection_map[6] = PAGE_COPY;
7466 protection_map[7] = PAGE_COPY;
7467 protection_map[8] = PAGE_NONE;
7468- protection_map[9] = PAGE_READONLY;
7469- protection_map[10] = PAGE_SHARED;
7470- protection_map[11] = PAGE_SHARED;
7471+ protection_map[9] = PAGE_READONLY_NOEXEC;
7472+ protection_map[10] = PAGE_SHARED_NOEXEC;
7473+ protection_map[11] = PAGE_SHARED_NOEXEC;
7474 protection_map[12] = PAGE_READONLY;
7475 protection_map[13] = PAGE_READONLY;
7476 protection_map[14] = PAGE_SHARED;
7477diff -urNp linux-2.6.39.1/arch/sparc/mm/Makefile linux-2.6.39.1/arch/sparc/mm/Makefile
7478--- linux-2.6.39.1/arch/sparc/mm/Makefile 2011-05-19 00:06:34.000000000 -0400
7479+++ linux-2.6.39.1/arch/sparc/mm/Makefile 2011-05-22 19:36:30.000000000 -0400
7480@@ -2,7 +2,7 @@
7481 #
7482
7483 asflags-y := -ansi
7484-ccflags-y := -Werror
7485+#ccflags-y := -Werror
7486
7487 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
7488 obj-y += fault_$(BITS).o
7489diff -urNp linux-2.6.39.1/arch/sparc/mm/srmmu.c linux-2.6.39.1/arch/sparc/mm/srmmu.c
7490--- linux-2.6.39.1/arch/sparc/mm/srmmu.c 2011-05-19 00:06:34.000000000 -0400
7491+++ linux-2.6.39.1/arch/sparc/mm/srmmu.c 2011-05-22 19:36:30.000000000 -0400
7492@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7493 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7494 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7495 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7496+
7497+#ifdef CONFIG_PAX_PAGEEXEC
7498+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7499+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7500+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7501+#endif
7502+
7503 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7504 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7505
7506diff -urNp linux-2.6.39.1/arch/tile/kernel/pci.c linux-2.6.39.1/arch/tile/kernel/pci.c
7507--- linux-2.6.39.1/arch/tile/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7508+++ linux-2.6.39.1/arch/tile/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7509@@ -60,7 +60,7 @@ int __write_once tile_plx_gen1;
7510 static struct pci_controller controllers[TILE_NUM_PCIE];
7511 static int num_controllers;
7512
7513-static struct pci_ops tile_cfg_ops;
7514+static const struct pci_ops tile_cfg_ops;
7515
7516
7517 /*
7518@@ -564,7 +564,7 @@ static int __devinit tile_cfg_write(stru
7519 }
7520
7521
7522-static struct pci_ops tile_cfg_ops = {
7523+static const struct pci_ops tile_cfg_ops = {
7524 .read = tile_cfg_read,
7525 .write = tile_cfg_write,
7526 };
7527diff -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
7528--- linux-2.6.39.1/arch/um/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
7529+++ linux-2.6.39.1/arch/um/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
7530@@ -23,6 +23,7 @@ enum km_type {
7531 KM_IRQ1,
7532 KM_SOFTIRQ0,
7533 KM_SOFTIRQ1,
7534+ KM_CLEARPAGE,
7535 KM_TYPE_NR
7536 };
7537
7538diff -urNp linux-2.6.39.1/arch/um/include/asm/page.h linux-2.6.39.1/arch/um/include/asm/page.h
7539--- linux-2.6.39.1/arch/um/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
7540+++ linux-2.6.39.1/arch/um/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
7541@@ -14,6 +14,9 @@
7542 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7543 #define PAGE_MASK (~(PAGE_SIZE-1))
7544
7545+#define ktla_ktva(addr) (addr)
7546+#define ktva_ktla(addr) (addr)
7547+
7548 #ifndef __ASSEMBLY__
7549
7550 struct page;
7551diff -urNp linux-2.6.39.1/arch/um/kernel/process.c linux-2.6.39.1/arch/um/kernel/process.c
7552--- linux-2.6.39.1/arch/um/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
7553+++ linux-2.6.39.1/arch/um/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
7554@@ -404,22 +404,6 @@ int singlestepping(void * t)
7555 return 2;
7556 }
7557
7558-/*
7559- * Only x86 and x86_64 have an arch_align_stack().
7560- * All other arches have "#define arch_align_stack(x) (x)"
7561- * in their asm/system.h
7562- * As this is included in UML from asm-um/system-generic.h,
7563- * we can use it to behave as the subarch does.
7564- */
7565-#ifndef arch_align_stack
7566-unsigned long arch_align_stack(unsigned long sp)
7567-{
7568- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7569- sp -= get_random_int() % 8192;
7570- return sp & ~0xf;
7571-}
7572-#endif
7573-
7574 unsigned long get_wchan(struct task_struct *p)
7575 {
7576 unsigned long stack_page, sp, ip;
7577diff -urNp linux-2.6.39.1/arch/um/sys-i386/syscalls.c linux-2.6.39.1/arch/um/sys-i386/syscalls.c
7578--- linux-2.6.39.1/arch/um/sys-i386/syscalls.c 2011-05-19 00:06:34.000000000 -0400
7579+++ linux-2.6.39.1/arch/um/sys-i386/syscalls.c 2011-05-22 19:36:30.000000000 -0400
7580@@ -11,6 +11,21 @@
7581 #include "asm/uaccess.h"
7582 #include "asm/unistd.h"
7583
7584+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
7585+{
7586+ unsigned long pax_task_size = TASK_SIZE;
7587+
7588+#ifdef CONFIG_PAX_SEGMEXEC
7589+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
7590+ pax_task_size = SEGMEXEC_TASK_SIZE;
7591+#endif
7592+
7593+ if (len > pax_task_size || addr > pax_task_size - len)
7594+ return -EINVAL;
7595+
7596+ return 0;
7597+}
7598+
7599 /*
7600 * The prototype on i386 is:
7601 *
7602diff -urNp linux-2.6.39.1/arch/unicore32/kernel/pci.c linux-2.6.39.1/arch/unicore32/kernel/pci.c
7603--- linux-2.6.39.1/arch/unicore32/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7604+++ linux-2.6.39.1/arch/unicore32/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7605@@ -66,7 +66,7 @@ puv3_write_config(struct pci_bus *bus, u
7606 return PCIBIOS_SUCCESSFUL;
7607 }
7608
7609-struct pci_ops pci_puv3_ops = {
7610+const struct pci_ops pci_puv3_ops = {
7611 .read = puv3_read_config,
7612 .write = puv3_write_config,
7613 };
7614diff -urNp linux-2.6.39.1/arch/x86/boot/bitops.h linux-2.6.39.1/arch/x86/boot/bitops.h
7615--- linux-2.6.39.1/arch/x86/boot/bitops.h 2011-05-19 00:06:34.000000000 -0400
7616+++ linux-2.6.39.1/arch/x86/boot/bitops.h 2011-05-22 19:36:30.000000000 -0400
7617@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
7618 u8 v;
7619 const u32 *p = (const u32 *)addr;
7620
7621- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7622+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7623 return v;
7624 }
7625
7626@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
7627
7628 static inline void set_bit(int nr, void *addr)
7629 {
7630- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7631+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7632 }
7633
7634 #endif /* BOOT_BITOPS_H */
7635diff -urNp linux-2.6.39.1/arch/x86/boot/boot.h linux-2.6.39.1/arch/x86/boot/boot.h
7636--- linux-2.6.39.1/arch/x86/boot/boot.h 2011-05-19 00:06:34.000000000 -0400
7637+++ linux-2.6.39.1/arch/x86/boot/boot.h 2011-05-22 19:36:30.000000000 -0400
7638@@ -85,7 +85,7 @@ static inline void io_delay(void)
7639 static inline u16 ds(void)
7640 {
7641 u16 seg;
7642- asm("movw %%ds,%0" : "=rm" (seg));
7643+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7644 return seg;
7645 }
7646
7647@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
7648 static inline int memcmp(const void *s1, const void *s2, size_t len)
7649 {
7650 u8 diff;
7651- asm("repe; cmpsb; setnz %0"
7652+ asm volatile("repe; cmpsb; setnz %0"
7653 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7654 return diff;
7655 }
7656diff -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
7657--- linux-2.6.39.1/arch/x86/boot/compressed/head_32.S 2011-05-19 00:06:34.000000000 -0400
7658+++ linux-2.6.39.1/arch/x86/boot/compressed/head_32.S 2011-05-22 19:36:30.000000000 -0400
7659@@ -76,7 +76,7 @@ ENTRY(startup_32)
7660 notl %eax
7661 andl %eax, %ebx
7662 #else
7663- movl $LOAD_PHYSICAL_ADDR, %ebx
7664+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7665 #endif
7666
7667 /* Target address to relocate to for decompression */
7668@@ -162,7 +162,7 @@ relocated:
7669 * and where it was actually loaded.
7670 */
7671 movl %ebp, %ebx
7672- subl $LOAD_PHYSICAL_ADDR, %ebx
7673+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7674 jz 2f /* Nothing to be done if loaded at compiled addr. */
7675 /*
7676 * Process relocations.
7677@@ -170,8 +170,7 @@ relocated:
7678
7679 1: subl $4, %edi
7680 movl (%edi), %ecx
7681- testl %ecx, %ecx
7682- jz 2f
7683+ jecxz 2f
7684 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7685 jmp 1b
7686 2:
7687diff -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
7688--- linux-2.6.39.1/arch/x86/boot/compressed/head_64.S 2011-05-19 00:06:34.000000000 -0400
7689+++ linux-2.6.39.1/arch/x86/boot/compressed/head_64.S 2011-05-22 19:36:30.000000000 -0400
7690@@ -91,7 +91,7 @@ ENTRY(startup_32)
7691 notl %eax
7692 andl %eax, %ebx
7693 #else
7694- movl $LOAD_PHYSICAL_ADDR, %ebx
7695+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7696 #endif
7697
7698 /* Target address to relocate to for decompression */
7699@@ -233,7 +233,7 @@ ENTRY(startup_64)
7700 notq %rax
7701 andq %rax, %rbp
7702 #else
7703- movq $LOAD_PHYSICAL_ADDR, %rbp
7704+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7705 #endif
7706
7707 /* Target address to relocate to for decompression */
7708diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/misc.c linux-2.6.39.1/arch/x86/boot/compressed/misc.c
7709--- linux-2.6.39.1/arch/x86/boot/compressed/misc.c 2011-05-19 00:06:34.000000000 -0400
7710+++ linux-2.6.39.1/arch/x86/boot/compressed/misc.c 2011-05-22 19:36:30.000000000 -0400
7711@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7712 case PT_LOAD:
7713 #ifdef CONFIG_RELOCATABLE
7714 dest = output;
7715- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7716+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7717 #else
7718 dest = (void *)(phdr->p_paddr);
7719 #endif
7720@@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *
7721 error("Destination address too large");
7722 #endif
7723 #ifndef CONFIG_RELOCATABLE
7724- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7725+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7726 error("Wrong destination address");
7727 #endif
7728
7729diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/relocs.c linux-2.6.39.1/arch/x86/boot/compressed/relocs.c
7730--- linux-2.6.39.1/arch/x86/boot/compressed/relocs.c 2011-05-19 00:06:34.000000000 -0400
7731+++ linux-2.6.39.1/arch/x86/boot/compressed/relocs.c 2011-05-22 19:36:30.000000000 -0400
7732@@ -13,8 +13,11 @@
7733
7734 static void die(char *fmt, ...);
7735
7736+#include "../../../../include/generated/autoconf.h"
7737+
7738 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7739 static Elf32_Ehdr ehdr;
7740+static Elf32_Phdr *phdr;
7741 static unsigned long reloc_count, reloc_idx;
7742 static unsigned long *relocs;
7743
7744@@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7745 }
7746 }
7747
7748+static void read_phdrs(FILE *fp)
7749+{
7750+ unsigned int i;
7751+
7752+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7753+ if (!phdr) {
7754+ die("Unable to allocate %d program headers\n",
7755+ ehdr.e_phnum);
7756+ }
7757+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7758+ die("Seek to %d failed: %s\n",
7759+ ehdr.e_phoff, strerror(errno));
7760+ }
7761+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7762+ die("Cannot read ELF program headers: %s\n",
7763+ strerror(errno));
7764+ }
7765+ for(i = 0; i < ehdr.e_phnum; i++) {
7766+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7767+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7768+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7769+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7770+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7771+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7772+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7773+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7774+ }
7775+
7776+}
7777+
7778 static void read_shdrs(FILE *fp)
7779 {
7780- int i;
7781+ unsigned int i;
7782 Elf32_Shdr shdr;
7783
7784 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7785@@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7786
7787 static void read_strtabs(FILE *fp)
7788 {
7789- int i;
7790+ unsigned int i;
7791 for (i = 0; i < ehdr.e_shnum; i++) {
7792 struct section *sec = &secs[i];
7793 if (sec->shdr.sh_type != SHT_STRTAB) {
7794@@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7795
7796 static void read_symtabs(FILE *fp)
7797 {
7798- int i,j;
7799+ unsigned int i,j;
7800 for (i = 0; i < ehdr.e_shnum; i++) {
7801 struct section *sec = &secs[i];
7802 if (sec->shdr.sh_type != SHT_SYMTAB) {
7803@@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7804
7805 static void read_relocs(FILE *fp)
7806 {
7807- int i,j;
7808+ unsigned int i,j;
7809+ uint32_t base;
7810+
7811 for (i = 0; i < ehdr.e_shnum; i++) {
7812 struct section *sec = &secs[i];
7813 if (sec->shdr.sh_type != SHT_REL) {
7814@@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7815 die("Cannot read symbol table: %s\n",
7816 strerror(errno));
7817 }
7818+ base = 0;
7819+ for (j = 0; j < ehdr.e_phnum; j++) {
7820+ if (phdr[j].p_type != PT_LOAD )
7821+ continue;
7822+ if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
7823+ continue;
7824+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7825+ break;
7826+ }
7827 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7828 Elf32_Rel *rel = &sec->reltab[j];
7829- rel->r_offset = elf32_to_cpu(rel->r_offset);
7830+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7831 rel->r_info = elf32_to_cpu(rel->r_info);
7832 }
7833 }
7834@@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7835
7836 static void print_absolute_symbols(void)
7837 {
7838- int i;
7839+ unsigned int i;
7840 printf("Absolute symbols\n");
7841 printf(" Num: Value Size Type Bind Visibility Name\n");
7842 for (i = 0; i < ehdr.e_shnum; i++) {
7843 struct section *sec = &secs[i];
7844 char *sym_strtab;
7845 Elf32_Sym *sh_symtab;
7846- int j;
7847+ unsigned int j;
7848
7849 if (sec->shdr.sh_type != SHT_SYMTAB) {
7850 continue;
7851@@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7852
7853 static void print_absolute_relocs(void)
7854 {
7855- int i, printed = 0;
7856+ unsigned int i, printed = 0;
7857
7858 for (i = 0; i < ehdr.e_shnum; i++) {
7859 struct section *sec = &secs[i];
7860 struct section *sec_applies, *sec_symtab;
7861 char *sym_strtab;
7862 Elf32_Sym *sh_symtab;
7863- int j;
7864+ unsigned int j;
7865 if (sec->shdr.sh_type != SHT_REL) {
7866 continue;
7867 }
7868@@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7869
7870 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7871 {
7872- int i;
7873+ unsigned int i;
7874 /* Walk through the relocations */
7875 for (i = 0; i < ehdr.e_shnum; i++) {
7876 char *sym_strtab;
7877 Elf32_Sym *sh_symtab;
7878 struct section *sec_applies, *sec_symtab;
7879- int j;
7880+ unsigned int j;
7881 struct section *sec = &secs[i];
7882
7883 if (sec->shdr.sh_type != SHT_REL) {
7884@@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
7885 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7886 continue;
7887 }
7888+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7889+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7890+ continue;
7891+
7892+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7893+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7894+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7895+ continue;
7896+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7897+ continue;
7898+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7899+ continue;
7900+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7901+ continue;
7902+#endif
7903+
7904 switch (r_type) {
7905 case R_386_NONE:
7906 case R_386_PC32:
7907@@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
7908
7909 static void emit_relocs(int as_text)
7910 {
7911- int i;
7912+ unsigned int i;
7913 /* Count how many relocations I have and allocate space for them. */
7914 reloc_count = 0;
7915 walk_relocs(count_reloc);
7916@@ -665,6 +725,7 @@ int main(int argc, char **argv)
7917 fname, strerror(errno));
7918 }
7919 read_ehdr(fp);
7920+ read_phdrs(fp);
7921 read_shdrs(fp);
7922 read_strtabs(fp);
7923 read_symtabs(fp);
7924diff -urNp linux-2.6.39.1/arch/x86/boot/cpucheck.c linux-2.6.39.1/arch/x86/boot/cpucheck.c
7925--- linux-2.6.39.1/arch/x86/boot/cpucheck.c 2011-05-19 00:06:34.000000000 -0400
7926+++ linux-2.6.39.1/arch/x86/boot/cpucheck.c 2011-05-22 19:36:30.000000000 -0400
7927@@ -74,7 +74,7 @@ static int has_fpu(void)
7928 u16 fcw = -1, fsw = -1;
7929 u32 cr0;
7930
7931- asm("movl %%cr0,%0" : "=r" (cr0));
7932+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7933 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7934 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7935 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7936@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7937 {
7938 u32 f0, f1;
7939
7940- asm("pushfl ; "
7941+ asm volatile("pushfl ; "
7942 "pushfl ; "
7943 "popl %0 ; "
7944 "movl %0,%1 ; "
7945@@ -115,7 +115,7 @@ static void get_flags(void)
7946 set_bit(X86_FEATURE_FPU, cpu.flags);
7947
7948 if (has_eflag(X86_EFLAGS_ID)) {
7949- asm("cpuid"
7950+ asm volatile("cpuid"
7951 : "=a" (max_intel_level),
7952 "=b" (cpu_vendor[0]),
7953 "=d" (cpu_vendor[1]),
7954@@ -124,7 +124,7 @@ static void get_flags(void)
7955
7956 if (max_intel_level >= 0x00000001 &&
7957 max_intel_level <= 0x0000ffff) {
7958- asm("cpuid"
7959+ asm volatile("cpuid"
7960 : "=a" (tfms),
7961 "=c" (cpu.flags[4]),
7962 "=d" (cpu.flags[0])
7963@@ -136,7 +136,7 @@ static void get_flags(void)
7964 cpu.model += ((tfms >> 16) & 0xf) << 4;
7965 }
7966
7967- asm("cpuid"
7968+ asm volatile("cpuid"
7969 : "=a" (max_amd_level)
7970 : "a" (0x80000000)
7971 : "ebx", "ecx", "edx");
7972@@ -144,7 +144,7 @@ static void get_flags(void)
7973 if (max_amd_level >= 0x80000001 &&
7974 max_amd_level <= 0x8000ffff) {
7975 u32 eax = 0x80000001;
7976- asm("cpuid"
7977+ asm volatile("cpuid"
7978 : "+a" (eax),
7979 "=c" (cpu.flags[6]),
7980 "=d" (cpu.flags[1])
7981@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7982 u32 ecx = MSR_K7_HWCR;
7983 u32 eax, edx;
7984
7985- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7986+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7987 eax &= ~(1 << 15);
7988- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7989+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7990
7991 get_flags(); /* Make sure it really did something */
7992 err = check_flags();
7993@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7994 u32 ecx = MSR_VIA_FCR;
7995 u32 eax, edx;
7996
7997- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7998+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7999 eax |= (1<<1)|(1<<7);
8000- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8001+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8002
8003 set_bit(X86_FEATURE_CX8, cpu.flags);
8004 err = check_flags();
8005@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
8006 u32 eax, edx;
8007 u32 level = 1;
8008
8009- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8010- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8011- asm("cpuid"
8012+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8013+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8014+ asm volatile("cpuid"
8015 : "+a" (level), "=d" (cpu.flags[0])
8016 : : "ecx", "ebx");
8017- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8018+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8019
8020 err = check_flags();
8021 }
8022diff -urNp linux-2.6.39.1/arch/x86/boot/header.S linux-2.6.39.1/arch/x86/boot/header.S
8023--- linux-2.6.39.1/arch/x86/boot/header.S 2011-05-19 00:06:34.000000000 -0400
8024+++ linux-2.6.39.1/arch/x86/boot/header.S 2011-05-22 19:36:30.000000000 -0400
8025@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
8026 # single linked list of
8027 # struct setup_data
8028
8029-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8030+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8031
8032 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8033 #define VO_INIT_SIZE (VO__end - VO__text)
8034diff -urNp linux-2.6.39.1/arch/x86/boot/memory.c linux-2.6.39.1/arch/x86/boot/memory.c
8035--- linux-2.6.39.1/arch/x86/boot/memory.c 2011-05-19 00:06:34.000000000 -0400
8036+++ linux-2.6.39.1/arch/x86/boot/memory.c 2011-05-22 19:36:30.000000000 -0400
8037@@ -19,7 +19,7 @@
8038
8039 static int detect_memory_e820(void)
8040 {
8041- int count = 0;
8042+ unsigned int count = 0;
8043 struct biosregs ireg, oreg;
8044 struct e820entry *desc = boot_params.e820_map;
8045 static struct e820entry buf; /* static so it is zeroed */
8046diff -urNp linux-2.6.39.1/arch/x86/boot/video.c linux-2.6.39.1/arch/x86/boot/video.c
8047--- linux-2.6.39.1/arch/x86/boot/video.c 2011-05-19 00:06:34.000000000 -0400
8048+++ linux-2.6.39.1/arch/x86/boot/video.c 2011-05-22 19:36:30.000000000 -0400
8049@@ -96,7 +96,7 @@ static void store_mode_params(void)
8050 static unsigned int get_entry(void)
8051 {
8052 char entry_buf[4];
8053- int i, len = 0;
8054+ unsigned int i, len = 0;
8055 int key;
8056 unsigned int v;
8057
8058diff -urNp linux-2.6.39.1/arch/x86/boot/video-vesa.c linux-2.6.39.1/arch/x86/boot/video-vesa.c
8059--- linux-2.6.39.1/arch/x86/boot/video-vesa.c 2011-05-19 00:06:34.000000000 -0400
8060+++ linux-2.6.39.1/arch/x86/boot/video-vesa.c 2011-05-22 19:36:30.000000000 -0400
8061@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8062
8063 boot_params.screen_info.vesapm_seg = oreg.es;
8064 boot_params.screen_info.vesapm_off = oreg.di;
8065+ boot_params.screen_info.vesapm_size = oreg.cx;
8066 }
8067
8068 /*
8069diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32_aout.c linux-2.6.39.1/arch/x86/ia32/ia32_aout.c
8070--- linux-2.6.39.1/arch/x86/ia32/ia32_aout.c 2011-05-19 00:06:34.000000000 -0400
8071+++ linux-2.6.39.1/arch/x86/ia32/ia32_aout.c 2011-05-22 19:41:32.000000000 -0400
8072@@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
8073 unsigned long dump_start, dump_size;
8074 struct user32 dump;
8075
8076+ memset(&dump, 0, sizeof(dump));
8077+
8078 fs = get_fs();
8079 set_fs(KERNEL_DS);
8080 has_dumped = 1;
8081diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32entry.S linux-2.6.39.1/arch/x86/ia32/ia32entry.S
8082--- linux-2.6.39.1/arch/x86/ia32/ia32entry.S 2011-05-19 00:06:34.000000000 -0400
8083+++ linux-2.6.39.1/arch/x86/ia32/ia32entry.S 2011-05-23 17:16:01.000000000 -0400
8084@@ -13,6 +13,7 @@
8085 #include <asm/thread_info.h>
8086 #include <asm/segment.h>
8087 #include <asm/irqflags.h>
8088+#include <asm/pgtable.h>
8089 #include <linux/linkage.h>
8090
8091 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8092@@ -95,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8093 ENDPROC(native_irq_enable_sysexit)
8094 #endif
8095
8096+ .macro pax_enter_kernel_user
8097+#ifdef CONFIG_PAX_MEMORY_UDEREF
8098+ call pax_enter_kernel_user
8099+#endif
8100+ .endm
8101+
8102+ .macro pax_exit_kernel_user
8103+#ifdef CONFIG_PAX_MEMORY_UDEREF
8104+ call pax_exit_kernel_user
8105+#endif
8106+#ifdef CONFIG_PAX_RANDKSTACK
8107+ pushq %rax
8108+ call pax_randomize_kstack
8109+ popq %rax
8110+#endif
8111+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8112+ call pax_erase_kstack
8113+#endif
8114+ .endm
8115+
8116+ .macro pax_erase_kstack
8117+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8118+ call pax_erase_kstack
8119+#endif
8120+ .endm
8121+
8122 /*
8123 * 32bit SYSENTER instruction entry.
8124 *
8125@@ -121,7 +148,7 @@ ENTRY(ia32_sysenter_target)
8126 CFI_REGISTER rsp,rbp
8127 SWAPGS_UNSAFE_STACK
8128 movq PER_CPU_VAR(kernel_stack), %rsp
8129- addq $(KERNEL_STACK_OFFSET),%rsp
8130+ pax_enter_kernel_user
8131 /*
8132 * No need to follow this irqs on/off section: the syscall
8133 * disabled irqs, here we enable it straight after entry:
8134@@ -134,7 +161,8 @@ ENTRY(ia32_sysenter_target)
8135 CFI_REL_OFFSET rsp,0
8136 pushfq_cfi
8137 /*CFI_REL_OFFSET rflags,0*/
8138- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
8139+ GET_THREAD_INFO(%r10)
8140+ movl TI_sysenter_return(%r10), %r10d
8141 CFI_REGISTER rip,r10
8142 pushq_cfi $__USER32_CS
8143 /*CFI_REL_OFFSET cs,0*/
8144@@ -146,6 +174,12 @@ ENTRY(ia32_sysenter_target)
8145 SAVE_ARGS 0,0,1
8146 /* no need to do an access_ok check here because rbp has been
8147 32bit zero extended */
8148+
8149+#ifdef CONFIG_PAX_MEMORY_UDEREF
8150+ mov $PAX_USER_SHADOW_BASE,%r10
8151+ add %r10,%rbp
8152+#endif
8153+
8154 1: movl (%rbp),%ebp
8155 .section __ex_table,"a"
8156 .quad 1b,ia32_badarg
8157@@ -168,6 +202,7 @@ sysenter_dispatch:
8158 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8159 jnz sysexit_audit
8160 sysexit_from_sys_call:
8161+ pax_exit_kernel_user
8162 andl $~TS_COMPAT,TI_status(%r10)
8163 /* clear IF, that popfq doesn't enable interrupts early */
8164 andl $~0x200,EFLAGS-R11(%rsp)
8165@@ -194,6 +229,9 @@ sysexit_from_sys_call:
8166 movl %eax,%esi /* 2nd arg: syscall number */
8167 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8168 call audit_syscall_entry
8169+
8170+ pax_erase_kstack
8171+
8172 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8173 cmpq $(IA32_NR_syscalls-1),%rax
8174 ja ia32_badsys
8175@@ -246,6 +284,9 @@ sysenter_tracesys:
8176 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8177 movq %rsp,%rdi /* &pt_regs -> arg1 */
8178 call syscall_trace_enter
8179+
8180+ pax_erase_kstack
8181+
8182 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8183 RESTORE_REST
8184 cmpq $(IA32_NR_syscalls-1),%rax
8185@@ -277,19 +318,24 @@ ENDPROC(ia32_sysenter_target)
8186 ENTRY(ia32_cstar_target)
8187 CFI_STARTPROC32 simple
8188 CFI_SIGNAL_FRAME
8189- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8190+ CFI_DEF_CFA rsp,0
8191 CFI_REGISTER rip,rcx
8192 /*CFI_REGISTER rflags,r11*/
8193 SWAPGS_UNSAFE_STACK
8194 movl %esp,%r8d
8195 CFI_REGISTER rsp,r8
8196 movq PER_CPU_VAR(kernel_stack),%rsp
8197+
8198+#ifdef CONFIG_PAX_MEMORY_UDEREF
8199+ pax_enter_kernel_user
8200+#endif
8201+
8202 /*
8203 * No need to follow this irqs on/off section: the syscall
8204 * disabled irqs and here we enable it straight after entry:
8205 */
8206 ENABLE_INTERRUPTS(CLBR_NONE)
8207- SAVE_ARGS 8,1,1
8208+ SAVE_ARGS 8*6,1,1
8209 movl %eax,%eax /* zero extension */
8210 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8211 movq %rcx,RIP-ARGOFFSET(%rsp)
8212@@ -305,6 +351,12 @@ ENTRY(ia32_cstar_target)
8213 /* no need to do an access_ok check here because r8 has been
8214 32bit zero extended */
8215 /* hardware stack frame is complete now */
8216+
8217+#ifdef CONFIG_PAX_MEMORY_UDEREF
8218+ mov $PAX_USER_SHADOW_BASE,%r10
8219+ add %r10,%r8
8220+#endif
8221+
8222 1: movl (%r8),%r9d
8223 .section __ex_table,"a"
8224 .quad 1b,ia32_badarg
8225@@ -327,6 +379,7 @@ cstar_dispatch:
8226 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8227 jnz sysretl_audit
8228 sysretl_from_sys_call:
8229+ pax_exit_kernel_user
8230 andl $~TS_COMPAT,TI_status(%r10)
8231 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8232 movl RIP-ARGOFFSET(%rsp),%ecx
8233@@ -364,6 +417,9 @@ cstar_tracesys:
8234 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8235 movq %rsp,%rdi /* &pt_regs -> arg1 */
8236 call syscall_trace_enter
8237+
8238+ pax_erase_kstack
8239+
8240 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8241 RESTORE_REST
8242 xchgl %ebp,%r9d
8243@@ -409,6 +465,7 @@ ENTRY(ia32_syscall)
8244 CFI_REL_OFFSET rip,RIP-RIP
8245 PARAVIRT_ADJUST_EXCEPTION_FRAME
8246 SWAPGS
8247+ pax_enter_kernel_user
8248 /*
8249 * No need to follow this irqs on/off section: the syscall
8250 * disabled irqs and here we enable it straight after entry:
8251@@ -441,6 +498,9 @@ ia32_tracesys:
8252 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8253 movq %rsp,%rdi /* &pt_regs -> arg1 */
8254 call syscall_trace_enter
8255+
8256+ pax_erase_kstack
8257+
8258 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8259 RESTORE_REST
8260 cmpq $(IA32_NR_syscalls-1),%rax
8261diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32_signal.c linux-2.6.39.1/arch/x86/ia32/ia32_signal.c
8262--- linux-2.6.39.1/arch/x86/ia32/ia32_signal.c 2011-05-19 00:06:34.000000000 -0400
8263+++ linux-2.6.39.1/arch/x86/ia32/ia32_signal.c 2011-05-22 19:36:30.000000000 -0400
8264@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
8265 sp -= frame_size;
8266 /* Align the stack pointer according to the i386 ABI,
8267 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8268- sp = ((sp + 4) & -16ul) - 4;
8269+ sp = ((sp - 12) & -16ul) - 4;
8270 return (void __user *) sp;
8271 }
8272
8273@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
8274 * These are actually not used anymore, but left because some
8275 * gdb versions depend on them as a marker.
8276 */
8277- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8278+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8279 } put_user_catch(err);
8280
8281 if (err)
8282@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
8283 0xb8,
8284 __NR_ia32_rt_sigreturn,
8285 0x80cd,
8286- 0,
8287+ 0
8288 };
8289
8290 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8291@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
8292
8293 if (ka->sa.sa_flags & SA_RESTORER)
8294 restorer = ka->sa.sa_restorer;
8295+ else if (current->mm->context.vdso)
8296+ /* Return stub is in 32bit vsyscall page */
8297+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8298 else
8299- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8300- rt_sigreturn);
8301+ restorer = &frame->retcode;
8302 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8303
8304 /*
8305 * Not actually used anymore, but left because some gdb
8306 * versions need it.
8307 */
8308- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8309+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8310 } put_user_catch(err);
8311
8312 if (err)
8313diff -urNp linux-2.6.39.1/arch/x86/include/asm/alternative.h linux-2.6.39.1/arch/x86/include/asm/alternative.h
8314--- linux-2.6.39.1/arch/x86/include/asm/alternative.h 2011-05-19 00:06:34.000000000 -0400
8315+++ linux-2.6.39.1/arch/x86/include/asm/alternative.h 2011-05-22 19:36:30.000000000 -0400
8316@@ -94,7 +94,7 @@ static inline int alternatives_text_rese
8317 ".section .discard,\"aw\",@progbits\n" \
8318 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8319 ".previous\n" \
8320- ".section .altinstr_replacement, \"ax\"\n" \
8321+ ".section .altinstr_replacement, \"a\"\n" \
8322 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8323 ".previous"
8324
8325diff -urNp linux-2.6.39.1/arch/x86/include/asm/apm.h linux-2.6.39.1/arch/x86/include/asm/apm.h
8326--- linux-2.6.39.1/arch/x86/include/asm/apm.h 2011-05-19 00:06:34.000000000 -0400
8327+++ linux-2.6.39.1/arch/x86/include/asm/apm.h 2011-05-22 19:36:30.000000000 -0400
8328@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
8329 __asm__ __volatile__(APM_DO_ZERO_SEGS
8330 "pushl %%edi\n\t"
8331 "pushl %%ebp\n\t"
8332- "lcall *%%cs:apm_bios_entry\n\t"
8333+ "lcall *%%ss:apm_bios_entry\n\t"
8334 "setc %%al\n\t"
8335 "popl %%ebp\n\t"
8336 "popl %%edi\n\t"
8337@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
8338 __asm__ __volatile__(APM_DO_ZERO_SEGS
8339 "pushl %%edi\n\t"
8340 "pushl %%ebp\n\t"
8341- "lcall *%%cs:apm_bios_entry\n\t"
8342+ "lcall *%%ss:apm_bios_entry\n\t"
8343 "setc %%bl\n\t"
8344 "popl %%ebp\n\t"
8345 "popl %%edi\n\t"
8346diff -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
8347--- linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h 2011-05-19 00:06:34.000000000 -0400
8348+++ linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h 2011-05-22 19:36:30.000000000 -0400
8349@@ -12,6 +12,14 @@ typedef struct {
8350 u64 __aligned(8) counter;
8351 } atomic64_t;
8352
8353+#ifdef CONFIG_PAX_REFCOUNT
8354+typedef struct {
8355+ u64 __aligned(8) counter;
8356+} atomic64_unchecked_t;
8357+#else
8358+typedef atomic64_t atomic64_unchecked_t;
8359+#endif
8360+
8361 #define ATOMIC64_INIT(val) { (val) }
8362
8363 #ifdef CONFIG_X86_CMPXCHG64
8364@@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg
8365 }
8366
8367 /**
8368+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
8369+ * @p: pointer to type atomic64_unchecked_t
8370+ * @o: expected value
8371+ * @n: new value
8372+ *
8373+ * Atomically sets @v to @n if it was equal to @o and returns
8374+ * the old value.
8375+ */
8376+
8377+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
8378+{
8379+ return cmpxchg64(&v->counter, o, n);
8380+}
8381+
8382+/**
8383 * atomic64_xchg - xchg atomic64 variable
8384 * @v: pointer to type atomic64_t
8385 * @n: value to assign
8386@@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64
8387 }
8388
8389 /**
8390+ * atomic64_set_unchecked - set atomic64 variable
8391+ * @v: pointer to type atomic64_unchecked_t
8392+ * @n: value to assign
8393+ *
8394+ * Atomically sets the value of @v to @n.
8395+ */
8396+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
8397+{
8398+ unsigned high = (unsigned)(i >> 32);
8399+ unsigned low = (unsigned)i;
8400+ asm volatile(ATOMIC64_ALTERNATIVE(set)
8401+ : "+b" (low), "+c" (high)
8402+ : "S" (v)
8403+ : "eax", "edx", "memory"
8404+ );
8405+}
8406+
8407+/**
8408 * atomic64_read - read atomic64 variable
8409 * @v: pointer to type atomic64_t
8410 *
8411@@ -93,6 +134,22 @@ static inline long long atomic64_read(at
8412 }
8413
8414 /**
8415+ * atomic64_read_unchecked - read atomic64 variable
8416+ * @v: pointer to type atomic64_unchecked_t
8417+ *
8418+ * Atomically reads the value of @v and returns it.
8419+ */
8420+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
8421+{
8422+ long long r;
8423+ asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
8424+ : "=A" (r), "+c" (v)
8425+ : : "memory"
8426+ );
8427+ return r;
8428+ }
8429+
8430+/**
8431 * atomic64_add_return - add and return
8432 * @i: integer value to add
8433 * @v: pointer to type atomic64_t
8434@@ -108,6 +165,22 @@ static inline long long atomic64_add_ret
8435 return i;
8436 }
8437
8438+/**
8439+ * atomic64_add_return_unchecked - add and return
8440+ * @i: integer value to add
8441+ * @v: pointer to type atomic64_unchecked_t
8442+ *
8443+ * Atomically adds @i to @v and returns @i + *@v
8444+ */
8445+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
8446+{
8447+ asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
8448+ : "+A" (i), "+c" (v)
8449+ : : "memory"
8450+ );
8451+ return i;
8452+}
8453+
8454 /*
8455 * Other variants with different arithmetic operators:
8456 */
8457@@ -131,6 +204,17 @@ static inline long long atomic64_inc_ret
8458 return a;
8459 }
8460
8461+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8462+{
8463+ long long a;
8464+ asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
8465+ : "=A" (a)
8466+ : "S" (v)
8467+ : "memory", "ecx"
8468+ );
8469+ return a;
8470+}
8471+
8472 static inline long long atomic64_dec_return(atomic64_t *v)
8473 {
8474 long long a;
8475@@ -159,6 +243,22 @@ static inline long long atomic64_add(lon
8476 }
8477
8478 /**
8479+ * atomic64_add_unchecked - add integer to atomic64 variable
8480+ * @i: integer value to add
8481+ * @v: pointer to type atomic64_unchecked_t
8482+ *
8483+ * Atomically adds @i to @v.
8484+ */
8485+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8486+{
8487+ asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8488+ : "+A" (i), "+c" (v)
8489+ : : "memory"
8490+ );
8491+ return i;
8492+}
8493+
8494+/**
8495 * atomic64_sub - subtract the atomic64 variable
8496 * @i: integer value to subtract
8497 * @v: pointer to type atomic64_t
8498diff -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
8499--- linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h 2011-05-19 00:06:34.000000000 -0400
8500+++ linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h 2011-05-22 19:36:30.000000000 -0400
8501@@ -18,7 +18,19 @@
8502 */
8503 static inline long atomic64_read(const atomic64_t *v)
8504 {
8505- return (*(volatile long *)&(v)->counter);
8506+ return (*(volatile const long *)&(v)->counter);
8507+}
8508+
8509+/**
8510+ * atomic64_read_unchecked - read atomic64 variable
8511+ * @v: pointer of type atomic64_unchecked_t
8512+ *
8513+ * Atomically reads the value of @v.
8514+ * Doesn't imply a read memory barrier.
8515+ */
8516+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8517+{
8518+ return (*(volatile const long *)&(v)->counter);
8519 }
8520
8521 /**
8522@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
8523 }
8524
8525 /**
8526+ * atomic64_set_unchecked - set atomic64 variable
8527+ * @v: pointer to type atomic64_unchecked_t
8528+ * @i: required value
8529+ *
8530+ * Atomically sets the value of @v to @i.
8531+ */
8532+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8533+{
8534+ v->counter = i;
8535+}
8536+
8537+/**
8538 * atomic64_add - add integer to atomic64 variable
8539 * @i: integer value to add
8540 * @v: pointer to type atomic64_t
8541@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
8542 */
8543 static inline void atomic64_add(long i, atomic64_t *v)
8544 {
8545+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
8546+
8547+#ifdef CONFIG_PAX_REFCOUNT
8548+ "jno 0f\n"
8549+ LOCK_PREFIX "subq %1,%0\n"
8550+ "int $4\n0:\n"
8551+ _ASM_EXTABLE(0b, 0b)
8552+#endif
8553+
8554+ : "=m" (v->counter)
8555+ : "er" (i), "m" (v->counter));
8556+}
8557+
8558+/**
8559+ * atomic64_add_unchecked - add integer to atomic64 variable
8560+ * @i: integer value to add
8561+ * @v: pointer to type atomic64_unchecked_t
8562+ *
8563+ * Atomically adds @i to @v.
8564+ */
8565+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8566+{
8567 asm volatile(LOCK_PREFIX "addq %1,%0"
8568 : "=m" (v->counter)
8569 : "er" (i), "m" (v->counter));
8570@@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
8571 */
8572 static inline void atomic64_sub(long i, atomic64_t *v)
8573 {
8574- asm volatile(LOCK_PREFIX "subq %1,%0"
8575+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
8576+
8577+#ifdef CONFIG_PAX_REFCOUNT
8578+ "jno 0f\n"
8579+ LOCK_PREFIX "addq %1,%0\n"
8580+ "int $4\n0:\n"
8581+ _ASM_EXTABLE(0b, 0b)
8582+#endif
8583+
8584+ : "=m" (v->counter)
8585+ : "er" (i), "m" (v->counter));
8586+}
8587+
8588+/**
8589+ * atomic64_sub_unchecked - subtract the atomic64 variable
8590+ * @i: integer value to subtract
8591+ * @v: pointer to type atomic64_unchecked_t
8592+ *
8593+ * Atomically subtracts @i from @v.
8594+ */
8595+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8596+{
8597+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
8598 : "=m" (v->counter)
8599 : "er" (i), "m" (v->counter));
8600 }
8601@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
8602 {
8603 unsigned char c;
8604
8605- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8606+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
8607+
8608+#ifdef CONFIG_PAX_REFCOUNT
8609+ "jno 0f\n"
8610+ LOCK_PREFIX "addq %2,%0\n"
8611+ "int $4\n0:\n"
8612+ _ASM_EXTABLE(0b, 0b)
8613+#endif
8614+
8615+ "sete %1\n"
8616 : "=m" (v->counter), "=qm" (c)
8617 : "er" (i), "m" (v->counter) : "memory");
8618 return c;
8619@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
8620 */
8621 static inline void atomic64_inc(atomic64_t *v)
8622 {
8623+ asm volatile(LOCK_PREFIX "incq %0\n"
8624+
8625+#ifdef CONFIG_PAX_REFCOUNT
8626+ "jno 0f\n"
8627+ LOCK_PREFIX "decq %0\n"
8628+ "int $4\n0:\n"
8629+ _ASM_EXTABLE(0b, 0b)
8630+#endif
8631+
8632+ : "=m" (v->counter)
8633+ : "m" (v->counter));
8634+}
8635+
8636+/**
8637+ * atomic64_inc_unchecked - increment atomic64 variable
8638+ * @v: pointer to type atomic64_unchecked_t
8639+ *
8640+ * Atomically increments @v by 1.
8641+ */
8642+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8643+{
8644 asm volatile(LOCK_PREFIX "incq %0"
8645 : "=m" (v->counter)
8646 : "m" (v->counter));
8647@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
8648 */
8649 static inline void atomic64_dec(atomic64_t *v)
8650 {
8651- asm volatile(LOCK_PREFIX "decq %0"
8652+ asm volatile(LOCK_PREFIX "decq %0\n"
8653+
8654+#ifdef CONFIG_PAX_REFCOUNT
8655+ "jno 0f\n"
8656+ LOCK_PREFIX "incq %0\n"
8657+ "int $4\n0:\n"
8658+ _ASM_EXTABLE(0b, 0b)
8659+#endif
8660+
8661+ : "=m" (v->counter)
8662+ : "m" (v->counter));
8663+}
8664+
8665+/**
8666+ * atomic64_dec_unchecked - decrement atomic64 variable
8667+ * @v: pointer to type atomic64_t
8668+ *
8669+ * Atomically decrements @v by 1.
8670+ */
8671+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8672+{
8673+ asm volatile(LOCK_PREFIX "decq %0\n"
8674 : "=m" (v->counter)
8675 : "m" (v->counter));
8676 }
8677@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
8678 {
8679 unsigned char c;
8680
8681- asm volatile(LOCK_PREFIX "decq %0; sete %1"
8682+ asm volatile(LOCK_PREFIX "decq %0\n"
8683+
8684+#ifdef CONFIG_PAX_REFCOUNT
8685+ "jno 0f\n"
8686+ LOCK_PREFIX "incq %0\n"
8687+ "int $4\n0:\n"
8688+ _ASM_EXTABLE(0b, 0b)
8689+#endif
8690+
8691+ "sete %1\n"
8692 : "=m" (v->counter), "=qm" (c)
8693 : "m" (v->counter) : "memory");
8694 return c != 0;
8695@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
8696 {
8697 unsigned char c;
8698
8699- asm volatile(LOCK_PREFIX "incq %0; sete %1"
8700+ asm volatile(LOCK_PREFIX "incq %0\n"
8701+
8702+#ifdef CONFIG_PAX_REFCOUNT
8703+ "jno 0f\n"
8704+ LOCK_PREFIX "decq %0\n"
8705+ "int $4\n0:\n"
8706+ _ASM_EXTABLE(0b, 0b)
8707+#endif
8708+
8709+ "sete %1\n"
8710 : "=m" (v->counter), "=qm" (c)
8711 : "m" (v->counter) : "memory");
8712 return c != 0;
8713@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
8714 {
8715 unsigned char c;
8716
8717- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8718+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
8719+
8720+#ifdef CONFIG_PAX_REFCOUNT
8721+ "jno 0f\n"
8722+ LOCK_PREFIX "subq %2,%0\n"
8723+ "int $4\n0:\n"
8724+ _ASM_EXTABLE(0b, 0b)
8725+#endif
8726+
8727+ "sets %1\n"
8728 : "=m" (v->counter), "=qm" (c)
8729 : "er" (i), "m" (v->counter) : "memory");
8730 return c;
8731@@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
8732 static inline long atomic64_add_return(long i, atomic64_t *v)
8733 {
8734 long __i = i;
8735- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
8736+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
8737+
8738+#ifdef CONFIG_PAX_REFCOUNT
8739+ "jno 0f\n"
8740+ "movq %0, %1\n"
8741+ "int $4\n0:\n"
8742+ _ASM_EXTABLE(0b, 0b)
8743+#endif
8744+
8745+ : "+r" (i), "+m" (v->counter)
8746+ : : "memory");
8747+ return i + __i;
8748+}
8749+
8750+/**
8751+ * atomic64_add_return_unchecked - add and return
8752+ * @i: integer value to add
8753+ * @v: pointer to type atomic64_unchecked_t
8754+ *
8755+ * Atomically adds @i to @v and returns @i + @v
8756+ */
8757+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8758+{
8759+ long __i = i;
8760+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
8761 : "+r" (i), "+m" (v->counter)
8762 : : "memory");
8763 return i + __i;
8764@@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
8765 }
8766
8767 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8768+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8769+{
8770+ return atomic64_add_return_unchecked(1, v);
8771+}
8772 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8773
8774 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8775@@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atom
8776 return cmpxchg(&v->counter, old, new);
8777 }
8778
8779+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8780+{
8781+ return cmpxchg(&v->counter, old, new);
8782+}
8783+
8784 static inline long atomic64_xchg(atomic64_t *v, long new)
8785 {
8786 return xchg(&v->counter, new);
8787@@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic6
8788 */
8789 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8790 {
8791- long c, old;
8792+ long c, old, new;
8793 c = atomic64_read(v);
8794 for (;;) {
8795- if (unlikely(c == (u)))
8796+ if (unlikely(c == u))
8797 break;
8798- old = atomic64_cmpxchg((v), c, c + (a));
8799+
8800+ asm volatile("add %2,%0\n"
8801+
8802+#ifdef CONFIG_PAX_REFCOUNT
8803+ "jno 0f\n"
8804+ "sub %2,%0\n"
8805+ "int $4\n0:\n"
8806+ _ASM_EXTABLE(0b, 0b)
8807+#endif
8808+
8809+ : "=r" (new)
8810+ : "0" (c), "ir" (a));
8811+
8812+ old = atomic64_cmpxchg(v, c, new);
8813 if (likely(old == c))
8814 break;
8815 c = old;
8816 }
8817- return c != (u);
8818+ return c != u;
8819 }
8820
8821 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8822diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic.h linux-2.6.39.1/arch/x86/include/asm/atomic.h
8823--- linux-2.6.39.1/arch/x86/include/asm/atomic.h 2011-05-19 00:06:34.000000000 -0400
8824+++ linux-2.6.39.1/arch/x86/include/asm/atomic.h 2011-05-22 19:36:30.000000000 -0400
8825@@ -22,7 +22,18 @@
8826 */
8827 static inline int atomic_read(const atomic_t *v)
8828 {
8829- return (*(volatile int *)&(v)->counter);
8830+ return (*(volatile const int *)&(v)->counter);
8831+}
8832+
8833+/**
8834+ * atomic_read_unchecked - read atomic variable
8835+ * @v: pointer of type atomic_unchecked_t
8836+ *
8837+ * Atomically reads the value of @v.
8838+ */
8839+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8840+{
8841+ return (*(volatile const int *)&(v)->counter);
8842 }
8843
8844 /**
8845@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
8846 }
8847
8848 /**
8849+ * atomic_set_unchecked - set atomic variable
8850+ * @v: pointer of type atomic_unchecked_t
8851+ * @i: required value
8852+ *
8853+ * Atomically sets the value of @v to @i.
8854+ */
8855+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8856+{
8857+ v->counter = i;
8858+}
8859+
8860+/**
8861 * atomic_add - add integer to atomic variable
8862 * @i: integer value to add
8863 * @v: pointer of type atomic_t
8864@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
8865 */
8866 static inline void atomic_add(int i, atomic_t *v)
8867 {
8868- asm volatile(LOCK_PREFIX "addl %1,%0"
8869+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8870+
8871+#ifdef CONFIG_PAX_REFCOUNT
8872+ "jno 0f\n"
8873+ LOCK_PREFIX "subl %1,%0\n"
8874+ "int $4\n0:\n"
8875+ _ASM_EXTABLE(0b, 0b)
8876+#endif
8877+
8878+ : "+m" (v->counter)
8879+ : "ir" (i));
8880+}
8881+
8882+/**
8883+ * atomic_add_unchecked - add integer to atomic variable
8884+ * @i: integer value to add
8885+ * @v: pointer of type atomic_unchecked_t
8886+ *
8887+ * Atomically adds @i to @v.
8888+ */
8889+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8890+{
8891+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8892 : "+m" (v->counter)
8893 : "ir" (i));
8894 }
8895@@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
8896 */
8897 static inline void atomic_sub(int i, atomic_t *v)
8898 {
8899- asm volatile(LOCK_PREFIX "subl %1,%0"
8900+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8901+
8902+#ifdef CONFIG_PAX_REFCOUNT
8903+ "jno 0f\n"
8904+ LOCK_PREFIX "addl %1,%0\n"
8905+ "int $4\n0:\n"
8906+ _ASM_EXTABLE(0b, 0b)
8907+#endif
8908+
8909+ : "+m" (v->counter)
8910+ : "ir" (i));
8911+}
8912+
8913+/**
8914+ * atomic_sub_unchecked - subtract integer from atomic variable
8915+ * @i: integer value to subtract
8916+ * @v: pointer of type atomic_unchecked_t
8917+ *
8918+ * Atomically subtracts @i from @v.
8919+ */
8920+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8921+{
8922+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8923 : "+m" (v->counter)
8924 : "ir" (i));
8925 }
8926@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
8927 {
8928 unsigned char c;
8929
8930- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8931+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8932+
8933+#ifdef CONFIG_PAX_REFCOUNT
8934+ "jno 0f\n"
8935+ LOCK_PREFIX "addl %2,%0\n"
8936+ "int $4\n0:\n"
8937+ _ASM_EXTABLE(0b, 0b)
8938+#endif
8939+
8940+ "sete %1\n"
8941 : "+m" (v->counter), "=qm" (c)
8942 : "ir" (i) : "memory");
8943 return c;
8944@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
8945 */
8946 static inline void atomic_inc(atomic_t *v)
8947 {
8948- asm volatile(LOCK_PREFIX "incl %0"
8949+ asm volatile(LOCK_PREFIX "incl %0\n"
8950+
8951+#ifdef CONFIG_PAX_REFCOUNT
8952+ "jno 0f\n"
8953+ LOCK_PREFIX "decl %0\n"
8954+ "int $4\n0:\n"
8955+ _ASM_EXTABLE(0b, 0b)
8956+#endif
8957+
8958+ : "+m" (v->counter));
8959+}
8960+
8961+/**
8962+ * atomic_inc_unchecked - increment atomic variable
8963+ * @v: pointer of type atomic_unchecked_t
8964+ *
8965+ * Atomically increments @v by 1.
8966+ */
8967+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8968+{
8969+ asm volatile(LOCK_PREFIX "incl %0\n"
8970 : "+m" (v->counter));
8971 }
8972
8973@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
8974 */
8975 static inline void atomic_dec(atomic_t *v)
8976 {
8977- asm volatile(LOCK_PREFIX "decl %0"
8978+ asm volatile(LOCK_PREFIX "decl %0\n"
8979+
8980+#ifdef CONFIG_PAX_REFCOUNT
8981+ "jno 0f\n"
8982+ LOCK_PREFIX "incl %0\n"
8983+ "int $4\n0:\n"
8984+ _ASM_EXTABLE(0b, 0b)
8985+#endif
8986+
8987+ : "+m" (v->counter));
8988+}
8989+
8990+/**
8991+ * atomic_dec_unchecked - decrement atomic variable
8992+ * @v: pointer of type atomic_unchecked_t
8993+ *
8994+ * Atomically decrements @v by 1.
8995+ */
8996+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8997+{
8998+ asm volatile(LOCK_PREFIX "decl %0\n"
8999 : "+m" (v->counter));
9000 }
9001
9002@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
9003 {
9004 unsigned char c;
9005
9006- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9007+ asm volatile(LOCK_PREFIX "decl %0\n"
9008+
9009+#ifdef CONFIG_PAX_REFCOUNT
9010+ "jno 0f\n"
9011+ LOCK_PREFIX "incl %0\n"
9012+ "int $4\n0:\n"
9013+ _ASM_EXTABLE(0b, 0b)
9014+#endif
9015+
9016+ "sete %1\n"
9017 : "+m" (v->counter), "=qm" (c)
9018 : : "memory");
9019 return c != 0;
9020@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(at
9021 {
9022 unsigned char c;
9023
9024- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9025+ asm volatile(LOCK_PREFIX "incl %0\n"
9026+
9027+#ifdef CONFIG_PAX_REFCOUNT
9028+ "jno 0f\n"
9029+ LOCK_PREFIX "decl %0\n"
9030+ "int $4\n0:\n"
9031+ _ASM_EXTABLE(0b, 0b)
9032+#endif
9033+
9034+ "sete %1\n"
9035+ : "+m" (v->counter), "=qm" (c)
9036+ : : "memory");
9037+ return c != 0;
9038+}
9039+
9040+/**
9041+ * atomic_inc_and_test_unchecked - increment and test
9042+ * @v: pointer of type atomic_unchecked_t
9043+ *
9044+ * Atomically increments @v by 1
9045+ * and returns true if the result is zero, or false for all
9046+ * other cases.
9047+ */
9048+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9049+{
9050+ unsigned char c;
9051+
9052+ asm volatile(LOCK_PREFIX "incl %0\n"
9053+ "sete %1\n"
9054 : "+m" (v->counter), "=qm" (c)
9055 : : "memory");
9056 return c != 0;
9057@@ -157,7 +310,16 @@ static inline int atomic_add_negative(in
9058 {
9059 unsigned char c;
9060
9061- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9062+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9063+
9064+#ifdef CONFIG_PAX_REFCOUNT
9065+ "jno 0f\n"
9066+ LOCK_PREFIX "subl %2,%0\n"
9067+ "int $4\n0:\n"
9068+ _ASM_EXTABLE(0b, 0b)
9069+#endif
9070+
9071+ "sets %1\n"
9072 : "+m" (v->counter), "=qm" (c)
9073 : "ir" (i) : "memory");
9074 return c;
9075@@ -180,6 +342,46 @@ static inline int atomic_add_return(int
9076 #endif
9077 /* Modern 486+ processor */
9078 __i = i;
9079+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9080+
9081+#ifdef CONFIG_PAX_REFCOUNT
9082+ "jno 0f\n"
9083+ "movl %0, %1\n"
9084+ "int $4\n0:\n"
9085+ _ASM_EXTABLE(0b, 0b)
9086+#endif
9087+
9088+ : "+r" (i), "+m" (v->counter)
9089+ : : "memory");
9090+ return i + __i;
9091+
9092+#ifdef CONFIG_M386
9093+no_xadd: /* Legacy 386 processor */
9094+ local_irq_save(flags);
9095+ __i = atomic_read(v);
9096+ atomic_set(v, i + __i);
9097+ local_irq_restore(flags);
9098+ return i + __i;
9099+#endif
9100+}
9101+
9102+/**
9103+ * atomic_add_return_unchecked - add integer and return
9104+ * @v: pointer of type atomic_unchecked_t
9105+ * @i: integer value to add
9106+ *
9107+ * Atomically adds @i to @v and returns @i + @v
9108+ */
9109+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9110+{
9111+ int __i;
9112+#ifdef CONFIG_M386
9113+ unsigned long flags;
9114+ if (unlikely(boot_cpu_data.x86 <= 3))
9115+ goto no_xadd;
9116+#endif
9117+ /* Modern 486+ processor */
9118+ __i = i;
9119 asm volatile(LOCK_PREFIX "xaddl %0, %1"
9120 : "+r" (i), "+m" (v->counter)
9121 : : "memory");
9122@@ -208,6 +410,10 @@ static inline int atomic_sub_return(int
9123 }
9124
9125 #define atomic_inc_return(v) (atomic_add_return(1, v))
9126+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9127+{
9128+ return atomic_add_return_unchecked(1, v);
9129+}
9130 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9131
9132 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9133@@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_
9134 return cmpxchg(&v->counter, old, new);
9135 }
9136
9137+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9138+{
9139+ return cmpxchg(&v->counter, old, new);
9140+}
9141+
9142 static inline int atomic_xchg(atomic_t *v, int new)
9143 {
9144 return xchg(&v->counter, new);
9145 }
9146
9147+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9148+{
9149+ return xchg(&v->counter, new);
9150+}
9151+
9152 /**
9153 * atomic_add_unless - add unless the number is already a given value
9154 * @v: pointer of type atomic_t
9155@@ -231,21 +447,77 @@ static inline int atomic_xchg(atomic_t *
9156 */
9157 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9158 {
9159- int c, old;
9160+ int c, old, new;
9161 c = atomic_read(v);
9162 for (;;) {
9163- if (unlikely(c == (u)))
9164+ if (unlikely(c == u))
9165 break;
9166- old = atomic_cmpxchg((v), c, c + (a));
9167+
9168+ asm volatile("addl %2,%0\n"
9169+
9170+#ifdef CONFIG_PAX_REFCOUNT
9171+ "jno 0f\n"
9172+ "subl %2,%0\n"
9173+ "int $4\n0:\n"
9174+ _ASM_EXTABLE(0b, 0b)
9175+#endif
9176+
9177+ : "=r" (new)
9178+ : "0" (c), "ir" (a));
9179+
9180+ old = atomic_cmpxchg(v, c, new);
9181 if (likely(old == c))
9182 break;
9183 c = old;
9184 }
9185- return c != (u);
9186+ return c != u;
9187 }
9188
9189 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9190
9191+/**
9192+ * atomic_inc_not_zero_hint - increment if not null
9193+ * @v: pointer of type atomic_t
9194+ * @hint: probable value of the atomic before the increment
9195+ *
9196+ * This version of atomic_inc_not_zero() gives a hint of probable
9197+ * value of the atomic. This helps processor to not read the memory
9198+ * before doing the atomic read/modify/write cycle, lowering
9199+ * number of bus transactions on some arches.
9200+ *
9201+ * Returns: 0 if increment was not done, 1 otherwise.
9202+ */
9203+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9204+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9205+{
9206+ int val, c = hint, new;
9207+
9208+ /* sanity test, should be removed by compiler if hint is a constant */
9209+ if (!hint)
9210+ return atomic_inc_not_zero(v);
9211+
9212+ do {
9213+ asm volatile("incl %0\n"
9214+
9215+#ifdef CONFIG_PAX_REFCOUNT
9216+ "jno 0f\n"
9217+ "decl %0\n"
9218+ "int $4\n0:\n"
9219+ _ASM_EXTABLE(0b, 0b)
9220+#endif
9221+
9222+ : "=r" (new)
9223+ : "0" (c));
9224+
9225+ val = atomic_cmpxchg(v, c, new);
9226+ if (val == c)
9227+ return 1;
9228+ c = val;
9229+ } while (c);
9230+
9231+ return 0;
9232+}
9233+
9234 /*
9235 * atomic_dec_if_positive - decrement by 1 if old value positive
9236 * @v: pointer of type atomic_t
9237diff -urNp linux-2.6.39.1/arch/x86/include/asm/bitops.h linux-2.6.39.1/arch/x86/include/asm/bitops.h
9238--- linux-2.6.39.1/arch/x86/include/asm/bitops.h 2011-05-19 00:06:34.000000000 -0400
9239+++ linux-2.6.39.1/arch/x86/include/asm/bitops.h 2011-05-22 19:36:30.000000000 -0400
9240@@ -38,7 +38,7 @@
9241 * a mask operation on a byte.
9242 */
9243 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9244-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9245+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9246 #define CONST_MASK(nr) (1 << ((nr) & 7))
9247
9248 /**
9249diff -urNp linux-2.6.39.1/arch/x86/include/asm/boot.h linux-2.6.39.1/arch/x86/include/asm/boot.h
9250--- linux-2.6.39.1/arch/x86/include/asm/boot.h 2011-05-19 00:06:34.000000000 -0400
9251+++ linux-2.6.39.1/arch/x86/include/asm/boot.h 2011-05-22 19:36:30.000000000 -0400
9252@@ -11,10 +11,15 @@
9253 #include <asm/pgtable_types.h>
9254
9255 /* Physical address where kernel should be loaded. */
9256-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9257+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9258 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9259 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9260
9261+#ifndef __ASSEMBLY__
9262+extern unsigned char __LOAD_PHYSICAL_ADDR[];
9263+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9264+#endif
9265+
9266 /* Minimum kernel alignment, as a power of two */
9267 #ifdef CONFIG_X86_64
9268 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9269diff -urNp linux-2.6.39.1/arch/x86/include/asm/cacheflush.h linux-2.6.39.1/arch/x86/include/asm/cacheflush.h
9270--- linux-2.6.39.1/arch/x86/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
9271+++ linux-2.6.39.1/arch/x86/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
9272@@ -26,7 +26,7 @@ static inline unsigned long get_page_mem
9273 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9274
9275 if (pg_flags == _PGMT_DEFAULT)
9276- return -1;
9277+ return ~0UL;
9278 else if (pg_flags == _PGMT_WC)
9279 return _PAGE_CACHE_WC;
9280 else if (pg_flags == _PGMT_UC_MINUS)
9281diff -urNp linux-2.6.39.1/arch/x86/include/asm/cache.h linux-2.6.39.1/arch/x86/include/asm/cache.h
9282--- linux-2.6.39.1/arch/x86/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
9283+++ linux-2.6.39.1/arch/x86/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
9284@@ -5,12 +5,13 @@
9285
9286 /* L1 cache line size */
9287 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9288-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9289+#define L1_CACHE_BYTES (_AC(1,U) << L1_CACHE_SHIFT)
9290
9291 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9292+#define __read_only __attribute__((__section__(".data..read_only")))
9293
9294 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9295-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9296+#define INTERNODE_CACHE_BYTES (_AC(1,U) << INTERNODE_CACHE_SHIFT)
9297
9298 #ifdef CONFIG_X86_VSMP
9299 #ifdef CONFIG_SMP
9300diff -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
9301--- linux-2.6.39.1/arch/x86/include/asm/checksum_32.h 2011-05-19 00:06:34.000000000 -0400
9302+++ linux-2.6.39.1/arch/x86/include/asm/checksum_32.h 2011-05-22 19:36:30.000000000 -0400
9303@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
9304 int len, __wsum sum,
9305 int *src_err_ptr, int *dst_err_ptr);
9306
9307+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9308+ int len, __wsum sum,
9309+ int *src_err_ptr, int *dst_err_ptr);
9310+
9311+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9312+ int len, __wsum sum,
9313+ int *src_err_ptr, int *dst_err_ptr);
9314+
9315 /*
9316 * Note: when you get a NULL pointer exception here this means someone
9317 * passed in an incorrect kernel address to one of these functions.
9318@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
9319 int *err_ptr)
9320 {
9321 might_sleep();
9322- return csum_partial_copy_generic((__force void *)src, dst,
9323+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
9324 len, sum, err_ptr, NULL);
9325 }
9326
9327@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
9328 {
9329 might_sleep();
9330 if (access_ok(VERIFY_WRITE, dst, len))
9331- return csum_partial_copy_generic(src, (__force void *)dst,
9332+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9333 len, sum, NULL, err_ptr);
9334
9335 if (len)
9336diff -urNp linux-2.6.39.1/arch/x86/include/asm/cpufeature.h linux-2.6.39.1/arch/x86/include/asm/cpufeature.h
9337--- linux-2.6.39.1/arch/x86/include/asm/cpufeature.h 2011-06-03 00:04:13.000000000 -0400
9338+++ linux-2.6.39.1/arch/x86/include/asm/cpufeature.h 2011-06-03 00:32:04.000000000 -0400
9339@@ -351,7 +351,7 @@ static __always_inline __pure bool __sta
9340 ".section .discard,\"aw\",@progbits\n"
9341 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9342 ".previous\n"
9343- ".section .altinstr_replacement,\"ax\"\n"
9344+ ".section .altinstr_replacement,\"a\"\n"
9345 "3: movb $1,%0\n"
9346 "4:\n"
9347 ".previous\n"
9348diff -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
9349--- linux-2.6.39.1/arch/x86/include/asm/desc_defs.h 2011-05-19 00:06:34.000000000 -0400
9350+++ linux-2.6.39.1/arch/x86/include/asm/desc_defs.h 2011-05-22 19:36:30.000000000 -0400
9351@@ -31,6 +31,12 @@ struct desc_struct {
9352 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9353 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9354 };
9355+ struct {
9356+ u16 offset_low;
9357+ u16 seg;
9358+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9359+ unsigned offset_high: 16;
9360+ } gate;
9361 };
9362 } __attribute__((packed));
9363
9364diff -urNp linux-2.6.39.1/arch/x86/include/asm/desc.h linux-2.6.39.1/arch/x86/include/asm/desc.h
9365--- linux-2.6.39.1/arch/x86/include/asm/desc.h 2011-05-19 00:06:34.000000000 -0400
9366+++ linux-2.6.39.1/arch/x86/include/asm/desc.h 2011-05-22 19:36:30.000000000 -0400
9367@@ -4,6 +4,7 @@
9368 #include <asm/desc_defs.h>
9369 #include <asm/ldt.h>
9370 #include <asm/mmu.h>
9371+#include <asm/pgtable.h>
9372 #include <linux/smp.h>
9373
9374 static inline void fill_ldt(struct desc_struct *desc,
9375@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
9376 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9377 desc->type = (info->read_exec_only ^ 1) << 1;
9378 desc->type |= info->contents << 2;
9379+ desc->type |= info->seg_not_present ^ 1;
9380 desc->s = 1;
9381 desc->dpl = 0x3;
9382 desc->p = info->seg_not_present ^ 1;
9383@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
9384 }
9385
9386 extern struct desc_ptr idt_descr;
9387-extern gate_desc idt_table[];
9388-
9389-struct gdt_page {
9390- struct desc_struct gdt[GDT_ENTRIES];
9391-} __attribute__((aligned(PAGE_SIZE)));
9392-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9393+extern gate_desc idt_table[256];
9394
9395+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9396 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9397 {
9398- return per_cpu(gdt_page, cpu).gdt;
9399+ return cpu_gdt_table[cpu];
9400 }
9401
9402 #ifdef CONFIG_X86_64
9403@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
9404 unsigned long base, unsigned dpl, unsigned flags,
9405 unsigned short seg)
9406 {
9407- gate->a = (seg << 16) | (base & 0xffff);
9408- gate->b = (base & 0xffff0000) |
9409- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9410+ gate->gate.offset_low = base;
9411+ gate->gate.seg = seg;
9412+ gate->gate.reserved = 0;
9413+ gate->gate.type = type;
9414+ gate->gate.s = 0;
9415+ gate->gate.dpl = dpl;
9416+ gate->gate.p = 1;
9417+ gate->gate.offset_high = base >> 16;
9418 }
9419
9420 #endif
9421@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
9422 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9423 const gate_desc *gate)
9424 {
9425+ pax_open_kernel();
9426 memcpy(&idt[entry], gate, sizeof(*gate));
9427+ pax_close_kernel();
9428 }
9429
9430 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9431 const void *desc)
9432 {
9433+ pax_open_kernel();
9434 memcpy(&ldt[entry], desc, 8);
9435+ pax_close_kernel();
9436 }
9437
9438 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9439@@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
9440 size = sizeof(struct desc_struct);
9441 break;
9442 }
9443+
9444+ pax_open_kernel();
9445 memcpy(&gdt[entry], desc, size);
9446+ pax_close_kernel();
9447 }
9448
9449 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9450@@ -211,7 +221,9 @@ static inline void native_set_ldt(const
9451
9452 static inline void native_load_tr_desc(void)
9453 {
9454+ pax_open_kernel();
9455 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9456+ pax_close_kernel();
9457 }
9458
9459 static inline void native_load_gdt(const struct desc_ptr *dtr)
9460@@ -246,8 +258,10 @@ static inline void native_load_tls(struc
9461 unsigned int i;
9462 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9463
9464+ pax_open_kernel();
9465 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9466 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9467+ pax_close_kernel();
9468 }
9469
9470 #define _LDT_empty(info) \
9471@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
9472 desc->limit = (limit >> 16) & 0xf;
9473 }
9474
9475-static inline void _set_gate(int gate, unsigned type, void *addr,
9476+static inline void _set_gate(int gate, unsigned type, const void *addr,
9477 unsigned dpl, unsigned ist, unsigned seg)
9478 {
9479 gate_desc s;
9480@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
9481 * Pentium F0 0F bugfix can have resulted in the mapped
9482 * IDT being write-protected.
9483 */
9484-static inline void set_intr_gate(unsigned int n, void *addr)
9485+static inline void set_intr_gate(unsigned int n, const void *addr)
9486 {
9487 BUG_ON((unsigned)n > 0xFF);
9488 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9489@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
9490 /*
9491 * This routine sets up an interrupt gate at directory privilege level 3.
9492 */
9493-static inline void set_system_intr_gate(unsigned int n, void *addr)
9494+static inline void set_system_intr_gate(unsigned int n, const void *addr)
9495 {
9496 BUG_ON((unsigned)n > 0xFF);
9497 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9498 }
9499
9500-static inline void set_system_trap_gate(unsigned int n, void *addr)
9501+static inline void set_system_trap_gate(unsigned int n, const void *addr)
9502 {
9503 BUG_ON((unsigned)n > 0xFF);
9504 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9505 }
9506
9507-static inline void set_trap_gate(unsigned int n, void *addr)
9508+static inline void set_trap_gate(unsigned int n, const void *addr)
9509 {
9510 BUG_ON((unsigned)n > 0xFF);
9511 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9512@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
9513 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9514 {
9515 BUG_ON((unsigned)n > 0xFF);
9516- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9517+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9518 }
9519
9520-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9521+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9522 {
9523 BUG_ON((unsigned)n > 0xFF);
9524 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9525 }
9526
9527-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9528+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9529 {
9530 BUG_ON((unsigned)n > 0xFF);
9531 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9532 }
9533
9534+#ifdef CONFIG_X86_32
9535+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9536+{
9537+ struct desc_struct d;
9538+
9539+ if (likely(limit))
9540+ limit = (limit - 1UL) >> PAGE_SHIFT;
9541+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
9542+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9543+}
9544+#endif
9545+
9546 #endif /* _ASM_X86_DESC_H */
9547diff -urNp linux-2.6.39.1/arch/x86/include/asm/device.h linux-2.6.39.1/arch/x86/include/asm/device.h
9548--- linux-2.6.39.1/arch/x86/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
9549+++ linux-2.6.39.1/arch/x86/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
9550@@ -6,7 +6,7 @@ struct dev_archdata {
9551 void *acpi_handle;
9552 #endif
9553 #ifdef CONFIG_X86_64
9554-struct dma_map_ops *dma_ops;
9555+ const struct dma_map_ops *dma_ops;
9556 #endif
9557 #if defined(CONFIG_DMAR) || defined(CONFIG_AMD_IOMMU)
9558 void *iommu; /* hook for IOMMU specific extension */
9559diff -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
9560--- linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
9561+++ linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
9562@@ -26,9 +26,9 @@ extern int iommu_merge;
9563 extern struct device x86_dma_fallback_dev;
9564 extern int panic_on_overflow;
9565
9566-extern struct dma_map_ops *dma_ops;
9567+extern const struct dma_map_ops *dma_ops;
9568
9569-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9570+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9571 {
9572 #ifdef CONFIG_X86_32
9573 return dma_ops;
9574@@ -45,7 +45,7 @@ static inline struct dma_map_ops *get_dm
9575 /* Make sure we keep the same behaviour */
9576 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9577 {
9578- struct dma_map_ops *ops = get_dma_ops(dev);
9579+ const struct dma_map_ops *ops = get_dma_ops(dev);
9580 if (ops->mapping_error)
9581 return ops->mapping_error(dev, dma_addr);
9582
9583@@ -115,7 +115,7 @@ static inline void *
9584 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9585 gfp_t gfp)
9586 {
9587- struct dma_map_ops *ops = get_dma_ops(dev);
9588+ const struct dma_map_ops *ops = get_dma_ops(dev);
9589 void *memory;
9590
9591 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9592@@ -142,7 +142,7 @@ dma_alloc_coherent(struct device *dev, s
9593 static inline void dma_free_coherent(struct device *dev, size_t size,
9594 void *vaddr, dma_addr_t bus)
9595 {
9596- struct dma_map_ops *ops = get_dma_ops(dev);
9597+ const struct dma_map_ops *ops = get_dma_ops(dev);
9598
9599 WARN_ON(irqs_disabled()); /* for portability */
9600
9601diff -urNp linux-2.6.39.1/arch/x86/include/asm/e820.h linux-2.6.39.1/arch/x86/include/asm/e820.h
9602--- linux-2.6.39.1/arch/x86/include/asm/e820.h 2011-05-19 00:06:34.000000000 -0400
9603+++ linux-2.6.39.1/arch/x86/include/asm/e820.h 2011-05-22 19:36:30.000000000 -0400
9604@@ -69,7 +69,7 @@ struct e820map {
9605 #define ISA_START_ADDRESS 0xa0000
9606 #define ISA_END_ADDRESS 0x100000
9607
9608-#define BIOS_BEGIN 0x000a0000
9609+#define BIOS_BEGIN 0x000c0000
9610 #define BIOS_END 0x00100000
9611
9612 #define BIOS_ROM_BASE 0xffe00000
9613diff -urNp linux-2.6.39.1/arch/x86/include/asm/elf.h linux-2.6.39.1/arch/x86/include/asm/elf.h
9614--- linux-2.6.39.1/arch/x86/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
9615+++ linux-2.6.39.1/arch/x86/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
9616@@ -237,7 +237,25 @@ extern int force_personality32;
9617 the loader. We need to make sure that it is out of the way of the program
9618 that it will "exec", and that there is sufficient room for the brk. */
9619
9620+#ifdef CONFIG_PAX_SEGMEXEC
9621+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9622+#else
9623 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9624+#endif
9625+
9626+#ifdef CONFIG_PAX_ASLR
9627+#ifdef CONFIG_X86_32
9628+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9629+
9630+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9631+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9632+#else
9633+#define PAX_ELF_ET_DYN_BASE 0x400000UL
9634+
9635+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9636+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9637+#endif
9638+#endif
9639
9640 /* This yields a mask that user programs can use to figure out what
9641 instruction set this CPU supports. This could be done in user space,
9642@@ -291,8 +309,7 @@ do { \
9643 #define ARCH_DLINFO \
9644 do { \
9645 if (vdso_enabled) \
9646- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9647- (unsigned long)current->mm->context.vdso); \
9648+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
9649 } while (0)
9650
9651 #define AT_SYSINFO 32
9652@@ -303,7 +320,7 @@ do { \
9653
9654 #endif /* !CONFIG_X86_32 */
9655
9656-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9657+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9658
9659 #define VDSO_ENTRY \
9660 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9661@@ -317,7 +334,4 @@ extern int arch_setup_additional_pages(s
9662 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9663 #define compat_arch_setup_additional_pages syscall32_setup_pages
9664
9665-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9666-#define arch_randomize_brk arch_randomize_brk
9667-
9668 #endif /* _ASM_X86_ELF_H */
9669diff -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
9670--- linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h 2011-05-19 00:06:34.000000000 -0400
9671+++ linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h 2011-05-22 19:36:30.000000000 -0400
9672@@ -15,6 +15,6 @@ enum reboot_type {
9673
9674 extern enum reboot_type reboot_type;
9675
9676-extern void machine_emergency_restart(void);
9677+extern void machine_emergency_restart(void) __noreturn;
9678
9679 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9680diff -urNp linux-2.6.39.1/arch/x86/include/asm/futex.h linux-2.6.39.1/arch/x86/include/asm/futex.h
9681--- linux-2.6.39.1/arch/x86/include/asm/futex.h 2011-05-19 00:06:34.000000000 -0400
9682+++ linux-2.6.39.1/arch/x86/include/asm/futex.h 2011-05-22 19:36:30.000000000 -0400
9683@@ -12,16 +12,18 @@
9684 #include <asm/system.h>
9685
9686 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9687+ typecheck(u32 *, uaddr); \
9688 asm volatile("1:\t" insn "\n" \
9689 "2:\t.section .fixup,\"ax\"\n" \
9690 "3:\tmov\t%3, %1\n" \
9691 "\tjmp\t2b\n" \
9692 "\t.previous\n" \
9693 _ASM_EXTABLE(1b, 3b) \
9694- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9695+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
9696 : "i" (-EFAULT), "0" (oparg), "1" (0))
9697
9698 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9699+ typecheck(u32 *, uaddr); \
9700 asm volatile("1:\tmovl %2, %0\n" \
9701 "\tmovl\t%0, %3\n" \
9702 "\t" insn "\n" \
9703@@ -34,7 +36,7 @@
9704 _ASM_EXTABLE(1b, 4b) \
9705 _ASM_EXTABLE(2b, 4b) \
9706 : "=&a" (oldval), "=&r" (ret), \
9707- "+m" (*uaddr), "=&r" (tem) \
9708+ "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
9709 : "r" (oparg), "i" (-EFAULT), "1" (0))
9710
9711 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9712@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
9713
9714 switch (op) {
9715 case FUTEX_OP_SET:
9716- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9717+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9718 break;
9719 case FUTEX_OP_ADD:
9720- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9721+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9722 uaddr, oparg);
9723 break;
9724 case FUTEX_OP_OR:
9725@@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_i
9726 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9727 return -EFAULT;
9728
9729- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
9730+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
9731 "2:\t.section .fixup, \"ax\"\n"
9732 "3:\tmov %3, %0\n"
9733 "\tjmp 2b\n"
9734 "\t.previous\n"
9735 _ASM_EXTABLE(1b, 3b)
9736- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
9737+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
9738 : "i" (-EFAULT), "r" (newval), "1" (oldval)
9739 : "memory"
9740 );
9741diff -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
9742--- linux-2.6.39.1/arch/x86/include/asm/hw_irq.h 2011-05-19 00:06:34.000000000 -0400
9743+++ linux-2.6.39.1/arch/x86/include/asm/hw_irq.h 2011-05-22 19:36:30.000000000 -0400
9744@@ -137,8 +137,8 @@ extern void setup_ioapic_dest(void);
9745 extern void enable_IO_APIC(void);
9746
9747 /* Statistics */
9748-extern atomic_t irq_err_count;
9749-extern atomic_t irq_mis_count;
9750+extern atomic_unchecked_t irq_err_count;
9751+extern atomic_unchecked_t irq_mis_count;
9752
9753 /* EISA */
9754 extern void eisa_set_level_irq(unsigned int irq);
9755diff -urNp linux-2.6.39.1/arch/x86/include/asm/i387.h linux-2.6.39.1/arch/x86/include/asm/i387.h
9756--- linux-2.6.39.1/arch/x86/include/asm/i387.h 2011-05-19 00:06:34.000000000 -0400
9757+++ linux-2.6.39.1/arch/x86/include/asm/i387.h 2011-05-22 19:36:30.000000000 -0400
9758@@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
9759 {
9760 int err;
9761
9762+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9763+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9764+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
9765+#endif
9766+
9767 /* See comment in fxsave() below. */
9768 #ifdef CONFIG_AS_FXSAVEQ
9769 asm volatile("1: fxrstorq %[fx]\n\t"
9770@@ -121,6 +126,11 @@ static inline int fxsave_user(struct i38
9771 {
9772 int err;
9773
9774+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9775+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9776+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9777+#endif
9778+
9779 /*
9780 * Clear the bytes not touched by the fxsave and reserved
9781 * for the SW usage.
9782@@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu
9783 #endif /* CONFIG_X86_64 */
9784
9785 /* We need a safe address that is cheap to find and that is already
9786- in L1 during context switch. The best choices are unfortunately
9787- different for UP and SMP */
9788-#ifdef CONFIG_SMP
9789-#define safe_address (__per_cpu_offset[0])
9790-#else
9791-#define safe_address (kstat_cpu(0).cpustat.user)
9792-#endif
9793+ in L1 during context switch. */
9794+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
9795
9796 /*
9797 * These must be called with preempt disabled
9798@@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void
9799 struct thread_info *me = current_thread_info();
9800 preempt_disable();
9801 if (me->status & TS_USEDFPU)
9802- __save_init_fpu(me->task);
9803+ __save_init_fpu(current);
9804 else
9805 clts();
9806 }
9807diff -urNp linux-2.6.39.1/arch/x86/include/asm/io.h linux-2.6.39.1/arch/x86/include/asm/io.h
9808--- linux-2.6.39.1/arch/x86/include/asm/io.h 2011-05-19 00:06:34.000000000 -0400
9809+++ linux-2.6.39.1/arch/x86/include/asm/io.h 2011-05-22 19:36:30.000000000 -0400
9810@@ -216,6 +216,17 @@ extern void set_iounmap_nonlazy(void);
9811
9812 #include <linux/vmalloc.h>
9813
9814+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9815+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9816+{
9817+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9818+}
9819+
9820+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9821+{
9822+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9823+}
9824+
9825 /*
9826 * Convert a virtual cached pointer to an uncached pointer
9827 */
9828diff -urNp linux-2.6.39.1/arch/x86/include/asm/iommu.h linux-2.6.39.1/arch/x86/include/asm/iommu.h
9829--- linux-2.6.39.1/arch/x86/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
9830+++ linux-2.6.39.1/arch/x86/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
9831@@ -1,7 +1,7 @@
9832 #ifndef _ASM_X86_IOMMU_H
9833 #define _ASM_X86_IOMMU_H
9834
9835-extern struct dma_map_ops nommu_dma_ops;
9836+extern const struct dma_map_ops nommu_dma_ops;
9837 extern int force_iommu, no_iommu;
9838 extern int iommu_detected;
9839 extern int iommu_pass_through;
9840diff -urNp linux-2.6.39.1/arch/x86/include/asm/irqflags.h linux-2.6.39.1/arch/x86/include/asm/irqflags.h
9841--- linux-2.6.39.1/arch/x86/include/asm/irqflags.h 2011-05-19 00:06:34.000000000 -0400
9842+++ linux-2.6.39.1/arch/x86/include/asm/irqflags.h 2011-05-22 19:36:30.000000000 -0400
9843@@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
9844 sti; \
9845 sysexit
9846
9847+#define GET_CR0_INTO_RDI mov %cr0, %rdi
9848+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9849+#define GET_CR3_INTO_RDI mov %cr3, %rdi
9850+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9851+
9852 #else
9853 #define INTERRUPT_RETURN iret
9854 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9855diff -urNp linux-2.6.39.1/arch/x86/include/asm/kprobes.h linux-2.6.39.1/arch/x86/include/asm/kprobes.h
9856--- linux-2.6.39.1/arch/x86/include/asm/kprobes.h 2011-05-19 00:06:34.000000000 -0400
9857+++ linux-2.6.39.1/arch/x86/include/asm/kprobes.h 2011-05-22 19:36:30.000000000 -0400
9858@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
9859 #define RELATIVEJUMP_SIZE 5
9860 #define RELATIVECALL_OPCODE 0xe8
9861 #define RELATIVE_ADDR_SIZE 4
9862-#define MAX_STACK_SIZE 64
9863-#define MIN_STACK_SIZE(ADDR) \
9864- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9865- THREAD_SIZE - (unsigned long)(ADDR))) \
9866- ? (MAX_STACK_SIZE) \
9867- : (((unsigned long)current_thread_info()) + \
9868- THREAD_SIZE - (unsigned long)(ADDR)))
9869+#define MAX_STACK_SIZE 64UL
9870+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9871
9872 #define flush_insn_slot(p) do { } while (0)
9873
9874diff -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
9875--- linux-2.6.39.1/arch/x86/include/asm/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
9876+++ linux-2.6.39.1/arch/x86/include/asm/kvm_host.h 2011-05-22 19:36:30.000000000 -0400
9877@@ -419,7 +419,7 @@ struct kvm_arch {
9878 unsigned int n_used_mmu_pages;
9879 unsigned int n_requested_mmu_pages;
9880 unsigned int n_max_mmu_pages;
9881- atomic_t invlpg_counter;
9882+ atomic_unchecked_t invlpg_counter;
9883 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
9884 /*
9885 * Hash table of struct kvm_mmu_page.
9886@@ -599,7 +599,7 @@ struct kvm_arch_async_pf {
9887 bool direct_map;
9888 };
9889
9890-extern struct kvm_x86_ops *kvm_x86_ops;
9891+extern const struct kvm_x86_ops *kvm_x86_ops;
9892
9893 int kvm_mmu_module_init(void);
9894 void kvm_mmu_module_exit(void);
9895diff -urNp linux-2.6.39.1/arch/x86/include/asm/local.h linux-2.6.39.1/arch/x86/include/asm/local.h
9896--- linux-2.6.39.1/arch/x86/include/asm/local.h 2011-05-19 00:06:34.000000000 -0400
9897+++ linux-2.6.39.1/arch/x86/include/asm/local.h 2011-05-22 19:36:30.000000000 -0400
9898@@ -18,26 +18,58 @@ typedef struct {
9899
9900 static inline void local_inc(local_t *l)
9901 {
9902- asm volatile(_ASM_INC "%0"
9903+ asm volatile(_ASM_INC "%0\n"
9904+
9905+#ifdef CONFIG_PAX_REFCOUNT
9906+ "jno 0f\n"
9907+ _ASM_DEC "%0\n"
9908+ "int $4\n0:\n"
9909+ _ASM_EXTABLE(0b, 0b)
9910+#endif
9911+
9912 : "+m" (l->a.counter));
9913 }
9914
9915 static inline void local_dec(local_t *l)
9916 {
9917- asm volatile(_ASM_DEC "%0"
9918+ asm volatile(_ASM_DEC "%0\n"
9919+
9920+#ifdef CONFIG_PAX_REFCOUNT
9921+ "jno 0f\n"
9922+ _ASM_INC "%0\n"
9923+ "int $4\n0:\n"
9924+ _ASM_EXTABLE(0b, 0b)
9925+#endif
9926+
9927 : "+m" (l->a.counter));
9928 }
9929
9930 static inline void local_add(long i, local_t *l)
9931 {
9932- asm volatile(_ASM_ADD "%1,%0"
9933+ asm volatile(_ASM_ADD "%1,%0\n"
9934+
9935+#ifdef CONFIG_PAX_REFCOUNT
9936+ "jno 0f\n"
9937+ _ASM_SUB "%1,%0\n"
9938+ "int $4\n0:\n"
9939+ _ASM_EXTABLE(0b, 0b)
9940+#endif
9941+
9942 : "+m" (l->a.counter)
9943 : "ir" (i));
9944 }
9945
9946 static inline void local_sub(long i, local_t *l)
9947 {
9948- asm volatile(_ASM_SUB "%1,%0"
9949+ asm volatile(_ASM_SUB "%1,%0\n"
9950+
9951+#ifdef CONFIG_PAX_REFCOUNT
9952+ "jno 0f\n"
9953+ _ASM_ADD "%1,%0\n"
9954+ "int $4\n0:\n"
9955+ _ASM_EXTABLE(0b, 0b)
9956+#endif
9957+
9958 : "+m" (l->a.counter)
9959 : "ir" (i));
9960 }
9961@@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
9962 {
9963 unsigned char c;
9964
9965- asm volatile(_ASM_SUB "%2,%0; sete %1"
9966+ asm volatile(_ASM_SUB "%2,%0\n"
9967+
9968+#ifdef CONFIG_PAX_REFCOUNT
9969+ "jno 0f\n"
9970+ _ASM_ADD "%2,%0\n"
9971+ "int $4\n0:\n"
9972+ _ASM_EXTABLE(0b, 0b)
9973+#endif
9974+
9975+ "sete %1\n"
9976 : "+m" (l->a.counter), "=qm" (c)
9977 : "ir" (i) : "memory");
9978 return c;
9979@@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
9980 {
9981 unsigned char c;
9982
9983- asm volatile(_ASM_DEC "%0; sete %1"
9984+ asm volatile(_ASM_DEC "%0\n"
9985+
9986+#ifdef CONFIG_PAX_REFCOUNT
9987+ "jno 0f\n"
9988+ _ASM_INC "%0\n"
9989+ "int $4\n0:\n"
9990+ _ASM_EXTABLE(0b, 0b)
9991+#endif
9992+
9993+ "sete %1\n"
9994 : "+m" (l->a.counter), "=qm" (c)
9995 : : "memory");
9996 return c != 0;
9997@@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
9998 {
9999 unsigned char c;
10000
10001- asm volatile(_ASM_INC "%0; sete %1"
10002+ asm volatile(_ASM_INC "%0\n"
10003+
10004+#ifdef CONFIG_PAX_REFCOUNT
10005+ "jno 0f\n"
10006+ _ASM_DEC "%0\n"
10007+ "int $4\n0:\n"
10008+ _ASM_EXTABLE(0b, 0b)
10009+#endif
10010+
10011+ "sete %1\n"
10012 : "+m" (l->a.counter), "=qm" (c)
10013 : : "memory");
10014 return c != 0;
10015@@ -110,7 +169,16 @@ static inline int local_add_negative(lon
10016 {
10017 unsigned char c;
10018
10019- asm volatile(_ASM_ADD "%2,%0; sets %1"
10020+ asm volatile(_ASM_ADD "%2,%0\n"
10021+
10022+#ifdef CONFIG_PAX_REFCOUNT
10023+ "jno 0f\n"
10024+ _ASM_SUB "%2,%0\n"
10025+ "int $4\n0:\n"
10026+ _ASM_EXTABLE(0b, 0b)
10027+#endif
10028+
10029+ "sets %1\n"
10030 : "+m" (l->a.counter), "=qm" (c)
10031 : "ir" (i) : "memory");
10032 return c;
10033@@ -133,7 +201,15 @@ static inline long local_add_return(long
10034 #endif
10035 /* Modern 486+ processor */
10036 __i = i;
10037- asm volatile(_ASM_XADD "%0, %1;"
10038+ asm volatile(_ASM_XADD "%0, %1\n"
10039+
10040+#ifdef CONFIG_PAX_REFCOUNT
10041+ "jno 0f\n"
10042+ _ASM_MOV "%0,%1\n"
10043+ "int $4\n0:\n"
10044+ _ASM_EXTABLE(0b, 0b)
10045+#endif
10046+
10047 : "+r" (i), "+m" (l->a.counter)
10048 : : "memory");
10049 return i + __i;
10050diff -urNp linux-2.6.39.1/arch/x86/include/asm/mce.h linux-2.6.39.1/arch/x86/include/asm/mce.h
10051--- linux-2.6.39.1/arch/x86/include/asm/mce.h 2011-05-19 00:06:34.000000000 -0400
10052+++ linux-2.6.39.1/arch/x86/include/asm/mce.h 2011-05-22 19:36:30.000000000 -0400
10053@@ -198,7 +198,7 @@ int mce_notify_irq(void);
10054 void mce_notify_process(void);
10055
10056 DECLARE_PER_CPU(struct mce, injectm);
10057-extern struct file_operations mce_chrdev_ops;
10058+extern struct file_operations mce_chrdev_ops; /* cannot be const, see arch/x86/kernel/cpu/mcheck/mce. */
10059
10060 /*
10061 * Exception handler
10062diff -urNp linux-2.6.39.1/arch/x86/include/asm/microcode.h linux-2.6.39.1/arch/x86/include/asm/microcode.h
10063--- linux-2.6.39.1/arch/x86/include/asm/microcode.h 2011-05-19 00:06:34.000000000 -0400
10064+++ linux-2.6.39.1/arch/x86/include/asm/microcode.h 2011-05-22 19:36:30.000000000 -0400
10065@@ -12,13 +12,13 @@ struct device;
10066 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
10067
10068 struct microcode_ops {
10069- enum ucode_state (*request_microcode_user) (int cpu,
10070+ enum ucode_state (* const request_microcode_user) (int cpu,
10071 const void __user *buf, size_t size);
10072
10073- enum ucode_state (*request_microcode_fw) (int cpu,
10074+ enum ucode_state (* const request_microcode_fw) (int cpu,
10075 struct device *device);
10076
10077- void (*microcode_fini_cpu) (int cpu);
10078+ void (* const microcode_fini_cpu) (int cpu);
10079
10080 /*
10081 * The generic 'microcode_core' part guarantees that
10082@@ -38,16 +38,16 @@ struct ucode_cpu_info {
10083 extern struct ucode_cpu_info ucode_cpu_info[];
10084
10085 #ifdef CONFIG_MICROCODE_INTEL
10086-extern struct microcode_ops * __init init_intel_microcode(void);
10087+extern const struct microcode_ops * __init init_intel_microcode(void);
10088 #else
10089-static inline struct microcode_ops * __init init_intel_microcode(void)
10090+static inline const struct microcode_ops * __init init_intel_microcode(void)
10091 {
10092 return NULL;
10093 }
10094 #endif /* CONFIG_MICROCODE_INTEL */
10095
10096 #ifdef CONFIG_MICROCODE_AMD
10097-extern struct microcode_ops * __init init_amd_microcode(void);
10098+extern const struct microcode_ops * __init init_amd_microcode(void);
10099
10100 static inline void get_ucode_data(void *to, const u8 *from, size_t n)
10101 {
10102@@ -55,7 +55,7 @@ static inline void get_ucode_data(void *
10103 }
10104
10105 #else
10106-static inline struct microcode_ops * __init init_amd_microcode(void)
10107+static inline const struct microcode_ops * __init init_amd_microcode(void)
10108 {
10109 return NULL;
10110 }
10111diff -urNp linux-2.6.39.1/arch/x86/include/asm/mman.h linux-2.6.39.1/arch/x86/include/asm/mman.h
10112--- linux-2.6.39.1/arch/x86/include/asm/mman.h 2011-05-19 00:06:34.000000000 -0400
10113+++ linux-2.6.39.1/arch/x86/include/asm/mman.h 2011-05-22 19:36:30.000000000 -0400
10114@@ -5,4 +5,14 @@
10115
10116 #include <asm-generic/mman.h>
10117
10118+#ifdef __KERNEL__
10119+#ifndef __ASSEMBLY__
10120+#ifdef CONFIG_X86_32
10121+#define arch_mmap_check i386_mmap_check
10122+int i386_mmap_check(unsigned long addr, unsigned long len,
10123+ unsigned long flags);
10124+#endif
10125+#endif
10126+#endif
10127+
10128 #endif /* _ASM_X86_MMAN_H */
10129diff -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
10130--- linux-2.6.39.1/arch/x86/include/asm/mmu_context.h 2011-05-19 00:06:34.000000000 -0400
10131+++ linux-2.6.39.1/arch/x86/include/asm/mmu_context.h 2011-05-22 19:36:30.000000000 -0400
10132@@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
10133
10134 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10135 {
10136+
10137+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10138+ unsigned int i;
10139+ pgd_t *pgd;
10140+
10141+ pax_open_kernel();
10142+ pgd = get_cpu_pgd(smp_processor_id());
10143+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10144+ if (paravirt_enabled())
10145+ set_pgd(pgd+i, native_make_pgd(0));
10146+ else
10147+ pgd[i] = native_make_pgd(0);
10148+ pax_close_kernel();
10149+#endif
10150+
10151 #ifdef CONFIG_SMP
10152 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10153 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10154@@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
10155 struct task_struct *tsk)
10156 {
10157 unsigned cpu = smp_processor_id();
10158+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
10159+ int tlbstate = TLBSTATE_OK;
10160+#endif
10161
10162 if (likely(prev != next)) {
10163 #ifdef CONFIG_SMP
10164+#ifdef CONFIG_X86_32
10165+ tlbstate = percpu_read(cpu_tlbstate.state);
10166+#endif
10167 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10168 percpu_write(cpu_tlbstate.active_mm, next);
10169 #endif
10170 cpumask_set_cpu(cpu, mm_cpumask(next));
10171
10172 /* Re-load page tables */
10173+#ifdef CONFIG_PAX_PER_CPU_PGD
10174+ pax_open_kernel();
10175+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10176+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10177+ pax_close_kernel();
10178+ load_cr3(get_cpu_pgd(cpu));
10179+#else
10180 load_cr3(next->pgd);
10181+#endif
10182
10183 /* stop flush ipis for the previous mm */
10184 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10185@@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
10186 */
10187 if (unlikely(prev->context.ldt != next->context.ldt))
10188 load_LDT_nolock(&next->context);
10189- }
10190+
10191+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10192+ if (!(__supported_pte_mask & _PAGE_NX)) {
10193+ smp_mb__before_clear_bit();
10194+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10195+ smp_mb__after_clear_bit();
10196+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10197+ }
10198+#endif
10199+
10200+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10201+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10202+ prev->context.user_cs_limit != next->context.user_cs_limit))
10203+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10204 #ifdef CONFIG_SMP
10205+ else if (unlikely(tlbstate != TLBSTATE_OK))
10206+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10207+#endif
10208+#endif
10209+
10210+ }
10211 else {
10212+
10213+#ifdef CONFIG_PAX_PER_CPU_PGD
10214+ pax_open_kernel();
10215+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10216+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10217+ pax_close_kernel();
10218+ load_cr3(get_cpu_pgd(cpu));
10219+#endif
10220+
10221+#ifdef CONFIG_SMP
10222 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10223 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10224
10225@@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
10226 * tlb flush IPI delivery. We must reload CR3
10227 * to make sure to use no freed page tables.
10228 */
10229+
10230+#ifndef CONFIG_PAX_PER_CPU_PGD
10231 load_cr3(next->pgd);
10232+#endif
10233+
10234 load_LDT_nolock(&next->context);
10235+
10236+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10237+ if (!(__supported_pte_mask & _PAGE_NX))
10238+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10239+#endif
10240+
10241+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10242+#ifdef CONFIG_PAX_PAGEEXEC
10243+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10244+#endif
10245+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10246+#endif
10247+
10248 }
10249- }
10250 #endif
10251+ }
10252 }
10253
10254 #define activate_mm(prev, next) \
10255diff -urNp linux-2.6.39.1/arch/x86/include/asm/mmu.h linux-2.6.39.1/arch/x86/include/asm/mmu.h
10256--- linux-2.6.39.1/arch/x86/include/asm/mmu.h 2011-05-19 00:06:34.000000000 -0400
10257+++ linux-2.6.39.1/arch/x86/include/asm/mmu.h 2011-05-22 19:36:30.000000000 -0400
10258@@ -9,10 +9,22 @@
10259 * we put the segment information here.
10260 */
10261 typedef struct {
10262- void *ldt;
10263+ struct desc_struct *ldt;
10264 int size;
10265 struct mutex lock;
10266- void *vdso;
10267+ unsigned long vdso;
10268+
10269+#ifdef CONFIG_X86_32
10270+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10271+ unsigned long user_cs_base;
10272+ unsigned long user_cs_limit;
10273+
10274+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10275+ cpumask_t cpu_user_cs_mask;
10276+#endif
10277+
10278+#endif
10279+#endif
10280
10281 #ifdef CONFIG_X86_64
10282 /* True if mm supports a task running in 32 bit compatibility mode. */
10283diff -urNp linux-2.6.39.1/arch/x86/include/asm/module.h linux-2.6.39.1/arch/x86/include/asm/module.h
10284--- linux-2.6.39.1/arch/x86/include/asm/module.h 2011-05-19 00:06:34.000000000 -0400
10285+++ linux-2.6.39.1/arch/x86/include/asm/module.h 2011-05-22 19:41:32.000000000 -0400
10286@@ -5,6 +5,7 @@
10287
10288 #ifdef CONFIG_X86_64
10289 /* X86_64 does not define MODULE_PROC_FAMILY */
10290+#define MODULE_PROC_FAMILY ""
10291 #elif defined CONFIG_M386
10292 #define MODULE_PROC_FAMILY "386 "
10293 #elif defined CONFIG_M486
10294@@ -59,8 +60,30 @@
10295 #error unknown processor family
10296 #endif
10297
10298-#ifdef CONFIG_X86_32
10299-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10300+#ifdef CONFIG_PAX_MEMORY_UDEREF
10301+#define MODULE_PAX_UDEREF "UDEREF "
10302+#else
10303+#define MODULE_PAX_UDEREF ""
10304+#endif
10305+
10306+#ifdef CONFIG_PAX_KERNEXEC
10307+#define MODULE_PAX_KERNEXEC "KERNEXEC "
10308+#else
10309+#define MODULE_PAX_KERNEXEC ""
10310 #endif
10311
10312+#ifdef CONFIG_PAX_REFCOUNT
10313+#define MODULE_PAX_REFCOUNT "REFCOUNT "
10314+#else
10315+#define MODULE_PAX_REFCOUNT ""
10316+#endif
10317+
10318+#ifdef CONFIG_GRKERNSEC
10319+#define MODULE_GRSEC "GRSECURITY "
10320+#else
10321+#define MODULE_GRSEC ""
10322+#endif
10323+
10324+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
10325+
10326 #endif /* _ASM_X86_MODULE_H */
10327diff -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
10328--- linux-2.6.39.1/arch/x86/include/asm/page_64_types.h 2011-05-19 00:06:34.000000000 -0400
10329+++ linux-2.6.39.1/arch/x86/include/asm/page_64_types.h 2011-05-22 19:36:30.000000000 -0400
10330@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10331
10332 /* duplicated to the one in bootmem.h */
10333 extern unsigned long max_pfn;
10334-extern unsigned long phys_base;
10335+extern const unsigned long phys_base;
10336
10337 extern unsigned long __phys_addr(unsigned long);
10338 #define __phys_reloc_hide(x) (x)
10339diff -urNp linux-2.6.39.1/arch/x86/include/asm/paravirt.h linux-2.6.39.1/arch/x86/include/asm/paravirt.h
10340--- linux-2.6.39.1/arch/x86/include/asm/paravirt.h 2011-05-19 00:06:34.000000000 -0400
10341+++ linux-2.6.39.1/arch/x86/include/asm/paravirt.h 2011-05-22 19:36:30.000000000 -0400
10342@@ -739,6 +739,21 @@ static inline void __set_fixmap(unsigned
10343 pv_mmu_ops.set_fixmap(idx, phys, flags);
10344 }
10345
10346+#ifdef CONFIG_PAX_KERNEXEC
10347+static inline unsigned long pax_open_kernel(void)
10348+{
10349+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10350+}
10351+
10352+static inline unsigned long pax_close_kernel(void)
10353+{
10354+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10355+}
10356+#else
10357+static inline unsigned long pax_open_kernel(void) { return 0; }
10358+static inline unsigned long pax_close_kernel(void) { return 0; }
10359+#endif
10360+
10361 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10362
10363 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10364@@ -955,7 +970,7 @@ extern void default_banner(void);
10365
10366 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10367 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10368-#define PARA_INDIRECT(addr) *%cs:addr
10369+#define PARA_INDIRECT(addr) *%ss:addr
10370 #endif
10371
10372 #define INTERRUPT_RETURN \
10373@@ -1032,6 +1047,21 @@ extern void default_banner(void);
10374 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10375 CLBR_NONE, \
10376 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10377+
10378+#define GET_CR0_INTO_RDI \
10379+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10380+ mov %rax,%rdi
10381+
10382+#define SET_RDI_INTO_CR0 \
10383+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10384+
10385+#define GET_CR3_INTO_RDI \
10386+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10387+ mov %rax,%rdi
10388+
10389+#define SET_RDI_INTO_CR3 \
10390+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10391+
10392 #endif /* CONFIG_X86_32 */
10393
10394 #endif /* __ASSEMBLY__ */
10395diff -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
10396--- linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h 2011-05-19 00:06:34.000000000 -0400
10397+++ linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h 2011-05-22 19:36:30.000000000 -0400
10398@@ -317,6 +317,12 @@ struct pv_mmu_ops {
10399 an mfn. We can tell which is which from the index. */
10400 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10401 phys_addr_t phys, pgprot_t flags);
10402+
10403+#ifdef CONFIG_PAX_KERNEXEC
10404+ unsigned long (*pax_open_kernel)(void);
10405+ unsigned long (*pax_close_kernel)(void);
10406+#endif
10407+
10408 };
10409
10410 struct arch_spinlock;
10411diff -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
10412--- linux-2.6.39.1/arch/x86/include/asm/pci_x86.h 2011-05-19 00:06:34.000000000 -0400
10413+++ linux-2.6.39.1/arch/x86/include/asm/pci_x86.h 2011-05-22 19:36:30.000000000 -0400
10414@@ -93,16 +93,16 @@ extern int (*pcibios_enable_irq)(struct
10415 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10416
10417 struct pci_raw_ops {
10418- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10419+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10420 int reg, int len, u32 *val);
10421- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10422+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10423 int reg, int len, u32 val);
10424 };
10425
10426-extern struct pci_raw_ops *raw_pci_ops;
10427-extern struct pci_raw_ops *raw_pci_ext_ops;
10428+extern const struct pci_raw_ops *raw_pci_ops;
10429+extern const struct pci_raw_ops *raw_pci_ext_ops;
10430
10431-extern struct pci_raw_ops pci_direct_conf1;
10432+extern const struct pci_raw_ops pci_direct_conf1;
10433 extern bool port_cf9_safe;
10434
10435 /* arch_initcall level */
10436diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgalloc.h linux-2.6.39.1/arch/x86/include/asm/pgalloc.h
10437--- linux-2.6.39.1/arch/x86/include/asm/pgalloc.h 2011-05-19 00:06:34.000000000 -0400
10438+++ linux-2.6.39.1/arch/x86/include/asm/pgalloc.h 2011-05-22 19:36:30.000000000 -0400
10439@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
10440 pmd_t *pmd, pte_t *pte)
10441 {
10442 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10443+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10444+}
10445+
10446+static inline void pmd_populate_user(struct mm_struct *mm,
10447+ pmd_t *pmd, pte_t *pte)
10448+{
10449+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10450 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10451 }
10452
10453diff -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
10454--- linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h 2011-05-19 00:06:34.000000000 -0400
10455+++ linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h 2011-05-22 19:36:30.000000000 -0400
10456@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
10457
10458 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10459 {
10460+ pax_open_kernel();
10461 *pmdp = pmd;
10462+ pax_close_kernel();
10463 }
10464
10465 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10466diff -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
10467--- linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
10468+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
10469@@ -25,9 +25,6 @@
10470 struct mm_struct;
10471 struct vm_area_struct;
10472
10473-extern pgd_t swapper_pg_dir[1024];
10474-extern pgd_t initial_page_table[1024];
10475-
10476 static inline void pgtable_cache_init(void) { }
10477 static inline void check_pgt_cache(void) { }
10478 void paging_init(void);
10479@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
10480 # include <asm/pgtable-2level.h>
10481 #endif
10482
10483+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10484+extern pgd_t initial_page_table[PTRS_PER_PGD];
10485+#ifdef CONFIG_X86_PAE
10486+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10487+#endif
10488+
10489 #if defined(CONFIG_HIGHPTE)
10490 #define pte_offset_map(dir, address) \
10491 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10492@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
10493 /* Clear a kernel PTE and flush it from the TLB */
10494 #define kpte_clear_flush(ptep, vaddr) \
10495 do { \
10496+ pax_open_kernel(); \
10497 pte_clear(&init_mm, (vaddr), (ptep)); \
10498+ pax_close_kernel(); \
10499 __flush_tlb_one((vaddr)); \
10500 } while (0)
10501
10502@@ -74,6 +79,9 @@ do { \
10503
10504 #endif /* !__ASSEMBLY__ */
10505
10506+#define HAVE_ARCH_UNMAPPED_AREA
10507+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10508+
10509 /*
10510 * kern_addr_valid() is (1) for FLATMEM and (0) for
10511 * SPARSEMEM and DISCONTIGMEM
10512diff -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
10513--- linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h 2011-05-19 00:06:34.000000000 -0400
10514+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h 2011-05-22 19:36:30.000000000 -0400
10515@@ -8,7 +8,7 @@
10516 */
10517 #ifdef CONFIG_X86_PAE
10518 # include <asm/pgtable-3level_types.h>
10519-# define PMD_SIZE (1UL << PMD_SHIFT)
10520+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10521 # define PMD_MASK (~(PMD_SIZE - 1))
10522 #else
10523 # include <asm/pgtable-2level_types.h>
10524@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
10525 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10526 #endif
10527
10528+#ifdef CONFIG_PAX_KERNEXEC
10529+#ifndef __ASSEMBLY__
10530+extern unsigned char MODULES_EXEC_VADDR[];
10531+extern unsigned char MODULES_EXEC_END[];
10532+#endif
10533+#include <asm/boot.h>
10534+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10535+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10536+#else
10537+#define ktla_ktva(addr) (addr)
10538+#define ktva_ktla(addr) (addr)
10539+#endif
10540+
10541 #define MODULES_VADDR VMALLOC_START
10542 #define MODULES_END VMALLOC_END
10543 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10544diff -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
10545--- linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h 2011-05-19 00:06:34.000000000 -0400
10546+++ linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h 2011-05-22 19:36:30.000000000 -0400
10547@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
10548
10549 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10550 {
10551+ pax_open_kernel();
10552 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10553+ pax_close_kernel();
10554 }
10555
10556 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10557 {
10558+ pax_open_kernel();
10559 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10560+ pax_close_kernel();
10561 }
10562
10563 /*
10564diff -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
10565--- linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h 2011-05-19 00:06:34.000000000 -0400
10566+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h 2011-05-22 19:36:30.000000000 -0400
10567@@ -16,10 +16,13 @@
10568
10569 extern pud_t level3_kernel_pgt[512];
10570 extern pud_t level3_ident_pgt[512];
10571+extern pud_t level3_vmalloc_pgt[512];
10572+extern pud_t level3_vmemmap_pgt[512];
10573+extern pud_t level2_vmemmap_pgt[512];
10574 extern pmd_t level2_kernel_pgt[512];
10575 extern pmd_t level2_fixmap_pgt[512];
10576-extern pmd_t level2_ident_pgt[512];
10577-extern pgd_t init_level4_pgt[];
10578+extern pmd_t level2_ident_pgt[512*2];
10579+extern pgd_t init_level4_pgt[512];
10580
10581 #define swapper_pg_dir init_level4_pgt
10582
10583@@ -61,7 +64,9 @@ static inline void native_set_pte_atomic
10584
10585 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10586 {
10587+ pax_open_kernel();
10588 *pmdp = pmd;
10589+ pax_close_kernel();
10590 }
10591
10592 static inline void native_pmd_clear(pmd_t *pmd)
10593@@ -107,7 +112,9 @@ static inline void native_pud_clear(pud_
10594
10595 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10596 {
10597+ pax_open_kernel();
10598 *pgdp = pgd;
10599+ pax_close_kernel();
10600 }
10601
10602 static inline void native_pgd_clear(pgd_t *pgd)
10603diff -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
10604--- linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h 2011-05-19 00:06:34.000000000 -0400
10605+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h 2011-05-22 19:36:30.000000000 -0400
10606@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10607 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10608 #define MODULES_END _AC(0xffffffffff000000, UL)
10609 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10610+#define MODULES_EXEC_VADDR MODULES_VADDR
10611+#define MODULES_EXEC_END MODULES_END
10612+
10613+#define ktla_ktva(addr) (addr)
10614+#define ktva_ktla(addr) (addr)
10615
10616 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10617diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable.h linux-2.6.39.1/arch/x86/include/asm/pgtable.h
10618--- linux-2.6.39.1/arch/x86/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
10619+++ linux-2.6.39.1/arch/x86/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
10620@@ -81,12 +81,51 @@ extern struct mm_struct *pgd_page_get_mm
10621
10622 #define arch_end_context_switch(prev) do {} while(0)
10623
10624+#define pax_open_kernel() native_pax_open_kernel()
10625+#define pax_close_kernel() native_pax_close_kernel()
10626 #endif /* CONFIG_PARAVIRT */
10627
10628+#define __HAVE_ARCH_PAX_OPEN_KERNEL
10629+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10630+
10631+#ifdef CONFIG_PAX_KERNEXEC
10632+static inline unsigned long native_pax_open_kernel(void)
10633+{
10634+ unsigned long cr0;
10635+
10636+ preempt_disable();
10637+ barrier();
10638+ cr0 = read_cr0() ^ X86_CR0_WP;
10639+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
10640+ write_cr0(cr0);
10641+ return cr0 ^ X86_CR0_WP;
10642+}
10643+
10644+static inline unsigned long native_pax_close_kernel(void)
10645+{
10646+ unsigned long cr0;
10647+
10648+ cr0 = read_cr0() ^ X86_CR0_WP;
10649+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10650+ write_cr0(cr0);
10651+ barrier();
10652+ preempt_enable_no_resched();
10653+ return cr0 ^ X86_CR0_WP;
10654+}
10655+#else
10656+static inline unsigned long native_pax_open_kernel(void) { return 0; }
10657+static inline unsigned long native_pax_close_kernel(void) { return 0; }
10658+#endif
10659+
10660 /*
10661 * The following only work if pte_present() is true.
10662 * Undefined behaviour if not..
10663 */
10664+static inline int pte_user(pte_t pte)
10665+{
10666+ return pte_val(pte) & _PAGE_USER;
10667+}
10668+
10669 static inline int pte_dirty(pte_t pte)
10670 {
10671 return pte_flags(pte) & _PAGE_DIRTY;
10672@@ -196,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t
10673 return pte_clear_flags(pte, _PAGE_RW);
10674 }
10675
10676+static inline pte_t pte_mkread(pte_t pte)
10677+{
10678+ return __pte(pte_val(pte) | _PAGE_USER);
10679+}
10680+
10681 static inline pte_t pte_mkexec(pte_t pte)
10682 {
10683- return pte_clear_flags(pte, _PAGE_NX);
10684+#ifdef CONFIG_X86_PAE
10685+ if (__supported_pte_mask & _PAGE_NX)
10686+ return pte_clear_flags(pte, _PAGE_NX);
10687+ else
10688+#endif
10689+ return pte_set_flags(pte, _PAGE_USER);
10690+}
10691+
10692+static inline pte_t pte_exprotect(pte_t pte)
10693+{
10694+#ifdef CONFIG_X86_PAE
10695+ if (__supported_pte_mask & _PAGE_NX)
10696+ return pte_set_flags(pte, _PAGE_NX);
10697+ else
10698+#endif
10699+ return pte_clear_flags(pte, _PAGE_USER);
10700 }
10701
10702 static inline pte_t pte_mkdirty(pte_t pte)
10703@@ -390,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long
10704 #endif
10705
10706 #ifndef __ASSEMBLY__
10707+
10708+#ifdef CONFIG_PAX_PER_CPU_PGD
10709+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10710+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10711+{
10712+ return cpu_pgd[cpu];
10713+}
10714+#endif
10715+
10716 #include <linux/mm_types.h>
10717
10718 static inline int pte_none(pte_t pte)
10719@@ -560,7 +628,7 @@ static inline pud_t *pud_offset(pgd_t *p
10720
10721 static inline int pgd_bad(pgd_t pgd)
10722 {
10723- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10724+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10725 }
10726
10727 static inline int pgd_none(pgd_t pgd)
10728@@ -583,7 +651,12 @@ static inline int pgd_none(pgd_t pgd)
10729 * pgd_offset() returns a (pgd_t *)
10730 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10731 */
10732-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10733+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10734+
10735+#ifdef CONFIG_PAX_PER_CPU_PGD
10736+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10737+#endif
10738+
10739 /*
10740 * a shortcut which implies the use of the kernel's pgd, instead
10741 * of a process's
10742@@ -594,6 +667,20 @@ static inline int pgd_none(pgd_t pgd)
10743 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10744 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10745
10746+#ifdef CONFIG_X86_32
10747+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10748+#else
10749+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10750+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10751+
10752+#ifdef CONFIG_PAX_MEMORY_UDEREF
10753+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10754+#else
10755+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10756+#endif
10757+
10758+#endif
10759+
10760 #ifndef __ASSEMBLY__
10761
10762 extern int direct_gbpages;
10763@@ -758,11 +845,23 @@ static inline void pmdp_set_wrprotect(st
10764 * dst and src can be on the same page, but the range must not overlap,
10765 * and must not cross a page boundary.
10766 */
10767-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10768+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10769 {
10770- memcpy(dst, src, count * sizeof(pgd_t));
10771+ pax_open_kernel();
10772+ while (count--)
10773+ *dst++ = *src++;
10774+ pax_close_kernel();
10775 }
10776
10777+#ifdef CONFIG_PAX_PER_CPU_PGD
10778+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10779+#endif
10780+
10781+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10782+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10783+#else
10784+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10785+#endif
10786
10787 #include <asm-generic/pgtable.h>
10788 #endif /* __ASSEMBLY__ */
10789diff -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
10790--- linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h 2011-05-19 00:06:34.000000000 -0400
10791+++ linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h 2011-05-22 19:36:30.000000000 -0400
10792@@ -16,13 +16,12 @@
10793 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10794 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10795 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10796-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10797+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10798 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10799 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10800 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10801-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10802-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10803-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
10804+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10805+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
10806 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10807
10808 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10809@@ -40,7 +39,6 @@
10810 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10811 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10812 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10813-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10814 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10815 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10816 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10817@@ -57,8 +55,10 @@
10818
10819 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10820 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10821-#else
10822+#elif defined(CONFIG_KMEMCHECK)
10823 #define _PAGE_NX (_AT(pteval_t, 0))
10824+#else
10825+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10826 #endif
10827
10828 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10829@@ -96,6 +96,9 @@
10830 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10831 _PAGE_ACCESSED)
10832
10833+#define PAGE_READONLY_NOEXEC PAGE_READONLY
10834+#define PAGE_SHARED_NOEXEC PAGE_SHARED
10835+
10836 #define __PAGE_KERNEL_EXEC \
10837 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10838 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10839@@ -106,8 +109,8 @@
10840 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10841 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10842 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10843-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10844-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
10845+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10846+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
10847 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10848 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
10849 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
10850@@ -166,8 +169,8 @@
10851 * bits are combined, this will alow user to access the high address mapped
10852 * VDSO in the presence of CONFIG_COMPAT_VDSO
10853 */
10854-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10855-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10856+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10857+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10858 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10859 #endif
10860
10861@@ -205,7 +208,17 @@ static inline pgdval_t pgd_flags(pgd_t p
10862 {
10863 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10864 }
10865+#endif
10866
10867+#if PAGETABLE_LEVELS == 3
10868+#include <asm-generic/pgtable-nopud.h>
10869+#endif
10870+
10871+#if PAGETABLE_LEVELS == 2
10872+#include <asm-generic/pgtable-nopmd.h>
10873+#endif
10874+
10875+#ifndef __ASSEMBLY__
10876 #if PAGETABLE_LEVELS > 3
10877 typedef struct { pudval_t pud; } pud_t;
10878
10879@@ -219,8 +232,6 @@ static inline pudval_t native_pud_val(pu
10880 return pud.pud;
10881 }
10882 #else
10883-#include <asm-generic/pgtable-nopud.h>
10884-
10885 static inline pudval_t native_pud_val(pud_t pud)
10886 {
10887 return native_pgd_val(pud.pgd);
10888@@ -240,8 +251,6 @@ static inline pmdval_t native_pmd_val(pm
10889 return pmd.pmd;
10890 }
10891 #else
10892-#include <asm-generic/pgtable-nopmd.h>
10893-
10894 static inline pmdval_t native_pmd_val(pmd_t pmd)
10895 {
10896 return native_pgd_val(pmd.pud.pgd);
10897@@ -281,7 +290,6 @@ typedef struct page *pgtable_t;
10898
10899 extern pteval_t __supported_pte_mask;
10900 extern void set_nx(void);
10901-extern int nx_enabled;
10902
10903 #define pgprot_writecombine pgprot_writecombine
10904 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10905diff -urNp linux-2.6.39.1/arch/x86/include/asm/processor.h linux-2.6.39.1/arch/x86/include/asm/processor.h
10906--- linux-2.6.39.1/arch/x86/include/asm/processor.h 2011-05-19 00:06:34.000000000 -0400
10907+++ linux-2.6.39.1/arch/x86/include/asm/processor.h 2011-05-22 19:36:30.000000000 -0400
10908@@ -266,7 +266,7 @@ struct tss_struct {
10909
10910 } ____cacheline_aligned;
10911
10912-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10913+extern struct tss_struct init_tss[NR_CPUS];
10914
10915 /*
10916 * Save the original ist values for checking stack pointers during debugging
10917@@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(co
10918 */
10919 #define TASK_SIZE PAGE_OFFSET
10920 #define TASK_SIZE_MAX TASK_SIZE
10921+
10922+#ifdef CONFIG_PAX_SEGMEXEC
10923+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10924+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10925+#else
10926 #define STACK_TOP TASK_SIZE
10927-#define STACK_TOP_MAX STACK_TOP
10928+#endif
10929+
10930+#define STACK_TOP_MAX TASK_SIZE
10931
10932 #define INIT_THREAD { \
10933- .sp0 = sizeof(init_stack) + (long)&init_stack, \
10934+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10935 .vm86_info = NULL, \
10936 .sysenter_cs = __KERNEL_CS, \
10937 .io_bitmap_ptr = NULL, \
10938@@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(co
10939 */
10940 #define INIT_TSS { \
10941 .x86_tss = { \
10942- .sp0 = sizeof(init_stack) + (long)&init_stack, \
10943+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10944 .ss0 = __KERNEL_DS, \
10945 .ss1 = __KERNEL_CS, \
10946 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10947@@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(co
10948 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10949
10950 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10951-#define KSTK_TOP(info) \
10952-({ \
10953- unsigned long *__ptr = (unsigned long *)(info); \
10954- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10955-})
10956+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10957
10958 /*
10959 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10960@@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(str
10961 #define task_pt_regs(task) \
10962 ({ \
10963 struct pt_regs *__regs__; \
10964- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10965+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10966 __regs__ - 1; \
10967 })
10968
10969@@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(str
10970 /*
10971 * User space process size. 47bits minus one guard page.
10972 */
10973-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10974+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10975
10976 /* This decides where the kernel will search for a free chunk of vm
10977 * space during mmap's.
10978 */
10979 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10980- 0xc0000000 : 0xFFFFe000)
10981+ 0xc0000000 : 0xFFFFf000)
10982
10983 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10984 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10985@@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(str
10986 #define STACK_TOP_MAX TASK_SIZE_MAX
10987
10988 #define INIT_THREAD { \
10989- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10990+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10991 }
10992
10993 #define INIT_TSS { \
10994- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10995+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10996 }
10997
10998 /*
10999@@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs
11000 */
11001 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11002
11003+#ifdef CONFIG_PAX_SEGMEXEC
11004+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11005+#endif
11006+
11007 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11008
11009 /* Get/set a process' ability to use the timestamp counter instruction */
11010diff -urNp linux-2.6.39.1/arch/x86/include/asm/ptrace.h linux-2.6.39.1/arch/x86/include/asm/ptrace.h
11011--- linux-2.6.39.1/arch/x86/include/asm/ptrace.h 2011-05-19 00:06:34.000000000 -0400
11012+++ linux-2.6.39.1/arch/x86/include/asm/ptrace.h 2011-05-22 19:36:30.000000000 -0400
11013@@ -152,28 +152,29 @@ static inline unsigned long regs_return_
11014 }
11015
11016 /*
11017- * user_mode_vm(regs) determines whether a register set came from user mode.
11018+ * user_mode(regs) determines whether a register set came from user mode.
11019 * This is true if V8086 mode was enabled OR if the register set was from
11020 * protected mode with RPL-3 CS value. This tricky test checks that with
11021 * one comparison. Many places in the kernel can bypass this full check
11022- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11023+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11024+ * be used.
11025 */
11026-static inline int user_mode(struct pt_regs *regs)
11027+static inline int user_mode_novm(struct pt_regs *regs)
11028 {
11029 #ifdef CONFIG_X86_32
11030 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11031 #else
11032- return !!(regs->cs & 3);
11033+ return !!(regs->cs & SEGMENT_RPL_MASK);
11034 #endif
11035 }
11036
11037-static inline int user_mode_vm(struct pt_regs *regs)
11038+static inline int user_mode(struct pt_regs *regs)
11039 {
11040 #ifdef CONFIG_X86_32
11041 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11042 USER_RPL;
11043 #else
11044- return user_mode(regs);
11045+ return user_mode_novm(regs);
11046 #endif
11047 }
11048
11049diff -urNp linux-2.6.39.1/arch/x86/include/asm/reboot.h linux-2.6.39.1/arch/x86/include/asm/reboot.h
11050--- linux-2.6.39.1/arch/x86/include/asm/reboot.h 2011-05-19 00:06:34.000000000 -0400
11051+++ linux-2.6.39.1/arch/x86/include/asm/reboot.h 2011-05-22 19:36:30.000000000 -0400
11052@@ -6,19 +6,19 @@
11053 struct pt_regs;
11054
11055 struct machine_ops {
11056- void (*restart)(char *cmd);
11057- void (*halt)(void);
11058- void (*power_off)(void);
11059+ void (* __noreturn restart)(char *cmd);
11060+ void (* __noreturn halt)(void);
11061+ void (* __noreturn power_off)(void);
11062 void (*shutdown)(void);
11063 void (*crash_shutdown)(struct pt_regs *);
11064- void (*emergency_restart)(void);
11065+ void (* __noreturn emergency_restart)(void);
11066 };
11067
11068 extern struct machine_ops machine_ops;
11069
11070 void native_machine_crash_shutdown(struct pt_regs *regs);
11071 void native_machine_shutdown(void);
11072-void machine_real_restart(unsigned int type);
11073+void machine_real_restart(unsigned int type) __noreturn;
11074 /* These must match dispatch_table in reboot_32.S */
11075 #define MRR_BIOS 0
11076 #define MRR_APM 1
11077diff -urNp linux-2.6.39.1/arch/x86/include/asm/rwsem.h linux-2.6.39.1/arch/x86/include/asm/rwsem.h
11078--- linux-2.6.39.1/arch/x86/include/asm/rwsem.h 2011-05-19 00:06:34.000000000 -0400
11079+++ linux-2.6.39.1/arch/x86/include/asm/rwsem.h 2011-05-22 19:36:30.000000000 -0400
11080@@ -64,6 +64,14 @@ static inline void __down_read(struct rw
11081 {
11082 asm volatile("# beginning down_read\n\t"
11083 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11084+
11085+#ifdef CONFIG_PAX_REFCOUNT
11086+ "jno 0f\n"
11087+ LOCK_PREFIX _ASM_DEC "(%1)\n"
11088+ "int $4\n0:\n"
11089+ _ASM_EXTABLE(0b, 0b)
11090+#endif
11091+
11092 /* adds 0x00000001 */
11093 " jns 1f\n"
11094 " call call_rwsem_down_read_failed\n"
11095@@ -85,6 +93,14 @@ static inline int __down_read_trylock(st
11096 "1:\n\t"
11097 " mov %1,%2\n\t"
11098 " add %3,%2\n\t"
11099+
11100+#ifdef CONFIG_PAX_REFCOUNT
11101+ "jno 0f\n"
11102+ "sub %3,%2\n"
11103+ "int $4\n0:\n"
11104+ _ASM_EXTABLE(0b, 0b)
11105+#endif
11106+
11107 " jle 2f\n\t"
11108 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11109 " jnz 1b\n\t"
11110@@ -104,6 +120,14 @@ static inline void __down_write_nested(s
11111 long tmp;
11112 asm volatile("# beginning down_write\n\t"
11113 LOCK_PREFIX " xadd %1,(%2)\n\t"
11114+
11115+#ifdef CONFIG_PAX_REFCOUNT
11116+ "jno 0f\n"
11117+ "mov %1,(%2)\n"
11118+ "int $4\n0:\n"
11119+ _ASM_EXTABLE(0b, 0b)
11120+#endif
11121+
11122 /* adds 0xffff0001, returns the old value */
11123 " test %1,%1\n\t"
11124 /* was the count 0 before? */
11125@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_s
11126 long tmp;
11127 asm volatile("# beginning __up_read\n\t"
11128 LOCK_PREFIX " xadd %1,(%2)\n\t"
11129+
11130+#ifdef CONFIG_PAX_REFCOUNT
11131+ "jno 0f\n"
11132+ "mov %1,(%2)\n"
11133+ "int $4\n0:\n"
11134+ _ASM_EXTABLE(0b, 0b)
11135+#endif
11136+
11137 /* subtracts 1, returns the old value */
11138 " jns 1f\n\t"
11139 " call call_rwsem_wake\n" /* expects old value in %edx */
11140@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_
11141 long tmp;
11142 asm volatile("# beginning __up_write\n\t"
11143 LOCK_PREFIX " xadd %1,(%2)\n\t"
11144+
11145+#ifdef CONFIG_PAX_REFCOUNT
11146+ "jno 0f\n"
11147+ "mov %1,(%2)\n"
11148+ "int $4\n0:\n"
11149+ _ASM_EXTABLE(0b, 0b)
11150+#endif
11151+
11152 /* subtracts 0xffff0001, returns the old value */
11153 " jns 1f\n\t"
11154 " call call_rwsem_wake\n" /* expects old value in %edx */
11155@@ -176,6 +216,14 @@ static inline void __downgrade_write(str
11156 {
11157 asm volatile("# beginning __downgrade_write\n\t"
11158 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11159+
11160+#ifdef CONFIG_PAX_REFCOUNT
11161+ "jno 0f\n"
11162+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11163+ "int $4\n0:\n"
11164+ _ASM_EXTABLE(0b, 0b)
11165+#endif
11166+
11167 /*
11168 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11169 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11170@@ -194,7 +242,15 @@ static inline void __downgrade_write(str
11171 */
11172 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11173 {
11174- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11175+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11176+
11177+#ifdef CONFIG_PAX_REFCOUNT
11178+ "jno 0f\n"
11179+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
11180+ "int $4\n0:\n"
11181+ _ASM_EXTABLE(0b, 0b)
11182+#endif
11183+
11184 : "+m" (sem->count)
11185 : "er" (delta));
11186 }
11187@@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(l
11188 {
11189 long tmp = delta;
11190
11191- asm volatile(LOCK_PREFIX "xadd %0,%1"
11192+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11193+
11194+#ifdef CONFIG_PAX_REFCOUNT
11195+ "jno 0f\n"
11196+ "mov %0,%1\n"
11197+ "int $4\n0:\n"
11198+ _ASM_EXTABLE(0b, 0b)
11199+#endif
11200+
11201 : "+r" (tmp), "+m" (sem->count)
11202 : : "memory");
11203
11204diff -urNp linux-2.6.39.1/arch/x86/include/asm/segment.h linux-2.6.39.1/arch/x86/include/asm/segment.h
11205--- linux-2.6.39.1/arch/x86/include/asm/segment.h 2011-05-19 00:06:34.000000000 -0400
11206+++ linux-2.6.39.1/arch/x86/include/asm/segment.h 2011-05-22 19:36:30.000000000 -0400
11207@@ -64,8 +64,8 @@
11208 * 26 - ESPFIX small SS
11209 * 27 - per-cpu [ offset to per-cpu data area ]
11210 * 28 - stack_canary-20 [ for stack protector ]
11211- * 29 - unused
11212- * 30 - unused
11213+ * 29 - PCI BIOS CS
11214+ * 30 - PCI BIOS DS
11215 * 31 - TSS for double fault handler
11216 */
11217 #define GDT_ENTRY_TLS_MIN 6
11218@@ -79,6 +79,8 @@
11219
11220 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11221
11222+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11223+
11224 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11225
11226 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11227@@ -104,6 +106,12 @@
11228 #define __KERNEL_STACK_CANARY 0
11229 #endif
11230
11231+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11232+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11233+
11234+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11235+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11236+
11237 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11238
11239 /*
11240@@ -141,7 +149,7 @@
11241 */
11242
11243 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11244-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11245+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11246
11247
11248 #else
11249@@ -165,6 +173,8 @@
11250 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11251 #define __USER32_DS __USER_DS
11252
11253+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11254+
11255 #define GDT_ENTRY_TSS 8 /* needs two entries */
11256 #define GDT_ENTRY_LDT 10 /* needs two entries */
11257 #define GDT_ENTRY_TLS_MIN 12
11258@@ -185,6 +195,7 @@
11259 #endif
11260
11261 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11262+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11263 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11264 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11265 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11266diff -urNp linux-2.6.39.1/arch/x86/include/asm/smp.h linux-2.6.39.1/arch/x86/include/asm/smp.h
11267--- linux-2.6.39.1/arch/x86/include/asm/smp.h 2011-05-19 00:06:34.000000000 -0400
11268+++ linux-2.6.39.1/arch/x86/include/asm/smp.h 2011-05-22 19:36:30.000000000 -0400
11269@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_
11270 /* cpus sharing the last level cache: */
11271 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11272 DECLARE_PER_CPU(u16, cpu_llc_id);
11273-DECLARE_PER_CPU(int, cpu_number);
11274+DECLARE_PER_CPU(unsigned int, cpu_number);
11275
11276 static inline struct cpumask *cpu_sibling_mask(int cpu)
11277 {
11278@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitd
11279 extern int safe_smp_processor_id(void);
11280
11281 #elif defined(CONFIG_X86_64_SMP)
11282-#define raw_smp_processor_id() (percpu_read(cpu_number))
11283-
11284-#define stack_smp_processor_id() \
11285-({ \
11286- struct thread_info *ti; \
11287- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11288- ti->cpu; \
11289-})
11290+#define raw_smp_processor_id() (percpu_read(cpu_number))
11291+#define stack_smp_processor_id() raw_smp_processor_id()
11292 #define safe_smp_processor_id() smp_processor_id()
11293
11294 #endif
11295diff -urNp linux-2.6.39.1/arch/x86/include/asm/spinlock.h linux-2.6.39.1/arch/x86/include/asm/spinlock.h
11296--- linux-2.6.39.1/arch/x86/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
11297+++ linux-2.6.39.1/arch/x86/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
11298@@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
11299 static inline void arch_read_lock(arch_rwlock_t *rw)
11300 {
11301 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11302+
11303+#ifdef CONFIG_PAX_REFCOUNT
11304+ "jno 0f\n"
11305+ LOCK_PREFIX " addl $1,(%0)\n"
11306+ "int $4\n0:\n"
11307+ _ASM_EXTABLE(0b, 0b)
11308+#endif
11309+
11310 "jns 1f\n"
11311 "call __read_lock_failed\n\t"
11312 "1:\n"
11313@@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
11314 static inline void arch_write_lock(arch_rwlock_t *rw)
11315 {
11316 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11317+
11318+#ifdef CONFIG_PAX_REFCOUNT
11319+ "jno 0f\n"
11320+ LOCK_PREFIX " addl %1,(%0)\n"
11321+ "int $4\n0:\n"
11322+ _ASM_EXTABLE(0b, 0b)
11323+#endif
11324+
11325 "jz 1f\n"
11326 "call __write_lock_failed\n\t"
11327 "1:\n"
11328@@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
11329
11330 static inline void arch_read_unlock(arch_rwlock_t *rw)
11331 {
11332- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11333+ asm volatile(LOCK_PREFIX "incl %0\n"
11334+
11335+#ifdef CONFIG_PAX_REFCOUNT
11336+ "jno 0f\n"
11337+ LOCK_PREFIX "decl %0\n"
11338+ "int $4\n0:\n"
11339+ _ASM_EXTABLE(0b, 0b)
11340+#endif
11341+
11342+ :"+m" (rw->lock) : : "memory");
11343 }
11344
11345 static inline void arch_write_unlock(arch_rwlock_t *rw)
11346 {
11347- asm volatile(LOCK_PREFIX "addl %1, %0"
11348+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
11349+
11350+#ifdef CONFIG_PAX_REFCOUNT
11351+ "jno 0f\n"
11352+ LOCK_PREFIX "subl %1, %0\n"
11353+ "int $4\n0:\n"
11354+ _ASM_EXTABLE(0b, 0b)
11355+#endif
11356+
11357 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11358 }
11359
11360diff -urNp linux-2.6.39.1/arch/x86/include/asm/stackprotector.h linux-2.6.39.1/arch/x86/include/asm/stackprotector.h
11361--- linux-2.6.39.1/arch/x86/include/asm/stackprotector.h 2011-05-19 00:06:34.000000000 -0400
11362+++ linux-2.6.39.1/arch/x86/include/asm/stackprotector.h 2011-05-22 19:36:30.000000000 -0400
11363@@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
11364
11365 static inline void load_stack_canary_segment(void)
11366 {
11367-#ifdef CONFIG_X86_32
11368+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11369 asm volatile ("mov %0, %%gs" : : "r" (0));
11370 #endif
11371 }
11372diff -urNp linux-2.6.39.1/arch/x86/include/asm/stacktrace.h linux-2.6.39.1/arch/x86/include/asm/stacktrace.h
11373--- linux-2.6.39.1/arch/x86/include/asm/stacktrace.h 2011-05-19 00:06:34.000000000 -0400
11374+++ linux-2.6.39.1/arch/x86/include/asm/stacktrace.h 2011-05-22 19:36:30.000000000 -0400
11375@@ -11,28 +11,20 @@
11376
11377 extern int kstack_depth_to_print;
11378
11379-struct thread_info;
11380+struct task_struct;
11381 struct stacktrace_ops;
11382
11383-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11384- unsigned long *stack,
11385- unsigned long bp,
11386- const struct stacktrace_ops *ops,
11387- void *data,
11388- unsigned long *end,
11389- int *graph);
11390-
11391-extern unsigned long
11392-print_context_stack(struct thread_info *tinfo,
11393- unsigned long *stack, unsigned long bp,
11394- const struct stacktrace_ops *ops, void *data,
11395- unsigned long *end, int *graph);
11396-
11397-extern unsigned long
11398-print_context_stack_bp(struct thread_info *tinfo,
11399- unsigned long *stack, unsigned long bp,
11400- const struct stacktrace_ops *ops, void *data,
11401- unsigned long *end, int *graph);
11402+typedef unsigned long walk_stack_t(struct task_struct *task,
11403+ void *stack_start,
11404+ unsigned long *stack,
11405+ unsigned long bp,
11406+ const struct stacktrace_ops *ops,
11407+ void *data,
11408+ unsigned long *end,
11409+ int *graph);
11410+
11411+extern walk_stack_t print_context_stack;
11412+extern walk_stack_t print_context_stack_bp;
11413
11414 /* Generic stack tracer with callbacks */
11415
11416@@ -43,7 +35,7 @@ struct stacktrace_ops {
11417 void (*address)(void *data, unsigned long address, int reliable);
11418 /* On negative return stop dumping */
11419 int (*stack)(void *data, char *name);
11420- walk_stack_t walk_stack;
11421+ walk_stack_t *walk_stack;
11422 };
11423
11424 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11425diff -urNp linux-2.6.39.1/arch/x86/include/asm/system.h linux-2.6.39.1/arch/x86/include/asm/system.h
11426--- linux-2.6.39.1/arch/x86/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
11427+++ linux-2.6.39.1/arch/x86/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
11428@@ -129,7 +129,7 @@ do { \
11429 "call __switch_to\n\t" \
11430 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11431 __switch_canary \
11432- "movq %P[thread_info](%%rsi),%%r8\n\t" \
11433+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11434 "movq %%rax,%%rdi\n\t" \
11435 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11436 "jnz ret_from_fork\n\t" \
11437@@ -140,7 +140,7 @@ do { \
11438 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11439 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11440 [_tif_fork] "i" (_TIF_FORK), \
11441- [thread_info] "i" (offsetof(struct task_struct, stack)), \
11442+ [thread_info] "m" (current_tinfo), \
11443 [current_task] "m" (current_task) \
11444 __switch_canary_iparam \
11445 : "memory", "cc" __EXTRA_CLOBBER)
11446@@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
11447 {
11448 unsigned long __limit;
11449 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11450- return __limit + 1;
11451+ return __limit;
11452 }
11453
11454 static inline void native_clts(void)
11455@@ -340,12 +340,12 @@ void enable_hlt(void);
11456
11457 void cpu_idle_wait(void);
11458
11459-extern unsigned long arch_align_stack(unsigned long sp);
11460+#define arch_align_stack(x) ((x) & ~0xfUL)
11461 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11462
11463 void default_idle(void);
11464
11465-void stop_this_cpu(void *dummy);
11466+void stop_this_cpu(void *dummy) __noreturn;
11467
11468 /*
11469 * Force strict CPU ordering.
11470diff -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
11471--- linux-2.6.39.1/arch/x86/include/asm/thread_info.h 2011-05-19 00:06:34.000000000 -0400
11472+++ linux-2.6.39.1/arch/x86/include/asm/thread_info.h 2011-05-22 19:36:30.000000000 -0400
11473@@ -10,6 +10,7 @@
11474 #include <linux/compiler.h>
11475 #include <asm/page.h>
11476 #include <asm/types.h>
11477+#include <asm/percpu.h>
11478
11479 /*
11480 * low level task data that entry.S needs immediate access to
11481@@ -24,7 +25,6 @@ struct exec_domain;
11482 #include <asm/atomic.h>
11483
11484 struct thread_info {
11485- struct task_struct *task; /* main task structure */
11486 struct exec_domain *exec_domain; /* execution domain */
11487 __u32 flags; /* low level flags */
11488 __u32 status; /* thread synchronous flags */
11489@@ -34,18 +34,12 @@ struct thread_info {
11490 mm_segment_t addr_limit;
11491 struct restart_block restart_block;
11492 void __user *sysenter_return;
11493-#ifdef CONFIG_X86_32
11494- unsigned long previous_esp; /* ESP of the previous stack in
11495- case of nested (IRQ) stacks
11496- */
11497- __u8 supervisor_stack[0];
11498-#endif
11499+ unsigned long lowest_stack;
11500 int uaccess_err;
11501 };
11502
11503-#define INIT_THREAD_INFO(tsk) \
11504+#define INIT_THREAD_INFO \
11505 { \
11506- .task = &tsk, \
11507 .exec_domain = &default_exec_domain, \
11508 .flags = 0, \
11509 .cpu = 0, \
11510@@ -56,7 +50,7 @@ struct thread_info {
11511 }, \
11512 }
11513
11514-#define init_thread_info (init_thread_union.thread_info)
11515+#define init_thread_info (init_thread_union.stack)
11516 #define init_stack (init_thread_union.stack)
11517
11518 #else /* !__ASSEMBLY__ */
11519@@ -170,6 +164,23 @@ struct thread_info {
11520 ret; \
11521 })
11522
11523+#ifdef __ASSEMBLY__
11524+/* how to get the thread information struct from ASM */
11525+#define GET_THREAD_INFO(reg) \
11526+ mov PER_CPU_VAR(current_tinfo), reg
11527+
11528+/* use this one if reg already contains %esp */
11529+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11530+#else
11531+/* how to get the thread information struct from C */
11532+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11533+
11534+static __always_inline struct thread_info *current_thread_info(void)
11535+{
11536+ return percpu_read_stable(current_tinfo);
11537+}
11538+#endif
11539+
11540 #ifdef CONFIG_X86_32
11541
11542 #define STACK_WARN (THREAD_SIZE/8)
11543@@ -180,35 +191,13 @@ struct thread_info {
11544 */
11545 #ifndef __ASSEMBLY__
11546
11547-
11548 /* how to get the current stack pointer from C */
11549 register unsigned long current_stack_pointer asm("esp") __used;
11550
11551-/* how to get the thread information struct from C */
11552-static inline struct thread_info *current_thread_info(void)
11553-{
11554- return (struct thread_info *)
11555- (current_stack_pointer & ~(THREAD_SIZE - 1));
11556-}
11557-
11558-#else /* !__ASSEMBLY__ */
11559-
11560-/* how to get the thread information struct from ASM */
11561-#define GET_THREAD_INFO(reg) \
11562- movl $-THREAD_SIZE, reg; \
11563- andl %esp, reg
11564-
11565-/* use this one if reg already contains %esp */
11566-#define GET_THREAD_INFO_WITH_ESP(reg) \
11567- andl $-THREAD_SIZE, reg
11568-
11569 #endif
11570
11571 #else /* X86_32 */
11572
11573-#include <asm/percpu.h>
11574-#define KERNEL_STACK_OFFSET (5*8)
11575-
11576 /*
11577 * macros/functions for gaining access to the thread information structure
11578 * preempt_count needs to be 1 initially, until the scheduler is functional.
11579@@ -216,21 +205,8 @@ static inline struct thread_info *curren
11580 #ifndef __ASSEMBLY__
11581 DECLARE_PER_CPU(unsigned long, kernel_stack);
11582
11583-static inline struct thread_info *current_thread_info(void)
11584-{
11585- struct thread_info *ti;
11586- ti = (void *)(percpu_read_stable(kernel_stack) +
11587- KERNEL_STACK_OFFSET - THREAD_SIZE);
11588- return ti;
11589-}
11590-
11591-#else /* !__ASSEMBLY__ */
11592-
11593-/* how to get the thread information struct from ASM */
11594-#define GET_THREAD_INFO(reg) \
11595- movq PER_CPU_VAR(kernel_stack),reg ; \
11596- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11597-
11598+/* how to get the current stack pointer from C */
11599+register unsigned long current_stack_pointer asm("rsp") __used;
11600 #endif
11601
11602 #endif /* !X86_32 */
11603@@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
11604 extern void free_thread_info(struct thread_info *ti);
11605 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11606 #define arch_task_cache_init arch_task_cache_init
11607+
11608+#define __HAVE_THREAD_FUNCTIONS
11609+#define task_thread_info(task) (&(task)->tinfo)
11610+#define task_stack_page(task) ((task)->stack)
11611+#define setup_thread_stack(p, org) do {} while (0)
11612+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11613+
11614+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11615+extern struct task_struct *alloc_task_struct_node(int node);
11616+extern void free_task_struct(struct task_struct *);
11617+
11618 #endif
11619 #endif /* _ASM_X86_THREAD_INFO_H */
11620diff -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
11621--- linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
11622+++ linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
11623@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
11624 static __always_inline unsigned long __must_check
11625 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11626 {
11627+ pax_track_stack();
11628+
11629+ if ((long)n < 0)
11630+ return n;
11631+
11632 if (__builtin_constant_p(n)) {
11633 unsigned long ret;
11634
11635@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
11636 return ret;
11637 }
11638 }
11639+ if (!__builtin_constant_p(n))
11640+ check_object_size(from, n, true);
11641 return __copy_to_user_ll(to, from, n);
11642 }
11643
11644@@ -83,12 +90,16 @@ static __always_inline unsigned long __m
11645 __copy_to_user(void __user *to, const void *from, unsigned long n)
11646 {
11647 might_fault();
11648+
11649 return __copy_to_user_inatomic(to, from, n);
11650 }
11651
11652 static __always_inline unsigned long
11653 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11654 {
11655+ if ((long)n < 0)
11656+ return n;
11657+
11658 /* Avoid zeroing the tail if the copy fails..
11659 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11660 * but as the zeroing behaviour is only significant when n is not
11661@@ -138,6 +149,12 @@ static __always_inline unsigned long
11662 __copy_from_user(void *to, const void __user *from, unsigned long n)
11663 {
11664 might_fault();
11665+
11666+ pax_track_stack();
11667+
11668+ if ((long)n < 0)
11669+ return n;
11670+
11671 if (__builtin_constant_p(n)) {
11672 unsigned long ret;
11673
11674@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
11675 return ret;
11676 }
11677 }
11678+ if (!__builtin_constant_p(n))
11679+ check_object_size(to, n, false);
11680 return __copy_from_user_ll(to, from, n);
11681 }
11682
11683@@ -160,6 +179,10 @@ static __always_inline unsigned long __c
11684 const void __user *from, unsigned long n)
11685 {
11686 might_fault();
11687+
11688+ if ((long)n < 0)
11689+ return n;
11690+
11691 if (__builtin_constant_p(n)) {
11692 unsigned long ret;
11693
11694@@ -182,15 +205,19 @@ static __always_inline unsigned long
11695 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11696 unsigned long n)
11697 {
11698- return __copy_from_user_ll_nocache_nozero(to, from, n);
11699-}
11700+ if ((long)n < 0)
11701+ return n;
11702
11703-unsigned long __must_check copy_to_user(void __user *to,
11704- const void *from, unsigned long n);
11705-unsigned long __must_check _copy_from_user(void *to,
11706- const void __user *from,
11707- unsigned long n);
11708+ return __copy_from_user_ll_nocache_nozero(to, from, n);
11709+}
11710
11711+extern void copy_to_user_overflow(void)
11712+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11713+ __compiletime_error("copy_to_user() buffer size is not provably correct")
11714+#else
11715+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
11716+#endif
11717+;
11718
11719 extern void copy_from_user_overflow(void)
11720 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11721@@ -200,17 +227,61 @@ extern void copy_from_user_overflow(void
11722 #endif
11723 ;
11724
11725-static inline unsigned long __must_check copy_from_user(void *to,
11726- const void __user *from,
11727- unsigned long n)
11728+/**
11729+ * copy_to_user: - Copy a block of data into user space.
11730+ * @to: Destination address, in user space.
11731+ * @from: Source address, in kernel space.
11732+ * @n: Number of bytes to copy.
11733+ *
11734+ * Context: User context only. This function may sleep.
11735+ *
11736+ * Copy data from kernel space to user space.
11737+ *
11738+ * Returns number of bytes that could not be copied.
11739+ * On success, this will be zero.
11740+ */
11741+static inline unsigned long __must_check
11742+copy_to_user(void __user *to, const void *from, unsigned long n)
11743+{
11744+ int sz = __compiletime_object_size(from);
11745+
11746+ if (unlikely(sz != -1 && sz < n))
11747+ copy_to_user_overflow();
11748+ else if (access_ok(VERIFY_WRITE, to, n))
11749+ n = __copy_to_user(to, from, n);
11750+ return n;
11751+}
11752+
11753+/**
11754+ * copy_from_user: - Copy a block of data from user space.
11755+ * @to: Destination address, in kernel space.
11756+ * @from: Source address, in user space.
11757+ * @n: Number of bytes to copy.
11758+ *
11759+ * Context: User context only. This function may sleep.
11760+ *
11761+ * Copy data from user space to kernel space.
11762+ *
11763+ * Returns number of bytes that could not be copied.
11764+ * On success, this will be zero.
11765+ *
11766+ * If some data could not be copied, this function will pad the copied
11767+ * data to the requested size using zero bytes.
11768+ */
11769+static inline unsigned long __must_check
11770+copy_from_user(void *to, const void __user *from, unsigned long n)
11771 {
11772 int sz = __compiletime_object_size(to);
11773
11774- if (likely(sz == -1 || sz >= n))
11775- n = _copy_from_user(to, from, n);
11776- else
11777+ if (unlikely(sz != -1 && sz < n))
11778 copy_from_user_overflow();
11779-
11780+ else if (access_ok(VERIFY_READ, from, n))
11781+ n = __copy_from_user(to, from, n);
11782+ else if ((long)n > 0) {
11783+ if (!__builtin_constant_p(n))
11784+ check_object_size(to, n, false);
11785+ memset(to, 0, n);
11786+ }
11787 return n;
11788 }
11789
11790diff -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
11791--- linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
11792+++ linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
11793@@ -11,6 +11,9 @@
11794 #include <asm/alternative.h>
11795 #include <asm/cpufeature.h>
11796 #include <asm/page.h>
11797+#include <asm/pgtable.h>
11798+
11799+#define set_fs(x) (current_thread_info()->addr_limit = (x))
11800
11801 /*
11802 * Copy To/From Userspace
11803@@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
11804 return ret;
11805 }
11806
11807-__must_check unsigned long
11808-_copy_to_user(void __user *to, const void *from, unsigned len);
11809-__must_check unsigned long
11810-_copy_from_user(void *to, const void __user *from, unsigned len);
11811+static __always_inline __must_check unsigned long
11812+__copy_to_user(void __user *to, const void *from, unsigned len);
11813+static __always_inline __must_check unsigned long
11814+__copy_from_user(void *to, const void __user *from, unsigned len);
11815 __must_check unsigned long
11816 copy_in_user(void __user *to, const void __user *from, unsigned len);
11817
11818 static inline unsigned long __must_check copy_from_user(void *to,
11819 const void __user *from,
11820- unsigned long n)
11821+ unsigned n)
11822 {
11823- int sz = __compiletime_object_size(to);
11824-
11825 might_fault();
11826- if (likely(sz == -1 || sz >= n))
11827- n = _copy_from_user(to, from, n);
11828-#ifdef CONFIG_DEBUG_VM
11829- else
11830- WARN(1, "Buffer overflow detected!\n");
11831-#endif
11832+
11833+ if (access_ok(VERIFY_READ, from, n))
11834+ n = __copy_from_user(to, from, n);
11835+ else if ((int)n > 0) {
11836+ if (!__builtin_constant_p(n))
11837+ check_object_size(to, n, false);
11838+ memset(to, 0, n);
11839+ }
11840 return n;
11841 }
11842
11843@@ -65,110 +68,198 @@ int copy_to_user(void __user *dst, const
11844 {
11845 might_fault();
11846
11847- return _copy_to_user(dst, src, size);
11848+ if (access_ok(VERIFY_WRITE, dst, size))
11849+ size = __copy_to_user(dst, src, size);
11850+ return size;
11851 }
11852
11853 static __always_inline __must_check
11854-int __copy_from_user(void *dst, const void __user *src, unsigned size)
11855+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
11856 {
11857- int ret = 0;
11858+ int sz = __compiletime_object_size(dst);
11859+ unsigned ret = 0;
11860
11861 might_fault();
11862- if (!__builtin_constant_p(size))
11863- return copy_user_generic(dst, (__force void *)src, size);
11864+
11865+ pax_track_stack();
11866+
11867+ if ((int)size < 0)
11868+ return size;
11869+
11870+#ifdef CONFIG_PAX_MEMORY_UDEREF
11871+ if (!__access_ok(VERIFY_READ, src, size))
11872+ return size;
11873+#endif
11874+
11875+ if (unlikely(sz != -1 && sz < size)) {
11876+#ifdef CONFIG_DEBUG_VM
11877+ WARN(1, "Buffer overflow detected!\n");
11878+#endif
11879+ return size;
11880+ }
11881+
11882+ if (!__builtin_constant_p(size)) {
11883+ check_object_size(dst, size, false);
11884+
11885+#ifdef CONFIG_PAX_MEMORY_UDEREF
11886+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11887+ src += PAX_USER_SHADOW_BASE;
11888+#endif
11889+
11890+ return copy_user_generic(dst, (__force const void *)src, size);
11891+ }
11892 switch (size) {
11893- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11894+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11895 ret, "b", "b", "=q", 1);
11896 return ret;
11897- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11898+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11899 ret, "w", "w", "=r", 2);
11900 return ret;
11901- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11902+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11903 ret, "l", "k", "=r", 4);
11904 return ret;
11905- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11906+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11907 ret, "q", "", "=r", 8);
11908 return ret;
11909 case 10:
11910- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11911+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11912 ret, "q", "", "=r", 10);
11913 if (unlikely(ret))
11914 return ret;
11915 __get_user_asm(*(u16 *)(8 + (char *)dst),
11916- (u16 __user *)(8 + (char __user *)src),
11917+ (const u16 __user *)(8 + (const char __user *)src),
11918 ret, "w", "w", "=r", 2);
11919 return ret;
11920 case 16:
11921- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11922+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11923 ret, "q", "", "=r", 16);
11924 if (unlikely(ret))
11925 return ret;
11926 __get_user_asm(*(u64 *)(8 + (char *)dst),
11927- (u64 __user *)(8 + (char __user *)src),
11928+ (const u64 __user *)(8 + (const char __user *)src),
11929 ret, "q", "", "=r", 8);
11930 return ret;
11931 default:
11932- return copy_user_generic(dst, (__force void *)src, size);
11933+
11934+#ifdef CONFIG_PAX_MEMORY_UDEREF
11935+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11936+ src += PAX_USER_SHADOW_BASE;
11937+#endif
11938+
11939+ return copy_user_generic(dst, (__force const void *)src, size);
11940 }
11941 }
11942
11943 static __always_inline __must_check
11944-int __copy_to_user(void __user *dst, const void *src, unsigned size)
11945+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
11946 {
11947- int ret = 0;
11948+ int sz = __compiletime_object_size(src);
11949+ unsigned ret = 0;
11950
11951 might_fault();
11952- if (!__builtin_constant_p(size))
11953+
11954+ pax_track_stack();
11955+
11956+ if ((int)size < 0)
11957+ return size;
11958+
11959+#ifdef CONFIG_PAX_MEMORY_UDEREF
11960+ if (!__access_ok(VERIFY_WRITE, dst, size))
11961+ return size;
11962+#endif
11963+
11964+ if (unlikely(sz != -1 && sz < size)) {
11965+#ifdef CONFIG_DEBUG_VM
11966+ WARN(1, "Buffer overflow detected!\n");
11967+#endif
11968+ return size;
11969+ }
11970+
11971+ if (!__builtin_constant_p(size)) {
11972+ check_object_size(src, size, true);
11973+
11974+#ifdef CONFIG_PAX_MEMORY_UDEREF
11975+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11976+ dst += PAX_USER_SHADOW_BASE;
11977+#endif
11978+
11979 return copy_user_generic((__force void *)dst, src, size);
11980+ }
11981 switch (size) {
11982- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11983+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11984 ret, "b", "b", "iq", 1);
11985 return ret;
11986- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11987+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11988 ret, "w", "w", "ir", 2);
11989 return ret;
11990- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11991+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11992 ret, "l", "k", "ir", 4);
11993 return ret;
11994- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11995+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11996 ret, "q", "", "er", 8);
11997 return ret;
11998 case 10:
11999- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12000+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12001 ret, "q", "", "er", 10);
12002 if (unlikely(ret))
12003 return ret;
12004 asm("":::"memory");
12005- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12006+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12007 ret, "w", "w", "ir", 2);
12008 return ret;
12009 case 16:
12010- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12011+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12012 ret, "q", "", "er", 16);
12013 if (unlikely(ret))
12014 return ret;
12015 asm("":::"memory");
12016- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12017+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12018 ret, "q", "", "er", 8);
12019 return ret;
12020 default:
12021+
12022+#ifdef CONFIG_PAX_MEMORY_UDEREF
12023+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12024+ dst += PAX_USER_SHADOW_BASE;
12025+#endif
12026+
12027 return copy_user_generic((__force void *)dst, src, size);
12028 }
12029 }
12030
12031 static __always_inline __must_check
12032-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12033+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12034 {
12035- int ret = 0;
12036+ unsigned ret = 0;
12037
12038 might_fault();
12039- if (!__builtin_constant_p(size))
12040+
12041+ if ((int)size < 0)
12042+ return size;
12043+
12044+#ifdef CONFIG_PAX_MEMORY_UDEREF
12045+ if (!__access_ok(VERIFY_READ, src, size))
12046+ return size;
12047+ if (!__access_ok(VERIFY_WRITE, dst, size))
12048+ return size;
12049+#endif
12050+
12051+ if (!__builtin_constant_p(size)) {
12052+
12053+#ifdef CONFIG_PAX_MEMORY_UDEREF
12054+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12055+ src += PAX_USER_SHADOW_BASE;
12056+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12057+ dst += PAX_USER_SHADOW_BASE;
12058+#endif
12059+
12060 return copy_user_generic((__force void *)dst,
12061- (__force void *)src, size);
12062+ (__force const void *)src, size);
12063+ }
12064 switch (size) {
12065 case 1: {
12066 u8 tmp;
12067- __get_user_asm(tmp, (u8 __user *)src,
12068+ __get_user_asm(tmp, (const u8 __user *)src,
12069 ret, "b", "b", "=q", 1);
12070 if (likely(!ret))
12071 __put_user_asm(tmp, (u8 __user *)dst,
12072@@ -177,7 +268,7 @@ int __copy_in_user(void __user *dst, con
12073 }
12074 case 2: {
12075 u16 tmp;
12076- __get_user_asm(tmp, (u16 __user *)src,
12077+ __get_user_asm(tmp, (const u16 __user *)src,
12078 ret, "w", "w", "=r", 2);
12079 if (likely(!ret))
12080 __put_user_asm(tmp, (u16 __user *)dst,
12081@@ -187,7 +278,7 @@ int __copy_in_user(void __user *dst, con
12082
12083 case 4: {
12084 u32 tmp;
12085- __get_user_asm(tmp, (u32 __user *)src,
12086+ __get_user_asm(tmp, (const u32 __user *)src,
12087 ret, "l", "k", "=r", 4);
12088 if (likely(!ret))
12089 __put_user_asm(tmp, (u32 __user *)dst,
12090@@ -196,7 +287,7 @@ int __copy_in_user(void __user *dst, con
12091 }
12092 case 8: {
12093 u64 tmp;
12094- __get_user_asm(tmp, (u64 __user *)src,
12095+ __get_user_asm(tmp, (const u64 __user *)src,
12096 ret, "q", "", "=r", 8);
12097 if (likely(!ret))
12098 __put_user_asm(tmp, (u64 __user *)dst,
12099@@ -204,8 +295,16 @@ int __copy_in_user(void __user *dst, con
12100 return ret;
12101 }
12102 default:
12103+
12104+#ifdef CONFIG_PAX_MEMORY_UDEREF
12105+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12106+ src += PAX_USER_SHADOW_BASE;
12107+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12108+ dst += PAX_USER_SHADOW_BASE;
12109+#endif
12110+
12111 return copy_user_generic((__force void *)dst,
12112- (__force void *)src, size);
12113+ (__force const void *)src, size);
12114 }
12115 }
12116
12117@@ -222,33 +321,72 @@ __must_check unsigned long __clear_user(
12118 static __must_check __always_inline int
12119 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12120 {
12121+ pax_track_stack();
12122+
12123+ if ((int)size < 0)
12124+ return size;
12125+
12126+#ifdef CONFIG_PAX_MEMORY_UDEREF
12127+ if (!__access_ok(VERIFY_READ, src, size))
12128+ return size;
12129+
12130+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12131+ src += PAX_USER_SHADOW_BASE;
12132+#endif
12133+
12134 return copy_user_generic(dst, (__force const void *)src, size);
12135 }
12136
12137-static __must_check __always_inline int
12138+static __must_check __always_inline unsigned long
12139 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12140 {
12141+ if ((int)size < 0)
12142+ return size;
12143+
12144+#ifdef CONFIG_PAX_MEMORY_UDEREF
12145+ if (!__access_ok(VERIFY_WRITE, dst, size))
12146+ return size;
12147+
12148+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12149+ dst += PAX_USER_SHADOW_BASE;
12150+#endif
12151+
12152 return copy_user_generic((__force void *)dst, src, size);
12153 }
12154
12155-extern long __copy_user_nocache(void *dst, const void __user *src,
12156+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12157 unsigned size, int zerorest);
12158
12159-static inline int
12160-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12161+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12162 {
12163 might_sleep();
12164+
12165+ if ((int)size < 0)
12166+ return size;
12167+
12168+#ifdef CONFIG_PAX_MEMORY_UDEREF
12169+ if (!__access_ok(VERIFY_READ, src, size))
12170+ return size;
12171+#endif
12172+
12173 return __copy_user_nocache(dst, src, size, 1);
12174 }
12175
12176-static inline int
12177-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12178+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12179 unsigned size)
12180 {
12181+ if ((int)size < 0)
12182+ return size;
12183+
12184+#ifdef CONFIG_PAX_MEMORY_UDEREF
12185+ if (!__access_ok(VERIFY_READ, src, size))
12186+ return size;
12187+#endif
12188+
12189 return __copy_user_nocache(dst, src, size, 0);
12190 }
12191
12192-unsigned long
12193+extern unsigned long
12194 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12195
12196 #endif /* _ASM_X86_UACCESS_64_H */
12197diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess.h linux-2.6.39.1/arch/x86/include/asm/uaccess.h
12198--- linux-2.6.39.1/arch/x86/include/asm/uaccess.h 2011-06-03 00:04:13.000000000 -0400
12199+++ linux-2.6.39.1/arch/x86/include/asm/uaccess.h 2011-06-03 00:32:04.000000000 -0400
12200@@ -8,12 +8,15 @@
12201 #include <linux/thread_info.h>
12202 #include <linux/prefetch.h>
12203 #include <linux/string.h>
12204+#include <linux/sched.h>
12205 #include <asm/asm.h>
12206 #include <asm/page.h>
12207
12208 #define VERIFY_READ 0
12209 #define VERIFY_WRITE 1
12210
12211+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12212+
12213 /*
12214 * The fs value determines whether argument validity checking should be
12215 * performed or not. If get_fs() == USER_DS, checking is performed, with
12216@@ -29,7 +32,12 @@
12217
12218 #define get_ds() (KERNEL_DS)
12219 #define get_fs() (current_thread_info()->addr_limit)
12220+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12221+void __set_fs(mm_segment_t x);
12222+void set_fs(mm_segment_t x);
12223+#else
12224 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12225+#endif
12226
12227 #define segment_eq(a, b) ((a).seg == (b).seg)
12228
12229@@ -77,7 +85,33 @@
12230 * checks that the pointer is in the user space range - after calling
12231 * this function, memory access functions may still return -EFAULT.
12232 */
12233-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12234+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12235+#define access_ok(type, addr, size) \
12236+({ \
12237+ long __size = size; \
12238+ unsigned long __addr = (unsigned long)addr; \
12239+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12240+ unsigned long __end_ao = __addr + __size - 1; \
12241+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12242+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12243+ while(__addr_ao <= __end_ao) { \
12244+ char __c_ao; \
12245+ __addr_ao += PAGE_SIZE; \
12246+ if (__size > PAGE_SIZE) \
12247+ cond_resched(); \
12248+ if (__get_user(__c_ao, (char __user *)__addr)) \
12249+ break; \
12250+ if (type != VERIFY_WRITE) { \
12251+ __addr = __addr_ao; \
12252+ continue; \
12253+ } \
12254+ if (__put_user(__c_ao, (char __user *)__addr)) \
12255+ break; \
12256+ __addr = __addr_ao; \
12257+ } \
12258+ } \
12259+ __ret_ao; \
12260+})
12261
12262 /*
12263 * The exception table consists of pairs of addresses: the first is the
12264@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12265 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12266 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12267
12268-
12269+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12270+#define __copyuser_seg "gs;"
12271+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12272+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12273+#else
12274+#define __copyuser_seg
12275+#define __COPYUSER_SET_ES
12276+#define __COPYUSER_RESTORE_ES
12277+#endif
12278
12279 #ifdef CONFIG_X86_32
12280 #define __put_user_asm_u64(x, addr, err, errret) \
12281- asm volatile("1: movl %%eax,0(%2)\n" \
12282- "2: movl %%edx,4(%2)\n" \
12283+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12284+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12285 "3:\n" \
12286 ".section .fixup,\"ax\"\n" \
12287 "4: movl %3,%0\n" \
12288@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12289 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12290
12291 #define __put_user_asm_ex_u64(x, addr) \
12292- asm volatile("1: movl %%eax,0(%1)\n" \
12293- "2: movl %%edx,4(%1)\n" \
12294+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12295+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12296 "3:\n" \
12297 _ASM_EXTABLE(1b, 2b - 1b) \
12298 _ASM_EXTABLE(2b, 3b - 2b) \
12299@@ -374,7 +416,7 @@ do { \
12300 } while (0)
12301
12302 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12303- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12304+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12305 "2:\n" \
12306 ".section .fixup,\"ax\"\n" \
12307 "3: mov %3,%0\n" \
12308@@ -382,7 +424,7 @@ do { \
12309 " jmp 2b\n" \
12310 ".previous\n" \
12311 _ASM_EXTABLE(1b, 3b) \
12312- : "=r" (err), ltype(x) \
12313+ : "=r" (err), ltype (x) \
12314 : "m" (__m(addr)), "i" (errret), "0" (err))
12315
12316 #define __get_user_size_ex(x, ptr, size) \
12317@@ -407,7 +449,7 @@ do { \
12318 } while (0)
12319
12320 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12321- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12322+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12323 "2:\n" \
12324 _ASM_EXTABLE(1b, 2b - 1b) \
12325 : ltype(x) : "m" (__m(addr)))
12326@@ -424,13 +466,24 @@ do { \
12327 int __gu_err; \
12328 unsigned long __gu_val; \
12329 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12330- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12331+ (x) = (__typeof__(*(ptr)))__gu_val; \
12332 __gu_err; \
12333 })
12334
12335 /* FIXME: this hack is definitely wrong -AK */
12336 struct __large_struct { unsigned long buf[100]; };
12337-#define __m(x) (*(struct __large_struct __user *)(x))
12338+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12339+#define ____m(x) \
12340+({ \
12341+ unsigned long ____x = (unsigned long)(x); \
12342+ if (____x < PAX_USER_SHADOW_BASE) \
12343+ ____x += PAX_USER_SHADOW_BASE; \
12344+ (void __user *)____x; \
12345+})
12346+#else
12347+#define ____m(x) (x)
12348+#endif
12349+#define __m(x) (*(struct __large_struct __user *)____m(x))
12350
12351 /*
12352 * Tell gcc we read from memory instead of writing: this is because
12353@@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
12354 * aliasing issues.
12355 */
12356 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12357- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12358+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12359 "2:\n" \
12360 ".section .fixup,\"ax\"\n" \
12361 "3: mov %3,%0\n" \
12362@@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
12363 ".previous\n" \
12364 _ASM_EXTABLE(1b, 3b) \
12365 : "=r"(err) \
12366- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12367+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12368
12369 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12370- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12371+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12372 "2:\n" \
12373 _ASM_EXTABLE(1b, 2b - 1b) \
12374 : : ltype(x), "m" (__m(addr)))
12375@@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
12376 * On error, the variable @x is set to zero.
12377 */
12378
12379+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12380+#define __get_user(x, ptr) get_user((x), (ptr))
12381+#else
12382 #define __get_user(x, ptr) \
12383 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12384+#endif
12385
12386 /**
12387 * __put_user: - Write a simple value into user space, with less checking.
12388@@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
12389 * Returns zero on success, or -EFAULT on error.
12390 */
12391
12392+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12393+#define __put_user(x, ptr) put_user((x), (ptr))
12394+#else
12395 #define __put_user(x, ptr) \
12396 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12397+#endif
12398
12399 #define __get_user_unaligned __get_user
12400 #define __put_user_unaligned __put_user
12401@@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
12402 #define get_user_ex(x, ptr) do { \
12403 unsigned long __gue_val; \
12404 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12405- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12406+ (x) = (__typeof__(*(ptr)))__gue_val; \
12407 } while (0)
12408
12409 #ifdef CONFIG_X86_WP_WORKS_OK
12410@@ -567,6 +628,7 @@ extern struct movsl_mask {
12411
12412 #define ARCH_HAS_NOCACHE_UACCESS 1
12413
12414+#define ARCH_HAS_SORT_EXTABLE
12415 #ifdef CONFIG_X86_32
12416 # include "uaccess_32.h"
12417 #else
12418diff -urNp linux-2.6.39.1/arch/x86/include/asm/vgtod.h linux-2.6.39.1/arch/x86/include/asm/vgtod.h
12419--- linux-2.6.39.1/arch/x86/include/asm/vgtod.h 2011-05-19 00:06:34.000000000 -0400
12420+++ linux-2.6.39.1/arch/x86/include/asm/vgtod.h 2011-05-22 19:36:30.000000000 -0400
12421@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12422 int sysctl_enabled;
12423 struct timezone sys_tz;
12424 struct { /* extract of a clocksource struct */
12425+ char name[8];
12426 cycle_t (*vread)(void);
12427 cycle_t cycle_last;
12428 cycle_t mask;
12429diff -urNp linux-2.6.39.1/arch/x86/include/asm/vsyscall.h linux-2.6.39.1/arch/x86/include/asm/vsyscall.h
12430--- linux-2.6.39.1/arch/x86/include/asm/vsyscall.h 2011-05-19 00:06:34.000000000 -0400
12431+++ linux-2.6.39.1/arch/x86/include/asm/vsyscall.h 2011-05-22 19:36:30.000000000 -0400
12432@@ -15,9 +15,10 @@ enum vsyscall_num {
12433
12434 #ifdef __KERNEL__
12435 #include <linux/seqlock.h>
12436+#include <linux/getcpu.h>
12437+#include <linux/time.h>
12438
12439 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12440-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12441
12442 /* Definitions for CONFIG_GENERIC_TIME definitions */
12443 #define __section_vsyscall_gtod_data __attribute__ \
12444@@ -31,7 +32,6 @@ enum vsyscall_num {
12445 #define VGETCPU_LSL 2
12446
12447 extern int __vgetcpu_mode;
12448-extern volatile unsigned long __jiffies;
12449
12450 /* kernel space (writeable) */
12451 extern int vgetcpu_mode;
12452@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12453
12454 extern void map_vsyscall(void);
12455
12456+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12457+extern time_t vtime(time_t *t);
12458+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12459 #endif /* __KERNEL__ */
12460
12461 #endif /* _ASM_X86_VSYSCALL_H */
12462diff -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
12463--- linux-2.6.39.1/arch/x86/include/asm/xen/pci.h 2011-05-19 00:06:34.000000000 -0400
12464+++ linux-2.6.39.1/arch/x86/include/asm/xen/pci.h 2011-05-22 19:36:30.000000000 -0400
12465@@ -33,7 +33,7 @@ struct xen_pci_frontend_ops {
12466 void (*disable_msix)(struct pci_dev *dev);
12467 };
12468
12469-extern struct xen_pci_frontend_ops *xen_pci_frontend;
12470+extern const struct xen_pci_frontend_ops *xen_pci_frontend;
12471
12472 static inline int xen_pci_frontend_enable_msi(struct pci_dev *dev,
12473 int vectors[])
12474diff -urNp linux-2.6.39.1/arch/x86/include/asm/xsave.h linux-2.6.39.1/arch/x86/include/asm/xsave.h
12475--- linux-2.6.39.1/arch/x86/include/asm/xsave.h 2011-05-19 00:06:34.000000000 -0400
12476+++ linux-2.6.39.1/arch/x86/include/asm/xsave.h 2011-05-22 19:36:30.000000000 -0400
12477@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
12478 {
12479 int err;
12480
12481+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12482+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12483+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12484+#endif
12485+
12486 /*
12487 * Clear the xsave header first, so that reserved fields are
12488 * initialized to zero.
12489@@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
12490 u32 lmask = mask;
12491 u32 hmask = mask >> 32;
12492
12493+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12494+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12495+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12496+#endif
12497+
12498 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12499 "2:\n"
12500 ".section .fixup,\"ax\"\n"
12501diff -urNp linux-2.6.39.1/arch/x86/Kconfig linux-2.6.39.1/arch/x86/Kconfig
12502--- linux-2.6.39.1/arch/x86/Kconfig 2011-05-19 00:06:34.000000000 -0400
12503+++ linux-2.6.39.1/arch/x86/Kconfig 2011-05-22 19:41:32.000000000 -0400
12504@@ -224,7 +224,7 @@ config X86_HT
12505
12506 config X86_32_LAZY_GS
12507 def_bool y
12508- depends on X86_32 && !CC_STACKPROTECTOR
12509+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12510
12511 config ARCH_HWEIGHT_CFLAGS
12512 string
12513@@ -1022,7 +1022,7 @@ choice
12514
12515 config NOHIGHMEM
12516 bool "off"
12517- depends on !X86_NUMAQ
12518+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12519 ---help---
12520 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12521 However, the address space of 32-bit x86 processors is only 4
12522@@ -1059,7 +1059,7 @@ config NOHIGHMEM
12523
12524 config HIGHMEM4G
12525 bool "4GB"
12526- depends on !X86_NUMAQ
12527+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12528 ---help---
12529 Select this if you have a 32-bit processor and between 1 and 4
12530 gigabytes of physical RAM.
12531@@ -1113,7 +1113,7 @@ config PAGE_OFFSET
12532 hex
12533 default 0xB0000000 if VMSPLIT_3G_OPT
12534 default 0x80000000 if VMSPLIT_2G
12535- default 0x78000000 if VMSPLIT_2G_OPT
12536+ default 0x70000000 if VMSPLIT_2G_OPT
12537 default 0x40000000 if VMSPLIT_1G
12538 default 0xC0000000
12539 depends on X86_32
12540@@ -1457,7 +1457,7 @@ config ARCH_USES_PG_UNCACHED
12541
12542 config EFI
12543 bool "EFI runtime service support"
12544- depends on ACPI
12545+ depends on ACPI && !PAX_KERNEXEC
12546 ---help---
12547 This enables the kernel to use EFI runtime services that are
12548 available (such as the EFI variable services).
12549@@ -1487,6 +1487,7 @@ config SECCOMP
12550
12551 config CC_STACKPROTECTOR
12552 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
12553+ depends on X86_64 || !PAX_MEMORY_UDEREF
12554 ---help---
12555 This option turns on the -fstack-protector GCC feature. This
12556 feature puts, at the beginning of functions, a canary value on
12557@@ -1544,6 +1545,7 @@ config KEXEC_JUMP
12558 config PHYSICAL_START
12559 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
12560 default "0x1000000"
12561+ range 0x400000 0x40000000
12562 ---help---
12563 This gives the physical address where the kernel is loaded.
12564
12565@@ -1607,6 +1609,7 @@ config X86_NEED_RELOCS
12566 config PHYSICAL_ALIGN
12567 hex "Alignment value to which kernel should be aligned" if X86_32
12568 default "0x1000000"
12569+ range 0x400000 0x1000000 if PAX_KERNEXEC
12570 range 0x2000 0x1000000
12571 ---help---
12572 This value puts the alignment restrictions on physical address
12573@@ -1638,9 +1641,10 @@ config HOTPLUG_CPU
12574 Say N if you want to disable CPU hotplug.
12575
12576 config COMPAT_VDSO
12577- def_bool y
12578+ def_bool n
12579 prompt "Compat VDSO support"
12580 depends on X86_32 || IA32_EMULATION
12581+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
12582 ---help---
12583 Map the 32-bit VDSO to the predictable old-style address too.
12584
12585diff -urNp linux-2.6.39.1/arch/x86/Kconfig.cpu linux-2.6.39.1/arch/x86/Kconfig.cpu
12586--- linux-2.6.39.1/arch/x86/Kconfig.cpu 2011-05-19 00:06:34.000000000 -0400
12587+++ linux-2.6.39.1/arch/x86/Kconfig.cpu 2011-05-22 19:36:30.000000000 -0400
12588@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
12589
12590 config X86_F00F_BUG
12591 def_bool y
12592- depends on M586MMX || M586TSC || M586 || M486 || M386
12593+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
12594
12595 config X86_INVD_BUG
12596 def_bool y
12597@@ -358,7 +358,7 @@ config X86_POPAD_OK
12598
12599 config X86_ALIGNMENT_16
12600 def_bool y
12601- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12602+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12603
12604 config X86_INTEL_USERCOPY
12605 def_bool y
12606@@ -404,7 +404,7 @@ config X86_CMPXCHG64
12607 # generates cmov.
12608 config X86_CMOV
12609 def_bool y
12610- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12611+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12612
12613 config X86_MINIMUM_CPU_FAMILY
12614 int
12615diff -urNp linux-2.6.39.1/arch/x86/Kconfig.debug linux-2.6.39.1/arch/x86/Kconfig.debug
12616--- linux-2.6.39.1/arch/x86/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
12617+++ linux-2.6.39.1/arch/x86/Kconfig.debug 2011-05-22 19:36:30.000000000 -0400
12618@@ -101,7 +101,7 @@ config X86_PTDUMP
12619 config DEBUG_RODATA
12620 bool "Write protect kernel read-only data structures"
12621 default y
12622- depends on DEBUG_KERNEL
12623+ depends on DEBUG_KERNEL && BROKEN
12624 ---help---
12625 Mark the kernel read-only data as write-protected in the pagetables,
12626 in order to catch accidental (and incorrect) writes to such const
12627@@ -119,7 +119,7 @@ config DEBUG_RODATA_TEST
12628
12629 config DEBUG_SET_MODULE_RONX
12630 bool "Set loadable kernel module data as NX and text as RO"
12631- depends on MODULES
12632+ depends on MODULES && BROKEN
12633 ---help---
12634 This option helps catch unintended modifications to loadable
12635 kernel module's text and read-only data. It also prevents execution
12636diff -urNp linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c
12637--- linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c 2011-05-19 00:06:34.000000000 -0400
12638+++ linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c 2011-05-22 19:36:30.000000000 -0400
12639@@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
12640 header->trampoline_segment = trampoline_address() >> 4;
12641 #ifdef CONFIG_SMP
12642 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12643+
12644+ pax_open_kernel();
12645 early_gdt_descr.address =
12646 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12647+ pax_close_kernel();
12648+
12649 initial_gs = per_cpu_offset(smp_processor_id());
12650 #endif
12651 initial_code = (unsigned long)wakeup_long64;
12652diff -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
12653--- linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S 2011-05-19 00:06:34.000000000 -0400
12654+++ linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S 2011-05-22 19:36:30.000000000 -0400
12655@@ -30,13 +30,11 @@ wakeup_pmode_return:
12656 # and restore the stack ... but you need gdt for this to work
12657 movl saved_context_esp, %esp
12658
12659- movl %cs:saved_magic, %eax
12660- cmpl $0x12345678, %eax
12661+ cmpl $0x12345678, saved_magic
12662 jne bogus_magic
12663
12664 # jump to place where we left off
12665- movl saved_eip, %eax
12666- jmp *%eax
12667+ jmp *(saved_eip)
12668
12669 bogus_magic:
12670 jmp bogus_magic
12671diff -urNp linux-2.6.39.1/arch/x86/kernel/alternative.c linux-2.6.39.1/arch/x86/kernel/alternative.c
12672--- linux-2.6.39.1/arch/x86/kernel/alternative.c 2011-05-19 00:06:34.000000000 -0400
12673+++ linux-2.6.39.1/arch/x86/kernel/alternative.c 2011-05-22 19:36:30.000000000 -0400
12674@@ -248,7 +248,7 @@ static void alternatives_smp_lock(const
12675 if (!*poff || ptr < text || ptr >= text_end)
12676 continue;
12677 /* turn DS segment override prefix into lock prefix */
12678- if (*ptr == 0x3e)
12679+ if (*ktla_ktva(ptr) == 0x3e)
12680 text_poke(ptr, ((unsigned char []){0xf0}), 1);
12681 };
12682 mutex_unlock(&text_mutex);
12683@@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
12684 if (!*poff || ptr < text || ptr >= text_end)
12685 continue;
12686 /* turn lock prefix into DS segment override prefix */
12687- if (*ptr == 0xf0)
12688+ if (*ktla_ktva(ptr) == 0xf0)
12689 text_poke(ptr, ((unsigned char []){0x3E}), 1);
12690 };
12691 mutex_unlock(&text_mutex);
12692@@ -438,7 +438,7 @@ void __init_or_module apply_paravirt(str
12693
12694 BUG_ON(p->len > MAX_PATCH_LEN);
12695 /* prep the buffer with the original instructions */
12696- memcpy(insnbuf, p->instr, p->len);
12697+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12698 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12699 (unsigned long)p->instr, p->len);
12700
12701@@ -506,7 +506,7 @@ void __init alternative_instructions(voi
12702 if (smp_alt_once)
12703 free_init_pages("SMP alternatives",
12704 (unsigned long)__smp_locks,
12705- (unsigned long)__smp_locks_end);
12706+ PAGE_ALIGN((unsigned long)__smp_locks_end));
12707
12708 restart_nmi();
12709 }
12710@@ -523,13 +523,17 @@ void __init alternative_instructions(voi
12711 * instructions. And on the local CPU you need to be protected again NMI or MCE
12712 * handlers seeing an inconsistent instruction while you patch.
12713 */
12714-void *__init_or_module text_poke_early(void *addr, const void *opcode,
12715+void *__kprobes text_poke_early(void *addr, const void *opcode,
12716 size_t len)
12717 {
12718 unsigned long flags;
12719 local_irq_save(flags);
12720- memcpy(addr, opcode, len);
12721+
12722+ pax_open_kernel();
12723+ memcpy(ktla_ktva(addr), opcode, len);
12724 sync_core();
12725+ pax_close_kernel();
12726+
12727 local_irq_restore(flags);
12728 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12729 that causes hangs on some VIA CPUs. */
12730@@ -551,36 +555,22 @@ void *__init_or_module text_poke_early(v
12731 */
12732 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12733 {
12734- unsigned long flags;
12735- char *vaddr;
12736+ unsigned char *vaddr = ktla_ktva(addr);
12737 struct page *pages[2];
12738- int i;
12739+ size_t i;
12740
12741 if (!core_kernel_text((unsigned long)addr)) {
12742- pages[0] = vmalloc_to_page(addr);
12743- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12744+ pages[0] = vmalloc_to_page(vaddr);
12745+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12746 } else {
12747- pages[0] = virt_to_page(addr);
12748+ pages[0] = virt_to_page(vaddr);
12749 WARN_ON(!PageReserved(pages[0]));
12750- pages[1] = virt_to_page(addr + PAGE_SIZE);
12751+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12752 }
12753 BUG_ON(!pages[0]);
12754- local_irq_save(flags);
12755- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12756- if (pages[1])
12757- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12758- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12759- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12760- clear_fixmap(FIX_TEXT_POKE0);
12761- if (pages[1])
12762- clear_fixmap(FIX_TEXT_POKE1);
12763- local_flush_tlb();
12764- sync_core();
12765- /* Could also do a CLFLUSH here to speed up CPU recovery; but
12766- that causes hangs on some VIA CPUs. */
12767+ text_poke_early(addr, opcode, len);
12768 for (i = 0; i < len; i++)
12769- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12770- local_irq_restore(flags);
12771+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12772 return addr;
12773 }
12774
12775@@ -682,9 +672,9 @@ void __kprobes text_poke_smp_batch(struc
12776 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
12777
12778 #ifdef CONFIG_X86_64
12779-unsigned char ideal_nop5[5] = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12780+unsigned char ideal_nop5[5] __read_only = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12781 #else
12782-unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12783+unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12784 #endif
12785
12786 void __init arch_init_ideal_nop5(void)
12787diff -urNp linux-2.6.39.1/arch/x86/kernel/amd_iommu.c linux-2.6.39.1/arch/x86/kernel/amd_iommu.c
12788--- linux-2.6.39.1/arch/x86/kernel/amd_iommu.c 2011-05-19 00:06:34.000000000 -0400
12789+++ linux-2.6.39.1/arch/x86/kernel/amd_iommu.c 2011-05-22 19:36:30.000000000 -0400
12790@@ -48,7 +48,7 @@ static DEFINE_SPINLOCK(iommu_pd_list_loc
12791 */
12792 static struct protection_domain *pt_domain;
12793
12794-static struct iommu_ops amd_iommu_ops;
12795+static const struct iommu_ops amd_iommu_ops;
12796
12797 /*
12798 * general struct to manage commands send to an IOMMU
12799@@ -2286,7 +2286,7 @@ static void prealloc_protection_domains(
12800 }
12801 }
12802
12803-static struct dma_map_ops amd_iommu_dma_ops = {
12804+static const struct dma_map_ops amd_iommu_dma_ops = {
12805 .alloc_coherent = alloc_coherent,
12806 .free_coherent = free_coherent,
12807 .map_page = map_page,
12808@@ -2582,7 +2582,7 @@ static int amd_iommu_domain_has_cap(stru
12809 return 0;
12810 }
12811
12812-static struct iommu_ops amd_iommu_ops = {
12813+static const struct iommu_ops amd_iommu_ops = {
12814 .domain_init = amd_iommu_domain_init,
12815 .domain_destroy = amd_iommu_domain_destroy,
12816 .attach_dev = amd_iommu_attach_device,
12817diff -urNp linux-2.6.39.1/arch/x86/kernel/apic/apic.c linux-2.6.39.1/arch/x86/kernel/apic/apic.c
12818--- linux-2.6.39.1/arch/x86/kernel/apic/apic.c 2011-05-19 00:06:34.000000000 -0400
12819+++ linux-2.6.39.1/arch/x86/kernel/apic/apic.c 2011-05-22 19:36:30.000000000 -0400
12820@@ -1821,7 +1821,7 @@ void smp_error_interrupt(struct pt_regs
12821 apic_write(APIC_ESR, 0);
12822 v1 = apic_read(APIC_ESR);
12823 ack_APIC_irq();
12824- atomic_inc(&irq_err_count);
12825+ atomic_inc_unchecked(&irq_err_count);
12826
12827 /*
12828 * Here is what the APIC error bits mean:
12829@@ -2204,6 +2204,8 @@ static int __cpuinit apic_cluster_num(vo
12830 u16 *bios_cpu_apicid;
12831 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
12832
12833+ pax_track_stack();
12834+
12835 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
12836 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
12837
12838diff -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
12839--- linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:04:13.000000000 -0400
12840+++ linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:42:37.000000000 -0400
12841@@ -623,7 +623,7 @@ struct IO_APIC_route_entry **alloc_ioapi
12842 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
12843 GFP_ATOMIC);
12844 if (!ioapic_entries)
12845- return 0;
12846+ return NULL;
12847
12848 for (apic = 0; apic < nr_ioapics; apic++) {
12849 ioapic_entries[apic] =
12850@@ -640,7 +640,7 @@ nomem:
12851 kfree(ioapic_entries[apic]);
12852 kfree(ioapic_entries);
12853
12854- return 0;
12855+ return NULL;
12856 }
12857
12858 /*
12859@@ -1040,7 +1040,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
12860 }
12861 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12862
12863-void lock_vector_lock(void)
12864+void lock_vector_lock(void) __acquires(vector_lock)
12865 {
12866 /* Used to the online set of cpus does not change
12867 * during assign_irq_vector.
12868@@ -1048,7 +1048,7 @@ void lock_vector_lock(void)
12869 raw_spin_lock(&vector_lock);
12870 }
12871
12872-void unlock_vector_lock(void)
12873+void unlock_vector_lock(void) __releases(vector_lock)
12874 {
12875 raw_spin_unlock(&vector_lock);
12876 }
12877@@ -2379,7 +2379,7 @@ static void ack_apic_edge(struct irq_dat
12878 ack_APIC_irq();
12879 }
12880
12881-atomic_t irq_mis_count;
12882+atomic_unchecked_t irq_mis_count;
12883
12884 /*
12885 * IO-APIC versions below 0x20 don't support EOI register.
12886@@ -2487,7 +2487,7 @@ static void ack_apic_level(struct irq_da
12887 * at the cpu.
12888 */
12889 if (!(v & (1 << (i & 0x1f)))) {
12890- atomic_inc(&irq_mis_count);
12891+ atomic_inc_unchecked(&irq_mis_count);
12892
12893 eoi_ioapic_irq(irq, cfg);
12894 }
12895diff -urNp linux-2.6.39.1/arch/x86/kernel/apm_32.c linux-2.6.39.1/arch/x86/kernel/apm_32.c
12896--- linux-2.6.39.1/arch/x86/kernel/apm_32.c 2011-05-19 00:06:34.000000000 -0400
12897+++ linux-2.6.39.1/arch/x86/kernel/apm_32.c 2011-05-22 19:36:30.000000000 -0400
12898@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
12899 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12900 * even though they are called in protected mode.
12901 */
12902-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12903+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12904 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12905
12906 static const char driver_version[] = "1.16ac"; /* no spaces */
12907@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
12908 BUG_ON(cpu != 0);
12909 gdt = get_cpu_gdt_table(cpu);
12910 save_desc_40 = gdt[0x40 / 8];
12911+
12912+ pax_open_kernel();
12913 gdt[0x40 / 8] = bad_bios_desc;
12914+ pax_close_kernel();
12915
12916 apm_irq_save(flags);
12917 APM_DO_SAVE_SEGS;
12918@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
12919 &call->esi);
12920 APM_DO_RESTORE_SEGS;
12921 apm_irq_restore(flags);
12922+
12923+ pax_open_kernel();
12924 gdt[0x40 / 8] = save_desc_40;
12925+ pax_close_kernel();
12926+
12927 put_cpu();
12928
12929 return call->eax & 0xff;
12930@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void
12931 BUG_ON(cpu != 0);
12932 gdt = get_cpu_gdt_table(cpu);
12933 save_desc_40 = gdt[0x40 / 8];
12934+
12935+ pax_open_kernel();
12936 gdt[0x40 / 8] = bad_bios_desc;
12937+ pax_close_kernel();
12938
12939 apm_irq_save(flags);
12940 APM_DO_SAVE_SEGS;
12941@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void
12942 &call->eax);
12943 APM_DO_RESTORE_SEGS;
12944 apm_irq_restore(flags);
12945+
12946+ pax_open_kernel();
12947 gdt[0x40 / 8] = save_desc_40;
12948+ pax_close_kernel();
12949+
12950 put_cpu();
12951 return error;
12952 }
12953@@ -2351,12 +2365,15 @@ static int __init apm_init(void)
12954 * code to that CPU.
12955 */
12956 gdt = get_cpu_gdt_table(0);
12957+
12958+ pax_open_kernel();
12959 set_desc_base(&gdt[APM_CS >> 3],
12960 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12961 set_desc_base(&gdt[APM_CS_16 >> 3],
12962 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12963 set_desc_base(&gdt[APM_DS >> 3],
12964 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12965+ pax_close_kernel();
12966
12967 proc_create("apm", 0, NULL, &apm_file_ops);
12968
12969diff -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
12970--- linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c 2011-05-19 00:06:34.000000000 -0400
12971+++ linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c 2011-05-22 19:36:30.000000000 -0400
12972@@ -69,6 +69,7 @@ int main(void)
12973 BLANK();
12974 #undef ENTRY
12975
12976+ DEFINE(TSS_size, sizeof(struct tss_struct));
12977 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12978 BLANK();
12979
12980diff -urNp linux-2.6.39.1/arch/x86/kernel/asm-offsets.c linux-2.6.39.1/arch/x86/kernel/asm-offsets.c
12981--- linux-2.6.39.1/arch/x86/kernel/asm-offsets.c 2011-05-19 00:06:34.000000000 -0400
12982+++ linux-2.6.39.1/arch/x86/kernel/asm-offsets.c 2011-05-25 17:35:48.000000000 -0400
12983@@ -33,6 +33,8 @@ void common(void) {
12984 OFFSET(TI_status, thread_info, status);
12985 OFFSET(TI_addr_limit, thread_info, addr_limit);
12986 OFFSET(TI_preempt_count, thread_info, preempt_count);
12987+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12988+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12989
12990 BLANK();
12991 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12992@@ -53,8 +55,26 @@ void common(void) {
12993 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12994 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12995 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12996+
12997+#ifdef CONFIG_PAX_KERNEXEC
12998+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12999+#endif
13000+
13001+#ifdef CONFIG_PAX_MEMORY_UDEREF
13002+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13003+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13004+#ifdef CONFIG_X86_64
13005+ OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
13006+#endif
13007 #endif
13008
13009+#endif
13010+
13011+ BLANK();
13012+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13013+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13014+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13015+
13016 #ifdef CONFIG_XEN
13017 BLANK();
13018 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13019diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/amd.c linux-2.6.39.1/arch/x86/kernel/cpu/amd.c
13020--- linux-2.6.39.1/arch/x86/kernel/cpu/amd.c 2011-06-03 00:04:13.000000000 -0400
13021+++ linux-2.6.39.1/arch/x86/kernel/cpu/amd.c 2011-06-03 00:32:04.000000000 -0400
13022@@ -647,7 +647,7 @@ static unsigned int __cpuinit amd_size_c
13023 unsigned int size)
13024 {
13025 /* AMD errata T13 (order #21922) */
13026- if ((c->x86 == 6)) {
13027+ if (c->x86 == 6) {
13028 /* Duron Rev A0 */
13029 if (c->x86_model == 3 && c->x86_mask == 0)
13030 size = 64;
13031diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/common.c linux-2.6.39.1/arch/x86/kernel/cpu/common.c
13032--- linux-2.6.39.1/arch/x86/kernel/cpu/common.c 2011-06-03 00:04:13.000000000 -0400
13033+++ linux-2.6.39.1/arch/x86/kernel/cpu/common.c 2011-06-03 00:32:04.000000000 -0400
13034@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
13035
13036 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13037
13038-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13039-#ifdef CONFIG_X86_64
13040- /*
13041- * We need valid kernel segments for data and code in long mode too
13042- * IRET will check the segment types kkeil 2000/10/28
13043- * Also sysret mandates a special GDT layout
13044- *
13045- * TLS descriptors are currently at a different place compared to i386.
13046- * Hopefully nobody expects them at a fixed place (Wine?)
13047- */
13048- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13049- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13050- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13051- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13052- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13053- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13054-#else
13055- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13056- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13057- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13058- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13059- /*
13060- * Segments used for calling PnP BIOS have byte granularity.
13061- * They code segments and data segments have fixed 64k limits,
13062- * the transfer segment sizes are set at run time.
13063- */
13064- /* 32-bit code */
13065- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13066- /* 16-bit code */
13067- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13068- /* 16-bit data */
13069- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13070- /* 16-bit data */
13071- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13072- /* 16-bit data */
13073- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13074- /*
13075- * The APM segments have byte granularity and their bases
13076- * are set at run time. All have 64k limits.
13077- */
13078- /* 32-bit code */
13079- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13080- /* 16-bit code */
13081- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13082- /* data */
13083- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13084-
13085- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13086- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13087- GDT_STACK_CANARY_INIT
13088-#endif
13089-} };
13090-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13091-
13092 static int __init x86_xsave_setup(char *s)
13093 {
13094 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13095@@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
13096 {
13097 struct desc_ptr gdt_descr;
13098
13099- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13100+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13101 gdt_descr.size = GDT_SIZE - 1;
13102 load_gdt(&gdt_descr);
13103 /* Reload the per-cpu base */
13104@@ -824,6 +770,10 @@ static void __cpuinit identify_cpu(struc
13105 /* Filter out anything that depends on CPUID levels we don't have */
13106 filter_cpuid_features(c, true);
13107
13108+#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
13109+ setup_clear_cpu_cap(X86_FEATURE_SEP);
13110+#endif
13111+
13112 /* If the model name is still unset, do table lookup. */
13113 if (!c->x86_model_id[0]) {
13114 const char *p;
13115@@ -1003,6 +953,9 @@ static __init int setup_disablecpuid(cha
13116 }
13117 __setup("clearcpuid=", setup_disablecpuid);
13118
13119+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13120+EXPORT_PER_CPU_SYMBOL(current_tinfo);
13121+
13122 #ifdef CONFIG_X86_64
13123 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13124
13125@@ -1018,7 +971,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
13126 EXPORT_PER_CPU_SYMBOL(current_task);
13127
13128 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13129- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13130+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13131 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13132
13133 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13134@@ -1083,7 +1036,7 @@ struct pt_regs * __cpuinit idle_regs(str
13135 {
13136 memset(regs, 0, sizeof(struct pt_regs));
13137 regs->fs = __KERNEL_PERCPU;
13138- regs->gs = __KERNEL_STACK_CANARY;
13139+ savesegment(gs, regs->gs);
13140
13141 return regs;
13142 }
13143@@ -1138,7 +1091,7 @@ void __cpuinit cpu_init(void)
13144 int i;
13145
13146 cpu = stack_smp_processor_id();
13147- t = &per_cpu(init_tss, cpu);
13148+ t = init_tss + cpu;
13149 oist = &per_cpu(orig_ist, cpu);
13150
13151 #ifdef CONFIG_NUMA
13152@@ -1164,7 +1117,7 @@ void __cpuinit cpu_init(void)
13153 switch_to_new_gdt(cpu);
13154 loadsegment(fs, 0);
13155
13156- load_idt((const struct desc_ptr *)&idt_descr);
13157+ load_idt(&idt_descr);
13158
13159 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13160 syscall_init();
13161@@ -1173,7 +1126,6 @@ void __cpuinit cpu_init(void)
13162 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13163 barrier();
13164
13165- x86_configure_nx();
13166 if (cpu != 0)
13167 enable_x2apic();
13168
13169@@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
13170 {
13171 int cpu = smp_processor_id();
13172 struct task_struct *curr = current;
13173- struct tss_struct *t = &per_cpu(init_tss, cpu);
13174+ struct tss_struct *t = init_tss + cpu;
13175 struct thread_struct *thread = &curr->thread;
13176
13177 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13178diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/intel.c linux-2.6.39.1/arch/x86/kernel/cpu/intel.c
13179--- linux-2.6.39.1/arch/x86/kernel/cpu/intel.c 2011-05-19 00:06:34.000000000 -0400
13180+++ linux-2.6.39.1/arch/x86/kernel/cpu/intel.c 2011-05-22 19:36:30.000000000 -0400
13181@@ -161,7 +161,7 @@ static void __cpuinit trap_init_f00f_bug
13182 * Update the IDT descriptor and reload the IDT so that
13183 * it uses the read-only mapped virtual address.
13184 */
13185- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13186+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13187 load_idt(&idt_descr);
13188 }
13189 #endif
13190diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/Makefile linux-2.6.39.1/arch/x86/kernel/cpu/Makefile
13191--- linux-2.6.39.1/arch/x86/kernel/cpu/Makefile 2011-05-19 00:06:34.000000000 -0400
13192+++ linux-2.6.39.1/arch/x86/kernel/cpu/Makefile 2011-05-22 19:36:30.000000000 -0400
13193@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13194 CFLAGS_REMOVE_perf_event.o = -pg
13195 endif
13196
13197-# Make sure load_percpu_segment has no stackprotector
13198-nostackp := $(call cc-option, -fno-stack-protector)
13199-CFLAGS_common.o := $(nostackp)
13200-
13201 obj-y := intel_cacheinfo.o scattered.o topology.o
13202 obj-y += proc.o capflags.o powerflags.o common.o
13203 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13204diff -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
13205--- linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-19 00:06:34.000000000 -0400
13206+++ linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-22 19:36:30.000000000 -0400
13207@@ -46,6 +46,7 @@
13208 #include <asm/ipi.h>
13209 #include <asm/mce.h>
13210 #include <asm/msr.h>
13211+#include <asm/local.h>
13212
13213 #include "mce-internal.h"
13214
13215@@ -220,7 +221,7 @@ static void print_mce(struct mce *m)
13216 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13217 m->cs, m->ip);
13218
13219- if (m->cs == __KERNEL_CS)
13220+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13221 print_symbol("{%s}", m->ip);
13222 pr_cont("\n");
13223 }
13224@@ -244,10 +245,10 @@ static void print_mce(struct mce *m)
13225
13226 #define PANIC_TIMEOUT 5 /* 5 seconds */
13227
13228-static atomic_t mce_paniced;
13229+static atomic_unchecked_t mce_paniced;
13230
13231 static int fake_panic;
13232-static atomic_t mce_fake_paniced;
13233+static atomic_unchecked_t mce_fake_paniced;
13234
13235 /* Panic in progress. Enable interrupts and wait for final IPI */
13236 static void wait_for_panic(void)
13237@@ -271,7 +272,7 @@ static void mce_panic(char *msg, struct
13238 /*
13239 * Make sure only one CPU runs in machine check panic
13240 */
13241- if (atomic_inc_return(&mce_paniced) > 1)
13242+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13243 wait_for_panic();
13244 barrier();
13245
13246@@ -279,7 +280,7 @@ static void mce_panic(char *msg, struct
13247 console_verbose();
13248 } else {
13249 /* Don't log too much for fake panic */
13250- if (atomic_inc_return(&mce_fake_paniced) > 1)
13251+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13252 return;
13253 }
13254 /* First print corrected ones that are still unlogged */
13255@@ -647,7 +648,7 @@ static int mce_timed_out(u64 *t)
13256 * might have been modified by someone else.
13257 */
13258 rmb();
13259- if (atomic_read(&mce_paniced))
13260+ if (atomic_read_unchecked(&mce_paniced))
13261 wait_for_panic();
13262 if (!monarch_timeout)
13263 goto out;
13264@@ -1461,14 +1462,14 @@ void __cpuinit mcheck_cpu_init(struct cp
13265 */
13266
13267 static DEFINE_SPINLOCK(mce_state_lock);
13268-static int open_count; /* #times opened */
13269+static local_t open_count; /* #times opened */
13270 static int open_exclu; /* already open exclusive? */
13271
13272 static int mce_open(struct inode *inode, struct file *file)
13273 {
13274 spin_lock(&mce_state_lock);
13275
13276- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13277+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13278 spin_unlock(&mce_state_lock);
13279
13280 return -EBUSY;
13281@@ -1476,7 +1477,7 @@ static int mce_open(struct inode *inode,
13282
13283 if (file->f_flags & O_EXCL)
13284 open_exclu = 1;
13285- open_count++;
13286+ local_inc(&open_count);
13287
13288 spin_unlock(&mce_state_lock);
13289
13290@@ -1487,7 +1488,7 @@ static int mce_release(struct inode *ino
13291 {
13292 spin_lock(&mce_state_lock);
13293
13294- open_count--;
13295+ local_dec(&open_count);
13296 open_exclu = 0;
13297
13298 spin_unlock(&mce_state_lock);
13299@@ -2174,7 +2175,7 @@ struct dentry *mce_get_debugfs_dir(void)
13300 static void mce_reset(void)
13301 {
13302 cpu_missing = 0;
13303- atomic_set(&mce_fake_paniced, 0);
13304+ atomic_set_unchecked(&mce_fake_paniced, 0);
13305 atomic_set(&mce_executing, 0);
13306 atomic_set(&mce_callin, 0);
13307 atomic_set(&global_nwo, 0);
13308diff -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
13309--- linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c 2011-05-19 00:06:34.000000000 -0400
13310+++ linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c 2011-05-22 19:36:30.000000000 -0400
13311@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13312 u64 size_or_mask, size_and_mask;
13313 static bool mtrr_aps_delayed_init;
13314
13315-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13316+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13317
13318 const struct mtrr_ops *mtrr_if;
13319
13320diff -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
13321--- linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-19 00:06:34.000000000 -0400
13322+++ linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-22 19:36:30.000000000 -0400
13323@@ -12,19 +12,19 @@
13324 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
13325
13326 struct mtrr_ops {
13327- u32 vendor;
13328- u32 use_intel_if;
13329- void (*set)(unsigned int reg, unsigned long base,
13330+ const u32 vendor;
13331+ const u32 use_intel_if;
13332+ void (* const set)(unsigned int reg, unsigned long base,
13333 unsigned long size, mtrr_type type);
13334- void (*set_all)(void);
13335+ void (* const set_all)(void);
13336
13337- void (*get)(unsigned int reg, unsigned long *base,
13338+ void (* const get)(unsigned int reg, unsigned long *base,
13339 unsigned long *size, mtrr_type *type);
13340- int (*get_free_region)(unsigned long base, unsigned long size,
13341+ int (* const get_free_region)(unsigned long base, unsigned long size,
13342 int replace_reg);
13343- int (*validate_add_page)(unsigned long base, unsigned long size,
13344+ int (* const validate_add_page)(unsigned long base, unsigned long size,
13345 unsigned int type);
13346- int (*have_wrcomb)(void);
13347+ int (* const have_wrcomb)(void);
13348 };
13349
13350 extern int generic_get_free_region(unsigned long base, unsigned long size,
13351diff -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
13352--- linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c 2011-05-19 00:06:34.000000000 -0400
13353+++ linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c 2011-05-22 19:36:30.000000000 -0400
13354@@ -774,6 +774,8 @@ static int x86_schedule_events(struct cp
13355 int i, j, w, wmax, num = 0;
13356 struct hw_perf_event *hwc;
13357
13358+ pax_track_stack();
13359+
13360 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
13361
13362 for (i = 0; i < n; i++) {
13363@@ -1878,7 +1880,7 @@ perf_callchain_user(struct perf_callchai
13364 break;
13365
13366 perf_callchain_store(entry, frame.return_address);
13367- fp = frame.next_frame;
13368+ fp = (__force const void __user *)frame.next_frame;
13369 }
13370 }
13371
13372diff -urNp linux-2.6.39.1/arch/x86/kernel/crash.c linux-2.6.39.1/arch/x86/kernel/crash.c
13373--- linux-2.6.39.1/arch/x86/kernel/crash.c 2011-05-19 00:06:34.000000000 -0400
13374+++ linux-2.6.39.1/arch/x86/kernel/crash.c 2011-05-22 19:36:30.000000000 -0400
13375@@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
13376 regs = args->regs;
13377
13378 #ifdef CONFIG_X86_32
13379- if (!user_mode_vm(regs)) {
13380+ if (!user_mode(regs)) {
13381 crash_fixup_ss_esp(&fixed_regs, regs);
13382 regs = &fixed_regs;
13383 }
13384diff -urNp linux-2.6.39.1/arch/x86/kernel/doublefault_32.c linux-2.6.39.1/arch/x86/kernel/doublefault_32.c
13385--- linux-2.6.39.1/arch/x86/kernel/doublefault_32.c 2011-05-19 00:06:34.000000000 -0400
13386+++ linux-2.6.39.1/arch/x86/kernel/doublefault_32.c 2011-05-22 19:36:30.000000000 -0400
13387@@ -11,7 +11,7 @@
13388
13389 #define DOUBLEFAULT_STACKSIZE (1024)
13390 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13391-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13392+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13393
13394 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13395
13396@@ -21,7 +21,7 @@ static void doublefault_fn(void)
13397 unsigned long gdt, tss;
13398
13399 store_gdt(&gdt_desc);
13400- gdt = gdt_desc.address;
13401+ gdt = (unsigned long)gdt_desc.address;
13402
13403 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13404
13405@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
13406 /* 0x2 bit is always set */
13407 .flags = X86_EFLAGS_SF | 0x2,
13408 .sp = STACK_START,
13409- .es = __USER_DS,
13410+ .es = __KERNEL_DS,
13411 .cs = __KERNEL_CS,
13412 .ss = __KERNEL_DS,
13413- .ds = __USER_DS,
13414+ .ds = __KERNEL_DS,
13415 .fs = __KERNEL_PERCPU,
13416
13417 .__cr3 = __pa_nodebug(swapper_pg_dir),
13418diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c
13419--- linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c 2011-05-19 00:06:34.000000000 -0400
13420+++ linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c 2011-05-22 19:36:30.000000000 -0400
13421@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task
13422 bp = stack_frame(task, regs);
13423
13424 for (;;) {
13425- struct thread_info *context;
13426+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13427
13428- context = (struct thread_info *)
13429- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13430- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
13431+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13432
13433- stack = (unsigned long *)context->previous_esp;
13434- if (!stack)
13435+ if (stack_start == task_stack_page(task))
13436 break;
13437+ stack = *(unsigned long **)stack_start;
13438 if (ops->stack(data, "IRQ") < 0)
13439 break;
13440 touch_nmi_watchdog();
13441@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs
13442 * When in-kernel, we also print out the stack and code at the
13443 * time of the fault..
13444 */
13445- if (!user_mode_vm(regs)) {
13446+ if (!user_mode(regs)) {
13447 unsigned int code_prologue = code_bytes * 43 / 64;
13448 unsigned int code_len = code_bytes;
13449 unsigned char c;
13450 u8 *ip;
13451+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13452
13453 printk(KERN_EMERG "Stack:\n");
13454 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
13455
13456 printk(KERN_EMERG "Code: ");
13457
13458- ip = (u8 *)regs->ip - code_prologue;
13459+ ip = (u8 *)regs->ip - code_prologue + cs_base;
13460 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13461 /* try starting at IP */
13462- ip = (u8 *)regs->ip;
13463+ ip = (u8 *)regs->ip + cs_base;
13464 code_len = code_len - code_prologue + 1;
13465 }
13466 for (i = 0; i < code_len; i++, ip++) {
13467@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs
13468 printk(" Bad EIP value.");
13469 break;
13470 }
13471- if (ip == (u8 *)regs->ip)
13472+ if (ip == (u8 *)regs->ip + cs_base)
13473 printk("<%02x> ", c);
13474 else
13475 printk("%02x ", c);
13476@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
13477 {
13478 unsigned short ud2;
13479
13480+ ip = ktla_ktva(ip);
13481 if (ip < PAGE_OFFSET)
13482 return 0;
13483 if (probe_kernel_address((unsigned short *)ip, ud2))
13484diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c
13485--- linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c 2011-05-19 00:06:34.000000000 -0400
13486+++ linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c 2011-05-22 19:36:30.000000000 -0400
13487@@ -147,9 +147,9 @@ void dump_trace(struct task_struct *task
13488 unsigned long *irq_stack_end =
13489 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13490 unsigned used = 0;
13491- struct thread_info *tinfo;
13492 int graph = 0;
13493 unsigned long dummy;
13494+ void *stack_start;
13495
13496 if (!task)
13497 task = current;
13498@@ -167,10 +167,10 @@ void dump_trace(struct task_struct *task
13499 * current stack address. If the stacks consist of nested
13500 * exceptions
13501 */
13502- tinfo = task_thread_info(task);
13503 for (;;) {
13504 char *id;
13505 unsigned long *estack_end;
13506+
13507 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13508 &used, &id);
13509
13510@@ -178,7 +178,7 @@ void dump_trace(struct task_struct *task
13511 if (ops->stack(data, id) < 0)
13512 break;
13513
13514- bp = ops->walk_stack(tinfo, stack, bp, ops,
13515+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13516 data, estack_end, &graph);
13517 ops->stack(data, "<EOE>");
13518 /*
13519@@ -197,7 +197,7 @@ void dump_trace(struct task_struct *task
13520 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
13521 if (ops->stack(data, "IRQ") < 0)
13522 break;
13523- bp = ops->walk_stack(tinfo, stack, bp,
13524+ bp = ops->walk_stack(task, irq_stack, stack, bp,
13525 ops, data, irq_stack_end, &graph);
13526 /*
13527 * We link to the next stack (which would be
13528@@ -218,7 +218,8 @@ void dump_trace(struct task_struct *task
13529 /*
13530 * This handles the process stack:
13531 */
13532- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13533+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13534+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13535 put_cpu();
13536 }
13537 EXPORT_SYMBOL(dump_trace);
13538diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack.c linux-2.6.39.1/arch/x86/kernel/dumpstack.c
13539--- linux-2.6.39.1/arch/x86/kernel/dumpstack.c 2011-05-19 00:06:34.000000000 -0400
13540+++ linux-2.6.39.1/arch/x86/kernel/dumpstack.c 2011-05-22 19:41:32.000000000 -0400
13541@@ -2,6 +2,9 @@
13542 * Copyright (C) 1991, 1992 Linus Torvalds
13543 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13544 */
13545+#ifdef CONFIG_GRKERNSEC_HIDESYM
13546+#define __INCLUDED_BY_HIDESYM 1
13547+#endif
13548 #include <linux/kallsyms.h>
13549 #include <linux/kprobes.h>
13550 #include <linux/uaccess.h>
13551@@ -35,9 +38,8 @@ void printk_address(unsigned long addres
13552 static void
13553 print_ftrace_graph_addr(unsigned long addr, void *data,
13554 const struct stacktrace_ops *ops,
13555- struct thread_info *tinfo, int *graph)
13556+ struct task_struct *task, int *graph)
13557 {
13558- struct task_struct *task = tinfo->task;
13559 unsigned long ret_addr;
13560 int index = task->curr_ret_stack;
13561
13562@@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long ad
13563 static inline void
13564 print_ftrace_graph_addr(unsigned long addr, void *data,
13565 const struct stacktrace_ops *ops,
13566- struct thread_info *tinfo, int *graph)
13567+ struct task_struct *task, int *graph)
13568 { }
13569 #endif
13570
13571@@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long ad
13572 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13573 */
13574
13575-static inline int valid_stack_ptr(struct thread_info *tinfo,
13576- void *p, unsigned int size, void *end)
13577+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13578 {
13579- void *t = tinfo;
13580 if (end) {
13581 if (p < end && p >= (end-THREAD_SIZE))
13582 return 1;
13583@@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct
13584 }
13585
13586 unsigned long
13587-print_context_stack(struct thread_info *tinfo,
13588+print_context_stack(struct task_struct *task, void *stack_start,
13589 unsigned long *stack, unsigned long bp,
13590 const struct stacktrace_ops *ops, void *data,
13591 unsigned long *end, int *graph)
13592 {
13593 struct stack_frame *frame = (struct stack_frame *)bp;
13594
13595- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13596+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13597 unsigned long addr;
13598
13599 addr = *stack;
13600@@ -102,7 +102,7 @@ print_context_stack(struct thread_info *
13601 } else {
13602 ops->address(data, addr, 0);
13603 }
13604- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13605+ print_ftrace_graph_addr(addr, data, ops, task, graph);
13606 }
13607 stack++;
13608 }
13609@@ -111,7 +111,7 @@ print_context_stack(struct thread_info *
13610 EXPORT_SYMBOL_GPL(print_context_stack);
13611
13612 unsigned long
13613-print_context_stack_bp(struct thread_info *tinfo,
13614+print_context_stack_bp(struct task_struct *task, void *stack_start,
13615 unsigned long *stack, unsigned long bp,
13616 const struct stacktrace_ops *ops, void *data,
13617 unsigned long *end, int *graph)
13618@@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_inf
13619 struct stack_frame *frame = (struct stack_frame *)bp;
13620 unsigned long *ret_addr = &frame->return_address;
13621
13622- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13623+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13624 unsigned long addr = *ret_addr;
13625
13626 if (!__kernel_text_address(addr))
13627@@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_inf
13628 ops->address(data, addr, 1);
13629 frame = frame->next_frame;
13630 ret_addr = &frame->return_address;
13631- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13632+ print_ftrace_graph_addr(addr, data, ops, task, graph);
13633 }
13634
13635 return (unsigned long)frame;
13636@@ -202,7 +202,7 @@ void dump_stack(void)
13637
13638 bp = stack_frame(current, NULL);
13639 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13640- current->pid, current->comm, print_tainted(),
13641+ task_pid_nr(current), current->comm, print_tainted(),
13642 init_utsname()->release,
13643 (int)strcspn(init_utsname()->version, " "),
13644 init_utsname()->version);
13645@@ -238,6 +238,8 @@ unsigned __kprobes long oops_begin(void)
13646 }
13647 EXPORT_SYMBOL_GPL(oops_begin);
13648
13649+extern void gr_handle_kernel_exploit(void);
13650+
13651 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13652 {
13653 if (regs && kexec_should_crash(current))
13654@@ -259,7 +261,10 @@ void __kprobes oops_end(unsigned long fl
13655 panic("Fatal exception in interrupt");
13656 if (panic_on_oops)
13657 panic("Fatal exception");
13658- do_exit(signr);
13659+
13660+ gr_handle_kernel_exploit();
13661+
13662+ do_group_exit(signr);
13663 }
13664
13665 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13666@@ -286,7 +291,7 @@ int __kprobes __die(const char *str, str
13667
13668 show_registers(regs);
13669 #ifdef CONFIG_X86_32
13670- if (user_mode_vm(regs)) {
13671+ if (user_mode(regs)) {
13672 sp = regs->sp;
13673 ss = regs->ss & 0xffff;
13674 } else {
13675@@ -314,7 +319,7 @@ void die(const char *str, struct pt_regs
13676 unsigned long flags = oops_begin();
13677 int sig = SIGSEGV;
13678
13679- if (!user_mode_vm(regs))
13680+ if (!user_mode(regs))
13681 report_bug(regs->ip, regs);
13682
13683 if (__die(str, regs, err))
13684diff -urNp linux-2.6.39.1/arch/x86/kernel/early_printk.c linux-2.6.39.1/arch/x86/kernel/early_printk.c
13685--- linux-2.6.39.1/arch/x86/kernel/early_printk.c 2011-05-19 00:06:34.000000000 -0400
13686+++ linux-2.6.39.1/arch/x86/kernel/early_printk.c 2011-05-22 19:36:30.000000000 -0400
13687@@ -7,6 +7,7 @@
13688 #include <linux/pci_regs.h>
13689 #include <linux/pci_ids.h>
13690 #include <linux/errno.h>
13691+#include <linux/sched.h>
13692 #include <asm/io.h>
13693 #include <asm/processor.h>
13694 #include <asm/fcntl.h>
13695@@ -179,6 +180,8 @@ asmlinkage void early_printk(const char
13696 int n;
13697 va_list ap;
13698
13699+ pax_track_stack();
13700+
13701 va_start(ap, fmt);
13702 n = vscnprintf(buf, sizeof(buf), fmt, ap);
13703 early_console->write(early_console, buf, n);
13704diff -urNp linux-2.6.39.1/arch/x86/kernel/entry_32.S linux-2.6.39.1/arch/x86/kernel/entry_32.S
13705--- linux-2.6.39.1/arch/x86/kernel/entry_32.S 2011-05-19 00:06:34.000000000 -0400
13706+++ linux-2.6.39.1/arch/x86/kernel/entry_32.S 2011-05-23 17:07:00.000000000 -0400
13707@@ -185,13 +185,146 @@
13708 /*CFI_REL_OFFSET gs, PT_GS*/
13709 .endm
13710 .macro SET_KERNEL_GS reg
13711+
13712+#ifdef CONFIG_CC_STACKPROTECTOR
13713 movl $(__KERNEL_STACK_CANARY), \reg
13714+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13715+ movl $(__USER_DS), \reg
13716+#else
13717+ xorl \reg, \reg
13718+#endif
13719+
13720 movl \reg, %gs
13721 .endm
13722
13723 #endif /* CONFIG_X86_32_LAZY_GS */
13724
13725-.macro SAVE_ALL
13726+.macro pax_enter_kernel
13727+#ifdef CONFIG_PAX_KERNEXEC
13728+ call pax_enter_kernel
13729+#endif
13730+.endm
13731+
13732+.macro pax_exit_kernel
13733+#ifdef CONFIG_PAX_KERNEXEC
13734+ call pax_exit_kernel
13735+#endif
13736+.endm
13737+
13738+#ifdef CONFIG_PAX_KERNEXEC
13739+ENTRY(pax_enter_kernel)
13740+#ifdef CONFIG_PARAVIRT
13741+ pushl %eax
13742+ pushl %ecx
13743+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13744+ mov %eax, %esi
13745+#else
13746+ mov %cr0, %esi
13747+#endif
13748+ bts $16, %esi
13749+ jnc 1f
13750+ mov %cs, %esi
13751+ cmp $__KERNEL_CS, %esi
13752+ jz 3f
13753+ ljmp $__KERNEL_CS, $3f
13754+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13755+2:
13756+#ifdef CONFIG_PARAVIRT
13757+ mov %esi, %eax
13758+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13759+#else
13760+ mov %esi, %cr0
13761+#endif
13762+3:
13763+#ifdef CONFIG_PARAVIRT
13764+ popl %ecx
13765+ popl %eax
13766+#endif
13767+ ret
13768+ENDPROC(pax_enter_kernel)
13769+
13770+ENTRY(pax_exit_kernel)
13771+#ifdef CONFIG_PARAVIRT
13772+ pushl %eax
13773+ pushl %ecx
13774+#endif
13775+ mov %cs, %esi
13776+ cmp $__KERNEXEC_KERNEL_CS, %esi
13777+ jnz 2f
13778+#ifdef CONFIG_PARAVIRT
13779+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13780+ mov %eax, %esi
13781+#else
13782+ mov %cr0, %esi
13783+#endif
13784+ btr $16, %esi
13785+ ljmp $__KERNEL_CS, $1f
13786+1:
13787+#ifdef CONFIG_PARAVIRT
13788+ mov %esi, %eax
13789+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13790+#else
13791+ mov %esi, %cr0
13792+#endif
13793+2:
13794+#ifdef CONFIG_PARAVIRT
13795+ popl %ecx
13796+ popl %eax
13797+#endif
13798+ ret
13799+ENDPROC(pax_exit_kernel)
13800+#endif
13801+
13802+.macro pax_erase_kstack
13803+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13804+ call pax_erase_kstack
13805+#endif
13806+.endm
13807+
13808+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13809+/*
13810+ * ebp: thread_info
13811+ * ecx, edx: can be clobbered
13812+ */
13813+ENTRY(pax_erase_kstack)
13814+ pushl %edi
13815+ pushl %eax
13816+
13817+ mov TI_lowest_stack(%ebp), %edi
13818+ mov $-0xBEEF, %eax
13819+ std
13820+
13821+1: mov %edi, %ecx
13822+ and $THREAD_SIZE_asm - 1, %ecx
13823+ shr $2, %ecx
13824+ repne scasl
13825+ jecxz 2f
13826+
13827+ cmp $2*16, %ecx
13828+ jc 2f
13829+
13830+ mov $2*16, %ecx
13831+ repe scasl
13832+ jecxz 2f
13833+ jne 1b
13834+
13835+2: cld
13836+ mov %esp, %ecx
13837+ sub %edi, %ecx
13838+ shr $2, %ecx
13839+ rep stosl
13840+
13841+ mov TI_task_thread_sp0(%ebp), %edi
13842+ sub $128, %edi
13843+ mov %edi, TI_lowest_stack(%ebp)
13844+
13845+ popl %eax
13846+ popl %edi
13847+ ret
13848+ENDPROC(pax_erase_kstack)
13849+#endif
13850+
13851+.macro __SAVE_ALL _DS
13852 cld
13853 PUSH_GS
13854 pushl_cfi %fs
13855@@ -214,7 +347,7 @@
13856 CFI_REL_OFFSET ecx, 0
13857 pushl_cfi %ebx
13858 CFI_REL_OFFSET ebx, 0
13859- movl $(__USER_DS), %edx
13860+ movl $\_DS, %edx
13861 movl %edx, %ds
13862 movl %edx, %es
13863 movl $(__KERNEL_PERCPU), %edx
13864@@ -222,6 +355,15 @@
13865 SET_KERNEL_GS %edx
13866 .endm
13867
13868+.macro SAVE_ALL
13869+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13870+ __SAVE_ALL __KERNEL_DS
13871+ pax_enter_kernel
13872+#else
13873+ __SAVE_ALL __USER_DS
13874+#endif
13875+.endm
13876+
13877 .macro RESTORE_INT_REGS
13878 popl_cfi %ebx
13879 CFI_RESTORE ebx
13880@@ -332,7 +474,15 @@ check_userspace:
13881 movb PT_CS(%esp), %al
13882 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13883 cmpl $USER_RPL, %eax
13884+
13885+#ifdef CONFIG_PAX_KERNEXEC
13886+ jae resume_userspace
13887+
13888+ PAX_EXIT_KERNEL
13889+ jmp resume_kernel
13890+#else
13891 jb resume_kernel # not returning to v8086 or userspace
13892+#endif
13893
13894 ENTRY(resume_userspace)
13895 LOCKDEP_SYS_EXIT
13896@@ -344,7 +494,7 @@ ENTRY(resume_userspace)
13897 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13898 # int/exception return?
13899 jne work_pending
13900- jmp restore_all
13901+ jmp restore_all_pax
13902 END(ret_from_exception)
13903
13904 #ifdef CONFIG_PREEMPT
13905@@ -394,23 +544,34 @@ sysenter_past_esp:
13906 /*CFI_REL_OFFSET cs, 0*/
13907 /*
13908 * Push current_thread_info()->sysenter_return to the stack.
13909- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13910- * pushed above; +8 corresponds to copy_thread's esp0 setting.
13911 */
13912- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13913+ pushl_cfi $0
13914 CFI_REL_OFFSET eip, 0
13915
13916 pushl_cfi %eax
13917 SAVE_ALL
13918+ GET_THREAD_INFO(%ebp)
13919+ movl TI_sysenter_return(%ebp),%ebp
13920+ movl %ebp,PT_EIP(%esp)
13921 ENABLE_INTERRUPTS(CLBR_NONE)
13922
13923 /*
13924 * Load the potential sixth argument from user stack.
13925 * Careful about security.
13926 */
13927+ movl PT_OLDESP(%esp),%ebp
13928+
13929+#ifdef CONFIG_PAX_MEMORY_UDEREF
13930+ mov PT_OLDSS(%esp),%ds
13931+1: movl %ds:(%ebp),%ebp
13932+ push %ss
13933+ pop %ds
13934+#else
13935 cmpl $__PAGE_OFFSET-3,%ebp
13936 jae syscall_fault
13937 1: movl (%ebp),%ebp
13938+#endif
13939+
13940 movl %ebp,PT_EBP(%esp)
13941 .section __ex_table,"a"
13942 .align 4
13943@@ -433,12 +594,23 @@ sysenter_do_call:
13944 testl $_TIF_ALLWORK_MASK, %ecx
13945 jne sysexit_audit
13946 sysenter_exit:
13947+
13948+#ifdef CONFIG_PAX_RANDKSTACK
13949+ pushl_cfi %eax
13950+ call pax_randomize_kstack
13951+ popl_cfi %eax
13952+#endif
13953+
13954+ pax_erase_kstack
13955+
13956 /* if something modifies registers it must also disable sysexit */
13957 movl PT_EIP(%esp), %edx
13958 movl PT_OLDESP(%esp), %ecx
13959 xorl %ebp,%ebp
13960 TRACE_IRQS_ON
13961 1: mov PT_FS(%esp), %fs
13962+2: mov PT_DS(%esp), %ds
13963+3: mov PT_ES(%esp), %es
13964 PTGS_TO_GS
13965 ENABLE_INTERRUPTS_SYSEXIT
13966
13967@@ -455,6 +627,9 @@ sysenter_audit:
13968 movl %eax,%edx /* 2nd arg: syscall number */
13969 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13970 call audit_syscall_entry
13971+
13972+ pax_erase_kstack
13973+
13974 pushl_cfi %ebx
13975 movl PT_EAX(%esp),%eax /* reload syscall number */
13976 jmp sysenter_do_call
13977@@ -481,11 +656,17 @@ sysexit_audit:
13978
13979 CFI_ENDPROC
13980 .pushsection .fixup,"ax"
13981-2: movl $0,PT_FS(%esp)
13982+4: movl $0,PT_FS(%esp)
13983+ jmp 1b
13984+5: movl $0,PT_DS(%esp)
13985+ jmp 1b
13986+6: movl $0,PT_ES(%esp)
13987 jmp 1b
13988 .section __ex_table,"a"
13989 .align 4
13990- .long 1b,2b
13991+ .long 1b,4b
13992+ .long 2b,5b
13993+ .long 3b,6b
13994 .popsection
13995 PTGS_TO_GS_EX
13996 ENDPROC(ia32_sysenter_target)
13997@@ -518,6 +699,14 @@ syscall_exit:
13998 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13999 jne syscall_exit_work
14000
14001+restore_all_pax:
14002+
14003+#ifdef CONFIG_PAX_RANDKSTACK
14004+ call pax_randomize_kstack
14005+#endif
14006+
14007+ pax_erase_kstack
14008+
14009 restore_all:
14010 TRACE_IRQS_IRET
14011 restore_all_notrace:
14012@@ -577,14 +766,21 @@ ldt_ss:
14013 * compensating for the offset by changing to the ESPFIX segment with
14014 * a base address that matches for the difference.
14015 */
14016-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14017+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14018 mov %esp, %edx /* load kernel esp */
14019 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14020 mov %dx, %ax /* eax: new kernel esp */
14021 sub %eax, %edx /* offset (low word is 0) */
14022+#ifdef CONFIG_SMP
14023+ movl PER_CPU_VAR(cpu_number), %ebx
14024+ shll $PAGE_SHIFT_asm, %ebx
14025+ addl $cpu_gdt_table, %ebx
14026+#else
14027+ movl $cpu_gdt_table, %ebx
14028+#endif
14029 shr $16, %edx
14030- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14031- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14032+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14033+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14034 pushl_cfi $__ESPFIX_SS
14035 pushl_cfi %eax /* new kernel esp */
14036 /* Disable interrupts, but do not irqtrace this section: we
14037@@ -613,29 +809,23 @@ work_resched:
14038 movl TI_flags(%ebp), %ecx
14039 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14040 # than syscall tracing?
14041- jz restore_all
14042+ jz restore_all_pax
14043 testb $_TIF_NEED_RESCHED, %cl
14044 jnz work_resched
14045
14046 work_notifysig: # deal with pending signals and
14047 # notify-resume requests
14048+ movl %esp, %eax
14049 #ifdef CONFIG_VM86
14050 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14051- movl %esp, %eax
14052- jne work_notifysig_v86 # returning to kernel-space or
14053+ jz 1f # returning to kernel-space or
14054 # vm86-space
14055- xorl %edx, %edx
14056- call do_notify_resume
14057- jmp resume_userspace_sig
14058
14059- ALIGN
14060-work_notifysig_v86:
14061 pushl_cfi %ecx # save ti_flags for do_notify_resume
14062 call save_v86_state # %eax contains pt_regs pointer
14063 popl_cfi %ecx
14064 movl %eax, %esp
14065-#else
14066- movl %esp, %eax
14067+1:
14068 #endif
14069 xorl %edx, %edx
14070 call do_notify_resume
14071@@ -648,6 +838,9 @@ syscall_trace_entry:
14072 movl $-ENOSYS,PT_EAX(%esp)
14073 movl %esp, %eax
14074 call syscall_trace_enter
14075+
14076+ pax_erase_kstack
14077+
14078 /* What it returned is what we'll actually use. */
14079 cmpl $(nr_syscalls), %eax
14080 jnae syscall_call
14081@@ -670,6 +863,10 @@ END(syscall_exit_work)
14082
14083 RING0_INT_FRAME # can't unwind into user space anyway
14084 syscall_fault:
14085+#ifdef CONFIG_PAX_MEMORY_UDEREF
14086+ push %ss
14087+ pop %ds
14088+#endif
14089 GET_THREAD_INFO(%ebp)
14090 movl $-EFAULT,PT_EAX(%esp)
14091 jmp resume_userspace
14092@@ -752,6 +949,36 @@ ptregs_clone:
14093 CFI_ENDPROC
14094 ENDPROC(ptregs_clone)
14095
14096+ ALIGN;
14097+ENTRY(kernel_execve)
14098+ CFI_STARTPROC
14099+ pushl_cfi %ebp
14100+ sub $PT_OLDSS+4,%esp
14101+ pushl_cfi %edi
14102+ pushl_cfi %ecx
14103+ pushl_cfi %eax
14104+ lea 3*4(%esp),%edi
14105+ mov $PT_OLDSS/4+1,%ecx
14106+ xorl %eax,%eax
14107+ rep stosl
14108+ popl_cfi %eax
14109+ popl_cfi %ecx
14110+ popl_cfi %edi
14111+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14112+ pushl_cfi %esp
14113+ call sys_execve
14114+ add $4,%esp
14115+ CFI_ADJUST_CFA_OFFSET -4
14116+ GET_THREAD_INFO(%ebp)
14117+ test %eax,%eax
14118+ jz syscall_exit
14119+ add $PT_OLDSS+4,%esp
14120+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14121+ popl_cfi %ebp
14122+ ret
14123+ CFI_ENDPROC
14124+ENDPROC(kernel_execve)
14125+
14126 .macro FIXUP_ESPFIX_STACK
14127 /*
14128 * Switch back for ESPFIX stack to the normal zerobased stack
14129@@ -761,8 +988,15 @@ ENDPROC(ptregs_clone)
14130 * normal stack and adjusts ESP with the matching offset.
14131 */
14132 /* fixup the stack */
14133- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14134- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14135+#ifdef CONFIG_SMP
14136+ movl PER_CPU_VAR(cpu_number), %ebx
14137+ shll $PAGE_SHIFT_asm, %ebx
14138+ addl $cpu_gdt_table, %ebx
14139+#else
14140+ movl $cpu_gdt_table, %ebx
14141+#endif
14142+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14143+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14144 shl $16, %eax
14145 addl %esp, %eax /* the adjusted stack pointer */
14146 pushl_cfi $__KERNEL_DS
14147@@ -1213,7 +1447,6 @@ return_to_handler:
14148 jmp *%ecx
14149 #endif
14150
14151-.section .rodata,"a"
14152 #include "syscall_table_32.S"
14153
14154 syscall_table_size=(.-sys_call_table)
14155@@ -1259,9 +1492,12 @@ error_code:
14156 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14157 REG_TO_PTGS %ecx
14158 SET_KERNEL_GS %ecx
14159- movl $(__USER_DS), %ecx
14160+ movl $(__KERNEL_DS), %ecx
14161 movl %ecx, %ds
14162 movl %ecx, %es
14163+
14164+ pax_enter_kernel
14165+
14166 TRACE_IRQS_OFF
14167 movl %esp,%eax # pt_regs pointer
14168 call *%edi
14169@@ -1346,6 +1582,9 @@ nmi_stack_correct:
14170 xorl %edx,%edx # zero error code
14171 movl %esp,%eax # pt_regs pointer
14172 call do_nmi
14173+
14174+ pax_exit_kernel
14175+
14176 jmp restore_all_notrace
14177 CFI_ENDPROC
14178
14179@@ -1382,6 +1621,9 @@ nmi_espfix_stack:
14180 FIXUP_ESPFIX_STACK # %eax == %esp
14181 xorl %edx,%edx # zero error code
14182 call do_nmi
14183+
14184+ pax_exit_kernel
14185+
14186 RESTORE_REGS
14187 lss 12+4(%esp), %esp # back to espfix stack
14188 CFI_ADJUST_CFA_OFFSET -24
14189diff -urNp linux-2.6.39.1/arch/x86/kernel/entry_64.S linux-2.6.39.1/arch/x86/kernel/entry_64.S
14190--- linux-2.6.39.1/arch/x86/kernel/entry_64.S 2011-05-19 00:06:34.000000000 -0400
14191+++ linux-2.6.39.1/arch/x86/kernel/entry_64.S 2011-05-23 17:10:49.000000000 -0400
14192@@ -53,6 +53,7 @@
14193 #include <asm/paravirt.h>
14194 #include <asm/ftrace.h>
14195 #include <asm/percpu.h>
14196+#include <asm/pgtable.h>
14197
14198 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14199 #include <linux/elf-em.h>
14200@@ -176,6 +177,259 @@ ENTRY(native_usergs_sysret64)
14201 ENDPROC(native_usergs_sysret64)
14202 #endif /* CONFIG_PARAVIRT */
14203
14204+ .macro ljmpq sel, off
14205+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14206+ .byte 0x48; ljmp *1234f(%rip)
14207+ .pushsection .rodata
14208+ .align 16
14209+ 1234: .quad \off; .word \sel
14210+ .popsection
14211+#else
14212+ pushq $\sel
14213+ pushq $\off
14214+ lretq
14215+#endif
14216+ .endm
14217+
14218+ .macro pax_enter_kernel
14219+#ifdef CONFIG_PAX_KERNEXEC
14220+ call pax_enter_kernel
14221+#endif
14222+ .endm
14223+
14224+ .macro pax_exit_kernel
14225+#ifdef CONFIG_PAX_KERNEXEC
14226+ call pax_exit_kernel
14227+#endif
14228+ .endm
14229+
14230+#ifdef CONFIG_PAX_KERNEXEC
14231+ENTRY(pax_enter_kernel)
14232+ pushq %rdi
14233+
14234+#ifdef CONFIG_PARAVIRT
14235+ PV_SAVE_REGS(CLBR_RDI)
14236+#endif
14237+
14238+ GET_CR0_INTO_RDI
14239+ bts $16,%rdi
14240+ jnc 1f
14241+ mov %cs,%edi
14242+ cmp $__KERNEL_CS,%edi
14243+ jz 3f
14244+ ljmpq __KERNEL_CS,3f
14245+1: ljmpq __KERNEXEC_KERNEL_CS,2f
14246+2: SET_RDI_INTO_CR0
14247+3:
14248+
14249+#ifdef CONFIG_PARAVIRT
14250+ PV_RESTORE_REGS(CLBR_RDI)
14251+#endif
14252+
14253+ popq %rdi
14254+ retq
14255+ENDPROC(pax_enter_kernel)
14256+
14257+ENTRY(pax_exit_kernel)
14258+ pushq %rdi
14259+
14260+#ifdef CONFIG_PARAVIRT
14261+ PV_SAVE_REGS(CLBR_RDI)
14262+#endif
14263+
14264+ mov %cs,%rdi
14265+ cmp $__KERNEXEC_KERNEL_CS,%edi
14266+ jnz 2f
14267+ GET_CR0_INTO_RDI
14268+ btr $16,%rdi
14269+ ljmpq __KERNEL_CS,1f
14270+1: SET_RDI_INTO_CR0
14271+2:
14272+
14273+#ifdef CONFIG_PARAVIRT
14274+ PV_RESTORE_REGS(CLBR_RDI);
14275+#endif
14276+
14277+ popq %rdi
14278+ retq
14279+ENDPROC(pax_exit_kernel)
14280+#endif
14281+
14282+ .macro pax_enter_kernel_user
14283+#ifdef CONFIG_PAX_MEMORY_UDEREF
14284+ call pax_enter_kernel_user
14285+#endif
14286+ .endm
14287+
14288+ .macro pax_exit_kernel_user
14289+#ifdef CONFIG_PAX_MEMORY_UDEREF
14290+ call pax_exit_kernel_user
14291+#endif
14292+#ifdef CONFIG_PAX_RANDKSTACK
14293+ push %rax
14294+ call pax_randomize_kstack
14295+ pop %rax
14296+#endif
14297+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14298+ call pax_erase_kstack
14299+#endif
14300+ .endm
14301+
14302+#ifdef CONFIG_PAX_MEMORY_UDEREF
14303+ENTRY(pax_enter_kernel_user)
14304+ pushq %rdi
14305+ pushq %rbx
14306+
14307+#ifdef CONFIG_PARAVIRT
14308+ PV_SAVE_REGS(CLBR_RDI)
14309+#endif
14310+
14311+ GET_CR3_INTO_RDI
14312+ mov %rdi,%rbx
14313+ add $__START_KERNEL_map,%rbx
14314+ sub phys_base(%rip),%rbx
14315+
14316+#ifdef CONFIG_PARAVIRT
14317+ pushq %rdi
14318+ cmpl $0, pv_info+PARAVIRT_enabled
14319+ jz 1f
14320+ i = 0
14321+ .rept USER_PGD_PTRS
14322+ mov i*8(%rbx),%rsi
14323+ mov $0,%sil
14324+ lea i*8(%rbx),%rdi
14325+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14326+ i = i + 1
14327+ .endr
14328+ jmp 2f
14329+1:
14330+#endif
14331+
14332+ i = 0
14333+ .rept USER_PGD_PTRS
14334+ movb $0,i*8(%rbx)
14335+ i = i + 1
14336+ .endr
14337+
14338+#ifdef CONFIG_PARAVIRT
14339+2: popq %rdi
14340+#endif
14341+ SET_RDI_INTO_CR3
14342+
14343+#ifdef CONFIG_PAX_KERNEXEC
14344+ GET_CR0_INTO_RDI
14345+ bts $16,%rdi
14346+ SET_RDI_INTO_CR0
14347+#endif
14348+
14349+#ifdef CONFIG_PARAVIRT
14350+ PV_RESTORE_REGS(CLBR_RDI)
14351+#endif
14352+
14353+ popq %rbx
14354+ popq %rdi
14355+ retq
14356+ENDPROC(pax_enter_kernel_user)
14357+
14358+ENTRY(pax_exit_kernel_user)
14359+ push %rdi
14360+
14361+#ifdef CONFIG_PARAVIRT
14362+ pushq %rbx
14363+ PV_SAVE_REGS(CLBR_RDI)
14364+#endif
14365+
14366+#ifdef CONFIG_PAX_KERNEXEC
14367+ GET_CR0_INTO_RDI
14368+ btr $16,%rdi
14369+ SET_RDI_INTO_CR0
14370+#endif
14371+
14372+ GET_CR3_INTO_RDI
14373+ add $__START_KERNEL_map,%rdi
14374+ sub phys_base(%rip),%rdi
14375+
14376+#ifdef CONFIG_PARAVIRT
14377+ cmpl $0, pv_info+PARAVIRT_enabled
14378+ jz 1f
14379+ mov %rdi,%rbx
14380+ i = 0
14381+ .rept USER_PGD_PTRS
14382+ mov i*8(%rbx),%rsi
14383+ mov $0x67,%sil
14384+ lea i*8(%rbx),%rdi
14385+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14386+ i = i + 1
14387+ .endr
14388+ jmp 2f
14389+1:
14390+#endif
14391+
14392+ i = 0
14393+ .rept USER_PGD_PTRS
14394+ movb $0x67,i*8(%rdi)
14395+ i = i + 1
14396+ .endr
14397+
14398+#ifdef CONFIG_PARAVIRT
14399+2: PV_RESTORE_REGS(CLBR_RDI)
14400+ popq %rbx
14401+#endif
14402+
14403+ popq %rdi
14404+ retq
14405+ENDPROC(pax_exit_kernel_user)
14406+#endif
14407+
14408+ .macro pax_erase_kstack
14409+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14410+ call pax_erase_kstack
14411+#endif
14412+ .endm
14413+
14414+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14415+/*
14416+ * r10: thread_info
14417+ * rcx, rdx: can be clobbered
14418+ */
14419+ENTRY(pax_erase_kstack)
14420+ pushq %rdi
14421+ pushq %rax
14422+
14423+ GET_THREAD_INFO(%r10)
14424+ mov TI_lowest_stack(%r10), %rdi
14425+ mov $-0xBEEF, %rax
14426+ std
14427+
14428+1: mov %edi, %ecx
14429+ and $THREAD_SIZE_asm - 1, %ecx
14430+ shr $3, %ecx
14431+ repne scasq
14432+ jecxz 2f
14433+
14434+ cmp $2*8, %ecx
14435+ jc 2f
14436+
14437+ mov $2*8, %ecx
14438+ repe scasq
14439+ jecxz 2f
14440+ jne 1b
14441+
14442+2: cld
14443+ mov %esp, %ecx
14444+ sub %edi, %ecx
14445+ shr $3, %ecx
14446+ rep stosq
14447+
14448+ mov TI_task_thread_sp0(%r10), %rdi
14449+ sub $256, %rdi
14450+ mov %rdi, TI_lowest_stack(%r10)
14451+
14452+ popq %rax
14453+ popq %rdi
14454+ ret
14455+ENDPROC(pax_erase_kstack)
14456+#endif
14457
14458 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14459 #ifdef CONFIG_TRACE_IRQFLAGS
14460@@ -318,7 +572,7 @@ ENTRY(save_args)
14461 leaq -RBP+8(%rsp),%rdi /* arg1 for handler */
14462 movq_cfi rbp, 8 /* push %rbp */
14463 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
14464- testl $3, CS(%rdi)
14465+ testb $3, CS(%rdi)
14466 je 1f
14467 SWAPGS
14468 /*
14469@@ -409,7 +663,7 @@ ENTRY(ret_from_fork)
14470
14471 RESTORE_REST
14472
14473- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14474+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14475 je int_ret_from_sys_call
14476
14477 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14478@@ -455,7 +709,7 @@ END(ret_from_fork)
14479 ENTRY(system_call)
14480 CFI_STARTPROC simple
14481 CFI_SIGNAL_FRAME
14482- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14483+ CFI_DEF_CFA rsp,0
14484 CFI_REGISTER rip,rcx
14485 /*CFI_REGISTER rflags,r11*/
14486 SWAPGS_UNSAFE_STACK
14487@@ -468,12 +722,13 @@ ENTRY(system_call_after_swapgs)
14488
14489 movq %rsp,PER_CPU_VAR(old_rsp)
14490 movq PER_CPU_VAR(kernel_stack),%rsp
14491+ pax_enter_kernel_user
14492 /*
14493 * No need to follow this irqs off/on section - it's straight
14494 * and short:
14495 */
14496 ENABLE_INTERRUPTS(CLBR_NONE)
14497- SAVE_ARGS 8,1
14498+ SAVE_ARGS 8*6,1
14499 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14500 movq %rcx,RIP-ARGOFFSET(%rsp)
14501 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14502@@ -502,6 +757,7 @@ sysret_check:
14503 andl %edi,%edx
14504 jnz sysret_careful
14505 CFI_REMEMBER_STATE
14506+ pax_exit_kernel_user
14507 /*
14508 * sysretq will re-enable interrupts:
14509 */
14510@@ -560,6 +816,9 @@ auditsys:
14511 movq %rax,%rsi /* 2nd arg: syscall number */
14512 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14513 call audit_syscall_entry
14514+
14515+ pax_erase_kstack
14516+
14517 LOAD_ARGS 0 /* reload call-clobbered registers */
14518 jmp system_call_fastpath
14519
14520@@ -590,6 +849,9 @@ tracesys:
14521 FIXUP_TOP_OF_STACK %rdi
14522 movq %rsp,%rdi
14523 call syscall_trace_enter
14524+
14525+ pax_erase_kstack
14526+
14527 /*
14528 * Reload arg registers from stack in case ptrace changed them.
14529 * We don't reload %rax because syscall_trace_enter() returned
14530@@ -611,7 +873,7 @@ tracesys:
14531 GLOBAL(int_ret_from_sys_call)
14532 DISABLE_INTERRUPTS(CLBR_NONE)
14533 TRACE_IRQS_OFF
14534- testl $3,CS-ARGOFFSET(%rsp)
14535+ testb $3,CS-ARGOFFSET(%rsp)
14536 je retint_restore_args
14537 movl $_TIF_ALLWORK_MASK,%edi
14538 /* edi: mask to check */
14539@@ -793,6 +1055,16 @@ END(interrupt)
14540 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14541 call save_args
14542 PARTIAL_FRAME 0
14543+#ifdef CONFIG_PAX_MEMORY_UDEREF
14544+ testb $3, CS(%rdi)
14545+ jnz 1f
14546+ pax_enter_kernel
14547+ jmp 2f
14548+1: pax_enter_kernel_user
14549+2:
14550+#else
14551+ pax_enter_kernel
14552+#endif
14553 call \func
14554 .endm
14555
14556@@ -825,7 +1097,7 @@ ret_from_intr:
14557 CFI_ADJUST_CFA_OFFSET -8
14558 exit_intr:
14559 GET_THREAD_INFO(%rcx)
14560- testl $3,CS-ARGOFFSET(%rsp)
14561+ testb $3,CS-ARGOFFSET(%rsp)
14562 je retint_kernel
14563
14564 /* Interrupt came from user space */
14565@@ -847,12 +1119,14 @@ retint_swapgs: /* return to user-space
14566 * The iretq could re-enable interrupts:
14567 */
14568 DISABLE_INTERRUPTS(CLBR_ANY)
14569+ pax_exit_kernel_user
14570 TRACE_IRQS_IRETQ
14571 SWAPGS
14572 jmp restore_args
14573
14574 retint_restore_args: /* return to kernel space */
14575 DISABLE_INTERRUPTS(CLBR_ANY)
14576+ pax_exit_kernel
14577 /*
14578 * The iretq could re-enable interrupts:
14579 */
14580@@ -1027,6 +1301,16 @@ ENTRY(\sym)
14581 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14582 call error_entry
14583 DEFAULT_FRAME 0
14584+#ifdef CONFIG_PAX_MEMORY_UDEREF
14585+ testb $3, CS(%rsp)
14586+ jnz 1f
14587+ pax_enter_kernel
14588+ jmp 2f
14589+1: pax_enter_kernel_user
14590+2:
14591+#else
14592+ pax_enter_kernel
14593+#endif
14594 movq %rsp,%rdi /* pt_regs pointer */
14595 xorl %esi,%esi /* no error code */
14596 call \do_sym
14597@@ -1044,6 +1328,16 @@ ENTRY(\sym)
14598 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14599 call save_paranoid
14600 TRACE_IRQS_OFF
14601+#ifdef CONFIG_PAX_MEMORY_UDEREF
14602+ testb $3, CS(%rsp)
14603+ jnz 1f
14604+ pax_enter_kernel
14605+ jmp 2f
14606+1: pax_enter_kernel_user
14607+2:
14608+#else
14609+ pax_enter_kernel
14610+#endif
14611 movq %rsp,%rdi /* pt_regs pointer */
14612 xorl %esi,%esi /* no error code */
14613 call \do_sym
14614@@ -1052,7 +1346,7 @@ ENTRY(\sym)
14615 END(\sym)
14616 .endm
14617
14618-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14619+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14620 .macro paranoidzeroentry_ist sym do_sym ist
14621 ENTRY(\sym)
14622 INTR_FRAME
14623@@ -1062,8 +1356,24 @@ ENTRY(\sym)
14624 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14625 call save_paranoid
14626 TRACE_IRQS_OFF
14627+#ifdef CONFIG_PAX_MEMORY_UDEREF
14628+ testb $3, CS(%rsp)
14629+ jnz 1f
14630+ pax_enter_kernel
14631+ jmp 2f
14632+1: pax_enter_kernel_user
14633+2:
14634+#else
14635+ pax_enter_kernel
14636+#endif
14637 movq %rsp,%rdi /* pt_regs pointer */
14638 xorl %esi,%esi /* no error code */
14639+#ifdef CONFIG_SMP
14640+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14641+ lea init_tss(%r12), %r12
14642+#else
14643+ lea init_tss(%rip), %r12
14644+#endif
14645 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14646 call \do_sym
14647 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14648@@ -1080,6 +1390,16 @@ ENTRY(\sym)
14649 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14650 call error_entry
14651 DEFAULT_FRAME 0
14652+#ifdef CONFIG_PAX_MEMORY_UDEREF
14653+ testb $3, CS(%rsp)
14654+ jnz 1f
14655+ pax_enter_kernel
14656+ jmp 2f
14657+1: pax_enter_kernel_user
14658+2:
14659+#else
14660+ pax_enter_kernel
14661+#endif
14662 movq %rsp,%rdi /* pt_regs pointer */
14663 movq ORIG_RAX(%rsp),%rsi /* get error code */
14664 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14665@@ -1099,6 +1419,16 @@ ENTRY(\sym)
14666 call save_paranoid
14667 DEFAULT_FRAME 0
14668 TRACE_IRQS_OFF
14669+#ifdef CONFIG_PAX_MEMORY_UDEREF
14670+ testb $3, CS(%rsp)
14671+ jnz 1f
14672+ pax_enter_kernel
14673+ jmp 2f
14674+1: pax_enter_kernel_user
14675+2:
14676+#else
14677+ pax_enter_kernel
14678+#endif
14679 movq %rsp,%rdi /* pt_regs pointer */
14680 movq ORIG_RAX(%rsp),%rsi /* get error code */
14681 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14682@@ -1361,14 +1691,27 @@ ENTRY(paranoid_exit)
14683 TRACE_IRQS_OFF
14684 testl %ebx,%ebx /* swapgs needed? */
14685 jnz paranoid_restore
14686- testl $3,CS(%rsp)
14687+ testb $3,CS(%rsp)
14688 jnz paranoid_userspace
14689+#ifdef CONFIG_PAX_MEMORY_UDEREF
14690+ pax_exit_kernel
14691+ TRACE_IRQS_IRETQ 0
14692+ SWAPGS_UNSAFE_STACK
14693+ RESTORE_ALL 8
14694+ jmp irq_return
14695+#endif
14696 paranoid_swapgs:
14697+#ifdef CONFIG_PAX_MEMORY_UDEREF
14698+ pax_exit_kernel_user
14699+#else
14700+ pax_exit_kernel
14701+#endif
14702 TRACE_IRQS_IRETQ 0
14703 SWAPGS_UNSAFE_STACK
14704 RESTORE_ALL 8
14705 jmp irq_return
14706 paranoid_restore:
14707+ pax_exit_kernel
14708 TRACE_IRQS_IRETQ 0
14709 RESTORE_ALL 8
14710 jmp irq_return
14711@@ -1426,7 +1769,7 @@ ENTRY(error_entry)
14712 movq_cfi r14, R14+8
14713 movq_cfi r15, R15+8
14714 xorl %ebx,%ebx
14715- testl $3,CS+8(%rsp)
14716+ testb $3,CS+8(%rsp)
14717 je error_kernelspace
14718 error_swapgs:
14719 SWAPGS
14720@@ -1490,6 +1833,16 @@ ENTRY(nmi)
14721 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14722 call save_paranoid
14723 DEFAULT_FRAME 0
14724+#ifdef CONFIG_PAX_MEMORY_UDEREF
14725+ testb $3, CS(%rsp)
14726+ jnz 1f
14727+ pax_enter_kernel
14728+ jmp 2f
14729+1: pax_enter_kernel_user
14730+2:
14731+#else
14732+ pax_enter_kernel
14733+#endif
14734 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14735 movq %rsp,%rdi
14736 movq $-1,%rsi
14737@@ -1500,11 +1853,25 @@ ENTRY(nmi)
14738 DISABLE_INTERRUPTS(CLBR_NONE)
14739 testl %ebx,%ebx /* swapgs needed? */
14740 jnz nmi_restore
14741- testl $3,CS(%rsp)
14742+ testb $3,CS(%rsp)
14743 jnz nmi_userspace
14744+#ifdef CONFIG_PAX_MEMORY_UDEREF
14745+ pax_exit_kernel
14746+ SWAPGS_UNSAFE_STACK
14747+ RESTORE_ALL 8
14748+ jmp irq_return
14749+#endif
14750 nmi_swapgs:
14751+#ifdef CONFIG_PAX_MEMORY_UDEREF
14752+ pax_exit_kernel_user
14753+#else
14754+ pax_exit_kernel
14755+#endif
14756 SWAPGS_UNSAFE_STACK
14757+ RESTORE_ALL 8
14758+ jmp irq_return
14759 nmi_restore:
14760+ pax_exit_kernel
14761 RESTORE_ALL 8
14762 jmp irq_return
14763 nmi_userspace:
14764diff -urNp linux-2.6.39.1/arch/x86/kernel/ftrace.c linux-2.6.39.1/arch/x86/kernel/ftrace.c
14765--- linux-2.6.39.1/arch/x86/kernel/ftrace.c 2011-05-19 00:06:34.000000000 -0400
14766+++ linux-2.6.39.1/arch/x86/kernel/ftrace.c 2011-05-22 19:36:30.000000000 -0400
14767@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the
14768 static void *mod_code_newcode; /* holds the text to write to the IP */
14769
14770 static unsigned nmi_wait_count;
14771-static atomic_t nmi_update_count = ATOMIC_INIT(0);
14772+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14773
14774 int ftrace_arch_read_dyn_info(char *buf, int size)
14775 {
14776@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14777
14778 r = snprintf(buf, size, "%u %u",
14779 nmi_wait_count,
14780- atomic_read(&nmi_update_count));
14781+ atomic_read_unchecked(&nmi_update_count));
14782 return r;
14783 }
14784
14785@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14786
14787 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14788 smp_rmb();
14789+ pax_open_kernel();
14790 ftrace_mod_code();
14791- atomic_inc(&nmi_update_count);
14792+ pax_close_kernel();
14793+ atomic_inc_unchecked(&nmi_update_count);
14794 }
14795 /* Must have previous changes seen before executions */
14796 smp_mb();
14797@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, uns
14798 {
14799 unsigned char replaced[MCOUNT_INSN_SIZE];
14800
14801+ ip = ktla_ktva(ip);
14802+
14803 /*
14804 * Note: Due to modules and __init, code can
14805 * disappear and change, we need to protect against faulting
14806@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14807 unsigned char old[MCOUNT_INSN_SIZE], *new;
14808 int ret;
14809
14810- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14811+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14812 new = ftrace_call_replace(ip, (unsigned long)func);
14813 ret = ftrace_modify_code(ip, old, new);
14814
14815@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long
14816 {
14817 unsigned char code[MCOUNT_INSN_SIZE];
14818
14819+ ip = ktla_ktva(ip);
14820+
14821 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14822 return -EFAULT;
14823
14824diff -urNp linux-2.6.39.1/arch/x86/kernel/head32.c linux-2.6.39.1/arch/x86/kernel/head32.c
14825--- linux-2.6.39.1/arch/x86/kernel/head32.c 2011-05-19 00:06:34.000000000 -0400
14826+++ linux-2.6.39.1/arch/x86/kernel/head32.c 2011-05-22 19:36:30.000000000 -0400
14827@@ -19,6 +19,7 @@
14828 #include <asm/io_apic.h>
14829 #include <asm/bios_ebda.h>
14830 #include <asm/tlbflush.h>
14831+#include <asm/boot.h>
14832
14833 static void __init i386_default_early_setup(void)
14834 {
14835@@ -34,7 +35,7 @@ void __init i386_start_kernel(void)
14836 {
14837 memblock_init();
14838
14839- memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14840+ memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14841
14842 #ifdef CONFIG_BLK_DEV_INITRD
14843 /* Reserve INITRD */
14844diff -urNp linux-2.6.39.1/arch/x86/kernel/head_32.S linux-2.6.39.1/arch/x86/kernel/head_32.S
14845--- linux-2.6.39.1/arch/x86/kernel/head_32.S 2011-05-19 00:06:34.000000000 -0400
14846+++ linux-2.6.39.1/arch/x86/kernel/head_32.S 2011-05-22 19:36:30.000000000 -0400
14847@@ -25,6 +25,12 @@
14848 /* Physical address */
14849 #define pa(X) ((X) - __PAGE_OFFSET)
14850
14851+#ifdef CONFIG_PAX_KERNEXEC
14852+#define ta(X) (X)
14853+#else
14854+#define ta(X) ((X) - __PAGE_OFFSET)
14855+#endif
14856+
14857 /*
14858 * References to members of the new_cpu_data structure.
14859 */
14860@@ -54,11 +60,7 @@
14861 * and small than max_low_pfn, otherwise will waste some page table entries
14862 */
14863
14864-#if PTRS_PER_PMD > 1
14865-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14866-#else
14867-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14868-#endif
14869+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14870
14871 /* Number of possible pages in the lowmem region */
14872 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14873@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14874 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14875
14876 /*
14877+ * Real beginning of normal "text" segment
14878+ */
14879+ENTRY(stext)
14880+ENTRY(_stext)
14881+
14882+/*
14883 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14884 * %esi points to the real-mode code as a 32-bit pointer.
14885 * CS and DS must be 4 GB flat segments, but we don't depend on
14886@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14887 * can.
14888 */
14889 __HEAD
14890+
14891+#ifdef CONFIG_PAX_KERNEXEC
14892+ jmp startup_32
14893+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14894+.fill PAGE_SIZE-5,1,0xcc
14895+#endif
14896+
14897 ENTRY(startup_32)
14898 movl pa(stack_start),%ecx
14899
14900@@ -105,6 +120,57 @@ ENTRY(startup_32)
14901 2:
14902 leal -__PAGE_OFFSET(%ecx),%esp
14903
14904+#ifdef CONFIG_SMP
14905+ movl $pa(cpu_gdt_table),%edi
14906+ movl $__per_cpu_load,%eax
14907+ movw %ax,__KERNEL_PERCPU + 2(%edi)
14908+ rorl $16,%eax
14909+ movb %al,__KERNEL_PERCPU + 4(%edi)
14910+ movb %ah,__KERNEL_PERCPU + 7(%edi)
14911+ movl $__per_cpu_end - 1,%eax
14912+ subl $__per_cpu_start,%eax
14913+ movw %ax,__KERNEL_PERCPU + 0(%edi)
14914+#endif
14915+
14916+#ifdef CONFIG_PAX_MEMORY_UDEREF
14917+ movl $NR_CPUS,%ecx
14918+ movl $pa(cpu_gdt_table),%edi
14919+1:
14920+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14921+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14922+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14923+ addl $PAGE_SIZE_asm,%edi
14924+ loop 1b
14925+#endif
14926+
14927+#ifdef CONFIG_PAX_KERNEXEC
14928+ movl $pa(boot_gdt),%edi
14929+ movl $__LOAD_PHYSICAL_ADDR,%eax
14930+ movw %ax,__BOOT_CS + 2(%edi)
14931+ rorl $16,%eax
14932+ movb %al,__BOOT_CS + 4(%edi)
14933+ movb %ah,__BOOT_CS + 7(%edi)
14934+ rorl $16,%eax
14935+
14936+ ljmp $(__BOOT_CS),$1f
14937+1:
14938+
14939+ movl $NR_CPUS,%ecx
14940+ movl $pa(cpu_gdt_table),%edi
14941+ addl $__PAGE_OFFSET,%eax
14942+1:
14943+ movw %ax,__KERNEL_CS + 2(%edi)
14944+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14945+ rorl $16,%eax
14946+ movb %al,__KERNEL_CS + 4(%edi)
14947+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14948+ movb %ah,__KERNEL_CS + 7(%edi)
14949+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14950+ rorl $16,%eax
14951+ addl $PAGE_SIZE_asm,%edi
14952+ loop 1b
14953+#endif
14954+
14955 /*
14956 * Clear BSS first so that there are no surprises...
14957 */
14958@@ -195,8 +261,11 @@ ENTRY(startup_32)
14959 movl %eax, pa(max_pfn_mapped)
14960
14961 /* Do early initialization of the fixmap area */
14962- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14963- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14964+#ifdef CONFIG_COMPAT_VDSO
14965+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14966+#else
14967+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14968+#endif
14969 #else /* Not PAE */
14970
14971 page_pde_offset = (__PAGE_OFFSET >> 20);
14972@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14973 movl %eax, pa(max_pfn_mapped)
14974
14975 /* Do early initialization of the fixmap area */
14976- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14977- movl %eax,pa(initial_page_table+0xffc)
14978+#ifdef CONFIG_COMPAT_VDSO
14979+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14980+#else
14981+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14982+#endif
14983 #endif
14984
14985 #ifdef CONFIG_PARAVIRT
14986@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14987 cmpl $num_subarch_entries, %eax
14988 jae bad_subarch
14989
14990- movl pa(subarch_entries)(,%eax,4), %eax
14991- subl $__PAGE_OFFSET, %eax
14992- jmp *%eax
14993+ jmp *pa(subarch_entries)(,%eax,4)
14994
14995 bad_subarch:
14996 WEAK(lguest_entry)
14997@@ -255,10 +325,10 @@ WEAK(xen_entry)
14998 __INITDATA
14999
15000 subarch_entries:
15001- .long default_entry /* normal x86/PC */
15002- .long lguest_entry /* lguest hypervisor */
15003- .long xen_entry /* Xen hypervisor */
15004- .long default_entry /* Moorestown MID */
15005+ .long ta(default_entry) /* normal x86/PC */
15006+ .long ta(lguest_entry) /* lguest hypervisor */
15007+ .long ta(xen_entry) /* Xen hypervisor */
15008+ .long ta(default_entry) /* Moorestown MID */
15009 num_subarch_entries = (. - subarch_entries) / 4
15010 .previous
15011 #else
15012@@ -312,6 +382,7 @@ default_entry:
15013 orl %edx,%eax
15014 movl %eax,%cr4
15015
15016+#ifdef CONFIG_X86_PAE
15017 testb $X86_CR4_PAE, %al # check if PAE is enabled
15018 jz 6f
15019
15020@@ -340,6 +411,9 @@ default_entry:
15021 /* Make changes effective */
15022 wrmsr
15023
15024+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
15025+#endif
15026+
15027 6:
15028
15029 /*
15030@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
15031 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
15032 movl %eax,%ss # after changing gdt.
15033
15034- movl $(__USER_DS),%eax # DS/ES contains default USER segment
15035+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
15036 movl %eax,%ds
15037 movl %eax,%es
15038
15039@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
15040 */
15041 cmpb $0,ready
15042 jne 1f
15043- movl $gdt_page,%eax
15044+ movl $cpu_gdt_table,%eax
15045 movl $stack_canary,%ecx
15046+#ifdef CONFIG_SMP
15047+ addl $__per_cpu_load,%ecx
15048+#endif
15049 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
15050 shrl $16, %ecx
15051 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
15052 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
15053 1:
15054-#endif
15055 movl $(__KERNEL_STACK_CANARY),%eax
15056+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15057+ movl $(__USER_DS),%eax
15058+#else
15059+ xorl %eax,%eax
15060+#endif
15061 movl %eax,%gs
15062
15063 xorl %eax,%eax # Clear LDT
15064@@ -558,22 +639,22 @@ early_page_fault:
15065 jmp early_fault
15066
15067 early_fault:
15068- cld
15069 #ifdef CONFIG_PRINTK
15070+ cmpl $1,%ss:early_recursion_flag
15071+ je hlt_loop
15072+ incl %ss:early_recursion_flag
15073+ cld
15074 pusha
15075 movl $(__KERNEL_DS),%eax
15076 movl %eax,%ds
15077 movl %eax,%es
15078- cmpl $2,early_recursion_flag
15079- je hlt_loop
15080- incl early_recursion_flag
15081 movl %cr2,%eax
15082 pushl %eax
15083 pushl %edx /* trapno */
15084 pushl $fault_msg
15085 call printk
15086+; call dump_stack
15087 #endif
15088- call dump_stack
15089 hlt_loop:
15090 hlt
15091 jmp hlt_loop
15092@@ -581,8 +662,11 @@ hlt_loop:
15093 /* This is the default interrupt "handler" :-) */
15094 ALIGN
15095 ignore_int:
15096- cld
15097 #ifdef CONFIG_PRINTK
15098+ cmpl $2,%ss:early_recursion_flag
15099+ je hlt_loop
15100+ incl %ss:early_recursion_flag
15101+ cld
15102 pushl %eax
15103 pushl %ecx
15104 pushl %edx
15105@@ -591,9 +675,6 @@ ignore_int:
15106 movl $(__KERNEL_DS),%eax
15107 movl %eax,%ds
15108 movl %eax,%es
15109- cmpl $2,early_recursion_flag
15110- je hlt_loop
15111- incl early_recursion_flag
15112 pushl 16(%esp)
15113 pushl 24(%esp)
15114 pushl 32(%esp)
15115@@ -622,29 +703,43 @@ ENTRY(initial_code)
15116 /*
15117 * BSS section
15118 */
15119-__PAGE_ALIGNED_BSS
15120- .align PAGE_SIZE
15121 #ifdef CONFIG_X86_PAE
15122+.section .initial_pg_pmd,"a",@progbits
15123 initial_pg_pmd:
15124 .fill 1024*KPMDS,4,0
15125 #else
15126+.section .initial_page_table,"a",@progbits
15127 ENTRY(initial_page_table)
15128 .fill 1024,4,0
15129 #endif
15130+.section .initial_pg_fixmap,"a",@progbits
15131 initial_pg_fixmap:
15132 .fill 1024,4,0
15133+.section .empty_zero_page,"a",@progbits
15134 ENTRY(empty_zero_page)
15135 .fill 4096,1,0
15136+.section .swapper_pg_dir,"a",@progbits
15137 ENTRY(swapper_pg_dir)
15138+#ifdef CONFIG_X86_PAE
15139+ .fill 4,8,0
15140+#else
15141 .fill 1024,4,0
15142+#endif
15143+
15144+/*
15145+ * The IDT has to be page-aligned to simplify the Pentium
15146+ * F0 0F bug workaround.. We have a special link segment
15147+ * for this.
15148+ */
15149+.section .idt,"a",@progbits
15150+ENTRY(idt_table)
15151+ .fill 256,8,0
15152
15153 /*
15154 * This starts the data section.
15155 */
15156 #ifdef CONFIG_X86_PAE
15157-__PAGE_ALIGNED_DATA
15158- /* Page-aligned for the benefit of paravirt? */
15159- .align PAGE_SIZE
15160+.section .initial_page_table,"a",@progbits
15161 ENTRY(initial_page_table)
15162 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15163 # if KPMDS == 3
15164@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15165 # error "Kernel PMDs should be 1, 2 or 3"
15166 # endif
15167 .align PAGE_SIZE /* needs to be page-sized too */
15168+
15169+#ifdef CONFIG_PAX_PER_CPU_PGD
15170+ENTRY(cpu_pgd)
15171+ .rept NR_CPUS
15172+ .fill 4,8,0
15173+ .endr
15174+#endif
15175+
15176 #endif
15177
15178 .data
15179 .balign 4
15180 ENTRY(stack_start)
15181- .long init_thread_union+THREAD_SIZE
15182+ .long init_thread_union+THREAD_SIZE-8
15183+
15184+ready: .byte 0
15185
15186+.section .rodata,"a",@progbits
15187 early_recursion_flag:
15188 .long 0
15189
15190-ready: .byte 0
15191-
15192 int_msg:
15193 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15194
15195@@ -707,7 +811,7 @@ fault_msg:
15196 .word 0 # 32 bit align gdt_desc.address
15197 boot_gdt_descr:
15198 .word __BOOT_DS+7
15199- .long boot_gdt - __PAGE_OFFSET
15200+ .long pa(boot_gdt)
15201
15202 .word 0 # 32-bit align idt_desc.address
15203 idt_descr:
15204@@ -718,7 +822,7 @@ idt_descr:
15205 .word 0 # 32 bit align gdt_desc.address
15206 ENTRY(early_gdt_descr)
15207 .word GDT_ENTRIES*8-1
15208- .long gdt_page /* Overwritten for secondary CPUs */
15209+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
15210
15211 /*
15212 * The boot_gdt must mirror the equivalent in setup.S and is
15213@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15214 .align L1_CACHE_BYTES
15215 ENTRY(boot_gdt)
15216 .fill GDT_ENTRY_BOOT_CS,8,0
15217- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15218- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15219+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15220+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15221+
15222+ .align PAGE_SIZE_asm
15223+ENTRY(cpu_gdt_table)
15224+ .rept NR_CPUS
15225+ .quad 0x0000000000000000 /* NULL descriptor */
15226+ .quad 0x0000000000000000 /* 0x0b reserved */
15227+ .quad 0x0000000000000000 /* 0x13 reserved */
15228+ .quad 0x0000000000000000 /* 0x1b reserved */
15229+
15230+#ifdef CONFIG_PAX_KERNEXEC
15231+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15232+#else
15233+ .quad 0x0000000000000000 /* 0x20 unused */
15234+#endif
15235+
15236+ .quad 0x0000000000000000 /* 0x28 unused */
15237+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15238+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15239+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15240+ .quad 0x0000000000000000 /* 0x4b reserved */
15241+ .quad 0x0000000000000000 /* 0x53 reserved */
15242+ .quad 0x0000000000000000 /* 0x5b reserved */
15243+
15244+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15245+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15246+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15247+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15248+
15249+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15250+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15251+
15252+ /*
15253+ * Segments used for calling PnP BIOS have byte granularity.
15254+ * The code segments and data segments have fixed 64k limits,
15255+ * the transfer segment sizes are set at run time.
15256+ */
15257+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
15258+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
15259+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
15260+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
15261+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
15262+
15263+ /*
15264+ * The APM segments have byte granularity and their bases
15265+ * are set at run time. All have 64k limits.
15266+ */
15267+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15268+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15269+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
15270+
15271+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15272+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15273+ .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
15274+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15275+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15276+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15277+
15278+ /* Be sure this is zeroed to avoid false validations in Xen */
15279+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15280+ .endr
15281diff -urNp linux-2.6.39.1/arch/x86/kernel/head_64.S linux-2.6.39.1/arch/x86/kernel/head_64.S
15282--- linux-2.6.39.1/arch/x86/kernel/head_64.S 2011-05-19 00:06:34.000000000 -0400
15283+++ linux-2.6.39.1/arch/x86/kernel/head_64.S 2011-05-22 19:36:30.000000000 -0400
15284@@ -19,6 +19,7 @@
15285 #include <asm/cache.h>
15286 #include <asm/processor-flags.h>
15287 #include <asm/percpu.h>
15288+#include <asm/cpufeature.h>
15289
15290 #ifdef CONFIG_PARAVIRT
15291 #include <asm/asm-offsets.h>
15292@@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
15293 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15294 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15295 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15296+L4_VMALLOC_START = pgd_index(VMALLOC_START)
15297+L3_VMALLOC_START = pud_index(VMALLOC_START)
15298+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15299+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15300
15301 .text
15302 __HEAD
15303@@ -85,35 +90,22 @@ startup_64:
15304 */
15305 addq %rbp, init_level4_pgt + 0(%rip)
15306 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15307+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15308+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15309 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15310
15311 addq %rbp, level3_ident_pgt + 0(%rip)
15312+#ifndef CONFIG_XEN
15313+ addq %rbp, level3_ident_pgt + 8(%rip)
15314+#endif
15315
15316- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15317- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15318+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15319
15320- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15321+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15322+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15323
15324- /* Add an Identity mapping if I am above 1G */
15325- leaq _text(%rip), %rdi
15326- andq $PMD_PAGE_MASK, %rdi
15327-
15328- movq %rdi, %rax
15329- shrq $PUD_SHIFT, %rax
15330- andq $(PTRS_PER_PUD - 1), %rax
15331- jz ident_complete
15332-
15333- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15334- leaq level3_ident_pgt(%rip), %rbx
15335- movq %rdx, 0(%rbx, %rax, 8)
15336-
15337- movq %rdi, %rax
15338- shrq $PMD_SHIFT, %rax
15339- andq $(PTRS_PER_PMD - 1), %rax
15340- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15341- leaq level2_spare_pgt(%rip), %rbx
15342- movq %rdx, 0(%rbx, %rax, 8)
15343-ident_complete:
15344+ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15345+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15346
15347 /*
15348 * Fixup the kernel text+data virtual addresses. Note that
15349@@ -160,8 +152,8 @@ ENTRY(secondary_startup_64)
15350 * after the boot processor executes this code.
15351 */
15352
15353- /* Enable PAE mode and PGE */
15354- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15355+ /* Enable PAE mode and PSE/PGE */
15356+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15357 movq %rax, %cr4
15358
15359 /* Setup early boot stage 4 level pagetables. */
15360@@ -183,9 +175,14 @@ ENTRY(secondary_startup_64)
15361 movl $MSR_EFER, %ecx
15362 rdmsr
15363 btsl $_EFER_SCE, %eax /* Enable System Call */
15364- btl $20,%edi /* No Execute supported? */
15365+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15366 jnc 1f
15367 btsl $_EFER_NX, %eax
15368+ leaq init_level4_pgt(%rip), %rdi
15369+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15370+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15371+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15372+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15373 1: wrmsr /* Make changes effective */
15374
15375 /* Setup cr0 */
15376@@ -269,7 +266,7 @@ ENTRY(secondary_startup_64)
15377 bad_address:
15378 jmp bad_address
15379
15380- .section ".init.text","ax"
15381+ __INIT
15382 #ifdef CONFIG_EARLY_PRINTK
15383 .globl early_idt_handlers
15384 early_idt_handlers:
15385@@ -314,18 +311,23 @@ ENTRY(early_idt_handler)
15386 #endif /* EARLY_PRINTK */
15387 1: hlt
15388 jmp 1b
15389+ .previous
15390
15391 #ifdef CONFIG_EARLY_PRINTK
15392+ __INITDATA
15393 early_recursion_flag:
15394 .long 0
15395+ .previous
15396
15397+ .section .rodata,"a",@progbits
15398 early_idt_msg:
15399 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15400 early_idt_ripmsg:
15401 .asciz "RIP %s\n"
15402-#endif /* CONFIG_EARLY_PRINTK */
15403 .previous
15404+#endif /* CONFIG_EARLY_PRINTK */
15405
15406+ .section .rodata,"a",@progbits
15407 #define NEXT_PAGE(name) \
15408 .balign PAGE_SIZE; \
15409 ENTRY(name)
15410@@ -338,7 +340,6 @@ ENTRY(name)
15411 i = i + 1 ; \
15412 .endr
15413
15414- .data
15415 /*
15416 * This default setting generates an ident mapping at address 0x100000
15417 * and a mapping for the kernel that precisely maps virtual address
15418@@ -349,13 +350,36 @@ NEXT_PAGE(init_level4_pgt)
15419 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15420 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15421 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15422+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
15423+ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
15424+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15425+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15426 .org init_level4_pgt + L4_START_KERNEL*8, 0
15427 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15428 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15429
15430+#ifdef CONFIG_PAX_PER_CPU_PGD
15431+NEXT_PAGE(cpu_pgd)
15432+ .rept NR_CPUS
15433+ .fill 512,8,0
15434+ .endr
15435+#endif
15436+
15437 NEXT_PAGE(level3_ident_pgt)
15438 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15439+#ifdef CONFIG_XEN
15440 .fill 511,8,0
15441+#else
15442+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15443+ .fill 510,8,0
15444+#endif
15445+
15446+NEXT_PAGE(level3_vmalloc_pgt)
15447+ .fill 512,8,0
15448+
15449+NEXT_PAGE(level3_vmemmap_pgt)
15450+ .fill L3_VMEMMAP_START,8,0
15451+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15452
15453 NEXT_PAGE(level3_kernel_pgt)
15454 .fill L3_START_KERNEL,8,0
15455@@ -363,20 +387,23 @@ NEXT_PAGE(level3_kernel_pgt)
15456 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15457 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15458
15459+NEXT_PAGE(level2_vmemmap_pgt)
15460+ .fill 512,8,0
15461+
15462 NEXT_PAGE(level2_fixmap_pgt)
15463- .fill 506,8,0
15464- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15465- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15466- .fill 5,8,0
15467+ .fill 507,8,0
15468+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15469+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15470+ .fill 4,8,0
15471
15472-NEXT_PAGE(level1_fixmap_pgt)
15473+NEXT_PAGE(level1_vsyscall_pgt)
15474 .fill 512,8,0
15475
15476-NEXT_PAGE(level2_ident_pgt)
15477- /* Since I easily can, map the first 1G.
15478+ /* Since I easily can, map the first 2G.
15479 * Don't set NX because code runs from these pages.
15480 */
15481- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15482+NEXT_PAGE(level2_ident_pgt)
15483+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15484
15485 NEXT_PAGE(level2_kernel_pgt)
15486 /*
15487@@ -389,33 +416,55 @@ NEXT_PAGE(level2_kernel_pgt)
15488 * If you want to increase this then increase MODULES_VADDR
15489 * too.)
15490 */
15491- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15492- KERNEL_IMAGE_SIZE/PMD_SIZE)
15493-
15494-NEXT_PAGE(level2_spare_pgt)
15495- .fill 512, 8, 0
15496+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15497
15498 #undef PMDS
15499 #undef NEXT_PAGE
15500
15501- .data
15502+ .align PAGE_SIZE
15503+ENTRY(cpu_gdt_table)
15504+ .rept NR_CPUS
15505+ .quad 0x0000000000000000 /* NULL descriptor */
15506+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15507+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
15508+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
15509+ .quad 0x00cffb000000ffff /* __USER32_CS */
15510+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15511+ .quad 0x00affb000000ffff /* __USER_CS */
15512+
15513+#ifdef CONFIG_PAX_KERNEXEC
15514+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15515+#else
15516+ .quad 0x0 /* unused */
15517+#endif
15518+
15519+ .quad 0,0 /* TSS */
15520+ .quad 0,0 /* LDT */
15521+ .quad 0,0,0 /* three TLS descriptors */
15522+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
15523+ /* asm/segment.h:GDT_ENTRIES must match this */
15524+
15525+ /* zero the remaining page */
15526+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15527+ .endr
15528+
15529 .align 16
15530 .globl early_gdt_descr
15531 early_gdt_descr:
15532 .word GDT_ENTRIES*8-1
15533 early_gdt_descr_base:
15534- .quad INIT_PER_CPU_VAR(gdt_page)
15535+ .quad cpu_gdt_table
15536
15537 ENTRY(phys_base)
15538 /* This must match the first entry in level2_kernel_pgt */
15539 .quad 0x0000000000000000
15540
15541 #include "../../x86/xen/xen-head.S"
15542-
15543- .section .bss, "aw", @nobits
15544+
15545+ .section .rodata,"a",@progbits
15546 .align L1_CACHE_BYTES
15547 ENTRY(idt_table)
15548- .skip IDT_ENTRIES * 16
15549+ .fill 512,8,0
15550
15551 __PAGE_ALIGNED_BSS
15552 .align PAGE_SIZE
15553diff -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
15554--- linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c 2011-05-19 00:06:34.000000000 -0400
15555+++ linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c 2011-05-22 19:36:30.000000000 -0400
15556@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15557 EXPORT_SYMBOL(cmpxchg8b_emu);
15558 #endif
15559
15560+EXPORT_SYMBOL_GPL(cpu_gdt_table);
15561+
15562 /* Networking helper routines. */
15563 EXPORT_SYMBOL(csum_partial_copy_generic);
15564+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15565+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15566
15567 EXPORT_SYMBOL(__get_user_1);
15568 EXPORT_SYMBOL(__get_user_2);
15569@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15570
15571 EXPORT_SYMBOL(csum_partial);
15572 EXPORT_SYMBOL(empty_zero_page);
15573+
15574+#ifdef CONFIG_PAX_KERNEXEC
15575+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15576+#endif
15577diff -urNp linux-2.6.39.1/arch/x86/kernel/i8259.c linux-2.6.39.1/arch/x86/kernel/i8259.c
15578--- linux-2.6.39.1/arch/x86/kernel/i8259.c 2011-05-19 00:06:34.000000000 -0400
15579+++ linux-2.6.39.1/arch/x86/kernel/i8259.c 2011-05-22 19:36:30.000000000 -0400
15580@@ -210,7 +210,7 @@ spurious_8259A_irq:
15581 "spurious 8259A interrupt: IRQ%d.\n", irq);
15582 spurious_irq_mask |= irqmask;
15583 }
15584- atomic_inc(&irq_err_count);
15585+ atomic_inc_unchecked(&irq_err_count);
15586 /*
15587 * Theoretically we do not have to handle this IRQ,
15588 * but in Linux this does not cause problems and is
15589diff -urNp linux-2.6.39.1/arch/x86/kernel/init_task.c linux-2.6.39.1/arch/x86/kernel/init_task.c
15590--- linux-2.6.39.1/arch/x86/kernel/init_task.c 2011-05-19 00:06:34.000000000 -0400
15591+++ linux-2.6.39.1/arch/x86/kernel/init_task.c 2011-05-22 19:36:30.000000000 -0400
15592@@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15593 * way process stacks are handled. This is done by having a special
15594 * "init_task" linker map entry..
15595 */
15596-union thread_union init_thread_union __init_task_data =
15597- { INIT_THREAD_INFO(init_task) };
15598+union thread_union init_thread_union __init_task_data;
15599
15600 /*
15601 * Initial task structure.
15602@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15603 * section. Since TSS's are completely CPU-local, we want them
15604 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15605 */
15606-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15607-
15608+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15609+EXPORT_SYMBOL(init_tss);
15610diff -urNp linux-2.6.39.1/arch/x86/kernel/ioport.c linux-2.6.39.1/arch/x86/kernel/ioport.c
15611--- linux-2.6.39.1/arch/x86/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
15612+++ linux-2.6.39.1/arch/x86/kernel/ioport.c 2011-05-22 19:41:32.000000000 -0400
15613@@ -6,6 +6,7 @@
15614 #include <linux/sched.h>
15615 #include <linux/kernel.h>
15616 #include <linux/capability.h>
15617+#include <linux/security.h>
15618 #include <linux/errno.h>
15619 #include <linux/types.h>
15620 #include <linux/ioport.h>
15621@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long
15622
15623 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15624 return -EINVAL;
15625+#ifdef CONFIG_GRKERNSEC_IO
15626+ if (turn_on && grsec_disable_privio) {
15627+ gr_handle_ioperm();
15628+ return -EPERM;
15629+ }
15630+#endif
15631 if (turn_on && !capable(CAP_SYS_RAWIO))
15632 return -EPERM;
15633
15634@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long
15635 * because the ->io_bitmap_max value must match the bitmap
15636 * contents:
15637 */
15638- tss = &per_cpu(init_tss, get_cpu());
15639+ tss = init_tss + get_cpu();
15640
15641 if (turn_on)
15642 bitmap_clear(t->io_bitmap_ptr, from, num);
15643@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct
15644 return -EINVAL;
15645 /* Trying to gain more privileges? */
15646 if (level > old) {
15647+#ifdef CONFIG_GRKERNSEC_IO
15648+ if (grsec_disable_privio) {
15649+ gr_handle_iopl();
15650+ return -EPERM;
15651+ }
15652+#endif
15653 if (!capable(CAP_SYS_RAWIO))
15654 return -EPERM;
15655 }
15656diff -urNp linux-2.6.39.1/arch/x86/kernel/irq_32.c linux-2.6.39.1/arch/x86/kernel/irq_32.c
15657--- linux-2.6.39.1/arch/x86/kernel/irq_32.c 2011-05-19 00:06:34.000000000 -0400
15658+++ linux-2.6.39.1/arch/x86/kernel/irq_32.c 2011-05-22 19:36:30.000000000 -0400
15659@@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15660 __asm__ __volatile__("andl %%esp,%0" :
15661 "=r" (sp) : "0" (THREAD_SIZE - 1));
15662
15663- return sp < (sizeof(struct thread_info) + STACK_WARN);
15664+ return sp < STACK_WARN;
15665 }
15666
15667 static void print_stack_overflow(void)
15668@@ -54,8 +54,8 @@ static inline void print_stack_overflow(
15669 * per-CPU IRQ handling contexts (thread information and stack)
15670 */
15671 union irq_ctx {
15672- struct thread_info tinfo;
15673- u32 stack[THREAD_SIZE/sizeof(u32)];
15674+ unsigned long previous_esp;
15675+ u32 stack[THREAD_SIZE/sizeof(u32)];
15676 } __attribute__((aligned(THREAD_SIZE)));
15677
15678 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15679@@ -75,10 +75,9 @@ static void call_on_stack(void *func, vo
15680 static inline int
15681 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15682 {
15683- union irq_ctx *curctx, *irqctx;
15684+ union irq_ctx *irqctx;
15685 u32 *isp, arg1, arg2;
15686
15687- curctx = (union irq_ctx *) current_thread_info();
15688 irqctx = __this_cpu_read(hardirq_ctx);
15689
15690 /*
15691@@ -87,21 +86,17 @@ execute_on_irq_stack(int overflow, struc
15692 * handler) we can't do that and just have to keep using the
15693 * current stack (which is the irq stack already after all)
15694 */
15695- if (unlikely(curctx == irqctx))
15696+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15697 return 0;
15698
15699 /* build the stack frame on the IRQ stack */
15700- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15701- irqctx->tinfo.task = curctx->tinfo.task;
15702- irqctx->tinfo.previous_esp = current_stack_pointer;
15703+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15704+ irqctx->previous_esp = current_stack_pointer;
15705+ add_preempt_count(HARDIRQ_OFFSET);
15706
15707- /*
15708- * Copy the softirq bits in preempt_count so that the
15709- * softirq checks work in the hardirq context.
15710- */
15711- irqctx->tinfo.preempt_count =
15712- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15713- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15714+#ifdef CONFIG_PAX_MEMORY_UDEREF
15715+ __set_fs(MAKE_MM_SEG(0));
15716+#endif
15717
15718 if (unlikely(overflow))
15719 call_on_stack(print_stack_overflow, isp);
15720@@ -113,6 +108,12 @@ execute_on_irq_stack(int overflow, struc
15721 : "0" (irq), "1" (desc), "2" (isp),
15722 "D" (desc->handle_irq)
15723 : "memory", "cc", "ecx");
15724+
15725+#ifdef CONFIG_PAX_MEMORY_UDEREF
15726+ __set_fs(current_thread_info()->addr_limit);
15727+#endif
15728+
15729+ sub_preempt_count(HARDIRQ_OFFSET);
15730 return 1;
15731 }
15732
15733@@ -121,29 +122,11 @@ execute_on_irq_stack(int overflow, struc
15734 */
15735 void __cpuinit irq_ctx_init(int cpu)
15736 {
15737- union irq_ctx *irqctx;
15738-
15739 if (per_cpu(hardirq_ctx, cpu))
15740 return;
15741
15742- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15743- THREAD_FLAGS,
15744- THREAD_ORDER));
15745- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15746- irqctx->tinfo.cpu = cpu;
15747- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15748- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15749-
15750- per_cpu(hardirq_ctx, cpu) = irqctx;
15751-
15752- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15753- THREAD_FLAGS,
15754- THREAD_ORDER));
15755- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15756- irqctx->tinfo.cpu = cpu;
15757- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15758-
15759- per_cpu(softirq_ctx, cpu) = irqctx;
15760+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15761+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15762
15763 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15764 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15765@@ -152,7 +135,6 @@ void __cpuinit irq_ctx_init(int cpu)
15766 asmlinkage void do_softirq(void)
15767 {
15768 unsigned long flags;
15769- struct thread_info *curctx;
15770 union irq_ctx *irqctx;
15771 u32 *isp;
15772
15773@@ -162,15 +144,22 @@ asmlinkage void do_softirq(void)
15774 local_irq_save(flags);
15775
15776 if (local_softirq_pending()) {
15777- curctx = current_thread_info();
15778 irqctx = __this_cpu_read(softirq_ctx);
15779- irqctx->tinfo.task = curctx->task;
15780- irqctx->tinfo.previous_esp = current_stack_pointer;
15781+ irqctx->previous_esp = current_stack_pointer;
15782
15783 /* build the stack frame on the softirq stack */
15784- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15785+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15786+
15787+#ifdef CONFIG_PAX_MEMORY_UDEREF
15788+ __set_fs(MAKE_MM_SEG(0));
15789+#endif
15790
15791 call_on_stack(__do_softirq, isp);
15792+
15793+#ifdef CONFIG_PAX_MEMORY_UDEREF
15794+ __set_fs(current_thread_info()->addr_limit);
15795+#endif
15796+
15797 /*
15798 * Shouldn't happen, we returned above if in_interrupt():
15799 */
15800diff -urNp linux-2.6.39.1/arch/x86/kernel/irq.c linux-2.6.39.1/arch/x86/kernel/irq.c
15801--- linux-2.6.39.1/arch/x86/kernel/irq.c 2011-05-19 00:06:34.000000000 -0400
15802+++ linux-2.6.39.1/arch/x86/kernel/irq.c 2011-05-22 19:36:30.000000000 -0400
15803@@ -17,7 +17,7 @@
15804 #include <asm/mce.h>
15805 #include <asm/hw_irq.h>
15806
15807-atomic_t irq_err_count;
15808+atomic_unchecked_t irq_err_count;
15809
15810 /* Function pointer for generic interrupt vector handling */
15811 void (*x86_platform_ipi_callback)(void) = NULL;
15812@@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file
15813 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15814 seq_printf(p, " Machine check polls\n");
15815 #endif
15816- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15817+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15818 #if defined(CONFIG_X86_IO_APIC)
15819- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15820+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15821 #endif
15822 return 0;
15823 }
15824@@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15825
15826 u64 arch_irq_stat(void)
15827 {
15828- u64 sum = atomic_read(&irq_err_count);
15829+ u64 sum = atomic_read_unchecked(&irq_err_count);
15830
15831 #ifdef CONFIG_X86_IO_APIC
15832- sum += atomic_read(&irq_mis_count);
15833+ sum += atomic_read_unchecked(&irq_mis_count);
15834 #endif
15835 return sum;
15836 }
15837diff -urNp linux-2.6.39.1/arch/x86/kernel/kgdb.c linux-2.6.39.1/arch/x86/kernel/kgdb.c
15838--- linux-2.6.39.1/arch/x86/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
15839+++ linux-2.6.39.1/arch/x86/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
15840@@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem,
15841 #ifdef CONFIG_X86_32
15842 switch (regno) {
15843 case GDB_SS:
15844- if (!user_mode_vm(regs))
15845+ if (!user_mode(regs))
15846 *(unsigned long *)mem = __KERNEL_DS;
15847 break;
15848 case GDB_SP:
15849- if (!user_mode_vm(regs))
15850+ if (!user_mode(regs))
15851 *(unsigned long *)mem = kernel_stack_pointer(regs);
15852 break;
15853 case GDB_GS:
15854@@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vec
15855 case 'k':
15856 /* clear the trace bit */
15857 linux_regs->flags &= ~X86_EFLAGS_TF;
15858- atomic_set(&kgdb_cpu_doing_single_step, -1);
15859+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15860
15861 /* set the trace bit if we're stepping */
15862 if (remcomInBuffer[0] == 's') {
15863 linux_regs->flags |= X86_EFLAGS_TF;
15864- atomic_set(&kgdb_cpu_doing_single_step,
15865+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15866 raw_smp_processor_id());
15867 }
15868
15869@@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args
15870 return NOTIFY_DONE;
15871
15872 case DIE_DEBUG:
15873- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15874+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15875 if (user_mode(regs))
15876 return single_step_cont(regs, args);
15877 break;
15878@@ -710,7 +710,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
15879 regs->ip = ip;
15880 }
15881
15882-struct kgdb_arch arch_kgdb_ops = {
15883+const struct kgdb_arch arch_kgdb_ops = {
15884 /* Breakpoint instruction: */
15885 .gdb_bpt_instr = { 0xcc },
15886 .flags = KGDB_HW_BREAKPOINT,
15887diff -urNp linux-2.6.39.1/arch/x86/kernel/kprobes.c linux-2.6.39.1/arch/x86/kernel/kprobes.c
15888--- linux-2.6.39.1/arch/x86/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
15889+++ linux-2.6.39.1/arch/x86/kernel/kprobes.c 2011-05-22 19:36:30.000000000 -0400
15890@@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
15891 } __attribute__((packed)) *insn;
15892
15893 insn = (struct __arch_relative_insn *)from;
15894+
15895+ pax_open_kernel();
15896 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15897 insn->op = op;
15898+ pax_close_kernel();
15899 }
15900
15901 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15902@@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
15903 kprobe_opcode_t opcode;
15904 kprobe_opcode_t *orig_opcodes = opcodes;
15905
15906- if (search_exception_tables((unsigned long)opcodes))
15907+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15908 return 0; /* Page fault may occur on this address. */
15909
15910 retry:
15911@@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
15912 }
15913 }
15914 insn_get_length(&insn);
15915+ pax_open_kernel();
15916 memcpy(dest, insn.kaddr, insn.length);
15917+ pax_close_kernel();
15918
15919 #ifdef CONFIG_X86_64
15920 if (insn_rip_relative(&insn)) {
15921@@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
15922 (u8 *) dest;
15923 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15924 disp = (u8 *) dest + insn_offset_displacement(&insn);
15925+ pax_open_kernel();
15926 *(s32 *) disp = (s32) newdisp;
15927+ pax_close_kernel();
15928 }
15929 #endif
15930 return insn.length;
15931@@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
15932 */
15933 __copy_instruction(p->ainsn.insn, p->addr, 0);
15934
15935- if (can_boost(p->addr))
15936+ if (can_boost(ktla_ktva(p->addr)))
15937 p->ainsn.boostable = 0;
15938 else
15939 p->ainsn.boostable = -1;
15940
15941- p->opcode = *p->addr;
15942+ p->opcode = *(ktla_ktva(p->addr));
15943 }
15944
15945 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15946@@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
15947 * nor set current_kprobe, because it doesn't use single
15948 * stepping.
15949 */
15950- regs->ip = (unsigned long)p->ainsn.insn;
15951+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15952 preempt_enable_no_resched();
15953 return;
15954 }
15955@@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
15956 if (p->opcode == BREAKPOINT_INSTRUCTION)
15957 regs->ip = (unsigned long)p->addr;
15958 else
15959- regs->ip = (unsigned long)p->ainsn.insn;
15960+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15961 }
15962
15963 /*
15964@@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
15965 setup_singlestep(p, regs, kcb, 0);
15966 return 1;
15967 }
15968- } else if (*addr != BREAKPOINT_INSTRUCTION) {
15969+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15970 /*
15971 * The breakpoint instruction was removed right
15972 * after we hit it. Another cpu has removed
15973@@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
15974 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15975 {
15976 unsigned long *tos = stack_addr(regs);
15977- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15978+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15979 unsigned long orig_ip = (unsigned long)p->addr;
15980 kprobe_opcode_t *insn = p->ainsn.insn;
15981
15982@@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
15983 struct die_args *args = data;
15984 int ret = NOTIFY_DONE;
15985
15986- if (args->regs && user_mode_vm(args->regs))
15987+ if (args->regs && user_mode(args->regs))
15988 return ret;
15989
15990 switch (val) {
15991@@ -1381,7 +1388,7 @@ int __kprobes arch_prepare_optimized_kpr
15992 * Verify if the address gap is in 2GB range, because this uses
15993 * a relative jump.
15994 */
15995- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15996+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15997 if (abs(rel) > 0x7fffffff)
15998 return -ERANGE;
15999
16000@@ -1402,11 +1409,11 @@ int __kprobes arch_prepare_optimized_kpr
16001 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
16002
16003 /* Set probe function call */
16004- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
16005+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
16006
16007 /* Set returning jmp instruction at the tail of out-of-line buffer */
16008 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
16009- (u8 *)op->kp.addr + op->optinsn.size);
16010+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
16011
16012 flush_icache_range((unsigned long) buf,
16013 (unsigned long) buf + TMPL_END_IDX +
16014@@ -1428,7 +1435,7 @@ static void __kprobes setup_optimize_kpr
16015 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
16016
16017 /* Backup instructions which will be replaced by jump address */
16018- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
16019+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
16020 RELATIVE_ADDR_SIZE);
16021
16022 insn_buf[0] = RELATIVEJUMP_OPCODE;
16023diff -urNp linux-2.6.39.1/arch/x86/kernel/ldt.c linux-2.6.39.1/arch/x86/kernel/ldt.c
16024--- linux-2.6.39.1/arch/x86/kernel/ldt.c 2011-05-19 00:06:34.000000000 -0400
16025+++ linux-2.6.39.1/arch/x86/kernel/ldt.c 2011-05-22 19:36:30.000000000 -0400
16026@@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
16027 if (reload) {
16028 #ifdef CONFIG_SMP
16029 preempt_disable();
16030- load_LDT(pc);
16031+ load_LDT_nolock(pc);
16032 if (!cpumask_equal(mm_cpumask(current->mm),
16033 cpumask_of(smp_processor_id())))
16034 smp_call_function(flush_ldt, current->mm, 1);
16035 preempt_enable();
16036 #else
16037- load_LDT(pc);
16038+ load_LDT_nolock(pc);
16039 #endif
16040 }
16041 if (oldsize) {
16042@@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
16043 return err;
16044
16045 for (i = 0; i < old->size; i++)
16046- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
16047+ write_ldt_entry(new->ldt, i, old->ldt + i);
16048 return 0;
16049 }
16050
16051@@ -116,6 +116,24 @@ int init_new_context(struct task_struct
16052 retval = copy_ldt(&mm->context, &old_mm->context);
16053 mutex_unlock(&old_mm->context.lock);
16054 }
16055+
16056+ if (tsk == current) {
16057+ mm->context.vdso = 0;
16058+
16059+#ifdef CONFIG_X86_32
16060+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16061+ mm->context.user_cs_base = 0UL;
16062+ mm->context.user_cs_limit = ~0UL;
16063+
16064+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16065+ cpus_clear(mm->context.cpu_user_cs_mask);
16066+#endif
16067+
16068+#endif
16069+#endif
16070+
16071+ }
16072+
16073 return retval;
16074 }
16075
16076@@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
16077 }
16078 }
16079
16080+#ifdef CONFIG_PAX_SEGMEXEC
16081+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
16082+ error = -EINVAL;
16083+ goto out_unlock;
16084+ }
16085+#endif
16086+
16087 fill_ldt(&ldt, &ldt_info);
16088 if (oldmode)
16089 ldt.avl = 0;
16090diff -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
16091--- linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c 2011-05-19 00:06:34.000000000 -0400
16092+++ linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c 2011-05-22 19:36:30.000000000 -0400
16093@@ -27,7 +27,7 @@
16094 #include <asm/cacheflush.h>
16095 #include <asm/debugreg.h>
16096
16097-static void set_idt(void *newidt, __u16 limit)
16098+static void set_idt(struct desc_struct *newidt, __u16 limit)
16099 {
16100 struct desc_ptr curidt;
16101
16102@@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
16103 }
16104
16105
16106-static void set_gdt(void *newgdt, __u16 limit)
16107+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
16108 {
16109 struct desc_ptr curgdt;
16110
16111@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
16112 }
16113
16114 control_page = page_address(image->control_code_page);
16115- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
16116+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
16117
16118 relocate_kernel_ptr = control_page;
16119 page_list[PA_CONTROL_PAGE] = __pa(control_page);
16120diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_amd.c linux-2.6.39.1/arch/x86/kernel/microcode_amd.c
16121--- linux-2.6.39.1/arch/x86/kernel/microcode_amd.c 2011-05-19 00:06:34.000000000 -0400
16122+++ linux-2.6.39.1/arch/x86/kernel/microcode_amd.c 2011-05-22 19:36:30.000000000 -0400
16123@@ -339,7 +339,7 @@ static void microcode_fini_cpu_amd(int c
16124 uci->mc = NULL;
16125 }
16126
16127-static struct microcode_ops microcode_amd_ops = {
16128+static const struct microcode_ops microcode_amd_ops = {
16129 .request_microcode_user = request_microcode_user,
16130 .request_microcode_fw = request_microcode_amd,
16131 .collect_cpu_info = collect_cpu_info_amd,
16132@@ -347,7 +347,7 @@ static struct microcode_ops microcode_am
16133 .microcode_fini_cpu = microcode_fini_cpu_amd,
16134 };
16135
16136-struct microcode_ops * __init init_amd_microcode(void)
16137+const struct microcode_ops * __init init_amd_microcode(void)
16138 {
16139 return &microcode_amd_ops;
16140 }
16141diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_core.c linux-2.6.39.1/arch/x86/kernel/microcode_core.c
16142--- linux-2.6.39.1/arch/x86/kernel/microcode_core.c 2011-05-19 00:06:34.000000000 -0400
16143+++ linux-2.6.39.1/arch/x86/kernel/microcode_core.c 2011-05-22 19:36:30.000000000 -0400
16144@@ -93,7 +93,7 @@ MODULE_LICENSE("GPL");
16145
16146 #define MICROCODE_VERSION "2.00"
16147
16148-static struct microcode_ops *microcode_ops;
16149+static const struct microcode_ops *microcode_ops;
16150
16151 /*
16152 * Synchronization.
16153diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_intel.c linux-2.6.39.1/arch/x86/kernel/microcode_intel.c
16154--- linux-2.6.39.1/arch/x86/kernel/microcode_intel.c 2011-05-19 00:06:34.000000000 -0400
16155+++ linux-2.6.39.1/arch/x86/kernel/microcode_intel.c 2011-05-22 19:36:30.000000000 -0400
16156@@ -440,13 +440,13 @@ static enum ucode_state request_microcod
16157
16158 static int get_ucode_user(void *to, const void *from, size_t n)
16159 {
16160- return copy_from_user(to, from, n);
16161+ return copy_from_user(to, (__force const void __user *)from, n);
16162 }
16163
16164 static enum ucode_state
16165 request_microcode_user(int cpu, const void __user *buf, size_t size)
16166 {
16167- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16168+ return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
16169 }
16170
16171 static void microcode_fini_cpu(int cpu)
16172@@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
16173 uci->mc = NULL;
16174 }
16175
16176-static struct microcode_ops microcode_intel_ops = {
16177+static const struct microcode_ops microcode_intel_ops = {
16178 .request_microcode_user = request_microcode_user,
16179 .request_microcode_fw = request_microcode_fw,
16180 .collect_cpu_info = collect_cpu_info,
16181@@ -465,7 +465,7 @@ static struct microcode_ops microcode_in
16182 .microcode_fini_cpu = microcode_fini_cpu,
16183 };
16184
16185-struct microcode_ops * __init init_intel_microcode(void)
16186+const struct microcode_ops * __init init_intel_microcode(void)
16187 {
16188 return &microcode_intel_ops;
16189 }
16190diff -urNp linux-2.6.39.1/arch/x86/kernel/module.c linux-2.6.39.1/arch/x86/kernel/module.c
16191--- linux-2.6.39.1/arch/x86/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
16192+++ linux-2.6.39.1/arch/x86/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
16193@@ -35,21 +35,66 @@
16194 #define DEBUGP(fmt...)
16195 #endif
16196
16197-void *module_alloc(unsigned long size)
16198+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16199 {
16200 if (PAGE_ALIGN(size) > MODULES_LEN)
16201 return NULL;
16202 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16203- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16204+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16205 -1, __builtin_return_address(0));
16206 }
16207
16208+void *module_alloc(unsigned long size)
16209+{
16210+
16211+#ifdef CONFIG_PAX_KERNEXEC
16212+ return __module_alloc(size, PAGE_KERNEL);
16213+#else
16214+ return __module_alloc(size, PAGE_KERNEL_EXEC);
16215+#endif
16216+
16217+}
16218+
16219 /* Free memory returned from module_alloc */
16220 void module_free(struct module *mod, void *module_region)
16221 {
16222 vfree(module_region);
16223 }
16224
16225+#ifdef CONFIG_PAX_KERNEXEC
16226+#ifdef CONFIG_X86_32
16227+void *module_alloc_exec(unsigned long size)
16228+{
16229+ struct vm_struct *area;
16230+
16231+ if (size == 0)
16232+ return NULL;
16233+
16234+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16235+ return area ? area->addr : NULL;
16236+}
16237+EXPORT_SYMBOL(module_alloc_exec);
16238+
16239+void module_free_exec(struct module *mod, void *module_region)
16240+{
16241+ vunmap(module_region);
16242+}
16243+EXPORT_SYMBOL(module_free_exec);
16244+#else
16245+void module_free_exec(struct module *mod, void *module_region)
16246+{
16247+ module_free(mod, module_region);
16248+}
16249+EXPORT_SYMBOL(module_free_exec);
16250+
16251+void *module_alloc_exec(unsigned long size)
16252+{
16253+ return __module_alloc(size, PAGE_KERNEL_RX);
16254+}
16255+EXPORT_SYMBOL(module_alloc_exec);
16256+#endif
16257+#endif
16258+
16259 /* We don't need anything special. */
16260 int module_frob_arch_sections(Elf_Ehdr *hdr,
16261 Elf_Shdr *sechdrs,
16262@@ -69,14 +114,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16263 unsigned int i;
16264 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16265 Elf32_Sym *sym;
16266- uint32_t *location;
16267+ uint32_t *plocation, location;
16268
16269 DEBUGP("Applying relocate section %u to %u\n", relsec,
16270 sechdrs[relsec].sh_info);
16271 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16272 /* This is where to make the change */
16273- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16274- + rel[i].r_offset;
16275+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16276+ location = (uint32_t)plocation;
16277+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16278+ plocation = ktla_ktva((void *)plocation);
16279 /* This is the symbol it is referring to. Note that all
16280 undefined symbols have been resolved. */
16281 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16282@@ -85,11 +132,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16283 switch (ELF32_R_TYPE(rel[i].r_info)) {
16284 case R_386_32:
16285 /* We add the value into the location given */
16286- *location += sym->st_value;
16287+ pax_open_kernel();
16288+ *plocation += sym->st_value;
16289+ pax_close_kernel();
16290 break;
16291 case R_386_PC32:
16292 /* Add the value, subtract its postition */
16293- *location += sym->st_value - (uint32_t)location;
16294+ pax_open_kernel();
16295+ *plocation += sym->st_value - location;
16296+ pax_close_kernel();
16297 break;
16298 default:
16299 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16300@@ -145,21 +196,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
16301 case R_X86_64_NONE:
16302 break;
16303 case R_X86_64_64:
16304+ pax_open_kernel();
16305 *(u64 *)loc = val;
16306+ pax_close_kernel();
16307 break;
16308 case R_X86_64_32:
16309+ pax_open_kernel();
16310 *(u32 *)loc = val;
16311+ pax_close_kernel();
16312 if (val != *(u32 *)loc)
16313 goto overflow;
16314 break;
16315 case R_X86_64_32S:
16316+ pax_open_kernel();
16317 *(s32 *)loc = val;
16318+ pax_close_kernel();
16319 if ((s64)val != *(s32 *)loc)
16320 goto overflow;
16321 break;
16322 case R_X86_64_PC32:
16323 val -= (u64)loc;
16324+ pax_open_kernel();
16325 *(u32 *)loc = val;
16326+ pax_close_kernel();
16327+
16328 #if 0
16329 if ((s64)val != *(s32 *)loc)
16330 goto overflow;
16331diff -urNp linux-2.6.39.1/arch/x86/kernel/paravirt.c linux-2.6.39.1/arch/x86/kernel/paravirt.c
16332--- linux-2.6.39.1/arch/x86/kernel/paravirt.c 2011-05-19 00:06:34.000000000 -0400
16333+++ linux-2.6.39.1/arch/x86/kernel/paravirt.c 2011-05-22 19:36:30.000000000 -0400
16334@@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
16335 * corresponding structure. */
16336 static void *get_call_destination(u8 type)
16337 {
16338- struct paravirt_patch_template tmpl = {
16339+ const struct paravirt_patch_template tmpl = {
16340 .pv_init_ops = pv_init_ops,
16341 .pv_time_ops = pv_time_ops,
16342 .pv_cpu_ops = pv_cpu_ops,
16343@@ -133,6 +133,9 @@ static void *get_call_destination(u8 typ
16344 .pv_lock_ops = pv_lock_ops,
16345 #endif
16346 };
16347+
16348+ pax_track_stack();
16349+
16350 return *((void **)&tmpl + type);
16351 }
16352
16353@@ -145,14 +148,14 @@ unsigned paravirt_patch_default(u8 type,
16354 if (opfunc == NULL)
16355 /* If there's no function, patch it with a ud2a (BUG) */
16356 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16357- else if (opfunc == _paravirt_nop)
16358+ else if (opfunc == (void *)_paravirt_nop)
16359 /* If the operation is a nop, then nop the callsite */
16360 ret = paravirt_patch_nop();
16361
16362 /* identity functions just return their single argument */
16363- else if (opfunc == _paravirt_ident_32)
16364+ else if (opfunc == (void *)_paravirt_ident_32)
16365 ret = paravirt_patch_ident_32(insnbuf, len);
16366- else if (opfunc == _paravirt_ident_64)
16367+ else if (opfunc == (void *)_paravirt_ident_64)
16368 ret = paravirt_patch_ident_64(insnbuf, len);
16369
16370 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16371@@ -178,7 +181,7 @@ unsigned paravirt_patch_insns(void *insn
16372 if (insn_len > len || start == NULL)
16373 insn_len = len;
16374 else
16375- memcpy(insnbuf, start, insn_len);
16376+ memcpy(insnbuf, ktla_ktva(start), insn_len);
16377
16378 return insn_len;
16379 }
16380@@ -294,22 +297,22 @@ void arch_flush_lazy_mmu_mode(void)
16381 preempt_enable();
16382 }
16383
16384-struct pv_info pv_info = {
16385+struct pv_info pv_info __read_only = {
16386 .name = "bare hardware",
16387 .paravirt_enabled = 0,
16388 .kernel_rpl = 0,
16389 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
16390 };
16391
16392-struct pv_init_ops pv_init_ops = {
16393+struct pv_init_ops pv_init_ops __read_only = {
16394 .patch = native_patch,
16395 };
16396
16397-struct pv_time_ops pv_time_ops = {
16398+struct pv_time_ops pv_time_ops __read_only = {
16399 .sched_clock = native_sched_clock,
16400 };
16401
16402-struct pv_irq_ops pv_irq_ops = {
16403+struct pv_irq_ops pv_irq_ops __read_only = {
16404 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16405 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16406 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16407@@ -321,7 +324,7 @@ struct pv_irq_ops pv_irq_ops = {
16408 #endif
16409 };
16410
16411-struct pv_cpu_ops pv_cpu_ops = {
16412+struct pv_cpu_ops pv_cpu_ops __read_only = {
16413 .cpuid = native_cpuid,
16414 .get_debugreg = native_get_debugreg,
16415 .set_debugreg = native_set_debugreg,
16416@@ -382,7 +385,7 @@ struct pv_cpu_ops pv_cpu_ops = {
16417 .end_context_switch = paravirt_nop,
16418 };
16419
16420-struct pv_apic_ops pv_apic_ops = {
16421+struct pv_apic_ops pv_apic_ops __read_only = {
16422 #ifdef CONFIG_X86_LOCAL_APIC
16423 .startup_ipi_hook = paravirt_nop,
16424 #endif
16425@@ -396,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = {
16426 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16427 #endif
16428
16429-struct pv_mmu_ops pv_mmu_ops = {
16430+struct pv_mmu_ops pv_mmu_ops __read_only = {
16431
16432 .read_cr2 = native_read_cr2,
16433 .write_cr2 = native_write_cr2,
16434@@ -465,6 +468,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16435 },
16436
16437 .set_fixmap = native_set_fixmap,
16438+
16439+#ifdef CONFIG_PAX_KERNEXEC
16440+ .pax_open_kernel = native_pax_open_kernel,
16441+ .pax_close_kernel = native_pax_close_kernel,
16442+#endif
16443+
16444 };
16445
16446 EXPORT_SYMBOL_GPL(pv_time_ops);
16447diff -urNp linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c
16448--- linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c 2011-05-19 00:06:34.000000000 -0400
16449+++ linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c 2011-05-22 19:36:30.000000000 -0400
16450@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
16451 arch_spin_lock(lock);
16452 }
16453
16454-struct pv_lock_ops pv_lock_ops = {
16455+struct pv_lock_ops pv_lock_ops __read_only = {
16456 #ifdef CONFIG_SMP
16457 .spin_is_locked = __ticket_spin_is_locked,
16458 .spin_is_contended = __ticket_spin_is_contended,
16459diff -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
16460--- linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c 2011-05-19 00:06:34.000000000 -0400
16461+++ linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c 2011-05-22 19:36:30.000000000 -0400
16462@@ -179,13 +179,13 @@ static void calioc2_dump_error_regs(stru
16463 static void calgary_init_bitmap_from_tce_table(struct iommu_table *tbl);
16464 static void get_tce_space_from_tar(void);
16465
16466-static struct cal_chipset_ops calgary_chip_ops = {
16467+static const struct cal_chipset_ops calgary_chip_ops = {
16468 .handle_quirks = calgary_handle_quirks,
16469 .tce_cache_blast = calgary_tce_cache_blast,
16470 .dump_error_regs = calgary_dump_error_regs
16471 };
16472
16473-static struct cal_chipset_ops calioc2_chip_ops = {
16474+static const struct cal_chipset_ops calioc2_chip_ops = {
16475 .handle_quirks = calioc2_handle_quirks,
16476 .tce_cache_blast = calioc2_tce_cache_blast,
16477 .dump_error_regs = calioc2_dump_error_regs
16478@@ -476,7 +476,7 @@ static void calgary_free_coherent(struct
16479 free_pages((unsigned long)vaddr, get_order(size));
16480 }
16481
16482-static struct dma_map_ops calgary_dma_ops = {
16483+static const struct dma_map_ops calgary_dma_ops = {
16484 .alloc_coherent = calgary_alloc_coherent,
16485 .free_coherent = calgary_free_coherent,
16486 .map_sg = calgary_map_sg,
16487diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-dma.c linux-2.6.39.1/arch/x86/kernel/pci-dma.c
16488--- linux-2.6.39.1/arch/x86/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
16489+++ linux-2.6.39.1/arch/x86/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
16490@@ -16,7 +16,7 @@
16491
16492 static int forbid_dac __read_mostly;
16493
16494-struct dma_map_ops *dma_ops = &nommu_dma_ops;
16495+const struct dma_map_ops *dma_ops = &nommu_dma_ops;
16496 EXPORT_SYMBOL(dma_ops);
16497
16498 static int iommu_sac_force __read_mostly;
16499@@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
16500
16501 int dma_supported(struct device *dev, u64 mask)
16502 {
16503- struct dma_map_ops *ops = get_dma_ops(dev);
16504+ const struct dma_map_ops *ops = get_dma_ops(dev);
16505
16506 #ifdef CONFIG_PCI
16507 if (mask > 0xffffffff && forbid_dac > 0) {
16508diff -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
16509--- linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c 2011-05-19 00:06:34.000000000 -0400
16510+++ linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c 2011-05-22 19:36:30.000000000 -0400
16511@@ -695,7 +695,7 @@ static __init int init_amd_gatt(struct a
16512 return -1;
16513 }
16514
16515-static struct dma_map_ops gart_dma_ops = {
16516+static const struct dma_map_ops gart_dma_ops = {
16517 .map_sg = gart_map_sg,
16518 .unmap_sg = gart_unmap_sg,
16519 .map_page = gart_map_page,
16520diff -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
16521--- linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c 2011-05-19 00:06:34.000000000 -0400
16522+++ linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c 2011-05-22 19:36:30.000000000 -0400
16523@@ -2,7 +2,7 @@
16524 #include <asm/iommu_table.h>
16525 #include <linux/string.h>
16526 #include <linux/kallsyms.h>
16527-
16528+#include <linux/sched.h>
16529
16530 #define DEBUG 1
16531
16532@@ -53,6 +53,8 @@ void __init check_iommu_entries(struct i
16533 char sym_p[KSYM_SYMBOL_LEN];
16534 char sym_q[KSYM_SYMBOL_LEN];
16535
16536+ pax_track_stack();
16537+
16538 /* Simple cyclic dependency checker. */
16539 for (p = start; p < finish; p++) {
16540 q = find_dependents_of(start, finish, p);
16541diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-nommu.c linux-2.6.39.1/arch/x86/kernel/pci-nommu.c
16542--- linux-2.6.39.1/arch/x86/kernel/pci-nommu.c 2011-05-19 00:06:34.000000000 -0400
16543+++ linux-2.6.39.1/arch/x86/kernel/pci-nommu.c 2011-05-22 19:36:30.000000000 -0400
16544@@ -95,7 +95,7 @@ static void nommu_sync_sg_for_device(str
16545 flush_write_buffers();
16546 }
16547
16548-struct dma_map_ops nommu_dma_ops = {
16549+const struct dma_map_ops nommu_dma_ops = {
16550 .alloc_coherent = dma_generic_alloc_coherent,
16551 .free_coherent = nommu_free_coherent,
16552 .map_sg = nommu_map_sg,
16553diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c
16554--- linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
16555+++ linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
16556@@ -26,7 +26,7 @@ static void *x86_swiotlb_alloc_coherent(
16557 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
16558 }
16559
16560-static struct dma_map_ops swiotlb_dma_ops = {
16561+static const struct dma_map_ops swiotlb_dma_ops = {
16562 .mapping_error = swiotlb_dma_mapping_error,
16563 .alloc_coherent = x86_swiotlb_alloc_coherent,
16564 .free_coherent = swiotlb_free_coherent,
16565diff -urNp linux-2.6.39.1/arch/x86/kernel/process_32.c linux-2.6.39.1/arch/x86/kernel/process_32.c
16566--- linux-2.6.39.1/arch/x86/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
16567+++ linux-2.6.39.1/arch/x86/kernel/process_32.c 2011-05-22 19:36:30.000000000 -0400
16568@@ -65,6 +65,7 @@ asmlinkage void ret_from_fork(void) __as
16569 unsigned long thread_saved_pc(struct task_struct *tsk)
16570 {
16571 return ((unsigned long *)tsk->thread.sp)[3];
16572+//XXX return tsk->thread.eip;
16573 }
16574
16575 #ifndef CONFIG_SMP
16576@@ -126,15 +127,14 @@ void __show_regs(struct pt_regs *regs, i
16577 unsigned long sp;
16578 unsigned short ss, gs;
16579
16580- if (user_mode_vm(regs)) {
16581+ if (user_mode(regs)) {
16582 sp = regs->sp;
16583 ss = regs->ss & 0xffff;
16584- gs = get_user_gs(regs);
16585 } else {
16586 sp = kernel_stack_pointer(regs);
16587 savesegment(ss, ss);
16588- savesegment(gs, gs);
16589 }
16590+ gs = get_user_gs(regs);
16591
16592 show_regs_common();
16593
16594@@ -196,13 +196,14 @@ int copy_thread(unsigned long clone_flag
16595 struct task_struct *tsk;
16596 int err;
16597
16598- childregs = task_pt_regs(p);
16599+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16600 *childregs = *regs;
16601 childregs->ax = 0;
16602 childregs->sp = sp;
16603
16604 p->thread.sp = (unsigned long) childregs;
16605 p->thread.sp0 = (unsigned long) (childregs+1);
16606+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16607
16608 p->thread.ip = (unsigned long) ret_from_fork;
16609
16610@@ -293,7 +294,7 @@ __switch_to(struct task_struct *prev_p,
16611 struct thread_struct *prev = &prev_p->thread,
16612 *next = &next_p->thread;
16613 int cpu = smp_processor_id();
16614- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16615+ struct tss_struct *tss = init_tss + cpu;
16616 bool preload_fpu;
16617
16618 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16619@@ -328,6 +329,10 @@ __switch_to(struct task_struct *prev_p,
16620 */
16621 lazy_save_gs(prev->gs);
16622
16623+#ifdef CONFIG_PAX_MEMORY_UDEREF
16624+ __set_fs(task_thread_info(next_p)->addr_limit);
16625+#endif
16626+
16627 /*
16628 * Load the per-thread Thread-Local Storage descriptor.
16629 */
16630@@ -363,6 +368,9 @@ __switch_to(struct task_struct *prev_p,
16631 */
16632 arch_end_context_switch(next_p);
16633
16634+ percpu_write(current_task, next_p);
16635+ percpu_write(current_tinfo, &next_p->tinfo);
16636+
16637 if (preload_fpu)
16638 __math_state_restore();
16639
16640@@ -372,8 +380,6 @@ __switch_to(struct task_struct *prev_p,
16641 if (prev->gs | next->gs)
16642 lazy_load_gs(next->gs);
16643
16644- percpu_write(current_task, next_p);
16645-
16646 return prev_p;
16647 }
16648
16649@@ -403,4 +409,3 @@ unsigned long get_wchan(struct task_stru
16650 } while (count++ < 16);
16651 return 0;
16652 }
16653-
16654diff -urNp linux-2.6.39.1/arch/x86/kernel/process_64.c linux-2.6.39.1/arch/x86/kernel/process_64.c
16655--- linux-2.6.39.1/arch/x86/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
16656+++ linux-2.6.39.1/arch/x86/kernel/process_64.c 2011-05-22 19:36:30.000000000 -0400
16657@@ -87,7 +87,7 @@ static void __exit_idle(void)
16658 void exit_idle(void)
16659 {
16660 /* idle loop has pid 0 */
16661- if (current->pid)
16662+ if (task_pid_nr(current))
16663 return;
16664 __exit_idle();
16665 }
16666@@ -260,8 +260,7 @@ int copy_thread(unsigned long clone_flag
16667 struct pt_regs *childregs;
16668 struct task_struct *me = current;
16669
16670- childregs = ((struct pt_regs *)
16671- (THREAD_SIZE + task_stack_page(p))) - 1;
16672+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16673 *childregs = *regs;
16674
16675 childregs->ax = 0;
16676@@ -273,6 +272,7 @@ int copy_thread(unsigned long clone_flag
16677 p->thread.sp = (unsigned long) childregs;
16678 p->thread.sp0 = (unsigned long) (childregs+1);
16679 p->thread.usersp = me->thread.usersp;
16680+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16681
16682 set_tsk_thread_flag(p, TIF_FORK);
16683
16684@@ -376,7 +376,7 @@ __switch_to(struct task_struct *prev_p,
16685 struct thread_struct *prev = &prev_p->thread;
16686 struct thread_struct *next = &next_p->thread;
16687 int cpu = smp_processor_id();
16688- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16689+ struct tss_struct *tss = init_tss + cpu;
16690 unsigned fsindex, gsindex;
16691 bool preload_fpu;
16692
16693@@ -472,10 +472,9 @@ __switch_to(struct task_struct *prev_p,
16694 prev->usersp = percpu_read(old_rsp);
16695 percpu_write(old_rsp, next->usersp);
16696 percpu_write(current_task, next_p);
16697+ percpu_write(current_tinfo, &next_p->tinfo);
16698
16699- percpu_write(kernel_stack,
16700- (unsigned long)task_stack_page(next_p) +
16701- THREAD_SIZE - KERNEL_STACK_OFFSET);
16702+ percpu_write(kernel_stack, next->sp0);
16703
16704 /*
16705 * Now maybe reload the debug registers and handle I/O bitmaps
16706@@ -537,12 +536,11 @@ unsigned long get_wchan(struct task_stru
16707 if (!p || p == current || p->state == TASK_RUNNING)
16708 return 0;
16709 stack = (unsigned long)task_stack_page(p);
16710- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16711+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16712 return 0;
16713 fp = *(u64 *)(p->thread.sp);
16714 do {
16715- if (fp < (unsigned long)stack ||
16716- fp >= (unsigned long)stack+THREAD_SIZE)
16717+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16718 return 0;
16719 ip = *(u64 *)(fp+8);
16720 if (!in_sched_functions(ip))
16721diff -urNp linux-2.6.39.1/arch/x86/kernel/process.c linux-2.6.39.1/arch/x86/kernel/process.c
16722--- linux-2.6.39.1/arch/x86/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
16723+++ linux-2.6.39.1/arch/x86/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
16724@@ -48,16 +48,33 @@ void free_thread_xstate(struct task_stru
16725
16726 void free_thread_info(struct thread_info *ti)
16727 {
16728- free_thread_xstate(ti->task);
16729 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16730 }
16731
16732+static struct kmem_cache *task_struct_cachep;
16733+
16734 void arch_task_cache_init(void)
16735 {
16736- task_xstate_cachep =
16737- kmem_cache_create("task_xstate", xstate_size,
16738+ /* create a slab on which task_structs can be allocated */
16739+ task_struct_cachep =
16740+ kmem_cache_create("task_struct", sizeof(struct task_struct),
16741+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16742+
16743+ task_xstate_cachep =
16744+ kmem_cache_create("task_xstate", xstate_size,
16745 __alignof__(union thread_xstate),
16746- SLAB_PANIC | SLAB_NOTRACK, NULL);
16747+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16748+}
16749+
16750+struct task_struct *alloc_task_struct_node(int node)
16751+{
16752+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16753+}
16754+
16755+void free_task_struct(struct task_struct *task)
16756+{
16757+ free_thread_xstate(task);
16758+ kmem_cache_free(task_struct_cachep, task);
16759 }
16760
16761 /*
16762@@ -70,7 +87,7 @@ void exit_thread(void)
16763 unsigned long *bp = t->io_bitmap_ptr;
16764
16765 if (bp) {
16766- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16767+ struct tss_struct *tss = init_tss + get_cpu();
16768
16769 t->io_bitmap_ptr = NULL;
16770 clear_thread_flag(TIF_IO_BITMAP);
16771@@ -106,7 +123,7 @@ void show_regs_common(void)
16772
16773 printk(KERN_CONT "\n");
16774 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16775- current->pid, current->comm, print_tainted(),
16776+ task_pid_nr(current), current->comm, print_tainted(),
16777 init_utsname()->release,
16778 (int)strcspn(init_utsname()->version, " "),
16779 init_utsname()->version);
16780@@ -120,6 +137,9 @@ void flush_thread(void)
16781 {
16782 struct task_struct *tsk = current;
16783
16784+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16785+ loadsegment(gs, 0);
16786+#endif
16787 flush_ptrace_hw_breakpoint(tsk);
16788 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16789 /*
16790@@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), voi
16791 regs.di = (unsigned long) arg;
16792
16793 #ifdef CONFIG_X86_32
16794- regs.ds = __USER_DS;
16795- regs.es = __USER_DS;
16796+ regs.ds = __KERNEL_DS;
16797+ regs.es = __KERNEL_DS;
16798 regs.fs = __KERNEL_PERCPU;
16799- regs.gs = __KERNEL_STACK_CANARY;
16800+ savesegment(gs, regs.gs);
16801 #else
16802 regs.ss = __KERNEL_DS;
16803 #endif
16804@@ -401,7 +421,7 @@ void default_idle(void)
16805 EXPORT_SYMBOL(default_idle);
16806 #endif
16807
16808-void stop_this_cpu(void *dummy)
16809+__noreturn void stop_this_cpu(void *dummy)
16810 {
16811 local_irq_disable();
16812 /*
16813@@ -665,16 +685,34 @@ static int __init idle_setup(char *str)
16814 }
16815 early_param("idle", idle_setup);
16816
16817-unsigned long arch_align_stack(unsigned long sp)
16818+#ifdef CONFIG_PAX_RANDKSTACK
16819+asmlinkage void pax_randomize_kstack(void)
16820 {
16821- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16822- sp -= get_random_int() % 8192;
16823- return sp & ~0xf;
16824-}
16825+ struct thread_struct *thread = &current->thread;
16826+ unsigned long time;
16827
16828-unsigned long arch_randomize_brk(struct mm_struct *mm)
16829-{
16830- unsigned long range_end = mm->brk + 0x02000000;
16831- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16832-}
16833+ if (!randomize_va_space)
16834+ return;
16835+
16836+ rdtscl(time);
16837+
16838+ /* P4 seems to return a 0 LSB, ignore it */
16839+#ifdef CONFIG_MPENTIUM4
16840+ time &= 0x3EUL;
16841+ time <<= 2;
16842+#elif defined(CONFIG_X86_64)
16843+ time &= 0xFUL;
16844+ time <<= 4;
16845+#else
16846+ time &= 0x1FUL;
16847+ time <<= 3;
16848+#endif
16849+
16850+ thread->sp0 ^= time;
16851+ load_sp0(init_tss + smp_processor_id(), thread);
16852
16853+#ifdef CONFIG_X86_64
16854+ percpu_write(kernel_stack, thread->sp0);
16855+#endif
16856+}
16857+#endif
16858diff -urNp linux-2.6.39.1/arch/x86/kernel/ptrace.c linux-2.6.39.1/arch/x86/kernel/ptrace.c
16859--- linux-2.6.39.1/arch/x86/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
16860+++ linux-2.6.39.1/arch/x86/kernel/ptrace.c 2011-05-22 19:36:30.000000000 -0400
16861@@ -821,7 +821,7 @@ long arch_ptrace(struct task_struct *chi
16862 unsigned long addr, unsigned long data)
16863 {
16864 int ret;
16865- unsigned long __user *datap = (unsigned long __user *)data;
16866+ unsigned long __user *datap = (__force unsigned long __user *)data;
16867
16868 switch (request) {
16869 /* read the word at location addr in the USER area. */
16870@@ -906,14 +906,14 @@ long arch_ptrace(struct task_struct *chi
16871 if ((int) addr < 0)
16872 return -EIO;
16873 ret = do_get_thread_area(child, addr,
16874- (struct user_desc __user *)data);
16875+ (__force struct user_desc __user *) data);
16876 break;
16877
16878 case PTRACE_SET_THREAD_AREA:
16879 if ((int) addr < 0)
16880 return -EIO;
16881 ret = do_set_thread_area(child, addr,
16882- (struct user_desc __user *)data, 0);
16883+ (__force struct user_desc __user *) data, 0);
16884 break;
16885 #endif
16886
16887@@ -1330,7 +1330,7 @@ static void fill_sigtrap_info(struct tas
16888 memset(info, 0, sizeof(*info));
16889 info->si_signo = SIGTRAP;
16890 info->si_code = si_code;
16891- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16892+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16893 }
16894
16895 void user_single_step_siginfo(struct task_struct *tsk,
16896@@ -1363,7 +1363,7 @@ void send_sigtrap(struct task_struct *ts
16897 * We must return the syscall number to actually look up in the table.
16898 * This can be -1L to skip running any syscall at all.
16899 */
16900-asmregparm long syscall_trace_enter(struct pt_regs *regs)
16901+long syscall_trace_enter(struct pt_regs *regs)
16902 {
16903 long ret = 0;
16904
16905@@ -1408,7 +1408,7 @@ asmregparm long syscall_trace_enter(stru
16906 return ret ?: regs->orig_ax;
16907 }
16908
16909-asmregparm void syscall_trace_leave(struct pt_regs *regs)
16910+void syscall_trace_leave(struct pt_regs *regs)
16911 {
16912 bool step;
16913
16914diff -urNp linux-2.6.39.1/arch/x86/kernel/pvclock.c linux-2.6.39.1/arch/x86/kernel/pvclock.c
16915--- linux-2.6.39.1/arch/x86/kernel/pvclock.c 2011-05-19 00:06:34.000000000 -0400
16916+++ linux-2.6.39.1/arch/x86/kernel/pvclock.c 2011-05-22 19:36:30.000000000 -0400
16917@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvc
16918 return pv_tsc_khz;
16919 }
16920
16921-static atomic64_t last_value = ATOMIC64_INIT(0);
16922+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16923
16924 void pvclock_resume(void)
16925 {
16926- atomic64_set(&last_value, 0);
16927+ atomic64_set_unchecked(&last_value, 0);
16928 }
16929
16930 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16931@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct
16932 * updating at the same time, and one of them could be slightly behind,
16933 * making the assumption that last_value always go forward fail to hold.
16934 */
16935- last = atomic64_read(&last_value);
16936+ last = atomic64_read_unchecked(&last_value);
16937 do {
16938 if (ret < last)
16939 return last;
16940- last = atomic64_cmpxchg(&last_value, last, ret);
16941+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16942 } while (unlikely(last != ret));
16943
16944 return ret;
16945diff -urNp linux-2.6.39.1/arch/x86/kernel/reboot.c linux-2.6.39.1/arch/x86/kernel/reboot.c
16946--- linux-2.6.39.1/arch/x86/kernel/reboot.c 2011-05-19 00:06:34.000000000 -0400
16947+++ linux-2.6.39.1/arch/x86/kernel/reboot.c 2011-05-23 17:07:00.000000000 -0400
16948@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16949 EXPORT_SYMBOL(pm_power_off);
16950
16951 static const struct desc_ptr no_idt = {};
16952-static int reboot_mode;
16953+static unsigned short reboot_mode;
16954 enum reboot_type reboot_type = BOOT_KBD;
16955 int reboot_force;
16956
16957@@ -307,13 +307,17 @@ core_initcall(reboot_init);
16958 extern const unsigned char machine_real_restart_asm[];
16959 extern const u64 machine_real_restart_gdt[3];
16960
16961-void machine_real_restart(unsigned int type)
16962+__noreturn void machine_real_restart(unsigned int type)
16963 {
16964 void *restart_va;
16965 unsigned long restart_pa;
16966- void (*restart_lowmem)(unsigned int);
16967+ void (* __noreturn restart_lowmem)(unsigned int);
16968 u64 *lowmem_gdt;
16969
16970+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16971+ struct desc_struct *gdt;
16972+#endif
16973+
16974 local_irq_disable();
16975
16976 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16977@@ -339,14 +343,14 @@ void machine_real_restart(unsigned int t
16978 boot)". This seems like a fairly standard thing that gets set by
16979 REBOOT.COM programs, and the previous reset routine did this
16980 too. */
16981- *((unsigned short *)0x472) = reboot_mode;
16982+ *(unsigned short *)(__va(0x472)) = reboot_mode;
16983
16984 /* Patch the GDT in the low memory trampoline */
16985 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16986
16987 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16988 restart_pa = virt_to_phys(restart_va);
16989- restart_lowmem = (void (*)(unsigned int))restart_pa;
16990+ restart_lowmem = (void *)restart_pa;
16991
16992 /* GDT[0]: GDT self-pointer */
16993 lowmem_gdt[0] =
16994@@ -357,7 +361,33 @@ void machine_real_restart(unsigned int t
16995 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16996
16997 /* Jump to the identity-mapped low memory code */
16998+
16999+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17000+ gdt = get_cpu_gdt_table(smp_processor_id());
17001+ pax_open_kernel();
17002+#ifdef CONFIG_PAX_MEMORY_UDEREF
17003+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
17004+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
17005+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
17006+#endif
17007+#ifdef CONFIG_PAX_KERNEXEC
17008+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
17009+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
17010+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
17011+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
17012+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
17013+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
17014+#endif
17015+ pax_close_kernel();
17016+#endif
17017+
17018+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17019+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
17020+ unreachable();
17021+#else
17022 restart_lowmem(type);
17023+#endif
17024+
17025 }
17026 #ifdef CONFIG_APM_MODULE
17027 EXPORT_SYMBOL(machine_real_restart);
17028@@ -478,7 +508,7 @@ void __attribute__((weak)) mach_reboot_f
17029 {
17030 }
17031
17032-static void native_machine_emergency_restart(void)
17033+__noreturn static void native_machine_emergency_restart(void)
17034 {
17035 int i;
17036
17037@@ -593,13 +623,13 @@ void native_machine_shutdown(void)
17038 #endif
17039 }
17040
17041-static void __machine_emergency_restart(int emergency)
17042+static __noreturn void __machine_emergency_restart(int emergency)
17043 {
17044 reboot_emergency = emergency;
17045 machine_ops.emergency_restart();
17046 }
17047
17048-static void native_machine_restart(char *__unused)
17049+static __noreturn void native_machine_restart(char *__unused)
17050 {
17051 printk("machine restart\n");
17052
17053@@ -608,7 +638,7 @@ static void native_machine_restart(char
17054 __machine_emergency_restart(0);
17055 }
17056
17057-static void native_machine_halt(void)
17058+static __noreturn void native_machine_halt(void)
17059 {
17060 /* stop other cpus and apics */
17061 machine_shutdown();
17062@@ -619,7 +649,7 @@ static void native_machine_halt(void)
17063 stop_this_cpu(NULL);
17064 }
17065
17066-static void native_machine_power_off(void)
17067+__noreturn static void native_machine_power_off(void)
17068 {
17069 if (pm_power_off) {
17070 if (!reboot_force)
17071@@ -628,6 +658,7 @@ static void native_machine_power_off(voi
17072 }
17073 /* a fallback in case there is no PM info available */
17074 tboot_shutdown(TB_SHUTDOWN_HALT);
17075+ unreachable();
17076 }
17077
17078 struct machine_ops machine_ops = {
17079diff -urNp linux-2.6.39.1/arch/x86/kernel/setup.c linux-2.6.39.1/arch/x86/kernel/setup.c
17080--- linux-2.6.39.1/arch/x86/kernel/setup.c 2011-06-03 00:04:13.000000000 -0400
17081+++ linux-2.6.39.1/arch/x86/kernel/setup.c 2011-06-03 00:32:04.000000000 -0400
17082@@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
17083 * area (640->1Mb) as ram even though it is not.
17084 * take them out.
17085 */
17086- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
17087+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
17088 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
17089 }
17090
17091@@ -775,14 +775,14 @@ void __init setup_arch(char **cmdline_p)
17092
17093 if (!boot_params.hdr.root_flags)
17094 root_mountflags &= ~MS_RDONLY;
17095- init_mm.start_code = (unsigned long) _text;
17096- init_mm.end_code = (unsigned long) _etext;
17097+ init_mm.start_code = ktla_ktva((unsigned long) _text);
17098+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
17099 init_mm.end_data = (unsigned long) _edata;
17100 init_mm.brk = _brk_end;
17101
17102- code_resource.start = virt_to_phys(_text);
17103- code_resource.end = virt_to_phys(_etext)-1;
17104- data_resource.start = virt_to_phys(_etext);
17105+ code_resource.start = virt_to_phys(ktla_ktva(_text));
17106+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
17107+ data_resource.start = virt_to_phys(_sdata);
17108 data_resource.end = virt_to_phys(_edata)-1;
17109 bss_resource.start = virt_to_phys(&__bss_start);
17110 bss_resource.end = virt_to_phys(&__bss_stop)-1;
17111diff -urNp linux-2.6.39.1/arch/x86/kernel/setup_percpu.c linux-2.6.39.1/arch/x86/kernel/setup_percpu.c
17112--- linux-2.6.39.1/arch/x86/kernel/setup_percpu.c 2011-05-19 00:06:34.000000000 -0400
17113+++ linux-2.6.39.1/arch/x86/kernel/setup_percpu.c 2011-06-04 20:08:30.000000000 -0400
17114@@ -21,19 +21,17 @@
17115 #include <asm/cpu.h>
17116 #include <asm/stackprotector.h>
17117
17118-DEFINE_PER_CPU(int, cpu_number);
17119+#ifdef CONFIG_SMP
17120+DEFINE_PER_CPU(unsigned int, cpu_number);
17121 EXPORT_PER_CPU_SYMBOL(cpu_number);
17122+#endif
17123
17124-#ifdef CONFIG_X86_64
17125 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
17126-#else
17127-#define BOOT_PERCPU_OFFSET 0
17128-#endif
17129
17130 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
17131 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
17132
17133-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
17134+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
17135 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17136 };
17137 EXPORT_SYMBOL(__per_cpu_offset);
17138@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
17139 {
17140 #ifdef CONFIG_X86_32
17141 struct desc_struct gdt;
17142+ unsigned long base = per_cpu_offset(cpu);
17143
17144- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17145- 0x2 | DESCTYPE_S, 0x8);
17146- gdt.s = 1;
17147+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17148+ 0x83 | DESCTYPE_S, 0xC);
17149 write_gdt_entry(get_cpu_gdt_table(cpu),
17150 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17151 #endif
17152@@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
17153 /* alrighty, percpu areas up and running */
17154 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17155 for_each_possible_cpu(cpu) {
17156+#ifdef CONFIG_CC_STACKPROTECTOR
17157+#ifdef CONFIG_X86_32
17158+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
17159+#endif
17160+#endif
17161 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17162 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17163 per_cpu(cpu_number, cpu) = cpu;
17164@@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17165 */
17166 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17167 #endif
17168+#ifdef CONFIG_CC_STACKPROTECTOR
17169+#ifdef CONFIG_X86_32
17170+ if (!cpu)
17171+ per_cpu(stack_canary.canary, cpu) = canary;
17172+#endif
17173+#endif
17174 /*
17175 * Up to this point, the boot CPU has been using .init.data
17176 * area. Reload any changed state for the boot CPU.
17177diff -urNp linux-2.6.39.1/arch/x86/kernel/signal.c linux-2.6.39.1/arch/x86/kernel/signal.c
17178--- linux-2.6.39.1/arch/x86/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
17179+++ linux-2.6.39.1/arch/x86/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
17180@@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
17181 * Align the stack pointer according to the i386 ABI,
17182 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17183 */
17184- sp = ((sp + 4) & -16ul) - 4;
17185+ sp = ((sp - 12) & -16ul) - 4;
17186 #else /* !CONFIG_X86_32 */
17187 sp = round_down(sp, 16) - 8;
17188 #endif
17189@@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
17190 * Return an always-bogus address instead so we will die with SIGSEGV.
17191 */
17192 if (onsigstack && !likely(on_sig_stack(sp)))
17193- return (void __user *)-1L;
17194+ return (__force void __user *)-1L;
17195
17196 /* save i387 state */
17197 if (used_math() && save_i387_xstate(*fpstate) < 0)
17198- return (void __user *)-1L;
17199+ return (__force void __user *)-1L;
17200
17201 return (void __user *)sp;
17202 }
17203@@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
17204 }
17205
17206 if (current->mm->context.vdso)
17207- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17208+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17209 else
17210- restorer = &frame->retcode;
17211+ restorer = (void __user *)&frame->retcode;
17212 if (ka->sa.sa_flags & SA_RESTORER)
17213 restorer = ka->sa.sa_restorer;
17214
17215@@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
17216 * reasons and because gdb uses it as a signature to notice
17217 * signal handler stack frames.
17218 */
17219- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17220+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17221
17222 if (err)
17223 return -EFAULT;
17224@@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
17225 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17226
17227 /* Set up to return from userspace. */
17228- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17229+ if (current->mm->context.vdso)
17230+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17231+ else
17232+ restorer = (void __user *)&frame->retcode;
17233 if (ka->sa.sa_flags & SA_RESTORER)
17234 restorer = ka->sa.sa_restorer;
17235 put_user_ex(restorer, &frame->pretcode);
17236@@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
17237 * reasons and because gdb uses it as a signature to notice
17238 * signal handler stack frames.
17239 */
17240- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17241+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17242 } put_user_catch(err);
17243
17244 if (err)
17245@@ -773,6 +776,8 @@ static void do_signal(struct pt_regs *re
17246 int signr;
17247 sigset_t *oldset;
17248
17249+ pax_track_stack();
17250+
17251 /*
17252 * We want the common case to go fast, which is why we may in certain
17253 * cases get here from kernel mode. Just return without doing anything
17254@@ -780,7 +785,7 @@ static void do_signal(struct pt_regs *re
17255 * X86_32: vm86 regs switched out by assembly code before reaching
17256 * here, so testing against kernel CS suffices.
17257 */
17258- if (!user_mode(regs))
17259+ if (!user_mode_novm(regs))
17260 return;
17261
17262 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
17263diff -urNp linux-2.6.39.1/arch/x86/kernel/smpboot.c linux-2.6.39.1/arch/x86/kernel/smpboot.c
17264--- linux-2.6.39.1/arch/x86/kernel/smpboot.c 2011-05-19 00:06:34.000000000 -0400
17265+++ linux-2.6.39.1/arch/x86/kernel/smpboot.c 2011-05-22 19:36:30.000000000 -0400
17266@@ -696,17 +696,20 @@ static int __cpuinit do_boot_cpu(int api
17267 set_idle_for_cpu(cpu, c_idle.idle);
17268 do_rest:
17269 per_cpu(current_task, cpu) = c_idle.idle;
17270+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17271 #ifdef CONFIG_X86_32
17272 /* Stack for startup_32 can be just as for start_secondary onwards */
17273 irq_ctx_init(cpu);
17274 #else
17275 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17276 initial_gs = per_cpu_offset(cpu);
17277- per_cpu(kernel_stack, cpu) =
17278- (unsigned long)task_stack_page(c_idle.idle) -
17279- KERNEL_STACK_OFFSET + THREAD_SIZE;
17280+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17281 #endif
17282+
17283+ pax_open_kernel();
17284 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17285+ pax_close_kernel();
17286+
17287 initial_code = (unsigned long)start_secondary;
17288 stack_start = c_idle.idle->thread.sp;
17289
17290@@ -848,6 +851,12 @@ int __cpuinit native_cpu_up(unsigned int
17291
17292 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17293
17294+#ifdef CONFIG_PAX_PER_CPU_PGD
17295+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17296+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17297+ KERNEL_PGD_PTRS);
17298+#endif
17299+
17300 err = do_boot_cpu(apicid, cpu);
17301 if (err) {
17302 pr_debug("do_boot_cpu failed %d\n", err);
17303diff -urNp linux-2.6.39.1/arch/x86/kernel/step.c linux-2.6.39.1/arch/x86/kernel/step.c
17304--- linux-2.6.39.1/arch/x86/kernel/step.c 2011-05-19 00:06:34.000000000 -0400
17305+++ linux-2.6.39.1/arch/x86/kernel/step.c 2011-05-22 19:36:30.000000000 -0400
17306@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
17307 struct desc_struct *desc;
17308 unsigned long base;
17309
17310- seg &= ~7UL;
17311+ seg >>= 3;
17312
17313 mutex_lock(&child->mm->context.lock);
17314- if (unlikely((seg >> 3) >= child->mm->context.size))
17315+ if (unlikely(seg >= child->mm->context.size))
17316 addr = -1L; /* bogus selector, access would fault */
17317 else {
17318 desc = child->mm->context.ldt + seg;
17319@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
17320 addr += base;
17321 }
17322 mutex_unlock(&child->mm->context.lock);
17323- }
17324+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17325+ addr = ktla_ktva(addr);
17326
17327 return addr;
17328 }
17329@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
17330 unsigned char opcode[15];
17331 unsigned long addr = convert_ip_to_linear(child, regs);
17332
17333+ if (addr == -EINVAL)
17334+ return 0;
17335+
17336 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17337 for (i = 0; i < copied; i++) {
17338 switch (opcode[i]) {
17339@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
17340
17341 #ifdef CONFIG_X86_64
17342 case 0x40 ... 0x4f:
17343- if (regs->cs != __USER_CS)
17344+ if ((regs->cs & 0xffff) != __USER_CS)
17345 /* 32-bit mode: register increment */
17346 return 0;
17347 /* 64-bit mode: REX prefix */
17348diff -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
17349--- linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S 2011-05-19 00:06:34.000000000 -0400
17350+++ linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S 2011-05-22 19:36:30.000000000 -0400
17351@@ -1,3 +1,4 @@
17352+.section .rodata,"a",@progbits
17353 ENTRY(sys_call_table)
17354 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17355 .long sys_exit
17356diff -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
17357--- linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c 2011-05-19 00:06:34.000000000 -0400
17358+++ linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c 2011-05-22 19:36:30.000000000 -0400
17359@@ -24,17 +24,224 @@
17360
17361 #include <asm/syscalls.h>
17362
17363-/*
17364- * Do a system call from kernel instead of calling sys_execve so we
17365- * end up with proper pt_regs.
17366- */
17367-int kernel_execve(const char *filename,
17368- const char *const argv[],
17369- const char *const envp[])
17370+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17371 {
17372- long __res;
17373- asm volatile ("int $0x80"
17374- : "=a" (__res)
17375- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17376- return __res;
17377+ unsigned long pax_task_size = TASK_SIZE;
17378+
17379+#ifdef CONFIG_PAX_SEGMEXEC
17380+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17381+ pax_task_size = SEGMEXEC_TASK_SIZE;
17382+#endif
17383+
17384+ if (len > pax_task_size || addr > pax_task_size - len)
17385+ return -EINVAL;
17386+
17387+ return 0;
17388+}
17389+
17390+unsigned long
17391+arch_get_unmapped_area(struct file *filp, unsigned long addr,
17392+ unsigned long len, unsigned long pgoff, unsigned long flags)
17393+{
17394+ struct mm_struct *mm = current->mm;
17395+ struct vm_area_struct *vma;
17396+ unsigned long start_addr, pax_task_size = TASK_SIZE;
17397+
17398+#ifdef CONFIG_PAX_SEGMEXEC
17399+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17400+ pax_task_size = SEGMEXEC_TASK_SIZE;
17401+#endif
17402+
17403+ pax_task_size -= PAGE_SIZE;
17404+
17405+ if (len > pax_task_size)
17406+ return -ENOMEM;
17407+
17408+ if (flags & MAP_FIXED)
17409+ return addr;
17410+
17411+#ifdef CONFIG_PAX_RANDMMAP
17412+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17413+#endif
17414+
17415+ if (addr) {
17416+ addr = PAGE_ALIGN(addr);
17417+ if (pax_task_size - len >= addr) {
17418+ vma = find_vma(mm, addr);
17419+ if (check_heap_stack_gap(vma, addr, len))
17420+ return addr;
17421+ }
17422+ }
17423+ if (len > mm->cached_hole_size) {
17424+ start_addr = addr = mm->free_area_cache;
17425+ } else {
17426+ start_addr = addr = mm->mmap_base;
17427+ mm->cached_hole_size = 0;
17428+ }
17429+
17430+#ifdef CONFIG_PAX_PAGEEXEC
17431+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17432+ start_addr = 0x00110000UL;
17433+
17434+#ifdef CONFIG_PAX_RANDMMAP
17435+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17436+ start_addr += mm->delta_mmap & 0x03FFF000UL;
17437+#endif
17438+
17439+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17440+ start_addr = addr = mm->mmap_base;
17441+ else
17442+ addr = start_addr;
17443+ }
17444+#endif
17445+
17446+full_search:
17447+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17448+ /* At this point: (!vma || addr < vma->vm_end). */
17449+ if (pax_task_size - len < addr) {
17450+ /*
17451+ * Start a new search - just in case we missed
17452+ * some holes.
17453+ */
17454+ if (start_addr != mm->mmap_base) {
17455+ start_addr = addr = mm->mmap_base;
17456+ mm->cached_hole_size = 0;
17457+ goto full_search;
17458+ }
17459+ return -ENOMEM;
17460+ }
17461+ if (check_heap_stack_gap(vma, addr, len))
17462+ break;
17463+ if (addr + mm->cached_hole_size < vma->vm_start)
17464+ mm->cached_hole_size = vma->vm_start - addr;
17465+ addr = vma->vm_end;
17466+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
17467+ start_addr = addr = mm->mmap_base;
17468+ mm->cached_hole_size = 0;
17469+ goto full_search;
17470+ }
17471+ }
17472+
17473+ /*
17474+ * Remember the place where we stopped the search:
17475+ */
17476+ mm->free_area_cache = addr + len;
17477+ return addr;
17478+}
17479+
17480+unsigned long
17481+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17482+ const unsigned long len, const unsigned long pgoff,
17483+ const unsigned long flags)
17484+{
17485+ struct vm_area_struct *vma;
17486+ struct mm_struct *mm = current->mm;
17487+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17488+
17489+#ifdef CONFIG_PAX_SEGMEXEC
17490+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17491+ pax_task_size = SEGMEXEC_TASK_SIZE;
17492+#endif
17493+
17494+ pax_task_size -= PAGE_SIZE;
17495+
17496+ /* requested length too big for entire address space */
17497+ if (len > pax_task_size)
17498+ return -ENOMEM;
17499+
17500+ if (flags & MAP_FIXED)
17501+ return addr;
17502+
17503+#ifdef CONFIG_PAX_PAGEEXEC
17504+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17505+ goto bottomup;
17506+#endif
17507+
17508+#ifdef CONFIG_PAX_RANDMMAP
17509+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17510+#endif
17511+
17512+ /* requesting a specific address */
17513+ if (addr) {
17514+ addr = PAGE_ALIGN(addr);
17515+ if (pax_task_size - len >= addr) {
17516+ vma = find_vma(mm, addr);
17517+ if (check_heap_stack_gap(vma, addr, len))
17518+ return addr;
17519+ }
17520+ }
17521+
17522+ /* check if free_area_cache is useful for us */
17523+ if (len <= mm->cached_hole_size) {
17524+ mm->cached_hole_size = 0;
17525+ mm->free_area_cache = mm->mmap_base;
17526+ }
17527+
17528+ /* either no address requested or can't fit in requested address hole */
17529+ addr = mm->free_area_cache;
17530+
17531+ /* make sure it can fit in the remaining address space */
17532+ if (addr > len) {
17533+ vma = find_vma(mm, addr-len);
17534+ if (check_heap_stack_gap(vma, addr - len, len))
17535+ /* remember the address as a hint for next time */
17536+ return (mm->free_area_cache = addr-len);
17537+ }
17538+
17539+ if (mm->mmap_base < len)
17540+ goto bottomup;
17541+
17542+ addr = mm->mmap_base-len;
17543+
17544+ do {
17545+ /*
17546+ * Lookup failure means no vma is above this address,
17547+ * else if new region fits below vma->vm_start,
17548+ * return with success:
17549+ */
17550+ vma = find_vma(mm, addr);
17551+ if (check_heap_stack_gap(vma, addr, len))
17552+ /* remember the address as a hint for next time */
17553+ return (mm->free_area_cache = addr);
17554+
17555+ /* remember the largest hole we saw so far */
17556+ if (addr + mm->cached_hole_size < vma->vm_start)
17557+ mm->cached_hole_size = vma->vm_start - addr;
17558+
17559+ /* try just below the current vma->vm_start */
17560+ addr = skip_heap_stack_gap(vma, len);
17561+ } while (!IS_ERR_VALUE(addr));
17562+
17563+bottomup:
17564+ /*
17565+ * A failed mmap() very likely causes application failure,
17566+ * so fall back to the bottom-up function here. This scenario
17567+ * can happen with large stack limits and large mmap()
17568+ * allocations.
17569+ */
17570+
17571+#ifdef CONFIG_PAX_SEGMEXEC
17572+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17573+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17574+ else
17575+#endif
17576+
17577+ mm->mmap_base = TASK_UNMAPPED_BASE;
17578+
17579+#ifdef CONFIG_PAX_RANDMMAP
17580+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17581+ mm->mmap_base += mm->delta_mmap;
17582+#endif
17583+
17584+ mm->free_area_cache = mm->mmap_base;
17585+ mm->cached_hole_size = ~0UL;
17586+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17587+ /*
17588+ * Restore the topdown base:
17589+ */
17590+ mm->mmap_base = base;
17591+ mm->free_area_cache = base;
17592+ mm->cached_hole_size = ~0UL;
17593+
17594+ return addr;
17595 }
17596diff -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
17597--- linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c 2011-05-19 00:06:34.000000000 -0400
17598+++ linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c 2011-05-22 19:36:30.000000000 -0400
17599@@ -32,8 +32,8 @@ out:
17600 return error;
17601 }
17602
17603-static void find_start_end(unsigned long flags, unsigned long *begin,
17604- unsigned long *end)
17605+static void find_start_end(struct mm_struct *mm, unsigned long flags,
17606+ unsigned long *begin, unsigned long *end)
17607 {
17608 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17609 unsigned long new_begin;
17610@@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17611 *begin = new_begin;
17612 }
17613 } else {
17614- *begin = TASK_UNMAPPED_BASE;
17615+ *begin = mm->mmap_base;
17616 *end = TASK_SIZE;
17617 }
17618 }
17619@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17620 if (flags & MAP_FIXED)
17621 return addr;
17622
17623- find_start_end(flags, &begin, &end);
17624+ find_start_end(mm, flags, &begin, &end);
17625
17626 if (len > end)
17627 return -ENOMEM;
17628
17629+#ifdef CONFIG_PAX_RANDMMAP
17630+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17631+#endif
17632+
17633 if (addr) {
17634 addr = PAGE_ALIGN(addr);
17635 vma = find_vma(mm, addr);
17636- if (end - len >= addr &&
17637- (!vma || addr + len <= vma->vm_start))
17638+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17639 return addr;
17640 }
17641 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17642@@ -106,7 +109,7 @@ full_search:
17643 }
17644 return -ENOMEM;
17645 }
17646- if (!vma || addr + len <= vma->vm_start) {
17647+ if (check_heap_stack_gap(vma, addr, len)) {
17648 /*
17649 * Remember the place where we stopped the search:
17650 */
17651@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17652 {
17653 struct vm_area_struct *vma;
17654 struct mm_struct *mm = current->mm;
17655- unsigned long addr = addr0;
17656+ unsigned long base = mm->mmap_base, addr = addr0;
17657
17658 /* requested length too big for entire address space */
17659 if (len > TASK_SIZE)
17660@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17661 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17662 goto bottomup;
17663
17664+#ifdef CONFIG_PAX_RANDMMAP
17665+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17666+#endif
17667+
17668 /* requesting a specific address */
17669 if (addr) {
17670 addr = PAGE_ALIGN(addr);
17671- vma = find_vma(mm, addr);
17672- if (TASK_SIZE - len >= addr &&
17673- (!vma || addr + len <= vma->vm_start))
17674- return addr;
17675+ if (TASK_SIZE - len >= addr) {
17676+ vma = find_vma(mm, addr);
17677+ if (check_heap_stack_gap(vma, addr, len))
17678+ return addr;
17679+ }
17680 }
17681
17682 /* check if free_area_cache is useful for us */
17683@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17684 /* make sure it can fit in the remaining address space */
17685 if (addr > len) {
17686 vma = find_vma(mm, addr-len);
17687- if (!vma || addr <= vma->vm_start)
17688+ if (check_heap_stack_gap(vma, addr - len, len))
17689 /* remember the address as a hint for next time */
17690 return mm->free_area_cache = addr-len;
17691 }
17692@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17693 * return with success:
17694 */
17695 vma = find_vma(mm, addr);
17696- if (!vma || addr+len <= vma->vm_start)
17697+ if (check_heap_stack_gap(vma, addr, len))
17698 /* remember the address as a hint for next time */
17699 return mm->free_area_cache = addr;
17700
17701@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17702 mm->cached_hole_size = vma->vm_start - addr;
17703
17704 /* try just below the current vma->vm_start */
17705- addr = vma->vm_start-len;
17706- } while (len < vma->vm_start);
17707+ addr = skip_heap_stack_gap(vma, len);
17708+ } while (!IS_ERR_VALUE(addr));
17709
17710 bottomup:
17711 /*
17712@@ -198,13 +206,21 @@ bottomup:
17713 * can happen with large stack limits and large mmap()
17714 * allocations.
17715 */
17716+ mm->mmap_base = TASK_UNMAPPED_BASE;
17717+
17718+#ifdef CONFIG_PAX_RANDMMAP
17719+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17720+ mm->mmap_base += mm->delta_mmap;
17721+#endif
17722+
17723+ mm->free_area_cache = mm->mmap_base;
17724 mm->cached_hole_size = ~0UL;
17725- mm->free_area_cache = TASK_UNMAPPED_BASE;
17726 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17727 /*
17728 * Restore the topdown base:
17729 */
17730- mm->free_area_cache = mm->mmap_base;
17731+ mm->mmap_base = base;
17732+ mm->free_area_cache = base;
17733 mm->cached_hole_size = ~0UL;
17734
17735 return addr;
17736diff -urNp linux-2.6.39.1/arch/x86/kernel/tboot.c linux-2.6.39.1/arch/x86/kernel/tboot.c
17737--- linux-2.6.39.1/arch/x86/kernel/tboot.c 2011-05-19 00:06:34.000000000 -0400
17738+++ linux-2.6.39.1/arch/x86/kernel/tboot.c 2011-05-22 19:36:30.000000000 -0400
17739@@ -218,7 +218,7 @@ static int tboot_setup_sleep(void)
17740
17741 void tboot_shutdown(u32 shutdown_type)
17742 {
17743- void (*shutdown)(void);
17744+ void (* __noreturn shutdown)(void);
17745
17746 if (!tboot_enabled())
17747 return;
17748@@ -240,7 +240,7 @@ void tboot_shutdown(u32 shutdown_type)
17749
17750 switch_to_tboot_pt();
17751
17752- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17753+ shutdown = (void *)tboot->shutdown_entry;
17754 shutdown();
17755
17756 /* should not reach here */
17757@@ -297,7 +297,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17758 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17759 }
17760
17761-static atomic_t ap_wfs_count;
17762+static atomic_unchecked_t ap_wfs_count;
17763
17764 static int tboot_wait_for_aps(int num_aps)
17765 {
17766@@ -321,9 +321,9 @@ static int __cpuinit tboot_cpu_callback(
17767 {
17768 switch (action) {
17769 case CPU_DYING:
17770- atomic_inc(&ap_wfs_count);
17771+ atomic_inc_unchecked(&ap_wfs_count);
17772 if (num_online_cpus() == 1)
17773- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17774+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17775 return NOTIFY_BAD;
17776 break;
17777 }
17778@@ -342,7 +342,7 @@ static __init int tboot_late_init(void)
17779
17780 tboot_create_trampoline();
17781
17782- atomic_set(&ap_wfs_count, 0);
17783+ atomic_set_unchecked(&ap_wfs_count, 0);
17784 register_hotcpu_notifier(&tboot_cpu_notifier);
17785 return 0;
17786 }
17787diff -urNp linux-2.6.39.1/arch/x86/kernel/time.c linux-2.6.39.1/arch/x86/kernel/time.c
17788--- linux-2.6.39.1/arch/x86/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
17789+++ linux-2.6.39.1/arch/x86/kernel/time.c 2011-05-22 19:36:30.000000000 -0400
17790@@ -22,17 +22,13 @@
17791 #include <asm/hpet.h>
17792 #include <asm/time.h>
17793
17794-#ifdef CONFIG_X86_64
17795-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17796-#endif
17797-
17798 unsigned long profile_pc(struct pt_regs *regs)
17799 {
17800 unsigned long pc = instruction_pointer(regs);
17801
17802- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17803+ if (!user_mode(regs) && in_lock_functions(pc)) {
17804 #ifdef CONFIG_FRAME_POINTER
17805- return *(unsigned long *)(regs->bp + sizeof(long));
17806+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17807 #else
17808 unsigned long *sp =
17809 (unsigned long *)kernel_stack_pointer(regs);
17810@@ -41,11 +37,17 @@ unsigned long profile_pc(struct pt_regs
17811 * or above a saved flags. Eflags has bits 22-31 zero,
17812 * kernel addresses don't.
17813 */
17814+
17815+#ifdef CONFIG_PAX_KERNEXEC
17816+ return ktla_ktva(sp[0]);
17817+#else
17818 if (sp[0] >> 22)
17819 return sp[0];
17820 if (sp[1] >> 22)
17821 return sp[1];
17822 #endif
17823+
17824+#endif
17825 }
17826 return pc;
17827 }
17828diff -urNp linux-2.6.39.1/arch/x86/kernel/tls.c linux-2.6.39.1/arch/x86/kernel/tls.c
17829--- linux-2.6.39.1/arch/x86/kernel/tls.c 2011-05-19 00:06:34.000000000 -0400
17830+++ linux-2.6.39.1/arch/x86/kernel/tls.c 2011-05-22 19:36:30.000000000 -0400
17831@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17832 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17833 return -EINVAL;
17834
17835+#ifdef CONFIG_PAX_SEGMEXEC
17836+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17837+ return -EINVAL;
17838+#endif
17839+
17840 set_tls_desc(p, idx, &info, 1);
17841
17842 return 0;
17843diff -urNp linux-2.6.39.1/arch/x86/kernel/trampoline_32.S linux-2.6.39.1/arch/x86/kernel/trampoline_32.S
17844--- linux-2.6.39.1/arch/x86/kernel/trampoline_32.S 2011-05-19 00:06:34.000000000 -0400
17845+++ linux-2.6.39.1/arch/x86/kernel/trampoline_32.S 2011-05-22 19:36:30.000000000 -0400
17846@@ -32,6 +32,12 @@
17847 #include <asm/segment.h>
17848 #include <asm/page_types.h>
17849
17850+#ifdef CONFIG_PAX_KERNEXEC
17851+#define ta(X) (X)
17852+#else
17853+#define ta(X) ((X) - __PAGE_OFFSET)
17854+#endif
17855+
17856 #ifdef CONFIG_SMP
17857
17858 .section ".x86_trampoline","a"
17859@@ -62,7 +68,7 @@ r_base = .
17860 inc %ax # protected mode (PE) bit
17861 lmsw %ax # into protected mode
17862 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17863- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17864+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
17865
17866 # These need to be in the same 64K segment as the above;
17867 # hence we don't use the boot_gdt_descr defined in head.S
17868diff -urNp linux-2.6.39.1/arch/x86/kernel/trampoline_64.S linux-2.6.39.1/arch/x86/kernel/trampoline_64.S
17869--- linux-2.6.39.1/arch/x86/kernel/trampoline_64.S 2011-05-19 00:06:34.000000000 -0400
17870+++ linux-2.6.39.1/arch/x86/kernel/trampoline_64.S 2011-05-22 19:36:30.000000000 -0400
17871@@ -90,7 +90,7 @@ startup_32:
17872 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17873 movl %eax, %ds
17874
17875- movl $X86_CR4_PAE, %eax
17876+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17877 movl %eax, %cr4 # Enable PAE mode
17878
17879 # Setup trampoline 4 level pagetables
17880@@ -138,7 +138,7 @@ tidt:
17881 # so the kernel can live anywhere
17882 .balign 4
17883 tgdt:
17884- .short tgdt_end - tgdt # gdt limit
17885+ .short tgdt_end - tgdt - 1 # gdt limit
17886 .long tgdt - r_base
17887 .short 0
17888 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17889diff -urNp linux-2.6.39.1/arch/x86/kernel/traps.c linux-2.6.39.1/arch/x86/kernel/traps.c
17890--- linux-2.6.39.1/arch/x86/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
17891+++ linux-2.6.39.1/arch/x86/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
17892@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17893
17894 /* Do we ignore FPU interrupts ? */
17895 char ignore_fpu_irq;
17896-
17897-/*
17898- * The IDT has to be page-aligned to simplify the Pentium
17899- * F0 0F bug workaround.
17900- */
17901-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17902 #endif
17903
17904 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17905@@ -117,13 +111,13 @@ static inline void preempt_conditional_c
17906 }
17907
17908 static void __kprobes
17909-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17910+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17911 long error_code, siginfo_t *info)
17912 {
17913 struct task_struct *tsk = current;
17914
17915 #ifdef CONFIG_X86_32
17916- if (regs->flags & X86_VM_MASK) {
17917+ if (v8086_mode(regs)) {
17918 /*
17919 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17920 * On nmi (interrupt 2), do_trap should not be called.
17921@@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str
17922 }
17923 #endif
17924
17925- if (!user_mode(regs))
17926+ if (!user_mode_novm(regs))
17927 goto kernel_trap;
17928
17929 #ifdef CONFIG_X86_32
17930@@ -157,7 +151,7 @@ trap_signal:
17931 printk_ratelimit()) {
17932 printk(KERN_INFO
17933 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17934- tsk->comm, tsk->pid, str,
17935+ tsk->comm, task_pid_nr(tsk), str,
17936 regs->ip, regs->sp, error_code);
17937 print_vma_addr(" in ", regs->ip);
17938 printk("\n");
17939@@ -174,8 +168,20 @@ kernel_trap:
17940 if (!fixup_exception(regs)) {
17941 tsk->thread.error_code = error_code;
17942 tsk->thread.trap_no = trapnr;
17943+
17944+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17945+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17946+ str = "PAX: suspicious stack segment fault";
17947+#endif
17948+
17949 die(str, regs, error_code);
17950 }
17951+
17952+#ifdef CONFIG_PAX_REFCOUNT
17953+ if (trapnr == 4)
17954+ pax_report_refcount_overflow(regs);
17955+#endif
17956+
17957 return;
17958
17959 #ifdef CONFIG_X86_32
17960@@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *re
17961 conditional_sti(regs);
17962
17963 #ifdef CONFIG_X86_32
17964- if (regs->flags & X86_VM_MASK)
17965+ if (v8086_mode(regs))
17966 goto gp_in_vm86;
17967 #endif
17968
17969 tsk = current;
17970- if (!user_mode(regs))
17971+ if (!user_mode_novm(regs))
17972 goto gp_in_kernel;
17973
17974+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17975+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17976+ struct mm_struct *mm = tsk->mm;
17977+ unsigned long limit;
17978+
17979+ down_write(&mm->mmap_sem);
17980+ limit = mm->context.user_cs_limit;
17981+ if (limit < TASK_SIZE) {
17982+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17983+ up_write(&mm->mmap_sem);
17984+ return;
17985+ }
17986+ up_write(&mm->mmap_sem);
17987+ }
17988+#endif
17989+
17990 tsk->thread.error_code = error_code;
17991 tsk->thread.trap_no = 13;
17992
17993@@ -304,6 +326,13 @@ gp_in_kernel:
17994 if (notify_die(DIE_GPF, "general protection fault", regs,
17995 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17996 return;
17997+
17998+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17999+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
18000+ die("PAX: suspicious general protection fault", regs, error_code);
18001+ else
18002+#endif
18003+
18004 die("general protection fault", regs, error_code);
18005 }
18006
18007@@ -569,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
18008 /* It's safe to allow irq's after DR6 has been saved */
18009 preempt_conditional_sti(regs);
18010
18011- if (regs->flags & X86_VM_MASK) {
18012+ if (v8086_mode(regs)) {
18013 handle_vm86_trap((struct kernel_vm86_regs *) regs,
18014 error_code, 1);
18015 preempt_conditional_cli(regs);
18016@@ -583,7 +612,7 @@ dotraplinkage void __kprobes do_debug(st
18017 * We already checked v86 mode above, so we can check for kernel mode
18018 * by just checking the CPL of CS.
18019 */
18020- if ((dr6 & DR_STEP) && !user_mode(regs)) {
18021+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
18022 tsk->thread.debugreg6 &= ~DR_STEP;
18023 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
18024 regs->flags &= ~X86_EFLAGS_TF;
18025@@ -612,7 +641,7 @@ void math_error(struct pt_regs *regs, in
18026 return;
18027 conditional_sti(regs);
18028
18029- if (!user_mode_vm(regs))
18030+ if (!user_mode(regs))
18031 {
18032 if (!fixup_exception(regs)) {
18033 task->thread.error_code = error_code;
18034@@ -723,7 +752,7 @@ asmlinkage void __attribute__((weak)) sm
18035 void __math_state_restore(void)
18036 {
18037 struct thread_info *thread = current_thread_info();
18038- struct task_struct *tsk = thread->task;
18039+ struct task_struct *tsk = current;
18040
18041 /*
18042 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
18043@@ -750,8 +779,7 @@ void __math_state_restore(void)
18044 */
18045 asmlinkage void math_state_restore(void)
18046 {
18047- struct thread_info *thread = current_thread_info();
18048- struct task_struct *tsk = thread->task;
18049+ struct task_struct *tsk = current;
18050
18051 if (!tsk_used_math(tsk)) {
18052 local_irq_enable();
18053diff -urNp linux-2.6.39.1/arch/x86/kernel/vm86_32.c linux-2.6.39.1/arch/x86/kernel/vm86_32.c
18054--- linux-2.6.39.1/arch/x86/kernel/vm86_32.c 2011-05-19 00:06:34.000000000 -0400
18055+++ linux-2.6.39.1/arch/x86/kernel/vm86_32.c 2011-05-22 19:41:32.000000000 -0400
18056@@ -41,6 +41,7 @@
18057 #include <linux/ptrace.h>
18058 #include <linux/audit.h>
18059 #include <linux/stddef.h>
18060+#include <linux/grsecurity.h>
18061
18062 #include <asm/uaccess.h>
18063 #include <asm/io.h>
18064@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
18065 do_exit(SIGSEGV);
18066 }
18067
18068- tss = &per_cpu(init_tss, get_cpu());
18069+ tss = init_tss + get_cpu();
18070 current->thread.sp0 = current->thread.saved_sp0;
18071 current->thread.sysenter_cs = __KERNEL_CS;
18072 load_sp0(tss, &current->thread);
18073@@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __use
18074 struct task_struct *tsk;
18075 int tmp, ret = -EPERM;
18076
18077+#ifdef CONFIG_GRKERNSEC_VM86
18078+ if (!capable(CAP_SYS_RAWIO)) {
18079+ gr_handle_vm86();
18080+ goto out;
18081+ }
18082+#endif
18083+
18084 tsk = current;
18085 if (tsk->thread.saved_sp0)
18086 goto out;
18087@@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned
18088 int tmp, ret;
18089 struct vm86plus_struct __user *v86;
18090
18091+#ifdef CONFIG_GRKERNSEC_VM86
18092+ if (!capable(CAP_SYS_RAWIO)) {
18093+ gr_handle_vm86();
18094+ ret = -EPERM;
18095+ goto out;
18096+ }
18097+#endif
18098+
18099 tsk = current;
18100 switch (cmd) {
18101 case VM86_REQUEST_IRQ:
18102@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
18103 tsk->thread.saved_fs = info->regs32->fs;
18104 tsk->thread.saved_gs = get_user_gs(info->regs32);
18105
18106- tss = &per_cpu(init_tss, get_cpu());
18107+ tss = init_tss + get_cpu();
18108 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
18109 if (cpu_has_sep)
18110 tsk->thread.sysenter_cs = 0;
18111@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
18112 goto cannot_handle;
18113 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
18114 goto cannot_handle;
18115- intr_ptr = (unsigned long __user *) (i << 2);
18116+ intr_ptr = (__force unsigned long __user *) (i << 2);
18117 if (get_user(segoffs, intr_ptr))
18118 goto cannot_handle;
18119 if ((segoffs >> 16) == BIOSSEG)
18120diff -urNp linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S
18121--- linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
18122+++ linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
18123@@ -26,6 +26,13 @@
18124 #include <asm/page_types.h>
18125 #include <asm/cache.h>
18126 #include <asm/boot.h>
18127+#include <asm/segment.h>
18128+
18129+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18130+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
18131+#else
18132+#define __KERNEL_TEXT_OFFSET 0
18133+#endif
18134
18135 #undef i386 /* in case the preprocessor is a 32bit one */
18136
18137@@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
18138 #ifdef CONFIG_X86_32
18139 OUTPUT_ARCH(i386)
18140 ENTRY(phys_startup_32)
18141-jiffies = jiffies_64;
18142 #else
18143 OUTPUT_ARCH(i386:x86-64)
18144 ENTRY(phys_startup_64)
18145-jiffies_64 = jiffies;
18146 #endif
18147
18148 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
18149@@ -69,31 +74,46 @@ jiffies_64 = jiffies;
18150
18151 PHDRS {
18152 text PT_LOAD FLAGS(5); /* R_E */
18153+#ifdef CONFIG_X86_32
18154+ module PT_LOAD FLAGS(5); /* R_E */
18155+#endif
18156+#ifdef CONFIG_XEN
18157+ rodata PT_LOAD FLAGS(5); /* R_E */
18158+#else
18159+ rodata PT_LOAD FLAGS(4); /* R__ */
18160+#endif
18161 data PT_LOAD FLAGS(6); /* RW_ */
18162 #ifdef CONFIG_X86_64
18163 user PT_LOAD FLAGS(5); /* R_E */
18164+#endif
18165+ init.begin PT_LOAD FLAGS(6); /* RW_ */
18166 #ifdef CONFIG_SMP
18167 percpu PT_LOAD FLAGS(6); /* RW_ */
18168 #endif
18169+ text.init PT_LOAD FLAGS(5); /* R_E */
18170+ text.exit PT_LOAD FLAGS(5); /* R_E */
18171 init PT_LOAD FLAGS(7); /* RWE */
18172-#endif
18173 note PT_NOTE FLAGS(0); /* ___ */
18174 }
18175
18176 SECTIONS
18177 {
18178 #ifdef CONFIG_X86_32
18179- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18180- phys_startup_32 = startup_32 - LOAD_OFFSET;
18181+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18182 #else
18183- . = __START_KERNEL;
18184- phys_startup_64 = startup_64 - LOAD_OFFSET;
18185+ . = __START_KERNEL;
18186 #endif
18187
18188 /* Text and read-only data */
18189- .text : AT(ADDR(.text) - LOAD_OFFSET) {
18190- _text = .;
18191+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18192 /* bootstrapping code */
18193+#ifdef CONFIG_X86_32
18194+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18195+#else
18196+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18197+#endif
18198+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18199+ _text = .;
18200 HEAD_TEXT
18201 #ifdef CONFIG_X86_32
18202 . = ALIGN(PAGE_SIZE);
18203@@ -109,13 +129,47 @@ SECTIONS
18204 IRQENTRY_TEXT
18205 *(.fixup)
18206 *(.gnu.warning)
18207- /* End of text section */
18208- _etext = .;
18209 } :text = 0x9090
18210
18211- NOTES :text :note
18212+ . += __KERNEL_TEXT_OFFSET;
18213+
18214+#ifdef CONFIG_X86_32
18215+ . = ALIGN(PAGE_SIZE);
18216+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18217+
18218+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18219+ MODULES_EXEC_VADDR = .;
18220+ BYTE(0)
18221+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18222+ . = ALIGN(HPAGE_SIZE);
18223+ MODULES_EXEC_END = . - 1;
18224+#endif
18225+
18226+ } :module
18227+#endif
18228+
18229+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18230+ /* End of text section */
18231+ _etext = . - __KERNEL_TEXT_OFFSET;
18232+ }
18233
18234- EXCEPTION_TABLE(16) :text = 0x9090
18235+#ifdef CONFIG_X86_32
18236+ . = ALIGN(PAGE_SIZE);
18237+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18238+ *(.idt)
18239+ . = ALIGN(PAGE_SIZE);
18240+ *(.empty_zero_page)
18241+ *(.initial_pg_fixmap)
18242+ *(.initial_pg_pmd)
18243+ *(.initial_page_table)
18244+ *(.swapper_pg_dir)
18245+ } :rodata
18246+#endif
18247+
18248+ . = ALIGN(PAGE_SIZE);
18249+ NOTES :rodata :note
18250+
18251+ EXCEPTION_TABLE(16) :rodata
18252
18253 #if defined(CONFIG_DEBUG_RODATA)
18254 /* .text should occupy whole number of pages */
18255@@ -127,16 +181,20 @@ SECTIONS
18256
18257 /* Data */
18258 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18259+
18260+#ifdef CONFIG_PAX_KERNEXEC
18261+ . = ALIGN(HPAGE_SIZE);
18262+#else
18263+ . = ALIGN(PAGE_SIZE);
18264+#endif
18265+
18266 /* Start of data section */
18267 _sdata = .;
18268
18269 /* init_task */
18270 INIT_TASK_DATA(THREAD_SIZE)
18271
18272-#ifdef CONFIG_X86_32
18273- /* 32 bit has nosave before _edata */
18274 NOSAVE_DATA
18275-#endif
18276
18277 PAGE_ALIGNED_DATA(PAGE_SIZE)
18278
18279@@ -145,6 +203,8 @@ SECTIONS
18280 DATA_DATA
18281 CONSTRUCTORS
18282
18283+ jiffies = jiffies_64;
18284+
18285 /* rarely changed data like cpu maps */
18286 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
18287
18288@@ -199,12 +259,6 @@ SECTIONS
18289 }
18290 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18291
18292- . = ALIGN(L1_CACHE_BYTES);
18293- .jiffies : AT(VLOAD(.jiffies)) {
18294- *(.jiffies)
18295- }
18296- jiffies = VVIRT(.jiffies);
18297-
18298 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18299 *(.vsyscall_3)
18300 }
18301@@ -220,12 +274,19 @@ SECTIONS
18302 #endif /* CONFIG_X86_64 */
18303
18304 /* Init code and data - will be freed after init */
18305- . = ALIGN(PAGE_SIZE);
18306 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18307+ BYTE(0)
18308+
18309+#ifdef CONFIG_PAX_KERNEXEC
18310+ . = ALIGN(HPAGE_SIZE);
18311+#else
18312+ . = ALIGN(PAGE_SIZE);
18313+#endif
18314+
18315 __init_begin = .; /* paired with __init_end */
18316- }
18317+ } :init.begin
18318
18319-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18320+#ifdef CONFIG_SMP
18321 /*
18322 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18323 * output PHDR, so the next output section - .init.text - should
18324@@ -234,12 +295,27 @@ SECTIONS
18325 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18326 #endif
18327
18328- INIT_TEXT_SECTION(PAGE_SIZE)
18329-#ifdef CONFIG_X86_64
18330- :init
18331-#endif
18332+ . = ALIGN(PAGE_SIZE);
18333+ init_begin = .;
18334+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18335+ VMLINUX_SYMBOL(_sinittext) = .;
18336+ INIT_TEXT
18337+ VMLINUX_SYMBOL(_einittext) = .;
18338+ . = ALIGN(PAGE_SIZE);
18339+ } :text.init
18340
18341- INIT_DATA_SECTION(16)
18342+ /*
18343+ * .exit.text is discard at runtime, not link time, to deal with
18344+ * references from .altinstructions and .eh_frame
18345+ */
18346+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18347+ EXIT_TEXT
18348+ . = ALIGN(16);
18349+ } :text.exit
18350+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18351+
18352+ . = ALIGN(PAGE_SIZE);
18353+ INIT_DATA_SECTION(16) :init
18354
18355 /*
18356 * Code and data for a variety of lowlevel trampolines, to be
18357@@ -306,19 +382,12 @@ SECTIONS
18358 }
18359
18360 . = ALIGN(8);
18361- /*
18362- * .exit.text is discard at runtime, not link time, to deal with
18363- * references from .altinstructions and .eh_frame
18364- */
18365- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18366- EXIT_TEXT
18367- }
18368
18369 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18370 EXIT_DATA
18371 }
18372
18373-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18374+#ifndef CONFIG_SMP
18375 PERCPU(INTERNODE_CACHE_BYTES, PAGE_SIZE)
18376 #endif
18377
18378@@ -337,16 +406,10 @@ SECTIONS
18379 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18380 __smp_locks = .;
18381 *(.smp_locks)
18382- . = ALIGN(PAGE_SIZE);
18383 __smp_locks_end = .;
18384+ . = ALIGN(PAGE_SIZE);
18385 }
18386
18387-#ifdef CONFIG_X86_64
18388- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18389- NOSAVE_DATA
18390- }
18391-#endif
18392-
18393 /* BSS */
18394 . = ALIGN(PAGE_SIZE);
18395 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18396@@ -362,6 +425,7 @@ SECTIONS
18397 __brk_base = .;
18398 . += 64 * 1024; /* 64k alignment slop space */
18399 *(.brk_reservation) /* areas brk users have reserved */
18400+ . = ALIGN(HPAGE_SIZE);
18401 __brk_limit = .;
18402 }
18403
18404@@ -388,13 +452,12 @@ SECTIONS
18405 * for the boot processor.
18406 */
18407 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18408-INIT_PER_CPU(gdt_page);
18409 INIT_PER_CPU(irq_stack_union);
18410
18411 /*
18412 * Build-time check on the image size:
18413 */
18414-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18415+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18416 "kernel image bigger than KERNEL_IMAGE_SIZE");
18417
18418 #ifdef CONFIG_SMP
18419diff -urNp linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c
18420--- linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c 2011-05-19 00:06:34.000000000 -0400
18421+++ linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c 2011-05-22 19:36:30.000000000 -0400
18422@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18423
18424 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18425 /* copy vsyscall data */
18426+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18427 vsyscall_gtod_data.clock.vread = clock->vread;
18428 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18429 vsyscall_gtod_data.clock.mask = clock->mask;
18430@@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18431 We do this here because otherwise user space would do it on
18432 its own in a likely inferior way (no access to jiffies).
18433 If you don't like it pass NULL. */
18434- if (tcache && tcache->blob[0] == (j = __jiffies)) {
18435+ if (tcache && tcache->blob[0] == (j = jiffies)) {
18436 p = tcache->blob[1];
18437 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18438 /* Load per CPU data from RDTSCP */
18439diff -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
18440--- linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c 2011-05-19 00:06:34.000000000 -0400
18441+++ linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c 2011-05-22 19:36:30.000000000 -0400
18442@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18443 EXPORT_SYMBOL(copy_user_generic_string);
18444 EXPORT_SYMBOL(copy_user_generic_unrolled);
18445 EXPORT_SYMBOL(__copy_user_nocache);
18446-EXPORT_SYMBOL(_copy_from_user);
18447-EXPORT_SYMBOL(_copy_to_user);
18448
18449 EXPORT_SYMBOL(copy_page);
18450 EXPORT_SYMBOL(clear_page);
18451diff -urNp linux-2.6.39.1/arch/x86/kernel/xsave.c linux-2.6.39.1/arch/x86/kernel/xsave.c
18452--- linux-2.6.39.1/arch/x86/kernel/xsave.c 2011-05-19 00:06:34.000000000 -0400
18453+++ linux-2.6.39.1/arch/x86/kernel/xsave.c 2011-05-22 19:36:30.000000000 -0400
18454@@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
18455 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18456 return -EINVAL;
18457
18458- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18459+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18460 fx_sw_user->extended_size -
18461 FP_XSTATE_MAGIC2_SIZE));
18462 if (err)
18463@@ -267,7 +267,7 @@ fx_only:
18464 * the other extended state.
18465 */
18466 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18467- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18468+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18469 }
18470
18471 /*
18472@@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
18473 if (use_xsave())
18474 err = restore_user_xstate(buf);
18475 else
18476- err = fxrstor_checking((__force struct i387_fxsave_struct *)
18477+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
18478 buf);
18479 if (unlikely(err)) {
18480 /*
18481diff -urNp linux-2.6.39.1/arch/x86/kvm/emulate.c linux-2.6.39.1/arch/x86/kvm/emulate.c
18482--- linux-2.6.39.1/arch/x86/kvm/emulate.c 2011-05-19 00:06:34.000000000 -0400
18483+++ linux-2.6.39.1/arch/x86/kvm/emulate.c 2011-05-22 19:36:30.000000000 -0400
18484@@ -89,7 +89,7 @@
18485 #define Src2ImmByte (2<<29)
18486 #define Src2One (3<<29)
18487 #define Src2Imm (4<<29)
18488-#define Src2Mask (7<<29)
18489+#define Src2Mask (7U<<29)
18490
18491 #define X2(x...) x, x
18492 #define X3(x...) X2(x), x
18493@@ -190,6 +190,7 @@ struct group_dual {
18494
18495 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
18496 do { \
18497+ unsigned long _tmp; \
18498 __asm__ __volatile__ ( \
18499 _PRE_EFLAGS("0", "4", "2") \
18500 _op _suffix " %"_x"3,%1; " \
18501@@ -203,8 +204,6 @@ struct group_dual {
18502 /* Raw emulation: instruction has two explicit operands. */
18503 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18504 do { \
18505- unsigned long _tmp; \
18506- \
18507 switch ((_dst).bytes) { \
18508 case 2: \
18509 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
18510@@ -220,7 +219,6 @@ struct group_dual {
18511
18512 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18513 do { \
18514- unsigned long _tmp; \
18515 switch ((_dst).bytes) { \
18516 case 1: \
18517 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
18518diff -urNp linux-2.6.39.1/arch/x86/kvm/lapic.c linux-2.6.39.1/arch/x86/kvm/lapic.c
18519--- linux-2.6.39.1/arch/x86/kvm/lapic.c 2011-05-19 00:06:34.000000000 -0400
18520+++ linux-2.6.39.1/arch/x86/kvm/lapic.c 2011-05-22 19:36:30.000000000 -0400
18521@@ -53,7 +53,7 @@
18522 #define APIC_BUS_CYCLE_NS 1
18523
18524 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18525-#define apic_debug(fmt, arg...)
18526+#define apic_debug(fmt, arg...) do {} while (0)
18527
18528 #define APIC_LVT_NUM 6
18529 /* 14 is the version for Xeon and Pentium 8.4.8*/
18530diff -urNp linux-2.6.39.1/arch/x86/kvm/mmu.c linux-2.6.39.1/arch/x86/kvm/mmu.c
18531--- linux-2.6.39.1/arch/x86/kvm/mmu.c 2011-05-19 00:06:34.000000000 -0400
18532+++ linux-2.6.39.1/arch/x86/kvm/mmu.c 2011-05-22 19:36:30.000000000 -0400
18533@@ -3240,7 +3240,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18534
18535 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18536
18537- invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18538+ invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18539
18540 /*
18541 * Assume that the pte write on a page table of the same type
18542@@ -3275,7 +3275,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18543 smp_rmb();
18544
18545 spin_lock(&vcpu->kvm->mmu_lock);
18546- if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18547+ if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18548 gentry = 0;
18549 kvm_mmu_free_some_pages(vcpu);
18550 ++vcpu->kvm->stat.mmu_pte_write;
18551diff -urNp linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h
18552--- linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h 2011-05-19 00:06:34.000000000 -0400
18553+++ linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h 2011-05-22 19:36:30.000000000 -0400
18554@@ -552,6 +552,8 @@ static int FNAME(page_fault)(struct kvm_
18555 unsigned long mmu_seq;
18556 bool map_writable;
18557
18558+ pax_track_stack();
18559+
18560 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18561
18562 r = mmu_topup_memory_caches(vcpu);
18563@@ -672,7 +674,7 @@ static void FNAME(invlpg)(struct kvm_vcp
18564 if (need_flush)
18565 kvm_flush_remote_tlbs(vcpu->kvm);
18566
18567- atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18568+ atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18569
18570 spin_unlock(&vcpu->kvm->mmu_lock);
18571
18572diff -urNp linux-2.6.39.1/arch/x86/kvm/svm.c linux-2.6.39.1/arch/x86/kvm/svm.c
18573--- linux-2.6.39.1/arch/x86/kvm/svm.c 2011-05-19 00:06:34.000000000 -0400
18574+++ linux-2.6.39.1/arch/x86/kvm/svm.c 2011-05-22 19:36:30.000000000 -0400
18575@@ -3278,7 +3278,11 @@ static void reload_tss(struct kvm_vcpu *
18576 int cpu = raw_smp_processor_id();
18577
18578 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18579+
18580+ pax_open_kernel();
18581 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18582+ pax_close_kernel();
18583+
18584 load_TR_desc();
18585 }
18586
18587@@ -3656,6 +3660,10 @@ static void svm_vcpu_run(struct kvm_vcpu
18588 #endif
18589 #endif
18590
18591+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18592+ __set_fs(current_thread_info()->addr_limit);
18593+#endif
18594+
18595 reload_tss(vcpu);
18596
18597 local_irq_disable();
18598@@ -3871,7 +3879,7 @@ static void svm_fpu_deactivate(struct kv
18599 update_cr0_intercept(svm);
18600 }
18601
18602-static struct kvm_x86_ops svm_x86_ops = {
18603+static const struct kvm_x86_ops svm_x86_ops = {
18604 .cpu_has_kvm_support = has_svm,
18605 .disabled_by_bios = is_disabled,
18606 .hardware_setup = svm_hardware_setup,
18607diff -urNp linux-2.6.39.1/arch/x86/kvm/vmx.c linux-2.6.39.1/arch/x86/kvm/vmx.c
18608--- linux-2.6.39.1/arch/x86/kvm/vmx.c 2011-05-19 00:06:34.000000000 -0400
18609+++ linux-2.6.39.1/arch/x86/kvm/vmx.c 2011-05-22 19:36:30.000000000 -0400
18610@@ -725,7 +725,11 @@ static void reload_tss(void)
18611 struct desc_struct *descs;
18612
18613 descs = (void *)gdt->address;
18614+
18615+ pax_open_kernel();
18616 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18617+ pax_close_kernel();
18618+
18619 load_TR_desc();
18620 }
18621
18622@@ -1648,8 +1652,11 @@ static __init int hardware_setup(void)
18623 if (!cpu_has_vmx_flexpriority())
18624 flexpriority_enabled = 0;
18625
18626- if (!cpu_has_vmx_tpr_shadow())
18627- kvm_x86_ops->update_cr8_intercept = NULL;
18628+ if (!cpu_has_vmx_tpr_shadow()) {
18629+ pax_open_kernel();
18630+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18631+ pax_close_kernel();
18632+ }
18633
18634 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18635 kvm_disable_largepages();
18636@@ -2693,7 +2700,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18637 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18638
18639 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18640- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18641+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18642 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18643 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18644 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
18645@@ -4068,6 +4075,12 @@ static void __noclone vmx_vcpu_run(struc
18646 "jmp .Lkvm_vmx_return \n\t"
18647 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18648 ".Lkvm_vmx_return: "
18649+
18650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18651+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18652+ ".Lkvm_vmx_return2: "
18653+#endif
18654+
18655 /* Save guest registers, load host registers, keep flags */
18656 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18657 "pop %0 \n\t"
18658@@ -4116,6 +4129,11 @@ static void __noclone vmx_vcpu_run(struc
18659 #endif
18660 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18661 [wordsize]"i"(sizeof(ulong))
18662+
18663+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18664+ ,[cs]"i"(__KERNEL_CS)
18665+#endif
18666+
18667 : "cc", "memory"
18668 , R"ax", R"bx", R"di", R"si"
18669 #ifdef CONFIG_X86_64
18670@@ -4130,7 +4148,16 @@ static void __noclone vmx_vcpu_run(struc
18671
18672 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
18673
18674- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18675+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18676+
18677+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18678+ loadsegment(fs, __KERNEL_PERCPU);
18679+#endif
18680+
18681+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18682+ __set_fs(current_thread_info()->addr_limit);
18683+#endif
18684+
18685 vmx->launched = 1;
18686
18687 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18688@@ -4368,7 +4395,7 @@ static void vmx_set_supported_cpuid(u32
18689 {
18690 }
18691
18692-static struct kvm_x86_ops vmx_x86_ops = {
18693+static const struct kvm_x86_ops vmx_x86_ops = {
18694 .cpu_has_kvm_support = cpu_has_kvm_support,
18695 .disabled_by_bios = vmx_disabled_by_bios,
18696 .hardware_setup = hardware_setup,
18697diff -urNp linux-2.6.39.1/arch/x86/kvm/x86.c linux-2.6.39.1/arch/x86/kvm/x86.c
18698--- linux-2.6.39.1/arch/x86/kvm/x86.c 2011-05-19 00:06:34.000000000 -0400
18699+++ linux-2.6.39.1/arch/x86/kvm/x86.c 2011-05-22 19:36:30.000000000 -0400
18700@@ -94,7 +94,7 @@ static void update_cr8_intercept(struct
18701 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18702 struct kvm_cpuid_entry2 __user *entries);
18703
18704-struct kvm_x86_ops *kvm_x86_ops;
18705+const struct kvm_x86_ops *kvm_x86_ops;
18706 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18707
18708 int ignore_msrs = 0;
18709@@ -2050,6 +2050,8 @@ long kvm_arch_dev_ioctl(struct file *fil
18710 if (n < msr_list.nmsrs)
18711 goto out;
18712 r = -EFAULT;
18713+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18714+ goto out;
18715 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18716 num_msrs_to_save * sizeof(u32)))
18717 goto out;
18718@@ -2217,15 +2219,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18719 struct kvm_cpuid2 *cpuid,
18720 struct kvm_cpuid_entry2 __user *entries)
18721 {
18722- int r;
18723+ int r, i;
18724
18725 r = -E2BIG;
18726 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18727 goto out;
18728 r = -EFAULT;
18729- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18730- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18731+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18732 goto out;
18733+ for (i = 0; i < cpuid->nent; ++i) {
18734+ struct kvm_cpuid_entry2 cpuid_entry;
18735+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18736+ goto out;
18737+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
18738+ }
18739 vcpu->arch.cpuid_nent = cpuid->nent;
18740 kvm_apic_set_version(vcpu);
18741 kvm_x86_ops->cpuid_update(vcpu);
18742@@ -2240,15 +2247,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18743 struct kvm_cpuid2 *cpuid,
18744 struct kvm_cpuid_entry2 __user *entries)
18745 {
18746- int r;
18747+ int r, i;
18748
18749 r = -E2BIG;
18750 if (cpuid->nent < vcpu->arch.cpuid_nent)
18751 goto out;
18752 r = -EFAULT;
18753- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18754- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18755+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18756 goto out;
18757+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18758+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18759+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18760+ goto out;
18761+ }
18762 return 0;
18763
18764 out:
18765@@ -2526,7 +2537,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18766 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18767 struct kvm_interrupt *irq)
18768 {
18769- if (irq->irq < 0 || irq->irq >= 256)
18770+ if (irq->irq >= 256)
18771 return -EINVAL;
18772 if (irqchip_in_kernel(vcpu->kvm))
18773 return -ENXIO;
18774@@ -4672,7 +4683,7 @@ static unsigned long kvm_get_guest_ip(vo
18775 return ip;
18776 }
18777
18778-static struct perf_guest_info_callbacks kvm_guest_cbs = {
18779+static const struct perf_guest_info_callbacks kvm_guest_cbs = {
18780 .is_in_guest = kvm_is_in_guest,
18781 .is_user_mode = kvm_is_user_mode,
18782 .get_guest_ip = kvm_get_guest_ip,
18783@@ -4690,10 +4701,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
18784 }
18785 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
18786
18787-int kvm_arch_init(void *opaque)
18788+int kvm_arch_init(const void *opaque)
18789 {
18790 int r;
18791- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18792+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18793
18794 if (kvm_x86_ops) {
18795 printk(KERN_ERR "kvm: already loaded the other module\n");
18796diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_32.c linux-2.6.39.1/arch/x86/lib/atomic64_32.c
18797--- linux-2.6.39.1/arch/x86/lib/atomic64_32.c 2011-05-19 00:06:34.000000000 -0400
18798+++ linux-2.6.39.1/arch/x86/lib/atomic64_32.c 2011-05-22 19:36:30.000000000 -0400
18799@@ -8,18 +8,30 @@
18800
18801 long long atomic64_read_cx8(long long, const atomic64_t *v);
18802 EXPORT_SYMBOL(atomic64_read_cx8);
18803+long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18804+EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18805 long long atomic64_set_cx8(long long, const atomic64_t *v);
18806 EXPORT_SYMBOL(atomic64_set_cx8);
18807+long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18808+EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18809 long long atomic64_xchg_cx8(long long, unsigned high);
18810 EXPORT_SYMBOL(atomic64_xchg_cx8);
18811 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18812 EXPORT_SYMBOL(atomic64_add_return_cx8);
18813+long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18814+EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18815 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18816 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18817+long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18818+EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18819 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18820 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18821+long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18822+EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18823 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18824 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18825+long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18826+EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18827 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18828 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18829 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18830@@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18831 #ifndef CONFIG_X86_CMPXCHG64
18832 long long atomic64_read_386(long long, const atomic64_t *v);
18833 EXPORT_SYMBOL(atomic64_read_386);
18834+long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18835+EXPORT_SYMBOL(atomic64_read_unchecked_386);
18836 long long atomic64_set_386(long long, const atomic64_t *v);
18837 EXPORT_SYMBOL(atomic64_set_386);
18838+long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18839+EXPORT_SYMBOL(atomic64_set_unchecked_386);
18840 long long atomic64_xchg_386(long long, unsigned high);
18841 EXPORT_SYMBOL(atomic64_xchg_386);
18842 long long atomic64_add_return_386(long long a, atomic64_t *v);
18843 EXPORT_SYMBOL(atomic64_add_return_386);
18844+long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18845+EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18846 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18847 EXPORT_SYMBOL(atomic64_sub_return_386);
18848+long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18849+EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18850 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18851 EXPORT_SYMBOL(atomic64_inc_return_386);
18852+long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18853+EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18854 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18855 EXPORT_SYMBOL(atomic64_dec_return_386);
18856+long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18857+EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18858 long long atomic64_add_386(long long a, atomic64_t *v);
18859 EXPORT_SYMBOL(atomic64_add_386);
18860+long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18861+EXPORT_SYMBOL(atomic64_add_unchecked_386);
18862 long long atomic64_sub_386(long long a, atomic64_t *v);
18863 EXPORT_SYMBOL(atomic64_sub_386);
18864+long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18865+EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18866 long long atomic64_inc_386(long long a, atomic64_t *v);
18867 EXPORT_SYMBOL(atomic64_inc_386);
18868+long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18869+EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18870 long long atomic64_dec_386(long long a, atomic64_t *v);
18871 EXPORT_SYMBOL(atomic64_dec_386);
18872+long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18873+EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18874 long long atomic64_dec_if_positive_386(atomic64_t *v);
18875 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18876 int atomic64_inc_not_zero_386(atomic64_t *v);
18877diff -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
18878--- linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S 2011-05-19 00:06:34.000000000 -0400
18879+++ linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S 2011-05-22 19:36:30.000000000 -0400
18880@@ -48,6 +48,10 @@ BEGIN(read)
18881 movl (v), %eax
18882 movl 4(v), %edx
18883 RET_ENDP
18884+BEGIN(read_unchecked)
18885+ movl (v), %eax
18886+ movl 4(v), %edx
18887+RET_ENDP
18888 #undef v
18889
18890 #define v %esi
18891@@ -55,6 +59,10 @@ BEGIN(set)
18892 movl %ebx, (v)
18893 movl %ecx, 4(v)
18894 RET_ENDP
18895+BEGIN(set_unchecked)
18896+ movl %ebx, (v)
18897+ movl %ecx, 4(v)
18898+RET_ENDP
18899 #undef v
18900
18901 #define v %esi
18902@@ -70,6 +78,20 @@ RET_ENDP
18903 BEGIN(add)
18904 addl %eax, (v)
18905 adcl %edx, 4(v)
18906+
18907+#ifdef CONFIG_PAX_REFCOUNT
18908+ jno 0f
18909+ subl %eax, (v)
18910+ sbbl %edx, 4(v)
18911+ int $4
18912+0:
18913+ _ASM_EXTABLE(0b, 0b)
18914+#endif
18915+
18916+RET_ENDP
18917+BEGIN(add_unchecked)
18918+ addl %eax, (v)
18919+ adcl %edx, 4(v)
18920 RET_ENDP
18921 #undef v
18922
18923@@ -77,6 +99,24 @@ RET_ENDP
18924 BEGIN(add_return)
18925 addl (v), %eax
18926 adcl 4(v), %edx
18927+
18928+#ifdef CONFIG_PAX_REFCOUNT
18929+ into
18930+1234:
18931+ _ASM_EXTABLE(1234b, 2f)
18932+#endif
18933+
18934+ movl %eax, (v)
18935+ movl %edx, 4(v)
18936+
18937+#ifdef CONFIG_PAX_REFCOUNT
18938+2:
18939+#endif
18940+
18941+RET_ENDP
18942+BEGIN(add_return_unchecked)
18943+ addl (v), %eax
18944+ adcl 4(v), %edx
18945 movl %eax, (v)
18946 movl %edx, 4(v)
18947 RET_ENDP
18948@@ -86,6 +126,20 @@ RET_ENDP
18949 BEGIN(sub)
18950 subl %eax, (v)
18951 sbbl %edx, 4(v)
18952+
18953+#ifdef CONFIG_PAX_REFCOUNT
18954+ jno 0f
18955+ addl %eax, (v)
18956+ adcl %edx, 4(v)
18957+ int $4
18958+0:
18959+ _ASM_EXTABLE(0b, 0b)
18960+#endif
18961+
18962+RET_ENDP
18963+BEGIN(sub_unchecked)
18964+ subl %eax, (v)
18965+ sbbl %edx, 4(v)
18966 RET_ENDP
18967 #undef v
18968
18969@@ -96,6 +150,27 @@ BEGIN(sub_return)
18970 sbbl $0, %edx
18971 addl (v), %eax
18972 adcl 4(v), %edx
18973+
18974+#ifdef CONFIG_PAX_REFCOUNT
18975+ into
18976+1234:
18977+ _ASM_EXTABLE(1234b, 2f)
18978+#endif
18979+
18980+ movl %eax, (v)
18981+ movl %edx, 4(v)
18982+
18983+#ifdef CONFIG_PAX_REFCOUNT
18984+2:
18985+#endif
18986+
18987+RET_ENDP
18988+BEGIN(sub_return_unchecked)
18989+ negl %edx
18990+ negl %eax
18991+ sbbl $0, %edx
18992+ addl (v), %eax
18993+ adcl 4(v), %edx
18994 movl %eax, (v)
18995 movl %edx, 4(v)
18996 RET_ENDP
18997@@ -105,6 +180,20 @@ RET_ENDP
18998 BEGIN(inc)
18999 addl $1, (v)
19000 adcl $0, 4(v)
19001+
19002+#ifdef CONFIG_PAX_REFCOUNT
19003+ jno 0f
19004+ subl $1, (v)
19005+ sbbl $0, 4(v)
19006+ int $4
19007+0:
19008+ _ASM_EXTABLE(0b, 0b)
19009+#endif
19010+
19011+RET_ENDP
19012+BEGIN(inc_unchecked)
19013+ addl $1, (v)
19014+ adcl $0, 4(v)
19015 RET_ENDP
19016 #undef v
19017
19018@@ -114,6 +203,26 @@ BEGIN(inc_return)
19019 movl 4(v), %edx
19020 addl $1, %eax
19021 adcl $0, %edx
19022+
19023+#ifdef CONFIG_PAX_REFCOUNT
19024+ into
19025+1234:
19026+ _ASM_EXTABLE(1234b, 2f)
19027+#endif
19028+
19029+ movl %eax, (v)
19030+ movl %edx, 4(v)
19031+
19032+#ifdef CONFIG_PAX_REFCOUNT
19033+2:
19034+#endif
19035+
19036+RET_ENDP
19037+BEGIN(inc_return_unchecked)
19038+ movl (v), %eax
19039+ movl 4(v), %edx
19040+ addl $1, %eax
19041+ adcl $0, %edx
19042 movl %eax, (v)
19043 movl %edx, 4(v)
19044 RET_ENDP
19045@@ -123,6 +232,20 @@ RET_ENDP
19046 BEGIN(dec)
19047 subl $1, (v)
19048 sbbl $0, 4(v)
19049+
19050+#ifdef CONFIG_PAX_REFCOUNT
19051+ jno 0f
19052+ addl $1, (v)
19053+ adcl $0, 4(v)
19054+ int $4
19055+0:
19056+ _ASM_EXTABLE(0b, 0b)
19057+#endif
19058+
19059+RET_ENDP
19060+BEGIN(dec_unchecked)
19061+ subl $1, (v)
19062+ sbbl $0, 4(v)
19063 RET_ENDP
19064 #undef v
19065
19066@@ -132,6 +255,26 @@ BEGIN(dec_return)
19067 movl 4(v), %edx
19068 subl $1, %eax
19069 sbbl $0, %edx
19070+
19071+#ifdef CONFIG_PAX_REFCOUNT
19072+ into
19073+1234:
19074+ _ASM_EXTABLE(1234b, 2f)
19075+#endif
19076+
19077+ movl %eax, (v)
19078+ movl %edx, 4(v)
19079+
19080+#ifdef CONFIG_PAX_REFCOUNT
19081+2:
19082+#endif
19083+
19084+RET_ENDP
19085+BEGIN(dec_return_unchecked)
19086+ movl (v), %eax
19087+ movl 4(v), %edx
19088+ subl $1, %eax
19089+ sbbl $0, %edx
19090 movl %eax, (v)
19091 movl %edx, 4(v)
19092 RET_ENDP
19093@@ -143,6 +286,13 @@ BEGIN(add_unless)
19094 adcl %edx, %edi
19095 addl (v), %eax
19096 adcl 4(v), %edx
19097+
19098+#ifdef CONFIG_PAX_REFCOUNT
19099+ into
19100+1234:
19101+ _ASM_EXTABLE(1234b, 2f)
19102+#endif
19103+
19104 cmpl %eax, %esi
19105 je 3f
19106 1:
19107@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
19108 1:
19109 addl $1, %eax
19110 adcl $0, %edx
19111+
19112+#ifdef CONFIG_PAX_REFCOUNT
19113+ into
19114+1234:
19115+ _ASM_EXTABLE(1234b, 2f)
19116+#endif
19117+
19118 movl %eax, (v)
19119 movl %edx, 4(v)
19120 movl $1, %eax
19121@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
19122 movl 4(v), %edx
19123 subl $1, %eax
19124 sbbl $0, %edx
19125+
19126+#ifdef CONFIG_PAX_REFCOUNT
19127+ into
19128+1234:
19129+ _ASM_EXTABLE(1234b, 1f)
19130+#endif
19131+
19132 js 1f
19133 movl %eax, (v)
19134 movl %edx, 4(v)
19135diff -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
19136--- linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S 2011-05-19 00:06:34.000000000 -0400
19137+++ linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S 2011-05-22 19:36:30.000000000 -0400
19138@@ -39,6 +39,14 @@ ENTRY(atomic64_read_cx8)
19139 CFI_ENDPROC
19140 ENDPROC(atomic64_read_cx8)
19141
19142+ENTRY(atomic64_read_unchecked_cx8)
19143+ CFI_STARTPROC
19144+
19145+ read64 %ecx
19146+ ret
19147+ CFI_ENDPROC
19148+ENDPROC(atomic64_read_unchecked_cx8)
19149+
19150 ENTRY(atomic64_set_cx8)
19151 CFI_STARTPROC
19152
19153@@ -52,6 +60,19 @@ ENTRY(atomic64_set_cx8)
19154 CFI_ENDPROC
19155 ENDPROC(atomic64_set_cx8)
19156
19157+ENTRY(atomic64_set_unchecked_cx8)
19158+ CFI_STARTPROC
19159+
19160+1:
19161+/* we don't need LOCK_PREFIX since aligned 64-bit writes
19162+ * are atomic on 586 and newer */
19163+ cmpxchg8b (%esi)
19164+ jne 1b
19165+
19166+ ret
19167+ CFI_ENDPROC
19168+ENDPROC(atomic64_set_unchecked_cx8)
19169+
19170 ENTRY(atomic64_xchg_cx8)
19171 CFI_STARTPROC
19172
19173@@ -66,8 +87,8 @@ ENTRY(atomic64_xchg_cx8)
19174 CFI_ENDPROC
19175 ENDPROC(atomic64_xchg_cx8)
19176
19177-.macro addsub_return func ins insc
19178-ENTRY(atomic64_\func\()_return_cx8)
19179+.macro addsub_return func ins insc unchecked=""
19180+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19181 CFI_STARTPROC
19182 SAVE ebp
19183 SAVE ebx
19184@@ -84,27 +105,43 @@ ENTRY(atomic64_\func\()_return_cx8)
19185 movl %edx, %ecx
19186 \ins\()l %esi, %ebx
19187 \insc\()l %edi, %ecx
19188+
19189+.ifb \unchecked
19190+#ifdef CONFIG_PAX_REFCOUNT
19191+ into
19192+2:
19193+ _ASM_EXTABLE(2b, 3f)
19194+#endif
19195+.endif
19196+
19197 LOCK_PREFIX
19198 cmpxchg8b (%ebp)
19199 jne 1b
19200-
19201-10:
19202 movl %ebx, %eax
19203 movl %ecx, %edx
19204+
19205+.ifb \unchecked
19206+#ifdef CONFIG_PAX_REFCOUNT
19207+3:
19208+#endif
19209+.endif
19210+
19211 RESTORE edi
19212 RESTORE esi
19213 RESTORE ebx
19214 RESTORE ebp
19215 ret
19216 CFI_ENDPROC
19217-ENDPROC(atomic64_\func\()_return_cx8)
19218+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19219 .endm
19220
19221 addsub_return add add adc
19222 addsub_return sub sub sbb
19223+addsub_return add add adc _unchecked
19224+addsub_return sub sub sbb _unchecked
19225
19226-.macro incdec_return func ins insc
19227-ENTRY(atomic64_\func\()_return_cx8)
19228+.macro incdec_return func ins insc unchecked
19229+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19230 CFI_STARTPROC
19231 SAVE ebx
19232
19233@@ -114,21 +151,38 @@ ENTRY(atomic64_\func\()_return_cx8)
19234 movl %edx, %ecx
19235 \ins\()l $1, %ebx
19236 \insc\()l $0, %ecx
19237+
19238+.ifb \unchecked
19239+#ifdef CONFIG_PAX_REFCOUNT
19240+ into
19241+2:
19242+ _ASM_EXTABLE(2b, 3f)
19243+#endif
19244+.endif
19245+
19246 LOCK_PREFIX
19247 cmpxchg8b (%esi)
19248 jne 1b
19249
19250-10:
19251 movl %ebx, %eax
19252 movl %ecx, %edx
19253+
19254+.ifb \unchecked
19255+#ifdef CONFIG_PAX_REFCOUNT
19256+3:
19257+#endif
19258+.endif
19259+
19260 RESTORE ebx
19261 ret
19262 CFI_ENDPROC
19263-ENDPROC(atomic64_\func\()_return_cx8)
19264+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19265 .endm
19266
19267 incdec_return inc add adc
19268 incdec_return dec sub sbb
19269+incdec_return inc add adc _unchecked
19270+incdec_return dec sub sbb _unchecked
19271
19272 ENTRY(atomic64_dec_if_positive_cx8)
19273 CFI_STARTPROC
19274@@ -140,6 +194,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19275 movl %edx, %ecx
19276 subl $1, %ebx
19277 sbb $0, %ecx
19278+
19279+#ifdef CONFIG_PAX_REFCOUNT
19280+ into
19281+1234:
19282+ _ASM_EXTABLE(1234b, 2f)
19283+#endif
19284+
19285 js 2f
19286 LOCK_PREFIX
19287 cmpxchg8b (%esi)
19288@@ -174,6 +235,13 @@ ENTRY(atomic64_add_unless_cx8)
19289 movl %edx, %ecx
19290 addl %esi, %ebx
19291 adcl %edi, %ecx
19292+
19293+#ifdef CONFIG_PAX_REFCOUNT
19294+ into
19295+1234:
19296+ _ASM_EXTABLE(1234b, 3f)
19297+#endif
19298+
19299 LOCK_PREFIX
19300 cmpxchg8b (%ebp)
19301 jne 1b
19302@@ -206,6 +274,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19303 movl %edx, %ecx
19304 addl $1, %ebx
19305 adcl $0, %ecx
19306+
19307+#ifdef CONFIG_PAX_REFCOUNT
19308+ into
19309+1234:
19310+ _ASM_EXTABLE(1234b, 3f)
19311+#endif
19312+
19313 LOCK_PREFIX
19314 cmpxchg8b (%esi)
19315 jne 1b
19316diff -urNp linux-2.6.39.1/arch/x86/lib/checksum_32.S linux-2.6.39.1/arch/x86/lib/checksum_32.S
19317--- linux-2.6.39.1/arch/x86/lib/checksum_32.S 2011-05-19 00:06:34.000000000 -0400
19318+++ linux-2.6.39.1/arch/x86/lib/checksum_32.S 2011-05-22 19:36:30.000000000 -0400
19319@@ -28,7 +28,8 @@
19320 #include <linux/linkage.h>
19321 #include <asm/dwarf2.h>
19322 #include <asm/errno.h>
19323-
19324+#include <asm/segment.h>
19325+
19326 /*
19327 * computes a partial checksum, e.g. for TCP/UDP fragments
19328 */
19329@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (
19330
19331 #define ARGBASE 16
19332 #define FP 12
19333-
19334-ENTRY(csum_partial_copy_generic)
19335+
19336+ENTRY(csum_partial_copy_generic_to_user)
19337 CFI_STARTPROC
19338+
19339+#ifdef CONFIG_PAX_MEMORY_UDEREF
19340+ pushl_cfi %gs
19341+ popl_cfi %es
19342+ jmp csum_partial_copy_generic
19343+#endif
19344+
19345+ENTRY(csum_partial_copy_generic_from_user)
19346+
19347+#ifdef CONFIG_PAX_MEMORY_UDEREF
19348+ pushl_cfi %gs
19349+ popl_cfi %ds
19350+#endif
19351+
19352+ENTRY(csum_partial_copy_generic)
19353 subl $4,%esp
19354 CFI_ADJUST_CFA_OFFSET 4
19355 pushl_cfi %edi
19356@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19357 jmp 4f
19358 SRC(1: movw (%esi), %bx )
19359 addl $2, %esi
19360-DST( movw %bx, (%edi) )
19361+DST( movw %bx, %es:(%edi) )
19362 addl $2, %edi
19363 addw %bx, %ax
19364 adcl $0, %eax
19365@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19366 SRC(1: movl (%esi), %ebx )
19367 SRC( movl 4(%esi), %edx )
19368 adcl %ebx, %eax
19369-DST( movl %ebx, (%edi) )
19370+DST( movl %ebx, %es:(%edi) )
19371 adcl %edx, %eax
19372-DST( movl %edx, 4(%edi) )
19373+DST( movl %edx, %es:4(%edi) )
19374
19375 SRC( movl 8(%esi), %ebx )
19376 SRC( movl 12(%esi), %edx )
19377 adcl %ebx, %eax
19378-DST( movl %ebx, 8(%edi) )
19379+DST( movl %ebx, %es:8(%edi) )
19380 adcl %edx, %eax
19381-DST( movl %edx, 12(%edi) )
19382+DST( movl %edx, %es:12(%edi) )
19383
19384 SRC( movl 16(%esi), %ebx )
19385 SRC( movl 20(%esi), %edx )
19386 adcl %ebx, %eax
19387-DST( movl %ebx, 16(%edi) )
19388+DST( movl %ebx, %es:16(%edi) )
19389 adcl %edx, %eax
19390-DST( movl %edx, 20(%edi) )
19391+DST( movl %edx, %es:20(%edi) )
19392
19393 SRC( movl 24(%esi), %ebx )
19394 SRC( movl 28(%esi), %edx )
19395 adcl %ebx, %eax
19396-DST( movl %ebx, 24(%edi) )
19397+DST( movl %ebx, %es:24(%edi) )
19398 adcl %edx, %eax
19399-DST( movl %edx, 28(%edi) )
19400+DST( movl %edx, %es:28(%edi) )
19401
19402 lea 32(%esi), %esi
19403 lea 32(%edi), %edi
19404@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19405 shrl $2, %edx # This clears CF
19406 SRC(3: movl (%esi), %ebx )
19407 adcl %ebx, %eax
19408-DST( movl %ebx, (%edi) )
19409+DST( movl %ebx, %es:(%edi) )
19410 lea 4(%esi), %esi
19411 lea 4(%edi), %edi
19412 dec %edx
19413@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19414 jb 5f
19415 SRC( movw (%esi), %cx )
19416 leal 2(%esi), %esi
19417-DST( movw %cx, (%edi) )
19418+DST( movw %cx, %es:(%edi) )
19419 leal 2(%edi), %edi
19420 je 6f
19421 shll $16,%ecx
19422 SRC(5: movb (%esi), %cl )
19423-DST( movb %cl, (%edi) )
19424+DST( movb %cl, %es:(%edi) )
19425 6: addl %ecx, %eax
19426 adcl $0, %eax
19427 7:
19428@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19429
19430 6001:
19431 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19432- movl $-EFAULT, (%ebx)
19433+ movl $-EFAULT, %ss:(%ebx)
19434
19435 # zero the complete destination - computing the rest
19436 # is too much work
19437@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19438
19439 6002:
19440 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19441- movl $-EFAULT,(%ebx)
19442+ movl $-EFAULT,%ss:(%ebx)
19443 jmp 5000b
19444
19445 .previous
19446
19447+ pushl_cfi %ss
19448+ popl_cfi %ds
19449+ pushl_cfi %ss
19450+ popl_cfi %es
19451 popl_cfi %ebx
19452 CFI_RESTORE ebx
19453 popl_cfi %esi
19454@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19455 popl_cfi %ecx # equivalent to addl $4,%esp
19456 ret
19457 CFI_ENDPROC
19458-ENDPROC(csum_partial_copy_generic)
19459+ENDPROC(csum_partial_copy_generic_to_user)
19460
19461 #else
19462
19463 /* Version for PentiumII/PPro */
19464
19465 #define ROUND1(x) \
19466+ nop; nop; nop; \
19467 SRC(movl x(%esi), %ebx ) ; \
19468 addl %ebx, %eax ; \
19469- DST(movl %ebx, x(%edi) ) ;
19470+ DST(movl %ebx, %es:x(%edi)) ;
19471
19472 #define ROUND(x) \
19473+ nop; nop; nop; \
19474 SRC(movl x(%esi), %ebx ) ; \
19475 adcl %ebx, %eax ; \
19476- DST(movl %ebx, x(%edi) ) ;
19477+ DST(movl %ebx, %es:x(%edi)) ;
19478
19479 #define ARGBASE 12
19480-
19481-ENTRY(csum_partial_copy_generic)
19482+
19483+ENTRY(csum_partial_copy_generic_to_user)
19484 CFI_STARTPROC
19485+
19486+#ifdef CONFIG_PAX_MEMORY_UDEREF
19487+ pushl_cfi %gs
19488+ popl_cfi %es
19489+ jmp csum_partial_copy_generic
19490+#endif
19491+
19492+ENTRY(csum_partial_copy_generic_from_user)
19493+
19494+#ifdef CONFIG_PAX_MEMORY_UDEREF
19495+ pushl_cfi %gs
19496+ popl_cfi %ds
19497+#endif
19498+
19499+ENTRY(csum_partial_copy_generic)
19500 pushl_cfi %ebx
19501 CFI_REL_OFFSET ebx, 0
19502 pushl_cfi %edi
19503@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19504 subl %ebx, %edi
19505 lea -1(%esi),%edx
19506 andl $-32,%edx
19507- lea 3f(%ebx,%ebx), %ebx
19508+ lea 3f(%ebx,%ebx,2), %ebx
19509 testl %esi, %esi
19510 jmp *%ebx
19511 1: addl $64,%esi
19512@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19513 jb 5f
19514 SRC( movw (%esi), %dx )
19515 leal 2(%esi), %esi
19516-DST( movw %dx, (%edi) )
19517+DST( movw %dx, %es:(%edi) )
19518 leal 2(%edi), %edi
19519 je 6f
19520 shll $16,%edx
19521 5:
19522 SRC( movb (%esi), %dl )
19523-DST( movb %dl, (%edi) )
19524+DST( movb %dl, %es:(%edi) )
19525 6: addl %edx, %eax
19526 adcl $0, %eax
19527 7:
19528 .section .fixup, "ax"
19529 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19530- movl $-EFAULT, (%ebx)
19531+ movl $-EFAULT, %ss:(%ebx)
19532 # zero the complete destination (computing the rest is too much work)
19533 movl ARGBASE+8(%esp),%edi # dst
19534 movl ARGBASE+12(%esp),%ecx # len
19535@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19536 rep; stosb
19537 jmp 7b
19538 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19539- movl $-EFAULT, (%ebx)
19540+ movl $-EFAULT, %ss:(%ebx)
19541 jmp 7b
19542 .previous
19543
19544+#ifdef CONFIG_PAX_MEMORY_UDEREF
19545+ pushl_cfi %ss
19546+ popl_cfi %ds
19547+ pushl_cfi %ss
19548+ popl_cfi %es
19549+#endif
19550+
19551 popl_cfi %esi
19552 CFI_RESTORE esi
19553 popl_cfi %edi
19554@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19555 CFI_RESTORE ebx
19556 ret
19557 CFI_ENDPROC
19558-ENDPROC(csum_partial_copy_generic)
19559+ENDPROC(csum_partial_copy_generic_to_user)
19560
19561 #undef ROUND
19562 #undef ROUND1
19563diff -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
19564--- linux-2.6.39.1/arch/x86/lib/clear_page_64.S 2011-05-19 00:06:34.000000000 -0400
19565+++ linux-2.6.39.1/arch/x86/lib/clear_page_64.S 2011-05-22 19:36:30.000000000 -0400
19566@@ -43,7 +43,7 @@ ENDPROC(clear_page)
19567
19568 #include <asm/cpufeature.h>
19569
19570- .section .altinstr_replacement,"ax"
19571+ .section .altinstr_replacement,"a"
19572 1: .byte 0xeb /* jmp <disp8> */
19573 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19574 2:
19575diff -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
19576--- linux-2.6.39.1/arch/x86/lib/copy_page_64.S 2011-05-19 00:06:34.000000000 -0400
19577+++ linux-2.6.39.1/arch/x86/lib/copy_page_64.S 2011-05-22 19:36:30.000000000 -0400
19578@@ -104,7 +104,7 @@ ENDPROC(copy_page)
19579
19580 #include <asm/cpufeature.h>
19581
19582- .section .altinstr_replacement,"ax"
19583+ .section .altinstr_replacement,"a"
19584 1: .byte 0xeb /* jmp <disp8> */
19585 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19586 2:
19587diff -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
19588--- linux-2.6.39.1/arch/x86/lib/copy_user_64.S 2011-06-03 00:04:13.000000000 -0400
19589+++ linux-2.6.39.1/arch/x86/lib/copy_user_64.S 2011-06-03 00:32:05.000000000 -0400
19590@@ -15,13 +15,14 @@
19591 #include <asm/asm-offsets.h>
19592 #include <asm/thread_info.h>
19593 #include <asm/cpufeature.h>
19594+#include <asm/pgtable.h>
19595
19596 .macro ALTERNATIVE_JUMP feature,orig,alt
19597 0:
19598 .byte 0xe9 /* 32bit jump */
19599 .long \orig-1f /* by default jump to orig */
19600 1:
19601- .section .altinstr_replacement,"ax"
19602+ .section .altinstr_replacement,"a"
19603 2: .byte 0xe9 /* near jump with 32bit immediate */
19604 .long \alt-1b /* offset */ /* or alternatively to alt */
19605 .previous
19606@@ -64,37 +65,13 @@
19607 #endif
19608 .endm
19609
19610-/* Standard copy_to_user with segment limit checking */
19611-ENTRY(_copy_to_user)
19612- CFI_STARTPROC
19613- GET_THREAD_INFO(%rax)
19614- movq %rdi,%rcx
19615- addq %rdx,%rcx
19616- jc bad_to_user
19617- cmpq TI_addr_limit(%rax),%rcx
19618- ja bad_to_user
19619- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19620- CFI_ENDPROC
19621-ENDPROC(_copy_to_user)
19622-
19623-/* Standard copy_from_user with segment limit checking */
19624-ENTRY(_copy_from_user)
19625- CFI_STARTPROC
19626- GET_THREAD_INFO(%rax)
19627- movq %rsi,%rcx
19628- addq %rdx,%rcx
19629- jc bad_from_user
19630- cmpq TI_addr_limit(%rax),%rcx
19631- ja bad_from_user
19632- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19633- CFI_ENDPROC
19634-ENDPROC(_copy_from_user)
19635-
19636 .section .fixup,"ax"
19637 /* must zero dest */
19638 ENTRY(bad_from_user)
19639 bad_from_user:
19640 CFI_STARTPROC
19641+ testl %edx,%edx
19642+ js bad_to_user
19643 movl %edx,%ecx
19644 xorl %eax,%eax
19645 rep
19646diff -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
19647--- linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S 2011-05-19 00:06:34.000000000 -0400
19648+++ linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S 2011-05-22 19:36:30.000000000 -0400
19649@@ -14,6 +14,7 @@
19650 #include <asm/current.h>
19651 #include <asm/asm-offsets.h>
19652 #include <asm/thread_info.h>
19653+#include <asm/pgtable.h>
19654
19655 .macro ALIGN_DESTINATION
19656 #ifdef FIX_ALIGNMENT
19657@@ -50,6 +51,15 @@
19658 */
19659 ENTRY(__copy_user_nocache)
19660 CFI_STARTPROC
19661+
19662+#ifdef CONFIG_PAX_MEMORY_UDEREF
19663+ mov $PAX_USER_SHADOW_BASE,%rcx
19664+ cmp %rcx,%rsi
19665+ jae 1f
19666+ add %rcx,%rsi
19667+1:
19668+#endif
19669+
19670 cmpl $8,%edx
19671 jb 20f /* less then 8 bytes, go to byte copy loop */
19672 ALIGN_DESTINATION
19673diff -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
19674--- linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c 2011-05-19 00:06:34.000000000 -0400
19675+++ linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c 2011-05-22 19:36:30.000000000 -0400
19676@@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19677 len -= 2;
19678 }
19679 }
19680+
19681+#ifdef CONFIG_PAX_MEMORY_UDEREF
19682+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19683+ src += PAX_USER_SHADOW_BASE;
19684+#endif
19685+
19686 isum = csum_partial_copy_generic((__force const void *)src,
19687 dst, len, isum, errp, NULL);
19688 if (unlikely(*errp))
19689@@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19690 }
19691
19692 *errp = 0;
19693+
19694+#ifdef CONFIG_PAX_MEMORY_UDEREF
19695+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19696+ dst += PAX_USER_SHADOW_BASE;
19697+#endif
19698+
19699 return csum_partial_copy_generic(src, (void __force *)dst,
19700 len, isum, NULL, errp);
19701 }
19702diff -urNp linux-2.6.39.1/arch/x86/lib/getuser.S linux-2.6.39.1/arch/x86/lib/getuser.S
19703--- linux-2.6.39.1/arch/x86/lib/getuser.S 2011-05-19 00:06:34.000000000 -0400
19704+++ linux-2.6.39.1/arch/x86/lib/getuser.S 2011-05-22 19:36:30.000000000 -0400
19705@@ -33,14 +33,35 @@
19706 #include <asm/asm-offsets.h>
19707 #include <asm/thread_info.h>
19708 #include <asm/asm.h>
19709+#include <asm/segment.h>
19710+#include <asm/pgtable.h>
19711+
19712+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19713+#define __copyuser_seg gs;
19714+#else
19715+#define __copyuser_seg
19716+#endif
19717
19718 .text
19719 ENTRY(__get_user_1)
19720 CFI_STARTPROC
19721+
19722+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19723 GET_THREAD_INFO(%_ASM_DX)
19724 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19725 jae bad_get_user
19726-1: movzb (%_ASM_AX),%edx
19727+
19728+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19729+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19730+ cmp %_ASM_DX,%_ASM_AX
19731+ jae 1234f
19732+ add %_ASM_DX,%_ASM_AX
19733+1234:
19734+#endif
19735+
19736+#endif
19737+
19738+1: __copyuser_seg movzb (%_ASM_AX),%edx
19739 xor %eax,%eax
19740 ret
19741 CFI_ENDPROC
19742@@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19743 ENTRY(__get_user_2)
19744 CFI_STARTPROC
19745 add $1,%_ASM_AX
19746+
19747+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19748 jc bad_get_user
19749 GET_THREAD_INFO(%_ASM_DX)
19750 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19751 jae bad_get_user
19752-2: movzwl -1(%_ASM_AX),%edx
19753+
19754+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19755+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19756+ cmp %_ASM_DX,%_ASM_AX
19757+ jae 1234f
19758+ add %_ASM_DX,%_ASM_AX
19759+1234:
19760+#endif
19761+
19762+#endif
19763+
19764+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19765 xor %eax,%eax
19766 ret
19767 CFI_ENDPROC
19768@@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19769 ENTRY(__get_user_4)
19770 CFI_STARTPROC
19771 add $3,%_ASM_AX
19772+
19773+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19774 jc bad_get_user
19775 GET_THREAD_INFO(%_ASM_DX)
19776 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19777 jae bad_get_user
19778-3: mov -3(%_ASM_AX),%edx
19779+
19780+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19781+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19782+ cmp %_ASM_DX,%_ASM_AX
19783+ jae 1234f
19784+ add %_ASM_DX,%_ASM_AX
19785+1234:
19786+#endif
19787+
19788+#endif
19789+
19790+3: __copyuser_seg mov -3(%_ASM_AX),%edx
19791 xor %eax,%eax
19792 ret
19793 CFI_ENDPROC
19794@@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19795 GET_THREAD_INFO(%_ASM_DX)
19796 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19797 jae bad_get_user
19798+
19799+#ifdef CONFIG_PAX_MEMORY_UDEREF
19800+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19801+ cmp %_ASM_DX,%_ASM_AX
19802+ jae 1234f
19803+ add %_ASM_DX,%_ASM_AX
19804+1234:
19805+#endif
19806+
19807 4: movq -7(%_ASM_AX),%_ASM_DX
19808 xor %eax,%eax
19809 ret
19810diff -urNp linux-2.6.39.1/arch/x86/lib/insn.c linux-2.6.39.1/arch/x86/lib/insn.c
19811--- linux-2.6.39.1/arch/x86/lib/insn.c 2011-05-19 00:06:34.000000000 -0400
19812+++ linux-2.6.39.1/arch/x86/lib/insn.c 2011-05-22 19:36:30.000000000 -0400
19813@@ -21,6 +21,11 @@
19814 #include <linux/string.h>
19815 #include <asm/inat.h>
19816 #include <asm/insn.h>
19817+#ifdef __KERNEL__
19818+#include <asm/pgtable_types.h>
19819+#else
19820+#define ktla_ktva(addr) addr
19821+#endif
19822
19823 #define get_next(t, insn) \
19824 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
19825@@ -40,8 +45,8 @@
19826 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19827 {
19828 memset(insn, 0, sizeof(*insn));
19829- insn->kaddr = kaddr;
19830- insn->next_byte = kaddr;
19831+ insn->kaddr = ktla_ktva(kaddr);
19832+ insn->next_byte = ktla_ktva(kaddr);
19833 insn->x86_64 = x86_64 ? 1 : 0;
19834 insn->opnd_bytes = 4;
19835 if (x86_64)
19836diff -urNp linux-2.6.39.1/arch/x86/lib/mmx_32.c linux-2.6.39.1/arch/x86/lib/mmx_32.c
19837--- linux-2.6.39.1/arch/x86/lib/mmx_32.c 2011-05-19 00:06:34.000000000 -0400
19838+++ linux-2.6.39.1/arch/x86/lib/mmx_32.c 2011-05-22 19:36:30.000000000 -0400
19839@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19840 {
19841 void *p;
19842 int i;
19843+ unsigned long cr0;
19844
19845 if (unlikely(in_interrupt()))
19846 return __memcpy(to, from, len);
19847@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19848 kernel_fpu_begin();
19849
19850 __asm__ __volatile__ (
19851- "1: prefetch (%0)\n" /* This set is 28 bytes */
19852- " prefetch 64(%0)\n"
19853- " prefetch 128(%0)\n"
19854- " prefetch 192(%0)\n"
19855- " prefetch 256(%0)\n"
19856+ "1: prefetch (%1)\n" /* This set is 28 bytes */
19857+ " prefetch 64(%1)\n"
19858+ " prefetch 128(%1)\n"
19859+ " prefetch 192(%1)\n"
19860+ " prefetch 256(%1)\n"
19861 "2: \n"
19862 ".section .fixup, \"ax\"\n"
19863- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19864+ "3: \n"
19865+
19866+#ifdef CONFIG_PAX_KERNEXEC
19867+ " movl %%cr0, %0\n"
19868+ " movl %0, %%eax\n"
19869+ " andl $0xFFFEFFFF, %%eax\n"
19870+ " movl %%eax, %%cr0\n"
19871+#endif
19872+
19873+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19874+
19875+#ifdef CONFIG_PAX_KERNEXEC
19876+ " movl %0, %%cr0\n"
19877+#endif
19878+
19879 " jmp 2b\n"
19880 ".previous\n"
19881 _ASM_EXTABLE(1b, 3b)
19882- : : "r" (from));
19883+ : "=&r" (cr0) : "r" (from) : "ax");
19884
19885 for ( ; i > 5; i--) {
19886 __asm__ __volatile__ (
19887- "1: prefetch 320(%0)\n"
19888- "2: movq (%0), %%mm0\n"
19889- " movq 8(%0), %%mm1\n"
19890- " movq 16(%0), %%mm2\n"
19891- " movq 24(%0), %%mm3\n"
19892- " movq %%mm0, (%1)\n"
19893- " movq %%mm1, 8(%1)\n"
19894- " movq %%mm2, 16(%1)\n"
19895- " movq %%mm3, 24(%1)\n"
19896- " movq 32(%0), %%mm0\n"
19897- " movq 40(%0), %%mm1\n"
19898- " movq 48(%0), %%mm2\n"
19899- " movq 56(%0), %%mm3\n"
19900- " movq %%mm0, 32(%1)\n"
19901- " movq %%mm1, 40(%1)\n"
19902- " movq %%mm2, 48(%1)\n"
19903- " movq %%mm3, 56(%1)\n"
19904+ "1: prefetch 320(%1)\n"
19905+ "2: movq (%1), %%mm0\n"
19906+ " movq 8(%1), %%mm1\n"
19907+ " movq 16(%1), %%mm2\n"
19908+ " movq 24(%1), %%mm3\n"
19909+ " movq %%mm0, (%2)\n"
19910+ " movq %%mm1, 8(%2)\n"
19911+ " movq %%mm2, 16(%2)\n"
19912+ " movq %%mm3, 24(%2)\n"
19913+ " movq 32(%1), %%mm0\n"
19914+ " movq 40(%1), %%mm1\n"
19915+ " movq 48(%1), %%mm2\n"
19916+ " movq 56(%1), %%mm3\n"
19917+ " movq %%mm0, 32(%2)\n"
19918+ " movq %%mm1, 40(%2)\n"
19919+ " movq %%mm2, 48(%2)\n"
19920+ " movq %%mm3, 56(%2)\n"
19921 ".section .fixup, \"ax\"\n"
19922- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19923+ "3:\n"
19924+
19925+#ifdef CONFIG_PAX_KERNEXEC
19926+ " movl %%cr0, %0\n"
19927+ " movl %0, %%eax\n"
19928+ " andl $0xFFFEFFFF, %%eax\n"
19929+ " movl %%eax, %%cr0\n"
19930+#endif
19931+
19932+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19933+
19934+#ifdef CONFIG_PAX_KERNEXEC
19935+ " movl %0, %%cr0\n"
19936+#endif
19937+
19938 " jmp 2b\n"
19939 ".previous\n"
19940 _ASM_EXTABLE(1b, 3b)
19941- : : "r" (from), "r" (to) : "memory");
19942+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19943
19944 from += 64;
19945 to += 64;
19946@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19947 static void fast_copy_page(void *to, void *from)
19948 {
19949 int i;
19950+ unsigned long cr0;
19951
19952 kernel_fpu_begin();
19953
19954@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19955 * but that is for later. -AV
19956 */
19957 __asm__ __volatile__(
19958- "1: prefetch (%0)\n"
19959- " prefetch 64(%0)\n"
19960- " prefetch 128(%0)\n"
19961- " prefetch 192(%0)\n"
19962- " prefetch 256(%0)\n"
19963+ "1: prefetch (%1)\n"
19964+ " prefetch 64(%1)\n"
19965+ " prefetch 128(%1)\n"
19966+ " prefetch 192(%1)\n"
19967+ " prefetch 256(%1)\n"
19968 "2: \n"
19969 ".section .fixup, \"ax\"\n"
19970- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19971+ "3: \n"
19972+
19973+#ifdef CONFIG_PAX_KERNEXEC
19974+ " movl %%cr0, %0\n"
19975+ " movl %0, %%eax\n"
19976+ " andl $0xFFFEFFFF, %%eax\n"
19977+ " movl %%eax, %%cr0\n"
19978+#endif
19979+
19980+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19981+
19982+#ifdef CONFIG_PAX_KERNEXEC
19983+ " movl %0, %%cr0\n"
19984+#endif
19985+
19986 " jmp 2b\n"
19987 ".previous\n"
19988- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19989+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19990
19991 for (i = 0; i < (4096-320)/64; i++) {
19992 __asm__ __volatile__ (
19993- "1: prefetch 320(%0)\n"
19994- "2: movq (%0), %%mm0\n"
19995- " movntq %%mm0, (%1)\n"
19996- " movq 8(%0), %%mm1\n"
19997- " movntq %%mm1, 8(%1)\n"
19998- " movq 16(%0), %%mm2\n"
19999- " movntq %%mm2, 16(%1)\n"
20000- " movq 24(%0), %%mm3\n"
20001- " movntq %%mm3, 24(%1)\n"
20002- " movq 32(%0), %%mm4\n"
20003- " movntq %%mm4, 32(%1)\n"
20004- " movq 40(%0), %%mm5\n"
20005- " movntq %%mm5, 40(%1)\n"
20006- " movq 48(%0), %%mm6\n"
20007- " movntq %%mm6, 48(%1)\n"
20008- " movq 56(%0), %%mm7\n"
20009- " movntq %%mm7, 56(%1)\n"
20010+ "1: prefetch 320(%1)\n"
20011+ "2: movq (%1), %%mm0\n"
20012+ " movntq %%mm0, (%2)\n"
20013+ " movq 8(%1), %%mm1\n"
20014+ " movntq %%mm1, 8(%2)\n"
20015+ " movq 16(%1), %%mm2\n"
20016+ " movntq %%mm2, 16(%2)\n"
20017+ " movq 24(%1), %%mm3\n"
20018+ " movntq %%mm3, 24(%2)\n"
20019+ " movq 32(%1), %%mm4\n"
20020+ " movntq %%mm4, 32(%2)\n"
20021+ " movq 40(%1), %%mm5\n"
20022+ " movntq %%mm5, 40(%2)\n"
20023+ " movq 48(%1), %%mm6\n"
20024+ " movntq %%mm6, 48(%2)\n"
20025+ " movq 56(%1), %%mm7\n"
20026+ " movntq %%mm7, 56(%2)\n"
20027 ".section .fixup, \"ax\"\n"
20028- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20029+ "3:\n"
20030+
20031+#ifdef CONFIG_PAX_KERNEXEC
20032+ " movl %%cr0, %0\n"
20033+ " movl %0, %%eax\n"
20034+ " andl $0xFFFEFFFF, %%eax\n"
20035+ " movl %%eax, %%cr0\n"
20036+#endif
20037+
20038+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20039+
20040+#ifdef CONFIG_PAX_KERNEXEC
20041+ " movl %0, %%cr0\n"
20042+#endif
20043+
20044 " jmp 2b\n"
20045 ".previous\n"
20046- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20047+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20048
20049 from += 64;
20050 to += 64;
20051@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20052 static void fast_copy_page(void *to, void *from)
20053 {
20054 int i;
20055+ unsigned long cr0;
20056
20057 kernel_fpu_begin();
20058
20059 __asm__ __volatile__ (
20060- "1: prefetch (%0)\n"
20061- " prefetch 64(%0)\n"
20062- " prefetch 128(%0)\n"
20063- " prefetch 192(%0)\n"
20064- " prefetch 256(%0)\n"
20065+ "1: prefetch (%1)\n"
20066+ " prefetch 64(%1)\n"
20067+ " prefetch 128(%1)\n"
20068+ " prefetch 192(%1)\n"
20069+ " prefetch 256(%1)\n"
20070 "2: \n"
20071 ".section .fixup, \"ax\"\n"
20072- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20073+ "3: \n"
20074+
20075+#ifdef CONFIG_PAX_KERNEXEC
20076+ " movl %%cr0, %0\n"
20077+ " movl %0, %%eax\n"
20078+ " andl $0xFFFEFFFF, %%eax\n"
20079+ " movl %%eax, %%cr0\n"
20080+#endif
20081+
20082+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20083+
20084+#ifdef CONFIG_PAX_KERNEXEC
20085+ " movl %0, %%cr0\n"
20086+#endif
20087+
20088 " jmp 2b\n"
20089 ".previous\n"
20090- _ASM_EXTABLE(1b, 3b) : : "r" (from));
20091+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20092
20093 for (i = 0; i < 4096/64; i++) {
20094 __asm__ __volatile__ (
20095- "1: prefetch 320(%0)\n"
20096- "2: movq (%0), %%mm0\n"
20097- " movq 8(%0), %%mm1\n"
20098- " movq 16(%0), %%mm2\n"
20099- " movq 24(%0), %%mm3\n"
20100- " movq %%mm0, (%1)\n"
20101- " movq %%mm1, 8(%1)\n"
20102- " movq %%mm2, 16(%1)\n"
20103- " movq %%mm3, 24(%1)\n"
20104- " movq 32(%0), %%mm0\n"
20105- " movq 40(%0), %%mm1\n"
20106- " movq 48(%0), %%mm2\n"
20107- " movq 56(%0), %%mm3\n"
20108- " movq %%mm0, 32(%1)\n"
20109- " movq %%mm1, 40(%1)\n"
20110- " movq %%mm2, 48(%1)\n"
20111- " movq %%mm3, 56(%1)\n"
20112+ "1: prefetch 320(%1)\n"
20113+ "2: movq (%1), %%mm0\n"
20114+ " movq 8(%1), %%mm1\n"
20115+ " movq 16(%1), %%mm2\n"
20116+ " movq 24(%1), %%mm3\n"
20117+ " movq %%mm0, (%2)\n"
20118+ " movq %%mm1, 8(%2)\n"
20119+ " movq %%mm2, 16(%2)\n"
20120+ " movq %%mm3, 24(%2)\n"
20121+ " movq 32(%1), %%mm0\n"
20122+ " movq 40(%1), %%mm1\n"
20123+ " movq 48(%1), %%mm2\n"
20124+ " movq 56(%1), %%mm3\n"
20125+ " movq %%mm0, 32(%2)\n"
20126+ " movq %%mm1, 40(%2)\n"
20127+ " movq %%mm2, 48(%2)\n"
20128+ " movq %%mm3, 56(%2)\n"
20129 ".section .fixup, \"ax\"\n"
20130- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20131+ "3:\n"
20132+
20133+#ifdef CONFIG_PAX_KERNEXEC
20134+ " movl %%cr0, %0\n"
20135+ " movl %0, %%eax\n"
20136+ " andl $0xFFFEFFFF, %%eax\n"
20137+ " movl %%eax, %%cr0\n"
20138+#endif
20139+
20140+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20141+
20142+#ifdef CONFIG_PAX_KERNEXEC
20143+ " movl %0, %%cr0\n"
20144+#endif
20145+
20146 " jmp 2b\n"
20147 ".previous\n"
20148 _ASM_EXTABLE(1b, 3b)
20149- : : "r" (from), "r" (to) : "memory");
20150+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20151
20152 from += 64;
20153 to += 64;
20154diff -urNp linux-2.6.39.1/arch/x86/lib/putuser.S linux-2.6.39.1/arch/x86/lib/putuser.S
20155--- linux-2.6.39.1/arch/x86/lib/putuser.S 2011-05-19 00:06:34.000000000 -0400
20156+++ linux-2.6.39.1/arch/x86/lib/putuser.S 2011-05-22 19:36:30.000000000 -0400
20157@@ -15,7 +15,8 @@
20158 #include <asm/thread_info.h>
20159 #include <asm/errno.h>
20160 #include <asm/asm.h>
20161-
20162+#include <asm/segment.h>
20163+#include <asm/pgtable.h>
20164
20165 /*
20166 * __put_user_X
20167@@ -29,52 +30,119 @@
20168 * as they get called from within inline assembly.
20169 */
20170
20171-#define ENTER CFI_STARTPROC ; \
20172- GET_THREAD_INFO(%_ASM_BX)
20173+#define ENTER CFI_STARTPROC
20174 #define EXIT ret ; \
20175 CFI_ENDPROC
20176
20177+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20178+#define _DEST %_ASM_CX,%_ASM_BX
20179+#else
20180+#define _DEST %_ASM_CX
20181+#endif
20182+
20183+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20184+#define __copyuser_seg gs;
20185+#else
20186+#define __copyuser_seg
20187+#endif
20188+
20189 .text
20190 ENTRY(__put_user_1)
20191 ENTER
20192+
20193+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20194+ GET_THREAD_INFO(%_ASM_BX)
20195 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20196 jae bad_put_user
20197-1: movb %al,(%_ASM_CX)
20198+
20199+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20200+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20201+ cmp %_ASM_BX,%_ASM_CX
20202+ jb 1234f
20203+ xor %ebx,%ebx
20204+1234:
20205+#endif
20206+
20207+#endif
20208+
20209+1: __copyuser_seg movb %al,(_DEST)
20210 xor %eax,%eax
20211 EXIT
20212 ENDPROC(__put_user_1)
20213
20214 ENTRY(__put_user_2)
20215 ENTER
20216+
20217+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20218+ GET_THREAD_INFO(%_ASM_BX)
20219 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20220 sub $1,%_ASM_BX
20221 cmp %_ASM_BX,%_ASM_CX
20222 jae bad_put_user
20223-2: movw %ax,(%_ASM_CX)
20224+
20225+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20226+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20227+ cmp %_ASM_BX,%_ASM_CX
20228+ jb 1234f
20229+ xor %ebx,%ebx
20230+1234:
20231+#endif
20232+
20233+#endif
20234+
20235+2: __copyuser_seg movw %ax,(_DEST)
20236 xor %eax,%eax
20237 EXIT
20238 ENDPROC(__put_user_2)
20239
20240 ENTRY(__put_user_4)
20241 ENTER
20242+
20243+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20244+ GET_THREAD_INFO(%_ASM_BX)
20245 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20246 sub $3,%_ASM_BX
20247 cmp %_ASM_BX,%_ASM_CX
20248 jae bad_put_user
20249-3: movl %eax,(%_ASM_CX)
20250+
20251+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20252+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20253+ cmp %_ASM_BX,%_ASM_CX
20254+ jb 1234f
20255+ xor %ebx,%ebx
20256+1234:
20257+#endif
20258+
20259+#endif
20260+
20261+3: __copyuser_seg movl %eax,(_DEST)
20262 xor %eax,%eax
20263 EXIT
20264 ENDPROC(__put_user_4)
20265
20266 ENTRY(__put_user_8)
20267 ENTER
20268+
20269+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20270+ GET_THREAD_INFO(%_ASM_BX)
20271 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20272 sub $7,%_ASM_BX
20273 cmp %_ASM_BX,%_ASM_CX
20274 jae bad_put_user
20275-4: mov %_ASM_AX,(%_ASM_CX)
20276+
20277+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20278+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20279+ cmp %_ASM_BX,%_ASM_CX
20280+ jb 1234f
20281+ xor %ebx,%ebx
20282+1234:
20283+#endif
20284+
20285+#endif
20286+
20287+4: __copyuser_seg mov %_ASM_AX,(_DEST)
20288 #ifdef CONFIG_X86_32
20289-5: movl %edx,4(%_ASM_CX)
20290+5: __copyuser_seg movl %edx,4(_DEST)
20291 #endif
20292 xor %eax,%eax
20293 EXIT
20294diff -urNp linux-2.6.39.1/arch/x86/lib/usercopy_32.c linux-2.6.39.1/arch/x86/lib/usercopy_32.c
20295--- linux-2.6.39.1/arch/x86/lib/usercopy_32.c 2011-05-19 00:06:34.000000000 -0400
20296+++ linux-2.6.39.1/arch/x86/lib/usercopy_32.c 2011-05-22 19:36:30.000000000 -0400
20297@@ -43,7 +43,7 @@ do { \
20298 __asm__ __volatile__( \
20299 " testl %1,%1\n" \
20300 " jz 2f\n" \
20301- "0: lodsb\n" \
20302+ "0: "__copyuser_seg"lodsb\n" \
20303 " stosb\n" \
20304 " testb %%al,%%al\n" \
20305 " jz 1f\n" \
20306@@ -128,10 +128,12 @@ do { \
20307 int __d0; \
20308 might_fault(); \
20309 __asm__ __volatile__( \
20310+ __COPYUSER_SET_ES \
20311 "0: rep; stosl\n" \
20312 " movl %2,%0\n" \
20313 "1: rep; stosb\n" \
20314 "2:\n" \
20315+ __COPYUSER_RESTORE_ES \
20316 ".section .fixup,\"ax\"\n" \
20317 "3: lea 0(%2,%0,4),%0\n" \
20318 " jmp 2b\n" \
20319@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
20320 might_fault();
20321
20322 __asm__ __volatile__(
20323+ __COPYUSER_SET_ES
20324 " testl %0, %0\n"
20325 " jz 3f\n"
20326 " andl %0,%%ecx\n"
20327@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
20328 " subl %%ecx,%0\n"
20329 " addl %0,%%eax\n"
20330 "1:\n"
20331+ __COPYUSER_RESTORE_ES
20332 ".section .fixup,\"ax\"\n"
20333 "2: xorl %%eax,%%eax\n"
20334 " jmp 1b\n"
20335@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20336
20337 #ifdef CONFIG_X86_INTEL_USERCOPY
20338 static unsigned long
20339-__copy_user_intel(void __user *to, const void *from, unsigned long size)
20340+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20341 {
20342 int d0, d1;
20343 __asm__ __volatile__(
20344@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
20345 " .align 2,0x90\n"
20346 "3: movl 0(%4), %%eax\n"
20347 "4: movl 4(%4), %%edx\n"
20348- "5: movl %%eax, 0(%3)\n"
20349- "6: movl %%edx, 4(%3)\n"
20350+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20351+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20352 "7: movl 8(%4), %%eax\n"
20353 "8: movl 12(%4),%%edx\n"
20354- "9: movl %%eax, 8(%3)\n"
20355- "10: movl %%edx, 12(%3)\n"
20356+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20357+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20358 "11: movl 16(%4), %%eax\n"
20359 "12: movl 20(%4), %%edx\n"
20360- "13: movl %%eax, 16(%3)\n"
20361- "14: movl %%edx, 20(%3)\n"
20362+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20363+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20364 "15: movl 24(%4), %%eax\n"
20365 "16: movl 28(%4), %%edx\n"
20366- "17: movl %%eax, 24(%3)\n"
20367- "18: movl %%edx, 28(%3)\n"
20368+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20369+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20370 "19: movl 32(%4), %%eax\n"
20371 "20: movl 36(%4), %%edx\n"
20372- "21: movl %%eax, 32(%3)\n"
20373- "22: movl %%edx, 36(%3)\n"
20374+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20375+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20376 "23: movl 40(%4), %%eax\n"
20377 "24: movl 44(%4), %%edx\n"
20378- "25: movl %%eax, 40(%3)\n"
20379- "26: movl %%edx, 44(%3)\n"
20380+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20381+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20382 "27: movl 48(%4), %%eax\n"
20383 "28: movl 52(%4), %%edx\n"
20384- "29: movl %%eax, 48(%3)\n"
20385- "30: movl %%edx, 52(%3)\n"
20386+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20387+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20388 "31: movl 56(%4), %%eax\n"
20389 "32: movl 60(%4), %%edx\n"
20390- "33: movl %%eax, 56(%3)\n"
20391- "34: movl %%edx, 60(%3)\n"
20392+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20393+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20394 " addl $-64, %0\n"
20395 " addl $64, %4\n"
20396 " addl $64, %3\n"
20397@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
20398 " shrl $2, %0\n"
20399 " andl $3, %%eax\n"
20400 " cld\n"
20401+ __COPYUSER_SET_ES
20402 "99: rep; movsl\n"
20403 "36: movl %%eax, %0\n"
20404 "37: rep; movsb\n"
20405 "100:\n"
20406+ __COPYUSER_RESTORE_ES
20407+ ".section .fixup,\"ax\"\n"
20408+ "101: lea 0(%%eax,%0,4),%0\n"
20409+ " jmp 100b\n"
20410+ ".previous\n"
20411+ ".section __ex_table,\"a\"\n"
20412+ " .align 4\n"
20413+ " .long 1b,100b\n"
20414+ " .long 2b,100b\n"
20415+ " .long 3b,100b\n"
20416+ " .long 4b,100b\n"
20417+ " .long 5b,100b\n"
20418+ " .long 6b,100b\n"
20419+ " .long 7b,100b\n"
20420+ " .long 8b,100b\n"
20421+ " .long 9b,100b\n"
20422+ " .long 10b,100b\n"
20423+ " .long 11b,100b\n"
20424+ " .long 12b,100b\n"
20425+ " .long 13b,100b\n"
20426+ " .long 14b,100b\n"
20427+ " .long 15b,100b\n"
20428+ " .long 16b,100b\n"
20429+ " .long 17b,100b\n"
20430+ " .long 18b,100b\n"
20431+ " .long 19b,100b\n"
20432+ " .long 20b,100b\n"
20433+ " .long 21b,100b\n"
20434+ " .long 22b,100b\n"
20435+ " .long 23b,100b\n"
20436+ " .long 24b,100b\n"
20437+ " .long 25b,100b\n"
20438+ " .long 26b,100b\n"
20439+ " .long 27b,100b\n"
20440+ " .long 28b,100b\n"
20441+ " .long 29b,100b\n"
20442+ " .long 30b,100b\n"
20443+ " .long 31b,100b\n"
20444+ " .long 32b,100b\n"
20445+ " .long 33b,100b\n"
20446+ " .long 34b,100b\n"
20447+ " .long 35b,100b\n"
20448+ " .long 36b,100b\n"
20449+ " .long 37b,100b\n"
20450+ " .long 99b,101b\n"
20451+ ".previous"
20452+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
20453+ : "1"(to), "2"(from), "0"(size)
20454+ : "eax", "edx", "memory");
20455+ return size;
20456+}
20457+
20458+static unsigned long
20459+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20460+{
20461+ int d0, d1;
20462+ __asm__ __volatile__(
20463+ " .align 2,0x90\n"
20464+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20465+ " cmpl $67, %0\n"
20466+ " jbe 3f\n"
20467+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20468+ " .align 2,0x90\n"
20469+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20470+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20471+ "5: movl %%eax, 0(%3)\n"
20472+ "6: movl %%edx, 4(%3)\n"
20473+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20474+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20475+ "9: movl %%eax, 8(%3)\n"
20476+ "10: movl %%edx, 12(%3)\n"
20477+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20478+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20479+ "13: movl %%eax, 16(%3)\n"
20480+ "14: movl %%edx, 20(%3)\n"
20481+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20482+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20483+ "17: movl %%eax, 24(%3)\n"
20484+ "18: movl %%edx, 28(%3)\n"
20485+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20486+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20487+ "21: movl %%eax, 32(%3)\n"
20488+ "22: movl %%edx, 36(%3)\n"
20489+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20490+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20491+ "25: movl %%eax, 40(%3)\n"
20492+ "26: movl %%edx, 44(%3)\n"
20493+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20494+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20495+ "29: movl %%eax, 48(%3)\n"
20496+ "30: movl %%edx, 52(%3)\n"
20497+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20498+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20499+ "33: movl %%eax, 56(%3)\n"
20500+ "34: movl %%edx, 60(%3)\n"
20501+ " addl $-64, %0\n"
20502+ " addl $64, %4\n"
20503+ " addl $64, %3\n"
20504+ " cmpl $63, %0\n"
20505+ " ja 1b\n"
20506+ "35: movl %0, %%eax\n"
20507+ " shrl $2, %0\n"
20508+ " andl $3, %%eax\n"
20509+ " cld\n"
20510+ "99: rep; "__copyuser_seg" movsl\n"
20511+ "36: movl %%eax, %0\n"
20512+ "37: rep; "__copyuser_seg" movsb\n"
20513+ "100:\n"
20514 ".section .fixup,\"ax\"\n"
20515 "101: lea 0(%%eax,%0,4),%0\n"
20516 " jmp 100b\n"
20517@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20518 int d0, d1;
20519 __asm__ __volatile__(
20520 " .align 2,0x90\n"
20521- "0: movl 32(%4), %%eax\n"
20522+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20523 " cmpl $67, %0\n"
20524 " jbe 2f\n"
20525- "1: movl 64(%4), %%eax\n"
20526+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20527 " .align 2,0x90\n"
20528- "2: movl 0(%4), %%eax\n"
20529- "21: movl 4(%4), %%edx\n"
20530+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20531+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20532 " movl %%eax, 0(%3)\n"
20533 " movl %%edx, 4(%3)\n"
20534- "3: movl 8(%4), %%eax\n"
20535- "31: movl 12(%4),%%edx\n"
20536+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20537+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20538 " movl %%eax, 8(%3)\n"
20539 " movl %%edx, 12(%3)\n"
20540- "4: movl 16(%4), %%eax\n"
20541- "41: movl 20(%4), %%edx\n"
20542+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20543+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20544 " movl %%eax, 16(%3)\n"
20545 " movl %%edx, 20(%3)\n"
20546- "10: movl 24(%4), %%eax\n"
20547- "51: movl 28(%4), %%edx\n"
20548+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20549+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20550 " movl %%eax, 24(%3)\n"
20551 " movl %%edx, 28(%3)\n"
20552- "11: movl 32(%4), %%eax\n"
20553- "61: movl 36(%4), %%edx\n"
20554+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20555+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20556 " movl %%eax, 32(%3)\n"
20557 " movl %%edx, 36(%3)\n"
20558- "12: movl 40(%4), %%eax\n"
20559- "71: movl 44(%4), %%edx\n"
20560+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20561+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20562 " movl %%eax, 40(%3)\n"
20563 " movl %%edx, 44(%3)\n"
20564- "13: movl 48(%4), %%eax\n"
20565- "81: movl 52(%4), %%edx\n"
20566+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20567+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20568 " movl %%eax, 48(%3)\n"
20569 " movl %%edx, 52(%3)\n"
20570- "14: movl 56(%4), %%eax\n"
20571- "91: movl 60(%4), %%edx\n"
20572+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20573+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20574 " movl %%eax, 56(%3)\n"
20575 " movl %%edx, 60(%3)\n"
20576 " addl $-64, %0\n"
20577@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20578 " shrl $2, %0\n"
20579 " andl $3, %%eax\n"
20580 " cld\n"
20581- "6: rep; movsl\n"
20582+ "6: rep; "__copyuser_seg" movsl\n"
20583 " movl %%eax,%0\n"
20584- "7: rep; movsb\n"
20585+ "7: rep; "__copyuser_seg" movsb\n"
20586 "8:\n"
20587 ".section .fixup,\"ax\"\n"
20588 "9: lea 0(%%eax,%0,4),%0\n"
20589@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20590
20591 __asm__ __volatile__(
20592 " .align 2,0x90\n"
20593- "0: movl 32(%4), %%eax\n"
20594+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20595 " cmpl $67, %0\n"
20596 " jbe 2f\n"
20597- "1: movl 64(%4), %%eax\n"
20598+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20599 " .align 2,0x90\n"
20600- "2: movl 0(%4), %%eax\n"
20601- "21: movl 4(%4), %%edx\n"
20602+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20603+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20604 " movnti %%eax, 0(%3)\n"
20605 " movnti %%edx, 4(%3)\n"
20606- "3: movl 8(%4), %%eax\n"
20607- "31: movl 12(%4),%%edx\n"
20608+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20609+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20610 " movnti %%eax, 8(%3)\n"
20611 " movnti %%edx, 12(%3)\n"
20612- "4: movl 16(%4), %%eax\n"
20613- "41: movl 20(%4), %%edx\n"
20614+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20615+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20616 " movnti %%eax, 16(%3)\n"
20617 " movnti %%edx, 20(%3)\n"
20618- "10: movl 24(%4), %%eax\n"
20619- "51: movl 28(%4), %%edx\n"
20620+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20621+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20622 " movnti %%eax, 24(%3)\n"
20623 " movnti %%edx, 28(%3)\n"
20624- "11: movl 32(%4), %%eax\n"
20625- "61: movl 36(%4), %%edx\n"
20626+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20627+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20628 " movnti %%eax, 32(%3)\n"
20629 " movnti %%edx, 36(%3)\n"
20630- "12: movl 40(%4), %%eax\n"
20631- "71: movl 44(%4), %%edx\n"
20632+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20633+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20634 " movnti %%eax, 40(%3)\n"
20635 " movnti %%edx, 44(%3)\n"
20636- "13: movl 48(%4), %%eax\n"
20637- "81: movl 52(%4), %%edx\n"
20638+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20639+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20640 " movnti %%eax, 48(%3)\n"
20641 " movnti %%edx, 52(%3)\n"
20642- "14: movl 56(%4), %%eax\n"
20643- "91: movl 60(%4), %%edx\n"
20644+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20645+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20646 " movnti %%eax, 56(%3)\n"
20647 " movnti %%edx, 60(%3)\n"
20648 " addl $-64, %0\n"
20649@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20650 " shrl $2, %0\n"
20651 " andl $3, %%eax\n"
20652 " cld\n"
20653- "6: rep; movsl\n"
20654+ "6: rep; "__copyuser_seg" movsl\n"
20655 " movl %%eax,%0\n"
20656- "7: rep; movsb\n"
20657+ "7: rep; "__copyuser_seg" movsb\n"
20658 "8:\n"
20659 ".section .fixup,\"ax\"\n"
20660 "9: lea 0(%%eax,%0,4),%0\n"
20661@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20662
20663 __asm__ __volatile__(
20664 " .align 2,0x90\n"
20665- "0: movl 32(%4), %%eax\n"
20666+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20667 " cmpl $67, %0\n"
20668 " jbe 2f\n"
20669- "1: movl 64(%4), %%eax\n"
20670+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20671 " .align 2,0x90\n"
20672- "2: movl 0(%4), %%eax\n"
20673- "21: movl 4(%4), %%edx\n"
20674+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20675+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20676 " movnti %%eax, 0(%3)\n"
20677 " movnti %%edx, 4(%3)\n"
20678- "3: movl 8(%4), %%eax\n"
20679- "31: movl 12(%4),%%edx\n"
20680+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20681+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20682 " movnti %%eax, 8(%3)\n"
20683 " movnti %%edx, 12(%3)\n"
20684- "4: movl 16(%4), %%eax\n"
20685- "41: movl 20(%4), %%edx\n"
20686+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20687+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20688 " movnti %%eax, 16(%3)\n"
20689 " movnti %%edx, 20(%3)\n"
20690- "10: movl 24(%4), %%eax\n"
20691- "51: movl 28(%4), %%edx\n"
20692+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20693+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20694 " movnti %%eax, 24(%3)\n"
20695 " movnti %%edx, 28(%3)\n"
20696- "11: movl 32(%4), %%eax\n"
20697- "61: movl 36(%4), %%edx\n"
20698+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20699+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20700 " movnti %%eax, 32(%3)\n"
20701 " movnti %%edx, 36(%3)\n"
20702- "12: movl 40(%4), %%eax\n"
20703- "71: movl 44(%4), %%edx\n"
20704+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20705+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20706 " movnti %%eax, 40(%3)\n"
20707 " movnti %%edx, 44(%3)\n"
20708- "13: movl 48(%4), %%eax\n"
20709- "81: movl 52(%4), %%edx\n"
20710+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20711+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20712 " movnti %%eax, 48(%3)\n"
20713 " movnti %%edx, 52(%3)\n"
20714- "14: movl 56(%4), %%eax\n"
20715- "91: movl 60(%4), %%edx\n"
20716+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20717+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20718 " movnti %%eax, 56(%3)\n"
20719 " movnti %%edx, 60(%3)\n"
20720 " addl $-64, %0\n"
20721@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20722 " shrl $2, %0\n"
20723 " andl $3, %%eax\n"
20724 " cld\n"
20725- "6: rep; movsl\n"
20726+ "6: rep; "__copyuser_seg" movsl\n"
20727 " movl %%eax,%0\n"
20728- "7: rep; movsb\n"
20729+ "7: rep; "__copyuser_seg" movsb\n"
20730 "8:\n"
20731 ".section .fixup,\"ax\"\n"
20732 "9: lea 0(%%eax,%0,4),%0\n"
20733@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20734 */
20735 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20736 unsigned long size);
20737-unsigned long __copy_user_intel(void __user *to, const void *from,
20738+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20739+ unsigned long size);
20740+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20741 unsigned long size);
20742 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20743 const void __user *from, unsigned long size);
20744 #endif /* CONFIG_X86_INTEL_USERCOPY */
20745
20746 /* Generic arbitrary sized copy. */
20747-#define __copy_user(to, from, size) \
20748+#define __copy_user(to, from, size, prefix, set, restore) \
20749 do { \
20750 int __d0, __d1, __d2; \
20751 __asm__ __volatile__( \
20752+ set \
20753 " cmp $7,%0\n" \
20754 " jbe 1f\n" \
20755 " movl %1,%0\n" \
20756 " negl %0\n" \
20757 " andl $7,%0\n" \
20758 " subl %0,%3\n" \
20759- "4: rep; movsb\n" \
20760+ "4: rep; "prefix"movsb\n" \
20761 " movl %3,%0\n" \
20762 " shrl $2,%0\n" \
20763 " andl $3,%3\n" \
20764 " .align 2,0x90\n" \
20765- "0: rep; movsl\n" \
20766+ "0: rep; "prefix"movsl\n" \
20767 " movl %3,%0\n" \
20768- "1: rep; movsb\n" \
20769+ "1: rep; "prefix"movsb\n" \
20770 "2:\n" \
20771+ restore \
20772 ".section .fixup,\"ax\"\n" \
20773 "5: addl %3,%0\n" \
20774 " jmp 2b\n" \
20775@@ -682,14 +799,14 @@ do { \
20776 " negl %0\n" \
20777 " andl $7,%0\n" \
20778 " subl %0,%3\n" \
20779- "4: rep; movsb\n" \
20780+ "4: rep; "__copyuser_seg"movsb\n" \
20781 " movl %3,%0\n" \
20782 " shrl $2,%0\n" \
20783 " andl $3,%3\n" \
20784 " .align 2,0x90\n" \
20785- "0: rep; movsl\n" \
20786+ "0: rep; "__copyuser_seg"movsl\n" \
20787 " movl %3,%0\n" \
20788- "1: rep; movsb\n" \
20789+ "1: rep; "__copyuser_seg"movsb\n" \
20790 "2:\n" \
20791 ".section .fixup,\"ax\"\n" \
20792 "5: addl %3,%0\n" \
20793@@ -775,9 +892,9 @@ survive:
20794 }
20795 #endif
20796 if (movsl_is_ok(to, from, n))
20797- __copy_user(to, from, n);
20798+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20799 else
20800- n = __copy_user_intel(to, from, n);
20801+ n = __generic_copy_to_user_intel(to, from, n);
20802 return n;
20803 }
20804 EXPORT_SYMBOL(__copy_to_user_ll);
20805@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20806 unsigned long n)
20807 {
20808 if (movsl_is_ok(to, from, n))
20809- __copy_user(to, from, n);
20810+ __copy_user(to, from, n, __copyuser_seg, "", "");
20811 else
20812- n = __copy_user_intel((void __user *)to,
20813- (const void *)from, n);
20814+ n = __generic_copy_from_user_intel(to, from, n);
20815 return n;
20816 }
20817 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20818@@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocach
20819 if (n > 64 && cpu_has_xmm2)
20820 n = __copy_user_intel_nocache(to, from, n);
20821 else
20822- __copy_user(to, from, n);
20823+ __copy_user(to, from, n, __copyuser_seg, "", "");
20824 #else
20825- __copy_user(to, from, n);
20826+ __copy_user(to, from, n, __copyuser_seg, "", "");
20827 #endif
20828 return n;
20829 }
20830 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20831
20832-/**
20833- * copy_to_user: - Copy a block of data into user space.
20834- * @to: Destination address, in user space.
20835- * @from: Source address, in kernel space.
20836- * @n: Number of bytes to copy.
20837- *
20838- * Context: User context only. This function may sleep.
20839- *
20840- * Copy data from kernel space to user space.
20841- *
20842- * Returns number of bytes that could not be copied.
20843- * On success, this will be zero.
20844- */
20845-unsigned long
20846-copy_to_user(void __user *to, const void *from, unsigned long n)
20847+void copy_from_user_overflow(void)
20848 {
20849- if (access_ok(VERIFY_WRITE, to, n))
20850- n = __copy_to_user(to, from, n);
20851- return n;
20852+ WARN(1, "Buffer overflow detected!\n");
20853 }
20854-EXPORT_SYMBOL(copy_to_user);
20855+EXPORT_SYMBOL(copy_from_user_overflow);
20856
20857-/**
20858- * copy_from_user: - Copy a block of data from user space.
20859- * @to: Destination address, in kernel space.
20860- * @from: Source address, in user space.
20861- * @n: Number of bytes to copy.
20862- *
20863- * Context: User context only. This function may sleep.
20864- *
20865- * Copy data from user space to kernel space.
20866- *
20867- * Returns number of bytes that could not be copied.
20868- * On success, this will be zero.
20869- *
20870- * If some data could not be copied, this function will pad the copied
20871- * data to the requested size using zero bytes.
20872- */
20873-unsigned long
20874-_copy_from_user(void *to, const void __user *from, unsigned long n)
20875+void copy_to_user_overflow(void)
20876 {
20877- if (access_ok(VERIFY_READ, from, n))
20878- n = __copy_from_user(to, from, n);
20879- else
20880- memset(to, 0, n);
20881- return n;
20882+ WARN(1, "Buffer overflow detected!\n");
20883 }
20884-EXPORT_SYMBOL(_copy_from_user);
20885+EXPORT_SYMBOL(copy_to_user_overflow);
20886
20887-void copy_from_user_overflow(void)
20888+#ifdef CONFIG_PAX_MEMORY_UDEREF
20889+void __set_fs(mm_segment_t x)
20890 {
20891- WARN(1, "Buffer overflow detected!\n");
20892+ switch (x.seg) {
20893+ case 0:
20894+ loadsegment(gs, 0);
20895+ break;
20896+ case TASK_SIZE_MAX:
20897+ loadsegment(gs, __USER_DS);
20898+ break;
20899+ case -1UL:
20900+ loadsegment(gs, __KERNEL_DS);
20901+ break;
20902+ default:
20903+ BUG();
20904+ }
20905+ return;
20906 }
20907-EXPORT_SYMBOL(copy_from_user_overflow);
20908+EXPORT_SYMBOL(__set_fs);
20909+
20910+void set_fs(mm_segment_t x)
20911+{
20912+ current_thread_info()->addr_limit = x;
20913+ __set_fs(x);
20914+}
20915+EXPORT_SYMBOL(set_fs);
20916+#endif
20917diff -urNp linux-2.6.39.1/arch/x86/lib/usercopy_64.c linux-2.6.39.1/arch/x86/lib/usercopy_64.c
20918--- linux-2.6.39.1/arch/x86/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
20919+++ linux-2.6.39.1/arch/x86/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
20920@@ -42,6 +42,12 @@ long
20921 __strncpy_from_user(char *dst, const char __user *src, long count)
20922 {
20923 long res;
20924+
20925+#ifdef CONFIG_PAX_MEMORY_UDEREF
20926+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20927+ src += PAX_USER_SHADOW_BASE;
20928+#endif
20929+
20930 __do_strncpy_from_user(dst, src, count, res);
20931 return res;
20932 }
20933@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20934 {
20935 long __d0;
20936 might_fault();
20937+
20938+#ifdef CONFIG_PAX_MEMORY_UDEREF
20939+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20940+ addr += PAX_USER_SHADOW_BASE;
20941+#endif
20942+
20943 /* no memory constraint because it doesn't change any memory gcc knows
20944 about */
20945 asm volatile(
20946@@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20947
20948 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20949 {
20950- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20951+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20952+
20953+#ifdef CONFIG_PAX_MEMORY_UDEREF
20954+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20955+ to += PAX_USER_SHADOW_BASE;
20956+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20957+ from += PAX_USER_SHADOW_BASE;
20958+#endif
20959+
20960 return copy_user_generic((__force void *)to, (__force void *)from, len);
20961- }
20962- return len;
20963+ }
20964+ return len;
20965 }
20966 EXPORT_SYMBOL(copy_in_user);
20967
20968diff -urNp linux-2.6.39.1/arch/x86/Makefile linux-2.6.39.1/arch/x86/Makefile
20969--- linux-2.6.39.1/arch/x86/Makefile 2011-05-19 00:06:34.000000000 -0400
20970+++ linux-2.6.39.1/arch/x86/Makefile 2011-05-22 19:36:30.000000000 -0400
20971@@ -195,3 +195,12 @@ define archhelp
20972 echo ' FDARGS="..." arguments for the booted kernel'
20973 echo ' FDINITRD=file initrd for the booted kernel'
20974 endef
20975+
20976+define OLD_LD
20977+
20978+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20979+*** Please upgrade your binutils to 2.18 or newer
20980+endef
20981+
20982+archprepare:
20983+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20984diff -urNp linux-2.6.39.1/arch/x86/mm/extable.c linux-2.6.39.1/arch/x86/mm/extable.c
20985--- linux-2.6.39.1/arch/x86/mm/extable.c 2011-05-19 00:06:34.000000000 -0400
20986+++ linux-2.6.39.1/arch/x86/mm/extable.c 2011-05-22 19:36:30.000000000 -0400
20987@@ -1,14 +1,71 @@
20988 #include <linux/module.h>
20989 #include <linux/spinlock.h>
20990+#include <linux/sort.h>
20991 #include <asm/uaccess.h>
20992+#include <asm/pgtable.h>
20993
20994+/*
20995+ * The exception table needs to be sorted so that the binary
20996+ * search that we use to find entries in it works properly.
20997+ * This is used both for the kernel exception table and for
20998+ * the exception tables of modules that get loaded.
20999+ */
21000+static int cmp_ex(const void *a, const void *b)
21001+{
21002+ const struct exception_table_entry *x = a, *y = b;
21003+
21004+ /* avoid overflow */
21005+ if (x->insn > y->insn)
21006+ return 1;
21007+ if (x->insn < y->insn)
21008+ return -1;
21009+ return 0;
21010+}
21011+
21012+static void swap_ex(void *a, void *b, int size)
21013+{
21014+ struct exception_table_entry t, *x = a, *y = b;
21015+
21016+ t = *x;
21017+
21018+ pax_open_kernel();
21019+ *x = *y;
21020+ *y = t;
21021+ pax_close_kernel();
21022+}
21023+
21024+void sort_extable(struct exception_table_entry *start,
21025+ struct exception_table_entry *finish)
21026+{
21027+ sort(start, finish - start, sizeof(struct exception_table_entry),
21028+ cmp_ex, swap_ex);
21029+}
21030+
21031+#ifdef CONFIG_MODULES
21032+/*
21033+ * If the exception table is sorted, any referring to the module init
21034+ * will be at the beginning or the end.
21035+ */
21036+void trim_init_extable(struct module *m)
21037+{
21038+ /*trim the beginning*/
21039+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
21040+ m->extable++;
21041+ m->num_exentries--;
21042+ }
21043+ /*trim the end*/
21044+ while (m->num_exentries &&
21045+ within_module_init(m->extable[m->num_exentries-1].insn, m))
21046+ m->num_exentries--;
21047+}
21048+#endif /* CONFIG_MODULES */
21049
21050 int fixup_exception(struct pt_regs *regs)
21051 {
21052 const struct exception_table_entry *fixup;
21053
21054 #ifdef CONFIG_PNPBIOS
21055- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21056+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21057 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21058 extern u32 pnp_bios_is_utter_crap;
21059 pnp_bios_is_utter_crap = 1;
21060diff -urNp linux-2.6.39.1/arch/x86/mm/fault.c linux-2.6.39.1/arch/x86/mm/fault.c
21061--- linux-2.6.39.1/arch/x86/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
21062+++ linux-2.6.39.1/arch/x86/mm/fault.c 2011-06-06 17:34:04.000000000 -0400
21063@@ -12,10 +12,18 @@
21064 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
21065 #include <linux/perf_event.h> /* perf_sw_event */
21066 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21067+#include <linux/unistd.h>
21068+#include <linux/compiler.h>
21069
21070 #include <asm/traps.h> /* dotraplinkage, ... */
21071 #include <asm/pgalloc.h> /* pgd_*(), ... */
21072 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21073+#include <asm/vsyscall.h>
21074+#include <asm/tlbflush.h>
21075+
21076+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21077+#include <asm/stacktrace.h>
21078+#endif
21079
21080 /*
21081 * Page fault error code bits:
21082@@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
21083 int ret = 0;
21084
21085 /* kprobe_running() needs smp_processor_id() */
21086- if (kprobes_built_in() && !user_mode_vm(regs)) {
21087+ if (kprobes_built_in() && !user_mode(regs)) {
21088 preempt_disable();
21089 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21090 ret = 1;
21091@@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
21092 return !instr_lo || (instr_lo>>1) == 1;
21093 case 0x00:
21094 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21095- if (probe_kernel_address(instr, opcode))
21096+ if (user_mode(regs)) {
21097+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
21098+ return 0;
21099+ } else if (probe_kernel_address(instr, opcode))
21100 return 0;
21101
21102 *prefetch = (instr_lo == 0xF) &&
21103@@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
21104 while (instr < max_instr) {
21105 unsigned char opcode;
21106
21107- if (probe_kernel_address(instr, opcode))
21108+ if (user_mode(regs)) {
21109+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
21110+ break;
21111+ } else if (probe_kernel_address(instr, opcode))
21112 break;
21113
21114 instr++;
21115@@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
21116 force_sig_info(si_signo, &info, tsk);
21117 }
21118
21119+#ifdef CONFIG_PAX_EMUTRAMP
21120+static int pax_handle_fetch_fault(struct pt_regs *regs);
21121+#endif
21122+
21123+#ifdef CONFIG_PAX_PAGEEXEC
21124+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21125+{
21126+ pgd_t *pgd;
21127+ pud_t *pud;
21128+ pmd_t *pmd;
21129+
21130+ pgd = pgd_offset(mm, address);
21131+ if (!pgd_present(*pgd))
21132+ return NULL;
21133+ pud = pud_offset(pgd, address);
21134+ if (!pud_present(*pud))
21135+ return NULL;
21136+ pmd = pmd_offset(pud, address);
21137+ if (!pmd_present(*pmd))
21138+ return NULL;
21139+ return pmd;
21140+}
21141+#endif
21142+
21143 DEFINE_SPINLOCK(pgd_lock);
21144 LIST_HEAD(pgd_list);
21145
21146@@ -229,10 +267,22 @@ void vmalloc_sync_all(void)
21147 for (address = VMALLOC_START & PMD_MASK;
21148 address >= TASK_SIZE && address < FIXADDR_TOP;
21149 address += PMD_SIZE) {
21150+
21151+#ifdef CONFIG_PAX_PER_CPU_PGD
21152+ unsigned long cpu;
21153+#else
21154 struct page *page;
21155+#endif
21156
21157 spin_lock(&pgd_lock);
21158+
21159+#ifdef CONFIG_PAX_PER_CPU_PGD
21160+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21161+ pgd_t *pgd = get_cpu_pgd(cpu);
21162+ pmd_t *ret;
21163+#else
21164 list_for_each_entry(page, &pgd_list, lru) {
21165+ pgd_t *pgd = page_address(page);
21166 spinlock_t *pgt_lock;
21167 pmd_t *ret;
21168
21169@@ -240,8 +290,13 @@ void vmalloc_sync_all(void)
21170 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21171
21172 spin_lock(pgt_lock);
21173- ret = vmalloc_sync_one(page_address(page), address);
21174+#endif
21175+
21176+ ret = vmalloc_sync_one(pgd, address);
21177+
21178+#ifndef CONFIG_PAX_PER_CPU_PGD
21179 spin_unlock(pgt_lock);
21180+#endif
21181
21182 if (!ret)
21183 break;
21184@@ -275,6 +330,11 @@ static noinline __kprobes int vmalloc_fa
21185 * an interrupt in the middle of a task switch..
21186 */
21187 pgd_paddr = read_cr3();
21188+
21189+#ifdef CONFIG_PAX_PER_CPU_PGD
21190+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21191+#endif
21192+
21193 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21194 if (!pmd_k)
21195 return -1;
21196@@ -370,7 +430,14 @@ static noinline __kprobes int vmalloc_fa
21197 * happen within a race in page table update. In the later
21198 * case just flush:
21199 */
21200+
21201+#ifdef CONFIG_PAX_PER_CPU_PGD
21202+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21203+ pgd = pgd_offset_cpu(smp_processor_id(), address);
21204+#else
21205 pgd = pgd_offset(current->active_mm, address);
21206+#endif
21207+
21208 pgd_ref = pgd_offset_k(address);
21209 if (pgd_none(*pgd_ref))
21210 return -1;
21211@@ -532,7 +599,7 @@ static int is_errata93(struct pt_regs *r
21212 static int is_errata100(struct pt_regs *regs, unsigned long address)
21213 {
21214 #ifdef CONFIG_X86_64
21215- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21216+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21217 return 1;
21218 #endif
21219 return 0;
21220@@ -559,7 +626,7 @@ static int is_f00f_bug(struct pt_regs *r
21221 }
21222
21223 static const char nx_warning[] = KERN_CRIT
21224-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21225+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21226
21227 static void
21228 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21229@@ -568,15 +635,26 @@ show_fault_oops(struct pt_regs *regs, un
21230 if (!oops_may_print())
21231 return;
21232
21233- if (error_code & PF_INSTR) {
21234+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21235 unsigned int level;
21236
21237 pte_t *pte = lookup_address(address, &level);
21238
21239 if (pte && pte_present(*pte) && !pte_exec(*pte))
21240- printk(nx_warning, current_uid());
21241+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21242 }
21243
21244+#ifdef CONFIG_PAX_KERNEXEC
21245+ if (init_mm.start_code <= address && address < init_mm.end_code) {
21246+ if (current->signal->curr_ip)
21247+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21248+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21249+ else
21250+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21251+ current->comm, task_pid_nr(current), current_uid(), current_euid());
21252+ }
21253+#endif
21254+
21255 printk(KERN_ALERT "BUG: unable to handle kernel ");
21256 if (address < PAGE_SIZE)
21257 printk(KERN_CONT "NULL pointer dereference");
21258@@ -701,6 +779,68 @@ __bad_area_nosemaphore(struct pt_regs *r
21259 unsigned long address, int si_code)
21260 {
21261 struct task_struct *tsk = current;
21262+ struct mm_struct *mm = tsk->mm;
21263+
21264+#ifdef CONFIG_X86_64
21265+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
21266+ if (regs->ip == (unsigned long)vgettimeofday) {
21267+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
21268+ return;
21269+ } else if (regs->ip == (unsigned long)vtime) {
21270+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
21271+ return;
21272+ } else if (regs->ip == (unsigned long)vgetcpu) {
21273+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
21274+ return;
21275+ }
21276+ }
21277+#endif
21278+
21279+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21280+ if (mm && (error_code & PF_USER)) {
21281+ unsigned long ip = regs->ip;
21282+
21283+ if (v8086_mode(regs))
21284+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21285+
21286+ /*
21287+ * It's possible to have interrupts off here:
21288+ */
21289+ local_irq_enable();
21290+
21291+#ifdef CONFIG_PAX_PAGEEXEC
21292+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
21293+ (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
21294+
21295+#ifdef CONFIG_PAX_EMUTRAMP
21296+ switch (pax_handle_fetch_fault(regs)) {
21297+ case 2:
21298+ return;
21299+ }
21300+#endif
21301+
21302+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21303+ do_group_exit(SIGKILL);
21304+ }
21305+#endif
21306+
21307+#ifdef CONFIG_PAX_SEGMEXEC
21308+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
21309+
21310+#ifdef CONFIG_PAX_EMUTRAMP
21311+ switch (pax_handle_fetch_fault(regs)) {
21312+ case 2:
21313+ return;
21314+ }
21315+#endif
21316+
21317+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21318+ do_group_exit(SIGKILL);
21319+ }
21320+#endif
21321+
21322+ }
21323+#endif
21324
21325 /* User mode accesses just cause a SIGSEGV */
21326 if (error_code & PF_USER) {
21327@@ -855,6 +995,99 @@ static int spurious_fault_check(unsigned
21328 return 1;
21329 }
21330
21331+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21332+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21333+{
21334+ pte_t *pte;
21335+ pmd_t *pmd;
21336+ spinlock_t *ptl;
21337+ unsigned char pte_mask;
21338+
21339+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21340+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
21341+ return 0;
21342+
21343+ /* PaX: it's our fault, let's handle it if we can */
21344+
21345+ /* PaX: take a look at read faults before acquiring any locks */
21346+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21347+ /* instruction fetch attempt from a protected page in user mode */
21348+ up_read(&mm->mmap_sem);
21349+
21350+#ifdef CONFIG_PAX_EMUTRAMP
21351+ switch (pax_handle_fetch_fault(regs)) {
21352+ case 2:
21353+ return 1;
21354+ }
21355+#endif
21356+
21357+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21358+ do_group_exit(SIGKILL);
21359+ }
21360+
21361+ pmd = pax_get_pmd(mm, address);
21362+ if (unlikely(!pmd))
21363+ return 0;
21364+
21365+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21366+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21367+ pte_unmap_unlock(pte, ptl);
21368+ return 0;
21369+ }
21370+
21371+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21372+ /* write attempt to a protected page in user mode */
21373+ pte_unmap_unlock(pte, ptl);
21374+ return 0;
21375+ }
21376+
21377+#ifdef CONFIG_SMP
21378+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21379+#else
21380+ if (likely(address > get_limit(regs->cs)))
21381+#endif
21382+ {
21383+ set_pte(pte, pte_mkread(*pte));
21384+ __flush_tlb_one(address);
21385+ pte_unmap_unlock(pte, ptl);
21386+ up_read(&mm->mmap_sem);
21387+ return 1;
21388+ }
21389+
21390+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21391+
21392+ /*
21393+ * PaX: fill DTLB with user rights and retry
21394+ */
21395+ __asm__ __volatile__ (
21396+ "orb %2,(%1)\n"
21397+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21398+/*
21399+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21400+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21401+ * page fault when examined during a TLB load attempt. this is true not only
21402+ * for PTEs holding a non-present entry but also present entries that will
21403+ * raise a page fault (such as those set up by PaX, or the copy-on-write
21404+ * mechanism). in effect it means that we do *not* need to flush the TLBs
21405+ * for our target pages since their PTEs are simply not in the TLBs at all.
21406+
21407+ * the best thing in omitting it is that we gain around 15-20% speed in the
21408+ * fast path of the page fault handler and can get rid of tracing since we
21409+ * can no longer flush unintended entries.
21410+ */
21411+ "invlpg (%0)\n"
21412+#endif
21413+ __copyuser_seg"testb $0,(%0)\n"
21414+ "xorb %3,(%1)\n"
21415+ :
21416+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21417+ : "memory", "cc");
21418+ pte_unmap_unlock(pte, ptl);
21419+ up_read(&mm->mmap_sem);
21420+ return 1;
21421+}
21422+#endif
21423+
21424 /*
21425 * Handle a spurious fault caused by a stale TLB entry.
21426 *
21427@@ -927,6 +1160,9 @@ int show_unhandled_signals = 1;
21428 static inline int
21429 access_error(unsigned long error_code, struct vm_area_struct *vma)
21430 {
21431+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21432+ return 1;
21433+
21434 if (error_code & PF_WRITE) {
21435 /* write, present and write, not present: */
21436 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21437@@ -960,19 +1196,33 @@ do_page_fault(struct pt_regs *regs, unsi
21438 {
21439 struct vm_area_struct *vma;
21440 struct task_struct *tsk;
21441- unsigned long address;
21442 struct mm_struct *mm;
21443 int fault;
21444 int write = error_code & PF_WRITE;
21445 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
21446 (write ? FAULT_FLAG_WRITE : 0);
21447
21448+ /* Get the faulting address: */
21449+ unsigned long address = read_cr2();
21450+
21451+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21452+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21453+ if (!search_exception_tables(regs->ip)) {
21454+ bad_area_nosemaphore(regs, error_code, address);
21455+ return;
21456+ }
21457+ if (address < PAX_USER_SHADOW_BASE) {
21458+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21459+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21460+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21461+ } else
21462+ address -= PAX_USER_SHADOW_BASE;
21463+ }
21464+#endif
21465+
21466 tsk = current;
21467 mm = tsk->mm;
21468
21469- /* Get the faulting address: */
21470- address = read_cr2();
21471-
21472 /*
21473 * Detect and handle instructions that would cause a page fault for
21474 * both a tracked kernel page and a userspace page.
21475@@ -1032,7 +1282,7 @@ do_page_fault(struct pt_regs *regs, unsi
21476 * User-mode registers count as a user access even for any
21477 * potential system fault or CPU buglet:
21478 */
21479- if (user_mode_vm(regs)) {
21480+ if (user_mode(regs)) {
21481 local_irq_enable();
21482 error_code |= PF_USER;
21483 } else {
21484@@ -1087,6 +1337,11 @@ retry:
21485 might_sleep();
21486 }
21487
21488+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21489+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21490+ return;
21491+#endif
21492+
21493 vma = find_vma(mm, address);
21494 if (unlikely(!vma)) {
21495 bad_area(regs, error_code, address);
21496@@ -1098,18 +1353,24 @@ retry:
21497 bad_area(regs, error_code, address);
21498 return;
21499 }
21500- if (error_code & PF_USER) {
21501- /*
21502- * Accessing the stack below %sp is always a bug.
21503- * The large cushion allows instructions like enter
21504- * and pusha to work. ("enter $65535, $31" pushes
21505- * 32 pointers and then decrements %sp by 65535.)
21506- */
21507- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21508- bad_area(regs, error_code, address);
21509- return;
21510- }
21511+ /*
21512+ * Accessing the stack below %sp is always a bug.
21513+ * The large cushion allows instructions like enter
21514+ * and pusha to work. ("enter $65535, $31" pushes
21515+ * 32 pointers and then decrements %sp by 65535.)
21516+ */
21517+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21518+ bad_area(regs, error_code, address);
21519+ return;
21520 }
21521+
21522+#ifdef CONFIG_PAX_SEGMEXEC
21523+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21524+ bad_area(regs, error_code, address);
21525+ return;
21526+ }
21527+#endif
21528+
21529 if (unlikely(expand_stack(vma, address))) {
21530 bad_area(regs, error_code, address);
21531 return;
21532@@ -1164,3 +1425,199 @@ good_area:
21533
21534 up_read(&mm->mmap_sem);
21535 }
21536+
21537+#ifdef CONFIG_PAX_EMUTRAMP
21538+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21539+{
21540+ int err;
21541+
21542+ do { /* PaX: gcc trampoline emulation #1 */
21543+ unsigned char mov1, mov2;
21544+ unsigned short jmp;
21545+ unsigned int addr1, addr2;
21546+
21547+#ifdef CONFIG_X86_64
21548+ if ((regs->ip + 11) >> 32)
21549+ break;
21550+#endif
21551+
21552+ err = get_user(mov1, (unsigned char __user *)regs->ip);
21553+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21554+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21555+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21556+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21557+
21558+ if (err)
21559+ break;
21560+
21561+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21562+ regs->cx = addr1;
21563+ regs->ax = addr2;
21564+ regs->ip = addr2;
21565+ return 2;
21566+ }
21567+ } while (0);
21568+
21569+ do { /* PaX: gcc trampoline emulation #2 */
21570+ unsigned char mov, jmp;
21571+ unsigned int addr1, addr2;
21572+
21573+#ifdef CONFIG_X86_64
21574+ if ((regs->ip + 9) >> 32)
21575+ break;
21576+#endif
21577+
21578+ err = get_user(mov, (unsigned char __user *)regs->ip);
21579+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21580+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21581+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21582+
21583+ if (err)
21584+ break;
21585+
21586+ if (mov == 0xB9 && jmp == 0xE9) {
21587+ regs->cx = addr1;
21588+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21589+ return 2;
21590+ }
21591+ } while (0);
21592+
21593+ return 1; /* PaX in action */
21594+}
21595+
21596+#ifdef CONFIG_X86_64
21597+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21598+{
21599+ int err;
21600+
21601+ do { /* PaX: gcc trampoline emulation #1 */
21602+ unsigned short mov1, mov2, jmp1;
21603+ unsigned char jmp2;
21604+ unsigned int addr1;
21605+ unsigned long addr2;
21606+
21607+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21608+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21609+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21610+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21611+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21612+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21613+
21614+ if (err)
21615+ break;
21616+
21617+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21618+ regs->r11 = addr1;
21619+ regs->r10 = addr2;
21620+ regs->ip = addr1;
21621+ return 2;
21622+ }
21623+ } while (0);
21624+
21625+ do { /* PaX: gcc trampoline emulation #2 */
21626+ unsigned short mov1, mov2, jmp1;
21627+ unsigned char jmp2;
21628+ unsigned long addr1, addr2;
21629+
21630+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21631+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21632+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21633+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21634+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21635+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21636+
21637+ if (err)
21638+ break;
21639+
21640+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21641+ regs->r11 = addr1;
21642+ regs->r10 = addr2;
21643+ regs->ip = addr1;
21644+ return 2;
21645+ }
21646+ } while (0);
21647+
21648+ return 1; /* PaX in action */
21649+}
21650+#endif
21651+
21652+/*
21653+ * PaX: decide what to do with offenders (regs->ip = fault address)
21654+ *
21655+ * returns 1 when task should be killed
21656+ * 2 when gcc trampoline was detected
21657+ */
21658+static int pax_handle_fetch_fault(struct pt_regs *regs)
21659+{
21660+ if (v8086_mode(regs))
21661+ return 1;
21662+
21663+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21664+ return 1;
21665+
21666+#ifdef CONFIG_X86_32
21667+ return pax_handle_fetch_fault_32(regs);
21668+#else
21669+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21670+ return pax_handle_fetch_fault_32(regs);
21671+ else
21672+ return pax_handle_fetch_fault_64(regs);
21673+#endif
21674+}
21675+#endif
21676+
21677+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21678+void pax_report_insns(void *pc, void *sp)
21679+{
21680+ long i;
21681+
21682+ printk(KERN_ERR "PAX: bytes at PC: ");
21683+ for (i = 0; i < 20; i++) {
21684+ unsigned char c;
21685+ if (get_user(c, (__force unsigned char __user *)pc+i))
21686+ printk(KERN_CONT "?? ");
21687+ else
21688+ printk(KERN_CONT "%02x ", c);
21689+ }
21690+ printk("\n");
21691+
21692+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21693+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
21694+ unsigned long c;
21695+ if (get_user(c, (__force unsigned long __user *)sp+i))
21696+#ifdef CONFIG_X86_32
21697+ printk(KERN_CONT "???????? ");
21698+#else
21699+ printk(KERN_CONT "???????????????? ");
21700+#endif
21701+ else
21702+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21703+ }
21704+ printk("\n");
21705+}
21706+#endif
21707+
21708+/**
21709+ * probe_kernel_write(): safely attempt to write to a location
21710+ * @dst: address to write to
21711+ * @src: pointer to the data that shall be written
21712+ * @size: size of the data chunk
21713+ *
21714+ * Safely write to address @dst from the buffer at @src. If a kernel fault
21715+ * happens, handle that and return -EFAULT.
21716+ */
21717+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21718+{
21719+ long ret;
21720+ mm_segment_t old_fs = get_fs();
21721+
21722+ set_fs(KERNEL_DS);
21723+ pagefault_disable();
21724+ pax_open_kernel();
21725+ ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21726+ pax_close_kernel();
21727+ pagefault_enable();
21728+ set_fs(old_fs);
21729+
21730+ return ret ? -EFAULT : 0;
21731+}
21732diff -urNp linux-2.6.39.1/arch/x86/mm/gup.c linux-2.6.39.1/arch/x86/mm/gup.c
21733--- linux-2.6.39.1/arch/x86/mm/gup.c 2011-05-19 00:06:34.000000000 -0400
21734+++ linux-2.6.39.1/arch/x86/mm/gup.c 2011-05-22 19:36:30.000000000 -0400
21735@@ -263,7 +263,7 @@ int __get_user_pages_fast(unsigned long
21736 addr = start;
21737 len = (unsigned long) nr_pages << PAGE_SHIFT;
21738 end = start + len;
21739- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21740+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21741 (void __user *)start, len)))
21742 return 0;
21743
21744diff -urNp linux-2.6.39.1/arch/x86/mm/highmem_32.c linux-2.6.39.1/arch/x86/mm/highmem_32.c
21745--- linux-2.6.39.1/arch/x86/mm/highmem_32.c 2011-05-19 00:06:34.000000000 -0400
21746+++ linux-2.6.39.1/arch/x86/mm/highmem_32.c 2011-05-22 19:36:30.000000000 -0400
21747@@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
21748 idx = type + KM_TYPE_NR*smp_processor_id();
21749 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21750 BUG_ON(!pte_none(*(kmap_pte-idx)));
21751+
21752+ pax_open_kernel();
21753 set_pte(kmap_pte-idx, mk_pte(page, prot));
21754+ pax_close_kernel();
21755
21756 return (void *)vaddr;
21757 }
21758diff -urNp linux-2.6.39.1/arch/x86/mm/hugetlbpage.c linux-2.6.39.1/arch/x86/mm/hugetlbpage.c
21759--- linux-2.6.39.1/arch/x86/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
21760+++ linux-2.6.39.1/arch/x86/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
21761@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
21762 struct hstate *h = hstate_file(file);
21763 struct mm_struct *mm = current->mm;
21764 struct vm_area_struct *vma;
21765- unsigned long start_addr;
21766+ unsigned long start_addr, pax_task_size = TASK_SIZE;
21767+
21768+#ifdef CONFIG_PAX_SEGMEXEC
21769+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21770+ pax_task_size = SEGMEXEC_TASK_SIZE;
21771+#endif
21772+
21773+ pax_task_size -= PAGE_SIZE;
21774
21775 if (len > mm->cached_hole_size) {
21776- start_addr = mm->free_area_cache;
21777+ start_addr = mm->free_area_cache;
21778 } else {
21779- start_addr = TASK_UNMAPPED_BASE;
21780- mm->cached_hole_size = 0;
21781+ start_addr = mm->mmap_base;
21782+ mm->cached_hole_size = 0;
21783 }
21784
21785 full_search:
21786@@ -280,26 +287,27 @@ full_search:
21787
21788 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21789 /* At this point: (!vma || addr < vma->vm_end). */
21790- if (TASK_SIZE - len < addr) {
21791+ if (pax_task_size - len < addr) {
21792 /*
21793 * Start a new search - just in case we missed
21794 * some holes.
21795 */
21796- if (start_addr != TASK_UNMAPPED_BASE) {
21797- start_addr = TASK_UNMAPPED_BASE;
21798+ if (start_addr != mm->mmap_base) {
21799+ start_addr = mm->mmap_base;
21800 mm->cached_hole_size = 0;
21801 goto full_search;
21802 }
21803 return -ENOMEM;
21804 }
21805- if (!vma || addr + len <= vma->vm_start) {
21806- mm->free_area_cache = addr + len;
21807- return addr;
21808- }
21809+ if (check_heap_stack_gap(vma, addr, len))
21810+ break;
21811 if (addr + mm->cached_hole_size < vma->vm_start)
21812 mm->cached_hole_size = vma->vm_start - addr;
21813 addr = ALIGN(vma->vm_end, huge_page_size(h));
21814 }
21815+
21816+ mm->free_area_cache = addr + len;
21817+ return addr;
21818 }
21819
21820 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21821@@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
21822 {
21823 struct hstate *h = hstate_file(file);
21824 struct mm_struct *mm = current->mm;
21825- struct vm_area_struct *vma, *prev_vma;
21826- unsigned long base = mm->mmap_base, addr = addr0;
21827+ struct vm_area_struct *vma;
21828+ unsigned long base = mm->mmap_base, addr;
21829 unsigned long largest_hole = mm->cached_hole_size;
21830- int first_time = 1;
21831
21832 /* don't allow allocations above current base */
21833 if (mm->free_area_cache > base)
21834@@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmappe
21835 largest_hole = 0;
21836 mm->free_area_cache = base;
21837 }
21838-try_again:
21839+
21840 /* make sure it can fit in the remaining address space */
21841 if (mm->free_area_cache < len)
21842 goto fail;
21843
21844 /* either no address requested or can't fit in requested address hole */
21845- addr = (mm->free_area_cache - len) & huge_page_mask(h);
21846+ addr = (mm->free_area_cache - len);
21847 do {
21848+ addr &= huge_page_mask(h);
21849+ vma = find_vma(mm, addr);
21850 /*
21851 * Lookup failure means no vma is above this address,
21852 * i.e. return with success:
21853- */
21854- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21855- return addr;
21856-
21857- /*
21858 * new region fits between prev_vma->vm_end and
21859 * vma->vm_start, use it:
21860 */
21861- if (addr + len <= vma->vm_start &&
21862- (!prev_vma || (addr >= prev_vma->vm_end))) {
21863+ if (check_heap_stack_gap(vma, addr, len)) {
21864 /* remember the address as a hint for next time */
21865- mm->cached_hole_size = largest_hole;
21866- return (mm->free_area_cache = addr);
21867- } else {
21868- /* pull free_area_cache down to the first hole */
21869- if (mm->free_area_cache == vma->vm_end) {
21870- mm->free_area_cache = vma->vm_start;
21871- mm->cached_hole_size = largest_hole;
21872- }
21873+ mm->cached_hole_size = largest_hole;
21874+ return (mm->free_area_cache = addr);
21875+ }
21876+ /* pull free_area_cache down to the first hole */
21877+ if (mm->free_area_cache == vma->vm_end) {
21878+ mm->free_area_cache = vma->vm_start;
21879+ mm->cached_hole_size = largest_hole;
21880 }
21881
21882 /* remember the largest hole we saw so far */
21883 if (addr + largest_hole < vma->vm_start)
21884- largest_hole = vma->vm_start - addr;
21885+ largest_hole = vma->vm_start - addr;
21886
21887 /* try just below the current vma->vm_start */
21888- addr = (vma->vm_start - len) & huge_page_mask(h);
21889- } while (len <= vma->vm_start);
21890+ addr = skip_heap_stack_gap(vma, len);
21891+ } while (!IS_ERR_VALUE(addr));
21892
21893 fail:
21894 /*
21895- * if hint left us with no space for the requested
21896- * mapping then try again:
21897- */
21898- if (first_time) {
21899- mm->free_area_cache = base;
21900- largest_hole = 0;
21901- first_time = 0;
21902- goto try_again;
21903- }
21904- /*
21905 * A failed mmap() very likely causes application failure,
21906 * so fall back to the bottom-up function here. This scenario
21907 * can happen with large stack limits and large mmap()
21908 * allocations.
21909 */
21910- mm->free_area_cache = TASK_UNMAPPED_BASE;
21911+
21912+#ifdef CONFIG_PAX_SEGMEXEC
21913+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21914+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21915+ else
21916+#endif
21917+
21918+ mm->mmap_base = TASK_UNMAPPED_BASE;
21919+
21920+#ifdef CONFIG_PAX_RANDMMAP
21921+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21922+ mm->mmap_base += mm->delta_mmap;
21923+#endif
21924+
21925+ mm->free_area_cache = mm->mmap_base;
21926 mm->cached_hole_size = ~0UL;
21927 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21928 len, pgoff, flags);
21929@@ -386,6 +392,7 @@ fail:
21930 /*
21931 * Restore the topdown base:
21932 */
21933+ mm->mmap_base = base;
21934 mm->free_area_cache = base;
21935 mm->cached_hole_size = ~0UL;
21936
21937@@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *f
21938 struct hstate *h = hstate_file(file);
21939 struct mm_struct *mm = current->mm;
21940 struct vm_area_struct *vma;
21941+ unsigned long pax_task_size = TASK_SIZE;
21942
21943 if (len & ~huge_page_mask(h))
21944 return -EINVAL;
21945- if (len > TASK_SIZE)
21946+
21947+#ifdef CONFIG_PAX_SEGMEXEC
21948+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21949+ pax_task_size = SEGMEXEC_TASK_SIZE;
21950+#endif
21951+
21952+ pax_task_size -= PAGE_SIZE;
21953+
21954+ if (len > pax_task_size)
21955 return -ENOMEM;
21956
21957 if (flags & MAP_FIXED) {
21958@@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *f
21959 if (addr) {
21960 addr = ALIGN(addr, huge_page_size(h));
21961 vma = find_vma(mm, addr);
21962- if (TASK_SIZE - len >= addr &&
21963- (!vma || addr + len <= vma->vm_start))
21964+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21965 return addr;
21966 }
21967 if (mm->get_unmapped_area == arch_get_unmapped_area)
21968diff -urNp linux-2.6.39.1/arch/x86/mm/init_32.c linux-2.6.39.1/arch/x86/mm/init_32.c
21969--- linux-2.6.39.1/arch/x86/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
21970+++ linux-2.6.39.1/arch/x86/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
21971@@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
21972 }
21973
21974 /*
21975- * Creates a middle page table and puts a pointer to it in the
21976- * given global directory entry. This only returns the gd entry
21977- * in non-PAE compilation mode, since the middle layer is folded.
21978- */
21979-static pmd_t * __init one_md_table_init(pgd_t *pgd)
21980-{
21981- pud_t *pud;
21982- pmd_t *pmd_table;
21983-
21984-#ifdef CONFIG_X86_PAE
21985- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21986- if (after_bootmem)
21987- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21988- else
21989- pmd_table = (pmd_t *)alloc_low_page();
21990- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21991- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21992- pud = pud_offset(pgd, 0);
21993- BUG_ON(pmd_table != pmd_offset(pud, 0));
21994-
21995- return pmd_table;
21996- }
21997-#endif
21998- pud = pud_offset(pgd, 0);
21999- pmd_table = pmd_offset(pud, 0);
22000-
22001- return pmd_table;
22002-}
22003-
22004-/*
22005 * Create a page table and place a pointer to it in a middle page
22006 * directory entry:
22007 */
22008@@ -123,13 +93,28 @@ static pte_t * __init one_page_table_ini
22009 page_table = (pte_t *)alloc_low_page();
22010
22011 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22012+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22013+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22014+#else
22015 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22016+#endif
22017 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22018 }
22019
22020 return pte_offset_kernel(pmd, 0);
22021 }
22022
22023+static pmd_t * __init one_md_table_init(pgd_t *pgd)
22024+{
22025+ pud_t *pud;
22026+ pmd_t *pmd_table;
22027+
22028+ pud = pud_offset(pgd, 0);
22029+ pmd_table = pmd_offset(pud, 0);
22030+
22031+ return pmd_table;
22032+}
22033+
22034 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22035 {
22036 int pgd_idx = pgd_index(vaddr);
22037@@ -203,6 +188,7 @@ page_table_range_init(unsigned long star
22038 int pgd_idx, pmd_idx;
22039 unsigned long vaddr;
22040 pgd_t *pgd;
22041+ pud_t *pud;
22042 pmd_t *pmd;
22043 pte_t *pte = NULL;
22044
22045@@ -212,8 +198,13 @@ page_table_range_init(unsigned long star
22046 pgd = pgd_base + pgd_idx;
22047
22048 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22049- pmd = one_md_table_init(pgd);
22050- pmd = pmd + pmd_index(vaddr);
22051+ pud = pud_offset(pgd, vaddr);
22052+ pmd = pmd_offset(pud, vaddr);
22053+
22054+#ifdef CONFIG_X86_PAE
22055+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22056+#endif
22057+
22058 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22059 pmd++, pmd_idx++) {
22060 pte = page_table_kmap_check(one_page_table_init(pmd),
22061@@ -225,11 +216,20 @@ page_table_range_init(unsigned long star
22062 }
22063 }
22064
22065-static inline int is_kernel_text(unsigned long addr)
22066+static inline int is_kernel_text(unsigned long start, unsigned long end)
22067 {
22068- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22069- return 1;
22070- return 0;
22071+ if ((start > ktla_ktva((unsigned long)_etext) ||
22072+ end <= ktla_ktva((unsigned long)_stext)) &&
22073+ (start > ktla_ktva((unsigned long)_einittext) ||
22074+ end <= ktla_ktva((unsigned long)_sinittext)) &&
22075+
22076+#ifdef CONFIG_ACPI_SLEEP
22077+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22078+#endif
22079+
22080+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22081+ return 0;
22082+ return 1;
22083 }
22084
22085 /*
22086@@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned lo
22087 unsigned long last_map_addr = end;
22088 unsigned long start_pfn, end_pfn;
22089 pgd_t *pgd_base = swapper_pg_dir;
22090- int pgd_idx, pmd_idx, pte_ofs;
22091+ unsigned int pgd_idx, pmd_idx, pte_ofs;
22092 unsigned long pfn;
22093 pgd_t *pgd;
22094+ pud_t *pud;
22095 pmd_t *pmd;
22096 pte_t *pte;
22097 unsigned pages_2m, pages_4k;
22098@@ -281,8 +282,13 @@ repeat:
22099 pfn = start_pfn;
22100 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22101 pgd = pgd_base + pgd_idx;
22102- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22103- pmd = one_md_table_init(pgd);
22104+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22105+ pud = pud_offset(pgd, 0);
22106+ pmd = pmd_offset(pud, 0);
22107+
22108+#ifdef CONFIG_X86_PAE
22109+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22110+#endif
22111
22112 if (pfn >= end_pfn)
22113 continue;
22114@@ -294,14 +300,13 @@ repeat:
22115 #endif
22116 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22117 pmd++, pmd_idx++) {
22118- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22119+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22120
22121 /*
22122 * Map with big pages if possible, otherwise
22123 * create normal page tables:
22124 */
22125 if (use_pse) {
22126- unsigned int addr2;
22127 pgprot_t prot = PAGE_KERNEL_LARGE;
22128 /*
22129 * first pass will use the same initial
22130@@ -311,11 +316,7 @@ repeat:
22131 __pgprot(PTE_IDENT_ATTR |
22132 _PAGE_PSE);
22133
22134- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22135- PAGE_OFFSET + PAGE_SIZE-1;
22136-
22137- if (is_kernel_text(addr) ||
22138- is_kernel_text(addr2))
22139+ if (is_kernel_text(address, address + PMD_SIZE))
22140 prot = PAGE_KERNEL_LARGE_EXEC;
22141
22142 pages_2m++;
22143@@ -332,7 +333,7 @@ repeat:
22144 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22145 pte += pte_ofs;
22146 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22147- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22148+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22149 pgprot_t prot = PAGE_KERNEL;
22150 /*
22151 * first pass will use the same initial
22152@@ -340,7 +341,7 @@ repeat:
22153 */
22154 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22155
22156- if (is_kernel_text(addr))
22157+ if (is_kernel_text(address, address + PAGE_SIZE))
22158 prot = PAGE_KERNEL_EXEC;
22159
22160 pages_4k++;
22161@@ -472,7 +473,7 @@ void __init native_pagetable_setup_start
22162
22163 pud = pud_offset(pgd, va);
22164 pmd = pmd_offset(pud, va);
22165- if (!pmd_present(*pmd))
22166+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
22167 break;
22168
22169 pte = pte_offset_kernel(pmd, va);
22170@@ -524,12 +525,10 @@ void __init early_ioremap_page_table_ran
22171
22172 static void __init pagetable_init(void)
22173 {
22174- pgd_t *pgd_base = swapper_pg_dir;
22175-
22176- permanent_kmaps_init(pgd_base);
22177+ permanent_kmaps_init(swapper_pg_dir);
22178 }
22179
22180-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22181+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22182 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22183
22184 /* user-defined highmem size */
22185@@ -754,6 +753,12 @@ void __init mem_init(void)
22186
22187 pci_iommu_alloc();
22188
22189+#ifdef CONFIG_PAX_PER_CPU_PGD
22190+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22191+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22192+ KERNEL_PGD_PTRS);
22193+#endif
22194+
22195 #ifdef CONFIG_FLATMEM
22196 BUG_ON(!mem_map);
22197 #endif
22198@@ -771,7 +776,7 @@ void __init mem_init(void)
22199 set_highmem_pages_init();
22200
22201 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22202- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22203+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22204 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22205
22206 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22207@@ -812,10 +817,10 @@ void __init mem_init(void)
22208 ((unsigned long)&__init_end -
22209 (unsigned long)&__init_begin) >> 10,
22210
22211- (unsigned long)&_etext, (unsigned long)&_edata,
22212- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22213+ (unsigned long)&_sdata, (unsigned long)&_edata,
22214+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22215
22216- (unsigned long)&_text, (unsigned long)&_etext,
22217+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22218 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22219
22220 /*
22221@@ -893,6 +898,7 @@ void set_kernel_text_rw(void)
22222 if (!kernel_set_to_readonly)
22223 return;
22224
22225+ start = ktla_ktva(start);
22226 pr_debug("Set kernel text: %lx - %lx for read write\n",
22227 start, start+size);
22228
22229@@ -907,6 +913,7 @@ void set_kernel_text_ro(void)
22230 if (!kernel_set_to_readonly)
22231 return;
22232
22233+ start = ktla_ktva(start);
22234 pr_debug("Set kernel text: %lx - %lx for read only\n",
22235 start, start+size);
22236
22237@@ -935,6 +942,7 @@ void mark_rodata_ro(void)
22238 unsigned long start = PFN_ALIGN(_text);
22239 unsigned long size = PFN_ALIGN(_etext) - start;
22240
22241+ start = ktla_ktva(start);
22242 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22243 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22244 size >> 10);
22245diff -urNp linux-2.6.39.1/arch/x86/mm/init_64.c linux-2.6.39.1/arch/x86/mm/init_64.c
22246--- linux-2.6.39.1/arch/x86/mm/init_64.c 2011-05-19 00:06:34.000000000 -0400
22247+++ linux-2.6.39.1/arch/x86/mm/init_64.c 2011-05-22 19:36:30.000000000 -0400
22248@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpa
22249 * around without checking the pgd every time.
22250 */
22251
22252-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22253+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22254 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22255
22256 int force_personality32;
22257@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long star
22258
22259 for (address = start; address <= end; address += PGDIR_SIZE) {
22260 const pgd_t *pgd_ref = pgd_offset_k(address);
22261+
22262+#ifdef CONFIG_PAX_PER_CPU_PGD
22263+ unsigned long cpu;
22264+#else
22265 struct page *page;
22266+#endif
22267
22268 if (pgd_none(*pgd_ref))
22269 continue;
22270
22271 spin_lock(&pgd_lock);
22272+
22273+#ifdef CONFIG_PAX_PER_CPU_PGD
22274+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22275+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
22276+#else
22277 list_for_each_entry(page, &pgd_list, lru) {
22278 pgd_t *pgd;
22279 spinlock_t *pgt_lock;
22280@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long star
22281 /* the pgt_lock only for Xen */
22282 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22283 spin_lock(pgt_lock);
22284+#endif
22285
22286 if (pgd_none(*pgd))
22287 set_pgd(pgd, *pgd_ref);
22288@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long star
22289 BUG_ON(pgd_page_vaddr(*pgd)
22290 != pgd_page_vaddr(*pgd_ref));
22291
22292+#ifndef CONFIG_PAX_PER_CPU_PGD
22293 spin_unlock(pgt_lock);
22294+#endif
22295+
22296 }
22297 spin_unlock(&pgd_lock);
22298 }
22299@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
22300 pmd = fill_pmd(pud, vaddr);
22301 pte = fill_pte(pmd, vaddr);
22302
22303+ pax_open_kernel();
22304 set_pte(pte, new_pte);
22305+ pax_close_kernel();
22306
22307 /*
22308 * It's enough to flush this one mapping.
22309@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(
22310 pgd = pgd_offset_k((unsigned long)__va(phys));
22311 if (pgd_none(*pgd)) {
22312 pud = (pud_t *) spp_getpage();
22313- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22314- _PAGE_USER));
22315+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22316 }
22317 pud = pud_offset(pgd, (unsigned long)__va(phys));
22318 if (pud_none(*pud)) {
22319 pmd = (pmd_t *) spp_getpage();
22320- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22321- _PAGE_USER));
22322+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22323 }
22324 pmd = pmd_offset(pud, phys);
22325 BUG_ON(!pmd_none(*pmd));
22326@@ -698,6 +712,12 @@ void __init mem_init(void)
22327
22328 pci_iommu_alloc();
22329
22330+#ifdef CONFIG_PAX_PER_CPU_PGD
22331+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22332+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22333+ KERNEL_PGD_PTRS);
22334+#endif
22335+
22336 /* clear_bss() already clear the empty_zero_page */
22337
22338 reservedpages = 0;
22339@@ -858,8 +878,8 @@ int kern_addr_valid(unsigned long addr)
22340 static struct vm_area_struct gate_vma = {
22341 .vm_start = VSYSCALL_START,
22342 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22343- .vm_page_prot = PAGE_READONLY_EXEC,
22344- .vm_flags = VM_READ | VM_EXEC
22345+ .vm_page_prot = PAGE_READONLY,
22346+ .vm_flags = VM_READ
22347 };
22348
22349 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22350@@ -893,7 +913,7 @@ int in_gate_area_no_mm(unsigned long add
22351
22352 const char *arch_vma_name(struct vm_area_struct *vma)
22353 {
22354- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22355+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22356 return "[vdso]";
22357 if (vma == &gate_vma)
22358 return "[vsyscall]";
22359diff -urNp linux-2.6.39.1/arch/x86/mm/init.c linux-2.6.39.1/arch/x86/mm/init.c
22360--- linux-2.6.39.1/arch/x86/mm/init.c 2011-05-19 00:06:34.000000000 -0400
22361+++ linux-2.6.39.1/arch/x86/mm/init.c 2011-06-07 19:41:11.000000000 -0400
22362@@ -33,7 +33,7 @@ int direct_gbpages
22363 static void __init find_early_table_space(unsigned long end, int use_pse,
22364 int use_gbpages)
22365 {
22366- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22367+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22368 phys_addr_t base;
22369
22370 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22371@@ -315,12 +315,34 @@ unsigned long __init_refok init_memory_m
22372 */
22373 int devmem_is_allowed(unsigned long pagenr)
22374 {
22375- if (pagenr <= 256)
22376+#ifdef CONFIG_GRKERNSEC_KMEM
22377+ /* allow BDA */
22378+ if (!pagenr)
22379+ return 1;
22380+ /* allow EBDA */
22381+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22382+ return 1;
22383+#else
22384+ if (!pagenr)
22385+ return 1;
22386+#ifdef CONFIG_VM86
22387+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22388+ return 1;
22389+#endif
22390+#endif
22391+
22392+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22393 return 1;
22394+#ifdef CONFIG_GRKERNSEC_KMEM
22395+ /* throw out everything else below 1MB */
22396+ if (pagenr <= 256)
22397+ return 0;
22398+#endif
22399 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22400 return 0;
22401 if (!page_is_ram(pagenr))
22402 return 1;
22403+
22404 return 0;
22405 }
22406
22407@@ -375,6 +397,86 @@ void free_init_pages(char *what, unsigne
22408
22409 void free_initmem(void)
22410 {
22411+
22412+#ifdef CONFIG_PAX_KERNEXEC
22413+#ifdef CONFIG_X86_32
22414+ /* PaX: limit KERNEL_CS to actual size */
22415+ unsigned long addr, limit;
22416+ struct desc_struct d;
22417+ int cpu;
22418+
22419+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22420+ limit = (limit - 1UL) >> PAGE_SHIFT;
22421+
22422+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22423+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
22424+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22425+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22426+ }
22427+
22428+ /* PaX: make KERNEL_CS read-only */
22429+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22430+ if (!paravirt_enabled())
22431+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22432+/*
22433+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22434+ pgd = pgd_offset_k(addr);
22435+ pud = pud_offset(pgd, addr);
22436+ pmd = pmd_offset(pud, addr);
22437+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22438+ }
22439+*/
22440+#ifdef CONFIG_X86_PAE
22441+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22442+/*
22443+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22444+ pgd = pgd_offset_k(addr);
22445+ pud = pud_offset(pgd, addr);
22446+ pmd = pmd_offset(pud, addr);
22447+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22448+ }
22449+*/
22450+#endif
22451+
22452+#ifdef CONFIG_MODULES
22453+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22454+#endif
22455+
22456+#else
22457+ pgd_t *pgd;
22458+ pud_t *pud;
22459+ pmd_t *pmd;
22460+ unsigned long addr, end;
22461+
22462+ /* PaX: make kernel code/rodata read-only, rest non-executable */
22463+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22464+ pgd = pgd_offset_k(addr);
22465+ pud = pud_offset(pgd, addr);
22466+ pmd = pmd_offset(pud, addr);
22467+ if (!pmd_present(*pmd))
22468+ continue;
22469+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22470+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22471+ else
22472+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22473+ }
22474+
22475+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22476+ end = addr + KERNEL_IMAGE_SIZE;
22477+ for (; addr < end; addr += PMD_SIZE) {
22478+ pgd = pgd_offset_k(addr);
22479+ pud = pud_offset(pgd, addr);
22480+ pmd = pmd_offset(pud, addr);
22481+ if (!pmd_present(*pmd))
22482+ continue;
22483+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22484+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22485+ }
22486+#endif
22487+
22488+ flush_tlb_all();
22489+#endif
22490+
22491 free_init_pages("unused kernel memory",
22492 (unsigned long)(&__init_begin),
22493 (unsigned long)(&__init_end));
22494diff -urNp linux-2.6.39.1/arch/x86/mm/iomap_32.c linux-2.6.39.1/arch/x86/mm/iomap_32.c
22495--- linux-2.6.39.1/arch/x86/mm/iomap_32.c 2011-05-19 00:06:34.000000000 -0400
22496+++ linux-2.6.39.1/arch/x86/mm/iomap_32.c 2011-05-22 19:36:30.000000000 -0400
22497@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22498 type = kmap_atomic_idx_push();
22499 idx = type + KM_TYPE_NR * smp_processor_id();
22500 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22501+
22502+ pax_open_kernel();
22503 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22504+ pax_close_kernel();
22505+
22506 arch_flush_lazy_mmu_mode();
22507
22508 return (void *)vaddr;
22509diff -urNp linux-2.6.39.1/arch/x86/mm/ioremap.c linux-2.6.39.1/arch/x86/mm/ioremap.c
22510--- linux-2.6.39.1/arch/x86/mm/ioremap.c 2011-05-19 00:06:34.000000000 -0400
22511+++ linux-2.6.39.1/arch/x86/mm/ioremap.c 2011-05-22 19:36:30.000000000 -0400
22512@@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
22513 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22514 int is_ram = page_is_ram(pfn);
22515
22516- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22517+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22518 return NULL;
22519 WARN_ON_ONCE(is_ram);
22520 }
22521@@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
22522 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22523
22524 static __initdata int after_paging_init;
22525-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22526+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22527
22528 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22529 {
22530@@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22531 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22532
22533 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22534- memset(bm_pte, 0, sizeof(bm_pte));
22535- pmd_populate_kernel(&init_mm, pmd, bm_pte);
22536+ pmd_populate_user(&init_mm, pmd, bm_pte);
22537
22538 /*
22539 * The boot-ioremap range spans multiple pmds, for which
22540diff -urNp linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c
22541--- linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-19 00:06:34.000000000 -0400
22542+++ linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-22 19:36:30.000000000 -0400
22543@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22544 * memory (e.g. tracked pages)? For now, we need this to avoid
22545 * invoking kmemcheck for PnP BIOS calls.
22546 */
22547- if (regs->flags & X86_VM_MASK)
22548+ if (v8086_mode(regs))
22549 return false;
22550- if (regs->cs != __KERNEL_CS)
22551+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22552 return false;
22553
22554 pte = kmemcheck_pte_lookup(address);
22555diff -urNp linux-2.6.39.1/arch/x86/mm/mmap.c linux-2.6.39.1/arch/x86/mm/mmap.c
22556--- linux-2.6.39.1/arch/x86/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
22557+++ linux-2.6.39.1/arch/x86/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
22558@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22559 * Leave an at least ~128 MB hole with possible stack randomization.
22560 */
22561 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22562-#define MAX_GAP (TASK_SIZE/6*5)
22563+#define MAX_GAP (pax_task_size/6*5)
22564
22565 /*
22566 * True on X86_32 or when emulating IA32 on X86_64
22567@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22568 return rnd << PAGE_SHIFT;
22569 }
22570
22571-static unsigned long mmap_base(void)
22572+static unsigned long mmap_base(struct mm_struct *mm)
22573 {
22574 unsigned long gap = rlimit(RLIMIT_STACK);
22575+ unsigned long pax_task_size = TASK_SIZE;
22576+
22577+#ifdef CONFIG_PAX_SEGMEXEC
22578+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22579+ pax_task_size = SEGMEXEC_TASK_SIZE;
22580+#endif
22581
22582 if (gap < MIN_GAP)
22583 gap = MIN_GAP;
22584 else if (gap > MAX_GAP)
22585 gap = MAX_GAP;
22586
22587- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22588+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22589 }
22590
22591 /*
22592 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22593 * does, but not when emulating X86_32
22594 */
22595-static unsigned long mmap_legacy_base(void)
22596+static unsigned long mmap_legacy_base(struct mm_struct *mm)
22597 {
22598- if (mmap_is_ia32())
22599+ if (mmap_is_ia32()) {
22600+
22601+#ifdef CONFIG_PAX_SEGMEXEC
22602+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22603+ return SEGMEXEC_TASK_UNMAPPED_BASE;
22604+ else
22605+#endif
22606+
22607 return TASK_UNMAPPED_BASE;
22608- else
22609+ } else
22610 return TASK_UNMAPPED_BASE + mmap_rnd();
22611 }
22612
22613@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22614 void arch_pick_mmap_layout(struct mm_struct *mm)
22615 {
22616 if (mmap_is_legacy()) {
22617- mm->mmap_base = mmap_legacy_base();
22618+ mm->mmap_base = mmap_legacy_base(mm);
22619+
22620+#ifdef CONFIG_PAX_RANDMMAP
22621+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22622+ mm->mmap_base += mm->delta_mmap;
22623+#endif
22624+
22625 mm->get_unmapped_area = arch_get_unmapped_area;
22626 mm->unmap_area = arch_unmap_area;
22627 } else {
22628- mm->mmap_base = mmap_base();
22629+ mm->mmap_base = mmap_base(mm);
22630+
22631+#ifdef CONFIG_PAX_RANDMMAP
22632+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22633+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22634+#endif
22635+
22636 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22637 mm->unmap_area = arch_unmap_area_topdown;
22638 }
22639diff -urNp linux-2.6.39.1/arch/x86/mm/mmio-mod.c linux-2.6.39.1/arch/x86/mm/mmio-mod.c
22640--- linux-2.6.39.1/arch/x86/mm/mmio-mod.c 2011-05-19 00:06:34.000000000 -0400
22641+++ linux-2.6.39.1/arch/x86/mm/mmio-mod.c 2011-05-22 19:36:30.000000000 -0400
22642@@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p,
22643 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22644 void __iomem *addr)
22645 {
22646- static atomic_t next_id;
22647+ static atomic_unchecked_t next_id;
22648 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22649 /* These are page-unaligned. */
22650 struct mmiotrace_map map = {
22651@@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_
22652 .private = trace
22653 },
22654 .phys = offset,
22655- .id = atomic_inc_return(&next_id)
22656+ .id = atomic_inc_return_unchecked(&next_id)
22657 };
22658 map.map_id = trace->id;
22659
22660diff -urNp linux-2.6.39.1/arch/x86/mm/numa_32.c linux-2.6.39.1/arch/x86/mm/numa_32.c
22661--- linux-2.6.39.1/arch/x86/mm/numa_32.c 2011-05-19 00:06:34.000000000 -0400
22662+++ linux-2.6.39.1/arch/x86/mm/numa_32.c 2011-05-22 19:36:30.000000000 -0400
22663@@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
22664 }
22665 #endif
22666
22667-extern unsigned long find_max_low_pfn(void);
22668 extern unsigned long highend_pfn, highstart_pfn;
22669
22670 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22671diff -urNp linux-2.6.39.1/arch/x86/mm/pageattr.c linux-2.6.39.1/arch/x86/mm/pageattr.c
22672--- linux-2.6.39.1/arch/x86/mm/pageattr.c 2011-05-19 00:06:34.000000000 -0400
22673+++ linux-2.6.39.1/arch/x86/mm/pageattr.c 2011-05-22 19:36:30.000000000 -0400
22674@@ -261,7 +261,7 @@ static inline pgprot_t static_protection
22675 */
22676 #ifdef CONFIG_PCI_BIOS
22677 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22678- pgprot_val(forbidden) |= _PAGE_NX;
22679+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22680 #endif
22681
22682 /*
22683@@ -269,9 +269,10 @@ static inline pgprot_t static_protection
22684 * Does not cover __inittext since that is gone later on. On
22685 * 64bit we do not enforce !NX on the low mapping
22686 */
22687- if (within(address, (unsigned long)_text, (unsigned long)_etext))
22688- pgprot_val(forbidden) |= _PAGE_NX;
22689+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22690+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22691
22692+#ifdef CONFIG_DEBUG_RODATA
22693 /*
22694 * The .rodata section needs to be read-only. Using the pfn
22695 * catches all aliases.
22696@@ -279,6 +280,7 @@ static inline pgprot_t static_protection
22697 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22698 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22699 pgprot_val(forbidden) |= _PAGE_RW;
22700+#endif
22701
22702 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
22703 /*
22704@@ -317,6 +319,13 @@ static inline pgprot_t static_protection
22705 }
22706 #endif
22707
22708+#ifdef CONFIG_PAX_KERNEXEC
22709+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22710+ pgprot_val(forbidden) |= _PAGE_RW;
22711+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22712+ }
22713+#endif
22714+
22715 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22716
22717 return prot;
22718@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22719 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22720 {
22721 /* change init_mm */
22722+ pax_open_kernel();
22723 set_pte_atomic(kpte, pte);
22724+
22725 #ifdef CONFIG_X86_32
22726 if (!SHARED_KERNEL_PMD) {
22727+
22728+#ifdef CONFIG_PAX_PER_CPU_PGD
22729+ unsigned long cpu;
22730+#else
22731 struct page *page;
22732+#endif
22733
22734+#ifdef CONFIG_PAX_PER_CPU_PGD
22735+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22736+ pgd_t *pgd = get_cpu_pgd(cpu);
22737+#else
22738 list_for_each_entry(page, &pgd_list, lru) {
22739- pgd_t *pgd;
22740+ pgd_t *pgd = (pgd_t *)page_address(page);
22741+#endif
22742+
22743 pud_t *pud;
22744 pmd_t *pmd;
22745
22746- pgd = (pgd_t *)page_address(page) + pgd_index(address);
22747+ pgd += pgd_index(address);
22748 pud = pud_offset(pgd, address);
22749 pmd = pmd_offset(pud, address);
22750 set_pte_atomic((pte_t *)pmd, pte);
22751 }
22752 }
22753 #endif
22754+ pax_close_kernel();
22755 }
22756
22757 static int
22758diff -urNp linux-2.6.39.1/arch/x86/mm/pageattr-test.c linux-2.6.39.1/arch/x86/mm/pageattr-test.c
22759--- linux-2.6.39.1/arch/x86/mm/pageattr-test.c 2011-05-19 00:06:34.000000000 -0400
22760+++ linux-2.6.39.1/arch/x86/mm/pageattr-test.c 2011-05-22 19:36:30.000000000 -0400
22761@@ -36,7 +36,7 @@ enum {
22762
22763 static int pte_testbit(pte_t pte)
22764 {
22765- return pte_flags(pte) & _PAGE_UNUSED1;
22766+ return pte_flags(pte) & _PAGE_CPA_TEST;
22767 }
22768
22769 struct split_state {
22770diff -urNp linux-2.6.39.1/arch/x86/mm/pat.c linux-2.6.39.1/arch/x86/mm/pat.c
22771--- linux-2.6.39.1/arch/x86/mm/pat.c 2011-05-19 00:06:34.000000000 -0400
22772+++ linux-2.6.39.1/arch/x86/mm/pat.c 2011-05-22 19:36:30.000000000 -0400
22773@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
22774
22775 if (!entry) {
22776 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22777- current->comm, current->pid, start, end);
22778+ current->comm, task_pid_nr(current), start, end);
22779 return -EINVAL;
22780 }
22781
22782@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
22783 while (cursor < to) {
22784 if (!devmem_is_allowed(pfn)) {
22785 printk(KERN_INFO
22786- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22787- current->comm, from, to);
22788+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22789+ current->comm, from, to, cursor);
22790 return 0;
22791 }
22792 cursor += PAGE_SIZE;
22793@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
22794 printk(KERN_INFO
22795 "%s:%d ioremap_change_attr failed %s "
22796 "for %Lx-%Lx\n",
22797- current->comm, current->pid,
22798+ current->comm, task_pid_nr(current),
22799 cattr_name(flags),
22800 base, (unsigned long long)(base + size));
22801 return -EINVAL;
22802@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
22803 if (want_flags != flags) {
22804 printk(KERN_WARNING
22805 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
22806- current->comm, current->pid,
22807+ current->comm, task_pid_nr(current),
22808 cattr_name(want_flags),
22809 (unsigned long long)paddr,
22810 (unsigned long long)(paddr + size),
22811@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
22812 free_memtype(paddr, paddr + size);
22813 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22814 " for %Lx-%Lx, got %s\n",
22815- current->comm, current->pid,
22816+ current->comm, task_pid_nr(current),
22817 cattr_name(want_flags),
22818 (unsigned long long)paddr,
22819 (unsigned long long)(paddr + size),
22820diff -urNp linux-2.6.39.1/arch/x86/mm/pgtable_32.c linux-2.6.39.1/arch/x86/mm/pgtable_32.c
22821--- linux-2.6.39.1/arch/x86/mm/pgtable_32.c 2011-05-19 00:06:34.000000000 -0400
22822+++ linux-2.6.39.1/arch/x86/mm/pgtable_32.c 2011-05-22 19:36:30.000000000 -0400
22823@@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
22824 return;
22825 }
22826 pte = pte_offset_kernel(pmd, vaddr);
22827+
22828+ pax_open_kernel();
22829 if (pte_val(pteval))
22830 set_pte_at(&init_mm, vaddr, pte, pteval);
22831 else
22832 pte_clear(&init_mm, vaddr, pte);
22833+ pax_close_kernel();
22834
22835 /*
22836 * It's enough to flush this one mapping.
22837diff -urNp linux-2.6.39.1/arch/x86/mm/pgtable.c linux-2.6.39.1/arch/x86/mm/pgtable.c
22838--- linux-2.6.39.1/arch/x86/mm/pgtable.c 2011-05-19 00:06:34.000000000 -0400
22839+++ linux-2.6.39.1/arch/x86/mm/pgtable.c 2011-05-22 19:36:30.000000000 -0400
22840@@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *p
22841 list_del(&page->lru);
22842 }
22843
22844-#define UNSHARED_PTRS_PER_PGD \
22845- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22846+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22847+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22848
22849+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22850+{
22851+ while (count--)
22852+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22853+}
22854+#endif
22855+
22856+#ifdef CONFIG_PAX_PER_CPU_PGD
22857+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22858+{
22859+ while (count--)
22860+
22861+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22862+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22863+#else
22864+ *dst++ = *src++;
22865+#endif
22866
22867+}
22868+#endif
22869+
22870+#ifdef CONFIG_X86_64
22871+#define pxd_t pud_t
22872+#define pyd_t pgd_t
22873+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22874+#define pxd_free(mm, pud) pud_free((mm), (pud))
22875+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22876+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22877+#define PYD_SIZE PGDIR_SIZE
22878+#else
22879+#define pxd_t pmd_t
22880+#define pyd_t pud_t
22881+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22882+#define pxd_free(mm, pud) pmd_free((mm), (pud))
22883+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22884+#define pyd_offset(mm ,address) pud_offset((mm), (address))
22885+#define PYD_SIZE PUD_SIZE
22886+#endif
22887+
22888+#ifdef CONFIG_PAX_PER_CPU_PGD
22889+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
22890+static inline void pgd_dtor(pgd_t *pgd) {}
22891+#else
22892 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
22893 {
22894 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
22895@@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
22896 pgd_list_del(pgd);
22897 spin_unlock(&pgd_lock);
22898 }
22899+#endif
22900
22901 /*
22902 * List of all pgd's needed for non-PAE so it can invalidate entries
22903@@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
22904 * -- wli
22905 */
22906
22907-#ifdef CONFIG_X86_PAE
22908+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22909 /*
22910 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22911 * updating the top-level pagetable entries to guarantee the
22912@@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
22913 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22914 * and initialize the kernel pmds here.
22915 */
22916-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22917+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22918
22919 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22920 {
22921@@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm,
22922 */
22923 flush_tlb_mm(mm);
22924 }
22925+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22926+#define PREALLOCATED_PXDS USER_PGD_PTRS
22927 #else /* !CONFIG_X86_PAE */
22928
22929 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22930-#define PREALLOCATED_PMDS 0
22931+#define PREALLOCATED_PXDS 0
22932
22933 #endif /* CONFIG_X86_PAE */
22934
22935-static void free_pmds(pmd_t *pmds[])
22936+static void free_pxds(pxd_t *pxds[])
22937 {
22938 int i;
22939
22940- for(i = 0; i < PREALLOCATED_PMDS; i++)
22941- if (pmds[i])
22942- free_page((unsigned long)pmds[i]);
22943+ for(i = 0; i < PREALLOCATED_PXDS; i++)
22944+ if (pxds[i])
22945+ free_page((unsigned long)pxds[i]);
22946 }
22947
22948-static int preallocate_pmds(pmd_t *pmds[])
22949+static int preallocate_pxds(pxd_t *pxds[])
22950 {
22951 int i;
22952 bool failed = false;
22953
22954- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22955- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22956- if (pmd == NULL)
22957+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22958+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22959+ if (pxd == NULL)
22960 failed = true;
22961- pmds[i] = pmd;
22962+ pxds[i] = pxd;
22963 }
22964
22965 if (failed) {
22966- free_pmds(pmds);
22967+ free_pxds(pxds);
22968 return -ENOMEM;
22969 }
22970
22971@@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[
22972 * preallocate which never got a corresponding vma will need to be
22973 * freed manually.
22974 */
22975-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22976+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22977 {
22978 int i;
22979
22980- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22981+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22982 pgd_t pgd = pgdp[i];
22983
22984 if (pgd_val(pgd) != 0) {
22985- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22986+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22987
22988- pgdp[i] = native_make_pgd(0);
22989+ set_pgd(pgdp + i, native_make_pgd(0));
22990
22991- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22992- pmd_free(mm, pmd);
22993+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22994+ pxd_free(mm, pxd);
22995 }
22996 }
22997 }
22998
22999-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23000+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23001 {
23002- pud_t *pud;
23003+ pyd_t *pyd;
23004 unsigned long addr;
23005 int i;
23006
23007- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23008+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23009 return;
23010
23011- pud = pud_offset(pgd, 0);
23012+#ifdef CONFIG_X86_64
23013+ pyd = pyd_offset(mm, 0L);
23014+#else
23015+ pyd = pyd_offset(pgd, 0L);
23016+#endif
23017
23018- for (addr = i = 0; i < PREALLOCATED_PMDS;
23019- i++, pud++, addr += PUD_SIZE) {
23020- pmd_t *pmd = pmds[i];
23021+ for (addr = i = 0; i < PREALLOCATED_PXDS;
23022+ i++, pyd++, addr += PYD_SIZE) {
23023+ pxd_t *pxd = pxds[i];
23024
23025 if (i >= KERNEL_PGD_BOUNDARY)
23026- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23027- sizeof(pmd_t) * PTRS_PER_PMD);
23028+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23029+ sizeof(pxd_t) * PTRS_PER_PMD);
23030
23031- pud_populate(mm, pud, pmd);
23032+ pyd_populate(mm, pyd, pxd);
23033 }
23034 }
23035
23036 pgd_t *pgd_alloc(struct mm_struct *mm)
23037 {
23038 pgd_t *pgd;
23039- pmd_t *pmds[PREALLOCATED_PMDS];
23040+ pxd_t *pxds[PREALLOCATED_PXDS];
23041
23042 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23043
23044@@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23045
23046 mm->pgd = pgd;
23047
23048- if (preallocate_pmds(pmds) != 0)
23049+ if (preallocate_pxds(pxds) != 0)
23050 goto out_free_pgd;
23051
23052 if (paravirt_pgd_alloc(mm) != 0)
23053- goto out_free_pmds;
23054+ goto out_free_pxds;
23055
23056 /*
23057 * Make sure that pre-populating the pmds is atomic with
23058@@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23059 spin_lock(&pgd_lock);
23060
23061 pgd_ctor(mm, pgd);
23062- pgd_prepopulate_pmd(mm, pgd, pmds);
23063+ pgd_prepopulate_pxd(mm, pgd, pxds);
23064
23065 spin_unlock(&pgd_lock);
23066
23067 return pgd;
23068
23069-out_free_pmds:
23070- free_pmds(pmds);
23071+out_free_pxds:
23072+ free_pxds(pxds);
23073 out_free_pgd:
23074 free_page((unsigned long)pgd);
23075 out:
23076@@ -295,7 +344,7 @@ out:
23077
23078 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23079 {
23080- pgd_mop_up_pmds(mm, pgd);
23081+ pgd_mop_up_pxds(mm, pgd);
23082 pgd_dtor(pgd);
23083 paravirt_pgd_free(mm, pgd);
23084 free_page((unsigned long)pgd);
23085diff -urNp linux-2.6.39.1/arch/x86/mm/setup_nx.c linux-2.6.39.1/arch/x86/mm/setup_nx.c
23086--- linux-2.6.39.1/arch/x86/mm/setup_nx.c 2011-05-19 00:06:34.000000000 -0400
23087+++ linux-2.6.39.1/arch/x86/mm/setup_nx.c 2011-05-22 19:36:30.000000000 -0400
23088@@ -5,8 +5,10 @@
23089 #include <asm/pgtable.h>
23090 #include <asm/proto.h>
23091
23092+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23093 static int disable_nx __cpuinitdata;
23094
23095+#ifndef CONFIG_PAX_PAGEEXEC
23096 /*
23097 * noexec = on|off
23098 *
23099@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
23100 return 0;
23101 }
23102 early_param("noexec", noexec_setup);
23103+#endif
23104+
23105+#endif
23106
23107 void __cpuinit x86_configure_nx(void)
23108 {
23109+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23110 if (cpu_has_nx && !disable_nx)
23111 __supported_pte_mask |= _PAGE_NX;
23112 else
23113+#endif
23114 __supported_pte_mask &= ~_PAGE_NX;
23115 }
23116
23117diff -urNp linux-2.6.39.1/arch/x86/mm/tlb.c linux-2.6.39.1/arch/x86/mm/tlb.c
23118--- linux-2.6.39.1/arch/x86/mm/tlb.c 2011-05-19 00:06:34.000000000 -0400
23119+++ linux-2.6.39.1/arch/x86/mm/tlb.c 2011-05-22 19:36:30.000000000 -0400
23120@@ -65,7 +65,11 @@ void leave_mm(int cpu)
23121 BUG();
23122 cpumask_clear_cpu(cpu,
23123 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23124+
23125+#ifndef CONFIG_PAX_PER_CPU_PGD
23126 load_cr3(swapper_pg_dir);
23127+#endif
23128+
23129 }
23130 EXPORT_SYMBOL_GPL(leave_mm);
23131
23132diff -urNp linux-2.6.39.1/arch/x86/oprofile/backtrace.c linux-2.6.39.1/arch/x86/oprofile/backtrace.c
23133--- linux-2.6.39.1/arch/x86/oprofile/backtrace.c 2011-05-19 00:06:34.000000000 -0400
23134+++ linux-2.6.39.1/arch/x86/oprofile/backtrace.c 2011-05-22 19:36:30.000000000 -0400
23135@@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
23136 struct stack_frame_ia32 *fp;
23137
23138 /* Also check accessibility of one struct frame_head beyond */
23139- if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
23140+ if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
23141 return NULL;
23142 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
23143 return NULL;
23144@@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
23145 {
23146 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23147
23148- if (!user_mode_vm(regs)) {
23149+ if (!user_mode(regs)) {
23150 unsigned long stack = kernel_stack_pointer(regs);
23151 if (depth)
23152 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23153diff -urNp linux-2.6.39.1/arch/x86/pci/ce4100.c linux-2.6.39.1/arch/x86/pci/ce4100.c
23154--- linux-2.6.39.1/arch/x86/pci/ce4100.c 2011-05-19 00:06:34.000000000 -0400
23155+++ linux-2.6.39.1/arch/x86/pci/ce4100.c 2011-05-22 19:36:30.000000000 -0400
23156@@ -302,7 +302,7 @@ static int ce4100_conf_write(unsigned in
23157 return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
23158 }
23159
23160-struct pci_raw_ops ce4100_pci_conf = {
23161+const struct pci_raw_ops ce4100_pci_conf = {
23162 .read = ce4100_conf_read,
23163 .write = ce4100_conf_write,
23164 };
23165diff -urNp linux-2.6.39.1/arch/x86/pci/common.c linux-2.6.39.1/arch/x86/pci/common.c
23166--- linux-2.6.39.1/arch/x86/pci/common.c 2011-05-19 00:06:34.000000000 -0400
23167+++ linux-2.6.39.1/arch/x86/pci/common.c 2011-05-22 19:36:30.000000000 -0400
23168@@ -33,8 +33,8 @@ int noioapicreroute = 1;
23169 int pcibios_last_bus = -1;
23170 unsigned long pirq_table_addr;
23171 struct pci_bus *pci_root_bus;
23172-struct pci_raw_ops *raw_pci_ops;
23173-struct pci_raw_ops *raw_pci_ext_ops;
23174+const struct pci_raw_ops *raw_pci_ops;
23175+const struct pci_raw_ops *raw_pci_ext_ops;
23176
23177 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
23178 int reg, int len, u32 *val)
23179diff -urNp linux-2.6.39.1/arch/x86/pci/direct.c linux-2.6.39.1/arch/x86/pci/direct.c
23180--- linux-2.6.39.1/arch/x86/pci/direct.c 2011-05-19 00:06:34.000000000 -0400
23181+++ linux-2.6.39.1/arch/x86/pci/direct.c 2011-05-22 19:36:30.000000000 -0400
23182@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
23183
23184 #undef PCI_CONF1_ADDRESS
23185
23186-struct pci_raw_ops pci_direct_conf1 = {
23187+const struct pci_raw_ops pci_direct_conf1 = {
23188 .read = pci_conf1_read,
23189 .write = pci_conf1_write,
23190 };
23191@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
23192
23193 #undef PCI_CONF2_ADDRESS
23194
23195-struct pci_raw_ops pci_direct_conf2 = {
23196+const struct pci_raw_ops pci_direct_conf2 = {
23197 .read = pci_conf2_read,
23198 .write = pci_conf2_write,
23199 };
23200@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
23201 * This should be close to trivial, but it isn't, because there are buggy
23202 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
23203 */
23204-static int __init pci_sanity_check(struct pci_raw_ops *o)
23205+static int __init pci_sanity_check(const struct pci_raw_ops *o)
23206 {
23207 u32 x = 0;
23208 int year, devfn;
23209diff -urNp linux-2.6.39.1/arch/x86/pci/fixup.c linux-2.6.39.1/arch/x86/pci/fixup.c
23210--- linux-2.6.39.1/arch/x86/pci/fixup.c 2011-05-19 00:06:34.000000000 -0400
23211+++ linux-2.6.39.1/arch/x86/pci/fixup.c 2011-05-22 19:36:30.000000000 -0400
23212@@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
23213 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
23214 },
23215 },
23216- { }
23217+ {}
23218 };
23219
23220 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
23221diff -urNp linux-2.6.39.1/arch/x86/pci/mmconfig_32.c linux-2.6.39.1/arch/x86/pci/mmconfig_32.c
23222--- linux-2.6.39.1/arch/x86/pci/mmconfig_32.c 2011-05-19 00:06:34.000000000 -0400
23223+++ linux-2.6.39.1/arch/x86/pci/mmconfig_32.c 2011-05-22 19:36:30.000000000 -0400
23224@@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
23225 return 0;
23226 }
23227
23228-static struct pci_raw_ops pci_mmcfg = {
23229+static const struct pci_raw_ops pci_mmcfg = {
23230 .read = pci_mmcfg_read,
23231 .write = pci_mmcfg_write,
23232 };
23233diff -urNp linux-2.6.39.1/arch/x86/pci/mmconfig_64.c linux-2.6.39.1/arch/x86/pci/mmconfig_64.c
23234--- linux-2.6.39.1/arch/x86/pci/mmconfig_64.c 2011-05-19 00:06:34.000000000 -0400
23235+++ linux-2.6.39.1/arch/x86/pci/mmconfig_64.c 2011-05-22 19:36:30.000000000 -0400
23236@@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
23237 return 0;
23238 }
23239
23240-static struct pci_raw_ops pci_mmcfg = {
23241+static const struct pci_raw_ops pci_mmcfg = {
23242 .read = pci_mmcfg_read,
23243 .write = pci_mmcfg_write,
23244 };
23245diff -urNp linux-2.6.39.1/arch/x86/pci/mrst.c linux-2.6.39.1/arch/x86/pci/mrst.c
23246--- linux-2.6.39.1/arch/x86/pci/mrst.c 2011-05-19 00:06:34.000000000 -0400
23247+++ linux-2.6.39.1/arch/x86/pci/mrst.c 2011-05-22 19:36:30.000000000 -0400
23248@@ -218,7 +218,7 @@ static int mrst_pci_irq_enable(struct pc
23249 return 0;
23250 }
23251
23252-struct pci_ops pci_mrst_ops = {
23253+const struct pci_ops pci_mrst_ops = {
23254 .read = pci_read,
23255 .write = pci_write,
23256 };
23257diff -urNp linux-2.6.39.1/arch/x86/pci/numaq_32.c linux-2.6.39.1/arch/x86/pci/numaq_32.c
23258--- linux-2.6.39.1/arch/x86/pci/numaq_32.c 2011-05-19 00:06:34.000000000 -0400
23259+++ linux-2.6.39.1/arch/x86/pci/numaq_32.c 2011-05-22 19:36:30.000000000 -0400
23260@@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
23261
23262 #undef PCI_CONF1_MQ_ADDRESS
23263
23264-static struct pci_raw_ops pci_direct_conf1_mq = {
23265+static const struct pci_raw_ops pci_direct_conf1_mq = {
23266 .read = pci_conf1_mq_read,
23267 .write = pci_conf1_mq_write
23268 };
23269diff -urNp linux-2.6.39.1/arch/x86/pci/olpc.c linux-2.6.39.1/arch/x86/pci/olpc.c
23270--- linux-2.6.39.1/arch/x86/pci/olpc.c 2011-05-19 00:06:34.000000000 -0400
23271+++ linux-2.6.39.1/arch/x86/pci/olpc.c 2011-05-22 19:36:30.000000000 -0400
23272@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
23273 return 0;
23274 }
23275
23276-static struct pci_raw_ops pci_olpc_conf = {
23277+static const struct pci_raw_ops pci_olpc_conf = {
23278 .read = pci_olpc_read,
23279 .write = pci_olpc_write,
23280 };
23281diff -urNp linux-2.6.39.1/arch/x86/pci/pcbios.c linux-2.6.39.1/arch/x86/pci/pcbios.c
23282--- linux-2.6.39.1/arch/x86/pci/pcbios.c 2011-05-19 00:06:34.000000000 -0400
23283+++ linux-2.6.39.1/arch/x86/pci/pcbios.c 2011-05-22 19:36:30.000000000 -0400
23284@@ -79,50 +79,93 @@ union bios32 {
23285 static struct {
23286 unsigned long address;
23287 unsigned short segment;
23288-} bios32_indirect = { 0, __KERNEL_CS };
23289+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23290
23291 /*
23292 * Returns the entry point for the given service, NULL on error
23293 */
23294
23295-static unsigned long bios32_service(unsigned long service)
23296+static unsigned long __devinit bios32_service(unsigned long service)
23297 {
23298 unsigned char return_code; /* %al */
23299 unsigned long address; /* %ebx */
23300 unsigned long length; /* %ecx */
23301 unsigned long entry; /* %edx */
23302 unsigned long flags;
23303+ struct desc_struct d, *gdt;
23304
23305 local_irq_save(flags);
23306- __asm__("lcall *(%%edi); cld"
23307+
23308+ gdt = get_cpu_gdt_table(smp_processor_id());
23309+
23310+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23311+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23312+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23313+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23314+
23315+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23316 : "=a" (return_code),
23317 "=b" (address),
23318 "=c" (length),
23319 "=d" (entry)
23320 : "0" (service),
23321 "1" (0),
23322- "D" (&bios32_indirect));
23323+ "D" (&bios32_indirect),
23324+ "r"(__PCIBIOS_DS)
23325+ : "memory");
23326+
23327+ pax_open_kernel();
23328+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23329+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23330+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23331+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23332+ pax_close_kernel();
23333+
23334 local_irq_restore(flags);
23335
23336 switch (return_code) {
23337- case 0:
23338- return address + entry;
23339- case 0x80: /* Not present */
23340- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23341- return 0;
23342- default: /* Shouldn't happen */
23343- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23344- service, return_code);
23345+ case 0: {
23346+ int cpu;
23347+ unsigned char flags;
23348+
23349+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23350+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23351+ printk(KERN_WARNING "bios32_service: not valid\n");
23352 return 0;
23353+ }
23354+ address = address + PAGE_OFFSET;
23355+ length += 16UL; /* some BIOSs underreport this... */
23356+ flags = 4;
23357+ if (length >= 64*1024*1024) {
23358+ length >>= PAGE_SHIFT;
23359+ flags |= 8;
23360+ }
23361+
23362+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
23363+ gdt = get_cpu_gdt_table(cpu);
23364+ pack_descriptor(&d, address, length, 0x9b, flags);
23365+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23366+ pack_descriptor(&d, address, length, 0x93, flags);
23367+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23368+ }
23369+ return entry;
23370+ }
23371+ case 0x80: /* Not present */
23372+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23373+ return 0;
23374+ default: /* Shouldn't happen */
23375+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23376+ service, return_code);
23377+ return 0;
23378 }
23379 }
23380
23381 static struct {
23382 unsigned long address;
23383 unsigned short segment;
23384-} pci_indirect = { 0, __KERNEL_CS };
23385+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23386
23387-static int pci_bios_present;
23388+static int pci_bios_present __read_only;
23389
23390 static int __devinit check_pcibios(void)
23391 {
23392@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23393 unsigned long flags, pcibios_entry;
23394
23395 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23396- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23397+ pci_indirect.address = pcibios_entry;
23398
23399 local_irq_save(flags);
23400- __asm__(
23401- "lcall *(%%edi); cld\n\t"
23402+ __asm__("movw %w6, %%ds\n\t"
23403+ "lcall *%%ss:(%%edi); cld\n\t"
23404+ "push %%ss\n\t"
23405+ "pop %%ds\n\t"
23406 "jc 1f\n\t"
23407 "xor %%ah, %%ah\n"
23408 "1:"
23409@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23410 "=b" (ebx),
23411 "=c" (ecx)
23412 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23413- "D" (&pci_indirect)
23414+ "D" (&pci_indirect),
23415+ "r" (__PCIBIOS_DS)
23416 : "memory");
23417 local_irq_restore(flags);
23418
23419@@ -188,7 +234,10 @@ static int pci_bios_read(unsigned int se
23420
23421 switch (len) {
23422 case 1:
23423- __asm__("lcall *(%%esi); cld\n\t"
23424+ __asm__("movw %w6, %%ds\n\t"
23425+ "lcall *%%ss:(%%esi); cld\n\t"
23426+ "push %%ss\n\t"
23427+ "pop %%ds\n\t"
23428 "jc 1f\n\t"
23429 "xor %%ah, %%ah\n"
23430 "1:"
23431@@ -197,7 +246,8 @@ static int pci_bios_read(unsigned int se
23432 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23433 "b" (bx),
23434 "D" ((long)reg),
23435- "S" (&pci_indirect));
23436+ "S" (&pci_indirect),
23437+ "r" (__PCIBIOS_DS));
23438 /*
23439 * Zero-extend the result beyond 8 bits, do not trust the
23440 * BIOS having done it:
23441@@ -205,7 +255,10 @@ static int pci_bios_read(unsigned int se
23442 *value &= 0xff;
23443 break;
23444 case 2:
23445- __asm__("lcall *(%%esi); cld\n\t"
23446+ __asm__("movw %w6, %%ds\n\t"
23447+ "lcall *%%ss:(%%esi); cld\n\t"
23448+ "push %%ss\n\t"
23449+ "pop %%ds\n\t"
23450 "jc 1f\n\t"
23451 "xor %%ah, %%ah\n"
23452 "1:"
23453@@ -214,7 +267,8 @@ static int pci_bios_read(unsigned int se
23454 : "1" (PCIBIOS_READ_CONFIG_WORD),
23455 "b" (bx),
23456 "D" ((long)reg),
23457- "S" (&pci_indirect));
23458+ "S" (&pci_indirect),
23459+ "r" (__PCIBIOS_DS));
23460 /*
23461 * Zero-extend the result beyond 16 bits, do not trust the
23462 * BIOS having done it:
23463@@ -222,7 +276,10 @@ static int pci_bios_read(unsigned int se
23464 *value &= 0xffff;
23465 break;
23466 case 4:
23467- __asm__("lcall *(%%esi); cld\n\t"
23468+ __asm__("movw %w6, %%ds\n\t"
23469+ "lcall *%%ss:(%%esi); cld\n\t"
23470+ "push %%ss\n\t"
23471+ "pop %%ds\n\t"
23472 "jc 1f\n\t"
23473 "xor %%ah, %%ah\n"
23474 "1:"
23475@@ -231,7 +288,8 @@ static int pci_bios_read(unsigned int se
23476 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23477 "b" (bx),
23478 "D" ((long)reg),
23479- "S" (&pci_indirect));
23480+ "S" (&pci_indirect),
23481+ "r" (__PCIBIOS_DS));
23482 break;
23483 }
23484
23485@@ -254,7 +312,10 @@ static int pci_bios_write(unsigned int s
23486
23487 switch (len) {
23488 case 1:
23489- __asm__("lcall *(%%esi); cld\n\t"
23490+ __asm__("movw %w6, %%ds\n\t"
23491+ "lcall *%%ss:(%%esi); cld\n\t"
23492+ "push %%ss\n\t"
23493+ "pop %%ds\n\t"
23494 "jc 1f\n\t"
23495 "xor %%ah, %%ah\n"
23496 "1:"
23497@@ -263,10 +324,14 @@ static int pci_bios_write(unsigned int s
23498 "c" (value),
23499 "b" (bx),
23500 "D" ((long)reg),
23501- "S" (&pci_indirect));
23502+ "S" (&pci_indirect),
23503+ "r" (__PCIBIOS_DS));
23504 break;
23505 case 2:
23506- __asm__("lcall *(%%esi); cld\n\t"
23507+ __asm__("movw %w6, %%ds\n\t"
23508+ "lcall *%%ss:(%%esi); cld\n\t"
23509+ "push %%ss\n\t"
23510+ "pop %%ds\n\t"
23511 "jc 1f\n\t"
23512 "xor %%ah, %%ah\n"
23513 "1:"
23514@@ -275,10 +340,14 @@ static int pci_bios_write(unsigned int s
23515 "c" (value),
23516 "b" (bx),
23517 "D" ((long)reg),
23518- "S" (&pci_indirect));
23519+ "S" (&pci_indirect),
23520+ "r" (__PCIBIOS_DS));
23521 break;
23522 case 4:
23523- __asm__("lcall *(%%esi); cld\n\t"
23524+ __asm__("movw %w6, %%ds\n\t"
23525+ "lcall *%%ss:(%%esi); cld\n\t"
23526+ "push %%ss\n\t"
23527+ "pop %%ds\n\t"
23528 "jc 1f\n\t"
23529 "xor %%ah, %%ah\n"
23530 "1:"
23531@@ -287,7 +356,8 @@ static int pci_bios_write(unsigned int s
23532 "c" (value),
23533 "b" (bx),
23534 "D" ((long)reg),
23535- "S" (&pci_indirect));
23536+ "S" (&pci_indirect),
23537+ "r" (__PCIBIOS_DS));
23538 break;
23539 }
23540
23541@@ -301,7 +371,7 @@ static int pci_bios_write(unsigned int s
23542 * Function table for BIOS32 access
23543 */
23544
23545-static struct pci_raw_ops pci_bios_access = {
23546+static const struct pci_raw_ops pci_bios_access = {
23547 .read = pci_bios_read,
23548 .write = pci_bios_write
23549 };
23550@@ -310,7 +380,7 @@ static struct pci_raw_ops pci_bios_acces
23551 * Try to find PCI BIOS.
23552 */
23553
23554-static struct pci_raw_ops * __devinit pci_find_bios(void)
23555+static const struct pci_raw_ops * __devinit pci_find_bios(void)
23556 {
23557 union bios32 *check;
23558 unsigned char sum;
23559@@ -392,10 +462,13 @@ struct irq_routing_table * pcibios_get_i
23560
23561 DBG("PCI: Fetching IRQ routing table... ");
23562 __asm__("push %%es\n\t"
23563+ "movw %w8, %%ds\n\t"
23564 "push %%ds\n\t"
23565 "pop %%es\n\t"
23566- "lcall *(%%esi); cld\n\t"
23567+ "lcall *%%ss:(%%esi); cld\n\t"
23568 "pop %%es\n\t"
23569+ "push %%ss\n\t"
23570+ "pop %%ds\n"
23571 "jc 1f\n\t"
23572 "xor %%ah, %%ah\n"
23573 "1:"
23574@@ -406,7 +479,8 @@ struct irq_routing_table * pcibios_get_i
23575 "1" (0),
23576 "D" ((long) &opt),
23577 "S" (&pci_indirect),
23578- "m" (opt)
23579+ "m" (opt),
23580+ "r" (__PCIBIOS_DS)
23581 : "memory");
23582 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23583 if (ret & 0xff00)
23584@@ -430,7 +504,10 @@ int pcibios_set_irq_routing(struct pci_d
23585 {
23586 int ret;
23587
23588- __asm__("lcall *(%%esi); cld\n\t"
23589+ __asm__("movw %w5, %%ds\n\t"
23590+ "lcall *%%ss:(%%esi); cld\n\t"
23591+ "push %%ss\n\t"
23592+ "pop %%ds\n"
23593 "jc 1f\n\t"
23594 "xor %%ah, %%ah\n"
23595 "1:"
23596@@ -438,7 +515,8 @@ int pcibios_set_irq_routing(struct pci_d
23597 : "0" (PCIBIOS_SET_PCI_HW_INT),
23598 "b" ((dev->bus->number << 8) | dev->devfn),
23599 "c" ((irq << 8) | (pin + 10)),
23600- "S" (&pci_indirect));
23601+ "S" (&pci_indirect),
23602+ "r" (__PCIBIOS_DS));
23603 return !(ret & 0xff00);
23604 }
23605 EXPORT_SYMBOL(pcibios_set_irq_routing);
23606diff -urNp linux-2.6.39.1/arch/x86/pci/xen.c linux-2.6.39.1/arch/x86/pci/xen.c
23607--- linux-2.6.39.1/arch/x86/pci/xen.c 2011-05-19 00:06:34.000000000 -0400
23608+++ linux-2.6.39.1/arch/x86/pci/xen.c 2011-05-22 19:36:30.000000000 -0400
23609@@ -62,7 +62,7 @@ static int acpi_register_gsi_xen_hvm(str
23610 #include <linux/msi.h>
23611 #include <asm/msidef.h>
23612
23613-struct xen_pci_frontend_ops *xen_pci_frontend;
23614+const struct xen_pci_frontend_ops *xen_pci_frontend;
23615 EXPORT_SYMBOL_GPL(xen_pci_frontend);
23616
23617 #define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
23618diff -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
23619--- linux-2.6.39.1/arch/x86/platform/efi/efi_32.c 2011-05-19 00:06:34.000000000 -0400
23620+++ linux-2.6.39.1/arch/x86/platform/efi/efi_32.c 2011-05-22 19:36:30.000000000 -0400
23621@@ -38,70 +38,37 @@
23622 */
23623
23624 static unsigned long efi_rt_eflags;
23625-static pgd_t efi_bak_pg_dir_pointer[2];
23626+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
23627
23628-void efi_call_phys_prelog(void)
23629+void __init efi_call_phys_prelog(void)
23630 {
23631- unsigned long cr4;
23632- unsigned long temp;
23633 struct desc_ptr gdt_descr;
23634
23635 local_irq_save(efi_rt_eflags);
23636
23637- /*
23638- * If I don't have PAE, I should just duplicate two entries in page
23639- * directory. If I have PAE, I just need to duplicate one entry in
23640- * page directory.
23641- */
23642- cr4 = read_cr4_safe();
23643-
23644- if (cr4 & X86_CR4_PAE) {
23645- efi_bak_pg_dir_pointer[0].pgd =
23646- swapper_pg_dir[pgd_index(0)].pgd;
23647- swapper_pg_dir[0].pgd =
23648- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23649- } else {
23650- efi_bak_pg_dir_pointer[0].pgd =
23651- swapper_pg_dir[pgd_index(0)].pgd;
23652- efi_bak_pg_dir_pointer[1].pgd =
23653- swapper_pg_dir[pgd_index(0x400000)].pgd;
23654- swapper_pg_dir[pgd_index(0)].pgd =
23655- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23656- temp = PAGE_OFFSET + 0x400000;
23657- swapper_pg_dir[pgd_index(0x400000)].pgd =
23658- swapper_pg_dir[pgd_index(temp)].pgd;
23659- }
23660+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
23661+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23662+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
23663
23664 /*
23665 * After the lock is released, the original page table is restored.
23666 */
23667 __flush_tlb_all();
23668
23669- gdt_descr.address = __pa(get_cpu_gdt_table(0));
23670+ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
23671 gdt_descr.size = GDT_SIZE - 1;
23672 load_gdt(&gdt_descr);
23673 }
23674
23675-void efi_call_phys_epilog(void)
23676+void __init efi_call_phys_epilog(void)
23677 {
23678- unsigned long cr4;
23679 struct desc_ptr gdt_descr;
23680
23681- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
23682+ gdt_descr.address = get_cpu_gdt_table(0);
23683 gdt_descr.size = GDT_SIZE - 1;
23684 load_gdt(&gdt_descr);
23685
23686- cr4 = read_cr4_safe();
23687-
23688- if (cr4 & X86_CR4_PAE) {
23689- swapper_pg_dir[pgd_index(0)].pgd =
23690- efi_bak_pg_dir_pointer[0].pgd;
23691- } else {
23692- swapper_pg_dir[pgd_index(0)].pgd =
23693- efi_bak_pg_dir_pointer[0].pgd;
23694- swapper_pg_dir[pgd_index(0x400000)].pgd =
23695- efi_bak_pg_dir_pointer[1].pgd;
23696- }
23697+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
23698
23699 /*
23700 * After the lock is released, the original page table is restored.
23701diff -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
23702--- linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S 2011-05-19 00:06:34.000000000 -0400
23703+++ linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S 2011-05-22 19:36:30.000000000 -0400
23704@@ -6,6 +6,7 @@
23705 */
23706
23707 #include <linux/linkage.h>
23708+#include <linux/init.h>
23709 #include <asm/page_types.h>
23710
23711 /*
23712@@ -20,7 +21,7 @@
23713 * service functions will comply with gcc calling convention, too.
23714 */
23715
23716-.text
23717+__INIT
23718 ENTRY(efi_call_phys)
23719 /*
23720 * 0. The function can only be called in Linux kernel. So CS has been
23721@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
23722 * The mapping of lower virtual memory has been created in prelog and
23723 * epilog.
23724 */
23725- movl $1f, %edx
23726- subl $__PAGE_OFFSET, %edx
23727- jmp *%edx
23728+ jmp 1f-__PAGE_OFFSET
23729 1:
23730
23731 /*
23732@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
23733 * parameter 2, ..., param n. To make things easy, we save the return
23734 * address of efi_call_phys in a global variable.
23735 */
23736- popl %edx
23737- movl %edx, saved_return_addr
23738- /* get the function pointer into ECX*/
23739- popl %ecx
23740- movl %ecx, efi_rt_function_ptr
23741- movl $2f, %edx
23742- subl $__PAGE_OFFSET, %edx
23743- pushl %edx
23744+ popl (saved_return_addr)
23745+ popl (efi_rt_function_ptr)
23746
23747 /*
23748 * 3. Clear PG bit in %CR0.
23749@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
23750 /*
23751 * 5. Call the physical function.
23752 */
23753- jmp *%ecx
23754+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
23755
23756-2:
23757 /*
23758 * 6. After EFI runtime service returns, control will return to
23759 * following instruction. We'd better readjust stack pointer first.
23760@@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
23761 movl %cr0, %edx
23762 orl $0x80000000, %edx
23763 movl %edx, %cr0
23764- jmp 1f
23765-1:
23766+
23767 /*
23768 * 8. Now restore the virtual mode from flat mode by
23769 * adding EIP with PAGE_OFFSET.
23770 */
23771- movl $1f, %edx
23772- jmp *%edx
23773+ jmp 1f+__PAGE_OFFSET
23774 1:
23775
23776 /*
23777 * 9. Balance the stack. And because EAX contain the return value,
23778 * we'd better not clobber it.
23779 */
23780- leal efi_rt_function_ptr, %edx
23781- movl (%edx), %ecx
23782- pushl %ecx
23783+ pushl (efi_rt_function_ptr)
23784
23785 /*
23786- * 10. Push the saved return address onto the stack and return.
23787+ * 10. Return to the saved return address.
23788 */
23789- leal saved_return_addr, %edx
23790- movl (%edx), %ecx
23791- pushl %ecx
23792- ret
23793+ jmpl *(saved_return_addr)
23794 ENDPROC(efi_call_phys)
23795 .previous
23796
23797-.data
23798+__INITDATA
23799 saved_return_addr:
23800 .long 0
23801 efi_rt_function_ptr:
23802diff -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
23803--- linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c 2011-05-19 00:06:34.000000000 -0400
23804+++ linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c 2011-05-22 19:36:30.000000000 -0400
23805@@ -154,7 +154,7 @@ void * __init prom_early_alloc(unsigned
23806 return res;
23807 }
23808
23809-static struct of_pdt_ops prom_olpc_ops __initdata = {
23810+static const struct of_pdt_ops prom_olpc_ops = {
23811 .nextprop = olpc_dt_nextprop,
23812 .getproplen = olpc_dt_getproplen,
23813 .getproperty = olpc_dt_getproperty,
23814diff -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
23815--- linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c 2011-05-19 00:06:34.000000000 -0400
23816+++ linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c 2011-05-22 19:36:30.000000000 -0400
23817@@ -342,6 +342,8 @@ static void uv_reset_with_ipi(struct bau
23818 cpumask_t mask;
23819 struct reset_args reset_args;
23820
23821+ pax_track_stack();
23822+
23823 reset_args.sender = sender;
23824
23825 cpus_clear(mask);
23826diff -urNp linux-2.6.39.1/arch/x86/power/cpu.c linux-2.6.39.1/arch/x86/power/cpu.c
23827--- linux-2.6.39.1/arch/x86/power/cpu.c 2011-05-19 00:06:34.000000000 -0400
23828+++ linux-2.6.39.1/arch/x86/power/cpu.c 2011-05-22 19:36:30.000000000 -0400
23829@@ -130,7 +130,7 @@ static void do_fpu_end(void)
23830 static void fix_processor_context(void)
23831 {
23832 int cpu = smp_processor_id();
23833- struct tss_struct *t = &per_cpu(init_tss, cpu);
23834+ struct tss_struct *t = init_tss + cpu;
23835
23836 set_tss_desc(cpu, t); /*
23837 * This just modifies memory; should not be
23838@@ -140,7 +140,9 @@ static void fix_processor_context(void)
23839 */
23840
23841 #ifdef CONFIG_X86_64
23842+ pax_open_kernel();
23843 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23844+ pax_close_kernel();
23845
23846 syscall_init(); /* This sets MSR_*STAR and related */
23847 #endif
23848diff -urNp linux-2.6.39.1/arch/x86/vdso/Makefile linux-2.6.39.1/arch/x86/vdso/Makefile
23849--- linux-2.6.39.1/arch/x86/vdso/Makefile 2011-05-19 00:06:34.000000000 -0400
23850+++ linux-2.6.39.1/arch/x86/vdso/Makefile 2011-05-22 19:36:30.000000000 -0400
23851@@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
23852 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
23853 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
23854
23855-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23856+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23857 GCOV_PROFILE := n
23858
23859 #
23860diff -urNp linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c
23861--- linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c 2011-05-19 00:06:34.000000000 -0400
23862+++ linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c 2011-05-22 19:36:30.000000000 -0400
23863@@ -22,24 +22,48 @@
23864 #include <asm/hpet.h>
23865 #include <asm/unistd.h>
23866 #include <asm/io.h>
23867+#include <asm/fixmap.h>
23868 #include "vextern.h"
23869
23870 #define gtod vdso_vsyscall_gtod_data
23871
23872+notrace noinline long __vdso_fallback_time(long *t)
23873+{
23874+ long secs;
23875+ asm volatile("syscall"
23876+ : "=a" (secs)
23877+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23878+ return secs;
23879+}
23880+
23881 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23882 {
23883 long ret;
23884 asm("syscall" : "=a" (ret) :
23885- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23886+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23887 return ret;
23888 }
23889
23890+notrace static inline cycle_t __vdso_vread_hpet(void)
23891+{
23892+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23893+}
23894+
23895+notrace static inline cycle_t __vdso_vread_tsc(void)
23896+{
23897+ cycle_t ret = (cycle_t)vget_cycles();
23898+
23899+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23900+}
23901+
23902 notrace static inline long vgetns(void)
23903 {
23904 long v;
23905- cycles_t (*vread)(void);
23906- vread = gtod->clock.vread;
23907- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23908+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23909+ v = __vdso_vread_tsc();
23910+ else
23911+ v = __vdso_vread_hpet();
23912+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23913 return (v * gtod->clock.mult) >> gtod->clock.shift;
23914 }
23915
23916@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23917
23918 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23919 {
23920- if (likely(gtod->sysctl_enabled))
23921+ if (likely(gtod->sysctl_enabled &&
23922+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23923+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23924 switch (clock) {
23925 case CLOCK_REALTIME:
23926 if (likely(gtod->clock.vread))
23927@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23928 int clock_gettime(clockid_t, struct timespec *)
23929 __attribute__((weak, alias("__vdso_clock_gettime")));
23930
23931-notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23932+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23933 {
23934 long ret;
23935- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23936+ asm("syscall" : "=a" (ret) :
23937+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23938+ return ret;
23939+}
23940+
23941+notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23942+{
23943+ if (likely(gtod->sysctl_enabled &&
23944+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23945+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23946+ {
23947 if (likely(tv != NULL)) {
23948 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23949 offsetof(struct timespec, tv_nsec) ||
23950@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23951 }
23952 return 0;
23953 }
23954- asm("syscall" : "=a" (ret) :
23955- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23956- return ret;
23957+ return __vdso_fallback_gettimeofday(tv, tz);
23958 }
23959 int gettimeofday(struct timeval *, struct timezone *)
23960 __attribute__((weak, alias("__vdso_gettimeofday")));
23961diff -urNp linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c
23962--- linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c 2011-05-19 00:06:34.000000000 -0400
23963+++ linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c 2011-05-22 19:36:30.000000000 -0400
23964@@ -25,6 +25,7 @@
23965 #include <asm/tlbflush.h>
23966 #include <asm/vdso.h>
23967 #include <asm/proto.h>
23968+#include <asm/mman.h>
23969
23970 enum {
23971 VDSO_DISABLED = 0,
23972@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23973 void enable_sep_cpu(void)
23974 {
23975 int cpu = get_cpu();
23976- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23977+ struct tss_struct *tss = init_tss + cpu;
23978
23979 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23980 put_cpu();
23981@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23982 gate_vma.vm_start = FIXADDR_USER_START;
23983 gate_vma.vm_end = FIXADDR_USER_END;
23984 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23985- gate_vma.vm_page_prot = __P101;
23986+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23987 /*
23988 * Make sure the vDSO gets into every core dump.
23989 * Dumping its contents makes post-mortem fully interpretable later
23990@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23991 if (compat)
23992 addr = VDSO_HIGH_BASE;
23993 else {
23994- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23995+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23996 if (IS_ERR_VALUE(addr)) {
23997 ret = addr;
23998 goto up_fail;
23999 }
24000 }
24001
24002- current->mm->context.vdso = (void *)addr;
24003+ current->mm->context.vdso = addr;
24004
24005 if (compat_uses_vma || !compat) {
24006 /*
24007@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
24008 }
24009
24010 current_thread_info()->sysenter_return =
24011- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24012+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24013
24014 up_fail:
24015 if (ret)
24016- current->mm->context.vdso = NULL;
24017+ current->mm->context.vdso = 0;
24018
24019 up_write(&mm->mmap_sem);
24020
24021@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24022
24023 const char *arch_vma_name(struct vm_area_struct *vma)
24024 {
24025- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24026+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24027 return "[vdso]";
24028+
24029+#ifdef CONFIG_PAX_SEGMEXEC
24030+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24031+ return "[vdso]";
24032+#endif
24033+
24034 return NULL;
24035 }
24036
24037@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
24038 * Check to see if the corresponding task was created in compat vdso
24039 * mode.
24040 */
24041- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24042+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24043 return &gate_vma;
24044 return NULL;
24045 }
24046diff -urNp linux-2.6.39.1/arch/x86/vdso/vdso.lds.S linux-2.6.39.1/arch/x86/vdso/vdso.lds.S
24047--- linux-2.6.39.1/arch/x86/vdso/vdso.lds.S 2011-05-19 00:06:34.000000000 -0400
24048+++ linux-2.6.39.1/arch/x86/vdso/vdso.lds.S 2011-06-06 17:34:26.000000000 -0400
24049@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
24050 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
24051 #include "vextern.h"
24052 #undef VEXTERN
24053+
24054+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
24055+VEXTERN(fallback_gettimeofday)
24056+VEXTERN(fallback_time)
24057+VEXTERN(getcpu)
24058+#undef VEXTERN
24059diff -urNp linux-2.6.39.1/arch/x86/vdso/vextern.h linux-2.6.39.1/arch/x86/vdso/vextern.h
24060--- linux-2.6.39.1/arch/x86/vdso/vextern.h 2011-05-19 00:06:34.000000000 -0400
24061+++ linux-2.6.39.1/arch/x86/vdso/vextern.h 2011-05-22 19:36:30.000000000 -0400
24062@@ -11,6 +11,5 @@
24063 put into vextern.h and be referenced as a pointer with vdso prefix.
24064 The main kernel later fills in the values. */
24065
24066-VEXTERN(jiffies)
24067 VEXTERN(vgetcpu_mode)
24068 VEXTERN(vsyscall_gtod_data)
24069diff -urNp linux-2.6.39.1/arch/x86/vdso/vma.c linux-2.6.39.1/arch/x86/vdso/vma.c
24070--- linux-2.6.39.1/arch/x86/vdso/vma.c 2011-05-19 00:06:34.000000000 -0400
24071+++ linux-2.6.39.1/arch/x86/vdso/vma.c 2011-05-22 19:36:30.000000000 -0400
24072@@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
24073 if (!vbase)
24074 goto oom;
24075
24076- if (memcmp(vbase, "\177ELF", 4)) {
24077+ if (memcmp(vbase, ELFMAG, SELFMAG)) {
24078 printk("VDSO: I'm broken; not ELF\n");
24079 vdso_enabled = 0;
24080 }
24081@@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
24082 goto up_fail;
24083 }
24084
24085- current->mm->context.vdso = (void *)addr;
24086+ current->mm->context.vdso = addr;
24087
24088 ret = install_special_mapping(mm, addr, vdso_size,
24089 VM_READ|VM_EXEC|
24090@@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
24091 VM_ALWAYSDUMP,
24092 vdso_pages);
24093 if (ret) {
24094- current->mm->context.vdso = NULL;
24095+ current->mm->context.vdso = 0;
24096 goto up_fail;
24097 }
24098
24099@@ -134,10 +134,3 @@ up_fail:
24100 up_write(&mm->mmap_sem);
24101 return ret;
24102 }
24103-
24104-static __init int vdso_setup(char *s)
24105-{
24106- vdso_enabled = simple_strtoul(s, NULL, 0);
24107- return 0;
24108-}
24109-__setup("vdso=", vdso_setup);
24110diff -urNp linux-2.6.39.1/arch/x86/xen/enlighten.c linux-2.6.39.1/arch/x86/xen/enlighten.c
24111--- linux-2.6.39.1/arch/x86/xen/enlighten.c 2011-05-19 00:06:34.000000000 -0400
24112+++ linux-2.6.39.1/arch/x86/xen/enlighten.c 2011-05-22 19:36:30.000000000 -0400
24113@@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24114
24115 struct shared_info xen_dummy_shared_info;
24116
24117-void *xen_initial_gdt;
24118-
24119 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24120 __read_mostly int xen_have_vector_callback;
24121 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24122@@ -1010,7 +1008,7 @@ static const struct pv_apic_ops xen_apic
24123 #endif
24124 };
24125
24126-static void xen_reboot(int reason)
24127+static __noreturn void xen_reboot(int reason)
24128 {
24129 struct sched_shutdown r = { .reason = reason };
24130
24131@@ -1018,17 +1016,17 @@ static void xen_reboot(int reason)
24132 BUG();
24133 }
24134
24135-static void xen_restart(char *msg)
24136+static __noreturn void xen_restart(char *msg)
24137 {
24138 xen_reboot(SHUTDOWN_reboot);
24139 }
24140
24141-static void xen_emergency_restart(void)
24142+static __noreturn void xen_emergency_restart(void)
24143 {
24144 xen_reboot(SHUTDOWN_reboot);
24145 }
24146
24147-static void xen_machine_halt(void)
24148+static __noreturn void xen_machine_halt(void)
24149 {
24150 xen_reboot(SHUTDOWN_poweroff);
24151 }
24152@@ -1127,7 +1125,17 @@ asmlinkage void __init xen_start_kernel(
24153 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24154
24155 /* Work out if we support NX */
24156- x86_configure_nx();
24157+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24158+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24159+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24160+ unsigned l, h;
24161+
24162+ __supported_pte_mask |= _PAGE_NX;
24163+ rdmsr(MSR_EFER, l, h);
24164+ l |= EFER_NX;
24165+ wrmsr(MSR_EFER, l, h);
24166+ }
24167+#endif
24168
24169 xen_setup_features();
24170
24171@@ -1158,13 +1166,6 @@ asmlinkage void __init xen_start_kernel(
24172
24173 machine_ops = xen_machine_ops;
24174
24175- /*
24176- * The only reliable way to retain the initial address of the
24177- * percpu gdt_page is to remember it here, so we can go and
24178- * mark it RW later, when the initial percpu area is freed.
24179- */
24180- xen_initial_gdt = &per_cpu(gdt_page, 0);
24181-
24182 xen_smp_init();
24183
24184 #ifdef CONFIG_ACPI_NUMA
24185diff -urNp linux-2.6.39.1/arch/x86/xen/mmu.c linux-2.6.39.1/arch/x86/xen/mmu.c
24186--- linux-2.6.39.1/arch/x86/xen/mmu.c 2011-06-03 00:04:13.000000000 -0400
24187+++ linux-2.6.39.1/arch/x86/xen/mmu.c 2011-06-03 00:32:05.000000000 -0400
24188@@ -1791,6 +1791,8 @@ __init pgd_t *xen_setup_kernel_pagetable
24189 convert_pfn_mfn(init_level4_pgt);
24190 convert_pfn_mfn(level3_ident_pgt);
24191 convert_pfn_mfn(level3_kernel_pgt);
24192+ convert_pfn_mfn(level3_vmalloc_pgt);
24193+ convert_pfn_mfn(level3_vmemmap_pgt);
24194
24195 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24196 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24197@@ -1809,7 +1811,10 @@ __init pgd_t *xen_setup_kernel_pagetable
24198 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24199 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24200 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24201+ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
24202+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24203 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24204+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24205 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24206 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24207
24208diff -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
24209--- linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c 2011-05-19 00:06:34.000000000 -0400
24210+++ linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c 2011-05-22 19:36:30.000000000 -0400
24211@@ -10,7 +10,7 @@
24212
24213 int xen_swiotlb __read_mostly;
24214
24215-static struct dma_map_ops xen_swiotlb_dma_ops = {
24216+static const struct dma_map_ops xen_swiotlb_dma_ops = {
24217 .mapping_error = xen_swiotlb_dma_mapping_error,
24218 .alloc_coherent = xen_swiotlb_alloc_coherent,
24219 .free_coherent = xen_swiotlb_free_coherent,
24220diff -urNp linux-2.6.39.1/arch/x86/xen/smp.c linux-2.6.39.1/arch/x86/xen/smp.c
24221--- linux-2.6.39.1/arch/x86/xen/smp.c 2011-05-19 00:06:34.000000000 -0400
24222+++ linux-2.6.39.1/arch/x86/xen/smp.c 2011-05-22 19:36:30.000000000 -0400
24223@@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
24224 {
24225 BUG_ON(smp_processor_id() != 0);
24226 native_smp_prepare_boot_cpu();
24227-
24228- /* We've switched to the "real" per-cpu gdt, so make sure the
24229- old memory can be recycled */
24230- make_lowmem_page_readwrite(xen_initial_gdt);
24231-
24232 xen_filter_cpu_maps();
24233 xen_setup_vcpu_info_placement();
24234 }
24235@@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
24236 gdt = get_cpu_gdt_table(cpu);
24237
24238 ctxt->flags = VGCF_IN_KERNEL;
24239- ctxt->user_regs.ds = __USER_DS;
24240- ctxt->user_regs.es = __USER_DS;
24241+ ctxt->user_regs.ds = __KERNEL_DS;
24242+ ctxt->user_regs.es = __KERNEL_DS;
24243 ctxt->user_regs.ss = __KERNEL_DS;
24244 #ifdef CONFIG_X86_32
24245 ctxt->user_regs.fs = __KERNEL_PERCPU;
24246- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24247+ savesegment(gs, ctxt->user_regs.gs);
24248 #else
24249 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24250 #endif
24251@@ -315,13 +310,12 @@ static int __cpuinit xen_cpu_up(unsigned
24252 int rc;
24253
24254 per_cpu(current_task, cpu) = idle;
24255+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
24256 #ifdef CONFIG_X86_32
24257 irq_ctx_init(cpu);
24258 #else
24259 clear_tsk_thread_flag(idle, TIF_FORK);
24260- per_cpu(kernel_stack, cpu) =
24261- (unsigned long)task_stack_page(idle) -
24262- KERNEL_STACK_OFFSET + THREAD_SIZE;
24263+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24264 #endif
24265 xen_setup_runstate_info(cpu);
24266 xen_setup_timer(cpu);
24267diff -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
24268--- linux-2.6.39.1/arch/x86/xen/xen-asm_32.S 2011-05-19 00:06:34.000000000 -0400
24269+++ linux-2.6.39.1/arch/x86/xen/xen-asm_32.S 2011-05-22 19:36:30.000000000 -0400
24270@@ -83,14 +83,14 @@ ENTRY(xen_iret)
24271 ESP_OFFSET=4 # bytes pushed onto stack
24272
24273 /*
24274- * Store vcpu_info pointer for easy access. Do it this way to
24275- * avoid having to reload %fs
24276+ * Store vcpu_info pointer for easy access.
24277 */
24278 #ifdef CONFIG_SMP
24279- GET_THREAD_INFO(%eax)
24280- movl TI_cpu(%eax), %eax
24281- movl __per_cpu_offset(,%eax,4), %eax
24282- mov xen_vcpu(%eax), %eax
24283+ push %fs
24284+ mov $(__KERNEL_PERCPU), %eax
24285+ mov %eax, %fs
24286+ mov PER_CPU_VAR(xen_vcpu), %eax
24287+ pop %fs
24288 #else
24289 movl xen_vcpu, %eax
24290 #endif
24291diff -urNp linux-2.6.39.1/arch/x86/xen/xen-head.S linux-2.6.39.1/arch/x86/xen/xen-head.S
24292--- linux-2.6.39.1/arch/x86/xen/xen-head.S 2011-05-19 00:06:34.000000000 -0400
24293+++ linux-2.6.39.1/arch/x86/xen/xen-head.S 2011-05-22 19:36:30.000000000 -0400
24294@@ -19,6 +19,17 @@ ENTRY(startup_xen)
24295 #ifdef CONFIG_X86_32
24296 mov %esi,xen_start_info
24297 mov $init_thread_union+THREAD_SIZE,%esp
24298+#ifdef CONFIG_SMP
24299+ movl $cpu_gdt_table,%edi
24300+ movl $__per_cpu_load,%eax
24301+ movw %ax,__KERNEL_PERCPU + 2(%edi)
24302+ rorl $16,%eax
24303+ movb %al,__KERNEL_PERCPU + 4(%edi)
24304+ movb %ah,__KERNEL_PERCPU + 7(%edi)
24305+ movl $__per_cpu_end - 1,%eax
24306+ subl $__per_cpu_start,%eax
24307+ movw %ax,__KERNEL_PERCPU + 0(%edi)
24308+#endif
24309 #else
24310 mov %rsi,xen_start_info
24311 mov $init_thread_union+THREAD_SIZE,%rsp
24312diff -urNp linux-2.6.39.1/arch/x86/xen/xen-ops.h linux-2.6.39.1/arch/x86/xen/xen-ops.h
24313--- linux-2.6.39.1/arch/x86/xen/xen-ops.h 2011-05-19 00:06:34.000000000 -0400
24314+++ linux-2.6.39.1/arch/x86/xen/xen-ops.h 2011-05-22 19:36:30.000000000 -0400
24315@@ -10,8 +10,6 @@
24316 extern const char xen_hypervisor_callback[];
24317 extern const char xen_failsafe_callback[];
24318
24319-extern void *xen_initial_gdt;
24320-
24321 struct trap_info;
24322 void xen_copy_trap_info(struct trap_info *traps);
24323
24324diff -urNp linux-2.6.39.1/block/blk-iopoll.c linux-2.6.39.1/block/blk-iopoll.c
24325--- linux-2.6.39.1/block/blk-iopoll.c 2011-05-19 00:06:34.000000000 -0400
24326+++ linux-2.6.39.1/block/blk-iopoll.c 2011-05-22 19:36:30.000000000 -0400
24327@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
24328 }
24329 EXPORT_SYMBOL(blk_iopoll_complete);
24330
24331-static void blk_iopoll_softirq(struct softirq_action *h)
24332+static void blk_iopoll_softirq(void)
24333 {
24334 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24335 int rearm = 0, budget = blk_iopoll_budget;
24336diff -urNp linux-2.6.39.1/block/blk-map.c linux-2.6.39.1/block/blk-map.c
24337--- linux-2.6.39.1/block/blk-map.c 2011-05-19 00:06:34.000000000 -0400
24338+++ linux-2.6.39.1/block/blk-map.c 2011-05-22 19:36:30.000000000 -0400
24339@@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
24340 if (!len || !kbuf)
24341 return -EINVAL;
24342
24343- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24344+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24345 if (do_copy)
24346 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24347 else
24348diff -urNp linux-2.6.39.1/block/blk-softirq.c linux-2.6.39.1/block/blk-softirq.c
24349--- linux-2.6.39.1/block/blk-softirq.c 2011-05-19 00:06:34.000000000 -0400
24350+++ linux-2.6.39.1/block/blk-softirq.c 2011-05-22 19:36:30.000000000 -0400
24351@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
24352 * Softirq action handler - move entries to local list and loop over them
24353 * while passing them to the queue registered handler.
24354 */
24355-static void blk_done_softirq(struct softirq_action *h)
24356+static void blk_done_softirq(void)
24357 {
24358 struct list_head *cpu_list, local_list;
24359
24360diff -urNp linux-2.6.39.1/block/bsg.c linux-2.6.39.1/block/bsg.c
24361--- linux-2.6.39.1/block/bsg.c 2011-05-19 00:06:34.000000000 -0400
24362+++ linux-2.6.39.1/block/bsg.c 2011-05-22 19:36:30.000000000 -0400
24363@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
24364 struct sg_io_v4 *hdr, struct bsg_device *bd,
24365 fmode_t has_write_perm)
24366 {
24367+ unsigned char tmpcmd[sizeof(rq->__cmd)];
24368+ unsigned char *cmdptr;
24369+
24370 if (hdr->request_len > BLK_MAX_CDB) {
24371 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24372 if (!rq->cmd)
24373 return -ENOMEM;
24374- }
24375+ cmdptr = rq->cmd;
24376+ } else
24377+ cmdptr = tmpcmd;
24378
24379- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
24380+ if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
24381 hdr->request_len))
24382 return -EFAULT;
24383
24384+ if (cmdptr != rq->cmd)
24385+ memcpy(rq->cmd, cmdptr, hdr->request_len);
24386+
24387 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24388 if (blk_verify_command(rq->cmd, has_write_perm))
24389 return -EPERM;
24390diff -urNp linux-2.6.39.1/block/scsi_ioctl.c linux-2.6.39.1/block/scsi_ioctl.c
24391--- linux-2.6.39.1/block/scsi_ioctl.c 2011-05-19 00:06:34.000000000 -0400
24392+++ linux-2.6.39.1/block/scsi_ioctl.c 2011-05-22 19:36:30.000000000 -0400
24393@@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
24394 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24395 struct sg_io_hdr *hdr, fmode_t mode)
24396 {
24397- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24398+ unsigned char tmpcmd[sizeof(rq->__cmd)];
24399+ unsigned char *cmdptr;
24400+
24401+ if (rq->cmd != rq->__cmd)
24402+ cmdptr = rq->cmd;
24403+ else
24404+ cmdptr = tmpcmd;
24405+
24406+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24407 return -EFAULT;
24408+
24409+ if (cmdptr != rq->cmd)
24410+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24411+
24412 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24413 return -EPERM;
24414
24415@@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *
24416 int err;
24417 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24418 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24419+ unsigned char tmpcmd[sizeof(rq->__cmd)];
24420+ unsigned char *cmdptr;
24421
24422 if (!sic)
24423 return -EINVAL;
24424@@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *
24425 */
24426 err = -EFAULT;
24427 rq->cmd_len = cmdlen;
24428- if (copy_from_user(rq->cmd, sic->data, cmdlen))
24429+
24430+ if (rq->cmd != rq->__cmd)
24431+ cmdptr = rq->cmd;
24432+ else
24433+ cmdptr = tmpcmd;
24434+
24435+ if (copy_from_user(cmdptr, sic->data, cmdlen))
24436 goto error;
24437
24438+ if (rq->cmd != cmdptr)
24439+ memcpy(rq->cmd, cmdptr, cmdlen);
24440+
24441 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
24442 goto error;
24443
24444diff -urNp linux-2.6.39.1/crypto/serpent.c linux-2.6.39.1/crypto/serpent.c
24445--- linux-2.6.39.1/crypto/serpent.c 2011-05-19 00:06:34.000000000 -0400
24446+++ linux-2.6.39.1/crypto/serpent.c 2011-05-22 19:36:30.000000000 -0400
24447@@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24448 u32 r0,r1,r2,r3,r4;
24449 int i;
24450
24451+ pax_track_stack();
24452+
24453 /* Copy key, add padding */
24454
24455 for (i = 0; i < keylen; ++i)
24456diff -urNp linux-2.6.39.1/Documentation/dontdiff linux-2.6.39.1/Documentation/dontdiff
24457--- linux-2.6.39.1/Documentation/dontdiff 2011-05-19 00:06:34.000000000 -0400
24458+++ linux-2.6.39.1/Documentation/dontdiff 2011-05-22 19:36:30.000000000 -0400
24459@@ -1,13 +1,16 @@
24460 *.a
24461 *.aux
24462 *.bin
24463+*.cis
24464 *.cpio
24465 *.csp
24466+*.dbg
24467 *.dsp
24468 *.dvi
24469 *.elf
24470 *.eps
24471 *.fw
24472+*.gcno
24473 *.gen.S
24474 *.gif
24475 *.grep
24476@@ -38,8 +41,10 @@
24477 *.tab.h
24478 *.tex
24479 *.ver
24480+*.vim
24481 *.xml
24482 *_MODULES
24483+*_reg_safe.h
24484 *_vga16.c
24485 *~
24486 *.9
24487@@ -49,11 +54,16 @@
24488 53c700_d.h
24489 CVS
24490 ChangeSet
24491+GPATH
24492+GRTAGS
24493+GSYMS
24494+GTAGS
24495 Image
24496 Kerntypes
24497 Module.markers
24498 Module.symvers
24499 PENDING
24500+PERF*
24501 SCCS
24502 System.map*
24503 TAGS
24504@@ -80,8 +90,11 @@ btfixupprep
24505 build
24506 bvmlinux
24507 bzImage*
24508+capability_names.h
24509 capflags.c
24510 classlist.h*
24511+clut_vga16.c
24512+common-cmds.h
24513 comp*.log
24514 compile.h*
24515 conf
24516@@ -106,16 +119,19 @@ fore200e_mkfirm
24517 fore200e_pca_fw.c*
24518 gconf
24519 gen-devlist
24520+gen-kdb_cmds.c
24521 gen_crc32table
24522 gen_init_cpio
24523 generated
24524 genheaders
24525 genksyms
24526 *_gray256.c
24527+hash
24528 ihex2fw
24529 ikconfig.h*
24530 inat-tables.c
24531 initramfs_data.cpio
24532+initramfs_data.cpio.bz2
24533 initramfs_data.cpio.gz
24534 initramfs_list
24535 int16.c
24536@@ -125,7 +141,6 @@ int32.c
24537 int4.c
24538 int8.c
24539 kallsyms
24540-kconfig
24541 keywords.c
24542 ksym.c*
24543 ksym.h*
24544@@ -149,7 +164,9 @@ mkboot
24545 mkbugboot
24546 mkcpustr
24547 mkdep
24548+mkpiggy
24549 mkprep
24550+mkregtable
24551 mktables
24552 mktree
24553 modpost
24554@@ -165,6 +182,7 @@ parse.h
24555 patches*
24556 pca200e.bin
24557 pca200e_ecd.bin2
24558+perf-archive
24559 piggy.gz
24560 piggyback
24561 piggy.S
24562@@ -180,7 +198,9 @@ r600_reg_safe.h
24563 raid6altivec*.c
24564 raid6int*.c
24565 raid6tables.c
24566+regdb.c
24567 relocs
24568+rlim_names.h
24569 rn50_reg_safe.h
24570 rs600_reg_safe.h
24571 rv515_reg_safe.h
24572@@ -189,6 +209,7 @@ setup
24573 setup.bin
24574 setup.elf
24575 sImage
24576+slabinfo
24577 sm_tbl*
24578 split-include
24579 syscalltab.h
24580@@ -213,13 +234,17 @@ version.h*
24581 vmlinux
24582 vmlinux-*
24583 vmlinux.aout
24584+vmlinux.bin.all
24585+vmlinux.bin.bz2
24586 vmlinux.lds
24587+vmlinux.relocs
24588 voffset.h
24589 vsyscall.lds
24590 vsyscall_32.lds
24591 wanxlfw.inc
24592 uImage
24593 unifdef
24594+utsrelease.h
24595 wakeup.bin
24596 wakeup.elf
24597 wakeup.lds
24598diff -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
24599--- linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-19 00:06:34.000000000 -0400
24600+++ linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-22 19:36:30.000000000 -0400
24601@@ -368,7 +368,7 @@ static struct configfs_item_operations g
24602 * Note that, since no extra work is required on ->drop_item(),
24603 * no ->drop_item() is provided.
24604 */
24605-static struct configfs_group_operations group_children_group_ops = {
24606+static const struct configfs_group_operations group_children_group_ops = {
24607 .make_group = group_children_make_group,
24608 };
24609
24610diff -urNp linux-2.6.39.1/Documentation/filesystems/sysfs.txt linux-2.6.39.1/Documentation/filesystems/sysfs.txt
24611--- linux-2.6.39.1/Documentation/filesystems/sysfs.txt 2011-05-19 00:06:34.000000000 -0400
24612+++ linux-2.6.39.1/Documentation/filesystems/sysfs.txt 2011-05-22 19:36:30.000000000 -0400
24613@@ -125,8 +125,8 @@ set of sysfs operations for forwarding r
24614 show and store methods of the attribute owners.
24615
24616 struct sysfs_ops {
24617- ssize_t (*show)(struct kobject *, struct attribute *, char *);
24618- ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
24619+ ssize_t (* const show)(struct kobject *, struct attribute *, char *);
24620+ ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
24621 };
24622
24623 [ Subsystems should have already defined a struct kobj_type as a
24624diff -urNp linux-2.6.39.1/Documentation/kernel-parameters.txt linux-2.6.39.1/Documentation/kernel-parameters.txt
24625--- linux-2.6.39.1/Documentation/kernel-parameters.txt 2011-05-19 00:06:34.000000000 -0400
24626+++ linux-2.6.39.1/Documentation/kernel-parameters.txt 2011-05-22 19:36:30.000000000 -0400
24627@@ -1879,6 +1879,13 @@ bytes respectively. Such letter suffixes
24628 the specified number of seconds. This is to be used if
24629 your oopses keep scrolling off the screen.
24630
24631+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24632+ virtualization environments that don't cope well with the
24633+ expand down segment used by UDEREF on X86-32 or the frequent
24634+ page table updates on X86-64.
24635+
24636+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24637+
24638 pcbit= [HW,ISDN]
24639
24640 pcd. [PARIDE]
24641diff -urNp linux-2.6.39.1/drivers/acpi/acpi_ipmi.c linux-2.6.39.1/drivers/acpi/acpi_ipmi.c
24642--- linux-2.6.39.1/drivers/acpi/acpi_ipmi.c 2011-05-19 00:06:34.000000000 -0400
24643+++ linux-2.6.39.1/drivers/acpi/acpi_ipmi.c 2011-05-22 19:36:30.000000000 -0400
24644@@ -70,7 +70,7 @@ struct acpi_ipmi_device {
24645 struct ipmi_driver_data {
24646 struct list_head ipmi_devices;
24647 struct ipmi_smi_watcher bmc_events;
24648- struct ipmi_user_hndl ipmi_hndlrs;
24649+ const struct ipmi_user_hndl ipmi_hndlrs;
24650 struct mutex ipmi_lock;
24651 };
24652
24653diff -urNp linux-2.6.39.1/drivers/acpi/apei/cper.c linux-2.6.39.1/drivers/acpi/apei/cper.c
24654--- linux-2.6.39.1/drivers/acpi/apei/cper.c 2011-05-19 00:06:34.000000000 -0400
24655+++ linux-2.6.39.1/drivers/acpi/apei/cper.c 2011-05-22 19:36:30.000000000 -0400
24656@@ -38,12 +38,12 @@
24657 */
24658 u64 cper_next_record_id(void)
24659 {
24660- static atomic64_t seq;
24661+ static atomic64_unchecked_t seq;
24662
24663- if (!atomic64_read(&seq))
24664- atomic64_set(&seq, ((u64)get_seconds()) << 32);
24665+ if (!atomic64_read_unchecked(&seq))
24666+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
24667
24668- return atomic64_inc_return(&seq);
24669+ return atomic64_inc_return_unchecked(&seq);
24670 }
24671 EXPORT_SYMBOL_GPL(cper_next_record_id);
24672
24673diff -urNp linux-2.6.39.1/drivers/acpi/battery.c linux-2.6.39.1/drivers/acpi/battery.c
24674--- linux-2.6.39.1/drivers/acpi/battery.c 2011-05-19 00:06:34.000000000 -0400
24675+++ linux-2.6.39.1/drivers/acpi/battery.c 2011-05-22 19:36:30.000000000 -0400
24676@@ -864,7 +864,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24677 }
24678
24679 static struct battery_file {
24680- struct file_operations ops;
24681+ const struct file_operations ops;
24682 mode_t mode;
24683 const char *name;
24684 } acpi_battery_file[] = {
24685diff -urNp linux-2.6.39.1/drivers/acpi/dock.c linux-2.6.39.1/drivers/acpi/dock.c
24686--- linux-2.6.39.1/drivers/acpi/dock.c 2011-05-19 00:06:34.000000000 -0400
24687+++ linux-2.6.39.1/drivers/acpi/dock.c 2011-05-22 19:36:30.000000000 -0400
24688@@ -77,7 +77,7 @@ struct dock_dependent_device {
24689 struct list_head list;
24690 struct list_head hotplug_list;
24691 acpi_handle handle;
24692- struct acpi_dock_ops *ops;
24693+ const struct acpi_dock_ops *ops;
24694 void *context;
24695 };
24696
24697@@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24698 * the dock driver after _DCK is executed.
24699 */
24700 int
24701-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24702+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24703 void *context)
24704 {
24705 struct dock_dependent_device *dd;
24706diff -urNp linux-2.6.39.1/drivers/acpi/ec_sys.c linux-2.6.39.1/drivers/acpi/ec_sys.c
24707--- linux-2.6.39.1/drivers/acpi/ec_sys.c 2011-05-19 00:06:34.000000000 -0400
24708+++ linux-2.6.39.1/drivers/acpi/ec_sys.c 2011-05-22 19:36:30.000000000 -0400
24709@@ -92,7 +92,7 @@ static ssize_t acpi_ec_write_io(struct f
24710 return count;
24711 }
24712
24713-static struct file_operations acpi_ec_io_ops = {
24714+static const struct file_operations acpi_ec_io_ops = {
24715 .owner = THIS_MODULE,
24716 .open = acpi_ec_open_io,
24717 .read = acpi_ec_read_io,
24718diff -urNp linux-2.6.39.1/drivers/acpi/fan.c linux-2.6.39.1/drivers/acpi/fan.c
24719--- linux-2.6.39.1/drivers/acpi/fan.c 2011-05-19 00:06:34.000000000 -0400
24720+++ linux-2.6.39.1/drivers/acpi/fan.c 2011-05-22 19:36:30.000000000 -0400
24721@@ -110,7 +110,7 @@ fan_set_cur_state(struct thermal_cooling
24722 return result;
24723 }
24724
24725-static struct thermal_cooling_device_ops fan_cooling_ops = {
24726+static const struct thermal_cooling_device_ops fan_cooling_ops = {
24727 .get_max_state = fan_get_max_state,
24728 .get_cur_state = fan_get_cur_state,
24729 .set_cur_state = fan_set_cur_state,
24730diff -urNp linux-2.6.39.1/drivers/acpi/power_meter.c linux-2.6.39.1/drivers/acpi/power_meter.c
24731--- linux-2.6.39.1/drivers/acpi/power_meter.c 2011-05-19 00:06:34.000000000 -0400
24732+++ linux-2.6.39.1/drivers/acpi/power_meter.c 2011-05-22 19:36:30.000000000 -0400
24733@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
24734 return res;
24735
24736 temp /= 1000;
24737- if (temp < 0)
24738- return -EINVAL;
24739
24740 mutex_lock(&resource->lock);
24741 resource->trip[attr->index - 7] = temp;
24742diff -urNp linux-2.6.39.1/drivers/acpi/proc.c linux-2.6.39.1/drivers/acpi/proc.c
24743--- linux-2.6.39.1/drivers/acpi/proc.c 2011-05-19 00:06:34.000000000 -0400
24744+++ linux-2.6.39.1/drivers/acpi/proc.c 2011-05-22 19:36:30.000000000 -0400
24745@@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct f
24746 size_t count, loff_t * ppos)
24747 {
24748 struct list_head *node, *next;
24749- char strbuf[5];
24750- char str[5] = "";
24751- unsigned int len = count;
24752-
24753- if (len > 4)
24754- len = 4;
24755- if (len < 0)
24756- return -EFAULT;
24757+ char strbuf[5] = {0};
24758
24759- if (copy_from_user(strbuf, buffer, len))
24760+ if (count > 4)
24761+ count = 4;
24762+ if (copy_from_user(strbuf, buffer, count))
24763 return -EFAULT;
24764- strbuf[len] = '\0';
24765- sscanf(strbuf, "%s", str);
24766+ strbuf[count] = '\0';
24767
24768 mutex_lock(&acpi_device_lock);
24769 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24770@@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct f
24771 if (!dev->wakeup.flags.valid)
24772 continue;
24773
24774- if (!strncmp(dev->pnp.bus_id, str, 4)) {
24775+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24776 if (device_can_wakeup(&dev->dev)) {
24777 bool enable = !device_may_wakeup(&dev->dev);
24778 device_set_wakeup_enable(&dev->dev, enable);
24779diff -urNp linux-2.6.39.1/drivers/acpi/processor_driver.c linux-2.6.39.1/drivers/acpi/processor_driver.c
24780--- linux-2.6.39.1/drivers/acpi/processor_driver.c 2011-05-19 00:06:34.000000000 -0400
24781+++ linux-2.6.39.1/drivers/acpi/processor_driver.c 2011-05-22 19:36:30.000000000 -0400
24782@@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(
24783 return 0;
24784 #endif
24785
24786- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24787+ BUG_ON(pr->id >= nr_cpu_ids);
24788
24789 /*
24790 * Buggy BIOS check
24791diff -urNp linux-2.6.39.1/drivers/acpi/processor_idle.c linux-2.6.39.1/drivers/acpi/processor_idle.c
24792--- linux-2.6.39.1/drivers/acpi/processor_idle.c 2011-05-19 00:06:34.000000000 -0400
24793+++ linux-2.6.39.1/drivers/acpi/processor_idle.c 2011-05-22 19:36:30.000000000 -0400
24794@@ -121,7 +121,7 @@ static struct dmi_system_id __cpuinitdat
24795 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
24796 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
24797 (void *)1},
24798- {},
24799+ {}
24800 };
24801
24802
24803diff -urNp linux-2.6.39.1/drivers/acpi/processor_thermal.c linux-2.6.39.1/drivers/acpi/processor_thermal.c
24804--- linux-2.6.39.1/drivers/acpi/processor_thermal.c 2011-05-19 00:06:34.000000000 -0400
24805+++ linux-2.6.39.1/drivers/acpi/processor_thermal.c 2011-05-22 19:36:30.000000000 -0400
24806@@ -244,7 +244,7 @@ processor_set_cur_state(struct thermal_c
24807 return result;
24808 }
24809
24810-struct thermal_cooling_device_ops processor_cooling_ops = {
24811+const struct thermal_cooling_device_ops processor_cooling_ops = {
24812 .get_max_state = processor_get_max_state,
24813 .get_cur_state = processor_get_cur_state,
24814 .set_cur_state = processor_set_cur_state,
24815diff -urNp linux-2.6.39.1/drivers/acpi/sysfs.c linux-2.6.39.1/drivers/acpi/sysfs.c
24816--- linux-2.6.39.1/drivers/acpi/sysfs.c 2011-05-19 00:06:34.000000000 -0400
24817+++ linux-2.6.39.1/drivers/acpi/sysfs.c 2011-05-22 19:36:30.000000000 -0400
24818@@ -149,12 +149,12 @@ static int param_get_debug_level(char *b
24819 return result;
24820 }
24821
24822-static struct kernel_param_ops param_ops_debug_layer = {
24823+static const struct kernel_param_ops param_ops_debug_layer = {
24824 .set = param_set_uint,
24825 .get = param_get_debug_layer,
24826 };
24827
24828-static struct kernel_param_ops param_ops_debug_level = {
24829+static const struct kernel_param_ops param_ops_debug_level = {
24830 .set = param_set_uint,
24831 .get = param_get_debug_level,
24832 };
24833diff -urNp linux-2.6.39.1/drivers/acpi/thermal.c linux-2.6.39.1/drivers/acpi/thermal.c
24834--- linux-2.6.39.1/drivers/acpi/thermal.c 2011-05-19 00:06:34.000000000 -0400
24835+++ linux-2.6.39.1/drivers/acpi/thermal.c 2011-05-22 19:36:30.000000000 -0400
24836@@ -812,7 +812,7 @@ acpi_thermal_unbind_cooling_device(struc
24837 thermal_zone_unbind_cooling_device);
24838 }
24839
24840-static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24841+static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24842 .bind = acpi_thermal_bind_cooling_device,
24843 .unbind = acpi_thermal_unbind_cooling_device,
24844 .get_temp = thermal_get_temp,
24845diff -urNp linux-2.6.39.1/drivers/acpi/video.c linux-2.6.39.1/drivers/acpi/video.c
24846--- linux-2.6.39.1/drivers/acpi/video.c 2011-05-19 00:06:34.000000000 -0400
24847+++ linux-2.6.39.1/drivers/acpi/video.c 2011-05-22 19:36:30.000000000 -0400
24848@@ -308,7 +308,7 @@ video_set_cur_state(struct thermal_cooli
24849 return acpi_video_device_lcd_set_level(video, level);
24850 }
24851
24852-static struct thermal_cooling_device_ops video_cooling_ops = {
24853+static const struct thermal_cooling_device_ops video_cooling_ops = {
24854 .get_max_state = video_get_max_state,
24855 .get_cur_state = video_get_cur_state,
24856 .set_cur_state = video_set_cur_state,
24857diff -urNp linux-2.6.39.1/drivers/ata/acard-ahci.c linux-2.6.39.1/drivers/ata/acard-ahci.c
24858--- linux-2.6.39.1/drivers/ata/acard-ahci.c 2011-05-19 00:06:34.000000000 -0400
24859+++ linux-2.6.39.1/drivers/ata/acard-ahci.c 2011-05-22 19:36:30.000000000 -0400
24860@@ -87,7 +87,7 @@ static struct scsi_host_template acard_a
24861 AHCI_SHT("acard-ahci"),
24862 };
24863
24864-static struct ata_port_operations acard_ops = {
24865+static const struct ata_port_operations acard_ops = {
24866 .inherits = &ahci_ops,
24867 .qc_prep = acard_ahci_qc_prep,
24868 .qc_fill_rtf = acard_ahci_qc_fill_rtf,
24869diff -urNp linux-2.6.39.1/drivers/ata/ahci.c linux-2.6.39.1/drivers/ata/ahci.c
24870--- linux-2.6.39.1/drivers/ata/ahci.c 2011-05-19 00:06:34.000000000 -0400
24871+++ linux-2.6.39.1/drivers/ata/ahci.c 2011-05-22 19:36:30.000000000 -0400
24872@@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
24873 AHCI_SHT("ahci"),
24874 };
24875
24876-static struct ata_port_operations ahci_vt8251_ops = {
24877+static const struct ata_port_operations ahci_vt8251_ops = {
24878 .inherits = &ahci_ops,
24879 .hardreset = ahci_vt8251_hardreset,
24880 };
24881
24882-static struct ata_port_operations ahci_p5wdh_ops = {
24883+static const struct ata_port_operations ahci_p5wdh_ops = {
24884 .inherits = &ahci_ops,
24885 .hardreset = ahci_p5wdh_hardreset,
24886 };
24887
24888-static struct ata_port_operations ahci_sb600_ops = {
24889+static const struct ata_port_operations ahci_sb600_ops = {
24890 .inherits = &ahci_ops,
24891 .softreset = ahci_sb600_softreset,
24892 .pmp_softreset = ahci_sb600_softreset,
24893diff -urNp linux-2.6.39.1/drivers/ata/ahci.h linux-2.6.39.1/drivers/ata/ahci.h
24894--- linux-2.6.39.1/drivers/ata/ahci.h 2011-05-19 00:06:34.000000000 -0400
24895+++ linux-2.6.39.1/drivers/ata/ahci.h 2011-05-22 19:36:30.000000000 -0400
24896@@ -311,7 +311,7 @@ extern struct device_attribute *ahci_sde
24897 .shost_attrs = ahci_shost_attrs, \
24898 .sdev_attrs = ahci_sdev_attrs
24899
24900-extern struct ata_port_operations ahci_ops;
24901+extern const struct ata_port_operations ahci_ops;
24902
24903 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
24904 u32 opts);
24905diff -urNp linux-2.6.39.1/drivers/ata/ata_generic.c linux-2.6.39.1/drivers/ata/ata_generic.c
24906--- linux-2.6.39.1/drivers/ata/ata_generic.c 2011-05-19 00:06:34.000000000 -0400
24907+++ linux-2.6.39.1/drivers/ata/ata_generic.c 2011-05-22 19:36:30.000000000 -0400
24908@@ -101,7 +101,7 @@ static struct scsi_host_template generic
24909 ATA_BMDMA_SHT(DRV_NAME),
24910 };
24911
24912-static struct ata_port_operations generic_port_ops = {
24913+static const struct ata_port_operations generic_port_ops = {
24914 .inherits = &ata_bmdma_port_ops,
24915 .cable_detect = ata_cable_unknown,
24916 .set_mode = generic_set_mode,
24917diff -urNp linux-2.6.39.1/drivers/ata/ata_piix.c linux-2.6.39.1/drivers/ata/ata_piix.c
24918--- linux-2.6.39.1/drivers/ata/ata_piix.c 2011-05-19 00:06:34.000000000 -0400
24919+++ linux-2.6.39.1/drivers/ata/ata_piix.c 2011-05-22 19:36:30.000000000 -0400
24920@@ -335,12 +335,12 @@ static struct scsi_host_template piix_sh
24921 ATA_BMDMA_SHT(DRV_NAME),
24922 };
24923
24924-static struct ata_port_operations piix_sata_ops = {
24925+static const struct ata_port_operations piix_sata_ops = {
24926 .inherits = &ata_bmdma32_port_ops,
24927 .sff_irq_check = piix_irq_check,
24928 };
24929
24930-static struct ata_port_operations piix_pata_ops = {
24931+static const struct ata_port_operations piix_pata_ops = {
24932 .inherits = &piix_sata_ops,
24933 .cable_detect = ata_cable_40wire,
24934 .set_piomode = piix_set_piomode,
24935@@ -348,12 +348,12 @@ static struct ata_port_operations piix_p
24936 .prereset = piix_pata_prereset,
24937 };
24938
24939-static struct ata_port_operations piix_vmw_ops = {
24940+static const struct ata_port_operations piix_vmw_ops = {
24941 .inherits = &piix_pata_ops,
24942 .bmdma_status = piix_vmw_bmdma_status,
24943 };
24944
24945-static struct ata_port_operations ich_pata_ops = {
24946+static const struct ata_port_operations ich_pata_ops = {
24947 .inherits = &piix_pata_ops,
24948 .cable_detect = ich_pata_cable_detect,
24949 .set_dmamode = ich_set_dmamode,
24950@@ -369,7 +369,7 @@ static struct scsi_host_template piix_si
24951 .shost_attrs = piix_sidpr_shost_attrs,
24952 };
24953
24954-static struct ata_port_operations piix_sidpr_sata_ops = {
24955+static const struct ata_port_operations piix_sidpr_sata_ops = {
24956 .inherits = &piix_sata_ops,
24957 .hardreset = sata_std_hardreset,
24958 .scr_read = piix_sidpr_scr_read,
24959diff -urNp linux-2.6.39.1/drivers/ata/libahci.c linux-2.6.39.1/drivers/ata/libahci.c
24960--- linux-2.6.39.1/drivers/ata/libahci.c 2011-05-19 00:06:34.000000000 -0400
24961+++ linux-2.6.39.1/drivers/ata/libahci.c 2011-05-22 19:36:30.000000000 -0400
24962@@ -141,7 +141,7 @@ struct device_attribute *ahci_sdev_attrs
24963 };
24964 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
24965
24966-struct ata_port_operations ahci_ops = {
24967+const struct ata_port_operations ahci_ops = {
24968 .inherits = &sata_pmp_port_ops,
24969
24970 .qc_defer = ahci_pmp_qc_defer,
24971diff -urNp linux-2.6.39.1/drivers/ata/libata-acpi.c linux-2.6.39.1/drivers/ata/libata-acpi.c
24972--- linux-2.6.39.1/drivers/ata/libata-acpi.c 2011-05-19 00:06:34.000000000 -0400
24973+++ linux-2.6.39.1/drivers/ata/libata-acpi.c 2011-05-22 19:36:30.000000000 -0400
24974@@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
24975 ata_acpi_uevent(dev->link->ap, dev, event);
24976 }
24977
24978-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24979+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24980 .handler = ata_acpi_dev_notify_dock,
24981 .uevent = ata_acpi_dev_uevent,
24982 };
24983
24984-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24985+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24986 .handler = ata_acpi_ap_notify_dock,
24987 .uevent = ata_acpi_ap_uevent,
24988 };
24989diff -urNp linux-2.6.39.1/drivers/ata/libata-core.c linux-2.6.39.1/drivers/ata/libata-core.c
24990--- linux-2.6.39.1/drivers/ata/libata-core.c 2011-05-19 00:06:34.000000000 -0400
24991+++ linux-2.6.39.1/drivers/ata/libata-core.c 2011-05-22 19:36:30.000000000 -0400
24992@@ -4747,7 +4747,7 @@ void ata_qc_free(struct ata_queued_cmd *
24993 struct ata_port *ap;
24994 unsigned int tag;
24995
24996- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24997+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24998 ap = qc->ap;
24999
25000 qc->flags = 0;
25001@@ -4763,7 +4763,7 @@ void __ata_qc_complete(struct ata_queued
25002 struct ata_port *ap;
25003 struct ata_link *link;
25004
25005- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25006+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25007 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25008 ap = qc->ap;
25009 link = qc->dev->link;
25010@@ -5756,7 +5756,7 @@ static void ata_host_stop(struct device
25011 * LOCKING:
25012 * None.
25013 */
25014-static void ata_finalize_port_ops(struct ata_port_operations *ops)
25015+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
25016 {
25017 static DEFINE_SPINLOCK(lock);
25018 const struct ata_port_operations *cur;
25019@@ -5768,6 +5768,7 @@ static void ata_finalize_port_ops(struct
25020 return;
25021
25022 spin_lock(&lock);
25023+ pax_open_kernel();
25024
25025 for (cur = ops->inherits; cur; cur = cur->inherits) {
25026 void **inherit = (void **)cur;
25027@@ -5781,8 +5782,9 @@ static void ata_finalize_port_ops(struct
25028 if (IS_ERR(*pp))
25029 *pp = NULL;
25030
25031- ops->inherits = NULL;
25032+ ((struct ata_port_operations *)ops)->inherits = NULL;
25033
25034+ pax_close_kernel();
25035 spin_unlock(&lock);
25036 }
25037
25038@@ -5879,7 +5881,7 @@ int ata_host_start(struct ata_host *host
25039 */
25040 /* KILLME - the only user left is ipr */
25041 void ata_host_init(struct ata_host *host, struct device *dev,
25042- unsigned long flags, struct ata_port_operations *ops)
25043+ unsigned long flags, const struct ata_port_operations *ops)
25044 {
25045 spin_lock_init(&host->lock);
25046 mutex_init(&host->eh_mutex);
25047@@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
25048 /* truly dummy */
25049 }
25050
25051-struct ata_port_operations ata_dummy_port_ops = {
25052+const struct ata_port_operations ata_dummy_port_ops = {
25053 .qc_prep = ata_noop_qc_prep,
25054 .qc_issue = ata_dummy_qc_issue,
25055 .error_handler = ata_dummy_error_handler,
25056diff -urNp linux-2.6.39.1/drivers/ata/libata-eh.c linux-2.6.39.1/drivers/ata/libata-eh.c
25057--- linux-2.6.39.1/drivers/ata/libata-eh.c 2011-05-19 00:06:34.000000000 -0400
25058+++ linux-2.6.39.1/drivers/ata/libata-eh.c 2011-05-22 19:36:30.000000000 -0400
25059@@ -2518,6 +2518,8 @@ void ata_eh_report(struct ata_port *ap)
25060 {
25061 struct ata_link *link;
25062
25063+ pax_track_stack();
25064+
25065 ata_for_each_link(link, ap, HOST_FIRST)
25066 ata_eh_link_report(link);
25067 }
25068@@ -3922,7 +3924,7 @@ void ata_do_eh(struct ata_port *ap, ata_
25069 */
25070 void ata_std_error_handler(struct ata_port *ap)
25071 {
25072- struct ata_port_operations *ops = ap->ops;
25073+ const struct ata_port_operations *ops = ap->ops;
25074 ata_reset_fn_t hardreset = ops->hardreset;
25075
25076 /* ignore built-in hardreset if SCR access is not available */
25077diff -urNp linux-2.6.39.1/drivers/ata/libata-pmp.c linux-2.6.39.1/drivers/ata/libata-pmp.c
25078--- linux-2.6.39.1/drivers/ata/libata-pmp.c 2011-05-19 00:06:34.000000000 -0400
25079+++ linux-2.6.39.1/drivers/ata/libata-pmp.c 2011-05-22 19:36:30.000000000 -0400
25080@@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
25081 */
25082 static int sata_pmp_eh_recover(struct ata_port *ap)
25083 {
25084- struct ata_port_operations *ops = ap->ops;
25085+ const struct ata_port_operations *ops = ap->ops;
25086 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
25087 struct ata_link *pmp_link = &ap->link;
25088 struct ata_device *pmp_dev = pmp_link->device;
25089diff -urNp linux-2.6.39.1/drivers/ata/pata_acpi.c linux-2.6.39.1/drivers/ata/pata_acpi.c
25090--- linux-2.6.39.1/drivers/ata/pata_acpi.c 2011-05-19 00:06:34.000000000 -0400
25091+++ linux-2.6.39.1/drivers/ata/pata_acpi.c 2011-05-22 19:36:30.000000000 -0400
25092@@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
25093 ATA_BMDMA_SHT(DRV_NAME),
25094 };
25095
25096-static struct ata_port_operations pacpi_ops = {
25097+static const struct ata_port_operations pacpi_ops = {
25098 .inherits = &ata_bmdma_port_ops,
25099 .qc_issue = pacpi_qc_issue,
25100 .cable_detect = pacpi_cable_detect,
25101diff -urNp linux-2.6.39.1/drivers/ata/pata_ali.c linux-2.6.39.1/drivers/ata/pata_ali.c
25102--- linux-2.6.39.1/drivers/ata/pata_ali.c 2011-05-19 00:06:34.000000000 -0400
25103+++ linux-2.6.39.1/drivers/ata/pata_ali.c 2011-05-22 19:36:30.000000000 -0400
25104@@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
25105 * Port operations for PIO only ALi
25106 */
25107
25108-static struct ata_port_operations ali_early_port_ops = {
25109+static const struct ata_port_operations ali_early_port_ops = {
25110 .inherits = &ata_sff_port_ops,
25111 .cable_detect = ata_cable_40wire,
25112 .set_piomode = ali_set_piomode,
25113@@ -380,7 +380,7 @@ static const struct ata_port_operations
25114 * Port operations for DMA capable ALi without cable
25115 * detect
25116 */
25117-static struct ata_port_operations ali_20_port_ops = {
25118+static const struct ata_port_operations ali_20_port_ops = {
25119 .inherits = &ali_dma_base_ops,
25120 .cable_detect = ata_cable_40wire,
25121 .mode_filter = ali_20_filter,
25122@@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
25123 /*
25124 * Port operations for DMA capable ALi with cable detect
25125 */
25126-static struct ata_port_operations ali_c2_port_ops = {
25127+static const struct ata_port_operations ali_c2_port_ops = {
25128 .inherits = &ali_dma_base_ops,
25129 .check_atapi_dma = ali_check_atapi_dma,
25130 .cable_detect = ali_c2_cable_detect,
25131@@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
25132 /*
25133 * Port operations for DMA capable ALi with cable detect
25134 */
25135-static struct ata_port_operations ali_c4_port_ops = {
25136+static const struct ata_port_operations ali_c4_port_ops = {
25137 .inherits = &ali_dma_base_ops,
25138 .check_atapi_dma = ali_check_atapi_dma,
25139 .cable_detect = ali_c2_cable_detect,
25140@@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
25141 /*
25142 * Port operations for DMA capable ALi with cable detect and LBA48
25143 */
25144-static struct ata_port_operations ali_c5_port_ops = {
25145+static const struct ata_port_operations ali_c5_port_ops = {
25146 .inherits = &ali_dma_base_ops,
25147 .check_atapi_dma = ali_check_atapi_dma,
25148 .dev_config = ali_warn_atapi_dma,
25149diff -urNp linux-2.6.39.1/drivers/ata/pata_amd.c linux-2.6.39.1/drivers/ata/pata_amd.c
25150--- linux-2.6.39.1/drivers/ata/pata_amd.c 2011-05-19 00:06:34.000000000 -0400
25151+++ linux-2.6.39.1/drivers/ata/pata_amd.c 2011-05-22 19:36:31.000000000 -0400
25152@@ -397,28 +397,28 @@ static const struct ata_port_operations
25153 .prereset = amd_pre_reset,
25154 };
25155
25156-static struct ata_port_operations amd33_port_ops = {
25157+static const struct ata_port_operations amd33_port_ops = {
25158 .inherits = &amd_base_port_ops,
25159 .cable_detect = ata_cable_40wire,
25160 .set_piomode = amd33_set_piomode,
25161 .set_dmamode = amd33_set_dmamode,
25162 };
25163
25164-static struct ata_port_operations amd66_port_ops = {
25165+static const struct ata_port_operations amd66_port_ops = {
25166 .inherits = &amd_base_port_ops,
25167 .cable_detect = ata_cable_unknown,
25168 .set_piomode = amd66_set_piomode,
25169 .set_dmamode = amd66_set_dmamode,
25170 };
25171
25172-static struct ata_port_operations amd100_port_ops = {
25173+static const struct ata_port_operations amd100_port_ops = {
25174 .inherits = &amd_base_port_ops,
25175 .cable_detect = ata_cable_unknown,
25176 .set_piomode = amd100_set_piomode,
25177 .set_dmamode = amd100_set_dmamode,
25178 };
25179
25180-static struct ata_port_operations amd133_port_ops = {
25181+static const struct ata_port_operations amd133_port_ops = {
25182 .inherits = &amd_base_port_ops,
25183 .cable_detect = amd_cable_detect,
25184 .set_piomode = amd133_set_piomode,
25185@@ -433,13 +433,13 @@ static const struct ata_port_operations
25186 .host_stop = nv_host_stop,
25187 };
25188
25189-static struct ata_port_operations nv100_port_ops = {
25190+static const struct ata_port_operations nv100_port_ops = {
25191 .inherits = &nv_base_port_ops,
25192 .set_piomode = nv100_set_piomode,
25193 .set_dmamode = nv100_set_dmamode,
25194 };
25195
25196-static struct ata_port_operations nv133_port_ops = {
25197+static const struct ata_port_operations nv133_port_ops = {
25198 .inherits = &nv_base_port_ops,
25199 .set_piomode = nv133_set_piomode,
25200 .set_dmamode = nv133_set_dmamode,
25201diff -urNp linux-2.6.39.1/drivers/ata/pata_arasan_cf.c linux-2.6.39.1/drivers/ata/pata_arasan_cf.c
25202--- linux-2.6.39.1/drivers/ata/pata_arasan_cf.c 2011-05-19 00:06:34.000000000 -0400
25203+++ linux-2.6.39.1/drivers/ata/pata_arasan_cf.c 2011-05-22 19:36:31.000000000 -0400
25204@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(str
25205 /* Handle platform specific quirks */
25206 if (pdata->quirk) {
25207 if (pdata->quirk & CF_BROKEN_PIO) {
25208- ap->ops->set_piomode = NULL;
25209+ pax_open_kernel();
25210+ *(void**)&ap->ops->set_piomode = NULL;
25211+ pax_close_kernel();
25212 ap->pio_mask = 0;
25213 }
25214 if (pdata->quirk & CF_BROKEN_MWDMA)
25215diff -urNp linux-2.6.39.1/drivers/ata/pata_artop.c linux-2.6.39.1/drivers/ata/pata_artop.c
25216--- linux-2.6.39.1/drivers/ata/pata_artop.c 2011-05-19 00:06:34.000000000 -0400
25217+++ linux-2.6.39.1/drivers/ata/pata_artop.c 2011-05-22 19:36:31.000000000 -0400
25218@@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
25219 ATA_BMDMA_SHT(DRV_NAME),
25220 };
25221
25222-static struct ata_port_operations artop6210_ops = {
25223+static const struct ata_port_operations artop6210_ops = {
25224 .inherits = &ata_bmdma_port_ops,
25225 .cable_detect = ata_cable_40wire,
25226 .set_piomode = artop6210_set_piomode,
25227@@ -321,7 +321,7 @@ static struct ata_port_operations artop6
25228 .qc_defer = artop6210_qc_defer,
25229 };
25230
25231-static struct ata_port_operations artop6260_ops = {
25232+static const struct ata_port_operations artop6260_ops = {
25233 .inherits = &ata_bmdma_port_ops,
25234 .cable_detect = artop6260_cable_detect,
25235 .set_piomode = artop6260_set_piomode,
25236diff -urNp linux-2.6.39.1/drivers/ata/pata_at32.c linux-2.6.39.1/drivers/ata/pata_at32.c
25237--- linux-2.6.39.1/drivers/ata/pata_at32.c 2011-05-19 00:06:34.000000000 -0400
25238+++ linux-2.6.39.1/drivers/ata/pata_at32.c 2011-05-22 19:36:31.000000000 -0400
25239@@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
25240 ATA_PIO_SHT(DRV_NAME),
25241 };
25242
25243-static struct ata_port_operations at32_port_ops = {
25244+static const struct ata_port_operations at32_port_ops = {
25245 .inherits = &ata_sff_port_ops,
25246 .cable_detect = ata_cable_40wire,
25247 .set_piomode = pata_at32_set_piomode,
25248diff -urNp linux-2.6.39.1/drivers/ata/pata_at91.c linux-2.6.39.1/drivers/ata/pata_at91.c
25249--- linux-2.6.39.1/drivers/ata/pata_at91.c 2011-05-19 00:06:34.000000000 -0400
25250+++ linux-2.6.39.1/drivers/ata/pata_at91.c 2011-05-22 19:36:31.000000000 -0400
25251@@ -212,7 +212,7 @@ static struct scsi_host_template pata_at
25252 ATA_PIO_SHT(DRV_NAME),
25253 };
25254
25255-static struct ata_port_operations pata_at91_port_ops = {
25256+static const struct ata_port_operations pata_at91_port_ops = {
25257 .inherits = &ata_sff_port_ops,
25258
25259 .sff_data_xfer = pata_at91_data_xfer_noirq,
25260diff -urNp linux-2.6.39.1/drivers/ata/pata_atiixp.c linux-2.6.39.1/drivers/ata/pata_atiixp.c
25261--- linux-2.6.39.1/drivers/ata/pata_atiixp.c 2011-05-19 00:06:34.000000000 -0400
25262+++ linux-2.6.39.1/drivers/ata/pata_atiixp.c 2011-05-22 19:36:31.000000000 -0400
25263@@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
25264 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25265 };
25266
25267-static struct ata_port_operations atiixp_port_ops = {
25268+static const struct ata_port_operations atiixp_port_ops = {
25269 .inherits = &ata_bmdma_port_ops,
25270
25271 .qc_prep = ata_bmdma_dumb_qc_prep,
25272diff -urNp linux-2.6.39.1/drivers/ata/pata_atp867x.c linux-2.6.39.1/drivers/ata/pata_atp867x.c
25273--- linux-2.6.39.1/drivers/ata/pata_atp867x.c 2011-05-19 00:06:34.000000000 -0400
25274+++ linux-2.6.39.1/drivers/ata/pata_atp867x.c 2011-05-22 19:36:31.000000000 -0400
25275@@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
25276 ATA_BMDMA_SHT(DRV_NAME),
25277 };
25278
25279-static struct ata_port_operations atp867x_ops = {
25280+static const struct ata_port_operations atp867x_ops = {
25281 .inherits = &ata_bmdma_port_ops,
25282 .cable_detect = atp867x_cable_detect,
25283 .set_piomode = atp867x_set_piomode,
25284diff -urNp linux-2.6.39.1/drivers/ata/pata_bf54x.c linux-2.6.39.1/drivers/ata/pata_bf54x.c
25285--- linux-2.6.39.1/drivers/ata/pata_bf54x.c 2011-05-19 00:06:34.000000000 -0400
25286+++ linux-2.6.39.1/drivers/ata/pata_bf54x.c 2011-05-22 19:36:31.000000000 -0400
25287@@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
25288 .dma_boundary = ATA_DMA_BOUNDARY,
25289 };
25290
25291-static struct ata_port_operations bfin_pata_ops = {
25292+static const struct ata_port_operations bfin_pata_ops = {
25293 .inherits = &ata_bmdma_port_ops,
25294
25295 .set_piomode = bfin_set_piomode,
25296diff -urNp linux-2.6.39.1/drivers/ata/pata_cmd640.c linux-2.6.39.1/drivers/ata/pata_cmd640.c
25297--- linux-2.6.39.1/drivers/ata/pata_cmd640.c 2011-05-19 00:06:34.000000000 -0400
25298+++ linux-2.6.39.1/drivers/ata/pata_cmd640.c 2011-05-22 19:36:31.000000000 -0400
25299@@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
25300 ATA_PIO_SHT(DRV_NAME),
25301 };
25302
25303-static struct ata_port_operations cmd640_port_ops = {
25304+static const struct ata_port_operations cmd640_port_ops = {
25305 .inherits = &ata_sff_port_ops,
25306 /* In theory xfer_noirq is not needed once we kill the prefetcher */
25307 .sff_data_xfer = ata_sff_data_xfer_noirq,
25308diff -urNp linux-2.6.39.1/drivers/ata/pata_cmd64x.c linux-2.6.39.1/drivers/ata/pata_cmd64x.c
25309--- linux-2.6.39.1/drivers/ata/pata_cmd64x.c 2011-06-03 00:04:13.000000000 -0400
25310+++ linux-2.6.39.1/drivers/ata/pata_cmd64x.c 2011-06-03 00:32:05.000000000 -0400
25311@@ -271,18 +271,18 @@ static const struct ata_port_operations
25312 .set_dmamode = cmd64x_set_dmamode,
25313 };
25314
25315-static struct ata_port_operations cmd64x_port_ops = {
25316+static const struct ata_port_operations cmd64x_port_ops = {
25317 .inherits = &cmd64x_base_ops,
25318 .cable_detect = ata_cable_40wire,
25319 };
25320
25321-static struct ata_port_operations cmd646r1_port_ops = {
25322+static const struct ata_port_operations cmd646r1_port_ops = {
25323 .inherits = &cmd64x_base_ops,
25324 .bmdma_stop = cmd646r1_bmdma_stop,
25325 .cable_detect = ata_cable_40wire,
25326 };
25327
25328-static struct ata_port_operations cmd648_port_ops = {
25329+static const struct ata_port_operations cmd648_port_ops = {
25330 .inherits = &cmd64x_base_ops,
25331 .bmdma_stop = cmd648_bmdma_stop,
25332 .cable_detect = cmd648_cable_detect,
25333diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5520.c linux-2.6.39.1/drivers/ata/pata_cs5520.c
25334--- linux-2.6.39.1/drivers/ata/pata_cs5520.c 2011-05-19 00:06:34.000000000 -0400
25335+++ linux-2.6.39.1/drivers/ata/pata_cs5520.c 2011-05-22 19:36:31.000000000 -0400
25336@@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
25337 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25338 };
25339
25340-static struct ata_port_operations cs5520_port_ops = {
25341+static const struct ata_port_operations cs5520_port_ops = {
25342 .inherits = &ata_bmdma_port_ops,
25343 .qc_prep = ata_bmdma_dumb_qc_prep,
25344 .cable_detect = ata_cable_40wire,
25345diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5530.c linux-2.6.39.1/drivers/ata/pata_cs5530.c
25346--- linux-2.6.39.1/drivers/ata/pata_cs5530.c 2011-05-19 00:06:34.000000000 -0400
25347+++ linux-2.6.39.1/drivers/ata/pata_cs5530.c 2011-05-22 19:36:31.000000000 -0400
25348@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
25349 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25350 };
25351
25352-static struct ata_port_operations cs5530_port_ops = {
25353+static const struct ata_port_operations cs5530_port_ops = {
25354 .inherits = &ata_bmdma_port_ops,
25355
25356 .qc_prep = ata_bmdma_dumb_qc_prep,
25357diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5535.c linux-2.6.39.1/drivers/ata/pata_cs5535.c
25358--- linux-2.6.39.1/drivers/ata/pata_cs5535.c 2011-05-19 00:06:34.000000000 -0400
25359+++ linux-2.6.39.1/drivers/ata/pata_cs5535.c 2011-05-22 19:36:31.000000000 -0400
25360@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
25361 ATA_BMDMA_SHT(DRV_NAME),
25362 };
25363
25364-static struct ata_port_operations cs5535_port_ops = {
25365+static const struct ata_port_operations cs5535_port_ops = {
25366 .inherits = &ata_bmdma_port_ops,
25367 .cable_detect = cs5535_cable_detect,
25368 .set_piomode = cs5535_set_piomode,
25369diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5536.c linux-2.6.39.1/drivers/ata/pata_cs5536.c
25370--- linux-2.6.39.1/drivers/ata/pata_cs5536.c 2011-05-19 00:06:34.000000000 -0400
25371+++ linux-2.6.39.1/drivers/ata/pata_cs5536.c 2011-05-22 19:36:31.000000000 -0400
25372@@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
25373 ATA_BMDMA_SHT(DRV_NAME),
25374 };
25375
25376-static struct ata_port_operations cs5536_port_ops = {
25377+static const struct ata_port_operations cs5536_port_ops = {
25378 .inherits = &ata_bmdma32_port_ops,
25379 .cable_detect = cs5536_cable_detect,
25380 .set_piomode = cs5536_set_piomode,
25381diff -urNp linux-2.6.39.1/drivers/ata/pata_cypress.c linux-2.6.39.1/drivers/ata/pata_cypress.c
25382--- linux-2.6.39.1/drivers/ata/pata_cypress.c 2011-05-19 00:06:34.000000000 -0400
25383+++ linux-2.6.39.1/drivers/ata/pata_cypress.c 2011-05-22 19:36:31.000000000 -0400
25384@@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
25385 ATA_BMDMA_SHT(DRV_NAME),
25386 };
25387
25388-static struct ata_port_operations cy82c693_port_ops = {
25389+static const struct ata_port_operations cy82c693_port_ops = {
25390 .inherits = &ata_bmdma_port_ops,
25391 .cable_detect = ata_cable_40wire,
25392 .set_piomode = cy82c693_set_piomode,
25393diff -urNp linux-2.6.39.1/drivers/ata/pata_efar.c linux-2.6.39.1/drivers/ata/pata_efar.c
25394--- linux-2.6.39.1/drivers/ata/pata_efar.c 2011-05-19 00:06:34.000000000 -0400
25395+++ linux-2.6.39.1/drivers/ata/pata_efar.c 2011-05-22 19:36:31.000000000 -0400
25396@@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
25397 ATA_BMDMA_SHT(DRV_NAME),
25398 };
25399
25400-static struct ata_port_operations efar_ops = {
25401+static const struct ata_port_operations efar_ops = {
25402 .inherits = &ata_bmdma_port_ops,
25403 .cable_detect = efar_cable_detect,
25404 .set_piomode = efar_set_piomode,
25405diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt366.c linux-2.6.39.1/drivers/ata/pata_hpt366.c
25406--- linux-2.6.39.1/drivers/ata/pata_hpt366.c 2011-05-19 00:06:34.000000000 -0400
25407+++ linux-2.6.39.1/drivers/ata/pata_hpt366.c 2011-05-22 19:36:31.000000000 -0400
25408@@ -276,7 +276,7 @@ static struct scsi_host_template hpt36x_
25409 * Configuration for HPT366/68
25410 */
25411
25412-static struct ata_port_operations hpt366_port_ops = {
25413+static const struct ata_port_operations hpt366_port_ops = {
25414 .inherits = &ata_bmdma_port_ops,
25415 .cable_detect = hpt36x_cable_detect,
25416 .mode_filter = hpt366_filter,
25417diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt37x.c linux-2.6.39.1/drivers/ata/pata_hpt37x.c
25418--- linux-2.6.39.1/drivers/ata/pata_hpt37x.c 2011-05-19 00:06:34.000000000 -0400
25419+++ linux-2.6.39.1/drivers/ata/pata_hpt37x.c 2011-05-22 19:36:31.000000000 -0400
25420@@ -589,7 +589,7 @@ static struct scsi_host_template hpt37x_
25421 * Configuration for HPT370
25422 */
25423
25424-static struct ata_port_operations hpt370_port_ops = {
25425+static const struct ata_port_operations hpt370_port_ops = {
25426 .inherits = &ata_bmdma_port_ops,
25427
25428 .bmdma_stop = hpt370_bmdma_stop,
25429@@ -605,7 +605,7 @@ static struct ata_port_operations hpt370
25430 * Configuration for HPT370A. Close to 370 but less filters
25431 */
25432
25433-static struct ata_port_operations hpt370a_port_ops = {
25434+static const struct ata_port_operations hpt370a_port_ops = {
25435 .inherits = &hpt370_port_ops,
25436 .mode_filter = hpt370a_filter,
25437 };
25438@@ -615,7 +615,7 @@ static struct ata_port_operations hpt370
25439 * mode setting functionality.
25440 */
25441
25442-static struct ata_port_operations hpt302_port_ops = {
25443+static const struct ata_port_operations hpt302_port_ops = {
25444 .inherits = &ata_bmdma_port_ops,
25445
25446 .bmdma_stop = hpt37x_bmdma_stop,
25447@@ -631,7 +631,7 @@ static struct ata_port_operations hpt302
25448 * but we have a mode filter.
25449 */
25450
25451-static struct ata_port_operations hpt372_port_ops = {
25452+static const struct ata_port_operations hpt372_port_ops = {
25453 .inherits = &hpt302_port_ops,
25454 .mode_filter = hpt372_filter,
25455 };
25456@@ -641,7 +641,7 @@ static struct ata_port_operations hpt372
25457 * but we have a different cable detection procedure for function 1.
25458 */
25459
25460-static struct ata_port_operations hpt374_fn1_port_ops = {
25461+static const struct ata_port_operations hpt374_fn1_port_ops = {
25462 .inherits = &hpt372_port_ops,
25463 .cable_detect = hpt374_fn1_cable_detect,
25464 };
25465diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c
25466--- linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c 2011-05-19 00:06:34.000000000 -0400
25467+++ linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c 2011-05-22 19:36:31.000000000 -0400
25468@@ -350,7 +350,7 @@ static struct scsi_host_template hpt3x2n
25469 * Configuration for HPT302N/371N.
25470 */
25471
25472-static struct ata_port_operations hpt3xxn_port_ops = {
25473+static const struct ata_port_operations hpt3xxn_port_ops = {
25474 .inherits = &ata_bmdma_port_ops,
25475
25476 .bmdma_stop = hpt3x2n_bmdma_stop,
25477@@ -368,7 +368,7 @@ static struct ata_port_operations hpt3xx
25478 * Configuration for HPT372N. Same as 302N/371N but we have a mode filter.
25479 */
25480
25481-static struct ata_port_operations hpt372n_port_ops = {
25482+static const struct ata_port_operations hpt372n_port_ops = {
25483 .inherits = &hpt3xxn_port_ops,
25484 .mode_filter = &hpt372n_filter,
25485 };
25486diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt3x3.c linux-2.6.39.1/drivers/ata/pata_hpt3x3.c
25487--- linux-2.6.39.1/drivers/ata/pata_hpt3x3.c 2011-05-19 00:06:34.000000000 -0400
25488+++ linux-2.6.39.1/drivers/ata/pata_hpt3x3.c 2011-05-22 19:36:31.000000000 -0400
25489@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
25490 ATA_BMDMA_SHT(DRV_NAME),
25491 };
25492
25493-static struct ata_port_operations hpt3x3_port_ops = {
25494+static const struct ata_port_operations hpt3x3_port_ops = {
25495 .inherits = &ata_bmdma_port_ops,
25496 .cable_detect = ata_cable_40wire,
25497 .set_piomode = hpt3x3_set_piomode,
25498diff -urNp linux-2.6.39.1/drivers/ata/pata_icside.c linux-2.6.39.1/drivers/ata/pata_icside.c
25499--- linux-2.6.39.1/drivers/ata/pata_icside.c 2011-05-19 00:06:34.000000000 -0400
25500+++ linux-2.6.39.1/drivers/ata/pata_icside.c 2011-05-22 19:36:31.000000000 -0400
25501@@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
25502 }
25503 }
25504
25505-static struct ata_port_operations pata_icside_port_ops = {
25506+static const struct ata_port_operations pata_icside_port_ops = {
25507 .inherits = &ata_bmdma_port_ops,
25508 /* no need to build any PRD tables for DMA */
25509 .qc_prep = ata_noop_qc_prep,
25510diff -urNp linux-2.6.39.1/drivers/ata/pata_isapnp.c linux-2.6.39.1/drivers/ata/pata_isapnp.c
25511--- linux-2.6.39.1/drivers/ata/pata_isapnp.c 2011-05-19 00:06:34.000000000 -0400
25512+++ linux-2.6.39.1/drivers/ata/pata_isapnp.c 2011-05-22 19:36:31.000000000 -0400
25513@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
25514 ATA_PIO_SHT(DRV_NAME),
25515 };
25516
25517-static struct ata_port_operations isapnp_port_ops = {
25518+static const struct ata_port_operations isapnp_port_ops = {
25519 .inherits = &ata_sff_port_ops,
25520 .cable_detect = ata_cable_40wire,
25521 };
25522
25523-static struct ata_port_operations isapnp_noalt_port_ops = {
25524+static const struct ata_port_operations isapnp_noalt_port_ops = {
25525 .inherits = &ata_sff_port_ops,
25526 .cable_detect = ata_cable_40wire,
25527 /* No altstatus so we don't want to use the lost interrupt poll */
25528diff -urNp linux-2.6.39.1/drivers/ata/pata_it8213.c linux-2.6.39.1/drivers/ata/pata_it8213.c
25529--- linux-2.6.39.1/drivers/ata/pata_it8213.c 2011-05-19 00:06:34.000000000 -0400
25530+++ linux-2.6.39.1/drivers/ata/pata_it8213.c 2011-05-22 19:36:31.000000000 -0400
25531@@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
25532 };
25533
25534
25535-static struct ata_port_operations it8213_ops = {
25536+static const struct ata_port_operations it8213_ops = {
25537 .inherits = &ata_bmdma_port_ops,
25538 .cable_detect = it8213_cable_detect,
25539 .set_piomode = it8213_set_piomode,
25540diff -urNp linux-2.6.39.1/drivers/ata/pata_it821x.c linux-2.6.39.1/drivers/ata/pata_it821x.c
25541--- linux-2.6.39.1/drivers/ata/pata_it821x.c 2011-05-19 00:06:34.000000000 -0400
25542+++ linux-2.6.39.1/drivers/ata/pata_it821x.c 2011-05-22 19:36:31.000000000 -0400
25543@@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
25544 ATA_BMDMA_SHT(DRV_NAME),
25545 };
25546
25547-static struct ata_port_operations it821x_smart_port_ops = {
25548+static const struct ata_port_operations it821x_smart_port_ops = {
25549 .inherits = &ata_bmdma_port_ops,
25550
25551 .check_atapi_dma= it821x_check_atapi_dma,
25552@@ -815,7 +815,7 @@ static struct ata_port_operations it821x
25553 .port_start = it821x_port_start,
25554 };
25555
25556-static struct ata_port_operations it821x_passthru_port_ops = {
25557+static const struct ata_port_operations it821x_passthru_port_ops = {
25558 .inherits = &ata_bmdma_port_ops,
25559
25560 .check_atapi_dma= it821x_check_atapi_dma,
25561@@ -831,7 +831,7 @@ static struct ata_port_operations it821x
25562 .port_start = it821x_port_start,
25563 };
25564
25565-static struct ata_port_operations it821x_rdc_port_ops = {
25566+static const struct ata_port_operations it821x_rdc_port_ops = {
25567 .inherits = &ata_bmdma_port_ops,
25568
25569 .check_atapi_dma= it821x_check_atapi_dma,
25570diff -urNp linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c
25571--- linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c 2011-05-19 00:06:34.000000000 -0400
25572+++ linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c 2011-05-22 19:36:31.000000000 -0400
25573@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25574 ATA_PIO_SHT(DRV_NAME),
25575 };
25576
25577-static struct ata_port_operations ixp4xx_port_ops = {
25578+static const struct ata_port_operations ixp4xx_port_ops = {
25579 .inherits = &ata_sff_port_ops,
25580 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25581 .cable_detect = ata_cable_40wire,
25582diff -urNp linux-2.6.39.1/drivers/ata/pata_jmicron.c linux-2.6.39.1/drivers/ata/pata_jmicron.c
25583--- linux-2.6.39.1/drivers/ata/pata_jmicron.c 2011-05-19 00:06:34.000000000 -0400
25584+++ linux-2.6.39.1/drivers/ata/pata_jmicron.c 2011-05-22 19:36:31.000000000 -0400
25585@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25586 ATA_BMDMA_SHT(DRV_NAME),
25587 };
25588
25589-static struct ata_port_operations jmicron_ops = {
25590+static const struct ata_port_operations jmicron_ops = {
25591 .inherits = &ata_bmdma_port_ops,
25592 .prereset = jmicron_pre_reset,
25593 };
25594diff -urNp linux-2.6.39.1/drivers/ata/pata_legacy.c linux-2.6.39.1/drivers/ata/pata_legacy.c
25595--- linux-2.6.39.1/drivers/ata/pata_legacy.c 2011-05-19 00:06:34.000000000 -0400
25596+++ linux-2.6.39.1/drivers/ata/pata_legacy.c 2011-05-22 19:36:31.000000000 -0400
25597@@ -116,7 +116,7 @@ struct legacy_probe {
25598
25599 struct legacy_controller {
25600 const char *name;
25601- struct ata_port_operations *ops;
25602+ const struct ata_port_operations *ops;
25603 unsigned int pio_mask;
25604 unsigned int flags;
25605 unsigned int pflags;
25606@@ -239,12 +239,12 @@ static const struct ata_port_operations
25607 * pio_mask as well.
25608 */
25609
25610-static struct ata_port_operations simple_port_ops = {
25611+static const struct ata_port_operations simple_port_ops = {
25612 .inherits = &legacy_base_port_ops,
25613 .sff_data_xfer = ata_sff_data_xfer_noirq,
25614 };
25615
25616-static struct ata_port_operations legacy_port_ops = {
25617+static const struct ata_port_operations legacy_port_ops = {
25618 .inherits = &legacy_base_port_ops,
25619 .sff_data_xfer = ata_sff_data_xfer_noirq,
25620 .set_mode = legacy_set_mode,
25621@@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
25622 return buflen;
25623 }
25624
25625-static struct ata_port_operations pdc20230_port_ops = {
25626+static const struct ata_port_operations pdc20230_port_ops = {
25627 .inherits = &legacy_base_port_ops,
25628 .set_piomode = pdc20230_set_piomode,
25629 .sff_data_xfer = pdc_data_xfer_vlb,
25630@@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
25631 ioread8(ap->ioaddr.status_addr);
25632 }
25633
25634-static struct ata_port_operations ht6560a_port_ops = {
25635+static const struct ata_port_operations ht6560a_port_ops = {
25636 .inherits = &legacy_base_port_ops,
25637 .set_piomode = ht6560a_set_piomode,
25638 };
25639@@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
25640 ioread8(ap->ioaddr.status_addr);
25641 }
25642
25643-static struct ata_port_operations ht6560b_port_ops = {
25644+static const struct ata_port_operations ht6560b_port_ops = {
25645 .inherits = &legacy_base_port_ops,
25646 .set_piomode = ht6560b_set_piomode,
25647 };
25648@@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
25649 }
25650
25651
25652-static struct ata_port_operations opti82c611a_port_ops = {
25653+static const struct ata_port_operations opti82c611a_port_ops = {
25654 .inherits = &legacy_base_port_ops,
25655 .set_piomode = opti82c611a_set_piomode,
25656 };
25657@@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
25658 return ata_sff_qc_issue(qc);
25659 }
25660
25661-static struct ata_port_operations opti82c46x_port_ops = {
25662+static const struct ata_port_operations opti82c46x_port_ops = {
25663 .inherits = &legacy_base_port_ops,
25664 .set_piomode = opti82c46x_set_piomode,
25665 .qc_issue = opti82c46x_qc_issue,
25666@@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
25667 return 0;
25668 }
25669
25670-static struct ata_port_operations qdi6500_port_ops = {
25671+static const struct ata_port_operations qdi6500_port_ops = {
25672 .inherits = &legacy_base_port_ops,
25673 .set_piomode = qdi6500_set_piomode,
25674 .qc_issue = qdi_qc_issue,
25675 .sff_data_xfer = vlb32_data_xfer,
25676 };
25677
25678-static struct ata_port_operations qdi6580_port_ops = {
25679+static const struct ata_port_operations qdi6580_port_ops = {
25680 .inherits = &legacy_base_port_ops,
25681 .set_piomode = qdi6580_set_piomode,
25682 .sff_data_xfer = vlb32_data_xfer,
25683 };
25684
25685-static struct ata_port_operations qdi6580dp_port_ops = {
25686+static const struct ata_port_operations qdi6580dp_port_ops = {
25687 .inherits = &legacy_base_port_ops,
25688 .set_piomode = qdi6580dp_set_piomode,
25689 .qc_issue = qdi_qc_issue,
25690@@ -872,7 +872,7 @@ static int winbond_port(struct platform_
25691 return 0;
25692 }
25693
25694-static struct ata_port_operations winbond_port_ops = {
25695+static const struct ata_port_operations winbond_port_ops = {
25696 .inherits = &legacy_base_port_ops,
25697 .set_piomode = winbond_set_piomode,
25698 .sff_data_xfer = vlb32_data_xfer,
25699@@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
25700 int pio_modes = controller->pio_mask;
25701 unsigned long io = probe->port;
25702 u32 mask = (1 << probe->slot);
25703- struct ata_port_operations *ops = controller->ops;
25704+ const struct ata_port_operations *ops = controller->ops;
25705 struct legacy_data *ld = &legacy_data[probe->slot];
25706 struct ata_host *host = NULL;
25707 struct ata_port *ap;
25708diff -urNp linux-2.6.39.1/drivers/ata/pata_macio.c linux-2.6.39.1/drivers/ata/pata_macio.c
25709--- linux-2.6.39.1/drivers/ata/pata_macio.c 2011-05-19 00:06:34.000000000 -0400
25710+++ linux-2.6.39.1/drivers/ata/pata_macio.c 2011-05-22 19:36:31.000000000 -0400
25711@@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
25712 .slave_configure = pata_macio_slave_config,
25713 };
25714
25715-static struct ata_port_operations pata_macio_ops = {
25716+static const struct ata_port_operations pata_macio_ops = {
25717 .inherits = &ata_bmdma_port_ops,
25718-
25719 .freeze = pata_macio_freeze,
25720 .set_piomode = pata_macio_set_timings,
25721 .set_dmamode = pata_macio_set_timings,
25722diff -urNp linux-2.6.39.1/drivers/ata/pata_marvell.c linux-2.6.39.1/drivers/ata/pata_marvell.c
25723--- linux-2.6.39.1/drivers/ata/pata_marvell.c 2011-05-19 00:06:34.000000000 -0400
25724+++ linux-2.6.39.1/drivers/ata/pata_marvell.c 2011-05-22 19:36:31.000000000 -0400
25725@@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25726 ATA_BMDMA_SHT(DRV_NAME),
25727 };
25728
25729-static struct ata_port_operations marvell_ops = {
25730+static const struct ata_port_operations marvell_ops = {
25731 .inherits = &ata_bmdma_port_ops,
25732 .cable_detect = marvell_cable_detect,
25733 .prereset = marvell_pre_reset,
25734diff -urNp linux-2.6.39.1/drivers/ata/pata_mpc52xx.c linux-2.6.39.1/drivers/ata/pata_mpc52xx.c
25735--- linux-2.6.39.1/drivers/ata/pata_mpc52xx.c 2011-05-19 00:06:34.000000000 -0400
25736+++ linux-2.6.39.1/drivers/ata/pata_mpc52xx.c 2011-05-22 19:36:31.000000000 -0400
25737@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25738 ATA_PIO_SHT(DRV_NAME),
25739 };
25740
25741-static struct ata_port_operations mpc52xx_ata_port_ops = {
25742+static const struct ata_port_operations mpc52xx_ata_port_ops = {
25743 .inherits = &ata_bmdma_port_ops,
25744 .sff_dev_select = mpc52xx_ata_dev_select,
25745 .set_piomode = mpc52xx_ata_set_piomode,
25746diff -urNp linux-2.6.39.1/drivers/ata/pata_mpiix.c linux-2.6.39.1/drivers/ata/pata_mpiix.c
25747--- linux-2.6.39.1/drivers/ata/pata_mpiix.c 2011-05-19 00:06:34.000000000 -0400
25748+++ linux-2.6.39.1/drivers/ata/pata_mpiix.c 2011-05-22 19:36:31.000000000 -0400
25749@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25750 ATA_PIO_SHT(DRV_NAME),
25751 };
25752
25753-static struct ata_port_operations mpiix_port_ops = {
25754+static const struct ata_port_operations mpiix_port_ops = {
25755 .inherits = &ata_sff_port_ops,
25756 .qc_issue = mpiix_qc_issue,
25757 .cable_detect = ata_cable_40wire,
25758diff -urNp linux-2.6.39.1/drivers/ata/pata_netcell.c linux-2.6.39.1/drivers/ata/pata_netcell.c
25759--- linux-2.6.39.1/drivers/ata/pata_netcell.c 2011-05-19 00:06:34.000000000 -0400
25760+++ linux-2.6.39.1/drivers/ata/pata_netcell.c 2011-05-22 19:36:31.000000000 -0400
25761@@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25762 ATA_BMDMA_SHT(DRV_NAME),
25763 };
25764
25765-static struct ata_port_operations netcell_ops = {
25766+static const struct ata_port_operations netcell_ops = {
25767 .inherits = &ata_bmdma_port_ops,
25768 .cable_detect = ata_cable_80wire,
25769 .read_id = netcell_read_id,
25770diff -urNp linux-2.6.39.1/drivers/ata/pata_ninja32.c linux-2.6.39.1/drivers/ata/pata_ninja32.c
25771--- linux-2.6.39.1/drivers/ata/pata_ninja32.c 2011-05-19 00:06:34.000000000 -0400
25772+++ linux-2.6.39.1/drivers/ata/pata_ninja32.c 2011-05-22 19:36:31.000000000 -0400
25773@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25774 ATA_BMDMA_SHT(DRV_NAME),
25775 };
25776
25777-static struct ata_port_operations ninja32_port_ops = {
25778+static const struct ata_port_operations ninja32_port_ops = {
25779 .inherits = &ata_bmdma_port_ops,
25780 .sff_dev_select = ninja32_dev_select,
25781 .cable_detect = ata_cable_40wire,
25782diff -urNp linux-2.6.39.1/drivers/ata/pata_ns87410.c linux-2.6.39.1/drivers/ata/pata_ns87410.c
25783--- linux-2.6.39.1/drivers/ata/pata_ns87410.c 2011-05-19 00:06:34.000000000 -0400
25784+++ linux-2.6.39.1/drivers/ata/pata_ns87410.c 2011-05-22 19:36:31.000000000 -0400
25785@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25786 ATA_PIO_SHT(DRV_NAME),
25787 };
25788
25789-static struct ata_port_operations ns87410_port_ops = {
25790+static const struct ata_port_operations ns87410_port_ops = {
25791 .inherits = &ata_sff_port_ops,
25792 .qc_issue = ns87410_qc_issue,
25793 .cable_detect = ata_cable_40wire,
25794diff -urNp linux-2.6.39.1/drivers/ata/pata_ns87415.c linux-2.6.39.1/drivers/ata/pata_ns87415.c
25795--- linux-2.6.39.1/drivers/ata/pata_ns87415.c 2011-05-19 00:06:34.000000000 -0400
25796+++ linux-2.6.39.1/drivers/ata/pata_ns87415.c 2011-05-22 19:36:31.000000000 -0400
25797@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25798 }
25799 #endif /* 87560 SuperIO Support */
25800
25801-static struct ata_port_operations ns87415_pata_ops = {
25802+static const struct ata_port_operations ns87415_pata_ops = {
25803 .inherits = &ata_bmdma_port_ops,
25804
25805 .check_atapi_dma = ns87415_check_atapi_dma,
25806@@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25807 };
25808
25809 #if defined(CONFIG_SUPERIO)
25810-static struct ata_port_operations ns87560_pata_ops = {
25811+static const struct ata_port_operations ns87560_pata_ops = {
25812 .inherits = &ns87415_pata_ops,
25813 .sff_tf_read = ns87560_tf_read,
25814 .sff_check_status = ns87560_check_status,
25815diff -urNp linux-2.6.39.1/drivers/ata/pata_octeon_cf.c linux-2.6.39.1/drivers/ata/pata_octeon_cf.c
25816--- linux-2.6.39.1/drivers/ata/pata_octeon_cf.c 2011-05-19 00:06:34.000000000 -0400
25817+++ linux-2.6.39.1/drivers/ata/pata_octeon_cf.c 2011-05-22 19:36:31.000000000 -0400
25818@@ -780,7 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
25819 return 0;
25820 }
25821
25822-static struct ata_port_operations octeon_cf_ops = {
25823+static struct ata_port_operations octeon_cf_ops = { /* cannot be const */
25824 .inherits = &ata_sff_port_ops,
25825 .check_atapi_dma = octeon_cf_check_atapi_dma,
25826 .qc_prep = ata_noop_qc_prep,
25827diff -urNp linux-2.6.39.1/drivers/ata/pata_oldpiix.c linux-2.6.39.1/drivers/ata/pata_oldpiix.c
25828--- linux-2.6.39.1/drivers/ata/pata_oldpiix.c 2011-05-19 00:06:34.000000000 -0400
25829+++ linux-2.6.39.1/drivers/ata/pata_oldpiix.c 2011-05-22 19:36:31.000000000 -0400
25830@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25831 ATA_BMDMA_SHT(DRV_NAME),
25832 };
25833
25834-static struct ata_port_operations oldpiix_pata_ops = {
25835+static const struct ata_port_operations oldpiix_pata_ops = {
25836 .inherits = &ata_bmdma_port_ops,
25837 .qc_issue = oldpiix_qc_issue,
25838 .cable_detect = ata_cable_40wire,
25839diff -urNp linux-2.6.39.1/drivers/ata/pata_opti.c linux-2.6.39.1/drivers/ata/pata_opti.c
25840--- linux-2.6.39.1/drivers/ata/pata_opti.c 2011-05-19 00:06:34.000000000 -0400
25841+++ linux-2.6.39.1/drivers/ata/pata_opti.c 2011-05-22 19:36:31.000000000 -0400
25842@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25843 ATA_PIO_SHT(DRV_NAME),
25844 };
25845
25846-static struct ata_port_operations opti_port_ops = {
25847+static const struct ata_port_operations opti_port_ops = {
25848 .inherits = &ata_sff_port_ops,
25849 .cable_detect = ata_cable_40wire,
25850 .set_piomode = opti_set_piomode,
25851diff -urNp linux-2.6.39.1/drivers/ata/pata_optidma.c linux-2.6.39.1/drivers/ata/pata_optidma.c
25852--- linux-2.6.39.1/drivers/ata/pata_optidma.c 2011-05-19 00:06:34.000000000 -0400
25853+++ linux-2.6.39.1/drivers/ata/pata_optidma.c 2011-05-22 19:36:31.000000000 -0400
25854@@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25855 ATA_BMDMA_SHT(DRV_NAME),
25856 };
25857
25858-static struct ata_port_operations optidma_port_ops = {
25859+static const struct ata_port_operations optidma_port_ops = {
25860 .inherits = &ata_bmdma_port_ops,
25861 .cable_detect = ata_cable_40wire,
25862 .set_piomode = optidma_set_pio_mode,
25863@@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25864 .prereset = optidma_pre_reset,
25865 };
25866
25867-static struct ata_port_operations optiplus_port_ops = {
25868+static const struct ata_port_operations optiplus_port_ops = {
25869 .inherits = &optidma_port_ops,
25870 .set_piomode = optiplus_set_pio_mode,
25871 .set_dmamode = optiplus_set_dma_mode,
25872diff -urNp linux-2.6.39.1/drivers/ata/pata_palmld.c linux-2.6.39.1/drivers/ata/pata_palmld.c
25873--- linux-2.6.39.1/drivers/ata/pata_palmld.c 2011-05-19 00:06:34.000000000 -0400
25874+++ linux-2.6.39.1/drivers/ata/pata_palmld.c 2011-05-22 19:36:31.000000000 -0400
25875@@ -42,7 +42,7 @@ static struct scsi_host_template palmld_
25876 ATA_PIO_SHT(DRV_NAME),
25877 };
25878
25879-static struct ata_port_operations palmld_port_ops = {
25880+static const struct ata_port_operations palmld_port_ops = {
25881 .inherits = &ata_sff_port_ops,
25882 .sff_data_xfer = ata_sff_data_xfer_noirq,
25883 .cable_detect = ata_cable_40wire,
25884diff -urNp linux-2.6.39.1/drivers/ata/pata_pcmcia.c linux-2.6.39.1/drivers/ata/pata_pcmcia.c
25885--- linux-2.6.39.1/drivers/ata/pata_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
25886+++ linux-2.6.39.1/drivers/ata/pata_pcmcia.c 2011-05-22 19:36:31.000000000 -0400
25887@@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
25888 ATA_PIO_SHT(DRV_NAME),
25889 };
25890
25891-static struct ata_port_operations pcmcia_port_ops = {
25892+static const struct ata_port_operations pcmcia_port_ops = {
25893 .inherits = &ata_sff_port_ops,
25894 .sff_data_xfer = ata_sff_data_xfer_noirq,
25895 .cable_detect = ata_cable_40wire,
25896 .set_mode = pcmcia_set_mode,
25897 };
25898
25899-static struct ata_port_operations pcmcia_8bit_port_ops = {
25900+static const struct ata_port_operations pcmcia_8bit_port_ops = {
25901 .inherits = &ata_sff_port_ops,
25902 .sff_data_xfer = ata_data_xfer_8bit,
25903 .cable_detect = ata_cable_40wire,
25904@@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
25905 unsigned long io_base, ctl_base;
25906 void __iomem *io_addr, *ctl_addr;
25907 int n_ports = 1;
25908- struct ata_port_operations *ops = &pcmcia_port_ops;
25909+ const struct ata_port_operations *ops = &pcmcia_port_ops;
25910
25911 /* Set up attributes in order to probe card and get resources */
25912 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
25913diff -urNp linux-2.6.39.1/drivers/ata/pata_pdc2027x.c linux-2.6.39.1/drivers/ata/pata_pdc2027x.c
25914--- linux-2.6.39.1/drivers/ata/pata_pdc2027x.c 2011-05-19 00:06:34.000000000 -0400
25915+++ linux-2.6.39.1/drivers/ata/pata_pdc2027x.c 2011-05-22 19:36:31.000000000 -0400
25916@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25917 ATA_BMDMA_SHT(DRV_NAME),
25918 };
25919
25920-static struct ata_port_operations pdc2027x_pata100_ops = {
25921+static const struct ata_port_operations pdc2027x_pata100_ops = {
25922 .inherits = &ata_bmdma_port_ops,
25923 .check_atapi_dma = pdc2027x_check_atapi_dma,
25924 .cable_detect = pdc2027x_cable_detect,
25925 .prereset = pdc2027x_prereset,
25926 };
25927
25928-static struct ata_port_operations pdc2027x_pata133_ops = {
25929+static const struct ata_port_operations pdc2027x_pata133_ops = {
25930 .inherits = &pdc2027x_pata100_ops,
25931 .mode_filter = pdc2027x_mode_filter,
25932 .set_piomode = pdc2027x_set_piomode,
25933diff -urNp linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c
25934--- linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c 2011-05-19 00:06:34.000000000 -0400
25935+++ linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c 2011-05-22 19:36:31.000000000 -0400
25936@@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
25937 ATA_BMDMA_SHT(DRV_NAME),
25938 };
25939
25940-static struct ata_port_operations pdc2024x_port_ops = {
25941+static const struct ata_port_operations pdc2024x_port_ops = {
25942 .inherits = &ata_bmdma_port_ops,
25943
25944 .cable_detect = ata_cable_40wire,
25945@@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
25946 .sff_irq_check = pdc202xx_irq_check,
25947 };
25948
25949-static struct ata_port_operations pdc2026x_port_ops = {
25950+static const struct ata_port_operations pdc2026x_port_ops = {
25951 .inherits = &pdc2024x_port_ops,
25952
25953 .check_atapi_dma = pdc2026x_check_atapi_dma,
25954diff -urNp linux-2.6.39.1/drivers/ata/pata_piccolo.c linux-2.6.39.1/drivers/ata/pata_piccolo.c
25955--- linux-2.6.39.1/drivers/ata/pata_piccolo.c 2011-05-19 00:06:34.000000000 -0400
25956+++ linux-2.6.39.1/drivers/ata/pata_piccolo.c 2011-05-22 19:36:31.000000000 -0400
25957@@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
25958 ATA_BMDMA_SHT(DRV_NAME),
25959 };
25960
25961-static struct ata_port_operations tosh_port_ops = {
25962+static const struct ata_port_operations tosh_port_ops = {
25963 .inherits = &ata_bmdma_port_ops,
25964 .cable_detect = ata_cable_unknown,
25965 .set_piomode = tosh_set_piomode,
25966diff -urNp linux-2.6.39.1/drivers/ata/pata_platform.c linux-2.6.39.1/drivers/ata/pata_platform.c
25967--- linux-2.6.39.1/drivers/ata/pata_platform.c 2011-05-19 00:06:34.000000000 -0400
25968+++ linux-2.6.39.1/drivers/ata/pata_platform.c 2011-05-22 19:36:31.000000000 -0400
25969@@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25970 ATA_PIO_SHT(DRV_NAME),
25971 };
25972
25973-static struct ata_port_operations pata_platform_port_ops = {
25974+static const struct ata_port_operations pata_platform_port_ops = {
25975 .inherits = &ata_sff_port_ops,
25976 .sff_data_xfer = ata_sff_data_xfer_noirq,
25977 .cable_detect = ata_cable_unknown,
25978diff -urNp linux-2.6.39.1/drivers/ata/pata_pxa.c linux-2.6.39.1/drivers/ata/pata_pxa.c
25979--- linux-2.6.39.1/drivers/ata/pata_pxa.c 2011-05-19 00:06:34.000000000 -0400
25980+++ linux-2.6.39.1/drivers/ata/pata_pxa.c 2011-05-22 19:36:31.000000000 -0400
25981@@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
25982 ATA_BMDMA_SHT(DRV_NAME),
25983 };
25984
25985-static struct ata_port_operations pxa_ata_port_ops = {
25986+static const struct ata_port_operations pxa_ata_port_ops = {
25987 .inherits = &ata_bmdma_port_ops,
25988 .cable_detect = ata_cable_40wire,
25989
25990diff -urNp linux-2.6.39.1/drivers/ata/pata_qdi.c linux-2.6.39.1/drivers/ata/pata_qdi.c
25991--- linux-2.6.39.1/drivers/ata/pata_qdi.c 2011-05-19 00:06:34.000000000 -0400
25992+++ linux-2.6.39.1/drivers/ata/pata_qdi.c 2011-05-22 19:36:31.000000000 -0400
25993@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25994 ATA_PIO_SHT(DRV_NAME),
25995 };
25996
25997-static struct ata_port_operations qdi6500_port_ops = {
25998+static const struct ata_port_operations qdi6500_port_ops = {
25999 .inherits = &ata_sff_port_ops,
26000 .qc_issue = qdi_qc_issue,
26001 .sff_data_xfer = qdi_data_xfer,
26002@@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
26003 .set_piomode = qdi6500_set_piomode,
26004 };
26005
26006-static struct ata_port_operations qdi6580_port_ops = {
26007+static const struct ata_port_operations qdi6580_port_ops = {
26008 .inherits = &qdi6500_port_ops,
26009 .set_piomode = qdi6580_set_piomode,
26010 };
26011diff -urNp linux-2.6.39.1/drivers/ata/pata_radisys.c linux-2.6.39.1/drivers/ata/pata_radisys.c
26012--- linux-2.6.39.1/drivers/ata/pata_radisys.c 2011-05-19 00:06:34.000000000 -0400
26013+++ linux-2.6.39.1/drivers/ata/pata_radisys.c 2011-05-22 19:36:31.000000000 -0400
26014@@ -187,7 +187,7 @@ static struct scsi_host_template radisys
26015 ATA_BMDMA_SHT(DRV_NAME),
26016 };
26017
26018-static struct ata_port_operations radisys_pata_ops = {
26019+static const struct ata_port_operations radisys_pata_ops = {
26020 .inherits = &ata_bmdma_port_ops,
26021 .qc_issue = radisys_qc_issue,
26022 .cable_detect = ata_cable_unknown,
26023diff -urNp linux-2.6.39.1/drivers/ata/pata_rb532_cf.c linux-2.6.39.1/drivers/ata/pata_rb532_cf.c
26024--- linux-2.6.39.1/drivers/ata/pata_rb532_cf.c 2011-05-19 00:06:34.000000000 -0400
26025+++ linux-2.6.39.1/drivers/ata/pata_rb532_cf.c 2011-05-22 19:36:31.000000000 -0400
26026@@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
26027 return IRQ_HANDLED;
26028 }
26029
26030-static struct ata_port_operations rb532_pata_port_ops = {
26031+static const struct ata_port_operations rb532_pata_port_ops = {
26032 .inherits = &ata_sff_port_ops,
26033 .sff_data_xfer = ata_sff_data_xfer32,
26034 };
26035diff -urNp linux-2.6.39.1/drivers/ata/pata_rdc.c linux-2.6.39.1/drivers/ata/pata_rdc.c
26036--- linux-2.6.39.1/drivers/ata/pata_rdc.c 2011-05-19 00:06:34.000000000 -0400
26037+++ linux-2.6.39.1/drivers/ata/pata_rdc.c 2011-05-22 19:36:31.000000000 -0400
26038@@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
26039 pci_write_config_byte(dev, 0x48, udma_enable);
26040 }
26041
26042-static struct ata_port_operations rdc_pata_ops = {
26043+static const struct ata_port_operations rdc_pata_ops = {
26044 .inherits = &ata_bmdma32_port_ops,
26045 .cable_detect = rdc_pata_cable_detect,
26046 .set_piomode = rdc_set_piomode,
26047diff -urNp linux-2.6.39.1/drivers/ata/pata_rz1000.c linux-2.6.39.1/drivers/ata/pata_rz1000.c
26048--- linux-2.6.39.1/drivers/ata/pata_rz1000.c 2011-05-19 00:06:34.000000000 -0400
26049+++ linux-2.6.39.1/drivers/ata/pata_rz1000.c 2011-05-22 19:36:31.000000000 -0400
26050@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
26051 ATA_PIO_SHT(DRV_NAME),
26052 };
26053
26054-static struct ata_port_operations rz1000_port_ops = {
26055+static const struct ata_port_operations rz1000_port_ops = {
26056 .inherits = &ata_sff_port_ops,
26057 .cable_detect = ata_cable_40wire,
26058 .set_mode = rz1000_set_mode,
26059diff -urNp linux-2.6.39.1/drivers/ata/pata_samsung_cf.c linux-2.6.39.1/drivers/ata/pata_samsung_cf.c
26060--- linux-2.6.39.1/drivers/ata/pata_samsung_cf.c 2011-05-19 00:06:34.000000000 -0400
26061+++ linux-2.6.39.1/drivers/ata/pata_samsung_cf.c 2011-05-22 19:36:31.000000000 -0400
26062@@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
26063 ATA_PIO_SHT(DRV_NAME),
26064 };
26065
26066-static struct ata_port_operations pata_s3c_port_ops = {
26067+static const struct ata_port_operations pata_s3c_port_ops = {
26068 .inherits = &ata_sff_port_ops,
26069 .sff_check_status = pata_s3c_check_status,
26070 .sff_check_altstatus = pata_s3c_check_altstatus,
26071@@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
26072 .set_piomode = pata_s3c_set_piomode,
26073 };
26074
26075-static struct ata_port_operations pata_s5p_port_ops = {
26076+static const struct ata_port_operations pata_s5p_port_ops = {
26077 .inherits = &ata_sff_port_ops,
26078 .set_piomode = pata_s3c_set_piomode,
26079 };
26080diff -urNp linux-2.6.39.1/drivers/ata/pata_sc1200.c linux-2.6.39.1/drivers/ata/pata_sc1200.c
26081--- linux-2.6.39.1/drivers/ata/pata_sc1200.c 2011-05-19 00:06:34.000000000 -0400
26082+++ linux-2.6.39.1/drivers/ata/pata_sc1200.c 2011-05-22 19:36:31.000000000 -0400
26083@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
26084 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
26085 };
26086
26087-static struct ata_port_operations sc1200_port_ops = {
26088+static const struct ata_port_operations sc1200_port_ops = {
26089 .inherits = &ata_bmdma_port_ops,
26090 .qc_prep = ata_bmdma_dumb_qc_prep,
26091 .qc_issue = sc1200_qc_issue,
26092diff -urNp linux-2.6.39.1/drivers/ata/pata_scc.c linux-2.6.39.1/drivers/ata/pata_scc.c
26093--- linux-2.6.39.1/drivers/ata/pata_scc.c 2011-05-19 00:06:34.000000000 -0400
26094+++ linux-2.6.39.1/drivers/ata/pata_scc.c 2011-05-22 19:36:31.000000000 -0400
26095@@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
26096 ATA_BMDMA_SHT(DRV_NAME),
26097 };
26098
26099-static struct ata_port_operations scc_pata_ops = {
26100+static const struct ata_port_operations scc_pata_ops = {
26101 .inherits = &ata_bmdma_port_ops,
26102
26103 .set_piomode = scc_set_piomode,
26104diff -urNp linux-2.6.39.1/drivers/ata/pata_sch.c linux-2.6.39.1/drivers/ata/pata_sch.c
26105--- linux-2.6.39.1/drivers/ata/pata_sch.c 2011-05-19 00:06:34.000000000 -0400
26106+++ linux-2.6.39.1/drivers/ata/pata_sch.c 2011-05-22 19:36:31.000000000 -0400
26107@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
26108 ATA_BMDMA_SHT(DRV_NAME),
26109 };
26110
26111-static struct ata_port_operations sch_pata_ops = {
26112+static const struct ata_port_operations sch_pata_ops = {
26113 .inherits = &ata_bmdma_port_ops,
26114 .cable_detect = ata_cable_unknown,
26115 .set_piomode = sch_set_piomode,
26116diff -urNp linux-2.6.39.1/drivers/ata/pata_serverworks.c linux-2.6.39.1/drivers/ata/pata_serverworks.c
26117--- linux-2.6.39.1/drivers/ata/pata_serverworks.c 2011-05-19 00:06:34.000000000 -0400
26118+++ linux-2.6.39.1/drivers/ata/pata_serverworks.c 2011-05-22 19:36:31.000000000 -0400
26119@@ -300,7 +300,7 @@ static struct scsi_host_template serverw
26120 ATA_BMDMA_SHT(DRV_NAME),
26121 };
26122
26123-static struct ata_port_operations serverworks_osb4_port_ops = {
26124+static const struct ata_port_operations serverworks_osb4_port_ops = {
26125 .inherits = &ata_bmdma_port_ops,
26126 .cable_detect = serverworks_cable_detect,
26127 .mode_filter = serverworks_osb4_filter,
26128@@ -308,7 +308,7 @@ static struct ata_port_operations server
26129 .set_dmamode = serverworks_set_dmamode,
26130 };
26131
26132-static struct ata_port_operations serverworks_csb_port_ops = {
26133+static const struct ata_port_operations serverworks_csb_port_ops = {
26134 .inherits = &serverworks_osb4_port_ops,
26135 .mode_filter = serverworks_csb_filter,
26136 };
26137diff -urNp linux-2.6.39.1/drivers/ata/pata_sil680.c linux-2.6.39.1/drivers/ata/pata_sil680.c
26138--- linux-2.6.39.1/drivers/ata/pata_sil680.c 2011-05-19 00:06:34.000000000 -0400
26139+++ linux-2.6.39.1/drivers/ata/pata_sil680.c 2011-05-22 19:36:31.000000000 -0400
26140@@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
26141 ATA_BMDMA_SHT(DRV_NAME),
26142 };
26143
26144-
26145-static struct ata_port_operations sil680_port_ops = {
26146+static const struct ata_port_operations sil680_port_ops = {
26147 .inherits = &ata_bmdma32_port_ops,
26148 .sff_exec_command = sil680_sff_exec_command,
26149 .sff_irq_check = sil680_sff_irq_check,
26150diff -urNp linux-2.6.39.1/drivers/ata/pata_sis.c linux-2.6.39.1/drivers/ata/pata_sis.c
26151--- linux-2.6.39.1/drivers/ata/pata_sis.c 2011-05-19 00:06:34.000000000 -0400
26152+++ linux-2.6.39.1/drivers/ata/pata_sis.c 2011-05-22 19:36:31.000000000 -0400
26153@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
26154 ATA_BMDMA_SHT(DRV_NAME),
26155 };
26156
26157-static struct ata_port_operations sis_133_for_sata_ops = {
26158+static const struct ata_port_operations sis_133_for_sata_ops = {
26159 .inherits = &ata_bmdma_port_ops,
26160 .set_piomode = sis_133_set_piomode,
26161 .set_dmamode = sis_133_set_dmamode,
26162 .cable_detect = sis_133_cable_detect,
26163 };
26164
26165-static struct ata_port_operations sis_base_ops = {
26166+static const struct ata_port_operations sis_base_ops = {
26167 .inherits = &ata_bmdma_port_ops,
26168 .prereset = sis_pre_reset,
26169 };
26170
26171-static struct ata_port_operations sis_133_ops = {
26172+static const struct ata_port_operations sis_133_ops = {
26173 .inherits = &sis_base_ops,
26174 .set_piomode = sis_133_set_piomode,
26175 .set_dmamode = sis_133_set_dmamode,
26176 .cable_detect = sis_133_cable_detect,
26177 };
26178
26179-static struct ata_port_operations sis_133_early_ops = {
26180+static const struct ata_port_operations sis_133_early_ops = {
26181 .inherits = &sis_base_ops,
26182 .set_piomode = sis_100_set_piomode,
26183 .set_dmamode = sis_133_early_set_dmamode,
26184 .cable_detect = sis_66_cable_detect,
26185 };
26186
26187-static struct ata_port_operations sis_100_ops = {
26188+static const struct ata_port_operations sis_100_ops = {
26189 .inherits = &sis_base_ops,
26190 .set_piomode = sis_100_set_piomode,
26191 .set_dmamode = sis_100_set_dmamode,
26192 .cable_detect = sis_66_cable_detect,
26193 };
26194
26195-static struct ata_port_operations sis_66_ops = {
26196+static const struct ata_port_operations sis_66_ops = {
26197 .inherits = &sis_base_ops,
26198 .set_piomode = sis_old_set_piomode,
26199 .set_dmamode = sis_66_set_dmamode,
26200 .cable_detect = sis_66_cable_detect,
26201 };
26202
26203-static struct ata_port_operations sis_old_ops = {
26204+static const struct ata_port_operations sis_old_ops = {
26205 .inherits = &sis_base_ops,
26206 .set_piomode = sis_old_set_piomode,
26207 .set_dmamode = sis_old_set_dmamode,
26208diff -urNp linux-2.6.39.1/drivers/ata/pata_sl82c105.c linux-2.6.39.1/drivers/ata/pata_sl82c105.c
26209--- linux-2.6.39.1/drivers/ata/pata_sl82c105.c 2011-05-19 00:06:34.000000000 -0400
26210+++ linux-2.6.39.1/drivers/ata/pata_sl82c105.c 2011-05-22 19:36:31.000000000 -0400
26211@@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
26212 ATA_BMDMA_SHT(DRV_NAME),
26213 };
26214
26215-static struct ata_port_operations sl82c105_port_ops = {
26216+static const struct ata_port_operations sl82c105_port_ops = {
26217 .inherits = &ata_bmdma_port_ops,
26218 .qc_defer = sl82c105_qc_defer,
26219 .bmdma_start = sl82c105_bmdma_start,
26220diff -urNp linux-2.6.39.1/drivers/ata/pata_triflex.c linux-2.6.39.1/drivers/ata/pata_triflex.c
26221--- linux-2.6.39.1/drivers/ata/pata_triflex.c 2011-05-19 00:06:34.000000000 -0400
26222+++ linux-2.6.39.1/drivers/ata/pata_triflex.c 2011-05-22 19:36:31.000000000 -0400
26223@@ -178,7 +178,7 @@ static struct scsi_host_template triflex
26224 ATA_BMDMA_SHT(DRV_NAME),
26225 };
26226
26227-static struct ata_port_operations triflex_port_ops = {
26228+static const struct ata_port_operations triflex_port_ops = {
26229 .inherits = &ata_bmdma_port_ops,
26230 .bmdma_start = triflex_bmdma_start,
26231 .bmdma_stop = triflex_bmdma_stop,
26232diff -urNp linux-2.6.39.1/drivers/ata/pata_via.c linux-2.6.39.1/drivers/ata/pata_via.c
26233--- linux-2.6.39.1/drivers/ata/pata_via.c 2011-05-19 00:06:34.000000000 -0400
26234+++ linux-2.6.39.1/drivers/ata/pata_via.c 2011-05-22 19:36:31.000000000 -0400
26235@@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
26236 ATA_BMDMA_SHT(DRV_NAME),
26237 };
26238
26239-static struct ata_port_operations via_port_ops = {
26240+static const struct ata_port_operations via_port_ops = {
26241 .inherits = &ata_bmdma_port_ops,
26242 .cable_detect = via_cable_detect,
26243 .set_piomode = via_set_piomode,
26244@@ -452,7 +452,7 @@ static struct ata_port_operations via_po
26245 .mode_filter = via_mode_filter,
26246 };
26247
26248-static struct ata_port_operations via_port_ops_noirq = {
26249+static const struct ata_port_operations via_port_ops_noirq = {
26250 .inherits = &via_port_ops,
26251 .sff_data_xfer = ata_sff_data_xfer_noirq,
26252 };
26253diff -urNp linux-2.6.39.1/drivers/ata/pdc_adma.c linux-2.6.39.1/drivers/ata/pdc_adma.c
26254--- linux-2.6.39.1/drivers/ata/pdc_adma.c 2011-05-19 00:06:34.000000000 -0400
26255+++ linux-2.6.39.1/drivers/ata/pdc_adma.c 2011-05-22 19:36:31.000000000 -0400
26256@@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
26257 .dma_boundary = ADMA_DMA_BOUNDARY,
26258 };
26259
26260-static struct ata_port_operations adma_ata_ops = {
26261+static const struct ata_port_operations adma_ata_ops = {
26262 .inherits = &ata_sff_port_ops,
26263
26264 .lost_interrupt = ATA_OP_NULL,
26265diff -urNp linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c
26266--- linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c 2011-05-19 00:06:34.000000000 -0400
26267+++ linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c 2011-05-22 19:36:31.000000000 -0400
26268@@ -1598,7 +1598,7 @@ static struct scsi_host_template sata_dw
26269 .dma_boundary = ATA_DMA_BOUNDARY,
26270 };
26271
26272-static struct ata_port_operations sata_dwc_ops = {
26273+static const struct ata_port_operations sata_dwc_ops = {
26274 .inherits = &ata_sff_port_ops,
26275
26276 .error_handler = sata_dwc_error_handler,
26277diff -urNp linux-2.6.39.1/drivers/ata/sata_fsl.c linux-2.6.39.1/drivers/ata/sata_fsl.c
26278--- linux-2.6.39.1/drivers/ata/sata_fsl.c 2011-05-19 00:06:34.000000000 -0400
26279+++ linux-2.6.39.1/drivers/ata/sata_fsl.c 2011-05-22 19:36:31.000000000 -0400
26280@@ -1268,7 +1268,7 @@ static struct scsi_host_template sata_fs
26281 .dma_boundary = ATA_DMA_BOUNDARY,
26282 };
26283
26284-static struct ata_port_operations sata_fsl_ops = {
26285+static const struct ata_port_operations sata_fsl_ops = {
26286 .inherits = &sata_pmp_port_ops,
26287
26288 .qc_defer = ata_std_qc_defer,
26289diff -urNp linux-2.6.39.1/drivers/ata/sata_inic162x.c linux-2.6.39.1/drivers/ata/sata_inic162x.c
26290--- linux-2.6.39.1/drivers/ata/sata_inic162x.c 2011-05-19 00:06:34.000000000 -0400
26291+++ linux-2.6.39.1/drivers/ata/sata_inic162x.c 2011-05-22 19:36:31.000000000 -0400
26292@@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
26293 return 0;
26294 }
26295
26296-static struct ata_port_operations inic_port_ops = {
26297+static const struct ata_port_operations inic_port_ops = {
26298 .inherits = &sata_port_ops,
26299
26300 .check_atapi_dma = inic_check_atapi_dma,
26301diff -urNp linux-2.6.39.1/drivers/ata/sata_mv.c linux-2.6.39.1/drivers/ata/sata_mv.c
26302--- linux-2.6.39.1/drivers/ata/sata_mv.c 2011-05-19 00:06:34.000000000 -0400
26303+++ linux-2.6.39.1/drivers/ata/sata_mv.c 2011-05-22 19:36:31.000000000 -0400
26304@@ -662,7 +662,7 @@ static struct scsi_host_template mv6_sht
26305 .dma_boundary = MV_DMA_BOUNDARY,
26306 };
26307
26308-static struct ata_port_operations mv5_ops = {
26309+static const struct ata_port_operations mv5_ops = {
26310 .inherits = &ata_sff_port_ops,
26311
26312 .lost_interrupt = ATA_OP_NULL,
26313@@ -682,7 +682,7 @@ static struct ata_port_operations mv5_op
26314 .port_stop = mv_port_stop,
26315 };
26316
26317-static struct ata_port_operations mv6_ops = {
26318+static const struct ata_port_operations mv6_ops = {
26319 .inherits = &ata_bmdma_port_ops,
26320
26321 .lost_interrupt = ATA_OP_NULL,
26322@@ -716,7 +716,7 @@ static struct ata_port_operations mv6_op
26323 .port_stop = mv_port_stop,
26324 };
26325
26326-static struct ata_port_operations mv_iie_ops = {
26327+static const struct ata_port_operations mv_iie_ops = {
26328 .inherits = &mv6_ops,
26329 .dev_config = ATA_OP_NULL,
26330 .qc_prep = mv_qc_prep_iie,
26331diff -urNp linux-2.6.39.1/drivers/ata/sata_nv.c linux-2.6.39.1/drivers/ata/sata_nv.c
26332--- linux-2.6.39.1/drivers/ata/sata_nv.c 2011-05-19 00:06:34.000000000 -0400
26333+++ linux-2.6.39.1/drivers/ata/sata_nv.c 2011-05-22 19:36:31.000000000 -0400
26334@@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
26335 * cases. Define nv_hardreset() which only kicks in for post-boot
26336 * probing and use it for all variants.
26337 */
26338-static struct ata_port_operations nv_generic_ops = {
26339+static const struct ata_port_operations nv_generic_ops = {
26340 .inherits = &ata_bmdma_port_ops,
26341 .lost_interrupt = ATA_OP_NULL,
26342 .scr_read = nv_scr_read,
26343@@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
26344 .hardreset = nv_hardreset,
26345 };
26346
26347-static struct ata_port_operations nv_nf2_ops = {
26348+static const struct ata_port_operations nv_nf2_ops = {
26349 .inherits = &nv_generic_ops,
26350 .freeze = nv_nf2_freeze,
26351 .thaw = nv_nf2_thaw,
26352 };
26353
26354-static struct ata_port_operations nv_ck804_ops = {
26355+static const struct ata_port_operations nv_ck804_ops = {
26356 .inherits = &nv_generic_ops,
26357 .freeze = nv_ck804_freeze,
26358 .thaw = nv_ck804_thaw,
26359 .host_stop = nv_ck804_host_stop,
26360 };
26361
26362-static struct ata_port_operations nv_adma_ops = {
26363+static const struct ata_port_operations nv_adma_ops = {
26364 .inherits = &nv_ck804_ops,
26365
26366 .check_atapi_dma = nv_adma_check_atapi_dma,
26367@@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
26368 .host_stop = nv_adma_host_stop,
26369 };
26370
26371-static struct ata_port_operations nv_swncq_ops = {
26372+static const struct ata_port_operations nv_swncq_ops = {
26373 .inherits = &nv_generic_ops,
26374
26375 .qc_defer = ata_std_qc_defer,
26376diff -urNp linux-2.6.39.1/drivers/ata/sata_promise.c linux-2.6.39.1/drivers/ata/sata_promise.c
26377--- linux-2.6.39.1/drivers/ata/sata_promise.c 2011-05-19 00:06:34.000000000 -0400
26378+++ linux-2.6.39.1/drivers/ata/sata_promise.c 2011-05-22 19:36:31.000000000 -0400
26379@@ -194,7 +194,7 @@ static const struct ata_port_operations
26380 .error_handler = pdc_error_handler,
26381 };
26382
26383-static struct ata_port_operations pdc_sata_ops = {
26384+static const struct ata_port_operations pdc_sata_ops = {
26385 .inherits = &pdc_common_ops,
26386 .cable_detect = pdc_sata_cable_detect,
26387 .freeze = pdc_sata_freeze,
26388@@ -207,14 +207,14 @@ static struct ata_port_operations pdc_sa
26389
26390 /* First-generation chips need a more restrictive ->check_atapi_dma op,
26391 and ->freeze/thaw that ignore the hotplug controls. */
26392-static struct ata_port_operations pdc_old_sata_ops = {
26393+static const struct ata_port_operations pdc_old_sata_ops = {
26394 .inherits = &pdc_sata_ops,
26395 .freeze = pdc_freeze,
26396 .thaw = pdc_thaw,
26397 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
26398 };
26399
26400-static struct ata_port_operations pdc_pata_ops = {
26401+static const struct ata_port_operations pdc_pata_ops = {
26402 .inherits = &pdc_common_ops,
26403 .cable_detect = pdc_pata_cable_detect,
26404 .freeze = pdc_freeze,
26405diff -urNp linux-2.6.39.1/drivers/ata/sata_qstor.c linux-2.6.39.1/drivers/ata/sata_qstor.c
26406--- linux-2.6.39.1/drivers/ata/sata_qstor.c 2011-05-19 00:06:34.000000000 -0400
26407+++ linux-2.6.39.1/drivers/ata/sata_qstor.c 2011-05-22 19:36:31.000000000 -0400
26408@@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
26409 .dma_boundary = QS_DMA_BOUNDARY,
26410 };
26411
26412-static struct ata_port_operations qs_ata_ops = {
26413+static const struct ata_port_operations qs_ata_ops = {
26414 .inherits = &ata_sff_port_ops,
26415
26416 .check_atapi_dma = qs_check_atapi_dma,
26417diff -urNp linux-2.6.39.1/drivers/ata/sata_sil24.c linux-2.6.39.1/drivers/ata/sata_sil24.c
26418--- linux-2.6.39.1/drivers/ata/sata_sil24.c 2011-05-19 00:06:34.000000000 -0400
26419+++ linux-2.6.39.1/drivers/ata/sata_sil24.c 2011-05-22 19:36:31.000000000 -0400
26420@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
26421 .dma_boundary = ATA_DMA_BOUNDARY,
26422 };
26423
26424-static struct ata_port_operations sil24_ops = {
26425+static const struct ata_port_operations sil24_ops = {
26426 .inherits = &sata_pmp_port_ops,
26427
26428 .qc_defer = sil24_qc_defer,
26429diff -urNp linux-2.6.39.1/drivers/ata/sata_sil.c linux-2.6.39.1/drivers/ata/sata_sil.c
26430--- linux-2.6.39.1/drivers/ata/sata_sil.c 2011-05-19 00:06:34.000000000 -0400
26431+++ linux-2.6.39.1/drivers/ata/sata_sil.c 2011-05-22 19:36:31.000000000 -0400
26432@@ -181,7 +181,7 @@ static struct scsi_host_template sil_sht
26433 .sg_tablesize = ATA_MAX_PRD
26434 };
26435
26436-static struct ata_port_operations sil_ops = {
26437+static const struct ata_port_operations sil_ops = {
26438 .inherits = &ata_bmdma32_port_ops,
26439 .dev_config = sil_dev_config,
26440 .set_mode = sil_set_mode,
26441diff -urNp linux-2.6.39.1/drivers/ata/sata_sis.c linux-2.6.39.1/drivers/ata/sata_sis.c
26442--- linux-2.6.39.1/drivers/ata/sata_sis.c 2011-05-19 00:06:34.000000000 -0400
26443+++ linux-2.6.39.1/drivers/ata/sata_sis.c 2011-05-22 19:36:31.000000000 -0400
26444@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
26445 ATA_BMDMA_SHT(DRV_NAME),
26446 };
26447
26448-static struct ata_port_operations sis_ops = {
26449+static const struct ata_port_operations sis_ops = {
26450 .inherits = &ata_bmdma_port_ops,
26451 .scr_read = sis_scr_read,
26452 .scr_write = sis_scr_write,
26453diff -urNp linux-2.6.39.1/drivers/ata/sata_svw.c linux-2.6.39.1/drivers/ata/sata_svw.c
26454--- linux-2.6.39.1/drivers/ata/sata_svw.c 2011-05-19 00:06:34.000000000 -0400
26455+++ linux-2.6.39.1/drivers/ata/sata_svw.c 2011-05-22 19:36:31.000000000 -0400
26456@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
26457 };
26458
26459
26460-static struct ata_port_operations k2_sata_ops = {
26461+static const struct ata_port_operations k2_sata_ops = {
26462 .inherits = &ata_bmdma_port_ops,
26463 .sff_tf_load = k2_sata_tf_load,
26464 .sff_tf_read = k2_sata_tf_read,
26465diff -urNp linux-2.6.39.1/drivers/ata/sata_sx4.c linux-2.6.39.1/drivers/ata/sata_sx4.c
26466--- linux-2.6.39.1/drivers/ata/sata_sx4.c 2011-05-19 00:06:34.000000000 -0400
26467+++ linux-2.6.39.1/drivers/ata/sata_sx4.c 2011-05-22 19:36:31.000000000 -0400
26468@@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
26469 };
26470
26471 /* TODO: inherit from base port_ops after converting to new EH */
26472-static struct ata_port_operations pdc_20621_ops = {
26473+static const struct ata_port_operations pdc_20621_ops = {
26474 .inherits = &ata_sff_port_ops,
26475
26476 .check_atapi_dma = pdc_check_atapi_dma,
26477diff -urNp linux-2.6.39.1/drivers/ata/sata_uli.c linux-2.6.39.1/drivers/ata/sata_uli.c
26478--- linux-2.6.39.1/drivers/ata/sata_uli.c 2011-05-19 00:06:34.000000000 -0400
26479+++ linux-2.6.39.1/drivers/ata/sata_uli.c 2011-05-22 19:36:31.000000000 -0400
26480@@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
26481 ATA_BMDMA_SHT(DRV_NAME),
26482 };
26483
26484-static struct ata_port_operations uli_ops = {
26485+static const struct ata_port_operations uli_ops = {
26486 .inherits = &ata_bmdma_port_ops,
26487 .scr_read = uli_scr_read,
26488 .scr_write = uli_scr_write,
26489diff -urNp linux-2.6.39.1/drivers/ata/sata_via.c linux-2.6.39.1/drivers/ata/sata_via.c
26490--- linux-2.6.39.1/drivers/ata/sata_via.c 2011-05-19 00:06:34.000000000 -0400
26491+++ linux-2.6.39.1/drivers/ata/sata_via.c 2011-05-22 19:36:31.000000000 -0400
26492@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
26493 ATA_BMDMA_SHT(DRV_NAME),
26494 };
26495
26496-static struct ata_port_operations svia_base_ops = {
26497+static const struct ata_port_operations svia_base_ops = {
26498 .inherits = &ata_bmdma_port_ops,
26499 .sff_tf_load = svia_tf_load,
26500 };
26501
26502-static struct ata_port_operations vt6420_sata_ops = {
26503+static const struct ata_port_operations vt6420_sata_ops = {
26504 .inherits = &svia_base_ops,
26505 .freeze = svia_noop_freeze,
26506 .prereset = vt6420_prereset,
26507 .bmdma_start = vt6420_bmdma_start,
26508 };
26509
26510-static struct ata_port_operations vt6421_pata_ops = {
26511+static const struct ata_port_operations vt6421_pata_ops = {
26512 .inherits = &svia_base_ops,
26513 .cable_detect = vt6421_pata_cable_detect,
26514 .set_piomode = vt6421_set_pio_mode,
26515 .set_dmamode = vt6421_set_dma_mode,
26516 };
26517
26518-static struct ata_port_operations vt6421_sata_ops = {
26519+static const struct ata_port_operations vt6421_sata_ops = {
26520 .inherits = &svia_base_ops,
26521 .scr_read = svia_scr_read,
26522 .scr_write = svia_scr_write,
26523 };
26524
26525-static struct ata_port_operations vt8251_ops = {
26526+static const struct ata_port_operations vt8251_ops = {
26527 .inherits = &svia_base_ops,
26528 .hardreset = sata_std_hardreset,
26529 .scr_read = vt8251_scr_read,
26530diff -urNp linux-2.6.39.1/drivers/ata/sata_vsc.c linux-2.6.39.1/drivers/ata/sata_vsc.c
26531--- linux-2.6.39.1/drivers/ata/sata_vsc.c 2011-05-19 00:06:34.000000000 -0400
26532+++ linux-2.6.39.1/drivers/ata/sata_vsc.c 2011-05-22 19:36:31.000000000 -0400
26533@@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
26534 };
26535
26536
26537-static struct ata_port_operations vsc_sata_ops = {
26538+static const struct ata_port_operations vsc_sata_ops = {
26539 .inherits = &ata_bmdma_port_ops,
26540 /* The IRQ handling is not quite standard SFF behaviour so we
26541 cannot use the default lost interrupt handler */
26542diff -urNp linux-2.6.39.1/drivers/atm/adummy.c linux-2.6.39.1/drivers/atm/adummy.c
26543--- linux-2.6.39.1/drivers/atm/adummy.c 2011-05-19 00:06:34.000000000 -0400
26544+++ linux-2.6.39.1/drivers/atm/adummy.c 2011-05-22 19:36:31.000000000 -0400
26545@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
26546 vcc->pop(vcc, skb);
26547 else
26548 dev_kfree_skb_any(skb);
26549- atomic_inc(&vcc->stats->tx);
26550+ atomic_inc_unchecked(&vcc->stats->tx);
26551
26552 return 0;
26553 }
26554diff -urNp linux-2.6.39.1/drivers/atm/ambassador.c linux-2.6.39.1/drivers/atm/ambassador.c
26555--- linux-2.6.39.1/drivers/atm/ambassador.c 2011-05-19 00:06:34.000000000 -0400
26556+++ linux-2.6.39.1/drivers/atm/ambassador.c 2011-05-22 19:36:31.000000000 -0400
26557@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
26558 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26559
26560 // VC layer stats
26561- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26562+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26563
26564 // free the descriptor
26565 kfree (tx_descr);
26566@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
26567 dump_skb ("<<<", vc, skb);
26568
26569 // VC layer stats
26570- atomic_inc(&atm_vcc->stats->rx);
26571+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26572 __net_timestamp(skb);
26573 // end of our responsibility
26574 atm_vcc->push (atm_vcc, skb);
26575@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
26576 } else {
26577 PRINTK (KERN_INFO, "dropped over-size frame");
26578 // should we count this?
26579- atomic_inc(&atm_vcc->stats->rx_drop);
26580+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26581 }
26582
26583 } else {
26584@@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
26585 }
26586
26587 if (check_area (skb->data, skb->len)) {
26588- atomic_inc(&atm_vcc->stats->tx_err);
26589+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26590 return -ENOMEM; // ?
26591 }
26592
26593diff -urNp linux-2.6.39.1/drivers/atm/atmtcp.c linux-2.6.39.1/drivers/atm/atmtcp.c
26594--- linux-2.6.39.1/drivers/atm/atmtcp.c 2011-05-19 00:06:34.000000000 -0400
26595+++ linux-2.6.39.1/drivers/atm/atmtcp.c 2011-05-22 19:36:31.000000000 -0400
26596@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
26597 if (vcc->pop) vcc->pop(vcc,skb);
26598 else dev_kfree_skb(skb);
26599 if (dev_data) return 0;
26600- atomic_inc(&vcc->stats->tx_err);
26601+ atomic_inc_unchecked(&vcc->stats->tx_err);
26602 return -ENOLINK;
26603 }
26604 size = skb->len+sizeof(struct atmtcp_hdr);
26605@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
26606 if (!new_skb) {
26607 if (vcc->pop) vcc->pop(vcc,skb);
26608 else dev_kfree_skb(skb);
26609- atomic_inc(&vcc->stats->tx_err);
26610+ atomic_inc_unchecked(&vcc->stats->tx_err);
26611 return -ENOBUFS;
26612 }
26613 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26614@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
26615 if (vcc->pop) vcc->pop(vcc,skb);
26616 else dev_kfree_skb(skb);
26617 out_vcc->push(out_vcc,new_skb);
26618- atomic_inc(&vcc->stats->tx);
26619- atomic_inc(&out_vcc->stats->rx);
26620+ atomic_inc_unchecked(&vcc->stats->tx);
26621+ atomic_inc_unchecked(&out_vcc->stats->rx);
26622 return 0;
26623 }
26624
26625@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
26626 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26627 read_unlock(&vcc_sklist_lock);
26628 if (!out_vcc) {
26629- atomic_inc(&vcc->stats->tx_err);
26630+ atomic_inc_unchecked(&vcc->stats->tx_err);
26631 goto done;
26632 }
26633 skb_pull(skb,sizeof(struct atmtcp_hdr));
26634@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
26635 __net_timestamp(new_skb);
26636 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26637 out_vcc->push(out_vcc,new_skb);
26638- atomic_inc(&vcc->stats->tx);
26639- atomic_inc(&out_vcc->stats->rx);
26640+ atomic_inc_unchecked(&vcc->stats->tx);
26641+ atomic_inc_unchecked(&out_vcc->stats->rx);
26642 done:
26643 if (vcc->pop) vcc->pop(vcc,skb);
26644 else dev_kfree_skb(skb);
26645diff -urNp linux-2.6.39.1/drivers/atm/eni.c linux-2.6.39.1/drivers/atm/eni.c
26646--- linux-2.6.39.1/drivers/atm/eni.c 2011-05-19 00:06:34.000000000 -0400
26647+++ linux-2.6.39.1/drivers/atm/eni.c 2011-05-22 19:36:31.000000000 -0400
26648@@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26649 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26650 vcc->dev->number);
26651 length = 0;
26652- atomic_inc(&vcc->stats->rx_err);
26653+ atomic_inc_unchecked(&vcc->stats->rx_err);
26654 }
26655 else {
26656 length = ATM_CELL_SIZE-1; /* no HEC */
26657@@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26658 size);
26659 }
26660 eff = length = 0;
26661- atomic_inc(&vcc->stats->rx_err);
26662+ atomic_inc_unchecked(&vcc->stats->rx_err);
26663 }
26664 else {
26665 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26666@@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26667 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26668 vcc->dev->number,vcc->vci,length,size << 2,descr);
26669 length = eff = 0;
26670- atomic_inc(&vcc->stats->rx_err);
26671+ atomic_inc_unchecked(&vcc->stats->rx_err);
26672 }
26673 }
26674 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26675@@ -771,7 +771,7 @@ rx_dequeued++;
26676 vcc->push(vcc,skb);
26677 pushed++;
26678 }
26679- atomic_inc(&vcc->stats->rx);
26680+ atomic_inc_unchecked(&vcc->stats->rx);
26681 }
26682 wake_up(&eni_dev->rx_wait);
26683 }
26684@@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
26685 PCI_DMA_TODEVICE);
26686 if (vcc->pop) vcc->pop(vcc,skb);
26687 else dev_kfree_skb_irq(skb);
26688- atomic_inc(&vcc->stats->tx);
26689+ atomic_inc_unchecked(&vcc->stats->tx);
26690 wake_up(&eni_dev->tx_wait);
26691 dma_complete++;
26692 }
26693diff -urNp linux-2.6.39.1/drivers/atm/firestream.c linux-2.6.39.1/drivers/atm/firestream.c
26694--- linux-2.6.39.1/drivers/atm/firestream.c 2011-05-19 00:06:34.000000000 -0400
26695+++ linux-2.6.39.1/drivers/atm/firestream.c 2011-05-22 19:36:31.000000000 -0400
26696@@ -749,7 +749,7 @@ static void process_txdone_queue (struct
26697 }
26698 }
26699
26700- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26701+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26702
26703 fs_dprintk (FS_DEBUG_TXMEM, "i");
26704 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26705@@ -816,7 +816,7 @@ static void process_incoming (struct fs_
26706 #endif
26707 skb_put (skb, qe->p1 & 0xffff);
26708 ATM_SKB(skb)->vcc = atm_vcc;
26709- atomic_inc(&atm_vcc->stats->rx);
26710+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26711 __net_timestamp(skb);
26712 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26713 atm_vcc->push (atm_vcc, skb);
26714@@ -837,12 +837,12 @@ static void process_incoming (struct fs_
26715 kfree (pe);
26716 }
26717 if (atm_vcc)
26718- atomic_inc(&atm_vcc->stats->rx_drop);
26719+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26720 break;
26721 case 0x1f: /* Reassembly abort: no buffers. */
26722 /* Silently increment error counter. */
26723 if (atm_vcc)
26724- atomic_inc(&atm_vcc->stats->rx_drop);
26725+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26726 break;
26727 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26728 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26729diff -urNp linux-2.6.39.1/drivers/atm/fore200e.c linux-2.6.39.1/drivers/atm/fore200e.c
26730--- linux-2.6.39.1/drivers/atm/fore200e.c 2011-05-19 00:06:34.000000000 -0400
26731+++ linux-2.6.39.1/drivers/atm/fore200e.c 2011-05-22 19:36:31.000000000 -0400
26732@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
26733 #endif
26734 /* check error condition */
26735 if (*entry->status & STATUS_ERROR)
26736- atomic_inc(&vcc->stats->tx_err);
26737+ atomic_inc_unchecked(&vcc->stats->tx_err);
26738 else
26739- atomic_inc(&vcc->stats->tx);
26740+ atomic_inc_unchecked(&vcc->stats->tx);
26741 }
26742 }
26743
26744@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
26745 if (skb == NULL) {
26746 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26747
26748- atomic_inc(&vcc->stats->rx_drop);
26749+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26750 return -ENOMEM;
26751 }
26752
26753@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
26754
26755 dev_kfree_skb_any(skb);
26756
26757- atomic_inc(&vcc->stats->rx_drop);
26758+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26759 return -ENOMEM;
26760 }
26761
26762 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26763
26764 vcc->push(vcc, skb);
26765- atomic_inc(&vcc->stats->rx);
26766+ atomic_inc_unchecked(&vcc->stats->rx);
26767
26768 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26769
26770@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
26771 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26772 fore200e->atm_dev->number,
26773 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26774- atomic_inc(&vcc->stats->rx_err);
26775+ atomic_inc_unchecked(&vcc->stats->rx_err);
26776 }
26777 }
26778
26779@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26780 goto retry_here;
26781 }
26782
26783- atomic_inc(&vcc->stats->tx_err);
26784+ atomic_inc_unchecked(&vcc->stats->tx_err);
26785
26786 fore200e->tx_sat++;
26787 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26788diff -urNp linux-2.6.39.1/drivers/atm/he.c linux-2.6.39.1/drivers/atm/he.c
26789--- linux-2.6.39.1/drivers/atm/he.c 2011-05-19 00:06:34.000000000 -0400
26790+++ linux-2.6.39.1/drivers/atm/he.c 2011-05-22 19:36:31.000000000 -0400
26791@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26792
26793 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26794 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26795- atomic_inc(&vcc->stats->rx_drop);
26796+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26797 goto return_host_buffers;
26798 }
26799
26800@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26801 RBRQ_LEN_ERR(he_dev->rbrq_head)
26802 ? "LEN_ERR" : "",
26803 vcc->vpi, vcc->vci);
26804- atomic_inc(&vcc->stats->rx_err);
26805+ atomic_inc_unchecked(&vcc->stats->rx_err);
26806 goto return_host_buffers;
26807 }
26808
26809@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26810 vcc->push(vcc, skb);
26811 spin_lock(&he_dev->global_lock);
26812
26813- atomic_inc(&vcc->stats->rx);
26814+ atomic_inc_unchecked(&vcc->stats->rx);
26815
26816 return_host_buffers:
26817 ++pdus_assembled;
26818@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26819 tpd->vcc->pop(tpd->vcc, tpd->skb);
26820 else
26821 dev_kfree_skb_any(tpd->skb);
26822- atomic_inc(&tpd->vcc->stats->tx_err);
26823+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26824 }
26825 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26826 return;
26827@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26828 vcc->pop(vcc, skb);
26829 else
26830 dev_kfree_skb_any(skb);
26831- atomic_inc(&vcc->stats->tx_err);
26832+ atomic_inc_unchecked(&vcc->stats->tx_err);
26833 return -EINVAL;
26834 }
26835
26836@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26837 vcc->pop(vcc, skb);
26838 else
26839 dev_kfree_skb_any(skb);
26840- atomic_inc(&vcc->stats->tx_err);
26841+ atomic_inc_unchecked(&vcc->stats->tx_err);
26842 return -EINVAL;
26843 }
26844 #endif
26845@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26846 vcc->pop(vcc, skb);
26847 else
26848 dev_kfree_skb_any(skb);
26849- atomic_inc(&vcc->stats->tx_err);
26850+ atomic_inc_unchecked(&vcc->stats->tx_err);
26851 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26852 return -ENOMEM;
26853 }
26854@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26855 vcc->pop(vcc, skb);
26856 else
26857 dev_kfree_skb_any(skb);
26858- atomic_inc(&vcc->stats->tx_err);
26859+ atomic_inc_unchecked(&vcc->stats->tx_err);
26860 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26861 return -ENOMEM;
26862 }
26863@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26864 __enqueue_tpd(he_dev, tpd, cid);
26865 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26866
26867- atomic_inc(&vcc->stats->tx);
26868+ atomic_inc_unchecked(&vcc->stats->tx);
26869
26870 return 0;
26871 }
26872diff -urNp linux-2.6.39.1/drivers/atm/horizon.c linux-2.6.39.1/drivers/atm/horizon.c
26873--- linux-2.6.39.1/drivers/atm/horizon.c 2011-05-19 00:06:34.000000000 -0400
26874+++ linux-2.6.39.1/drivers/atm/horizon.c 2011-05-22 19:36:31.000000000 -0400
26875@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
26876 {
26877 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26878 // VC layer stats
26879- atomic_inc(&vcc->stats->rx);
26880+ atomic_inc_unchecked(&vcc->stats->rx);
26881 __net_timestamp(skb);
26882 // end of our responsibility
26883 vcc->push (vcc, skb);
26884@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
26885 dev->tx_iovec = NULL;
26886
26887 // VC layer stats
26888- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26889+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26890
26891 // free the skb
26892 hrz_kfree_skb (skb);
26893diff -urNp linux-2.6.39.1/drivers/atm/idt77252.c linux-2.6.39.1/drivers/atm/idt77252.c
26894--- linux-2.6.39.1/drivers/atm/idt77252.c 2011-05-19 00:06:34.000000000 -0400
26895+++ linux-2.6.39.1/drivers/atm/idt77252.c 2011-05-22 19:36:31.000000000 -0400
26896@@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
26897 else
26898 dev_kfree_skb(skb);
26899
26900- atomic_inc(&vcc->stats->tx);
26901+ atomic_inc_unchecked(&vcc->stats->tx);
26902 }
26903
26904 atomic_dec(&scq->used);
26905@@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
26906 if ((sb = dev_alloc_skb(64)) == NULL) {
26907 printk("%s: Can't allocate buffers for aal0.\n",
26908 card->name);
26909- atomic_add(i, &vcc->stats->rx_drop);
26910+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
26911 break;
26912 }
26913 if (!atm_charge(vcc, sb->truesize)) {
26914 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26915 card->name);
26916- atomic_add(i - 1, &vcc->stats->rx_drop);
26917+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26918 dev_kfree_skb(sb);
26919 break;
26920 }
26921@@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
26922 ATM_SKB(sb)->vcc = vcc;
26923 __net_timestamp(sb);
26924 vcc->push(vcc, sb);
26925- atomic_inc(&vcc->stats->rx);
26926+ atomic_inc_unchecked(&vcc->stats->rx);
26927
26928 cell += ATM_CELL_PAYLOAD;
26929 }
26930@@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
26931 "(CDC: %08x)\n",
26932 card->name, len, rpp->len, readl(SAR_REG_CDC));
26933 recycle_rx_pool_skb(card, rpp);
26934- atomic_inc(&vcc->stats->rx_err);
26935+ atomic_inc_unchecked(&vcc->stats->rx_err);
26936 return;
26937 }
26938 if (stat & SAR_RSQE_CRC) {
26939 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26940 recycle_rx_pool_skb(card, rpp);
26941- atomic_inc(&vcc->stats->rx_err);
26942+ atomic_inc_unchecked(&vcc->stats->rx_err);
26943 return;
26944 }
26945 if (skb_queue_len(&rpp->queue) > 1) {
26946@@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
26947 RXPRINTK("%s: Can't alloc RX skb.\n",
26948 card->name);
26949 recycle_rx_pool_skb(card, rpp);
26950- atomic_inc(&vcc->stats->rx_err);
26951+ atomic_inc_unchecked(&vcc->stats->rx_err);
26952 return;
26953 }
26954 if (!atm_charge(vcc, skb->truesize)) {
26955@@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
26956 __net_timestamp(skb);
26957
26958 vcc->push(vcc, skb);
26959- atomic_inc(&vcc->stats->rx);
26960+ atomic_inc_unchecked(&vcc->stats->rx);
26961
26962 return;
26963 }
26964@@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
26965 __net_timestamp(skb);
26966
26967 vcc->push(vcc, skb);
26968- atomic_inc(&vcc->stats->rx);
26969+ atomic_inc_unchecked(&vcc->stats->rx);
26970
26971 if (skb->truesize > SAR_FB_SIZE_3)
26972 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26973@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26974 if (vcc->qos.aal != ATM_AAL0) {
26975 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26976 card->name, vpi, vci);
26977- atomic_inc(&vcc->stats->rx_drop);
26978+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26979 goto drop;
26980 }
26981
26982 if ((sb = dev_alloc_skb(64)) == NULL) {
26983 printk("%s: Can't allocate buffers for AAL0.\n",
26984 card->name);
26985- atomic_inc(&vcc->stats->rx_err);
26986+ atomic_inc_unchecked(&vcc->stats->rx_err);
26987 goto drop;
26988 }
26989
26990@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26991 ATM_SKB(sb)->vcc = vcc;
26992 __net_timestamp(sb);
26993 vcc->push(vcc, sb);
26994- atomic_inc(&vcc->stats->rx);
26995+ atomic_inc_unchecked(&vcc->stats->rx);
26996
26997 drop:
26998 skb_pull(queue, 64);
26999@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27000
27001 if (vc == NULL) {
27002 printk("%s: NULL connection in send().\n", card->name);
27003- atomic_inc(&vcc->stats->tx_err);
27004+ atomic_inc_unchecked(&vcc->stats->tx_err);
27005 dev_kfree_skb(skb);
27006 return -EINVAL;
27007 }
27008 if (!test_bit(VCF_TX, &vc->flags)) {
27009 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27010- atomic_inc(&vcc->stats->tx_err);
27011+ atomic_inc_unchecked(&vcc->stats->tx_err);
27012 dev_kfree_skb(skb);
27013 return -EINVAL;
27014 }
27015@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27016 break;
27017 default:
27018 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27019- atomic_inc(&vcc->stats->tx_err);
27020+ atomic_inc_unchecked(&vcc->stats->tx_err);
27021 dev_kfree_skb(skb);
27022 return -EINVAL;
27023 }
27024
27025 if (skb_shinfo(skb)->nr_frags != 0) {
27026 printk("%s: No scatter-gather yet.\n", card->name);
27027- atomic_inc(&vcc->stats->tx_err);
27028+ atomic_inc_unchecked(&vcc->stats->tx_err);
27029 dev_kfree_skb(skb);
27030 return -EINVAL;
27031 }
27032@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27033
27034 err = queue_skb(card, vc, skb, oam);
27035 if (err) {
27036- atomic_inc(&vcc->stats->tx_err);
27037+ atomic_inc_unchecked(&vcc->stats->tx_err);
27038 dev_kfree_skb(skb);
27039 return err;
27040 }
27041@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
27042 skb = dev_alloc_skb(64);
27043 if (!skb) {
27044 printk("%s: Out of memory in send_oam().\n", card->name);
27045- atomic_inc(&vcc->stats->tx_err);
27046+ atomic_inc_unchecked(&vcc->stats->tx_err);
27047 return -ENOMEM;
27048 }
27049 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27050diff -urNp linux-2.6.39.1/drivers/atm/iphase.c linux-2.6.39.1/drivers/atm/iphase.c
27051--- linux-2.6.39.1/drivers/atm/iphase.c 2011-05-19 00:06:34.000000000 -0400
27052+++ linux-2.6.39.1/drivers/atm/iphase.c 2011-05-22 19:36:31.000000000 -0400
27053@@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
27054 status = (u_short) (buf_desc_ptr->desc_mode);
27055 if (status & (RX_CER | RX_PTE | RX_OFL))
27056 {
27057- atomic_inc(&vcc->stats->rx_err);
27058+ atomic_inc_unchecked(&vcc->stats->rx_err);
27059 IF_ERR(printk("IA: bad packet, dropping it");)
27060 if (status & RX_CER) {
27061 IF_ERR(printk(" cause: packet CRC error\n");)
27062@@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
27063 len = dma_addr - buf_addr;
27064 if (len > iadev->rx_buf_sz) {
27065 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27066- atomic_inc(&vcc->stats->rx_err);
27067+ atomic_inc_unchecked(&vcc->stats->rx_err);
27068 goto out_free_desc;
27069 }
27070
27071@@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
27072 ia_vcc = INPH_IA_VCC(vcc);
27073 if (ia_vcc == NULL)
27074 {
27075- atomic_inc(&vcc->stats->rx_err);
27076+ atomic_inc_unchecked(&vcc->stats->rx_err);
27077 dev_kfree_skb_any(skb);
27078 atm_return(vcc, atm_guess_pdu2truesize(len));
27079 goto INCR_DLE;
27080@@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
27081 if ((length > iadev->rx_buf_sz) || (length >
27082 (skb->len - sizeof(struct cpcs_trailer))))
27083 {
27084- atomic_inc(&vcc->stats->rx_err);
27085+ atomic_inc_unchecked(&vcc->stats->rx_err);
27086 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27087 length, skb->len);)
27088 dev_kfree_skb_any(skb);
27089@@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
27090
27091 IF_RX(printk("rx_dle_intr: skb push");)
27092 vcc->push(vcc,skb);
27093- atomic_inc(&vcc->stats->rx);
27094+ atomic_inc_unchecked(&vcc->stats->rx);
27095 iadev->rx_pkt_cnt++;
27096 }
27097 INCR_DLE:
27098@@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
27099 {
27100 struct k_sonet_stats *stats;
27101 stats = &PRIV(_ia_dev[board])->sonet_stats;
27102- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27103- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27104- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27105- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27106- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27107- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27108- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27109- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27110- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27111+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27112+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27113+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27114+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27115+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27116+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27117+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27118+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27119+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27120 }
27121 ia_cmds.status = 0;
27122 break;
27123@@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
27124 if ((desc == 0) || (desc > iadev->num_tx_desc))
27125 {
27126 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27127- atomic_inc(&vcc->stats->tx);
27128+ atomic_inc_unchecked(&vcc->stats->tx);
27129 if (vcc->pop)
27130 vcc->pop(vcc, skb);
27131 else
27132@@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
27133 ATM_DESC(skb) = vcc->vci;
27134 skb_queue_tail(&iadev->tx_dma_q, skb);
27135
27136- atomic_inc(&vcc->stats->tx);
27137+ atomic_inc_unchecked(&vcc->stats->tx);
27138 iadev->tx_pkt_cnt++;
27139 /* Increment transaction counter */
27140 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27141
27142 #if 0
27143 /* add flow control logic */
27144- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27145+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27146 if (iavcc->vc_desc_cnt > 10) {
27147 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27148 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27149diff -urNp linux-2.6.39.1/drivers/atm/lanai.c linux-2.6.39.1/drivers/atm/lanai.c
27150--- linux-2.6.39.1/drivers/atm/lanai.c 2011-05-19 00:06:34.000000000 -0400
27151+++ linux-2.6.39.1/drivers/atm/lanai.c 2011-05-22 19:36:31.000000000 -0400
27152@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
27153 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27154 lanai_endtx(lanai, lvcc);
27155 lanai_free_skb(lvcc->tx.atmvcc, skb);
27156- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27157+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27158 }
27159
27160 /* Try to fill the buffer - don't call unless there is backlog */
27161@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
27162 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27163 __net_timestamp(skb);
27164 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27165- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27166+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27167 out:
27168 lvcc->rx.buf.ptr = end;
27169 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27170@@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
27171 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27172 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27173 lanai->stats.service_rxnotaal5++;
27174- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27175+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27176 return 0;
27177 }
27178 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27179@@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
27180 int bytes;
27181 read_unlock(&vcc_sklist_lock);
27182 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27183- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27184+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27185 lvcc->stats.x.aal5.service_trash++;
27186 bytes = (SERVICE_GET_END(s) * 16) -
27187 (((unsigned long) lvcc->rx.buf.ptr) -
27188@@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
27189 }
27190 if (s & SERVICE_STREAM) {
27191 read_unlock(&vcc_sklist_lock);
27192- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27193+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27194 lvcc->stats.x.aal5.service_stream++;
27195 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27196 "PDU on VCI %d!\n", lanai->number, vci);
27197@@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
27198 return 0;
27199 }
27200 DPRINTK("got rx crc error on vci %d\n", vci);
27201- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27202+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27203 lvcc->stats.x.aal5.service_rxcrc++;
27204 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27205 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27206diff -urNp linux-2.6.39.1/drivers/atm/nicstar.c linux-2.6.39.1/drivers/atm/nicstar.c
27207--- linux-2.6.39.1/drivers/atm/nicstar.c 2011-05-19 00:06:34.000000000 -0400
27208+++ linux-2.6.39.1/drivers/atm/nicstar.c 2011-05-22 19:36:31.000000000 -0400
27209@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
27210 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27211 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27212 card->index);
27213- atomic_inc(&vcc->stats->tx_err);
27214+ atomic_inc_unchecked(&vcc->stats->tx_err);
27215 dev_kfree_skb_any(skb);
27216 return -EINVAL;
27217 }
27218@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
27219 if (!vc->tx) {
27220 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27221 card->index);
27222- atomic_inc(&vcc->stats->tx_err);
27223+ atomic_inc_unchecked(&vcc->stats->tx_err);
27224 dev_kfree_skb_any(skb);
27225 return -EINVAL;
27226 }
27227@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
27228 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27229 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27230 card->index);
27231- atomic_inc(&vcc->stats->tx_err);
27232+ atomic_inc_unchecked(&vcc->stats->tx_err);
27233 dev_kfree_skb_any(skb);
27234 return -EINVAL;
27235 }
27236
27237 if (skb_shinfo(skb)->nr_frags != 0) {
27238 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27239- atomic_inc(&vcc->stats->tx_err);
27240+ atomic_inc_unchecked(&vcc->stats->tx_err);
27241 dev_kfree_skb_any(skb);
27242 return -EINVAL;
27243 }
27244@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
27245 }
27246
27247 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27248- atomic_inc(&vcc->stats->tx_err);
27249+ atomic_inc_unchecked(&vcc->stats->tx_err);
27250 dev_kfree_skb_any(skb);
27251 return -EIO;
27252 }
27253- atomic_inc(&vcc->stats->tx);
27254+ atomic_inc_unchecked(&vcc->stats->tx);
27255
27256 return 0;
27257 }
27258@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
27259 printk
27260 ("nicstar%d: Can't allocate buffers for aal0.\n",
27261 card->index);
27262- atomic_add(i, &vcc->stats->rx_drop);
27263+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
27264 break;
27265 }
27266 if (!atm_charge(vcc, sb->truesize)) {
27267 RXPRINTK
27268 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27269 card->index);
27270- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27271+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27272 dev_kfree_skb_any(sb);
27273 break;
27274 }
27275@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
27276 ATM_SKB(sb)->vcc = vcc;
27277 __net_timestamp(sb);
27278 vcc->push(vcc, sb);
27279- atomic_inc(&vcc->stats->rx);
27280+ atomic_inc_unchecked(&vcc->stats->rx);
27281 cell += ATM_CELL_PAYLOAD;
27282 }
27283
27284@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
27285 if (iovb == NULL) {
27286 printk("nicstar%d: Out of iovec buffers.\n",
27287 card->index);
27288- atomic_inc(&vcc->stats->rx_drop);
27289+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27290 recycle_rx_buf(card, skb);
27291 return;
27292 }
27293@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
27294 small or large buffer itself. */
27295 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27296 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27297- atomic_inc(&vcc->stats->rx_err);
27298+ atomic_inc_unchecked(&vcc->stats->rx_err);
27299 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27300 NS_MAX_IOVECS);
27301 NS_PRV_IOVCNT(iovb) = 0;
27302@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
27303 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27304 card->index);
27305 which_list(card, skb);
27306- atomic_inc(&vcc->stats->rx_err);
27307+ atomic_inc_unchecked(&vcc->stats->rx_err);
27308 recycle_rx_buf(card, skb);
27309 vc->rx_iov = NULL;
27310 recycle_iov_buf(card, iovb);
27311@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
27312 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27313 card->index);
27314 which_list(card, skb);
27315- atomic_inc(&vcc->stats->rx_err);
27316+ atomic_inc_unchecked(&vcc->stats->rx_err);
27317 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27318 NS_PRV_IOVCNT(iovb));
27319 vc->rx_iov = NULL;
27320@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
27321 printk(" - PDU size mismatch.\n");
27322 else
27323 printk(".\n");
27324- atomic_inc(&vcc->stats->rx_err);
27325+ atomic_inc_unchecked(&vcc->stats->rx_err);
27326 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27327 NS_PRV_IOVCNT(iovb));
27328 vc->rx_iov = NULL;
27329@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
27330 /* skb points to a small buffer */
27331 if (!atm_charge(vcc, skb->truesize)) {
27332 push_rxbufs(card, skb);
27333- atomic_inc(&vcc->stats->rx_drop);
27334+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27335 } else {
27336 skb_put(skb, len);
27337 dequeue_sm_buf(card, skb);
27338@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
27339 ATM_SKB(skb)->vcc = vcc;
27340 __net_timestamp(skb);
27341 vcc->push(vcc, skb);
27342- atomic_inc(&vcc->stats->rx);
27343+ atomic_inc_unchecked(&vcc->stats->rx);
27344 }
27345 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27346 struct sk_buff *sb;
27347@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
27348 if (len <= NS_SMBUFSIZE) {
27349 if (!atm_charge(vcc, sb->truesize)) {
27350 push_rxbufs(card, sb);
27351- atomic_inc(&vcc->stats->rx_drop);
27352+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27353 } else {
27354 skb_put(sb, len);
27355 dequeue_sm_buf(card, sb);
27356@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
27357 ATM_SKB(sb)->vcc = vcc;
27358 __net_timestamp(sb);
27359 vcc->push(vcc, sb);
27360- atomic_inc(&vcc->stats->rx);
27361+ atomic_inc_unchecked(&vcc->stats->rx);
27362 }
27363
27364 push_rxbufs(card, skb);
27365@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
27366
27367 if (!atm_charge(vcc, skb->truesize)) {
27368 push_rxbufs(card, skb);
27369- atomic_inc(&vcc->stats->rx_drop);
27370+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27371 } else {
27372 dequeue_lg_buf(card, skb);
27373 #ifdef NS_USE_DESTRUCTORS
27374@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
27375 ATM_SKB(skb)->vcc = vcc;
27376 __net_timestamp(skb);
27377 vcc->push(vcc, skb);
27378- atomic_inc(&vcc->stats->rx);
27379+ atomic_inc_unchecked(&vcc->stats->rx);
27380 }
27381
27382 push_rxbufs(card, sb);
27383@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
27384 printk
27385 ("nicstar%d: Out of huge buffers.\n",
27386 card->index);
27387- atomic_inc(&vcc->stats->rx_drop);
27388+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27389 recycle_iovec_rx_bufs(card,
27390 (struct iovec *)
27391 iovb->data,
27392@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
27393 card->hbpool.count++;
27394 } else
27395 dev_kfree_skb_any(hb);
27396- atomic_inc(&vcc->stats->rx_drop);
27397+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27398 } else {
27399 /* Copy the small buffer to the huge buffer */
27400 sb = (struct sk_buff *)iov->iov_base;
27401@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
27402 #endif /* NS_USE_DESTRUCTORS */
27403 __net_timestamp(hb);
27404 vcc->push(vcc, hb);
27405- atomic_inc(&vcc->stats->rx);
27406+ atomic_inc_unchecked(&vcc->stats->rx);
27407 }
27408 }
27409
27410diff -urNp linux-2.6.39.1/drivers/atm/solos-pci.c linux-2.6.39.1/drivers/atm/solos-pci.c
27411--- linux-2.6.39.1/drivers/atm/solos-pci.c 2011-05-19 00:06:34.000000000 -0400
27412+++ linux-2.6.39.1/drivers/atm/solos-pci.c 2011-05-22 19:36:31.000000000 -0400
27413@@ -715,7 +715,7 @@ void solos_bh(unsigned long card_arg)
27414 }
27415 atm_charge(vcc, skb->truesize);
27416 vcc->push(vcc, skb);
27417- atomic_inc(&vcc->stats->rx);
27418+ atomic_inc_unchecked(&vcc->stats->rx);
27419 break;
27420
27421 case PKT_STATUS:
27422@@ -900,6 +900,8 @@ static int print_buffer(struct sk_buff *
27423 char msg[500];
27424 char item[10];
27425
27426+ pax_track_stack();
27427+
27428 len = buf->len;
27429 for (i = 0; i < len; i++){
27430 if(i % 8 == 0)
27431@@ -1009,7 +1011,7 @@ static uint32_t fpga_tx(struct solos_car
27432 vcc = SKB_CB(oldskb)->vcc;
27433
27434 if (vcc) {
27435- atomic_inc(&vcc->stats->tx);
27436+ atomic_inc_unchecked(&vcc->stats->tx);
27437 solos_pop(vcc, oldskb);
27438 } else
27439 dev_kfree_skb_irq(oldskb);
27440diff -urNp linux-2.6.39.1/drivers/atm/suni.c linux-2.6.39.1/drivers/atm/suni.c
27441--- linux-2.6.39.1/drivers/atm/suni.c 2011-05-19 00:06:34.000000000 -0400
27442+++ linux-2.6.39.1/drivers/atm/suni.c 2011-05-22 19:36:31.000000000 -0400
27443@@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27444
27445
27446 #define ADD_LIMITED(s,v) \
27447- atomic_add((v),&stats->s); \
27448- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27449+ atomic_add_unchecked((v),&stats->s); \
27450+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27451
27452
27453 static void suni_hz(unsigned long from_timer)
27454diff -urNp linux-2.6.39.1/drivers/atm/uPD98402.c linux-2.6.39.1/drivers/atm/uPD98402.c
27455--- linux-2.6.39.1/drivers/atm/uPD98402.c 2011-05-19 00:06:34.000000000 -0400
27456+++ linux-2.6.39.1/drivers/atm/uPD98402.c 2011-05-22 19:36:31.000000000 -0400
27457@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
27458 struct sonet_stats tmp;
27459 int error = 0;
27460
27461- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27462+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27463 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27464 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27465 if (zero && !error) {
27466@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
27467
27468
27469 #define ADD_LIMITED(s,v) \
27470- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27471- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27472- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27473+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27474+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27475+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27476
27477
27478 static void stat_event(struct atm_dev *dev)
27479@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
27480 if (reason & uPD98402_INT_PFM) stat_event(dev);
27481 if (reason & uPD98402_INT_PCO) {
27482 (void) GET(PCOCR); /* clear interrupt cause */
27483- atomic_add(GET(HECCT),
27484+ atomic_add_unchecked(GET(HECCT),
27485 &PRIV(dev)->sonet_stats.uncorr_hcs);
27486 }
27487 if ((reason & uPD98402_INT_RFO) &&
27488@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
27489 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27490 uPD98402_INT_LOS),PIMR); /* enable them */
27491 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27492- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27493- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27494- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27495+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27496+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27497+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27498 return 0;
27499 }
27500
27501diff -urNp linux-2.6.39.1/drivers/atm/zatm.c linux-2.6.39.1/drivers/atm/zatm.c
27502--- linux-2.6.39.1/drivers/atm/zatm.c 2011-05-19 00:06:34.000000000 -0400
27503+++ linux-2.6.39.1/drivers/atm/zatm.c 2011-05-22 19:36:31.000000000 -0400
27504@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27505 }
27506 if (!size) {
27507 dev_kfree_skb_irq(skb);
27508- if (vcc) atomic_inc(&vcc->stats->rx_err);
27509+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27510 continue;
27511 }
27512 if (!atm_charge(vcc,skb->truesize)) {
27513@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27514 skb->len = size;
27515 ATM_SKB(skb)->vcc = vcc;
27516 vcc->push(vcc,skb);
27517- atomic_inc(&vcc->stats->rx);
27518+ atomic_inc_unchecked(&vcc->stats->rx);
27519 }
27520 zout(pos & 0xffff,MTA(mbx));
27521 #if 0 /* probably a stupid idea */
27522@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
27523 skb_queue_head(&zatm_vcc->backlog,skb);
27524 break;
27525 }
27526- atomic_inc(&vcc->stats->tx);
27527+ atomic_inc_unchecked(&vcc->stats->tx);
27528 wake_up(&zatm_vcc->tx_wait);
27529 }
27530
27531diff -urNp linux-2.6.39.1/drivers/base/iommu.c linux-2.6.39.1/drivers/base/iommu.c
27532--- linux-2.6.39.1/drivers/base/iommu.c 2011-05-19 00:06:34.000000000 -0400
27533+++ linux-2.6.39.1/drivers/base/iommu.c 2011-05-22 19:36:31.000000000 -0400
27534@@ -23,9 +23,8 @@
27535 #include <linux/errno.h>
27536 #include <linux/iommu.h>
27537
27538-static struct iommu_ops *iommu_ops;
27539-
27540-void register_iommu(struct iommu_ops *ops)
27541+static const struct iommu_ops *iommu_ops;
27542+void register_iommu(const struct iommu_ops *ops)
27543 {
27544 if (iommu_ops)
27545 BUG();
27546diff -urNp linux-2.6.39.1/drivers/base/power/generic_ops.c linux-2.6.39.1/drivers/base/power/generic_ops.c
27547--- linux-2.6.39.1/drivers/base/power/generic_ops.c 2011-05-19 00:06:34.000000000 -0400
27548+++ linux-2.6.39.1/drivers/base/power/generic_ops.c 2011-05-22 19:36:31.000000000 -0400
27549@@ -215,7 +215,7 @@ int pm_generic_restore(struct device *de
27550 EXPORT_SYMBOL_GPL(pm_generic_restore);
27551 #endif /* CONFIG_PM_SLEEP */
27552
27553-struct dev_pm_ops generic_subsys_pm_ops = {
27554+const struct dev_pm_ops generic_subsys_pm_ops = {
27555 #ifdef CONFIG_PM_SLEEP
27556 .suspend = pm_generic_suspend,
27557 .resume = pm_generic_resume,
27558diff -urNp linux-2.6.39.1/drivers/base/power/wakeup.c linux-2.6.39.1/drivers/base/power/wakeup.c
27559--- linux-2.6.39.1/drivers/base/power/wakeup.c 2011-05-19 00:06:34.000000000 -0400
27560+++ linux-2.6.39.1/drivers/base/power/wakeup.c 2011-05-22 19:36:31.000000000 -0400
27561@@ -29,14 +29,14 @@ bool events_check_enabled;
27562 * They need to be modified together atomically, so it's better to use one
27563 * atomic variable to hold them both.
27564 */
27565-static atomic_t combined_event_count = ATOMIC_INIT(0);
27566+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27567
27568 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27569 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27570
27571 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27572 {
27573- unsigned int comb = atomic_read(&combined_event_count);
27574+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
27575
27576 *cnt = (comb >> IN_PROGRESS_BITS);
27577 *inpr = comb & MAX_IN_PROGRESS;
27578@@ -351,7 +351,7 @@ static void wakeup_source_activate(struc
27579 ws->last_time = ktime_get();
27580
27581 /* Increment the counter of events in progress. */
27582- atomic_inc(&combined_event_count);
27583+ atomic_inc_unchecked(&combined_event_count);
27584 }
27585
27586 /**
27587@@ -441,7 +441,7 @@ static void wakeup_source_deactivate(str
27588 * Increment the counter of registered wakeup events and decrement the
27589 * couter of wakeup events in progress simultaneously.
27590 */
27591- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27592+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27593 }
27594
27595 /**
27596diff -urNp linux-2.6.39.1/drivers/block/cciss.c linux-2.6.39.1/drivers/block/cciss.c
27597--- linux-2.6.39.1/drivers/block/cciss.c 2011-05-19 00:06:34.000000000 -0400
27598+++ linux-2.6.39.1/drivers/block/cciss.c 2011-05-22 19:41:32.000000000 -0400
27599@@ -103,7 +103,7 @@ MODULE_DEVICE_TABLE(pci, cciss_pci_devic
27600 * product = Marketing Name for the board
27601 * access = Address of the struct of function pointers
27602 */
27603-static struct board_type products[] = {
27604+static const struct board_type products[] = {
27605 {0x40700E11, "Smart Array 5300", &SA5_access},
27606 {0x40800E11, "Smart Array 5i", &SA5B_access},
27607 {0x40820E11, "Smart Array 532", &SA5B_access},
27608@@ -1151,6 +1151,8 @@ static int cciss_ioctl32_passthru(struct
27609 int err;
27610 u32 cp;
27611
27612+ memset(&arg64, 0, sizeof(arg64));
27613+
27614 err = 0;
27615 err |=
27616 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27617diff -urNp linux-2.6.39.1/drivers/block/cciss.h linux-2.6.39.1/drivers/block/cciss.h
27618--- linux-2.6.39.1/drivers/block/cciss.h 2011-05-19 00:06:34.000000000 -0400
27619+++ linux-2.6.39.1/drivers/block/cciss.h 2011-05-22 19:36:31.000000000 -0400
27620@@ -393,7 +393,7 @@ static bool SA5_performant_intr_pending(
27621 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
27622 }
27623
27624-static struct access_method SA5_access = {
27625+static const struct access_method SA5_access = {
27626 SA5_submit_command,
27627 SA5_intr_mask,
27628 SA5_fifo_full,
27629@@ -401,7 +401,7 @@ static struct access_method SA5_access =
27630 SA5_completed,
27631 };
27632
27633-static struct access_method SA5B_access = {
27634+static const struct access_method SA5B_access = {
27635 SA5_submit_command,
27636 SA5B_intr_mask,
27637 SA5_fifo_full,
27638@@ -409,7 +409,7 @@ static struct access_method SA5B_access
27639 SA5_completed,
27640 };
27641
27642-static struct access_method SA5_performant_access = {
27643+static const struct access_method SA5_performant_access = {
27644 SA5_submit_command,
27645 SA5_performant_intr_mask,
27646 SA5_fifo_full,
27647@@ -420,7 +420,7 @@ static struct access_method SA5_performa
27648 struct board_type {
27649 __u32 board_id;
27650 char *product_name;
27651- struct access_method *access;
27652+ const struct access_method *access;
27653 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
27654 };
27655
27656diff -urNp linux-2.6.39.1/drivers/block/cpqarray.c linux-2.6.39.1/drivers/block/cpqarray.c
27657--- linux-2.6.39.1/drivers/block/cpqarray.c 2011-05-19 00:06:34.000000000 -0400
27658+++ linux-2.6.39.1/drivers/block/cpqarray.c 2011-05-22 19:36:31.000000000 -0400
27659@@ -80,7 +80,7 @@ static int eisa[8];
27660 * product = Marketing Name for the board
27661 * access = Address of the struct of function pointers
27662 */
27663-static struct board_type products[] = {
27664+static const struct board_type products[] = {
27665 { 0x0040110E, "IDA", &smart1_access },
27666 { 0x0140110E, "IDA-2", &smart1_access },
27667 { 0x1040110E, "IAES", &smart1_access },
27668@@ -911,6 +911,8 @@ static void do_ida_request(struct reques
27669 struct scatterlist tmp_sg[SG_MAX];
27670 int i, dir, seg;
27671
27672+ pax_track_stack();
27673+
27674 queue_next:
27675 creq = blk_peek_request(q);
27676 if (!creq)
27677diff -urNp linux-2.6.39.1/drivers/block/cpqarray.h linux-2.6.39.1/drivers/block/cpqarray.h
27678--- linux-2.6.39.1/drivers/block/cpqarray.h 2011-05-19 00:06:34.000000000 -0400
27679+++ linux-2.6.39.1/drivers/block/cpqarray.h 2011-05-22 19:36:31.000000000 -0400
27680@@ -69,7 +69,7 @@ struct access_method {
27681 struct board_type {
27682 __u32 board_id;
27683 char *product_name;
27684- struct access_method *access;
27685+ const struct access_method *access;
27686 };
27687
27688 struct ctlr_info {
27689diff -urNp linux-2.6.39.1/drivers/block/DAC960.c linux-2.6.39.1/drivers/block/DAC960.c
27690--- linux-2.6.39.1/drivers/block/DAC960.c 2011-05-19 00:06:34.000000000 -0400
27691+++ linux-2.6.39.1/drivers/block/DAC960.c 2011-05-22 19:36:31.000000000 -0400
27692@@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27693 unsigned long flags;
27694 int Channel, TargetID;
27695
27696+ pax_track_stack();
27697+
27698 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27699 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27700 sizeof(DAC960_SCSI_Inquiry_T) +
27701diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_int.h linux-2.6.39.1/drivers/block/drbd/drbd_int.h
27702--- linux-2.6.39.1/drivers/block/drbd/drbd_int.h 2011-05-19 00:06:34.000000000 -0400
27703+++ linux-2.6.39.1/drivers/block/drbd/drbd_int.h 2011-05-22 19:36:31.000000000 -0400
27704@@ -736,7 +736,7 @@ struct drbd_request;
27705 struct drbd_epoch {
27706 struct list_head list;
27707 unsigned int barrier_nr;
27708- atomic_t epoch_size; /* increased on every request added. */
27709+ atomic_unchecked_t epoch_size; /* increased on every request added. */
27710 atomic_t active; /* increased on every req. added, and dec on every finished. */
27711 unsigned long flags;
27712 };
27713@@ -1108,7 +1108,7 @@ struct drbd_conf {
27714 void *int_dig_in;
27715 void *int_dig_vv;
27716 wait_queue_head_t seq_wait;
27717- atomic_t packet_seq;
27718+ atomic_unchecked_t packet_seq;
27719 unsigned int peer_seq;
27720 spinlock_t peer_seq_lock;
27721 unsigned int minor;
27722diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_main.c linux-2.6.39.1/drivers/block/drbd/drbd_main.c
27723--- linux-2.6.39.1/drivers/block/drbd/drbd_main.c 2011-05-19 00:06:34.000000000 -0400
27724+++ linux-2.6.39.1/drivers/block/drbd/drbd_main.c 2011-05-22 19:36:31.000000000 -0400
27725@@ -2387,7 +2387,7 @@ static int _drbd_send_ack(struct drbd_co
27726 p.sector = sector;
27727 p.block_id = block_id;
27728 p.blksize = blksize;
27729- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
27730+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
27731
27732 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
27733 return false;
27734@@ -2686,7 +2686,7 @@ int drbd_send_dblock(struct drbd_conf *m
27735 p.sector = cpu_to_be64(req->sector);
27736 p.block_id = (unsigned long)req;
27737 p.seq_num = cpu_to_be32(req->seq_num =
27738- atomic_add_return(1, &mdev->packet_seq));
27739+ atomic_add_return_unchecked(1, &mdev->packet_seq));
27740
27741 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
27742
27743@@ -2971,7 +2971,7 @@ void drbd_init_set_defaults(struct drbd_
27744 atomic_set(&mdev->unacked_cnt, 0);
27745 atomic_set(&mdev->local_cnt, 0);
27746 atomic_set(&mdev->net_cnt, 0);
27747- atomic_set(&mdev->packet_seq, 0);
27748+ atomic_set_unchecked(&mdev->packet_seq, 0);
27749 atomic_set(&mdev->pp_in_use, 0);
27750 atomic_set(&mdev->pp_in_use_by_net, 0);
27751 atomic_set(&mdev->rs_sect_in, 0);
27752@@ -3051,8 +3051,8 @@ void drbd_mdev_cleanup(struct drbd_conf
27753 mdev->receiver.t_state);
27754
27755 /* no need to lock it, I'm the only thread alive */
27756- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
27757- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
27758+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
27759+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
27760 mdev->al_writ_cnt =
27761 mdev->bm_writ_cnt =
27762 mdev->read_cnt =
27763diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_nl.c linux-2.6.39.1/drivers/block/drbd/drbd_nl.c
27764--- linux-2.6.39.1/drivers/block/drbd/drbd_nl.c 2011-05-19 00:06:34.000000000 -0400
27765+++ linux-2.6.39.1/drivers/block/drbd/drbd_nl.c 2011-05-22 19:36:31.000000000 -0400
27766@@ -2298,7 +2298,7 @@ static void drbd_connector_callback(stru
27767 module_put(THIS_MODULE);
27768 }
27769
27770-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27771+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27772
27773 static unsigned short *
27774 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
27775@@ -2369,7 +2369,7 @@ void drbd_bcast_state(struct drbd_conf *
27776 cn_reply->id.idx = CN_IDX_DRBD;
27777 cn_reply->id.val = CN_VAL_DRBD;
27778
27779- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27780+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27781 cn_reply->ack = 0; /* not used here. */
27782 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27783 (int)((char *)tl - (char *)reply->tag_list);
27784@@ -2401,7 +2401,7 @@ void drbd_bcast_ev_helper(struct drbd_co
27785 cn_reply->id.idx = CN_IDX_DRBD;
27786 cn_reply->id.val = CN_VAL_DRBD;
27787
27788- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27789+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27790 cn_reply->ack = 0; /* not used here. */
27791 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27792 (int)((char *)tl - (char *)reply->tag_list);
27793@@ -2479,7 +2479,7 @@ void drbd_bcast_ee(struct drbd_conf *mde
27794 cn_reply->id.idx = CN_IDX_DRBD;
27795 cn_reply->id.val = CN_VAL_DRBD;
27796
27797- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
27798+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
27799 cn_reply->ack = 0; // not used here.
27800 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27801 (int)((char*)tl - (char*)reply->tag_list);
27802@@ -2518,7 +2518,7 @@ void drbd_bcast_sync_progress(struct drb
27803 cn_reply->id.idx = CN_IDX_DRBD;
27804 cn_reply->id.val = CN_VAL_DRBD;
27805
27806- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27807+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27808 cn_reply->ack = 0; /* not used here. */
27809 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27810 (int)((char *)tl - (char *)reply->tag_list);
27811diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c
27812--- linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c 2011-05-19 00:06:34.000000000 -0400
27813+++ linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c 2011-05-22 19:36:31.000000000 -0400
27814@@ -894,7 +894,7 @@ retry:
27815 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
27816 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
27817
27818- atomic_set(&mdev->packet_seq, 0);
27819+ atomic_set_unchecked(&mdev->packet_seq, 0);
27820 mdev->peer_seq = 0;
27821
27822 drbd_thread_start(&mdev->asender);
27823@@ -990,7 +990,7 @@ static enum finish_epoch drbd_may_finish
27824 do {
27825 next_epoch = NULL;
27826
27827- epoch_size = atomic_read(&epoch->epoch_size);
27828+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
27829
27830 switch (ev & ~EV_CLEANUP) {
27831 case EV_PUT:
27832@@ -1025,7 +1025,7 @@ static enum finish_epoch drbd_may_finish
27833 rv = FE_DESTROYED;
27834 } else {
27835 epoch->flags = 0;
27836- atomic_set(&epoch->epoch_size, 0);
27837+ atomic_set_unchecked(&epoch->epoch_size, 0);
27838 /* atomic_set(&epoch->active, 0); is already zero */
27839 if (rv == FE_STILL_LIVE)
27840 rv = FE_RECYCLED;
27841@@ -1196,14 +1196,14 @@ static int receive_Barrier(struct drbd_c
27842 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
27843 drbd_flush(mdev);
27844
27845- if (atomic_read(&mdev->current_epoch->epoch_size)) {
27846+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27847 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
27848 if (epoch)
27849 break;
27850 }
27851
27852 epoch = mdev->current_epoch;
27853- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
27854+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
27855
27856 D_ASSERT(atomic_read(&epoch->active) == 0);
27857 D_ASSERT(epoch->flags == 0);
27858@@ -1215,11 +1215,11 @@ static int receive_Barrier(struct drbd_c
27859 }
27860
27861 epoch->flags = 0;
27862- atomic_set(&epoch->epoch_size, 0);
27863+ atomic_set_unchecked(&epoch->epoch_size, 0);
27864 atomic_set(&epoch->active, 0);
27865
27866 spin_lock(&mdev->epoch_lock);
27867- if (atomic_read(&mdev->current_epoch->epoch_size)) {
27868+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27869 list_add(&epoch->list, &mdev->current_epoch->list);
27870 mdev->current_epoch = epoch;
27871 mdev->epochs++;
27872@@ -1668,7 +1668,7 @@ static int receive_Data(struct drbd_conf
27873 spin_unlock(&mdev->peer_seq_lock);
27874
27875 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
27876- atomic_inc(&mdev->current_epoch->epoch_size);
27877+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
27878 return drbd_drain_block(mdev, data_size);
27879 }
27880
27881@@ -1694,7 +1694,7 @@ static int receive_Data(struct drbd_conf
27882
27883 spin_lock(&mdev->epoch_lock);
27884 e->epoch = mdev->current_epoch;
27885- atomic_inc(&e->epoch->epoch_size);
27886+ atomic_inc_unchecked(&e->epoch->epoch_size);
27887 atomic_inc(&e->epoch->active);
27888 spin_unlock(&mdev->epoch_lock);
27889
27890@@ -3905,7 +3905,7 @@ static void drbd_disconnect(struct drbd_
27891 D_ASSERT(list_empty(&mdev->done_ee));
27892
27893 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
27894- atomic_set(&mdev->current_epoch->epoch_size, 0);
27895+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
27896 D_ASSERT(list_empty(&mdev->current_epoch->list));
27897 }
27898
27899diff -urNp linux-2.6.39.1/drivers/block/nbd.c linux-2.6.39.1/drivers/block/nbd.c
27900--- linux-2.6.39.1/drivers/block/nbd.c 2011-05-19 00:06:34.000000000 -0400
27901+++ linux-2.6.39.1/drivers/block/nbd.c 2011-05-22 19:36:31.000000000 -0400
27902@@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *
27903 struct kvec iov;
27904 sigset_t blocked, oldset;
27905
27906+ pax_track_stack();
27907+
27908 if (unlikely(!sock)) {
27909 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27910 lo->disk->disk_name, (send ? "send" : "recv"));
27911@@ -571,6 +573,8 @@ static void do_nbd_request(struct reques
27912 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27913 unsigned int cmd, unsigned long arg)
27914 {
27915+ pax_track_stack();
27916+
27917 switch (cmd) {
27918 case NBD_DISCONNECT: {
27919 struct request sreq;
27920diff -urNp linux-2.6.39.1/drivers/block/smart1,2.h linux-2.6.39.1/drivers/block/smart1,2.h
27921--- linux-2.6.39.1/drivers/block/smart1,2.h 2011-05-19 00:06:34.000000000 -0400
27922+++ linux-2.6.39.1/drivers/block/smart1,2.h 2011-05-22 19:36:31.000000000 -0400
27923@@ -107,7 +107,7 @@ static unsigned long smart4_intr_pending
27924 return 0 ;
27925 }
27926
27927-static struct access_method smart4_access = {
27928+static const struct access_method smart4_access = {
27929 smart4_submit_command,
27930 smart4_intr_mask,
27931 smart4_fifo_full,
27932@@ -143,7 +143,7 @@ static unsigned long smart2_intr_pending
27933 return readl(h->vaddr + INTR_PENDING);
27934 }
27935
27936-static struct access_method smart2_access = {
27937+static const struct access_method smart2_access = {
27938 smart2_submit_command,
27939 smart2_intr_mask,
27940 smart2_fifo_full,
27941@@ -179,7 +179,7 @@ static unsigned long smart2e_intr_pendin
27942 return inl(h->io_mem_addr + INTR_PENDING);
27943 }
27944
27945-static struct access_method smart2e_access = {
27946+static const struct access_method smart2e_access = {
27947 smart2e_submit_command,
27948 smart2e_intr_mask,
27949 smart2e_fifo_full,
27950@@ -269,7 +269,7 @@ static unsigned long smart1_intr_pending
27951 return chan;
27952 }
27953
27954-static struct access_method smart1_access = {
27955+static const struct access_method smart1_access = {
27956 smart1_submit_command,
27957 smart1_intr_mask,
27958 smart1_fifo_full,
27959diff -urNp linux-2.6.39.1/drivers/block/xsysace.c linux-2.6.39.1/drivers/block/xsysace.c
27960--- linux-2.6.39.1/drivers/block/xsysace.c 2011-05-19 00:06:34.000000000 -0400
27961+++ linux-2.6.39.1/drivers/block/xsysace.c 2011-05-22 19:36:31.000000000 -0400
27962@@ -262,7 +262,7 @@ static void ace_dataout_8(struct ace_dev
27963 ace->data_ptr = src;
27964 }
27965
27966-static struct ace_reg_ops ace_reg_8_ops = {
27967+static const struct ace_reg_ops ace_reg_8_ops = {
27968 .in = ace_in_8,
27969 .out = ace_out_8,
27970 .datain = ace_datain_8,
27971@@ -327,14 +327,14 @@ static void ace_dataout_le16(struct ace_
27972 ace->data_ptr = src;
27973 }
27974
27975-static struct ace_reg_ops ace_reg_be16_ops = {
27976+static const struct ace_reg_ops ace_reg_be16_ops = {
27977 .in = ace_in_be16,
27978 .out = ace_out_be16,
27979 .datain = ace_datain_be16,
27980 .dataout = ace_dataout_be16,
27981 };
27982
27983-static struct ace_reg_ops ace_reg_le16_ops = {
27984+static const struct ace_reg_ops ace_reg_le16_ops = {
27985 .in = ace_in_le16,
27986 .out = ace_out_le16,
27987 .datain = ace_datain_le16,
27988diff -urNp linux-2.6.39.1/drivers/char/agp/frontend.c linux-2.6.39.1/drivers/char/agp/frontend.c
27989--- linux-2.6.39.1/drivers/char/agp/frontend.c 2011-05-19 00:06:34.000000000 -0400
27990+++ linux-2.6.39.1/drivers/char/agp/frontend.c 2011-05-22 19:36:31.000000000 -0400
27991@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
27992 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27993 return -EFAULT;
27994
27995- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27996+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27997 return -EFAULT;
27998
27999 client = agp_find_client_by_pid(reserve.pid);
28000diff -urNp linux-2.6.39.1/drivers/char/briq_panel.c linux-2.6.39.1/drivers/char/briq_panel.c
28001--- linux-2.6.39.1/drivers/char/briq_panel.c 2011-05-19 00:06:34.000000000 -0400
28002+++ linux-2.6.39.1/drivers/char/briq_panel.c 2011-05-22 19:41:32.000000000 -0400
28003@@ -9,6 +9,7 @@
28004 #include <linux/types.h>
28005 #include <linux/errno.h>
28006 #include <linux/tty.h>
28007+#include <linux/mutex.h>
28008 #include <linux/timer.h>
28009 #include <linux/kernel.h>
28010 #include <linux/wait.h>
28011@@ -34,6 +35,7 @@ static int vfd_is_open;
28012 static unsigned char vfd[40];
28013 static int vfd_cursor;
28014 static unsigned char ledpb, led;
28015+static DEFINE_MUTEX(vfd_mutex);
28016
28017 static void update_vfd(void)
28018 {
28019@@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct f
28020 if (!vfd_is_open)
28021 return -EBUSY;
28022
28023+ mutex_lock(&vfd_mutex);
28024 for (;;) {
28025 char c;
28026 if (!indx)
28027 break;
28028- if (get_user(c, buf))
28029+ if (get_user(c, buf)) {
28030+ mutex_unlock(&vfd_mutex);
28031 return -EFAULT;
28032+ }
28033 if (esc) {
28034 set_led(c);
28035 esc = 0;
28036@@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct f
28037 buf++;
28038 }
28039 update_vfd();
28040+ mutex_unlock(&vfd_mutex);
28041
28042 return len;
28043 }
28044diff -urNp linux-2.6.39.1/drivers/char/genrtc.c linux-2.6.39.1/drivers/char/genrtc.c
28045--- linux-2.6.39.1/drivers/char/genrtc.c 2011-05-19 00:06:34.000000000 -0400
28046+++ linux-2.6.39.1/drivers/char/genrtc.c 2011-05-22 19:41:32.000000000 -0400
28047@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *fi
28048 switch (cmd) {
28049
28050 case RTC_PLL_GET:
28051+ memset(&pll, 0, sizeof(pll));
28052 if (get_rtc_pll(&pll))
28053 return -EINVAL;
28054 else
28055diff -urNp linux-2.6.39.1/drivers/char/hpet.c linux-2.6.39.1/drivers/char/hpet.c
28056--- linux-2.6.39.1/drivers/char/hpet.c 2011-05-19 00:06:34.000000000 -0400
28057+++ linux-2.6.39.1/drivers/char/hpet.c 2011-05-22 19:36:31.000000000 -0400
28058@@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
28059 }
28060
28061 static int
28062-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
28063+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
28064 struct hpet_info *info)
28065 {
28066 struct hpet_timer __iomem *timer;
28067diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c
28068--- linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c 2011-05-19 00:06:34.000000000 -0400
28069+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c 2011-05-22 19:36:31.000000000 -0400
28070@@ -109,8 +109,7 @@ static int ipmi_fasync(int fd, struct fi
28071 return (result);
28072 }
28073
28074-static struct ipmi_user_hndl ipmi_hndlrs =
28075-{
28076+static const struct ipmi_user_hndl ipmi_hndlrs = {
28077 .ipmi_recv_hndl = file_receive_handler,
28078 };
28079
28080diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c
28081--- linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c 2011-05-19 00:06:34.000000000 -0400
28082+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c 2011-05-22 19:36:31.000000000 -0400
28083@@ -82,7 +82,7 @@ struct ipmi_user {
28084 struct kref refcount;
28085
28086 /* The upper layer that handles receive messages. */
28087- struct ipmi_user_hndl *handler;
28088+ const struct ipmi_user_hndl *handler;
28089 void *handler_data;
28090
28091 /* The interface this user is bound to. */
28092@@ -414,7 +414,7 @@ struct ipmi_smi {
28093 struct proc_dir_entry *proc_dir;
28094 char proc_dir_name[10];
28095
28096- atomic_t stats[IPMI_NUM_STATS];
28097+ atomic_unchecked_t stats[IPMI_NUM_STATS];
28098
28099 /*
28100 * run_to_completion duplicate of smb_info, smi_info
28101@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
28102
28103
28104 #define ipmi_inc_stat(intf, stat) \
28105- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
28106+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
28107 #define ipmi_get_stat(intf, stat) \
28108- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
28109+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
28110
28111 static int is_lan_addr(struct ipmi_addr *addr)
28112 {
28113@@ -875,7 +875,7 @@ static int intf_err_seq(ipmi_smi_t int
28114
28115
28116 int ipmi_create_user(unsigned int if_num,
28117- struct ipmi_user_hndl *handler,
28118+ const struct ipmi_user_hndl *handler,
28119 void *handler_data,
28120 ipmi_user_t *user)
28121 {
28122@@ -2844,7 +2844,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
28123 INIT_LIST_HEAD(&intf->cmd_rcvrs);
28124 init_waitqueue_head(&intf->waitq);
28125 for (i = 0; i < IPMI_NUM_STATS; i++)
28126- atomic_set(&intf->stats[i], 0);
28127+ atomic_set_unchecked(&intf->stats[i], 0);
28128
28129 intf->proc_dir = NULL;
28130
28131@@ -4196,6 +4196,8 @@ static void send_panic_events(char *str)
28132 struct ipmi_smi_msg smi_msg;
28133 struct ipmi_recv_msg recv_msg;
28134
28135+ pax_track_stack();
28136+
28137 si = (struct ipmi_system_interface_addr *) &addr;
28138 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
28139 si->channel = IPMI_BMC_CHANNEL;
28140diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c
28141--- linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c 2011-05-19 00:06:34.000000000 -0400
28142+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c 2011-05-22 19:36:31.000000000 -0400
28143@@ -133,7 +133,7 @@ static void receive_handler(struct ipmi_
28144 complete(comp);
28145 }
28146
28147-static struct ipmi_user_hndl ipmi_poweroff_handler = {
28148+static const struct ipmi_user_hndl ipmi_poweroff_handler = {
28149 .ipmi_recv_hndl = receive_handler
28150 };
28151
28152diff -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
28153--- linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c 2011-05-19 00:06:34.000000000 -0400
28154+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c 2011-05-22 19:36:31.000000000 -0400
28155@@ -276,7 +276,7 @@ struct smi_info {
28156 unsigned char slave_addr;
28157
28158 /* Counters and things for the proc filesystem. */
28159- atomic_t stats[SI_NUM_STATS];
28160+ atomic_unchecked_t stats[SI_NUM_STATS];
28161
28162 struct task_struct *thread;
28163
28164@@ -285,9 +285,9 @@ struct smi_info {
28165 };
28166
28167 #define smi_inc_stat(smi, stat) \
28168- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28169+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28170 #define smi_get_stat(smi, stat) \
28171- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28172+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28173
28174 #define SI_MAX_PARMS 4
28175
28176@@ -3198,7 +3198,7 @@ static int try_smi_init(struct smi_info
28177 atomic_set(&new_smi->req_events, 0);
28178 new_smi->run_to_completion = 0;
28179 for (i = 0; i < SI_NUM_STATS; i++)
28180- atomic_set(&new_smi->stats[i], 0);
28181+ atomic_set_unchecked(&new_smi->stats[i], 0);
28182
28183 new_smi->interrupt_disabled = 1;
28184 atomic_set(&new_smi->stop_operation, 0);
28185diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c
28186--- linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c 2011-05-19 00:06:34.000000000 -0400
28187+++ linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c 2011-05-22 19:36:31.000000000 -0400
28188@@ -216,7 +216,7 @@ static int set_param_timeout(const char
28189 return rv;
28190 }
28191
28192-static struct kernel_param_ops param_ops_timeout = {
28193+static const struct kernel_param_ops param_ops_timeout = {
28194 .set = set_param_timeout,
28195 .get = param_get_int,
28196 };
28197@@ -278,14 +278,14 @@ static int set_param_wdog_ifnum(const ch
28198 return 0;
28199 }
28200
28201-static struct kernel_param_ops param_ops_wdog_ifnum = {
28202+static const struct kernel_param_ops param_ops_wdog_ifnum = {
28203 .set = set_param_wdog_ifnum,
28204 .get = param_get_int,
28205 };
28206
28207 #define param_check_wdog_ifnum param_check_int
28208
28209-static struct kernel_param_ops param_ops_str = {
28210+static const struct kernel_param_ops param_ops_str = {
28211 .set = set_param_str,
28212 .get = get_param_str,
28213 };
28214@@ -953,7 +953,7 @@ static void ipmi_wdog_pretimeout_handler
28215 pretimeout_since_last_heartbeat = 1;
28216 }
28217
28218-static struct ipmi_user_hndl ipmi_hndlrs = {
28219+static const struct ipmi_user_hndl ipmi_hndlrs = {
28220 .ipmi_recv_hndl = ipmi_wdog_msg_handler,
28221 .ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler
28222 };
28223diff -urNp linux-2.6.39.1/drivers/char/Kconfig linux-2.6.39.1/drivers/char/Kconfig
28224--- linux-2.6.39.1/drivers/char/Kconfig 2011-05-19 00:06:34.000000000 -0400
28225+++ linux-2.6.39.1/drivers/char/Kconfig 2011-05-22 19:41:37.000000000 -0400
28226@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28227
28228 config DEVKMEM
28229 bool "/dev/kmem virtual device support"
28230- default y
28231+ default n
28232+ depends on !GRKERNSEC_KMEM
28233 help
28234 Say Y here if you want to support the /dev/kmem device. The
28235 /dev/kmem device is rarely used, but can be used for certain
28236@@ -596,6 +597,7 @@ config DEVPORT
28237 bool
28238 depends on !M68K
28239 depends on ISA || PCI
28240+ depends on !GRKERNSEC_KMEM
28241 default y
28242
28243 source "drivers/s390/char/Kconfig"
28244diff -urNp linux-2.6.39.1/drivers/char/mem.c linux-2.6.39.1/drivers/char/mem.c
28245--- linux-2.6.39.1/drivers/char/mem.c 2011-05-19 00:06:34.000000000 -0400
28246+++ linux-2.6.39.1/drivers/char/mem.c 2011-05-22 19:41:37.000000000 -0400
28247@@ -18,6 +18,7 @@
28248 #include <linux/raw.h>
28249 #include <linux/tty.h>
28250 #include <linux/capability.h>
28251+#include <linux/security.h>
28252 #include <linux/ptrace.h>
28253 #include <linux/device.h>
28254 #include <linux/highmem.h>
28255@@ -34,6 +35,10 @@
28256 # include <linux/efi.h>
28257 #endif
28258
28259+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28260+extern struct file_operations grsec_fops;
28261+#endif
28262+
28263 static inline unsigned long size_inside_page(unsigned long start,
28264 unsigned long size)
28265 {
28266@@ -65,9 +70,13 @@ static inline int range_is_allowed(unsig
28267
28268 while (cursor < to) {
28269 if (!devmem_is_allowed(pfn)) {
28270+#ifdef CONFIG_GRKERNSEC_KMEM
28271+ gr_handle_mem_readwrite(from, to);
28272+#else
28273 printk(KERN_INFO
28274 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28275 current->comm, from, to);
28276+#endif
28277 return 0;
28278 }
28279 cursor += PAGE_SIZE;
28280@@ -75,6 +84,11 @@ static inline int range_is_allowed(unsig
28281 }
28282 return 1;
28283 }
28284+#elif defined(CONFIG_GRKERNSEC_KMEM)
28285+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28286+{
28287+ return 0;
28288+}
28289 #else
28290 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28291 {
28292@@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *fil
28293
28294 while (count > 0) {
28295 unsigned long remaining;
28296+ char *temp;
28297
28298 sz = size_inside_page(p, count);
28299
28300@@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *fil
28301 if (!ptr)
28302 return -EFAULT;
28303
28304- remaining = copy_to_user(buf, ptr, sz);
28305+#ifdef CONFIG_PAX_USERCOPY
28306+ temp = kmalloc(sz, GFP_KERNEL);
28307+ if (!temp) {
28308+ unxlate_dev_mem_ptr(p, ptr);
28309+ return -ENOMEM;
28310+ }
28311+ memcpy(temp, ptr, sz);
28312+#else
28313+ temp = ptr;
28314+#endif
28315+
28316+ remaining = copy_to_user(buf, temp, sz);
28317+
28318+#ifdef CONFIG_PAX_USERCOPY
28319+ kfree(temp);
28320+#endif
28321+
28322 unxlate_dev_mem_ptr(p, ptr);
28323 if (remaining)
28324 return -EFAULT;
28325@@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *fi
28326 size_t count, loff_t *ppos)
28327 {
28328 unsigned long p = *ppos;
28329- ssize_t low_count, read, sz;
28330+ ssize_t low_count, read, sz, err = 0;
28331 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28332- int err = 0;
28333
28334 read = 0;
28335 if (p < (unsigned long) high_memory) {
28336@@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *fi
28337 }
28338 #endif
28339 while (low_count > 0) {
28340+ char *temp;
28341+
28342 sz = size_inside_page(p, low_count);
28343
28344 /*
28345@@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *fi
28346 */
28347 kbuf = xlate_dev_kmem_ptr((char *)p);
28348
28349- if (copy_to_user(buf, kbuf, sz))
28350+#ifdef CONFIG_PAX_USERCOPY
28351+ temp = kmalloc(sz, GFP_KERNEL);
28352+ if (!temp)
28353+ return -ENOMEM;
28354+ memcpy(temp, kbuf, sz);
28355+#else
28356+ temp = kbuf;
28357+#endif
28358+
28359+ err = copy_to_user(buf, temp, sz);
28360+
28361+#ifdef CONFIG_PAX_USERCOPY
28362+ kfree(temp);
28363+#endif
28364+
28365+ if (err)
28366 return -EFAULT;
28367 buf += sz;
28368 p += sz;
28369@@ -854,6 +901,9 @@ static const struct memdev {
28370 #ifdef CONFIG_CRASH_DUMP
28371 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28372 #endif
28373+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28374+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28375+#endif
28376 };
28377
28378 static int memory_open(struct inode *inode, struct file *filp)
28379diff -urNp linux-2.6.39.1/drivers/char/mmtimer.c linux-2.6.39.1/drivers/char/mmtimer.c
28380--- linux-2.6.39.1/drivers/char/mmtimer.c 2011-05-19 00:06:34.000000000 -0400
28381+++ linux-2.6.39.1/drivers/char/mmtimer.c 2011-05-22 19:36:31.000000000 -0400
28382@@ -53,7 +53,7 @@ MODULE_LICENSE("GPL");
28383
28384 #define RTC_BITS 55 /* 55 bits for this implementation */
28385
28386-static struct k_clock sgi_clock;
28387+static const struct k_clock sgi_clock;
28388
28389 extern unsigned long sn_rtc_cycles_per_second;
28390
28391@@ -772,7 +772,7 @@ static int sgi_clock_getres(const clocki
28392 return 0;
28393 }
28394
28395-static struct k_clock sgi_clock = {
28396+static const struct k_clock sgi_clock = {
28397 .clock_set = sgi_clock_set,
28398 .clock_get = sgi_clock_get,
28399 .clock_getres = sgi_clock_getres,
28400diff -urNp linux-2.6.39.1/drivers/char/nvram.c linux-2.6.39.1/drivers/char/nvram.c
28401--- linux-2.6.39.1/drivers/char/nvram.c 2011-05-19 00:06:34.000000000 -0400
28402+++ linux-2.6.39.1/drivers/char/nvram.c 2011-05-22 19:36:31.000000000 -0400
28403@@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
28404
28405 spin_unlock_irq(&rtc_lock);
28406
28407- if (copy_to_user(buf, contents, tmp - contents))
28408+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28409 return -EFAULT;
28410
28411 *ppos = i;
28412diff -urNp linux-2.6.39.1/drivers/char/random.c linux-2.6.39.1/drivers/char/random.c
28413--- linux-2.6.39.1/drivers/char/random.c 2011-05-19 00:06:34.000000000 -0400
28414+++ linux-2.6.39.1/drivers/char/random.c 2011-05-22 19:41:37.000000000 -0400
28415@@ -261,8 +261,13 @@
28416 /*
28417 * Configuration information
28418 */
28419+#ifdef CONFIG_GRKERNSEC_RANDNET
28420+#define INPUT_POOL_WORDS 512
28421+#define OUTPUT_POOL_WORDS 128
28422+#else
28423 #define INPUT_POOL_WORDS 128
28424 #define OUTPUT_POOL_WORDS 32
28425+#endif
28426 #define SEC_XFER_SIZE 512
28427 #define EXTRACT_SIZE 10
28428
28429@@ -300,10 +305,17 @@ static struct poolinfo {
28430 int poolwords;
28431 int tap1, tap2, tap3, tap4, tap5;
28432 } poolinfo_table[] = {
28433+#ifdef CONFIG_GRKERNSEC_RANDNET
28434+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28435+ { 512, 411, 308, 208, 104, 1 },
28436+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28437+ { 128, 103, 76, 51, 25, 1 },
28438+#else
28439 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28440 { 128, 103, 76, 51, 25, 1 },
28441 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28442 { 32, 26, 20, 14, 7, 1 },
28443+#endif
28444 #if 0
28445 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28446 { 2048, 1638, 1231, 819, 411, 1 },
28447@@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(stru
28448
28449 extract_buf(r, tmp);
28450 i = min_t(int, nbytes, EXTRACT_SIZE);
28451- if (copy_to_user(buf, tmp, i)) {
28452+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28453 ret = -EFAULT;
28454 break;
28455 }
28456@@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28457 #include <linux/sysctl.h>
28458
28459 static int min_read_thresh = 8, min_write_thresh;
28460-static int max_read_thresh = INPUT_POOL_WORDS * 32;
28461+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28462 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28463 static char sysctl_bootid[16];
28464
28465diff -urNp linux-2.6.39.1/drivers/char/sonypi.c linux-2.6.39.1/drivers/char/sonypi.c
28466--- linux-2.6.39.1/drivers/char/sonypi.c 2011-05-19 00:06:34.000000000 -0400
28467+++ linux-2.6.39.1/drivers/char/sonypi.c 2011-05-22 19:36:31.000000000 -0400
28468@@ -55,6 +55,7 @@
28469 #include <asm/uaccess.h>
28470 #include <asm/io.h>
28471 #include <asm/system.h>
28472+#include <asm/local.h>
28473
28474 #include <linux/sonypi.h>
28475
28476@@ -491,7 +492,7 @@ static struct sonypi_device {
28477 spinlock_t fifo_lock;
28478 wait_queue_head_t fifo_proc_list;
28479 struct fasync_struct *fifo_async;
28480- int open_count;
28481+ local_t open_count;
28482 int model;
28483 struct input_dev *input_jog_dev;
28484 struct input_dev *input_key_dev;
28485@@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, st
28486 static int sonypi_misc_release(struct inode *inode, struct file *file)
28487 {
28488 mutex_lock(&sonypi_device.lock);
28489- sonypi_device.open_count--;
28490+ local_dec(&sonypi_device.open_count);
28491 mutex_unlock(&sonypi_device.lock);
28492 return 0;
28493 }
28494@@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode
28495 {
28496 mutex_lock(&sonypi_device.lock);
28497 /* Flush input queue on first open */
28498- if (!sonypi_device.open_count)
28499+ if (!local_read(&sonypi_device.open_count))
28500 kfifo_reset(&sonypi_device.fifo);
28501- sonypi_device.open_count++;
28502+ local_inc(&sonypi_device.open_count);
28503 mutex_unlock(&sonypi_device.lock);
28504
28505 return 0;
28506diff -urNp linux-2.6.39.1/drivers/char/tpm/tpm_bios.c linux-2.6.39.1/drivers/char/tpm/tpm_bios.c
28507--- linux-2.6.39.1/drivers/char/tpm/tpm_bios.c 2011-05-19 00:06:34.000000000 -0400
28508+++ linux-2.6.39.1/drivers/char/tpm/tpm_bios.c 2011-05-22 19:36:31.000000000 -0400
28509@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
28510 event = addr;
28511
28512 if ((event->event_type == 0 && event->event_size == 0) ||
28513- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28514+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28515 return NULL;
28516
28517 return addr;
28518@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
28519 return NULL;
28520
28521 if ((event->event_type == 0 && event->event_size == 0) ||
28522- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28523+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28524 return NULL;
28525
28526 (*pos)++;
28527@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
28528 int i;
28529
28530 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28531- seq_putc(m, data[i]);
28532+ if (!seq_putc(m, data[i]))
28533+ return -EFAULT;
28534
28535 return 0;
28536 }
28537@@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
28538 log->bios_event_log_end = log->bios_event_log + len;
28539
28540 virt = acpi_os_map_memory(start, len);
28541+ if (!virt) {
28542+ kfree(log->bios_event_log);
28543+ log->bios_event_log = NULL;
28544+ return -EFAULT;
28545+ }
28546
28547 memcpy(log->bios_event_log, virt, len);
28548
28549diff -urNp linux-2.6.39.1/drivers/char/tpm/tpm.c linux-2.6.39.1/drivers/char/tpm/tpm.c
28550--- linux-2.6.39.1/drivers/char/tpm/tpm.c 2011-05-19 00:06:34.000000000 -0400
28551+++ linux-2.6.39.1/drivers/char/tpm/tpm.c 2011-05-22 19:36:31.000000000 -0400
28552@@ -411,7 +411,7 @@ static ssize_t tpm_transmit(struct tpm_c
28553 chip->vendor.req_complete_val)
28554 goto out_recv;
28555
28556- if ((status == chip->vendor.req_canceled)) {
28557+ if (status == chip->vendor.req_canceled) {
28558 dev_err(chip->dev, "Operation Canceled\n");
28559 rc = -ECANCELED;
28560 goto out;
28561@@ -844,6 +844,8 @@ ssize_t tpm_show_pubek(struct device *de
28562
28563 struct tpm_chip *chip = dev_get_drvdata(dev);
28564
28565+ pax_track_stack();
28566+
28567 tpm_cmd.header.in = tpm_readpubek_header;
28568 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28569 "attempting to read the PUBEK");
28570diff -urNp linux-2.6.39.1/drivers/char/ttyprintk.c linux-2.6.39.1/drivers/char/ttyprintk.c
28571--- linux-2.6.39.1/drivers/char/ttyprintk.c 2011-05-19 00:06:34.000000000 -0400
28572+++ linux-2.6.39.1/drivers/char/ttyprintk.c 2011-05-22 19:36:31.000000000 -0400
28573@@ -170,7 +170,7 @@ static const struct tty_operations ttypr
28574 .ioctl = tpk_ioctl,
28575 };
28576
28577-struct tty_port_operations null_ops = { };
28578+const struct tty_port_operations null_ops = { };
28579
28580 static struct tty_driver *ttyprintk_driver;
28581
28582diff -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
28583--- linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-19 00:06:34.000000000 -0400
28584+++ linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-22 19:36:31.000000000 -0400
28585@@ -678,14 +678,14 @@ static int __devinit hwicap_setup(struct
28586 return retval;
28587 }
28588
28589-static struct hwicap_driver_config buffer_icap_config = {
28590+static const struct hwicap_driver_config buffer_icap_config = {
28591 .get_configuration = buffer_icap_get_configuration,
28592 .set_configuration = buffer_icap_set_configuration,
28593 .get_status = buffer_icap_get_status,
28594 .reset = buffer_icap_reset,
28595 };
28596
28597-static struct hwicap_driver_config fifo_icap_config = {
28598+static const struct hwicap_driver_config fifo_icap_config = {
28599 .get_configuration = fifo_icap_get_configuration,
28600 .set_configuration = fifo_icap_set_configuration,
28601 .get_status = fifo_icap_get_status,
28602diff -urNp linux-2.6.39.1/drivers/crypto/hifn_795x.c linux-2.6.39.1/drivers/crypto/hifn_795x.c
28603--- linux-2.6.39.1/drivers/crypto/hifn_795x.c 2011-05-19 00:06:34.000000000 -0400
28604+++ linux-2.6.39.1/drivers/crypto/hifn_795x.c 2011-05-22 19:36:31.000000000 -0400
28605@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28606 0xCA, 0x34, 0x2B, 0x2E};
28607 struct scatterlist sg;
28608
28609+ pax_track_stack();
28610+
28611 memset(src, 0, sizeof(src));
28612 memset(ctx.key, 0, sizeof(ctx.key));
28613
28614diff -urNp linux-2.6.39.1/drivers/crypto/padlock-aes.c linux-2.6.39.1/drivers/crypto/padlock-aes.c
28615--- linux-2.6.39.1/drivers/crypto/padlock-aes.c 2011-05-19 00:06:34.000000000 -0400
28616+++ linux-2.6.39.1/drivers/crypto/padlock-aes.c 2011-05-22 19:36:31.000000000 -0400
28617@@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm
28618 struct crypto_aes_ctx gen_aes;
28619 int cpu;
28620
28621+ pax_track_stack();
28622+
28623 if (key_len % 8) {
28624 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28625 return -EINVAL;
28626diff -urNp linux-2.6.39.1/drivers/dca/dca-core.c linux-2.6.39.1/drivers/dca/dca-core.c
28627--- linux-2.6.39.1/drivers/dca/dca-core.c 2011-05-19 00:06:34.000000000 -0400
28628+++ linux-2.6.39.1/drivers/dca/dca-core.c 2011-05-22 19:36:31.000000000 -0400
28629@@ -325,7 +325,7 @@ EXPORT_SYMBOL_GPL(dca_get_tag);
28630 * @ops - pointer to struct of dca operation function pointers
28631 * @priv_size - size of extra mem to be added for provider's needs
28632 */
28633-struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size)
28634+struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size)
28635 {
28636 struct dca_provider *dca;
28637 int alloc_size;
28638diff -urNp linux-2.6.39.1/drivers/dma/ioat/dca.c linux-2.6.39.1/drivers/dma/ioat/dca.c
28639--- linux-2.6.39.1/drivers/dma/ioat/dca.c 2011-05-19 00:06:34.000000000 -0400
28640+++ linux-2.6.39.1/drivers/dma/ioat/dca.c 2011-05-22 19:36:31.000000000 -0400
28641@@ -234,7 +234,7 @@ static int ioat_dca_dev_managed(struct d
28642 return 0;
28643 }
28644
28645-static struct dca_ops ioat_dca_ops = {
28646+static const struct dca_ops ioat_dca_ops = {
28647 .add_requester = ioat_dca_add_requester,
28648 .remove_requester = ioat_dca_remove_requester,
28649 .get_tag = ioat_dca_get_tag,
28650@@ -384,7 +384,7 @@ static u8 ioat2_dca_get_tag(struct dca_p
28651 return tag;
28652 }
28653
28654-static struct dca_ops ioat2_dca_ops = {
28655+static const struct dca_ops ioat2_dca_ops = {
28656 .add_requester = ioat2_dca_add_requester,
28657 .remove_requester = ioat2_dca_remove_requester,
28658 .get_tag = ioat2_dca_get_tag,
28659@@ -579,7 +579,7 @@ static u8 ioat3_dca_get_tag(struct dca_p
28660 return tag;
28661 }
28662
28663-static struct dca_ops ioat3_dca_ops = {
28664+static const struct dca_ops ioat3_dca_ops = {
28665 .add_requester = ioat3_dca_add_requester,
28666 .remove_requester = ioat3_dca_remove_requester,
28667 .get_tag = ioat3_dca_get_tag,
28668diff -urNp linux-2.6.39.1/drivers/edac/amd64_edac.h linux-2.6.39.1/drivers/edac/amd64_edac.h
28669--- linux-2.6.39.1/drivers/edac/amd64_edac.h 2011-05-19 00:06:34.000000000 -0400
28670+++ linux-2.6.39.1/drivers/edac/amd64_edac.h 2011-05-22 19:36:31.000000000 -0400
28671@@ -333,7 +333,7 @@ struct chip_select {
28672 };
28673
28674 struct amd64_pvt {
28675- struct low_ops *ops;
28676+ const struct low_ops *ops;
28677
28678 /* pci_device handles which we utilize */
28679 struct pci_dev *F1, *F2, *F3;
28680@@ -443,7 +443,7 @@ struct low_ops {
28681 struct amd64_family_type {
28682 const char *ctl_name;
28683 u16 f1_id, f3_id;
28684- struct low_ops ops;
28685+ const struct low_ops ops;
28686 };
28687
28688 int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
28689diff -urNp linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c
28690--- linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28691+++ linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28692@@ -760,7 +760,7 @@ static void edac_inst_grp_release(struct
28693 }
28694
28695 /* Intermediate show/store table */
28696-static struct sysfs_ops inst_grp_ops = {
28697+static const struct sysfs_ops inst_grp_ops = {
28698 .show = inst_grp_show,
28699 .store = inst_grp_store
28700 };
28701diff -urNp linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c
28702--- linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28703+++ linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28704@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log
28705 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28706 static int edac_pci_poll_msec = 1000; /* one second workq period */
28707
28708-static atomic_t pci_parity_count = ATOMIC_INIT(0);
28709-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28710+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28711+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28712
28713 static struct kobject *edac_pci_top_main_kobj;
28714 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28715@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(str
28716 edac_printk(KERN_CRIT, EDAC_PCI,
28717 "Signaled System Error on %s\n",
28718 pci_name(dev));
28719- atomic_inc(&pci_nonparity_count);
28720+ atomic_inc_unchecked(&pci_nonparity_count);
28721 }
28722
28723 if (status & (PCI_STATUS_PARITY)) {
28724@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(str
28725 "Master Data Parity Error on %s\n",
28726 pci_name(dev));
28727
28728- atomic_inc(&pci_parity_count);
28729+ atomic_inc_unchecked(&pci_parity_count);
28730 }
28731
28732 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28733@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(str
28734 "Detected Parity Error on %s\n",
28735 pci_name(dev));
28736
28737- atomic_inc(&pci_parity_count);
28738+ atomic_inc_unchecked(&pci_parity_count);
28739 }
28740 }
28741
28742@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(str
28743 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28744 "Signaled System Error on %s\n",
28745 pci_name(dev));
28746- atomic_inc(&pci_nonparity_count);
28747+ atomic_inc_unchecked(&pci_nonparity_count);
28748 }
28749
28750 if (status & (PCI_STATUS_PARITY)) {
28751@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(str
28752 "Master Data Parity Error on "
28753 "%s\n", pci_name(dev));
28754
28755- atomic_inc(&pci_parity_count);
28756+ atomic_inc_unchecked(&pci_parity_count);
28757 }
28758
28759 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28760@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(str
28761 "Detected Parity Error on %s\n",
28762 pci_name(dev));
28763
28764- atomic_inc(&pci_parity_count);
28765+ atomic_inc_unchecked(&pci_parity_count);
28766 }
28767 }
28768 }
28769@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28770 if (!check_pci_errors)
28771 return;
28772
28773- before_count = atomic_read(&pci_parity_count);
28774+ before_count = atomic_read_unchecked(&pci_parity_count);
28775
28776 /* scan all PCI devices looking for a Parity Error on devices and
28777 * bridges.
28778@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
28779 /* Only if operator has selected panic on PCI Error */
28780 if (edac_pci_get_panic_on_pe()) {
28781 /* If the count is different 'after' from 'before' */
28782- if (before_count != atomic_read(&pci_parity_count))
28783+ if (before_count != atomic_read_unchecked(&pci_parity_count))
28784 panic("EDAC: PCI Parity Error");
28785 }
28786 }
28787diff -urNp linux-2.6.39.1/drivers/firewire/core-cdev.c linux-2.6.39.1/drivers/firewire/core-cdev.c
28788--- linux-2.6.39.1/drivers/firewire/core-cdev.c 2011-05-19 00:06:34.000000000 -0400
28789+++ linux-2.6.39.1/drivers/firewire/core-cdev.c 2011-05-22 19:36:31.000000000 -0400
28790@@ -1312,8 +1312,7 @@ static int init_iso_resource(struct clie
28791 int ret;
28792
28793 if ((request->channels == 0 && request->bandwidth == 0) ||
28794- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28795- request->bandwidth < 0)
28796+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28797 return -EINVAL;
28798
28799 r = kmalloc(sizeof(*r), GFP_KERNEL);
28800diff -urNp linux-2.6.39.1/drivers/firewire/core-transaction.c linux-2.6.39.1/drivers/firewire/core-transaction.c
28801--- linux-2.6.39.1/drivers/firewire/core-transaction.c 2011-05-19 00:06:34.000000000 -0400
28802+++ linux-2.6.39.1/drivers/firewire/core-transaction.c 2011-05-22 19:36:31.000000000 -0400
28803@@ -36,6 +36,7 @@
28804 #include <linux/string.h>
28805 #include <linux/timer.h>
28806 #include <linux/types.h>
28807+#include <linux/sched.h>
28808
28809 #include <asm/byteorder.h>
28810
28811@@ -420,6 +421,8 @@ int fw_run_transaction(struct fw_card *c
28812 struct transaction_callback_data d;
28813 struct fw_transaction t;
28814
28815+ pax_track_stack();
28816+
28817 init_timer_on_stack(&t.split_timeout_timer);
28818 init_completion(&d.done);
28819 d.payload = payload;
28820diff -urNp linux-2.6.39.1/drivers/firmware/dmi_scan.c linux-2.6.39.1/drivers/firmware/dmi_scan.c
28821--- linux-2.6.39.1/drivers/firmware/dmi_scan.c 2011-05-19 00:06:34.000000000 -0400
28822+++ linux-2.6.39.1/drivers/firmware/dmi_scan.c 2011-05-22 19:36:31.000000000 -0400
28823@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
28824 }
28825 }
28826 else {
28827- /*
28828- * no iounmap() for that ioremap(); it would be a no-op, but
28829- * it's so early in setup that sucker gets confused into doing
28830- * what it shouldn't if we actually call it.
28831- */
28832 p = dmi_ioremap(0xF0000, 0x10000);
28833 if (p == NULL)
28834 goto error;
28835diff -urNp linux-2.6.39.1/drivers/gpio/vr41xx_giu.c linux-2.6.39.1/drivers/gpio/vr41xx_giu.c
28836--- linux-2.6.39.1/drivers/gpio/vr41xx_giu.c 2011-05-19 00:06:34.000000000 -0400
28837+++ linux-2.6.39.1/drivers/gpio/vr41xx_giu.c 2011-05-22 19:36:31.000000000 -0400
28838@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28839 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28840 maskl, pendl, maskh, pendh);
28841
28842- atomic_inc(&irq_err_count);
28843+ atomic_inc_unchecked(&irq_err_count);
28844
28845 return -EINVAL;
28846 }
28847diff -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
28848--- linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c 2011-05-19 00:06:34.000000000 -0400
28849+++ linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c 2011-05-22 19:36:31.000000000 -0400
28850@@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
28851 struct drm_crtc *tmp;
28852 int crtc_mask = 1;
28853
28854- WARN(!crtc, "checking null crtc?\n");
28855+ BUG_ON(!crtc);
28856
28857 dev = crtc->dev;
28858
28859@@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm
28860 struct drm_encoder *encoder;
28861 bool ret = true;
28862
28863+ pax_track_stack();
28864+
28865 crtc->enabled = drm_helper_crtc_in_use(crtc);
28866 if (!crtc->enabled)
28867 return true;
28868diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_drv.c linux-2.6.39.1/drivers/gpu/drm/drm_drv.c
28869--- linux-2.6.39.1/drivers/gpu/drm/drm_drv.c 2011-05-19 00:06:34.000000000 -0400
28870+++ linux-2.6.39.1/drivers/gpu/drm/drm_drv.c 2011-05-22 19:36:31.000000000 -0400
28871@@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
28872
28873 dev = file_priv->minor->dev;
28874 atomic_inc(&dev->ioctl_count);
28875- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28876+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28877 ++file_priv->ioctl_count;
28878
28879 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28880diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_fops.c linux-2.6.39.1/drivers/gpu/drm/drm_fops.c
28881--- linux-2.6.39.1/drivers/gpu/drm/drm_fops.c 2011-05-19 00:06:34.000000000 -0400
28882+++ linux-2.6.39.1/drivers/gpu/drm/drm_fops.c 2011-05-22 19:36:31.000000000 -0400
28883@@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
28884 }
28885
28886 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28887- atomic_set(&dev->counts[i], 0);
28888+ atomic_set_unchecked(&dev->counts[i], 0);
28889
28890 dev->sigdata.lock = NULL;
28891
28892@@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
28893
28894 retcode = drm_open_helper(inode, filp, dev);
28895 if (!retcode) {
28896- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28897- if (!dev->open_count++)
28898+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28899+ if (local_inc_return(&dev->open_count) == 1)
28900 retcode = drm_setup(dev);
28901 }
28902 if (!retcode) {
28903@@ -472,7 +472,7 @@ int drm_release(struct inode *inode, str
28904
28905 mutex_lock(&drm_global_mutex);
28906
28907- DRM_DEBUG("open_count = %d\n", dev->open_count);
28908+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28909
28910 if (dev->driver->preclose)
28911 dev->driver->preclose(dev, file_priv);
28912@@ -484,7 +484,7 @@ int drm_release(struct inode *inode, str
28913 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28914 task_pid_nr(current),
28915 (long)old_encode_dev(file_priv->minor->device),
28916- dev->open_count);
28917+ local_read(&dev->open_count));
28918
28919 /* if the master has gone away we can't do anything with the lock */
28920 if (file_priv->minor->master)
28921@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, str
28922 * End inline drm_release
28923 */
28924
28925- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28926- if (!--dev->open_count) {
28927+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28928+ if (local_dec_and_test(&dev->open_count)) {
28929 if (atomic_read(&dev->ioctl_count)) {
28930 DRM_ERROR("Device busy: %d\n",
28931 atomic_read(&dev->ioctl_count));
28932diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_global.c linux-2.6.39.1/drivers/gpu/drm/drm_global.c
28933--- linux-2.6.39.1/drivers/gpu/drm/drm_global.c 2011-05-19 00:06:34.000000000 -0400
28934+++ linux-2.6.39.1/drivers/gpu/drm/drm_global.c 2011-05-22 19:36:31.000000000 -0400
28935@@ -36,7 +36,7 @@
28936 struct drm_global_item {
28937 struct mutex mutex;
28938 void *object;
28939- int refcount;
28940+ atomic_t refcount;
28941 };
28942
28943 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28944@@ -49,7 +49,7 @@ void drm_global_init(void)
28945 struct drm_global_item *item = &glob[i];
28946 mutex_init(&item->mutex);
28947 item->object = NULL;
28948- item->refcount = 0;
28949+ atomic_set(&item->refcount, 0);
28950 }
28951 }
28952
28953@@ -59,7 +59,7 @@ void drm_global_release(void)
28954 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28955 struct drm_global_item *item = &glob[i];
28956 BUG_ON(item->object != NULL);
28957- BUG_ON(item->refcount != 0);
28958+ BUG_ON(atomic_read(&item->refcount) != 0);
28959 }
28960 }
28961
28962@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
28963 void *object;
28964
28965 mutex_lock(&item->mutex);
28966- if (item->refcount == 0) {
28967+ if (atomic_read(&item->refcount) == 0) {
28968 item->object = kzalloc(ref->size, GFP_KERNEL);
28969 if (unlikely(item->object == NULL)) {
28970 ret = -ENOMEM;
28971@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
28972 goto out_err;
28973
28974 }
28975- ++item->refcount;
28976+ atomic_inc(&item->refcount);
28977 ref->object = item->object;
28978 object = item->object;
28979 mutex_unlock(&item->mutex);
28980@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
28981 struct drm_global_item *item = &glob[ref->global_type];
28982
28983 mutex_lock(&item->mutex);
28984- BUG_ON(item->refcount == 0);
28985+ BUG_ON(atomic_read(&item->refcount) == 0);
28986 BUG_ON(ref->object != item->object);
28987- if (--item->refcount == 0) {
28988+ if (atomic_dec_and_test(&item->refcount)) {
28989 ref->release(ref);
28990 item->object = NULL;
28991 }
28992diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_info.c linux-2.6.39.1/drivers/gpu/drm/drm_info.c
28993--- linux-2.6.39.1/drivers/gpu/drm/drm_info.c 2011-05-19 00:06:34.000000000 -0400
28994+++ linux-2.6.39.1/drivers/gpu/drm/drm_info.c 2011-05-22 19:41:37.000000000 -0400
28995@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
28996 struct drm_local_map *map;
28997 struct drm_map_list *r_list;
28998
28999- /* Hardcoded from _DRM_FRAME_BUFFER,
29000- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29001- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29002- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29003+ static const char * const types[] = {
29004+ [_DRM_FRAME_BUFFER] = "FB",
29005+ [_DRM_REGISTERS] = "REG",
29006+ [_DRM_SHM] = "SHM",
29007+ [_DRM_AGP] = "AGP",
29008+ [_DRM_SCATTER_GATHER] = "SG",
29009+ [_DRM_CONSISTENT] = "PCI",
29010+ [_DRM_GEM] = "GEM" };
29011 const char *type;
29012 int i;
29013
29014@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
29015 map = r_list->map;
29016 if (!map)
29017 continue;
29018- if (map->type < 0 || map->type > 5)
29019+ if (map->type >= ARRAY_SIZE(types))
29020 type = "??";
29021 else
29022 type = types[map->type];
29023@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, voi
29024 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29025 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29026 vma->vm_flags & VM_IO ? 'i' : '-',
29027+#ifdef CONFIG_GRKERNSEC_HIDESYM
29028+ 0);
29029+#else
29030 vma->vm_pgoff);
29031+#endif
29032
29033 #if defined(__i386__)
29034 pgprot = pgprot_val(vma->vm_page_prot);
29035diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c
29036--- linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c 2011-05-19 00:06:34.000000000 -0400
29037+++ linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c 2011-05-22 19:36:31.000000000 -0400
29038@@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev,
29039 stats->data[i].value =
29040 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29041 else
29042- stats->data[i].value = atomic_read(&dev->counts[i]);
29043+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29044 stats->data[i].type = dev->types[i];
29045 }
29046
29047diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_lock.c linux-2.6.39.1/drivers/gpu/drm/drm_lock.c
29048--- linux-2.6.39.1/drivers/gpu/drm/drm_lock.c 2011-05-19 00:06:34.000000000 -0400
29049+++ linux-2.6.39.1/drivers/gpu/drm/drm_lock.c 2011-05-22 19:36:31.000000000 -0400
29050@@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
29051 if (drm_lock_take(&master->lock, lock->context)) {
29052 master->lock.file_priv = file_priv;
29053 master->lock.lock_time = jiffies;
29054- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29055+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29056 break; /* Got lock */
29057 }
29058
29059@@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
29060 return -EINVAL;
29061 }
29062
29063- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29064+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29065
29066 if (drm_lock_free(&master->lock, lock->context)) {
29067 /* FIXME: Should really bail out here. */
29068diff -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
29069--- linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c 2011-05-19 00:06:34.000000000 -0400
29070+++ linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c 2011-05-22 19:36:31.000000000 -0400
29071@@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_de
29072 dma->buflist[vertex->idx],
29073 vertex->discard, vertex->used);
29074
29075- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29076- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29077+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29078+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29079 sarea_priv->last_enqueue = dev_priv->counter - 1;
29080 sarea_priv->last_dispatch = (int)hw_status[5];
29081
29082@@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device
29083 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29084 mc->last_render);
29085
29086- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29087- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29088+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29089+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29090 sarea_priv->last_enqueue = dev_priv->counter - 1;
29091 sarea_priv->last_dispatch = (int)hw_status[5];
29092
29093diff -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
29094--- linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h 2011-05-19 00:06:34.000000000 -0400
29095+++ linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h 2011-05-22 19:36:31.000000000 -0400
29096@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29097 int page_flipping;
29098
29099 wait_queue_head_t irq_queue;
29100- atomic_t irq_received;
29101- atomic_t irq_emitted;
29102+ atomic_unchecked_t irq_received;
29103+ atomic_unchecked_t irq_emitted;
29104
29105 int front_offset;
29106 } drm_i810_private_t;
29107diff -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
29108--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-19 00:06:34.000000000 -0400
29109+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-22 19:36:31.000000000 -0400
29110@@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
29111 }
29112 }
29113
29114-struct intel_dvo_dev_ops ch7017_ops = {
29115+const struct intel_dvo_dev_ops ch7017_ops = {
29116 .init = ch7017_init,
29117 .detect = ch7017_detect,
29118 .mode_valid = ch7017_mode_valid,
29119diff -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
29120--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-19 00:06:34.000000000 -0400
29121+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-22 19:36:31.000000000 -0400
29122@@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
29123 }
29124 }
29125
29126-struct intel_dvo_dev_ops ch7xxx_ops = {
29127+const struct intel_dvo_dev_ops ch7xxx_ops = {
29128 .init = ch7xxx_init,
29129 .detect = ch7xxx_detect,
29130 .mode_valid = ch7xxx_mode_valid,
29131diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h
29132--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h 2011-05-19 00:06:34.000000000 -0400
29133+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h 2011-05-22 19:36:31.000000000 -0400
29134@@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
29135 *
29136 * \return singly-linked list of modes or NULL if no modes found.
29137 */
29138- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
29139+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
29140
29141 /**
29142 * Clean up driver-specific bits of the output
29143 */
29144- void (*destroy) (struct intel_dvo_device *dvo);
29145+ void (* const destroy) (struct intel_dvo_device *dvo);
29146
29147 /**
29148 * Debugging hook to dump device registers to log file
29149 */
29150- void (*dump_regs)(struct intel_dvo_device *dvo);
29151+ void (* const dump_regs)(struct intel_dvo_device *dvo);
29152 };
29153
29154-extern struct intel_dvo_dev_ops sil164_ops;
29155-extern struct intel_dvo_dev_ops ch7xxx_ops;
29156-extern struct intel_dvo_dev_ops ivch_ops;
29157-extern struct intel_dvo_dev_ops tfp410_ops;
29158-extern struct intel_dvo_dev_ops ch7017_ops;
29159+extern const struct intel_dvo_dev_ops sil164_ops;
29160+extern const struct intel_dvo_dev_ops ch7xxx_ops;
29161+extern const struct intel_dvo_dev_ops ivch_ops;
29162+extern const struct intel_dvo_dev_ops tfp410_ops;
29163+extern const struct intel_dvo_dev_ops ch7017_ops;
29164
29165 #endif /* _INTEL_DVO_H */
29166diff -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
29167--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-19 00:06:34.000000000 -0400
29168+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-22 19:36:31.000000000 -0400
29169@@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
29170 }
29171 }
29172
29173-struct intel_dvo_dev_ops ivch_ops= {
29174+const struct intel_dvo_dev_ops ivch_ops= {
29175 .init = ivch_init,
29176 .dpms = ivch_dpms,
29177 .mode_valid = ivch_mode_valid,
29178diff -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
29179--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-19 00:06:34.000000000 -0400
29180+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-22 19:36:31.000000000 -0400
29181@@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
29182 }
29183 }
29184
29185-struct intel_dvo_dev_ops sil164_ops = {
29186+const struct intel_dvo_dev_ops sil164_ops = {
29187 .init = sil164_init,
29188 .detect = sil164_detect,
29189 .mode_valid = sil164_mode_valid,
29190diff -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
29191--- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-19 00:06:34.000000000 -0400
29192+++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-22 19:36:31.000000000 -0400
29193@@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
29194 }
29195 }
29196
29197-struct intel_dvo_dev_ops tfp410_ops = {
29198+const struct intel_dvo_dev_ops tfp410_ops = {
29199 .init = tfp410_init,
29200 .detect = tfp410_detect,
29201 .mode_valid = tfp410_mode_valid,
29202diff -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
29203--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-19 00:06:34.000000000 -0400
29204+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-22 19:36:31.000000000 -0400
29205@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct se
29206 I915_READ(GTIMR));
29207 }
29208 seq_printf(m, "Interrupts received: %d\n",
29209- atomic_read(&dev_priv->irq_received));
29210+ atomic_read_unchecked(&dev_priv->irq_received));
29211 for (i = 0; i < I915_NUM_RINGS; i++) {
29212 if (IS_GEN6(dev)) {
29213 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29214diff -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
29215--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c 2011-05-19 00:06:34.000000000 -0400
29216+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c 2011-05-22 19:36:31.000000000 -0400
29217@@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(s
29218 bool can_switch;
29219
29220 spin_lock(&dev->count_lock);
29221- can_switch = (dev->open_count == 0);
29222+ can_switch = (local_read(&dev->open_count) == 0);
29223 spin_unlock(&dev->count_lock);
29224 return can_switch;
29225 }
29226diff -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
29227--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c 2011-05-19 00:06:34.000000000 -0400
29228+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c 2011-05-22 19:36:31.000000000 -0400
29229@@ -679,7 +679,7 @@ static const struct dev_pm_ops i915_pm_o
29230 .restore = i915_pm_resume,
29231 };
29232
29233-static struct vm_operations_struct i915_gem_vm_ops = {
29234+static const struct vm_operations_struct i915_gem_vm_ops = {
29235 .fault = i915_gem_fault,
29236 .open = drm_gem_vm_open,
29237 .close = drm_gem_vm_close,
29238diff -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
29239--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h 2011-05-19 00:06:34.000000000 -0400
29240+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h 2011-05-22 19:36:31.000000000 -0400
29241@@ -287,7 +287,7 @@ typedef struct drm_i915_private {
29242 int current_page;
29243 int page_flipping;
29244
29245- atomic_t irq_received;
29246+ atomic_unchecked_t irq_received;
29247
29248 /* protects the irq masks */
29249 spinlock_t irq_lock;
29250@@ -848,7 +848,7 @@ struct drm_i915_gem_object {
29251 * will be page flipped away on the next vblank. When it
29252 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29253 */
29254- atomic_t pending_flip;
29255+ atomic_unchecked_t pending_flip;
29256 };
29257
29258 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29259@@ -1232,7 +1232,7 @@ extern int intel_setup_gmbus(struct drm_
29260 extern void intel_teardown_gmbus(struct drm_device *dev);
29261 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29262 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29263-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29264+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29265 {
29266 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29267 }
29268diff -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
29269--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-19 00:06:34.000000000 -0400
29270+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-22 19:36:31.000000000 -0400
29271@@ -192,7 +192,7 @@ i915_gem_object_set_to_gpu_domain(struct
29272 i915_gem_release_mmap(obj);
29273
29274 if (obj->base.pending_write_domain)
29275- cd->flips |= atomic_read(&obj->pending_flip);
29276+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29277
29278 /* The actual obj->write_domain will be updated with
29279 * pending_write_domain after we emit the accumulated flush for all
29280diff -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
29281--- linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c 2011-05-19 00:06:34.000000000 -0400
29282+++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c 2011-05-22 19:36:31.000000000 -0400
29283@@ -1101,7 +1101,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29284 int ret = IRQ_NONE, pipe;
29285 bool blc_event = false;
29286
29287- atomic_inc(&dev_priv->irq_received);
29288+ atomic_inc_unchecked(&dev_priv->irq_received);
29289
29290 if (HAS_PCH_SPLIT(dev))
29291 return ironlake_irq_handler(dev);
29292@@ -1655,7 +1655,7 @@ void i915_driver_irq_preinstall(struct d
29293 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29294 int pipe;
29295
29296- atomic_set(&dev_priv->irq_received, 0);
29297+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29298
29299 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29300 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29301diff -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
29302--- linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c 2011-05-19 00:06:34.000000000 -0400
29303+++ linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c 2011-05-22 19:36:31.000000000 -0400
29304@@ -2244,7 +2244,7 @@ intel_pipe_set_base(struct drm_crtc *crt
29305
29306 wait_event(dev_priv->pending_flip_queue,
29307 atomic_read(&dev_priv->mm.wedged) ||
29308- atomic_read(&obj->pending_flip) == 0);
29309+ atomic_read_unchecked(&obj->pending_flip) == 0);
29310
29311 /* Big Hammer, we also need to ensure that any pending
29312 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29313@@ -2712,7 +2712,7 @@ static void intel_crtc_wait_for_pending_
29314 obj = to_intel_framebuffer(crtc->fb)->obj;
29315 dev_priv = crtc->dev->dev_private;
29316 wait_event(dev_priv->pending_flip_queue,
29317- atomic_read(&obj->pending_flip) == 0);
29318+ atomic_read_unchecked(&obj->pending_flip) == 0);
29319 }
29320
29321 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29322@@ -6016,7 +6016,7 @@ static void do_intel_finish_page_flip(st
29323
29324 atomic_clear_mask(1 << intel_crtc->plane,
29325 &obj->pending_flip.counter);
29326- if (atomic_read(&obj->pending_flip) == 0)
29327+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
29328 wake_up(&dev_priv->pending_flip_queue);
29329
29330 schedule_work(&work->work);
29331@@ -6145,7 +6145,7 @@ static int intel_crtc_page_flip(struct d
29332 /* Block clients from rendering to the new back buffer until
29333 * the flip occurs and the object is no longer visible.
29334 */
29335- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29336+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29337
29338 switch (INTEL_INFO(dev)->gen) {
29339 case 2:
29340diff -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
29341--- linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h 2011-05-19 00:06:34.000000000 -0400
29342+++ linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h 2011-05-22 19:36:31.000000000 -0400
29343@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29344 u32 clear_cmd;
29345 u32 maccess;
29346
29347- atomic_t vbl_received; /**< Number of vblanks received. */
29348+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29349 wait_queue_head_t fence_queue;
29350- atomic_t last_fence_retired;
29351+ atomic_unchecked_t last_fence_retired;
29352 u32 next_fence_to_post;
29353
29354 unsigned int fb_cpp;
29355diff -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
29356--- linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c 2011-05-19 00:06:34.000000000 -0400
29357+++ linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c 2011-05-22 19:36:31.000000000 -0400
29358@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29359 if (crtc != 0)
29360 return 0;
29361
29362- return atomic_read(&dev_priv->vbl_received);
29363+ return atomic_read_unchecked(&dev_priv->vbl_received);
29364 }
29365
29366
29367@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29368 /* VBLANK interrupt */
29369 if (status & MGA_VLINEPEN) {
29370 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29371- atomic_inc(&dev_priv->vbl_received);
29372+ atomic_inc_unchecked(&dev_priv->vbl_received);
29373 drm_handle_vblank(dev, 0);
29374 handled = 1;
29375 }
29376@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29377 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29378 MGA_WRITE(MGA_PRIMEND, prim_end);
29379
29380- atomic_inc(&dev_priv->last_fence_retired);
29381+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
29382 DRM_WAKEUP(&dev_priv->fence_queue);
29383 handled = 1;
29384 }
29385@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_dev
29386 * using fences.
29387 */
29388 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29389- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29390+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29391 - *sequence) <= (1 << 23)));
29392
29393 *sequence = cur_fence;
29394diff -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
29395--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-19 00:06:34.000000000 -0400
29396+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-22 19:36:31.000000000 -0400
29397@@ -141,7 +141,7 @@ static int nouveau_dsm_get_client_id(str
29398 return VGA_SWITCHEROO_DIS;
29399 }
29400
29401-static struct vga_switcheroo_handler nouveau_dsm_handler = {
29402+static const struct vga_switcheroo_handler nouveau_dsm_handler = {
29403 .switchto = nouveau_dsm_switchto,
29404 .power_state = nouveau_dsm_power_state,
29405 .init = nouveau_dsm_init,
29406diff -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
29407--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-19 00:06:34.000000000 -0400
29408+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-06-07 18:07:24.000000000 -0400
29409@@ -228,7 +228,7 @@ struct nouveau_channel {
29410 struct list_head pending;
29411 uint32_t sequence;
29412 uint32_t sequence_ack;
29413- atomic_t last_sequence_irq;
29414+ atomic_unchecked_t last_sequence_irq;
29415 } fence;
29416
29417 /* DMA push buffer */
29418@@ -662,7 +662,7 @@ struct drm_nouveau_private {
29419 struct drm_global_reference mem_global_ref;
29420 struct ttm_bo_global_ref bo_global_ref;
29421 struct ttm_bo_device bdev;
29422- atomic_t validate_sequence;
29423+ atomic_unchecked_t validate_sequence;
29424 } ttm;
29425
29426 struct {
29427diff -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
29428--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-19 00:06:34.000000000 -0400
29429+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-22 19:36:31.000000000 -0400
29430@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_chan
29431 if (USE_REFCNT(dev))
29432 sequence = nvchan_rd32(chan, 0x48);
29433 else
29434- sequence = atomic_read(&chan->fence.last_sequence_irq);
29435+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29436
29437 if (chan->fence.sequence_ack == sequence)
29438 goto out;
29439@@ -553,7 +553,7 @@ nouveau_fence_channel_init(struct nouvea
29440 out_initialised:
29441 INIT_LIST_HEAD(&chan->fence.pending);
29442 spin_lock_init(&chan->fence.lock);
29443- atomic_set(&chan->fence.last_sequence_irq, 0);
29444+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29445 return 0;
29446 }
29447
29448diff -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
29449--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-19 00:06:34.000000000 -0400
29450+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-22 19:36:31.000000000 -0400
29451@@ -249,7 +249,7 @@ validate_init(struct nouveau_channel *ch
29452 int trycnt = 0;
29453 int ret, i;
29454
29455- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29456+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29457 retry:
29458 if (++trycnt > 100000) {
29459 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29460diff -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
29461--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-19 00:06:34.000000000 -0400
29462+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-22 19:36:31.000000000 -0400
29463@@ -583,7 +583,7 @@ static bool nouveau_switcheroo_can_switc
29464 bool can_switch;
29465
29466 spin_lock(&dev->count_lock);
29467- can_switch = (dev->open_count == 0);
29468+ can_switch = (local_read(&dev->open_count) == 0);
29469 spin_unlock(&dev->count_lock);
29470 return can_switch;
29471 }
29472diff -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
29473--- linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-19 00:06:34.000000000 -0400
29474+++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-22 19:36:31.000000000 -0400
29475@@ -552,7 +552,7 @@ static int
29476 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29477 u32 class, u32 mthd, u32 data)
29478 {
29479- atomic_set(&chan->fence.last_sequence_irq, data);
29480+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29481 return 0;
29482 }
29483
29484diff -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
29485--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c 2011-05-19 00:06:34.000000000 -0400
29486+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c 2011-05-22 19:36:31.000000000 -0400
29487@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29488
29489 /* GH: Simple idle check.
29490 */
29491- atomic_set(&dev_priv->idle_count, 0);
29492+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29493
29494 /* We don't support anything other than bus-mastering ring mode,
29495 * but the ring can be in either AGP or PCI space for the ring
29496diff -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
29497--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h 2011-05-19 00:06:34.000000000 -0400
29498+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h 2011-05-22 19:36:31.000000000 -0400
29499@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29500 int is_pci;
29501 unsigned long cce_buffers_offset;
29502
29503- atomic_t idle_count;
29504+ atomic_unchecked_t idle_count;
29505
29506 int page_flipping;
29507 int current_page;
29508 u32 crtc_offset;
29509 u32 crtc_offset_cntl;
29510
29511- atomic_t vbl_received;
29512+ atomic_unchecked_t vbl_received;
29513
29514 u32 color_fmt;
29515 unsigned int front_offset;
29516diff -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
29517--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c 2011-05-19 00:06:34.000000000 -0400
29518+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c 2011-05-22 19:36:31.000000000 -0400
29519@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29520 if (crtc != 0)
29521 return 0;
29522
29523- return atomic_read(&dev_priv->vbl_received);
29524+ return atomic_read_unchecked(&dev_priv->vbl_received);
29525 }
29526
29527 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29528@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29529 /* VBLANK interrupt */
29530 if (status & R128_CRTC_VBLANK_INT) {
29531 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29532- atomic_inc(&dev_priv->vbl_received);
29533+ atomic_inc_unchecked(&dev_priv->vbl_received);
29534 drm_handle_vblank(dev, 0);
29535 return IRQ_HANDLED;
29536 }
29537diff -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
29538--- linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c 2011-05-19 00:06:34.000000000 -0400
29539+++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c 2011-05-22 19:36:31.000000000 -0400
29540@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_priv
29541
29542 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
29543 {
29544- if (atomic_read(&dev_priv->idle_count) == 0)
29545+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
29546 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29547 else
29548- atomic_set(&dev_priv->idle_count, 0);
29549+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29550 }
29551
29552 #endif
29553diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c
29554--- linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c 2011-05-19 00:06:34.000000000 -0400
29555+++ linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c 2011-05-22 19:36:31.000000000 -0400
29556@@ -1245,6 +1245,8 @@ struct atom_context *atom_parse(struct c
29557 char name[512];
29558 int i;
29559
29560+ pax_track_stack();
29561+
29562 ctx->card = card;
29563 ctx->bios = bios;
29564
29565diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c
29566--- linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c 2011-05-19 00:06:34.000000000 -0400
29567+++ linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c 2011-05-22 19:36:31.000000000 -0400
29568@@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
29569 regex_t mask_rex;
29570 regmatch_t match[4];
29571 char buf[1024];
29572- size_t end;
29573+ long end;
29574 int len;
29575 int done = 0;
29576 int r;
29577 unsigned o;
29578 struct offset *offset;
29579 char last_reg_s[10];
29580- int last_reg;
29581+ unsigned long last_reg;
29582
29583 if (regcomp
29584 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29585diff -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
29586--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-19 00:06:34.000000000 -0400
29587+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-22 19:36:31.000000000 -0400
29588@@ -545,6 +545,8 @@ bool radeon_get_atom_connector_info_from
29589 struct radeon_gpio_rec gpio;
29590 struct radeon_hpd hpd;
29591
29592+ pax_track_stack();
29593+
29594 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
29595 return false;
29596
29597diff -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
29598--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-19 00:06:34.000000000 -0400
29599+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-22 19:36:31.000000000 -0400
29600@@ -234,7 +234,7 @@ static int radeon_atpx_get_client_id(str
29601 return VGA_SWITCHEROO_DIS;
29602 }
29603
29604-static struct vga_switcheroo_handler radeon_atpx_handler = {
29605+static const struct vga_switcheroo_handler radeon_atpx_handler = {
29606 .switchto = radeon_atpx_switchto,
29607 .power_state = radeon_atpx_power_state,
29608 .init = radeon_atpx_init,
29609diff -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
29610--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c 2011-05-19 00:06:34.000000000 -0400
29611+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c 2011-05-22 19:36:31.000000000 -0400
29612@@ -674,7 +674,7 @@ static bool radeon_switcheroo_can_switch
29613 bool can_switch;
29614
29615 spin_lock(&dev->count_lock);
29616- can_switch = (dev->open_count == 0);
29617+ can_switch = (local_read(&dev->open_count) == 0);
29618 spin_unlock(&dev->count_lock);
29619 return can_switch;
29620 }
29621diff -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
29622--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c 2011-05-19 00:06:34.000000000 -0400
29623+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c 2011-05-22 19:36:31.000000000 -0400
29624@@ -934,6 +934,8 @@ void radeon_compute_pll_legacy(struct ra
29625 uint32_t post_div;
29626 u32 pll_out_min, pll_out_max;
29627
29628+ pax_track_stack();
29629+
29630 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
29631 freq = freq * 1000;
29632
29633diff -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
29634--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-19 00:06:34.000000000 -0400
29635+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-22 19:36:31.000000000 -0400
29636@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
29637
29638 /* SW interrupt */
29639 wait_queue_head_t swi_queue;
29640- atomic_t swi_emitted;
29641+ atomic_unchecked_t swi_emitted;
29642 int vblank_crtc;
29643 uint32_t irq_enable_reg;
29644 uint32_t r500_disp_irq_reg;
29645diff -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
29646--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-19 00:06:34.000000000 -0400
29647+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-22 19:36:31.000000000 -0400
29648@@ -49,7 +49,7 @@ int radeon_fence_emit(struct radeon_devi
29649 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29650 return 0;
29651 }
29652- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29653+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29654 if (!rdev->cp.ready) {
29655 /* FIXME: cp is not running assume everythings is done right
29656 * away
29657@@ -352,7 +352,7 @@ int radeon_fence_driver_init(struct rade
29658 return r;
29659 }
29660 WREG32(rdev->fence_drv.scratch_reg, 0);
29661- atomic_set(&rdev->fence_drv.seq, 0);
29662+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
29663 INIT_LIST_HEAD(&rdev->fence_drv.created);
29664 INIT_LIST_HEAD(&rdev->fence_drv.emited);
29665 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
29666diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h
29667--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h 2011-05-19 00:06:34.000000000 -0400
29668+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h 2011-05-22 19:36:31.000000000 -0400
29669@@ -189,7 +189,7 @@ extern int sumo_get_temp(struct radeon_d
29670 */
29671 struct radeon_fence_driver {
29672 uint32_t scratch_reg;
29673- atomic_t seq;
29674+ atomic_unchecked_t seq;
29675 uint32_t last_seq;
29676 unsigned long last_jiffies;
29677 unsigned long last_timeout;
29678diff -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
29679--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-19 00:06:34.000000000 -0400
29680+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-22 19:36:31.000000000 -0400
29681@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(str
29682 request = compat_alloc_user_space(sizeof(*request));
29683 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
29684 || __put_user(req32.param, &request->param)
29685- || __put_user((void __user *)(unsigned long)req32.value,
29686+ || __put_user((unsigned long)req32.value,
29687 &request->value))
29688 return -EFAULT;
29689
29690diff -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
29691--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-19 00:06:34.000000000 -0400
29692+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-22 19:36:31.000000000 -0400
29693@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
29694 unsigned int ret;
29695 RING_LOCALS;
29696
29697- atomic_inc(&dev_priv->swi_emitted);
29698- ret = atomic_read(&dev_priv->swi_emitted);
29699+ atomic_inc_unchecked(&dev_priv->swi_emitted);
29700+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29701
29702 BEGIN_RING(4);
29703 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29704@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
29705 drm_radeon_private_t *dev_priv =
29706 (drm_radeon_private_t *) dev->dev_private;
29707
29708- atomic_set(&dev_priv->swi_emitted, 0);
29709+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29710 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29711
29712 dev->max_vblank_count = 0x001fffff;
29713diff -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
29714--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c 2011-05-19 00:06:34.000000000 -0400
29715+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c 2011-05-22 19:36:31.000000000 -0400
29716@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
29717 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29718 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29719
29720- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29721+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29722 sarea_priv->nbox * sizeof(depth_boxes[0])))
29723 return -EFAULT;
29724
29725@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
29726 {
29727 drm_radeon_private_t *dev_priv = dev->dev_private;
29728 drm_radeon_getparam_t *param = data;
29729- int value;
29730+ int value = 0;
29731
29732 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29733
29734diff -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
29735--- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-19 00:06:34.000000000 -0400
29736+++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-22 19:36:31.000000000 -0400
29737@@ -603,8 +603,9 @@ void radeon_ttm_set_active_vram_size(str
29738 man->size = size >> PAGE_SHIFT;
29739 }
29740
29741-static struct vm_operations_struct radeon_ttm_vm_ops;
29742-static const struct vm_operations_struct *ttm_vm_ops = NULL;
29743+extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
29744+extern void ttm_bo_vm_open(struct vm_area_struct *vma);
29745+extern void ttm_bo_vm_close(struct vm_area_struct *vma);
29746
29747 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29748 {
29749@@ -612,17 +613,22 @@ static int radeon_ttm_fault(struct vm_ar
29750 struct radeon_device *rdev;
29751 int r;
29752
29753- bo = (struct ttm_buffer_object *)vma->vm_private_data;
29754- if (bo == NULL) {
29755+ bo = (struct ttm_buffer_object *)vma->vm_private_data;
29756+ if (!bo)
29757 return VM_FAULT_NOPAGE;
29758- }
29759 rdev = radeon_get_rdev(bo->bdev);
29760 mutex_lock(&rdev->vram_mutex);
29761- r = ttm_vm_ops->fault(vma, vmf);
29762+ r = ttm_bo_vm_fault(vma, vmf);
29763 mutex_unlock(&rdev->vram_mutex);
29764 return r;
29765 }
29766
29767+static const struct vm_operations_struct radeon_ttm_vm_ops = {
29768+ .fault = radeon_ttm_fault,
29769+ .open = ttm_bo_vm_open,
29770+ .close = ttm_bo_vm_close
29771+};
29772+
29773 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29774 {
29775 struct drm_file *file_priv;
29776@@ -635,18 +641,11 @@ int radeon_mmap(struct file *filp, struc
29777
29778 file_priv = filp->private_data;
29779 rdev = file_priv->minor->dev->dev_private;
29780- if (rdev == NULL) {
29781+ if (!rdev)
29782 return -EINVAL;
29783- }
29784 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29785- if (unlikely(r != 0)) {
29786+ if (r)
29787 return r;
29788- }
29789- if (unlikely(ttm_vm_ops == NULL)) {
29790- ttm_vm_ops = vma->vm_ops;
29791- radeon_ttm_vm_ops = *ttm_vm_ops;
29792- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29793- }
29794 vma->vm_ops = &radeon_ttm_vm_ops;
29795 return 0;
29796 }
29797diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c
29798--- linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c 2011-05-19 00:06:34.000000000 -0400
29799+++ linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c 2011-05-22 19:36:31.000000000 -0400
29800@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct
29801 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29802 rdev->pm.sideport_bandwidth.full)
29803 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29804- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29805+ read_delay_latency.full = dfixed_const(800 * 1000);
29806 read_delay_latency.full = dfixed_div(read_delay_latency,
29807 rdev->pm.igp_sideport_mclk);
29808+ a.full = dfixed_const(370);
29809+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29810 } else {
29811 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29812 rdev->pm.k8_bandwidth.full)
29813diff -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
29814--- linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-19 00:06:34.000000000 -0400
29815+++ linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-22 19:36:31.000000000 -0400
29816@@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
29817 return best_bo;
29818 }
29819
29820-static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29821+int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29822 {
29823 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
29824 vma->vm_private_data;
29825- struct ttm_bo_device *bdev = bo->bdev;
29826+ struct ttm_bo_device *bdev;
29827 unsigned long page_offset;
29828 unsigned long page_last;
29829 unsigned long pfn;
29830@@ -83,8 +83,12 @@ static int ttm_bo_vm_fault(struct vm_are
29831 int i;
29832 unsigned long address = (unsigned long)vmf->virtual_address;
29833 int retval = VM_FAULT_NOPAGE;
29834- struct ttm_mem_type_manager *man =
29835- &bdev->man[bo->mem.mem_type];
29836+ struct ttm_mem_type_manager *man;
29837+
29838+ if (!bo)
29839+ return VM_FAULT_NOPAGE;
29840+ bdev = bo->bdev;
29841+ man = &bdev->man[bo->mem.mem_type];
29842
29843 /*
29844 * Work around locking order reversal in fault / nopfn
29845@@ -219,22 +223,25 @@ out_unlock:
29846 ttm_bo_unreserve(bo);
29847 return retval;
29848 }
29849+EXPORT_SYMBOL(ttm_bo_vm_fault);
29850
29851-static void ttm_bo_vm_open(struct vm_area_struct *vma)
29852+void ttm_bo_vm_open(struct vm_area_struct *vma)
29853 {
29854 struct ttm_buffer_object *bo =
29855 (struct ttm_buffer_object *)vma->vm_private_data;
29856
29857 (void)ttm_bo_reference(bo);
29858 }
29859+EXPORT_SYMBOL(ttm_bo_vm_open);
29860
29861-static void ttm_bo_vm_close(struct vm_area_struct *vma)
29862+void ttm_bo_vm_close(struct vm_area_struct *vma)
29863 {
29864 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
29865
29866 ttm_bo_unref(&bo);
29867 vma->vm_private_data = NULL;
29868 }
29869+EXPORT_SYMBOL(ttm_bo_vm_close);
29870
29871 static const struct vm_operations_struct ttm_bo_vm_ops = {
29872 .fault = ttm_bo_vm_fault,
29873diff -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
29874--- linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-19 00:06:34.000000000 -0400
29875+++ linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-22 19:36:31.000000000 -0400
29876@@ -397,9 +397,9 @@ static int ttm_pool_get_num_unused_pages
29877 */
29878 static int ttm_pool_mm_shrink(struct shrinker *shrink, int shrink_pages, gfp_t gfp_mask)
29879 {
29880- static atomic_t start_pool = ATOMIC_INIT(0);
29881+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29882 unsigned i;
29883- unsigned pool_offset = atomic_add_return(1, &start_pool);
29884+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29885 struct ttm_page_pool *pool;
29886
29887 pool_offset = pool_offset % NUM_POOLS;
29888diff -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
29889--- linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h 2011-05-19 00:06:34.000000000 -0400
29890+++ linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h 2011-05-22 19:36:31.000000000 -0400
29891@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29892 typedef uint32_t maskarray_t[5];
29893
29894 typedef struct drm_via_irq {
29895- atomic_t irq_received;
29896+ atomic_unchecked_t irq_received;
29897 uint32_t pending_mask;
29898 uint32_t enable_mask;
29899 wait_queue_head_t irq_queue;
29900@@ -75,7 +75,7 @@ typedef struct drm_via_private {
29901 struct timeval last_vblank;
29902 int last_vblank_valid;
29903 unsigned usec_per_vblank;
29904- atomic_t vbl_received;
29905+ atomic_unchecked_t vbl_received;
29906 drm_via_state_t hc_state;
29907 char pci_buf[VIA_PCI_BUF_SIZE];
29908 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29909diff -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
29910--- linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c 2011-05-19 00:06:34.000000000 -0400
29911+++ linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c 2011-05-22 19:36:31.000000000 -0400
29912@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
29913 if (crtc != 0)
29914 return 0;
29915
29916- return atomic_read(&dev_priv->vbl_received);
29917+ return atomic_read_unchecked(&dev_priv->vbl_received);
29918 }
29919
29920 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29921@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
29922
29923 status = VIA_READ(VIA_REG_INTERRUPT);
29924 if (status & VIA_IRQ_VBLANK_PENDING) {
29925- atomic_inc(&dev_priv->vbl_received);
29926- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29927+ atomic_inc_unchecked(&dev_priv->vbl_received);
29928+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29929 do_gettimeofday(&cur_vblank);
29930 if (dev_priv->last_vblank_valid) {
29931 dev_priv->usec_per_vblank =
29932@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29933 dev_priv->last_vblank = cur_vblank;
29934 dev_priv->last_vblank_valid = 1;
29935 }
29936- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29937+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29938 DRM_DEBUG("US per vblank is: %u\n",
29939 dev_priv->usec_per_vblank);
29940 }
29941@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29942
29943 for (i = 0; i < dev_priv->num_irqs; ++i) {
29944 if (status & cur_irq->pending_mask) {
29945- atomic_inc(&cur_irq->irq_received);
29946+ atomic_inc_unchecked(&cur_irq->irq_received);
29947 DRM_WAKEUP(&cur_irq->irq_queue);
29948 handled = 1;
29949 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29950@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *d
29951 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29952 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29953 masks[irq][4]));
29954- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29955+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29956 } else {
29957 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29958 (((cur_irq_sequence =
29959- atomic_read(&cur_irq->irq_received)) -
29960+ atomic_read_unchecked(&cur_irq->irq_received)) -
29961 *sequence) <= (1 << 23)));
29962 }
29963 *sequence = cur_irq_sequence;
29964@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct dr
29965 }
29966
29967 for (i = 0; i < dev_priv->num_irqs; ++i) {
29968- atomic_set(&cur_irq->irq_received, 0);
29969+ atomic_set_unchecked(&cur_irq->irq_received, 0);
29970 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29971 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29972 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29973@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev,
29974 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29975 case VIA_IRQ_RELATIVE:
29976 irqwait->request.sequence +=
29977- atomic_read(&cur_irq->irq_received);
29978+ atomic_read_unchecked(&cur_irq->irq_received);
29979 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29980 case VIA_IRQ_ABSOLUTE:
29981 break;
29982diff -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
29983--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-19 00:06:34.000000000 -0400
29984+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-22 19:36:31.000000000 -0400
29985@@ -240,7 +240,7 @@ struct vmw_private {
29986 * Fencing and IRQs.
29987 */
29988
29989- atomic_t fence_seq;
29990+ atomic_unchecked_t fence_seq;
29991 wait_queue_head_t fence_queue;
29992 wait_queue_head_t fifo_queue;
29993 atomic_t fence_queue_waiters;
29994diff -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
29995--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-19 00:06:34.000000000 -0400
29996+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-22 19:36:31.000000000 -0400
29997@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev
29998 while (!vmw_lag_lt(queue, us)) {
29999 spin_lock(&queue->lock);
30000 if (list_empty(&queue->head))
30001- sequence = atomic_read(&dev_priv->fence_seq);
30002+ sequence = atomic_read_unchecked(&dev_priv->fence_seq);
30003 else {
30004 fence = list_first_entry(&queue->head,
30005 struct vmw_fence, head);
30006diff -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
30007--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-19 00:06:34.000000000 -0400
30008+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-22 19:36:31.000000000 -0400
30009@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *de
30010 (unsigned int) min,
30011 (unsigned int) fifo->capabilities);
30012
30013- atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
30014+ atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
30015 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
30016 vmw_fence_queue_init(&fifo->fence_queue);
30017 return vmw_fifo_send_fence(dev_priv, &dummy);
30018@@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_priva
30019
30020 fm = vmw_fifo_reserve(dev_priv, bytes);
30021 if (unlikely(fm == NULL)) {
30022- *sequence = atomic_read(&dev_priv->fence_seq);
30023+ *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
30024 ret = -ENOMEM;
30025 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
30026 false, 3*HZ);
30027@@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_priva
30028 }
30029
30030 do {
30031- *sequence = atomic_add_return(1, &dev_priv->fence_seq);
30032+ *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
30033 } while (*sequence == 0);
30034
30035 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
30036@@ -534,7 +534,7 @@ static int vmw_fifo_vm_fault(struct vm_a
30037 return VM_FAULT_SIGBUS;
30038 }
30039
30040-static struct vm_operations_struct vmw_fifo_vm_ops = {
30041+static const struct vm_operations_struct vmw_fifo_vm_ops = {
30042 .fault = vmw_fifo_vm_fault,
30043 .open = NULL,
30044 .close = NULL
30045diff -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
30046--- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-19 00:06:34.000000000 -0400
30047+++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-22 19:36:31.000000000 -0400
30048@@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_priva
30049 * emitted. Then the fence is stale and signaled.
30050 */
30051
30052- ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
30053+ ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
30054 > VMW_FENCE_WRAP);
30055
30056 return ret;
30057@@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private
30058
30059 if (fifo_idle)
30060 down_read(&fifo_state->rwsem);
30061- signal_seq = atomic_read(&dev_priv->fence_seq);
30062+ signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
30063 ret = 0;
30064
30065 for (;;) {
30066diff -urNp linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c
30067--- linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c 2011-05-19 00:06:34.000000000 -0400
30068+++ linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c 2011-05-22 19:36:31.000000000 -0400
30069@@ -53,7 +53,7 @@ struct vgasr_priv {
30070 int registered_clients;
30071 struct vga_switcheroo_client clients[VGA_SWITCHEROO_MAX_CLIENTS];
30072
30073- struct vga_switcheroo_handler *handler;
30074+ const struct vga_switcheroo_handler *handler;
30075 };
30076
30077 static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
30078@@ -62,7 +62,7 @@ static void vga_switcheroo_debugfs_fini(
30079 /* only one switcheroo per system */
30080 static struct vgasr_priv vgasr_priv;
30081
30082-int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
30083+int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler)
30084 {
30085 mutex_lock(&vgasr_mutex);
30086 if (vgasr_priv.handler) {
30087diff -urNp linux-2.6.39.1/drivers/hid/hid-core.c linux-2.6.39.1/drivers/hid/hid-core.c
30088--- linux-2.6.39.1/drivers/hid/hid-core.c 2011-05-19 00:06:34.000000000 -0400
30089+++ linux-2.6.39.1/drivers/hid/hid-core.c 2011-05-22 19:36:31.000000000 -0400
30090@@ -1888,7 +1888,7 @@ static bool hid_ignore(struct hid_device
30091
30092 int hid_add_device(struct hid_device *hdev)
30093 {
30094- static atomic_t id = ATOMIC_INIT(0);
30095+ static atomic_unchecked_t id = ATOMIC_INIT(0);
30096 int ret;
30097
30098 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30099@@ -1903,7 +1903,7 @@ int hid_add_device(struct hid_device *hd
30100 /* XXX hack, any other cleaner solution after the driver core
30101 * is converted to allow more than 20 bytes as the device name? */
30102 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30103- hdev->vendor, hdev->product, atomic_inc_return(&id));
30104+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30105
30106 hid_debug_register(hdev, dev_name(&hdev->dev));
30107 ret = device_add(&hdev->dev);
30108diff -urNp linux-2.6.39.1/drivers/hid/hid-picolcd.c linux-2.6.39.1/drivers/hid/hid-picolcd.c
30109--- linux-2.6.39.1/drivers/hid/hid-picolcd.c 2011-05-19 00:06:34.000000000 -0400
30110+++ linux-2.6.39.1/drivers/hid/hid-picolcd.c 2011-05-22 19:36:31.000000000 -0400
30111@@ -1037,7 +1037,7 @@ static int picolcd_check_lcd_fb(struct l
30112 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
30113 }
30114
30115-static struct lcd_ops picolcd_lcdops = {
30116+static const struct lcd_ops picolcd_lcdops = {
30117 .get_contrast = picolcd_get_contrast,
30118 .set_contrast = picolcd_set_contrast,
30119 .check_fb = picolcd_check_lcd_fb,
30120diff -urNp linux-2.6.39.1/drivers/hid/usbhid/hiddev.c linux-2.6.39.1/drivers/hid/usbhid/hiddev.c
30121--- linux-2.6.39.1/drivers/hid/usbhid/hiddev.c 2011-05-19 00:06:34.000000000 -0400
30122+++ linux-2.6.39.1/drivers/hid/usbhid/hiddev.c 2011-05-22 19:36:31.000000000 -0400
30123@@ -613,7 +613,7 @@ static long hiddev_ioctl(struct file *fi
30124 break;
30125
30126 case HIDIOCAPPLICATION:
30127- if (arg < 0 || arg >= hid->maxapplication)
30128+ if (arg >= hid->maxapplication)
30129 break;
30130
30131 for (i = 0; i < hid->maxcollection; i++)
30132diff -urNp linux-2.6.39.1/drivers/hwmon/ibmaem.c linux-2.6.39.1/drivers/hwmon/ibmaem.c
30133--- linux-2.6.39.1/drivers/hwmon/ibmaem.c 2011-05-19 00:06:34.000000000 -0400
30134+++ linux-2.6.39.1/drivers/hwmon/ibmaem.c 2011-05-22 19:36:31.000000000 -0400
30135@@ -238,7 +238,7 @@ struct aem_read_sensor_resp {
30136 struct aem_driver_data {
30137 struct list_head aem_devices;
30138 struct ipmi_smi_watcher bmc_events;
30139- struct ipmi_user_hndl ipmi_hndlrs;
30140+ const struct ipmi_user_hndl ipmi_hndlrs;
30141 };
30142
30143 static void aem_register_bmc(int iface, struct device *dev);
30144diff -urNp linux-2.6.39.1/drivers/hwmon/ibmpex.c linux-2.6.39.1/drivers/hwmon/ibmpex.c
30145--- linux-2.6.39.1/drivers/hwmon/ibmpex.c 2011-05-19 00:06:34.000000000 -0400
30146+++ linux-2.6.39.1/drivers/hwmon/ibmpex.c 2011-05-22 19:36:31.000000000 -0400
30147@@ -110,7 +110,7 @@ struct ibmpex_bmc_data {
30148 struct ibmpex_driver_data {
30149 struct list_head bmc_data;
30150 struct ipmi_smi_watcher bmc_events;
30151- struct ipmi_user_hndl ipmi_hndlrs;
30152+ const struct ipmi_user_hndl ipmi_hndlrs;
30153 };
30154
30155 static struct ibmpex_driver_data driver_data = {
30156diff -urNp linux-2.6.39.1/drivers/hwmon/sht15.c linux-2.6.39.1/drivers/hwmon/sht15.c
30157--- linux-2.6.39.1/drivers/hwmon/sht15.c 2011-05-19 00:06:34.000000000 -0400
30158+++ linux-2.6.39.1/drivers/hwmon/sht15.c 2011-05-22 19:36:31.000000000 -0400
30159@@ -113,7 +113,7 @@ struct sht15_data {
30160 int supply_uV;
30161 int supply_uV_valid;
30162 struct work_struct update_supply_work;
30163- atomic_t interrupt_handled;
30164+ atomic_unchecked_t interrupt_handled;
30165 };
30166
30167 /**
30168@@ -246,13 +246,13 @@ static inline int sht15_update_single_va
30169 return ret;
30170
30171 gpio_direction_input(data->pdata->gpio_data);
30172- atomic_set(&data->interrupt_handled, 0);
30173+ atomic_set_unchecked(&data->interrupt_handled, 0);
30174
30175 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30176 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30177 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30178 /* Only relevant if the interrupt hasn't occurred. */
30179- if (!atomic_read(&data->interrupt_handled))
30180+ if (!atomic_read_unchecked(&data->interrupt_handled))
30181 schedule_work(&data->read_work);
30182 }
30183 ret = wait_event_timeout(data->wait_queue,
30184@@ -399,7 +399,7 @@ static irqreturn_t sht15_interrupt_fired
30185 struct sht15_data *data = d;
30186 /* First disable the interrupt */
30187 disable_irq_nosync(irq);
30188- atomic_inc(&data->interrupt_handled);
30189+ atomic_inc_unchecked(&data->interrupt_handled);
30190 /* Then schedule a reading work struct */
30191 if (data->flag != SHT15_READING_NOTHING)
30192 schedule_work(&data->read_work);
30193@@ -450,11 +450,11 @@ static void sht15_bh_read_data(struct wo
30194 here as could have gone low in meantime so verify
30195 it hasn't!
30196 */
30197- atomic_set(&data->interrupt_handled, 0);
30198+ atomic_set_unchecked(&data->interrupt_handled, 0);
30199 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30200 /* If still not occurred or another handler has been scheduled */
30201 if (gpio_get_value(data->pdata->gpio_data)
30202- || atomic_read(&data->interrupt_handled))
30203+ || atomic_read_unchecked(&data->interrupt_handled))
30204 return;
30205 }
30206 /* Read the data back from the device */
30207diff -urNp linux-2.6.39.1/drivers/hwmon/w83791d.c linux-2.6.39.1/drivers/hwmon/w83791d.c
30208--- linux-2.6.39.1/drivers/hwmon/w83791d.c 2011-05-19 00:06:34.000000000 -0400
30209+++ linux-2.6.39.1/drivers/hwmon/w83791d.c 2011-05-22 19:36:31.000000000 -0400
30210@@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
30211 struct i2c_board_info *info);
30212 static int w83791d_remove(struct i2c_client *client);
30213
30214-static int w83791d_read(struct i2c_client *client, u8 register);
30215-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30216+static int w83791d_read(struct i2c_client *client, u8 reg);
30217+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30218 static struct w83791d_data *w83791d_update_device(struct device *dev);
30219
30220 #ifdef DEBUG
30221diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c
30222--- linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c 2011-05-19 00:06:34.000000000 -0400
30223+++ linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c 2011-05-22 19:36:31.000000000 -0400
30224@@ -181,7 +181,7 @@ static u32 at91_func(struct i2c_adapter
30225 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30226 }
30227
30228-static struct i2c_algorithm at91_algorithm = {
30229+static const struct i2c_algorithm at91_algorithm = {
30230 .master_xfer = at91_xfer,
30231 .functionality = at91_func,
30232 };
30233diff -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
30234--- linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-19 00:06:34.000000000 -0400
30235+++ linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-22 19:36:31.000000000 -0400
30236@@ -599,7 +599,7 @@ static u32 bfin_twi_functionality(struct
30237 I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
30238 }
30239
30240-static struct i2c_algorithm bfin_twi_algorithm = {
30241+static const struct i2c_algorithm bfin_twi_algorithm = {
30242 .master_xfer = bfin_twi_master_xfer,
30243 .smbus_xfer = bfin_twi_smbus_xfer,
30244 .functionality = bfin_twi_functionality,
30245diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c
30246--- linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c 2011-05-19 00:06:34.000000000 -0400
30247+++ linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c 2011-05-22 19:36:31.000000000 -0400
30248@@ -630,7 +630,7 @@ static inline void i2c_davinci_cpufreq_d
30249 }
30250 #endif
30251
30252-static struct i2c_algorithm i2c_davinci_algo = {
30253+static const struct i2c_algorithm i2c_davinci_algo = {
30254 .master_xfer = i2c_davinci_xfer,
30255 .functionality = i2c_davinci_func,
30256 };
30257diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c
30258--- linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c 2011-05-19 00:06:34.000000000 -0400
30259+++ linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c 2011-05-22 19:36:31.000000000 -0400
30260@@ -689,7 +689,7 @@ tx_aborted:
30261 return IRQ_HANDLED;
30262 }
30263
30264-static struct i2c_algorithm i2c_dw_algo = {
30265+static const struct i2c_algorithm i2c_dw_algo = {
30266 .master_xfer = i2c_dw_xfer,
30267 .functionality = i2c_dw_func,
30268 };
30269diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c
30270--- linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c 2011-05-19 00:06:34.000000000 -0400
30271+++ linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c 2011-05-22 19:36:31.000000000 -0400
30272@@ -708,7 +708,7 @@ static u32 pch_i2c_func(struct i2c_adapt
30273 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
30274 }
30275
30276-static struct i2c_algorithm pch_algorithm = {
30277+static const struct i2c_algorithm pch_algorithm = {
30278 .master_xfer = pch_i2c_xfer,
30279 .functionality = pch_i2c_func
30280 };
30281diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c
30282--- linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c 2011-05-19 00:06:34.000000000 -0400
30283+++ linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c 2011-05-22 19:36:31.000000000 -0400
30284@@ -457,7 +457,7 @@ static u32 i2c_imx_func(struct i2c_adapt
30285 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30286 }
30287
30288-static struct i2c_algorithm i2c_imx_algo = {
30289+static const struct i2c_algorithm i2c_imx_algo = {
30290 .master_xfer = i2c_imx_xfer,
30291 .functionality = i2c_imx_func,
30292 };
30293diff -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
30294--- linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c 2011-05-19 00:06:34.000000000 -0400
30295+++ linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c 2011-05-22 19:36:31.000000000 -0400
30296@@ -917,7 +917,7 @@ err:
30297 return IRQ_HANDLED;
30298 }
30299
30300-static struct i2c_algorithm intel_mid_i2c_algorithm = {
30301+static const struct i2c_algorithm intel_mid_i2c_algorithm = {
30302 .master_xfer = intel_mid_i2c_xfer,
30303 .functionality = intel_mid_i2c_func,
30304 };
30305diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c
30306--- linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c 2011-05-19 00:06:34.000000000 -0400
30307+++ linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c 2011-05-22 19:36:31.000000000 -0400
30308@@ -303,7 +303,7 @@ static u32 nforce2_func(struct i2c_adapt
30309 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
30310 }
30311
30312-static struct i2c_algorithm smbus_algorithm = {
30313+static const struct i2c_algorithm smbus_algorithm = {
30314 .smbus_xfer = nforce2_access,
30315 .functionality = nforce2_func,
30316 };
30317diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c
30318--- linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
30319+++ linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-22 19:36:31.000000000 -0400
30320@@ -615,7 +615,7 @@ static u32 pmcmsptwi_i2c_func(struct i2c
30321
30322 /* -- Initialization -- */
30323
30324-static struct i2c_algorithm pmcmsptwi_algo = {
30325+static const struct i2c_algorithm pmcmsptwi_algo = {
30326 .master_xfer = pmcmsptwi_master_xfer,
30327 .functionality = pmcmsptwi_i2c_func,
30328 };
30329diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c
30330--- linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c 2011-05-19 00:06:34.000000000 -0400
30331+++ linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c 2011-05-22 19:36:31.000000000 -0400
30332@@ -535,7 +535,7 @@ static u32 i2c_pnx_func(struct i2c_adapt
30333 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30334 }
30335
30336-static struct i2c_algorithm pnx_algorithm = {
30337+static const struct i2c_algorithm pnx_algorithm = {
30338 .master_xfer = i2c_pnx_xfer,
30339 .functionality = i2c_pnx_func,
30340 };
30341diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c
30342--- linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c 2011-05-19 00:06:34.000000000 -0400
30343+++ linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c 2011-05-22 19:36:31.000000000 -0400
30344@@ -176,7 +176,7 @@ static u32 puv3_i2c_func(struct i2c_adap
30345 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30346 }
30347
30348-static struct i2c_algorithm puv3_i2c_algorithm = {
30349+static const struct i2c_algorithm puv3_i2c_algorithm = {
30350 .master_xfer = puv3_i2c_xfer,
30351 .functionality = puv3_i2c_func,
30352 };
30353diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c
30354--- linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c 2011-05-19 00:06:34.000000000 -0400
30355+++ linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c 2011-05-22 19:36:31.000000000 -0400
30356@@ -243,7 +243,7 @@ static u32 s6i2c_functionality(struct i2
30357 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30358 }
30359
30360-static struct i2c_algorithm s6i2c_algorithm = {
30361+static const struct i2c_algorithm s6i2c_algorithm = {
30362 .master_xfer = s6i2c_master_xfer,
30363 .functionality = s6i2c_functionality,
30364 };
30365diff -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
30366--- linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-19 00:06:34.000000000 -0400
30367+++ linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-22 19:36:31.000000000 -0400
30368@@ -529,7 +529,7 @@ static u32 sh_mobile_i2c_func(struct i2c
30369 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30370 }
30371
30372-static struct i2c_algorithm sh_mobile_i2c_algorithm = {
30373+static const struct i2c_algorithm sh_mobile_i2c_algorithm = {
30374 .functionality = sh_mobile_i2c_func,
30375 .master_xfer = sh_mobile_i2c_xfer,
30376 };
30377diff -urNp linux-2.6.39.1/drivers/ide/ide-cd.c linux-2.6.39.1/drivers/ide/ide-cd.c
30378--- linux-2.6.39.1/drivers/ide/ide-cd.c 2011-06-03 00:04:14.000000000 -0400
30379+++ linux-2.6.39.1/drivers/ide/ide-cd.c 2011-06-03 00:32:05.000000000 -0400
30380@@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_
30381 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30382 if ((unsigned long)buf & alignment
30383 || blk_rq_bytes(rq) & q->dma_pad_mask
30384- || object_is_on_stack(buf))
30385+ || object_starts_on_stack(buf))
30386 drive->dma = 0;
30387 }
30388 }
30389diff -urNp linux-2.6.39.1/drivers/ide/ide-floppy.c linux-2.6.39.1/drivers/ide/ide-floppy.c
30390--- linux-2.6.39.1/drivers/ide/ide-floppy.c 2011-05-19 00:06:34.000000000 -0400
30391+++ linux-2.6.39.1/drivers/ide/ide-floppy.c 2011-05-22 19:36:31.000000000 -0400
30392@@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_d
30393 u8 pc_buf[256], header_len, desc_cnt;
30394 int i, rc = 1, blocks, length;
30395
30396+ pax_track_stack();
30397+
30398 ide_debug_log(IDE_DBG_FUNC, "enter");
30399
30400 drive->bios_cyl = 0;
30401diff -urNp linux-2.6.39.1/drivers/ide/it821x.c linux-2.6.39.1/drivers/ide/it821x.c
30402--- linux-2.6.39.1/drivers/ide/it821x.c 2011-05-19 00:06:34.000000000 -0400
30403+++ linux-2.6.39.1/drivers/ide/it821x.c 2011-05-22 19:36:31.000000000 -0400
30404@@ -508,7 +508,7 @@ static void it821x_quirkproc(ide_drive_t
30405
30406 }
30407
30408-static struct ide_dma_ops it821x_pass_through_dma_ops = {
30409+static const struct ide_dma_ops it821x_pass_through_dma_ops = {
30410 .dma_host_set = ide_dma_host_set,
30411 .dma_setup = ide_dma_setup,
30412 .dma_start = it821x_dma_start,
30413diff -urNp linux-2.6.39.1/drivers/ide/setup-pci.c linux-2.6.39.1/drivers/ide/setup-pci.c
30414--- linux-2.6.39.1/drivers/ide/setup-pci.c 2011-05-19 00:06:34.000000000 -0400
30415+++ linux-2.6.39.1/drivers/ide/setup-pci.c 2011-05-22 19:36:31.000000000 -0400
30416@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30417 int ret, i, n_ports = dev2 ? 4 : 2;
30418 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30419
30420+ pax_track_stack();
30421+
30422 for (i = 0; i < n_ports / 2; i++) {
30423 ret = ide_setup_pci_controller(pdev[i], d, !i);
30424 if (ret < 0)
30425diff -urNp linux-2.6.39.1/drivers/ide/trm290.c linux-2.6.39.1/drivers/ide/trm290.c
30426--- linux-2.6.39.1/drivers/ide/trm290.c 2011-05-19 00:06:34.000000000 -0400
30427+++ linux-2.6.39.1/drivers/ide/trm290.c 2011-05-22 19:36:31.000000000 -0400
30428@@ -314,7 +314,7 @@ static const struct ide_tp_ops trm290_tp
30429 .output_data = ide_output_data,
30430 };
30431
30432-static struct ide_dma_ops trm290_dma_ops = {
30433+static const struct ide_dma_ops trm290_dma_ops = {
30434 .dma_host_set = trm290_dma_host_set,
30435 .dma_setup = trm290_dma_setup,
30436 .dma_start = trm290_dma_start,
30437diff -urNp linux-2.6.39.1/drivers/infiniband/core/cm.c linux-2.6.39.1/drivers/infiniband/core/cm.c
30438--- linux-2.6.39.1/drivers/infiniband/core/cm.c 2011-05-19 00:06:34.000000000 -0400
30439+++ linux-2.6.39.1/drivers/infiniband/core/cm.c 2011-05-22 19:36:31.000000000 -0400
30440@@ -113,7 +113,7 @@ static char const counter_group_names[CM
30441
30442 struct cm_counter_group {
30443 struct kobject obj;
30444- atomic_long_t counter[CM_ATTR_COUNT];
30445+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30446 };
30447
30448 struct cm_counter_attribute {
30449@@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
30450 struct ib_mad_send_buf *msg = NULL;
30451 int ret;
30452
30453- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30454+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30455 counter[CM_REQ_COUNTER]);
30456
30457 /* Quick state check to discard duplicate REQs. */
30458@@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
30459 if (!cm_id_priv)
30460 return;
30461
30462- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30463+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30464 counter[CM_REP_COUNTER]);
30465 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30466 if (ret)
30467@@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
30468 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30469 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30470 spin_unlock_irq(&cm_id_priv->lock);
30471- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30472+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30473 counter[CM_RTU_COUNTER]);
30474 goto out;
30475 }
30476@@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_wor
30477 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30478 dreq_msg->local_comm_id);
30479 if (!cm_id_priv) {
30480- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30481+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30482 counter[CM_DREQ_COUNTER]);
30483 cm_issue_drep(work->port, work->mad_recv_wc);
30484 return -EINVAL;
30485@@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_wor
30486 case IB_CM_MRA_REP_RCVD:
30487 break;
30488 case IB_CM_TIMEWAIT:
30489- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30490+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30491 counter[CM_DREQ_COUNTER]);
30492 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30493 goto unlock;
30494@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_wor
30495 cm_free_msg(msg);
30496 goto deref;
30497 case IB_CM_DREQ_RCVD:
30498- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30499+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30500 counter[CM_DREQ_COUNTER]);
30501 goto unlock;
30502 default:
30503@@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work
30504 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30505 cm_id_priv->msg, timeout)) {
30506 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30507- atomic_long_inc(&work->port->
30508+ atomic_long_inc_unchecked(&work->port->
30509 counter_group[CM_RECV_DUPLICATES].
30510 counter[CM_MRA_COUNTER]);
30511 goto out;
30512@@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work
30513 break;
30514 case IB_CM_MRA_REQ_RCVD:
30515 case IB_CM_MRA_REP_RCVD:
30516- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30517+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30518 counter[CM_MRA_COUNTER]);
30519 /* fall through */
30520 default:
30521@@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work
30522 case IB_CM_LAP_IDLE:
30523 break;
30524 case IB_CM_MRA_LAP_SENT:
30525- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30526+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30527 counter[CM_LAP_COUNTER]);
30528 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30529 goto unlock;
30530@@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work
30531 cm_free_msg(msg);
30532 goto deref;
30533 case IB_CM_LAP_RCVD:
30534- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30535+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30536 counter[CM_LAP_COUNTER]);
30537 goto unlock;
30538 default:
30539@@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm
30540 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30541 if (cur_cm_id_priv) {
30542 spin_unlock_irq(&cm.lock);
30543- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30544+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30545 counter[CM_SIDR_REQ_COUNTER]);
30546 goto out; /* Duplicate message. */
30547 }
30548@@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_ma
30549 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30550 msg->retries = 1;
30551
30552- atomic_long_add(1 + msg->retries,
30553+ atomic_long_add_unchecked(1 + msg->retries,
30554 &port->counter_group[CM_XMIT].counter[attr_index]);
30555 if (msg->retries)
30556- atomic_long_add(msg->retries,
30557+ atomic_long_add_unchecked(msg->retries,
30558 &port->counter_group[CM_XMIT_RETRIES].
30559 counter[attr_index]);
30560
30561@@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_ma
30562 }
30563
30564 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30565- atomic_long_inc(&port->counter_group[CM_RECV].
30566+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30567 counter[attr_id - CM_ATTR_ID_OFFSET]);
30568
30569 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30570@@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct ko
30571 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30572
30573 return sprintf(buf, "%ld\n",
30574- atomic_long_read(&group->counter[cm_attr->index]));
30575+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30576 }
30577
30578 static const struct sysfs_ops cm_counter_ops = {
30579diff -urNp linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c
30580--- linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c 2011-05-19 00:06:34.000000000 -0400
30581+++ linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c 2011-05-22 19:36:31.000000000 -0400
30582@@ -97,8 +97,8 @@ struct ib_fmr_pool {
30583
30584 struct task_struct *thread;
30585
30586- atomic_t req_ser;
30587- atomic_t flush_ser;
30588+ atomic_unchecked_t req_ser;
30589+ atomic_unchecked_t flush_ser;
30590
30591 wait_queue_head_t force_wait;
30592 };
30593@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30594 struct ib_fmr_pool *pool = pool_ptr;
30595
30596 do {
30597- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30598+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30599 ib_fmr_batch_release(pool);
30600
30601- atomic_inc(&pool->flush_ser);
30602+ atomic_inc_unchecked(&pool->flush_ser);
30603 wake_up_interruptible(&pool->force_wait);
30604
30605 if (pool->flush_function)
30606@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30607 }
30608
30609 set_current_state(TASK_INTERRUPTIBLE);
30610- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30611+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30612 !kthread_should_stop())
30613 schedule();
30614 __set_current_state(TASK_RUNNING);
30615@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30616 pool->dirty_watermark = params->dirty_watermark;
30617 pool->dirty_len = 0;
30618 spin_lock_init(&pool->pool_lock);
30619- atomic_set(&pool->req_ser, 0);
30620- atomic_set(&pool->flush_ser, 0);
30621+ atomic_set_unchecked(&pool->req_ser, 0);
30622+ atomic_set_unchecked(&pool->flush_ser, 0);
30623 init_waitqueue_head(&pool->force_wait);
30624
30625 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30626@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30627 }
30628 spin_unlock_irq(&pool->pool_lock);
30629
30630- serial = atomic_inc_return(&pool->req_ser);
30631+ serial = atomic_inc_return_unchecked(&pool->req_ser);
30632 wake_up_process(pool->thread);
30633
30634 if (wait_event_interruptible(pool->force_wait,
30635- atomic_read(&pool->flush_ser) - serial >= 0))
30636+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30637 return -EINTR;
30638
30639 return 0;
30640@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30641 } else {
30642 list_add_tail(&fmr->list, &pool->dirty_list);
30643 if (++pool->dirty_len >= pool->dirty_watermark) {
30644- atomic_inc(&pool->req_ser);
30645+ atomic_inc_unchecked(&pool->req_ser);
30646 wake_up_process(pool->thread);
30647 }
30648 }
30649diff -urNp linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c
30650--- linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c 2011-05-19 00:06:34.000000000 -0400
30651+++ linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c 2011-05-22 19:36:31.000000000 -0400
30652@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_r
30653 int err;
30654 struct fw_ri_tpte tpt;
30655 u32 stag_idx;
30656- static atomic_t key;
30657+ static atomic_unchecked_t key;
30658
30659 if (c4iw_fatal_error(rdev))
30660 return -EIO;
30661@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_r
30662 &rdev->resource.tpt_fifo_lock);
30663 if (!stag_idx)
30664 return -ENOMEM;
30665- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30666+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30667 }
30668 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30669 __func__, stag_state, type, pdid, stag_idx);
30670diff -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
30671--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-19 00:06:34.000000000 -0400
30672+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-22 19:36:31.000000000 -0400
30673@@ -175,7 +175,7 @@ static void ipath_dma_free_coherent(stru
30674 free_pages((unsigned long) cpu_addr, get_order(size));
30675 }
30676
30677-struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30678+const struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30679 ipath_mapping_error,
30680 ipath_dma_map_single,
30681 ipath_dma_unmap_single,
30682diff -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
30683--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-19 00:06:34.000000000 -0400
30684+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-22 19:36:31.000000000 -0400
30685@@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(stru
30686 struct infinipath_counters counters;
30687 struct ipath_devdata *dd;
30688
30689+ pax_track_stack();
30690+
30691 dd = file->f_path.dentry->d_inode->i_private;
30692 dd->ipath_f_read_counters(dd, &counters);
30693
30694diff -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
30695--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-19 00:06:34.000000000 -0400
30696+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-22 19:36:31.000000000 -0400
30697@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30698 struct ib_atomic_eth *ateth;
30699 struct ipath_ack_entry *e;
30700 u64 vaddr;
30701- atomic64_t *maddr;
30702+ atomic64_unchecked_t *maddr;
30703 u64 sdata;
30704 u32 rkey;
30705 u8 next;
30706@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30707 IB_ACCESS_REMOTE_ATOMIC)))
30708 goto nack_acc_unlck;
30709 /* Perform atomic OP and save result. */
30710- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30711+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30712 sdata = be64_to_cpu(ateth->swap_data);
30713 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30714 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30715- (u64) atomic64_add_return(sdata, maddr) - sdata :
30716+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30717 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30718 be64_to_cpu(ateth->compare_data),
30719 sdata);
30720diff -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
30721--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-19 00:06:34.000000000 -0400
30722+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-22 19:36:31.000000000 -0400
30723@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ip
30724 unsigned long flags;
30725 struct ib_wc wc;
30726 u64 sdata;
30727- atomic64_t *maddr;
30728+ atomic64_unchecked_t *maddr;
30729 enum ib_wc_status send_status;
30730
30731 /*
30732@@ -382,11 +382,11 @@ again:
30733 IB_ACCESS_REMOTE_ATOMIC)))
30734 goto acc_err;
30735 /* Perform atomic OP and save result. */
30736- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30737+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30738 sdata = wqe->wr.wr.atomic.compare_add;
30739 *(u64 *) sqp->s_sge.sge.vaddr =
30740 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30741- (u64) atomic64_add_return(sdata, maddr) - sdata :
30742+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30743 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30744 sdata, wqe->wr.wr.atomic.swap);
30745 goto send_comp;
30746diff -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
30747--- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-19 00:06:34.000000000 -0400
30748+++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-22 19:36:31.000000000 -0400
30749@@ -931,6 +931,6 @@ extern unsigned int ib_ipath_max_srq_wrs
30750
30751 extern const u32 ib_ipath_rnr_table[];
30752
30753-extern struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30754+extern const struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30755
30756 #endif /* IPATH_VERBS_H */
30757diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c
30758--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c 2011-05-19 00:06:34.000000000 -0400
30759+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c 2011-05-22 19:36:31.000000000 -0400
30760@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
30761 LIST_HEAD(nes_adapter_list);
30762 static LIST_HEAD(nes_dev_list);
30763
30764-atomic_t qps_destroyed;
30765+atomic_unchecked_t qps_destroyed;
30766
30767 static unsigned int ee_flsh_adapter;
30768 static unsigned int sysfs_nonidx_addr;
30769@@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(str
30770 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30771 struct nes_adapter *nesadapter = nesdev->nesadapter;
30772
30773- atomic_inc(&qps_destroyed);
30774+ atomic_inc_unchecked(&qps_destroyed);
30775
30776 /* Free the control structures */
30777
30778diff -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
30779--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c 2011-05-19 00:06:34.000000000 -0400
30780+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c 2011-05-22 19:36:31.000000000 -0400
30781@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30782 u32 cm_packets_retrans;
30783 u32 cm_packets_created;
30784 u32 cm_packets_received;
30785-atomic_t cm_listens_created;
30786-atomic_t cm_listens_destroyed;
30787+atomic_unchecked_t cm_listens_created;
30788+atomic_unchecked_t cm_listens_destroyed;
30789 u32 cm_backlog_drops;
30790-atomic_t cm_loopbacks;
30791-atomic_t cm_nodes_created;
30792-atomic_t cm_nodes_destroyed;
30793-atomic_t cm_accel_dropped_pkts;
30794-atomic_t cm_resets_recvd;
30795+atomic_unchecked_t cm_loopbacks;
30796+atomic_unchecked_t cm_nodes_created;
30797+atomic_unchecked_t cm_nodes_destroyed;
30798+atomic_unchecked_t cm_accel_dropped_pkts;
30799+atomic_unchecked_t cm_resets_recvd;
30800
30801 static inline int mini_cm_accelerated(struct nes_cm_core *,
30802 struct nes_cm_node *);
30803@@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30804
30805 static struct nes_cm_core *g_cm_core;
30806
30807-atomic_t cm_connects;
30808-atomic_t cm_accepts;
30809-atomic_t cm_disconnects;
30810-atomic_t cm_closes;
30811-atomic_t cm_connecteds;
30812-atomic_t cm_connect_reqs;
30813-atomic_t cm_rejects;
30814+atomic_unchecked_t cm_connects;
30815+atomic_unchecked_t cm_accepts;
30816+atomic_unchecked_t cm_disconnects;
30817+atomic_unchecked_t cm_closes;
30818+atomic_unchecked_t cm_connecteds;
30819+atomic_unchecked_t cm_connect_reqs;
30820+atomic_unchecked_t cm_rejects;
30821
30822
30823 /**
30824@@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(str
30825 kfree(listener);
30826 listener = NULL;
30827 ret = 0;
30828- atomic_inc(&cm_listens_destroyed);
30829+ atomic_inc_unchecked(&cm_listens_destroyed);
30830 } else {
30831 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30832 }
30833@@ -1240,7 +1240,7 @@ static struct nes_cm_node *make_cm_node(
30834 cm_node->rem_mac);
30835
30836 add_hte_node(cm_core, cm_node);
30837- atomic_inc(&cm_nodes_created);
30838+ atomic_inc_unchecked(&cm_nodes_created);
30839
30840 return cm_node;
30841 }
30842@@ -1298,7 +1298,7 @@ static int rem_ref_cm_node(struct nes_cm
30843 }
30844
30845 atomic_dec(&cm_core->node_cnt);
30846- atomic_inc(&cm_nodes_destroyed);
30847+ atomic_inc_unchecked(&cm_nodes_destroyed);
30848 nesqp = cm_node->nesqp;
30849 if (nesqp) {
30850 nesqp->cm_node = NULL;
30851@@ -1365,7 +1365,7 @@ static int process_options(struct nes_cm
30852
30853 static void drop_packet(struct sk_buff *skb)
30854 {
30855- atomic_inc(&cm_accel_dropped_pkts);
30856+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
30857 dev_kfree_skb_any(skb);
30858 }
30859
30860@@ -1428,7 +1428,7 @@ static void handle_rst_pkt(struct nes_cm
30861 {
30862
30863 int reset = 0; /* whether to send reset in case of err.. */
30864- atomic_inc(&cm_resets_recvd);
30865+ atomic_inc_unchecked(&cm_resets_recvd);
30866 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30867 " refcnt=%d\n", cm_node, cm_node->state,
30868 atomic_read(&cm_node->ref_count));
30869@@ -2057,7 +2057,7 @@ static struct nes_cm_node *mini_cm_conne
30870 rem_ref_cm_node(cm_node->cm_core, cm_node);
30871 return NULL;
30872 }
30873- atomic_inc(&cm_loopbacks);
30874+ atomic_inc_unchecked(&cm_loopbacks);
30875 loopbackremotenode->loopbackpartner = cm_node;
30876 loopbackremotenode->tcp_cntxt.rcv_wscale =
30877 NES_CM_DEFAULT_RCV_WND_SCALE;
30878@@ -2332,7 +2332,7 @@ static int mini_cm_recv_pkt(struct nes_c
30879 add_ref_cm_node(cm_node);
30880 } else if (cm_node->state == NES_CM_STATE_TSA) {
30881 rem_ref_cm_node(cm_core, cm_node);
30882- atomic_inc(&cm_accel_dropped_pkts);
30883+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
30884 dev_kfree_skb_any(skb);
30885 break;
30886 }
30887@@ -2638,7 +2638,7 @@ static int nes_cm_disconn_true(struct ne
30888
30889 if ((cm_id) && (cm_id->event_handler)) {
30890 if (issue_disconn) {
30891- atomic_inc(&cm_disconnects);
30892+ atomic_inc_unchecked(&cm_disconnects);
30893 cm_event.event = IW_CM_EVENT_DISCONNECT;
30894 cm_event.status = disconn_status;
30895 cm_event.local_addr = cm_id->local_addr;
30896@@ -2660,7 +2660,7 @@ static int nes_cm_disconn_true(struct ne
30897 }
30898
30899 if (issue_close) {
30900- atomic_inc(&cm_closes);
30901+ atomic_inc_unchecked(&cm_closes);
30902 nes_disconnect(nesqp, 1);
30903
30904 cm_id->provider_data = nesqp;
30905@@ -2791,7 +2791,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
30906
30907 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30908 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30909- atomic_inc(&cm_accepts);
30910+ atomic_inc_unchecked(&cm_accepts);
30911
30912 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30913 netdev_refcnt_read(nesvnic->netdev));
30914@@ -3001,7 +3001,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
30915
30916 struct nes_cm_core *cm_core;
30917
30918- atomic_inc(&cm_rejects);
30919+ atomic_inc_unchecked(&cm_rejects);
30920 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30921 loopback = cm_node->loopbackpartner;
30922 cm_core = cm_node->cm_core;
30923@@ -3067,7 +3067,7 @@ int nes_connect(struct iw_cm_id *cm_id,
30924 ntohl(cm_id->local_addr.sin_addr.s_addr),
30925 ntohs(cm_id->local_addr.sin_port));
30926
30927- atomic_inc(&cm_connects);
30928+ atomic_inc_unchecked(&cm_connects);
30929 nesqp->active_conn = 1;
30930
30931 /* cache the cm_id in the qp */
30932@@ -3173,7 +3173,7 @@ int nes_create_listen(struct iw_cm_id *c
30933 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30934 return err;
30935 }
30936- atomic_inc(&cm_listens_created);
30937+ atomic_inc_unchecked(&cm_listens_created);
30938 }
30939
30940 cm_id->add_ref(cm_id);
30941@@ -3278,7 +3278,7 @@ static void cm_event_connected(struct ne
30942 if (nesqp->destroyed) {
30943 return;
30944 }
30945- atomic_inc(&cm_connecteds);
30946+ atomic_inc_unchecked(&cm_connecteds);
30947 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30948 " local port 0x%04X. jiffies = %lu.\n",
30949 nesqp->hwqp.qp_id,
30950@@ -3493,7 +3493,7 @@ static void cm_event_reset(struct nes_cm
30951
30952 cm_id->add_ref(cm_id);
30953 ret = cm_id->event_handler(cm_id, &cm_event);
30954- atomic_inc(&cm_closes);
30955+ atomic_inc_unchecked(&cm_closes);
30956 cm_event.event = IW_CM_EVENT_CLOSE;
30957 cm_event.status = IW_CM_EVENT_STATUS_OK;
30958 cm_event.provider_data = cm_id->provider_data;
30959@@ -3529,7 +3529,7 @@ static void cm_event_mpa_req(struct nes_
30960 return;
30961 cm_id = cm_node->cm_id;
30962
30963- atomic_inc(&cm_connect_reqs);
30964+ atomic_inc_unchecked(&cm_connect_reqs);
30965 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30966 cm_node, cm_id, jiffies);
30967
30968@@ -3567,7 +3567,7 @@ static void cm_event_mpa_reject(struct n
30969 return;
30970 cm_id = cm_node->cm_id;
30971
30972- atomic_inc(&cm_connect_reqs);
30973+ atomic_inc_unchecked(&cm_connect_reqs);
30974 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30975 cm_node, cm_id, jiffies);
30976
30977diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h
30978--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h 2011-05-19 00:06:34.000000000 -0400
30979+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h 2011-05-22 19:36:31.000000000 -0400
30980@@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30981 extern unsigned int wqm_quanta;
30982 extern struct list_head nes_adapter_list;
30983
30984-extern atomic_t cm_connects;
30985-extern atomic_t cm_accepts;
30986-extern atomic_t cm_disconnects;
30987-extern atomic_t cm_closes;
30988-extern atomic_t cm_connecteds;
30989-extern atomic_t cm_connect_reqs;
30990-extern atomic_t cm_rejects;
30991-extern atomic_t mod_qp_timouts;
30992-extern atomic_t qps_created;
30993-extern atomic_t qps_destroyed;
30994-extern atomic_t sw_qps_destroyed;
30995+extern atomic_unchecked_t cm_connects;
30996+extern atomic_unchecked_t cm_accepts;
30997+extern atomic_unchecked_t cm_disconnects;
30998+extern atomic_unchecked_t cm_closes;
30999+extern atomic_unchecked_t cm_connecteds;
31000+extern atomic_unchecked_t cm_connect_reqs;
31001+extern atomic_unchecked_t cm_rejects;
31002+extern atomic_unchecked_t mod_qp_timouts;
31003+extern atomic_unchecked_t qps_created;
31004+extern atomic_unchecked_t qps_destroyed;
31005+extern atomic_unchecked_t sw_qps_destroyed;
31006 extern u32 mh_detected;
31007 extern u32 mh_pauses_sent;
31008 extern u32 cm_packets_sent;
31009@@ -194,14 +194,14 @@ extern u32 cm_packets_created;
31010 extern u32 cm_packets_received;
31011 extern u32 cm_packets_dropped;
31012 extern u32 cm_packets_retrans;
31013-extern atomic_t cm_listens_created;
31014-extern atomic_t cm_listens_destroyed;
31015+extern atomic_unchecked_t cm_listens_created;
31016+extern atomic_unchecked_t cm_listens_destroyed;
31017 extern u32 cm_backlog_drops;
31018-extern atomic_t cm_loopbacks;
31019-extern atomic_t cm_nodes_created;
31020-extern atomic_t cm_nodes_destroyed;
31021-extern atomic_t cm_accel_dropped_pkts;
31022-extern atomic_t cm_resets_recvd;
31023+extern atomic_unchecked_t cm_loopbacks;
31024+extern atomic_unchecked_t cm_nodes_created;
31025+extern atomic_unchecked_t cm_nodes_destroyed;
31026+extern atomic_unchecked_t cm_accel_dropped_pkts;
31027+extern atomic_unchecked_t cm_resets_recvd;
31028
31029 extern u32 int_mod_timer_init;
31030 extern u32 int_mod_cq_depth_256;
31031diff -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
31032--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c 2011-05-19 00:06:34.000000000 -0400
31033+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c 2011-05-22 19:36:31.000000000 -0400
31034@@ -1302,31 +1302,31 @@ static void nes_netdev_get_ethtool_stats
31035 target_stat_values[++index] = mh_detected;
31036 target_stat_values[++index] = mh_pauses_sent;
31037 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31038- target_stat_values[++index] = atomic_read(&cm_connects);
31039- target_stat_values[++index] = atomic_read(&cm_accepts);
31040- target_stat_values[++index] = atomic_read(&cm_disconnects);
31041- target_stat_values[++index] = atomic_read(&cm_connecteds);
31042- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31043- target_stat_values[++index] = atomic_read(&cm_rejects);
31044- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31045- target_stat_values[++index] = atomic_read(&qps_created);
31046- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31047- target_stat_values[++index] = atomic_read(&qps_destroyed);
31048- target_stat_values[++index] = atomic_read(&cm_closes);
31049+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31050+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31051+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31052+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31053+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31054+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31055+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31056+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31057+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31058+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31059+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31060 target_stat_values[++index] = cm_packets_sent;
31061 target_stat_values[++index] = cm_packets_bounced;
31062 target_stat_values[++index] = cm_packets_created;
31063 target_stat_values[++index] = cm_packets_received;
31064 target_stat_values[++index] = cm_packets_dropped;
31065 target_stat_values[++index] = cm_packets_retrans;
31066- target_stat_values[++index] = atomic_read(&cm_listens_created);
31067- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
31068+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
31069+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
31070 target_stat_values[++index] = cm_backlog_drops;
31071- target_stat_values[++index] = atomic_read(&cm_loopbacks);
31072- target_stat_values[++index] = atomic_read(&cm_nodes_created);
31073- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31074- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31075- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31076+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31077+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31078+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31079+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31080+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31081 target_stat_values[++index] = nesadapter->free_4kpbl;
31082 target_stat_values[++index] = nesadapter->free_256pbl;
31083 target_stat_values[++index] = int_mod_timer_init;
31084diff -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
31085--- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-19 00:06:34.000000000 -0400
31086+++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-22 19:36:31.000000000 -0400
31087@@ -46,9 +46,9 @@
31088
31089 #include <rdma/ib_umem.h>
31090
31091-atomic_t mod_qp_timouts;
31092-atomic_t qps_created;
31093-atomic_t sw_qps_destroyed;
31094+atomic_unchecked_t mod_qp_timouts;
31095+atomic_unchecked_t qps_created;
31096+atomic_unchecked_t sw_qps_destroyed;
31097
31098 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31099
31100@@ -1141,7 +1141,7 @@ static struct ib_qp *nes_create_qp(struc
31101 if (init_attr->create_flags)
31102 return ERR_PTR(-EINVAL);
31103
31104- atomic_inc(&qps_created);
31105+ atomic_inc_unchecked(&qps_created);
31106 switch (init_attr->qp_type) {
31107 case IB_QPT_RC:
31108 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31109@@ -1470,7 +1470,7 @@ static int nes_destroy_qp(struct ib_qp *
31110 struct iw_cm_event cm_event;
31111 int ret;
31112
31113- atomic_inc(&sw_qps_destroyed);
31114+ atomic_inc_unchecked(&sw_qps_destroyed);
31115 nesqp->destroyed = 1;
31116
31117 /* Blow away the connection if it exists. */
31118diff -urNp linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h
31119--- linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h 2011-05-19 00:06:34.000000000 -0400
31120+++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h 2011-05-22 19:36:31.000000000 -0400
31121@@ -51,6 +51,7 @@
31122 #include <linux/completion.h>
31123 #include <linux/kref.h>
31124 #include <linux/sched.h>
31125+#include <linux/slab.h>
31126
31127 #include "qib_common.h"
31128 #include "qib_verbs.h"
31129@@ -87,7 +88,7 @@ struct qlogic_ib_stats {
31130 };
31131
31132 extern struct qlogic_ib_stats qib_stats;
31133-extern struct pci_error_handlers qib_pci_err_handler;
31134+extern const struct pci_error_handlers qib_pci_err_handler;
31135 extern struct pci_driver qib_driver;
31136
31137 #define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
31138diff -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
31139--- linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-19 00:06:34.000000000 -0400
31140+++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-22 19:36:31.000000000 -0400
31141@@ -75,7 +75,7 @@ static void qib_vma_close(struct vm_area
31142 kref_put(&ip->ref, qib_release_mmap_info);
31143 }
31144
31145-static struct vm_operations_struct qib_vm_ops = {
31146+static const struct vm_operations_struct qib_vm_ops = {
31147 .open = qib_vma_open,
31148 .close = qib_vma_close,
31149 };
31150diff -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
31151--- linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-19 00:06:34.000000000 -0400
31152+++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-22 19:36:31.000000000 -0400
31153@@ -735,7 +735,7 @@ qib_pci_resume(struct pci_dev *pdev)
31154 qib_init(dd, 1); /* same as re-init after reset */
31155 }
31156
31157-struct pci_error_handlers qib_pci_err_handler = {
31158+const struct pci_error_handlers qib_pci_err_handler = {
31159 .error_detected = qib_pci_error_detected,
31160 .mmio_enabled = qib_pci_mmio_enabled,
31161 .link_reset = qib_pci_link_reset,
31162diff -urNp linux-2.6.39.1/drivers/input/gameport/gameport.c linux-2.6.39.1/drivers/input/gameport/gameport.c
31163--- linux-2.6.39.1/drivers/input/gameport/gameport.c 2011-05-19 00:06:34.000000000 -0400
31164+++ linux-2.6.39.1/drivers/input/gameport/gameport.c 2011-05-22 19:36:31.000000000 -0400
31165@@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31166 */
31167 static void gameport_init_port(struct gameport *gameport)
31168 {
31169- static atomic_t gameport_no = ATOMIC_INIT(0);
31170+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31171
31172 __module_get(THIS_MODULE);
31173
31174 mutex_init(&gameport->drv_mutex);
31175 device_initialize(&gameport->dev);
31176 dev_set_name(&gameport->dev, "gameport%lu",
31177- (unsigned long)atomic_inc_return(&gameport_no) - 1);
31178+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31179 gameport->dev.bus = &gameport_bus;
31180 gameport->dev.release = gameport_release_port;
31181 if (gameport->parent)
31182diff -urNp linux-2.6.39.1/drivers/input/input.c linux-2.6.39.1/drivers/input/input.c
31183--- linux-2.6.39.1/drivers/input/input.c 2011-05-19 00:06:34.000000000 -0400
31184+++ linux-2.6.39.1/drivers/input/input.c 2011-05-22 19:36:31.000000000 -0400
31185@@ -1815,7 +1815,7 @@ static void input_cleanse_bitmasks(struc
31186 */
31187 int input_register_device(struct input_dev *dev)
31188 {
31189- static atomic_t input_no = ATOMIC_INIT(0);
31190+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31191 struct input_handler *handler;
31192 const char *path;
31193 int error;
31194@@ -1852,7 +1852,7 @@ int input_register_device(struct input_d
31195 dev->setkeycode = input_default_setkeycode;
31196
31197 dev_set_name(&dev->dev, "input%ld",
31198- (unsigned long) atomic_inc_return(&input_no) - 1);
31199+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31200
31201 error = device_add(&dev->dev);
31202 if (error)
31203diff -urNp linux-2.6.39.1/drivers/input/joystick/sidewinder.c linux-2.6.39.1/drivers/input/joystick/sidewinder.c
31204--- linux-2.6.39.1/drivers/input/joystick/sidewinder.c 2011-05-19 00:06:34.000000000 -0400
31205+++ linux-2.6.39.1/drivers/input/joystick/sidewinder.c 2011-05-22 19:36:31.000000000 -0400
31206@@ -30,6 +30,7 @@
31207 #include <linux/kernel.h>
31208 #include <linux/module.h>
31209 #include <linux/slab.h>
31210+#include <linux/sched.h>
31211 #include <linux/init.h>
31212 #include <linux/input.h>
31213 #include <linux/gameport.h>
31214@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31215 unsigned char buf[SW_LENGTH];
31216 int i;
31217
31218+ pax_track_stack();
31219+
31220 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31221
31222 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31223diff -urNp linux-2.6.39.1/drivers/input/joystick/xpad.c linux-2.6.39.1/drivers/input/joystick/xpad.c
31224--- linux-2.6.39.1/drivers/input/joystick/xpad.c 2011-05-19 00:06:34.000000000 -0400
31225+++ linux-2.6.39.1/drivers/input/joystick/xpad.c 2011-05-22 19:36:31.000000000 -0400
31226@@ -689,7 +689,7 @@ static void xpad_led_set(struct led_clas
31227
31228 static int xpad_led_probe(struct usb_xpad *xpad)
31229 {
31230- static atomic_t led_seq = ATOMIC_INIT(0);
31231+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31232 long led_no;
31233 struct xpad_led *led;
31234 struct led_classdev *led_cdev;
31235@@ -702,7 +702,7 @@ static int xpad_led_probe(struct usb_xpa
31236 if (!led)
31237 return -ENOMEM;
31238
31239- led_no = (long)atomic_inc_return(&led_seq) - 1;
31240+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31241
31242 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31243 led->xpad = xpad;
31244diff -urNp linux-2.6.39.1/drivers/input/mousedev.c linux-2.6.39.1/drivers/input/mousedev.c
31245--- linux-2.6.39.1/drivers/input/mousedev.c 2011-05-19 00:06:34.000000000 -0400
31246+++ linux-2.6.39.1/drivers/input/mousedev.c 2011-05-22 19:36:31.000000000 -0400
31247@@ -764,7 +764,7 @@ static ssize_t mousedev_read(struct file
31248
31249 spin_unlock_irq(&client->packet_lock);
31250
31251- if (copy_to_user(buffer, data, count))
31252+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
31253 return -EFAULT;
31254
31255 return count;
31256diff -urNp linux-2.6.39.1/drivers/input/serio/serio.c linux-2.6.39.1/drivers/input/serio/serio.c
31257--- linux-2.6.39.1/drivers/input/serio/serio.c 2011-05-19 00:06:34.000000000 -0400
31258+++ linux-2.6.39.1/drivers/input/serio/serio.c 2011-05-22 19:36:31.000000000 -0400
31259@@ -497,7 +497,7 @@ static void serio_release_port(struct de
31260 */
31261 static void serio_init_port(struct serio *serio)
31262 {
31263- static atomic_t serio_no = ATOMIC_INIT(0);
31264+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31265
31266 __module_get(THIS_MODULE);
31267
31268@@ -508,7 +508,7 @@ static void serio_init_port(struct serio
31269 mutex_init(&serio->drv_mutex);
31270 device_initialize(&serio->dev);
31271 dev_set_name(&serio->dev, "serio%ld",
31272- (long)atomic_inc_return(&serio_no) - 1);
31273+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
31274 serio->dev.bus = &serio_bus;
31275 serio->dev.release = serio_release_port;
31276 serio->dev.groups = serio_device_attr_groups;
31277diff -urNp linux-2.6.39.1/drivers/isdn/capi/capi.c linux-2.6.39.1/drivers/isdn/capi/capi.c
31278--- linux-2.6.39.1/drivers/isdn/capi/capi.c 2011-05-19 00:06:34.000000000 -0400
31279+++ linux-2.6.39.1/drivers/isdn/capi/capi.c 2011-05-22 19:36:31.000000000 -0400
31280@@ -89,8 +89,8 @@ struct capiminor {
31281
31282 struct capi20_appl *ap;
31283 u32 ncci;
31284- atomic_t datahandle;
31285- atomic_t msgid;
31286+ atomic_unchecked_t datahandle;
31287+ atomic_unchecked_t msgid;
31288
31289 struct tty_port port;
31290 int ttyinstop;
31291@@ -414,7 +414,7 @@ gen_data_b3_resp_for(struct capiminor *m
31292 capimsg_setu16(s, 2, mp->ap->applid);
31293 capimsg_setu8 (s, 4, CAPI_DATA_B3);
31294 capimsg_setu8 (s, 5, CAPI_RESP);
31295- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
31296+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
31297 capimsg_setu32(s, 8, mp->ncci);
31298 capimsg_setu16(s, 12, datahandle);
31299 }
31300@@ -547,14 +547,14 @@ static void handle_minor_send(struct cap
31301 mp->outbytes -= len;
31302 spin_unlock_bh(&mp->outlock);
31303
31304- datahandle = atomic_inc_return(&mp->datahandle);
31305+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
31306 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
31307 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31308 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31309 capimsg_setu16(skb->data, 2, mp->ap->applid);
31310 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
31311 capimsg_setu8 (skb->data, 5, CAPI_REQ);
31312- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
31313+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
31314 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
31315 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
31316 capimsg_setu16(skb->data, 16, len); /* Data length */
31317diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/common.c linux-2.6.39.1/drivers/isdn/gigaset/common.c
31318--- linux-2.6.39.1/drivers/isdn/gigaset/common.c 2011-05-19 00:06:34.000000000 -0400
31319+++ linux-2.6.39.1/drivers/isdn/gigaset/common.c 2011-05-22 19:36:31.000000000 -0400
31320@@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
31321 cs->commands_pending = 0;
31322 cs->cur_at_seq = 0;
31323 cs->gotfwver = -1;
31324- cs->open_count = 0;
31325+ local_set(&cs->open_count, 0);
31326 cs->dev = NULL;
31327 cs->tty = NULL;
31328 cs->tty_dev = NULL;
31329diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h
31330--- linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h 2011-05-19 00:06:34.000000000 -0400
31331+++ linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h 2011-05-22 19:36:31.000000000 -0400
31332@@ -35,6 +35,7 @@
31333 #include <linux/tty_driver.h>
31334 #include <linux/list.h>
31335 #include <asm/atomic.h>
31336+#include <asm/local.h>
31337
31338 #define GIG_VERSION {0, 5, 0, 0}
31339 #define GIG_COMPAT {0, 4, 0, 0}
31340@@ -433,7 +434,7 @@ struct cardstate {
31341 spinlock_t cmdlock;
31342 unsigned curlen, cmdbytes;
31343
31344- unsigned open_count;
31345+ local_t open_count;
31346 struct tty_struct *tty;
31347 struct tasklet_struct if_wake_tasklet;
31348 unsigned control_state;
31349diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/interface.c linux-2.6.39.1/drivers/isdn/gigaset/interface.c
31350--- linux-2.6.39.1/drivers/isdn/gigaset/interface.c 2011-05-19 00:06:34.000000000 -0400
31351+++ linux-2.6.39.1/drivers/isdn/gigaset/interface.c 2011-05-22 19:36:31.000000000 -0400
31352@@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
31353 return -ERESTARTSYS;
31354 tty->driver_data = cs;
31355
31356- ++cs->open_count;
31357-
31358- if (cs->open_count == 1) {
31359+ if (local_inc_return(&cs->open_count) == 1) {
31360 spin_lock_irqsave(&cs->lock, flags);
31361 cs->tty = tty;
31362 spin_unlock_irqrestore(&cs->lock, flags);
31363@@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
31364
31365 if (!cs->connected)
31366 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31367- else if (!cs->open_count)
31368+ else if (!local_read(&cs->open_count))
31369 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31370 else {
31371- if (!--cs->open_count) {
31372+ if (!local_dec_return(&cs->open_count)) {
31373 spin_lock_irqsave(&cs->lock, flags);
31374 cs->tty = NULL;
31375 spin_unlock_irqrestore(&cs->lock, flags);
31376@@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
31377 if (!cs->connected) {
31378 gig_dbg(DEBUG_IF, "not connected");
31379 retval = -ENODEV;
31380- } else if (!cs->open_count)
31381+ } else if (!local_read(&cs->open_count))
31382 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31383 else {
31384 retval = 0;
31385@@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
31386 retval = -ENODEV;
31387 goto done;
31388 }
31389- if (!cs->open_count) {
31390+ if (!local_read(&cs->open_count)) {
31391 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31392 retval = -ENODEV;
31393 goto done;
31394@@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
31395 if (!cs->connected) {
31396 gig_dbg(DEBUG_IF, "not connected");
31397 retval = -ENODEV;
31398- } else if (!cs->open_count)
31399+ } else if (!local_read(&cs->open_count))
31400 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31401 else if (cs->mstate != MS_LOCKED) {
31402 dev_warn(cs->dev, "can't write to unlocked device\n");
31403@@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
31404
31405 if (!cs->connected)
31406 gig_dbg(DEBUG_IF, "not connected");
31407- else if (!cs->open_count)
31408+ else if (!local_read(&cs->open_count))
31409 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31410 else if (cs->mstate != MS_LOCKED)
31411 dev_warn(cs->dev, "can't write to unlocked device\n");
31412@@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
31413
31414 if (!cs->connected)
31415 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31416- else if (!cs->open_count)
31417+ else if (!local_read(&cs->open_count))
31418 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31419 else
31420 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31421@@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
31422
31423 if (!cs->connected)
31424 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31425- else if (!cs->open_count)
31426+ else if (!local_read(&cs->open_count))
31427 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31428 else
31429 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31430@@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
31431 goto out;
31432 }
31433
31434- if (!cs->open_count) {
31435+ if (!local_read(&cs->open_count)) {
31436 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31437 goto out;
31438 }
31439diff -urNp linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c
31440--- linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c 2011-05-19 00:06:34.000000000 -0400
31441+++ linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c 2011-05-22 19:36:31.000000000 -0400
31442@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
31443 }
31444 if (left) {
31445 if (t4file->user) {
31446- if (copy_from_user(buf, dp, left))
31447+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31448 return -EFAULT;
31449 } else {
31450 memcpy(buf, dp, left);
31451@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
31452 }
31453 if (left) {
31454 if (config->user) {
31455- if (copy_from_user(buf, dp, left))
31456+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31457 return -EFAULT;
31458 } else {
31459 memcpy(buf, dp, left);
31460diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c
31461--- linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-19 00:06:34.000000000 -0400
31462+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-22 19:36:31.000000000 -0400
31463@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31464 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31465 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31466
31467+ pax_track_stack();
31468
31469 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31470 {
31471diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c
31472--- linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c 2011-05-19 00:06:34.000000000 -0400
31473+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c 2011-05-22 19:36:31.000000000 -0400
31474@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31475 IDI_SYNC_REQ req;
31476 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31477
31478+ pax_track_stack();
31479+
31480 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31481
31482 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31483diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c
31484--- linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-19 00:06:34.000000000 -0400
31485+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-22 19:36:31.000000000 -0400
31486@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31487 IDI_SYNC_REQ req;
31488 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31489
31490+ pax_track_stack();
31491+
31492 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31493
31494 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31495diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c
31496--- linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-19 00:06:34.000000000 -0400
31497+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-22 19:36:31.000000000 -0400
31498@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31499 IDI_SYNC_REQ req;
31500 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31501
31502+ pax_track_stack();
31503+
31504 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31505
31506 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31507diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c
31508--- linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c 2011-05-19 00:06:34.000000000 -0400
31509+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c 2011-05-22 19:36:31.000000000 -0400
31510@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31511 IDI_SYNC_REQ req;
31512 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31513
31514+ pax_track_stack();
31515+
31516 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31517
31518 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31519diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c
31520--- linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c 2011-05-19 00:06:34.000000000 -0400
31521+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c 2011-05-22 19:36:31.000000000 -0400
31522@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31523 dword d;
31524 word w;
31525
31526+ pax_track_stack();
31527+
31528 a = plci->adapter;
31529 Id = ((word)plci->Id<<8)|a->Id;
31530 PUT_WORD(&SS_Ind[4],0x0000);
31531@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31532 word j, n, w;
31533 dword d;
31534
31535+ pax_track_stack();
31536+
31537
31538 for(i=0;i<8;i++) bp_parms[i].length = 0;
31539 for(i=0;i<2;i++) global_config[i].length = 0;
31540@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31541 const byte llc3[] = {4,3,2,2,6,6,0};
31542 const byte header[] = {0,2,3,3,0,0,0};
31543
31544+ pax_track_stack();
31545+
31546 for(i=0;i<8;i++) bp_parms[i].length = 0;
31547 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31548 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31549@@ -14760,6 +14766,8 @@ static void group_optimization(DIVA_CAPI
31550 word appl_number_group_type[MAX_APPL];
31551 PLCI *auxplci;
31552
31553+ pax_track_stack();
31554+
31555 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31556
31557 if(!a->group_optimization_enabled)
31558diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c
31559--- linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-19 00:06:34.000000000 -0400
31560+++ linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-22 19:36:31.000000000 -0400
31561@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31562 IDI_SYNC_REQ req;
31563 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31564
31565+ pax_track_stack();
31566+
31567 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31568
31569 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31570diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c
31571--- linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c 2011-05-19 00:06:34.000000000 -0400
31572+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c 2011-05-22 19:36:31.000000000 -0400
31573@@ -1292,6 +1292,8 @@ isdn_ioctl(struct file *file, uint cmd,
31574 } iocpar;
31575 void __user *argp = (void __user *)arg;
31576
31577+ pax_track_stack();
31578+
31579 #define name iocpar.name
31580 #define bname iocpar.bname
31581 #define iocts iocpar.iocts
31582diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c
31583--- linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c 2011-05-19 00:06:34.000000000 -0400
31584+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c 2011-05-22 19:36:31.000000000 -0400
31585@@ -400,7 +400,7 @@ isdn_net_stat_callback(int idx, isdn_ctr
31586 isdn_net_local *lp = p->local;
31587 #ifdef CONFIG_ISDN_X25
31588 struct concap_proto *cprot = lp->netdev->cprot;
31589- struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31590+ const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31591 #endif
31592 switch (cmd) {
31593 case ISDN_STAT_BSENT:
31594@@ -831,7 +831,7 @@ isdn_net_hangup(struct net_device *d)
31595 isdn_ctrl cmd;
31596 #ifdef CONFIG_ISDN_X25
31597 struct concap_proto *cprot = lp->netdev->cprot;
31598- struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31599+ const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31600 #endif
31601
31602 if (lp->flags & ISDN_NET_CONNECTED) {
31603diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c
31604--- linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c 2011-05-19 00:06:34.000000000 -0400
31605+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c 2011-05-22 19:36:31.000000000 -0400
31606@@ -52,7 +52,7 @@ static int isdn_x25iface_connect_ind( st
31607 static int isdn_x25iface_disconn_ind( struct concap_proto * );
31608
31609
31610-static struct concap_proto_ops ix25_pops = {
31611+static const struct concap_proto_ops ix25_pops = {
31612 &isdn_x25iface_proto_new,
31613 &isdn_x25iface_proto_del,
31614 &isdn_x25iface_proto_restart,
31615diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h
31616--- linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h 2011-05-19 00:06:34.000000000 -0400
31617+++ linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h 2011-05-22 19:36:31.000000000 -0400
31618@@ -23,7 +23,7 @@
31619 #include <linux/isdn.h>
31620 #include <linux/concap.h>
31621
31622-extern struct concap_proto_ops * isdn_x25iface_concap_proto_ops_pt;
31623+extern const struct concap_proto_ops *isdn_x25iface_concap_proto_ops_pt;
31624 extern struct concap_proto * isdn_x25iface_proto_new(void);
31625
31626
31627diff -urNp linux-2.6.39.1/drivers/isdn/icn/icn.c linux-2.6.39.1/drivers/isdn/icn/icn.c
31628--- linux-2.6.39.1/drivers/isdn/icn/icn.c 2011-05-19 00:06:34.000000000 -0400
31629+++ linux-2.6.39.1/drivers/isdn/icn/icn.c 2011-05-22 19:36:31.000000000 -0400
31630@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
31631 if (count > len)
31632 count = len;
31633 if (user) {
31634- if (copy_from_user(msg, buf, count))
31635+ if (count > sizeof msg || copy_from_user(msg, buf, count))
31636 return -EFAULT;
31637 } else
31638 memcpy(msg, buf, count);
31639diff -urNp linux-2.6.39.1/drivers/lguest/core.c linux-2.6.39.1/drivers/lguest/core.c
31640--- linux-2.6.39.1/drivers/lguest/core.c 2011-05-19 00:06:34.000000000 -0400
31641+++ linux-2.6.39.1/drivers/lguest/core.c 2011-05-22 19:36:31.000000000 -0400
31642@@ -92,9 +92,17 @@ static __init int map_switcher(void)
31643 * it's worked so far. The end address needs +1 because __get_vm_area
31644 * allocates an extra guard page, so we need space for that.
31645 */
31646+
31647+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31648+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31649+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31650+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31651+#else
31652 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31653 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31654 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31655+#endif
31656+
31657 if (!switcher_vma) {
31658 err = -ENOMEM;
31659 printk("lguest: could not map switcher pages high\n");
31660@@ -119,7 +127,7 @@ static __init int map_switcher(void)
31661 * Now the Switcher is mapped at the right address, we can't fail!
31662 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31663 */
31664- memcpy(switcher_vma->addr, start_switcher_text,
31665+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31666 end_switcher_text - start_switcher_text);
31667
31668 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31669diff -urNp linux-2.6.39.1/drivers/lguest/lguest_device.c linux-2.6.39.1/drivers/lguest/lguest_device.c
31670--- linux-2.6.39.1/drivers/lguest/lguest_device.c 2011-05-19 00:06:34.000000000 -0400
31671+++ linux-2.6.39.1/drivers/lguest/lguest_device.c 2011-05-22 19:36:31.000000000 -0400
31672@@ -374,7 +374,7 @@ error:
31673 }
31674
31675 /* The ops structure which hooks everything together. */
31676-static struct virtio_config_ops lguest_config_ops = {
31677+static const struct virtio_config_ops lguest_config_ops = {
31678 .get_features = lg_get_features,
31679 .finalize_features = lg_finalize_features,
31680 .get = lg_get,
31681diff -urNp linux-2.6.39.1/drivers/lguest/x86/core.c linux-2.6.39.1/drivers/lguest/x86/core.c
31682--- linux-2.6.39.1/drivers/lguest/x86/core.c 2011-05-19 00:06:34.000000000 -0400
31683+++ linux-2.6.39.1/drivers/lguest/x86/core.c 2011-05-22 19:36:31.000000000 -0400
31684@@ -59,7 +59,7 @@ static struct {
31685 /* Offset from where switcher.S was compiled to where we've copied it */
31686 static unsigned long switcher_offset(void)
31687 {
31688- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31689+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31690 }
31691
31692 /* This cpu's struct lguest_pages. */
31693@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31694 * These copies are pretty cheap, so we do them unconditionally: */
31695 /* Save the current Host top-level page directory.
31696 */
31697+
31698+#ifdef CONFIG_PAX_PER_CPU_PGD
31699+ pages->state.host_cr3 = read_cr3();
31700+#else
31701 pages->state.host_cr3 = __pa(current->mm->pgd);
31702+#endif
31703+
31704 /*
31705 * Set up the Guest's page tables to see this CPU's pages (and no
31706 * other CPU's pages).
31707@@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
31708 * compiled-in switcher code and the high-mapped copy we just made.
31709 */
31710 for (i = 0; i < IDT_ENTRIES; i++)
31711- default_idt_entries[i] += switcher_offset();
31712+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31713
31714 /*
31715 * Set up the Switcher's per-cpu areas.
31716@@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
31717 * it will be undisturbed when we switch. To change %cs and jump we
31718 * need this structure to feed to Intel's "lcall" instruction.
31719 */
31720- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31721+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31722 lguest_entry.segment = LGUEST_CS;
31723
31724 /*
31725diff -urNp linux-2.6.39.1/drivers/lguest/x86/switcher_32.S linux-2.6.39.1/drivers/lguest/x86/switcher_32.S
31726--- linux-2.6.39.1/drivers/lguest/x86/switcher_32.S 2011-05-19 00:06:34.000000000 -0400
31727+++ linux-2.6.39.1/drivers/lguest/x86/switcher_32.S 2011-05-22 19:36:31.000000000 -0400
31728@@ -87,6 +87,7 @@
31729 #include <asm/page.h>
31730 #include <asm/segment.h>
31731 #include <asm/lguest.h>
31732+#include <asm/processor-flags.h>
31733
31734 // We mark the start of the code to copy
31735 // It's placed in .text tho it's never run here
31736@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31737 // Changes type when we load it: damn Intel!
31738 // For after we switch over our page tables
31739 // That entry will be read-only: we'd crash.
31740+
31741+#ifdef CONFIG_PAX_KERNEXEC
31742+ mov %cr0, %edx
31743+ xor $X86_CR0_WP, %edx
31744+ mov %edx, %cr0
31745+#endif
31746+
31747 movl $(GDT_ENTRY_TSS*8), %edx
31748 ltr %dx
31749
31750@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31751 // Let's clear it again for our return.
31752 // The GDT descriptor of the Host
31753 // Points to the table after two "size" bytes
31754- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31755+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31756 // Clear "used" from type field (byte 5, bit 2)
31757- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31758+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31759+
31760+#ifdef CONFIG_PAX_KERNEXEC
31761+ mov %cr0, %eax
31762+ xor $X86_CR0_WP, %eax
31763+ mov %eax, %cr0
31764+#endif
31765
31766 // Once our page table's switched, the Guest is live!
31767 // The Host fades as we run this final step.
31768@@ -295,13 +309,12 @@ deliver_to_host:
31769 // I consulted gcc, and it gave
31770 // These instructions, which I gladly credit:
31771 leal (%edx,%ebx,8), %eax
31772- movzwl (%eax),%edx
31773- movl 4(%eax), %eax
31774- xorw %ax, %ax
31775- orl %eax, %edx
31776+ movl 4(%eax), %edx
31777+ movw (%eax), %dx
31778 // Now the address of the handler's in %edx
31779 // We call it now: its "iret" drops us home.
31780- jmp *%edx
31781+ ljmp $__KERNEL_CS, $1f
31782+1: jmp *%edx
31783
31784 // Every interrupt can come to us here
31785 // But we must truly tell each apart.
31786diff -urNp linux-2.6.39.1/drivers/md/dm.c linux-2.6.39.1/drivers/md/dm.c
31787--- linux-2.6.39.1/drivers/md/dm.c 2011-05-19 00:06:34.000000000 -0400
31788+++ linux-2.6.39.1/drivers/md/dm.c 2011-05-22 19:36:31.000000000 -0400
31789@@ -162,9 +162,9 @@ struct mapped_device {
31790 /*
31791 * Event handling.
31792 */
31793- atomic_t event_nr;
31794+ atomic_unchecked_t event_nr;
31795 wait_queue_head_t eventq;
31796- atomic_t uevent_seq;
31797+ atomic_unchecked_t uevent_seq;
31798 struct list_head uevent_list;
31799 spinlock_t uevent_lock; /* Protect access to uevent_list */
31800
31801@@ -1836,8 +1836,8 @@ static struct mapped_device *alloc_dev(i
31802 rwlock_init(&md->map_lock);
31803 atomic_set(&md->holders, 1);
31804 atomic_set(&md->open_count, 0);
31805- atomic_set(&md->event_nr, 0);
31806- atomic_set(&md->uevent_seq, 0);
31807+ atomic_set_unchecked(&md->event_nr, 0);
31808+ atomic_set_unchecked(&md->uevent_seq, 0);
31809 INIT_LIST_HEAD(&md->uevent_list);
31810 spin_lock_init(&md->uevent_lock);
31811
31812@@ -1971,7 +1971,7 @@ static void event_callback(void *context
31813
31814 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31815
31816- atomic_inc(&md->event_nr);
31817+ atomic_inc_unchecked(&md->event_nr);
31818 wake_up(&md->eventq);
31819 }
31820
31821@@ -2547,18 +2547,18 @@ int dm_kobject_uevent(struct mapped_devi
31822
31823 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31824 {
31825- return atomic_add_return(1, &md->uevent_seq);
31826+ return atomic_add_return_unchecked(1, &md->uevent_seq);
31827 }
31828
31829 uint32_t dm_get_event_nr(struct mapped_device *md)
31830 {
31831- return atomic_read(&md->event_nr);
31832+ return atomic_read_unchecked(&md->event_nr);
31833 }
31834
31835 int dm_wait_event(struct mapped_device *md, int event_nr)
31836 {
31837 return wait_event_interruptible(md->eventq,
31838- (event_nr != atomic_read(&md->event_nr)));
31839+ (event_nr != atomic_read_unchecked(&md->event_nr)));
31840 }
31841
31842 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31843diff -urNp linux-2.6.39.1/drivers/md/dm-crypt.c linux-2.6.39.1/drivers/md/dm-crypt.c
31844--- linux-2.6.39.1/drivers/md/dm-crypt.c 2011-05-19 00:06:34.000000000 -0400
31845+++ linux-2.6.39.1/drivers/md/dm-crypt.c 2011-05-22 19:36:31.000000000 -0400
31846@@ -138,7 +138,7 @@ struct crypt_config {
31847 char *cipher;
31848 char *cipher_string;
31849
31850- struct crypt_iv_operations *iv_gen_ops;
31851+ const struct crypt_iv_operations *iv_gen_ops;
31852 union {
31853 struct iv_essiv_private essiv;
31854 struct iv_benbi_private benbi;
31855@@ -620,15 +620,15 @@ static int crypt_iv_lmk_post(struct cryp
31856 return r;
31857 }
31858
31859-static struct crypt_iv_operations crypt_iv_plain_ops = {
31860+static const struct crypt_iv_operations crypt_iv_plain_ops = {
31861 .generator = crypt_iv_plain_gen
31862 };
31863
31864-static struct crypt_iv_operations crypt_iv_plain64_ops = {
31865+static const struct crypt_iv_operations crypt_iv_plain64_ops = {
31866 .generator = crypt_iv_plain64_gen
31867 };
31868
31869-static struct crypt_iv_operations crypt_iv_essiv_ops = {
31870+static const struct crypt_iv_operations crypt_iv_essiv_ops = {
31871 .ctr = crypt_iv_essiv_ctr,
31872 .dtr = crypt_iv_essiv_dtr,
31873 .init = crypt_iv_essiv_init,
31874@@ -636,17 +636,17 @@ static struct crypt_iv_operations crypt_
31875 .generator = crypt_iv_essiv_gen
31876 };
31877
31878-static struct crypt_iv_operations crypt_iv_benbi_ops = {
31879+static const struct crypt_iv_operations crypt_iv_benbi_ops = {
31880 .ctr = crypt_iv_benbi_ctr,
31881 .dtr = crypt_iv_benbi_dtr,
31882 .generator = crypt_iv_benbi_gen
31883 };
31884
31885-static struct crypt_iv_operations crypt_iv_null_ops = {
31886+static const struct crypt_iv_operations crypt_iv_null_ops = {
31887 .generator = crypt_iv_null_gen
31888 };
31889
31890-static struct crypt_iv_operations crypt_iv_lmk_ops = {
31891+static const struct crypt_iv_operations crypt_iv_lmk_ops = {
31892 .ctr = crypt_iv_lmk_ctr,
31893 .dtr = crypt_iv_lmk_dtr,
31894 .init = crypt_iv_lmk_init,
31895diff -urNp linux-2.6.39.1/drivers/md/dm-ioctl.c linux-2.6.39.1/drivers/md/dm-ioctl.c
31896--- linux-2.6.39.1/drivers/md/dm-ioctl.c 2011-05-19 00:06:34.000000000 -0400
31897+++ linux-2.6.39.1/drivers/md/dm-ioctl.c 2011-05-22 19:36:31.000000000 -0400
31898@@ -1551,7 +1551,7 @@ static int validate_params(uint cmd, str
31899 cmd == DM_LIST_VERSIONS_CMD)
31900 return 0;
31901
31902- if ((cmd == DM_DEV_CREATE_CMD)) {
31903+ if (cmd == DM_DEV_CREATE_CMD) {
31904 if (!*param->name) {
31905 DMWARN("name not supplied when creating device");
31906 return -EINVAL;
31907diff -urNp linux-2.6.39.1/drivers/md/dm-raid1.c linux-2.6.39.1/drivers/md/dm-raid1.c
31908--- linux-2.6.39.1/drivers/md/dm-raid1.c 2011-05-19 00:06:34.000000000 -0400
31909+++ linux-2.6.39.1/drivers/md/dm-raid1.c 2011-05-22 19:36:31.000000000 -0400
31910@@ -42,7 +42,7 @@ enum dm_raid1_error {
31911
31912 struct mirror {
31913 struct mirror_set *ms;
31914- atomic_t error_count;
31915+ atomic_unchecked_t error_count;
31916 unsigned long error_type;
31917 struct dm_dev *dev;
31918 sector_t offset;
31919@@ -187,7 +187,7 @@ static struct mirror *get_valid_mirror(s
31920 struct mirror *m;
31921
31922 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31923- if (!atomic_read(&m->error_count))
31924+ if (!atomic_read_unchecked(&m->error_count))
31925 return m;
31926
31927 return NULL;
31928@@ -219,7 +219,7 @@ static void fail_mirror(struct mirror *m
31929 * simple way to tell if a device has encountered
31930 * errors.
31931 */
31932- atomic_inc(&m->error_count);
31933+ atomic_inc_unchecked(&m->error_count);
31934
31935 if (test_and_set_bit(error_type, &m->error_type))
31936 return;
31937@@ -410,7 +410,7 @@ static struct mirror *choose_mirror(stru
31938 struct mirror *m = get_default_mirror(ms);
31939
31940 do {
31941- if (likely(!atomic_read(&m->error_count)))
31942+ if (likely(!atomic_read_unchecked(&m->error_count)))
31943 return m;
31944
31945 if (m-- == ms->mirror)
31946@@ -424,7 +424,7 @@ static int default_ok(struct mirror *m)
31947 {
31948 struct mirror *default_mirror = get_default_mirror(m->ms);
31949
31950- return !atomic_read(&default_mirror->error_count);
31951+ return !atomic_read_unchecked(&default_mirror->error_count);
31952 }
31953
31954 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31955@@ -561,7 +561,7 @@ static void do_reads(struct mirror_set *
31956 */
31957 if (likely(region_in_sync(ms, region, 1)))
31958 m = choose_mirror(ms, bio->bi_sector);
31959- else if (m && atomic_read(&m->error_count))
31960+ else if (m && atomic_read_unchecked(&m->error_count))
31961 m = NULL;
31962
31963 if (likely(m))
31964@@ -939,7 +939,7 @@ static int get_mirror(struct mirror_set
31965 }
31966
31967 ms->mirror[mirror].ms = ms;
31968- atomic_set(&(ms->mirror[mirror].error_count), 0);
31969+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31970 ms->mirror[mirror].error_type = 0;
31971 ms->mirror[mirror].offset = offset;
31972
31973@@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_targ
31974 */
31975 static char device_status_char(struct mirror *m)
31976 {
31977- if (!atomic_read(&(m->error_count)))
31978+ if (!atomic_read_unchecked(&(m->error_count)))
31979 return 'A';
31980
31981 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31982diff -urNp linux-2.6.39.1/drivers/md/dm-stripe.c linux-2.6.39.1/drivers/md/dm-stripe.c
31983--- linux-2.6.39.1/drivers/md/dm-stripe.c 2011-05-19 00:06:34.000000000 -0400
31984+++ linux-2.6.39.1/drivers/md/dm-stripe.c 2011-05-22 19:36:31.000000000 -0400
31985@@ -20,7 +20,7 @@ struct stripe {
31986 struct dm_dev *dev;
31987 sector_t physical_start;
31988
31989- atomic_t error_count;
31990+ atomic_unchecked_t error_count;
31991 };
31992
31993 struct stripe_c {
31994@@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *
31995 kfree(sc);
31996 return r;
31997 }
31998- atomic_set(&(sc->stripe[i].error_count), 0);
31999+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32000 }
32001
32002 ti->private = sc;
32003@@ -314,7 +314,7 @@ static int stripe_status(struct dm_targe
32004 DMEMIT("%d ", sc->stripes);
32005 for (i = 0; i < sc->stripes; i++) {
32006 DMEMIT("%s ", sc->stripe[i].dev->name);
32007- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32008+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32009 'D' : 'A';
32010 }
32011 buffer[i] = '\0';
32012@@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_targe
32013 */
32014 for (i = 0; i < sc->stripes; i++)
32015 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32016- atomic_inc(&(sc->stripe[i].error_count));
32017- if (atomic_read(&(sc->stripe[i].error_count)) <
32018+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
32019+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32020 DM_IO_ERROR_THRESHOLD)
32021 schedule_work(&sc->trigger_event);
32022 }
32023diff -urNp linux-2.6.39.1/drivers/md/dm-table.c linux-2.6.39.1/drivers/md/dm-table.c
32024--- linux-2.6.39.1/drivers/md/dm-table.c 2011-06-03 00:04:14.000000000 -0400
32025+++ linux-2.6.39.1/drivers/md/dm-table.c 2011-06-03 00:32:05.000000000 -0400
32026@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct
32027 if (!dev_size)
32028 return 0;
32029
32030- if ((start >= dev_size) || (start + len > dev_size)) {
32031+ if ((start >= dev_size) || (len > dev_size - start)) {
32032 DMWARN("%s: %s too small for target: "
32033 "start=%llu, len=%llu, dev_size=%llu",
32034 dm_device_name(ti->table->md), bdevname(bdev, b),
32035diff -urNp linux-2.6.39.1/drivers/md/md.c linux-2.6.39.1/drivers/md/md.c
32036--- linux-2.6.39.1/drivers/md/md.c 2011-06-03 00:04:14.000000000 -0400
32037+++ linux-2.6.39.1/drivers/md/md.c 2011-06-03 00:32:05.000000000 -0400
32038@@ -226,10 +226,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
32039 * start build, activate spare
32040 */
32041 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32042-static atomic_t md_event_count;
32043+static atomic_unchecked_t md_event_count;
32044 void md_new_event(mddev_t *mddev)
32045 {
32046- atomic_inc(&md_event_count);
32047+ atomic_inc_unchecked(&md_event_count);
32048 wake_up(&md_event_waiters);
32049 }
32050 EXPORT_SYMBOL_GPL(md_new_event);
32051@@ -239,7 +239,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32052 */
32053 static void md_new_event_inintr(mddev_t *mddev)
32054 {
32055- atomic_inc(&md_event_count);
32056+ atomic_inc_unchecked(&md_event_count);
32057 wake_up(&md_event_waiters);
32058 }
32059
32060@@ -1454,7 +1454,7 @@ static int super_1_load(mdk_rdev_t *rdev
32061
32062 rdev->preferred_minor = 0xffff;
32063 rdev->data_offset = le64_to_cpu(sb->data_offset);
32064- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32065+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32066
32067 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32068 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32069@@ -1632,7 +1632,7 @@ static void super_1_sync(mddev_t *mddev,
32070 else
32071 sb->resync_offset = cpu_to_le64(0);
32072
32073- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32074+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32075
32076 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32077 sb->size = cpu_to_le64(mddev->dev_sectors);
32078@@ -2414,7 +2414,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
32079 static ssize_t
32080 errors_show(mdk_rdev_t *rdev, char *page)
32081 {
32082- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32083+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32084 }
32085
32086 static ssize_t
32087@@ -2423,7 +2423,7 @@ errors_store(mdk_rdev_t *rdev, const cha
32088 char *e;
32089 unsigned long n = simple_strtoul(buf, &e, 10);
32090 if (*buf && (*e == 0 || *e == '\n')) {
32091- atomic_set(&rdev->corrected_errors, n);
32092+ atomic_set_unchecked(&rdev->corrected_errors, n);
32093 return len;
32094 }
32095 return -EINVAL;
32096@@ -2779,8 +2779,8 @@ void md_rdev_init(mdk_rdev_t *rdev)
32097 rdev->last_read_error.tv_sec = 0;
32098 rdev->last_read_error.tv_nsec = 0;
32099 atomic_set(&rdev->nr_pending, 0);
32100- atomic_set(&rdev->read_errors, 0);
32101- atomic_set(&rdev->corrected_errors, 0);
32102+ atomic_set_unchecked(&rdev->read_errors, 0);
32103+ atomic_set_unchecked(&rdev->corrected_errors, 0);
32104
32105 INIT_LIST_HEAD(&rdev->same_set);
32106 init_waitqueue_head(&rdev->blocked_wait);
32107@@ -6388,7 +6388,7 @@ static int md_seq_show(struct seq_file *
32108
32109 spin_unlock(&pers_lock);
32110 seq_printf(seq, "\n");
32111- mi->event = atomic_read(&md_event_count);
32112+ mi->event = atomic_read_unchecked(&md_event_count);
32113 return 0;
32114 }
32115 if (v == (void*)2) {
32116@@ -6477,7 +6477,7 @@ static int md_seq_show(struct seq_file *
32117 chunk_kb ? "KB" : "B");
32118 if (bitmap->file) {
32119 seq_printf(seq, ", file: ");
32120- seq_path(seq, &bitmap->file->f_path, " \t\n");
32121+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32122 }
32123
32124 seq_printf(seq, "\n");
32125@@ -6511,7 +6511,7 @@ static int md_seq_open(struct inode *ino
32126 else {
32127 struct seq_file *p = file->private_data;
32128 p->private = mi;
32129- mi->event = atomic_read(&md_event_count);
32130+ mi->event = atomic_read_unchecked(&md_event_count);
32131 }
32132 return error;
32133 }
32134@@ -6527,7 +6527,7 @@ static unsigned int mdstat_poll(struct f
32135 /* always allow read */
32136 mask = POLLIN | POLLRDNORM;
32137
32138- if (mi->event != atomic_read(&md_event_count))
32139+ if (mi->event != atomic_read_unchecked(&md_event_count))
32140 mask |= POLLERR | POLLPRI;
32141 return mask;
32142 }
32143@@ -6571,7 +6571,7 @@ static int is_mddev_idle(mddev_t *mddev,
32144 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32145 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32146 (int)part_stat_read(&disk->part0, sectors[1]) -
32147- atomic_read(&disk->sync_io);
32148+ atomic_read_unchecked(&disk->sync_io);
32149 /* sync IO will cause sync_io to increase before the disk_stats
32150 * as sync_io is counted when a request starts, and
32151 * disk_stats is counted when it completes.
32152diff -urNp linux-2.6.39.1/drivers/md/md.h linux-2.6.39.1/drivers/md/md.h
32153--- linux-2.6.39.1/drivers/md/md.h 2011-05-19 00:06:34.000000000 -0400
32154+++ linux-2.6.39.1/drivers/md/md.h 2011-05-22 19:36:31.000000000 -0400
32155@@ -97,13 +97,13 @@ struct mdk_rdev_s
32156 * only maintained for arrays that
32157 * support hot removal
32158 */
32159- atomic_t read_errors; /* number of consecutive read errors that
32160+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
32161 * we have tried to ignore.
32162 */
32163 struct timespec last_read_error; /* monotonic time since our
32164 * last read error
32165 */
32166- atomic_t corrected_errors; /* number of corrected read errors,
32167+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32168 * for reporting to userspace and storing
32169 * in superblock.
32170 */
32171@@ -342,7 +342,7 @@ static inline void rdev_dec_pending(mdk_
32172
32173 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32174 {
32175- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32176+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32177 }
32178
32179 struct mdk_personality
32180diff -urNp linux-2.6.39.1/drivers/md/raid10.c linux-2.6.39.1/drivers/md/raid10.c
32181--- linux-2.6.39.1/drivers/md/raid10.c 2011-05-19 00:06:34.000000000 -0400
32182+++ linux-2.6.39.1/drivers/md/raid10.c 2011-05-22 19:36:31.000000000 -0400
32183@@ -1209,7 +1209,7 @@ static void end_sync_read(struct bio *bi
32184 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
32185 set_bit(R10BIO_Uptodate, &r10_bio->state);
32186 else {
32187- atomic_add(r10_bio->sectors,
32188+ atomic_add_unchecked(r10_bio->sectors,
32189 &conf->mirrors[d].rdev->corrected_errors);
32190 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
32191 md_error(r10_bio->mddev,
32192@@ -1417,7 +1417,7 @@ static void check_decay_read_errors(mdde
32193 {
32194 struct timespec cur_time_mon;
32195 unsigned long hours_since_last;
32196- unsigned int read_errors = atomic_read(&rdev->read_errors);
32197+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32198
32199 ktime_get_ts(&cur_time_mon);
32200
32201@@ -1439,9 +1439,9 @@ static void check_decay_read_errors(mdde
32202 * overflowing the shift of read_errors by hours_since_last.
32203 */
32204 if (hours_since_last >= 8 * sizeof(read_errors))
32205- atomic_set(&rdev->read_errors, 0);
32206+ atomic_set_unchecked(&rdev->read_errors, 0);
32207 else
32208- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32209+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32210 }
32211
32212 /*
32213@@ -1476,8 +1476,8 @@ static void fix_read_error(conf_t *conf,
32214 }
32215
32216 check_decay_read_errors(mddev, rdev);
32217- atomic_inc(&rdev->read_errors);
32218- cur_read_error_count = atomic_read(&rdev->read_errors);
32219+ atomic_inc_unchecked(&rdev->read_errors);
32220+ cur_read_error_count = atomic_read_unchecked(&rdev->read_errors);
32221 if (cur_read_error_count > max_read_errors) {
32222 rcu_read_unlock();
32223 printk(KERN_NOTICE
32224@@ -1550,7 +1550,7 @@ static void fix_read_error(conf_t *conf,
32225 test_bit(In_sync, &rdev->flags)) {
32226 atomic_inc(&rdev->nr_pending);
32227 rcu_read_unlock();
32228- atomic_add(s, &rdev->corrected_errors);
32229+ atomic_add_unchecked(s, &rdev->corrected_errors);
32230 if (sync_page_io(rdev,
32231 r10_bio->devs[sl].addr +
32232 sect,
32233diff -urNp linux-2.6.39.1/drivers/md/raid1.c linux-2.6.39.1/drivers/md/raid1.c
32234--- linux-2.6.39.1/drivers/md/raid1.c 2011-05-19 00:06:34.000000000 -0400
32235+++ linux-2.6.39.1/drivers/md/raid1.c 2011-05-22 19:36:31.000000000 -0400
32236@@ -1342,7 +1342,7 @@ static void sync_request_write(mddev_t *
32237 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
32238 continue;
32239 rdev = conf->mirrors[d].rdev;
32240- atomic_add(s, &rdev->corrected_errors);
32241+ atomic_add_unchecked(s, &rdev->corrected_errors);
32242 if (sync_page_io(rdev,
32243 sect,
32244 s<<9,
32245@@ -1488,7 +1488,7 @@ static void fix_read_error(conf_t *conf,
32246 /* Well, this device is dead */
32247 md_error(mddev, rdev);
32248 else {
32249- atomic_add(s, &rdev->corrected_errors);
32250+ atomic_add_unchecked(s, &rdev->corrected_errors);
32251 printk(KERN_INFO
32252 "md/raid1:%s: read error corrected "
32253 "(%d sectors at %llu on %s)\n",
32254diff -urNp linux-2.6.39.1/drivers/md/raid5.c linux-2.6.39.1/drivers/md/raid5.c
32255--- linux-2.6.39.1/drivers/md/raid5.c 2011-05-19 00:06:34.000000000 -0400
32256+++ linux-2.6.39.1/drivers/md/raid5.c 2011-05-22 19:36:31.000000000 -0400
32257@@ -550,7 +550,7 @@ static void ops_run_io(struct stripe_hea
32258 bi->bi_next = NULL;
32259 if (rw == WRITE &&
32260 test_bit(R5_ReWrite, &sh->dev[i].flags))
32261- atomic_add(STRIPE_SECTORS,
32262+ atomic_add_unchecked(STRIPE_SECTORS,
32263 &rdev->corrected_errors);
32264 generic_make_request(bi);
32265 } else {
32266@@ -1596,15 +1596,15 @@ static void raid5_end_read_request(struc
32267 clear_bit(R5_ReadError, &sh->dev[i].flags);
32268 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32269 }
32270- if (atomic_read(&conf->disks[i].rdev->read_errors))
32271- atomic_set(&conf->disks[i].rdev->read_errors, 0);
32272+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32273+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32274 } else {
32275 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32276 int retry = 0;
32277 rdev = conf->disks[i].rdev;
32278
32279 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32280- atomic_inc(&rdev->read_errors);
32281+ atomic_inc_unchecked(&rdev->read_errors);
32282 if (conf->mddev->degraded >= conf->max_degraded)
32283 printk_rl(KERN_WARNING
32284 "md/raid:%s: read error not correctable "
32285@@ -1622,7 +1622,7 @@ static void raid5_end_read_request(struc
32286 (unsigned long long)(sh->sector
32287 + rdev->data_offset),
32288 bdn);
32289- else if (atomic_read(&rdev->read_errors)
32290+ else if (atomic_read_unchecked(&rdev->read_errors)
32291 > conf->max_nr_stripes)
32292 printk(KERN_WARNING
32293 "md/raid:%s: Too many read errors, failing device %s.\n",
32294@@ -1947,6 +1947,7 @@ static sector_t compute_blocknr(struct s
32295 sector_t r_sector;
32296 struct stripe_head sh2;
32297
32298+ pax_track_stack();
32299
32300 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32301 stripe = new_sector;
32302diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_hlp.c linux-2.6.39.1/drivers/media/common/saa7146_hlp.c
32303--- linux-2.6.39.1/drivers/media/common/saa7146_hlp.c 2011-05-19 00:06:34.000000000 -0400
32304+++ linux-2.6.39.1/drivers/media/common/saa7146_hlp.c 2011-05-22 19:36:31.000000000 -0400
32305@@ -353,6 +353,8 @@ static void calculate_clipping_registers
32306
32307 int x[32], y[32], w[32], h[32];
32308
32309+ pax_track_stack();
32310+
32311 /* clear out memory */
32312 memset(&line_list[0], 0x00, sizeof(u32)*32);
32313 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32314diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_vbi.c linux-2.6.39.1/drivers/media/common/saa7146_vbi.c
32315--- linux-2.6.39.1/drivers/media/common/saa7146_vbi.c 2011-05-19 00:06:34.000000000 -0400
32316+++ linux-2.6.39.1/drivers/media/common/saa7146_vbi.c 2011-05-22 19:36:31.000000000 -0400
32317@@ -501,7 +501,7 @@ static ssize_t vbi_read(struct file *fil
32318 return ret;
32319 }
32320
32321-struct saa7146_use_ops saa7146_vbi_uops = {
32322+const struct saa7146_use_ops saa7146_vbi_uops = {
32323 .init = vbi_init,
32324 .open = vbi_open,
32325 .release = vbi_close,
32326diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_video.c linux-2.6.39.1/drivers/media/common/saa7146_video.c
32327--- linux-2.6.39.1/drivers/media/common/saa7146_video.c 2011-05-19 00:06:34.000000000 -0400
32328+++ linux-2.6.39.1/drivers/media/common/saa7146_video.c 2011-05-22 19:36:31.000000000 -0400
32329@@ -1420,7 +1420,7 @@ out:
32330 return ret;
32331 }
32332
32333-struct saa7146_use_ops saa7146_video_uops = {
32334+const struct saa7146_use_ops saa7146_video_uops = {
32335 .init = video_init,
32336 .open = video_open,
32337 .release = video_close,
32338diff -urNp linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c
32339--- linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c 2011-05-19 00:06:34.000000000 -0400
32340+++ linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c 2011-05-22 19:36:31.000000000 -0400
32341@@ -418,7 +418,7 @@ static u32 functionality(struct i2c_adap
32342 return I2C_FUNC_I2C;
32343 }
32344
32345-static struct i2c_algorithm dm1105_algo = {
32346+static const struct i2c_algorithm dm1105_algo = {
32347 .master_xfer = dm1105_i2c_xfer,
32348 .functionality = functionality,
32349 };
32350diff -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
32351--- linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-19 00:06:34.000000000 -0400
32352+++ linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-22 19:36:31.000000000 -0400
32353@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32354 u8 buf[HOST_LINK_BUF_SIZE];
32355 int i;
32356
32357+ pax_track_stack();
32358+
32359 dprintk("%s\n", __func__);
32360
32361 /* check if we have space for a link buf in the rx_buffer */
32362@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32363 unsigned long timeout;
32364 int written;
32365
32366+ pax_track_stack();
32367+
32368 dprintk("%s\n", __func__);
32369
32370 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32371diff -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
32372--- linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-19 00:06:34.000000000 -0400
32373+++ linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-22 19:36:31.000000000 -0400
32374@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapt
32375 const struct dvb_device *template, void *priv, int type)
32376 {
32377 struct dvb_device *dvbdev;
32378- struct file_operations *dvbdevfops;
32379+ struct file_operations *dvbdevfops; /* cannot be const, see this function */
32380 struct device *clsdev;
32381 int minor;
32382 int id;
32383diff -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
32384--- linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-19 00:06:34.000000000 -0400
32385+++ linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-22 19:36:31.000000000 -0400
32386@@ -391,6 +391,8 @@ int dib0700_download_firmware(struct usb
32387
32388 u8 buf[260];
32389
32390+ pax_track_stack();
32391+
32392 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32393 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
32394 hx.addr, hx.len, hx.chk);
32395diff -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
32396--- linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-19 00:06:34.000000000 -0400
32397+++ linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-22 19:36:31.000000000 -0400
32398@@ -663,6 +663,7 @@ static int lme2510_download_firmware(str
32399 packet_size = 0x31;
32400 len_in = 1;
32401
32402+ pax_track_stack();
32403
32404 info("FRM Starting Firmware Download");
32405
32406@@ -715,6 +716,8 @@ static void lme_coldreset(struct usb_dev
32407 int ret = 0, len_in;
32408 u8 data[512] = {0};
32409
32410+ pax_track_stack();
32411+
32412 data[0] = 0x0a;
32413 len_in = 1;
32414 info("FRM Firmware Cold Reset");
32415diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c
32416--- linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:04:14.000000000 -0400
32417+++ linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:32:05.000000000 -0400
32418@@ -1945,7 +1945,7 @@ static u32 dib7000p_i2c_func(struct i2c_
32419 return I2C_FUNC_I2C;
32420 }
32421
32422-static struct i2c_algorithm dib7090_tuner_xfer_algo = {
32423+static const struct i2c_algorithm dib7090_tuner_xfer_algo = {
32424 .master_xfer = dib7090_tuner_xfer,
32425 .functionality = dib7000p_i2c_func,
32426 };
32427diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c
32428--- linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:04:14.000000000 -0400
32429+++ linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:32:05.000000000 -0400
32430@@ -1676,12 +1676,12 @@ static u32 dib9000_i2c_func(struct i2c_a
32431 return I2C_FUNC_I2C;
32432 }
32433
32434-static struct i2c_algorithm dib9000_tuner_algo = {
32435+static const struct i2c_algorithm dib9000_tuner_algo = {
32436 .master_xfer = dib9000_tuner_xfer,
32437 .functionality = dib9000_i2c_func,
32438 };
32439
32440-static struct i2c_algorithm dib9000_component_bus_algo = {
32441+static const struct i2c_algorithm dib9000_component_bus_algo = {
32442 .master_xfer = dib9000_fw_component_bus_xfer,
32443 .functionality = dib9000_i2c_func,
32444 };
32445diff -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
32446--- linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:04:14.000000000 -0400
32447+++ linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:37:36.000000000 -0400
32448@@ -221,12 +221,12 @@ static int dibx000_i2c_master_xfer_gpio3
32449 return num;
32450 }
32451
32452-static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32453+static const struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32454 .master_xfer = dibx000_i2c_master_xfer_gpio12,
32455 .functionality = dibx000_i2c_func,
32456 };
32457
32458-static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32459+static const struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32460 .master_xfer = dibx000_i2c_master_xfer_gpio34,
32461 .functionality = dibx000_i2c_func,
32462 };
32463@@ -285,7 +285,7 @@ static int dibx000_i2c_gated_gpio67_xfer
32464 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32465 }
32466
32467-static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32468+static const struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32469 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
32470 .functionality = dibx000_i2c_func,
32471 };
32472@@ -322,7 +322,7 @@ static int dibx000_i2c_gated_tuner_xfer(
32473 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32474 }
32475
32476-static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32477+static const struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32478 .master_xfer = dibx000_i2c_gated_tuner_xfer,
32479 .functionality = dibx000_i2c_func,
32480 };
32481@@ -375,7 +375,7 @@ void dibx000_reset_i2c_master(struct dib
32482 EXPORT_SYMBOL(dibx000_reset_i2c_master);
32483
32484 static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
32485- struct i2c_algorithm *algo, const char *name,
32486+ const struct i2c_algorithm *algo, const char *name,
32487 struct dibx000_i2c_master *mst)
32488 {
32489 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
32490diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c
32491--- linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c 2011-05-19 00:06:34.000000000 -0400
32492+++ linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c 2011-05-22 19:36:31.000000000 -0400
32493@@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16
32494 int ret = -1;
32495 int sync;
32496
32497+ pax_track_stack();
32498+
32499 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
32500
32501 fcp = 3000;
32502diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c
32503--- linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c 2011-05-19 00:06:34.000000000 -0400
32504+++ linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c 2011-05-22 19:36:31.000000000 -0400
32505@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32506 u8 tudata[585];
32507 int i;
32508
32509+ pax_track_stack();
32510+
32511 dprintk("Firmware is %zd bytes\n",fw->size);
32512
32513 /* Get eprom data */
32514diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c
32515--- linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c 2011-05-19 00:06:34.000000000 -0400
32516+++ linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c 2011-05-22 19:36:31.000000000 -0400
32517@@ -870,7 +870,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(
32518 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
32519 }
32520
32521-static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32522+static const struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32523 .master_xfer = s5h1420_tuner_i2c_tuner_xfer,
32524 .functionality = s5h1420_tuner_i2c_func,
32525 };
32526diff -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
32527--- linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-19 00:06:34.000000000 -0400
32528+++ linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-22 19:36:31.000000000 -0400
32529@@ -212,7 +212,7 @@ static u32 mantis_i2c_func(struct i2c_ad
32530 return I2C_FUNC_SMBUS_EMUL;
32531 }
32532
32533-static struct i2c_algorithm mantis_algo = {
32534+static const struct i2c_algorithm mantis_algo = {
32535 .master_xfer = mantis_i2c_xfer,
32536 .functionality = mantis_i2c_func,
32537 };
32538diff -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
32539--- linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-19 00:06:34.000000000 -0400
32540+++ linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-22 19:36:31.000000000 -0400
32541@@ -1614,7 +1614,7 @@ static int fe_send_command(struct dvb_fr
32542 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
32543 }
32544
32545-static struct ttusbdecfe_config fe_config = {
32546+static const struct ttusbdecfe_config fe_config = {
32547 .send_command = fe_send_command
32548 };
32549
32550diff -urNp linux-2.6.39.1/drivers/media/radio/radio-cadet.c linux-2.6.39.1/drivers/media/radio/radio-cadet.c
32551--- linux-2.6.39.1/drivers/media/radio/radio-cadet.c 2011-05-19 00:06:34.000000000 -0400
32552+++ linux-2.6.39.1/drivers/media/radio/radio-cadet.c 2011-05-22 19:36:31.000000000 -0400
32553@@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
32554 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32555 mutex_unlock(&dev->lock);
32556
32557- if (copy_to_user(data, readbuf, i))
32558+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32559 return -EFAULT;
32560 return i;
32561 }
32562diff -urNp linux-2.6.39.1/drivers/media/radio/radio-si4713.c linux-2.6.39.1/drivers/media/radio/radio-si4713.c
32563--- linux-2.6.39.1/drivers/media/radio/radio-si4713.c 2011-05-19 00:06:34.000000000 -0400
32564+++ linux-2.6.39.1/drivers/media/radio/radio-si4713.c 2011-05-22 19:36:31.000000000 -0400
32565@@ -231,7 +231,7 @@ static long radio_si4713_default(struct
32566 ioctl, cmd, arg);
32567 }
32568
32569-static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32570+static const struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32571 .vidioc_enumaudout = radio_si4713_enumaudout,
32572 .vidioc_g_audout = radio_si4713_g_audout,
32573 .vidioc_s_audout = radio_si4713_s_audout,
32574diff -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
32575--- linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c 2011-05-19 00:06:34.000000000 -0400
32576+++ linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c 2011-05-22 19:36:31.000000000 -0400
32577@@ -277,7 +277,7 @@ static void ir_lirc_close(void *data)
32578 return;
32579 }
32580
32581-static struct file_operations lirc_fops = {
32582+static const struct file_operations lirc_fops = {
32583 .owner = THIS_MODULE,
32584 .write = ir_lirc_transmit_ir,
32585 .unlocked_ioctl = ir_lirc_ioctl,
32586diff -urNp linux-2.6.39.1/drivers/media/rc/lirc_dev.c linux-2.6.39.1/drivers/media/rc/lirc_dev.c
32587--- linux-2.6.39.1/drivers/media/rc/lirc_dev.c 2011-05-19 00:06:34.000000000 -0400
32588+++ linux-2.6.39.1/drivers/media/rc/lirc_dev.c 2011-05-22 19:36:31.000000000 -0400
32589@@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
32590 }
32591
32592
32593-static struct file_operations lirc_dev_fops = {
32594+static const struct file_operations lirc_dev_fops = {
32595 .owner = THIS_MODULE,
32596 .read = lirc_dev_fop_read,
32597 .write = lirc_dev_fop_write,
32598diff -urNp linux-2.6.39.1/drivers/media/rc/rc-main.c linux-2.6.39.1/drivers/media/rc/rc-main.c
32599--- linux-2.6.39.1/drivers/media/rc/rc-main.c 2011-05-19 00:06:34.000000000 -0400
32600+++ linux-2.6.39.1/drivers/media/rc/rc-main.c 2011-05-22 19:36:31.000000000 -0400
32601@@ -996,7 +996,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
32602
32603 int rc_register_device(struct rc_dev *dev)
32604 {
32605- static atomic_t devno = ATOMIC_INIT(0);
32606+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
32607 struct rc_map *rc_map;
32608 const char *path;
32609 int rc;
32610@@ -1019,7 +1019,7 @@ int rc_register_device(struct rc_dev *de
32611 if (dev->close)
32612 dev->input_dev->close = ir_close;
32613
32614- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
32615+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
32616 dev_set_name(&dev->dev, "rc%ld", dev->devno);
32617 dev_set_drvdata(&dev->dev, dev);
32618 rc = device_add(&dev->dev);
32619diff -urNp linux-2.6.39.1/drivers/media/video/cafe_ccic.c linux-2.6.39.1/drivers/media/video/cafe_ccic.c
32620--- linux-2.6.39.1/drivers/media/video/cafe_ccic.c 2011-05-19 00:06:34.000000000 -0400
32621+++ linux-2.6.39.1/drivers/media/video/cafe_ccic.c 2011-05-22 19:36:31.000000000 -0400
32622@@ -520,7 +520,7 @@ static u32 cafe_smbus_func(struct i2c_ad
32623 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
32624 }
32625
32626-static struct i2c_algorithm cafe_smbus_algo = {
32627+static const struct i2c_algorithm cafe_smbus_algo = {
32628 .smbus_xfer = cafe_smbus_xfer,
32629 .functionality = cafe_smbus_func
32630 };
32631diff -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
32632--- linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-19 00:06:34.000000000 -0400
32633+++ linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-22 19:36:31.000000000 -0400
32634@@ -314,7 +314,7 @@ static struct page *snd_pcm_get_vmalloc_
32635 return vmalloc_to_page(pageptr);
32636 }
32637
32638-static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32639+static const struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32640 .open = snd_cx18_pcm_capture_open,
32641 .close = snd_cx18_pcm_capture_close,
32642 .ioctl = snd_cx18_pcm_ioctl,
32643diff -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
32644--- linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c 2011-05-19 00:06:34.000000000 -0400
32645+++ linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c 2011-05-22 19:36:31.000000000 -0400
32646@@ -61,7 +61,7 @@ static struct pci_device_id cx18_pci_tbl
32647
32648 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32649
32650-static atomic_t cx18_instance = ATOMIC_INIT(0);
32651+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32652
32653 /* Parameter declarations */
32654 static int cardtype[CX18_MAX_CARDS];
32655@@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32656 struct i2c_client c;
32657 u8 eedata[256];
32658
32659+ pax_track_stack();
32660+
32661 memset(&c, 0, sizeof(c));
32662 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32663 c.adapter = &cx->i2c_adap[0];
32664@@ -892,7 +894,7 @@ static int __devinit cx18_probe(struct p
32665 struct cx18 *cx;
32666
32667 /* FIXME - module parameter arrays constrain max instances */
32668- i = atomic_inc_return(&cx18_instance) - 1;
32669+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32670 if (i >= CX18_MAX_CARDS) {
32671 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32672 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32673diff -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
32674--- linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32675+++ linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32676@@ -613,7 +613,7 @@ static struct page *snd_pcm_get_vmalloc_
32677 return vmalloc_to_page(pageptr);
32678 }
32679
32680-static struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32681+static const struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32682 .open = snd_cx231xx_capture_open,
32683 .close = snd_cx231xx_pcm_close,
32684 .ioctl = snd_pcm_lib_ioctl,
32685diff -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
32686--- linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32687+++ linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32688@@ -435,7 +435,7 @@ static u32 functionality(struct i2c_adap
32689 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32690 }
32691
32692-static struct i2c_algorithm cx231xx_algo = {
32693+static const struct i2c_algorithm cx231xx_algo = {
32694 .master_xfer = cx231xx_i2c_xfer,
32695 .functionality = functionality,
32696 };
32697diff -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
32698--- linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c 2011-05-19 00:06:34.000000000 -0400
32699+++ linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c 2011-05-22 19:36:31.000000000 -0400
32700@@ -53,6 +53,8 @@ static void cx23885_input_process_measur
32701 bool handle = false;
32702 struct ir_raw_event ir_core_event[64];
32703
32704+ pax_track_stack();
32705+
32706 do {
32707 num = 0;
32708 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
32709diff -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
32710--- linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c 2011-05-19 00:06:34.000000000 -0400
32711+++ linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c 2011-05-22 19:36:31.000000000 -0400
32712@@ -519,7 +519,7 @@ static struct page *snd_cx88_page(struct
32713 /*
32714 * operators
32715 */
32716-static struct snd_pcm_ops snd_cx88_pcm_ops = {
32717+static const struct snd_pcm_ops snd_cx88_pcm_ops = {
32718 .open = snd_cx88_pcm_open,
32719 .close = snd_cx88_close,
32720 .ioctl = snd_pcm_lib_ioctl,
32721diff -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
32722--- linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-19 00:06:34.000000000 -0400
32723+++ linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-22 19:36:31.000000000 -0400
32724@@ -99,7 +99,7 @@ struct ccdc_hw_device {
32725 /* module owner */
32726 struct module *owner;
32727 /* hw ops */
32728- struct ccdc_hw_ops hw_ops;
32729+ const struct ccdc_hw_ops hw_ops;
32730 };
32731
32732 /* Used by CCDC module to register & unregister with vpfe capture driver */
32733diff -urNp linux-2.6.39.1/drivers/media/video/davinci/vpss.c linux-2.6.39.1/drivers/media/video/davinci/vpss.c
32734--- linux-2.6.39.1/drivers/media/video/davinci/vpss.c 2011-05-19 00:06:34.000000000 -0400
32735+++ linux-2.6.39.1/drivers/media/video/davinci/vpss.c 2011-05-22 19:36:31.000000000 -0400
32736@@ -103,7 +103,7 @@ struct vpss_oper_config {
32737 __iomem void *vpss_regs_base1;
32738 enum vpss_platform_type platform;
32739 spinlock_t vpss_lock;
32740- struct vpss_hw_ops hw_ops;
32741+ const struct vpss_hw_ops hw_ops;
32742 };
32743
32744 static struct vpss_oper_config oper_cfg;
32745diff -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
32746--- linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32747+++ linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32748@@ -432,7 +432,7 @@ static struct page *snd_pcm_get_vmalloc_
32749 return vmalloc_to_page(pageptr);
32750 }
32751
32752-static struct snd_pcm_ops snd_em28xx_pcm_capture = {
32753+static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
32754 .open = snd_em28xx_capture_open,
32755 .close = snd_em28xx_pcm_close,
32756 .ioctl = snd_pcm_lib_ioctl,
32757diff -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
32758--- linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32759+++ linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32760@@ -451,7 +451,7 @@ static u32 functionality(struct i2c_adap
32761 return I2C_FUNC_SMBUS_EMUL;
32762 }
32763
32764-static struct i2c_algorithm em28xx_algo = {
32765+static const struct i2c_algorithm em28xx_algo = {
32766 .master_xfer = em28xx_i2c_xfer,
32767 .functionality = functionality,
32768 };
32769diff -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
32770--- linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-19 00:06:34.000000000 -0400
32771+++ linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-22 19:36:31.000000000 -0400
32772@@ -179,7 +179,7 @@ static u32 hdpvr_functionality(struct i2
32773 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
32774 }
32775
32776-static struct i2c_algorithm hdpvr_algo = {
32777+static const struct i2c_algorithm hdpvr_algo = {
32778 .master_xfer = hdpvr_transfer,
32779 .functionality = hdpvr_functionality,
32780 };
32781diff -urNp linux-2.6.39.1/drivers/media/video/imx074.c linux-2.6.39.1/drivers/media/video/imx074.c
32782--- linux-2.6.39.1/drivers/media/video/imx074.c 2011-05-19 00:06:34.000000000 -0400
32783+++ linux-2.6.39.1/drivers/media/video/imx074.c 2011-05-22 19:36:31.000000000 -0400
32784@@ -267,7 +267,7 @@ static int imx074_g_chip_ident(struct v4
32785 return 0;
32786 }
32787
32788-static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32789+static const struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32790 .s_stream = imx074_s_stream,
32791 .s_mbus_fmt = imx074_s_fmt,
32792 .g_mbus_fmt = imx074_g_fmt,
32793@@ -277,7 +277,7 @@ static struct v4l2_subdev_video_ops imx0
32794 .cropcap = imx074_cropcap,
32795 };
32796
32797-static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32798+static const struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32799 .g_chip_ident = imx074_g_chip_ident,
32800 };
32801
32802diff -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
32803--- linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c 2011-05-19 00:06:34.000000000 -0400
32804+++ linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c 2011-05-22 19:36:31.000000000 -0400
32805@@ -80,7 +80,7 @@ static struct pci_device_id ivtv_pci_tbl
32806 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32807
32808 /* ivtv instance counter */
32809-static atomic_t ivtv_instance = ATOMIC_INIT(0);
32810+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32811
32812 /* Parameter declarations */
32813 static int cardtype[IVTV_MAX_CARDS];
32814diff -urNp linux-2.6.39.1/drivers/media/video/mt9m001.c linux-2.6.39.1/drivers/media/video/mt9m001.c
32815--- linux-2.6.39.1/drivers/media/video/mt9m001.c 2011-05-19 00:06:34.000000000 -0400
32816+++ linux-2.6.39.1/drivers/media/video/mt9m001.c 2011-05-22 19:36:31.000000000 -0400
32817@@ -691,7 +691,7 @@ static int mt9m001_g_skip_top_lines(stru
32818 return 0;
32819 }
32820
32821-static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32822+static const struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32823 .g_ctrl = mt9m001_g_ctrl,
32824 .s_ctrl = mt9m001_s_ctrl,
32825 .g_chip_ident = mt9m001_g_chip_ident,
32826@@ -714,7 +714,7 @@ static int mt9m001_enum_fmt(struct v4l2_
32827 return 0;
32828 }
32829
32830-static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32831+static const struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32832 .s_stream = mt9m001_s_stream,
32833 .s_mbus_fmt = mt9m001_s_fmt,
32834 .g_mbus_fmt = mt9m001_g_fmt,
32835@@ -725,7 +725,7 @@ static struct v4l2_subdev_video_ops mt9m
32836 .enum_mbus_fmt = mt9m001_enum_fmt,
32837 };
32838
32839-static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32840+static const struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32841 .g_skip_top_lines = mt9m001_g_skip_top_lines,
32842 };
32843
32844diff -urNp linux-2.6.39.1/drivers/media/video/mt9t031.c linux-2.6.39.1/drivers/media/video/mt9t031.c
32845--- linux-2.6.39.1/drivers/media/video/mt9t031.c 2011-05-19 00:06:34.000000000 -0400
32846+++ linux-2.6.39.1/drivers/media/video/mt9t031.c 2011-05-22 19:36:31.000000000 -0400
32847@@ -725,7 +725,7 @@ static int mt9t031_runtime_resume(struct
32848 return 0;
32849 }
32850
32851-static struct dev_pm_ops mt9t031_dev_pm_ops = {
32852+static const struct dev_pm_ops mt9t031_dev_pm_ops = {
32853 .runtime_suspend = mt9t031_runtime_suspend,
32854 .runtime_resume = mt9t031_runtime_resume,
32855 };
32856@@ -788,7 +788,7 @@ static int mt9t031_g_skip_top_lines(stru
32857 return 0;
32858 }
32859
32860-static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32861+static const struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32862 .g_ctrl = mt9t031_g_ctrl,
32863 .s_ctrl = mt9t031_s_ctrl,
32864 .g_chip_ident = mt9t031_g_chip_ident,
32865@@ -808,7 +808,7 @@ static int mt9t031_enum_fmt(struct v4l2_
32866 return 0;
32867 }
32868
32869-static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32870+static const struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32871 .s_stream = mt9t031_s_stream,
32872 .s_mbus_fmt = mt9t031_s_fmt,
32873 .g_mbus_fmt = mt9t031_g_fmt,
32874@@ -819,7 +819,7 @@ static struct v4l2_subdev_video_ops mt9t
32875 .enum_mbus_fmt = mt9t031_enum_fmt,
32876 };
32877
32878-static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32879+static const struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32880 .g_skip_top_lines = mt9t031_g_skip_top_lines,
32881 };
32882
32883diff -urNp linux-2.6.39.1/drivers/media/video/mt9v022.c linux-2.6.39.1/drivers/media/video/mt9v022.c
32884--- linux-2.6.39.1/drivers/media/video/mt9v022.c 2011-05-19 00:06:34.000000000 -0400
32885+++ linux-2.6.39.1/drivers/media/video/mt9v022.c 2011-05-22 19:36:31.000000000 -0400
32886@@ -825,7 +825,7 @@ static int mt9v022_g_skip_top_lines(stru
32887 return 0;
32888 }
32889
32890-static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32891+static const struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32892 .g_ctrl = mt9v022_g_ctrl,
32893 .s_ctrl = mt9v022_s_ctrl,
32894 .g_chip_ident = mt9v022_g_chip_ident,
32895@@ -848,7 +848,7 @@ static int mt9v022_enum_fmt(struct v4l2_
32896 return 0;
32897 }
32898
32899-static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32900+static const struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32901 .s_stream = mt9v022_s_stream,
32902 .s_mbus_fmt = mt9v022_s_fmt,
32903 .g_mbus_fmt = mt9v022_g_fmt,
32904@@ -859,7 +859,7 @@ static struct v4l2_subdev_video_ops mt9v
32905 .enum_mbus_fmt = mt9v022_enum_fmt,
32906 };
32907
32908-static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32909+static const struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32910 .g_skip_top_lines = mt9v022_g_skip_top_lines,
32911 };
32912
32913diff -urNp linux-2.6.39.1/drivers/media/video/mx2_camera.c linux-2.6.39.1/drivers/media/video/mx2_camera.c
32914--- linux-2.6.39.1/drivers/media/video/mx2_camera.c 2011-05-19 00:06:34.000000000 -0400
32915+++ linux-2.6.39.1/drivers/media/video/mx2_camera.c 2011-05-22 19:36:31.000000000 -0400
32916@@ -668,7 +668,7 @@ static void mx2_videobuf_release(struct
32917 free_buffer(vq, buf);
32918 }
32919
32920-static struct videobuf_queue_ops mx2_videobuf_ops = {
32921+static const struct videobuf_queue_ops mx2_videobuf_ops = {
32922 .buf_setup = mx2_videobuf_setup,
32923 .buf_prepare = mx2_videobuf_prepare,
32924 .buf_queue = mx2_videobuf_queue,
32925diff -urNp linux-2.6.39.1/drivers/media/video/omap24xxcam.c linux-2.6.39.1/drivers/media/video/omap24xxcam.c
32926--- linux-2.6.39.1/drivers/media/video/omap24xxcam.c 2011-05-19 00:06:34.000000000 -0400
32927+++ linux-2.6.39.1/drivers/media/video/omap24xxcam.c 2011-05-22 19:36:31.000000000 -0400
32928@@ -403,7 +403,7 @@ static void omap24xxcam_vbq_complete(str
32929 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32930
32931 do_gettimeofday(&vb->ts);
32932- vb->field_count = atomic_add_return(2, &fh->field_count);
32933+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32934 if (csr & csr_error) {
32935 vb->state = VIDEOBUF_ERROR;
32936 if (!atomic_read(&fh->cam->in_reset)) {
32937diff -urNp linux-2.6.39.1/drivers/media/video/omap24xxcam.h linux-2.6.39.1/drivers/media/video/omap24xxcam.h
32938--- linux-2.6.39.1/drivers/media/video/omap24xxcam.h 2011-05-19 00:06:34.000000000 -0400
32939+++ linux-2.6.39.1/drivers/media/video/omap24xxcam.h 2011-05-22 19:36:31.000000000 -0400
32940@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32941 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32942 struct videobuf_queue vbq;
32943 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32944- atomic_t field_count; /* field counter for videobuf_buffer */
32945+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32946 /* accessing cam here doesn't need serialisation: it's constant */
32947 struct omap24xxcam_device *cam;
32948 };
32949diff -urNp linux-2.6.39.1/drivers/media/video/omap3isp/isp.h linux-2.6.39.1/drivers/media/video/omap3isp/isp.h
32950--- linux-2.6.39.1/drivers/media/video/omap3isp/isp.h 2011-05-19 00:06:34.000000000 -0400
32951+++ linux-2.6.39.1/drivers/media/video/omap3isp/isp.h 2011-05-22 19:36:31.000000000 -0400
32952@@ -290,7 +290,7 @@ struct isp_device {
32953
32954 struct iommu *iommu;
32955
32956- struct isp_platform_callback platform_cb;
32957+ const struct isp_platform_callback platform_cb;
32958 };
32959
32960 #define v4l2_dev_to_isp_device(dev) \
32961diff -urNp linux-2.6.39.1/drivers/media/video/ov2640.c linux-2.6.39.1/drivers/media/video/ov2640.c
32962--- linux-2.6.39.1/drivers/media/video/ov2640.c 2011-05-19 00:06:34.000000000 -0400
32963+++ linux-2.6.39.1/drivers/media/video/ov2640.c 2011-05-22 19:36:31.000000000 -0400
32964@@ -1080,7 +1080,7 @@ static struct soc_camera_ops ov2640_ops
32965 .num_controls = ARRAY_SIZE(ov2640_controls),
32966 };
32967
32968-static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32969+static const struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32970 .g_ctrl = ov2640_g_ctrl,
32971 .s_ctrl = ov2640_s_ctrl,
32972 .g_chip_ident = ov2640_g_chip_ident,
32973@@ -1090,7 +1090,7 @@ static struct v4l2_subdev_core_ops ov264
32974 #endif
32975 };
32976
32977-static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32978+static const struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32979 .s_stream = ov2640_s_stream,
32980 .g_mbus_fmt = ov2640_g_fmt,
32981 .s_mbus_fmt = ov2640_s_fmt,
32982diff -urNp linux-2.6.39.1/drivers/media/video/ov772x.c linux-2.6.39.1/drivers/media/video/ov772x.c
32983--- linux-2.6.39.1/drivers/media/video/ov772x.c 2011-05-19 00:06:34.000000000 -0400
32984+++ linux-2.6.39.1/drivers/media/video/ov772x.c 2011-05-22 19:36:31.000000000 -0400
32985@@ -1079,7 +1079,7 @@ static struct soc_camera_ops ov772x_ops
32986 .num_controls = ARRAY_SIZE(ov772x_controls),
32987 };
32988
32989-static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32990+static const struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32991 .g_ctrl = ov772x_g_ctrl,
32992 .s_ctrl = ov772x_s_ctrl,
32993 .g_chip_ident = ov772x_g_chip_ident,
32994@@ -1099,7 +1099,7 @@ static int ov772x_enum_fmt(struct v4l2_s
32995 return 0;
32996 }
32997
32998-static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32999+static const struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
33000 .s_stream = ov772x_s_stream,
33001 .g_mbus_fmt = ov772x_g_fmt,
33002 .s_mbus_fmt = ov772x_s_fmt,
33003diff -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
33004--- linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-19 00:06:34.000000000 -0400
33005+++ linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-22 19:36:31.000000000 -0400
33006@@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
33007 u8 *eeprom;
33008 struct tveeprom tvdata;
33009
33010+ pax_track_stack();
33011+
33012 memset(&tvdata,0,sizeof(tvdata));
33013
33014 eeprom = pvr2_eeprom_fetch(hdw);
33015diff -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
33016--- linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-19 00:06:34.000000000 -0400
33017+++ linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-22 19:36:31.000000000 -0400
33018@@ -527,7 +527,7 @@ static u32 pvr2_i2c_functionality(struct
33019 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
33020 }
33021
33022-static struct i2c_algorithm pvr2_i2c_algo_template = {
33023+static const struct i2c_algorithm pvr2_i2c_algo_template = {
33024 .master_xfer = pvr2_i2c_xfer,
33025 .functionality = pvr2_i2c_functionality,
33026 };
33027diff -urNp linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c
33028--- linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c 2011-05-19 00:06:34.000000000 -0400
33029+++ linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c 2011-05-22 19:36:31.000000000 -0400
33030@@ -1327,7 +1327,7 @@ static int rj54n1_s_ctrl(struct v4l2_sub
33031 return 0;
33032 }
33033
33034-static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
33035+static const struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
33036 .g_ctrl = rj54n1_g_ctrl,
33037 .s_ctrl = rj54n1_s_ctrl,
33038 .g_chip_ident = rj54n1_g_chip_ident,
33039@@ -1337,7 +1337,7 @@ static struct v4l2_subdev_core_ops rj54n
33040 #endif
33041 };
33042
33043-static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
33044+static const struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
33045 .s_stream = rj54n1_s_stream,
33046 .s_mbus_fmt = rj54n1_s_fmt,
33047 .g_mbus_fmt = rj54n1_g_fmt,
33048diff -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
33049--- linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-19 00:06:34.000000000 -0400
33050+++ linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-22 19:36:31.000000000 -0400
33051@@ -376,7 +376,7 @@ static void fimc_unlock(struct vb2_queue
33052 mutex_unlock(&ctx->fimc_dev->lock);
33053 }
33054
33055-static struct vb2_ops fimc_capture_qops = {
33056+static const struct vb2_ops fimc_capture_qops = {
33057 .queue_setup = queue_setup,
33058 .buf_prepare = buffer_prepare,
33059 .buf_queue = buffer_queue,
33060diff -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
33061--- linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-19 00:06:34.000000000 -0400
33062+++ linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-22 19:36:31.000000000 -0400
33063@@ -768,7 +768,7 @@ static void fimc_unlock(struct vb2_queue
33064 mutex_unlock(&ctx->fimc_dev->lock);
33065 }
33066
33067-static struct vb2_ops fimc_qops = {
33068+static const struct vb2_ops fimc_qops = {
33069 .queue_setup = fimc_queue_setup,
33070 .buf_prepare = fimc_buf_prepare,
33071 .buf_queue = fimc_buf_queue,
33072diff -urNp linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c
33073--- linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c 2011-05-19 00:06:34.000000000 -0400
33074+++ linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c 2011-05-22 19:36:31.000000000 -0400
33075@@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_su
33076 unsigned char localPAT[256];
33077 unsigned char localPMT[256];
33078
33079+ pax_track_stack();
33080+
33081 /* Set video format - must be done first as it resets other settings */
33082 set_reg8(client, 0x41, h->video_format);
33083
33084diff -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
33085--- linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-19 00:06:34.000000000 -0400
33086+++ linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-22 19:36:31.000000000 -0400
33087@@ -808,7 +808,7 @@ static struct page *snd_card_saa7134_pag
33088 * ALSA capture callbacks definition
33089 */
33090
33091-static struct snd_pcm_ops snd_card_saa7134_capture_ops = {
33092+static const struct snd_pcm_ops snd_card_saa7134_capture_ops = {
33093 .open = snd_card_saa7134_capture_open,
33094 .close = snd_card_saa7134_capture_close,
33095 .ioctl = snd_pcm_lib_ioctl,
33096diff -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
33097--- linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-19 00:06:34.000000000 -0400
33098+++ linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-22 19:36:31.000000000 -0400
33099@@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_d
33100 u8 tmp[512];
33101 dprintk(DBGLVL_CMD, "%s()\n", __func__);
33102
33103+ pax_track_stack();
33104+
33105 /* While any outstand message on the bus exists... */
33106 do {
33107
33108@@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
33109 u8 tmp[512];
33110 dprintk(DBGLVL_CMD, "%s()\n", __func__);
33111
33112+ pax_track_stack();
33113+
33114 while (loop) {
33115
33116 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
33117diff -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
33118--- linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c 2011-05-19 00:06:34.000000000 -0400
33119+++ linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c 2011-05-22 19:36:31.000000000 -0400
33120@@ -127,12 +127,12 @@ static int sh_csi2_s_fmt(struct v4l2_sub
33121 return 0;
33122 }
33123
33124-static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
33125+static const struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
33126 .s_mbus_fmt = sh_csi2_s_fmt,
33127 .try_mbus_fmt = sh_csi2_try_fmt,
33128 };
33129
33130-static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
33131+static const struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
33132
33133 static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
33134 .core = &sh_csi2_subdev_core_ops,
33135diff -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
33136--- linux-2.6.39.1/drivers/media/video/soc_camera_platform.c 2011-05-19 00:06:34.000000000 -0400
33137+++ linux-2.6.39.1/drivers/media/video/soc_camera_platform.c 2011-05-22 19:36:31.000000000 -0400
33138@@ -70,7 +70,7 @@ static int soc_camera_platform_fill_fmt(
33139 return 0;
33140 }
33141
33142-static struct v4l2_subdev_core_ops platform_subdev_core_ops;
33143+static const struct v4l2_subdev_core_ops platform_subdev_core_ops;
33144
33145 static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
33146 enum v4l2_mbus_pixelcode *code)
33147@@ -115,7 +115,7 @@ static int soc_camera_platform_cropcap(s
33148 return 0;
33149 }
33150
33151-static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33152+static const struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33153 .s_stream = soc_camera_platform_s_stream,
33154 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
33155 .cropcap = soc_camera_platform_cropcap,
33156diff -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
33157--- linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c 2011-05-19 00:06:34.000000000 -0400
33158+++ linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c 2011-05-22 19:36:31.000000000 -0400
33159@@ -265,7 +265,7 @@ static struct page *snd_pcm_pd_get_page(
33160 return vmalloc_to_page(pageptr);
33161 }
33162
33163-static struct snd_pcm_ops pcm_capture_ops = {
33164+static const struct snd_pcm_ops pcm_capture_ops = {
33165 .open = snd_pd_capture_open,
33166 .close = snd_pd_pcm_close,
33167 .ioctl = snd_pcm_lib_ioctl,
33168diff -urNp linux-2.6.39.1/drivers/media/video/tw9910.c linux-2.6.39.1/drivers/media/video/tw9910.c
33169--- linux-2.6.39.1/drivers/media/video/tw9910.c 2011-05-19 00:06:34.000000000 -0400
33170+++ linux-2.6.39.1/drivers/media/video/tw9910.c 2011-05-22 19:36:31.000000000 -0400
33171@@ -894,7 +894,7 @@ static struct soc_camera_ops tw9910_ops
33172 .enum_input = tw9910_enum_input,
33173 };
33174
33175-static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33176+static const struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33177 .g_chip_ident = tw9910_g_chip_ident,
33178 .s_std = tw9910_s_std,
33179 #ifdef CONFIG_VIDEO_ADV_DEBUG
33180@@ -913,7 +913,7 @@ static int tw9910_enum_fmt(struct v4l2_s
33181 return 0;
33182 }
33183
33184-static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33185+static const struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33186 .s_stream = tw9910_s_stream,
33187 .g_mbus_fmt = tw9910_g_fmt,
33188 .s_mbus_fmt = tw9910_s_fmt,
33189diff -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
33190--- linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c 2011-05-19 00:06:34.000000000 -0400
33191+++ linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c 2011-05-22 19:36:31.000000000 -0400
33192@@ -799,6 +799,8 @@ static enum parse_state usbvision_parse_
33193 unsigned char rv, gv, bv;
33194 static unsigned char *Y, *U, *V;
33195
33196+ pax_track_stack();
33197+
33198 frame = usbvision->cur_frame;
33199 image_size = frame->frmwidth * frame->frmheight;
33200 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
33201diff -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
33202--- linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-19 00:06:34.000000000 -0400
33203+++ linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-22 19:36:31.000000000 -0400
33204@@ -189,7 +189,7 @@ static u32 functionality(struct i2c_adap
33205
33206 /* -----exported algorithm data: ------------------------------------- */
33207
33208-static struct i2c_algorithm usbvision_algo = {
33209+static const struct i2c_algorithm usbvision_algo = {
33210 .master_xfer = usbvision_i2c_xfer,
33211 .smbus_xfer = NULL,
33212 .functionality = functionality,
33213diff -urNp linux-2.6.39.1/drivers/media/video/v4l2-device.c linux-2.6.39.1/drivers/media/video/v4l2-device.c
33214--- linux-2.6.39.1/drivers/media/video/v4l2-device.c 2011-05-19 00:06:34.000000000 -0400
33215+++ linux-2.6.39.1/drivers/media/video/v4l2-device.c 2011-05-22 19:36:31.000000000 -0400
33216@@ -71,9 +71,9 @@ int v4l2_device_put(struct v4l2_device *
33217 EXPORT_SYMBOL_GPL(v4l2_device_put);
33218
33219 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
33220- atomic_t *instance)
33221+ atomic_unchecked_t *instance)
33222 {
33223- int num = atomic_inc_return(instance) - 1;
33224+ int num = atomic_inc_return_unchecked(instance) - 1;
33225 int len = strlen(basename);
33226
33227 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33228diff -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
33229--- linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c 2011-05-19 00:06:34.000000000 -0400
33230+++ linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c 2011-05-22 19:36:31.000000000 -0400
33231@@ -606,6 +606,8 @@ void *videobuf_sg_alloc(size_t size)
33232 {
33233 struct videobuf_queue q;
33234
33235+ pax_track_stack();
33236+
33237 /* Required to make generic handler to call __videobuf_alloc */
33238 q.int_ops = &sg_ops;
33239
33240diff -urNp linux-2.6.39.1/drivers/message/fusion/mptbase.c linux-2.6.39.1/drivers/message/fusion/mptbase.c
33241--- linux-2.6.39.1/drivers/message/fusion/mptbase.c 2011-05-19 00:06:34.000000000 -0400
33242+++ linux-2.6.39.1/drivers/message/fusion/mptbase.c 2011-05-22 19:41:37.000000000 -0400
33243@@ -143,7 +143,7 @@ static int MptDriverClass[MPT_MAX_PRO
33244 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33245 /* Reset handler lookup table */
33246 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33247-static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33248+static const struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33249
33250 #ifdef CONFIG_PROC_FS
33251 static struct proc_dir_entry *mpt_proc_root_dir;
33252@@ -772,7 +772,7 @@ mpt_reset_deregister(u8 cb_idx)
33253 * @cb_idx: MPT protocol driver index
33254 */
33255 int
33256-mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33257+mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33258 {
33259 MPT_ADAPTER *ioc;
33260 const struct pci_device_id *id;
33261@@ -801,7 +801,7 @@ mpt_device_driver_register(struct mpt_pc
33262 void
33263 mpt_device_driver_deregister(u8 cb_idx)
33264 {
33265- struct mpt_pci_driver *dd_cbfunc;
33266+ const struct mpt_pci_driver *dd_cbfunc;
33267 MPT_ADAPTER *ioc;
33268
33269 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
33270@@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
33271 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33272 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33273
33274+#ifdef CONFIG_GRKERNSEC_HIDESYM
33275+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33276+#else
33277 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33278 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33279+#endif
33280+
33281 /*
33282 * Rounding UP to nearest 4-kB boundary here...
33283 */
33284diff -urNp linux-2.6.39.1/drivers/message/fusion/mptbase.h linux-2.6.39.1/drivers/message/fusion/mptbase.h
33285--- linux-2.6.39.1/drivers/message/fusion/mptbase.h 2011-05-19 00:06:34.000000000 -0400
33286+++ linux-2.6.39.1/drivers/message/fusion/mptbase.h 2011-05-22 19:36:31.000000000 -0400
33287@@ -908,7 +908,7 @@ extern int mpt_event_register(u8 cb_idx
33288 extern void mpt_event_deregister(u8 cb_idx);
33289 extern int mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func);
33290 extern void mpt_reset_deregister(u8 cb_idx);
33291-extern int mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33292+extern int mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33293 extern void mpt_device_driver_deregister(u8 cb_idx);
33294 extern MPT_FRAME_HDR *mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc);
33295 extern void mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
33296diff -urNp linux-2.6.39.1/drivers/message/fusion/mptctl.c linux-2.6.39.1/drivers/message/fusion/mptctl.c
33297--- linux-2.6.39.1/drivers/message/fusion/mptctl.c 2011-05-19 00:06:34.000000000 -0400
33298+++ linux-2.6.39.1/drivers/message/fusion/mptctl.c 2011-05-22 19:36:31.000000000 -0400
33299@@ -3000,7 +3000,7 @@ mptctl_remove(struct pci_dev *pdev)
33300 {
33301 }
33302
33303-static struct mpt_pci_driver mptctl_driver = {
33304+static const struct mpt_pci_driver mptctl_driver = {
33305 .probe = mptctl_probe,
33306 .remove = mptctl_remove,
33307 };
33308diff -urNp linux-2.6.39.1/drivers/message/fusion/mptsas.c linux-2.6.39.1/drivers/message/fusion/mptsas.c
33309--- linux-2.6.39.1/drivers/message/fusion/mptsas.c 2011-05-19 00:06:34.000000000 -0400
33310+++ linux-2.6.39.1/drivers/message/fusion/mptsas.c 2011-05-22 19:36:31.000000000 -0400
33311@@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
33312 return 0;
33313 }
33314
33315+static inline void
33316+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33317+{
33318+ if (phy_info->port_details) {
33319+ phy_info->port_details->rphy = rphy;
33320+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33321+ ioc->name, rphy));
33322+ }
33323+
33324+ if (rphy) {
33325+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33326+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33327+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33328+ ioc->name, rphy, rphy->dev.release));
33329+ }
33330+}
33331+
33332 /* no mutex */
33333 static void
33334 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33335@@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33336 return NULL;
33337 }
33338
33339-static inline void
33340-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33341-{
33342- if (phy_info->port_details) {
33343- phy_info->port_details->rphy = rphy;
33344- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33345- ioc->name, rphy));
33346- }
33347-
33348- if (rphy) {
33349- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33350- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33351- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33352- ioc->name, rphy, rphy->dev.release));
33353- }
33354-}
33355-
33356 static inline struct sas_port *
33357 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33358 {
33359diff -urNp linux-2.6.39.1/drivers/message/fusion/mptscsih.c linux-2.6.39.1/drivers/message/fusion/mptscsih.c
33360--- linux-2.6.39.1/drivers/message/fusion/mptscsih.c 2011-05-19 00:06:34.000000000 -0400
33361+++ linux-2.6.39.1/drivers/message/fusion/mptscsih.c 2011-05-22 19:36:31.000000000 -0400
33362@@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33363
33364 h = shost_priv(SChost);
33365
33366- if (h) {
33367- if (h->info_kbuf == NULL)
33368- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33369- return h->info_kbuf;
33370- h->info_kbuf[0] = '\0';
33371+ if (!h)
33372+ return NULL;
33373
33374- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33375- h->info_kbuf[size-1] = '\0';
33376- }
33377+ if (h->info_kbuf == NULL)
33378+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33379+ return h->info_kbuf;
33380+ h->info_kbuf[0] = '\0';
33381+
33382+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33383+ h->info_kbuf[size-1] = '\0';
33384
33385 return h->info_kbuf;
33386 }
33387diff -urNp linux-2.6.39.1/drivers/message/i2o/i2o_config.c linux-2.6.39.1/drivers/message/i2o/i2o_config.c
33388--- linux-2.6.39.1/drivers/message/i2o/i2o_config.c 2011-05-19 00:06:34.000000000 -0400
33389+++ linux-2.6.39.1/drivers/message/i2o/i2o_config.c 2011-05-22 19:36:31.000000000 -0400
33390@@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned lon
33391 struct i2o_message *msg;
33392 unsigned int iop;
33393
33394+ pax_track_stack();
33395+
33396 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
33397 return -EFAULT;
33398
33399diff -urNp linux-2.6.39.1/drivers/message/i2o/i2o_proc.c linux-2.6.39.1/drivers/message/i2o/i2o_proc.c
33400--- linux-2.6.39.1/drivers/message/i2o/i2o_proc.c 2011-05-19 00:06:34.000000000 -0400
33401+++ linux-2.6.39.1/drivers/message/i2o/i2o_proc.c 2011-05-22 19:36:31.000000000 -0400
33402@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33403 "Array Controller Device"
33404 };
33405
33406-static char *chtostr(u8 * chars, int n)
33407-{
33408- char tmp[256];
33409- tmp[0] = 0;
33410- return strncat(tmp, (char *)chars, n);
33411-}
33412-
33413 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33414 char *group)
33415 {
33416@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
33417
33418 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33419 seq_printf(seq, "%-#8x", ddm_table.module_id);
33420- seq_printf(seq, "%-29s",
33421- chtostr(ddm_table.module_name_version, 28));
33422+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33423 seq_printf(seq, "%9d ", ddm_table.data_size);
33424 seq_printf(seq, "%8d", ddm_table.code_size);
33425
33426@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
33427
33428 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33429 seq_printf(seq, "%-#8x", dst->module_id);
33430- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33431- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33432+ seq_printf(seq, "%-.28s", dst->module_name_version);
33433+ seq_printf(seq, "%-.8s", dst->date);
33434 seq_printf(seq, "%8d ", dst->module_size);
33435 seq_printf(seq, "%8d ", dst->mpb_size);
33436 seq_printf(seq, "0x%04x", dst->module_flags);
33437@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
33438 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33439 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33440 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33441- seq_printf(seq, "Vendor info : %s\n",
33442- chtostr((u8 *) (work32 + 2), 16));
33443- seq_printf(seq, "Product info : %s\n",
33444- chtostr((u8 *) (work32 + 6), 16));
33445- seq_printf(seq, "Description : %s\n",
33446- chtostr((u8 *) (work32 + 10), 16));
33447- seq_printf(seq, "Product rev. : %s\n",
33448- chtostr((u8 *) (work32 + 14), 8));
33449+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33450+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33451+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33452+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33453
33454 seq_printf(seq, "Serial number : ");
33455 print_serial_number(seq, (u8 *) (work32 + 16),
33456@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
33457 }
33458
33459 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33460- seq_printf(seq, "Module name : %s\n",
33461- chtostr(result.module_name, 24));
33462- seq_printf(seq, "Module revision : %s\n",
33463- chtostr(result.module_rev, 8));
33464+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33465+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33466
33467 seq_printf(seq, "Serial number : ");
33468 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33469@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
33470 return 0;
33471 }
33472
33473- seq_printf(seq, "Device name : %s\n",
33474- chtostr(result.device_name, 64));
33475- seq_printf(seq, "Service name : %s\n",
33476- chtostr(result.service_name, 64));
33477- seq_printf(seq, "Physical name : %s\n",
33478- chtostr(result.physical_location, 64));
33479- seq_printf(seq, "Instance number : %s\n",
33480- chtostr(result.instance_number, 4));
33481+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
33482+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
33483+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33484+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33485
33486 return 0;
33487 }
33488diff -urNp linux-2.6.39.1/drivers/message/i2o/iop.c linux-2.6.39.1/drivers/message/i2o/iop.c
33489--- linux-2.6.39.1/drivers/message/i2o/iop.c 2011-05-19 00:06:34.000000000 -0400
33490+++ linux-2.6.39.1/drivers/message/i2o/iop.c 2011-05-22 19:36:31.000000000 -0400
33491@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
33492
33493 spin_lock_irqsave(&c->context_list_lock, flags);
33494
33495- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33496- atomic_inc(&c->context_list_counter);
33497+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33498+ atomic_inc_unchecked(&c->context_list_counter);
33499
33500- entry->context = atomic_read(&c->context_list_counter);
33501+ entry->context = atomic_read_unchecked(&c->context_list_counter);
33502
33503 list_add(&entry->list, &c->context_list);
33504
33505@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(voi
33506
33507 #if BITS_PER_LONG == 64
33508 spin_lock_init(&c->context_list_lock);
33509- atomic_set(&c->context_list_counter, 0);
33510+ atomic_set_unchecked(&c->context_list_counter, 0);
33511 INIT_LIST_HEAD(&c->context_list);
33512 #endif
33513
33514diff -urNp linux-2.6.39.1/drivers/mfd/ab3100-core.c linux-2.6.39.1/drivers/mfd/ab3100-core.c
33515--- linux-2.6.39.1/drivers/mfd/ab3100-core.c 2011-05-19 00:06:34.000000000 -0400
33516+++ linux-2.6.39.1/drivers/mfd/ab3100-core.c 2011-05-22 19:36:31.000000000 -0400
33517@@ -385,7 +385,7 @@ static int ab3100_event_registers_startu
33518 return 0;
33519 }
33520
33521-static struct abx500_ops ab3100_ops = {
33522+static const struct abx500_ops ab3100_ops = {
33523 .get_chip_id = ab3100_get_chip_id,
33524 .set_register = set_register_interruptible,
33525 .get_register = get_register_interruptible,
33526diff -urNp linux-2.6.39.1/drivers/mfd/ab3550-core.c linux-2.6.39.1/drivers/mfd/ab3550-core.c
33527--- linux-2.6.39.1/drivers/mfd/ab3550-core.c 2011-05-19 00:06:34.000000000 -0400
33528+++ linux-2.6.39.1/drivers/mfd/ab3550-core.c 2011-05-22 19:36:31.000000000 -0400
33529@@ -676,7 +676,7 @@ static int ab3550_startup_irq_enabled(st
33530 return val;
33531 }
33532
33533-static struct abx500_ops ab3550_ops = {
33534+static const struct abx500_ops ab3550_ops = {
33535 .get_chip_id = ab3550_get_chip_id,
33536 .get_register = ab3550_get_register_interruptible,
33537 .set_register = ab3550_set_register_interruptible,
33538diff -urNp linux-2.6.39.1/drivers/mfd/ab8500-core.c linux-2.6.39.1/drivers/mfd/ab8500-core.c
33539--- linux-2.6.39.1/drivers/mfd/ab8500-core.c 2011-05-19 00:06:34.000000000 -0400
33540+++ linux-2.6.39.1/drivers/mfd/ab8500-core.c 2011-05-22 19:36:31.000000000 -0400
33541@@ -223,7 +223,7 @@ static int ab8500_mask_and_set_register(
33542
33543 }
33544
33545-static struct abx500_ops ab8500_ops = {
33546+static const struct abx500_ops ab8500_ops = {
33547 .get_chip_id = ab8500_get_chip_id,
33548 .get_register = ab8500_get_register,
33549 .set_register = ab8500_set_register,
33550diff -urNp linux-2.6.39.1/drivers/mfd/abx500-core.c linux-2.6.39.1/drivers/mfd/abx500-core.c
33551--- linux-2.6.39.1/drivers/mfd/abx500-core.c 2011-05-19 00:06:34.000000000 -0400
33552+++ linux-2.6.39.1/drivers/mfd/abx500-core.c 2011-05-22 19:36:31.000000000 -0400
33553@@ -18,7 +18,7 @@ struct abx500_device_entry {
33554 struct device *dev;
33555 };
33556
33557-static void lookup_ops(struct device *dev, struct abx500_ops **ops)
33558+static void lookup_ops(struct device *dev, const struct abx500_ops **ops)
33559 {
33560 struct abx500_device_entry *dev_entry;
33561
33562@@ -31,7 +31,7 @@ static void lookup_ops(struct device *de
33563 }
33564 }
33565
33566-int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
33567+int abx500_register_ops(struct device *dev, const struct abx500_ops *ops)
33568 {
33569 struct abx500_device_entry *dev_entry;
33570
33571@@ -65,7 +65,7 @@ EXPORT_SYMBOL(abx500_remove_ops);
33572 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
33573 u8 value)
33574 {
33575- struct abx500_ops *ops;
33576+ const struct abx500_ops *ops;
33577
33578 lookup_ops(dev->parent, &ops);
33579 if ((ops != NULL) && (ops->set_register != NULL))
33580@@ -78,7 +78,7 @@ EXPORT_SYMBOL(abx500_set_register_interr
33581 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
33582 u8 *value)
33583 {
33584- struct abx500_ops *ops;
33585+ const struct abx500_ops *ops;
33586
33587 lookup_ops(dev->parent, &ops);
33588 if ((ops != NULL) && (ops->get_register != NULL))
33589@@ -91,7 +91,7 @@ EXPORT_SYMBOL(abx500_get_register_interr
33590 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
33591 u8 first_reg, u8 *regvals, u8 numregs)
33592 {
33593- struct abx500_ops *ops;
33594+ const struct abx500_ops *ops;
33595
33596 lookup_ops(dev->parent, &ops);
33597 if ((ops != NULL) && (ops->get_register_page != NULL))
33598@@ -105,7 +105,7 @@ EXPORT_SYMBOL(abx500_get_register_page_i
33599 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
33600 u8 reg, u8 bitmask, u8 bitvalues)
33601 {
33602- struct abx500_ops *ops;
33603+ const struct abx500_ops *ops;
33604
33605 lookup_ops(dev->parent, &ops);
33606 if ((ops != NULL) && (ops->mask_and_set_register != NULL))
33607@@ -118,7 +118,7 @@ EXPORT_SYMBOL(abx500_mask_and_set_regist
33608
33609 int abx500_get_chip_id(struct device *dev)
33610 {
33611- struct abx500_ops *ops;
33612+ const struct abx500_ops *ops;
33613
33614 lookup_ops(dev->parent, &ops);
33615 if ((ops != NULL) && (ops->get_chip_id != NULL))
33616@@ -130,7 +130,7 @@ EXPORT_SYMBOL(abx500_get_chip_id);
33617
33618 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
33619 {
33620- struct abx500_ops *ops;
33621+ const struct abx500_ops *ops;
33622
33623 lookup_ops(dev->parent, &ops);
33624 if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
33625@@ -142,7 +142,7 @@ EXPORT_SYMBOL(abx500_event_registers_sta
33626
33627 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
33628 {
33629- struct abx500_ops *ops;
33630+ const struct abx500_ops *ops;
33631
33632 lookup_ops(dev->parent, &ops);
33633 if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
33634diff -urNp linux-2.6.39.1/drivers/mfd/janz-cmodio.c linux-2.6.39.1/drivers/mfd/janz-cmodio.c
33635--- linux-2.6.39.1/drivers/mfd/janz-cmodio.c 2011-05-19 00:06:34.000000000 -0400
33636+++ linux-2.6.39.1/drivers/mfd/janz-cmodio.c 2011-05-22 19:36:31.000000000 -0400
33637@@ -13,6 +13,7 @@
33638
33639 #include <linux/kernel.h>
33640 #include <linux/module.h>
33641+#include <linux/slab.h>
33642 #include <linux/init.h>
33643 #include <linux/pci.h>
33644 #include <linux/interrupt.h>
33645diff -urNp linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c
33646--- linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c 2011-05-19 00:06:34.000000000 -0400
33647+++ linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c 2011-05-22 19:36:31.000000000 -0400
33648@@ -128,7 +128,7 @@ static void mcp_sa11x0_disable(struct mc
33649 /*
33650 * Our methods.
33651 */
33652-static struct mcp_ops mcp_sa11x0 = {
33653+static const struct mcp_ops mcp_sa11x0 = {
33654 .set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
33655 .set_audio_divisor = mcp_sa11x0_set_audio_divisor,
33656 .reg_write = mcp_sa11x0_write,
33657diff -urNp linux-2.6.39.1/drivers/mfd/wm8350-i2c.c linux-2.6.39.1/drivers/mfd/wm8350-i2c.c
33658--- linux-2.6.39.1/drivers/mfd/wm8350-i2c.c 2011-05-19 00:06:34.000000000 -0400
33659+++ linux-2.6.39.1/drivers/mfd/wm8350-i2c.c 2011-05-22 19:36:31.000000000 -0400
33660@@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struc
33661 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
33662 int ret;
33663
33664+ pax_track_stack();
33665+
33666 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
33667 return -EINVAL;
33668
33669diff -urNp linux-2.6.39.1/drivers/misc/enclosure.c linux-2.6.39.1/drivers/misc/enclosure.c
33670--- linux-2.6.39.1/drivers/misc/enclosure.c 2011-05-19 00:06:34.000000000 -0400
33671+++ linux-2.6.39.1/drivers/misc/enclosure.c 2011-05-22 19:36:31.000000000 -0400
33672@@ -161,7 +161,7 @@ enclosure_register(struct device *dev, c
33673 }
33674 EXPORT_SYMBOL_GPL(enclosure_register);
33675
33676-static struct enclosure_component_callbacks enclosure_null_callbacks;
33677+static const struct enclosure_component_callbacks enclosure_null_callbacks;
33678
33679 /**
33680 * enclosure_unregister - remove an enclosure
33681diff -urNp linux-2.6.39.1/drivers/misc/kgdbts.c linux-2.6.39.1/drivers/misc/kgdbts.c
33682--- linux-2.6.39.1/drivers/misc/kgdbts.c 2011-05-19 00:06:34.000000000 -0400
33683+++ linux-2.6.39.1/drivers/misc/kgdbts.c 2011-05-22 19:36:31.000000000 -0400
33684@@ -118,7 +118,7 @@
33685 } while (0)
33686 #define MAX_CONFIG_LEN 40
33687
33688-static struct kgdb_io kgdbts_io_ops;
33689+static const struct kgdb_io kgdbts_io_ops;
33690 static char get_buf[BUFMAX];
33691 static int get_buf_cnt;
33692 static char put_buf[BUFMAX];
33693@@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
33694 module_put(THIS_MODULE);
33695 }
33696
33697-static struct kgdb_io kgdbts_io_ops = {
33698+static const struct kgdb_io kgdbts_io_ops = {
33699 .name = "kgdbts",
33700 .read_char = kgdbts_get_char,
33701 .write_char = kgdbts_put_char,
33702diff -urNp linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c
33703--- linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-19 00:06:34.000000000 -0400
33704+++ linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-22 19:36:31.000000000 -0400
33705@@ -435,7 +435,7 @@ static irqreturn_t lis302dl_interrupt(in
33706 * the lid is closed. This leads to interrupts as soon as a little move
33707 * is done.
33708 */
33709- atomic_inc(&lis3_dev.count);
33710+ atomic_inc_unchecked(&lis3_dev.count);
33711
33712 wake_up_interruptible(&lis3_dev.misc_wait);
33713 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33714@@ -518,7 +518,7 @@ static int lis3lv02d_misc_open(struct in
33715 if (lis3_dev.pm_dev)
33716 pm_runtime_get_sync(lis3_dev.pm_dev);
33717
33718- atomic_set(&lis3_dev.count, 0);
33719+ atomic_set_unchecked(&lis3_dev.count, 0);
33720 return 0;
33721 }
33722
33723@@ -545,7 +545,7 @@ static ssize_t lis3lv02d_misc_read(struc
33724 add_wait_queue(&lis3_dev.misc_wait, &wait);
33725 while (true) {
33726 set_current_state(TASK_INTERRUPTIBLE);
33727- data = atomic_xchg(&lis3_dev.count, 0);
33728+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33729 if (data)
33730 break;
33731
33732@@ -583,7 +583,7 @@ out:
33733 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33734 {
33735 poll_wait(file, &lis3_dev.misc_wait, wait);
33736- if (atomic_read(&lis3_dev.count))
33737+ if (atomic_read_unchecked(&lis3_dev.count))
33738 return POLLIN | POLLRDNORM;
33739 return 0;
33740 }
33741diff -urNp linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h
33742--- linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-19 00:06:34.000000000 -0400
33743+++ linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-22 19:36:31.000000000 -0400
33744@@ -265,7 +265,7 @@ struct lis3lv02d {
33745 struct input_polled_dev *idev; /* input device */
33746 struct platform_device *pdev; /* platform device */
33747 struct regulator_bulk_data regulators[2];
33748- atomic_t count; /* interrupt count after last read */
33749+ atomic_unchecked_t count; /* interrupt count after last read */
33750 union axis_conversion ac; /* hw -> logical axis */
33751 int mapped_btns[3];
33752
33753diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c
33754--- linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c 2011-05-19 00:06:34.000000000 -0400
33755+++ linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c 2011-05-22 19:36:31.000000000 -0400
33756@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
33757 unsigned long nsec;
33758
33759 nsec = CLKS2NSEC(clks);
33760- atomic_long_inc(&mcs_op_statistics[op].count);
33761- atomic_long_add(nsec, &mcs_op_statistics[op].total);
33762+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33763+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33764 if (mcs_op_statistics[op].max < nsec)
33765 mcs_op_statistics[op].max = nsec;
33766 }
33767diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c
33768--- linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c 2011-05-19 00:06:34.000000000 -0400
33769+++ linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c 2011-05-22 19:36:31.000000000 -0400
33770@@ -32,9 +32,9 @@
33771
33772 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33773
33774-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33775+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33776 {
33777- unsigned long val = atomic_long_read(v);
33778+ unsigned long val = atomic_long_read_unchecked(v);
33779
33780 seq_printf(s, "%16lu %s\n", val, id);
33781 }
33782@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
33783
33784 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33785 for (op = 0; op < mcsop_last; op++) {
33786- count = atomic_long_read(&mcs_op_statistics[op].count);
33787- total = atomic_long_read(&mcs_op_statistics[op].total);
33788+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33789+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33790 max = mcs_op_statistics[op].max;
33791 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33792 count ? total / count : 0, max);
33793diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h
33794--- linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h 2011-05-19 00:06:34.000000000 -0400
33795+++ linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h 2011-05-22 19:36:31.000000000 -0400
33796@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33797 * GRU statistics.
33798 */
33799 struct gru_stats_s {
33800- atomic_long_t vdata_alloc;
33801- atomic_long_t vdata_free;
33802- atomic_long_t gts_alloc;
33803- atomic_long_t gts_free;
33804- atomic_long_t gms_alloc;
33805- atomic_long_t gms_free;
33806- atomic_long_t gts_double_allocate;
33807- atomic_long_t assign_context;
33808- atomic_long_t assign_context_failed;
33809- atomic_long_t free_context;
33810- atomic_long_t load_user_context;
33811- atomic_long_t load_kernel_context;
33812- atomic_long_t lock_kernel_context;
33813- atomic_long_t unlock_kernel_context;
33814- atomic_long_t steal_user_context;
33815- atomic_long_t steal_kernel_context;
33816- atomic_long_t steal_context_failed;
33817- atomic_long_t nopfn;
33818- atomic_long_t asid_new;
33819- atomic_long_t asid_next;
33820- atomic_long_t asid_wrap;
33821- atomic_long_t asid_reuse;
33822- atomic_long_t intr;
33823- atomic_long_t intr_cbr;
33824- atomic_long_t intr_tfh;
33825- atomic_long_t intr_spurious;
33826- atomic_long_t intr_mm_lock_failed;
33827- atomic_long_t call_os;
33828- atomic_long_t call_os_wait_queue;
33829- atomic_long_t user_flush_tlb;
33830- atomic_long_t user_unload_context;
33831- atomic_long_t user_exception;
33832- atomic_long_t set_context_option;
33833- atomic_long_t check_context_retarget_intr;
33834- atomic_long_t check_context_unload;
33835- atomic_long_t tlb_dropin;
33836- atomic_long_t tlb_preload_page;
33837- atomic_long_t tlb_dropin_fail_no_asid;
33838- atomic_long_t tlb_dropin_fail_upm;
33839- atomic_long_t tlb_dropin_fail_invalid;
33840- atomic_long_t tlb_dropin_fail_range_active;
33841- atomic_long_t tlb_dropin_fail_idle;
33842- atomic_long_t tlb_dropin_fail_fmm;
33843- atomic_long_t tlb_dropin_fail_no_exception;
33844- atomic_long_t tfh_stale_on_fault;
33845- atomic_long_t mmu_invalidate_range;
33846- atomic_long_t mmu_invalidate_page;
33847- atomic_long_t flush_tlb;
33848- atomic_long_t flush_tlb_gru;
33849- atomic_long_t flush_tlb_gru_tgh;
33850- atomic_long_t flush_tlb_gru_zero_asid;
33851-
33852- atomic_long_t copy_gpa;
33853- atomic_long_t read_gpa;
33854-
33855- atomic_long_t mesq_receive;
33856- atomic_long_t mesq_receive_none;
33857- atomic_long_t mesq_send;
33858- atomic_long_t mesq_send_failed;
33859- atomic_long_t mesq_noop;
33860- atomic_long_t mesq_send_unexpected_error;
33861- atomic_long_t mesq_send_lb_overflow;
33862- atomic_long_t mesq_send_qlimit_reached;
33863- atomic_long_t mesq_send_amo_nacked;
33864- atomic_long_t mesq_send_put_nacked;
33865- atomic_long_t mesq_page_overflow;
33866- atomic_long_t mesq_qf_locked;
33867- atomic_long_t mesq_qf_noop_not_full;
33868- atomic_long_t mesq_qf_switch_head_failed;
33869- atomic_long_t mesq_qf_unexpected_error;
33870- atomic_long_t mesq_noop_unexpected_error;
33871- atomic_long_t mesq_noop_lb_overflow;
33872- atomic_long_t mesq_noop_qlimit_reached;
33873- atomic_long_t mesq_noop_amo_nacked;
33874- atomic_long_t mesq_noop_put_nacked;
33875- atomic_long_t mesq_noop_page_overflow;
33876+ atomic_long_unchecked_t vdata_alloc;
33877+ atomic_long_unchecked_t vdata_free;
33878+ atomic_long_unchecked_t gts_alloc;
33879+ atomic_long_unchecked_t gts_free;
33880+ atomic_long_unchecked_t gms_alloc;
33881+ atomic_long_unchecked_t gms_free;
33882+ atomic_long_unchecked_t gts_double_allocate;
33883+ atomic_long_unchecked_t assign_context;
33884+ atomic_long_unchecked_t assign_context_failed;
33885+ atomic_long_unchecked_t free_context;
33886+ atomic_long_unchecked_t load_user_context;
33887+ atomic_long_unchecked_t load_kernel_context;
33888+ atomic_long_unchecked_t lock_kernel_context;
33889+ atomic_long_unchecked_t unlock_kernel_context;
33890+ atomic_long_unchecked_t steal_user_context;
33891+ atomic_long_unchecked_t steal_kernel_context;
33892+ atomic_long_unchecked_t steal_context_failed;
33893+ atomic_long_unchecked_t nopfn;
33894+ atomic_long_unchecked_t asid_new;
33895+ atomic_long_unchecked_t asid_next;
33896+ atomic_long_unchecked_t asid_wrap;
33897+ atomic_long_unchecked_t asid_reuse;
33898+ atomic_long_unchecked_t intr;
33899+ atomic_long_unchecked_t intr_cbr;
33900+ atomic_long_unchecked_t intr_tfh;
33901+ atomic_long_unchecked_t intr_spurious;
33902+ atomic_long_unchecked_t intr_mm_lock_failed;
33903+ atomic_long_unchecked_t call_os;
33904+ atomic_long_unchecked_t call_os_wait_queue;
33905+ atomic_long_unchecked_t user_flush_tlb;
33906+ atomic_long_unchecked_t user_unload_context;
33907+ atomic_long_unchecked_t user_exception;
33908+ atomic_long_unchecked_t set_context_option;
33909+ atomic_long_unchecked_t check_context_retarget_intr;
33910+ atomic_long_unchecked_t check_context_unload;
33911+ atomic_long_unchecked_t tlb_dropin;
33912+ atomic_long_unchecked_t tlb_preload_page;
33913+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33914+ atomic_long_unchecked_t tlb_dropin_fail_upm;
33915+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
33916+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
33917+ atomic_long_unchecked_t tlb_dropin_fail_idle;
33918+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
33919+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33920+ atomic_long_unchecked_t tfh_stale_on_fault;
33921+ atomic_long_unchecked_t mmu_invalidate_range;
33922+ atomic_long_unchecked_t mmu_invalidate_page;
33923+ atomic_long_unchecked_t flush_tlb;
33924+ atomic_long_unchecked_t flush_tlb_gru;
33925+ atomic_long_unchecked_t flush_tlb_gru_tgh;
33926+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33927+
33928+ atomic_long_unchecked_t copy_gpa;
33929+ atomic_long_unchecked_t read_gpa;
33930+
33931+ atomic_long_unchecked_t mesq_receive;
33932+ atomic_long_unchecked_t mesq_receive_none;
33933+ atomic_long_unchecked_t mesq_send;
33934+ atomic_long_unchecked_t mesq_send_failed;
33935+ atomic_long_unchecked_t mesq_noop;
33936+ atomic_long_unchecked_t mesq_send_unexpected_error;
33937+ atomic_long_unchecked_t mesq_send_lb_overflow;
33938+ atomic_long_unchecked_t mesq_send_qlimit_reached;
33939+ atomic_long_unchecked_t mesq_send_amo_nacked;
33940+ atomic_long_unchecked_t mesq_send_put_nacked;
33941+ atomic_long_unchecked_t mesq_page_overflow;
33942+ atomic_long_unchecked_t mesq_qf_locked;
33943+ atomic_long_unchecked_t mesq_qf_noop_not_full;
33944+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
33945+ atomic_long_unchecked_t mesq_qf_unexpected_error;
33946+ atomic_long_unchecked_t mesq_noop_unexpected_error;
33947+ atomic_long_unchecked_t mesq_noop_lb_overflow;
33948+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
33949+ atomic_long_unchecked_t mesq_noop_amo_nacked;
33950+ atomic_long_unchecked_t mesq_noop_put_nacked;
33951+ atomic_long_unchecked_t mesq_noop_page_overflow;
33952
33953 };
33954
33955@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
33956 tghop_invalidate, mcsop_last};
33957
33958 struct mcs_op_statistic {
33959- atomic_long_t count;
33960- atomic_long_t total;
33961+ atomic_long_unchecked_t count;
33962+ atomic_long_unchecked_t total;
33963 unsigned long max;
33964 };
33965
33966@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
33967
33968 #define STAT(id) do { \
33969 if (gru_options & OPT_STATS) \
33970- atomic_long_inc(&gru_stats.id); \
33971+ atomic_long_inc_unchecked(&gru_stats.id); \
33972 } while (0)
33973
33974 #ifdef CONFIG_SGI_GRU_DEBUG
33975diff -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
33976--- linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-19 00:06:34.000000000 -0400
33977+++ linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-22 19:36:31.000000000 -0400
33978@@ -2351,7 +2351,7 @@ xpc_received_payload_sn2(struct xpc_chan
33979 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33980 }
33981
33982-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33983+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33984 .setup_partitions = xpc_setup_partitions_sn2,
33985 .teardown_partitions = xpc_teardown_partitions_sn2,
33986 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33987diff -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
33988--- linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c 2011-05-19 00:06:34.000000000 -0400
33989+++ linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c 2011-05-22 19:36:31.000000000 -0400
33990@@ -1674,7 +1674,7 @@ xpc_received_payload_uv(struct xpc_chann
33991 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33992 }
33993
33994-static struct xpc_arch_operations xpc_arch_ops_uv = {
33995+static const struct xpc_arch_operations xpc_arch_ops_uv = {
33996 .setup_partitions = xpc_setup_partitions_uv,
33997 .teardown_partitions = xpc_teardown_partitions_uv,
33998 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33999diff -urNp linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c
34000--- linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c 2011-05-19 00:06:34.000000000 -0400
34001+++ linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c 2011-05-22 19:36:31.000000000 -0400
34002@@ -644,7 +644,7 @@ static ssize_t pcie_gadget_target_attr_s
34003 return ret;
34004 }
34005
34006-static struct configfs_item_operations pcie_gadget_target_item_ops = {
34007+static const struct configfs_item_operations pcie_gadget_target_item_ops = {
34008 .show_attribute = pcie_gadget_target_attr_show,
34009 .store_attribute = pcie_gadget_target_attr_store,
34010 };
34011diff -urNp linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c
34012--- linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c 2011-05-19 00:06:34.000000000 -0400
34013+++ linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c 2011-05-22 19:36:31.000000000 -0400
34014@@ -1133,7 +1133,7 @@ static void mmc_davinci_enable_sdio_irq(
34015 }
34016 }
34017
34018-static struct mmc_host_ops mmc_davinci_ops = {
34019+static const struct mmc_host_ops mmc_davinci_ops = {
34020 .request = mmc_davinci_request,
34021 .set_ios = mmc_davinci_set_ios,
34022 .get_cd = mmc_davinci_get_cd,
34023diff -urNp linux-2.6.39.1/drivers/mmc/host/dw_mmc.c linux-2.6.39.1/drivers/mmc/host/dw_mmc.c
34024--- linux-2.6.39.1/drivers/mmc/host/dw_mmc.c 2011-05-19 00:06:34.000000000 -0400
34025+++ linux-2.6.39.1/drivers/mmc/host/dw_mmc.c 2011-05-22 19:36:31.000000000 -0400
34026@@ -417,7 +417,7 @@ static int dw_mci_idmac_init(struct dw_m
34027 return 0;
34028 }
34029
34030-static struct dw_mci_dma_ops dw_mci_idmac_ops = {
34031+static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
34032 .init = dw_mci_idmac_init,
34033 .start = dw_mci_idmac_start_dma,
34034 .stop = dw_mci_idmac_stop_dma,
34035diff -urNp linux-2.6.39.1/drivers/mmc/host/s3cmci.c linux-2.6.39.1/drivers/mmc/host/s3cmci.c
34036--- linux-2.6.39.1/drivers/mmc/host/s3cmci.c 2011-05-19 00:06:34.000000000 -0400
34037+++ linux-2.6.39.1/drivers/mmc/host/s3cmci.c 2011-05-22 19:36:31.000000000 -0400
34038@@ -1349,7 +1349,7 @@ static void s3cmci_enable_sdio_irq(struc
34039 s3cmci_check_sdio_irq(host);
34040 }
34041
34042-static struct mmc_host_ops s3cmci_ops = {
34043+static const struct mmc_host_ops s3cmci_ops = {
34044 .request = s3cmci_request,
34045 .set_ios = s3cmci_set_ios,
34046 .get_ro = s3cmci_get_ro,
34047diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c
34048--- linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-19 00:06:34.000000000 -0400
34049+++ linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-22 19:36:31.000000000 -0400
34050@@ -81,7 +81,7 @@ out:
34051 host->clock = clock;
34052 }
34053
34054-static struct sdhci_ops sdhci_cns3xxx_ops = {
34055+static const struct sdhci_ops sdhci_cns3xxx_ops = {
34056 .get_max_clock = sdhci_cns3xxx_get_max_clk,
34057 .set_clock = sdhci_cns3xxx_set_clock,
34058 };
34059diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c
34060--- linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c 2011-05-19 00:06:34.000000000 -0400
34061+++ linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c 2011-05-22 19:36:31.000000000 -0400
34062@@ -56,7 +56,7 @@ static u32 sdhci_dove_readl(struct sdhci
34063 return ret;
34064 }
34065
34066-static struct sdhci_ops sdhci_dove_ops = {
34067+static const struct sdhci_ops sdhci_dove_ops = {
34068 .read_w = sdhci_dove_readw,
34069 .read_l = sdhci_dove_readl,
34070 };
34071diff -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
34072--- linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-19 00:06:34.000000000 -0400
34073+++ linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-22 19:36:31.000000000 -0400
34074@@ -201,7 +201,7 @@ static unsigned int esdhc_pltfm_get_ro(s
34075 return -ENOSYS;
34076 }
34077
34078-static struct sdhci_ops sdhci_esdhc_ops = {
34079+static const struct sdhci_ops sdhci_esdhc_ops = {
34080 .read_l = esdhc_readl_le,
34081 .read_w = esdhc_readw_le,
34082 .write_l = esdhc_writel_le,
34083diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-of.h linux-2.6.39.1/drivers/mmc/host/sdhci-of.h
34084--- linux-2.6.39.1/drivers/mmc/host/sdhci-of.h 2011-05-19 00:06:34.000000000 -0400
34085+++ linux-2.6.39.1/drivers/mmc/host/sdhci-of.h 2011-05-22 19:36:31.000000000 -0400
34086@@ -21,7 +21,7 @@
34087
34088 struct sdhci_of_data {
34089 unsigned int quirks;
34090- struct sdhci_ops ops;
34091+ const struct sdhci_ops ops;
34092 };
34093
34094 struct sdhci_of_host {
34095diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c
34096--- linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c 2011-05-19 00:06:34.000000000 -0400
34097+++ linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c 2011-05-22 19:36:31.000000000 -0400
34098@@ -786,7 +786,7 @@ static int sdhci_pci_enable_dma(struct s
34099 return 0;
34100 }
34101
34102-static struct sdhci_ops sdhci_pci_ops = {
34103+static const struct sdhci_ops sdhci_pci_ops = {
34104 .enable_dma = sdhci_pci_enable_dma,
34105 };
34106
34107diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c
34108--- linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c 2011-05-19 00:06:34.000000000 -0400
34109+++ linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c 2011-05-22 19:36:31.000000000 -0400
34110@@ -41,7 +41,7 @@
34111 * *
34112 \*****************************************************************************/
34113
34114-static struct sdhci_ops sdhci_pltfm_ops = {
34115+static const struct sdhci_ops sdhci_pltfm_ops = {
34116 };
34117
34118 /*****************************************************************************\
34119diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c
34120--- linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c 2011-05-19 00:06:34.000000000 -0400
34121+++ linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c 2011-05-22 19:36:31.000000000 -0400
34122@@ -69,7 +69,7 @@ static void set_clock(struct sdhci_host
34123 }
34124 }
34125
34126-static struct sdhci_ops sdhci_pxa_ops = {
34127+static const struct sdhci_ops sdhci_pxa_ops = {
34128 .set_clock = set_clock,
34129 };
34130
34131diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c
34132--- linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c 2011-05-19 00:06:34.000000000 -0400
34133+++ linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c 2011-05-22 19:36:31.000000000 -0400
34134@@ -309,7 +309,7 @@ static int sdhci_s3c_platform_8bit_width
34135 return 0;
34136 }
34137
34138-static struct sdhci_ops sdhci_s3c_ops = {
34139+static const struct sdhci_ops sdhci_s3c_ops = {
34140 .get_max_clock = sdhci_s3c_get_max_clk,
34141 .set_clock = sdhci_s3c_set_clock,
34142 .get_min_clock = sdhci_s3c_get_min_clock,
34143diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c
34144--- linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c 2011-05-19 00:06:34.000000000 -0400
34145+++ linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c 2011-05-22 19:36:31.000000000 -0400
34146@@ -32,7 +32,7 @@ struct spear_sdhci {
34147 };
34148
34149 /* sdhci ops */
34150-static struct sdhci_ops sdhci_pltfm_ops = {
34151+static const struct sdhci_ops sdhci_pltfm_ops = {
34152 /* Nothing to do for now. */
34153 };
34154
34155diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c
34156--- linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c 2011-05-19 00:06:34.000000000 -0400
34157+++ linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c 2011-05-22 19:36:31.000000000 -0400
34158@@ -242,7 +242,7 @@ static void tegra_sdhci_pltfm_exit(struc
34159 clk_put(pltfm_host->clk);
34160 }
34161
34162-static struct sdhci_ops tegra_sdhci_ops = {
34163+static const struct sdhci_ops tegra_sdhci_ops = {
34164 .get_ro = tegra_sdhci_get_ro,
34165 .read_l = tegra_sdhci_readl,
34166 .read_w = tegra_sdhci_readw,
34167diff -urNp linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c
34168--- linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c 2011-05-19 00:06:34.000000000 -0400
34169+++ linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c 2011-05-22 19:36:31.000000000 -0400
34170@@ -387,7 +387,7 @@ static int sdricoh_get_ro(struct mmc_hos
34171 return (status & STATUS_CARD_LOCKED);
34172 }
34173
34174-static struct mmc_host_ops sdricoh_ops = {
34175+static const struct mmc_host_ops sdricoh_ops = {
34176 .request = sdricoh_request,
34177 .set_ios = sdricoh_set_ios,
34178 .get_ro = sdricoh_get_ro,
34179diff -urNp linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c
34180--- linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c 2011-05-19 00:06:34.000000000 -0400
34181+++ linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c 2011-05-22 19:36:31.000000000 -0400
34182@@ -872,7 +872,7 @@ static int sh_mmcif_get_cd(struct mmc_ho
34183 return p->get_cd(host->pd);
34184 }
34185
34186-static struct mmc_host_ops sh_mmcif_ops = {
34187+static const struct mmc_host_ops sh_mmcif_ops = {
34188 .request = sh_mmcif_request,
34189 .set_ios = sh_mmcif_set_ios,
34190 .get_cd = sh_mmcif_get_cd,
34191diff -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
34192--- linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-19 00:06:34.000000000 -0400
34193+++ linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-22 19:36:31.000000000 -0400
34194@@ -757,6 +757,8 @@ static int chip_ready (struct map_info *
34195 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
34196 unsigned long timeo = jiffies + HZ;
34197
34198+ pax_track_stack();
34199+
34200 /* Prevent setting state FL_SYNCING for chip in suspended state. */
34201 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
34202 goto sleep;
34203@@ -1657,6 +1659,8 @@ static int __xipram do_write_buffer(stru
34204 unsigned long initial_adr;
34205 int initial_len = len;
34206
34207+ pax_track_stack();
34208+
34209 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
34210 adr += chip->start;
34211 initial_adr = adr;
34212@@ -1875,6 +1879,8 @@ static int __xipram do_erase_oneblock(st
34213 int retries = 3;
34214 int ret;
34215
34216+ pax_track_stack();
34217+
34218 adr += chip->start;
34219
34220 retry:
34221diff -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
34222--- linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-19 00:06:34.000000000 -0400
34223+++ linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-22 19:36:31.000000000 -0400
34224@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
34225 unsigned long cmd_addr;
34226 struct cfi_private *cfi = map->fldrv_priv;
34227
34228+ pax_track_stack();
34229+
34230 adr += chip->start;
34231
34232 /* Ensure cmd read/writes are aligned. */
34233@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
34234 DECLARE_WAITQUEUE(wait, current);
34235 int wbufsize, z;
34236
34237+ pax_track_stack();
34238+
34239 /* M58LW064A requires bus alignment for buffer wriets -- saw */
34240 if (adr & (map_bankwidth(map)-1))
34241 return -EINVAL;
34242@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
34243 DECLARE_WAITQUEUE(wait, current);
34244 int ret = 0;
34245
34246+ pax_track_stack();
34247+
34248 adr += chip->start;
34249
34250 /* Let's determine this according to the interleave only once */
34251@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
34252 unsigned long timeo = jiffies + HZ;
34253 DECLARE_WAITQUEUE(wait, current);
34254
34255+ pax_track_stack();
34256+
34257 adr += chip->start;
34258
34259 /* Let's determine this according to the interleave only once */
34260@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
34261 unsigned long timeo = jiffies + HZ;
34262 DECLARE_WAITQUEUE(wait, current);
34263
34264+ pax_track_stack();
34265+
34266 adr += chip->start;
34267
34268 /* Let's determine this according to the interleave only once */
34269diff -urNp linux-2.6.39.1/drivers/mtd/devices/doc2000.c linux-2.6.39.1/drivers/mtd/devices/doc2000.c
34270--- linux-2.6.39.1/drivers/mtd/devices/doc2000.c 2011-05-19 00:06:34.000000000 -0400
34271+++ linux-2.6.39.1/drivers/mtd/devices/doc2000.c 2011-05-22 19:36:31.000000000 -0400
34272@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
34273
34274 /* The ECC will not be calculated correctly if less than 512 is written */
34275 /* DBB-
34276- if (len != 0x200 && eccbuf)
34277+ if (len != 0x200)
34278 printk(KERN_WARNING
34279 "ECC needs a full sector write (adr: %lx size %lx)\n",
34280 (long) to, (long) len);
34281diff -urNp linux-2.6.39.1/drivers/mtd/devices/doc2001.c linux-2.6.39.1/drivers/mtd/devices/doc2001.c
34282--- linux-2.6.39.1/drivers/mtd/devices/doc2001.c 2011-05-19 00:06:34.000000000 -0400
34283+++ linux-2.6.39.1/drivers/mtd/devices/doc2001.c 2011-05-22 19:36:31.000000000 -0400
34284@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
34285 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34286
34287 /* Don't allow read past end of device */
34288- if (from >= this->totlen)
34289+ if (from >= this->totlen || !len)
34290 return -EINVAL;
34291
34292 /* Don't allow a single read to cross a 512-byte block boundary */
34293diff -urNp linux-2.6.39.1/drivers/mtd/ftl.c linux-2.6.39.1/drivers/mtd/ftl.c
34294--- linux-2.6.39.1/drivers/mtd/ftl.c 2011-05-19 00:06:34.000000000 -0400
34295+++ linux-2.6.39.1/drivers/mtd/ftl.c 2011-05-22 19:36:31.000000000 -0400
34296@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
34297 loff_t offset;
34298 uint16_t srcunitswap = cpu_to_le16(srcunit);
34299
34300+ pax_track_stack();
34301+
34302 eun = &part->EUNInfo[srcunit];
34303 xfer = &part->XferInfo[xferunit];
34304 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
34305diff -urNp linux-2.6.39.1/drivers/mtd/inftlcore.c linux-2.6.39.1/drivers/mtd/inftlcore.c
34306--- linux-2.6.39.1/drivers/mtd/inftlcore.c 2011-05-19 00:06:34.000000000 -0400
34307+++ linux-2.6.39.1/drivers/mtd/inftlcore.c 2011-05-22 19:36:31.000000000 -0400
34308@@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLr
34309 struct inftl_oob oob;
34310 size_t retlen;
34311
34312+ pax_track_stack();
34313+
34314 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
34315 "pending=%d)\n", inftl, thisVUC, pendingblock);
34316
34317diff -urNp linux-2.6.39.1/drivers/mtd/inftlmount.c linux-2.6.39.1/drivers/mtd/inftlmount.c
34318--- linux-2.6.39.1/drivers/mtd/inftlmount.c 2011-05-19 00:06:34.000000000 -0400
34319+++ linux-2.6.39.1/drivers/mtd/inftlmount.c 2011-05-22 19:36:31.000000000 -0400
34320@@ -53,6 +53,8 @@ static int find_boot_record(struct INFTL
34321 struct INFTLPartition *ip;
34322 size_t retlen;
34323
34324+ pax_track_stack();
34325+
34326 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
34327
34328 /*
34329diff -urNp linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c
34330--- linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c 2011-05-19 00:06:34.000000000 -0400
34331+++ linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c 2011-05-22 19:36:31.000000000 -0400
34332@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
34333 {
34334 map_word pfow_val[4];
34335
34336+ pax_track_stack();
34337+
34338 /* Check identification string */
34339 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
34340 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
34341diff -urNp linux-2.6.39.1/drivers/mtd/mtdchar.c linux-2.6.39.1/drivers/mtd/mtdchar.c
34342--- linux-2.6.39.1/drivers/mtd/mtdchar.c 2011-05-19 00:06:34.000000000 -0400
34343+++ linux-2.6.39.1/drivers/mtd/mtdchar.c 2011-05-22 19:36:31.000000000 -0400
34344@@ -560,6 +560,8 @@ static int mtd_ioctl(struct file *file,
34345 u_long size;
34346 struct mtd_info_user info;
34347
34348+ pax_track_stack();
34349+
34350 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
34351
34352 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
34353diff -urNp linux-2.6.39.1/drivers/mtd/nand/denali.c linux-2.6.39.1/drivers/mtd/nand/denali.c
34354--- linux-2.6.39.1/drivers/mtd/nand/denali.c 2011-05-19 00:06:34.000000000 -0400
34355+++ linux-2.6.39.1/drivers/mtd/nand/denali.c 2011-05-22 19:36:31.000000000 -0400
34356@@ -25,6 +25,7 @@
34357 #include <linux/pci.h>
34358 #include <linux/mtd/mtd.h>
34359 #include <linux/module.h>
34360+#include <linux/slab.h>
34361
34362 #include "denali.h"
34363
34364diff -urNp linux-2.6.39.1/drivers/mtd/nftlcore.c linux-2.6.39.1/drivers/mtd/nftlcore.c
34365--- linux-2.6.39.1/drivers/mtd/nftlcore.c 2011-05-19 00:06:34.000000000 -0400
34366+++ linux-2.6.39.1/drivers/mtd/nftlcore.c 2011-05-22 19:36:31.000000000 -0400
34367@@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLre
34368 int inplace = 1;
34369 size_t retlen;
34370
34371+ pax_track_stack();
34372+
34373 memset(BlockMap, 0xff, sizeof(BlockMap));
34374 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
34375
34376diff -urNp linux-2.6.39.1/drivers/mtd/nftlmount.c linux-2.6.39.1/drivers/mtd/nftlmount.c
34377--- linux-2.6.39.1/drivers/mtd/nftlmount.c 2011-05-19 00:06:34.000000000 -0400
34378+++ linux-2.6.39.1/drivers/mtd/nftlmount.c 2011-05-22 19:36:31.000000000 -0400
34379@@ -24,6 +24,7 @@
34380 #include <asm/errno.h>
34381 #include <linux/delay.h>
34382 #include <linux/slab.h>
34383+#include <linux/sched.h>
34384 #include <linux/mtd/mtd.h>
34385 #include <linux/mtd/nand.h>
34386 #include <linux/mtd/nftl.h>
34387@@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLr
34388 struct mtd_info *mtd = nftl->mbd.mtd;
34389 unsigned int i;
34390
34391+ pax_track_stack();
34392+
34393 /* Assume logical EraseSize == physical erasesize for starting the scan.
34394 We'll sort it out later if we find a MediaHeader which says otherwise */
34395 /* Actually, we won't. The new DiskOnChip driver has already scanned
34396diff -urNp linux-2.6.39.1/drivers/mtd/ubi/build.c linux-2.6.39.1/drivers/mtd/ubi/build.c
34397--- linux-2.6.39.1/drivers/mtd/ubi/build.c 2011-05-19 00:06:34.000000000 -0400
34398+++ linux-2.6.39.1/drivers/mtd/ubi/build.c 2011-05-22 19:36:31.000000000 -0400
34399@@ -1287,7 +1287,7 @@ module_exit(ubi_exit);
34400 static int __init bytes_str_to_int(const char *str)
34401 {
34402 char *endp;
34403- unsigned long result;
34404+ unsigned long result, scale = 1;
34405
34406 result = simple_strtoul(str, &endp, 0);
34407 if (str == endp || result >= INT_MAX) {
34408@@ -1298,11 +1298,11 @@ static int __init bytes_str_to_int(const
34409
34410 switch (*endp) {
34411 case 'G':
34412- result *= 1024;
34413+ scale *= 1024;
34414 case 'M':
34415- result *= 1024;
34416+ scale *= 1024;
34417 case 'K':
34418- result *= 1024;
34419+ scale *= 1024;
34420 if (endp[1] == 'i' && endp[2] == 'B')
34421 endp += 2;
34422 case '\0':
34423@@ -1313,7 +1313,13 @@ static int __init bytes_str_to_int(const
34424 return -EINVAL;
34425 }
34426
34427- return result;
34428+ if ((intoverflow_t)result*scale >= INT_MAX) {
34429+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34430+ str);
34431+ return -EINVAL;
34432+ }
34433+
34434+ return result*scale;
34435 }
34436
34437 /**
34438diff -urNp linux-2.6.39.1/drivers/net/bcm63xx_enet.c linux-2.6.39.1/drivers/net/bcm63xx_enet.c
34439--- linux-2.6.39.1/drivers/net/bcm63xx_enet.c 2011-05-19 00:06:34.000000000 -0400
34440+++ linux-2.6.39.1/drivers/net/bcm63xx_enet.c 2011-05-22 19:36:31.000000000 -0400
34441@@ -1469,7 +1469,7 @@ static int bcm_enet_set_pauseparam(struc
34442 return 0;
34443 }
34444
34445-static struct ethtool_ops bcm_enet_ethtool_ops = {
34446+static const struct ethtool_ops bcm_enet_ethtool_ops = {
34447 .get_strings = bcm_enet_get_strings,
34448 .get_sset_count = bcm_enet_get_sset_count,
34449 .get_ethtool_stats = bcm_enet_get_ethtool_stats,
34450diff -urNp linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c
34451--- linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34452+++ linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34453@@ -1242,7 +1242,7 @@ bnad_get_sset_count(struct net_device *n
34454 }
34455 }
34456
34457-static struct ethtool_ops bnad_ethtool_ops = {
34458+static const struct ethtool_ops bnad_ethtool_ops = {
34459 .get_settings = bnad_get_settings,
34460 .set_settings = bnad_set_settings,
34461 .get_drvinfo = bnad_get_drvinfo,
34462diff -urNp linux-2.6.39.1/drivers/net/bnx2.c linux-2.6.39.1/drivers/net/bnx2.c
34463--- linux-2.6.39.1/drivers/net/bnx2.c 2011-05-19 00:06:34.000000000 -0400
34464+++ linux-2.6.39.1/drivers/net/bnx2.c 2011-05-22 19:36:31.000000000 -0400
34465@@ -5828,6 +5828,8 @@ bnx2_test_nvram(struct bnx2 *bp)
34466 int rc = 0;
34467 u32 magic, csum;
34468
34469+ pax_track_stack();
34470+
34471 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
34472 goto test_nvram_done;
34473
34474diff -urNp linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c
34475--- linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34476+++ linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34477@@ -1788,6 +1788,8 @@ static int bnx2x_test_nvram(struct bnx2x
34478 int i, rc;
34479 u32 magic, crc;
34480
34481+ pax_track_stack();
34482+
34483 if (BP_NOMCP(bp))
34484 return 0;
34485
34486diff -urNp linux-2.6.39.1/drivers/net/chelsio/pm3393.c linux-2.6.39.1/drivers/net/chelsio/pm3393.c
34487--- linux-2.6.39.1/drivers/net/chelsio/pm3393.c 2011-05-19 00:06:34.000000000 -0400
34488+++ linux-2.6.39.1/drivers/net/chelsio/pm3393.c 2011-05-22 19:36:31.000000000 -0400
34489@@ -571,7 +571,7 @@ static void pm3393_destroy(struct cmac *
34490 kfree(cmac);
34491 }
34492
34493-static struct cmac_ops pm3393_ops = {
34494+static const struct cmac_ops pm3393_ops = {
34495 .destroy = pm3393_destroy,
34496 .reset = pm3393_reset,
34497 .interrupt_enable = pm3393_interrupt_enable,
34498diff -urNp linux-2.6.39.1/drivers/net/chelsio/vsc7326.c linux-2.6.39.1/drivers/net/chelsio/vsc7326.c
34499--- linux-2.6.39.1/drivers/net/chelsio/vsc7326.c 2011-05-19 00:06:34.000000000 -0400
34500+++ linux-2.6.39.1/drivers/net/chelsio/vsc7326.c 2011-05-22 19:36:31.000000000 -0400
34501@@ -666,7 +666,7 @@ static void mac_destroy(struct cmac *mac
34502 kfree(mac);
34503 }
34504
34505-static struct cmac_ops vsc7326_ops = {
34506+static const struct cmac_ops vsc7326_ops = {
34507 .destroy = mac_destroy,
34508 .reset = mac_reset,
34509 .interrupt_handler = mac_intr_handler,
34510diff -urNp linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c
34511--- linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c 2011-05-19 00:06:34.000000000 -0400
34512+++ linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c 2011-05-22 19:36:31.000000000 -0400
34513@@ -3428,6 +3428,8 @@ static int __devinit enable_msix(struct
34514 unsigned int nchan = adap->params.nports;
34515 struct msix_entry entries[MAX_INGQ + 1];
34516
34517+ pax_track_stack();
34518+
34519 for (i = 0; i < ARRAY_SIZE(entries); ++i)
34520 entries[i].entry = i;
34521
34522diff -urNp linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c
34523--- linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c 2011-05-19 00:06:34.000000000 -0400
34524+++ linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c 2011-05-22 19:36:31.000000000 -0400
34525@@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter
34526 u8 vpd[VPD_LEN], csum;
34527 unsigned int vpdr_len, kw_offset, id_len;
34528
34529+ pax_track_stack();
34530+
34531 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
34532 if (ret < 0)
34533 return ret;
34534diff -urNp linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c
34535--- linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-19 00:06:34.000000000 -0400
34536+++ linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-22 19:36:31.000000000 -0400
34537@@ -1572,7 +1572,7 @@ static int cxgb4vf_set_tso(struct net_de
34538 return 0;
34539 }
34540
34541-static struct ethtool_ops cxgb4vf_ethtool_ops = {
34542+static const struct ethtool_ops cxgb4vf_ethtool_ops = {
34543 .get_settings = cxgb4vf_get_settings,
34544 .get_drvinfo = cxgb4vf_get_drvinfo,
34545 .get_msglevel = cxgb4vf_get_msglevel,
34546diff -urNp linux-2.6.39.1/drivers/net/e1000e/82571.c linux-2.6.39.1/drivers/net/e1000e/82571.c
34547--- linux-2.6.39.1/drivers/net/e1000e/82571.c 2011-05-19 00:06:34.000000000 -0400
34548+++ linux-2.6.39.1/drivers/net/e1000e/82571.c 2011-05-22 19:36:31.000000000 -0400
34549@@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(s
34550 {
34551 struct e1000_hw *hw = &adapter->hw;
34552 struct e1000_mac_info *mac = &hw->mac;
34553- struct e1000_mac_operations *func = &mac->ops;
34554+ struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34555 u32 swsm = 0;
34556 u32 swsm2 = 0;
34557 bool force_clear_smbi = false;
34558@@ -1930,7 +1930,7 @@ static void e1000_clear_hw_cntrs_82571(s
34559 er32(ICRXDMTC);
34560 }
34561
34562-static struct e1000_mac_operations e82571_mac_ops = {
34563+static const struct e1000_mac_operations e82571_mac_ops = {
34564 /* .check_mng_mode: mac type dependent */
34565 /* .check_for_link: media type dependent */
34566 .id_led_init = e1000e_id_led_init,
34567@@ -1952,7 +1952,7 @@ static struct e1000_mac_operations e8257
34568 .read_mac_addr = e1000_read_mac_addr_82571,
34569 };
34570
34571-static struct e1000_phy_operations e82_phy_ops_igp = {
34572+static const struct e1000_phy_operations e82_phy_ops_igp = {
34573 .acquire = e1000_get_hw_semaphore_82571,
34574 .check_polarity = e1000_check_polarity_igp,
34575 .check_reset_block = e1000e_check_reset_block_generic,
34576@@ -1970,7 +1970,7 @@ static struct e1000_phy_operations e82_p
34577 .cfg_on_link_up = NULL,
34578 };
34579
34580-static struct e1000_phy_operations e82_phy_ops_m88 = {
34581+static const struct e1000_phy_operations e82_phy_ops_m88 = {
34582 .acquire = e1000_get_hw_semaphore_82571,
34583 .check_polarity = e1000_check_polarity_m88,
34584 .check_reset_block = e1000e_check_reset_block_generic,
34585@@ -1988,7 +1988,7 @@ static struct e1000_phy_operations e82_p
34586 .cfg_on_link_up = NULL,
34587 };
34588
34589-static struct e1000_phy_operations e82_phy_ops_bm = {
34590+static const struct e1000_phy_operations e82_phy_ops_bm = {
34591 .acquire = e1000_get_hw_semaphore_82571,
34592 .check_polarity = e1000_check_polarity_m88,
34593 .check_reset_block = e1000e_check_reset_block_generic,
34594@@ -2006,7 +2006,7 @@ static struct e1000_phy_operations e82_p
34595 .cfg_on_link_up = NULL,
34596 };
34597
34598-static struct e1000_nvm_operations e82571_nvm_ops = {
34599+static const struct e1000_nvm_operations e82571_nvm_ops = {
34600 .acquire = e1000_acquire_nvm_82571,
34601 .read = e1000e_read_nvm_eerd,
34602 .release = e1000_release_nvm_82571,
34603diff -urNp linux-2.6.39.1/drivers/net/e1000e/e1000.h linux-2.6.39.1/drivers/net/e1000e/e1000.h
34604--- linux-2.6.39.1/drivers/net/e1000e/e1000.h 2011-05-19 00:06:34.000000000 -0400
34605+++ linux-2.6.39.1/drivers/net/e1000e/e1000.h 2011-05-22 19:36:31.000000000 -0400
34606@@ -409,9 +409,9 @@ struct e1000_info {
34607 u32 pba;
34608 u32 max_hw_frame_size;
34609 s32 (*get_variants)(struct e1000_adapter *);
34610- struct e1000_mac_operations *mac_ops;
34611- struct e1000_phy_operations *phy_ops;
34612- struct e1000_nvm_operations *nvm_ops;
34613+ const struct e1000_mac_operations *mac_ops;
34614+ const struct e1000_phy_operations *phy_ops;
34615+ const struct e1000_nvm_operations *nvm_ops;
34616 };
34617
34618 /* hardware capability, feature, and workaround flags */
34619diff -urNp linux-2.6.39.1/drivers/net/e1000e/es2lan.c linux-2.6.39.1/drivers/net/e1000e/es2lan.c
34620--- linux-2.6.39.1/drivers/net/e1000e/es2lan.c 2011-05-19 00:06:34.000000000 -0400
34621+++ linux-2.6.39.1/drivers/net/e1000e/es2lan.c 2011-05-22 19:36:31.000000000 -0400
34622@@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es
34623 {
34624 struct e1000_hw *hw = &adapter->hw;
34625 struct e1000_mac_info *mac = &hw->mac;
34626- struct e1000_mac_operations *func = &mac->ops;
34627+ struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34628
34629 /* Set media type */
34630 switch (adapter->pdev->device) {
34631@@ -1431,7 +1431,7 @@ static void e1000_clear_hw_cntrs_80003es
34632 er32(ICRXDMTC);
34633 }
34634
34635-static struct e1000_mac_operations es2_mac_ops = {
34636+static const struct e1000_mac_operations es2_mac_ops = {
34637 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
34638 .id_led_init = e1000e_id_led_init,
34639 .check_mng_mode = e1000e_check_mng_mode_generic,
34640@@ -1453,7 +1453,7 @@ static struct e1000_mac_operations es2_m
34641 .setup_led = e1000e_setup_led_generic,
34642 };
34643
34644-static struct e1000_phy_operations es2_phy_ops = {
34645+static const struct e1000_phy_operations es2_phy_ops = {
34646 .acquire = e1000_acquire_phy_80003es2lan,
34647 .check_polarity = e1000_check_polarity_m88,
34648 .check_reset_block = e1000e_check_reset_block_generic,
34649@@ -1471,7 +1471,7 @@ static struct e1000_phy_operations es2_p
34650 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34651 };
34652
34653-static struct e1000_nvm_operations es2_nvm_ops = {
34654+static const struct e1000_nvm_operations es2_nvm_ops = {
34655 .acquire = e1000_acquire_nvm_80003es2lan,
34656 .read = e1000e_read_nvm_eerd,
34657 .release = e1000_release_nvm_80003es2lan,
34658diff -urNp linux-2.6.39.1/drivers/net/e1000e/hw.h linux-2.6.39.1/drivers/net/e1000e/hw.h
34659--- linux-2.6.39.1/drivers/net/e1000e/hw.h 2011-05-19 00:06:34.000000000 -0400
34660+++ linux-2.6.39.1/drivers/net/e1000e/hw.h 2011-05-22 19:36:31.000000000 -0400
34661@@ -811,6 +811,7 @@ struct e1000_nvm_operations {
34662 };
34663
34664 struct e1000_mac_info {
34665+ /* cannot be const see e1000_init_mac_params_ich8lan */
34666 struct e1000_mac_operations ops;
34667 u8 addr[ETH_ALEN];
34668 u8 perm_addr[ETH_ALEN];
34669@@ -852,6 +853,7 @@ struct e1000_mac_info {
34670 };
34671
34672 struct e1000_phy_info {
34673+ /* Cannot be const see e1000_init_phy_params_82571() */
34674 struct e1000_phy_operations ops;
34675
34676 enum e1000_phy_type type;
34677@@ -886,6 +888,7 @@ struct e1000_phy_info {
34678 };
34679
34680 struct e1000_nvm_info {
34681+ /* cannot be const */
34682 struct e1000_nvm_operations ops;
34683
34684 enum e1000_nvm_type type;
34685diff -urNp linux-2.6.39.1/drivers/net/e1000e/ich8lan.c linux-2.6.39.1/drivers/net/e1000e/ich8lan.c
34686--- linux-2.6.39.1/drivers/net/e1000e/ich8lan.c 2011-05-19 00:06:34.000000000 -0400
34687+++ linux-2.6.39.1/drivers/net/e1000e/ich8lan.c 2011-05-22 19:36:31.000000000 -0400
34688@@ -3866,7 +3866,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34689 }
34690 }
34691
34692-static struct e1000_mac_operations ich8_mac_ops = {
34693+static const struct e1000_mac_operations ich8_mac_ops = {
34694 .id_led_init = e1000e_id_led_init,
34695 /* check_mng_mode dependent on mac type */
34696 .check_for_link = e1000_check_for_copper_link_ich8lan,
34697@@ -3885,7 +3885,7 @@ static struct e1000_mac_operations ich8_
34698 /* id_led_init dependent on mac type */
34699 };
34700
34701-static struct e1000_phy_operations ich8_phy_ops = {
34702+static const struct e1000_phy_operations ich8_phy_ops = {
34703 .acquire = e1000_acquire_swflag_ich8lan,
34704 .check_reset_block = e1000_check_reset_block_ich8lan,
34705 .commit = NULL,
34706@@ -3899,7 +3899,7 @@ static struct e1000_phy_operations ich8_
34707 .write_reg = e1000e_write_phy_reg_igp,
34708 };
34709
34710-static struct e1000_nvm_operations ich8_nvm_ops = {
34711+static const struct e1000_nvm_operations ich8_nvm_ops = {
34712 .acquire = e1000_acquire_nvm_ich8lan,
34713 .read = e1000_read_nvm_ich8lan,
34714 .release = e1000_release_nvm_ich8lan,
34715diff -urNp linux-2.6.39.1/drivers/net/greth.c linux-2.6.39.1/drivers/net/greth.c
34716--- linux-2.6.39.1/drivers/net/greth.c 2011-05-19 00:06:34.000000000 -0400
34717+++ linux-2.6.39.1/drivers/net/greth.c 2011-05-22 19:36:31.000000000 -0400
34718@@ -1192,7 +1192,7 @@ static const struct ethtool_ops greth_et
34719 .get_link = ethtool_op_get_link,
34720 };
34721
34722-static struct net_device_ops greth_netdev_ops = {
34723+static const struct net_device_ops greth_netdev_ops = {
34724 .ndo_open = greth_open,
34725 .ndo_stop = greth_close,
34726 .ndo_start_xmit = greth_start_xmit,
34727diff -urNp linux-2.6.39.1/drivers/net/hamradio/6pack.c linux-2.6.39.1/drivers/net/hamradio/6pack.c
34728--- linux-2.6.39.1/drivers/net/hamradio/6pack.c 2011-05-19 00:06:34.000000000 -0400
34729+++ linux-2.6.39.1/drivers/net/hamradio/6pack.c 2011-05-22 19:36:31.000000000 -0400
34730@@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct t
34731 unsigned char buf[512];
34732 int count1;
34733
34734+ pax_track_stack();
34735+
34736 if (!count)
34737 return;
34738
34739diff -urNp linux-2.6.39.1/drivers/net/ibm_newemac/phy.c linux-2.6.39.1/drivers/net/ibm_newemac/phy.c
34740--- linux-2.6.39.1/drivers/net/ibm_newemac/phy.c 2011-05-19 00:06:34.000000000 -0400
34741+++ linux-2.6.39.1/drivers/net/ibm_newemac/phy.c 2011-05-22 19:36:31.000000000 -0400
34742@@ -273,7 +273,7 @@ static int genmii_read_link(struct mii_p
34743 }
34744
34745 /* Generic implementation for most 10/100/1000 PHYs */
34746-static struct mii_phy_ops generic_phy_ops = {
34747+static const struct mii_phy_ops generic_phy_ops = {
34748 .setup_aneg = genmii_setup_aneg,
34749 .setup_forced = genmii_setup_forced,
34750 .poll_link = genmii_poll_link,
34751@@ -337,7 +337,7 @@ static int cis8201_init(struct mii_phy *
34752 return 0;
34753 }
34754
34755-static struct mii_phy_ops cis8201_phy_ops = {
34756+static const struct mii_phy_ops cis8201_phy_ops = {
34757 .init = cis8201_init,
34758 .setup_aneg = genmii_setup_aneg,
34759 .setup_forced = genmii_setup_forced,
34760@@ -417,7 +417,7 @@ static int et1011c_init(struct mii_phy *
34761 return 0;
34762 }
34763
34764-static struct mii_phy_ops et1011c_phy_ops = {
34765+static const struct mii_phy_ops et1011c_phy_ops = {
34766 .init = et1011c_init,
34767 .setup_aneg = genmii_setup_aneg,
34768 .setup_forced = genmii_setup_forced,
34769@@ -436,7 +436,7 @@ static struct mii_phy_def et1011c_phy_de
34770
34771
34772
34773-static struct mii_phy_ops m88e1111_phy_ops = {
34774+static const struct mii_phy_ops m88e1111_phy_ops = {
34775 .init = m88e1111_init,
34776 .setup_aneg = genmii_setup_aneg,
34777 .setup_forced = genmii_setup_forced,
34778@@ -452,7 +452,7 @@ static struct mii_phy_def m88e1111_phy_d
34779 .ops = &m88e1111_phy_ops,
34780 };
34781
34782-static struct mii_phy_ops m88e1112_phy_ops = {
34783+static const struct mii_phy_ops m88e1112_phy_ops = {
34784 .init = m88e1112_init,
34785 .setup_aneg = genmii_setup_aneg,
34786 .setup_forced = genmii_setup_forced,
34787diff -urNp linux-2.6.39.1/drivers/net/ibmveth.c linux-2.6.39.1/drivers/net/ibmveth.c
34788--- linux-2.6.39.1/drivers/net/ibmveth.c 2011-05-19 00:06:34.000000000 -0400
34789+++ linux-2.6.39.1/drivers/net/ibmveth.c 2011-05-22 19:36:31.000000000 -0400
34790@@ -1625,7 +1625,7 @@ static struct vio_device_id ibmveth_devi
34791 };
34792 MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
34793
34794-static struct dev_pm_ops ibmveth_pm_ops = {
34795+static const struct dev_pm_ops ibmveth_pm_ops = {
34796 .resume = ibmveth_resume
34797 };
34798
34799diff -urNp linux-2.6.39.1/drivers/net/igb/e1000_82575.c linux-2.6.39.1/drivers/net/igb/e1000_82575.c
34800--- linux-2.6.39.1/drivers/net/igb/e1000_82575.c 2011-05-19 00:06:34.000000000 -0400
34801+++ linux-2.6.39.1/drivers/net/igb/e1000_82575.c 2011-05-22 19:36:31.000000000 -0400
34802@@ -2029,7 +2029,7 @@ out:
34803 return ret_val;
34804 }
34805
34806-static struct e1000_mac_operations e1000_mac_ops_82575 = {
34807+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34808 .init_hw = igb_init_hw_82575,
34809 .check_for_link = igb_check_for_link_82575,
34810 .rar_set = igb_rar_set,
34811@@ -2037,13 +2037,13 @@ static struct e1000_mac_operations e1000
34812 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34813 };
34814
34815-static struct e1000_phy_operations e1000_phy_ops_82575 = {
34816+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34817 .acquire = igb_acquire_phy_82575,
34818 .get_cfg_done = igb_get_cfg_done_82575,
34819 .release = igb_release_phy_82575,
34820 };
34821
34822-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34823+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34824 .acquire = igb_acquire_nvm_82575,
34825 .read = igb_read_nvm_eerd,
34826 .release = igb_release_nvm_82575,
34827diff -urNp linux-2.6.39.1/drivers/net/igb/e1000_hw.h linux-2.6.39.1/drivers/net/igb/e1000_hw.h
34828--- linux-2.6.39.1/drivers/net/igb/e1000_hw.h 2011-05-19 00:06:34.000000000 -0400
34829+++ linux-2.6.39.1/drivers/net/igb/e1000_hw.h 2011-05-22 19:36:31.000000000 -0400
34830@@ -342,14 +342,15 @@ struct e1000_nvm_operations {
34831
34832 struct e1000_info {
34833 s32 (*get_invariants)(struct e1000_hw *);
34834- struct e1000_mac_operations *mac_ops;
34835- struct e1000_phy_operations *phy_ops;
34836- struct e1000_nvm_operations *nvm_ops;
34837+ const struct e1000_mac_operations *mac_ops;
34838+ const struct e1000_phy_operations *phy_ops;
34839+ const struct e1000_nvm_operations *nvm_ops;
34840 };
34841
34842 extern const struct e1000_info e1000_82575_info;
34843
34844 struct e1000_mac_info {
34845+ /* cannot be const see igb_get_invariants_82575() */
34846 struct e1000_mac_operations ops;
34847
34848 u8 addr[6];
34849@@ -388,6 +389,7 @@ struct e1000_mac_info {
34850 };
34851
34852 struct e1000_phy_info {
34853+ /* cannot be const see igb_get_invariants_82575() */
34854 struct e1000_phy_operations ops;
34855
34856 enum e1000_phy_type type;
34857@@ -423,6 +425,7 @@ struct e1000_phy_info {
34858 };
34859
34860 struct e1000_nvm_info {
34861+ /* cannot be const */
34862 struct e1000_nvm_operations ops;
34863 enum e1000_nvm_type type;
34864 enum e1000_nvm_override override;
34865diff -urNp linux-2.6.39.1/drivers/net/igbvf/vf.h linux-2.6.39.1/drivers/net/igbvf/vf.h
34866--- linux-2.6.39.1/drivers/net/igbvf/vf.h 2011-05-19 00:06:34.000000000 -0400
34867+++ linux-2.6.39.1/drivers/net/igbvf/vf.h 2011-05-22 19:36:31.000000000 -0400
34868@@ -191,6 +191,7 @@ struct e1000_mac_operations {
34869 };
34870
34871 struct e1000_mac_info {
34872+ /* cannot be const see e1000_init_mac_params_vf() */
34873 struct e1000_mac_operations ops;
34874 u8 addr[6];
34875 u8 perm_addr[6];
34876diff -urNp linux-2.6.39.1/drivers/net/irda/sh_irda.c linux-2.6.39.1/drivers/net/irda/sh_irda.c
34877--- linux-2.6.39.1/drivers/net/irda/sh_irda.c 2011-05-19 00:06:34.000000000 -0400
34878+++ linux-2.6.39.1/drivers/net/irda/sh_irda.c 2011-05-22 19:36:31.000000000 -0400
34879@@ -307,7 +307,7 @@ static int xir_fte(struct sh_irda_self *
34880 return 0;
34881 }
34882
34883-static struct sh_irda_xir_func xir_func = {
34884+static const struct sh_irda_xir_func xir_func = {
34885 .xir_fre = xir_fre,
34886 .xir_trov = xir_trov,
34887 .xir_9 = xir_9,
34888@@ -321,7 +321,7 @@ static struct sh_irda_xir_func xir_func
34889 *
34890 * MIR/FIR are not supported now
34891 *=====================================*/
34892-static struct sh_irda_xir_func mfir_func = {
34893+static const struct sh_irda_xir_func mfir_func = {
34894 .xir_fre = xir_fre,
34895 .xir_trov = xir_trov,
34896 .xir_9 = xir_9,
34897@@ -400,7 +400,7 @@ static int sir_fte(struct sh_irda_self *
34898 return 0;
34899 }
34900
34901-static struct sh_irda_xir_func sir_func = {
34902+static const struct sh_irda_xir_func sir_func = {
34903 .xir_fre = sir_fre,
34904 .xir_trov = sir_trov,
34905 .xir_9 = sir_tot,
34906@@ -411,7 +411,7 @@ static struct sh_irda_xir_func sir_func
34907 static void sh_irda_set_mode(struct sh_irda_self *self, enum sh_irda_mode mode)
34908 {
34909 struct device *dev = &self->ndev->dev;
34910- struct sh_irda_xir_func *func;
34911+ const struct sh_irda_xir_func *func;
34912 const char *name;
34913 u16 data;
34914
34915diff -urNp linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c
34916--- linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c 2011-05-19 00:06:34.000000000 -0400
34917+++ linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c 2011-05-22 19:36:31.000000000 -0400
34918@@ -1069,6 +1069,8 @@ ixgb_set_multi(struct net_device *netdev
34919 u32 rctl;
34920 int i;
34921
34922+ pax_track_stack();
34923+
34924 /* Check for Promiscuous and All Multicast modes */
34925
34926 rctl = IXGB_READ_REG(hw, RCTL);
34927diff -urNp linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c
34928--- linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c 2011-05-19 00:06:34.000000000 -0400
34929+++ linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c 2011-05-22 19:36:31.000000000 -0400
34930@@ -261,6 +261,9 @@ void __devinit
34931 ixgb_check_options(struct ixgb_adapter *adapter)
34932 {
34933 int bd = adapter->bd_number;
34934+
34935+ pax_track_stack();
34936+
34937 if (bd >= IXGB_MAX_NIC) {
34938 pr_notice("Warning: no configuration for board #%i\n", bd);
34939 pr_notice("Using defaults for all values\n");
34940diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c
34941--- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c 2011-05-19 00:06:34.000000000 -0400
34942+++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c 2011-05-22 19:36:31.000000000 -0400
34943@@ -2099,7 +2099,7 @@ static struct ixgbe_phy_operations phy_o
34944 .check_overtemp = &ixgbe_tn_check_overtemp,
34945 };
34946
34947-struct ixgbe_info ixgbe_82599_info = {
34948+const struct ixgbe_info ixgbe_82599_info = {
34949 .mac = ixgbe_mac_82599EB,
34950 .get_invariants = &ixgbe_get_invariants_82599,
34951 .mac_ops = &mac_ops_82599,
34952diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h
34953--- linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h 2011-05-19 00:06:34.000000000 -0400
34954+++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h 2011-05-22 19:36:31.000000000 -0400
34955@@ -493,8 +493,8 @@ enum ixgbe_boards {
34956 };
34957
34958 extern struct ixgbe_info ixgbe_82598_info;
34959-extern struct ixgbe_info ixgbe_82599_info;
34960-extern struct ixgbe_info ixgbe_X540_info;
34961+extern const struct ixgbe_info ixgbe_82599_info;
34962+extern const struct ixgbe_info ixgbe_X540_info;
34963 #ifdef CONFIG_IXGBE_DCB
34964 extern const struct dcbnl_rtnl_ops dcbnl_ops;
34965 extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
34966diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c
34967--- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c 2011-05-19 00:06:34.000000000 -0400
34968+++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c 2011-05-22 19:36:31.000000000 -0400
34969@@ -727,7 +727,7 @@ static struct ixgbe_phy_operations phy_o
34970 .check_overtemp = &ixgbe_tn_check_overtemp,
34971 };
34972
34973-struct ixgbe_info ixgbe_X540_info = {
34974+const struct ixgbe_info ixgbe_X540_info = {
34975 .mac = ixgbe_mac_X540,
34976 .get_invariants = &ixgbe_get_invariants_X540,
34977 .mac_ops = &mac_ops_X540,
34978diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c
34979--- linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c 2011-05-19 00:06:34.000000000 -0400
34980+++ linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c 2011-05-22 19:36:31.000000000 -0400
34981@@ -709,7 +709,7 @@ static int ixgbevf_nway_reset(struct net
34982 return 0;
34983 }
34984
34985-static struct ethtool_ops ixgbevf_ethtool_ops = {
34986+static const struct ethtool_ops ixgbevf_ethtool_ops = {
34987 .get_settings = ixgbevf_get_settings,
34988 .get_drvinfo = ixgbevf_get_drvinfo,
34989 .get_regs_len = ixgbevf_get_regs_len,
34990diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h
34991--- linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h 2011-05-19 00:06:34.000000000 -0400
34992+++ linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h 2011-05-22 19:36:31.000000000 -0400
34993@@ -279,7 +279,7 @@ enum ixgbevf_boards {
34994
34995 extern struct ixgbevf_info ixgbevf_82599_vf_info;
34996 extern struct ixgbevf_info ixgbevf_X540_vf_info;
34997-extern struct ixgbe_mac_operations ixgbevf_mbx_ops;
34998+extern const struct ixgbe_mac_operations ixgbevf_mbx_ops;
34999
35000 /* needed by ethtool.c */
35001 extern char ixgbevf_driver_name[];
35002diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/vf.c linux-2.6.39.1/drivers/net/ixgbevf/vf.c
35003--- linux-2.6.39.1/drivers/net/ixgbevf/vf.c 2011-05-19 00:06:34.000000000 -0400
35004+++ linux-2.6.39.1/drivers/net/ixgbevf/vf.c 2011-05-22 19:36:31.000000000 -0400
35005@@ -368,7 +368,7 @@ static s32 ixgbevf_check_mac_link_vf(str
35006 return 0;
35007 }
35008
35009-static struct ixgbe_mac_operations ixgbevf_mac_ops = {
35010+static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
35011 .init_hw = ixgbevf_init_hw_vf,
35012 .reset_hw = ixgbevf_reset_hw_vf,
35013 .start_hw = ixgbevf_start_hw_vf,
35014@@ -381,12 +381,12 @@ static struct ixgbe_mac_operations ixgbe
35015 .set_vfta = ixgbevf_set_vfta_vf,
35016 };
35017
35018-struct ixgbevf_info ixgbevf_82599_vf_info = {
35019+const struct ixgbevf_info ixgbevf_82599_vf_info = {
35020 .mac = ixgbe_mac_82599_vf,
35021 .mac_ops = &ixgbevf_mac_ops,
35022 };
35023
35024-struct ixgbevf_info ixgbevf_X540_vf_info = {
35025+const struct ixgbevf_info ixgbevf_X540_vf_info = {
35026 .mac = ixgbe_mac_X540_vf,
35027 .mac_ops = &ixgbevf_mac_ops,
35028 };
35029diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/vf.h linux-2.6.39.1/drivers/net/ixgbevf/vf.h
35030--- linux-2.6.39.1/drivers/net/ixgbevf/vf.h 2011-05-19 00:06:34.000000000 -0400
35031+++ linux-2.6.39.1/drivers/net/ixgbevf/vf.h 2011-05-22 19:36:31.000000000 -0400
35032@@ -166,7 +166,7 @@ struct ixgbevf_hw_stats {
35033
35034 struct ixgbevf_info {
35035 enum ixgbe_mac_type mac;
35036- struct ixgbe_mac_operations *mac_ops;
35037+ const struct ixgbe_mac_operations *mac_ops;
35038 };
35039
35040 #endif /* __IXGBE_VF_H__ */
35041diff -urNp linux-2.6.39.1/drivers/net/ksz884x.c linux-2.6.39.1/drivers/net/ksz884x.c
35042--- linux-2.6.39.1/drivers/net/ksz884x.c 2011-05-19 00:06:34.000000000 -0400
35043+++ linux-2.6.39.1/drivers/net/ksz884x.c 2011-05-22 19:36:31.000000000 -0400
35044@@ -6536,6 +6536,8 @@ static void netdev_get_ethtool_stats(str
35045 int rc;
35046 u64 counter[TOTAL_PORT_COUNTER_NUM];
35047
35048+ pax_track_stack();
35049+
35050 mutex_lock(&hw_priv->lock);
35051 n = SWITCH_PORT_NUM;
35052 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
35053@@ -6637,7 +6639,7 @@ static int netdev_set_rx_csum(struct net
35054 return 0;
35055 }
35056
35057-static struct ethtool_ops netdev_ethtool_ops = {
35058+static const struct ethtool_ops netdev_ethtool_ops = {
35059 .get_settings = netdev_get_settings,
35060 .set_settings = netdev_set_settings,
35061 .nway_reset = netdev_nway_reset,
35062diff -urNp linux-2.6.39.1/drivers/net/mlx4/main.c linux-2.6.39.1/drivers/net/mlx4/main.c
35063--- linux-2.6.39.1/drivers/net/mlx4/main.c 2011-05-19 00:06:34.000000000 -0400
35064+++ linux-2.6.39.1/drivers/net/mlx4/main.c 2011-05-22 19:36:31.000000000 -0400
35065@@ -40,6 +40,7 @@
35066 #include <linux/dma-mapping.h>
35067 #include <linux/slab.h>
35068 #include <linux/io-mapping.h>
35069+#include <linux/sched.h>
35070
35071 #include <linux/mlx4/device.h>
35072 #include <linux/mlx4/doorbell.h>
35073@@ -764,6 +765,8 @@ static int mlx4_init_hca(struct mlx4_dev
35074 u64 icm_size;
35075 int err;
35076
35077+ pax_track_stack();
35078+
35079 err = mlx4_QUERY_FW(dev);
35080 if (err) {
35081 if (err == -EACCES)
35082diff -urNp linux-2.6.39.1/drivers/net/netconsole.c linux-2.6.39.1/drivers/net/netconsole.c
35083--- linux-2.6.39.1/drivers/net/netconsole.c 2011-05-19 00:06:34.000000000 -0400
35084+++ linux-2.6.39.1/drivers/net/netconsole.c 2011-05-22 19:36:31.000000000 -0400
35085@@ -634,7 +634,7 @@ static void drop_netconsole_target(struc
35086 config_item_put(&nt->item);
35087 }
35088
35089-static struct configfs_group_operations netconsole_subsys_group_ops = {
35090+static const struct configfs_group_operations netconsole_subsys_group_ops = {
35091 .make_item = make_netconsole_target,
35092 .drop_item = drop_netconsole_target,
35093 };
35094diff -urNp linux-2.6.39.1/drivers/net/niu.c linux-2.6.39.1/drivers/net/niu.c
35095--- linux-2.6.39.1/drivers/net/niu.c 2011-05-19 00:06:34.000000000 -0400
35096+++ linux-2.6.39.1/drivers/net/niu.c 2011-05-22 19:36:31.000000000 -0400
35097@@ -9067,6 +9067,8 @@ static void __devinit niu_try_msix(struc
35098 int i, num_irqs, err;
35099 u8 first_ldg;
35100
35101+ pax_track_stack();
35102+
35103 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
35104 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
35105 ldg_num_map[i] = first_ldg + i;
35106diff -urNp linux-2.6.39.1/drivers/net/pcnet32.c linux-2.6.39.1/drivers/net/pcnet32.c
35107--- linux-2.6.39.1/drivers/net/pcnet32.c 2011-05-19 00:06:34.000000000 -0400
35108+++ linux-2.6.39.1/drivers/net/pcnet32.c 2011-05-22 19:36:31.000000000 -0400
35109@@ -82,7 +82,7 @@ static int cards_found;
35110 /*
35111 * VLB I/O addresses
35112 */
35113-static unsigned int pcnet32_portlist[] __initdata =
35114+static unsigned int pcnet32_portlist[] __devinitdata =
35115 { 0x300, 0x320, 0x340, 0x360, 0 };
35116
35117 static int pcnet32_debug;
35118@@ -379,7 +379,7 @@ static int pcnet32_wio_check(unsigned lo
35119 return inw(addr + PCNET32_WIO_RAP) == 88;
35120 }
35121
35122-static struct pcnet32_access pcnet32_wio = {
35123+static const struct pcnet32_access pcnet32_wio = {
35124 .read_csr = pcnet32_wio_read_csr,
35125 .write_csr = pcnet32_wio_write_csr,
35126 .read_bcr = pcnet32_wio_read_bcr,
35127@@ -434,7 +434,7 @@ static int pcnet32_dwio_check(unsigned l
35128 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88;
35129 }
35130
35131-static struct pcnet32_access pcnet32_dwio = {
35132+static const struct pcnet32_access pcnet32_dwio = {
35133 .read_csr = pcnet32_dwio_read_csr,
35134 .write_csr = pcnet32_dwio_write_csr,
35135 .read_bcr = pcnet32_dwio_read_bcr,
35136@@ -1546,7 +1546,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35137 int chip_version;
35138 char *chipname;
35139 struct net_device *dev;
35140- struct pcnet32_access *a = NULL;
35141+ const struct pcnet32_access *a = NULL;
35142 u8 promaddr[6];
35143 int ret = -ENODEV;
35144
35145diff -urNp linux-2.6.39.1/drivers/net/ppp_generic.c linux-2.6.39.1/drivers/net/ppp_generic.c
35146--- linux-2.6.39.1/drivers/net/ppp_generic.c 2011-05-19 00:06:34.000000000 -0400
35147+++ linux-2.6.39.1/drivers/net/ppp_generic.c 2011-05-22 19:36:31.000000000 -0400
35148@@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, st
35149 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35150 struct ppp_stats stats;
35151 struct ppp_comp_stats cstats;
35152- char *vers;
35153
35154 switch (cmd) {
35155 case SIOCGPPPSTATS:
35156@@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, st
35157 break;
35158
35159 case SIOCGPPPVER:
35160- vers = PPP_VERSION;
35161- if (copy_to_user(addr, vers, strlen(vers) + 1))
35162+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35163 break;
35164 err = 0;
35165 break;
35166diff -urNp linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h
35167--- linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h 2011-05-19 00:06:34.000000000 -0400
35168+++ linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h 2011-05-22 19:36:31.000000000 -0400
35169@@ -1037,7 +1037,7 @@ struct qlcnic_adapter {
35170 struct vlan_group *vlgrp;
35171 struct qlcnic_npar_info *npars;
35172 struct qlcnic_eswitch *eswitch;
35173- struct qlcnic_nic_template *nic_ops;
35174+ const struct qlcnic_nic_template *nic_ops;
35175
35176 struct qlcnic_adapter_stats stats;
35177
35178diff -urNp linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c
35179--- linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c 2011-05-19 00:06:34.000000000 -0400
35180+++ linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c 2011-05-22 19:36:31.000000000 -0400
35181@@ -340,13 +340,13 @@ static const struct net_device_ops qlcni
35182 #endif
35183 };
35184
35185-static struct qlcnic_nic_template qlcnic_ops = {
35186+static const struct qlcnic_nic_template qlcnic_ops = {
35187 .config_bridged_mode = qlcnic_config_bridged_mode,
35188 .config_led = qlcnic_config_led,
35189 .start_firmware = qlcnic_start_firmware
35190 };
35191
35192-static struct qlcnic_nic_template qlcnic_vf_ops = {
35193+static const struct qlcnic_nic_template qlcnic_vf_ops = {
35194 .config_bridged_mode = qlcnicvf_config_bridged_mode,
35195 .config_led = qlcnicvf_config_led,
35196 .start_firmware = qlcnicvf_start_firmware
35197diff -urNp linux-2.6.39.1/drivers/net/qlge/qlge.h linux-2.6.39.1/drivers/net/qlge/qlge.h
35198--- linux-2.6.39.1/drivers/net/qlge/qlge.h 2011-05-19 00:06:34.000000000 -0400
35199+++ linux-2.6.39.1/drivers/net/qlge/qlge.h 2011-05-22 19:36:31.000000000 -0400
35200@@ -2134,7 +2134,7 @@ struct ql_adapter {
35201 struct delayed_work mpi_idc_work;
35202 struct delayed_work mpi_core_to_log;
35203 struct completion ide_completion;
35204- struct nic_operations *nic_ops;
35205+ const struct nic_operations *nic_ops;
35206 u16 device_id;
35207 struct timer_list timer;
35208 atomic_t lb_count;
35209diff -urNp linux-2.6.39.1/drivers/net/qlge/qlge_main.c linux-2.6.39.1/drivers/net/qlge/qlge_main.c
35210--- linux-2.6.39.1/drivers/net/qlge/qlge_main.c 2011-05-19 00:06:34.000000000 -0400
35211+++ linux-2.6.39.1/drivers/net/qlge/qlge_main.c 2011-05-22 19:36:31.000000000 -0400
35212@@ -4412,12 +4412,12 @@ error:
35213 rtnl_unlock();
35214 }
35215
35216-static struct nic_operations qla8012_nic_ops = {
35217+static const struct nic_operations qla8012_nic_ops = {
35218 .get_flash = ql_get_8012_flash_params,
35219 .port_initialize = ql_8012_port_initialize,
35220 };
35221
35222-static struct nic_operations qla8000_nic_ops = {
35223+static const struct nic_operations qla8000_nic_ops = {
35224 .get_flash = ql_get_8000_flash_params,
35225 .port_initialize = ql_8000_port_initialize,
35226 };
35227diff -urNp linux-2.6.39.1/drivers/net/sfc/falcon.c linux-2.6.39.1/drivers/net/sfc/falcon.c
35228--- linux-2.6.39.1/drivers/net/sfc/falcon.c 2011-05-19 00:06:34.000000000 -0400
35229+++ linux-2.6.39.1/drivers/net/sfc/falcon.c 2011-05-22 19:36:31.000000000 -0400
35230@@ -1703,7 +1703,7 @@ static int falcon_set_wol(struct efx_nic
35231 **************************************************************************
35232 */
35233
35234-struct efx_nic_type falcon_a1_nic_type = {
35235+const struct efx_nic_type falcon_a1_nic_type = {
35236 .probe = falcon_probe_nic,
35237 .remove = falcon_remove_nic,
35238 .init = falcon_init_nic,
35239@@ -1744,7 +1744,7 @@ struct efx_nic_type falcon_a1_nic_type =
35240 .reset_world_flags = ETH_RESET_IRQ,
35241 };
35242
35243-struct efx_nic_type falcon_b0_nic_type = {
35244+const struct efx_nic_type falcon_b0_nic_type = {
35245 .probe = falcon_probe_nic,
35246 .remove = falcon_remove_nic,
35247 .init = falcon_init_nic,
35248diff -urNp linux-2.6.39.1/drivers/net/sfc/mtd.c linux-2.6.39.1/drivers/net/sfc/mtd.c
35249--- linux-2.6.39.1/drivers/net/sfc/mtd.c 2011-05-19 00:06:34.000000000 -0400
35250+++ linux-2.6.39.1/drivers/net/sfc/mtd.c 2011-05-22 19:36:31.000000000 -0400
35251@@ -382,7 +382,7 @@ static int falcon_mtd_sync(struct mtd_in
35252 return rc;
35253 }
35254
35255-static struct efx_mtd_ops falcon_mtd_ops = {
35256+static const struct efx_mtd_ops falcon_mtd_ops = {
35257 .read = falcon_mtd_read,
35258 .erase = falcon_mtd_erase,
35259 .write = falcon_mtd_write,
35260@@ -560,7 +560,7 @@ static int siena_mtd_sync(struct mtd_inf
35261 return rc;
35262 }
35263
35264-static struct efx_mtd_ops siena_mtd_ops = {
35265+static const struct efx_mtd_ops siena_mtd_ops = {
35266 .read = siena_mtd_read,
35267 .erase = siena_mtd_erase,
35268 .write = siena_mtd_write,
35269diff -urNp linux-2.6.39.1/drivers/net/sfc/nic.h linux-2.6.39.1/drivers/net/sfc/nic.h
35270--- linux-2.6.39.1/drivers/net/sfc/nic.h 2011-05-19 00:06:34.000000000 -0400
35271+++ linux-2.6.39.1/drivers/net/sfc/nic.h 2011-05-22 19:36:31.000000000 -0400
35272@@ -152,9 +152,9 @@ struct siena_nic_data {
35273 int wol_filter_id;
35274 };
35275
35276-extern struct efx_nic_type falcon_a1_nic_type;
35277-extern struct efx_nic_type falcon_b0_nic_type;
35278-extern struct efx_nic_type siena_a0_nic_type;
35279+extern const struct efx_nic_type falcon_a1_nic_type;
35280+extern const struct efx_nic_type falcon_b0_nic_type;
35281+extern const struct efx_nic_type siena_a0_nic_type;
35282
35283 /**************************************************************************
35284 *
35285diff -urNp linux-2.6.39.1/drivers/net/sfc/siena.c linux-2.6.39.1/drivers/net/sfc/siena.c
35286--- linux-2.6.39.1/drivers/net/sfc/siena.c 2011-05-19 00:06:34.000000000 -0400
35287+++ linux-2.6.39.1/drivers/net/sfc/siena.c 2011-05-22 19:36:31.000000000 -0400
35288@@ -599,7 +599,7 @@ static void siena_init_wol(struct efx_ni
35289 **************************************************************************
35290 */
35291
35292-struct efx_nic_type siena_a0_nic_type = {
35293+const struct efx_nic_type siena_a0_nic_type = {
35294 .probe = siena_probe_nic,
35295 .remove = siena_remove_nic,
35296 .init = siena_init_nic,
35297diff -urNp linux-2.6.39.1/drivers/net/sh_eth.c linux-2.6.39.1/drivers/net/sh_eth.c
35298--- linux-2.6.39.1/drivers/net/sh_eth.c 2011-05-19 00:06:34.000000000 -0400
35299+++ linux-2.6.39.1/drivers/net/sh_eth.c 2011-05-22 19:36:31.000000000 -0400
35300@@ -1360,7 +1360,7 @@ static void sh_eth_get_strings(struct ne
35301 }
35302 }
35303
35304-static struct ethtool_ops sh_eth_ethtool_ops = {
35305+static const struct ethtool_ops sh_eth_ethtool_ops = {
35306 .get_settings = sh_eth_get_settings,
35307 .set_settings = sh_eth_set_settings,
35308 .nway_reset = sh_eth_nway_reset,
35309diff -urNp linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c
35310--- linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35311+++ linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35312@@ -348,7 +348,7 @@ static int stmmac_set_wol(struct net_dev
35313 return 0;
35314 }
35315
35316-static struct ethtool_ops stmmac_ethtool_ops = {
35317+static const struct ethtool_ops stmmac_ethtool_ops = {
35318 .begin = stmmac_check_if_running,
35319 .get_drvinfo = stmmac_ethtool_getdrvinfo,
35320 .get_settings = stmmac_ethtool_getsettings,
35321diff -urNp linux-2.6.39.1/drivers/net/sungem_phy.c linux-2.6.39.1/drivers/net/sungem_phy.c
35322--- linux-2.6.39.1/drivers/net/sungem_phy.c 2011-05-19 00:06:34.000000000 -0400
35323+++ linux-2.6.39.1/drivers/net/sungem_phy.c 2011-05-22 19:36:31.000000000 -0400
35324@@ -886,7 +886,7 @@ static int marvell_read_link(struct mii_
35325 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
35326
35327 /* Broadcom BCM 5201 */
35328-static struct mii_phy_ops bcm5201_phy_ops = {
35329+static const struct mii_phy_ops bcm5201_phy_ops = {
35330 .init = bcm5201_init,
35331 .suspend = bcm5201_suspend,
35332 .setup_aneg = genmii_setup_aneg,
35333@@ -905,7 +905,7 @@ static struct mii_phy_def bcm5201_phy_de
35334 };
35335
35336 /* Broadcom BCM 5221 */
35337-static struct mii_phy_ops bcm5221_phy_ops = {
35338+static const struct mii_phy_ops bcm5221_phy_ops = {
35339 .suspend = bcm5221_suspend,
35340 .init = bcm5221_init,
35341 .setup_aneg = genmii_setup_aneg,
35342@@ -924,7 +924,7 @@ static struct mii_phy_def bcm5221_phy_de
35343 };
35344
35345 /* Broadcom BCM 5241 */
35346-static struct mii_phy_ops bcm5241_phy_ops = {
35347+static const struct mii_phy_ops bcm5241_phy_ops = {
35348 .suspend = bcm5241_suspend,
35349 .init = bcm5241_init,
35350 .setup_aneg = genmii_setup_aneg,
35351@@ -942,7 +942,7 @@ static struct mii_phy_def bcm5241_phy_de
35352 };
35353
35354 /* Broadcom BCM 5400 */
35355-static struct mii_phy_ops bcm5400_phy_ops = {
35356+static const struct mii_phy_ops bcm5400_phy_ops = {
35357 .init = bcm5400_init,
35358 .suspend = bcm5400_suspend,
35359 .setup_aneg = bcm54xx_setup_aneg,
35360@@ -961,7 +961,7 @@ static struct mii_phy_def bcm5400_phy_de
35361 };
35362
35363 /* Broadcom BCM 5401 */
35364-static struct mii_phy_ops bcm5401_phy_ops = {
35365+static const struct mii_phy_ops bcm5401_phy_ops = {
35366 .init = bcm5401_init,
35367 .suspend = bcm5401_suspend,
35368 .setup_aneg = bcm54xx_setup_aneg,
35369@@ -980,7 +980,7 @@ static struct mii_phy_def bcm5401_phy_de
35370 };
35371
35372 /* Broadcom BCM 5411 */
35373-static struct mii_phy_ops bcm5411_phy_ops = {
35374+static const struct mii_phy_ops bcm5411_phy_ops = {
35375 .init = bcm5411_init,
35376 .suspend = generic_suspend,
35377 .setup_aneg = bcm54xx_setup_aneg,
35378@@ -999,7 +999,7 @@ static struct mii_phy_def bcm5411_phy_de
35379 };
35380
35381 /* Broadcom BCM 5421 */
35382-static struct mii_phy_ops bcm5421_phy_ops = {
35383+static const struct mii_phy_ops bcm5421_phy_ops = {
35384 .init = bcm5421_init,
35385 .suspend = generic_suspend,
35386 .setup_aneg = bcm54xx_setup_aneg,
35387@@ -1019,7 +1019,7 @@ static struct mii_phy_def bcm5421_phy_de
35388 };
35389
35390 /* Broadcom BCM 5421 built-in K2 */
35391-static struct mii_phy_ops bcm5421k2_phy_ops = {
35392+static const struct mii_phy_ops bcm5421k2_phy_ops = {
35393 .init = bcm5421_init,
35394 .suspend = generic_suspend,
35395 .setup_aneg = bcm54xx_setup_aneg,
35396@@ -1037,7 +1037,7 @@ static struct mii_phy_def bcm5421k2_phy_
35397 .ops = &bcm5421k2_phy_ops
35398 };
35399
35400-static struct mii_phy_ops bcm5461_phy_ops = {
35401+static const struct mii_phy_ops bcm5461_phy_ops = {
35402 .init = bcm5421_init,
35403 .suspend = generic_suspend,
35404 .setup_aneg = bcm54xx_setup_aneg,
35405@@ -1057,7 +1057,7 @@ static struct mii_phy_def bcm5461_phy_de
35406 };
35407
35408 /* Broadcom BCM 5462 built-in Vesta */
35409-static struct mii_phy_ops bcm5462V_phy_ops = {
35410+static const struct mii_phy_ops bcm5462V_phy_ops = {
35411 .init = bcm5421_init,
35412 .suspend = generic_suspend,
35413 .setup_aneg = bcm54xx_setup_aneg,
35414@@ -1076,7 +1076,7 @@ static struct mii_phy_def bcm5462V_phy_d
35415 };
35416
35417 /* Marvell 88E1101 amd 88E1111 */
35418-static struct mii_phy_ops marvell88e1101_phy_ops = {
35419+static const struct mii_phy_ops marvell88e1101_phy_ops = {
35420 .suspend = generic_suspend,
35421 .setup_aneg = marvell_setup_aneg,
35422 .setup_forced = marvell_setup_forced,
35423@@ -1084,7 +1084,7 @@ static struct mii_phy_ops marvell88e1101
35424 .read_link = marvell_read_link
35425 };
35426
35427-static struct mii_phy_ops marvell88e1111_phy_ops = {
35428+static const struct mii_phy_ops marvell88e1111_phy_ops = {
35429 .init = marvell88e1111_init,
35430 .suspend = generic_suspend,
35431 .setup_aneg = marvell_setup_aneg,
35432@@ -1122,7 +1122,7 @@ static struct mii_phy_def marvell88e1111
35433 };
35434
35435 /* Generic implementation for most 10/100 PHYs */
35436-static struct mii_phy_ops generic_phy_ops = {
35437+static const struct mii_phy_ops generic_phy_ops = {
35438 .setup_aneg = genmii_setup_aneg,
35439 .setup_forced = genmii_setup_forced,
35440 .poll_link = genmii_poll_link,
35441diff -urNp linux-2.6.39.1/drivers/net/tg3.h linux-2.6.39.1/drivers/net/tg3.h
35442--- linux-2.6.39.1/drivers/net/tg3.h 2011-05-19 00:06:34.000000000 -0400
35443+++ linux-2.6.39.1/drivers/net/tg3.h 2011-05-22 19:36:31.000000000 -0400
35444@@ -131,6 +131,7 @@
35445 #define CHIPREV_ID_5750_A0 0x4000
35446 #define CHIPREV_ID_5750_A1 0x4001
35447 #define CHIPREV_ID_5750_A3 0x4003
35448+#define CHIPREV_ID_5750_C1 0x4201
35449 #define CHIPREV_ID_5750_C2 0x4202
35450 #define CHIPREV_ID_5752_A0_HW 0x5000
35451 #define CHIPREV_ID_5752_A0 0x6000
35452diff -urNp linux-2.6.39.1/drivers/net/tile/tilepro.c linux-2.6.39.1/drivers/net/tile/tilepro.c
35453--- linux-2.6.39.1/drivers/net/tile/tilepro.c 2011-05-19 00:06:34.000000000 -0400
35454+++ linux-2.6.39.1/drivers/net/tile/tilepro.c 2011-05-22 19:36:31.000000000 -0400
35455@@ -2263,7 +2263,7 @@ static int tile_net_get_mac(struct net_d
35456 }
35457
35458
35459-static struct net_device_ops tile_net_ops = {
35460+static const struct net_device_ops tile_net_ops = {
35461 .ndo_open = tile_net_open,
35462 .ndo_stop = tile_net_stop,
35463 .ndo_start_xmit = tile_net_tx,
35464diff -urNp linux-2.6.39.1/drivers/net/tulip/de2104x.c linux-2.6.39.1/drivers/net/tulip/de2104x.c
35465--- linux-2.6.39.1/drivers/net/tulip/de2104x.c 2011-05-19 00:06:34.000000000 -0400
35466+++ linux-2.6.39.1/drivers/net/tulip/de2104x.c 2011-05-22 19:36:31.000000000 -0400
35467@@ -1817,6 +1817,8 @@ static void __devinit de21041_get_srom_i
35468 struct de_srom_info_leaf *il;
35469 void *bufp;
35470
35471+ pax_track_stack();
35472+
35473 /* download entire eeprom */
35474 for (i = 0; i < DE_EEPROM_WORDS; i++)
35475 ((__le16 *)ee_data)[i] =
35476diff -urNp linux-2.6.39.1/drivers/net/tulip/de4x5.c linux-2.6.39.1/drivers/net/tulip/de4x5.c
35477--- linux-2.6.39.1/drivers/net/tulip/de4x5.c 2011-05-19 00:06:34.000000000 -0400
35478+++ linux-2.6.39.1/drivers/net/tulip/de4x5.c 2011-05-22 19:36:31.000000000 -0400
35479@@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
35480 for (i=0; i<ETH_ALEN; i++) {
35481 tmp.addr[i] = dev->dev_addr[i];
35482 }
35483- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35484+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35485 break;
35486
35487 case DE4X5_SET_HWADDR: /* Set the hardware address */
35488@@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
35489 spin_lock_irqsave(&lp->lock, flags);
35490 memcpy(&statbuf, &lp->pktStats, ioc->len);
35491 spin_unlock_irqrestore(&lp->lock, flags);
35492- if (copy_to_user(ioc->data, &statbuf, ioc->len))
35493+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35494 return -EFAULT;
35495 break;
35496 }
35497diff -urNp linux-2.6.39.1/drivers/net/usb/asix.c linux-2.6.39.1/drivers/net/usb/asix.c
35498--- linux-2.6.39.1/drivers/net/usb/asix.c 2011-05-19 00:06:34.000000000 -0400
35499+++ linux-2.6.39.1/drivers/net/usb/asix.c 2011-05-22 19:36:31.000000000 -0400
35500@@ -1098,7 +1098,7 @@ out:
35501 return ret;
35502 }
35503
35504-static struct ethtool_ops ax88178_ethtool_ops = {
35505+static const struct ethtool_ops ax88178_ethtool_ops = {
35506 .get_drvinfo = asix_get_drvinfo,
35507 .get_link = asix_get_link,
35508 .get_msglevel = usbnet_get_msglevel,
35509diff -urNp linux-2.6.39.1/drivers/net/usb/cdc_ncm.c linux-2.6.39.1/drivers/net/usb/cdc_ncm.c
35510--- linux-2.6.39.1/drivers/net/usb/cdc_ncm.c 2011-05-19 00:06:34.000000000 -0400
35511+++ linux-2.6.39.1/drivers/net/usb/cdc_ncm.c 2011-05-22 19:36:31.000000000 -0400
35512@@ -141,7 +141,7 @@ struct cdc_ncm_ctx {
35513 static void cdc_ncm_tx_timeout(unsigned long arg);
35514 static const struct driver_info cdc_ncm_info;
35515 static struct usb_driver cdc_ncm_driver;
35516-static struct ethtool_ops cdc_ncm_ethtool_ops;
35517+static const struct ethtool_ops cdc_ncm_ethtool_ops;
35518
35519 static const struct usb_device_id cdc_devs[] = {
35520 { USB_INTERFACE_INFO(USB_CLASS_COMM,
35521@@ -1257,7 +1257,7 @@ static struct usb_driver cdc_ncm_driver
35522 .supports_autosuspend = 1,
35523 };
35524
35525-static struct ethtool_ops cdc_ncm_ethtool_ops = {
35526+static const struct ethtool_ops cdc_ncm_ethtool_ops = {
35527 .get_drvinfo = cdc_ncm_get_drvinfo,
35528 .get_link = usbnet_get_link,
35529 .get_msglevel = usbnet_get_msglevel,
35530diff -urNp linux-2.6.39.1/drivers/net/usb/hso.c linux-2.6.39.1/drivers/net/usb/hso.c
35531--- linux-2.6.39.1/drivers/net/usb/hso.c 2011-05-19 00:06:34.000000000 -0400
35532+++ linux-2.6.39.1/drivers/net/usb/hso.c 2011-05-22 19:36:31.000000000 -0400
35533@@ -71,7 +71,7 @@
35534 #include <asm/byteorder.h>
35535 #include <linux/serial_core.h>
35536 #include <linux/serial.h>
35537-
35538+#include <asm/local.h>
35539
35540 #define MOD_AUTHOR "Option Wireless"
35541 #define MOD_DESCRIPTION "USB High Speed Option driver"
35542@@ -257,7 +257,7 @@ struct hso_serial {
35543
35544 /* from usb_serial_port */
35545 struct tty_struct *tty;
35546- int open_count;
35547+ local_t open_count;
35548 spinlock_t serial_lock;
35549
35550 int (*write_data) (struct hso_serial *serial);
35551@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_
35552 struct urb *urb;
35553
35554 urb = serial->rx_urb[0];
35555- if (serial->open_count > 0) {
35556+ if (local_read(&serial->open_count) > 0) {
35557 count = put_rxbuf_data(urb, serial);
35558 if (count == -1)
35559 return;
35560@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_cal
35561 DUMP1(urb->transfer_buffer, urb->actual_length);
35562
35563 /* Anyone listening? */
35564- if (serial->open_count == 0)
35565+ if (local_read(&serial->open_count) == 0)
35566 return;
35567
35568 if (status == 0) {
35569@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35570 spin_unlock_irq(&serial->serial_lock);
35571
35572 /* check for port already opened, if not set the termios */
35573- serial->open_count++;
35574- if (serial->open_count == 1) {
35575+ if (local_inc_return(&serial->open_count) == 1) {
35576 serial->rx_state = RX_IDLE;
35577 /* Force default termio settings */
35578 _hso_serial_set_termios(tty, NULL);
35579@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_st
35580 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35581 if (result) {
35582 hso_stop_serial_device(serial->parent);
35583- serial->open_count--;
35584+ local_dec(&serial->open_count);
35585 kref_put(&serial->parent->ref, hso_serial_ref_free);
35586 }
35587 } else {
35588@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_
35589
35590 /* reset the rts and dtr */
35591 /* do the actual close */
35592- serial->open_count--;
35593+ local_dec(&serial->open_count);
35594
35595- if (serial->open_count <= 0) {
35596- serial->open_count = 0;
35597+ if (local_read(&serial->open_count) <= 0) {
35598+ local_set(&serial->open_count, 0);
35599 spin_lock_irq(&serial->serial_lock);
35600 if (serial->tty == tty) {
35601 serial->tty->driver_data = NULL;
35602@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struc
35603
35604 /* the actual setup */
35605 spin_lock_irqsave(&serial->serial_lock, flags);
35606- if (serial->open_count)
35607+ if (local_read(&serial->open_count))
35608 _hso_serial_set_termios(tty, old);
35609 else
35610 tty->termios = old;
35611@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *ur
35612 D1("Pending read interrupt on port %d\n", i);
35613 spin_lock(&serial->serial_lock);
35614 if (serial->rx_state == RX_IDLE &&
35615- serial->open_count > 0) {
35616+ local_read(&serial->open_count) > 0) {
35617 /* Setup and send a ctrl req read on
35618 * port i */
35619 if (!serial->rx_urb_filled[0]) {
35620@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35621 /* Start all serial ports */
35622 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35623 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35624- if (dev2ser(serial_table[i])->open_count) {
35625+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35626 result =
35627 hso_start_serial_device(serial_table[i], GFP_NOIO);
35628 hso_kick_transmit(dev2ser(serial_table[i]));
35629diff -urNp linux-2.6.39.1/drivers/net/usb/ipheth.c linux-2.6.39.1/drivers/net/usb/ipheth.c
35630--- linux-2.6.39.1/drivers/net/usb/ipheth.c 2011-05-19 00:06:34.000000000 -0400
35631+++ linux-2.6.39.1/drivers/net/usb/ipheth.c 2011-05-22 19:36:31.000000000 -0400
35632@@ -421,7 +421,7 @@ static u32 ipheth_ethtool_op_get_link(st
35633 return netif_carrier_ok(dev->net);
35634 }
35635
35636-static struct ethtool_ops ops = {
35637+static const struct ethtool_ops ops = {
35638 .get_link = ipheth_ethtool_op_get_link
35639 };
35640
35641diff -urNp linux-2.6.39.1/drivers/net/usb/sierra_net.c linux-2.6.39.1/drivers/net/usb/sierra_net.c
35642--- linux-2.6.39.1/drivers/net/usb/sierra_net.c 2011-05-19 00:06:34.000000000 -0400
35643+++ linux-2.6.39.1/drivers/net/usb/sierra_net.c 2011-05-22 19:36:31.000000000 -0400
35644@@ -618,7 +618,7 @@ static u32 sierra_net_get_link(struct ne
35645 return sierra_net_get_private(dev)->link_up && netif_running(net);
35646 }
35647
35648-static struct ethtool_ops sierra_net_ethtool_ops = {
35649+static const struct ethtool_ops sierra_net_ethtool_ops = {
35650 .get_drvinfo = sierra_net_get_drvinfo,
35651 .get_link = sierra_net_get_link,
35652 .get_msglevel = usbnet_get_msglevel,
35653diff -urNp linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c
35654--- linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35655+++ linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35656@@ -631,8 +631,7 @@ vmxnet3_set_rss_indir(struct net_device
35657 * Return with error code if any of the queue indices
35658 * is out of range
35659 */
35660- if (p->ring_index[i] < 0 ||
35661- p->ring_index[i] >= adapter->num_rx_queues)
35662+ if (p->ring_index[i] >= adapter->num_rx_queues)
35663 return -EINVAL;
35664 }
35665
35666diff -urNp linux-2.6.39.1/drivers/net/vxge/vxge-main.c linux-2.6.39.1/drivers/net/vxge/vxge-main.c
35667--- linux-2.6.39.1/drivers/net/vxge/vxge-main.c 2011-05-19 00:06:34.000000000 -0400
35668+++ linux-2.6.39.1/drivers/net/vxge/vxge-main.c 2011-05-22 19:36:31.000000000 -0400
35669@@ -97,6 +97,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35670 struct sk_buff *completed[NR_SKB_COMPLETED];
35671 int more;
35672
35673+ pax_track_stack();
35674+
35675 do {
35676 more = 0;
35677 skb_ptr = completed;
35678@@ -1927,6 +1929,8 @@ static enum vxge_hw_status vxge_rth_conf
35679 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35680 int index;
35681
35682+ pax_track_stack();
35683+
35684 /*
35685 * Filling
35686 * - itable with bucket numbers
35687diff -urNp linux-2.6.39.1/drivers/net/wan/cycx_x25.c linux-2.6.39.1/drivers/net/wan/cycx_x25.c
35688--- linux-2.6.39.1/drivers/net/wan/cycx_x25.c 2011-05-19 00:06:34.000000000 -0400
35689+++ linux-2.6.39.1/drivers/net/wan/cycx_x25.c 2011-05-22 19:36:31.000000000 -0400
35690@@ -1018,6 +1018,8 @@ static void hex_dump(char *msg, unsigned
35691 unsigned char hex[1024],
35692 * phex = hex;
35693
35694+ pax_track_stack();
35695+
35696 if (len >= (sizeof(hex) / 2))
35697 len = (sizeof(hex) / 2) - 1;
35698
35699diff -urNp linux-2.6.39.1/drivers/net/wan/lapbether.c linux-2.6.39.1/drivers/net/wan/lapbether.c
35700--- linux-2.6.39.1/drivers/net/wan/lapbether.c 2011-05-19 00:06:34.000000000 -0400
35701+++ linux-2.6.39.1/drivers/net/wan/lapbether.c 2011-05-22 19:36:31.000000000 -0400
35702@@ -259,7 +259,7 @@ static int lapbeth_set_mac_address(struc
35703 }
35704
35705
35706-static struct lapb_register_struct lapbeth_callbacks = {
35707+static const struct lapb_register_struct lapbeth_callbacks = {
35708 .connect_confirmation = lapbeth_connected,
35709 .connect_indication = lapbeth_connected,
35710 .disconnect_confirmation = lapbeth_disconnected,
35711diff -urNp linux-2.6.39.1/drivers/net/wan/x25_asy.c linux-2.6.39.1/drivers/net/wan/x25_asy.c
35712--- linux-2.6.39.1/drivers/net/wan/x25_asy.c 2011-05-19 00:06:34.000000000 -0400
35713+++ linux-2.6.39.1/drivers/net/wan/x25_asy.c 2011-05-22 19:36:31.000000000 -0400
35714@@ -434,7 +434,7 @@ static void x25_asy_disconnected(struct
35715 netif_rx(skb);
35716 }
35717
35718-static struct lapb_register_struct x25_asy_callbacks = {
35719+static const struct lapb_register_struct x25_asy_callbacks = {
35720 .connect_confirmation = x25_asy_connected,
35721 .connect_indication = x25_asy_connected,
35722 .disconnect_confirmation = x25_asy_disconnected,
35723diff -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
35724--- linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c 2011-05-19 00:06:34.000000000 -0400
35725+++ linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c 2011-05-22 19:36:31.000000000 -0400
35726@@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35727 int do_autopm = 1;
35728 DECLARE_COMPLETION_ONSTACK(notif_completion);
35729
35730+ pax_track_stack();
35731+
35732 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35733 i2400m, ack, ack_size);
35734 BUG_ON(_ack == i2400m->bm_ack_buf);
35735diff -urNp linux-2.6.39.1/drivers/net/wireless/airo.c linux-2.6.39.1/drivers/net/wireless/airo.c
35736--- linux-2.6.39.1/drivers/net/wireless/airo.c 2011-05-19 00:06:34.000000000 -0400
35737+++ linux-2.6.39.1/drivers/net/wireless/airo.c 2011-05-22 19:36:31.000000000 -0400
35738@@ -3001,6 +3001,8 @@ static void airo_process_scan_results (s
35739 BSSListElement * loop_net;
35740 BSSListElement * tmp_net;
35741
35742+ pax_track_stack();
35743+
35744 /* Blow away current list of scan results */
35745 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35746 list_move_tail (&loop_net->list, &ai->network_free_list);
35747@@ -3792,6 +3794,8 @@ static u16 setup_card(struct airo_info *
35748 WepKeyRid wkr;
35749 int rc;
35750
35751+ pax_track_stack();
35752+
35753 memset( &mySsid, 0, sizeof( mySsid ) );
35754 kfree (ai->flash);
35755 ai->flash = NULL;
35756@@ -4760,6 +4764,8 @@ static int proc_stats_rid_open( struct i
35757 __le32 *vals = stats.vals;
35758 int len;
35759
35760+ pax_track_stack();
35761+
35762 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35763 return -ENOMEM;
35764 data = file->private_data;
35765@@ -5483,6 +5489,8 @@ static int proc_BSSList_open( struct ino
35766 /* If doLoseSync is not 1, we won't do a Lose Sync */
35767 int doLoseSync = -1;
35768
35769+ pax_track_stack();
35770+
35771 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35772 return -ENOMEM;
35773 data = file->private_data;
35774@@ -7190,6 +7198,8 @@ static int airo_get_aplist(struct net_de
35775 int i;
35776 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35777
35778+ pax_track_stack();
35779+
35780 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35781 if (!qual)
35782 return -ENOMEM;
35783@@ -7750,6 +7760,8 @@ static void airo_read_wireless_stats(str
35784 CapabilityRid cap_rid;
35785 __le32 *vals = stats_rid.vals;
35786
35787+ pax_track_stack();
35788+
35789 /* Get stats out of the card */
35790 clear_bit(JOB_WSTATS, &local->jobs);
35791 if (local->power.event) {
35792diff -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
35793--- linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c 2011-05-19 00:06:34.000000000 -0400
35794+++ linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c 2011-05-22 19:36:31.000000000 -0400
35795@@ -204,6 +204,8 @@ static ssize_t read_file_beacon(struct f
35796 unsigned int v;
35797 u64 tsf;
35798
35799+ pax_track_stack();
35800+
35801 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35802 len += snprintf(buf+len, sizeof(buf)-len,
35803 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35804@@ -323,6 +325,8 @@ static ssize_t read_file_debug(struct fi
35805 unsigned int len = 0;
35806 unsigned int i;
35807
35808+ pax_track_stack();
35809+
35810 len += snprintf(buf+len, sizeof(buf)-len,
35811 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35812
35813@@ -384,6 +388,8 @@ static ssize_t read_file_antenna(struct
35814 unsigned int i;
35815 unsigned int v;
35816
35817+ pax_track_stack();
35818+
35819 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
35820 sc->ah->ah_ant_mode);
35821 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
35822@@ -494,6 +500,8 @@ static ssize_t read_file_misc(struct fil
35823 unsigned int len = 0;
35824 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
35825
35826+ pax_track_stack();
35827+
35828 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
35829 sc->bssidmask);
35830 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
35831@@ -550,6 +558,8 @@ static ssize_t read_file_frameerrors(str
35832 unsigned int len = 0;
35833 int i;
35834
35835+ pax_track_stack();
35836+
35837 len += snprintf(buf+len, sizeof(buf)-len,
35838 "RX\n---------------------\n");
35839 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
35840@@ -667,6 +677,8 @@ static ssize_t read_file_ani(struct file
35841 char buf[700];
35842 unsigned int len = 0;
35843
35844+ pax_track_stack();
35845+
35846 len += snprintf(buf+len, sizeof(buf)-len,
35847 "HW has PHY error counters:\t%s\n",
35848 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
35849@@ -827,6 +839,8 @@ static ssize_t read_file_queue(struct fi
35850 struct ath5k_buf *bf, *bf0;
35851 int i, n;
35852
35853+ pax_track_stack();
35854+
35855 len += snprintf(buf+len, sizeof(buf)-len,
35856 "available txbuffers: %d\n", sc->txbuf_len);
35857
35858diff -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
35859--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-19 00:06:34.000000000 -0400
35860+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-22 19:36:31.000000000 -0400
35861@@ -734,6 +734,8 @@ static void ar9003_hw_tx_iq_cal(struct a
35862 s32 i, j, ip, im, nmeasurement;
35863 u8 nchains = get_streams(common->tx_chainmask);
35864
35865+ pax_track_stack();
35866+
35867 for (ip = 0; ip < MPASS; ip++) {
35868 REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
35869 AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
35870@@ -856,6 +858,8 @@ static void ar9003_hw_tx_iq_cal_post_pro
35871 int i, ip, im, j;
35872 int nmeasurement;
35873
35874+ pax_track_stack();
35875+
35876 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
35877 if (ah->txchainmask & (1 << i))
35878 num_chains++;
35879diff -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
35880--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-19 00:06:34.000000000 -0400
35881+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-22 19:36:31.000000000 -0400
35882@@ -356,6 +356,8 @@ static bool create_pa_curve(u32 *data_L,
35883 int theta_low_bin = 0;
35884 int i;
35885
35886+ pax_track_stack();
35887+
35888 /* disregard any bin that contains <= 16 samples */
35889 thresh_accum_cnt = 16;
35890 scale_factor = 5;
35891diff -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
35892--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c 2011-05-19 00:06:34.000000000 -0400
35893+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c 2011-05-22 19:36:31.000000000 -0400
35894@@ -335,6 +335,8 @@ static ssize_t read_file_interrupt(struc
35895 char buf[512];
35896 unsigned int len = 0;
35897
35898+ pax_track_stack();
35899+
35900 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
35901 len += snprintf(buf + len, sizeof(buf) - len,
35902 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
35903@@ -422,6 +424,8 @@ static ssize_t read_file_wiphy(struct fi
35904 u8 addr[ETH_ALEN];
35905 u32 tmp;
35906
35907+ pax_track_stack();
35908+
35909 len += snprintf(buf + len, sizeof(buf) - len,
35910 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
35911 wiphy_name(sc->hw->wiphy),
35912diff -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
35913--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-19 00:06:34.000000000 -0400
35914+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-22 19:36:31.000000000 -0400
35915@@ -737,6 +737,8 @@ static ssize_t read_file_tgt_stats(struc
35916 unsigned int len = 0;
35917 int ret = 0;
35918
35919+ pax_track_stack();
35920+
35921 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
35922
35923 WMI_CMD(WMI_TGT_STATS_CMDID);
35924@@ -782,6 +784,8 @@ static ssize_t read_file_xmit(struct fil
35925 char buf[512];
35926 unsigned int len = 0;
35927
35928+ pax_track_stack();
35929+
35930 len += snprintf(buf + len, sizeof(buf) - len,
35931 "%20s : %10u\n", "Buffers queued",
35932 priv->debug.tx_stats.buf_queued);
35933@@ -831,6 +835,8 @@ static ssize_t read_file_recv(struct fil
35934 char buf[512];
35935 unsigned int len = 0;
35936
35937+ pax_track_stack();
35938+
35939 len += snprintf(buf + len, sizeof(buf) - len,
35940 "%20s : %10u\n", "SKBs allocated",
35941 priv->debug.rx_stats.skb_allocated);
35942@@ -1816,7 +1822,7 @@ static void ath9k_htc_set_coverage_class
35943 mutex_unlock(&priv->mutex);
35944 }
35945
35946-struct ieee80211_ops ath9k_htc_ops = {
35947+const struct ieee80211_ops ath9k_htc_ops = {
35948 .tx = ath9k_htc_tx,
35949 .start = ath9k_htc_start,
35950 .stop = ath9k_htc_stop,
35951diff -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
35952--- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h 2011-05-19 00:06:34.000000000 -0400
35953+++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h 2011-05-22 19:36:31.000000000 -0400
35954@@ -42,7 +42,7 @@
35955 #define TSF_TO_TU(_h, _l) \
35956 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
35957
35958-extern struct ieee80211_ops ath9k_htc_ops;
35959+extern const struct ieee80211_ops ath9k_htc_ops;
35960 extern int htc_modparam_nohwcrypt;
35961
35962 enum htc_phymode {
35963diff -urNp linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c
35964--- linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35965+++ linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35966@@ -43,7 +43,7 @@ static struct dentry *rootdir;
35967 struct b43_debugfs_fops {
35968 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35969 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35970- struct file_operations fops;
35971+ const struct file_operations fops;
35972 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35973 size_t file_struct_offset;
35974 };
35975diff -urNp linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c
35976--- linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35977+++ linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35978@@ -44,7 +44,7 @@ static struct dentry *rootdir;
35979 struct b43legacy_debugfs_fops {
35980 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35981 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35982- struct file_operations fops;
35983+ const struct file_operations fops;
35984 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35985 size_t file_struct_offset;
35986 /* Take wl->irq_lock before calling read/write? */
35987diff -urNp linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c
35988--- linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-19 00:06:34.000000000 -0400
35989+++ linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-22 19:36:31.000000000 -0400
35990@@ -2100,6 +2100,8 @@ static int ipw2100_set_essid(struct ipw2
35991 int err;
35992 DECLARE_SSID_BUF(ssid);
35993
35994+ pax_track_stack();
35995+
35996 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35997
35998 if (ssid_len)
35999@@ -5449,6 +5451,8 @@ static int ipw2100_set_key(struct ipw210
36000 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
36001 int err;
36002
36003+ pax_track_stack();
36004+
36005 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
36006 idx, keylen, len);
36007
36008diff -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
36009--- linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-19 00:06:34.000000000 -0400
36010+++ linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-22 19:36:31.000000000 -0400
36011@@ -1565,6 +1565,8 @@ static void libipw_process_probe_respons
36012 unsigned long flags;
36013 DECLARE_SSID_BUF(ssid);
36014
36015+ pax_track_stack();
36016+
36017 LIBIPW_DEBUG_SCAN("'%s' (%pM"
36018 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
36019 print_ssid(ssid, info_element->data, info_element->len),
36020diff -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
36021--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-19 00:06:34.000000000 -0400
36022+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-22 19:36:31.000000000 -0400
36023@@ -2630,7 +2630,7 @@ static int iwl3945_load_bsm(struct iwl_p
36024 return 0;
36025 }
36026
36027-static struct iwl_hcmd_ops iwl3945_hcmd = {
36028+static const struct iwl_hcmd_ops iwl3945_hcmd = {
36029 .rxon_assoc = iwl3945_send_rxon_assoc,
36030 .commit_rxon = iwl3945_commit_rxon,
36031 };
36032@@ -2675,7 +2675,7 @@ static const struct iwl_legacy_ops iwl39
36033 .manage_ibss_station = iwl3945_manage_ibss_station,
36034 };
36035
36036-static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
36037+static const struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
36038 .get_hcmd_size = iwl3945_get_hcmd_size,
36039 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
36040 .request_scan = iwl3945_request_scan,
36041diff -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
36042--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-19 00:06:34.000000000 -0400
36043+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-22 19:36:32.000000000 -0400
36044@@ -1904,7 +1904,7 @@ static void iwl4965_rx_handler_setup(str
36045 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
36046 }
36047
36048-static struct iwl_hcmd_ops iwl4965_hcmd = {
36049+static const struct iwl_hcmd_ops iwl4965_hcmd = {
36050 .rxon_assoc = iwl4965_send_rxon_assoc,
36051 .commit_rxon = iwl4965_commit_rxon,
36052 .set_rxon_chain = iwl4965_set_rxon_chain,
36053@@ -2056,7 +2056,7 @@ static void iwl4965_config_ap(struct iwl
36054 iwl4965_send_beacon_cmd(priv);
36055 }
36056
36057-static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
36058+static const struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
36059 .get_hcmd_size = iwl4965_get_hcmd_size,
36060 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
36061 .request_scan = iwl4965_request_scan,
36062@@ -2114,7 +2114,7 @@ static const struct iwl_legacy_ops iwl49
36063 .update_bcast_stations = iwl4965_update_bcast_stations,
36064 };
36065
36066-struct ieee80211_ops iwl4965_hw_ops = {
36067+const struct ieee80211_ops iwl4965_hw_ops = {
36068 .tx = iwl4965_mac_tx,
36069 .start = iwl4965_mac_start,
36070 .stop = iwl4965_mac_stop,
36071diff -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
36072--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-19 00:06:34.000000000 -0400
36073+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-22 19:36:32.000000000 -0400
36074@@ -70,7 +70,7 @@ extern struct iwl_cfg iwl4965_cfg;
36075
36076 extern struct iwl_mod_params iwl4965_mod_params;
36077
36078-extern struct ieee80211_ops iwl4965_hw_ops;
36079+extern const struct ieee80211_ops iwl4965_hw_ops;
36080
36081 /* tx queue */
36082 void iwl4965_free_tfds_in_queue(struct iwl_priv *priv,
36083diff -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
36084--- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36085+++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36086@@ -150,7 +150,7 @@ struct iwl_lib_ops {
36087 int (*set_channel_switch)(struct iwl_priv *priv,
36088 struct ieee80211_channel_switch *ch_switch);
36089 /* power management */
36090- struct iwl_apm_ops apm_ops;
36091+ const struct iwl_apm_ops apm_ops;
36092
36093 /* power */
36094 int (*send_tx_power) (struct iwl_priv *priv);
36095@@ -160,12 +160,12 @@ struct iwl_lib_ops {
36096 struct iwl_eeprom_ops eeprom_ops;
36097
36098 /* temperature */
36099- struct iwl_temp_ops temp_ops;
36100+ const struct iwl_temp_ops temp_ops;
36101 /* check for plcp health */
36102 bool (*check_plcp_health)(struct iwl_priv *priv,
36103 struct iwl_rx_packet *pkt);
36104
36105- struct iwl_debugfs_ops debugfs_ops;
36106+ const struct iwl_debugfs_ops debugfs_ops;
36107
36108 };
36109
36110diff -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
36111--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-19 00:06:34.000000000 -0400
36112+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-22 19:36:32.000000000 -0400
36113@@ -422,11 +422,11 @@ static struct iwl_lib_ops iwl6030_lib =
36114 }
36115 };
36116
36117-static struct iwl_nic_ops iwl6050_nic_ops = {
36118+static const struct iwl_nic_ops iwl6050_nic_ops = {
36119 .additional_nic_config = &iwl6050_additional_nic_config,
36120 };
36121
36122-static struct iwl_nic_ops iwl6150_nic_ops = {
36123+static const struct iwl_nic_ops iwl6150_nic_ops = {
36124 .additional_nic_config = &iwl6150_additional_nic_config,
36125 };
36126
36127diff -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
36128--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-19 00:06:34.000000000 -0400
36129+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-22 19:36:32.000000000 -0400
36130@@ -109,9 +109,9 @@ extern struct iwl_cfg iwl230_bg_cfg;
36131 extern struct iwl_cfg iwl230_bgn_cfg;
36132
36133 extern struct iwl_mod_params iwlagn_mod_params;
36134-extern struct iwl_hcmd_ops iwlagn_hcmd;
36135-extern struct iwl_hcmd_ops iwlagn_bt_hcmd;
36136-extern struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36137+extern const struct iwl_hcmd_ops iwlagn_hcmd;
36138+extern const struct iwl_hcmd_ops iwlagn_bt_hcmd;
36139+extern const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36140
36141 extern struct ieee80211_ops iwlagn_hw_ops;
36142 extern struct ieee80211_ops iwl4965_hw_ops;
36143diff -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
36144--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-19 00:06:34.000000000 -0400
36145+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-22 19:36:32.000000000 -0400
36146@@ -363,7 +363,7 @@ static int iwlagn_set_pan_params(struct
36147 return ret;
36148 }
36149
36150-struct iwl_hcmd_ops iwlagn_hcmd = {
36151+const struct iwl_hcmd_ops iwlagn_hcmd = {
36152 .rxon_assoc = iwlagn_send_rxon_assoc,
36153 .commit_rxon = iwlagn_commit_rxon,
36154 .set_rxon_chain = iwlagn_set_rxon_chain,
36155@@ -372,7 +372,7 @@ struct iwl_hcmd_ops iwlagn_hcmd = {
36156 .set_pan_params = iwlagn_set_pan_params,
36157 };
36158
36159-struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36160+const struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36161 .rxon_assoc = iwlagn_send_rxon_assoc,
36162 .commit_rxon = iwlagn_commit_rxon,
36163 .set_rxon_chain = iwlagn_set_rxon_chain,
36164@@ -381,7 +381,7 @@ struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36165 .set_pan_params = iwlagn_set_pan_params,
36166 };
36167
36168-struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36169+const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36170 .get_hcmd_size = iwlagn_get_hcmd_size,
36171 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
36172 .gain_computation = iwlagn_gain_computation,
36173diff -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
36174--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-19 00:06:34.000000000 -0400
36175+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-22 19:36:32.000000000 -0400
36176@@ -883,6 +883,8 @@ static void rs_tx_status(void *priv_r, s
36177 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
36178 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
36179
36180+ pax_track_stack();
36181+
36182 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
36183
36184 /* Treat uninitialized rate scaling data same as non-existing. */
36185@@ -2894,6 +2896,8 @@ static void rs_fill_link_cmd(struct iwl_
36186 container_of(lq_sta, struct iwl_station_priv, lq_sta);
36187 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
36188
36189+ pax_track_stack();
36190+
36191 /* Override starting rate (index 0) if needed for debug purposes */
36192 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
36193
36194diff -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
36195--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36196+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36197@@ -198,28 +198,25 @@ struct iwl_lib_ops {
36198 int (*set_channel_switch)(struct iwl_priv *priv,
36199 struct ieee80211_channel_switch *ch_switch);
36200 /* power management */
36201- struct iwl_apm_ops apm_ops;
36202+ const struct iwl_apm_ops apm_ops;
36203
36204 /* power */
36205 int (*send_tx_power) (struct iwl_priv *priv);
36206 void (*update_chain_flags)(struct iwl_priv *priv);
36207
36208 /* isr */
36209- struct iwl_isr_ops isr_ops;
36210+ const struct iwl_isr_ops isr_ops;
36211
36212 /* eeprom operations (as defined in iwl-eeprom.h) */
36213 struct iwl_eeprom_ops eeprom_ops;
36214
36215 /* temperature */
36216- struct iwl_temp_ops temp_ops;
36217+ const struct iwl_temp_ops temp_ops;
36218
36219 int (*txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36220 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36221
36222- struct iwl_debugfs_ops debugfs_ops;
36223-
36224- /* thermal throttling */
36225- struct iwl_tt_ops tt_ops;
36226+ const struct iwl_debugfs_ops debugfs_ops;const struct iwl_tt_ops tt_ops;
36227 };
36228
36229 struct iwl_led_ops {
36230diff -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
36231--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-19 00:06:34.000000000 -0400
36232+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-22 19:36:32.000000000 -0400
36233@@ -549,6 +549,8 @@ static ssize_t iwl_dbgfs_status_read(str
36234 int pos = 0;
36235 const size_t bufsz = sizeof(buf);
36236
36237+ pax_track_stack();
36238+
36239 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
36240 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
36241 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
36242@@ -681,6 +683,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
36243 char buf[256 * NUM_IWL_RXON_CTX];
36244 const size_t bufsz = sizeof(buf);
36245
36246+ pax_track_stack();
36247+
36248 for_each_context(priv, ctx) {
36249 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
36250 ctx->ctxid);
36251diff -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
36252--- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-19 00:06:34.000000000 -0400
36253+++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-22 19:36:32.000000000 -0400
36254@@ -68,8 +68,8 @@ do {
36255 } while (0)
36256
36257 #else
36258-#define IWL_DEBUG(__priv, level, fmt, args...)
36259-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
36260+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
36261+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
36262 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
36263 const void *p, u32 len)
36264 {}
36265diff -urNp linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c
36266--- linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
36267+++ linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
36268@@ -763,7 +763,7 @@ static int iwm_cfg80211_flush_pmksa(stru
36269 }
36270
36271
36272-static struct cfg80211_ops iwm_cfg80211_ops = {
36273+static const struct cfg80211_ops iwm_cfg80211_ops = {
36274 .change_virtual_intf = iwm_cfg80211_change_iface,
36275 .add_key = iwm_cfg80211_add_key,
36276 .get_key = iwm_cfg80211_get_key,
36277diff -urNp linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c
36278--- linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36279+++ linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36280@@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
36281 int buf_len = 512;
36282 size_t len = 0;
36283
36284+ pax_track_stack();
36285+
36286 if (*ppos != 0)
36287 return 0;
36288 if (count < sizeof(buf))
36289diff -urNp linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c
36290--- linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c 2011-05-19 00:06:34.000000000 -0400
36291+++ linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c 2011-05-22 19:36:32.000000000 -0400
36292@@ -2003,7 +2003,7 @@ static int lbs_leave_ibss(struct wiphy *
36293 * Initialization
36294 */
36295
36296-static struct cfg80211_ops lbs_cfg80211_ops = {
36297+static const struct cfg80211_ops lbs_cfg80211_ops = {
36298 .set_channel = lbs_cfg_set_channel,
36299 .scan = lbs_cfg_scan,
36300 .connect = lbs_cfg_connect,
36301diff -urNp linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c
36302--- linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36303+++ linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36304@@ -702,7 +702,7 @@ out_unlock:
36305 struct lbs_debugfs_files {
36306 const char *name;
36307 int perm;
36308- struct file_operations fops;
36309+ const struct file_operations fops;
36310 };
36311
36312 static const struct lbs_debugfs_files debugfs_files[] = {
36313diff -urNp linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c
36314--- linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c 2011-05-19 00:06:34.000000000 -0400
36315+++ linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c 2011-05-22 19:36:32.000000000 -0400
36316@@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbn
36317
36318 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36319
36320- if (rts_threshold < 0 || rts_threshold > 2347)
36321+ if (rts_threshold > 2347)
36322 rts_threshold = 2347;
36323
36324 tmp = cpu_to_le32(rts_threshold);
36325diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c
36326--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c 2011-05-19 00:06:34.000000000 -0400
36327+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c 2011-05-22 19:36:32.000000000 -0400
36328@@ -1869,7 +1869,7 @@ int rtl_pci_resume(struct pci_dev *pdev)
36329 }
36330 EXPORT_SYMBOL(rtl_pci_resume);
36331
36332-struct rtl_intf_ops rtl_pci_ops = {
36333+const struct rtl_intf_ops rtl_pci_ops = {
36334 .adapter_start = rtl_pci_start,
36335 .adapter_stop = rtl_pci_stop,
36336 .adapter_tx = rtl_pci_tx,
36337diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h
36338--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h 2011-05-19 00:06:34.000000000 -0400
36339+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h 2011-05-22 19:36:32.000000000 -0400
36340@@ -234,7 +234,7 @@ struct rtl_pci_priv {
36341
36342 int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
36343
36344-extern struct rtl_intf_ops rtl_pci_ops;
36345+extern const struct rtl_intf_ops rtl_pci_ops;
36346
36347 int __devinit rtl_pci_probe(struct pci_dev *pdev,
36348 const struct pci_device_id *id);
36349diff -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
36350--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-19 00:06:34.000000000 -0400
36351+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-22 19:36:32.000000000 -0400
36352@@ -827,6 +827,8 @@ static bool _rtl92c_phy_sw_chnl_step_by_
36353 u8 rfpath;
36354 u8 num_total_rfpath = rtlphy->num_total_rfpath;
36355
36356+ pax_track_stack();
36357+
36358 precommoncmdcnt = 0;
36359 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
36360 MAX_PRECMD_CNT,
36361diff -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
36362--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-19 00:06:34.000000000 -0400
36363+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-22 19:36:32.000000000 -0400
36364@@ -96,7 +96,7 @@ void rtl92c_deinit_sw_vars(struct ieee80
36365 }
36366 }
36367
36368-static struct rtl_hal_ops rtl8192ce_hal_ops = {
36369+static const struct rtl_hal_ops rtl8192ce_hal_ops = {
36370 .init_sw_vars = rtl92c_init_sw_vars,
36371 .deinit_sw_vars = rtl92c_deinit_sw_vars,
36372 .read_eeprom_info = rtl92ce_read_eeprom_info,
36373@@ -151,7 +151,7 @@ static struct rtl_mod_params rtl92ce_mod
36374 .sw_crypto = 0,
36375 };
36376
36377-static struct rtl_hal_cfg rtl92ce_hal_cfg = {
36378+static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
36379 .name = "rtl92c_pci",
36380 .fw_name = "rtlwifi/rtl8192cfw.bin",
36381 .ops = &rtl8192ce_hal_ops,
36382diff -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
36383--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-19 00:06:34.000000000 -0400
36384+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-22 19:36:32.000000000 -0400
36385@@ -77,7 +77,7 @@ static void rtl92cu_deinit_sw_vars(struc
36386 }
36387 }
36388
36389-static struct rtl_hal_ops rtl8192cu_hal_ops = {
36390+static const struct rtl_hal_ops rtl8192cu_hal_ops = {
36391 .init_sw_vars = rtl92cu_init_sw_vars,
36392 .deinit_sw_vars = rtl92cu_deinit_sw_vars,
36393 .read_chip_version = rtl92c_read_chip_version,
36394@@ -147,7 +147,7 @@ static struct rtl_hal_usbint_cfg rtl92cu
36395 .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
36396 };
36397
36398-static struct rtl_hal_cfg rtl92cu_hal_cfg = {
36399+static const struct rtl_hal_cfg rtl92cu_hal_cfg = {
36400 .name = "rtl92c_usb",
36401 .fw_name = "rtlwifi/rtl8192cufw.bin",
36402 .ops = &rtl8192cu_hal_ops,
36403diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c
36404--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c 2011-05-19 00:06:34.000000000 -0400
36405+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c 2011-05-22 19:36:32.000000000 -0400
36406@@ -913,7 +913,7 @@ static bool rtl_usb_tx_chk_waitq_insert(
36407 return false;
36408 }
36409
36410-static struct rtl_intf_ops rtl_usb_ops = {
36411+static const struct rtl_intf_ops rtl_usb_ops = {
36412 .adapter_start = rtl_usb_start,
36413 .adapter_stop = rtl_usb_stop,
36414 .adapter_tx = rtl_usb_tx,
36415diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h
36416--- linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h 2011-05-19 00:06:34.000000000 -0400
36417+++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h 2011-05-22 19:36:32.000000000 -0400
36418@@ -1447,7 +1447,7 @@ struct rtl_hal_cfg {
36419 u8 bar_id;
36420 char *name;
36421 char *fw_name;
36422- struct rtl_hal_ops *ops;
36423+ const struct rtl_hal_ops *ops;
36424 struct rtl_mod_params *mod_params;
36425 struct rtl_hal_usbint_cfg *usb_interface_cfg;
36426
36427@@ -1533,7 +1533,7 @@ struct rtl_priv {
36428 *intf_ops : for diff interrface usb/pcie
36429 */
36430 struct rtl_hal_cfg *cfg;
36431- struct rtl_intf_ops *intf_ops;
36432+ const struct rtl_intf_ops *intf_ops;
36433
36434 /*this var will be set by set_bit,
36435 and was used to indicate status of
36436diff -urNp linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c
36437--- linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c 2011-05-19 00:06:34.000000000 -0400
36438+++ linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c 2011-05-22 19:36:32.000000000 -0400
36439@@ -280,6 +280,8 @@ static void wl1271_spi_raw_write(struct
36440 u32 chunk_len;
36441 int i;
36442
36443+ pax_track_stack();
36444+
36445 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
36446
36447 spi_message_init(&m);
36448diff -urNp linux-2.6.39.1/drivers/net/xen-netback/interface.c linux-2.6.39.1/drivers/net/xen-netback/interface.c
36449--- linux-2.6.39.1/drivers/net/xen-netback/interface.c 2011-05-19 00:06:34.000000000 -0400
36450+++ linux-2.6.39.1/drivers/net/xen-netback/interface.c 2011-05-22 19:36:32.000000000 -0400
36451@@ -273,7 +273,7 @@ static void xenvif_get_strings(struct ne
36452 }
36453 }
36454
36455-static struct ethtool_ops xenvif_ethtool_ops = {
36456+static const struct ethtool_ops xenvif_ethtool_ops = {
36457 .get_tx_csum = ethtool_op_get_tx_csum,
36458 .set_tx_csum = xenvif_set_tx_csum,
36459 .get_sg = ethtool_op_get_sg,
36460diff -urNp linux-2.6.39.1/drivers/net/xilinx_emaclite.c linux-2.6.39.1/drivers/net/xilinx_emaclite.c
36461--- linux-2.6.39.1/drivers/net/xilinx_emaclite.c 2011-05-19 00:06:34.000000000 -0400
36462+++ linux-2.6.39.1/drivers/net/xilinx_emaclite.c 2011-05-22 19:36:32.000000000 -0400
36463@@ -1085,7 +1085,7 @@ static bool get_bool(struct platform_dev
36464 }
36465 }
36466
36467-static struct net_device_ops xemaclite_netdev_ops;
36468+static const struct net_device_ops xemaclite_netdev_ops;
36469
36470 /**
36471 * xemaclite_of_probe - Probe method for the Emaclite device.
36472@@ -1264,7 +1264,7 @@ xemaclite_poll_controller(struct net_dev
36473 }
36474 #endif
36475
36476-static struct net_device_ops xemaclite_netdev_ops = {
36477+static const struct net_device_ops xemaclite_netdev_ops = {
36478 .ndo_open = xemaclite_open,
36479 .ndo_stop = xemaclite_close,
36480 .ndo_start_xmit = xemaclite_send,
36481diff -urNp linux-2.6.39.1/drivers/nfc/pn544.c linux-2.6.39.1/drivers/nfc/pn544.c
36482--- linux-2.6.39.1/drivers/nfc/pn544.c 2011-05-19 00:06:34.000000000 -0400
36483+++ linux-2.6.39.1/drivers/nfc/pn544.c 2011-05-22 19:36:32.000000000 -0400
36484@@ -89,7 +89,7 @@ static ssize_t pn544_test(struct device
36485
36486 static int pn544_enable(struct pn544_info *info, int mode)
36487 {
36488- struct pn544_nfc_platform_data *pdata;
36489+ const struct pn544_nfc_platform_data *pdata;
36490 struct i2c_client *client = info->i2c_dev;
36491
36492 int r;
36493@@ -118,7 +118,7 @@ static int pn544_enable(struct pn544_inf
36494
36495 static void pn544_disable(struct pn544_info *info)
36496 {
36497- struct pn544_nfc_platform_data *pdata;
36498+ const struct pn544_nfc_platform_data *pdata;
36499 struct i2c_client *client = info->i2c_dev;
36500
36501 pdata = client->dev.platform_data;
36502@@ -509,7 +509,7 @@ static long pn544_ioctl(struct file *fil
36503 struct pn544_info *info = container_of(file->private_data,
36504 struct pn544_info, miscdev);
36505 struct i2c_client *client = info->i2c_dev;
36506- struct pn544_nfc_platform_data *pdata;
36507+ const struct pn544_nfc_platform_data *pdata;
36508 unsigned int val;
36509 int r = 0;
36510
36511@@ -715,7 +715,7 @@ static int __devinit pn544_probe(struct
36512 const struct i2c_device_id *id)
36513 {
36514 struct pn544_info *info;
36515- struct pn544_nfc_platform_data *pdata;
36516+ const struct pn544_nfc_platform_data *pdata;
36517 int r = 0;
36518
36519 dev_dbg(&client->dev, "%s\n", __func__);
36520diff -urNp linux-2.6.39.1/drivers/of/pdt.c linux-2.6.39.1/drivers/of/pdt.c
36521--- linux-2.6.39.1/drivers/of/pdt.c 2011-05-19 00:06:34.000000000 -0400
36522+++ linux-2.6.39.1/drivers/of/pdt.c 2011-05-22 19:36:32.000000000 -0400
36523@@ -24,7 +24,7 @@
36524 #include <linux/of_pdt.h>
36525 #include <asm/prom.h>
36526
36527-static struct of_pdt_ops *of_pdt_prom_ops __initdata;
36528+static const struct of_pdt_ops *of_pdt_prom_ops;
36529
36530 void __initdata (*of_pdt_build_more)(struct device_node *dp,
36531 struct device_node ***nextp);
36532diff -urNp linux-2.6.39.1/drivers/oprofile/buffer_sync.c linux-2.6.39.1/drivers/oprofile/buffer_sync.c
36533--- linux-2.6.39.1/drivers/oprofile/buffer_sync.c 2011-05-19 00:06:34.000000000 -0400
36534+++ linux-2.6.39.1/drivers/oprofile/buffer_sync.c 2011-05-22 19:36:32.000000000 -0400
36535@@ -342,7 +342,7 @@ static void add_data(struct op_entry *en
36536 if (cookie == NO_COOKIE)
36537 offset = pc;
36538 if (cookie == INVALID_COOKIE) {
36539- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36540+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36541 offset = pc;
36542 }
36543 if (cookie != last_cookie) {
36544@@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct
36545 /* add userspace sample */
36546
36547 if (!mm) {
36548- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36549+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36550 return 0;
36551 }
36552
36553 cookie = lookup_dcookie(mm, s->eip, &offset);
36554
36555 if (cookie == INVALID_COOKIE) {
36556- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36557+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36558 return 0;
36559 }
36560
36561@@ -562,7 +562,7 @@ void sync_buffer(int cpu)
36562 /* ignore backtraces if failed to add a sample */
36563 if (state == sb_bt_start) {
36564 state = sb_bt_ignore;
36565- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36566+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36567 }
36568 }
36569 release_mm(mm);
36570diff -urNp linux-2.6.39.1/drivers/oprofile/event_buffer.c linux-2.6.39.1/drivers/oprofile/event_buffer.c
36571--- linux-2.6.39.1/drivers/oprofile/event_buffer.c 2011-05-19 00:06:34.000000000 -0400
36572+++ linux-2.6.39.1/drivers/oprofile/event_buffer.c 2011-05-22 19:36:32.000000000 -0400
36573@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36574 }
36575
36576 if (buffer_pos == buffer_size) {
36577- atomic_inc(&oprofile_stats.event_lost_overflow);
36578+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36579 return;
36580 }
36581
36582diff -urNp linux-2.6.39.1/drivers/oprofile/oprof.c linux-2.6.39.1/drivers/oprofile/oprof.c
36583--- linux-2.6.39.1/drivers/oprofile/oprof.c 2011-05-19 00:06:34.000000000 -0400
36584+++ linux-2.6.39.1/drivers/oprofile/oprof.c 2011-05-22 19:36:32.000000000 -0400
36585@@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36586 if (oprofile_ops.switch_events())
36587 return;
36588
36589- atomic_inc(&oprofile_stats.multiplex_counter);
36590+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36591 start_switch_worker();
36592 }
36593
36594diff -urNp linux-2.6.39.1/drivers/oprofile/oprofilefs.c linux-2.6.39.1/drivers/oprofile/oprofilefs.c
36595--- linux-2.6.39.1/drivers/oprofile/oprofilefs.c 2011-05-19 00:06:34.000000000 -0400
36596+++ linux-2.6.39.1/drivers/oprofile/oprofilefs.c 2011-05-22 19:36:32.000000000 -0400
36597@@ -186,7 +186,7 @@ static const struct file_operations atom
36598
36599
36600 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36601- char const *name, atomic_t *val)
36602+ char const *name, atomic_unchecked_t *val)
36603 {
36604 return __oprofilefs_create_file(sb, root, name,
36605 &atomic_ro_fops, 0444, val);
36606diff -urNp linux-2.6.39.1/drivers/oprofile/oprofile_stats.c linux-2.6.39.1/drivers/oprofile/oprofile_stats.c
36607--- linux-2.6.39.1/drivers/oprofile/oprofile_stats.c 2011-05-19 00:06:34.000000000 -0400
36608+++ linux-2.6.39.1/drivers/oprofile/oprofile_stats.c 2011-05-22 19:36:32.000000000 -0400
36609@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36610 cpu_buf->sample_invalid_eip = 0;
36611 }
36612
36613- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36614- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36615- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36616- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36617- atomic_set(&oprofile_stats.multiplex_counter, 0);
36618+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36619+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36620+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36621+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36622+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36623 }
36624
36625
36626diff -urNp linux-2.6.39.1/drivers/oprofile/oprofile_stats.h linux-2.6.39.1/drivers/oprofile/oprofile_stats.h
36627--- linux-2.6.39.1/drivers/oprofile/oprofile_stats.h 2011-05-19 00:06:34.000000000 -0400
36628+++ linux-2.6.39.1/drivers/oprofile/oprofile_stats.h 2011-05-22 19:36:32.000000000 -0400
36629@@ -13,11 +13,11 @@
36630 #include <asm/atomic.h>
36631
36632 struct oprofile_stat_struct {
36633- atomic_t sample_lost_no_mm;
36634- atomic_t sample_lost_no_mapping;
36635- atomic_t bt_lost_no_mapping;
36636- atomic_t event_lost_overflow;
36637- atomic_t multiplex_counter;
36638+ atomic_unchecked_t sample_lost_no_mm;
36639+ atomic_unchecked_t sample_lost_no_mapping;
36640+ atomic_unchecked_t bt_lost_no_mapping;
36641+ atomic_unchecked_t event_lost_overflow;
36642+ atomic_unchecked_t multiplex_counter;
36643 };
36644
36645 extern struct oprofile_stat_struct oprofile_stats;
36646diff -urNp linux-2.6.39.1/drivers/parisc/dino.c linux-2.6.39.1/drivers/parisc/dino.c
36647--- linux-2.6.39.1/drivers/parisc/dino.c 2011-05-19 00:06:34.000000000 -0400
36648+++ linux-2.6.39.1/drivers/parisc/dino.c 2011-05-22 19:36:32.000000000 -0400
36649@@ -238,7 +238,7 @@ static int dino_cfg_write(struct pci_bus
36650 return 0;
36651 }
36652
36653-static struct pci_ops dino_cfg_ops = {
36654+static const struct pci_ops dino_cfg_ops = {
36655 .read = dino_cfg_read,
36656 .write = dino_cfg_write,
36657 };
36658diff -urNp linux-2.6.39.1/drivers/parisc/lba_pci.c linux-2.6.39.1/drivers/parisc/lba_pci.c
36659--- linux-2.6.39.1/drivers/parisc/lba_pci.c 2011-05-19 00:06:34.000000000 -0400
36660+++ linux-2.6.39.1/drivers/parisc/lba_pci.c 2011-05-22 19:36:32.000000000 -0400
36661@@ -468,7 +468,7 @@ static int elroy_cfg_write(struct pci_bu
36662 }
36663
36664
36665-static struct pci_ops elroy_cfg_ops = {
36666+static const struct pci_ops elroy_cfg_ops = {
36667 .read = elroy_cfg_read,
36668 .write = elroy_cfg_write,
36669 };
36670@@ -541,7 +541,7 @@ static int mercury_cfg_write(struct pci_
36671 return 0;
36672 }
36673
36674-static struct pci_ops mercury_cfg_ops = {
36675+static const struct pci_ops mercury_cfg_ops = {
36676 .read = mercury_cfg_read,
36677 .write = mercury_cfg_write,
36678 };
36679@@ -1405,7 +1405,7 @@ lba_driver_probe(struct parisc_device *d
36680 {
36681 struct lba_device *lba_dev;
36682 struct pci_bus *lba_bus;
36683- struct pci_ops *cfg_ops;
36684+ const struct pci_ops *cfg_ops;
36685 u32 func_class;
36686 void *tmp_obj;
36687 char *version;
36688diff -urNp linux-2.6.39.1/drivers/parport/procfs.c linux-2.6.39.1/drivers/parport/procfs.c
36689--- linux-2.6.39.1/drivers/parport/procfs.c 2011-05-19 00:06:34.000000000 -0400
36690+++ linux-2.6.39.1/drivers/parport/procfs.c 2011-05-22 19:36:32.000000000 -0400
36691@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36692
36693 *ppos += len;
36694
36695- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36696+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36697 }
36698
36699 #ifdef CONFIG_PARPORT_1284
36700@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36701
36702 *ppos += len;
36703
36704- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36705+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36706 }
36707 #endif /* IEEE1284.3 support. */
36708
36709diff -urNp linux-2.6.39.1/drivers/pci/access.c linux-2.6.39.1/drivers/pci/access.c
36710--- linux-2.6.39.1/drivers/pci/access.c 2011-05-19 00:06:34.000000000 -0400
36711+++ linux-2.6.39.1/drivers/pci/access.c 2011-05-22 19:36:32.000000000 -0400
36712@@ -74,9 +74,9 @@ EXPORT_SYMBOL(pci_bus_write_config_dword
36713 *
36714 * Return previous raw operations
36715 */
36716-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
36717+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops)
36718 {
36719- struct pci_ops *old_ops;
36720+ const struct pci_ops *old_ops;
36721 unsigned long flags;
36722
36723 raw_spin_lock_irqsave(&pci_lock, flags);
36724diff -urNp linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c
36725--- linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c 2011-05-19 00:06:34.000000000 -0400
36726+++ linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c 2011-05-22 19:36:32.000000000 -0400
36727@@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
36728 }
36729
36730
36731-static struct acpi_dock_ops acpiphp_dock_ops = {
36732+static const struct acpi_dock_ops acpiphp_dock_ops = {
36733 .handler = handle_hotplug_event_func,
36734 };
36735
36736diff -urNp linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c
36737--- linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-19 00:06:34.000000000 -0400
36738+++ linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-22 19:36:32.000000000 -0400
36739@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36740
36741 void compaq_nvram_init (void __iomem *rom_start)
36742 {
36743+
36744+#ifndef CONFIG_PAX_KERNEXEC
36745 if (rom_start) {
36746 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36747 }
36748+#endif
36749+
36750 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36751
36752 /* initialize our int15 lock */
36753diff -urNp linux-2.6.39.1/drivers/pci/hotplug/shpchp.h linux-2.6.39.1/drivers/pci/hotplug/shpchp.h
36754--- linux-2.6.39.1/drivers/pci/hotplug/shpchp.h 2011-05-19 00:06:34.000000000 -0400
36755+++ linux-2.6.39.1/drivers/pci/hotplug/shpchp.h 2011-05-22 19:36:32.000000000 -0400
36756@@ -86,7 +86,7 @@ struct slot {
36757 u8 presence_save;
36758 u8 pwr_save;
36759 struct controller *ctrl;
36760- struct hpc_ops *hpc_ops;
36761+ const struct hpc_ops *hpc_ops;
36762 struct hotplug_slot *hotplug_slot;
36763 struct list_head slot_list;
36764 struct delayed_work work; /* work for button event */
36765@@ -107,7 +107,7 @@ struct controller {
36766 int slot_num_inc; /* 1 or -1 */
36767 struct pci_dev *pci_dev;
36768 struct list_head slot_list;
36769- struct hpc_ops *hpc_ops;
36770+ const struct hpc_ops *hpc_ops;
36771 wait_queue_head_t queue; /* sleep & wake process */
36772 u8 slot_device_offset;
36773 u32 pcix_misc2_reg; /* for amd pogo errata */
36774diff -urNp linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c
36775--- linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c 2011-05-19 00:06:34.000000000 -0400
36776+++ linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c 2011-05-22 19:36:32.000000000 -0400
36777@@ -910,7 +910,7 @@ static int shpc_get_max_bus_speed(struct
36778 return retval;
36779 }
36780
36781-static struct hpc_ops shpchp_hpc_ops = {
36782+static const struct hpc_ops shpchp_hpc_ops = {
36783 .power_on_slot = hpc_power_on_slot,
36784 .slot_enable = hpc_slot_enable,
36785 .slot_disable = hpc_slot_disable,
36786diff -urNp linux-2.6.39.1/drivers/pci/intel-iommu.c linux-2.6.39.1/drivers/pci/intel-iommu.c
36787--- linux-2.6.39.1/drivers/pci/intel-iommu.c 2011-05-19 00:06:34.000000000 -0400
36788+++ linux-2.6.39.1/drivers/pci/intel-iommu.c 2011-05-22 19:36:32.000000000 -0400
36789@@ -391,7 +391,7 @@ static int intel_iommu_strict;
36790 static DEFINE_SPINLOCK(device_domain_lock);
36791 static LIST_HEAD(device_domain_list);
36792
36793-static struct iommu_ops intel_iommu_ops;
36794+static const struct iommu_ops intel_iommu_ops;
36795
36796 static int __init intel_iommu_setup(char *str)
36797 {
36798@@ -2945,7 +2945,7 @@ static int intel_mapping_error(struct de
36799 return !dma_addr;
36800 }
36801
36802-struct dma_map_ops intel_dma_ops = {
36803+const struct dma_map_ops intel_dma_ops = {
36804 .alloc_coherent = intel_alloc_coherent,
36805 .free_coherent = intel_free_coherent,
36806 .map_sg = intel_map_sg,
36807@@ -3739,7 +3739,7 @@ static int intel_iommu_domain_has_cap(st
36808 return 0;
36809 }
36810
36811-static struct iommu_ops intel_iommu_ops = {
36812+static const struct iommu_ops intel_iommu_ops = {
36813 .domain_init = intel_iommu_domain_init,
36814 .domain_destroy = intel_iommu_domain_destroy,
36815 .attach_dev = intel_iommu_attach_device,
36816diff -urNp linux-2.6.39.1/drivers/pci/pci-acpi.c linux-2.6.39.1/drivers/pci/pci-acpi.c
36817--- linux-2.6.39.1/drivers/pci/pci-acpi.c 2011-05-19 00:06:34.000000000 -0400
36818+++ linux-2.6.39.1/drivers/pci/pci-acpi.c 2011-05-22 19:36:32.000000000 -0400
36819@@ -332,7 +332,7 @@ static int acpi_pci_run_wake(struct pci_
36820 return 0;
36821 }
36822
36823-static struct pci_platform_pm_ops acpi_pci_platform_pm = {
36824+static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
36825 .is_manageable = acpi_pci_power_manageable,
36826 .set_state = acpi_pci_set_power_state,
36827 .choose_state = acpi_pci_choose_state,
36828diff -urNp linux-2.6.39.1/drivers/pci/pci.c linux-2.6.39.1/drivers/pci/pci.c
36829--- linux-2.6.39.1/drivers/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
36830+++ linux-2.6.39.1/drivers/pci/pci.c 2011-05-22 19:36:32.000000000 -0400
36831@@ -480,9 +480,9 @@ pci_restore_bars(struct pci_dev *dev)
36832 pci_update_resource(dev, i);
36833 }
36834
36835-static struct pci_platform_pm_ops *pci_platform_pm;
36836+static const struct pci_platform_pm_ops *pci_platform_pm;
36837
36838-int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
36839+int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
36840 {
36841 if (!ops->is_manageable || !ops->set_state || !ops->choose_state
36842 || !ops->sleep_wake || !ops->can_wakeup)
36843diff -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
36844--- linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-19 00:06:34.000000000 -0400
36845+++ linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-22 19:36:32.000000000 -0400
36846@@ -239,7 +239,7 @@ static bool find_source_device(struct pc
36847 static int report_error_detected(struct pci_dev *dev, void *data)
36848 {
36849 pci_ers_result_t vote;
36850- struct pci_error_handlers *err_handler;
36851+ const struct pci_error_handlers *err_handler;
36852 struct aer_broadcast_data *result_data;
36853 result_data = (struct aer_broadcast_data *) data;
36854
36855@@ -273,7 +273,7 @@ static int report_error_detected(struct
36856 static int report_mmio_enabled(struct pci_dev *dev, void *data)
36857 {
36858 pci_ers_result_t vote;
36859- struct pci_error_handlers *err_handler;
36860+ const struct pci_error_handlers *err_handler;
36861 struct aer_broadcast_data *result_data;
36862 result_data = (struct aer_broadcast_data *) data;
36863
36864@@ -291,7 +291,7 @@ static int report_mmio_enabled(struct pc
36865 static int report_slot_reset(struct pci_dev *dev, void *data)
36866 {
36867 pci_ers_result_t vote;
36868- struct pci_error_handlers *err_handler;
36869+ const struct pci_error_handlers *err_handler;
36870 struct aer_broadcast_data *result_data;
36871 result_data = (struct aer_broadcast_data *) data;
36872
36873@@ -308,7 +308,7 @@ static int report_slot_reset(struct pci_
36874
36875 static int report_resume(struct pci_dev *dev, void *data)
36876 {
36877- struct pci_error_handlers *err_handler;
36878+ const struct pci_error_handlers *err_handler;
36879
36880 dev->error_state = pci_channel_io_normal;
36881
36882diff -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
36883--- linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c 2011-05-19 00:06:34.000000000 -0400
36884+++ linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c 2011-05-22 19:36:32.000000000 -0400
36885@@ -64,7 +64,7 @@ struct aer_error {
36886 struct pci_bus_ops {
36887 struct list_head list;
36888 struct pci_bus *bus;
36889- struct pci_ops *ops;
36890+ const struct pci_ops *ops;
36891 };
36892
36893 static LIST_HEAD(einjected);
36894@@ -110,7 +110,7 @@ static struct aer_error *__find_aer_erro
36895 }
36896
36897 /* inject_lock must be held before calling */
36898-static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36899+static const struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36900 {
36901 struct pci_bus_ops *bus_ops;
36902
36903@@ -187,7 +187,7 @@ static int pci_read_aer(struct pci_bus *
36904 u32 *sim;
36905 struct aer_error *err;
36906 unsigned long flags;
36907- struct pci_ops *ops;
36908+ const struct pci_ops *ops;
36909 int domain;
36910
36911 spin_lock_irqsave(&inject_lock, flags);
36912@@ -219,7 +219,7 @@ int pci_write_aer(struct pci_bus *bus, u
36913 struct aer_error *err;
36914 unsigned long flags;
36915 int rw1cs;
36916- struct pci_ops *ops;
36917+ const struct pci_ops *ops;
36918 int domain;
36919
36920 spin_lock_irqsave(&inject_lock, flags);
36921@@ -254,7 +254,7 @@ static struct pci_ops pci_ops_aer = {
36922
36923 static void pci_bus_ops_init(struct pci_bus_ops *bus_ops,
36924 struct pci_bus *bus,
36925- struct pci_ops *ops)
36926+ const struct pci_ops *ops)
36927 {
36928 INIT_LIST_HEAD(&bus_ops->list);
36929 bus_ops->bus = bus;
36930@@ -263,7 +263,7 @@ static void pci_bus_ops_init(struct pci_
36931
36932 static int pci_bus_set_aer_ops(struct pci_bus *bus)
36933 {
36934- struct pci_ops *ops;
36935+ const struct pci_ops *ops;
36936 struct pci_bus_ops *bus_ops;
36937 unsigned long flags;
36938
36939diff -urNp linux-2.6.39.1/drivers/pci/pcie/aspm.c linux-2.6.39.1/drivers/pci/pcie/aspm.c
36940--- linux-2.6.39.1/drivers/pci/pcie/aspm.c 2011-05-19 00:06:34.000000000 -0400
36941+++ linux-2.6.39.1/drivers/pci/pcie/aspm.c 2011-05-22 19:36:32.000000000 -0400
36942@@ -27,9 +27,9 @@
36943 #define MODULE_PARAM_PREFIX "pcie_aspm."
36944
36945 /* Note: those are not register definitions */
36946-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36947-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36948-#define ASPM_STATE_L1 (4) /* L1 state */
36949+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36950+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36951+#define ASPM_STATE_L1 (4U) /* L1 state */
36952 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36953 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36954
36955diff -urNp linux-2.6.39.1/drivers/pci/pci.h linux-2.6.39.1/drivers/pci/pci.h
36956--- linux-2.6.39.1/drivers/pci/pci.h 2011-05-19 00:06:34.000000000 -0400
36957+++ linux-2.6.39.1/drivers/pci/pci.h 2011-05-22 19:36:32.000000000 -0400
36958@@ -65,7 +65,7 @@ struct pci_platform_pm_ops {
36959 int (*run_wake)(struct pci_dev *dev, bool enable);
36960 };
36961
36962-extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
36963+extern int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
36964 extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
36965 extern void pci_disable_enabled_device(struct pci_dev *dev);
36966 extern int pci_finish_runtime_suspend(struct pci_dev *dev);
36967diff -urNp linux-2.6.39.1/drivers/pci/probe.c linux-2.6.39.1/drivers/pci/probe.c
36968--- linux-2.6.39.1/drivers/pci/probe.c 2011-05-19 00:06:34.000000000 -0400
36969+++ linux-2.6.39.1/drivers/pci/probe.c 2011-05-22 19:36:32.000000000 -0400
36970@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36971 return ret;
36972 }
36973
36974-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36975+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36976 struct device_attribute *attr,
36977 char *buf)
36978 {
36979 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36980 }
36981
36982-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36983+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36984 struct device_attribute *attr,
36985 char *buf)
36986 {
36987@@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
36988 u32 l, sz, mask;
36989 u16 orig_cmd;
36990
36991- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36992+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36993
36994 if (!dev->mmio_always_on) {
36995 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36996@@ -1407,7 +1407,7 @@ unsigned int __devinit pci_scan_child_bu
36997 }
36998
36999 struct pci_bus * pci_create_bus(struct device *parent,
37000- int bus, struct pci_ops *ops, void *sysdata)
37001+ int bus, const struct pci_ops *ops, void *sysdata)
37002 {
37003 int error;
37004 struct pci_bus *b, *b2;
37005@@ -1483,7 +1483,7 @@ err_out:
37006 }
37007
37008 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
37009- int bus, struct pci_ops *ops, void *sysdata)
37010+ int bus, const struct pci_ops *ops, void *sysdata)
37011 {
37012 struct pci_bus *b;
37013
37014diff -urNp linux-2.6.39.1/drivers/pci/proc.c linux-2.6.39.1/drivers/pci/proc.c
37015--- linux-2.6.39.1/drivers/pci/proc.c 2011-05-19 00:06:34.000000000 -0400
37016+++ linux-2.6.39.1/drivers/pci/proc.c 2011-05-22 19:41:37.000000000 -0400
37017@@ -476,7 +476,16 @@ static const struct file_operations proc
37018 static int __init pci_proc_init(void)
37019 {
37020 struct pci_dev *dev = NULL;
37021+
37022+#ifdef CONFIG_GRKERNSEC_PROC_ADD
37023+#ifdef CONFIG_GRKERNSEC_PROC_USER
37024+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37025+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37026+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37027+#endif
37028+#else
37029 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37030+#endif
37031 proc_create("devices", 0, proc_bus_pci_dir,
37032 &proc_bus_pci_dev_operations);
37033 proc_initialized = 1;
37034diff -urNp linux-2.6.39.1/drivers/pci/xen-pcifront.c linux-2.6.39.1/drivers/pci/xen-pcifront.c
37035--- linux-2.6.39.1/drivers/pci/xen-pcifront.c 2011-05-19 00:06:34.000000000 -0400
37036+++ linux-2.6.39.1/drivers/pci/xen-pcifront.c 2011-05-22 19:36:32.000000000 -0400
37037@@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_
37038 struct pcifront_sd *sd = bus->sysdata;
37039 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37040
37041+ pax_track_stack();
37042+
37043 if (verbose_request)
37044 dev_info(&pdev->xdev->dev,
37045 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
37046@@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci
37047 struct pcifront_sd *sd = bus->sysdata;
37048 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37049
37050+ pax_track_stack();
37051+
37052 if (verbose_request)
37053 dev_info(&pdev->xdev->dev,
37054 "write dev=%04x:%02x:%02x.%01x - "
37055@@ -236,7 +240,7 @@ static int pcifront_bus_write(struct pci
37056 return errno_to_pcibios_err(do_pci_op(pdev, &op));
37057 }
37058
37059-struct pci_ops pcifront_bus_ops = {
37060+const struct pci_ops pcifront_bus_ops = {
37061 .read = pcifront_bus_read,
37062 .write = pcifront_bus_write,
37063 };
37064@@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(stru
37065 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37066 struct msi_desc *entry;
37067
37068+ pax_track_stack();
37069+
37070 if (nvec > SH_INFO_MAX_VEC) {
37071 dev_err(&dev->dev, "too much vector for pci frontend: %x."
37072 " Increase SH_INFO_MAX_VEC.\n", nvec);
37073@@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(st
37074 struct pcifront_sd *sd = dev->bus->sysdata;
37075 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37076
37077+ pax_track_stack();
37078+
37079 err = do_pci_op(pdev, &op);
37080
37081 /* What should do for error ? */
37082@@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struc
37083 struct pcifront_sd *sd = dev->bus->sysdata;
37084 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37085
37086+ pax_track_stack();
37087+
37088 err = do_pci_op(pdev, &op);
37089 if (likely(!err)) {
37090 vector[0] = op.value;
37091@@ -368,7 +378,7 @@ static void pci_frontend_disable_msi(str
37092 printk(KERN_DEBUG "get fake response frombackend\n");
37093 }
37094
37095-static struct xen_pci_frontend_ops pci_frontend_ops = {
37096+static const struct xen_pci_frontend_ops pci_frontend_ops = {
37097 .enable_msi = pci_frontend_enable_msi,
37098 .disable_msi = pci_frontend_disable_msi,
37099 .enable_msix = pci_frontend_enable_msix,
37100diff -urNp linux-2.6.39.1/drivers/pcmcia/at91_cf.c linux-2.6.39.1/drivers/pcmcia/at91_cf.c
37101--- linux-2.6.39.1/drivers/pcmcia/at91_cf.c 2011-05-19 00:06:34.000000000 -0400
37102+++ linux-2.6.39.1/drivers/pcmcia/at91_cf.c 2011-05-22 19:36:32.000000000 -0400
37103@@ -203,7 +203,7 @@ at91_cf_set_mem_map(struct pcmcia_socket
37104 return 0;
37105 }
37106
37107-static struct pccard_operations at91_cf_ops = {
37108+static const struct pccard_operations at91_cf_ops = {
37109 .init = at91_cf_ss_init,
37110 .suspend = at91_cf_ss_suspend,
37111 .get_status = at91_cf_get_status,
37112diff -urNp linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c
37113--- linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37114+++ linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37115@@ -184,7 +184,7 @@ bfin_cf_set_mem_map(struct pcmcia_socket
37116 return 0;
37117 }
37118
37119-static struct pccard_operations bfin_cf_ops = {
37120+static const struct pccard_operations bfin_cf_ops = {
37121 .init = bfin_cf_ss_init,
37122 .suspend = bfin_cf_ss_suspend,
37123 .get_status = bfin_cf_get_status,
37124diff -urNp linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c
37125--- linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c 2011-05-19 00:06:34.000000000 -0400
37126+++ linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c 2011-05-22 19:36:32.000000000 -0400
37127@@ -384,7 +384,7 @@ static int au1x00_pcmcia_set_mem_map(str
37128 return 0;
37129 }
37130
37131-static struct pccard_operations db1x_pcmcia_operations = {
37132+static const struct pccard_operations db1x_pcmcia_operations = {
37133 .init = db1x_pcmcia_sock_init,
37134 .suspend = db1x_pcmcia_sock_suspend,
37135 .get_status = db1x_pcmcia_get_status,
37136diff -urNp linux-2.6.39.1/drivers/pcmcia/electra_cf.c linux-2.6.39.1/drivers/pcmcia/electra_cf.c
37137--- linux-2.6.39.1/drivers/pcmcia/electra_cf.c 2011-05-19 00:06:34.000000000 -0400
37138+++ linux-2.6.39.1/drivers/pcmcia/electra_cf.c 2011-05-22 19:36:32.000000000 -0400
37139@@ -173,7 +173,7 @@ static int electra_cf_set_mem_map(struct
37140 return 0;
37141 }
37142
37143-static struct pccard_operations electra_cf_ops = {
37144+static const struct pccard_operations electra_cf_ops = {
37145 .init = electra_cf_ss_init,
37146 .get_status = electra_cf_get_status,
37147 .set_socket = electra_cf_set_socket,
37148diff -urNp linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c
37149--- linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c 2011-05-19 00:06:34.000000000 -0400
37150+++ linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c 2011-05-22 19:36:32.000000000 -0400
37151@@ -674,7 +674,7 @@ static int pcc_init(struct pcmcia_socket
37152 return 0;
37153 }
37154
37155-static struct pccard_operations pcc_operations = {
37156+static const struct pccard_operations pcc_operations = {
37157 .init = pcc_init,
37158 .get_status = pcc_get_status,
37159 .set_socket = pcc_set_socket,
37160diff -urNp linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c
37161--- linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c 2011-05-19 00:06:34.000000000 -0400
37162+++ linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c 2011-05-22 19:36:32.000000000 -0400
37163@@ -652,7 +652,7 @@ static int pcc_init(struct pcmcia_socket
37164 return 0;
37165 }
37166
37167-static struct pccard_operations pcc_operations = {
37168+static const struct pccard_operations pcc_operations = {
37169 .init = pcc_init,
37170 .get_status = pcc_get_status,
37171 .set_socket = pcc_set_socket,
37172diff -urNp linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c
37173--- linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37174+++ linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37175@@ -1139,7 +1139,7 @@ static int m8xx_sock_suspend(struct pcmc
37176 return m8xx_set_socket(sock, &dead_socket);
37177 }
37178
37179-static struct pccard_operations m8xx_services = {
37180+static const struct pccard_operations m8xx_services = {
37181 .init = m8xx_sock_init,
37182 .suspend = m8xx_sock_suspend,
37183 .get_status = m8xx_get_status,
37184diff -urNp linux-2.6.39.1/drivers/pcmcia/omap_cf.c linux-2.6.39.1/drivers/pcmcia/omap_cf.c
37185--- linux-2.6.39.1/drivers/pcmcia/omap_cf.c 2011-05-19 00:06:34.000000000 -0400
37186+++ linux-2.6.39.1/drivers/pcmcia/omap_cf.c 2011-05-22 19:36:32.000000000 -0400
37187@@ -185,7 +185,7 @@ omap_cf_set_mem_map(struct pcmcia_socket
37188 return 0;
37189 }
37190
37191-static struct pccard_operations omap_cf_ops = {
37192+static const struct pccard_operations omap_cf_ops = {
37193 .init = omap_cf_ss_init,
37194 .suspend = omap_cf_ss_suspend,
37195 .get_status = omap_cf_get_status,
37196diff -urNp linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c
37197--- linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c 2011-05-19 00:06:34.000000000 -0400
37198+++ linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c 2011-05-22 19:36:32.000000000 -0400
37199@@ -161,7 +161,7 @@ static int iodyn_find_io(struct pcmcia_s
37200 }
37201
37202
37203-struct pccard_resource_ops pccard_iodyn_ops = {
37204+const struct pccard_resource_ops pccard_iodyn_ops = {
37205 .validate_mem = NULL,
37206 .find_io = iodyn_find_io,
37207 .find_mem = NULL,
37208diff -urNp linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c
37209--- linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c 2011-05-19 00:06:34.000000000 -0400
37210+++ linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c 2011-05-22 19:36:32.000000000 -0400
37211@@ -57,7 +57,7 @@ static int static_find_io(struct pcmcia_
37212 }
37213
37214
37215-struct pccard_resource_ops pccard_static_ops = {
37216+const struct pccard_resource_ops pccard_static_ops = {
37217 .validate_mem = NULL,
37218 .find_io = static_find_io,
37219 .find_mem = NULL,
37220diff -urNp linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c
37221--- linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c 2011-05-19 00:06:34.000000000 -0400
37222+++ linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c 2011-05-22 19:36:32.000000000 -0400
37223@@ -479,7 +479,7 @@ static int pccard_set_mem_map(struct pcm
37224 return 0;
37225 }
37226
37227-static struct pccard_operations vrc4171_pccard_operations = {
37228+static const struct pccard_operations vrc4171_pccard_operations = {
37229 .init = pccard_init,
37230 .get_status = pccard_get_status,
37231 .set_socket = pccard_set_socket,
37232diff -urNp linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c
37233--- linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c 2011-05-19 00:06:34.000000000 -0400
37234+++ linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c 2011-05-22 19:36:32.000000000 -0400
37235@@ -384,7 +384,7 @@ static void cardu_proc_setup(unsigned in
37236 {
37237 }
37238
37239-static struct pccard_operations cardu_operations = {
37240+static const struct pccard_operations cardu_operations = {
37241 .init = cardu_init,
37242 .register_callback = cardu_register_callback,
37243 .inquire_socket = cardu_inquire_socket,
37244diff -urNp linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c
37245--- linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c 2011-05-19 00:06:34.000000000 -0400
37246+++ linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c 2011-05-22 19:36:32.000000000 -0400
37247@@ -196,7 +196,7 @@ static int au1x00_pcmcia_set_mem_map(str
37248 return 0;
37249 }
37250
37251-static struct pccard_operations xxs1500_pcmcia_operations = {
37252+static const struct pccard_operations xxs1500_pcmcia_operations = {
37253 .init = xxs1500_pcmcia_sock_init,
37254 .suspend = xxs1500_pcmcia_sock_suspend,
37255 .get_status = xxs1500_pcmcia_get_status,
37256diff -urNp linux-2.6.39.1/drivers/platform/x86/acerhdf.c linux-2.6.39.1/drivers/platform/x86/acerhdf.c
37257--- linux-2.6.39.1/drivers/platform/x86/acerhdf.c 2011-05-19 00:06:34.000000000 -0400
37258+++ linux-2.6.39.1/drivers/platform/x86/acerhdf.c 2011-05-22 19:36:32.000000000 -0400
37259@@ -406,7 +406,7 @@ static int acerhdf_get_crit_temp(struct
37260 }
37261
37262 /* bind callback functions to thermalzone */
37263-static struct thermal_zone_device_ops acerhdf_dev_ops = {
37264+static const struct thermal_zone_device_ops acerhdf_dev_ops = {
37265 .bind = acerhdf_bind,
37266 .unbind = acerhdf_unbind,
37267 .get_temp = acerhdf_get_ec_temp,
37268@@ -481,7 +481,7 @@ err_out:
37269 }
37270
37271 /* bind fan callbacks to fan device */
37272-static struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37273+static const struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37274 .get_max_state = acerhdf_get_max_state,
37275 .get_cur_state = acerhdf_get_cur_state,
37276 .set_cur_state = acerhdf_set_cur_state,
37277diff -urNp linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c
37278--- linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c 2011-05-19 00:06:34.000000000 -0400
37279+++ linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c 2011-05-22 19:36:32.000000000 -0400
37280@@ -207,7 +207,7 @@ static int ideapad_rfk_set(void *data, b
37281 return write_ec_cmd(ideapad_handle, opcode, !blocked);
37282 }
37283
37284-static struct rfkill_ops ideapad_rfk_ops = {
37285+static const struct rfkill_ops ideapad_rfk_ops = {
37286 .set_block = ideapad_rfk_set,
37287 };
37288
37289diff -urNp linux-2.6.39.1/drivers/platform/x86/intel_menlow.c linux-2.6.39.1/drivers/platform/x86/intel_menlow.c
37290--- linux-2.6.39.1/drivers/platform/x86/intel_menlow.c 2011-05-19 00:06:34.000000000 -0400
37291+++ linux-2.6.39.1/drivers/platform/x86/intel_menlow.c 2011-05-22 19:36:32.000000000 -0400
37292@@ -143,7 +143,7 @@ static int memory_set_cur_bandwidth(stru
37293 return 0;
37294 }
37295
37296-static struct thermal_cooling_device_ops memory_cooling_ops = {
37297+static const struct thermal_cooling_device_ops memory_cooling_ops = {
37298 .get_max_state = memory_get_max_bandwidth,
37299 .get_cur_state = memory_get_cur_bandwidth,
37300 .set_cur_state = memory_set_cur_bandwidth,
37301diff -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
37302--- linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c 2011-05-19 00:06:34.000000000 -0400
37303+++ linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c 2011-05-22 19:36:32.000000000 -0400
37304@@ -458,7 +458,7 @@ static int read_curr_temp(struct thermal
37305 }
37306
37307 /* Can't be const */
37308-static struct thermal_zone_device_ops tzd_ops = {
37309+static const struct thermal_zone_device_ops tzd_ops = {
37310 .get_temp = read_curr_temp,
37311 };
37312
37313diff -urNp linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c
37314--- linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c 2011-05-19 00:06:34.000000000 -0400
37315+++ linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c 2011-05-22 19:36:32.000000000 -0400
37316@@ -419,7 +419,7 @@ static int rfkill_set(void *data, bool b
37317 return 0;
37318 }
37319
37320-static struct rfkill_ops rfkill_ops = {
37321+static const struct rfkill_ops rfkill_ops = {
37322 .set_block = rfkill_set,
37323 };
37324
37325diff -urNp linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c
37326--- linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c 2011-05-19 00:06:34.000000000 -0400
37327+++ linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c 2011-05-22 19:36:32.000000000 -0400
37328@@ -59,7 +59,7 @@ do { \
37329 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37330 } while(0)
37331
37332-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37333+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37334 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37335
37336 /*
37337@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
37338
37339 cpu = get_cpu();
37340 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37341+
37342+ pax_open_kernel();
37343 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37344+ pax_close_kernel();
37345
37346 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37347 spin_lock_irqsave(&pnp_bios_lock, flags);
37348@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
37349 :"memory");
37350 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37351
37352+ pax_open_kernel();
37353 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37354+ pax_close_kernel();
37355+
37356 put_cpu();
37357
37358 /* If we get here and this is set then the PnP BIOS faulted on us. */
37359@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
37360 return status;
37361 }
37362
37363-void pnpbios_calls_init(union pnp_bios_install_struct *header)
37364+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37365 {
37366 int i;
37367
37368@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
37369 pnp_bios_callpoint.offset = header->fields.pm16offset;
37370 pnp_bios_callpoint.segment = PNP_CS16;
37371
37372+ pax_open_kernel();
37373+
37374 for_each_possible_cpu(i) {
37375 struct desc_struct *gdt = get_cpu_gdt_table(i);
37376 if (!gdt)
37377@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
37378 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37379 (unsigned long)__va(header->fields.pm16dseg));
37380 }
37381+
37382+ pax_close_kernel();
37383 }
37384diff -urNp linux-2.6.39.1/drivers/pnp/resource.c linux-2.6.39.1/drivers/pnp/resource.c
37385--- linux-2.6.39.1/drivers/pnp/resource.c 2011-05-19 00:06:34.000000000 -0400
37386+++ linux-2.6.39.1/drivers/pnp/resource.c 2011-05-22 19:36:32.000000000 -0400
37387@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
37388 return 1;
37389
37390 /* check if the resource is valid */
37391- if (*irq < 0 || *irq > 15)
37392+ if (*irq > 15)
37393 return 0;
37394
37395 /* check if the resource is reserved */
37396@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
37397 return 1;
37398
37399 /* check if the resource is valid */
37400- if (*dma < 0 || *dma == 4 || *dma > 7)
37401+ if (*dma == 4 || *dma > 7)
37402 return 0;
37403
37404 /* check if the resource is reserved */
37405diff -urNp linux-2.6.39.1/drivers/power/max8925_power.c linux-2.6.39.1/drivers/power/max8925_power.c
37406--- linux-2.6.39.1/drivers/power/max8925_power.c 2011-05-19 00:06:34.000000000 -0400
37407+++ linux-2.6.39.1/drivers/power/max8925_power.c 2011-05-22 19:36:32.000000000 -0400
37408@@ -426,7 +426,7 @@ static __devinit int max8925_power_probe
37409 {
37410 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
37411 struct max8925_platform_data *max8925_pdata;
37412- struct max8925_power_pdata *pdata = NULL;
37413+ const struct max8925_power_pdata *pdata = NULL;
37414 struct max8925_power_info *info;
37415 int ret;
37416
37417diff -urNp linux-2.6.39.1/drivers/regulator/core.c linux-2.6.39.1/drivers/regulator/core.c
37418--- linux-2.6.39.1/drivers/regulator/core.c 2011-05-19 00:06:34.000000000 -0400
37419+++ linux-2.6.39.1/drivers/regulator/core.c 2011-05-22 19:36:32.000000000 -0400
37420@@ -2883,7 +2883,7 @@ core_initcall(regulator_init);
37421 static int __init regulator_init_complete(void)
37422 {
37423 struct regulator_dev *rdev;
37424- struct regulator_ops *ops;
37425+ const struct regulator_ops *ops;
37426 struct regulation_constraints *c;
37427 int enabled, ret;
37428
37429diff -urNp linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c
37430--- linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c 2011-05-19 00:06:34.000000000 -0400
37431+++ linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c 2011-05-22 19:36:32.000000000 -0400
37432@@ -187,7 +187,7 @@ static irqreturn_t at32_rtc_interrupt(in
37433 return ret;
37434 }
37435
37436-static struct rtc_class_ops at32_rtc_ops = {
37437+static const struct rtc_class_ops at32_rtc_ops = {
37438 .read_time = at32_rtc_readtime,
37439 .set_time = at32_rtc_settime,
37440 .read_alarm = at32_rtc_readalarm,
37441diff -urNp linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c
37442--- linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c 2011-05-19 00:06:34.000000000 -0400
37443+++ linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c 2011-05-22 19:36:32.000000000 -0400
37444@@ -57,7 +57,7 @@ static int au1xtoy_rtc_set_time(struct d
37445 return 0;
37446 }
37447
37448-static struct rtc_class_ops au1xtoy_rtc_ops = {
37449+static const struct rtc_class_ops au1xtoy_rtc_ops = {
37450 .read_time = au1xtoy_rtc_read_time,
37451 .set_time = au1xtoy_rtc_set_time,
37452 };
37453diff -urNp linux-2.6.39.1/drivers/rtc/rtc-bfin.c linux-2.6.39.1/drivers/rtc/rtc-bfin.c
37454--- linux-2.6.39.1/drivers/rtc/rtc-bfin.c 2011-05-19 00:06:34.000000000 -0400
37455+++ linux-2.6.39.1/drivers/rtc/rtc-bfin.c 2011-05-22 19:36:32.000000000 -0400
37456@@ -333,7 +333,7 @@ static int bfin_rtc_proc(struct device *
37457 #undef yesno
37458 }
37459
37460-static struct rtc_class_ops bfin_rtc_ops = {
37461+static const struct rtc_class_ops bfin_rtc_ops = {
37462 .read_time = bfin_rtc_read_time,
37463 .set_time = bfin_rtc_set_time,
37464 .read_alarm = bfin_rtc_read_alarm,
37465diff -urNp linux-2.6.39.1/drivers/rtc/rtc-coh901331.c linux-2.6.39.1/drivers/rtc/rtc-coh901331.c
37466--- linux-2.6.39.1/drivers/rtc/rtc-coh901331.c 2011-05-19 00:06:34.000000000 -0400
37467+++ linux-2.6.39.1/drivers/rtc/rtc-coh901331.c 2011-05-22 19:36:32.000000000 -0400
37468@@ -142,7 +142,7 @@ static int coh901331_alarm_irq_enable(st
37469 return 0;
37470 }
37471
37472-static struct rtc_class_ops coh901331_ops = {
37473+static const struct rtc_class_ops coh901331_ops = {
37474 .read_time = coh901331_read_time,
37475 .set_mmss = coh901331_set_mmss,
37476 .read_alarm = coh901331_read_alarm,
37477diff -urNp linux-2.6.39.1/drivers/rtc/rtc-davinci.c linux-2.6.39.1/drivers/rtc/rtc-davinci.c
37478--- linux-2.6.39.1/drivers/rtc/rtc-davinci.c 2011-05-19 00:06:34.000000000 -0400
37479+++ linux-2.6.39.1/drivers/rtc/rtc-davinci.c 2011-05-22 19:36:32.000000000 -0400
37480@@ -469,7 +469,7 @@ static int davinci_rtc_set_alarm(struct
37481 return 0;
37482 }
37483
37484-static struct rtc_class_ops davinci_rtc_ops = {
37485+static const struct rtc_class_ops davinci_rtc_ops = {
37486 .ioctl = davinci_rtc_ioctl,
37487 .read_time = davinci_rtc_read_time,
37488 .set_time = davinci_rtc_set_time,
37489diff -urNp linux-2.6.39.1/drivers/rtc/rtc-dev.c linux-2.6.39.1/drivers/rtc/rtc-dev.c
37490--- linux-2.6.39.1/drivers/rtc/rtc-dev.c 2011-05-19 00:06:34.000000000 -0400
37491+++ linux-2.6.39.1/drivers/rtc/rtc-dev.c 2011-05-22 19:41:37.000000000 -0400
37492@@ -14,6 +14,7 @@
37493 #include <linux/module.h>
37494 #include <linux/rtc.h>
37495 #include <linux/sched.h>
37496+#include <linux/grsecurity.h>
37497 #include "rtc-core.h"
37498
37499 static dev_t rtc_devt;
37500@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *f
37501 if (copy_from_user(&tm, uarg, sizeof(tm)))
37502 return -EFAULT;
37503
37504+ gr_log_timechange();
37505+
37506 return rtc_set_time(rtc, &tm);
37507
37508 case RTC_PIE_ON:
37509diff -urNp linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c
37510--- linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c 2011-05-19 00:06:34.000000000 -0400
37511+++ linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c 2011-05-22 19:36:32.000000000 -0400
37512@@ -115,7 +115,7 @@ static int dm355evm_rtc_set_time(struct
37513 return 0;
37514 }
37515
37516-static struct rtc_class_ops dm355evm_rtc_ops = {
37517+static const struct rtc_class_ops dm355evm_rtc_ops = {
37518 .read_time = dm355evm_rtc_read_time,
37519 .set_time = dm355evm_rtc_set_time,
37520 };
37521diff -urNp linux-2.6.39.1/drivers/rtc/rtc-ds1302.c linux-2.6.39.1/drivers/rtc/rtc-ds1302.c
37522--- linux-2.6.39.1/drivers/rtc/rtc-ds1302.c 2011-05-19 00:06:34.000000000 -0400
37523+++ linux-2.6.39.1/drivers/rtc/rtc-ds1302.c 2011-05-22 19:36:32.000000000 -0400
37524@@ -199,7 +199,7 @@ static int ds1302_rtc_ioctl(struct devic
37525 return -ENOIOCTLCMD;
37526 }
37527
37528-static struct rtc_class_ops ds1302_rtc_ops = {
37529+static const struct rtc_class_ops ds1302_rtc_ops = {
37530 .read_time = ds1302_rtc_read_time,
37531 .set_time = ds1302_rtc_set_time,
37532 .ioctl = ds1302_rtc_ioctl,
37533diff -urNp linux-2.6.39.1/drivers/rtc/rtc-imxdi.c linux-2.6.39.1/drivers/rtc/rtc-imxdi.c
37534--- linux-2.6.39.1/drivers/rtc/rtc-imxdi.c 2011-05-19 00:06:34.000000000 -0400
37535+++ linux-2.6.39.1/drivers/rtc/rtc-imxdi.c 2011-05-22 19:36:32.000000000 -0400
37536@@ -290,7 +290,7 @@ static int dryice_rtc_set_alarm(struct d
37537 return 0;
37538 }
37539
37540-static struct rtc_class_ops dryice_rtc_ops = {
37541+static const struct rtc_class_ops dryice_rtc_ops = {
37542 .read_time = dryice_rtc_read_time,
37543 .set_mmss = dryice_rtc_set_mmss,
37544 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
37545diff -urNp linux-2.6.39.1/drivers/rtc/rtc-jz4740.c linux-2.6.39.1/drivers/rtc/rtc-jz4740.c
37546--- linux-2.6.39.1/drivers/rtc/rtc-jz4740.c 2011-05-19 00:06:34.000000000 -0400
37547+++ linux-2.6.39.1/drivers/rtc/rtc-jz4740.c 2011-05-22 19:36:32.000000000 -0400
37548@@ -174,7 +174,7 @@ static int jz4740_rtc_alarm_irq_enable(s
37549 return jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AF_IRQ, enable);
37550 }
37551
37552-static struct rtc_class_ops jz4740_rtc_ops = {
37553+static const struct rtc_class_ops jz4740_rtc_ops = {
37554 .read_time = jz4740_rtc_read_time,
37555 .set_mmss = jz4740_rtc_set_mmss,
37556 .read_alarm = jz4740_rtc_read_alarm,
37557diff -urNp linux-2.6.39.1/drivers/rtc/rtc-m41t80.c linux-2.6.39.1/drivers/rtc/rtc-m41t80.c
37558--- linux-2.6.39.1/drivers/rtc/rtc-m41t80.c 2011-05-19 00:06:34.000000000 -0400
37559+++ linux-2.6.39.1/drivers/rtc/rtc-m41t80.c 2011-05-22 19:36:32.000000000 -0400
37560@@ -354,7 +354,7 @@ static int m41t80_rtc_read_alarm(struct
37561 return 0;
37562 }
37563
37564-static struct rtc_class_ops m41t80_rtc_ops = {
37565+static const struct rtc_class_ops m41t80_rtc_ops = {
37566 .read_time = m41t80_rtc_read_time,
37567 .set_time = m41t80_rtc_set_time,
37568 .read_alarm = m41t80_rtc_read_alarm,
37569diff -urNp linux-2.6.39.1/drivers/rtc/rtc-mxc.c linux-2.6.39.1/drivers/rtc/rtc-mxc.c
37570--- linux-2.6.39.1/drivers/rtc/rtc-mxc.c 2011-05-19 00:06:34.000000000 -0400
37571+++ linux-2.6.39.1/drivers/rtc/rtc-mxc.c 2011-05-22 19:36:32.000000000 -0400
37572@@ -355,7 +355,7 @@ static int mxc_rtc_set_alarm(struct devi
37573 }
37574
37575 /* RTC layer */
37576-static struct rtc_class_ops mxc_rtc_ops = {
37577+static const struct rtc_class_ops mxc_rtc_ops = {
37578 .release = mxc_rtc_release,
37579 .read_time = mxc_rtc_read_time,
37580 .set_mmss = mxc_rtc_set_mmss,
37581diff -urNp linux-2.6.39.1/drivers/rtc/rtc-nuc900.c linux-2.6.39.1/drivers/rtc/rtc-nuc900.c
37582--- linux-2.6.39.1/drivers/rtc/rtc-nuc900.c 2011-05-19 00:06:34.000000000 -0400
37583+++ linux-2.6.39.1/drivers/rtc/rtc-nuc900.c 2011-05-22 19:36:32.000000000 -0400
37584@@ -214,7 +214,7 @@ static int nuc900_rtc_set_alarm(struct d
37585 return 0;
37586 }
37587
37588-static struct rtc_class_ops nuc900_rtc_ops = {
37589+static const struct rtc_class_ops nuc900_rtc_ops = {
37590 .read_time = nuc900_rtc_read_time,
37591 .set_time = nuc900_rtc_set_time,
37592 .read_alarm = nuc900_rtc_read_alarm,
37593diff -urNp linux-2.6.39.1/drivers/rtc/rtc-omap.c linux-2.6.39.1/drivers/rtc/rtc-omap.c
37594--- linux-2.6.39.1/drivers/rtc/rtc-omap.c 2011-05-19 00:06:34.000000000 -0400
37595+++ linux-2.6.39.1/drivers/rtc/rtc-omap.c 2011-05-22 19:36:32.000000000 -0400
37596@@ -274,7 +274,7 @@ static int omap_rtc_set_alarm(struct dev
37597 return 0;
37598 }
37599
37600-static struct rtc_class_ops omap_rtc_ops = {
37601+static const struct rtc_class_ops omap_rtc_ops = {
37602 .read_time = omap_rtc_read_time,
37603 .set_time = omap_rtc_set_time,
37604 .read_alarm = omap_rtc_read_alarm,
37605diff -urNp linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c
37606--- linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c 2011-05-19 00:06:34.000000000 -0400
37607+++ linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c 2011-05-22 19:36:32.000000000 -0400
37608@@ -238,7 +238,7 @@ static int pcf50633_rtc_set_alarm(struct
37609 return ret;
37610 }
37611
37612-static struct rtc_class_ops pcf50633_rtc_ops = {
37613+static const struct rtc_class_ops pcf50633_rtc_ops = {
37614 .read_time = pcf50633_rtc_read_time,
37615 .set_time = pcf50633_rtc_set_time,
37616 .read_alarm = pcf50633_rtc_read_alarm,
37617diff -urNp linux-2.6.39.1/drivers/rtc/rtc-pl031.c linux-2.6.39.1/drivers/rtc/rtc-pl031.c
37618--- linux-2.6.39.1/drivers/rtc/rtc-pl031.c 2011-05-19 00:06:34.000000000 -0400
37619+++ linux-2.6.39.1/drivers/rtc/rtc-pl031.c 2011-05-22 19:36:32.000000000 -0400
37620@@ -374,7 +374,7 @@ err_req:
37621 }
37622
37623 /* Operations for the original ARM version */
37624-static struct rtc_class_ops arm_pl031_ops = {
37625+static const struct rtc_class_ops arm_pl031_ops = {
37626 .read_time = pl031_read_time,
37627 .set_time = pl031_set_time,
37628 .read_alarm = pl031_read_alarm,
37629@@ -383,7 +383,7 @@ static struct rtc_class_ops arm_pl031_op
37630 };
37631
37632 /* The First ST derivative */
37633-static struct rtc_class_ops stv1_pl031_ops = {
37634+static const struct rtc_class_ops stv1_pl031_ops = {
37635 .read_time = pl031_read_time,
37636 .set_time = pl031_set_time,
37637 .read_alarm = pl031_read_alarm,
37638@@ -392,7 +392,7 @@ static struct rtc_class_ops stv1_pl031_o
37639 };
37640
37641 /* And the second ST derivative */
37642-static struct rtc_class_ops stv2_pl031_ops = {
37643+static const struct rtc_class_ops stv2_pl031_ops = {
37644 .read_time = pl031_stv2_read_time,
37645 .set_time = pl031_stv2_set_time,
37646 .read_alarm = pl031_stv2_read_alarm,
37647diff -urNp linux-2.6.39.1/drivers/rtc/rtc-rx8025.c linux-2.6.39.1/drivers/rtc/rtc-rx8025.c
37648--- linux-2.6.39.1/drivers/rtc/rtc-rx8025.c 2011-05-19 00:06:34.000000000 -0400
37649+++ linux-2.6.39.1/drivers/rtc/rtc-rx8025.c 2011-05-22 19:36:32.000000000 -0400
37650@@ -424,7 +424,7 @@ static int rx8025_alarm_irq_enable(struc
37651 return 0;
37652 }
37653
37654-static struct rtc_class_ops rx8025_rtc_ops = {
37655+static const struct rtc_class_ops rx8025_rtc_ops = {
37656 .read_time = rx8025_get_time,
37657 .set_time = rx8025_set_time,
37658 .read_alarm = rx8025_read_alarm,
37659diff -urNp linux-2.6.39.1/drivers/rtc/rtc-sh.c linux-2.6.39.1/drivers/rtc/rtc-sh.c
37660--- linux-2.6.39.1/drivers/rtc/rtc-sh.c 2011-05-19 00:06:34.000000000 -0400
37661+++ linux-2.6.39.1/drivers/rtc/rtc-sh.c 2011-05-22 19:36:32.000000000 -0400
37662@@ -576,7 +576,7 @@ static int sh_rtc_set_alarm(struct devic
37663 return 0;
37664 }
37665
37666-static struct rtc_class_ops sh_rtc_ops = {
37667+static const struct rtc_class_ops sh_rtc_ops = {
37668 .read_time = sh_rtc_read_time,
37669 .set_time = sh_rtc_set_time,
37670 .read_alarm = sh_rtc_read_alarm,
37671diff -urNp linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c
37672--- linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c 2011-05-19 00:06:34.000000000 -0400
37673+++ linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c 2011-05-22 19:36:32.000000000 -0400
37674@@ -133,7 +133,7 @@ static int stmp3xxx_rtc_set_alarm(struct
37675 return 0;
37676 }
37677
37678-static struct rtc_class_ops stmp3xxx_rtc_ops = {
37679+static const struct rtc_class_ops stmp3xxx_rtc_ops = {
37680 .alarm_irq_enable =
37681 stmp3xxx_alarm_irq_enable,
37682 .read_time = stmp3xxx_rtc_gettime,
37683diff -urNp linux-2.6.39.1/drivers/rtc/rtc-tegra.c linux-2.6.39.1/drivers/rtc/rtc-tegra.c
37684--- linux-2.6.39.1/drivers/rtc/rtc-tegra.c 2011-05-19 00:06:34.000000000 -0400
37685+++ linux-2.6.39.1/drivers/rtc/rtc-tegra.c 2011-05-22 19:36:32.000000000 -0400
37686@@ -294,7 +294,7 @@ static irqreturn_t tegra_rtc_irq_handler
37687 return IRQ_HANDLED;
37688 }
37689
37690-static struct rtc_class_ops tegra_rtc_ops = {
37691+static const struct rtc_class_ops tegra_rtc_ops = {
37692 .read_time = tegra_rtc_read_time,
37693 .set_time = tegra_rtc_set_time,
37694 .read_alarm = tegra_rtc_read_alarm,
37695diff -urNp linux-2.6.39.1/drivers/rtc/rtc-twl.c linux-2.6.39.1/drivers/rtc/rtc-twl.c
37696--- linux-2.6.39.1/drivers/rtc/rtc-twl.c 2011-05-19 00:06:34.000000000 -0400
37697+++ linux-2.6.39.1/drivers/rtc/rtc-twl.c 2011-05-22 19:36:32.000000000 -0400
37698@@ -415,7 +415,7 @@ out:
37699 return ret;
37700 }
37701
37702-static struct rtc_class_ops twl_rtc_ops = {
37703+static const struct rtc_class_ops twl_rtc_ops = {
37704 .read_time = twl_rtc_read_time,
37705 .set_time = twl_rtc_set_time,
37706 .read_alarm = twl_rtc_read_alarm,
37707diff -urNp linux-2.6.39.1/drivers/rtc/rtc-v3020.c linux-2.6.39.1/drivers/rtc/rtc-v3020.c
37708--- linux-2.6.39.1/drivers/rtc/rtc-v3020.c 2011-05-19 00:06:34.000000000 -0400
37709+++ linux-2.6.39.1/drivers/rtc/rtc-v3020.c 2011-05-22 19:36:32.000000000 -0400
37710@@ -62,7 +62,7 @@ struct v3020 {
37711 /* GPIO access */
37712 struct v3020_gpio *gpio;
37713
37714- struct v3020_chip_ops *ops;
37715+ const struct v3020_chip_ops *ops;
37716
37717 struct rtc_device *rtc;
37718 };
37719@@ -100,7 +100,7 @@ static unsigned char v3020_mmio_read_bit
37720 return !!(readl(chip->ioaddress) & (1 << chip->leftshift));
37721 }
37722
37723-static struct v3020_chip_ops v3020_mmio_ops = {
37724+static const struct v3020_chip_ops v3020_mmio_ops = {
37725 .map_io = v3020_mmio_map,
37726 .unmap_io = v3020_mmio_unmap,
37727 .read_bit = v3020_mmio_read_bit,
37728@@ -177,7 +177,7 @@ static unsigned char v3020_gpio_read_bit
37729 return bit;
37730 }
37731
37732-static struct v3020_chip_ops v3020_gpio_ops = {
37733+static const struct v3020_chip_ops v3020_gpio_ops = {
37734 .map_io = v3020_gpio_map,
37735 .unmap_io = v3020_gpio_unmap,
37736 .read_bit = v3020_gpio_read_bit,
37737diff -urNp linux-2.6.39.1/drivers/s390/char/con3270.c linux-2.6.39.1/drivers/s390/char/con3270.c
37738--- linux-2.6.39.1/drivers/s390/char/con3270.c 2011-05-19 00:06:34.000000000 -0400
37739+++ linux-2.6.39.1/drivers/s390/char/con3270.c 2011-05-22 19:36:32.000000000 -0400
37740@@ -28,7 +28,7 @@
37741 #define CON3270_OUTPUT_BUFFER_SIZE 1024
37742 #define CON3270_STRING_PAGES 4
37743
37744-static struct raw3270_fn con3270_fn;
37745+static const struct raw3270_fn con3270_fn;
37746
37747 /*
37748 * Main 3270 console view data structure.
37749@@ -413,7 +413,7 @@ con3270_irq(struct con3270 *cp, struct r
37750 }
37751
37752 /* Console view to a 3270 device. */
37753-static struct raw3270_fn con3270_fn = {
37754+static const struct raw3270_fn con3270_fn = {
37755 .activate = con3270_activate,
37756 .deactivate = con3270_deactivate,
37757 .intv = (void *) con3270_irq
37758diff -urNp linux-2.6.39.1/drivers/s390/char/fs3270.c linux-2.6.39.1/drivers/s390/char/fs3270.c
37759--- linux-2.6.39.1/drivers/s390/char/fs3270.c 2011-05-19 00:06:34.000000000 -0400
37760+++ linux-2.6.39.1/drivers/s390/char/fs3270.c 2011-05-22 19:36:32.000000000 -0400
37761@@ -24,7 +24,7 @@
37762 #include "raw3270.h"
37763 #include "ctrlchar.h"
37764
37765-static struct raw3270_fn fs3270_fn;
37766+static const struct raw3270_fn fs3270_fn;
37767
37768 struct fs3270 {
37769 struct raw3270_view view;
37770@@ -413,7 +413,7 @@ fs3270_release(struct raw3270_view *view
37771 }
37772
37773 /* View to a 3270 device. Can be console, tty or fullscreen. */
37774-static struct raw3270_fn fs3270_fn = {
37775+static const struct raw3270_fn fs3270_fn = {
37776 .activate = fs3270_activate,
37777 .deactivate = fs3270_deactivate,
37778 .intv = (void *) fs3270_irq,
37779diff -urNp linux-2.6.39.1/drivers/s390/char/raw3270.c linux-2.6.39.1/drivers/s390/char/raw3270.c
37780--- linux-2.6.39.1/drivers/s390/char/raw3270.c 2011-05-19 00:06:34.000000000 -0400
37781+++ linux-2.6.39.1/drivers/s390/char/raw3270.c 2011-05-22 19:36:32.000000000 -0400
37782@@ -488,7 +488,7 @@ raw3270_init_irq(struct raw3270_view *vi
37783 return RAW3270_IO_DONE;
37784 }
37785
37786-static struct raw3270_fn raw3270_init_fn = {
37787+static const struct raw3270_fn raw3270_init_fn = {
37788 .intv = raw3270_init_irq
37789 };
37790
37791diff -urNp linux-2.6.39.1/drivers/s390/char/tty3270.c linux-2.6.39.1/drivers/s390/char/tty3270.c
37792--- linux-2.6.39.1/drivers/s390/char/tty3270.c 2011-05-19 00:06:34.000000000 -0400
37793+++ linux-2.6.39.1/drivers/s390/char/tty3270.c 2011-05-22 19:36:32.000000000 -0400
37794@@ -37,7 +37,7 @@
37795 struct tty_driver *tty3270_driver;
37796 static int tty3270_max_index;
37797
37798-static struct raw3270_fn tty3270_fn;
37799+static const struct raw3270_fn tty3270_fn;
37800
37801 struct tty3270_cell {
37802 unsigned char character;
37803@@ -834,7 +834,7 @@ tty3270_del_views(void)
37804 }
37805 }
37806
37807-static struct raw3270_fn tty3270_fn = {
37808+static const struct raw3270_fn tty3270_fn = {
37809 .activate = tty3270_activate,
37810 .deactivate = tty3270_deactivate,
37811 .intv = (void *) tty3270_irq,
37812diff -urNp linux-2.6.39.1/drivers/s390/cio/qdio_debug.c linux-2.6.39.1/drivers/s390/cio/qdio_debug.c
37813--- linux-2.6.39.1/drivers/s390/cio/qdio_debug.c 2011-05-19 00:06:34.000000000 -0400
37814+++ linux-2.6.39.1/drivers/s390/cio/qdio_debug.c 2011-05-22 19:36:32.000000000 -0400
37815@@ -225,7 +225,7 @@ static int qperf_seq_open(struct inode *
37816 filp->f_path.dentry->d_inode->i_private);
37817 }
37818
37819-static struct file_operations debugfs_perf_fops = {
37820+static const struct file_operations debugfs_perf_fops = {
37821 .owner = THIS_MODULE,
37822 .open = qperf_seq_open,
37823 .read = seq_read,
37824diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c
37825--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-19 00:06:34.000000000 -0400
37826+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-22 19:36:32.000000000 -0400
37827@@ -415,7 +415,7 @@ out_free:
37828 /**
37829 * The crypto operations for a CEX2A card.
37830 */
37831-static struct zcrypt_ops zcrypt_cex2a_ops = {
37832+static const struct zcrypt_ops zcrypt_cex2a_ops = {
37833 .rsa_modexpo = zcrypt_cex2a_modexpo,
37834 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
37835 };
37836diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c
37837--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c 2011-05-19 00:06:34.000000000 -0400
37838+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c 2011-05-22 19:36:32.000000000 -0400
37839@@ -347,7 +347,7 @@ out_free:
37840 /**
37841 * The crypto operations for a PCICA card.
37842 */
37843-static struct zcrypt_ops zcrypt_pcica_ops = {
37844+static const struct zcrypt_ops zcrypt_pcica_ops = {
37845 .rsa_modexpo = zcrypt_pcica_modexpo,
37846 .rsa_modexpo_crt = zcrypt_pcica_modexpo_crt,
37847 };
37848diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c
37849--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-19 00:06:34.000000000 -0400
37850+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-22 19:36:32.000000000 -0400
37851@@ -553,7 +553,7 @@ out_free:
37852 /**
37853 * The crypto operations for a PCICC card.
37854 */
37855-static struct zcrypt_ops zcrypt_pcicc_ops = {
37856+static const struct zcrypt_ops zcrypt_pcicc_ops = {
37857 .rsa_modexpo = zcrypt_pcicc_modexpo,
37858 .rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt,
37859 };
37860diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c
37861--- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-19 00:06:34.000000000 -0400
37862+++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-22 19:36:32.000000000 -0400
37863@@ -851,13 +851,13 @@ static long zcrypt_pcixcc_rng(struct zcr
37864 /**
37865 * The crypto operations for a PCIXCC/CEX2C card.
37866 */
37867-static struct zcrypt_ops zcrypt_pcixcc_ops = {
37868+static const struct zcrypt_ops zcrypt_pcixcc_ops = {
37869 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37870 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37871 .send_cprb = zcrypt_pcixcc_send_cprb,
37872 };
37873
37874-static struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37875+static const struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37876 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37877 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37878 .send_cprb = zcrypt_pcixcc_send_cprb,
37879diff -urNp linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c
37880--- linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c 2011-05-19 00:06:34.000000000 -0400
37881+++ linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c 2011-05-22 19:36:32.000000000 -0400
37882@@ -266,7 +266,7 @@ error:
37883 /*
37884 * The config ops structure as defined by virtio config
37885 */
37886-static struct virtio_config_ops kvm_vq_configspace_ops = {
37887+static const struct virtio_config_ops kvm_vq_configspace_ops = {
37888 .get_features = kvm_get_features,
37889 .finalize_features = kvm_finalize_features,
37890 .get = kvm_get,
37891diff -urNp linux-2.6.39.1/drivers/s390/net/qeth_core.h linux-2.6.39.1/drivers/s390/net/qeth_core.h
37892--- linux-2.6.39.1/drivers/s390/net/qeth_core.h 2011-05-19 00:06:34.000000000 -0400
37893+++ linux-2.6.39.1/drivers/s390/net/qeth_core.h 2011-05-22 19:36:32.000000000 -0400
37894@@ -743,7 +743,7 @@ struct qeth_card {
37895 struct qeth_qdio_info qdio;
37896 struct qeth_perf_stats perf_stats;
37897 int read_or_write_problem;
37898- struct qeth_osn_info osn_info;
37899+ const struct qeth_osn_info osn_info;
37900 struct qeth_discipline discipline;
37901 atomic_t force_alloc_skb;
37902 struct service_level qeth_service_level;
37903diff -urNp linux-2.6.39.1/drivers/scsi/53c700.c linux-2.6.39.1/drivers/scsi/53c700.c
37904--- linux-2.6.39.1/drivers/scsi/53c700.c 2011-05-19 00:06:34.000000000 -0400
37905+++ linux-2.6.39.1/drivers/scsi/53c700.c 2011-05-22 19:36:32.000000000 -0400
37906@@ -2153,7 +2153,7 @@ EXPORT_SYMBOL(NCR_700_detect);
37907 EXPORT_SYMBOL(NCR_700_release);
37908 EXPORT_SYMBOL(NCR_700_intr);
37909
37910-static struct spi_function_template NCR_700_transport_functions = {
37911+static struct spi_function_template NCR_700_transport_functions = {
37912 .set_period = NCR_700_set_period,
37913 .show_period = 1,
37914 .set_offset = NCR_700_set_offset,
37915diff -urNp linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c
37916--- linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c 2011-05-19 00:06:34.000000000 -0400
37917+++ linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c 2011-05-22 19:36:32.000000000 -0400
37918@@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_d
37919 u32 actual_fibsize64, actual_fibsize = 0;
37920 int i;
37921
37922+ pax_track_stack();
37923
37924 if (dev->in_reset) {
37925 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
37926diff -urNp linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c
37927--- linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-19 00:06:34.000000000 -0400
37928+++ linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-22 19:41:37.000000000 -0400
37929@@ -486,7 +486,7 @@ static ssize_t asd_show_update_bios(stru
37930 flash_error_table[i].reason);
37931 }
37932
37933-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
37934+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
37935 asd_show_update_bios, asd_store_update_bios);
37936
37937 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
37938diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c
37939--- linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c 2011-05-19 00:06:34.000000000 -0400
37940+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c 2011-05-22 19:36:32.000000000 -0400
37941@@ -24,7 +24,7 @@ BFA_TRC_FILE(HAL, CORE);
37942 /*
37943 * BFA module list terminated by NULL
37944 */
37945-static struct bfa_module_s *hal_mods[] = {
37946+static const struct bfa_module_s *hal_mods[] = {
37947 &hal_mod_sgpg,
37948 &hal_mod_fcport,
37949 &hal_mod_fcxp,
37950diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfad.c linux-2.6.39.1/drivers/scsi/bfa/bfad.c
37951--- linux-2.6.39.1/drivers/scsi/bfa/bfad.c 2011-05-19 00:06:34.000000000 -0400
37952+++ linux-2.6.39.1/drivers/scsi/bfa/bfad.c 2011-05-22 19:36:32.000000000 -0400
37953@@ -1027,6 +1027,8 @@ bfad_start_ops(struct bfad_s *bfad) {
37954 struct bfad_vport_s *vport, *vport_new;
37955 struct bfa_fcs_driver_info_s driver_info;
37956
37957+ pax_track_stack();
37958+
37959 /* Fill the driver_info info to fcs*/
37960 memset(&driver_info, 0, sizeof(driver_info));
37961 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
37962diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c
37963--- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c 2011-05-19 00:06:34.000000000 -0400
37964+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c 2011-05-22 19:36:32.000000000 -0400
37965@@ -70,7 +70,7 @@ bfa_fcs_attach(struct bfa_fcs_s *fcs, st
37966 bfa_boolean_t min_cfg)
37967 {
37968 int i;
37969- struct bfa_fcs_mod_s *mod;
37970+ const struct bfa_fcs_mod_s *mod;
37971
37972 fcs->bfa = bfa;
37973 fcs->bfad = bfad;
37974@@ -93,7 +93,7 @@ void
37975 bfa_fcs_init(struct bfa_fcs_s *fcs)
37976 {
37977 int i, npbc_vports;
37978- struct bfa_fcs_mod_s *mod;
37979+ const struct bfa_fcs_mod_s *mod;
37980 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
37981
37982 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
37983@@ -140,7 +140,7 @@ bfa_fcs_driver_info_init(struct bfa_fcs_
37984 void
37985 bfa_fcs_exit(struct bfa_fcs_s *fcs)
37986 {
37987- struct bfa_fcs_mod_s *mod;
37988+ const struct bfa_fcs_mod_s *mod;
37989 int nmods, i;
37990
37991 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
37992diff -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
37993--- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-19 00:06:34.000000000 -0400
37994+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-22 19:36:32.000000000 -0400
37995@@ -1559,6 +1559,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struc
37996 u16 len, count;
37997 u16 templen;
37998
37999+ pax_track_stack();
38000+
38001 /*
38002 * get hba attributes
38003 */
38004@@ -1836,6 +1838,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(
38005 u8 count = 0;
38006 u16 templen;
38007
38008+ pax_track_stack();
38009+
38010 /*
38011 * get port attributes
38012 */
38013diff -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
38014--- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-19 00:06:34.000000000 -0400
38015+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-22 19:36:32.000000000 -0400
38016@@ -1844,6 +1844,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fc
38017 struct fc_rpsc_speed_info_s speeds;
38018 struct bfa_port_attr_s pport_attr;
38019
38020+ pax_track_stack();
38021+
38022 bfa_trc(port->fcs, rx_fchs->s_id);
38023 bfa_trc(port->fcs, rx_fchs->d_id);
38024
38025diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h
38026--- linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h 2011-05-19 00:06:34.000000000 -0400
38027+++ linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h 2011-05-22 19:36:32.000000000 -0400
38028@@ -68,8 +68,8 @@ enum {
38029 static void bfa_ ## __mod ## _stop(struct bfa_s *bfa); \
38030 static void bfa_ ## __mod ## _iocdisable(struct bfa_s *bfa); \
38031 \
38032- extern struct bfa_module_s hal_mod_ ## __mod; \
38033- struct bfa_module_s hal_mod_ ## __mod = { \
38034+ extern const struct bfa_module_s hal_mod_ ## __mod; \
38035+ const struct bfa_module_s hal_mod_ ## __mod = { \
38036 bfa_ ## __mod ## _meminfo, \
38037 bfa_ ## __mod ## _attach, \
38038 bfa_ ## __mod ## _detach, \
38039@@ -116,12 +116,12 @@ struct bfa_s {
38040 };
38041
38042 extern bfa_boolean_t bfa_auto_recover;
38043-extern struct bfa_module_s hal_mod_sgpg;
38044-extern struct bfa_module_s hal_mod_fcport;
38045-extern struct bfa_module_s hal_mod_fcxp;
38046-extern struct bfa_module_s hal_mod_lps;
38047-extern struct bfa_module_s hal_mod_uf;
38048-extern struct bfa_module_s hal_mod_rport;
38049-extern struct bfa_module_s hal_mod_fcpim;
38050+extern const struct bfa_module_s hal_mod_sgpg;
38051+extern const struct bfa_module_s hal_mod_fcport;
38052+extern const struct bfa_module_s hal_mod_fcxp;
38053+extern const struct bfa_module_s hal_mod_lps;
38054+extern const struct bfa_module_s hal_mod_uf;
38055+extern const struct bfa_module_s hal_mod_rport;
38056+extern const struct bfa_module_s hal_mod_fcpim;
38057
38058 #endif /* __BFA_MODULES_H__ */
38059diff -urNp linux-2.6.39.1/drivers/scsi/BusLogic.c linux-2.6.39.1/drivers/scsi/BusLogic.c
38060--- linux-2.6.39.1/drivers/scsi/BusLogic.c 2011-05-19 00:06:34.000000000 -0400
38061+++ linux-2.6.39.1/drivers/scsi/BusLogic.c 2011-05-22 19:36:32.000000000 -0400
38062@@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFla
38063 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
38064 *PrototypeHostAdapter)
38065 {
38066+ pax_track_stack();
38067+
38068 /*
38069 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
38070 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
38071diff -urNp linux-2.6.39.1/drivers/scsi/dpt_i2o.c linux-2.6.39.1/drivers/scsi/dpt_i2o.c
38072--- linux-2.6.39.1/drivers/scsi/dpt_i2o.c 2011-05-19 00:06:34.000000000 -0400
38073+++ linux-2.6.39.1/drivers/scsi/dpt_i2o.c 2011-05-22 19:36:32.000000000 -0400
38074@@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* p
38075 dma_addr_t addr;
38076 ulong flags = 0;
38077
38078+ pax_track_stack();
38079+
38080 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
38081 // get user msg size in u32s
38082 if(get_user(size, &user_msg[0])){
38083@@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
38084 s32 rcode;
38085 dma_addr_t addr;
38086
38087+ pax_track_stack();
38088+
38089 memset(msg, 0 , sizeof(msg));
38090 len = scsi_bufflen(cmd);
38091 direction = 0x00000000;
38092diff -urNp linux-2.6.39.1/drivers/scsi/eata.c linux-2.6.39.1/drivers/scsi/eata.c
38093--- linux-2.6.39.1/drivers/scsi/eata.c 2011-05-19 00:06:34.000000000 -0400
38094+++ linux-2.6.39.1/drivers/scsi/eata.c 2011-05-22 19:36:32.000000000 -0400
38095@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
38096 struct hostdata *ha;
38097 char name[16];
38098
38099+ pax_track_stack();
38100+
38101 sprintf(name, "%s%d", driver_name, j);
38102
38103 if (!request_region(port_base, REGION_SIZE, driver_name)) {
38104diff -urNp linux-2.6.39.1/drivers/scsi/esp_scsi.c linux-2.6.39.1/drivers/scsi/esp_scsi.c
38105--- linux-2.6.39.1/drivers/scsi/esp_scsi.c 2011-05-19 00:06:34.000000000 -0400
38106+++ linux-2.6.39.1/drivers/scsi/esp_scsi.c 2011-05-22 19:36:32.000000000 -0400
38107@@ -2680,7 +2680,7 @@ static void esp_set_width(struct scsi_ta
38108 tp->flags |= ESP_TGT_CHECK_NEGO;
38109 }
38110
38111-static struct spi_function_template esp_transport_ops = {
38112+static const struct spi_function_template esp_transport_ops = {
38113 .set_offset = esp_set_offset,
38114 .show_offset = 1,
38115 .set_period = esp_set_period,
38116diff -urNp linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c
38117--- linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c 2011-05-19 00:06:34.000000000 -0400
38118+++ linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c 2011-05-22 19:36:32.000000000 -0400
38119@@ -138,7 +138,7 @@ static int fcoe_vport_disable(struct fc_
38120 static void fcoe_set_vport_symbolic_name(struct fc_vport *);
38121 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
38122
38123-static struct libfc_function_template fcoe_libfc_fcn_templ = {
38124+static const struct libfc_function_template fcoe_libfc_fcn_templ = {
38125 .frame_send = fcoe_xmit,
38126 .ddp_setup = fcoe_ddp_setup,
38127 .ddp_done = fcoe_ddp_done,
38128diff -urNp linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c
38129--- linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-19 00:06:34.000000000 -0400
38130+++ linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-22 19:36:32.000000000 -0400
38131@@ -1912,7 +1912,7 @@ static void fcoe_ctlr_vn_rport_callback(
38132 mutex_unlock(&fip->ctlr_mutex);
38133 }
38134
38135-static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38136+static const struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38137 .event_callback = fcoe_ctlr_vn_rport_callback,
38138 };
38139
38140@@ -2458,6 +2458,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe
38141 } buf;
38142 int rc;
38143
38144+ pax_track_stack();
38145+
38146 fiph = (struct fip_header *)skb->data;
38147 sub = fiph->fip_subcode;
38148
38149diff -urNp linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c
38150--- linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c 2011-05-19 00:06:34.000000000 -0400
38151+++ linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c 2011-05-22 19:36:32.000000000 -0400
38152@@ -69,7 +69,7 @@ module_param(fnic_log_level, int, S_IRUG
38153 MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
38154
38155
38156-static struct libfc_function_template fnic_transport_template = {
38157+static const struct libfc_function_template fnic_transport_template = {
38158 .frame_send = fnic_send,
38159 .lport_set_port_id = fnic_set_port_id,
38160 .fcp_abort_io = fnic_empty_scsi_cleanup,
38161diff -urNp linux-2.6.39.1/drivers/scsi/gdth.c linux-2.6.39.1/drivers/scsi/gdth.c
38162--- linux-2.6.39.1/drivers/scsi/gdth.c 2011-05-19 00:06:34.000000000 -0400
38163+++ linux-2.6.39.1/drivers/scsi/gdth.c 2011-05-22 19:36:32.000000000 -0400
38164@@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
38165 unsigned long flags;
38166 gdth_ha_str *ha;
38167
38168+ pax_track_stack();
38169+
38170 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
38171 return -EFAULT;
38172 ha = gdth_find_ha(ldrv.ionode);
38173@@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg
38174 gdth_ha_str *ha;
38175 int rval;
38176
38177+ pax_track_stack();
38178+
38179 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
38180 res.number >= MAX_HDRIVES)
38181 return -EFAULT;
38182@@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg,
38183 gdth_ha_str *ha;
38184 int rval;
38185
38186+ pax_track_stack();
38187+
38188 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
38189 return -EFAULT;
38190 ha = gdth_find_ha(gen.ionode);
38191@@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
38192 int i;
38193 gdth_cmd_str gdtcmd;
38194 char cmnd[MAX_COMMAND_SIZE];
38195+
38196+ pax_track_stack();
38197+
38198 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
38199
38200 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
38201diff -urNp linux-2.6.39.1/drivers/scsi/gdth_proc.c linux-2.6.39.1/drivers/scsi/gdth_proc.c
38202--- linux-2.6.39.1/drivers/scsi/gdth_proc.c 2011-05-19 00:06:34.000000000 -0400
38203+++ linux-2.6.39.1/drivers/scsi/gdth_proc.c 2011-05-22 19:36:32.000000000 -0400
38204@@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi
38205 u64 paddr;
38206
38207 char cmnd[MAX_COMMAND_SIZE];
38208+
38209+ pax_track_stack();
38210+
38211 memset(cmnd, 0xff, 12);
38212 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
38213
38214@@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,ch
38215 gdth_hget_str *phg;
38216 char cmnd[MAX_COMMAND_SIZE];
38217
38218+ pax_track_stack();
38219+
38220 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
38221 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
38222 if (!gdtcmd || !estr)
38223diff -urNp linux-2.6.39.1/drivers/scsi/hosts.c linux-2.6.39.1/drivers/scsi/hosts.c
38224--- linux-2.6.39.1/drivers/scsi/hosts.c 2011-05-19 00:06:34.000000000 -0400
38225+++ linux-2.6.39.1/drivers/scsi/hosts.c 2011-05-22 19:36:32.000000000 -0400
38226@@ -42,7 +42,7 @@
38227 #include "scsi_logging.h"
38228
38229
38230-static atomic_t scsi_host_next_hn; /* host_no for next new host */
38231+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
38232
38233
38234 static void scsi_host_cls_release(struct device *dev)
38235@@ -354,7 +354,7 @@ struct Scsi_Host *scsi_host_alloc(struct
38236 * subtract one because we increment first then return, but we need to
38237 * know what the next host number was before increment
38238 */
38239- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38240+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38241 shost->dma_channel = 0xff;
38242
38243 /* These three are default values which can be overridden */
38244diff -urNp linux-2.6.39.1/drivers/scsi/hpsa.h linux-2.6.39.1/drivers/scsi/hpsa.h
38245--- linux-2.6.39.1/drivers/scsi/hpsa.h 2011-05-19 00:06:34.000000000 -0400
38246+++ linux-2.6.39.1/drivers/scsi/hpsa.h 2011-05-22 19:36:32.000000000 -0400
38247@@ -347,7 +347,7 @@ static struct access_method SA5_access =
38248 SA5_completed,
38249 };
38250
38251-static struct access_method SA5_performant_access = {
38252+static const struct access_method SA5_performant_access = {
38253 SA5_submit_command,
38254 SA5_performant_intr_mask,
38255 SA5_fifo_full,
38256diff -urNp linux-2.6.39.1/drivers/scsi/hptiop.c linux-2.6.39.1/drivers/scsi/hptiop.c
38257--- linux-2.6.39.1/drivers/scsi/hptiop.c 2011-05-19 00:06:34.000000000 -0400
38258+++ linux-2.6.39.1/drivers/scsi/hptiop.c 2011-05-22 19:36:32.000000000 -0400
38259@@ -1226,7 +1226,7 @@ static void hptiop_remove(struct pci_dev
38260 scsi_host_put(host);
38261 }
38262
38263-static struct hptiop_adapter_ops hptiop_itl_ops = {
38264+static const struct hptiop_adapter_ops hptiop_itl_ops = {
38265 .iop_wait_ready = iop_wait_ready_itl,
38266 .internal_memalloc = NULL,
38267 .internal_memfree = NULL,
38268@@ -1241,7 +1241,7 @@ static struct hptiop_adapter_ops hptiop_
38269 .post_req = hptiop_post_req_itl,
38270 };
38271
38272-static struct hptiop_adapter_ops hptiop_mv_ops = {
38273+static const struct hptiop_adapter_ops hptiop_mv_ops = {
38274 .iop_wait_ready = iop_wait_ready_mv,
38275 .internal_memalloc = hptiop_internal_memalloc_mv,
38276 .internal_memfree = hptiop_internal_memfree_mv,
38277diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c
38278--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-19 00:06:34.000000000 -0400
38279+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-22 19:36:32.000000000 -0400
38280@@ -4881,7 +4881,7 @@ static struct vio_device_id ibmvfc_devic
38281 };
38282 MODULE_DEVICE_TABLE(vio, ibmvfc_device_table);
38283
38284-static struct dev_pm_ops ibmvfc_pm_ops = {
38285+static const struct dev_pm_ops ibmvfc_pm_ops = {
38286 .resume = ibmvfc_resume
38287 };
38288
38289diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c
38290--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-19 00:06:34.000000000 -0400
38291+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-22 19:36:32.000000000 -0400
38292@@ -104,7 +104,7 @@ static struct scsi_transport_template *i
38293
38294 #define IBMVSCSI_VERSION "1.5.9"
38295
38296-static struct ibmvscsi_ops *ibmvscsi_ops;
38297+static const struct ibmvscsi_ops *ibmvscsi_ops;
38298
38299 MODULE_DESCRIPTION("IBM Virtual SCSI");
38300 MODULE_AUTHOR("Dave Boutcher");
38301@@ -2059,7 +2059,7 @@ static struct vio_device_id ibmvscsi_dev
38302 };
38303 MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
38304
38305-static struct dev_pm_ops ibmvscsi_pm_ops = {
38306+static const struct dev_pm_ops ibmvscsi_pm_ops = {
38307 .resume = ibmvscsi_resume
38308 };
38309
38310@@ -2075,7 +2075,7 @@ static struct vio_driver ibmvscsi_driver
38311 }
38312 };
38313
38314-static struct srp_function_template ibmvscsi_transport_functions = {
38315+static const struct srp_function_template ibmvscsi_transport_functions = {
38316 };
38317
38318 int __init ibmvscsi_module_init(void)
38319diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h
38320--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-19 00:06:34.000000000 -0400
38321+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-22 19:36:32.000000000 -0400
38322@@ -127,7 +127,7 @@ struct ibmvscsi_ops {
38323 int (*resume) (struct ibmvscsi_host_data *hostdata);
38324 };
38325
38326-extern struct ibmvscsi_ops iseriesvscsi_ops;
38327-extern struct ibmvscsi_ops rpavscsi_ops;
38328+extern const struct ibmvscsi_ops iseriesvscsi_ops;
38329+extern const struct ibmvscsi_ops rpavscsi_ops;
38330
38331 #endif /* IBMVSCSI_H */
38332diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c
38333--- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-19 00:06:34.000000000 -0400
38334+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-22 19:36:32.000000000 -0400
38335@@ -951,7 +951,7 @@ static int get_system_info(void)
38336 return 0;
38337 }
38338
38339-static struct srp_function_template ibmvstgt_transport_functions = {
38340+static const struct srp_function_template ibmvstgt_transport_functions = {
38341 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
38342 .it_nexus_response = ibmvstgt_it_nexus_response,
38343 };
38344diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c
38345--- linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38346+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38347@@ -163,7 +163,7 @@ static int iseriesvscsi_resume(struct ib
38348 return 0;
38349 }
38350
38351-struct ibmvscsi_ops iseriesvscsi_ops = {
38352+const struct ibmvscsi_ops iseriesvscsi_ops = {
38353 .init_crq_queue = iseriesvscsi_init_crq_queue,
38354 .release_crq_queue = iseriesvscsi_release_crq_queue,
38355 .reset_crq_queue = iseriesvscsi_reset_crq_queue,
38356diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c
38357--- linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38358+++ linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38359@@ -358,7 +358,7 @@ static int rpavscsi_resume(struct ibmvsc
38360 return 0;
38361 }
38362
38363-struct ibmvscsi_ops rpavscsi_ops = {
38364+const struct ibmvscsi_ops rpavscsi_ops = {
38365 .init_crq_queue = rpavscsi_init_crq_queue,
38366 .release_crq_queue = rpavscsi_release_crq_queue,
38367 .reset_crq_queue = rpavscsi_reset_crq_queue,
38368diff -urNp linux-2.6.39.1/drivers/scsi/ipr.c linux-2.6.39.1/drivers/scsi/ipr.c
38369--- linux-2.6.39.1/drivers/scsi/ipr.c 2011-05-19 00:06:34.000000000 -0400
38370+++ linux-2.6.39.1/drivers/scsi/ipr.c 2011-05-22 19:36:32.000000000 -0400
38371@@ -6210,7 +6210,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
38372 return true;
38373 }
38374
38375-static struct ata_port_operations ipr_sata_ops = {
38376+static const struct ata_port_operations ipr_sata_ops = {
38377 .phy_reset = ipr_ata_phy_reset,
38378 .hardreset = ipr_sata_reset,
38379 .post_internal_cmd = ipr_ata_post_internal,
38380diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c
38381--- linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c 2011-05-19 00:06:34.000000000 -0400
38382+++ linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c 2011-05-22 19:36:32.000000000 -0400
38383@@ -105,12 +105,12 @@ struct fc_exch_mgr {
38384 * all together if not used XXX
38385 */
38386 struct {
38387- atomic_t no_free_exch;
38388- atomic_t no_free_exch_xid;
38389- atomic_t xid_not_found;
38390- atomic_t xid_busy;
38391- atomic_t seq_not_found;
38392- atomic_t non_bls_resp;
38393+ atomic_unchecked_t no_free_exch;
38394+ atomic_unchecked_t no_free_exch_xid;
38395+ atomic_unchecked_t xid_not_found;
38396+ atomic_unchecked_t xid_busy;
38397+ atomic_unchecked_t seq_not_found;
38398+ atomic_unchecked_t non_bls_resp;
38399 } stats;
38400 };
38401
38402@@ -700,7 +700,7 @@ static struct fc_exch *fc_exch_em_alloc(
38403 /* allocate memory for exchange */
38404 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38405 if (!ep) {
38406- atomic_inc(&mp->stats.no_free_exch);
38407+ atomic_inc_unchecked(&mp->stats.no_free_exch);
38408 goto out;
38409 }
38410 memset(ep, 0, sizeof(*ep));
38411@@ -761,7 +761,7 @@ out:
38412 return ep;
38413 err:
38414 spin_unlock_bh(&pool->lock);
38415- atomic_inc(&mp->stats.no_free_exch_xid);
38416+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38417 mempool_free(ep, mp->ep_pool);
38418 return NULL;
38419 }
38420@@ -906,7 +906,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38421 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38422 ep = fc_exch_find(mp, xid);
38423 if (!ep) {
38424- atomic_inc(&mp->stats.xid_not_found);
38425+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38426 reject = FC_RJT_OX_ID;
38427 goto out;
38428 }
38429@@ -936,7 +936,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38430 ep = fc_exch_find(mp, xid);
38431 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38432 if (ep) {
38433- atomic_inc(&mp->stats.xid_busy);
38434+ atomic_inc_unchecked(&mp->stats.xid_busy);
38435 reject = FC_RJT_RX_ID;
38436 goto rel;
38437 }
38438@@ -947,7 +947,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38439 }
38440 xid = ep->xid; /* get our XID */
38441 } else if (!ep) {
38442- atomic_inc(&mp->stats.xid_not_found);
38443+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38444 reject = FC_RJT_RX_ID; /* XID not found */
38445 goto out;
38446 }
38447@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38448 } else {
38449 sp = &ep->seq;
38450 if (sp->id != fh->fh_seq_id) {
38451- atomic_inc(&mp->stats.seq_not_found);
38452+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38453 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
38454 goto rel;
38455 }
38456@@ -1392,22 +1392,22 @@ static void fc_exch_recv_seq_resp(struct
38457
38458 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38459 if (!ep) {
38460- atomic_inc(&mp->stats.xid_not_found);
38461+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38462 goto out;
38463 }
38464 if (ep->esb_stat & ESB_ST_COMPLETE) {
38465- atomic_inc(&mp->stats.xid_not_found);
38466+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38467 goto rel;
38468 }
38469 if (ep->rxid == FC_XID_UNKNOWN)
38470 ep->rxid = ntohs(fh->fh_rx_id);
38471 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38472- atomic_inc(&mp->stats.xid_not_found);
38473+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38474 goto rel;
38475 }
38476 if (ep->did != ntoh24(fh->fh_s_id) &&
38477 ep->did != FC_FID_FLOGI) {
38478- atomic_inc(&mp->stats.xid_not_found);
38479+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38480 goto rel;
38481 }
38482 sof = fr_sof(fp);
38483@@ -1416,7 +1416,7 @@ static void fc_exch_recv_seq_resp(struct
38484 sp->ssb_stat |= SSB_ST_RESP;
38485 sp->id = fh->fh_seq_id;
38486 } else if (sp->id != fh->fh_seq_id) {
38487- atomic_inc(&mp->stats.seq_not_found);
38488+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38489 goto rel;
38490 }
38491
38492@@ -1479,9 +1479,9 @@ static void fc_exch_recv_resp(struct fc_
38493 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38494
38495 if (!sp)
38496- atomic_inc(&mp->stats.xid_not_found);
38497+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38498 else
38499- atomic_inc(&mp->stats.non_bls_resp);
38500+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
38501
38502 fc_frame_free(fp);
38503 }
38504diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c
38505--- linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c 2011-05-19 00:06:34.000000000 -0400
38506+++ linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c 2011-05-22 19:36:32.000000000 -0400
38507@@ -1299,7 +1299,7 @@ static void fc_lport_enter_ns(struct fc_
38508 fc_lport_error(lport, fp);
38509 }
38510
38511-static struct fc_rport_operations fc_lport_rport_ops = {
38512+static const struct fc_rport_operations fc_lport_rport_ops = {
38513 .event_callback = fc_lport_rport_callback,
38514 };
38515
38516diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c
38517--- linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c 2011-05-19 00:06:34.000000000 -0400
38518+++ linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c 2011-05-22 19:36:32.000000000 -0400
38519@@ -256,7 +256,7 @@ static void fc_rport_work(struct work_st
38520 struct fc_rport_libfc_priv *rpriv;
38521 enum fc_rport_event event;
38522 struct fc_lport *lport = rdata->local_port;
38523- struct fc_rport_operations *rport_ops;
38524+ const struct fc_rport_operations *rport_ops;
38525 struct fc_rport_identifiers ids;
38526 struct fc_rport *rport;
38527 struct fc4_prov *prov;
38528diff -urNp linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c
38529--- linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c 2011-05-19 00:06:34.000000000 -0400
38530+++ linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c 2011-05-22 19:36:32.000000000 -0400
38531@@ -307,14 +307,14 @@ static void sas_ata_post_internal(struct
38532 }
38533 }
38534
38535-static struct ata_port_operations sas_sata_ops = {
38536+static const struct ata_port_operations sas_sata_ops = {
38537 .prereset = ata_std_prereset,
38538 .softreset = NULL,
38539 .hardreset = sas_ata_hard_reset,
38540 .postreset = ata_std_postreset,
38541 .error_handler = ata_std_error_handler,
38542 .post_internal_cmd = sas_ata_post_internal,
38543- .qc_defer = ata_std_qc_defer,
38544+ .qc_defer = ata_std_qc_defer,
38545 .qc_prep = ata_noop_qc_prep,
38546 .qc_issue = sas_ata_qc_issue,
38547 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38548diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c
38549--- linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-19 00:06:34.000000000 -0400
38550+++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-22 19:36:32.000000000 -0400
38551@@ -104,7 +104,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_
38552
38553 #include <linux/debugfs.h>
38554
38555-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38556+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38557 static unsigned long lpfc_debugfs_start_time = 0L;
38558
38559 /* iDiag */
38560@@ -141,7 +141,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
38561 lpfc_debugfs_enable = 0;
38562
38563 len = 0;
38564- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38565+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38566 (lpfc_debugfs_max_disc_trc - 1);
38567 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38568 dtp = vport->disc_trc + i;
38569@@ -202,7 +202,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
38570 lpfc_debugfs_enable = 0;
38571
38572 len = 0;
38573- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38574+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38575 (lpfc_debugfs_max_slow_ring_trc - 1);
38576 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38577 dtp = phba->slow_ring_trc + i;
38578@@ -380,6 +380,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
38579 uint32_t *ptr;
38580 char buffer[1024];
38581
38582+ pax_track_stack();
38583+
38584 off = 0;
38585 spin_lock_irq(&phba->hbalock);
38586
38587@@ -617,14 +619,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
38588 !vport || !vport->disc_trc)
38589 return;
38590
38591- index = atomic_inc_return(&vport->disc_trc_cnt) &
38592+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38593 (lpfc_debugfs_max_disc_trc - 1);
38594 dtp = vport->disc_trc + index;
38595 dtp->fmt = fmt;
38596 dtp->data1 = data1;
38597 dtp->data2 = data2;
38598 dtp->data3 = data3;
38599- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38600+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38601 dtp->jif = jiffies;
38602 #endif
38603 return;
38604@@ -655,14 +657,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
38605 !phba || !phba->slow_ring_trc)
38606 return;
38607
38608- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38609+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38610 (lpfc_debugfs_max_slow_ring_trc - 1);
38611 dtp = phba->slow_ring_trc + index;
38612 dtp->fmt = fmt;
38613 dtp->data1 = data1;
38614 dtp->data2 = data2;
38615 dtp->data3 = data3;
38616- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38617+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38618 dtp->jif = jiffies;
38619 #endif
38620 return;
38621@@ -2145,7 +2147,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38622 "slow_ring buffer\n");
38623 goto debug_failed;
38624 }
38625- atomic_set(&phba->slow_ring_trc_cnt, 0);
38626+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38627 memset(phba->slow_ring_trc, 0,
38628 (sizeof(struct lpfc_debugfs_trc) *
38629 lpfc_debugfs_max_slow_ring_trc));
38630@@ -2191,7 +2193,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38631 "buffer\n");
38632 goto debug_failed;
38633 }
38634- atomic_set(&vport->disc_trc_cnt, 0);
38635+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38636
38637 snprintf(name, sizeof(name), "discovery_trace");
38638 vport->debug_disc_trc =
38639diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h
38640--- linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h 2011-05-19 00:06:34.000000000 -0400
38641+++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h 2011-05-22 19:36:32.000000000 -0400
38642@@ -419,7 +419,7 @@ struct lpfc_vport {
38643 struct dentry *debug_nodelist;
38644 struct dentry *vport_debugfs_root;
38645 struct lpfc_debugfs_trc *disc_trc;
38646- atomic_t disc_trc_cnt;
38647+ atomic_unchecked_t disc_trc_cnt;
38648 #endif
38649 uint8_t stat_data_enabled;
38650 uint8_t stat_data_blocked;
38651@@ -785,8 +785,8 @@ struct lpfc_hba {
38652 struct timer_list fabric_block_timer;
38653 unsigned long bit_flags;
38654 #define FABRIC_COMANDS_BLOCKED 0
38655- atomic_t num_rsrc_err;
38656- atomic_t num_cmd_success;
38657+ atomic_unchecked_t num_rsrc_err;
38658+ atomic_unchecked_t num_cmd_success;
38659 unsigned long last_rsrc_error_time;
38660 unsigned long last_ramp_down_time;
38661 unsigned long last_ramp_up_time;
38662@@ -800,7 +800,7 @@ struct lpfc_hba {
38663 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
38664 struct dentry *debug_slow_ring_trc;
38665 struct lpfc_debugfs_trc *slow_ring_trc;
38666- atomic_t slow_ring_trc_cnt;
38667+ atomic_unchecked_t slow_ring_trc_cnt;
38668 /* iDiag debugfs sub-directory */
38669 struct dentry *idiag_root;
38670 struct dentry *idiag_pci_cfg;
38671diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c
38672--- linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-19 00:06:34.000000000 -0400
38673+++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-22 19:36:32.000000000 -0400
38674@@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
38675 uint32_t evt_posted;
38676
38677 spin_lock_irqsave(&phba->hbalock, flags);
38678- atomic_inc(&phba->num_rsrc_err);
38679+ atomic_inc_unchecked(&phba->num_rsrc_err);
38680 phba->last_rsrc_error_time = jiffies;
38681
38682 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38683@@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
38684 unsigned long flags;
38685 struct lpfc_hba *phba = vport->phba;
38686 uint32_t evt_posted;
38687- atomic_inc(&phba->num_cmd_success);
38688+ atomic_inc_unchecked(&phba->num_cmd_success);
38689
38690 if (vport->cfg_lun_queue_depth <= queue_depth)
38691 return;
38692@@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38693 unsigned long num_rsrc_err, num_cmd_success;
38694 int i;
38695
38696- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38697- num_cmd_success = atomic_read(&phba->num_cmd_success);
38698+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38699+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38700
38701 vports = lpfc_create_vport_work_array(phba);
38702 if (vports != NULL)
38703@@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38704 }
38705 }
38706 lpfc_destroy_vport_work_array(phba, vports);
38707- atomic_set(&phba->num_rsrc_err, 0);
38708- atomic_set(&phba->num_cmd_success, 0);
38709+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38710+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38711 }
38712
38713 /**
38714@@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
38715 }
38716 }
38717 lpfc_destroy_vport_work_array(phba, vports);
38718- atomic_set(&phba->num_rsrc_err, 0);
38719- atomic_set(&phba->num_cmd_success, 0);
38720+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38721+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38722 }
38723
38724 /**
38725diff -urNp linux-2.6.39.1/drivers/scsi/mac_esp.c linux-2.6.39.1/drivers/scsi/mac_esp.c
38726--- linux-2.6.39.1/drivers/scsi/mac_esp.c 2011-05-19 00:06:34.000000000 -0400
38727+++ linux-2.6.39.1/drivers/scsi/mac_esp.c 2011-05-22 19:36:32.000000000 -0400
38728@@ -473,7 +473,7 @@ static irqreturn_t mac_scsi_esp_intr(int
38729 return IRQ_HANDLED;
38730 }
38731
38732-static struct esp_driver_ops mac_esp_ops = {
38733+static const struct esp_driver_ops mac_esp_ops = {
38734 .esp_write8 = mac_esp_write8,
38735 .esp_read8 = mac_esp_read8,
38736 .map_single = mac_esp_map_single,
38737diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c
38738--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-19 00:06:34.000000000 -0400
38739+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-22 19:36:32.000000000 -0400
38740@@ -3510,6 +3510,8 @@ megaraid_cmm_register(adapter_t *adapter
38741 int rval;
38742 int i;
38743
38744+ pax_track_stack();
38745+
38746 // Allocate memory for the base list of scb for management module.
38747 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
38748
38749diff -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
38750--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-19 00:06:34.000000000 -0400
38751+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-22 19:36:32.000000000 -0400
38752@@ -366,7 +366,7 @@ megasas_check_reset_xscale(struct megasa
38753 return 0;
38754 }
38755
38756-static struct megasas_instance_template megasas_instance_template_xscale = {
38757+static const struct megasas_instance_template megasas_instance_template_xscale = {
38758
38759 .fire_cmd = megasas_fire_cmd_xscale,
38760 .enable_intr = megasas_enable_intr_xscale,
38761@@ -497,7 +497,7 @@ megasas_check_reset_ppc(struct megasas_i
38762 {
38763 return 0;
38764 }
38765-static struct megasas_instance_template megasas_instance_template_ppc = {
38766+static const struct megasas_instance_template megasas_instance_template_ppc = {
38767
38768 .fire_cmd = megasas_fire_cmd_ppc,
38769 .enable_intr = megasas_enable_intr_ppc,
38770@@ -623,7 +623,7 @@ megasas_check_reset_skinny(struct megasa
38771 return 0;
38772 }
38773
38774-static struct megasas_instance_template megasas_instance_template_skinny = {
38775+static const struct megasas_instance_template megasas_instance_template_skinny = {
38776
38777 .fire_cmd = megasas_fire_cmd_skinny,
38778 .enable_intr = megasas_enable_intr_skinny,
38779@@ -810,7 +810,7 @@ megasas_check_reset_gen2(struct megasas_
38780 return 0;
38781 }
38782
38783-static struct megasas_instance_template megasas_instance_template_gen2 = {
38784+static const struct megasas_instance_template megasas_instance_template_gen2 = {
38785
38786 .fire_cmd = megasas_fire_cmd_gen2,
38787 .enable_intr = megasas_enable_intr_gen2,
38788@@ -834,7 +834,7 @@ static struct megasas_instance_template
38789 /*
38790 * Template added for TB (Fusion)
38791 */
38792-extern struct megasas_instance_template megasas_instance_template_fusion;
38793+extern const struct megasas_instance_template megasas_instance_template_fusion;
38794
38795 /**
38796 * megasas_issue_polled - Issues a polling command
38797diff -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
38798--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-19 00:06:34.000000000 -0400
38799+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-22 19:36:32.000000000 -0400
38800@@ -2236,7 +2236,7 @@ void megasas_fusion_ocr_wq(struct work_s
38801 megasas_reset_fusion(instance->host);
38802 }
38803
38804-struct megasas_instance_template megasas_instance_template_fusion = {
38805+const struct megasas_instance_template megasas_instance_template_fusion = {
38806 .fire_cmd = megasas_fire_cmd_fusion,
38807 .enable_intr = megasas_enable_intr_fusion,
38808 .disable_intr = megasas_disable_intr_fusion,
38809diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h
38810--- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h 2011-05-19 00:06:34.000000000 -0400
38811+++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h 2011-05-22 19:36:32.000000000 -0400
38812@@ -1330,7 +1330,7 @@ struct megasas_instance {
38813 atomic_t fw_outstanding;
38814 atomic_t fw_reset_no_pci_access;
38815
38816- struct megasas_instance_template *instancet;
38817+ const struct megasas_instance_template *instancet;
38818 struct tasklet_struct isr_tasklet;
38819 struct work_struct work_init;
38820
38821diff -urNp linux-2.6.39.1/drivers/scsi/ncr53c8xx.c linux-2.6.39.1/drivers/scsi/ncr53c8xx.c
38822--- linux-2.6.39.1/drivers/scsi/ncr53c8xx.c 2011-05-19 00:06:34.000000000 -0400
38823+++ linux-2.6.39.1/drivers/scsi/ncr53c8xx.c 2011-05-22 19:36:32.000000000 -0400
38824@@ -8606,7 +8606,7 @@ static void ncr53c8xx_get_signalling(str
38825 spi_signalling(shost) = type;
38826 }
38827
38828-static struct spi_function_template ncr53c8xx_transport_functions = {
38829+static struct spi_function_template ncr53c8xx_transport_functions = {
38830 .set_period = ncr53c8xx_set_period,
38831 .show_period = 1,
38832 .set_offset = ncr53c8xx_set_offset,
38833diff -urNp linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c
38834--- linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c 2011-05-19 00:06:34.000000000 -0400
38835+++ linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c 2011-05-22 19:36:32.000000000 -0400
38836@@ -97,6 +97,8 @@ static int _osd_get_print_system_info(st
38837 int nelem = ARRAY_SIZE(get_attrs), a = 0;
38838 int ret;
38839
38840+ pax_track_stack();
38841+
38842 or = osd_start_request(od, GFP_KERNEL);
38843 if (!or)
38844 return -ENOMEM;
38845diff -urNp linux-2.6.39.1/drivers/scsi/pmcraid.c linux-2.6.39.1/drivers/scsi/pmcraid.c
38846--- linux-2.6.39.1/drivers/scsi/pmcraid.c 2011-05-19 00:06:34.000000000 -0400
38847+++ linux-2.6.39.1/drivers/scsi/pmcraid.c 2011-05-22 19:36:32.000000000 -0400
38848@@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct sc
38849 res->scsi_dev = scsi_dev;
38850 scsi_dev->hostdata = res;
38851 res->change_detected = 0;
38852- atomic_set(&res->read_failures, 0);
38853- atomic_set(&res->write_failures, 0);
38854+ atomic_set_unchecked(&res->read_failures, 0);
38855+ atomic_set_unchecked(&res->write_failures, 0);
38856 rc = 0;
38857 }
38858 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38859@@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct
38860
38861 /* If this was a SCSI read/write command keep count of errors */
38862 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38863- atomic_inc(&res->read_failures);
38864+ atomic_inc_unchecked(&res->read_failures);
38865 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38866- atomic_inc(&res->write_failures);
38867+ atomic_inc_unchecked(&res->write_failures);
38868
38869 if (!RES_IS_GSCSI(res->cfg_entry) &&
38870 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38871@@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
38872 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38873 * hrrq_id assigned here in queuecommand
38874 */
38875- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38876+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38877 pinstance->num_hrrq;
38878 cmd->cmd_done = pmcraid_io_done;
38879
38880@@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
38881 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38882 * hrrq_id assigned here in queuecommand
38883 */
38884- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38885+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38886 pinstance->num_hrrq;
38887
38888 if (request_size) {
38889@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(stru
38890
38891 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38892 /* add resources only after host is added into system */
38893- if (!atomic_read(&pinstance->expose_resources))
38894+ if (!atomic_read_unchecked(&pinstance->expose_resources))
38895 return;
38896
38897 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38898@@ -5329,8 +5329,8 @@ static int __devinit pmcraid_init_instan
38899 init_waitqueue_head(&pinstance->reset_wait_q);
38900
38901 atomic_set(&pinstance->outstanding_cmds, 0);
38902- atomic_set(&pinstance->last_message_id, 0);
38903- atomic_set(&pinstance->expose_resources, 0);
38904+ atomic_set_unchecked(&pinstance->last_message_id, 0);
38905+ atomic_set_unchecked(&pinstance->expose_resources, 0);
38906
38907 INIT_LIST_HEAD(&pinstance->free_res_q);
38908 INIT_LIST_HEAD(&pinstance->used_res_q);
38909@@ -6045,7 +6045,7 @@ static int __devinit pmcraid_probe(
38910 /* Schedule worker thread to handle CCN and take care of adding and
38911 * removing devices to OS
38912 */
38913- atomic_set(&pinstance->expose_resources, 1);
38914+ atomic_set_unchecked(&pinstance->expose_resources, 1);
38915 schedule_work(&pinstance->worker_q);
38916 return rc;
38917
38918diff -urNp linux-2.6.39.1/drivers/scsi/pmcraid.h linux-2.6.39.1/drivers/scsi/pmcraid.h
38919--- linux-2.6.39.1/drivers/scsi/pmcraid.h 2011-05-19 00:06:34.000000000 -0400
38920+++ linux-2.6.39.1/drivers/scsi/pmcraid.h 2011-05-22 19:36:32.000000000 -0400
38921@@ -750,7 +750,7 @@ struct pmcraid_instance {
38922 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38923
38924 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38925- atomic_t last_message_id;
38926+ atomic_unchecked_t last_message_id;
38927
38928 /* configuration table */
38929 struct pmcraid_config_table *cfg_table;
38930@@ -779,7 +779,7 @@ struct pmcraid_instance {
38931 atomic_t outstanding_cmds;
38932
38933 /* should add/delete resources to mid-layer now ?*/
38934- atomic_t expose_resources;
38935+ atomic_unchecked_t expose_resources;
38936
38937
38938
38939@@ -815,8 +815,8 @@ struct pmcraid_resource_entry {
38940 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38941 };
38942 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38943- atomic_t read_failures; /* count of failed READ commands */
38944- atomic_t write_failures; /* count of failed WRITE commands */
38945+ atomic_unchecked_t read_failures; /* count of failed READ commands */
38946+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38947
38948 /* To indicate add/delete/modify during CCN */
38949 u8 change_detected;
38950diff -urNp linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c
38951--- linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:04:14.000000000 -0400
38952+++ linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:32:06.000000000 -0400
38953@@ -4103,7 +4103,7 @@ static struct pci_driver qla2xxx_pci_dri
38954 .err_handler = &qla2xxx_err_handler,
38955 };
38956
38957-static struct file_operations apidev_fops = {
38958+static const struct file_operations apidev_fops = {
38959 .owner = THIS_MODULE,
38960 .llseek = noop_llseek,
38961 };
38962diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h
38963--- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h 2011-05-19 00:06:34.000000000 -0400
38964+++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h 2011-05-22 19:36:32.000000000 -0400
38965@@ -256,7 +256,7 @@ struct ddb_entry {
38966 atomic_t retry_relogin_timer; /* Min Time between relogins
38967 * (4000 only) */
38968 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
38969- atomic_t relogin_retry_count; /* Num of times relogin has been
38970+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38971 * retried */
38972
38973 uint16_t port;
38974diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c
38975--- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c 2011-05-19 00:06:34.000000000 -0400
38976+++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c 2011-05-22 19:36:32.000000000 -0400
38977@@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_
38978 ddb_entry->fw_ddb_index = fw_ddb_index;
38979 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38980 atomic_set(&ddb_entry->relogin_timer, 0);
38981- atomic_set(&ddb_entry->relogin_retry_count, 0);
38982+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38983 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38984 list_add_tail(&ddb_entry->list, &ha->ddb_list);
38985 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
38986@@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct s
38987 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
38988 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
38989 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38990- atomic_set(&ddb_entry->relogin_retry_count, 0);
38991+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38992 atomic_set(&ddb_entry->relogin_timer, 0);
38993 clear_bit(DF_RELOGIN, &ddb_entry->flags);
38994 iscsi_unblock_session(ddb_entry->sess);
38995diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c
38996--- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c 2011-05-19 00:06:34.000000000 -0400
38997+++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c 2011-05-22 19:36:32.000000000 -0400
38998@@ -802,13 +802,13 @@ static void qla4xxx_timer(struct scsi_ql
38999 ddb_entry->fw_ddb_device_state ==
39000 DDB_DS_SESSION_FAILED) {
39001 /* Reset retry relogin timer */
39002- atomic_inc(&ddb_entry->relogin_retry_count);
39003+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39004 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
39005 " timed out-retrying"
39006 " relogin (%d)\n",
39007 ha->host_no,
39008 ddb_entry->fw_ddb_index,
39009- atomic_read(&ddb_entry->
39010+ atomic_read_unchecked(&ddb_entry->
39011 relogin_retry_count))
39012 );
39013 start_dpc++;
39014diff -urNp linux-2.6.39.1/drivers/scsi/scsi.c linux-2.6.39.1/drivers/scsi/scsi.c
39015--- linux-2.6.39.1/drivers/scsi/scsi.c 2011-05-19 00:06:34.000000000 -0400
39016+++ linux-2.6.39.1/drivers/scsi/scsi.c 2011-05-22 19:36:32.000000000 -0400
39017@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
39018 unsigned long timeout;
39019 int rtn = 0;
39020
39021- atomic_inc(&cmd->device->iorequest_cnt);
39022+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39023
39024 /* check if the device is still usable */
39025 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39026diff -urNp linux-2.6.39.1/drivers/scsi/scsi_debug.c linux-2.6.39.1/drivers/scsi/scsi_debug.c
39027--- linux-2.6.39.1/drivers/scsi/scsi_debug.c 2011-05-19 00:06:34.000000000 -0400
39028+++ linux-2.6.39.1/drivers/scsi/scsi_debug.c 2011-05-22 19:36:32.000000000 -0400
39029@@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_
39030 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
39031 unsigned char *cmd = (unsigned char *)scp->cmnd;
39032
39033+ pax_track_stack();
39034+
39035 if ((errsts = check_readiness(scp, 1, devip)))
39036 return errsts;
39037 memset(arr, 0, sizeof(arr));
39038@@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cm
39039 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
39040 unsigned char *cmd = (unsigned char *)scp->cmnd;
39041
39042+ pax_track_stack();
39043+
39044 if ((errsts = check_readiness(scp, 1, devip)))
39045 return errsts;
39046 memset(arr, 0, sizeof(arr));
39047diff -urNp linux-2.6.39.1/drivers/scsi/scsi_lib.c linux-2.6.39.1/drivers/scsi/scsi_lib.c
39048--- linux-2.6.39.1/drivers/scsi/scsi_lib.c 2011-05-19 00:06:34.000000000 -0400
39049+++ linux-2.6.39.1/drivers/scsi/scsi_lib.c 2011-05-22 19:36:32.000000000 -0400
39050@@ -1410,7 +1410,7 @@ static void scsi_kill_request(struct req
39051 shost = sdev->host;
39052 scsi_init_cmd_errh(cmd);
39053 cmd->result = DID_NO_CONNECT << 16;
39054- atomic_inc(&cmd->device->iorequest_cnt);
39055+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39056
39057 /*
39058 * SCSI request completion path will do scsi_device_unbusy(),
39059@@ -1436,9 +1436,9 @@ static void scsi_softirq_done(struct req
39060
39061 INIT_LIST_HEAD(&cmd->eh_entry);
39062
39063- atomic_inc(&cmd->device->iodone_cnt);
39064+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
39065 if (cmd->result)
39066- atomic_inc(&cmd->device->ioerr_cnt);
39067+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39068
39069 disposition = scsi_decide_disposition(cmd);
39070 if (disposition != SUCCESS &&
39071diff -urNp linux-2.6.39.1/drivers/scsi/scsi_sysfs.c linux-2.6.39.1/drivers/scsi/scsi_sysfs.c
39072--- linux-2.6.39.1/drivers/scsi/scsi_sysfs.c 2011-05-19 00:06:34.000000000 -0400
39073+++ linux-2.6.39.1/drivers/scsi/scsi_sysfs.c 2011-05-22 19:36:32.000000000 -0400
39074@@ -621,7 +621,7 @@ show_iostat_##field(struct device *dev,
39075 char *buf) \
39076 { \
39077 struct scsi_device *sdev = to_scsi_device(dev); \
39078- unsigned long long count = atomic_read(&sdev->field); \
39079+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
39080 return snprintf(buf, 20, "0x%llx\n", count); \
39081 } \
39082 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39083diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c
39084--- linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c 2011-05-19 00:06:34.000000000 -0400
39085+++ linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c 2011-05-22 19:36:32.000000000 -0400
39086@@ -485,7 +485,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_
39087 * Netlink Infrastructure
39088 */
39089
39090-static atomic_t fc_event_seq;
39091+static atomic_unchecked_t fc_event_seq;
39092
39093 /**
39094 * fc_get_event_number - Obtain the next sequential FC event number
39095@@ -498,7 +498,7 @@ static atomic_t fc_event_seq;
39096 u32
39097 fc_get_event_number(void)
39098 {
39099- return atomic_add_return(1, &fc_event_seq);
39100+ return atomic_add_return_unchecked(1, &fc_event_seq);
39101 }
39102 EXPORT_SYMBOL(fc_get_event_number);
39103
39104@@ -646,7 +646,7 @@ static __init int fc_transport_init(void
39105 {
39106 int error;
39107
39108- atomic_set(&fc_event_seq, 0);
39109+ atomic_set_unchecked(&fc_event_seq, 0);
39110
39111 error = transport_class_register(&fc_host_class);
39112 if (error)
39113@@ -836,7 +836,7 @@ static int fc_str_to_dev_loss(const char
39114 char *cp;
39115
39116 *val = simple_strtoul(buf, &cp, 0);
39117- if ((*cp && (*cp != '\n')) || (*val < 0))
39118+ if (*cp && (*cp != '\n'))
39119 return -EINVAL;
39120 /*
39121 * Check for overflow; dev_loss_tmo is u32
39122diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c
39123--- linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c 2011-05-19 00:06:34.000000000 -0400
39124+++ linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c 2011-05-22 19:36:32.000000000 -0400
39125@@ -83,7 +83,7 @@ struct iscsi_internal {
39126 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
39127 };
39128
39129-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39130+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39131 static struct workqueue_struct *iscsi_eh_timer_workq;
39132
39133 /*
39134@@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_s
39135 int err;
39136
39137 ihost = shost->shost_data;
39138- session->sid = atomic_add_return(1, &iscsi_session_nr);
39139+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39140
39141 if (id == ISCSI_MAX_TARGET) {
39142 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
39143@@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(v
39144 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39145 ISCSI_TRANSPORT_VERSION);
39146
39147- atomic_set(&iscsi_session_nr, 0);
39148+ atomic_set_unchecked(&iscsi_session_nr, 0);
39149
39150 err = class_register(&iscsi_transport_class);
39151 if (err)
39152diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c
39153--- linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c 2011-05-19 00:06:34.000000000 -0400
39154+++ linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c 2011-05-22 19:36:32.000000000 -0400
39155@@ -33,7 +33,7 @@
39156 #include "scsi_transport_srp_internal.h"
39157
39158 struct srp_host_attrs {
39159- atomic_t next_port_id;
39160+ atomic_unchecked_t next_port_id;
39161 };
39162 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39163
39164@@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
39165 struct Scsi_Host *shost = dev_to_shost(dev);
39166 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39167
39168- atomic_set(&srp_host->next_port_id, 0);
39169+ atomic_set_unchecked(&srp_host->next_port_id, 0);
39170 return 0;
39171 }
39172
39173@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
39174 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39175 rport->roles = ids->roles;
39176
39177- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39178+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39179 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39180
39181 transport_setup_device(&rport->dev);
39182diff -urNp linux-2.6.39.1/drivers/scsi/sg.c linux-2.6.39.1/drivers/scsi/sg.c
39183--- linux-2.6.39.1/drivers/scsi/sg.c 2011-05-19 00:06:34.000000000 -0400
39184+++ linux-2.6.39.1/drivers/scsi/sg.c 2011-05-22 19:36:32.000000000 -0400
39185@@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
39186 const struct file_operations * fops;
39187 };
39188
39189-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
39190+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
39191 {"allow_dio", &adio_fops},
39192 {"debug", &debug_fops},
39193 {"def_reserved_size", &dressz_fops},
39194@@ -2325,7 +2325,7 @@ sg_proc_init(void)
39195 {
39196 int k, mask;
39197 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
39198- struct sg_proc_leaf * leaf;
39199+ const struct sg_proc_leaf * leaf;
39200
39201 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
39202 if (!sg_proc_sgp)
39203diff -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
39204--- linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-19 00:06:34.000000000 -0400
39205+++ linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-22 19:36:32.000000000 -0400
39206@@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct p
39207 int do_iounmap = 0;
39208 int do_disable_device = 1;
39209
39210+ pax_track_stack();
39211+
39212 memset(&sym_dev, 0, sizeof(sym_dev));
39213 memset(&nvram, 0, sizeof(nvram));
39214 sym_dev.pdev = pdev;
39215diff -urNp linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c
39216--- linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c 2011-05-19 00:06:34.000000000 -0400
39217+++ linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c 2011-05-22 19:36:32.000000000 -0400
39218@@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const
39219 dma_addr_t base;
39220 unsigned i;
39221
39222+ pax_track_stack();
39223+
39224 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
39225 cmd.reqRingNumPages = adapter->req_pages;
39226 cmd.cmpRingNumPages = adapter->cmp_pages;
39227diff -urNp linux-2.6.39.1/drivers/sh/clk/cpg.c linux-2.6.39.1/drivers/sh/clk/cpg.c
39228--- linux-2.6.39.1/drivers/sh/clk/cpg.c 2011-06-03 00:04:14.000000000 -0400
39229+++ linux-2.6.39.1/drivers/sh/clk/cpg.c 2011-06-03 00:32:06.000000000 -0400
39230@@ -26,7 +26,7 @@ static void sh_clk_mstp32_disable(struct
39231 clk->enable_reg);
39232 }
39233
39234-static struct clk_ops sh_clk_mstp32_clk_ops = {
39235+static const struct clk_ops sh_clk_mstp32_clk_ops = {
39236 .enable = sh_clk_mstp32_enable,
39237 .disable = sh_clk_mstp32_disable,
39238 .recalc = followparent_recalc,
39239@@ -150,7 +150,7 @@ static void sh_clk_div6_disable(struct c
39240 __raw_writel(value, clk->enable_reg);
39241 }
39242
39243-static struct clk_ops sh_clk_div6_clk_ops = {
39244+static const struct clk_ops sh_clk_div6_clk_ops = {
39245 .recalc = sh_clk_div6_recalc,
39246 .round_rate = sh_clk_div_round_rate,
39247 .set_rate = sh_clk_div6_set_rate,
39248@@ -158,7 +158,7 @@ static struct clk_ops sh_clk_div6_clk_op
39249 .disable = sh_clk_div6_disable,
39250 };
39251
39252-static struct clk_ops sh_clk_div6_reparent_clk_ops = {
39253+static const struct clk_ops sh_clk_div6_reparent_clk_ops = {
39254 .recalc = sh_clk_div6_recalc,
39255 .round_rate = sh_clk_div_round_rate,
39256 .set_rate = sh_clk_div6_set_rate,
39257@@ -282,13 +282,13 @@ static void sh_clk_div4_disable(struct c
39258 __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
39259 }
39260
39261-static struct clk_ops sh_clk_div4_clk_ops = {
39262+static const struct clk_ops sh_clk_div4_clk_ops = {
39263 .recalc = sh_clk_div4_recalc,
39264 .set_rate = sh_clk_div4_set_rate,
39265 .round_rate = sh_clk_div_round_rate,
39266 };
39267
39268-static struct clk_ops sh_clk_div4_enable_clk_ops = {
39269+static const struct clk_ops sh_clk_div4_enable_clk_ops = {
39270 .recalc = sh_clk_div4_recalc,
39271 .set_rate = sh_clk_div4_set_rate,
39272 .round_rate = sh_clk_div_round_rate,
39273@@ -296,7 +296,7 @@ static struct clk_ops sh_clk_div4_enable
39274 .disable = sh_clk_div4_disable,
39275 };
39276
39277-static struct clk_ops sh_clk_div4_reparent_clk_ops = {
39278+static const struct clk_ops sh_clk_div4_reparent_clk_ops = {
39279 .recalc = sh_clk_div4_recalc,
39280 .set_rate = sh_clk_div4_set_rate,
39281 .round_rate = sh_clk_div_round_rate,
39282diff -urNp linux-2.6.39.1/drivers/spi/dw_spi.h linux-2.6.39.1/drivers/spi/dw_spi.h
39283--- linux-2.6.39.1/drivers/spi/dw_spi.h 2011-05-19 00:06:34.000000000 -0400
39284+++ linux-2.6.39.1/drivers/spi/dw_spi.h 2011-05-22 19:36:32.000000000 -0400
39285@@ -151,7 +151,7 @@ struct dw_spi {
39286 int dma_chan_done;
39287 struct device *dma_dev;
39288 dma_addr_t dma_addr; /* phy address of the Data register */
39289- struct dw_spi_dma_ops *dma_ops;
39290+ const struct dw_spi_dma_ops *dma_ops;
39291 void *dma_priv; /* platform relate info */
39292 struct pci_dev *dmac;
39293
39294diff -urNp linux-2.6.39.1/drivers/spi/dw_spi_mid.c linux-2.6.39.1/drivers/spi/dw_spi_mid.c
39295--- linux-2.6.39.1/drivers/spi/dw_spi_mid.c 2011-05-19 00:06:34.000000000 -0400
39296+++ linux-2.6.39.1/drivers/spi/dw_spi_mid.c 2011-05-22 19:36:32.000000000 -0400
39297@@ -180,7 +180,7 @@ static int mid_spi_dma_transfer(struct d
39298 return 0;
39299 }
39300
39301-static struct dw_spi_dma_ops mid_dma_ops = {
39302+static const struct dw_spi_dma_ops mid_dma_ops = {
39303 .dma_init = mid_spi_dma_init,
39304 .dma_exit = mid_spi_dma_exit,
39305 .dma_transfer = mid_spi_dma_transfer,
39306diff -urNp linux-2.6.39.1/drivers/spi/spi.c linux-2.6.39.1/drivers/spi/spi.c
39307--- linux-2.6.39.1/drivers/spi/spi.c 2011-05-19 00:06:34.000000000 -0400
39308+++ linux-2.6.39.1/drivers/spi/spi.c 2011-05-22 19:36:32.000000000 -0400
39309@@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *ma
39310 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39311
39312 /* portable code must never pass more than 32 bytes */
39313-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39314+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
39315
39316 static u8 *buf;
39317
39318diff -urNp linux-2.6.39.1/drivers/ssb/driver_pcicore.c linux-2.6.39.1/drivers/ssb/driver_pcicore.c
39319--- linux-2.6.39.1/drivers/ssb/driver_pcicore.c 2011-05-19 00:06:34.000000000 -0400
39320+++ linux-2.6.39.1/drivers/ssb/driver_pcicore.c 2011-05-22 19:36:32.000000000 -0400
39321@@ -223,7 +223,7 @@ static int ssb_pcicore_write_config(stru
39322 return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
39323 }
39324
39325-static struct pci_ops ssb_pcicore_pciops = {
39326+static const struct pci_ops ssb_pcicore_pciops = {
39327 .read = ssb_pcicore_read_config,
39328 .write = ssb_pcicore_write_config,
39329 };
39330diff -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
39331--- linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39332+++ linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39333@@ -1391,8 +1391,7 @@ u32 cipher_suites[] = {
39334 WLAN_CIPHER_SUITE_CCMP,
39335 };
39336
39337-static struct
39338-cfg80211_ops ar6k_cfg80211_ops = {
39339+static const struct cfg80211_ops ar6k_cfg80211_ops = {
39340 .change_virtual_intf = ar6k_cfg80211_change_iface,
39341 .add_virtual_intf = ar6k_cfg80211_add_virtual_intf,
39342 .del_virtual_intf = ar6k_cfg80211_del_virtual_intf,
39343diff -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
39344--- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-19 00:06:34.000000000 -0400
39345+++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-22 19:36:32.000000000 -0400
39346@@ -857,14 +857,14 @@ static void dhd_op_if(dhd_if_t *ifp)
39347 free_netdev(ifp->net);
39348 }
39349 /* Allocate etherdev, including space for private structure */
39350- ifp->net = alloc_etherdev(sizeof(dhd));
39351+ ifp->net = alloc_etherdev(sizeof(*dhd));
39352 if (!ifp->net) {
39353 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39354 ret = -ENOMEM;
39355 }
39356 if (ret == 0) {
39357 strcpy(ifp->net->name, ifp->name);
39358- memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
39359+ memcpy(netdev_priv(ifp->net), dhd, sizeof(*dhd));
39360 err = dhd_net_attach(&dhd->pub, ifp->idx);
39361 if (err != 0) {
39362 DHD_ERROR(("%s: dhd_net_attach failed, "
39363@@ -1500,7 +1500,7 @@ static void dhd_ethtool_get_drvinfo(stru
39364 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
39365 }
39366
39367-struct ethtool_ops dhd_ethtool_ops = {
39368+const struct ethtool_ops dhd_ethtool_ops = {
39369 .get_drvinfo = dhd_ethtool_get_drvinfo
39370 };
39371
39372@@ -1923,7 +1923,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39373 strcpy(nv_path, nvram_path);
39374
39375 /* Allocate etherdev, including space for private structure */
39376- net = alloc_etherdev(sizeof(dhd));
39377+ net = alloc_etherdev(sizeof(*dhd));
39378 if (!net) {
39379 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39380 goto fail;
39381@@ -1939,7 +1939,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39382 /*
39383 * Save the dhd_info into the priv
39384 */
39385- memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39386+ memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39387
39388 /* Set network interface name if it was provided as module parameter */
39389 if (iface_name[0]) {
39390@@ -2056,7 +2056,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39391 /*
39392 * Save the dhd_info into the priv
39393 */
39394- memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39395+ memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39396
39397 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
39398 g_bus = bus;
39399@@ -2206,7 +2206,7 @@ dhd_iovar(dhd_pub_t *pub, int ifidx, cha
39400 return ret;
39401 }
39402
39403-static struct net_device_ops dhd_ops_pri = {
39404+static const struct net_device_ops dhd_ops_pri = {
39405 .ndo_open = dhd_open,
39406 .ndo_stop = dhd_stop,
39407 .ndo_get_stats = dhd_get_stats,
39408diff -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
39409--- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39410+++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39411@@ -2109,7 +2109,7 @@ wl_cfg80211_flush_pmksa(struct wiphy *wi
39412
39413 }
39414
39415-static struct cfg80211_ops wl_cfg80211_ops = {
39416+static const struct cfg80211_ops wl_cfg80211_ops = {
39417 .change_virtual_intf = wl_cfg80211_change_iface,
39418 .scan = wl_cfg80211_scan,
39419 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
39420diff -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
39421--- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-19 00:06:34.000000000 -0400
39422+++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-22 19:36:32.000000000 -0400
39423@@ -495,7 +495,7 @@ wl_iw_get_range(struct net_device *dev,
39424 list = (wl_u32_list_t *) channels;
39425
39426 dwrq->length = sizeof(struct iw_range);
39427- memset(range, 0, sizeof(range));
39428+ memset(range, 0, sizeof(*range));
39429
39430 range->min_nwid = range->max_nwid = 0;
39431
39432diff -urNp linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c
39433--- linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c 2011-05-19 00:06:34.000000000 -0400
39434+++ linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c 2011-05-22 19:36:32.000000000 -0400
39435@@ -1445,7 +1445,7 @@ static void comedi_unmap(struct vm_area_
39436 mutex_unlock(&dev->mutex);
39437 }
39438
39439-static struct vm_operations_struct comedi_vm_ops = {
39440+static const struct vm_operations_struct comedi_vm_ops = {
39441 .close = comedi_unmap,
39442 };
39443
39444diff -urNp linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c
39445--- linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c 2011-05-19 00:06:34.000000000 -0400
39446+++ linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c 2011-05-22 19:36:32.000000000 -0400
39447@@ -586,7 +586,7 @@ static struct page *snd_cx25821_page(str
39448 /*
39449 * operators
39450 */
39451-static struct snd_pcm_ops snd_cx25821_pcm_ops = {
39452+static const struct snd_pcm_ops snd_cx25821_pcm_ops = {
39453 .open = snd_cx25821_pcm_open,
39454 .close = snd_cx25821_close,
39455 .ioctl = snd_pcm_lib_ioctl,
39456diff -urNp linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c
39457--- linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c 2011-05-19 00:06:34.000000000 -0400
39458+++ linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c 2011-05-22 19:36:32.000000000 -0400
39459@@ -282,7 +282,7 @@ static u32 cx25821_functionality(struct
39460 I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
39461 }
39462
39463-static struct i2c_algorithm cx25821_i2c_algo_template = {
39464+static const struct i2c_algorithm cx25821_i2c_algo_template = {
39465 .master_xfer = i2c_xfer,
39466 .functionality = cx25821_functionality,
39467 #ifdef NEED_ALGO_CONTROL
39468diff -urNp linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c
39469--- linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c 2011-05-19 00:06:34.000000000 -0400
39470+++ linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c 2011-05-22 19:36:32.000000000 -0400
39471@@ -635,11 +635,11 @@ inline void et131x_free_send_packet(stru
39472 struct net_device_stats *stats = &etdev->net_stats;
39473
39474 if (tcb->flags & fMP_DEST_BROAD)
39475- atomic_inc(&etdev->Stats.brdcstxmt);
39476+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
39477 else if (tcb->flags & fMP_DEST_MULTI)
39478- atomic_inc(&etdev->Stats.multixmt);
39479+ atomic_inc_unchecked(&etdev->Stats.multixmt);
39480 else
39481- atomic_inc(&etdev->Stats.unixmt);
39482+ atomic_inc_unchecked(&etdev->Stats.unixmt);
39483
39484 if (tcb->skb) {
39485 stats->tx_bytes += tcb->skb->len;
39486diff -urNp linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h
39487--- linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h 2011-05-19 00:06:34.000000000 -0400
39488+++ linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h 2011-05-22 19:36:32.000000000 -0400
39489@@ -110,11 +110,11 @@ typedef struct _ce_stats_t {
39490 * operations
39491 */
39492 u32 unircv; /* # multicast packets received */
39493- atomic_t unixmt; /* # multicast packets for Tx */
39494+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
39495 u32 multircv; /* # multicast packets received */
39496- atomic_t multixmt; /* # multicast packets for Tx */
39497+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
39498 u32 brdcstrcv; /* # broadcast packets received */
39499- atomic_t brdcstxmt; /* # broadcast packets for Tx */
39500+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
39501 u32 norcvbuf; /* # Rx packets discarded */
39502 u32 noxmtbuf; /* # Tx packets discarded */
39503
39504diff -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
39505--- linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-19 00:06:34.000000000 -0400
39506+++ linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-22 19:36:32.000000000 -0400
39507@@ -55,7 +55,7 @@ int numofmsgbuf = 0;
39508 //
39509 // Table of entry-point routines for char device
39510 //
39511-static struct file_operations ft1000fops =
39512+static const struct file_operations ft1000fops =
39513 {
39514 .unlocked_ioctl = ft1000_ioctl,
39515 .poll = ft1000_poll_dev,
39516diff -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
39517--- linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-19 00:06:34.000000000 -0400
39518+++ linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-22 19:36:32.000000000 -0400
39519@@ -221,7 +221,7 @@ module_param(rio_poll, int, 0);
39520 module_param(rio_debug, int, 0644);
39521 module_param(rio_irqmask, long, 0);
39522
39523-static struct real_driver rio_real_driver = {
39524+static const struct real_driver rio_real_driver = {
39525 rio_disable_tx_interrupts,
39526 rio_enable_tx_interrupts,
39527 rio_disable_rx_interrupts,
39528diff -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
39529--- linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c 2011-05-19 00:06:34.000000000 -0400
39530+++ linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c 2011-05-22 19:36:32.000000000 -0400
39531@@ -144,7 +144,7 @@ static int a2232_open(struct tty_struct
39532 /*---------------------------------------------------------------------------
39533 * Interface from generic_serial.c back here
39534 *--------------------------------------------------------------------------*/
39535-static struct real_driver a2232_real_driver = {
39536+static const struct real_driver a2232_real_driver = {
39537 a2232_disable_tx_interrupts,
39538 a2232_enable_tx_interrupts,
39539 a2232_disable_rx_interrupts,
39540diff -urNp linux-2.6.39.1/drivers/staging/generic_serial/sx.c linux-2.6.39.1/drivers/staging/generic_serial/sx.c
39541--- linux-2.6.39.1/drivers/staging/generic_serial/sx.c 2011-05-19 00:06:34.000000000 -0400
39542+++ linux-2.6.39.1/drivers/staging/generic_serial/sx.c 2011-05-22 19:36:32.000000000 -0400
39543@@ -355,7 +355,7 @@ module_param(sx_irqmask, int, 0);
39544
39545 MODULE_LICENSE("GPL");
39546
39547-static struct real_driver sx_real_driver = {
39548+static const struct real_driver sx_real_driver = {
39549 sx_disable_tx_interrupts,
39550 sx_enable_tx_interrupts,
39551 sx_disable_rx_interrupts,
39552diff -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
39553--- linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c 2011-05-19 00:06:34.000000000 -0400
39554+++ linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c 2011-05-22 19:36:32.000000000 -0400
39555@@ -94,7 +94,7 @@ static struct scc_port scc_ports[2];
39556 * Interface from generic_serial.c back here
39557 *--------------------------------------------------------------------------*/
39558
39559-static struct real_driver scc_real_driver = {
39560+static const struct real_driver scc_real_driver = {
39561 scc_disable_tx_interrupts,
39562 scc_enable_tx_interrupts,
39563 scc_disable_rx_interrupts,
39564diff -urNp linux-2.6.39.1/drivers/staging/gma500/psb_fb.c linux-2.6.39.1/drivers/staging/gma500/psb_fb.c
39565--- linux-2.6.39.1/drivers/staging/gma500/psb_fb.c 2011-05-19 00:06:34.000000000 -0400
39566+++ linux-2.6.39.1/drivers/staging/gma500/psb_fb.c 2011-05-22 19:36:32.000000000 -0400
39567@@ -230,7 +230,7 @@ static void psbfb_vm_close(struct vm_are
39568 DRM_DEBUG("vm_close\n");
39569 }
39570
39571-static struct vm_operations_struct psbfb_vm_ops = {
39572+static const struct vm_operations_struct psbfb_vm_ops = {
39573 .fault = psbfb_vm_fault,
39574 .open = psbfb_vm_open,
39575 .close = psbfb_vm_close
39576diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c
39577--- linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c 2011-05-19 00:06:34.000000000 -0400
39578+++ linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c 2011-05-22 19:36:32.000000000 -0400
39579@@ -198,7 +198,7 @@ static u32 go7007_functionality(struct i
39580 return I2C_FUNC_SMBUS_BYTE_DATA;
39581 }
39582
39583-static struct i2c_algorithm go7007_algo = {
39584+static const struct i2c_algorithm go7007_algo = {
39585 .smbus_xfer = go7007_smbus_xfer,
39586 .master_xfer = go7007_i2c_master_xfer,
39587 .functionality = go7007_functionality,
39588diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c
39589--- linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c 2011-05-19 00:06:34.000000000 -0400
39590+++ linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c 2011-05-22 19:36:32.000000000 -0400
39591@@ -849,7 +849,7 @@ static int go7007_usb_send_firmware(stru
39592 &transferred, timeout);
39593 }
39594
39595-static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39596+static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39597 .interface_reset = go7007_usb_interface_reset,
39598 .write_interrupt = go7007_usb_ezusb_write_interrupt,
39599 .read_interrupt = go7007_usb_read_interrupt,
39600@@ -858,7 +858,7 @@ static struct go7007_hpi_ops go7007_usb_
39601 .send_firmware = go7007_usb_send_firmware,
39602 };
39603
39604-static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39605+static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39606 .interface_reset = go7007_usb_interface_reset,
39607 .write_interrupt = go7007_usb_onboard_write_interrupt,
39608 .read_interrupt = go7007_usb_read_interrupt,
39609@@ -950,7 +950,7 @@ static u32 go7007_usb_functionality(stru
39610 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
39611 }
39612
39613-static struct i2c_algorithm go7007_usb_algo = {
39614+static const struct i2c_algorithm go7007_usb_algo = {
39615 .master_xfer = go7007_usb_i2c_master_xfer,
39616 .functionality = go7007_usb_functionality,
39617 };
39618diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c
39619--- linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c 2011-05-19 00:06:34.000000000 -0400
39620+++ linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c 2011-05-22 19:36:32.000000000 -0400
39621@@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
39622 return 0;
39623 }
39624
39625-static struct vm_operations_struct go7007_vm_ops = {
39626+static const struct vm_operations_struct go7007_vm_ops = {
39627 .open = go7007_vm_open,
39628 .close = go7007_vm_close,
39629 .fault = go7007_vm_fault,
39630diff -urNp linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c
39631--- linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c 2011-05-19 00:06:34.000000000 -0400
39632+++ linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c 2011-05-22 19:36:32.000000000 -0400
39633@@ -421,7 +421,7 @@ static int saa7134_go7007_send_command(s
39634
39635 }
39636
39637-static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39638+static const struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39639 .interface_reset = saa7134_go7007_interface_reset,
39640 .write_interrupt = saa7134_go7007_write_interrupt,
39641 .read_interrupt = saa7134_go7007_read_interrupt,
39642diff -urNp linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c
39643--- linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c 2011-05-19 00:06:34.000000000 -0400
39644+++ linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c 2011-05-22 19:36:32.000000000 -0400
39645@@ -204,7 +204,7 @@ static struct page *go7007_snd_pcm_page(
39646 return vmalloc_to_page(substream->runtime->dma_area + offset);
39647 }
39648
39649-static struct snd_pcm_ops go7007_snd_capture_ops = {
39650+static const struct snd_pcm_ops go7007_snd_capture_ops = {
39651 .open = go7007_snd_capture_open,
39652 .close = go7007_snd_capture_close,
39653 .ioctl = snd_pcm_lib_ioctl,
39654@@ -227,7 +227,7 @@ static int go7007_snd_free(struct snd_de
39655 return 0;
39656 }
39657
39658-static struct snd_device_ops go7007_snd_device_ops = {
39659+static const struct snd_device_ops go7007_snd_device_ops = {
39660 .dev_free = go7007_snd_free,
39661 };
39662
39663diff -urNp linux-2.6.39.1/drivers/staging/hv/channel.c linux-2.6.39.1/drivers/staging/hv/channel.c
39664--- linux-2.6.39.1/drivers/staging/hv/channel.c 2011-05-19 00:06:34.000000000 -0400
39665+++ linux-2.6.39.1/drivers/staging/hv/channel.c 2011-05-22 19:36:32.000000000 -0400
39666@@ -509,8 +509,8 @@ int vmbus_establish_gpadl(struct vmbus_c
39667 unsigned long flags;
39668 int ret = 0;
39669
39670- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39671- atomic_inc(&vmbus_connection.next_gpadl_handle);
39672+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39673+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39674
39675 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39676 if (ret)
39677diff -urNp linux-2.6.39.1/drivers/staging/hv/hv.c linux-2.6.39.1/drivers/staging/hv/hv.c
39678--- linux-2.6.39.1/drivers/staging/hv/hv.c 2011-05-19 00:06:34.000000000 -0400
39679+++ linux-2.6.39.1/drivers/staging/hv/hv.c 2011-05-22 19:36:32.000000000 -0400
39680@@ -163,7 +163,7 @@ static u64 do_hypercall(u64 control, voi
39681 u64 output_address = (output) ? virt_to_phys(output) : 0;
39682 u32 output_address_hi = output_address >> 32;
39683 u32 output_address_lo = output_address & 0xFFFFFFFF;
39684- volatile void *hypercall_page = hv_context.hypercall_page;
39685+ volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39686
39687 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
39688 control, input, output);
39689diff -urNp linux-2.6.39.1/drivers/staging/hv/rndis_filter.c linux-2.6.39.1/drivers/staging/hv/rndis_filter.c
39690--- linux-2.6.39.1/drivers/staging/hv/rndis_filter.c 2011-05-19 00:06:34.000000000 -0400
39691+++ linux-2.6.39.1/drivers/staging/hv/rndis_filter.c 2011-05-22 19:36:32.000000000 -0400
39692@@ -49,7 +49,7 @@ struct rndis_device {
39693
39694 enum rndis_device_state state;
39695 u32 link_stat;
39696- atomic_t new_req_id;
39697+ atomic_unchecked_t new_req_id;
39698
39699 spinlock_t request_lock;
39700 struct list_head req_list;
39701@@ -144,7 +144,7 @@ static struct rndis_request *get_rndis_r
39702 * template
39703 */
39704 set = &rndis_msg->msg.set_req;
39705- set->req_id = atomic_inc_return(&dev->new_req_id);
39706+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39707
39708 /* Add to the request list */
39709 spin_lock_irqsave(&dev->request_lock, flags);
39710@@ -709,7 +709,7 @@ static void rndis_filter_halt_device(str
39711
39712 /* Setup the rndis set */
39713 halt = &request->request_msg.msg.halt_req;
39714- halt->req_id = atomic_inc_return(&dev->new_req_id);
39715+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39716
39717 /* Ignore return since this msg is optional. */
39718 rndis_filter_send_request(dev, request);
39719diff -urNp linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c
39720--- linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c 2011-05-19 00:06:34.000000000 -0400
39721+++ linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c 2011-05-22 19:36:32.000000000 -0400
39722@@ -661,14 +661,14 @@ int vmbus_child_device_register(struct h
39723 {
39724 int ret = 0;
39725
39726- static atomic_t device_num = ATOMIC_INIT(0);
39727+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39728
39729 DPRINT_DBG(VMBUS_DRV, "child device (%p) registering",
39730 child_device_obj);
39731
39732 /* Set the device name. Otherwise, device_register() will fail. */
39733 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39734- atomic_inc_return(&device_num));
39735+ atomic_inc_return_unchecked(&device_num));
39736
39737 /* The new device belongs to this bus */
39738 child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */
39739diff -urNp linux-2.6.39.1/drivers/staging/hv/vmbus_private.h linux-2.6.39.1/drivers/staging/hv/vmbus_private.h
39740--- linux-2.6.39.1/drivers/staging/hv/vmbus_private.h 2011-05-19 00:06:34.000000000 -0400
39741+++ linux-2.6.39.1/drivers/staging/hv/vmbus_private.h 2011-05-22 19:36:32.000000000 -0400
39742@@ -58,7 +58,7 @@ enum vmbus_connect_state {
39743 struct vmbus_connection {
39744 enum vmbus_connect_state conn_state;
39745
39746- atomic_t next_gpadl_handle;
39747+ atomic_unchecked_t next_gpadl_handle;
39748
39749 /*
39750 * Represents channel interrupts. Each bit position represents a
39751diff -urNp linux-2.6.39.1/drivers/staging/iio/ring_generic.h linux-2.6.39.1/drivers/staging/iio/ring_generic.h
39752--- linux-2.6.39.1/drivers/staging/iio/ring_generic.h 2011-05-19 00:06:34.000000000 -0400
39753+++ linux-2.6.39.1/drivers/staging/iio/ring_generic.h 2011-05-25 16:55:27.000000000 -0400
39754@@ -134,7 +134,7 @@ struct iio_ring_buffer {
39755 struct iio_handler access_handler;
39756 struct iio_event_interface ev_int;
39757 struct iio_shared_ev_pointer shared_ev_pointer;
39758- struct iio_ring_access_funcs access;
39759+ struct iio_ring_access_funcs access;
39760 int (*preenable)(struct iio_dev *);
39761 int (*postenable)(struct iio_dev *);
39762 int (*predisable)(struct iio_dev *);
39763diff -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
39764--- linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-19 00:06:34.000000000 -0400
39765+++ linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-22 19:36:32.000000000 -0400
39766@@ -494,7 +494,7 @@ static int snd_intelmad_device_set(struc
39767 struct snd_intelmad *intelmaddata;
39768 struct snd_pmic_ops *scard_ops;
39769 int ret_val = 0, vendor, status;
39770- struct intel_sst_pcm_control *pcm_control;
39771+ const struct intel_sst_pcm_control *pcm_control;
39772
39773 pr_debug("snd_intelmad_device_set called\n");
39774
39775diff -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
39776--- linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-19 00:06:34.000000000 -0400
39777+++ linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-22 19:36:32.000000000 -0400
39778@@ -470,7 +470,7 @@ int sst_device_control(int cmd, void *ar
39779 }
39780
39781
39782-struct intel_sst_pcm_control pcm_ops = {
39783+const struct intel_sst_pcm_control pcm_ops = {
39784 .open = sst_open_pcm_stream,
39785 .device_control = sst_device_control,
39786 .close = sst_close_pcm_stream,
39787diff -urNp linux-2.6.39.1/drivers/staging/line6/capture.c linux-2.6.39.1/drivers/staging/line6/capture.c
39788--- linux-2.6.39.1/drivers/staging/line6/capture.c 2011-05-19 00:06:34.000000000 -0400
39789+++ linux-2.6.39.1/drivers/staging/line6/capture.c 2011-05-22 19:36:32.000000000 -0400
39790@@ -378,7 +378,7 @@ snd_line6_capture_pointer(struct snd_pcm
39791 }
39792
39793 /* capture operators */
39794-struct snd_pcm_ops snd_line6_capture_ops = {
39795+const struct snd_pcm_ops snd_line6_capture_ops = {
39796 .open = snd_line6_capture_open,
39797 .close = snd_line6_capture_close,
39798 .ioctl = snd_pcm_lib_ioctl,
39799diff -urNp linux-2.6.39.1/drivers/staging/line6/capture.h linux-2.6.39.1/drivers/staging/line6/capture.h
39800--- linux-2.6.39.1/drivers/staging/line6/capture.h 2011-05-19 00:06:34.000000000 -0400
39801+++ linux-2.6.39.1/drivers/staging/line6/capture.h 2011-05-22 19:36:32.000000000 -0400
39802@@ -17,7 +17,7 @@
39803 #include "driver.h"
39804 #include "pcm.h"
39805
39806-extern struct snd_pcm_ops snd_line6_capture_ops;
39807+extern const struct snd_pcm_ops snd_line6_capture_ops;
39808
39809 extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
39810 int fsize);
39811diff -urNp linux-2.6.39.1/drivers/staging/line6/midi.c linux-2.6.39.1/drivers/staging/line6/midi.c
39812--- linux-2.6.39.1/drivers/staging/line6/midi.c 2011-05-19 00:06:34.000000000 -0400
39813+++ linux-2.6.39.1/drivers/staging/line6/midi.c 2011-05-22 19:36:32.000000000 -0400
39814@@ -239,14 +239,14 @@ static void line6_midi_input_trigger(str
39815 line6->line6midi->substream_receive = 0;
39816 }
39817
39818-static struct snd_rawmidi_ops line6_midi_output_ops = {
39819+static const struct snd_rawmidi_ops line6_midi_output_ops = {
39820 .open = line6_midi_output_open,
39821 .close = line6_midi_output_close,
39822 .trigger = line6_midi_output_trigger,
39823 .drain = line6_midi_output_drain,
39824 };
39825
39826-static struct snd_rawmidi_ops line6_midi_input_ops = {
39827+static const struct snd_rawmidi_ops line6_midi_input_ops = {
39828 .open = line6_midi_input_open,
39829 .close = line6_midi_input_close,
39830 .trigger = line6_midi_input_trigger,
39831@@ -373,7 +373,7 @@ static int snd_line6_midi_free(struct sn
39832 */
39833 int line6_init_midi(struct usb_line6 *line6)
39834 {
39835- static struct snd_device_ops midi_ops = {
39836+ static const struct snd_device_ops midi_ops = {
39837 .dev_free = snd_line6_midi_free,
39838 };
39839
39840diff -urNp linux-2.6.39.1/drivers/staging/line6/pcm.c linux-2.6.39.1/drivers/staging/line6/pcm.c
39841--- linux-2.6.39.1/drivers/staging/line6/pcm.c 2011-05-19 00:06:34.000000000 -0400
39842+++ linux-2.6.39.1/drivers/staging/line6/pcm.c 2011-05-22 19:36:32.000000000 -0400
39843@@ -384,7 +384,7 @@ void line6_pcm_disconnect(struct snd_lin
39844 int line6_init_pcm(struct usb_line6 *line6,
39845 struct line6_pcm_properties *properties)
39846 {
39847- static struct snd_device_ops pcm_ops = {
39848+ static const struct snd_device_ops pcm_ops = {
39849 .dev_free = snd_line6_pcm_free,
39850 };
39851
39852diff -urNp linux-2.6.39.1/drivers/staging/line6/playback.c linux-2.6.39.1/drivers/staging/line6/playback.c
39853--- linux-2.6.39.1/drivers/staging/line6/playback.c 2011-05-19 00:06:34.000000000 -0400
39854+++ linux-2.6.39.1/drivers/staging/line6/playback.c 2011-05-22 19:36:32.000000000 -0400
39855@@ -536,7 +536,7 @@ snd_line6_playback_pointer(struct snd_pc
39856 }
39857
39858 /* playback operators */
39859-struct snd_pcm_ops snd_line6_playback_ops = {
39860+const struct snd_pcm_ops snd_line6_playback_ops = {
39861 .open = snd_line6_playback_open,
39862 .close = snd_line6_playback_close,
39863 .ioctl = snd_pcm_lib_ioctl,
39864diff -urNp linux-2.6.39.1/drivers/staging/line6/playback.h linux-2.6.39.1/drivers/staging/line6/playback.h
39865--- linux-2.6.39.1/drivers/staging/line6/playback.h 2011-05-19 00:06:34.000000000 -0400
39866+++ linux-2.6.39.1/drivers/staging/line6/playback.h 2011-05-22 19:36:32.000000000 -0400
39867@@ -27,7 +27,7 @@
39868 */
39869 #define USE_CLEAR_BUFFER_WORKAROUND 1
39870
39871-extern struct snd_pcm_ops snd_line6_playback_ops;
39872+extern const struct snd_pcm_ops snd_line6_playback_ops;
39873
39874 extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
39875 extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
39876diff -urNp linux-2.6.39.1/drivers/staging/msm/staging-devices.c linux-2.6.39.1/drivers/staging/msm/staging-devices.c
39877--- linux-2.6.39.1/drivers/staging/msm/staging-devices.c 2011-05-19 00:06:34.000000000 -0400
39878+++ linux-2.6.39.1/drivers/staging/msm/staging-devices.c 2011-05-22 19:36:32.000000000 -0400
39879@@ -211,7 +211,7 @@ static int msm_fb_lcdc_gpio_config(int o
39880 }
39881
39882
39883-static struct lcdc_platform_data lcdc_pdata = {
39884+static const struct lcdc_platform_data lcdc_pdata = {
39885 .lcdc_gpio_config = msm_fb_lcdc_gpio_config,
39886 };
39887
39888diff -urNp linux-2.6.39.1/drivers/staging/octeon/ethernet.c linux-2.6.39.1/drivers/staging/octeon/ethernet.c
39889--- linux-2.6.39.1/drivers/staging/octeon/ethernet.c 2011-05-19 00:06:34.000000000 -0400
39890+++ linux-2.6.39.1/drivers/staging/octeon/ethernet.c 2011-05-22 19:36:32.000000000 -0400
39891@@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_
39892 * since the RX tasklet also increments it.
39893 */
39894 #ifdef CONFIG_64BIT
39895- atomic64_add(rx_status.dropped_packets,
39896- (atomic64_t *)&priv->stats.rx_dropped);
39897+ atomic64_add_unchecked(rx_status.dropped_packets,
39898+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39899 #else
39900- atomic_add(rx_status.dropped_packets,
39901- (atomic_t *)&priv->stats.rx_dropped);
39902+ atomic_add_unchecked(rx_status.dropped_packets,
39903+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
39904 #endif
39905 }
39906
39907diff -urNp linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c
39908--- linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c 2011-05-19 00:06:34.000000000 -0400
39909+++ linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c 2011-05-22 19:36:32.000000000 -0400
39910@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi
39911 /* Increment RX stats for virtual ports */
39912 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39913 #ifdef CONFIG_64BIT
39914- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39915- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39916+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39917+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39918 #else
39919- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39920- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39921+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39922+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39923 #endif
39924 }
39925 netif_receive_skb(skb);
39926@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi
39927 dev->name);
39928 */
39929 #ifdef CONFIG_64BIT
39930- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39931+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39932 #else
39933- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39934+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39935 #endif
39936 dev_kfree_skb_irq(skb);
39937 }
39938diff -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
39939--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-19 00:06:34.000000000 -0400
39940+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-22 19:36:32.000000000 -0400
39941@@ -43,7 +43,7 @@ module_param(noinit, int, 0444);
39942 static int useaa = 1;
39943 module_param(useaa, int, 0444);
39944
39945-static struct dcon_platform_data *pdata;
39946+static const struct dcon_platform_data *pdata;
39947
39948 /* I2C structures */
39949
39950diff -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
39951--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-19 00:06:34.000000000 -0400
39952+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-22 19:36:32.000000000 -0400
39953@@ -92,11 +92,11 @@ struct dcon_platform_data {
39954 extern irqreturn_t dcon_interrupt(int irq, void *id);
39955
39956 #ifdef CONFIG_FB_OLPC_DCON_1
39957-extern struct dcon_platform_data dcon_pdata_xo_1;
39958+extern const struct dcon_platform_data dcon_pdata_xo_1;
39959 #endif
39960
39961 #ifdef CONFIG_FB_OLPC_DCON_1_5
39962-extern struct dcon_platform_data dcon_pdata_xo_1_5;
39963+extern const struct dcon_platform_data dcon_pdata_xo_1_5;
39964 #endif
39965
39966 #endif
39967diff -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
39968--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-19 00:06:34.000000000 -0400
39969+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-22 19:36:32.000000000 -0400
39970@@ -185,7 +185,7 @@ static u8 dcon_read_status_xo_1_5(void)
39971 return status;
39972 }
39973
39974-struct dcon_platform_data dcon_pdata_xo_1_5 = {
39975+const struct dcon_platform_data dcon_pdata_xo_1_5 = {
39976 .init = dcon_init_xo_1_5,
39977 .bus_stabilize_wiggle = dcon_wiggle_xo_1_5,
39978 .set_dconload = dcon_set_dconload_xo_1_5,
39979diff -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
39980--- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-19 00:06:34.000000000 -0400
39981+++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-22 19:36:32.000000000 -0400
39982@@ -196,7 +196,7 @@ static u8 dcon_read_status_xo_1(void)
39983 return status;
39984 }
39985
39986-struct dcon_platform_data dcon_pdata_xo_1 = {
39987+const struct dcon_platform_data dcon_pdata_xo_1 = {
39988 .init = dcon_init_xo_1,
39989 .bus_stabilize_wiggle = dcon_wiggle_xo_1,
39990 .set_dconload = dcon_set_dconload_1,
39991diff -urNp linux-2.6.39.1/drivers/staging/phison/phison.c linux-2.6.39.1/drivers/staging/phison/phison.c
39992--- linux-2.6.39.1/drivers/staging/phison/phison.c 2011-05-19 00:06:34.000000000 -0400
39993+++ linux-2.6.39.1/drivers/staging/phison/phison.c 2011-05-22 19:36:32.000000000 -0400
39994@@ -43,7 +43,7 @@ static struct scsi_host_template phison_
39995 ATA_BMDMA_SHT(DRV_NAME),
39996 };
39997
39998-static struct ata_port_operations phison_ops = {
39999+static const struct ata_port_operations phison_ops = {
40000 .inherits = &ata_bmdma_port_ops,
40001 .prereset = phison_pre_reset,
40002 };
40003diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/inode.c linux-2.6.39.1/drivers/staging/pohmelfs/inode.c
40004--- linux-2.6.39.1/drivers/staging/pohmelfs/inode.c 2011-05-19 00:06:34.000000000 -0400
40005+++ linux-2.6.39.1/drivers/staging/pohmelfs/inode.c 2011-05-22 19:36:32.000000000 -0400
40006@@ -1855,7 +1855,7 @@ static int pohmelfs_fill_super(struct su
40007 mutex_init(&psb->mcache_lock);
40008 psb->mcache_root = RB_ROOT;
40009 psb->mcache_timeout = msecs_to_jiffies(5000);
40010- atomic_long_set(&psb->mcache_gen, 0);
40011+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
40012
40013 psb->trans_max_pages = 100;
40014
40015@@ -1870,7 +1870,7 @@ static int pohmelfs_fill_super(struct su
40016 INIT_LIST_HEAD(&psb->crypto_ready_list);
40017 INIT_LIST_HEAD(&psb->crypto_active_list);
40018
40019- atomic_set(&psb->trans_gen, 1);
40020+ atomic_set_unchecked(&psb->trans_gen, 1);
40021 atomic_long_set(&psb->total_inodes, 0);
40022
40023 mutex_init(&psb->state_lock);
40024diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c
40025--- linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c 2011-05-19 00:06:34.000000000 -0400
40026+++ linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c 2011-05-22 19:36:32.000000000 -0400
40027@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
40028 m->data = data;
40029 m->start = start;
40030 m->size = size;
40031- m->gen = atomic_long_inc_return(&psb->mcache_gen);
40032+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
40033
40034 mutex_lock(&psb->mcache_lock);
40035 err = pohmelfs_mcache_insert(psb, m);
40036diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h
40037--- linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h 2011-05-19 00:06:34.000000000 -0400
40038+++ linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h 2011-05-22 19:36:32.000000000 -0400
40039@@ -571,14 +571,14 @@ struct pohmelfs_config;
40040 struct pohmelfs_sb {
40041 struct rb_root mcache_root;
40042 struct mutex mcache_lock;
40043- atomic_long_t mcache_gen;
40044+ atomic_long_unchecked_t mcache_gen;
40045 unsigned long mcache_timeout;
40046
40047 unsigned int idx;
40048
40049 unsigned int trans_retries;
40050
40051- atomic_t trans_gen;
40052+ atomic_unchecked_t trans_gen;
40053
40054 unsigned int crypto_attached_size;
40055 unsigned int crypto_align_size;
40056diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/trans.c linux-2.6.39.1/drivers/staging/pohmelfs/trans.c
40057--- linux-2.6.39.1/drivers/staging/pohmelfs/trans.c 2011-05-19 00:06:34.000000000 -0400
40058+++ linux-2.6.39.1/drivers/staging/pohmelfs/trans.c 2011-05-22 19:36:32.000000000 -0400
40059@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
40060 int err;
40061 struct netfs_cmd *cmd = t->iovec.iov_base;
40062
40063- t->gen = atomic_inc_return(&psb->trans_gen);
40064+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
40065
40066 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
40067 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
40068diff -urNp linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c
40069--- linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-19 00:06:34.000000000 -0400
40070+++ linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-22 19:36:32.000000000 -0400
40071@@ -87,7 +87,7 @@ static int c_show(struct seq_file *m, vo
40072 return 0;
40073 }
40074
40075-static struct seq_operations crypto_seq_ops = {
40076+static const struct seq_operations crypto_seq_ops = {
40077 .start = c_start,
40078 .next = c_next,
40079 .stop = c_stop,
40080@@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
40081 return seq_open(file, &crypto_seq_ops);
40082 }
40083
40084-static struct file_operations proc_crypto_ops = {
40085+static const struct file_operations proc_crypto_ops = {
40086 .open = crypto_info_open,
40087 .read = seq_read,
40088 .llseek = seq_lseek,
40089diff -urNp linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h
40090--- linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h 2011-05-19 00:06:34.000000000 -0400
40091+++ linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h 2011-05-22 19:36:32.000000000 -0400
40092@@ -107,7 +107,7 @@ struct intf_hdl {
40093 void (*intf_hdl_unload)(u8 *priv);
40094 void (*intf_hdl_open)(u8 *priv);
40095 void (*intf_hdl_close)(u8 *priv);
40096- struct _io_ops io_ops;
40097+ const struct _io_ops io_ops;
40098 };
40099
40100 struct reg_protocol_rd {
40101diff -urNp linux-2.6.39.1/drivers/staging/solo6x10/g723.c linux-2.6.39.1/drivers/staging/solo6x10/g723.c
40102--- linux-2.6.39.1/drivers/staging/solo6x10/g723.c 2011-05-19 00:06:34.000000000 -0400
40103+++ linux-2.6.39.1/drivers/staging/solo6x10/g723.c 2011-05-22 19:36:32.000000000 -0400
40104@@ -237,7 +237,7 @@ static int snd_solo_pcm_copy(struct snd_
40105 return 0;
40106 }
40107
40108-static struct snd_pcm_ops snd_solo_pcm_ops = {
40109+static const struct snd_pcm_ops snd_solo_pcm_ops = {
40110 .open = snd_solo_pcm_open,
40111 .close = snd_solo_pcm_close,
40112 .ioctl = snd_pcm_lib_ioctl,
40113@@ -334,7 +334,7 @@ static int solo_snd_pcm_init(struct solo
40114
40115 int solo_g723_init(struct solo_dev *solo_dev)
40116 {
40117- static struct snd_device_ops ops = { NULL };
40118+ static const struct snd_device_ops ops = { NULL };
40119 struct snd_card *card;
40120 struct snd_kcontrol_new kctl;
40121 char name[32];
40122diff -urNp linux-2.6.39.1/drivers/staging/spectra/ffsport.c linux-2.6.39.1/drivers/staging/spectra/ffsport.c
40123--- linux-2.6.39.1/drivers/staging/spectra/ffsport.c 2011-05-19 00:06:34.000000000 -0400
40124+++ linux-2.6.39.1/drivers/staging/spectra/ffsport.c 2011-05-22 19:36:32.000000000 -0400
40125@@ -604,7 +604,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
40126 return ret;
40127 }
40128
40129-static struct block_device_operations GLOB_SBD_ops = {
40130+static const struct block_device_operations GLOB_SBD_ops = {
40131 .owner = THIS_MODULE,
40132 .open = GLOB_SBD_open,
40133 .release = GLOB_SBD_release,
40134diff -urNp linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c
40135--- linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c 2011-05-19 00:06:34.000000000 -0400
40136+++ linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c 2011-05-22 19:36:32.000000000 -0400
40137@@ -380,7 +380,7 @@ static snd_pcm_uframes_t snd_tm6000_poin
40138 /*
40139 * operators
40140 */
40141-static struct snd_pcm_ops snd_tm6000_pcm_ops = {
40142+static const struct snd_pcm_ops snd_tm6000_pcm_ops = {
40143 .open = snd_tm6000_pcm_open,
40144 .close = snd_tm6000_close,
40145 .ioctl = snd_pcm_lib_ioctl,
40146diff -urNp linux-2.6.39.1/drivers/staging/tty/istallion.c linux-2.6.39.1/drivers/staging/tty/istallion.c
40147--- linux-2.6.39.1/drivers/staging/tty/istallion.c 2011-05-19 00:06:34.000000000 -0400
40148+++ linux-2.6.39.1/drivers/staging/tty/istallion.c 2011-05-22 20:49:07.000000000 -0400
40149@@ -186,7 +186,6 @@ static struct ktermios stli_deftermios
40150 * re-used for each stats call.
40151 */
40152 static comstats_t stli_comstats;
40153-static combrd_t stli_brdstats;
40154 static struct asystats stli_cdkstats;
40155
40156 /*****************************************************************************/
40157@@ -4003,6 +4002,7 @@ out:
40158
40159 static int stli_getbrdstats(combrd_t __user *bp)
40160 {
40161+ combrd_t stli_brdstats;
40162 struct stlibrd *brdp;
40163 unsigned int i;
40164
40165@@ -4226,6 +4226,8 @@ static int stli_getportstruct(struct stl
40166 struct stliport stli_dummyport;
40167 struct stliport *portp;
40168
40169+ pax_track_stack();
40170+
40171 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
40172 return -EFAULT;
40173 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
40174@@ -4248,6 +4250,8 @@ static int stli_getbrdstruct(struct stli
40175 struct stlibrd stli_dummybrd;
40176 struct stlibrd *brdp;
40177
40178+ pax_track_stack();
40179+
40180 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
40181 return -EFAULT;
40182 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
40183diff -urNp linux-2.6.39.1/drivers/staging/tty/stallion.c linux-2.6.39.1/drivers/staging/tty/stallion.c
40184--- linux-2.6.39.1/drivers/staging/tty/stallion.c 2011-05-19 00:06:34.000000000 -0400
40185+++ linux-2.6.39.1/drivers/staging/tty/stallion.c 2011-05-22 19:36:32.000000000 -0400
40186@@ -2406,6 +2406,8 @@ static int stl_getportstruct(struct stlp
40187 struct stlport stl_dummyport;
40188 struct stlport *portp;
40189
40190+ pax_track_stack();
40191+
40192 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
40193 return -EFAULT;
40194 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
40195diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci.h linux-2.6.39.1/drivers/staging/usbip/vhci.h
40196--- linux-2.6.39.1/drivers/staging/usbip/vhci.h 2011-05-19 00:06:34.000000000 -0400
40197+++ linux-2.6.39.1/drivers/staging/usbip/vhci.h 2011-05-22 19:36:32.000000000 -0400
40198@@ -92,7 +92,7 @@ struct vhci_hcd {
40199 unsigned resuming:1;
40200 unsigned long re_timeout;
40201
40202- atomic_t seqnum;
40203+ atomic_unchecked_t seqnum;
40204
40205 /*
40206 * NOTE:
40207diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c
40208--- linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c 2011-05-19 00:06:34.000000000 -0400
40209+++ linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c 2011-05-22 19:36:32.000000000 -0400
40210@@ -536,7 +536,7 @@ static void vhci_tx_urb(struct urb *urb)
40211 return;
40212 }
40213
40214- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40215+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40216 if (priv->seqnum == 0xffff)
40217 usbip_uinfo("seqnum max\n");
40218
40219@@ -795,7 +795,7 @@ static int vhci_urb_dequeue(struct usb_h
40220 return -ENOMEM;
40221 }
40222
40223- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40224+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40225 if (unlink->seqnum == 0xffff)
40226 usbip_uinfo("seqnum max\n");
40227
40228@@ -992,7 +992,7 @@ static int vhci_start(struct usb_hcd *hc
40229 vdev->rhport = rhport;
40230 }
40231
40232- atomic_set(&vhci->seqnum, 0);
40233+ atomic_set_unchecked(&vhci->seqnum, 0);
40234 spin_lock_init(&vhci->lock);
40235
40236
40237diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c
40238--- linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c 2011-05-19 00:06:34.000000000 -0400
40239+++ linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c 2011-05-22 19:36:32.000000000 -0400
40240@@ -81,7 +81,7 @@ static void vhci_recv_ret_submit(struct
40241 usbip_uerr("cannot find a urb of seqnum %u\n",
40242 pdu->base.seqnum);
40243 usbip_uinfo("max seqnum %d\n",
40244- atomic_read(&the_controller->seqnum));
40245+ atomic_read_unchecked(&the_controller->seqnum));
40246 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40247 return;
40248 }
40249diff -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
40250--- linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c 2011-05-19 00:06:34.000000000 -0400
40251+++ linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c 2011-05-22 19:36:32.000000000 -0400
40252@@ -138,7 +138,7 @@ static long vme_user_unlocked_ioctl(stru
40253 static int __devinit vme_user_probe(struct device *, int, int);
40254 static int __devexit vme_user_remove(struct device *, int, int);
40255
40256-static struct file_operations vme_user_fops = {
40257+static const struct file_operations vme_user_fops = {
40258 .open = vme_user_open,
40259 .release = vme_user_release,
40260 .read = vme_user_read,
40261diff -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
40262--- linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-19 00:06:34.000000000 -0400
40263+++ linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-22 19:36:32.000000000 -0400
40264@@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
40265
40266
40267 /*standard block device driver interface */
40268-static struct block_device_operations cyasblkdev_bdops = {
40269+static const struct block_device_operations cyasblkdev_bdops = {
40270 .open = cyasblkdev_blk_open,
40271 .release = cyasblkdev_blk_release,
40272 .ioctl = cyasblkdev_blk_ioctl,
40273diff -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
40274--- linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-19 00:06:34.000000000 -0400
40275+++ linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-22 19:36:32.000000000 -0400
40276@@ -474,7 +474,7 @@ static void wl_get_drvinfo(struct net_de
40277 }
40278 } // wl_get_drvinfo
40279
40280-static struct ethtool_ops wl_ethtool_ops = {
40281+static const struct ethtool_ops wl_ethtool_ops = {
40282 .get_drvinfo = wl_get_drvinfo,
40283 .get_link = ethtool_op_get_link,
40284 };
40285diff -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
40286--- linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-19 00:06:34.000000000 -0400
40287+++ linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-22 19:36:32.000000000 -0400
40288@@ -671,7 +671,7 @@ struct usbctlx_cmd_completor {
40289 hfa384x_cmdresult_t *result;
40290 };
40291
40292-static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
40293+static inline int usbctlx_cmd_completor_fn(const struct usbctlx_completor *head)
40294 {
40295 struct usbctlx_cmd_completor *complete;
40296
40297@@ -705,7 +705,7 @@ struct usbctlx_rrid_completor {
40298 unsigned int riddatalen;
40299 };
40300
40301-static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
40302+static int usbctlx_rrid_completor_fn(const struct usbctlx_completor *head)
40303 {
40304 struct usbctlx_rrid_completor *complete;
40305 hfa384x_rridresult_t rridresult;
40306@@ -768,7 +768,7 @@ struct usbctlx_rmem_completor {
40307 };
40308 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
40309
40310-static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
40311+static int usbctlx_rmem_completor_fn(const struct usbctlx_completor *head)
40312 {
40313 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
40314
40315diff -urNp linux-2.6.39.1/drivers/staging/zcache/tmem.c linux-2.6.39.1/drivers/staging/zcache/tmem.c
40316--- linux-2.6.39.1/drivers/staging/zcache/tmem.c 2011-05-19 00:06:34.000000000 -0400
40317+++ linux-2.6.39.1/drivers/staging/zcache/tmem.c 2011-05-22 19:36:32.000000000 -0400
40318@@ -39,7 +39,7 @@
40319 * A tmem host implementation must use this function to register callbacks
40320 * for memory allocation.
40321 */
40322-static struct tmem_hostops tmem_hostops;
40323+static const struct tmem_hostops tmem_hostops;
40324
40325 static void tmem_objnode_tree_init(void);
40326
40327@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_h
40328 * A tmem host implementation must use this function to register
40329 * callbacks for a page-accessible memory (PAM) implementation
40330 */
40331-static struct tmem_pamops tmem_pamops;
40332+static const struct tmem_pamops tmem_pamops;
40333
40334 void tmem_register_pamops(struct tmem_pamops *m)
40335 {
40336diff -urNp linux-2.6.39.1/drivers/staging/zcache/zcache.c linux-2.6.39.1/drivers/staging/zcache/zcache.c
40337--- linux-2.6.39.1/drivers/staging/zcache/zcache.c 2011-05-19 00:06:34.000000000 -0400
40338+++ linux-2.6.39.1/drivers/staging/zcache/zcache.c 2011-05-22 19:36:32.000000000 -0400
40339@@ -882,7 +882,7 @@ static void zcache_obj_free(struct tmem_
40340 kmem_cache_free(zcache_obj_cache, obj);
40341 }
40342
40343-static struct tmem_hostops zcache_hostops = {
40344+static const struct tmem_hostops zcache_hostops = {
40345 .obj_alloc = zcache_obj_alloc,
40346 .obj_free = zcache_obj_free,
40347 .objnode_alloc = zcache_objnode_alloc,
40348@@ -987,7 +987,7 @@ static void zcache_pampd_free(void *pamp
40349 }
40350 }
40351
40352-static struct tmem_pamops zcache_pamops = {
40353+static const struct tmem_pamops zcache_pamops = {
40354 .create = zcache_pampd_create,
40355 .get_data = zcache_pampd_get_data,
40356 .free = zcache_pampd_free,
40357diff -urNp linux-2.6.39.1/drivers/target/target_core_alua.c linux-2.6.39.1/drivers/target/target_core_alua.c
40358--- linux-2.6.39.1/drivers/target/target_core_alua.c 2011-05-19 00:06:34.000000000 -0400
40359+++ linux-2.6.39.1/drivers/target/target_core_alua.c 2011-05-22 19:36:32.000000000 -0400
40360@@ -675,6 +675,8 @@ static int core_alua_update_tpg_primary_
40361 char path[ALUA_METADATA_PATH_LEN];
40362 int len;
40363
40364+ pax_track_stack();
40365+
40366 memset(path, 0, ALUA_METADATA_PATH_LEN);
40367
40368 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
40369@@ -938,6 +940,8 @@ static int core_alua_update_tpg_secondar
40370 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
40371 int len;
40372
40373+ pax_track_stack();
40374+
40375 memset(path, 0, ALUA_METADATA_PATH_LEN);
40376 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
40377
40378diff -urNp linux-2.6.39.1/drivers/target/target_core_cdb.c linux-2.6.39.1/drivers/target/target_core_cdb.c
40379--- linux-2.6.39.1/drivers/target/target_core_cdb.c 2011-05-19 00:06:34.000000000 -0400
40380+++ linux-2.6.39.1/drivers/target/target_core_cdb.c 2011-05-22 19:36:32.000000000 -0400
40381@@ -838,6 +838,8 @@ target_emulate_modesense(struct se_cmd *
40382 int length = 0;
40383 unsigned char buf[SE_MODE_PAGE_BUF];
40384
40385+ pax_track_stack();
40386+
40387 memset(buf, 0, SE_MODE_PAGE_BUF);
40388
40389 switch (cdb[2] & 0x3f) {
40390diff -urNp linux-2.6.39.1/drivers/target/target_core_configfs.c linux-2.6.39.1/drivers/target/target_core_configfs.c
40391--- linux-2.6.39.1/drivers/target/target_core_configfs.c 2011-05-19 00:06:34.000000000 -0400
40392+++ linux-2.6.39.1/drivers/target/target_core_configfs.c 2011-05-22 19:36:32.000000000 -0400
40393@@ -1280,6 +1280,8 @@ static ssize_t target_core_dev_pr_show_a
40394 ssize_t len = 0;
40395 int reg_count = 0, prf_isid;
40396
40397+ pax_track_stack();
40398+
40399 if (!(su_dev->se_dev_ptr))
40400 return -ENODEV;
40401
40402@@ -2682,7 +2684,7 @@ static void target_core_alua_drop_tg_pt_
40403 config_item_put(item);
40404 }
40405
40406-static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40407+static const struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40408 .make_group = &target_core_alua_create_tg_pt_gp,
40409 .drop_item = &target_core_alua_drop_tg_pt_gp,
40410 };
40411@@ -2726,7 +2728,7 @@ static void target_core_stat_rmdir(
40412 return;
40413 }
40414
40415-static struct configfs_group_operations target_core_stat_group_ops = {
40416+static const struct configfs_group_operations target_core_stat_group_ops = {
40417 .make_group = &target_core_stat_mkdir,
40418 .drop_item = &target_core_stat_rmdir,
40419 };
40420@@ -2939,7 +2941,7 @@ static void target_core_drop_subdev(
40421 mutex_unlock(&hba->hba_access_mutex);
40422 }
40423
40424-static struct configfs_group_operations target_core_hba_group_ops = {
40425+static const struct configfs_group_operations target_core_hba_group_ops = {
40426 .make_group = target_core_make_subdev,
40427 .drop_item = target_core_drop_subdev,
40428 };
40429@@ -3117,7 +3119,7 @@ static void target_core_call_delhbafromt
40430 config_item_put(item);
40431 }
40432
40433-static struct configfs_group_operations target_core_group_ops = {
40434+static const struct configfs_group_operations target_core_group_ops = {
40435 .make_group = target_core_call_addhbatotarget,
40436 .drop_item = target_core_call_delhbafromtarget,
40437 };
40438diff -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
40439--- linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c 2011-05-19 00:06:34.000000000 -0400
40440+++ linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c 2011-05-22 19:36:32.000000000 -0400
40441@@ -1174,7 +1174,7 @@ static void target_fabric_drop_wwn(
40442 config_item_put(item);
40443 }
40444
40445-static struct configfs_group_operations target_fabric_wwn_group_ops = {
40446+static const struct configfs_group_operations target_fabric_wwn_group_ops = {
40447 .make_group = target_fabric_make_wwn,
40448 .drop_item = target_fabric_drop_wwn,
40449 };
40450diff -urNp linux-2.6.39.1/drivers/target/target_core_pr.c linux-2.6.39.1/drivers/target/target_core_pr.c
40451--- linux-2.6.39.1/drivers/target/target_core_pr.c 2011-05-19 00:06:34.000000000 -0400
40452+++ linux-2.6.39.1/drivers/target/target_core_pr.c 2011-05-22 19:36:32.000000000 -0400
40453@@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_regi
40454 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
40455 u16 tpgt;
40456
40457+ pax_track_stack();
40458+
40459 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
40460 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
40461 /*
40462@@ -1861,6 +1863,8 @@ static int __core_scsi3_update_aptpl_buf
40463 ssize_t len = 0;
40464 int reg_count = 0;
40465
40466+ pax_track_stack();
40467+
40468 memset(buf, 0, pr_aptpl_buf_len);
40469 /*
40470 * Called to clear metadata once APTPL has been deactivated.
40471@@ -1983,6 +1987,8 @@ static int __core_scsi3_write_aptpl_to_f
40472 char path[512];
40473 int ret;
40474
40475+ pax_track_stack();
40476+
40477 memset(iov, 0, sizeof(struct iovec));
40478 memset(path, 0, 512);
40479
40480diff -urNp linux-2.6.39.1/drivers/target/target_core_tmr.c linux-2.6.39.1/drivers/target/target_core_tmr.c
40481--- linux-2.6.39.1/drivers/target/target_core_tmr.c 2011-06-03 00:04:14.000000000 -0400
40482+++ linux-2.6.39.1/drivers/target/target_core_tmr.c 2011-06-03 00:32:07.000000000 -0400
40483@@ -263,7 +263,7 @@ int core_tmr_lun_reset(
40484 CMD_TFO(cmd)->get_task_tag(cmd), cmd->pr_res_key,
40485 T_TASK(cmd)->t_task_cdbs,
40486 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40487- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40488+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40489 atomic_read(&T_TASK(cmd)->t_transport_active),
40490 atomic_read(&T_TASK(cmd)->t_transport_stop),
40491 atomic_read(&T_TASK(cmd)->t_transport_sent));
40492@@ -305,7 +305,7 @@ int core_tmr_lun_reset(
40493 DEBUG_LR("LUN_RESET: got t_transport_active = 1 for"
40494 " task: %p, t_fe_count: %d dev: %p\n", task,
40495 fe_count, dev);
40496- atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40497+ atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40498 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock,
40499 flags);
40500 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40501@@ -315,7 +315,7 @@ int core_tmr_lun_reset(
40502 }
40503 DEBUG_LR("LUN_RESET: Got t_transport_active = 0 for task: %p,"
40504 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
40505- atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40506+ atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40507 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
40508 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40509
40510diff -urNp linux-2.6.39.1/drivers/target/target_core_transport.c linux-2.6.39.1/drivers/target/target_core_transport.c
40511--- linux-2.6.39.1/drivers/target/target_core_transport.c 2011-06-03 00:04:14.000000000 -0400
40512+++ linux-2.6.39.1/drivers/target/target_core_transport.c 2011-06-03 00:32:07.000000000 -0400
40513@@ -1681,7 +1681,7 @@ struct se_device *transport_add_device_t
40514
40515 dev->queue_depth = dev_limits->queue_depth;
40516 atomic_set(&dev->depth_left, dev->queue_depth);
40517- atomic_set(&dev->dev_ordered_id, 0);
40518+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
40519
40520 se_dev_set_default_attribs(dev, dev_limits);
40521
40522@@ -1882,7 +1882,7 @@ static int transport_check_alloc_task_at
40523 * Used to determine when ORDERED commands should go from
40524 * Dormant to Active status.
40525 */
40526- cmd->se_ordered_id = atomic_inc_return(&SE_DEV(cmd)->dev_ordered_id);
40527+ cmd->se_ordered_id = atomic_inc_return_unchecked(&SE_DEV(cmd)->dev_ordered_id);
40528 smp_mb__after_atomic_inc();
40529 DEBUG_STA("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40530 cmd->se_ordered_id, cmd->sam_task_attr,
40531@@ -2169,7 +2169,7 @@ static void transport_generic_request_fa
40532 " t_transport_active: %d t_transport_stop: %d"
40533 " t_transport_sent: %d\n", T_TASK(cmd)->t_task_cdbs,
40534 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40535- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40536+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40537 atomic_read(&T_TASK(cmd)->t_task_cdbs_ex_left),
40538 atomic_read(&T_TASK(cmd)->t_transport_active),
40539 atomic_read(&T_TASK(cmd)->t_transport_stop),
40540@@ -2673,9 +2673,9 @@ check_depth:
40541 spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
40542 atomic_set(&task->task_active, 1);
40543 atomic_set(&task->task_sent, 1);
40544- atomic_inc(&T_TASK(cmd)->t_task_cdbs_sent);
40545+ atomic_inc_unchecked(&T_TASK(cmd)->t_task_cdbs_sent);
40546
40547- if (atomic_read(&T_TASK(cmd)->t_task_cdbs_sent) ==
40548+ if (atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent) ==
40549 T_TASK(cmd)->t_task_cdbs)
40550 atomic_set(&cmd->transport_sent, 1);
40551
40552@@ -5568,7 +5568,7 @@ static void transport_generic_wait_for_t
40553 atomic_set(&T_TASK(cmd)->transport_lun_stop, 0);
40554 }
40555 if (!atomic_read(&T_TASK(cmd)->t_transport_active) ||
40556- atomic_read(&T_TASK(cmd)->t_transport_aborted))
40557+ atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted))
40558 goto remove;
40559
40560 atomic_set(&T_TASK(cmd)->t_transport_stop, 1);
40561@@ -5797,7 +5797,7 @@ int transport_check_aborted_status(struc
40562 {
40563 int ret = 0;
40564
40565- if (atomic_read(&T_TASK(cmd)->t_transport_aborted) != 0) {
40566+ if (atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted) != 0) {
40567 if (!(send_status) ||
40568 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
40569 return 1;
40570@@ -5825,7 +5825,7 @@ void transport_send_task_abort(struct se
40571 */
40572 if (cmd->data_direction == DMA_TO_DEVICE) {
40573 if (CMD_TFO(cmd)->write_pending_status(cmd) != 0) {
40574- atomic_inc(&T_TASK(cmd)->t_transport_aborted);
40575+ atomic_inc_unchecked(&T_TASK(cmd)->t_transport_aborted);
40576 smp_mb__after_atomic_inc();
40577 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
40578 transport_new_cmd_failure(cmd);
40579@@ -5949,7 +5949,7 @@ static void transport_processing_shutdow
40580 CMD_TFO(cmd)->get_task_tag(cmd),
40581 T_TASK(cmd)->t_task_cdbs,
40582 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40583- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40584+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40585 atomic_read(&T_TASK(cmd)->t_transport_active),
40586 atomic_read(&T_TASK(cmd)->t_transport_stop),
40587 atomic_read(&T_TASK(cmd)->t_transport_sent));
40588diff -urNp linux-2.6.39.1/drivers/telephony/ixj.c linux-2.6.39.1/drivers/telephony/ixj.c
40589--- linux-2.6.39.1/drivers/telephony/ixj.c 2011-05-19 00:06:34.000000000 -0400
40590+++ linux-2.6.39.1/drivers/telephony/ixj.c 2011-05-22 19:36:32.000000000 -0400
40591@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
40592 bool mContinue;
40593 char *pIn, *pOut;
40594
40595+ pax_track_stack();
40596+
40597 if (!SCI_Prepare(j))
40598 return 0;
40599
40600diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_console.h linux-2.6.39.1/drivers/tty/hvc/hvc_console.h
40601--- linux-2.6.39.1/drivers/tty/hvc/hvc_console.h 2011-05-19 00:06:34.000000000 -0400
40602+++ linux-2.6.39.1/drivers/tty/hvc/hvc_console.h 2011-05-22 19:36:32.000000000 -0400
40603@@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
40604 /* register a vterm for hvc tty operation (module_init or hotplug add) */
40605 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
40606 const struct hv_ops *ops, int outbuf_size);
40607+
40608 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
40609 extern int hvc_remove(struct hvc_struct *hp);
40610
40611diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c
40612--- linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c 2011-05-19 00:06:34.000000000 -0400
40613+++ linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c 2011-05-22 19:36:32.000000000 -0400
40614@@ -1203,7 +1203,7 @@ static int param_get_vmidfilter(char *bu
40615
40616 #define param_check_vmidfilter(name, p) __param_check(name, p, void)
40617
40618-static struct kernel_param_ops param_ops_vmidfilter = {
40619+static const struct kernel_param_ops param_ops_vmidfilter = {
40620 .set = param_set_vmidfilter,
40621 .get = param_get_vmidfilter,
40622 };
40623diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvcs.c linux-2.6.39.1/drivers/tty/hvc/hvcs.c
40624--- linux-2.6.39.1/drivers/tty/hvc/hvcs.c 2011-05-19 00:06:34.000000000 -0400
40625+++ linux-2.6.39.1/drivers/tty/hvc/hvcs.c 2011-05-22 19:36:32.000000000 -0400
40626@@ -83,6 +83,7 @@
40627 #include <asm/hvcserver.h>
40628 #include <asm/uaccess.h>
40629 #include <asm/vio.h>
40630+#include <asm/local.h>
40631
40632 /*
40633 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40634@@ -270,7 +271,7 @@ struct hvcs_struct {
40635 unsigned int index;
40636
40637 struct tty_struct *tty;
40638- int open_count;
40639+ local_t open_count;
40640
40641 /*
40642 * Used to tell the driver kernel_thread what operations need to take
40643@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(st
40644
40645 spin_lock_irqsave(&hvcsd->lock, flags);
40646
40647- if (hvcsd->open_count > 0) {
40648+ if (local_read(&hvcsd->open_count) > 0) {
40649 spin_unlock_irqrestore(&hvcsd->lock, flags);
40650 printk(KERN_INFO "HVCS: vterm state unchanged. "
40651 "The hvcs device node is still in use.\n");
40652@@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *
40653 if ((retval = hvcs_partner_connect(hvcsd)))
40654 goto error_release;
40655
40656- hvcsd->open_count = 1;
40657+ local_set(&hvcsd->open_count, 1);
40658 hvcsd->tty = tty;
40659 tty->driver_data = hvcsd;
40660
40661@@ -1179,7 +1180,7 @@ fast_open:
40662
40663 spin_lock_irqsave(&hvcsd->lock, flags);
40664 kref_get(&hvcsd->kref);
40665- hvcsd->open_count++;
40666+ local_inc(&hvcsd->open_count);
40667 hvcsd->todo_mask |= HVCS_SCHED_READ;
40668 spin_unlock_irqrestore(&hvcsd->lock, flags);
40669
40670@@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct
40671 hvcsd = tty->driver_data;
40672
40673 spin_lock_irqsave(&hvcsd->lock, flags);
40674- if (--hvcsd->open_count == 0) {
40675+ if (local_dec_and_test(&hvcsd->open_count)) {
40676
40677 vio_disable_interrupts(hvcsd->vdev);
40678
40679@@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct
40680 free_irq(irq, hvcsd);
40681 kref_put(&hvcsd->kref, destroy_hvcs_struct);
40682 return;
40683- } else if (hvcsd->open_count < 0) {
40684+ } else if (local_read(&hvcsd->open_count) < 0) {
40685 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40686 " is missmanaged.\n",
40687- hvcsd->vdev->unit_address, hvcsd->open_count);
40688+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
40689 }
40690
40691 spin_unlock_irqrestore(&hvcsd->lock, flags);
40692@@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struc
40693
40694 spin_lock_irqsave(&hvcsd->lock, flags);
40695 /* Preserve this so that we know how many kref refs to put */
40696- temp_open_count = hvcsd->open_count;
40697+ temp_open_count = local_read(&hvcsd->open_count);
40698
40699 /*
40700 * Don't kref put inside the spinlock because the destruction
40701@@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struc
40702 hvcsd->tty->driver_data = NULL;
40703 hvcsd->tty = NULL;
40704
40705- hvcsd->open_count = 0;
40706+ local_set(&hvcsd->open_count, 0);
40707
40708 /* This will drop any buffered data on the floor which is OK in a hangup
40709 * scenario. */
40710@@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct
40711 * the middle of a write operation? This is a crummy place to do this
40712 * but we want to keep it all in the spinlock.
40713 */
40714- if (hvcsd->open_count <= 0) {
40715+ if (local_read(&hvcsd->open_count) <= 0) {
40716 spin_unlock_irqrestore(&hvcsd->lock, flags);
40717 return -ENODEV;
40718 }
40719@@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_st
40720 {
40721 struct hvcs_struct *hvcsd = tty->driver_data;
40722
40723- if (!hvcsd || hvcsd->open_count <= 0)
40724+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
40725 return 0;
40726
40727 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40728diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c
40729--- linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c 2011-05-19 00:06:34.000000000 -0400
40730+++ linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c 2011-05-22 19:36:32.000000000 -0400
40731@@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
40732 return recv;
40733 }
40734
40735-static struct hv_ops domU_hvc_ops = {
40736+static const struct hv_ops domU_hvc_ops = {
40737 .get_chars = domU_read_console,
40738 .put_chars = domU_write_console,
40739 .notifier_add = notifier_add_irq,
40740@@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
40741 return len;
40742 }
40743
40744-static struct hv_ops dom0_hvc_ops = {
40745+static const struct hv_ops dom0_hvc_ops = {
40746 .get_chars = dom0_read_console,
40747 .put_chars = dom0_write_console,
40748 .notifier_add = notifier_add_irq,
40749@@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
40750 static int __init xen_hvc_init(void)
40751 {
40752 struct hvc_struct *hp;
40753- struct hv_ops *ops;
40754+ const struct hv_ops *ops;
40755
40756 if (!xen_pv_domain())
40757 return -ENODEV;
40758@@ -205,7 +205,7 @@ static void __exit xen_hvc_fini(void)
40759
40760 static int xen_cons_init(void)
40761 {
40762- struct hv_ops *ops;
40763+ const struct hv_ops *ops;
40764
40765 if (!xen_pv_domain())
40766 return 0;
40767diff -urNp linux-2.6.39.1/drivers/tty/ipwireless/tty.c linux-2.6.39.1/drivers/tty/ipwireless/tty.c
40768--- linux-2.6.39.1/drivers/tty/ipwireless/tty.c 2011-05-19 00:06:34.000000000 -0400
40769+++ linux-2.6.39.1/drivers/tty/ipwireless/tty.c 2011-05-22 19:36:32.000000000 -0400
40770@@ -29,6 +29,7 @@
40771 #include <linux/tty_driver.h>
40772 #include <linux/tty_flip.h>
40773 #include <linux/uaccess.h>
40774+#include <asm/local.h>
40775
40776 #include "tty.h"
40777 #include "network.h"
40778@@ -51,7 +52,7 @@ struct ipw_tty {
40779 int tty_type;
40780 struct ipw_network *network;
40781 struct tty_struct *linux_tty;
40782- int open_count;
40783+ local_t open_count;
40784 unsigned int control_lines;
40785 struct mutex ipw_tty_mutex;
40786 int tx_bytes_queued;
40787@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
40788 mutex_unlock(&tty->ipw_tty_mutex);
40789 return -ENODEV;
40790 }
40791- if (tty->open_count == 0)
40792+ if (local_read(&tty->open_count) == 0)
40793 tty->tx_bytes_queued = 0;
40794
40795- tty->open_count++;
40796+ local_inc(&tty->open_count);
40797
40798 tty->linux_tty = linux_tty;
40799 linux_tty->driver_data = tty;
40800@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
40801
40802 static void do_ipw_close(struct ipw_tty *tty)
40803 {
40804- tty->open_count--;
40805-
40806- if (tty->open_count == 0) {
40807+ if (local_dec_return(&tty->open_count) == 0) {
40808 struct tty_struct *linux_tty = tty->linux_tty;
40809
40810 if (linux_tty != NULL) {
40811@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
40812 return;
40813
40814 mutex_lock(&tty->ipw_tty_mutex);
40815- if (tty->open_count == 0) {
40816+ if (local_read(&tty->open_count) == 0) {
40817 mutex_unlock(&tty->ipw_tty_mutex);
40818 return;
40819 }
40820@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
40821 return;
40822 }
40823
40824- if (!tty->open_count) {
40825+ if (!local_read(&tty->open_count)) {
40826 mutex_unlock(&tty->ipw_tty_mutex);
40827 return;
40828 }
40829@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
40830 return -ENODEV;
40831
40832 mutex_lock(&tty->ipw_tty_mutex);
40833- if (!tty->open_count) {
40834+ if (!local_read(&tty->open_count)) {
40835 mutex_unlock(&tty->ipw_tty_mutex);
40836 return -EINVAL;
40837 }
40838@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
40839 if (!tty)
40840 return -ENODEV;
40841
40842- if (!tty->open_count)
40843+ if (!local_read(&tty->open_count))
40844 return -EINVAL;
40845
40846 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40847@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
40848 if (!tty)
40849 return 0;
40850
40851- if (!tty->open_count)
40852+ if (!local_read(&tty->open_count))
40853 return 0;
40854
40855 return tty->tx_bytes_queued;
40856@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
40857 if (!tty)
40858 return -ENODEV;
40859
40860- if (!tty->open_count)
40861+ if (!local_read(&tty->open_count))
40862 return -EINVAL;
40863
40864 return get_control_lines(tty);
40865@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
40866 if (!tty)
40867 return -ENODEV;
40868
40869- if (!tty->open_count)
40870+ if (!local_read(&tty->open_count))
40871 return -EINVAL;
40872
40873 return set_control_lines(tty, set, clear);
40874@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
40875 if (!tty)
40876 return -ENODEV;
40877
40878- if (!tty->open_count)
40879+ if (!local_read(&tty->open_count))
40880 return -EINVAL;
40881
40882 /* FIXME: Exactly how is the tty object locked here .. */
40883@@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty
40884 against a parallel ioctl etc */
40885 mutex_lock(&ttyj->ipw_tty_mutex);
40886 }
40887- while (ttyj->open_count)
40888+ while (local_read(&ttyj->open_count))
40889 do_ipw_close(ttyj);
40890 ipwireless_disassociate_network_ttys(network,
40891 ttyj->channel_idx);
40892diff -urNp linux-2.6.39.1/drivers/tty/mxser.c linux-2.6.39.1/drivers/tty/mxser.c
40893--- linux-2.6.39.1/drivers/tty/mxser.c 2011-05-19 00:06:34.000000000 -0400
40894+++ linux-2.6.39.1/drivers/tty/mxser.c 2011-05-22 19:36:32.000000000 -0400
40895@@ -2340,7 +2340,7 @@ static const struct tty_operations mxser
40896 .get_icount = mxser_get_icount,
40897 };
40898
40899-struct tty_port_operations mxser_port_ops = {
40900+const struct tty_port_operations mxser_port_ops = {
40901 .carrier_raised = mxser_carrier_raised,
40902 .dtr_rts = mxser_dtr_rts,
40903 .activate = mxser_activate,
40904diff -urNp linux-2.6.39.1/drivers/tty/n_gsm.c linux-2.6.39.1/drivers/tty/n_gsm.c
40905--- linux-2.6.39.1/drivers/tty/n_gsm.c 2011-05-19 00:06:34.000000000 -0400
40906+++ linux-2.6.39.1/drivers/tty/n_gsm.c 2011-05-22 19:36:32.000000000 -0400
40907@@ -1588,7 +1588,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
40908 return NULL;
40909 spin_lock_init(&dlci->lock);
40910 dlci->fifo = &dlci->_fifo;
40911- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40912+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40913 kfree(dlci);
40914 return NULL;
40915 }
40916diff -urNp linux-2.6.39.1/drivers/tty/n_tty.c linux-2.6.39.1/drivers/tty/n_tty.c
40917--- linux-2.6.39.1/drivers/tty/n_tty.c 2011-05-19 00:06:34.000000000 -0400
40918+++ linux-2.6.39.1/drivers/tty/n_tty.c 2011-05-22 19:36:32.000000000 -0400
40919@@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
40920 {
40921 *ops = tty_ldisc_N_TTY;
40922 ops->owner = NULL;
40923- ops->refcount = ops->flags = 0;
40924+ atomic_set(&ops->refcount, 0);
40925+ ops->flags = 0;
40926 }
40927 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40928diff -urNp linux-2.6.39.1/drivers/tty/pty.c linux-2.6.39.1/drivers/tty/pty.c
40929--- linux-2.6.39.1/drivers/tty/pty.c 2011-05-19 00:06:34.000000000 -0400
40930+++ linux-2.6.39.1/drivers/tty/pty.c 2011-05-22 19:36:32.000000000 -0400
40931@@ -699,7 +699,18 @@ out:
40932 return retval;
40933 }
40934
40935-static struct file_operations ptmx_fops;
40936+static const struct file_operations ptmx_fops = {
40937+ .llseek = no_llseek,
40938+ .read = tty_read,
40939+ .write = tty_write,
40940+ .poll = tty_poll,
40941+ .unlocked_ioctl = tty_ioctl,
40942+ .compat_ioctl = tty_compat_ioctl,
40943+ .open = ptmx_open,
40944+ .release = tty_release,
40945+ .fasync = tty_fasync,
40946+};
40947+
40948
40949 static void __init unix98_pty_init(void)
40950 {
40951@@ -752,10 +763,6 @@ static void __init unix98_pty_init(void)
40952
40953 register_sysctl_table(pty_root_table);
40954
40955- /* Now create the /dev/ptmx special device */
40956- tty_default_fops(&ptmx_fops);
40957- ptmx_fops.open = ptmx_open;
40958-
40959 cdev_init(&ptmx_cdev, &ptmx_fops);
40960 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40961 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
40962diff -urNp linux-2.6.39.1/drivers/tty/rocket.c linux-2.6.39.1/drivers/tty/rocket.c
40963--- linux-2.6.39.1/drivers/tty/rocket.c 2011-05-19 00:06:34.000000000 -0400
40964+++ linux-2.6.39.1/drivers/tty/rocket.c 2011-05-22 19:36:32.000000000 -0400
40965@@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info
40966 struct rocket_ports tmp;
40967 int board;
40968
40969+ pax_track_stack();
40970+
40971 if (!retports)
40972 return -EFAULT;
40973 memset(&tmp, 0, sizeof (tmp));
40974diff -urNp linux-2.6.39.1/drivers/tty/serial/21285.c linux-2.6.39.1/drivers/tty/serial/21285.c
40975--- linux-2.6.39.1/drivers/tty/serial/21285.c 2011-05-19 00:06:34.000000000 -0400
40976+++ linux-2.6.39.1/drivers/tty/serial/21285.c 2011-05-22 19:36:32.000000000 -0400
40977@@ -340,7 +340,7 @@ static int serial21285_verify_port(struc
40978 return ret;
40979 }
40980
40981-static struct uart_ops serial21285_ops = {
40982+static const struct uart_ops serial21285_ops = {
40983 .tx_empty = serial21285_tx_empty,
40984 .get_mctrl = serial21285_get_mctrl,
40985 .set_mctrl = serial21285_set_mctrl,
40986diff -urNp linux-2.6.39.1/drivers/tty/serial/8250.c linux-2.6.39.1/drivers/tty/serial/8250.c
40987--- linux-2.6.39.1/drivers/tty/serial/8250.c 2011-05-19 00:06:34.000000000 -0400
40988+++ linux-2.6.39.1/drivers/tty/serial/8250.c 2011-05-22 19:36:32.000000000 -0400
40989@@ -2708,7 +2708,7 @@ serial8250_type(struct uart_port *port)
40990 return uart_config[type].name;
40991 }
40992
40993-static struct uart_ops serial8250_pops = {
40994+static const struct uart_ops serial8250_pops = {
40995 .tx_empty = serial8250_tx_empty,
40996 .set_mctrl = serial8250_set_mctrl,
40997 .get_mctrl = serial8250_get_mctrl,
40998diff -urNp linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c
40999--- linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c 2011-05-19 00:06:34.000000000 -0400
41000+++ linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c 2011-05-22 19:36:32.000000000 -0400
41001@@ -281,7 +281,7 @@ static int altera_jtaguart_verify_port(s
41002 /*
41003 * Define the basic serial functions we support.
41004 */
41005-static struct uart_ops altera_jtaguart_ops = {
41006+static const struct uart_ops altera_jtaguart_ops = {
41007 .tx_empty = altera_jtaguart_tx_empty,
41008 .get_mctrl = altera_jtaguart_get_mctrl,
41009 .set_mctrl = altera_jtaguart_set_mctrl,
41010diff -urNp linux-2.6.39.1/drivers/tty/serial/altera_uart.c linux-2.6.39.1/drivers/tty/serial/altera_uart.c
41011--- linux-2.6.39.1/drivers/tty/serial/altera_uart.c 2011-05-19 00:06:34.000000000 -0400
41012+++ linux-2.6.39.1/drivers/tty/serial/altera_uart.c 2011-05-22 19:36:32.000000000 -0400
41013@@ -380,7 +380,7 @@ static int altera_uart_verify_port(struc
41014 /*
41015 * Define the basic serial functions we support.
41016 */
41017-static struct uart_ops altera_uart_ops = {
41018+static const struct uart_ops altera_uart_ops = {
41019 .tx_empty = altera_uart_tx_empty,
41020 .get_mctrl = altera_uart_get_mctrl,
41021 .set_mctrl = altera_uart_set_mctrl,
41022diff -urNp linux-2.6.39.1/drivers/tty/serial/amba-pl010.c linux-2.6.39.1/drivers/tty/serial/amba-pl010.c
41023--- linux-2.6.39.1/drivers/tty/serial/amba-pl010.c 2011-05-19 00:06:34.000000000 -0400
41024+++ linux-2.6.39.1/drivers/tty/serial/amba-pl010.c 2011-05-22 19:36:32.000000000 -0400
41025@@ -529,7 +529,7 @@ static int pl010_verify_port(struct uart
41026 return ret;
41027 }
41028
41029-static struct uart_ops amba_pl010_pops = {
41030+static const struct uart_ops amba_pl010_pops = {
41031 .tx_empty = pl010_tx_empty,
41032 .set_mctrl = pl010_set_mctrl,
41033 .get_mctrl = pl010_get_mctrl,
41034diff -urNp linux-2.6.39.1/drivers/tty/serial/amba-pl011.c linux-2.6.39.1/drivers/tty/serial/amba-pl011.c
41035--- linux-2.6.39.1/drivers/tty/serial/amba-pl011.c 2011-05-19 00:06:34.000000000 -0400
41036+++ linux-2.6.39.1/drivers/tty/serial/amba-pl011.c 2011-05-22 19:36:32.000000000 -0400
41037@@ -1581,7 +1581,7 @@ static int pl010_verify_port(struct uart
41038 return ret;
41039 }
41040
41041-static struct uart_ops amba_pl011_pops = {
41042+static const struct uart_ops amba_pl011_pops = {
41043 .tx_empty = pl01x_tx_empty,
41044 .set_mctrl = pl011_set_mctrl,
41045 .get_mctrl = pl01x_get_mctrl,
41046diff -urNp linux-2.6.39.1/drivers/tty/serial/apbuart.c linux-2.6.39.1/drivers/tty/serial/apbuart.c
41047--- linux-2.6.39.1/drivers/tty/serial/apbuart.c 2011-05-19 00:06:34.000000000 -0400
41048+++ linux-2.6.39.1/drivers/tty/serial/apbuart.c 2011-05-22 19:36:32.000000000 -0400
41049@@ -328,7 +328,7 @@ static int apbuart_verify_port(struct ua
41050 return ret;
41051 }
41052
41053-static struct uart_ops grlib_apbuart_ops = {
41054+static const struct uart_ops grlib_apbuart_ops = {
41055 .tx_empty = apbuart_tx_empty,
41056 .set_mctrl = apbuart_set_mctrl,
41057 .get_mctrl = apbuart_get_mctrl,
41058diff -urNp linux-2.6.39.1/drivers/tty/serial/atmel_serial.c linux-2.6.39.1/drivers/tty/serial/atmel_serial.c
41059--- linux-2.6.39.1/drivers/tty/serial/atmel_serial.c 2011-05-19 00:06:34.000000000 -0400
41060+++ linux-2.6.39.1/drivers/tty/serial/atmel_serial.c 2011-05-22 19:36:32.000000000 -0400
41061@@ -1382,7 +1382,7 @@ atmel_ioctl(struct uart_port *port, unsi
41062
41063
41064
41065-static struct uart_ops atmel_pops = {
41066+static const struct uart_ops atmel_pops = {
41067 .tx_empty = atmel_tx_empty,
41068 .set_mctrl = atmel_set_mctrl,
41069 .get_mctrl = atmel_get_mctrl,
41070diff -urNp linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c
41071--- linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41072+++ linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41073@@ -636,7 +636,7 @@ static int bcm_uart_verify_port(struct u
41074 }
41075
41076 /* serial core callbacks */
41077-static struct uart_ops bcm_uart_ops = {
41078+static const struct uart_ops bcm_uart_ops = {
41079 .tx_empty = bcm_uart_tx_empty,
41080 .get_mctrl = bcm_uart_get_mctrl,
41081 .set_mctrl = bcm_uart_set_mctrl,
41082diff -urNp linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c
41083--- linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c 2011-05-19 00:06:34.000000000 -0400
41084+++ linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c 2011-05-22 19:36:32.000000000 -0400
41085@@ -1036,7 +1036,7 @@ static int bfin_kgdboc_port_startup(stru
41086 }
41087 #endif
41088
41089-static struct uart_ops bfin_serial_pops = {
41090+static const struct uart_ops bfin_serial_pops = {
41091 .tx_empty = bfin_serial_tx_empty,
41092 .set_mctrl = bfin_serial_set_mctrl,
41093 .get_mctrl = bfin_serial_get_mctrl,
41094diff -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
41095--- linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c 2011-05-19 00:06:34.000000000 -0400
41096+++ linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c 2011-05-22 19:36:32.000000000 -0400
41097@@ -571,7 +571,7 @@ static void sport_set_termios(struct uar
41098 spin_unlock_irqrestore(&up->port.lock, flags);
41099 }
41100
41101-struct uart_ops sport_uart_ops = {
41102+const struct uart_ops sport_uart_ops = {
41103 .tx_empty = sport_tx_empty,
41104 .set_mctrl = sport_set_mctrl,
41105 .get_mctrl = sport_get_mctrl,
41106diff -urNp linux-2.6.39.1/drivers/tty/serial/clps711x.c linux-2.6.39.1/drivers/tty/serial/clps711x.c
41107--- linux-2.6.39.1/drivers/tty/serial/clps711x.c 2011-05-19 00:06:34.000000000 -0400
41108+++ linux-2.6.39.1/drivers/tty/serial/clps711x.c 2011-05-22 19:36:32.000000000 -0400
41109@@ -380,7 +380,7 @@ static int clps711xuart_request_port(str
41110 return 0;
41111 }
41112
41113-static struct uart_ops clps711x_pops = {
41114+static const struct uart_ops clps711x_pops = {
41115 .tx_empty = clps711xuart_tx_empty,
41116 .set_mctrl = clps711xuart_set_mctrl_null,
41117 .get_mctrl = clps711xuart_get_mctrl,
41118diff -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
41119--- linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-19 00:06:34.000000000 -0400
41120+++ linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-22 19:36:32.000000000 -0400
41121@@ -1099,7 +1099,7 @@ static void cpm_put_poll_char(struct uar
41122 }
41123 #endif /* CONFIG_CONSOLE_POLL */
41124
41125-static struct uart_ops cpm_uart_pops = {
41126+static const struct uart_ops cpm_uart_pops = {
41127 .tx_empty = cpm_uart_tx_empty,
41128 .set_mctrl = cpm_uart_set_mctrl,
41129 .get_mctrl = cpm_uart_get_mctrl,
41130diff -urNp linux-2.6.39.1/drivers/tty/serial/dz.c linux-2.6.39.1/drivers/tty/serial/dz.c
41131--- linux-2.6.39.1/drivers/tty/serial/dz.c 2011-05-19 00:06:34.000000000 -0400
41132+++ linux-2.6.39.1/drivers/tty/serial/dz.c 2011-05-22 19:36:32.000000000 -0400
41133@@ -746,7 +746,7 @@ static int dz_verify_port(struct uart_po
41134 return ret;
41135 }
41136
41137-static struct uart_ops dz_ops = {
41138+static const struct uart_ops dz_ops = {
41139 .tx_empty = dz_tx_empty,
41140 .get_mctrl = dz_get_mctrl,
41141 .set_mctrl = dz_set_mctrl,
41142diff -urNp linux-2.6.39.1/drivers/tty/serial/imx.c linux-2.6.39.1/drivers/tty/serial/imx.c
41143--- linux-2.6.39.1/drivers/tty/serial/imx.c 2011-05-19 00:06:34.000000000 -0400
41144+++ linux-2.6.39.1/drivers/tty/serial/imx.c 2011-05-22 19:36:32.000000000 -0400
41145@@ -1018,7 +1018,7 @@ imx_verify_port(struct uart_port *port,
41146 return ret;
41147 }
41148
41149-static struct uart_ops imx_pops = {
41150+static const struct uart_ops imx_pops = {
41151 .tx_empty = imx_tx_empty,
41152 .set_mctrl = imx_set_mctrl,
41153 .get_mctrl = imx_get_mctrl,
41154diff -urNp linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c
41155--- linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c 2011-05-19 00:06:34.000000000 -0400
41156+++ linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c 2011-05-22 19:36:32.000000000 -0400
41157@@ -1874,7 +1874,7 @@ static int ic3_request_port(struct uart_
41158 }
41159
41160 /* Associate the uart functions above - given to serial core */
41161-static struct uart_ops ioc3_ops = {
41162+static const struct uart_ops ioc3_ops = {
41163 .tx_empty = ic3_tx_empty,
41164 .set_mctrl = ic3_set_mctrl,
41165 .get_mctrl = ic3_get_mctrl,
41166diff -urNp linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c
41167--- linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c 2011-05-19 00:06:34.000000000 -0400
41168+++ linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c 2011-05-22 19:36:32.000000000 -0400
41169@@ -2593,7 +2593,7 @@ static int ic4_request_port(struct uart_
41170
41171 /* Associate the uart functions above - given to serial core */
41172
41173-static struct uart_ops ioc4_ops = {
41174+static const struct uart_ops ioc4_ops = {
41175 .tx_empty = ic4_tx_empty,
41176 .set_mctrl = ic4_set_mctrl,
41177 .get_mctrl = ic4_get_mctrl,
41178diff -urNp linux-2.6.39.1/drivers/tty/serial/ip22zilog.c linux-2.6.39.1/drivers/tty/serial/ip22zilog.c
41179--- linux-2.6.39.1/drivers/tty/serial/ip22zilog.c 2011-05-19 00:06:34.000000000 -0400
41180+++ linux-2.6.39.1/drivers/tty/serial/ip22zilog.c 2011-05-22 19:36:32.000000000 -0400
41181@@ -928,7 +928,7 @@ static int ip22zilog_verify_port(struct
41182 return -EINVAL;
41183 }
41184
41185-static struct uart_ops ip22zilog_pops = {
41186+static const struct uart_ops ip22zilog_pops = {
41187 .tx_empty = ip22zilog_tx_empty,
41188 .set_mctrl = ip22zilog_set_mctrl,
41189 .get_mctrl = ip22zilog_get_mctrl,
41190diff -urNp linux-2.6.39.1/drivers/tty/serial/kgdboc.c linux-2.6.39.1/drivers/tty/serial/kgdboc.c
41191--- linux-2.6.39.1/drivers/tty/serial/kgdboc.c 2011-05-19 00:06:34.000000000 -0400
41192+++ linux-2.6.39.1/drivers/tty/serial/kgdboc.c 2011-05-22 19:36:32.000000000 -0400
41193@@ -22,7 +22,7 @@
41194
41195 #define MAX_CONFIG_LEN 40
41196
41197-static struct kgdb_io kgdboc_io_ops;
41198+static struct kgdb_io kgdboc_io_ops; /* cannot be const, see configure_kgdboc() */
41199
41200 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41201 static int configured = -1;
41202@@ -293,7 +293,7 @@ static void kgdboc_post_exp_handler(void
41203 kgdboc_restore_input();
41204 }
41205
41206-static struct kgdb_io kgdboc_io_ops = {
41207+static struct kgdb_io kgdboc_io_ops = { /* cannot be const, see configure_kgdboc() */
41208 .name = "kgdboc",
41209 .read_char = kgdboc_get_char,
41210 .write_char = kgdboc_put_char,
41211diff -urNp linux-2.6.39.1/drivers/tty/serial/m32r_sio.c linux-2.6.39.1/drivers/tty/serial/m32r_sio.c
41212--- linux-2.6.39.1/drivers/tty/serial/m32r_sio.c 2011-05-19 00:06:34.000000000 -0400
41213+++ linux-2.6.39.1/drivers/tty/serial/m32r_sio.c 2011-05-22 19:36:32.000000000 -0400
41214@@ -939,7 +939,7 @@ m32r_sio_type(struct uart_port *port)
41215 return uart_config[type].name;
41216 }
41217
41218-static struct uart_ops m32r_sio_pops = {
41219+static const struct uart_ops m32r_sio_pops = {
41220 .tx_empty = m32r_sio_tx_empty,
41221 .set_mctrl = m32r_sio_set_mctrl,
41222 .get_mctrl = m32r_sio_get_mctrl,
41223diff -urNp linux-2.6.39.1/drivers/tty/serial/max3100.c linux-2.6.39.1/drivers/tty/serial/max3100.c
41224--- linux-2.6.39.1/drivers/tty/serial/max3100.c 2011-05-19 00:06:34.000000000 -0400
41225+++ linux-2.6.39.1/drivers/tty/serial/max3100.c 2011-05-22 19:36:32.000000000 -0400
41226@@ -710,7 +710,7 @@ static void max3100_break_ctl(struct uar
41227 dev_dbg(&s->spi->dev, "%s\n", __func__);
41228 }
41229
41230-static struct uart_ops max3100_ops = {
41231+static const struct uart_ops max3100_ops = {
41232 .tx_empty = max3100_tx_empty,
41233 .set_mctrl = max3100_set_mctrl,
41234 .get_mctrl = max3100_get_mctrl,
41235diff -urNp linux-2.6.39.1/drivers/tty/serial/max3107.c linux-2.6.39.1/drivers/tty/serial/max3107.c
41236--- linux-2.6.39.1/drivers/tty/serial/max3107.c 2011-05-19 00:06:34.000000000 -0400
41237+++ linux-2.6.39.1/drivers/tty/serial/max3107.c 2011-05-22 19:36:32.000000000 -0400
41238@@ -910,7 +910,7 @@ static void max3107_break_ctl(struct uar
41239
41240
41241 /* Port functions */
41242-static struct uart_ops max3107_ops = {
41243+static const struct uart_ops max3107_ops = {
41244 .tx_empty = max3107_tx_empty,
41245 .set_mctrl = max3107_set_mctrl,
41246 .get_mctrl = max3107_get_mctrl,
41247diff -urNp linux-2.6.39.1/drivers/tty/serial/mfd.c linux-2.6.39.1/drivers/tty/serial/mfd.c
41248--- linux-2.6.39.1/drivers/tty/serial/mfd.c 2011-05-19 00:06:34.000000000 -0400
41249+++ linux-2.6.39.1/drivers/tty/serial/mfd.c 2011-05-22 19:36:32.000000000 -0400
41250@@ -1178,7 +1178,7 @@ static struct console serial_hsu_console
41251 };
41252 #endif
41253
41254-struct uart_ops serial_hsu_pops = {
41255+const struct uart_ops serial_hsu_pops = {
41256 .tx_empty = serial_hsu_tx_empty,
41257 .set_mctrl = serial_hsu_set_mctrl,
41258 .get_mctrl = serial_hsu_get_mctrl,
41259diff -urNp linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c
41260--- linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41261+++ linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41262@@ -283,7 +283,7 @@ static irqreturn_t mpc52xx_psc_handle_ir
41263 return mpc5xxx_uart_process_int(port);
41264 }
41265
41266-static struct psc_ops mpc52xx_psc_ops = {
41267+static const struct psc_ops mpc52xx_psc_ops = {
41268 .fifo_init = mpc52xx_psc_fifo_init,
41269 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41270 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41271@@ -304,7 +304,7 @@ static struct psc_ops mpc52xx_psc_ops =
41272 .handle_irq = mpc52xx_psc_handle_irq,
41273 };
41274
41275-static struct psc_ops mpc5200b_psc_ops = {
41276+static const struct psc_ops mpc5200b_psc_ops = {
41277 .fifo_init = mpc52xx_psc_fifo_init,
41278 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41279 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41280@@ -571,7 +571,7 @@ static void mpc512x_psc_get_irq(struct u
41281 port->irq = psc_fifoc_irq;
41282 }
41283
41284-static struct psc_ops mpc512x_psc_ops = {
41285+static const struct psc_ops mpc512x_psc_ops = {
41286 .fifo_init = mpc512x_psc_fifo_init,
41287 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
41288 .raw_tx_rdy = mpc512x_psc_raw_tx_rdy,
41289@@ -596,7 +596,7 @@ static struct psc_ops mpc512x_psc_ops =
41290 };
41291 #endif
41292
41293-static struct psc_ops *psc_ops;
41294+static const struct psc_ops *psc_ops;
41295
41296 /* ======================================================================== */
41297 /* UART operations */
41298@@ -905,7 +905,7 @@ mpc52xx_uart_verify_port(struct uart_por
41299 }
41300
41301
41302-static struct uart_ops mpc52xx_uart_ops = {
41303+static const struct uart_ops mpc52xx_uart_ops = {
41304 .tx_empty = mpc52xx_uart_tx_empty,
41305 .set_mctrl = mpc52xx_uart_set_mctrl,
41306 .get_mctrl = mpc52xx_uart_get_mctrl,
41307diff -urNp linux-2.6.39.1/drivers/tty/serial/mpsc.c linux-2.6.39.1/drivers/tty/serial/mpsc.c
41308--- linux-2.6.39.1/drivers/tty/serial/mpsc.c 2011-05-19 00:06:34.000000000 -0400
41309+++ linux-2.6.39.1/drivers/tty/serial/mpsc.c 2011-05-22 19:36:32.000000000 -0400
41310@@ -1663,7 +1663,7 @@ static void mpsc_put_poll_char(struct ua
41311 }
41312 #endif
41313
41314-static struct uart_ops mpsc_pops = {
41315+static const struct uart_ops mpsc_pops = {
41316 .tx_empty = mpsc_tx_empty,
41317 .set_mctrl = mpsc_set_mctrl,
41318 .get_mctrl = mpsc_get_mctrl,
41319diff -urNp linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c
41320--- linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c 2011-05-19 00:06:34.000000000 -0400
41321+++ linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c 2011-05-22 19:36:32.000000000 -0400
41322@@ -393,6 +393,8 @@ static void max3110_con_receive(struct u
41323 int loop = 1, num, total = 0;
41324 u8 recv_buf[512], *pbuf;
41325
41326+ pax_track_stack();
41327+
41328 pbuf = recv_buf;
41329 do {
41330 num = max3110_read_multi(max, pbuf);
41331@@ -726,7 +728,7 @@ static void serial_m3110_enable_ms(struc
41332 {
41333 }
41334
41335-struct uart_ops serial_m3110_ops = {
41336+const struct uart_ops serial_m3110_ops = {
41337 .tx_empty = serial_m3110_tx_empty,
41338 .set_mctrl = serial_m3110_set_mctrl,
41339 .get_mctrl = serial_m3110_get_mctrl,
41340diff -urNp linux-2.6.39.1/drivers/tty/serial/msm_serial.c linux-2.6.39.1/drivers/tty/serial/msm_serial.c
41341--- linux-2.6.39.1/drivers/tty/serial/msm_serial.c 2011-05-19 00:06:34.000000000 -0400
41342+++ linux-2.6.39.1/drivers/tty/serial/msm_serial.c 2011-05-22 19:36:32.000000000 -0400
41343@@ -702,7 +702,7 @@ static void msm_power(struct uart_port *
41344 }
41345 }
41346
41347-static struct uart_ops msm_uart_pops = {
41348+static const struct uart_ops msm_uart_pops = {
41349 .tx_empty = msm_tx_empty,
41350 .set_mctrl = msm_set_mctrl,
41351 .get_mctrl = msm_get_mctrl,
41352diff -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
41353--- linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c 2011-05-19 00:06:34.000000000 -0400
41354+++ linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c 2011-05-22 19:36:32.000000000 -0400
41355@@ -360,7 +360,7 @@ struct msm_hs_port {
41356 static struct msm_hs_port q_uart_port[UARTDM_NR];
41357 static struct platform_driver msm_serial_hs_platform_driver;
41358 static struct uart_driver msm_hs_driver;
41359-static struct uart_ops msm_hs_ops;
41360+static const struct uart_ops msm_hs_ops;
41361 static struct workqueue_struct *msm_hs_workqueue;
41362
41363 #define UARTDM_TO_MSM(uart_port) \
41364@@ -1856,7 +1856,7 @@ static struct uart_driver msm_hs_driver
41365 .cons = 0,
41366 };
41367
41368-static struct uart_ops msm_hs_ops = {
41369+static const struct uart_ops msm_hs_ops = {
41370 .tx_empty = msm_hs_tx_empty,
41371 .set_mctrl = msm_hs_set_mctrl_locked,
41372 .get_mctrl = msm_hs_get_mctrl_locked,
41373diff -urNp linux-2.6.39.1/drivers/tty/serial/mux.c linux-2.6.39.1/drivers/tty/serial/mux.c
41374--- linux-2.6.39.1/drivers/tty/serial/mux.c 2011-05-19 00:06:34.000000000 -0400
41375+++ linux-2.6.39.1/drivers/tty/serial/mux.c 2011-05-22 19:36:32.000000000 -0400
41376@@ -442,7 +442,7 @@ static struct console mux_console = {
41377 #define MUX_CONSOLE NULL
41378 #endif
41379
41380-static struct uart_ops mux_pops = {
41381+static const struct uart_ops mux_pops = {
41382 .tx_empty = mux_tx_empty,
41383 .set_mctrl = mux_set_mctrl,
41384 .get_mctrl = mux_get_mctrl,
41385diff -urNp linux-2.6.39.1/drivers/tty/serial/mxs-auart.c linux-2.6.39.1/drivers/tty/serial/mxs-auart.c
41386--- linux-2.6.39.1/drivers/tty/serial/mxs-auart.c 2011-05-19 00:06:34.000000000 -0400
41387+++ linux-2.6.39.1/drivers/tty/serial/mxs-auart.c 2011-05-22 19:36:32.000000000 -0400
41388@@ -499,7 +499,7 @@ static void mxs_auart_enable_ms(struct u
41389 /* just empty */
41390 }
41391
41392-static struct uart_ops mxs_auart_ops = {
41393+static const struct uart_ops mxs_auart_ops = {
41394 .tx_empty = mxs_auart_tx_empty,
41395 .start_tx = mxs_auart_start_tx,
41396 .stop_tx = mxs_auart_stop_tx,
41397diff -urNp linux-2.6.39.1/drivers/tty/serial/netx-serial.c linux-2.6.39.1/drivers/tty/serial/netx-serial.c
41398--- linux-2.6.39.1/drivers/tty/serial/netx-serial.c 2011-05-19 00:06:34.000000000 -0400
41399+++ linux-2.6.39.1/drivers/tty/serial/netx-serial.c 2011-05-22 19:36:32.000000000 -0400
41400@@ -464,7 +464,7 @@ netx_verify_port(struct uart_port *port,
41401 return ret;
41402 }
41403
41404-static struct uart_ops netx_pops = {
41405+static const struct uart_ops netx_pops = {
41406 .tx_empty = netx_tx_empty,
41407 .set_mctrl = netx_set_mctrl,
41408 .get_mctrl = netx_get_mctrl,
41409diff -urNp linux-2.6.39.1/drivers/tty/serial/nwpserial.c linux-2.6.39.1/drivers/tty/serial/nwpserial.c
41410--- linux-2.6.39.1/drivers/tty/serial/nwpserial.c 2011-05-19 00:06:34.000000000 -0400
41411+++ linux-2.6.39.1/drivers/tty/serial/nwpserial.c 2011-05-22 19:36:32.000000000 -0400
41412@@ -303,7 +303,7 @@ static unsigned int nwpserial_tx_empty(s
41413 return ret & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
41414 }
41415
41416-static struct uart_ops nwpserial_pops = {
41417+static const struct uart_ops nwpserial_pops = {
41418 .tx_empty = nwpserial_tx_empty,
41419 .set_mctrl = nwpserial_set_mctrl,
41420 .get_mctrl = nwpserial_get_mctrl,
41421diff -urNp linux-2.6.39.1/drivers/tty/serial/omap-serial.c linux-2.6.39.1/drivers/tty/serial/omap-serial.c
41422--- linux-2.6.39.1/drivers/tty/serial/omap-serial.c 2011-05-19 00:06:34.000000000 -0400
41423+++ linux-2.6.39.1/drivers/tty/serial/omap-serial.c 2011-05-22 19:36:32.000000000 -0400
41424@@ -1029,7 +1029,7 @@ static inline void serial_omap_add_conso
41425
41426 #endif
41427
41428-static struct uart_ops serial_omap_pops = {
41429+static const struct uart_ops serial_omap_pops = {
41430 .tx_empty = serial_omap_tx_empty,
41431 .set_mctrl = serial_omap_set_mctrl,
41432 .get_mctrl = serial_omap_get_mctrl,
41433diff -urNp linux-2.6.39.1/drivers/tty/serial/pch_uart.c linux-2.6.39.1/drivers/tty/serial/pch_uart.c
41434--- linux-2.6.39.1/drivers/tty/serial/pch_uart.c 2011-05-19 00:06:34.000000000 -0400
41435+++ linux-2.6.39.1/drivers/tty/serial/pch_uart.c 2011-05-22 19:36:32.000000000 -0400
41436@@ -1351,7 +1351,7 @@ static int pch_uart_verify_port(struct u
41437 return 0;
41438 }
41439
41440-static struct uart_ops pch_uart_ops = {
41441+static const struct uart_ops pch_uart_ops = {
41442 .tx_empty = pch_uart_tx_empty,
41443 .set_mctrl = pch_uart_set_mctrl,
41444 .get_mctrl = pch_uart_get_mctrl,
41445diff -urNp linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c
41446--- linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c 2011-05-19 00:06:34.000000000 -0400
41447+++ linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c 2011-05-22 19:36:32.000000000 -0400
41448@@ -1427,7 +1427,7 @@ static void pmz_poll_put_char(struct uar
41449
41450 #endif /* CONFIG_CONSOLE_POLL */
41451
41452-static struct uart_ops pmz_pops = {
41453+static const struct uart_ops pmz_pops = {
41454 .tx_empty = pmz_tx_empty,
41455 .set_mctrl = pmz_set_mctrl,
41456 .get_mctrl = pmz_get_mctrl,
41457diff -urNp linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c
41458--- linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c 2011-05-19 00:06:34.000000000 -0400
41459+++ linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c 2011-05-22 19:36:32.000000000 -0400
41460@@ -614,7 +614,7 @@ pnx8xxx_verify_port(struct uart_port *po
41461 return ret;
41462 }
41463
41464-static struct uart_ops pnx8xxx_pops = {
41465+static const struct uart_ops pnx8xxx_pops = {
41466 .tx_empty = pnx8xxx_tx_empty,
41467 .set_mctrl = pnx8xxx_set_mctrl,
41468 .get_mctrl = pnx8xxx_get_mctrl,
41469diff -urNp linux-2.6.39.1/drivers/tty/serial/pxa.c linux-2.6.39.1/drivers/tty/serial/pxa.c
41470--- linux-2.6.39.1/drivers/tty/serial/pxa.c 2011-05-19 00:06:34.000000000 -0400
41471+++ linux-2.6.39.1/drivers/tty/serial/pxa.c 2011-05-22 19:36:32.000000000 -0400
41472@@ -706,7 +706,7 @@ static struct console serial_pxa_console
41473 #define PXA_CONSOLE NULL
41474 #endif
41475
41476-struct uart_ops serial_pxa_pops = {
41477+const struct uart_ops serial_pxa_pops = {
41478 .tx_empty = serial_pxa_tx_empty,
41479 .set_mctrl = serial_pxa_set_mctrl,
41480 .get_mctrl = serial_pxa_get_mctrl,
41481diff -urNp linux-2.6.39.1/drivers/tty/serial/sa1100.c linux-2.6.39.1/drivers/tty/serial/sa1100.c
41482--- linux-2.6.39.1/drivers/tty/serial/sa1100.c 2011-05-19 00:06:34.000000000 -0400
41483+++ linux-2.6.39.1/drivers/tty/serial/sa1100.c 2011-05-22 19:36:32.000000000 -0400
41484@@ -577,7 +577,7 @@ sa1100_verify_port(struct uart_port *por
41485 return ret;
41486 }
41487
41488-static struct uart_ops sa1100_pops = {
41489+static const struct uart_ops sa1100_pops = {
41490 .tx_empty = sa1100_tx_empty,
41491 .set_mctrl = sa1100_set_mctrl,
41492 .get_mctrl = sa1100_get_mctrl,
41493diff -urNp linux-2.6.39.1/drivers/tty/serial/samsung.c linux-2.6.39.1/drivers/tty/serial/samsung.c
41494--- linux-2.6.39.1/drivers/tty/serial/samsung.c 2011-05-19 00:06:34.000000000 -0400
41495+++ linux-2.6.39.1/drivers/tty/serial/samsung.c 2011-05-22 19:36:32.000000000 -0400
41496@@ -860,7 +860,7 @@ static struct console s3c24xx_serial_con
41497 #define S3C24XX_SERIAL_CONSOLE NULL
41498 #endif
41499
41500-static struct uart_ops s3c24xx_serial_ops = {
41501+static const struct uart_ops s3c24xx_serial_ops = {
41502 .pm = s3c24xx_serial_pm,
41503 .tx_empty = s3c24xx_serial_tx_empty,
41504 .get_mctrl = s3c24xx_serial_get_mctrl,
41505diff -urNp linux-2.6.39.1/drivers/tty/serial/sc26xx.c linux-2.6.39.1/drivers/tty/serial/sc26xx.c
41506--- linux-2.6.39.1/drivers/tty/serial/sc26xx.c 2011-05-19 00:06:34.000000000 -0400
41507+++ linux-2.6.39.1/drivers/tty/serial/sc26xx.c 2011-05-22 19:36:32.000000000 -0400
41508@@ -515,7 +515,7 @@ static int sc26xx_verify_port(struct uar
41509 return -EINVAL;
41510 }
41511
41512-static struct uart_ops sc26xx_ops = {
41513+static const struct uart_ops sc26xx_ops = {
41514 .tx_empty = sc26xx_tx_empty,
41515 .set_mctrl = sc26xx_set_mctrl,
41516 .get_mctrl = sc26xx_get_mctrl,
41517diff -urNp linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c
41518--- linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c 2011-05-19 00:06:34.000000000 -0400
41519+++ linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c 2011-05-22 19:36:32.000000000 -0400
41520@@ -528,7 +528,7 @@ static int ks8695uart_verify_port(struct
41521 return ret;
41522 }
41523
41524-static struct uart_ops ks8695uart_pops = {
41525+static const struct uart_ops ks8695uart_pops = {
41526 .tx_empty = ks8695uart_tx_empty,
41527 .set_mctrl = ks8695uart_set_mctrl,
41528 .get_mctrl = ks8695uart_get_mctrl,
41529diff -urNp linux-2.6.39.1/drivers/tty/serial/serial_txx9.c linux-2.6.39.1/drivers/tty/serial/serial_txx9.c
41530--- linux-2.6.39.1/drivers/tty/serial/serial_txx9.c 2011-05-19 00:06:34.000000000 -0400
41531+++ linux-2.6.39.1/drivers/tty/serial/serial_txx9.c 2011-05-22 19:36:32.000000000 -0400
41532@@ -857,7 +857,7 @@ serial_txx9_type(struct uart_port *port)
41533 return "txx9";
41534 }
41535
41536-static struct uart_ops serial_txx9_pops = {
41537+static const struct uart_ops serial_txx9_pops = {
41538 .tx_empty = serial_txx9_tx_empty,
41539 .set_mctrl = serial_txx9_set_mctrl,
41540 .get_mctrl = serial_txx9_get_mctrl,
41541diff -urNp linux-2.6.39.1/drivers/tty/serial/sn_console.c linux-2.6.39.1/drivers/tty/serial/sn_console.c
41542--- linux-2.6.39.1/drivers/tty/serial/sn_console.c 2011-05-19 00:06:34.000000000 -0400
41543+++ linux-2.6.39.1/drivers/tty/serial/sn_console.c 2011-05-22 19:36:32.000000000 -0400
41544@@ -388,7 +388,7 @@ static void snp_config_port(struct uart_
41545
41546 /* Associate the uart functions above - given to serial core */
41547
41548-static struct uart_ops sn_console_ops = {
41549+static const struct uart_ops sn_console_ops = {
41550 .tx_empty = snp_tx_empty,
41551 .set_mctrl = snp_set_mctrl,
41552 .get_mctrl = snp_get_mctrl,
41553diff -urNp linux-2.6.39.1/drivers/tty/serial/sunhv.c linux-2.6.39.1/drivers/tty/serial/sunhv.c
41554--- linux-2.6.39.1/drivers/tty/serial/sunhv.c 2011-05-19 00:06:34.000000000 -0400
41555+++ linux-2.6.39.1/drivers/tty/serial/sunhv.c 2011-05-22 19:36:32.000000000 -0400
41556@@ -168,12 +168,12 @@ struct sunhv_ops {
41557 int (*receive_chars)(struct uart_port *port, struct tty_struct *tty);
41558 };
41559
41560-static struct sunhv_ops bychar_ops = {
41561+static const struct sunhv_ops bychar_ops = {
41562 .transmit_chars = transmit_chars_putchar,
41563 .receive_chars = receive_chars_getchar,
41564 };
41565
41566-static struct sunhv_ops bywrite_ops = {
41567+static const struct sunhv_ops bywrite_ops = {
41568 .transmit_chars = transmit_chars_write,
41569 .receive_chars = receive_chars_read,
41570 };
41571@@ -370,7 +370,7 @@ static int sunhv_verify_port(struct uart
41572 return -EINVAL;
41573 }
41574
41575-static struct uart_ops sunhv_pops = {
41576+static const struct uart_ops sunhv_pops = {
41577 .tx_empty = sunhv_tx_empty,
41578 .set_mctrl = sunhv_set_mctrl,
41579 .get_mctrl = sunhv_get_mctrl,
41580diff -urNp linux-2.6.39.1/drivers/tty/serial/sunsab.c linux-2.6.39.1/drivers/tty/serial/sunsab.c
41581--- linux-2.6.39.1/drivers/tty/serial/sunsab.c 2011-05-19 00:06:34.000000000 -0400
41582+++ linux-2.6.39.1/drivers/tty/serial/sunsab.c 2011-05-22 19:36:32.000000000 -0400
41583@@ -804,7 +804,7 @@ static int sunsab_verify_port(struct uar
41584 return -EINVAL;
41585 }
41586
41587-static struct uart_ops sunsab_pops = {
41588+static const struct uart_ops sunsab_pops = {
41589 .tx_empty = sunsab_tx_empty,
41590 .set_mctrl = sunsab_set_mctrl,
41591 .get_mctrl = sunsab_get_mctrl,
41592diff -urNp linux-2.6.39.1/drivers/tty/serial/sunsu.c linux-2.6.39.1/drivers/tty/serial/sunsu.c
41593--- linux-2.6.39.1/drivers/tty/serial/sunsu.c 2011-05-19 00:06:34.000000000 -0400
41594+++ linux-2.6.39.1/drivers/tty/serial/sunsu.c 2011-05-22 19:36:32.000000000 -0400
41595@@ -946,7 +946,7 @@ sunsu_type(struct uart_port *port)
41596 return uart_config[type].name;
41597 }
41598
41599-static struct uart_ops sunsu_pops = {
41600+static const struct uart_ops sunsu_pops = {
41601 .tx_empty = sunsu_tx_empty,
41602 .set_mctrl = sunsu_set_mctrl,
41603 .get_mctrl = sunsu_get_mctrl,
41604diff -urNp linux-2.6.39.1/drivers/tty/serial/sunzilog.c linux-2.6.39.1/drivers/tty/serial/sunzilog.c
41605--- linux-2.6.39.1/drivers/tty/serial/sunzilog.c 2011-05-19 00:06:34.000000000 -0400
41606+++ linux-2.6.39.1/drivers/tty/serial/sunzilog.c 2011-05-22 19:36:32.000000000 -0400
41607@@ -1042,7 +1042,7 @@ static void sunzilog_put_poll_char(struc
41608 }
41609 #endif /* CONFIG_CONSOLE_POLL */
41610
41611-static struct uart_ops sunzilog_pops = {
41612+static const struct uart_ops sunzilog_pops = {
41613 .tx_empty = sunzilog_tx_empty,
41614 .set_mctrl = sunzilog_set_mctrl,
41615 .get_mctrl = sunzilog_get_mctrl,
41616diff -urNp linux-2.6.39.1/drivers/tty/serial/timbuart.c linux-2.6.39.1/drivers/tty/serial/timbuart.c
41617--- linux-2.6.39.1/drivers/tty/serial/timbuart.c 2011-05-19 00:06:34.000000000 -0400
41618+++ linux-2.6.39.1/drivers/tty/serial/timbuart.c 2011-05-22 19:36:32.000000000 -0400
41619@@ -394,7 +394,7 @@ static int timbuart_verify_port(struct u
41620 return -EINVAL;
41621 }
41622
41623-static struct uart_ops timbuart_ops = {
41624+static const struct uart_ops timbuart_ops = {
41625 .tx_empty = timbuart_tx_empty,
41626 .set_mctrl = timbuart_set_mctrl,
41627 .get_mctrl = timbuart_get_mctrl,
41628diff -urNp linux-2.6.39.1/drivers/tty/serial/uartlite.c linux-2.6.39.1/drivers/tty/serial/uartlite.c
41629--- linux-2.6.39.1/drivers/tty/serial/uartlite.c 2011-05-19 00:06:34.000000000 -0400
41630+++ linux-2.6.39.1/drivers/tty/serial/uartlite.c 2011-05-22 19:36:32.000000000 -0400
41631@@ -331,7 +331,7 @@ static void ulite_put_poll_char(struct u
41632 }
41633 #endif
41634
41635-static struct uart_ops ulite_ops = {
41636+static const struct uart_ops ulite_ops = {
41637 .tx_empty = ulite_tx_empty,
41638 .set_mctrl = ulite_set_mctrl,
41639 .get_mctrl = ulite_get_mctrl,
41640diff -urNp linux-2.6.39.1/drivers/tty/serial/ucc_uart.c linux-2.6.39.1/drivers/tty/serial/ucc_uart.c
41641--- linux-2.6.39.1/drivers/tty/serial/ucc_uart.c 2011-05-19 00:06:34.000000000 -0400
41642+++ linux-2.6.39.1/drivers/tty/serial/ucc_uart.c 2011-05-22 19:36:32.000000000 -0400
41643@@ -1088,7 +1088,7 @@ static int qe_uart_verify_port(struct ua
41644 *
41645 * Details on these functions can be found in Documentation/serial/driver
41646 */
41647-static struct uart_ops qe_uart_pops = {
41648+static const struct uart_ops qe_uart_pops = {
41649 .tx_empty = qe_uart_tx_empty,
41650 .set_mctrl = qe_uart_set_mctrl,
41651 .get_mctrl = qe_uart_get_mctrl,
41652diff -urNp linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c
41653--- linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c 2011-05-19 00:06:34.000000000 -0400
41654+++ linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c 2011-05-22 19:36:32.000000000 -0400
41655@@ -683,7 +683,7 @@ static int siu_verify_port(struct uart_p
41656 return 0;
41657 }
41658
41659-static struct uart_ops siu_uart_ops = {
41660+static const struct uart_ops siu_uart_ops = {
41661 .tx_empty = siu_tx_empty,
41662 .set_mctrl = siu_set_mctrl,
41663 .get_mctrl = siu_get_mctrl,
41664diff -urNp linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c
41665--- linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c 2011-05-19 00:06:34.000000000 -0400
41666+++ linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c 2011-05-22 19:36:32.000000000 -0400
41667@@ -519,7 +519,7 @@ static struct console vt8500_console = {
41668 #define VT8500_CONSOLE NULL
41669 #endif
41670
41671-static struct uart_ops vt8500_uart_pops = {
41672+static const struct uart_ops vt8500_uart_pops = {
41673 .tx_empty = vt8500_tx_empty,
41674 .set_mctrl = vt8500_set_mctrl,
41675 .get_mctrl = vt8500_get_mctrl,
41676diff -urNp linux-2.6.39.1/drivers/tty/serial/zs.c linux-2.6.39.1/drivers/tty/serial/zs.c
41677--- linux-2.6.39.1/drivers/tty/serial/zs.c 2011-05-19 00:06:34.000000000 -0400
41678+++ linux-2.6.39.1/drivers/tty/serial/zs.c 2011-05-22 19:36:32.000000000 -0400
41679@@ -1044,7 +1044,7 @@ static int zs_verify_port(struct uart_po
41680 }
41681
41682
41683-static struct uart_ops zs_ops = {
41684+static const struct uart_ops zs_ops = {
41685 .tx_empty = zs_tx_empty,
41686 .set_mctrl = zs_set_mctrl,
41687 .get_mctrl = zs_get_mctrl,
41688diff -urNp linux-2.6.39.1/drivers/tty/tty_io.c linux-2.6.39.1/drivers/tty/tty_io.c
41689--- linux-2.6.39.1/drivers/tty/tty_io.c 2011-05-19 00:06:34.000000000 -0400
41690+++ linux-2.6.39.1/drivers/tty/tty_io.c 2011-05-22 19:36:32.000000000 -0400
41691@@ -139,21 +139,11 @@ EXPORT_SYMBOL(tty_mutex);
41692 /* Spinlock to protect the tty->tty_files list */
41693 DEFINE_SPINLOCK(tty_files_lock);
41694
41695-static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
41696-static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
41697 ssize_t redirected_tty_write(struct file *, const char __user *,
41698 size_t, loff_t *);
41699-static unsigned int tty_poll(struct file *, poll_table *);
41700 static int tty_open(struct inode *, struct file *);
41701 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
41702-#ifdef CONFIG_COMPAT
41703-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41704- unsigned long arg);
41705-#else
41706-#define tty_compat_ioctl NULL
41707-#endif
41708 static int __tty_fasync(int fd, struct file *filp, int on);
41709-static int tty_fasync(int fd, struct file *filp, int on);
41710 static void release_tty(struct tty_struct *tty, int idx);
41711 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41712 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41713@@ -937,7 +927,7 @@ EXPORT_SYMBOL(start_tty);
41714 * read calls may be outstanding in parallel.
41715 */
41716
41717-static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41718+ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41719 loff_t *ppos)
41720 {
41721 int i;
41722@@ -963,6 +953,8 @@ static ssize_t tty_read(struct file *fil
41723 return i;
41724 }
41725
41726+EXPORT_SYMBOL(tty_read);
41727+
41728 void tty_write_unlock(struct tty_struct *tty)
41729 {
41730 mutex_unlock(&tty->atomic_write_lock);
41731@@ -1112,7 +1104,7 @@ void tty_write_message(struct tty_struct
41732 * write method will not be invoked in parallel for each device.
41733 */
41734
41735-static ssize_t tty_write(struct file *file, const char __user *buf,
41736+ssize_t tty_write(struct file *file, const char __user *buf,
41737 size_t count, loff_t *ppos)
41738 {
41739 struct inode *inode = file->f_path.dentry->d_inode;
41740@@ -1138,6 +1130,8 @@ static ssize_t tty_write(struct file *fi
41741 return ret;
41742 }
41743
41744+EXPORT_SYMBOL(tty_write);
41745+
41746 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
41747 size_t count, loff_t *ppos)
41748 {
41749@@ -1777,6 +1771,8 @@ int tty_release(struct inode *inode, str
41750 return 0;
41751 }
41752
41753+EXPORT_SYMBOL(tty_release);
41754+
41755 /**
41756 * tty_open - open a tty device
41757 * @inode: inode of device file
41758@@ -1968,7 +1964,7 @@ got_driver:
41759 * may be re-entered freely by other callers.
41760 */
41761
41762-static unsigned int tty_poll(struct file *filp, poll_table *wait)
41763+unsigned int tty_poll(struct file *filp, poll_table *wait)
41764 {
41765 struct tty_struct *tty = file_tty(filp);
41766 struct tty_ldisc *ld;
41767@@ -1984,6 +1980,8 @@ static unsigned int tty_poll(struct file
41768 return ret;
41769 }
41770
41771+EXPORT_SYMBOL(tty_poll);
41772+
41773 static int __tty_fasync(int fd, struct file *filp, int on)
41774 {
41775 struct tty_struct *tty = file_tty(filp);
41776@@ -2025,7 +2023,7 @@ out:
41777 return retval;
41778 }
41779
41780-static int tty_fasync(int fd, struct file *filp, int on)
41781+int tty_fasync(int fd, struct file *filp, int on)
41782 {
41783 int retval;
41784 tty_lock();
41785@@ -2034,6 +2032,8 @@ static int tty_fasync(int fd, struct fil
41786 return retval;
41787 }
41788
41789+EXPORT_SYMBOL(tty_fasync);
41790+
41791 /**
41792 * tiocsti - fake input character
41793 * @tty: tty to fake input into
41794@@ -2695,8 +2695,10 @@ long tty_ioctl(struct file *file, unsign
41795 return retval;
41796 }
41797
41798+EXPORT_SYMBOL(tty_ioctl);
41799+
41800 #ifdef CONFIG_COMPAT
41801-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41802+long tty_compat_ioctl(struct file *file, unsigned int cmd,
41803 unsigned long arg)
41804 {
41805 struct inode *inode = file->f_dentry->d_inode;
41806@@ -2720,6 +2722,9 @@ static long tty_compat_ioctl(struct file
41807
41808 return retval;
41809 }
41810+
41811+EXPORT_SYMBOL(tty_compat_ioctl);
41812+
41813 #endif
41814
41815 /*
41816@@ -3198,11 +3203,6 @@ struct tty_struct *get_current_tty(void)
41817 }
41818 EXPORT_SYMBOL_GPL(get_current_tty);
41819
41820-void tty_default_fops(struct file_operations *fops)
41821-{
41822- *fops = tty_fops;
41823-}
41824-
41825 /*
41826 * Initialize the console device. This is called *early*, so
41827 * we can't necessarily depend on lots of kernel help here.
41828diff -urNp linux-2.6.39.1/drivers/tty/tty_ldisc.c linux-2.6.39.1/drivers/tty/tty_ldisc.c
41829--- linux-2.6.39.1/drivers/tty/tty_ldisc.c 2011-05-19 00:06:34.000000000 -0400
41830+++ linux-2.6.39.1/drivers/tty/tty_ldisc.c 2011-05-22 19:36:32.000000000 -0400
41831@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
41832 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
41833 struct tty_ldisc_ops *ldo = ld->ops;
41834
41835- ldo->refcount--;
41836+ atomic_dec(&ldo->refcount);
41837 module_put(ldo->owner);
41838 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41839
41840@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
41841 spin_lock_irqsave(&tty_ldisc_lock, flags);
41842 tty_ldiscs[disc] = new_ldisc;
41843 new_ldisc->num = disc;
41844- new_ldisc->refcount = 0;
41845+ atomic_set(&new_ldisc->refcount, 0);
41846 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41847
41848 return ret;
41849@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
41850 return -EINVAL;
41851
41852 spin_lock_irqsave(&tty_ldisc_lock, flags);
41853- if (tty_ldiscs[disc]->refcount)
41854+ if (atomic_read(&tty_ldiscs[disc]->refcount))
41855 ret = -EBUSY;
41856 else
41857 tty_ldiscs[disc] = NULL;
41858@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
41859 if (ldops) {
41860 ret = ERR_PTR(-EAGAIN);
41861 if (try_module_get(ldops->owner)) {
41862- ldops->refcount++;
41863+ atomic_inc(&ldops->refcount);
41864 ret = ldops;
41865 }
41866 }
41867@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
41868 unsigned long flags;
41869
41870 spin_lock_irqsave(&tty_ldisc_lock, flags);
41871- ldops->refcount--;
41872+ atomic_dec(&ldops->refcount);
41873 module_put(ldops->owner);
41874 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41875 }
41876diff -urNp linux-2.6.39.1/drivers/tty/vt/keyboard.c linux-2.6.39.1/drivers/tty/vt/keyboard.c
41877--- linux-2.6.39.1/drivers/tty/vt/keyboard.c 2011-05-19 00:06:34.000000000 -0400
41878+++ linux-2.6.39.1/drivers/tty/vt/keyboard.c 2011-05-22 20:32:43.000000000 -0400
41879@@ -658,6 +658,16 @@ static void k_spec(struct vc_data *vc, u
41880 kbd->kbdmode == VC_OFF) &&
41881 value != KVAL(K_SAK))
41882 return; /* SAK is allowed even in raw mode */
41883+
41884+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41885+ {
41886+ void *func = fn_handler[value];
41887+ if (func == fn_show_state || func == fn_show_ptregs ||
41888+ func == fn_show_mem)
41889+ return;
41890+ }
41891+#endif
41892+
41893 fn_handler[value](vc);
41894 }
41895
41896diff -urNp linux-2.6.39.1/drivers/tty/vt/vt.c linux-2.6.39.1/drivers/tty/vt/vt.c
41897--- linux-2.6.39.1/drivers/tty/vt/vt.c 2011-05-19 00:06:34.000000000 -0400
41898+++ linux-2.6.39.1/drivers/tty/vt/vt.c 2011-05-22 19:36:32.000000000 -0400
41899@@ -261,7 +261,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
41900
41901 static void notify_write(struct vc_data *vc, unsigned int unicode)
41902 {
41903- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
41904+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
41905 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
41906 }
41907
41908diff -urNp linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c
41909--- linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c 2011-05-19 00:06:34.000000000 -0400
41910+++ linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c 2011-05-22 19:41:37.000000000 -0400
41911@@ -209,9 +209,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41912 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41913 return -EFAULT;
41914
41915- if (!capable(CAP_SYS_TTY_CONFIG))
41916- perm = 0;
41917-
41918 switch (cmd) {
41919 case KDGKBENT:
41920 key_map = key_maps[s];
41921@@ -223,6 +220,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41922 val = (i ? K_HOLE : K_NOSUCHMAP);
41923 return put_user(val, &user_kbe->kb_value);
41924 case KDSKBENT:
41925+ if (!capable(CAP_SYS_TTY_CONFIG))
41926+ perm = 0;
41927+
41928 if (!perm)
41929 return -EPERM;
41930 if (!i && v == K_NOSUCHMAP) {
41931@@ -324,9 +324,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41932 int i, j, k;
41933 int ret;
41934
41935- if (!capable(CAP_SYS_TTY_CONFIG))
41936- perm = 0;
41937-
41938 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41939 if (!kbs) {
41940 ret = -ENOMEM;
41941@@ -360,6 +357,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41942 kfree(kbs);
41943 return ((p && *p) ? -EOVERFLOW : 0);
41944 case KDSKBSENT:
41945+ if (!capable(CAP_SYS_TTY_CONFIG))
41946+ perm = 0;
41947+
41948 if (!perm) {
41949 ret = -EPERM;
41950 goto reterr;
41951diff -urNp linux-2.6.39.1/drivers/uio/uio.c linux-2.6.39.1/drivers/uio/uio.c
41952--- linux-2.6.39.1/drivers/uio/uio.c 2011-05-19 00:06:34.000000000 -0400
41953+++ linux-2.6.39.1/drivers/uio/uio.c 2011-05-22 19:36:32.000000000 -0400
41954@@ -25,6 +25,7 @@
41955 #include <linux/kobject.h>
41956 #include <linux/cdev.h>
41957 #include <linux/uio_driver.h>
41958+#include <asm/local.h>
41959
41960 #define UIO_MAX_DEVICES (1U << MINORBITS)
41961
41962@@ -32,10 +33,10 @@ struct uio_device {
41963 struct module *owner;
41964 struct device *dev;
41965 int minor;
41966- atomic_t event;
41967+ atomic_unchecked_t event;
41968 struct fasync_struct *async_queue;
41969 wait_queue_head_t wait;
41970- int vma_count;
41971+ local_t vma_count;
41972 struct uio_info *info;
41973 struct kobject *map_dir;
41974 struct kobject *portio_dir;
41975@@ -242,7 +243,7 @@ static ssize_t show_event(struct device
41976 struct device_attribute *attr, char *buf)
41977 {
41978 struct uio_device *idev = dev_get_drvdata(dev);
41979- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41980+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41981 }
41982
41983 static struct device_attribute uio_class_attributes[] = {
41984@@ -402,7 +403,7 @@ void uio_event_notify(struct uio_info *i
41985 {
41986 struct uio_device *idev = info->uio_dev;
41987
41988- atomic_inc(&idev->event);
41989+ atomic_inc_unchecked(&idev->event);
41990 wake_up_interruptible(&idev->wait);
41991 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41992 }
41993@@ -455,7 +456,7 @@ static int uio_open(struct inode *inode,
41994 }
41995
41996 listener->dev = idev;
41997- listener->event_count = atomic_read(&idev->event);
41998+ listener->event_count = atomic_read_unchecked(&idev->event);
41999 filep->private_data = listener;
42000
42001 if (idev->info->open) {
42002@@ -506,7 +507,7 @@ static unsigned int uio_poll(struct file
42003 return -EIO;
42004
42005 poll_wait(filep, &idev->wait, wait);
42006- if (listener->event_count != atomic_read(&idev->event))
42007+ if (listener->event_count != atomic_read_unchecked(&idev->event))
42008 return POLLIN | POLLRDNORM;
42009 return 0;
42010 }
42011@@ -531,7 +532,7 @@ static ssize_t uio_read(struct file *fil
42012 do {
42013 set_current_state(TASK_INTERRUPTIBLE);
42014
42015- event_count = atomic_read(&idev->event);
42016+ event_count = atomic_read_unchecked(&idev->event);
42017 if (event_count != listener->event_count) {
42018 if (copy_to_user(buf, &event_count, count))
42019 retval = -EFAULT;
42020@@ -602,13 +603,13 @@ static int uio_find_mem_index(struct vm_
42021 static void uio_vma_open(struct vm_area_struct *vma)
42022 {
42023 struct uio_device *idev = vma->vm_private_data;
42024- idev->vma_count++;
42025+ local_inc(&idev->vma_count);
42026 }
42027
42028 static void uio_vma_close(struct vm_area_struct *vma)
42029 {
42030 struct uio_device *idev = vma->vm_private_data;
42031- idev->vma_count--;
42032+ local_dec(&idev->vma_count);
42033 }
42034
42035 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42036@@ -819,7 +820,7 @@ int __uio_register_device(struct module
42037 idev->owner = owner;
42038 idev->info = info;
42039 init_waitqueue_head(&idev->wait);
42040- atomic_set(&idev->event, 0);
42041+ atomic_set_unchecked(&idev->event, 0);
42042
42043 ret = uio_get_minor(idev);
42044 if (ret)
42045diff -urNp linux-2.6.39.1/drivers/usb/atm/cxacru.c linux-2.6.39.1/drivers/usb/atm/cxacru.c
42046--- linux-2.6.39.1/drivers/usb/atm/cxacru.c 2011-05-19 00:06:34.000000000 -0400
42047+++ linux-2.6.39.1/drivers/usb/atm/cxacru.c 2011-05-22 19:36:32.000000000 -0400
42048@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
42049 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
42050 if (ret < 2)
42051 return -EINVAL;
42052- if (index < 0 || index > 0x7f)
42053+ if (index > 0x7f)
42054 return -EINVAL;
42055 pos += tmp;
42056
42057diff -urNp linux-2.6.39.1/drivers/usb/atm/usbatm.c linux-2.6.39.1/drivers/usb/atm/usbatm.c
42058--- linux-2.6.39.1/drivers/usb/atm/usbatm.c 2011-05-19 00:06:34.000000000 -0400
42059+++ linux-2.6.39.1/drivers/usb/atm/usbatm.c 2011-05-22 19:36:32.000000000 -0400
42060@@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
42061 if (printk_ratelimit())
42062 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42063 __func__, vpi, vci);
42064- atomic_inc(&vcc->stats->rx_err);
42065+ atomic_inc_unchecked(&vcc->stats->rx_err);
42066 return;
42067 }
42068
42069@@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
42070 if (length > ATM_MAX_AAL5_PDU) {
42071 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42072 __func__, length, vcc);
42073- atomic_inc(&vcc->stats->rx_err);
42074+ atomic_inc_unchecked(&vcc->stats->rx_err);
42075 goto out;
42076 }
42077
42078@@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
42079 if (sarb->len < pdu_length) {
42080 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42081 __func__, pdu_length, sarb->len, vcc);
42082- atomic_inc(&vcc->stats->rx_err);
42083+ atomic_inc_unchecked(&vcc->stats->rx_err);
42084 goto out;
42085 }
42086
42087 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42088 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42089 __func__, vcc);
42090- atomic_inc(&vcc->stats->rx_err);
42091+ atomic_inc_unchecked(&vcc->stats->rx_err);
42092 goto out;
42093 }
42094
42095@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
42096 if (printk_ratelimit())
42097 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42098 __func__, length);
42099- atomic_inc(&vcc->stats->rx_drop);
42100+ atomic_inc_unchecked(&vcc->stats->rx_drop);
42101 goto out;
42102 }
42103
42104@@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
42105
42106 vcc->push(vcc, skb);
42107
42108- atomic_inc(&vcc->stats->rx);
42109+ atomic_inc_unchecked(&vcc->stats->rx);
42110 out:
42111 skb_trim(sarb, 0);
42112 }
42113@@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
42114 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42115
42116 usbatm_pop(vcc, skb);
42117- atomic_inc(&vcc->stats->tx);
42118+ atomic_inc_unchecked(&vcc->stats->tx);
42119
42120 skb = skb_dequeue(&instance->sndqueue);
42121 }
42122@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
42123 if (!left--)
42124 return sprintf(page,
42125 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42126- atomic_read(&atm_dev->stats.aal5.tx),
42127- atomic_read(&atm_dev->stats.aal5.tx_err),
42128- atomic_read(&atm_dev->stats.aal5.rx),
42129- atomic_read(&atm_dev->stats.aal5.rx_err),
42130- atomic_read(&atm_dev->stats.aal5.rx_drop));
42131+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42132+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42133+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42134+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42135+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42136
42137 if (!left--) {
42138 if (instance->disconnected)
42139diff -urNp linux-2.6.39.1/drivers/usb/core/devices.c linux-2.6.39.1/drivers/usb/core/devices.c
42140--- linux-2.6.39.1/drivers/usb/core/devices.c 2011-05-19 00:06:34.000000000 -0400
42141+++ linux-2.6.39.1/drivers/usb/core/devices.c 2011-05-22 19:36:32.000000000 -0400
42142@@ -126,7 +126,7 @@ static const char *format_endpt =
42143 * time it gets called.
42144 */
42145 static struct device_connect_event {
42146- atomic_t count;
42147+ atomic_unchecked_t count;
42148 wait_queue_head_t wait;
42149 } device_event = {
42150 .count = ATOMIC_INIT(1),
42151@@ -164,7 +164,7 @@ static const struct class_info clas_info
42152
42153 void usbfs_conn_disc_event(void)
42154 {
42155- atomic_add(2, &device_event.count);
42156+ atomic_add_unchecked(2, &device_event.count);
42157 wake_up(&device_event.wait);
42158 }
42159
42160@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(stru
42161
42162 poll_wait(file, &device_event.wait, wait);
42163
42164- event_count = atomic_read(&device_event.count);
42165+ event_count = atomic_read_unchecked(&device_event.count);
42166 if (file->f_version != event_count) {
42167 file->f_version = event_count;
42168 return POLLIN | POLLRDNORM;
42169diff -urNp linux-2.6.39.1/drivers/usb/core/hcd.c linux-2.6.39.1/drivers/usb/core/hcd.c
42170--- linux-2.6.39.1/drivers/usb/core/hcd.c 2011-06-03 00:04:14.000000000 -0400
42171+++ linux-2.6.39.1/drivers/usb/core/hcd.c 2011-06-03 00:32:07.000000000 -0400
42172@@ -2574,7 +2574,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
42173
42174 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42175
42176-struct usb_mon_operations *mon_ops;
42177+const struct usb_mon_operations *mon_ops;
42178
42179 /*
42180 * The registration is unlocked.
42181@@ -2584,7 +2584,7 @@ struct usb_mon_operations *mon_ops;
42182 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42183 */
42184
42185-int usb_mon_register (struct usb_mon_operations *ops)
42186+int usb_mon_register (const struct usb_mon_operations *ops)
42187 {
42188
42189 if (mon_ops)
42190diff -urNp linux-2.6.39.1/drivers/usb/core/message.c linux-2.6.39.1/drivers/usb/core/message.c
42191--- linux-2.6.39.1/drivers/usb/core/message.c 2011-05-19 00:06:34.000000000 -0400
42192+++ linux-2.6.39.1/drivers/usb/core/message.c 2011-05-22 19:36:32.000000000 -0400
42193@@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
42194 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42195 if (buf) {
42196 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42197- if (len > 0) {
42198- smallbuf = kmalloc(++len, GFP_NOIO);
42199+ if (len++ > 0) {
42200+ smallbuf = kmalloc(len, GFP_NOIO);
42201 if (!smallbuf)
42202 return buf;
42203 memcpy(smallbuf, buf, len);
42204diff -urNp linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c
42205--- linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c 2011-05-19 00:06:34.000000000 -0400
42206+++ linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c 2011-05-22 19:36:32.000000000 -0400
42207@@ -96,7 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
42208 }
42209
42210 #ifdef CONFIG_KGDB
42211-static struct kgdb_io kgdbdbgp_io_ops;
42212+static struct kgdb_io kgdbdbgp_io_ops; /* cannot be const, see kgdbdbgp_parse_config */
42213 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
42214 #else
42215 #define dbgp_kgdb_mode (0)
42216@@ -1026,7 +1026,7 @@ static void kgdbdbgp_write_char(u8 chr)
42217 early_dbgp_write(NULL, &chr, 1);
42218 }
42219
42220-static struct kgdb_io kgdbdbgp_io_ops = {
42221+static struct kgdb_io kgdbdbgp_io_ops = { /* cannot be const, see kgdbdbgp_parse_config() */
42222 .name = "kgdbdbgp",
42223 .read_char = kgdbdbgp_read_char,
42224 .write_char = kgdbdbgp_write_char,
42225diff -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
42226--- linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c 2011-05-19 00:06:34.000000000 -0400
42227+++ linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c 2011-05-22 19:36:32.000000000 -0400
42228@@ -1859,7 +1859,7 @@ out:
42229 return status;
42230 }
42231
42232-static struct usb_ep_ops qe_ep_ops = {
42233+static const struct usb_ep_ops qe_ep_ops = {
42234 .enable = qe_ep_enable,
42235 .disable = qe_ep_disable,
42236
42237@@ -1928,7 +1928,7 @@ static int qe_pullup(struct usb_gadget *
42238 }
42239
42240 /* defined in usb_gadget.h */
42241-static struct usb_gadget_ops qe_gadget_ops = {
42242+static const struct usb_gadget_ops qe_gadget_ops = {
42243 .get_frame = qe_get_frame,
42244 .wakeup = qe_wakeup,
42245 /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */
42246diff -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
42247--- linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42248+++ linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42249@@ -1003,7 +1003,7 @@ static void fsl_ep_fifo_flush(struct usb
42250 } while (fsl_readl(&dr_regs->endptstatus) & bits);
42251 }
42252
42253-static struct usb_ep_ops fsl_ep_ops = {
42254+static const struct usb_ep_ops fsl_ep_ops = {
42255 .enable = fsl_ep_enable,
42256 .disable = fsl_ep_disable,
42257
42258@@ -1114,7 +1114,7 @@ static int fsl_pullup(struct usb_gadget
42259 }
42260
42261 /* defined in gadget.h */
42262-static struct usb_gadget_ops fsl_gadget_ops = {
42263+static const struct usb_gadget_ops fsl_gadget_ops = {
42264 .get_frame = fsl_get_frame,
42265 .wakeup = fsl_wakeup,
42266 /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */
42267diff -urNp linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c
42268--- linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c 2011-05-19 00:06:34.000000000 -0400
42269+++ linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c 2011-05-22 19:36:32.000000000 -0400
42270@@ -527,7 +527,7 @@ static void fusb300_fifo_flush(struct us
42271 {
42272 }
42273
42274-static struct usb_ep_ops fusb300_ep_ops = {
42275+static const struct usb_ep_ops fusb300_ep_ops = {
42276 .enable = fusb300_enable,
42277 .disable = fusb300_disable,
42278
42279@@ -1570,7 +1570,7 @@ static int fusb300_udc_pullup(struct usb
42280 return 0;
42281 }
42282
42283-static struct usb_gadget_ops fusb300_gadget_ops = {
42284+static const struct usb_gadget_ops fusb300_gadget_ops = {
42285 .pullup = fusb300_udc_pullup,
42286 };
42287
42288diff -urNp linux-2.6.39.1/drivers/usb/gadget/goku_udc.c linux-2.6.39.1/drivers/usb/gadget/goku_udc.c
42289--- linux-2.6.39.1/drivers/usb/gadget/goku_udc.c 2011-05-19 00:06:34.000000000 -0400
42290+++ linux-2.6.39.1/drivers/usb/gadget/goku_udc.c 2011-05-22 19:36:32.000000000 -0400
42291@@ -973,7 +973,7 @@ static void goku_fifo_flush(struct usb_e
42292 command(regs, COMMAND_FIFO_CLEAR, ep->num);
42293 }
42294
42295-static struct usb_ep_ops goku_ep_ops = {
42296+static const struct usb_ep_ops goku_ep_ops = {
42297 .enable = goku_ep_enable,
42298 .disable = goku_ep_disable,
42299
42300diff -urNp linux-2.6.39.1/drivers/usb/gadget/imx_udc.c linux-2.6.39.1/drivers/usb/gadget/imx_udc.c
42301--- linux-2.6.39.1/drivers/usb/gadget/imx_udc.c 2011-05-19 00:06:34.000000000 -0400
42302+++ linux-2.6.39.1/drivers/usb/gadget/imx_udc.c 2011-05-22 19:36:32.000000000 -0400
42303@@ -937,7 +937,7 @@ static void imx_ep_fifo_flush(struct usb
42304 local_irq_restore(flags);
42305 }
42306
42307-static struct usb_ep_ops imx_ep_ops = {
42308+static const struct usb_ep_ops imx_ep_ops = {
42309 .enable = imx_ep_enable,
42310 .disable = imx_ep_disable,
42311
42312diff -urNp linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c
42313--- linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c 2011-05-19 00:06:34.000000000 -0400
42314+++ linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c 2011-05-22 19:36:32.000000000 -0400
42315@@ -1437,7 +1437,7 @@ static void m66592_fifo_flush(struct usb
42316 spin_unlock_irqrestore(&ep->m66592->lock, flags);
42317 }
42318
42319-static struct usb_ep_ops m66592_ep_ops = {
42320+static const struct usb_ep_ops m66592_ep_ops = {
42321 .enable = m66592_enable,
42322 .disable = m66592_disable,
42323
42324@@ -1542,7 +1542,7 @@ static int m66592_get_frame(struct usb_g
42325 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
42326 }
42327
42328-static struct usb_gadget_ops m66592_gadget_ops = {
42329+static const struct usb_gadget_ops m66592_gadget_ops = {
42330 .get_frame = m66592_get_frame,
42331 };
42332
42333diff -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
42334--- linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42335+++ linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42336@@ -972,7 +972,7 @@ static int mv_ep_set_wedge(struct usb_ep
42337 return mv_ep_set_halt_wedge(_ep, 1, 1);
42338 }
42339
42340-static struct usb_ep_ops mv_ep_ops = {
42341+static const struct usb_ep_ops mv_ep_ops = {
42342 .enable = mv_ep_enable,
42343 .disable = mv_ep_disable,
42344
42345diff -urNp linux-2.6.39.1/drivers/usb/gadget/omap_udc.c linux-2.6.39.1/drivers/usb/gadget/omap_udc.c
42346--- linux-2.6.39.1/drivers/usb/gadget/omap_udc.c 2011-05-19 00:06:34.000000000 -0400
42347+++ linux-2.6.39.1/drivers/usb/gadget/omap_udc.c 2011-05-22 19:36:32.000000000 -0400
42348@@ -1177,7 +1177,7 @@ done:
42349 return status;
42350 }
42351
42352-static struct usb_ep_ops omap_ep_ops = {
42353+static const struct usb_ep_ops omap_ep_ops = {
42354 .enable = omap_ep_enable,
42355 .disable = omap_ep_disable,
42356
42357@@ -1374,7 +1374,7 @@ static int omap_pullup(struct usb_gadget
42358 return 0;
42359 }
42360
42361-static struct usb_gadget_ops omap_gadget_ops = {
42362+static const struct usb_gadget_ops omap_gadget_ops = {
42363 .get_frame = omap_get_frame,
42364 .wakeup = omap_wakeup,
42365 .set_selfpowered = omap_set_selfpowered,
42366diff -urNp linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c
42367--- linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c 2011-05-19 00:06:34.000000000 -0400
42368+++ linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c 2011-05-22 19:36:32.000000000 -0400
42369@@ -896,7 +896,7 @@ static void pxa25x_ep_fifo_flush(struct
42370 }
42371
42372
42373-static struct usb_ep_ops pxa25x_ep_ops = {
42374+static const struct usb_ep_ops pxa25x_ep_ops = {
42375 .enable = pxa25x_ep_enable,
42376 .disable = pxa25x_ep_disable,
42377
42378diff -urNp linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c
42379--- linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c 2011-05-19 00:06:34.000000000 -0400
42380+++ linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c 2011-05-22 19:36:32.000000000 -0400
42381@@ -1491,7 +1491,7 @@ static int pxa_ep_disable(struct usb_ep
42382 return 0;
42383 }
42384
42385-static struct usb_ep_ops pxa_ep_ops = {
42386+static const struct usb_ep_ops pxa_ep_ops = {
42387 .enable = pxa_ep_enable,
42388 .disable = pxa_ep_disable,
42389
42390diff -urNp linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c
42391--- linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c 2011-05-19 00:06:34.000000000 -0400
42392+++ linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c 2011-05-22 19:36:32.000000000 -0400
42393@@ -1392,7 +1392,7 @@ static void r8a66597_fifo_flush(struct u
42394 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
42395 }
42396
42397-static struct usb_ep_ops r8a66597_ep_ops = {
42398+static const struct usb_ep_ops r8a66597_ep_ops = {
42399 .enable = r8a66597_enable,
42400 .disable = r8a66597_disable,
42401
42402@@ -1497,7 +1497,7 @@ static int r8a66597_get_frame(struct usb
42403 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
42404 }
42405
42406-static struct usb_gadget_ops r8a66597_gadget_ops = {
42407+static const struct usb_gadget_ops r8a66597_gadget_ops = {
42408 .get_frame = r8a66597_get_frame,
42409 };
42410
42411diff -urNp linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c
42412--- linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c 2011-05-19 00:06:34.000000000 -0400
42413+++ linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c 2011-05-22 19:36:32.000000000 -0400
42414@@ -2461,7 +2461,7 @@ static int s3c_hsotg_ep_sethalt(struct u
42415 return 0;
42416 }
42417
42418-static struct usb_ep_ops s3c_hsotg_ep_ops = {
42419+static const struct usb_ep_ops s3c_hsotg_ep_ops = {
42420 .enable = s3c_hsotg_ep_enable,
42421 .disable = s3c_hsotg_ep_disable,
42422 .alloc_request = s3c_hsotg_ep_alloc_request,
42423@@ -2725,7 +2725,7 @@ static int s3c_hsotg_gadget_getframe(str
42424 return s3c_hsotg_read_frameno(to_hsotg(gadget));
42425 }
42426
42427-static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42428+static const struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42429 .get_frame = s3c_hsotg_gadget_getframe,
42430 };
42431
42432diff -urNp linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c
42433--- linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c 2011-05-19 00:06:34.000000000 -0400
42434+++ linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c 2011-05-22 19:36:32.000000000 -0400
42435@@ -400,7 +400,7 @@ static void uvc_vm_close(struct vm_area_
42436 buffer->vma_use_count--;
42437 }
42438
42439-static struct vm_operations_struct uvc_vm_ops = {
42440+static const struct vm_operations_struct uvc_vm_ops = {
42441 .open = uvc_vm_open,
42442 .close = uvc_vm_close,
42443 };
42444diff -urNp linux-2.6.39.1/drivers/usb/host/ehci-fsl.c linux-2.6.39.1/drivers/usb/host/ehci-fsl.c
42445--- linux-2.6.39.1/drivers/usb/host/ehci-fsl.c 2011-05-19 00:06:34.000000000 -0400
42446+++ linux-2.6.39.1/drivers/usb/host/ehci-fsl.c 2011-05-22 19:36:32.000000000 -0400
42447@@ -380,7 +380,7 @@ static int ehci_fsl_drv_restore(struct d
42448 return 0;
42449 }
42450
42451-static struct dev_pm_ops ehci_fsl_pm_ops = {
42452+static const struct dev_pm_ops ehci_fsl_pm_ops = {
42453 .suspend = ehci_fsl_drv_suspend,
42454 .resume = ehci_fsl_drv_resume,
42455 .restore = ehci_fsl_drv_restore,
42456diff -urNp linux-2.6.39.1/drivers/usb/host/xhci-mem.c linux-2.6.39.1/drivers/usb/host/xhci-mem.c
42457--- linux-2.6.39.1/drivers/usb/host/xhci-mem.c 2011-06-03 00:04:14.000000000 -0400
42458+++ linux-2.6.39.1/drivers/usb/host/xhci-mem.c 2011-06-03 00:32:07.000000000 -0400
42459@@ -1670,6 +1670,8 @@ static int xhci_check_trb_in_td_math(str
42460 unsigned int num_tests;
42461 int i, ret;
42462
42463+ pax_track_stack();
42464+
42465 num_tests = ARRAY_SIZE(simple_test_vector);
42466 for (i = 0; i < num_tests; i++) {
42467 ret = xhci_test_trb_in_td(xhci,
42468diff -urNp linux-2.6.39.1/drivers/usb/mon/mon_main.c linux-2.6.39.1/drivers/usb/mon/mon_main.c
42469--- linux-2.6.39.1/drivers/usb/mon/mon_main.c 2011-05-19 00:06:34.000000000 -0400
42470+++ linux-2.6.39.1/drivers/usb/mon/mon_main.c 2011-05-22 19:36:32.000000000 -0400
42471@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42472 /*
42473 * Ops
42474 */
42475-static struct usb_mon_operations mon_ops_0 = {
42476+static const struct usb_mon_operations mon_ops_0 = {
42477 .urb_submit = mon_submit,
42478 .urb_submit_error = mon_submit_error,
42479 .urb_complete = mon_complete,
42480diff -urNp linux-2.6.39.1/drivers/usb/musb/cppi_dma.h linux-2.6.39.1/drivers/usb/musb/cppi_dma.h
42481--- linux-2.6.39.1/drivers/usb/musb/cppi_dma.h 2011-05-19 00:06:34.000000000 -0400
42482+++ linux-2.6.39.1/drivers/usb/musb/cppi_dma.h 2011-05-22 19:36:32.000000000 -0400
42483@@ -113,7 +113,7 @@ struct cppi_channel {
42484
42485 /* CPPI DMA controller object */
42486 struct cppi {
42487- struct dma_controller controller;
42488+ const struct dma_controller controller;
42489 struct musb *musb;
42490 void __iomem *mregs; /* Mentor regs */
42491 void __iomem *tibase; /* TI/CPPI regs */
42492diff -urNp linux-2.6.39.1/drivers/usb/otg/msm_otg.c linux-2.6.39.1/drivers/usb/otg/msm_otg.c
42493--- linux-2.6.39.1/drivers/usb/otg/msm_otg.c 2011-05-19 00:06:34.000000000 -0400
42494+++ linux-2.6.39.1/drivers/usb/otg/msm_otg.c 2011-05-22 19:36:32.000000000 -0400
42495@@ -95,7 +95,7 @@ static int ulpi_write(struct otg_transce
42496 return 0;
42497 }
42498
42499-static struct otg_io_access_ops msm_otg_io_ops = {
42500+static const struct otg_io_access_ops msm_otg_io_ops = {
42501 .read = ulpi_read,
42502 .write = ulpi_write,
42503 };
42504diff -urNp linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c
42505--- linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c 2011-05-19 00:06:34.000000000 -0400
42506+++ linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c 2011-05-22 19:36:32.000000000 -0400
42507@@ -74,7 +74,7 @@ static int ulpi_viewport_write(struct ot
42508 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
42509 }
42510
42511-struct otg_io_access_ops ulpi_viewport_access_ops = {
42512+const struct otg_io_access_ops ulpi_viewport_access_ops = {
42513 .read = ulpi_viewport_read,
42514 .write = ulpi_viewport_write,
42515 };
42516diff -urNp linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c
42517--- linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c 2011-06-03 00:04:14.000000000 -0400
42518+++ linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c 2011-06-03 00:32:07.000000000 -0400
42519@@ -104,27 +104,27 @@ static int ftdi_stmclite_probe(struct
42520 static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
42521 static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
42522
42523-static struct ftdi_sio_quirk ftdi_jtag_quirk = {
42524+static const struct ftdi_sio_quirk ftdi_jtag_quirk = {
42525 .probe = ftdi_jtag_probe,
42526 };
42527
42528-static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42529+static const struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42530 .probe = ftdi_mtxorb_hack_setup,
42531 };
42532
42533-static struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42534+static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42535 .probe = ftdi_NDI_device_setup,
42536 };
42537
42538-static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42539+static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42540 .port_probe = ftdi_USB_UIRT_setup,
42541 };
42542
42543-static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42544+static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42545 .port_probe = ftdi_HE_TIRA1_setup,
42546 };
42547
42548-static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42549+static const struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42550 .probe = ftdi_stmclite_probe,
42551 };
42552
42553diff -urNp linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h
42554--- linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h 2011-05-19 00:06:34.000000000 -0400
42555+++ linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h 2011-05-22 19:36:32.000000000 -0400
42556@@ -192,7 +192,7 @@ struct wahc {
42557 struct list_head xfer_delayed_list;
42558 spinlock_t xfer_list_lock;
42559 struct work_struct xfer_work;
42560- atomic_t xfer_id_count;
42561+ atomic_unchecked_t xfer_id_count;
42562 };
42563
42564
42565@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
42566 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42567 spin_lock_init(&wa->xfer_list_lock);
42568 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42569- atomic_set(&wa->xfer_id_count, 1);
42570+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42571 }
42572
42573 /**
42574diff -urNp linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c
42575--- linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c 2011-05-19 00:06:34.000000000 -0400
42576+++ linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c 2011-05-22 19:36:32.000000000 -0400
42577@@ -294,7 +294,7 @@ out:
42578 */
42579 static void wa_xfer_id_init(struct wa_xfer *xfer)
42580 {
42581- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42582+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42583 }
42584
42585 /*
42586diff -urNp linux-2.6.39.1/drivers/vhost/vhost.c linux-2.6.39.1/drivers/vhost/vhost.c
42587--- linux-2.6.39.1/drivers/vhost/vhost.c 2011-05-19 00:06:34.000000000 -0400
42588+++ linux-2.6.39.1/drivers/vhost/vhost.c 2011-05-22 19:36:32.000000000 -0400
42589@@ -580,7 +580,7 @@ static int init_used(struct vhost_virtqu
42590 return get_user(vq->last_used_idx, &used->idx);
42591 }
42592
42593-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
42594+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
42595 {
42596 struct file *eventfp, *filep = NULL,
42597 *pollstart = NULL, *pollstop = NULL;
42598diff -urNp linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c
42599--- linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c 2011-05-19 00:06:34.000000000 -0400
42600+++ linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c 2011-05-22 19:36:32.000000000 -0400
42601@@ -383,7 +383,7 @@ static int corgi_lcd_get_power(struct lc
42602 return lcd->power;
42603 }
42604
42605-static struct lcd_ops corgi_lcd_ops = {
42606+static const struct lcd_ops corgi_lcd_ops = {
42607 .get_power = corgi_lcd_get_power,
42608 .set_power = corgi_lcd_set_power,
42609 .set_mode = corgi_lcd_set_mode,
42610diff -urNp linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c
42611--- linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c 2011-05-19 00:06:34.000000000 -0400
42612+++ linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c 2011-05-22 19:36:32.000000000 -0400
42613@@ -165,7 +165,7 @@ static int cr_lcd_set_power(struct lcd_d
42614 return 0;
42615 }
42616
42617-static struct lcd_ops cr_lcd_ops = {
42618+static const struct lcd_ops cr_lcd_ops = {
42619 .set_power = cr_lcd_set_power,
42620 };
42621
42622diff -urNp linux-2.6.39.1/drivers/video/backlight/ili9320.c linux-2.6.39.1/drivers/video/backlight/ili9320.c
42623--- linux-2.6.39.1/drivers/video/backlight/ili9320.c 2011-05-19 00:06:34.000000000 -0400
42624+++ linux-2.6.39.1/drivers/video/backlight/ili9320.c 2011-05-22 19:36:32.000000000 -0400
42625@@ -166,7 +166,7 @@ static int ili9320_get_power(struct lcd_
42626 return lcd->power;
42627 }
42628
42629-static struct lcd_ops ili9320_ops = {
42630+static const struct lcd_ops ili9320_ops = {
42631 .get_power = ili9320_get_power,
42632 .set_power = ili9320_set_power,
42633 };
42634diff -urNp linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c
42635--- linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c 2011-05-19 00:06:34.000000000 -0400
42636+++ linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c 2011-05-22 19:36:32.000000000 -0400
42637@@ -87,7 +87,7 @@ static int jornada_lcd_set_power(struct
42638 return 0;
42639 }
42640
42641-static struct lcd_ops jornada_lcd_props = {
42642+static const struct lcd_ops jornada_lcd_props = {
42643 .get_contrast = jornada_lcd_get_contrast,
42644 .set_contrast = jornada_lcd_set_contrast,
42645 .get_power = jornada_lcd_get_power,
42646diff -urNp linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c
42647--- linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c 2011-05-19 00:06:34.000000000 -0400
42648+++ linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c 2011-05-22 19:36:32.000000000 -0400
42649@@ -149,7 +149,7 @@ static int l4f00242t03_lcd_power_set(str
42650 return 0;
42651 }
42652
42653-static struct lcd_ops l4f_ops = {
42654+static const struct lcd_ops l4f_ops = {
42655 .set_power = l4f00242t03_lcd_power_set,
42656 .get_power = l4f00242t03_lcd_power_get,
42657 };
42658diff -urNp linux-2.6.39.1/drivers/video/backlight/lcd.c linux-2.6.39.1/drivers/video/backlight/lcd.c
42659--- linux-2.6.39.1/drivers/video/backlight/lcd.c 2011-05-19 00:06:34.000000000 -0400
42660+++ linux-2.6.39.1/drivers/video/backlight/lcd.c 2011-05-22 19:36:32.000000000 -0400
42661@@ -192,7 +192,7 @@ static struct device_attribute lcd_devic
42662 * or a pointer to the newly allocated device.
42663 */
42664 struct lcd_device *lcd_device_register(const char *name, struct device *parent,
42665- void *devdata, struct lcd_ops *ops)
42666+ void *devdata, const struct lcd_ops *ops)
42667 {
42668 struct lcd_device *new_ld;
42669 int rc;
42670diff -urNp linux-2.6.39.1/drivers/video/backlight/ld9040.c linux-2.6.39.1/drivers/video/backlight/ld9040.c
42671--- linux-2.6.39.1/drivers/video/backlight/ld9040.c 2011-05-19 00:06:34.000000000 -0400
42672+++ linux-2.6.39.1/drivers/video/backlight/ld9040.c 2011-05-22 19:36:32.000000000 -0400
42673@@ -651,7 +651,7 @@ static int ld9040_set_brightness(struct
42674 return ret;
42675 }
42676
42677-static struct lcd_ops ld9040_lcd_ops = {
42678+static const struct lcd_ops ld9040_lcd_ops = {
42679 .set_power = ld9040_set_power,
42680 .get_power = ld9040_get_power,
42681 };
42682diff -urNp linux-2.6.39.1/drivers/video/backlight/lms283gf05.c linux-2.6.39.1/drivers/video/backlight/lms283gf05.c
42683--- linux-2.6.39.1/drivers/video/backlight/lms283gf05.c 2011-05-19 00:06:34.000000000 -0400
42684+++ linux-2.6.39.1/drivers/video/backlight/lms283gf05.c 2011-05-22 19:36:32.000000000 -0400
42685@@ -144,7 +144,7 @@ static int lms283gf05_power_set(struct l
42686 return 0;
42687 }
42688
42689-static struct lcd_ops lms_ops = {
42690+static const struct lcd_ops lms_ops = {
42691 .set_power = lms283gf05_power_set,
42692 .get_power = NULL,
42693 };
42694diff -urNp linux-2.6.39.1/drivers/video/backlight/ltv350qv.c linux-2.6.39.1/drivers/video/backlight/ltv350qv.c
42695--- linux-2.6.39.1/drivers/video/backlight/ltv350qv.c 2011-05-19 00:06:34.000000000 -0400
42696+++ linux-2.6.39.1/drivers/video/backlight/ltv350qv.c 2011-05-22 19:36:32.000000000 -0400
42697@@ -221,7 +221,7 @@ static int ltv350qv_get_power(struct lcd
42698 return lcd->power;
42699 }
42700
42701-static struct lcd_ops ltv_ops = {
42702+static const struct lcd_ops ltv_ops = {
42703 .get_power = ltv350qv_get_power,
42704 .set_power = ltv350qv_set_power,
42705 };
42706diff -urNp linux-2.6.39.1/drivers/video/backlight/platform_lcd.c linux-2.6.39.1/drivers/video/backlight/platform_lcd.c
42707--- linux-2.6.39.1/drivers/video/backlight/platform_lcd.c 2011-05-19 00:06:34.000000000 -0400
42708+++ linux-2.6.39.1/drivers/video/backlight/platform_lcd.c 2011-05-22 19:36:32.000000000 -0400
42709@@ -66,7 +66,7 @@ static int platform_lcd_match(struct lcd
42710 return plcd->us->parent == info->device;
42711 }
42712
42713-static struct lcd_ops platform_lcd_ops = {
42714+static const struct lcd_ops platform_lcd_ops = {
42715 .get_power = platform_lcd_get_power,
42716 .set_power = platform_lcd_set_power,
42717 .check_fb = platform_lcd_match,
42718diff -urNp linux-2.6.39.1/drivers/video/backlight/s6e63m0.c linux-2.6.39.1/drivers/video/backlight/s6e63m0.c
42719--- linux-2.6.39.1/drivers/video/backlight/s6e63m0.c 2011-05-19 00:06:34.000000000 -0400
42720+++ linux-2.6.39.1/drivers/video/backlight/s6e63m0.c 2011-05-22 19:36:32.000000000 -0400
42721@@ -644,7 +644,7 @@ static int s6e63m0_set_brightness(struct
42722 return ret;
42723 }
42724
42725-static struct lcd_ops s6e63m0_lcd_ops = {
42726+static const struct lcd_ops s6e63m0_lcd_ops = {
42727 .set_power = s6e63m0_set_power,
42728 .get_power = s6e63m0_get_power,
42729 };
42730diff -urNp linux-2.6.39.1/drivers/video/backlight/tdo24m.c linux-2.6.39.1/drivers/video/backlight/tdo24m.c
42731--- linux-2.6.39.1/drivers/video/backlight/tdo24m.c 2011-05-19 00:06:34.000000000 -0400
42732+++ linux-2.6.39.1/drivers/video/backlight/tdo24m.c 2011-05-22 19:36:32.000000000 -0400
42733@@ -322,7 +322,7 @@ static int tdo24m_set_mode(struct lcd_de
42734 return lcd->adj_mode(lcd, mode);
42735 }
42736
42737-static struct lcd_ops tdo24m_ops = {
42738+static const struct lcd_ops tdo24m_ops = {
42739 .get_power = tdo24m_get_power,
42740 .set_power = tdo24m_set_power,
42741 .set_mode = tdo24m_set_mode,
42742diff -urNp linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c
42743--- linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c 2011-05-19 00:06:34.000000000 -0400
42744+++ linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c 2011-05-22 19:36:32.000000000 -0400
42745@@ -163,7 +163,7 @@ static int tosa_lcd_set_mode(struct lcd_
42746 return 0;
42747 }
42748
42749-static struct lcd_ops tosa_lcd_ops = {
42750+static const struct lcd_ops tosa_lcd_ops = {
42751 .set_power = tosa_lcd_set_power,
42752 .get_power = tosa_lcd_get_power,
42753 .set_mode = tosa_lcd_set_mode,
42754diff -urNp linux-2.6.39.1/drivers/video/bf537-lq035.c linux-2.6.39.1/drivers/video/bf537-lq035.c
42755--- linux-2.6.39.1/drivers/video/bf537-lq035.c 2011-05-19 00:06:34.000000000 -0400
42756+++ linux-2.6.39.1/drivers/video/bf537-lq035.c 2011-05-22 19:36:32.000000000 -0400
42757@@ -682,7 +682,7 @@ static int bfin_lcd_check_fb(struct lcd_
42758 return 0;
42759 }
42760
42761-static struct lcd_ops bfin_lcd_ops = {
42762+static const struct lcd_ops bfin_lcd_ops = {
42763 .get_power = bfin_lcd_get_power,
42764 .set_power = bfin_lcd_set_power,
42765 .get_contrast = bfin_lcd_get_contrast,
42766diff -urNp linux-2.6.39.1/drivers/video/bf54x-lq043fb.c linux-2.6.39.1/drivers/video/bf54x-lq043fb.c
42767--- linux-2.6.39.1/drivers/video/bf54x-lq043fb.c 2011-05-19 00:06:34.000000000 -0400
42768+++ linux-2.6.39.1/drivers/video/bf54x-lq043fb.c 2011-05-22 19:36:32.000000000 -0400
42769@@ -467,7 +467,7 @@ static int bfin_lcd_check_fb(struct lcd_
42770 return 0;
42771 }
42772
42773-static struct lcd_ops bfin_lcd_ops = {
42774+static const struct lcd_ops bfin_lcd_ops = {
42775 .get_power = bfin_lcd_get_power,
42776 .set_power = bfin_lcd_set_power,
42777 .get_contrast = bfin_lcd_get_contrast,
42778diff -urNp linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c
42779--- linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c 2011-05-19 00:06:34.000000000 -0400
42780+++ linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c 2011-05-22 19:36:32.000000000 -0400
42781@@ -387,7 +387,7 @@ static int bfin_lcd_check_fb(struct lcd_
42782 return 0;
42783 }
42784
42785-static struct lcd_ops bfin_lcd_ops = {
42786+static const struct lcd_ops bfin_lcd_ops = {
42787 .get_power = bfin_lcd_get_power,
42788 .set_power = bfin_lcd_set_power,
42789 .get_contrast = bfin_lcd_get_contrast,
42790diff -urNp linux-2.6.39.1/drivers/video/fbcmap.c linux-2.6.39.1/drivers/video/fbcmap.c
42791--- linux-2.6.39.1/drivers/video/fbcmap.c 2011-05-19 00:06:34.000000000 -0400
42792+++ linux-2.6.39.1/drivers/video/fbcmap.c 2011-05-22 19:36:32.000000000 -0400
42793@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
42794 rc = -ENODEV;
42795 goto out;
42796 }
42797- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42798- !info->fbops->fb_setcmap)) {
42799+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42800 rc = -EINVAL;
42801 goto out1;
42802 }
42803diff -urNp linux-2.6.39.1/drivers/video/fbmem.c linux-2.6.39.1/drivers/video/fbmem.c
42804--- linux-2.6.39.1/drivers/video/fbmem.c 2011-05-19 00:06:34.000000000 -0400
42805+++ linux-2.6.39.1/drivers/video/fbmem.c 2011-05-22 19:36:32.000000000 -0400
42806@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_in
42807 image->dx += image->width + 8;
42808 }
42809 } else if (rotate == FB_ROTATE_UD) {
42810- for (x = 0; x < num && image->dx >= 0; x++) {
42811+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42812 info->fbops->fb_imageblit(info, image);
42813 image->dx -= image->width + 8;
42814 }
42815@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_in
42816 image->dy += image->height + 8;
42817 }
42818 } else if (rotate == FB_ROTATE_CCW) {
42819- for (x = 0; x < num && image->dy >= 0; x++) {
42820+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42821 info->fbops->fb_imageblit(info, image);
42822 image->dy -= image->height + 8;
42823 }
42824@@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct
42825 int flags = info->flags;
42826 int ret = 0;
42827
42828+ pax_track_stack();
42829+
42830 if (var->activate & FB_ACTIVATE_INV_MODE) {
42831 struct fb_videomode mode1, mode2;
42832
42833@@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *
42834 void __user *argp = (void __user *)arg;
42835 long ret = 0;
42836
42837+ pax_track_stack();
42838+
42839 switch (cmd) {
42840 case FBIOGET_VSCREENINFO:
42841 if (!lock_fb_info(info))
42842@@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *
42843 return -EFAULT;
42844 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42845 return -EINVAL;
42846- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42847+ if (con2fb.framebuffer >= FB_MAX)
42848 return -EINVAL;
42849 if (!registered_fb[con2fb.framebuffer])
42850 request_module("fb%d", con2fb.framebuffer);
42851diff -urNp linux-2.6.39.1/drivers/video/geode/display_gx1.c linux-2.6.39.1/drivers/video/geode/display_gx1.c
42852--- linux-2.6.39.1/drivers/video/geode/display_gx1.c 2011-05-19 00:06:34.000000000 -0400
42853+++ linux-2.6.39.1/drivers/video/geode/display_gx1.c 2011-05-22 19:36:32.000000000 -0400
42854@@ -208,7 +208,7 @@ static void gx1_set_hw_palette_reg(struc
42855 writel(val, par->dc_regs + DC_PAL_DATA);
42856 }
42857
42858-struct geode_dc_ops gx1_dc_ops = {
42859+const struct geode_dc_ops gx1_dc_ops = {
42860 .set_mode = gx1_set_mode,
42861 .set_palette_reg = gx1_set_hw_palette_reg,
42862 };
42863diff -urNp linux-2.6.39.1/drivers/video/geode/display_gx1.h linux-2.6.39.1/drivers/video/geode/display_gx1.h
42864--- linux-2.6.39.1/drivers/video/geode/display_gx1.h 2011-05-19 00:06:34.000000000 -0400
42865+++ linux-2.6.39.1/drivers/video/geode/display_gx1.h 2011-05-22 19:36:32.000000000 -0400
42866@@ -18,7 +18,7 @@
42867 unsigned gx1_gx_base(void);
42868 int gx1_frame_buffer_size(void);
42869
42870-extern struct geode_dc_ops gx1_dc_ops;
42871+extern const struct geode_dc_ops gx1_dc_ops;
42872
42873 /* GX1 configuration I/O registers */
42874
42875diff -urNp linux-2.6.39.1/drivers/video/geode/geodefb.h linux-2.6.39.1/drivers/video/geode/geodefb.h
42876--- linux-2.6.39.1/drivers/video/geode/geodefb.h 2011-05-19 00:06:34.000000000 -0400
42877+++ linux-2.6.39.1/drivers/video/geode/geodefb.h 2011-05-22 19:36:32.000000000 -0400
42878@@ -31,8 +31,8 @@ struct geodefb_par {
42879 int panel_y;
42880 void __iomem *dc_regs;
42881 void __iomem *vid_regs;
42882- struct geode_dc_ops *dc_ops;
42883- struct geode_vid_ops *vid_ops;
42884+ const struct geode_dc_ops *dc_ops;
42885+ const struct geode_vid_ops *vid_ops;
42886 };
42887
42888 #endif /* !__GEODEFB_H__ */
42889diff -urNp linux-2.6.39.1/drivers/video/geode/video_cs5530.c linux-2.6.39.1/drivers/video/geode/video_cs5530.c
42890--- linux-2.6.39.1/drivers/video/geode/video_cs5530.c 2011-05-19 00:06:34.000000000 -0400
42891+++ linux-2.6.39.1/drivers/video/geode/video_cs5530.c 2011-05-22 19:36:32.000000000 -0400
42892@@ -186,7 +186,7 @@ static int cs5530_blank_display(struct f
42893 return 0;
42894 }
42895
42896-struct geode_vid_ops cs5530_vid_ops = {
42897+const struct geode_vid_ops cs5530_vid_ops = {
42898 .set_dclk = cs5530_set_dclk_frequency,
42899 .configure_display = cs5530_configure_display,
42900 .blank_display = cs5530_blank_display,
42901diff -urNp linux-2.6.39.1/drivers/video/geode/video_cs5530.h linux-2.6.39.1/drivers/video/geode/video_cs5530.h
42902--- linux-2.6.39.1/drivers/video/geode/video_cs5530.h 2011-05-19 00:06:34.000000000 -0400
42903+++ linux-2.6.39.1/drivers/video/geode/video_cs5530.h 2011-05-22 19:36:32.000000000 -0400
42904@@ -15,7 +15,7 @@
42905 #ifndef __VIDEO_CS5530_H__
42906 #define __VIDEO_CS5530_H__
42907
42908-extern struct geode_vid_ops cs5530_vid_ops;
42909+extern const struct geode_vid_ops cs5530_vid_ops;
42910
42911 /* CS5530 Video device registers */
42912
42913diff -urNp linux-2.6.39.1/drivers/video/i810/i810_accel.c linux-2.6.39.1/drivers/video/i810/i810_accel.c
42914--- linux-2.6.39.1/drivers/video/i810/i810_accel.c 2011-05-19 00:06:34.000000000 -0400
42915+++ linux-2.6.39.1/drivers/video/i810/i810_accel.c 2011-05-22 19:36:32.000000000 -0400
42916@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
42917 }
42918 }
42919 printk("ringbuffer lockup!!!\n");
42920+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42921 i810_report_error(mmio);
42922 par->dev_flags |= LOCKUP;
42923 info->pixmap.scan_align = 1;
42924diff -urNp linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c
42925--- linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c 2011-05-19 00:06:34.000000000 -0400
42926+++ linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c 2011-05-22 19:36:32.000000000 -0400
42927@@ -1232,7 +1232,7 @@ static struct fb_ops matroxfb_ops = {
42928 #define RSText 0x7
42929 #define RSText8 0x8
42930 /* 9-F */
42931-static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42932+static const struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42933 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
42934 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
42935 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
42936diff -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
42937--- linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c 2011-05-19 00:06:34.000000000 -0400
42938+++ linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c 2011-05-22 19:36:32.000000000 -0400
42939@@ -87,7 +87,7 @@ static int ams_delta_lcd_get_contrast(st
42940 return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
42941 }
42942
42943-static struct lcd_ops ams_delta_lcd_ops = {
42944+static const struct lcd_ops ams_delta_lcd_ops = {
42945 .get_power = ams_delta_lcd_get_power,
42946 .set_power = ams_delta_lcd_set_power,
42947 .get_contrast = ams_delta_lcd_get_contrast,
42948diff -urNp linux-2.6.39.1/drivers/video/pxa3xx-gcu.c linux-2.6.39.1/drivers/video/pxa3xx-gcu.c
42949--- linux-2.6.39.1/drivers/video/pxa3xx-gcu.c 2011-05-19 00:06:34.000000000 -0400
42950+++ linux-2.6.39.1/drivers/video/pxa3xx-gcu.c 2011-05-22 19:36:32.000000000 -0400
42951@@ -103,7 +103,7 @@ struct pxa3xx_gcu_priv {
42952 dma_addr_t shared_phys;
42953 struct resource *resource_mem;
42954 struct miscdevice misc_dev;
42955- struct file_operations misc_fops;
42956+ const struct file_operations misc_fops;
42957 wait_queue_head_t wait_idle;
42958 wait_queue_head_t wait_free;
42959 spinlock_t spinlock;
42960diff -urNp linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c
42961--- linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c 2011-05-19 00:06:34.000000000 -0400
42962+++ linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c 2011-05-22 19:36:32.000000000 -0400
42963@@ -245,7 +245,7 @@ static unsigned long lcdc_sys_read_data(
42964 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
42965 }
42966
42967-struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42968+const struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42969 lcdc_sys_write_index,
42970 lcdc_sys_write_data,
42971 lcdc_sys_read_data,
42972diff -urNp linux-2.6.39.1/drivers/video/udlfb.c linux-2.6.39.1/drivers/video/udlfb.c
42973--- linux-2.6.39.1/drivers/video/udlfb.c 2011-05-19 00:06:34.000000000 -0400
42974+++ linux-2.6.39.1/drivers/video/udlfb.c 2011-05-22 19:36:32.000000000 -0400
42975@@ -584,11 +584,11 @@ int dlfb_handle_damage(struct dlfb_data
42976 dlfb_urb_completion(urb);
42977
42978 error:
42979- atomic_add(bytes_sent, &dev->bytes_sent);
42980- atomic_add(bytes_identical, &dev->bytes_identical);
42981- atomic_add(width*height*2, &dev->bytes_rendered);
42982+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42983+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42984+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42985 end_cycles = get_cycles();
42986- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42987+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42988 >> 10)), /* Kcycles */
42989 &dev->cpu_kcycles_used);
42990
42991@@ -709,11 +709,11 @@ static void dlfb_dpy_deferred_io(struct
42992 dlfb_urb_completion(urb);
42993
42994 error:
42995- atomic_add(bytes_sent, &dev->bytes_sent);
42996- atomic_add(bytes_identical, &dev->bytes_identical);
42997- atomic_add(bytes_rendered, &dev->bytes_rendered);
42998+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42999+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43000+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43001 end_cycles = get_cycles();
43002- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43003+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43004 >> 10)), /* Kcycles */
43005 &dev->cpu_kcycles_used);
43006 }
43007@@ -1301,7 +1301,7 @@ static ssize_t metrics_bytes_rendered_sh
43008 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43009 struct dlfb_data *dev = fb_info->par;
43010 return snprintf(buf, PAGE_SIZE, "%u\n",
43011- atomic_read(&dev->bytes_rendered));
43012+ atomic_read_unchecked(&dev->bytes_rendered));
43013 }
43014
43015 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43016@@ -1309,7 +1309,7 @@ static ssize_t metrics_bytes_identical_s
43017 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43018 struct dlfb_data *dev = fb_info->par;
43019 return snprintf(buf, PAGE_SIZE, "%u\n",
43020- atomic_read(&dev->bytes_identical));
43021+ atomic_read_unchecked(&dev->bytes_identical));
43022 }
43023
43024 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43025@@ -1317,7 +1317,7 @@ static ssize_t metrics_bytes_sent_show(s
43026 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43027 struct dlfb_data *dev = fb_info->par;
43028 return snprintf(buf, PAGE_SIZE, "%u\n",
43029- atomic_read(&dev->bytes_sent));
43030+ atomic_read_unchecked(&dev->bytes_sent));
43031 }
43032
43033 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43034@@ -1325,7 +1325,7 @@ static ssize_t metrics_cpu_kcycles_used_
43035 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43036 struct dlfb_data *dev = fb_info->par;
43037 return snprintf(buf, PAGE_SIZE, "%u\n",
43038- atomic_read(&dev->cpu_kcycles_used));
43039+ atomic_read_unchecked(&dev->cpu_kcycles_used));
43040 }
43041
43042 static ssize_t edid_show(
43043@@ -1382,10 +1382,10 @@ static ssize_t metrics_reset_store(struc
43044 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43045 struct dlfb_data *dev = fb_info->par;
43046
43047- atomic_set(&dev->bytes_rendered, 0);
43048- atomic_set(&dev->bytes_identical, 0);
43049- atomic_set(&dev->bytes_sent, 0);
43050- atomic_set(&dev->cpu_kcycles_used, 0);
43051+ atomic_set_unchecked(&dev->bytes_rendered, 0);
43052+ atomic_set_unchecked(&dev->bytes_identical, 0);
43053+ atomic_set_unchecked(&dev->bytes_sent, 0);
43054+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43055
43056 return count;
43057 }
43058diff -urNp linux-2.6.39.1/drivers/video/uvesafb.c linux-2.6.39.1/drivers/video/uvesafb.c
43059--- linux-2.6.39.1/drivers/video/uvesafb.c 2011-05-19 00:06:34.000000000 -0400
43060+++ linux-2.6.39.1/drivers/video/uvesafb.c 2011-05-22 19:36:32.000000000 -0400
43061@@ -19,6 +19,7 @@
43062 #include <linux/io.h>
43063 #include <linux/mutex.h>
43064 #include <linux/slab.h>
43065+#include <linux/moduleloader.h>
43066 #include <video/edid.h>
43067 #include <video/uvesafb.h>
43068 #ifdef CONFIG_X86
43069@@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
43070 NULL,
43071 };
43072
43073- return call_usermodehelper(v86d_path, argv, envp, 1);
43074+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
43075 }
43076
43077 /*
43078@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
43079 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43080 par->pmi_setpal = par->ypan = 0;
43081 } else {
43082+
43083+#ifdef CONFIG_PAX_KERNEXEC
43084+#ifdef CONFIG_MODULES
43085+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43086+#endif
43087+ if (!par->pmi_code) {
43088+ par->pmi_setpal = par->ypan = 0;
43089+ return 0;
43090+ }
43091+#endif
43092+
43093 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43094 + task->t.regs.edi);
43095+
43096+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43097+ pax_open_kernel();
43098+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43099+ pax_close_kernel();
43100+
43101+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43102+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43103+#else
43104 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43105 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43106+#endif
43107+
43108 printk(KERN_INFO "uvesafb: protected mode interface info at "
43109 "%04x:%04x\n",
43110 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43111@@ -1821,6 +1844,11 @@ out:
43112 if (par->vbe_modes)
43113 kfree(par->vbe_modes);
43114
43115+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43116+ if (par->pmi_code)
43117+ module_free_exec(NULL, par->pmi_code);
43118+#endif
43119+
43120 framebuffer_release(info);
43121 return err;
43122 }
43123@@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platfor
43124 kfree(par->vbe_state_orig);
43125 if (par->vbe_state_saved)
43126 kfree(par->vbe_state_saved);
43127+
43128+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43129+ if (par->pmi_code)
43130+ module_free_exec(NULL, par->pmi_code);
43131+#endif
43132+
43133 }
43134
43135 framebuffer_release(info);
43136@@ -2013,7 +2047,7 @@ static int param_set_scroll(const char *
43137
43138 return 0;
43139 }
43140-static struct kernel_param_ops param_ops_scroll = {
43141+static const struct kernel_param_ops param_ops_scroll = {
43142 .set = param_set_scroll,
43143 };
43144 #define param_check_scroll(name, p) __param_check(name, p, void)
43145diff -urNp linux-2.6.39.1/drivers/video/vesafb.c linux-2.6.39.1/drivers/video/vesafb.c
43146--- linux-2.6.39.1/drivers/video/vesafb.c 2011-05-19 00:06:34.000000000 -0400
43147+++ linux-2.6.39.1/drivers/video/vesafb.c 2011-05-22 19:36:32.000000000 -0400
43148@@ -9,6 +9,7 @@
43149 */
43150
43151 #include <linux/module.h>
43152+#include <linux/moduleloader.h>
43153 #include <linux/kernel.h>
43154 #include <linux/errno.h>
43155 #include <linux/string.h>
43156@@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
43157 static int vram_total __initdata; /* Set total amount of memory */
43158 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43159 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43160-static void (*pmi_start)(void) __read_mostly;
43161-static void (*pmi_pal) (void) __read_mostly;
43162+static void (*pmi_start)(void) __read_only;
43163+static void (*pmi_pal) (void) __read_only;
43164 static int depth __read_mostly;
43165 static int vga_compat __read_mostly;
43166 /* --------------------------------------------------------------------- */
43167@@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
43168 unsigned int size_vmode;
43169 unsigned int size_remap;
43170 unsigned int size_total;
43171+ void *pmi_code = NULL;
43172
43173 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43174 return -ENODEV;
43175@@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
43176 size_remap = size_total;
43177 vesafb_fix.smem_len = size_remap;
43178
43179-#ifndef __i386__
43180- screen_info.vesapm_seg = 0;
43181-#endif
43182-
43183 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43184 printk(KERN_WARNING
43185 "vesafb: cannot reserve video memory at 0x%lx\n",
43186@@ -306,9 +304,21 @@ static int __init vesafb_probe(struct pl
43187 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43188 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43189
43190+#ifdef __i386__
43191+
43192+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43193+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
43194+ if (!pmi_code)
43195+#elif !defined(CONFIG_PAX_KERNEXEC)
43196+ if (0)
43197+#endif
43198+
43199+#endif
43200+ screen_info.vesapm_seg = 0;
43201+
43202 if (screen_info.vesapm_seg) {
43203- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43204- screen_info.vesapm_seg,screen_info.vesapm_off);
43205+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43206+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43207 }
43208
43209 if (screen_info.vesapm_seg < 0xc000)
43210@@ -316,9 +326,25 @@ static int __init vesafb_probe(struct pl
43211
43212 if (ypan || pmi_setpal) {
43213 unsigned short *pmi_base;
43214- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43215- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43216- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43217+
43218+ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43219+
43220+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43221+ pax_open_kernel();
43222+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43223+#else
43224+ pmi_code = pmi_base;
43225+#endif
43226+
43227+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43228+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43229+
43230+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43231+ pmi_start = ktva_ktla(pmi_start);
43232+ pmi_pal = ktva_ktla(pmi_pal);
43233+ pax_close_kernel();
43234+#endif
43235+
43236 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43237 if (pmi_base[3]) {
43238 printk(KERN_INFO "vesafb: pmi: ports = ");
43239@@ -487,6 +513,11 @@ static int __init vesafb_probe(struct pl
43240 info->node, info->fix.id);
43241 return 0;
43242 err:
43243+
43244+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43245+ module_free_exec(NULL, pmi_code);
43246+#endif
43247+
43248 if (info->screen_base)
43249 iounmap(info->screen_base);
43250 framebuffer_release(info);
43251diff -urNp linux-2.6.39.1/drivers/virtio/virtio_balloon.c linux-2.6.39.1/drivers/virtio/virtio_balloon.c
43252--- linux-2.6.39.1/drivers/virtio/virtio_balloon.c 2011-05-19 00:06:34.000000000 -0400
43253+++ linux-2.6.39.1/drivers/virtio/virtio_balloon.c 2011-05-22 19:36:32.000000000 -0400
43254@@ -176,6 +176,8 @@ static void update_balloon_stats(struct
43255 struct sysinfo i;
43256 int idx = 0;
43257
43258+ pax_track_stack();
43259+
43260 all_vm_events(events);
43261 si_meminfo(&i);
43262
43263diff -urNp linux-2.6.39.1/drivers/xen/gntalloc.c linux-2.6.39.1/drivers/xen/gntalloc.c
43264--- linux-2.6.39.1/drivers/xen/gntalloc.c 2011-05-19 00:06:34.000000000 -0400
43265+++ linux-2.6.39.1/drivers/xen/gntalloc.c 2011-05-22 19:36:32.000000000 -0400
43266@@ -440,7 +440,7 @@ static void gntalloc_vma_close(struct vm
43267 spin_unlock(&gref_lock);
43268 }
43269
43270-static struct vm_operations_struct gntalloc_vmops = {
43271+static const struct vm_operations_struct gntalloc_vmops = {
43272 .close = gntalloc_vma_close,
43273 };
43274
43275diff -urNp linux-2.6.39.1/drivers/xen/gntdev.c linux-2.6.39.1/drivers/xen/gntdev.c
43276--- linux-2.6.39.1/drivers/xen/gntdev.c 2011-05-19 00:06:34.000000000 -0400
43277+++ linux-2.6.39.1/drivers/xen/gntdev.c 2011-05-22 19:36:32.000000000 -0400
43278@@ -340,7 +340,7 @@ static void gntdev_vma_close(struct vm_a
43279 gntdev_put_map(map);
43280 }
43281
43282-static struct vm_operations_struct gntdev_vmops = {
43283+static const struct vm_operations_struct gntdev_vmops = {
43284 .close = gntdev_vma_close,
43285 };
43286
43287@@ -404,7 +404,7 @@ static void mn_release(struct mmu_notifi
43288 spin_unlock(&priv->lock);
43289 }
43290
43291-struct mmu_notifier_ops gntdev_mmu_ops = {
43292+const struct mmu_notifier_ops gntdev_mmu_ops = {
43293 .release = mn_release,
43294 .invalidate_page = mn_invl_page,
43295 .invalidate_range_start = mn_invl_range_start,
43296diff -urNp linux-2.6.39.1/drivers/xen/xenfs/privcmd.c linux-2.6.39.1/drivers/xen/xenfs/privcmd.c
43297--- linux-2.6.39.1/drivers/xen/xenfs/privcmd.c 2011-05-19 00:06:34.000000000 -0400
43298+++ linux-2.6.39.1/drivers/xen/xenfs/privcmd.c 2011-05-22 19:36:32.000000000 -0400
43299@@ -268,7 +268,7 @@ static int mmap_return_errors(void *data
43300 return put_user(*mfnp, st->user++);
43301 }
43302
43303-static struct vm_operations_struct privcmd_vm_ops;
43304+static const struct vm_operations_struct privcmd_vm_ops;
43305
43306 static long privcmd_ioctl_mmap_batch(void __user *udata)
43307 {
43308@@ -369,7 +369,7 @@ static int privcmd_fault(struct vm_area_
43309 return VM_FAULT_SIGBUS;
43310 }
43311
43312-static struct vm_operations_struct privcmd_vm_ops = {
43313+static const struct vm_operations_struct privcmd_vm_ops = {
43314 .fault = privcmd_fault
43315 };
43316
43317diff -urNp linux-2.6.39.1/fs/9p/vfs_inode.c linux-2.6.39.1/fs/9p/vfs_inode.c
43318--- linux-2.6.39.1/fs/9p/vfs_inode.c 2011-05-19 00:06:34.000000000 -0400
43319+++ linux-2.6.39.1/fs/9p/vfs_inode.c 2011-05-22 19:36:32.000000000 -0400
43320@@ -1210,7 +1210,7 @@ static void *v9fs_vfs_follow_link(struct
43321 void
43322 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43323 {
43324- char *s = nd_get_link(nd);
43325+ const char *s = nd_get_link(nd);
43326
43327 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
43328 IS_ERR(s) ? "<error>" : s);
43329diff -urNp linux-2.6.39.1/fs/aio.c linux-2.6.39.1/fs/aio.c
43330--- linux-2.6.39.1/fs/aio.c 2011-05-19 00:06:34.000000000 -0400
43331+++ linux-2.6.39.1/fs/aio.c 2011-06-03 01:00:34.000000000 -0400
43332@@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx
43333 size += sizeof(struct io_event) * nr_events;
43334 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43335
43336- if (nr_pages < 0)
43337+ if (nr_pages <= 0)
43338 return -EINVAL;
43339
43340 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43341@@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ct
43342 struct aio_timeout to;
43343 int retry = 0;
43344
43345+ pax_track_stack();
43346+
43347 /* needed to zero any padding within an entry (there shouldn't be
43348 * any, but C is fun!
43349 */
43350@@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *i
43351 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43352 {
43353 ssize_t ret;
43354+ struct iovec iovstack;
43355
43356 #ifdef CONFIG_COMPAT
43357 if (compat)
43358 ret = compat_rw_copy_check_uvector(type,
43359 (struct compat_iovec __user *)kiocb->ki_buf,
43360- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43361+ kiocb->ki_nbytes, 1, &iovstack,
43362 &kiocb->ki_iovec);
43363 else
43364 #endif
43365 ret = rw_copy_check_uvector(type,
43366 (struct iovec __user *)kiocb->ki_buf,
43367- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43368+ kiocb->ki_nbytes, 1, &iovstack,
43369 &kiocb->ki_iovec);
43370 if (ret < 0)
43371 goto out;
43372
43373+ if (kiocb->ki_iovec == &iovstack) {
43374+ kiocb->ki_inline_vec = iovstack;
43375+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
43376+ }
43377 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43378 kiocb->ki_cur_seg = 0;
43379 /* ki_nbytes/left now reflect bytes instead of segs */
43380diff -urNp linux-2.6.39.1/fs/attr.c linux-2.6.39.1/fs/attr.c
43381--- linux-2.6.39.1/fs/attr.c 2011-05-19 00:06:34.000000000 -0400
43382+++ linux-2.6.39.1/fs/attr.c 2011-05-22 19:41:37.000000000 -0400
43383@@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
43384 unsigned long limit;
43385
43386 limit = rlimit(RLIMIT_FSIZE);
43387+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43388 if (limit != RLIM_INFINITY && offset > limit)
43389 goto out_sig;
43390 if (offset > inode->i_sb->s_maxbytes)
43391diff -urNp linux-2.6.39.1/fs/befs/linuxvfs.c linux-2.6.39.1/fs/befs/linuxvfs.c
43392--- linux-2.6.39.1/fs/befs/linuxvfs.c 2011-05-19 00:06:34.000000000 -0400
43393+++ linux-2.6.39.1/fs/befs/linuxvfs.c 2011-05-22 19:36:32.000000000 -0400
43394@@ -498,7 +498,7 @@ static void befs_put_link(struct dentry
43395 {
43396 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43397 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43398- char *link = nd_get_link(nd);
43399+ const char *link = nd_get_link(nd);
43400 if (!IS_ERR(link))
43401 kfree(link);
43402 }
43403diff -urNp linux-2.6.39.1/fs/binfmt_aout.c linux-2.6.39.1/fs/binfmt_aout.c
43404--- linux-2.6.39.1/fs/binfmt_aout.c 2011-05-19 00:06:34.000000000 -0400
43405+++ linux-2.6.39.1/fs/binfmt_aout.c 2011-05-22 19:41:37.000000000 -0400
43406@@ -16,6 +16,7 @@
43407 #include <linux/string.h>
43408 #include <linux/fs.h>
43409 #include <linux/file.h>
43410+#include <linux/security.h>
43411 #include <linux/stat.h>
43412 #include <linux/fcntl.h>
43413 #include <linux/ptrace.h>
43414@@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
43415 #endif
43416 # define START_STACK(u) ((void __user *)u.start_stack)
43417
43418+ memset(&dump, 0, sizeof(dump));
43419+
43420 fs = get_fs();
43421 set_fs(KERNEL_DS);
43422 has_dumped = 1;
43423@@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
43424
43425 /* If the size of the dump file exceeds the rlimit, then see what would happen
43426 if we wrote the stack, but not the data area. */
43427+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43428 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43429 dump.u_dsize = 0;
43430
43431 /* Make sure we have enough room to write the stack and data areas. */
43432+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43433 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43434 dump.u_ssize = 0;
43435
43436@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
43437 rlim = rlimit(RLIMIT_DATA);
43438 if (rlim >= RLIM_INFINITY)
43439 rlim = ~0;
43440+
43441+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43442 if (ex.a_data + ex.a_bss > rlim)
43443 return -ENOMEM;
43444
43445@@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
43446 install_exec_creds(bprm);
43447 current->flags &= ~PF_FORKNOEXEC;
43448
43449+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43450+ current->mm->pax_flags = 0UL;
43451+#endif
43452+
43453+#ifdef CONFIG_PAX_PAGEEXEC
43454+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43455+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43456+
43457+#ifdef CONFIG_PAX_EMUTRAMP
43458+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43459+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43460+#endif
43461+
43462+#ifdef CONFIG_PAX_MPROTECT
43463+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43464+ current->mm->pax_flags |= MF_PAX_MPROTECT;
43465+#endif
43466+
43467+ }
43468+#endif
43469+
43470 if (N_MAGIC(ex) == OMAGIC) {
43471 unsigned long text_addr, map_size;
43472 loff_t pos;
43473@@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
43474
43475 down_write(&current->mm->mmap_sem);
43476 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43477- PROT_READ | PROT_WRITE | PROT_EXEC,
43478+ PROT_READ | PROT_WRITE,
43479 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43480 fd_offset + ex.a_text);
43481 up_write(&current->mm->mmap_sem);
43482diff -urNp linux-2.6.39.1/fs/binfmt_elf.c linux-2.6.39.1/fs/binfmt_elf.c
43483--- linux-2.6.39.1/fs/binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
43484+++ linux-2.6.39.1/fs/binfmt_elf.c 2011-05-22 19:41:37.000000000 -0400
43485@@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
43486 #define elf_core_dump NULL
43487 #endif
43488
43489+#ifdef CONFIG_PAX_MPROTECT
43490+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43491+#endif
43492+
43493 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43494 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43495 #else
43496@@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
43497 .load_binary = load_elf_binary,
43498 .load_shlib = load_elf_library,
43499 .core_dump = elf_core_dump,
43500+
43501+#ifdef CONFIG_PAX_MPROTECT
43502+ .handle_mprotect= elf_handle_mprotect,
43503+#endif
43504+
43505 .min_coredump = ELF_EXEC_PAGESIZE,
43506 };
43507
43508@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
43509
43510 static int set_brk(unsigned long start, unsigned long end)
43511 {
43512+ unsigned long e = end;
43513+
43514 start = ELF_PAGEALIGN(start);
43515 end = ELF_PAGEALIGN(end);
43516 if (end > start) {
43517@@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
43518 if (BAD_ADDR(addr))
43519 return addr;
43520 }
43521- current->mm->start_brk = current->mm->brk = end;
43522+ current->mm->start_brk = current->mm->brk = e;
43523 return 0;
43524 }
43525
43526@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
43527 elf_addr_t __user *u_rand_bytes;
43528 const char *k_platform = ELF_PLATFORM;
43529 const char *k_base_platform = ELF_BASE_PLATFORM;
43530- unsigned char k_rand_bytes[16];
43531+ u32 k_rand_bytes[4];
43532 int items;
43533 elf_addr_t *elf_info;
43534 int ei_index = 0;
43535 const struct cred *cred = current_cred();
43536 struct vm_area_struct *vma;
43537+ unsigned long saved_auxv[AT_VECTOR_SIZE];
43538+
43539+ pax_track_stack();
43540
43541 /*
43542 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43543@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
43544 * Generate 16 random bytes for userspace PRNG seeding.
43545 */
43546 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43547- u_rand_bytes = (elf_addr_t __user *)
43548- STACK_ALLOC(p, sizeof(k_rand_bytes));
43549+ srandom32(k_rand_bytes[0] ^ random32());
43550+ srandom32(k_rand_bytes[1] ^ random32());
43551+ srandom32(k_rand_bytes[2] ^ random32());
43552+ srandom32(k_rand_bytes[3] ^ random32());
43553+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
43554+ u_rand_bytes = (elf_addr_t __user *) p;
43555 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43556 return -EFAULT;
43557
43558@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
43559 return -EFAULT;
43560 current->mm->env_end = p;
43561
43562+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43563+
43564 /* Put the elf_info on the stack in the right place. */
43565 sp = (elf_addr_t __user *)envp + 1;
43566- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43567+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43568 return -EFAULT;
43569 return 0;
43570 }
43571@@ -381,10 +401,10 @@ static unsigned long load_elf_interp(str
43572 {
43573 struct elf_phdr *elf_phdata;
43574 struct elf_phdr *eppnt;
43575- unsigned long load_addr = 0;
43576+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43577 int load_addr_set = 0;
43578 unsigned long last_bss = 0, elf_bss = 0;
43579- unsigned long error = ~0UL;
43580+ unsigned long error = -EINVAL;
43581 unsigned long total_size;
43582 int retval, i, size;
43583
43584@@ -430,6 +450,11 @@ static unsigned long load_elf_interp(str
43585 goto out_close;
43586 }
43587
43588+#ifdef CONFIG_PAX_SEGMEXEC
43589+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43590+ pax_task_size = SEGMEXEC_TASK_SIZE;
43591+#endif
43592+
43593 eppnt = elf_phdata;
43594 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43595 if (eppnt->p_type == PT_LOAD) {
43596@@ -473,8 +498,8 @@ static unsigned long load_elf_interp(str
43597 k = load_addr + eppnt->p_vaddr;
43598 if (BAD_ADDR(k) ||
43599 eppnt->p_filesz > eppnt->p_memsz ||
43600- eppnt->p_memsz > TASK_SIZE ||
43601- TASK_SIZE - eppnt->p_memsz < k) {
43602+ eppnt->p_memsz > pax_task_size ||
43603+ pax_task_size - eppnt->p_memsz < k) {
43604 error = -ENOMEM;
43605 goto out_close;
43606 }
43607@@ -528,6 +553,193 @@ out:
43608 return error;
43609 }
43610
43611+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
43612+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
43613+{
43614+ unsigned long pax_flags = 0UL;
43615+
43616+#ifdef CONFIG_PAX_PAGEEXEC
43617+ if (elf_phdata->p_flags & PF_PAGEEXEC)
43618+ pax_flags |= MF_PAX_PAGEEXEC;
43619+#endif
43620+
43621+#ifdef CONFIG_PAX_SEGMEXEC
43622+ if (elf_phdata->p_flags & PF_SEGMEXEC)
43623+ pax_flags |= MF_PAX_SEGMEXEC;
43624+#endif
43625+
43626+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43627+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43628+ if ((__supported_pte_mask & _PAGE_NX))
43629+ pax_flags &= ~MF_PAX_SEGMEXEC;
43630+ else
43631+ pax_flags &= ~MF_PAX_PAGEEXEC;
43632+ }
43633+#endif
43634+
43635+#ifdef CONFIG_PAX_EMUTRAMP
43636+ if (elf_phdata->p_flags & PF_EMUTRAMP)
43637+ pax_flags |= MF_PAX_EMUTRAMP;
43638+#endif
43639+
43640+#ifdef CONFIG_PAX_MPROTECT
43641+ if (elf_phdata->p_flags & PF_MPROTECT)
43642+ pax_flags |= MF_PAX_MPROTECT;
43643+#endif
43644+
43645+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43646+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43647+ pax_flags |= MF_PAX_RANDMMAP;
43648+#endif
43649+
43650+ return pax_flags;
43651+}
43652+#endif
43653+
43654+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43655+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
43656+{
43657+ unsigned long pax_flags = 0UL;
43658+
43659+#ifdef CONFIG_PAX_PAGEEXEC
43660+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43661+ pax_flags |= MF_PAX_PAGEEXEC;
43662+#endif
43663+
43664+#ifdef CONFIG_PAX_SEGMEXEC
43665+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43666+ pax_flags |= MF_PAX_SEGMEXEC;
43667+#endif
43668+
43669+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43670+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43671+ if ((__supported_pte_mask & _PAGE_NX))
43672+ pax_flags &= ~MF_PAX_SEGMEXEC;
43673+ else
43674+ pax_flags &= ~MF_PAX_PAGEEXEC;
43675+ }
43676+#endif
43677+
43678+#ifdef CONFIG_PAX_EMUTRAMP
43679+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43680+ pax_flags |= MF_PAX_EMUTRAMP;
43681+#endif
43682+
43683+#ifdef CONFIG_PAX_MPROTECT
43684+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43685+ pax_flags |= MF_PAX_MPROTECT;
43686+#endif
43687+
43688+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43689+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43690+ pax_flags |= MF_PAX_RANDMMAP;
43691+#endif
43692+
43693+ return pax_flags;
43694+}
43695+#endif
43696+
43697+#ifdef CONFIG_PAX_EI_PAX
43698+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43699+{
43700+ unsigned long pax_flags = 0UL;
43701+
43702+#ifdef CONFIG_PAX_PAGEEXEC
43703+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43704+ pax_flags |= MF_PAX_PAGEEXEC;
43705+#endif
43706+
43707+#ifdef CONFIG_PAX_SEGMEXEC
43708+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43709+ pax_flags |= MF_PAX_SEGMEXEC;
43710+#endif
43711+
43712+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43713+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43714+ if ((__supported_pte_mask & _PAGE_NX))
43715+ pax_flags &= ~MF_PAX_SEGMEXEC;
43716+ else
43717+ pax_flags &= ~MF_PAX_PAGEEXEC;
43718+ }
43719+#endif
43720+
43721+#ifdef CONFIG_PAX_EMUTRAMP
43722+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43723+ pax_flags |= MF_PAX_EMUTRAMP;
43724+#endif
43725+
43726+#ifdef CONFIG_PAX_MPROTECT
43727+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43728+ pax_flags |= MF_PAX_MPROTECT;
43729+#endif
43730+
43731+#ifdef CONFIG_PAX_ASLR
43732+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43733+ pax_flags |= MF_PAX_RANDMMAP;
43734+#endif
43735+
43736+ return pax_flags;
43737+}
43738+#endif
43739+
43740+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43741+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43742+{
43743+ unsigned long pax_flags = 0UL;
43744+
43745+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43746+ unsigned long i;
43747+ int found_flags = 0;
43748+#endif
43749+
43750+#ifdef CONFIG_PAX_EI_PAX
43751+ pax_flags = pax_parse_ei_pax(elf_ex);
43752+#endif
43753+
43754+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43755+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43756+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43757+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43758+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43759+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43760+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43761+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43762+ return -EINVAL;
43763+
43764+#ifdef CONFIG_PAX_SOFTMODE
43765+ if (pax_softmode)
43766+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
43767+ else
43768+#endif
43769+
43770+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
43771+ found_flags = 1;
43772+ break;
43773+ }
43774+#endif
43775+
43776+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
43777+ if (found_flags == 0) {
43778+ struct elf_phdr phdr;
43779+ memset(&phdr, 0, sizeof(phdr));
43780+ phdr.p_flags = PF_NOEMUTRAMP;
43781+#ifdef CONFIG_PAX_SOFTMODE
43782+ if (pax_softmode)
43783+ pax_flags = pax_parse_softmode(&phdr);
43784+ else
43785+#endif
43786+ pax_flags = pax_parse_hardmode(&phdr);
43787+ }
43788+#endif
43789+
43790+ if (0 > pax_check_flags(&pax_flags))
43791+ return -EINVAL;
43792+
43793+ current->mm->pax_flags = pax_flags;
43794+ return 0;
43795+}
43796+#endif
43797+
43798 /*
43799 * These are the functions used to load ELF style executables and shared
43800 * libraries. There is no binary dependent code anywhere else.
43801@@ -544,6 +756,11 @@ static unsigned long randomize_stack_top
43802 {
43803 unsigned int random_variable = 0;
43804
43805+#ifdef CONFIG_PAX_RANDUSTACK
43806+ if (randomize_va_space)
43807+ return stack_top - current->mm->delta_stack;
43808+#endif
43809+
43810 if ((current->flags & PF_RANDOMIZE) &&
43811 !(current->personality & ADDR_NO_RANDOMIZE)) {
43812 random_variable = get_random_int() & STACK_RND_MASK;
43813@@ -562,7 +779,7 @@ static int load_elf_binary(struct linux_
43814 unsigned long load_addr = 0, load_bias = 0;
43815 int load_addr_set = 0;
43816 char * elf_interpreter = NULL;
43817- unsigned long error;
43818+ unsigned long error = 0;
43819 struct elf_phdr *elf_ppnt, *elf_phdata;
43820 unsigned long elf_bss, elf_brk;
43821 int retval, i;
43822@@ -572,11 +789,11 @@ static int load_elf_binary(struct linux_
43823 unsigned long start_code, end_code, start_data, end_data;
43824 unsigned long reloc_func_desc __maybe_unused = 0;
43825 int executable_stack = EXSTACK_DEFAULT;
43826- unsigned long def_flags = 0;
43827 struct {
43828 struct elfhdr elf_ex;
43829 struct elfhdr interp_elf_ex;
43830 } *loc;
43831+ unsigned long pax_task_size = TASK_SIZE;
43832
43833 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43834 if (!loc) {
43835@@ -714,11 +931,81 @@ static int load_elf_binary(struct linux_
43836
43837 /* OK, This is the point of no return */
43838 current->flags &= ~PF_FORKNOEXEC;
43839- current->mm->def_flags = def_flags;
43840+
43841+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43842+ current->mm->pax_flags = 0UL;
43843+#endif
43844+
43845+#ifdef CONFIG_PAX_DLRESOLVE
43846+ current->mm->call_dl_resolve = 0UL;
43847+#endif
43848+
43849+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43850+ current->mm->call_syscall = 0UL;
43851+#endif
43852+
43853+#ifdef CONFIG_PAX_ASLR
43854+ current->mm->delta_mmap = 0UL;
43855+ current->mm->delta_stack = 0UL;
43856+#endif
43857+
43858+ current->mm->def_flags = 0;
43859+
43860+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43861+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
43862+ send_sig(SIGKILL, current, 0);
43863+ goto out_free_dentry;
43864+ }
43865+#endif
43866+
43867+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43868+ pax_set_initial_flags(bprm);
43869+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43870+ if (pax_set_initial_flags_func)
43871+ (pax_set_initial_flags_func)(bprm);
43872+#endif
43873+
43874+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43875+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43876+ current->mm->context.user_cs_limit = PAGE_SIZE;
43877+ current->mm->def_flags |= VM_PAGEEXEC;
43878+ }
43879+#endif
43880+
43881+#ifdef CONFIG_PAX_SEGMEXEC
43882+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43883+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43884+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43885+ pax_task_size = SEGMEXEC_TASK_SIZE;
43886+ current->mm->def_flags |= VM_NOHUGEPAGE;
43887+ }
43888+#endif
43889+
43890+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43891+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43892+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43893+ put_cpu();
43894+ }
43895+#endif
43896
43897 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43898 may depend on the personality. */
43899 SET_PERSONALITY(loc->elf_ex);
43900+
43901+#ifdef CONFIG_PAX_ASLR
43902+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43903+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43904+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43905+ }
43906+#endif
43907+
43908+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43909+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43910+ executable_stack = EXSTACK_DISABLE_X;
43911+ current->personality &= ~READ_IMPLIES_EXEC;
43912+ } else
43913+#endif
43914+
43915 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43916 current->personality |= READ_IMPLIES_EXEC;
43917
43918@@ -800,6 +1087,20 @@ static int load_elf_binary(struct linux_
43919 #else
43920 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43921 #endif
43922+
43923+#ifdef CONFIG_PAX_RANDMMAP
43924+ /* PaX: randomize base address at the default exe base if requested */
43925+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43926+#ifdef CONFIG_SPARC64
43927+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43928+#else
43929+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43930+#endif
43931+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43932+ elf_flags |= MAP_FIXED;
43933+ }
43934+#endif
43935+
43936 }
43937
43938 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43939@@ -832,9 +1133,9 @@ static int load_elf_binary(struct linux_
43940 * allowed task size. Note that p_filesz must always be
43941 * <= p_memsz so it is only necessary to check p_memsz.
43942 */
43943- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43944- elf_ppnt->p_memsz > TASK_SIZE ||
43945- TASK_SIZE - elf_ppnt->p_memsz < k) {
43946+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43947+ elf_ppnt->p_memsz > pax_task_size ||
43948+ pax_task_size - elf_ppnt->p_memsz < k) {
43949 /* set_brk can never work. Avoid overflows. */
43950 send_sig(SIGKILL, current, 0);
43951 retval = -EINVAL;
43952@@ -862,6 +1163,11 @@ static int load_elf_binary(struct linux_
43953 start_data += load_bias;
43954 end_data += load_bias;
43955
43956+#ifdef CONFIG_PAX_RANDMMAP
43957+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
43958+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
43959+#endif
43960+
43961 /* Calling set_brk effectively mmaps the pages that we need
43962 * for the bss and break sections. We must do this before
43963 * mapping in the interpreter, to make sure it doesn't wind
43964@@ -873,9 +1179,11 @@ static int load_elf_binary(struct linux_
43965 goto out_free_dentry;
43966 }
43967 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43968- send_sig(SIGSEGV, current, 0);
43969- retval = -EFAULT; /* Nobody gets to see this, but.. */
43970- goto out_free_dentry;
43971+ /*
43972+ * This bss-zeroing can fail if the ELF
43973+ * file specifies odd protections. So
43974+ * we don't check the return value
43975+ */
43976 }
43977
43978 if (elf_interpreter) {
43979@@ -1090,7 +1398,7 @@ out:
43980 * Decide what to dump of a segment, part, all or none.
43981 */
43982 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43983- unsigned long mm_flags)
43984+ unsigned long mm_flags, long signr)
43985 {
43986 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43987
43988@@ -1124,7 +1432,7 @@ static unsigned long vma_dump_size(struc
43989 if (vma->vm_file == NULL)
43990 return 0;
43991
43992- if (FILTER(MAPPED_PRIVATE))
43993+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43994 goto whole;
43995
43996 /*
43997@@ -1346,9 +1654,9 @@ static void fill_auxv_note(struct memelf
43998 {
43999 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
44000 int i = 0;
44001- do
44002+ do {
44003 i += 2;
44004- while (auxv[i - 2] != AT_NULL);
44005+ } while (auxv[i - 2] != AT_NULL);
44006 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
44007 }
44008
44009@@ -1854,14 +2162,14 @@ static void fill_extnum_info(struct elfh
44010 }
44011
44012 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
44013- unsigned long mm_flags)
44014+ struct coredump_params *cprm)
44015 {
44016 struct vm_area_struct *vma;
44017 size_t size = 0;
44018
44019 for (vma = first_vma(current, gate_vma); vma != NULL;
44020 vma = next_vma(vma, gate_vma))
44021- size += vma_dump_size(vma, mm_flags);
44022+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44023 return size;
44024 }
44025
44026@@ -1955,7 +2263,7 @@ static int elf_core_dump(struct coredump
44027
44028 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
44029
44030- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
44031+ offset += elf_core_vma_data_size(gate_vma, cprm);
44032 offset += elf_core_extra_data_size();
44033 e_shoff = offset;
44034
44035@@ -1969,10 +2277,12 @@ static int elf_core_dump(struct coredump
44036 offset = dataoff;
44037
44038 size += sizeof(*elf);
44039+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44040 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
44041 goto end_coredump;
44042
44043 size += sizeof(*phdr4note);
44044+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44045 if (size > cprm->limit
44046 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44047 goto end_coredump;
44048@@ -1986,7 +2296,7 @@ static int elf_core_dump(struct coredump
44049 phdr.p_offset = offset;
44050 phdr.p_vaddr = vma->vm_start;
44051 phdr.p_paddr = 0;
44052- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44053+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44054 phdr.p_memsz = vma->vm_end - vma->vm_start;
44055 offset += phdr.p_filesz;
44056 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44057@@ -1997,6 +2307,7 @@ static int elf_core_dump(struct coredump
44058 phdr.p_align = ELF_EXEC_PAGESIZE;
44059
44060 size += sizeof(phdr);
44061+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44062 if (size > cprm->limit
44063 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44064 goto end_coredump;
44065@@ -2021,7 +2332,7 @@ static int elf_core_dump(struct coredump
44066 unsigned long addr;
44067 unsigned long end;
44068
44069- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44070+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44071
44072 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44073 struct page *page;
44074@@ -2030,6 +2341,7 @@ static int elf_core_dump(struct coredump
44075 page = get_dump_page(addr);
44076 if (page) {
44077 void *kaddr = kmap(page);
44078+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44079 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44080 !dump_write(cprm->file, kaddr,
44081 PAGE_SIZE);
44082@@ -2047,6 +2359,7 @@ static int elf_core_dump(struct coredump
44083
44084 if (e_phnum == PN_XNUM) {
44085 size += sizeof(*shdr4extnum);
44086+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44087 if (size > cprm->limit
44088 || !dump_write(cprm->file, shdr4extnum,
44089 sizeof(*shdr4extnum)))
44090@@ -2067,6 +2380,97 @@ out:
44091
44092 #endif /* CONFIG_ELF_CORE */
44093
44094+#ifdef CONFIG_PAX_MPROTECT
44095+/* PaX: non-PIC ELF libraries need relocations on their executable segments
44096+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44097+ * we'll remove VM_MAYWRITE for good on RELRO segments.
44098+ *
44099+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44100+ * basis because we want to allow the common case and not the special ones.
44101+ */
44102+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44103+{
44104+ struct elfhdr elf_h;
44105+ struct elf_phdr elf_p;
44106+ unsigned long i;
44107+ unsigned long oldflags;
44108+ bool is_textrel_rw, is_textrel_rx, is_relro;
44109+
44110+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44111+ return;
44112+
44113+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44114+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44115+
44116+#ifdef CONFIG_PAX_ELFRELOCS
44117+ /* possible TEXTREL */
44118+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44119+ is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
44120+#else
44121+ is_textrel_rw = false;
44122+ is_textrel_rx = false;
44123+#endif
44124+
44125+ /* possible RELRO */
44126+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44127+
44128+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44129+ return;
44130+
44131+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44132+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44133+
44134+#ifdef CONFIG_PAX_ETEXECRELOCS
44135+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44136+#else
44137+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44138+#endif
44139+
44140+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44141+ !elf_check_arch(&elf_h) ||
44142+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44143+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44144+ return;
44145+
44146+ for (i = 0UL; i < elf_h.e_phnum; i++) {
44147+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44148+ return;
44149+ switch (elf_p.p_type) {
44150+ case PT_DYNAMIC:
44151+ if (!is_textrel_rw && !is_textrel_rx)
44152+ continue;
44153+ i = 0UL;
44154+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44155+ elf_dyn dyn;
44156+
44157+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44158+ return;
44159+ if (dyn.d_tag == DT_NULL)
44160+ return;
44161+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44162+ gr_log_textrel(vma);
44163+ if (is_textrel_rw)
44164+ vma->vm_flags |= VM_MAYWRITE;
44165+ else
44166+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44167+ vma->vm_flags &= ~VM_MAYWRITE;
44168+ return;
44169+ }
44170+ i++;
44171+ }
44172+ return;
44173+
44174+ case PT_GNU_RELRO:
44175+ if (!is_relro)
44176+ continue;
44177+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44178+ vma->vm_flags &= ~VM_MAYWRITE;
44179+ return;
44180+ }
44181+ }
44182+}
44183+#endif
44184+
44185 static int __init init_elf_binfmt(void)
44186 {
44187 return register_binfmt(&elf_format);
44188diff -urNp linux-2.6.39.1/fs/binfmt_flat.c linux-2.6.39.1/fs/binfmt_flat.c
44189--- linux-2.6.39.1/fs/binfmt_flat.c 2011-05-19 00:06:34.000000000 -0400
44190+++ linux-2.6.39.1/fs/binfmt_flat.c 2011-05-22 19:36:32.000000000 -0400
44191@@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
44192 realdatastart = (unsigned long) -ENOMEM;
44193 printk("Unable to allocate RAM for process data, errno %d\n",
44194 (int)-realdatastart);
44195+ down_write(&current->mm->mmap_sem);
44196 do_munmap(current->mm, textpos, text_len);
44197+ up_write(&current->mm->mmap_sem);
44198 ret = realdatastart;
44199 goto err;
44200 }
44201@@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
44202 }
44203 if (IS_ERR_VALUE(result)) {
44204 printk("Unable to read data+bss, errno %d\n", (int)-result);
44205+ down_write(&current->mm->mmap_sem);
44206 do_munmap(current->mm, textpos, text_len);
44207 do_munmap(current->mm, realdatastart, len);
44208+ up_write(&current->mm->mmap_sem);
44209 ret = result;
44210 goto err;
44211 }
44212@@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
44213 }
44214 if (IS_ERR_VALUE(result)) {
44215 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44216+ down_write(&current->mm->mmap_sem);
44217 do_munmap(current->mm, textpos, text_len + data_len + extra +
44218 MAX_SHARED_LIBS * sizeof(unsigned long));
44219+ up_write(&current->mm->mmap_sem);
44220 ret = result;
44221 goto err;
44222 }
44223diff -urNp linux-2.6.39.1/fs/bio.c linux-2.6.39.1/fs/bio.c
44224--- linux-2.6.39.1/fs/bio.c 2011-05-19 00:06:34.000000000 -0400
44225+++ linux-2.6.39.1/fs/bio.c 2011-05-22 19:36:32.000000000 -0400
44226@@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
44227 const int read = bio_data_dir(bio) == READ;
44228 struct bio_map_data *bmd = bio->bi_private;
44229 int i;
44230- char *p = bmd->sgvecs[0].iov_base;
44231+ char *p = (__force char *)bmd->sgvecs[0].iov_base;
44232
44233 __bio_for_each_segment(bvec, bio, i, 0) {
44234 char *addr = page_address(bvec->bv_page);
44235diff -urNp linux-2.6.39.1/fs/block_dev.c linux-2.6.39.1/fs/block_dev.c
44236--- linux-2.6.39.1/fs/block_dev.c 2011-06-03 00:04:14.000000000 -0400
44237+++ linux-2.6.39.1/fs/block_dev.c 2011-06-06 19:57:05.000000000 -0400
44238@@ -671,7 +671,7 @@ static bool bd_may_claim(struct block_de
44239 else if (bdev->bd_contains == bdev)
44240 return true; /* is a whole device which isn't held */
44241
44242- else if (whole->bd_holder == bd_may_claim)
44243+ else if (whole->bd_holder == (void *)bd_may_claim)
44244 return true; /* is a partition of a device that is being partitioned */
44245 else if (whole->bd_holder != NULL)
44246 return false; /* is a partition of a held device */
44247@@ -1272,8 +1272,8 @@ int blkdev_get(struct block_device *bdev
44248 * individual writeable reference is too fragile given the
44249 * way @mode is used in blkdev_get/put().
44250 */
44251- if ((disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE) &&
44252- !res && (mode & FMODE_WRITE) && !bdev->bd_write_holder) {
44253+ if (!res && (mode & FMODE_WRITE) && !bdev->bd_write_holder &&
44254+ (disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE)) {
44255 bdev->bd_write_holder = true;
44256 disk_block_events(disk);
44257 }
44258diff -urNp linux-2.6.39.1/fs/btrfs/compression.c linux-2.6.39.1/fs/btrfs/compression.c
44259--- linux-2.6.39.1/fs/btrfs/compression.c 2011-05-19 00:06:34.000000000 -0400
44260+++ linux-2.6.39.1/fs/btrfs/compression.c 2011-05-22 19:36:32.000000000 -0400
44261@@ -719,7 +719,7 @@ static int comp_num_workspace[BTRFS_COMP
44262 static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
44263 static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
44264
44265-struct btrfs_compress_op *btrfs_compress_op[] = {
44266+const struct btrfs_compress_op *btrfs_compress_op[] = {
44267 &btrfs_zlib_compress,
44268 &btrfs_lzo_compress,
44269 };
44270diff -urNp linux-2.6.39.1/fs/btrfs/compression.h linux-2.6.39.1/fs/btrfs/compression.h
44271--- linux-2.6.39.1/fs/btrfs/compression.h 2011-05-19 00:06:34.000000000 -0400
44272+++ linux-2.6.39.1/fs/btrfs/compression.h 2011-05-22 19:36:32.000000000 -0400
44273@@ -77,7 +77,7 @@ struct btrfs_compress_op {
44274 size_t srclen, size_t destlen);
44275 };
44276
44277-extern struct btrfs_compress_op btrfs_zlib_compress;
44278-extern struct btrfs_compress_op btrfs_lzo_compress;
44279+extern const struct btrfs_compress_op btrfs_zlib_compress;
44280+extern const struct btrfs_compress_op btrfs_lzo_compress;
44281
44282 #endif
44283diff -urNp linux-2.6.39.1/fs/btrfs/ctree.c linux-2.6.39.1/fs/btrfs/ctree.c
44284--- linux-2.6.39.1/fs/btrfs/ctree.c 2011-05-19 00:06:34.000000000 -0400
44285+++ linux-2.6.39.1/fs/btrfs/ctree.c 2011-05-22 19:36:32.000000000 -0400
44286@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
44287 free_extent_buffer(buf);
44288 add_root_to_dirty_list(root);
44289 } else {
44290- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44291- parent_start = parent->start;
44292- else
44293+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44294+ if (parent)
44295+ parent_start = parent->start;
44296+ else
44297+ parent_start = 0;
44298+ } else
44299 parent_start = 0;
44300
44301 WARN_ON(trans->transid != btrfs_header_generation(parent));
44302@@ -3647,7 +3650,6 @@ setup_items_for_insert(struct btrfs_tran
44303
44304 ret = 0;
44305 if (slot == 0) {
44306- struct btrfs_disk_key disk_key;
44307 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
44308 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
44309 }
44310diff -urNp linux-2.6.39.1/fs/btrfs/disk-io.c linux-2.6.39.1/fs/btrfs/disk-io.c
44311--- linux-2.6.39.1/fs/btrfs/disk-io.c 2011-05-19 00:06:34.000000000 -0400
44312+++ linux-2.6.39.1/fs/btrfs/disk-io.c 2011-05-22 19:36:32.000000000 -0400
44313@@ -42,7 +42,7 @@
44314 #include "tree-log.h"
44315 #include "free-space-cache.h"
44316
44317-static struct extent_io_ops btree_extent_io_ops;
44318+static const struct extent_io_ops btree_extent_io_ops;
44319 static void end_workqueue_fn(struct btrfs_work *work);
44320 static void free_fs_root(struct btrfs_root *root);
44321 static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
44322@@ -3070,7 +3070,7 @@ static int btrfs_cleanup_transaction(str
44323 return 0;
44324 }
44325
44326-static struct extent_io_ops btree_extent_io_ops = {
44327+static const struct extent_io_ops btree_extent_io_ops = {
44328 .write_cache_pages_lock_hook = btree_lock_page_hook,
44329 .readpage_end_io_hook = btree_readpage_end_io_hook,
44330 .submit_bio_hook = btree_submit_bio_hook,
44331diff -urNp linux-2.6.39.1/fs/btrfs/extent_io.h linux-2.6.39.1/fs/btrfs/extent_io.h
44332--- linux-2.6.39.1/fs/btrfs/extent_io.h 2011-05-19 00:06:34.000000000 -0400
44333+++ linux-2.6.39.1/fs/btrfs/extent_io.h 2011-05-22 19:36:32.000000000 -0400
44334@@ -56,36 +56,36 @@ typedef int (extent_submit_bio_hook_t)(s
44335 struct bio *bio, int mirror_num,
44336 unsigned long bio_flags, u64 bio_offset);
44337 struct extent_io_ops {
44338- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
44339+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
44340 u64 start, u64 end, int *page_started,
44341 unsigned long *nr_written);
44342- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
44343- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
44344+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
44345+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
44346 extent_submit_bio_hook_t *submit_bio_hook;
44347- int (*merge_bio_hook)(struct page *page, unsigned long offset,
44348+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
44349 size_t size, struct bio *bio,
44350 unsigned long bio_flags);
44351- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
44352- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
44353+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
44354+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
44355 u64 start, u64 end,
44356 struct extent_state *state);
44357- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
44358+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
44359 u64 start, u64 end,
44360 struct extent_state *state);
44361- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44362+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44363 struct extent_state *state);
44364- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44365+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44366 struct extent_state *state, int uptodate);
44367- int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
44368+ int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
44369 int *bits);
44370- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
44371+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
44372 int *bits);
44373- int (*merge_extent_hook)(struct inode *inode,
44374+ int (* const merge_extent_hook)(struct inode *inode,
44375 struct extent_state *new,
44376 struct extent_state *other);
44377- int (*split_extent_hook)(struct inode *inode,
44378+ int (* const split_extent_hook)(struct inode *inode,
44379 struct extent_state *orig, u64 split);
44380- int (*write_cache_pages_lock_hook)(struct page *page);
44381+ int (* const write_cache_pages_lock_hook)(struct page *page);
44382 };
44383
44384 struct extent_io_tree {
44385@@ -95,7 +95,7 @@ struct extent_io_tree {
44386 u64 dirty_bytes;
44387 spinlock_t lock;
44388 spinlock_t buffer_lock;
44389- struct extent_io_ops *ops;
44390+ const struct extent_io_ops *ops;
44391 };
44392
44393 struct extent_state {
44394diff -urNp linux-2.6.39.1/fs/btrfs/free-space-cache.c linux-2.6.39.1/fs/btrfs/free-space-cache.c
44395--- linux-2.6.39.1/fs/btrfs/free-space-cache.c 2011-05-19 00:06:34.000000000 -0400
44396+++ linux-2.6.39.1/fs/btrfs/free-space-cache.c 2011-05-22 19:36:32.000000000 -0400
44397@@ -1910,8 +1910,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44398 while(1) {
44399 if (entry->bytes < bytes ||
44400 (!entry->bitmap && entry->offset < min_start)) {
44401- struct rb_node *node;
44402-
44403 node = rb_next(&entry->offset_index);
44404 if (!node)
44405 break;
44406@@ -1925,7 +1923,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44407 cluster, entry, bytes,
44408 min_start);
44409 if (ret == 0) {
44410- struct rb_node *node;
44411 node = rb_next(&entry->offset_index);
44412 if (!node)
44413 break;
44414diff -urNp linux-2.6.39.1/fs/btrfs/inode.c linux-2.6.39.1/fs/btrfs/inode.c
44415--- linux-2.6.39.1/fs/btrfs/inode.c 2011-05-19 00:06:34.000000000 -0400
44416+++ linux-2.6.39.1/fs/btrfs/inode.c 2011-05-22 20:42:42.000000000 -0400
44417@@ -65,7 +65,7 @@ static const struct inode_operations btr
44418 static const struct address_space_operations btrfs_aops;
44419 static const struct address_space_operations btrfs_symlink_aops;
44420 static const struct file_operations btrfs_dir_file_operations;
44421-static struct extent_io_ops btrfs_extent_io_ops;
44422+static const struct extent_io_ops btrfs_extent_io_ops;
44423
44424 static struct kmem_cache *btrfs_inode_cachep;
44425 struct kmem_cache *btrfs_trans_handle_cachep;
44426@@ -6947,7 +6947,7 @@ fail:
44427 return -ENOMEM;
44428 }
44429
44430-static int btrfs_getattr(struct vfsmount *mnt,
44431+int btrfs_getattr(struct vfsmount *mnt,
44432 struct dentry *dentry, struct kstat *stat)
44433 {
44434 struct inode *inode = dentry->d_inode;
44435@@ -6959,6 +6959,14 @@ static int btrfs_getattr(struct vfsmount
44436 return 0;
44437 }
44438
44439+EXPORT_SYMBOL(btrfs_getattr);
44440+
44441+dev_t get_btrfs_dev_from_inode(struct inode *inode)
44442+{
44443+ return BTRFS_I(inode)->root->anon_super.s_dev;
44444+}
44445+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44446+
44447 /*
44448 * If a file is moved, it will inherit the cow and compression flags of the new
44449 * directory.
44450@@ -7488,7 +7496,7 @@ static const struct file_operations btrf
44451 .fsync = btrfs_sync_file,
44452 };
44453
44454-static struct extent_io_ops btrfs_extent_io_ops = {
44455+static const struct extent_io_ops btrfs_extent_io_ops = {
44456 .fill_delalloc = run_delalloc_range,
44457 .submit_bio_hook = btrfs_submit_bio_hook,
44458 .merge_bio_hook = btrfs_merge_bio_hook,
44459diff -urNp linux-2.6.39.1/fs/btrfs/ioctl.c linux-2.6.39.1/fs/btrfs/ioctl.c
44460--- linux-2.6.39.1/fs/btrfs/ioctl.c 2011-05-19 00:06:34.000000000 -0400
44461+++ linux-2.6.39.1/fs/btrfs/ioctl.c 2011-05-22 19:41:37.000000000 -0400
44462@@ -2361,9 +2361,12 @@ long btrfs_ioctl_space_info(struct btrfs
44463 for (i = 0; i < num_types; i++) {
44464 struct btrfs_space_info *tmp;
44465
44466+ /* Don't copy in more than we allocated */
44467 if (!slot_count)
44468 break;
44469
44470+ slot_count--;
44471+
44472 info = NULL;
44473 rcu_read_lock();
44474 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44475@@ -2385,10 +2388,7 @@ long btrfs_ioctl_space_info(struct btrfs
44476 memcpy(dest, &space, sizeof(space));
44477 dest++;
44478 space_args.total_spaces++;
44479- slot_count--;
44480 }
44481- if (!slot_count)
44482- break;
44483 }
44484 up_read(&info->groups_sem);
44485 }
44486diff -urNp linux-2.6.39.1/fs/btrfs/lzo.c linux-2.6.39.1/fs/btrfs/lzo.c
44487--- linux-2.6.39.1/fs/btrfs/lzo.c 2011-05-19 00:06:34.000000000 -0400
44488+++ linux-2.6.39.1/fs/btrfs/lzo.c 2011-05-22 19:36:32.000000000 -0400
44489@@ -418,7 +418,7 @@ out:
44490 return ret;
44491 }
44492
44493-struct btrfs_compress_op btrfs_lzo_compress = {
44494+const struct btrfs_compress_op btrfs_lzo_compress = {
44495 .alloc_workspace = lzo_alloc_workspace,
44496 .free_workspace = lzo_free_workspace,
44497 .compress_pages = lzo_compress_pages,
44498diff -urNp linux-2.6.39.1/fs/btrfs/relocation.c linux-2.6.39.1/fs/btrfs/relocation.c
44499--- linux-2.6.39.1/fs/btrfs/relocation.c 2011-05-19 00:06:34.000000000 -0400
44500+++ linux-2.6.39.1/fs/btrfs/relocation.c 2011-05-22 19:36:32.000000000 -0400
44501@@ -1239,7 +1239,7 @@ static int __update_reloc_root(struct bt
44502 }
44503 spin_unlock(&rc->reloc_root_tree.lock);
44504
44505- BUG_ON((struct btrfs_root *)node->data != root);
44506+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
44507
44508 if (!del) {
44509 spin_lock(&rc->reloc_root_tree.lock);
44510diff -urNp linux-2.6.39.1/fs/btrfs/zlib.c linux-2.6.39.1/fs/btrfs/zlib.c
44511--- linux-2.6.39.1/fs/btrfs/zlib.c 2011-05-19 00:06:34.000000000 -0400
44512+++ linux-2.6.39.1/fs/btrfs/zlib.c 2011-05-22 19:36:32.000000000 -0400
44513@@ -390,7 +390,7 @@ next:
44514 return ret;
44515 }
44516
44517-struct btrfs_compress_op btrfs_zlib_compress = {
44518+const struct btrfs_compress_op btrfs_zlib_compress = {
44519 .alloc_workspace = zlib_alloc_workspace,
44520 .free_workspace = zlib_free_workspace,
44521 .compress_pages = zlib_compress_pages,
44522diff -urNp linux-2.6.39.1/fs/cachefiles/bind.c linux-2.6.39.1/fs/cachefiles/bind.c
44523--- linux-2.6.39.1/fs/cachefiles/bind.c 2011-05-19 00:06:34.000000000 -0400
44524+++ linux-2.6.39.1/fs/cachefiles/bind.c 2011-05-22 19:36:32.000000000 -0400
44525@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
44526 args);
44527
44528 /* start by checking things over */
44529- ASSERT(cache->fstop_percent >= 0 &&
44530- cache->fstop_percent < cache->fcull_percent &&
44531+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
44532 cache->fcull_percent < cache->frun_percent &&
44533 cache->frun_percent < 100);
44534
44535- ASSERT(cache->bstop_percent >= 0 &&
44536- cache->bstop_percent < cache->bcull_percent &&
44537+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
44538 cache->bcull_percent < cache->brun_percent &&
44539 cache->brun_percent < 100);
44540
44541diff -urNp linux-2.6.39.1/fs/cachefiles/daemon.c linux-2.6.39.1/fs/cachefiles/daemon.c
44542--- linux-2.6.39.1/fs/cachefiles/daemon.c 2011-05-19 00:06:34.000000000 -0400
44543+++ linux-2.6.39.1/fs/cachefiles/daemon.c 2011-05-22 19:36:32.000000000 -0400
44544@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
44545 if (n > buflen)
44546 return -EMSGSIZE;
44547
44548- if (copy_to_user(_buffer, buffer, n) != 0)
44549+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44550 return -EFAULT;
44551
44552 return n;
44553@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
44554 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44555 return -EIO;
44556
44557- if (datalen < 0 || datalen > PAGE_SIZE - 1)
44558+ if (datalen > PAGE_SIZE - 1)
44559 return -EOPNOTSUPP;
44560
44561 /* drag the command string into the kernel so we can parse it */
44562@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
44563 if (args[0] != '%' || args[1] != '\0')
44564 return -EINVAL;
44565
44566- if (fstop < 0 || fstop >= cache->fcull_percent)
44567+ if (fstop >= cache->fcull_percent)
44568 return cachefiles_daemon_range_error(cache, args);
44569
44570 cache->fstop_percent = fstop;
44571@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
44572 if (args[0] != '%' || args[1] != '\0')
44573 return -EINVAL;
44574
44575- if (bstop < 0 || bstop >= cache->bcull_percent)
44576+ if (bstop >= cache->bcull_percent)
44577 return cachefiles_daemon_range_error(cache, args);
44578
44579 cache->bstop_percent = bstop;
44580diff -urNp linux-2.6.39.1/fs/cachefiles/internal.h linux-2.6.39.1/fs/cachefiles/internal.h
44581--- linux-2.6.39.1/fs/cachefiles/internal.h 2011-05-19 00:06:34.000000000 -0400
44582+++ linux-2.6.39.1/fs/cachefiles/internal.h 2011-05-22 19:36:32.000000000 -0400
44583@@ -57,7 +57,7 @@ struct cachefiles_cache {
44584 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44585 struct rb_root active_nodes; /* active nodes (can't be culled) */
44586 rwlock_t active_lock; /* lock for active_nodes */
44587- atomic_t gravecounter; /* graveyard uniquifier */
44588+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44589 unsigned frun_percent; /* when to stop culling (% files) */
44590 unsigned fcull_percent; /* when to start culling (% files) */
44591 unsigned fstop_percent; /* when to stop allocating (% files) */
44592@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struc
44593 * proc.c
44594 */
44595 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44596-extern atomic_t cachefiles_lookup_histogram[HZ];
44597-extern atomic_t cachefiles_mkdir_histogram[HZ];
44598-extern atomic_t cachefiles_create_histogram[HZ];
44599+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44600+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44601+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44602
44603 extern int __init cachefiles_proc_init(void);
44604 extern void cachefiles_proc_cleanup(void);
44605 static inline
44606-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44607+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44608 {
44609 unsigned long jif = jiffies - start_jif;
44610 if (jif >= HZ)
44611 jif = HZ - 1;
44612- atomic_inc(&histogram[jif]);
44613+ atomic_inc_unchecked(&histogram[jif]);
44614 }
44615
44616 #else
44617diff -urNp linux-2.6.39.1/fs/cachefiles/namei.c linux-2.6.39.1/fs/cachefiles/namei.c
44618--- linux-2.6.39.1/fs/cachefiles/namei.c 2011-05-19 00:06:34.000000000 -0400
44619+++ linux-2.6.39.1/fs/cachefiles/namei.c 2011-05-22 19:36:32.000000000 -0400
44620@@ -318,7 +318,7 @@ try_again:
44621 /* first step is to make up a grave dentry in the graveyard */
44622 sprintf(nbuffer, "%08x%08x",
44623 (uint32_t) get_seconds(),
44624- (uint32_t) atomic_inc_return(&cache->gravecounter));
44625+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44626
44627 /* do the multiway lock magic */
44628 trap = lock_rename(cache->graveyard, dir);
44629diff -urNp linux-2.6.39.1/fs/cachefiles/proc.c linux-2.6.39.1/fs/cachefiles/proc.c
44630--- linux-2.6.39.1/fs/cachefiles/proc.c 2011-05-19 00:06:34.000000000 -0400
44631+++ linux-2.6.39.1/fs/cachefiles/proc.c 2011-05-22 19:36:32.000000000 -0400
44632@@ -14,9 +14,9 @@
44633 #include <linux/seq_file.h>
44634 #include "internal.h"
44635
44636-atomic_t cachefiles_lookup_histogram[HZ];
44637-atomic_t cachefiles_mkdir_histogram[HZ];
44638-atomic_t cachefiles_create_histogram[HZ];
44639+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44640+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44641+atomic_unchecked_t cachefiles_create_histogram[HZ];
44642
44643 /*
44644 * display the latency histogram
44645@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
44646 return 0;
44647 default:
44648 index = (unsigned long) v - 3;
44649- x = atomic_read(&cachefiles_lookup_histogram[index]);
44650- y = atomic_read(&cachefiles_mkdir_histogram[index]);
44651- z = atomic_read(&cachefiles_create_histogram[index]);
44652+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44653+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44654+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44655 if (x == 0 && y == 0 && z == 0)
44656 return 0;
44657
44658diff -urNp linux-2.6.39.1/fs/cachefiles/rdwr.c linux-2.6.39.1/fs/cachefiles/rdwr.c
44659--- linux-2.6.39.1/fs/cachefiles/rdwr.c 2011-05-19 00:06:34.000000000 -0400
44660+++ linux-2.6.39.1/fs/cachefiles/rdwr.c 2011-05-22 19:36:32.000000000 -0400
44661@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
44662 old_fs = get_fs();
44663 set_fs(KERNEL_DS);
44664 ret = file->f_op->write(
44665- file, (const void __user *) data, len, &pos);
44666+ file, (__force const void __user *) data, len, &pos);
44667 set_fs(old_fs);
44668 kunmap(page);
44669 if (ret != len)
44670diff -urNp linux-2.6.39.1/fs/ceph/addr.c linux-2.6.39.1/fs/ceph/addr.c
44671--- linux-2.6.39.1/fs/ceph/addr.c 2011-05-19 00:06:34.000000000 -0400
44672+++ linux-2.6.39.1/fs/ceph/addr.c 2011-05-22 19:36:32.000000000 -0400
44673@@ -1164,7 +1164,7 @@ out:
44674 return ret;
44675 }
44676
44677-static struct vm_operations_struct ceph_vmops = {
44678+static const struct vm_operations_struct ceph_vmops = {
44679 .fault = filemap_fault,
44680 .page_mkwrite = ceph_page_mkwrite,
44681 };
44682diff -urNp linux-2.6.39.1/fs/ceph/dir.c linux-2.6.39.1/fs/ceph/dir.c
44683--- linux-2.6.39.1/fs/ceph/dir.c 2011-05-19 00:06:34.000000000 -0400
44684+++ linux-2.6.39.1/fs/ceph/dir.c 2011-05-22 19:36:32.000000000 -0400
44685@@ -226,7 +226,7 @@ static int ceph_readdir(struct file *fil
44686 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44687 struct ceph_mds_client *mdsc = fsc->mdsc;
44688 unsigned frag = fpos_frag(filp->f_pos);
44689- int off = fpos_off(filp->f_pos);
44690+ unsigned int off = fpos_off(filp->f_pos);
44691 int err;
44692 u32 ftype;
44693 struct ceph_mds_reply_info_parsed *rinfo;
44694@@ -360,7 +360,7 @@ more:
44695 rinfo = &fi->last_readdir->r_reply_info;
44696 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
44697 rinfo->dir_nr, off, fi->offset);
44698- while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
44699+ while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
44700 u64 pos = ceph_make_fpos(frag, off);
44701 struct ceph_mds_reply_inode *in =
44702 rinfo->dir_in[off - fi->offset].in;
44703diff -urNp linux-2.6.39.1/fs/cifs/cifs_debug.c linux-2.6.39.1/fs/cifs/cifs_debug.c
44704--- linux-2.6.39.1/fs/cifs/cifs_debug.c 2011-05-19 00:06:34.000000000 -0400
44705+++ linux-2.6.39.1/fs/cifs/cifs_debug.c 2011-05-22 19:36:32.000000000 -0400
44706@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(str
44707 tcon = list_entry(tmp3,
44708 struct cifsTconInfo,
44709 tcon_list);
44710- atomic_set(&tcon->num_smbs_sent, 0);
44711- atomic_set(&tcon->num_writes, 0);
44712- atomic_set(&tcon->num_reads, 0);
44713- atomic_set(&tcon->num_oplock_brks, 0);
44714- atomic_set(&tcon->num_opens, 0);
44715- atomic_set(&tcon->num_posixopens, 0);
44716- atomic_set(&tcon->num_posixmkdirs, 0);
44717- atomic_set(&tcon->num_closes, 0);
44718- atomic_set(&tcon->num_deletes, 0);
44719- atomic_set(&tcon->num_mkdirs, 0);
44720- atomic_set(&tcon->num_rmdirs, 0);
44721- atomic_set(&tcon->num_renames, 0);
44722- atomic_set(&tcon->num_t2renames, 0);
44723- atomic_set(&tcon->num_ffirst, 0);
44724- atomic_set(&tcon->num_fnext, 0);
44725- atomic_set(&tcon->num_fclose, 0);
44726- atomic_set(&tcon->num_hardlinks, 0);
44727- atomic_set(&tcon->num_symlinks, 0);
44728- atomic_set(&tcon->num_locks, 0);
44729+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44730+ atomic_set_unchecked(&tcon->num_writes, 0);
44731+ atomic_set_unchecked(&tcon->num_reads, 0);
44732+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44733+ atomic_set_unchecked(&tcon->num_opens, 0);
44734+ atomic_set_unchecked(&tcon->num_posixopens, 0);
44735+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44736+ atomic_set_unchecked(&tcon->num_closes, 0);
44737+ atomic_set_unchecked(&tcon->num_deletes, 0);
44738+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
44739+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
44740+ atomic_set_unchecked(&tcon->num_renames, 0);
44741+ atomic_set_unchecked(&tcon->num_t2renames, 0);
44742+ atomic_set_unchecked(&tcon->num_ffirst, 0);
44743+ atomic_set_unchecked(&tcon->num_fnext, 0);
44744+ atomic_set_unchecked(&tcon->num_fclose, 0);
44745+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
44746+ atomic_set_unchecked(&tcon->num_symlinks, 0);
44747+ atomic_set_unchecked(&tcon->num_locks, 0);
44748 }
44749 }
44750 }
44751@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct s
44752 if (tcon->need_reconnect)
44753 seq_puts(m, "\tDISCONNECTED ");
44754 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44755- atomic_read(&tcon->num_smbs_sent),
44756- atomic_read(&tcon->num_oplock_brks));
44757+ atomic_read_unchecked(&tcon->num_smbs_sent),
44758+ atomic_read_unchecked(&tcon->num_oplock_brks));
44759 seq_printf(m, "\nReads: %d Bytes: %lld",
44760- atomic_read(&tcon->num_reads),
44761+ atomic_read_unchecked(&tcon->num_reads),
44762 (long long)(tcon->bytes_read));
44763 seq_printf(m, "\nWrites: %d Bytes: %lld",
44764- atomic_read(&tcon->num_writes),
44765+ atomic_read_unchecked(&tcon->num_writes),
44766 (long long)(tcon->bytes_written));
44767 seq_printf(m, "\nFlushes: %d",
44768- atomic_read(&tcon->num_flushes));
44769+ atomic_read_unchecked(&tcon->num_flushes));
44770 seq_printf(m, "\nLocks: %d HardLinks: %d "
44771 "Symlinks: %d",
44772- atomic_read(&tcon->num_locks),
44773- atomic_read(&tcon->num_hardlinks),
44774- atomic_read(&tcon->num_symlinks));
44775+ atomic_read_unchecked(&tcon->num_locks),
44776+ atomic_read_unchecked(&tcon->num_hardlinks),
44777+ atomic_read_unchecked(&tcon->num_symlinks));
44778 seq_printf(m, "\nOpens: %d Closes: %d "
44779 "Deletes: %d",
44780- atomic_read(&tcon->num_opens),
44781- atomic_read(&tcon->num_closes),
44782- atomic_read(&tcon->num_deletes));
44783+ atomic_read_unchecked(&tcon->num_opens),
44784+ atomic_read_unchecked(&tcon->num_closes),
44785+ atomic_read_unchecked(&tcon->num_deletes));
44786 seq_printf(m, "\nPosix Opens: %d "
44787 "Posix Mkdirs: %d",
44788- atomic_read(&tcon->num_posixopens),
44789- atomic_read(&tcon->num_posixmkdirs));
44790+ atomic_read_unchecked(&tcon->num_posixopens),
44791+ atomic_read_unchecked(&tcon->num_posixmkdirs));
44792 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44793- atomic_read(&tcon->num_mkdirs),
44794- atomic_read(&tcon->num_rmdirs));
44795+ atomic_read_unchecked(&tcon->num_mkdirs),
44796+ atomic_read_unchecked(&tcon->num_rmdirs));
44797 seq_printf(m, "\nRenames: %d T2 Renames %d",
44798- atomic_read(&tcon->num_renames),
44799- atomic_read(&tcon->num_t2renames));
44800+ atomic_read_unchecked(&tcon->num_renames),
44801+ atomic_read_unchecked(&tcon->num_t2renames));
44802 seq_printf(m, "\nFindFirst: %d FNext %d "
44803 "FClose %d",
44804- atomic_read(&tcon->num_ffirst),
44805- atomic_read(&tcon->num_fnext),
44806- atomic_read(&tcon->num_fclose));
44807+ atomic_read_unchecked(&tcon->num_ffirst),
44808+ atomic_read_unchecked(&tcon->num_fnext),
44809+ atomic_read_unchecked(&tcon->num_fclose));
44810 }
44811 }
44812 }
44813diff -urNp linux-2.6.39.1/fs/cifs/cifsglob.h linux-2.6.39.1/fs/cifs/cifsglob.h
44814--- linux-2.6.39.1/fs/cifs/cifsglob.h 2011-05-19 00:06:34.000000000 -0400
44815+++ linux-2.6.39.1/fs/cifs/cifsglob.h 2011-05-22 19:36:32.000000000 -0400
44816@@ -305,28 +305,28 @@ struct cifsTconInfo {
44817 __u16 Flags; /* optional support bits */
44818 enum statusEnum tidStatus;
44819 #ifdef CONFIG_CIFS_STATS
44820- atomic_t num_smbs_sent;
44821- atomic_t num_writes;
44822- atomic_t num_reads;
44823- atomic_t num_flushes;
44824- atomic_t num_oplock_brks;
44825- atomic_t num_opens;
44826- atomic_t num_closes;
44827- atomic_t num_deletes;
44828- atomic_t num_mkdirs;
44829- atomic_t num_posixopens;
44830- atomic_t num_posixmkdirs;
44831- atomic_t num_rmdirs;
44832- atomic_t num_renames;
44833- atomic_t num_t2renames;
44834- atomic_t num_ffirst;
44835- atomic_t num_fnext;
44836- atomic_t num_fclose;
44837- atomic_t num_hardlinks;
44838- atomic_t num_symlinks;
44839- atomic_t num_locks;
44840- atomic_t num_acl_get;
44841- atomic_t num_acl_set;
44842+ atomic_unchecked_t num_smbs_sent;
44843+ atomic_unchecked_t num_writes;
44844+ atomic_unchecked_t num_reads;
44845+ atomic_unchecked_t num_flushes;
44846+ atomic_unchecked_t num_oplock_brks;
44847+ atomic_unchecked_t num_opens;
44848+ atomic_unchecked_t num_closes;
44849+ atomic_unchecked_t num_deletes;
44850+ atomic_unchecked_t num_mkdirs;
44851+ atomic_unchecked_t num_posixopens;
44852+ atomic_unchecked_t num_posixmkdirs;
44853+ atomic_unchecked_t num_rmdirs;
44854+ atomic_unchecked_t num_renames;
44855+ atomic_unchecked_t num_t2renames;
44856+ atomic_unchecked_t num_ffirst;
44857+ atomic_unchecked_t num_fnext;
44858+ atomic_unchecked_t num_fclose;
44859+ atomic_unchecked_t num_hardlinks;
44860+ atomic_unchecked_t num_symlinks;
44861+ atomic_unchecked_t num_locks;
44862+ atomic_unchecked_t num_acl_get;
44863+ atomic_unchecked_t num_acl_set;
44864 #ifdef CONFIG_CIFS_STATS2
44865 unsigned long long time_writes;
44866 unsigned long long time_reads;
44867@@ -509,7 +509,7 @@ static inline char CIFS_DIR_SEP(const st
44868 }
44869
44870 #ifdef CONFIG_CIFS_STATS
44871-#define cifs_stats_inc atomic_inc
44872+#define cifs_stats_inc atomic_inc_unchecked
44873
44874 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
44875 unsigned int bytes)
44876diff -urNp linux-2.6.39.1/fs/cifs/link.c linux-2.6.39.1/fs/cifs/link.c
44877--- linux-2.6.39.1/fs/cifs/link.c 2011-05-19 00:06:34.000000000 -0400
44878+++ linux-2.6.39.1/fs/cifs/link.c 2011-05-22 19:36:32.000000000 -0400
44879@@ -577,7 +577,7 @@ symlink_exit:
44880
44881 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44882 {
44883- char *p = nd_get_link(nd);
44884+ const char *p = nd_get_link(nd);
44885 if (!IS_ERR(p))
44886 kfree(p);
44887 }
44888diff -urNp linux-2.6.39.1/fs/coda/cache.c linux-2.6.39.1/fs/coda/cache.c
44889--- linux-2.6.39.1/fs/coda/cache.c 2011-05-19 00:06:34.000000000 -0400
44890+++ linux-2.6.39.1/fs/coda/cache.c 2011-05-22 19:36:32.000000000 -0400
44891@@ -24,7 +24,7 @@
44892 #include "coda_linux.h"
44893 #include "coda_cache.h"
44894
44895-static atomic_t permission_epoch = ATOMIC_INIT(0);
44896+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44897
44898 /* replace or extend an acl cache hit */
44899 void coda_cache_enter(struct inode *inode, int mask)
44900@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inod
44901 struct coda_inode_info *cii = ITOC(inode);
44902
44903 spin_lock(&cii->c_lock);
44904- cii->c_cached_epoch = atomic_read(&permission_epoch);
44905+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44906 if (cii->c_uid != current_fsuid()) {
44907 cii->c_uid = current_fsuid();
44908 cii->c_cached_perm = mask;
44909@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode
44910 {
44911 struct coda_inode_info *cii = ITOC(inode);
44912 spin_lock(&cii->c_lock);
44913- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44914+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44915 spin_unlock(&cii->c_lock);
44916 }
44917
44918 /* remove all acl caches */
44919 void coda_cache_clear_all(struct super_block *sb)
44920 {
44921- atomic_inc(&permission_epoch);
44922+ atomic_inc_unchecked(&permission_epoch);
44923 }
44924
44925
44926@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode
44927 spin_lock(&cii->c_lock);
44928 hit = (mask & cii->c_cached_perm) == mask &&
44929 cii->c_uid == current_fsuid() &&
44930- cii->c_cached_epoch == atomic_read(&permission_epoch);
44931+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44932 spin_unlock(&cii->c_lock);
44933
44934 return hit;
44935diff -urNp linux-2.6.39.1/fs/compat_binfmt_elf.c linux-2.6.39.1/fs/compat_binfmt_elf.c
44936--- linux-2.6.39.1/fs/compat_binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
44937+++ linux-2.6.39.1/fs/compat_binfmt_elf.c 2011-05-22 19:36:32.000000000 -0400
44938@@ -30,11 +30,13 @@
44939 #undef elf_phdr
44940 #undef elf_shdr
44941 #undef elf_note
44942+#undef elf_dyn
44943 #undef elf_addr_t
44944 #define elfhdr elf32_hdr
44945 #define elf_phdr elf32_phdr
44946 #define elf_shdr elf32_shdr
44947 #define elf_note elf32_note
44948+#define elf_dyn Elf32_Dyn
44949 #define elf_addr_t Elf32_Addr
44950
44951 /*
44952diff -urNp linux-2.6.39.1/fs/compat.c linux-2.6.39.1/fs/compat.c
44953--- linux-2.6.39.1/fs/compat.c 2011-05-19 00:06:34.000000000 -0400
44954+++ linux-2.6.39.1/fs/compat.c 2011-05-22 19:41:37.000000000 -0400
44955@@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int
44956 goto out;
44957
44958 ret = -EINVAL;
44959- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44960+ if (nr_segs > UIO_MAXIOV)
44961 goto out;
44962 if (nr_segs > fast_segs) {
44963 ret = -ENOMEM;
44964@@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
44965
44966 struct compat_readdir_callback {
44967 struct compat_old_linux_dirent __user *dirent;
44968+ struct file * file;
44969 int result;
44970 };
44971
44972@@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf
44973 buf->result = -EOVERFLOW;
44974 return -EOVERFLOW;
44975 }
44976+
44977+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44978+ return 0;
44979+
44980 buf->result++;
44981 dirent = buf->dirent;
44982 if (!access_ok(VERIFY_WRITE, dirent,
44983@@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(u
44984
44985 buf.result = 0;
44986 buf.dirent = dirent;
44987+ buf.file = file;
44988
44989 error = vfs_readdir(file, compat_fillonedir, &buf);
44990 if (buf.result)
44991@@ -917,6 +923,7 @@ struct compat_linux_dirent {
44992 struct compat_getdents_callback {
44993 struct compat_linux_dirent __user *current_dir;
44994 struct compat_linux_dirent __user *previous;
44995+ struct file * file;
44996 int count;
44997 int error;
44998 };
44999@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, c
45000 buf->error = -EOVERFLOW;
45001 return -EOVERFLOW;
45002 }
45003+
45004+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45005+ return 0;
45006+
45007 dirent = buf->previous;
45008 if (dirent) {
45009 if (__put_user(offset, &dirent->d_off))
45010@@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsi
45011 buf.previous = NULL;
45012 buf.count = count;
45013 buf.error = 0;
45014+ buf.file = file;
45015
45016 error = vfs_readdir(file, compat_filldir, &buf);
45017 if (error >= 0)
45018@@ -1006,6 +1018,7 @@ out:
45019 struct compat_getdents_callback64 {
45020 struct linux_dirent64 __user *current_dir;
45021 struct linux_dirent64 __user *previous;
45022+ struct file * file;
45023 int count;
45024 int error;
45025 };
45026@@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf
45027 buf->error = -EINVAL; /* only used if we fail.. */
45028 if (reclen > buf->count)
45029 return -EINVAL;
45030+
45031+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45032+ return 0;
45033+
45034 dirent = buf->previous;
45035
45036 if (dirent) {
45037@@ -1073,6 +1090,7 @@ asmlinkage long compat_sys_getdents64(un
45038 buf.previous = NULL;
45039 buf.count = count;
45040 buf.error = 0;
45041+ buf.file = file;
45042
45043 error = vfs_readdir(file, compat_filldir64, &buf);
45044 if (error >= 0)
45045@@ -1436,6 +1454,11 @@ int compat_do_execve(char * filename,
45046 compat_uptr_t __user *envp,
45047 struct pt_regs * regs)
45048 {
45049+#ifdef CONFIG_GRKERNSEC
45050+ struct file *old_exec_file;
45051+ struct acl_subject_label *old_acl;
45052+ struct rlimit old_rlim[RLIM_NLIMITS];
45053+#endif
45054 struct linux_binprm *bprm;
45055 struct file *file;
45056 struct files_struct *displaced;
45057@@ -1472,6 +1495,19 @@ int compat_do_execve(char * filename,
45058 bprm->filename = filename;
45059 bprm->interp = filename;
45060
45061+ if (gr_process_user_ban()) {
45062+ retval = -EPERM;
45063+ goto out_file;
45064+ }
45065+
45066+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45067+ retval = -EAGAIN;
45068+ if (gr_handle_nproc())
45069+ goto out_file;
45070+ retval = -EACCES;
45071+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
45072+ goto out_file;
45073+
45074 retval = bprm_mm_init(bprm);
45075 if (retval)
45076 goto out_file;
45077@@ -1501,9 +1537,40 @@ int compat_do_execve(char * filename,
45078 if (retval < 0)
45079 goto out;
45080
45081+ if (!gr_tpe_allow(file)) {
45082+ retval = -EACCES;
45083+ goto out;
45084+ }
45085+
45086+ if (gr_check_crash_exec(file)) {
45087+ retval = -EACCES;
45088+ goto out;
45089+ }
45090+
45091+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45092+
45093+ gr_handle_exec_args_compat(bprm, argv);
45094+
45095+#ifdef CONFIG_GRKERNSEC
45096+ old_acl = current->acl;
45097+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45098+ old_exec_file = current->exec_file;
45099+ get_file(file);
45100+ current->exec_file = file;
45101+#endif
45102+
45103+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45104+ bprm->unsafe & LSM_UNSAFE_SHARE);
45105+ if (retval < 0)
45106+ goto out_fail;
45107+
45108 retval = search_binary_handler(bprm, regs);
45109 if (retval < 0)
45110- goto out;
45111+ goto out_fail;
45112+#ifdef CONFIG_GRKERNSEC
45113+ if (old_exec_file)
45114+ fput(old_exec_file);
45115+#endif
45116
45117 /* execve succeeded */
45118 current->fs->in_exec = 0;
45119@@ -1514,6 +1581,14 @@ int compat_do_execve(char * filename,
45120 put_files_struct(displaced);
45121 return retval;
45122
45123+out_fail:
45124+#ifdef CONFIG_GRKERNSEC
45125+ current->acl = old_acl;
45126+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45127+ fput(current->exec_file);
45128+ current->exec_file = old_exec_file;
45129+#endif
45130+
45131 out:
45132 if (bprm->mm) {
45133 acct_arg_size(bprm, 0);
45134@@ -1681,6 +1756,8 @@ int compat_core_sys_select(int n, compat
45135 struct fdtable *fdt;
45136 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
45137
45138+ pax_track_stack();
45139+
45140 if (n < 0)
45141 goto out_nofds;
45142
45143diff -urNp linux-2.6.39.1/fs/compat_ioctl.c linux-2.6.39.1/fs/compat_ioctl.c
45144--- linux-2.6.39.1/fs/compat_ioctl.c 2011-05-19 00:06:34.000000000 -0400
45145+++ linux-2.6.39.1/fs/compat_ioctl.c 2011-05-22 19:36:32.000000000 -0400
45146@@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
45147
45148 err = get_user(palp, &up->palette);
45149 err |= get_user(length, &up->length);
45150+ if (err)
45151+ return -EFAULT;
45152
45153 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
45154 err = put_user(compat_ptr(palp), &up_native->palette);
45155@@ -1638,8 +1640,8 @@ asmlinkage long compat_sys_ioctl(unsigne
45156 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45157 {
45158 unsigned int a, b;
45159- a = *(unsigned int *)p;
45160- b = *(unsigned int *)q;
45161+ a = *(const unsigned int *)p;
45162+ b = *(const unsigned int *)q;
45163 if (a > b)
45164 return 1;
45165 if (a < b)
45166diff -urNp linux-2.6.39.1/fs/configfs/dir.c linux-2.6.39.1/fs/configfs/dir.c
45167--- linux-2.6.39.1/fs/configfs/dir.c 2011-05-19 00:06:34.000000000 -0400
45168+++ linux-2.6.39.1/fs/configfs/dir.c 2011-05-22 19:36:32.000000000 -0400
45169@@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file
45170 }
45171 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45172 struct configfs_dirent *next;
45173- const char * name;
45174+ const unsigned char * name;
45175+ char d_name[sizeof(next->s_dentry->d_iname)];
45176 int len;
45177 struct inode *inode = NULL;
45178
45179@@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file
45180 continue;
45181
45182 name = configfs_get_name(next);
45183- len = strlen(name);
45184+ if (next->s_dentry && name == next->s_dentry->d_iname) {
45185+ len = next->s_dentry->d_name.len;
45186+ memcpy(d_name, name, len);
45187+ name = d_name;
45188+ } else
45189+ len = strlen(name);
45190
45191 /*
45192 * We'll have a dentry and an inode for
45193diff -urNp linux-2.6.39.1/fs/configfs/file.c linux-2.6.39.1/fs/configfs/file.c
45194--- linux-2.6.39.1/fs/configfs/file.c 2011-05-19 00:06:34.000000000 -0400
45195+++ linux-2.6.39.1/fs/configfs/file.c 2011-05-22 19:36:32.000000000 -0400
45196@@ -215,7 +215,7 @@ static int check_perm(struct inode * ino
45197 struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent);
45198 struct configfs_attribute * attr = to_attr(file->f_path.dentry);
45199 struct configfs_buffer * buffer;
45200- struct configfs_item_operations * ops = NULL;
45201+ struct configfs_item_operations *ops = NULL;
45202 int error = 0;
45203
45204 if (!item || !attr)
45205diff -urNp linux-2.6.39.1/fs/configfs/item.c linux-2.6.39.1/fs/configfs/item.c
45206--- linux-2.6.39.1/fs/configfs/item.c 2011-05-19 00:06:34.000000000 -0400
45207+++ linux-2.6.39.1/fs/configfs/item.c 2011-05-22 19:36:32.000000000 -0400
45208@@ -123,7 +123,7 @@ void config_item_init_type_name(struct c
45209 EXPORT_SYMBOL(config_item_init_type_name);
45210
45211 void config_group_init_type_name(struct config_group *group, const char *name,
45212- struct config_item_type *type)
45213+ struct config_item_type *type)
45214 {
45215 config_item_set_name(&group->cg_item, name);
45216 group->cg_item.ci_type = type;
45217diff -urNp linux-2.6.39.1/fs/dcache.c linux-2.6.39.1/fs/dcache.c
45218--- linux-2.6.39.1/fs/dcache.c 2011-05-19 00:06:34.000000000 -0400
45219+++ linux-2.6.39.1/fs/dcache.c 2011-05-22 19:36:32.000000000 -0400
45220@@ -3069,7 +3069,7 @@ void __init vfs_caches_init(unsigned lon
45221 mempages -= reserve;
45222
45223 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45224- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45225+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45226
45227 dcache_init();
45228 inode_init();
45229diff -urNp linux-2.6.39.1/fs/dlm/lockspace.c linux-2.6.39.1/fs/dlm/lockspace.c
45230--- linux-2.6.39.1/fs/dlm/lockspace.c 2011-05-19 00:06:34.000000000 -0400
45231+++ linux-2.6.39.1/fs/dlm/lockspace.c 2011-05-22 19:36:32.000000000 -0400
45232@@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
45233 return 0;
45234 }
45235
45236-static struct kset_uevent_ops dlm_uevent_ops = {
45237+static const struct kset_uevent_ops dlm_uevent_ops = {
45238 .uevent = dlm_uevent,
45239 };
45240
45241diff -urNp linux-2.6.39.1/fs/ecryptfs/inode.c linux-2.6.39.1/fs/ecryptfs/inode.c
45242--- linux-2.6.39.1/fs/ecryptfs/inode.c 2011-06-03 00:04:14.000000000 -0400
45243+++ linux-2.6.39.1/fs/ecryptfs/inode.c 2011-06-03 00:32:07.000000000 -0400
45244@@ -623,7 +623,7 @@ static int ecryptfs_readlink_lower(struc
45245 old_fs = get_fs();
45246 set_fs(get_ds());
45247 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45248- (char __user *)lower_buf,
45249+ (__force char __user *)lower_buf,
45250 lower_bufsiz);
45251 set_fs(old_fs);
45252 if (rc < 0)
45253@@ -669,7 +669,7 @@ static void *ecryptfs_follow_link(struct
45254 }
45255 old_fs = get_fs();
45256 set_fs(get_ds());
45257- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
45258+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
45259 set_fs(old_fs);
45260 if (rc < 0) {
45261 kfree(buf);
45262@@ -684,7 +684,7 @@ out:
45263 static void
45264 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45265 {
45266- char *buf = nd_get_link(nd);
45267+ const char *buf = nd_get_link(nd);
45268 if (!IS_ERR(buf)) {
45269 /* Free the char* */
45270 kfree(buf);
45271diff -urNp linux-2.6.39.1/fs/ecryptfs/miscdev.c linux-2.6.39.1/fs/ecryptfs/miscdev.c
45272--- linux-2.6.39.1/fs/ecryptfs/miscdev.c 2011-05-19 00:06:34.000000000 -0400
45273+++ linux-2.6.39.1/fs/ecryptfs/miscdev.c 2011-05-22 19:36:32.000000000 -0400
45274@@ -328,7 +328,7 @@ check_list:
45275 goto out_unlock_msg_ctx;
45276 i = 5;
45277 if (msg_ctx->msg) {
45278- if (copy_to_user(&buf[i], packet_length, packet_length_size))
45279+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45280 goto out_unlock_msg_ctx;
45281 i += packet_length_size;
45282 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45283diff -urNp linux-2.6.39.1/fs/exec.c linux-2.6.39.1/fs/exec.c
45284--- linux-2.6.39.1/fs/exec.c 2011-05-19 00:06:34.000000000 -0400
45285+++ linux-2.6.39.1/fs/exec.c 2011-06-03 23:33:13.000000000 -0400
45286@@ -55,12 +55,24 @@
45287 #include <linux/fs_struct.h>
45288 #include <linux/pipe_fs_i.h>
45289 #include <linux/oom.h>
45290+#include <linux/random.h>
45291+#include <linux/seq_file.h>
45292+
45293+#ifdef CONFIG_PAX_REFCOUNT
45294+#include <linux/kallsyms.h>
45295+#include <linux/kdebug.h>
45296+#endif
45297
45298 #include <asm/uaccess.h>
45299 #include <asm/mmu_context.h>
45300 #include <asm/tlb.h>
45301 #include "internal.h"
45302
45303+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45304+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45305+EXPORT_SYMBOL(pax_set_initial_flags_func);
45306+#endif
45307+
45308 int core_uses_pid;
45309 char core_pattern[CORENAME_MAX_SIZE] = "core";
45310 unsigned int core_pipe_limit;
45311@@ -70,7 +82,7 @@ struct core_name {
45312 char *corename;
45313 int used, size;
45314 };
45315-static atomic_t call_count = ATOMIC_INIT(1);
45316+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45317
45318 /* The maximal length of core_pattern is also specified in sysctl.c */
45319
45320@@ -116,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __use
45321 char *tmp = getname(library);
45322 int error = PTR_ERR(tmp);
45323 static const struct open_flags uselib_flags = {
45324- .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45325+ .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45326 .acc_mode = MAY_READ | MAY_EXEC | MAY_OPEN,
45327 .intent = LOOKUP_OPEN
45328 };
45329@@ -190,18 +202,10 @@ struct page *get_arg_page(struct linux_b
45330 int write)
45331 {
45332 struct page *page;
45333- int ret;
45334
45335-#ifdef CONFIG_STACK_GROWSUP
45336- if (write) {
45337- ret = expand_stack_downwards(bprm->vma, pos);
45338- if (ret < 0)
45339- return NULL;
45340- }
45341-#endif
45342- ret = get_user_pages(current, bprm->mm, pos,
45343- 1, write, 1, &page, NULL);
45344- if (ret <= 0)
45345+ if (0 > expand_stack_downwards(bprm->vma, pos))
45346+ return NULL;
45347+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45348 return NULL;
45349
45350 if (write) {
45351@@ -276,6 +280,11 @@ static int __bprm_mm_init(struct linux_b
45352 vma->vm_end = STACK_TOP_MAX;
45353 vma->vm_start = vma->vm_end - PAGE_SIZE;
45354 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45355+
45356+#ifdef CONFIG_PAX_SEGMEXEC
45357+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45358+#endif
45359+
45360 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45361 INIT_LIST_HEAD(&vma->anon_vma_chain);
45362
45363@@ -290,6 +299,12 @@ static int __bprm_mm_init(struct linux_b
45364 mm->stack_vm = mm->total_vm = 1;
45365 up_write(&mm->mmap_sem);
45366 bprm->p = vma->vm_end - sizeof(void *);
45367+
45368+#ifdef CONFIG_PAX_RANDUSTACK
45369+ if (randomize_va_space)
45370+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
45371+#endif
45372+
45373 return 0;
45374 err:
45375 up_write(&mm->mmap_sem);
45376@@ -525,7 +540,7 @@ int copy_strings_kernel(int argc, const
45377 int r;
45378 mm_segment_t oldfs = get_fs();
45379 set_fs(KERNEL_DS);
45380- r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
45381+ r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
45382 set_fs(oldfs);
45383 return r;
45384 }
45385@@ -555,7 +570,8 @@ static int shift_arg_pages(struct vm_are
45386 unsigned long new_end = old_end - shift;
45387 struct mmu_gather *tlb;
45388
45389- BUG_ON(new_start > new_end);
45390+ if (new_start >= new_end || new_start < mmap_min_addr)
45391+ return -ENOMEM;
45392
45393 /*
45394 * ensure there are no vmas between where we want to go
45395@@ -564,6 +580,10 @@ static int shift_arg_pages(struct vm_are
45396 if (vma != find_vma(mm, new_start))
45397 return -EFAULT;
45398
45399+#ifdef CONFIG_PAX_SEGMEXEC
45400+ BUG_ON(pax_find_mirror_vma(vma));
45401+#endif
45402+
45403 /*
45404 * cover the whole range: [new_start, old_end)
45405 */
45406@@ -644,10 +664,6 @@ int setup_arg_pages(struct linux_binprm
45407 stack_top = arch_align_stack(stack_top);
45408 stack_top = PAGE_ALIGN(stack_top);
45409
45410- if (unlikely(stack_top < mmap_min_addr) ||
45411- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45412- return -ENOMEM;
45413-
45414 stack_shift = vma->vm_end - stack_top;
45415
45416 bprm->p -= stack_shift;
45417@@ -659,8 +675,28 @@ int setup_arg_pages(struct linux_binprm
45418 bprm->exec -= stack_shift;
45419
45420 down_write(&mm->mmap_sem);
45421+
45422+ /* Move stack pages down in memory. */
45423+ if (stack_shift) {
45424+ ret = shift_arg_pages(vma, stack_shift);
45425+ if (ret)
45426+ goto out_unlock;
45427+ }
45428+
45429 vm_flags = VM_STACK_FLAGS;
45430
45431+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45432+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45433+ vm_flags &= ~VM_EXEC;
45434+
45435+#ifdef CONFIG_PAX_MPROTECT
45436+ if (mm->pax_flags & MF_PAX_MPROTECT)
45437+ vm_flags &= ~VM_MAYEXEC;
45438+#endif
45439+
45440+ }
45441+#endif
45442+
45443 /*
45444 * Adjust stack execute permissions; explicitly enable for
45445 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45446@@ -679,13 +715,6 @@ int setup_arg_pages(struct linux_binprm
45447 goto out_unlock;
45448 BUG_ON(prev != vma);
45449
45450- /* Move stack pages down in memory. */
45451- if (stack_shift) {
45452- ret = shift_arg_pages(vma, stack_shift);
45453- if (ret)
45454- goto out_unlock;
45455- }
45456-
45457 /* mprotect_fixup is overkill to remove the temporary stack flags */
45458 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45459
45460@@ -725,7 +754,7 @@ struct file *open_exec(const char *name)
45461 struct file *file;
45462 int err;
45463 static const struct open_flags open_exec_flags = {
45464- .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45465+ .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45466 .acc_mode = MAY_EXEC | MAY_OPEN,
45467 .intent = LOOKUP_OPEN
45468 };
45469@@ -766,7 +795,7 @@ int kernel_read(struct file *file, loff_
45470 old_fs = get_fs();
45471 set_fs(get_ds());
45472 /* The cast to a user pointer is valid due to the set_fs() */
45473- result = vfs_read(file, (void __user *)addr, count, &pos);
45474+ result = vfs_read(file, (__force void __user *)addr, count, &pos);
45475 set_fs(old_fs);
45476 return result;
45477 }
45478@@ -1188,7 +1217,7 @@ int check_unsafe_exec(struct linux_binpr
45479 }
45480 rcu_read_unlock();
45481
45482- if (p->fs->users > n_fs) {
45483+ if (atomic_read(&p->fs->users) > n_fs) {
45484 bprm->unsafe |= LSM_UNSAFE_SHARE;
45485 } else {
45486 res = -EAGAIN;
45487@@ -1384,6 +1413,11 @@ int do_execve(const char * filename,
45488 const char __user *const __user *envp,
45489 struct pt_regs * regs)
45490 {
45491+#ifdef CONFIG_GRKERNSEC
45492+ struct file *old_exec_file;
45493+ struct acl_subject_label *old_acl;
45494+ struct rlimit old_rlim[RLIM_NLIMITS];
45495+#endif
45496 struct linux_binprm *bprm;
45497 struct file *file;
45498 struct files_struct *displaced;
45499@@ -1420,6 +1454,23 @@ int do_execve(const char * filename,
45500 bprm->filename = filename;
45501 bprm->interp = filename;
45502
45503+ if (gr_process_user_ban()) {
45504+ retval = -EPERM;
45505+ goto out_file;
45506+ }
45507+
45508+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45509+
45510+ if (gr_handle_nproc()) {
45511+ retval = -EAGAIN;
45512+ goto out_file;
45513+ }
45514+
45515+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45516+ retval = -EACCES;
45517+ goto out_file;
45518+ }
45519+
45520 retval = bprm_mm_init(bprm);
45521 if (retval)
45522 goto out_file;
45523@@ -1449,9 +1500,40 @@ int do_execve(const char * filename,
45524 if (retval < 0)
45525 goto out;
45526
45527+ if (!gr_tpe_allow(file)) {
45528+ retval = -EACCES;
45529+ goto out;
45530+ }
45531+
45532+ if (gr_check_crash_exec(file)) {
45533+ retval = -EACCES;
45534+ goto out;
45535+ }
45536+
45537+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45538+
45539+ gr_handle_exec_args(bprm, argv);
45540+
45541+#ifdef CONFIG_GRKERNSEC
45542+ old_acl = current->acl;
45543+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45544+ old_exec_file = current->exec_file;
45545+ get_file(file);
45546+ current->exec_file = file;
45547+#endif
45548+
45549+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45550+ bprm->unsafe & LSM_UNSAFE_SHARE);
45551+ if (retval < 0)
45552+ goto out_fail;
45553+
45554 retval = search_binary_handler(bprm,regs);
45555 if (retval < 0)
45556- goto out;
45557+ goto out_fail;
45558+#ifdef CONFIG_GRKERNSEC
45559+ if (old_exec_file)
45560+ fput(old_exec_file);
45561+#endif
45562
45563 /* execve succeeded */
45564 current->fs->in_exec = 0;
45565@@ -1462,6 +1544,14 @@ int do_execve(const char * filename,
45566 put_files_struct(displaced);
45567 return retval;
45568
45569+out_fail:
45570+#ifdef CONFIG_GRKERNSEC
45571+ current->acl = old_acl;
45572+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45573+ fput(current->exec_file);
45574+ current->exec_file = old_exec_file;
45575+#endif
45576+
45577 out:
45578 if (bprm->mm) {
45579 acct_arg_size(bprm, 0);
45580@@ -1507,7 +1597,7 @@ static int expand_corename(struct core_n
45581 {
45582 char *old_corename = cn->corename;
45583
45584- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45585+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45586 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45587
45588 if (!cn->corename) {
45589@@ -1560,7 +1650,7 @@ static int format_corename(struct core_n
45590 int pid_in_pattern = 0;
45591 int err = 0;
45592
45593- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45594+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45595 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45596 cn->used = 0;
45597
45598@@ -1648,6 +1738,219 @@ out:
45599 return ispipe;
45600 }
45601
45602+int pax_check_flags(unsigned long *flags)
45603+{
45604+ int retval = 0;
45605+
45606+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45607+ if (*flags & MF_PAX_SEGMEXEC)
45608+ {
45609+ *flags &= ~MF_PAX_SEGMEXEC;
45610+ retval = -EINVAL;
45611+ }
45612+#endif
45613+
45614+ if ((*flags & MF_PAX_PAGEEXEC)
45615+
45616+#ifdef CONFIG_PAX_PAGEEXEC
45617+ && (*flags & MF_PAX_SEGMEXEC)
45618+#endif
45619+
45620+ )
45621+ {
45622+ *flags &= ~MF_PAX_PAGEEXEC;
45623+ retval = -EINVAL;
45624+ }
45625+
45626+ if ((*flags & MF_PAX_MPROTECT)
45627+
45628+#ifdef CONFIG_PAX_MPROTECT
45629+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45630+#endif
45631+
45632+ )
45633+ {
45634+ *flags &= ~MF_PAX_MPROTECT;
45635+ retval = -EINVAL;
45636+ }
45637+
45638+ if ((*flags & MF_PAX_EMUTRAMP)
45639+
45640+#ifdef CONFIG_PAX_EMUTRAMP
45641+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45642+#endif
45643+
45644+ )
45645+ {
45646+ *flags &= ~MF_PAX_EMUTRAMP;
45647+ retval = -EINVAL;
45648+ }
45649+
45650+ return retval;
45651+}
45652+
45653+EXPORT_SYMBOL(pax_check_flags);
45654+
45655+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45656+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45657+{
45658+ struct task_struct *tsk = current;
45659+ struct mm_struct *mm = current->mm;
45660+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45661+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45662+ char *path_exec = NULL;
45663+ char *path_fault = NULL;
45664+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45665+
45666+ if (buffer_exec && buffer_fault) {
45667+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45668+
45669+ down_read(&mm->mmap_sem);
45670+ vma = mm->mmap;
45671+ while (vma && (!vma_exec || !vma_fault)) {
45672+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45673+ vma_exec = vma;
45674+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45675+ vma_fault = vma;
45676+ vma = vma->vm_next;
45677+ }
45678+ if (vma_exec) {
45679+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45680+ if (IS_ERR(path_exec))
45681+ path_exec = "<path too long>";
45682+ else {
45683+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45684+ if (path_exec) {
45685+ *path_exec = 0;
45686+ path_exec = buffer_exec;
45687+ } else
45688+ path_exec = "<path too long>";
45689+ }
45690+ }
45691+ if (vma_fault) {
45692+ start = vma_fault->vm_start;
45693+ end = vma_fault->vm_end;
45694+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45695+ if (vma_fault->vm_file) {
45696+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45697+ if (IS_ERR(path_fault))
45698+ path_fault = "<path too long>";
45699+ else {
45700+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45701+ if (path_fault) {
45702+ *path_fault = 0;
45703+ path_fault = buffer_fault;
45704+ } else
45705+ path_fault = "<path too long>";
45706+ }
45707+ } else
45708+ path_fault = "<anonymous mapping>";
45709+ }
45710+ up_read(&mm->mmap_sem);
45711+ }
45712+ if (tsk->signal->curr_ip)
45713+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45714+ else
45715+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45716+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45717+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45718+ task_uid(tsk), task_euid(tsk), pc, sp);
45719+ free_page((unsigned long)buffer_exec);
45720+ free_page((unsigned long)buffer_fault);
45721+ pax_report_insns(pc, sp);
45722+ do_coredump(SIGKILL, SIGKILL, regs);
45723+}
45724+#endif
45725+
45726+#ifdef CONFIG_PAX_REFCOUNT
45727+void pax_report_refcount_overflow(struct pt_regs *regs)
45728+{
45729+ if (current->signal->curr_ip)
45730+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45731+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45732+ else
45733+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45734+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45735+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45736+ show_regs(regs);
45737+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45738+}
45739+#endif
45740+
45741+#ifdef CONFIG_PAX_USERCOPY
45742+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45743+int object_is_on_stack(const void *obj, unsigned long len)
45744+{
45745+ const void * const stack = task_stack_page(current);
45746+ const void * const stackend = stack + THREAD_SIZE;
45747+
45748+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45749+ const void *frame = NULL;
45750+ const void *oldframe;
45751+#endif
45752+
45753+ if (obj + len < obj)
45754+ return -1;
45755+
45756+ if (obj + len <= stack || stackend <= obj)
45757+ return 0;
45758+
45759+ if (obj < stack || stackend < obj + len)
45760+ return -1;
45761+
45762+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45763+ oldframe = __builtin_frame_address(1);
45764+ if (oldframe)
45765+ frame = __builtin_frame_address(2);
45766+ /*
45767+ low ----------------------------------------------> high
45768+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45769+ ^----------------^
45770+ allow copies only within here
45771+ */
45772+ while (stack <= frame && frame < stackend) {
45773+ /* if obj + len extends past the last frame, this
45774+ check won't pass and the next frame will be 0,
45775+ causing us to bail out and correctly report
45776+ the copy as invalid
45777+ */
45778+ if (obj + len <= frame)
45779+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45780+ oldframe = frame;
45781+ frame = *(const void * const *)frame;
45782+ }
45783+ return -1;
45784+#else
45785+ return 1;
45786+#endif
45787+}
45788+
45789+
45790+void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45791+{
45792+ if (current->signal->curr_ip)
45793+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45794+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45795+ else
45796+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45797+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45798+ dump_stack();
45799+ gr_handle_kernel_exploit();
45800+ do_group_exit(SIGKILL);
45801+}
45802+#endif
45803+
45804+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45805+void pax_track_stack(void)
45806+{
45807+ unsigned long sp = (unsigned long)&sp;
45808+ if (sp < current_thread_info()->lowest_stack &&
45809+ sp > (unsigned long)task_stack_page(current))
45810+ current_thread_info()->lowest_stack = sp;
45811+}
45812+EXPORT_SYMBOL(pax_track_stack);
45813+#endif
45814+
45815 static int zap_process(struct task_struct *start, int exit_code)
45816 {
45817 struct task_struct *t;
45818@@ -1858,17 +2161,17 @@ static void wait_for_dump_helpers(struct
45819 pipe = file->f_path.dentry->d_inode->i_pipe;
45820
45821 pipe_lock(pipe);
45822- pipe->readers++;
45823- pipe->writers--;
45824+ atomic_inc(&pipe->readers);
45825+ atomic_dec(&pipe->writers);
45826
45827- while ((pipe->readers > 1) && (!signal_pending(current))) {
45828+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45829 wake_up_interruptible_sync(&pipe->wait);
45830 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45831 pipe_wait(pipe);
45832 }
45833
45834- pipe->readers--;
45835- pipe->writers++;
45836+ atomic_dec(&pipe->readers);
45837+ atomic_inc(&pipe->writers);
45838 pipe_unlock(pipe);
45839
45840 }
45841@@ -1929,7 +2232,7 @@ void do_coredump(long signr, int exit_co
45842 int retval = 0;
45843 int flag = 0;
45844 int ispipe;
45845- static atomic_t core_dump_count = ATOMIC_INIT(0);
45846+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45847 struct coredump_params cprm = {
45848 .signr = signr,
45849 .regs = regs,
45850@@ -1944,6 +2247,9 @@ void do_coredump(long signr, int exit_co
45851
45852 audit_core_dumps(signr);
45853
45854+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45855+ gr_handle_brute_attach(current, cprm.mm_flags);
45856+
45857 binfmt = mm->binfmt;
45858 if (!binfmt || !binfmt->core_dump)
45859 goto fail;
45860@@ -1984,6 +2290,8 @@ void do_coredump(long signr, int exit_co
45861 goto fail_corename;
45862 }
45863
45864+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45865+
45866 if (ispipe) {
45867 int dump_count;
45868 char **helper_argv;
45869@@ -2011,7 +2319,7 @@ void do_coredump(long signr, int exit_co
45870 }
45871 cprm.limit = RLIM_INFINITY;
45872
45873- dump_count = atomic_inc_return(&core_dump_count);
45874+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45875 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45876 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45877 task_tgid_vnr(current), current->comm);
45878@@ -2081,7 +2389,7 @@ close_fail:
45879 filp_close(cprm.file, NULL);
45880 fail_dropcount:
45881 if (ispipe)
45882- atomic_dec(&core_dump_count);
45883+ atomic_dec_unchecked(&core_dump_count);
45884 fail_unlock:
45885 kfree(cn.corename);
45886 fail_corename:
45887diff -urNp linux-2.6.39.1/fs/ext2/balloc.c linux-2.6.39.1/fs/ext2/balloc.c
45888--- linux-2.6.39.1/fs/ext2/balloc.c 2011-05-19 00:06:34.000000000 -0400
45889+++ linux-2.6.39.1/fs/ext2/balloc.c 2011-05-22 19:41:37.000000000 -0400
45890@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
45891
45892 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45893 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45894- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45895+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45896 sbi->s_resuid != current_fsuid() &&
45897 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45898 return 0;
45899diff -urNp linux-2.6.39.1/fs/ext3/balloc.c linux-2.6.39.1/fs/ext3/balloc.c
45900--- linux-2.6.39.1/fs/ext3/balloc.c 2011-05-19 00:06:34.000000000 -0400
45901+++ linux-2.6.39.1/fs/ext3/balloc.c 2011-05-22 19:41:37.000000000 -0400
45902@@ -1441,7 +1441,7 @@ static int ext3_has_free_blocks(struct e
45903
45904 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45905 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45906- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45907+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45908 sbi->s_resuid != current_fsuid() &&
45909 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45910 return 0;
45911diff -urNp linux-2.6.39.1/fs/ext4/balloc.c linux-2.6.39.1/fs/ext4/balloc.c
45912--- linux-2.6.39.1/fs/ext4/balloc.c 2011-05-19 00:06:34.000000000 -0400
45913+++ linux-2.6.39.1/fs/ext4/balloc.c 2011-05-22 19:41:37.000000000 -0400
45914@@ -522,7 +522,7 @@ static int ext4_has_free_blocks(struct e
45915 /* Hm, nope. Are (enough) root reserved blocks available? */
45916 if (sbi->s_resuid == current_fsuid() ||
45917 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45918- capable(CAP_SYS_RESOURCE)) {
45919+ capable_nolog(CAP_SYS_RESOURCE)) {
45920 if (free_blocks >= (nblocks + dirty_blocks))
45921 return 1;
45922 }
45923diff -urNp linux-2.6.39.1/fs/ext4/ext4.h linux-2.6.39.1/fs/ext4/ext4.h
45924--- linux-2.6.39.1/fs/ext4/ext4.h 2011-06-03 00:04:14.000000000 -0400
45925+++ linux-2.6.39.1/fs/ext4/ext4.h 2011-06-03 00:32:07.000000000 -0400
45926@@ -1166,19 +1166,19 @@ struct ext4_sb_info {
45927 unsigned long s_mb_last_start;
45928
45929 /* stats for buddy allocator */
45930- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45931- atomic_t s_bal_success; /* we found long enough chunks */
45932- atomic_t s_bal_allocated; /* in blocks */
45933- atomic_t s_bal_ex_scanned; /* total extents scanned */
45934- atomic_t s_bal_goals; /* goal hits */
45935- atomic_t s_bal_breaks; /* too long searches */
45936- atomic_t s_bal_2orders; /* 2^order hits */
45937+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45938+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45939+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45940+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45941+ atomic_unchecked_t s_bal_goals; /* goal hits */
45942+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45943+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45944 spinlock_t s_bal_lock;
45945 unsigned long s_mb_buddies_generated;
45946 unsigned long long s_mb_generation_time;
45947- atomic_t s_mb_lost_chunks;
45948- atomic_t s_mb_preallocated;
45949- atomic_t s_mb_discarded;
45950+ atomic_unchecked_t s_mb_lost_chunks;
45951+ atomic_unchecked_t s_mb_preallocated;
45952+ atomic_unchecked_t s_mb_discarded;
45953 atomic_t s_lock_busy;
45954
45955 /* locality groups */
45956diff -urNp linux-2.6.39.1/fs/ext4/mballoc.c linux-2.6.39.1/fs/ext4/mballoc.c
45957--- linux-2.6.39.1/fs/ext4/mballoc.c 2011-06-03 00:04:14.000000000 -0400
45958+++ linux-2.6.39.1/fs/ext4/mballoc.c 2011-06-03 00:32:07.000000000 -0400
45959@@ -1853,7 +1853,7 @@ void ext4_mb_simple_scan_group(struct ex
45960 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45961
45962 if (EXT4_SB(sb)->s_mb_stats)
45963- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45964+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45965
45966 break;
45967 }
45968@@ -2147,7 +2147,7 @@ repeat:
45969 ac->ac_status = AC_STATUS_CONTINUE;
45970 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45971 cr = 3;
45972- atomic_inc(&sbi->s_mb_lost_chunks);
45973+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45974 goto repeat;
45975 }
45976 }
45977@@ -2190,6 +2190,8 @@ static int ext4_mb_seq_groups_show(struc
45978 ext4_grpblk_t counters[16];
45979 } sg;
45980
45981+ pax_track_stack();
45982+
45983 group--;
45984 if (group == 0)
45985 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
45986@@ -2613,25 +2615,25 @@ int ext4_mb_release(struct super_block *
45987 if (sbi->s_mb_stats) {
45988 printk(KERN_INFO
45989 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
45990- atomic_read(&sbi->s_bal_allocated),
45991- atomic_read(&sbi->s_bal_reqs),
45992- atomic_read(&sbi->s_bal_success));
45993+ atomic_read_unchecked(&sbi->s_bal_allocated),
45994+ atomic_read_unchecked(&sbi->s_bal_reqs),
45995+ atomic_read_unchecked(&sbi->s_bal_success));
45996 printk(KERN_INFO
45997 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
45998 "%u 2^N hits, %u breaks, %u lost\n",
45999- atomic_read(&sbi->s_bal_ex_scanned),
46000- atomic_read(&sbi->s_bal_goals),
46001- atomic_read(&sbi->s_bal_2orders),
46002- atomic_read(&sbi->s_bal_breaks),
46003- atomic_read(&sbi->s_mb_lost_chunks));
46004+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46005+ atomic_read_unchecked(&sbi->s_bal_goals),
46006+ atomic_read_unchecked(&sbi->s_bal_2orders),
46007+ atomic_read_unchecked(&sbi->s_bal_breaks),
46008+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46009 printk(KERN_INFO
46010 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
46011 sbi->s_mb_buddies_generated++,
46012 sbi->s_mb_generation_time);
46013 printk(KERN_INFO
46014 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
46015- atomic_read(&sbi->s_mb_preallocated),
46016- atomic_read(&sbi->s_mb_discarded));
46017+ atomic_read_unchecked(&sbi->s_mb_preallocated),
46018+ atomic_read_unchecked(&sbi->s_mb_discarded));
46019 }
46020
46021 free_percpu(sbi->s_locality_groups);
46022@@ -3107,16 +3109,16 @@ static void ext4_mb_collect_stats(struct
46023 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46024
46025 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46026- atomic_inc(&sbi->s_bal_reqs);
46027- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46028+ atomic_inc_unchecked(&sbi->s_bal_reqs);
46029+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46030 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46031- atomic_inc(&sbi->s_bal_success);
46032- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46033+ atomic_inc_unchecked(&sbi->s_bal_success);
46034+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46035 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46036 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46037- atomic_inc(&sbi->s_bal_goals);
46038+ atomic_inc_unchecked(&sbi->s_bal_goals);
46039 if (ac->ac_found > sbi->s_mb_max_to_scan)
46040- atomic_inc(&sbi->s_bal_breaks);
46041+ atomic_inc_unchecked(&sbi->s_bal_breaks);
46042 }
46043
46044 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46045@@ -3514,7 +3516,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
46046 trace_ext4_mb_new_inode_pa(ac, pa);
46047
46048 ext4_mb_use_inode_pa(ac, pa);
46049- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46050+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46051
46052 ei = EXT4_I(ac->ac_inode);
46053 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46054@@ -3574,7 +3576,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
46055 trace_ext4_mb_new_group_pa(ac, pa);
46056
46057 ext4_mb_use_group_pa(ac, pa);
46058- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46059+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46060
46061 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46062 lg = ac->ac_lg;
46063@@ -3661,7 +3663,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
46064 * from the bitmap and continue.
46065 */
46066 }
46067- atomic_add(free, &sbi->s_mb_discarded);
46068+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
46069
46070 return err;
46071 }
46072@@ -3679,7 +3681,7 @@ ext4_mb_release_group_pa(struct ext4_bud
46073 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46074 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46075 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46076- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46077+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46078 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46079
46080 return 0;
46081diff -urNp linux-2.6.39.1/fs/fcntl.c linux-2.6.39.1/fs/fcntl.c
46082--- linux-2.6.39.1/fs/fcntl.c 2011-05-19 00:06:34.000000000 -0400
46083+++ linux-2.6.39.1/fs/fcntl.c 2011-05-22 20:45:50.000000000 -0400
46084@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
46085 if (err)
46086 return err;
46087
46088+ if (gr_handle_chroot_fowner(pid, type))
46089+ return -ENOENT;
46090+ if (gr_check_protected_task_fowner(pid, type))
46091+ return -EACCES;
46092+
46093 f_modown(filp, pid, type, force);
46094 return 0;
46095 }
46096@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
46097 switch (cmd) {
46098 case F_DUPFD:
46099 case F_DUPFD_CLOEXEC:
46100+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46101 if (arg >= rlimit(RLIMIT_NOFILE))
46102 break;
46103 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46104@@ -835,14 +841,14 @@ static int __init fcntl_init(void)
46105 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
46106 * is defined as O_NONBLOCK on some platforms and not on others.
46107 */
46108- BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
46109+ BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
46110 O_RDONLY | O_WRONLY | O_RDWR |
46111 O_CREAT | O_EXCL | O_NOCTTY |
46112 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
46113 __O_SYNC | O_DSYNC | FASYNC |
46114 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
46115 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
46116- __FMODE_EXEC | O_PATH
46117+ __FMODE_EXEC | O_PATH | FMODE_GREXEC
46118 ));
46119
46120 fasync_cache = kmem_cache_create("fasync_cache",
46121diff -urNp linux-2.6.39.1/fs/fifo.c linux-2.6.39.1/fs/fifo.c
46122--- linux-2.6.39.1/fs/fifo.c 2011-05-19 00:06:34.000000000 -0400
46123+++ linux-2.6.39.1/fs/fifo.c 2011-05-22 19:36:32.000000000 -0400
46124@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
46125 */
46126 filp->f_op = &read_pipefifo_fops;
46127 pipe->r_counter++;
46128- if (pipe->readers++ == 0)
46129+ if (atomic_inc_return(&pipe->readers) == 1)
46130 wake_up_partner(inode);
46131
46132- if (!pipe->writers) {
46133+ if (!atomic_read(&pipe->writers)) {
46134 if ((filp->f_flags & O_NONBLOCK)) {
46135 /* suppress POLLHUP until we have
46136 * seen a writer */
46137@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode
46138 * errno=ENXIO when there is no process reading the FIFO.
46139 */
46140 ret = -ENXIO;
46141- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46142+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46143 goto err;
46144
46145 filp->f_op = &write_pipefifo_fops;
46146 pipe->w_counter++;
46147- if (!pipe->writers++)
46148+ if (atomic_inc_return(&pipe->writers) == 1)
46149 wake_up_partner(inode);
46150
46151- if (!pipe->readers) {
46152+ if (!atomic_read(&pipe->readers)) {
46153 wait_for_partner(inode, &pipe->r_counter);
46154 if (signal_pending(current))
46155 goto err_wr;
46156@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode
46157 */
46158 filp->f_op = &rdwr_pipefifo_fops;
46159
46160- pipe->readers++;
46161- pipe->writers++;
46162+ atomic_inc(&pipe->readers);
46163+ atomic_inc(&pipe->writers);
46164 pipe->r_counter++;
46165 pipe->w_counter++;
46166- if (pipe->readers == 1 || pipe->writers == 1)
46167+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46168 wake_up_partner(inode);
46169 break;
46170
46171@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode
46172 return 0;
46173
46174 err_rd:
46175- if (!--pipe->readers)
46176+ if (atomic_dec_and_test(&pipe->readers))
46177 wake_up_interruptible(&pipe->wait);
46178 ret = -ERESTARTSYS;
46179 goto err;
46180
46181 err_wr:
46182- if (!--pipe->writers)
46183+ if (atomic_dec_and_test(&pipe->writers))
46184 wake_up_interruptible(&pipe->wait);
46185 ret = -ERESTARTSYS;
46186 goto err;
46187
46188 err:
46189- if (!pipe->readers && !pipe->writers)
46190+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46191 free_pipe_info(inode);
46192
46193 err_nocleanup:
46194diff -urNp linux-2.6.39.1/fs/file.c linux-2.6.39.1/fs/file.c
46195--- linux-2.6.39.1/fs/file.c 2011-05-19 00:06:34.000000000 -0400
46196+++ linux-2.6.39.1/fs/file.c 2011-05-22 19:41:37.000000000 -0400
46197@@ -15,6 +15,7 @@
46198 #include <linux/slab.h>
46199 #include <linux/vmalloc.h>
46200 #include <linux/file.h>
46201+#include <linux/security.h>
46202 #include <linux/fdtable.h>
46203 #include <linux/bitops.h>
46204 #include <linux/interrupt.h>
46205@@ -254,6 +255,7 @@ int expand_files(struct files_struct *fi
46206 * N.B. For clone tasks sharing a files structure, this test
46207 * will limit the total number of files that can be opened.
46208 */
46209+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46210 if (nr >= rlimit(RLIMIT_NOFILE))
46211 return -EMFILE;
46212
46213diff -urNp linux-2.6.39.1/fs/filesystems.c linux-2.6.39.1/fs/filesystems.c
46214--- linux-2.6.39.1/fs/filesystems.c 2011-05-19 00:06:34.000000000 -0400
46215+++ linux-2.6.39.1/fs/filesystems.c 2011-05-22 19:41:37.000000000 -0400
46216@@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(con
46217 int len = dot ? dot - name : strlen(name);
46218
46219 fs = __get_fs_type(name, len);
46220+
46221+#ifdef CONFIG_GRKERNSEC_MODHARDEN
46222+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46223+#else
46224 if (!fs && (request_module("%.*s", len, name) == 0))
46225+#endif
46226 fs = __get_fs_type(name, len);
46227
46228 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46229diff -urNp linux-2.6.39.1/fs/fscache/cookie.c linux-2.6.39.1/fs/fscache/cookie.c
46230--- linux-2.6.39.1/fs/fscache/cookie.c 2011-05-19 00:06:34.000000000 -0400
46231+++ linux-2.6.39.1/fs/fscache/cookie.c 2011-05-22 19:36:32.000000000 -0400
46232@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
46233 parent ? (char *) parent->def->name : "<no-parent>",
46234 def->name, netfs_data);
46235
46236- fscache_stat(&fscache_n_acquires);
46237+ fscache_stat_unchecked(&fscache_n_acquires);
46238
46239 /* if there's no parent cookie, then we don't create one here either */
46240 if (!parent) {
46241- fscache_stat(&fscache_n_acquires_null);
46242+ fscache_stat_unchecked(&fscache_n_acquires_null);
46243 _leave(" [no parent]");
46244 return NULL;
46245 }
46246@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
46247 /* allocate and initialise a cookie */
46248 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46249 if (!cookie) {
46250- fscache_stat(&fscache_n_acquires_oom);
46251+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46252 _leave(" [ENOMEM]");
46253 return NULL;
46254 }
46255@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
46256
46257 switch (cookie->def->type) {
46258 case FSCACHE_COOKIE_TYPE_INDEX:
46259- fscache_stat(&fscache_n_cookie_index);
46260+ fscache_stat_unchecked(&fscache_n_cookie_index);
46261 break;
46262 case FSCACHE_COOKIE_TYPE_DATAFILE:
46263- fscache_stat(&fscache_n_cookie_data);
46264+ fscache_stat_unchecked(&fscache_n_cookie_data);
46265 break;
46266 default:
46267- fscache_stat(&fscache_n_cookie_special);
46268+ fscache_stat_unchecked(&fscache_n_cookie_special);
46269 break;
46270 }
46271
46272@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
46273 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46274 atomic_dec(&parent->n_children);
46275 __fscache_cookie_put(cookie);
46276- fscache_stat(&fscache_n_acquires_nobufs);
46277+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46278 _leave(" = NULL");
46279 return NULL;
46280 }
46281 }
46282
46283- fscache_stat(&fscache_n_acquires_ok);
46284+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46285 _leave(" = %p", cookie);
46286 return cookie;
46287 }
46288@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
46289 cache = fscache_select_cache_for_object(cookie->parent);
46290 if (!cache) {
46291 up_read(&fscache_addremove_sem);
46292- fscache_stat(&fscache_n_acquires_no_cache);
46293+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46294 _leave(" = -ENOMEDIUM [no cache]");
46295 return -ENOMEDIUM;
46296 }
46297@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
46298 object = cache->ops->alloc_object(cache, cookie);
46299 fscache_stat_d(&fscache_n_cop_alloc_object);
46300 if (IS_ERR(object)) {
46301- fscache_stat(&fscache_n_object_no_alloc);
46302+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46303 ret = PTR_ERR(object);
46304 goto error;
46305 }
46306
46307- fscache_stat(&fscache_n_object_alloc);
46308+ fscache_stat_unchecked(&fscache_n_object_alloc);
46309
46310 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46311
46312@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
46313 struct fscache_object *object;
46314 struct hlist_node *_p;
46315
46316- fscache_stat(&fscache_n_updates);
46317+ fscache_stat_unchecked(&fscache_n_updates);
46318
46319 if (!cookie) {
46320- fscache_stat(&fscache_n_updates_null);
46321+ fscache_stat_unchecked(&fscache_n_updates_null);
46322 _leave(" [no cookie]");
46323 return;
46324 }
46325@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
46326 struct fscache_object *object;
46327 unsigned long event;
46328
46329- fscache_stat(&fscache_n_relinquishes);
46330+ fscache_stat_unchecked(&fscache_n_relinquishes);
46331 if (retire)
46332- fscache_stat(&fscache_n_relinquishes_retire);
46333+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46334
46335 if (!cookie) {
46336- fscache_stat(&fscache_n_relinquishes_null);
46337+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46338 _leave(" [no cookie]");
46339 return;
46340 }
46341@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
46342
46343 /* wait for the cookie to finish being instantiated (or to fail) */
46344 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46345- fscache_stat(&fscache_n_relinquishes_waitcrt);
46346+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46347 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46348 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46349 }
46350diff -urNp linux-2.6.39.1/fs/fscache/internal.h linux-2.6.39.1/fs/fscache/internal.h
46351--- linux-2.6.39.1/fs/fscache/internal.h 2011-05-19 00:06:34.000000000 -0400
46352+++ linux-2.6.39.1/fs/fscache/internal.h 2011-05-22 19:36:32.000000000 -0400
46353@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46354 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46355 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46356
46357-extern atomic_t fscache_n_op_pend;
46358-extern atomic_t fscache_n_op_run;
46359-extern atomic_t fscache_n_op_enqueue;
46360-extern atomic_t fscache_n_op_deferred_release;
46361-extern atomic_t fscache_n_op_release;
46362-extern atomic_t fscache_n_op_gc;
46363-extern atomic_t fscache_n_op_cancelled;
46364-extern atomic_t fscache_n_op_rejected;
46365-
46366-extern atomic_t fscache_n_attr_changed;
46367-extern atomic_t fscache_n_attr_changed_ok;
46368-extern atomic_t fscache_n_attr_changed_nobufs;
46369-extern atomic_t fscache_n_attr_changed_nomem;
46370-extern atomic_t fscache_n_attr_changed_calls;
46371-
46372-extern atomic_t fscache_n_allocs;
46373-extern atomic_t fscache_n_allocs_ok;
46374-extern atomic_t fscache_n_allocs_wait;
46375-extern atomic_t fscache_n_allocs_nobufs;
46376-extern atomic_t fscache_n_allocs_intr;
46377-extern atomic_t fscache_n_allocs_object_dead;
46378-extern atomic_t fscache_n_alloc_ops;
46379-extern atomic_t fscache_n_alloc_op_waits;
46380-
46381-extern atomic_t fscache_n_retrievals;
46382-extern atomic_t fscache_n_retrievals_ok;
46383-extern atomic_t fscache_n_retrievals_wait;
46384-extern atomic_t fscache_n_retrievals_nodata;
46385-extern atomic_t fscache_n_retrievals_nobufs;
46386-extern atomic_t fscache_n_retrievals_intr;
46387-extern atomic_t fscache_n_retrievals_nomem;
46388-extern atomic_t fscache_n_retrievals_object_dead;
46389-extern atomic_t fscache_n_retrieval_ops;
46390-extern atomic_t fscache_n_retrieval_op_waits;
46391-
46392-extern atomic_t fscache_n_stores;
46393-extern atomic_t fscache_n_stores_ok;
46394-extern atomic_t fscache_n_stores_again;
46395-extern atomic_t fscache_n_stores_nobufs;
46396-extern atomic_t fscache_n_stores_oom;
46397-extern atomic_t fscache_n_store_ops;
46398-extern atomic_t fscache_n_store_calls;
46399-extern atomic_t fscache_n_store_pages;
46400-extern atomic_t fscache_n_store_radix_deletes;
46401-extern atomic_t fscache_n_store_pages_over_limit;
46402-
46403-extern atomic_t fscache_n_store_vmscan_not_storing;
46404-extern atomic_t fscache_n_store_vmscan_gone;
46405-extern atomic_t fscache_n_store_vmscan_busy;
46406-extern atomic_t fscache_n_store_vmscan_cancelled;
46407-
46408-extern atomic_t fscache_n_marks;
46409-extern atomic_t fscache_n_uncaches;
46410-
46411-extern atomic_t fscache_n_acquires;
46412-extern atomic_t fscache_n_acquires_null;
46413-extern atomic_t fscache_n_acquires_no_cache;
46414-extern atomic_t fscache_n_acquires_ok;
46415-extern atomic_t fscache_n_acquires_nobufs;
46416-extern atomic_t fscache_n_acquires_oom;
46417-
46418-extern atomic_t fscache_n_updates;
46419-extern atomic_t fscache_n_updates_null;
46420-extern atomic_t fscache_n_updates_run;
46421-
46422-extern atomic_t fscache_n_relinquishes;
46423-extern atomic_t fscache_n_relinquishes_null;
46424-extern atomic_t fscache_n_relinquishes_waitcrt;
46425-extern atomic_t fscache_n_relinquishes_retire;
46426-
46427-extern atomic_t fscache_n_cookie_index;
46428-extern atomic_t fscache_n_cookie_data;
46429-extern atomic_t fscache_n_cookie_special;
46430-
46431-extern atomic_t fscache_n_object_alloc;
46432-extern atomic_t fscache_n_object_no_alloc;
46433-extern atomic_t fscache_n_object_lookups;
46434-extern atomic_t fscache_n_object_lookups_negative;
46435-extern atomic_t fscache_n_object_lookups_positive;
46436-extern atomic_t fscache_n_object_lookups_timed_out;
46437-extern atomic_t fscache_n_object_created;
46438-extern atomic_t fscache_n_object_avail;
46439-extern atomic_t fscache_n_object_dead;
46440-
46441-extern atomic_t fscache_n_checkaux_none;
46442-extern atomic_t fscache_n_checkaux_okay;
46443-extern atomic_t fscache_n_checkaux_update;
46444-extern atomic_t fscache_n_checkaux_obsolete;
46445+extern atomic_unchecked_t fscache_n_op_pend;
46446+extern atomic_unchecked_t fscache_n_op_run;
46447+extern atomic_unchecked_t fscache_n_op_enqueue;
46448+extern atomic_unchecked_t fscache_n_op_deferred_release;
46449+extern atomic_unchecked_t fscache_n_op_release;
46450+extern atomic_unchecked_t fscache_n_op_gc;
46451+extern atomic_unchecked_t fscache_n_op_cancelled;
46452+extern atomic_unchecked_t fscache_n_op_rejected;
46453+
46454+extern atomic_unchecked_t fscache_n_attr_changed;
46455+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46456+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46457+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46458+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46459+
46460+extern atomic_unchecked_t fscache_n_allocs;
46461+extern atomic_unchecked_t fscache_n_allocs_ok;
46462+extern atomic_unchecked_t fscache_n_allocs_wait;
46463+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46464+extern atomic_unchecked_t fscache_n_allocs_intr;
46465+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46466+extern atomic_unchecked_t fscache_n_alloc_ops;
46467+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46468+
46469+extern atomic_unchecked_t fscache_n_retrievals;
46470+extern atomic_unchecked_t fscache_n_retrievals_ok;
46471+extern atomic_unchecked_t fscache_n_retrievals_wait;
46472+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46473+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46474+extern atomic_unchecked_t fscache_n_retrievals_intr;
46475+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46476+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46477+extern atomic_unchecked_t fscache_n_retrieval_ops;
46478+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46479+
46480+extern atomic_unchecked_t fscache_n_stores;
46481+extern atomic_unchecked_t fscache_n_stores_ok;
46482+extern atomic_unchecked_t fscache_n_stores_again;
46483+extern atomic_unchecked_t fscache_n_stores_nobufs;
46484+extern atomic_unchecked_t fscache_n_stores_oom;
46485+extern atomic_unchecked_t fscache_n_store_ops;
46486+extern atomic_unchecked_t fscache_n_store_calls;
46487+extern atomic_unchecked_t fscache_n_store_pages;
46488+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46489+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46490+
46491+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46492+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46493+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46494+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46495+
46496+extern atomic_unchecked_t fscache_n_marks;
46497+extern atomic_unchecked_t fscache_n_uncaches;
46498+
46499+extern atomic_unchecked_t fscache_n_acquires;
46500+extern atomic_unchecked_t fscache_n_acquires_null;
46501+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46502+extern atomic_unchecked_t fscache_n_acquires_ok;
46503+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46504+extern atomic_unchecked_t fscache_n_acquires_oom;
46505+
46506+extern atomic_unchecked_t fscache_n_updates;
46507+extern atomic_unchecked_t fscache_n_updates_null;
46508+extern atomic_unchecked_t fscache_n_updates_run;
46509+
46510+extern atomic_unchecked_t fscache_n_relinquishes;
46511+extern atomic_unchecked_t fscache_n_relinquishes_null;
46512+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46513+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46514+
46515+extern atomic_unchecked_t fscache_n_cookie_index;
46516+extern atomic_unchecked_t fscache_n_cookie_data;
46517+extern atomic_unchecked_t fscache_n_cookie_special;
46518+
46519+extern atomic_unchecked_t fscache_n_object_alloc;
46520+extern atomic_unchecked_t fscache_n_object_no_alloc;
46521+extern atomic_unchecked_t fscache_n_object_lookups;
46522+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46523+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46524+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46525+extern atomic_unchecked_t fscache_n_object_created;
46526+extern atomic_unchecked_t fscache_n_object_avail;
46527+extern atomic_unchecked_t fscache_n_object_dead;
46528+
46529+extern atomic_unchecked_t fscache_n_checkaux_none;
46530+extern atomic_unchecked_t fscache_n_checkaux_okay;
46531+extern atomic_unchecked_t fscache_n_checkaux_update;
46532+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46533
46534 extern atomic_t fscache_n_cop_alloc_object;
46535 extern atomic_t fscache_n_cop_lookup_object;
46536@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t
46537 atomic_inc(stat);
46538 }
46539
46540+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46541+{
46542+ atomic_inc_unchecked(stat);
46543+}
46544+
46545 static inline void fscache_stat_d(atomic_t *stat)
46546 {
46547 atomic_dec(stat);
46548@@ -267,6 +272,7 @@ extern const struct file_operations fsca
46549
46550 #define __fscache_stat(stat) (NULL)
46551 #define fscache_stat(stat) do {} while (0)
46552+#define fscache_stat_unchecked(stat) do {} while (0)
46553 #define fscache_stat_d(stat) do {} while (0)
46554 #endif
46555
46556diff -urNp linux-2.6.39.1/fs/fscache/object.c linux-2.6.39.1/fs/fscache/object.c
46557--- linux-2.6.39.1/fs/fscache/object.c 2011-05-19 00:06:34.000000000 -0400
46558+++ linux-2.6.39.1/fs/fscache/object.c 2011-05-22 19:36:32.000000000 -0400
46559@@ -128,7 +128,7 @@ static void fscache_object_state_machine
46560 /* update the object metadata on disk */
46561 case FSCACHE_OBJECT_UPDATING:
46562 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46563- fscache_stat(&fscache_n_updates_run);
46564+ fscache_stat_unchecked(&fscache_n_updates_run);
46565 fscache_stat(&fscache_n_cop_update_object);
46566 object->cache->ops->update_object(object);
46567 fscache_stat_d(&fscache_n_cop_update_object);
46568@@ -217,7 +217,7 @@ static void fscache_object_state_machine
46569 spin_lock(&object->lock);
46570 object->state = FSCACHE_OBJECT_DEAD;
46571 spin_unlock(&object->lock);
46572- fscache_stat(&fscache_n_object_dead);
46573+ fscache_stat_unchecked(&fscache_n_object_dead);
46574 goto terminal_transit;
46575
46576 /* handle the parent cache of this object being withdrawn from
46577@@ -232,7 +232,7 @@ static void fscache_object_state_machine
46578 spin_lock(&object->lock);
46579 object->state = FSCACHE_OBJECT_DEAD;
46580 spin_unlock(&object->lock);
46581- fscache_stat(&fscache_n_object_dead);
46582+ fscache_stat_unchecked(&fscache_n_object_dead);
46583 goto terminal_transit;
46584
46585 /* complain about the object being woken up once it is
46586@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct
46587 parent->cookie->def->name, cookie->def->name,
46588 object->cache->tag->name);
46589
46590- fscache_stat(&fscache_n_object_lookups);
46591+ fscache_stat_unchecked(&fscache_n_object_lookups);
46592 fscache_stat(&fscache_n_cop_lookup_object);
46593 ret = object->cache->ops->lookup_object(object);
46594 fscache_stat_d(&fscache_n_cop_lookup_object);
46595@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct
46596 if (ret == -ETIMEDOUT) {
46597 /* probably stuck behind another object, so move this one to
46598 * the back of the queue */
46599- fscache_stat(&fscache_n_object_lookups_timed_out);
46600+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46601 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46602 }
46603
46604@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(stru
46605
46606 spin_lock(&object->lock);
46607 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46608- fscache_stat(&fscache_n_object_lookups_negative);
46609+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46610
46611 /* transit here to allow write requests to begin stacking up
46612 * and read requests to begin returning ENODATA */
46613@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fsca
46614 * result, in which case there may be data available */
46615 spin_lock(&object->lock);
46616 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46617- fscache_stat(&fscache_n_object_lookups_positive);
46618+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46619
46620 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46621
46622@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fsca
46623 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46624 } else {
46625 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46626- fscache_stat(&fscache_n_object_created);
46627+ fscache_stat_unchecked(&fscache_n_object_created);
46628
46629 object->state = FSCACHE_OBJECT_AVAILABLE;
46630 spin_unlock(&object->lock);
46631@@ -602,7 +602,7 @@ static void fscache_object_available(str
46632 fscache_enqueue_dependents(object);
46633
46634 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46635- fscache_stat(&fscache_n_object_avail);
46636+ fscache_stat_unchecked(&fscache_n_object_avail);
46637
46638 _leave("");
46639 }
46640@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
46641 enum fscache_checkaux result;
46642
46643 if (!object->cookie->def->check_aux) {
46644- fscache_stat(&fscache_n_checkaux_none);
46645+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46646 return FSCACHE_CHECKAUX_OKAY;
46647 }
46648
46649@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
46650 switch (result) {
46651 /* entry okay as is */
46652 case FSCACHE_CHECKAUX_OKAY:
46653- fscache_stat(&fscache_n_checkaux_okay);
46654+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46655 break;
46656
46657 /* entry requires update */
46658 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46659- fscache_stat(&fscache_n_checkaux_update);
46660+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46661 break;
46662
46663 /* entry requires deletion */
46664 case FSCACHE_CHECKAUX_OBSOLETE:
46665- fscache_stat(&fscache_n_checkaux_obsolete);
46666+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46667 break;
46668
46669 default:
46670diff -urNp linux-2.6.39.1/fs/fscache/operation.c linux-2.6.39.1/fs/fscache/operation.c
46671--- linux-2.6.39.1/fs/fscache/operation.c 2011-05-19 00:06:34.000000000 -0400
46672+++ linux-2.6.39.1/fs/fscache/operation.c 2011-05-22 19:36:32.000000000 -0400
46673@@ -17,7 +17,7 @@
46674 #include <linux/slab.h>
46675 #include "internal.h"
46676
46677-atomic_t fscache_op_debug_id;
46678+atomic_unchecked_t fscache_op_debug_id;
46679 EXPORT_SYMBOL(fscache_op_debug_id);
46680
46681 /**
46682@@ -40,7 +40,7 @@ void fscache_enqueue_operation(struct fs
46683 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46684 ASSERTCMP(atomic_read(&op->usage), >, 0);
46685
46686- fscache_stat(&fscache_n_op_enqueue);
46687+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46688 switch (op->flags & FSCACHE_OP_TYPE) {
46689 case FSCACHE_OP_ASYNC:
46690 _debug("queue async");
46691@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscach
46692 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46693 if (op->processor)
46694 fscache_enqueue_operation(op);
46695- fscache_stat(&fscache_n_op_run);
46696+ fscache_stat_unchecked(&fscache_n_op_run);
46697 }
46698
46699 /*
46700@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct f
46701 if (object->n_ops > 1) {
46702 atomic_inc(&op->usage);
46703 list_add_tail(&op->pend_link, &object->pending_ops);
46704- fscache_stat(&fscache_n_op_pend);
46705+ fscache_stat_unchecked(&fscache_n_op_pend);
46706 } else if (!list_empty(&object->pending_ops)) {
46707 atomic_inc(&op->usage);
46708 list_add_tail(&op->pend_link, &object->pending_ops);
46709- fscache_stat(&fscache_n_op_pend);
46710+ fscache_stat_unchecked(&fscache_n_op_pend);
46711 fscache_start_operations(object);
46712 } else {
46713 ASSERTCMP(object->n_in_progress, ==, 0);
46714@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct f
46715 object->n_exclusive++; /* reads and writes must wait */
46716 atomic_inc(&op->usage);
46717 list_add_tail(&op->pend_link, &object->pending_ops);
46718- fscache_stat(&fscache_n_op_pend);
46719+ fscache_stat_unchecked(&fscache_n_op_pend);
46720 ret = 0;
46721 } else {
46722 /* not allowed to submit ops in any other state */
46723@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_obj
46724 if (object->n_exclusive > 0) {
46725 atomic_inc(&op->usage);
46726 list_add_tail(&op->pend_link, &object->pending_ops);
46727- fscache_stat(&fscache_n_op_pend);
46728+ fscache_stat_unchecked(&fscache_n_op_pend);
46729 } else if (!list_empty(&object->pending_ops)) {
46730 atomic_inc(&op->usage);
46731 list_add_tail(&op->pend_link, &object->pending_ops);
46732- fscache_stat(&fscache_n_op_pend);
46733+ fscache_stat_unchecked(&fscache_n_op_pend);
46734 fscache_start_operations(object);
46735 } else {
46736 ASSERTCMP(object->n_exclusive, ==, 0);
46737@@ -227,12 +227,12 @@ int fscache_submit_op(struct fscache_obj
46738 object->n_ops++;
46739 atomic_inc(&op->usage);
46740 list_add_tail(&op->pend_link, &object->pending_ops);
46741- fscache_stat(&fscache_n_op_pend);
46742+ fscache_stat_unchecked(&fscache_n_op_pend);
46743 ret = 0;
46744 } else if (object->state == FSCACHE_OBJECT_DYING ||
46745 object->state == FSCACHE_OBJECT_LC_DYING ||
46746 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46747- fscache_stat(&fscache_n_op_rejected);
46748+ fscache_stat_unchecked(&fscache_n_op_rejected);
46749 ret = -ENOBUFS;
46750 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46751 fscache_report_unexpected_submission(object, op, ostate);
46752@@ -302,7 +302,7 @@ int fscache_cancel_op(struct fscache_ope
46753
46754 ret = -EBUSY;
46755 if (!list_empty(&op->pend_link)) {
46756- fscache_stat(&fscache_n_op_cancelled);
46757+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46758 list_del_init(&op->pend_link);
46759 object->n_ops--;
46760 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46761@@ -341,7 +341,7 @@ void fscache_put_operation(struct fscach
46762 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46763 BUG();
46764
46765- fscache_stat(&fscache_n_op_release);
46766+ fscache_stat_unchecked(&fscache_n_op_release);
46767
46768 if (op->release) {
46769 op->release(op);
46770@@ -358,7 +358,7 @@ void fscache_put_operation(struct fscach
46771 * lock, and defer it otherwise */
46772 if (!spin_trylock(&object->lock)) {
46773 _debug("defer put");
46774- fscache_stat(&fscache_n_op_deferred_release);
46775+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46776
46777 cache = object->cache;
46778 spin_lock(&cache->op_gc_list_lock);
46779@@ -420,7 +420,7 @@ void fscache_operation_gc(struct work_st
46780
46781 _debug("GC DEFERRED REL OBJ%x OP%x",
46782 object->debug_id, op->debug_id);
46783- fscache_stat(&fscache_n_op_gc);
46784+ fscache_stat_unchecked(&fscache_n_op_gc);
46785
46786 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46787
46788diff -urNp linux-2.6.39.1/fs/fscache/page.c linux-2.6.39.1/fs/fscache/page.c
46789--- linux-2.6.39.1/fs/fscache/page.c 2011-05-19 00:06:34.000000000 -0400
46790+++ linux-2.6.39.1/fs/fscache/page.c 2011-05-22 19:36:32.000000000 -0400
46791@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct
46792 val = radix_tree_lookup(&cookie->stores, page->index);
46793 if (!val) {
46794 rcu_read_unlock();
46795- fscache_stat(&fscache_n_store_vmscan_not_storing);
46796+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46797 __fscache_uncache_page(cookie, page);
46798 return true;
46799 }
46800@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct
46801 spin_unlock(&cookie->stores_lock);
46802
46803 if (xpage) {
46804- fscache_stat(&fscache_n_store_vmscan_cancelled);
46805- fscache_stat(&fscache_n_store_radix_deletes);
46806+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46807+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46808 ASSERTCMP(xpage, ==, page);
46809 } else {
46810- fscache_stat(&fscache_n_store_vmscan_gone);
46811+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46812 }
46813
46814 wake_up_bit(&cookie->flags, 0);
46815@@ -107,7 +107,7 @@ page_busy:
46816 /* we might want to wait here, but that could deadlock the allocator as
46817 * the work threads writing to the cache may all end up sleeping
46818 * on memory allocation */
46819- fscache_stat(&fscache_n_store_vmscan_busy);
46820+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46821 return false;
46822 }
46823 EXPORT_SYMBOL(__fscache_maybe_release_page);
46824@@ -131,7 +131,7 @@ static void fscache_end_page_write(struc
46825 FSCACHE_COOKIE_STORING_TAG);
46826 if (!radix_tree_tag_get(&cookie->stores, page->index,
46827 FSCACHE_COOKIE_PENDING_TAG)) {
46828- fscache_stat(&fscache_n_store_radix_deletes);
46829+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46830 xpage = radix_tree_delete(&cookie->stores, page->index);
46831 }
46832 spin_unlock(&cookie->stores_lock);
46833@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(stru
46834
46835 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46836
46837- fscache_stat(&fscache_n_attr_changed_calls);
46838+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46839
46840 if (fscache_object_is_active(object)) {
46841 fscache_set_op_state(op, "CallFS");
46842@@ -179,11 +179,11 @@ int __fscache_attr_changed(struct fscach
46843
46844 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46845
46846- fscache_stat(&fscache_n_attr_changed);
46847+ fscache_stat_unchecked(&fscache_n_attr_changed);
46848
46849 op = kzalloc(sizeof(*op), GFP_KERNEL);
46850 if (!op) {
46851- fscache_stat(&fscache_n_attr_changed_nomem);
46852+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46853 _leave(" = -ENOMEM");
46854 return -ENOMEM;
46855 }
46856@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
46857 if (fscache_submit_exclusive_op(object, op) < 0)
46858 goto nobufs;
46859 spin_unlock(&cookie->lock);
46860- fscache_stat(&fscache_n_attr_changed_ok);
46861+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46862 fscache_put_operation(op);
46863 _leave(" = 0");
46864 return 0;
46865@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
46866 nobufs:
46867 spin_unlock(&cookie->lock);
46868 kfree(op);
46869- fscache_stat(&fscache_n_attr_changed_nobufs);
46870+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46871 _leave(" = %d", -ENOBUFS);
46872 return -ENOBUFS;
46873 }
46874@@ -246,7 +246,7 @@ static struct fscache_retrieval *fscache
46875 /* allocate a retrieval operation and attempt to submit it */
46876 op = kzalloc(sizeof(*op), GFP_NOIO);
46877 if (!op) {
46878- fscache_stat(&fscache_n_retrievals_nomem);
46879+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46880 return NULL;
46881 }
46882
46883@@ -275,13 +275,13 @@ static int fscache_wait_for_deferred_loo
46884 return 0;
46885 }
46886
46887- fscache_stat(&fscache_n_retrievals_wait);
46888+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46889
46890 jif = jiffies;
46891 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46892 fscache_wait_bit_interruptible,
46893 TASK_INTERRUPTIBLE) != 0) {
46894- fscache_stat(&fscache_n_retrievals_intr);
46895+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46896 _leave(" = -ERESTARTSYS");
46897 return -ERESTARTSYS;
46898 }
46899@@ -299,8 +299,8 @@ static int fscache_wait_for_deferred_loo
46900 */
46901 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46902 struct fscache_retrieval *op,
46903- atomic_t *stat_op_waits,
46904- atomic_t *stat_object_dead)
46905+ atomic_unchecked_t *stat_op_waits,
46906+ atomic_unchecked_t *stat_object_dead)
46907 {
46908 int ret;
46909
46910@@ -308,7 +308,7 @@ static int fscache_wait_for_retrieval_ac
46911 goto check_if_dead;
46912
46913 _debug(">>> WT");
46914- fscache_stat(stat_op_waits);
46915+ fscache_stat_unchecked(stat_op_waits);
46916 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46917 fscache_wait_bit_interruptible,
46918 TASK_INTERRUPTIBLE) < 0) {
46919@@ -325,7 +325,7 @@ static int fscache_wait_for_retrieval_ac
46920
46921 check_if_dead:
46922 if (unlikely(fscache_object_is_dead(object))) {
46923- fscache_stat(stat_object_dead);
46924+ fscache_stat_unchecked(stat_object_dead);
46925 return -ENOBUFS;
46926 }
46927 return 0;
46928@@ -352,7 +352,7 @@ int __fscache_read_or_alloc_page(struct
46929
46930 _enter("%p,%p,,,", cookie, page);
46931
46932- fscache_stat(&fscache_n_retrievals);
46933+ fscache_stat_unchecked(&fscache_n_retrievals);
46934
46935 if (hlist_empty(&cookie->backing_objects))
46936 goto nobufs;
46937@@ -386,7 +386,7 @@ int __fscache_read_or_alloc_page(struct
46938 goto nobufs_unlock;
46939 spin_unlock(&cookie->lock);
46940
46941- fscache_stat(&fscache_n_retrieval_ops);
46942+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46943
46944 /* pin the netfs read context in case we need to do the actual netfs
46945 * read because we've encountered a cache read failure */
46946@@ -416,15 +416,15 @@ int __fscache_read_or_alloc_page(struct
46947
46948 error:
46949 if (ret == -ENOMEM)
46950- fscache_stat(&fscache_n_retrievals_nomem);
46951+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46952 else if (ret == -ERESTARTSYS)
46953- fscache_stat(&fscache_n_retrievals_intr);
46954+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46955 else if (ret == -ENODATA)
46956- fscache_stat(&fscache_n_retrievals_nodata);
46957+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46958 else if (ret < 0)
46959- fscache_stat(&fscache_n_retrievals_nobufs);
46960+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46961 else
46962- fscache_stat(&fscache_n_retrievals_ok);
46963+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46964
46965 fscache_put_retrieval(op);
46966 _leave(" = %d", ret);
46967@@ -434,7 +434,7 @@ nobufs_unlock:
46968 spin_unlock(&cookie->lock);
46969 kfree(op);
46970 nobufs:
46971- fscache_stat(&fscache_n_retrievals_nobufs);
46972+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46973 _leave(" = -ENOBUFS");
46974 return -ENOBUFS;
46975 }
46976@@ -472,7 +472,7 @@ int __fscache_read_or_alloc_pages(struct
46977
46978 _enter("%p,,%d,,,", cookie, *nr_pages);
46979
46980- fscache_stat(&fscache_n_retrievals);
46981+ fscache_stat_unchecked(&fscache_n_retrievals);
46982
46983 if (hlist_empty(&cookie->backing_objects))
46984 goto nobufs;
46985@@ -503,7 +503,7 @@ int __fscache_read_or_alloc_pages(struct
46986 goto nobufs_unlock;
46987 spin_unlock(&cookie->lock);
46988
46989- fscache_stat(&fscache_n_retrieval_ops);
46990+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46991
46992 /* pin the netfs read context in case we need to do the actual netfs
46993 * read because we've encountered a cache read failure */
46994@@ -533,15 +533,15 @@ int __fscache_read_or_alloc_pages(struct
46995
46996 error:
46997 if (ret == -ENOMEM)
46998- fscache_stat(&fscache_n_retrievals_nomem);
46999+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47000 else if (ret == -ERESTARTSYS)
47001- fscache_stat(&fscache_n_retrievals_intr);
47002+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47003 else if (ret == -ENODATA)
47004- fscache_stat(&fscache_n_retrievals_nodata);
47005+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47006 else if (ret < 0)
47007- fscache_stat(&fscache_n_retrievals_nobufs);
47008+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47009 else
47010- fscache_stat(&fscache_n_retrievals_ok);
47011+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
47012
47013 fscache_put_retrieval(op);
47014 _leave(" = %d", ret);
47015@@ -551,7 +551,7 @@ nobufs_unlock:
47016 spin_unlock(&cookie->lock);
47017 kfree(op);
47018 nobufs:
47019- fscache_stat(&fscache_n_retrievals_nobufs);
47020+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47021 _leave(" = -ENOBUFS");
47022 return -ENOBUFS;
47023 }
47024@@ -575,7 +575,7 @@ int __fscache_alloc_page(struct fscache_
47025
47026 _enter("%p,%p,,,", cookie, page);
47027
47028- fscache_stat(&fscache_n_allocs);
47029+ fscache_stat_unchecked(&fscache_n_allocs);
47030
47031 if (hlist_empty(&cookie->backing_objects))
47032 goto nobufs;
47033@@ -602,7 +602,7 @@ int __fscache_alloc_page(struct fscache_
47034 goto nobufs_unlock;
47035 spin_unlock(&cookie->lock);
47036
47037- fscache_stat(&fscache_n_alloc_ops);
47038+ fscache_stat_unchecked(&fscache_n_alloc_ops);
47039
47040 ret = fscache_wait_for_retrieval_activation(
47041 object, op,
47042@@ -618,11 +618,11 @@ int __fscache_alloc_page(struct fscache_
47043
47044 error:
47045 if (ret == -ERESTARTSYS)
47046- fscache_stat(&fscache_n_allocs_intr);
47047+ fscache_stat_unchecked(&fscache_n_allocs_intr);
47048 else if (ret < 0)
47049- fscache_stat(&fscache_n_allocs_nobufs);
47050+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47051 else
47052- fscache_stat(&fscache_n_allocs_ok);
47053+ fscache_stat_unchecked(&fscache_n_allocs_ok);
47054
47055 fscache_put_retrieval(op);
47056 _leave(" = %d", ret);
47057@@ -632,7 +632,7 @@ nobufs_unlock:
47058 spin_unlock(&cookie->lock);
47059 kfree(op);
47060 nobufs:
47061- fscache_stat(&fscache_n_allocs_nobufs);
47062+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47063 _leave(" = -ENOBUFS");
47064 return -ENOBUFS;
47065 }
47066@@ -675,7 +675,7 @@ static void fscache_write_op(struct fsca
47067
47068 spin_lock(&cookie->stores_lock);
47069
47070- fscache_stat(&fscache_n_store_calls);
47071+ fscache_stat_unchecked(&fscache_n_store_calls);
47072
47073 /* find a page to store */
47074 page = NULL;
47075@@ -686,7 +686,7 @@ static void fscache_write_op(struct fsca
47076 page = results[0];
47077 _debug("gang %d [%lx]", n, page->index);
47078 if (page->index > op->store_limit) {
47079- fscache_stat(&fscache_n_store_pages_over_limit);
47080+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47081 goto superseded;
47082 }
47083
47084@@ -699,7 +699,7 @@ static void fscache_write_op(struct fsca
47085 spin_unlock(&object->lock);
47086
47087 fscache_set_op_state(&op->op, "Store");
47088- fscache_stat(&fscache_n_store_pages);
47089+ fscache_stat_unchecked(&fscache_n_store_pages);
47090 fscache_stat(&fscache_n_cop_write_page);
47091 ret = object->cache->ops->write_page(op, page);
47092 fscache_stat_d(&fscache_n_cop_write_page);
47093@@ -769,7 +769,7 @@ int __fscache_write_page(struct fscache_
47094 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47095 ASSERT(PageFsCache(page));
47096
47097- fscache_stat(&fscache_n_stores);
47098+ fscache_stat_unchecked(&fscache_n_stores);
47099
47100 op = kzalloc(sizeof(*op), GFP_NOIO);
47101 if (!op)
47102@@ -821,7 +821,7 @@ int __fscache_write_page(struct fscache_
47103 spin_unlock(&cookie->stores_lock);
47104 spin_unlock(&object->lock);
47105
47106- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47107+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47108 op->store_limit = object->store_limit;
47109
47110 if (fscache_submit_op(object, &op->op) < 0)
47111@@ -829,8 +829,8 @@ int __fscache_write_page(struct fscache_
47112
47113 spin_unlock(&cookie->lock);
47114 radix_tree_preload_end();
47115- fscache_stat(&fscache_n_store_ops);
47116- fscache_stat(&fscache_n_stores_ok);
47117+ fscache_stat_unchecked(&fscache_n_store_ops);
47118+ fscache_stat_unchecked(&fscache_n_stores_ok);
47119
47120 /* the work queue now carries its own ref on the object */
47121 fscache_put_operation(&op->op);
47122@@ -838,14 +838,14 @@ int __fscache_write_page(struct fscache_
47123 return 0;
47124
47125 already_queued:
47126- fscache_stat(&fscache_n_stores_again);
47127+ fscache_stat_unchecked(&fscache_n_stores_again);
47128 already_pending:
47129 spin_unlock(&cookie->stores_lock);
47130 spin_unlock(&object->lock);
47131 spin_unlock(&cookie->lock);
47132 radix_tree_preload_end();
47133 kfree(op);
47134- fscache_stat(&fscache_n_stores_ok);
47135+ fscache_stat_unchecked(&fscache_n_stores_ok);
47136 _leave(" = 0");
47137 return 0;
47138
47139@@ -864,14 +864,14 @@ nobufs:
47140 spin_unlock(&cookie->lock);
47141 radix_tree_preload_end();
47142 kfree(op);
47143- fscache_stat(&fscache_n_stores_nobufs);
47144+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
47145 _leave(" = -ENOBUFS");
47146 return -ENOBUFS;
47147
47148 nomem_free:
47149 kfree(op);
47150 nomem:
47151- fscache_stat(&fscache_n_stores_oom);
47152+ fscache_stat_unchecked(&fscache_n_stores_oom);
47153 _leave(" = -ENOMEM");
47154 return -ENOMEM;
47155 }
47156@@ -889,7 +889,7 @@ void __fscache_uncache_page(struct fscac
47157 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47158 ASSERTCMP(page, !=, NULL);
47159
47160- fscache_stat(&fscache_n_uncaches);
47161+ fscache_stat_unchecked(&fscache_n_uncaches);
47162
47163 /* cache withdrawal may beat us to it */
47164 if (!PageFsCache(page))
47165@@ -942,7 +942,7 @@ void fscache_mark_pages_cached(struct fs
47166 unsigned long loop;
47167
47168 #ifdef CONFIG_FSCACHE_STATS
47169- atomic_add(pagevec->nr, &fscache_n_marks);
47170+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47171 #endif
47172
47173 for (loop = 0; loop < pagevec->nr; loop++) {
47174diff -urNp linux-2.6.39.1/fs/fscache/stats.c linux-2.6.39.1/fs/fscache/stats.c
47175--- linux-2.6.39.1/fs/fscache/stats.c 2011-05-19 00:06:34.000000000 -0400
47176+++ linux-2.6.39.1/fs/fscache/stats.c 2011-05-22 19:36:32.000000000 -0400
47177@@ -18,95 +18,95 @@
47178 /*
47179 * operation counters
47180 */
47181-atomic_t fscache_n_op_pend;
47182-atomic_t fscache_n_op_run;
47183-atomic_t fscache_n_op_enqueue;
47184-atomic_t fscache_n_op_requeue;
47185-atomic_t fscache_n_op_deferred_release;
47186-atomic_t fscache_n_op_release;
47187-atomic_t fscache_n_op_gc;
47188-atomic_t fscache_n_op_cancelled;
47189-atomic_t fscache_n_op_rejected;
47190-
47191-atomic_t fscache_n_attr_changed;
47192-atomic_t fscache_n_attr_changed_ok;
47193-atomic_t fscache_n_attr_changed_nobufs;
47194-atomic_t fscache_n_attr_changed_nomem;
47195-atomic_t fscache_n_attr_changed_calls;
47196-
47197-atomic_t fscache_n_allocs;
47198-atomic_t fscache_n_allocs_ok;
47199-atomic_t fscache_n_allocs_wait;
47200-atomic_t fscache_n_allocs_nobufs;
47201-atomic_t fscache_n_allocs_intr;
47202-atomic_t fscache_n_allocs_object_dead;
47203-atomic_t fscache_n_alloc_ops;
47204-atomic_t fscache_n_alloc_op_waits;
47205-
47206-atomic_t fscache_n_retrievals;
47207-atomic_t fscache_n_retrievals_ok;
47208-atomic_t fscache_n_retrievals_wait;
47209-atomic_t fscache_n_retrievals_nodata;
47210-atomic_t fscache_n_retrievals_nobufs;
47211-atomic_t fscache_n_retrievals_intr;
47212-atomic_t fscache_n_retrievals_nomem;
47213-atomic_t fscache_n_retrievals_object_dead;
47214-atomic_t fscache_n_retrieval_ops;
47215-atomic_t fscache_n_retrieval_op_waits;
47216-
47217-atomic_t fscache_n_stores;
47218-atomic_t fscache_n_stores_ok;
47219-atomic_t fscache_n_stores_again;
47220-atomic_t fscache_n_stores_nobufs;
47221-atomic_t fscache_n_stores_oom;
47222-atomic_t fscache_n_store_ops;
47223-atomic_t fscache_n_store_calls;
47224-atomic_t fscache_n_store_pages;
47225-atomic_t fscache_n_store_radix_deletes;
47226-atomic_t fscache_n_store_pages_over_limit;
47227-
47228-atomic_t fscache_n_store_vmscan_not_storing;
47229-atomic_t fscache_n_store_vmscan_gone;
47230-atomic_t fscache_n_store_vmscan_busy;
47231-atomic_t fscache_n_store_vmscan_cancelled;
47232-
47233-atomic_t fscache_n_marks;
47234-atomic_t fscache_n_uncaches;
47235-
47236-atomic_t fscache_n_acquires;
47237-atomic_t fscache_n_acquires_null;
47238-atomic_t fscache_n_acquires_no_cache;
47239-atomic_t fscache_n_acquires_ok;
47240-atomic_t fscache_n_acquires_nobufs;
47241-atomic_t fscache_n_acquires_oom;
47242-
47243-atomic_t fscache_n_updates;
47244-atomic_t fscache_n_updates_null;
47245-atomic_t fscache_n_updates_run;
47246-
47247-atomic_t fscache_n_relinquishes;
47248-atomic_t fscache_n_relinquishes_null;
47249-atomic_t fscache_n_relinquishes_waitcrt;
47250-atomic_t fscache_n_relinquishes_retire;
47251-
47252-atomic_t fscache_n_cookie_index;
47253-atomic_t fscache_n_cookie_data;
47254-atomic_t fscache_n_cookie_special;
47255-
47256-atomic_t fscache_n_object_alloc;
47257-atomic_t fscache_n_object_no_alloc;
47258-atomic_t fscache_n_object_lookups;
47259-atomic_t fscache_n_object_lookups_negative;
47260-atomic_t fscache_n_object_lookups_positive;
47261-atomic_t fscache_n_object_lookups_timed_out;
47262-atomic_t fscache_n_object_created;
47263-atomic_t fscache_n_object_avail;
47264-atomic_t fscache_n_object_dead;
47265-
47266-atomic_t fscache_n_checkaux_none;
47267-atomic_t fscache_n_checkaux_okay;
47268-atomic_t fscache_n_checkaux_update;
47269-atomic_t fscache_n_checkaux_obsolete;
47270+atomic_unchecked_t fscache_n_op_pend;
47271+atomic_unchecked_t fscache_n_op_run;
47272+atomic_unchecked_t fscache_n_op_enqueue;
47273+atomic_unchecked_t fscache_n_op_requeue;
47274+atomic_unchecked_t fscache_n_op_deferred_release;
47275+atomic_unchecked_t fscache_n_op_release;
47276+atomic_unchecked_t fscache_n_op_gc;
47277+atomic_unchecked_t fscache_n_op_cancelled;
47278+atomic_unchecked_t fscache_n_op_rejected;
47279+
47280+atomic_unchecked_t fscache_n_attr_changed;
47281+atomic_unchecked_t fscache_n_attr_changed_ok;
47282+atomic_unchecked_t fscache_n_attr_changed_nobufs;
47283+atomic_unchecked_t fscache_n_attr_changed_nomem;
47284+atomic_unchecked_t fscache_n_attr_changed_calls;
47285+
47286+atomic_unchecked_t fscache_n_allocs;
47287+atomic_unchecked_t fscache_n_allocs_ok;
47288+atomic_unchecked_t fscache_n_allocs_wait;
47289+atomic_unchecked_t fscache_n_allocs_nobufs;
47290+atomic_unchecked_t fscache_n_allocs_intr;
47291+atomic_unchecked_t fscache_n_allocs_object_dead;
47292+atomic_unchecked_t fscache_n_alloc_ops;
47293+atomic_unchecked_t fscache_n_alloc_op_waits;
47294+
47295+atomic_unchecked_t fscache_n_retrievals;
47296+atomic_unchecked_t fscache_n_retrievals_ok;
47297+atomic_unchecked_t fscache_n_retrievals_wait;
47298+atomic_unchecked_t fscache_n_retrievals_nodata;
47299+atomic_unchecked_t fscache_n_retrievals_nobufs;
47300+atomic_unchecked_t fscache_n_retrievals_intr;
47301+atomic_unchecked_t fscache_n_retrievals_nomem;
47302+atomic_unchecked_t fscache_n_retrievals_object_dead;
47303+atomic_unchecked_t fscache_n_retrieval_ops;
47304+atomic_unchecked_t fscache_n_retrieval_op_waits;
47305+
47306+atomic_unchecked_t fscache_n_stores;
47307+atomic_unchecked_t fscache_n_stores_ok;
47308+atomic_unchecked_t fscache_n_stores_again;
47309+atomic_unchecked_t fscache_n_stores_nobufs;
47310+atomic_unchecked_t fscache_n_stores_oom;
47311+atomic_unchecked_t fscache_n_store_ops;
47312+atomic_unchecked_t fscache_n_store_calls;
47313+atomic_unchecked_t fscache_n_store_pages;
47314+atomic_unchecked_t fscache_n_store_radix_deletes;
47315+atomic_unchecked_t fscache_n_store_pages_over_limit;
47316+
47317+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47318+atomic_unchecked_t fscache_n_store_vmscan_gone;
47319+atomic_unchecked_t fscache_n_store_vmscan_busy;
47320+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47321+
47322+atomic_unchecked_t fscache_n_marks;
47323+atomic_unchecked_t fscache_n_uncaches;
47324+
47325+atomic_unchecked_t fscache_n_acquires;
47326+atomic_unchecked_t fscache_n_acquires_null;
47327+atomic_unchecked_t fscache_n_acquires_no_cache;
47328+atomic_unchecked_t fscache_n_acquires_ok;
47329+atomic_unchecked_t fscache_n_acquires_nobufs;
47330+atomic_unchecked_t fscache_n_acquires_oom;
47331+
47332+atomic_unchecked_t fscache_n_updates;
47333+atomic_unchecked_t fscache_n_updates_null;
47334+atomic_unchecked_t fscache_n_updates_run;
47335+
47336+atomic_unchecked_t fscache_n_relinquishes;
47337+atomic_unchecked_t fscache_n_relinquishes_null;
47338+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47339+atomic_unchecked_t fscache_n_relinquishes_retire;
47340+
47341+atomic_unchecked_t fscache_n_cookie_index;
47342+atomic_unchecked_t fscache_n_cookie_data;
47343+atomic_unchecked_t fscache_n_cookie_special;
47344+
47345+atomic_unchecked_t fscache_n_object_alloc;
47346+atomic_unchecked_t fscache_n_object_no_alloc;
47347+atomic_unchecked_t fscache_n_object_lookups;
47348+atomic_unchecked_t fscache_n_object_lookups_negative;
47349+atomic_unchecked_t fscache_n_object_lookups_positive;
47350+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47351+atomic_unchecked_t fscache_n_object_created;
47352+atomic_unchecked_t fscache_n_object_avail;
47353+atomic_unchecked_t fscache_n_object_dead;
47354+
47355+atomic_unchecked_t fscache_n_checkaux_none;
47356+atomic_unchecked_t fscache_n_checkaux_okay;
47357+atomic_unchecked_t fscache_n_checkaux_update;
47358+atomic_unchecked_t fscache_n_checkaux_obsolete;
47359
47360 atomic_t fscache_n_cop_alloc_object;
47361 atomic_t fscache_n_cop_lookup_object;
47362@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
47363 seq_puts(m, "FS-Cache statistics\n");
47364
47365 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47366- atomic_read(&fscache_n_cookie_index),
47367- atomic_read(&fscache_n_cookie_data),
47368- atomic_read(&fscache_n_cookie_special));
47369+ atomic_read_unchecked(&fscache_n_cookie_index),
47370+ atomic_read_unchecked(&fscache_n_cookie_data),
47371+ atomic_read_unchecked(&fscache_n_cookie_special));
47372
47373 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47374- atomic_read(&fscache_n_object_alloc),
47375- atomic_read(&fscache_n_object_no_alloc),
47376- atomic_read(&fscache_n_object_avail),
47377- atomic_read(&fscache_n_object_dead));
47378+ atomic_read_unchecked(&fscache_n_object_alloc),
47379+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47380+ atomic_read_unchecked(&fscache_n_object_avail),
47381+ atomic_read_unchecked(&fscache_n_object_dead));
47382 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47383- atomic_read(&fscache_n_checkaux_none),
47384- atomic_read(&fscache_n_checkaux_okay),
47385- atomic_read(&fscache_n_checkaux_update),
47386- atomic_read(&fscache_n_checkaux_obsolete));
47387+ atomic_read_unchecked(&fscache_n_checkaux_none),
47388+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47389+ atomic_read_unchecked(&fscache_n_checkaux_update),
47390+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47391
47392 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47393- atomic_read(&fscache_n_marks),
47394- atomic_read(&fscache_n_uncaches));
47395+ atomic_read_unchecked(&fscache_n_marks),
47396+ atomic_read_unchecked(&fscache_n_uncaches));
47397
47398 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47399 " oom=%u\n",
47400- atomic_read(&fscache_n_acquires),
47401- atomic_read(&fscache_n_acquires_null),
47402- atomic_read(&fscache_n_acquires_no_cache),
47403- atomic_read(&fscache_n_acquires_ok),
47404- atomic_read(&fscache_n_acquires_nobufs),
47405- atomic_read(&fscache_n_acquires_oom));
47406+ atomic_read_unchecked(&fscache_n_acquires),
47407+ atomic_read_unchecked(&fscache_n_acquires_null),
47408+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47409+ atomic_read_unchecked(&fscache_n_acquires_ok),
47410+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47411+ atomic_read_unchecked(&fscache_n_acquires_oom));
47412
47413 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47414- atomic_read(&fscache_n_object_lookups),
47415- atomic_read(&fscache_n_object_lookups_negative),
47416- atomic_read(&fscache_n_object_lookups_positive),
47417- atomic_read(&fscache_n_object_created),
47418- atomic_read(&fscache_n_object_lookups_timed_out));
47419+ atomic_read_unchecked(&fscache_n_object_lookups),
47420+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47421+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47422+ atomic_read_unchecked(&fscache_n_object_created),
47423+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47424
47425 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47426- atomic_read(&fscache_n_updates),
47427- atomic_read(&fscache_n_updates_null),
47428- atomic_read(&fscache_n_updates_run));
47429+ atomic_read_unchecked(&fscache_n_updates),
47430+ atomic_read_unchecked(&fscache_n_updates_null),
47431+ atomic_read_unchecked(&fscache_n_updates_run));
47432
47433 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47434- atomic_read(&fscache_n_relinquishes),
47435- atomic_read(&fscache_n_relinquishes_null),
47436- atomic_read(&fscache_n_relinquishes_waitcrt),
47437- atomic_read(&fscache_n_relinquishes_retire));
47438+ atomic_read_unchecked(&fscache_n_relinquishes),
47439+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47440+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47441+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47442
47443 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47444- atomic_read(&fscache_n_attr_changed),
47445- atomic_read(&fscache_n_attr_changed_ok),
47446- atomic_read(&fscache_n_attr_changed_nobufs),
47447- atomic_read(&fscache_n_attr_changed_nomem),
47448- atomic_read(&fscache_n_attr_changed_calls));
47449+ atomic_read_unchecked(&fscache_n_attr_changed),
47450+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47451+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47452+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47453+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47454
47455 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47456- atomic_read(&fscache_n_allocs),
47457- atomic_read(&fscache_n_allocs_ok),
47458- atomic_read(&fscache_n_allocs_wait),
47459- atomic_read(&fscache_n_allocs_nobufs),
47460- atomic_read(&fscache_n_allocs_intr));
47461+ atomic_read_unchecked(&fscache_n_allocs),
47462+ atomic_read_unchecked(&fscache_n_allocs_ok),
47463+ atomic_read_unchecked(&fscache_n_allocs_wait),
47464+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47465+ atomic_read_unchecked(&fscache_n_allocs_intr));
47466 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47467- atomic_read(&fscache_n_alloc_ops),
47468- atomic_read(&fscache_n_alloc_op_waits),
47469- atomic_read(&fscache_n_allocs_object_dead));
47470+ atomic_read_unchecked(&fscache_n_alloc_ops),
47471+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47472+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47473
47474 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47475 " int=%u oom=%u\n",
47476- atomic_read(&fscache_n_retrievals),
47477- atomic_read(&fscache_n_retrievals_ok),
47478- atomic_read(&fscache_n_retrievals_wait),
47479- atomic_read(&fscache_n_retrievals_nodata),
47480- atomic_read(&fscache_n_retrievals_nobufs),
47481- atomic_read(&fscache_n_retrievals_intr),
47482- atomic_read(&fscache_n_retrievals_nomem));
47483+ atomic_read_unchecked(&fscache_n_retrievals),
47484+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47485+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47486+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47487+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47488+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47489+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47490 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47491- atomic_read(&fscache_n_retrieval_ops),
47492- atomic_read(&fscache_n_retrieval_op_waits),
47493- atomic_read(&fscache_n_retrievals_object_dead));
47494+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47495+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47496+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47497
47498 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47499- atomic_read(&fscache_n_stores),
47500- atomic_read(&fscache_n_stores_ok),
47501- atomic_read(&fscache_n_stores_again),
47502- atomic_read(&fscache_n_stores_nobufs),
47503- atomic_read(&fscache_n_stores_oom));
47504+ atomic_read_unchecked(&fscache_n_stores),
47505+ atomic_read_unchecked(&fscache_n_stores_ok),
47506+ atomic_read_unchecked(&fscache_n_stores_again),
47507+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47508+ atomic_read_unchecked(&fscache_n_stores_oom));
47509 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47510- atomic_read(&fscache_n_store_ops),
47511- atomic_read(&fscache_n_store_calls),
47512- atomic_read(&fscache_n_store_pages),
47513- atomic_read(&fscache_n_store_radix_deletes),
47514- atomic_read(&fscache_n_store_pages_over_limit));
47515+ atomic_read_unchecked(&fscache_n_store_ops),
47516+ atomic_read_unchecked(&fscache_n_store_calls),
47517+ atomic_read_unchecked(&fscache_n_store_pages),
47518+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47519+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47520
47521 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47522- atomic_read(&fscache_n_store_vmscan_not_storing),
47523- atomic_read(&fscache_n_store_vmscan_gone),
47524- atomic_read(&fscache_n_store_vmscan_busy),
47525- atomic_read(&fscache_n_store_vmscan_cancelled));
47526+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47527+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47528+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47529+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47530
47531 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47532- atomic_read(&fscache_n_op_pend),
47533- atomic_read(&fscache_n_op_run),
47534- atomic_read(&fscache_n_op_enqueue),
47535- atomic_read(&fscache_n_op_cancelled),
47536- atomic_read(&fscache_n_op_rejected));
47537+ atomic_read_unchecked(&fscache_n_op_pend),
47538+ atomic_read_unchecked(&fscache_n_op_run),
47539+ atomic_read_unchecked(&fscache_n_op_enqueue),
47540+ atomic_read_unchecked(&fscache_n_op_cancelled),
47541+ atomic_read_unchecked(&fscache_n_op_rejected));
47542 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47543- atomic_read(&fscache_n_op_deferred_release),
47544- atomic_read(&fscache_n_op_release),
47545- atomic_read(&fscache_n_op_gc));
47546+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47547+ atomic_read_unchecked(&fscache_n_op_release),
47548+ atomic_read_unchecked(&fscache_n_op_gc));
47549
47550 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47551 atomic_read(&fscache_n_cop_alloc_object),
47552diff -urNp linux-2.6.39.1/fs/fs_struct.c linux-2.6.39.1/fs/fs_struct.c
47553--- linux-2.6.39.1/fs/fs_struct.c 2011-05-19 00:06:34.000000000 -0400
47554+++ linux-2.6.39.1/fs/fs_struct.c 2011-05-22 19:41:37.000000000 -0400
47555@@ -4,6 +4,7 @@
47556 #include <linux/path.h>
47557 #include <linux/slab.h>
47558 #include <linux/fs_struct.h>
47559+#include <linux/grsecurity.h>
47560 #include "internal.h"
47561
47562 static inline void path_get_longterm(struct path *path)
47563@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, s
47564 old_root = fs->root;
47565 fs->root = *path;
47566 path_get_longterm(path);
47567+ gr_set_chroot_entries(current, path);
47568 write_seqcount_end(&fs->seq);
47569 spin_unlock(&fs->lock);
47570 if (old_root.dentry)
47571@@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_roo
47572 && fs->root.mnt == old_root->mnt) {
47573 path_get_longterm(new_root);
47574 fs->root = *new_root;
47575+ gr_set_chroot_entries(p, new_root);
47576 count++;
47577 }
47578 if (fs->pwd.dentry == old_root->dentry
47579@@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
47580 spin_lock(&fs->lock);
47581 write_seqcount_begin(&fs->seq);
47582 tsk->fs = NULL;
47583- kill = !--fs->users;
47584+ gr_clear_chroot_entries(tsk);
47585+ kill = !atomic_dec_return(&fs->users);
47586 write_seqcount_end(&fs->seq);
47587 spin_unlock(&fs->lock);
47588 task_unlock(tsk);
47589@@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct
47590 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47591 /* We don't need to lock fs - think why ;-) */
47592 if (fs) {
47593- fs->users = 1;
47594+ atomic_set(&fs->users, 1);
47595 fs->in_exec = 0;
47596 spin_lock_init(&fs->lock);
47597 seqcount_init(&fs->seq);
47598@@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct
47599 spin_lock(&old->lock);
47600 fs->root = old->root;
47601 path_get_longterm(&fs->root);
47602+ /* instead of calling gr_set_chroot_entries here,
47603+ we call it from every caller of this function
47604+ */
47605 fs->pwd = old->pwd;
47606 path_get_longterm(&fs->pwd);
47607 spin_unlock(&old->lock);
47608@@ -150,8 +157,9 @@ int unshare_fs_struct(void)
47609
47610 task_lock(current);
47611 spin_lock(&fs->lock);
47612- kill = !--fs->users;
47613+ kill = !atomic_dec_return(&fs->users);
47614 current->fs = new_fs;
47615+ gr_set_chroot_entries(current, &new_fs->root);
47616 spin_unlock(&fs->lock);
47617 task_unlock(current);
47618
47619@@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
47620
47621 /* to be mentioned only in INIT_TASK */
47622 struct fs_struct init_fs = {
47623- .users = 1,
47624+ .users = ATOMIC_INIT(1),
47625 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47626 .seq = SEQCNT_ZERO,
47627 .umask = 0022,
47628@@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
47629 task_lock(current);
47630
47631 spin_lock(&init_fs.lock);
47632- init_fs.users++;
47633+ atomic_inc(&init_fs.users);
47634 spin_unlock(&init_fs.lock);
47635
47636 spin_lock(&fs->lock);
47637 current->fs = &init_fs;
47638- kill = !--fs->users;
47639+ gr_set_chroot_entries(current, &current->fs->root);
47640+ kill = !atomic_dec_return(&fs->users);
47641 spin_unlock(&fs->lock);
47642
47643 task_unlock(current);
47644diff -urNp linux-2.6.39.1/fs/fuse/cuse.c linux-2.6.39.1/fs/fuse/cuse.c
47645--- linux-2.6.39.1/fs/fuse/cuse.c 2011-05-19 00:06:34.000000000 -0400
47646+++ linux-2.6.39.1/fs/fuse/cuse.c 2011-05-22 19:36:32.000000000 -0400
47647@@ -538,8 +538,18 @@ static int cuse_channel_release(struct i
47648 return rc;
47649 }
47650
47651-static struct file_operations cuse_channel_fops; /* initialized during init */
47652-
47653+static const struct file_operations cuse_channel_fops = { /* initialized during init */
47654+ .owner = THIS_MODULE,
47655+ .llseek = no_llseek,
47656+ .read = do_sync_read,
47657+ .aio_read = fuse_dev_read,
47658+ .write = do_sync_write,
47659+ .aio_write = fuse_dev_write,
47660+ .poll = fuse_dev_poll,
47661+ .open = cuse_channel_open,
47662+ .release = cuse_channel_release,
47663+ .fasync = fuse_dev_fasync,
47664+};
47665
47666 /**************************************************************************
47667 * Misc stuff and module initializatiion
47668@@ -585,12 +595,6 @@ static int __init cuse_init(void)
47669 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
47670 INIT_LIST_HEAD(&cuse_conntbl[i]);
47671
47672- /* inherit and extend fuse_dev_operations */
47673- cuse_channel_fops = fuse_dev_operations;
47674- cuse_channel_fops.owner = THIS_MODULE;
47675- cuse_channel_fops.open = cuse_channel_open;
47676- cuse_channel_fops.release = cuse_channel_release;
47677-
47678 cuse_class = class_create(THIS_MODULE, "cuse");
47679 if (IS_ERR(cuse_class))
47680 return PTR_ERR(cuse_class);
47681diff -urNp linux-2.6.39.1/fs/fuse/dev.c linux-2.6.39.1/fs/fuse/dev.c
47682--- linux-2.6.39.1/fs/fuse/dev.c 2011-05-19 00:06:34.000000000 -0400
47683+++ linux-2.6.39.1/fs/fuse/dev.c 2011-05-22 19:36:32.000000000 -0400
47684@@ -1181,7 +1181,7 @@ static ssize_t fuse_dev_do_read(struct f
47685 return err;
47686 }
47687
47688-static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47689+ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47690 unsigned long nr_segs, loff_t pos)
47691 {
47692 struct fuse_copy_state cs;
47693@@ -1195,6 +1195,8 @@ static ssize_t fuse_dev_read(struct kioc
47694 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
47695 }
47696
47697+EXPORT_SYMBOL_GPL(fuse_dev_read);
47698+
47699 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
47700 struct pipe_buffer *buf)
47701 {
47702@@ -1238,7 +1240,7 @@ static ssize_t fuse_dev_splice_read(stru
47703 ret = 0;
47704 pipe_lock(pipe);
47705
47706- if (!pipe->readers) {
47707+ if (!atomic_read(&pipe->readers)) {
47708 send_sig(SIGPIPE, current, 0);
47709 if (!ret)
47710 ret = -EPIPE;
47711@@ -1731,7 +1733,7 @@ static ssize_t fuse_dev_do_write(struct
47712 return err;
47713 }
47714
47715-static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47716+ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47717 unsigned long nr_segs, loff_t pos)
47718 {
47719 struct fuse_copy_state cs;
47720@@ -1744,6 +1746,8 @@ static ssize_t fuse_dev_write(struct kio
47721 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
47722 }
47723
47724+EXPORT_SYMBOL_GPL(fuse_dev_write);
47725+
47726 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
47727 struct file *out, loff_t *ppos,
47728 size_t len, unsigned int flags)
47729@@ -1822,7 +1826,7 @@ out:
47730 return ret;
47731 }
47732
47733-static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47734+unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47735 {
47736 unsigned mask = POLLOUT | POLLWRNORM;
47737 struct fuse_conn *fc = fuse_get_conn(file);
47738@@ -1841,6 +1845,8 @@ static unsigned fuse_dev_poll(struct fil
47739 return mask;
47740 }
47741
47742+EXPORT_SYMBOL_GPL(fuse_dev_poll);
47743+
47744 /*
47745 * Abort all requests on the given list (pending or processing)
47746 *
47747@@ -1977,7 +1983,7 @@ int fuse_dev_release(struct inode *inode
47748 }
47749 EXPORT_SYMBOL_GPL(fuse_dev_release);
47750
47751-static int fuse_dev_fasync(int fd, struct file *file, int on)
47752+int fuse_dev_fasync(int fd, struct file *file, int on)
47753 {
47754 struct fuse_conn *fc = fuse_get_conn(file);
47755 if (!fc)
47756@@ -1987,6 +1993,8 @@ static int fuse_dev_fasync(int fd, struc
47757 return fasync_helper(fd, file, on, &fc->fasync);
47758 }
47759
47760+EXPORT_SYMBOL_GPL(fuse_dev_fasync);
47761+
47762 const struct file_operations fuse_dev_operations = {
47763 .owner = THIS_MODULE,
47764 .llseek = no_llseek,
47765diff -urNp linux-2.6.39.1/fs/fuse/dir.c linux-2.6.39.1/fs/fuse/dir.c
47766--- linux-2.6.39.1/fs/fuse/dir.c 2011-05-19 00:06:34.000000000 -0400
47767+++ linux-2.6.39.1/fs/fuse/dir.c 2011-05-22 19:36:32.000000000 -0400
47768@@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *de
47769 return link;
47770 }
47771
47772-static void free_link(char *link)
47773+static void free_link(const char *link)
47774 {
47775 if (!IS_ERR(link))
47776 free_page((unsigned long) link);
47777diff -urNp linux-2.6.39.1/fs/fuse/fuse_i.h linux-2.6.39.1/fs/fuse/fuse_i.h
47778--- linux-2.6.39.1/fs/fuse/fuse_i.h 2011-05-19 00:06:34.000000000 -0400
47779+++ linux-2.6.39.1/fs/fuse/fuse_i.h 2011-05-22 19:36:32.000000000 -0400
47780@@ -540,6 +540,16 @@ extern const struct file_operations fuse
47781
47782 extern const struct dentry_operations fuse_dentry_operations;
47783
47784+extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47785+ unsigned long nr_segs, loff_t pos);
47786+
47787+extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47788+ unsigned long nr_segs, loff_t pos);
47789+
47790+extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
47791+
47792+extern int fuse_dev_fasync(int fd, struct file *file, int on);
47793+
47794 /**
47795 * Inode to nodeid comparison.
47796 */
47797diff -urNp linux-2.6.39.1/fs/gfs2/ops_inode.c linux-2.6.39.1/fs/gfs2/ops_inode.c
47798--- linux-2.6.39.1/fs/gfs2/ops_inode.c 2011-05-19 00:06:34.000000000 -0400
47799+++ linux-2.6.39.1/fs/gfs2/ops_inode.c 2011-05-22 19:36:32.000000000 -0400
47800@@ -740,6 +740,8 @@ static int gfs2_rename(struct inode *odi
47801 unsigned int x;
47802 int error;
47803
47804+ pax_track_stack();
47805+
47806 if (ndentry->d_inode) {
47807 nip = GFS2_I(ndentry->d_inode);
47808 if (ip == nip)
47809@@ -1019,7 +1021,7 @@ out:
47810
47811 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47812 {
47813- char *s = nd_get_link(nd);
47814+ const char *s = nd_get_link(nd);
47815 if (!IS_ERR(s))
47816 kfree(s);
47817 }
47818diff -urNp linux-2.6.39.1/fs/hfsplus/catalog.c linux-2.6.39.1/fs/hfsplus/catalog.c
47819--- linux-2.6.39.1/fs/hfsplus/catalog.c 2011-05-19 00:06:34.000000000 -0400
47820+++ linux-2.6.39.1/fs/hfsplus/catalog.c 2011-05-22 19:36:32.000000000 -0400
47821@@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block
47822 int err;
47823 u16 type;
47824
47825+ pax_track_stack();
47826+
47827 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
47828 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
47829 if (err)
47830@@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct
47831 int entry_size;
47832 int err;
47833
47834+ pax_track_stack();
47835+
47836 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
47837 str->name, cnid, inode->i_nlink);
47838 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
47839@@ -349,6 +353,8 @@ int hfsplus_rename_cat(u32 cnid,
47840 int entry_size, type;
47841 int err = 0;
47842
47843+ pax_track_stack();
47844+
47845 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
47846 cnid, src_dir->i_ino, src_name->name,
47847 dst_dir->i_ino, dst_name->name);
47848diff -urNp linux-2.6.39.1/fs/hfsplus/dir.c linux-2.6.39.1/fs/hfsplus/dir.c
47849--- linux-2.6.39.1/fs/hfsplus/dir.c 2011-05-19 00:06:34.000000000 -0400
47850+++ linux-2.6.39.1/fs/hfsplus/dir.c 2011-05-22 19:36:32.000000000 -0400
47851@@ -129,6 +129,8 @@ static int hfsplus_readdir(struct file *
47852 struct hfsplus_readdir_data *rd;
47853 u16 type;
47854
47855+ pax_track_stack();
47856+
47857 if (filp->f_pos >= inode->i_size)
47858 return 0;
47859
47860diff -urNp linux-2.6.39.1/fs/hfsplus/inode.c linux-2.6.39.1/fs/hfsplus/inode.c
47861--- linux-2.6.39.1/fs/hfsplus/inode.c 2011-05-19 00:06:34.000000000 -0400
47862+++ linux-2.6.39.1/fs/hfsplus/inode.c 2011-05-22 19:36:32.000000000 -0400
47863@@ -489,6 +489,8 @@ int hfsplus_cat_read_inode(struct inode
47864 int res = 0;
47865 u16 type;
47866
47867+ pax_track_stack();
47868+
47869 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
47870
47871 HFSPLUS_I(inode)->linkid = 0;
47872@@ -552,6 +554,8 @@ int hfsplus_cat_write_inode(struct inode
47873 struct hfs_find_data fd;
47874 hfsplus_cat_entry entry;
47875
47876+ pax_track_stack();
47877+
47878 if (HFSPLUS_IS_RSRC(inode))
47879 main_inode = HFSPLUS_I(inode)->rsrc_inode;
47880
47881diff -urNp linux-2.6.39.1/fs/hfsplus/ioctl.c linux-2.6.39.1/fs/hfsplus/ioctl.c
47882--- linux-2.6.39.1/fs/hfsplus/ioctl.c 2011-05-19 00:06:34.000000000 -0400
47883+++ linux-2.6.39.1/fs/hfsplus/ioctl.c 2011-05-22 19:36:32.000000000 -0400
47884@@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dent
47885 struct hfsplus_cat_file *file;
47886 int res;
47887
47888+ pax_track_stack();
47889+
47890 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47891 return -EOPNOTSUPP;
47892
47893@@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *
47894 struct hfsplus_cat_file *file;
47895 ssize_t res = 0;
47896
47897+ pax_track_stack();
47898+
47899 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47900 return -EOPNOTSUPP;
47901
47902diff -urNp linux-2.6.39.1/fs/hfsplus/super.c linux-2.6.39.1/fs/hfsplus/super.c
47903--- linux-2.6.39.1/fs/hfsplus/super.c 2011-05-19 00:06:34.000000000 -0400
47904+++ linux-2.6.39.1/fs/hfsplus/super.c 2011-05-22 19:36:32.000000000 -0400
47905@@ -340,6 +340,8 @@ static int hfsplus_fill_super(struct sup
47906 struct nls_table *nls = NULL;
47907 int err;
47908
47909+ pax_track_stack();
47910+
47911 err = -EINVAL;
47912 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
47913 if (!sbi)
47914diff -urNp linux-2.6.39.1/fs/hugetlbfs/inode.c linux-2.6.39.1/fs/hugetlbfs/inode.c
47915--- linux-2.6.39.1/fs/hugetlbfs/inode.c 2011-05-19 00:06:34.000000000 -0400
47916+++ linux-2.6.39.1/fs/hugetlbfs/inode.c 2011-05-22 19:41:37.000000000 -0400
47917@@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs
47918 .kill_sb = kill_litter_super,
47919 };
47920
47921-static struct vfsmount *hugetlbfs_vfsmount;
47922+struct vfsmount *hugetlbfs_vfsmount;
47923
47924 static int can_do_hugetlb_shm(void)
47925 {
47926diff -urNp linux-2.6.39.1/fs/inode.c linux-2.6.39.1/fs/inode.c
47927--- linux-2.6.39.1/fs/inode.c 2011-05-19 00:06:34.000000000 -0400
47928+++ linux-2.6.39.1/fs/inode.c 2011-05-22 19:36:32.000000000 -0400
47929@@ -862,8 +862,8 @@ unsigned int get_next_ino(void)
47930
47931 #ifdef CONFIG_SMP
47932 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47933- static atomic_t shared_last_ino;
47934- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47935+ static atomic_unchecked_t shared_last_ino;
47936+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47937
47938 res = next - LAST_INO_BATCH;
47939 }
47940diff -urNp linux-2.6.39.1/fs/jbd/checkpoint.c linux-2.6.39.1/fs/jbd/checkpoint.c
47941--- linux-2.6.39.1/fs/jbd/checkpoint.c 2011-05-19 00:06:34.000000000 -0400
47942+++ linux-2.6.39.1/fs/jbd/checkpoint.c 2011-05-22 19:36:32.000000000 -0400
47943@@ -350,6 +350,8 @@ int log_do_checkpoint(journal_t *journal
47944 tid_t this_tid;
47945 int result;
47946
47947+ pax_track_stack();
47948+
47949 jbd_debug(1, "Start checkpoint\n");
47950
47951 /*
47952diff -urNp linux-2.6.39.1/fs/jffs2/compr_rtime.c linux-2.6.39.1/fs/jffs2/compr_rtime.c
47953--- linux-2.6.39.1/fs/jffs2/compr_rtime.c 2011-05-19 00:06:34.000000000 -0400
47954+++ linux-2.6.39.1/fs/jffs2/compr_rtime.c 2011-05-22 19:36:32.000000000 -0400
47955@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
47956 int outpos = 0;
47957 int pos=0;
47958
47959+ pax_track_stack();
47960+
47961 memset(positions,0,sizeof(positions));
47962
47963 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
47964@@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsign
47965 int outpos = 0;
47966 int pos=0;
47967
47968+ pax_track_stack();
47969+
47970 memset(positions,0,sizeof(positions));
47971
47972 while (outpos<destlen) {
47973diff -urNp linux-2.6.39.1/fs/jffs2/compr_rubin.c linux-2.6.39.1/fs/jffs2/compr_rubin.c
47974--- linux-2.6.39.1/fs/jffs2/compr_rubin.c 2011-05-19 00:06:34.000000000 -0400
47975+++ linux-2.6.39.1/fs/jffs2/compr_rubin.c 2011-05-22 19:36:32.000000000 -0400
47976@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
47977 int ret;
47978 uint32_t mysrclen, mydstlen;
47979
47980+ pax_track_stack();
47981+
47982 mysrclen = *sourcelen;
47983 mydstlen = *dstlen - 8;
47984
47985diff -urNp linux-2.6.39.1/fs/jffs2/erase.c linux-2.6.39.1/fs/jffs2/erase.c
47986--- linux-2.6.39.1/fs/jffs2/erase.c 2011-05-19 00:06:34.000000000 -0400
47987+++ linux-2.6.39.1/fs/jffs2/erase.c 2011-05-22 19:36:32.000000000 -0400
47988@@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
47989 struct jffs2_unknown_node marker = {
47990 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47991 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47992- .totlen = cpu_to_je32(c->cleanmarker_size)
47993+ .totlen = cpu_to_je32(c->cleanmarker_size),
47994+ .hdr_crc = cpu_to_je32(0)
47995 };
47996
47997 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47998diff -urNp linux-2.6.39.1/fs/jffs2/wbuf.c linux-2.6.39.1/fs/jffs2/wbuf.c
47999--- linux-2.6.39.1/fs/jffs2/wbuf.c 2011-05-19 00:06:34.000000000 -0400
48000+++ linux-2.6.39.1/fs/jffs2/wbuf.c 2011-05-22 19:36:32.000000000 -0400
48001@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
48002 {
48003 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
48004 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48005- .totlen = constant_cpu_to_je32(8)
48006+ .totlen = constant_cpu_to_je32(8),
48007+ .hdr_crc = constant_cpu_to_je32(0)
48008 };
48009
48010 /*
48011diff -urNp linux-2.6.39.1/fs/jffs2/xattr.c linux-2.6.39.1/fs/jffs2/xattr.c
48012--- linux-2.6.39.1/fs/jffs2/xattr.c 2011-05-19 00:06:34.000000000 -0400
48013+++ linux-2.6.39.1/fs/jffs2/xattr.c 2011-05-22 19:36:32.000000000 -0400
48014@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
48015
48016 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
48017
48018+ pax_track_stack();
48019+
48020 /* Phase.1 : Merge same xref */
48021 for (i=0; i < XREF_TMPHASH_SIZE; i++)
48022 xref_tmphash[i] = NULL;
48023diff -urNp linux-2.6.39.1/fs/jfs/super.c linux-2.6.39.1/fs/jfs/super.c
48024--- linux-2.6.39.1/fs/jfs/super.c 2011-05-19 00:06:34.000000000 -0400
48025+++ linux-2.6.39.1/fs/jfs/super.c 2011-06-07 18:07:24.000000000 -0400
48026@@ -803,7 +803,7 @@ static int __init init_jfs_fs(void)
48027
48028 jfs_inode_cachep =
48029 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48030- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48031+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48032 init_once);
48033 if (jfs_inode_cachep == NULL)
48034 return -ENOMEM;
48035diff -urNp linux-2.6.39.1/fs/Kconfig.binfmt linux-2.6.39.1/fs/Kconfig.binfmt
48036--- linux-2.6.39.1/fs/Kconfig.binfmt 2011-05-19 00:06:34.000000000 -0400
48037+++ linux-2.6.39.1/fs/Kconfig.binfmt 2011-05-22 19:36:32.000000000 -0400
48038@@ -86,7 +86,7 @@ config HAVE_AOUT
48039
48040 config BINFMT_AOUT
48041 tristate "Kernel support for a.out and ECOFF binaries"
48042- depends on HAVE_AOUT
48043+ depends on HAVE_AOUT && BROKEN
48044 ---help---
48045 A.out (Assembler.OUTput) is a set of formats for libraries and
48046 executables used in the earliest versions of UNIX. Linux used
48047diff -urNp linux-2.6.39.1/fs/libfs.c linux-2.6.39.1/fs/libfs.c
48048--- linux-2.6.39.1/fs/libfs.c 2011-05-19 00:06:34.000000000 -0400
48049+++ linux-2.6.39.1/fs/libfs.c 2011-05-22 19:36:32.000000000 -0400
48050@@ -163,6 +163,9 @@ int dcache_readdir(struct file * filp, v
48051
48052 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
48053 struct dentry *next;
48054+ char d_name[sizeof(next->d_iname)];
48055+ const unsigned char *name;
48056+
48057 next = list_entry(p, struct dentry, d_u.d_child);
48058 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
48059 if (!simple_positive(next)) {
48060@@ -172,7 +175,12 @@ int dcache_readdir(struct file * filp, v
48061
48062 spin_unlock(&next->d_lock);
48063 spin_unlock(&dentry->d_lock);
48064- if (filldir(dirent, next->d_name.name,
48065+ name = next->d_name.name;
48066+ if (name == next->d_iname) {
48067+ memcpy(d_name, name, next->d_name.len);
48068+ name = d_name;
48069+ }
48070+ if (filldir(dirent, name,
48071 next->d_name.len, filp->f_pos,
48072 next->d_inode->i_ino,
48073 dt_type(next->d_inode)) < 0)
48074diff -urNp linux-2.6.39.1/fs/lockd/clntproc.c linux-2.6.39.1/fs/lockd/clntproc.c
48075--- linux-2.6.39.1/fs/lockd/clntproc.c 2011-05-19 00:06:34.000000000 -0400
48076+++ linux-2.6.39.1/fs/lockd/clntproc.c 2011-05-22 19:36:32.000000000 -0400
48077@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
48078 /*
48079 * Cookie counter for NLM requests
48080 */
48081-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48082+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48083
48084 void nlmclnt_next_cookie(struct nlm_cookie *c)
48085 {
48086- u32 cookie = atomic_inc_return(&nlm_cookie);
48087+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48088
48089 memcpy(c->data, &cookie, 4);
48090 c->len=4;
48091@@ -620,6 +620,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
48092 struct nlm_rqst reqst, *req;
48093 int status;
48094
48095+ pax_track_stack();
48096+
48097 req = &reqst;
48098 memset(req, 0, sizeof(*req));
48099 locks_init_lock(&req->a_args.lock.fl);
48100diff -urNp linux-2.6.39.1/fs/lockd/svc.c linux-2.6.39.1/fs/lockd/svc.c
48101--- linux-2.6.39.1/fs/lockd/svc.c 2011-05-19 00:06:34.000000000 -0400
48102+++ linux-2.6.39.1/fs/lockd/svc.c 2011-05-22 19:36:32.000000000 -0400
48103@@ -41,7 +41,7 @@
48104
48105 static struct svc_program nlmsvc_program;
48106
48107-struct nlmsvc_binding * nlmsvc_ops;
48108+const struct nlmsvc_binding * nlmsvc_ops;
48109 EXPORT_SYMBOL_GPL(nlmsvc_ops);
48110
48111 static DEFINE_MUTEX(nlmsvc_mutex);
48112diff -urNp linux-2.6.39.1/fs/locks.c linux-2.6.39.1/fs/locks.c
48113--- linux-2.6.39.1/fs/locks.c 2011-05-19 00:06:34.000000000 -0400
48114+++ linux-2.6.39.1/fs/locks.c 2011-05-22 19:36:32.000000000 -0400
48115@@ -2033,16 +2033,16 @@ void locks_remove_flock(struct file *fil
48116 return;
48117
48118 if (filp->f_op && filp->f_op->flock) {
48119- struct file_lock fl = {
48120+ struct file_lock flock = {
48121 .fl_pid = current->tgid,
48122 .fl_file = filp,
48123 .fl_flags = FL_FLOCK,
48124 .fl_type = F_UNLCK,
48125 .fl_end = OFFSET_MAX,
48126 };
48127- filp->f_op->flock(filp, F_SETLKW, &fl);
48128- if (fl.fl_ops && fl.fl_ops->fl_release_private)
48129- fl.fl_ops->fl_release_private(&fl);
48130+ filp->f_op->flock(filp, F_SETLKW, &flock);
48131+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
48132+ flock.fl_ops->fl_release_private(&flock);
48133 }
48134
48135 lock_flocks();
48136diff -urNp linux-2.6.39.1/fs/logfs/super.c linux-2.6.39.1/fs/logfs/super.c
48137--- linux-2.6.39.1/fs/logfs/super.c 2011-05-19 00:06:34.000000000 -0400
48138+++ linux-2.6.39.1/fs/logfs/super.c 2011-05-22 19:36:32.000000000 -0400
48139@@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super
48140 struct logfs_disk_super _ds1, *ds1 = &_ds1;
48141 int err, valid0, valid1;
48142
48143+ pax_track_stack();
48144+
48145 /* read first superblock */
48146 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
48147 if (err)
48148diff -urNp linux-2.6.39.1/fs/namei.c linux-2.6.39.1/fs/namei.c
48149--- linux-2.6.39.1/fs/namei.c 2011-06-03 00:04:14.000000000 -0400
48150+++ linux-2.6.39.1/fs/namei.c 2011-06-03 00:32:07.000000000 -0400
48151@@ -237,20 +237,30 @@ int generic_permission(struct inode *ino
48152 return ret;
48153
48154 /*
48155- * Read/write DACs are always overridable.
48156- * Executable DACs are overridable if at least one exec bit is set.
48157+ * Searching includes executable on directories, else just read.
48158 */
48159- if (!(mask & MAY_EXEC) || execute_ok(inode))
48160- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48161+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48162+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) {
48163+#ifdef CONFIG_GRKERNSEC
48164+ if (flags & IPERM_FLAG_RCU)
48165+ return -ECHILD;
48166+#endif
48167+ if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48168 return 0;
48169+ }
48170
48171 /*
48172- * Searching includes executable on directories, else just read.
48173+ * Read/write DACs are always overridable.
48174+ * Executable DACs are overridable if at least one exec bit is set.
48175 */
48176- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48177- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
48178- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48179+ if (!(mask & MAY_EXEC) || execute_ok(inode)) {
48180+#ifdef CONFIG_GRKERNSEC
48181+ if (flags & IPERM_FLAG_RCU)
48182+ return -ECHILD;
48183+#endif
48184+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48185 return 0;
48186+ }
48187
48188 return -EACCES;
48189 }
48190@@ -626,6 +636,9 @@ static inline int handle_reval_path(stru
48191 struct dentry *dentry = nd->path.dentry;
48192 int status;
48193
48194+ if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
48195+ return -ENOENT;
48196+
48197 if (likely(!(nd->flags & LOOKUP_JUMPED)))
48198 return 0;
48199
48200@@ -671,9 +684,16 @@ static inline int exec_permission(struct
48201 if (ret == -ECHILD)
48202 return ret;
48203
48204- if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
48205- ns_capable(ns, CAP_DAC_READ_SEARCH))
48206+ if (ns_capable_nolog(ns, CAP_DAC_OVERRIDE))
48207 goto ok;
48208+ else {
48209+#ifdef CONFIG_GRKERNSEC
48210+ if (flags & IPERM_FLAG_RCU)
48211+ return -ECHILD;
48212+#endif
48213+ if (ns_capable(ns, CAP_DAC_READ_SEARCH) || ns_capable(ns, CAP_DAC_OVERRIDE))
48214+ goto ok;
48215+ }
48216
48217 return ret;
48218 ok:
48219@@ -781,11 +801,19 @@ follow_link(struct path *link, struct na
48220 return error;
48221 }
48222
48223+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
48224+ dentry->d_inode, dentry, nd->path.mnt)) {
48225+ error = -EACCES;
48226+ *p = ERR_PTR(error); /* no ->put_link(), please */
48227+ path_put(&nd->path);
48228+ return error;
48229+ }
48230+
48231 nd->last_type = LAST_BIND;
48232 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48233 error = PTR_ERR(*p);
48234 if (!IS_ERR(*p)) {
48235- char *s = nd_get_link(nd);
48236+ const char *s = nd_get_link(nd);
48237 error = 0;
48238 if (s)
48239 error = __vfs_follow_link(nd, s);
48240@@ -1697,6 +1725,9 @@ static int do_path_lookup(int dfd, const
48241 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48242
48243 if (likely(!retval)) {
48244+ if (*name != '/' && nd->path.dentry && nd->inode && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48245+ return -ENOENT;
48246+
48247 if (unlikely(!audit_dummy_context())) {
48248 if (nd->path.dentry && nd->inode)
48249 audit_inode(name, nd->path.dentry);
48250@@ -2007,6 +2038,30 @@ int vfs_create(struct inode *dir, struct
48251 return error;
48252 }
48253
48254+/*
48255+ * Note that while the flag value (low two bits) for sys_open means:
48256+ * 00 - read-only
48257+ * 01 - write-only
48258+ * 10 - read-write
48259+ * 11 - special
48260+ * it is changed into
48261+ * 00 - no permissions needed
48262+ * 01 - read-permission
48263+ * 10 - write-permission
48264+ * 11 - read-write
48265+ * for the internal routines (ie open_namei()/follow_link() etc)
48266+ * This is more logical, and also allows the 00 "no perm needed"
48267+ * to be used for symlinks (where the permissions are checked
48268+ * later).
48269+ *
48270+*/
48271+static inline int open_to_namei_flags(int flag)
48272+{
48273+ if ((flag+1) & O_ACCMODE)
48274+ flag++;
48275+ return flag;
48276+}
48277+
48278 static int may_open(struct path *path, int acc_mode, int flag)
48279 {
48280 struct dentry *dentry = path->dentry;
48281@@ -2059,7 +2114,27 @@ static int may_open(struct path *path, i
48282 /*
48283 * Ensure there are no outstanding leases on the file.
48284 */
48285- return break_lease(inode, flag);
48286+ error = break_lease(inode, flag);
48287+
48288+ if (error)
48289+ return error;
48290+
48291+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
48292+ error = -EPERM;
48293+ goto exit;
48294+ }
48295+
48296+ if (gr_handle_rawio(inode)) {
48297+ error = -EPERM;
48298+ goto exit;
48299+ }
48300+
48301+ if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
48302+ error = -EACCES;
48303+ goto exit;
48304+ }
48305+exit:
48306+ return error;
48307 }
48308
48309 static int handle_truncate(struct file *filp)
48310@@ -2085,30 +2160,6 @@ static int handle_truncate(struct file *
48311 }
48312
48313 /*
48314- * Note that while the flag value (low two bits) for sys_open means:
48315- * 00 - read-only
48316- * 01 - write-only
48317- * 10 - read-write
48318- * 11 - special
48319- * it is changed into
48320- * 00 - no permissions needed
48321- * 01 - read-permission
48322- * 10 - write-permission
48323- * 11 - read-write
48324- * for the internal routines (ie open_namei()/follow_link() etc)
48325- * This is more logical, and also allows the 00 "no perm needed"
48326- * to be used for symlinks (where the permissions are checked
48327- * later).
48328- *
48329-*/
48330-static inline int open_to_namei_flags(int flag)
48331-{
48332- if ((flag+1) & O_ACCMODE)
48333- flag++;
48334- return flag;
48335-}
48336-
48337-/*
48338 * Handle the last step of open()
48339 */
48340 static struct file *do_last(struct nameidata *nd, struct path *path,
48341@@ -2117,6 +2168,7 @@ static struct file *do_last(struct namei
48342 struct dentry *dir = nd->path.dentry;
48343 struct dentry *dentry;
48344 int open_flag = op->open_flag;
48345+ int flag = open_to_namei_flags(open_flag);
48346 int will_truncate = open_flag & O_TRUNC;
48347 int want_write = 0;
48348 int acc_mode = op->acc_mode;
48349@@ -2212,6 +2264,12 @@ static struct file *do_last(struct namei
48350 /* Negative dentry, just create the file */
48351 if (!dentry->d_inode) {
48352 int mode = op->mode;
48353+
48354+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, flag, mode)) {
48355+ error = -EACCES;
48356+ goto exit_mutex_unlock;
48357+ }
48358+
48359 if (!IS_POSIXACL(dir->d_inode))
48360 mode &= ~current_umask();
48361 /*
48362@@ -2235,6 +2293,8 @@ static struct file *do_last(struct namei
48363 error = vfs_create(dir->d_inode, dentry, mode, nd);
48364 if (error)
48365 goto exit_mutex_unlock;
48366+ else
48367+ gr_handle_create(path->dentry, path->mnt);
48368 mutex_unlock(&dir->d_inode->i_mutex);
48369 dput(nd->path.dentry);
48370 nd->path.dentry = dentry;
48371@@ -2244,6 +2304,14 @@ static struct file *do_last(struct namei
48372 /*
48373 * It already exists.
48374 */
48375+
48376+ /* only check if O_CREAT is specified, all other checks need to go
48377+ into may_open */
48378+ if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
48379+ error = -EACCES;
48380+ goto exit_mutex_unlock;
48381+ }
48382+
48383 mutex_unlock(&dir->d_inode->i_mutex);
48384 audit_inode(pathname, path->dentry);
48385
48386@@ -2530,6 +2598,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48387 error = may_mknod(mode);
48388 if (error)
48389 goto out_dput;
48390+
48391+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
48392+ error = -EPERM;
48393+ goto out_dput;
48394+ }
48395+
48396+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
48397+ error = -EACCES;
48398+ goto out_dput;
48399+ }
48400+
48401 error = mnt_want_write(nd.path.mnt);
48402 if (error)
48403 goto out_dput;
48404@@ -2550,6 +2629,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48405 }
48406 out_drop_write:
48407 mnt_drop_write(nd.path.mnt);
48408+
48409+ if (!error)
48410+ gr_handle_create(dentry, nd.path.mnt);
48411 out_dput:
48412 dput(dentry);
48413 out_unlock:
48414@@ -2602,6 +2684,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48415 if (IS_ERR(dentry))
48416 goto out_unlock;
48417
48418+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
48419+ error = -EACCES;
48420+ goto out_dput;
48421+ }
48422+
48423 if (!IS_POSIXACL(nd.path.dentry->d_inode))
48424 mode &= ~current_umask();
48425 error = mnt_want_write(nd.path.mnt);
48426@@ -2613,6 +2700,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48427 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
48428 out_drop_write:
48429 mnt_drop_write(nd.path.mnt);
48430+
48431+ if (!error)
48432+ gr_handle_create(dentry, nd.path.mnt);
48433+
48434 out_dput:
48435 dput(dentry);
48436 out_unlock:
48437@@ -2692,6 +2783,8 @@ static long do_rmdir(int dfd, const char
48438 char * name;
48439 struct dentry *dentry;
48440 struct nameidata nd;
48441+ ino_t saved_ino = 0;
48442+ dev_t saved_dev = 0;
48443
48444 error = user_path_parent(dfd, pathname, &nd, &name);
48445 if (error)
48446@@ -2716,6 +2809,19 @@ static long do_rmdir(int dfd, const char
48447 error = PTR_ERR(dentry);
48448 if (IS_ERR(dentry))
48449 goto exit2;
48450+
48451+ if (dentry->d_inode != NULL) {
48452+ if (dentry->d_inode->i_nlink <= 1) {
48453+ saved_ino = dentry->d_inode->i_ino;
48454+ saved_dev = gr_get_dev_from_dentry(dentry);
48455+ }
48456+
48457+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48458+ error = -EACCES;
48459+ goto exit3;
48460+ }
48461+ }
48462+
48463 error = mnt_want_write(nd.path.mnt);
48464 if (error)
48465 goto exit3;
48466@@ -2723,6 +2829,8 @@ static long do_rmdir(int dfd, const char
48467 if (error)
48468 goto exit4;
48469 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48470+ if (!error && (saved_dev || saved_ino))
48471+ gr_handle_delete(saved_ino, saved_dev);
48472 exit4:
48473 mnt_drop_write(nd.path.mnt);
48474 exit3:
48475@@ -2785,6 +2893,8 @@ static long do_unlinkat(int dfd, const c
48476 struct dentry *dentry;
48477 struct nameidata nd;
48478 struct inode *inode = NULL;
48479+ ino_t saved_ino = 0;
48480+ dev_t saved_dev = 0;
48481
48482 error = user_path_parent(dfd, pathname, &nd, &name);
48483 if (error)
48484@@ -2804,8 +2914,17 @@ static long do_unlinkat(int dfd, const c
48485 if (nd.last.name[nd.last.len])
48486 goto slashes;
48487 inode = dentry->d_inode;
48488- if (inode)
48489+ if (inode) {
48490 ihold(inode);
48491+ if (inode->i_nlink <= 1) {
48492+ saved_ino = inode->i_ino;
48493+ saved_dev = gr_get_dev_from_dentry(dentry);
48494+ }
48495+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48496+ error = -EACCES;
48497+ goto exit2;
48498+ }
48499+ }
48500 error = mnt_want_write(nd.path.mnt);
48501 if (error)
48502 goto exit2;
48503@@ -2813,6 +2932,8 @@ static long do_unlinkat(int dfd, const c
48504 if (error)
48505 goto exit3;
48506 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48507+ if (!error && (saved_ino || saved_dev))
48508+ gr_handle_delete(saved_ino, saved_dev);
48509 exit3:
48510 mnt_drop_write(nd.path.mnt);
48511 exit2:
48512@@ -2890,6 +3011,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
48513 if (IS_ERR(dentry))
48514 goto out_unlock;
48515
48516+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
48517+ error = -EACCES;
48518+ goto out_dput;
48519+ }
48520+
48521 error = mnt_want_write(nd.path.mnt);
48522 if (error)
48523 goto out_dput;
48524@@ -2897,6 +3023,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
48525 if (error)
48526 goto out_drop_write;
48527 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
48528+ if (!error)
48529+ gr_handle_create(dentry, nd.path.mnt);
48530 out_drop_write:
48531 mnt_drop_write(nd.path.mnt);
48532 out_dput:
48533@@ -3005,6 +3133,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48534 error = PTR_ERR(new_dentry);
48535 if (IS_ERR(new_dentry))
48536 goto out_unlock;
48537+
48538+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48539+ old_path.dentry->d_inode,
48540+ old_path.dentry->d_inode->i_mode, to)) {
48541+ error = -EACCES;
48542+ goto out_dput;
48543+ }
48544+
48545+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
48546+ old_path.dentry, old_path.mnt, to)) {
48547+ error = -EACCES;
48548+ goto out_dput;
48549+ }
48550+
48551 error = mnt_want_write(nd.path.mnt);
48552 if (error)
48553 goto out_dput;
48554@@ -3012,6 +3154,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48555 if (error)
48556 goto out_drop_write;
48557 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
48558+ if (!error)
48559+ gr_handle_create(new_dentry, nd.path.mnt);
48560 out_drop_write:
48561 mnt_drop_write(nd.path.mnt);
48562 out_dput:
48563@@ -3189,6 +3333,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48564 char *to;
48565 int error;
48566
48567+ pax_track_stack();
48568+
48569 error = user_path_parent(olddfd, oldname, &oldnd, &from);
48570 if (error)
48571 goto exit;
48572@@ -3245,6 +3391,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48573 if (new_dentry == trap)
48574 goto exit5;
48575
48576+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48577+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48578+ to);
48579+ if (error)
48580+ goto exit5;
48581+
48582 error = mnt_want_write(oldnd.path.mnt);
48583 if (error)
48584 goto exit5;
48585@@ -3254,6 +3406,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48586 goto exit6;
48587 error = vfs_rename(old_dir->d_inode, old_dentry,
48588 new_dir->d_inode, new_dentry);
48589+ if (!error)
48590+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48591+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48592 exit6:
48593 mnt_drop_write(oldnd.path.mnt);
48594 exit5:
48595@@ -3279,6 +3434,8 @@ SYSCALL_DEFINE2(rename, const char __use
48596
48597 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48598 {
48599+ char tmpbuf[64];
48600+ const char *newlink;
48601 int len;
48602
48603 len = PTR_ERR(link);
48604@@ -3288,7 +3445,14 @@ int vfs_readlink(struct dentry *dentry,
48605 len = strlen(link);
48606 if (len > (unsigned) buflen)
48607 len = buflen;
48608- if (copy_to_user(buffer, link, len))
48609+
48610+ if (len < sizeof(tmpbuf)) {
48611+ memcpy(tmpbuf, link, len);
48612+ newlink = tmpbuf;
48613+ } else
48614+ newlink = link;
48615+
48616+ if (copy_to_user(buffer, newlink, len))
48617 len = -EFAULT;
48618 out:
48619 return len;
48620diff -urNp linux-2.6.39.1/fs/namespace.c linux-2.6.39.1/fs/namespace.c
48621--- linux-2.6.39.1/fs/namespace.c 2011-05-19 00:06:34.000000000 -0400
48622+++ linux-2.6.39.1/fs/namespace.c 2011-05-22 20:43:58.000000000 -0400
48623@@ -1328,6 +1328,9 @@ static int do_umount(struct vfsmount *mn
48624 if (!(sb->s_flags & MS_RDONLY))
48625 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48626 up_write(&sb->s_umount);
48627+
48628+ gr_log_remount(mnt->mnt_devname, retval);
48629+
48630 return retval;
48631 }
48632
48633@@ -1347,6 +1350,9 @@ static int do_umount(struct vfsmount *mn
48634 br_write_unlock(vfsmount_lock);
48635 up_write(&namespace_sem);
48636 release_mounts(&umount_list);
48637+
48638+ gr_log_unmount(mnt->mnt_devname, retval);
48639+
48640 return retval;
48641 }
48642
48643@@ -2338,6 +2344,16 @@ long do_mount(char *dev_name, char *dir_
48644 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48645 MS_STRICTATIME);
48646
48647+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48648+ retval = -EPERM;
48649+ goto dput_out;
48650+ }
48651+
48652+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48653+ retval = -EPERM;
48654+ goto dput_out;
48655+ }
48656+
48657 if (flags & MS_REMOUNT)
48658 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48659 data_page);
48660@@ -2352,6 +2368,9 @@ long do_mount(char *dev_name, char *dir_
48661 dev_name, data_page);
48662 dput_out:
48663 path_put(&path);
48664+
48665+ gr_log_mount(dev_name, dir_name, retval);
48666+
48667 return retval;
48668 }
48669
48670@@ -2575,6 +2594,11 @@ SYSCALL_DEFINE2(pivot_root, const char _
48671 if (error)
48672 goto out2;
48673
48674+ if (gr_handle_chroot_pivot()) {
48675+ error = -EPERM;
48676+ goto out2;
48677+ }
48678+
48679 get_fs_root(current->fs, &root);
48680 error = lock_mount(&old);
48681 if (error)
48682diff -urNp linux-2.6.39.1/fs/ncpfs/dir.c linux-2.6.39.1/fs/ncpfs/dir.c
48683--- linux-2.6.39.1/fs/ncpfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48684+++ linux-2.6.39.1/fs/ncpfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48685@@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentr
48686 int res, val = 0, len;
48687 __u8 __name[NCP_MAXPATHLEN + 1];
48688
48689+ pax_track_stack();
48690+
48691 if (dentry == dentry->d_sb->s_root)
48692 return 1;
48693
48694@@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct
48695 int error, res, len;
48696 __u8 __name[NCP_MAXPATHLEN + 1];
48697
48698+ pax_track_stack();
48699+
48700 error = -EIO;
48701 if (!ncp_conn_valid(server))
48702 goto finished;
48703@@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, st
48704 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
48705 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
48706
48707+ pax_track_stack();
48708+
48709 ncp_age_dentry(server, dentry);
48710 len = sizeof(__name);
48711 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
48712@@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir,
48713 int error, len;
48714 __u8 __name[NCP_MAXPATHLEN + 1];
48715
48716+ pax_track_stack();
48717+
48718 DPRINTK("ncp_mkdir: making %s/%s\n",
48719 dentry->d_parent->d_name.name, dentry->d_name.name);
48720
48721@@ -1135,6 +1143,8 @@ static int ncp_rename(struct inode *old_
48722 int old_len, new_len;
48723 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
48724
48725+ pax_track_stack();
48726+
48727 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
48728 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
48729 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
48730diff -urNp linux-2.6.39.1/fs/ncpfs/inode.c linux-2.6.39.1/fs/ncpfs/inode.c
48731--- linux-2.6.39.1/fs/ncpfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48732+++ linux-2.6.39.1/fs/ncpfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48733@@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_b
48734 #endif
48735 struct ncp_entry_info finfo;
48736
48737+ pax_track_stack();
48738+
48739 data.wdog_pid = NULL;
48740 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
48741 if (!server)
48742diff -urNp linux-2.6.39.1/fs/nfs/inode.c linux-2.6.39.1/fs/nfs/inode.c
48743--- linux-2.6.39.1/fs/nfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48744+++ linux-2.6.39.1/fs/nfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48745@@ -999,16 +999,16 @@ static int nfs_size_need_update(const st
48746 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48747 }
48748
48749-static atomic_long_t nfs_attr_generation_counter;
48750+static atomic_long_unchecked_t nfs_attr_generation_counter;
48751
48752 static unsigned long nfs_read_attr_generation_counter(void)
48753 {
48754- return atomic_long_read(&nfs_attr_generation_counter);
48755+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48756 }
48757
48758 unsigned long nfs_inc_attr_generation_counter(void)
48759 {
48760- return atomic_long_inc_return(&nfs_attr_generation_counter);
48761+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48762 }
48763
48764 void nfs_fattr_init(struct nfs_fattr *fattr)
48765diff -urNp linux-2.6.39.1/fs/nfs/nfs4proc.c linux-2.6.39.1/fs/nfs/nfs4proc.c
48766--- linux-2.6.39.1/fs/nfs/nfs4proc.c 2011-06-03 00:04:14.000000000 -0400
48767+++ linux-2.6.39.1/fs/nfs/nfs4proc.c 2011-06-03 00:32:07.000000000 -0400
48768@@ -5845,14 +5845,14 @@ struct nfs4_state_recovery_ops nfs41_nog
48769 };
48770 #endif /* CONFIG_NFS_V4_1 */
48771
48772-struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48773+const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48774 .sched_state_renewal = nfs4_proc_async_renew,
48775 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
48776 .renew_lease = nfs4_proc_renew,
48777 };
48778
48779 #if defined(CONFIG_NFS_V4_1)
48780-struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48781+const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48782 .sched_state_renewal = nfs41_proc_async_sequence,
48783 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
48784 .renew_lease = nfs4_proc_sequence,
48785diff -urNp linux-2.6.39.1/fs/nfsd/lockd.c linux-2.6.39.1/fs/nfsd/lockd.c
48786--- linux-2.6.39.1/fs/nfsd/lockd.c 2011-05-19 00:06:34.000000000 -0400
48787+++ linux-2.6.39.1/fs/nfsd/lockd.c 2011-05-22 19:36:32.000000000 -0400
48788@@ -60,7 +60,7 @@ nlm_fclose(struct file *filp)
48789 fput(filp);
48790 }
48791
48792-static struct nlmsvc_binding nfsd_nlm_ops = {
48793+static const struct nlmsvc_binding nfsd_nlm_ops = {
48794 .fopen = nlm_fopen, /* open file for locking */
48795 .fclose = nlm_fclose, /* close file */
48796 };
48797diff -urNp linux-2.6.39.1/fs/nfsd/nfs4state.c linux-2.6.39.1/fs/nfsd/nfs4state.c
48798--- linux-2.6.39.1/fs/nfsd/nfs4state.c 2011-05-19 00:06:34.000000000 -0400
48799+++ linux-2.6.39.1/fs/nfsd/nfs4state.c 2011-05-22 19:36:32.000000000 -0400
48800@@ -3784,6 +3784,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
48801 unsigned int strhashval;
48802 int err;
48803
48804+ pax_track_stack();
48805+
48806 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
48807 (long long) lock->lk_offset,
48808 (long long) lock->lk_length);
48809diff -urNp linux-2.6.39.1/fs/nfsd/nfs4xdr.c linux-2.6.39.1/fs/nfsd/nfs4xdr.c
48810--- linux-2.6.39.1/fs/nfsd/nfs4xdr.c 2011-05-19 00:06:34.000000000 -0400
48811+++ linux-2.6.39.1/fs/nfsd/nfs4xdr.c 2011-05-22 19:36:32.000000000 -0400
48812@@ -1793,6 +1793,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
48813 .dentry = dentry,
48814 };
48815
48816+ pax_track_stack();
48817+
48818 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
48819 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
48820 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
48821diff -urNp linux-2.6.39.1/fs/nfsd/nfsctl.c linux-2.6.39.1/fs/nfsd/nfsctl.c
48822--- linux-2.6.39.1/fs/nfsd/nfsctl.c 2011-05-19 00:06:34.000000000 -0400
48823+++ linux-2.6.39.1/fs/nfsd/nfsctl.c 2011-05-22 19:36:32.000000000 -0400
48824@@ -182,7 +182,7 @@ static int export_features_open(struct i
48825 return single_open(file, export_features_show, NULL);
48826 }
48827
48828-static struct file_operations export_features_operations = {
48829+static const struct file_operations export_features_operations = {
48830 .open = export_features_open,
48831 .read = seq_read,
48832 .llseek = seq_lseek,
48833diff -urNp linux-2.6.39.1/fs/nfsd/vfs.c linux-2.6.39.1/fs/nfsd/vfs.c
48834--- linux-2.6.39.1/fs/nfsd/vfs.c 2011-05-19 00:06:34.000000000 -0400
48835+++ linux-2.6.39.1/fs/nfsd/vfs.c 2011-05-22 19:36:32.000000000 -0400
48836@@ -898,7 +898,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
48837 } else {
48838 oldfs = get_fs();
48839 set_fs(KERNEL_DS);
48840- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48841+ host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
48842 set_fs(oldfs);
48843 }
48844
48845@@ -1002,7 +1002,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
48846
48847 /* Write the data. */
48848 oldfs = get_fs(); set_fs(KERNEL_DS);
48849- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48850+ host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
48851 set_fs(oldfs);
48852 if (host_err < 0)
48853 goto out_nfserr;
48854@@ -1525,7 +1525,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
48855 */
48856
48857 oldfs = get_fs(); set_fs(KERNEL_DS);
48858- host_err = inode->i_op->readlink(dentry, buf, *lenp);
48859+ host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
48860 set_fs(oldfs);
48861
48862 if (host_err < 0)
48863diff -urNp linux-2.6.39.1/fs/nilfs2/segment.c linux-2.6.39.1/fs/nilfs2/segment.c
48864--- linux-2.6.39.1/fs/nilfs2/segment.c 2011-05-19 00:06:34.000000000 -0400
48865+++ linux-2.6.39.1/fs/nilfs2/segment.c 2011-05-22 19:36:32.000000000 -0400
48866@@ -555,7 +555,7 @@ static void nilfs_write_file_node_binfo(
48867 *vblocknr = binfo->bi_v.bi_vblocknr;
48868 }
48869
48870-static struct nilfs_sc_operations nilfs_sc_file_ops = {
48871+static const struct nilfs_sc_operations nilfs_sc_file_ops = {
48872 .collect_data = nilfs_collect_file_data,
48873 .collect_node = nilfs_collect_file_node,
48874 .collect_bmap = nilfs_collect_file_bmap,
48875@@ -604,7 +604,7 @@ static void nilfs_write_dat_node_binfo(s
48876 *binfo_dat = binfo->bi_dat;
48877 }
48878
48879-static struct nilfs_sc_operations nilfs_sc_dat_ops = {
48880+static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
48881 .collect_data = nilfs_collect_dat_data,
48882 .collect_node = nilfs_collect_file_node,
48883 .collect_bmap = nilfs_collect_dat_bmap,
48884@@ -612,7 +612,7 @@ static struct nilfs_sc_operations nilfs_
48885 .write_node_binfo = nilfs_write_dat_node_binfo,
48886 };
48887
48888-static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48889+static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48890 .collect_data = nilfs_collect_file_data,
48891 .collect_node = NULL,
48892 .collect_bmap = NULL,
48893@@ -971,7 +971,7 @@ static size_t nilfs_segctor_buffer_rest(
48894
48895 static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
48896 struct inode *inode,
48897- struct nilfs_sc_operations *sc_ops)
48898+ const struct nilfs_sc_operations *sc_ops)
48899 {
48900 LIST_HEAD(data_buffers);
48901 LIST_HEAD(node_buffers);
48902@@ -1475,7 +1475,7 @@ nilfs_segctor_update_payload_blocknr(str
48903 sector_t blocknr;
48904 unsigned long nfinfo = segbuf->sb_sum.nfinfo;
48905 unsigned long nblocks = 0, ndatablk = 0;
48906- struct nilfs_sc_operations *sc_op = NULL;
48907+ const struct nilfs_sc_operations *sc_op = NULL;
48908 struct nilfs_segsum_pointer ssp;
48909 struct nilfs_finfo *finfo = NULL;
48910 union nilfs_binfo binfo;
48911diff -urNp linux-2.6.39.1/fs/notify/dnotify/dnotify.c linux-2.6.39.1/fs/notify/dnotify/dnotify.c
48912--- linux-2.6.39.1/fs/notify/dnotify/dnotify.c 2011-05-19 00:06:34.000000000 -0400
48913+++ linux-2.6.39.1/fs/notify/dnotify/dnotify.c 2011-05-22 19:36:32.000000000 -0400
48914@@ -151,7 +151,7 @@ static void dnotify_free_mark(struct fsn
48915 kmem_cache_free(dnotify_mark_cache, dn_mark);
48916 }
48917
48918-static struct fsnotify_ops dnotify_fsnotify_ops = {
48919+static const struct fsnotify_ops dnotify_fsnotify_ops = {
48920 .handle_event = dnotify_handle_event,
48921 .should_send_event = dnotify_should_send_event,
48922 .free_group_priv = NULL,
48923diff -urNp linux-2.6.39.1/fs/notify/notification.c linux-2.6.39.1/fs/notify/notification.c
48924--- linux-2.6.39.1/fs/notify/notification.c 2011-05-19 00:06:34.000000000 -0400
48925+++ linux-2.6.39.1/fs/notify/notification.c 2011-05-22 19:36:32.000000000 -0400
48926@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
48927 * get set to 0 so it will never get 'freed'
48928 */
48929 static struct fsnotify_event *q_overflow_event;
48930-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48931+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48932
48933 /**
48934 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48935@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
48936 */
48937 u32 fsnotify_get_cookie(void)
48938 {
48939- return atomic_inc_return(&fsnotify_sync_cookie);
48940+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48941 }
48942 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48943
48944diff -urNp linux-2.6.39.1/fs/ntfs/dir.c linux-2.6.39.1/fs/ntfs/dir.c
48945--- linux-2.6.39.1/fs/ntfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48946+++ linux-2.6.39.1/fs/ntfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48947@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48948 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48949 ~(s64)(ndir->itype.index.block_size - 1)));
48950 /* Bounds checks. */
48951- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48952+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48953 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48954 "inode 0x%lx or driver bug.", vdir->i_ino);
48955 goto err_out;
48956diff -urNp linux-2.6.39.1/fs/ntfs/file.c linux-2.6.39.1/fs/ntfs/file.c
48957--- linux-2.6.39.1/fs/ntfs/file.c 2011-05-19 00:06:34.000000000 -0400
48958+++ linux-2.6.39.1/fs/ntfs/file.c 2011-05-22 19:36:32.000000000 -0400
48959@@ -2222,6 +2222,6 @@ const struct inode_operations ntfs_file_
48960 #endif /* NTFS_RW */
48961 };
48962
48963-const struct file_operations ntfs_empty_file_ops = {};
48964+const struct file_operations ntfs_empty_file_ops __read_only;
48965
48966-const struct inode_operations ntfs_empty_inode_ops = {};
48967+const struct inode_operations ntfs_empty_inode_ops __read_only;
48968diff -urNp linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c
48969--- linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c 2011-05-19 00:06:34.000000000 -0400
48970+++ linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c 2011-05-22 19:36:32.000000000 -0400
48971@@ -2261,7 +2261,7 @@ static struct configfs_item_operations o
48972 .store_attribute = o2hb_heartbeat_group_store,
48973 };
48974
48975-static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48976+static const struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48977 .make_item = o2hb_heartbeat_group_make_item,
48978 .drop_item = o2hb_heartbeat_group_drop_item,
48979 };
48980diff -urNp linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c
48981--- linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c 2011-05-19 00:06:34.000000000 -0400
48982+++ linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c 2011-05-22 19:36:32.000000000 -0400
48983@@ -752,7 +752,7 @@ static void o2nm_node_group_drop_item(st
48984 config_item_put(item);
48985 }
48986
48987-static struct configfs_group_operations o2nm_node_group_group_ops = {
48988+static const struct configfs_group_operations o2nm_node_group_group_ops = {
48989 .make_item = o2nm_node_group_make_item,
48990 .drop_item = o2nm_node_group_drop_item,
48991 };
48992@@ -869,7 +869,7 @@ static void o2nm_cluster_group_drop_item
48993 config_item_put(item);
48994 }
48995
48996-static struct configfs_group_operations o2nm_cluster_group_group_ops = {
48997+static const struct configfs_group_operations o2nm_cluster_group_group_ops = {
48998 .make_group = o2nm_cluster_group_make_group,
48999 .drop_item = o2nm_cluster_group_drop_item,
49000 };
49001diff -urNp linux-2.6.39.1/fs/ocfs2/localalloc.c linux-2.6.39.1/fs/ocfs2/localalloc.c
49002--- linux-2.6.39.1/fs/ocfs2/localalloc.c 2011-05-19 00:06:34.000000000 -0400
49003+++ linux-2.6.39.1/fs/ocfs2/localalloc.c 2011-05-22 19:36:32.000000000 -0400
49004@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_windo
49005 goto bail;
49006 }
49007
49008- atomic_inc(&osb->alloc_stats.moves);
49009+ atomic_inc_unchecked(&osb->alloc_stats.moves);
49010
49011 bail:
49012 if (handle)
49013diff -urNp linux-2.6.39.1/fs/ocfs2/namei.c linux-2.6.39.1/fs/ocfs2/namei.c
49014--- linux-2.6.39.1/fs/ocfs2/namei.c 2011-05-19 00:06:34.000000000 -0400
49015+++ linux-2.6.39.1/fs/ocfs2/namei.c 2011-05-22 19:36:32.000000000 -0400
49016@@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *ol
49017 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
49018 struct ocfs2_dir_lookup_result target_insert = { NULL, };
49019
49020+ pax_track_stack();
49021+
49022 /* At some point it might be nice to break this function up a
49023 * bit. */
49024
49025diff -urNp linux-2.6.39.1/fs/ocfs2/ocfs2.h linux-2.6.39.1/fs/ocfs2/ocfs2.h
49026--- linux-2.6.39.1/fs/ocfs2/ocfs2.h 2011-05-19 00:06:34.000000000 -0400
49027+++ linux-2.6.39.1/fs/ocfs2/ocfs2.h 2011-05-22 19:36:32.000000000 -0400
49028@@ -235,11 +235,11 @@ enum ocfs2_vol_state
49029
49030 struct ocfs2_alloc_stats
49031 {
49032- atomic_t moves;
49033- atomic_t local_data;
49034- atomic_t bitmap_data;
49035- atomic_t bg_allocs;
49036- atomic_t bg_extends;
49037+ atomic_unchecked_t moves;
49038+ atomic_unchecked_t local_data;
49039+ atomic_unchecked_t bitmap_data;
49040+ atomic_unchecked_t bg_allocs;
49041+ atomic_unchecked_t bg_extends;
49042 };
49043
49044 enum ocfs2_local_alloc_state
49045diff -urNp linux-2.6.39.1/fs/ocfs2/stackglue.h linux-2.6.39.1/fs/ocfs2/stackglue.h
49046--- linux-2.6.39.1/fs/ocfs2/stackglue.h 2011-05-19 00:06:34.000000000 -0400
49047+++ linux-2.6.39.1/fs/ocfs2/stackglue.h 2011-05-22 19:36:32.000000000 -0400
49048@@ -221,13 +221,13 @@ struct ocfs2_stack_operations {
49049 };
49050
49051 /*
49052- * Each stack plugin must describe itself by registering a
49053+ * Each stack plugin must describe itself by registerin const g a
49054 * ocfs2_stack_plugin structure. This is only seen by stackglue and the
49055 * stack driver.
49056 */
49057 struct ocfs2_stack_plugin {
49058 char *sp_name;
49059- struct ocfs2_stack_operations *sp_ops;
49060+ const struct ocfs2_stack_operations *sp_ops;
49061 struct module *sp_owner;
49062
49063 /* These are managed by the stackglue code. */
49064diff -urNp linux-2.6.39.1/fs/ocfs2/stack_o2cb.c linux-2.6.39.1/fs/ocfs2/stack_o2cb.c
49065--- linux-2.6.39.1/fs/ocfs2/stack_o2cb.c 2011-05-19 00:06:34.000000000 -0400
49066+++ linux-2.6.39.1/fs/ocfs2/stack_o2cb.c 2011-06-07 18:07:24.000000000 -0400
49067@@ -358,7 +358,7 @@ static int o2cb_cluster_this_node(unsign
49068 return 0;
49069 }
49070
49071-static struct ocfs2_stack_operations o2cb_stack_ops = {
49072+static const struct ocfs2_stack_operations o2cb_stack_ops = {
49073 .connect = o2cb_cluster_connect,
49074 .disconnect = o2cb_cluster_disconnect,
49075 .this_node = o2cb_cluster_this_node,
49076diff -urNp linux-2.6.39.1/fs/ocfs2/stack_user.c linux-2.6.39.1/fs/ocfs2/stack_user.c
49077--- linux-2.6.39.1/fs/ocfs2/stack_user.c 2011-05-19 00:06:34.000000000 -0400
49078+++ linux-2.6.39.1/fs/ocfs2/stack_user.c 2011-05-22 19:36:32.000000000 -0400
49079@@ -399,7 +399,7 @@ static int ocfs2_control_do_setversion_m
49080 long major, minor;
49081 char *ptr = NULL;
49082 struct ocfs2_control_private *p = file->private_data;
49083- struct ocfs2_protocol_version *max =
49084+ const struct ocfs2_protocol_version *max =
49085 &ocfs2_user_plugin.sp_max_proto;
49086
49087 if (ocfs2_control_get_handshake_state(file) !=
49088@@ -861,7 +861,7 @@ static int user_cluster_this_node(unsign
49089 return 0;
49090 }
49091
49092-static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
49093+static const struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
49094 .connect = user_cluster_connect,
49095 .disconnect = user_cluster_disconnect,
49096 .this_node = user_cluster_this_node,
49097diff -urNp linux-2.6.39.1/fs/ocfs2/suballoc.c linux-2.6.39.1/fs/ocfs2/suballoc.c
49098--- linux-2.6.39.1/fs/ocfs2/suballoc.c 2011-05-19 00:06:34.000000000 -0400
49099+++ linux-2.6.39.1/fs/ocfs2/suballoc.c 2011-05-22 19:36:32.000000000 -0400
49100@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(s
49101 mlog_errno(status);
49102 goto bail;
49103 }
49104- atomic_inc(&osb->alloc_stats.bg_extends);
49105+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49106
49107 /* You should never ask for this much metadata */
49108 BUG_ON(bits_wanted >
49109@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handl
49110 mlog_errno(status);
49111 goto bail;
49112 }
49113- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49114+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49115
49116 *suballoc_loc = res.sr_bg_blkno;
49117 *suballoc_bit_start = res.sr_bit_offset;
49118@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_
49119 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49120 res->sr_bits);
49121
49122- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49123+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49124
49125 BUG_ON(res->sr_bits != 1);
49126
49127@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *hand
49128 mlog_errno(status);
49129 goto bail;
49130 }
49131- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49132+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49133
49134 BUG_ON(res.sr_bits != 1);
49135
49136@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *han
49137 cluster_start,
49138 num_clusters);
49139 if (!status)
49140- atomic_inc(&osb->alloc_stats.local_data);
49141+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
49142 } else {
49143 if (min_clusters > (osb->bitmap_cpg - 1)) {
49144 /* The only paths asking for contiguousness
49145@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *han
49146 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49147 res.sr_bg_blkno,
49148 res.sr_bit_offset);
49149- atomic_inc(&osb->alloc_stats.bitmap_data);
49150+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49151 *num_clusters = res.sr_bits;
49152 }
49153 }
49154diff -urNp linux-2.6.39.1/fs/ocfs2/super.c linux-2.6.39.1/fs/ocfs2/super.c
49155--- linux-2.6.39.1/fs/ocfs2/super.c 2011-05-19 00:06:34.000000000 -0400
49156+++ linux-2.6.39.1/fs/ocfs2/super.c 2011-05-22 19:36:32.000000000 -0400
49157@@ -299,11 +299,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
49158 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49159 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49160 "Stats",
49161- atomic_read(&osb->alloc_stats.bitmap_data),
49162- atomic_read(&osb->alloc_stats.local_data),
49163- atomic_read(&osb->alloc_stats.bg_allocs),
49164- atomic_read(&osb->alloc_stats.moves),
49165- atomic_read(&osb->alloc_stats.bg_extends));
49166+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49167+ atomic_read_unchecked(&osb->alloc_stats.local_data),
49168+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49169+ atomic_read_unchecked(&osb->alloc_stats.moves),
49170+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49171
49172 out += snprintf(buf + out, len - out,
49173 "%10s => State: %u Descriptor: %llu Size: %u bits "
49174@@ -2111,11 +2111,11 @@ static int ocfs2_initialize_super(struct
49175 spin_lock_init(&osb->osb_xattr_lock);
49176 ocfs2_init_steal_slots(osb);
49177
49178- atomic_set(&osb->alloc_stats.moves, 0);
49179- atomic_set(&osb->alloc_stats.local_data, 0);
49180- atomic_set(&osb->alloc_stats.bitmap_data, 0);
49181- atomic_set(&osb->alloc_stats.bg_allocs, 0);
49182- atomic_set(&osb->alloc_stats.bg_extends, 0);
49183+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49184+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49185+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49186+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49187+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49188
49189 /* Copy the blockcheck stats from the superblock probe */
49190 osb->osb_ecc_stats = *stats;
49191diff -urNp linux-2.6.39.1/fs/ocfs2/symlink.c linux-2.6.39.1/fs/ocfs2/symlink.c
49192--- linux-2.6.39.1/fs/ocfs2/symlink.c 2011-05-19 00:06:34.000000000 -0400
49193+++ linux-2.6.39.1/fs/ocfs2/symlink.c 2011-05-22 19:36:32.000000000 -0400
49194@@ -142,7 +142,7 @@ bail:
49195
49196 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49197 {
49198- char *link = nd_get_link(nd);
49199+ const char *link = nd_get_link(nd);
49200 if (!IS_ERR(link))
49201 kfree(link);
49202 }
49203diff -urNp linux-2.6.39.1/fs/open.c linux-2.6.39.1/fs/open.c
49204--- linux-2.6.39.1/fs/open.c 2011-05-19 00:06:34.000000000 -0400
49205+++ linux-2.6.39.1/fs/open.c 2011-05-22 20:46:51.000000000 -0400
49206@@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
49207 error = locks_verify_truncate(inode, NULL, length);
49208 if (!error)
49209 error = security_path_truncate(&path);
49210+
49211+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49212+ error = -EACCES;
49213+
49214 if (!error)
49215 error = do_truncate(path.dentry, length, 0, NULL);
49216
49217@@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
49218 if (__mnt_is_readonly(path.mnt))
49219 res = -EROFS;
49220
49221+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49222+ res = -EACCES;
49223+
49224 out_path_release:
49225 path_put(&path);
49226 out:
49227@@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user
49228 if (error)
49229 goto dput_and_out;
49230
49231+ gr_log_chdir(path.dentry, path.mnt);
49232+
49233 set_fs_pwd(current->fs, &path);
49234
49235 dput_and_out:
49236@@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
49237 goto out_putf;
49238
49239 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49240+
49241+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49242+ error = -EPERM;
49243+
49244+ if (!error)
49245+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49246+
49247 if (!error)
49248 set_fs_pwd(current->fs, &file->f_path);
49249 out_putf:
49250@@ -438,7 +454,18 @@ SYSCALL_DEFINE1(chroot, const char __use
49251 if (error)
49252 goto dput_and_out;
49253
49254+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49255+ goto dput_and_out;
49256+
49257+ if (gr_handle_chroot_caps(&path)) {
49258+ error = -ENOMEM;
49259+ goto dput_and_out;
49260+ }
49261+
49262 set_fs_root(current->fs, &path);
49263+
49264+ gr_handle_chroot_chdir(&path);
49265+
49266 error = 0;
49267 dput_and_out:
49268 path_put(&path);
49269@@ -466,12 +493,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
49270 err = mnt_want_write_file(file);
49271 if (err)
49272 goto out_putf;
49273+
49274 mutex_lock(&inode->i_mutex);
49275+
49276+ if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
49277+ err = -EACCES;
49278+ goto out_unlock;
49279+ }
49280+
49281 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
49282 if (err)
49283 goto out_unlock;
49284 if (mode == (mode_t) -1)
49285 mode = inode->i_mode;
49286+
49287+ if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
49288+ err = -EACCES;
49289+ goto out_unlock;
49290+ }
49291+
49292 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49293 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49294 err = notify_change(dentry, &newattrs);
49295@@ -499,12 +539,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
49296 error = mnt_want_write(path.mnt);
49297 if (error)
49298 goto dput_and_out;
49299+
49300 mutex_lock(&inode->i_mutex);
49301+
49302+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
49303+ error = -EACCES;
49304+ goto out_unlock;
49305+ }
49306+
49307 error = security_path_chmod(path.dentry, path.mnt, mode);
49308 if (error)
49309 goto out_unlock;
49310 if (mode == (mode_t) -1)
49311 mode = inode->i_mode;
49312+
49313+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
49314+ error = -EACCES;
49315+ goto out_unlock;
49316+ }
49317+
49318 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49319 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49320 error = notify_change(path.dentry, &newattrs);
49321@@ -528,6 +581,9 @@ static int chown_common(struct path *pat
49322 int error;
49323 struct iattr newattrs;
49324
49325+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
49326+ return -EACCES;
49327+
49328 newattrs.ia_valid = ATTR_CTIME;
49329 if (user != (uid_t) -1) {
49330 newattrs.ia_valid |= ATTR_UID;
49331@@ -998,7 +1054,10 @@ long do_sys_open(int dfd, const char __u
49332 if (!IS_ERR(tmp)) {
49333 fd = get_unused_fd_flags(flags);
49334 if (fd >= 0) {
49335- struct file *f = do_filp_open(dfd, tmp, &op, lookup);
49336+ struct file *f;
49337+ /* don't allow to be set by userland */
49338+ flags &= ~FMODE_GREXEC;
49339+ f = do_filp_open(dfd, tmp, &op, lookup);
49340 if (IS_ERR(f)) {
49341 put_unused_fd(fd);
49342 fd = PTR_ERR(f);
49343diff -urNp linux-2.6.39.1/fs/partitions/ldm.c linux-2.6.39.1/fs/partitions/ldm.c
49344--- linux-2.6.39.1/fs/partitions/ldm.c 2011-06-03 00:04:14.000000000 -0400
49345+++ linux-2.6.39.1/fs/partitions/ldm.c 2011-06-03 00:32:07.000000000 -0400
49346@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
49347 ldm_error ("A VBLK claims to have %d parts.", num);
49348 return false;
49349 }
49350+
49351 if (rec >= num) {
49352 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
49353 return false;
49354@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
49355 goto found;
49356 }
49357
49358- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
49359+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
49360 if (!f) {
49361 ldm_crit ("Out of memory.");
49362 return false;
49363diff -urNp linux-2.6.39.1/fs/pipe.c linux-2.6.39.1/fs/pipe.c
49364--- linux-2.6.39.1/fs/pipe.c 2011-05-19 00:06:34.000000000 -0400
49365+++ linux-2.6.39.1/fs/pipe.c 2011-05-22 19:41:37.000000000 -0400
49366@@ -420,9 +420,9 @@ redo:
49367 }
49368 if (bufs) /* More to do? */
49369 continue;
49370- if (!pipe->writers)
49371+ if (!atomic_read(&pipe->writers))
49372 break;
49373- if (!pipe->waiting_writers) {
49374+ if (!atomic_read(&pipe->waiting_writers)) {
49375 /* syscall merging: Usually we must not sleep
49376 * if O_NONBLOCK is set, or if we got some data.
49377 * But if a writer sleeps in kernel space, then
49378@@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
49379 mutex_lock(&inode->i_mutex);
49380 pipe = inode->i_pipe;
49381
49382- if (!pipe->readers) {
49383+ if (!atomic_read(&pipe->readers)) {
49384 send_sig(SIGPIPE, current, 0);
49385 ret = -EPIPE;
49386 goto out;
49387@@ -530,7 +530,7 @@ redo1:
49388 for (;;) {
49389 int bufs;
49390
49391- if (!pipe->readers) {
49392+ if (!atomic_read(&pipe->readers)) {
49393 send_sig(SIGPIPE, current, 0);
49394 if (!ret)
49395 ret = -EPIPE;
49396@@ -616,9 +616,9 @@ redo2:
49397 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49398 do_wakeup = 0;
49399 }
49400- pipe->waiting_writers++;
49401+ atomic_inc(&pipe->waiting_writers);
49402 pipe_wait(pipe);
49403- pipe->waiting_writers--;
49404+ atomic_dec(&pipe->waiting_writers);
49405 }
49406 out:
49407 mutex_unlock(&inode->i_mutex);
49408@@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
49409 mask = 0;
49410 if (filp->f_mode & FMODE_READ) {
49411 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49412- if (!pipe->writers && filp->f_version != pipe->w_counter)
49413+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49414 mask |= POLLHUP;
49415 }
49416
49417@@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
49418 * Most Unices do not set POLLERR for FIFOs but on Linux they
49419 * behave exactly like pipes for poll().
49420 */
49421- if (!pipe->readers)
49422+ if (!atomic_read(&pipe->readers))
49423 mask |= POLLERR;
49424 }
49425
49426@@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
49427
49428 mutex_lock(&inode->i_mutex);
49429 pipe = inode->i_pipe;
49430- pipe->readers -= decr;
49431- pipe->writers -= decw;
49432+ atomic_sub(decr, &pipe->readers);
49433+ atomic_sub(decw, &pipe->writers);
49434
49435- if (!pipe->readers && !pipe->writers) {
49436+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49437 free_pipe_info(inode);
49438 } else {
49439 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49440@@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
49441
49442 if (inode->i_pipe) {
49443 ret = 0;
49444- inode->i_pipe->readers++;
49445+ atomic_inc(&inode->i_pipe->readers);
49446 }
49447
49448 mutex_unlock(&inode->i_mutex);
49449@@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
49450
49451 if (inode->i_pipe) {
49452 ret = 0;
49453- inode->i_pipe->writers++;
49454+ atomic_inc(&inode->i_pipe->writers);
49455 }
49456
49457 mutex_unlock(&inode->i_mutex);
49458@@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
49459 if (inode->i_pipe) {
49460 ret = 0;
49461 if (filp->f_mode & FMODE_READ)
49462- inode->i_pipe->readers++;
49463+ atomic_inc(&inode->i_pipe->readers);
49464 if (filp->f_mode & FMODE_WRITE)
49465- inode->i_pipe->writers++;
49466+ atomic_inc(&inode->i_pipe->writers);
49467 }
49468
49469 mutex_unlock(&inode->i_mutex);
49470@@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
49471 inode->i_pipe = NULL;
49472 }
49473
49474-static struct vfsmount *pipe_mnt __read_mostly;
49475+struct vfsmount *pipe_mnt __read_mostly;
49476
49477 /*
49478 * pipefs_dname() is called from d_path().
49479@@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
49480 goto fail_iput;
49481 inode->i_pipe = pipe;
49482
49483- pipe->readers = pipe->writers = 1;
49484+ atomic_set(&pipe->readers, 1);
49485+ atomic_set(&pipe->writers, 1);
49486 inode->i_fop = &rdwr_pipefifo_fops;
49487
49488 /*
49489diff -urNp linux-2.6.39.1/fs/proc/array.c linux-2.6.39.1/fs/proc/array.c
49490--- linux-2.6.39.1/fs/proc/array.c 2011-05-19 00:06:34.000000000 -0400
49491+++ linux-2.6.39.1/fs/proc/array.c 2011-05-22 19:41:37.000000000 -0400
49492@@ -60,6 +60,7 @@
49493 #include <linux/tty.h>
49494 #include <linux/string.h>
49495 #include <linux/mman.h>
49496+#include <linux/grsecurity.h>
49497 #include <linux/proc_fs.h>
49498 #include <linux/ioport.h>
49499 #include <linux/uaccess.h>
49500@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
49501 seq_putc(m, '\n');
49502 }
49503
49504+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49505+static inline void task_pax(struct seq_file *m, struct task_struct *p)
49506+{
49507+ if (p->mm)
49508+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49509+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49510+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49511+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49512+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49513+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49514+ else
49515+ seq_printf(m, "PaX:\t-----\n");
49516+}
49517+#endif
49518+
49519 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49520 struct pid *pid, struct task_struct *task)
49521 {
49522@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
49523 task_cpus_allowed(m, task);
49524 cpuset_task_status_allowed(m, task);
49525 task_context_switch_counts(m, task);
49526+
49527+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49528+ task_pax(m, task);
49529+#endif
49530+
49531+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49532+ task_grsec_rbac(m, task);
49533+#endif
49534+
49535 return 0;
49536 }
49537
49538+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49539+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49540+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49541+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49542+#endif
49543+
49544 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49545 struct pid *pid, struct task_struct *task, int whole)
49546 {
49547@@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
49548 cputime_t cutime, cstime, utime, stime;
49549 cputime_t cgtime, gtime;
49550 unsigned long rsslim = 0;
49551- char tcomm[sizeof(task->comm)];
49552+ char tcomm[sizeof(task->comm)] = { 0 };
49553 unsigned long flags;
49554
49555+ pax_track_stack();
49556+
49557 state = *get_task_state(task);
49558 vsize = eip = esp = 0;
49559 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
49560@@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
49561 gtime = task->gtime;
49562 }
49563
49564+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49565+ if (PAX_RAND_FLAGS(mm)) {
49566+ eip = 0;
49567+ esp = 0;
49568+ wchan = 0;
49569+ }
49570+#endif
49571+#ifdef CONFIG_GRKERNSEC_HIDESYM
49572+ wchan = 0;
49573+ eip =0;
49574+ esp =0;
49575+#endif
49576+
49577 /* scale priority and nice values from timeslices to -20..20 */
49578 /* to make it look like a "normal" Unix priority/nice value */
49579 priority = task_prio(task);
49580@@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
49581 vsize,
49582 mm ? get_mm_rss(mm) : 0,
49583 rsslim,
49584+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49585+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
49586+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
49587+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
49588+#else
49589 mm ? (permitted ? mm->start_code : 1) : 0,
49590 mm ? (permitted ? mm->end_code : 1) : 0,
49591 (permitted && mm) ? mm->start_stack : 0,
49592+#endif
49593 esp,
49594 eip,
49595 /* The signal information here is obsolete.
49596@@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
49597
49598 return 0;
49599 }
49600+
49601+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49602+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49603+{
49604+ u32 curr_ip = 0;
49605+ unsigned long flags;
49606+
49607+ if (lock_task_sighand(task, &flags)) {
49608+ curr_ip = task->signal->curr_ip;
49609+ unlock_task_sighand(task, &flags);
49610+ }
49611+
49612+ return sprintf(buffer, "%pI4\n", &curr_ip);
49613+}
49614+#endif
49615diff -urNp linux-2.6.39.1/fs/proc/base.c linux-2.6.39.1/fs/proc/base.c
49616--- linux-2.6.39.1/fs/proc/base.c 2011-05-19 00:06:34.000000000 -0400
49617+++ linux-2.6.39.1/fs/proc/base.c 2011-06-04 21:20:04.000000000 -0400
49618@@ -104,6 +104,22 @@ struct pid_entry {
49619 union proc_op op;
49620 };
49621
49622+struct getdents_callback {
49623+ struct linux_dirent __user * current_dir;
49624+ struct linux_dirent __user * previous;
49625+ struct file * file;
49626+ int count;
49627+ int error;
49628+};
49629+
49630+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
49631+ loff_t offset, u64 ino, unsigned int d_type)
49632+{
49633+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
49634+ buf->error = -EINVAL;
49635+ return 0;
49636+}
49637+
49638 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49639 .name = (NAME), \
49640 .len = sizeof(NAME) - 1, \
49641@@ -206,6 +222,9 @@ static struct mm_struct *__check_mem_per
49642 if (task == current)
49643 return mm;
49644
49645+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
49646+ return ERR_PTR(-EPERM);
49647+
49648 /*
49649 * If current is actively ptrace'ing, and would also be
49650 * permitted to freshly attach with ptrace now, permit it.
49651@@ -279,6 +298,9 @@ static int proc_pid_cmdline(struct task_
49652 if (!mm->arg_end)
49653 goto out_mm; /* Shh! No looking before we're done */
49654
49655+ if (gr_acl_handle_procpidmem(task))
49656+ goto out_mm;
49657+
49658 len = mm->arg_end - mm->arg_start;
49659
49660 if (len > PAGE_SIZE)
49661@@ -306,12 +328,28 @@ out:
49662 return res;
49663 }
49664
49665+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49666+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49667+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49668+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49669+#endif
49670+
49671 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49672 {
49673 struct mm_struct *mm = mm_for_maps(task);
49674 int res = PTR_ERR(mm);
49675 if (mm && !IS_ERR(mm)) {
49676 unsigned int nwords = 0;
49677+
49678+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49679+ /* allow if we're currently ptracing this task */
49680+ if (PAX_RAND_FLAGS(mm) &&
49681+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49682+ mmput(mm);
49683+ return res;
49684+ }
49685+#endif
49686+
49687 do {
49688 nwords += 2;
49689 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49690@@ -325,7 +363,7 @@ static int proc_pid_auxv(struct task_str
49691 }
49692
49693
49694-#ifdef CONFIG_KALLSYMS
49695+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49696 /*
49697 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49698 * Returns the resolved symbol. If that fails, simply return the address.
49699@@ -364,7 +402,7 @@ static void unlock_trace(struct task_str
49700 mutex_unlock(&task->signal->cred_guard_mutex);
49701 }
49702
49703-#ifdef CONFIG_STACKTRACE
49704+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49705
49706 #define MAX_STACK_TRACE_DEPTH 64
49707
49708@@ -555,7 +593,7 @@ static int proc_pid_limits(struct task_s
49709 return count;
49710 }
49711
49712-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49713+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49714 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49715 {
49716 long nr;
49717@@ -584,7 +622,7 @@ static int proc_pid_syscall(struct task_
49718 /************************************************************************/
49719
49720 /* permission checks */
49721-static int proc_fd_access_allowed(struct inode *inode)
49722+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49723 {
49724 struct task_struct *task;
49725 int allowed = 0;
49726@@ -594,7 +632,10 @@ static int proc_fd_access_allowed(struct
49727 */
49728 task = get_proc_task(inode);
49729 if (task) {
49730- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49731+ if (log)
49732+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
49733+ else
49734+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49735 put_task_struct(task);
49736 }
49737 return allowed;
49738@@ -973,6 +1014,9 @@ static ssize_t environ_read(struct file
49739 if (!task)
49740 goto out_no_task;
49741
49742+ if (gr_acl_handle_procpidmem(task))
49743+ goto out;
49744+
49745 ret = -ENOMEM;
49746 page = (char *)__get_free_page(GFP_TEMPORARY);
49747 if (!page)
49748@@ -1660,7 +1704,7 @@ static void *proc_pid_follow_link(struct
49749 path_put(&nd->path);
49750
49751 /* Are we allowed to snoop on the tasks file descriptors? */
49752- if (!proc_fd_access_allowed(inode))
49753+ if (!proc_fd_access_allowed(inode,0))
49754 goto out;
49755
49756 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
49757@@ -1699,8 +1743,18 @@ static int proc_pid_readlink(struct dent
49758 struct path path;
49759
49760 /* Are we allowed to snoop on the tasks file descriptors? */
49761- if (!proc_fd_access_allowed(inode))
49762- goto out;
49763+ /* logging this is needed for learning on chromium to work properly,
49764+ but we don't want to flood the logs from 'ps' which does a readlink
49765+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49766+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49767+ */
49768+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49769+ if (!proc_fd_access_allowed(inode,0))
49770+ goto out;
49771+ } else {
49772+ if (!proc_fd_access_allowed(inode,1))
49773+ goto out;
49774+ }
49775
49776 error = PROC_I(inode)->op.proc_get_link(inode, &path);
49777 if (error)
49778@@ -1766,7 +1820,11 @@ static struct inode *proc_pid_make_inode
49779 rcu_read_lock();
49780 cred = __task_cred(task);
49781 inode->i_uid = cred->euid;
49782+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49783+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49784+#else
49785 inode->i_gid = cred->egid;
49786+#endif
49787 rcu_read_unlock();
49788 }
49789 security_task_to_inode(task, inode);
49790@@ -1784,6 +1842,9 @@ static int pid_getattr(struct vfsmount *
49791 struct inode *inode = dentry->d_inode;
49792 struct task_struct *task;
49793 const struct cred *cred;
49794+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49795+ const struct cred *tmpcred = current_cred();
49796+#endif
49797
49798 generic_fillattr(inode, stat);
49799
49800@@ -1791,13 +1852,41 @@ static int pid_getattr(struct vfsmount *
49801 stat->uid = 0;
49802 stat->gid = 0;
49803 task = pid_task(proc_pid(inode), PIDTYPE_PID);
49804+
49805+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
49806+ rcu_read_unlock();
49807+ return -ENOENT;
49808+ }
49809+
49810 if (task) {
49811+ cred = __task_cred(task);
49812+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49813+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49814+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49815+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49816+#endif
49817+ ) {
49818+#endif
49819 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49820+#ifdef CONFIG_GRKERNSEC_PROC_USER
49821+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49822+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49823+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49824+#endif
49825 task_dumpable(task)) {
49826- cred = __task_cred(task);
49827 stat->uid = cred->euid;
49828+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49829+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49830+#else
49831 stat->gid = cred->egid;
49832+#endif
49833 }
49834+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49835+ } else {
49836+ rcu_read_unlock();
49837+ return -ENOENT;
49838+ }
49839+#endif
49840 }
49841 rcu_read_unlock();
49842 return 0;
49843@@ -1834,11 +1923,20 @@ static int pid_revalidate(struct dentry
49844
49845 if (task) {
49846 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49847+#ifdef CONFIG_GRKERNSEC_PROC_USER
49848+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49849+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49850+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49851+#endif
49852 task_dumpable(task)) {
49853 rcu_read_lock();
49854 cred = __task_cred(task);
49855 inode->i_uid = cred->euid;
49856+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49857+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49858+#else
49859 inode->i_gid = cred->egid;
49860+#endif
49861 rcu_read_unlock();
49862 } else {
49863 inode->i_uid = 0;
49864@@ -1959,7 +2057,8 @@ static int proc_fd_info(struct inode *in
49865 int fd = proc_fd(inode);
49866
49867 if (task) {
49868- files = get_files_struct(task);
49869+ if (!gr_acl_handle_procpidmem(task))
49870+ files = get_files_struct(task);
49871 put_task_struct(task);
49872 }
49873 if (files) {
49874@@ -2219,15 +2318,25 @@ static const struct file_operations proc
49875 */
49876 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
49877 {
49878+ struct task_struct *task;
49879 int rv;
49880
49881 if (flags & IPERM_FLAG_RCU)
49882 return -ECHILD;
49883 rv = generic_permission(inode, mask, flags, NULL);
49884- if (rv == 0)
49885- return 0;
49886+
49887 if (task_pid(current) == proc_pid(inode))
49888 rv = 0;
49889+
49890+ task = get_proc_task(inode);
49891+ if (task == NULL)
49892+ return rv;
49893+
49894+ if (gr_acl_handle_procpidmem(task))
49895+ rv = -EACCES;
49896+
49897+ put_task_struct(task);
49898+
49899 return rv;
49900 }
49901
49902@@ -2337,6 +2446,9 @@ static struct dentry *proc_pident_lookup
49903 if (!task)
49904 goto out_no_task;
49905
49906+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49907+ goto out;
49908+
49909 /*
49910 * Yes, it does not scale. And it should not. Don't add
49911 * new entries into /proc/<tgid>/ without very good reasons.
49912@@ -2381,6 +2493,9 @@ static int proc_pident_readdir(struct fi
49913 if (!task)
49914 goto out_no_task;
49915
49916+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49917+ goto out;
49918+
49919 ret = 0;
49920 i = filp->f_pos;
49921 switch (i) {
49922@@ -2651,7 +2766,7 @@ static void *proc_self_follow_link(struc
49923 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49924 void *cookie)
49925 {
49926- char *s = nd_get_link(nd);
49927+ const char *s = nd_get_link(nd);
49928 if (!IS_ERR(s))
49929 __putname(s);
49930 }
49931@@ -2835,7 +2950,7 @@ static const struct pid_entry tgid_base_
49932 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49933 #endif
49934 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49935-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49936+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49937 INF("syscall", S_IRUGO, proc_pid_syscall),
49938 #endif
49939 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49940@@ -2860,10 +2975,10 @@ static const struct pid_entry tgid_base_
49941 #ifdef CONFIG_SECURITY
49942 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49943 #endif
49944-#ifdef CONFIG_KALLSYMS
49945+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49946 INF("wchan", S_IRUGO, proc_pid_wchan),
49947 #endif
49948-#ifdef CONFIG_STACKTRACE
49949+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49950 ONE("stack", S_IRUGO, proc_pid_stack),
49951 #endif
49952 #ifdef CONFIG_SCHEDSTATS
49953@@ -2894,6 +3009,9 @@ static const struct pid_entry tgid_base_
49954 #ifdef CONFIG_TASK_IO_ACCOUNTING
49955 INF("io", S_IRUGO, proc_tgid_io_accounting),
49956 #endif
49957+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49958+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49959+#endif
49960 };
49961
49962 static int proc_tgid_base_readdir(struct file * filp,
49963@@ -3019,7 +3137,14 @@ static struct dentry *proc_pid_instantia
49964 if (!inode)
49965 goto out;
49966
49967+#ifdef CONFIG_GRKERNSEC_PROC_USER
49968+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49969+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49970+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49971+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49972+#else
49973 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49974+#endif
49975 inode->i_op = &proc_tgid_base_inode_operations;
49976 inode->i_fop = &proc_tgid_base_operations;
49977 inode->i_flags|=S_IMMUTABLE;
49978@@ -3061,7 +3186,11 @@ struct dentry *proc_pid_lookup(struct in
49979 if (!task)
49980 goto out;
49981
49982+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49983+ goto out_put_task;
49984+
49985 result = proc_pid_instantiate(dir, dentry, task, NULL);
49986+out_put_task:
49987 put_task_struct(task);
49988 out:
49989 return result;
49990@@ -3126,6 +3255,11 @@ int proc_pid_readdir(struct file * filp,
49991 {
49992 unsigned int nr;
49993 struct task_struct *reaper;
49994+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49995+ const struct cred *tmpcred = current_cred();
49996+ const struct cred *itercred;
49997+#endif
49998+ filldir_t __filldir = filldir;
49999 struct tgid_iter iter;
50000 struct pid_namespace *ns;
50001
50002@@ -3149,8 +3283,27 @@ int proc_pid_readdir(struct file * filp,
50003 for (iter = next_tgid(ns, iter);
50004 iter.task;
50005 iter.tgid += 1, iter = next_tgid(ns, iter)) {
50006+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50007+ rcu_read_lock();
50008+ itercred = __task_cred(iter.task);
50009+#endif
50010+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
50011+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50012+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
50013+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50014+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
50015+#endif
50016+ )
50017+#endif
50018+ )
50019+ __filldir = &gr_fake_filldir;
50020+ else
50021+ __filldir = filldir;
50022+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50023+ rcu_read_unlock();
50024+#endif
50025 filp->f_pos = iter.tgid + TGID_OFFSET;
50026- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
50027+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
50028 put_task_struct(iter.task);
50029 goto out;
50030 }
50031@@ -3177,7 +3330,7 @@ static const struct pid_entry tid_base_s
50032 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50033 #endif
50034 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50035-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50036+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50037 INF("syscall", S_IRUGO, proc_pid_syscall),
50038 #endif
50039 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50040@@ -3201,10 +3354,10 @@ static const struct pid_entry tid_base_s
50041 #ifdef CONFIG_SECURITY
50042 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50043 #endif
50044-#ifdef CONFIG_KALLSYMS
50045+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50046 INF("wchan", S_IRUGO, proc_pid_wchan),
50047 #endif
50048-#ifdef CONFIG_STACKTRACE
50049+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50050 ONE("stack", S_IRUGO, proc_pid_stack),
50051 #endif
50052 #ifdef CONFIG_SCHEDSTATS
50053diff -urNp linux-2.6.39.1/fs/proc/cmdline.c linux-2.6.39.1/fs/proc/cmdline.c
50054--- linux-2.6.39.1/fs/proc/cmdline.c 2011-05-19 00:06:34.000000000 -0400
50055+++ linux-2.6.39.1/fs/proc/cmdline.c 2011-05-22 19:41:37.000000000 -0400
50056@@ -23,7 +23,11 @@ static const struct file_operations cmdl
50057
50058 static int __init proc_cmdline_init(void)
50059 {
50060+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50061+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50062+#else
50063 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50064+#endif
50065 return 0;
50066 }
50067 module_init(proc_cmdline_init);
50068diff -urNp linux-2.6.39.1/fs/proc/devices.c linux-2.6.39.1/fs/proc/devices.c
50069--- linux-2.6.39.1/fs/proc/devices.c 2011-05-19 00:06:34.000000000 -0400
50070+++ linux-2.6.39.1/fs/proc/devices.c 2011-05-22 19:41:37.000000000 -0400
50071@@ -64,7 +64,11 @@ static const struct file_operations proc
50072
50073 static int __init proc_devices_init(void)
50074 {
50075+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50076+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50077+#else
50078 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50079+#endif
50080 return 0;
50081 }
50082 module_init(proc_devices_init);
50083diff -urNp linux-2.6.39.1/fs/proc/inode.c linux-2.6.39.1/fs/proc/inode.c
50084--- linux-2.6.39.1/fs/proc/inode.c 2011-05-19 00:06:34.000000000 -0400
50085+++ linux-2.6.39.1/fs/proc/inode.c 2011-05-22 19:41:37.000000000 -0400
50086@@ -433,7 +433,11 @@ struct inode *proc_get_inode(struct supe
50087 if (de->mode) {
50088 inode->i_mode = de->mode;
50089 inode->i_uid = de->uid;
50090+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50091+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
50092+#else
50093 inode->i_gid = de->gid;
50094+#endif
50095 }
50096 if (de->size)
50097 inode->i_size = de->size;
50098diff -urNp linux-2.6.39.1/fs/proc/internal.h linux-2.6.39.1/fs/proc/internal.h
50099--- linux-2.6.39.1/fs/proc/internal.h 2011-05-19 00:06:34.000000000 -0400
50100+++ linux-2.6.39.1/fs/proc/internal.h 2011-05-22 19:41:37.000000000 -0400
50101@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
50102 struct pid *pid, struct task_struct *task);
50103 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50104 struct pid *pid, struct task_struct *task);
50105+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50106+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50107+#endif
50108 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50109
50110 extern const struct file_operations proc_maps_operations;
50111diff -urNp linux-2.6.39.1/fs/proc/Kconfig linux-2.6.39.1/fs/proc/Kconfig
50112--- linux-2.6.39.1/fs/proc/Kconfig 2011-05-19 00:06:34.000000000 -0400
50113+++ linux-2.6.39.1/fs/proc/Kconfig 2011-05-22 19:41:37.000000000 -0400
50114@@ -30,12 +30,12 @@ config PROC_FS
50115
50116 config PROC_KCORE
50117 bool "/proc/kcore support" if !ARM
50118- depends on PROC_FS && MMU
50119+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50120
50121 config PROC_VMCORE
50122 bool "/proc/vmcore support"
50123- depends on PROC_FS && CRASH_DUMP
50124- default y
50125+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50126+ default n
50127 help
50128 Exports the dump image of crashed kernel in ELF format.
50129
50130@@ -59,8 +59,8 @@ config PROC_SYSCTL
50131 limited in memory.
50132
50133 config PROC_PAGE_MONITOR
50134- default y
50135- depends on PROC_FS && MMU
50136+ default n
50137+ depends on PROC_FS && MMU && !GRKERNSEC
50138 bool "Enable /proc page monitoring" if EXPERT
50139 help
50140 Various /proc files exist to monitor process memory utilization:
50141diff -urNp linux-2.6.39.1/fs/proc/kcore.c linux-2.6.39.1/fs/proc/kcore.c
50142--- linux-2.6.39.1/fs/proc/kcore.c 2011-05-19 00:06:34.000000000 -0400
50143+++ linux-2.6.39.1/fs/proc/kcore.c 2011-05-22 19:41:37.000000000 -0400
50144@@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
50145 off_t offset = 0;
50146 struct kcore_list *m;
50147
50148+ pax_track_stack();
50149+
50150 /* setup ELF header */
50151 elf = (struct elfhdr *) bufp;
50152 bufp += sizeof(struct elfhdr);
50153@@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
50154 * the addresses in the elf_phdr on our list.
50155 */
50156 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50157- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50158+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50159+ if (tsz > buflen)
50160 tsz = buflen;
50161-
50162+
50163 while (buflen) {
50164 struct kcore_list *m;
50165
50166@@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
50167 kfree(elf_buf);
50168 } else {
50169 if (kern_addr_valid(start)) {
50170- unsigned long n;
50171+ char *elf_buf;
50172+ mm_segment_t oldfs;
50173
50174- n = copy_to_user(buffer, (char *)start, tsz);
50175- /*
50176- * We cannot distingush between fault on source
50177- * and fault on destination. When this happens
50178- * we clear too and hope it will trigger the
50179- * EFAULT again.
50180- */
50181- if (n) {
50182- if (clear_user(buffer + tsz - n,
50183- n))
50184+ elf_buf = kmalloc(tsz, GFP_KERNEL);
50185+ if (!elf_buf)
50186+ return -ENOMEM;
50187+ oldfs = get_fs();
50188+ set_fs(KERNEL_DS);
50189+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50190+ set_fs(oldfs);
50191+ if (copy_to_user(buffer, elf_buf, tsz)) {
50192+ kfree(elf_buf);
50193 return -EFAULT;
50194+ }
50195 }
50196+ set_fs(oldfs);
50197+ kfree(elf_buf);
50198 } else {
50199 if (clear_user(buffer, tsz))
50200 return -EFAULT;
50201@@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
50202
50203 static int open_kcore(struct inode *inode, struct file *filp)
50204 {
50205+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50206+ return -EPERM;
50207+#endif
50208 if (!capable(CAP_SYS_RAWIO))
50209 return -EPERM;
50210 if (kcore_need_update)
50211diff -urNp linux-2.6.39.1/fs/proc/meminfo.c linux-2.6.39.1/fs/proc/meminfo.c
50212--- linux-2.6.39.1/fs/proc/meminfo.c 2011-05-19 00:06:34.000000000 -0400
50213+++ linux-2.6.39.1/fs/proc/meminfo.c 2011-05-22 19:36:32.000000000 -0400
50214@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
50215 unsigned long pages[NR_LRU_LISTS];
50216 int lru;
50217
50218+ pax_track_stack();
50219+
50220 /*
50221 * display in kilobytes.
50222 */
50223@@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
50224 vmi.used >> 10,
50225 vmi.largest_chunk >> 10
50226 #ifdef CONFIG_MEMORY_FAILURE
50227- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50228+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50229 #endif
50230 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50231 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50232diff -urNp linux-2.6.39.1/fs/proc/nommu.c linux-2.6.39.1/fs/proc/nommu.c
50233--- linux-2.6.39.1/fs/proc/nommu.c 2011-05-19 00:06:34.000000000 -0400
50234+++ linux-2.6.39.1/fs/proc/nommu.c 2011-05-22 19:36:32.000000000 -0400
50235@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
50236 if (len < 1)
50237 len = 1;
50238 seq_printf(m, "%*c", len, ' ');
50239- seq_path(m, &file->f_path, "");
50240+ seq_path(m, &file->f_path, "\n\\");
50241 }
50242
50243 seq_putc(m, '\n');
50244diff -urNp linux-2.6.39.1/fs/proc/proc_net.c linux-2.6.39.1/fs/proc/proc_net.c
50245--- linux-2.6.39.1/fs/proc/proc_net.c 2011-05-19 00:06:34.000000000 -0400
50246+++ linux-2.6.39.1/fs/proc/proc_net.c 2011-05-22 19:41:37.000000000 -0400
50247@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
50248 struct task_struct *task;
50249 struct nsproxy *ns;
50250 struct net *net = NULL;
50251+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50252+ const struct cred *cred = current_cred();
50253+#endif
50254+
50255+#ifdef CONFIG_GRKERNSEC_PROC_USER
50256+ if (cred->fsuid)
50257+ return net;
50258+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50259+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
50260+ return net;
50261+#endif
50262
50263 rcu_read_lock();
50264 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50265diff -urNp linux-2.6.39.1/fs/proc/proc_sysctl.c linux-2.6.39.1/fs/proc/proc_sysctl.c
50266--- linux-2.6.39.1/fs/proc/proc_sysctl.c 2011-05-19 00:06:34.000000000 -0400
50267+++ linux-2.6.39.1/fs/proc/proc_sysctl.c 2011-05-22 19:41:37.000000000 -0400
50268@@ -8,6 +8,8 @@
50269 #include <linux/namei.h>
50270 #include "internal.h"
50271
50272+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
50273+
50274 static const struct dentry_operations proc_sys_dentry_operations;
50275 static const struct file_operations proc_sys_file_operations;
50276 static const struct inode_operations proc_sys_inode_operations;
50277@@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
50278 if (!p)
50279 goto out;
50280
50281+ if (gr_handle_sysctl(p, MAY_EXEC))
50282+ goto out;
50283+
50284 err = ERR_PTR(-ENOMEM);
50285 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
50286 if (h)
50287@@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
50288 if (*pos < file->f_pos)
50289 continue;
50290
50291+ if (gr_handle_sysctl(table, 0))
50292+ continue;
50293+
50294 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
50295 if (res)
50296 return res;
50297@@ -358,6 +366,9 @@ static int proc_sys_getattr(struct vfsmo
50298 if (IS_ERR(head))
50299 return PTR_ERR(head);
50300
50301+ if (table && gr_handle_sysctl(table, MAY_EXEC))
50302+ return -ENOENT;
50303+
50304 generic_fillattr(inode, stat);
50305 if (table)
50306 stat->mode = (stat->mode & S_IFMT) | table->mode;
50307diff -urNp linux-2.6.39.1/fs/proc/root.c linux-2.6.39.1/fs/proc/root.c
50308--- linux-2.6.39.1/fs/proc/root.c 2011-05-19 00:06:34.000000000 -0400
50309+++ linux-2.6.39.1/fs/proc/root.c 2011-05-22 19:41:37.000000000 -0400
50310@@ -122,7 +122,15 @@ void __init proc_root_init(void)
50311 #ifdef CONFIG_PROC_DEVICETREE
50312 proc_device_tree_init();
50313 #endif
50314+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50315+#ifdef CONFIG_GRKERNSEC_PROC_USER
50316+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50317+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50318+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50319+#endif
50320+#else
50321 proc_mkdir("bus", NULL);
50322+#endif
50323 proc_sys_init();
50324 }
50325
50326diff -urNp linux-2.6.39.1/fs/proc/task_mmu.c linux-2.6.39.1/fs/proc/task_mmu.c
50327--- linux-2.6.39.1/fs/proc/task_mmu.c 2011-05-19 00:06:34.000000000 -0400
50328+++ linux-2.6.39.1/fs/proc/task_mmu.c 2011-05-22 22:43:29.000000000 -0400
50329@@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
50330 "VmExe:\t%8lu kB\n"
50331 "VmLib:\t%8lu kB\n"
50332 "VmPTE:\t%8lu kB\n"
50333- "VmSwap:\t%8lu kB\n",
50334- hiwater_vm << (PAGE_SHIFT-10),
50335+ "VmSwap:\t%8lu kB\n"
50336+
50337+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50338+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50339+#endif
50340+
50341+ ,hiwater_vm << (PAGE_SHIFT-10),
50342 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50343 mm->locked_vm << (PAGE_SHIFT-10),
50344 hiwater_rss << (PAGE_SHIFT-10),
50345@@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
50346 data << (PAGE_SHIFT-10),
50347 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50348 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50349- swap << (PAGE_SHIFT-10));
50350+ swap << (PAGE_SHIFT-10)
50351+
50352+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50353+ , mm->context.user_cs_base, mm->context.user_cs_limit
50354+#endif
50355+
50356+ );
50357 }
50358
50359 unsigned long task_vsize(struct mm_struct *mm)
50360@@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
50361 return ret;
50362 }
50363
50364+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50365+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50366+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50367+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50368+#endif
50369+
50370 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
50371 {
50372 struct mm_struct *mm = vma->vm_mm;
50373@@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
50374 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50375 }
50376
50377- /* We don't show the stack guard page in /proc/maps */
50378+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50379+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50380+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50381+#else
50382 start = vma->vm_start;
50383- if (stack_guard_page_start(vma, start))
50384- start += PAGE_SIZE;
50385 end = vma->vm_end;
50386- if (stack_guard_page_end(vma, end))
50387- end -= PAGE_SIZE;
50388+#endif
50389
50390 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50391 start,
50392@@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
50393 flags & VM_WRITE ? 'w' : '-',
50394 flags & VM_EXEC ? 'x' : '-',
50395 flags & VM_MAYSHARE ? 's' : 'p',
50396+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50397+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50398+#else
50399 pgoff,
50400+#endif
50401 MAJOR(dev), MINOR(dev), ino, &len);
50402
50403 /*
50404@@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
50405 */
50406 if (file) {
50407 pad_len_spaces(m, len);
50408- seq_path(m, &file->f_path, "\n");
50409+ seq_path(m, &file->f_path, "\n\\");
50410 } else {
50411 const char *name = arch_vma_name(vma);
50412 if (!name) {
50413@@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
50414 if (vma->vm_start <= mm->brk &&
50415 vma->vm_end >= mm->start_brk) {
50416 name = "[heap]";
50417- } else if (vma->vm_start <= mm->start_stack &&
50418- vma->vm_end >= mm->start_stack) {
50419+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50420+ (vma->vm_start <= mm->start_stack &&
50421+ vma->vm_end >= mm->start_stack)) {
50422 name = "[stack]";
50423 }
50424 } else {
50425@@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
50426 };
50427
50428 memset(&mss, 0, sizeof mss);
50429- mss.vma = vma;
50430- /* mmap_sem is held in m_start */
50431- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50432- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50433-
50434+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50435+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50436+#endif
50437+ mss.vma = vma;
50438+ /* mmap_sem is held in m_start */
50439+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50440+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50441+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50442+ }
50443+#endif
50444 show_map_vma(m, vma);
50445
50446 seq_printf(m,
50447@@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
50448 "KernelPageSize: %8lu kB\n"
50449 "MMUPageSize: %8lu kB\n"
50450 "Locked: %8lu kB\n",
50451+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50452+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50453+#else
50454 (vma->vm_end - vma->vm_start) >> 10,
50455+#endif
50456 mss.resident >> 10,
50457 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50458 mss.shared_clean >> 10,
50459diff -urNp linux-2.6.39.1/fs/proc/task_nommu.c linux-2.6.39.1/fs/proc/task_nommu.c
50460--- linux-2.6.39.1/fs/proc/task_nommu.c 2011-05-19 00:06:34.000000000 -0400
50461+++ linux-2.6.39.1/fs/proc/task_nommu.c 2011-05-22 19:36:32.000000000 -0400
50462@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
50463 else
50464 bytes += kobjsize(mm);
50465
50466- if (current->fs && current->fs->users > 1)
50467+ if (current->fs && atomic_read(&current->fs->users) > 1)
50468 sbytes += kobjsize(current->fs);
50469 else
50470 bytes += kobjsize(current->fs);
50471@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
50472
50473 if (file) {
50474 pad_len_spaces(m, len);
50475- seq_path(m, &file->f_path, "");
50476+ seq_path(m, &file->f_path, "\n\\");
50477 } else if (mm) {
50478 if (vma->vm_start <= mm->start_stack &&
50479 vma->vm_end >= mm->start_stack) {
50480diff -urNp linux-2.6.39.1/fs/quota/netlink.c linux-2.6.39.1/fs/quota/netlink.c
50481--- linux-2.6.39.1/fs/quota/netlink.c 2011-05-19 00:06:34.000000000 -0400
50482+++ linux-2.6.39.1/fs/quota/netlink.c 2011-05-22 19:36:32.000000000 -0400
50483@@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
50484 void quota_send_warning(short type, unsigned int id, dev_t dev,
50485 const char warntype)
50486 {
50487- static atomic_t seq;
50488+ static atomic_unchecked_t seq;
50489 struct sk_buff *skb;
50490 void *msg_head;
50491 int ret;
50492@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
50493 "VFS: Not enough memory to send quota warning.\n");
50494 return;
50495 }
50496- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50497+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50498 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50499 if (!msg_head) {
50500 printk(KERN_ERR
50501diff -urNp linux-2.6.39.1/fs/readdir.c linux-2.6.39.1/fs/readdir.c
50502--- linux-2.6.39.1/fs/readdir.c 2011-05-19 00:06:34.000000000 -0400
50503+++ linux-2.6.39.1/fs/readdir.c 2011-05-22 19:41:42.000000000 -0400
50504@@ -17,6 +17,7 @@
50505 #include <linux/security.h>
50506 #include <linux/syscalls.h>
50507 #include <linux/unistd.h>
50508+#include <linux/namei.h>
50509
50510 #include <asm/uaccess.h>
50511
50512@@ -67,6 +68,7 @@ struct old_linux_dirent {
50513
50514 struct readdir_callback {
50515 struct old_linux_dirent __user * dirent;
50516+ struct file * file;
50517 int result;
50518 };
50519
50520@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
50521 buf->result = -EOVERFLOW;
50522 return -EOVERFLOW;
50523 }
50524+
50525+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50526+ return 0;
50527+
50528 buf->result++;
50529 dirent = buf->dirent;
50530 if (!access_ok(VERIFY_WRITE, dirent,
50531@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
50532
50533 buf.result = 0;
50534 buf.dirent = dirent;
50535+ buf.file = file;
50536
50537 error = vfs_readdir(file, fillonedir, &buf);
50538 if (buf.result)
50539@@ -142,6 +149,7 @@ struct linux_dirent {
50540 struct getdents_callback {
50541 struct linux_dirent __user * current_dir;
50542 struct linux_dirent __user * previous;
50543+ struct file * file;
50544 int count;
50545 int error;
50546 };
50547@@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
50548 buf->error = -EOVERFLOW;
50549 return -EOVERFLOW;
50550 }
50551+
50552+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50553+ return 0;
50554+
50555 dirent = buf->previous;
50556 if (dirent) {
50557 if (__put_user(offset, &dirent->d_off))
50558@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
50559 buf.previous = NULL;
50560 buf.count = count;
50561 buf.error = 0;
50562+ buf.file = file;
50563
50564 error = vfs_readdir(file, filldir, &buf);
50565 if (error >= 0)
50566@@ -229,6 +242,7 @@ out:
50567 struct getdents_callback64 {
50568 struct linux_dirent64 __user * current_dir;
50569 struct linux_dirent64 __user * previous;
50570+ struct file *file;
50571 int count;
50572 int error;
50573 };
50574@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
50575 buf->error = -EINVAL; /* only used if we fail.. */
50576 if (reclen > buf->count)
50577 return -EINVAL;
50578+
50579+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50580+ return 0;
50581+
50582 dirent = buf->previous;
50583 if (dirent) {
50584 if (__put_user(offset, &dirent->d_off))
50585@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
50586
50587 buf.current_dir = dirent;
50588 buf.previous = NULL;
50589+ buf.file = file;
50590 buf.count = count;
50591 buf.error = 0;
50592
50593diff -urNp linux-2.6.39.1/fs/reiserfs/dir.c linux-2.6.39.1/fs/reiserfs/dir.c
50594--- linux-2.6.39.1/fs/reiserfs/dir.c 2011-05-19 00:06:34.000000000 -0400
50595+++ linux-2.6.39.1/fs/reiserfs/dir.c 2011-05-22 19:36:32.000000000 -0400
50596@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
50597 struct reiserfs_dir_entry de;
50598 int ret = 0;
50599
50600+ pax_track_stack();
50601+
50602 reiserfs_write_lock(inode->i_sb);
50603
50604 reiserfs_check_lock_depth(inode->i_sb, "readdir");
50605diff -urNp linux-2.6.39.1/fs/reiserfs/do_balan.c linux-2.6.39.1/fs/reiserfs/do_balan.c
50606--- linux-2.6.39.1/fs/reiserfs/do_balan.c 2011-05-19 00:06:34.000000000 -0400
50607+++ linux-2.6.39.1/fs/reiserfs/do_balan.c 2011-05-22 19:36:32.000000000 -0400
50608@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
50609 return;
50610 }
50611
50612- atomic_inc(&(fs_generation(tb->tb_sb)));
50613+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50614 do_balance_starts(tb);
50615
50616 /* balance leaf returns 0 except if combining L R and S into
50617diff -urNp linux-2.6.39.1/fs/reiserfs/item_ops.c linux-2.6.39.1/fs/reiserfs/item_ops.c
50618--- linux-2.6.39.1/fs/reiserfs/item_ops.c 2011-05-19 00:06:34.000000000 -0400
50619+++ linux-2.6.39.1/fs/reiserfs/item_ops.c 2011-05-22 19:36:32.000000000 -0400
50620@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
50621 vi->vi_index, vi->vi_type, vi->vi_ih);
50622 }
50623
50624-static struct item_operations stat_data_ops = {
50625+static const struct item_operations stat_data_ops = {
50626 .bytes_number = sd_bytes_number,
50627 .decrement_key = sd_decrement_key,
50628 .is_left_mergeable = sd_is_left_mergeable,
50629@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
50630 vi->vi_index, vi->vi_type, vi->vi_ih);
50631 }
50632
50633-static struct item_operations direct_ops = {
50634+static const struct item_operations direct_ops = {
50635 .bytes_number = direct_bytes_number,
50636 .decrement_key = direct_decrement_key,
50637 .is_left_mergeable = direct_is_left_mergeable,
50638@@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
50639 vi->vi_index, vi->vi_type, vi->vi_ih);
50640 }
50641
50642-static struct item_operations indirect_ops = {
50643+static const struct item_operations indirect_ops = {
50644 .bytes_number = indirect_bytes_number,
50645 .decrement_key = indirect_decrement_key,
50646 .is_left_mergeable = indirect_is_left_mergeable,
50647@@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
50648 printk("\n");
50649 }
50650
50651-static struct item_operations direntry_ops = {
50652+static const struct item_operations direntry_ops = {
50653 .bytes_number = direntry_bytes_number,
50654 .decrement_key = direntry_decrement_key,
50655 .is_left_mergeable = direntry_is_left_mergeable,
50656@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
50657 "Invalid item type observed, run fsck ASAP");
50658 }
50659
50660-static struct item_operations errcatch_ops = {
50661+static const struct item_operations errcatch_ops = {
50662 errcatch_bytes_number,
50663 errcatch_decrement_key,
50664 errcatch_is_left_mergeable,
50665@@ -746,7 +746,7 @@ static struct item_operations errcatch_o
50666 #error Item types must use disk-format assigned values.
50667 #endif
50668
50669-struct item_operations *item_ops[TYPE_ANY + 1] = {
50670+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
50671 &stat_data_ops,
50672 &indirect_ops,
50673 &direct_ops,
50674diff -urNp linux-2.6.39.1/fs/reiserfs/journal.c linux-2.6.39.1/fs/reiserfs/journal.c
50675--- linux-2.6.39.1/fs/reiserfs/journal.c 2011-05-19 00:06:34.000000000 -0400
50676+++ linux-2.6.39.1/fs/reiserfs/journal.c 2011-05-22 19:36:32.000000000 -0400
50677@@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
50678 struct buffer_head *bh;
50679 int i, j;
50680
50681+ pax_track_stack();
50682+
50683 bh = __getblk(dev, block, bufsize);
50684 if (buffer_uptodate(bh))
50685 return (bh);
50686diff -urNp linux-2.6.39.1/fs/reiserfs/namei.c linux-2.6.39.1/fs/reiserfs/namei.c
50687--- linux-2.6.39.1/fs/reiserfs/namei.c 2011-05-19 00:06:34.000000000 -0400
50688+++ linux-2.6.39.1/fs/reiserfs/namei.c 2011-05-22 19:36:32.000000000 -0400
50689@@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
50690 unsigned long savelink = 1;
50691 struct timespec ctime;
50692
50693+ pax_track_stack();
50694+
50695 /* three balancings: (1) old name removal, (2) new name insertion
50696 and (3) maybe "save" link insertion
50697 stat data updates: (1) old directory,
50698diff -urNp linux-2.6.39.1/fs/reiserfs/procfs.c linux-2.6.39.1/fs/reiserfs/procfs.c
50699--- linux-2.6.39.1/fs/reiserfs/procfs.c 2011-05-19 00:06:34.000000000 -0400
50700+++ linux-2.6.39.1/fs/reiserfs/procfs.c 2011-05-22 19:36:32.000000000 -0400
50701@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
50702 "SMALL_TAILS " : "NO_TAILS ",
50703 replay_only(sb) ? "REPLAY_ONLY " : "",
50704 convert_reiserfs(sb) ? "CONV " : "",
50705- atomic_read(&r->s_generation_counter),
50706+ atomic_read_unchecked(&r->s_generation_counter),
50707 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50708 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50709 SF(s_good_search_by_key_reada), SF(s_bmaps),
50710@@ -299,6 +299,8 @@ static int show_journal(struct seq_file
50711 struct journal_params *jp = &rs->s_v1.s_journal;
50712 char b[BDEVNAME_SIZE];
50713
50714+ pax_track_stack();
50715+
50716 seq_printf(m, /* on-disk fields */
50717 "jp_journal_1st_block: \t%i\n"
50718 "jp_journal_dev: \t%s[%x]\n"
50719diff -urNp linux-2.6.39.1/fs/reiserfs/stree.c linux-2.6.39.1/fs/reiserfs/stree.c
50720--- linux-2.6.39.1/fs/reiserfs/stree.c 2011-05-19 00:06:34.000000000 -0400
50721+++ linux-2.6.39.1/fs/reiserfs/stree.c 2011-05-22 19:36:32.000000000 -0400
50722@@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
50723 int iter = 0;
50724 #endif
50725
50726+ pax_track_stack();
50727+
50728 BUG_ON(!th->t_trans_id);
50729
50730 init_tb_struct(th, &s_del_balance, sb, path,
50731@@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
50732 int retval;
50733 int quota_cut_bytes = 0;
50734
50735+ pax_track_stack();
50736+
50737 BUG_ON(!th->t_trans_id);
50738
50739 le_key2cpu_key(&cpu_key, key);
50740@@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
50741 int quota_cut_bytes;
50742 loff_t tail_pos = 0;
50743
50744+ pax_track_stack();
50745+
50746 BUG_ON(!th->t_trans_id);
50747
50748 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
50749@@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
50750 int retval;
50751 int fs_gen;
50752
50753+ pax_track_stack();
50754+
50755 BUG_ON(!th->t_trans_id);
50756
50757 fs_gen = get_generation(inode->i_sb);
50758@@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
50759 int fs_gen = 0;
50760 int quota_bytes = 0;
50761
50762+ pax_track_stack();
50763+
50764 BUG_ON(!th->t_trans_id);
50765
50766 if (inode) { /* Do we count quotas for item? */
50767diff -urNp linux-2.6.39.1/fs/reiserfs/super.c linux-2.6.39.1/fs/reiserfs/super.c
50768--- linux-2.6.39.1/fs/reiserfs/super.c 2011-05-19 00:06:34.000000000 -0400
50769+++ linux-2.6.39.1/fs/reiserfs/super.c 2011-05-22 19:36:32.000000000 -0400
50770@@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
50771 {.option_name = NULL}
50772 };
50773
50774+ pax_track_stack();
50775+
50776 *blocks = 0;
50777 if (!options || !*options)
50778 /* use default configuration: create tails, journaling on, no
50779diff -urNp linux-2.6.39.1/fs/select.c linux-2.6.39.1/fs/select.c
50780--- linux-2.6.39.1/fs/select.c 2011-05-19 00:06:34.000000000 -0400
50781+++ linux-2.6.39.1/fs/select.c 2011-05-22 19:41:42.000000000 -0400
50782@@ -20,6 +20,7 @@
50783 #include <linux/module.h>
50784 #include <linux/slab.h>
50785 #include <linux/poll.h>
50786+#include <linux/security.h>
50787 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50788 #include <linux/file.h>
50789 #include <linux/fdtable.h>
50790@@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
50791 int retval, i, timed_out = 0;
50792 unsigned long slack = 0;
50793
50794+ pax_track_stack();
50795+
50796 rcu_read_lock();
50797 retval = max_select_fd(n, fds);
50798 rcu_read_unlock();
50799@@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
50800 /* Allocate small arguments on the stack to save memory and be faster */
50801 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
50802
50803+ pax_track_stack();
50804+
50805 ret = -EINVAL;
50806 if (n < 0)
50807 goto out_nofds;
50808@@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
50809 struct poll_list *walk = head;
50810 unsigned long todo = nfds;
50811
50812+ pax_track_stack();
50813+
50814+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50815 if (nfds > rlimit(RLIMIT_NOFILE))
50816 return -EINVAL;
50817
50818diff -urNp linux-2.6.39.1/fs/seq_file.c linux-2.6.39.1/fs/seq_file.c
50819--- linux-2.6.39.1/fs/seq_file.c 2011-05-19 00:06:34.000000000 -0400
50820+++ linux-2.6.39.1/fs/seq_file.c 2011-05-22 19:36:32.000000000 -0400
50821@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
50822 return 0;
50823 }
50824 if (!m->buf) {
50825- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50826+ m->size = PAGE_SIZE;
50827+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50828 if (!m->buf)
50829 return -ENOMEM;
50830 }
50831@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
50832 Eoverflow:
50833 m->op->stop(m, p);
50834 kfree(m->buf);
50835- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50836+ m->size <<= 1;
50837+ m->buf = kmalloc(m->size, GFP_KERNEL);
50838 return !m->buf ? -ENOMEM : -EAGAIN;
50839 }
50840
50841@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
50842 m->version = file->f_version;
50843 /* grab buffer if we didn't have one */
50844 if (!m->buf) {
50845- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50846+ m->size = PAGE_SIZE;
50847+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50848 if (!m->buf)
50849 goto Enomem;
50850 }
50851@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
50852 goto Fill;
50853 m->op->stop(m, p);
50854 kfree(m->buf);
50855- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50856+ m->size <<= 1;
50857+ m->buf = kmalloc(m->size, GFP_KERNEL);
50858 if (!m->buf)
50859 goto Enomem;
50860 m->count = 0;
50861diff -urNp linux-2.6.39.1/fs/splice.c linux-2.6.39.1/fs/splice.c
50862--- linux-2.6.39.1/fs/splice.c 2011-05-19 00:06:34.000000000 -0400
50863+++ linux-2.6.39.1/fs/splice.c 2011-05-22 19:36:32.000000000 -0400
50864@@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
50865 pipe_lock(pipe);
50866
50867 for (;;) {
50868- if (!pipe->readers) {
50869+ if (!atomic_read(&pipe->readers)) {
50870 send_sig(SIGPIPE, current, 0);
50871 if (!ret)
50872 ret = -EPIPE;
50873@@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
50874 do_wakeup = 0;
50875 }
50876
50877- pipe->waiting_writers++;
50878+ atomic_inc(&pipe->waiting_writers);
50879 pipe_wait(pipe);
50880- pipe->waiting_writers--;
50881+ atomic_dec(&pipe->waiting_writers);
50882 }
50883
50884 pipe_unlock(pipe);
50885@@ -316,6 +316,8 @@ __generic_file_splice_read(struct file *
50886 .spd_release = spd_release_page,
50887 };
50888
50889+ pax_track_stack();
50890+
50891 if (splice_grow_spd(pipe, &spd))
50892 return -ENOMEM;
50893
50894@@ -556,7 +558,7 @@ static ssize_t kernel_readv(struct file
50895 old_fs = get_fs();
50896 set_fs(get_ds());
50897 /* The cast to a user pointer is valid due to the set_fs() */
50898- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50899+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
50900 set_fs(old_fs);
50901
50902 return res;
50903@@ -571,7 +573,7 @@ static ssize_t kernel_write(struct file
50904 old_fs = get_fs();
50905 set_fs(get_ds());
50906 /* The cast to a user pointer is valid due to the set_fs() */
50907- res = vfs_write(file, (const char __user *)buf, count, &pos);
50908+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
50909 set_fs(old_fs);
50910
50911 return res;
50912@@ -599,6 +601,8 @@ ssize_t default_file_splice_read(struct
50913 .spd_release = spd_release_page,
50914 };
50915
50916+ pax_track_stack();
50917+
50918 if (splice_grow_spd(pipe, &spd))
50919 return -ENOMEM;
50920
50921@@ -622,7 +626,7 @@ ssize_t default_file_splice_read(struct
50922 goto err;
50923
50924 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50925- vec[i].iov_base = (void __user *) page_address(page);
50926+ vec[i].iov_base = (__force void __user *) page_address(page);
50927 vec[i].iov_len = this_len;
50928 spd.pages[i] = page;
50929 spd.nr_pages++;
50930@@ -842,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50931 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50932 {
50933 while (!pipe->nrbufs) {
50934- if (!pipe->writers)
50935+ if (!atomic_read(&pipe->writers))
50936 return 0;
50937
50938- if (!pipe->waiting_writers && sd->num_spliced)
50939+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50940 return 0;
50941
50942 if (sd->flags & SPLICE_F_NONBLOCK)
50943@@ -1178,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct fi
50944 * out of the pipe right after the splice_to_pipe(). So set
50945 * PIPE_READERS appropriately.
50946 */
50947- pipe->readers = 1;
50948+ atomic_set(&pipe->readers, 1);
50949
50950 current->splice_pipe = pipe;
50951 }
50952@@ -1615,6 +1619,8 @@ static long vmsplice_to_pipe(struct file
50953 };
50954 long ret;
50955
50956+ pax_track_stack();
50957+
50958 pipe = get_pipe_info(file);
50959 if (!pipe)
50960 return -EBADF;
50961@@ -1730,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_
50962 ret = -ERESTARTSYS;
50963 break;
50964 }
50965- if (!pipe->writers)
50966+ if (!atomic_read(&pipe->writers))
50967 break;
50968- if (!pipe->waiting_writers) {
50969+ if (!atomic_read(&pipe->waiting_writers)) {
50970 if (flags & SPLICE_F_NONBLOCK) {
50971 ret = -EAGAIN;
50972 break;
50973@@ -1764,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_
50974 pipe_lock(pipe);
50975
50976 while (pipe->nrbufs >= pipe->buffers) {
50977- if (!pipe->readers) {
50978+ if (!atomic_read(&pipe->readers)) {
50979 send_sig(SIGPIPE, current, 0);
50980 ret = -EPIPE;
50981 break;
50982@@ -1777,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_
50983 ret = -ERESTARTSYS;
50984 break;
50985 }
50986- pipe->waiting_writers++;
50987+ atomic_inc(&pipe->waiting_writers);
50988 pipe_wait(pipe);
50989- pipe->waiting_writers--;
50990+ atomic_dec(&pipe->waiting_writers);
50991 }
50992
50993 pipe_unlock(pipe);
50994@@ -1815,14 +1821,14 @@ retry:
50995 pipe_double_lock(ipipe, opipe);
50996
50997 do {
50998- if (!opipe->readers) {
50999+ if (!atomic_read(&opipe->readers)) {
51000 send_sig(SIGPIPE, current, 0);
51001 if (!ret)
51002 ret = -EPIPE;
51003 break;
51004 }
51005
51006- if (!ipipe->nrbufs && !ipipe->writers)
51007+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
51008 break;
51009
51010 /*
51011@@ -1922,7 +1928,7 @@ static int link_pipe(struct pipe_inode_i
51012 pipe_double_lock(ipipe, opipe);
51013
51014 do {
51015- if (!opipe->readers) {
51016+ if (!atomic_read(&opipe->readers)) {
51017 send_sig(SIGPIPE, current, 0);
51018 if (!ret)
51019 ret = -EPIPE;
51020@@ -1967,7 +1973,7 @@ static int link_pipe(struct pipe_inode_i
51021 * return EAGAIN if we have the potential of some data in the
51022 * future, otherwise just return 0
51023 */
51024- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51025+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51026 ret = -EAGAIN;
51027
51028 pipe_unlock(ipipe);
51029diff -urNp linux-2.6.39.1/fs/sysfs/file.c linux-2.6.39.1/fs/sysfs/file.c
51030--- linux-2.6.39.1/fs/sysfs/file.c 2011-05-19 00:06:34.000000000 -0400
51031+++ linux-2.6.39.1/fs/sysfs/file.c 2011-05-22 19:36:32.000000000 -0400
51032@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
51033
51034 struct sysfs_open_dirent {
51035 atomic_t refcnt;
51036- atomic_t event;
51037+ atomic_unchecked_t event;
51038 wait_queue_head_t poll;
51039 struct list_head buffers; /* goes through sysfs_buffer.list */
51040 };
51041@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
51042 if (!sysfs_get_active(attr_sd))
51043 return -ENODEV;
51044
51045- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
51046+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
51047 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
51048
51049 sysfs_put_active(attr_sd);
51050@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
51051 return -ENOMEM;
51052
51053 atomic_set(&new_od->refcnt, 0);
51054- atomic_set(&new_od->event, 1);
51055+ atomic_set_unchecked(&new_od->event, 1);
51056 init_waitqueue_head(&new_od->poll);
51057 INIT_LIST_HEAD(&new_od->buffers);
51058 goto retry;
51059@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
51060
51061 sysfs_put_active(attr_sd);
51062
51063- if (buffer->event != atomic_read(&od->event))
51064+ if (buffer->event != atomic_read_unchecked(&od->event))
51065 goto trigger;
51066
51067 return DEFAULT_POLLMASK;
51068@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
51069
51070 od = sd->s_attr.open;
51071 if (od) {
51072- atomic_inc(&od->event);
51073+ atomic_inc_unchecked(&od->event);
51074 wake_up_interruptible(&od->poll);
51075 }
51076
51077diff -urNp linux-2.6.39.1/fs/sysfs/mount.c linux-2.6.39.1/fs/sysfs/mount.c
51078--- linux-2.6.39.1/fs/sysfs/mount.c 2011-05-19 00:06:34.000000000 -0400
51079+++ linux-2.6.39.1/fs/sysfs/mount.c 2011-05-22 19:41:42.000000000 -0400
51080@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
51081 .s_name = "",
51082 .s_count = ATOMIC_INIT(1),
51083 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
51084+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51085+ .s_mode = S_IFDIR | S_IRWXU,
51086+#else
51087 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
51088+#endif
51089 .s_ino = 1,
51090 };
51091
51092diff -urNp linux-2.6.39.1/fs/sysfs/symlink.c linux-2.6.39.1/fs/sysfs/symlink.c
51093--- linux-2.6.39.1/fs/sysfs/symlink.c 2011-05-19 00:06:34.000000000 -0400
51094+++ linux-2.6.39.1/fs/sysfs/symlink.c 2011-05-22 19:36:32.000000000 -0400
51095@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
51096
51097 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
51098 {
51099- char *page = nd_get_link(nd);
51100+ const char *page = nd_get_link(nd);
51101 if (!IS_ERR(page))
51102 free_page((unsigned long)page);
51103 }
51104diff -urNp linux-2.6.39.1/fs/udf/inode.c linux-2.6.39.1/fs/udf/inode.c
51105--- linux-2.6.39.1/fs/udf/inode.c 2011-05-19 00:06:34.000000000 -0400
51106+++ linux-2.6.39.1/fs/udf/inode.c 2011-05-22 19:36:32.000000000 -0400
51107@@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
51108 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
51109 int lastblock = 0;
51110
51111+ pax_track_stack();
51112+
51113 prev_epos.offset = udf_file_entry_alloc_offset(inode);
51114 prev_epos.block = iinfo->i_location;
51115 prev_epos.bh = NULL;
51116diff -urNp linux-2.6.39.1/fs/udf/misc.c linux-2.6.39.1/fs/udf/misc.c
51117--- linux-2.6.39.1/fs/udf/misc.c 2011-05-19 00:06:34.000000000 -0400
51118+++ linux-2.6.39.1/fs/udf/misc.c 2011-05-22 19:36:32.000000000 -0400
51119@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
51120
51121 u8 udf_tag_checksum(const struct tag *t)
51122 {
51123- u8 *data = (u8 *)t;
51124+ const u8 *data = (const u8 *)t;
51125 u8 checksum = 0;
51126 int i;
51127 for (i = 0; i < sizeof(struct tag); ++i)
51128diff -urNp linux-2.6.39.1/fs/utimes.c linux-2.6.39.1/fs/utimes.c
51129--- linux-2.6.39.1/fs/utimes.c 2011-05-19 00:06:34.000000000 -0400
51130+++ linux-2.6.39.1/fs/utimes.c 2011-05-22 19:41:42.000000000 -0400
51131@@ -1,6 +1,7 @@
51132 #include <linux/compiler.h>
51133 #include <linux/file.h>
51134 #include <linux/fs.h>
51135+#include <linux/security.h>
51136 #include <linux/linkage.h>
51137 #include <linux/mount.h>
51138 #include <linux/namei.h>
51139@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
51140 goto mnt_drop_write_and_out;
51141 }
51142 }
51143+
51144+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51145+ error = -EACCES;
51146+ goto mnt_drop_write_and_out;
51147+ }
51148+
51149 mutex_lock(&inode->i_mutex);
51150 error = notify_change(path->dentry, &newattrs);
51151 mutex_unlock(&inode->i_mutex);
51152diff -urNp linux-2.6.39.1/fs/xattr_acl.c linux-2.6.39.1/fs/xattr_acl.c
51153--- linux-2.6.39.1/fs/xattr_acl.c 2011-05-19 00:06:34.000000000 -0400
51154+++ linux-2.6.39.1/fs/xattr_acl.c 2011-05-22 19:36:32.000000000 -0400
51155@@ -17,8 +17,8 @@
51156 struct posix_acl *
51157 posix_acl_from_xattr(const void *value, size_t size)
51158 {
51159- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51160- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51161+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51162+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51163 int count;
51164 struct posix_acl *acl;
51165 struct posix_acl_entry *acl_e;
51166diff -urNp linux-2.6.39.1/fs/xattr.c linux-2.6.39.1/fs/xattr.c
51167--- linux-2.6.39.1/fs/xattr.c 2011-05-19 00:06:34.000000000 -0400
51168+++ linux-2.6.39.1/fs/xattr.c 2011-05-22 19:41:42.000000000 -0400
51169@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51170 * Extended attribute SET operations
51171 */
51172 static long
51173-setxattr(struct dentry *d, const char __user *name, const void __user *value,
51174+setxattr(struct path *path, const char __user *name, const void __user *value,
51175 size_t size, int flags)
51176 {
51177 int error;
51178@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
51179 return PTR_ERR(kvalue);
51180 }
51181
51182- error = vfs_setxattr(d, kname, kvalue, size, flags);
51183+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51184+ error = -EACCES;
51185+ goto out;
51186+ }
51187+
51188+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51189+out:
51190 kfree(kvalue);
51191 return error;
51192 }
51193@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
51194 return error;
51195 error = mnt_want_write(path.mnt);
51196 if (!error) {
51197- error = setxattr(path.dentry, name, value, size, flags);
51198+ error = setxattr(&path, name, value, size, flags);
51199 mnt_drop_write(path.mnt);
51200 }
51201 path_put(&path);
51202@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
51203 return error;
51204 error = mnt_want_write(path.mnt);
51205 if (!error) {
51206- error = setxattr(path.dentry, name, value, size, flags);
51207+ error = setxattr(&path, name, value, size, flags);
51208 mnt_drop_write(path.mnt);
51209 }
51210 path_put(&path);
51211@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
51212 const void __user *,value, size_t, size, int, flags)
51213 {
51214 struct file *f;
51215- struct dentry *dentry;
51216 int error = -EBADF;
51217
51218 f = fget(fd);
51219 if (!f)
51220 return error;
51221- dentry = f->f_path.dentry;
51222- audit_inode(NULL, dentry);
51223+ audit_inode(NULL, f->f_path.dentry);
51224 error = mnt_want_write_file(f);
51225 if (!error) {
51226- error = setxattr(dentry, name, value, size, flags);
51227+ error = setxattr(&f->f_path, name, value, size, flags);
51228 mnt_drop_write(f->f_path.mnt);
51229 }
51230 fput(f);
51231diff -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
51232--- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-19 00:06:34.000000000 -0400
51233+++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-22 19:41:42.000000000 -0400
51234@@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
51235 xfs_fsop_geom_t fsgeo;
51236 int error;
51237
51238+ memset(&fsgeo, 0, sizeof(fsgeo));
51239 error = xfs_fs_geometry(mp, &fsgeo, 3);
51240 if (error)
51241 return -error;
51242diff -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
51243--- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-19 00:06:34.000000000 -0400
51244+++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-22 19:36:32.000000000 -0400
51245@@ -128,7 +128,7 @@ xfs_find_handle(
51246 }
51247
51248 error = -EFAULT;
51249- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51250+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51251 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51252 goto out_put;
51253
51254diff -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
51255--- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c 2011-05-19 00:06:34.000000000 -0400
51256+++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c 2011-05-22 19:36:32.000000000 -0400
51257@@ -437,7 +437,7 @@ xfs_vn_put_link(
51258 struct nameidata *nd,
51259 void *p)
51260 {
51261- char *s = nd_get_link(nd);
51262+ const char *s = nd_get_link(nd);
51263
51264 if (!IS_ERR(s))
51265 kfree(s);
51266diff -urNp linux-2.6.39.1/fs/xfs/xfs_bmap.c linux-2.6.39.1/fs/xfs/xfs_bmap.c
51267--- linux-2.6.39.1/fs/xfs/xfs_bmap.c 2011-05-19 00:06:34.000000000 -0400
51268+++ linux-2.6.39.1/fs/xfs/xfs_bmap.c 2011-05-22 19:36:32.000000000 -0400
51269@@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
51270 int nmap,
51271 int ret_nmap);
51272 #else
51273-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51274+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51275 #endif /* DEBUG */
51276
51277 STATIC int
51278diff -urNp linux-2.6.39.1/fs/xfs/xfs_dir2.c linux-2.6.39.1/fs/xfs/xfs_dir2.c
51279--- linux-2.6.39.1/fs/xfs/xfs_dir2.c 2011-05-19 00:06:34.000000000 -0400
51280+++ linux-2.6.39.1/fs/xfs/xfs_dir2.c 2011-05-22 19:36:32.000000000 -0400
51281@@ -85,7 +85,7 @@ xfs_ascii_ci_compname(
51282 return result;
51283 }
51284
51285-static struct xfs_nameops xfs_ascii_ci_nameops = {
51286+static const struct xfs_nameops xfs_ascii_ci_nameops = {
51287 .hashname = xfs_ascii_ci_hashname,
51288 .compname = xfs_ascii_ci_compname,
51289 };
51290diff -urNp linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c
51291--- linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c 2011-05-19 00:06:34.000000000 -0400
51292+++ linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c 2011-05-22 19:36:32.000000000 -0400
51293@@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
51294 }
51295
51296 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
51297- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51298+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51299+ char name[sfep->namelen];
51300+ memcpy(name, sfep->name, sfep->namelen);
51301+ if (filldir(dirent, name, sfep->namelen,
51302+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
51303+ *offset = off & 0x7fffffff;
51304+ return 0;
51305+ }
51306+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51307 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51308 *offset = off & 0x7fffffff;
51309 return 0;
51310diff -urNp linux-2.6.39.1/grsecurity/gracl_alloc.c linux-2.6.39.1/grsecurity/gracl_alloc.c
51311--- linux-2.6.39.1/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
51312+++ linux-2.6.39.1/grsecurity/gracl_alloc.c 2011-05-22 19:41:42.000000000 -0400
51313@@ -0,0 +1,105 @@
51314+#include <linux/kernel.h>
51315+#include <linux/mm.h>
51316+#include <linux/slab.h>
51317+#include <linux/vmalloc.h>
51318+#include <linux/gracl.h>
51319+#include <linux/grsecurity.h>
51320+
51321+static unsigned long alloc_stack_next = 1;
51322+static unsigned long alloc_stack_size = 1;
51323+static void **alloc_stack;
51324+
51325+static __inline__ int
51326+alloc_pop(void)
51327+{
51328+ if (alloc_stack_next == 1)
51329+ return 0;
51330+
51331+ kfree(alloc_stack[alloc_stack_next - 2]);
51332+
51333+ alloc_stack_next--;
51334+
51335+ return 1;
51336+}
51337+
51338+static __inline__ int
51339+alloc_push(void *buf)
51340+{
51341+ if (alloc_stack_next >= alloc_stack_size)
51342+ return 1;
51343+
51344+ alloc_stack[alloc_stack_next - 1] = buf;
51345+
51346+ alloc_stack_next++;
51347+
51348+ return 0;
51349+}
51350+
51351+void *
51352+acl_alloc(unsigned long len)
51353+{
51354+ void *ret = NULL;
51355+
51356+ if (!len || len > PAGE_SIZE)
51357+ goto out;
51358+
51359+ ret = kmalloc(len, GFP_KERNEL);
51360+
51361+ if (ret) {
51362+ if (alloc_push(ret)) {
51363+ kfree(ret);
51364+ ret = NULL;
51365+ }
51366+ }
51367+
51368+out:
51369+ return ret;
51370+}
51371+
51372+void *
51373+acl_alloc_num(unsigned long num, unsigned long len)
51374+{
51375+ if (!len || (num > (PAGE_SIZE / len)))
51376+ return NULL;
51377+
51378+ return acl_alloc(num * len);
51379+}
51380+
51381+void
51382+acl_free_all(void)
51383+{
51384+ if (gr_acl_is_enabled() || !alloc_stack)
51385+ return;
51386+
51387+ while (alloc_pop()) ;
51388+
51389+ if (alloc_stack) {
51390+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
51391+ kfree(alloc_stack);
51392+ else
51393+ vfree(alloc_stack);
51394+ }
51395+
51396+ alloc_stack = NULL;
51397+ alloc_stack_size = 1;
51398+ alloc_stack_next = 1;
51399+
51400+ return;
51401+}
51402+
51403+int
51404+acl_alloc_stack_init(unsigned long size)
51405+{
51406+ if ((size * sizeof (void *)) <= PAGE_SIZE)
51407+ alloc_stack =
51408+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
51409+ else
51410+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
51411+
51412+ alloc_stack_size = size;
51413+
51414+ if (!alloc_stack)
51415+ return 0;
51416+ else
51417+ return 1;
51418+}
51419diff -urNp linux-2.6.39.1/grsecurity/gracl.c linux-2.6.39.1/grsecurity/gracl.c
51420--- linux-2.6.39.1/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
51421+++ linux-2.6.39.1/grsecurity/gracl.c 2011-06-11 16:26:18.000000000 -0400
51422@@ -0,0 +1,4109 @@
51423+#include <linux/kernel.h>
51424+#include <linux/module.h>
51425+#include <linux/sched.h>
51426+#include <linux/mm.h>
51427+#include <linux/file.h>
51428+#include <linux/fs.h>
51429+#include <linux/namei.h>
51430+#include <linux/mount.h>
51431+#include <linux/tty.h>
51432+#include <linux/proc_fs.h>
51433+#include <linux/lglock.h>
51434+#include <linux/slab.h>
51435+#include <linux/vmalloc.h>
51436+#include <linux/types.h>
51437+#include <linux/sysctl.h>
51438+#include <linux/netdevice.h>
51439+#include <linux/ptrace.h>
51440+#include <linux/gracl.h>
51441+#include <linux/gralloc.h>
51442+#include <linux/grsecurity.h>
51443+#include <linux/grinternal.h>
51444+#include <linux/pid_namespace.h>
51445+#include <linux/fdtable.h>
51446+#include <linux/percpu.h>
51447+
51448+#include <asm/uaccess.h>
51449+#include <asm/errno.h>
51450+#include <asm/mman.h>
51451+
51452+static struct acl_role_db acl_role_set;
51453+static struct name_db name_set;
51454+static struct inodev_db inodev_set;
51455+
51456+/* for keeping track of userspace pointers used for subjects, so we
51457+ can share references in the kernel as well
51458+*/
51459+
51460+static struct path real_root;
51461+
51462+static struct acl_subj_map_db subj_map_set;
51463+
51464+static struct acl_role_label *default_role;
51465+
51466+static struct acl_role_label *role_list;
51467+
51468+static u16 acl_sp_role_value;
51469+
51470+extern char *gr_shared_page[4];
51471+static DEFINE_MUTEX(gr_dev_mutex);
51472+DEFINE_RWLOCK(gr_inode_lock);
51473+
51474+struct gr_arg *gr_usermode;
51475+
51476+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51477+
51478+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51479+extern void gr_clear_learn_entries(void);
51480+
51481+#ifdef CONFIG_GRKERNSEC_RESLOG
51482+extern void gr_log_resource(const struct task_struct *task,
51483+ const int res, const unsigned long wanted, const int gt);
51484+#endif
51485+
51486+unsigned char *gr_system_salt;
51487+unsigned char *gr_system_sum;
51488+
51489+static struct sprole_pw **acl_special_roles = NULL;
51490+static __u16 num_sprole_pws = 0;
51491+
51492+static struct acl_role_label *kernel_role = NULL;
51493+
51494+static unsigned int gr_auth_attempts = 0;
51495+static unsigned long gr_auth_expires = 0UL;
51496+
51497+#ifdef CONFIG_NET
51498+extern struct vfsmount *sock_mnt;
51499+#endif
51500+
51501+extern struct vfsmount *pipe_mnt;
51502+extern struct vfsmount *shm_mnt;
51503+#ifdef CONFIG_HUGETLBFS
51504+extern struct vfsmount *hugetlbfs_vfsmount;
51505+#endif
51506+
51507+static struct acl_object_label *fakefs_obj_rw;
51508+static struct acl_object_label *fakefs_obj_rwx;
51509+
51510+extern int gr_init_uidset(void);
51511+extern void gr_free_uidset(void);
51512+extern void gr_remove_uid(uid_t uid);
51513+extern int gr_find_uid(uid_t uid);
51514+
51515+DECLARE_BRLOCK(vfsmount_lock);
51516+
51517+__inline__ int
51518+gr_acl_is_enabled(void)
51519+{
51520+ return (gr_status & GR_READY);
51521+}
51522+
51523+#ifdef CONFIG_BTRFS_FS
51524+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51525+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51526+#endif
51527+
51528+static inline dev_t __get_dev(const struct dentry *dentry)
51529+{
51530+#ifdef CONFIG_BTRFS_FS
51531+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51532+ return get_btrfs_dev_from_inode(dentry->d_inode);
51533+ else
51534+#endif
51535+ return dentry->d_inode->i_sb->s_dev;
51536+}
51537+
51538+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51539+{
51540+ return __get_dev(dentry);
51541+}
51542+
51543+static char gr_task_roletype_to_char(struct task_struct *task)
51544+{
51545+ switch (task->role->roletype &
51546+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51547+ GR_ROLE_SPECIAL)) {
51548+ case GR_ROLE_DEFAULT:
51549+ return 'D';
51550+ case GR_ROLE_USER:
51551+ return 'U';
51552+ case GR_ROLE_GROUP:
51553+ return 'G';
51554+ case GR_ROLE_SPECIAL:
51555+ return 'S';
51556+ }
51557+
51558+ return 'X';
51559+}
51560+
51561+char gr_roletype_to_char(void)
51562+{
51563+ return gr_task_roletype_to_char(current);
51564+}
51565+
51566+__inline__ int
51567+gr_acl_tpe_check(void)
51568+{
51569+ if (unlikely(!(gr_status & GR_READY)))
51570+ return 0;
51571+ if (current->role->roletype & GR_ROLE_TPE)
51572+ return 1;
51573+ else
51574+ return 0;
51575+}
51576+
51577+int
51578+gr_handle_rawio(const struct inode *inode)
51579+{
51580+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51581+ if (inode && S_ISBLK(inode->i_mode) &&
51582+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51583+ !capable(CAP_SYS_RAWIO))
51584+ return 1;
51585+#endif
51586+ return 0;
51587+}
51588+
51589+static int
51590+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51591+{
51592+ if (likely(lena != lenb))
51593+ return 0;
51594+
51595+ return !memcmp(a, b, lena);
51596+}
51597+
51598+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51599+{
51600+ *buflen -= namelen;
51601+ if (*buflen < 0)
51602+ return -ENAMETOOLONG;
51603+ *buffer -= namelen;
51604+ memcpy(*buffer, str, namelen);
51605+ return 0;
51606+}
51607+
51608+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51609+{
51610+ return prepend(buffer, buflen, name->name, name->len);
51611+}
51612+
51613+static int prepend_path(const struct path *path, struct path *root,
51614+ char **buffer, int *buflen)
51615+{
51616+ struct dentry *dentry = path->dentry;
51617+ struct vfsmount *vfsmnt = path->mnt;
51618+ bool slash = false;
51619+ int error = 0;
51620+
51621+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51622+ struct dentry * parent;
51623+
51624+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51625+ /* Global root? */
51626+ if (vfsmnt->mnt_parent == vfsmnt) {
51627+ goto out;
51628+ }
51629+ dentry = vfsmnt->mnt_mountpoint;
51630+ vfsmnt = vfsmnt->mnt_parent;
51631+ continue;
51632+ }
51633+ parent = dentry->d_parent;
51634+ prefetch(parent);
51635+ spin_lock(&dentry->d_lock);
51636+ error = prepend_name(buffer, buflen, &dentry->d_name);
51637+ spin_unlock(&dentry->d_lock);
51638+ if (!error)
51639+ error = prepend(buffer, buflen, "/", 1);
51640+ if (error)
51641+ break;
51642+
51643+ slash = true;
51644+ dentry = parent;
51645+ }
51646+
51647+out:
51648+ if (!error && !slash)
51649+ error = prepend(buffer, buflen, "/", 1);
51650+
51651+ return error;
51652+}
51653+
51654+/* this must be called with vfsmount_lock and rename_lock held */
51655+
51656+static char *__our_d_path(const struct path *path, struct path *root,
51657+ char *buf, int buflen)
51658+{
51659+ char *res = buf + buflen;
51660+ int error;
51661+
51662+ prepend(&res, &buflen, "\0", 1);
51663+ error = prepend_path(path, root, &res, &buflen);
51664+ if (error)
51665+ return ERR_PTR(error);
51666+
51667+ return res;
51668+}
51669+
51670+static char *
51671+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51672+{
51673+ char *retval;
51674+
51675+ retval = __our_d_path(path, root, buf, buflen);
51676+ if (unlikely(IS_ERR(retval)))
51677+ retval = strcpy(buf, "<path too long>");
51678+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51679+ retval[1] = '\0';
51680+
51681+ return retval;
51682+}
51683+
51684+static char *
51685+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51686+ char *buf, int buflen)
51687+{
51688+ struct path path;
51689+ char *res;
51690+
51691+ path.dentry = (struct dentry *)dentry;
51692+ path.mnt = (struct vfsmount *)vfsmnt;
51693+
51694+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51695+ by the RBAC system */
51696+ res = gen_full_path(&path, &real_root, buf, buflen);
51697+
51698+ return res;
51699+}
51700+
51701+static char *
51702+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51703+ char *buf, int buflen)
51704+{
51705+ char *res;
51706+ struct path path;
51707+ struct path root;
51708+ struct task_struct *reaper = &init_task;
51709+
51710+ path.dentry = (struct dentry *)dentry;
51711+ path.mnt = (struct vfsmount *)vfsmnt;
51712+
51713+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51714+ get_fs_root(reaper->fs, &root);
51715+
51716+ write_seqlock(&rename_lock);
51717+ br_read_lock(vfsmount_lock);
51718+ res = gen_full_path(&path, &root, buf, buflen);
51719+ br_read_unlock(vfsmount_lock);
51720+ write_sequnlock(&rename_lock);
51721+
51722+ path_put(&root);
51723+ return res;
51724+}
51725+
51726+static char *
51727+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51728+{
51729+ char *ret;
51730+ write_seqlock(&rename_lock);
51731+ br_read_lock(vfsmount_lock);
51732+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51733+ PAGE_SIZE);
51734+ br_read_unlock(vfsmount_lock);
51735+ write_sequnlock(&rename_lock);
51736+ return ret;
51737+}
51738+
51739+char *
51740+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51741+{
51742+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51743+ PAGE_SIZE);
51744+}
51745+
51746+char *
51747+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51748+{
51749+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51750+ PAGE_SIZE);
51751+}
51752+
51753+char *
51754+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51755+{
51756+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51757+ PAGE_SIZE);
51758+}
51759+
51760+char *
51761+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51762+{
51763+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51764+ PAGE_SIZE);
51765+}
51766+
51767+char *
51768+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51769+{
51770+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51771+ PAGE_SIZE);
51772+}
51773+
51774+__inline__ __u32
51775+to_gr_audit(const __u32 reqmode)
51776+{
51777+ /* masks off auditable permission flags, then shifts them to create
51778+ auditing flags, and adds the special case of append auditing if
51779+ we're requesting write */
51780+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51781+}
51782+
51783+struct acl_subject_label *
51784+lookup_subject_map(const struct acl_subject_label *userp)
51785+{
51786+ unsigned int index = shash(userp, subj_map_set.s_size);
51787+ struct subject_map *match;
51788+
51789+ match = subj_map_set.s_hash[index];
51790+
51791+ while (match && match->user != userp)
51792+ match = match->next;
51793+
51794+ if (match != NULL)
51795+ return match->kernel;
51796+ else
51797+ return NULL;
51798+}
51799+
51800+static void
51801+insert_subj_map_entry(struct subject_map *subjmap)
51802+{
51803+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51804+ struct subject_map **curr;
51805+
51806+ subjmap->prev = NULL;
51807+
51808+ curr = &subj_map_set.s_hash[index];
51809+ if (*curr != NULL)
51810+ (*curr)->prev = subjmap;
51811+
51812+ subjmap->next = *curr;
51813+ *curr = subjmap;
51814+
51815+ return;
51816+}
51817+
51818+static struct acl_role_label *
51819+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51820+ const gid_t gid)
51821+{
51822+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51823+ struct acl_role_label *match;
51824+ struct role_allowed_ip *ipp;
51825+ unsigned int x;
51826+ u32 curr_ip = task->signal->curr_ip;
51827+
51828+ task->signal->saved_ip = curr_ip;
51829+
51830+ match = acl_role_set.r_hash[index];
51831+
51832+ while (match) {
51833+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51834+ for (x = 0; x < match->domain_child_num; x++) {
51835+ if (match->domain_children[x] == uid)
51836+ goto found;
51837+ }
51838+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51839+ break;
51840+ match = match->next;
51841+ }
51842+found:
51843+ if (match == NULL) {
51844+ try_group:
51845+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51846+ match = acl_role_set.r_hash[index];
51847+
51848+ while (match) {
51849+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51850+ for (x = 0; x < match->domain_child_num; x++) {
51851+ if (match->domain_children[x] == gid)
51852+ goto found2;
51853+ }
51854+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51855+ break;
51856+ match = match->next;
51857+ }
51858+found2:
51859+ if (match == NULL)
51860+ match = default_role;
51861+ if (match->allowed_ips == NULL)
51862+ return match;
51863+ else {
51864+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51865+ if (likely
51866+ ((ntohl(curr_ip) & ipp->netmask) ==
51867+ (ntohl(ipp->addr) & ipp->netmask)))
51868+ return match;
51869+ }
51870+ match = default_role;
51871+ }
51872+ } else if (match->allowed_ips == NULL) {
51873+ return match;
51874+ } else {
51875+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51876+ if (likely
51877+ ((ntohl(curr_ip) & ipp->netmask) ==
51878+ (ntohl(ipp->addr) & ipp->netmask)))
51879+ return match;
51880+ }
51881+ goto try_group;
51882+ }
51883+
51884+ return match;
51885+}
51886+
51887+struct acl_subject_label *
51888+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51889+ const struct acl_role_label *role)
51890+{
51891+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51892+ struct acl_subject_label *match;
51893+
51894+ match = role->subj_hash[index];
51895+
51896+ while (match && (match->inode != ino || match->device != dev ||
51897+ (match->mode & GR_DELETED))) {
51898+ match = match->next;
51899+ }
51900+
51901+ if (match && !(match->mode & GR_DELETED))
51902+ return match;
51903+ else
51904+ return NULL;
51905+}
51906+
51907+struct acl_subject_label *
51908+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51909+ const struct acl_role_label *role)
51910+{
51911+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51912+ struct acl_subject_label *match;
51913+
51914+ match = role->subj_hash[index];
51915+
51916+ while (match && (match->inode != ino || match->device != dev ||
51917+ !(match->mode & GR_DELETED))) {
51918+ match = match->next;
51919+ }
51920+
51921+ if (match && (match->mode & GR_DELETED))
51922+ return match;
51923+ else
51924+ return NULL;
51925+}
51926+
51927+static struct acl_object_label *
51928+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51929+ const struct acl_subject_label *subj)
51930+{
51931+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51932+ struct acl_object_label *match;
51933+
51934+ match = subj->obj_hash[index];
51935+
51936+ while (match && (match->inode != ino || match->device != dev ||
51937+ (match->mode & GR_DELETED))) {
51938+ match = match->next;
51939+ }
51940+
51941+ if (match && !(match->mode & GR_DELETED))
51942+ return match;
51943+ else
51944+ return NULL;
51945+}
51946+
51947+static struct acl_object_label *
51948+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51949+ const struct acl_subject_label *subj)
51950+{
51951+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51952+ struct acl_object_label *match;
51953+
51954+ match = subj->obj_hash[index];
51955+
51956+ while (match && (match->inode != ino || match->device != dev ||
51957+ !(match->mode & GR_DELETED))) {
51958+ match = match->next;
51959+ }
51960+
51961+ if (match && (match->mode & GR_DELETED))
51962+ return match;
51963+
51964+ match = subj->obj_hash[index];
51965+
51966+ while (match && (match->inode != ino || match->device != dev ||
51967+ (match->mode & GR_DELETED))) {
51968+ match = match->next;
51969+ }
51970+
51971+ if (match && !(match->mode & GR_DELETED))
51972+ return match;
51973+ else
51974+ return NULL;
51975+}
51976+
51977+static struct name_entry *
51978+lookup_name_entry(const char *name)
51979+{
51980+ unsigned int len = strlen(name);
51981+ unsigned int key = full_name_hash(name, len);
51982+ unsigned int index = key % name_set.n_size;
51983+ struct name_entry *match;
51984+
51985+ match = name_set.n_hash[index];
51986+
51987+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51988+ match = match->next;
51989+
51990+ return match;
51991+}
51992+
51993+static struct name_entry *
51994+lookup_name_entry_create(const char *name)
51995+{
51996+ unsigned int len = strlen(name);
51997+ unsigned int key = full_name_hash(name, len);
51998+ unsigned int index = key % name_set.n_size;
51999+ struct name_entry *match;
52000+
52001+ match = name_set.n_hash[index];
52002+
52003+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52004+ !match->deleted))
52005+ match = match->next;
52006+
52007+ if (match && match->deleted)
52008+ return match;
52009+
52010+ match = name_set.n_hash[index];
52011+
52012+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52013+ match->deleted))
52014+ match = match->next;
52015+
52016+ if (match && !match->deleted)
52017+ return match;
52018+ else
52019+ return NULL;
52020+}
52021+
52022+static struct inodev_entry *
52023+lookup_inodev_entry(const ino_t ino, const dev_t dev)
52024+{
52025+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
52026+ struct inodev_entry *match;
52027+
52028+ match = inodev_set.i_hash[index];
52029+
52030+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52031+ match = match->next;
52032+
52033+ return match;
52034+}
52035+
52036+static void
52037+insert_inodev_entry(struct inodev_entry *entry)
52038+{
52039+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52040+ inodev_set.i_size);
52041+ struct inodev_entry **curr;
52042+
52043+ entry->prev = NULL;
52044+
52045+ curr = &inodev_set.i_hash[index];
52046+ if (*curr != NULL)
52047+ (*curr)->prev = entry;
52048+
52049+ entry->next = *curr;
52050+ *curr = entry;
52051+
52052+ return;
52053+}
52054+
52055+static void
52056+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52057+{
52058+ unsigned int index =
52059+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52060+ struct acl_role_label **curr;
52061+ struct acl_role_label *tmp;
52062+
52063+ curr = &acl_role_set.r_hash[index];
52064+
52065+ /* if role was already inserted due to domains and already has
52066+ a role in the same bucket as it attached, then we need to
52067+ combine these two buckets
52068+ */
52069+ if (role->next) {
52070+ tmp = role->next;
52071+ while (tmp->next)
52072+ tmp = tmp->next;
52073+ tmp->next = *curr;
52074+ } else
52075+ role->next = *curr;
52076+ *curr = role;
52077+
52078+ return;
52079+}
52080+
52081+static void
52082+insert_acl_role_label(struct acl_role_label *role)
52083+{
52084+ int i;
52085+
52086+ if (role_list == NULL) {
52087+ role_list = role;
52088+ role->prev = NULL;
52089+ } else {
52090+ role->prev = role_list;
52091+ role_list = role;
52092+ }
52093+
52094+ /* used for hash chains */
52095+ role->next = NULL;
52096+
52097+ if (role->roletype & GR_ROLE_DOMAIN) {
52098+ for (i = 0; i < role->domain_child_num; i++)
52099+ __insert_acl_role_label(role, role->domain_children[i]);
52100+ } else
52101+ __insert_acl_role_label(role, role->uidgid);
52102+}
52103+
52104+static int
52105+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52106+{
52107+ struct name_entry **curr, *nentry;
52108+ struct inodev_entry *ientry;
52109+ unsigned int len = strlen(name);
52110+ unsigned int key = full_name_hash(name, len);
52111+ unsigned int index = key % name_set.n_size;
52112+
52113+ curr = &name_set.n_hash[index];
52114+
52115+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52116+ curr = &((*curr)->next);
52117+
52118+ if (*curr != NULL)
52119+ return 1;
52120+
52121+ nentry = acl_alloc(sizeof (struct name_entry));
52122+ if (nentry == NULL)
52123+ return 0;
52124+ ientry = acl_alloc(sizeof (struct inodev_entry));
52125+ if (ientry == NULL)
52126+ return 0;
52127+ ientry->nentry = nentry;
52128+
52129+ nentry->key = key;
52130+ nentry->name = name;
52131+ nentry->inode = inode;
52132+ nentry->device = device;
52133+ nentry->len = len;
52134+ nentry->deleted = deleted;
52135+
52136+ nentry->prev = NULL;
52137+ curr = &name_set.n_hash[index];
52138+ if (*curr != NULL)
52139+ (*curr)->prev = nentry;
52140+ nentry->next = *curr;
52141+ *curr = nentry;
52142+
52143+ /* insert us into the table searchable by inode/dev */
52144+ insert_inodev_entry(ientry);
52145+
52146+ return 1;
52147+}
52148+
52149+static void
52150+insert_acl_obj_label(struct acl_object_label *obj,
52151+ struct acl_subject_label *subj)
52152+{
52153+ unsigned int index =
52154+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52155+ struct acl_object_label **curr;
52156+
52157+
52158+ obj->prev = NULL;
52159+
52160+ curr = &subj->obj_hash[index];
52161+ if (*curr != NULL)
52162+ (*curr)->prev = obj;
52163+
52164+ obj->next = *curr;
52165+ *curr = obj;
52166+
52167+ return;
52168+}
52169+
52170+static void
52171+insert_acl_subj_label(struct acl_subject_label *obj,
52172+ struct acl_role_label *role)
52173+{
52174+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52175+ struct acl_subject_label **curr;
52176+
52177+ obj->prev = NULL;
52178+
52179+ curr = &role->subj_hash[index];
52180+ if (*curr != NULL)
52181+ (*curr)->prev = obj;
52182+
52183+ obj->next = *curr;
52184+ *curr = obj;
52185+
52186+ return;
52187+}
52188+
52189+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52190+
52191+static void *
52192+create_table(__u32 * len, int elementsize)
52193+{
52194+ unsigned int table_sizes[] = {
52195+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52196+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52197+ 4194301, 8388593, 16777213, 33554393, 67108859
52198+ };
52199+ void *newtable = NULL;
52200+ unsigned int pwr = 0;
52201+
52202+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52203+ table_sizes[pwr] <= *len)
52204+ pwr++;
52205+
52206+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52207+ return newtable;
52208+
52209+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52210+ newtable =
52211+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52212+ else
52213+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52214+
52215+ *len = table_sizes[pwr];
52216+
52217+ return newtable;
52218+}
52219+
52220+static int
52221+init_variables(const struct gr_arg *arg)
52222+{
52223+ struct task_struct *reaper = &init_task;
52224+ unsigned int stacksize;
52225+
52226+ subj_map_set.s_size = arg->role_db.num_subjects;
52227+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52228+ name_set.n_size = arg->role_db.num_objects;
52229+ inodev_set.i_size = arg->role_db.num_objects;
52230+
52231+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52232+ !name_set.n_size || !inodev_set.i_size)
52233+ return 1;
52234+
52235+ if (!gr_init_uidset())
52236+ return 1;
52237+
52238+ /* set up the stack that holds allocation info */
52239+
52240+ stacksize = arg->role_db.num_pointers + 5;
52241+
52242+ if (!acl_alloc_stack_init(stacksize))
52243+ return 1;
52244+
52245+ /* grab reference for the real root dentry and vfsmount */
52246+ get_fs_root(reaper->fs, &real_root);
52247+
52248+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52249+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52250+#endif
52251+
52252+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52253+ if (fakefs_obj_rw == NULL)
52254+ return 1;
52255+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52256+
52257+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52258+ if (fakefs_obj_rwx == NULL)
52259+ return 1;
52260+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52261+
52262+ subj_map_set.s_hash =
52263+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52264+ acl_role_set.r_hash =
52265+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52266+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52267+ inodev_set.i_hash =
52268+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52269+
52270+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52271+ !name_set.n_hash || !inodev_set.i_hash)
52272+ return 1;
52273+
52274+ memset(subj_map_set.s_hash, 0,
52275+ sizeof(struct subject_map *) * subj_map_set.s_size);
52276+ memset(acl_role_set.r_hash, 0,
52277+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52278+ memset(name_set.n_hash, 0,
52279+ sizeof (struct name_entry *) * name_set.n_size);
52280+ memset(inodev_set.i_hash, 0,
52281+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52282+
52283+ return 0;
52284+}
52285+
52286+/* free information not needed after startup
52287+ currently contains user->kernel pointer mappings for subjects
52288+*/
52289+
52290+static void
52291+free_init_variables(void)
52292+{
52293+ __u32 i;
52294+
52295+ if (subj_map_set.s_hash) {
52296+ for (i = 0; i < subj_map_set.s_size; i++) {
52297+ if (subj_map_set.s_hash[i]) {
52298+ kfree(subj_map_set.s_hash[i]);
52299+ subj_map_set.s_hash[i] = NULL;
52300+ }
52301+ }
52302+
52303+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52304+ PAGE_SIZE)
52305+ kfree(subj_map_set.s_hash);
52306+ else
52307+ vfree(subj_map_set.s_hash);
52308+ }
52309+
52310+ return;
52311+}
52312+
52313+static void
52314+free_variables(void)
52315+{
52316+ struct acl_subject_label *s;
52317+ struct acl_role_label *r;
52318+ struct task_struct *task, *task2;
52319+ unsigned int x;
52320+
52321+ gr_clear_learn_entries();
52322+
52323+ read_lock(&tasklist_lock);
52324+ do_each_thread(task2, task) {
52325+ task->acl_sp_role = 0;
52326+ task->acl_role_id = 0;
52327+ task->acl = NULL;
52328+ task->role = NULL;
52329+ } while_each_thread(task2, task);
52330+ read_unlock(&tasklist_lock);
52331+
52332+ /* release the reference to the real root dentry and vfsmount */
52333+ path_put(&real_root);
52334+
52335+ /* free all object hash tables */
52336+
52337+ FOR_EACH_ROLE_START(r)
52338+ if (r->subj_hash == NULL)
52339+ goto next_role;
52340+ FOR_EACH_SUBJECT_START(r, s, x)
52341+ if (s->obj_hash == NULL)
52342+ break;
52343+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52344+ kfree(s->obj_hash);
52345+ else
52346+ vfree(s->obj_hash);
52347+ FOR_EACH_SUBJECT_END(s, x)
52348+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52349+ if (s->obj_hash == NULL)
52350+ break;
52351+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52352+ kfree(s->obj_hash);
52353+ else
52354+ vfree(s->obj_hash);
52355+ FOR_EACH_NESTED_SUBJECT_END(s)
52356+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52357+ kfree(r->subj_hash);
52358+ else
52359+ vfree(r->subj_hash);
52360+ r->subj_hash = NULL;
52361+next_role:
52362+ FOR_EACH_ROLE_END(r)
52363+
52364+ acl_free_all();
52365+
52366+ if (acl_role_set.r_hash) {
52367+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52368+ PAGE_SIZE)
52369+ kfree(acl_role_set.r_hash);
52370+ else
52371+ vfree(acl_role_set.r_hash);
52372+ }
52373+ if (name_set.n_hash) {
52374+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52375+ PAGE_SIZE)
52376+ kfree(name_set.n_hash);
52377+ else
52378+ vfree(name_set.n_hash);
52379+ }
52380+
52381+ if (inodev_set.i_hash) {
52382+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52383+ PAGE_SIZE)
52384+ kfree(inodev_set.i_hash);
52385+ else
52386+ vfree(inodev_set.i_hash);
52387+ }
52388+
52389+ gr_free_uidset();
52390+
52391+ memset(&name_set, 0, sizeof (struct name_db));
52392+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52393+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52394+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52395+
52396+ default_role = NULL;
52397+ role_list = NULL;
52398+
52399+ return;
52400+}
52401+
52402+static __u32
52403+count_user_objs(struct acl_object_label *userp)
52404+{
52405+ struct acl_object_label o_tmp;
52406+ __u32 num = 0;
52407+
52408+ while (userp) {
52409+ if (copy_from_user(&o_tmp, userp,
52410+ sizeof (struct acl_object_label)))
52411+ break;
52412+
52413+ userp = o_tmp.prev;
52414+ num++;
52415+ }
52416+
52417+ return num;
52418+}
52419+
52420+static struct acl_subject_label *
52421+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52422+
52423+static int
52424+copy_user_glob(struct acl_object_label *obj)
52425+{
52426+ struct acl_object_label *g_tmp, **guser;
52427+ unsigned int len;
52428+ char *tmp;
52429+
52430+ if (obj->globbed == NULL)
52431+ return 0;
52432+
52433+ guser = &obj->globbed;
52434+ while (*guser) {
52435+ g_tmp = (struct acl_object_label *)
52436+ acl_alloc(sizeof (struct acl_object_label));
52437+ if (g_tmp == NULL)
52438+ return -ENOMEM;
52439+
52440+ if (copy_from_user(g_tmp, *guser,
52441+ sizeof (struct acl_object_label)))
52442+ return -EFAULT;
52443+
52444+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52445+
52446+ if (!len || len >= PATH_MAX)
52447+ return -EINVAL;
52448+
52449+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52450+ return -ENOMEM;
52451+
52452+ if (copy_from_user(tmp, g_tmp->filename, len))
52453+ return -EFAULT;
52454+ tmp[len-1] = '\0';
52455+ g_tmp->filename = tmp;
52456+
52457+ *guser = g_tmp;
52458+ guser = &(g_tmp->next);
52459+ }
52460+
52461+ return 0;
52462+}
52463+
52464+static int
52465+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52466+ struct acl_role_label *role)
52467+{
52468+ struct acl_object_label *o_tmp;
52469+ unsigned int len;
52470+ int ret;
52471+ char *tmp;
52472+
52473+ while (userp) {
52474+ if ((o_tmp = (struct acl_object_label *)
52475+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52476+ return -ENOMEM;
52477+
52478+ if (copy_from_user(o_tmp, userp,
52479+ sizeof (struct acl_object_label)))
52480+ return -EFAULT;
52481+
52482+ userp = o_tmp->prev;
52483+
52484+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52485+
52486+ if (!len || len >= PATH_MAX)
52487+ return -EINVAL;
52488+
52489+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52490+ return -ENOMEM;
52491+
52492+ if (copy_from_user(tmp, o_tmp->filename, len))
52493+ return -EFAULT;
52494+ tmp[len-1] = '\0';
52495+ o_tmp->filename = tmp;
52496+
52497+ insert_acl_obj_label(o_tmp, subj);
52498+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52499+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52500+ return -ENOMEM;
52501+
52502+ ret = copy_user_glob(o_tmp);
52503+ if (ret)
52504+ return ret;
52505+
52506+ if (o_tmp->nested) {
52507+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52508+ if (IS_ERR(o_tmp->nested))
52509+ return PTR_ERR(o_tmp->nested);
52510+
52511+ /* insert into nested subject list */
52512+ o_tmp->nested->next = role->hash->first;
52513+ role->hash->first = o_tmp->nested;
52514+ }
52515+ }
52516+
52517+ return 0;
52518+}
52519+
52520+static __u32
52521+count_user_subjs(struct acl_subject_label *userp)
52522+{
52523+ struct acl_subject_label s_tmp;
52524+ __u32 num = 0;
52525+
52526+ while (userp) {
52527+ if (copy_from_user(&s_tmp, userp,
52528+ sizeof (struct acl_subject_label)))
52529+ break;
52530+
52531+ userp = s_tmp.prev;
52532+ /* do not count nested subjects against this count, since
52533+ they are not included in the hash table, but are
52534+ attached to objects. We have already counted
52535+ the subjects in userspace for the allocation
52536+ stack
52537+ */
52538+ if (!(s_tmp.mode & GR_NESTED))
52539+ num++;
52540+ }
52541+
52542+ return num;
52543+}
52544+
52545+static int
52546+copy_user_allowedips(struct acl_role_label *rolep)
52547+{
52548+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52549+
52550+ ruserip = rolep->allowed_ips;
52551+
52552+ while (ruserip) {
52553+ rlast = rtmp;
52554+
52555+ if ((rtmp = (struct role_allowed_ip *)
52556+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52557+ return -ENOMEM;
52558+
52559+ if (copy_from_user(rtmp, ruserip,
52560+ sizeof (struct role_allowed_ip)))
52561+ return -EFAULT;
52562+
52563+ ruserip = rtmp->prev;
52564+
52565+ if (!rlast) {
52566+ rtmp->prev = NULL;
52567+ rolep->allowed_ips = rtmp;
52568+ } else {
52569+ rlast->next = rtmp;
52570+ rtmp->prev = rlast;
52571+ }
52572+
52573+ if (!ruserip)
52574+ rtmp->next = NULL;
52575+ }
52576+
52577+ return 0;
52578+}
52579+
52580+static int
52581+copy_user_transitions(struct acl_role_label *rolep)
52582+{
52583+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52584+
52585+ unsigned int len;
52586+ char *tmp;
52587+
52588+ rusertp = rolep->transitions;
52589+
52590+ while (rusertp) {
52591+ rlast = rtmp;
52592+
52593+ if ((rtmp = (struct role_transition *)
52594+ acl_alloc(sizeof (struct role_transition))) == NULL)
52595+ return -ENOMEM;
52596+
52597+ if (copy_from_user(rtmp, rusertp,
52598+ sizeof (struct role_transition)))
52599+ return -EFAULT;
52600+
52601+ rusertp = rtmp->prev;
52602+
52603+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52604+
52605+ if (!len || len >= GR_SPROLE_LEN)
52606+ return -EINVAL;
52607+
52608+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52609+ return -ENOMEM;
52610+
52611+ if (copy_from_user(tmp, rtmp->rolename, len))
52612+ return -EFAULT;
52613+ tmp[len-1] = '\0';
52614+ rtmp->rolename = tmp;
52615+
52616+ if (!rlast) {
52617+ rtmp->prev = NULL;
52618+ rolep->transitions = rtmp;
52619+ } else {
52620+ rlast->next = rtmp;
52621+ rtmp->prev = rlast;
52622+ }
52623+
52624+ if (!rusertp)
52625+ rtmp->next = NULL;
52626+ }
52627+
52628+ return 0;
52629+}
52630+
52631+static struct acl_subject_label *
52632+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52633+{
52634+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52635+ unsigned int len;
52636+ char *tmp;
52637+ __u32 num_objs;
52638+ struct acl_ip_label **i_tmp, *i_utmp2;
52639+ struct gr_hash_struct ghash;
52640+ struct subject_map *subjmap;
52641+ unsigned int i_num;
52642+ int err;
52643+
52644+ s_tmp = lookup_subject_map(userp);
52645+
52646+ /* we've already copied this subject into the kernel, just return
52647+ the reference to it, and don't copy it over again
52648+ */
52649+ if (s_tmp)
52650+ return(s_tmp);
52651+
52652+ if ((s_tmp = (struct acl_subject_label *)
52653+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52654+ return ERR_PTR(-ENOMEM);
52655+
52656+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52657+ if (subjmap == NULL)
52658+ return ERR_PTR(-ENOMEM);
52659+
52660+ subjmap->user = userp;
52661+ subjmap->kernel = s_tmp;
52662+ insert_subj_map_entry(subjmap);
52663+
52664+ if (copy_from_user(s_tmp, userp,
52665+ sizeof (struct acl_subject_label)))
52666+ return ERR_PTR(-EFAULT);
52667+
52668+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52669+
52670+ if (!len || len >= PATH_MAX)
52671+ return ERR_PTR(-EINVAL);
52672+
52673+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52674+ return ERR_PTR(-ENOMEM);
52675+
52676+ if (copy_from_user(tmp, s_tmp->filename, len))
52677+ return ERR_PTR(-EFAULT);
52678+ tmp[len-1] = '\0';
52679+ s_tmp->filename = tmp;
52680+
52681+ if (!strcmp(s_tmp->filename, "/"))
52682+ role->root_label = s_tmp;
52683+
52684+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52685+ return ERR_PTR(-EFAULT);
52686+
52687+ /* copy user and group transition tables */
52688+
52689+ if (s_tmp->user_trans_num) {
52690+ uid_t *uidlist;
52691+
52692+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52693+ if (uidlist == NULL)
52694+ return ERR_PTR(-ENOMEM);
52695+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52696+ return ERR_PTR(-EFAULT);
52697+
52698+ s_tmp->user_transitions = uidlist;
52699+ }
52700+
52701+ if (s_tmp->group_trans_num) {
52702+ gid_t *gidlist;
52703+
52704+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52705+ if (gidlist == NULL)
52706+ return ERR_PTR(-ENOMEM);
52707+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52708+ return ERR_PTR(-EFAULT);
52709+
52710+ s_tmp->group_transitions = gidlist;
52711+ }
52712+
52713+ /* set up object hash table */
52714+ num_objs = count_user_objs(ghash.first);
52715+
52716+ s_tmp->obj_hash_size = num_objs;
52717+ s_tmp->obj_hash =
52718+ (struct acl_object_label **)
52719+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52720+
52721+ if (!s_tmp->obj_hash)
52722+ return ERR_PTR(-ENOMEM);
52723+
52724+ memset(s_tmp->obj_hash, 0,
52725+ s_tmp->obj_hash_size *
52726+ sizeof (struct acl_object_label *));
52727+
52728+ /* add in objects */
52729+ err = copy_user_objs(ghash.first, s_tmp, role);
52730+
52731+ if (err)
52732+ return ERR_PTR(err);
52733+
52734+ /* set pointer for parent subject */
52735+ if (s_tmp->parent_subject) {
52736+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52737+
52738+ if (IS_ERR(s_tmp2))
52739+ return s_tmp2;
52740+
52741+ s_tmp->parent_subject = s_tmp2;
52742+ }
52743+
52744+ /* add in ip acls */
52745+
52746+ if (!s_tmp->ip_num) {
52747+ s_tmp->ips = NULL;
52748+ goto insert;
52749+ }
52750+
52751+ i_tmp =
52752+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52753+ sizeof (struct acl_ip_label *));
52754+
52755+ if (!i_tmp)
52756+ return ERR_PTR(-ENOMEM);
52757+
52758+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52759+ *(i_tmp + i_num) =
52760+ (struct acl_ip_label *)
52761+ acl_alloc(sizeof (struct acl_ip_label));
52762+ if (!*(i_tmp + i_num))
52763+ return ERR_PTR(-ENOMEM);
52764+
52765+ if (copy_from_user
52766+ (&i_utmp2, s_tmp->ips + i_num,
52767+ sizeof (struct acl_ip_label *)))
52768+ return ERR_PTR(-EFAULT);
52769+
52770+ if (copy_from_user
52771+ (*(i_tmp + i_num), i_utmp2,
52772+ sizeof (struct acl_ip_label)))
52773+ return ERR_PTR(-EFAULT);
52774+
52775+ if ((*(i_tmp + i_num))->iface == NULL)
52776+ continue;
52777+
52778+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52779+ if (!len || len >= IFNAMSIZ)
52780+ return ERR_PTR(-EINVAL);
52781+ tmp = acl_alloc(len);
52782+ if (tmp == NULL)
52783+ return ERR_PTR(-ENOMEM);
52784+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52785+ return ERR_PTR(-EFAULT);
52786+ (*(i_tmp + i_num))->iface = tmp;
52787+ }
52788+
52789+ s_tmp->ips = i_tmp;
52790+
52791+insert:
52792+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52793+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52794+ return ERR_PTR(-ENOMEM);
52795+
52796+ return s_tmp;
52797+}
52798+
52799+static int
52800+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52801+{
52802+ struct acl_subject_label s_pre;
52803+ struct acl_subject_label * ret;
52804+ int err;
52805+
52806+ while (userp) {
52807+ if (copy_from_user(&s_pre, userp,
52808+ sizeof (struct acl_subject_label)))
52809+ return -EFAULT;
52810+
52811+ /* do not add nested subjects here, add
52812+ while parsing objects
52813+ */
52814+
52815+ if (s_pre.mode & GR_NESTED) {
52816+ userp = s_pre.prev;
52817+ continue;
52818+ }
52819+
52820+ ret = do_copy_user_subj(userp, role);
52821+
52822+ err = PTR_ERR(ret);
52823+ if (IS_ERR(ret))
52824+ return err;
52825+
52826+ insert_acl_subj_label(ret, role);
52827+
52828+ userp = s_pre.prev;
52829+ }
52830+
52831+ return 0;
52832+}
52833+
52834+static int
52835+copy_user_acl(struct gr_arg *arg)
52836+{
52837+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52838+ struct sprole_pw *sptmp;
52839+ struct gr_hash_struct *ghash;
52840+ uid_t *domainlist;
52841+ unsigned int r_num;
52842+ unsigned int len;
52843+ char *tmp;
52844+ int err = 0;
52845+ __u16 i;
52846+ __u32 num_subjs;
52847+
52848+ /* we need a default and kernel role */
52849+ if (arg->role_db.num_roles < 2)
52850+ return -EINVAL;
52851+
52852+ /* copy special role authentication info from userspace */
52853+
52854+ num_sprole_pws = arg->num_sprole_pws;
52855+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52856+
52857+ if (!acl_special_roles) {
52858+ err = -ENOMEM;
52859+ goto cleanup;
52860+ }
52861+
52862+ for (i = 0; i < num_sprole_pws; i++) {
52863+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52864+ if (!sptmp) {
52865+ err = -ENOMEM;
52866+ goto cleanup;
52867+ }
52868+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52869+ sizeof (struct sprole_pw))) {
52870+ err = -EFAULT;
52871+ goto cleanup;
52872+ }
52873+
52874+ len =
52875+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52876+
52877+ if (!len || len >= GR_SPROLE_LEN) {
52878+ err = -EINVAL;
52879+ goto cleanup;
52880+ }
52881+
52882+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
52883+ err = -ENOMEM;
52884+ goto cleanup;
52885+ }
52886+
52887+ if (copy_from_user(tmp, sptmp->rolename, len)) {
52888+ err = -EFAULT;
52889+ goto cleanup;
52890+ }
52891+ tmp[len-1] = '\0';
52892+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52893+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52894+#endif
52895+ sptmp->rolename = tmp;
52896+ acl_special_roles[i] = sptmp;
52897+ }
52898+
52899+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52900+
52901+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52902+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52903+
52904+ if (!r_tmp) {
52905+ err = -ENOMEM;
52906+ goto cleanup;
52907+ }
52908+
52909+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52910+ sizeof (struct acl_role_label *))) {
52911+ err = -EFAULT;
52912+ goto cleanup;
52913+ }
52914+
52915+ if (copy_from_user(r_tmp, r_utmp2,
52916+ sizeof (struct acl_role_label))) {
52917+ err = -EFAULT;
52918+ goto cleanup;
52919+ }
52920+
52921+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52922+
52923+ if (!len || len >= PATH_MAX) {
52924+ err = -EINVAL;
52925+ goto cleanup;
52926+ }
52927+
52928+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
52929+ err = -ENOMEM;
52930+ goto cleanup;
52931+ }
52932+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
52933+ err = -EFAULT;
52934+ goto cleanup;
52935+ }
52936+ tmp[len-1] = '\0';
52937+ r_tmp->rolename = tmp;
52938+
52939+ if (!strcmp(r_tmp->rolename, "default")
52940+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52941+ default_role = r_tmp;
52942+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52943+ kernel_role = r_tmp;
52944+ }
52945+
52946+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52947+ err = -ENOMEM;
52948+ goto cleanup;
52949+ }
52950+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52951+ err = -EFAULT;
52952+ goto cleanup;
52953+ }
52954+
52955+ r_tmp->hash = ghash;
52956+
52957+ num_subjs = count_user_subjs(r_tmp->hash->first);
52958+
52959+ r_tmp->subj_hash_size = num_subjs;
52960+ r_tmp->subj_hash =
52961+ (struct acl_subject_label **)
52962+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52963+
52964+ if (!r_tmp->subj_hash) {
52965+ err = -ENOMEM;
52966+ goto cleanup;
52967+ }
52968+
52969+ err = copy_user_allowedips(r_tmp);
52970+ if (err)
52971+ goto cleanup;
52972+
52973+ /* copy domain info */
52974+ if (r_tmp->domain_children != NULL) {
52975+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52976+ if (domainlist == NULL) {
52977+ err = -ENOMEM;
52978+ goto cleanup;
52979+ }
52980+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52981+ err = -EFAULT;
52982+ goto cleanup;
52983+ }
52984+ r_tmp->domain_children = domainlist;
52985+ }
52986+
52987+ err = copy_user_transitions(r_tmp);
52988+ if (err)
52989+ goto cleanup;
52990+
52991+ memset(r_tmp->subj_hash, 0,
52992+ r_tmp->subj_hash_size *
52993+ sizeof (struct acl_subject_label *));
52994+
52995+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52996+
52997+ if (err)
52998+ goto cleanup;
52999+
53000+ /* set nested subject list to null */
53001+ r_tmp->hash->first = NULL;
53002+
53003+ insert_acl_role_label(r_tmp);
53004+ }
53005+
53006+ goto return_err;
53007+ cleanup:
53008+ free_variables();
53009+ return_err:
53010+ return err;
53011+
53012+}
53013+
53014+static int
53015+gracl_init(struct gr_arg *args)
53016+{
53017+ int error = 0;
53018+
53019+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53020+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53021+
53022+ if (init_variables(args)) {
53023+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53024+ error = -ENOMEM;
53025+ free_variables();
53026+ goto out;
53027+ }
53028+
53029+ error = copy_user_acl(args);
53030+ free_init_variables();
53031+ if (error) {
53032+ free_variables();
53033+ goto out;
53034+ }
53035+
53036+ if ((error = gr_set_acls(0))) {
53037+ free_variables();
53038+ goto out;
53039+ }
53040+
53041+ pax_open_kernel();
53042+ gr_status |= GR_READY;
53043+ pax_close_kernel();
53044+
53045+ out:
53046+ return error;
53047+}
53048+
53049+/* derived from glibc fnmatch() 0: match, 1: no match*/
53050+
53051+static int
53052+glob_match(const char *p, const char *n)
53053+{
53054+ char c;
53055+
53056+ while ((c = *p++) != '\0') {
53057+ switch (c) {
53058+ case '?':
53059+ if (*n == '\0')
53060+ return 1;
53061+ else if (*n == '/')
53062+ return 1;
53063+ break;
53064+ case '\\':
53065+ if (*n != c)
53066+ return 1;
53067+ break;
53068+ case '*':
53069+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
53070+ if (*n == '/')
53071+ return 1;
53072+ else if (c == '?') {
53073+ if (*n == '\0')
53074+ return 1;
53075+ else
53076+ ++n;
53077+ }
53078+ }
53079+ if (c == '\0') {
53080+ return 0;
53081+ } else {
53082+ const char *endp;
53083+
53084+ if ((endp = strchr(n, '/')) == NULL)
53085+ endp = n + strlen(n);
53086+
53087+ if (c == '[') {
53088+ for (--p; n < endp; ++n)
53089+ if (!glob_match(p, n))
53090+ return 0;
53091+ } else if (c == '/') {
53092+ while (*n != '\0' && *n != '/')
53093+ ++n;
53094+ if (*n == '/' && !glob_match(p, n + 1))
53095+ return 0;
53096+ } else {
53097+ for (--p; n < endp; ++n)
53098+ if (*n == c && !glob_match(p, n))
53099+ return 0;
53100+ }
53101+
53102+ return 1;
53103+ }
53104+ case '[':
53105+ {
53106+ int not;
53107+ char cold;
53108+
53109+ if (*n == '\0' || *n == '/')
53110+ return 1;
53111+
53112+ not = (*p == '!' || *p == '^');
53113+ if (not)
53114+ ++p;
53115+
53116+ c = *p++;
53117+ for (;;) {
53118+ unsigned char fn = (unsigned char)*n;
53119+
53120+ if (c == '\0')
53121+ return 1;
53122+ else {
53123+ if (c == fn)
53124+ goto matched;
53125+ cold = c;
53126+ c = *p++;
53127+
53128+ if (c == '-' && *p != ']') {
53129+ unsigned char cend = *p++;
53130+
53131+ if (cend == '\0')
53132+ return 1;
53133+
53134+ if (cold <= fn && fn <= cend)
53135+ goto matched;
53136+
53137+ c = *p++;
53138+ }
53139+ }
53140+
53141+ if (c == ']')
53142+ break;
53143+ }
53144+ if (!not)
53145+ return 1;
53146+ break;
53147+ matched:
53148+ while (c != ']') {
53149+ if (c == '\0')
53150+ return 1;
53151+
53152+ c = *p++;
53153+ }
53154+ if (not)
53155+ return 1;
53156+ }
53157+ break;
53158+ default:
53159+ if (c != *n)
53160+ return 1;
53161+ }
53162+
53163+ ++n;
53164+ }
53165+
53166+ if (*n == '\0')
53167+ return 0;
53168+
53169+ if (*n == '/')
53170+ return 0;
53171+
53172+ return 1;
53173+}
53174+
53175+static struct acl_object_label *
53176+chk_glob_label(struct acl_object_label *globbed,
53177+ struct dentry *dentry, struct vfsmount *mnt, char **path)
53178+{
53179+ struct acl_object_label *tmp;
53180+
53181+ if (*path == NULL)
53182+ *path = gr_to_filename_nolock(dentry, mnt);
53183+
53184+ tmp = globbed;
53185+
53186+ while (tmp) {
53187+ if (!glob_match(tmp->filename, *path))
53188+ return tmp;
53189+ tmp = tmp->next;
53190+ }
53191+
53192+ return NULL;
53193+}
53194+
53195+static struct acl_object_label *
53196+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53197+ const ino_t curr_ino, const dev_t curr_dev,
53198+ const struct acl_subject_label *subj, char **path, const int checkglob)
53199+{
53200+ struct acl_subject_label *tmpsubj;
53201+ struct acl_object_label *retval;
53202+ struct acl_object_label *retval2;
53203+
53204+ tmpsubj = (struct acl_subject_label *) subj;
53205+ read_lock(&gr_inode_lock);
53206+ do {
53207+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53208+ if (retval) {
53209+ if (checkglob && retval->globbed) {
53210+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53211+ (struct vfsmount *)orig_mnt, path);
53212+ if (retval2)
53213+ retval = retval2;
53214+ }
53215+ break;
53216+ }
53217+ } while ((tmpsubj = tmpsubj->parent_subject));
53218+ read_unlock(&gr_inode_lock);
53219+
53220+ return retval;
53221+}
53222+
53223+static __inline__ struct acl_object_label *
53224+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53225+ struct dentry *curr_dentry,
53226+ const struct acl_subject_label *subj, char **path, const int checkglob)
53227+{
53228+ int newglob = checkglob;
53229+ ino_t inode;
53230+ dev_t device;
53231+
53232+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53233+ as we don't want a / * rule to match instead of the / object
53234+ don't do this for create lookups that call this function though, since they're looking up
53235+ on the parent and thus need globbing checks on all paths
53236+ */
53237+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53238+ newglob = GR_NO_GLOB;
53239+
53240+ spin_lock(&curr_dentry->d_lock);
53241+ inode = curr_dentry->d_inode->i_ino;
53242+ device = __get_dev(curr_dentry);
53243+ spin_unlock(&curr_dentry->d_lock);
53244+
53245+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53246+}
53247+
53248+static struct acl_object_label *
53249+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53250+ const struct acl_subject_label *subj, char *path, const int checkglob)
53251+{
53252+ struct dentry *dentry = (struct dentry *) l_dentry;
53253+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53254+ struct acl_object_label *retval;
53255+ struct dentry *parent;
53256+
53257+ write_seqlock(&rename_lock);
53258+ br_read_lock(vfsmount_lock);
53259+
53260+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53261+#ifdef CONFIG_NET
53262+ mnt == sock_mnt ||
53263+#endif
53264+#ifdef CONFIG_HUGETLBFS
53265+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53266+#endif
53267+ /* ignore Eric Biederman */
53268+ IS_PRIVATE(l_dentry->d_inode))) {
53269+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53270+ goto out;
53271+ }
53272+
53273+ for (;;) {
53274+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53275+ break;
53276+
53277+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53278+ if (mnt->mnt_parent == mnt)
53279+ break;
53280+
53281+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53282+ if (retval != NULL)
53283+ goto out;
53284+
53285+ dentry = mnt->mnt_mountpoint;
53286+ mnt = mnt->mnt_parent;
53287+ continue;
53288+ }
53289+
53290+ parent = dentry->d_parent;
53291+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53292+ if (retval != NULL)
53293+ goto out;
53294+
53295+ dentry = parent;
53296+ }
53297+
53298+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53299+
53300+ /* real_root is pinned so we don't have to hold a reference */
53301+ if (retval == NULL)
53302+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53303+out:
53304+ br_read_unlock(vfsmount_lock);
53305+ write_sequnlock(&rename_lock);
53306+
53307+ BUG_ON(retval == NULL);
53308+
53309+ return retval;
53310+}
53311+
53312+static __inline__ struct acl_object_label *
53313+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53314+ const struct acl_subject_label *subj)
53315+{
53316+ char *path = NULL;
53317+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53318+}
53319+
53320+static __inline__ struct acl_object_label *
53321+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53322+ const struct acl_subject_label *subj)
53323+{
53324+ char *path = NULL;
53325+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53326+}
53327+
53328+static __inline__ struct acl_object_label *
53329+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53330+ const struct acl_subject_label *subj, char *path)
53331+{
53332+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53333+}
53334+
53335+static struct acl_subject_label *
53336+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53337+ const struct acl_role_label *role)
53338+{
53339+ struct dentry *dentry = (struct dentry *) l_dentry;
53340+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53341+ struct acl_subject_label *retval;
53342+ struct dentry *parent;
53343+
53344+ write_seqlock(&rename_lock);
53345+ br_read_lock(vfsmount_lock);
53346+
53347+ for (;;) {
53348+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53349+ break;
53350+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53351+ if (mnt->mnt_parent == mnt)
53352+ break;
53353+
53354+ spin_lock(&dentry->d_lock);
53355+ read_lock(&gr_inode_lock);
53356+ retval =
53357+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53358+ __get_dev(dentry), role);
53359+ read_unlock(&gr_inode_lock);
53360+ spin_unlock(&dentry->d_lock);
53361+ if (retval != NULL)
53362+ goto out;
53363+
53364+ dentry = mnt->mnt_mountpoint;
53365+ mnt = mnt->mnt_parent;
53366+ continue;
53367+ }
53368+
53369+ spin_lock(&dentry->d_lock);
53370+ read_lock(&gr_inode_lock);
53371+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53372+ __get_dev(dentry), role);
53373+ read_unlock(&gr_inode_lock);
53374+ parent = dentry->d_parent;
53375+ spin_unlock(&dentry->d_lock);
53376+
53377+ if (retval != NULL)
53378+ goto out;
53379+
53380+ dentry = parent;
53381+ }
53382+
53383+ spin_lock(&dentry->d_lock);
53384+ read_lock(&gr_inode_lock);
53385+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53386+ __get_dev(dentry), role);
53387+ read_unlock(&gr_inode_lock);
53388+ spin_unlock(&dentry->d_lock);
53389+
53390+ if (unlikely(retval == NULL)) {
53391+ /* real_root is pinned, we don't need to hold a reference */
53392+ read_lock(&gr_inode_lock);
53393+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53394+ __get_dev(real_root.dentry), role);
53395+ read_unlock(&gr_inode_lock);
53396+ }
53397+out:
53398+ br_read_unlock(vfsmount_lock);
53399+ write_sequnlock(&rename_lock);
53400+
53401+ BUG_ON(retval == NULL);
53402+
53403+ return retval;
53404+}
53405+
53406+static void
53407+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53408+{
53409+ struct task_struct *task = current;
53410+ const struct cred *cred = current_cred();
53411+
53412+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53413+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53414+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53415+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53416+
53417+ return;
53418+}
53419+
53420+static void
53421+gr_log_learn_sysctl(const char *path, const __u32 mode)
53422+{
53423+ struct task_struct *task = current;
53424+ const struct cred *cred = current_cred();
53425+
53426+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53427+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53428+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53429+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53430+
53431+ return;
53432+}
53433+
53434+static void
53435+gr_log_learn_id_change(const char type, const unsigned int real,
53436+ const unsigned int effective, const unsigned int fs)
53437+{
53438+ struct task_struct *task = current;
53439+ const struct cred *cred = current_cred();
53440+
53441+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53442+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53443+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53444+ type, real, effective, fs, &task->signal->saved_ip);
53445+
53446+ return;
53447+}
53448+
53449+__u32
53450+gr_check_link(const struct dentry * new_dentry,
53451+ const struct dentry * parent_dentry,
53452+ const struct vfsmount * parent_mnt,
53453+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53454+{
53455+ struct acl_object_label *obj;
53456+ __u32 oldmode, newmode;
53457+ __u32 needmode;
53458+
53459+ if (unlikely(!(gr_status & GR_READY)))
53460+ return (GR_CREATE | GR_LINK);
53461+
53462+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53463+ oldmode = obj->mode;
53464+
53465+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53466+ oldmode |= (GR_CREATE | GR_LINK);
53467+
53468+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
53469+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53470+ needmode |= GR_SETID | GR_AUDIT_SETID;
53471+
53472+ newmode =
53473+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
53474+ oldmode | needmode);
53475+
53476+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
53477+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
53478+ GR_INHERIT | GR_AUDIT_INHERIT);
53479+
53480+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
53481+ goto bad;
53482+
53483+ if ((oldmode & needmode) != needmode)
53484+ goto bad;
53485+
53486+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53487+ if ((newmode & needmode) != needmode)
53488+ goto bad;
53489+
53490+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53491+ return newmode;
53492+bad:
53493+ needmode = oldmode;
53494+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53495+ needmode |= GR_SETID;
53496+
53497+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53498+ gr_log_learn(old_dentry, old_mnt, needmode);
53499+ return (GR_CREATE | GR_LINK);
53500+ } else if (newmode & GR_SUPPRESS)
53501+ return GR_SUPPRESS;
53502+ else
53503+ return 0;
53504+}
53505+
53506+__u32
53507+gr_search_file(const struct dentry * dentry, const __u32 mode,
53508+ const struct vfsmount * mnt)
53509+{
53510+ __u32 retval = mode;
53511+ struct acl_subject_label *curracl;
53512+ struct acl_object_label *currobj;
53513+
53514+ if (unlikely(!(gr_status & GR_READY)))
53515+ return (mode & ~GR_AUDITS);
53516+
53517+ curracl = current->acl;
53518+
53519+ currobj = chk_obj_label(dentry, mnt, curracl);
53520+ retval = currobj->mode & mode;
53521+
53522+ /* if we're opening a specified transfer file for writing
53523+ (e.g. /dev/initctl), then transfer our role to init
53524+ */
53525+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53526+ current->role->roletype & GR_ROLE_PERSIST)) {
53527+ struct task_struct *task = init_pid_ns.child_reaper;
53528+
53529+ if (task->role != current->role) {
53530+ task->acl_sp_role = 0;
53531+ task->acl_role_id = current->acl_role_id;
53532+ task->role = current->role;
53533+ rcu_read_lock();
53534+ read_lock(&grsec_exec_file_lock);
53535+ gr_apply_subject_to_task(task);
53536+ read_unlock(&grsec_exec_file_lock);
53537+ rcu_read_unlock();
53538+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53539+ }
53540+ }
53541+
53542+ if (unlikely
53543+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53544+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53545+ __u32 new_mode = mode;
53546+
53547+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53548+
53549+ retval = new_mode;
53550+
53551+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53552+ new_mode |= GR_INHERIT;
53553+
53554+ if (!(mode & GR_NOLEARN))
53555+ gr_log_learn(dentry, mnt, new_mode);
53556+ }
53557+
53558+ return retval;
53559+}
53560+
53561+__u32
53562+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53563+ const struct vfsmount * mnt, const __u32 mode)
53564+{
53565+ struct name_entry *match;
53566+ struct acl_object_label *matchpo;
53567+ struct acl_subject_label *curracl;
53568+ char *path;
53569+ __u32 retval;
53570+
53571+ if (unlikely(!(gr_status & GR_READY)))
53572+ return (mode & ~GR_AUDITS);
53573+
53574+ preempt_disable();
53575+ path = gr_to_filename_rbac(new_dentry, mnt);
53576+ match = lookup_name_entry_create(path);
53577+
53578+ if (!match)
53579+ goto check_parent;
53580+
53581+ curracl = current->acl;
53582+
53583+ read_lock(&gr_inode_lock);
53584+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53585+ read_unlock(&gr_inode_lock);
53586+
53587+ if (matchpo) {
53588+ if ((matchpo->mode & mode) !=
53589+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
53590+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53591+ __u32 new_mode = mode;
53592+
53593+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53594+
53595+ gr_log_learn(new_dentry, mnt, new_mode);
53596+
53597+ preempt_enable();
53598+ return new_mode;
53599+ }
53600+ preempt_enable();
53601+ return (matchpo->mode & mode);
53602+ }
53603+
53604+ check_parent:
53605+ curracl = current->acl;
53606+
53607+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53608+ retval = matchpo->mode & mode;
53609+
53610+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53611+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53612+ __u32 new_mode = mode;
53613+
53614+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53615+
53616+ gr_log_learn(new_dentry, mnt, new_mode);
53617+ preempt_enable();
53618+ return new_mode;
53619+ }
53620+
53621+ preempt_enable();
53622+ return retval;
53623+}
53624+
53625+int
53626+gr_check_hidden_task(const struct task_struct *task)
53627+{
53628+ if (unlikely(!(gr_status & GR_READY)))
53629+ return 0;
53630+
53631+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53632+ return 1;
53633+
53634+ return 0;
53635+}
53636+
53637+int
53638+gr_check_protected_task(const struct task_struct *task)
53639+{
53640+ if (unlikely(!(gr_status & GR_READY) || !task))
53641+ return 0;
53642+
53643+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53644+ task->acl != current->acl)
53645+ return 1;
53646+
53647+ return 0;
53648+}
53649+
53650+int
53651+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53652+{
53653+ struct task_struct *p;
53654+ int ret = 0;
53655+
53656+ if (unlikely(!(gr_status & GR_READY) || !pid))
53657+ return ret;
53658+
53659+ read_lock(&tasklist_lock);
53660+ do_each_pid_task(pid, type, p) {
53661+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53662+ p->acl != current->acl) {
53663+ ret = 1;
53664+ goto out;
53665+ }
53666+ } while_each_pid_task(pid, type, p);
53667+out:
53668+ read_unlock(&tasklist_lock);
53669+
53670+ return ret;
53671+}
53672+
53673+void
53674+gr_copy_label(struct task_struct *tsk)
53675+{
53676+ tsk->signal->used_accept = 0;
53677+ tsk->acl_sp_role = 0;
53678+ tsk->acl_role_id = current->acl_role_id;
53679+ tsk->acl = current->acl;
53680+ tsk->role = current->role;
53681+ tsk->signal->curr_ip = current->signal->curr_ip;
53682+ tsk->signal->saved_ip = current->signal->saved_ip;
53683+ if (current->exec_file)
53684+ get_file(current->exec_file);
53685+ tsk->exec_file = current->exec_file;
53686+ tsk->is_writable = current->is_writable;
53687+ if (unlikely(current->signal->used_accept)) {
53688+ current->signal->curr_ip = 0;
53689+ current->signal->saved_ip = 0;
53690+ }
53691+
53692+ return;
53693+}
53694+
53695+static void
53696+gr_set_proc_res(struct task_struct *task)
53697+{
53698+ struct acl_subject_label *proc;
53699+ unsigned short i;
53700+
53701+ proc = task->acl;
53702+
53703+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53704+ return;
53705+
53706+ for (i = 0; i < RLIM_NLIMITS; i++) {
53707+ if (!(proc->resmask & (1 << i)))
53708+ continue;
53709+
53710+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53711+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53712+ }
53713+
53714+ return;
53715+}
53716+
53717+extern int __gr_process_user_ban(struct user_struct *user);
53718+
53719+int
53720+gr_check_user_change(int real, int effective, int fs)
53721+{
53722+ unsigned int i;
53723+ __u16 num;
53724+ uid_t *uidlist;
53725+ int curuid;
53726+ int realok = 0;
53727+ int effectiveok = 0;
53728+ int fsok = 0;
53729+
53730+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53731+ struct user_struct *user;
53732+
53733+ if (real == -1)
53734+ goto skipit;
53735+
53736+ user = find_user(real);
53737+ if (user == NULL)
53738+ goto skipit;
53739+
53740+ if (__gr_process_user_ban(user)) {
53741+ /* for find_user */
53742+ free_uid(user);
53743+ return 1;
53744+ }
53745+
53746+ /* for find_user */
53747+ free_uid(user);
53748+
53749+skipit:
53750+#endif
53751+
53752+ if (unlikely(!(gr_status & GR_READY)))
53753+ return 0;
53754+
53755+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53756+ gr_log_learn_id_change('u', real, effective, fs);
53757+
53758+ num = current->acl->user_trans_num;
53759+ uidlist = current->acl->user_transitions;
53760+
53761+ if (uidlist == NULL)
53762+ return 0;
53763+
53764+ if (real == -1)
53765+ realok = 1;
53766+ if (effective == -1)
53767+ effectiveok = 1;
53768+ if (fs == -1)
53769+ fsok = 1;
53770+
53771+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53772+ for (i = 0; i < num; i++) {
53773+ curuid = (int)uidlist[i];
53774+ if (real == curuid)
53775+ realok = 1;
53776+ if (effective == curuid)
53777+ effectiveok = 1;
53778+ if (fs == curuid)
53779+ fsok = 1;
53780+ }
53781+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53782+ for (i = 0; i < num; i++) {
53783+ curuid = (int)uidlist[i];
53784+ if (real == curuid)
53785+ break;
53786+ if (effective == curuid)
53787+ break;
53788+ if (fs == curuid)
53789+ break;
53790+ }
53791+ /* not in deny list */
53792+ if (i == num) {
53793+ realok = 1;
53794+ effectiveok = 1;
53795+ fsok = 1;
53796+ }
53797+ }
53798+
53799+ if (realok && effectiveok && fsok)
53800+ return 0;
53801+ else {
53802+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53803+ return 1;
53804+ }
53805+}
53806+
53807+int
53808+gr_check_group_change(int real, int effective, int fs)
53809+{
53810+ unsigned int i;
53811+ __u16 num;
53812+ gid_t *gidlist;
53813+ int curgid;
53814+ int realok = 0;
53815+ int effectiveok = 0;
53816+ int fsok = 0;
53817+
53818+ if (unlikely(!(gr_status & GR_READY)))
53819+ return 0;
53820+
53821+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53822+ gr_log_learn_id_change('g', real, effective, fs);
53823+
53824+ num = current->acl->group_trans_num;
53825+ gidlist = current->acl->group_transitions;
53826+
53827+ if (gidlist == NULL)
53828+ return 0;
53829+
53830+ if (real == -1)
53831+ realok = 1;
53832+ if (effective == -1)
53833+ effectiveok = 1;
53834+ if (fs == -1)
53835+ fsok = 1;
53836+
53837+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53838+ for (i = 0; i < num; i++) {
53839+ curgid = (int)gidlist[i];
53840+ if (real == curgid)
53841+ realok = 1;
53842+ if (effective == curgid)
53843+ effectiveok = 1;
53844+ if (fs == curgid)
53845+ fsok = 1;
53846+ }
53847+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53848+ for (i = 0; i < num; i++) {
53849+ curgid = (int)gidlist[i];
53850+ if (real == curgid)
53851+ break;
53852+ if (effective == curgid)
53853+ break;
53854+ if (fs == curgid)
53855+ break;
53856+ }
53857+ /* not in deny list */
53858+ if (i == num) {
53859+ realok = 1;
53860+ effectiveok = 1;
53861+ fsok = 1;
53862+ }
53863+ }
53864+
53865+ if (realok && effectiveok && fsok)
53866+ return 0;
53867+ else {
53868+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53869+ return 1;
53870+ }
53871+}
53872+
53873+void
53874+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53875+{
53876+ struct acl_role_label *role = task->role;
53877+ struct acl_subject_label *subj = NULL;
53878+ struct acl_object_label *obj;
53879+ struct file *filp;
53880+
53881+ if (unlikely(!(gr_status & GR_READY)))
53882+ return;
53883+
53884+ filp = task->exec_file;
53885+
53886+ /* kernel process, we'll give them the kernel role */
53887+ if (unlikely(!filp)) {
53888+ task->role = kernel_role;
53889+ task->acl = kernel_role->root_label;
53890+ return;
53891+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53892+ role = lookup_acl_role_label(task, uid, gid);
53893+
53894+ /* perform subject lookup in possibly new role
53895+ we can use this result below in the case where role == task->role
53896+ */
53897+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53898+
53899+ /* if we changed uid/gid, but result in the same role
53900+ and are using inheritance, don't lose the inherited subject
53901+ if current subject is other than what normal lookup
53902+ would result in, we arrived via inheritance, don't
53903+ lose subject
53904+ */
53905+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53906+ (subj == task->acl)))
53907+ task->acl = subj;
53908+
53909+ task->role = role;
53910+
53911+ task->is_writable = 0;
53912+
53913+ /* ignore additional mmap checks for processes that are writable
53914+ by the default ACL */
53915+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53916+ if (unlikely(obj->mode & GR_WRITE))
53917+ task->is_writable = 1;
53918+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53919+ if (unlikely(obj->mode & GR_WRITE))
53920+ task->is_writable = 1;
53921+
53922+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53923+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53924+#endif
53925+
53926+ gr_set_proc_res(task);
53927+
53928+ return;
53929+}
53930+
53931+int
53932+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53933+ const int unsafe_share)
53934+{
53935+ struct task_struct *task = current;
53936+ struct acl_subject_label *newacl;
53937+ struct acl_object_label *obj;
53938+ __u32 retmode;
53939+
53940+ if (unlikely(!(gr_status & GR_READY)))
53941+ return 0;
53942+
53943+ newacl = chk_subj_label(dentry, mnt, task->role);
53944+
53945+ task_lock(task);
53946+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53947+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53948+ !(task->role->roletype & GR_ROLE_GOD) &&
53949+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53950+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53951+ task_unlock(task);
53952+ if (unsafe_share)
53953+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53954+ else
53955+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53956+ return -EACCES;
53957+ }
53958+ task_unlock(task);
53959+
53960+ obj = chk_obj_label(dentry, mnt, task->acl);
53961+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53962+
53963+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53964+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53965+ if (obj->nested)
53966+ task->acl = obj->nested;
53967+ else
53968+ task->acl = newacl;
53969+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53970+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53971+
53972+ task->is_writable = 0;
53973+
53974+ /* ignore additional mmap checks for processes that are writable
53975+ by the default ACL */
53976+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53977+ if (unlikely(obj->mode & GR_WRITE))
53978+ task->is_writable = 1;
53979+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53980+ if (unlikely(obj->mode & GR_WRITE))
53981+ task->is_writable = 1;
53982+
53983+ gr_set_proc_res(task);
53984+
53985+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53986+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53987+#endif
53988+ return 0;
53989+}
53990+
53991+/* always called with valid inodev ptr */
53992+static void
53993+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53994+{
53995+ struct acl_object_label *matchpo;
53996+ struct acl_subject_label *matchps;
53997+ struct acl_subject_label *subj;
53998+ struct acl_role_label *role;
53999+ unsigned int x;
54000+
54001+ FOR_EACH_ROLE_START(role)
54002+ FOR_EACH_SUBJECT_START(role, subj, x)
54003+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54004+ matchpo->mode |= GR_DELETED;
54005+ FOR_EACH_SUBJECT_END(subj,x)
54006+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54007+ if (subj->inode == ino && subj->device == dev)
54008+ subj->mode |= GR_DELETED;
54009+ FOR_EACH_NESTED_SUBJECT_END(subj)
54010+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54011+ matchps->mode |= GR_DELETED;
54012+ FOR_EACH_ROLE_END(role)
54013+
54014+ inodev->nentry->deleted = 1;
54015+
54016+ return;
54017+}
54018+
54019+void
54020+gr_handle_delete(const ino_t ino, const dev_t dev)
54021+{
54022+ struct inodev_entry *inodev;
54023+
54024+ if (unlikely(!(gr_status & GR_READY)))
54025+ return;
54026+
54027+ write_lock(&gr_inode_lock);
54028+ inodev = lookup_inodev_entry(ino, dev);
54029+ if (inodev != NULL)
54030+ do_handle_delete(inodev, ino, dev);
54031+ write_unlock(&gr_inode_lock);
54032+
54033+ return;
54034+}
54035+
54036+static void
54037+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54038+ const ino_t newinode, const dev_t newdevice,
54039+ struct acl_subject_label *subj)
54040+{
54041+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54042+ struct acl_object_label *match;
54043+
54044+ match = subj->obj_hash[index];
54045+
54046+ while (match && (match->inode != oldinode ||
54047+ match->device != olddevice ||
54048+ !(match->mode & GR_DELETED)))
54049+ match = match->next;
54050+
54051+ if (match && (match->inode == oldinode)
54052+ && (match->device == olddevice)
54053+ && (match->mode & GR_DELETED)) {
54054+ if (match->prev == NULL) {
54055+ subj->obj_hash[index] = match->next;
54056+ if (match->next != NULL)
54057+ match->next->prev = NULL;
54058+ } else {
54059+ match->prev->next = match->next;
54060+ if (match->next != NULL)
54061+ match->next->prev = match->prev;
54062+ }
54063+ match->prev = NULL;
54064+ match->next = NULL;
54065+ match->inode = newinode;
54066+ match->device = newdevice;
54067+ match->mode &= ~GR_DELETED;
54068+
54069+ insert_acl_obj_label(match, subj);
54070+ }
54071+
54072+ return;
54073+}
54074+
54075+static void
54076+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54077+ const ino_t newinode, const dev_t newdevice,
54078+ struct acl_role_label *role)
54079+{
54080+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54081+ struct acl_subject_label *match;
54082+
54083+ match = role->subj_hash[index];
54084+
54085+ while (match && (match->inode != oldinode ||
54086+ match->device != olddevice ||
54087+ !(match->mode & GR_DELETED)))
54088+ match = match->next;
54089+
54090+ if (match && (match->inode == oldinode)
54091+ && (match->device == olddevice)
54092+ && (match->mode & GR_DELETED)) {
54093+ if (match->prev == NULL) {
54094+ role->subj_hash[index] = match->next;
54095+ if (match->next != NULL)
54096+ match->next->prev = NULL;
54097+ } else {
54098+ match->prev->next = match->next;
54099+ if (match->next != NULL)
54100+ match->next->prev = match->prev;
54101+ }
54102+ match->prev = NULL;
54103+ match->next = NULL;
54104+ match->inode = newinode;
54105+ match->device = newdevice;
54106+ match->mode &= ~GR_DELETED;
54107+
54108+ insert_acl_subj_label(match, role);
54109+ }
54110+
54111+ return;
54112+}
54113+
54114+static void
54115+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54116+ const ino_t newinode, const dev_t newdevice)
54117+{
54118+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54119+ struct inodev_entry *match;
54120+
54121+ match = inodev_set.i_hash[index];
54122+
54123+ while (match && (match->nentry->inode != oldinode ||
54124+ match->nentry->device != olddevice || !match->nentry->deleted))
54125+ match = match->next;
54126+
54127+ if (match && (match->nentry->inode == oldinode)
54128+ && (match->nentry->device == olddevice) &&
54129+ match->nentry->deleted) {
54130+ if (match->prev == NULL) {
54131+ inodev_set.i_hash[index] = match->next;
54132+ if (match->next != NULL)
54133+ match->next->prev = NULL;
54134+ } else {
54135+ match->prev->next = match->next;
54136+ if (match->next != NULL)
54137+ match->next->prev = match->prev;
54138+ }
54139+ match->prev = NULL;
54140+ match->next = NULL;
54141+ match->nentry->inode = newinode;
54142+ match->nentry->device = newdevice;
54143+ match->nentry->deleted = 0;
54144+
54145+ insert_inodev_entry(match);
54146+ }
54147+
54148+ return;
54149+}
54150+
54151+static void
54152+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54153+ const struct vfsmount *mnt)
54154+{
54155+ struct acl_subject_label *subj;
54156+ struct acl_role_label *role;
54157+ unsigned int x;
54158+ ino_t ino = dentry->d_inode->i_ino;
54159+ dev_t dev = __get_dev(dentry);
54160+
54161+ FOR_EACH_ROLE_START(role)
54162+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54163+
54164+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54165+ if ((subj->inode == ino) && (subj->device == dev)) {
54166+ subj->inode = ino;
54167+ subj->device = dev;
54168+ }
54169+ FOR_EACH_NESTED_SUBJECT_END(subj)
54170+ FOR_EACH_SUBJECT_START(role, subj, x)
54171+ update_acl_obj_label(matchn->inode, matchn->device,
54172+ ino, dev, subj);
54173+ FOR_EACH_SUBJECT_END(subj,x)
54174+ FOR_EACH_ROLE_END(role)
54175+
54176+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54177+
54178+ return;
54179+}
54180+
54181+void
54182+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54183+{
54184+ struct name_entry *matchn;
54185+
54186+ if (unlikely(!(gr_status & GR_READY)))
54187+ return;
54188+
54189+ preempt_disable();
54190+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54191+
54192+ if (unlikely((unsigned long)matchn)) {
54193+ write_lock(&gr_inode_lock);
54194+ do_handle_create(matchn, dentry, mnt);
54195+ write_unlock(&gr_inode_lock);
54196+ }
54197+ preempt_enable();
54198+
54199+ return;
54200+}
54201+
54202+void
54203+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54204+ struct dentry *old_dentry,
54205+ struct dentry *new_dentry,
54206+ struct vfsmount *mnt, const __u8 replace)
54207+{
54208+ struct name_entry *matchn;
54209+ struct inodev_entry *inodev;
54210+ ino_t old_ino = old_dentry->d_inode->i_ino;
54211+ dev_t old_dev = __get_dev(old_dentry);
54212+
54213+ /* vfs_rename swaps the name and parent link for old_dentry and
54214+ new_dentry
54215+ at this point, old_dentry has the new name, parent link, and inode
54216+ for the renamed file
54217+ if a file is being replaced by a rename, new_dentry has the inode
54218+ and name for the replaced file
54219+ */
54220+
54221+ if (unlikely(!(gr_status & GR_READY)))
54222+ return;
54223+
54224+ preempt_disable();
54225+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54226+
54227+ /* we wouldn't have to check d_inode if it weren't for
54228+ NFS silly-renaming
54229+ */
54230+
54231+ write_lock(&gr_inode_lock);
54232+ if (unlikely(replace && new_dentry->d_inode)) {
54233+ ino_t new_ino = new_dentry->d_inode->i_ino;
54234+ dev_t new_dev = __get_dev(new_dentry);
54235+
54236+ inodev = lookup_inodev_entry(new_ino, new_dev);
54237+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
54238+ do_handle_delete(inodev, new_ino, new_dev);
54239+ }
54240+
54241+ inodev = lookup_inodev_entry(old_ino, old_dev);
54242+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
54243+ do_handle_delete(inodev, old_ino, old_dev);
54244+
54245+ if (unlikely((unsigned long)matchn))
54246+ do_handle_create(matchn, old_dentry, mnt);
54247+
54248+ write_unlock(&gr_inode_lock);
54249+ preempt_enable();
54250+
54251+ return;
54252+}
54253+
54254+static int
54255+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54256+ unsigned char **sum)
54257+{
54258+ struct acl_role_label *r;
54259+ struct role_allowed_ip *ipp;
54260+ struct role_transition *trans;
54261+ unsigned int i;
54262+ int found = 0;
54263+ u32 curr_ip = current->signal->curr_ip;
54264+
54265+ current->signal->saved_ip = curr_ip;
54266+
54267+ /* check transition table */
54268+
54269+ for (trans = current->role->transitions; trans; trans = trans->next) {
54270+ if (!strcmp(rolename, trans->rolename)) {
54271+ found = 1;
54272+ break;
54273+ }
54274+ }
54275+
54276+ if (!found)
54277+ return 0;
54278+
54279+ /* handle special roles that do not require authentication
54280+ and check ip */
54281+
54282+ FOR_EACH_ROLE_START(r)
54283+ if (!strcmp(rolename, r->rolename) &&
54284+ (r->roletype & GR_ROLE_SPECIAL)) {
54285+ found = 0;
54286+ if (r->allowed_ips != NULL) {
54287+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54288+ if ((ntohl(curr_ip) & ipp->netmask) ==
54289+ (ntohl(ipp->addr) & ipp->netmask))
54290+ found = 1;
54291+ }
54292+ } else
54293+ found = 2;
54294+ if (!found)
54295+ return 0;
54296+
54297+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54298+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54299+ *salt = NULL;
54300+ *sum = NULL;
54301+ return 1;
54302+ }
54303+ }
54304+ FOR_EACH_ROLE_END(r)
54305+
54306+ for (i = 0; i < num_sprole_pws; i++) {
54307+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54308+ *salt = acl_special_roles[i]->salt;
54309+ *sum = acl_special_roles[i]->sum;
54310+ return 1;
54311+ }
54312+ }
54313+
54314+ return 0;
54315+}
54316+
54317+static void
54318+assign_special_role(char *rolename)
54319+{
54320+ struct acl_object_label *obj;
54321+ struct acl_role_label *r;
54322+ struct acl_role_label *assigned = NULL;
54323+ struct task_struct *tsk;
54324+ struct file *filp;
54325+
54326+ FOR_EACH_ROLE_START(r)
54327+ if (!strcmp(rolename, r->rolename) &&
54328+ (r->roletype & GR_ROLE_SPECIAL)) {
54329+ assigned = r;
54330+ break;
54331+ }
54332+ FOR_EACH_ROLE_END(r)
54333+
54334+ if (!assigned)
54335+ return;
54336+
54337+ read_lock(&tasklist_lock);
54338+ read_lock(&grsec_exec_file_lock);
54339+
54340+ tsk = current->real_parent;
54341+ if (tsk == NULL)
54342+ goto out_unlock;
54343+
54344+ filp = tsk->exec_file;
54345+ if (filp == NULL)
54346+ goto out_unlock;
54347+
54348+ tsk->is_writable = 0;
54349+
54350+ tsk->acl_sp_role = 1;
54351+ tsk->acl_role_id = ++acl_sp_role_value;
54352+ tsk->role = assigned;
54353+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54354+
54355+ /* ignore additional mmap checks for processes that are writable
54356+ by the default ACL */
54357+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54358+ if (unlikely(obj->mode & GR_WRITE))
54359+ tsk->is_writable = 1;
54360+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54361+ if (unlikely(obj->mode & GR_WRITE))
54362+ tsk->is_writable = 1;
54363+
54364+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54365+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54366+#endif
54367+
54368+out_unlock:
54369+ read_unlock(&grsec_exec_file_lock);
54370+ read_unlock(&tasklist_lock);
54371+ return;
54372+}
54373+
54374+int gr_check_secure_terminal(struct task_struct *task)
54375+{
54376+ struct task_struct *p, *p2, *p3;
54377+ struct files_struct *files;
54378+ struct fdtable *fdt;
54379+ struct file *our_file = NULL, *file;
54380+ int i;
54381+
54382+ if (task->signal->tty == NULL)
54383+ return 1;
54384+
54385+ files = get_files_struct(task);
54386+ if (files != NULL) {
54387+ rcu_read_lock();
54388+ fdt = files_fdtable(files);
54389+ for (i=0; i < fdt->max_fds; i++) {
54390+ file = fcheck_files(files, i);
54391+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54392+ get_file(file);
54393+ our_file = file;
54394+ }
54395+ }
54396+ rcu_read_unlock();
54397+ put_files_struct(files);
54398+ }
54399+
54400+ if (our_file == NULL)
54401+ return 1;
54402+
54403+ read_lock(&tasklist_lock);
54404+ do_each_thread(p2, p) {
54405+ files = get_files_struct(p);
54406+ if (files == NULL ||
54407+ (p->signal && p->signal->tty == task->signal->tty)) {
54408+ if (files != NULL)
54409+ put_files_struct(files);
54410+ continue;
54411+ }
54412+ rcu_read_lock();
54413+ fdt = files_fdtable(files);
54414+ for (i=0; i < fdt->max_fds; i++) {
54415+ file = fcheck_files(files, i);
54416+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54417+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54418+ p3 = task;
54419+ while (p3->pid > 0) {
54420+ if (p3 == p)
54421+ break;
54422+ p3 = p3->real_parent;
54423+ }
54424+ if (p3 == p)
54425+ break;
54426+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54427+ gr_handle_alertkill(p);
54428+ rcu_read_unlock();
54429+ put_files_struct(files);
54430+ read_unlock(&tasklist_lock);
54431+ fput(our_file);
54432+ return 0;
54433+ }
54434+ }
54435+ rcu_read_unlock();
54436+ put_files_struct(files);
54437+ } while_each_thread(p2, p);
54438+ read_unlock(&tasklist_lock);
54439+
54440+ fput(our_file);
54441+ return 1;
54442+}
54443+
54444+ssize_t
54445+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54446+{
54447+ struct gr_arg_wrapper uwrap;
54448+ unsigned char *sprole_salt = NULL;
54449+ unsigned char *sprole_sum = NULL;
54450+ int error = sizeof (struct gr_arg_wrapper);
54451+ int error2 = 0;
54452+
54453+ mutex_lock(&gr_dev_mutex);
54454+
54455+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54456+ error = -EPERM;
54457+ goto out;
54458+ }
54459+
54460+ if (count != sizeof (struct gr_arg_wrapper)) {
54461+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54462+ error = -EINVAL;
54463+ goto out;
54464+ }
54465+
54466+
54467+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54468+ gr_auth_expires = 0;
54469+ gr_auth_attempts = 0;
54470+ }
54471+
54472+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54473+ error = -EFAULT;
54474+ goto out;
54475+ }
54476+
54477+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54478+ error = -EINVAL;
54479+ goto out;
54480+ }
54481+
54482+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54483+ error = -EFAULT;
54484+ goto out;
54485+ }
54486+
54487+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54488+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54489+ time_after(gr_auth_expires, get_seconds())) {
54490+ error = -EBUSY;
54491+ goto out;
54492+ }
54493+
54494+ /* if non-root trying to do anything other than use a special role,
54495+ do not attempt authentication, do not count towards authentication
54496+ locking
54497+ */
54498+
54499+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54500+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54501+ current_uid()) {
54502+ error = -EPERM;
54503+ goto out;
54504+ }
54505+
54506+ /* ensure pw and special role name are null terminated */
54507+
54508+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54509+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54510+
54511+ /* Okay.
54512+ * We have our enough of the argument structure..(we have yet
54513+ * to copy_from_user the tables themselves) . Copy the tables
54514+ * only if we need them, i.e. for loading operations. */
54515+
54516+ switch (gr_usermode->mode) {
54517+ case GR_STATUS:
54518+ if (gr_status & GR_READY) {
54519+ error = 1;
54520+ if (!gr_check_secure_terminal(current))
54521+ error = 3;
54522+ } else
54523+ error = 2;
54524+ goto out;
54525+ case GR_SHUTDOWN:
54526+ if ((gr_status & GR_READY)
54527+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54528+ pax_open_kernel();
54529+ gr_status &= ~GR_READY;
54530+ pax_close_kernel();
54531+
54532+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54533+ free_variables();
54534+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54535+ memset(gr_system_salt, 0, GR_SALT_LEN);
54536+ memset(gr_system_sum, 0, GR_SHA_LEN);
54537+ } else if (gr_status & GR_READY) {
54538+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54539+ error = -EPERM;
54540+ } else {
54541+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54542+ error = -EAGAIN;
54543+ }
54544+ break;
54545+ case GR_ENABLE:
54546+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54547+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54548+ else {
54549+ if (gr_status & GR_READY)
54550+ error = -EAGAIN;
54551+ else
54552+ error = error2;
54553+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54554+ }
54555+ break;
54556+ case GR_RELOAD:
54557+ if (!(gr_status & GR_READY)) {
54558+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54559+ error = -EAGAIN;
54560+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54561+ preempt_disable();
54562+
54563+ pax_open_kernel();
54564+ gr_status &= ~GR_READY;
54565+ pax_close_kernel();
54566+
54567+ free_variables();
54568+ if (!(error2 = gracl_init(gr_usermode))) {
54569+ preempt_enable();
54570+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54571+ } else {
54572+ preempt_enable();
54573+ error = error2;
54574+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54575+ }
54576+ } else {
54577+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54578+ error = -EPERM;
54579+ }
54580+ break;
54581+ case GR_SEGVMOD:
54582+ if (unlikely(!(gr_status & GR_READY))) {
54583+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54584+ error = -EAGAIN;
54585+ break;
54586+ }
54587+
54588+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54589+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54590+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54591+ struct acl_subject_label *segvacl;
54592+ segvacl =
54593+ lookup_acl_subj_label(gr_usermode->segv_inode,
54594+ gr_usermode->segv_device,
54595+ current->role);
54596+ if (segvacl) {
54597+ segvacl->crashes = 0;
54598+ segvacl->expires = 0;
54599+ }
54600+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54601+ gr_remove_uid(gr_usermode->segv_uid);
54602+ }
54603+ } else {
54604+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54605+ error = -EPERM;
54606+ }
54607+ break;
54608+ case GR_SPROLE:
54609+ case GR_SPROLEPAM:
54610+ if (unlikely(!(gr_status & GR_READY))) {
54611+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54612+ error = -EAGAIN;
54613+ break;
54614+ }
54615+
54616+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54617+ current->role->expires = 0;
54618+ current->role->auth_attempts = 0;
54619+ }
54620+
54621+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54622+ time_after(current->role->expires, get_seconds())) {
54623+ error = -EBUSY;
54624+ goto out;
54625+ }
54626+
54627+ if (lookup_special_role_auth
54628+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54629+ && ((!sprole_salt && !sprole_sum)
54630+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54631+ char *p = "";
54632+ assign_special_role(gr_usermode->sp_role);
54633+ read_lock(&tasklist_lock);
54634+ if (current->real_parent)
54635+ p = current->real_parent->role->rolename;
54636+ read_unlock(&tasklist_lock);
54637+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54638+ p, acl_sp_role_value);
54639+ } else {
54640+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54641+ error = -EPERM;
54642+ if(!(current->role->auth_attempts++))
54643+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54644+
54645+ goto out;
54646+ }
54647+ break;
54648+ case GR_UNSPROLE:
54649+ if (unlikely(!(gr_status & GR_READY))) {
54650+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54651+ error = -EAGAIN;
54652+ break;
54653+ }
54654+
54655+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54656+ char *p = "";
54657+ int i = 0;
54658+
54659+ read_lock(&tasklist_lock);
54660+ if (current->real_parent) {
54661+ p = current->real_parent->role->rolename;
54662+ i = current->real_parent->acl_role_id;
54663+ }
54664+ read_unlock(&tasklist_lock);
54665+
54666+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54667+ gr_set_acls(1);
54668+ } else {
54669+ error = -EPERM;
54670+ goto out;
54671+ }
54672+ break;
54673+ default:
54674+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54675+ error = -EINVAL;
54676+ break;
54677+ }
54678+
54679+ if (error != -EPERM)
54680+ goto out;
54681+
54682+ if(!(gr_auth_attempts++))
54683+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54684+
54685+ out:
54686+ mutex_unlock(&gr_dev_mutex);
54687+ return error;
54688+}
54689+
54690+/* must be called with
54691+ rcu_read_lock();
54692+ read_lock(&tasklist_lock);
54693+ read_lock(&grsec_exec_file_lock);
54694+*/
54695+int gr_apply_subject_to_task(struct task_struct *task)
54696+{
54697+ struct acl_object_label *obj;
54698+ char *tmpname;
54699+ struct acl_subject_label *tmpsubj;
54700+ struct file *filp;
54701+ struct name_entry *nmatch;
54702+
54703+ filp = task->exec_file;
54704+ if (filp == NULL)
54705+ return 0;
54706+
54707+ /* the following is to apply the correct subject
54708+ on binaries running when the RBAC system
54709+ is enabled, when the binaries have been
54710+ replaced or deleted since their execution
54711+ -----
54712+ when the RBAC system starts, the inode/dev
54713+ from exec_file will be one the RBAC system
54714+ is unaware of. It only knows the inode/dev
54715+ of the present file on disk, or the absence
54716+ of it.
54717+ */
54718+ preempt_disable();
54719+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54720+
54721+ nmatch = lookup_name_entry(tmpname);
54722+ preempt_enable();
54723+ tmpsubj = NULL;
54724+ if (nmatch) {
54725+ if (nmatch->deleted)
54726+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54727+ else
54728+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54729+ if (tmpsubj != NULL)
54730+ task->acl = tmpsubj;
54731+ }
54732+ if (tmpsubj == NULL)
54733+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54734+ task->role);
54735+ if (task->acl) {
54736+ struct acl_subject_label *curr;
54737+ curr = task->acl;
54738+
54739+ task->is_writable = 0;
54740+ /* ignore additional mmap checks for processes that are writable
54741+ by the default ACL */
54742+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54743+ if (unlikely(obj->mode & GR_WRITE))
54744+ task->is_writable = 1;
54745+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54746+ if (unlikely(obj->mode & GR_WRITE))
54747+ task->is_writable = 1;
54748+
54749+ gr_set_proc_res(task);
54750+
54751+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54752+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54753+#endif
54754+ } else {
54755+ return 1;
54756+ }
54757+
54758+ return 0;
54759+}
54760+
54761+int
54762+gr_set_acls(const int type)
54763+{
54764+ struct task_struct *task, *task2;
54765+ struct acl_role_label *role = current->role;
54766+ __u16 acl_role_id = current->acl_role_id;
54767+ const struct cred *cred;
54768+ int ret;
54769+
54770+ rcu_read_lock();
54771+ read_lock(&tasklist_lock);
54772+ read_lock(&grsec_exec_file_lock);
54773+ do_each_thread(task2, task) {
54774+ /* check to see if we're called from the exit handler,
54775+ if so, only replace ACLs that have inherited the admin
54776+ ACL */
54777+
54778+ if (type && (task->role != role ||
54779+ task->acl_role_id != acl_role_id))
54780+ continue;
54781+
54782+ task->acl_role_id = 0;
54783+ task->acl_sp_role = 0;
54784+
54785+ if (task->exec_file) {
54786+ cred = __task_cred(task);
54787+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54788+ ret = gr_apply_subject_to_task(task);
54789+ if (ret) {
54790+ read_unlock(&grsec_exec_file_lock);
54791+ read_unlock(&tasklist_lock);
54792+ rcu_read_unlock();
54793+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54794+ return ret;
54795+ }
54796+ } else {
54797+ // it's a kernel process
54798+ task->role = kernel_role;
54799+ task->acl = kernel_role->root_label;
54800+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54801+ task->acl->mode &= ~GR_PROCFIND;
54802+#endif
54803+ }
54804+ } while_each_thread(task2, task);
54805+ read_unlock(&grsec_exec_file_lock);
54806+ read_unlock(&tasklist_lock);
54807+ rcu_read_unlock();
54808+
54809+ return 0;
54810+}
54811+
54812+void
54813+gr_learn_resource(const struct task_struct *task,
54814+ const int res, const unsigned long wanted, const int gt)
54815+{
54816+ struct acl_subject_label *acl;
54817+ const struct cred *cred;
54818+
54819+ if (unlikely((gr_status & GR_READY) &&
54820+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54821+ goto skip_reslog;
54822+
54823+#ifdef CONFIG_GRKERNSEC_RESLOG
54824+ gr_log_resource(task, res, wanted, gt);
54825+#endif
54826+ skip_reslog:
54827+
54828+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54829+ return;
54830+
54831+ acl = task->acl;
54832+
54833+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54834+ !(acl->resmask & (1 << (unsigned short) res))))
54835+ return;
54836+
54837+ if (wanted >= acl->res[res].rlim_cur) {
54838+ unsigned long res_add;
54839+
54840+ res_add = wanted;
54841+ switch (res) {
54842+ case RLIMIT_CPU:
54843+ res_add += GR_RLIM_CPU_BUMP;
54844+ break;
54845+ case RLIMIT_FSIZE:
54846+ res_add += GR_RLIM_FSIZE_BUMP;
54847+ break;
54848+ case RLIMIT_DATA:
54849+ res_add += GR_RLIM_DATA_BUMP;
54850+ break;
54851+ case RLIMIT_STACK:
54852+ res_add += GR_RLIM_STACK_BUMP;
54853+ break;
54854+ case RLIMIT_CORE:
54855+ res_add += GR_RLIM_CORE_BUMP;
54856+ break;
54857+ case RLIMIT_RSS:
54858+ res_add += GR_RLIM_RSS_BUMP;
54859+ break;
54860+ case RLIMIT_NPROC:
54861+ res_add += GR_RLIM_NPROC_BUMP;
54862+ break;
54863+ case RLIMIT_NOFILE:
54864+ res_add += GR_RLIM_NOFILE_BUMP;
54865+ break;
54866+ case RLIMIT_MEMLOCK:
54867+ res_add += GR_RLIM_MEMLOCK_BUMP;
54868+ break;
54869+ case RLIMIT_AS:
54870+ res_add += GR_RLIM_AS_BUMP;
54871+ break;
54872+ case RLIMIT_LOCKS:
54873+ res_add += GR_RLIM_LOCKS_BUMP;
54874+ break;
54875+ case RLIMIT_SIGPENDING:
54876+ res_add += GR_RLIM_SIGPENDING_BUMP;
54877+ break;
54878+ case RLIMIT_MSGQUEUE:
54879+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54880+ break;
54881+ case RLIMIT_NICE:
54882+ res_add += GR_RLIM_NICE_BUMP;
54883+ break;
54884+ case RLIMIT_RTPRIO:
54885+ res_add += GR_RLIM_RTPRIO_BUMP;
54886+ break;
54887+ case RLIMIT_RTTIME:
54888+ res_add += GR_RLIM_RTTIME_BUMP;
54889+ break;
54890+ }
54891+
54892+ acl->res[res].rlim_cur = res_add;
54893+
54894+ if (wanted > acl->res[res].rlim_max)
54895+ acl->res[res].rlim_max = res_add;
54896+
54897+ /* only log the subject filename, since resource logging is supported for
54898+ single-subject learning only */
54899+ rcu_read_lock();
54900+ cred = __task_cred(task);
54901+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54902+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54903+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54904+ "", (unsigned long) res, &task->signal->saved_ip);
54905+ rcu_read_unlock();
54906+ }
54907+
54908+ return;
54909+}
54910+
54911+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54912+void
54913+pax_set_initial_flags(struct linux_binprm *bprm)
54914+{
54915+ struct task_struct *task = current;
54916+ struct acl_subject_label *proc;
54917+ unsigned long flags;
54918+
54919+ if (unlikely(!(gr_status & GR_READY)))
54920+ return;
54921+
54922+ flags = pax_get_flags(task);
54923+
54924+ proc = task->acl;
54925+
54926+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54927+ flags &= ~MF_PAX_PAGEEXEC;
54928+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54929+ flags &= ~MF_PAX_SEGMEXEC;
54930+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54931+ flags &= ~MF_PAX_RANDMMAP;
54932+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54933+ flags &= ~MF_PAX_EMUTRAMP;
54934+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54935+ flags &= ~MF_PAX_MPROTECT;
54936+
54937+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54938+ flags |= MF_PAX_PAGEEXEC;
54939+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54940+ flags |= MF_PAX_SEGMEXEC;
54941+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54942+ flags |= MF_PAX_RANDMMAP;
54943+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54944+ flags |= MF_PAX_EMUTRAMP;
54945+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54946+ flags |= MF_PAX_MPROTECT;
54947+
54948+ pax_set_flags(task, flags);
54949+
54950+ return;
54951+}
54952+#endif
54953+
54954+#ifdef CONFIG_SYSCTL
54955+/* Eric Biederman likes breaking userland ABI and every inode-based security
54956+ system to save 35kb of memory */
54957+
54958+/* we modify the passed in filename, but adjust it back before returning */
54959+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54960+{
54961+ struct name_entry *nmatch;
54962+ char *p, *lastp = NULL;
54963+ struct acl_object_label *obj = NULL, *tmp;
54964+ struct acl_subject_label *tmpsubj;
54965+ char c = '\0';
54966+
54967+ read_lock(&gr_inode_lock);
54968+
54969+ p = name + len - 1;
54970+ do {
54971+ nmatch = lookup_name_entry(name);
54972+ if (lastp != NULL)
54973+ *lastp = c;
54974+
54975+ if (nmatch == NULL)
54976+ goto next_component;
54977+ tmpsubj = current->acl;
54978+ do {
54979+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54980+ if (obj != NULL) {
54981+ tmp = obj->globbed;
54982+ while (tmp) {
54983+ if (!glob_match(tmp->filename, name)) {
54984+ obj = tmp;
54985+ goto found_obj;
54986+ }
54987+ tmp = tmp->next;
54988+ }
54989+ goto found_obj;
54990+ }
54991+ } while ((tmpsubj = tmpsubj->parent_subject));
54992+next_component:
54993+ /* end case */
54994+ if (p == name)
54995+ break;
54996+
54997+ while (*p != '/')
54998+ p--;
54999+ if (p == name)
55000+ lastp = p + 1;
55001+ else {
55002+ lastp = p;
55003+ p--;
55004+ }
55005+ c = *lastp;
55006+ *lastp = '\0';
55007+ } while (1);
55008+found_obj:
55009+ read_unlock(&gr_inode_lock);
55010+ /* obj returned will always be non-null */
55011+ return obj;
55012+}
55013+
55014+/* returns 0 when allowing, non-zero on error
55015+ op of 0 is used for readdir, so we don't log the names of hidden files
55016+*/
55017+__u32
55018+gr_handle_sysctl(const struct ctl_table *table, const int op)
55019+{
55020+ struct ctl_table *tmp;
55021+ const char *proc_sys = "/proc/sys";
55022+ char *path;
55023+ struct acl_object_label *obj;
55024+ unsigned short len = 0, pos = 0, depth = 0, i;
55025+ __u32 err = 0;
55026+ __u32 mode = 0;
55027+
55028+ if (unlikely(!(gr_status & GR_READY)))
55029+ return 0;
55030+
55031+ /* for now, ignore operations on non-sysctl entries if it's not a
55032+ readdir*/
55033+ if (table->child != NULL && op != 0)
55034+ return 0;
55035+
55036+ mode |= GR_FIND;
55037+ /* it's only a read if it's an entry, read on dirs is for readdir */
55038+ if (op & MAY_READ)
55039+ mode |= GR_READ;
55040+ if (op & MAY_WRITE)
55041+ mode |= GR_WRITE;
55042+
55043+ preempt_disable();
55044+
55045+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55046+
55047+ /* it's only a read/write if it's an actual entry, not a dir
55048+ (which are opened for readdir)
55049+ */
55050+
55051+ /* convert the requested sysctl entry into a pathname */
55052+
55053+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55054+ len += strlen(tmp->procname);
55055+ len++;
55056+ depth++;
55057+ }
55058+
55059+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
55060+ /* deny */
55061+ goto out;
55062+ }
55063+
55064+ memset(path, 0, PAGE_SIZE);
55065+
55066+ memcpy(path, proc_sys, strlen(proc_sys));
55067+
55068+ pos += strlen(proc_sys);
55069+
55070+ for (; depth > 0; depth--) {
55071+ path[pos] = '/';
55072+ pos++;
55073+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55074+ if (depth == i) {
55075+ memcpy(path + pos, tmp->procname,
55076+ strlen(tmp->procname));
55077+ pos += strlen(tmp->procname);
55078+ }
55079+ i++;
55080+ }
55081+ }
55082+
55083+ obj = gr_lookup_by_name(path, pos);
55084+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
55085+
55086+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
55087+ ((err & mode) != mode))) {
55088+ __u32 new_mode = mode;
55089+
55090+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55091+
55092+ err = 0;
55093+ gr_log_learn_sysctl(path, new_mode);
55094+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
55095+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
55096+ err = -ENOENT;
55097+ } else if (!(err & GR_FIND)) {
55098+ err = -ENOENT;
55099+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
55100+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
55101+ path, (mode & GR_READ) ? " reading" : "",
55102+ (mode & GR_WRITE) ? " writing" : "");
55103+ err = -EACCES;
55104+ } else if ((err & mode) != mode) {
55105+ err = -EACCES;
55106+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
55107+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
55108+ path, (mode & GR_READ) ? " reading" : "",
55109+ (mode & GR_WRITE) ? " writing" : "");
55110+ err = 0;
55111+ } else
55112+ err = 0;
55113+
55114+ out:
55115+ preempt_enable();
55116+
55117+ return err;
55118+}
55119+#endif
55120+
55121+int
55122+gr_handle_proc_ptrace(struct task_struct *task)
55123+{
55124+ struct file *filp;
55125+ struct task_struct *tmp = task;
55126+ struct task_struct *curtemp = current;
55127+ __u32 retmode;
55128+
55129+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55130+ if (unlikely(!(gr_status & GR_READY)))
55131+ return 0;
55132+#endif
55133+
55134+ read_lock(&tasklist_lock);
55135+ read_lock(&grsec_exec_file_lock);
55136+ filp = task->exec_file;
55137+
55138+ while (tmp->pid > 0) {
55139+ if (tmp == curtemp)
55140+ break;
55141+ tmp = tmp->real_parent;
55142+ }
55143+
55144+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55145+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55146+ read_unlock(&grsec_exec_file_lock);
55147+ read_unlock(&tasklist_lock);
55148+ return 1;
55149+ }
55150+
55151+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55152+ if (!(gr_status & GR_READY)) {
55153+ read_unlock(&grsec_exec_file_lock);
55154+ read_unlock(&tasklist_lock);
55155+ return 0;
55156+ }
55157+#endif
55158+
55159+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55160+ read_unlock(&grsec_exec_file_lock);
55161+ read_unlock(&tasklist_lock);
55162+
55163+ if (retmode & GR_NOPTRACE)
55164+ return 1;
55165+
55166+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55167+ && (current->acl != task->acl || (current->acl != current->role->root_label
55168+ && current->pid != task->pid)))
55169+ return 1;
55170+
55171+ return 0;
55172+}
55173+
55174+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55175+{
55176+ if (unlikely(!(gr_status & GR_READY)))
55177+ return;
55178+
55179+ if (!(current->role->roletype & GR_ROLE_GOD))
55180+ return;
55181+
55182+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55183+ p->role->rolename, gr_task_roletype_to_char(p),
55184+ p->acl->filename);
55185+}
55186+
55187+int
55188+gr_handle_ptrace(struct task_struct *task, const long request)
55189+{
55190+ struct task_struct *tmp = task;
55191+ struct task_struct *curtemp = current;
55192+ __u32 retmode;
55193+
55194+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55195+ if (unlikely(!(gr_status & GR_READY)))
55196+ return 0;
55197+#endif
55198+
55199+ read_lock(&tasklist_lock);
55200+ while (tmp->pid > 0) {
55201+ if (tmp == curtemp)
55202+ break;
55203+ tmp = tmp->real_parent;
55204+ }
55205+
55206+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55207+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55208+ read_unlock(&tasklist_lock);
55209+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55210+ return 1;
55211+ }
55212+ read_unlock(&tasklist_lock);
55213+
55214+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55215+ if (!(gr_status & GR_READY))
55216+ return 0;
55217+#endif
55218+
55219+ read_lock(&grsec_exec_file_lock);
55220+ if (unlikely(!task->exec_file)) {
55221+ read_unlock(&grsec_exec_file_lock);
55222+ return 0;
55223+ }
55224+
55225+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55226+ read_unlock(&grsec_exec_file_lock);
55227+
55228+ if (retmode & GR_NOPTRACE) {
55229+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55230+ return 1;
55231+ }
55232+
55233+ if (retmode & GR_PTRACERD) {
55234+ switch (request) {
55235+ case PTRACE_POKETEXT:
55236+ case PTRACE_POKEDATA:
55237+ case PTRACE_POKEUSR:
55238+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55239+ case PTRACE_SETREGS:
55240+ case PTRACE_SETFPREGS:
55241+#endif
55242+#ifdef CONFIG_X86
55243+ case PTRACE_SETFPXREGS:
55244+#endif
55245+#ifdef CONFIG_ALTIVEC
55246+ case PTRACE_SETVRREGS:
55247+#endif
55248+ return 1;
55249+ default:
55250+ return 0;
55251+ }
55252+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55253+ !(current->role->roletype & GR_ROLE_GOD) &&
55254+ (current->acl != task->acl)) {
55255+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55256+ return 1;
55257+ }
55258+
55259+ return 0;
55260+}
55261+
55262+static int is_writable_mmap(const struct file *filp)
55263+{
55264+ struct task_struct *task = current;
55265+ struct acl_object_label *obj, *obj2;
55266+
55267+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55268+ !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))) {
55269+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55270+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55271+ task->role->root_label);
55272+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55273+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55274+ return 1;
55275+ }
55276+ }
55277+ return 0;
55278+}
55279+
55280+int
55281+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55282+{
55283+ __u32 mode;
55284+
55285+ if (unlikely(!file || !(prot & PROT_EXEC)))
55286+ return 1;
55287+
55288+ if (is_writable_mmap(file))
55289+ return 0;
55290+
55291+ mode =
55292+ gr_search_file(file->f_path.dentry,
55293+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55294+ file->f_path.mnt);
55295+
55296+ if (!gr_tpe_allow(file))
55297+ return 0;
55298+
55299+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55300+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55301+ return 0;
55302+ } else if (unlikely(!(mode & GR_EXEC))) {
55303+ return 0;
55304+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55305+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55306+ return 1;
55307+ }
55308+
55309+ return 1;
55310+}
55311+
55312+int
55313+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55314+{
55315+ __u32 mode;
55316+
55317+ if (unlikely(!file || !(prot & PROT_EXEC)))
55318+ return 1;
55319+
55320+ if (is_writable_mmap(file))
55321+ return 0;
55322+
55323+ mode =
55324+ gr_search_file(file->f_path.dentry,
55325+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55326+ file->f_path.mnt);
55327+
55328+ if (!gr_tpe_allow(file))
55329+ return 0;
55330+
55331+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55332+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55333+ return 0;
55334+ } else if (unlikely(!(mode & GR_EXEC))) {
55335+ return 0;
55336+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55337+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55338+ return 1;
55339+ }
55340+
55341+ return 1;
55342+}
55343+
55344+void
55345+gr_acl_handle_psacct(struct task_struct *task, const long code)
55346+{
55347+ unsigned long runtime;
55348+ unsigned long cputime;
55349+ unsigned int wday, cday;
55350+ __u8 whr, chr;
55351+ __u8 wmin, cmin;
55352+ __u8 wsec, csec;
55353+ struct timespec timeval;
55354+
55355+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55356+ !(task->acl->mode & GR_PROCACCT)))
55357+ return;
55358+
55359+ do_posix_clock_monotonic_gettime(&timeval);
55360+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55361+ wday = runtime / (3600 * 24);
55362+ runtime -= wday * (3600 * 24);
55363+ whr = runtime / 3600;
55364+ runtime -= whr * 3600;
55365+ wmin = runtime / 60;
55366+ runtime -= wmin * 60;
55367+ wsec = runtime;
55368+
55369+ cputime = (task->utime + task->stime) / HZ;
55370+ cday = cputime / (3600 * 24);
55371+ cputime -= cday * (3600 * 24);
55372+ chr = cputime / 3600;
55373+ cputime -= chr * 3600;
55374+ cmin = cputime / 60;
55375+ cputime -= cmin * 60;
55376+ csec = cputime;
55377+
55378+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55379+
55380+ return;
55381+}
55382+
55383+void gr_set_kernel_label(struct task_struct *task)
55384+{
55385+ if (gr_status & GR_READY) {
55386+ task->role = kernel_role;
55387+ task->acl = kernel_role->root_label;
55388+ }
55389+ return;
55390+}
55391+
55392+#ifdef CONFIG_TASKSTATS
55393+int gr_is_taskstats_denied(int pid)
55394+{
55395+ struct task_struct *task;
55396+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55397+ const struct cred *cred;
55398+#endif
55399+ int ret = 0;
55400+
55401+ /* restrict taskstats viewing to un-chrooted root users
55402+ who have the 'view' subject flag if the RBAC system is enabled
55403+ */
55404+
55405+ rcu_read_lock();
55406+ read_lock(&tasklist_lock);
55407+ task = find_task_by_vpid(pid);
55408+ if (task) {
55409+#ifdef CONFIG_GRKERNSEC_CHROOT
55410+ if (proc_is_chrooted(task))
55411+ ret = -EACCES;
55412+#endif
55413+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55414+ cred = __task_cred(task);
55415+#ifdef CONFIG_GRKERNSEC_PROC_USER
55416+ if (cred->uid != 0)
55417+ ret = -EACCES;
55418+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55419+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55420+ ret = -EACCES;
55421+#endif
55422+#endif
55423+ if (gr_status & GR_READY) {
55424+ if (!(task->acl->mode & GR_VIEW))
55425+ ret = -EACCES;
55426+ }
55427+ } else
55428+ ret = -ENOENT;
55429+
55430+ read_unlock(&tasklist_lock);
55431+ rcu_read_unlock();
55432+
55433+ return ret;
55434+}
55435+#endif
55436+
55437+/* AUXV entries are filled via a descendant of search_binary_handler
55438+ after we've already applied the subject for the target
55439+*/
55440+int gr_acl_enable_at_secure(void)
55441+{
55442+ if (unlikely(!(gr_status & GR_READY)))
55443+ return 0;
55444+
55445+ if (current->acl->mode & GR_ATSECURE)
55446+ return 1;
55447+
55448+ return 0;
55449+}
55450+
55451+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55452+{
55453+ struct task_struct *task = current;
55454+ struct dentry *dentry = file->f_path.dentry;
55455+ struct vfsmount *mnt = file->f_path.mnt;
55456+ struct acl_object_label *obj, *tmp;
55457+ struct acl_subject_label *subj;
55458+ unsigned int bufsize;
55459+ int is_not_root;
55460+ char *path;
55461+ dev_t dev = __get_dev(dentry);
55462+
55463+ if (unlikely(!(gr_status & GR_READY)))
55464+ return 1;
55465+
55466+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55467+ return 1;
55468+
55469+ /* ignore Eric Biederman */
55470+ if (IS_PRIVATE(dentry->d_inode))
55471+ return 1;
55472+
55473+ subj = task->acl;
55474+ do {
55475+ obj = lookup_acl_obj_label(ino, dev, subj);
55476+ if (obj != NULL)
55477+ return (obj->mode & GR_FIND) ? 1 : 0;
55478+ } while ((subj = subj->parent_subject));
55479+
55480+ /* this is purely an optimization since we're looking for an object
55481+ for the directory we're doing a readdir on
55482+ if it's possible for any globbed object to match the entry we're
55483+ filling into the directory, then the object we find here will be
55484+ an anchor point with attached globbed objects
55485+ */
55486+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55487+ if (obj->globbed == NULL)
55488+ return (obj->mode & GR_FIND) ? 1 : 0;
55489+
55490+ is_not_root = ((obj->filename[0] == '/') &&
55491+ (obj->filename[1] == '\0')) ? 0 : 1;
55492+ bufsize = PAGE_SIZE - namelen - is_not_root;
55493+
55494+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55495+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55496+ return 1;
55497+
55498+ preempt_disable();
55499+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55500+ bufsize);
55501+
55502+ bufsize = strlen(path);
55503+
55504+ /* if base is "/", don't append an additional slash */
55505+ if (is_not_root)
55506+ *(path + bufsize) = '/';
55507+ memcpy(path + bufsize + is_not_root, name, namelen);
55508+ *(path + bufsize + namelen + is_not_root) = '\0';
55509+
55510+ tmp = obj->globbed;
55511+ while (tmp) {
55512+ if (!glob_match(tmp->filename, path)) {
55513+ preempt_enable();
55514+ return (tmp->mode & GR_FIND) ? 1 : 0;
55515+ }
55516+ tmp = tmp->next;
55517+ }
55518+ preempt_enable();
55519+ return (obj->mode & GR_FIND) ? 1 : 0;
55520+}
55521+
55522+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55523+EXPORT_SYMBOL(gr_acl_is_enabled);
55524+#endif
55525+EXPORT_SYMBOL(gr_learn_resource);
55526+EXPORT_SYMBOL(gr_set_kernel_label);
55527+#ifdef CONFIG_SECURITY
55528+EXPORT_SYMBOL(gr_check_user_change);
55529+EXPORT_SYMBOL(gr_check_group_change);
55530+#endif
55531+
55532diff -urNp linux-2.6.39.1/grsecurity/gracl_cap.c linux-2.6.39.1/grsecurity/gracl_cap.c
55533--- linux-2.6.39.1/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
55534+++ linux-2.6.39.1/grsecurity/gracl_cap.c 2011-05-22 19:41:42.000000000 -0400
55535@@ -0,0 +1,139 @@
55536+#include <linux/kernel.h>
55537+#include <linux/module.h>
55538+#include <linux/sched.h>
55539+#include <linux/gracl.h>
55540+#include <linux/grsecurity.h>
55541+#include <linux/grinternal.h>
55542+
55543+static const char *captab_log[] = {
55544+ "CAP_CHOWN",
55545+ "CAP_DAC_OVERRIDE",
55546+ "CAP_DAC_READ_SEARCH",
55547+ "CAP_FOWNER",
55548+ "CAP_FSETID",
55549+ "CAP_KILL",
55550+ "CAP_SETGID",
55551+ "CAP_SETUID",
55552+ "CAP_SETPCAP",
55553+ "CAP_LINUX_IMMUTABLE",
55554+ "CAP_NET_BIND_SERVICE",
55555+ "CAP_NET_BROADCAST",
55556+ "CAP_NET_ADMIN",
55557+ "CAP_NET_RAW",
55558+ "CAP_IPC_LOCK",
55559+ "CAP_IPC_OWNER",
55560+ "CAP_SYS_MODULE",
55561+ "CAP_SYS_RAWIO",
55562+ "CAP_SYS_CHROOT",
55563+ "CAP_SYS_PTRACE",
55564+ "CAP_SYS_PACCT",
55565+ "CAP_SYS_ADMIN",
55566+ "CAP_SYS_BOOT",
55567+ "CAP_SYS_NICE",
55568+ "CAP_SYS_RESOURCE",
55569+ "CAP_SYS_TIME",
55570+ "CAP_SYS_TTY_CONFIG",
55571+ "CAP_MKNOD",
55572+ "CAP_LEASE",
55573+ "CAP_AUDIT_WRITE",
55574+ "CAP_AUDIT_CONTROL",
55575+ "CAP_SETFCAP",
55576+ "CAP_MAC_OVERRIDE",
55577+ "CAP_MAC_ADMIN",
55578+ "CAP_SYSLOG"
55579+};
55580+
55581+EXPORT_SYMBOL(gr_is_capable);
55582+EXPORT_SYMBOL(gr_is_capable_nolog);
55583+
55584+int
55585+gr_is_capable(const int cap)
55586+{
55587+ struct task_struct *task = current;
55588+ const struct cred *cred = current_cred();
55589+ struct acl_subject_label *curracl;
55590+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55591+ kernel_cap_t cap_audit = __cap_empty_set;
55592+
55593+ if (!gr_acl_is_enabled())
55594+ return 1;
55595+
55596+ curracl = task->acl;
55597+
55598+ cap_drop = curracl->cap_lower;
55599+ cap_mask = curracl->cap_mask;
55600+ cap_audit = curracl->cap_invert_audit;
55601+
55602+ while ((curracl = curracl->parent_subject)) {
55603+ /* if the cap isn't specified in the current computed mask but is specified in the
55604+ current level subject, and is lowered in the current level subject, then add
55605+ it to the set of dropped capabilities
55606+ otherwise, add the current level subject's mask to the current computed mask
55607+ */
55608+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55609+ cap_raise(cap_mask, cap);
55610+ if (cap_raised(curracl->cap_lower, cap))
55611+ cap_raise(cap_drop, cap);
55612+ if (cap_raised(curracl->cap_invert_audit, cap))
55613+ cap_raise(cap_audit, cap);
55614+ }
55615+ }
55616+
55617+ if (!cap_raised(cap_drop, cap)) {
55618+ if (cap_raised(cap_audit, cap))
55619+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55620+ return 1;
55621+ }
55622+
55623+ curracl = task->acl;
55624+
55625+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55626+ && cap_raised(cred->cap_effective, cap)) {
55627+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55628+ task->role->roletype, cred->uid,
55629+ cred->gid, task->exec_file ?
55630+ gr_to_filename(task->exec_file->f_path.dentry,
55631+ task->exec_file->f_path.mnt) : curracl->filename,
55632+ curracl->filename, 0UL,
55633+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55634+ return 1;
55635+ }
55636+
55637+ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55638+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55639+ return 0;
55640+}
55641+
55642+int
55643+gr_is_capable_nolog(const int cap)
55644+{
55645+ struct acl_subject_label *curracl;
55646+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55647+
55648+ if (!gr_acl_is_enabled())
55649+ return 1;
55650+
55651+ curracl = current->acl;
55652+
55653+ cap_drop = curracl->cap_lower;
55654+ cap_mask = curracl->cap_mask;
55655+
55656+ while ((curracl = curracl->parent_subject)) {
55657+ /* if the cap isn't specified in the current computed mask but is specified in the
55658+ current level subject, and is lowered in the current level subject, then add
55659+ it to the set of dropped capabilities
55660+ otherwise, add the current level subject's mask to the current computed mask
55661+ */
55662+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55663+ cap_raise(cap_mask, cap);
55664+ if (cap_raised(curracl->cap_lower, cap))
55665+ cap_raise(cap_drop, cap);
55666+ }
55667+ }
55668+
55669+ if (!cap_raised(cap_drop, cap))
55670+ return 1;
55671+
55672+ return 0;
55673+}
55674+
55675diff -urNp linux-2.6.39.1/grsecurity/gracl_fs.c linux-2.6.39.1/grsecurity/gracl_fs.c
55676--- linux-2.6.39.1/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
55677+++ linux-2.6.39.1/grsecurity/gracl_fs.c 2011-05-22 19:41:42.000000000 -0400
55678@@ -0,0 +1,431 @@
55679+#include <linux/kernel.h>
55680+#include <linux/sched.h>
55681+#include <linux/types.h>
55682+#include <linux/fs.h>
55683+#include <linux/file.h>
55684+#include <linux/stat.h>
55685+#include <linux/grsecurity.h>
55686+#include <linux/grinternal.h>
55687+#include <linux/gracl.h>
55688+
55689+__u32
55690+gr_acl_handle_hidden_file(const struct dentry * dentry,
55691+ const struct vfsmount * mnt)
55692+{
55693+ __u32 mode;
55694+
55695+ if (unlikely(!dentry->d_inode))
55696+ return GR_FIND;
55697+
55698+ mode =
55699+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55700+
55701+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55702+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55703+ return mode;
55704+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55705+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55706+ return 0;
55707+ } else if (unlikely(!(mode & GR_FIND)))
55708+ return 0;
55709+
55710+ return GR_FIND;
55711+}
55712+
55713+__u32
55714+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55715+ const int fmode)
55716+{
55717+ __u32 reqmode = GR_FIND;
55718+ __u32 mode;
55719+
55720+ if (unlikely(!dentry->d_inode))
55721+ return reqmode;
55722+
55723+ if (unlikely(fmode & O_APPEND))
55724+ reqmode |= GR_APPEND;
55725+ else if (unlikely(fmode & FMODE_WRITE))
55726+ reqmode |= GR_WRITE;
55727+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55728+ reqmode |= GR_READ;
55729+ if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
55730+ reqmode &= ~GR_READ;
55731+ mode =
55732+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55733+ mnt);
55734+
55735+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55736+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55737+ reqmode & GR_READ ? " reading" : "",
55738+ reqmode & GR_WRITE ? " writing" : reqmode &
55739+ GR_APPEND ? " appending" : "");
55740+ return reqmode;
55741+ } else
55742+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55743+ {
55744+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55745+ reqmode & GR_READ ? " reading" : "",
55746+ reqmode & GR_WRITE ? " writing" : reqmode &
55747+ GR_APPEND ? " appending" : "");
55748+ return 0;
55749+ } else if (unlikely((mode & reqmode) != reqmode))
55750+ return 0;
55751+
55752+ return reqmode;
55753+}
55754+
55755+__u32
55756+gr_acl_handle_creat(const struct dentry * dentry,
55757+ const struct dentry * p_dentry,
55758+ const struct vfsmount * p_mnt, const int fmode,
55759+ const int imode)
55760+{
55761+ __u32 reqmode = GR_WRITE | GR_CREATE;
55762+ __u32 mode;
55763+
55764+ if (unlikely(fmode & O_APPEND))
55765+ reqmode |= GR_APPEND;
55766+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55767+ reqmode |= GR_READ;
55768+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
55769+ reqmode |= GR_SETID;
55770+
55771+ mode =
55772+ gr_check_create(dentry, p_dentry, p_mnt,
55773+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55774+
55775+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55776+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55777+ reqmode & GR_READ ? " reading" : "",
55778+ reqmode & GR_WRITE ? " writing" : reqmode &
55779+ GR_APPEND ? " appending" : "");
55780+ return reqmode;
55781+ } else
55782+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55783+ {
55784+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55785+ reqmode & GR_READ ? " reading" : "",
55786+ reqmode & GR_WRITE ? " writing" : reqmode &
55787+ GR_APPEND ? " appending" : "");
55788+ return 0;
55789+ } else if (unlikely((mode & reqmode) != reqmode))
55790+ return 0;
55791+
55792+ return reqmode;
55793+}
55794+
55795+__u32
55796+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55797+ const int fmode)
55798+{
55799+ __u32 mode, reqmode = GR_FIND;
55800+
55801+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55802+ reqmode |= GR_EXEC;
55803+ if (fmode & S_IWOTH)
55804+ reqmode |= GR_WRITE;
55805+ if (fmode & S_IROTH)
55806+ reqmode |= GR_READ;
55807+
55808+ mode =
55809+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55810+ mnt);
55811+
55812+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55813+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55814+ reqmode & GR_READ ? " reading" : "",
55815+ reqmode & GR_WRITE ? " writing" : "",
55816+ reqmode & GR_EXEC ? " executing" : "");
55817+ return reqmode;
55818+ } else
55819+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55820+ {
55821+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55822+ reqmode & GR_READ ? " reading" : "",
55823+ reqmode & GR_WRITE ? " writing" : "",
55824+ reqmode & GR_EXEC ? " executing" : "");
55825+ return 0;
55826+ } else if (unlikely((mode & reqmode) != reqmode))
55827+ return 0;
55828+
55829+ return reqmode;
55830+}
55831+
55832+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55833+{
55834+ __u32 mode;
55835+
55836+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55837+
55838+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55839+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55840+ return mode;
55841+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55842+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55843+ return 0;
55844+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55845+ return 0;
55846+
55847+ return (reqmode);
55848+}
55849+
55850+__u32
55851+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55852+{
55853+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55854+}
55855+
55856+__u32
55857+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55858+{
55859+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55860+}
55861+
55862+__u32
55863+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55864+{
55865+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55866+}
55867+
55868+__u32
55869+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55870+{
55871+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55872+}
55873+
55874+__u32
55875+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55876+ mode_t mode)
55877+{
55878+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55879+ return 1;
55880+
55881+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55882+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55883+ GR_FCHMOD_ACL_MSG);
55884+ } else {
55885+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55886+ }
55887+}
55888+
55889+__u32
55890+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55891+ mode_t mode)
55892+{
55893+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55894+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55895+ GR_CHMOD_ACL_MSG);
55896+ } else {
55897+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55898+ }
55899+}
55900+
55901+__u32
55902+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55903+{
55904+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55905+}
55906+
55907+__u32
55908+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55909+{
55910+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55911+}
55912+
55913+__u32
55914+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55915+{
55916+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55917+}
55918+
55919+__u32
55920+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55921+{
55922+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55923+ GR_UNIXCONNECT_ACL_MSG);
55924+}
55925+
55926+/* hardlinks require at minimum create permission,
55927+ any additional privilege required is based on the
55928+ privilege of the file being linked to
55929+*/
55930+__u32
55931+gr_acl_handle_link(const struct dentry * new_dentry,
55932+ const struct dentry * parent_dentry,
55933+ const struct vfsmount * parent_mnt,
55934+ const struct dentry * old_dentry,
55935+ const struct vfsmount * old_mnt, const char *to)
55936+{
55937+ __u32 mode;
55938+ __u32 needmode = GR_CREATE | GR_LINK;
55939+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55940+
55941+ mode =
55942+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55943+ old_mnt);
55944+
55945+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55946+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55947+ return mode;
55948+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55949+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55950+ return 0;
55951+ } else if (unlikely((mode & needmode) != needmode))
55952+ return 0;
55953+
55954+ return 1;
55955+}
55956+
55957+__u32
55958+gr_acl_handle_symlink(const struct dentry * new_dentry,
55959+ const struct dentry * parent_dentry,
55960+ const struct vfsmount * parent_mnt, const char *from)
55961+{
55962+ __u32 needmode = GR_WRITE | GR_CREATE;
55963+ __u32 mode;
55964+
55965+ mode =
55966+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55967+ GR_CREATE | GR_AUDIT_CREATE |
55968+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55969+
55970+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55971+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55972+ return mode;
55973+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55974+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55975+ return 0;
55976+ } else if (unlikely((mode & needmode) != needmode))
55977+ return 0;
55978+
55979+ return (GR_WRITE | GR_CREATE);
55980+}
55981+
55982+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)
55983+{
55984+ __u32 mode;
55985+
55986+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55987+
55988+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55989+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55990+ return mode;
55991+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55992+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55993+ return 0;
55994+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55995+ return 0;
55996+
55997+ return (reqmode);
55998+}
55999+
56000+__u32
56001+gr_acl_handle_mknod(const struct dentry * new_dentry,
56002+ const struct dentry * parent_dentry,
56003+ const struct vfsmount * parent_mnt,
56004+ const int mode)
56005+{
56006+ __u32 reqmode = GR_WRITE | GR_CREATE;
56007+ if (unlikely(mode & (S_ISUID | S_ISGID)))
56008+ reqmode |= GR_SETID;
56009+
56010+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56011+ reqmode, GR_MKNOD_ACL_MSG);
56012+}
56013+
56014+__u32
56015+gr_acl_handle_mkdir(const struct dentry *new_dentry,
56016+ const struct dentry *parent_dentry,
56017+ const struct vfsmount *parent_mnt)
56018+{
56019+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56020+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56021+}
56022+
56023+#define RENAME_CHECK_SUCCESS(old, new) \
56024+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56025+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56026+
56027+int
56028+gr_acl_handle_rename(struct dentry *new_dentry,
56029+ struct dentry *parent_dentry,
56030+ const struct vfsmount *parent_mnt,
56031+ struct dentry *old_dentry,
56032+ struct inode *old_parent_inode,
56033+ struct vfsmount *old_mnt, const char *newname)
56034+{
56035+ __u32 comp1, comp2;
56036+ int error = 0;
56037+
56038+ if (unlikely(!gr_acl_is_enabled()))
56039+ return 0;
56040+
56041+ if (!new_dentry->d_inode) {
56042+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56043+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56044+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56045+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56046+ GR_DELETE | GR_AUDIT_DELETE |
56047+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56048+ GR_SUPPRESS, old_mnt);
56049+ } else {
56050+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56051+ GR_CREATE | GR_DELETE |
56052+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56053+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56054+ GR_SUPPRESS, parent_mnt);
56055+ comp2 =
56056+ gr_search_file(old_dentry,
56057+ GR_READ | GR_WRITE | GR_AUDIT_READ |
56058+ GR_DELETE | GR_AUDIT_DELETE |
56059+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56060+ }
56061+
56062+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56063+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56064+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56065+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56066+ && !(comp2 & GR_SUPPRESS)) {
56067+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56068+ error = -EACCES;
56069+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56070+ error = -EACCES;
56071+
56072+ return error;
56073+}
56074+
56075+void
56076+gr_acl_handle_exit(void)
56077+{
56078+ u16 id;
56079+ char *rolename;
56080+ struct file *exec_file;
56081+
56082+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56083+ !(current->role->roletype & GR_ROLE_PERSIST))) {
56084+ id = current->acl_role_id;
56085+ rolename = current->role->rolename;
56086+ gr_set_acls(1);
56087+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56088+ }
56089+
56090+ write_lock(&grsec_exec_file_lock);
56091+ exec_file = current->exec_file;
56092+ current->exec_file = NULL;
56093+ write_unlock(&grsec_exec_file_lock);
56094+
56095+ if (exec_file)
56096+ fput(exec_file);
56097+}
56098+
56099+int
56100+gr_acl_handle_procpidmem(const struct task_struct *task)
56101+{
56102+ if (unlikely(!gr_acl_is_enabled()))
56103+ return 0;
56104+
56105+ if (task != current && task->acl->mode & GR_PROTPROCFD)
56106+ return -EACCES;
56107+
56108+ return 0;
56109+}
56110diff -urNp linux-2.6.39.1/grsecurity/gracl_ip.c linux-2.6.39.1/grsecurity/gracl_ip.c
56111--- linux-2.6.39.1/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
56112+++ linux-2.6.39.1/grsecurity/gracl_ip.c 2011-05-22 22:47:31.000000000 -0400
56113@@ -0,0 +1,381 @@
56114+#include <linux/kernel.h>
56115+#include <asm/uaccess.h>
56116+#include <asm/errno.h>
56117+#include <net/sock.h>
56118+#include <linux/file.h>
56119+#include <linux/fs.h>
56120+#include <linux/net.h>
56121+#include <linux/in.h>
56122+#include <linux/skbuff.h>
56123+#include <linux/ip.h>
56124+#include <linux/udp.h>
56125+#include <linux/types.h>
56126+#include <linux/sched.h>
56127+#include <linux/netdevice.h>
56128+#include <linux/inetdevice.h>
56129+#include <linux/gracl.h>
56130+#include <linux/grsecurity.h>
56131+#include <linux/grinternal.h>
56132+
56133+#define GR_BIND 0x01
56134+#define GR_CONNECT 0x02
56135+#define GR_INVERT 0x04
56136+#define GR_BINDOVERRIDE 0x08
56137+#define GR_CONNECTOVERRIDE 0x10
56138+#define GR_SOCK_FAMILY 0x20
56139+
56140+static const char * gr_protocols[IPPROTO_MAX] = {
56141+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56142+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56143+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56144+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56145+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56146+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56147+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56148+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56149+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56150+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56151+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56152+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56153+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56154+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56155+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56156+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56157+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56158+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56159+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56160+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56161+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56162+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56163+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56164+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56165+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56166+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56167+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56168+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56169+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56170+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56171+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56172+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56173+ };
56174+
56175+static const char * gr_socktypes[SOCK_MAX] = {
56176+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56177+ "unknown:7", "unknown:8", "unknown:9", "packet"
56178+ };
56179+
56180+static const char * gr_sockfamilies[AF_MAX+1] = {
56181+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56182+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56183+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56184+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56185+ };
56186+
56187+const char *
56188+gr_proto_to_name(unsigned char proto)
56189+{
56190+ return gr_protocols[proto];
56191+}
56192+
56193+const char *
56194+gr_socktype_to_name(unsigned char type)
56195+{
56196+ return gr_socktypes[type];
56197+}
56198+
56199+const char *
56200+gr_sockfamily_to_name(unsigned char family)
56201+{
56202+ return gr_sockfamilies[family];
56203+}
56204+
56205+int
56206+gr_search_socket(const int domain, const int type, const int protocol)
56207+{
56208+ struct acl_subject_label *curr;
56209+ const struct cred *cred = current_cred();
56210+
56211+ if (unlikely(!gr_acl_is_enabled()))
56212+ goto exit;
56213+
56214+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56215+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56216+ goto exit; // let the kernel handle it
56217+
56218+ curr = current->acl;
56219+
56220+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56221+ /* the family is allowed, if this is PF_INET allow it only if
56222+ the extra sock type/protocol checks pass */
56223+ if (domain == PF_INET)
56224+ goto inet_check;
56225+ goto exit;
56226+ } else {
56227+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56228+ __u32 fakeip = 0;
56229+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56230+ current->role->roletype, cred->uid,
56231+ cred->gid, current->exec_file ?
56232+ gr_to_filename(current->exec_file->f_path.dentry,
56233+ current->exec_file->f_path.mnt) :
56234+ curr->filename, curr->filename,
56235+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56236+ &current->signal->saved_ip);
56237+ goto exit;
56238+ }
56239+ goto exit_fail;
56240+ }
56241+
56242+inet_check:
56243+ /* the rest of this checking is for IPv4 only */
56244+ if (!curr->ips)
56245+ goto exit;
56246+
56247+ if ((curr->ip_type & (1 << type)) &&
56248+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56249+ goto exit;
56250+
56251+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56252+ /* we don't place acls on raw sockets , and sometimes
56253+ dgram/ip sockets are opened for ioctl and not
56254+ bind/connect, so we'll fake a bind learn log */
56255+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56256+ __u32 fakeip = 0;
56257+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56258+ current->role->roletype, cred->uid,
56259+ cred->gid, current->exec_file ?
56260+ gr_to_filename(current->exec_file->f_path.dentry,
56261+ current->exec_file->f_path.mnt) :
56262+ curr->filename, curr->filename,
56263+ &fakeip, 0, type,
56264+ protocol, GR_CONNECT, &current->signal->saved_ip);
56265+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56266+ __u32 fakeip = 0;
56267+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56268+ current->role->roletype, cred->uid,
56269+ cred->gid, current->exec_file ?
56270+ gr_to_filename(current->exec_file->f_path.dentry,
56271+ current->exec_file->f_path.mnt) :
56272+ curr->filename, curr->filename,
56273+ &fakeip, 0, type,
56274+ protocol, GR_BIND, &current->signal->saved_ip);
56275+ }
56276+ /* we'll log when they use connect or bind */
56277+ goto exit;
56278+ }
56279+
56280+exit_fail:
56281+ if (domain == PF_INET)
56282+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56283+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56284+ else
56285+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56286+ gr_socktype_to_name(type), protocol);
56287+
56288+ return 0;
56289+exit:
56290+ return 1;
56291+}
56292+
56293+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)
56294+{
56295+ if ((ip->mode & mode) &&
56296+ (ip_port >= ip->low) &&
56297+ (ip_port <= ip->high) &&
56298+ ((ntohl(ip_addr) & our_netmask) ==
56299+ (ntohl(our_addr) & our_netmask))
56300+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56301+ && (ip->type & (1 << type))) {
56302+ if (ip->mode & GR_INVERT)
56303+ return 2; // specifically denied
56304+ else
56305+ return 1; // allowed
56306+ }
56307+
56308+ return 0; // not specifically allowed, may continue parsing
56309+}
56310+
56311+static int
56312+gr_search_connectbind(const int full_mode, struct sock *sk,
56313+ struct sockaddr_in *addr, const int type)
56314+{
56315+ char iface[IFNAMSIZ] = {0};
56316+ struct acl_subject_label *curr;
56317+ struct acl_ip_label *ip;
56318+ struct inet_sock *isk;
56319+ struct net_device *dev;
56320+ struct in_device *idev;
56321+ unsigned long i;
56322+ int ret;
56323+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56324+ __u32 ip_addr = 0;
56325+ __u32 our_addr;
56326+ __u32 our_netmask;
56327+ char *p;
56328+ __u16 ip_port = 0;
56329+ const struct cred *cred = current_cred();
56330+
56331+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56332+ return 0;
56333+
56334+ curr = current->acl;
56335+ isk = inet_sk(sk);
56336+
56337+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56338+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56339+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56340+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56341+ struct sockaddr_in saddr;
56342+ int err;
56343+
56344+ saddr.sin_family = AF_INET;
56345+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56346+ saddr.sin_port = isk->inet_sport;
56347+
56348+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56349+ if (err)
56350+ return err;
56351+
56352+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56353+ if (err)
56354+ return err;
56355+ }
56356+
56357+ if (!curr->ips)
56358+ return 0;
56359+
56360+ ip_addr = addr->sin_addr.s_addr;
56361+ ip_port = ntohs(addr->sin_port);
56362+
56363+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56364+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56365+ current->role->roletype, cred->uid,
56366+ cred->gid, current->exec_file ?
56367+ gr_to_filename(current->exec_file->f_path.dentry,
56368+ current->exec_file->f_path.mnt) :
56369+ curr->filename, curr->filename,
56370+ &ip_addr, ip_port, type,
56371+ sk->sk_protocol, mode, &current->signal->saved_ip);
56372+ return 0;
56373+ }
56374+
56375+ for (i = 0; i < curr->ip_num; i++) {
56376+ ip = *(curr->ips + i);
56377+ if (ip->iface != NULL) {
56378+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56379+ p = strchr(iface, ':');
56380+ if (p != NULL)
56381+ *p = '\0';
56382+ dev = dev_get_by_name(sock_net(sk), iface);
56383+ if (dev == NULL)
56384+ continue;
56385+ idev = in_dev_get(dev);
56386+ if (idev == NULL) {
56387+ dev_put(dev);
56388+ continue;
56389+ }
56390+ rcu_read_lock();
56391+ for_ifa(idev) {
56392+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56393+ our_addr = ifa->ifa_address;
56394+ our_netmask = 0xffffffff;
56395+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56396+ if (ret == 1) {
56397+ rcu_read_unlock();
56398+ in_dev_put(idev);
56399+ dev_put(dev);
56400+ return 0;
56401+ } else if (ret == 2) {
56402+ rcu_read_unlock();
56403+ in_dev_put(idev);
56404+ dev_put(dev);
56405+ goto denied;
56406+ }
56407+ }
56408+ } endfor_ifa(idev);
56409+ rcu_read_unlock();
56410+ in_dev_put(idev);
56411+ dev_put(dev);
56412+ } else {
56413+ our_addr = ip->addr;
56414+ our_netmask = ip->netmask;
56415+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56416+ if (ret == 1)
56417+ return 0;
56418+ else if (ret == 2)
56419+ goto denied;
56420+ }
56421+ }
56422+
56423+denied:
56424+ if (mode == GR_BIND)
56425+ 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));
56426+ else if (mode == GR_CONNECT)
56427+ 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));
56428+
56429+ return -EACCES;
56430+}
56431+
56432+int
56433+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56434+{
56435+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56436+}
56437+
56438+int
56439+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56440+{
56441+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56442+}
56443+
56444+int gr_search_listen(struct socket *sock)
56445+{
56446+ struct sock *sk = sock->sk;
56447+ struct sockaddr_in addr;
56448+
56449+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56450+ addr.sin_port = inet_sk(sk)->inet_sport;
56451+
56452+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56453+}
56454+
56455+int gr_search_accept(struct socket *sock)
56456+{
56457+ struct sock *sk = sock->sk;
56458+ struct sockaddr_in addr;
56459+
56460+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56461+ addr.sin_port = inet_sk(sk)->inet_sport;
56462+
56463+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56464+}
56465+
56466+int
56467+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56468+{
56469+ if (addr)
56470+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56471+ else {
56472+ struct sockaddr_in sin;
56473+ const struct inet_sock *inet = inet_sk(sk);
56474+
56475+ sin.sin_addr.s_addr = inet->inet_daddr;
56476+ sin.sin_port = inet->inet_dport;
56477+
56478+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56479+ }
56480+}
56481+
56482+int
56483+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56484+{
56485+ struct sockaddr_in sin;
56486+
56487+ if (unlikely(skb->len < sizeof (struct udphdr)))
56488+ return 0; // skip this packet
56489+
56490+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56491+ sin.sin_port = udp_hdr(skb)->source;
56492+
56493+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56494+}
56495diff -urNp linux-2.6.39.1/grsecurity/gracl_learn.c linux-2.6.39.1/grsecurity/gracl_learn.c
56496--- linux-2.6.39.1/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
56497+++ linux-2.6.39.1/grsecurity/gracl_learn.c 2011-05-22 22:47:45.000000000 -0400
56498@@ -0,0 +1,210 @@
56499+#include <linux/kernel.h>
56500+#include <linux/mm.h>
56501+#include <linux/sched.h>
56502+#include <linux/poll.h>
56503+#include <linux/string.h>
56504+#include <linux/file.h>
56505+#include <linux/types.h>
56506+#include <linux/vmalloc.h>
56507+#include <linux/grinternal.h>
56508+
56509+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56510+ size_t count, loff_t *ppos);
56511+extern int gr_acl_is_enabled(void);
56512+
56513+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56514+static int gr_learn_attached;
56515+
56516+/* use a 512k buffer */
56517+#define LEARN_BUFFER_SIZE (512 * 1024)
56518+
56519+static DEFINE_SPINLOCK(gr_learn_lock);
56520+static DEFINE_MUTEX(gr_learn_user_mutex);
56521+
56522+/* we need to maintain two buffers, so that the kernel context of grlearn
56523+ uses a semaphore around the userspace copying, and the other kernel contexts
56524+ use a spinlock when copying into the buffer, since they cannot sleep
56525+*/
56526+static char *learn_buffer;
56527+static char *learn_buffer_user;
56528+static int learn_buffer_len;
56529+static int learn_buffer_user_len;
56530+
56531+static ssize_t
56532+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56533+{
56534+ DECLARE_WAITQUEUE(wait, current);
56535+ ssize_t retval = 0;
56536+
56537+ add_wait_queue(&learn_wait, &wait);
56538+ set_current_state(TASK_INTERRUPTIBLE);
56539+ do {
56540+ mutex_lock(&gr_learn_user_mutex);
56541+ spin_lock(&gr_learn_lock);
56542+ if (learn_buffer_len)
56543+ break;
56544+ spin_unlock(&gr_learn_lock);
56545+ mutex_unlock(&gr_learn_user_mutex);
56546+ if (file->f_flags & O_NONBLOCK) {
56547+ retval = -EAGAIN;
56548+ goto out;
56549+ }
56550+ if (signal_pending(current)) {
56551+ retval = -ERESTARTSYS;
56552+ goto out;
56553+ }
56554+
56555+ schedule();
56556+ } while (1);
56557+
56558+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56559+ learn_buffer_user_len = learn_buffer_len;
56560+ retval = learn_buffer_len;
56561+ learn_buffer_len = 0;
56562+
56563+ spin_unlock(&gr_learn_lock);
56564+
56565+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56566+ retval = -EFAULT;
56567+
56568+ mutex_unlock(&gr_learn_user_mutex);
56569+out:
56570+ set_current_state(TASK_RUNNING);
56571+ remove_wait_queue(&learn_wait, &wait);
56572+ return retval;
56573+}
56574+
56575+static unsigned int
56576+poll_learn(struct file * file, poll_table * wait)
56577+{
56578+ poll_wait(file, &learn_wait, wait);
56579+
56580+ if (learn_buffer_len)
56581+ return (POLLIN | POLLRDNORM);
56582+
56583+ return 0;
56584+}
56585+
56586+void
56587+gr_clear_learn_entries(void)
56588+{
56589+ char *tmp;
56590+
56591+ mutex_lock(&gr_learn_user_mutex);
56592+ if (learn_buffer != NULL) {
56593+ spin_lock(&gr_learn_lock);
56594+ tmp = learn_buffer;
56595+ learn_buffer = NULL;
56596+ spin_unlock(&gr_learn_lock);
56597+ vfree(learn_buffer);
56598+ }
56599+ if (learn_buffer_user != NULL) {
56600+ vfree(learn_buffer_user);
56601+ learn_buffer_user = NULL;
56602+ }
56603+ learn_buffer_len = 0;
56604+ mutex_unlock(&gr_learn_user_mutex);
56605+
56606+ return;
56607+}
56608+
56609+void
56610+gr_add_learn_entry(const char *fmt, ...)
56611+{
56612+ va_list args;
56613+ unsigned int len;
56614+
56615+ if (!gr_learn_attached)
56616+ return;
56617+
56618+ spin_lock(&gr_learn_lock);
56619+
56620+ /* leave a gap at the end so we know when it's "full" but don't have to
56621+ compute the exact length of the string we're trying to append
56622+ */
56623+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56624+ spin_unlock(&gr_learn_lock);
56625+ wake_up_interruptible(&learn_wait);
56626+ return;
56627+ }
56628+ if (learn_buffer == NULL) {
56629+ spin_unlock(&gr_learn_lock);
56630+ return;
56631+ }
56632+
56633+ va_start(args, fmt);
56634+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56635+ va_end(args);
56636+
56637+ learn_buffer_len += len + 1;
56638+
56639+ spin_unlock(&gr_learn_lock);
56640+ wake_up_interruptible(&learn_wait);
56641+
56642+ return;
56643+}
56644+
56645+static int
56646+open_learn(struct inode *inode, struct file *file)
56647+{
56648+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56649+ return -EBUSY;
56650+ if (file->f_mode & FMODE_READ) {
56651+ int retval = 0;
56652+ mutex_lock(&gr_learn_user_mutex);
56653+ if (learn_buffer == NULL)
56654+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56655+ if (learn_buffer_user == NULL)
56656+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56657+ if (learn_buffer == NULL) {
56658+ retval = -ENOMEM;
56659+ goto out_error;
56660+ }
56661+ if (learn_buffer_user == NULL) {
56662+ retval = -ENOMEM;
56663+ goto out_error;
56664+ }
56665+ learn_buffer_len = 0;
56666+ learn_buffer_user_len = 0;
56667+ gr_learn_attached = 1;
56668+out_error:
56669+ mutex_unlock(&gr_learn_user_mutex);
56670+ return retval;
56671+ }
56672+ return 0;
56673+}
56674+
56675+static int
56676+close_learn(struct inode *inode, struct file *file)
56677+{
56678+ char *tmp;
56679+
56680+ if (file->f_mode & FMODE_READ) {
56681+ mutex_lock(&gr_learn_user_mutex);
56682+ if (learn_buffer != NULL) {
56683+ spin_lock(&gr_learn_lock);
56684+ tmp = learn_buffer;
56685+ learn_buffer = NULL;
56686+ spin_unlock(&gr_learn_lock);
56687+ vfree(tmp);
56688+ }
56689+ if (learn_buffer_user != NULL) {
56690+ vfree(learn_buffer_user);
56691+ learn_buffer_user = NULL;
56692+ }
56693+ learn_buffer_len = 0;
56694+ learn_buffer_user_len = 0;
56695+ gr_learn_attached = 0;
56696+ mutex_unlock(&gr_learn_user_mutex);
56697+ }
56698+
56699+ return 0;
56700+}
56701+
56702+const struct file_operations grsec_fops = {
56703+ .read = read_learn,
56704+ .write = write_grsec_handler,
56705+ .open = open_learn,
56706+ .release = close_learn,
56707+ .poll = poll_learn,
56708+};
56709diff -urNp linux-2.6.39.1/grsecurity/gracl_res.c linux-2.6.39.1/grsecurity/gracl_res.c
56710--- linux-2.6.39.1/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
56711+++ linux-2.6.39.1/grsecurity/gracl_res.c 2011-05-22 19:41:42.000000000 -0400
56712@@ -0,0 +1,68 @@
56713+#include <linux/kernel.h>
56714+#include <linux/sched.h>
56715+#include <linux/gracl.h>
56716+#include <linux/grinternal.h>
56717+
56718+static const char *restab_log[] = {
56719+ [RLIMIT_CPU] = "RLIMIT_CPU",
56720+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56721+ [RLIMIT_DATA] = "RLIMIT_DATA",
56722+ [RLIMIT_STACK] = "RLIMIT_STACK",
56723+ [RLIMIT_CORE] = "RLIMIT_CORE",
56724+ [RLIMIT_RSS] = "RLIMIT_RSS",
56725+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56726+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56727+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56728+ [RLIMIT_AS] = "RLIMIT_AS",
56729+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56730+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56731+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56732+ [RLIMIT_NICE] = "RLIMIT_NICE",
56733+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56734+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56735+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56736+};
56737+
56738+void
56739+gr_log_resource(const struct task_struct *task,
56740+ const int res, const unsigned long wanted, const int gt)
56741+{
56742+ const struct cred *cred;
56743+ unsigned long rlim;
56744+
56745+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56746+ return;
56747+
56748+ // not yet supported resource
56749+ if (unlikely(!restab_log[res]))
56750+ return;
56751+
56752+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56753+ rlim = task_rlimit_max(task, res);
56754+ else
56755+ rlim = task_rlimit(task, res);
56756+
56757+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56758+ return;
56759+
56760+ rcu_read_lock();
56761+ cred = __task_cred(task);
56762+
56763+ if (res == RLIMIT_NPROC &&
56764+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56765+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56766+ goto out_rcu_unlock;
56767+ else if (res == RLIMIT_MEMLOCK &&
56768+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56769+ goto out_rcu_unlock;
56770+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56771+ goto out_rcu_unlock;
56772+ rcu_read_unlock();
56773+
56774+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56775+
56776+ return;
56777+out_rcu_unlock:
56778+ rcu_read_unlock();
56779+ return;
56780+}
56781diff -urNp linux-2.6.39.1/grsecurity/gracl_segv.c linux-2.6.39.1/grsecurity/gracl_segv.c
56782--- linux-2.6.39.1/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
56783+++ linux-2.6.39.1/grsecurity/gracl_segv.c 2011-05-22 22:47:39.000000000 -0400
56784@@ -0,0 +1,299 @@
56785+#include <linux/kernel.h>
56786+#include <linux/mm.h>
56787+#include <asm/uaccess.h>
56788+#include <asm/errno.h>
56789+#include <asm/mman.h>
56790+#include <net/sock.h>
56791+#include <linux/file.h>
56792+#include <linux/fs.h>
56793+#include <linux/net.h>
56794+#include <linux/in.h>
56795+#include <linux/slab.h>
56796+#include <linux/types.h>
56797+#include <linux/sched.h>
56798+#include <linux/timer.h>
56799+#include <linux/gracl.h>
56800+#include <linux/grsecurity.h>
56801+#include <linux/grinternal.h>
56802+
56803+static struct crash_uid *uid_set;
56804+static unsigned short uid_used;
56805+static DEFINE_SPINLOCK(gr_uid_lock);
56806+extern rwlock_t gr_inode_lock;
56807+extern struct acl_subject_label *
56808+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56809+ struct acl_role_label *role);
56810+
56811+#ifdef CONFIG_BTRFS_FS
56812+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56813+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56814+#endif
56815+
56816+static inline dev_t __get_dev(const struct dentry *dentry)
56817+{
56818+#ifdef CONFIG_BTRFS_FS
56819+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56820+ return get_btrfs_dev_from_inode(dentry->d_inode);
56821+ else
56822+#endif
56823+ return dentry->d_inode->i_sb->s_dev;
56824+}
56825+
56826+int
56827+gr_init_uidset(void)
56828+{
56829+ uid_set =
56830+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56831+ uid_used = 0;
56832+
56833+ return uid_set ? 1 : 0;
56834+}
56835+
56836+void
56837+gr_free_uidset(void)
56838+{
56839+ if (uid_set)
56840+ kfree(uid_set);
56841+
56842+ return;
56843+}
56844+
56845+int
56846+gr_find_uid(const uid_t uid)
56847+{
56848+ struct crash_uid *tmp = uid_set;
56849+ uid_t buid;
56850+ int low = 0, high = uid_used - 1, mid;
56851+
56852+ while (high >= low) {
56853+ mid = (low + high) >> 1;
56854+ buid = tmp[mid].uid;
56855+ if (buid == uid)
56856+ return mid;
56857+ if (buid > uid)
56858+ high = mid - 1;
56859+ if (buid < uid)
56860+ low = mid + 1;
56861+ }
56862+
56863+ return -1;
56864+}
56865+
56866+static __inline__ void
56867+gr_insertsort(void)
56868+{
56869+ unsigned short i, j;
56870+ struct crash_uid index;
56871+
56872+ for (i = 1; i < uid_used; i++) {
56873+ index = uid_set[i];
56874+ j = i;
56875+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56876+ uid_set[j] = uid_set[j - 1];
56877+ j--;
56878+ }
56879+ uid_set[j] = index;
56880+ }
56881+
56882+ return;
56883+}
56884+
56885+static __inline__ void
56886+gr_insert_uid(const uid_t uid, const unsigned long expires)
56887+{
56888+ int loc;
56889+
56890+ if (uid_used == GR_UIDTABLE_MAX)
56891+ return;
56892+
56893+ loc = gr_find_uid(uid);
56894+
56895+ if (loc >= 0) {
56896+ uid_set[loc].expires = expires;
56897+ return;
56898+ }
56899+
56900+ uid_set[uid_used].uid = uid;
56901+ uid_set[uid_used].expires = expires;
56902+ uid_used++;
56903+
56904+ gr_insertsort();
56905+
56906+ return;
56907+}
56908+
56909+void
56910+gr_remove_uid(const unsigned short loc)
56911+{
56912+ unsigned short i;
56913+
56914+ for (i = loc + 1; i < uid_used; i++)
56915+ uid_set[i - 1] = uid_set[i];
56916+
56917+ uid_used--;
56918+
56919+ return;
56920+}
56921+
56922+int
56923+gr_check_crash_uid(const uid_t uid)
56924+{
56925+ int loc;
56926+ int ret = 0;
56927+
56928+ if (unlikely(!gr_acl_is_enabled()))
56929+ return 0;
56930+
56931+ spin_lock(&gr_uid_lock);
56932+ loc = gr_find_uid(uid);
56933+
56934+ if (loc < 0)
56935+ goto out_unlock;
56936+
56937+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56938+ gr_remove_uid(loc);
56939+ else
56940+ ret = 1;
56941+
56942+out_unlock:
56943+ spin_unlock(&gr_uid_lock);
56944+ return ret;
56945+}
56946+
56947+static __inline__ int
56948+proc_is_setxid(const struct cred *cred)
56949+{
56950+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
56951+ cred->uid != cred->fsuid)
56952+ return 1;
56953+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56954+ cred->gid != cred->fsgid)
56955+ return 1;
56956+
56957+ return 0;
56958+}
56959+
56960+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56961+
56962+void
56963+gr_handle_crash(struct task_struct *task, const int sig)
56964+{
56965+ struct acl_subject_label *curr;
56966+ struct acl_subject_label *curr2;
56967+ struct task_struct *tsk, *tsk2;
56968+ const struct cred *cred;
56969+ const struct cred *cred2;
56970+
56971+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56972+ return;
56973+
56974+ if (unlikely(!gr_acl_is_enabled()))
56975+ return;
56976+
56977+ curr = task->acl;
56978+
56979+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56980+ return;
56981+
56982+ if (time_before_eq(curr->expires, get_seconds())) {
56983+ curr->expires = 0;
56984+ curr->crashes = 0;
56985+ }
56986+
56987+ curr->crashes++;
56988+
56989+ if (!curr->expires)
56990+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56991+
56992+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56993+ time_after(curr->expires, get_seconds())) {
56994+ rcu_read_lock();
56995+ cred = __task_cred(task);
56996+ if (cred->uid && proc_is_setxid(cred)) {
56997+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56998+ spin_lock(&gr_uid_lock);
56999+ gr_insert_uid(cred->uid, curr->expires);
57000+ spin_unlock(&gr_uid_lock);
57001+ curr->expires = 0;
57002+ curr->crashes = 0;
57003+ read_lock(&tasklist_lock);
57004+ do_each_thread(tsk2, tsk) {
57005+ cred2 = __task_cred(tsk);
57006+ if (tsk != task && cred2->uid == cred->uid)
57007+ gr_fake_force_sig(SIGKILL, tsk);
57008+ } while_each_thread(tsk2, tsk);
57009+ read_unlock(&tasklist_lock);
57010+ } else {
57011+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57012+ read_lock(&tasklist_lock);
57013+ do_each_thread(tsk2, tsk) {
57014+ if (likely(tsk != task)) {
57015+ curr2 = tsk->acl;
57016+
57017+ if (curr2->device == curr->device &&
57018+ curr2->inode == curr->inode)
57019+ gr_fake_force_sig(SIGKILL, tsk);
57020+ }
57021+ } while_each_thread(tsk2, tsk);
57022+ read_unlock(&tasklist_lock);
57023+ }
57024+ rcu_read_unlock();
57025+ }
57026+
57027+ return;
57028+}
57029+
57030+int
57031+gr_check_crash_exec(const struct file *filp)
57032+{
57033+ struct acl_subject_label *curr;
57034+
57035+ if (unlikely(!gr_acl_is_enabled()))
57036+ return 0;
57037+
57038+ read_lock(&gr_inode_lock);
57039+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57040+ __get_dev(filp->f_path.dentry),
57041+ current->role);
57042+ read_unlock(&gr_inode_lock);
57043+
57044+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57045+ (!curr->crashes && !curr->expires))
57046+ return 0;
57047+
57048+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57049+ time_after(curr->expires, get_seconds()))
57050+ return 1;
57051+ else if (time_before_eq(curr->expires, get_seconds())) {
57052+ curr->crashes = 0;
57053+ curr->expires = 0;
57054+ }
57055+
57056+ return 0;
57057+}
57058+
57059+void
57060+gr_handle_alertkill(struct task_struct *task)
57061+{
57062+ struct acl_subject_label *curracl;
57063+ __u32 curr_ip;
57064+ struct task_struct *p, *p2;
57065+
57066+ if (unlikely(!gr_acl_is_enabled()))
57067+ return;
57068+
57069+ curracl = task->acl;
57070+ curr_ip = task->signal->curr_ip;
57071+
57072+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57073+ read_lock(&tasklist_lock);
57074+ do_each_thread(p2, p) {
57075+ if (p->signal->curr_ip == curr_ip)
57076+ gr_fake_force_sig(SIGKILL, p);
57077+ } while_each_thread(p2, p);
57078+ read_unlock(&tasklist_lock);
57079+ } else if (curracl->mode & GR_KILLPROC)
57080+ gr_fake_force_sig(SIGKILL, task);
57081+
57082+ return;
57083+}
57084diff -urNp linux-2.6.39.1/grsecurity/gracl_shm.c linux-2.6.39.1/grsecurity/gracl_shm.c
57085--- linux-2.6.39.1/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
57086+++ linux-2.6.39.1/grsecurity/gracl_shm.c 2011-05-22 19:41:42.000000000 -0400
57087@@ -0,0 +1,40 @@
57088+#include <linux/kernel.h>
57089+#include <linux/mm.h>
57090+#include <linux/sched.h>
57091+#include <linux/file.h>
57092+#include <linux/ipc.h>
57093+#include <linux/gracl.h>
57094+#include <linux/grsecurity.h>
57095+#include <linux/grinternal.h>
57096+
57097+int
57098+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57099+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57100+{
57101+ struct task_struct *task;
57102+
57103+ if (!gr_acl_is_enabled())
57104+ return 1;
57105+
57106+ rcu_read_lock();
57107+ read_lock(&tasklist_lock);
57108+
57109+ task = find_task_by_vpid(shm_cprid);
57110+
57111+ if (unlikely(!task))
57112+ task = find_task_by_vpid(shm_lapid);
57113+
57114+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57115+ (task->pid == shm_lapid)) &&
57116+ (task->acl->mode & GR_PROTSHM) &&
57117+ (task->acl != current->acl))) {
57118+ read_unlock(&tasklist_lock);
57119+ rcu_read_unlock();
57120+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57121+ return 0;
57122+ }
57123+ read_unlock(&tasklist_lock);
57124+ rcu_read_unlock();
57125+
57126+ return 1;
57127+}
57128diff -urNp linux-2.6.39.1/grsecurity/grsec_chdir.c linux-2.6.39.1/grsecurity/grsec_chdir.c
57129--- linux-2.6.39.1/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
57130+++ linux-2.6.39.1/grsecurity/grsec_chdir.c 2011-05-22 19:41:42.000000000 -0400
57131@@ -0,0 +1,19 @@
57132+#include <linux/kernel.h>
57133+#include <linux/sched.h>
57134+#include <linux/fs.h>
57135+#include <linux/file.h>
57136+#include <linux/grsecurity.h>
57137+#include <linux/grinternal.h>
57138+
57139+void
57140+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57141+{
57142+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57143+ if ((grsec_enable_chdir && grsec_enable_group &&
57144+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57145+ !grsec_enable_group)) {
57146+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57147+ }
57148+#endif
57149+ return;
57150+}
57151diff -urNp linux-2.6.39.1/grsecurity/grsec_chroot.c linux-2.6.39.1/grsecurity/grsec_chroot.c
57152--- linux-2.6.39.1/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
57153+++ linux-2.6.39.1/grsecurity/grsec_chroot.c 2011-05-22 19:41:42.000000000 -0400
57154@@ -0,0 +1,355 @@
57155+#include <linux/kernel.h>
57156+#include <linux/module.h>
57157+#include <linux/sched.h>
57158+#include <linux/file.h>
57159+#include <linux/fs.h>
57160+#include <linux/mount.h>
57161+#include <linux/types.h>
57162+#include <linux/pid_namespace.h>
57163+#include <linux/grsecurity.h>
57164+#include <linux/grinternal.h>
57165+
57166+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57167+{
57168+#ifdef CONFIG_GRKERNSEC
57169+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57170+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57171+ task->gr_is_chrooted = 1;
57172+ else
57173+ task->gr_is_chrooted = 0;
57174+
57175+ task->gr_chroot_dentry = path->dentry;
57176+#endif
57177+ return;
57178+}
57179+
57180+void gr_clear_chroot_entries(struct task_struct *task)
57181+{
57182+#ifdef CONFIG_GRKERNSEC
57183+ task->gr_is_chrooted = 0;
57184+ task->gr_chroot_dentry = NULL;
57185+#endif
57186+ return;
57187+}
57188+
57189+int
57190+gr_handle_chroot_unix(struct pid *pid)
57191+{
57192+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57193+ struct task_struct *p;
57194+
57195+ if (unlikely(!grsec_enable_chroot_unix))
57196+ return 1;
57197+
57198+ if (likely(!proc_is_chrooted(current)))
57199+ return 1;
57200+
57201+ rcu_read_lock();
57202+ read_lock(&tasklist_lock);
57203+ p = pid_task(pid, PIDTYPE_PID);
57204+ if (unlikely(p && !have_same_root(current, p))) {
57205+ read_unlock(&tasklist_lock);
57206+ rcu_read_unlock();
57207+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57208+ return 0;
57209+ }
57210+ read_unlock(&tasklist_lock);
57211+ rcu_read_unlock();
57212+#endif
57213+ return 1;
57214+}
57215+
57216+int
57217+gr_handle_chroot_nice(void)
57218+{
57219+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57220+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57221+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57222+ return -EPERM;
57223+ }
57224+#endif
57225+ return 0;
57226+}
57227+
57228+int
57229+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57230+{
57231+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57232+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57233+ && proc_is_chrooted(current)) {
57234+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57235+ return -EACCES;
57236+ }
57237+#endif
57238+ return 0;
57239+}
57240+
57241+int
57242+gr_handle_chroot_rawio(const struct inode *inode)
57243+{
57244+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57245+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57246+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57247+ return 1;
57248+#endif
57249+ return 0;
57250+}
57251+
57252+int
57253+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57254+{
57255+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57256+ struct task_struct *p;
57257+ int ret = 0;
57258+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57259+ return ret;
57260+
57261+ read_lock(&tasklist_lock);
57262+ do_each_pid_task(pid, type, p) {
57263+ if (!have_same_root(current, p)) {
57264+ ret = 1;
57265+ goto out;
57266+ }
57267+ } while_each_pid_task(pid, type, p);
57268+out:
57269+ read_unlock(&tasklist_lock);
57270+ return ret;
57271+#endif
57272+ return 0;
57273+}
57274+
57275+int
57276+gr_pid_is_chrooted(struct task_struct *p)
57277+{
57278+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57279+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57280+ return 0;
57281+
57282+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57283+ !have_same_root(current, p)) {
57284+ return 1;
57285+ }
57286+#endif
57287+ return 0;
57288+}
57289+
57290+EXPORT_SYMBOL(gr_pid_is_chrooted);
57291+
57292+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57293+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57294+{
57295+ struct path path, currentroot;
57296+ int ret = 0;
57297+
57298+ path.dentry = (struct dentry *)u_dentry;
57299+ path.mnt = (struct vfsmount *)u_mnt;
57300+ get_fs_root(current->fs, &currentroot);
57301+ if (path_is_under(&path, &currentroot))
57302+ ret = 1;
57303+ path_put(&currentroot);
57304+
57305+ return ret;
57306+}
57307+#endif
57308+
57309+int
57310+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57311+{
57312+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57313+ if (!grsec_enable_chroot_fchdir)
57314+ return 1;
57315+
57316+ if (!proc_is_chrooted(current))
57317+ return 1;
57318+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57319+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57320+ return 0;
57321+ }
57322+#endif
57323+ return 1;
57324+}
57325+
57326+int
57327+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57328+ const time_t shm_createtime)
57329+{
57330+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57331+ struct pid *pid = NULL;
57332+ time_t starttime;
57333+
57334+ if (unlikely(!grsec_enable_chroot_shmat))
57335+ return 1;
57336+
57337+ if (likely(!proc_is_chrooted(current)))
57338+ return 1;
57339+
57340+ rcu_read_lock();
57341+ read_lock(&tasklist_lock);
57342+
57343+ pid = find_vpid(shm_cprid);
57344+ if (pid) {
57345+ struct task_struct *p;
57346+ p = pid_task(pid, PIDTYPE_PID);
57347+ if (p == NULL)
57348+ goto unlock;
57349+ starttime = p->start_time.tv_sec;
57350+ if (unlikely(!have_same_root(current, p) &&
57351+ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
57352+ read_unlock(&tasklist_lock);
57353+ rcu_read_unlock();
57354+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57355+ return 0;
57356+ }
57357+ } else {
57358+ pid = find_vpid(shm_lapid);
57359+ if (pid) {
57360+ struct task_struct *p;
57361+ p = pid_task(pid, PIDTYPE_PID);
57362+ if (p == NULL)
57363+ goto unlock;
57364+ if (unlikely(!have_same_root(current, p))) {
57365+ read_unlock(&tasklist_lock);
57366+ rcu_read_unlock();
57367+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57368+ return 0;
57369+ }
57370+ }
57371+ }
57372+unlock:
57373+ read_unlock(&tasklist_lock);
57374+ rcu_read_unlock();
57375+#endif
57376+ return 1;
57377+}
57378+
57379+void
57380+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57381+{
57382+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57383+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57384+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57385+#endif
57386+ return;
57387+}
57388+
57389+int
57390+gr_handle_chroot_mknod(const struct dentry *dentry,
57391+ const struct vfsmount *mnt, const int mode)
57392+{
57393+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57394+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57395+ proc_is_chrooted(current)) {
57396+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57397+ return -EPERM;
57398+ }
57399+#endif
57400+ return 0;
57401+}
57402+
57403+int
57404+gr_handle_chroot_mount(const struct dentry *dentry,
57405+ const struct vfsmount *mnt, const char *dev_name)
57406+{
57407+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57408+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57409+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
57410+ return -EPERM;
57411+ }
57412+#endif
57413+ return 0;
57414+}
57415+
57416+int
57417+gr_handle_chroot_pivot(void)
57418+{
57419+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57420+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57421+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57422+ return -EPERM;
57423+ }
57424+#endif
57425+ return 0;
57426+}
57427+
57428+int
57429+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57430+{
57431+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57432+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57433+ !gr_is_outside_chroot(dentry, mnt)) {
57434+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57435+ return -EPERM;
57436+ }
57437+#endif
57438+ return 0;
57439+}
57440+
57441+int
57442+gr_handle_chroot_caps(struct path *path)
57443+{
57444+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57445+ if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
57446+ (init_task.fs->root.dentry != path->dentry) &&
57447+ (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
57448+
57449+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57450+ const struct cred *old = current_cred();
57451+ struct cred *new = prepare_creds();
57452+ if (new == NULL)
57453+ return 1;
57454+
57455+ new->cap_permitted = cap_drop(old->cap_permitted,
57456+ chroot_caps);
57457+ new->cap_inheritable = cap_drop(old->cap_inheritable,
57458+ chroot_caps);
57459+ new->cap_effective = cap_drop(old->cap_effective,
57460+ chroot_caps);
57461+
57462+ commit_creds(new);
57463+
57464+ return 0;
57465+ }
57466+#endif
57467+ return 0;
57468+}
57469+
57470+int
57471+gr_handle_chroot_sysctl(const int op)
57472+{
57473+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57474+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57475+ proc_is_chrooted(current))
57476+ return -EACCES;
57477+#endif
57478+ return 0;
57479+}
57480+
57481+void
57482+gr_handle_chroot_chdir(struct path *path)
57483+{
57484+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57485+ if (grsec_enable_chroot_chdir)
57486+ set_fs_pwd(current->fs, path);
57487+#endif
57488+ return;
57489+}
57490+
57491+int
57492+gr_handle_chroot_chmod(const struct dentry *dentry,
57493+ const struct vfsmount *mnt, const int mode)
57494+{
57495+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57496+ /* allow chmod +s on directories, but not files */
57497+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57498+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57499+ proc_is_chrooted(current)) {
57500+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57501+ return -EPERM;
57502+ }
57503+#endif
57504+ return 0;
57505+}
57506+
57507+#ifdef CONFIG_SECURITY
57508+EXPORT_SYMBOL(gr_handle_chroot_caps);
57509+#endif
57510diff -urNp linux-2.6.39.1/grsecurity/grsec_disabled.c linux-2.6.39.1/grsecurity/grsec_disabled.c
57511--- linux-2.6.39.1/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
57512+++ linux-2.6.39.1/grsecurity/grsec_disabled.c 2011-05-22 19:41:42.000000000 -0400
57513@@ -0,0 +1,447 @@
57514+#include <linux/kernel.h>
57515+#include <linux/module.h>
57516+#include <linux/sched.h>
57517+#include <linux/file.h>
57518+#include <linux/fs.h>
57519+#include <linux/kdev_t.h>
57520+#include <linux/net.h>
57521+#include <linux/in.h>
57522+#include <linux/ip.h>
57523+#include <linux/skbuff.h>
57524+#include <linux/sysctl.h>
57525+
57526+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57527+void
57528+pax_set_initial_flags(struct linux_binprm *bprm)
57529+{
57530+ return;
57531+}
57532+#endif
57533+
57534+#ifdef CONFIG_SYSCTL
57535+__u32
57536+gr_handle_sysctl(const struct ctl_table * table, const int op)
57537+{
57538+ return 0;
57539+}
57540+#endif
57541+
57542+#ifdef CONFIG_TASKSTATS
57543+int gr_is_taskstats_denied(int pid)
57544+{
57545+ return 0;
57546+}
57547+#endif
57548+
57549+int
57550+gr_acl_is_enabled(void)
57551+{
57552+ return 0;
57553+}
57554+
57555+int
57556+gr_handle_rawio(const struct inode *inode)
57557+{
57558+ return 0;
57559+}
57560+
57561+void
57562+gr_acl_handle_psacct(struct task_struct *task, const long code)
57563+{
57564+ return;
57565+}
57566+
57567+int
57568+gr_handle_ptrace(struct task_struct *task, const long request)
57569+{
57570+ return 0;
57571+}
57572+
57573+int
57574+gr_handle_proc_ptrace(struct task_struct *task)
57575+{
57576+ return 0;
57577+}
57578+
57579+void
57580+gr_learn_resource(const struct task_struct *task,
57581+ const int res, const unsigned long wanted, const int gt)
57582+{
57583+ return;
57584+}
57585+
57586+int
57587+gr_set_acls(const int type)
57588+{
57589+ return 0;
57590+}
57591+
57592+int
57593+gr_check_hidden_task(const struct task_struct *tsk)
57594+{
57595+ return 0;
57596+}
57597+
57598+int
57599+gr_check_protected_task(const struct task_struct *task)
57600+{
57601+ return 0;
57602+}
57603+
57604+int
57605+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57606+{
57607+ return 0;
57608+}
57609+
57610+void
57611+gr_copy_label(struct task_struct *tsk)
57612+{
57613+ return;
57614+}
57615+
57616+void
57617+gr_set_pax_flags(struct task_struct *task)
57618+{
57619+ return;
57620+}
57621+
57622+int
57623+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57624+ const int unsafe_share)
57625+{
57626+ return 0;
57627+}
57628+
57629+void
57630+gr_handle_delete(const ino_t ino, const dev_t dev)
57631+{
57632+ return;
57633+}
57634+
57635+void
57636+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57637+{
57638+ return;
57639+}
57640+
57641+void
57642+gr_handle_crash(struct task_struct *task, const int sig)
57643+{
57644+ return;
57645+}
57646+
57647+int
57648+gr_check_crash_exec(const struct file *filp)
57649+{
57650+ return 0;
57651+}
57652+
57653+int
57654+gr_check_crash_uid(const uid_t uid)
57655+{
57656+ return 0;
57657+}
57658+
57659+void
57660+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57661+ struct dentry *old_dentry,
57662+ struct dentry *new_dentry,
57663+ struct vfsmount *mnt, const __u8 replace)
57664+{
57665+ return;
57666+}
57667+
57668+int
57669+gr_search_socket(const int family, const int type, const int protocol)
57670+{
57671+ return 1;
57672+}
57673+
57674+int
57675+gr_search_connectbind(const int mode, const struct socket *sock,
57676+ const struct sockaddr_in *addr)
57677+{
57678+ return 0;
57679+}
57680+
57681+int
57682+gr_is_capable(const int cap)
57683+{
57684+ return 1;
57685+}
57686+
57687+int
57688+gr_is_capable_nolog(const int cap)
57689+{
57690+ return 1;
57691+}
57692+
57693+void
57694+gr_handle_alertkill(struct task_struct *task)
57695+{
57696+ return;
57697+}
57698+
57699+__u32
57700+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57701+{
57702+ return 1;
57703+}
57704+
57705+__u32
57706+gr_acl_handle_hidden_file(const struct dentry * dentry,
57707+ const struct vfsmount * mnt)
57708+{
57709+ return 1;
57710+}
57711+
57712+__u32
57713+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57714+ const int fmode)
57715+{
57716+ return 1;
57717+}
57718+
57719+__u32
57720+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57721+{
57722+ return 1;
57723+}
57724+
57725+__u32
57726+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57727+{
57728+ return 1;
57729+}
57730+
57731+int
57732+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57733+ unsigned int *vm_flags)
57734+{
57735+ return 1;
57736+}
57737+
57738+__u32
57739+gr_acl_handle_truncate(const struct dentry * dentry,
57740+ const struct vfsmount * mnt)
57741+{
57742+ return 1;
57743+}
57744+
57745+__u32
57746+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57747+{
57748+ return 1;
57749+}
57750+
57751+__u32
57752+gr_acl_handle_access(const struct dentry * dentry,
57753+ const struct vfsmount * mnt, const int fmode)
57754+{
57755+ return 1;
57756+}
57757+
57758+__u32
57759+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57760+ mode_t mode)
57761+{
57762+ return 1;
57763+}
57764+
57765+__u32
57766+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57767+ mode_t mode)
57768+{
57769+ return 1;
57770+}
57771+
57772+__u32
57773+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57774+{
57775+ return 1;
57776+}
57777+
57778+__u32
57779+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57780+{
57781+ return 1;
57782+}
57783+
57784+void
57785+grsecurity_init(void)
57786+{
57787+ return;
57788+}
57789+
57790+__u32
57791+gr_acl_handle_mknod(const struct dentry * new_dentry,
57792+ const struct dentry * parent_dentry,
57793+ const struct vfsmount * parent_mnt,
57794+ const int mode)
57795+{
57796+ return 1;
57797+}
57798+
57799+__u32
57800+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57801+ const struct dentry * parent_dentry,
57802+ const struct vfsmount * parent_mnt)
57803+{
57804+ return 1;
57805+}
57806+
57807+__u32
57808+gr_acl_handle_symlink(const struct dentry * new_dentry,
57809+ const struct dentry * parent_dentry,
57810+ const struct vfsmount * parent_mnt, const char *from)
57811+{
57812+ return 1;
57813+}
57814+
57815+__u32
57816+gr_acl_handle_link(const struct dentry * new_dentry,
57817+ const struct dentry * parent_dentry,
57818+ const struct vfsmount * parent_mnt,
57819+ const struct dentry * old_dentry,
57820+ const struct vfsmount * old_mnt, const char *to)
57821+{
57822+ return 1;
57823+}
57824+
57825+int
57826+gr_acl_handle_rename(const struct dentry *new_dentry,
57827+ const struct dentry *parent_dentry,
57828+ const struct vfsmount *parent_mnt,
57829+ const struct dentry *old_dentry,
57830+ const struct inode *old_parent_inode,
57831+ const struct vfsmount *old_mnt, const char *newname)
57832+{
57833+ return 0;
57834+}
57835+
57836+int
57837+gr_acl_handle_filldir(const struct file *file, const char *name,
57838+ const int namelen, const ino_t ino)
57839+{
57840+ return 1;
57841+}
57842+
57843+int
57844+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57845+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57846+{
57847+ return 1;
57848+}
57849+
57850+int
57851+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57852+{
57853+ return 0;
57854+}
57855+
57856+int
57857+gr_search_accept(const struct socket *sock)
57858+{
57859+ return 0;
57860+}
57861+
57862+int
57863+gr_search_listen(const struct socket *sock)
57864+{
57865+ return 0;
57866+}
57867+
57868+int
57869+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57870+{
57871+ return 0;
57872+}
57873+
57874+__u32
57875+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57876+{
57877+ return 1;
57878+}
57879+
57880+__u32
57881+gr_acl_handle_creat(const struct dentry * dentry,
57882+ const struct dentry * p_dentry,
57883+ const struct vfsmount * p_mnt, const int fmode,
57884+ const int imode)
57885+{
57886+ return 1;
57887+}
57888+
57889+void
57890+gr_acl_handle_exit(void)
57891+{
57892+ return;
57893+}
57894+
57895+int
57896+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57897+{
57898+ return 1;
57899+}
57900+
57901+void
57902+gr_set_role_label(const uid_t uid, const gid_t gid)
57903+{
57904+ return;
57905+}
57906+
57907+int
57908+gr_acl_handle_procpidmem(const struct task_struct *task)
57909+{
57910+ return 0;
57911+}
57912+
57913+int
57914+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57915+{
57916+ return 0;
57917+}
57918+
57919+int
57920+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57921+{
57922+ return 0;
57923+}
57924+
57925+void
57926+gr_set_kernel_label(struct task_struct *task)
57927+{
57928+ return;
57929+}
57930+
57931+int
57932+gr_check_user_change(int real, int effective, int fs)
57933+{
57934+ return 0;
57935+}
57936+
57937+int
57938+gr_check_group_change(int real, int effective, int fs)
57939+{
57940+ return 0;
57941+}
57942+
57943+int gr_acl_enable_at_secure(void)
57944+{
57945+ return 0;
57946+}
57947+
57948+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57949+{
57950+ return dentry->d_inode->i_sb->s_dev;
57951+}
57952+
57953+EXPORT_SYMBOL(gr_is_capable);
57954+EXPORT_SYMBOL(gr_is_capable_nolog);
57955+EXPORT_SYMBOL(gr_learn_resource);
57956+EXPORT_SYMBOL(gr_set_kernel_label);
57957+#ifdef CONFIG_SECURITY
57958+EXPORT_SYMBOL(gr_check_user_change);
57959+EXPORT_SYMBOL(gr_check_group_change);
57960+#endif
57961diff -urNp linux-2.6.39.1/grsecurity/grsec_exec.c linux-2.6.39.1/grsecurity/grsec_exec.c
57962--- linux-2.6.39.1/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
57963+++ linux-2.6.39.1/grsecurity/grsec_exec.c 2011-05-22 22:41:29.000000000 -0400
57964@@ -0,0 +1,146 @@
57965+#include <linux/kernel.h>
57966+#include <linux/sched.h>
57967+#include <linux/file.h>
57968+#include <linux/binfmts.h>
57969+#include <linux/fs.h>
57970+#include <linux/types.h>
57971+#include <linux/grdefs.h>
57972+#include <linux/grinternal.h>
57973+#include <linux/capability.h>
57974+#include <linux/compat.h>
57975+
57976+#include <asm/uaccess.h>
57977+
57978+#ifdef CONFIG_GRKERNSEC_EXECLOG
57979+static char gr_exec_arg_buf[132];
57980+static DEFINE_MUTEX(gr_exec_arg_mutex);
57981+#endif
57982+
57983+int
57984+gr_handle_nproc(void)
57985+{
57986+#ifdef CONFIG_GRKERNSEC_EXECVE
57987+ const struct cred *cred = current_cred();
57988+ if (grsec_enable_execve && cred->user &&
57989+ (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
57990+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
57991+ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
57992+ return -EAGAIN;
57993+ }
57994+#endif
57995+ return 0;
57996+}
57997+
57998+void
57999+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
58000+{
58001+#ifdef CONFIG_GRKERNSEC_EXECLOG
58002+ char *grarg = gr_exec_arg_buf;
58003+ unsigned int i, x, execlen = 0;
58004+ char c;
58005+
58006+ if (!((grsec_enable_execlog && grsec_enable_group &&
58007+ in_group_p(grsec_audit_gid))
58008+ || (grsec_enable_execlog && !grsec_enable_group)))
58009+ return;
58010+
58011+ mutex_lock(&gr_exec_arg_mutex);
58012+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58013+
58014+ if (unlikely(argv == NULL))
58015+ goto log;
58016+
58017+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58018+ const char __user *p;
58019+ unsigned int len;
58020+
58021+ if (copy_from_user(&p, argv + i, sizeof(p)))
58022+ goto log;
58023+ if (!p)
58024+ goto log;
58025+ len = strnlen_user(p, 128 - execlen);
58026+ if (len > 128 - execlen)
58027+ len = 128 - execlen;
58028+ else if (len > 0)
58029+ len--;
58030+ if (copy_from_user(grarg + execlen, p, len))
58031+ goto log;
58032+
58033+ /* rewrite unprintable characters */
58034+ for (x = 0; x < len; x++) {
58035+ c = *(grarg + execlen + x);
58036+ if (c < 32 || c > 126)
58037+ *(grarg + execlen + x) = ' ';
58038+ }
58039+
58040+ execlen += len;
58041+ *(grarg + execlen) = ' ';
58042+ *(grarg + execlen + 1) = '\0';
58043+ execlen++;
58044+ }
58045+
58046+ log:
58047+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58048+ bprm->file->f_path.mnt, grarg);
58049+ mutex_unlock(&gr_exec_arg_mutex);
58050+#endif
58051+ return;
58052+}
58053+
58054+#ifdef CONFIG_COMPAT
58055+void
58056+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
58057+{
58058+#ifdef CONFIG_GRKERNSEC_EXECLOG
58059+ char *grarg = gr_exec_arg_buf;
58060+ unsigned int i, x, execlen = 0;
58061+ char c;
58062+
58063+ if (!((grsec_enable_execlog && grsec_enable_group &&
58064+ in_group_p(grsec_audit_gid))
58065+ || (grsec_enable_execlog && !grsec_enable_group)))
58066+ return;
58067+
58068+ mutex_lock(&gr_exec_arg_mutex);
58069+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58070+
58071+ if (unlikely(argv == NULL))
58072+ goto log;
58073+
58074+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58075+ compat_uptr_t p;
58076+ unsigned int len;
58077+
58078+ if (get_user(p, argv + i))
58079+ goto log;
58080+ len = strnlen_user(compat_ptr(p), 128 - execlen);
58081+ if (len > 128 - execlen)
58082+ len = 128 - execlen;
58083+ else if (len > 0)
58084+ len--;
58085+ else
58086+ goto log;
58087+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
58088+ goto log;
58089+
58090+ /* rewrite unprintable characters */
58091+ for (x = 0; x < len; x++) {
58092+ c = *(grarg + execlen + x);
58093+ if (c < 32 || c > 126)
58094+ *(grarg + execlen + x) = ' ';
58095+ }
58096+
58097+ execlen += len;
58098+ *(grarg + execlen) = ' ';
58099+ *(grarg + execlen + 1) = '\0';
58100+ execlen++;
58101+ }
58102+
58103+ log:
58104+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58105+ bprm->file->f_path.mnt, grarg);
58106+ mutex_unlock(&gr_exec_arg_mutex);
58107+#endif
58108+ return;
58109+}
58110+#endif
58111diff -urNp linux-2.6.39.1/grsecurity/grsec_fifo.c linux-2.6.39.1/grsecurity/grsec_fifo.c
58112--- linux-2.6.39.1/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
58113+++ linux-2.6.39.1/grsecurity/grsec_fifo.c 2011-05-22 19:41:42.000000000 -0400
58114@@ -0,0 +1,24 @@
58115+#include <linux/kernel.h>
58116+#include <linux/sched.h>
58117+#include <linux/fs.h>
58118+#include <linux/file.h>
58119+#include <linux/grinternal.h>
58120+
58121+int
58122+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58123+ const struct dentry *dir, const int flag, const int acc_mode)
58124+{
58125+#ifdef CONFIG_GRKERNSEC_FIFO
58126+ const struct cred *cred = current_cred();
58127+
58128+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58129+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58130+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58131+ (cred->fsuid != dentry->d_inode->i_uid)) {
58132+ if (!inode_permission(dentry->d_inode, acc_mode))
58133+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58134+ return -EACCES;
58135+ }
58136+#endif
58137+ return 0;
58138+}
58139diff -urNp linux-2.6.39.1/grsecurity/grsec_fork.c linux-2.6.39.1/grsecurity/grsec_fork.c
58140--- linux-2.6.39.1/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
58141+++ linux-2.6.39.1/grsecurity/grsec_fork.c 2011-05-22 19:41:42.000000000 -0400
58142@@ -0,0 +1,23 @@
58143+#include <linux/kernel.h>
58144+#include <linux/sched.h>
58145+#include <linux/grsecurity.h>
58146+#include <linux/grinternal.h>
58147+#include <linux/errno.h>
58148+
58149+void
58150+gr_log_forkfail(const int retval)
58151+{
58152+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58153+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58154+ switch (retval) {
58155+ case -EAGAIN:
58156+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58157+ break;
58158+ case -ENOMEM:
58159+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58160+ break;
58161+ }
58162+ }
58163+#endif
58164+ return;
58165+}
58166diff -urNp linux-2.6.39.1/grsecurity/grsec_init.c linux-2.6.39.1/grsecurity/grsec_init.c
58167--- linux-2.6.39.1/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
58168+++ linux-2.6.39.1/grsecurity/grsec_init.c 2011-05-22 22:47:15.000000000 -0400
58169@@ -0,0 +1,269 @@
58170+#include <linux/kernel.h>
58171+#include <linux/sched.h>
58172+#include <linux/mm.h>
58173+#include <linux/gracl.h>
58174+#include <linux/slab.h>
58175+#include <linux/vmalloc.h>
58176+#include <linux/percpu.h>
58177+#include <linux/module.h>
58178+
58179+int grsec_enable_link;
58180+int grsec_enable_dmesg;
58181+int grsec_enable_harden_ptrace;
58182+int grsec_enable_fifo;
58183+int grsec_enable_execve;
58184+int grsec_enable_execlog;
58185+int grsec_enable_signal;
58186+int grsec_enable_forkfail;
58187+int grsec_enable_audit_ptrace;
58188+int grsec_enable_time;
58189+int grsec_enable_audit_textrel;
58190+int grsec_enable_group;
58191+int grsec_audit_gid;
58192+int grsec_enable_chdir;
58193+int grsec_enable_mount;
58194+int grsec_enable_rofs;
58195+int grsec_enable_chroot_findtask;
58196+int grsec_enable_chroot_mount;
58197+int grsec_enable_chroot_shmat;
58198+int grsec_enable_chroot_fchdir;
58199+int grsec_enable_chroot_double;
58200+int grsec_enable_chroot_pivot;
58201+int grsec_enable_chroot_chdir;
58202+int grsec_enable_chroot_chmod;
58203+int grsec_enable_chroot_mknod;
58204+int grsec_enable_chroot_nice;
58205+int grsec_enable_chroot_execlog;
58206+int grsec_enable_chroot_caps;
58207+int grsec_enable_chroot_sysctl;
58208+int grsec_enable_chroot_unix;
58209+int grsec_enable_tpe;
58210+int grsec_tpe_gid;
58211+int grsec_enable_blackhole;
58212+#ifdef CONFIG_IPV6_MODULE
58213+EXPORT_SYMBOL(grsec_enable_blackhole);
58214+#endif
58215+int grsec_lastack_retries;
58216+int grsec_enable_tpe_all;
58217+int grsec_enable_tpe_invert;
58218+int grsec_enable_socket_all;
58219+int grsec_socket_all_gid;
58220+int grsec_enable_socket_client;
58221+int grsec_socket_client_gid;
58222+int grsec_enable_socket_server;
58223+int grsec_socket_server_gid;
58224+int grsec_resource_logging;
58225+int grsec_disable_privio;
58226+int grsec_enable_log_rwxmaps;
58227+int grsec_lock;
58228+
58229+DEFINE_SPINLOCK(grsec_alert_lock);
58230+unsigned long grsec_alert_wtime = 0;
58231+unsigned long grsec_alert_fyet = 0;
58232+
58233+DEFINE_SPINLOCK(grsec_audit_lock);
58234+
58235+DEFINE_RWLOCK(grsec_exec_file_lock);
58236+
58237+char *gr_shared_page[4];
58238+
58239+char *gr_alert_log_fmt;
58240+char *gr_audit_log_fmt;
58241+char *gr_alert_log_buf;
58242+char *gr_audit_log_buf;
58243+
58244+extern struct gr_arg *gr_usermode;
58245+extern unsigned char *gr_system_salt;
58246+extern unsigned char *gr_system_sum;
58247+
58248+void __init
58249+grsecurity_init(void)
58250+{
58251+ int j;
58252+ /* create the per-cpu shared pages */
58253+
58254+#ifdef CONFIG_X86
58255+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58256+#endif
58257+
58258+ for (j = 0; j < 4; j++) {
58259+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58260+ if (gr_shared_page[j] == NULL) {
58261+ panic("Unable to allocate grsecurity shared page");
58262+ return;
58263+ }
58264+ }
58265+
58266+ /* allocate log buffers */
58267+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58268+ if (!gr_alert_log_fmt) {
58269+ panic("Unable to allocate grsecurity alert log format buffer");
58270+ return;
58271+ }
58272+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58273+ if (!gr_audit_log_fmt) {
58274+ panic("Unable to allocate grsecurity audit log format buffer");
58275+ return;
58276+ }
58277+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58278+ if (!gr_alert_log_buf) {
58279+ panic("Unable to allocate grsecurity alert log buffer");
58280+ return;
58281+ }
58282+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58283+ if (!gr_audit_log_buf) {
58284+ panic("Unable to allocate grsecurity audit log buffer");
58285+ return;
58286+ }
58287+
58288+ /* allocate memory for authentication structure */
58289+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58290+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58291+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58292+
58293+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58294+ panic("Unable to allocate grsecurity authentication structure");
58295+ return;
58296+ }
58297+
58298+
58299+#ifdef CONFIG_GRKERNSEC_IO
58300+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58301+ grsec_disable_privio = 1;
58302+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58303+ grsec_disable_privio = 1;
58304+#else
58305+ grsec_disable_privio = 0;
58306+#endif
58307+#endif
58308+
58309+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58310+ /* for backward compatibility, tpe_invert always defaults to on if
58311+ enabled in the kernel
58312+ */
58313+ grsec_enable_tpe_invert = 1;
58314+#endif
58315+
58316+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58317+#ifndef CONFIG_GRKERNSEC_SYSCTL
58318+ grsec_lock = 1;
58319+#endif
58320+
58321+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58322+ grsec_enable_audit_textrel = 1;
58323+#endif
58324+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58325+ grsec_enable_log_rwxmaps = 1;
58326+#endif
58327+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58328+ grsec_enable_group = 1;
58329+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58330+#endif
58331+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58332+ grsec_enable_chdir = 1;
58333+#endif
58334+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58335+ grsec_enable_harden_ptrace = 1;
58336+#endif
58337+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58338+ grsec_enable_mount = 1;
58339+#endif
58340+#ifdef CONFIG_GRKERNSEC_LINK
58341+ grsec_enable_link = 1;
58342+#endif
58343+#ifdef CONFIG_GRKERNSEC_DMESG
58344+ grsec_enable_dmesg = 1;
58345+#endif
58346+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58347+ grsec_enable_blackhole = 1;
58348+ grsec_lastack_retries = 4;
58349+#endif
58350+#ifdef CONFIG_GRKERNSEC_FIFO
58351+ grsec_enable_fifo = 1;
58352+#endif
58353+#ifdef CONFIG_GRKERNSEC_EXECVE
58354+ grsec_enable_execve = 1;
58355+#endif
58356+#ifdef CONFIG_GRKERNSEC_EXECLOG
58357+ grsec_enable_execlog = 1;
58358+#endif
58359+#ifdef CONFIG_GRKERNSEC_SIGNAL
58360+ grsec_enable_signal = 1;
58361+#endif
58362+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58363+ grsec_enable_forkfail = 1;
58364+#endif
58365+#ifdef CONFIG_GRKERNSEC_TIME
58366+ grsec_enable_time = 1;
58367+#endif
58368+#ifdef CONFIG_GRKERNSEC_RESLOG
58369+ grsec_resource_logging = 1;
58370+#endif
58371+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58372+ grsec_enable_chroot_findtask = 1;
58373+#endif
58374+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58375+ grsec_enable_chroot_unix = 1;
58376+#endif
58377+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58378+ grsec_enable_chroot_mount = 1;
58379+#endif
58380+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58381+ grsec_enable_chroot_fchdir = 1;
58382+#endif
58383+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58384+ grsec_enable_chroot_shmat = 1;
58385+#endif
58386+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58387+ grsec_enable_audit_ptrace = 1;
58388+#endif
58389+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58390+ grsec_enable_chroot_double = 1;
58391+#endif
58392+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58393+ grsec_enable_chroot_pivot = 1;
58394+#endif
58395+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58396+ grsec_enable_chroot_chdir = 1;
58397+#endif
58398+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58399+ grsec_enable_chroot_chmod = 1;
58400+#endif
58401+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58402+ grsec_enable_chroot_mknod = 1;
58403+#endif
58404+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58405+ grsec_enable_chroot_nice = 1;
58406+#endif
58407+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58408+ grsec_enable_chroot_execlog = 1;
58409+#endif
58410+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58411+ grsec_enable_chroot_caps = 1;
58412+#endif
58413+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58414+ grsec_enable_chroot_sysctl = 1;
58415+#endif
58416+#ifdef CONFIG_GRKERNSEC_TPE
58417+ grsec_enable_tpe = 1;
58418+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58419+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58420+ grsec_enable_tpe_all = 1;
58421+#endif
58422+#endif
58423+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58424+ grsec_enable_socket_all = 1;
58425+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58426+#endif
58427+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58428+ grsec_enable_socket_client = 1;
58429+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58430+#endif
58431+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58432+ grsec_enable_socket_server = 1;
58433+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58434+#endif
58435+#endif
58436+
58437+ return;
58438+}
58439diff -urNp linux-2.6.39.1/grsecurity/grsec_link.c linux-2.6.39.1/grsecurity/grsec_link.c
58440--- linux-2.6.39.1/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
58441+++ linux-2.6.39.1/grsecurity/grsec_link.c 2011-05-22 19:41:42.000000000 -0400
58442@@ -0,0 +1,43 @@
58443+#include <linux/kernel.h>
58444+#include <linux/sched.h>
58445+#include <linux/fs.h>
58446+#include <linux/file.h>
58447+#include <linux/grinternal.h>
58448+
58449+int
58450+gr_handle_follow_link(const struct inode *parent,
58451+ const struct inode *inode,
58452+ const struct dentry *dentry, const struct vfsmount *mnt)
58453+{
58454+#ifdef CONFIG_GRKERNSEC_LINK
58455+ const struct cred *cred = current_cred();
58456+
58457+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58458+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58459+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58460+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58461+ return -EACCES;
58462+ }
58463+#endif
58464+ return 0;
58465+}
58466+
58467+int
58468+gr_handle_hardlink(const struct dentry *dentry,
58469+ const struct vfsmount *mnt,
58470+ struct inode *inode, const int mode, const char *to)
58471+{
58472+#ifdef CONFIG_GRKERNSEC_LINK
58473+ const struct cred *cred = current_cred();
58474+
58475+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58476+ (!S_ISREG(mode) || (mode & S_ISUID) ||
58477+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58478+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58479+ !capable(CAP_FOWNER) && cred->uid) {
58480+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58481+ return -EPERM;
58482+ }
58483+#endif
58484+ return 0;
58485+}
58486diff -urNp linux-2.6.39.1/grsecurity/grsec_log.c linux-2.6.39.1/grsecurity/grsec_log.c
58487--- linux-2.6.39.1/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
58488+++ linux-2.6.39.1/grsecurity/grsec_log.c 2011-05-22 19:41:42.000000000 -0400
58489@@ -0,0 +1,310 @@
58490+#include <linux/kernel.h>
58491+#include <linux/sched.h>
58492+#include <linux/file.h>
58493+#include <linux/tty.h>
58494+#include <linux/fs.h>
58495+#include <linux/grinternal.h>
58496+
58497+#ifdef CONFIG_TREE_PREEMPT_RCU
58498+#define DISABLE_PREEMPT() preempt_disable()
58499+#define ENABLE_PREEMPT() preempt_enable()
58500+#else
58501+#define DISABLE_PREEMPT()
58502+#define ENABLE_PREEMPT()
58503+#endif
58504+
58505+#define BEGIN_LOCKS(x) \
58506+ DISABLE_PREEMPT(); \
58507+ rcu_read_lock(); \
58508+ read_lock(&tasklist_lock); \
58509+ read_lock(&grsec_exec_file_lock); \
58510+ if (x != GR_DO_AUDIT) \
58511+ spin_lock(&grsec_alert_lock); \
58512+ else \
58513+ spin_lock(&grsec_audit_lock)
58514+
58515+#define END_LOCKS(x) \
58516+ if (x != GR_DO_AUDIT) \
58517+ spin_unlock(&grsec_alert_lock); \
58518+ else \
58519+ spin_unlock(&grsec_audit_lock); \
58520+ read_unlock(&grsec_exec_file_lock); \
58521+ read_unlock(&tasklist_lock); \
58522+ rcu_read_unlock(); \
58523+ ENABLE_PREEMPT(); \
58524+ if (x == GR_DONT_AUDIT) \
58525+ gr_handle_alertkill(current)
58526+
58527+enum {
58528+ FLOODING,
58529+ NO_FLOODING
58530+};
58531+
58532+extern char *gr_alert_log_fmt;
58533+extern char *gr_audit_log_fmt;
58534+extern char *gr_alert_log_buf;
58535+extern char *gr_audit_log_buf;
58536+
58537+static int gr_log_start(int audit)
58538+{
58539+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58540+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58541+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58542+
58543+ if (audit == GR_DO_AUDIT)
58544+ goto set_fmt;
58545+
58546+ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
58547+ grsec_alert_wtime = jiffies;
58548+ grsec_alert_fyet = 0;
58549+ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58550+ grsec_alert_fyet++;
58551+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58552+ grsec_alert_wtime = jiffies;
58553+ grsec_alert_fyet++;
58554+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58555+ return FLOODING;
58556+ } else return FLOODING;
58557+
58558+set_fmt:
58559+ memset(buf, 0, PAGE_SIZE);
58560+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58561+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58562+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58563+ } else if (current->signal->curr_ip) {
58564+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58565+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58566+ } else if (gr_acl_is_enabled()) {
58567+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58568+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58569+ } else {
58570+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58571+ strcpy(buf, fmt);
58572+ }
58573+
58574+ return NO_FLOODING;
58575+}
58576+
58577+static void gr_log_middle(int audit, const char *msg, va_list ap)
58578+ __attribute__ ((format (printf, 2, 0)));
58579+
58580+static void gr_log_middle(int audit, const char *msg, va_list ap)
58581+{
58582+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58583+ unsigned int len = strlen(buf);
58584+
58585+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58586+
58587+ return;
58588+}
58589+
58590+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58591+ __attribute__ ((format (printf, 2, 3)));
58592+
58593+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58594+{
58595+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58596+ unsigned int len = strlen(buf);
58597+ va_list ap;
58598+
58599+ va_start(ap, msg);
58600+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58601+ va_end(ap);
58602+
58603+ return;
58604+}
58605+
58606+static void gr_log_end(int audit)
58607+{
58608+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58609+ unsigned int len = strlen(buf);
58610+
58611+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58612+ printk("%s\n", buf);
58613+
58614+ return;
58615+}
58616+
58617+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58618+{
58619+ int logtype;
58620+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58621+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58622+ void *voidptr = NULL;
58623+ int num1 = 0, num2 = 0;
58624+ unsigned long ulong1 = 0, ulong2 = 0;
58625+ struct dentry *dentry = NULL;
58626+ struct vfsmount *mnt = NULL;
58627+ struct file *file = NULL;
58628+ struct task_struct *task = NULL;
58629+ const struct cred *cred, *pcred;
58630+ va_list ap;
58631+
58632+ BEGIN_LOCKS(audit);
58633+ logtype = gr_log_start(audit);
58634+ if (logtype == FLOODING) {
58635+ END_LOCKS(audit);
58636+ return;
58637+ }
58638+ va_start(ap, argtypes);
58639+ switch (argtypes) {
58640+ case GR_TTYSNIFF:
58641+ task = va_arg(ap, struct task_struct *);
58642+ 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);
58643+ break;
58644+ case GR_SYSCTL_HIDDEN:
58645+ str1 = va_arg(ap, char *);
58646+ gr_log_middle_varargs(audit, msg, result, str1);
58647+ break;
58648+ case GR_RBAC:
58649+ dentry = va_arg(ap, struct dentry *);
58650+ mnt = va_arg(ap, struct vfsmount *);
58651+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58652+ break;
58653+ case GR_RBAC_STR:
58654+ dentry = va_arg(ap, struct dentry *);
58655+ mnt = va_arg(ap, struct vfsmount *);
58656+ str1 = va_arg(ap, char *);
58657+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58658+ break;
58659+ case GR_STR_RBAC:
58660+ str1 = va_arg(ap, char *);
58661+ dentry = va_arg(ap, struct dentry *);
58662+ mnt = va_arg(ap, struct vfsmount *);
58663+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58664+ break;
58665+ case GR_RBAC_MODE2:
58666+ dentry = va_arg(ap, struct dentry *);
58667+ mnt = va_arg(ap, struct vfsmount *);
58668+ str1 = va_arg(ap, char *);
58669+ str2 = va_arg(ap, char *);
58670+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58671+ break;
58672+ case GR_RBAC_MODE3:
58673+ dentry = va_arg(ap, struct dentry *);
58674+ mnt = va_arg(ap, struct vfsmount *);
58675+ str1 = va_arg(ap, char *);
58676+ str2 = va_arg(ap, char *);
58677+ str3 = va_arg(ap, char *);
58678+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58679+ break;
58680+ case GR_FILENAME:
58681+ dentry = va_arg(ap, struct dentry *);
58682+ mnt = va_arg(ap, struct vfsmount *);
58683+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58684+ break;
58685+ case GR_STR_FILENAME:
58686+ str1 = va_arg(ap, char *);
58687+ dentry = va_arg(ap, struct dentry *);
58688+ mnt = va_arg(ap, struct vfsmount *);
58689+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58690+ break;
58691+ case GR_FILENAME_STR:
58692+ dentry = va_arg(ap, struct dentry *);
58693+ mnt = va_arg(ap, struct vfsmount *);
58694+ str1 = va_arg(ap, char *);
58695+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58696+ break;
58697+ case GR_FILENAME_TWO_INT:
58698+ dentry = va_arg(ap, struct dentry *);
58699+ mnt = va_arg(ap, struct vfsmount *);
58700+ num1 = va_arg(ap, int);
58701+ num2 = va_arg(ap, int);
58702+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58703+ break;
58704+ case GR_FILENAME_TWO_INT_STR:
58705+ dentry = va_arg(ap, struct dentry *);
58706+ mnt = va_arg(ap, struct vfsmount *);
58707+ num1 = va_arg(ap, int);
58708+ num2 = va_arg(ap, int);
58709+ str1 = va_arg(ap, char *);
58710+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58711+ break;
58712+ case GR_TEXTREL:
58713+ file = va_arg(ap, struct file *);
58714+ ulong1 = va_arg(ap, unsigned long);
58715+ ulong2 = va_arg(ap, unsigned long);
58716+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58717+ break;
58718+ case GR_PTRACE:
58719+ task = va_arg(ap, struct task_struct *);
58720+ 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);
58721+ break;
58722+ case GR_RESOURCE:
58723+ task = va_arg(ap, struct task_struct *);
58724+ cred = __task_cred(task);
58725+ pcred = __task_cred(task->real_parent);
58726+ ulong1 = va_arg(ap, unsigned long);
58727+ str1 = va_arg(ap, char *);
58728+ ulong2 = va_arg(ap, unsigned long);
58729+ 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);
58730+ break;
58731+ case GR_CAP:
58732+ task = va_arg(ap, struct task_struct *);
58733+ cred = __task_cred(task);
58734+ pcred = __task_cred(task->real_parent);
58735+ str1 = va_arg(ap, char *);
58736+ 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);
58737+ break;
58738+ case GR_SIG:
58739+ str1 = va_arg(ap, char *);
58740+ voidptr = va_arg(ap, void *);
58741+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58742+ break;
58743+ case GR_SIG2:
58744+ task = va_arg(ap, struct task_struct *);
58745+ cred = __task_cred(task);
58746+ pcred = __task_cred(task->real_parent);
58747+ num1 = va_arg(ap, int);
58748+ 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);
58749+ break;
58750+ case GR_CRASH1:
58751+ task = va_arg(ap, struct task_struct *);
58752+ cred = __task_cred(task);
58753+ pcred = __task_cred(task->real_parent);
58754+ ulong1 = va_arg(ap, unsigned long);
58755+ 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);
58756+ break;
58757+ case GR_CRASH2:
58758+ task = va_arg(ap, struct task_struct *);
58759+ cred = __task_cred(task);
58760+ pcred = __task_cred(task->real_parent);
58761+ ulong1 = va_arg(ap, unsigned long);
58762+ 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);
58763+ break;
58764+ case GR_RWXMAP:
58765+ file = va_arg(ap, struct file *);
58766+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58767+ break;
58768+ case GR_PSACCT:
58769+ {
58770+ unsigned int wday, cday;
58771+ __u8 whr, chr;
58772+ __u8 wmin, cmin;
58773+ __u8 wsec, csec;
58774+ char cur_tty[64] = { 0 };
58775+ char parent_tty[64] = { 0 };
58776+
58777+ task = va_arg(ap, struct task_struct *);
58778+ wday = va_arg(ap, unsigned int);
58779+ cday = va_arg(ap, unsigned int);
58780+ whr = va_arg(ap, int);
58781+ chr = va_arg(ap, int);
58782+ wmin = va_arg(ap, int);
58783+ cmin = va_arg(ap, int);
58784+ wsec = va_arg(ap, int);
58785+ csec = va_arg(ap, int);
58786+ ulong1 = va_arg(ap, unsigned long);
58787+ cred = __task_cred(task);
58788+ pcred = __task_cred(task->real_parent);
58789+
58790+ 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);
58791+ }
58792+ break;
58793+ default:
58794+ gr_log_middle(audit, msg, ap);
58795+ }
58796+ va_end(ap);
58797+ gr_log_end(audit);
58798+ END_LOCKS(audit);
58799+}
58800diff -urNp linux-2.6.39.1/grsecurity/grsec_mem.c linux-2.6.39.1/grsecurity/grsec_mem.c
58801--- linux-2.6.39.1/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
58802+++ linux-2.6.39.1/grsecurity/grsec_mem.c 2011-05-22 19:41:42.000000000 -0400
58803@@ -0,0 +1,33 @@
58804+#include <linux/kernel.h>
58805+#include <linux/sched.h>
58806+#include <linux/mm.h>
58807+#include <linux/mman.h>
58808+#include <linux/grinternal.h>
58809+
58810+void
58811+gr_handle_ioperm(void)
58812+{
58813+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58814+ return;
58815+}
58816+
58817+void
58818+gr_handle_iopl(void)
58819+{
58820+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58821+ return;
58822+}
58823+
58824+void
58825+gr_handle_mem_readwrite(u64 from, u64 to)
58826+{
58827+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58828+ return;
58829+}
58830+
58831+void
58832+gr_handle_vm86(void)
58833+{
58834+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58835+ return;
58836+}
58837diff -urNp linux-2.6.39.1/grsecurity/grsec_mount.c linux-2.6.39.1/grsecurity/grsec_mount.c
58838--- linux-2.6.39.1/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
58839+++ linux-2.6.39.1/grsecurity/grsec_mount.c 2011-05-22 19:41:42.000000000 -0400
58840@@ -0,0 +1,62 @@
58841+#include <linux/kernel.h>
58842+#include <linux/sched.h>
58843+#include <linux/mount.h>
58844+#include <linux/grsecurity.h>
58845+#include <linux/grinternal.h>
58846+
58847+void
58848+gr_log_remount(const char *devname, const int retval)
58849+{
58850+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58851+ if (grsec_enable_mount && (retval >= 0))
58852+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58853+#endif
58854+ return;
58855+}
58856+
58857+void
58858+gr_log_unmount(const char *devname, const int retval)
58859+{
58860+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58861+ if (grsec_enable_mount && (retval >= 0))
58862+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58863+#endif
58864+ return;
58865+}
58866+
58867+void
58868+gr_log_mount(const char *from, const char *to, const int retval)
58869+{
58870+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58871+ if (grsec_enable_mount && (retval >= 0))
58872+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
58873+#endif
58874+ return;
58875+}
58876+
58877+int
58878+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58879+{
58880+#ifdef CONFIG_GRKERNSEC_ROFS
58881+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58882+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58883+ return -EPERM;
58884+ } else
58885+ return 0;
58886+#endif
58887+ return 0;
58888+}
58889+
58890+int
58891+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58892+{
58893+#ifdef CONFIG_GRKERNSEC_ROFS
58894+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58895+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58896+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58897+ return -EPERM;
58898+ } else
58899+ return 0;
58900+#endif
58901+ return 0;
58902+}
58903diff -urNp linux-2.6.39.1/grsecurity/grsec_pax.c linux-2.6.39.1/grsecurity/grsec_pax.c
58904--- linux-2.6.39.1/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
58905+++ linux-2.6.39.1/grsecurity/grsec_pax.c 2011-05-22 19:41:42.000000000 -0400
58906@@ -0,0 +1,36 @@
58907+#include <linux/kernel.h>
58908+#include <linux/sched.h>
58909+#include <linux/mm.h>
58910+#include <linux/file.h>
58911+#include <linux/grinternal.h>
58912+#include <linux/grsecurity.h>
58913+
58914+void
58915+gr_log_textrel(struct vm_area_struct * vma)
58916+{
58917+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58918+ if (grsec_enable_audit_textrel)
58919+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58920+#endif
58921+ return;
58922+}
58923+
58924+void
58925+gr_log_rwxmmap(struct file *file)
58926+{
58927+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58928+ if (grsec_enable_log_rwxmaps)
58929+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58930+#endif
58931+ return;
58932+}
58933+
58934+void
58935+gr_log_rwxmprotect(struct file *file)
58936+{
58937+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58938+ if (grsec_enable_log_rwxmaps)
58939+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58940+#endif
58941+ return;
58942+}
58943diff -urNp linux-2.6.39.1/grsecurity/grsec_ptrace.c linux-2.6.39.1/grsecurity/grsec_ptrace.c
58944--- linux-2.6.39.1/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
58945+++ linux-2.6.39.1/grsecurity/grsec_ptrace.c 2011-05-22 19:41:42.000000000 -0400
58946@@ -0,0 +1,14 @@
58947+#include <linux/kernel.h>
58948+#include <linux/sched.h>
58949+#include <linux/grinternal.h>
58950+#include <linux/grsecurity.h>
58951+
58952+void
58953+gr_audit_ptrace(struct task_struct *task)
58954+{
58955+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58956+ if (grsec_enable_audit_ptrace)
58957+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58958+#endif
58959+ return;
58960+}
58961diff -urNp linux-2.6.39.1/grsecurity/grsec_sig.c linux-2.6.39.1/grsecurity/grsec_sig.c
58962--- linux-2.6.39.1/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
58963+++ linux-2.6.39.1/grsecurity/grsec_sig.c 2011-05-22 19:41:42.000000000 -0400
58964@@ -0,0 +1,203 @@
58965+#include <linux/kernel.h>
58966+#include <linux/sched.h>
58967+#include <linux/delay.h>
58968+#include <linux/grsecurity.h>
58969+#include <linux/grinternal.h>
58970+#include <linux/hardirq.h>
58971+
58972+char *signames[] = {
58973+ [SIGSEGV] = "Segmentation fault",
58974+ [SIGILL] = "Illegal instruction",
58975+ [SIGABRT] = "Abort",
58976+ [SIGBUS] = "Invalid alignment/Bus error"
58977+};
58978+
58979+void
58980+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58981+{
58982+#ifdef CONFIG_GRKERNSEC_SIGNAL
58983+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58984+ (sig == SIGABRT) || (sig == SIGBUS))) {
58985+ if (t->pid == current->pid) {
58986+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58987+ } else {
58988+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58989+ }
58990+ }
58991+#endif
58992+ return;
58993+}
58994+
58995+int
58996+gr_handle_signal(const struct task_struct *p, const int sig)
58997+{
58998+#ifdef CONFIG_GRKERNSEC
58999+ if (current->pid > 1 && gr_check_protected_task(p)) {
59000+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59001+ return -EPERM;
59002+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59003+ return -EPERM;
59004+ }
59005+#endif
59006+ return 0;
59007+}
59008+
59009+#ifdef CONFIG_GRKERNSEC
59010+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59011+
59012+int gr_fake_force_sig(int sig, struct task_struct *t)
59013+{
59014+ unsigned long int flags;
59015+ int ret, blocked, ignored;
59016+ struct k_sigaction *action;
59017+
59018+ spin_lock_irqsave(&t->sighand->siglock, flags);
59019+ action = &t->sighand->action[sig-1];
59020+ ignored = action->sa.sa_handler == SIG_IGN;
59021+ blocked = sigismember(&t->blocked, sig);
59022+ if (blocked || ignored) {
59023+ action->sa.sa_handler = SIG_DFL;
59024+ if (blocked) {
59025+ sigdelset(&t->blocked, sig);
59026+ recalc_sigpending_and_wake(t);
59027+ }
59028+ }
59029+ if (action->sa.sa_handler == SIG_DFL)
59030+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
59031+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59032+
59033+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
59034+
59035+ return ret;
59036+}
59037+#endif
59038+
59039+#ifdef CONFIG_GRKERNSEC_BRUTE
59040+#define GR_USER_BAN_TIME (15 * 60)
59041+
59042+static int __get_dumpable(unsigned long mm_flags)
59043+{
59044+ int ret;
59045+
59046+ ret = mm_flags & MMF_DUMPABLE_MASK;
59047+ return (ret >= 2) ? 2 : ret;
59048+}
59049+#endif
59050+
59051+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59052+{
59053+#ifdef CONFIG_GRKERNSEC_BRUTE
59054+ uid_t uid = 0;
59055+
59056+ rcu_read_lock();
59057+ read_lock(&tasklist_lock);
59058+ read_lock(&grsec_exec_file_lock);
59059+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59060+ p->real_parent->brute = 1;
59061+ else {
59062+ const struct cred *cred = __task_cred(p), *cred2;
59063+ struct task_struct *tsk, *tsk2;
59064+
59065+ if (!__get_dumpable(mm_flags) && cred->uid) {
59066+ struct user_struct *user;
59067+
59068+ uid = cred->uid;
59069+
59070+ /* this is put upon execution past expiration */
59071+ user = find_user(uid);
59072+ if (user == NULL)
59073+ goto unlock;
59074+ user->banned = 1;
59075+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59076+ if (user->ban_expires == ~0UL)
59077+ user->ban_expires--;
59078+
59079+ do_each_thread(tsk2, tsk) {
59080+ cred2 = __task_cred(tsk);
59081+ if (tsk != p && cred2->uid == uid)
59082+ gr_fake_force_sig(SIGKILL, tsk);
59083+ } while_each_thread(tsk2, tsk);
59084+ }
59085+ }
59086+unlock:
59087+ read_unlock(&grsec_exec_file_lock);
59088+ read_unlock(&tasklist_lock);
59089+ rcu_read_unlock();
59090+
59091+ if (uid)
59092+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
59093+
59094+#endif
59095+ return;
59096+}
59097+
59098+void gr_handle_brute_check(void)
59099+{
59100+#ifdef CONFIG_GRKERNSEC_BRUTE
59101+ if (current->brute)
59102+ msleep(30 * 1000);
59103+#endif
59104+ return;
59105+}
59106+
59107+void gr_handle_kernel_exploit(void)
59108+{
59109+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59110+ const struct cred *cred;
59111+ struct task_struct *tsk, *tsk2;
59112+ struct user_struct *user;
59113+ uid_t uid;
59114+
59115+ if (in_irq() || in_serving_softirq() || in_nmi())
59116+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59117+
59118+ uid = current_uid();
59119+
59120+ if (uid == 0)
59121+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59122+ else {
59123+ /* kill all the processes of this user, hold a reference
59124+ to their creds struct, and prevent them from creating
59125+ another process until system reset
59126+ */
59127+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
59128+ /* we intentionally leak this ref */
59129+ user = get_uid(current->cred->user);
59130+ if (user) {
59131+ user->banned = 1;
59132+ user->ban_expires = ~0UL;
59133+ }
59134+
59135+ read_lock(&tasklist_lock);
59136+ do_each_thread(tsk2, tsk) {
59137+ cred = __task_cred(tsk);
59138+ if (cred->uid == uid)
59139+ gr_fake_force_sig(SIGKILL, tsk);
59140+ } while_each_thread(tsk2, tsk);
59141+ read_unlock(&tasklist_lock);
59142+ }
59143+#endif
59144+}
59145+
59146+int __gr_process_user_ban(struct user_struct *user)
59147+{
59148+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59149+ if (unlikely(user->banned)) {
59150+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59151+ user->banned = 0;
59152+ user->ban_expires = 0;
59153+ free_uid(user);
59154+ } else
59155+ return -EPERM;
59156+ }
59157+#endif
59158+ return 0;
59159+}
59160+
59161+int gr_process_user_ban(void)
59162+{
59163+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59164+ return __gr_process_user_ban(current->cred->user);
59165+#endif
59166+ return 0;
59167+}
59168diff -urNp linux-2.6.39.1/grsecurity/grsec_sock.c linux-2.6.39.1/grsecurity/grsec_sock.c
59169--- linux-2.6.39.1/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
59170+++ linux-2.6.39.1/grsecurity/grsec_sock.c 2011-05-22 20:29:21.000000000 -0400
59171@@ -0,0 +1,244 @@
59172+#include <linux/kernel.h>
59173+#include <linux/module.h>
59174+#include <linux/sched.h>
59175+#include <linux/file.h>
59176+#include <linux/net.h>
59177+#include <linux/in.h>
59178+#include <linux/ip.h>
59179+#include <net/sock.h>
59180+#include <net/inet_sock.h>
59181+#include <linux/grsecurity.h>
59182+#include <linux/grinternal.h>
59183+#include <linux/gracl.h>
59184+
59185+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59186+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59187+
59188+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59189+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59190+
59191+#ifdef CONFIG_UNIX_MODULE
59192+EXPORT_SYMBOL(gr_acl_handle_unix);
59193+EXPORT_SYMBOL(gr_acl_handle_mknod);
59194+EXPORT_SYMBOL(gr_handle_chroot_unix);
59195+EXPORT_SYMBOL(gr_handle_create);
59196+#endif
59197+
59198+#ifdef CONFIG_GRKERNSEC
59199+#define gr_conn_table_size 32749
59200+struct conn_table_entry {
59201+ struct conn_table_entry *next;
59202+ struct signal_struct *sig;
59203+};
59204+
59205+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59206+DEFINE_SPINLOCK(gr_conn_table_lock);
59207+
59208+extern const char * gr_socktype_to_name(unsigned char type);
59209+extern const char * gr_proto_to_name(unsigned char proto);
59210+extern const char * gr_sockfamily_to_name(unsigned char family);
59211+
59212+static __inline__ int
59213+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59214+{
59215+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59216+}
59217+
59218+static __inline__ int
59219+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59220+ __u16 sport, __u16 dport)
59221+{
59222+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59223+ sig->gr_sport == sport && sig->gr_dport == dport))
59224+ return 1;
59225+ else
59226+ return 0;
59227+}
59228+
59229+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59230+{
59231+ struct conn_table_entry **match;
59232+ unsigned int index;
59233+
59234+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59235+ sig->gr_sport, sig->gr_dport,
59236+ gr_conn_table_size);
59237+
59238+ newent->sig = sig;
59239+
59240+ match = &gr_conn_table[index];
59241+ newent->next = *match;
59242+ *match = newent;
59243+
59244+ return;
59245+}
59246+
59247+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59248+{
59249+ struct conn_table_entry *match, *last = NULL;
59250+ unsigned int index;
59251+
59252+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59253+ sig->gr_sport, sig->gr_dport,
59254+ gr_conn_table_size);
59255+
59256+ match = gr_conn_table[index];
59257+ while (match && !conn_match(match->sig,
59258+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59259+ sig->gr_dport)) {
59260+ last = match;
59261+ match = match->next;
59262+ }
59263+
59264+ if (match) {
59265+ if (last)
59266+ last->next = match->next;
59267+ else
59268+ gr_conn_table[index] = NULL;
59269+ kfree(match);
59270+ }
59271+
59272+ return;
59273+}
59274+
59275+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59276+ __u16 sport, __u16 dport)
59277+{
59278+ struct conn_table_entry *match;
59279+ unsigned int index;
59280+
59281+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59282+
59283+ match = gr_conn_table[index];
59284+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59285+ match = match->next;
59286+
59287+ if (match)
59288+ return match->sig;
59289+ else
59290+ return NULL;
59291+}
59292+
59293+#endif
59294+
59295+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59296+{
59297+#ifdef CONFIG_GRKERNSEC
59298+ struct signal_struct *sig = task->signal;
59299+ struct conn_table_entry *newent;
59300+
59301+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59302+ if (newent == NULL)
59303+ return;
59304+ /* no bh lock needed since we are called with bh disabled */
59305+ spin_lock(&gr_conn_table_lock);
59306+ gr_del_task_from_ip_table_nolock(sig);
59307+ sig->gr_saddr = inet->inet_rcv_saddr;
59308+ sig->gr_daddr = inet->inet_daddr;
59309+ sig->gr_sport = inet->inet_sport;
59310+ sig->gr_dport = inet->inet_dport;
59311+ gr_add_to_task_ip_table_nolock(sig, newent);
59312+ spin_unlock(&gr_conn_table_lock);
59313+#endif
59314+ return;
59315+}
59316+
59317+void gr_del_task_from_ip_table(struct task_struct *task)
59318+{
59319+#ifdef CONFIG_GRKERNSEC
59320+ spin_lock_bh(&gr_conn_table_lock);
59321+ gr_del_task_from_ip_table_nolock(task->signal);
59322+ spin_unlock_bh(&gr_conn_table_lock);
59323+#endif
59324+ return;
59325+}
59326+
59327+void
59328+gr_attach_curr_ip(const struct sock *sk)
59329+{
59330+#ifdef CONFIG_GRKERNSEC
59331+ struct signal_struct *p, *set;
59332+ const struct inet_sock *inet = inet_sk(sk);
59333+
59334+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59335+ return;
59336+
59337+ set = current->signal;
59338+
59339+ spin_lock_bh(&gr_conn_table_lock);
59340+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59341+ inet->inet_dport, inet->inet_sport);
59342+ if (unlikely(p != NULL)) {
59343+ set->curr_ip = p->curr_ip;
59344+ set->used_accept = 1;
59345+ gr_del_task_from_ip_table_nolock(p);
59346+ spin_unlock_bh(&gr_conn_table_lock);
59347+ return;
59348+ }
59349+ spin_unlock_bh(&gr_conn_table_lock);
59350+
59351+ set->curr_ip = inet->inet_daddr;
59352+ set->used_accept = 1;
59353+#endif
59354+ return;
59355+}
59356+
59357+int
59358+gr_handle_sock_all(const int family, const int type, const int protocol)
59359+{
59360+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59361+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59362+ (family != AF_UNIX)) {
59363+ if (family == AF_INET)
59364+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59365+ else
59366+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59367+ return -EACCES;
59368+ }
59369+#endif
59370+ return 0;
59371+}
59372+
59373+int
59374+gr_handle_sock_server(const struct sockaddr *sck)
59375+{
59376+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59377+ if (grsec_enable_socket_server &&
59378+ in_group_p(grsec_socket_server_gid) &&
59379+ sck && (sck->sa_family != AF_UNIX) &&
59380+ (sck->sa_family != AF_LOCAL)) {
59381+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59382+ return -EACCES;
59383+ }
59384+#endif
59385+ return 0;
59386+}
59387+
59388+int
59389+gr_handle_sock_server_other(const struct sock *sck)
59390+{
59391+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59392+ if (grsec_enable_socket_server &&
59393+ in_group_p(grsec_socket_server_gid) &&
59394+ sck && (sck->sk_family != AF_UNIX) &&
59395+ (sck->sk_family != AF_LOCAL)) {
59396+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59397+ return -EACCES;
59398+ }
59399+#endif
59400+ return 0;
59401+}
59402+
59403+int
59404+gr_handle_sock_client(const struct sockaddr *sck)
59405+{
59406+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59407+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59408+ sck && (sck->sa_family != AF_UNIX) &&
59409+ (sck->sa_family != AF_LOCAL)) {
59410+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59411+ return -EACCES;
59412+ }
59413+#endif
59414+ return 0;
59415+}
59416diff -urNp linux-2.6.39.1/grsecurity/grsec_sysctl.c linux-2.6.39.1/grsecurity/grsec_sysctl.c
59417--- linux-2.6.39.1/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
59418+++ linux-2.6.39.1/grsecurity/grsec_sysctl.c 2011-05-22 19:41:42.000000000 -0400
59419@@ -0,0 +1,433 @@
59420+#include <linux/kernel.h>
59421+#include <linux/sched.h>
59422+#include <linux/sysctl.h>
59423+#include <linux/grsecurity.h>
59424+#include <linux/grinternal.h>
59425+
59426+int
59427+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59428+{
59429+#ifdef CONFIG_GRKERNSEC_SYSCTL
59430+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59431+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59432+ return -EACCES;
59433+ }
59434+#endif
59435+ return 0;
59436+}
59437+
59438+#ifdef CONFIG_GRKERNSEC_ROFS
59439+static int __maybe_unused one = 1;
59440+#endif
59441+
59442+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59443+struct ctl_table grsecurity_table[] = {
59444+#ifdef CONFIG_GRKERNSEC_SYSCTL
59445+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59446+#ifdef CONFIG_GRKERNSEC_IO
59447+ {
59448+ .procname = "disable_priv_io",
59449+ .data = &grsec_disable_privio,
59450+ .maxlen = sizeof(int),
59451+ .mode = 0600,
59452+ .proc_handler = &proc_dointvec,
59453+ },
59454+#endif
59455+#endif
59456+#ifdef CONFIG_GRKERNSEC_LINK
59457+ {
59458+ .procname = "linking_restrictions",
59459+ .data = &grsec_enable_link,
59460+ .maxlen = sizeof(int),
59461+ .mode = 0600,
59462+ .proc_handler = &proc_dointvec,
59463+ },
59464+#endif
59465+#ifdef CONFIG_GRKERNSEC_FIFO
59466+ {
59467+ .procname = "fifo_restrictions",
59468+ .data = &grsec_enable_fifo,
59469+ .maxlen = sizeof(int),
59470+ .mode = 0600,
59471+ .proc_handler = &proc_dointvec,
59472+ },
59473+#endif
59474+#ifdef CONFIG_GRKERNSEC_EXECVE
59475+ {
59476+ .procname = "execve_limiting",
59477+ .data = &grsec_enable_execve,
59478+ .maxlen = sizeof(int),
59479+ .mode = 0600,
59480+ .proc_handler = &proc_dointvec,
59481+ },
59482+#endif
59483+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59484+ {
59485+ .procname = "ip_blackhole",
59486+ .data = &grsec_enable_blackhole,
59487+ .maxlen = sizeof(int),
59488+ .mode = 0600,
59489+ .proc_handler = &proc_dointvec,
59490+ },
59491+ {
59492+ .procname = "lastack_retries",
59493+ .data = &grsec_lastack_retries,
59494+ .maxlen = sizeof(int),
59495+ .mode = 0600,
59496+ .proc_handler = &proc_dointvec,
59497+ },
59498+#endif
59499+#ifdef CONFIG_GRKERNSEC_EXECLOG
59500+ {
59501+ .procname = "exec_logging",
59502+ .data = &grsec_enable_execlog,
59503+ .maxlen = sizeof(int),
59504+ .mode = 0600,
59505+ .proc_handler = &proc_dointvec,
59506+ },
59507+#endif
59508+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59509+ {
59510+ .procname = "rwxmap_logging",
59511+ .data = &grsec_enable_log_rwxmaps,
59512+ .maxlen = sizeof(int),
59513+ .mode = 0600,
59514+ .proc_handler = &proc_dointvec,
59515+ },
59516+#endif
59517+#ifdef CONFIG_GRKERNSEC_SIGNAL
59518+ {
59519+ .procname = "signal_logging",
59520+ .data = &grsec_enable_signal,
59521+ .maxlen = sizeof(int),
59522+ .mode = 0600,
59523+ .proc_handler = &proc_dointvec,
59524+ },
59525+#endif
59526+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59527+ {
59528+ .procname = "forkfail_logging",
59529+ .data = &grsec_enable_forkfail,
59530+ .maxlen = sizeof(int),
59531+ .mode = 0600,
59532+ .proc_handler = &proc_dointvec,
59533+ },
59534+#endif
59535+#ifdef CONFIG_GRKERNSEC_TIME
59536+ {
59537+ .procname = "timechange_logging",
59538+ .data = &grsec_enable_time,
59539+ .maxlen = sizeof(int),
59540+ .mode = 0600,
59541+ .proc_handler = &proc_dointvec,
59542+ },
59543+#endif
59544+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59545+ {
59546+ .procname = "chroot_deny_shmat",
59547+ .data = &grsec_enable_chroot_shmat,
59548+ .maxlen = sizeof(int),
59549+ .mode = 0600,
59550+ .proc_handler = &proc_dointvec,
59551+ },
59552+#endif
59553+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59554+ {
59555+ .procname = "chroot_deny_unix",
59556+ .data = &grsec_enable_chroot_unix,
59557+ .maxlen = sizeof(int),
59558+ .mode = 0600,
59559+ .proc_handler = &proc_dointvec,
59560+ },
59561+#endif
59562+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59563+ {
59564+ .procname = "chroot_deny_mount",
59565+ .data = &grsec_enable_chroot_mount,
59566+ .maxlen = sizeof(int),
59567+ .mode = 0600,
59568+ .proc_handler = &proc_dointvec,
59569+ },
59570+#endif
59571+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59572+ {
59573+ .procname = "chroot_deny_fchdir",
59574+ .data = &grsec_enable_chroot_fchdir,
59575+ .maxlen = sizeof(int),
59576+ .mode = 0600,
59577+ .proc_handler = &proc_dointvec,
59578+ },
59579+#endif
59580+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59581+ {
59582+ .procname = "chroot_deny_chroot",
59583+ .data = &grsec_enable_chroot_double,
59584+ .maxlen = sizeof(int),
59585+ .mode = 0600,
59586+ .proc_handler = &proc_dointvec,
59587+ },
59588+#endif
59589+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59590+ {
59591+ .procname = "chroot_deny_pivot",
59592+ .data = &grsec_enable_chroot_pivot,
59593+ .maxlen = sizeof(int),
59594+ .mode = 0600,
59595+ .proc_handler = &proc_dointvec,
59596+ },
59597+#endif
59598+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59599+ {
59600+ .procname = "chroot_enforce_chdir",
59601+ .data = &grsec_enable_chroot_chdir,
59602+ .maxlen = sizeof(int),
59603+ .mode = 0600,
59604+ .proc_handler = &proc_dointvec,
59605+ },
59606+#endif
59607+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59608+ {
59609+ .procname = "chroot_deny_chmod",
59610+ .data = &grsec_enable_chroot_chmod,
59611+ .maxlen = sizeof(int),
59612+ .mode = 0600,
59613+ .proc_handler = &proc_dointvec,
59614+ },
59615+#endif
59616+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59617+ {
59618+ .procname = "chroot_deny_mknod",
59619+ .data = &grsec_enable_chroot_mknod,
59620+ .maxlen = sizeof(int),
59621+ .mode = 0600,
59622+ .proc_handler = &proc_dointvec,
59623+ },
59624+#endif
59625+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59626+ {
59627+ .procname = "chroot_restrict_nice",
59628+ .data = &grsec_enable_chroot_nice,
59629+ .maxlen = sizeof(int),
59630+ .mode = 0600,
59631+ .proc_handler = &proc_dointvec,
59632+ },
59633+#endif
59634+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59635+ {
59636+ .procname = "chroot_execlog",
59637+ .data = &grsec_enable_chroot_execlog,
59638+ .maxlen = sizeof(int),
59639+ .mode = 0600,
59640+ .proc_handler = &proc_dointvec,
59641+ },
59642+#endif
59643+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59644+ {
59645+ .procname = "chroot_caps",
59646+ .data = &grsec_enable_chroot_caps,
59647+ .maxlen = sizeof(int),
59648+ .mode = 0600,
59649+ .proc_handler = &proc_dointvec,
59650+ },
59651+#endif
59652+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59653+ {
59654+ .procname = "chroot_deny_sysctl",
59655+ .data = &grsec_enable_chroot_sysctl,
59656+ .maxlen = sizeof(int),
59657+ .mode = 0600,
59658+ .proc_handler = &proc_dointvec,
59659+ },
59660+#endif
59661+#ifdef CONFIG_GRKERNSEC_TPE
59662+ {
59663+ .procname = "tpe",
59664+ .data = &grsec_enable_tpe,
59665+ .maxlen = sizeof(int),
59666+ .mode = 0600,
59667+ .proc_handler = &proc_dointvec,
59668+ },
59669+ {
59670+ .procname = "tpe_gid",
59671+ .data = &grsec_tpe_gid,
59672+ .maxlen = sizeof(int),
59673+ .mode = 0600,
59674+ .proc_handler = &proc_dointvec,
59675+ },
59676+#endif
59677+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59678+ {
59679+ .procname = "tpe_invert",
59680+ .data = &grsec_enable_tpe_invert,
59681+ .maxlen = sizeof(int),
59682+ .mode = 0600,
59683+ .proc_handler = &proc_dointvec,
59684+ },
59685+#endif
59686+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59687+ {
59688+ .procname = "tpe_restrict_all",
59689+ .data = &grsec_enable_tpe_all,
59690+ .maxlen = sizeof(int),
59691+ .mode = 0600,
59692+ .proc_handler = &proc_dointvec,
59693+ },
59694+#endif
59695+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59696+ {
59697+ .procname = "socket_all",
59698+ .data = &grsec_enable_socket_all,
59699+ .maxlen = sizeof(int),
59700+ .mode = 0600,
59701+ .proc_handler = &proc_dointvec,
59702+ },
59703+ {
59704+ .procname = "socket_all_gid",
59705+ .data = &grsec_socket_all_gid,
59706+ .maxlen = sizeof(int),
59707+ .mode = 0600,
59708+ .proc_handler = &proc_dointvec,
59709+ },
59710+#endif
59711+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59712+ {
59713+ .procname = "socket_client",
59714+ .data = &grsec_enable_socket_client,
59715+ .maxlen = sizeof(int),
59716+ .mode = 0600,
59717+ .proc_handler = &proc_dointvec,
59718+ },
59719+ {
59720+ .procname = "socket_client_gid",
59721+ .data = &grsec_socket_client_gid,
59722+ .maxlen = sizeof(int),
59723+ .mode = 0600,
59724+ .proc_handler = &proc_dointvec,
59725+ },
59726+#endif
59727+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59728+ {
59729+ .procname = "socket_server",
59730+ .data = &grsec_enable_socket_server,
59731+ .maxlen = sizeof(int),
59732+ .mode = 0600,
59733+ .proc_handler = &proc_dointvec,
59734+ },
59735+ {
59736+ .procname = "socket_server_gid",
59737+ .data = &grsec_socket_server_gid,
59738+ .maxlen = sizeof(int),
59739+ .mode = 0600,
59740+ .proc_handler = &proc_dointvec,
59741+ },
59742+#endif
59743+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59744+ {
59745+ .procname = "audit_group",
59746+ .data = &grsec_enable_group,
59747+ .maxlen = sizeof(int),
59748+ .mode = 0600,
59749+ .proc_handler = &proc_dointvec,
59750+ },
59751+ {
59752+ .procname = "audit_gid",
59753+ .data = &grsec_audit_gid,
59754+ .maxlen = sizeof(int),
59755+ .mode = 0600,
59756+ .proc_handler = &proc_dointvec,
59757+ },
59758+#endif
59759+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59760+ {
59761+ .procname = "audit_chdir",
59762+ .data = &grsec_enable_chdir,
59763+ .maxlen = sizeof(int),
59764+ .mode = 0600,
59765+ .proc_handler = &proc_dointvec,
59766+ },
59767+#endif
59768+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59769+ {
59770+ .procname = "audit_mount",
59771+ .data = &grsec_enable_mount,
59772+ .maxlen = sizeof(int),
59773+ .mode = 0600,
59774+ .proc_handler = &proc_dointvec,
59775+ },
59776+#endif
59777+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59778+ {
59779+ .procname = "audit_textrel",
59780+ .data = &grsec_enable_audit_textrel,
59781+ .maxlen = sizeof(int),
59782+ .mode = 0600,
59783+ .proc_handler = &proc_dointvec,
59784+ },
59785+#endif
59786+#ifdef CONFIG_GRKERNSEC_DMESG
59787+ {
59788+ .procname = "dmesg",
59789+ .data = &grsec_enable_dmesg,
59790+ .maxlen = sizeof(int),
59791+ .mode = 0600,
59792+ .proc_handler = &proc_dointvec,
59793+ },
59794+#endif
59795+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59796+ {
59797+ .procname = "chroot_findtask",
59798+ .data = &grsec_enable_chroot_findtask,
59799+ .maxlen = sizeof(int),
59800+ .mode = 0600,
59801+ .proc_handler = &proc_dointvec,
59802+ },
59803+#endif
59804+#ifdef CONFIG_GRKERNSEC_RESLOG
59805+ {
59806+ .procname = "resource_logging",
59807+ .data = &grsec_resource_logging,
59808+ .maxlen = sizeof(int),
59809+ .mode = 0600,
59810+ .proc_handler = &proc_dointvec,
59811+ },
59812+#endif
59813+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59814+ {
59815+ .procname = "audit_ptrace",
59816+ .data = &grsec_enable_audit_ptrace,
59817+ .maxlen = sizeof(int),
59818+ .mode = 0600,
59819+ .proc_handler = &proc_dointvec,
59820+ },
59821+#endif
59822+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59823+ {
59824+ .procname = "harden_ptrace",
59825+ .data = &grsec_enable_harden_ptrace,
59826+ .maxlen = sizeof(int),
59827+ .mode = 0600,
59828+ .proc_handler = &proc_dointvec,
59829+ },
59830+#endif
59831+ {
59832+ .procname = "grsec_lock",
59833+ .data = &grsec_lock,
59834+ .maxlen = sizeof(int),
59835+ .mode = 0600,
59836+ .proc_handler = &proc_dointvec,
59837+ },
59838+#endif
59839+#ifdef CONFIG_GRKERNSEC_ROFS
59840+ {
59841+ .procname = "romount_protect",
59842+ .data = &grsec_enable_rofs,
59843+ .maxlen = sizeof(int),
59844+ .mode = 0600,
59845+ .proc_handler = &proc_dointvec_minmax,
59846+ .extra1 = &one,
59847+ .extra2 = &one,
59848+ },
59849+#endif
59850+ { }
59851+};
59852+#endif
59853diff -urNp linux-2.6.39.1/grsecurity/grsec_time.c linux-2.6.39.1/grsecurity/grsec_time.c
59854--- linux-2.6.39.1/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
59855+++ linux-2.6.39.1/grsecurity/grsec_time.c 2011-05-22 19:41:42.000000000 -0400
59856@@ -0,0 +1,16 @@
59857+#include <linux/kernel.h>
59858+#include <linux/sched.h>
59859+#include <linux/grinternal.h>
59860+#include <linux/module.h>
59861+
59862+void
59863+gr_log_timechange(void)
59864+{
59865+#ifdef CONFIG_GRKERNSEC_TIME
59866+ if (grsec_enable_time)
59867+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59868+#endif
59869+ return;
59870+}
59871+
59872+EXPORT_SYMBOL(gr_log_timechange);
59873diff -urNp linux-2.6.39.1/grsecurity/grsec_tpe.c linux-2.6.39.1/grsecurity/grsec_tpe.c
59874--- linux-2.6.39.1/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
59875+++ linux-2.6.39.1/grsecurity/grsec_tpe.c 2011-05-22 19:41:42.000000000 -0400
59876@@ -0,0 +1,39 @@
59877+#include <linux/kernel.h>
59878+#include <linux/sched.h>
59879+#include <linux/file.h>
59880+#include <linux/fs.h>
59881+#include <linux/grinternal.h>
59882+
59883+extern int gr_acl_tpe_check(void);
59884+
59885+int
59886+gr_tpe_allow(const struct file *file)
59887+{
59888+#ifdef CONFIG_GRKERNSEC
59889+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59890+ const struct cred *cred = current_cred();
59891+
59892+ if (cred->uid && ((grsec_enable_tpe &&
59893+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59894+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59895+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59896+#else
59897+ in_group_p(grsec_tpe_gid)
59898+#endif
59899+ ) || gr_acl_tpe_check()) &&
59900+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59901+ (inode->i_mode & S_IWOTH))))) {
59902+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59903+ return 0;
59904+ }
59905+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59906+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59907+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59908+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59909+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59910+ return 0;
59911+ }
59912+#endif
59913+#endif
59914+ return 1;
59915+}
59916diff -urNp linux-2.6.39.1/grsecurity/grsum.c linux-2.6.39.1/grsecurity/grsum.c
59917--- linux-2.6.39.1/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
59918+++ linux-2.6.39.1/grsecurity/grsum.c 2011-05-22 19:41:42.000000000 -0400
59919@@ -0,0 +1,61 @@
59920+#include <linux/err.h>
59921+#include <linux/kernel.h>
59922+#include <linux/sched.h>
59923+#include <linux/mm.h>
59924+#include <linux/scatterlist.h>
59925+#include <linux/crypto.h>
59926+#include <linux/gracl.h>
59927+
59928+
59929+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59930+#error "crypto and sha256 must be built into the kernel"
59931+#endif
59932+
59933+int
59934+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59935+{
59936+ char *p;
59937+ struct crypto_hash *tfm;
59938+ struct hash_desc desc;
59939+ struct scatterlist sg;
59940+ unsigned char temp_sum[GR_SHA_LEN];
59941+ volatile int retval = 0;
59942+ volatile int dummy = 0;
59943+ unsigned int i;
59944+
59945+ sg_init_table(&sg, 1);
59946+
59947+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59948+ if (IS_ERR(tfm)) {
59949+ /* should never happen, since sha256 should be built in */
59950+ return 1;
59951+ }
59952+
59953+ desc.tfm = tfm;
59954+ desc.flags = 0;
59955+
59956+ crypto_hash_init(&desc);
59957+
59958+ p = salt;
59959+ sg_set_buf(&sg, p, GR_SALT_LEN);
59960+ crypto_hash_update(&desc, &sg, sg.length);
59961+
59962+ p = entry->pw;
59963+ sg_set_buf(&sg, p, strlen(p));
59964+
59965+ crypto_hash_update(&desc, &sg, sg.length);
59966+
59967+ crypto_hash_final(&desc, temp_sum);
59968+
59969+ memset(entry->pw, 0, GR_PW_LEN);
59970+
59971+ for (i = 0; i < GR_SHA_LEN; i++)
59972+ if (sum[i] != temp_sum[i])
59973+ retval = 1;
59974+ else
59975+ dummy = 1; // waste a cycle
59976+
59977+ crypto_free_hash(tfm);
59978+
59979+ return retval;
59980+}
59981diff -urNp linux-2.6.39.1/grsecurity/Kconfig linux-2.6.39.1/grsecurity/Kconfig
59982--- linux-2.6.39.1/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
59983+++ linux-2.6.39.1/grsecurity/Kconfig 2011-06-13 21:34:34.000000000 -0400
59984@@ -0,0 +1,1045 @@
59985+#
59986+# grecurity configuration
59987+#
59988+
59989+menu "Grsecurity"
59990+
59991+config GRKERNSEC
59992+ bool "Grsecurity"
59993+ select CRYPTO
59994+ select CRYPTO_SHA256
59995+ help
59996+ If you say Y here, you will be able to configure many features
59997+ that will enhance the security of your system. It is highly
59998+ recommended that you say Y here and read through the help
59999+ for each option so that you fully understand the features and
60000+ can evaluate their usefulness for your machine.
60001+
60002+choice
60003+ prompt "Security Level"
60004+ depends on GRKERNSEC
60005+ default GRKERNSEC_CUSTOM
60006+
60007+config GRKERNSEC_LOW
60008+ bool "Low"
60009+ select GRKERNSEC_LINK
60010+ select GRKERNSEC_FIFO
60011+ select GRKERNSEC_EXECVE
60012+ select GRKERNSEC_RANDNET
60013+ select GRKERNSEC_DMESG
60014+ select GRKERNSEC_CHROOT
60015+ select GRKERNSEC_CHROOT_CHDIR
60016+
60017+ help
60018+ If you choose this option, several of the grsecurity options will
60019+ be enabled that will give you greater protection against a number
60020+ of attacks, while assuring that none of your software will have any
60021+ conflicts with the additional security measures. If you run a lot
60022+ of unusual software, or you are having problems with the higher
60023+ security levels, you should say Y here. With this option, the
60024+ following features are enabled:
60025+
60026+ - Linking restrictions
60027+ - FIFO restrictions
60028+ - Enforcing RLIMIT_NPROC on execve
60029+ - Restricted dmesg
60030+ - Enforced chdir("/") on chroot
60031+ - Runtime module disabling
60032+
60033+config GRKERNSEC_MEDIUM
60034+ bool "Medium"
60035+ select PAX
60036+ select PAX_EI_PAX
60037+ select PAX_PT_PAX_FLAGS
60038+ select PAX_HAVE_ACL_FLAGS
60039+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
60040+ select GRKERNSEC_CHROOT
60041+ select GRKERNSEC_CHROOT_SYSCTL
60042+ select GRKERNSEC_LINK
60043+ select GRKERNSEC_FIFO
60044+ select GRKERNSEC_EXECVE
60045+ select GRKERNSEC_DMESG
60046+ select GRKERNSEC_RANDNET
60047+ select GRKERNSEC_FORKFAIL
60048+ select GRKERNSEC_TIME
60049+ select GRKERNSEC_SIGNAL
60050+ select GRKERNSEC_CHROOT
60051+ select GRKERNSEC_CHROOT_UNIX
60052+ select GRKERNSEC_CHROOT_MOUNT
60053+ select GRKERNSEC_CHROOT_PIVOT
60054+ select GRKERNSEC_CHROOT_DOUBLE
60055+ select GRKERNSEC_CHROOT_CHDIR
60056+ select GRKERNSEC_CHROOT_MKNOD
60057+ select GRKERNSEC_PROC
60058+ select GRKERNSEC_PROC_USERGROUP
60059+ select PAX_RANDUSTACK
60060+ select PAX_ASLR
60061+ select PAX_RANDMMAP
60062+ select PAX_REFCOUNT if (X86 || SPARC64)
60063+ select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
60064+
60065+ help
60066+ If you say Y here, several features in addition to those included
60067+ in the low additional security level will be enabled. These
60068+ features provide even more security to your system, though in rare
60069+ cases they may be incompatible with very old or poorly written
60070+ software. If you enable this option, make sure that your auth
60071+ service (identd) is running as gid 1001. With this option,
60072+ the following features (in addition to those provided in the
60073+ low additional security level) will be enabled:
60074+
60075+ - Failed fork logging
60076+ - Time change logging
60077+ - Signal logging
60078+ - Deny mounts in chroot
60079+ - Deny double chrooting
60080+ - Deny sysctl writes in chroot
60081+ - Deny mknod in chroot
60082+ - Deny access to abstract AF_UNIX sockets out of chroot
60083+ - Deny pivot_root in chroot
60084+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
60085+ - /proc restrictions with special GID set to 10 (usually wheel)
60086+ - Address Space Layout Randomization (ASLR)
60087+ - Prevent exploitation of most refcount overflows
60088+ - Bounds checking of copying between the kernel and userland
60089+
60090+config GRKERNSEC_HIGH
60091+ bool "High"
60092+ select GRKERNSEC_LINK
60093+ select GRKERNSEC_FIFO
60094+ select GRKERNSEC_EXECVE
60095+ select GRKERNSEC_DMESG
60096+ select GRKERNSEC_FORKFAIL
60097+ select GRKERNSEC_TIME
60098+ select GRKERNSEC_SIGNAL
60099+ select GRKERNSEC_CHROOT
60100+ select GRKERNSEC_CHROOT_SHMAT
60101+ select GRKERNSEC_CHROOT_UNIX
60102+ select GRKERNSEC_CHROOT_MOUNT
60103+ select GRKERNSEC_CHROOT_FCHDIR
60104+ select GRKERNSEC_CHROOT_PIVOT
60105+ select GRKERNSEC_CHROOT_DOUBLE
60106+ select GRKERNSEC_CHROOT_CHDIR
60107+ select GRKERNSEC_CHROOT_MKNOD
60108+ select GRKERNSEC_CHROOT_CAPS
60109+ select GRKERNSEC_CHROOT_SYSCTL
60110+ select GRKERNSEC_CHROOT_FINDTASK
60111+ select GRKERNSEC_SYSFS_RESTRICT
60112+ select GRKERNSEC_PROC
60113+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
60114+ select GRKERNSEC_HIDESYM
60115+ select GRKERNSEC_BRUTE
60116+ select GRKERNSEC_PROC_USERGROUP
60117+ select GRKERNSEC_KMEM
60118+ select GRKERNSEC_RESLOG
60119+ select GRKERNSEC_RANDNET
60120+ select GRKERNSEC_PROC_ADD
60121+ select GRKERNSEC_CHROOT_CHMOD
60122+ select GRKERNSEC_CHROOT_NICE
60123+ select GRKERNSEC_AUDIT_MOUNT
60124+ select GRKERNSEC_MODHARDEN if (MODULES)
60125+ select GRKERNSEC_HARDEN_PTRACE
60126+ select GRKERNSEC_VM86 if (X86_32)
60127+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC32 || SPARC64)
60128+ select PAX
60129+ select PAX_RANDUSTACK
60130+ select PAX_ASLR
60131+ select PAX_RANDMMAP
60132+ select PAX_NOEXEC
60133+ select PAX_MPROTECT
60134+ select PAX_EI_PAX
60135+ select PAX_PT_PAX_FLAGS
60136+ select PAX_HAVE_ACL_FLAGS
60137+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
60138+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
60139+ select PAX_RANDKSTACK if (X86_TSC && X86)
60140+ select PAX_SEGMEXEC if (X86_32)
60141+ select PAX_PAGEEXEC
60142+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
60143+ select PAX_EMUTRAMP if (PARISC)
60144+ select PAX_EMUSIGRT if (PARISC)
60145+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
60146+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
60147+ select PAX_REFCOUNT if (X86 || SPARC64)
60148+ select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
60149+ help
60150+ If you say Y here, many of the features of grsecurity will be
60151+ enabled, which will protect you against many kinds of attacks
60152+ against your system. The heightened security comes at a cost
60153+ of an increased chance of incompatibilities with rare software
60154+ on your machine. Since this security level enables PaX, you should
60155+ view <http://pax.grsecurity.net> and read about the PaX
60156+ project. While you are there, download chpax and run it on
60157+ binaries that cause problems with PaX. Also remember that
60158+ since the /proc restrictions are enabled, you must run your
60159+ identd as gid 1001. This security level enables the following
60160+ features in addition to those listed in the low and medium
60161+ security levels:
60162+
60163+ - Additional /proc restrictions
60164+ - Chmod restrictions in chroot
60165+ - No signals, ptrace, or viewing of processes outside of chroot
60166+ - Capability restrictions in chroot
60167+ - Deny fchdir out of chroot
60168+ - Priority restrictions in chroot
60169+ - Segmentation-based implementation of PaX
60170+ - Mprotect restrictions
60171+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
60172+ - Kernel stack randomization
60173+ - Mount/unmount/remount logging
60174+ - Kernel symbol hiding
60175+ - Prevention of memory exhaustion-based exploits
60176+ - Hardening of module auto-loading
60177+ - Ptrace restrictions
60178+ - Restricted vm86 mode
60179+ - Restricted sysfs/debugfs
60180+ - Active kernel exploit response
60181+
60182+config GRKERNSEC_CUSTOM
60183+ bool "Custom"
60184+ help
60185+ If you say Y here, you will be able to configure every grsecurity
60186+ option, which allows you to enable many more features that aren't
60187+ covered in the basic security levels. These additional features
60188+ include TPE, socket restrictions, and the sysctl system for
60189+ grsecurity. It is advised that you read through the help for
60190+ each option to determine its usefulness in your situation.
60191+
60192+endchoice
60193+
60194+menu "Address Space Protection"
60195+depends on GRKERNSEC
60196+
60197+config GRKERNSEC_KMEM
60198+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
60199+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60200+ help
60201+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60202+ be written to via mmap or otherwise to modify the running kernel.
60203+ /dev/port will also not be allowed to be opened. If you have module
60204+ support disabled, enabling this will close up four ways that are
60205+ currently used to insert malicious code into the running kernel.
60206+ Even with all these features enabled, we still highly recommend that
60207+ you use the RBAC system, as it is still possible for an attacker to
60208+ modify the running kernel through privileged I/O granted by ioperm/iopl.
60209+ If you are not using XFree86, you may be able to stop this additional
60210+ case by enabling the 'Disable privileged I/O' option. Though nothing
60211+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60212+ but only to video memory, which is the only writing we allow in this
60213+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60214+ not be allowed to mprotect it with PROT_WRITE later.
60215+ It is highly recommended that you say Y here if you meet all the
60216+ conditions above.
60217+
60218+config GRKERNSEC_VM86
60219+ bool "Restrict VM86 mode"
60220+ depends on X86_32
60221+
60222+ help
60223+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60224+ make use of a special execution mode on 32bit x86 processors called
60225+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60226+ video cards and will still work with this option enabled. The purpose
60227+ of the option is to prevent exploitation of emulation errors in
60228+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
60229+ Nearly all users should be able to enable this option.
60230+
60231+config GRKERNSEC_IO
60232+ bool "Disable privileged I/O"
60233+ depends on X86
60234+ select RTC_CLASS
60235+ select RTC_INTF_DEV
60236+ select RTC_DRV_CMOS
60237+
60238+ help
60239+ If you say Y here, all ioperm and iopl calls will return an error.
60240+ Ioperm and iopl can be used to modify the running kernel.
60241+ Unfortunately, some programs need this access to operate properly,
60242+ the most notable of which are XFree86 and hwclock. hwclock can be
60243+ remedied by having RTC support in the kernel, so real-time
60244+ clock support is enabled if this option is enabled, to ensure
60245+ that hwclock operates correctly. XFree86 still will not
60246+ operate correctly with this option enabled, so DO NOT CHOOSE Y
60247+ IF YOU USE XFree86. If you use XFree86 and you still want to
60248+ protect your kernel against modification, use the RBAC system.
60249+
60250+config GRKERNSEC_PROC_MEMMAP
60251+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
60252+ default y if (PAX_NOEXEC || PAX_ASLR)
60253+ depends on PAX_NOEXEC || PAX_ASLR
60254+ help
60255+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
60256+ give no information about the addresses of its mappings if
60257+ PaX features that rely on random addresses are enabled on the task.
60258+ If you use PaX it is greatly recommended that you say Y here as it
60259+ closes up a hole that makes the full ASLR useless for suid
60260+ binaries.
60261+
60262+config GRKERNSEC_BRUTE
60263+ bool "Deter exploit bruteforcing"
60264+ help
60265+ If you say Y here, attempts to bruteforce exploits against forking
60266+ daemons such as apache or sshd, as well as against suid/sgid binaries
60267+ will be deterred. When a child of a forking daemon is killed by PaX
60268+ or crashes due to an illegal instruction or other suspicious signal,
60269+ the parent process will be delayed 30 seconds upon every subsequent
60270+ fork until the administrator is able to assess the situation and
60271+ restart the daemon.
60272+ In the suid/sgid case, the attempt is logged, the user has all their
60273+ processes terminated, and they are prevented from executing any further
60274+ processes for 15 minutes.
60275+ It is recommended that you also enable signal logging in the auditing
60276+ section so that logs are generated when a process triggers a suspicious
60277+ signal.
60278+
60279+config GRKERNSEC_MODHARDEN
60280+ bool "Harden module auto-loading"
60281+ depends on MODULES
60282+ help
60283+ If you say Y here, module auto-loading in response to use of some
60284+ feature implemented by an unloaded module will be restricted to
60285+ root users. Enabling this option helps defend against attacks
60286+ by unprivileged users who abuse the auto-loading behavior to
60287+ cause a vulnerable module to load that is then exploited.
60288+
60289+ If this option prevents a legitimate use of auto-loading for a
60290+ non-root user, the administrator can execute modprobe manually
60291+ with the exact name of the module mentioned in the alert log.
60292+ Alternatively, the administrator can add the module to the list
60293+ of modules loaded at boot by modifying init scripts.
60294+
60295+ Modification of init scripts will most likely be needed on
60296+ Ubuntu servers with encrypted home directory support enabled,
60297+ as the first non-root user logging in will cause the ecb(aes),
60298+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
60299+
60300+config GRKERNSEC_HIDESYM
60301+ bool "Hide kernel symbols"
60302+ help
60303+ If you say Y here, getting information on loaded modules, and
60304+ displaying all kernel symbols through a syscall will be restricted
60305+ to users with CAP_SYS_MODULE. For software compatibility reasons,
60306+ /proc/kallsyms will be restricted to the root user. The RBAC
60307+ system can hide that entry even from root.
60308+
60309+ This option also prevents leaking of kernel addresses through
60310+ several /proc entries.
60311+
60312+ Note that this option is only effective provided the following
60313+ conditions are met:
60314+ 1) The kernel using grsecurity is not precompiled by some distribution
60315+ 2) You have also enabled GRKERNSEC_DMESG
60316+ 3) You are using the RBAC system and hiding other files such as your
60317+ kernel image and System.map. Alternatively, enabling this option
60318+ causes the permissions on /boot, /lib/modules, and the kernel
60319+ source directory to change at compile time to prevent
60320+ reading by non-root users.
60321+ If the above conditions are met, this option will aid in providing a
60322+ useful protection against local kernel exploitation of overflows
60323+ and arbitrary read/write vulnerabilities.
60324+
60325+config GRKERNSEC_KERN_LOCKOUT
60326+ bool "Active kernel exploit response"
60327+ depends on X86 || ARM || PPC || SPARC32 || SPARC64
60328+ help
60329+ If you say Y here, when a PaX alert is triggered due to suspicious
60330+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
60331+ or an OOPs occurs due to bad memory accesses, instead of just
60332+ terminating the offending process (and potentially allowing
60333+ a subsequent exploit from the same user), we will take one of two
60334+ actions:
60335+ If the user was root, we will panic the system
60336+ If the user was non-root, we will log the attempt, terminate
60337+ all processes owned by the user, then prevent them from creating
60338+ any new processes until the system is restarted
60339+ This deters repeated kernel exploitation/bruteforcing attempts
60340+ and is useful for later forensics.
60341+
60342+endmenu
60343+menu "Role Based Access Control Options"
60344+depends on GRKERNSEC
60345+
60346+config GRKERNSEC_RBAC_DEBUG
60347+ bool
60348+
60349+config GRKERNSEC_NO_RBAC
60350+ bool "Disable RBAC system"
60351+ help
60352+ If you say Y here, the /dev/grsec device will be removed from the kernel,
60353+ preventing the RBAC system from being enabled. You should only say Y
60354+ here if you have no intention of using the RBAC system, so as to prevent
60355+ an attacker with root access from misusing the RBAC system to hide files
60356+ and processes when loadable module support and /dev/[k]mem have been
60357+ locked down.
60358+
60359+config GRKERNSEC_ACL_HIDEKERN
60360+ bool "Hide kernel processes"
60361+ help
60362+ If you say Y here, all kernel threads will be hidden to all
60363+ processes but those whose subject has the "view hidden processes"
60364+ flag.
60365+
60366+config GRKERNSEC_ACL_MAXTRIES
60367+ int "Maximum tries before password lockout"
60368+ default 3
60369+ help
60370+ This option enforces the maximum number of times a user can attempt
60371+ to authorize themselves with the grsecurity RBAC system before being
60372+ denied the ability to attempt authorization again for a specified time.
60373+ The lower the number, the harder it will be to brute-force a password.
60374+
60375+config GRKERNSEC_ACL_TIMEOUT
60376+ int "Time to wait after max password tries, in seconds"
60377+ default 30
60378+ help
60379+ This option specifies the time the user must wait after attempting to
60380+ authorize to the RBAC system with the maximum number of invalid
60381+ passwords. The higher the number, the harder it will be to brute-force
60382+ a password.
60383+
60384+endmenu
60385+menu "Filesystem Protections"
60386+depends on GRKERNSEC
60387+
60388+config GRKERNSEC_PROC
60389+ bool "Proc restrictions"
60390+ help
60391+ If you say Y here, the permissions of the /proc filesystem
60392+ will be altered to enhance system security and privacy. You MUST
60393+ choose either a user only restriction or a user and group restriction.
60394+ Depending upon the option you choose, you can either restrict users to
60395+ see only the processes they themselves run, or choose a group that can
60396+ view all processes and files normally restricted to root if you choose
60397+ the "restrict to user only" option. NOTE: If you're running identd as
60398+ a non-root user, you will have to run it as the group you specify here.
60399+
60400+config GRKERNSEC_PROC_USER
60401+ bool "Restrict /proc to user only"
60402+ depends on GRKERNSEC_PROC
60403+ help
60404+ If you say Y here, non-root users will only be able to view their own
60405+ processes, and restricts them from viewing network-related information,
60406+ and viewing kernel symbol and module information.
60407+
60408+config GRKERNSEC_PROC_USERGROUP
60409+ bool "Allow special group"
60410+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
60411+ help
60412+ If you say Y here, you will be able to select a group that will be
60413+ able to view all processes and network-related information. If you've
60414+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
60415+ remain hidden. This option is useful if you want to run identd as
60416+ a non-root user.
60417+
60418+config GRKERNSEC_PROC_GID
60419+ int "GID for special group"
60420+ depends on GRKERNSEC_PROC_USERGROUP
60421+ default 1001
60422+
60423+config GRKERNSEC_PROC_ADD
60424+ bool "Additional restrictions"
60425+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
60426+ help
60427+ If you say Y here, additional restrictions will be placed on
60428+ /proc that keep normal users from viewing device information and
60429+ slabinfo information that could be useful for exploits.
60430+
60431+config GRKERNSEC_LINK
60432+ bool "Linking restrictions"
60433+ help
60434+ If you say Y here, /tmp race exploits will be prevented, since users
60435+ will no longer be able to follow symlinks owned by other users in
60436+ world-writable +t directories (e.g. /tmp), unless the owner of the
60437+ symlink is the owner of the directory. users will also not be
60438+ able to hardlink to files they do not own. If the sysctl option is
60439+ enabled, a sysctl option with name "linking_restrictions" is created.
60440+
60441+config GRKERNSEC_FIFO
60442+ bool "FIFO restrictions"
60443+ help
60444+ If you say Y here, users will not be able to write to FIFOs they don't
60445+ own in world-writable +t directories (e.g. /tmp), unless the owner of
60446+ the FIFO is the same owner of the directory it's held in. If the sysctl
60447+ option is enabled, a sysctl option with name "fifo_restrictions" is
60448+ created.
60449+
60450+config GRKERNSEC_SYSFS_RESTRICT
60451+ bool "Sysfs/debugfs restriction"
60452+ depends on SYSFS
60453+ help
60454+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
60455+ any filesystem normally mounted under it (e.g. debugfs) will only
60456+ be accessible by root. These filesystems generally provide access
60457+ to hardware and debug information that isn't appropriate for unprivileged
60458+ users of the system. Sysfs and debugfs have also become a large source
60459+ of new vulnerabilities, ranging from infoleaks to local compromise.
60460+ There has been very little oversight with an eye toward security involved
60461+ in adding new exporters of information to these filesystems, so their
60462+ use is discouraged.
60463+ This option is equivalent to a chmod 0700 of the mount paths.
60464+
60465+config GRKERNSEC_ROFS
60466+ bool "Runtime read-only mount protection"
60467+ help
60468+ If you say Y here, a sysctl option with name "romount_protect" will
60469+ be created. By setting this option to 1 at runtime, filesystems
60470+ will be protected in the following ways:
60471+ * No new writable mounts will be allowed
60472+ * Existing read-only mounts won't be able to be remounted read/write
60473+ * Write operations will be denied on all block devices
60474+ This option acts independently of grsec_lock: once it is set to 1,
60475+ it cannot be turned off. Therefore, please be mindful of the resulting
60476+ behavior if this option is enabled in an init script on a read-only
60477+ filesystem. This feature is mainly intended for secure embedded systems.
60478+
60479+config GRKERNSEC_CHROOT
60480+ bool "Chroot jail restrictions"
60481+ help
60482+ If you say Y here, you will be able to choose several options that will
60483+ make breaking out of a chrooted jail much more difficult. If you
60484+ encounter no software incompatibilities with the following options, it
60485+ is recommended that you enable each one.
60486+
60487+config GRKERNSEC_CHROOT_MOUNT
60488+ bool "Deny mounts"
60489+ depends on GRKERNSEC_CHROOT
60490+ help
60491+ If you say Y here, processes inside a chroot will not be able to
60492+ mount or remount filesystems. If the sysctl option is enabled, a
60493+ sysctl option with name "chroot_deny_mount" is created.
60494+
60495+config GRKERNSEC_CHROOT_DOUBLE
60496+ bool "Deny double-chroots"
60497+ depends on GRKERNSEC_CHROOT
60498+ help
60499+ If you say Y here, processes inside a chroot will not be able to chroot
60500+ again outside the chroot. This is a widely used method of breaking
60501+ out of a chroot jail and should not be allowed. If the sysctl
60502+ option is enabled, a sysctl option with name
60503+ "chroot_deny_chroot" is created.
60504+
60505+config GRKERNSEC_CHROOT_PIVOT
60506+ bool "Deny pivot_root in chroot"
60507+ depends on GRKERNSEC_CHROOT
60508+ help
60509+ If you say Y here, processes inside a chroot will not be able to use
60510+ a function called pivot_root() that was introduced in Linux 2.3.41. It
60511+ works similar to chroot in that it changes the root filesystem. This
60512+ function could be misused in a chrooted process to attempt to break out
60513+ of the chroot, and therefore should not be allowed. If the sysctl
60514+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
60515+ created.
60516+
60517+config GRKERNSEC_CHROOT_CHDIR
60518+ bool "Enforce chdir(\"/\") on all chroots"
60519+ depends on GRKERNSEC_CHROOT
60520+ help
60521+ If you say Y here, the current working directory of all newly-chrooted
60522+ applications will be set to the the root directory of the chroot.
60523+ The man page on chroot(2) states:
60524+ Note that this call does not change the current working
60525+ directory, so that `.' can be outside the tree rooted at
60526+ `/'. In particular, the super-user can escape from a
60527+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
60528+
60529+ It is recommended that you say Y here, since it's not known to break
60530+ any software. If the sysctl option is enabled, a sysctl option with
60531+ name "chroot_enforce_chdir" is created.
60532+
60533+config GRKERNSEC_CHROOT_CHMOD
60534+ bool "Deny (f)chmod +s"
60535+ depends on GRKERNSEC_CHROOT
60536+ help
60537+ If you say Y here, processes inside a chroot will not be able to chmod
60538+ or fchmod files to make them have suid or sgid bits. This protects
60539+ against another published method of breaking a chroot. If the sysctl
60540+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
60541+ created.
60542+
60543+config GRKERNSEC_CHROOT_FCHDIR
60544+ bool "Deny fchdir out of chroot"
60545+ depends on GRKERNSEC_CHROOT
60546+ help
60547+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
60548+ to a file descriptor of the chrooting process that points to a directory
60549+ outside the filesystem will be stopped. If the sysctl option
60550+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
60551+
60552+config GRKERNSEC_CHROOT_MKNOD
60553+ bool "Deny mknod"
60554+ depends on GRKERNSEC_CHROOT
60555+ help
60556+ If you say Y here, processes inside a chroot will not be allowed to
60557+ mknod. The problem with using mknod inside a chroot is that it
60558+ would allow an attacker to create a device entry that is the same
60559+ as one on the physical root of your system, which could range from
60560+ anything from the console device to a device for your harddrive (which
60561+ they could then use to wipe the drive or steal data). It is recommended
60562+ that you say Y here, unless you run into software incompatibilities.
60563+ If the sysctl option is enabled, a sysctl option with name
60564+ "chroot_deny_mknod" is created.
60565+
60566+config GRKERNSEC_CHROOT_SHMAT
60567+ bool "Deny shmat() out of chroot"
60568+ depends on GRKERNSEC_CHROOT
60569+ help
60570+ If you say Y here, processes inside a chroot will not be able to attach
60571+ to shared memory segments that were created outside of the chroot jail.
60572+ It is recommended that you say Y here. If the sysctl option is enabled,
60573+ a sysctl option with name "chroot_deny_shmat" is created.
60574+
60575+config GRKERNSEC_CHROOT_UNIX
60576+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
60577+ depends on GRKERNSEC_CHROOT
60578+ help
60579+ If you say Y here, processes inside a chroot will not be able to
60580+ connect to abstract (meaning not belonging to a filesystem) Unix
60581+ domain sockets that were bound outside of a chroot. It is recommended
60582+ that you say Y here. If the sysctl option is enabled, a sysctl option
60583+ with name "chroot_deny_unix" is created.
60584+
60585+config GRKERNSEC_CHROOT_FINDTASK
60586+ bool "Protect outside processes"
60587+ depends on GRKERNSEC_CHROOT
60588+ help
60589+ If you say Y here, processes inside a chroot will not be able to
60590+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
60591+ getsid, or view any process outside of the chroot. If the sysctl
60592+ option is enabled, a sysctl option with name "chroot_findtask" is
60593+ created.
60594+
60595+config GRKERNSEC_CHROOT_NICE
60596+ bool "Restrict priority changes"
60597+ depends on GRKERNSEC_CHROOT
60598+ help
60599+ If you say Y here, processes inside a chroot will not be able to raise
60600+ the priority of processes in the chroot, or alter the priority of
60601+ processes outside the chroot. This provides more security than simply
60602+ removing CAP_SYS_NICE from the process' capability set. If the
60603+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
60604+ is created.
60605+
60606+config GRKERNSEC_CHROOT_SYSCTL
60607+ bool "Deny sysctl writes"
60608+ depends on GRKERNSEC_CHROOT
60609+ help
60610+ If you say Y here, an attacker in a chroot will not be able to
60611+ write to sysctl entries, either by sysctl(2) or through a /proc
60612+ interface. It is strongly recommended that you say Y here. If the
60613+ sysctl option is enabled, a sysctl option with name
60614+ "chroot_deny_sysctl" is created.
60615+
60616+config GRKERNSEC_CHROOT_CAPS
60617+ bool "Capability restrictions"
60618+ depends on GRKERNSEC_CHROOT
60619+ help
60620+ If you say Y here, the capabilities on all root processes within a
60621+ chroot jail will be lowered to stop module insertion, raw i/o,
60622+ system and net admin tasks, rebooting the system, modifying immutable
60623+ files, modifying IPC owned by another, and changing the system time.
60624+ This is left an option because it can break some apps. Disable this
60625+ if your chrooted apps are having problems performing those kinds of
60626+ tasks. If the sysctl option is enabled, a sysctl option with
60627+ name "chroot_caps" is created.
60628+
60629+endmenu
60630+menu "Kernel Auditing"
60631+depends on GRKERNSEC
60632+
60633+config GRKERNSEC_AUDIT_GROUP
60634+ bool "Single group for auditing"
60635+ help
60636+ If you say Y here, the exec, chdir, and (un)mount logging features
60637+ will only operate on a group you specify. This option is recommended
60638+ if you only want to watch certain users instead of having a large
60639+ amount of logs from the entire system. If the sysctl option is enabled,
60640+ a sysctl option with name "audit_group" is created.
60641+
60642+config GRKERNSEC_AUDIT_GID
60643+ int "GID for auditing"
60644+ depends on GRKERNSEC_AUDIT_GROUP
60645+ default 1007
60646+
60647+config GRKERNSEC_EXECLOG
60648+ bool "Exec logging"
60649+ help
60650+ If you say Y here, all execve() calls will be logged (since the
60651+ other exec*() calls are frontends to execve(), all execution
60652+ will be logged). Useful for shell-servers that like to keep track
60653+ of their users. If the sysctl option is enabled, a sysctl option with
60654+ name "exec_logging" is created.
60655+ WARNING: This option when enabled will produce a LOT of logs, especially
60656+ on an active system.
60657+
60658+config GRKERNSEC_RESLOG
60659+ bool "Resource logging"
60660+ help
60661+ If you say Y here, all attempts to overstep resource limits will
60662+ be logged with the resource name, the requested size, and the current
60663+ limit. It is highly recommended that you say Y here. If the sysctl
60664+ option is enabled, a sysctl option with name "resource_logging" is
60665+ created. If the RBAC system is enabled, the sysctl value is ignored.
60666+
60667+config GRKERNSEC_CHROOT_EXECLOG
60668+ bool "Log execs within chroot"
60669+ help
60670+ If you say Y here, all executions inside a chroot jail will be logged
60671+ to syslog. This can cause a large amount of logs if certain
60672+ applications (eg. djb's daemontools) are installed on the system, and
60673+ is therefore left as an option. If the sysctl option is enabled, a
60674+ sysctl option with name "chroot_execlog" is created.
60675+
60676+config GRKERNSEC_AUDIT_PTRACE
60677+ bool "Ptrace logging"
60678+ help
60679+ If you say Y here, all attempts to attach to a process via ptrace
60680+ will be logged. If the sysctl option is enabled, a sysctl option
60681+ with name "audit_ptrace" is created.
60682+
60683+config GRKERNSEC_AUDIT_CHDIR
60684+ bool "Chdir logging"
60685+ help
60686+ If you say Y here, all chdir() calls will be logged. If the sysctl
60687+ option is enabled, a sysctl option with name "audit_chdir" is created.
60688+
60689+config GRKERNSEC_AUDIT_MOUNT
60690+ bool "(Un)Mount logging"
60691+ help
60692+ If you say Y here, all mounts and unmounts will be logged. If the
60693+ sysctl option is enabled, a sysctl option with name "audit_mount" is
60694+ created.
60695+
60696+config GRKERNSEC_SIGNAL
60697+ bool "Signal logging"
60698+ help
60699+ If you say Y here, certain important signals will be logged, such as
60700+ SIGSEGV, which will as a result inform you of when a error in a program
60701+ occurred, which in some cases could mean a possible exploit attempt.
60702+ If the sysctl option is enabled, a sysctl option with name
60703+ "signal_logging" is created.
60704+
60705+config GRKERNSEC_FORKFAIL
60706+ bool "Fork failure logging"
60707+ help
60708+ If you say Y here, all failed fork() attempts will be logged.
60709+ This could suggest a fork bomb, or someone attempting to overstep
60710+ their process limit. If the sysctl option is enabled, a sysctl option
60711+ with name "forkfail_logging" is created.
60712+
60713+config GRKERNSEC_TIME
60714+ bool "Time change logging"
60715+ help
60716+ If you say Y here, any changes of the system clock will be logged.
60717+ If the sysctl option is enabled, a sysctl option with name
60718+ "timechange_logging" is created.
60719+
60720+config GRKERNSEC_PROC_IPADDR
60721+ bool "/proc/<pid>/ipaddr support"
60722+ help
60723+ If you say Y here, a new entry will be added to each /proc/<pid>
60724+ directory that contains the IP address of the person using the task.
60725+ The IP is carried across local TCP and AF_UNIX stream sockets.
60726+ This information can be useful for IDS/IPSes to perform remote response
60727+ to a local attack. The entry is readable by only the owner of the
60728+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
60729+ the RBAC system), and thus does not create privacy concerns.
60730+
60731+config GRKERNSEC_RWXMAP_LOG
60732+ bool 'Denied RWX mmap/mprotect logging'
60733+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
60734+ help
60735+ If you say Y here, calls to mmap() and mprotect() with explicit
60736+ usage of PROT_WRITE and PROT_EXEC together will be logged when
60737+ denied by the PAX_MPROTECT feature. If the sysctl option is
60738+ enabled, a sysctl option with name "rwxmap_logging" is created.
60739+
60740+config GRKERNSEC_AUDIT_TEXTREL
60741+ bool 'ELF text relocations logging (READ HELP)'
60742+ depends on PAX_MPROTECT
60743+ help
60744+ If you say Y here, text relocations will be logged with the filename
60745+ of the offending library or binary. The purpose of the feature is
60746+ to help Linux distribution developers get rid of libraries and
60747+ binaries that need text relocations which hinder the future progress
60748+ of PaX. Only Linux distribution developers should say Y here, and
60749+ never on a production machine, as this option creates an information
60750+ leak that could aid an attacker in defeating the randomization of
60751+ a single memory region. If the sysctl option is enabled, a sysctl
60752+ option with name "audit_textrel" is created.
60753+
60754+endmenu
60755+
60756+menu "Executable Protections"
60757+depends on GRKERNSEC
60758+
60759+config GRKERNSEC_EXECVE
60760+ bool "Enforce RLIMIT_NPROC on execs"
60761+ help
60762+ If you say Y here, users with a resource limit on processes will
60763+ have the value checked during execve() calls. The current system
60764+ only checks the system limit during fork() calls. If the sysctl option
60765+ is enabled, a sysctl option with name "execve_limiting" is created.
60766+
60767+config GRKERNSEC_DMESG
60768+ bool "Dmesg(8) restriction"
60769+ help
60770+ If you say Y here, non-root users will not be able to use dmesg(8)
60771+ to view up to the last 4kb of messages in the kernel's log buffer.
60772+ The kernel's log buffer often contains kernel addresses and other
60773+ identifying information useful to an attacker in fingerprinting a
60774+ system for a targeted exploit.
60775+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
60776+ created.
60777+
60778+config GRKERNSEC_HARDEN_PTRACE
60779+ bool "Deter ptrace-based process snooping"
60780+ help
60781+ If you say Y here, TTY sniffers and other malicious monitoring
60782+ programs implemented through ptrace will be defeated. If you
60783+ have been using the RBAC system, this option has already been
60784+ enabled for several years for all users, with the ability to make
60785+ fine-grained exceptions.
60786+
60787+ This option only affects the ability of non-root users to ptrace
60788+ processes that are not a descendent of the ptracing process.
60789+ This means that strace ./binary and gdb ./binary will still work,
60790+ but attaching to arbitrary processes will not. If the sysctl
60791+ option is enabled, a sysctl option with name "harden_ptrace" is
60792+ created.
60793+
60794+config GRKERNSEC_TPE
60795+ bool "Trusted Path Execution (TPE)"
60796+ help
60797+ If you say Y here, you will be able to choose a gid to add to the
60798+ supplementary groups of users you want to mark as "untrusted."
60799+ These users will not be able to execute any files that are not in
60800+ root-owned directories writable only by root. If the sysctl option
60801+ is enabled, a sysctl option with name "tpe" is created.
60802+
60803+config GRKERNSEC_TPE_ALL
60804+ bool "Partially restrict all non-root users"
60805+ depends on GRKERNSEC_TPE
60806+ help
60807+ If you say Y here, all non-root users will be covered under
60808+ a weaker TPE restriction. This is separate from, and in addition to,
60809+ the main TPE options that you have selected elsewhere. Thus, if a
60810+ "trusted" GID is chosen, this restriction applies to even that GID.
60811+ Under this restriction, all non-root users will only be allowed to
60812+ execute files in directories they own that are not group or
60813+ world-writable, or in directories owned by root and writable only by
60814+ root. If the sysctl option is enabled, a sysctl option with name
60815+ "tpe_restrict_all" is created.
60816+
60817+config GRKERNSEC_TPE_INVERT
60818+ bool "Invert GID option"
60819+ depends on GRKERNSEC_TPE
60820+ help
60821+ If you say Y here, the group you specify in the TPE configuration will
60822+ decide what group TPE restrictions will be *disabled* for. This
60823+ option is useful if you want TPE restrictions to be applied to most
60824+ users on the system. If the sysctl option is enabled, a sysctl option
60825+ with name "tpe_invert" is created. Unlike other sysctl options, this
60826+ entry will default to on for backward-compatibility.
60827+
60828+config GRKERNSEC_TPE_GID
60829+ int "GID for untrusted users"
60830+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
60831+ default 1005
60832+ help
60833+ Setting this GID determines what group TPE restrictions will be
60834+ *enabled* for. If the sysctl option is enabled, a sysctl option
60835+ with name "tpe_gid" is created.
60836+
60837+config GRKERNSEC_TPE_GID
60838+ int "GID for trusted users"
60839+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
60840+ default 1005
60841+ help
60842+ Setting this GID determines what group TPE restrictions will be
60843+ *disabled* for. If the sysctl option is enabled, a sysctl option
60844+ with name "tpe_gid" is created.
60845+
60846+endmenu
60847+menu "Network Protections"
60848+depends on GRKERNSEC
60849+
60850+config GRKERNSEC_RANDNET
60851+ bool "Larger entropy pools"
60852+ help
60853+ If you say Y here, the entropy pools used for many features of Linux
60854+ and grsecurity will be doubled in size. Since several grsecurity
60855+ features use additional randomness, it is recommended that you say Y
60856+ here. Saying Y here has a similar effect as modifying
60857+ /proc/sys/kernel/random/poolsize.
60858+
60859+config GRKERNSEC_BLACKHOLE
60860+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
60861+ help
60862+ If you say Y here, neither TCP resets nor ICMP
60863+ destination-unreachable packets will be sent in response to packets
60864+ sent to ports for which no associated listening process exists.
60865+ This feature supports both IPV4 and IPV6 and exempts the
60866+ loopback interface from blackholing. Enabling this feature
60867+ makes a host more resilient to DoS attacks and reduces network
60868+ visibility against scanners.
60869+
60870+ The blackhole feature as-implemented is equivalent to the FreeBSD
60871+ blackhole feature, as it prevents RST responses to all packets, not
60872+ just SYNs. Under most application behavior this causes no
60873+ problems, but applications (like haproxy) may not close certain
60874+ connections in a way that cleanly terminates them on the remote
60875+ end, leaving the remote host in LAST_ACK state. Because of this
60876+ side-effect and to prevent intentional LAST_ACK DoSes, this
60877+ feature also adds automatic mitigation against such attacks.
60878+ The mitigation drastically reduces the amount of time a socket
60879+ can spend in LAST_ACK state. If you're using haproxy and not
60880+ all servers it connects to have this option enabled, consider
60881+ disabling this feature on the haproxy host.
60882+
60883+ If the sysctl option is enabled, two sysctl options with names
60884+ "ip_blackhole" and "lastack_retries" will be created.
60885+ While "ip_blackhole" takes the standard zero/non-zero on/off
60886+ toggle, "lastack_retries" uses the same kinds of values as
60887+ "tcp_retries1" and "tcp_retries2". The default value of 4
60888+ prevents a socket from lasting more than 45 seconds in LAST_ACK
60889+ state.
60890+
60891+config GRKERNSEC_SOCKET
60892+ bool "Socket restrictions"
60893+ help
60894+ If you say Y here, you will be able to choose from several options.
60895+ If you assign a GID on your system and add it to the supplementary
60896+ groups of users you want to restrict socket access to, this patch
60897+ will perform up to three things, based on the option(s) you choose.
60898+
60899+config GRKERNSEC_SOCKET_ALL
60900+ bool "Deny any sockets to group"
60901+ depends on GRKERNSEC_SOCKET
60902+ help
60903+ If you say Y here, you will be able to choose a GID of whose users will
60904+ be unable to connect to other hosts from your machine or run server
60905+ applications from your machine. If the sysctl option is enabled, a
60906+ sysctl option with name "socket_all" is created.
60907+
60908+config GRKERNSEC_SOCKET_ALL_GID
60909+ int "GID to deny all sockets for"
60910+ depends on GRKERNSEC_SOCKET_ALL
60911+ default 1004
60912+ help
60913+ Here you can choose the GID to disable socket access for. Remember to
60914+ add the users you want socket access disabled for to the GID
60915+ specified here. If the sysctl option is enabled, a sysctl option
60916+ with name "socket_all_gid" is created.
60917+
60918+config GRKERNSEC_SOCKET_CLIENT
60919+ bool "Deny client sockets to group"
60920+ depends on GRKERNSEC_SOCKET
60921+ help
60922+ If you say Y here, you will be able to choose a GID of whose users will
60923+ be unable to connect to other hosts from your machine, but will be
60924+ able to run servers. If this option is enabled, all users in the group
60925+ you specify will have to use passive mode when initiating ftp transfers
60926+ from the shell on your machine. If the sysctl option is enabled, a
60927+ sysctl option with name "socket_client" is created.
60928+
60929+config GRKERNSEC_SOCKET_CLIENT_GID
60930+ int "GID to deny client sockets for"
60931+ depends on GRKERNSEC_SOCKET_CLIENT
60932+ default 1003
60933+ help
60934+ Here you can choose the GID to disable client socket access for.
60935+ Remember to add the users you want client socket access disabled for to
60936+ the GID specified here. If the sysctl option is enabled, a sysctl
60937+ option with name "socket_client_gid" is created.
60938+
60939+config GRKERNSEC_SOCKET_SERVER
60940+ bool "Deny server sockets to group"
60941+ depends on GRKERNSEC_SOCKET
60942+ help
60943+ If you say Y here, you will be able to choose a GID of whose users will
60944+ be unable to run server applications from your machine. If the sysctl
60945+ option is enabled, a sysctl option with name "socket_server" is created.
60946+
60947+config GRKERNSEC_SOCKET_SERVER_GID
60948+ int "GID to deny server sockets for"
60949+ depends on GRKERNSEC_SOCKET_SERVER
60950+ default 1002
60951+ help
60952+ Here you can choose the GID to disable server socket access for.
60953+ Remember to add the users you want server socket access disabled for to
60954+ the GID specified here. If the sysctl option is enabled, a sysctl
60955+ option with name "socket_server_gid" is created.
60956+
60957+endmenu
60958+menu "Sysctl support"
60959+depends on GRKERNSEC && SYSCTL
60960+
60961+config GRKERNSEC_SYSCTL
60962+ bool "Sysctl support"
60963+ help
60964+ If you say Y here, you will be able to change the options that
60965+ grsecurity runs with at bootup, without having to recompile your
60966+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
60967+ to enable (1) or disable (0) various features. All the sysctl entries
60968+ are mutable until the "grsec_lock" entry is set to a non-zero value.
60969+ All features enabled in the kernel configuration are disabled at boot
60970+ if you do not say Y to the "Turn on features by default" option.
60971+ All options should be set at startup, and the grsec_lock entry should
60972+ be set to a non-zero value after all the options are set.
60973+ *THIS IS EXTREMELY IMPORTANT*
60974+
60975+config GRKERNSEC_SYSCTL_DISTRO
60976+ bool "Extra sysctl support for distro makers (READ HELP)"
60977+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
60978+ help
60979+ If you say Y here, additional sysctl options will be created
60980+ for features that affect processes running as root. Therefore,
60981+ it is critical when using this option that the grsec_lock entry be
60982+ enabled after boot. Only distros with prebuilt kernel packages
60983+ with this option enabled that can ensure grsec_lock is enabled
60984+ after boot should use this option.
60985+ *Failure to set grsec_lock after boot makes all grsec features
60986+ this option covers useless*
60987+
60988+ Currently this option creates the following sysctl entries:
60989+ "Disable Privileged I/O": "disable_priv_io"
60990+
60991+config GRKERNSEC_SYSCTL_ON
60992+ bool "Turn on features by default"
60993+ depends on GRKERNSEC_SYSCTL
60994+ help
60995+ If you say Y here, instead of having all features enabled in the
60996+ kernel configuration disabled at boot time, the features will be
60997+ enabled at boot time. It is recommended you say Y here unless
60998+ there is some reason you would want all sysctl-tunable features to
60999+ be disabled by default. As mentioned elsewhere, it is important
61000+ to enable the grsec_lock entry once you have finished modifying
61001+ the sysctl entries.
61002+
61003+endmenu
61004+menu "Logging Options"
61005+depends on GRKERNSEC
61006+
61007+config GRKERNSEC_FLOODTIME
61008+ int "Seconds in between log messages (minimum)"
61009+ default 10
61010+ help
61011+ This option allows you to enforce the number of seconds between
61012+ grsecurity log messages. The default should be suitable for most
61013+ people, however, if you choose to change it, choose a value small enough
61014+ to allow informative logs to be produced, but large enough to
61015+ prevent flooding.
61016+
61017+config GRKERNSEC_FLOODBURST
61018+ int "Number of messages in a burst (maximum)"
61019+ default 4
61020+ help
61021+ This option allows you to choose the maximum number of messages allowed
61022+ within the flood time interval you chose in a separate option. The
61023+ default should be suitable for most people, however if you find that
61024+ many of your logs are being interpreted as flooding, you may want to
61025+ raise this value.
61026+
61027+endmenu
61028+
61029+endmenu
61030diff -urNp linux-2.6.39.1/grsecurity/Makefile linux-2.6.39.1/grsecurity/Makefile
61031--- linux-2.6.39.1/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
61032+++ linux-2.6.39.1/grsecurity/Makefile 2011-05-24 20:26:54.000000000 -0400
61033@@ -0,0 +1,33 @@
61034+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
61035+# during 2001-2009 it has been completely redesigned by Brad Spengler
61036+# into an RBAC system
61037+#
61038+# All code in this directory and various hooks inserted throughout the kernel
61039+# are copyright Brad Spengler - Open Source Security, Inc., and released
61040+# under the GPL v2 or higher
61041+
61042+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
61043+ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
61044+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
61045+
61046+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
61047+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
61048+ gracl_learn.o grsec_log.o
61049+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
61050+
61051+ifdef CONFIG_NET
61052+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
61053+endif
61054+
61055+ifndef CONFIG_GRKERNSEC
61056+obj-y += grsec_disabled.o
61057+endif
61058+
61059+ifdef CONFIG_GRKERNSEC_HIDESYM
61060+extra-y := grsec_hidesym.o
61061+$(obj)/grsec_hidesym.o:
61062+ @-chmod -f 500 /boot
61063+ @-chmod -f 500 /lib/modules
61064+ @-chmod -f 700 .
61065+ @echo ' grsec: protected kernel image paths'
61066+endif
61067diff -urNp linux-2.6.39.1/include/acpi/acpi_drivers.h linux-2.6.39.1/include/acpi/acpi_drivers.h
61068--- linux-2.6.39.1/include/acpi/acpi_drivers.h 2011-05-19 00:06:34.000000000 -0400
61069+++ linux-2.6.39.1/include/acpi/acpi_drivers.h 2011-05-22 19:36:32.000000000 -0400
61070@@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
61071 Dock Station
61072 -------------------------------------------------------------------------- */
61073 struct acpi_dock_ops {
61074- acpi_notify_handler handler;
61075- acpi_notify_handler uevent;
61076+ const acpi_notify_handler handler;
61077+ const acpi_notify_handler uevent;
61078 };
61079
61080 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
61081@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
61082 extern int register_dock_notifier(struct notifier_block *nb);
61083 extern void unregister_dock_notifier(struct notifier_block *nb);
61084 extern int register_hotplug_dock_device(acpi_handle handle,
61085- struct acpi_dock_ops *ops,
61086+ const struct acpi_dock_ops *ops,
61087 void *context);
61088 extern void unregister_hotplug_dock_device(acpi_handle handle);
61089 #else
61090@@ -144,7 +144,7 @@ static inline void unregister_dock_notif
61091 {
61092 }
61093 static inline int register_hotplug_dock_device(acpi_handle handle,
61094- struct acpi_dock_ops *ops,
61095+ const struct acpi_dock_ops *ops,
61096 void *context)
61097 {
61098 return -ENODEV;
61099diff -urNp linux-2.6.39.1/include/acpi/processor.h linux-2.6.39.1/include/acpi/processor.h
61100--- linux-2.6.39.1/include/acpi/processor.h 2011-05-19 00:06:34.000000000 -0400
61101+++ linux-2.6.39.1/include/acpi/processor.h 2011-05-22 19:36:32.000000000 -0400
61102@@ -344,7 +344,7 @@ extern struct cpuidle_driver acpi_idle_d
61103
61104 /* in processor_thermal.c */
61105 int acpi_processor_get_limit_info(struct acpi_processor *pr);
61106-extern struct thermal_cooling_device_ops processor_cooling_ops;
61107+extern const struct thermal_cooling_device_ops processor_cooling_ops;
61108 #ifdef CONFIG_CPU_FREQ
61109 void acpi_thermal_cpufreq_init(void);
61110 void acpi_thermal_cpufreq_exit(void);
61111diff -urNp linux-2.6.39.1/include/asm-generic/atomic-long.h linux-2.6.39.1/include/asm-generic/atomic-long.h
61112--- linux-2.6.39.1/include/asm-generic/atomic-long.h 2011-05-19 00:06:34.000000000 -0400
61113+++ linux-2.6.39.1/include/asm-generic/atomic-long.h 2011-05-22 19:36:32.000000000 -0400
61114@@ -22,6 +22,12 @@
61115
61116 typedef atomic64_t atomic_long_t;
61117
61118+#ifdef CONFIG_PAX_REFCOUNT
61119+typedef atomic64_unchecked_t atomic_long_unchecked_t;
61120+#else
61121+typedef atomic64_t atomic_long_unchecked_t;
61122+#endif
61123+
61124 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61125
61126 static inline long atomic_long_read(atomic_long_t *l)
61127@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
61128 return (long)atomic64_read(v);
61129 }
61130
61131+#ifdef CONFIG_PAX_REFCOUNT
61132+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61133+{
61134+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61135+
61136+ return (long)atomic64_read_unchecked(v);
61137+}
61138+#endif
61139+
61140 static inline void atomic_long_set(atomic_long_t *l, long i)
61141 {
61142 atomic64_t *v = (atomic64_t *)l;
61143@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
61144 atomic64_set(v, i);
61145 }
61146
61147+#ifdef CONFIG_PAX_REFCOUNT
61148+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61149+{
61150+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61151+
61152+ atomic64_set_unchecked(v, i);
61153+}
61154+#endif
61155+
61156 static inline void atomic_long_inc(atomic_long_t *l)
61157 {
61158 atomic64_t *v = (atomic64_t *)l;
61159@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
61160 atomic64_inc(v);
61161 }
61162
61163+#ifdef CONFIG_PAX_REFCOUNT
61164+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61165+{
61166+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61167+
61168+ atomic64_inc_unchecked(v);
61169+}
61170+#endif
61171+
61172 static inline void atomic_long_dec(atomic_long_t *l)
61173 {
61174 atomic64_t *v = (atomic64_t *)l;
61175@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
61176 atomic64_dec(v);
61177 }
61178
61179+#ifdef CONFIG_PAX_REFCOUNT
61180+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61181+{
61182+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61183+
61184+ atomic64_dec_unchecked(v);
61185+}
61186+#endif
61187+
61188 static inline void atomic_long_add(long i, atomic_long_t *l)
61189 {
61190 atomic64_t *v = (atomic64_t *)l;
61191@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
61192 atomic64_add(i, v);
61193 }
61194
61195+#ifdef CONFIG_PAX_REFCOUNT
61196+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61197+{
61198+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61199+
61200+ atomic64_add_unchecked(i, v);
61201+}
61202+#endif
61203+
61204 static inline void atomic_long_sub(long i, atomic_long_t *l)
61205 {
61206 atomic64_t *v = (atomic64_t *)l;
61207@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
61208 atomic64_sub(i, v);
61209 }
61210
61211+#ifdef CONFIG_PAX_REFCOUNT
61212+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61213+{
61214+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61215+
61216+ atomic64_sub_unchecked(i, v);
61217+}
61218+#endif
61219+
61220 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61221 {
61222 atomic64_t *v = (atomic64_t *)l;
61223@@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
61224 return (long)atomic64_inc_return(v);
61225 }
61226
61227+#ifdef CONFIG_PAX_REFCOUNT
61228+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61229+{
61230+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61231+
61232+ return (long)atomic64_inc_return_unchecked(v);
61233+}
61234+#endif
61235+
61236 static inline long atomic_long_dec_return(atomic_long_t *l)
61237 {
61238 atomic64_t *v = (atomic64_t *)l;
61239@@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
61240
61241 typedef atomic_t atomic_long_t;
61242
61243+#ifdef CONFIG_PAX_REFCOUNT
61244+typedef atomic_unchecked_t atomic_long_unchecked_t;
61245+#else
61246+typedef atomic_t atomic_long_unchecked_t;
61247+#endif
61248+
61249 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61250 static inline long atomic_long_read(atomic_long_t *l)
61251 {
61252@@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
61253 return (long)atomic_read(v);
61254 }
61255
61256+#ifdef CONFIG_PAX_REFCOUNT
61257+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61258+{
61259+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61260+
61261+ return (long)atomic_read_unchecked(v);
61262+}
61263+#endif
61264+
61265 static inline void atomic_long_set(atomic_long_t *l, long i)
61266 {
61267 atomic_t *v = (atomic_t *)l;
61268@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
61269 atomic_set(v, i);
61270 }
61271
61272+#ifdef CONFIG_PAX_REFCOUNT
61273+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61274+{
61275+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61276+
61277+ atomic_set_unchecked(v, i);
61278+}
61279+#endif
61280+
61281 static inline void atomic_long_inc(atomic_long_t *l)
61282 {
61283 atomic_t *v = (atomic_t *)l;
61284@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
61285 atomic_inc(v);
61286 }
61287
61288+#ifdef CONFIG_PAX_REFCOUNT
61289+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61290+{
61291+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61292+
61293+ atomic_inc_unchecked(v);
61294+}
61295+#endif
61296+
61297 static inline void atomic_long_dec(atomic_long_t *l)
61298 {
61299 atomic_t *v = (atomic_t *)l;
61300@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
61301 atomic_dec(v);
61302 }
61303
61304+#ifdef CONFIG_PAX_REFCOUNT
61305+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61306+{
61307+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61308+
61309+ atomic_dec_unchecked(v);
61310+}
61311+#endif
61312+
61313 static inline void atomic_long_add(long i, atomic_long_t *l)
61314 {
61315 atomic_t *v = (atomic_t *)l;
61316@@ -176,6 +287,15 @@ static inline void atomic_long_add(long
61317 atomic_add(i, v);
61318 }
61319
61320+#ifdef CONFIG_PAX_REFCOUNT
61321+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61322+{
61323+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61324+
61325+ atomic_add_unchecked(i, v);
61326+}
61327+#endif
61328+
61329 static inline void atomic_long_sub(long i, atomic_long_t *l)
61330 {
61331 atomic_t *v = (atomic_t *)l;
61332@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
61333 atomic_sub(i, v);
61334 }
61335
61336+#ifdef CONFIG_PAX_REFCOUNT
61337+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61338+{
61339+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61340+
61341+ atomic_sub_unchecked(i, v);
61342+}
61343+#endif
61344+
61345 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61346 {
61347 atomic_t *v = (atomic_t *)l;
61348@@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
61349 return (long)atomic_inc_return(v);
61350 }
61351
61352+#ifdef CONFIG_PAX_REFCOUNT
61353+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61354+{
61355+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61356+
61357+ return (long)atomic_inc_return_unchecked(v);
61358+}
61359+#endif
61360+
61361 static inline long atomic_long_dec_return(atomic_long_t *l)
61362 {
61363 atomic_t *v = (atomic_t *)l;
61364@@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
61365
61366 #endif /* BITS_PER_LONG == 64 */
61367
61368+#ifdef CONFIG_PAX_REFCOUNT
61369+static inline void pax_refcount_needs_these_functions(void)
61370+{
61371+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
61372+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61373+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61374+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61375+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61376+ atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61377+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61378+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61379+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61380+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61381+ atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61382+
61383+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61384+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61385+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61386+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61387+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61388+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61389+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61390+}
61391+#else
61392+#define atomic_read_unchecked(v) atomic_read(v)
61393+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61394+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61395+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61396+#define atomic_inc_unchecked(v) atomic_inc(v)
61397+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61398+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61399+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61400+#define atomic_dec_unchecked(v) atomic_dec(v)
61401+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61402+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61403+
61404+#define atomic_long_read_unchecked(v) atomic_long_read(v)
61405+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61406+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61407+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61408+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61409+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61410+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61411+#endif
61412+
61413 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61414diff -urNp linux-2.6.39.1/include/asm-generic/cache.h linux-2.6.39.1/include/asm-generic/cache.h
61415--- linux-2.6.39.1/include/asm-generic/cache.h 2011-05-19 00:06:34.000000000 -0400
61416+++ linux-2.6.39.1/include/asm-generic/cache.h 2011-05-22 19:36:32.000000000 -0400
61417@@ -6,7 +6,7 @@
61418 * cache lines need to provide their own cache.h.
61419 */
61420
61421-#define L1_CACHE_SHIFT 5
61422-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61423+#define L1_CACHE_SHIFT 5U
61424+#define L1_CACHE_BYTES (1U << L1_CACHE_SHIFT)
61425
61426 #endif /* __ASM_GENERIC_CACHE_H */
61427diff -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
61428--- linux-2.6.39.1/include/asm-generic/dma-mapping-common.h 2011-05-19 00:06:34.000000000 -0400
61429+++ linux-2.6.39.1/include/asm-generic/dma-mapping-common.h 2011-05-22 19:36:32.000000000 -0400
61430@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
61431 enum dma_data_direction dir,
61432 struct dma_attrs *attrs)
61433 {
61434- struct dma_map_ops *ops = get_dma_ops(dev);
61435+ const struct dma_map_ops *ops = get_dma_ops(dev);
61436 dma_addr_t addr;
61437
61438 kmemcheck_mark_initialized(ptr, size);
61439@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
61440 enum dma_data_direction dir,
61441 struct dma_attrs *attrs)
61442 {
61443- struct dma_map_ops *ops = get_dma_ops(dev);
61444+ const struct dma_map_ops *ops = get_dma_ops(dev);
61445
61446 BUG_ON(!valid_dma_direction(dir));
61447 if (ops->unmap_page)
61448@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
61449 int nents, enum dma_data_direction dir,
61450 struct dma_attrs *attrs)
61451 {
61452- struct dma_map_ops *ops = get_dma_ops(dev);
61453+ const struct dma_map_ops *ops = get_dma_ops(dev);
61454 int i, ents;
61455 struct scatterlist *s;
61456
61457@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
61458 int nents, enum dma_data_direction dir,
61459 struct dma_attrs *attrs)
61460 {
61461- struct dma_map_ops *ops = get_dma_ops(dev);
61462+ const struct dma_map_ops *ops = get_dma_ops(dev);
61463
61464 BUG_ON(!valid_dma_direction(dir));
61465 debug_dma_unmap_sg(dev, sg, nents, dir);
61466@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
61467 size_t offset, size_t size,
61468 enum dma_data_direction dir)
61469 {
61470- struct dma_map_ops *ops = get_dma_ops(dev);
61471+ const struct dma_map_ops *ops = get_dma_ops(dev);
61472 dma_addr_t addr;
61473
61474 kmemcheck_mark_initialized(page_address(page) + offset, size);
61475@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
61476 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
61477 size_t size, enum dma_data_direction dir)
61478 {
61479- struct dma_map_ops *ops = get_dma_ops(dev);
61480+ const struct dma_map_ops *ops = get_dma_ops(dev);
61481
61482 BUG_ON(!valid_dma_direction(dir));
61483 if (ops->unmap_page)
61484@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
61485 size_t size,
61486 enum dma_data_direction dir)
61487 {
61488- struct dma_map_ops *ops = get_dma_ops(dev);
61489+ const struct dma_map_ops *ops = get_dma_ops(dev);
61490
61491 BUG_ON(!valid_dma_direction(dir));
61492 if (ops->sync_single_for_cpu)
61493@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
61494 dma_addr_t addr, size_t size,
61495 enum dma_data_direction dir)
61496 {
61497- struct dma_map_ops *ops = get_dma_ops(dev);
61498+ const struct dma_map_ops *ops = get_dma_ops(dev);
61499
61500 BUG_ON(!valid_dma_direction(dir));
61501 if (ops->sync_single_for_device)
61502@@ -139,7 +139,7 @@ static inline void
61503 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
61504 int nelems, enum dma_data_direction dir)
61505 {
61506- struct dma_map_ops *ops = get_dma_ops(dev);
61507+ const struct dma_map_ops *ops = get_dma_ops(dev);
61508
61509 BUG_ON(!valid_dma_direction(dir));
61510 if (ops->sync_sg_for_cpu)
61511@@ -151,7 +151,7 @@ static inline void
61512 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
61513 int nelems, enum dma_data_direction dir)
61514 {
61515- struct dma_map_ops *ops = get_dma_ops(dev);
61516+ const struct dma_map_ops *ops = get_dma_ops(dev);
61517
61518 BUG_ON(!valid_dma_direction(dir));
61519 if (ops->sync_sg_for_device)
61520diff -urNp linux-2.6.39.1/include/asm-generic/int-l64.h linux-2.6.39.1/include/asm-generic/int-l64.h
61521--- linux-2.6.39.1/include/asm-generic/int-l64.h 2011-05-19 00:06:34.000000000 -0400
61522+++ linux-2.6.39.1/include/asm-generic/int-l64.h 2011-05-22 19:36:32.000000000 -0400
61523@@ -46,6 +46,8 @@ typedef unsigned int u32;
61524 typedef signed long s64;
61525 typedef unsigned long u64;
61526
61527+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
61528+
61529 #define S8_C(x) x
61530 #define U8_C(x) x ## U
61531 #define S16_C(x) x
61532diff -urNp linux-2.6.39.1/include/asm-generic/int-ll64.h linux-2.6.39.1/include/asm-generic/int-ll64.h
61533--- linux-2.6.39.1/include/asm-generic/int-ll64.h 2011-05-19 00:06:34.000000000 -0400
61534+++ linux-2.6.39.1/include/asm-generic/int-ll64.h 2011-05-22 19:36:32.000000000 -0400
61535@@ -51,6 +51,8 @@ typedef unsigned int u32;
61536 typedef signed long long s64;
61537 typedef unsigned long long u64;
61538
61539+typedef unsigned long long intoverflow_t;
61540+
61541 #define S8_C(x) x
61542 #define U8_C(x) x ## U
61543 #define S16_C(x) x
61544diff -urNp linux-2.6.39.1/include/asm-generic/kmap_types.h linux-2.6.39.1/include/asm-generic/kmap_types.h
61545--- linux-2.6.39.1/include/asm-generic/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
61546+++ linux-2.6.39.1/include/asm-generic/kmap_types.h 2011-05-22 19:36:32.000000000 -0400
61547@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
61548 KMAP_D(17) KM_NMI,
61549 KMAP_D(18) KM_NMI_PTE,
61550 KMAP_D(19) KM_KDB,
61551+KMAP_D(20) KM_CLEARPAGE,
61552 /*
61553 * Remember to update debug_kmap_atomic() when adding new kmap types!
61554 */
61555-KMAP_D(20) KM_TYPE_NR
61556+KMAP_D(21) KM_TYPE_NR
61557 };
61558
61559 #undef KMAP_D
61560diff -urNp linux-2.6.39.1/include/asm-generic/pgtable.h linux-2.6.39.1/include/asm-generic/pgtable.h
61561--- linux-2.6.39.1/include/asm-generic/pgtable.h 2011-05-19 00:06:34.000000000 -0400
61562+++ linux-2.6.39.1/include/asm-generic/pgtable.h 2011-05-22 19:36:32.000000000 -0400
61563@@ -447,6 +447,14 @@ static inline int pmd_write(pmd_t pmd)
61564 #endif /* __HAVE_ARCH_PMD_WRITE */
61565 #endif
61566
61567+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61568+static inline unsigned long pax_open_kernel(void) { return 0; }
61569+#endif
61570+
61571+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61572+static inline unsigned long pax_close_kernel(void) { return 0; }
61573+#endif
61574+
61575 #endif /* !__ASSEMBLY__ */
61576
61577 #endif /* _ASM_GENERIC_PGTABLE_H */
61578diff -urNp linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h
61579--- linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h 2011-05-19 00:06:34.000000000 -0400
61580+++ linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h 2011-05-22 19:36:32.000000000 -0400
61581@@ -1,14 +1,19 @@
61582 #ifndef _PGTABLE_NOPMD_H
61583 #define _PGTABLE_NOPMD_H
61584
61585-#ifndef __ASSEMBLY__
61586-
61587 #include <asm-generic/pgtable-nopud.h>
61588
61589-struct mm_struct;
61590-
61591 #define __PAGETABLE_PMD_FOLDED
61592
61593+#define PMD_SHIFT PUD_SHIFT
61594+#define PTRS_PER_PMD 1
61595+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61596+#define PMD_MASK (~(PMD_SIZE-1))
61597+
61598+#ifndef __ASSEMBLY__
61599+
61600+struct mm_struct;
61601+
61602 /*
61603 * Having the pmd type consist of a pud gets the size right, and allows
61604 * us to conceptually access the pud entry that this pmd is folded into
61605@@ -16,11 +21,6 @@ struct mm_struct;
61606 */
61607 typedef struct { pud_t pud; } pmd_t;
61608
61609-#define PMD_SHIFT PUD_SHIFT
61610-#define PTRS_PER_PMD 1
61611-#define PMD_SIZE (1UL << PMD_SHIFT)
61612-#define PMD_MASK (~(PMD_SIZE-1))
61613-
61614 /*
61615 * The "pud_xxx()" functions here are trivial for a folded two-level
61616 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61617diff -urNp linux-2.6.39.1/include/asm-generic/pgtable-nopud.h linux-2.6.39.1/include/asm-generic/pgtable-nopud.h
61618--- linux-2.6.39.1/include/asm-generic/pgtable-nopud.h 2011-05-19 00:06:34.000000000 -0400
61619+++ linux-2.6.39.1/include/asm-generic/pgtable-nopud.h 2011-05-22 19:36:32.000000000 -0400
61620@@ -1,10 +1,15 @@
61621 #ifndef _PGTABLE_NOPUD_H
61622 #define _PGTABLE_NOPUD_H
61623
61624-#ifndef __ASSEMBLY__
61625-
61626 #define __PAGETABLE_PUD_FOLDED
61627
61628+#define PUD_SHIFT PGDIR_SHIFT
61629+#define PTRS_PER_PUD 1
61630+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61631+#define PUD_MASK (~(PUD_SIZE-1))
61632+
61633+#ifndef __ASSEMBLY__
61634+
61635 /*
61636 * Having the pud type consist of a pgd gets the size right, and allows
61637 * us to conceptually access the pgd entry that this pud is folded into
61638@@ -12,11 +17,6 @@
61639 */
61640 typedef struct { pgd_t pgd; } pud_t;
61641
61642-#define PUD_SHIFT PGDIR_SHIFT
61643-#define PTRS_PER_PUD 1
61644-#define PUD_SIZE (1UL << PUD_SHIFT)
61645-#define PUD_MASK (~(PUD_SIZE-1))
61646-
61647 /*
61648 * The "pgd_xxx()" functions here are trivial for a folded two-level
61649 * setup: the pud is never bad, and a pud always exists (as it's folded
61650diff -urNp linux-2.6.39.1/include/asm-generic/vmlinux.lds.h linux-2.6.39.1/include/asm-generic/vmlinux.lds.h
61651--- linux-2.6.39.1/include/asm-generic/vmlinux.lds.h 2011-05-19 00:06:34.000000000 -0400
61652+++ linux-2.6.39.1/include/asm-generic/vmlinux.lds.h 2011-05-22 19:36:32.000000000 -0400
61653@@ -213,6 +213,7 @@
61654 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61655 VMLINUX_SYMBOL(__start_rodata) = .; \
61656 *(.rodata) *(.rodata.*) \
61657+ *(.data..read_only) \
61658 *(__vermagic) /* Kernel version magic */ \
61659 . = ALIGN(8); \
61660 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61661@@ -707,14 +708,15 @@
61662 * section in the linker script will go there too. @phdr should have
61663 * a leading colon.
61664 *
61665- * Note that this macros defines __per_cpu_load as an absolute symbol.
61666+ * Note that this macros defines per_cpu_load as an absolute symbol.
61667 * If there is no need to put the percpu section at a predetermined
61668 * address, use PERCPU().
61669 */
61670 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61671- VMLINUX_SYMBOL(__per_cpu_load) = .; \
61672- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61673+ per_cpu_load = .; \
61674+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61675 - LOAD_OFFSET) { \
61676+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61677 VMLINUX_SYMBOL(__per_cpu_start) = .; \
61678 *(.data..percpu..first) \
61679 . = ALIGN(PAGE_SIZE); \
61680@@ -726,7 +728,7 @@
61681 *(.data..percpu..shared_aligned) \
61682 VMLINUX_SYMBOL(__per_cpu_end) = .; \
61683 } phdr \
61684- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61685+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61686
61687 /**
61688 * PERCPU - define output section for percpu area, simple version
61689diff -urNp linux-2.6.39.1/include/drm/drmP.h linux-2.6.39.1/include/drm/drmP.h
61690--- linux-2.6.39.1/include/drm/drmP.h 2011-05-19 00:06:34.000000000 -0400
61691+++ linux-2.6.39.1/include/drm/drmP.h 2011-05-22 19:41:42.000000000 -0400
61692@@ -73,6 +73,7 @@
61693 #include <linux/workqueue.h>
61694 #include <linux/poll.h>
61695 #include <asm/pgalloc.h>
61696+#include <asm/local.h>
61697 #include "drm.h"
61698
61699 #include <linux/idr.h>
61700@@ -908,7 +909,7 @@ struct drm_driver {
61701 uint32_t handle);
61702
61703 /* Driver private ops for this object */
61704- struct vm_operations_struct *gem_vm_ops;
61705+ const struct vm_operations_struct *gem_vm_ops;
61706
61707 int major;
61708 int minor;
61709@@ -1023,7 +1024,7 @@ struct drm_device {
61710
61711 /** \name Usage Counters */
61712 /*@{ */
61713- int open_count; /**< Outstanding files open */
61714+ local_t open_count; /**< Outstanding files open */
61715 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61716 atomic_t vma_count; /**< Outstanding vma areas open */
61717 int buf_use; /**< Buffers in use -- cannot alloc */
61718@@ -1034,7 +1035,7 @@ struct drm_device {
61719 /*@{ */
61720 unsigned long counters;
61721 enum drm_stat_type types[15];
61722- atomic_t counts[15];
61723+ atomic_unchecked_t counts[15];
61724 /*@} */
61725
61726 struct list_head filelist;
61727diff -urNp linux-2.6.39.1/include/linux/a.out.h linux-2.6.39.1/include/linux/a.out.h
61728--- linux-2.6.39.1/include/linux/a.out.h 2011-05-19 00:06:34.000000000 -0400
61729+++ linux-2.6.39.1/include/linux/a.out.h 2011-05-22 19:36:32.000000000 -0400
61730@@ -39,6 +39,14 @@ enum machine_type {
61731 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61732 };
61733
61734+/* Constants for the N_FLAGS field */
61735+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61736+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61737+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61738+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61739+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61740+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61741+
61742 #if !defined (N_MAGIC)
61743 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61744 #endif
61745diff -urNp linux-2.6.39.1/include/linux/atmdev.h linux-2.6.39.1/include/linux/atmdev.h
61746--- linux-2.6.39.1/include/linux/atmdev.h 2011-05-19 00:06:34.000000000 -0400
61747+++ linux-2.6.39.1/include/linux/atmdev.h 2011-05-22 19:36:32.000000000 -0400
61748@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61749 #endif
61750
61751 struct k_atm_aal_stats {
61752-#define __HANDLE_ITEM(i) atomic_t i
61753+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61754 __AAL_STAT_ITEMS
61755 #undef __HANDLE_ITEM
61756 };
61757diff -urNp linux-2.6.39.1/include/linux/binfmts.h linux-2.6.39.1/include/linux/binfmts.h
61758--- linux-2.6.39.1/include/linux/binfmts.h 2011-05-19 00:06:34.000000000 -0400
61759+++ linux-2.6.39.1/include/linux/binfmts.h 2011-05-22 19:36:32.000000000 -0400
61760@@ -92,6 +92,7 @@ struct linux_binfmt {
61761 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61762 int (*load_shlib)(struct file *);
61763 int (*core_dump)(struct coredump_params *cprm);
61764+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61765 unsigned long min_coredump; /* minimal dump size */
61766 };
61767
61768diff -urNp linux-2.6.39.1/include/linux/blkdev.h linux-2.6.39.1/include/linux/blkdev.h
61769--- linux-2.6.39.1/include/linux/blkdev.h 2011-06-03 00:04:14.000000000 -0400
61770+++ linux-2.6.39.1/include/linux/blkdev.h 2011-06-03 00:32:08.000000000 -0400
61771@@ -1292,22 +1292,22 @@ queue_max_integrity_segments(struct requ
61772 #endif /* CONFIG_BLK_DEV_INTEGRITY */
61773
61774 struct block_device_operations {
61775- int (*open) (struct block_device *, fmode_t);
61776- int (*release) (struct gendisk *, fmode_t);
61777- int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61778- int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61779- int (*direct_access) (struct block_device *, sector_t,
61780+ int (* const open) (struct block_device *, fmode_t);
61781+ int (* const release) (struct gendisk *, fmode_t);
61782+ int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61783+ int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61784+ int (* const direct_access) (struct block_device *, sector_t,
61785 void **, unsigned long *);
61786- unsigned int (*check_events) (struct gendisk *disk,
61787+ unsigned int (* const check_events) (struct gendisk *disk,
61788 unsigned int clearing);
61789 /* ->media_changed() is DEPRECATED, use ->check_events() instead */
61790- int (*media_changed) (struct gendisk *);
61791- void (*unlock_native_capacity) (struct gendisk *);
61792- int (*revalidate_disk) (struct gendisk *);
61793- int (*getgeo)(struct block_device *, struct hd_geometry *);
61794+ int (* const media_changed) (struct gendisk *);
61795+ void (* const unlock_native_capacity) (struct gendisk *);
61796+ int (* const revalidate_disk) (struct gendisk *);
61797+ int (* const getgeo)(struct block_device *, struct hd_geometry *);
61798 /* this callback is with swap_lock and sometimes page table lock held */
61799- void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61800- struct module *owner;
61801+ void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
61802+ struct module * const owner;
61803 };
61804
61805 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61806diff -urNp linux-2.6.39.1/include/linux/blktrace_api.h linux-2.6.39.1/include/linux/blktrace_api.h
61807--- linux-2.6.39.1/include/linux/blktrace_api.h 2011-05-19 00:06:34.000000000 -0400
61808+++ linux-2.6.39.1/include/linux/blktrace_api.h 2011-05-22 19:36:32.000000000 -0400
61809@@ -161,7 +161,7 @@ struct blk_trace {
61810 struct dentry *dir;
61811 struct dentry *dropped_file;
61812 struct dentry *msg_file;
61813- atomic_t dropped;
61814+ atomic_unchecked_t dropped;
61815 };
61816
61817 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61818diff -urNp linux-2.6.39.1/include/linux/byteorder/little_endian.h linux-2.6.39.1/include/linux/byteorder/little_endian.h
61819--- linux-2.6.39.1/include/linux/byteorder/little_endian.h 2011-05-19 00:06:34.000000000 -0400
61820+++ linux-2.6.39.1/include/linux/byteorder/little_endian.h 2011-05-22 19:36:32.000000000 -0400
61821@@ -42,51 +42,51 @@
61822
61823 static inline __le64 __cpu_to_le64p(const __u64 *p)
61824 {
61825- return (__force __le64)*p;
61826+ return (__force const __le64)*p;
61827 }
61828 static inline __u64 __le64_to_cpup(const __le64 *p)
61829 {
61830- return (__force __u64)*p;
61831+ return (__force const __u64)*p;
61832 }
61833 static inline __le32 __cpu_to_le32p(const __u32 *p)
61834 {
61835- return (__force __le32)*p;
61836+ return (__force const __le32)*p;
61837 }
61838 static inline __u32 __le32_to_cpup(const __le32 *p)
61839 {
61840- return (__force __u32)*p;
61841+ return (__force const __u32)*p;
61842 }
61843 static inline __le16 __cpu_to_le16p(const __u16 *p)
61844 {
61845- return (__force __le16)*p;
61846+ return (__force const __le16)*p;
61847 }
61848 static inline __u16 __le16_to_cpup(const __le16 *p)
61849 {
61850- return (__force __u16)*p;
61851+ return (__force const __u16)*p;
61852 }
61853 static inline __be64 __cpu_to_be64p(const __u64 *p)
61854 {
61855- return (__force __be64)__swab64p(p);
61856+ return (__force const __be64)__swab64p(p);
61857 }
61858 static inline __u64 __be64_to_cpup(const __be64 *p)
61859 {
61860- return __swab64p((__u64 *)p);
61861+ return __swab64p((const __u64 *)p);
61862 }
61863 static inline __be32 __cpu_to_be32p(const __u32 *p)
61864 {
61865- return (__force __be32)__swab32p(p);
61866+ return (__force const __be32)__swab32p(p);
61867 }
61868 static inline __u32 __be32_to_cpup(const __be32 *p)
61869 {
61870- return __swab32p((__u32 *)p);
61871+ return __swab32p((const __u32 *)p);
61872 }
61873 static inline __be16 __cpu_to_be16p(const __u16 *p)
61874 {
61875- return (__force __be16)__swab16p(p);
61876+ return (__force const __be16)__swab16p(p);
61877 }
61878 static inline __u16 __be16_to_cpup(const __be16 *p)
61879 {
61880- return __swab16p((__u16 *)p);
61881+ return __swab16p((const __u16 *)p);
61882 }
61883 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61884 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61885diff -urNp linux-2.6.39.1/include/linux/cache.h linux-2.6.39.1/include/linux/cache.h
61886--- linux-2.6.39.1/include/linux/cache.h 2011-05-19 00:06:34.000000000 -0400
61887+++ linux-2.6.39.1/include/linux/cache.h 2011-05-22 19:36:32.000000000 -0400
61888@@ -16,6 +16,10 @@
61889 #define __read_mostly
61890 #endif
61891
61892+#ifndef __read_only
61893+#define __read_only __read_mostly
61894+#endif
61895+
61896 #ifndef ____cacheline_aligned
61897 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61898 #endif
61899diff -urNp linux-2.6.39.1/include/linux/capability.h linux-2.6.39.1/include/linux/capability.h
61900--- linux-2.6.39.1/include/linux/capability.h 2011-05-19 00:06:34.000000000 -0400
61901+++ linux-2.6.39.1/include/linux/capability.h 2011-05-22 21:02:47.000000000 -0400
61902@@ -547,6 +547,9 @@ extern bool capable(int cap);
61903 extern bool ns_capable(struct user_namespace *ns, int cap);
61904 extern bool task_ns_capable(struct task_struct *t, int cap);
61905 extern bool nsown_capable(int cap);
61906+extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
61907+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61908+extern bool capable_nolog(int cap);
61909
61910 /* audit system wants to get cap info from files as well */
61911 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61912diff -urNp linux-2.6.39.1/include/linux/compiler-gcc4.h linux-2.6.39.1/include/linux/compiler-gcc4.h
61913--- linux-2.6.39.1/include/linux/compiler-gcc4.h 2011-05-19 00:06:34.000000000 -0400
61914+++ linux-2.6.39.1/include/linux/compiler-gcc4.h 2011-05-22 19:36:32.000000000 -0400
61915@@ -46,6 +46,11 @@
61916 #define __noclone __attribute__((__noclone__))
61917
61918 #endif
61919+
61920+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61921+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61922+#define __bos0(ptr) __bos((ptr), 0)
61923+#define __bos1(ptr) __bos((ptr), 1)
61924 #endif
61925
61926 #if __GNUC_MINOR__ > 0
61927diff -urNp linux-2.6.39.1/include/linux/compiler.h linux-2.6.39.1/include/linux/compiler.h
61928--- linux-2.6.39.1/include/linux/compiler.h 2011-05-19 00:06:34.000000000 -0400
61929+++ linux-2.6.39.1/include/linux/compiler.h 2011-05-22 19:36:32.000000000 -0400
61930@@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
61931 #define __cold
61932 #endif
61933
61934+#ifndef __alloc_size
61935+#define __alloc_size
61936+#endif
61937+
61938+#ifndef __bos
61939+#define __bos
61940+#endif
61941+
61942+#ifndef __bos0
61943+#define __bos0
61944+#endif
61945+
61946+#ifndef __bos1
61947+#define __bos1
61948+#endif
61949+
61950 /* Simple shorthand for a section definition */
61951 #ifndef __section
61952 # define __section(S) __attribute__ ((__section__(#S)))
61953@@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
61954 * use is to mediate communication between process-level code and irq/NMI
61955 * handlers, all running on the same CPU.
61956 */
61957-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61958+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61959+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61960
61961 #endif /* __LINUX_COMPILER_H */
61962diff -urNp linux-2.6.39.1/include/linux/concap.h linux-2.6.39.1/include/linux/concap.h
61963--- linux-2.6.39.1/include/linux/concap.h 2011-05-19 00:06:34.000000000 -0400
61964+++ linux-2.6.39.1/include/linux/concap.h 2011-05-22 19:36:32.000000000 -0400
61965@@ -30,7 +30,7 @@ struct concap_device_ops;
61966 struct concap_proto{
61967 struct net_device *net_dev; /* net device using our service */
61968 struct concap_device_ops *dops; /* callbacks provided by device */
61969- struct concap_proto_ops *pops; /* callbacks provided by us */
61970+ const struct concap_proto_ops *pops; /* callbacks provided by us */
61971 spinlock_t lock;
61972 int flags;
61973 void *proto_data; /* protocol specific private data, to
61974diff -urNp linux-2.6.39.1/include/linux/configfs.h linux-2.6.39.1/include/linux/configfs.h
61975--- linux-2.6.39.1/include/linux/configfs.h 2011-05-19 00:06:34.000000000 -0400
61976+++ linux-2.6.39.1/include/linux/configfs.h 2011-05-22 19:36:32.000000000 -0400
61977@@ -82,7 +82,7 @@ extern void config_item_put(struct confi
61978 struct config_item_type {
61979 struct module *ct_owner;
61980 struct configfs_item_operations *ct_item_ops;
61981- struct configfs_group_operations *ct_group_ops;
61982+ const struct configfs_group_operations *ct_group_ops;
61983 struct configfs_attribute **ct_attrs;
61984 };
61985
61986diff -urNp linux-2.6.39.1/include/linux/cpuset.h linux-2.6.39.1/include/linux/cpuset.h
61987--- linux-2.6.39.1/include/linux/cpuset.h 2011-05-19 00:06:34.000000000 -0400
61988+++ linux-2.6.39.1/include/linux/cpuset.h 2011-05-22 19:36:32.000000000 -0400
61989@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
61990 * nodemask.
61991 */
61992 smp_mb();
61993- --ACCESS_ONCE(current->mems_allowed_change_disable);
61994+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
61995 }
61996
61997 static inline void set_mems_allowed(nodemask_t nodemask)
61998diff -urNp linux-2.6.39.1/include/linux/dca.h linux-2.6.39.1/include/linux/dca.h
61999--- linux-2.6.39.1/include/linux/dca.h 2011-05-19 00:06:34.000000000 -0400
62000+++ linux-2.6.39.1/include/linux/dca.h 2011-05-22 19:36:32.000000000 -0400
62001@@ -34,7 +34,7 @@ void dca_unregister_notify(struct notifi
62002
62003 struct dca_provider {
62004 struct list_head node;
62005- struct dca_ops *ops;
62006+ const struct dca_ops *ops;
62007 struct device *cd;
62008 int id;
62009 };
62010@@ -53,7 +53,7 @@ struct dca_ops {
62011 int (*dev_managed) (struct dca_provider *, struct device *);
62012 };
62013
62014-struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size);
62015+struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size);
62016 void free_dca_provider(struct dca_provider *dca);
62017 int register_dca_provider(struct dca_provider *dca, struct device *dev);
62018 void unregister_dca_provider(struct dca_provider *dca, struct device *dev);
62019diff -urNp linux-2.6.39.1/include/linux/decompress/mm.h linux-2.6.39.1/include/linux/decompress/mm.h
62020--- linux-2.6.39.1/include/linux/decompress/mm.h 2011-05-19 00:06:34.000000000 -0400
62021+++ linux-2.6.39.1/include/linux/decompress/mm.h 2011-05-22 19:36:33.000000000 -0400
62022@@ -77,7 +77,7 @@ static void free(void *where)
62023 * warnings when not needed (indeed large_malloc / large_free are not
62024 * needed by inflate */
62025
62026-#define malloc(a) kmalloc(a, GFP_KERNEL)
62027+#define malloc(a) kmalloc((a), GFP_KERNEL)
62028 #define free(a) kfree(a)
62029
62030 #define large_malloc(a) vmalloc(a)
62031diff -urNp linux-2.6.39.1/include/linux/dma-mapping.h linux-2.6.39.1/include/linux/dma-mapping.h
62032--- linux-2.6.39.1/include/linux/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
62033+++ linux-2.6.39.1/include/linux/dma-mapping.h 2011-05-22 19:36:33.000000000 -0400
62034@@ -16,40 +16,40 @@ enum dma_data_direction {
62035 };
62036
62037 struct dma_map_ops {
62038- void* (*alloc_coherent)(struct device *dev, size_t size,
62039+ void* (* const alloc_coherent)(struct device *dev, size_t size,
62040 dma_addr_t *dma_handle, gfp_t gfp);
62041- void (*free_coherent)(struct device *dev, size_t size,
62042+ void (* const free_coherent)(struct device *dev, size_t size,
62043 void *vaddr, dma_addr_t dma_handle);
62044- dma_addr_t (*map_page)(struct device *dev, struct page *page,
62045+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
62046 unsigned long offset, size_t size,
62047 enum dma_data_direction dir,
62048 struct dma_attrs *attrs);
62049- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
62050+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
62051 size_t size, enum dma_data_direction dir,
62052 struct dma_attrs *attrs);
62053- int (*map_sg)(struct device *dev, struct scatterlist *sg,
62054+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
62055 int nents, enum dma_data_direction dir,
62056 struct dma_attrs *attrs);
62057- void (*unmap_sg)(struct device *dev,
62058+ void (* const unmap_sg)(struct device *dev,
62059 struct scatterlist *sg, int nents,
62060 enum dma_data_direction dir,
62061 struct dma_attrs *attrs);
62062- void (*sync_single_for_cpu)(struct device *dev,
62063+ void (* const sync_single_for_cpu)(struct device *dev,
62064 dma_addr_t dma_handle, size_t size,
62065 enum dma_data_direction dir);
62066- void (*sync_single_for_device)(struct device *dev,
62067+ void (* const sync_single_for_device)(struct device *dev,
62068 dma_addr_t dma_handle, size_t size,
62069 enum dma_data_direction dir);
62070- void (*sync_sg_for_cpu)(struct device *dev,
62071+ void (* const sync_sg_for_cpu)(struct device *dev,
62072 struct scatterlist *sg, int nents,
62073 enum dma_data_direction dir);
62074- void (*sync_sg_for_device)(struct device *dev,
62075+ void (* const sync_sg_for_device)(struct device *dev,
62076 struct scatterlist *sg, int nents,
62077 enum dma_data_direction dir);
62078- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
62079- int (*dma_supported)(struct device *dev, u64 mask);
62080- int (*set_dma_mask)(struct device *dev, u64 mask);
62081- int is_phys;
62082+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
62083+ int (* const dma_supported)(struct device *dev, u64 mask);
62084+ int (* set_dma_mask)(struct device *dev, u64 mask);
62085+ const int is_phys;
62086 };
62087
62088 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62089diff -urNp linux-2.6.39.1/include/linux/elf.h linux-2.6.39.1/include/linux/elf.h
62090--- linux-2.6.39.1/include/linux/elf.h 2011-05-19 00:06:34.000000000 -0400
62091+++ linux-2.6.39.1/include/linux/elf.h 2011-05-22 19:36:33.000000000 -0400
62092@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
62093 #define PT_GNU_EH_FRAME 0x6474e550
62094
62095 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62096+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62097+
62098+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62099+
62100+/* Constants for the e_flags field */
62101+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62102+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62103+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62104+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62105+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62106+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62107
62108 /*
62109 * Extended Numbering
62110@@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
62111 #define DT_DEBUG 21
62112 #define DT_TEXTREL 22
62113 #define DT_JMPREL 23
62114+#define DT_FLAGS 30
62115+ #define DF_TEXTREL 0x00000004
62116 #define DT_ENCODING 32
62117 #define OLD_DT_LOOS 0x60000000
62118 #define DT_LOOS 0x6000000d
62119@@ -252,6 +265,19 @@ typedef struct elf64_hdr {
62120 #define PF_W 0x2
62121 #define PF_X 0x1
62122
62123+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62124+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62125+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62126+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62127+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62128+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62129+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62130+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62131+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62132+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62133+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62134+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62135+
62136 typedef struct elf32_phdr{
62137 Elf32_Word p_type;
62138 Elf32_Off p_offset;
62139@@ -344,6 +370,8 @@ typedef struct elf64_shdr {
62140 #define EI_OSABI 7
62141 #define EI_PAD 8
62142
62143+#define EI_PAX 14
62144+
62145 #define ELFMAG0 0x7f /* EI_MAG */
62146 #define ELFMAG1 'E'
62147 #define ELFMAG2 'L'
62148@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62149 #define elf_note elf32_note
62150 #define elf_addr_t Elf32_Off
62151 #define Elf_Half Elf32_Half
62152+#define elf_dyn Elf32_Dyn
62153
62154 #else
62155
62156@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62157 #define elf_note elf64_note
62158 #define elf_addr_t Elf64_Off
62159 #define Elf_Half Elf64_Half
62160+#define elf_dyn Elf64_Dyn
62161
62162 #endif
62163
62164diff -urNp linux-2.6.39.1/include/linux/enclosure.h linux-2.6.39.1/include/linux/enclosure.h
62165--- linux-2.6.39.1/include/linux/enclosure.h 2011-05-19 00:06:34.000000000 -0400
62166+++ linux-2.6.39.1/include/linux/enclosure.h 2011-05-22 19:36:33.000000000 -0400
62167@@ -98,7 +98,7 @@ struct enclosure_device {
62168 void *scratch;
62169 struct list_head node;
62170 struct device edev;
62171- struct enclosure_component_callbacks *cb;
62172+ const struct enclosure_component_callbacks *cb;
62173 int components;
62174 struct enclosure_component component[0];
62175 };
62176diff -urNp linux-2.6.39.1/include/linux/fscache-cache.h linux-2.6.39.1/include/linux/fscache-cache.h
62177--- linux-2.6.39.1/include/linux/fscache-cache.h 2011-05-19 00:06:34.000000000 -0400
62178+++ linux-2.6.39.1/include/linux/fscache-cache.h 2011-05-22 19:36:33.000000000 -0400
62179@@ -113,7 +113,7 @@ struct fscache_operation {
62180 #endif
62181 };
62182
62183-extern atomic_t fscache_op_debug_id;
62184+extern atomic_unchecked_t fscache_op_debug_id;
62185 extern void fscache_op_work_func(struct work_struct *work);
62186
62187 extern void fscache_enqueue_operation(struct fscache_operation *);
62188@@ -133,7 +133,7 @@ static inline void fscache_operation_ini
62189 {
62190 INIT_WORK(&op->work, fscache_op_work_func);
62191 atomic_set(&op->usage, 1);
62192- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62193+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62194 op->processor = processor;
62195 op->release = release;
62196 INIT_LIST_HEAD(&op->pend_link);
62197diff -urNp linux-2.6.39.1/include/linux/fs.h linux-2.6.39.1/include/linux/fs.h
62198--- linux-2.6.39.1/include/linux/fs.h 2011-05-19 00:06:34.000000000 -0400
62199+++ linux-2.6.39.1/include/linux/fs.h 2011-05-22 19:41:42.000000000 -0400
62200@@ -108,6 +108,11 @@ struct inodes_stat_t {
62201 /* File was opened by fanotify and shouldn't generate fanotify events */
62202 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
62203
62204+/* Hack for grsec so as not to require read permission simply to execute
62205+ * a binary
62206+ */
62207+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
62208+
62209 /*
62210 * The below are the various read and write types that we support. Some of
62211 * them include behavioral modifiers that send information down to the
62212@@ -575,41 +580,41 @@ typedef int (*read_actor_t)(read_descrip
62213 unsigned long, unsigned long);
62214
62215 struct address_space_operations {
62216- int (*writepage)(struct page *page, struct writeback_control *wbc);
62217- int (*readpage)(struct file *, struct page *);
62218+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
62219+ int (* const readpage)(struct file *, struct page *);
62220
62221 /* Write back some dirty pages from this mapping. */
62222- int (*writepages)(struct address_space *, struct writeback_control *);
62223+ int (* const writepages)(struct address_space *, struct writeback_control *);
62224
62225 /* Set a page dirty. Return true if this dirtied it */
62226- int (*set_page_dirty)(struct page *page);
62227+ int (* const set_page_dirty)(struct page *page);
62228
62229- int (*readpages)(struct file *filp, struct address_space *mapping,
62230+ int (* const readpages)(struct file *filp, struct address_space *mapping,
62231 struct list_head *pages, unsigned nr_pages);
62232
62233- int (*write_begin)(struct file *, struct address_space *mapping,
62234+ int (* const write_begin)(struct file *, struct address_space *mapping,
62235 loff_t pos, unsigned len, unsigned flags,
62236 struct page **pagep, void **fsdata);
62237- int (*write_end)(struct file *, struct address_space *mapping,
62238+ int (* const write_end)(struct file *, struct address_space *mapping,
62239 loff_t pos, unsigned len, unsigned copied,
62240 struct page *page, void *fsdata);
62241
62242 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
62243- sector_t (*bmap)(struct address_space *, sector_t);
62244- void (*invalidatepage) (struct page *, unsigned long);
62245- int (*releasepage) (struct page *, gfp_t);
62246- void (*freepage)(struct page *);
62247- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
62248+ sector_t (* const bmap)(struct address_space *, sector_t);
62249+ void (* const invalidatepage) (struct page *, unsigned long);
62250+ int (* const releasepage) (struct page *, gfp_t);
62251+ void (* const freepage)(struct page *);
62252+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
62253 loff_t offset, unsigned long nr_segs);
62254- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
62255+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
62256 void **, unsigned long *);
62257 /* migrate the contents of a page to the specified target */
62258- int (*migratepage) (struct address_space *,
62259+ int (* const migratepage) (struct address_space *,
62260 struct page *, struct page *);
62261- int (*launder_page) (struct page *);
62262- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
62263+ int (* const launder_page) (struct page *);
62264+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
62265 unsigned long);
62266- int (*error_remove_page)(struct address_space *, struct page *);
62267+ int (* const error_remove_page)(struct address_space *, struct page *);
62268 };
62269
62270 extern const struct address_space_operations empty_aops;
62271@@ -1060,17 +1065,17 @@ static inline int file_check_writeable(s
62272 typedef struct files_struct *fl_owner_t;
62273
62274 struct file_lock_operations {
62275- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62276- void (*fl_release_private)(struct file_lock *);
62277+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62278+ void (* const fl_release_private)(struct file_lock *);
62279 };
62280
62281 struct lock_manager_operations {
62282- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
62283- void (*fl_notify)(struct file_lock *); /* unblock callback */
62284- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
62285- void (*fl_release_private)(struct file_lock *);
62286- void (*fl_break)(struct file_lock *);
62287- int (*fl_change)(struct file_lock **, int);
62288+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
62289+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
62290+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
62291+ void (* const fl_release_private)(struct file_lock *);
62292+ void (* const fl_break)(struct file_lock *);
62293+ int (* const fl_change)(struct file_lock **, int);
62294 };
62295
62296 struct lock_manager {
62297@@ -1611,31 +1616,31 @@ extern ssize_t vfs_writev(struct file *,
62298 unsigned long, loff_t *);
62299
62300 struct super_operations {
62301- struct inode *(*alloc_inode)(struct super_block *sb);
62302- void (*destroy_inode)(struct inode *);
62303+ struct inode *(* const alloc_inode)(struct super_block *sb);
62304+ void (* const destroy_inode)(struct inode *);
62305
62306- void (*dirty_inode) (struct inode *);
62307- int (*write_inode) (struct inode *, struct writeback_control *wbc);
62308- int (*drop_inode) (struct inode *);
62309- void (*evict_inode) (struct inode *);
62310- void (*put_super) (struct super_block *);
62311- void (*write_super) (struct super_block *);
62312- int (*sync_fs)(struct super_block *sb, int wait);
62313- int (*freeze_fs) (struct super_block *);
62314- int (*unfreeze_fs) (struct super_block *);
62315- int (*statfs) (struct dentry *, struct kstatfs *);
62316- int (*remount_fs) (struct super_block *, int *, char *);
62317- void (*umount_begin) (struct super_block *);
62318-
62319- int (*show_options)(struct seq_file *, struct vfsmount *);
62320- int (*show_devname)(struct seq_file *, struct vfsmount *);
62321- int (*show_path)(struct seq_file *, struct vfsmount *);
62322- int (*show_stats)(struct seq_file *, struct vfsmount *);
62323+ void (* const dirty_inode) (struct inode *);
62324+ int (* const write_inode) (struct inode *, struct writeback_control *wbc);
62325+ int (* const drop_inode) (struct inode *);
62326+ void (* const evict_inode) (struct inode *);
62327+ void (* const put_super) (struct super_block *);
62328+ void (* const write_super) (struct super_block *);
62329+ int (* const sync_fs)(struct super_block *sb, int wait);
62330+ int (* const freeze_fs) (struct super_block *);
62331+ int (* const unfreeze_fs) (struct super_block *);
62332+ int (* const statfs) (struct dentry *, struct kstatfs *);
62333+ int (* const remount_fs) (struct super_block *, int *, char *);
62334+ void (* const umount_begin) (struct super_block *);
62335+
62336+ int (* const show_options)(struct seq_file *, struct vfsmount *);
62337+ int (* const show_devname)(struct seq_file *, struct vfsmount *);
62338+ int (* const show_path)(struct seq_file *, struct vfsmount *);
62339+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
62340 #ifdef CONFIG_QUOTA
62341- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
62342- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62343+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
62344+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62345 #endif
62346- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62347+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62348 };
62349
62350 /*
62351diff -urNp linux-2.6.39.1/include/linux/fs_struct.h linux-2.6.39.1/include/linux/fs_struct.h
62352--- linux-2.6.39.1/include/linux/fs_struct.h 2011-05-19 00:06:34.000000000 -0400
62353+++ linux-2.6.39.1/include/linux/fs_struct.h 2011-05-22 19:36:33.000000000 -0400
62354@@ -6,7 +6,7 @@
62355 #include <linux/seqlock.h>
62356
62357 struct fs_struct {
62358- int users;
62359+ atomic_t users;
62360 spinlock_t lock;
62361 seqcount_t seq;
62362 int umask;
62363diff -urNp linux-2.6.39.1/include/linux/ftrace_event.h linux-2.6.39.1/include/linux/ftrace_event.h
62364--- linux-2.6.39.1/include/linux/ftrace_event.h 2011-05-19 00:06:34.000000000 -0400
62365+++ linux-2.6.39.1/include/linux/ftrace_event.h 2011-05-22 19:36:33.000000000 -0400
62366@@ -235,7 +235,7 @@ extern int trace_define_field(struct ftr
62367 extern int trace_add_event_call(struct ftrace_event_call *call);
62368 extern void trace_remove_event_call(struct ftrace_event_call *call);
62369
62370-#define is_signed_type(type) (((type)(-1)) < 0)
62371+#define is_signed_type(type) (((type)(-1)) < (type)1)
62372
62373 int trace_set_clr_event(const char *system, const char *event, int set);
62374
62375diff -urNp linux-2.6.39.1/include/linux/ftrace.h linux-2.6.39.1/include/linux/ftrace.h
62376--- linux-2.6.39.1/include/linux/ftrace.h 2011-05-19 00:06:34.000000000 -0400
62377+++ linux-2.6.39.1/include/linux/ftrace.h 2011-05-22 19:36:33.000000000 -0400
62378@@ -140,7 +140,7 @@ extern void
62379 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62380 void *data);
62381 extern void
62382-unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
62383+unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops);
62384 extern void unregister_ftrace_function_probe_all(char *glob);
62385
62386 extern int ftrace_text_reserved(void *start, void *end);
62387diff -urNp linux-2.6.39.1/include/linux/genhd.h linux-2.6.39.1/include/linux/genhd.h
62388--- linux-2.6.39.1/include/linux/genhd.h 2011-06-03 00:04:14.000000000 -0400
62389+++ linux-2.6.39.1/include/linux/genhd.h 2011-06-03 00:32:08.000000000 -0400
62390@@ -184,7 +184,7 @@ struct gendisk {
62391 struct kobject *slave_dir;
62392
62393 struct timer_rand_state *random;
62394- atomic_t sync_io; /* RAID */
62395+ atomic_unchecked_t sync_io; /* RAID */
62396 struct disk_events *ev;
62397 #ifdef CONFIG_BLK_DEV_INTEGRITY
62398 struct blk_integrity *integrity;
62399diff -urNp linux-2.6.39.1/include/linux/gracl.h linux-2.6.39.1/include/linux/gracl.h
62400--- linux-2.6.39.1/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
62401+++ linux-2.6.39.1/include/linux/gracl.h 2011-05-22 19:41:42.000000000 -0400
62402@@ -0,0 +1,317 @@
62403+#ifndef GR_ACL_H
62404+#define GR_ACL_H
62405+
62406+#include <linux/grdefs.h>
62407+#include <linux/resource.h>
62408+#include <linux/capability.h>
62409+#include <linux/dcache.h>
62410+#include <asm/resource.h>
62411+
62412+/* Major status information */
62413+
62414+#define GR_VERSION "grsecurity 2.2.2"
62415+#define GRSECURITY_VERSION 0x2202
62416+
62417+enum {
62418+ GR_SHUTDOWN = 0,
62419+ GR_ENABLE = 1,
62420+ GR_SPROLE = 2,
62421+ GR_RELOAD = 3,
62422+ GR_SEGVMOD = 4,
62423+ GR_STATUS = 5,
62424+ GR_UNSPROLE = 6,
62425+ GR_PASSSET = 7,
62426+ GR_SPROLEPAM = 8,
62427+};
62428+
62429+/* Password setup definitions
62430+ * kernel/grhash.c */
62431+enum {
62432+ GR_PW_LEN = 128,
62433+ GR_SALT_LEN = 16,
62434+ GR_SHA_LEN = 32,
62435+};
62436+
62437+enum {
62438+ GR_SPROLE_LEN = 64,
62439+};
62440+
62441+enum {
62442+ GR_NO_GLOB = 0,
62443+ GR_REG_GLOB,
62444+ GR_CREATE_GLOB
62445+};
62446+
62447+#define GR_NLIMITS 32
62448+
62449+/* Begin Data Structures */
62450+
62451+struct sprole_pw {
62452+ unsigned char *rolename;
62453+ unsigned char salt[GR_SALT_LEN];
62454+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62455+};
62456+
62457+struct name_entry {
62458+ __u32 key;
62459+ ino_t inode;
62460+ dev_t device;
62461+ char *name;
62462+ __u16 len;
62463+ __u8 deleted;
62464+ struct name_entry *prev;
62465+ struct name_entry *next;
62466+};
62467+
62468+struct inodev_entry {
62469+ struct name_entry *nentry;
62470+ struct inodev_entry *prev;
62471+ struct inodev_entry *next;
62472+};
62473+
62474+struct acl_role_db {
62475+ struct acl_role_label **r_hash;
62476+ __u32 r_size;
62477+};
62478+
62479+struct inodev_db {
62480+ struct inodev_entry **i_hash;
62481+ __u32 i_size;
62482+};
62483+
62484+struct name_db {
62485+ struct name_entry **n_hash;
62486+ __u32 n_size;
62487+};
62488+
62489+struct crash_uid {
62490+ uid_t uid;
62491+ unsigned long expires;
62492+};
62493+
62494+struct gr_hash_struct {
62495+ void **table;
62496+ void **nametable;
62497+ void *first;
62498+ __u32 table_size;
62499+ __u32 used_size;
62500+ int type;
62501+};
62502+
62503+/* Userspace Grsecurity ACL data structures */
62504+
62505+struct acl_subject_label {
62506+ char *filename;
62507+ ino_t inode;
62508+ dev_t device;
62509+ __u32 mode;
62510+ kernel_cap_t cap_mask;
62511+ kernel_cap_t cap_lower;
62512+ kernel_cap_t cap_invert_audit;
62513+
62514+ struct rlimit res[GR_NLIMITS];
62515+ __u32 resmask;
62516+
62517+ __u8 user_trans_type;
62518+ __u8 group_trans_type;
62519+ uid_t *user_transitions;
62520+ gid_t *group_transitions;
62521+ __u16 user_trans_num;
62522+ __u16 group_trans_num;
62523+
62524+ __u32 sock_families[2];
62525+ __u32 ip_proto[8];
62526+ __u32 ip_type;
62527+ struct acl_ip_label **ips;
62528+ __u32 ip_num;
62529+ __u32 inaddr_any_override;
62530+
62531+ __u32 crashes;
62532+ unsigned long expires;
62533+
62534+ struct acl_subject_label *parent_subject;
62535+ struct gr_hash_struct *hash;
62536+ struct acl_subject_label *prev;
62537+ struct acl_subject_label *next;
62538+
62539+ struct acl_object_label **obj_hash;
62540+ __u32 obj_hash_size;
62541+ __u16 pax_flags;
62542+};
62543+
62544+struct role_allowed_ip {
62545+ __u32 addr;
62546+ __u32 netmask;
62547+
62548+ struct role_allowed_ip *prev;
62549+ struct role_allowed_ip *next;
62550+};
62551+
62552+struct role_transition {
62553+ char *rolename;
62554+
62555+ struct role_transition *prev;
62556+ struct role_transition *next;
62557+};
62558+
62559+struct acl_role_label {
62560+ char *rolename;
62561+ uid_t uidgid;
62562+ __u16 roletype;
62563+
62564+ __u16 auth_attempts;
62565+ unsigned long expires;
62566+
62567+ struct acl_subject_label *root_label;
62568+ struct gr_hash_struct *hash;
62569+
62570+ struct acl_role_label *prev;
62571+ struct acl_role_label *next;
62572+
62573+ struct role_transition *transitions;
62574+ struct role_allowed_ip *allowed_ips;
62575+ uid_t *domain_children;
62576+ __u16 domain_child_num;
62577+
62578+ struct acl_subject_label **subj_hash;
62579+ __u32 subj_hash_size;
62580+};
62581+
62582+struct user_acl_role_db {
62583+ struct acl_role_label **r_table;
62584+ __u32 num_pointers; /* Number of allocations to track */
62585+ __u32 num_roles; /* Number of roles */
62586+ __u32 num_domain_children; /* Number of domain children */
62587+ __u32 num_subjects; /* Number of subjects */
62588+ __u32 num_objects; /* Number of objects */
62589+};
62590+
62591+struct acl_object_label {
62592+ char *filename;
62593+ ino_t inode;
62594+ dev_t device;
62595+ __u32 mode;
62596+
62597+ struct acl_subject_label *nested;
62598+ struct acl_object_label *globbed;
62599+
62600+ /* next two structures not used */
62601+
62602+ struct acl_object_label *prev;
62603+ struct acl_object_label *next;
62604+};
62605+
62606+struct acl_ip_label {
62607+ char *iface;
62608+ __u32 addr;
62609+ __u32 netmask;
62610+ __u16 low, high;
62611+ __u8 mode;
62612+ __u32 type;
62613+ __u32 proto[8];
62614+
62615+ /* next two structures not used */
62616+
62617+ struct acl_ip_label *prev;
62618+ struct acl_ip_label *next;
62619+};
62620+
62621+struct gr_arg {
62622+ struct user_acl_role_db role_db;
62623+ unsigned char pw[GR_PW_LEN];
62624+ unsigned char salt[GR_SALT_LEN];
62625+ unsigned char sum[GR_SHA_LEN];
62626+ unsigned char sp_role[GR_SPROLE_LEN];
62627+ struct sprole_pw *sprole_pws;
62628+ dev_t segv_device;
62629+ ino_t segv_inode;
62630+ uid_t segv_uid;
62631+ __u16 num_sprole_pws;
62632+ __u16 mode;
62633+};
62634+
62635+struct gr_arg_wrapper {
62636+ struct gr_arg *arg;
62637+ __u32 version;
62638+ __u32 size;
62639+};
62640+
62641+struct subject_map {
62642+ struct acl_subject_label *user;
62643+ struct acl_subject_label *kernel;
62644+ struct subject_map *prev;
62645+ struct subject_map *next;
62646+};
62647+
62648+struct acl_subj_map_db {
62649+ struct subject_map **s_hash;
62650+ __u32 s_size;
62651+};
62652+
62653+/* End Data Structures Section */
62654+
62655+/* Hash functions generated by empirical testing by Brad Spengler
62656+ Makes good use of the low bits of the inode. Generally 0-1 times
62657+ in loop for successful match. 0-3 for unsuccessful match.
62658+ Shift/add algorithm with modulus of table size and an XOR*/
62659+
62660+static __inline__ unsigned int
62661+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62662+{
62663+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
62664+}
62665+
62666+ static __inline__ unsigned int
62667+shash(const struct acl_subject_label *userp, const unsigned int sz)
62668+{
62669+ return ((const unsigned long)userp % sz);
62670+}
62671+
62672+static __inline__ unsigned int
62673+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62674+{
62675+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62676+}
62677+
62678+static __inline__ unsigned int
62679+nhash(const char *name, const __u16 len, const unsigned int sz)
62680+{
62681+ return full_name_hash((const unsigned char *)name, len) % sz;
62682+}
62683+
62684+#define FOR_EACH_ROLE_START(role) \
62685+ role = role_list; \
62686+ while (role) {
62687+
62688+#define FOR_EACH_ROLE_END(role) \
62689+ role = role->prev; \
62690+ }
62691+
62692+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62693+ subj = NULL; \
62694+ iter = 0; \
62695+ while (iter < role->subj_hash_size) { \
62696+ if (subj == NULL) \
62697+ subj = role->subj_hash[iter]; \
62698+ if (subj == NULL) { \
62699+ iter++; \
62700+ continue; \
62701+ }
62702+
62703+#define FOR_EACH_SUBJECT_END(subj,iter) \
62704+ subj = subj->next; \
62705+ if (subj == NULL) \
62706+ iter++; \
62707+ }
62708+
62709+
62710+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62711+ subj = role->hash->first; \
62712+ while (subj != NULL) {
62713+
62714+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62715+ subj = subj->next; \
62716+ }
62717+
62718+#endif
62719+
62720diff -urNp linux-2.6.39.1/include/linux/gralloc.h linux-2.6.39.1/include/linux/gralloc.h
62721--- linux-2.6.39.1/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
62722+++ linux-2.6.39.1/include/linux/gralloc.h 2011-05-22 19:41:42.000000000 -0400
62723@@ -0,0 +1,9 @@
62724+#ifndef __GRALLOC_H
62725+#define __GRALLOC_H
62726+
62727+void acl_free_all(void);
62728+int acl_alloc_stack_init(unsigned long size);
62729+void *acl_alloc(unsigned long len);
62730+void *acl_alloc_num(unsigned long num, unsigned long len);
62731+
62732+#endif
62733diff -urNp linux-2.6.39.1/include/linux/grdefs.h linux-2.6.39.1/include/linux/grdefs.h
62734--- linux-2.6.39.1/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
62735+++ linux-2.6.39.1/include/linux/grdefs.h 2011-06-11 16:24:51.000000000 -0400
62736@@ -0,0 +1,140 @@
62737+#ifndef GRDEFS_H
62738+#define GRDEFS_H
62739+
62740+/* Begin grsecurity status declarations */
62741+
62742+enum {
62743+ GR_READY = 0x01,
62744+ GR_STATUS_INIT = 0x00 // disabled state
62745+};
62746+
62747+/* Begin ACL declarations */
62748+
62749+/* Role flags */
62750+
62751+enum {
62752+ GR_ROLE_USER = 0x0001,
62753+ GR_ROLE_GROUP = 0x0002,
62754+ GR_ROLE_DEFAULT = 0x0004,
62755+ GR_ROLE_SPECIAL = 0x0008,
62756+ GR_ROLE_AUTH = 0x0010,
62757+ GR_ROLE_NOPW = 0x0020,
62758+ GR_ROLE_GOD = 0x0040,
62759+ GR_ROLE_LEARN = 0x0080,
62760+ GR_ROLE_TPE = 0x0100,
62761+ GR_ROLE_DOMAIN = 0x0200,
62762+ GR_ROLE_PAM = 0x0400,
62763+ GR_ROLE_PERSIST = 0x0800
62764+};
62765+
62766+/* ACL Subject and Object mode flags */
62767+enum {
62768+ GR_DELETED = 0x80000000
62769+};
62770+
62771+/* ACL Object-only mode flags */
62772+enum {
62773+ GR_READ = 0x00000001,
62774+ GR_APPEND = 0x00000002,
62775+ GR_WRITE = 0x00000004,
62776+ GR_EXEC = 0x00000008,
62777+ GR_FIND = 0x00000010,
62778+ GR_INHERIT = 0x00000020,
62779+ GR_SETID = 0x00000040,
62780+ GR_CREATE = 0x00000080,
62781+ GR_DELETE = 0x00000100,
62782+ GR_LINK = 0x00000200,
62783+ GR_AUDIT_READ = 0x00000400,
62784+ GR_AUDIT_APPEND = 0x00000800,
62785+ GR_AUDIT_WRITE = 0x00001000,
62786+ GR_AUDIT_EXEC = 0x00002000,
62787+ GR_AUDIT_FIND = 0x00004000,
62788+ GR_AUDIT_INHERIT= 0x00008000,
62789+ GR_AUDIT_SETID = 0x00010000,
62790+ GR_AUDIT_CREATE = 0x00020000,
62791+ GR_AUDIT_DELETE = 0x00040000,
62792+ GR_AUDIT_LINK = 0x00080000,
62793+ GR_PTRACERD = 0x00100000,
62794+ GR_NOPTRACE = 0x00200000,
62795+ GR_SUPPRESS = 0x00400000,
62796+ GR_NOLEARN = 0x00800000,
62797+ GR_INIT_TRANSFER= 0x01000000
62798+};
62799+
62800+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62801+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62802+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62803+
62804+/* ACL subject-only mode flags */
62805+enum {
62806+ GR_KILL = 0x00000001,
62807+ GR_VIEW = 0x00000002,
62808+ GR_PROTECTED = 0x00000004,
62809+ GR_LEARN = 0x00000008,
62810+ GR_OVERRIDE = 0x00000010,
62811+ /* just a placeholder, this mode is only used in userspace */
62812+ GR_DUMMY = 0x00000020,
62813+ GR_PROTSHM = 0x00000040,
62814+ GR_KILLPROC = 0x00000080,
62815+ GR_KILLIPPROC = 0x00000100,
62816+ /* just a placeholder, this mode is only used in userspace */
62817+ GR_NOTROJAN = 0x00000200,
62818+ GR_PROTPROCFD = 0x00000400,
62819+ GR_PROCACCT = 0x00000800,
62820+ GR_RELAXPTRACE = 0x00001000,
62821+ GR_NESTED = 0x00002000,
62822+ GR_INHERITLEARN = 0x00004000,
62823+ GR_PROCFIND = 0x00008000,
62824+ GR_POVERRIDE = 0x00010000,
62825+ GR_KERNELAUTH = 0x00020000,
62826+ GR_ATSECURE = 0x00040000,
62827+ GR_SHMEXEC = 0x00080000
62828+};
62829+
62830+enum {
62831+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62832+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62833+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62834+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62835+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62836+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62837+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62838+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62839+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62840+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62841+};
62842+
62843+enum {
62844+ GR_ID_USER = 0x01,
62845+ GR_ID_GROUP = 0x02,
62846+};
62847+
62848+enum {
62849+ GR_ID_ALLOW = 0x01,
62850+ GR_ID_DENY = 0x02,
62851+};
62852+
62853+#define GR_CRASH_RES 31
62854+#define GR_UIDTABLE_MAX 500
62855+
62856+/* begin resource learning section */
62857+enum {
62858+ GR_RLIM_CPU_BUMP = 60,
62859+ GR_RLIM_FSIZE_BUMP = 50000,
62860+ GR_RLIM_DATA_BUMP = 10000,
62861+ GR_RLIM_STACK_BUMP = 1000,
62862+ GR_RLIM_CORE_BUMP = 10000,
62863+ GR_RLIM_RSS_BUMP = 500000,
62864+ GR_RLIM_NPROC_BUMP = 1,
62865+ GR_RLIM_NOFILE_BUMP = 5,
62866+ GR_RLIM_MEMLOCK_BUMP = 50000,
62867+ GR_RLIM_AS_BUMP = 500000,
62868+ GR_RLIM_LOCKS_BUMP = 2,
62869+ GR_RLIM_SIGPENDING_BUMP = 5,
62870+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62871+ GR_RLIM_NICE_BUMP = 1,
62872+ GR_RLIM_RTPRIO_BUMP = 1,
62873+ GR_RLIM_RTTIME_BUMP = 1000000
62874+};
62875+
62876+#endif
62877diff -urNp linux-2.6.39.1/include/linux/grinternal.h linux-2.6.39.1/include/linux/grinternal.h
62878--- linux-2.6.39.1/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
62879+++ linux-2.6.39.1/include/linux/grinternal.h 2011-05-22 19:41:42.000000000 -0400
62880@@ -0,0 +1,219 @@
62881+#ifndef __GRINTERNAL_H
62882+#define __GRINTERNAL_H
62883+
62884+#ifdef CONFIG_GRKERNSEC
62885+
62886+#include <linux/fs.h>
62887+#include <linux/mnt_namespace.h>
62888+#include <linux/nsproxy.h>
62889+#include <linux/gracl.h>
62890+#include <linux/grdefs.h>
62891+#include <linux/grmsg.h>
62892+
62893+void gr_add_learn_entry(const char *fmt, ...)
62894+ __attribute__ ((format (printf, 1, 2)));
62895+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62896+ const struct vfsmount *mnt);
62897+__u32 gr_check_create(const struct dentry *new_dentry,
62898+ const struct dentry *parent,
62899+ const struct vfsmount *mnt, const __u32 mode);
62900+int gr_check_protected_task(const struct task_struct *task);
62901+__u32 to_gr_audit(const __u32 reqmode);
62902+int gr_set_acls(const int type);
62903+int gr_apply_subject_to_task(struct task_struct *task);
62904+int gr_acl_is_enabled(void);
62905+char gr_roletype_to_char(void);
62906+
62907+void gr_handle_alertkill(struct task_struct *task);
62908+char *gr_to_filename(const struct dentry *dentry,
62909+ const struct vfsmount *mnt);
62910+char *gr_to_filename1(const struct dentry *dentry,
62911+ const struct vfsmount *mnt);
62912+char *gr_to_filename2(const struct dentry *dentry,
62913+ const struct vfsmount *mnt);
62914+char *gr_to_filename3(const struct dentry *dentry,
62915+ const struct vfsmount *mnt);
62916+
62917+extern int grsec_enable_harden_ptrace;
62918+extern int grsec_enable_link;
62919+extern int grsec_enable_fifo;
62920+extern int grsec_enable_execve;
62921+extern int grsec_enable_shm;
62922+extern int grsec_enable_execlog;
62923+extern int grsec_enable_signal;
62924+extern int grsec_enable_audit_ptrace;
62925+extern int grsec_enable_forkfail;
62926+extern int grsec_enable_time;
62927+extern int grsec_enable_rofs;
62928+extern int grsec_enable_chroot_shmat;
62929+extern int grsec_enable_chroot_findtask;
62930+extern int grsec_enable_chroot_mount;
62931+extern int grsec_enable_chroot_double;
62932+extern int grsec_enable_chroot_pivot;
62933+extern int grsec_enable_chroot_chdir;
62934+extern int grsec_enable_chroot_chmod;
62935+extern int grsec_enable_chroot_mknod;
62936+extern int grsec_enable_chroot_fchdir;
62937+extern int grsec_enable_chroot_nice;
62938+extern int grsec_enable_chroot_execlog;
62939+extern int grsec_enable_chroot_caps;
62940+extern int grsec_enable_chroot_sysctl;
62941+extern int grsec_enable_chroot_unix;
62942+extern int grsec_enable_tpe;
62943+extern int grsec_tpe_gid;
62944+extern int grsec_enable_tpe_all;
62945+extern int grsec_enable_tpe_invert;
62946+extern int grsec_enable_socket_all;
62947+extern int grsec_socket_all_gid;
62948+extern int grsec_enable_socket_client;
62949+extern int grsec_socket_client_gid;
62950+extern int grsec_enable_socket_server;
62951+extern int grsec_socket_server_gid;
62952+extern int grsec_audit_gid;
62953+extern int grsec_enable_group;
62954+extern int grsec_enable_audit_textrel;
62955+extern int grsec_enable_log_rwxmaps;
62956+extern int grsec_enable_mount;
62957+extern int grsec_enable_chdir;
62958+extern int grsec_resource_logging;
62959+extern int grsec_enable_blackhole;
62960+extern int grsec_lastack_retries;
62961+extern int grsec_lock;
62962+
62963+extern spinlock_t grsec_alert_lock;
62964+extern unsigned long grsec_alert_wtime;
62965+extern unsigned long grsec_alert_fyet;
62966+
62967+extern spinlock_t grsec_audit_lock;
62968+
62969+extern rwlock_t grsec_exec_file_lock;
62970+
62971+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62972+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62973+ (tsk)->exec_file->f_vfsmnt) : "/")
62974+
62975+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62976+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62977+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62978+
62979+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62980+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62981+ (tsk)->exec_file->f_vfsmnt) : "/")
62982+
62983+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62984+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62985+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62986+
62987+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62988+
62989+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62990+
62991+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62992+ (task)->pid, (cred)->uid, \
62993+ (cred)->euid, (cred)->gid, (cred)->egid, \
62994+ gr_parent_task_fullpath(task), \
62995+ (task)->real_parent->comm, (task)->real_parent->pid, \
62996+ (pcred)->uid, (pcred)->euid, \
62997+ (pcred)->gid, (pcred)->egid
62998+
62999+#define GR_CHROOT_CAPS {{ \
63000+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
63001+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
63002+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
63003+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
63004+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
63005+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
63006+
63007+#define security_learn(normal_msg,args...) \
63008+({ \
63009+ read_lock(&grsec_exec_file_lock); \
63010+ gr_add_learn_entry(normal_msg "\n", ## args); \
63011+ read_unlock(&grsec_exec_file_lock); \
63012+})
63013+
63014+enum {
63015+ GR_DO_AUDIT,
63016+ GR_DONT_AUDIT,
63017+ /* used for non-audit messages that we shouldn't kill the task on */
63018+ GR_DONT_AUDIT_GOOD
63019+};
63020+
63021+enum {
63022+ GR_TTYSNIFF,
63023+ GR_RBAC,
63024+ GR_RBAC_STR,
63025+ GR_STR_RBAC,
63026+ GR_RBAC_MODE2,
63027+ GR_RBAC_MODE3,
63028+ GR_FILENAME,
63029+ GR_SYSCTL_HIDDEN,
63030+ GR_NOARGS,
63031+ GR_ONE_INT,
63032+ GR_ONE_INT_TWO_STR,
63033+ GR_ONE_STR,
63034+ GR_STR_INT,
63035+ GR_TWO_STR_INT,
63036+ GR_TWO_INT,
63037+ GR_TWO_U64,
63038+ GR_THREE_INT,
63039+ GR_FIVE_INT_TWO_STR,
63040+ GR_TWO_STR,
63041+ GR_THREE_STR,
63042+ GR_FOUR_STR,
63043+ GR_STR_FILENAME,
63044+ GR_FILENAME_STR,
63045+ GR_FILENAME_TWO_INT,
63046+ GR_FILENAME_TWO_INT_STR,
63047+ GR_TEXTREL,
63048+ GR_PTRACE,
63049+ GR_RESOURCE,
63050+ GR_CAP,
63051+ GR_SIG,
63052+ GR_SIG2,
63053+ GR_CRASH1,
63054+ GR_CRASH2,
63055+ GR_PSACCT,
63056+ GR_RWXMAP
63057+};
63058+
63059+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63060+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63061+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63062+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63063+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63064+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63065+#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)
63066+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63067+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63068+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63069+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63070+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63071+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63072+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63073+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63074+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63075+#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)
63076+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63077+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63078+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63079+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63080+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63081+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63082+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63083+#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)
63084+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63085+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63086+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63087+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63088+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63089+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63090+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63091+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63092+#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)
63093+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63094+
63095+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63096+
63097+#endif
63098+
63099+#endif
63100diff -urNp linux-2.6.39.1/include/linux/grmsg.h linux-2.6.39.1/include/linux/grmsg.h
63101--- linux-2.6.39.1/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
63102+++ linux-2.6.39.1/include/linux/grmsg.h 2011-05-22 19:41:42.000000000 -0400
63103@@ -0,0 +1,108 @@
63104+#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"
63105+#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"
63106+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63107+#define GR_STOPMOD_MSG "denied modification of module state by "
63108+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63109+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63110+#define GR_IOPERM_MSG "denied use of ioperm() by "
63111+#define GR_IOPL_MSG "denied use of iopl() by "
63112+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63113+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63114+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63115+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63116+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63117+#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"
63118+#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"
63119+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63120+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63121+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63122+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63123+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63124+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63125+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63126+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63127+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63128+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63129+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63130+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63131+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63132+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63133+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63134+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63135+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63136+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63137+#define GR_NPROC_MSG "denied overstep of process limit by "
63138+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63139+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
63140+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63141+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63142+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63143+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63144+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63145+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63146+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63147+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63148+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
63149+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63150+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63151+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63152+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63153+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63154+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63155+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63156+#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"
63157+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
63158+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63159+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63160+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63161+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63162+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63163+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63164+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63165+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63166+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63167+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63168+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63169+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63170+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63171+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63172+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63173+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63174+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63175+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63176+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63177+#define GR_FAILFORK_MSG "failed fork with errno %s by "
63178+#define GR_NICE_CHROOT_MSG "denied priority change by "
63179+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63180+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63181+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63182+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63183+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63184+#define GR_TIME_MSG "time set by "
63185+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63186+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63187+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63188+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63189+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63190+#define GR_BIND_MSG "denied bind() by "
63191+#define GR_CONNECT_MSG "denied connect() by "
63192+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63193+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63194+#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"
63195+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63196+#define GR_CAP_ACL_MSG "use of %s denied for "
63197+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63198+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63199+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63200+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63201+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63202+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63203+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63204+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63205+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63206+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63207+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63208+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63209+#define GR_VM86_MSG "denied use of vm86 by "
63210+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63211+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63212diff -urNp linux-2.6.39.1/include/linux/grsecurity.h linux-2.6.39.1/include/linux/grsecurity.h
63213--- linux-2.6.39.1/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
63214+++ linux-2.6.39.1/include/linux/grsecurity.h 2011-05-22 19:41:42.000000000 -0400
63215@@ -0,0 +1,212 @@
63216+#ifndef GR_SECURITY_H
63217+#define GR_SECURITY_H
63218+#include <linux/fs.h>
63219+#include <linux/fs_struct.h>
63220+#include <linux/binfmts.h>
63221+#include <linux/gracl.h>
63222+#include <linux/compat.h>
63223+
63224+/* notify of brain-dead configs */
63225+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63226+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63227+#endif
63228+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63229+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63230+#endif
63231+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63232+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63233+#endif
63234+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63235+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63236+#endif
63237+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63238+#error "CONFIG_PAX enabled, but no PaX options are enabled."
63239+#endif
63240+
63241+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63242+void gr_handle_brute_check(void);
63243+void gr_handle_kernel_exploit(void);
63244+int gr_process_user_ban(void);
63245+
63246+char gr_roletype_to_char(void);
63247+
63248+int gr_acl_enable_at_secure(void);
63249+
63250+int gr_check_user_change(int real, int effective, int fs);
63251+int gr_check_group_change(int real, int effective, int fs);
63252+
63253+void gr_del_task_from_ip_table(struct task_struct *p);
63254+
63255+int gr_pid_is_chrooted(struct task_struct *p);
63256+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63257+int gr_handle_chroot_nice(void);
63258+int gr_handle_chroot_sysctl(const int op);
63259+int gr_handle_chroot_setpriority(struct task_struct *p,
63260+ const int niceval);
63261+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63262+int gr_handle_chroot_chroot(const struct dentry *dentry,
63263+ const struct vfsmount *mnt);
63264+int gr_handle_chroot_caps(struct path *path);
63265+void gr_handle_chroot_chdir(struct path *path);
63266+int gr_handle_chroot_chmod(const struct dentry *dentry,
63267+ const struct vfsmount *mnt, const int mode);
63268+int gr_handle_chroot_mknod(const struct dentry *dentry,
63269+ const struct vfsmount *mnt, const int mode);
63270+int gr_handle_chroot_mount(const struct dentry *dentry,
63271+ const struct vfsmount *mnt,
63272+ const char *dev_name);
63273+int gr_handle_chroot_pivot(void);
63274+int gr_handle_chroot_unix(struct pid *pid);
63275+
63276+int gr_handle_rawio(const struct inode *inode);
63277+int gr_handle_nproc(void);
63278+
63279+void gr_handle_ioperm(void);
63280+void gr_handle_iopl(void);
63281+
63282+int gr_tpe_allow(const struct file *file);
63283+
63284+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63285+void gr_clear_chroot_entries(struct task_struct *task);
63286+
63287+void gr_log_forkfail(const int retval);
63288+void gr_log_timechange(void);
63289+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63290+void gr_log_chdir(const struct dentry *dentry,
63291+ const struct vfsmount *mnt);
63292+void gr_log_chroot_exec(const struct dentry *dentry,
63293+ const struct vfsmount *mnt);
63294+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
63295+#ifdef CONFIG_COMPAT
63296+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
63297+#endif
63298+void gr_log_remount(const char *devname, const int retval);
63299+void gr_log_unmount(const char *devname, const int retval);
63300+void gr_log_mount(const char *from, const char *to, const int retval);
63301+void gr_log_textrel(struct vm_area_struct *vma);
63302+void gr_log_rwxmmap(struct file *file);
63303+void gr_log_rwxmprotect(struct file *file);
63304+
63305+int gr_handle_follow_link(const struct inode *parent,
63306+ const struct inode *inode,
63307+ const struct dentry *dentry,
63308+ const struct vfsmount *mnt);
63309+int gr_handle_fifo(const struct dentry *dentry,
63310+ const struct vfsmount *mnt,
63311+ const struct dentry *dir, const int flag,
63312+ const int acc_mode);
63313+int gr_handle_hardlink(const struct dentry *dentry,
63314+ const struct vfsmount *mnt,
63315+ struct inode *inode,
63316+ const int mode, const char *to);
63317+
63318+int gr_is_capable(const int cap);
63319+int gr_is_capable_nolog(const int cap);
63320+void gr_learn_resource(const struct task_struct *task, const int limit,
63321+ const unsigned long wanted, const int gt);
63322+void gr_copy_label(struct task_struct *tsk);
63323+void gr_handle_crash(struct task_struct *task, const int sig);
63324+int gr_handle_signal(const struct task_struct *p, const int sig);
63325+int gr_check_crash_uid(const uid_t uid);
63326+int gr_check_protected_task(const struct task_struct *task);
63327+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63328+int gr_acl_handle_mmap(const struct file *file,
63329+ const unsigned long prot);
63330+int gr_acl_handle_mprotect(const struct file *file,
63331+ const unsigned long prot);
63332+int gr_check_hidden_task(const struct task_struct *tsk);
63333+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63334+ const struct vfsmount *mnt);
63335+__u32 gr_acl_handle_utime(const struct dentry *dentry,
63336+ const struct vfsmount *mnt);
63337+__u32 gr_acl_handle_access(const struct dentry *dentry,
63338+ const struct vfsmount *mnt, const int fmode);
63339+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
63340+ const struct vfsmount *mnt, mode_t mode);
63341+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63342+ const struct vfsmount *mnt, mode_t mode);
63343+__u32 gr_acl_handle_chown(const struct dentry *dentry,
63344+ const struct vfsmount *mnt);
63345+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63346+ const struct vfsmount *mnt);
63347+int gr_handle_ptrace(struct task_struct *task, const long request);
63348+int gr_handle_proc_ptrace(struct task_struct *task);
63349+__u32 gr_acl_handle_execve(const struct dentry *dentry,
63350+ const struct vfsmount *mnt);
63351+int gr_check_crash_exec(const struct file *filp);
63352+int gr_acl_is_enabled(void);
63353+void gr_set_kernel_label(struct task_struct *task);
63354+void gr_set_role_label(struct task_struct *task, const uid_t uid,
63355+ const gid_t gid);
63356+int gr_set_proc_label(const struct dentry *dentry,
63357+ const struct vfsmount *mnt,
63358+ const int unsafe_share);
63359+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63360+ const struct vfsmount *mnt);
63361+__u32 gr_acl_handle_open(const struct dentry *dentry,
63362+ const struct vfsmount *mnt, const int fmode);
63363+__u32 gr_acl_handle_creat(const struct dentry *dentry,
63364+ const struct dentry *p_dentry,
63365+ const struct vfsmount *p_mnt, const int fmode,
63366+ const int imode);
63367+void gr_handle_create(const struct dentry *dentry,
63368+ const struct vfsmount *mnt);
63369+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63370+ const struct dentry *parent_dentry,
63371+ const struct vfsmount *parent_mnt,
63372+ const int mode);
63373+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63374+ const struct dentry *parent_dentry,
63375+ const struct vfsmount *parent_mnt);
63376+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63377+ const struct vfsmount *mnt);
63378+void gr_handle_delete(const ino_t ino, const dev_t dev);
63379+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63380+ const struct vfsmount *mnt);
63381+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63382+ const struct dentry *parent_dentry,
63383+ const struct vfsmount *parent_mnt,
63384+ const char *from);
63385+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63386+ const struct dentry *parent_dentry,
63387+ const struct vfsmount *parent_mnt,
63388+ const struct dentry *old_dentry,
63389+ const struct vfsmount *old_mnt, const char *to);
63390+int gr_acl_handle_rename(struct dentry *new_dentry,
63391+ struct dentry *parent_dentry,
63392+ const struct vfsmount *parent_mnt,
63393+ struct dentry *old_dentry,
63394+ struct inode *old_parent_inode,
63395+ struct vfsmount *old_mnt, const char *newname);
63396+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63397+ struct dentry *old_dentry,
63398+ struct dentry *new_dentry,
63399+ struct vfsmount *mnt, const __u8 replace);
63400+__u32 gr_check_link(const struct dentry *new_dentry,
63401+ const struct dentry *parent_dentry,
63402+ const struct vfsmount *parent_mnt,
63403+ const struct dentry *old_dentry,
63404+ const struct vfsmount *old_mnt);
63405+int gr_acl_handle_filldir(const struct file *file, const char *name,
63406+ const unsigned int namelen, const ino_t ino);
63407+
63408+__u32 gr_acl_handle_unix(const struct dentry *dentry,
63409+ const struct vfsmount *mnt);
63410+void gr_acl_handle_exit(void);
63411+void gr_acl_handle_psacct(struct task_struct *task, const long code);
63412+int gr_acl_handle_procpidmem(const struct task_struct *task);
63413+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63414+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63415+void gr_audit_ptrace(struct task_struct *task);
63416+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63417+
63418+#ifdef CONFIG_GRKERNSEC
63419+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63420+void gr_handle_vm86(void);
63421+void gr_handle_mem_readwrite(u64 from, u64 to);
63422+
63423+extern int grsec_enable_dmesg;
63424+extern int grsec_disable_privio;
63425+#endif
63426+
63427+#endif
63428diff -urNp linux-2.6.39.1/include/linux/grsock.h linux-2.6.39.1/include/linux/grsock.h
63429--- linux-2.6.39.1/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
63430+++ linux-2.6.39.1/include/linux/grsock.h 2011-05-22 19:41:42.000000000 -0400
63431@@ -0,0 +1,19 @@
63432+#ifndef __GRSOCK_H
63433+#define __GRSOCK_H
63434+
63435+extern void gr_attach_curr_ip(const struct sock *sk);
63436+extern int gr_handle_sock_all(const int family, const int type,
63437+ const int protocol);
63438+extern int gr_handle_sock_server(const struct sockaddr *sck);
63439+extern int gr_handle_sock_server_other(const struct sock *sck);
63440+extern int gr_handle_sock_client(const struct sockaddr *sck);
63441+extern int gr_search_connect(struct socket * sock,
63442+ struct sockaddr_in * addr);
63443+extern int gr_search_bind(struct socket * sock,
63444+ struct sockaddr_in * addr);
63445+extern int gr_search_listen(struct socket * sock);
63446+extern int gr_search_accept(struct socket * sock);
63447+extern int gr_search_socket(const int domain, const int type,
63448+ const int protocol);
63449+
63450+#endif
63451diff -urNp linux-2.6.39.1/include/linux/highmem.h linux-2.6.39.1/include/linux/highmem.h
63452--- linux-2.6.39.1/include/linux/highmem.h 2011-05-19 00:06:34.000000000 -0400
63453+++ linux-2.6.39.1/include/linux/highmem.h 2011-05-22 19:36:33.000000000 -0400
63454@@ -185,6 +185,18 @@ static inline void clear_highpage(struct
63455 kunmap_atomic(kaddr, KM_USER0);
63456 }
63457
63458+static inline void sanitize_highpage(struct page *page)
63459+{
63460+ void *kaddr;
63461+ unsigned long flags;
63462+
63463+ local_irq_save(flags);
63464+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
63465+ clear_page(kaddr);
63466+ kunmap_atomic(kaddr, KM_CLEARPAGE);
63467+ local_irq_restore(flags);
63468+}
63469+
63470 static inline void zero_user_segments(struct page *page,
63471 unsigned start1, unsigned end1,
63472 unsigned start2, unsigned end2)
63473diff -urNp linux-2.6.39.1/include/linux/i2o.h linux-2.6.39.1/include/linux/i2o.h
63474--- linux-2.6.39.1/include/linux/i2o.h 2011-05-19 00:06:34.000000000 -0400
63475+++ linux-2.6.39.1/include/linux/i2o.h 2011-05-22 19:36:33.000000000 -0400
63476@@ -564,7 +564,7 @@ struct i2o_controller {
63477 struct i2o_device *exec; /* Executive */
63478 #if BITS_PER_LONG == 64
63479 spinlock_t context_list_lock; /* lock for context_list */
63480- atomic_t context_list_counter; /* needed for unique contexts */
63481+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63482 struct list_head context_list; /* list of context id's
63483 and pointers */
63484 #endif
63485diff -urNp linux-2.6.39.1/include/linux/if_phonet.h linux-2.6.39.1/include/linux/if_phonet.h
63486--- linux-2.6.39.1/include/linux/if_phonet.h 2011-05-19 00:06:34.000000000 -0400
63487+++ linux-2.6.39.1/include/linux/if_phonet.h 2011-05-22 19:36:33.000000000 -0400
63488@@ -13,7 +13,7 @@
63489 #define PHONET_DEV_MTU PHONET_MAX_MTU
63490
63491 #ifdef __KERNEL__
63492-extern struct header_ops phonet_header_ops;
63493+extern const struct header_ops phonet_header_ops;
63494 #endif
63495
63496 #endif
63497diff -urNp linux-2.6.39.1/include/linux/init.h linux-2.6.39.1/include/linux/init.h
63498--- linux-2.6.39.1/include/linux/init.h 2011-05-19 00:06:34.000000000 -0400
63499+++ linux-2.6.39.1/include/linux/init.h 2011-05-22 19:36:33.000000000 -0400
63500@@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
63501
63502 /* Each module must use one module_init(). */
63503 #define module_init(initfn) \
63504- static inline initcall_t __inittest(void) \
63505+ static inline __used initcall_t __inittest(void) \
63506 { return initfn; } \
63507 int init_module(void) __attribute__((alias(#initfn)));
63508
63509 /* This is only required if you want to be unloadable. */
63510 #define module_exit(exitfn) \
63511- static inline exitcall_t __exittest(void) \
63512+ static inline __used exitcall_t __exittest(void) \
63513 { return exitfn; } \
63514 void cleanup_module(void) __attribute__((alias(#exitfn)));
63515
63516diff -urNp linux-2.6.39.1/include/linux/init_task.h linux-2.6.39.1/include/linux/init_task.h
63517--- linux-2.6.39.1/include/linux/init_task.h 2011-05-19 00:06:34.000000000 -0400
63518+++ linux-2.6.39.1/include/linux/init_task.h 2011-05-22 19:36:33.000000000 -0400
63519@@ -83,6 +83,12 @@ extern struct group_info init_groups;
63520 #define INIT_IDS
63521 #endif
63522
63523+#ifdef CONFIG_X86
63524+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63525+#else
63526+#define INIT_TASK_THREAD_INFO
63527+#endif
63528+
63529 /*
63530 * Because of the reduced scope of CAP_SETPCAP when filesystem
63531 * capabilities are in effect, it is safe to allow CAP_SETPCAP to
63532@@ -163,6 +169,7 @@ extern struct cred init_cred;
63533 RCU_INIT_POINTER(.cred, &init_cred), \
63534 .comm = "swapper", \
63535 .thread = INIT_THREAD, \
63536+ INIT_TASK_THREAD_INFO \
63537 .fs = &init_fs, \
63538 .files = &init_files, \
63539 .signal = &init_signals, \
63540diff -urNp linux-2.6.39.1/include/linux/interrupt.h linux-2.6.39.1/include/linux/interrupt.h
63541--- linux-2.6.39.1/include/linux/interrupt.h 2011-05-19 00:06:34.000000000 -0400
63542+++ linux-2.6.39.1/include/linux/interrupt.h 2011-05-22 19:36:33.000000000 -0400
63543@@ -422,7 +422,7 @@ enum
63544 /* map softirq index to softirq name. update 'softirq_to_name' in
63545 * kernel/softirq.c when adding a new softirq.
63546 */
63547-extern char *softirq_to_name[NR_SOFTIRQS];
63548+extern const char * const softirq_to_name[NR_SOFTIRQS];
63549
63550 /* softirq mask and active fields moved to irq_cpustat_t in
63551 * asm/hardirq.h to get better cache usage. KAO
63552@@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
63553
63554 struct softirq_action
63555 {
63556- void (*action)(struct softirq_action *);
63557+ void (*action)(void);
63558 };
63559
63560 asmlinkage void do_softirq(void);
63561 asmlinkage void __do_softirq(void);
63562-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63563+extern void open_softirq(int nr, void (*action)(void));
63564 extern void softirq_init(void);
63565 static inline void __raise_softirq_irqoff(unsigned int nr)
63566 {
63567diff -urNp linux-2.6.39.1/include/linux/iommu.h linux-2.6.39.1/include/linux/iommu.h
63568--- linux-2.6.39.1/include/linux/iommu.h 2011-05-19 00:06:34.000000000 -0400
63569+++ linux-2.6.39.1/include/linux/iommu.h 2011-05-22 19:36:33.000000000 -0400
63570@@ -49,7 +49,7 @@ struct iommu_ops {
63571
63572 #ifdef CONFIG_IOMMU_API
63573
63574-extern void register_iommu(struct iommu_ops *ops);
63575+extern void register_iommu(const struct iommu_ops *ops);
63576 extern bool iommu_found(void);
63577 extern struct iommu_domain *iommu_domain_alloc(void);
63578 extern void iommu_domain_free(struct iommu_domain *domain);
63579diff -urNp linux-2.6.39.1/include/linux/ipmi.h linux-2.6.39.1/include/linux/ipmi.h
63580--- linux-2.6.39.1/include/linux/ipmi.h 2011-05-19 00:06:34.000000000 -0400
63581+++ linux-2.6.39.1/include/linux/ipmi.h 2011-05-22 19:36:33.000000000 -0400
63582@@ -282,7 +282,7 @@ struct ipmi_user_hndl {
63583
63584 /* Create a new user of the IPMI layer on the given interface number. */
63585 int ipmi_create_user(unsigned int if_num,
63586- struct ipmi_user_hndl *handler,
63587+ const struct ipmi_user_hndl *handler,
63588 void *handler_data,
63589 ipmi_user_t *user);
63590
63591diff -urNp linux-2.6.39.1/include/linux/kallsyms.h linux-2.6.39.1/include/linux/kallsyms.h
63592--- linux-2.6.39.1/include/linux/kallsyms.h 2011-05-19 00:06:34.000000000 -0400
63593+++ linux-2.6.39.1/include/linux/kallsyms.h 2011-05-22 22:52:54.000000000 -0400
63594@@ -15,7 +15,8 @@
63595
63596 struct module;
63597
63598-#ifdef CONFIG_KALLSYMS
63599+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63600+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63601 /* Lookup the address for a symbol. Returns 0 if not found. */
63602 unsigned long kallsyms_lookup_name(const char *name);
63603
63604@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
63605 /* Stupid that this does nothing, but I didn't create this mess. */
63606 #define __print_symbol(fmt, addr)
63607 #endif /*CONFIG_KALLSYMS*/
63608+#else /* when included by kallsyms.c, vsnprintf.c, or
63609+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63610+extern void __print_symbol(const char *fmt, unsigned long address);
63611+extern int sprint_backtrace(char *buffer, unsigned long address);
63612+extern int sprint_symbol(char *buffer, unsigned long address);
63613+const char *kallsyms_lookup(unsigned long addr,
63614+ unsigned long *symbolsize,
63615+ unsigned long *offset,
63616+ char **modname, char *namebuf);
63617+#endif
63618
63619 /* This macro allows us to keep printk typechecking */
63620 static void __check_printsym_format(const char *fmt, ...)
63621diff -urNp linux-2.6.39.1/include/linux/kgdb.h linux-2.6.39.1/include/linux/kgdb.h
63622--- linux-2.6.39.1/include/linux/kgdb.h 2011-05-19 00:06:34.000000000 -0400
63623+++ linux-2.6.39.1/include/linux/kgdb.h 2011-05-22 19:36:33.000000000 -0400
63624@@ -53,7 +53,7 @@ extern int kgdb_connected;
63625 extern int kgdb_io_module_registered;
63626
63627 extern atomic_t kgdb_setting_breakpoint;
63628-extern atomic_t kgdb_cpu_doing_single_step;
63629+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63630
63631 extern struct task_struct *kgdb_usethread;
63632 extern struct task_struct *kgdb_contthread;
63633@@ -269,22 +269,22 @@ struct kgdb_arch {
63634 */
63635 struct kgdb_io {
63636 const char *name;
63637- int (*read_char) (void);
63638- void (*write_char) (u8);
63639- void (*flush) (void);
63640- int (*init) (void);
63641- void (*pre_exception) (void);
63642- void (*post_exception) (void);
63643+ int (* const read_char) (void);
63644+ void (* const write_char) (u8);
63645+ void (* const flush) (void);
63646+ int (* const init) (void);
63647+ void (* const pre_exception) (void);
63648+ void (* const post_exception) (void);
63649 int is_console;
63650 };
63651
63652-extern struct kgdb_arch arch_kgdb_ops;
63653+extern const struct kgdb_arch arch_kgdb_ops;
63654
63655 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
63656
63657-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
63658-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
63659-extern struct kgdb_io *dbg_io_ops;
63660+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
63661+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
63662+extern const struct kgdb_io *dbg_io_ops;
63663
63664 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
63665 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
63666diff -urNp linux-2.6.39.1/include/linux/kmod.h linux-2.6.39.1/include/linux/kmod.h
63667--- linux-2.6.39.1/include/linux/kmod.h 2011-05-19 00:06:34.000000000 -0400
63668+++ linux-2.6.39.1/include/linux/kmod.h 2011-05-22 19:41:42.000000000 -0400
63669@@ -33,6 +33,8 @@ extern char modprobe_path[]; /* for sysc
63670 * usually useless though. */
63671 extern int __request_module(bool wait, const char *name, ...) \
63672 __attribute__((format(printf, 2, 3)));
63673+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
63674+ __attribute__((format(printf, 3, 4)));
63675 #define request_module(mod...) __request_module(true, mod)
63676 #define request_module_nowait(mod...) __request_module(false, mod)
63677 #define try_then_request_module(x, mod...) \
63678diff -urNp linux-2.6.39.1/include/linux/kvm_host.h linux-2.6.39.1/include/linux/kvm_host.h
63679--- linux-2.6.39.1/include/linux/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
63680+++ linux-2.6.39.1/include/linux/kvm_host.h 2011-05-22 19:36:33.000000000 -0400
63681@@ -302,7 +302,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
63682 void vcpu_load(struct kvm_vcpu *vcpu);
63683 void vcpu_put(struct kvm_vcpu *vcpu);
63684
63685-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63686+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63687 struct module *module);
63688 void kvm_exit(void);
63689
63690@@ -442,7 +442,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
63691 struct kvm_guest_debug *dbg);
63692 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63693
63694-int kvm_arch_init(void *opaque);
63695+int kvm_arch_init(const void *opaque);
63696 void kvm_arch_exit(void);
63697
63698 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63699diff -urNp linux-2.6.39.1/include/linux/lapb.h linux-2.6.39.1/include/linux/lapb.h
63700--- linux-2.6.39.1/include/linux/lapb.h 2011-05-19 00:06:34.000000000 -0400
63701+++ linux-2.6.39.1/include/linux/lapb.h 2011-05-22 19:36:33.000000000 -0400
63702@@ -44,7 +44,7 @@ struct lapb_parms_struct {
63703 unsigned int mode;
63704 };
63705
63706-extern int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks);
63707+extern int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks);
63708 extern int lapb_unregister(struct net_device *dev);
63709 extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms);
63710 extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
63711diff -urNp linux-2.6.39.1/include/linux/lcd.h linux-2.6.39.1/include/linux/lcd.h
63712--- linux-2.6.39.1/include/linux/lcd.h 2011-05-19 00:06:34.000000000 -0400
63713+++ linux-2.6.39.1/include/linux/lcd.h 2011-05-22 19:36:33.000000000 -0400
63714@@ -60,7 +60,7 @@ struct lcd_device {
63715 points to something in the body of that driver, it is also invalid. */
63716 struct mutex ops_lock;
63717 /* If this is NULL, the backing module is unloaded */
63718- struct lcd_ops *ops;
63719+ const struct lcd_ops *ops;
63720 /* Serialise access to set_power method */
63721 struct mutex update_lock;
63722 /* The framebuffer notifier block */
63723@@ -101,7 +101,7 @@ static inline void lcd_set_power(struct
63724 }
63725
63726 extern struct lcd_device *lcd_device_register(const char *name,
63727- struct device *parent, void *devdata, struct lcd_ops *ops);
63728+ struct device *parent, void *devdata, const struct lcd_ops *ops);
63729 extern void lcd_device_unregister(struct lcd_device *ld);
63730
63731 #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
63732diff -urNp linux-2.6.39.1/include/linux/libata.h linux-2.6.39.1/include/linux/libata.h
63733--- linux-2.6.39.1/include/linux/libata.h 2011-05-19 00:06:34.000000000 -0400
63734+++ linux-2.6.39.1/include/linux/libata.h 2011-05-22 19:36:33.000000000 -0400
63735@@ -524,11 +524,11 @@ struct ata_ioports {
63736
63737 struct ata_host {
63738 spinlock_t lock;
63739- struct device *dev;
63740+ struct device *dev;
63741 void __iomem * const *iomap;
63742 unsigned int n_ports;
63743 void *private_data;
63744- struct ata_port_operations *ops;
63745+ const struct ata_port_operations *ops;
63746 unsigned long flags;
63747
63748 struct mutex eh_mutex;
63749@@ -719,7 +719,7 @@ struct ata_link {
63750
63751 struct ata_port {
63752 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
63753- struct ata_port_operations *ops;
63754+ const struct ata_port_operations *ops;
63755 spinlock_t *lock;
63756 /* Flags owned by the EH context. Only EH should touch these once the
63757 port is active */
63758@@ -907,7 +907,7 @@ struct ata_port_info {
63759 unsigned long pio_mask;
63760 unsigned long mwdma_mask;
63761 unsigned long udma_mask;
63762- struct ata_port_operations *port_ops;
63763+ const struct ata_port_operations *port_ops;
63764 void *private_data;
63765 };
63766
63767@@ -931,7 +931,7 @@ extern const unsigned long sata_deb_timi
63768 extern const unsigned long sata_deb_timing_hotplug[];
63769 extern const unsigned long sata_deb_timing_long[];
63770
63771-extern struct ata_port_operations ata_dummy_port_ops;
63772+extern const struct ata_port_operations ata_dummy_port_ops;
63773 extern const struct ata_port_info ata_dummy_port_info;
63774
63775 static inline const unsigned long *
63776@@ -977,7 +977,7 @@ extern int ata_host_activate(struct ata_
63777 struct scsi_host_template *sht);
63778 extern void ata_host_detach(struct ata_host *host);
63779 extern void ata_host_init(struct ata_host *, struct device *,
63780- unsigned long, struct ata_port_operations *);
63781+ unsigned long, const struct ata_port_operations *);
63782 extern int ata_scsi_detect(struct scsi_host_template *sht);
63783 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
63784 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
63785diff -urNp linux-2.6.39.1/include/linux/lockd/bind.h linux-2.6.39.1/include/linux/lockd/bind.h
63786--- linux-2.6.39.1/include/linux/lockd/bind.h 2011-05-19 00:06:34.000000000 -0400
63787+++ linux-2.6.39.1/include/linux/lockd/bind.h 2011-05-22 19:36:33.000000000 -0400
63788@@ -23,13 +23,13 @@ struct svc_rqst;
63789 * This is the set of functions for lockd->nfsd communication
63790 */
63791 struct nlmsvc_binding {
63792- __be32 (*fopen)(struct svc_rqst *,
63793+ __be32 (* const fopen)(struct svc_rqst *,
63794 struct nfs_fh *,
63795 struct file **);
63796- void (*fclose)(struct file *);
63797+ void (* const fclose)(struct file *);
63798 };
63799
63800-extern struct nlmsvc_binding * nlmsvc_ops;
63801+extern const struct nlmsvc_binding * nlmsvc_ops;
63802
63803 /*
63804 * Similar to nfs_client_initdata, but without the NFS-specific
63805diff -urNp linux-2.6.39.1/include/linux/mfd/abx500.h linux-2.6.39.1/include/linux/mfd/abx500.h
63806--- linux-2.6.39.1/include/linux/mfd/abx500.h 2011-05-19 00:06:34.000000000 -0400
63807+++ linux-2.6.39.1/include/linux/mfd/abx500.h 2011-05-22 19:36:33.000000000 -0400
63808@@ -227,6 +227,6 @@ struct abx500_ops {
63809 int (*startup_irq_enabled) (struct device *, unsigned int);
63810 };
63811
63812-int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63813+int abx500_register_ops(struct device *core_dev, const struct abx500_ops *ops);
63814 void abx500_remove_ops(struct device *dev);
63815 #endif
63816diff -urNp linux-2.6.39.1/include/linux/mm.h linux-2.6.39.1/include/linux/mm.h
63817--- linux-2.6.39.1/include/linux/mm.h 2011-05-19 00:06:34.000000000 -0400
63818+++ linux-2.6.39.1/include/linux/mm.h 2011-05-22 19:36:33.000000000 -0400
63819@@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
63820
63821 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63822 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63823+
63824+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63825+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63826+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63827+#else
63828 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63829+#endif
63830+
63831 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63832 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63833
63834@@ -1010,34 +1017,6 @@ int set_page_dirty(struct page *page);
63835 int set_page_dirty_lock(struct page *page);
63836 int clear_page_dirty_for_io(struct page *page);
63837
63838-/* Is the vma a continuation of the stack vma above it? */
63839-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63840-{
63841- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63842-}
63843-
63844-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63845- unsigned long addr)
63846-{
63847- return (vma->vm_flags & VM_GROWSDOWN) &&
63848- (vma->vm_start == addr) &&
63849- !vma_growsdown(vma->vm_prev, addr);
63850-}
63851-
63852-/* Is the vma a continuation of the stack vma below it? */
63853-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63854-{
63855- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63856-}
63857-
63858-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63859- unsigned long addr)
63860-{
63861- return (vma->vm_flags & VM_GROWSUP) &&
63862- (vma->vm_end == addr) &&
63863- !vma_growsup(vma->vm_next, addr);
63864-}
63865-
63866 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63867 unsigned long old_addr, struct vm_area_struct *new_vma,
63868 unsigned long new_addr, unsigned long len);
63869@@ -1189,6 +1168,15 @@ struct shrinker {
63870 extern void register_shrinker(struct shrinker *);
63871 extern void unregister_shrinker(struct shrinker *);
63872
63873+#ifdef CONFIG_MMU
63874+pgprot_t vm_get_page_prot(unsigned long vm_flags);
63875+#else
63876+static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63877+{
63878+ return __pgprot(0);
63879+}
63880+#endif
63881+
63882 int vma_wants_writenotify(struct vm_area_struct *vma);
63883
63884 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63885@@ -1476,6 +1464,7 @@ out:
63886 }
63887
63888 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63889+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63890
63891 extern unsigned long do_brk(unsigned long, unsigned long);
63892
63893@@ -1532,6 +1521,10 @@ extern struct vm_area_struct * find_vma(
63894 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63895 struct vm_area_struct **pprev);
63896
63897+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63898+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63899+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63900+
63901 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63902 NULL if none. Assume start_addr < end_addr. */
63903 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63904@@ -1548,15 +1541,6 @@ static inline unsigned long vma_pages(st
63905 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63906 }
63907
63908-#ifdef CONFIG_MMU
63909-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63910-#else
63911-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63912-{
63913- return __pgprot(0);
63914-}
63915-#endif
63916-
63917 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63918 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63919 unsigned long pfn, unsigned long size, pgprot_t);
63920@@ -1668,7 +1652,7 @@ extern int unpoison_memory(unsigned long
63921 extern int sysctl_memory_failure_early_kill;
63922 extern int sysctl_memory_failure_recovery;
63923 extern void shake_page(struct page *p, int access);
63924-extern atomic_long_t mce_bad_pages;
63925+extern atomic_long_unchecked_t mce_bad_pages;
63926 extern int soft_offline_page(struct page *page, int flags);
63927
63928 extern void dump_page(struct page *page);
63929@@ -1682,5 +1666,11 @@ extern void copy_user_huge_page(struct p
63930 unsigned int pages_per_huge_page);
63931 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
63932
63933+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63934+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63935+#else
63936+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63937+#endif
63938+
63939 #endif /* __KERNEL__ */
63940 #endif /* _LINUX_MM_H */
63941diff -urNp linux-2.6.39.1/include/linux/mm_types.h linux-2.6.39.1/include/linux/mm_types.h
63942--- linux-2.6.39.1/include/linux/mm_types.h 2011-05-19 00:06:34.000000000 -0400
63943+++ linux-2.6.39.1/include/linux/mm_types.h 2011-05-22 19:36:33.000000000 -0400
63944@@ -183,6 +183,8 @@ struct vm_area_struct {
63945 #ifdef CONFIG_NUMA
63946 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63947 #endif
63948+
63949+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63950 };
63951
63952 struct core_thread {
63953@@ -317,6 +319,24 @@ struct mm_struct {
63954 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63955 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
63956 #endif
63957+
63958+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63959+ unsigned long pax_flags;
63960+#endif
63961+
63962+#ifdef CONFIG_PAX_DLRESOLVE
63963+ unsigned long call_dl_resolve;
63964+#endif
63965+
63966+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63967+ unsigned long call_syscall;
63968+#endif
63969+
63970+#ifdef CONFIG_PAX_ASLR
63971+ unsigned long delta_mmap; /* randomized offset */
63972+ unsigned long delta_stack; /* randomized offset */
63973+#endif
63974+
63975 };
63976
63977 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
63978diff -urNp linux-2.6.39.1/include/linux/mmu_notifier.h linux-2.6.39.1/include/linux/mmu_notifier.h
63979--- linux-2.6.39.1/include/linux/mmu_notifier.h 2011-05-19 00:06:34.000000000 -0400
63980+++ linux-2.6.39.1/include/linux/mmu_notifier.h 2011-05-22 19:36:33.000000000 -0400
63981@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
63982 */
63983 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63984 ({ \
63985- pte_t __pte; \
63986+ pte_t ___pte; \
63987 struct vm_area_struct *___vma = __vma; \
63988 unsigned long ___address = __address; \
63989- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63990+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63991 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63992- __pte; \
63993+ ___pte; \
63994 })
63995
63996 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63997diff -urNp linux-2.6.39.1/include/linux/mmzone.h linux-2.6.39.1/include/linux/mmzone.h
63998--- linux-2.6.39.1/include/linux/mmzone.h 2011-05-19 00:06:34.000000000 -0400
63999+++ linux-2.6.39.1/include/linux/mmzone.h 2011-05-22 19:36:33.000000000 -0400
64000@@ -355,7 +355,7 @@ struct zone {
64001 unsigned long flags; /* zone flags, see below */
64002
64003 /* Zone statistics */
64004- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64005+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64006
64007 /*
64008 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
64009diff -urNp linux-2.6.39.1/include/linux/mod_devicetable.h linux-2.6.39.1/include/linux/mod_devicetable.h
64010--- linux-2.6.39.1/include/linux/mod_devicetable.h 2011-05-19 00:06:34.000000000 -0400
64011+++ linux-2.6.39.1/include/linux/mod_devicetable.h 2011-05-22 19:36:33.000000000 -0400
64012@@ -12,7 +12,7 @@
64013 typedef unsigned long kernel_ulong_t;
64014 #endif
64015
64016-#define PCI_ANY_ID (~0)
64017+#define PCI_ANY_ID ((__u16)~0)
64018
64019 struct pci_device_id {
64020 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64021@@ -131,7 +131,7 @@ struct usb_device_id {
64022 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
64023 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64024
64025-#define HID_ANY_ID (~0)
64026+#define HID_ANY_ID (~0U)
64027
64028 struct hid_device_id {
64029 __u16 bus;
64030diff -urNp linux-2.6.39.1/include/linux/module.h linux-2.6.39.1/include/linux/module.h
64031--- linux-2.6.39.1/include/linux/module.h 2011-05-19 00:06:34.000000000 -0400
64032+++ linux-2.6.39.1/include/linux/module.h 2011-05-22 19:36:33.000000000 -0400
64033@@ -324,19 +324,16 @@ struct module
64034 int (*init)(void);
64035
64036 /* If this is non-NULL, vfree after init() returns */
64037- void *module_init;
64038+ void *module_init_rx, *module_init_rw;
64039
64040 /* Here is the actual code + data, vfree'd on unload. */
64041- void *module_core;
64042+ void *module_core_rx, *module_core_rw;
64043
64044 /* Here are the sizes of the init and core sections */
64045- unsigned int init_size, core_size;
64046+ unsigned int init_size_rw, core_size_rw;
64047
64048 /* The size of the executable code in each section. */
64049- unsigned int init_text_size, core_text_size;
64050-
64051- /* Size of RO sections of the module (text+rodata) */
64052- unsigned int init_ro_size, core_ro_size;
64053+ unsigned int init_size_rx, core_size_rx;
64054
64055 /* Arch-specific module values */
64056 struct mod_arch_specific arch;
64057@@ -441,16 +438,46 @@ bool is_module_address(unsigned long add
64058 bool is_module_percpu_address(unsigned long addr);
64059 bool is_module_text_address(unsigned long addr);
64060
64061+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64062+{
64063+
64064+#ifdef CONFIG_PAX_KERNEXEC
64065+ if (ktla_ktva(addr) >= (unsigned long)start &&
64066+ ktla_ktva(addr) < (unsigned long)start + size)
64067+ return 1;
64068+#endif
64069+
64070+ return ((void *)addr >= start && (void *)addr < start + size);
64071+}
64072+
64073+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64074+{
64075+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64076+}
64077+
64078+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64079+{
64080+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64081+}
64082+
64083+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64084+{
64085+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64086+}
64087+
64088+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64089+{
64090+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64091+}
64092+
64093 static inline int within_module_core(unsigned long addr, struct module *mod)
64094 {
64095- return (unsigned long)mod->module_core <= addr &&
64096- addr < (unsigned long)mod->module_core + mod->core_size;
64097+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64098 }
64099
64100 static inline int within_module_init(unsigned long addr, struct module *mod)
64101 {
64102- return (unsigned long)mod->module_init <= addr &&
64103- addr < (unsigned long)mod->module_init + mod->init_size;
64104+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64105 }
64106
64107 /* Search for module by name: must hold module_mutex. */
64108diff -urNp linux-2.6.39.1/include/linux/moduleloader.h linux-2.6.39.1/include/linux/moduleloader.h
64109--- linux-2.6.39.1/include/linux/moduleloader.h 2011-05-19 00:06:34.000000000 -0400
64110+++ linux-2.6.39.1/include/linux/moduleloader.h 2011-05-22 19:36:33.000000000 -0400
64111@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
64112 sections. Returns NULL on failure. */
64113 void *module_alloc(unsigned long size);
64114
64115+#ifdef CONFIG_PAX_KERNEXEC
64116+void *module_alloc_exec(unsigned long size);
64117+#else
64118+#define module_alloc_exec(x) module_alloc(x)
64119+#endif
64120+
64121 /* Free memory returned from module_alloc. */
64122 void module_free(struct module *mod, void *module_region);
64123
64124+#ifdef CONFIG_PAX_KERNEXEC
64125+void module_free_exec(struct module *mod, void *module_region);
64126+#else
64127+#define module_free_exec(x, y) module_free((x), (y))
64128+#endif
64129+
64130 /* Apply the given relocation to the (simplified) ELF. Return -error
64131 or 0. */
64132 int apply_relocate(Elf_Shdr *sechdrs,
64133diff -urNp linux-2.6.39.1/include/linux/moduleparam.h linux-2.6.39.1/include/linux/moduleparam.h
64134--- linux-2.6.39.1/include/linux/moduleparam.h 2011-05-19 00:06:34.000000000 -0400
64135+++ linux-2.6.39.1/include/linux/moduleparam.h 2011-05-22 19:36:33.000000000 -0400
64136@@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
64137 * @len is usually just sizeof(string).
64138 */
64139 #define module_param_string(name, string, len, perm) \
64140- static const struct kparam_string __param_string_##name \
64141+ static const struct kparam_string __param_string_##name __used \
64142 = { len, string }; \
64143 __module_param_call(MODULE_PARAM_PREFIX, name, \
64144 &param_ops_string, \
64145@@ -285,48 +285,48 @@ static inline void destroy_params(const
64146 #define __param_check(name, p, type) \
64147 static inline type *__check_##name(void) { return(p); }
64148
64149-extern struct kernel_param_ops param_ops_byte;
64150+extern const struct kernel_param_ops param_ops_byte;
64151 extern int param_set_byte(const char *val, const struct kernel_param *kp);
64152 extern int param_get_byte(char *buffer, const struct kernel_param *kp);
64153 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
64154
64155-extern struct kernel_param_ops param_ops_short;
64156+extern const struct kernel_param_ops param_ops_short;
64157 extern int param_set_short(const char *val, const struct kernel_param *kp);
64158 extern int param_get_short(char *buffer, const struct kernel_param *kp);
64159 #define param_check_short(name, p) __param_check(name, p, short)
64160
64161-extern struct kernel_param_ops param_ops_ushort;
64162+extern const struct kernel_param_ops param_ops_ushort;
64163 extern int param_set_ushort(const char *val, const struct kernel_param *kp);
64164 extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
64165 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
64166
64167-extern struct kernel_param_ops param_ops_int;
64168+extern const struct kernel_param_ops param_ops_int;
64169 extern int param_set_int(const char *val, const struct kernel_param *kp);
64170 extern int param_get_int(char *buffer, const struct kernel_param *kp);
64171 #define param_check_int(name, p) __param_check(name, p, int)
64172
64173-extern struct kernel_param_ops param_ops_uint;
64174+extern const struct kernel_param_ops param_ops_uint;
64175 extern int param_set_uint(const char *val, const struct kernel_param *kp);
64176 extern int param_get_uint(char *buffer, const struct kernel_param *kp);
64177 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
64178
64179-extern struct kernel_param_ops param_ops_long;
64180+extern const struct kernel_param_ops param_ops_long;
64181 extern int param_set_long(const char *val, const struct kernel_param *kp);
64182 extern int param_get_long(char *buffer, const struct kernel_param *kp);
64183 #define param_check_long(name, p) __param_check(name, p, long)
64184
64185-extern struct kernel_param_ops param_ops_ulong;
64186+extern const struct kernel_param_ops param_ops_ulong;
64187 extern int param_set_ulong(const char *val, const struct kernel_param *kp);
64188 extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
64189 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
64190
64191-extern struct kernel_param_ops param_ops_charp;
64192+extern const struct kernel_param_ops param_ops_charp;
64193 extern int param_set_charp(const char *val, const struct kernel_param *kp);
64194 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
64195 #define param_check_charp(name, p) __param_check(name, p, char *)
64196
64197 /* For historical reasons "bool" parameters can be (unsigned) "int". */
64198-extern struct kernel_param_ops param_ops_bool;
64199+extern const struct kernel_param_ops param_ops_bool;
64200 extern int param_set_bool(const char *val, const struct kernel_param *kp);
64201 extern int param_get_bool(char *buffer, const struct kernel_param *kp);
64202 #define param_check_bool(name, p) \
64203@@ -337,7 +337,7 @@ extern int param_get_bool(char *buffer,
64204 !__same_type((p), int *)); \
64205 }
64206
64207-extern struct kernel_param_ops param_ops_invbool;
64208+extern const struct kernel_param_ops param_ops_invbool;
64209 extern int param_set_invbool(const char *val, const struct kernel_param *kp);
64210 extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
64211 #define param_check_invbool(name, p) __param_check(name, p, bool)
64212@@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
64213 * module_param_named() for why this might be necessary.
64214 */
64215 #define module_param_array_named(name, array, type, nump, perm) \
64216- static const struct kparam_array __param_arr_##name \
64217+ static const struct kparam_array __param_arr_##name __used \
64218 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
64219 sizeof(array[0]), array }; \
64220 __module_param_call(MODULE_PARAM_PREFIX, name, \
64221@@ -379,9 +379,9 @@ extern int param_get_invbool(char *buffe
64222 __same_type(array[0], bool), perm); \
64223 __MODULE_PARM_TYPE(name, "array of " #type)
64224
64225-extern struct kernel_param_ops param_array_ops;
64226+extern const struct kernel_param_ops param_array_ops;
64227
64228-extern struct kernel_param_ops param_ops_string;
64229+extern const struct kernel_param_ops param_ops_string;
64230 extern int param_set_copystring(const char *val, const struct kernel_param *);
64231 extern int param_get_string(char *buffer, const struct kernel_param *kp);
64232
64233diff -urNp linux-2.6.39.1/include/linux/mutex.h linux-2.6.39.1/include/linux/mutex.h
64234--- linux-2.6.39.1/include/linux/mutex.h 2011-05-19 00:06:34.000000000 -0400
64235+++ linux-2.6.39.1/include/linux/mutex.h 2011-05-22 19:36:33.000000000 -0400
64236@@ -51,7 +51,7 @@ struct mutex {
64237 spinlock_t wait_lock;
64238 struct list_head wait_list;
64239 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
64240- struct thread_info *owner;
64241+ struct task_struct *owner;
64242 #endif
64243 #ifdef CONFIG_DEBUG_MUTEXES
64244 const char *name;
64245diff -urNp linux-2.6.39.1/include/linux/namei.h linux-2.6.39.1/include/linux/namei.h
64246--- linux-2.6.39.1/include/linux/namei.h 2011-05-19 00:06:34.000000000 -0400
64247+++ linux-2.6.39.1/include/linux/namei.h 2011-05-22 19:36:33.000000000 -0400
64248@@ -24,7 +24,7 @@ struct nameidata {
64249 unsigned seq;
64250 int last_type;
64251 unsigned depth;
64252- char *saved_names[MAX_NESTED_LINKS + 1];
64253+ const char *saved_names[MAX_NESTED_LINKS + 1];
64254
64255 /* Intent data */
64256 union {
64257@@ -91,12 +91,12 @@ extern int follow_up(struct path *);
64258 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
64259 extern void unlock_rename(struct dentry *, struct dentry *);
64260
64261-static inline void nd_set_link(struct nameidata *nd, char *path)
64262+static inline void nd_set_link(struct nameidata *nd, const char *path)
64263 {
64264 nd->saved_names[nd->depth] = path;
64265 }
64266
64267-static inline char *nd_get_link(struct nameidata *nd)
64268+static inline const char *nd_get_link(const struct nameidata *nd)
64269 {
64270 return nd->saved_names[nd->depth];
64271 }
64272diff -urNp linux-2.6.39.1/include/linux/netfilter/xt_gradm.h linux-2.6.39.1/include/linux/netfilter/xt_gradm.h
64273--- linux-2.6.39.1/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
64274+++ linux-2.6.39.1/include/linux/netfilter/xt_gradm.h 2011-05-22 19:41:42.000000000 -0400
64275@@ -0,0 +1,9 @@
64276+#ifndef _LINUX_NETFILTER_XT_GRADM_H
64277+#define _LINUX_NETFILTER_XT_GRADM_H 1
64278+
64279+struct xt_gradm_mtinfo {
64280+ __u16 flags;
64281+ __u16 invflags;
64282+};
64283+
64284+#endif
64285diff -urNp linux-2.6.39.1/include/linux/oprofile.h linux-2.6.39.1/include/linux/oprofile.h
64286--- linux-2.6.39.1/include/linux/oprofile.h 2011-05-19 00:06:34.000000000 -0400
64287+++ linux-2.6.39.1/include/linux/oprofile.h 2011-05-22 19:36:33.000000000 -0400
64288@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
64289 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64290 char const * name, ulong * val);
64291
64292-/** Create a file for read-only access to an atomic_t. */
64293+/** Create a file for read-only access to an atomic_unchecked_t. */
64294 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64295- char const * name, atomic_t * val);
64296+ char const * name, atomic_unchecked_t * val);
64297
64298 /** create a directory */
64299 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64300diff -urNp linux-2.6.39.1/include/linux/padata.h linux-2.6.39.1/include/linux/padata.h
64301--- linux-2.6.39.1/include/linux/padata.h 2011-05-19 00:06:34.000000000 -0400
64302+++ linux-2.6.39.1/include/linux/padata.h 2011-05-22 19:36:33.000000000 -0400
64303@@ -129,7 +129,7 @@ struct parallel_data {
64304 struct padata_instance *pinst;
64305 struct padata_parallel_queue __percpu *pqueue;
64306 struct padata_serial_queue __percpu *squeue;
64307- atomic_t seq_nr;
64308+ atomic_unchecked_t seq_nr;
64309 atomic_t reorder_objects;
64310 atomic_t refcnt;
64311 unsigned int max_seq_nr;
64312diff -urNp linux-2.6.39.1/include/linux/pci.h linux-2.6.39.1/include/linux/pci.h
64313--- linux-2.6.39.1/include/linux/pci.h 2011-05-19 00:06:34.000000000 -0400
64314+++ linux-2.6.39.1/include/linux/pci.h 2011-05-22 19:36:33.000000000 -0400
64315@@ -411,7 +411,7 @@ struct pci_bus {
64316 struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
64317 struct list_head resources; /* address space routed to this bus */
64318
64319- struct pci_ops *ops; /* configuration access functions */
64320+ const struct pci_ops *ops; /* configuration access functions */
64321 void *sysdata; /* hook for sys-specific extension */
64322 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
64323
64324@@ -550,7 +550,7 @@ struct pci_driver {
64325 int (*resume_early) (struct pci_dev *dev);
64326 int (*resume) (struct pci_dev *dev); /* Device woken up */
64327 void (*shutdown) (struct pci_dev *dev);
64328- struct pci_error_handlers *err_handler;
64329+ const struct pci_error_handlers *err_handler;
64330 struct device_driver driver;
64331 struct pci_dynids dynids;
64332 };
64333@@ -639,7 +639,7 @@ void pcibios_scan_specific_bus(int busn)
64334 extern struct pci_bus *pci_find_bus(int domain, int busnr);
64335 void pci_bus_add_devices(const struct pci_bus *bus);
64336 struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
64337- struct pci_ops *ops, void *sysdata);
64338+ const struct pci_ops *ops, void *sysdata);
64339 static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,
64340 void *sysdata)
64341 {
64342@@ -650,7 +650,7 @@ static inline struct pci_bus * __devinit
64343 return root_bus;
64344 }
64345 struct pci_bus *pci_create_bus(struct device *parent, int bus,
64346- struct pci_ops *ops, void *sysdata);
64347+ const struct pci_ops *ops, void *sysdata);
64348 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
64349 int busnr);
64350 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
64351@@ -727,7 +727,7 @@ int pci_bus_write_config_word(struct pci
64352 int where, u16 val);
64353 int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
64354 int where, u32 val);
64355-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
64356+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops);
64357
64358 static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
64359 {
64360diff -urNp linux-2.6.39.1/include/linux/perf_event.h linux-2.6.39.1/include/linux/perf_event.h
64361--- linux-2.6.39.1/include/linux/perf_event.h 2011-05-19 00:06:34.000000000 -0400
64362+++ linux-2.6.39.1/include/linux/perf_event.h 2011-05-22 19:36:33.000000000 -0400
64363@@ -759,8 +759,8 @@ struct perf_event {
64364
64365 enum perf_event_active_state state;
64366 unsigned int attach_state;
64367- local64_t count;
64368- atomic64_t child_count;
64369+ local64_t count; /* PaX: fix it one day */
64370+ atomic64_unchecked_t child_count;
64371
64372 /*
64373 * These are the total time in nanoseconds that the event
64374@@ -811,8 +811,8 @@ struct perf_event {
64375 * These accumulate total time (in nanoseconds) that children
64376 * events have been enabled and running, respectively.
64377 */
64378- atomic64_t child_total_time_enabled;
64379- atomic64_t child_total_time_running;
64380+ atomic64_unchecked_t child_total_time_enabled;
64381+ atomic64_unchecked_t child_total_time_running;
64382
64383 /*
64384 * Protect attach/detach and child_list:
64385@@ -1090,9 +1090,9 @@ void perf_event_task_sched_out(struct ta
64386 }
64387
64388 extern void perf_event_mmap(struct vm_area_struct *vma);
64389-extern struct perf_guest_info_callbacks *perf_guest_cbs;
64390-extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64391-extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64392+extern const struct perf_guest_info_callbacks *perf_guest_cbs;
64393+extern int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64394+extern int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64395
64396 extern void perf_event_comm(struct task_struct *tsk);
64397 extern void perf_event_fork(struct task_struct *tsk);
64398diff -urNp linux-2.6.39.1/include/linux/pipe_fs_i.h linux-2.6.39.1/include/linux/pipe_fs_i.h
64399--- linux-2.6.39.1/include/linux/pipe_fs_i.h 2011-05-19 00:06:34.000000000 -0400
64400+++ linux-2.6.39.1/include/linux/pipe_fs_i.h 2011-05-22 19:36:33.000000000 -0400
64401@@ -46,9 +46,9 @@ struct pipe_buffer {
64402 struct pipe_inode_info {
64403 wait_queue_head_t wait;
64404 unsigned int nrbufs, curbuf, buffers;
64405- unsigned int readers;
64406- unsigned int writers;
64407- unsigned int waiting_writers;
64408+ atomic_t readers;
64409+ atomic_t writers;
64410+ atomic_t waiting_writers;
64411 unsigned int r_counter;
64412 unsigned int w_counter;
64413 struct page *tmp_page;
64414diff -urNp linux-2.6.39.1/include/linux/pm.h linux-2.6.39.1/include/linux/pm.h
64415--- linux-2.6.39.1/include/linux/pm.h 2011-05-19 00:06:34.000000000 -0400
64416+++ linux-2.6.39.1/include/linux/pm.h 2011-05-22 19:36:33.000000000 -0400
64417@@ -268,7 +268,7 @@ const struct dev_pm_ops name = { \
64418 * runtime PM, make the pm member point to generic_subsys_pm_ops.
64419 */
64420 #ifdef CONFIG_PM
64421-extern struct dev_pm_ops generic_subsys_pm_ops;
64422+extern const struct dev_pm_ops generic_subsys_pm_ops;
64423 #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
64424 #else
64425 #define GENERIC_SUBSYS_PM_OPS NULL
64426@@ -471,7 +471,7 @@ extern void update_pm_runtime_accounting
64427 * subsystem-level and driver-level callbacks.
64428 */
64429 struct dev_power_domain {
64430- struct dev_pm_ops ops;
64431+ const struct dev_pm_ops ops;
64432 };
64433
64434 /*
64435diff -urNp linux-2.6.39.1/include/linux/pm_runtime.h linux-2.6.39.1/include/linux/pm_runtime.h
64436--- linux-2.6.39.1/include/linux/pm_runtime.h 2011-05-19 00:06:34.000000000 -0400
64437+++ linux-2.6.39.1/include/linux/pm_runtime.h 2011-05-22 19:36:33.000000000 -0400
64438@@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
64439
64440 static inline void pm_runtime_mark_last_busy(struct device *dev)
64441 {
64442- ACCESS_ONCE(dev->power.last_busy) = jiffies;
64443+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64444 }
64445
64446 #else /* !CONFIG_PM_RUNTIME */
64447diff -urNp linux-2.6.39.1/include/linux/poison.h linux-2.6.39.1/include/linux/poison.h
64448--- linux-2.6.39.1/include/linux/poison.h 2011-05-19 00:06:34.000000000 -0400
64449+++ linux-2.6.39.1/include/linux/poison.h 2011-05-22 19:36:33.000000000 -0400
64450@@ -19,8 +19,8 @@
64451 * under normal circumstances, used to verify that nobody uses
64452 * non-initialized list entries.
64453 */
64454-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64455-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64456+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64457+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64458
64459 /********** include/linux/timer.h **********/
64460 /*
64461diff -urNp linux-2.6.39.1/include/linux/posix-timers.h linux-2.6.39.1/include/linux/posix-timers.h
64462--- linux-2.6.39.1/include/linux/posix-timers.h 2011-05-19 00:06:34.000000000 -0400
64463+++ linux-2.6.39.1/include/linux/posix-timers.h 2011-05-22 19:36:33.000000000 -0400
64464@@ -102,10 +102,10 @@ struct k_clock {
64465 struct itimerspec * cur_setting);
64466 };
64467
64468-extern struct k_clock clock_posix_cpu;
64469-extern struct k_clock clock_posix_dynamic;
64470+extern const struct k_clock clock_posix_cpu;
64471+extern const struct k_clock clock_posix_dynamic;
64472
64473-void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
64474+void posix_timers_register_clock(const clockid_t clock_id, const struct k_clock *new_clock);
64475
64476 /* function to call to trigger timer event */
64477 int posix_timer_event(struct k_itimer *timr, int si_private);
64478diff -urNp linux-2.6.39.1/include/linux/proc_fs.h linux-2.6.39.1/include/linux/proc_fs.h
64479--- linux-2.6.39.1/include/linux/proc_fs.h 2011-05-19 00:06:34.000000000 -0400
64480+++ linux-2.6.39.1/include/linux/proc_fs.h 2011-05-22 19:41:42.000000000 -0400
64481@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
64482 return proc_create_data(name, mode, parent, proc_fops, NULL);
64483 }
64484
64485+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
64486+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64487+{
64488+#ifdef CONFIG_GRKERNSEC_PROC_USER
64489+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64490+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64491+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64492+#else
64493+ return proc_create_data(name, mode, parent, proc_fops, NULL);
64494+#endif
64495+}
64496+
64497+
64498 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64499 mode_t mode, struct proc_dir_entry *base,
64500 read_proc_t *read_proc, void * data)
64501diff -urNp linux-2.6.39.1/include/linux/ptrace.h linux-2.6.39.1/include/linux/ptrace.h
64502--- linux-2.6.39.1/include/linux/ptrace.h 2011-05-19 00:06:34.000000000 -0400
64503+++ linux-2.6.39.1/include/linux/ptrace.h 2011-05-22 19:41:42.000000000 -0400
64504@@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
64505 extern void exit_ptrace(struct task_struct *tracer);
64506 #define PTRACE_MODE_READ 1
64507 #define PTRACE_MODE_ATTACH 2
64508-/* Returns 0 on success, -errno on denial. */
64509-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
64510 /* Returns true on success, false on denial. */
64511 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
64512+/* Returns true on success, false on denial. */
64513+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
64514
64515 static inline int ptrace_reparented(struct task_struct *child)
64516 {
64517diff -urNp linux-2.6.39.1/include/linux/random.h linux-2.6.39.1/include/linux/random.h
64518--- linux-2.6.39.1/include/linux/random.h 2011-05-19 00:06:34.000000000 -0400
64519+++ linux-2.6.39.1/include/linux/random.h 2011-05-22 19:36:33.000000000 -0400
64520@@ -80,12 +80,17 @@ void srandom32(u32 seed);
64521
64522 u32 prandom32(struct rnd_state *);
64523
64524+static inline unsigned long pax_get_random_long(void)
64525+{
64526+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64527+}
64528+
64529 /*
64530 * Handle minimum values for seeds
64531 */
64532 static inline u32 __seed(u32 x, u32 m)
64533 {
64534- return (x < m) ? x + m : x;
64535+ return (x <= m) ? x + m + 1 : x;
64536 }
64537
64538 /**
64539diff -urNp linux-2.6.39.1/include/linux/reboot.h linux-2.6.39.1/include/linux/reboot.h
64540--- linux-2.6.39.1/include/linux/reboot.h 2011-05-19 00:06:34.000000000 -0400
64541+++ linux-2.6.39.1/include/linux/reboot.h 2011-05-22 19:36:33.000000000 -0400
64542@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
64543 * Architecture-specific implementations of sys_reboot commands.
64544 */
64545
64546-extern void machine_restart(char *cmd);
64547-extern void machine_halt(void);
64548-extern void machine_power_off(void);
64549+extern void machine_restart(char *cmd) __noreturn;
64550+extern void machine_halt(void) __noreturn;
64551+extern void machine_power_off(void) __noreturn;
64552
64553 extern void machine_shutdown(void);
64554 struct pt_regs;
64555@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
64556 */
64557
64558 extern void kernel_restart_prepare(char *cmd);
64559-extern void kernel_restart(char *cmd);
64560-extern void kernel_halt(void);
64561-extern void kernel_power_off(void);
64562+extern void kernel_restart(char *cmd) __noreturn;
64563+extern void kernel_halt(void) __noreturn;
64564+extern void kernel_power_off(void) __noreturn;
64565
64566 extern int C_A_D; /* for sysctl */
64567 void ctrl_alt_del(void);
64568@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
64569 * Emergency restart, callable from an interrupt handler.
64570 */
64571
64572-extern void emergency_restart(void);
64573+extern void emergency_restart(void) __noreturn;
64574 #include <asm/emergency-restart.h>
64575
64576 #endif
64577diff -urNp linux-2.6.39.1/include/linux/reiserfs_fs.h linux-2.6.39.1/include/linux/reiserfs_fs.h
64578--- linux-2.6.39.1/include/linux/reiserfs_fs.h 2011-05-19 00:06:34.000000000 -0400
64579+++ linux-2.6.39.1/include/linux/reiserfs_fs.h 2011-05-22 19:36:33.000000000 -0400
64580@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
64581 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64582
64583 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64584-#define get_generation(s) atomic_read (&fs_generation(s))
64585+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64586 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64587 #define __fs_changed(gen,s) (gen != get_generation (s))
64588 #define fs_changed(gen,s) \
64589@@ -1618,24 +1618,24 @@ static inline struct super_block *sb_fro
64590 */
64591
64592 struct item_operations {
64593- int (*bytes_number) (struct item_head * ih, int block_size);
64594- void (*decrement_key) (struct cpu_key *);
64595- int (*is_left_mergeable) (struct reiserfs_key * ih,
64596+ int (* const bytes_number) (struct item_head * ih, int block_size);
64597+ void (* const decrement_key) (struct cpu_key *);
64598+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
64599 unsigned long bsize);
64600- void (*print_item) (struct item_head *, char *item);
64601- void (*check_item) (struct item_head *, char *item);
64602+ void (* const print_item) (struct item_head *, char *item);
64603+ void (* const check_item) (struct item_head *, char *item);
64604
64605- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64606+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64607 int is_affected, int insert_size);
64608- int (*check_left) (struct virtual_item * vi, int free,
64609+ int (* const check_left) (struct virtual_item * vi, int free,
64610 int start_skip, int end_skip);
64611- int (*check_right) (struct virtual_item * vi, int free);
64612- int (*part_size) (struct virtual_item * vi, int from, int to);
64613- int (*unit_num) (struct virtual_item * vi);
64614- void (*print_vi) (struct virtual_item * vi);
64615+ int (* const check_right) (struct virtual_item * vi, int free);
64616+ int (* const part_size) (struct virtual_item * vi, int from, int to);
64617+ int (* const unit_num) (struct virtual_item * vi);
64618+ void (* const print_vi) (struct virtual_item * vi);
64619 };
64620
64621-extern struct item_operations *item_ops[TYPE_ANY + 1];
64622+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
64623
64624 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
64625 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
64626diff -urNp linux-2.6.39.1/include/linux/reiserfs_fs_sb.h linux-2.6.39.1/include/linux/reiserfs_fs_sb.h
64627--- linux-2.6.39.1/include/linux/reiserfs_fs_sb.h 2011-05-19 00:06:34.000000000 -0400
64628+++ linux-2.6.39.1/include/linux/reiserfs_fs_sb.h 2011-05-22 19:36:33.000000000 -0400
64629@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
64630 /* Comment? -Hans */
64631 wait_queue_head_t s_wait;
64632 /* To be obsoleted soon by per buffer seals.. -Hans */
64633- atomic_t s_generation_counter; // increased by one every time the
64634+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64635 // tree gets re-balanced
64636 unsigned long s_properties; /* File system properties. Currently holds
64637 on-disk FS format */
64638diff -urNp linux-2.6.39.1/include/linux/rmap.h linux-2.6.39.1/include/linux/rmap.h
64639--- linux-2.6.39.1/include/linux/rmap.h 2011-05-19 00:06:34.000000000 -0400
64640+++ linux-2.6.39.1/include/linux/rmap.h 2011-05-22 19:36:33.000000000 -0400
64641@@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
64642 void anon_vma_init(void); /* create anon_vma_cachep */
64643 int anon_vma_prepare(struct vm_area_struct *);
64644 void unlink_anon_vmas(struct vm_area_struct *);
64645-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64646-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64647+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64648+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64649 void __anon_vma_link(struct vm_area_struct *);
64650
64651 static inline void anon_vma_merge(struct vm_area_struct *vma,
64652diff -urNp linux-2.6.39.1/include/linux/sched.h linux-2.6.39.1/include/linux/sched.h
64653--- linux-2.6.39.1/include/linux/sched.h 2011-05-19 00:06:34.000000000 -0400
64654+++ linux-2.6.39.1/include/linux/sched.h 2011-06-03 23:34:26.000000000 -0400
64655@@ -100,6 +100,7 @@ struct bio_list;
64656 struct fs_struct;
64657 struct perf_event_context;
64658 struct blk_plug;
64659+struct linux_binprm;
64660
64661 /*
64662 * List of flags we want to share for kernel threads,
64663@@ -360,7 +361,7 @@ extern signed long schedule_timeout_inte
64664 extern signed long schedule_timeout_killable(signed long timeout);
64665 extern signed long schedule_timeout_uninterruptible(signed long timeout);
64666 asmlinkage void schedule(void);
64667-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
64668+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
64669
64670 struct nsproxy;
64671 struct user_namespace;
64672@@ -381,10 +382,13 @@ struct user_namespace;
64673 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64674
64675 extern int sysctl_max_map_count;
64676+extern unsigned long sysctl_heap_stack_gap;
64677
64678 #include <linux/aio.h>
64679
64680 #ifdef CONFIG_MMU
64681+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64682+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64683 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64684 extern unsigned long
64685 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64686@@ -629,6 +633,17 @@ struct signal_struct {
64687 #ifdef CONFIG_TASKSTATS
64688 struct taskstats *stats;
64689 #endif
64690+
64691+#ifdef CONFIG_GRKERNSEC
64692+ u32 curr_ip;
64693+ u32 saved_ip;
64694+ u32 gr_saddr;
64695+ u32 gr_daddr;
64696+ u16 gr_sport;
64697+ u16 gr_dport;
64698+ u8 used_accept:1;
64699+#endif
64700+
64701 #ifdef CONFIG_AUDIT
64702 unsigned audit_tty;
64703 struct tty_audit_buf *tty_audit_buf;
64704@@ -701,6 +716,11 @@ struct user_struct {
64705 struct key *session_keyring; /* UID's default session keyring */
64706 #endif
64707
64708+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64709+ unsigned int banned;
64710+ unsigned long ban_expires;
64711+#endif
64712+
64713 /* Hash table maintenance information */
64714 struct hlist_node uidhash_node;
64715 uid_t uid;
64716@@ -1310,8 +1330,8 @@ struct task_struct {
64717 struct list_head thread_group;
64718
64719 struct completion *vfork_done; /* for vfork() */
64720- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64721- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64722+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64723+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64724
64725 cputime_t utime, stime, utimescaled, stimescaled;
64726 cputime_t gtime;
64727@@ -1327,13 +1347,6 @@ struct task_struct {
64728 struct task_cputime cputime_expires;
64729 struct list_head cpu_timers[3];
64730
64731-/* process credentials */
64732- const struct cred __rcu *real_cred; /* objective and real subjective task
64733- * credentials (COW) */
64734- const struct cred __rcu *cred; /* effective (overridable) subjective task
64735- * credentials (COW) */
64736- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64737-
64738 char comm[TASK_COMM_LEN]; /* executable name excluding path
64739 - access with [gs]et_task_comm (which lock
64740 it with task_lock())
64741@@ -1350,8 +1363,16 @@ struct task_struct {
64742 #endif
64743 /* CPU-specific state of this task */
64744 struct thread_struct thread;
64745+/* thread_info moved to task_struct */
64746+#ifdef CONFIG_X86
64747+ struct thread_info tinfo;
64748+#endif
64749 /* filesystem information */
64750 struct fs_struct *fs;
64751+
64752+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64753+ * credentials (COW) */
64754+
64755 /* open file information */
64756 struct files_struct *files;
64757 /* namespaces */
64758@@ -1398,6 +1419,11 @@ struct task_struct {
64759 struct rt_mutex_waiter *pi_blocked_on;
64760 #endif
64761
64762+/* process credentials */
64763+ const struct cred __rcu *real_cred; /* objective and real subjective task
64764+ * credentials (COW) */
64765+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64766+
64767 #ifdef CONFIG_DEBUG_MUTEXES
64768 /* mutex deadlock detection */
64769 struct mutex_waiter *blocked_on;
64770@@ -1508,6 +1534,21 @@ struct task_struct {
64771 unsigned long default_timer_slack_ns;
64772
64773 struct list_head *scm_work_list;
64774+
64775+#ifdef CONFIG_GRKERNSEC
64776+ /* grsecurity */
64777+ struct dentry *gr_chroot_dentry;
64778+ struct acl_subject_label *acl;
64779+ struct acl_role_label *role;
64780+ struct file *exec_file;
64781+ u16 acl_role_id;
64782+ /* is this the task that authenticated to the special role */
64783+ u8 acl_sp_role;
64784+ u8 is_writable;
64785+ u8 brute;
64786+ u8 gr_is_chrooted;
64787+#endif
64788+
64789 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64790 /* Index of current stored address in ret_stack */
64791 int curr_ret_stack;
64792@@ -1542,6 +1583,57 @@ struct task_struct {
64793 #endif
64794 };
64795
64796+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64797+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64798+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64799+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64800+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64801+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64802+
64803+#ifdef CONFIG_PAX_SOFTMODE
64804+extern unsigned int pax_softmode;
64805+#endif
64806+
64807+extern int pax_check_flags(unsigned long *);
64808+
64809+/* if tsk != current then task_lock must be held on it */
64810+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64811+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64812+{
64813+ if (likely(tsk->mm))
64814+ return tsk->mm->pax_flags;
64815+ else
64816+ return 0UL;
64817+}
64818+
64819+/* if tsk != current then task_lock must be held on it */
64820+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64821+{
64822+ if (likely(tsk->mm)) {
64823+ tsk->mm->pax_flags = flags;
64824+ return 0;
64825+ }
64826+ return -EINVAL;
64827+}
64828+#endif
64829+
64830+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64831+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64832+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64833+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64834+#endif
64835+
64836+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64837+void pax_report_insns(void *pc, void *sp);
64838+void pax_report_refcount_overflow(struct pt_regs *regs);
64839+void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
64840+
64841+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
64842+extern void pax_track_stack(void);
64843+#else
64844+static inline void pax_track_stack(void) {}
64845+#endif
64846+
64847 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64848 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64849
64850@@ -2009,7 +2101,9 @@ void yield(void);
64851 extern struct exec_domain default_exec_domain;
64852
64853 union thread_union {
64854+#ifndef CONFIG_X86
64855 struct thread_info thread_info;
64856+#endif
64857 unsigned long stack[THREAD_SIZE/sizeof(long)];
64858 };
64859
64860@@ -2179,7 +2273,7 @@ extern void __cleanup_sighand(struct sig
64861 extern void exit_itimers(struct signal_struct *);
64862 extern void flush_itimer_signals(void);
64863
64864-extern NORET_TYPE void do_group_exit(int);
64865+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
64866
64867 extern void daemonize(const char *, ...);
64868 extern int allow_signal(int);
64869@@ -2320,13 +2414,17 @@ static inline unsigned long *end_of_stac
64870
64871 #endif
64872
64873-static inline int object_is_on_stack(void *obj)
64874+static inline int object_starts_on_stack(void *obj)
64875 {
64876- void *stack = task_stack_page(current);
64877+ const void *stack = task_stack_page(current);
64878
64879 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64880 }
64881
64882+#ifdef CONFIG_PAX_USERCOPY
64883+extern int object_is_on_stack(const void *obj, unsigned long len);
64884+#endif
64885+
64886 extern void thread_info_cache_init(void);
64887
64888 #ifdef CONFIG_DEBUG_STACK_USAGE
64889diff -urNp linux-2.6.39.1/include/linux/screen_info.h linux-2.6.39.1/include/linux/screen_info.h
64890--- linux-2.6.39.1/include/linux/screen_info.h 2011-05-19 00:06:34.000000000 -0400
64891+++ linux-2.6.39.1/include/linux/screen_info.h 2011-05-22 19:36:33.000000000 -0400
64892@@ -43,7 +43,8 @@ struct screen_info {
64893 __u16 pages; /* 0x32 */
64894 __u16 vesa_attributes; /* 0x34 */
64895 __u32 capabilities; /* 0x36 */
64896- __u8 _reserved[6]; /* 0x3a */
64897+ __u16 vesapm_size; /* 0x3a */
64898+ __u8 _reserved[4]; /* 0x3c */
64899 } __attribute__((packed));
64900
64901 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64902diff -urNp linux-2.6.39.1/include/linux/security.h linux-2.6.39.1/include/linux/security.h
64903--- linux-2.6.39.1/include/linux/security.h 2011-05-19 00:06:34.000000000 -0400
64904+++ linux-2.6.39.1/include/linux/security.h 2011-05-22 19:41:42.000000000 -0400
64905@@ -36,6 +36,7 @@
64906 #include <linux/key.h>
64907 #include <linux/xfrm.h>
64908 #include <linux/slab.h>
64909+#include <linux/grsecurity.h>
64910 #include <net/flow.h>
64911
64912 /* Maximum number of letters for an LSM name string */
64913diff -urNp linux-2.6.39.1/include/linux/shm.h linux-2.6.39.1/include/linux/shm.h
64914--- linux-2.6.39.1/include/linux/shm.h 2011-05-19 00:06:34.000000000 -0400
64915+++ linux-2.6.39.1/include/linux/shm.h 2011-05-22 19:41:42.000000000 -0400
64916@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
64917 pid_t shm_cprid;
64918 pid_t shm_lprid;
64919 struct user_struct *mlock_user;
64920+#ifdef CONFIG_GRKERNSEC
64921+ time_t shm_createtime;
64922+ pid_t shm_lapid;
64923+#endif
64924 };
64925
64926 /* shm_mode upper byte flags */
64927diff -urNp linux-2.6.39.1/include/linux/skbuff.h linux-2.6.39.1/include/linux/skbuff.h
64928--- linux-2.6.39.1/include/linux/skbuff.h 2011-05-19 00:06:34.000000000 -0400
64929+++ linux-2.6.39.1/include/linux/skbuff.h 2011-05-22 19:36:33.000000000 -0400
64930@@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
64931 */
64932 static inline int skb_queue_empty(const struct sk_buff_head *list)
64933 {
64934- return list->next == (struct sk_buff *)list;
64935+ return list->next == (const struct sk_buff *)list;
64936 }
64937
64938 /**
64939@@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
64940 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64941 const struct sk_buff *skb)
64942 {
64943- return skb->next == (struct sk_buff *)list;
64944+ return skb->next == (const struct sk_buff *)list;
64945 }
64946
64947 /**
64948@@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
64949 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64950 const struct sk_buff *skb)
64951 {
64952- return skb->prev == (struct sk_buff *)list;
64953+ return skb->prev == (const struct sk_buff *)list;
64954 }
64955
64956 /**
64957@@ -1435,7 +1435,7 @@ static inline int pskb_network_may_pull(
64958 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64959 */
64960 #ifndef NET_SKB_PAD
64961-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64962+#define NET_SKB_PAD max(_AC(32,U), L1_CACHE_BYTES)
64963 #endif
64964
64965 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64966diff -urNp linux-2.6.39.1/include/linux/slab_def.h linux-2.6.39.1/include/linux/slab_def.h
64967--- linux-2.6.39.1/include/linux/slab_def.h 2011-05-19 00:06:34.000000000 -0400
64968+++ linux-2.6.39.1/include/linux/slab_def.h 2011-05-22 19:36:33.000000000 -0400
64969@@ -96,10 +96,10 @@ struct kmem_cache {
64970 unsigned long node_allocs;
64971 unsigned long node_frees;
64972 unsigned long node_overflow;
64973- atomic_t allochit;
64974- atomic_t allocmiss;
64975- atomic_t freehit;
64976- atomic_t freemiss;
64977+ atomic_unchecked_t allochit;
64978+ atomic_unchecked_t allocmiss;
64979+ atomic_unchecked_t freehit;
64980+ atomic_unchecked_t freemiss;
64981
64982 /*
64983 * If debugging is enabled, then the allocator can add additional
64984diff -urNp linux-2.6.39.1/include/linux/slab.h linux-2.6.39.1/include/linux/slab.h
64985--- linux-2.6.39.1/include/linux/slab.h 2011-05-19 00:06:34.000000000 -0400
64986+++ linux-2.6.39.1/include/linux/slab.h 2011-05-23 17:07:00.000000000 -0400
64987@@ -11,12 +11,20 @@
64988
64989 #include <linux/gfp.h>
64990 #include <linux/types.h>
64991+#include <linux/err.h>
64992
64993 /*
64994 * Flags to pass to kmem_cache_create().
64995 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64996 */
64997 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64998+
64999+#ifdef CONFIG_PAX_USERCOPY
65000+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
65001+#else
65002+#define SLAB_USERCOPY 0x00000000UL
65003+#endif
65004+
65005 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
65006 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
65007 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
65008@@ -87,10 +95,13 @@
65009 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
65010 * Both make kfree a no-op.
65011 */
65012-#define ZERO_SIZE_PTR ((void *)16)
65013+#define ZERO_SIZE_PTR \
65014+({ \
65015+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65016+ (void *)(-MAX_ERRNO-1L); \
65017+})
65018
65019-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65020- (unsigned long)ZERO_SIZE_PTR)
65021+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65022
65023 /*
65024 * struct kmem_cache related prototypes
65025@@ -141,6 +152,7 @@ void * __must_check krealloc(const void
65026 void kfree(const void *);
65027 void kzfree(const void *);
65028 size_t ksize(const void *);
65029+void check_object_size(const void *ptr, unsigned long n, bool to);
65030
65031 /*
65032 * Allocator specific definitions. These are mainly used to establish optimized
65033@@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
65034
65035 void __init kmem_cache_init_late(void);
65036
65037+#define kmalloc(x, y) \
65038+({ \
65039+ void *___retval; \
65040+ intoverflow_t ___x = (intoverflow_t)x; \
65041+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
65042+ ___retval = NULL; \
65043+ else \
65044+ ___retval = kmalloc((size_t)___x, (y)); \
65045+ ___retval; \
65046+})
65047+
65048+#define kmalloc_node(x, y, z) \
65049+({ \
65050+ void *___retval; \
65051+ intoverflow_t ___x = (intoverflow_t)x; \
65052+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
65053+ ___retval = NULL; \
65054+ else \
65055+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
65056+ ___retval; \
65057+})
65058+
65059+#define kzalloc(x, y) \
65060+({ \
65061+ void *___retval; \
65062+ intoverflow_t ___x = (intoverflow_t)x; \
65063+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
65064+ ___retval = NULL; \
65065+ else \
65066+ ___retval = kzalloc((size_t)___x, (y)); \
65067+ ___retval; \
65068+})
65069+
65070+#define __krealloc(x, y, z) \
65071+({ \
65072+ void *___retval; \
65073+ intoverflow_t ___y = (intoverflow_t)y; \
65074+ if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
65075+ ___retval = NULL; \
65076+ else \
65077+ ___retval = __krealloc((x), (size_t)___y, (z)); \
65078+ ___retval; \
65079+})
65080+
65081+#define krealloc(x, y, z) \
65082+({ \
65083+ void *___retval; \
65084+ intoverflow_t ___y = (intoverflow_t)y; \
65085+ if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
65086+ ___retval = NULL; \
65087+ else \
65088+ ___retval = krealloc((x), (size_t)___y, (z)); \
65089+ ___retval; \
65090+})
65091+
65092 #endif /* _LINUX_SLAB_H */
65093diff -urNp linux-2.6.39.1/include/linux/slub_def.h linux-2.6.39.1/include/linux/slub_def.h
65094--- linux-2.6.39.1/include/linux/slub_def.h 2011-05-19 00:06:34.000000000 -0400
65095+++ linux-2.6.39.1/include/linux/slub_def.h 2011-05-22 19:36:33.000000000 -0400
65096@@ -84,7 +84,7 @@ struct kmem_cache {
65097 struct kmem_cache_order_objects max;
65098 struct kmem_cache_order_objects min;
65099 gfp_t allocflags; /* gfp flags to use on each alloc */
65100- int refcount; /* Refcount for slab cache destroy */
65101+ atomic_t refcount; /* Refcount for slab cache destroy */
65102 void (*ctor)(void *);
65103 int inuse; /* Offset to metadata */
65104 int align; /* Alignment */
65105diff -urNp linux-2.6.39.1/include/linux/sonet.h linux-2.6.39.1/include/linux/sonet.h
65106--- linux-2.6.39.1/include/linux/sonet.h 2011-05-19 00:06:34.000000000 -0400
65107+++ linux-2.6.39.1/include/linux/sonet.h 2011-05-22 19:36:33.000000000 -0400
65108@@ -61,7 +61,7 @@ struct sonet_stats {
65109 #include <asm/atomic.h>
65110
65111 struct k_sonet_stats {
65112-#define __HANDLE_ITEM(i) atomic_t i
65113+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65114 __SONET_ITEMS
65115 #undef __HANDLE_ITEM
65116 };
65117diff -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
65118--- linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h 2011-05-19 00:06:34.000000000 -0400
65119+++ linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h 2011-05-22 19:36:33.000000000 -0400
65120@@ -44,7 +44,7 @@ struct ssb_gige {
65121
65122 /* The PCI controller device. */
65123 struct pci_controller pci_controller;
65124- struct pci_ops pci_ops;
65125+ const struct pci_ops pci_ops;
65126 struct resource mem_resource;
65127 struct resource io_resource;
65128 };
65129diff -urNp linux-2.6.39.1/include/linux/sunrpc/clnt.h linux-2.6.39.1/include/linux/sunrpc/clnt.h
65130--- linux-2.6.39.1/include/linux/sunrpc/clnt.h 2011-05-19 00:06:34.000000000 -0400
65131+++ linux-2.6.39.1/include/linux/sunrpc/clnt.h 2011-05-22 19:36:33.000000000 -0400
65132@@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
65133 {
65134 switch (sap->sa_family) {
65135 case AF_INET:
65136- return ntohs(((struct sockaddr_in *)sap)->sin_port);
65137+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65138 case AF_INET6:
65139- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65140+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65141 }
65142 return 0;
65143 }
65144@@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
65145 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65146 const struct sockaddr *src)
65147 {
65148- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65149+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65150 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65151
65152 dsin->sin_family = ssin->sin_family;
65153@@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
65154 if (sa->sa_family != AF_INET6)
65155 return 0;
65156
65157- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65158+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65159 }
65160
65161 #endif /* __KERNEL__ */
65162diff -urNp linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h
65163--- linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h 2011-05-19 00:06:34.000000000 -0400
65164+++ linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h 2011-05-22 19:36:33.000000000 -0400
65165@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65166 extern unsigned int svcrdma_max_requests;
65167 extern unsigned int svcrdma_max_req_size;
65168
65169-extern atomic_t rdma_stat_recv;
65170-extern atomic_t rdma_stat_read;
65171-extern atomic_t rdma_stat_write;
65172-extern atomic_t rdma_stat_sq_starve;
65173-extern atomic_t rdma_stat_rq_starve;
65174-extern atomic_t rdma_stat_rq_poll;
65175-extern atomic_t rdma_stat_rq_prod;
65176-extern atomic_t rdma_stat_sq_poll;
65177-extern atomic_t rdma_stat_sq_prod;
65178+extern atomic_unchecked_t rdma_stat_recv;
65179+extern atomic_unchecked_t rdma_stat_read;
65180+extern atomic_unchecked_t rdma_stat_write;
65181+extern atomic_unchecked_t rdma_stat_sq_starve;
65182+extern atomic_unchecked_t rdma_stat_rq_starve;
65183+extern atomic_unchecked_t rdma_stat_rq_poll;
65184+extern atomic_unchecked_t rdma_stat_rq_prod;
65185+extern atomic_unchecked_t rdma_stat_sq_poll;
65186+extern atomic_unchecked_t rdma_stat_sq_prod;
65187
65188 #define RPCRDMA_VERSION 1
65189
65190diff -urNp linux-2.6.39.1/include/linux/suspend.h linux-2.6.39.1/include/linux/suspend.h
65191--- linux-2.6.39.1/include/linux/suspend.h 2011-05-19 00:06:34.000000000 -0400
65192+++ linux-2.6.39.1/include/linux/suspend.h 2011-05-22 19:36:33.000000000 -0400
65193@@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
65194 * which require special recovery actions in that situation.
65195 */
65196 struct platform_suspend_ops {
65197- int (*valid)(suspend_state_t state);
65198- int (*begin)(suspend_state_t state);
65199- int (*prepare)(void);
65200- int (*prepare_late)(void);
65201- int (*enter)(suspend_state_t state);
65202- void (*wake)(void);
65203- void (*finish)(void);
65204- void (*end)(void);
65205- void (*recover)(void);
65206+ int (* const valid)(suspend_state_t state);
65207+ int (* const begin)(suspend_state_t state);
65208+ int (* const prepare)(void);
65209+ int (* const prepare_late)(void);
65210+ int (* const enter)(suspend_state_t state);
65211+ void (* const wake)(void);
65212+ void (* const finish)(void);
65213+ void (* const end)(void);
65214+ void (* const recover)(void);
65215 };
65216
65217 #ifdef CONFIG_SUSPEND
65218@@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
65219 * platforms which require special recovery actions in that situation.
65220 */
65221 struct platform_hibernation_ops {
65222- int (*begin)(void);
65223- void (*end)(void);
65224- int (*pre_snapshot)(void);
65225- void (*finish)(void);
65226- int (*prepare)(void);
65227- int (*enter)(void);
65228- void (*leave)(void);
65229- int (*pre_restore)(void);
65230- void (*restore_cleanup)(void);
65231- void (*recover)(void);
65232+ int (* const begin)(void);
65233+ void (* const end)(void);
65234+ int (* const pre_snapshot)(void);
65235+ void (* const finish)(void);
65236+ int (* const prepare)(void);
65237+ int (* const enter)(void);
65238+ void (* const leave)(void);
65239+ int (* const pre_restore)(void);
65240+ void (* const restore_cleanup)(void);
65241+ void (* const recover)(void);
65242 };
65243
65244 #ifdef CONFIG_HIBERNATION
65245diff -urNp linux-2.6.39.1/include/linux/sysctl.h linux-2.6.39.1/include/linux/sysctl.h
65246--- linux-2.6.39.1/include/linux/sysctl.h 2011-05-19 00:06:34.000000000 -0400
65247+++ linux-2.6.39.1/include/linux/sysctl.h 2011-05-22 19:41:42.000000000 -0400
65248@@ -155,7 +155,11 @@ enum
65249 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65250 };
65251
65252-
65253+#ifdef CONFIG_PAX_SOFTMODE
65254+enum {
65255+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65256+};
65257+#endif
65258
65259 /* CTL_VM names: */
65260 enum
65261@@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
65262
65263 extern int proc_dostring(struct ctl_table *, int,
65264 void __user *, size_t *, loff_t *);
65265+extern int proc_dostring_modpriv(struct ctl_table *, int,
65266+ void __user *, size_t *, loff_t *);
65267 extern int proc_dointvec(struct ctl_table *, int,
65268 void __user *, size_t *, loff_t *);
65269 extern int proc_dointvec_minmax(struct ctl_table *, int,
65270diff -urNp linux-2.6.39.1/include/linux/sysfs.h linux-2.6.39.1/include/linux/sysfs.h
65271--- linux-2.6.39.1/include/linux/sysfs.h 2011-05-19 00:06:34.000000000 -0400
65272+++ linux-2.6.39.1/include/linux/sysfs.h 2011-05-22 19:36:33.000000000 -0400
65273@@ -110,8 +110,8 @@ struct bin_attribute {
65274 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
65275
65276 struct sysfs_ops {
65277- ssize_t (*show)(struct kobject *, struct attribute *,char *);
65278- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
65279+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
65280+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
65281 };
65282
65283 struct sysfs_dirent;
65284diff -urNp linux-2.6.39.1/include/linux/tty.h linux-2.6.39.1/include/linux/tty.h
65285--- linux-2.6.39.1/include/linux/tty.h 2011-05-19 00:06:34.000000000 -0400
65286+++ linux-2.6.39.1/include/linux/tty.h 2011-05-22 19:36:33.000000000 -0400
65287@@ -13,6 +13,7 @@
65288 #include <linux/tty_driver.h>
65289 #include <linux/tty_ldisc.h>
65290 #include <linux/mutex.h>
65291+#include <linux/poll.h>
65292
65293 #include <asm/system.h>
65294
65295@@ -466,7 +467,6 @@ extern int tty_perform_flush(struct tty_
65296 extern dev_t tty_devnum(struct tty_struct *tty);
65297 extern void proc_clear_tty(struct task_struct *p);
65298 extern struct tty_struct *get_current_tty(void);
65299-extern void tty_default_fops(struct file_operations *fops);
65300 extern struct tty_struct *alloc_tty_struct(void);
65301 extern int tty_add_file(struct tty_struct *tty, struct file *file);
65302 extern void free_tty_struct(struct tty_struct *tty);
65303@@ -529,6 +529,18 @@ extern void tty_ldisc_begin(void);
65304 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
65305 extern void tty_ldisc_enable(struct tty_struct *tty);
65306
65307+/* tty_io.c */
65308+extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
65309+extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
65310+extern unsigned int tty_poll(struct file *, poll_table *);
65311+#ifdef CONFIG_COMPAT
65312+extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
65313+ unsigned long arg);
65314+#else
65315+#define tty_compat_ioctl NULL
65316+#endif
65317+extern int tty_release(struct inode *, struct file *);
65318+extern int tty_fasync(int fd, struct file *filp, int on);
65319
65320 /* n_tty.c */
65321 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
65322diff -urNp linux-2.6.39.1/include/linux/tty_ldisc.h linux-2.6.39.1/include/linux/tty_ldisc.h
65323--- linux-2.6.39.1/include/linux/tty_ldisc.h 2011-05-19 00:06:34.000000000 -0400
65324+++ linux-2.6.39.1/include/linux/tty_ldisc.h 2011-05-22 19:36:33.000000000 -0400
65325@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
65326
65327 struct module *owner;
65328
65329- int refcount;
65330+ atomic_t refcount;
65331 };
65332
65333 struct tty_ldisc {
65334diff -urNp linux-2.6.39.1/include/linux/types.h linux-2.6.39.1/include/linux/types.h
65335--- linux-2.6.39.1/include/linux/types.h 2011-05-19 00:06:34.000000000 -0400
65336+++ linux-2.6.39.1/include/linux/types.h 2011-05-22 19:36:33.000000000 -0400
65337@@ -213,10 +213,26 @@ typedef struct {
65338 int counter;
65339 } atomic_t;
65340
65341+#ifdef CONFIG_PAX_REFCOUNT
65342+typedef struct {
65343+ int counter;
65344+} atomic_unchecked_t;
65345+#else
65346+typedef atomic_t atomic_unchecked_t;
65347+#endif
65348+
65349 #ifdef CONFIG_64BIT
65350 typedef struct {
65351 long counter;
65352 } atomic64_t;
65353+
65354+#ifdef CONFIG_PAX_REFCOUNT
65355+typedef struct {
65356+ long counter;
65357+} atomic64_unchecked_t;
65358+#else
65359+typedef atomic64_t atomic64_unchecked_t;
65360+#endif
65361 #endif
65362
65363 struct list_head {
65364diff -urNp linux-2.6.39.1/include/linux/uaccess.h linux-2.6.39.1/include/linux/uaccess.h
65365--- linux-2.6.39.1/include/linux/uaccess.h 2011-05-19 00:06:34.000000000 -0400
65366+++ linux-2.6.39.1/include/linux/uaccess.h 2011-05-22 19:36:33.000000000 -0400
65367@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
65368 long ret; \
65369 mm_segment_t old_fs = get_fs(); \
65370 \
65371- set_fs(KERNEL_DS); \
65372 pagefault_disable(); \
65373+ set_fs(KERNEL_DS); \
65374 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65375- pagefault_enable(); \
65376 set_fs(old_fs); \
65377+ pagefault_enable(); \
65378 ret; \
65379 })
65380
65381@@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
65382 * Safely read from address @src to the buffer at @dst. If a kernel fault
65383 * happens, handle that and return -EFAULT.
65384 */
65385-extern long probe_kernel_read(void *dst, void *src, size_t size);
65386-extern long __probe_kernel_read(void *dst, void *src, size_t size);
65387+extern long probe_kernel_read(void *dst, const void *src, size_t size);
65388+extern long __probe_kernel_read(void *dst, const void *src, size_t size);
65389
65390 /*
65391 * probe_kernel_write(): safely attempt to write to a location
65392@@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
65393 * Safely write to address @dst from the buffer at @src. If a kernel fault
65394 * happens, handle that and return -EFAULT.
65395 */
65396-extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
65397-extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
65398+extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
65399+extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
65400
65401 #endif /* __LINUX_UACCESS_H__ */
65402diff -urNp linux-2.6.39.1/include/linux/unaligned/access_ok.h linux-2.6.39.1/include/linux/unaligned/access_ok.h
65403--- linux-2.6.39.1/include/linux/unaligned/access_ok.h 2011-05-19 00:06:34.000000000 -0400
65404+++ linux-2.6.39.1/include/linux/unaligned/access_ok.h 2011-05-22 19:36:33.000000000 -0400
65405@@ -6,32 +6,32 @@
65406
65407 static inline u16 get_unaligned_le16(const void *p)
65408 {
65409- return le16_to_cpup((__le16 *)p);
65410+ return le16_to_cpup((const __le16 *)p);
65411 }
65412
65413 static inline u32 get_unaligned_le32(const void *p)
65414 {
65415- return le32_to_cpup((__le32 *)p);
65416+ return le32_to_cpup((const __le32 *)p);
65417 }
65418
65419 static inline u64 get_unaligned_le64(const void *p)
65420 {
65421- return le64_to_cpup((__le64 *)p);
65422+ return le64_to_cpup((const __le64 *)p);
65423 }
65424
65425 static inline u16 get_unaligned_be16(const void *p)
65426 {
65427- return be16_to_cpup((__be16 *)p);
65428+ return be16_to_cpup((const __be16 *)p);
65429 }
65430
65431 static inline u32 get_unaligned_be32(const void *p)
65432 {
65433- return be32_to_cpup((__be32 *)p);
65434+ return be32_to_cpup((const __be32 *)p);
65435 }
65436
65437 static inline u64 get_unaligned_be64(const void *p)
65438 {
65439- return be64_to_cpup((__be64 *)p);
65440+ return be64_to_cpup((const __be64 *)p);
65441 }
65442
65443 static inline void put_unaligned_le16(u16 val, void *p)
65444diff -urNp linux-2.6.39.1/include/linux/usb/hcd.h linux-2.6.39.1/include/linux/usb/hcd.h
65445--- linux-2.6.39.1/include/linux/usb/hcd.h 2011-05-19 00:06:34.000000000 -0400
65446+++ linux-2.6.39.1/include/linux/usb/hcd.h 2011-05-22 19:36:33.000000000 -0400
65447@@ -615,7 +615,7 @@ struct usb_mon_operations {
65448 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
65449 };
65450
65451-extern struct usb_mon_operations *mon_ops;
65452+extern const struct usb_mon_operations *mon_ops;
65453
65454 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
65455 {
65456@@ -637,7 +637,7 @@ static inline void usbmon_urb_complete(s
65457 (*mon_ops->urb_complete)(bus, urb, status);
65458 }
65459
65460-int usb_mon_register(struct usb_mon_operations *ops);
65461+int usb_mon_register(const struct usb_mon_operations *ops);
65462 void usb_mon_deregister(void);
65463
65464 #else
65465diff -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
65466--- linux-2.6.39.1/include/linux/usb/intel_mid_otg.h 2011-05-19 00:06:34.000000000 -0400
65467+++ linux-2.6.39.1/include/linux/usb/intel_mid_otg.h 2011-05-22 19:36:33.000000000 -0400
65468@@ -115,7 +115,7 @@ struct intel_mid_otg_xceiv {
65469 void __iomem *base;
65470
65471 /* ops to access ulpi */
65472- struct iotg_ulpi_access_ops ulpi_ops;
65473+ const struct iotg_ulpi_access_ops ulpi_ops;
65474
65475 /* atomic notifier for interrupt context */
65476 struct atomic_notifier_head iotg_notifier;
65477diff -urNp linux-2.6.39.1/include/linux/usb/ulpi.h linux-2.6.39.1/include/linux/usb/ulpi.h
65478--- linux-2.6.39.1/include/linux/usb/ulpi.h 2011-05-19 00:06:34.000000000 -0400
65479+++ linux-2.6.39.1/include/linux/usb/ulpi.h 2011-05-22 19:36:33.000000000 -0400
65480@@ -186,7 +186,7 @@ struct otg_transceiver *otg_ulpi_create(
65481
65482 #ifdef CONFIG_USB_ULPI_VIEWPORT
65483 /* access ops for controllers with a viewport register */
65484-extern struct otg_io_access_ops ulpi_viewport_access_ops;
65485+extern const struct otg_io_access_ops ulpi_viewport_access_ops;
65486 #endif
65487
65488 #endif /* __LINUX_USB_ULPI_H */
65489diff -urNp linux-2.6.39.1/include/linux/vga_switcheroo.h linux-2.6.39.1/include/linux/vga_switcheroo.h
65490--- linux-2.6.39.1/include/linux/vga_switcheroo.h 2011-05-19 00:06:34.000000000 -0400
65491+++ linux-2.6.39.1/include/linux/vga_switcheroo.h 2011-05-22 19:36:33.000000000 -0400
65492@@ -39,7 +39,7 @@ int vga_switcheroo_register_client(struc
65493 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
65494 struct fb_info *info);
65495
65496-int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
65497+int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
65498 void vga_switcheroo_unregister_handler(void);
65499
65500 int vga_switcheroo_process_delayed_switch(void);
65501@@ -52,7 +52,7 @@ static inline int vga_switcheroo_registe
65502 void (*reprobe)(struct pci_dev *dev),
65503 bool (*can_switch)(struct pci_dev *dev)) { return 0; }
65504 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
65505-static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; }
65506+static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
65507 static inline void vga_switcheroo_unregister_handler(void) {}
65508 static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
65509
65510diff -urNp linux-2.6.39.1/include/linux/virtio.h linux-2.6.39.1/include/linux/virtio.h
65511--- linux-2.6.39.1/include/linux/virtio.h 2011-05-19 00:06:34.000000000 -0400
65512+++ linux-2.6.39.1/include/linux/virtio.h 2011-05-22 19:36:33.000000000 -0400
65513@@ -102,7 +102,7 @@ struct virtio_device {
65514 int index;
65515 struct device dev;
65516 struct virtio_device_id id;
65517- struct virtio_config_ops *config;
65518+ const struct virtio_config_ops *config;
65519 struct list_head vqs;
65520 /* Note that this is a Linux set_bit-style bitmap. */
65521 unsigned long features[1];
65522diff -urNp linux-2.6.39.1/include/linux/vmalloc.h linux-2.6.39.1/include/linux/vmalloc.h
65523--- linux-2.6.39.1/include/linux/vmalloc.h 2011-05-19 00:06:34.000000000 -0400
65524+++ linux-2.6.39.1/include/linux/vmalloc.h 2011-05-22 19:36:33.000000000 -0400
65525@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
65526 #define VM_MAP 0x00000004 /* vmap()ed pages */
65527 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65528 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65529+
65530+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65531+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
65532+#endif
65533+
65534 /* bits [20..32] reserved for arch specific ioremap internals */
65535
65536 /*
65537@@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
65538 # endif
65539 #endif
65540
65541+#define vmalloc(x) \
65542+({ \
65543+ void *___retval; \
65544+ intoverflow_t ___x = (intoverflow_t)x; \
65545+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
65546+ ___retval = NULL; \
65547+ else \
65548+ ___retval = vmalloc((unsigned long)___x); \
65549+ ___retval; \
65550+})
65551+
65552+#define vzalloc(x) \
65553+({ \
65554+ void *___retval; \
65555+ intoverflow_t ___x = (intoverflow_t)x; \
65556+ if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
65557+ ___retval = NULL; \
65558+ else \
65559+ ___retval = vzalloc((unsigned long)___x); \
65560+ ___retval; \
65561+})
65562+
65563+#define __vmalloc(x, y, z) \
65564+({ \
65565+ void *___retval; \
65566+ intoverflow_t ___x = (intoverflow_t)x; \
65567+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
65568+ ___retval = NULL; \
65569+ else \
65570+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
65571+ ___retval; \
65572+})
65573+
65574+#define vmalloc_user(x) \
65575+({ \
65576+ void *___retval; \
65577+ intoverflow_t ___x = (intoverflow_t)x; \
65578+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
65579+ ___retval = NULL; \
65580+ else \
65581+ ___retval = vmalloc_user((unsigned long)___x); \
65582+ ___retval; \
65583+})
65584+
65585+#define vmalloc_exec(x) \
65586+({ \
65587+ void *___retval; \
65588+ intoverflow_t ___x = (intoverflow_t)x; \
65589+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
65590+ ___retval = NULL; \
65591+ else \
65592+ ___retval = vmalloc_exec((unsigned long)___x); \
65593+ ___retval; \
65594+})
65595+
65596+#define vmalloc_node(x, y) \
65597+({ \
65598+ void *___retval; \
65599+ intoverflow_t ___x = (intoverflow_t)x; \
65600+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
65601+ ___retval = NULL; \
65602+ else \
65603+ ___retval = vmalloc_node((unsigned long)___x, (y));\
65604+ ___retval; \
65605+})
65606+
65607+#define vzalloc_node(x, y) \
65608+({ \
65609+ void *___retval; \
65610+ intoverflow_t ___x = (intoverflow_t)x; \
65611+ if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
65612+ ___retval = NULL; \
65613+ else \
65614+ ___retval = vzalloc_node((unsigned long)___x, (y));\
65615+ ___retval; \
65616+})
65617+
65618+#define vmalloc_32(x) \
65619+({ \
65620+ void *___retval; \
65621+ intoverflow_t ___x = (intoverflow_t)x; \
65622+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
65623+ ___retval = NULL; \
65624+ else \
65625+ ___retval = vmalloc_32((unsigned long)___x); \
65626+ ___retval; \
65627+})
65628+
65629+#define vmalloc_32_user(x) \
65630+({ \
65631+void *___retval; \
65632+ intoverflow_t ___x = (intoverflow_t)x; \
65633+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
65634+ ___retval = NULL; \
65635+ else \
65636+ ___retval = vmalloc_32_user((unsigned long)___x);\
65637+ ___retval; \
65638+})
65639+
65640 #endif /* _LINUX_VMALLOC_H */
65641diff -urNp linux-2.6.39.1/include/linux/vmstat.h linux-2.6.39.1/include/linux/vmstat.h
65642--- linux-2.6.39.1/include/linux/vmstat.h 2011-05-19 00:06:34.000000000 -0400
65643+++ linux-2.6.39.1/include/linux/vmstat.h 2011-05-22 19:36:33.000000000 -0400
65644@@ -147,18 +147,18 @@ static inline void vm_events_fold_cpu(in
65645 /*
65646 * Zone based page accounting with per cpu differentials.
65647 */
65648-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65649+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65650
65651 static inline void zone_page_state_add(long x, struct zone *zone,
65652 enum zone_stat_item item)
65653 {
65654- atomic_long_add(x, &zone->vm_stat[item]);
65655- atomic_long_add(x, &vm_stat[item]);
65656+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65657+ atomic_long_add_unchecked(x, &vm_stat[item]);
65658 }
65659
65660 static inline unsigned long global_page_state(enum zone_stat_item item)
65661 {
65662- long x = atomic_long_read(&vm_stat[item]);
65663+ long x = atomic_long_read_unchecked(&vm_stat[item]);
65664 #ifdef CONFIG_SMP
65665 if (x < 0)
65666 x = 0;
65667@@ -169,7 +169,7 @@ static inline unsigned long global_page_
65668 static inline unsigned long zone_page_state(struct zone *zone,
65669 enum zone_stat_item item)
65670 {
65671- long x = atomic_long_read(&zone->vm_stat[item]);
65672+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65673 #ifdef CONFIG_SMP
65674 if (x < 0)
65675 x = 0;
65676@@ -186,7 +186,7 @@ static inline unsigned long zone_page_st
65677 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65678 enum zone_stat_item item)
65679 {
65680- long x = atomic_long_read(&zone->vm_stat[item]);
65681+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65682
65683 #ifdef CONFIG_SMP
65684 int cpu;
65685@@ -280,8 +280,8 @@ static inline void __mod_zone_page_state
65686
65687 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65688 {
65689- atomic_long_inc(&zone->vm_stat[item]);
65690- atomic_long_inc(&vm_stat[item]);
65691+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
65692+ atomic_long_inc_unchecked(&vm_stat[item]);
65693 }
65694
65695 static inline void __inc_zone_page_state(struct page *page,
65696@@ -292,8 +292,8 @@ static inline void __inc_zone_page_state
65697
65698 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65699 {
65700- atomic_long_dec(&zone->vm_stat[item]);
65701- atomic_long_dec(&vm_stat[item]);
65702+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
65703+ atomic_long_dec_unchecked(&vm_stat[item]);
65704 }
65705
65706 static inline void __dec_zone_page_state(struct page *page,
65707diff -urNp linux-2.6.39.1/include/media/saa7146_vv.h linux-2.6.39.1/include/media/saa7146_vv.h
65708--- linux-2.6.39.1/include/media/saa7146_vv.h 2011-05-19 00:06:34.000000000 -0400
65709+++ linux-2.6.39.1/include/media/saa7146_vv.h 2011-05-22 19:36:33.000000000 -0400
65710@@ -202,13 +202,13 @@ void saa7146_set_gpio(struct saa7146_dev
65711
65712 /* from saa7146_video.c */
65713 extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
65714-extern struct saa7146_use_ops saa7146_video_uops;
65715+extern const struct saa7146_use_ops saa7146_video_uops;
65716 int saa7146_start_preview(struct saa7146_fh *fh);
65717 int saa7146_stop_preview(struct saa7146_fh *fh);
65718 long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
65719
65720 /* from saa7146_vbi.c */
65721-extern struct saa7146_use_ops saa7146_vbi_uops;
65722+extern const struct saa7146_use_ops saa7146_vbi_uops;
65723
65724 /* resource management functions */
65725 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
65726diff -urNp linux-2.6.39.1/include/media/v4l2-device.h linux-2.6.39.1/include/media/v4l2-device.h
65727--- linux-2.6.39.1/include/media/v4l2-device.h 2011-05-19 00:06:34.000000000 -0400
65728+++ linux-2.6.39.1/include/media/v4l2-device.h 2011-05-22 19:36:33.000000000 -0400
65729@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(st
65730 this function returns 0. If the name ends with a digit (e.g. cx18),
65731 then the name will be set to cx18-0 since cx180 looks really odd. */
65732 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
65733- atomic_t *instance);
65734+ atomic_unchecked_t *instance);
65735
65736 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
65737 Since the parent disappears this ensures that v4l2_dev doesn't have an
65738diff -urNp linux-2.6.39.1/include/net/caif/cfctrl.h linux-2.6.39.1/include/net/caif/cfctrl.h
65739--- linux-2.6.39.1/include/net/caif/cfctrl.h 2011-05-19 00:06:34.000000000 -0400
65740+++ linux-2.6.39.1/include/net/caif/cfctrl.h 2011-05-22 19:36:33.000000000 -0400
65741@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65742 struct cfctrl {
65743 struct cfsrvl serv;
65744 struct cfctrl_rsp res;
65745- atomic_t req_seq_no;
65746- atomic_t rsp_seq_no;
65747+ atomic_unchecked_t req_seq_no;
65748+ atomic_unchecked_t rsp_seq_no;
65749 struct list_head list;
65750 /* Protects from simultaneous access to first_req list */
65751 spinlock_t info_list_lock;
65752diff -urNp linux-2.6.39.1/include/net/flow.h linux-2.6.39.1/include/net/flow.h
65753--- linux-2.6.39.1/include/net/flow.h 2011-05-19 00:06:34.000000000 -0400
65754+++ linux-2.6.39.1/include/net/flow.h 2011-05-22 19:36:33.000000000 -0400
65755@@ -167,6 +167,6 @@ extern struct flow_cache_object *flow_ca
65756 u8 dir, flow_resolve_t resolver, void *ctx);
65757
65758 extern void flow_cache_flush(void);
65759-extern atomic_t flow_cache_genid;
65760+extern atomic_unchecked_t flow_cache_genid;
65761
65762 #endif
65763diff -urNp linux-2.6.39.1/include/net/inetpeer.h linux-2.6.39.1/include/net/inetpeer.h
65764--- linux-2.6.39.1/include/net/inetpeer.h 2011-05-19 00:06:34.000000000 -0400
65765+++ linux-2.6.39.1/include/net/inetpeer.h 2011-05-22 19:36:33.000000000 -0400
65766@@ -43,8 +43,8 @@ struct inet_peer {
65767 */
65768 union {
65769 struct {
65770- atomic_t rid; /* Frag reception counter */
65771- atomic_t ip_id_count; /* IP ID for the next packet */
65772+ atomic_unchecked_t rid; /* Frag reception counter */
65773+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65774 __u32 tcp_ts;
65775 __u32 tcp_ts_stamp;
65776 u32 metrics[RTAX_MAX];
65777@@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
65778 {
65779 more++;
65780 inet_peer_refcheck(p);
65781- return atomic_add_return(more, &p->ip_id_count) - more;
65782+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
65783 }
65784
65785 #endif /* _NET_INETPEER_H */
65786diff -urNp linux-2.6.39.1/include/net/ip_fib.h linux-2.6.39.1/include/net/ip_fib.h
65787--- linux-2.6.39.1/include/net/ip_fib.h 2011-05-19 00:06:34.000000000 -0400
65788+++ linux-2.6.39.1/include/net/ip_fib.h 2011-05-22 19:36:33.000000000 -0400
65789@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
65790
65791 #define FIB_RES_SADDR(net, res) \
65792 ((FIB_RES_NH(res).nh_saddr_genid == \
65793- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65794+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65795 FIB_RES_NH(res).nh_saddr : \
65796 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65797 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65798diff -urNp linux-2.6.39.1/include/net/ip_vs.h linux-2.6.39.1/include/net/ip_vs.h
65799--- linux-2.6.39.1/include/net/ip_vs.h 2011-05-19 00:06:34.000000000 -0400
65800+++ linux-2.6.39.1/include/net/ip_vs.h 2011-05-22 19:36:33.000000000 -0400
65801@@ -512,7 +512,7 @@ struct ip_vs_conn {
65802 struct ip_vs_conn *control; /* Master control connection */
65803 atomic_t n_control; /* Number of controlled ones */
65804 struct ip_vs_dest *dest; /* real server */
65805- atomic_t in_pkts; /* incoming packet counter */
65806+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65807
65808 /* packet transmitter for different forwarding methods. If it
65809 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65810@@ -650,7 +650,7 @@ struct ip_vs_dest {
65811 __be16 port; /* port number of the server */
65812 union nf_inet_addr addr; /* IP address of the server */
65813 volatile unsigned flags; /* dest status flags */
65814- atomic_t conn_flags; /* flags to copy to conn */
65815+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65816 atomic_t weight; /* server weight */
65817
65818 atomic_t refcnt; /* reference counter */
65819diff -urNp linux-2.6.39.1/include/net/irda/ircomm_tty.h linux-2.6.39.1/include/net/irda/ircomm_tty.h
65820--- linux-2.6.39.1/include/net/irda/ircomm_tty.h 2011-05-19 00:06:34.000000000 -0400
65821+++ linux-2.6.39.1/include/net/irda/ircomm_tty.h 2011-05-22 19:36:33.000000000 -0400
65822@@ -35,6 +35,7 @@
65823 #include <linux/termios.h>
65824 #include <linux/timer.h>
65825 #include <linux/tty.h> /* struct tty_struct */
65826+#include <asm/local.h>
65827
65828 #include <net/irda/irias_object.h>
65829 #include <net/irda/ircomm_core.h>
65830@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65831 unsigned short close_delay;
65832 unsigned short closing_wait; /* time to wait before closing */
65833
65834- int open_count;
65835- int blocked_open; /* # of blocked opens */
65836+ local_t open_count;
65837+ local_t blocked_open; /* # of blocked opens */
65838
65839 /* Protect concurent access to :
65840 * o self->open_count
65841diff -urNp linux-2.6.39.1/include/net/iucv/af_iucv.h linux-2.6.39.1/include/net/iucv/af_iucv.h
65842--- linux-2.6.39.1/include/net/iucv/af_iucv.h 2011-05-19 00:06:34.000000000 -0400
65843+++ linux-2.6.39.1/include/net/iucv/af_iucv.h 2011-05-22 19:36:33.000000000 -0400
65844@@ -87,7 +87,7 @@ struct iucv_sock {
65845 struct iucv_sock_list {
65846 struct hlist_head head;
65847 rwlock_t lock;
65848- atomic_t autobind_name;
65849+ atomic_unchecked_t autobind_name;
65850 };
65851
65852 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65853diff -urNp linux-2.6.39.1/include/net/neighbour.h linux-2.6.39.1/include/net/neighbour.h
65854--- linux-2.6.39.1/include/net/neighbour.h 2011-05-19 00:06:34.000000000 -0400
65855+++ linux-2.6.39.1/include/net/neighbour.h 2011-05-22 19:36:33.000000000 -0400
65856@@ -118,12 +118,12 @@ struct neighbour {
65857
65858 struct neigh_ops {
65859 int family;
65860- void (*solicit)(struct neighbour *, struct sk_buff*);
65861- void (*error_report)(struct neighbour *, struct sk_buff*);
65862- int (*output)(struct sk_buff*);
65863- int (*connected_output)(struct sk_buff*);
65864- int (*hh_output)(struct sk_buff*);
65865- int (*queue_xmit)(struct sk_buff*);
65866+ void (* const solicit)(struct neighbour *, struct sk_buff*);
65867+ void (* const error_report)(struct neighbour *, struct sk_buff*);
65868+ int (* const output)(struct sk_buff*);
65869+ int (* const connected_output)(struct sk_buff*);
65870+ int (* const hh_output)(struct sk_buff*);
65871+ int (* const queue_xmit)(struct sk_buff*);
65872 };
65873
65874 struct pneigh_entry {
65875diff -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
65876--- linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h 2011-05-19 00:06:34.000000000 -0400
65877+++ linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h 2011-05-22 19:36:33.000000000 -0400
65878@@ -95,7 +95,7 @@ nf_conntrack_eventmask_report(unsigned i
65879 int report)
65880 {
65881 int ret = 0;
65882- struct nf_ct_event_notifier *notify;
65883+ const struct nf_ct_event_notifier *notify;
65884 struct nf_conntrack_ecache *e;
65885
65886 rcu_read_lock();
65887@@ -174,7 +174,7 @@ nf_ct_expect_event_report(enum ip_conntr
65888 u32 pid,
65889 int report)
65890 {
65891- struct nf_exp_event_notifier *notify;
65892+ const struct nf_exp_event_notifier *notify;
65893 struct nf_conntrack_ecache *e;
65894
65895 rcu_read_lock();
65896diff -urNp linux-2.6.39.1/include/net/netlink.h linux-2.6.39.1/include/net/netlink.h
65897--- linux-2.6.39.1/include/net/netlink.h 2011-05-19 00:06:34.000000000 -0400
65898+++ linux-2.6.39.1/include/net/netlink.h 2011-05-22 19:36:33.000000000 -0400
65899@@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
65900 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65901 {
65902 if (mark)
65903- skb_trim(skb, (unsigned char *) mark - skb->data);
65904+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65905 }
65906
65907 /**
65908diff -urNp linux-2.6.39.1/include/net/netns/ipv4.h linux-2.6.39.1/include/net/netns/ipv4.h
65909--- linux-2.6.39.1/include/net/netns/ipv4.h 2011-05-19 00:06:34.000000000 -0400
65910+++ linux-2.6.39.1/include/net/netns/ipv4.h 2011-05-22 19:36:33.000000000 -0400
65911@@ -54,8 +54,8 @@ struct netns_ipv4 {
65912 int sysctl_rt_cache_rebuild_count;
65913 int current_rt_cache_rebuild_count;
65914
65915- atomic_t rt_genid;
65916- atomic_t dev_addr_genid;
65917+ atomic_unchecked_t rt_genid;
65918+ atomic_unchecked_t dev_addr_genid;
65919
65920 #ifdef CONFIG_IP_MROUTE
65921 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65922diff -urNp linux-2.6.39.1/include/net/sctp/sctp.h linux-2.6.39.1/include/net/sctp/sctp.h
65923--- linux-2.6.39.1/include/net/sctp/sctp.h 2011-05-19 00:06:34.000000000 -0400
65924+++ linux-2.6.39.1/include/net/sctp/sctp.h 2011-05-22 19:36:33.000000000 -0400
65925@@ -316,9 +316,9 @@ do { \
65926
65927 #else /* SCTP_DEBUG */
65928
65929-#define SCTP_DEBUG_PRINTK(whatever...)
65930-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65931-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65932+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65933+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65934+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65935 #define SCTP_ENABLE_DEBUG
65936 #define SCTP_DISABLE_DEBUG
65937 #define SCTP_ASSERT(expr, str, func)
65938diff -urNp linux-2.6.39.1/include/net/sock.h linux-2.6.39.1/include/net/sock.h
65939--- linux-2.6.39.1/include/net/sock.h 2011-05-19 00:06:34.000000000 -0400
65940+++ linux-2.6.39.1/include/net/sock.h 2011-05-22 19:36:33.000000000 -0400
65941@@ -277,7 +277,7 @@ struct sock {
65942 #ifdef CONFIG_RPS
65943 __u32 sk_rxhash;
65944 #endif
65945- atomic_t sk_drops;
65946+ atomic_unchecked_t sk_drops;
65947 int sk_rcvbuf;
65948
65949 struct sk_filter __rcu *sk_filter;
65950diff -urNp linux-2.6.39.1/include/net/tcp.h linux-2.6.39.1/include/net/tcp.h
65951--- linux-2.6.39.1/include/net/tcp.h 2011-05-19 00:06:34.000000000 -0400
65952+++ linux-2.6.39.1/include/net/tcp.h 2011-05-22 19:36:33.000000000 -0400
65953@@ -1374,7 +1374,7 @@ enum tcp_seq_states {
65954 struct tcp_seq_afinfo {
65955 char *name;
65956 sa_family_t family;
65957- struct file_operations seq_fops;
65958+ struct file_operations seq_fops; /* cannot be const */
65959 struct seq_operations seq_ops;
65960 };
65961
65962diff -urNp linux-2.6.39.1/include/net/udp.h linux-2.6.39.1/include/net/udp.h
65963--- linux-2.6.39.1/include/net/udp.h 2011-05-19 00:06:34.000000000 -0400
65964+++ linux-2.6.39.1/include/net/udp.h 2011-05-22 19:36:33.000000000 -0400
65965@@ -234,7 +234,7 @@ struct udp_seq_afinfo {
65966 char *name;
65967 sa_family_t family;
65968 struct udp_table *udp_table;
65969- struct file_operations seq_fops;
65970+ struct file_operations seq_fops; /* cannot be const */
65971 struct seq_operations seq_ops;
65972 };
65973
65974diff -urNp linux-2.6.39.1/include/net/xfrm.h linux-2.6.39.1/include/net/xfrm.h
65975--- linux-2.6.39.1/include/net/xfrm.h 2011-05-19 00:06:34.000000000 -0400
65976+++ linux-2.6.39.1/include/net/xfrm.h 2011-05-22 19:36:33.000000000 -0400
65977@@ -505,7 +505,7 @@ struct xfrm_policy {
65978 struct timer_list timer;
65979
65980 struct flow_cache_object flo;
65981- atomic_t genid;
65982+ atomic_unchecked_t genid;
65983 u32 priority;
65984 u32 index;
65985 struct xfrm_mark mark;
65986diff -urNp linux-2.6.39.1/include/pcmcia/ss.h linux-2.6.39.1/include/pcmcia/ss.h
65987--- linux-2.6.39.1/include/pcmcia/ss.h 2011-05-19 00:06:34.000000000 -0400
65988+++ linux-2.6.39.1/include/pcmcia/ss.h 2011-05-22 19:36:33.000000000 -0400
65989@@ -241,9 +241,9 @@ struct pcmcia_socket {
65990 * "select PCCARD_NONSTATIC" in Kconfig.
65991 *
65992 */
65993-extern struct pccard_resource_ops pccard_static_ops;
65994+extern const struct pccard_resource_ops pccard_static_ops;
65995 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
65996-extern struct pccard_resource_ops pccard_iodyn_ops;
65997+extern const struct pccard_resource_ops pccard_iodyn_ops;
65998 extern struct pccard_resource_ops pccard_nonstatic_ops;
65999 #else
66000 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
66001diff -urNp linux-2.6.39.1/include/rdma/ib_verbs.h linux-2.6.39.1/include/rdma/ib_verbs.h
66002--- linux-2.6.39.1/include/rdma/ib_verbs.h 2011-05-19 00:06:34.000000000 -0400
66003+++ linux-2.6.39.1/include/rdma/ib_verbs.h 2011-05-22 19:36:33.000000000 -0400
66004@@ -1149,7 +1149,7 @@ struct ib_device {
66005 struct ib_mad *in_mad,
66006 struct ib_mad *out_mad);
66007
66008- struct ib_dma_mapping_ops *dma_ops;
66009+ const struct ib_dma_mapping_ops *dma_ops;
66010
66011 struct module *owner;
66012 struct device dev;
66013diff -urNp linux-2.6.39.1/include/scsi/libfc.h linux-2.6.39.1/include/scsi/libfc.h
66014--- linux-2.6.39.1/include/scsi/libfc.h 2011-05-19 00:06:34.000000000 -0400
66015+++ linux-2.6.39.1/include/scsi/libfc.h 2011-05-22 19:36:33.000000000 -0400
66016@@ -202,7 +202,7 @@ struct fc_rport_priv {
66017 struct mutex rp_mutex;
66018 struct delayed_work retry_work;
66019 enum fc_rport_event event;
66020- struct fc_rport_operations *ops;
66021+ const struct fc_rport_operations *ops;
66022 struct list_head peers;
66023 struct work_struct event_work;
66024 u32 supported_classes;
66025diff -urNp linux-2.6.39.1/include/scsi/scsi_device.h linux-2.6.39.1/include/scsi/scsi_device.h
66026--- linux-2.6.39.1/include/scsi/scsi_device.h 2011-05-19 00:06:34.000000000 -0400
66027+++ linux-2.6.39.1/include/scsi/scsi_device.h 2011-05-22 19:36:33.000000000 -0400
66028@@ -161,9 +161,9 @@ struct scsi_device {
66029 unsigned int max_device_blocked; /* what device_blocked counts down from */
66030 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
66031
66032- atomic_t iorequest_cnt;
66033- atomic_t iodone_cnt;
66034- atomic_t ioerr_cnt;
66035+ atomic_unchecked_t iorequest_cnt;
66036+ atomic_unchecked_t iodone_cnt;
66037+ atomic_unchecked_t ioerr_cnt;
66038
66039 struct device sdev_gendev,
66040 sdev_dev;
66041diff -urNp linux-2.6.39.1/include/sound/ac97_codec.h linux-2.6.39.1/include/sound/ac97_codec.h
66042--- linux-2.6.39.1/include/sound/ac97_codec.h 2011-05-19 00:06:34.000000000 -0400
66043+++ linux-2.6.39.1/include/sound/ac97_codec.h 2011-05-22 19:36:33.000000000 -0400
66044@@ -424,15 +424,15 @@
66045 struct snd_ac97;
66046
66047 struct snd_ac97_build_ops {
66048- int (*build_3d) (struct snd_ac97 *ac97);
66049- int (*build_specific) (struct snd_ac97 *ac97);
66050- int (*build_spdif) (struct snd_ac97 *ac97);
66051- int (*build_post_spdif) (struct snd_ac97 *ac97);
66052+ int (* const build_3d) (struct snd_ac97 *ac97);
66053+ int (* const build_specific) (struct snd_ac97 *ac97);
66054+ int (* const build_spdif) (struct snd_ac97 *ac97);
66055+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
66056 #ifdef CONFIG_PM
66057- void (*suspend) (struct snd_ac97 *ac97);
66058- void (*resume) (struct snd_ac97 *ac97);
66059+ void (* const suspend) (struct snd_ac97 *ac97);
66060+ void (* const resume) (struct snd_ac97 *ac97);
66061 #endif
66062- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
66063+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
66064 };
66065
66066 struct snd_ac97_bus_ops {
66067@@ -446,7 +446,7 @@ struct snd_ac97_bus_ops {
66068
66069 struct snd_ac97_bus {
66070 /* -- lowlevel (hardware) driver specific -- */
66071- struct snd_ac97_bus_ops *ops;
66072+ const struct snd_ac97_bus_ops *ops;
66073 void *private_data;
66074 void (*private_free) (struct snd_ac97_bus *bus);
66075 /* --- */
66076@@ -556,7 +556,7 @@ static inline int ac97_can_spdif(struct
66077
66078 /* functions */
66079 /* create new AC97 bus */
66080-int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
66081+int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
66082 void *private_data, struct snd_ac97_bus **rbus);
66083 /* create mixer controls */
66084 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
66085diff -urNp linux-2.6.39.1/include/sound/core.h linux-2.6.39.1/include/sound/core.h
66086--- linux-2.6.39.1/include/sound/core.h 2011-05-19 00:06:34.000000000 -0400
66087+++ linux-2.6.39.1/include/sound/core.h 2011-05-22 19:36:33.000000000 -0400
66088@@ -88,7 +88,7 @@ struct snd_device {
66089 snd_device_state_t state; /* state of the device */
66090 snd_device_type_t type; /* device type */
66091 void *device_data; /* device structure */
66092- struct snd_device_ops *ops; /* operations */
66093+ const struct snd_device_ops *ops; /* operations */
66094 };
66095
66096 #define snd_device(n) list_entry(n, struct snd_device, list)
66097@@ -301,7 +301,7 @@ int snd_card_file_remove(struct snd_card
66098 /* device.c */
66099
66100 int snd_device_new(struct snd_card *card, snd_device_type_t type,
66101- void *device_data, struct snd_device_ops *ops);
66102+ void *device_data, const struct snd_device_ops *ops);
66103 int snd_device_register(struct snd_card *card, void *device_data);
66104 int snd_device_register_all(struct snd_card *card);
66105 int snd_device_disconnect(struct snd_card *card, void *device_data);
66106diff -urNp linux-2.6.39.1/include/sound/pcm.h linux-2.6.39.1/include/sound/pcm.h
66107--- linux-2.6.39.1/include/sound/pcm.h 2011-05-19 00:06:34.000000000 -0400
66108+++ linux-2.6.39.1/include/sound/pcm.h 2011-05-22 19:36:33.000000000 -0400
66109@@ -379,7 +379,7 @@ struct snd_pcm_substream {
66110 unsigned int dma_buf_id;
66111 size_t dma_max;
66112 /* -- hardware operations -- */
66113- struct snd_pcm_ops *ops;
66114+ const struct snd_pcm_ops *ops;
66115 /* -- runtime information -- */
66116 struct snd_pcm_runtime *runtime;
66117 /* -- timer section -- */
66118@@ -845,7 +845,7 @@ const unsigned char *snd_pcm_format_sile
66119 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
66120 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
66121
66122-void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
66123+void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, const struct snd_pcm_ops *ops);
66124 void snd_pcm_set_sync(struct snd_pcm_substream *substream);
66125 int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
66126 int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
66127diff -urNp linux-2.6.39.1/include/sound/rawmidi.h linux-2.6.39.1/include/sound/rawmidi.h
66128--- linux-2.6.39.1/include/sound/rawmidi.h 2011-05-19 00:06:34.000000000 -0400
66129+++ linux-2.6.39.1/include/sound/rawmidi.h 2011-05-22 19:36:33.000000000 -0400
66130@@ -100,7 +100,7 @@ struct snd_rawmidi_substream {
66131 struct snd_rawmidi_runtime *runtime;
66132 struct pid *pid;
66133 /* hardware layer */
66134- struct snd_rawmidi_ops *ops;
66135+ const struct snd_rawmidi_ops *ops;
66136 };
66137
66138 struct snd_rawmidi_file {
66139@@ -127,7 +127,7 @@ struct snd_rawmidi {
66140 int ossreg;
66141 #endif
66142
66143- struct snd_rawmidi_global_ops *ops;
66144+ const struct snd_rawmidi_global_ops *ops;
66145
66146 struct snd_rawmidi_str streams[2];
66147
66148@@ -151,7 +151,7 @@ int snd_rawmidi_new(struct snd_card *car
66149 int output_count, int input_count,
66150 struct snd_rawmidi **rmidi);
66151 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
66152- struct snd_rawmidi_ops *ops);
66153+ const struct snd_rawmidi_ops *ops);
66154
66155 /* callbacks */
66156
66157diff -urNp linux-2.6.39.1/include/sound/seq_device.h linux-2.6.39.1/include/sound/seq_device.h
66158--- linux-2.6.39.1/include/sound/seq_device.h 2011-05-19 00:06:34.000000000 -0400
66159+++ linux-2.6.39.1/include/sound/seq_device.h 2011-05-22 19:36:33.000000000 -0400
66160@@ -69,7 +69,7 @@ struct snd_seq_dev_ops {
66161 */
66162 void snd_seq_device_load_drivers(void);
66163 int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result);
66164-int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize);
66165+int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry, int argsize);
66166 int snd_seq_device_unregister_driver(char *id);
66167
66168 #define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device))
66169diff -urNp linux-2.6.39.1/include/sound/snd_wavefront.h linux-2.6.39.1/include/sound/snd_wavefront.h
66170--- linux-2.6.39.1/include/sound/snd_wavefront.h 2011-05-19 00:06:34.000000000 -0400
66171+++ linux-2.6.39.1/include/sound/snd_wavefront.h 2011-05-22 19:36:33.000000000 -0400
66172@@ -37,8 +37,8 @@ struct _snd_wavefront_midi {
66173 #define MPU_ACK 0xFE
66174 #define UART_MODE_ON 0x3F
66175
66176-extern struct snd_rawmidi_ops snd_wavefront_midi_output;
66177-extern struct snd_rawmidi_ops snd_wavefront_midi_input;
66178+extern const struct snd_rawmidi_ops snd_wavefront_midi_output;
66179+extern const struct snd_rawmidi_ops snd_wavefront_midi_input;
66180
66181 extern void snd_wavefront_midi_enable_virtual (snd_wavefront_card_t *);
66182 extern void snd_wavefront_midi_disable_virtual (snd_wavefront_card_t *);
66183diff -urNp linux-2.6.39.1/include/sound/soc.h linux-2.6.39.1/include/sound/soc.h
66184--- linux-2.6.39.1/include/sound/soc.h 2011-05-19 00:06:34.000000000 -0400
66185+++ linux-2.6.39.1/include/sound/soc.h 2011-05-22 19:36:33.000000000 -0400
66186@@ -245,7 +245,7 @@ struct snd_soc_jack_gpio;
66187
66188 typedef int (*hw_write_t)(void *,const char* ,int);
66189
66190-extern struct snd_ac97_bus_ops soc_ac97_ops;
66191+extern const struct snd_ac97_bus_ops soc_ac97_ops;
66192
66193 enum snd_soc_control_type {
66194 SND_SOC_CUSTOM,
66195diff -urNp linux-2.6.39.1/include/sound/ymfpci.h linux-2.6.39.1/include/sound/ymfpci.h
66196--- linux-2.6.39.1/include/sound/ymfpci.h 2011-05-19 00:06:34.000000000 -0400
66197+++ linux-2.6.39.1/include/sound/ymfpci.h 2011-05-22 19:36:33.000000000 -0400
66198@@ -358,7 +358,7 @@ struct snd_ymfpci {
66199 spinlock_t reg_lock;
66200 spinlock_t voice_lock;
66201 wait_queue_head_t interrupt_sleep;
66202- atomic_t interrupt_sleep_count;
66203+ atomic_unchecked_t interrupt_sleep_count;
66204 struct snd_info_entry *proc_entry;
66205 const struct firmware *dsp_microcode;
66206 const struct firmware *controller_microcode;
66207diff -urNp linux-2.6.39.1/include/target/target_core_base.h linux-2.6.39.1/include/target/target_core_base.h
66208--- linux-2.6.39.1/include/target/target_core_base.h 2011-06-03 00:04:14.000000000 -0400
66209+++ linux-2.6.39.1/include/target/target_core_base.h 2011-06-03 00:32:08.000000000 -0400
66210@@ -432,8 +432,8 @@ struct se_transport_task {
66211 atomic_t t_task_cdbs_left;
66212 atomic_t t_task_cdbs_ex_left;
66213 atomic_t t_task_cdbs_timeout_left;
66214- atomic_t t_task_cdbs_sent;
66215- atomic_t t_transport_aborted;
66216+ atomic_unchecked_t t_task_cdbs_sent;
66217+ atomic_unchecked_t t_transport_aborted;
66218 atomic_t t_transport_active;
66219 atomic_t t_transport_complete;
66220 atomic_t t_transport_queue_active;
66221@@ -774,7 +774,7 @@ struct se_device {
66222 atomic_t active_cmds;
66223 atomic_t simple_cmds;
66224 atomic_t depth_left;
66225- atomic_t dev_ordered_id;
66226+ atomic_unchecked_t dev_ordered_id;
66227 atomic_t dev_tur_active;
66228 atomic_t execute_tasks;
66229 atomic_t dev_status_thr_count;
66230diff -urNp linux-2.6.39.1/include/trace/events/irq.h linux-2.6.39.1/include/trace/events/irq.h
66231--- linux-2.6.39.1/include/trace/events/irq.h 2011-05-19 00:06:34.000000000 -0400
66232+++ linux-2.6.39.1/include/trace/events/irq.h 2011-05-22 19:36:33.000000000 -0400
66233@@ -36,7 +36,7 @@ struct softirq_action;
66234 */
66235 TRACE_EVENT(irq_handler_entry,
66236
66237- TP_PROTO(int irq, struct irqaction *action),
66238+ TP_PROTO(int irq, const struct irqaction *action),
66239
66240 TP_ARGS(irq, action),
66241
66242@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66243 */
66244 TRACE_EVENT(irq_handler_exit,
66245
66246- TP_PROTO(int irq, struct irqaction *action, int ret),
66247+ TP_PROTO(int irq, const struct irqaction *action, int ret),
66248
66249 TP_ARGS(irq, action, ret),
66250
66251diff -urNp linux-2.6.39.1/include/video/udlfb.h linux-2.6.39.1/include/video/udlfb.h
66252--- linux-2.6.39.1/include/video/udlfb.h 2011-05-19 00:06:34.000000000 -0400
66253+++ linux-2.6.39.1/include/video/udlfb.h 2011-05-22 19:36:33.000000000 -0400
66254@@ -51,10 +51,10 @@ struct dlfb_data {
66255 int base8;
66256 u32 pseudo_palette[256];
66257 /* blit-only rendering path metrics, exposed through sysfs */
66258- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66259- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66260- atomic_t bytes_sent; /* to usb, after compression including overhead */
66261- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66262+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66263+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66264+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66265+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66266 };
66267
66268 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66269diff -urNp linux-2.6.39.1/include/video/uvesafb.h linux-2.6.39.1/include/video/uvesafb.h
66270--- linux-2.6.39.1/include/video/uvesafb.h 2011-05-19 00:06:34.000000000 -0400
66271+++ linux-2.6.39.1/include/video/uvesafb.h 2011-05-22 19:36:33.000000000 -0400
66272@@ -177,6 +177,7 @@ struct uvesafb_par {
66273 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66274 u8 pmi_setpal; /* PMI for palette changes */
66275 u16 *pmi_base; /* protected mode interface location */
66276+ u8 *pmi_code; /* protected mode code location */
66277 void *pmi_start;
66278 void *pmi_pal;
66279 u8 *vbe_state_orig; /*
66280diff -urNp linux-2.6.39.1/init/do_mounts.c linux-2.6.39.1/init/do_mounts.c
66281--- linux-2.6.39.1/init/do_mounts.c 2011-05-19 00:06:34.000000000 -0400
66282+++ linux-2.6.39.1/init/do_mounts.c 2011-05-22 19:36:33.000000000 -0400
66283@@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
66284
66285 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66286 {
66287- int err = sys_mount(name, "/root", fs, flags, data);
66288+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
66289 if (err)
66290 return err;
66291
66292@@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
66293 va_start(args, fmt);
66294 vsprintf(buf, fmt, args);
66295 va_end(args);
66296- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66297+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66298 if (fd >= 0) {
66299 sys_ioctl(fd, FDEJECT, 0);
66300 sys_close(fd);
66301 }
66302 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66303- fd = sys_open("/dev/console", O_RDWR, 0);
66304+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66305 if (fd >= 0) {
66306 sys_ioctl(fd, TCGETS, (long)&termios);
66307 termios.c_lflag &= ~ICANON;
66308 sys_ioctl(fd, TCSETSF, (long)&termios);
66309- sys_read(fd, &c, 1);
66310+ sys_read(fd, (char __user *)&c, 1);
66311 termios.c_lflag |= ICANON;
66312 sys_ioctl(fd, TCSETSF, (long)&termios);
66313 sys_close(fd);
66314@@ -488,6 +488,6 @@ void __init prepare_namespace(void)
66315 mount_root();
66316 out:
66317 devtmpfs_mount("dev");
66318- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66319+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66320 sys_chroot((const char __user __force *)".");
66321 }
66322diff -urNp linux-2.6.39.1/init/do_mounts.h linux-2.6.39.1/init/do_mounts.h
66323--- linux-2.6.39.1/init/do_mounts.h 2011-05-19 00:06:34.000000000 -0400
66324+++ linux-2.6.39.1/init/do_mounts.h 2011-05-22 19:36:33.000000000 -0400
66325@@ -15,15 +15,15 @@ extern int root_mountflags;
66326
66327 static inline int create_dev(char *name, dev_t dev)
66328 {
66329- sys_unlink(name);
66330- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66331+ sys_unlink((__force char __user *)name);
66332+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
66333 }
66334
66335 #if BITS_PER_LONG == 32
66336 static inline u32 bstat(char *name)
66337 {
66338 struct stat64 stat;
66339- if (sys_stat64(name, &stat) != 0)
66340+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
66341 return 0;
66342 if (!S_ISBLK(stat.st_mode))
66343 return 0;
66344diff -urNp linux-2.6.39.1/init/do_mounts_initrd.c linux-2.6.39.1/init/do_mounts_initrd.c
66345--- linux-2.6.39.1/init/do_mounts_initrd.c 2011-05-19 00:06:34.000000000 -0400
66346+++ linux-2.6.39.1/init/do_mounts_initrd.c 2011-05-22 19:36:33.000000000 -0400
66347@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
66348 create_dev("/dev/root.old", Root_RAM0);
66349 /* mount initrd on rootfs' /root */
66350 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66351- sys_mkdir("/old", 0700);
66352- root_fd = sys_open("/", 0, 0);
66353- old_fd = sys_open("/old", 0, 0);
66354+ sys_mkdir((__force const char __user *)"/old", 0700);
66355+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
66356+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
66357 /* move initrd over / and chdir/chroot in initrd root */
66358- sys_chdir("/root");
66359- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66360- sys_chroot(".");
66361+ sys_chdir((__force const char __user *)"/root");
66362+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66363+ sys_chroot((__force const char __user *)".");
66364
66365 /*
66366 * In case that a resume from disk is carried out by linuxrc or one of
66367@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
66368
66369 /* move initrd to rootfs' /old */
66370 sys_fchdir(old_fd);
66371- sys_mount("/", ".", NULL, MS_MOVE, NULL);
66372+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
66373 /* switch root and cwd back to / of rootfs */
66374 sys_fchdir(root_fd);
66375- sys_chroot(".");
66376+ sys_chroot((__force const char __user *)".");
66377 sys_close(old_fd);
66378 sys_close(root_fd);
66379
66380 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66381- sys_chdir("/old");
66382+ sys_chdir((__force const char __user *)"/old");
66383 return;
66384 }
66385
66386@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
66387 mount_root();
66388
66389 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66390- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66391+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
66392 if (!error)
66393 printk("okay\n");
66394 else {
66395- int fd = sys_open("/dev/root.old", O_RDWR, 0);
66396+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
66397 if (error == -ENOENT)
66398 printk("/initrd does not exist. Ignored.\n");
66399 else
66400 printk("failed\n");
66401 printk(KERN_NOTICE "Unmounting old root\n");
66402- sys_umount("/old", MNT_DETACH);
66403+ sys_umount((__force char __user *)"/old", MNT_DETACH);
66404 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66405 if (fd < 0) {
66406 error = fd;
66407@@ -116,11 +116,11 @@ int __init initrd_load(void)
66408 * mounted in the normal path.
66409 */
66410 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66411- sys_unlink("/initrd.image");
66412+ sys_unlink((__force const char __user *)"/initrd.image");
66413 handle_initrd();
66414 return 1;
66415 }
66416 }
66417- sys_unlink("/initrd.image");
66418+ sys_unlink((__force const char __user *)"/initrd.image");
66419 return 0;
66420 }
66421diff -urNp linux-2.6.39.1/init/do_mounts_md.c linux-2.6.39.1/init/do_mounts_md.c
66422--- linux-2.6.39.1/init/do_mounts_md.c 2011-05-19 00:06:34.000000000 -0400
66423+++ linux-2.6.39.1/init/do_mounts_md.c 2011-05-22 19:36:33.000000000 -0400
66424@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66425 partitioned ? "_d" : "", minor,
66426 md_setup_args[ent].device_names);
66427
66428- fd = sys_open(name, 0, 0);
66429+ fd = sys_open((__force char __user *)name, 0, 0);
66430 if (fd < 0) {
66431 printk(KERN_ERR "md: open failed - cannot start "
66432 "array %s\n", name);
66433@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66434 * array without it
66435 */
66436 sys_close(fd);
66437- fd = sys_open(name, 0, 0);
66438+ fd = sys_open((__force char __user *)name, 0, 0);
66439 sys_ioctl(fd, BLKRRPART, 0);
66440 }
66441 sys_close(fd);
66442diff -urNp linux-2.6.39.1/init/initramfs.c linux-2.6.39.1/init/initramfs.c
66443--- linux-2.6.39.1/init/initramfs.c 2011-05-19 00:06:34.000000000 -0400
66444+++ linux-2.6.39.1/init/initramfs.c 2011-05-22 19:36:33.000000000 -0400
66445@@ -74,7 +74,7 @@ static void __init free_hash(void)
66446 }
66447 }
66448
66449-static long __init do_utime(char __user *filename, time_t mtime)
66450+static long __init do_utime(__force char __user *filename, time_t mtime)
66451 {
66452 struct timespec t[2];
66453
66454@@ -109,7 +109,7 @@ static void __init dir_utime(void)
66455 struct dir_entry *de, *tmp;
66456 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66457 list_del(&de->list);
66458- do_utime(de->name, de->mtime);
66459+ do_utime((__force char __user *)de->name, de->mtime);
66460 kfree(de->name);
66461 kfree(de);
66462 }
66463@@ -271,7 +271,7 @@ static int __init maybe_link(void)
66464 if (nlink >= 2) {
66465 char *old = find_link(major, minor, ino, mode, collected);
66466 if (old)
66467- return (sys_link(old, collected) < 0) ? -1 : 1;
66468+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
66469 }
66470 return 0;
66471 }
66472@@ -280,11 +280,11 @@ static void __init clean_path(char *path
66473 {
66474 struct stat st;
66475
66476- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66477+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
66478 if (S_ISDIR(st.st_mode))
66479- sys_rmdir(path);
66480+ sys_rmdir((__force char __user *)path);
66481 else
66482- sys_unlink(path);
66483+ sys_unlink((__force char __user *)path);
66484 }
66485 }
66486
66487@@ -305,7 +305,7 @@ static int __init do_name(void)
66488 int openflags = O_WRONLY|O_CREAT;
66489 if (ml != 1)
66490 openflags |= O_TRUNC;
66491- wfd = sys_open(collected, openflags, mode);
66492+ wfd = sys_open((__force char __user *)collected, openflags, mode);
66493
66494 if (wfd >= 0) {
66495 sys_fchown(wfd, uid, gid);
66496@@ -317,17 +317,17 @@ static int __init do_name(void)
66497 }
66498 }
66499 } else if (S_ISDIR(mode)) {
66500- sys_mkdir(collected, mode);
66501- sys_chown(collected, uid, gid);
66502- sys_chmod(collected, mode);
66503+ sys_mkdir((__force char __user *)collected, mode);
66504+ sys_chown((__force char __user *)collected, uid, gid);
66505+ sys_chmod((__force char __user *)collected, mode);
66506 dir_add(collected, mtime);
66507 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66508 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66509 if (maybe_link() == 0) {
66510- sys_mknod(collected, mode, rdev);
66511- sys_chown(collected, uid, gid);
66512- sys_chmod(collected, mode);
66513- do_utime(collected, mtime);
66514+ sys_mknod((__force char __user *)collected, mode, rdev);
66515+ sys_chown((__force char __user *)collected, uid, gid);
66516+ sys_chmod((__force char __user *)collected, mode);
66517+ do_utime((__force char __user *)collected, mtime);
66518 }
66519 }
66520 return 0;
66521@@ -336,15 +336,15 @@ static int __init do_name(void)
66522 static int __init do_copy(void)
66523 {
66524 if (count >= body_len) {
66525- sys_write(wfd, victim, body_len);
66526+ sys_write(wfd, (__force char __user *)victim, body_len);
66527 sys_close(wfd);
66528- do_utime(vcollected, mtime);
66529+ do_utime((__force char __user *)vcollected, mtime);
66530 kfree(vcollected);
66531 eat(body_len);
66532 state = SkipIt;
66533 return 0;
66534 } else {
66535- sys_write(wfd, victim, count);
66536+ sys_write(wfd, (__force char __user *)victim, count);
66537 body_len -= count;
66538 eat(count);
66539 return 1;
66540@@ -355,9 +355,9 @@ static int __init do_symlink(void)
66541 {
66542 collected[N_ALIGN(name_len) + body_len] = '\0';
66543 clean_path(collected, 0);
66544- sys_symlink(collected + N_ALIGN(name_len), collected);
66545- sys_lchown(collected, uid, gid);
66546- do_utime(collected, mtime);
66547+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
66548+ sys_lchown((__force char __user *)collected, uid, gid);
66549+ do_utime((__force char __user *)collected, mtime);
66550 state = SkipIt;
66551 next_state = Reset;
66552 return 0;
66553diff -urNp linux-2.6.39.1/init/Kconfig linux-2.6.39.1/init/Kconfig
66554--- linux-2.6.39.1/init/Kconfig 2011-05-19 00:06:34.000000000 -0400
66555+++ linux-2.6.39.1/init/Kconfig 2011-05-22 19:36:33.000000000 -0400
66556@@ -1202,7 +1202,7 @@ config SLUB_DEBUG
66557
66558 config COMPAT_BRK
66559 bool "Disable heap randomization"
66560- default y
66561+ default n
66562 help
66563 Randomizing heap placement makes heap exploits harder, but it
66564 also breaks ancient binaries (including anything libc5 based).
66565diff -urNp linux-2.6.39.1/init/main.c linux-2.6.39.1/init/main.c
66566--- linux-2.6.39.1/init/main.c 2011-06-03 00:04:14.000000000 -0400
66567+++ linux-2.6.39.1/init/main.c 2011-06-03 00:32:08.000000000 -0400
66568@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
66569 extern void tc_init(void);
66570 #endif
66571
66572+extern void grsecurity_init(void);
66573+
66574 /*
66575 * Debug helper: via this flag we know that we are in 'early bootup code'
66576 * where only the boot processor is running with IRQ disabled. This means
66577@@ -149,6 +151,49 @@ static int __init set_reset_devices(char
66578
66579 __setup("reset_devices", set_reset_devices);
66580
66581+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66582+extern char pax_enter_kernel_user[];
66583+extern char pax_exit_kernel_user[];
66584+extern pgdval_t clone_pgd_mask;
66585+#endif
66586+
66587+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66588+static int __init setup_pax_nouderef(char *str)
66589+{
66590+#ifdef CONFIG_X86_32
66591+ unsigned int cpu;
66592+ struct desc_struct *gdt;
66593+
66594+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
66595+ gdt = get_cpu_gdt_table(cpu);
66596+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66597+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66598+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66599+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66600+ }
66601+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66602+#else
66603+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66604+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66605+ clone_pgd_mask = ~(pgdval_t)0UL;
66606+#endif
66607+
66608+ return 0;
66609+}
66610+early_param("pax_nouderef", setup_pax_nouderef);
66611+#endif
66612+
66613+#ifdef CONFIG_PAX_SOFTMODE
66614+unsigned int pax_softmode;
66615+
66616+static int __init setup_pax_softmode(char *str)
66617+{
66618+ get_option(&str, &pax_softmode);
66619+ return 1;
66620+}
66621+__setup("pax_softmode=", setup_pax_softmode);
66622+#endif
66623+
66624 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66625 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66626 static const char *panic_later, *panic_param;
66627@@ -663,6 +708,7 @@ int __init_or_module do_one_initcall(ini
66628 {
66629 int count = preempt_count();
66630 int ret;
66631+ const char *msg1 = "", *msg2 = "";
66632
66633 if (initcall_debug)
66634 ret = do_one_initcall_debug(fn);
66635@@ -675,15 +721,15 @@ int __init_or_module do_one_initcall(ini
66636 sprintf(msgbuf, "error code %d ", ret);
66637
66638 if (preempt_count() != count) {
66639- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66640+ msg1 = " preemption imbalance";
66641 preempt_count() = count;
66642 }
66643 if (irqs_disabled()) {
66644- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66645+ msg2 = " disabled interrupts";
66646 local_irq_enable();
66647 }
66648- if (msgbuf[0]) {
66649- printk("initcall %pF returned with %s\n", fn, msgbuf);
66650+ if (msgbuf[0] || *msg1 || *msg2) {
66651+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66652 }
66653
66654 return ret;
66655@@ -801,7 +847,7 @@ static int __init kernel_init(void * unu
66656 do_basic_setup();
66657
66658 /* Open the /dev/console on the rootfs, this should never fail */
66659- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66660+ if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
66661 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66662
66663 (void) sys_dup(0);
66664@@ -814,11 +860,13 @@ static int __init kernel_init(void * unu
66665 if (!ramdisk_execute_command)
66666 ramdisk_execute_command = "/init";
66667
66668- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66669+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
66670 ramdisk_execute_command = NULL;
66671 prepare_namespace();
66672 }
66673
66674+ grsecurity_init();
66675+
66676 /*
66677 * Ok, we have completed the initial bootup, and
66678 * we're essentially up and running. Get rid of the
66679diff -urNp linux-2.6.39.1/ipc/mqueue.c linux-2.6.39.1/ipc/mqueue.c
66680--- linux-2.6.39.1/ipc/mqueue.c 2011-05-19 00:06:34.000000000 -0400
66681+++ linux-2.6.39.1/ipc/mqueue.c 2011-05-22 19:41:42.000000000 -0400
66682@@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
66683 mq_bytes = (mq_msg_tblsz +
66684 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66685
66686+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66687 spin_lock(&mq_lock);
66688 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66689 u->mq_bytes + mq_bytes >
66690diff -urNp linux-2.6.39.1/ipc/sem.c linux-2.6.39.1/ipc/sem.c
66691--- linux-2.6.39.1/ipc/sem.c 2011-05-19 00:06:34.000000000 -0400
66692+++ linux-2.6.39.1/ipc/sem.c 2011-05-22 19:36:33.000000000 -0400
66693@@ -854,6 +854,8 @@ static int semctl_main(struct ipc_namesp
66694 int nsems;
66695 struct list_head tasks;
66696
66697+ pax_track_stack();
66698+
66699 sma = sem_lock_check(ns, semid);
66700 if (IS_ERR(sma))
66701 return PTR_ERR(sma);
66702@@ -1301,6 +1303,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
66703 struct ipc_namespace *ns;
66704 struct list_head tasks;
66705
66706+ pax_track_stack();
66707+
66708 ns = current->nsproxy->ipc_ns;
66709
66710 if (nsops < 1 || semid < 0)
66711diff -urNp linux-2.6.39.1/ipc/shm.c linux-2.6.39.1/ipc/shm.c
66712--- linux-2.6.39.1/ipc/shm.c 2011-05-19 00:06:34.000000000 -0400
66713+++ linux-2.6.39.1/ipc/shm.c 2011-05-22 19:41:42.000000000 -0400
66714@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
66715 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66716 #endif
66717
66718+#ifdef CONFIG_GRKERNSEC
66719+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66720+ const time_t shm_createtime, const uid_t cuid,
66721+ const int shmid);
66722+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66723+ const time_t shm_createtime);
66724+#endif
66725+
66726 void shm_init_ns(struct ipc_namespace *ns)
66727 {
66728 ns->shm_ctlmax = SHMMAX;
66729@@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
66730 shp->shm_lprid = 0;
66731 shp->shm_atim = shp->shm_dtim = 0;
66732 shp->shm_ctim = get_seconds();
66733+#ifdef CONFIG_GRKERNSEC
66734+ {
66735+ struct timespec timeval;
66736+ do_posix_clock_monotonic_gettime(&timeval);
66737+
66738+ shp->shm_createtime = timeval.tv_sec;
66739+ }
66740+#endif
66741 shp->shm_segsz = size;
66742 shp->shm_nattch = 0;
66743 shp->shm_file = file;
66744@@ -762,8 +778,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
66745 case SHM_LOCK:
66746 case SHM_UNLOCK:
66747 {
66748- struct file *uninitialized_var(shm_file);
66749-
66750 lru_add_drain_all(); /* drain pagevecs to lru lists */
66751
66752 shp = shm_lock_check(ns, shmid);
66753@@ -896,9 +910,21 @@ long do_shmat(int shmid, char __user *sh
66754 if (err)
66755 goto out_unlock;
66756
66757+#ifdef CONFIG_GRKERNSEC
66758+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66759+ shp->shm_perm.cuid, shmid) ||
66760+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66761+ err = -EACCES;
66762+ goto out_unlock;
66763+ }
66764+#endif
66765+
66766 path = shp->shm_file->f_path;
66767 path_get(&path);
66768 shp->shm_nattch++;
66769+#ifdef CONFIG_GRKERNSEC
66770+ shp->shm_lapid = current->pid;
66771+#endif
66772 size = i_size_read(path.dentry->d_inode);
66773 shm_unlock(shp);
66774
66775diff -urNp linux-2.6.39.1/kernel/acct.c linux-2.6.39.1/kernel/acct.c
66776--- linux-2.6.39.1/kernel/acct.c 2011-05-19 00:06:34.000000000 -0400
66777+++ linux-2.6.39.1/kernel/acct.c 2011-05-22 19:36:33.000000000 -0400
66778@@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
66779 */
66780 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66781 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66782- file->f_op->write(file, (char *)&ac,
66783+ file->f_op->write(file, (__force char __user *)&ac,
66784 sizeof(acct_t), &file->f_pos);
66785 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66786 set_fs(fs);
66787diff -urNp linux-2.6.39.1/kernel/audit.c linux-2.6.39.1/kernel/audit.c
66788--- linux-2.6.39.1/kernel/audit.c 2011-05-19 00:06:34.000000000 -0400
66789+++ linux-2.6.39.1/kernel/audit.c 2011-05-22 19:36:33.000000000 -0400
66790@@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
66791 3) suppressed due to audit_rate_limit
66792 4) suppressed due to audit_backlog_limit
66793 */
66794-static atomic_t audit_lost = ATOMIC_INIT(0);
66795+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66796
66797 /* The netlink socket. */
66798 static struct sock *audit_sock;
66799@@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
66800 unsigned long now;
66801 int print;
66802
66803- atomic_inc(&audit_lost);
66804+ atomic_inc_unchecked(&audit_lost);
66805
66806 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66807
66808@@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
66809 printk(KERN_WARNING
66810 "audit: audit_lost=%d audit_rate_limit=%d "
66811 "audit_backlog_limit=%d\n",
66812- atomic_read(&audit_lost),
66813+ atomic_read_unchecked(&audit_lost),
66814 audit_rate_limit,
66815 audit_backlog_limit);
66816 audit_panic(message);
66817@@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
66818 status_set.pid = audit_pid;
66819 status_set.rate_limit = audit_rate_limit;
66820 status_set.backlog_limit = audit_backlog_limit;
66821- status_set.lost = atomic_read(&audit_lost);
66822+ status_set.lost = atomic_read_unchecked(&audit_lost);
66823 status_set.backlog = skb_queue_len(&audit_skb_queue);
66824 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66825 &status_set, sizeof(status_set));
66826diff -urNp linux-2.6.39.1/kernel/auditsc.c linux-2.6.39.1/kernel/auditsc.c
66827--- linux-2.6.39.1/kernel/auditsc.c 2011-05-19 00:06:34.000000000 -0400
66828+++ linux-2.6.39.1/kernel/auditsc.c 2011-05-22 19:36:33.000000000 -0400
66829@@ -2111,7 +2111,7 @@ int auditsc_get_stamp(struct audit_conte
66830 }
66831
66832 /* global counter which is incremented every time something logs in */
66833-static atomic_t session_id = ATOMIC_INIT(0);
66834+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66835
66836 /**
66837 * audit_set_loginuid - set a task's audit_context loginuid
66838@@ -2124,7 +2124,7 @@ static atomic_t session_id = ATOMIC_INIT
66839 */
66840 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
66841 {
66842- unsigned int sessionid = atomic_inc_return(&session_id);
66843+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
66844 struct audit_context *context = task->audit_context;
66845
66846 if (context && context->in_syscall) {
66847diff -urNp linux-2.6.39.1/kernel/capability.c linux-2.6.39.1/kernel/capability.c
66848--- linux-2.6.39.1/kernel/capability.c 2011-05-19 00:06:34.000000000 -0400
66849+++ linux-2.6.39.1/kernel/capability.c 2011-05-22 21:02:23.000000000 -0400
66850@@ -206,6 +206,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
66851 * before modification is attempted and the application
66852 * fails.
66853 */
66854+ if (tocopy > ARRAY_SIZE(kdata))
66855+ return -EFAULT;
66856+
66857 if (copy_to_user(dataptr, kdata, tocopy
66858 * sizeof(struct __user_cap_data_struct))) {
66859 return -EFAULT;
66860@@ -378,7 +381,7 @@ bool ns_capable(struct user_namespace *n
66861 BUG();
66862 }
66863
66864- if (security_capable(ns, current_cred(), cap) == 0) {
66865+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
66866 current->flags |= PF_SUPERPRIV;
66867 return true;
66868 }
66869@@ -386,6 +389,27 @@ bool ns_capable(struct user_namespace *n
66870 }
66871 EXPORT_SYMBOL(ns_capable);
66872
66873+bool ns_capable_nolog(struct user_namespace *ns, int cap)
66874+{
66875+ if (unlikely(!cap_valid(cap))) {
66876+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66877+ BUG();
66878+ }
66879+
66880+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
66881+ current->flags |= PF_SUPERPRIV;
66882+ return true;
66883+ }
66884+ return false;
66885+}
66886+EXPORT_SYMBOL(ns_capable_nolog);
66887+
66888+bool capable_nolog(int cap)
66889+{
66890+ return ns_capable_nolog(&init_user_ns, cap);
66891+}
66892+EXPORT_SYMBOL(capable_nolog);
66893+
66894 /**
66895 * task_ns_capable - Determine whether current task has a superior
66896 * capability targeted at a specific task's user namespace.
66897@@ -400,6 +424,12 @@ bool task_ns_capable(struct task_struct
66898 }
66899 EXPORT_SYMBOL(task_ns_capable);
66900
66901+bool task_ns_capable_nolog(struct task_struct *t, int cap)
66902+{
66903+ return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
66904+}
66905+EXPORT_SYMBOL(task_ns_capable_nolog);
66906+
66907 /**
66908 * nsown_capable - Check superior capability to one's own user_ns
66909 * @cap: The capability in question
66910diff -urNp linux-2.6.39.1/kernel/cgroup.c linux-2.6.39.1/kernel/cgroup.c
66911--- linux-2.6.39.1/kernel/cgroup.c 2011-05-19 00:06:34.000000000 -0400
66912+++ linux-2.6.39.1/kernel/cgroup.c 2011-05-22 19:36:33.000000000 -0400
66913@@ -598,6 +598,8 @@ static struct css_set *find_css_set(
66914 struct hlist_head *hhead;
66915 struct cg_cgroup_link *link;
66916
66917+ pax_track_stack();
66918+
66919 /* First see if we already have a cgroup group that matches
66920 * the desired set */
66921 read_lock(&css_set_lock);
66922diff -urNp linux-2.6.39.1/kernel/compat.c linux-2.6.39.1/kernel/compat.c
66923--- linux-2.6.39.1/kernel/compat.c 2011-05-19 00:06:34.000000000 -0400
66924+++ linux-2.6.39.1/kernel/compat.c 2011-05-22 19:41:42.000000000 -0400
66925@@ -13,6 +13,7 @@
66926
66927 #include <linux/linkage.h>
66928 #include <linux/compat.h>
66929+#include <linux/module.h>
66930 #include <linux/errno.h>
66931 #include <linux/time.h>
66932 #include <linux/signal.h>
66933diff -urNp linux-2.6.39.1/kernel/configs.c linux-2.6.39.1/kernel/configs.c
66934--- linux-2.6.39.1/kernel/configs.c 2011-05-19 00:06:34.000000000 -0400
66935+++ linux-2.6.39.1/kernel/configs.c 2011-05-22 19:41:42.000000000 -0400
66936@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66937 struct proc_dir_entry *entry;
66938
66939 /* create the current config file */
66940+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66941+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66942+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66943+ &ikconfig_file_ops);
66944+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66945+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66946+ &ikconfig_file_ops);
66947+#endif
66948+#else
66949 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66950 &ikconfig_file_ops);
66951+#endif
66952+
66953 if (!entry)
66954 return -ENOMEM;
66955
66956diff -urNp linux-2.6.39.1/kernel/cred.c linux-2.6.39.1/kernel/cred.c
66957--- linux-2.6.39.1/kernel/cred.c 2011-05-19 00:06:34.000000000 -0400
66958+++ linux-2.6.39.1/kernel/cred.c 2011-05-22 19:41:42.000000000 -0400
66959@@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
66960 */
66961 void __put_cred(struct cred *cred)
66962 {
66963+ pax_track_stack();
66964+
66965 kdebug("__put_cred(%p{%d,%d})", cred,
66966 atomic_read(&cred->usage),
66967 read_cred_subscribers(cred));
66968@@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
66969 {
66970 struct cred *cred;
66971
66972+ pax_track_stack();
66973+
66974 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
66975 atomic_read(&tsk->cred->usage),
66976 read_cred_subscribers(tsk->cred));
66977@@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
66978 {
66979 const struct cred *cred;
66980
66981+ pax_track_stack();
66982+
66983 rcu_read_lock();
66984
66985 do {
66986@@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
66987 {
66988 struct cred *new;
66989
66990+ pax_track_stack();
66991+
66992 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
66993 if (!new)
66994 return NULL;
66995@@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
66996 const struct cred *old;
66997 struct cred *new;
66998
66999+ pax_track_stack();
67000+
67001 validate_process_creds();
67002
67003 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
67004@@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
67005 struct thread_group_cred *tgcred = NULL;
67006 struct cred *new;
67007
67008+ pax_track_stack();
67009+
67010 #ifdef CONFIG_KEYS
67011 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
67012 if (!tgcred)
67013@@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
67014 struct cred *new;
67015 int ret;
67016
67017+ pax_track_stack();
67018+
67019 if (
67020 #ifdef CONFIG_KEYS
67021 !p->cred->thread_keyring &&
67022@@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
67023 struct task_struct *task = current;
67024 const struct cred *old = task->real_cred;
67025
67026+ pax_track_stack();
67027+
67028 kdebug("commit_creds(%p{%d,%d})", new,
67029 atomic_read(&new->usage),
67030 read_cred_subscribers(new));
67031@@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
67032
67033 get_cred(new); /* we will require a ref for the subj creds too */
67034
67035+ gr_set_role_label(task, new->uid, new->gid);
67036+
67037 /* dumpability changes */
67038 if (old->euid != new->euid ||
67039 old->egid != new->egid ||
67040@@ -551,6 +569,8 @@ EXPORT_SYMBOL(commit_creds);
67041 */
67042 void abort_creds(struct cred *new)
67043 {
67044+ pax_track_stack();
67045+
67046 kdebug("abort_creds(%p{%d,%d})", new,
67047 atomic_read(&new->usage),
67048 read_cred_subscribers(new));
67049@@ -574,6 +594,8 @@ const struct cred *override_creds(const
67050 {
67051 const struct cred *old = current->cred;
67052
67053+ pax_track_stack();
67054+
67055 kdebug("override_creds(%p{%d,%d})", new,
67056 atomic_read(&new->usage),
67057 read_cred_subscribers(new));
67058@@ -603,6 +625,8 @@ void revert_creds(const struct cred *old
67059 {
67060 const struct cred *override = current->cred;
67061
67062+ pax_track_stack();
67063+
67064 kdebug("revert_creds(%p{%d,%d})", old,
67065 atomic_read(&old->usage),
67066 read_cred_subscribers(old));
67067@@ -649,6 +673,8 @@ struct cred *prepare_kernel_cred(struct
67068 const struct cred *old;
67069 struct cred *new;
67070
67071+ pax_track_stack();
67072+
67073 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
67074 if (!new)
67075 return NULL;
67076@@ -703,6 +729,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
67077 */
67078 int set_security_override(struct cred *new, u32 secid)
67079 {
67080+ pax_track_stack();
67081+
67082 return security_kernel_act_as(new, secid);
67083 }
67084 EXPORT_SYMBOL(set_security_override);
67085@@ -722,6 +750,8 @@ int set_security_override_from_ctx(struc
67086 u32 secid;
67087 int ret;
67088
67089+ pax_track_stack();
67090+
67091 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
67092 if (ret < 0)
67093 return ret;
67094diff -urNp linux-2.6.39.1/kernel/debug/debug_core.c linux-2.6.39.1/kernel/debug/debug_core.c
67095--- linux-2.6.39.1/kernel/debug/debug_core.c 2011-05-19 00:06:34.000000000 -0400
67096+++ linux-2.6.39.1/kernel/debug/debug_core.c 2011-05-22 19:36:33.000000000 -0400
67097@@ -72,7 +72,7 @@ int kgdb_io_module_registered;
67098 /* Guard for recursive entry */
67099 static int exception_level;
67100
67101-struct kgdb_io *dbg_io_ops;
67102+const struct kgdb_io *dbg_io_ops;
67103 static DEFINE_SPINLOCK(kgdb_registration_lock);
67104
67105 /* kgdb console driver is loaded */
67106@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
67107 */
67108 static atomic_t masters_in_kgdb;
67109 static atomic_t slaves_in_kgdb;
67110-static atomic_t kgdb_break_tasklet_var;
67111+static atomic_unchecked_t kgdb_break_tasklet_var;
67112 atomic_t kgdb_setting_breakpoint;
67113
67114 struct task_struct *kgdb_usethread;
67115@@ -129,7 +129,7 @@ int kgdb_single_step;
67116 static pid_t kgdb_sstep_pid;
67117
67118 /* to keep track of the CPU which is doing the single stepping*/
67119-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67120+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67121
67122 /*
67123 * If you are debugging a problem where roundup (the collection of
67124@@ -542,7 +542,7 @@ return_normal:
67125 * kernel will only try for the value of sstep_tries before
67126 * giving up and continuing on.
67127 */
67128- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67129+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67130 (kgdb_info[cpu].task &&
67131 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67132 atomic_set(&kgdb_active, -1);
67133@@ -636,8 +636,8 @@ cpu_master_loop:
67134 }
67135
67136 kgdb_restore:
67137- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67138- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67139+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67140+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67141 if (kgdb_info[sstep_cpu].task)
67142 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67143 else
67144@@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
67145 static void kgdb_tasklet_bpt(unsigned long ing)
67146 {
67147 kgdb_breakpoint();
67148- atomic_set(&kgdb_break_tasklet_var, 0);
67149+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67150 }
67151
67152 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67153
67154 void kgdb_schedule_breakpoint(void)
67155 {
67156- if (atomic_read(&kgdb_break_tasklet_var) ||
67157+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67158 atomic_read(&kgdb_active) != -1 ||
67159 atomic_read(&kgdb_setting_breakpoint))
67160 return;
67161- atomic_inc(&kgdb_break_tasklet_var);
67162+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
67163 tasklet_schedule(&kgdb_tasklet_breakpoint);
67164 }
67165 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67166@@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
67167 *
67168 * Register it with the KGDB core.
67169 */
67170-int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
67171+int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
67172 {
67173 int err;
67174
67175@@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
67176 *
67177 * Unregister it with the KGDB core.
67178 */
67179-void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
67180+void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
67181 {
67182 BUG_ON(kgdb_connected);
67183
67184diff -urNp linux-2.6.39.1/kernel/debug/kdb/kdb_main.c linux-2.6.39.1/kernel/debug/kdb/kdb_main.c
67185--- linux-2.6.39.1/kernel/debug/kdb/kdb_main.c 2011-05-19 00:06:34.000000000 -0400
67186+++ linux-2.6.39.1/kernel/debug/kdb/kdb_main.c 2011-05-22 19:36:33.000000000 -0400
67187@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
67188 list_for_each_entry(mod, kdb_modules, list) {
67189
67190 kdb_printf("%-20s%8u 0x%p ", mod->name,
67191- mod->core_size, (void *)mod);
67192+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
67193 #ifdef CONFIG_MODULE_UNLOAD
67194 kdb_printf("%4d ", module_refcount(mod));
67195 #endif
67196@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
67197 kdb_printf(" (Loading)");
67198 else
67199 kdb_printf(" (Live)");
67200- kdb_printf(" 0x%p", mod->module_core);
67201+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67202
67203 #ifdef CONFIG_MODULE_UNLOAD
67204 {
67205diff -urNp linux-2.6.39.1/kernel/exit.c linux-2.6.39.1/kernel/exit.c
67206--- linux-2.6.39.1/kernel/exit.c 2011-05-19 00:06:34.000000000 -0400
67207+++ linux-2.6.39.1/kernel/exit.c 2011-05-22 20:02:30.000000000 -0400
67208@@ -57,6 +57,10 @@
67209 #include <asm/pgtable.h>
67210 #include <asm/mmu_context.h>
67211
67212+#ifdef CONFIG_GRKERNSEC
67213+extern rwlock_t grsec_exec_file_lock;
67214+#endif
67215+
67216 static void exit_mm(struct task_struct * tsk);
67217
67218 static void __unhash_process(struct task_struct *p, bool group_dead)
67219@@ -169,6 +173,8 @@ void release_task(struct task_struct * p
67220 struct task_struct *leader;
67221 int zap_leader;
67222 repeat:
67223+ gr_del_task_from_ip_table(p);
67224+
67225 tracehook_prepare_release_task(p);
67226 /* don't need to get the RCU readlock here - the process is dead and
67227 * can't be modifying its own credentials. But shut RCU-lockdep up */
67228@@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
67229 {
67230 write_lock_irq(&tasklist_lock);
67231
67232+#ifdef CONFIG_GRKERNSEC
67233+ write_lock(&grsec_exec_file_lock);
67234+ if (current->exec_file) {
67235+ fput(current->exec_file);
67236+ current->exec_file = NULL;
67237+ }
67238+ write_unlock(&grsec_exec_file_lock);
67239+#endif
67240+
67241 ptrace_unlink(current);
67242 /* Reparent to init */
67243 current->real_parent = current->parent = kthreadd_task;
67244 list_move_tail(&current->sibling, &current->real_parent->children);
67245
67246+ gr_set_kernel_label(current);
67247+
67248 /* Set the exit signal to SIGCHLD so we signal init on exit */
67249 current->exit_signal = SIGCHLD;
67250
67251@@ -394,7 +411,7 @@ int allow_signal(int sig)
67252 * know it'll be handled, so that they don't get converted to
67253 * SIGKILL or just silently dropped.
67254 */
67255- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67256+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67257 recalc_sigpending();
67258 spin_unlock_irq(&current->sighand->siglock);
67259 return 0;
67260@@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
67261 vsnprintf(current->comm, sizeof(current->comm), name, args);
67262 va_end(args);
67263
67264+#ifdef CONFIG_GRKERNSEC
67265+ write_lock(&grsec_exec_file_lock);
67266+ if (current->exec_file) {
67267+ fput(current->exec_file);
67268+ current->exec_file = NULL;
67269+ }
67270+ write_unlock(&grsec_exec_file_lock);
67271+#endif
67272+
67273+ gr_set_kernel_label(current);
67274+
67275 /*
67276 * If we were started as result of loading a module, close all of the
67277 * user space pages. We don't need them, and if we didn't close them
67278@@ -905,15 +933,8 @@ NORET_TYPE void do_exit(long code)
67279 struct task_struct *tsk = current;
67280 int group_dead;
67281
67282- profile_task_exit(tsk);
67283-
67284- WARN_ON(atomic_read(&tsk->fs_excl));
67285- WARN_ON(blk_needs_flush_plug(tsk));
67286-
67287 if (unlikely(in_interrupt()))
67288 panic("Aiee, killing interrupt handler!");
67289- if (unlikely(!tsk->pid))
67290- panic("Attempted to kill the idle task!");
67291
67292 /*
67293 * If do_exit is called because this processes oopsed, it's possible
67294@@ -924,6 +945,14 @@ NORET_TYPE void do_exit(long code)
67295 */
67296 set_fs(USER_DS);
67297
67298+ profile_task_exit(tsk);
67299+
67300+ WARN_ON(atomic_read(&tsk->fs_excl));
67301+ WARN_ON(blk_needs_flush_plug(tsk));
67302+
67303+ if (unlikely(!tsk->pid))
67304+ panic("Attempted to kill the idle task!");
67305+
67306 tracehook_report_exit(&code);
67307
67308 validate_creds_for_do_exit(tsk);
67309@@ -984,6 +1013,9 @@ NORET_TYPE void do_exit(long code)
67310 tsk->exit_code = code;
67311 taskstats_exit(tsk, group_dead);
67312
67313+ gr_acl_handle_psacct(tsk, code);
67314+ gr_acl_handle_exit();
67315+
67316 exit_mm(tsk);
67317
67318 if (group_dead)
67319diff -urNp linux-2.6.39.1/kernel/fork.c linux-2.6.39.1/kernel/fork.c
67320--- linux-2.6.39.1/kernel/fork.c 2011-05-19 00:06:34.000000000 -0400
67321+++ linux-2.6.39.1/kernel/fork.c 2011-05-22 19:41:42.000000000 -0400
67322@@ -287,7 +287,7 @@ static struct task_struct *dup_task_stru
67323 *stackend = STACK_END_MAGIC; /* for overflow detection */
67324
67325 #ifdef CONFIG_CC_STACKPROTECTOR
67326- tsk->stack_canary = get_random_int();
67327+ tsk->stack_canary = pax_get_random_long();
67328 #endif
67329
67330 /* One for us, one for whoever does the "release_task()" (usually parent) */
67331@@ -309,13 +309,78 @@ out:
67332 }
67333
67334 #ifdef CONFIG_MMU
67335+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
67336+{
67337+ struct vm_area_struct *tmp;
67338+ unsigned long charge;
67339+ struct mempolicy *pol;
67340+ struct file *file;
67341+
67342+ charge = 0;
67343+ if (mpnt->vm_flags & VM_ACCOUNT) {
67344+ unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67345+ if (security_vm_enough_memory(len))
67346+ goto fail_nomem;
67347+ charge = len;
67348+ }
67349+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67350+ if (!tmp)
67351+ goto fail_nomem;
67352+ *tmp = *mpnt;
67353+ tmp->vm_mm = mm;
67354+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
67355+ pol = mpol_dup(vma_policy(mpnt));
67356+ if (IS_ERR(pol))
67357+ goto fail_nomem_policy;
67358+ vma_set_policy(tmp, pol);
67359+ if (anon_vma_fork(tmp, mpnt))
67360+ goto fail_nomem_anon_vma_fork;
67361+ tmp->vm_flags &= ~VM_LOCKED;
67362+ tmp->vm_next = tmp->vm_prev = NULL;
67363+ tmp->vm_mirror = NULL;
67364+ file = tmp->vm_file;
67365+ if (file) {
67366+ struct inode *inode = file->f_path.dentry->d_inode;
67367+ struct address_space *mapping = file->f_mapping;
67368+
67369+ get_file(file);
67370+ if (tmp->vm_flags & VM_DENYWRITE)
67371+ atomic_dec(&inode->i_writecount);
67372+ spin_lock(&mapping->i_mmap_lock);
67373+ if (tmp->vm_flags & VM_SHARED)
67374+ mapping->i_mmap_writable++;
67375+ tmp->vm_truncate_count = mpnt->vm_truncate_count;
67376+ flush_dcache_mmap_lock(mapping);
67377+ /* insert tmp into the share list, just after mpnt */
67378+ vma_prio_tree_add(tmp, mpnt);
67379+ flush_dcache_mmap_unlock(mapping);
67380+ spin_unlock(&mapping->i_mmap_lock);
67381+ }
67382+
67383+ /*
67384+ * Clear hugetlb-related page reserves for children. This only
67385+ * affects MAP_PRIVATE mappings. Faults generated by the child
67386+ * are not guaranteed to succeed, even if read-only
67387+ */
67388+ if (is_vm_hugetlb_page(tmp))
67389+ reset_vma_resv_huge_pages(tmp);
67390+
67391+ return tmp;
67392+
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+ vm_unacct_memory(charge);
67399+ return NULL;
67400+}
67401+
67402 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67403 {
67404 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67405 struct rb_node **rb_link, *rb_parent;
67406 int retval;
67407- unsigned long charge;
67408- struct mempolicy *pol;
67409
67410 down_write(&oldmm->mmap_sem);
67411 flush_cache_dup_mm(oldmm);
67412@@ -327,8 +392,8 @@ static int dup_mmap(struct mm_struct *mm
67413 mm->locked_vm = 0;
67414 mm->mmap = NULL;
67415 mm->mmap_cache = NULL;
67416- mm->free_area_cache = oldmm->mmap_base;
67417- mm->cached_hole_size = ~0UL;
67418+ mm->free_area_cache = oldmm->free_area_cache;
67419+ mm->cached_hole_size = oldmm->cached_hole_size;
67420 mm->map_count = 0;
67421 cpumask_clear(mm_cpumask(mm));
67422 mm->mm_rb = RB_ROOT;
67423@@ -344,8 +409,6 @@ static int dup_mmap(struct mm_struct *mm
67424
67425 prev = NULL;
67426 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67427- struct file *file;
67428-
67429 if (mpnt->vm_flags & VM_DONTCOPY) {
67430 long pages = vma_pages(mpnt);
67431 mm->total_vm -= pages;
67432@@ -353,56 +416,13 @@ static int dup_mmap(struct mm_struct *mm
67433 -pages);
67434 continue;
67435 }
67436- charge = 0;
67437- if (mpnt->vm_flags & VM_ACCOUNT) {
67438- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67439- if (security_vm_enough_memory(len))
67440- goto fail_nomem;
67441- charge = len;
67442- }
67443- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67444- if (!tmp)
67445- goto fail_nomem;
67446- *tmp = *mpnt;
67447- INIT_LIST_HEAD(&tmp->anon_vma_chain);
67448- pol = mpol_dup(vma_policy(mpnt));
67449- retval = PTR_ERR(pol);
67450- if (IS_ERR(pol))
67451- goto fail_nomem_policy;
67452- vma_set_policy(tmp, pol);
67453- tmp->vm_mm = mm;
67454- if (anon_vma_fork(tmp, mpnt))
67455- goto fail_nomem_anon_vma_fork;
67456- tmp->vm_flags &= ~VM_LOCKED;
67457- tmp->vm_next = tmp->vm_prev = NULL;
67458- file = tmp->vm_file;
67459- if (file) {
67460- struct inode *inode = file->f_path.dentry->d_inode;
67461- struct address_space *mapping = file->f_mapping;
67462-
67463- get_file(file);
67464- if (tmp->vm_flags & VM_DENYWRITE)
67465- atomic_dec(&inode->i_writecount);
67466- spin_lock(&mapping->i_mmap_lock);
67467- if (tmp->vm_flags & VM_SHARED)
67468- mapping->i_mmap_writable++;
67469- tmp->vm_truncate_count = mpnt->vm_truncate_count;
67470- flush_dcache_mmap_lock(mapping);
67471- /* insert tmp into the share list, just after mpnt */
67472- vma_prio_tree_add(tmp, mpnt);
67473- flush_dcache_mmap_unlock(mapping);
67474- spin_unlock(&mapping->i_mmap_lock);
67475+ tmp = dup_vma(mm, mpnt);
67476+ if (!tmp) {
67477+ retval = -ENOMEM;
67478+ goto out;
67479 }
67480
67481 /*
67482- * Clear hugetlb-related page reserves for children. This only
67483- * affects MAP_PRIVATE mappings. Faults generated by the child
67484- * are not guaranteed to succeed, even if read-only
67485- */
67486- if (is_vm_hugetlb_page(tmp))
67487- reset_vma_resv_huge_pages(tmp);
67488-
67489- /*
67490 * Link in the new vma and copy the page table entries.
67491 */
67492 *pprev = tmp;
67493@@ -423,6 +443,31 @@ static int dup_mmap(struct mm_struct *mm
67494 if (retval)
67495 goto out;
67496 }
67497+
67498+#ifdef CONFIG_PAX_SEGMEXEC
67499+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67500+ struct vm_area_struct *mpnt_m;
67501+
67502+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67503+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67504+
67505+ if (!mpnt->vm_mirror)
67506+ continue;
67507+
67508+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67509+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67510+ mpnt->vm_mirror = mpnt_m;
67511+ } else {
67512+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67513+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67514+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67515+ mpnt->vm_mirror->vm_mirror = mpnt;
67516+ }
67517+ }
67518+ BUG_ON(mpnt_m);
67519+ }
67520+#endif
67521+
67522 /* a new mm has just been created */
67523 arch_dup_mmap(oldmm, mm);
67524 retval = 0;
67525@@ -431,14 +476,6 @@ out:
67526 flush_tlb_mm(oldmm);
67527 up_write(&oldmm->mmap_sem);
67528 return retval;
67529-fail_nomem_anon_vma_fork:
67530- mpol_put(pol);
67531-fail_nomem_policy:
67532- kmem_cache_free(vm_area_cachep, tmp);
67533-fail_nomem:
67534- retval = -ENOMEM;
67535- vm_unacct_memory(charge);
67536- goto out;
67537 }
67538
67539 static inline int mm_alloc_pgd(struct mm_struct * mm)
67540@@ -785,13 +822,14 @@ static int copy_fs(unsigned long clone_f
67541 spin_unlock(&fs->lock);
67542 return -EAGAIN;
67543 }
67544- fs->users++;
67545+ atomic_inc(&fs->users);
67546 spin_unlock(&fs->lock);
67547 return 0;
67548 }
67549 tsk->fs = copy_fs_struct(fs);
67550 if (!tsk->fs)
67551 return -ENOMEM;
67552+ gr_set_chroot_entries(tsk, &tsk->fs->root);
67553 return 0;
67554 }
67555
67556@@ -1049,10 +1087,13 @@ static struct task_struct *copy_process(
67557 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67558 #endif
67559 retval = -EAGAIN;
67560+
67561+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67562+
67563 if (atomic_read(&p->real_cred->user->processes) >=
67564 task_rlimit(p, RLIMIT_NPROC)) {
67565- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67566- p->real_cred->user != INIT_USER)
67567+ if (p->real_cred->user != INIT_USER &&
67568+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
67569 goto bad_fork_free;
67570 }
67571
67572@@ -1200,6 +1241,8 @@ static struct task_struct *copy_process(
67573 goto bad_fork_free_pid;
67574 }
67575
67576+ gr_copy_label(p);
67577+
67578 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67579 /*
67580 * Clear TID on mm_release()?
67581@@ -1360,6 +1403,8 @@ bad_fork_cleanup_count:
67582 bad_fork_free:
67583 free_task(p);
67584 fork_out:
67585+ gr_log_forkfail(retval);
67586+
67587 return ERR_PTR(retval);
67588 }
67589
67590@@ -1448,6 +1493,8 @@ long do_fork(unsigned long clone_flags,
67591 if (clone_flags & CLONE_PARENT_SETTID)
67592 put_user(nr, parent_tidptr);
67593
67594+ gr_handle_brute_check();
67595+
67596 if (clone_flags & CLONE_VFORK) {
67597 p->vfork_done = &vfork;
67598 init_completion(&vfork);
67599@@ -1549,7 +1596,7 @@ static int unshare_fs(unsigned long unsh
67600 return 0;
67601
67602 /* don't need lock here; in the worst case we'll do useless copy */
67603- if (fs->users == 1)
67604+ if (atomic_read(&fs->users) == 1)
67605 return 0;
67606
67607 *new_fsp = copy_fs_struct(fs);
67608@@ -1636,7 +1683,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
67609 fs = current->fs;
67610 spin_lock(&fs->lock);
67611 current->fs = new_fs;
67612- if (--fs->users)
67613+ gr_set_chroot_entries(current, &current->fs->root);
67614+ if (atomic_dec_return(&fs->users))
67615 new_fs = NULL;
67616 else
67617 new_fs = fs;
67618diff -urNp linux-2.6.39.1/kernel/futex.c linux-2.6.39.1/kernel/futex.c
67619--- linux-2.6.39.1/kernel/futex.c 2011-05-19 00:06:34.000000000 -0400
67620+++ linux-2.6.39.1/kernel/futex.c 2011-05-22 22:41:57.000000000 -0400
67621@@ -54,6 +54,7 @@
67622 #include <linux/mount.h>
67623 #include <linux/pagemap.h>
67624 #include <linux/syscalls.h>
67625+#include <linux/ptrace.h>
67626 #include <linux/signal.h>
67627 #include <linux/module.h>
67628 #include <linux/magic.h>
67629@@ -236,6 +237,11 @@ get_futex_key(u32 __user *uaddr, int fsh
67630 struct page *page, *page_head;
67631 int err;
67632
67633+#ifdef CONFIG_PAX_SEGMEXEC
67634+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67635+ return -EFAULT;
67636+#endif
67637+
67638 /*
67639 * The futex address must be "naturally" aligned.
67640 */
67641@@ -1833,6 +1839,8 @@ static int futex_wait(u32 __user *uaddr,
67642 struct futex_q q = futex_q_init;
67643 int ret;
67644
67645+ pax_track_stack();
67646+
67647 if (!bitset)
67648 return -EINVAL;
67649 q.bitset = bitset;
67650@@ -2229,6 +2237,8 @@ static int futex_wait_requeue_pi(u32 __u
67651 struct futex_q q = futex_q_init;
67652 int res, ret;
67653
67654+ pax_track_stack();
67655+
67656 if (!bitset)
67657 return -EINVAL;
67658
67659@@ -2401,7 +2411,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67660 {
67661 struct robust_list_head __user *head;
67662 unsigned long ret;
67663+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67664 const struct cred *cred = current_cred(), *pcred;
67665+#endif
67666
67667 if (!futex_cmpxchg_enabled)
67668 return -ENOSYS;
67669@@ -2417,6 +2429,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67670 if (!p)
67671 goto err_unlock;
67672 ret = -EPERM;
67673+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67674+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
67675+ goto err_unlock;
67676+#else
67677 pcred = __task_cred(p);
67678 /* If victim is in different user_ns, then uids are not
67679 comparable, so we must have CAP_SYS_PTRACE */
67680@@ -2431,6 +2447,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67681 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67682 goto err_unlock;
67683 ok:
67684+#endif
67685 head = p->robust_list;
67686 rcu_read_unlock();
67687 }
67688@@ -2682,6 +2699,7 @@ static int __init futex_init(void)
67689 {
67690 u32 curval;
67691 int i;
67692+ mm_segment_t oldfs;
67693
67694 /*
67695 * This will fail and we want it. Some arch implementations do
67696@@ -2693,8 +2711,11 @@ static int __init futex_init(void)
67697 * implementation, the non-functional ones will return
67698 * -ENOSYS.
67699 */
67700+ oldfs = get_fs();
67701+ set_fs(USER_DS);
67702 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67703 futex_cmpxchg_enabled = 1;
67704+ set_fs(oldfs);
67705
67706 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67707 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
67708diff -urNp linux-2.6.39.1/kernel/futex_compat.c linux-2.6.39.1/kernel/futex_compat.c
67709--- linux-2.6.39.1/kernel/futex_compat.c 2011-05-19 00:06:34.000000000 -0400
67710+++ linux-2.6.39.1/kernel/futex_compat.c 2011-05-22 22:42:09.000000000 -0400
67711@@ -10,6 +10,7 @@
67712 #include <linux/compat.h>
67713 #include <linux/nsproxy.h>
67714 #include <linux/futex.h>
67715+#include <linux/ptrace.h>
67716
67717 #include <asm/uaccess.h>
67718
67719@@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
67720 {
67721 struct compat_robust_list_head __user *head;
67722 unsigned long ret;
67723- const struct cred *cred = current_cred(), *pcred;
67724+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67725+ const struct cred *cred = current_cred();
67726+ const struct cred *pcred;
67727+#endif
67728
67729 if (!futex_cmpxchg_enabled)
67730 return -ENOSYS;
67731@@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
67732 if (!p)
67733 goto err_unlock;
67734 ret = -EPERM;
67735+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67736+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
67737+ goto err_unlock;
67738+#else
67739 pcred = __task_cred(p);
67740 /* If victim is in different user_ns, then uids are not
67741 comparable, so we must have CAP_SYS_PTRACE */
67742@@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
67743 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67744 goto err_unlock;
67745 ok:
67746+#endif
67747 head = p->compat_robust_list;
67748 rcu_read_unlock();
67749 }
67750diff -urNp linux-2.6.39.1/kernel/gcov/base.c linux-2.6.39.1/kernel/gcov/base.c
67751--- linux-2.6.39.1/kernel/gcov/base.c 2011-05-19 00:06:34.000000000 -0400
67752+++ linux-2.6.39.1/kernel/gcov/base.c 2011-05-22 19:36:33.000000000 -0400
67753@@ -102,11 +102,6 @@ void gcov_enable_events(void)
67754 }
67755
67756 #ifdef CONFIG_MODULES
67757-static inline int within(void *addr, void *start, unsigned long size)
67758-{
67759- return ((addr >= start) && (addr < start + size));
67760-}
67761-
67762 /* Update list and generate events when modules are unloaded. */
67763 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67764 void *data)
67765@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
67766 prev = NULL;
67767 /* Remove entries located in module from linked list. */
67768 for (info = gcov_info_head; info; info = info->next) {
67769- if (within(info, mod->module_core, mod->core_size)) {
67770+ if (within_module_core_rw((unsigned long)info, mod)) {
67771 if (prev)
67772 prev->next = info->next;
67773 else
67774diff -urNp linux-2.6.39.1/kernel/hrtimer.c linux-2.6.39.1/kernel/hrtimer.c
67775--- linux-2.6.39.1/kernel/hrtimer.c 2011-05-19 00:06:34.000000000 -0400
67776+++ linux-2.6.39.1/kernel/hrtimer.c 2011-05-22 19:36:33.000000000 -0400
67777@@ -1383,7 +1383,7 @@ void hrtimer_peek_ahead_timers(void)
67778 local_irq_restore(flags);
67779 }
67780
67781-static void run_hrtimer_softirq(struct softirq_action *h)
67782+static void run_hrtimer_softirq(void)
67783 {
67784 hrtimer_peek_ahead_timers();
67785 }
67786diff -urNp linux-2.6.39.1/kernel/irq/manage.c linux-2.6.39.1/kernel/irq/manage.c
67787--- linux-2.6.39.1/kernel/irq/manage.c 2011-05-19 00:06:34.000000000 -0400
67788+++ linux-2.6.39.1/kernel/irq/manage.c 2011-06-13 17:09:06.000000000 -0400
67789@@ -491,6 +491,9 @@ int irq_set_irq_wake(unsigned int irq, u
67790 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags);
67791 int ret = 0;
67792
67793+ if (!desc)
67794+ return -EINVAL;
67795+
67796 /* wakeup-capable irqs can be shared between drivers that
67797 * don't need to have the same sleep mode behaviors.
67798 */
67799diff -urNp linux-2.6.39.1/kernel/jump_label.c linux-2.6.39.1/kernel/jump_label.c
67800--- linux-2.6.39.1/kernel/jump_label.c 2011-05-19 00:06:34.000000000 -0400
67801+++ linux-2.6.39.1/kernel/jump_label.c 2011-05-22 19:36:33.000000000 -0400
67802@@ -49,6 +49,17 @@ void jump_label_unlock(void)
67803 mutex_unlock(&jump_label_mutex);
67804 }
67805
67806+static void jump_label_swap(void *a, void *b, int size)
67807+{
67808+ struct jump_entry t;
67809+
67810+ t = *(struct jump_entry *)a;
67811+ pax_open_kernel();
67812+ *(struct jump_entry *)a = *(struct jump_entry *)b;
67813+ *(struct jump_entry *)b = t;
67814+ pax_close_kernel();
67815+}
67816+
67817 static int jump_label_cmp(const void *a, const void *b)
67818 {
67819 const struct jump_entry *jea = a;
67820@@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
67821
67822 size = (((unsigned long)stop - (unsigned long)start)
67823 / sizeof(struct jump_entry));
67824- sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67825+ sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
67826 }
67827
67828 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
67829@@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
67830 count = e_module->nr_entries;
67831 iter = e_module->table;
67832 while (count--) {
67833- if (within_module_init(iter->code, mod))
67834+ if (within_module_init(iter->code, mod)) {
67835+ pax_open_kernel();
67836 iter->key = 0;
67837+ pax_close_kernel();
67838+ }
67839 iter++;
67840 }
67841 }
67842diff -urNp linux-2.6.39.1/kernel/kallsyms.c linux-2.6.39.1/kernel/kallsyms.c
67843--- linux-2.6.39.1/kernel/kallsyms.c 2011-05-19 00:06:34.000000000 -0400
67844+++ linux-2.6.39.1/kernel/kallsyms.c 2011-05-22 19:41:42.000000000 -0400
67845@@ -11,6 +11,9 @@
67846 * Changed the compression method from stem compression to "table lookup"
67847 * compression (see scripts/kallsyms.c for a more complete description)
67848 */
67849+#ifdef CONFIG_GRKERNSEC_HIDESYM
67850+#define __INCLUDED_BY_HIDESYM 1
67851+#endif
67852 #include <linux/kallsyms.h>
67853 #include <linux/module.h>
67854 #include <linux/init.h>
67855@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
67856
67857 static inline int is_kernel_inittext(unsigned long addr)
67858 {
67859+ if (system_state != SYSTEM_BOOTING)
67860+ return 0;
67861+
67862 if (addr >= (unsigned long)_sinittext
67863 && addr <= (unsigned long)_einittext)
67864 return 1;
67865 return 0;
67866 }
67867
67868+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67869+#ifdef CONFIG_MODULES
67870+static inline int is_module_text(unsigned long addr)
67871+{
67872+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67873+ return 1;
67874+
67875+ addr = ktla_ktva(addr);
67876+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67877+}
67878+#else
67879+static inline int is_module_text(unsigned long addr)
67880+{
67881+ return 0;
67882+}
67883+#endif
67884+#endif
67885+
67886 static inline int is_kernel_text(unsigned long addr)
67887 {
67888 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67889@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
67890
67891 static inline int is_kernel(unsigned long addr)
67892 {
67893+
67894+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67895+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67896+ return 1;
67897+
67898+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67899+#else
67900 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67901+#endif
67902+
67903 return 1;
67904 return in_gate_area_no_mm(addr);
67905 }
67906
67907 static int is_ksym_addr(unsigned long addr)
67908 {
67909+
67910+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67911+ if (is_module_text(addr))
67912+ return 0;
67913+#endif
67914+
67915 if (all_var)
67916 return is_kernel(addr);
67917
67918@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
67919
67920 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67921 {
67922- iter->name[0] = '\0';
67923 iter->nameoff = get_symbol_offset(new_pos);
67924 iter->pos = new_pos;
67925 }
67926@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
67927 {
67928 struct kallsym_iter *iter = m->private;
67929
67930+#ifdef CONFIG_GRKERNSEC_HIDESYM
67931+ if (current_uid())
67932+ return 0;
67933+#endif
67934+
67935 /* Some debugging symbols have no name. Ignore them. */
67936 if (!iter->name[0])
67937 return 0;
67938@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
67939 struct kallsym_iter *iter;
67940 int ret;
67941
67942- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67943+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67944 if (!iter)
67945 return -ENOMEM;
67946 reset_iter(iter, 0);
67947diff -urNp linux-2.6.39.1/kernel/kmod.c linux-2.6.39.1/kernel/kmod.c
67948--- linux-2.6.39.1/kernel/kmod.c 2011-05-19 00:06:34.000000000 -0400
67949+++ linux-2.6.39.1/kernel/kmod.c 2011-05-22 19:41:42.000000000 -0400
67950@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
67951 * If module auto-loading support is disabled then this function
67952 * becomes a no-operation.
67953 */
67954-int __request_module(bool wait, const char *fmt, ...)
67955+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67956 {
67957- va_list args;
67958 char module_name[MODULE_NAME_LEN];
67959 unsigned int max_modprobes;
67960 int ret;
67961- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67962+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67963 static char *envp[] = { "HOME=/",
67964 "TERM=linux",
67965 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67966@@ -80,9 +79,7 @@ int __request_module(bool wait, const ch
67967 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67968 static int kmod_loop_msg;
67969
67970- va_start(args, fmt);
67971- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67972- va_end(args);
67973+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67974 if (ret >= MODULE_NAME_LEN)
67975 return -ENAMETOOLONG;
67976
67977@@ -90,6 +87,20 @@ int __request_module(bool wait, const ch
67978 if (ret)
67979 return ret;
67980
67981+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67982+ if (!current_uid()) {
67983+ /* hack to workaround consolekit/udisks stupidity */
67984+ read_lock(&tasklist_lock);
67985+ if (!strcmp(current->comm, "mount") &&
67986+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67987+ read_unlock(&tasklist_lock);
67988+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67989+ return -EPERM;
67990+ }
67991+ read_unlock(&tasklist_lock);
67992+ }
67993+#endif
67994+
67995 /* If modprobe needs a service that is in a module, we get a recursive
67996 * loop. Limit the number of running kmod threads to max_threads/2 or
67997 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67998@@ -123,6 +134,47 @@ int __request_module(bool wait, const ch
67999 atomic_dec(&kmod_concurrent);
68000 return ret;
68001 }
68002+
68003+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68004+{
68005+ va_list args;
68006+ int ret;
68007+
68008+ va_start(args, fmt);
68009+ ret = ____request_module(wait, module_param, fmt, args);
68010+ va_end(args);
68011+
68012+ return ret;
68013+}
68014+
68015+int __request_module(bool wait, const char *fmt, ...)
68016+{
68017+ va_list args;
68018+ int ret;
68019+
68020+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68021+ if (current_uid()) {
68022+ char module_param[MODULE_NAME_LEN];
68023+
68024+ memset(module_param, 0, sizeof(module_param));
68025+
68026+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68027+
68028+ va_start(args, fmt);
68029+ ret = ____request_module(wait, module_param, fmt, args);
68030+ va_end(args);
68031+
68032+ return ret;
68033+ }
68034+#endif
68035+
68036+ va_start(args, fmt);
68037+ ret = ____request_module(wait, NULL, fmt, args);
68038+ va_end(args);
68039+
68040+ return ret;
68041+}
68042+
68043 EXPORT_SYMBOL(__request_module);
68044 #endif /* CONFIG_MODULES */
68045
68046diff -urNp linux-2.6.39.1/kernel/kprobes.c linux-2.6.39.1/kernel/kprobes.c
68047--- linux-2.6.39.1/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
68048+++ linux-2.6.39.1/kernel/kprobes.c 2011-05-22 19:36:33.000000000 -0400
68049@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
68050 * kernel image and loaded module images reside. This is required
68051 * so x86_64 can correctly handle the %rip-relative fixups.
68052 */
68053- kip->insns = module_alloc(PAGE_SIZE);
68054+ kip->insns = module_alloc_exec(PAGE_SIZE);
68055 if (!kip->insns) {
68056 kfree(kip);
68057 return NULL;
68058@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
68059 */
68060 if (!list_is_singular(&kip->list)) {
68061 list_del(&kip->list);
68062- module_free(NULL, kip->insns);
68063+ module_free_exec(NULL, kip->insns);
68064 kfree(kip);
68065 }
68066 return 1;
68067@@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
68068 {
68069 int i, err = 0;
68070 unsigned long offset = 0, size = 0;
68071- char *modname, namebuf[128];
68072+ char *modname, namebuf[KSYM_NAME_LEN];
68073 const char *symbol_name;
68074 void *addr;
68075 struct kprobe_blackpoint *kb;
68076@@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
68077 const char *sym = NULL;
68078 unsigned int i = *(loff_t *) v;
68079 unsigned long offset = 0;
68080- char *modname, namebuf[128];
68081+ char *modname, namebuf[KSYM_NAME_LEN];
68082
68083 head = &kprobe_table[i];
68084 preempt_disable();
68085diff -urNp linux-2.6.39.1/kernel/lockdep.c linux-2.6.39.1/kernel/lockdep.c
68086--- linux-2.6.39.1/kernel/lockdep.c 2011-05-19 00:06:34.000000000 -0400
68087+++ linux-2.6.39.1/kernel/lockdep.c 2011-05-22 19:36:33.000000000 -0400
68088@@ -571,6 +571,10 @@ static int static_obj(void *obj)
68089 end = (unsigned long) &_end,
68090 addr = (unsigned long) obj;
68091
68092+#ifdef CONFIG_PAX_KERNEXEC
68093+ start = ktla_ktva(start);
68094+#endif
68095+
68096 /*
68097 * static variable?
68098 */
68099@@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
68100 if (!static_obj(lock->key)) {
68101 debug_locks_off();
68102 printk("INFO: trying to register non-static key.\n");
68103+ printk("lock:%pS key:%pS.\n", lock, lock->key);
68104 printk("the code is fine but needs lockdep annotation.\n");
68105 printk("turning off the locking correctness validator.\n");
68106 dump_stack();
68107@@ -2752,7 +2757,7 @@ static int __lock_acquire(struct lockdep
68108 if (!class)
68109 return 0;
68110 }
68111- atomic_inc((atomic_t *)&class->ops);
68112+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68113 if (very_verbose(class)) {
68114 printk("\nacquire class [%p] %s", class->key, class->name);
68115 if (class->name_version > 1)
68116diff -urNp linux-2.6.39.1/kernel/lockdep_proc.c linux-2.6.39.1/kernel/lockdep_proc.c
68117--- linux-2.6.39.1/kernel/lockdep_proc.c 2011-05-19 00:06:34.000000000 -0400
68118+++ linux-2.6.39.1/kernel/lockdep_proc.c 2011-05-22 19:36:33.000000000 -0400
68119@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
68120
68121 static void print_name(struct seq_file *m, struct lock_class *class)
68122 {
68123- char str[128];
68124+ char str[KSYM_NAME_LEN];
68125 const char *name = class->name;
68126
68127 if (!name) {
68128diff -urNp linux-2.6.39.1/kernel/module.c linux-2.6.39.1/kernel/module.c
68129--- linux-2.6.39.1/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
68130+++ linux-2.6.39.1/kernel/module.c 2011-05-22 19:41:42.000000000 -0400
68131@@ -57,6 +57,7 @@
68132 #include <linux/kmemleak.h>
68133 #include <linux/jump_label.h>
68134 #include <linux/pfn.h>
68135+#include <linux/grsecurity.h>
68136
68137 #define CREATE_TRACE_POINTS
68138 #include <trace/events/module.h>
68139@@ -118,7 +119,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
68140
68141 /* Bounds of module allocation, for speeding __module_address.
68142 * Protected by module_mutex. */
68143-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68144+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68145+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68146
68147 int register_module_notifier(struct notifier_block * nb)
68148 {
68149@@ -282,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
68150 return true;
68151
68152 list_for_each_entry_rcu(mod, &modules, list) {
68153- struct symsearch arr[] = {
68154+ struct symsearch modarr[] = {
68155 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68156 NOT_GPL_ONLY, false },
68157 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68158@@ -304,7 +306,7 @@ bool each_symbol(bool (*fn)(const struct
68159 #endif
68160 };
68161
68162- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68163+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68164 return true;
68165 }
68166 return false;
68167@@ -415,7 +417,7 @@ static inline void __percpu *mod_percpu(
68168 static int percpu_modalloc(struct module *mod,
68169 unsigned long size, unsigned long align)
68170 {
68171- if (align > PAGE_SIZE) {
68172+ if (align-1 >= PAGE_SIZE) {
68173 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68174 mod->name, align, PAGE_SIZE);
68175 align = PAGE_SIZE;
68176@@ -1143,7 +1145,7 @@ resolve_symbol_wait(struct module *mod,
68177 */
68178 #ifdef CONFIG_SYSFS
68179
68180-#ifdef CONFIG_KALLSYMS
68181+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68182 static inline bool sect_empty(const Elf_Shdr *sect)
68183 {
68184 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68185@@ -1612,17 +1614,17 @@ void unset_section_ro_nx(struct module *
68186 {
68187 unsigned long total_pages;
68188
68189- if (mod->module_core == module_region) {
68190+ if (mod->module_core_rx == module_region) {
68191 /* Set core as NX+RW */
68192- total_pages = MOD_NUMBER_OF_PAGES(mod->module_core, mod->core_size);
68193- set_memory_nx((unsigned long)mod->module_core, total_pages);
68194- set_memory_rw((unsigned long)mod->module_core, total_pages);
68195+ total_pages = MOD_NUMBER_OF_PAGES(mod->module_core_rx, mod->core_size_rx);
68196+ set_memory_nx((unsigned long)mod->module_core_rx, total_pages);
68197+ set_memory_rw((unsigned long)mod->module_core_rx, total_pages);
68198
68199- } else if (mod->module_init == module_region) {
68200+ } else if (mod->module_init_rx == module_region) {
68201 /* Set init as NX+RW */
68202- total_pages = MOD_NUMBER_OF_PAGES(mod->module_init, mod->init_size);
68203- set_memory_nx((unsigned long)mod->module_init, total_pages);
68204- set_memory_rw((unsigned long)mod->module_init, total_pages);
68205+ total_pages = MOD_NUMBER_OF_PAGES(mod->module_init_rx, mod->init_size_rx);
68206+ set_memory_nx((unsigned long)mod->module_init_rx, total_pages);
68207+ set_memory_rw((unsigned long)mod->module_init_rx, total_pages);
68208 }
68209 }
68210
68211@@ -1633,14 +1635,14 @@ void set_all_modules_text_rw()
68212
68213 mutex_lock(&module_mutex);
68214 list_for_each_entry_rcu(mod, &modules, list) {
68215- if ((mod->module_core) && (mod->core_text_size)) {
68216- set_page_attributes(mod->module_core,
68217- mod->module_core + mod->core_text_size,
68218+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68219+ set_page_attributes(mod->module_core_rx,
68220+ mod->module_core_rx + mod->core_size_rx,
68221 set_memory_rw);
68222 }
68223- if ((mod->module_init) && (mod->init_text_size)) {
68224- set_page_attributes(mod->module_init,
68225- mod->module_init + mod->init_text_size,
68226+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68227+ set_page_attributes(mod->module_init_rx,
68228+ mod->module_init_rx + mod->init_size_rx,
68229 set_memory_rw);
68230 }
68231 }
68232@@ -1654,14 +1656,14 @@ void set_all_modules_text_ro()
68233
68234 mutex_lock(&module_mutex);
68235 list_for_each_entry_rcu(mod, &modules, list) {
68236- if ((mod->module_core) && (mod->core_text_size)) {
68237- set_page_attributes(mod->module_core,
68238- mod->module_core + mod->core_text_size,
68239+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68240+ set_page_attributes(mod->module_core_rx,
68241+ mod->module_core_rx + mod->core_size_rx,
68242 set_memory_ro);
68243 }
68244- if ((mod->module_init) && (mod->init_text_size)) {
68245- set_page_attributes(mod->module_init,
68246- mod->module_init + mod->init_text_size,
68247+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68248+ set_page_attributes(mod->module_init_rx,
68249+ mod->module_init_rx + mod->init_size_rx,
68250 set_memory_ro);
68251 }
68252 }
68253@@ -1696,17 +1698,20 @@ static void free_module(struct module *m
68254 destroy_params(mod->kp, mod->num_kp);
68255
68256 /* This may be NULL, but that's OK */
68257- unset_section_ro_nx(mod, mod->module_init);
68258- module_free(mod, mod->module_init);
68259+ unset_section_ro_nx(mod, mod->module_init_rx);
68260+ module_free(mod, mod->module_init_rw);
68261+ module_free_exec(mod, mod->module_init_rx);
68262 kfree(mod->args);
68263 percpu_modfree(mod);
68264
68265 /* Free lock-classes: */
68266- lockdep_free_key_range(mod->module_core, mod->core_size);
68267+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68268+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68269
68270 /* Finally, free the core (containing the module structure) */
68271- unset_section_ro_nx(mod, mod->module_core);
68272- module_free(mod, mod->module_core);
68273+ unset_section_ro_nx(mod, mod->module_core_rx);
68274+ module_free_exec(mod, mod->module_core_rx);
68275+ module_free(mod, mod->module_core_rw);
68276
68277 #ifdef CONFIG_MPU
68278 update_protections(current->mm);
68279@@ -1775,10 +1780,31 @@ static int simplify_symbols(struct modul
68280 unsigned int i;
68281 int ret = 0;
68282 const struct kernel_symbol *ksym;
68283+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68284+ int is_fs_load = 0;
68285+ int register_filesystem_found = 0;
68286+ char *p;
68287+
68288+ p = strstr(mod->args, "grsec_modharden_fs");
68289+ if (p) {
68290+ char *endptr = p + strlen("grsec_modharden_fs");
68291+ /* copy \0 as well */
68292+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68293+ is_fs_load = 1;
68294+ }
68295+#endif
68296
68297 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68298 const char *name = info->strtab + sym[i].st_name;
68299
68300+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68301+ /* it's a real shame this will never get ripped and copied
68302+ upstream! ;(
68303+ */
68304+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68305+ register_filesystem_found = 1;
68306+#endif
68307+
68308 switch (sym[i].st_shndx) {
68309 case SHN_COMMON:
68310 /* We compiled with -fno-common. These are not
68311@@ -1799,7 +1825,9 @@ static int simplify_symbols(struct modul
68312 ksym = resolve_symbol_wait(mod, info, name);
68313 /* Ok if resolved. */
68314 if (ksym && !IS_ERR(ksym)) {
68315+ pax_open_kernel();
68316 sym[i].st_value = ksym->value;
68317+ pax_close_kernel();
68318 break;
68319 }
68320
68321@@ -1818,11 +1846,20 @@ static int simplify_symbols(struct modul
68322 secbase = (unsigned long)mod_percpu(mod);
68323 else
68324 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68325+ pax_open_kernel();
68326 sym[i].st_value += secbase;
68327+ pax_close_kernel();
68328 break;
68329 }
68330 }
68331
68332+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68333+ if (is_fs_load && !register_filesystem_found) {
68334+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68335+ ret = -EPERM;
68336+ }
68337+#endif
68338+
68339 return ret;
68340 }
68341
68342@@ -1906,22 +1943,12 @@ static void layout_sections(struct modul
68343 || s->sh_entsize != ~0UL
68344 || strstarts(sname, ".init"))
68345 continue;
68346- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68347+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68348+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68349+ else
68350+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68351 DEBUGP("\t%s\n", name);
68352 }
68353- switch (m) {
68354- case 0: /* executable */
68355- mod->core_size = debug_align(mod->core_size);
68356- mod->core_text_size = mod->core_size;
68357- break;
68358- case 1: /* RO: text and ro-data */
68359- mod->core_size = debug_align(mod->core_size);
68360- mod->core_ro_size = mod->core_size;
68361- break;
68362- case 3: /* whole core */
68363- mod->core_size = debug_align(mod->core_size);
68364- break;
68365- }
68366 }
68367
68368 DEBUGP("Init section allocation order:\n");
68369@@ -1935,23 +1962,13 @@ static void layout_sections(struct modul
68370 || s->sh_entsize != ~0UL
68371 || !strstarts(sname, ".init"))
68372 continue;
68373- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68374- | INIT_OFFSET_MASK);
68375+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68376+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68377+ else
68378+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68379+ s->sh_entsize |= INIT_OFFSET_MASK;
68380 DEBUGP("\t%s\n", sname);
68381 }
68382- switch (m) {
68383- case 0: /* executable */
68384- mod->init_size = debug_align(mod->init_size);
68385- mod->init_text_size = mod->init_size;
68386- break;
68387- case 1: /* RO: text and ro-data */
68388- mod->init_size = debug_align(mod->init_size);
68389- mod->init_ro_size = mod->init_size;
68390- break;
68391- case 3: /* whole init */
68392- mod->init_size = debug_align(mod->init_size);
68393- break;
68394- }
68395 }
68396 }
68397
68398@@ -2119,7 +2136,7 @@ static void layout_symtab(struct module
68399
68400 /* Put symbol section at end of init part of module. */
68401 symsect->sh_flags |= SHF_ALLOC;
68402- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68403+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68404 info->index.sym) | INIT_OFFSET_MASK;
68405 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
68406
68407@@ -2136,19 +2153,19 @@ static void layout_symtab(struct module
68408 }
68409
68410 /* Append room for core symbols at end of core part. */
68411- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68412- mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68413+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68414+ mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68415
68416 /* Put string table section at end of init part of module. */
68417 strsect->sh_flags |= SHF_ALLOC;
68418- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68419+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68420 info->index.str) | INIT_OFFSET_MASK;
68421 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
68422
68423 /* Append room for core symbols' strings at end of core part. */
68424- info->stroffs = mod->core_size;
68425+ info->stroffs = mod->core_size_rx;
68426 __set_bit(0, info->strmap);
68427- mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
68428+ mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
68429 }
68430
68431 static void add_kallsyms(struct module *mod, const struct load_info *info)
68432@@ -2164,11 +2181,13 @@ static void add_kallsyms(struct module *
68433 /* Make sure we get permanent strtab: don't use info->strtab. */
68434 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68435
68436+ pax_open_kernel();
68437+
68438 /* Set types up while we still have access to sections. */
68439 for (i = 0; i < mod->num_symtab; i++)
68440 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68441
68442- mod->core_symtab = dst = mod->module_core + info->symoffs;
68443+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68444 src = mod->symtab;
68445 *dst = *src;
68446 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68447@@ -2181,10 +2200,12 @@ static void add_kallsyms(struct module *
68448 }
68449 mod->core_num_syms = ndst;
68450
68451- mod->core_strtab = s = mod->module_core + info->stroffs;
68452+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68453 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
68454 if (test_bit(i, info->strmap))
68455 *++s = mod->strtab[i];
68456+
68457+ pax_close_kernel();
68458 }
68459 #else
68460 static inline void layout_symtab(struct module *mod, struct load_info *info)
68461@@ -2213,17 +2234,33 @@ static void dynamic_debug_remove(struct
68462 ddebug_remove_module(debug->modname);
68463 }
68464
68465-static void *module_alloc_update_bounds(unsigned long size)
68466+static void *module_alloc_update_bounds_rw(unsigned long size)
68467 {
68468 void *ret = module_alloc(size);
68469
68470 if (ret) {
68471 mutex_lock(&module_mutex);
68472 /* Update module bounds. */
68473- if ((unsigned long)ret < module_addr_min)
68474- module_addr_min = (unsigned long)ret;
68475- if ((unsigned long)ret + size > module_addr_max)
68476- module_addr_max = (unsigned long)ret + size;
68477+ if ((unsigned long)ret < module_addr_min_rw)
68478+ module_addr_min_rw = (unsigned long)ret;
68479+ if ((unsigned long)ret + size > module_addr_max_rw)
68480+ module_addr_max_rw = (unsigned long)ret + size;
68481+ mutex_unlock(&module_mutex);
68482+ }
68483+ return ret;
68484+}
68485+
68486+static void *module_alloc_update_bounds_rx(unsigned long size)
68487+{
68488+ void *ret = module_alloc_exec(size);
68489+
68490+ if (ret) {
68491+ mutex_lock(&module_mutex);
68492+ /* Update module bounds. */
68493+ if ((unsigned long)ret < module_addr_min_rx)
68494+ module_addr_min_rx = (unsigned long)ret;
68495+ if ((unsigned long)ret + size > module_addr_max_rx)
68496+ module_addr_max_rx = (unsigned long)ret + size;
68497 mutex_unlock(&module_mutex);
68498 }
68499 return ret;
68500@@ -2516,7 +2553,7 @@ static int move_module(struct module *mo
68501 void *ptr;
68502
68503 /* Do the allocs. */
68504- ptr = module_alloc_update_bounds(mod->core_size);
68505+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68506 /*
68507 * The pointer to this block is stored in the module structure
68508 * which is inside the block. Just mark it as not being a
68509@@ -2526,23 +2563,50 @@ static int move_module(struct module *mo
68510 if (!ptr)
68511 return -ENOMEM;
68512
68513- memset(ptr, 0, mod->core_size);
68514- mod->module_core = ptr;
68515+ memset(ptr, 0, mod->core_size_rw);
68516+ mod->module_core_rw = ptr;
68517
68518- ptr = module_alloc_update_bounds(mod->init_size);
68519+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68520 /*
68521 * The pointer to this block is stored in the module structure
68522 * which is inside the block. This block doesn't need to be
68523 * scanned as it contains data and code that will be freed
68524 * after the module is initialized.
68525 */
68526- kmemleak_ignore(ptr);
68527- if (!ptr && mod->init_size) {
68528- module_free(mod, mod->module_core);
68529+ kmemleak_not_leak(ptr);
68530+ if (!ptr && mod->init_size_rw) {
68531+ module_free(mod, mod->module_core_rw);
68532 return -ENOMEM;
68533 }
68534- memset(ptr, 0, mod->init_size);
68535- mod->module_init = ptr;
68536+ memset(ptr, 0, mod->init_size_rw);
68537+ mod->module_init_rw = ptr;
68538+
68539+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68540+ kmemleak_not_leak(ptr);
68541+ if (!ptr) {
68542+ module_free(mod, mod->module_init_rw);
68543+ module_free(mod, mod->module_core_rw);
68544+ return -ENOMEM;
68545+ }
68546+
68547+ pax_open_kernel();
68548+ memset(ptr, 0, mod->core_size_rx);
68549+ pax_close_kernel();
68550+ mod->module_core_rx = ptr;
68551+
68552+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68553+ kmemleak_not_leak(ptr);
68554+ if (!ptr && mod->init_size_rx) {
68555+ module_free_exec(mod, mod->module_core_rx);
68556+ module_free(mod, mod->module_init_rw);
68557+ module_free(mod, mod->module_core_rw);
68558+ return -ENOMEM;
68559+ }
68560+
68561+ pax_open_kernel();
68562+ memset(ptr, 0, mod->init_size_rx);
68563+ pax_close_kernel();
68564+ mod->module_init_rx = ptr;
68565
68566 /* Transfer each section which specifies SHF_ALLOC */
68567 DEBUGP("final section addresses:\n");
68568@@ -2553,16 +2617,45 @@ static int move_module(struct module *mo
68569 if (!(shdr->sh_flags & SHF_ALLOC))
68570 continue;
68571
68572- if (shdr->sh_entsize & INIT_OFFSET_MASK)
68573- dest = mod->module_init
68574- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68575- else
68576- dest = mod->module_core + shdr->sh_entsize;
68577+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68578+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68579+ dest = mod->module_init_rw
68580+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68581+ else
68582+ dest = mod->module_init_rx
68583+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68584+ } else {
68585+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68586+ dest = mod->module_core_rw + shdr->sh_entsize;
68587+ else
68588+ dest = mod->module_core_rx + shdr->sh_entsize;
68589+ }
68590+
68591+ if (shdr->sh_type != SHT_NOBITS) {
68592+
68593+#ifdef CONFIG_PAX_KERNEXEC
68594+#ifdef CONFIG_X86_64
68595+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68596+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68597+#endif
68598+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68599+ pax_open_kernel();
68600+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68601+ pax_close_kernel();
68602+ } else
68603+#endif
68604
68605- if (shdr->sh_type != SHT_NOBITS)
68606 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68607+ }
68608 /* Update sh_addr to point to copy in image. */
68609- shdr->sh_addr = (unsigned long)dest;
68610+
68611+#ifdef CONFIG_PAX_KERNEXEC
68612+ if (shdr->sh_flags & SHF_EXECINSTR)
68613+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
68614+ else
68615+#endif
68616+
68617+ shdr->sh_addr = (unsigned long)dest;
68618 DEBUGP("\t0x%lx %s\n",
68619 shdr->sh_addr, info->secstrings + shdr->sh_name);
68620 }
68621@@ -2613,12 +2706,12 @@ static void flush_module_icache(const st
68622 * Do it before processing of module parameters, so the module
68623 * can provide parameter accessor functions of its own.
68624 */
68625- if (mod->module_init)
68626- flush_icache_range((unsigned long)mod->module_init,
68627- (unsigned long)mod->module_init
68628- + mod->init_size);
68629- flush_icache_range((unsigned long)mod->module_core,
68630- (unsigned long)mod->module_core + mod->core_size);
68631+ if (mod->module_init_rx)
68632+ flush_icache_range((unsigned long)mod->module_init_rx,
68633+ (unsigned long)mod->module_init_rx
68634+ + mod->init_size_rx);
68635+ flush_icache_range((unsigned long)mod->module_core_rx,
68636+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
68637
68638 set_fs(old_fs);
68639 }
68640@@ -2690,8 +2783,10 @@ static void module_deallocate(struct mod
68641 {
68642 kfree(info->strmap);
68643 percpu_modfree(mod);
68644- module_free(mod, mod->module_init);
68645- module_free(mod, mod->module_core);
68646+ module_free_exec(mod, mod->module_init_rx);
68647+ module_free_exec(mod, mod->module_core_rx);
68648+ module_free(mod, mod->module_init_rw);
68649+ module_free(mod, mod->module_core_rw);
68650 }
68651
68652 static int post_relocation(struct module *mod, const struct load_info *info)
68653@@ -2748,9 +2843,38 @@ static struct module *load_module(void _
68654 if (err)
68655 goto free_unload;
68656
68657+ /* Now copy in args */
68658+ mod->args = strndup_user(uargs, ~0UL >> 1);
68659+ if (IS_ERR(mod->args)) {
68660+ err = PTR_ERR(mod->args);
68661+ goto free_unload;
68662+ }
68663+
68664 /* Set up MODINFO_ATTR fields */
68665 setup_modinfo(mod, &info);
68666
68667+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68668+ {
68669+ char *p, *p2;
68670+
68671+ if (strstr(mod->args, "grsec_modharden_netdev")) {
68672+ 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);
68673+ err = -EPERM;
68674+ goto free_modinfo;
68675+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68676+ p += strlen("grsec_modharden_normal");
68677+ p2 = strstr(p, "_");
68678+ if (p2) {
68679+ *p2 = '\0';
68680+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68681+ *p2 = '_';
68682+ }
68683+ err = -EPERM;
68684+ goto free_modinfo;
68685+ }
68686+ }
68687+#endif
68688+
68689 /* Fix up syms, so that st_value is a pointer to location. */
68690 err = simplify_symbols(mod, &info);
68691 if (err < 0)
68692@@ -2766,13 +2890,6 @@ static struct module *load_module(void _
68693
68694 flush_module_icache(mod);
68695
68696- /* Now copy in args */
68697- mod->args = strndup_user(uargs, ~0UL >> 1);
68698- if (IS_ERR(mod->args)) {
68699- err = PTR_ERR(mod->args);
68700- goto free_arch_cleanup;
68701- }
68702-
68703 /* Mark state as coming so strong_try_module_get() ignores us. */
68704 mod->state = MODULE_STATE_COMING;
68705
68706@@ -2832,11 +2949,10 @@ static struct module *load_module(void _
68707 unlock:
68708 mutex_unlock(&module_mutex);
68709 synchronize_sched();
68710- kfree(mod->args);
68711- free_arch_cleanup:
68712 module_arch_cleanup(mod);
68713 free_modinfo:
68714 free_modinfo(mod);
68715+ kfree(mod->args);
68716 free_unload:
68717 module_unload_free(mod);
68718 free_module:
68719@@ -2877,16 +2993,16 @@ SYSCALL_DEFINE3(init_module, void __user
68720 MODULE_STATE_COMING, mod);
68721
68722 /* Set RO and NX regions for core */
68723- set_section_ro_nx(mod->module_core,
68724- mod->core_text_size,
68725- mod->core_ro_size,
68726- mod->core_size);
68727+ set_section_ro_nx(mod->module_core_rx,
68728+ mod->core_size_rx,
68729+ mod->core_size_rx,
68730+ mod->core_size_rx);
68731
68732 /* Set RO and NX regions for init */
68733- set_section_ro_nx(mod->module_init,
68734- mod->init_text_size,
68735- mod->init_ro_size,
68736- mod->init_size);
68737+ set_section_ro_nx(mod->module_init_rx,
68738+ mod->init_size_rx,
68739+ mod->init_size_rx,
68740+ mod->init_size_rx);
68741
68742 do_mod_ctors(mod);
68743 /* Start the module */
68744@@ -2931,11 +3047,13 @@ SYSCALL_DEFINE3(init_module, void __user
68745 mod->symtab = mod->core_symtab;
68746 mod->strtab = mod->core_strtab;
68747 #endif
68748- unset_section_ro_nx(mod, mod->module_init);
68749- module_free(mod, mod->module_init);
68750- mod->module_init = NULL;
68751- mod->init_size = 0;
68752- mod->init_text_size = 0;
68753+ unset_section_ro_nx(mod, mod->module_init_rx);
68754+ module_free(mod, mod->module_init_rw);
68755+ module_free_exec(mod, mod->module_init_rx);
68756+ mod->module_init_rw = NULL;
68757+ mod->module_init_rx = NULL;
68758+ mod->init_size_rw = 0;
68759+ mod->init_size_rx = 0;
68760 mutex_unlock(&module_mutex);
68761
68762 return 0;
68763@@ -2966,10 +3084,16 @@ static const char *get_ksymbol(struct mo
68764 unsigned long nextval;
68765
68766 /* At worse, next value is at end of module */
68767- if (within_module_init(addr, mod))
68768- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68769+ if (within_module_init_rx(addr, mod))
68770+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68771+ else if (within_module_init_rw(addr, mod))
68772+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68773+ else if (within_module_core_rx(addr, mod))
68774+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68775+ else if (within_module_core_rw(addr, mod))
68776+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68777 else
68778- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68779+ return NULL;
68780
68781 /* Scan for closest preceding symbol, and next symbol. (ELF
68782 starts real symbols at 1). */
68783@@ -3215,7 +3339,7 @@ static int m_show(struct seq_file *m, vo
68784 char buf[8];
68785
68786 seq_printf(m, "%s %u",
68787- mod->name, mod->init_size + mod->core_size);
68788+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68789 print_unload_info(m, mod);
68790
68791 /* Informative for users. */
68792@@ -3224,7 +3348,7 @@ static int m_show(struct seq_file *m, vo
68793 mod->state == MODULE_STATE_COMING ? "Loading":
68794 "Live");
68795 /* Used by oprofile and other similar tools. */
68796- seq_printf(m, " 0x%pK", mod->module_core);
68797+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68798
68799 /* Taints info */
68800 if (mod->taints)
68801@@ -3260,7 +3384,17 @@ static const struct file_operations proc
68802
68803 static int __init proc_modules_init(void)
68804 {
68805+#ifndef CONFIG_GRKERNSEC_HIDESYM
68806+#ifdef CONFIG_GRKERNSEC_PROC_USER
68807+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68808+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68809+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68810+#else
68811 proc_create("modules", 0, NULL, &proc_modules_operations);
68812+#endif
68813+#else
68814+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68815+#endif
68816 return 0;
68817 }
68818 module_init(proc_modules_init);
68819@@ -3319,12 +3453,12 @@ struct module *__module_address(unsigned
68820 {
68821 struct module *mod;
68822
68823- if (addr < module_addr_min || addr > module_addr_max)
68824+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68825+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68826 return NULL;
68827
68828 list_for_each_entry_rcu(mod, &modules, list)
68829- if (within_module_core(addr, mod)
68830- || within_module_init(addr, mod))
68831+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68832 return mod;
68833 return NULL;
68834 }
68835@@ -3358,11 +3492,20 @@ bool is_module_text_address(unsigned lon
68836 */
68837 struct module *__module_text_address(unsigned long addr)
68838 {
68839- struct module *mod = __module_address(addr);
68840+ struct module *mod;
68841+
68842+#ifdef CONFIG_X86_32
68843+ addr = ktla_ktva(addr);
68844+#endif
68845+
68846+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68847+ return NULL;
68848+
68849+ mod = __module_address(addr);
68850+
68851 if (mod) {
68852 /* Make sure it's within the text section. */
68853- if (!within(addr, mod->module_init, mod->init_text_size)
68854- && !within(addr, mod->module_core, mod->core_text_size))
68855+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68856 mod = NULL;
68857 }
68858 return mod;
68859diff -urNp linux-2.6.39.1/kernel/mutex.c linux-2.6.39.1/kernel/mutex.c
68860--- linux-2.6.39.1/kernel/mutex.c 2011-05-19 00:06:34.000000000 -0400
68861+++ linux-2.6.39.1/kernel/mutex.c 2011-05-22 19:36:33.000000000 -0400
68862@@ -160,7 +160,7 @@ __mutex_lock_common(struct mutex *lock,
68863 */
68864
68865 for (;;) {
68866- struct thread_info *owner;
68867+ struct task_struct *owner;
68868
68869 /*
68870 * If we own the BKL, then don't spin. The owner of
68871@@ -205,7 +205,7 @@ __mutex_lock_common(struct mutex *lock,
68872 spin_lock_mutex(&lock->wait_lock, flags);
68873
68874 debug_mutex_lock_common(lock, &waiter);
68875- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68876+ debug_mutex_add_waiter(lock, &waiter, task);
68877
68878 /* add waiting tasks to the end of the waitqueue (FIFO): */
68879 list_add_tail(&waiter.list, &lock->wait_list);
68880@@ -234,8 +234,7 @@ __mutex_lock_common(struct mutex *lock,
68881 * TASK_UNINTERRUPTIBLE case.)
68882 */
68883 if (unlikely(signal_pending_state(state, task))) {
68884- mutex_remove_waiter(lock, &waiter,
68885- task_thread_info(task));
68886+ mutex_remove_waiter(lock, &waiter, task);
68887 mutex_release(&lock->dep_map, 1, ip);
68888 spin_unlock_mutex(&lock->wait_lock, flags);
68889
68890@@ -256,7 +255,7 @@ __mutex_lock_common(struct mutex *lock,
68891 done:
68892 lock_acquired(&lock->dep_map, ip);
68893 /* got the lock - rejoice! */
68894- mutex_remove_waiter(lock, &waiter, current_thread_info());
68895+ mutex_remove_waiter(lock, &waiter, task);
68896 mutex_set_owner(lock);
68897
68898 /* set it to 0 if there are no waiters left: */
68899diff -urNp linux-2.6.39.1/kernel/mutex-debug.c linux-2.6.39.1/kernel/mutex-debug.c
68900--- linux-2.6.39.1/kernel/mutex-debug.c 2011-05-19 00:06:34.000000000 -0400
68901+++ linux-2.6.39.1/kernel/mutex-debug.c 2011-05-22 19:36:33.000000000 -0400
68902@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
68903 }
68904
68905 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68906- struct thread_info *ti)
68907+ struct task_struct *task)
68908 {
68909 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68910
68911 /* Mark the current thread as blocked on the lock: */
68912- ti->task->blocked_on = waiter;
68913+ task->blocked_on = waiter;
68914 }
68915
68916 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68917- struct thread_info *ti)
68918+ struct task_struct *task)
68919 {
68920 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68921- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68922- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68923- ti->task->blocked_on = NULL;
68924+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68925+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68926+ task->blocked_on = NULL;
68927
68928 list_del_init(&waiter->list);
68929 waiter->task = NULL;
68930@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
68931 return;
68932
68933 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
68934- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
68935+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
68936 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
68937 mutex_clear_owner(lock);
68938 }
68939diff -urNp linux-2.6.39.1/kernel/mutex-debug.h linux-2.6.39.1/kernel/mutex-debug.h
68940--- linux-2.6.39.1/kernel/mutex-debug.h 2011-05-19 00:06:34.000000000 -0400
68941+++ linux-2.6.39.1/kernel/mutex-debug.h 2011-05-22 19:36:33.000000000 -0400
68942@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
68943 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68944 extern void debug_mutex_add_waiter(struct mutex *lock,
68945 struct mutex_waiter *waiter,
68946- struct thread_info *ti);
68947+ struct task_struct *task);
68948 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68949- struct thread_info *ti);
68950+ struct task_struct *task);
68951 extern void debug_mutex_unlock(struct mutex *lock);
68952 extern void debug_mutex_init(struct mutex *lock, const char *name,
68953 struct lock_class_key *key);
68954
68955 static inline void mutex_set_owner(struct mutex *lock)
68956 {
68957- lock->owner = current_thread_info();
68958+ lock->owner = current;
68959 }
68960
68961 static inline void mutex_clear_owner(struct mutex *lock)
68962diff -urNp linux-2.6.39.1/kernel/mutex.h linux-2.6.39.1/kernel/mutex.h
68963--- linux-2.6.39.1/kernel/mutex.h 2011-05-19 00:06:34.000000000 -0400
68964+++ linux-2.6.39.1/kernel/mutex.h 2011-05-22 19:36:33.000000000 -0400
68965@@ -19,7 +19,7 @@
68966 #ifdef CONFIG_SMP
68967 static inline void mutex_set_owner(struct mutex *lock)
68968 {
68969- lock->owner = current_thread_info();
68970+ lock->owner = current;
68971 }
68972
68973 static inline void mutex_clear_owner(struct mutex *lock)
68974diff -urNp linux-2.6.39.1/kernel/padata.c linux-2.6.39.1/kernel/padata.c
68975--- linux-2.6.39.1/kernel/padata.c 2011-05-19 00:06:34.000000000 -0400
68976+++ linux-2.6.39.1/kernel/padata.c 2011-05-22 19:36:33.000000000 -0400
68977@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
68978 padata->pd = pd;
68979 padata->cb_cpu = cb_cpu;
68980
68981- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68982- atomic_set(&pd->seq_nr, -1);
68983+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68984+ atomic_set_unchecked(&pd->seq_nr, -1);
68985
68986- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68987+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68988
68989 target_cpu = padata_cpu_hash(padata);
68990 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68991@@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
68992 padata_init_pqueues(pd);
68993 padata_init_squeues(pd);
68994 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68995- atomic_set(&pd->seq_nr, -1);
68996+ atomic_set_unchecked(&pd->seq_nr, -1);
68997 atomic_set(&pd->reorder_objects, 0);
68998 atomic_set(&pd->refcnt, 0);
68999 pd->pinst = pinst;
69000diff -urNp linux-2.6.39.1/kernel/panic.c linux-2.6.39.1/kernel/panic.c
69001--- linux-2.6.39.1/kernel/panic.c 2011-05-19 00:06:34.000000000 -0400
69002+++ linux-2.6.39.1/kernel/panic.c 2011-05-22 19:41:42.000000000 -0400
69003@@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
69004 const char *board;
69005
69006 printk(KERN_WARNING "------------[ cut here ]------------\n");
69007- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69008+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69009 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69010 if (board)
69011 printk(KERN_WARNING "Hardware name: %s\n", board);
69012@@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69013 */
69014 void __stack_chk_fail(void)
69015 {
69016- panic("stack-protector: Kernel stack is corrupted in: %p\n",
69017+ dump_stack();
69018+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69019 __builtin_return_address(0));
69020 }
69021 EXPORT_SYMBOL(__stack_chk_fail);
69022diff -urNp linux-2.6.39.1/kernel/params.c linux-2.6.39.1/kernel/params.c
69023--- linux-2.6.39.1/kernel/params.c 2011-05-19 00:06:34.000000000 -0400
69024+++ linux-2.6.39.1/kernel/params.c 2011-05-22 19:36:33.000000000 -0400
69025@@ -234,7 +234,7 @@ int parse_args(const char *name,
69026 { \
69027 return sprintf(buffer, format, *((type *)kp->arg)); \
69028 } \
69029- struct kernel_param_ops param_ops_##name = { \
69030+ const struct kernel_param_ops param_ops_##name = { \
69031 .set = param_set_##name, \
69032 .get = param_get_##name, \
69033 }; \
69034@@ -286,7 +286,7 @@ static void param_free_charp(void *arg)
69035 maybe_kfree_parameter(*((char **)arg));
69036 }
69037
69038-struct kernel_param_ops param_ops_charp = {
69039+const struct kernel_param_ops param_ops_charp = {
69040 .set = param_set_charp,
69041 .get = param_get_charp,
69042 .free = param_free_charp,
69043@@ -334,7 +334,7 @@ int param_get_bool(char *buffer, const s
69044 }
69045 EXPORT_SYMBOL(param_get_bool);
69046
69047-struct kernel_param_ops param_ops_bool = {
69048+const struct kernel_param_ops param_ops_bool = {
69049 .set = param_set_bool,
69050 .get = param_get_bool,
69051 };
69052@@ -362,7 +362,7 @@ int param_get_invbool(char *buffer, cons
69053 }
69054 EXPORT_SYMBOL(param_get_invbool);
69055
69056-struct kernel_param_ops param_ops_invbool = {
69057+const struct kernel_param_ops param_ops_invbool = {
69058 .set = param_set_invbool,
69059 .get = param_get_invbool,
69060 };
69061@@ -460,7 +460,7 @@ static void param_array_free(void *arg)
69062 arr->ops->free(arr->elem + arr->elemsize * i);
69063 }
69064
69065-struct kernel_param_ops param_array_ops = {
69066+const struct kernel_param_ops param_array_ops = {
69067 .set = param_array_set,
69068 .get = param_array_get,
69069 .free = param_array_free,
69070@@ -488,7 +488,7 @@ int param_get_string(char *buffer, const
69071 }
69072 EXPORT_SYMBOL(param_get_string);
69073
69074-struct kernel_param_ops param_ops_string = {
69075+const struct kernel_param_ops param_ops_string = {
69076 .set = param_set_copystring,
69077 .get = param_get_string,
69078 };
69079diff -urNp linux-2.6.39.1/kernel/perf_event.c linux-2.6.39.1/kernel/perf_event.c
69080--- linux-2.6.39.1/kernel/perf_event.c 2011-05-19 00:06:34.000000000 -0400
69081+++ linux-2.6.39.1/kernel/perf_event.c 2011-05-22 19:36:33.000000000 -0400
69082@@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
69083 return 0;
69084 }
69085
69086-static atomic64_t perf_event_id;
69087+static atomic64_unchecked_t perf_event_id;
69088
69089 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69090 enum event_type_t event_type);
69091@@ -2496,7 +2496,7 @@ static void __perf_event_read(void *info
69092
69093 static inline u64 perf_event_count(struct perf_event *event)
69094 {
69095- return local64_read(&event->count) + atomic64_read(&event->child_count);
69096+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69097 }
69098
69099 static u64 perf_event_read(struct perf_event *event)
69100@@ -3031,9 +3031,9 @@ u64 perf_event_read_value(struct perf_ev
69101 mutex_lock(&event->child_mutex);
69102 total += perf_event_read(event);
69103 *enabled += event->total_time_enabled +
69104- atomic64_read(&event->child_total_time_enabled);
69105+ atomic64_read_unchecked(&event->child_total_time_enabled);
69106 *running += event->total_time_running +
69107- atomic64_read(&event->child_total_time_running);
69108+ atomic64_read_unchecked(&event->child_total_time_running);
69109
69110 list_for_each_entry(child, &event->child_list, child_list) {
69111 total += perf_event_read(child);
69112@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct p
69113 userpg->offset -= local64_read(&event->hw.prev_count);
69114
69115 userpg->time_enabled = event->total_time_enabled +
69116- atomic64_read(&event->child_total_time_enabled);
69117+ atomic64_read_unchecked(&event->child_total_time_enabled);
69118
69119 userpg->time_running = event->total_time_running +
69120- atomic64_read(&event->child_total_time_running);
69121+ atomic64_read_unchecked(&event->child_total_time_running);
69122
69123 barrier();
69124 ++userpg->lock;
69125@@ -3884,16 +3884,16 @@ static void perf_pending_event(struct ir
69126 * Later on, we might change it to a list if there is
69127 * another virtualization implementation supporting the callbacks.
69128 */
69129-struct perf_guest_info_callbacks *perf_guest_cbs;
69130+const struct perf_guest_info_callbacks *perf_guest_cbs;
69131
69132-int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69133+int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
69134 {
69135 perf_guest_cbs = cbs;
69136 return 0;
69137 }
69138 EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
69139
69140-int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69141+int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
69142 {
69143 perf_guest_cbs = NULL;
69144 return 0;
69145@@ -4196,11 +4196,11 @@ static void perf_output_read_one(struct
69146 values[n++] = perf_event_count(event);
69147 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69148 values[n++] = enabled +
69149- atomic64_read(&event->child_total_time_enabled);
69150+ atomic64_read_unchecked(&event->child_total_time_enabled);
69151 }
69152 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69153 values[n++] = running +
69154- atomic64_read(&event->child_total_time_running);
69155+ atomic64_read_unchecked(&event->child_total_time_running);
69156 }
69157 if (read_format & PERF_FORMAT_ID)
69158 values[n++] = primary_event_id(event);
69159@@ -6201,7 +6201,7 @@ perf_event_alloc(struct perf_event_attr
69160 event->parent = parent_event;
69161
69162 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69163- event->id = atomic64_inc_return(&perf_event_id);
69164+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
69165
69166 event->state = PERF_EVENT_STATE_INACTIVE;
69167
69168@@ -6724,10 +6724,10 @@ static void sync_child_event(struct perf
69169 /*
69170 * Add back the child's count to the parent's count:
69171 */
69172- atomic64_add(child_val, &parent_event->child_count);
69173- atomic64_add(child_event->total_time_enabled,
69174+ atomic64_add_unchecked(child_val, &parent_event->child_count);
69175+ atomic64_add_unchecked(child_event->total_time_enabled,
69176 &parent_event->child_total_time_enabled);
69177- atomic64_add(child_event->total_time_running,
69178+ atomic64_add_unchecked(child_event->total_time_running,
69179 &parent_event->child_total_time_running);
69180
69181 /*
69182diff -urNp linux-2.6.39.1/kernel/pid.c linux-2.6.39.1/kernel/pid.c
69183--- linux-2.6.39.1/kernel/pid.c 2011-05-19 00:06:34.000000000 -0400
69184+++ linux-2.6.39.1/kernel/pid.c 2011-05-22 19:41:42.000000000 -0400
69185@@ -33,6 +33,7 @@
69186 #include <linux/rculist.h>
69187 #include <linux/bootmem.h>
69188 #include <linux/hash.h>
69189+#include <linux/security.h>
69190 #include <linux/pid_namespace.h>
69191 #include <linux/init_task.h>
69192 #include <linux/syscalls.h>
69193@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
69194
69195 int pid_max = PID_MAX_DEFAULT;
69196
69197-#define RESERVED_PIDS 300
69198+#define RESERVED_PIDS 500
69199
69200 int pid_max_min = RESERVED_PIDS + 1;
69201 int pid_max_max = PID_MAX_LIMIT;
69202@@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
69203 */
69204 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69205 {
69206+ struct task_struct *task;
69207+
69208 rcu_lockdep_assert(rcu_read_lock_held());
69209- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69210+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69211+
69212+ if (gr_pid_is_chrooted(task))
69213+ return NULL;
69214+
69215+ return task;
69216 }
69217
69218 struct task_struct *find_task_by_vpid(pid_t vnr)
69219diff -urNp linux-2.6.39.1/kernel/posix-cpu-timers.c linux-2.6.39.1/kernel/posix-cpu-timers.c
69220--- linux-2.6.39.1/kernel/posix-cpu-timers.c 2011-05-19 00:06:34.000000000 -0400
69221+++ linux-2.6.39.1/kernel/posix-cpu-timers.c 2011-05-22 19:41:42.000000000 -0400
69222@@ -6,6 +6,7 @@
69223 #include <linux/posix-timers.h>
69224 #include <linux/errno.h>
69225 #include <linux/math64.h>
69226+#include <linux/security.h>
69227 #include <asm/uaccess.h>
69228 #include <linux/kernel_stat.h>
69229 #include <trace/events/timer.h>
69230@@ -1590,7 +1591,7 @@ static int thread_cpu_timer_create(struc
69231 return posix_cpu_timer_create(timer);
69232 }
69233
69234-struct k_clock clock_posix_cpu = {
69235+const struct k_clock clock_posix_cpu = {
69236 .clock_getres = posix_cpu_clock_getres,
69237 .clock_set = posix_cpu_clock_set,
69238 .clock_get = posix_cpu_clock_get,
69239@@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
69240
69241 static __init int init_posix_cpu_timers(void)
69242 {
69243- struct k_clock process = {
69244+ const struct k_clock process = {
69245 .clock_getres = process_cpu_clock_getres,
69246 .clock_get = process_cpu_clock_get,
69247 .timer_create = process_cpu_timer_create,
69248 .nsleep = process_cpu_nsleep,
69249 .nsleep_restart = process_cpu_nsleep_restart,
69250 };
69251- struct k_clock thread = {
69252+ const struct k_clock thread = {
69253 .clock_getres = thread_cpu_clock_getres,
69254 .clock_get = thread_cpu_clock_get,
69255 .timer_create = thread_cpu_timer_create,
69256diff -urNp linux-2.6.39.1/kernel/posix-timers.c linux-2.6.39.1/kernel/posix-timers.c
69257--- linux-2.6.39.1/kernel/posix-timers.c 2011-05-19 00:06:34.000000000 -0400
69258+++ linux-2.6.39.1/kernel/posix-timers.c 2011-05-22 20:13:41.000000000 -0400
69259@@ -43,6 +43,7 @@
69260 #include <linux/idr.h>
69261 #include <linux/posix-clock.h>
69262 #include <linux/posix-timers.h>
69263+#include <linux/grsecurity.h>
69264 #include <linux/syscalls.h>
69265 #include <linux/wait.h>
69266 #include <linux/workqueue.h>
69267@@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
69268 */
69269 static __init int init_posix_timers(void)
69270 {
69271- struct k_clock clock_realtime = {
69272+ const struct k_clock clock_realtime = {
69273 .clock_getres = hrtimer_get_res,
69274 .clock_get = posix_clock_realtime_get,
69275 .clock_set = posix_clock_realtime_set,
69276@@ -239,7 +240,7 @@ static __init int init_posix_timers(void
69277 .timer_get = common_timer_get,
69278 .timer_del = common_timer_del,
69279 };
69280- struct k_clock clock_monotonic = {
69281+ const struct k_clock clock_monotonic = {
69282 .clock_getres = hrtimer_get_res,
69283 .clock_get = posix_ktime_get_ts,
69284 .nsleep = common_nsleep,
69285@@ -249,19 +250,19 @@ static __init int init_posix_timers(void
69286 .timer_get = common_timer_get,
69287 .timer_del = common_timer_del,
69288 };
69289- struct k_clock clock_monotonic_raw = {
69290+ const struct k_clock clock_monotonic_raw = {
69291 .clock_getres = hrtimer_get_res,
69292 .clock_get = posix_get_monotonic_raw,
69293 };
69294- struct k_clock clock_realtime_coarse = {
69295+ const struct k_clock clock_realtime_coarse = {
69296 .clock_getres = posix_get_coarse_res,
69297 .clock_get = posix_get_realtime_coarse,
69298 };
69299- struct k_clock clock_monotonic_coarse = {
69300+ const struct k_clock clock_monotonic_coarse = {
69301 .clock_getres = posix_get_coarse_res,
69302 .clock_get = posix_get_monotonic_coarse,
69303 };
69304- struct k_clock clock_boottime = {
69305+ const struct k_clock clock_boottime = {
69306 .clock_getres = hrtimer_get_res,
69307 .clock_get = posix_get_boottime,
69308 .nsleep = common_nsleep,
69309@@ -272,6 +273,8 @@ static __init int init_posix_timers(void
69310 .timer_del = common_timer_del,
69311 };
69312
69313+ pax_track_stack();
69314+
69315 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
69316 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
69317 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
69318@@ -454,7 +457,7 @@ static struct pid *good_sigevent(sigeven
69319 }
69320
69321 void posix_timers_register_clock(const clockid_t clock_id,
69322- struct k_clock *new_clock)
69323+ const struct k_clock *new_clock)
69324 {
69325 if ((unsigned) clock_id >= MAX_CLOCKS) {
69326 printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
69327@@ -506,7 +509,7 @@ static void release_posix_timer(struct k
69328 kmem_cache_free(posix_timers_cache, tmr);
69329 }
69330
69331-static struct k_clock *clockid_to_kclock(const clockid_t id)
69332+static const struct k_clock *clockid_to_kclock(const clockid_t id)
69333 {
69334 if (id < 0)
69335 return (id & CLOCKFD_MASK) == CLOCKFD ?
69336@@ -529,7 +532,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
69337 struct sigevent __user *, timer_event_spec,
69338 timer_t __user *, created_timer_id)
69339 {
69340- struct k_clock *kc = clockid_to_kclock(which_clock);
69341+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69342 struct k_itimer *new_timer;
69343 int error, new_timer_id;
69344 sigevent_t event;
69345@@ -714,7 +717,7 @@ SYSCALL_DEFINE2(timer_gettime, timer_t,
69346 {
69347 struct itimerspec cur_setting;
69348 struct k_itimer *timr;
69349- struct k_clock *kc;
69350+ const struct k_clock *kc;
69351 unsigned long flags;
69352 int ret = 0;
69353
69354@@ -822,7 +825,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t,
69355 int error = 0;
69356 unsigned long flag;
69357 struct itimerspec *rtn = old_setting ? &old_spec : NULL;
69358- struct k_clock *kc;
69359+ const struct k_clock *kc;
69360
69361 if (!new_setting)
69362 return -EINVAL;
69363@@ -868,7 +871,7 @@ static int common_timer_del(struct k_iti
69364
69365 static inline int timer_delete_hook(struct k_itimer *timer)
69366 {
69367- struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69368+ const struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69369
69370 if (WARN_ON_ONCE(!kc || !kc->timer_del))
69371 return -EINVAL;
69372@@ -947,7 +950,7 @@ void exit_itimers(struct signal_struct *
69373 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69374 const struct timespec __user *, tp)
69375 {
69376- struct k_clock *kc = clockid_to_kclock(which_clock);
69377+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69378 struct timespec new_tp;
69379
69380 if (!kc || !kc->clock_set)
69381@@ -956,13 +959,20 @@ SYSCALL_DEFINE2(clock_settime, const clo
69382 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69383 return -EFAULT;
69384
69385+ /* only the CLOCK_REALTIME clock can be set, all other clocks
69386+ have their clock_set fptr set to a nosettime dummy function
69387+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69388+ call common_clock_set, which calls do_sys_settimeofday, which
69389+ we hook
69390+ */
69391+
69392 return kc->clock_set(which_clock, &new_tp);
69393 }
69394
69395 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
69396 struct timespec __user *,tp)
69397 {
69398- struct k_clock *kc = clockid_to_kclock(which_clock);
69399+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69400 struct timespec kernel_tp;
69401 int error;
69402
69403@@ -980,7 +990,7 @@ SYSCALL_DEFINE2(clock_gettime, const clo
69404 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
69405 struct timex __user *, utx)
69406 {
69407- struct k_clock *kc = clockid_to_kclock(which_clock);
69408+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69409 struct timex ktx;
69410 int err;
69411
69412@@ -1003,7 +1013,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clo
69413 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
69414 struct timespec __user *, tp)
69415 {
69416- struct k_clock *kc = clockid_to_kclock(which_clock);
69417+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69418 struct timespec rtn_tp;
69419 int error;
69420
69421@@ -1033,7 +1043,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69422 const struct timespec __user *, rqtp,
69423 struct timespec __user *, rmtp)
69424 {
69425- struct k_clock *kc = clockid_to_kclock(which_clock);
69426+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69427 struct timespec t;
69428
69429 if (!kc)
69430@@ -1057,7 +1067,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69431 long clock_nanosleep_restart(struct restart_block *restart_block)
69432 {
69433 clockid_t which_clock = restart_block->nanosleep.index;
69434- struct k_clock *kc = clockid_to_kclock(which_clock);
69435+ const struct k_clock *kc = clockid_to_kclock(which_clock);
69436
69437 if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))
69438 return -EINVAL;
69439diff -urNp linux-2.6.39.1/kernel/power/poweroff.c linux-2.6.39.1/kernel/power/poweroff.c
69440--- linux-2.6.39.1/kernel/power/poweroff.c 2011-05-19 00:06:34.000000000 -0400
69441+++ linux-2.6.39.1/kernel/power/poweroff.c 2011-05-22 19:36:33.000000000 -0400
69442@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
69443 .enable_mask = SYSRQ_ENABLE_BOOT,
69444 };
69445
69446-static int pm_sysrq_init(void)
69447+static int __init pm_sysrq_init(void)
69448 {
69449 register_sysrq_key('o', &sysrq_poweroff_op);
69450 return 0;
69451diff -urNp linux-2.6.39.1/kernel/power/process.c linux-2.6.39.1/kernel/power/process.c
69452--- linux-2.6.39.1/kernel/power/process.c 2011-05-19 00:06:34.000000000 -0400
69453+++ linux-2.6.39.1/kernel/power/process.c 2011-05-22 19:36:33.000000000 -0400
69454@@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
69455 u64 elapsed_csecs64;
69456 unsigned int elapsed_csecs;
69457 bool wakeup = false;
69458+ bool timedout = false;
69459
69460 do_gettimeofday(&start);
69461
69462@@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
69463
69464 while (true) {
69465 todo = 0;
69466+ if (time_after(jiffies, end_time))
69467+ timedout = true;
69468 read_lock(&tasklist_lock);
69469 do_each_thread(g, p) {
69470 if (frozen(p) || !freezable(p))
69471@@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
69472 * try_to_stop() after schedule() in ptrace/signal
69473 * stop sees TIF_FREEZE.
69474 */
69475- if (!task_is_stopped_or_traced(p) &&
69476- !freezer_should_skip(p))
69477+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69478 todo++;
69479+ if (timedout) {
69480+ printk(KERN_ERR "Task refusing to freeze:\n");
69481+ sched_show_task(p);
69482+ }
69483+ }
69484 } while_each_thread(g, p);
69485 read_unlock(&tasklist_lock);
69486
69487@@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
69488 todo += wq_busy;
69489 }
69490
69491- if (!todo || time_after(jiffies, end_time))
69492+ if (!todo || timedout)
69493 break;
69494
69495 if (pm_wakeup_pending()) {
69496diff -urNp linux-2.6.39.1/kernel/printk.c linux-2.6.39.1/kernel/printk.c
69497--- linux-2.6.39.1/kernel/printk.c 2011-05-19 00:06:34.000000000 -0400
69498+++ linux-2.6.39.1/kernel/printk.c 2011-05-22 19:41:42.000000000 -0400
69499@@ -284,12 +284,17 @@ static int check_syslog_permissions(int
69500 if (from_file && type != SYSLOG_ACTION_OPEN)
69501 return 0;
69502
69503+#ifdef CONFIG_GRKERNSEC_DMESG
69504+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69505+ return -EPERM;
69506+#endif
69507+
69508 if (syslog_action_restricted(type)) {
69509 if (capable(CAP_SYSLOG))
69510 return 0;
69511 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
69512 if (capable(CAP_SYS_ADMIN)) {
69513- WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
69514+ printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
69515 "but no CAP_SYSLOG (deprecated).\n");
69516 return 0;
69517 }
69518diff -urNp linux-2.6.39.1/kernel/profile.c linux-2.6.39.1/kernel/profile.c
69519--- linux-2.6.39.1/kernel/profile.c 2011-05-19 00:06:34.000000000 -0400
69520+++ linux-2.6.39.1/kernel/profile.c 2011-05-22 19:36:33.000000000 -0400
69521@@ -39,7 +39,7 @@ struct profile_hit {
69522 /* Oprofile timer tick hook */
69523 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69524
69525-static atomic_t *prof_buffer;
69526+static atomic_unchecked_t *prof_buffer;
69527 static unsigned long prof_len, prof_shift;
69528
69529 int prof_on __read_mostly;
69530@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
69531 hits[i].pc = 0;
69532 continue;
69533 }
69534- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69535+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69536 hits[i].hits = hits[i].pc = 0;
69537 }
69538 }
69539@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
69540 * Add the current hit(s) and flush the write-queue out
69541 * to the global buffer:
69542 */
69543- atomic_add(nr_hits, &prof_buffer[pc]);
69544+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69545 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69546- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69547+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69548 hits[i].pc = hits[i].hits = 0;
69549 }
69550 out:
69551@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
69552 if (prof_on != type || !prof_buffer)
69553 return;
69554 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69555- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69556+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69557 }
69558 #endif /* !CONFIG_SMP */
69559 EXPORT_SYMBOL_GPL(profile_hits);
69560@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
69561 return -EFAULT;
69562 buf++; p++; count--; read++;
69563 }
69564- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69565+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69566 if (copy_to_user(buf, (void *)pnt, count))
69567 return -EFAULT;
69568 read += count;
69569@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
69570 }
69571 #endif
69572 profile_discard_flip_buffers();
69573- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69574+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69575 return count;
69576 }
69577
69578diff -urNp linux-2.6.39.1/kernel/ptrace.c linux-2.6.39.1/kernel/ptrace.c
69579--- linux-2.6.39.1/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
69580+++ linux-2.6.39.1/kernel/ptrace.c 2011-05-23 17:07:00.000000000 -0400
69581@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
69582 return ret;
69583 }
69584
69585-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
69586+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
69587+ unsigned int log)
69588 {
69589 const struct cred *cred = current_cred(), *tcred;
69590
69591@@ -143,7 +144,8 @@ int __ptrace_may_access(struct task_stru
69592 cred->gid == tcred->sgid &&
69593 cred->gid == tcred->gid))
69594 goto ok;
69595- if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
69596+ if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
69597+ (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
69598 goto ok;
69599 rcu_read_unlock();
69600 return -EPERM;
69601@@ -152,7 +154,9 @@ ok:
69602 smp_rmb();
69603 if (task->mm)
69604 dumpable = get_dumpable(task->mm);
69605- if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
69606+ if (!dumpable &&
69607+ ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
69608+ (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
69609 return -EPERM;
69610
69611 return security_ptrace_access_check(task, mode);
69612@@ -162,7 +166,16 @@ bool ptrace_may_access(struct task_struc
69613 {
69614 int err;
69615 task_lock(task);
69616- err = __ptrace_may_access(task, mode);
69617+ err = __ptrace_may_access(task, mode, 0);
69618+ task_unlock(task);
69619+ return !err;
69620+}
69621+
69622+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
69623+{
69624+ int err;
69625+ task_lock(task);
69626+ err = __ptrace_may_access(task, mode, 1);
69627 task_unlock(task);
69628 return !err;
69629 }
69630@@ -189,7 +202,7 @@ static int ptrace_attach(struct task_str
69631 goto out;
69632
69633 task_lock(task);
69634- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
69635+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
69636 task_unlock(task);
69637 if (retval)
69638 goto unlock_creds;
69639@@ -202,7 +215,7 @@ static int ptrace_attach(struct task_str
69640 goto unlock_tasklist;
69641
69642 task->ptrace = PT_PTRACED;
69643- if (task_ns_capable(task, CAP_SYS_PTRACE))
69644+ if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
69645 task->ptrace |= PT_PTRACE_CAP;
69646
69647 __ptrace_link(task, current);
69648@@ -362,6 +375,8 @@ int ptrace_readdata(struct task_struct *
69649 {
69650 int copied = 0;
69651
69652+ pax_track_stack();
69653+
69654 while (len > 0) {
69655 char buf[128];
69656 int this_len, retval;
69657@@ -373,7 +388,7 @@ int ptrace_readdata(struct task_struct *
69658 break;
69659 return -EIO;
69660 }
69661- if (copy_to_user(dst, buf, retval))
69662+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69663 return -EFAULT;
69664 copied += retval;
69665 src += retval;
69666@@ -387,6 +402,8 @@ int ptrace_writedata(struct task_struct
69667 {
69668 int copied = 0;
69669
69670+ pax_track_stack();
69671+
69672 while (len > 0) {
69673 char buf[128];
69674 int this_len, retval;
69675@@ -569,9 +586,11 @@ int ptrace_request(struct task_struct *c
69676 {
69677 int ret = -EIO;
69678 siginfo_t siginfo;
69679- void __user *datavp = (void __user *) data;
69680+ void __user *datavp = (__force void __user *) data;
69681 unsigned long __user *datalp = datavp;
69682
69683+ pax_track_stack();
69684+
69685 switch (request) {
69686 case PTRACE_PEEKTEXT:
69687 case PTRACE_PEEKDATA:
69688@@ -717,14 +736,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
69689 goto out;
69690 }
69691
69692+ if (gr_handle_ptrace(child, request)) {
69693+ ret = -EPERM;
69694+ goto out_put_task_struct;
69695+ }
69696+
69697 if (request == PTRACE_ATTACH) {
69698 ret = ptrace_attach(child);
69699 /*
69700 * Some architectures need to do book-keeping after
69701 * a ptrace attach.
69702 */
69703- if (!ret)
69704+ if (!ret) {
69705 arch_ptrace_attach(child);
69706+ gr_audit_ptrace(child);
69707+ }
69708 goto out_put_task_struct;
69709 }
69710
69711@@ -749,7 +775,7 @@ int generic_ptrace_peekdata(struct task_
69712 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69713 if (copied != sizeof(tmp))
69714 return -EIO;
69715- return put_user(tmp, (unsigned long __user *)data);
69716+ return put_user(tmp, (__force unsigned long __user *)data);
69717 }
69718
69719 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69720@@ -772,6 +798,8 @@ int compat_ptrace_request(struct task_st
69721 siginfo_t siginfo;
69722 int ret;
69723
69724+ pax_track_stack();
69725+
69726 switch (request) {
69727 case PTRACE_PEEKTEXT:
69728 case PTRACE_PEEKDATA:
69729@@ -859,14 +887,21 @@ asmlinkage long compat_sys_ptrace(compat
69730 goto out;
69731 }
69732
69733+ if (gr_handle_ptrace(child, request)) {
69734+ ret = -EPERM;
69735+ goto out_put_task_struct;
69736+ }
69737+
69738 if (request == PTRACE_ATTACH) {
69739 ret = ptrace_attach(child);
69740 /*
69741 * Some architectures need to do book-keeping after
69742 * a ptrace attach.
69743 */
69744- if (!ret)
69745+ if (!ret) {
69746 arch_ptrace_attach(child);
69747+ gr_audit_ptrace(child);
69748+ }
69749 goto out_put_task_struct;
69750 }
69751
69752diff -urNp linux-2.6.39.1/kernel/rcutorture.c linux-2.6.39.1/kernel/rcutorture.c
69753--- linux-2.6.39.1/kernel/rcutorture.c 2011-05-19 00:06:34.000000000 -0400
69754+++ linux-2.6.39.1/kernel/rcutorture.c 2011-05-22 19:36:33.000000000 -0400
69755@@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
69756 { 0 };
69757 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69758 { 0 };
69759-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69760-static atomic_t n_rcu_torture_alloc;
69761-static atomic_t n_rcu_torture_alloc_fail;
69762-static atomic_t n_rcu_torture_free;
69763-static atomic_t n_rcu_torture_mberror;
69764-static atomic_t n_rcu_torture_error;
69765+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69766+static atomic_unchecked_t n_rcu_torture_alloc;
69767+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69768+static atomic_unchecked_t n_rcu_torture_free;
69769+static atomic_unchecked_t n_rcu_torture_mberror;
69770+static atomic_unchecked_t n_rcu_torture_error;
69771 static long n_rcu_torture_boost_ktrerror;
69772 static long n_rcu_torture_boost_rterror;
69773 static long n_rcu_torture_boost_allocerror;
69774@@ -225,11 +225,11 @@ rcu_torture_alloc(void)
69775
69776 spin_lock_bh(&rcu_torture_lock);
69777 if (list_empty(&rcu_torture_freelist)) {
69778- atomic_inc(&n_rcu_torture_alloc_fail);
69779+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69780 spin_unlock_bh(&rcu_torture_lock);
69781 return NULL;
69782 }
69783- atomic_inc(&n_rcu_torture_alloc);
69784+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69785 p = rcu_torture_freelist.next;
69786 list_del_init(p);
69787 spin_unlock_bh(&rcu_torture_lock);
69788@@ -242,7 +242,7 @@ rcu_torture_alloc(void)
69789 static void
69790 rcu_torture_free(struct rcu_torture *p)
69791 {
69792- atomic_inc(&n_rcu_torture_free);
69793+ atomic_inc_unchecked(&n_rcu_torture_free);
69794 spin_lock_bh(&rcu_torture_lock);
69795 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69796 spin_unlock_bh(&rcu_torture_lock);
69797@@ -362,7 +362,7 @@ rcu_torture_cb(struct rcu_head *p)
69798 i = rp->rtort_pipe_count;
69799 if (i > RCU_TORTURE_PIPE_LEN)
69800 i = RCU_TORTURE_PIPE_LEN;
69801- atomic_inc(&rcu_torture_wcount[i]);
69802+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69803 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69804 rp->rtort_mbtest = 0;
69805 rcu_torture_free(rp);
69806@@ -409,7 +409,7 @@ static void rcu_sync_torture_deferred_fr
69807 i = rp->rtort_pipe_count;
69808 if (i > RCU_TORTURE_PIPE_LEN)
69809 i = RCU_TORTURE_PIPE_LEN;
69810- atomic_inc(&rcu_torture_wcount[i]);
69811+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69812 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69813 rp->rtort_mbtest = 0;
69814 list_del(&rp->rtort_free);
69815@@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
69816 i = old_rp->rtort_pipe_count;
69817 if (i > RCU_TORTURE_PIPE_LEN)
69818 i = RCU_TORTURE_PIPE_LEN;
69819- atomic_inc(&rcu_torture_wcount[i]);
69820+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69821 old_rp->rtort_pipe_count++;
69822 cur_ops->deferred_free(old_rp);
69823 }
69824@@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
69825 return;
69826 }
69827 if (p->rtort_mbtest == 0)
69828- atomic_inc(&n_rcu_torture_mberror);
69829+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69830 spin_lock(&rand_lock);
69831 cur_ops->read_delay(&rand);
69832 n_rcu_torture_timers++;
69833@@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
69834 continue;
69835 }
69836 if (p->rtort_mbtest == 0)
69837- atomic_inc(&n_rcu_torture_mberror);
69838+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69839 cur_ops->read_delay(&rand);
69840 preempt_disable();
69841 pipe_count = p->rtort_pipe_count;
69842@@ -1072,10 +1072,10 @@ rcu_torture_printk(char *page)
69843 rcu_torture_current,
69844 rcu_torture_current_version,
69845 list_empty(&rcu_torture_freelist),
69846- atomic_read(&n_rcu_torture_alloc),
69847- atomic_read(&n_rcu_torture_alloc_fail),
69848- atomic_read(&n_rcu_torture_free),
69849- atomic_read(&n_rcu_torture_mberror),
69850+ atomic_read_unchecked(&n_rcu_torture_alloc),
69851+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69852+ atomic_read_unchecked(&n_rcu_torture_free),
69853+ atomic_read_unchecked(&n_rcu_torture_mberror),
69854 n_rcu_torture_boost_ktrerror,
69855 n_rcu_torture_boost_rterror,
69856 n_rcu_torture_boost_allocerror,
69857@@ -1083,7 +1083,7 @@ rcu_torture_printk(char *page)
69858 n_rcu_torture_boost_failure,
69859 n_rcu_torture_boosts,
69860 n_rcu_torture_timers);
69861- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69862+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69863 n_rcu_torture_boost_ktrerror != 0 ||
69864 n_rcu_torture_boost_rterror != 0 ||
69865 n_rcu_torture_boost_allocerror != 0 ||
69866@@ -1093,7 +1093,7 @@ rcu_torture_printk(char *page)
69867 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69868 if (i > 1) {
69869 cnt += sprintf(&page[cnt], "!!! ");
69870- atomic_inc(&n_rcu_torture_error);
69871+ atomic_inc_unchecked(&n_rcu_torture_error);
69872 WARN_ON_ONCE(1);
69873 }
69874 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69875@@ -1107,7 +1107,7 @@ rcu_torture_printk(char *page)
69876 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69877 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69878 cnt += sprintf(&page[cnt], " %d",
69879- atomic_read(&rcu_torture_wcount[i]));
69880+ atomic_read_unchecked(&rcu_torture_wcount[i]));
69881 }
69882 cnt += sprintf(&page[cnt], "\n");
69883 if (cur_ops->stats)
69884@@ -1415,7 +1415,7 @@ rcu_torture_cleanup(void)
69885
69886 if (cur_ops->cleanup)
69887 cur_ops->cleanup();
69888- if (atomic_read(&n_rcu_torture_error))
69889+ if (atomic_read_unchecked(&n_rcu_torture_error))
69890 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69891 else
69892 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
69893@@ -1479,11 +1479,11 @@ rcu_torture_init(void)
69894
69895 rcu_torture_current = NULL;
69896 rcu_torture_current_version = 0;
69897- atomic_set(&n_rcu_torture_alloc, 0);
69898- atomic_set(&n_rcu_torture_alloc_fail, 0);
69899- atomic_set(&n_rcu_torture_free, 0);
69900- atomic_set(&n_rcu_torture_mberror, 0);
69901- atomic_set(&n_rcu_torture_error, 0);
69902+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69903+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69904+ atomic_set_unchecked(&n_rcu_torture_free, 0);
69905+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69906+ atomic_set_unchecked(&n_rcu_torture_error, 0);
69907 n_rcu_torture_boost_ktrerror = 0;
69908 n_rcu_torture_boost_rterror = 0;
69909 n_rcu_torture_boost_allocerror = 0;
69910@@ -1491,7 +1491,7 @@ rcu_torture_init(void)
69911 n_rcu_torture_boost_failure = 0;
69912 n_rcu_torture_boosts = 0;
69913 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69914- atomic_set(&rcu_torture_wcount[i], 0);
69915+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69916 for_each_possible_cpu(cpu) {
69917 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69918 per_cpu(rcu_torture_count, cpu)[i] = 0;
69919diff -urNp linux-2.6.39.1/kernel/rcutree.c linux-2.6.39.1/kernel/rcutree.c
69920--- linux-2.6.39.1/kernel/rcutree.c 2011-05-19 00:06:34.000000000 -0400
69921+++ linux-2.6.39.1/kernel/rcutree.c 2011-05-22 19:36:33.000000000 -0400
69922@@ -1389,7 +1389,7 @@ __rcu_process_callbacks(struct rcu_state
69923 /*
69924 * Do softirq processing for the current CPU.
69925 */
69926-static void rcu_process_callbacks(struct softirq_action *unused)
69927+static void rcu_process_callbacks(void)
69928 {
69929 /*
69930 * Memory references from any prior RCU read-side critical sections
69931diff -urNp linux-2.6.39.1/kernel/rcutree_plugin.h linux-2.6.39.1/kernel/rcutree_plugin.h
69932--- linux-2.6.39.1/kernel/rcutree_plugin.h 2011-05-19 00:06:34.000000000 -0400
69933+++ linux-2.6.39.1/kernel/rcutree_plugin.h 2011-05-22 19:36:33.000000000 -0400
69934@@ -730,7 +730,7 @@ void synchronize_rcu_expedited(void)
69935
69936 /* Clean up and exit. */
69937 smp_mb(); /* ensure expedited GP seen before counter increment. */
69938- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69939+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69940 unlock_mb_ret:
69941 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69942 mb_ret:
69943@@ -1025,8 +1025,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
69944
69945 #else /* #ifndef CONFIG_SMP */
69946
69947-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69948-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69949+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69950+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69951
69952 static int synchronize_sched_expedited_cpu_stop(void *data)
69953 {
69954@@ -1081,7 +1081,7 @@ void synchronize_sched_expedited(void)
69955 int firstsnap, s, snap, trycount = 0;
69956
69957 /* Note that atomic_inc_return() implies full memory barrier. */
69958- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69959+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69960 get_online_cpus();
69961
69962 /*
69963@@ -1102,7 +1102,7 @@ void synchronize_sched_expedited(void)
69964 }
69965
69966 /* Check to see if someone else did our work for us. */
69967- s = atomic_read(&sync_sched_expedited_done);
69968+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69969 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69970 smp_mb(); /* ensure test happens before caller kfree */
69971 return;
69972@@ -1117,7 +1117,7 @@ void synchronize_sched_expedited(void)
69973 * grace period works for us.
69974 */
69975 get_online_cpus();
69976- snap = atomic_read(&sync_sched_expedited_started) - 1;
69977+ snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
69978 smp_mb(); /* ensure read is before try_stop_cpus(). */
69979 }
69980
69981@@ -1128,12 +1128,12 @@ void synchronize_sched_expedited(void)
69982 * than we did beat us to the punch.
69983 */
69984 do {
69985- s = atomic_read(&sync_sched_expedited_done);
69986+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69987 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69988 smp_mb(); /* ensure test happens before caller kfree */
69989 break;
69990 }
69991- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69992+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69993
69994 put_online_cpus();
69995 }
69996diff -urNp linux-2.6.39.1/kernel/relay.c linux-2.6.39.1/kernel/relay.c
69997--- linux-2.6.39.1/kernel/relay.c 2011-05-19 00:06:34.000000000 -0400
69998+++ linux-2.6.39.1/kernel/relay.c 2011-05-22 19:36:33.000000000 -0400
69999@@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
70000 };
70001 ssize_t ret;
70002
70003+ pax_track_stack();
70004+
70005 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
70006 return 0;
70007 if (splice_grow_spd(pipe, &spd))
70008diff -urNp linux-2.6.39.1/kernel/resource.c linux-2.6.39.1/kernel/resource.c
70009--- linux-2.6.39.1/kernel/resource.c 2011-05-19 00:06:34.000000000 -0400
70010+++ linux-2.6.39.1/kernel/resource.c 2011-05-22 19:41:42.000000000 -0400
70011@@ -133,8 +133,18 @@ static const struct file_operations proc
70012
70013 static int __init ioresources_init(void)
70014 {
70015+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70016+#ifdef CONFIG_GRKERNSEC_PROC_USER
70017+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70018+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70019+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70020+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70021+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70022+#endif
70023+#else
70024 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70025 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70026+#endif
70027 return 0;
70028 }
70029 __initcall(ioresources_init);
70030diff -urNp linux-2.6.39.1/kernel/rtmutex-tester.c linux-2.6.39.1/kernel/rtmutex-tester.c
70031--- linux-2.6.39.1/kernel/rtmutex-tester.c 2011-05-19 00:06:34.000000000 -0400
70032+++ linux-2.6.39.1/kernel/rtmutex-tester.c 2011-05-22 19:36:33.000000000 -0400
70033@@ -20,7 +20,7 @@
70034 #define MAX_RT_TEST_MUTEXES 8
70035
70036 static spinlock_t rttest_lock;
70037-static atomic_t rttest_event;
70038+static atomic_unchecked_t rttest_event;
70039
70040 struct test_thread_data {
70041 int opcode;
70042@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
70043
70044 case RTTEST_LOCKCONT:
70045 td->mutexes[td->opdata] = 1;
70046- td->event = atomic_add_return(1, &rttest_event);
70047+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70048 return 0;
70049
70050 case RTTEST_RESET:
70051@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
70052 return 0;
70053
70054 case RTTEST_RESETEVENT:
70055- atomic_set(&rttest_event, 0);
70056+ atomic_set_unchecked(&rttest_event, 0);
70057 return 0;
70058
70059 default:
70060@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
70061 return ret;
70062
70063 td->mutexes[id] = 1;
70064- td->event = atomic_add_return(1, &rttest_event);
70065+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70066 rt_mutex_lock(&mutexes[id]);
70067- td->event = atomic_add_return(1, &rttest_event);
70068+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70069 td->mutexes[id] = 4;
70070 return 0;
70071
70072@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
70073 return ret;
70074
70075 td->mutexes[id] = 1;
70076- td->event = atomic_add_return(1, &rttest_event);
70077+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70078 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70079- td->event = atomic_add_return(1, &rttest_event);
70080+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70081 td->mutexes[id] = ret ? 0 : 4;
70082 return ret ? -EINTR : 0;
70083
70084@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
70085 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70086 return ret;
70087
70088- td->event = atomic_add_return(1, &rttest_event);
70089+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70090 rt_mutex_unlock(&mutexes[id]);
70091- td->event = atomic_add_return(1, &rttest_event);
70092+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70093 td->mutexes[id] = 0;
70094 return 0;
70095
70096@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
70097 break;
70098
70099 td->mutexes[dat] = 2;
70100- td->event = atomic_add_return(1, &rttest_event);
70101+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70102 break;
70103
70104 default:
70105@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
70106 return;
70107
70108 td->mutexes[dat] = 3;
70109- td->event = atomic_add_return(1, &rttest_event);
70110+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70111 break;
70112
70113 case RTTEST_LOCKNOWAIT:
70114@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
70115 return;
70116
70117 td->mutexes[dat] = 1;
70118- td->event = atomic_add_return(1, &rttest_event);
70119+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70120 return;
70121
70122 default:
70123diff -urNp linux-2.6.39.1/kernel/sched_autogroup.c linux-2.6.39.1/kernel/sched_autogroup.c
70124--- linux-2.6.39.1/kernel/sched_autogroup.c 2011-05-19 00:06:34.000000000 -0400
70125+++ linux-2.6.39.1/kernel/sched_autogroup.c 2011-05-22 19:36:33.000000000 -0400
70126@@ -7,7 +7,7 @@
70127
70128 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70129 static struct autogroup autogroup_default;
70130-static atomic_t autogroup_seq_nr;
70131+static atomic_unchecked_t autogroup_seq_nr;
70132
70133 static void __init autogroup_init(struct task_struct *init_task)
70134 {
70135@@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
70136
70137 kref_init(&ag->kref);
70138 init_rwsem(&ag->lock);
70139- ag->id = atomic_inc_return(&autogroup_seq_nr);
70140+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70141 ag->tg = tg;
70142 #ifdef CONFIG_RT_GROUP_SCHED
70143 /*
70144diff -urNp linux-2.6.39.1/kernel/sched.c linux-2.6.39.1/kernel/sched.c
70145--- linux-2.6.39.1/kernel/sched.c 2011-05-19 00:06:34.000000000 -0400
70146+++ linux-2.6.39.1/kernel/sched.c 2011-05-23 17:07:00.000000000 -0400
70147@@ -4078,6 +4078,8 @@ asmlinkage void __sched schedule(void)
70148 struct rq *rq;
70149 int cpu;
70150
70151+ pax_track_stack();
70152+
70153 need_resched:
70154 preempt_disable();
70155 cpu = smp_processor_id();
70156@@ -4165,7 +4167,7 @@ EXPORT_SYMBOL(schedule);
70157 * Look out! "owner" is an entirely speculative pointer
70158 * access and not reliable.
70159 */
70160-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
70161+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
70162 {
70163 unsigned int cpu;
70164 struct rq *rq;
70165@@ -4179,10 +4181,10 @@ int mutex_spin_on_owner(struct mutex *lo
70166 * DEBUG_PAGEALLOC could have unmapped it if
70167 * the mutex owner just released it and exited.
70168 */
70169- if (probe_kernel_address(&owner->cpu, cpu))
70170+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
70171 return 0;
70172 #else
70173- cpu = owner->cpu;
70174+ cpu = task_thread_info(owner)->cpu;
70175 #endif
70176
70177 /*
70178@@ -4219,7 +4221,7 @@ int mutex_spin_on_owner(struct mutex *lo
70179 /*
70180 * Is that owner really running on that cpu?
70181 */
70182- if (task_thread_info(rq->curr) != owner || need_resched())
70183+ if (rq->curr != owner || need_resched())
70184 return 0;
70185
70186 arch_mutex_cpu_relax();
70187@@ -4778,6 +4780,8 @@ int can_nice(const struct task_struct *p
70188 /* convert nice value [19,-20] to rlimit style value [1,40] */
70189 int nice_rlim = 20 - nice;
70190
70191+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70192+
70193 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70194 capable(CAP_SYS_NICE));
70195 }
70196@@ -4811,7 +4815,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70197 if (nice > 19)
70198 nice = 19;
70199
70200- if (increment < 0 && !can_nice(current, nice))
70201+ if (increment < 0 && (!can_nice(current, nice) ||
70202+ gr_handle_chroot_nice()))
70203 return -EPERM;
70204
70205 retval = security_task_setnice(current, nice);
70206@@ -4957,6 +4962,7 @@ recheck:
70207 unsigned long rlim_rtprio =
70208 task_rlimit(p, RLIMIT_RTPRIO);
70209
70210+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70211 /* can't set/change the rt policy */
70212 if (policy != p->policy && !rlim_rtprio)
70213 return -EPERM;
70214@@ -7164,7 +7170,7 @@ static void init_sched_groups_power(int
70215 long power;
70216 int weight;
70217
70218- WARN_ON(!sd || !sd->groups);
70219+ BUG_ON(!sd || !sd->groups);
70220
70221 if (cpu != group_first_cpu(sd->groups))
70222 return;
70223diff -urNp linux-2.6.39.1/kernel/sched_fair.c linux-2.6.39.1/kernel/sched_fair.c
70224--- linux-2.6.39.1/kernel/sched_fair.c 2011-05-19 00:06:34.000000000 -0400
70225+++ linux-2.6.39.1/kernel/sched_fair.c 2011-05-22 19:36:33.000000000 -0400
70226@@ -3999,7 +3999,7 @@ static void nohz_idle_balance(int this_c
70227 * run_rebalance_domains is triggered when needed from the scheduler tick.
70228 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70229 */
70230-static void run_rebalance_domains(struct softirq_action *h)
70231+static void run_rebalance_domains(void)
70232 {
70233 int this_cpu = smp_processor_id();
70234 struct rq *this_rq = cpu_rq(this_cpu);
70235diff -urNp linux-2.6.39.1/kernel/signal.c linux-2.6.39.1/kernel/signal.c
70236--- linux-2.6.39.1/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
70237+++ linux-2.6.39.1/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
70238@@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
70239
70240 int print_fatal_signals __read_mostly;
70241
70242-static void __user *sig_handler(struct task_struct *t, int sig)
70243+static __sighandler_t sig_handler(struct task_struct *t, int sig)
70244 {
70245 return t->sighand->action[sig - 1].sa.sa_handler;
70246 }
70247
70248-static int sig_handler_ignored(void __user *handler, int sig)
70249+static int sig_handler_ignored(__sighandler_t handler, int sig)
70250 {
70251 /* Is it explicitly or implicitly ignored? */
70252 return handler == SIG_IGN ||
70253@@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
70254 static int sig_task_ignored(struct task_struct *t, int sig,
70255 int from_ancestor_ns)
70256 {
70257- void __user *handler;
70258+ __sighandler_t handler;
70259
70260 handler = sig_handler(t, sig);
70261
70262@@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
70263 atomic_inc(&user->sigpending);
70264 rcu_read_unlock();
70265
70266+ if (!override_rlimit)
70267+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70268+
70269 if (override_rlimit ||
70270 atomic_read(&user->sigpending) <=
70271 task_rlimit(t, RLIMIT_SIGPENDING)) {
70272@@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
70273
70274 int unhandled_signal(struct task_struct *tsk, int sig)
70275 {
70276- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70277+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70278 if (is_global_init(tsk))
70279 return 1;
70280 if (handler != SIG_IGN && handler != SIG_DFL)
70281@@ -693,6 +696,9 @@ static int check_kill_permission(int sig
70282 }
70283 }
70284
70285+ if (gr_handle_signal(t, sig))
70286+ return -EPERM;
70287+
70288 return security_task_kill(t, info, sig, 0);
70289 }
70290
70291@@ -1041,7 +1047,7 @@ __group_send_sig_info(int sig, struct si
70292 return send_signal(sig, info, p, 1);
70293 }
70294
70295-static int
70296+int
70297 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70298 {
70299 return send_signal(sig, info, t, 0);
70300@@ -1078,6 +1084,7 @@ force_sig_info(int sig, struct siginfo *
70301 unsigned long int flags;
70302 int ret, blocked, ignored;
70303 struct k_sigaction *action;
70304+ int is_unhandled = 0;
70305
70306 spin_lock_irqsave(&t->sighand->siglock, flags);
70307 action = &t->sighand->action[sig-1];
70308@@ -1092,9 +1099,18 @@ force_sig_info(int sig, struct siginfo *
70309 }
70310 if (action->sa.sa_handler == SIG_DFL)
70311 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70312+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70313+ is_unhandled = 1;
70314 ret = specific_send_sig_info(sig, info, t);
70315 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70316
70317+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
70318+ normal operation */
70319+ if (is_unhandled) {
70320+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70321+ gr_handle_crash(t, sig);
70322+ }
70323+
70324 return ret;
70325 }
70326
70327@@ -1153,8 +1169,11 @@ int group_send_sig_info(int sig, struct
70328 ret = check_kill_permission(sig, info, p);
70329 rcu_read_unlock();
70330
70331- if (!ret && sig)
70332+ if (!ret && sig) {
70333 ret = do_send_sig_info(sig, info, p, true);
70334+ if (!ret)
70335+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70336+ }
70337
70338 return ret;
70339 }
70340@@ -1718,6 +1737,8 @@ void ptrace_notify(int exit_code)
70341 {
70342 siginfo_t info;
70343
70344+ pax_track_stack();
70345+
70346 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
70347
70348 memset(&info, 0, sizeof info);
70349diff -urNp linux-2.6.39.1/kernel/smp.c linux-2.6.39.1/kernel/smp.c
70350--- linux-2.6.39.1/kernel/smp.c 2011-05-19 00:06:34.000000000 -0400
70351+++ linux-2.6.39.1/kernel/smp.c 2011-05-22 19:36:33.000000000 -0400
70352@@ -583,22 +583,22 @@ int smp_call_function(smp_call_func_t fu
70353 }
70354 EXPORT_SYMBOL(smp_call_function);
70355
70356-void ipi_call_lock(void)
70357+void ipi_call_lock(void) __acquires(call_function.lock)
70358 {
70359 raw_spin_lock(&call_function.lock);
70360 }
70361
70362-void ipi_call_unlock(void)
70363+void ipi_call_unlock(void) __releases(call_function.lock)
70364 {
70365 raw_spin_unlock(&call_function.lock);
70366 }
70367
70368-void ipi_call_lock_irq(void)
70369+void ipi_call_lock_irq(void) __acquires(call_function.lock)
70370 {
70371 raw_spin_lock_irq(&call_function.lock);
70372 }
70373
70374-void ipi_call_unlock_irq(void)
70375+void ipi_call_unlock_irq(void) __releases(call_function.lock)
70376 {
70377 raw_spin_unlock_irq(&call_function.lock);
70378 }
70379diff -urNp linux-2.6.39.1/kernel/softirq.c linux-2.6.39.1/kernel/softirq.c
70380--- linux-2.6.39.1/kernel/softirq.c 2011-05-19 00:06:34.000000000 -0400
70381+++ linux-2.6.39.1/kernel/softirq.c 2011-05-22 19:36:33.000000000 -0400
70382@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
70383
70384 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70385
70386-char *softirq_to_name[NR_SOFTIRQS] = {
70387+const char * const softirq_to_name[NR_SOFTIRQS] = {
70388 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70389 "TASKLET", "SCHED", "HRTIMER", "RCU"
70390 };
70391@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
70392
70393 asmlinkage void __do_softirq(void)
70394 {
70395- struct softirq_action *h;
70396+ const struct softirq_action *h;
70397 __u32 pending;
70398 int max_restart = MAX_SOFTIRQ_RESTART;
70399 int cpu;
70400@@ -235,7 +235,7 @@ restart:
70401 kstat_incr_softirqs_this_cpu(vec_nr);
70402
70403 trace_softirq_entry(vec_nr);
70404- h->action(h);
70405+ h->action();
70406 trace_softirq_exit(vec_nr);
70407 if (unlikely(prev_count != preempt_count())) {
70408 printk(KERN_ERR "huh, entered softirq %u %s %p"
70409@@ -377,7 +377,7 @@ void raise_softirq(unsigned int nr)
70410 local_irq_restore(flags);
70411 }
70412
70413-void open_softirq(int nr, void (*action)(struct softirq_action *))
70414+void open_softirq(int nr, void (*action)(void))
70415 {
70416 softirq_vec[nr].action = action;
70417 }
70418@@ -433,7 +433,7 @@ void __tasklet_hi_schedule_first(struct
70419
70420 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70421
70422-static void tasklet_action(struct softirq_action *a)
70423+static void tasklet_action(void)
70424 {
70425 struct tasklet_struct *list;
70426
70427@@ -468,7 +468,7 @@ static void tasklet_action(struct softir
70428 }
70429 }
70430
70431-static void tasklet_hi_action(struct softirq_action *a)
70432+static void tasklet_hi_action(void)
70433 {
70434 struct tasklet_struct *list;
70435
70436diff -urNp linux-2.6.39.1/kernel/sys.c linux-2.6.39.1/kernel/sys.c
70437--- linux-2.6.39.1/kernel/sys.c 2011-05-19 00:06:34.000000000 -0400
70438+++ linux-2.6.39.1/kernel/sys.c 2011-05-22 21:08:10.000000000 -0400
70439@@ -154,6 +154,12 @@ static int set_one_prio(struct task_stru
70440 error = -EACCES;
70441 goto out;
70442 }
70443+
70444+ if (gr_handle_chroot_setpriority(p, niceval)) {
70445+ error = -EACCES;
70446+ goto out;
70447+ }
70448+
70449 no_nice = security_task_setnice(p, niceval);
70450 if (no_nice) {
70451 error = no_nice;
70452@@ -538,6 +544,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
70453 goto error;
70454 }
70455
70456+ if (gr_check_group_change(new->gid, new->egid, -1))
70457+ goto error;
70458+
70459 if (rgid != (gid_t) -1 ||
70460 (egid != (gid_t) -1 && egid != old->gid))
70461 new->sgid = new->egid;
70462@@ -567,6 +576,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70463 old = current_cred();
70464
70465 retval = -EPERM;
70466+
70467+ if (gr_check_group_change(gid, gid, gid))
70468+ goto error;
70469+
70470 if (nsown_capable(CAP_SETGID))
70471 new->gid = new->egid = new->sgid = new->fsgid = gid;
70472 else if (gid == old->gid || gid == old->sgid)
70473@@ -647,6 +660,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
70474 goto error;
70475 }
70476
70477+ if (gr_check_user_change(new->uid, new->euid, -1))
70478+ goto error;
70479+
70480 if (new->uid != old->uid) {
70481 retval = set_user(new);
70482 if (retval < 0)
70483@@ -691,6 +707,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70484 old = current_cred();
70485
70486 retval = -EPERM;
70487+
70488+ if (gr_check_crash_uid(uid))
70489+ goto error;
70490+ if (gr_check_user_change(uid, uid, uid))
70491+ goto error;
70492+
70493 if (nsown_capable(CAP_SETUID)) {
70494 new->suid = new->uid = uid;
70495 if (uid != old->uid) {
70496@@ -745,6 +767,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
70497 goto error;
70498 }
70499
70500+ if (gr_check_user_change(ruid, euid, -1))
70501+ goto error;
70502+
70503 if (ruid != (uid_t) -1) {
70504 new->uid = ruid;
70505 if (ruid != old->uid) {
70506@@ -809,6 +834,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
70507 goto error;
70508 }
70509
70510+ if (gr_check_group_change(rgid, egid, -1))
70511+ goto error;
70512+
70513 if (rgid != (gid_t) -1)
70514 new->gid = rgid;
70515 if (egid != (gid_t) -1)
70516@@ -855,6 +883,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70517 old = current_cred();
70518 old_fsuid = old->fsuid;
70519
70520+ if (gr_check_user_change(-1, -1, uid))
70521+ goto error;
70522+
70523 if (uid == old->uid || uid == old->euid ||
70524 uid == old->suid || uid == old->fsuid ||
70525 nsown_capable(CAP_SETUID)) {
70526@@ -865,6 +896,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70527 }
70528 }
70529
70530+error:
70531 abort_creds(new);
70532 return old_fsuid;
70533
70534@@ -891,12 +923,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70535 if (gid == old->gid || gid == old->egid ||
70536 gid == old->sgid || gid == old->fsgid ||
70537 nsown_capable(CAP_SETGID)) {
70538+ if (gr_check_group_change(-1, -1, gid))
70539+ goto error;
70540+
70541 if (gid != old_fsgid) {
70542 new->fsgid = gid;
70543 goto change_okay;
70544 }
70545 }
70546
70547+error:
70548 abort_creds(new);
70549 return old_fsgid;
70550
70551@@ -1643,7 +1679,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
70552 error = get_dumpable(me->mm);
70553 break;
70554 case PR_SET_DUMPABLE:
70555- if (arg2 < 0 || arg2 > 1) {
70556+ if (arg2 > 1) {
70557 error = -EINVAL;
70558 break;
70559 }
70560diff -urNp linux-2.6.39.1/kernel/sysctl.c linux-2.6.39.1/kernel/sysctl.c
70561--- linux-2.6.39.1/kernel/sysctl.c 2011-05-19 00:06:34.000000000 -0400
70562+++ linux-2.6.39.1/kernel/sysctl.c 2011-05-22 20:23:10.000000000 -0400
70563@@ -84,6 +84,13 @@
70564
70565
70566 #if defined(CONFIG_SYSCTL)
70567+#include <linux/grsecurity.h>
70568+#include <linux/grinternal.h>
70569+
70570+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70571+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70572+ const int op);
70573+extern int gr_handle_chroot_sysctl(const int op);
70574
70575 /* External variables not in a header file. */
70576 extern int sysctl_overcommit_memory;
70577@@ -196,6 +203,7 @@ static int sysrq_sysctl_handler(ctl_tabl
70578 }
70579
70580 #endif
70581+extern struct ctl_table grsecurity_table[];
70582
70583 static struct ctl_table root_table[];
70584 static struct ctl_table_root sysctl_table_root;
70585@@ -225,6 +233,20 @@ extern struct ctl_table epoll_table[];
70586 int sysctl_legacy_va_layout;
70587 #endif
70588
70589+#ifdef CONFIG_PAX_SOFTMODE
70590+static ctl_table pax_table[] = {
70591+ {
70592+ .procname = "softmode",
70593+ .data = &pax_softmode,
70594+ .maxlen = sizeof(unsigned int),
70595+ .mode = 0600,
70596+ .proc_handler = &proc_dointvec,
70597+ },
70598+
70599+ { }
70600+};
70601+#endif
70602+
70603 /* The default sysctl tables: */
70604
70605 static struct ctl_table root_table[] = {
70606@@ -271,6 +293,22 @@ static int max_extfrag_threshold = 1000;
70607 #endif
70608
70609 static struct ctl_table kern_table[] = {
70610+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70611+ {
70612+ .procname = "grsecurity",
70613+ .mode = 0500,
70614+ .child = grsecurity_table,
70615+ },
70616+#endif
70617+
70618+#ifdef CONFIG_PAX_SOFTMODE
70619+ {
70620+ .procname = "pax",
70621+ .mode = 0500,
70622+ .child = pax_table,
70623+ },
70624+#endif
70625+
70626 {
70627 .procname = "sched_child_runs_first",
70628 .data = &sysctl_sched_child_runs_first,
70629@@ -545,7 +583,7 @@ static struct ctl_table kern_table[] = {
70630 .data = &modprobe_path,
70631 .maxlen = KMOD_PATH_LEN,
70632 .mode = 0644,
70633- .proc_handler = proc_dostring,
70634+ .proc_handler = proc_dostring_modpriv,
70635 },
70636 {
70637 .procname = "modules_disabled",
70638@@ -707,16 +745,20 @@ static struct ctl_table kern_table[] = {
70639 .extra1 = &zero,
70640 .extra2 = &one,
70641 },
70642+#endif
70643 {
70644 .procname = "kptr_restrict",
70645 .data = &kptr_restrict,
70646 .maxlen = sizeof(int),
70647 .mode = 0644,
70648 .proc_handler = proc_dmesg_restrict,
70649+#ifdef CONFIG_GRKERNSEC_HIDESYM
70650+ .extra1 = &two,
70651+#else
70652 .extra1 = &zero,
70653+#endif
70654 .extra2 = &two,
70655 },
70656-#endif
70657 {
70658 .procname = "ngroups_max",
70659 .data = &ngroups_max,
70660@@ -1189,6 +1231,13 @@ static struct ctl_table vm_table[] = {
70661 .proc_handler = proc_dointvec_minmax,
70662 .extra1 = &zero,
70663 },
70664+ {
70665+ .procname = "heap_stack_gap",
70666+ .data = &sysctl_heap_stack_gap,
70667+ .maxlen = sizeof(sysctl_heap_stack_gap),
70668+ .mode = 0644,
70669+ .proc_handler = proc_doulongvec_minmax,
70670+ },
70671 #else
70672 {
70673 .procname = "nr_trim_pages",
70674@@ -1698,6 +1747,17 @@ static int test_perm(int mode, int op)
70675 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
70676 {
70677 int mode;
70678+ int error;
70679+
70680+ if (table->parent != NULL && table->parent->procname != NULL &&
70681+ table->procname != NULL &&
70682+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70683+ return -EACCES;
70684+ if (gr_handle_chroot_sysctl(op))
70685+ return -EACCES;
70686+ error = gr_handle_sysctl(table, op);
70687+ if (error)
70688+ return error;
70689
70690 if (root->permissions)
70691 mode = root->permissions(root, current->nsproxy, table);
70692@@ -2102,6 +2162,16 @@ int proc_dostring(struct ctl_table *tabl
70693 buffer, lenp, ppos);
70694 }
70695
70696+int proc_dostring_modpriv(struct ctl_table *table, int write,
70697+ void __user *buffer, size_t *lenp, loff_t *ppos)
70698+{
70699+ if (write && !capable(CAP_SYS_MODULE))
70700+ return -EPERM;
70701+
70702+ return _proc_do_string(table->data, table->maxlen, write,
70703+ buffer, lenp, ppos);
70704+}
70705+
70706 static size_t proc_skip_spaces(char **buf)
70707 {
70708 size_t ret;
70709@@ -2207,6 +2277,8 @@ static int proc_put_long(void __user **b
70710 len = strlen(tmp);
70711 if (len > *size)
70712 len = *size;
70713+ if (len > sizeof(tmp))
70714+ len = sizeof(tmp);
70715 if (copy_to_user(*buf, tmp, len))
70716 return -EFAULT;
70717 *size -= len;
70718@@ -2523,8 +2595,11 @@ static int __do_proc_doulongvec_minmax(v
70719 *i = val;
70720 } else {
70721 val = convdiv * (*i) / convmul;
70722- if (!first)
70723+ if (!first) {
70724 err = proc_put_char(&buffer, &left, '\t');
70725+ if (err)
70726+ break;
70727+ }
70728 err = proc_put_long(&buffer, &left, val, false);
70729 if (err)
70730 break;
70731@@ -2919,6 +2994,12 @@ int proc_dostring(struct ctl_table *tabl
70732 return -ENOSYS;
70733 }
70734
70735+int proc_dostring_modpriv(struct ctl_table *table, int write,
70736+ void __user *buffer, size_t *lenp, loff_t *ppos)
70737+{
70738+ return -ENOSYS;
70739+}
70740+
70741 int proc_dointvec(struct ctl_table *table, int write,
70742 void __user *buffer, size_t *lenp, loff_t *ppos)
70743 {
70744@@ -2975,6 +3056,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70745 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70746 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70747 EXPORT_SYMBOL(proc_dostring);
70748+EXPORT_SYMBOL(proc_dostring_modpriv);
70749 EXPORT_SYMBOL(proc_doulongvec_minmax);
70750 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70751 EXPORT_SYMBOL(register_sysctl_table);
70752diff -urNp linux-2.6.39.1/kernel/sysctl_check.c linux-2.6.39.1/kernel/sysctl_check.c
70753--- linux-2.6.39.1/kernel/sysctl_check.c 2011-05-19 00:06:34.000000000 -0400
70754+++ linux-2.6.39.1/kernel/sysctl_check.c 2011-05-22 19:41:42.000000000 -0400
70755@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
70756 set_fail(&fail, table, "Directory with extra2");
70757 } else {
70758 if ((table->proc_handler == proc_dostring) ||
70759+ (table->proc_handler == proc_dostring_modpriv) ||
70760 (table->proc_handler == proc_dointvec) ||
70761 (table->proc_handler == proc_dointvec_minmax) ||
70762 (table->proc_handler == proc_dointvec_jiffies) ||
70763diff -urNp linux-2.6.39.1/kernel/taskstats.c linux-2.6.39.1/kernel/taskstats.c
70764--- linux-2.6.39.1/kernel/taskstats.c 2011-05-19 00:06:34.000000000 -0400
70765+++ linux-2.6.39.1/kernel/taskstats.c 2011-05-22 19:41:42.000000000 -0400
70766@@ -27,9 +27,12 @@
70767 #include <linux/cgroup.h>
70768 #include <linux/fs.h>
70769 #include <linux/file.h>
70770+#include <linux/grsecurity.h>
70771 #include <net/genetlink.h>
70772 #include <asm/atomic.h>
70773
70774+extern int gr_is_taskstats_denied(int pid);
70775+
70776 /*
70777 * Maximum length of a cpumask that can be specified in
70778 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70779@@ -549,6 +552,9 @@ err:
70780
70781 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70782 {
70783+ if (gr_is_taskstats_denied(current->pid))
70784+ return -EACCES;
70785+
70786 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70787 return cmd_attr_register_cpumask(info);
70788 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70789diff -urNp linux-2.6.39.1/kernel/time/posix-clock.c linux-2.6.39.1/kernel/time/posix-clock.c
70790--- linux-2.6.39.1/kernel/time/posix-clock.c 2011-05-19 00:06:34.000000000 -0400
70791+++ linux-2.6.39.1/kernel/time/posix-clock.c 2011-05-22 19:36:33.000000000 -0400
70792@@ -433,7 +433,7 @@ static int pc_timer_settime(struct k_iti
70793 return err;
70794 }
70795
70796-struct k_clock clock_posix_dynamic = {
70797+const struct k_clock clock_posix_dynamic = {
70798 .clock_getres = pc_clock_getres,
70799 .clock_set = pc_clock_settime,
70800 .clock_get = pc_clock_gettime,
70801diff -urNp linux-2.6.39.1/kernel/time/tick-broadcast.c linux-2.6.39.1/kernel/time/tick-broadcast.c
70802--- linux-2.6.39.1/kernel/time/tick-broadcast.c 2011-05-19 00:06:34.000000000 -0400
70803+++ linux-2.6.39.1/kernel/time/tick-broadcast.c 2011-05-22 19:36:33.000000000 -0400
70804@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
70805 * then clear the broadcast bit.
70806 */
70807 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70808- int cpu = smp_processor_id();
70809+ cpu = smp_processor_id();
70810
70811 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70812 tick_broadcast_clear_oneshot(cpu);
70813diff -urNp linux-2.6.39.1/kernel/time/timekeeping.c linux-2.6.39.1/kernel/time/timekeeping.c
70814--- linux-2.6.39.1/kernel/time/timekeeping.c 2011-05-19 00:06:34.000000000 -0400
70815+++ linux-2.6.39.1/kernel/time/timekeeping.c 2011-05-22 20:40:50.000000000 -0400
70816@@ -14,6 +14,7 @@
70817 #include <linux/init.h>
70818 #include <linux/mm.h>
70819 #include <linux/sched.h>
70820+#include <linux/grsecurity.h>
70821 #include <linux/syscore_ops.h>
70822 #include <linux/clocksource.h>
70823 #include <linux/jiffies.h>
70824@@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
70825 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70826 return -EINVAL;
70827
70828+ gr_log_timechange();
70829+
70830 write_seqlock_irqsave(&xtime_lock, flags);
70831
70832 timekeeping_forward_now();
70833diff -urNp linux-2.6.39.1/kernel/time/timer_list.c linux-2.6.39.1/kernel/time/timer_list.c
70834--- linux-2.6.39.1/kernel/time/timer_list.c 2011-05-19 00:06:34.000000000 -0400
70835+++ linux-2.6.39.1/kernel/time/timer_list.c 2011-05-22 19:41:42.000000000 -0400
70836@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
70837
70838 static void print_name_offset(struct seq_file *m, void *sym)
70839 {
70840+#ifdef CONFIG_GRKERNSEC_HIDESYM
70841+ SEQ_printf(m, "<%p>", NULL);
70842+#else
70843 char symname[KSYM_NAME_LEN];
70844
70845 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70846 SEQ_printf(m, "<%pK>", sym);
70847 else
70848 SEQ_printf(m, "%s", symname);
70849+#endif
70850 }
70851
70852 static void
70853@@ -112,7 +116,11 @@ next_one:
70854 static void
70855 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70856 {
70857+#ifdef CONFIG_GRKERNSEC_HIDESYM
70858+ SEQ_printf(m, " .base: %p\n", NULL);
70859+#else
70860 SEQ_printf(m, " .base: %pK\n", base);
70861+#endif
70862 SEQ_printf(m, " .index: %d\n",
70863 base->index);
70864 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70865@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
70866 {
70867 struct proc_dir_entry *pe;
70868
70869+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70870+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70871+#else
70872 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70873+#endif
70874 if (!pe)
70875 return -ENOMEM;
70876 return 0;
70877diff -urNp linux-2.6.39.1/kernel/time/timer_stats.c linux-2.6.39.1/kernel/time/timer_stats.c
70878--- linux-2.6.39.1/kernel/time/timer_stats.c 2011-05-19 00:06:34.000000000 -0400
70879+++ linux-2.6.39.1/kernel/time/timer_stats.c 2011-05-22 19:41:42.000000000 -0400
70880@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70881 static unsigned long nr_entries;
70882 static struct entry entries[MAX_ENTRIES];
70883
70884-static atomic_t overflow_count;
70885+static atomic_unchecked_t overflow_count;
70886
70887 /*
70888 * The entries are in a hash-table, for fast lookup:
70889@@ -140,7 +140,7 @@ static void reset_entries(void)
70890 nr_entries = 0;
70891 memset(entries, 0, sizeof(entries));
70892 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70893- atomic_set(&overflow_count, 0);
70894+ atomic_set_unchecked(&overflow_count, 0);
70895 }
70896
70897 static struct entry *alloc_entry(void)
70898@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
70899 if (likely(entry))
70900 entry->count++;
70901 else
70902- atomic_inc(&overflow_count);
70903+ atomic_inc_unchecked(&overflow_count);
70904
70905 out_unlock:
70906 raw_spin_unlock_irqrestore(lock, flags);
70907@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
70908
70909 static void print_name_offset(struct seq_file *m, unsigned long addr)
70910 {
70911+#ifdef CONFIG_GRKERNSEC_HIDESYM
70912+ seq_printf(m, "<%p>", NULL);
70913+#else
70914 char symname[KSYM_NAME_LEN];
70915
70916 if (lookup_symbol_name(addr, symname) < 0)
70917 seq_printf(m, "<%p>", (void *)addr);
70918 else
70919 seq_printf(m, "%s", symname);
70920+#endif
70921 }
70922
70923 static int tstats_show(struct seq_file *m, void *v)
70924@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
70925
70926 seq_puts(m, "Timer Stats Version: v0.2\n");
70927 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70928- if (atomic_read(&overflow_count))
70929+ if (atomic_read_unchecked(&overflow_count))
70930 seq_printf(m, "Overflow: %d entries\n",
70931- atomic_read(&overflow_count));
70932+ atomic_read_unchecked(&overflow_count));
70933
70934 for (i = 0; i < nr_entries; i++) {
70935 entry = entries + i;
70936@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
70937 {
70938 struct proc_dir_entry *pe;
70939
70940+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70941+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70942+#else
70943 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70944+#endif
70945 if (!pe)
70946 return -ENOMEM;
70947 return 0;
70948diff -urNp linux-2.6.39.1/kernel/time.c linux-2.6.39.1/kernel/time.c
70949--- linux-2.6.39.1/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
70950+++ linux-2.6.39.1/kernel/time.c 2011-05-22 19:41:42.000000000 -0400
70951@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
70952 return error;
70953
70954 if (tz) {
70955+ /* we log in do_settimeofday called below, so don't log twice
70956+ */
70957+ if (!tv)
70958+ gr_log_timechange();
70959+
70960 /* SMP safe, global irq locking makes it work. */
70961 sys_tz = *tz;
70962 update_vsyscall_tz();
70963diff -urNp linux-2.6.39.1/kernel/timer.c linux-2.6.39.1/kernel/timer.c
70964--- linux-2.6.39.1/kernel/timer.c 2011-05-19 00:06:34.000000000 -0400
70965+++ linux-2.6.39.1/kernel/timer.c 2011-05-22 19:36:33.000000000 -0400
70966@@ -1305,7 +1305,7 @@ void update_process_times(int user_tick)
70967 /*
70968 * This function runs timers and the timer-tq in bottom half context.
70969 */
70970-static void run_timer_softirq(struct softirq_action *h)
70971+static void run_timer_softirq(void)
70972 {
70973 struct tvec_base *base = __this_cpu_read(tvec_bases);
70974
70975diff -urNp linux-2.6.39.1/kernel/trace/blktrace.c linux-2.6.39.1/kernel/trace/blktrace.c
70976--- linux-2.6.39.1/kernel/trace/blktrace.c 2011-05-19 00:06:34.000000000 -0400
70977+++ linux-2.6.39.1/kernel/trace/blktrace.c 2011-05-22 19:36:33.000000000 -0400
70978@@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
70979 struct blk_trace *bt = filp->private_data;
70980 char buf[16];
70981
70982- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70983+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70984
70985 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70986 }
70987@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
70988 return 1;
70989
70990 bt = buf->chan->private_data;
70991- atomic_inc(&bt->dropped);
70992+ atomic_inc_unchecked(&bt->dropped);
70993 return 0;
70994 }
70995
70996@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
70997
70998 bt->dir = dir;
70999 bt->dev = dev;
71000- atomic_set(&bt->dropped, 0);
71001+ atomic_set_unchecked(&bt->dropped, 0);
71002
71003 ret = -EIO;
71004 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71005diff -urNp linux-2.6.39.1/kernel/trace/ftrace.c linux-2.6.39.1/kernel/trace/ftrace.c
71006--- linux-2.6.39.1/kernel/trace/ftrace.c 2011-06-03 00:04:14.000000000 -0400
71007+++ linux-2.6.39.1/kernel/trace/ftrace.c 2011-06-03 00:32:08.000000000 -0400
71008@@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
71009
71010 ip = rec->ip;
71011
71012+ ret = ftrace_arch_code_modify_prepare();
71013+ FTRACE_WARN_ON(ret);
71014+ if (ret)
71015+ return 0;
71016+
71017 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71018+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71019 if (ret) {
71020 ftrace_bug(ret, ip);
71021 rec->flags |= FTRACE_FL_FAILED;
71022- return 0;
71023 }
71024- return 1;
71025+ return ret ? 0 : 1;
71026 }
71027
71028 /*
71029@@ -2011,7 +2016,7 @@ static void ftrace_free_entry_rcu(struct
71030
71031 int
71032 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71033- void *data)
71034+ void *data)
71035 {
71036 struct ftrace_func_probe *entry;
71037 struct ftrace_page *pg;
71038@@ -2083,7 +2088,7 @@ enum {
71039 };
71040
71041 static void
71042-__unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71043+__unregister_ftrace_function_probe(char *glob, const struct ftrace_probe_ops *ops,
71044 void *data, int flags)
71045 {
71046 struct ftrace_func_probe *entry;
71047@@ -2144,7 +2149,7 @@ unregister_ftrace_function_probe(char *g
71048 }
71049
71050 void
71051-unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
71052+unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops)
71053 {
71054 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
71055 }
71056diff -urNp linux-2.6.39.1/kernel/trace/trace.c linux-2.6.39.1/kernel/trace/trace.c
71057--- linux-2.6.39.1/kernel/trace/trace.c 2011-05-19 00:06:34.000000000 -0400
71058+++ linux-2.6.39.1/kernel/trace/trace.c 2011-05-22 19:36:33.000000000 -0400
71059@@ -3330,6 +3330,8 @@ static ssize_t tracing_splice_read_pipe(
71060 size_t rem;
71061 unsigned int i;
71062
71063+ pax_track_stack();
71064+
71065 if (splice_grow_spd(pipe, &spd))
71066 return -ENOMEM;
71067
71068@@ -3813,6 +3815,8 @@ tracing_buffers_splice_read(struct file
71069 int entries, size, i;
71070 size_t ret;
71071
71072+ pax_track_stack();
71073+
71074 if (splice_grow_spd(pipe, &spd))
71075 return -ENOMEM;
71076
71077@@ -3981,10 +3985,9 @@ static const struct file_operations trac
71078 };
71079 #endif
71080
71081-static struct dentry *d_tracer;
71082-
71083 struct dentry *tracing_init_dentry(void)
71084 {
71085+ static struct dentry *d_tracer;
71086 static int once;
71087
71088 if (d_tracer)
71089@@ -4004,10 +4007,9 @@ struct dentry *tracing_init_dentry(void)
71090 return d_tracer;
71091 }
71092
71093-static struct dentry *d_percpu;
71094-
71095 struct dentry *tracing_dentry_percpu(void)
71096 {
71097+ static struct dentry *d_percpu;
71098 static int once;
71099 struct dentry *d_tracer;
71100
71101diff -urNp linux-2.6.39.1/kernel/trace/trace_events.c linux-2.6.39.1/kernel/trace/trace_events.c
71102--- linux-2.6.39.1/kernel/trace/trace_events.c 2011-05-19 00:06:34.000000000 -0400
71103+++ linux-2.6.39.1/kernel/trace/trace_events.c 2011-05-22 19:36:33.000000000 -0400
71104@@ -1241,10 +1241,10 @@ static LIST_HEAD(ftrace_module_file_list
71105 struct ftrace_module_file_ops {
71106 struct list_head list;
71107 struct module *mod;
71108- struct file_operations id;
71109- struct file_operations enable;
71110- struct file_operations format;
71111- struct file_operations filter;
71112+ struct file_operations id; /* cannot be const, see trace_create_file_ops() */
71113+ struct file_operations enable; /* cannot be const, see trace_create_file_ops() */
71114+ struct file_operations format; /* cannot be const, see trace_create_file_ops() */
71115+ struct file_operations filter; /* cannot be const, see trace_create_file_ops() */
71116 };
71117
71118 static struct ftrace_module_file_ops *
71119diff -urNp linux-2.6.39.1/kernel/trace/trace_functions.c linux-2.6.39.1/kernel/trace/trace_functions.c
71120--- linux-2.6.39.1/kernel/trace/trace_functions.c 2011-05-19 00:06:34.000000000 -0400
71121+++ linux-2.6.39.1/kernel/trace/trace_functions.c 2011-05-22 19:36:33.000000000 -0400
71122@@ -308,7 +308,7 @@ ftrace_trace_onoff_print(struct seq_file
71123 static int
71124 ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param)
71125 {
71126- struct ftrace_probe_ops *ops;
71127+ const struct ftrace_probe_ops *ops;
71128
71129 /* we register both traceon and traceoff to this callback */
71130 if (strcmp(cmd, "traceon") == 0)
71131diff -urNp linux-2.6.39.1/kernel/trace/trace_mmiotrace.c linux-2.6.39.1/kernel/trace/trace_mmiotrace.c
71132--- linux-2.6.39.1/kernel/trace/trace_mmiotrace.c 2011-05-19 00:06:34.000000000 -0400
71133+++ linux-2.6.39.1/kernel/trace/trace_mmiotrace.c 2011-05-22 19:36:33.000000000 -0400
71134@@ -24,7 +24,7 @@ struct header_iter {
71135 static struct trace_array *mmio_trace_array;
71136 static bool overrun_detected;
71137 static unsigned long prev_overruns;
71138-static atomic_t dropped_count;
71139+static atomic_unchecked_t dropped_count;
71140
71141 static void mmio_reset_data(struct trace_array *tr)
71142 {
71143@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
71144
71145 static unsigned long count_overruns(struct trace_iterator *iter)
71146 {
71147- unsigned long cnt = atomic_xchg(&dropped_count, 0);
71148+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71149 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71150
71151 if (over > prev_overruns)
71152@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
71153 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71154 sizeof(*entry), 0, pc);
71155 if (!event) {
71156- atomic_inc(&dropped_count);
71157+ atomic_inc_unchecked(&dropped_count);
71158 return;
71159 }
71160 entry = ring_buffer_event_data(event);
71161@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
71162 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71163 sizeof(*entry), 0, pc);
71164 if (!event) {
71165- atomic_inc(&dropped_count);
71166+ atomic_inc_unchecked(&dropped_count);
71167 return;
71168 }
71169 entry = ring_buffer_event_data(event);
71170diff -urNp linux-2.6.39.1/kernel/trace/trace_output.c linux-2.6.39.1/kernel/trace/trace_output.c
71171--- linux-2.6.39.1/kernel/trace/trace_output.c 2011-05-19 00:06:34.000000000 -0400
71172+++ linux-2.6.39.1/kernel/trace/trace_output.c 2011-05-22 19:36:33.000000000 -0400
71173@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
71174
71175 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71176 if (!IS_ERR(p)) {
71177- p = mangle_path(s->buffer + s->len, p, "\n");
71178+ p = mangle_path(s->buffer + s->len, p, "\n\\");
71179 if (p) {
71180 s->len = p - s->buffer;
71181 return 1;
71182diff -urNp linux-2.6.39.1/kernel/trace/trace_stack.c linux-2.6.39.1/kernel/trace/trace_stack.c
71183--- linux-2.6.39.1/kernel/trace/trace_stack.c 2011-05-19 00:06:34.000000000 -0400
71184+++ linux-2.6.39.1/kernel/trace/trace_stack.c 2011-05-22 19:36:33.000000000 -0400
71185@@ -50,7 +50,7 @@ static inline void check_stack(void)
71186 return;
71187
71188 /* we do not handle interrupt stacks yet */
71189- if (!object_is_on_stack(&this_size))
71190+ if (!object_starts_on_stack(&this_size))
71191 return;
71192
71193 local_irq_save(flags);
71194diff -urNp linux-2.6.39.1/kernel/trace/trace_workqueue.c linux-2.6.39.1/kernel/trace/trace_workqueue.c
71195--- linux-2.6.39.1/kernel/trace/trace_workqueue.c 2011-05-19 00:06:34.000000000 -0400
71196+++ linux-2.6.39.1/kernel/trace/trace_workqueue.c 2011-05-22 19:36:33.000000000 -0400
71197@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
71198 int cpu;
71199 pid_t pid;
71200 /* Can be inserted from interrupt or user context, need to be atomic */
71201- atomic_t inserted;
71202+ atomic_unchecked_t inserted;
71203 /*
71204 * Don't need to be atomic, works are serialized in a single workqueue thread
71205 * on a single CPU.
71206@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
71207 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
71208 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
71209 if (node->pid == wq_thread->pid) {
71210- atomic_inc(&node->inserted);
71211+ atomic_inc_unchecked(&node->inserted);
71212 goto found;
71213 }
71214 }
71215@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
71216 tsk = get_pid_task(pid, PIDTYPE_PID);
71217 if (tsk) {
71218 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
71219- atomic_read(&cws->inserted), cws->executed,
71220+ atomic_read_unchecked(&cws->inserted), cws->executed,
71221 tsk->comm);
71222 put_task_struct(tsk);
71223 }
71224diff -urNp linux-2.6.39.1/lib/bug.c linux-2.6.39.1/lib/bug.c
71225--- linux-2.6.39.1/lib/bug.c 2011-05-19 00:06:34.000000000 -0400
71226+++ linux-2.6.39.1/lib/bug.c 2011-05-22 19:36:33.000000000 -0400
71227@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
71228 return BUG_TRAP_TYPE_NONE;
71229
71230 bug = find_bug(bugaddr);
71231+ if (!bug)
71232+ return BUG_TRAP_TYPE_NONE;
71233
71234 file = NULL;
71235 line = 0;
71236diff -urNp linux-2.6.39.1/lib/debugobjects.c linux-2.6.39.1/lib/debugobjects.c
71237--- linux-2.6.39.1/lib/debugobjects.c 2011-05-19 00:06:34.000000000 -0400
71238+++ linux-2.6.39.1/lib/debugobjects.c 2011-05-22 19:36:33.000000000 -0400
71239@@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
71240 if (limit > 4)
71241 return;
71242
71243- is_on_stack = object_is_on_stack(addr);
71244+ is_on_stack = object_starts_on_stack(addr);
71245 if (is_on_stack == onstack)
71246 return;
71247
71248diff -urNp linux-2.6.39.1/lib/dma-debug.c linux-2.6.39.1/lib/dma-debug.c
71249--- linux-2.6.39.1/lib/dma-debug.c 2011-05-19 00:06:34.000000000 -0400
71250+++ linux-2.6.39.1/lib/dma-debug.c 2011-05-22 19:36:33.000000000 -0400
71251@@ -862,7 +862,7 @@ out:
71252
71253 static void check_for_stack(struct device *dev, void *addr)
71254 {
71255- if (object_is_on_stack(addr))
71256+ if (object_starts_on_stack(addr))
71257 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71258 "stack [addr=%p]\n", addr);
71259 }
71260diff -urNp linux-2.6.39.1/lib/inflate.c linux-2.6.39.1/lib/inflate.c
71261--- linux-2.6.39.1/lib/inflate.c 2011-05-19 00:06:34.000000000 -0400
71262+++ linux-2.6.39.1/lib/inflate.c 2011-05-22 19:36:33.000000000 -0400
71263@@ -269,7 +269,7 @@ static void free(void *where)
71264 malloc_ptr = free_mem_ptr;
71265 }
71266 #else
71267-#define malloc(a) kmalloc(a, GFP_KERNEL)
71268+#define malloc(a) kmalloc((a), GFP_KERNEL)
71269 #define free(a) kfree(a)
71270 #endif
71271
71272diff -urNp linux-2.6.39.1/lib/Kconfig.debug linux-2.6.39.1/lib/Kconfig.debug
71273--- linux-2.6.39.1/lib/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
71274+++ linux-2.6.39.1/lib/Kconfig.debug 2011-05-22 19:41:42.000000000 -0400
71275@@ -1078,6 +1078,7 @@ config LATENCYTOP
71276 depends on DEBUG_KERNEL
71277 depends on STACKTRACE_SUPPORT
71278 depends on PROC_FS
71279+ depends on !GRKERNSEC_HIDESYM
71280 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
71281 select KALLSYMS
71282 select KALLSYMS_ALL
71283diff -urNp linux-2.6.39.1/lib/kref.c linux-2.6.39.1/lib/kref.c
71284--- linux-2.6.39.1/lib/kref.c 2011-05-19 00:06:34.000000000 -0400
71285+++ linux-2.6.39.1/lib/kref.c 2011-05-22 19:36:33.000000000 -0400
71286@@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
71287 */
71288 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
71289 {
71290- WARN_ON(release == NULL);
71291+ BUG_ON(release == NULL);
71292 WARN_ON(release == (void (*)(struct kref *))kfree);
71293
71294 if (atomic_dec_and_test(&kref->refcount)) {
71295diff -urNp linux-2.6.39.1/lib/radix-tree.c linux-2.6.39.1/lib/radix-tree.c
71296--- linux-2.6.39.1/lib/radix-tree.c 2011-05-19 00:06:34.000000000 -0400
71297+++ linux-2.6.39.1/lib/radix-tree.c 2011-05-22 19:36:33.000000000 -0400
71298@@ -80,7 +80,7 @@ struct radix_tree_preload {
71299 int nr;
71300 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71301 };
71302-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71303+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71304
71305 static inline void *ptr_to_indirect(void *ptr)
71306 {
71307diff -urNp linux-2.6.39.1/lib/vsprintf.c linux-2.6.39.1/lib/vsprintf.c
71308--- linux-2.6.39.1/lib/vsprintf.c 2011-05-19 00:06:34.000000000 -0400
71309+++ linux-2.6.39.1/lib/vsprintf.c 2011-05-22 20:54:59.000000000 -0400
71310@@ -16,6 +16,9 @@
71311 * - scnprintf and vscnprintf
71312 */
71313
71314+#ifdef CONFIG_GRKERNSEC_HIDESYM
71315+#define __INCLUDED_BY_HIDESYM 1
71316+#endif
71317 #include <stdarg.h>
71318 #include <linux/module.h>
71319 #include <linux/types.h>
71320@@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
71321 char sym[KSYM_SYMBOL_LEN];
71322 if (ext == 'B')
71323 sprint_backtrace(sym, value);
71324- else if (ext != 'f' && ext != 's')
71325+ else if (ext != 'f' && ext != 's' && ext != 'a')
71326 sprint_symbol(sym, value);
71327 else
71328 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71329@@ -797,7 +800,11 @@ char *uuid_string(char *buf, char *end,
71330 return string(buf, end, uuid, spec);
71331 }
71332
71333+#ifdef CONFIG_GRKERNSEC_HIDESYM
71334+int kptr_restrict __read_mostly = 2;
71335+#else
71336 int kptr_restrict __read_mostly;
71337+#endif
71338
71339 /*
71340 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71341@@ -811,6 +818,8 @@ int kptr_restrict __read_mostly;
71342 * - 'S' For symbolic direct pointers with offset
71343 * - 's' For symbolic direct pointers without offset
71344 * - 'B' For backtraced symbolic direct pointers with offset
71345+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71346+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71347 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71348 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71349 * - 'M' For a 6-byte MAC address, it prints the address in the
71350@@ -855,12 +864,12 @@ char *pointer(const char *fmt, char *buf
71351 {
71352 if (!ptr && *fmt != 'K') {
71353 /*
71354- * Print (null) with the same width as a pointer so it makes
71355+ * Print (nil) with the same width as a pointer so it makes
71356 * tabular output look nice.
71357 */
71358 if (spec.field_width == -1)
71359 spec.field_width = 2 * sizeof(void *);
71360- return string(buf, end, "(null)", spec);
71361+ return string(buf, end, "(nil)", spec);
71362 }
71363
71364 switch (*fmt) {
71365@@ -870,6 +879,13 @@ char *pointer(const char *fmt, char *buf
71366 /* Fallthrough */
71367 case 'S':
71368 case 's':
71369+#ifdef CONFIG_GRKERNSEC_HIDESYM
71370+ break;
71371+#else
71372+ return symbol_string(buf, end, ptr, spec, *fmt);
71373+#endif
71374+ case 'A':
71375+ case 'a':
71376 case 'B':
71377 return symbol_string(buf, end, ptr, spec, *fmt);
71378 case 'R':
71379@@ -1632,11 +1648,11 @@ int bstr_printf(char *buf, size_t size,
71380 typeof(type) value; \
71381 if (sizeof(type) == 8) { \
71382 args = PTR_ALIGN(args, sizeof(u32)); \
71383- *(u32 *)&value = *(u32 *)args; \
71384- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71385+ *(u32 *)&value = *(const u32 *)args; \
71386+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71387 } else { \
71388 args = PTR_ALIGN(args, sizeof(type)); \
71389- value = *(typeof(type) *)args; \
71390+ value = *(const typeof(type) *)args; \
71391 } \
71392 args += sizeof(type); \
71393 value; \
71394@@ -1699,7 +1715,7 @@ int bstr_printf(char *buf, size_t size,
71395 case FORMAT_TYPE_STR: {
71396 const char *str_arg = args;
71397 args += strlen(str_arg) + 1;
71398- str = string(str, end, (char *)str_arg, spec);
71399+ str = string(str, end, str_arg, spec);
71400 break;
71401 }
71402
71403diff -urNp linux-2.6.39.1/localversion-grsec linux-2.6.39.1/localversion-grsec
71404--- linux-2.6.39.1/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
71405+++ linux-2.6.39.1/localversion-grsec 2011-05-22 19:41:42.000000000 -0400
71406@@ -0,0 +1 @@
71407+-grsec
71408diff -urNp linux-2.6.39.1/Makefile linux-2.6.39.1/Makefile
71409--- linux-2.6.39.1/Makefile 2011-06-03 00:04:13.000000000 -0400
71410+++ linux-2.6.39.1/Makefile 2011-06-04 17:40:47.000000000 -0400
71411@@ -237,8 +237,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
71412
71413 HOSTCC = gcc
71414 HOSTCXX = g++
71415-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
71416-HOSTCXXFLAGS = -O2
71417+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
71418+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
71419+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
71420
71421 # Decide whether to build built-in, modular, or both.
71422 # Normally, just do built-in.
71423@@ -356,10 +357,12 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
71424 KBUILD_CPPFLAGS := -D__KERNEL__
71425
71426 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
71427+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
71428 -fno-strict-aliasing -fno-common \
71429 -Werror-implicit-function-declaration \
71430 -Wno-format-security \
71431 -fno-delete-null-pointer-checks
71432+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
71433 KBUILD_AFLAGS_KERNEL :=
71434 KBUILD_CFLAGS_KERNEL :=
71435 KBUILD_AFLAGS := -D__ASSEMBLY__
71436@@ -685,7 +688,7 @@ export mod_strip_cmd
71437
71438
71439 ifeq ($(KBUILD_EXTMOD),)
71440-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
71441+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
71442
71443 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
71444 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
71445@@ -931,7 +934,19 @@ include/config/kernel.release: include/c
71446 # version.h and scripts_basic is processed / created.
71447
71448 # Listed in dependency order
71449-PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
71450+PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 pax-plugin
71451+
71452+ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71453+KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0405, -fplugin=$(objtree)/tools/gcc/pax_plugin.so -fplugin-arg-pax_plugin-track-lowest-sp=100)
71454+endif
71455+pax-plugin:
71456+ifneq (,$(findstring pax_plugin, $(KBUILD_CFLAGS)))
71457+ $(Q)$(MAKE) $(build)=tools/gcc
71458+else
71459+ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71460+ $(Q)echo "warning, your gcc does not support plugins, PAX_MEMORY_STACKLEAK will be less secure"
71461+endif
71462+endif
71463
71464 # prepare3 is used to check if we are building in a separate output directory,
71465 # and if so do:
71466@@ -947,7 +962,7 @@ ifneq ($(KBUILD_SRC),)
71467 endif
71468
71469 # prepare2 creates a makefile if using a separate output directory
71470-prepare2: prepare3 outputmakefile
71471+prepare2: prepare3 outputmakefile pax-plugin
71472
71473 prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
71474 include/config/auto.conf
71475diff -urNp linux-2.6.39.1/mm/filemap.c linux-2.6.39.1/mm/filemap.c
71476--- linux-2.6.39.1/mm/filemap.c 2011-05-19 00:06:34.000000000 -0400
71477+++ linux-2.6.39.1/mm/filemap.c 2011-05-22 19:41:42.000000000 -0400
71478@@ -1724,7 +1724,7 @@ int generic_file_mmap(struct file * file
71479 struct address_space *mapping = file->f_mapping;
71480
71481 if (!mapping->a_ops->readpage)
71482- return -ENOEXEC;
71483+ return -ENODEV;
71484 file_accessed(file);
71485 vma->vm_ops = &generic_file_vm_ops;
71486 vma->vm_flags |= VM_CAN_NONLINEAR;
71487@@ -2120,6 +2120,7 @@ inline int generic_write_checks(struct f
71488 *pos = i_size_read(inode);
71489
71490 if (limit != RLIM_INFINITY) {
71491+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71492 if (*pos >= limit) {
71493 send_sig(SIGXFSZ, current, 0);
71494 return -EFBIG;
71495diff -urNp linux-2.6.39.1/mm/fremap.c linux-2.6.39.1/mm/fremap.c
71496--- linux-2.6.39.1/mm/fremap.c 2011-05-19 00:06:34.000000000 -0400
71497+++ linux-2.6.39.1/mm/fremap.c 2011-05-22 19:36:33.000000000 -0400
71498@@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71499 retry:
71500 vma = find_vma(mm, start);
71501
71502+#ifdef CONFIG_PAX_SEGMEXEC
71503+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71504+ goto out;
71505+#endif
71506+
71507 /*
71508 * Make sure the vma is shared, that it supports prefaulting,
71509 * and that the remapped range is valid and fully within
71510@@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71511 /*
71512 * drop PG_Mlocked flag for over-mapped range
71513 */
71514- unsigned int saved_flags = vma->vm_flags;
71515+ unsigned long saved_flags = vma->vm_flags;
71516 munlock_vma_pages_range(vma, start, start + size);
71517 vma->vm_flags = saved_flags;
71518 }
71519diff -urNp linux-2.6.39.1/mm/highmem.c linux-2.6.39.1/mm/highmem.c
71520--- linux-2.6.39.1/mm/highmem.c 2011-05-19 00:06:34.000000000 -0400
71521+++ linux-2.6.39.1/mm/highmem.c 2011-05-22 19:36:33.000000000 -0400
71522@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71523 * So no dangers, even with speculative execution.
71524 */
71525 page = pte_page(pkmap_page_table[i]);
71526+ pax_open_kernel();
71527 pte_clear(&init_mm, (unsigned long)page_address(page),
71528 &pkmap_page_table[i]);
71529-
71530+ pax_close_kernel();
71531 set_page_address(page, NULL);
71532 need_flush = 1;
71533 }
71534@@ -186,9 +187,11 @@ start:
71535 }
71536 }
71537 vaddr = PKMAP_ADDR(last_pkmap_nr);
71538+
71539+ pax_open_kernel();
71540 set_pte_at(&init_mm, vaddr,
71541 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71542-
71543+ pax_close_kernel();
71544 pkmap_count[last_pkmap_nr] = 1;
71545 set_page_address(page, (void *)vaddr);
71546
71547diff -urNp linux-2.6.39.1/mm/huge_memory.c linux-2.6.39.1/mm/huge_memory.c
71548--- linux-2.6.39.1/mm/huge_memory.c 2011-05-19 00:06:34.000000000 -0400
71549+++ linux-2.6.39.1/mm/huge_memory.c 2011-05-22 19:36:33.000000000 -0400
71550@@ -702,7 +702,7 @@ out:
71551 * run pte_offset_map on the pmd, if an huge pmd could
71552 * materialize from under us from a different thread.
71553 */
71554- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71555+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71556 return VM_FAULT_OOM;
71557 /* if an huge pmd materialized from under us just retry later */
71558 if (unlikely(pmd_trans_huge(*pmd)))
71559diff -urNp linux-2.6.39.1/mm/hugetlb.c linux-2.6.39.1/mm/hugetlb.c
71560--- linux-2.6.39.1/mm/hugetlb.c 2011-05-19 00:06:34.000000000 -0400
71561+++ linux-2.6.39.1/mm/hugetlb.c 2011-05-22 19:36:33.000000000 -0400
71562@@ -2331,6 +2331,27 @@ static int unmap_ref_private(struct mm_s
71563 return 1;
71564 }
71565
71566+#ifdef CONFIG_PAX_SEGMEXEC
71567+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71568+{
71569+ struct mm_struct *mm = vma->vm_mm;
71570+ struct vm_area_struct *vma_m;
71571+ unsigned long address_m;
71572+ pte_t *ptep_m;
71573+
71574+ vma_m = pax_find_mirror_vma(vma);
71575+ if (!vma_m)
71576+ return;
71577+
71578+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71579+ address_m = address + SEGMEXEC_TASK_SIZE;
71580+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71581+ get_page(page_m);
71582+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
71583+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71584+}
71585+#endif
71586+
71587 /*
71588 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71589 */
71590@@ -2432,6 +2453,11 @@ retry_avoidcopy:
71591 make_huge_pte(vma, new_page, 1));
71592 page_remove_rmap(old_page);
71593 hugepage_add_new_anon_rmap(new_page, vma, address);
71594+
71595+#ifdef CONFIG_PAX_SEGMEXEC
71596+ pax_mirror_huge_pte(vma, address, new_page);
71597+#endif
71598+
71599 /* Make the old page be freed below */
71600 new_page = old_page;
71601 mmu_notifier_invalidate_range_end(mm,
71602@@ -2583,6 +2609,10 @@ retry:
71603 && (vma->vm_flags & VM_SHARED)));
71604 set_huge_pte_at(mm, address, ptep, new_pte);
71605
71606+#ifdef CONFIG_PAX_SEGMEXEC
71607+ pax_mirror_huge_pte(vma, address, page);
71608+#endif
71609+
71610 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71611 /* Optimization, do the COW without a second fault */
71612 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71613@@ -2612,6 +2642,10 @@ int hugetlb_fault(struct mm_struct *mm,
71614 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71615 struct hstate *h = hstate_vma(vma);
71616
71617+#ifdef CONFIG_PAX_SEGMEXEC
71618+ struct vm_area_struct *vma_m;
71619+#endif
71620+
71621 ptep = huge_pte_offset(mm, address);
71622 if (ptep) {
71623 entry = huge_ptep_get(ptep);
71624@@ -2623,6 +2657,26 @@ int hugetlb_fault(struct mm_struct *mm,
71625 VM_FAULT_SET_HINDEX(h - hstates);
71626 }
71627
71628+#ifdef CONFIG_PAX_SEGMEXEC
71629+ vma_m = pax_find_mirror_vma(vma);
71630+ if (vma_m) {
71631+ unsigned long address_m;
71632+
71633+ if (vma->vm_start > vma_m->vm_start) {
71634+ address_m = address;
71635+ address -= SEGMEXEC_TASK_SIZE;
71636+ vma = vma_m;
71637+ h = hstate_vma(vma);
71638+ } else
71639+ address_m = address + SEGMEXEC_TASK_SIZE;
71640+
71641+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71642+ return VM_FAULT_OOM;
71643+ address_m &= HPAGE_MASK;
71644+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71645+ }
71646+#endif
71647+
71648 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71649 if (!ptep)
71650 return VM_FAULT_OOM;
71651diff -urNp linux-2.6.39.1/mm/Kconfig linux-2.6.39.1/mm/Kconfig
71652--- linux-2.6.39.1/mm/Kconfig 2011-05-19 00:06:34.000000000 -0400
71653+++ linux-2.6.39.1/mm/Kconfig 2011-05-22 19:41:42.000000000 -0400
71654@@ -240,7 +240,7 @@ config KSM
71655 config DEFAULT_MMAP_MIN_ADDR
71656 int "Low address space to protect from user allocation"
71657 depends on MMU
71658- default 4096
71659+ default 65536
71660 help
71661 This is the portion of low virtual memory which should be protected
71662 from userspace allocation. Keeping a user from writing to low pages
71663diff -urNp linux-2.6.39.1/mm/kmemleak.c linux-2.6.39.1/mm/kmemleak.c
71664--- linux-2.6.39.1/mm/kmemleak.c 2011-06-03 00:04:14.000000000 -0400
71665+++ linux-2.6.39.1/mm/kmemleak.c 2011-06-03 00:32:08.000000000 -0400
71666@@ -357,7 +357,7 @@ static void print_unreferenced(struct se
71667
71668 for (i = 0; i < object->trace_len; i++) {
71669 void *ptr = (void *)object->trace[i];
71670- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71671+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71672 }
71673 }
71674
71675diff -urNp linux-2.6.39.1/mm/maccess.c linux-2.6.39.1/mm/maccess.c
71676--- linux-2.6.39.1/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
71677+++ linux-2.6.39.1/mm/maccess.c 2011-05-22 19:36:33.000000000 -0400
71678@@ -15,10 +15,10 @@
71679 * happens, handle that and return -EFAULT.
71680 */
71681
71682-long __weak probe_kernel_read(void *dst, void *src, size_t size)
71683+long __weak probe_kernel_read(void *dst, const void *src, size_t size)
71684 __attribute__((alias("__probe_kernel_read")));
71685
71686-long __probe_kernel_read(void *dst, void *src, size_t size)
71687+long __probe_kernel_read(void *dst, const void *src, size_t size)
71688 {
71689 long ret;
71690 mm_segment_t old_fs = get_fs();
71691@@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
71692 * Safely write to address @dst from the buffer at @src. If a kernel fault
71693 * happens, handle that and return -EFAULT.
71694 */
71695-long __weak probe_kernel_write(void *dst, void *src, size_t size)
71696+long __weak probe_kernel_write(void *dst, const void *src, size_t size)
71697 __attribute__((alias("__probe_kernel_write")));
71698
71699-long __probe_kernel_write(void *dst, void *src, size_t size)
71700+long __probe_kernel_write(void *dst, const void *src, size_t size)
71701 {
71702 long ret;
71703 mm_segment_t old_fs = get_fs();
71704diff -urNp linux-2.6.39.1/mm/madvise.c linux-2.6.39.1/mm/madvise.c
71705--- linux-2.6.39.1/mm/madvise.c 2011-05-19 00:06:34.000000000 -0400
71706+++ linux-2.6.39.1/mm/madvise.c 2011-05-22 19:36:33.000000000 -0400
71707@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
71708 pgoff_t pgoff;
71709 unsigned long new_flags = vma->vm_flags;
71710
71711+#ifdef CONFIG_PAX_SEGMEXEC
71712+ struct vm_area_struct *vma_m;
71713+#endif
71714+
71715 switch (behavior) {
71716 case MADV_NORMAL:
71717 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71718@@ -110,6 +114,13 @@ success:
71719 /*
71720 * vm_flags is protected by the mmap_sem held in write mode.
71721 */
71722+
71723+#ifdef CONFIG_PAX_SEGMEXEC
71724+ vma_m = pax_find_mirror_vma(vma);
71725+ if (vma_m)
71726+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71727+#endif
71728+
71729 vma->vm_flags = new_flags;
71730
71731 out:
71732@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
71733 struct vm_area_struct ** prev,
71734 unsigned long start, unsigned long end)
71735 {
71736+
71737+#ifdef CONFIG_PAX_SEGMEXEC
71738+ struct vm_area_struct *vma_m;
71739+#endif
71740+
71741 *prev = vma;
71742 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71743 return -EINVAL;
71744@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
71745 zap_page_range(vma, start, end - start, &details);
71746 } else
71747 zap_page_range(vma, start, end - start, NULL);
71748+
71749+#ifdef CONFIG_PAX_SEGMEXEC
71750+ vma_m = pax_find_mirror_vma(vma);
71751+ if (vma_m) {
71752+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71753+ struct zap_details details = {
71754+ .nonlinear_vma = vma_m,
71755+ .last_index = ULONG_MAX,
71756+ };
71757+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71758+ } else
71759+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71760+ }
71761+#endif
71762+
71763 return 0;
71764 }
71765
71766@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
71767 if (end < start)
71768 goto out;
71769
71770+#ifdef CONFIG_PAX_SEGMEXEC
71771+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71772+ if (end > SEGMEXEC_TASK_SIZE)
71773+ goto out;
71774+ } else
71775+#endif
71776+
71777+ if (end > TASK_SIZE)
71778+ goto out;
71779+
71780 error = 0;
71781 if (end == start)
71782 goto out;
71783diff -urNp linux-2.6.39.1/mm/memory.c linux-2.6.39.1/mm/memory.c
71784--- linux-2.6.39.1/mm/memory.c 2011-05-19 00:06:34.000000000 -0400
71785+++ linux-2.6.39.1/mm/memory.c 2011-05-22 19:36:33.000000000 -0400
71786@@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
71787 return;
71788
71789 pmd = pmd_offset(pud, start);
71790+
71791+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71792 pud_clear(pud);
71793 pmd_free_tlb(tlb, pmd, start);
71794+#endif
71795+
71796 }
71797
71798 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71799@@ -291,9 +295,12 @@ static inline void free_pud_range(struct
71800 if (end - 1 > ceiling - 1)
71801 return;
71802
71803+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71804 pud = pud_offset(pgd, start);
71805 pgd_clear(pgd);
71806 pud_free_tlb(tlb, pud, start);
71807+#endif
71808+
71809 }
71810
71811 /*
71812@@ -1410,12 +1417,6 @@ no_page_table:
71813 return page;
71814 }
71815
71816-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71817-{
71818- return stack_guard_page_start(vma, addr) ||
71819- stack_guard_page_end(vma, addr+PAGE_SIZE);
71820-}
71821-
71822 /**
71823 * __get_user_pages() - pin user pages in memory
71824 * @tsk: task_struct of target task
71825@@ -1488,10 +1489,10 @@ int __get_user_pages(struct task_struct
71826 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71827 i = 0;
71828
71829- do {
71830+ while (nr_pages) {
71831 struct vm_area_struct *vma;
71832
71833- vma = find_extend_vma(mm, start);
71834+ vma = find_vma(mm, start);
71835 if (!vma && in_gate_area(mm, start)) {
71836 unsigned long pg = start & PAGE_MASK;
71837 pgd_t *pgd;
71838@@ -1539,7 +1540,7 @@ int __get_user_pages(struct task_struct
71839 goto next_page;
71840 }
71841
71842- if (!vma ||
71843+ if (!vma || start < vma->vm_start ||
71844 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71845 !(vm_flags & vma->vm_flags))
71846 return i ? : -EFAULT;
71847@@ -1566,11 +1567,6 @@ int __get_user_pages(struct task_struct
71848 int ret;
71849 unsigned int fault_flags = 0;
71850
71851- /* For mlock, just skip the stack guard page. */
71852- if (foll_flags & FOLL_MLOCK) {
71853- if (stack_guard_page(vma, start))
71854- goto next_page;
71855- }
71856 if (foll_flags & FOLL_WRITE)
71857 fault_flags |= FAULT_FLAG_WRITE;
71858 if (nonblocking)
71859@@ -1644,7 +1640,7 @@ next_page:
71860 start += PAGE_SIZE;
71861 nr_pages--;
71862 } while (nr_pages && start < vma->vm_end);
71863- } while (nr_pages);
71864+ }
71865 return i;
71866 }
71867 EXPORT_SYMBOL(__get_user_pages);
71868@@ -1795,6 +1791,10 @@ static int insert_page(struct vm_area_st
71869 page_add_file_rmap(page);
71870 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71871
71872+#ifdef CONFIG_PAX_SEGMEXEC
71873+ pax_mirror_file_pte(vma, addr, page, ptl);
71874+#endif
71875+
71876 retval = 0;
71877 pte_unmap_unlock(pte, ptl);
71878 return retval;
71879@@ -1829,10 +1829,22 @@ out:
71880 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71881 struct page *page)
71882 {
71883+
71884+#ifdef CONFIG_PAX_SEGMEXEC
71885+ struct vm_area_struct *vma_m;
71886+#endif
71887+
71888 if (addr < vma->vm_start || addr >= vma->vm_end)
71889 return -EFAULT;
71890 if (!page_count(page))
71891 return -EINVAL;
71892+
71893+#ifdef CONFIG_PAX_SEGMEXEC
71894+ vma_m = pax_find_mirror_vma(vma);
71895+ if (vma_m)
71896+ vma_m->vm_flags |= VM_INSERTPAGE;
71897+#endif
71898+
71899 vma->vm_flags |= VM_INSERTPAGE;
71900 return insert_page(vma, addr, page, vma->vm_page_prot);
71901 }
71902@@ -1918,6 +1930,7 @@ int vm_insert_mixed(struct vm_area_struc
71903 unsigned long pfn)
71904 {
71905 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71906+ BUG_ON(vma->vm_mirror);
71907
71908 if (addr < vma->vm_start || addr >= vma->vm_end)
71909 return -EFAULT;
71910@@ -2233,6 +2246,186 @@ static inline void cow_user_page(struct
71911 copy_user_highpage(dst, src, va, vma);
71912 }
71913
71914+#ifdef CONFIG_PAX_SEGMEXEC
71915+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71916+{
71917+ struct mm_struct *mm = vma->vm_mm;
71918+ spinlock_t *ptl;
71919+ pte_t *pte, entry;
71920+
71921+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71922+ entry = *pte;
71923+ if (!pte_present(entry)) {
71924+ if (!pte_none(entry)) {
71925+ BUG_ON(pte_file(entry));
71926+ free_swap_and_cache(pte_to_swp_entry(entry));
71927+ pte_clear_not_present_full(mm, address, pte, 0);
71928+ }
71929+ } else {
71930+ struct page *page;
71931+
71932+ flush_cache_page(vma, address, pte_pfn(entry));
71933+ entry = ptep_clear_flush(vma, address, pte);
71934+ BUG_ON(pte_dirty(entry));
71935+ page = vm_normal_page(vma, address, entry);
71936+ if (page) {
71937+ update_hiwater_rss(mm);
71938+ if (PageAnon(page))
71939+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71940+ else
71941+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71942+ page_remove_rmap(page);
71943+ page_cache_release(page);
71944+ }
71945+ }
71946+ pte_unmap_unlock(pte, ptl);
71947+}
71948+
71949+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71950+ *
71951+ * the ptl of the lower mapped page is held on entry and is not released on exit
71952+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71953+ */
71954+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71955+{
71956+ struct mm_struct *mm = vma->vm_mm;
71957+ unsigned long address_m;
71958+ spinlock_t *ptl_m;
71959+ struct vm_area_struct *vma_m;
71960+ pmd_t *pmd_m;
71961+ pte_t *pte_m, entry_m;
71962+
71963+ BUG_ON(!page_m || !PageAnon(page_m));
71964+
71965+ vma_m = pax_find_mirror_vma(vma);
71966+ if (!vma_m)
71967+ return;
71968+
71969+ BUG_ON(!PageLocked(page_m));
71970+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71971+ address_m = address + SEGMEXEC_TASK_SIZE;
71972+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71973+ pte_m = pte_offset_map(pmd_m, address_m);
71974+ ptl_m = pte_lockptr(mm, pmd_m);
71975+ if (ptl != ptl_m) {
71976+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71977+ if (!pte_none(*pte_m))
71978+ goto out;
71979+ }
71980+
71981+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71982+ page_cache_get(page_m);
71983+ page_add_anon_rmap(page_m, vma_m, address_m);
71984+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71985+ set_pte_at(mm, address_m, pte_m, entry_m);
71986+ update_mmu_cache(vma_m, address_m, entry_m);
71987+out:
71988+ if (ptl != ptl_m)
71989+ spin_unlock(ptl_m);
71990+ pte_unmap(pte_m);
71991+ unlock_page(page_m);
71992+}
71993+
71994+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71995+{
71996+ struct mm_struct *mm = vma->vm_mm;
71997+ unsigned long address_m;
71998+ spinlock_t *ptl_m;
71999+ struct vm_area_struct *vma_m;
72000+ pmd_t *pmd_m;
72001+ pte_t *pte_m, entry_m;
72002+
72003+ BUG_ON(!page_m || PageAnon(page_m));
72004+
72005+ vma_m = pax_find_mirror_vma(vma);
72006+ if (!vma_m)
72007+ return;
72008+
72009+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72010+ address_m = address + SEGMEXEC_TASK_SIZE;
72011+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72012+ pte_m = pte_offset_map(pmd_m, address_m);
72013+ ptl_m = pte_lockptr(mm, pmd_m);
72014+ if (ptl != ptl_m) {
72015+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72016+ if (!pte_none(*pte_m))
72017+ goto out;
72018+ }
72019+
72020+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72021+ page_cache_get(page_m);
72022+ page_add_file_rmap(page_m);
72023+ inc_mm_counter_fast(mm, MM_FILEPAGES);
72024+ set_pte_at(mm, address_m, pte_m, entry_m);
72025+ update_mmu_cache(vma_m, address_m, entry_m);
72026+out:
72027+ if (ptl != ptl_m)
72028+ spin_unlock(ptl_m);
72029+ pte_unmap(pte_m);
72030+}
72031+
72032+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72033+{
72034+ struct mm_struct *mm = vma->vm_mm;
72035+ unsigned long address_m;
72036+ spinlock_t *ptl_m;
72037+ struct vm_area_struct *vma_m;
72038+ pmd_t *pmd_m;
72039+ pte_t *pte_m, entry_m;
72040+
72041+ vma_m = pax_find_mirror_vma(vma);
72042+ if (!vma_m)
72043+ return;
72044+
72045+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72046+ address_m = address + SEGMEXEC_TASK_SIZE;
72047+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72048+ pte_m = pte_offset_map(pmd_m, address_m);
72049+ ptl_m = pte_lockptr(mm, pmd_m);
72050+ if (ptl != ptl_m) {
72051+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72052+ if (!pte_none(*pte_m))
72053+ goto out;
72054+ }
72055+
72056+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72057+ set_pte_at(mm, address_m, pte_m, entry_m);
72058+out:
72059+ if (ptl != ptl_m)
72060+ spin_unlock(ptl_m);
72061+ pte_unmap(pte_m);
72062+}
72063+
72064+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72065+{
72066+ struct page *page_m;
72067+ pte_t entry;
72068+
72069+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72070+ goto out;
72071+
72072+ entry = *pte;
72073+ page_m = vm_normal_page(vma, address, entry);
72074+ if (!page_m)
72075+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72076+ else if (PageAnon(page_m)) {
72077+ if (pax_find_mirror_vma(vma)) {
72078+ pte_unmap_unlock(pte, ptl);
72079+ lock_page(page_m);
72080+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72081+ if (pte_same(entry, *pte))
72082+ pax_mirror_anon_pte(vma, address, page_m, ptl);
72083+ else
72084+ unlock_page(page_m);
72085+ }
72086+ } else
72087+ pax_mirror_file_pte(vma, address, page_m, ptl);
72088+
72089+out:
72090+ pte_unmap_unlock(pte, ptl);
72091+}
72092+#endif
72093+
72094 /*
72095 * This routine handles present pages, when users try to write
72096 * to a shared page. It is done by copying the page to a new address
72097@@ -2444,6 +2637,12 @@ gotten:
72098 */
72099 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72100 if (likely(pte_same(*page_table, orig_pte))) {
72101+
72102+#ifdef CONFIG_PAX_SEGMEXEC
72103+ if (pax_find_mirror_vma(vma))
72104+ BUG_ON(!trylock_page(new_page));
72105+#endif
72106+
72107 if (old_page) {
72108 if (!PageAnon(old_page)) {
72109 dec_mm_counter_fast(mm, MM_FILEPAGES);
72110@@ -2495,6 +2694,10 @@ gotten:
72111 page_remove_rmap(old_page);
72112 }
72113
72114+#ifdef CONFIG_PAX_SEGMEXEC
72115+ pax_mirror_anon_pte(vma, address, new_page, ptl);
72116+#endif
72117+
72118 /* Free the old page.. */
72119 new_page = old_page;
72120 ret |= VM_FAULT_WRITE;
72121@@ -2905,6 +3108,11 @@ static int do_swap_page(struct mm_struct
72122 swap_free(entry);
72123 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72124 try_to_free_swap(page);
72125+
72126+#ifdef CONFIG_PAX_SEGMEXEC
72127+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72128+#endif
72129+
72130 unlock_page(page);
72131 if (swapcache) {
72132 /*
72133@@ -2928,6 +3136,11 @@ static int do_swap_page(struct mm_struct
72134
72135 /* No need to invalidate - it was non-present before */
72136 update_mmu_cache(vma, address, page_table);
72137+
72138+#ifdef CONFIG_PAX_SEGMEXEC
72139+ pax_mirror_anon_pte(vma, address, page, ptl);
72140+#endif
72141+
72142 unlock:
72143 pte_unmap_unlock(page_table, ptl);
72144 out:
72145@@ -2947,40 +3160,6 @@ out_release:
72146 }
72147
72148 /*
72149- * This is like a special single-page "expand_{down|up}wards()",
72150- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72151- * doesn't hit another vma.
72152- */
72153-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72154-{
72155- address &= PAGE_MASK;
72156- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72157- struct vm_area_struct *prev = vma->vm_prev;
72158-
72159- /*
72160- * Is there a mapping abutting this one below?
72161- *
72162- * That's only ok if it's the same stack mapping
72163- * that has gotten split..
72164- */
72165- if (prev && prev->vm_end == address)
72166- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72167-
72168- expand_stack(vma, address - PAGE_SIZE);
72169- }
72170- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72171- struct vm_area_struct *next = vma->vm_next;
72172-
72173- /* As VM_GROWSDOWN but s/below/above/ */
72174- if (next && next->vm_start == address + PAGE_SIZE)
72175- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72176-
72177- expand_upwards(vma, address + PAGE_SIZE);
72178- }
72179- return 0;
72180-}
72181-
72182-/*
72183 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72184 * but allow concurrent faults), and pte mapped but not yet locked.
72185 * We return with mmap_sem still held, but pte unmapped and unlocked.
72186@@ -2989,27 +3168,23 @@ static int do_anonymous_page(struct mm_s
72187 unsigned long address, pte_t *page_table, pmd_t *pmd,
72188 unsigned int flags)
72189 {
72190- struct page *page;
72191+ struct page *page = NULL;
72192 spinlock_t *ptl;
72193 pte_t entry;
72194
72195- pte_unmap(page_table);
72196-
72197- /* Check if we need to add a guard page to the stack */
72198- if (check_stack_guard_page(vma, address) < 0)
72199- return VM_FAULT_SIGBUS;
72200-
72201- /* Use the zero-page for reads */
72202 if (!(flags & FAULT_FLAG_WRITE)) {
72203 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72204 vma->vm_page_prot));
72205- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72206+ ptl = pte_lockptr(mm, pmd);
72207+ spin_lock(ptl);
72208 if (!pte_none(*page_table))
72209 goto unlock;
72210 goto setpte;
72211 }
72212
72213 /* Allocate our own private page. */
72214+ pte_unmap(page_table);
72215+
72216 if (unlikely(anon_vma_prepare(vma)))
72217 goto oom;
72218 page = alloc_zeroed_user_highpage_movable(vma, address);
72219@@ -3028,6 +3203,11 @@ static int do_anonymous_page(struct mm_s
72220 if (!pte_none(*page_table))
72221 goto release;
72222
72223+#ifdef CONFIG_PAX_SEGMEXEC
72224+ if (pax_find_mirror_vma(vma))
72225+ BUG_ON(!trylock_page(page));
72226+#endif
72227+
72228 inc_mm_counter_fast(mm, MM_ANONPAGES);
72229 page_add_new_anon_rmap(page, vma, address);
72230 setpte:
72231@@ -3035,6 +3215,12 @@ setpte:
72232
72233 /* No need to invalidate - it was non-present before */
72234 update_mmu_cache(vma, address, page_table);
72235+
72236+#ifdef CONFIG_PAX_SEGMEXEC
72237+ if (page)
72238+ pax_mirror_anon_pte(vma, address, page, ptl);
72239+#endif
72240+
72241 unlock:
72242 pte_unmap_unlock(page_table, ptl);
72243 return 0;
72244@@ -3172,6 +3358,12 @@ static int __do_fault(struct mm_struct *
72245 */
72246 /* Only go through if we didn't race with anybody else... */
72247 if (likely(pte_same(*page_table, orig_pte))) {
72248+
72249+#ifdef CONFIG_PAX_SEGMEXEC
72250+ if (anon && pax_find_mirror_vma(vma))
72251+ BUG_ON(!trylock_page(page));
72252+#endif
72253+
72254 flush_icache_page(vma, page);
72255 entry = mk_pte(page, vma->vm_page_prot);
72256 if (flags & FAULT_FLAG_WRITE)
72257@@ -3191,6 +3383,14 @@ static int __do_fault(struct mm_struct *
72258
72259 /* no need to invalidate: a not-present page won't be cached */
72260 update_mmu_cache(vma, address, page_table);
72261+
72262+#ifdef CONFIG_PAX_SEGMEXEC
72263+ if (anon)
72264+ pax_mirror_anon_pte(vma, address, page, ptl);
72265+ else
72266+ pax_mirror_file_pte(vma, address, page, ptl);
72267+#endif
72268+
72269 } else {
72270 if (charged)
72271 mem_cgroup_uncharge_page(page);
72272@@ -3338,6 +3538,12 @@ int handle_pte_fault(struct mm_struct *m
72273 if (flags & FAULT_FLAG_WRITE)
72274 flush_tlb_fix_spurious_fault(vma, address);
72275 }
72276+
72277+#ifdef CONFIG_PAX_SEGMEXEC
72278+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72279+ return 0;
72280+#endif
72281+
72282 unlock:
72283 pte_unmap_unlock(pte, ptl);
72284 return 0;
72285@@ -3354,6 +3560,10 @@ int handle_mm_fault(struct mm_struct *mm
72286 pmd_t *pmd;
72287 pte_t *pte;
72288
72289+#ifdef CONFIG_PAX_SEGMEXEC
72290+ struct vm_area_struct *vma_m;
72291+#endif
72292+
72293 __set_current_state(TASK_RUNNING);
72294
72295 count_vm_event(PGFAULT);
72296@@ -3364,6 +3574,34 @@ int handle_mm_fault(struct mm_struct *mm
72297 if (unlikely(is_vm_hugetlb_page(vma)))
72298 return hugetlb_fault(mm, vma, address, flags);
72299
72300+#ifdef CONFIG_PAX_SEGMEXEC
72301+ vma_m = pax_find_mirror_vma(vma);
72302+ if (vma_m) {
72303+ unsigned long address_m;
72304+ pgd_t *pgd_m;
72305+ pud_t *pud_m;
72306+ pmd_t *pmd_m;
72307+
72308+ if (vma->vm_start > vma_m->vm_start) {
72309+ address_m = address;
72310+ address -= SEGMEXEC_TASK_SIZE;
72311+ vma = vma_m;
72312+ } else
72313+ address_m = address + SEGMEXEC_TASK_SIZE;
72314+
72315+ pgd_m = pgd_offset(mm, address_m);
72316+ pud_m = pud_alloc(mm, pgd_m, address_m);
72317+ if (!pud_m)
72318+ return VM_FAULT_OOM;
72319+ pmd_m = pmd_alloc(mm, pud_m, address_m);
72320+ if (!pmd_m)
72321+ return VM_FAULT_OOM;
72322+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72323+ return VM_FAULT_OOM;
72324+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72325+ }
72326+#endif
72327+
72328 pgd = pgd_offset(mm, address);
72329 pud = pud_alloc(mm, pgd, address);
72330 if (!pud)
72331@@ -3393,7 +3631,7 @@ int handle_mm_fault(struct mm_struct *mm
72332 * run pte_offset_map on the pmd, if an huge pmd could
72333 * materialize from under us from a different thread.
72334 */
72335- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72336+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72337 return VM_FAULT_OOM;
72338 /* if an huge pmd materialized from under us just retry later */
72339 if (unlikely(pmd_trans_huge(*pmd)))
72340@@ -3497,7 +3735,7 @@ static int __init gate_vma_init(void)
72341 gate_vma.vm_start = FIXADDR_USER_START;
72342 gate_vma.vm_end = FIXADDR_USER_END;
72343 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72344- gate_vma.vm_page_prot = __P101;
72345+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72346 /*
72347 * Make sure the vDSO gets into every core dump.
72348 * Dumping its contents makes post-mortem fully interpretable later
72349diff -urNp linux-2.6.39.1/mm/memory-failure.c linux-2.6.39.1/mm/memory-failure.c
72350--- linux-2.6.39.1/mm/memory-failure.c 2011-05-19 00:06:34.000000000 -0400
72351+++ linux-2.6.39.1/mm/memory-failure.c 2011-05-22 19:36:33.000000000 -0400
72352@@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
72353
72354 int sysctl_memory_failure_recovery __read_mostly = 1;
72355
72356-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72357+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72358
72359 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72360
72361@@ -1012,7 +1012,7 @@ int __memory_failure(unsigned long pfn,
72362 }
72363
72364 nr_pages = 1 << compound_trans_order(hpage);
72365- atomic_long_add(nr_pages, &mce_bad_pages);
72366+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72367
72368 /*
72369 * We need/can do nothing about count=0 pages.
72370@@ -1042,7 +1042,7 @@ int __memory_failure(unsigned long pfn,
72371 if (!PageHWPoison(hpage)
72372 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72373 || (p != hpage && TestSetPageHWPoison(hpage))) {
72374- atomic_long_sub(nr_pages, &mce_bad_pages);
72375+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72376 return 0;
72377 }
72378 set_page_hwpoison_huge_page(hpage);
72379@@ -1100,7 +1100,7 @@ int __memory_failure(unsigned long pfn,
72380 }
72381 if (hwpoison_filter(p)) {
72382 if (TestClearPageHWPoison(p))
72383- atomic_long_sub(nr_pages, &mce_bad_pages);
72384+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72385 unlock_page(hpage);
72386 put_page(hpage);
72387 return 0;
72388@@ -1226,7 +1226,7 @@ int unpoison_memory(unsigned long pfn)
72389 return 0;
72390 }
72391 if (TestClearPageHWPoison(p))
72392- atomic_long_sub(nr_pages, &mce_bad_pages);
72393+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72394 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72395 return 0;
72396 }
72397@@ -1240,7 +1240,7 @@ int unpoison_memory(unsigned long pfn)
72398 */
72399 if (TestClearPageHWPoison(page)) {
72400 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72401- atomic_long_sub(nr_pages, &mce_bad_pages);
72402+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72403 freeit = 1;
72404 if (PageHuge(page))
72405 clear_page_hwpoison_huge_page(page);
72406@@ -1353,7 +1353,7 @@ static int soft_offline_huge_page(struct
72407 }
72408 done:
72409 if (!PageHWPoison(hpage))
72410- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
72411+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
72412 set_page_hwpoison_huge_page(hpage);
72413 dequeue_hwpoisoned_huge_page(hpage);
72414 /* keep elevated page count for bad page */
72415@@ -1482,7 +1482,7 @@ int soft_offline_page(struct page *page,
72416 return ret;
72417
72418 done:
72419- atomic_long_add(1, &mce_bad_pages);
72420+ atomic_long_add_unchecked(1, &mce_bad_pages);
72421 SetPageHWPoison(page);
72422 /* keep elevated page count for bad page */
72423 return ret;
72424diff -urNp linux-2.6.39.1/mm/mempolicy.c linux-2.6.39.1/mm/mempolicy.c
72425--- linux-2.6.39.1/mm/mempolicy.c 2011-05-19 00:06:34.000000000 -0400
72426+++ linux-2.6.39.1/mm/mempolicy.c 2011-05-22 19:41:42.000000000 -0400
72427@@ -643,6 +643,10 @@ static int mbind_range(struct mm_struct
72428 unsigned long vmstart;
72429 unsigned long vmend;
72430
72431+#ifdef CONFIG_PAX_SEGMEXEC
72432+ struct vm_area_struct *vma_m;
72433+#endif
72434+
72435 vma = find_vma_prev(mm, start, &prev);
72436 if (!vma || vma->vm_start > start)
72437 return -EFAULT;
72438@@ -673,6 +677,16 @@ static int mbind_range(struct mm_struct
72439 err = policy_vma(vma, new_pol);
72440 if (err)
72441 goto out;
72442+
72443+#ifdef CONFIG_PAX_SEGMEXEC
72444+ vma_m = pax_find_mirror_vma(vma);
72445+ if (vma_m) {
72446+ err = policy_vma(vma_m, new_pol);
72447+ if (err)
72448+ goto out;
72449+ }
72450+#endif
72451+
72452 }
72453
72454 out:
72455@@ -1106,6 +1120,17 @@ static long do_mbind(unsigned long start
72456
72457 if (end < start)
72458 return -EINVAL;
72459+
72460+#ifdef CONFIG_PAX_SEGMEXEC
72461+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72462+ if (end > SEGMEXEC_TASK_SIZE)
72463+ return -EINVAL;
72464+ } else
72465+#endif
72466+
72467+ if (end > TASK_SIZE)
72468+ return -EINVAL;
72469+
72470 if (end == start)
72471 return 0;
72472
72473@@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72474 if (!mm)
72475 goto out;
72476
72477+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72478+ if (mm != current->mm &&
72479+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72480+ err = -EPERM;
72481+ goto out;
72482+ }
72483+#endif
72484+
72485 /*
72486 * Check if this process has the right to modify the specified
72487 * process. The right exists if the process has administrative
72488@@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72489 rcu_read_lock();
72490 tcred = __task_cred(task);
72491 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72492- cred->uid != tcred->suid && cred->uid != tcred->uid &&
72493- !capable(CAP_SYS_NICE)) {
72494+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72495 rcu_read_unlock();
72496 err = -EPERM;
72497 goto out;
72498@@ -2634,7 +2666,7 @@ int show_numa_map(struct seq_file *m, vo
72499
72500 if (file) {
72501 seq_printf(m, " file=");
72502- seq_path(m, &file->f_path, "\n\t= ");
72503+ seq_path(m, &file->f_path, "\n\t\\= ");
72504 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
72505 seq_printf(m, " heap");
72506 } else if (vma->vm_start <= mm->start_stack &&
72507diff -urNp linux-2.6.39.1/mm/migrate.c linux-2.6.39.1/mm/migrate.c
72508--- linux-2.6.39.1/mm/migrate.c 2011-05-19 00:06:34.000000000 -0400
72509+++ linux-2.6.39.1/mm/migrate.c 2011-05-22 19:41:42.000000000 -0400
72510@@ -1133,6 +1133,8 @@ static int do_pages_move(struct mm_struc
72511 unsigned long chunk_start;
72512 int err;
72513
72514+ pax_track_stack();
72515+
72516 task_nodes = cpuset_mems_allowed(task);
72517
72518 err = -ENOMEM;
72519@@ -1317,6 +1319,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72520 if (!mm)
72521 return -EINVAL;
72522
72523+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72524+ if (mm != current->mm &&
72525+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72526+ err = -EPERM;
72527+ goto out;
72528+ }
72529+#endif
72530+
72531 /*
72532 * Check if this process has the right to modify the specified
72533 * process. The right exists if the process has administrative
72534@@ -1326,8 +1336,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72535 rcu_read_lock();
72536 tcred = __task_cred(task);
72537 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72538- cred->uid != tcred->suid && cred->uid != tcred->uid &&
72539- !capable(CAP_SYS_NICE)) {
72540+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72541 rcu_read_unlock();
72542 err = -EPERM;
72543 goto out;
72544diff -urNp linux-2.6.39.1/mm/mlock.c linux-2.6.39.1/mm/mlock.c
72545--- linux-2.6.39.1/mm/mlock.c 2011-05-19 00:06:34.000000000 -0400
72546+++ linux-2.6.39.1/mm/mlock.c 2011-05-22 19:41:42.000000000 -0400
72547@@ -13,6 +13,7 @@
72548 #include <linux/pagemap.h>
72549 #include <linux/mempolicy.h>
72550 #include <linux/syscalls.h>
72551+#include <linux/security.h>
72552 #include <linux/sched.h>
72553 #include <linux/module.h>
72554 #include <linux/rmap.h>
72555@@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
72556 return -EINVAL;
72557 if (end == start)
72558 return 0;
72559+ if (end > TASK_SIZE)
72560+ return -EINVAL;
72561+
72562 vma = find_vma_prev(current->mm, start, &prev);
72563 if (!vma || vma->vm_start > start)
72564 return -ENOMEM;
72565@@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
72566 for (nstart = start ; ; ) {
72567 unsigned int newflags;
72568
72569+#ifdef CONFIG_PAX_SEGMEXEC
72570+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72571+ break;
72572+#endif
72573+
72574 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72575
72576 newflags = vma->vm_flags | VM_LOCKED;
72577@@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
72578 lock_limit >>= PAGE_SHIFT;
72579
72580 /* check against resource limits */
72581+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72582 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72583 error = do_mlock(start, len, 1);
72584 up_write(&current->mm->mmap_sem);
72585@@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
72586 static int do_mlockall(int flags)
72587 {
72588 struct vm_area_struct * vma, * prev = NULL;
72589- unsigned int def_flags = 0;
72590
72591 if (flags & MCL_FUTURE)
72592- def_flags = VM_LOCKED;
72593- current->mm->def_flags = def_flags;
72594+ current->mm->def_flags |= VM_LOCKED;
72595+ else
72596+ current->mm->def_flags &= ~VM_LOCKED;
72597 if (flags == MCL_FUTURE)
72598 goto out;
72599
72600 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72601- unsigned int newflags;
72602+ unsigned long newflags;
72603+
72604+#ifdef CONFIG_PAX_SEGMEXEC
72605+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72606+ break;
72607+#endif
72608
72609+ BUG_ON(vma->vm_end > TASK_SIZE);
72610 newflags = vma->vm_flags | VM_LOCKED;
72611 if (!(flags & MCL_CURRENT))
72612 newflags &= ~VM_LOCKED;
72613@@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72614 lock_limit >>= PAGE_SHIFT;
72615
72616 ret = -ENOMEM;
72617+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72618 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72619 capable(CAP_IPC_LOCK))
72620 ret = do_mlockall(flags);
72621diff -urNp linux-2.6.39.1/mm/mmap.c linux-2.6.39.1/mm/mmap.c
72622--- linux-2.6.39.1/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
72623+++ linux-2.6.39.1/mm/mmap.c 2011-05-22 19:41:42.000000000 -0400
72624@@ -46,6 +46,16 @@
72625 #define arch_rebalance_pgtables(addr, len) (addr)
72626 #endif
72627
72628+static inline void verify_mm_writelocked(struct mm_struct *mm)
72629+{
72630+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72631+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72632+ up_read(&mm->mmap_sem);
72633+ BUG();
72634+ }
72635+#endif
72636+}
72637+
72638 static void unmap_region(struct mm_struct *mm,
72639 struct vm_area_struct *vma, struct vm_area_struct *prev,
72640 unsigned long start, unsigned long end);
72641@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
72642 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72643 *
72644 */
72645-pgprot_t protection_map[16] = {
72646+pgprot_t protection_map[16] __read_only = {
72647 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72648 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72649 };
72650
72651 pgprot_t vm_get_page_prot(unsigned long vm_flags)
72652 {
72653- return __pgprot(pgprot_val(protection_map[vm_flags &
72654+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72655 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72656 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72657+
72658+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72659+ if (!(__supported_pte_mask & _PAGE_NX) &&
72660+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72661+ (vm_flags & (VM_READ | VM_WRITE)))
72662+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72663+#endif
72664+
72665+ return prot;
72666 }
72667 EXPORT_SYMBOL(vm_get_page_prot);
72668
72669 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72670 int sysctl_overcommit_ratio = 50; /* default is 50% */
72671 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72672+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72673 struct percpu_counter vm_committed_as;
72674
72675 /*
72676@@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
72677 struct vm_area_struct *next = vma->vm_next;
72678
72679 might_sleep();
72680+ BUG_ON(vma->vm_mirror);
72681 if (vma->vm_ops && vma->vm_ops->close)
72682 vma->vm_ops->close(vma);
72683 if (vma->vm_file) {
72684@@ -276,6 +297,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72685 * not page aligned -Ram Gupta
72686 */
72687 rlim = rlimit(RLIMIT_DATA);
72688+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72689 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72690 (mm->end_data - mm->start_data) > rlim)
72691 goto out;
72692@@ -719,6 +741,12 @@ static int
72693 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72694 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72695 {
72696+
72697+#ifdef CONFIG_PAX_SEGMEXEC
72698+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72699+ return 0;
72700+#endif
72701+
72702 if (is_mergeable_vma(vma, file, vm_flags) &&
72703 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72704 if (vma->vm_pgoff == vm_pgoff)
72705@@ -738,6 +766,12 @@ static int
72706 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72707 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72708 {
72709+
72710+#ifdef CONFIG_PAX_SEGMEXEC
72711+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72712+ return 0;
72713+#endif
72714+
72715 if (is_mergeable_vma(vma, file, vm_flags) &&
72716 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72717 pgoff_t vm_pglen;
72718@@ -780,13 +814,20 @@ can_vma_merge_after(struct vm_area_struc
72719 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72720 struct vm_area_struct *prev, unsigned long addr,
72721 unsigned long end, unsigned long vm_flags,
72722- struct anon_vma *anon_vma, struct file *file,
72723+ struct anon_vma *anon_vma, struct file *file,
72724 pgoff_t pgoff, struct mempolicy *policy)
72725 {
72726 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72727 struct vm_area_struct *area, *next;
72728 int err;
72729
72730+#ifdef CONFIG_PAX_SEGMEXEC
72731+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72732+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72733+
72734+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72735+#endif
72736+
72737 /*
72738 * We later require that vma->vm_flags == vm_flags,
72739 * so this tests vma->vm_flags & VM_SPECIAL, too.
72740@@ -802,6 +843,15 @@ struct vm_area_struct *vma_merge(struct
72741 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72742 next = next->vm_next;
72743
72744+#ifdef CONFIG_PAX_SEGMEXEC
72745+ if (prev)
72746+ prev_m = pax_find_mirror_vma(prev);
72747+ if (area)
72748+ area_m = pax_find_mirror_vma(area);
72749+ if (next)
72750+ next_m = pax_find_mirror_vma(next);
72751+#endif
72752+
72753 /*
72754 * Can it merge with the predecessor?
72755 */
72756@@ -821,9 +871,24 @@ struct vm_area_struct *vma_merge(struct
72757 /* cases 1, 6 */
72758 err = vma_adjust(prev, prev->vm_start,
72759 next->vm_end, prev->vm_pgoff, NULL);
72760- } else /* cases 2, 5, 7 */
72761+
72762+#ifdef CONFIG_PAX_SEGMEXEC
72763+ if (!err && prev_m)
72764+ err = vma_adjust(prev_m, prev_m->vm_start,
72765+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72766+#endif
72767+
72768+ } else { /* cases 2, 5, 7 */
72769 err = vma_adjust(prev, prev->vm_start,
72770 end, prev->vm_pgoff, NULL);
72771+
72772+#ifdef CONFIG_PAX_SEGMEXEC
72773+ if (!err && prev_m)
72774+ err = vma_adjust(prev_m, prev_m->vm_start,
72775+ end_m, prev_m->vm_pgoff, NULL);
72776+#endif
72777+
72778+ }
72779 if (err)
72780 return NULL;
72781 khugepaged_enter_vma_merge(prev);
72782@@ -837,12 +902,27 @@ struct vm_area_struct *vma_merge(struct
72783 mpol_equal(policy, vma_policy(next)) &&
72784 can_vma_merge_before(next, vm_flags,
72785 anon_vma, file, pgoff+pglen)) {
72786- if (prev && addr < prev->vm_end) /* case 4 */
72787+ if (prev && addr < prev->vm_end) { /* case 4 */
72788 err = vma_adjust(prev, prev->vm_start,
72789 addr, prev->vm_pgoff, NULL);
72790- else /* cases 3, 8 */
72791+
72792+#ifdef CONFIG_PAX_SEGMEXEC
72793+ if (!err && prev_m)
72794+ err = vma_adjust(prev_m, prev_m->vm_start,
72795+ addr_m, prev_m->vm_pgoff, NULL);
72796+#endif
72797+
72798+ } else { /* cases 3, 8 */
72799 err = vma_adjust(area, addr, next->vm_end,
72800 next->vm_pgoff - pglen, NULL);
72801+
72802+#ifdef CONFIG_PAX_SEGMEXEC
72803+ if (!err && area_m)
72804+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72805+ next_m->vm_pgoff - pglen, NULL);
72806+#endif
72807+
72808+ }
72809 if (err)
72810 return NULL;
72811 khugepaged_enter_vma_merge(area);
72812@@ -958,14 +1038,11 @@ none:
72813 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72814 struct file *file, long pages)
72815 {
72816- const unsigned long stack_flags
72817- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72818-
72819 if (file) {
72820 mm->shared_vm += pages;
72821 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72822 mm->exec_vm += pages;
72823- } else if (flags & stack_flags)
72824+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72825 mm->stack_vm += pages;
72826 if (flags & (VM_RESERVED|VM_IO))
72827 mm->reserved_vm += pages;
72828@@ -992,7 +1069,7 @@ unsigned long do_mmap_pgoff(struct file
72829 * (the exception is when the underlying filesystem is noexec
72830 * mounted, in which case we dont add PROT_EXEC.)
72831 */
72832- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72833+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72834 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72835 prot |= PROT_EXEC;
72836
72837@@ -1018,7 +1095,7 @@ unsigned long do_mmap_pgoff(struct file
72838 /* Obtain the address to map to. we verify (or select) it and ensure
72839 * that it represents a valid section of the address space.
72840 */
72841- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72842+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72843 if (addr & ~PAGE_MASK)
72844 return addr;
72845
72846@@ -1029,6 +1106,36 @@ unsigned long do_mmap_pgoff(struct file
72847 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72848 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72849
72850+#ifdef CONFIG_PAX_MPROTECT
72851+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72852+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72853+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72854+ gr_log_rwxmmap(file);
72855+
72856+#ifdef CONFIG_PAX_EMUPLT
72857+ vm_flags &= ~VM_EXEC;
72858+#else
72859+ return -EPERM;
72860+#endif
72861+
72862+ }
72863+
72864+ if (!(vm_flags & VM_EXEC))
72865+ vm_flags &= ~VM_MAYEXEC;
72866+#else
72867+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72868+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72869+#endif
72870+ else
72871+ vm_flags &= ~VM_MAYWRITE;
72872+ }
72873+#endif
72874+
72875+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72876+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72877+ vm_flags &= ~VM_PAGEEXEC;
72878+#endif
72879+
72880 if (flags & MAP_LOCKED)
72881 if (!can_do_mlock())
72882 return -EPERM;
72883@@ -1040,6 +1147,7 @@ unsigned long do_mmap_pgoff(struct file
72884 locked += mm->locked_vm;
72885 lock_limit = rlimit(RLIMIT_MEMLOCK);
72886 lock_limit >>= PAGE_SHIFT;
72887+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72888 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72889 return -EAGAIN;
72890 }
72891@@ -1110,6 +1218,9 @@ unsigned long do_mmap_pgoff(struct file
72892 if (error)
72893 return error;
72894
72895+ if (!gr_acl_handle_mmap(file, prot))
72896+ return -EACCES;
72897+
72898 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72899 }
72900 EXPORT_SYMBOL(do_mmap_pgoff);
72901@@ -1187,10 +1298,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
72902 */
72903 int vma_wants_writenotify(struct vm_area_struct *vma)
72904 {
72905- unsigned int vm_flags = vma->vm_flags;
72906+ unsigned long vm_flags = vma->vm_flags;
72907
72908 /* If it was private or non-writable, the write bit is already clear */
72909- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72910+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72911 return 0;
72912
72913 /* The backer wishes to know when pages are first written to? */
72914@@ -1239,14 +1350,24 @@ unsigned long mmap_region(struct file *f
72915 unsigned long charged = 0;
72916 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72917
72918+#ifdef CONFIG_PAX_SEGMEXEC
72919+ struct vm_area_struct *vma_m = NULL;
72920+#endif
72921+
72922+ /*
72923+ * mm->mmap_sem is required to protect against another thread
72924+ * changing the mappings in case we sleep.
72925+ */
72926+ verify_mm_writelocked(mm);
72927+
72928 /* Clear old maps */
72929 error = -ENOMEM;
72930-munmap_back:
72931 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72932 if (vma && vma->vm_start < addr + len) {
72933 if (do_munmap(mm, addr, len))
72934 return -ENOMEM;
72935- goto munmap_back;
72936+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72937+ BUG_ON(vma && vma->vm_start < addr + len);
72938 }
72939
72940 /* Check against address space limit. */
72941@@ -1295,6 +1416,16 @@ munmap_back:
72942 goto unacct_error;
72943 }
72944
72945+#ifdef CONFIG_PAX_SEGMEXEC
72946+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72947+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72948+ if (!vma_m) {
72949+ error = -ENOMEM;
72950+ goto free_vma;
72951+ }
72952+ }
72953+#endif
72954+
72955 vma->vm_mm = mm;
72956 vma->vm_start = addr;
72957 vma->vm_end = addr + len;
72958@@ -1318,6 +1449,19 @@ munmap_back:
72959 error = file->f_op->mmap(file, vma);
72960 if (error)
72961 goto unmap_and_free_vma;
72962+
72963+#ifdef CONFIG_PAX_SEGMEXEC
72964+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72965+ added_exe_file_vma(mm);
72966+#endif
72967+
72968+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72969+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72970+ vma->vm_flags |= VM_PAGEEXEC;
72971+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72972+ }
72973+#endif
72974+
72975 if (vm_flags & VM_EXECUTABLE)
72976 added_exe_file_vma(mm);
72977
72978@@ -1353,6 +1497,11 @@ munmap_back:
72979 vma_link(mm, vma, prev, rb_link, rb_parent);
72980 file = vma->vm_file;
72981
72982+#ifdef CONFIG_PAX_SEGMEXEC
72983+ if (vma_m)
72984+ BUG_ON(pax_mirror_vma(vma_m, vma));
72985+#endif
72986+
72987 /* Once vma denies write, undo our temporary denial count */
72988 if (correct_wcount)
72989 atomic_inc(&inode->i_writecount);
72990@@ -1361,6 +1510,7 @@ out:
72991
72992 mm->total_vm += len >> PAGE_SHIFT;
72993 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72994+ track_exec_limit(mm, addr, addr + len, vm_flags);
72995 if (vm_flags & VM_LOCKED) {
72996 if (!mlock_vma_pages_range(vma, addr, addr + len))
72997 mm->locked_vm += (len >> PAGE_SHIFT);
72998@@ -1378,6 +1528,12 @@ unmap_and_free_vma:
72999 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73000 charged = 0;
73001 free_vma:
73002+
73003+#ifdef CONFIG_PAX_SEGMEXEC
73004+ if (vma_m)
73005+ kmem_cache_free(vm_area_cachep, vma_m);
73006+#endif
73007+
73008 kmem_cache_free(vm_area_cachep, vma);
73009 unacct_error:
73010 if (charged)
73011@@ -1385,6 +1541,44 @@ unacct_error:
73012 return error;
73013 }
73014
73015+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73016+{
73017+ if (!vma) {
73018+#ifdef CONFIG_STACK_GROWSUP
73019+ if (addr > sysctl_heap_stack_gap)
73020+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73021+ else
73022+ vma = find_vma(current->mm, 0);
73023+ if (vma && (vma->vm_flags & VM_GROWSUP))
73024+ return false;
73025+#endif
73026+ return true;
73027+ }
73028+
73029+ if (addr + len > vma->vm_start)
73030+ return false;
73031+
73032+ if (vma->vm_flags & VM_GROWSDOWN)
73033+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73034+#ifdef CONFIG_STACK_GROWSUP
73035+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73036+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73037+#endif
73038+
73039+ return true;
73040+}
73041+
73042+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73043+{
73044+ if (vma->vm_start < len)
73045+ return -ENOMEM;
73046+ if (!(vma->vm_flags & VM_GROWSDOWN))
73047+ return vma->vm_start - len;
73048+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
73049+ return vma->vm_start - len - sysctl_heap_stack_gap;
73050+ return -ENOMEM;
73051+}
73052+
73053 /* Get an address range which is currently unmapped.
73054 * For shmat() with addr=0.
73055 *
73056@@ -1411,18 +1605,23 @@ arch_get_unmapped_area(struct file *filp
73057 if (flags & MAP_FIXED)
73058 return addr;
73059
73060+#ifdef CONFIG_PAX_RANDMMAP
73061+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73062+#endif
73063+
73064 if (addr) {
73065 addr = PAGE_ALIGN(addr);
73066- vma = find_vma(mm, addr);
73067- if (TASK_SIZE - len >= addr &&
73068- (!vma || addr + len <= vma->vm_start))
73069- return addr;
73070+ if (TASK_SIZE - len >= addr) {
73071+ vma = find_vma(mm, addr);
73072+ if (check_heap_stack_gap(vma, addr, len))
73073+ return addr;
73074+ }
73075 }
73076 if (len > mm->cached_hole_size) {
73077- start_addr = addr = mm->free_area_cache;
73078+ start_addr = addr = mm->free_area_cache;
73079 } else {
73080- start_addr = addr = TASK_UNMAPPED_BASE;
73081- mm->cached_hole_size = 0;
73082+ start_addr = addr = mm->mmap_base;
73083+ mm->cached_hole_size = 0;
73084 }
73085
73086 full_search:
73087@@ -1433,34 +1632,40 @@ full_search:
73088 * Start a new search - just in case we missed
73089 * some holes.
73090 */
73091- if (start_addr != TASK_UNMAPPED_BASE) {
73092- addr = TASK_UNMAPPED_BASE;
73093- start_addr = addr;
73094+ if (start_addr != mm->mmap_base) {
73095+ start_addr = addr = mm->mmap_base;
73096 mm->cached_hole_size = 0;
73097 goto full_search;
73098 }
73099 return -ENOMEM;
73100 }
73101- if (!vma || addr + len <= vma->vm_start) {
73102- /*
73103- * Remember the place where we stopped the search:
73104- */
73105- mm->free_area_cache = addr + len;
73106- return addr;
73107- }
73108+ if (check_heap_stack_gap(vma, addr, len))
73109+ break;
73110 if (addr + mm->cached_hole_size < vma->vm_start)
73111 mm->cached_hole_size = vma->vm_start - addr;
73112 addr = vma->vm_end;
73113 }
73114+
73115+ /*
73116+ * Remember the place where we stopped the search:
73117+ */
73118+ mm->free_area_cache = addr + len;
73119+ return addr;
73120 }
73121 #endif
73122
73123 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73124 {
73125+
73126+#ifdef CONFIG_PAX_SEGMEXEC
73127+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73128+ return;
73129+#endif
73130+
73131 /*
73132 * Is this a new hole at the lowest possible address?
73133 */
73134- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
73135+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
73136 mm->free_area_cache = addr;
73137 mm->cached_hole_size = ~0UL;
73138 }
73139@@ -1478,7 +1683,7 @@ arch_get_unmapped_area_topdown(struct fi
73140 {
73141 struct vm_area_struct *vma;
73142 struct mm_struct *mm = current->mm;
73143- unsigned long addr = addr0;
73144+ unsigned long base = mm->mmap_base, addr = addr0;
73145
73146 /* requested length too big for entire address space */
73147 if (len > TASK_SIZE)
73148@@ -1487,13 +1692,18 @@ arch_get_unmapped_area_topdown(struct fi
73149 if (flags & MAP_FIXED)
73150 return addr;
73151
73152+#ifdef CONFIG_PAX_RANDMMAP
73153+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73154+#endif
73155+
73156 /* requesting a specific address */
73157 if (addr) {
73158 addr = PAGE_ALIGN(addr);
73159- vma = find_vma(mm, addr);
73160- if (TASK_SIZE - len >= addr &&
73161- (!vma || addr + len <= vma->vm_start))
73162- return addr;
73163+ if (TASK_SIZE - len >= addr) {
73164+ vma = find_vma(mm, addr);
73165+ if (check_heap_stack_gap(vma, addr, len))
73166+ return addr;
73167+ }
73168 }
73169
73170 /* check if free_area_cache is useful for us */
73171@@ -1508,7 +1718,7 @@ arch_get_unmapped_area_topdown(struct fi
73172 /* make sure it can fit in the remaining address space */
73173 if (addr > len) {
73174 vma = find_vma(mm, addr-len);
73175- if (!vma || addr <= vma->vm_start)
73176+ if (check_heap_stack_gap(vma, addr - len, len))
73177 /* remember the address as a hint for next time */
73178 return (mm->free_area_cache = addr-len);
73179 }
73180@@ -1525,7 +1735,7 @@ arch_get_unmapped_area_topdown(struct fi
73181 * return with success:
73182 */
73183 vma = find_vma(mm, addr);
73184- if (!vma || addr+len <= vma->vm_start)
73185+ if (check_heap_stack_gap(vma, addr, len))
73186 /* remember the address as a hint for next time */
73187 return (mm->free_area_cache = addr);
73188
73189@@ -1534,8 +1744,8 @@ arch_get_unmapped_area_topdown(struct fi
73190 mm->cached_hole_size = vma->vm_start - addr;
73191
73192 /* try just below the current vma->vm_start */
73193- addr = vma->vm_start-len;
73194- } while (len < vma->vm_start);
73195+ addr = skip_heap_stack_gap(vma, len);
73196+ } while (!IS_ERR_VALUE(addr));
73197
73198 bottomup:
73199 /*
73200@@ -1544,13 +1754,21 @@ bottomup:
73201 * can happen with large stack limits and large mmap()
73202 * allocations.
73203 */
73204+ mm->mmap_base = TASK_UNMAPPED_BASE;
73205+
73206+#ifdef CONFIG_PAX_RANDMMAP
73207+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73208+ mm->mmap_base += mm->delta_mmap;
73209+#endif
73210+
73211+ mm->free_area_cache = mm->mmap_base;
73212 mm->cached_hole_size = ~0UL;
73213- mm->free_area_cache = TASK_UNMAPPED_BASE;
73214 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73215 /*
73216 * Restore the topdown base:
73217 */
73218- mm->free_area_cache = mm->mmap_base;
73219+ mm->mmap_base = base;
73220+ mm->free_area_cache = base;
73221 mm->cached_hole_size = ~0UL;
73222
73223 return addr;
73224@@ -1559,6 +1777,12 @@ bottomup:
73225
73226 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73227 {
73228+
73229+#ifdef CONFIG_PAX_SEGMEXEC
73230+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73231+ return;
73232+#endif
73233+
73234 /*
73235 * Is this a new hole at the highest possible address?
73236 */
73237@@ -1566,8 +1790,10 @@ void arch_unmap_area_topdown(struct mm_s
73238 mm->free_area_cache = addr;
73239
73240 /* dont allow allocations above current base */
73241- if (mm->free_area_cache > mm->mmap_base)
73242+ if (mm->free_area_cache > mm->mmap_base) {
73243 mm->free_area_cache = mm->mmap_base;
73244+ mm->cached_hole_size = ~0UL;
73245+ }
73246 }
73247
73248 unsigned long
73249@@ -1675,6 +1901,28 @@ out:
73250 return prev ? prev->vm_next : vma;
73251 }
73252
73253+#ifdef CONFIG_PAX_SEGMEXEC
73254+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73255+{
73256+ struct vm_area_struct *vma_m;
73257+
73258+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73259+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73260+ BUG_ON(vma->vm_mirror);
73261+ return NULL;
73262+ }
73263+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73264+ vma_m = vma->vm_mirror;
73265+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73266+ BUG_ON(vma->vm_file != vma_m->vm_file);
73267+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73268+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73269+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73270+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73271+ return vma_m;
73272+}
73273+#endif
73274+
73275 /*
73276 * Verify that the stack growth is acceptable and
73277 * update accounting. This is shared with both the
73278@@ -1691,6 +1939,7 @@ static int acct_stack_growth(struct vm_a
73279 return -ENOMEM;
73280
73281 /* Stack limit test */
73282+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73283 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73284 return -ENOMEM;
73285
73286@@ -1701,6 +1950,7 @@ static int acct_stack_growth(struct vm_a
73287 locked = mm->locked_vm + grow;
73288 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73289 limit >>= PAGE_SHIFT;
73290+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73291 if (locked > limit && !capable(CAP_IPC_LOCK))
73292 return -ENOMEM;
73293 }
73294@@ -1731,37 +1981,48 @@ static int acct_stack_growth(struct vm_a
73295 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73296 * vma is the last one with address > vma->vm_end. Have to extend vma.
73297 */
73298+#ifndef CONFIG_IA64
73299+static
73300+#endif
73301 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73302 {
73303 int error;
73304+ bool locknext;
73305
73306 if (!(vma->vm_flags & VM_GROWSUP))
73307 return -EFAULT;
73308
73309+ /* Also guard against wrapping around to address 0. */
73310+ if (address < PAGE_ALIGN(address+1))
73311+ address = PAGE_ALIGN(address+1);
73312+ else
73313+ return -ENOMEM;
73314+
73315 /*
73316 * We must make sure the anon_vma is allocated
73317 * so that the anon_vma locking is not a noop.
73318 */
73319 if (unlikely(anon_vma_prepare(vma)))
73320 return -ENOMEM;
73321+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73322+ if (locknext && anon_vma_prepare(vma->vm_next))
73323+ return -ENOMEM;
73324 vma_lock_anon_vma(vma);
73325+ if (locknext)
73326+ vma_lock_anon_vma(vma->vm_next);
73327
73328 /*
73329 * vma->vm_start/vm_end cannot change under us because the caller
73330 * is required to hold the mmap_sem in read mode. We need the
73331- * anon_vma lock to serialize against concurrent expand_stacks.
73332- * Also guard against wrapping around to address 0.
73333+ * anon_vma locks to serialize against concurrent expand_stacks
73334+ * and expand_upwards.
73335 */
73336- if (address < PAGE_ALIGN(address+4))
73337- address = PAGE_ALIGN(address+4);
73338- else {
73339- vma_unlock_anon_vma(vma);
73340- return -ENOMEM;
73341- }
73342 error = 0;
73343
73344 /* Somebody else might have raced and expanded it already */
73345- if (address > vma->vm_end) {
73346+ 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)
73347+ error = -ENOMEM;
73348+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73349 unsigned long size, grow;
73350
73351 size = address - vma->vm_start;
73352@@ -1776,6 +2037,8 @@ int expand_upwards(struct vm_area_struct
73353 }
73354 }
73355 }
73356+ if (locknext)
73357+ vma_unlock_anon_vma(vma->vm_next);
73358 vma_unlock_anon_vma(vma);
73359 khugepaged_enter_vma_merge(vma);
73360 return error;
73361@@ -1789,6 +2052,8 @@ static int expand_downwards(struct vm_ar
73362 unsigned long address)
73363 {
73364 int error;
73365+ bool lockprev = false;
73366+ struct vm_area_struct *prev;
73367
73368 /*
73369 * We must make sure the anon_vma is allocated
73370@@ -1802,6 +2067,15 @@ static int expand_downwards(struct vm_ar
73371 if (error)
73372 return error;
73373
73374+ prev = vma->vm_prev;
73375+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73376+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73377+#endif
73378+ if (lockprev && anon_vma_prepare(prev))
73379+ return -ENOMEM;
73380+ if (lockprev)
73381+ vma_lock_anon_vma(prev);
73382+
73383 vma_lock_anon_vma(vma);
73384
73385 /*
73386@@ -1811,9 +2085,17 @@ static int expand_downwards(struct vm_ar
73387 */
73388
73389 /* Somebody else might have raced and expanded it already */
73390- if (address < vma->vm_start) {
73391+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73392+ error = -ENOMEM;
73393+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73394 unsigned long size, grow;
73395
73396+#ifdef CONFIG_PAX_SEGMEXEC
73397+ struct vm_area_struct *vma_m;
73398+
73399+ vma_m = pax_find_mirror_vma(vma);
73400+#endif
73401+
73402 size = vma->vm_end - address;
73403 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73404
73405@@ -1823,11 +2105,22 @@ static int expand_downwards(struct vm_ar
73406 if (!error) {
73407 vma->vm_start = address;
73408 vma->vm_pgoff -= grow;
73409+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73410+
73411+#ifdef CONFIG_PAX_SEGMEXEC
73412+ if (vma_m) {
73413+ vma_m->vm_start -= grow << PAGE_SHIFT;
73414+ vma_m->vm_pgoff -= grow;
73415+ }
73416+#endif
73417+
73418 perf_event_mmap(vma);
73419 }
73420 }
73421 }
73422 vma_unlock_anon_vma(vma);
73423+ if (lockprev)
73424+ vma_unlock_anon_vma(prev);
73425 khugepaged_enter_vma_merge(vma);
73426 return error;
73427 }
73428@@ -1902,6 +2195,13 @@ static void remove_vma_list(struct mm_st
73429 do {
73430 long nrpages = vma_pages(vma);
73431
73432+#ifdef CONFIG_PAX_SEGMEXEC
73433+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73434+ vma = remove_vma(vma);
73435+ continue;
73436+ }
73437+#endif
73438+
73439 mm->total_vm -= nrpages;
73440 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73441 vma = remove_vma(vma);
73442@@ -1947,6 +2247,16 @@ detach_vmas_to_be_unmapped(struct mm_str
73443 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73444 vma->vm_prev = NULL;
73445 do {
73446+
73447+#ifdef CONFIG_PAX_SEGMEXEC
73448+ if (vma->vm_mirror) {
73449+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73450+ vma->vm_mirror->vm_mirror = NULL;
73451+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
73452+ vma->vm_mirror = NULL;
73453+ }
73454+#endif
73455+
73456 rb_erase(&vma->vm_rb, &mm->mm_rb);
73457 mm->map_count--;
73458 tail_vma = vma;
73459@@ -1975,14 +2285,33 @@ static int __split_vma(struct mm_struct
73460 struct vm_area_struct *new;
73461 int err = -ENOMEM;
73462
73463+#ifdef CONFIG_PAX_SEGMEXEC
73464+ struct vm_area_struct *vma_m, *new_m = NULL;
73465+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73466+#endif
73467+
73468 if (is_vm_hugetlb_page(vma) && (addr &
73469 ~(huge_page_mask(hstate_vma(vma)))))
73470 return -EINVAL;
73471
73472+#ifdef CONFIG_PAX_SEGMEXEC
73473+ vma_m = pax_find_mirror_vma(vma);
73474+#endif
73475+
73476 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73477 if (!new)
73478 goto out_err;
73479
73480+#ifdef CONFIG_PAX_SEGMEXEC
73481+ if (vma_m) {
73482+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73483+ if (!new_m) {
73484+ kmem_cache_free(vm_area_cachep, new);
73485+ goto out_err;
73486+ }
73487+ }
73488+#endif
73489+
73490 /* most fields are the same, copy all, and then fixup */
73491 *new = *vma;
73492
73493@@ -1995,6 +2324,22 @@ static int __split_vma(struct mm_struct
73494 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73495 }
73496
73497+#ifdef CONFIG_PAX_SEGMEXEC
73498+ if (vma_m) {
73499+ *new_m = *vma_m;
73500+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
73501+ new_m->vm_mirror = new;
73502+ new->vm_mirror = new_m;
73503+
73504+ if (new_below)
73505+ new_m->vm_end = addr_m;
73506+ else {
73507+ new_m->vm_start = addr_m;
73508+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73509+ }
73510+ }
73511+#endif
73512+
73513 pol = mpol_dup(vma_policy(vma));
73514 if (IS_ERR(pol)) {
73515 err = PTR_ERR(pol);
73516@@ -2020,6 +2365,42 @@ static int __split_vma(struct mm_struct
73517 else
73518 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73519
73520+#ifdef CONFIG_PAX_SEGMEXEC
73521+ if (!err && vma_m) {
73522+ if (anon_vma_clone(new_m, vma_m))
73523+ goto out_free_mpol;
73524+
73525+ mpol_get(pol);
73526+ vma_set_policy(new_m, pol);
73527+
73528+ if (new_m->vm_file) {
73529+ get_file(new_m->vm_file);
73530+ if (vma_m->vm_flags & VM_EXECUTABLE)
73531+ added_exe_file_vma(mm);
73532+ }
73533+
73534+ if (new_m->vm_ops && new_m->vm_ops->open)
73535+ new_m->vm_ops->open(new_m);
73536+
73537+ if (new_below)
73538+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73539+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73540+ else
73541+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73542+
73543+ if (err) {
73544+ if (new_m->vm_ops && new_m->vm_ops->close)
73545+ new_m->vm_ops->close(new_m);
73546+ if (new_m->vm_file) {
73547+ if (vma_m->vm_flags & VM_EXECUTABLE)
73548+ removed_exe_file_vma(mm);
73549+ fput(new_m->vm_file);
73550+ }
73551+ mpol_put(pol);
73552+ }
73553+ }
73554+#endif
73555+
73556 /* Success. */
73557 if (!err)
73558 return 0;
73559@@ -2032,10 +2413,18 @@ static int __split_vma(struct mm_struct
73560 removed_exe_file_vma(mm);
73561 fput(new->vm_file);
73562 }
73563- unlink_anon_vmas(new);
73564 out_free_mpol:
73565 mpol_put(pol);
73566 out_free_vma:
73567+
73568+#ifdef CONFIG_PAX_SEGMEXEC
73569+ if (new_m) {
73570+ unlink_anon_vmas(new_m);
73571+ kmem_cache_free(vm_area_cachep, new_m);
73572+ }
73573+#endif
73574+
73575+ unlink_anon_vmas(new);
73576 kmem_cache_free(vm_area_cachep, new);
73577 out_err:
73578 return err;
73579@@ -2048,6 +2437,15 @@ static int __split_vma(struct mm_struct
73580 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73581 unsigned long addr, int new_below)
73582 {
73583+
73584+#ifdef CONFIG_PAX_SEGMEXEC
73585+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73586+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73587+ if (mm->map_count >= sysctl_max_map_count-1)
73588+ return -ENOMEM;
73589+ } else
73590+#endif
73591+
73592 if (mm->map_count >= sysctl_max_map_count)
73593 return -ENOMEM;
73594
73595@@ -2059,11 +2457,30 @@ int split_vma(struct mm_struct *mm, stru
73596 * work. This now handles partial unmappings.
73597 * Jeremy Fitzhardinge <jeremy@goop.org>
73598 */
73599+#ifdef CONFIG_PAX_SEGMEXEC
73600+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73601+{
73602+ int ret = __do_munmap(mm, start, len);
73603+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73604+ return ret;
73605+
73606+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73607+}
73608+
73609+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73610+#else
73611 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73612+#endif
73613 {
73614 unsigned long end;
73615 struct vm_area_struct *vma, *prev, *last;
73616
73617+ /*
73618+ * mm->mmap_sem is required to protect against another thread
73619+ * changing the mappings in case we sleep.
73620+ */
73621+ verify_mm_writelocked(mm);
73622+
73623 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73624 return -EINVAL;
73625
73626@@ -2137,6 +2554,8 @@ int do_munmap(struct mm_struct *mm, unsi
73627 /* Fix up all other VM information */
73628 remove_vma_list(mm, vma);
73629
73630+ track_exec_limit(mm, start, end, 0UL);
73631+
73632 return 0;
73633 }
73634
73635@@ -2149,22 +2568,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
73636
73637 profile_munmap(addr);
73638
73639+#ifdef CONFIG_PAX_SEGMEXEC
73640+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73641+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73642+ return -EINVAL;
73643+#endif
73644+
73645 down_write(&mm->mmap_sem);
73646 ret = do_munmap(mm, addr, len);
73647 up_write(&mm->mmap_sem);
73648 return ret;
73649 }
73650
73651-static inline void verify_mm_writelocked(struct mm_struct *mm)
73652-{
73653-#ifdef CONFIG_DEBUG_VM
73654- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73655- WARN_ON(1);
73656- up_read(&mm->mmap_sem);
73657- }
73658-#endif
73659-}
73660-
73661 /*
73662 * this is really a simplified "do_mmap". it only handles
73663 * anonymous maps. eventually we may be able to do some
73664@@ -2178,6 +2593,7 @@ unsigned long do_brk(unsigned long addr,
73665 struct rb_node ** rb_link, * rb_parent;
73666 pgoff_t pgoff = addr >> PAGE_SHIFT;
73667 int error;
73668+ unsigned long charged;
73669
73670 len = PAGE_ALIGN(len);
73671 if (!len)
73672@@ -2189,16 +2605,30 @@ unsigned long do_brk(unsigned long addr,
73673
73674 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73675
73676+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73677+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73678+ flags &= ~VM_EXEC;
73679+
73680+#ifdef CONFIG_PAX_MPROTECT
73681+ if (mm->pax_flags & MF_PAX_MPROTECT)
73682+ flags &= ~VM_MAYEXEC;
73683+#endif
73684+
73685+ }
73686+#endif
73687+
73688 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73689 if (error & ~PAGE_MASK)
73690 return error;
73691
73692+ charged = len >> PAGE_SHIFT;
73693+
73694 /*
73695 * mlock MCL_FUTURE?
73696 */
73697 if (mm->def_flags & VM_LOCKED) {
73698 unsigned long locked, lock_limit;
73699- locked = len >> PAGE_SHIFT;
73700+ locked = charged;
73701 locked += mm->locked_vm;
73702 lock_limit = rlimit(RLIMIT_MEMLOCK);
73703 lock_limit >>= PAGE_SHIFT;
73704@@ -2215,22 +2645,22 @@ unsigned long do_brk(unsigned long addr,
73705 /*
73706 * Clear old maps. this also does some error checking for us
73707 */
73708- munmap_back:
73709 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73710 if (vma && vma->vm_start < addr + len) {
73711 if (do_munmap(mm, addr, len))
73712 return -ENOMEM;
73713- goto munmap_back;
73714+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73715+ BUG_ON(vma && vma->vm_start < addr + len);
73716 }
73717
73718 /* Check against address space limits *after* clearing old maps... */
73719- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73720+ if (!may_expand_vm(mm, charged))
73721 return -ENOMEM;
73722
73723 if (mm->map_count > sysctl_max_map_count)
73724 return -ENOMEM;
73725
73726- if (security_vm_enough_memory(len >> PAGE_SHIFT))
73727+ if (security_vm_enough_memory(charged))
73728 return -ENOMEM;
73729
73730 /* Can we just expand an old private anonymous mapping? */
73731@@ -2244,7 +2674,7 @@ unsigned long do_brk(unsigned long addr,
73732 */
73733 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73734 if (!vma) {
73735- vm_unacct_memory(len >> PAGE_SHIFT);
73736+ vm_unacct_memory(charged);
73737 return -ENOMEM;
73738 }
73739
73740@@ -2258,11 +2688,12 @@ unsigned long do_brk(unsigned long addr,
73741 vma_link(mm, vma, prev, rb_link, rb_parent);
73742 out:
73743 perf_event_mmap(vma);
73744- mm->total_vm += len >> PAGE_SHIFT;
73745+ mm->total_vm += charged;
73746 if (flags & VM_LOCKED) {
73747 if (!mlock_vma_pages_range(vma, addr, addr + len))
73748- mm->locked_vm += (len >> PAGE_SHIFT);
73749+ mm->locked_vm += charged;
73750 }
73751+ track_exec_limit(mm, addr, addr + len, flags);
73752 return addr;
73753 }
73754
73755@@ -2309,8 +2740,10 @@ void exit_mmap(struct mm_struct *mm)
73756 * Walk the list again, actually closing and freeing it,
73757 * with preemption enabled, without holding any MM locks.
73758 */
73759- while (vma)
73760+ while (vma) {
73761+ vma->vm_mirror = NULL;
73762 vma = remove_vma(vma);
73763+ }
73764
73765 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73766 }
73767@@ -2324,6 +2757,13 @@ int insert_vm_struct(struct mm_struct *
73768 struct vm_area_struct * __vma, * prev;
73769 struct rb_node ** rb_link, * rb_parent;
73770
73771+#ifdef CONFIG_PAX_SEGMEXEC
73772+ struct vm_area_struct *vma_m = NULL;
73773+#endif
73774+
73775+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
73776+ return -EPERM;
73777+
73778 /*
73779 * The vm_pgoff of a purely anonymous vma should be irrelevant
73780 * until its first write fault, when page's anon_vma and index
73781@@ -2346,7 +2786,22 @@ int insert_vm_struct(struct mm_struct *
73782 if ((vma->vm_flags & VM_ACCOUNT) &&
73783 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73784 return -ENOMEM;
73785+
73786+#ifdef CONFIG_PAX_SEGMEXEC
73787+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73788+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73789+ if (!vma_m)
73790+ return -ENOMEM;
73791+ }
73792+#endif
73793+
73794 vma_link(mm, vma, prev, rb_link, rb_parent);
73795+
73796+#ifdef CONFIG_PAX_SEGMEXEC
73797+ if (vma_m)
73798+ BUG_ON(pax_mirror_vma(vma_m, vma));
73799+#endif
73800+
73801 return 0;
73802 }
73803
73804@@ -2364,6 +2819,8 @@ struct vm_area_struct *copy_vma(struct v
73805 struct rb_node **rb_link, *rb_parent;
73806 struct mempolicy *pol;
73807
73808+ BUG_ON(vma->vm_mirror);
73809+
73810 /*
73811 * If anonymous vma has not yet been faulted, update new pgoff
73812 * to match new location, to increase its chance of merging.
73813@@ -2413,6 +2870,39 @@ struct vm_area_struct *copy_vma(struct v
73814 kmem_cache_free(vm_area_cachep, new_vma);
73815 return NULL;
73816 }
73817+
73818+#ifdef CONFIG_PAX_SEGMEXEC
73819+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73820+{
73821+ struct vm_area_struct *prev_m;
73822+ struct rb_node **rb_link_m, *rb_parent_m;
73823+ struct mempolicy *pol_m;
73824+
73825+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73826+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73827+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73828+ *vma_m = *vma;
73829+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73830+ if (anon_vma_clone(vma_m, vma))
73831+ return -ENOMEM;
73832+ pol_m = vma_policy(vma_m);
73833+ mpol_get(pol_m);
73834+ vma_set_policy(vma_m, pol_m);
73835+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73836+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73837+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73838+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73839+ if (vma_m->vm_file)
73840+ get_file(vma_m->vm_file);
73841+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73842+ vma_m->vm_ops->open(vma_m);
73843+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73844+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73845+ vma_m->vm_mirror = vma;
73846+ vma->vm_mirror = vma_m;
73847+ return 0;
73848+}
73849+#endif
73850
73851 /*
73852 * Return true if the calling process may expand its vm space by the passed
73853@@ -2424,7 +2914,7 @@ int may_expand_vm(struct mm_struct *mm,
73854 unsigned long lim;
73855
73856 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73857-
73858+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73859 if (cur + npages > lim)
73860 return 0;
73861 return 1;
73862@@ -2495,6 +2985,22 @@ int install_special_mapping(struct mm_st
73863 vma->vm_start = addr;
73864 vma->vm_end = addr + len;
73865
73866+#ifdef CONFIG_PAX_MPROTECT
73867+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73868+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73869+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73870+ return -EPERM;
73871+ if (!(vm_flags & VM_EXEC))
73872+ vm_flags &= ~VM_MAYEXEC;
73873+#else
73874+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73875+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73876+#endif
73877+ else
73878+ vm_flags &= ~VM_MAYWRITE;
73879+ }
73880+#endif
73881+
73882 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73883 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73884
73885diff -urNp linux-2.6.39.1/mm/mprotect.c linux-2.6.39.1/mm/mprotect.c
73886--- linux-2.6.39.1/mm/mprotect.c 2011-05-19 00:06:34.000000000 -0400
73887+++ linux-2.6.39.1/mm/mprotect.c 2011-05-22 19:41:42.000000000 -0400
73888@@ -23,10 +23,16 @@
73889 #include <linux/mmu_notifier.h>
73890 #include <linux/migrate.h>
73891 #include <linux/perf_event.h>
73892+
73893+#ifdef CONFIG_PAX_MPROTECT
73894+#include <linux/elf.h>
73895+#endif
73896+
73897 #include <asm/uaccess.h>
73898 #include <asm/pgtable.h>
73899 #include <asm/cacheflush.h>
73900 #include <asm/tlbflush.h>
73901+#include <asm/mmu_context.h>
73902
73903 #ifndef pgprot_modify
73904 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73905@@ -141,6 +147,48 @@ static void change_protection(struct vm_
73906 flush_tlb_range(vma, start, end);
73907 }
73908
73909+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73910+/* called while holding the mmap semaphor for writing except stack expansion */
73911+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73912+{
73913+ unsigned long oldlimit, newlimit = 0UL;
73914+
73915+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73916+ return;
73917+
73918+ spin_lock(&mm->page_table_lock);
73919+ oldlimit = mm->context.user_cs_limit;
73920+ if ((prot & VM_EXEC) && oldlimit < end)
73921+ /* USER_CS limit moved up */
73922+ newlimit = end;
73923+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73924+ /* USER_CS limit moved down */
73925+ newlimit = start;
73926+
73927+ if (newlimit) {
73928+ mm->context.user_cs_limit = newlimit;
73929+
73930+#ifdef CONFIG_SMP
73931+ wmb();
73932+ cpus_clear(mm->context.cpu_user_cs_mask);
73933+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73934+#endif
73935+
73936+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73937+ }
73938+ spin_unlock(&mm->page_table_lock);
73939+ if (newlimit == end) {
73940+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73941+
73942+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73943+ if (is_vm_hugetlb_page(vma))
73944+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73945+ else
73946+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73947+ }
73948+}
73949+#endif
73950+
73951 int
73952 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73953 unsigned long start, unsigned long end, unsigned long newflags)
73954@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
73955 int error;
73956 int dirty_accountable = 0;
73957
73958+#ifdef CONFIG_PAX_SEGMEXEC
73959+ struct vm_area_struct *vma_m = NULL;
73960+ unsigned long start_m, end_m;
73961+
73962+ start_m = start + SEGMEXEC_TASK_SIZE;
73963+ end_m = end + SEGMEXEC_TASK_SIZE;
73964+#endif
73965+
73966 if (newflags == oldflags) {
73967 *pprev = vma;
73968 return 0;
73969 }
73970
73971+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73972+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73973+
73974+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73975+ return -ENOMEM;
73976+
73977+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73978+ return -ENOMEM;
73979+ }
73980+
73981 /*
73982 * If we make a private mapping writable we increase our commit;
73983 * but (without finer accounting) cannot reduce our commit if we
73984@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
73985 }
73986 }
73987
73988+#ifdef CONFIG_PAX_SEGMEXEC
73989+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73990+ if (start != vma->vm_start) {
73991+ error = split_vma(mm, vma, start, 1);
73992+ if (error)
73993+ goto fail;
73994+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73995+ *pprev = (*pprev)->vm_next;
73996+ }
73997+
73998+ if (end != vma->vm_end) {
73999+ error = split_vma(mm, vma, end, 0);
74000+ if (error)
74001+ goto fail;
74002+ }
74003+
74004+ if (pax_find_mirror_vma(vma)) {
74005+ error = __do_munmap(mm, start_m, end_m - start_m);
74006+ if (error)
74007+ goto fail;
74008+ } else {
74009+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74010+ if (!vma_m) {
74011+ error = -ENOMEM;
74012+ goto fail;
74013+ }
74014+ vma->vm_flags = newflags;
74015+ error = pax_mirror_vma(vma_m, vma);
74016+ if (error) {
74017+ vma->vm_flags = oldflags;
74018+ goto fail;
74019+ }
74020+ }
74021+ }
74022+#endif
74023+
74024 /*
74025 * First try to merge with previous and/or next vma.
74026 */
74027@@ -204,9 +306,21 @@ success:
74028 * vm_flags and vm_page_prot are protected by the mmap_sem
74029 * held in write mode.
74030 */
74031+
74032+#ifdef CONFIG_PAX_SEGMEXEC
74033+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74034+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74035+#endif
74036+
74037 vma->vm_flags = newflags;
74038+
74039+#ifdef CONFIG_PAX_MPROTECT
74040+ if (mm->binfmt && mm->binfmt->handle_mprotect)
74041+ mm->binfmt->handle_mprotect(vma, newflags);
74042+#endif
74043+
74044 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74045- vm_get_page_prot(newflags));
74046+ vm_get_page_prot(vma->vm_flags));
74047
74048 if (vma_wants_writenotify(vma)) {
74049 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74050@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74051 end = start + len;
74052 if (end <= start)
74053 return -ENOMEM;
74054+
74055+#ifdef CONFIG_PAX_SEGMEXEC
74056+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74057+ if (end > SEGMEXEC_TASK_SIZE)
74058+ return -EINVAL;
74059+ } else
74060+#endif
74061+
74062+ if (end > TASK_SIZE)
74063+ return -EINVAL;
74064+
74065 if (!arch_validate_prot(prot))
74066 return -EINVAL;
74067
74068@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74069 /*
74070 * Does the application expect PROT_READ to imply PROT_EXEC:
74071 */
74072- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74073+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74074 prot |= PROT_EXEC;
74075
74076 vm_flags = calc_vm_prot_bits(prot);
74077@@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74078 if (start > vma->vm_start)
74079 prev = vma;
74080
74081+#ifdef CONFIG_PAX_MPROTECT
74082+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74083+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
74084+#endif
74085+
74086 for (nstart = start ; ; ) {
74087 unsigned long newflags;
74088
74089@@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74090
74091 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74092 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74093+ if (prot & (PROT_WRITE | PROT_EXEC))
74094+ gr_log_rwxmprotect(vma->vm_file);
74095+
74096+ error = -EACCES;
74097+ goto out;
74098+ }
74099+
74100+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74101 error = -EACCES;
74102 goto out;
74103 }
74104@@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74105 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74106 if (error)
74107 goto out;
74108+
74109+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
74110+
74111 nstart = tmp;
74112
74113 if (nstart < prev->vm_end)
74114diff -urNp linux-2.6.39.1/mm/mremap.c linux-2.6.39.1/mm/mremap.c
74115--- linux-2.6.39.1/mm/mremap.c 2011-05-19 00:06:34.000000000 -0400
74116+++ linux-2.6.39.1/mm/mremap.c 2011-05-22 19:36:33.000000000 -0400
74117@@ -114,6 +114,12 @@ static void move_ptes(struct vm_area_str
74118 continue;
74119 pte = ptep_clear_flush(vma, old_addr, old_pte);
74120 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74121+
74122+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74123+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74124+ pte = pte_exprotect(pte);
74125+#endif
74126+
74127 set_pte_at(mm, new_addr, new_pte, pte);
74128 }
74129
74130@@ -273,6 +279,11 @@ static struct vm_area_struct *vma_to_res
74131 if (is_vm_hugetlb_page(vma))
74132 goto Einval;
74133
74134+#ifdef CONFIG_PAX_SEGMEXEC
74135+ if (pax_find_mirror_vma(vma))
74136+ goto Einval;
74137+#endif
74138+
74139 /* We can't remap across vm area boundaries */
74140 if (old_len > vma->vm_end - addr)
74141 goto Efault;
74142@@ -329,20 +340,25 @@ static unsigned long mremap_to(unsigned
74143 unsigned long ret = -EINVAL;
74144 unsigned long charged = 0;
74145 unsigned long map_flags;
74146+ unsigned long pax_task_size = TASK_SIZE;
74147
74148 if (new_addr & ~PAGE_MASK)
74149 goto out;
74150
74151- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74152+#ifdef CONFIG_PAX_SEGMEXEC
74153+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74154+ pax_task_size = SEGMEXEC_TASK_SIZE;
74155+#endif
74156+
74157+ pax_task_size -= PAGE_SIZE;
74158+
74159+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74160 goto out;
74161
74162 /* Check if the location we're moving into overlaps the
74163 * old location at all, and fail if it does.
74164 */
74165- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74166- goto out;
74167-
74168- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74169+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74170 goto out;
74171
74172 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74173@@ -414,6 +430,7 @@ unsigned long do_mremap(unsigned long ad
74174 struct vm_area_struct *vma;
74175 unsigned long ret = -EINVAL;
74176 unsigned long charged = 0;
74177+ unsigned long pax_task_size = TASK_SIZE;
74178
74179 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
74180 goto out;
74181@@ -432,6 +449,17 @@ unsigned long do_mremap(unsigned long ad
74182 if (!new_len)
74183 goto out;
74184
74185+#ifdef CONFIG_PAX_SEGMEXEC
74186+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74187+ pax_task_size = SEGMEXEC_TASK_SIZE;
74188+#endif
74189+
74190+ pax_task_size -= PAGE_SIZE;
74191+
74192+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74193+ old_len > pax_task_size || addr > pax_task_size-old_len)
74194+ goto out;
74195+
74196 if (flags & MREMAP_FIXED) {
74197 if (flags & MREMAP_MAYMOVE)
74198 ret = mremap_to(addr, old_len, new_addr, new_len);
74199@@ -481,6 +509,7 @@ unsigned long do_mremap(unsigned long ad
74200 addr + new_len);
74201 }
74202 ret = addr;
74203+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74204 goto out;
74205 }
74206 }
74207@@ -507,7 +536,13 @@ unsigned long do_mremap(unsigned long ad
74208 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74209 if (ret)
74210 goto out;
74211+
74212+ map_flags = vma->vm_flags;
74213 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74214+ if (!(ret & ~PAGE_MASK)) {
74215+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74216+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74217+ }
74218 }
74219 out:
74220 if (ret & ~PAGE_MASK)
74221diff -urNp linux-2.6.39.1/mm/nobootmem.c linux-2.6.39.1/mm/nobootmem.c
74222--- linux-2.6.39.1/mm/nobootmem.c 2011-05-19 00:06:34.000000000 -0400
74223+++ linux-2.6.39.1/mm/nobootmem.c 2011-05-22 19:36:33.000000000 -0400
74224@@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
74225 unsigned long __init free_all_memory_core_early(int nodeid)
74226 {
74227 int i;
74228- u64 start, end;
74229+ u64 start, end, startrange, endrange;
74230 unsigned long count = 0;
74231- struct range *range = NULL;
74232+ struct range *range = NULL, rangerange = { 0, 0 };
74233 int nr_range;
74234
74235 nr_range = get_free_all_memory_range(&range, nodeid);
74236+ startrange = __pa(range) >> PAGE_SHIFT;
74237+ endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
74238
74239 for (i = 0; i < nr_range; i++) {
74240 start = range[i].start;
74241 end = range[i].end;
74242+ if (start <= endrange && startrange < end) {
74243+ BUG_ON(rangerange.start | rangerange.end);
74244+ rangerange = range[i];
74245+ continue;
74246+ }
74247 count += end - start;
74248 __free_pages_memory(start, end);
74249 }
74250+ start = rangerange.start;
74251+ end = rangerange.end;
74252+ count += end - start;
74253+ __free_pages_memory(start, end);
74254
74255 return count;
74256 }
74257diff -urNp linux-2.6.39.1/mm/nommu.c linux-2.6.39.1/mm/nommu.c
74258--- linux-2.6.39.1/mm/nommu.c 2011-05-19 00:06:34.000000000 -0400
74259+++ linux-2.6.39.1/mm/nommu.c 2011-05-22 19:36:33.000000000 -0400
74260@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
74261 int sysctl_overcommit_ratio = 50; /* default is 50% */
74262 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74263 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74264-int heap_stack_gap = 0;
74265
74266 atomic_long_t mmap_pages_allocated;
74267
74268@@ -833,15 +832,6 @@ struct vm_area_struct *find_vma(struct m
74269 EXPORT_SYMBOL(find_vma);
74270
74271 /*
74272- * find a VMA
74273- * - we don't extend stack VMAs under NOMMU conditions
74274- */
74275-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74276-{
74277- return find_vma(mm, addr);
74278-}
74279-
74280-/*
74281 * expand a stack to a given address
74282 * - not supported under NOMMU conditions
74283 */
74284@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, stru
74285
74286 /* most fields are the same, copy all, and then fixup */
74287 *new = *vma;
74288+ INIT_LIST_HEAD(&new->anon_vma_chain);
74289 *region = *vma->vm_region;
74290 new->vm_region = region;
74291
74292diff -urNp linux-2.6.39.1/mm/page_alloc.c linux-2.6.39.1/mm/page_alloc.c
74293--- linux-2.6.39.1/mm/page_alloc.c 2011-06-03 00:04:14.000000000 -0400
74294+++ linux-2.6.39.1/mm/page_alloc.c 2011-06-03 00:32:08.000000000 -0400
74295@@ -650,6 +650,10 @@ static bool free_pages_prepare(struct pa
74296 int i;
74297 int bad = 0;
74298
74299+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74300+ unsigned long index = 1UL << order;
74301+#endif
74302+
74303 trace_mm_page_free_direct(page, order);
74304 kmemcheck_free_shadow(page, order);
74305
74306@@ -665,6 +669,12 @@ static bool free_pages_prepare(struct pa
74307 debug_check_no_obj_freed(page_address(page),
74308 PAGE_SIZE << order);
74309 }
74310+
74311+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74312+ for (; index; --index)
74313+ sanitize_highpage(page + index - 1);
74314+#endif
74315+
74316 arch_free_page(page, order);
74317 kernel_map_pages(page, 1 << order, 0);
74318
74319@@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
74320 arch_alloc_page(page, order);
74321 kernel_map_pages(page, 1 << order, 1);
74322
74323+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74324 if (gfp_flags & __GFP_ZERO)
74325 prep_zero_page(page, order, gfp_flags);
74326+#endif
74327
74328 if (order && (gfp_flags & __GFP_COMP))
74329 prep_compound_page(page, order);
74330@@ -2504,6 +2516,8 @@ void __show_free_areas(unsigned int filt
74331 int cpu;
74332 struct zone *zone;
74333
74334+ pax_track_stack();
74335+
74336 for_each_populated_zone(zone) {
74337 if (skip_free_areas_zone(filter, zone))
74338 continue;
74339diff -urNp linux-2.6.39.1/mm/percpu.c linux-2.6.39.1/mm/percpu.c
74340--- linux-2.6.39.1/mm/percpu.c 2011-05-19 00:06:34.000000000 -0400
74341+++ linux-2.6.39.1/mm/percpu.c 2011-05-22 19:36:33.000000000 -0400
74342@@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
74343 static unsigned int pcpu_last_unit_cpu __read_mostly;
74344
74345 /* the address of the first chunk which starts with the kernel static area */
74346-void *pcpu_base_addr __read_mostly;
74347+void *pcpu_base_addr __read_only;
74348 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74349
74350 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74351diff -urNp linux-2.6.39.1/mm/rmap.c linux-2.6.39.1/mm/rmap.c
74352--- linux-2.6.39.1/mm/rmap.c 2011-05-19 00:06:34.000000000 -0400
74353+++ linux-2.6.39.1/mm/rmap.c 2011-05-22 19:36:33.000000000 -0400
74354@@ -131,6 +131,10 @@ int anon_vma_prepare(struct vm_area_stru
74355 struct anon_vma *anon_vma = vma->anon_vma;
74356 struct anon_vma_chain *avc;
74357
74358+#ifdef CONFIG_PAX_SEGMEXEC
74359+ struct anon_vma_chain *avc_m = NULL;
74360+#endif
74361+
74362 might_sleep();
74363 if (unlikely(!anon_vma)) {
74364 struct mm_struct *mm = vma->vm_mm;
74365@@ -140,6 +144,12 @@ int anon_vma_prepare(struct vm_area_stru
74366 if (!avc)
74367 goto out_enomem;
74368
74369+#ifdef CONFIG_PAX_SEGMEXEC
74370+ avc_m = anon_vma_chain_alloc();
74371+ if (!avc_m)
74372+ goto out_enomem_free_avc;
74373+#endif
74374+
74375 anon_vma = find_mergeable_anon_vma(vma);
74376 allocated = NULL;
74377 if (!anon_vma) {
74378@@ -153,6 +163,21 @@ int anon_vma_prepare(struct vm_area_stru
74379 /* page_table_lock to protect against threads */
74380 spin_lock(&mm->page_table_lock);
74381 if (likely(!vma->anon_vma)) {
74382+
74383+#ifdef CONFIG_PAX_SEGMEXEC
74384+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74385+
74386+ if (vma_m) {
74387+ BUG_ON(vma_m->anon_vma);
74388+ vma_m->anon_vma = anon_vma;
74389+ avc_m->anon_vma = anon_vma;
74390+ avc_m->vma = vma;
74391+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
74392+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
74393+ avc_m = NULL;
74394+ }
74395+#endif
74396+
74397 vma->anon_vma = anon_vma;
74398 avc->anon_vma = anon_vma;
74399 avc->vma = vma;
74400@@ -166,12 +191,24 @@ int anon_vma_prepare(struct vm_area_stru
74401
74402 if (unlikely(allocated))
74403 put_anon_vma(allocated);
74404+
74405+#ifdef CONFIG_PAX_SEGMEXEC
74406+ if (unlikely(avc_m))
74407+ anon_vma_chain_free(avc_m);
74408+#endif
74409+
74410 if (unlikely(avc))
74411 anon_vma_chain_free(avc);
74412 }
74413 return 0;
74414
74415 out_enomem_free_avc:
74416+
74417+#ifdef CONFIG_PAX_SEGMEXEC
74418+ if (avc_m)
74419+ anon_vma_chain_free(avc_m);
74420+#endif
74421+
74422 anon_vma_chain_free(avc);
74423 out_enomem:
74424 return -ENOMEM;
74425@@ -198,7 +235,7 @@ static void anon_vma_chain_link(struct v
74426 * Attach the anon_vmas from src to dst.
74427 * Returns 0 on success, -ENOMEM on failure.
74428 */
74429-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74430+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74431 {
74432 struct anon_vma_chain *avc, *pavc;
74433
74434@@ -220,7 +257,7 @@ int anon_vma_clone(struct vm_area_struct
74435 * the corresponding VMA in the parent process is attached to.
74436 * Returns 0 on success, non-zero on failure.
74437 */
74438-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74439+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74440 {
74441 struct anon_vma_chain *avc;
74442 struct anon_vma *anon_vma;
74443diff -urNp linux-2.6.39.1/mm/shmem.c linux-2.6.39.1/mm/shmem.c
74444--- linux-2.6.39.1/mm/shmem.c 2011-06-03 00:04:14.000000000 -0400
74445+++ linux-2.6.39.1/mm/shmem.c 2011-06-03 00:32:08.000000000 -0400
74446@@ -31,7 +31,7 @@
74447 #include <linux/percpu_counter.h>
74448 #include <linux/swap.h>
74449
74450-static struct vfsmount *shm_mnt;
74451+struct vfsmount *shm_mnt;
74452
74453 #ifdef CONFIG_SHMEM
74454 /*
74455@@ -1087,6 +1087,8 @@ static int shmem_writepage(struct page *
74456 goto unlock;
74457 }
74458 entry = shmem_swp_entry(info, index, NULL);
74459+ if (!entry)
74460+ goto unlock;
74461 if (entry->val) {
74462 /*
74463 * The more uptodate page coming down from a stacked
74464@@ -1158,6 +1160,8 @@ static struct page *shmem_swapin(swp_ent
74465 struct vm_area_struct pvma;
74466 struct page *page;
74467
74468+ pax_track_stack();
74469+
74470 spol = mpol_cond_copy(&mpol,
74471 mpol_shared_policy_lookup(&info->policy, idx));
74472
74473@@ -2014,7 +2018,7 @@ static int shmem_symlink(struct inode *d
74474
74475 info = SHMEM_I(inode);
74476 inode->i_size = len-1;
74477- if (len <= (char *)inode - (char *)info) {
74478+ if (len <= (char *)inode - (char *)info && len <= 64) {
74479 /* do it inline */
74480 memcpy(info, symname, len);
74481 inode->i_op = &shmem_symlink_inline_operations;
74482@@ -2362,8 +2366,7 @@ int shmem_fill_super(struct super_block
74483 int err = -ENOMEM;
74484
74485 /* Round up to L1_CACHE_BYTES to resist false sharing */
74486- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74487- L1_CACHE_BYTES), GFP_KERNEL);
74488+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74489 if (!sbinfo)
74490 return -ENOMEM;
74491
74492diff -urNp linux-2.6.39.1/mm/slab.c linux-2.6.39.1/mm/slab.c
74493--- linux-2.6.39.1/mm/slab.c 2011-05-19 00:06:34.000000000 -0400
74494+++ linux-2.6.39.1/mm/slab.c 2011-05-22 19:41:42.000000000 -0400
74495@@ -150,7 +150,7 @@
74496
74497 /* Legal flag mask for kmem_cache_create(). */
74498 #if DEBUG
74499-# define CREATE_MASK (SLAB_RED_ZONE | \
74500+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74501 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74502 SLAB_CACHE_DMA | \
74503 SLAB_STORE_USER | \
74504@@ -158,7 +158,7 @@
74505 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74506 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74507 #else
74508-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74509+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74510 SLAB_CACHE_DMA | \
74511 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74512 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74513@@ -287,7 +287,7 @@ struct kmem_list3 {
74514 * Need this for bootstrapping a per node allocator.
74515 */
74516 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74517-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74518+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74519 #define CACHE_CACHE 0
74520 #define SIZE_AC MAX_NUMNODES
74521 #define SIZE_L3 (2 * MAX_NUMNODES)
74522@@ -388,10 +388,10 @@ static void kmem_list3_init(struct kmem_
74523 if ((x)->max_freeable < i) \
74524 (x)->max_freeable = i; \
74525 } while (0)
74526-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74527-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74528-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74529-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74530+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74531+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74532+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74533+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74534 #else
74535 #define STATS_INC_ACTIVE(x) do { } while (0)
74536 #define STATS_DEC_ACTIVE(x) do { } while (0)
74537@@ -537,7 +537,7 @@ static inline void *index_to_obj(struct
74538 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74539 */
74540 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74541- const struct slab *slab, void *obj)
74542+ const struct slab *slab, const void *obj)
74543 {
74544 u32 offset = (obj - slab->s_mem);
74545 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74546@@ -563,7 +563,7 @@ struct cache_names {
74547 static struct cache_names __initdata cache_names[] = {
74548 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74549 #include <linux/kmalloc_sizes.h>
74550- {NULL,}
74551+ {NULL}
74552 #undef CACHE
74553 };
74554
74555@@ -1529,7 +1529,7 @@ void __init kmem_cache_init(void)
74556 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74557 sizes[INDEX_AC].cs_size,
74558 ARCH_KMALLOC_MINALIGN,
74559- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74560+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74561 NULL);
74562
74563 if (INDEX_AC != INDEX_L3) {
74564@@ -1537,7 +1537,7 @@ void __init kmem_cache_init(void)
74565 kmem_cache_create(names[INDEX_L3].name,
74566 sizes[INDEX_L3].cs_size,
74567 ARCH_KMALLOC_MINALIGN,
74568- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74569+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74570 NULL);
74571 }
74572
74573@@ -1555,7 +1555,7 @@ void __init kmem_cache_init(void)
74574 sizes->cs_cachep = kmem_cache_create(names->name,
74575 sizes->cs_size,
74576 ARCH_KMALLOC_MINALIGN,
74577- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74578+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74579 NULL);
74580 }
74581 #ifdef CONFIG_ZONE_DMA
74582@@ -4270,10 +4270,10 @@ static int s_show(struct seq_file *m, vo
74583 }
74584 /* cpu stats */
74585 {
74586- unsigned long allochit = atomic_read(&cachep->allochit);
74587- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74588- unsigned long freehit = atomic_read(&cachep->freehit);
74589- unsigned long freemiss = atomic_read(&cachep->freemiss);
74590+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74591+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74592+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74593+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74594
74595 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74596 allochit, allocmiss, freehit, freemiss);
74597@@ -4530,15 +4530,66 @@ static const struct file_operations proc
74598
74599 static int __init slab_proc_init(void)
74600 {
74601- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
74602+ mode_t gr_mode = S_IRUGO;
74603+
74604+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74605+ gr_mode = S_IRUSR;
74606+#endif
74607+
74608+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
74609 #ifdef CONFIG_DEBUG_SLAB_LEAK
74610- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74611+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
74612 #endif
74613 return 0;
74614 }
74615 module_init(slab_proc_init);
74616 #endif
74617
74618+void check_object_size(const void *ptr, unsigned long n, bool to)
74619+{
74620+
74621+#ifdef CONFIG_PAX_USERCOPY
74622+ struct page *page;
74623+ struct kmem_cache *cachep = NULL;
74624+ struct slab *slabp;
74625+ unsigned int objnr;
74626+ unsigned long offset;
74627+
74628+ if (!n)
74629+ return;
74630+
74631+ if (ZERO_OR_NULL_PTR(ptr))
74632+ goto report;
74633+
74634+ if (!virt_addr_valid(ptr))
74635+ return;
74636+
74637+ page = virt_to_head_page(ptr);
74638+
74639+ if (!PageSlab(page)) {
74640+ if (object_is_on_stack(ptr, n) == -1)
74641+ goto report;
74642+ return;
74643+ }
74644+
74645+ cachep = page_get_cache(page);
74646+ if (!(cachep->flags & SLAB_USERCOPY))
74647+ goto report;
74648+
74649+ slabp = page_get_slab(page);
74650+ objnr = obj_to_index(cachep, slabp, ptr);
74651+ BUG_ON(objnr >= cachep->num);
74652+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74653+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74654+ return;
74655+
74656+report:
74657+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
74658+#endif
74659+
74660+}
74661+EXPORT_SYMBOL(check_object_size);
74662+
74663 /**
74664 * ksize - get the actual amount of memory allocated for a given object
74665 * @objp: Pointer to the object
74666diff -urNp linux-2.6.39.1/mm/slob.c linux-2.6.39.1/mm/slob.c
74667--- linux-2.6.39.1/mm/slob.c 2011-05-19 00:06:34.000000000 -0400
74668+++ linux-2.6.39.1/mm/slob.c 2011-05-22 19:36:33.000000000 -0400
74669@@ -29,7 +29,7 @@
74670 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74671 * alloc_pages() directly, allocating compound pages so the page order
74672 * does not have to be separately tracked, and also stores the exact
74673- * allocation size in page->private so that it can be used to accurately
74674+ * allocation size in slob_page->size so that it can be used to accurately
74675 * provide ksize(). These objects are detected in kfree() because slob_page()
74676 * is false for them.
74677 *
74678@@ -58,6 +58,7 @@
74679 */
74680
74681 #include <linux/kernel.h>
74682+#include <linux/sched.h>
74683 #include <linux/slab.h>
74684 #include <linux/mm.h>
74685 #include <linux/swap.h> /* struct reclaim_state */
74686@@ -102,7 +103,8 @@ struct slob_page {
74687 unsigned long flags; /* mandatory */
74688 atomic_t _count; /* mandatory */
74689 slobidx_t units; /* free units left in page */
74690- unsigned long pad[2];
74691+ unsigned long pad[1];
74692+ unsigned long size; /* size when >=PAGE_SIZE */
74693 slob_t *free; /* first free slob_t in page */
74694 struct list_head list; /* linked list of free pages */
74695 };
74696@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74697 */
74698 static inline int is_slob_page(struct slob_page *sp)
74699 {
74700- return PageSlab((struct page *)sp);
74701+ return PageSlab((struct page *)sp) && !sp->size;
74702 }
74703
74704 static inline void set_slob_page(struct slob_page *sp)
74705@@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
74706
74707 static inline struct slob_page *slob_page(const void *addr)
74708 {
74709- return (struct slob_page *)virt_to_page(addr);
74710+ return (struct slob_page *)virt_to_head_page(addr);
74711 }
74712
74713 /*
74714@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
74715 /*
74716 * Return the size of a slob block.
74717 */
74718-static slobidx_t slob_units(slob_t *s)
74719+static slobidx_t slob_units(const slob_t *s)
74720 {
74721 if (s->units > 0)
74722 return s->units;
74723@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74724 /*
74725 * Return the next free slob block pointer after this one.
74726 */
74727-static slob_t *slob_next(slob_t *s)
74728+static slob_t *slob_next(const slob_t *s)
74729 {
74730 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74731 slobidx_t next;
74732@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74733 /*
74734 * Returns true if s is the last free block in its page.
74735 */
74736-static int slob_last(slob_t *s)
74737+static int slob_last(const slob_t *s)
74738 {
74739 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74740 }
74741@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
74742 if (!page)
74743 return NULL;
74744
74745+ set_slob_page(page);
74746 return page_address(page);
74747 }
74748
74749@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
74750 if (!b)
74751 return NULL;
74752 sp = slob_page(b);
74753- set_slob_page(sp);
74754
74755 spin_lock_irqsave(&slob_lock, flags);
74756 sp->units = SLOB_UNITS(PAGE_SIZE);
74757 sp->free = b;
74758+ sp->size = 0;
74759 INIT_LIST_HEAD(&sp->list);
74760 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74761 set_slob_page_free(sp, slob_list);
74762@@ -476,10 +479,9 @@ out:
74763 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74764 */
74765
74766-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74767+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74768 {
74769- unsigned int *m;
74770- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74771+ slob_t *m;
74772 void *ret;
74773
74774 lockdep_trace_alloc(gfp);
74775@@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
74776
74777 if (!m)
74778 return NULL;
74779- *m = size;
74780+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74781+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74782+ m[0].units = size;
74783+ m[1].units = align;
74784 ret = (void *)m + align;
74785
74786 trace_kmalloc_node(_RET_IP_, ret,
74787@@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
74788 gfp |= __GFP_COMP;
74789 ret = slob_new_pages(gfp, order, node);
74790 if (ret) {
74791- struct page *page;
74792- page = virt_to_page(ret);
74793- page->private = size;
74794+ struct slob_page *sp;
74795+ sp = slob_page(ret);
74796+ sp->size = size;
74797 }
74798
74799 trace_kmalloc_node(_RET_IP_, ret,
74800@@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
74801 kmemleak_alloc(ret, size, 1, gfp);
74802 return ret;
74803 }
74804+
74805+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74806+{
74807+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74808+
74809+ return __kmalloc_node_align(size, gfp, node, align);
74810+}
74811 EXPORT_SYMBOL(__kmalloc_node);
74812
74813 void kfree(const void *block)
74814@@ -531,13 +543,81 @@ void kfree(const void *block)
74815 sp = slob_page(block);
74816 if (is_slob_page(sp)) {
74817 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74818- unsigned int *m = (unsigned int *)(block - align);
74819- slob_free(m, *m + align);
74820- } else
74821+ slob_t *m = (slob_t *)(block - align);
74822+ slob_free(m, m[0].units + align);
74823+ } else {
74824+ clear_slob_page(sp);
74825+ free_slob_page(sp);
74826+ sp->size = 0;
74827 put_page(&sp->page);
74828+ }
74829 }
74830 EXPORT_SYMBOL(kfree);
74831
74832+void check_object_size(const void *ptr, unsigned long n, bool to)
74833+{
74834+
74835+#ifdef CONFIG_PAX_USERCOPY
74836+ struct slob_page *sp;
74837+ const slob_t *free;
74838+ const void *base;
74839+
74840+ if (!n)
74841+ return;
74842+
74843+ if (ZERO_OR_NULL_PTR(ptr))
74844+ goto report;
74845+
74846+ if (!virt_addr_valid(ptr))
74847+ return;
74848+
74849+ sp = slob_page(ptr);
74850+ if (!PageSlab((struct page*)sp)) {
74851+ if (object_is_on_stack(ptr, n) == -1)
74852+ goto report;
74853+ return;
74854+ }
74855+
74856+ if (sp->size) {
74857+ base = page_address(&sp->page);
74858+ if (base <= ptr && n <= sp->size - (ptr - base))
74859+ return;
74860+ goto report;
74861+ }
74862+
74863+ /* some tricky double walking to find the chunk */
74864+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74865+ free = sp->free;
74866+
74867+ while (!slob_last(free) && (void *)free <= ptr) {
74868+ base = free + slob_units(free);
74869+ free = slob_next(free);
74870+ }
74871+
74872+ while (base < (void *)free) {
74873+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74874+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74875+ int offset;
74876+
74877+ if (ptr < base + align)
74878+ goto report;
74879+
74880+ offset = ptr - base - align;
74881+ if (offset < m) {
74882+ if (n <= m - offset)
74883+ return;
74884+ goto report;
74885+ }
74886+ base += size;
74887+ }
74888+
74889+report:
74890+ pax_report_usercopy(ptr, n, to, NULL);
74891+#endif
74892+
74893+}
74894+EXPORT_SYMBOL(check_object_size);
74895+
74896 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74897 size_t ksize(const void *block)
74898 {
74899@@ -550,10 +630,10 @@ size_t ksize(const void *block)
74900 sp = slob_page(block);
74901 if (is_slob_page(sp)) {
74902 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74903- unsigned int *m = (unsigned int *)(block - align);
74904- return SLOB_UNITS(*m) * SLOB_UNIT;
74905+ slob_t *m = (slob_t *)(block - align);
74906+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74907 } else
74908- return sp->page.private;
74909+ return sp->size;
74910 }
74911 EXPORT_SYMBOL(ksize);
74912
74913@@ -608,17 +688,25 @@ void *kmem_cache_alloc_node(struct kmem_
74914 {
74915 void *b;
74916
74917+#ifdef CONFIG_PAX_USERCOPY
74918+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74919+#else
74920 if (c->size < PAGE_SIZE) {
74921 b = slob_alloc(c->size, flags, c->align, node);
74922 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74923 SLOB_UNITS(c->size) * SLOB_UNIT,
74924 flags, node);
74925 } else {
74926+ struct slob_page *sp;
74927+
74928 b = slob_new_pages(flags, get_order(c->size), node);
74929+ sp = slob_page(b);
74930+ sp->size = c->size;
74931 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74932 PAGE_SIZE << get_order(c->size),
74933 flags, node);
74934 }
74935+#endif
74936
74937 if (c->ctor)
74938 c->ctor(b);
74939@@ -630,10 +718,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74940
74941 static void __kmem_cache_free(void *b, int size)
74942 {
74943- if (size < PAGE_SIZE)
74944+ struct slob_page *sp = slob_page(b);
74945+
74946+ if (is_slob_page(sp))
74947 slob_free(b, size);
74948- else
74949+ else {
74950+ clear_slob_page(sp);
74951+ free_slob_page(sp);
74952+ sp->size = 0;
74953 slob_free_pages(b, get_order(size));
74954+ }
74955 }
74956
74957 static void kmem_rcu_free(struct rcu_head *head)
74958@@ -646,14 +740,23 @@ static void kmem_rcu_free(struct rcu_hea
74959
74960 void kmem_cache_free(struct kmem_cache *c, void *b)
74961 {
74962+ int size = c->size;
74963+
74964+#ifdef CONFIG_PAX_USERCOPY
74965+ if (size + c->align < PAGE_SIZE) {
74966+ size += c->align;
74967+ b -= c->align;
74968+ }
74969+#endif
74970+
74971 kmemleak_free_recursive(b, c->flags);
74972 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74973 struct slob_rcu *slob_rcu;
74974- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74975- slob_rcu->size = c->size;
74976+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74977+ slob_rcu->size = size;
74978 call_rcu(&slob_rcu->head, kmem_rcu_free);
74979 } else {
74980- __kmem_cache_free(b, c->size);
74981+ __kmem_cache_free(b, size);
74982 }
74983
74984 trace_kmem_cache_free(_RET_IP_, b);
74985diff -urNp linux-2.6.39.1/mm/slub.c linux-2.6.39.1/mm/slub.c
74986--- linux-2.6.39.1/mm/slub.c 2011-06-03 00:04:14.000000000 -0400
74987+++ linux-2.6.39.1/mm/slub.c 2011-06-03 00:32:08.000000000 -0400
74988@@ -431,7 +431,7 @@ static void print_track(const char *s, s
74989 if (!t->addr)
74990 return;
74991
74992- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74993+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74994 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74995 }
74996
74997@@ -2183,6 +2183,8 @@ void kmem_cache_free(struct kmem_cache *
74998
74999 page = virt_to_head_page(x);
75000
75001+ BUG_ON(!PageSlab(page));
75002+
75003 slab_free(s, page, x, _RET_IP_);
75004
75005 trace_kmem_cache_free(_RET_IP_, x);
75006@@ -2216,7 +2218,7 @@ static int slub_min_objects;
75007 * Merge control. If this is set then no merging of slab caches will occur.
75008 * (Could be removed. This was introduced to pacify the merge skeptics.)
75009 */
75010-static int slub_nomerge;
75011+static int slub_nomerge = 1;
75012
75013 /*
75014 * Calculate the order of allocation given an slab object size.
75015@@ -2644,7 +2646,7 @@ static int kmem_cache_open(struct kmem_c
75016 * list to avoid pounding the page allocator excessively.
75017 */
75018 set_min_partial(s, ilog2(s->size));
75019- s->refcount = 1;
75020+ atomic_set(&s->refcount, 1);
75021 #ifdef CONFIG_NUMA
75022 s->remote_node_defrag_ratio = 1000;
75023 #endif
75024@@ -2750,8 +2752,7 @@ static inline int kmem_cache_close(struc
75025 void kmem_cache_destroy(struct kmem_cache *s)
75026 {
75027 down_write(&slub_lock);
75028- s->refcount--;
75029- if (!s->refcount) {
75030+ if (atomic_dec_and_test(&s->refcount)) {
75031 list_del(&s->list);
75032 if (kmem_cache_close(s)) {
75033 printk(KERN_ERR "SLUB %s: %s called for cache that "
75034@@ -2961,6 +2962,46 @@ void *__kmalloc_node(size_t size, gfp_t
75035 EXPORT_SYMBOL(__kmalloc_node);
75036 #endif
75037
75038+void check_object_size(const void *ptr, unsigned long n, bool to)
75039+{
75040+
75041+#ifdef CONFIG_PAX_USERCOPY
75042+ struct page *page;
75043+ struct kmem_cache *s = NULL;
75044+ unsigned long offset;
75045+
75046+ if (!n)
75047+ return;
75048+
75049+ if (ZERO_OR_NULL_PTR(ptr))
75050+ goto report;
75051+
75052+ if (!virt_addr_valid(ptr))
75053+ return;
75054+
75055+ page = virt_to_head_page(ptr);
75056+
75057+ if (!PageSlab(page)) {
75058+ if (object_is_on_stack(ptr, n) == -1)
75059+ goto report;
75060+ return;
75061+ }
75062+
75063+ s = page->slab;
75064+ if (!(s->flags & SLAB_USERCOPY))
75065+ goto report;
75066+
75067+ offset = (ptr - page_address(page)) % s->size;
75068+ if (offset <= s->objsize && n <= s->objsize - offset)
75069+ return;
75070+
75071+report:
75072+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
75073+#endif
75074+
75075+}
75076+EXPORT_SYMBOL(check_object_size);
75077+
75078 size_t ksize(const void *object)
75079 {
75080 struct page *page;
75081@@ -3205,7 +3246,7 @@ static void __init kmem_cache_bootstrap_
75082 int node;
75083
75084 list_add(&s->list, &slab_caches);
75085- s->refcount = -1;
75086+ atomic_set(&s->refcount, -1);
75087
75088 for_each_node_state(node, N_NORMAL_MEMORY) {
75089 struct kmem_cache_node *n = get_node(s, node);
75090@@ -3322,17 +3363,17 @@ void __init kmem_cache_init(void)
75091
75092 /* Caches that are not of the two-to-the-power-of size */
75093 if (KMALLOC_MIN_SIZE <= 32) {
75094- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75095+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75096 caches++;
75097 }
75098
75099 if (KMALLOC_MIN_SIZE <= 64) {
75100- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75101+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75102 caches++;
75103 }
75104
75105 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75106- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75107+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75108 caches++;
75109 }
75110
75111@@ -3400,7 +3441,7 @@ static int slab_unmergeable(struct kmem_
75112 /*
75113 * We may have set a slab to be unmergeable during bootstrap.
75114 */
75115- if (s->refcount < 0)
75116+ if (atomic_read(&s->refcount) < 0)
75117 return 1;
75118
75119 return 0;
75120@@ -3459,7 +3500,7 @@ struct kmem_cache *kmem_cache_create(con
75121 down_write(&slub_lock);
75122 s = find_mergeable(size, align, flags, name, ctor);
75123 if (s) {
75124- s->refcount++;
75125+ atomic_inc(&s->refcount);
75126 /*
75127 * Adjust the object sizes so that we clear
75128 * the complete object on kzalloc.
75129@@ -3468,7 +3509,7 @@ struct kmem_cache *kmem_cache_create(con
75130 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75131
75132 if (sysfs_slab_alias(s, name)) {
75133- s->refcount--;
75134+ atomic_dec(&s->refcount);
75135 goto err;
75136 }
75137 up_write(&slub_lock);
75138@@ -4201,7 +4242,7 @@ SLAB_ATTR_RO(ctor);
75139
75140 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75141 {
75142- return sprintf(buf, "%d\n", s->refcount - 1);
75143+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75144 }
75145 SLAB_ATTR_RO(aliases);
75146
75147@@ -4945,7 +4986,13 @@ static const struct file_operations proc
75148
75149 static int __init slab_proc_init(void)
75150 {
75151- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
75152+ mode_t gr_mode = S_IRUGO;
75153+
75154+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75155+ gr_mode = S_IRUSR;
75156+#endif
75157+
75158+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
75159 return 0;
75160 }
75161 module_init(slab_proc_init);
75162diff -urNp linux-2.6.39.1/mm/swapfile.c linux-2.6.39.1/mm/swapfile.c
75163--- linux-2.6.39.1/mm/swapfile.c 2011-05-19 00:06:34.000000000 -0400
75164+++ linux-2.6.39.1/mm/swapfile.c 2011-05-22 19:36:33.000000000 -0400
75165@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
75166
75167 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75168 /* Activity counter to indicate that a swapon or swapoff has occurred */
75169-static atomic_t proc_poll_event = ATOMIC_INIT(0);
75170+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75171
75172 static inline unsigned char swap_count(unsigned char ent)
75173 {
75174@@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
75175 }
75176 filp_close(swap_file, NULL);
75177 err = 0;
75178- atomic_inc(&proc_poll_event);
75179+ atomic_inc_unchecked(&proc_poll_event);
75180 wake_up_interruptible(&proc_poll_wait);
75181
75182 out_dput:
75183@@ -1690,8 +1690,8 @@ static unsigned swaps_poll(struct file *
75184
75185 poll_wait(file, &proc_poll_wait, wait);
75186
75187- if (s->event != atomic_read(&proc_poll_event)) {
75188- s->event = atomic_read(&proc_poll_event);
75189+ if (s->event != atomic_read_unchecked(&proc_poll_event)) {
75190+ s->event = atomic_read_unchecked(&proc_poll_event);
75191 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75192 }
75193
75194@@ -1797,7 +1797,7 @@ static int swaps_open(struct inode *inod
75195 }
75196
75197 s->seq.private = s;
75198- s->event = atomic_read(&proc_poll_event);
75199+ s->event = atomic_read_unchecked(&proc_poll_event);
75200 return ret;
75201 }
75202
75203@@ -2131,7 +2131,7 @@ SYSCALL_DEFINE2(swapon, const char __use
75204 (p->flags & SWP_DISCARDABLE) ? "D" : "");
75205
75206 mutex_unlock(&swapon_mutex);
75207- atomic_inc(&proc_poll_event);
75208+ atomic_inc_unchecked(&proc_poll_event);
75209 wake_up_interruptible(&proc_poll_wait);
75210
75211 if (S_ISREG(inode->i_mode))
75212diff -urNp linux-2.6.39.1/mm/util.c linux-2.6.39.1/mm/util.c
75213--- linux-2.6.39.1/mm/util.c 2011-05-19 00:06:34.000000000 -0400
75214+++ linux-2.6.39.1/mm/util.c 2011-05-23 17:07:00.000000000 -0400
75215@@ -112,6 +112,7 @@ EXPORT_SYMBOL(memdup_user);
75216 * allocated buffer. Use this if you don't want to free the buffer immediately
75217 * like, for example, with RCU.
75218 */
75219+#undef __krealloc
75220 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
75221 {
75222 void *ret;
75223@@ -145,6 +146,7 @@ EXPORT_SYMBOL(__krealloc);
75224 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
75225 * %NULL pointer, the object pointed to is freed.
75226 */
75227+#undef krealloc
75228 void *krealloc(const void *p, size_t new_size, gfp_t flags)
75229 {
75230 void *ret;
75231@@ -219,6 +221,12 @@ EXPORT_SYMBOL(strndup_user);
75232 void arch_pick_mmap_layout(struct mm_struct *mm)
75233 {
75234 mm->mmap_base = TASK_UNMAPPED_BASE;
75235+
75236+#ifdef CONFIG_PAX_RANDMMAP
75237+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75238+ mm->mmap_base += mm->delta_mmap;
75239+#endif
75240+
75241 mm->get_unmapped_area = arch_get_unmapped_area;
75242 mm->unmap_area = arch_unmap_area;
75243 }
75244diff -urNp linux-2.6.39.1/mm/vmalloc.c linux-2.6.39.1/mm/vmalloc.c
75245--- linux-2.6.39.1/mm/vmalloc.c 2011-05-19 00:06:34.000000000 -0400
75246+++ linux-2.6.39.1/mm/vmalloc.c 2011-05-22 19:36:33.000000000 -0400
75247@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
75248
75249 pte = pte_offset_kernel(pmd, addr);
75250 do {
75251- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75252- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75253+
75254+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75255+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75256+ BUG_ON(!pte_exec(*pte));
75257+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75258+ continue;
75259+ }
75260+#endif
75261+
75262+ {
75263+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75264+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75265+ }
75266 } while (pte++, addr += PAGE_SIZE, addr != end);
75267 }
75268
75269@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
75270 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75271 {
75272 pte_t *pte;
75273+ int ret = -ENOMEM;
75274
75275 /*
75276 * nr is a running index into the array which helps higher level
75277@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
75278 pte = pte_alloc_kernel(pmd, addr);
75279 if (!pte)
75280 return -ENOMEM;
75281+
75282+ pax_open_kernel();
75283 do {
75284 struct page *page = pages[*nr];
75285
75286- if (WARN_ON(!pte_none(*pte)))
75287- return -EBUSY;
75288- if (WARN_ON(!page))
75289- return -ENOMEM;
75290+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75291+ if (pgprot_val(prot) & _PAGE_NX)
75292+#endif
75293+
75294+ if (WARN_ON(!pte_none(*pte))) {
75295+ ret = -EBUSY;
75296+ goto out;
75297+ }
75298+ if (WARN_ON(!page)) {
75299+ ret = -ENOMEM;
75300+ goto out;
75301+ }
75302 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75303 (*nr)++;
75304 } while (pte++, addr += PAGE_SIZE, addr != end);
75305- return 0;
75306+ ret = 0;
75307+out:
75308+ pax_close_kernel();
75309+ return ret;
75310 }
75311
75312 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75313@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
75314 * and fall back on vmalloc() if that fails. Others
75315 * just put it in the vmalloc space.
75316 */
75317-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75318+#ifdef CONFIG_MODULES
75319+#ifdef MODULES_VADDR
75320 unsigned long addr = (unsigned long)x;
75321 if (addr >= MODULES_VADDR && addr < MODULES_END)
75322 return 1;
75323 #endif
75324+
75325+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75326+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75327+ return 1;
75328+#endif
75329+
75330+#endif
75331+
75332 return is_vmalloc_addr(x);
75333 }
75334
75335@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
75336
75337 if (!pgd_none(*pgd)) {
75338 pud_t *pud = pud_offset(pgd, addr);
75339+#ifdef CONFIG_X86
75340+ if (!pud_large(*pud))
75341+#endif
75342 if (!pud_none(*pud)) {
75343 pmd_t *pmd = pmd_offset(pud, addr);
75344+#ifdef CONFIG_X86
75345+ if (!pmd_large(*pmd))
75346+#endif
75347 if (!pmd_none(*pmd)) {
75348 pte_t *ptep, pte;
75349
75350@@ -1296,6 +1336,16 @@ static struct vm_struct *__get_vm_area_n
75351 struct vm_struct *area;
75352
75353 BUG_ON(in_interrupt());
75354+
75355+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75356+ if (flags & VM_KERNEXEC) {
75357+ if (start != VMALLOC_START || end != VMALLOC_END)
75358+ return NULL;
75359+ start = (unsigned long)MODULES_EXEC_VADDR;
75360+ end = (unsigned long)MODULES_EXEC_END;
75361+ }
75362+#endif
75363+
75364 if (flags & VM_IOREMAP) {
75365 int bit = fls(size);
75366
75367@@ -1514,6 +1564,11 @@ void *vmap(struct page **pages, unsigned
75368 if (count > totalram_pages)
75369 return NULL;
75370
75371+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75372+ if (!(pgprot_val(prot) & _PAGE_NX))
75373+ flags |= VM_KERNEXEC;
75374+#endif
75375+
75376 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75377 __builtin_return_address(0));
75378 if (!area)
75379@@ -1610,6 +1665,13 @@ void *__vmalloc_node_range(unsigned long
75380 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75381 return NULL;
75382
75383+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75384+ if (!(pgprot_val(prot) & _PAGE_NX))
75385+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
75386+ node, gfp_mask, caller);
75387+ else
75388+#endif
75389+
75390 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
75391 gfp_mask, caller);
75392
75393@@ -1649,6 +1711,7 @@ static void *__vmalloc_node(unsigned lon
75394 gfp_mask, prot, node, caller);
75395 }
75396
75397+#undef __vmalloc
75398 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
75399 {
75400 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
75401@@ -1672,6 +1735,7 @@ static inline void *__vmalloc_node_flags
75402 * For tight control over page level allocator and protection flags
75403 * use __vmalloc() instead.
75404 */
75405+#undef vmalloc
75406 void *vmalloc(unsigned long size)
75407 {
75408 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
75409@@ -1688,6 +1752,7 @@ EXPORT_SYMBOL(vmalloc);
75410 * For tight control over page level allocator and protection flags
75411 * use __vmalloc() instead.
75412 */
75413+#undef vzalloc
75414 void *vzalloc(unsigned long size)
75415 {
75416 return __vmalloc_node_flags(size, -1,
75417@@ -1702,6 +1767,7 @@ EXPORT_SYMBOL(vzalloc);
75418 * The resulting memory area is zeroed so it can be mapped to userspace
75419 * without leaking data.
75420 */
75421+#undef vmalloc_user
75422 void *vmalloc_user(unsigned long size)
75423 {
75424 struct vm_struct *area;
75425@@ -1729,6 +1795,7 @@ EXPORT_SYMBOL(vmalloc_user);
75426 * For tight control over page level allocator and protection flags
75427 * use __vmalloc() instead.
75428 */
75429+#undef vmalloc_node
75430 void *vmalloc_node(unsigned long size, int node)
75431 {
75432 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75433@@ -1748,6 +1815,7 @@ EXPORT_SYMBOL(vmalloc_node);
75434 * For tight control over page level allocator and protection flags
75435 * use __vmalloc_node() instead.
75436 */
75437+#undef vzalloc_node
75438 void *vzalloc_node(unsigned long size, int node)
75439 {
75440 return __vmalloc_node_flags(size, node,
75441@@ -1770,10 +1838,10 @@ EXPORT_SYMBOL(vzalloc_node);
75442 * For tight control over page level allocator and protection flags
75443 * use __vmalloc() instead.
75444 */
75445-
75446+#undef vmalloc_exec
75447 void *vmalloc_exec(unsigned long size)
75448 {
75449- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75450+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75451 -1, __builtin_return_address(0));
75452 }
75453
75454@@ -1792,6 +1860,7 @@ void *vmalloc_exec(unsigned long size)
75455 * Allocate enough 32bit PA addressable pages to cover @size from the
75456 * page level allocator and map them into contiguous kernel virtual space.
75457 */
75458+#undef vmalloc_32
75459 void *vmalloc_32(unsigned long size)
75460 {
75461 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
75462@@ -1806,6 +1875,7 @@ EXPORT_SYMBOL(vmalloc_32);
75463 * The resulting memory area is 32bit addressable and zeroed so it can be
75464 * mapped to userspace without leaking data.
75465 */
75466+#undef vmalloc_32_user
75467 void *vmalloc_32_user(unsigned long size)
75468 {
75469 struct vm_struct *area;
75470@@ -2068,6 +2138,8 @@ int remap_vmalloc_range(struct vm_area_s
75471 unsigned long uaddr = vma->vm_start;
75472 unsigned long usize = vma->vm_end - vma->vm_start;
75473
75474+ BUG_ON(vma->vm_mirror);
75475+
75476 if ((PAGE_SIZE-1) & (unsigned long)addr)
75477 return -EINVAL;
75478
75479diff -urNp linux-2.6.39.1/mm/vmstat.c linux-2.6.39.1/mm/vmstat.c
75480--- linux-2.6.39.1/mm/vmstat.c 2011-05-19 00:06:34.000000000 -0400
75481+++ linux-2.6.39.1/mm/vmstat.c 2011-05-22 19:41:42.000000000 -0400
75482@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75483 *
75484 * vm_stat contains the global counters
75485 */
75486-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75487+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75488 EXPORT_SYMBOL(vm_stat);
75489
75490 #ifdef CONFIG_SMP
75491@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75492 v = p->vm_stat_diff[i];
75493 p->vm_stat_diff[i] = 0;
75494 local_irq_restore(flags);
75495- atomic_long_add(v, &zone->vm_stat[i]);
75496+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75497 global_diff[i] += v;
75498 #ifdef CONFIG_NUMA
75499 /* 3 seconds idle till flush */
75500@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75501
75502 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75503 if (global_diff[i])
75504- atomic_long_add(global_diff[i], &vm_stat[i]);
75505+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75506 }
75507
75508 #endif
75509@@ -1205,10 +1205,20 @@ static int __init setup_vmstat(void)
75510 start_cpu_timer(cpu);
75511 #endif
75512 #ifdef CONFIG_PROC_FS
75513- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75514- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75515- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75516- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75517+ {
75518+ mode_t gr_mode = S_IRUGO;
75519+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75520+ gr_mode = S_IRUSR;
75521+#endif
75522+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75523+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75524+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75525+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75526+#else
75527+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75528+#endif
75529+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75530+ }
75531 #endif
75532 return 0;
75533 }
75534diff -urNp linux-2.6.39.1/net/8021q/vlan.c linux-2.6.39.1/net/8021q/vlan.c
75535--- linux-2.6.39.1/net/8021q/vlan.c 2011-05-19 00:06:34.000000000 -0400
75536+++ linux-2.6.39.1/net/8021q/vlan.c 2011-05-22 19:36:33.000000000 -0400
75537@@ -592,8 +592,7 @@ static int vlan_ioctl_handler(struct net
75538 err = -EPERM;
75539 if (!capable(CAP_NET_ADMIN))
75540 break;
75541- if ((args.u.name_type >= 0) &&
75542- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75543+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75544 struct vlan_net *vn;
75545
75546 vn = net_generic(net, vlan_net_id);
75547diff -urNp linux-2.6.39.1/net/atm/atm_misc.c linux-2.6.39.1/net/atm/atm_misc.c
75548--- linux-2.6.39.1/net/atm/atm_misc.c 2011-05-19 00:06:34.000000000 -0400
75549+++ linux-2.6.39.1/net/atm/atm_misc.c 2011-05-22 19:36:33.000000000 -0400
75550@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
75551 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75552 return 1;
75553 atm_return(vcc, truesize);
75554- atomic_inc(&vcc->stats->rx_drop);
75555+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75556 return 0;
75557 }
75558 EXPORT_SYMBOL(atm_charge);
75559@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
75560 }
75561 }
75562 atm_return(vcc, guess);
75563- atomic_inc(&vcc->stats->rx_drop);
75564+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75565 return NULL;
75566 }
75567 EXPORT_SYMBOL(atm_alloc_charge);
75568@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75569
75570 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75571 {
75572-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75573+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75574 __SONET_ITEMS
75575 #undef __HANDLE_ITEM
75576 }
75577@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75578
75579 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75580 {
75581-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75582+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75583 __SONET_ITEMS
75584 #undef __HANDLE_ITEM
75585 }
75586diff -urNp linux-2.6.39.1/net/atm/mpoa_caches.c linux-2.6.39.1/net/atm/mpoa_caches.c
75587--- linux-2.6.39.1/net/atm/mpoa_caches.c 2011-05-19 00:06:34.000000000 -0400
75588+++ linux-2.6.39.1/net/atm/mpoa_caches.c 2011-05-22 19:36:33.000000000 -0400
75589@@ -255,6 +255,8 @@ static void check_resolving_entries(stru
75590 struct timeval now;
75591 struct k_message msg;
75592
75593+ pax_track_stack();
75594+
75595 do_gettimeofday(&now);
75596
75597 read_lock_bh(&client->ingress_lock);
75598diff -urNp linux-2.6.39.1/net/atm/proc.c linux-2.6.39.1/net/atm/proc.c
75599--- linux-2.6.39.1/net/atm/proc.c 2011-05-19 00:06:34.000000000 -0400
75600+++ linux-2.6.39.1/net/atm/proc.c 2011-05-22 19:41:42.000000000 -0400
75601@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
75602 const struct k_atm_aal_stats *stats)
75603 {
75604 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75605- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75606- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75607- atomic_read(&stats->rx_drop));
75608+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75609+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75610+ atomic_read_unchecked(&stats->rx_drop));
75611 }
75612
75613 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75614@@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
75615 {
75616 struct sock *sk = sk_atm(vcc);
75617
75618+#ifdef CONFIG_GRKERNSEC_HIDESYM
75619+ seq_printf(seq, "%p ", NULL);
75620+#else
75621 seq_printf(seq, "%p ", vcc);
75622+#endif
75623+
75624 if (!vcc->dev)
75625 seq_printf(seq, "Unassigned ");
75626 else
75627@@ -218,7 +223,11 @@ static void svc_info(struct seq_file *se
75628 {
75629 if (!vcc->dev)
75630 seq_printf(seq, sizeof(void *) == 4 ?
75631+#ifdef CONFIG_GRKERNSEC_HIDESYM
75632+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
75633+#else
75634 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
75635+#endif
75636 else
75637 seq_printf(seq, "%3d %3d %5d ",
75638 vcc->dev->number, vcc->vpi, vcc->vci);
75639diff -urNp linux-2.6.39.1/net/atm/resources.c linux-2.6.39.1/net/atm/resources.c
75640--- linux-2.6.39.1/net/atm/resources.c 2011-05-19 00:06:34.000000000 -0400
75641+++ linux-2.6.39.1/net/atm/resources.c 2011-05-22 19:36:33.000000000 -0400
75642@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75643 static void copy_aal_stats(struct k_atm_aal_stats *from,
75644 struct atm_aal_stats *to)
75645 {
75646-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75647+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75648 __AAL_STAT_ITEMS
75649 #undef __HANDLE_ITEM
75650 }
75651@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
75652 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75653 struct atm_aal_stats *to)
75654 {
75655-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75656+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75657 __AAL_STAT_ITEMS
75658 #undef __HANDLE_ITEM
75659 }
75660diff -urNp linux-2.6.39.1/net/batman-adv/hard-interface.c linux-2.6.39.1/net/batman-adv/hard-interface.c
75661--- linux-2.6.39.1/net/batman-adv/hard-interface.c 2011-05-19 00:06:34.000000000 -0400
75662+++ linux-2.6.39.1/net/batman-adv/hard-interface.c 2011-05-22 19:36:33.000000000 -0400
75663@@ -339,8 +339,8 @@ int hardif_enable_interface(struct hard_
75664 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75665 dev_add_pack(&hard_iface->batman_adv_ptype);
75666
75667- atomic_set(&hard_iface->seqno, 1);
75668- atomic_set(&hard_iface->frag_seqno, 1);
75669+ atomic_set_unchecked(&hard_iface->seqno, 1);
75670+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75671 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75672 hard_iface->net_dev->name);
75673
75674diff -urNp linux-2.6.39.1/net/batman-adv/routing.c linux-2.6.39.1/net/batman-adv/routing.c
75675--- linux-2.6.39.1/net/batman-adv/routing.c 2011-05-19 00:06:34.000000000 -0400
75676+++ linux-2.6.39.1/net/batman-adv/routing.c 2011-05-22 19:36:33.000000000 -0400
75677@@ -625,7 +625,7 @@ void receive_bat_packet(struct ethhdr *e
75678 return;
75679
75680 /* could be changed by schedule_own_packet() */
75681- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75682+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75683
75684 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
75685
75686diff -urNp linux-2.6.39.1/net/batman-adv/send.c linux-2.6.39.1/net/batman-adv/send.c
75687--- linux-2.6.39.1/net/batman-adv/send.c 2011-05-19 00:06:34.000000000 -0400
75688+++ linux-2.6.39.1/net/batman-adv/send.c 2011-05-22 19:36:33.000000000 -0400
75689@@ -277,7 +277,7 @@ void schedule_own_packet(struct hard_ifa
75690
75691 /* change sequence number to network order */
75692 batman_packet->seqno =
75693- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75694+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75695
75696 if (vis_server == VIS_TYPE_SERVER_SYNC)
75697 batman_packet->flags |= VIS_SERVER;
75698@@ -291,7 +291,7 @@ void schedule_own_packet(struct hard_ifa
75699 else
75700 batman_packet->gw_flags = 0;
75701
75702- atomic_inc(&hard_iface->seqno);
75703+ atomic_inc_unchecked(&hard_iface->seqno);
75704
75705 slide_own_bcast_window(hard_iface);
75706 send_time = own_send_time(bat_priv);
75707diff -urNp linux-2.6.39.1/net/batman-adv/soft-interface.c linux-2.6.39.1/net/batman-adv/soft-interface.c
75708--- linux-2.6.39.1/net/batman-adv/soft-interface.c 2011-05-19 00:06:34.000000000 -0400
75709+++ linux-2.6.39.1/net/batman-adv/soft-interface.c 2011-05-22 19:36:33.000000000 -0400
75710@@ -386,7 +386,7 @@ int interface_tx(struct sk_buff *skb, st
75711
75712 /* set broadcast sequence number */
75713 bcast_packet->seqno =
75714- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75715+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75716
75717 add_bcast_packet_to_list(bat_priv, skb);
75718
75719@@ -579,7 +579,7 @@ struct net_device *softif_create(char *n
75720 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75721
75722 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75723- atomic_set(&bat_priv->bcast_seqno, 1);
75724+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75725 atomic_set(&bat_priv->hna_local_changed, 0);
75726
75727 bat_priv->primary_if = NULL;
75728diff -urNp linux-2.6.39.1/net/batman-adv/types.h linux-2.6.39.1/net/batman-adv/types.h
75729--- linux-2.6.39.1/net/batman-adv/types.h 2011-05-19 00:06:34.000000000 -0400
75730+++ linux-2.6.39.1/net/batman-adv/types.h 2011-05-22 19:36:33.000000000 -0400
75731@@ -38,8 +38,8 @@ struct hard_iface {
75732 int16_t if_num;
75733 char if_status;
75734 struct net_device *net_dev;
75735- atomic_t seqno;
75736- atomic_t frag_seqno;
75737+ atomic_unchecked_t seqno;
75738+ atomic_unchecked_t frag_seqno;
75739 unsigned char *packet_buff;
75740 int packet_len;
75741 struct kobject *hardif_obj;
75742@@ -141,7 +141,7 @@ struct bat_priv {
75743 atomic_t orig_interval; /* uint */
75744 atomic_t hop_penalty; /* uint */
75745 atomic_t log_level; /* uint */
75746- atomic_t bcast_seqno;
75747+ atomic_unchecked_t bcast_seqno;
75748 atomic_t bcast_queue_left;
75749 atomic_t batman_queue_left;
75750 char num_ifaces;
75751diff -urNp linux-2.6.39.1/net/batman-adv/unicast.c linux-2.6.39.1/net/batman-adv/unicast.c
75752--- linux-2.6.39.1/net/batman-adv/unicast.c 2011-05-19 00:06:34.000000000 -0400
75753+++ linux-2.6.39.1/net/batman-adv/unicast.c 2011-05-22 19:36:33.000000000 -0400
75754@@ -263,7 +263,7 @@ int frag_send_skb(struct sk_buff *skb, s
75755 frag1->flags = UNI_FRAG_HEAD | large_tail;
75756 frag2->flags = large_tail;
75757
75758- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75759+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75760 frag1->seqno = htons(seqno - 1);
75761 frag2->seqno = htons(seqno);
75762
75763diff -urNp linux-2.6.39.1/net/bluetooth/l2cap_sock.c linux-2.6.39.1/net/bluetooth/l2cap_sock.c
75764--- linux-2.6.39.1/net/bluetooth/l2cap_sock.c 2011-05-19 00:06:34.000000000 -0400
75765+++ linux-2.6.39.1/net/bluetooth/l2cap_sock.c 2011-06-12 06:36:08.000000000 -0400
75766@@ -446,6 +446,7 @@ static int l2cap_sock_getsockopt_old(str
75767 break;
75768 }
75769
75770+ memset(&cinfo, 0, sizeof(cinfo));
75771 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle;
75772 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3);
75773
75774diff -urNp linux-2.6.39.1/net/bluetooth/rfcomm/sock.c linux-2.6.39.1/net/bluetooth/rfcomm/sock.c
75775--- linux-2.6.39.1/net/bluetooth/rfcomm/sock.c 2011-05-19 00:06:34.000000000 -0400
75776+++ linux-2.6.39.1/net/bluetooth/rfcomm/sock.c 2011-06-12 06:36:42.000000000 -0400
75777@@ -787,6 +787,7 @@ static int rfcomm_sock_getsockopt_old(st
75778
75779 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
75780
75781+ memset(&cinfo, 0, sizeof(cinfo));
75782 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
75783 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
75784
75785diff -urNp linux-2.6.39.1/net/bridge/br_multicast.c linux-2.6.39.1/net/bridge/br_multicast.c
75786--- linux-2.6.39.1/net/bridge/br_multicast.c 2011-05-19 00:06:34.000000000 -0400
75787+++ linux-2.6.39.1/net/bridge/br_multicast.c 2011-05-22 19:36:33.000000000 -0400
75788@@ -1482,7 +1482,7 @@ static int br_multicast_ipv6_rcv(struct
75789 nexthdr = ip6h->nexthdr;
75790 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75791
75792- if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75793+ if (nexthdr != IPPROTO_ICMPV6)
75794 return 0;
75795
75796 /* Okay, we found ICMPv6 header */
75797diff -urNp linux-2.6.39.1/net/bridge/netfilter/ebtables.c linux-2.6.39.1/net/bridge/netfilter/ebtables.c
75798--- linux-2.6.39.1/net/bridge/netfilter/ebtables.c 2011-05-19 00:06:34.000000000 -0400
75799+++ linux-2.6.39.1/net/bridge/netfilter/ebtables.c 2011-05-22 19:36:33.000000000 -0400
75800@@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
75801 tmp.valid_hooks = t->table->valid_hooks;
75802 }
75803 mutex_unlock(&ebt_mutex);
75804- if (copy_to_user(user, &tmp, *len) != 0){
75805+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75806 BUGPRINT("c2u Didn't work\n");
75807 ret = -EFAULT;
75808 break;
75809@@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
75810 int ret;
75811 void __user *pos;
75812
75813+ pax_track_stack();
75814+
75815 memset(&tinfo, 0, sizeof(tinfo));
75816
75817 if (cmd == EBT_SO_GET_ENTRIES) {
75818diff -urNp linux-2.6.39.1/net/caif/caif_socket.c linux-2.6.39.1/net/caif/caif_socket.c
75819--- linux-2.6.39.1/net/caif/caif_socket.c 2011-05-19 00:06:34.000000000 -0400
75820+++ linux-2.6.39.1/net/caif/caif_socket.c 2011-05-22 19:36:33.000000000 -0400
75821@@ -48,18 +48,19 @@ static struct dentry *debugfsdir;
75822 #ifdef CONFIG_DEBUG_FS
75823 struct debug_fs_counter {
75824 atomic_t caif_nr_socks;
75825- atomic_t num_connect_req;
75826- atomic_t num_connect_resp;
75827- atomic_t num_connect_fail_resp;
75828- atomic_t num_disconnect;
75829- atomic_t num_remote_shutdown_ind;
75830- atomic_t num_tx_flow_off_ind;
75831- atomic_t num_tx_flow_on_ind;
75832- atomic_t num_rx_flow_off;
75833- atomic_t num_rx_flow_on;
75834+ atomic_unchecked_t num_connect_req;
75835+ atomic_unchecked_t num_connect_resp;
75836+ atomic_unchecked_t num_connect_fail_resp;
75837+ atomic_unchecked_t num_disconnect;
75838+ atomic_unchecked_t num_remote_shutdown_ind;
75839+ atomic_unchecked_t num_tx_flow_off_ind;
75840+ atomic_unchecked_t num_tx_flow_on_ind;
75841+ atomic_unchecked_t num_rx_flow_off;
75842+ atomic_unchecked_t num_rx_flow_on;
75843 };
75844 static struct debug_fs_counter cnt;
75845 #define dbfs_atomic_inc(v) atomic_inc(v)
75846+#define dbfs_atomic_inc_unchecked(v) atomic_inc_unchecked(v)
75847 #define dbfs_atomic_dec(v) atomic_dec(v)
75848 #else
75849 #define dbfs_atomic_inc(v)
75850@@ -159,7 +160,7 @@ static int caif_queue_rcv_skb(struct soc
75851 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75852 sk_rcvbuf_lowwater(cf_sk));
75853 set_rx_flow_off(cf_sk);
75854- dbfs_atomic_inc(&cnt.num_rx_flow_off);
75855+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75856 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75857 }
75858
75859@@ -169,7 +170,7 @@ static int caif_queue_rcv_skb(struct soc
75860 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
75861 set_rx_flow_off(cf_sk);
75862 pr_debug("sending flow OFF due to rmem_schedule\n");
75863- dbfs_atomic_inc(&cnt.num_rx_flow_off);
75864+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75865 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75866 }
75867 skb->dev = NULL;
75868@@ -218,21 +219,21 @@ static void caif_ctrl_cb(struct cflayer
75869 switch (flow) {
75870 case CAIF_CTRLCMD_FLOW_ON_IND:
75871 /* OK from modem to start sending again */
75872- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75873+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75874 set_tx_flow_on(cf_sk);
75875 cf_sk->sk.sk_state_change(&cf_sk->sk);
75876 break;
75877
75878 case CAIF_CTRLCMD_FLOW_OFF_IND:
75879 /* Modem asks us to shut up */
75880- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75881+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75882 set_tx_flow_off(cf_sk);
75883 cf_sk->sk.sk_state_change(&cf_sk->sk);
75884 break;
75885
75886 case CAIF_CTRLCMD_INIT_RSP:
75887 /* We're now connected */
75888- dbfs_atomic_inc(&cnt.num_connect_resp);
75889+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75890 cf_sk->sk.sk_state = CAIF_CONNECTED;
75891 set_tx_flow_on(cf_sk);
75892 cf_sk->sk.sk_state_change(&cf_sk->sk);
75893@@ -247,7 +248,7 @@ static void caif_ctrl_cb(struct cflayer
75894
75895 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75896 /* Connect request failed */
75897- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75898+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75899 cf_sk->sk.sk_err = ECONNREFUSED;
75900 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75901 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75902@@ -261,7 +262,7 @@ static void caif_ctrl_cb(struct cflayer
75903
75904 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75905 /* Modem has closed this connection, or device is down. */
75906- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75907+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75908 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75909 cf_sk->sk.sk_err = ECONNRESET;
75910 set_rx_flow_on(cf_sk);
75911@@ -281,7 +282,7 @@ static void caif_check_flow_release(stru
75912 return;
75913
75914 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75915- dbfs_atomic_inc(&cnt.num_rx_flow_on);
75916+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75917 set_rx_flow_on(cf_sk);
75918 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75919 }
75920@@ -864,7 +865,7 @@ static int caif_connect(struct socket *s
75921 /*ifindex = id of the interface.*/
75922 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75923
75924- dbfs_atomic_inc(&cnt.num_connect_req);
75925+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75926 cf_sk->layer.receive = caif_sktrecv_cb;
75927 err = caif_connect_client(&cf_sk->conn_req,
75928 &cf_sk->layer, &ifindex, &headroom, &tailroom);
75929@@ -952,7 +953,7 @@ static int caif_release(struct socket *s
75930 spin_unlock(&sk->sk_receive_queue.lock);
75931 sock->sk = NULL;
75932
75933- dbfs_atomic_inc(&cnt.num_disconnect);
75934+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75935
75936 if (cf_sk->debugfs_socket_dir != NULL)
75937 debugfs_remove_recursive(cf_sk->debugfs_socket_dir);
75938diff -urNp linux-2.6.39.1/net/caif/cfctrl.c linux-2.6.39.1/net/caif/cfctrl.c
75939--- linux-2.6.39.1/net/caif/cfctrl.c 2011-05-19 00:06:34.000000000 -0400
75940+++ linux-2.6.39.1/net/caif/cfctrl.c 2011-05-22 19:36:33.000000000 -0400
75941@@ -9,6 +9,7 @@
75942 #include <linux/stddef.h>
75943 #include <linux/spinlock.h>
75944 #include <linux/slab.h>
75945+#include <linux/sched.h>
75946 #include <net/caif/caif_layer.h>
75947 #include <net/caif/cfpkt.h>
75948 #include <net/caif/cfctrl.h>
75949@@ -46,8 +47,8 @@ struct cflayer *cfctrl_create(void)
75950 dev_info.id = 0xff;
75951 memset(this, 0, sizeof(*this));
75952 cfsrvl_init(&this->serv, 0, &dev_info, false);
75953- atomic_set(&this->req_seq_no, 1);
75954- atomic_set(&this->rsp_seq_no, 1);
75955+ atomic_set_unchecked(&this->req_seq_no, 1);
75956+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75957 this->serv.layer.receive = cfctrl_recv;
75958 sprintf(this->serv.layer.name, "ctrl");
75959 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75960@@ -116,8 +117,8 @@ void cfctrl_insert_req(struct cfctrl *ct
75961 struct cfctrl_request_info *req)
75962 {
75963 spin_lock(&ctrl->info_list_lock);
75964- atomic_inc(&ctrl->req_seq_no);
75965- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75966+ atomic_inc_unchecked(&ctrl->req_seq_no);
75967+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75968 list_add_tail(&req->list, &ctrl->list);
75969 spin_unlock(&ctrl->info_list_lock);
75970 }
75971@@ -136,7 +137,7 @@ struct cfctrl_request_info *cfctrl_remov
75972 if (p != first)
75973 pr_warn("Requests are not received in order\n");
75974
75975- atomic_set(&ctrl->rsp_seq_no,
75976+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75977 p->sequence_no);
75978 list_del(&p->list);
75979 goto out;
75980@@ -385,6 +386,7 @@ static int cfctrl_recv(struct cflayer *l
75981 struct cfctrl *cfctrl = container_obj(layer);
75982 struct cfctrl_request_info rsp, *req;
75983
75984+ pax_track_stack();
75985
75986 cfpkt_extr_head(pkt, &cmdrsp, 1);
75987 cmd = cmdrsp & CFCTRL_CMD_MASK;
75988diff -urNp linux-2.6.39.1/net/can/bcm.c linux-2.6.39.1/net/can/bcm.c
75989--- linux-2.6.39.1/net/can/bcm.c 2011-05-19 00:06:34.000000000 -0400
75990+++ linux-2.6.39.1/net/can/bcm.c 2011-05-22 19:41:42.000000000 -0400
75991@@ -165,9 +165,15 @@ static int bcm_proc_show(struct seq_file
75992 struct bcm_sock *bo = bcm_sk(sk);
75993 struct bcm_op *op;
75994
75995+#ifdef CONFIG_GRKERNSEC_HIDESYM
75996+ seq_printf(m, ">>> socket %p", NULL);
75997+ seq_printf(m, " / sk %p", NULL);
75998+ seq_printf(m, " / bo %p", NULL);
75999+#else
76000 seq_printf(m, ">>> socket %p", sk->sk_socket);
76001 seq_printf(m, " / sk %p", sk);
76002 seq_printf(m, " / bo %p", bo);
76003+#endif
76004 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
76005 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
76006 seq_printf(m, " <<<\n");
76007diff -urNp linux-2.6.39.1/net/core/datagram.c linux-2.6.39.1/net/core/datagram.c
76008--- linux-2.6.39.1/net/core/datagram.c 2011-05-19 00:06:34.000000000 -0400
76009+++ linux-2.6.39.1/net/core/datagram.c 2011-05-22 19:36:33.000000000 -0400
76010@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
76011 }
76012
76013 kfree_skb(skb);
76014- atomic_inc(&sk->sk_drops);
76015+ atomic_inc_unchecked(&sk->sk_drops);
76016 sk_mem_reclaim_partial(sk);
76017
76018 return err;
76019diff -urNp linux-2.6.39.1/net/core/dev.c linux-2.6.39.1/net/core/dev.c
76020--- linux-2.6.39.1/net/core/dev.c 2011-06-03 00:04:14.000000000 -0400
76021+++ linux-2.6.39.1/net/core/dev.c 2011-06-03 00:32:08.000000000 -0400
76022@@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
76023 if (no_module && capable(CAP_NET_ADMIN))
76024 no_module = request_module("netdev-%s", name);
76025 if (no_module && capable(CAP_SYS_MODULE)) {
76026+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76027+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
76028+#else
76029 if (!request_module("%s", name))
76030 pr_err("Loading kernel module for a network device "
76031 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
76032 "instead\n", name);
76033+#endif
76034 }
76035 }
76036 EXPORT_SYMBOL(dev_load);
76037@@ -1957,7 +1961,7 @@ struct dev_gso_cb {
76038
76039 static void dev_gso_skb_destructor(struct sk_buff *skb)
76040 {
76041- struct dev_gso_cb *cb;
76042+ const struct dev_gso_cb *cb;
76043
76044 do {
76045 struct sk_buff *nskb = skb->next;
76046@@ -2901,7 +2905,7 @@ int netif_rx_ni(struct sk_buff *skb)
76047 }
76048 EXPORT_SYMBOL(netif_rx_ni);
76049
76050-static void net_tx_action(struct softirq_action *h)
76051+static void net_tx_action(void)
76052 {
76053 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76054
76055@@ -3765,7 +3769,7 @@ void netif_napi_del(struct napi_struct *
76056 }
76057 EXPORT_SYMBOL(netif_napi_del);
76058
76059-static void net_rx_action(struct softirq_action *h)
76060+static void net_rx_action(void)
76061 {
76062 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76063 unsigned long time_limit = jiffies + 2;
76064diff -urNp linux-2.6.39.1/net/core/flow.c linux-2.6.39.1/net/core/flow.c
76065--- linux-2.6.39.1/net/core/flow.c 2011-05-19 00:06:34.000000000 -0400
76066+++ linux-2.6.39.1/net/core/flow.c 2011-05-22 19:36:34.000000000 -0400
76067@@ -60,7 +60,7 @@ struct flow_cache {
76068 struct timer_list rnd_timer;
76069 };
76070
76071-atomic_t flow_cache_genid = ATOMIC_INIT(0);
76072+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76073 EXPORT_SYMBOL(flow_cache_genid);
76074 static struct flow_cache flow_cache_global;
76075 static struct kmem_cache *flow_cachep __read_mostly;
76076@@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
76077
76078 static int flow_entry_valid(struct flow_cache_entry *fle)
76079 {
76080- if (atomic_read(&flow_cache_genid) != fle->genid)
76081+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76082 return 0;
76083 if (fle->object && !fle->object->ops->check(fle->object))
76084 return 0;
76085@@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
76086 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76087 fcp->hash_count++;
76088 }
76089- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76090+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76091 flo = fle->object;
76092 if (!flo)
76093 goto ret_object;
76094@@ -274,7 +274,7 @@ nocache:
76095 }
76096 flo = resolver(net, key, family, dir, flo, ctx);
76097 if (fle) {
76098- fle->genid = atomic_read(&flow_cache_genid);
76099+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
76100 if (!IS_ERR(flo))
76101 fle->object = flo;
76102 else
76103diff -urNp linux-2.6.39.1/net/core/skbuff.c linux-2.6.39.1/net/core/skbuff.c
76104--- linux-2.6.39.1/net/core/skbuff.c 2011-06-03 00:04:14.000000000 -0400
76105+++ linux-2.6.39.1/net/core/skbuff.c 2011-06-03 00:32:08.000000000 -0400
76106@@ -1542,6 +1542,8 @@ int skb_splice_bits(struct sk_buff *skb,
76107 struct sock *sk = skb->sk;
76108 int ret = 0;
76109
76110+ pax_track_stack();
76111+
76112 if (splice_grow_spd(pipe, &spd))
76113 return -ENOMEM;
76114
76115diff -urNp linux-2.6.39.1/net/core/sock.c linux-2.6.39.1/net/core/sock.c
76116--- linux-2.6.39.1/net/core/sock.c 2011-05-19 00:06:34.000000000 -0400
76117+++ linux-2.6.39.1/net/core/sock.c 2011-05-22 19:36:34.000000000 -0400
76118@@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76119 */
76120 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
76121 (unsigned)sk->sk_rcvbuf) {
76122- atomic_inc(&sk->sk_drops);
76123+ atomic_inc_unchecked(&sk->sk_drops);
76124 return -ENOMEM;
76125 }
76126
76127@@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76128 return err;
76129
76130 if (!sk_rmem_schedule(sk, skb->truesize)) {
76131- atomic_inc(&sk->sk_drops);
76132+ atomic_inc_unchecked(&sk->sk_drops);
76133 return -ENOBUFS;
76134 }
76135
76136@@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76137 skb_dst_force(skb);
76138
76139 spin_lock_irqsave(&list->lock, flags);
76140- skb->dropcount = atomic_read(&sk->sk_drops);
76141+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76142 __skb_queue_tail(list, skb);
76143 spin_unlock_irqrestore(&list->lock, flags);
76144
76145@@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
76146 skb->dev = NULL;
76147
76148 if (sk_rcvqueues_full(sk, skb)) {
76149- atomic_inc(&sk->sk_drops);
76150+ atomic_inc_unchecked(&sk->sk_drops);
76151 goto discard_and_relse;
76152 }
76153 if (nested)
76154@@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
76155 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76156 } else if (sk_add_backlog(sk, skb)) {
76157 bh_unlock_sock(sk);
76158- atomic_inc(&sk->sk_drops);
76159+ atomic_inc_unchecked(&sk->sk_drops);
76160 goto discard_and_relse;
76161 }
76162
76163@@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
76164 return -ENOTCONN;
76165 if (lv < len)
76166 return -EINVAL;
76167- if (copy_to_user(optval, address, len))
76168+ if (len > sizeof(address) || copy_to_user(optval, address, len))
76169 return -EFAULT;
76170 goto lenout;
76171 }
76172@@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
76173
76174 if (len > lv)
76175 len = lv;
76176- if (copy_to_user(optval, &v, len))
76177+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76178 return -EFAULT;
76179 lenout:
76180 if (put_user(len, optlen))
76181@@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
76182 */
76183 smp_wmb();
76184 atomic_set(&sk->sk_refcnt, 1);
76185- atomic_set(&sk->sk_drops, 0);
76186+ atomic_set_unchecked(&sk->sk_drops, 0);
76187 }
76188 EXPORT_SYMBOL(sock_init_data);
76189
76190diff -urNp linux-2.6.39.1/net/decnet/sysctl_net_decnet.c linux-2.6.39.1/net/decnet/sysctl_net_decnet.c
76191--- linux-2.6.39.1/net/decnet/sysctl_net_decnet.c 2011-05-19 00:06:34.000000000 -0400
76192+++ linux-2.6.39.1/net/decnet/sysctl_net_decnet.c 2011-05-22 19:36:34.000000000 -0400
76193@@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
76194
76195 if (len > *lenp) len = *lenp;
76196
76197- if (copy_to_user(buffer, addr, len))
76198+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76199 return -EFAULT;
76200
76201 *lenp = len;
76202@@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
76203
76204 if (len > *lenp) len = *lenp;
76205
76206- if (copy_to_user(buffer, devname, len))
76207+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76208 return -EFAULT;
76209
76210 *lenp = len;
76211diff -urNp linux-2.6.39.1/net/econet/Kconfig linux-2.6.39.1/net/econet/Kconfig
76212--- linux-2.6.39.1/net/econet/Kconfig 2011-05-19 00:06:34.000000000 -0400
76213+++ linux-2.6.39.1/net/econet/Kconfig 2011-05-22 19:41:42.000000000 -0400
76214@@ -4,7 +4,7 @@
76215
76216 config ECONET
76217 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
76218- depends on EXPERIMENTAL && INET
76219+ depends on EXPERIMENTAL && INET && BROKEN
76220 ---help---
76221 Econet is a fairly old and slow networking protocol mainly used by
76222 Acorn computers to access file and print servers. It uses native
76223diff -urNp linux-2.6.39.1/net/ipv4/fib_frontend.c linux-2.6.39.1/net/ipv4/fib_frontend.c
76224--- linux-2.6.39.1/net/ipv4/fib_frontend.c 2011-05-19 00:06:34.000000000 -0400
76225+++ linux-2.6.39.1/net/ipv4/fib_frontend.c 2011-05-22 19:36:34.000000000 -0400
76226@@ -968,12 +968,12 @@ static int fib_inetaddr_event(struct not
76227 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76228 fib_sync_up(dev);
76229 #endif
76230- atomic_inc(&net->ipv4.dev_addr_genid);
76231+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76232 rt_cache_flush(dev_net(dev), -1);
76233 break;
76234 case NETDEV_DOWN:
76235 fib_del_ifaddr(ifa, NULL);
76236- atomic_inc(&net->ipv4.dev_addr_genid);
76237+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76238 if (ifa->ifa_dev->ifa_list == NULL) {
76239 /* Last address was deleted from this interface.
76240 * Disable IP.
76241@@ -1009,7 +1009,7 @@ static int fib_netdev_event(struct notif
76242 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76243 fib_sync_up(dev);
76244 #endif
76245- atomic_inc(&net->ipv4.dev_addr_genid);
76246+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76247 rt_cache_flush(dev_net(dev), -1);
76248 break;
76249 case NETDEV_DOWN:
76250diff -urNp linux-2.6.39.1/net/ipv4/fib_semantics.c linux-2.6.39.1/net/ipv4/fib_semantics.c
76251--- linux-2.6.39.1/net/ipv4/fib_semantics.c 2011-05-19 00:06:34.000000000 -0400
76252+++ linux-2.6.39.1/net/ipv4/fib_semantics.c 2011-05-22 19:36:34.000000000 -0400
76253@@ -701,7 +701,7 @@ __be32 fib_info_update_nh_saddr(struct n
76254 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76255 nh->nh_gw,
76256 nh->nh_parent->fib_scope);
76257- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76258+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76259
76260 return nh->nh_saddr;
76261 }
76262diff -urNp linux-2.6.39.1/net/ipv4/inet_diag.c linux-2.6.39.1/net/ipv4/inet_diag.c
76263--- linux-2.6.39.1/net/ipv4/inet_diag.c 2011-05-19 00:06:34.000000000 -0400
76264+++ linux-2.6.39.1/net/ipv4/inet_diag.c 2011-05-22 19:41:42.000000000 -0400
76265@@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
76266 r->idiag_retrans = 0;
76267
76268 r->id.idiag_if = sk->sk_bound_dev_if;
76269+
76270+#ifdef CONFIG_GRKERNSEC_HIDESYM
76271+ r->id.idiag_cookie[0] = 0;
76272+ r->id.idiag_cookie[1] = 0;
76273+#else
76274 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
76275 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76276+#endif
76277
76278 r->id.idiag_sport = inet->inet_sport;
76279 r->id.idiag_dport = inet->inet_dport;
76280@@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
76281 r->idiag_family = tw->tw_family;
76282 r->idiag_retrans = 0;
76283 r->id.idiag_if = tw->tw_bound_dev_if;
76284+
76285+#ifdef CONFIG_GRKERNSEC_HIDESYM
76286+ r->id.idiag_cookie[0] = 0;
76287+ r->id.idiag_cookie[1] = 0;
76288+#else
76289 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
76290 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
76291+#endif
76292+
76293 r->id.idiag_sport = tw->tw_sport;
76294 r->id.idiag_dport = tw->tw_dport;
76295 r->id.idiag_src[0] = tw->tw_rcv_saddr;
76296@@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
76297 if (sk == NULL)
76298 goto unlock;
76299
76300+#ifndef CONFIG_GRKERNSEC_HIDESYM
76301 err = -ESTALE;
76302 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
76303 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
76304 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
76305 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
76306 goto out;
76307+#endif
76308
76309 err = -ENOMEM;
76310 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
76311@@ -582,8 +597,14 @@ static int inet_diag_fill_req(struct sk_
76312 r->idiag_retrans = req->retrans;
76313
76314 r->id.idiag_if = sk->sk_bound_dev_if;
76315+
76316+#ifdef CONFIG_GRKERNSEC_HIDESYM
76317+ r->id.idiag_cookie[0] = 0;
76318+ r->id.idiag_cookie[1] = 0;
76319+#else
76320 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
76321 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
76322+#endif
76323
76324 tmo = req->expires - jiffies;
76325 if (tmo < 0)
76326diff -urNp linux-2.6.39.1/net/ipv4/inet_hashtables.c linux-2.6.39.1/net/ipv4/inet_hashtables.c
76327--- linux-2.6.39.1/net/ipv4/inet_hashtables.c 2011-05-19 00:06:34.000000000 -0400
76328+++ linux-2.6.39.1/net/ipv4/inet_hashtables.c 2011-05-22 19:41:42.000000000 -0400
76329@@ -18,11 +18,14 @@
76330 #include <linux/sched.h>
76331 #include <linux/slab.h>
76332 #include <linux/wait.h>
76333+#include <linux/security.h>
76334
76335 #include <net/inet_connection_sock.h>
76336 #include <net/inet_hashtables.h>
76337 #include <net/ip.h>
76338
76339+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76340+
76341 /*
76342 * Allocate and initialize a new local port bind bucket.
76343 * The bindhash mutex for snum's hash chain must be held here.
76344@@ -529,6 +532,8 @@ ok:
76345 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76346 spin_unlock(&head->lock);
76347
76348+ gr_update_task_in_ip_table(current, inet_sk(sk));
76349+
76350 if (tw) {
76351 inet_twsk_deschedule(tw, death_row);
76352 while (twrefcnt) {
76353diff -urNp linux-2.6.39.1/net/ipv4/inetpeer.c linux-2.6.39.1/net/ipv4/inetpeer.c
76354--- linux-2.6.39.1/net/ipv4/inetpeer.c 2011-05-19 00:06:34.000000000 -0400
76355+++ linux-2.6.39.1/net/ipv4/inetpeer.c 2011-05-22 19:36:34.000000000 -0400
76356@@ -467,6 +467,8 @@ struct inet_peer *inet_getpeer(struct in
76357 unsigned int sequence;
76358 int invalidated;
76359
76360+ pax_track_stack();
76361+
76362 /* Look up for the address quickly, lockless.
76363 * Because of a concurrent writer, we might not find an existing entry.
76364 */
76365@@ -504,8 +506,8 @@ struct inet_peer *inet_getpeer(struct in
76366 if (p) {
76367 p->daddr = *daddr;
76368 atomic_set(&p->refcnt, 1);
76369- atomic_set(&p->rid, 0);
76370- atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76371+ atomic_set_unchecked(&p->rid, 0);
76372+ atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76373 p->tcp_ts_stamp = 0;
76374 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
76375 p->rate_tokens = 0;
76376diff -urNp linux-2.6.39.1/net/ipv4/ip_fragment.c linux-2.6.39.1/net/ipv4/ip_fragment.c
76377--- linux-2.6.39.1/net/ipv4/ip_fragment.c 2011-05-19 00:06:34.000000000 -0400
76378+++ linux-2.6.39.1/net/ipv4/ip_fragment.c 2011-05-22 19:36:34.000000000 -0400
76379@@ -297,7 +297,7 @@ static inline int ip_frag_too_far(struct
76380 return 0;
76381
76382 start = qp->rid;
76383- end = atomic_inc_return(&peer->rid);
76384+ end = atomic_inc_return_unchecked(&peer->rid);
76385 qp->rid = end;
76386
76387 rc = qp->q.fragments && (end - start) > max;
76388diff -urNp linux-2.6.39.1/net/ipv4/ip_sockglue.c linux-2.6.39.1/net/ipv4/ip_sockglue.c
76389--- linux-2.6.39.1/net/ipv4/ip_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76390+++ linux-2.6.39.1/net/ipv4/ip_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76391@@ -1064,6 +1064,8 @@ static int do_ip_getsockopt(struct sock
76392 int val;
76393 int len;
76394
76395+ pax_track_stack();
76396+
76397 if (level != SOL_IP)
76398 return -EOPNOTSUPP;
76399
76400diff -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
76401--- linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-19 00:06:34.000000000 -0400
76402+++ linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-22 19:36:34.000000000 -0400
76403@@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
76404
76405 *len = 0;
76406
76407- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76408+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76409 if (*octets == NULL) {
76410 if (net_ratelimit())
76411 pr_notice("OOM in bsalg (%d)\n", __LINE__);
76412diff -urNp linux-2.6.39.1/net/ipv4/raw.c linux-2.6.39.1/net/ipv4/raw.c
76413--- linux-2.6.39.1/net/ipv4/raw.c 2011-05-19 00:06:34.000000000 -0400
76414+++ linux-2.6.39.1/net/ipv4/raw.c 2011-05-22 19:41:42.000000000 -0400
76415@@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
76416 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76417 {
76418 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76419- atomic_inc(&sk->sk_drops);
76420+ atomic_inc_unchecked(&sk->sk_drops);
76421 kfree_skb(skb);
76422 return NET_RX_DROP;
76423 }
76424@@ -730,15 +730,19 @@ static int raw_init(struct sock *sk)
76425
76426 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76427 {
76428+ struct icmp_filter filter;
76429+
76430 if (optlen > sizeof(struct icmp_filter))
76431 optlen = sizeof(struct icmp_filter);
76432- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76433+ if (copy_from_user(&filter, optval, optlen))
76434 return -EFAULT;
76435+ memcpy(&raw_sk(sk)->filter, &filter, sizeof(filter));
76436 return 0;
76437 }
76438
76439 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76440 {
76441+ struct icmp_filter filter;
76442 int len, ret = -EFAULT;
76443
76444 if (get_user(len, optlen))
76445@@ -749,8 +753,9 @@ static int raw_geticmpfilter(struct sock
76446 if (len > sizeof(struct icmp_filter))
76447 len = sizeof(struct icmp_filter);
76448 ret = -EFAULT;
76449+ memcpy(&filter, &raw_sk(sk)->filter, len);
76450 if (put_user(len, optlen) ||
76451- copy_to_user(optval, &raw_sk(sk)->filter, len))
76452+ copy_to_user(optval, &filter, len))
76453 goto out;
76454 ret = 0;
76455 out: return ret;
76456@@ -978,7 +983,13 @@ static void raw_sock_seq_show(struct seq
76457 sk_wmem_alloc_get(sp),
76458 sk_rmem_alloc_get(sp),
76459 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76460- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76461+ atomic_read(&sp->sk_refcnt),
76462+#ifdef CONFIG_GRKERNSEC_HIDESYM
76463+ NULL,
76464+#else
76465+ sp,
76466+#endif
76467+ atomic_read_unchecked(&sp->sk_drops));
76468 }
76469
76470 static int raw_seq_show(struct seq_file *seq, void *v)
76471diff -urNp linux-2.6.39.1/net/ipv4/route.c linux-2.6.39.1/net/ipv4/route.c
76472--- linux-2.6.39.1/net/ipv4/route.c 2011-05-19 00:06:34.000000000 -0400
76473+++ linux-2.6.39.1/net/ipv4/route.c 2011-05-22 19:36:34.000000000 -0400
76474@@ -303,7 +303,7 @@ static inline unsigned int rt_hash(__be3
76475
76476 static inline int rt_genid(struct net *net)
76477 {
76478- return atomic_read(&net->ipv4.rt_genid);
76479+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76480 }
76481
76482 #ifdef CONFIG_PROC_FS
76483@@ -831,7 +831,7 @@ static void rt_cache_invalidate(struct n
76484 unsigned char shuffle;
76485
76486 get_random_bytes(&shuffle, sizeof(shuffle));
76487- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76488+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76489 }
76490
76491 /*
76492@@ -2835,7 +2835,7 @@ static int rt_fill_info(struct net *net,
76493 rt->peer->pmtu_expires - jiffies : 0;
76494 if (rt->peer) {
76495 inet_peer_refcheck(rt->peer);
76496- id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
76497+ id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
76498 if (rt->peer->tcp_ts_stamp) {
76499 ts = rt->peer->tcp_ts;
76500 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
76501diff -urNp linux-2.6.39.1/net/ipv4/tcp.c linux-2.6.39.1/net/ipv4/tcp.c
76502--- linux-2.6.39.1/net/ipv4/tcp.c 2011-05-19 00:06:34.000000000 -0400
76503+++ linux-2.6.39.1/net/ipv4/tcp.c 2011-05-22 19:36:34.000000000 -0400
76504@@ -2121,6 +2121,8 @@ static int do_tcp_setsockopt(struct sock
76505 int val;
76506 int err = 0;
76507
76508+ pax_track_stack();
76509+
76510 /* These are data/string values, all the others are ints */
76511 switch (optname) {
76512 case TCP_CONGESTION: {
76513@@ -2500,6 +2502,8 @@ static int do_tcp_getsockopt(struct sock
76514 struct tcp_sock *tp = tcp_sk(sk);
76515 int val, len;
76516
76517+ pax_track_stack();
76518+
76519 if (get_user(len, optlen))
76520 return -EFAULT;
76521
76522diff -urNp linux-2.6.39.1/net/ipv4/tcp_ipv4.c linux-2.6.39.1/net/ipv4/tcp_ipv4.c
76523--- linux-2.6.39.1/net/ipv4/tcp_ipv4.c 2011-05-19 00:06:34.000000000 -0400
76524+++ linux-2.6.39.1/net/ipv4/tcp_ipv4.c 2011-05-22 19:41:42.000000000 -0400
76525@@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76526 int sysctl_tcp_low_latency __read_mostly;
76527 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76528
76529+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76530+extern int grsec_enable_blackhole;
76531+#endif
76532
76533 #ifdef CONFIG_TCP_MD5SIG
76534 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76535@@ -1594,6 +1597,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
76536 return 0;
76537
76538 reset:
76539+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76540+ if (!grsec_enable_blackhole)
76541+#endif
76542 tcp_v4_send_reset(rsk, skb);
76543 discard:
76544 kfree_skb(skb);
76545@@ -1656,12 +1662,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76546 TCP_SKB_CB(skb)->sacked = 0;
76547
76548 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76549- if (!sk)
76550+ if (!sk) {
76551+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76552+ ret = 1;
76553+#endif
76554 goto no_tcp_socket;
76555-
76556+ }
76557 process:
76558- if (sk->sk_state == TCP_TIME_WAIT)
76559+ if (sk->sk_state == TCP_TIME_WAIT) {
76560+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76561+ ret = 2;
76562+#endif
76563 goto do_time_wait;
76564+ }
76565
76566 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76567 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76568@@ -1711,6 +1724,10 @@ no_tcp_socket:
76569 bad_packet:
76570 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76571 } else {
76572+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76573+ if (!grsec_enable_blackhole || (ret == 1 &&
76574+ (skb->dev->flags & IFF_LOOPBACK)))
76575+#endif
76576 tcp_v4_send_reset(NULL, skb);
76577 }
76578
76579@@ -2374,7 +2391,11 @@ static void get_openreq4(struct sock *sk
76580 0, /* non standard timer */
76581 0, /* open_requests have no inode */
76582 atomic_read(&sk->sk_refcnt),
76583+#ifdef CONFIG_GRKERNSEC_HIDESYM
76584+ NULL,
76585+#else
76586 req,
76587+#endif
76588 len);
76589 }
76590
76591@@ -2424,7 +2445,12 @@ static void get_tcp4_sock(struct sock *s
76592 sock_i_uid(sk),
76593 icsk->icsk_probes_out,
76594 sock_i_ino(sk),
76595- atomic_read(&sk->sk_refcnt), sk,
76596+ atomic_read(&sk->sk_refcnt),
76597+#ifdef CONFIG_GRKERNSEC_HIDESYM
76598+ NULL,
76599+#else
76600+ sk,
76601+#endif
76602 jiffies_to_clock_t(icsk->icsk_rto),
76603 jiffies_to_clock_t(icsk->icsk_ack.ato),
76604 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76605@@ -2452,7 +2478,13 @@ static void get_timewait4_sock(struct in
76606 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
76607 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76608 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76609- atomic_read(&tw->tw_refcnt), tw, len);
76610+ atomic_read(&tw->tw_refcnt),
76611+#ifdef CONFIG_GRKERNSEC_HIDESYM
76612+ NULL,
76613+#else
76614+ tw,
76615+#endif
76616+ len);
76617 }
76618
76619 #define TMPSZ 150
76620diff -urNp linux-2.6.39.1/net/ipv4/tcp_minisocks.c linux-2.6.39.1/net/ipv4/tcp_minisocks.c
76621--- linux-2.6.39.1/net/ipv4/tcp_minisocks.c 2011-05-19 00:06:34.000000000 -0400
76622+++ linux-2.6.39.1/net/ipv4/tcp_minisocks.c 2011-05-22 19:41:42.000000000 -0400
76623@@ -27,6 +27,10 @@
76624 #include <net/inet_common.h>
76625 #include <net/xfrm.h>
76626
76627+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76628+extern int grsec_enable_blackhole;
76629+#endif
76630+
76631 int sysctl_tcp_syncookies __read_mostly = 1;
76632 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76633
76634@@ -745,6 +749,10 @@ listen_overflow:
76635
76636 embryonic_reset:
76637 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76638+
76639+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76640+ if (!grsec_enable_blackhole)
76641+#endif
76642 if (!(flg & TCP_FLAG_RST))
76643 req->rsk_ops->send_reset(sk, skb);
76644
76645diff -urNp linux-2.6.39.1/net/ipv4/tcp_output.c linux-2.6.39.1/net/ipv4/tcp_output.c
76646--- linux-2.6.39.1/net/ipv4/tcp_output.c 2011-05-19 00:06:34.000000000 -0400
76647+++ linux-2.6.39.1/net/ipv4/tcp_output.c 2011-05-22 19:36:34.000000000 -0400
76648@@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
76649 int mss;
76650 int s_data_desired = 0;
76651
76652+ pax_track_stack();
76653+
76654 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76655 s_data_desired = cvp->s_data_desired;
76656 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76657diff -urNp linux-2.6.39.1/net/ipv4/tcp_probe.c linux-2.6.39.1/net/ipv4/tcp_probe.c
76658--- linux-2.6.39.1/net/ipv4/tcp_probe.c 2011-05-19 00:06:34.000000000 -0400
76659+++ linux-2.6.39.1/net/ipv4/tcp_probe.c 2011-05-22 19:36:34.000000000 -0400
76660@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
76661 if (cnt + width >= len)
76662 break;
76663
76664- if (copy_to_user(buf + cnt, tbuf, width))
76665+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76666 return -EFAULT;
76667 cnt += width;
76668 }
76669diff -urNp linux-2.6.39.1/net/ipv4/tcp_timer.c linux-2.6.39.1/net/ipv4/tcp_timer.c
76670--- linux-2.6.39.1/net/ipv4/tcp_timer.c 2011-05-19 00:06:34.000000000 -0400
76671+++ linux-2.6.39.1/net/ipv4/tcp_timer.c 2011-05-22 19:41:42.000000000 -0400
76672@@ -22,6 +22,10 @@
76673 #include <linux/gfp.h>
76674 #include <net/tcp.h>
76675
76676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76677+extern int grsec_lastack_retries;
76678+#endif
76679+
76680 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76681 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76682 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76683@@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
76684 }
76685 }
76686
76687+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76688+ if ((sk->sk_state == TCP_LAST_ACK) &&
76689+ (grsec_lastack_retries > 0) &&
76690+ (grsec_lastack_retries < retry_until))
76691+ retry_until = grsec_lastack_retries;
76692+#endif
76693+
76694 if (retransmits_timed_out(sk, retry_until,
76695 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76696 /* Has it gone just too far? */
76697diff -urNp linux-2.6.39.1/net/ipv4/udp.c linux-2.6.39.1/net/ipv4/udp.c
76698--- linux-2.6.39.1/net/ipv4/udp.c 2011-05-19 00:06:34.000000000 -0400
76699+++ linux-2.6.39.1/net/ipv4/udp.c 2011-05-22 19:41:42.000000000 -0400
76700@@ -86,6 +86,7 @@
76701 #include <linux/types.h>
76702 #include <linux/fcntl.h>
76703 #include <linux/module.h>
76704+#include <linux/security.h>
76705 #include <linux/socket.h>
76706 #include <linux/sockios.h>
76707 #include <linux/igmp.h>
76708@@ -107,6 +108,10 @@
76709 #include <net/xfrm.h>
76710 #include "udp_impl.h"
76711
76712+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76713+extern int grsec_enable_blackhole;
76714+#endif
76715+
76716 struct udp_table udp_table __read_mostly;
76717 EXPORT_SYMBOL(udp_table);
76718
76719@@ -564,6 +569,9 @@ found:
76720 return s;
76721 }
76722
76723+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76724+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76725+
76726 /*
76727 * This routine is called by the ICMP module when it gets some
76728 * sort of error condition. If err < 0 then the socket should
76729@@ -853,9 +861,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
76730 dport = usin->sin_port;
76731 if (dport == 0)
76732 return -EINVAL;
76733+
76734+ err = gr_search_udp_sendmsg(sk, usin);
76735+ if (err)
76736+ return err;
76737 } else {
76738 if (sk->sk_state != TCP_ESTABLISHED)
76739 return -EDESTADDRREQ;
76740+
76741+ err = gr_search_udp_sendmsg(sk, NULL);
76742+ if (err)
76743+ return err;
76744+
76745 daddr = inet->inet_daddr;
76746 dport = inet->inet_dport;
76747 /* Open fast path for connected socket.
76748@@ -1090,7 +1107,7 @@ static unsigned int first_packet_length(
76749 udp_lib_checksum_complete(skb)) {
76750 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76751 IS_UDPLITE(sk));
76752- atomic_inc(&sk->sk_drops);
76753+ atomic_inc_unchecked(&sk->sk_drops);
76754 __skb_unlink(skb, rcvq);
76755 __skb_queue_tail(&list_kill, skb);
76756 }
76757@@ -1176,6 +1193,10 @@ try_again:
76758 if (!skb)
76759 goto out;
76760
76761+ err = gr_search_udp_recvmsg(sk, skb);
76762+ if (err)
76763+ goto out_free;
76764+
76765 ulen = skb->len - sizeof(struct udphdr);
76766 if (len > ulen)
76767 len = ulen;
76768@@ -1472,7 +1493,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
76769
76770 drop:
76771 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76772- atomic_inc(&sk->sk_drops);
76773+ atomic_inc_unchecked(&sk->sk_drops);
76774 kfree_skb(skb);
76775 return -1;
76776 }
76777@@ -1491,7 +1512,7 @@ static void flush_stack(struct sock **st
76778 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76779
76780 if (!skb1) {
76781- atomic_inc(&sk->sk_drops);
76782+ atomic_inc_unchecked(&sk->sk_drops);
76783 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76784 IS_UDPLITE(sk));
76785 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76786@@ -1660,6 +1681,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
76787 goto csum_error;
76788
76789 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76790+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76791+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76792+#endif
76793 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76794
76795 /*
76796@@ -2087,8 +2111,13 @@ static void udp4_format_sock(struct sock
76797 sk_wmem_alloc_get(sp),
76798 sk_rmem_alloc_get(sp),
76799 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76800- atomic_read(&sp->sk_refcnt), sp,
76801- atomic_read(&sp->sk_drops), len);
76802+ atomic_read(&sp->sk_refcnt),
76803+#ifdef CONFIG_GRKERNSEC_HIDESYM
76804+ NULL,
76805+#else
76806+ sp,
76807+#endif
76808+ atomic_read_unchecked(&sp->sk_drops), len);
76809 }
76810
76811 int udp4_seq_show(struct seq_file *seq, void *v)
76812diff -urNp linux-2.6.39.1/net/ipv6/inet6_connection_sock.c linux-2.6.39.1/net/ipv6/inet6_connection_sock.c
76813--- linux-2.6.39.1/net/ipv6/inet6_connection_sock.c 2011-05-19 00:06:34.000000000 -0400
76814+++ linux-2.6.39.1/net/ipv6/inet6_connection_sock.c 2011-05-22 19:36:34.000000000 -0400
76815@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
76816 #ifdef CONFIG_XFRM
76817 {
76818 struct rt6_info *rt = (struct rt6_info *)dst;
76819- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76820+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76821 }
76822 #endif
76823 }
76824@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
76825 #ifdef CONFIG_XFRM
76826 if (dst) {
76827 struct rt6_info *rt = (struct rt6_info *)dst;
76828- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76829+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76830 __sk_dst_reset(sk);
76831 dst = NULL;
76832 }
76833diff -urNp linux-2.6.39.1/net/ipv6/ipv6_sockglue.c linux-2.6.39.1/net/ipv6/ipv6_sockglue.c
76834--- linux-2.6.39.1/net/ipv6/ipv6_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76835+++ linux-2.6.39.1/net/ipv6/ipv6_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76836@@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
76837 int val, valbool;
76838 int retv = -ENOPROTOOPT;
76839
76840+ pax_track_stack();
76841+
76842 if (optval == NULL)
76843 val=0;
76844 else {
76845@@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
76846 int len;
76847 int val;
76848
76849+ pax_track_stack();
76850+
76851 if (ip6_mroute_opt(optname))
76852 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76853
76854diff -urNp linux-2.6.39.1/net/ipv6/raw.c linux-2.6.39.1/net/ipv6/raw.c
76855--- linux-2.6.39.1/net/ipv6/raw.c 2011-05-19 00:06:34.000000000 -0400
76856+++ linux-2.6.39.1/net/ipv6/raw.c 2011-05-22 19:41:42.000000000 -0400
76857@@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
76858 {
76859 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76860 skb_checksum_complete(skb)) {
76861- atomic_inc(&sk->sk_drops);
76862+ atomic_inc_unchecked(&sk->sk_drops);
76863 kfree_skb(skb);
76864 return NET_RX_DROP;
76865 }
76866@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76867 struct raw6_sock *rp = raw6_sk(sk);
76868
76869 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76870- atomic_inc(&sk->sk_drops);
76871+ atomic_inc_unchecked(&sk->sk_drops);
76872 kfree_skb(skb);
76873 return NET_RX_DROP;
76874 }
76875@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76876
76877 if (inet->hdrincl) {
76878 if (skb_checksum_complete(skb)) {
76879- atomic_inc(&sk->sk_drops);
76880+ atomic_inc_unchecked(&sk->sk_drops);
76881 kfree_skb(skb);
76882 return NET_RX_DROP;
76883 }
76884@@ -601,7 +601,7 @@ out:
76885 return err;
76886 }
76887
76888-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76889+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76890 struct flowi6 *fl6, struct dst_entry **dstp,
76891 unsigned int flags)
76892 {
76893@@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
76894 u16 proto;
76895 int err;
76896
76897+ pax_track_stack();
76898+
76899 /* Rough check on arithmetic overflow,
76900 better check is made in ip6_append_data().
76901 */
76902@@ -909,12 +911,15 @@ do_confirm:
76903 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76904 char __user *optval, int optlen)
76905 {
76906+ struct icmp6_filter filter;
76907+
76908 switch (optname) {
76909 case ICMPV6_FILTER:
76910 if (optlen > sizeof(struct icmp6_filter))
76911 optlen = sizeof(struct icmp6_filter);
76912- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76913+ if (copy_from_user(&filter, optval, optlen))
76914 return -EFAULT;
76915+ memcpy(&raw6_sk(sk)->filter, &filter, optlen);
76916 return 0;
76917 default:
76918 return -ENOPROTOOPT;
76919@@ -926,6 +931,7 @@ static int rawv6_seticmpfilter(struct so
76920 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76921 char __user *optval, int __user *optlen)
76922 {
76923+ struct icmp6_filter filter;
76924 int len;
76925
76926 switch (optname) {
76927@@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
76928 len = sizeof(struct icmp6_filter);
76929 if (put_user(len, optlen))
76930 return -EFAULT;
76931- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76932+ memcpy(&filter, &raw6_sk(sk)->filter, len);
76933+ if (copy_to_user(optval, &filter, len))
76934 return -EFAULT;
76935 return 0;
76936 default:
76937@@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
76938 0, 0L, 0,
76939 sock_i_uid(sp), 0,
76940 sock_i_ino(sp),
76941- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76942+ atomic_read(&sp->sk_refcnt),
76943+#ifdef CONFIG_GRKERNSEC_HIDESYM
76944+ NULL,
76945+#else
76946+ sp,
76947+#endif
76948+ atomic_read_unchecked(&sp->sk_drops));
76949 }
76950
76951 static int raw6_seq_show(struct seq_file *seq, void *v)
76952diff -urNp linux-2.6.39.1/net/ipv6/tcp_ipv6.c linux-2.6.39.1/net/ipv6/tcp_ipv6.c
76953--- linux-2.6.39.1/net/ipv6/tcp_ipv6.c 2011-05-19 00:06:34.000000000 -0400
76954+++ linux-2.6.39.1/net/ipv6/tcp_ipv6.c 2011-05-22 19:41:42.000000000 -0400
76955@@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
76956 }
76957 #endif
76958
76959+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76960+extern int grsec_enable_blackhole;
76961+#endif
76962+
76963 static void tcp_v6_hash(struct sock *sk)
76964 {
76965 if (sk->sk_state != TCP_CLOSE) {
76966@@ -1660,6 +1664,9 @@ static int tcp_v6_do_rcv(struct sock *sk
76967 return 0;
76968
76969 reset:
76970+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76971+ if (!grsec_enable_blackhole)
76972+#endif
76973 tcp_v6_send_reset(sk, skb);
76974 discard:
76975 if (opt_skb)
76976@@ -1739,12 +1746,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
76977 TCP_SKB_CB(skb)->sacked = 0;
76978
76979 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76980- if (!sk)
76981+ if (!sk) {
76982+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76983+ ret = 1;
76984+#endif
76985 goto no_tcp_socket;
76986+ }
76987
76988 process:
76989- if (sk->sk_state == TCP_TIME_WAIT)
76990+ if (sk->sk_state == TCP_TIME_WAIT) {
76991+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76992+ ret = 2;
76993+#endif
76994 goto do_time_wait;
76995+ }
76996
76997 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76998 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76999@@ -1792,6 +1807,10 @@ no_tcp_socket:
77000 bad_packet:
77001 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77002 } else {
77003+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77004+ if (!grsec_enable_blackhole || (ret == 1 &&
77005+ (skb->dev->flags & IFF_LOOPBACK)))
77006+#endif
77007 tcp_v6_send_reset(NULL, skb);
77008 }
77009
77010@@ -2052,7 +2071,13 @@ static void get_openreq6(struct seq_file
77011 uid,
77012 0, /* non standard timer */
77013 0, /* open_requests have no inode */
77014- 0, req);
77015+ 0,
77016+#ifdef CONFIG_GRKERNSEC_HIDESYM
77017+ NULL
77018+#else
77019+ req
77020+#endif
77021+ );
77022 }
77023
77024 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77025@@ -2102,7 +2127,12 @@ static void get_tcp6_sock(struct seq_fil
77026 sock_i_uid(sp),
77027 icsk->icsk_probes_out,
77028 sock_i_ino(sp),
77029- atomic_read(&sp->sk_refcnt), sp,
77030+ atomic_read(&sp->sk_refcnt),
77031+#ifdef CONFIG_GRKERNSEC_HIDESYM
77032+ NULL,
77033+#else
77034+ sp,
77035+#endif
77036 jiffies_to_clock_t(icsk->icsk_rto),
77037 jiffies_to_clock_t(icsk->icsk_ack.ato),
77038 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77039@@ -2137,7 +2167,13 @@ static void get_timewait6_sock(struct se
77040 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77041 tw->tw_substate, 0, 0,
77042 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77043- atomic_read(&tw->tw_refcnt), tw);
77044+ atomic_read(&tw->tw_refcnt),
77045+#ifdef CONFIG_GRKERNSEC_HIDESYM
77046+ NULL
77047+#else
77048+ tw
77049+#endif
77050+ );
77051 }
77052
77053 static int tcp6_seq_show(struct seq_file *seq, void *v)
77054diff -urNp linux-2.6.39.1/net/ipv6/udp.c linux-2.6.39.1/net/ipv6/udp.c
77055--- linux-2.6.39.1/net/ipv6/udp.c 2011-05-19 00:06:34.000000000 -0400
77056+++ linux-2.6.39.1/net/ipv6/udp.c 2011-05-22 19:41:42.000000000 -0400
77057@@ -50,6 +50,10 @@
77058 #include <linux/seq_file.h>
77059 #include "udp_impl.h"
77060
77061+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77062+extern int grsec_enable_blackhole;
77063+#endif
77064+
77065 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77066 {
77067 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77068@@ -545,7 +549,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
77069
77070 return 0;
77071 drop:
77072- atomic_inc(&sk->sk_drops);
77073+ atomic_inc_unchecked(&sk->sk_drops);
77074 drop_no_sk_drops_inc:
77075 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77076 kfree_skb(skb);
77077@@ -621,7 +625,7 @@ static void flush_stack(struct sock **st
77078 continue;
77079 }
77080 drop:
77081- atomic_inc(&sk->sk_drops);
77082+ atomic_inc_unchecked(&sk->sk_drops);
77083 UDP6_INC_STATS_BH(sock_net(sk),
77084 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
77085 UDP6_INC_STATS_BH(sock_net(sk),
77086@@ -776,6 +780,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
77087 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
77088 proto == IPPROTO_UDPLITE);
77089
77090+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77091+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77092+#endif
77093 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77094
77095 kfree_skb(skb);
77096@@ -792,7 +799,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
77097 if (!sock_owned_by_user(sk))
77098 udpv6_queue_rcv_skb(sk, skb);
77099 else if (sk_add_backlog(sk, skb)) {
77100- atomic_inc(&sk->sk_drops);
77101+ atomic_inc_unchecked(&sk->sk_drops);
77102 bh_unlock_sock(sk);
77103 sock_put(sk);
77104 goto discard;
77105@@ -1403,8 +1410,13 @@ static void udp6_sock_seq_show(struct se
77106 0, 0L, 0,
77107 sock_i_uid(sp), 0,
77108 sock_i_ino(sp),
77109- atomic_read(&sp->sk_refcnt), sp,
77110- atomic_read(&sp->sk_drops));
77111+ atomic_read(&sp->sk_refcnt),
77112+#ifdef CONFIG_GRKERNSEC_HIDESYM
77113+ NULL,
77114+#else
77115+ sp,
77116+#endif
77117+ atomic_read_unchecked(&sp->sk_drops));
77118 }
77119
77120 int udp6_seq_show(struct seq_file *seq, void *v)
77121diff -urNp linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c
77122--- linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c 2011-05-19 00:06:34.000000000 -0400
77123+++ linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c 2011-05-22 19:36:34.000000000 -0400
77124@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
77125 add_wait_queue(&self->open_wait, &wait);
77126
77127 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77128- __FILE__,__LINE__, tty->driver->name, self->open_count );
77129+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77130
77131 /* As far as I can see, we protect open_count - Jean II */
77132 spin_lock_irqsave(&self->spinlock, flags);
77133 if (!tty_hung_up_p(filp)) {
77134 extra_count = 1;
77135- self->open_count--;
77136+ local_dec(&self->open_count);
77137 }
77138 spin_unlock_irqrestore(&self->spinlock, flags);
77139- self->blocked_open++;
77140+ local_inc(&self->blocked_open);
77141
77142 while (1) {
77143 if (tty->termios->c_cflag & CBAUD) {
77144@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
77145 }
77146
77147 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77148- __FILE__,__LINE__, tty->driver->name, self->open_count );
77149+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77150
77151 schedule();
77152 }
77153@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
77154 if (extra_count) {
77155 /* ++ is not atomic, so this should be protected - Jean II */
77156 spin_lock_irqsave(&self->spinlock, flags);
77157- self->open_count++;
77158+ local_inc(&self->open_count);
77159 spin_unlock_irqrestore(&self->spinlock, flags);
77160 }
77161- self->blocked_open--;
77162+ local_dec(&self->blocked_open);
77163
77164 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77165- __FILE__,__LINE__, tty->driver->name, self->open_count);
77166+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77167
77168 if (!retval)
77169 self->flags |= ASYNC_NORMAL_ACTIVE;
77170@@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
77171 }
77172 /* ++ is not atomic, so this should be protected - Jean II */
77173 spin_lock_irqsave(&self->spinlock, flags);
77174- self->open_count++;
77175+ local_inc(&self->open_count);
77176
77177 tty->driver_data = self;
77178 self->tty = tty;
77179 spin_unlock_irqrestore(&self->spinlock, flags);
77180
77181 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77182- self->line, self->open_count);
77183+ self->line, local_read(&self->open_count));
77184
77185 /* Not really used by us, but lets do it anyway */
77186 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77187@@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
77188 return;
77189 }
77190
77191- if ((tty->count == 1) && (self->open_count != 1)) {
77192+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77193 /*
77194 * Uh, oh. tty->count is 1, which means that the tty
77195 * structure will be freed. state->count should always
77196@@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
77197 */
77198 IRDA_DEBUG(0, "%s(), bad serial port count; "
77199 "tty->count is 1, state->count is %d\n", __func__ ,
77200- self->open_count);
77201- self->open_count = 1;
77202+ local_read(&self->open_count));
77203+ local_set(&self->open_count, 1);
77204 }
77205
77206- if (--self->open_count < 0) {
77207+ if (local_dec_return(&self->open_count) < 0) {
77208 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77209- __func__, self->line, self->open_count);
77210- self->open_count = 0;
77211+ __func__, self->line, local_read(&self->open_count));
77212+ local_set(&self->open_count, 0);
77213 }
77214- if (self->open_count) {
77215+ if (local_read(&self->open_count)) {
77216 spin_unlock_irqrestore(&self->spinlock, flags);
77217
77218 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77219@@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
77220 tty->closing = 0;
77221 self->tty = NULL;
77222
77223- if (self->blocked_open) {
77224+ if (local_read(&self->blocked_open)) {
77225 if (self->close_delay)
77226 schedule_timeout_interruptible(self->close_delay);
77227 wake_up_interruptible(&self->open_wait);
77228@@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
77229 spin_lock_irqsave(&self->spinlock, flags);
77230 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77231 self->tty = NULL;
77232- self->open_count = 0;
77233+ local_set(&self->open_count, 0);
77234 spin_unlock_irqrestore(&self->spinlock, flags);
77235
77236 wake_up_interruptible(&self->open_wait);
77237@@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
77238 seq_putc(m, '\n');
77239
77240 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77241- seq_printf(m, "Open count: %d\n", self->open_count);
77242+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77243 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77244 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77245
77246diff -urNp linux-2.6.39.1/net/iucv/af_iucv.c linux-2.6.39.1/net/iucv/af_iucv.c
77247--- linux-2.6.39.1/net/iucv/af_iucv.c 2011-05-19 00:06:34.000000000 -0400
77248+++ linux-2.6.39.1/net/iucv/af_iucv.c 2011-05-22 19:36:34.000000000 -0400
77249@@ -653,10 +653,10 @@ static int iucv_sock_autobind(struct soc
77250
77251 write_lock_bh(&iucv_sk_list.lock);
77252
77253- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77254+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77255 while (__iucv_get_sock_by_name(name)) {
77256 sprintf(name, "%08x",
77257- atomic_inc_return(&iucv_sk_list.autobind_name));
77258+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77259 }
77260
77261 write_unlock_bh(&iucv_sk_list.lock);
77262diff -urNp linux-2.6.39.1/net/key/af_key.c linux-2.6.39.1/net/key/af_key.c
77263--- linux-2.6.39.1/net/key/af_key.c 2011-05-19 00:06:34.000000000 -0400
77264+++ linux-2.6.39.1/net/key/af_key.c 2011-05-22 19:41:42.000000000 -0400
77265@@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
77266 struct xfrm_migrate m[XFRM_MAX_DEPTH];
77267 struct xfrm_kmaddress k;
77268
77269+ pax_track_stack();
77270+
77271 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
77272 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
77273 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
77274@@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
77275 static u32 get_acqseq(void)
77276 {
77277 u32 res;
77278- static atomic_t acqseq;
77279+ static atomic_unchecked_t acqseq;
77280
77281 do {
77282- res = atomic_inc_return(&acqseq);
77283+ res = atomic_inc_return_unchecked(&acqseq);
77284 } while (!res);
77285 return res;
77286 }
77287@@ -3657,7 +3659,11 @@ static int pfkey_seq_show(struct seq_fil
77288 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
77289 else
77290 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
77291+#ifdef CONFIG_GRKERNSEC_HIDESYM
77292+ NULL,
77293+#else
77294 s,
77295+#endif
77296 atomic_read(&s->sk_refcnt),
77297 sk_rmem_alloc_get(s),
77298 sk_wmem_alloc_get(s),
77299diff -urNp linux-2.6.39.1/net/l2tp/l2tp_ip.c linux-2.6.39.1/net/l2tp/l2tp_ip.c
77300--- linux-2.6.39.1/net/l2tp/l2tp_ip.c 2011-05-19 00:06:34.000000000 -0400
77301+++ linux-2.6.39.1/net/l2tp/l2tp_ip.c 2011-05-22 19:36:34.000000000 -0400
77302@@ -625,7 +625,7 @@ static struct inet_protosw l2tp_ip_proto
77303 .no_check = 0,
77304 };
77305
77306-static struct net_protocol l2tp_ip_protocol __read_mostly = {
77307+static const struct net_protocol l2tp_ip_protocol = {
77308 .handler = l2tp_ip_recv,
77309 };
77310
77311diff -urNp linux-2.6.39.1/net/lapb/lapb_iface.c linux-2.6.39.1/net/lapb/lapb_iface.c
77312--- linux-2.6.39.1/net/lapb/lapb_iface.c 2011-05-19 00:06:34.000000000 -0400
77313+++ linux-2.6.39.1/net/lapb/lapb_iface.c 2011-05-22 19:36:34.000000000 -0400
77314@@ -138,8 +138,7 @@ static struct lapb_cb *lapb_create_cb(vo
77315 out:
77316 return lapb;
77317 }
77318-
77319-int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks)
77320+int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks)
77321 {
77322 struct lapb_cb *lapb;
77323 int rc = LAPB_BADTOKEN;
77324diff -urNp linux-2.6.39.1/net/mac80211/cfg.c linux-2.6.39.1/net/mac80211/cfg.c
77325--- linux-2.6.39.1/net/mac80211/cfg.c 2011-06-03 00:04:14.000000000 -0400
77326+++ linux-2.6.39.1/net/mac80211/cfg.c 2011-06-03 00:32:08.000000000 -0400
77327@@ -2031,7 +2031,7 @@ static void ieee80211_get_ringparam(stru
77328 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
77329 }
77330
77331-struct cfg80211_ops mac80211_config_ops = {
77332+const struct cfg80211_ops mac80211_config_ops = {
77333 .add_virtual_intf = ieee80211_add_iface,
77334 .del_virtual_intf = ieee80211_del_iface,
77335 .change_virtual_intf = ieee80211_change_iface,
77336diff -urNp linux-2.6.39.1/net/mac80211/cfg.h linux-2.6.39.1/net/mac80211/cfg.h
77337--- linux-2.6.39.1/net/mac80211/cfg.h 2011-05-19 00:06:34.000000000 -0400
77338+++ linux-2.6.39.1/net/mac80211/cfg.h 2011-05-22 19:36:34.000000000 -0400
77339@@ -4,6 +4,6 @@
77340 #ifndef __CFG_H
77341 #define __CFG_H
77342
77343-extern struct cfg80211_ops mac80211_config_ops;
77344+extern const struct cfg80211_ops mac80211_config_ops;
77345
77346 #endif /* __CFG_H */
77347diff -urNp linux-2.6.39.1/net/mac80211/debugfs_sta.c linux-2.6.39.1/net/mac80211/debugfs_sta.c
77348--- linux-2.6.39.1/net/mac80211/debugfs_sta.c 2011-05-19 00:06:34.000000000 -0400
77349+++ linux-2.6.39.1/net/mac80211/debugfs_sta.c 2011-05-22 19:36:34.000000000 -0400
77350@@ -115,6 +115,8 @@ static ssize_t sta_agg_status_read(struc
77351 struct tid_ampdu_rx *tid_rx;
77352 struct tid_ampdu_tx *tid_tx;
77353
77354+ pax_track_stack();
77355+
77356 rcu_read_lock();
77357
77358 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
77359@@ -215,6 +217,8 @@ static ssize_t sta_ht_capa_read(struct f
77360 struct sta_info *sta = file->private_data;
77361 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
77362
77363+ pax_track_stack();
77364+
77365 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
77366 htc->ht_supported ? "" : "not ");
77367 if (htc->ht_supported) {
77368diff -urNp linux-2.6.39.1/net/mac80211/ieee80211_i.h linux-2.6.39.1/net/mac80211/ieee80211_i.h
77369--- linux-2.6.39.1/net/mac80211/ieee80211_i.h 2011-05-19 00:06:34.000000000 -0400
77370+++ linux-2.6.39.1/net/mac80211/ieee80211_i.h 2011-05-22 19:36:34.000000000 -0400
77371@@ -27,6 +27,7 @@
77372 #include <net/ieee80211_radiotap.h>
77373 #include <net/cfg80211.h>
77374 #include <net/mac80211.h>
77375+#include <asm/local.h>
77376 #include "key.h"
77377 #include "sta_info.h"
77378
77379@@ -714,7 +715,7 @@ struct ieee80211_local {
77380 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77381 spinlock_t queue_stop_reason_lock;
77382
77383- int open_count;
77384+ local_t open_count;
77385 int monitors, cooked_mntrs;
77386 /* number of interfaces with corresponding FIF_ flags */
77387 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77388diff -urNp linux-2.6.39.1/net/mac80211/iface.c linux-2.6.39.1/net/mac80211/iface.c
77389--- linux-2.6.39.1/net/mac80211/iface.c 2011-05-19 00:06:34.000000000 -0400
77390+++ linux-2.6.39.1/net/mac80211/iface.c 2011-05-22 19:36:34.000000000 -0400
77391@@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
77392 break;
77393 }
77394
77395- if (local->open_count == 0) {
77396+ if (local_read(&local->open_count) == 0) {
77397 res = drv_start(local);
77398 if (res)
77399 goto err_del_bss;
77400@@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
77401 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77402
77403 if (!is_valid_ether_addr(dev->dev_addr)) {
77404- if (!local->open_count)
77405+ if (!local_read(&local->open_count))
77406 drv_stop(local);
77407 return -EADDRNOTAVAIL;
77408 }
77409@@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
77410 mutex_unlock(&local->mtx);
77411
77412 if (coming_up)
77413- local->open_count++;
77414+ local_inc(&local->open_count);
77415
77416 if (hw_reconf_flags) {
77417 ieee80211_hw_config(local, hw_reconf_flags);
77418@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
77419 err_del_interface:
77420 drv_remove_interface(local, &sdata->vif);
77421 err_stop:
77422- if (!local->open_count)
77423+ if (!local_read(&local->open_count))
77424 drv_stop(local);
77425 err_del_bss:
77426 sdata->bss = NULL;
77427@@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct iee
77428 }
77429
77430 if (going_down)
77431- local->open_count--;
77432+ local_dec(&local->open_count);
77433
77434 switch (sdata->vif.type) {
77435 case NL80211_IFTYPE_AP_VLAN:
77436@@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct iee
77437
77438 ieee80211_recalc_ps(local, -1);
77439
77440- if (local->open_count == 0) {
77441+ if (local_read(&local->open_count) == 0) {
77442 if (local->ops->napi_poll)
77443 napi_disable(&local->napi);
77444 ieee80211_clear_tx_pending(local);
77445diff -urNp linux-2.6.39.1/net/mac80211/main.c linux-2.6.39.1/net/mac80211/main.c
77446--- linux-2.6.39.1/net/mac80211/main.c 2011-05-19 00:06:34.000000000 -0400
77447+++ linux-2.6.39.1/net/mac80211/main.c 2011-05-22 19:36:34.000000000 -0400
77448@@ -215,7 +215,7 @@ int ieee80211_hw_config(struct ieee80211
77449 local->hw.conf.power_level = power;
77450 }
77451
77452- if (changed && local->open_count) {
77453+ if (changed && local_read(&local->open_count)) {
77454 ret = drv_config(local, changed);
77455 /*
77456 * Goal:
77457diff -urNp linux-2.6.39.1/net/mac80211/mlme.c linux-2.6.39.1/net/mac80211/mlme.c
77458--- linux-2.6.39.1/net/mac80211/mlme.c 2011-06-03 00:04:14.000000000 -0400
77459+++ linux-2.6.39.1/net/mac80211/mlme.c 2011-06-03 00:32:08.000000000 -0400
77460@@ -1431,6 +1431,8 @@ static bool ieee80211_assoc_success(stru
77461 bool have_higher_than_11mbit = false;
77462 u16 ap_ht_cap_flags;
77463
77464+ pax_track_stack();
77465+
77466 /* AssocResp and ReassocResp have identical structure */
77467
77468 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
77469diff -urNp linux-2.6.39.1/net/mac80211/pm.c linux-2.6.39.1/net/mac80211/pm.c
77470--- linux-2.6.39.1/net/mac80211/pm.c 2011-05-19 00:06:34.000000000 -0400
77471+++ linux-2.6.39.1/net/mac80211/pm.c 2011-05-22 19:36:34.000000000 -0400
77472@@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
77473 }
77474
77475 /* stop hardware - this must stop RX */
77476- if (local->open_count)
77477+ if (local_read(&local->open_count))
77478 ieee80211_stop_device(local);
77479
77480 local->suspended = true;
77481diff -urNp linux-2.6.39.1/net/mac80211/rate.c linux-2.6.39.1/net/mac80211/rate.c
77482--- linux-2.6.39.1/net/mac80211/rate.c 2011-05-19 00:06:34.000000000 -0400
77483+++ linux-2.6.39.1/net/mac80211/rate.c 2011-05-22 19:36:34.000000000 -0400
77484@@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
77485
77486 ASSERT_RTNL();
77487
77488- if (local->open_count)
77489+ if (local_read(&local->open_count))
77490 return -EBUSY;
77491
77492 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77493diff -urNp linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c
77494--- linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c 2011-05-19 00:06:34.000000000 -0400
77495+++ linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c 2011-05-22 19:36:34.000000000 -0400
77496@@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
77497
77498 spin_unlock_irqrestore(&events->lock, status);
77499
77500- if (copy_to_user(buf, pb, p))
77501+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77502 return -EFAULT;
77503
77504 return p;
77505diff -urNp linux-2.6.39.1/net/mac80211/util.c linux-2.6.39.1/net/mac80211/util.c
77506--- linux-2.6.39.1/net/mac80211/util.c 2011-05-19 00:06:34.000000000 -0400
77507+++ linux-2.6.39.1/net/mac80211/util.c 2011-05-22 19:36:34.000000000 -0400
77508@@ -1129,7 +1129,7 @@ int ieee80211_reconfig(struct ieee80211_
77509 local->resuming = true;
77510
77511 /* restart hardware */
77512- if (local->open_count) {
77513+ if (local_read(&local->open_count)) {
77514 /*
77515 * Upon resume hardware can sometimes be goofy due to
77516 * various platform / driver / bus issues, so restarting
77517diff -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
77518--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c 2011-05-19 00:06:34.000000000 -0400
77519+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c 2011-05-22 19:36:34.000000000 -0400
77520@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
77521 /* Increase the refcnt counter of the dest */
77522 atomic_inc(&dest->refcnt);
77523
77524- conn_flags = atomic_read(&dest->conn_flags);
77525+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77526 if (cp->protocol != IPPROTO_UDP)
77527 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77528 /* Bind with the destination and its corresponding transmitter */
77529@@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
77530 atomic_set(&cp->refcnt, 1);
77531
77532 atomic_set(&cp->n_control, 0);
77533- atomic_set(&cp->in_pkts, 0);
77534+ atomic_set_unchecked(&cp->in_pkts, 0);
77535
77536 atomic_inc(&ipvs->conn_count);
77537 if (flags & IP_VS_CONN_F_NO_CPORT)
77538@@ -1141,7 +1141,7 @@ static inline int todrop_entry(struct ip
77539
77540 /* Don't drop the entry if its number of incoming packets is not
77541 located in [0, 8] */
77542- i = atomic_read(&cp->in_pkts);
77543+ i = atomic_read_unchecked(&cp->in_pkts);
77544 if (i > 8 || i < 0) return 0;
77545
77546 if (!todrop_rate[i]) return 0;
77547diff -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
77548--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c 2011-05-19 00:06:34.000000000 -0400
77549+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c 2011-05-22 19:36:34.000000000 -0400
77550@@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
77551 ret = cp->packet_xmit(skb, cp, pd->pp);
77552 /* do not touch skb anymore */
77553
77554- atomic_inc(&cp->in_pkts);
77555+ atomic_inc_unchecked(&cp->in_pkts);
77556 ip_vs_conn_put(cp);
77557 return ret;
77558 }
77559@@ -1633,7 +1633,7 @@ ip_vs_in(unsigned int hooknum, struct sk
77560 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77561 pkts = sysctl_sync_threshold(ipvs);
77562 else
77563- pkts = atomic_add_return(1, &cp->in_pkts);
77564+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77565
77566 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77567 cp->protocol == IPPROTO_SCTP) {
77568diff -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
77569--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-19 00:06:34.000000000 -0400
77570+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-22 19:36:34.000000000 -0400
77571@@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
77572 ip_vs_rs_hash(ipvs, dest);
77573 write_unlock_bh(&ipvs->rs_lock);
77574 }
77575- atomic_set(&dest->conn_flags, conn_flags);
77576+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77577
77578 /* bind the service */
77579 if (!dest->svc) {
77580@@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
77581 " %-7s %-6d %-10d %-10d\n",
77582 &dest->addr.in6,
77583 ntohs(dest->port),
77584- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77585+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77586 atomic_read(&dest->weight),
77587 atomic_read(&dest->activeconns),
77588 atomic_read(&dest->inactconns));
77589@@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
77590 "%-7s %-6d %-10d %-10d\n",
77591 ntohl(dest->addr.ip),
77592 ntohs(dest->port),
77593- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77594+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77595 atomic_read(&dest->weight),
77596 atomic_read(&dest->activeconns),
77597 atomic_read(&dest->inactconns));
77598@@ -2287,6 +2287,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
77599 struct ip_vs_dest_user *udest_compat;
77600 struct ip_vs_dest_user_kern udest;
77601
77602+ pax_track_stack();
77603+
77604 if (!capable(CAP_NET_ADMIN))
77605 return -EPERM;
77606
77607@@ -2501,7 +2503,7 @@ __ip_vs_get_dest_entries(struct net *net
77608
77609 entry.addr = dest->addr.ip;
77610 entry.port = dest->port;
77611- entry.conn_flags = atomic_read(&dest->conn_flags);
77612+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77613 entry.weight = atomic_read(&dest->weight);
77614 entry.u_threshold = dest->u_threshold;
77615 entry.l_threshold = dest->l_threshold;
77616@@ -3029,7 +3031,7 @@ static int ip_vs_genl_fill_dest(struct s
77617 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77618
77619 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77620- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77621+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77622 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77623 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77624 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77625diff -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
77626--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c 2011-05-19 00:06:34.000000000 -0400
77627+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c 2011-05-22 19:36:34.000000000 -0400
77628@@ -648,7 +648,7 @@ control:
77629 * i.e only increment in_pkts for Templates.
77630 */
77631 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77632- int pkts = atomic_add_return(1, &cp->in_pkts);
77633+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77634
77635 if (pkts % sysctl_sync_period(ipvs) != 1)
77636 return;
77637@@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
77638
77639 if (opt)
77640 memcpy(&cp->in_seq, opt, sizeof(*opt));
77641- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77642+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77643 cp->state = state;
77644 cp->old_state = cp->state;
77645 /*
77646diff -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
77647--- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-19 00:06:34.000000000 -0400
77648+++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-22 19:36:34.000000000 -0400
77649@@ -1127,7 +1127,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
77650 else
77651 rc = NF_ACCEPT;
77652 /* do not touch skb anymore */
77653- atomic_inc(&cp->in_pkts);
77654+ atomic_inc_unchecked(&cp->in_pkts);
77655 goto out;
77656 }
77657
77658@@ -1245,7 +1245,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
77659 else
77660 rc = NF_ACCEPT;
77661 /* do not touch skb anymore */
77662- atomic_inc(&cp->in_pkts);
77663+ atomic_inc_unchecked(&cp->in_pkts);
77664 goto out;
77665 }
77666
77667diff -urNp linux-2.6.39.1/net/netfilter/Kconfig linux-2.6.39.1/net/netfilter/Kconfig
77668--- linux-2.6.39.1/net/netfilter/Kconfig 2011-05-19 00:06:34.000000000 -0400
77669+++ linux-2.6.39.1/net/netfilter/Kconfig 2011-05-22 19:41:42.000000000 -0400
77670@@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
77671
77672 To compile it as a module, choose M here. If unsure, say N.
77673
77674+config NETFILTER_XT_MATCH_GRADM
77675+ tristate '"gradm" match support'
77676+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77677+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77678+ ---help---
77679+ The gradm match allows to match on grsecurity RBAC being enabled.
77680+ It is useful when iptables rules are applied early on bootup to
77681+ prevent connections to the machine (except from a trusted host)
77682+ while the RBAC system is disabled.
77683+
77684 config NETFILTER_XT_MATCH_HASHLIMIT
77685 tristate '"hashlimit" match support'
77686 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77687diff -urNp linux-2.6.39.1/net/netfilter/Makefile linux-2.6.39.1/net/netfilter/Makefile
77688--- linux-2.6.39.1/net/netfilter/Makefile 2011-05-19 00:06:34.000000000 -0400
77689+++ linux-2.6.39.1/net/netfilter/Makefile 2011-05-22 20:40:16.000000000 -0400
77690@@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
77691 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77692 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77693 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77694+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77695 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77696 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77697 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77698diff -urNp linux-2.6.39.1/net/netfilter/nfnetlink_log.c linux-2.6.39.1/net/netfilter/nfnetlink_log.c
77699--- linux-2.6.39.1/net/netfilter/nfnetlink_log.c 2011-05-19 00:06:34.000000000 -0400
77700+++ linux-2.6.39.1/net/netfilter/nfnetlink_log.c 2011-05-22 19:36:35.000000000 -0400
77701@@ -70,7 +70,7 @@ struct nfulnl_instance {
77702 };
77703
77704 static DEFINE_SPINLOCK(instances_lock);
77705-static atomic_t global_seq;
77706+static atomic_unchecked_t global_seq;
77707
77708 #define INSTANCE_BUCKETS 16
77709 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77710@@ -506,7 +506,7 @@ __build_packet_message(struct nfulnl_ins
77711 /* global sequence number */
77712 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77713 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77714- htonl(atomic_inc_return(&global_seq)));
77715+ htonl(atomic_inc_return_unchecked(&global_seq)));
77716
77717 if (data_len) {
77718 struct nlattr *nla;
77719diff -urNp linux-2.6.39.1/net/netfilter/nfnetlink_queue.c linux-2.6.39.1/net/netfilter/nfnetlink_queue.c
77720--- linux-2.6.39.1/net/netfilter/nfnetlink_queue.c 2011-05-19 00:06:34.000000000 -0400
77721+++ linux-2.6.39.1/net/netfilter/nfnetlink_queue.c 2011-05-22 19:36:35.000000000 -0400
77722@@ -58,7 +58,7 @@ struct nfqnl_instance {
77723 */
77724 spinlock_t lock;
77725 unsigned int queue_total;
77726- atomic_t id_sequence; /* 'sequence' of pkt ids */
77727+ atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
77728 struct list_head queue_list; /* packets in queue */
77729 };
77730
77731@@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
77732 nfmsg->version = NFNETLINK_V0;
77733 nfmsg->res_id = htons(queue->queue_num);
77734
77735- entry->id = atomic_inc_return(&queue->id_sequence);
77736+ entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
77737 pmsg.packet_id = htonl(entry->id);
77738 pmsg.hw_protocol = entskb->protocol;
77739 pmsg.hook = entry->hook;
77740@@ -869,7 +869,7 @@ static int seq_show(struct seq_file *s,
77741 inst->peer_pid, inst->queue_total,
77742 inst->copy_mode, inst->copy_range,
77743 inst->queue_dropped, inst->queue_user_dropped,
77744- atomic_read(&inst->id_sequence), 1);
77745+ atomic_read_unchecked(&inst->id_sequence), 1);
77746 }
77747
77748 static const struct seq_operations nfqnl_seq_ops = {
77749diff -urNp linux-2.6.39.1/net/netfilter/xt_gradm.c linux-2.6.39.1/net/netfilter/xt_gradm.c
77750--- linux-2.6.39.1/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
77751+++ linux-2.6.39.1/net/netfilter/xt_gradm.c 2011-05-22 19:41:42.000000000 -0400
77752@@ -0,0 +1,51 @@
77753+/*
77754+ * gradm match for netfilter
77755