]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-2.6.39.1-201106032238.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.39.1-201106032238.patch
1 diff -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 }
16 diff -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
33 diff -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))
54 diff -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,
66 diff -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,
78 diff -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,
90 diff -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,
102 diff -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,
114 diff -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,
126 diff -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,
138 diff -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,
150 diff -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,
162 diff -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,
174 diff -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,
186 diff -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++) {
198 diff -urNp linux-2.6.39.1/arch/alpha/kernel/osf_sys.c linux-2.6.39.1/arch/alpha/kernel/osf_sys.c
199 --- linux-2.6.39.1/arch/alpha/kernel/osf_sys.c 2011-05-19 00:06:34.000000000 -0400
200 +++ linux-2.6.39.1/arch/alpha/kernel/osf_sys.c 2011-05-22 19:36:30.000000000 -0400
201 @@ -1142,7 +1142,7 @@ arch_get_unmapped_area_1(unsigned long a
202 /* At this point: (!vma || addr < vma->vm_end). */
203 if (limit - len < addr)
204 return -ENOMEM;
205 - if (!vma || addr + len <= vma->vm_start)
206 + if (check_heap_stack_gap(vma, addr, len))
207 return addr;
208 addr = vma->vm_end;
209 vma = vma->vm_next;
210 @@ -1178,6 +1178,10 @@ arch_get_unmapped_area(struct file *filp
211 merely specific addresses, but regions of memory -- perhaps
212 this feature should be incorporated into all ports? */
213
214 +#ifdef CONFIG_PAX_RANDMMAP
215 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
216 +#endif
217 +
218 if (addr) {
219 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
220 if (addr != (unsigned long) -ENOMEM)
221 @@ -1185,8 +1189,8 @@ arch_get_unmapped_area(struct file *filp
222 }
223
224 /* Next, try allocating at TASK_UNMAPPED_BASE. */
225 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
226 - len, limit);
227 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
228 +
229 if (addr != (unsigned long) -ENOMEM)
230 return addr;
231
232 diff -urNp linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c
233 --- linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c 2011-05-19 00:06:34.000000000 -0400
234 +++ linux-2.6.39.1/arch/alpha/kernel/pci_iommu.c 2011-05-22 19:36:30.000000000 -0400
235 @@ -950,7 +950,7 @@ static int alpha_pci_set_mask(struct dev
236 return 0;
237 }
238
239 -struct dma_map_ops alpha_pci_ops = {
240 +const struct dma_map_ops alpha_pci_ops = {
241 .alloc_coherent = alpha_pci_alloc_coherent,
242 .free_coherent = alpha_pci_free_coherent,
243 .map_page = alpha_pci_map_page,
244 @@ -962,5 +962,5 @@ struct dma_map_ops alpha_pci_ops = {
245 .set_dma_mask = alpha_pci_set_mask,
246 };
247
248 -struct dma_map_ops *dma_ops = &alpha_pci_ops;
249 +const struct dma_map_ops *dma_ops = &alpha_pci_ops;
250 EXPORT_SYMBOL(dma_ops);
251 diff -urNp linux-2.6.39.1/arch/alpha/kernel/pci-noop.c linux-2.6.39.1/arch/alpha/kernel/pci-noop.c
252 --- linux-2.6.39.1/arch/alpha/kernel/pci-noop.c 2011-05-19 00:06:34.000000000 -0400
253 +++ linux-2.6.39.1/arch/alpha/kernel/pci-noop.c 2011-05-22 19:36:30.000000000 -0400
254 @@ -173,7 +173,7 @@ static int alpha_noop_set_mask(struct de
255 return 0;
256 }
257
258 -struct dma_map_ops alpha_noop_ops = {
259 +const struct dma_map_ops alpha_noop_ops = {
260 .alloc_coherent = alpha_noop_alloc_coherent,
261 .free_coherent = alpha_noop_free_coherent,
262 .map_page = alpha_noop_map_page,
263 @@ -183,7 +183,7 @@ struct dma_map_ops alpha_noop_ops = {
264 .set_dma_mask = alpha_noop_set_mask,
265 };
266
267 -struct dma_map_ops *dma_ops = &alpha_noop_ops;
268 +const struct dma_map_ops *dma_ops = &alpha_noop_ops;
269 EXPORT_SYMBOL(dma_ops);
270
271 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
272 diff -urNp linux-2.6.39.1/arch/alpha/kernel/proto.h linux-2.6.39.1/arch/alpha/kernel/proto.h
273 --- linux-2.6.39.1/arch/alpha/kernel/proto.h 2011-05-19 00:06:34.000000000 -0400
274 +++ linux-2.6.39.1/arch/alpha/kernel/proto.h 2011-05-22 19:36:30.000000000 -0400
275 @@ -17,14 +17,14 @@ struct pci_dev;
276 struct pci_controller;
277
278 /* core_apecs.c */
279 -extern struct pci_ops apecs_pci_ops;
280 +extern const struct pci_ops apecs_pci_ops;
281 extern void apecs_init_arch(void);
282 extern void apecs_pci_clr_err(void);
283 extern void apecs_machine_check(unsigned long vector, unsigned long la_ptr);
284 extern void apecs_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
285
286 /* core_cia.c */
287 -extern struct pci_ops cia_pci_ops;
288 +extern const struct pci_ops cia_pci_ops;
289 extern void cia_init_pci(void);
290 extern void cia_init_arch(void);
291 extern void pyxis_init_arch(void);
292 @@ -33,19 +33,19 @@ extern void cia_machine_check(unsigned l
293 extern void cia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
294
295 /* core_irongate.c */
296 -extern struct pci_ops irongate_pci_ops;
297 +extern const struct pci_ops irongate_pci_ops;
298 extern int irongate_pci_clr_err(void);
299 extern void irongate_init_arch(void);
300 #define irongate_pci_tbi ((void *)0)
301
302 /* core_lca.c */
303 -extern struct pci_ops lca_pci_ops;
304 +extern const struct pci_ops lca_pci_ops;
305 extern void lca_init_arch(void);
306 extern void lca_machine_check(unsigned long vector, unsigned long la_ptr);
307 extern void lca_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
308
309 /* core_marvel.c */
310 -extern struct pci_ops marvel_pci_ops;
311 +extern const struct pci_ops marvel_pci_ops;
312 extern void marvel_init_arch(void);
313 extern void marvel_kill_arch(int);
314 extern void marvel_machine_check(unsigned long, unsigned long);
315 @@ -60,14 +60,14 @@ struct io7 *marvel_next_io7(struct io7 *
316 void io7_clear_errors(struct io7 *io7);
317
318 /* core_mcpcia.c */
319 -extern struct pci_ops mcpcia_pci_ops;
320 +extern const struct pci_ops mcpcia_pci_ops;
321 extern void mcpcia_init_arch(void);
322 extern void mcpcia_init_hoses(void);
323 extern void mcpcia_machine_check(unsigned long vector, unsigned long la_ptr);
324 extern void mcpcia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
325
326 /* core_polaris.c */
327 -extern struct pci_ops polaris_pci_ops;
328 +extern const struct pci_ops polaris_pci_ops;
329 extern int polaris_read_config_dword(struct pci_dev *, int, u32 *);
330 extern int polaris_write_config_dword(struct pci_dev *, int, u32);
331 extern void polaris_init_arch(void);
332 @@ -75,14 +75,14 @@ extern void polaris_machine_check(unsign
333 #define polaris_pci_tbi ((void *)0)
334
335 /* core_t2.c */
336 -extern struct pci_ops t2_pci_ops;
337 +extern const struct pci_ops t2_pci_ops;
338 extern void t2_init_arch(void);
339 extern void t2_kill_arch(int);
340 extern void t2_machine_check(unsigned long vector, unsigned long la_ptr);
341 extern void t2_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
342
343 /* core_titan.c */
344 -extern struct pci_ops titan_pci_ops;
345 +extern const struct pci_ops titan_pci_ops;
346 extern void titan_init_arch(void);
347 extern void titan_kill_arch(int);
348 extern void titan_machine_check(unsigned long, unsigned long);
349 @@ -90,14 +90,14 @@ extern void titan_pci_tbi(struct pci_con
350 extern struct _alpha_agp_info *titan_agp_info(void);
351
352 /* core_tsunami.c */
353 -extern struct pci_ops tsunami_pci_ops;
354 +extern const struct pci_ops tsunami_pci_ops;
355 extern void tsunami_init_arch(void);
356 extern void tsunami_kill_arch(int);
357 extern void tsunami_machine_check(unsigned long vector, unsigned long la_ptr);
358 extern void tsunami_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
359
360 /* core_wildfire.c */
361 -extern struct pci_ops wildfire_pci_ops;
362 +extern const struct pci_ops wildfire_pci_ops;
363 extern void wildfire_init_arch(void);
364 extern void wildfire_kill_arch(int);
365 extern void wildfire_machine_check(unsigned long vector, unsigned long la_ptr);
366 diff -urNp linux-2.6.39.1/arch/alpha/mm/fault.c linux-2.6.39.1/arch/alpha/mm/fault.c
367 --- linux-2.6.39.1/arch/alpha/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
368 +++ linux-2.6.39.1/arch/alpha/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
369 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
370 __reload_thread(pcb);
371 }
372
373 +#ifdef CONFIG_PAX_PAGEEXEC
374 +/*
375 + * PaX: decide what to do with offenders (regs->pc = fault address)
376 + *
377 + * returns 1 when task should be killed
378 + * 2 when patched PLT trampoline was detected
379 + * 3 when unpatched PLT trampoline was detected
380 + */
381 +static int pax_handle_fetch_fault(struct pt_regs *regs)
382 +{
383 +
384 +#ifdef CONFIG_PAX_EMUPLT
385 + int err;
386 +
387 + do { /* PaX: patched PLT emulation #1 */
388 + unsigned int ldah, ldq, jmp;
389 +
390 + err = get_user(ldah, (unsigned int *)regs->pc);
391 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
392 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
393 +
394 + if (err)
395 + break;
396 +
397 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
398 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
399 + jmp == 0x6BFB0000U)
400 + {
401 + unsigned long r27, addr;
402 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
403 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
404 +
405 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
406 + err = get_user(r27, (unsigned long *)addr);
407 + if (err)
408 + break;
409 +
410 + regs->r27 = r27;
411 + regs->pc = r27;
412 + return 2;
413 + }
414 + } while (0);
415 +
416 + do { /* PaX: patched PLT emulation #2 */
417 + unsigned int ldah, lda, br;
418 +
419 + err = get_user(ldah, (unsigned int *)regs->pc);
420 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
421 + err |= get_user(br, (unsigned int *)(regs->pc+8));
422 +
423 + if (err)
424 + break;
425 +
426 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
427 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
428 + (br & 0xFFE00000U) == 0xC3E00000U)
429 + {
430 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
431 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
432 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
433 +
434 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
435 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
436 + return 2;
437 + }
438 + } while (0);
439 +
440 + do { /* PaX: unpatched PLT emulation */
441 + unsigned int br;
442 +
443 + err = get_user(br, (unsigned int *)regs->pc);
444 +
445 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
446 + unsigned int br2, ldq, nop, jmp;
447 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
448 +
449 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
450 + err = get_user(br2, (unsigned int *)addr);
451 + err |= get_user(ldq, (unsigned int *)(addr+4));
452 + err |= get_user(nop, (unsigned int *)(addr+8));
453 + err |= get_user(jmp, (unsigned int *)(addr+12));
454 + err |= get_user(resolver, (unsigned long *)(addr+16));
455 +
456 + if (err)
457 + break;
458 +
459 + if (br2 == 0xC3600000U &&
460 + ldq == 0xA77B000CU &&
461 + nop == 0x47FF041FU &&
462 + jmp == 0x6B7B0000U)
463 + {
464 + regs->r28 = regs->pc+4;
465 + regs->r27 = addr+16;
466 + regs->pc = resolver;
467 + return 3;
468 + }
469 + }
470 + } while (0);
471 +#endif
472 +
473 + return 1;
474 +}
475 +
476 +void pax_report_insns(void *pc, void *sp)
477 +{
478 + unsigned long i;
479 +
480 + printk(KERN_ERR "PAX: bytes at PC: ");
481 + for (i = 0; i < 5; i++) {
482 + unsigned int c;
483 + if (get_user(c, (unsigned int *)pc+i))
484 + printk(KERN_CONT "???????? ");
485 + else
486 + printk(KERN_CONT "%08x ", c);
487 + }
488 + printk("\n");
489 +}
490 +#endif
491
492 /*
493 * This routine handles page faults. It determines the address,
494 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
495 good_area:
496 si_code = SEGV_ACCERR;
497 if (cause < 0) {
498 - if (!(vma->vm_flags & VM_EXEC))
499 + if (!(vma->vm_flags & VM_EXEC)) {
500 +
501 +#ifdef CONFIG_PAX_PAGEEXEC
502 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
503 + goto bad_area;
504 +
505 + up_read(&mm->mmap_sem);
506 + switch (pax_handle_fetch_fault(regs)) {
507 +
508 +#ifdef CONFIG_PAX_EMUPLT
509 + case 2:
510 + case 3:
511 + return;
512 +#endif
513 +
514 + }
515 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
516 + do_group_exit(SIGKILL);
517 +#else
518 goto bad_area;
519 +#endif
520 +
521 + }
522 } else if (!cause) {
523 /* Allow reads even for write-only mappings */
524 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
525 diff -urNp linux-2.6.39.1/arch/arm/common/it8152.c linux-2.6.39.1/arch/arm/common/it8152.c
526 --- linux-2.6.39.1/arch/arm/common/it8152.c 2011-05-19 00:06:34.000000000 -0400
527 +++ linux-2.6.39.1/arch/arm/common/it8152.c 2011-05-22 19:36:30.000000000 -0400
528 @@ -221,7 +221,7 @@ static int it8152_pci_write_config(struc
529 return PCIBIOS_SUCCESSFUL;
530 }
531
532 -static struct pci_ops it8152_ops = {
533 +static const struct pci_ops it8152_ops = {
534 .read = it8152_pci_read_config,
535 .write = it8152_pci_write_config,
536 };
537 diff -urNp linux-2.6.39.1/arch/arm/common/via82c505.c linux-2.6.39.1/arch/arm/common/via82c505.c
538 --- linux-2.6.39.1/arch/arm/common/via82c505.c 2011-05-19 00:06:34.000000000 -0400
539 +++ linux-2.6.39.1/arch/arm/common/via82c505.c 2011-05-22 19:36:30.000000000 -0400
540 @@ -52,7 +52,7 @@ via82c505_write_config(struct pci_bus *b
541 return PCIBIOS_SUCCESSFUL;
542 }
543
544 -static struct pci_ops via82c505_ops = {
545 +static const struct pci_ops via82c505_ops = {
546 .read = via82c505_read_config,
547 .write = via82c505_write_config,
548 };
549 diff -urNp linux-2.6.39.1/arch/arm/include/asm/cacheflush.h linux-2.6.39.1/arch/arm/include/asm/cacheflush.h
550 --- linux-2.6.39.1/arch/arm/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
551 +++ linux-2.6.39.1/arch/arm/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
552 @@ -115,7 +115,7 @@ struct cpu_cache_fns {
553 */
554 #ifdef MULTI_CACHE
555
556 -extern struct cpu_cache_fns cpu_cache;
557 +extern const struct cpu_cache_fns cpu_cache;
558
559 #define __cpuc_flush_icache_all cpu_cache.flush_icache_all
560 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
561 diff -urNp linux-2.6.39.1/arch/arm/include/asm/elf.h linux-2.6.39.1/arch/arm/include/asm/elf.h
562 --- linux-2.6.39.1/arch/arm/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
563 +++ linux-2.6.39.1/arch/arm/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
564 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t
565 the loader. We need to make sure that it is out of the way of the program
566 that it will "exec", and that there is sufficient room for the brk. */
567
568 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
569 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
570 +
571 +#ifdef CONFIG_PAX_ASLR
572 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
573 +
574 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
575 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
576 +#endif
577
578 /* When the program starts, a1 contains a pointer to a function to be
579 registered with atexit, as per the SVR4 ABI. A value of 0 means we
580 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t
581 extern void elf_set_personality(const struct elf32_hdr *);
582 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
583
584 -struct mm_struct;
585 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
586 -#define arch_randomize_brk arch_randomize_brk
587 -
588 extern int vectors_user_mapping(void);
589 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
590 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
591 diff -urNp linux-2.6.39.1/arch/arm/include/asm/kmap_types.h linux-2.6.39.1/arch/arm/include/asm/kmap_types.h
592 --- linux-2.6.39.1/arch/arm/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
593 +++ linux-2.6.39.1/arch/arm/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
594 @@ -21,6 +21,7 @@ enum km_type {
595 KM_L1_CACHE,
596 KM_L2_CACHE,
597 KM_KDB,
598 + KM_CLEARPAGE,
599 KM_TYPE_NR
600 };
601
602 diff -urNp linux-2.6.39.1/arch/arm/include/asm/outercache.h linux-2.6.39.1/arch/arm/include/asm/outercache.h
603 --- linux-2.6.39.1/arch/arm/include/asm/outercache.h 2011-05-19 00:06:34.000000000 -0400
604 +++ linux-2.6.39.1/arch/arm/include/asm/outercache.h 2011-05-22 19:36:30.000000000 -0400
605 @@ -38,7 +38,7 @@ struct outer_cache_fns {
606
607 #ifdef CONFIG_OUTER_CACHE
608
609 -extern struct outer_cache_fns outer_cache;
610 +extern const struct outer_cache_fns outer_cache;
611
612 static inline void outer_inv_range(phys_addr_t start, phys_addr_t end)
613 {
614 diff -urNp linux-2.6.39.1/arch/arm/include/asm/page.h linux-2.6.39.1/arch/arm/include/asm/page.h
615 --- linux-2.6.39.1/arch/arm/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
616 +++ linux-2.6.39.1/arch/arm/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
617 @@ -126,7 +126,7 @@ struct cpu_user_fns {
618 };
619
620 #ifdef MULTI_USER
621 -extern struct cpu_user_fns cpu_user;
622 +extern const struct cpu_user_fns cpu_user;
623
624 #define __cpu_clear_user_highpage cpu_user.cpu_clear_user_highpage
625 #define __cpu_copy_user_highpage cpu_user.cpu_copy_user_highpage
626 diff -urNp linux-2.6.39.1/arch/arm/include/asm/uaccess.h linux-2.6.39.1/arch/arm/include/asm/uaccess.h
627 --- linux-2.6.39.1/arch/arm/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
628 +++ linux-2.6.39.1/arch/arm/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
629 @@ -403,6 +403,9 @@ extern unsigned long __must_check __strn
630
631 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
632 {
633 + if ((long)n < 0)
634 + return n;
635 +
636 if (access_ok(VERIFY_READ, from, n))
637 n = __copy_from_user(to, from, n);
638 else /* security hole - plug it */
639 @@ -412,6 +415,9 @@ static inline unsigned long __must_check
640
641 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
642 {
643 + if ((long)n < 0)
644 + return n;
645 +
646 if (access_ok(VERIFY_WRITE, to, n))
647 n = __copy_to_user(to, from, n);
648 return n;
649 diff -urNp linux-2.6.39.1/arch/arm/kernel/kgdb.c linux-2.6.39.1/arch/arm/kernel/kgdb.c
650 --- linux-2.6.39.1/arch/arm/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
651 +++ linux-2.6.39.1/arch/arm/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
652 @@ -246,7 +246,7 @@ void kgdb_arch_exit(void)
653 * and we handle the normal undef case within the do_undefinstr
654 * handler.
655 */
656 -struct kgdb_arch arch_kgdb_ops = {
657 +const struct kgdb_arch arch_kgdb_ops = {
658 #ifndef __ARMEB__
659 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
660 #else /* ! __ARMEB__ */
661 diff -urNp linux-2.6.39.1/arch/arm/kernel/process.c linux-2.6.39.1/arch/arm/kernel/process.c
662 --- linux-2.6.39.1/arch/arm/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
663 +++ linux-2.6.39.1/arch/arm/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
664 @@ -28,7 +28,6 @@
665 #include <linux/tick.h>
666 #include <linux/utsname.h>
667 #include <linux/uaccess.h>
668 -#include <linux/random.h>
669 #include <linux/hw_breakpoint.h>
670
671 #include <asm/cacheflush.h>
672 @@ -479,12 +478,6 @@ unsigned long get_wchan(struct task_stru
673 return 0;
674 }
675
676 -unsigned long arch_randomize_brk(struct mm_struct *mm)
677 -{
678 - unsigned long range_end = mm->brk + 0x02000000;
679 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
680 -}
681 -
682 #ifdef CONFIG_MMU
683 /*
684 * The vectors page is always readable from user space for the
685 diff -urNp linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c
686 --- linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c 2011-05-19 00:06:34.000000000 -0400
687 +++ linux-2.6.39.1/arch/arm/mach-cns3xxx/pcie.c 2011-05-22 19:36:30.000000000 -0400
688 @@ -162,7 +162,7 @@ static int cns3xxx_pci_setup(int nr, str
689 return 1;
690 }
691
692 -static struct pci_ops cns3xxx_pcie_ops = {
693 +static const struct pci_ops cns3xxx_pcie_ops = {
694 .read = cns3xxx_pci_read_config,
695 .write = cns3xxx_pci_write_config,
696 };
697 diff -urNp linux-2.6.39.1/arch/arm/mach-dove/pcie.c linux-2.6.39.1/arch/arm/mach-dove/pcie.c
698 --- linux-2.6.39.1/arch/arm/mach-dove/pcie.c 2011-05-19 00:06:34.000000000 -0400
699 +++ linux-2.6.39.1/arch/arm/mach-dove/pcie.c 2011-05-22 19:36:30.000000000 -0400
700 @@ -155,7 +155,7 @@ static int pcie_wr_conf(struct pci_bus *
701 return ret;
702 }
703
704 -static struct pci_ops pcie_ops = {
705 +static const struct pci_ops pcie_ops = {
706 .read = pcie_rd_conf,
707 .write = pcie_wr_conf,
708 };
709 diff -urNp linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c
710 --- linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c 2011-05-19 00:06:34.000000000 -0400
711 +++ linux-2.6.39.1/arch/arm/mach-footbridge/dc21285.c 2011-05-22 19:36:30.000000000 -0400
712 @@ -129,7 +129,7 @@ dc21285_write_config(struct pci_bus *bus
713 return PCIBIOS_SUCCESSFUL;
714 }
715
716 -static struct pci_ops dc21285_ops = {
717 +static const struct pci_ops dc21285_ops = {
718 .read = dc21285_read_config,
719 .write = dc21285_write_config,
720 };
721 diff -urNp linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c
722 --- linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c 2011-05-19 00:06:34.000000000 -0400
723 +++ linux-2.6.39.1/arch/arm/mach-integrator/pci_v3.c 2011-05-22 19:36:30.000000000 -0400
724 @@ -340,7 +340,7 @@ static int v3_write_config(struct pci_bu
725 return PCIBIOS_SUCCESSFUL;
726 }
727
728 -static struct pci_ops pci_v3_ops = {
729 +static const struct pci_ops pci_v3_ops = {
730 .read = v3_read_config,
731 .write = v3_write_config,
732 };
733 diff -urNp linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c
734 --- linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c 2011-05-19 00:06:34.000000000 -0400
735 +++ linux-2.6.39.1/arch/arm/mach-iop13xx/pci.c 2011-05-22 19:36:30.000000000 -0400
736 @@ -324,7 +324,7 @@ iop13xx_atux_write_config(struct pci_bus
737 return PCIBIOS_SUCCESSFUL;
738 }
739
740 -static struct pci_ops iop13xx_atux_ops = {
741 +static const struct pci_ops iop13xx_atux_ops = {
742 .read = iop13xx_atux_read_config,
743 .write = iop13xx_atux_write_config,
744 };
745 @@ -471,7 +471,7 @@ iop13xx_atue_write_config(struct pci_bus
746 return PCIBIOS_SUCCESSFUL;
747 }
748
749 -static struct pci_ops iop13xx_atue_ops = {
750 +static const struct pci_ops iop13xx_atue_ops = {
751 .read = iop13xx_atue_read_config,
752 .write = iop13xx_atue_write_config,
753 };
754 diff -urNp linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c
755 --- linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c 2011-05-19 00:06:34.000000000 -0400
756 +++ linux-2.6.39.1/arch/arm/mach-ixp2000/enp2611.c 2011-05-22 19:36:30.000000000 -0400
757 @@ -137,7 +137,7 @@ static int enp2611_pci_write_config(stru
758 return PCIBIOS_DEVICE_NOT_FOUND;
759 }
760
761 -static struct pci_ops enp2611_pci_ops = {
762 +static const struct pci_ops enp2611_pci_ops = {
763 .read = enp2611_pci_read_config,
764 .write = enp2611_pci_write_config
765 };
766 diff -urNp linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c
767 --- linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c 2011-05-19 00:06:34.000000000 -0400
768 +++ linux-2.6.39.1/arch/arm/mach-ixp2000/pci.c 2011-05-22 19:36:30.000000000 -0400
769 @@ -125,7 +125,7 @@ int ixp2000_pci_write_config(struct pci_
770 }
771
772
773 -static struct pci_ops ixp2000_pci_ops = {
774 +static const struct pci_ops ixp2000_pci_ops = {
775 .read = ixp2000_pci_read_config,
776 .write = ixp2000_pci_write_config
777 };
778 diff -urNp linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c
779 --- linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c 2011-05-19 00:06:34.000000000 -0400
780 +++ linux-2.6.39.1/arch/arm/mach-ixp23xx/pci.c 2011-05-22 19:36:30.000000000 -0400
781 @@ -136,7 +136,7 @@ static int ixp23xx_pci_write_config(stru
782 return PCIBIOS_SUCCESSFUL;
783 }
784
785 -struct pci_ops ixp23xx_pci_ops = {
786 +const struct pci_ops ixp23xx_pci_ops = {
787 .read = ixp23xx_pci_read_config,
788 .write = ixp23xx_pci_write_config,
789 };
790 diff -urNp linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c
791 --- linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c 2011-05-19 00:06:34.000000000 -0400
792 +++ linux-2.6.39.1/arch/arm/mach-ixp4xx/common-pci.c 2011-05-22 19:36:30.000000000 -0400
793 @@ -283,7 +283,7 @@ static int ixp4xx_pci_write_config(struc
794 return PCIBIOS_SUCCESSFUL;
795 }
796
797 -struct pci_ops ixp4xx_ops = {
798 +const struct pci_ops ixp4xx_ops = {
799 .read = ixp4xx_pci_read_config,
800 .write = ixp4xx_pci_write_config,
801 };
802 diff -urNp linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c
803 --- linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c 2011-05-19 00:06:34.000000000 -0400
804 +++ linux-2.6.39.1/arch/arm/mach-kirkwood/pcie.c 2011-05-22 19:36:30.000000000 -0400
805 @@ -111,7 +111,7 @@ static int pcie_wr_conf(struct pci_bus *
806 return ret;
807 }
808
809 -static struct pci_ops pcie_ops = {
810 +static const struct pci_ops pcie_ops = {
811 .read = pcie_rd_conf,
812 .write = pcie_wr_conf,
813 };
814 diff -urNp linux-2.6.39.1/arch/arm/mach-ks8695/pci.c linux-2.6.39.1/arch/arm/mach-ks8695/pci.c
815 --- linux-2.6.39.1/arch/arm/mach-ks8695/pci.c 2011-05-19 00:06:34.000000000 -0400
816 +++ linux-2.6.39.1/arch/arm/mach-ks8695/pci.c 2011-05-22 19:36:30.000000000 -0400
817 @@ -136,7 +136,7 @@ static void ks8695_local_writeconfig(int
818 __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
819 }
820
821 -static struct pci_ops ks8695_pci_ops = {
822 +static const struct pci_ops ks8695_pci_ops = {
823 .read = ks8695_pci_readconfig,
824 .write = ks8695_pci_writeconfig,
825 };
826 diff -urNp linux-2.6.39.1/arch/arm/mach-mmp/clock.c linux-2.6.39.1/arch/arm/mach-mmp/clock.c
827 --- linux-2.6.39.1/arch/arm/mach-mmp/clock.c 2011-05-19 00:06:34.000000000 -0400
828 +++ linux-2.6.39.1/arch/arm/mach-mmp/clock.c 2011-05-22 19:36:30.000000000 -0400
829 @@ -29,7 +29,7 @@ static void apbc_clk_disable(struct clk
830 __raw_writel(0, clk->clk_rst);
831 }
832
833 -struct clkops apbc_clk_ops = {
834 +const struct clkops apbc_clk_ops = {
835 .enable = apbc_clk_enable,
836 .disable = apbc_clk_disable,
837 };
838 @@ -44,7 +44,7 @@ static void apmu_clk_disable(struct clk
839 __raw_writel(0, clk->clk_rst);
840 }
841
842 -struct clkops apmu_clk_ops = {
843 +const struct clkops apmu_clk_ops = {
844 .enable = apmu_clk_enable,
845 .disable = apmu_clk_disable,
846 };
847 diff -urNp linux-2.6.39.1/arch/arm/mach-msm/iommu.c linux-2.6.39.1/arch/arm/mach-msm/iommu.c
848 --- linux-2.6.39.1/arch/arm/mach-msm/iommu.c 2011-05-19 00:06:34.000000000 -0400
849 +++ linux-2.6.39.1/arch/arm/mach-msm/iommu.c 2011-05-22 19:36:30.000000000 -0400
850 @@ -669,7 +669,7 @@ fail:
851 return 0;
852 }
853
854 -static struct iommu_ops msm_iommu_ops = {
855 +static const struct iommu_ops msm_iommu_ops = {
856 .domain_init = msm_iommu_domain_init,
857 .domain_destroy = msm_iommu_domain_destroy,
858 .attach_dev = msm_iommu_attach_dev,
859 diff -urNp linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c
860 --- linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c 2011-05-19 00:06:34.000000000 -0400
861 +++ linux-2.6.39.1/arch/arm/mach-msm/last_radio_log.c 2011-05-22 19:36:30.000000000 -0400
862 @@ -48,6 +48,7 @@ static ssize_t last_radio_log_read(struc
863 }
864
865 static struct file_operations last_radio_log_fops = {
866 + /* cannot be const, see msm_init_last_radio_log */
867 .read = last_radio_log_read,
868 .llseek = default_llseek,
869 };
870 diff -urNp linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c
871 --- linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c 2011-05-19 00:06:34.000000000 -0400
872 +++ linux-2.6.39.1/arch/arm/mach-mv78xx0/pcie.c 2011-05-22 19:36:30.000000000 -0400
873 @@ -222,7 +222,7 @@ static int pcie_wr_conf(struct pci_bus *
874 return ret;
875 }
876
877 -static struct pci_ops pcie_ops = {
878 +static const struct pci_ops pcie_ops = {
879 .read = pcie_rd_conf,
880 .write = pcie_wr_conf,
881 };
882 diff -urNp linux-2.6.39.1/arch/arm/mach-orion5x/pci.c linux-2.6.39.1/arch/arm/mach-orion5x/pci.c
883 --- linux-2.6.39.1/arch/arm/mach-orion5x/pci.c 2011-05-19 00:06:34.000000000 -0400
884 +++ linux-2.6.39.1/arch/arm/mach-orion5x/pci.c 2011-05-22 19:36:30.000000000 -0400
885 @@ -130,7 +130,7 @@ static int pcie_wr_conf(struct pci_bus *
886 return ret;
887 }
888
889 -static struct pci_ops pcie_ops = {
890 +static const struct pci_ops pcie_ops = {
891 .read = pcie_rd_conf,
892 .write = pcie_wr_conf,
893 };
894 @@ -368,7 +368,7 @@ static int orion5x_pci_wr_conf(struct pc
895 PCI_FUNC(devfn), where, size, val);
896 }
897
898 -static struct pci_ops pci_ops = {
899 +static const struct pci_ops pci_ops = {
900 .read = orion5x_pci_rd_conf,
901 .write = orion5x_pci_wr_conf,
902 };
903 diff -urNp linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c
904 --- linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-19 00:06:34.000000000 -0400
905 +++ linux-2.6.39.1/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-22 19:36:30.000000000 -0400
906 @@ -117,7 +117,7 @@ static int nanoengine_write_config(struc
907 return PCIBIOS_SUCCESSFUL;
908 }
909
910 -static struct pci_ops pci_nano_ops = {
911 +static const struct pci_ops pci_nano_ops = {
912 .read = nanoengine_read_config,
913 .write = nanoengine_write_config,
914 };
915 diff -urNp linux-2.6.39.1/arch/arm/mach-tegra/pcie.c linux-2.6.39.1/arch/arm/mach-tegra/pcie.c
916 --- linux-2.6.39.1/arch/arm/mach-tegra/pcie.c 2011-05-19 00:06:34.000000000 -0400
917 +++ linux-2.6.39.1/arch/arm/mach-tegra/pcie.c 2011-05-22 19:36:30.000000000 -0400
918 @@ -336,7 +336,7 @@ static int tegra_pcie_write_conf(struct
919 return PCIBIOS_SUCCESSFUL;
920 }
921
922 -static struct pci_ops tegra_pcie_ops = {
923 +static const struct pci_ops tegra_pcie_ops = {
924 .read = tegra_pcie_read_conf,
925 .write = tegra_pcie_write_conf,
926 };
927 diff -urNp linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c
928 --- linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c 2011-05-19 00:06:34.000000000 -0400
929 +++ linux-2.6.39.1/arch/arm/mach-ux500/mbox-db5500.c 2011-05-22 19:41:32.000000000 -0400
930 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct dev
931 return sprintf(buf, "0x%X\n", mbox_value);
932 }
933
934 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
935 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
936
937 static int mbox_show(struct seq_file *s, void *data)
938 {
939 diff -urNp linux-2.6.39.1/arch/arm/mach-versatile/pci.c linux-2.6.39.1/arch/arm/mach-versatile/pci.c
940 --- linux-2.6.39.1/arch/arm/mach-versatile/pci.c 2011-05-19 00:06:34.000000000 -0400
941 +++ linux-2.6.39.1/arch/arm/mach-versatile/pci.c 2011-05-22 19:36:30.000000000 -0400
942 @@ -165,7 +165,7 @@ static int versatile_write_config(struct
943 return PCIBIOS_SUCCESSFUL;
944 }
945
946 -static struct pci_ops pci_versatile_ops = {
947 +static const struct pci_ops pci_versatile_ops = {
948 .read = versatile_read_config,
949 .write = versatile_write_config,
950 };
951 diff -urNp linux-2.6.39.1/arch/arm/mm/fault.c linux-2.6.39.1/arch/arm/mm/fault.c
952 --- linux-2.6.39.1/arch/arm/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
953 +++ linux-2.6.39.1/arch/arm/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
954 @@ -182,6 +182,13 @@ __do_user_fault(struct task_struct *tsk,
955 }
956 #endif
957
958 +#ifdef CONFIG_PAX_PAGEEXEC
959 + if (fsr & FSR_LNX_PF) {
960 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
961 + do_group_exit(SIGKILL);
962 + }
963 +#endif
964 +
965 tsk->thread.address = addr;
966 tsk->thread.error_code = fsr;
967 tsk->thread.trap_no = 14;
968 @@ -379,6 +386,33 @@ do_page_fault(unsigned long addr, unsign
969 }
970 #endif /* CONFIG_MMU */
971
972 +#ifdef CONFIG_PAX_PAGEEXEC
973 +void pax_report_insns(void *pc, void *sp)
974 +{
975 + long i;
976 +
977 + printk(KERN_ERR "PAX: bytes at PC: ");
978 + for (i = 0; i < 20; i++) {
979 + unsigned char c;
980 + if (get_user(c, (__force unsigned char __user *)pc+i))
981 + printk(KERN_CONT "?? ");
982 + else
983 + printk(KERN_CONT "%02x ", c);
984 + }
985 + printk("\n");
986 +
987 + printk(KERN_ERR "PAX: bytes at SP-4: ");
988 + for (i = -1; i < 20; i++) {
989 + unsigned long c;
990 + if (get_user(c, (__force unsigned long __user *)sp+i))
991 + printk(KERN_CONT "???????? ");
992 + else
993 + printk(KERN_CONT "%08lx ", c);
994 + }
995 + printk("\n");
996 +}
997 +#endif
998 +
999 /*
1000 * First Level Translation Fault Handler
1001 *
1002 diff -urNp linux-2.6.39.1/arch/arm/mm/mmap.c linux-2.6.39.1/arch/arm/mm/mmap.c
1003 --- linux-2.6.39.1/arch/arm/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
1004 +++ linux-2.6.39.1/arch/arm/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
1005 @@ -65,6 +65,10 @@ arch_get_unmapped_area(struct file *filp
1006 if (len > TASK_SIZE)
1007 return -ENOMEM;
1008
1009 +#ifdef CONFIG_PAX_RANDMMAP
1010 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1011 +#endif
1012 +
1013 if (addr) {
1014 if (do_align)
1015 addr = COLOUR_ALIGN(addr, pgoff);
1016 @@ -72,15 +76,14 @@ arch_get_unmapped_area(struct file *filp
1017 addr = PAGE_ALIGN(addr);
1018
1019 vma = find_vma(mm, addr);
1020 - if (TASK_SIZE - len >= addr &&
1021 - (!vma || addr + len <= vma->vm_start))
1022 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1023 return addr;
1024 }
1025 if (len > mm->cached_hole_size) {
1026 - start_addr = addr = mm->free_area_cache;
1027 + start_addr = addr = mm->free_area_cache;
1028 } else {
1029 - start_addr = addr = TASK_UNMAPPED_BASE;
1030 - mm->cached_hole_size = 0;
1031 + start_addr = addr = mm->mmap_base;
1032 + mm->cached_hole_size = 0;
1033 }
1034 /* 8 bits of randomness in 20 address space bits */
1035 if ((current->flags & PF_RANDOMIZE) &&
1036 @@ -100,14 +103,14 @@ full_search:
1037 * Start a new search - just in case we missed
1038 * some holes.
1039 */
1040 - if (start_addr != TASK_UNMAPPED_BASE) {
1041 - start_addr = addr = TASK_UNMAPPED_BASE;
1042 + if (start_addr != mm->mmap_base) {
1043 + start_addr = addr = mm->mmap_base;
1044 mm->cached_hole_size = 0;
1045 goto full_search;
1046 }
1047 return -ENOMEM;
1048 }
1049 - if (!vma || addr + len <= vma->vm_start) {
1050 + if (check_heap_stack_gap(vma, addr, len)) {
1051 /*
1052 * Remember the place where we stopped the search:
1053 */
1054 diff -urNp linux-2.6.39.1/arch/arm/plat-iop/pci.c linux-2.6.39.1/arch/arm/plat-iop/pci.c
1055 --- linux-2.6.39.1/arch/arm/plat-iop/pci.c 2011-05-19 00:06:34.000000000 -0400
1056 +++ linux-2.6.39.1/arch/arm/plat-iop/pci.c 2011-05-22 19:36:30.000000000 -0400
1057 @@ -161,7 +161,7 @@ iop3xx_write_config(struct pci_bus *bus,
1058 return PCIBIOS_SUCCESSFUL;
1059 }
1060
1061 -static struct pci_ops iop3xx_ops = {
1062 +static const struct pci_ops iop3xx_ops = {
1063 .read = iop3xx_read_config,
1064 .write = iop3xx_write_config,
1065 };
1066 diff -urNp linux-2.6.39.1/arch/avr32/include/asm/elf.h linux-2.6.39.1/arch/avr32/include/asm/elf.h
1067 --- linux-2.6.39.1/arch/avr32/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1068 +++ linux-2.6.39.1/arch/avr32/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1069 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpreg
1070 the loader. We need to make sure that it is out of the way of the program
1071 that it will "exec", and that there is sufficient room for the brk. */
1072
1073 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1074 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1075
1076 +#ifdef CONFIG_PAX_ASLR
1077 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1078 +
1079 +#define PAX_DELTA_MMAP_LEN 15
1080 +#define PAX_DELTA_STACK_LEN 15
1081 +#endif
1082
1083 /* This yields a mask that user programs can use to figure out what
1084 instruction set this CPU supports. This could be done in user space,
1085 diff -urNp linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h
1086 --- linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1087 +++ linux-2.6.39.1/arch/avr32/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1088 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1089 D(11) KM_IRQ1,
1090 D(12) KM_SOFTIRQ0,
1091 D(13) KM_SOFTIRQ1,
1092 -D(14) KM_TYPE_NR
1093 +D(14) KM_CLEARPAGE,
1094 +D(15) KM_TYPE_NR
1095 };
1096
1097 #undef D
1098 diff -urNp linux-2.6.39.1/arch/avr32/mm/fault.c linux-2.6.39.1/arch/avr32/mm/fault.c
1099 --- linux-2.6.39.1/arch/avr32/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1100 +++ linux-2.6.39.1/arch/avr32/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1101 @@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
1102
1103 int exception_trace = 1;
1104
1105 +#ifdef CONFIG_PAX_PAGEEXEC
1106 +void pax_report_insns(void *pc, void *sp)
1107 +{
1108 + unsigned long i;
1109 +
1110 + printk(KERN_ERR "PAX: bytes at PC: ");
1111 + for (i = 0; i < 20; i++) {
1112 + unsigned char c;
1113 + if (get_user(c, (unsigned char *)pc+i))
1114 + printk(KERN_CONT "???????? ");
1115 + else
1116 + printk(KERN_CONT "%02x ", c);
1117 + }
1118 + printk("\n");
1119 +}
1120 +#endif
1121 +
1122 /*
1123 * This routine handles page faults. It determines the address and the
1124 * problem, and then passes it off to one of the appropriate routines.
1125 @@ -156,6 +173,16 @@ bad_area:
1126 up_read(&mm->mmap_sem);
1127
1128 if (user_mode(regs)) {
1129 +
1130 +#ifdef CONFIG_PAX_PAGEEXEC
1131 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1132 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1133 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1134 + do_group_exit(SIGKILL);
1135 + }
1136 + }
1137 +#endif
1138 +
1139 if (exception_trace && printk_ratelimit())
1140 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1141 "sp %08lx ecr %lu\n",
1142 diff -urNp linux-2.6.39.1/arch/blackfin/kernel/kgdb.c linux-2.6.39.1/arch/blackfin/kernel/kgdb.c
1143 --- linux-2.6.39.1/arch/blackfin/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1144 +++ linux-2.6.39.1/arch/blackfin/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1145 @@ -420,7 +420,7 @@ int kgdb_arch_handle_exception(int vecto
1146 return -1; /* this means that we do not want to exit from the handler */
1147 }
1148
1149 -struct kgdb_arch arch_kgdb_ops = {
1150 +const struct kgdb_arch arch_kgdb_ops = {
1151 .gdb_bpt_instr = {0xa1},
1152 .flags = KGDB_HW_BREAKPOINT,
1153 .set_hw_breakpoint = bfin_set_hw_break,
1154 diff -urNp linux-2.6.39.1/arch/blackfin/mm/maccess.c linux-2.6.39.1/arch/blackfin/mm/maccess.c
1155 --- linux-2.6.39.1/arch/blackfin/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
1156 +++ linux-2.6.39.1/arch/blackfin/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
1157 @@ -16,7 +16,7 @@ static int validate_memory_access_addres
1158 return bfin_mem_access_type(addr, size);
1159 }
1160
1161 -long probe_kernel_read(void *dst, void *src, size_t size)
1162 +long probe_kernel_read(void *dst, const void *src, size_t size)
1163 {
1164 unsigned long lsrc = (unsigned long)src;
1165 int mem_type;
1166 @@ -55,7 +55,7 @@ long probe_kernel_read(void *dst, void *
1167 return -EFAULT;
1168 }
1169
1170 -long probe_kernel_write(void *dst, void *src, size_t size)
1171 +long probe_kernel_write(void *dst, const void *src, size_t size)
1172 {
1173 unsigned long ldst = (unsigned long)dst;
1174 int mem_type;
1175 diff -urNp linux-2.6.39.1/arch/frv/include/asm/kmap_types.h linux-2.6.39.1/arch/frv/include/asm/kmap_types.h
1176 --- linux-2.6.39.1/arch/frv/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1177 +++ linux-2.6.39.1/arch/frv/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1178 @@ -23,6 +23,7 @@ enum km_type {
1179 KM_IRQ1,
1180 KM_SOFTIRQ0,
1181 KM_SOFTIRQ1,
1182 + KM_CLEARPAGE,
1183 KM_TYPE_NR
1184 };
1185
1186 diff -urNp linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h
1187 --- linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h 2011-05-19 00:06:34.000000000 -0400
1188 +++ linux-2.6.39.1/arch/frv/mb93090-mb00/pci-frv.h 2011-05-22 19:36:30.000000000 -0400
1189 @@ -34,7 +34,7 @@ void pcibios_resource_survey(void);
1190
1191 extern int __nongpreldata pcibios_last_bus;
1192 extern struct pci_bus *__nongpreldata pci_root_bus;
1193 -extern struct pci_ops *__nongpreldata pci_root_ops;
1194 +extern const struct pci_ops *__nongpreldata pci_root_ops;
1195
1196 /* pci-irq.c */
1197 extern unsigned int pcibios_irq_mask;
1198 diff -urNp linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c
1199 --- linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-19 00:06:34.000000000 -0400
1200 +++ linux-2.6.39.1/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-22 19:36:30.000000000 -0400
1201 @@ -27,7 +27,7 @@ unsigned int __nongpreldata pci_probe =
1202
1203 int __nongpreldata pcibios_last_bus = -1;
1204 struct pci_bus *__nongpreldata pci_root_bus;
1205 -struct pci_ops *__nongpreldata pci_root_ops;
1206 +const struct pci_ops *__nongpreldata pci_root_ops;
1207
1208 /*
1209 * The accessible PCI window does not cover the entire CPU address space, but
1210 @@ -169,7 +169,7 @@ static int pci_frv_write_config(struct p
1211 return PCIBIOS_SUCCESSFUL;
1212 }
1213
1214 -static struct pci_ops pci_direct_frv = {
1215 +static const struct pci_ops pci_direct_frv = {
1216 pci_frv_read_config,
1217 pci_frv_write_config,
1218 };
1219 @@ -356,7 +356,7 @@ void __init pcibios_fixup_bus(struct pci
1220
1221 int __init pcibios_init(void)
1222 {
1223 - struct pci_ops *dir = NULL;
1224 + const struct pci_ops *dir = NULL;
1225
1226 if (!mb93090_mb00_detected)
1227 return -ENXIO;
1228 diff -urNp linux-2.6.39.1/arch/frv/mm/elf-fdpic.c linux-2.6.39.1/arch/frv/mm/elf-fdpic.c
1229 --- linux-2.6.39.1/arch/frv/mm/elf-fdpic.c 2011-05-19 00:06:34.000000000 -0400
1230 +++ linux-2.6.39.1/arch/frv/mm/elf-fdpic.c 2011-05-22 19:36:30.000000000 -0400
1231 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
1232 if (addr) {
1233 addr = PAGE_ALIGN(addr);
1234 vma = find_vma(current->mm, addr);
1235 - if (TASK_SIZE - len >= addr &&
1236 - (!vma || addr + len <= vma->vm_start))
1237 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1238 goto success;
1239 }
1240
1241 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
1242 for (; vma; vma = vma->vm_next) {
1243 if (addr > limit)
1244 break;
1245 - if (addr + len <= vma->vm_start)
1246 + if (check_heap_stack_gap(vma, addr, len))
1247 goto success;
1248 addr = vma->vm_end;
1249 }
1250 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
1251 for (; vma; vma = vma->vm_next) {
1252 if (addr > limit)
1253 break;
1254 - if (addr + len <= vma->vm_start)
1255 + if (check_heap_stack_gap(vma, addr, len))
1256 goto success;
1257 addr = vma->vm_end;
1258 }
1259 diff -urNp linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c
1260 --- linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c 2011-05-19 00:06:34.000000000 -0400
1261 +++ linux-2.6.39.1/arch/ia64/hp/common/hwsw_iommu.c 2011-05-22 19:36:30.000000000 -0400
1262 @@ -17,7 +17,7 @@
1263 #include <linux/swiotlb.h>
1264 #include <asm/machvec.h>
1265
1266 -extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1267 +extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1268
1269 /* swiotlb declarations & definitions: */
1270 extern int swiotlb_late_init_with_default_size (size_t size);
1271 @@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
1272 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1273 }
1274
1275 -struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1276 +const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1277 {
1278 if (use_swiotlb(dev))
1279 return &swiotlb_dma_ops;
1280 diff -urNp linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c
1281 --- linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c 2011-05-19 00:06:34.000000000 -0400
1282 +++ linux-2.6.39.1/arch/ia64/hp/common/sba_iommu.c 2011-05-22 19:36:30.000000000 -0400
1283 @@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
1284 },
1285 };
1286
1287 -extern struct dma_map_ops swiotlb_dma_ops;
1288 +extern const struct dma_map_ops swiotlb_dma_ops;
1289
1290 static int __init
1291 sba_init(void)
1292 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1293
1294 __setup("sbapagesize=",sba_page_override);
1295
1296 -struct dma_map_ops sba_dma_ops = {
1297 +const struct dma_map_ops sba_dma_ops = {
1298 .alloc_coherent = sba_alloc_coherent,
1299 .free_coherent = sba_free_coherent,
1300 .map_page = sba_map_page,
1301 diff -urNp linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h
1302 --- linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1303 +++ linux-2.6.39.1/arch/ia64/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1304 @@ -14,7 +14,7 @@
1305
1306 #define DMA_ERROR_CODE 0
1307
1308 -extern struct dma_map_ops *dma_ops;
1309 +extern const struct dma_map_ops *dma_ops;
1310 extern struct ia64_machine_vector ia64_mv;
1311 extern void set_iommu_machvec(void);
1312
1313 @@ -26,7 +26,7 @@ extern void machvec_dma_sync_sg(struct d
1314 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1315 dma_addr_t *daddr, gfp_t gfp)
1316 {
1317 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1318 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1319 void *caddr;
1320
1321 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1322 @@ -37,7 +37,7 @@ static inline void *dma_alloc_coherent(s
1323 static inline void dma_free_coherent(struct device *dev, size_t size,
1324 void *caddr, dma_addr_t daddr)
1325 {
1326 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1327 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1328 debug_dma_free_coherent(dev, size, caddr, daddr);
1329 ops->free_coherent(dev, size, caddr, daddr);
1330 }
1331 @@ -51,13 +51,13 @@ static inline void dma_free_coherent(str
1332
1333 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1334 {
1335 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1336 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1337 return ops->mapping_error(dev, daddr);
1338 }
1339
1340 static inline int dma_supported(struct device *dev, u64 mask)
1341 {
1342 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1343 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1344 return ops->dma_supported(dev, mask);
1345 }
1346
1347 diff -urNp linux-2.6.39.1/arch/ia64/include/asm/elf.h linux-2.6.39.1/arch/ia64/include/asm/elf.h
1348 --- linux-2.6.39.1/arch/ia64/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1349 +++ linux-2.6.39.1/arch/ia64/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1350 @@ -42,6 +42,13 @@
1351 */
1352 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1353
1354 +#ifdef CONFIG_PAX_ASLR
1355 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1356 +
1357 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1358 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1359 +#endif
1360 +
1361 #define PT_IA_64_UNWIND 0x70000001
1362
1363 /* IA-64 relocations: */
1364 diff -urNp linux-2.6.39.1/arch/ia64/include/asm/machvec.h linux-2.6.39.1/arch/ia64/include/asm/machvec.h
1365 --- linux-2.6.39.1/arch/ia64/include/asm/machvec.h 2011-05-19 00:06:34.000000000 -0400
1366 +++ linux-2.6.39.1/arch/ia64/include/asm/machvec.h 2011-05-22 19:36:30.000000000 -0400
1367 @@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1368 /* DMA-mapping interface: */
1369 typedef void ia64_mv_dma_init (void);
1370 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1371 -typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1372 +typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1373
1374 /*
1375 * WARNING: The legacy I/O space is _architected_. Platforms are
1376 @@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1377 # endif /* CONFIG_IA64_GENERIC */
1378
1379 extern void swiotlb_dma_init(void);
1380 -extern struct dma_map_ops *dma_get_ops(struct device *);
1381 +extern const struct dma_map_ops *dma_get_ops(struct device *);
1382
1383 /*
1384 * Define default versions so we can extend machvec for new platforms without having
1385 diff -urNp linux-2.6.39.1/arch/ia64/include/asm/pgtable.h linux-2.6.39.1/arch/ia64/include/asm/pgtable.h
1386 --- linux-2.6.39.1/arch/ia64/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
1387 +++ linux-2.6.39.1/arch/ia64/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
1388 @@ -12,7 +12,7 @@
1389 * David Mosberger-Tang <davidm@hpl.hp.com>
1390 */
1391
1392 -
1393 +#include <linux/const.h>
1394 #include <asm/mman.h>
1395 #include <asm/page.h>
1396 #include <asm/processor.h>
1397 @@ -143,6 +143,17 @@
1398 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1399 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1400 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1401 +
1402 +#ifdef CONFIG_PAX_PAGEEXEC
1403 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1404 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1405 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1406 +#else
1407 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1408 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1409 +# define PAGE_COPY_NOEXEC PAGE_COPY
1410 +#endif
1411 +
1412 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1413 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1414 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1415 diff -urNp linux-2.6.39.1/arch/ia64/include/asm/spinlock.h linux-2.6.39.1/arch/ia64/include/asm/spinlock.h
1416 --- linux-2.6.39.1/arch/ia64/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
1417 +++ linux-2.6.39.1/arch/ia64/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
1418 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1419 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1420
1421 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1422 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1423 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1424 }
1425
1426 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1427 diff -urNp linux-2.6.39.1/arch/ia64/include/asm/uaccess.h linux-2.6.39.1/arch/ia64/include/asm/uaccess.h
1428 --- linux-2.6.39.1/arch/ia64/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
1429 +++ linux-2.6.39.1/arch/ia64/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
1430 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1431 const void *__cu_from = (from); \
1432 long __cu_len = (n); \
1433 \
1434 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1435 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1436 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1437 __cu_len; \
1438 })
1439 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1440 long __cu_len = (n); \
1441 \
1442 __chk_user_ptr(__cu_from); \
1443 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1444 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1445 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1446 __cu_len; \
1447 })
1448 diff -urNp linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c
1449 --- linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c 2011-05-19 00:06:34.000000000 -0400
1450 +++ linux-2.6.39.1/arch/ia64/kernel/dma-mapping.c 2011-05-22 19:36:30.000000000 -0400
1451 @@ -3,7 +3,7 @@
1452 /* Set this to 1 if there is a HW IOMMU in the system */
1453 int iommu_detected __read_mostly;
1454
1455 -struct dma_map_ops *dma_ops;
1456 +const struct dma_map_ops *dma_ops;
1457 EXPORT_SYMBOL(dma_ops);
1458
1459 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1460 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1461 }
1462 fs_initcall(dma_init);
1463
1464 -struct dma_map_ops *dma_get_ops(struct device *dev)
1465 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1466 {
1467 return dma_ops;
1468 }
1469 diff -urNp linux-2.6.39.1/arch/ia64/kernel/module.c linux-2.6.39.1/arch/ia64/kernel/module.c
1470 --- linux-2.6.39.1/arch/ia64/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
1471 +++ linux-2.6.39.1/arch/ia64/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
1472 @@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1473 void
1474 module_free (struct module *mod, void *module_region)
1475 {
1476 - if (mod && mod->arch.init_unw_table &&
1477 - module_region == mod->module_init) {
1478 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1479 unw_remove_unwind_table(mod->arch.init_unw_table);
1480 mod->arch.init_unw_table = NULL;
1481 }
1482 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1483 }
1484
1485 static inline int
1486 +in_init_rx (const struct module *mod, uint64_t addr)
1487 +{
1488 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1489 +}
1490 +
1491 +static inline int
1492 +in_init_rw (const struct module *mod, uint64_t addr)
1493 +{
1494 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1495 +}
1496 +
1497 +static inline int
1498 in_init (const struct module *mod, uint64_t addr)
1499 {
1500 - return addr - (uint64_t) mod->module_init < mod->init_size;
1501 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1502 +}
1503 +
1504 +static inline int
1505 +in_core_rx (const struct module *mod, uint64_t addr)
1506 +{
1507 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1508 +}
1509 +
1510 +static inline int
1511 +in_core_rw (const struct module *mod, uint64_t addr)
1512 +{
1513 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1514 }
1515
1516 static inline int
1517 in_core (const struct module *mod, uint64_t addr)
1518 {
1519 - return addr - (uint64_t) mod->module_core < mod->core_size;
1520 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1521 }
1522
1523 static inline int
1524 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1525 break;
1526
1527 case RV_BDREL:
1528 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1529 + if (in_init_rx(mod, val))
1530 + val -= (uint64_t) mod->module_init_rx;
1531 + else if (in_init_rw(mod, val))
1532 + val -= (uint64_t) mod->module_init_rw;
1533 + else if (in_core_rx(mod, val))
1534 + val -= (uint64_t) mod->module_core_rx;
1535 + else if (in_core_rw(mod, val))
1536 + val -= (uint64_t) mod->module_core_rw;
1537 break;
1538
1539 case RV_LTV:
1540 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1541 * addresses have been selected...
1542 */
1543 uint64_t gp;
1544 - if (mod->core_size > MAX_LTOFF)
1545 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1546 /*
1547 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1548 * at the end of the module.
1549 */
1550 - gp = mod->core_size - MAX_LTOFF / 2;
1551 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1552 else
1553 - gp = mod->core_size / 2;
1554 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1555 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1556 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1557 mod->arch.gp = gp;
1558 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1559 }
1560 diff -urNp linux-2.6.39.1/arch/ia64/kernel/pci-dma.c linux-2.6.39.1/arch/ia64/kernel/pci-dma.c
1561 --- linux-2.6.39.1/arch/ia64/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
1562 +++ linux-2.6.39.1/arch/ia64/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
1563 @@ -43,7 +43,7 @@ struct device fallback_dev = {
1564 .dma_mask = &fallback_dev.coherent_dma_mask,
1565 };
1566
1567 -extern struct dma_map_ops intel_dma_ops;
1568 +extern const struct dma_map_ops intel_dma_ops;
1569
1570 static int __init pci_iommu_init(void)
1571 {
1572 diff -urNp linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c
1573 --- linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
1574 +++ linux-2.6.39.1/arch/ia64/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
1575 @@ -22,7 +22,7 @@ static void *ia64_swiotlb_alloc_coherent
1576 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1577 }
1578
1579 -struct dma_map_ops swiotlb_dma_ops = {
1580 +const struct dma_map_ops swiotlb_dma_ops = {
1581 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1582 .free_coherent = swiotlb_free_coherent,
1583 .map_page = swiotlb_map_page,
1584 diff -urNp linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c
1585 --- linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c 2011-05-19 00:06:34.000000000 -0400
1586 +++ linux-2.6.39.1/arch/ia64/kernel/sys_ia64.c 2011-05-22 19:36:30.000000000 -0400
1587 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1588 if (REGION_NUMBER(addr) == RGN_HPAGE)
1589 addr = 0;
1590 #endif
1591 +
1592 +#ifdef CONFIG_PAX_RANDMMAP
1593 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1594 + addr = mm->free_area_cache;
1595 + else
1596 +#endif
1597 +
1598 if (!addr)
1599 addr = mm->free_area_cache;
1600
1601 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1602 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1603 /* At this point: (!vma || addr < vma->vm_end). */
1604 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1605 - if (start_addr != TASK_UNMAPPED_BASE) {
1606 + if (start_addr != mm->mmap_base) {
1607 /* Start a new search --- just in case we missed some holes. */
1608 - addr = TASK_UNMAPPED_BASE;
1609 + addr = mm->mmap_base;
1610 goto full_search;
1611 }
1612 return -ENOMEM;
1613 }
1614 - if (!vma || addr + len <= vma->vm_start) {
1615 + if (check_heap_stack_gap(vma, addr, len)) {
1616 /* Remember the address where we stopped this search: */
1617 mm->free_area_cache = addr + len;
1618 return addr;
1619 diff -urNp linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S
1620 --- linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
1621 +++ linux-2.6.39.1/arch/ia64/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
1622 @@ -199,7 +199,7 @@ SECTIONS {
1623 /* Per-cpu data: */
1624 . = ALIGN(PERCPU_PAGE_SIZE);
1625 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1626 - __phys_per_cpu_start = __per_cpu_load;
1627 + __phys_per_cpu_start = per_cpu_load;
1628 /*
1629 * ensure percpu data fits
1630 * into percpu page size
1631 diff -urNp linux-2.6.39.1/arch/ia64/mm/fault.c linux-2.6.39.1/arch/ia64/mm/fault.c
1632 --- linux-2.6.39.1/arch/ia64/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1633 +++ linux-2.6.39.1/arch/ia64/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1634 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1635 return pte_present(pte);
1636 }
1637
1638 +#ifdef CONFIG_PAX_PAGEEXEC
1639 +void pax_report_insns(void *pc, void *sp)
1640 +{
1641 + unsigned long i;
1642 +
1643 + printk(KERN_ERR "PAX: bytes at PC: ");
1644 + for (i = 0; i < 8; i++) {
1645 + unsigned int c;
1646 + if (get_user(c, (unsigned int *)pc+i))
1647 + printk(KERN_CONT "???????? ");
1648 + else
1649 + printk(KERN_CONT "%08x ", c);
1650 + }
1651 + printk("\n");
1652 +}
1653 +#endif
1654 +
1655 void __kprobes
1656 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1657 {
1658 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1659 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1660 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1661
1662 - if ((vma->vm_flags & mask) != mask)
1663 + if ((vma->vm_flags & mask) != mask) {
1664 +
1665 +#ifdef CONFIG_PAX_PAGEEXEC
1666 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1667 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1668 + goto bad_area;
1669 +
1670 + up_read(&mm->mmap_sem);
1671 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1672 + do_group_exit(SIGKILL);
1673 + }
1674 +#endif
1675 +
1676 goto bad_area;
1677
1678 + }
1679 +
1680 /*
1681 * If for any reason at all we couldn't handle the fault, make
1682 * sure we exit gracefully rather than endlessly redo the
1683 diff -urNp linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c
1684 --- linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
1685 +++ linux-2.6.39.1/arch/ia64/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
1686 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(
1687 /* At this point: (!vmm || addr < vmm->vm_end). */
1688 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1689 return -ENOMEM;
1690 - if (!vmm || (addr + len) <= vmm->vm_start)
1691 + if (check_heap_stack_gap(vmm, addr, len))
1692 return addr;
1693 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1694 }
1695 diff -urNp linux-2.6.39.1/arch/ia64/mm/init.c linux-2.6.39.1/arch/ia64/mm/init.c
1696 --- linux-2.6.39.1/arch/ia64/mm/init.c 2011-05-19 00:06:34.000000000 -0400
1697 +++ linux-2.6.39.1/arch/ia64/mm/init.c 2011-05-22 19:36:30.000000000 -0400
1698 @@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1699 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1700 vma->vm_end = vma->vm_start + PAGE_SIZE;
1701 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1702 +
1703 +#ifdef CONFIG_PAX_PAGEEXEC
1704 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1705 + vma->vm_flags &= ~VM_EXEC;
1706 +
1707 +#ifdef CONFIG_PAX_MPROTECT
1708 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1709 + vma->vm_flags &= ~VM_MAYEXEC;
1710 +#endif
1711 +
1712 + }
1713 +#endif
1714 +
1715 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1716 down_write(&current->mm->mmap_sem);
1717 if (insert_vm_struct(current->mm, vma)) {
1718 diff -urNp linux-2.6.39.1/arch/ia64/pci/pci.c linux-2.6.39.1/arch/ia64/pci/pci.c
1719 --- linux-2.6.39.1/arch/ia64/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
1720 +++ linux-2.6.39.1/arch/ia64/pci/pci.c 2011-05-22 19:36:30.000000000 -0400
1721 @@ -109,7 +109,7 @@ static int pci_write(struct pci_bus *bus
1722 devfn, where, size, value);
1723 }
1724
1725 -struct pci_ops pci_root_ops = {
1726 +const struct pci_ops pci_root_ops = {
1727 .read = pci_read,
1728 .write = pci_write,
1729 };
1730 diff -urNp linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c
1731 --- linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c 2011-05-19 00:06:34.000000000 -0400
1732 +++ linux-2.6.39.1/arch/ia64/sn/pci/pci_dma.c 2011-05-22 19:36:30.000000000 -0400
1733 @@ -465,7 +465,7 @@ int sn_pci_legacy_write(struct pci_bus *
1734 return ret;
1735 }
1736
1737 -static struct dma_map_ops sn_dma_ops = {
1738 +static const struct dma_map_ops sn_dma_ops = {
1739 .alloc_coherent = sn_dma_alloc_coherent,
1740 .free_coherent = sn_dma_free_coherent,
1741 .map_page = sn_dma_map_page,
1742 diff -urNp linux-2.6.39.1/arch/m32r/lib/usercopy.c linux-2.6.39.1/arch/m32r/lib/usercopy.c
1743 --- linux-2.6.39.1/arch/m32r/lib/usercopy.c 2011-05-19 00:06:34.000000000 -0400
1744 +++ linux-2.6.39.1/arch/m32r/lib/usercopy.c 2011-05-22 19:36:30.000000000 -0400
1745 @@ -14,6 +14,9 @@
1746 unsigned long
1747 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1748 {
1749 + if ((long)n < 0)
1750 + return n;
1751 +
1752 prefetch(from);
1753 if (access_ok(VERIFY_WRITE, to, n))
1754 __copy_user(to,from,n);
1755 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1756 unsigned long
1757 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1758 {
1759 + if ((long)n < 0)
1760 + return n;
1761 +
1762 prefetchw(to);
1763 if (access_ok(VERIFY_READ, from, n))
1764 __copy_user_zeroing(to,from,n);
1765 diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/device.h linux-2.6.39.1/arch/microblaze/include/asm/device.h
1766 --- linux-2.6.39.1/arch/microblaze/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1767 +++ linux-2.6.39.1/arch/microblaze/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
1768 @@ -13,7 +13,7 @@ struct device_node;
1769
1770 struct dev_archdata {
1771 /* DMA operations on that device */
1772 - struct dma_map_ops *dma_ops;
1773 + const struct dma_map_ops *dma_ops;
1774 void *dma_data;
1775 };
1776
1777 diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h
1778 --- linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1779 +++ linux-2.6.39.1/arch/microblaze/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1780 @@ -43,14 +43,14 @@ static inline unsigned long device_to_ma
1781 return 0xfffffffful;
1782 }
1783
1784 -extern struct dma_map_ops *dma_ops;
1785 +extern const struct dma_map_ops *dma_ops;
1786
1787 /*
1788 * Available generic sets of operations
1789 */
1790 -extern struct dma_map_ops dma_direct_ops;
1791 +extern const struct dma_map_ops dma_direct_ops;
1792
1793 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1794 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1795 {
1796 /* We don't handle the NULL dev case for ISA for now. We could
1797 * do it via an out of line call but it is not needed for now. The
1798 @@ -63,14 +63,14 @@ static inline struct dma_map_ops *get_dm
1799 return dev->archdata.dma_ops;
1800 }
1801
1802 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
1803 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
1804 {
1805 dev->archdata.dma_ops = ops;
1806 }
1807
1808 static inline int dma_supported(struct device *dev, u64 mask)
1809 {
1810 - struct dma_map_ops *ops = get_dma_ops(dev);
1811 + const struct dma_map_ops *ops = get_dma_ops(dev);
1812
1813 if (unlikely(!ops))
1814 return 0;
1815 @@ -81,7 +81,7 @@ static inline int dma_supported(struct d
1816
1817 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1818 {
1819 - struct dma_map_ops *ops = get_dma_ops(dev);
1820 + const struct dma_map_ops *ops = get_dma_ops(dev);
1821
1822 if (unlikely(ops == NULL))
1823 return -EIO;
1824 @@ -97,7 +97,7 @@ static inline int dma_set_mask(struct de
1825
1826 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1827 {
1828 - struct dma_map_ops *ops = get_dma_ops(dev);
1829 + const struct dma_map_ops *ops = get_dma_ops(dev);
1830 if (ops->mapping_error)
1831 return ops->mapping_error(dev, dma_addr);
1832
1833 @@ -110,7 +110,7 @@ static inline int dma_mapping_error(stru
1834 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1835 dma_addr_t *dma_handle, gfp_t flag)
1836 {
1837 - struct dma_map_ops *ops = get_dma_ops(dev);
1838 + const struct dma_map_ops *ops = get_dma_ops(dev);
1839 void *memory;
1840
1841 BUG_ON(!ops);
1842 @@ -124,7 +124,7 @@ static inline void *dma_alloc_coherent(s
1843 static inline void dma_free_coherent(struct device *dev, size_t size,
1844 void *cpu_addr, dma_addr_t dma_handle)
1845 {
1846 - struct dma_map_ops *ops = get_dma_ops(dev);
1847 + const struct dma_map_ops *ops = get_dma_ops(dev);
1848
1849 BUG_ON(!ops);
1850 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
1851 diff -urNp linux-2.6.39.1/arch/microblaze/include/asm/pci.h linux-2.6.39.1/arch/microblaze/include/asm/pci.h
1852 --- linux-2.6.39.1/arch/microblaze/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
1853 +++ linux-2.6.39.1/arch/microblaze/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
1854 @@ -54,8 +54,8 @@ static inline void pcibios_penalize_isa_
1855 }
1856
1857 #ifdef CONFIG_PCI
1858 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
1859 -extern struct dma_map_ops *get_pci_dma_ops(void);
1860 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
1861 +extern const struct dma_map_ops *get_pci_dma_ops(void);
1862 #else /* CONFIG_PCI */
1863 #define set_pci_dma_ops(d)
1864 #define get_pci_dma_ops() NULL
1865 diff -urNp linux-2.6.39.1/arch/microblaze/kernel/dma.c linux-2.6.39.1/arch/microblaze/kernel/dma.c
1866 --- linux-2.6.39.1/arch/microblaze/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
1867 +++ linux-2.6.39.1/arch/microblaze/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
1868 @@ -134,7 +134,7 @@ static inline void dma_direct_unmap_page
1869 __dma_sync_page(dma_address, 0 , size, direction);
1870 }
1871
1872 -struct dma_map_ops dma_direct_ops = {
1873 +const struct dma_map_ops dma_direct_ops = {
1874 .alloc_coherent = dma_direct_alloc_coherent,
1875 .free_coherent = dma_direct_free_coherent,
1876 .map_sg = dma_direct_map_sg,
1877 diff -urNp linux-2.6.39.1/arch/microblaze/kernel/kgdb.c linux-2.6.39.1/arch/microblaze/kernel/kgdb.c
1878 --- linux-2.6.39.1/arch/microblaze/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1879 +++ linux-2.6.39.1/arch/microblaze/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1880 @@ -141,7 +141,7 @@ void kgdb_arch_exit(void)
1881 /*
1882 * Global data
1883 */
1884 -struct kgdb_arch arch_kgdb_ops = {
1885 +const struct kgdb_arch arch_kgdb_ops = {
1886 #ifdef __MICROBLAZEEL__
1887 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
1888 #else
1889 diff -urNp linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c
1890 --- linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
1891 +++ linux-2.6.39.1/arch/microblaze/pci/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
1892 @@ -140,7 +140,7 @@ indirect_write_config(struct pci_bus *bu
1893 return PCIBIOS_SUCCESSFUL;
1894 }
1895
1896 -static struct pci_ops indirect_pci_ops = {
1897 +static const struct pci_ops indirect_pci_ops = {
1898 .read = indirect_read_config,
1899 .write = indirect_write_config,
1900 };
1901 diff -urNp linux-2.6.39.1/arch/microblaze/pci/pci-common.c linux-2.6.39.1/arch/microblaze/pci/pci-common.c
1902 --- linux-2.6.39.1/arch/microblaze/pci/pci-common.c 2011-05-19 00:06:34.000000000 -0400
1903 +++ linux-2.6.39.1/arch/microblaze/pci/pci-common.c 2011-05-22 19:36:30.000000000 -0400
1904 @@ -48,14 +48,14 @@ resource_size_t isa_mem_base;
1905 /* Default PCI flags is 0 on ppc32, modified at boot on ppc64 */
1906 unsigned int pci_flags;
1907
1908 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1909 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1910
1911 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
1912 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
1913 {
1914 pci_dma_ops = dma_ops;
1915 }
1916
1917 -struct dma_map_ops *get_pci_dma_ops(void)
1918 +const struct dma_map_ops *get_pci_dma_ops(void)
1919 {
1920 return pci_dma_ops;
1921 }
1922 @@ -1583,7 +1583,7 @@ null_write_config(struct pci_bus *bus, u
1923 return PCIBIOS_DEVICE_NOT_FOUND;
1924 }
1925
1926 -static struct pci_ops null_pci_ops = {
1927 +static const struct pci_ops null_pci_ops = {
1928 .read = null_read_config,
1929 .write = null_write_config,
1930 };
1931 diff -urNp linux-2.6.39.1/arch/mips/alchemy/common/pci.c linux-2.6.39.1/arch/mips/alchemy/common/pci.c
1932 --- linux-2.6.39.1/arch/mips/alchemy/common/pci.c 2011-05-19 00:06:34.000000000 -0400
1933 +++ linux-2.6.39.1/arch/mips/alchemy/common/pci.c 2011-05-22 19:36:30.000000000 -0400
1934 @@ -51,7 +51,7 @@ static struct resource pci_mem_resource
1935 .flags = IORESOURCE_MEM
1936 };
1937
1938 -extern struct pci_ops au1x_pci_ops;
1939 +extern const struct pci_ops au1x_pci_ops;
1940
1941 static struct pci_controller au1x_controller = {
1942 .pci_ops = &au1x_pci_ops,
1943 diff -urNp linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c
1944 --- linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c 2011-05-19 00:06:34.000000000 -0400
1945 +++ linux-2.6.39.1/arch/mips/cavium-octeon/dma-octeon.c 2011-05-22 19:36:30.000000000 -0400
1946 @@ -202,7 +202,7 @@ static phys_addr_t octeon_unity_dma_to_p
1947 }
1948
1949 struct octeon_dma_map_ops {
1950 - struct dma_map_ops dma_map_ops;
1951 + const struct dma_map_ops dma_map_ops;
1952 dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
1953 phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
1954 };
1955 @@ -324,7 +324,7 @@ static struct octeon_dma_map_ops _octeon
1956 },
1957 };
1958
1959 -struct dma_map_ops *octeon_pci_dma_map_ops;
1960 +const struct dma_map_ops *octeon_pci_dma_map_ops;
1961
1962 void __init octeon_pci_dma_init(void)
1963 {
1964 diff -urNp linux-2.6.39.1/arch/mips/cobalt/pci.c linux-2.6.39.1/arch/mips/cobalt/pci.c
1965 --- linux-2.6.39.1/arch/mips/cobalt/pci.c 2011-05-19 00:06:34.000000000 -0400
1966 +++ linux-2.6.39.1/arch/mips/cobalt/pci.c 2011-05-22 19:36:30.000000000 -0400
1967 @@ -14,7 +14,7 @@
1968
1969 #include <asm/gt64120.h>
1970
1971 -extern struct pci_ops gt64xxx_pci0_ops;
1972 +extern const struct pci_ops gt64xxx_pci0_ops;
1973
1974 static struct resource cobalt_mem_resource = {
1975 .start = GT_DEF_PCI0_MEM0_BASE,
1976 diff -urNp linux-2.6.39.1/arch/mips/include/asm/device.h linux-2.6.39.1/arch/mips/include/asm/device.h
1977 --- linux-2.6.39.1/arch/mips/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1978 +++ linux-2.6.39.1/arch/mips/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
1979 @@ -10,7 +10,7 @@ struct dma_map_ops;
1980
1981 struct dev_archdata {
1982 /* DMA operations on that device */
1983 - struct dma_map_ops *dma_ops;
1984 + const struct dma_map_ops *dma_ops;
1985 };
1986
1987 struct pdev_archdata {
1988 diff -urNp linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h
1989 --- linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1990 +++ linux-2.6.39.1/arch/mips/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1991 @@ -9,9 +9,9 @@
1992 #include <dma-coherence.h>
1993 #endif
1994
1995 -extern struct dma_map_ops *mips_dma_map_ops;
1996 +extern const struct dma_map_ops *mips_dma_map_ops;
1997
1998 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1999 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2000 {
2001 if (dev && dev->archdata.dma_ops)
2002 return dev->archdata.dma_ops;
2003 @@ -33,13 +33,13 @@ static inline void dma_mark_clean(void *
2004
2005 static inline int dma_supported(struct device *dev, u64 mask)
2006 {
2007 - struct dma_map_ops *ops = get_dma_ops(dev);
2008 + const struct dma_map_ops *ops = get_dma_ops(dev);
2009 return ops->dma_supported(dev, mask);
2010 }
2011
2012 static inline int dma_mapping_error(struct device *dev, u64 mask)
2013 {
2014 - struct dma_map_ops *ops = get_dma_ops(dev);
2015 + const struct dma_map_ops *ops = get_dma_ops(dev);
2016 return ops->mapping_error(dev, mask);
2017 }
2018
2019 @@ -61,7 +61,7 @@ static inline void *dma_alloc_coherent(s
2020 dma_addr_t *dma_handle, gfp_t gfp)
2021 {
2022 void *ret;
2023 - struct dma_map_ops *ops = get_dma_ops(dev);
2024 + const struct dma_map_ops *ops = get_dma_ops(dev);
2025
2026 ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
2027
2028 @@ -73,7 +73,7 @@ static inline void *dma_alloc_coherent(s
2029 static inline void dma_free_coherent(struct device *dev, size_t size,
2030 void *vaddr, dma_addr_t dma_handle)
2031 {
2032 - struct dma_map_ops *ops = get_dma_ops(dev);
2033 + const struct dma_map_ops *ops = get_dma_ops(dev);
2034
2035 ops->free_coherent(dev, size, vaddr, dma_handle);
2036
2037 diff -urNp linux-2.6.39.1/arch/mips/include/asm/elf.h linux-2.6.39.1/arch/mips/include/asm/elf.h
2038 --- linux-2.6.39.1/arch/mips/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2039 +++ linux-2.6.39.1/arch/mips/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2040 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2041 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2042 #endif
2043
2044 +#ifdef CONFIG_PAX_ASLR
2045 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2046 +
2047 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2048 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2049 +#endif
2050 +
2051 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2052 struct linux_binprm;
2053 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2054 int uses_interp);
2055
2056 -struct mm_struct;
2057 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2058 -#define arch_randomize_brk arch_randomize_brk
2059 -
2060 #endif /* _ASM_ELF_H */
2061 diff -urNp linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
2062 --- linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-19 00:06:34.000000000 -0400
2063 +++ linux-2.6.39.1/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-22 19:36:30.000000000 -0400
2064 @@ -66,7 +66,7 @@ dma_addr_t phys_to_dma(struct device *de
2065 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
2066
2067 struct dma_map_ops;
2068 -extern struct dma_map_ops *octeon_pci_dma_map_ops;
2069 +extern const struct dma_map_ops *octeon_pci_dma_map_ops;
2070 extern char *octeon_swiotlb;
2071
2072 #endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
2073 diff -urNp linux-2.6.39.1/arch/mips/include/asm/page.h linux-2.6.39.1/arch/mips/include/asm/page.h
2074 --- linux-2.6.39.1/arch/mips/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
2075 +++ linux-2.6.39.1/arch/mips/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
2076 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
2077 #ifdef CONFIG_CPU_MIPS32
2078 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2079 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2080 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2081 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2082 #else
2083 typedef struct { unsigned long long pte; } pte_t;
2084 #define pte_val(x) ((x).pte)
2085 diff -urNp linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h
2086 --- linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h 2011-05-19 00:06:34.000000000 -0400
2087 +++ linux-2.6.39.1/arch/mips/include/asm/pci/bridge.h 2011-05-22 19:36:30.000000000 -0400
2088 @@ -849,6 +849,6 @@ struct bridge_controller {
2089 extern void register_bridge_irq(unsigned int irq);
2090 extern int request_bridge_irq(struct bridge_controller *bc);
2091
2092 -extern struct pci_ops bridge_pci_ops;
2093 +extern const struct pci_ops bridge_pci_ops;
2094
2095 #endif /* _ASM_PCI_BRIDGE_H */
2096 diff -urNp linux-2.6.39.1/arch/mips/include/asm/system.h linux-2.6.39.1/arch/mips/include/asm/system.h
2097 --- linux-2.6.39.1/arch/mips/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
2098 +++ linux-2.6.39.1/arch/mips/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
2099 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2100 */
2101 #define __ARCH_WANT_UNLOCKED_CTXSW
2102
2103 -extern unsigned long arch_align_stack(unsigned long sp);
2104 +#define arch_align_stack(x) ((x) & ~0xfUL)
2105
2106 #endif /* _ASM_SYSTEM_H */
2107 diff -urNp linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c
2108 --- linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c 2011-05-19 00:06:34.000000000 -0400
2109 +++ linux-2.6.39.1/arch/mips/kernel/binfmt_elfn32.c 2011-05-22 19:36:30.000000000 -0400
2110 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2111 #undef ELF_ET_DYN_BASE
2112 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2113
2114 +#ifdef CONFIG_PAX_ASLR
2115 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2116 +
2117 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2118 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2119 +#endif
2120 +
2121 #include <asm/processor.h>
2122 #include <linux/module.h>
2123 #include <linux/elfcore.h>
2124 diff -urNp linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c
2125 --- linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c 2011-05-19 00:06:34.000000000 -0400
2126 +++ linux-2.6.39.1/arch/mips/kernel/binfmt_elfo32.c 2011-05-22 19:36:30.000000000 -0400
2127 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2128 #undef ELF_ET_DYN_BASE
2129 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2130
2131 +#ifdef CONFIG_PAX_ASLR
2132 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2133 +
2134 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2135 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2136 +#endif
2137 +
2138 #include <asm/processor.h>
2139
2140 /*
2141 diff -urNp linux-2.6.39.1/arch/mips/kernel/kgdb.c linux-2.6.39.1/arch/mips/kernel/kgdb.c
2142 --- linux-2.6.39.1/arch/mips/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
2143 +++ linux-2.6.39.1/arch/mips/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
2144 @@ -351,7 +351,7 @@ int kgdb_arch_handle_exception(int vecto
2145 return -1;
2146 }
2147
2148 -struct kgdb_arch arch_kgdb_ops;
2149 +struct kgdb_arch arch_kgdb_ops; /* cannot be const, see kgdb_arch_init */
2150
2151 /*
2152 * We use kgdb_early_setup so that functions we need to call now don't
2153 diff -urNp linux-2.6.39.1/arch/mips/kernel/process.c linux-2.6.39.1/arch/mips/kernel/process.c
2154 --- linux-2.6.39.1/arch/mips/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
2155 +++ linux-2.6.39.1/arch/mips/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
2156 @@ -473,15 +473,3 @@ unsigned long get_wchan(struct task_stru
2157 out:
2158 return pc;
2159 }
2160 -
2161 -/*
2162 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2163 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2164 - */
2165 -unsigned long arch_align_stack(unsigned long sp)
2166 -{
2167 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2168 - sp -= get_random_int() & ~PAGE_MASK;
2169 -
2170 - return sp & ALMASK;
2171 -}
2172 diff -urNp linux-2.6.39.1/arch/mips/kernel/syscall.c linux-2.6.39.1/arch/mips/kernel/syscall.c
2173 --- linux-2.6.39.1/arch/mips/kernel/syscall.c 2011-05-19 00:06:34.000000000 -0400
2174 +++ linux-2.6.39.1/arch/mips/kernel/syscall.c 2011-05-22 19:36:30.000000000 -0400
2175 @@ -108,14 +108,18 @@ unsigned long arch_get_unmapped_area(str
2176 do_color_align = 0;
2177 if (filp || (flags & MAP_SHARED))
2178 do_color_align = 1;
2179 +
2180 +#ifdef CONFIG_PAX_RANDMMAP
2181 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2182 +#endif
2183 +
2184 if (addr) {
2185 if (do_color_align)
2186 addr = COLOUR_ALIGN(addr, pgoff);
2187 else
2188 addr = PAGE_ALIGN(addr);
2189 vmm = find_vma(current->mm, addr);
2190 - if (task_size - len >= addr &&
2191 - (!vmm || addr + len <= vmm->vm_start))
2192 + if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2193 return addr;
2194 }
2195 addr = current->mm->mmap_base;
2196 @@ -128,7 +132,7 @@ unsigned long arch_get_unmapped_area(str
2197 /* At this point: (!vmm || addr < vmm->vm_end). */
2198 if (task_size - len < addr)
2199 return -ENOMEM;
2200 - if (!vmm || addr + len <= vmm->vm_start)
2201 + if (check_heap_stack_gap(vmm, addr, len))
2202 return addr;
2203 addr = vmm->vm_end;
2204 if (do_color_align)
2205 @@ -154,33 +158,6 @@ void arch_pick_mmap_layout(struct mm_str
2206 mm->unmap_area = arch_unmap_area;
2207 }
2208
2209 -static inline unsigned long brk_rnd(void)
2210 -{
2211 - unsigned long rnd = get_random_int();
2212 -
2213 - rnd = rnd << PAGE_SHIFT;
2214 - /* 8MB for 32bit, 256MB for 64bit */
2215 - if (TASK_IS_32BIT_ADDR)
2216 - rnd = rnd & 0x7ffffful;
2217 - else
2218 - rnd = rnd & 0xffffffful;
2219 -
2220 - return rnd;
2221 -}
2222 -
2223 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2224 -{
2225 - unsigned long base = mm->brk;
2226 - unsigned long ret;
2227 -
2228 - ret = PAGE_ALIGN(base + brk_rnd());
2229 -
2230 - if (ret < mm->brk)
2231 - return mm->brk;
2232 -
2233 - return ret;
2234 -}
2235 -
2236 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
2237 unsigned long, prot, unsigned long, flags, unsigned long,
2238 fd, off_t, offset)
2239 diff -urNp linux-2.6.39.1/arch/mips/mm/dma-default.c linux-2.6.39.1/arch/mips/mm/dma-default.c
2240 --- linux-2.6.39.1/arch/mips/mm/dma-default.c 2011-05-19 00:06:34.000000000 -0400
2241 +++ linux-2.6.39.1/arch/mips/mm/dma-default.c 2011-05-22 19:36:30.000000000 -0400
2242 @@ -300,7 +300,7 @@ void dma_cache_sync(struct device *dev,
2243
2244 EXPORT_SYMBOL(dma_cache_sync);
2245
2246 -static struct dma_map_ops mips_default_dma_map_ops = {
2247 +static const struct dma_map_ops mips_default_dma_map_ops = {
2248 .alloc_coherent = mips_dma_alloc_coherent,
2249 .free_coherent = mips_dma_free_coherent,
2250 .map_page = mips_dma_map_page,
2251 @@ -315,7 +315,7 @@ static struct dma_map_ops mips_default_d
2252 .dma_supported = mips_dma_supported
2253 };
2254
2255 -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2256 +const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2257 EXPORT_SYMBOL(mips_dma_map_ops);
2258
2259 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
2260 diff -urNp linux-2.6.39.1/arch/mips/mm/fault.c linux-2.6.39.1/arch/mips/mm/fault.c
2261 --- linux-2.6.39.1/arch/mips/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
2262 +++ linux-2.6.39.1/arch/mips/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
2263 @@ -28,6 +28,23 @@
2264 #include <asm/highmem.h> /* For VMALLOC_END */
2265 #include <linux/kdebug.h>
2266
2267 +#ifdef CONFIG_PAX_PAGEEXEC
2268 +void pax_report_insns(void *pc, void *sp)
2269 +{
2270 + unsigned long i;
2271 +
2272 + printk(KERN_ERR "PAX: bytes at PC: ");
2273 + for (i = 0; i < 5; i++) {
2274 + unsigned int c;
2275 + if (get_user(c, (unsigned int *)pc+i))
2276 + printk(KERN_CONT "???????? ");
2277 + else
2278 + printk(KERN_CONT "%08x ", c);
2279 + }
2280 + printk("\n");
2281 +}
2282 +#endif
2283 +
2284 /*
2285 * This routine handles page faults. It determines the address,
2286 * and the problem, and then passes it off to one of the appropriate
2287 diff -urNp linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c
2288 --- linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c 2011-05-19 00:06:34.000000000 -0400
2289 +++ linux-2.6.39.1/arch/mips/mti-malta/malta-pci.c 2011-05-22 19:36:30.000000000 -0400
2290 @@ -64,9 +64,9 @@ static struct resource msc_io_resource =
2291 .flags = IORESOURCE_IO,
2292 };
2293
2294 -extern struct pci_ops bonito64_pci_ops;
2295 -extern struct pci_ops gt64xxx_pci0_ops;
2296 -extern struct pci_ops msc_pci_ops;
2297 +extern const struct pci_ops bonito64_pci_ops;
2298 +extern const struct pci_ops gt64xxx_pci0_ops;
2299 +extern const struct pci_ops msc_pci_ops;
2300
2301 static struct pci_controller bonito64_controller = {
2302 .pci_ops = &bonito64_pci_ops,
2303 diff -urNp linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c
2304 --- linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2305 +++ linux-2.6.39.1/arch/mips/nxp/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2306 @@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2307 .flags = IORESOURCE_MEM
2308 };
2309
2310 -extern struct pci_ops pnx8550_pci_ops;
2311 +extern const struct pci_ops pnx8550_pci_ops;
2312
2313 static struct pci_controller pnx8550_controller = {
2314 .pci_ops = &pnx8550_pci_ops,
2315 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-au1000.c linux-2.6.39.1/arch/mips/pci/ops-au1000.c
2316 --- linux-2.6.39.1/arch/mips/pci/ops-au1000.c 2011-05-19 00:06:34.000000000 -0400
2317 +++ linux-2.6.39.1/arch/mips/pci/ops-au1000.c 2011-05-22 19:36:30.000000000 -0400
2318 @@ -302,7 +302,7 @@ static int config_write(struct pci_bus *
2319 }
2320 }
2321
2322 -struct pci_ops au1x_pci_ops = {
2323 +const struct pci_ops au1x_pci_ops = {
2324 config_read,
2325 config_write
2326 };
2327 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c
2328 --- linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c 2011-05-19 00:06:34.000000000 -0400
2329 +++ linux-2.6.39.1/arch/mips/pci/ops-bcm63xx.c 2011-05-22 19:36:30.000000000 -0400
2330 @@ -173,7 +173,7 @@ static int bcm63xx_pci_write(struct pci_
2331 where, size, val);
2332 }
2333
2334 -struct pci_ops bcm63xx_pci_ops = {
2335 +const struct pci_ops bcm63xx_pci_ops = {
2336 .read = bcm63xx_pci_read,
2337 .write = bcm63xx_pci_write
2338 };
2339 @@ -402,7 +402,7 @@ static int bcm63xx_cb_write(struct pci_b
2340 return PCIBIOS_DEVICE_NOT_FOUND;
2341 }
2342
2343 -struct pci_ops bcm63xx_cb_ops = {
2344 +const struct pci_ops bcm63xx_cb_ops = {
2345 .read = bcm63xx_cb_read,
2346 .write = bcm63xx_cb_write,
2347 };
2348 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bonito64.c linux-2.6.39.1/arch/mips/pci/ops-bonito64.c
2349 --- linux-2.6.39.1/arch/mips/pci/ops-bonito64.c 2011-05-19 00:06:34.000000000 -0400
2350 +++ linux-2.6.39.1/arch/mips/pci/ops-bonito64.c 2011-05-22 19:36:30.000000000 -0400
2351 @@ -155,7 +155,7 @@ static int bonito64_pcibios_write(struct
2352 return PCIBIOS_SUCCESSFUL;
2353 }
2354
2355 -struct pci_ops bonito64_pci_ops = {
2356 +const struct pci_ops bonito64_pci_ops = {
2357 .read = bonito64_pcibios_read,
2358 .write = bonito64_pcibios_write
2359 };
2360 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-bridge.c linux-2.6.39.1/arch/mips/pci/ops-bridge.c
2361 --- linux-2.6.39.1/arch/mips/pci/ops-bridge.c 2011-05-19 00:06:34.000000000 -0400
2362 +++ linux-2.6.39.1/arch/mips/pci/ops-bridge.c 2011-05-22 19:36:30.000000000 -0400
2363 @@ -316,7 +316,7 @@ static int pci_write_config(struct pci_b
2364 return pci_conf0_write_config(bus, devfn, where, size, value);
2365 }
2366
2367 -struct pci_ops bridge_pci_ops = {
2368 +const struct pci_ops bridge_pci_ops = {
2369 .read = pci_read_config,
2370 .write = pci_write_config,
2371 };
2372 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c
2373 --- linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2374 +++ linux-2.6.39.1/arch/mips/pci/ops-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2375 @@ -176,7 +176,7 @@ static int pci_config_write(struct pci_b
2376 return PCIBIOS_SUCCESSFUL;
2377 }
2378
2379 -struct pci_ops emma2rh_pci_ops = {
2380 +const struct pci_ops emma2rh_pci_ops = {
2381 .read = pci_config_read,
2382 .write = pci_config_write,
2383 };
2384 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c
2385 --- linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-19 00:06:34.000000000 -0400
2386 +++ linux-2.6.39.1/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-22 19:36:30.000000000 -0400
2387 @@ -146,7 +146,7 @@ static int gt64xxx_pci0_pcibios_write(st
2388 return PCIBIOS_SUCCESSFUL;
2389 }
2390
2391 -struct pci_ops gt64xxx_pci0_ops = {
2392 +const struct pci_ops gt64xxx_pci0_ops = {
2393 .read = gt64xxx_pci0_pcibios_read,
2394 .write = gt64xxx_pci0_pcibios_write
2395 };
2396 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-loongson2.c linux-2.6.39.1/arch/mips/pci/ops-loongson2.c
2397 --- linux-2.6.39.1/arch/mips/pci/ops-loongson2.c 2011-05-19 00:06:34.000000000 -0400
2398 +++ linux-2.6.39.1/arch/mips/pci/ops-loongson2.c 2011-05-22 19:36:30.000000000 -0400
2399 @@ -174,7 +174,7 @@ static int loongson_pcibios_write(struct
2400 return PCIBIOS_SUCCESSFUL;
2401 }
2402
2403 -struct pci_ops loongson_pci_ops = {
2404 +const struct pci_ops loongson_pci_ops = {
2405 .read = loongson_pcibios_read,
2406 .write = loongson_pcibios_write
2407 };
2408 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-mace.c linux-2.6.39.1/arch/mips/pci/ops-mace.c
2409 --- linux-2.6.39.1/arch/mips/pci/ops-mace.c 2011-05-19 00:06:34.000000000 -0400
2410 +++ linux-2.6.39.1/arch/mips/pci/ops-mace.c 2011-05-22 19:36:30.000000000 -0400
2411 @@ -96,7 +96,7 @@ mace_pci_write_config(struct pci_bus *bu
2412 return PCIBIOS_SUCCESSFUL;
2413 }
2414
2415 -struct pci_ops mace_pci_ops = {
2416 +const struct pci_ops mace_pci_ops = {
2417 .read = mace_pci_read_config,
2418 .write = mace_pci_write_config,
2419 };
2420 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-msc.c linux-2.6.39.1/arch/mips/pci/ops-msc.c
2421 --- linux-2.6.39.1/arch/mips/pci/ops-msc.c 2011-05-19 00:06:34.000000000 -0400
2422 +++ linux-2.6.39.1/arch/mips/pci/ops-msc.c 2011-05-22 19:36:30.000000000 -0400
2423 @@ -142,7 +142,7 @@ static int msc_pcibios_write(struct pci_
2424 return PCIBIOS_SUCCESSFUL;
2425 }
2426
2427 -struct pci_ops msc_pci_ops = {
2428 +const struct pci_ops msc_pci_ops = {
2429 .read = msc_pcibios_read,
2430 .write = msc_pcibios_write
2431 };
2432 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-nile4.c linux-2.6.39.1/arch/mips/pci/ops-nile4.c
2433 --- linux-2.6.39.1/arch/mips/pci/ops-nile4.c 2011-05-19 00:06:34.000000000 -0400
2434 +++ linux-2.6.39.1/arch/mips/pci/ops-nile4.c 2011-05-22 19:36:30.000000000 -0400
2435 @@ -141,7 +141,7 @@ static int nile4_pcibios_write(struct pc
2436 return PCIBIOS_SUCCESSFUL;
2437 }
2438
2439 -struct pci_ops nile4_pci_ops = {
2440 +const struct pci_ops nile4_pci_ops = {
2441 .read = nile4_pcibios_read,
2442 .write = nile4_pcibios_write,
2443 };
2444 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c
2445 --- linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
2446 +++ linux-2.6.39.1/arch/mips/pci/ops-pmcmsp.c 2011-05-22 19:36:30.000000000 -0400
2447 @@ -904,7 +904,7 @@ msp_pcibios_write_config(struct pci_bus
2448 * write - function for Linux to generate PCI Configuration writes.
2449 *
2450 ****************************************************************************/
2451 -struct pci_ops msp_pci_ops = {
2452 +const struct pci_ops msp_pci_ops = {
2453 .read = msp_pcibios_read_config,
2454 .write = msp_pcibios_write_config
2455 };
2456 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c
2457 --- linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c 2011-05-19 00:06:34.000000000 -0400
2458 +++ linux-2.6.39.1/arch/mips/pci/ops-pnx8550.c 2011-05-22 19:36:30.000000000 -0400
2459 @@ -276,7 +276,7 @@ static int config_write(struct pci_bus *
2460 }
2461 }
2462
2463 -struct pci_ops pnx8550_pci_ops = {
2464 +const struct pci_ops pnx8550_pci_ops = {
2465 config_read,
2466 config_write
2467 };
2468 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-rc32434.c linux-2.6.39.1/arch/mips/pci/ops-rc32434.c
2469 --- linux-2.6.39.1/arch/mips/pci/ops-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2470 +++ linux-2.6.39.1/arch/mips/pci/ops-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2471 @@ -201,7 +201,7 @@ static int pci_config_write(struct pci_b
2472 }
2473 }
2474
2475 -struct pci_ops rc32434_pci_ops = {
2476 +const struct pci_ops rc32434_pci_ops = {
2477 .read = pci_config_read,
2478 .write = pci_config_write,
2479 };
2480 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-sni.c linux-2.6.39.1/arch/mips/pci/ops-sni.c
2481 --- linux-2.6.39.1/arch/mips/pci/ops-sni.c 2011-05-19 00:06:34.000000000 -0400
2482 +++ linux-2.6.39.1/arch/mips/pci/ops-sni.c 2011-05-22 19:36:30.000000000 -0400
2483 @@ -83,7 +83,7 @@ static int pcimt_write(struct pci_bus *b
2484 return 0;
2485 }
2486
2487 -struct pci_ops sni_pcimt_ops = {
2488 +const struct pci_ops sni_pcimt_ops = {
2489 .read = pcimt_read,
2490 .write = pcimt_write,
2491 };
2492 @@ -158,7 +158,7 @@ static int pcit_write(struct pci_bus *bu
2493 }
2494
2495
2496 -struct pci_ops sni_pcit_ops = {
2497 +const struct pci_ops sni_pcit_ops = {
2498 .read = pcit_read,
2499 .write = pcit_write,
2500 };
2501 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-titan.c linux-2.6.39.1/arch/mips/pci/ops-titan.c
2502 --- linux-2.6.39.1/arch/mips/pci/ops-titan.c 2011-05-19 00:06:34.000000000 -0400
2503 +++ linux-2.6.39.1/arch/mips/pci/ops-titan.c 2011-05-22 19:36:30.000000000 -0400
2504 @@ -105,7 +105,7 @@ static int titan_write_config(struct pci
2505 /*
2506 * Titan PCI structure
2507 */
2508 -struct pci_ops titan_pci_ops = {
2509 +const struct pci_ops titan_pci_ops = {
2510 titan_read_config,
2511 titan_write_config,
2512 };
2513 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c
2514 --- linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c 2011-05-19 00:06:34.000000000 -0400
2515 +++ linux-2.6.39.1/arch/mips/pci/ops-titan-ht.c 2011-05-22 19:36:30.000000000 -0400
2516 @@ -118,7 +118,7 @@ static int titan_ht_config_write(struct
2517 return PCIBIOS_SUCCESSFUL;
2518 }
2519
2520 -struct pci_ops titan_ht_pci_ops = {
2521 +const struct pci_ops titan_ht_pci_ops = {
2522 .read = titan_ht_config_read,
2523 .write = titan_ht_config_write,
2524 };
2525 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-tx3927.c linux-2.6.39.1/arch/mips/pci/ops-tx3927.c
2526 --- linux-2.6.39.1/arch/mips/pci/ops-tx3927.c 2011-05-19 00:06:34.000000000 -0400
2527 +++ linux-2.6.39.1/arch/mips/pci/ops-tx3927.c 2011-05-22 19:36:30.000000000 -0400
2528 @@ -121,7 +121,7 @@ static int tx3927_pci_write_config(struc
2529 return check_abort();
2530 }
2531
2532 -static struct pci_ops tx3927_pci_ops = {
2533 +static const struct pci_ops tx3927_pci_ops = {
2534 .read = tx3927_pci_read_config,
2535 .write = tx3927_pci_write_config,
2536 };
2537 diff -urNp linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c
2538 --- linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2539 +++ linux-2.6.39.1/arch/mips/pci/ops-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2540 @@ -120,7 +120,7 @@ static int pci_config_write(struct pci_b
2541 return PCIBIOS_SUCCESSFUL;
2542 }
2543
2544 -struct pci_ops vr41xx_pci_ops = {
2545 +const struct pci_ops vr41xx_pci_ops = {
2546 .read = pci_config_read,
2547 .write = pci_config_write,
2548 };
2549 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c
2550 --- linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c 2011-05-19 00:06:34.000000000 -0400
2551 +++ linux-2.6.39.1/arch/mips/pci/pci-bcm1480.c 2011-05-22 19:36:30.000000000 -0400
2552 @@ -171,7 +171,7 @@ static int bcm1480_pcibios_write(struct
2553 return PCIBIOS_SUCCESSFUL;
2554 }
2555
2556 -struct pci_ops bcm1480_pci_ops = {
2557 +const struct pci_ops bcm1480_pci_ops = {
2558 bcm1480_pcibios_read,
2559 bcm1480_pcibios_write,
2560 };
2561 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c
2562 --- linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c 2011-05-19 00:06:34.000000000 -0400
2563 +++ linux-2.6.39.1/arch/mips/pci/pci-bcm1480ht.c 2011-05-22 19:36:30.000000000 -0400
2564 @@ -166,7 +166,7 @@ static int bcm1480ht_pcibios_get_busno(v
2565 return 0;
2566 }
2567
2568 -struct pci_ops bcm1480ht_pci_ops = {
2569 +const struct pci_ops bcm1480ht_pci_ops = {
2570 .read = bcm1480ht_pcibios_read,
2571 .write = bcm1480ht_pcibios_write,
2572 };
2573 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h
2574 --- linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h 2011-05-19 00:06:34.000000000 -0400
2575 +++ linux-2.6.39.1/arch/mips/pci/pci-bcm63xx.h 2011-05-22 19:36:30.000000000 -0400
2576 @@ -16,8 +16,8 @@
2577 /*
2578 * defined in ops-bcm63xx.c
2579 */
2580 -extern struct pci_ops bcm63xx_pci_ops;
2581 -extern struct pci_ops bcm63xx_cb_ops;
2582 +extern const struct pci_ops bcm63xx_pci_ops;
2583 +extern const struct pci_ops bcm63xx_cb_ops;
2584
2585 /*
2586 * defined in pci-bcm63xx.c
2587 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c
2588 --- linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2589 +++ linux-2.6.39.1/arch/mips/pci/pci-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2590 @@ -43,7 +43,7 @@ static struct resource pci_mem_resource
2591 .flags = IORESOURCE_MEM,
2592 };
2593
2594 -extern struct pci_ops emma2rh_pci_ops;
2595 +extern const struct pci_ops emma2rh_pci_ops;
2596
2597 static struct pci_controller emma2rh_pci_controller = {
2598 .pci_ops = &emma2rh_pci_ops,
2599 diff -urNp linux-2.6.39.1/arch/mips/pci/pcie-octeon.c linux-2.6.39.1/arch/mips/pci/pcie-octeon.c
2600 --- linux-2.6.39.1/arch/mips/pci/pcie-octeon.c 2011-05-19 00:06:34.000000000 -0400
2601 +++ linux-2.6.39.1/arch/mips/pci/pcie-octeon.c 2011-05-22 19:36:30.000000000 -0400
2602 @@ -1237,7 +1237,7 @@ static int octeon_pcie1_write_config(str
2603 return octeon_pcie_write_config(1, bus, devfn, reg, size, val);
2604 }
2605
2606 -static struct pci_ops octeon_pcie0_ops = {
2607 +static const struct pci_ops octeon_pcie0_ops = {
2608 octeon_pcie0_read_config,
2609 octeon_pcie0_write_config,
2610 };
2611 @@ -1258,7 +1258,7 @@ static struct pci_controller octeon_pcie
2612 .io_resource = &octeon_pcie0_io_resource,
2613 };
2614
2615 -static struct pci_ops octeon_pcie1_ops = {
2616 +static const struct pci_ops octeon_pcie1_ops = {
2617 octeon_pcie1_read_config,
2618 octeon_pcie1_write_config,
2619 };
2620 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-ip27.c linux-2.6.39.1/arch/mips/pci/pci-ip27.c
2621 --- linux-2.6.39.1/arch/mips/pci/pci-ip27.c 2011-05-19 00:06:34.000000000 -0400
2622 +++ linux-2.6.39.1/arch/mips/pci/pci-ip27.c 2011-05-22 19:36:30.000000000 -0400
2623 @@ -39,7 +39,7 @@ static struct bridge_controller bridges[
2624 struct bridge_controller *irq_to_bridge[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2625 int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2626
2627 -extern struct pci_ops bridge_pci_ops;
2628 +extern const struct pci_ops bridge_pci_ops;
2629
2630 int __cpuinit bridge_probe(nasid_t nasid, int widget_id, int masterwid)
2631 {
2632 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-ip32.c linux-2.6.39.1/arch/mips/pci/pci-ip32.c
2633 --- linux-2.6.39.1/arch/mips/pci/pci-ip32.c 2011-05-19 00:06:34.000000000 -0400
2634 +++ linux-2.6.39.1/arch/mips/pci/pci-ip32.c 2011-05-22 19:36:30.000000000 -0400
2635 @@ -82,7 +82,7 @@ static irqreturn_t macepci_error(int irq
2636 }
2637
2638
2639 -extern struct pci_ops mace_pci_ops;
2640 +extern const struct pci_ops mace_pci_ops;
2641 #ifdef CONFIG_64BIT
2642 static struct resource mace_pci_mem_resource = {
2643 .name = "SGI O2 PCI MEM",
2644 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-lasat.c linux-2.6.39.1/arch/mips/pci/pci-lasat.c
2645 --- linux-2.6.39.1/arch/mips/pci/pci-lasat.c 2011-05-19 00:06:34.000000000 -0400
2646 +++ linux-2.6.39.1/arch/mips/pci/pci-lasat.c 2011-05-22 19:36:30.000000000 -0400
2647 @@ -14,8 +14,8 @@
2648
2649 #include <irq.h>
2650
2651 -extern struct pci_ops nile4_pci_ops;
2652 -extern struct pci_ops gt64xxx_pci0_ops;
2653 +extern const struct pci_ops nile4_pci_ops;
2654 +extern const struct pci_ops gt64xxx_pci0_ops;
2655 static struct resource lasat_pci_mem_resource = {
2656 .name = "LASAT PCI MEM",
2657 .start = 0x18000000,
2658 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-octeon.c linux-2.6.39.1/arch/mips/pci/pci-octeon.c
2659 --- linux-2.6.39.1/arch/mips/pci/pci-octeon.c 2011-05-19 00:06:34.000000000 -0400
2660 +++ linux-2.6.39.1/arch/mips/pci/pci-octeon.c 2011-05-22 19:36:30.000000000 -0400
2661 @@ -334,7 +334,7 @@ static int octeon_write_config(struct pc
2662 }
2663
2664
2665 -static struct pci_ops octeon_pci_ops = {
2666 +static const struct pci_ops octeon_pci_ops = {
2667 octeon_read_config,
2668 octeon_write_config,
2669 };
2670 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-rc32434.c linux-2.6.39.1/arch/mips/pci/pci-rc32434.c
2671 --- linux-2.6.39.1/arch/mips/pci/pci-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2672 +++ linux-2.6.39.1/arch/mips/pci/pci-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2673 @@ -75,7 +75,7 @@ static struct resource rc32434_res_pci_i
2674 .flags = IORESOURCE_IO,
2675 };
2676
2677 -extern struct pci_ops rc32434_pci_ops;
2678 +extern const struct pci_ops rc32434_pci_ops;
2679
2680 #define PCI_MEM1_START PCI_ADDR_START
2681 #define PCI_MEM1_END (PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1)
2682 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-sb1250.c linux-2.6.39.1/arch/mips/pci/pci-sb1250.c
2683 --- linux-2.6.39.1/arch/mips/pci/pci-sb1250.c 2011-05-19 00:06:34.000000000 -0400
2684 +++ linux-2.6.39.1/arch/mips/pci/pci-sb1250.c 2011-05-22 19:36:30.000000000 -0400
2685 @@ -181,7 +181,7 @@ static int sb1250_pcibios_write(struct p
2686 return PCIBIOS_SUCCESSFUL;
2687 }
2688
2689 -struct pci_ops sb1250_pci_ops = {
2690 +const struct pci_ops sb1250_pci_ops = {
2691 .read = sb1250_pcibios_read,
2692 .write = sb1250_pcibios_write,
2693 };
2694 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c
2695 --- linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2696 +++ linux-2.6.39.1/arch/mips/pci/pci-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2697 @@ -36,7 +36,7 @@
2698
2699 #include "pci-vr41xx.h"
2700
2701 -extern struct pci_ops vr41xx_pci_ops;
2702 +extern const struct pci_ops vr41xx_pci_ops;
2703
2704 static void __iomem *pciu_base;
2705
2706 diff -urNp linux-2.6.39.1/arch/mips/pci/pci-yosemite.c linux-2.6.39.1/arch/mips/pci/pci-yosemite.c
2707 --- linux-2.6.39.1/arch/mips/pci/pci-yosemite.c 2011-05-19 00:06:34.000000000 -0400
2708 +++ linux-2.6.39.1/arch/mips/pci/pci-yosemite.c 2011-05-22 19:36:30.000000000 -0400
2709 @@ -11,7 +11,7 @@
2710 #include <linux/pci.h>
2711 #include <asm/titan_dep.h>
2712
2713 -extern struct pci_ops titan_pci_ops;
2714 +extern const struct pci_ops titan_pci_ops;
2715
2716 static struct resource py_mem_resource = {
2717 .start = 0xe0000000UL,
2718 diff -urNp linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c
2719 --- linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-19 00:06:34.000000000 -0400
2720 +++ linux-2.6.39.1/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-22 19:36:30.000000000 -0400
2721 @@ -366,7 +366,7 @@ resource_size_t pcibios_align_resource(v
2722 return start;
2723 }
2724
2725 -struct pci_ops titan_pci_ops = {
2726 +const struct pci_ops titan_pci_ops = {
2727 titan_ht_config_read_byte,
2728 titan_ht_config_read_word,
2729 titan_ht_config_read_dword,
2730 diff -urNp linux-2.6.39.1/arch/mips/pnx8550/common/pci.c linux-2.6.39.1/arch/mips/pnx8550/common/pci.c
2731 --- linux-2.6.39.1/arch/mips/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2732 +++ linux-2.6.39.1/arch/mips/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2733 @@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2734 .flags = IORESOURCE_MEM
2735 };
2736
2737 -extern struct pci_ops pnx8550_pci_ops;
2738 +extern const struct pci_ops pnx8550_pci_ops;
2739
2740 static struct pci_controller pnx8550_controller = {
2741 .pci_ops = &pnx8550_pci_ops,
2742 diff -urNp linux-2.6.39.1/arch/mips/sni/pcimt.c linux-2.6.39.1/arch/mips/sni/pcimt.c
2743 --- linux-2.6.39.1/arch/mips/sni/pcimt.c 2011-05-19 00:06:34.000000000 -0400
2744 +++ linux-2.6.39.1/arch/mips/sni/pcimt.c 2011-05-22 19:36:30.000000000 -0400
2745 @@ -183,7 +183,7 @@ static void __init sni_pcimt_resource_in
2746 request_resource(&sni_mem_resource, pcimt_mem_resources + i);
2747 }
2748
2749 -extern struct pci_ops sni_pcimt_ops;
2750 +extern const struct pci_ops sni_pcimt_ops;
2751
2752 static struct pci_controller sni_controller = {
2753 .pci_ops = &sni_pcimt_ops,
2754 diff -urNp linux-2.6.39.1/arch/mips/sni/pcit.c linux-2.6.39.1/arch/mips/sni/pcit.c
2755 --- linux-2.6.39.1/arch/mips/sni/pcit.c 2011-05-19 00:06:34.000000000 -0400
2756 +++ linux-2.6.39.1/arch/mips/sni/pcit.c 2011-05-22 19:36:30.000000000 -0400
2757 @@ -145,7 +145,7 @@ static void __init sni_pcit_resource_ini
2758 }
2759
2760
2761 -extern struct pci_ops sni_pcit_ops;
2762 +extern const struct pci_ops sni_pcit_ops;
2763
2764 static struct pci_controller sni_pcit_controller = {
2765 .pci_ops = &sni_pcit_ops,
2766 diff -urNp linux-2.6.39.1/arch/mips/wrppmc/pci.c linux-2.6.39.1/arch/mips/wrppmc/pci.c
2767 --- linux-2.6.39.1/arch/mips/wrppmc/pci.c 2011-05-19 00:06:34.000000000 -0400
2768 +++ linux-2.6.39.1/arch/mips/wrppmc/pci.c 2011-05-22 19:36:30.000000000 -0400
2769 @@ -14,7 +14,7 @@
2770
2771 #include <asm/gt64120.h>
2772
2773 -extern struct pci_ops gt64xxx_pci0_ops;
2774 +extern const struct pci_ops gt64xxx_pci0_ops;
2775
2776 static struct resource pci0_io_resource = {
2777 .name = "pci_0 io",
2778 diff -urNp linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h
2779 --- linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-19 00:06:34.000000000 -0400
2780 +++ linux-2.6.39.1/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-22 19:36:30.000000000 -0400
2781 @@ -39,7 +39,7 @@ extern void pcibios_resource_survey(void
2782
2783 extern int pcibios_last_bus;
2784 extern struct pci_bus *pci_root_bus;
2785 -extern struct pci_ops *pci_root_ops;
2786 +extern const struct pci_ops *pci_root_ops;
2787
2788 extern struct irq_routing_table *pcibios_get_irq_routing_table(void);
2789 extern int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
2790 diff -urNp linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c
2791 --- linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c 2011-05-19 00:06:34.000000000 -0400
2792 +++ linux-2.6.39.1/arch/mn10300/unit-asb2305/pci.c 2011-05-22 19:36:30.000000000 -0400
2793 @@ -24,7 +24,7 @@ unsigned int pci_probe = 1;
2794
2795 int pcibios_last_bus = -1;
2796 struct pci_bus *pci_root_bus;
2797 -struct pci_ops *pci_root_ops;
2798 +const struct pci_ops *pci_root_ops;
2799
2800 /*
2801 * The accessible PCI window does not cover the entire CPU address space, but
2802 @@ -274,7 +274,7 @@ static int pci_ampci_write_config(struct
2803 }
2804 }
2805
2806 -static struct pci_ops pci_direct_ampci = {
2807 +static const struct pci_ops pci_direct_ampci = {
2808 pci_ampci_read_config,
2809 pci_ampci_write_config,
2810 };
2811 @@ -289,7 +289,7 @@ static struct pci_ops pci_direct_ampci =
2812 * This should be close to trivial, but it isn't, because there are buggy
2813 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
2814 */
2815 -static int __init pci_sanity_check(struct pci_ops *o)
2816 +static int __init pci_sanity_check(const struct pci_ops *o)
2817 {
2818 struct pci_bus bus; /* Fake bus and device */
2819 u32 x;
2820 diff -urNp linux-2.6.39.1/arch/parisc/include/asm/elf.h linux-2.6.39.1/arch/parisc/include/asm/elf.h
2821 --- linux-2.6.39.1/arch/parisc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2822 +++ linux-2.6.39.1/arch/parisc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2823 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration..
2824
2825 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2826
2827 +#ifdef CONFIG_PAX_ASLR
2828 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2829 +
2830 +#define PAX_DELTA_MMAP_LEN 16
2831 +#define PAX_DELTA_STACK_LEN 16
2832 +#endif
2833 +
2834 /* This yields a mask that user programs can use to figure out what
2835 instruction set this CPU supports. This could be done in user space,
2836 but it's not easy, and we've already done it here. */
2837 diff -urNp linux-2.6.39.1/arch/parisc/include/asm/pgtable.h linux-2.6.39.1/arch/parisc/include/asm/pgtable.h
2838 --- linux-2.6.39.1/arch/parisc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
2839 +++ linux-2.6.39.1/arch/parisc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
2840 @@ -207,6 +207,17 @@ struct vm_area_struct;
2841 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2842 #define PAGE_COPY PAGE_EXECREAD
2843 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2844 +
2845 +#ifdef CONFIG_PAX_PAGEEXEC
2846 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2847 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2848 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2849 +#else
2850 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2851 +# define PAGE_COPY_NOEXEC PAGE_COPY
2852 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2853 +#endif
2854 +
2855 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2856 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2857 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2858 diff -urNp linux-2.6.39.1/arch/parisc/kernel/module.c linux-2.6.39.1/arch/parisc/kernel/module.c
2859 --- linux-2.6.39.1/arch/parisc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
2860 +++ linux-2.6.39.1/arch/parisc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
2861 @@ -96,16 +96,38 @@
2862
2863 /* three functions to determine where in the module core
2864 * or init pieces the location is */
2865 +static inline int in_init_rx(struct module *me, void *loc)
2866 +{
2867 + return (loc >= me->module_init_rx &&
2868 + loc < (me->module_init_rx + me->init_size_rx));
2869 +}
2870 +
2871 +static inline int in_init_rw(struct module *me, void *loc)
2872 +{
2873 + return (loc >= me->module_init_rw &&
2874 + loc < (me->module_init_rw + me->init_size_rw));
2875 +}
2876 +
2877 static inline int in_init(struct module *me, void *loc)
2878 {
2879 - return (loc >= me->module_init &&
2880 - loc <= (me->module_init + me->init_size));
2881 + return in_init_rx(me, loc) || in_init_rw(me, loc);
2882 +}
2883 +
2884 +static inline int in_core_rx(struct module *me, void *loc)
2885 +{
2886 + return (loc >= me->module_core_rx &&
2887 + loc < (me->module_core_rx + me->core_size_rx));
2888 +}
2889 +
2890 +static inline int in_core_rw(struct module *me, void *loc)
2891 +{
2892 + return (loc >= me->module_core_rw &&
2893 + loc < (me->module_core_rw + me->core_size_rw));
2894 }
2895
2896 static inline int in_core(struct module *me, void *loc)
2897 {
2898 - return (loc >= me->module_core &&
2899 - loc <= (me->module_core + me->core_size));
2900 + return in_core_rx(me, loc) || in_core_rw(me, loc);
2901 }
2902
2903 static inline int in_local(struct module *me, void *loc)
2904 @@ -365,13 +387,13 @@ int module_frob_arch_sections(CONST Elf_
2905 }
2906
2907 /* align things a bit */
2908 - me->core_size = ALIGN(me->core_size, 16);
2909 - me->arch.got_offset = me->core_size;
2910 - me->core_size += gots * sizeof(struct got_entry);
2911 -
2912 - me->core_size = ALIGN(me->core_size, 16);
2913 - me->arch.fdesc_offset = me->core_size;
2914 - me->core_size += fdescs * sizeof(Elf_Fdesc);
2915 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2916 + me->arch.got_offset = me->core_size_rw;
2917 + me->core_size_rw += gots * sizeof(struct got_entry);
2918 +
2919 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2920 + me->arch.fdesc_offset = me->core_size_rw;
2921 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2922
2923 me->arch.got_max = gots;
2924 me->arch.fdesc_max = fdescs;
2925 @@ -389,7 +411,7 @@ static Elf64_Word get_got(struct module
2926
2927 BUG_ON(value == 0);
2928
2929 - got = me->module_core + me->arch.got_offset;
2930 + got = me->module_core_rw + me->arch.got_offset;
2931 for (i = 0; got[i].addr; i++)
2932 if (got[i].addr == value)
2933 goto out;
2934 @@ -407,7 +429,7 @@ static Elf64_Word get_got(struct module
2935 #ifdef CONFIG_64BIT
2936 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2937 {
2938 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2939 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2940
2941 if (!value) {
2942 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2943 @@ -425,7 +447,7 @@ static Elf_Addr get_fdesc(struct module
2944
2945 /* Create new one */
2946 fdesc->addr = value;
2947 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2948 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2949 return (Elf_Addr)fdesc;
2950 }
2951 #endif /* CONFIG_64BIT */
2952 @@ -849,7 +871,7 @@ register_unwind_table(struct module *me,
2953
2954 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2955 end = table + sechdrs[me->arch.unwind_section].sh_size;
2956 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2957 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2958
2959 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2960 me->arch.unwind_section, table, end, gp);
2961 diff -urNp linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c
2962 --- linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c 2011-05-19 00:06:34.000000000 -0400
2963 +++ linux-2.6.39.1/arch/parisc/kernel/sys_parisc.c 2011-05-22 19:36:30.000000000 -0400
2964 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
2965 /* At this point: (!vma || addr < vma->vm_end). */
2966 if (TASK_SIZE - len < addr)
2967 return -ENOMEM;
2968 - if (!vma || addr + len <= vma->vm_start)
2969 + if (check_heap_stack_gap(vma, addr, len))
2970 return addr;
2971 addr = vma->vm_end;
2972 }
2973 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
2974 /* At this point: (!vma || addr < vma->vm_end). */
2975 if (TASK_SIZE - len < addr)
2976 return -ENOMEM;
2977 - if (!vma || addr + len <= vma->vm_start)
2978 + if (check_heap_stack_gap(vma, addr, len))
2979 return addr;
2980 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2981 if (addr < vma->vm_end) /* handle wraparound */
2982 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
2983 if (flags & MAP_FIXED)
2984 return addr;
2985 if (!addr)
2986 - addr = TASK_UNMAPPED_BASE;
2987 + addr = current->mm->mmap_base;
2988
2989 if (filp) {
2990 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2991 diff -urNp linux-2.6.39.1/arch/parisc/kernel/traps.c linux-2.6.39.1/arch/parisc/kernel/traps.c
2992 --- linux-2.6.39.1/arch/parisc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
2993 +++ linux-2.6.39.1/arch/parisc/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
2994 @@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
2995
2996 down_read(&current->mm->mmap_sem);
2997 vma = find_vma(current->mm,regs->iaoq[0]);
2998 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2999 - && (vma->vm_flags & VM_EXEC)) {
3000 -
3001 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3002 fault_address = regs->iaoq[0];
3003 fault_space = regs->iasq[0];
3004
3005 diff -urNp linux-2.6.39.1/arch/parisc/mm/fault.c linux-2.6.39.1/arch/parisc/mm/fault.c
3006 --- linux-2.6.39.1/arch/parisc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
3007 +++ linux-2.6.39.1/arch/parisc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
3008 @@ -15,6 +15,7 @@
3009 #include <linux/sched.h>
3010 #include <linux/interrupt.h>
3011 #include <linux/module.h>
3012 +#include <linux/unistd.h>
3013
3014 #include <asm/uaccess.h>
3015 #include <asm/traps.h>
3016 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
3017 static unsigned long
3018 parisc_acctyp(unsigned long code, unsigned int inst)
3019 {
3020 - if (code == 6 || code == 16)
3021 + if (code == 6 || code == 7 || code == 16)
3022 return VM_EXEC;
3023
3024 switch (inst & 0xf0000000) {
3025 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
3026 }
3027 #endif
3028
3029 +#ifdef CONFIG_PAX_PAGEEXEC
3030 +/*
3031 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3032 + *
3033 + * returns 1 when task should be killed
3034 + * 2 when rt_sigreturn trampoline was detected
3035 + * 3 when unpatched PLT trampoline was detected
3036 + */
3037 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3038 +{
3039 +
3040 +#ifdef CONFIG_PAX_EMUPLT
3041 + int err;
3042 +
3043 + do { /* PaX: unpatched PLT emulation */
3044 + unsigned int bl, depwi;
3045 +
3046 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3047 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3048 +
3049 + if (err)
3050 + break;
3051 +
3052 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3053 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3054 +
3055 + err = get_user(ldw, (unsigned int *)addr);
3056 + err |= get_user(bv, (unsigned int *)(addr+4));
3057 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3058 +
3059 + if (err)
3060 + break;
3061 +
3062 + if (ldw == 0x0E801096U &&
3063 + bv == 0xEAC0C000U &&
3064 + ldw2 == 0x0E881095U)
3065 + {
3066 + unsigned int resolver, map;
3067 +
3068 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3069 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3070 + if (err)
3071 + break;
3072 +
3073 + regs->gr[20] = instruction_pointer(regs)+8;
3074 + regs->gr[21] = map;
3075 + regs->gr[22] = resolver;
3076 + regs->iaoq[0] = resolver | 3UL;
3077 + regs->iaoq[1] = regs->iaoq[0] + 4;
3078 + return 3;
3079 + }
3080 + }
3081 + } while (0);
3082 +#endif
3083 +
3084 +#ifdef CONFIG_PAX_EMUTRAMP
3085 +
3086 +#ifndef CONFIG_PAX_EMUSIGRT
3087 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3088 + return 1;
3089 +#endif
3090 +
3091 + do { /* PaX: rt_sigreturn emulation */
3092 + unsigned int ldi1, ldi2, bel, nop;
3093 +
3094 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3095 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3096 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3097 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3098 +
3099 + if (err)
3100 + break;
3101 +
3102 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3103 + ldi2 == 0x3414015AU &&
3104 + bel == 0xE4008200U &&
3105 + nop == 0x08000240U)
3106 + {
3107 + regs->gr[25] = (ldi1 & 2) >> 1;
3108 + regs->gr[20] = __NR_rt_sigreturn;
3109 + regs->gr[31] = regs->iaoq[1] + 16;
3110 + regs->sr[0] = regs->iasq[1];
3111 + regs->iaoq[0] = 0x100UL;
3112 + regs->iaoq[1] = regs->iaoq[0] + 4;
3113 + regs->iasq[0] = regs->sr[2];
3114 + regs->iasq[1] = regs->sr[2];
3115 + return 2;
3116 + }
3117 + } while (0);
3118 +#endif
3119 +
3120 + return 1;
3121 +}
3122 +
3123 +void pax_report_insns(void *pc, void *sp)
3124 +{
3125 + unsigned long i;
3126 +
3127 + printk(KERN_ERR "PAX: bytes at PC: ");
3128 + for (i = 0; i < 5; i++) {
3129 + unsigned int c;
3130 + if (get_user(c, (unsigned int *)pc+i))
3131 + printk(KERN_CONT "???????? ");
3132 + else
3133 + printk(KERN_CONT "%08x ", c);
3134 + }
3135 + printk("\n");
3136 +}
3137 +#endif
3138 +
3139 int fixup_exception(struct pt_regs *regs)
3140 {
3141 const struct exception_table_entry *fix;
3142 @@ -192,8 +303,33 @@ good_area:
3143
3144 acc_type = parisc_acctyp(code,regs->iir);
3145
3146 - if ((vma->vm_flags & acc_type) != acc_type)
3147 + if ((vma->vm_flags & acc_type) != acc_type) {
3148 +
3149 +#ifdef CONFIG_PAX_PAGEEXEC
3150 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3151 + (address & ~3UL) == instruction_pointer(regs))
3152 + {
3153 + up_read(&mm->mmap_sem);
3154 + switch (pax_handle_fetch_fault(regs)) {
3155 +
3156 +#ifdef CONFIG_PAX_EMUPLT
3157 + case 3:
3158 + return;
3159 +#endif
3160 +
3161 +#ifdef CONFIG_PAX_EMUTRAMP
3162 + case 2:
3163 + return;
3164 +#endif
3165 +
3166 + }
3167 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3168 + do_group_exit(SIGKILL);
3169 + }
3170 +#endif
3171 +
3172 goto bad_area;
3173 + }
3174
3175 /*
3176 * If for any reason at all we couldn't handle the fault, make
3177 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/device.h linux-2.6.39.1/arch/powerpc/include/asm/device.h
3178 --- linux-2.6.39.1/arch/powerpc/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
3179 +++ linux-2.6.39.1/arch/powerpc/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
3180 @@ -17,7 +17,7 @@ struct device_node;
3181 */
3182 struct dev_archdata {
3183 /* DMA operations on that device */
3184 - struct dma_map_ops *dma_ops;
3185 + const struct dma_map_ops *dma_ops;
3186
3187 /*
3188 * When an iommu is in use, dma_data is used as a ptr to the base of the
3189 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h
3190 --- linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3191 +++ linux-2.6.39.1/arch/powerpc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
3192 @@ -67,12 +67,13 @@ static inline unsigned long device_to_ma
3193 /*
3194 * Available generic sets of operations
3195 */
3196 +/* cannot be const */
3197 #ifdef CONFIG_PPC64
3198 -extern struct dma_map_ops dma_iommu_ops;
3199 +extern const struct dma_map_ops dma_iommu_ops;
3200 #endif
3201 -extern struct dma_map_ops dma_direct_ops;
3202 +extern const struct dma_map_ops dma_direct_ops;
3203
3204 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3205 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3206 {
3207 /* We don't handle the NULL dev case for ISA for now. We could
3208 * do it via an out of line call but it is not needed for now. The
3209 @@ -85,7 +86,7 @@ static inline struct dma_map_ops *get_dm
3210 return dev->archdata.dma_ops;
3211 }
3212
3213 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
3214 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
3215 {
3216 dev->archdata.dma_ops = ops;
3217 }
3218 @@ -119,7 +120,7 @@ static inline void set_dma_offset(struct
3219
3220 static inline int dma_supported(struct device *dev, u64 mask)
3221 {
3222 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3223 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3224
3225 if (unlikely(dma_ops == NULL))
3226 return 0;
3227 @@ -133,7 +134,7 @@ extern int dma_set_mask(struct device *d
3228 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3229 dma_addr_t *dma_handle, gfp_t flag)
3230 {
3231 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3232 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3233 void *cpu_addr;
3234
3235 BUG_ON(!dma_ops);
3236 @@ -148,7 +149,7 @@ static inline void *dma_alloc_coherent(s
3237 static inline void dma_free_coherent(struct device *dev, size_t size,
3238 void *cpu_addr, dma_addr_t dma_handle)
3239 {
3240 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3241 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3242
3243 BUG_ON(!dma_ops);
3244
3245 @@ -159,7 +160,7 @@ static inline void dma_free_coherent(str
3246
3247 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
3248 {
3249 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3250 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3251
3252 if (dma_ops->mapping_error)
3253 return dma_ops->mapping_error(dev, dma_addr);
3254 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/elf.h linux-2.6.39.1/arch/powerpc/include/asm/elf.h
3255 --- linux-2.6.39.1/arch/powerpc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
3256 +++ linux-2.6.39.1/arch/powerpc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
3257 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
3258 the loader. We need to make sure that it is out of the way of the program
3259 that it will "exec", and that there is sufficient room for the brk. */
3260
3261 -extern unsigned long randomize_et_dyn(unsigned long base);
3262 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3263 +#define ELF_ET_DYN_BASE (0x20000000)
3264 +
3265 +#ifdef CONFIG_PAX_ASLR
3266 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3267 +
3268 +#ifdef __powerpc64__
3269 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3270 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3271 +#else
3272 +#define PAX_DELTA_MMAP_LEN 15
3273 +#define PAX_DELTA_STACK_LEN 15
3274 +#endif
3275 +#endif
3276
3277 /*
3278 * Our registers are always unsigned longs, whether we're a 32 bit
3279 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(s
3280 (0x7ff >> (PAGE_SHIFT - 12)) : \
3281 (0x3ffff >> (PAGE_SHIFT - 12)))
3282
3283 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3284 -#define arch_randomize_brk arch_randomize_brk
3285 -
3286 #endif /* __KERNEL__ */
3287
3288 /*
3289 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/iommu.h linux-2.6.39.1/arch/powerpc/include/asm/iommu.h
3290 --- linux-2.6.39.1/arch/powerpc/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
3291 +++ linux-2.6.39.1/arch/powerpc/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
3292 @@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
3293 extern void iommu_init_early_dart(void);
3294 extern void iommu_init_early_pasemi(void);
3295
3296 +/* dma-iommu.c */
3297 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
3298 +
3299 #ifdef CONFIG_PCI
3300 extern void pci_iommu_init(void);
3301 extern void pci_direct_iommu_init(void);
3302 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h
3303 --- linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
3304 +++ linux-2.6.39.1/arch/powerpc/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
3305 @@ -27,6 +27,7 @@ enum km_type {
3306 KM_PPC_SYNC_PAGE,
3307 KM_PPC_SYNC_ICACHE,
3308 KM_KDB,
3309 + KM_CLEARPAGE,
3310 KM_TYPE_NR
3311 };
3312
3313 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/page_64.h linux-2.6.39.1/arch/powerpc/include/asm/page_64.h
3314 --- linux-2.6.39.1/arch/powerpc/include/asm/page_64.h 2011-05-19 00:06:34.000000000 -0400
3315 +++ linux-2.6.39.1/arch/powerpc/include/asm/page_64.h 2011-05-22 19:36:30.000000000 -0400
3316 @@ -172,15 +172,18 @@ do { \
3317 * stack by default, so in the absence of a PT_GNU_STACK program header
3318 * we turn execute permission off.
3319 */
3320 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3321 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3322 +#define VM_STACK_DEFAULT_FLAGS32 \
3323 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3324 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3325
3326 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3327 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3328
3329 +#ifndef CONFIG_PAX_PAGEEXEC
3330 #define VM_STACK_DEFAULT_FLAGS \
3331 (is_32bit_task() ? \
3332 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3333 +#endif
3334
3335 #include <asm-generic/getorder.h>
3336
3337 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/page.h linux-2.6.39.1/arch/powerpc/include/asm/page.h
3338 --- linux-2.6.39.1/arch/powerpc/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
3339 +++ linux-2.6.39.1/arch/powerpc/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
3340 @@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
3341 * and needs to be executable. This means the whole heap ends
3342 * up being executable.
3343 */
3344 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3345 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3346 +#define VM_DATA_DEFAULT_FLAGS32 \
3347 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3348 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3349
3350 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3351 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3352 @@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
3353 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3354 #endif
3355
3356 +#define ktla_ktva(addr) (addr)
3357 +#define ktva_ktla(addr) (addr)
3358 +
3359 #ifndef __ASSEMBLY__
3360
3361 #undef STRICT_MM_TYPECHECKS
3362 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pci.h linux-2.6.39.1/arch/powerpc/include/asm/pci.h
3363 --- linux-2.6.39.1/arch/powerpc/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
3364 +++ linux-2.6.39.1/arch/powerpc/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
3365 @@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
3366 }
3367
3368 #ifdef CONFIG_PCI
3369 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
3370 -extern struct dma_map_ops *get_pci_dma_ops(void);
3371 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
3372 +extern const struct dma_map_ops *get_pci_dma_ops(void);
3373 #else /* CONFIG_PCI */
3374 #define set_pci_dma_ops(d)
3375 #define get_pci_dma_ops() NULL
3376 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h
3377 --- linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
3378 +++ linux-2.6.39.1/arch/powerpc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
3379 @@ -2,6 +2,7 @@
3380 #define _ASM_POWERPC_PGTABLE_H
3381 #ifdef __KERNEL__
3382
3383 +#include <linux/const.h>
3384 #ifndef __ASSEMBLY__
3385 #include <asm/processor.h> /* For TASK_SIZE */
3386 #include <asm/mmu.h>
3387 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h
3388 --- linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h 2011-05-19 00:06:34.000000000 -0400
3389 +++ linux-2.6.39.1/arch/powerpc/include/asm/pte-hash32.h 2011-05-22 19:36:30.000000000 -0400
3390 @@ -21,6 +21,7 @@
3391 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3392 #define _PAGE_USER 0x004 /* usermode access allowed */
3393 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3394 +#define _PAGE_EXEC _PAGE_GUARDED
3395 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3396 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3397 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3398 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/reg.h linux-2.6.39.1/arch/powerpc/include/asm/reg.h
3399 --- linux-2.6.39.1/arch/powerpc/include/asm/reg.h 2011-05-19 00:06:34.000000000 -0400
3400 +++ linux-2.6.39.1/arch/powerpc/include/asm/reg.h 2011-05-22 19:36:30.000000000 -0400
3401 @@ -201,6 +201,7 @@
3402 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3403 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3404 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3405 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3406 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3407 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3408 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3409 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h
3410 --- linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h 2011-05-19 00:06:34.000000000 -0400
3411 +++ linux-2.6.39.1/arch/powerpc/include/asm/swiotlb.h 2011-05-22 19:36:30.000000000 -0400
3412 @@ -13,7 +13,7 @@
3413
3414 #include <linux/swiotlb.h>
3415
3416 -extern struct dma_map_ops swiotlb_dma_ops;
3417 +extern const struct dma_map_ops swiotlb_dma_ops;
3418
3419 static inline void dma_mark_clean(void *addr, size_t size) {}
3420
3421 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/system.h linux-2.6.39.1/arch/powerpc/include/asm/system.h
3422 --- linux-2.6.39.1/arch/powerpc/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
3423 +++ linux-2.6.39.1/arch/powerpc/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
3424 @@ -533,7 +533,7 @@ __cmpxchg_local(volatile void *ptr, unsi
3425 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3426 #endif
3427
3428 -extern unsigned long arch_align_stack(unsigned long sp);
3429 +#define arch_align_stack(x) ((x) & ~0xfUL)
3430
3431 /* Used in very early kernel initialization. */
3432 extern unsigned long reloc_offset(void);
3433 diff -urNp linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h
3434 --- linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
3435 +++ linux-2.6.39.1/arch/powerpc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
3436 @@ -13,6 +13,8 @@
3437 #define VERIFY_READ 0
3438 #define VERIFY_WRITE 1
3439
3440 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3441 +
3442 /*
3443 * The fs value determines whether argument validity checking should be
3444 * performed or not. If get_fs() == USER_DS, checking is performed, with
3445 @@ -327,52 +329,6 @@ do { \
3446 extern unsigned long __copy_tofrom_user(void __user *to,
3447 const void __user *from, unsigned long size);
3448
3449 -#ifndef __powerpc64__
3450 -
3451 -static inline unsigned long copy_from_user(void *to,
3452 - const void __user *from, unsigned long n)
3453 -{
3454 - unsigned long over;
3455 -
3456 - if (access_ok(VERIFY_READ, from, n))
3457 - return __copy_tofrom_user((__force void __user *)to, from, n);
3458 - if ((unsigned long)from < TASK_SIZE) {
3459 - over = (unsigned long)from + n - TASK_SIZE;
3460 - return __copy_tofrom_user((__force void __user *)to, from,
3461 - n - over) + over;
3462 - }
3463 - return n;
3464 -}
3465 -
3466 -static inline unsigned long copy_to_user(void __user *to,
3467 - const void *from, unsigned long n)
3468 -{
3469 - unsigned long over;
3470 -
3471 - if (access_ok(VERIFY_WRITE, to, n))
3472 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3473 - if ((unsigned long)to < TASK_SIZE) {
3474 - over = (unsigned long)to + n - TASK_SIZE;
3475 - return __copy_tofrom_user(to, (__force void __user *)from,
3476 - n - over) + over;
3477 - }
3478 - return n;
3479 -}
3480 -
3481 -#else /* __powerpc64__ */
3482 -
3483 -#define __copy_in_user(to, from, size) \
3484 - __copy_tofrom_user((to), (from), (size))
3485 -
3486 -extern unsigned long copy_from_user(void *to, const void __user *from,
3487 - unsigned long n);
3488 -extern unsigned long copy_to_user(void __user *to, const void *from,
3489 - unsigned long n);
3490 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3491 - unsigned long n);
3492 -
3493 -#endif /* __powerpc64__ */
3494 -
3495 static inline unsigned long __copy_from_user_inatomic(void *to,
3496 const void __user *from, unsigned long n)
3497 {
3498 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
3499 if (ret == 0)
3500 return 0;
3501 }
3502 +
3503 + if (!__builtin_constant_p(n))
3504 + check_object_size(to, n, false);
3505 +
3506 return __copy_tofrom_user((__force void __user *)to, from, n);
3507 }
3508
3509 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
3510 if (ret == 0)
3511 return 0;
3512 }
3513 +
3514 + if (!__builtin_constant_p(n))
3515 + check_object_size(from, n, true);
3516 +
3517 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3518 }
3519
3520 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
3521 return __copy_to_user_inatomic(to, from, size);
3522 }
3523
3524 +#ifndef __powerpc64__
3525 +
3526 +static inline unsigned long __must_check copy_from_user(void *to,
3527 + const void __user *from, unsigned long n)
3528 +{
3529 + unsigned long over;
3530 +
3531 + if ((long)n < 0)
3532 + return n;
3533 +
3534 + if (access_ok(VERIFY_READ, from, n)) {
3535 + if (!__builtin_constant_p(n))
3536 + check_object_size(to, n, false);
3537 + return __copy_tofrom_user((__force void __user *)to, from, n);
3538 + }
3539 + if ((unsigned long)from < TASK_SIZE) {
3540 + over = (unsigned long)from + n - TASK_SIZE;
3541 + if (!__builtin_constant_p(n - over))
3542 + check_object_size(to, n - over, false);
3543 + return __copy_tofrom_user((__force void __user *)to, from,
3544 + n - over) + over;
3545 + }
3546 + return n;
3547 +}
3548 +
3549 +static inline unsigned long __must_check copy_to_user(void __user *to,
3550 + const void *from, unsigned long n)
3551 +{
3552 + unsigned long over;
3553 +
3554 + if ((long)n < 0)
3555 + return n;
3556 +
3557 + if (access_ok(VERIFY_WRITE, to, n)) {
3558 + if (!__builtin_constant_p(n))
3559 + check_object_size(from, n, true);
3560 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3561 + }
3562 + if ((unsigned long)to < TASK_SIZE) {
3563 + over = (unsigned long)to + n - TASK_SIZE;
3564 + if (!__builtin_constant_p(n))
3565 + check_object_size(from, n - over, true);
3566 + return __copy_tofrom_user(to, (__force void __user *)from,
3567 + n - over) + over;
3568 + }
3569 + return n;
3570 +}
3571 +
3572 +#else /* __powerpc64__ */
3573 +
3574 +#define __copy_in_user(to, from, size) \
3575 + __copy_tofrom_user((to), (from), (size))
3576 +
3577 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3578 +{
3579 + if ((long)n < 0 || n > INT_MAX)
3580 + return n;
3581 +
3582 + if (!__builtin_constant_p(n))
3583 + check_object_size(to, n, false);
3584 +
3585 + if (likely(access_ok(VERIFY_READ, from, n)))
3586 + n = __copy_from_user(to, from, n);
3587 + else
3588 + memset(to, 0, n);
3589 + return n;
3590 +}
3591 +
3592 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3593 +{
3594 + if ((long)n < 0 || n > INT_MAX)
3595 + return n;
3596 +
3597 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3598 + if (!__builtin_constant_p(n))
3599 + check_object_size(from, n, true);
3600 + n = __copy_to_user(to, from, n);
3601 + }
3602 + return n;
3603 +}
3604 +
3605 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3606 + unsigned long n);
3607 +
3608 +#endif /* __powerpc64__ */
3609 +
3610 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3611
3612 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3613 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma.c linux-2.6.39.1/arch/powerpc/kernel/dma.c
3614 --- linux-2.6.39.1/arch/powerpc/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
3615 +++ linux-2.6.39.1/arch/powerpc/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
3616 @@ -136,7 +136,7 @@ static inline void dma_direct_sync_singl
3617 }
3618 #endif
3619
3620 -struct dma_map_ops dma_direct_ops = {
3621 +const struct dma_map_ops dma_direct_ops = {
3622 .alloc_coherent = dma_direct_alloc_coherent,
3623 .free_coherent = dma_direct_free_coherent,
3624 .map_sg = dma_direct_map_sg,
3625 @@ -157,7 +157,7 @@ EXPORT_SYMBOL(dma_direct_ops);
3626
3627 int dma_set_mask(struct device *dev, u64 dma_mask)
3628 {
3629 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3630 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3631
3632 if (ppc_md.dma_set_mask)
3633 return ppc_md.dma_set_mask(dev, dma_mask);
3634 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c
3635 --- linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c 2011-05-19 00:06:34.000000000 -0400
3636 +++ linux-2.6.39.1/arch/powerpc/kernel/dma-iommu.c 2011-05-22 19:36:30.000000000 -0400
3637 @@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
3638 }
3639
3640 /* We support DMA to/from any memory page via the iommu */
3641 -static int dma_iommu_dma_supported(struct device *dev, u64 mask)
3642 +int dma_iommu_dma_supported(struct device *dev, u64 mask)
3643 {
3644 struct iommu_table *tbl = get_iommu_table_base(dev);
3645
3646 @@ -90,7 +90,7 @@ static int dma_iommu_dma_supported(struc
3647 return 1;
3648 }
3649
3650 -struct dma_map_ops dma_iommu_ops = {
3651 +struct dma_map_ops dma_iommu_ops = { /* cannot be const, see arch/powerpc/platforms/cell/iommu.c */
3652 .alloc_coherent = dma_iommu_alloc_coherent,
3653 .free_coherent = dma_iommu_free_coherent,
3654 .map_sg = dma_iommu_map_sg,
3655 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c
3656 --- linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
3657 +++ linux-2.6.39.1/arch/powerpc/kernel/dma-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
3658 @@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
3659 * map_page, and unmap_page on highmem, use normal dma_ops
3660 * for everything else.
3661 */
3662 -struct dma_map_ops swiotlb_dma_ops = {
3663 +const struct dma_map_ops swiotlb_dma_ops = {
3664 .alloc_coherent = dma_direct_alloc_coherent,
3665 .free_coherent = dma_direct_free_coherent,
3666 .map_sg = swiotlb_map_sg_attrs,
3667 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S
3668 --- linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S 2011-05-19 00:06:34.000000000 -0400
3669 +++ linux-2.6.39.1/arch/powerpc/kernel/exceptions-64e.S 2011-05-22 19:36:30.000000000 -0400
3670 @@ -495,6 +495,7 @@ storage_fault_common:
3671 std r14,_DAR(r1)
3672 std r15,_DSISR(r1)
3673 addi r3,r1,STACK_FRAME_OVERHEAD
3674 + bl .save_nvgprs
3675 mr r4,r14
3676 mr r5,r15
3677 ld r14,PACA_EXGEN+EX_R14(r13)
3678 @@ -504,8 +505,7 @@ storage_fault_common:
3679 cmpdi r3,0
3680 bne- 1f
3681 b .ret_from_except_lite
3682 -1: bl .save_nvgprs
3683 - mr r5,r3
3684 +1: mr r5,r3
3685 addi r3,r1,STACK_FRAME_OVERHEAD
3686 ld r4,_DAR(r1)
3687 bl .bad_page_fault
3688 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S
3689 --- linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S 2011-05-19 00:06:34.000000000 -0400
3690 +++ linux-2.6.39.1/arch/powerpc/kernel/exceptions-64s.S 2011-05-22 19:36:30.000000000 -0400
3691 @@ -848,10 +848,10 @@ handle_page_fault:
3692 11: ld r4,_DAR(r1)
3693 ld r5,_DSISR(r1)
3694 addi r3,r1,STACK_FRAME_OVERHEAD
3695 + bl .save_nvgprs
3696 bl .do_page_fault
3697 cmpdi r3,0
3698 beq+ 13f
3699 - bl .save_nvgprs
3700 mr r5,r3
3701 addi r3,r1,STACK_FRAME_OVERHEAD
3702 lwz r4,_DAR(r1)
3703 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c
3704 --- linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c 2011-05-19 00:06:34.000000000 -0400
3705 +++ linux-2.6.39.1/arch/powerpc/kernel/ibmebus.c 2011-05-22 19:36:30.000000000 -0400
3706 @@ -128,7 +128,7 @@ static int ibmebus_dma_supported(struct
3707 return 1;
3708 }
3709
3710 -static struct dma_map_ops ibmebus_dma_ops = {
3711 +static const struct dma_map_ops ibmebus_dma_ops = {
3712 .alloc_coherent = ibmebus_alloc_coherent,
3713 .free_coherent = ibmebus_free_coherent,
3714 .map_sg = ibmebus_map_sg,
3715 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/kgdb.c linux-2.6.39.1/arch/powerpc/kernel/kgdb.c
3716 --- linux-2.6.39.1/arch/powerpc/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
3717 +++ linux-2.6.39.1/arch/powerpc/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
3718 @@ -422,7 +422,7 @@ int kgdb_arch_handle_exception(int vecto
3719 /*
3720 * Global data
3721 */
3722 -struct kgdb_arch arch_kgdb_ops = {
3723 +const struct kgdb_arch arch_kgdb_ops = {
3724 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
3725 };
3726
3727 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/module_32.c linux-2.6.39.1/arch/powerpc/kernel/module_32.c
3728 --- linux-2.6.39.1/arch/powerpc/kernel/module_32.c 2011-05-19 00:06:34.000000000 -0400
3729 +++ linux-2.6.39.1/arch/powerpc/kernel/module_32.c 2011-05-22 19:36:30.000000000 -0400
3730 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3731 me->arch.core_plt_section = i;
3732 }
3733 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3734 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3735 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3736 return -ENOEXEC;
3737 }
3738
3739 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
3740
3741 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3742 /* Init, or core PLT? */
3743 - if (location >= mod->module_core
3744 - && location < mod->module_core + mod->core_size)
3745 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3746 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3747 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3748 - else
3749 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3750 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3751 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3752 + else {
3753 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3754 + return ~0UL;
3755 + }
3756
3757 /* Find this entry, or if that fails, the next avail. entry */
3758 while (entry->jump[0]) {
3759 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/module.c linux-2.6.39.1/arch/powerpc/kernel/module.c
3760 --- linux-2.6.39.1/arch/powerpc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
3761 +++ linux-2.6.39.1/arch/powerpc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
3762 @@ -31,11 +31,24 @@
3763
3764 LIST_HEAD(module_bug_list);
3765
3766 +#ifdef CONFIG_PAX_KERNEXEC
3767 void *module_alloc(unsigned long size)
3768 {
3769 if (size == 0)
3770 return NULL;
3771
3772 + return vmalloc(size);
3773 +}
3774 +
3775 +void *module_alloc_exec(unsigned long size)
3776 +#else
3777 +void *module_alloc(unsigned long size)
3778 +#endif
3779 +
3780 +{
3781 + if (size == 0)
3782 + return NULL;
3783 +
3784 return vmalloc_exec(size);
3785 }
3786
3787 @@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
3788 vfree(module_region);
3789 }
3790
3791 +#ifdef CONFIG_PAX_KERNEXEC
3792 +void module_free_exec(struct module *mod, void *module_region)
3793 +{
3794 + module_free(mod, module_region);
3795 +}
3796 +#endif
3797 +
3798 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3799 const Elf_Shdr *sechdrs,
3800 const char *name)
3801 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/pci-common.c linux-2.6.39.1/arch/powerpc/kernel/pci-common.c
3802 --- linux-2.6.39.1/arch/powerpc/kernel/pci-common.c 2011-05-19 00:06:34.000000000 -0400
3803 +++ linux-2.6.39.1/arch/powerpc/kernel/pci-common.c 2011-05-22 19:36:30.000000000 -0400
3804 @@ -53,14 +53,14 @@ resource_size_t isa_mem_base;
3805 unsigned int ppc_pci_flags = 0;
3806
3807
3808 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3809 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3810
3811 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3812 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3813 {
3814 pci_dma_ops = dma_ops;
3815 }
3816
3817 -struct dma_map_ops *get_pci_dma_ops(void)
3818 +const struct dma_map_ops *get_pci_dma_ops(void)
3819 {
3820 return pci_dma_ops;
3821 }
3822 @@ -1639,7 +1639,7 @@ null_write_config(struct pci_bus *bus, u
3823 return PCIBIOS_DEVICE_NOT_FOUND;
3824 }
3825
3826 -static struct pci_ops null_pci_ops =
3827 +static const struct pci_ops null_pci_ops =
3828 {
3829 .read = null_read_config,
3830 .write = null_write_config,
3831 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/process.c linux-2.6.39.1/arch/powerpc/kernel/process.c
3832 --- linux-2.6.39.1/arch/powerpc/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
3833 +++ linux-2.6.39.1/arch/powerpc/kernel/process.c 2011-05-22 19:41:32.000000000 -0400
3834 @@ -655,8 +655,8 @@ void show_regs(struct pt_regs * regs)
3835 * Lookup NIP late so we have the best change of getting the
3836 * above info out without failing
3837 */
3838 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3839 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3840 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3841 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3842 #endif
3843 show_stack(current, (unsigned long *) regs->gpr[1]);
3844 if (!user_mode(regs))
3845 @@ -1146,10 +1146,10 @@ void show_stack(struct task_struct *tsk,
3846 newsp = stack[0];
3847 ip = stack[STACK_FRAME_LR_SAVE];
3848 if (!firstframe || ip != lr) {
3849 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3850 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3851 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3852 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3853 - printk(" (%pS)",
3854 + printk(" (%pA)",
3855 (void *)current->ret_stack[curr_frame].ret);
3856 curr_frame--;
3857 }
3858 @@ -1169,7 +1169,7 @@ void show_stack(struct task_struct *tsk,
3859 struct pt_regs *regs = (struct pt_regs *)
3860 (sp + STACK_FRAME_OVERHEAD);
3861 lr = regs->link;
3862 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3863 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3864 regs->trap, (void *)regs->nip, (void *)lr);
3865 firstframe = 1;
3866 }
3867 @@ -1244,58 +1244,3 @@ void thread_info_cache_init(void)
3868 }
3869
3870 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3871 -
3872 -unsigned long arch_align_stack(unsigned long sp)
3873 -{
3874 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3875 - sp -= get_random_int() & ~PAGE_MASK;
3876 - return sp & ~0xf;
3877 -}
3878 -
3879 -static inline unsigned long brk_rnd(void)
3880 -{
3881 - unsigned long rnd = 0;
3882 -
3883 - /* 8MB for 32bit, 1GB for 64bit */
3884 - if (is_32bit_task())
3885 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3886 - else
3887 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3888 -
3889 - return rnd << PAGE_SHIFT;
3890 -}
3891 -
3892 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3893 -{
3894 - unsigned long base = mm->brk;
3895 - unsigned long ret;
3896 -
3897 -#ifdef CONFIG_PPC_STD_MMU_64
3898 - /*
3899 - * If we are using 1TB segments and we are allowed to randomise
3900 - * the heap, we can put it above 1TB so it is backed by a 1TB
3901 - * segment. Otherwise the heap will be in the bottom 1TB
3902 - * which always uses 256MB segments and this may result in a
3903 - * performance penalty.
3904 - */
3905 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3906 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3907 -#endif
3908 -
3909 - ret = PAGE_ALIGN(base + brk_rnd());
3910 -
3911 - if (ret < mm->brk)
3912 - return mm->brk;
3913 -
3914 - return ret;
3915 -}
3916 -
3917 -unsigned long randomize_et_dyn(unsigned long base)
3918 -{
3919 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3920 -
3921 - if (ret < base)
3922 - return base;
3923 -
3924 - return ret;
3925 -}
3926 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c
3927 --- linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c 2011-05-19 00:06:34.000000000 -0400
3928 +++ linux-2.6.39.1/arch/powerpc/kernel/rtas_pci.c 2011-05-22 19:36:30.000000000 -0400
3929 @@ -149,7 +149,7 @@ static int rtas_pci_write_config(struct
3930 return PCIBIOS_DEVICE_NOT_FOUND;
3931 }
3932
3933 -static struct pci_ops rtas_pci_ops = {
3934 +static const struct pci_ops rtas_pci_ops = {
3935 .read = rtas_pci_read_config,
3936 .write = rtas_pci_write_config,
3937 };
3938 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/signal_32.c linux-2.6.39.1/arch/powerpc/kernel/signal_32.c
3939 --- linux-2.6.39.1/arch/powerpc/kernel/signal_32.c 2011-05-19 00:06:34.000000000 -0400
3940 +++ linux-2.6.39.1/arch/powerpc/kernel/signal_32.c 2011-05-22 19:36:30.000000000 -0400
3941 @@ -858,7 +858,7 @@ int handle_rt_signal32(unsigned long sig
3942 /* Save user registers on the stack */
3943 frame = &rt_sf->uc.uc_mcontext;
3944 addr = frame;
3945 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3946 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3947 if (save_user_regs(regs, frame, 0, 1))
3948 goto badframe;
3949 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3950 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/signal_64.c linux-2.6.39.1/arch/powerpc/kernel/signal_64.c
3951 --- linux-2.6.39.1/arch/powerpc/kernel/signal_64.c 2011-05-19 00:06:34.000000000 -0400
3952 +++ linux-2.6.39.1/arch/powerpc/kernel/signal_64.c 2011-05-22 19:36:30.000000000 -0400
3953 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
3954 current->thread.fpscr.val = 0;
3955
3956 /* Set up to return from userspace. */
3957 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3958 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3959 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3960 } else {
3961 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3962 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/vdso.c linux-2.6.39.1/arch/powerpc/kernel/vdso.c
3963 --- linux-2.6.39.1/arch/powerpc/kernel/vdso.c 2011-05-19 00:06:34.000000000 -0400
3964 +++ linux-2.6.39.1/arch/powerpc/kernel/vdso.c 2011-05-22 19:36:30.000000000 -0400
3965 @@ -36,6 +36,7 @@
3966 #include <asm/firmware.h>
3967 #include <asm/vdso.h>
3968 #include <asm/vdso_datapage.h>
3969 +#include <asm/mman.h>
3970
3971 #include "setup.h"
3972
3973 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
3974 vdso_base = VDSO32_MBASE;
3975 #endif
3976
3977 - current->mm->context.vdso_base = 0;
3978 + current->mm->context.vdso_base = ~0UL;
3979
3980 /* vDSO has a problem and was disabled, just don't "enable" it for the
3981 * process
3982 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
3983 vdso_base = get_unmapped_area(NULL, vdso_base,
3984 (vdso_pages << PAGE_SHIFT) +
3985 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3986 - 0, 0);
3987 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3988 if (IS_ERR_VALUE(vdso_base)) {
3989 rc = vdso_base;
3990 goto fail_mmapsem;
3991 diff -urNp linux-2.6.39.1/arch/powerpc/kernel/vio.c linux-2.6.39.1/arch/powerpc/kernel/vio.c
3992 --- linux-2.6.39.1/arch/powerpc/kernel/vio.c 2011-05-19 00:06:34.000000000 -0400
3993 +++ linux-2.6.39.1/arch/powerpc/kernel/vio.c 2011-05-22 19:36:30.000000000 -0400
3994 @@ -605,11 +605,12 @@ static int vio_dma_iommu_dma_supported(s
3995 return dma_iommu_ops.dma_supported(dev, mask);
3996 }
3997
3998 -struct dma_map_ops vio_dma_mapping_ops = {
3999 +const struct dma_map_ops vio_dma_mapping_ops = {
4000 .alloc_coherent = vio_dma_iommu_alloc_coherent,
4001 .free_coherent = vio_dma_iommu_free_coherent,
4002 .map_sg = vio_dma_iommu_map_sg,
4003 .unmap_sg = vio_dma_iommu_unmap_sg,
4004 + .dma_supported = dma_iommu_dma_supported,
4005 .map_page = vio_dma_iommu_map_page,
4006 .unmap_page = vio_dma_iommu_unmap_page,
4007 .dma_supported = vio_dma_iommu_dma_supported,
4008 diff -urNp linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c
4009 --- linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
4010 +++ linux-2.6.39.1/arch/powerpc/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
4011 @@ -9,22 +9,6 @@
4012 #include <linux/module.h>
4013 #include <asm/uaccess.h>
4014
4015 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4016 -{
4017 - if (likely(access_ok(VERIFY_READ, from, n)))
4018 - n = __copy_from_user(to, from, n);
4019 - else
4020 - memset(to, 0, n);
4021 - return n;
4022 -}
4023 -
4024 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4025 -{
4026 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4027 - n = __copy_to_user(to, from, n);
4028 - return n;
4029 -}
4030 -
4031 unsigned long copy_in_user(void __user *to, const void __user *from,
4032 unsigned long n)
4033 {
4034 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
4035 return n;
4036 }
4037
4038 -EXPORT_SYMBOL(copy_from_user);
4039 -EXPORT_SYMBOL(copy_to_user);
4040 EXPORT_SYMBOL(copy_in_user);
4041
4042 diff -urNp linux-2.6.39.1/arch/powerpc/mm/fault.c linux-2.6.39.1/arch/powerpc/mm/fault.c
4043 --- linux-2.6.39.1/arch/powerpc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
4044 +++ linux-2.6.39.1/arch/powerpc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
4045 @@ -31,6 +31,10 @@
4046 #include <linux/kdebug.h>
4047 #include <linux/perf_event.h>
4048 #include <linux/magic.h>
4049 +#include <linux/slab.h>
4050 +#include <linux/pagemap.h>
4051 +#include <linux/compiler.h>
4052 +#include <linux/unistd.h>
4053
4054 #include <asm/firmware.h>
4055 #include <asm/page.h>
4056 @@ -42,6 +46,7 @@
4057 #include <asm/tlbflush.h>
4058 #include <asm/siginfo.h>
4059 #include <mm/mmu_decl.h>
4060 +#include <asm/ptrace.h>
4061
4062 #ifdef CONFIG_KPROBES
4063 static inline int notify_page_fault(struct pt_regs *regs)
4064 @@ -65,6 +70,33 @@ static inline int notify_page_fault(stru
4065 }
4066 #endif
4067
4068 +#ifdef CONFIG_PAX_PAGEEXEC
4069 +/*
4070 + * PaX: decide what to do with offenders (regs->nip = fault address)
4071 + *
4072 + * returns 1 when task should be killed
4073 + */
4074 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4075 +{
4076 + return 1;
4077 +}
4078 +
4079 +void pax_report_insns(void *pc, void *sp)
4080 +{
4081 + unsigned long i;
4082 +
4083 + printk(KERN_ERR "PAX: bytes at PC: ");
4084 + for (i = 0; i < 5; i++) {
4085 + unsigned int c;
4086 + if (get_user(c, (unsigned int __user *)pc+i))
4087 + printk(KERN_CONT "???????? ");
4088 + else
4089 + printk(KERN_CONT "%08x ", c);
4090 + }
4091 + printk("\n");
4092 +}
4093 +#endif
4094 +
4095 /*
4096 * Check whether the instruction at regs->nip is a store using
4097 * an update addressing form which will update r1.
4098 @@ -135,7 +167,7 @@ int __kprobes do_page_fault(struct pt_re
4099 * indicate errors in DSISR but can validly be set in SRR1.
4100 */
4101 if (trap == 0x400)
4102 - error_code &= 0x48200000;
4103 + error_code &= 0x58200000;
4104 else
4105 is_write = error_code & DSISR_ISSTORE;
4106 #else
4107 @@ -258,7 +290,7 @@ good_area:
4108 * "undefined". Of those that can be set, this is the only
4109 * one which seems bad.
4110 */
4111 - if (error_code & 0x10000000)
4112 + if (error_code & DSISR_GUARDED)
4113 /* Guarded storage error. */
4114 goto bad_area;
4115 #endif /* CONFIG_8xx */
4116 @@ -273,7 +305,7 @@ good_area:
4117 * processors use the same I/D cache coherency mechanism
4118 * as embedded.
4119 */
4120 - if (error_code & DSISR_PROTFAULT)
4121 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4122 goto bad_area;
4123 #endif /* CONFIG_PPC_STD_MMU */
4124
4125 @@ -342,6 +374,23 @@ bad_area:
4126 bad_area_nosemaphore:
4127 /* User mode accesses cause a SIGSEGV */
4128 if (user_mode(regs)) {
4129 +
4130 +#ifdef CONFIG_PAX_PAGEEXEC
4131 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4132 +#ifdef CONFIG_PPC_STD_MMU
4133 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4134 +#else
4135 + if (is_exec && regs->nip == address) {
4136 +#endif
4137 + switch (pax_handle_fetch_fault(regs)) {
4138 + }
4139 +
4140 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4141 + do_group_exit(SIGKILL);
4142 + }
4143 + }
4144 +#endif
4145 +
4146 _exception(SIGSEGV, regs, code, address);
4147 return 0;
4148 }
4149 diff -urNp linux-2.6.39.1/arch/powerpc/mm/mmap_64.c linux-2.6.39.1/arch/powerpc/mm/mmap_64.c
4150 --- linux-2.6.39.1/arch/powerpc/mm/mmap_64.c 2011-05-19 00:06:34.000000000 -0400
4151 +++ linux-2.6.39.1/arch/powerpc/mm/mmap_64.c 2011-05-22 19:36:30.000000000 -0400
4152 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
4153 */
4154 if (mmap_is_legacy()) {
4155 mm->mmap_base = TASK_UNMAPPED_BASE;
4156 +
4157 +#ifdef CONFIG_PAX_RANDMMAP
4158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4159 + mm->mmap_base += mm->delta_mmap;
4160 +#endif
4161 +
4162 mm->get_unmapped_area = arch_get_unmapped_area;
4163 mm->unmap_area = arch_unmap_area;
4164 } else {
4165 mm->mmap_base = mmap_base();
4166 +
4167 +#ifdef CONFIG_PAX_RANDMMAP
4168 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4169 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4170 +#endif
4171 +
4172 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4173 mm->unmap_area = arch_unmap_area_topdown;
4174 }
4175 diff -urNp linux-2.6.39.1/arch/powerpc/mm/slice.c linux-2.6.39.1/arch/powerpc/mm/slice.c
4176 --- linux-2.6.39.1/arch/powerpc/mm/slice.c 2011-05-19 00:06:34.000000000 -0400
4177 +++ linux-2.6.39.1/arch/powerpc/mm/slice.c 2011-05-22 19:36:30.000000000 -0400
4178 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
4179 if ((mm->task_size - len) < addr)
4180 return 0;
4181 vma = find_vma(mm, addr);
4182 - return (!vma || (addr + len) <= vma->vm_start);
4183 + return check_heap_stack_gap(vma, addr, len);
4184 }
4185
4186 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4187 @@ -256,7 +256,7 @@ full_search:
4188 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4189 continue;
4190 }
4191 - if (!vma || addr + len <= vma->vm_start) {
4192 + if (check_heap_stack_gap(vma, addr, len)) {
4193 /*
4194 * Remember the place where we stopped the search:
4195 */
4196 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
4197 }
4198 }
4199
4200 - addr = mm->mmap_base;
4201 - while (addr > len) {
4202 + if (mm->mmap_base < len)
4203 + addr = -ENOMEM;
4204 + else
4205 + addr = mm->mmap_base - len;
4206 +
4207 + while (!IS_ERR_VALUE(addr)) {
4208 /* Go down by chunk size */
4209 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4210 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4211
4212 /* Check for hit with different page size */
4213 mask = slice_range_to_mask(addr, len);
4214 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
4215 * return with success:
4216 */
4217 vma = find_vma(mm, addr);
4218 - if (!vma || (addr + len) <= vma->vm_start) {
4219 + if (check_heap_stack_gap(vma, addr, len)) {
4220 /* remember the address as a hint for next time */
4221 if (use_cache)
4222 mm->free_area_cache = addr;
4223 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
4224 mm->cached_hole_size = vma->vm_start - addr;
4225
4226 /* try just below the current vma->vm_start */
4227 - addr = vma->vm_start;
4228 + addr = skip_heap_stack_gap(vma, len);
4229 }
4230
4231 /*
4232 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
4233 if (fixed && addr > (mm->task_size - len))
4234 return -EINVAL;
4235
4236 +#ifdef CONFIG_PAX_RANDMMAP
4237 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4238 + addr = 0;
4239 +#endif
4240 +
4241 /* If hint, make sure it matches our alignment restrictions */
4242 if (!fixed && addr) {
4243 addr = _ALIGN_UP(addr, 1ul << pshift);
4244 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c
4245 --- linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c 2011-05-19 00:06:34.000000000 -0400
4246 +++ linux-2.6.39.1/arch/powerpc/platforms/52xx/efika.c 2011-05-22 19:36:30.000000000 -0400
4247 @@ -60,7 +60,7 @@ static int rtas_write_config(struct pci_
4248 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
4249 }
4250
4251 -static struct pci_ops rtas_pci_ops = {
4252 +static const struct pci_ops rtas_pci_ops = {
4253 .read = rtas_read_config,
4254 .write = rtas_write_config,
4255 };
4256 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c
4257 --- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-19 00:06:34.000000000 -0400
4258 +++ linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-22 19:36:30.000000000 -0400
4259 @@ -234,7 +234,7 @@ static int celleb_fake_pci_write_config(
4260 return PCIBIOS_SUCCESSFUL;
4261 }
4262
4263 -static struct pci_ops celleb_fake_pci_ops = {
4264 +static const struct pci_ops celleb_fake_pci_ops = {
4265 .read = celleb_fake_pci_read_config,
4266 .write = celleb_fake_pci_write_config,
4267 };
4268 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c
4269 --- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-19 00:06:34.000000000 -0400
4270 +++ linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-22 19:36:30.000000000 -0400
4271 @@ -245,7 +245,7 @@ static int celleb_epci_write_config(stru
4272 return celleb_epci_check_abort(hose, addr);
4273 }
4274
4275 -struct pci_ops celleb_epci_ops = {
4276 +const struct pci_ops celleb_epci_ops = {
4277 .read = celleb_epci_read_config,
4278 .write = celleb_epci_write_config,
4279 };
4280 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c
4281 --- linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-19 00:06:34.000000000 -0400
4282 +++ linux-2.6.39.1/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-22 19:36:30.000000000 -0400
4283 @@ -399,7 +399,7 @@ static int scc_pciex_write_config(struct
4284 return PCIBIOS_SUCCESSFUL;
4285 }
4286
4287 -static struct pci_ops scc_pciex_pci_ops = {
4288 +static const struct pci_ops scc_pciex_pci_ops = {
4289 scc_pciex_read_config,
4290 scc_pciex_write_config,
4291 };
4292 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c
4293 --- linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c 2011-05-19 00:06:34.000000000 -0400
4294 +++ linux-2.6.39.1/arch/powerpc/platforms/cell/iommu.c 2011-05-22 19:36:30.000000000 -0400
4295 @@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
4296
4297 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
4298
4299 -struct dma_map_ops dma_iommu_fixed_ops = {
4300 +const struct dma_map_ops dma_iommu_fixed_ops = {
4301 .alloc_coherent = dma_fixed_alloc_coherent,
4302 .free_coherent = dma_fixed_free_coherent,
4303 .map_sg = dma_fixed_map_sg,
4304 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c
4305 --- linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c 2011-05-19 00:06:34.000000000 -0400
4306 +++ linux-2.6.39.1/arch/powerpc/platforms/chrp/pci.c 2011-05-22 19:36:30.000000000 -0400
4307 @@ -84,7 +84,7 @@ int gg2_write_config(struct pci_bus *bus
4308 return PCIBIOS_SUCCESSFUL;
4309 }
4310
4311 -static struct pci_ops gg2_pci_ops =
4312 +static const struct pci_ops gg2_pci_ops =
4313 {
4314 .read = gg2_read_config,
4315 .write = gg2_write_config,
4316 @@ -122,7 +122,7 @@ int rtas_write_config(struct pci_bus *bu
4317 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
4318 }
4319
4320 -static struct pci_ops rtas_pci_ops =
4321 +static const struct pci_ops rtas_pci_ops =
4322 {
4323 .read = rtas_read_config,
4324 .write = rtas_write_config,
4325 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c
4326 --- linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c 2011-05-19 00:06:34.000000000 -0400
4327 +++ linux-2.6.39.1/arch/powerpc/platforms/iseries/pci.c 2011-05-22 19:36:30.000000000 -0400
4328 @@ -533,7 +533,7 @@ static int iSeries_pci_write_config(stru
4329 return 0;
4330 }
4331
4332 -static struct pci_ops iSeries_pci_ops = {
4333 +static const struct pci_ops iSeries_pci_ops = {
4334 .read = iSeries_pci_read_config,
4335 .write = iSeries_pci_write_config
4336 };
4337 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c
4338 --- linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c 2011-05-19 00:06:34.000000000 -0400
4339 +++ linux-2.6.39.1/arch/powerpc/platforms/maple/pci.c 2011-05-22 19:36:30.000000000 -0400
4340 @@ -180,7 +180,7 @@ static int u3_agp_write_config(struct pc
4341 return PCIBIOS_SUCCESSFUL;
4342 }
4343
4344 -static struct pci_ops u3_agp_pci_ops =
4345 +static const struct pci_ops u3_agp_pci_ops =
4346 {
4347 .read = u3_agp_read_config,
4348 .write = u3_agp_write_config,
4349 @@ -276,7 +276,7 @@ static int u3_ht_write_config(struct pci
4350 return PCIBIOS_SUCCESSFUL;
4351 }
4352
4353 -static struct pci_ops u3_ht_pci_ops =
4354 +static const struct pci_ops u3_ht_pci_ops =
4355 {
4356 .read = u3_ht_read_config,
4357 .write = u3_ht_write_config,
4358 @@ -381,7 +381,7 @@ static int u4_pcie_write_config(struct p
4359 return PCIBIOS_SUCCESSFUL;
4360 }
4361
4362 -static struct pci_ops u4_pcie_pci_ops =
4363 +static const struct pci_ops u4_pcie_pci_ops =
4364 {
4365 .read = u4_pcie_read_config,
4366 .write = u4_pcie_write_config,
4367 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c
4368 --- linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c 2011-05-19 00:06:34.000000000 -0400
4369 +++ linux-2.6.39.1/arch/powerpc/platforms/pasemi/pci.c 2011-05-22 19:36:30.000000000 -0400
4370 @@ -176,7 +176,7 @@ static int pa_pxp_write_config(struct pc
4371 return PCIBIOS_SUCCESSFUL;
4372 }
4373
4374 -static struct pci_ops pa_pxp_ops = {
4375 +static const struct pci_ops pa_pxp_ops = {
4376 .read = pa_pxp_read_config,
4377 .write = pa_pxp_write_config,
4378 };
4379 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c
4380 --- linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c 2011-05-19 00:06:34.000000000 -0400
4381 +++ linux-2.6.39.1/arch/powerpc/platforms/powermac/pci.c 2011-05-22 19:36:30.000000000 -0400
4382 @@ -218,7 +218,7 @@ static int macrisc_write_config(struct p
4383 return PCIBIOS_SUCCESSFUL;
4384 }
4385
4386 -static struct pci_ops macrisc_pci_ops =
4387 +static const struct pci_ops macrisc_pci_ops =
4388 {
4389 .read = macrisc_read_config,
4390 .write = macrisc_write_config,
4391 @@ -273,7 +273,7 @@ chaos_write_config(struct pci_bus *bus,
4392 return macrisc_write_config(bus, devfn, offset, len, val);
4393 }
4394
4395 -static struct pci_ops chaos_pci_ops =
4396 +static const struct pci_ops chaos_pci_ops =
4397 {
4398 .read = chaos_read_config,
4399 .write = chaos_write_config,
4400 diff -urNp linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c
4401 --- linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c 2011-05-19 00:06:34.000000000 -0400
4402 +++ linux-2.6.39.1/arch/powerpc/platforms/ps3/system-bus.c 2011-05-22 19:36:30.000000000 -0400
4403 @@ -695,7 +695,7 @@ static int ps3_dma_supported(struct devi
4404 return mask >= DMA_BIT_MASK(32);
4405 }
4406
4407 -static struct dma_map_ops ps3_sb_dma_ops = {
4408 +static const struct dma_map_ops ps3_sb_dma_ops = {
4409 .alloc_coherent = ps3_alloc_coherent,
4410 .free_coherent = ps3_free_coherent,
4411 .map_sg = ps3_sb_map_sg,
4412 @@ -705,7 +705,7 @@ static struct dma_map_ops ps3_sb_dma_ops
4413 .unmap_page = ps3_unmap_page,
4414 };
4415
4416 -static struct dma_map_ops ps3_ioc0_dma_ops = {
4417 +static const struct dma_map_ops ps3_ioc0_dma_ops = {
4418 .alloc_coherent = ps3_alloc_coherent,
4419 .free_coherent = ps3_free_coherent,
4420 .map_sg = ps3_ioc0_map_sg,
4421 diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c
4422 --- linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c 2011-05-19 00:06:34.000000000 -0400
4423 +++ linux-2.6.39.1/arch/powerpc/sysdev/fsl_pci.c 2011-05-22 19:36:30.000000000 -0400
4424 @@ -573,7 +573,7 @@ static int mpc83xx_pcie_write_config(str
4425 return PCIBIOS_SUCCESSFUL;
4426 }
4427
4428 -static struct pci_ops mpc83xx_pcie_ops = {
4429 +static const struct pci_ops mpc83xx_pcie_ops = {
4430 .read = mpc83xx_pcie_read_config,
4431 .write = mpc83xx_pcie_write_config,
4432 };
4433 diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c
4434 --- linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
4435 +++ linux-2.6.39.1/arch/powerpc/sysdev/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
4436 @@ -148,7 +148,7 @@ indirect_write_config(struct pci_bus *bu
4437 return PCIBIOS_SUCCESSFUL;
4438 }
4439
4440 -static struct pci_ops indirect_pci_ops =
4441 +static const struct pci_ops indirect_pci_ops =
4442 {
4443 .read = indirect_read_config,
4444 .write = indirect_write_config,
4445 diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c
4446 --- linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-19 00:06:34.000000000 -0400
4447 +++ linux-2.6.39.1/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-22 19:36:30.000000000 -0400
4448 @@ -1514,7 +1514,7 @@ static int ppc4xx_pciex_write_config(str
4449 return PCIBIOS_SUCCESSFUL;
4450 }
4451
4452 -static struct pci_ops ppc4xx_pciex_pci_ops =
4453 +static const struct pci_ops ppc4xx_pciex_pci_ops =
4454 {
4455 .read = ppc4xx_pciex_read_config,
4456 .write = ppc4xx_pciex_write_config,
4457 diff -urNp linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c
4458 --- linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c 2011-05-19 00:06:34.000000000 -0400
4459 +++ linux-2.6.39.1/arch/powerpc/sysdev/tsi108_pci.c 2011-05-22 19:36:30.000000000 -0400
4460 @@ -190,7 +190,7 @@ void tsi108_clear_pci_cfg_error(void)
4461 tsi108_clear_pci_error(tsi108_pci_cfg_phys);
4462 }
4463
4464 -static struct pci_ops tsi108_direct_pci_ops = {
4465 +static const struct pci_ops tsi108_direct_pci_ops = {
4466 .read = tsi108_direct_read_config,
4467 .write = tsi108_direct_write_config,
4468 };
4469 diff -urNp linux-2.6.39.1/arch/s390/include/asm/elf.h linux-2.6.39.1/arch/s390/include/asm/elf.h
4470 --- linux-2.6.39.1/arch/s390/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
4471 +++ linux-2.6.39.1/arch/s390/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
4472 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4473 the loader. We need to make sure that it is out of the way of the program
4474 that it will "exec", and that there is sufficient room for the brk. */
4475
4476 -extern unsigned long randomize_et_dyn(unsigned long base);
4477 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4478 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4479 +
4480 +#ifdef CONFIG_PAX_ASLR
4481 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4482 +
4483 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4484 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4485 +#endif
4486
4487 /* This yields a mask that user programs can use to figure out what
4488 instruction set this CPU supports. */
4489 @@ -222,7 +228,4 @@ struct linux_binprm;
4490 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4491 int arch_setup_additional_pages(struct linux_binprm *, int);
4492
4493 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4494 -#define arch_randomize_brk arch_randomize_brk
4495 -
4496 #endif
4497 diff -urNp linux-2.6.39.1/arch/s390/include/asm/system.h linux-2.6.39.1/arch/s390/include/asm/system.h
4498 --- linux-2.6.39.1/arch/s390/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4499 +++ linux-2.6.39.1/arch/s390/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4500 @@ -255,7 +255,7 @@ extern void (*_machine_restart)(char *co
4501 extern void (*_machine_halt)(void);
4502 extern void (*_machine_power_off)(void);
4503
4504 -extern unsigned long arch_align_stack(unsigned long sp);
4505 +#define arch_align_stack(x) ((x) & ~0xfUL)
4506
4507 static inline int tprot(unsigned long addr)
4508 {
4509 diff -urNp linux-2.6.39.1/arch/s390/include/asm/uaccess.h linux-2.6.39.1/arch/s390/include/asm/uaccess.h
4510 --- linux-2.6.39.1/arch/s390/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
4511 +++ linux-2.6.39.1/arch/s390/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
4512 @@ -234,6 +234,10 @@ static inline unsigned long __must_check
4513 copy_to_user(void __user *to, const void *from, unsigned long n)
4514 {
4515 might_fault();
4516 +
4517 + if ((long)n < 0)
4518 + return n;
4519 +
4520 if (access_ok(VERIFY_WRITE, to, n))
4521 n = __copy_to_user(to, from, n);
4522 return n;
4523 @@ -259,6 +263,9 @@ copy_to_user(void __user *to, const void
4524 static inline unsigned long __must_check
4525 __copy_from_user(void *to, const void __user *from, unsigned long n)
4526 {
4527 + if ((long)n < 0)
4528 + return n;
4529 +
4530 if (__builtin_constant_p(n) && (n <= 256))
4531 return uaccess.copy_from_user_small(n, from, to);
4532 else
4533 @@ -293,6 +300,10 @@ copy_from_user(void *to, const void __us
4534 unsigned int sz = __compiletime_object_size(to);
4535
4536 might_fault();
4537 +
4538 + if ((long)n < 0)
4539 + return n;
4540 +
4541 if (unlikely(sz != -1 && sz < n)) {
4542 copy_from_user_overflow();
4543 return n;
4544 diff -urNp linux-2.6.39.1/arch/s390/Kconfig linux-2.6.39.1/arch/s390/Kconfig
4545 --- linux-2.6.39.1/arch/s390/Kconfig 2011-05-19 00:06:34.000000000 -0400
4546 +++ linux-2.6.39.1/arch/s390/Kconfig 2011-05-22 19:36:30.000000000 -0400
4547 @@ -234,11 +234,9 @@ config S390_EXEC_PROTECT
4548 prompt "Data execute protection"
4549 help
4550 This option allows to enable a buffer overflow protection for user
4551 - space programs and it also selects the addressing mode option above.
4552 - The kernel parameter noexec=on will enable this feature and also
4553 - switch the addressing modes, default is disabled. Enabling this (via
4554 - kernel parameter) on machines earlier than IBM System z9 this will
4555 - reduce system performance.
4556 + space programs.
4557 + Enabling this (via kernel parameter) on machines earlier than IBM
4558 + System z9 this will reduce system performance.
4559
4560 comment "Code generation options"
4561
4562 diff -urNp linux-2.6.39.1/arch/s390/kernel/module.c linux-2.6.39.1/arch/s390/kernel/module.c
4563 --- linux-2.6.39.1/arch/s390/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
4564 +++ linux-2.6.39.1/arch/s390/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
4565 @@ -168,11 +168,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
4566
4567 /* Increase core size by size of got & plt and set start
4568 offsets for got and plt. */
4569 - me->core_size = ALIGN(me->core_size, 4);
4570 - me->arch.got_offset = me->core_size;
4571 - me->core_size += me->arch.got_size;
4572 - me->arch.plt_offset = me->core_size;
4573 - me->core_size += me->arch.plt_size;
4574 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4575 + me->arch.got_offset = me->core_size_rw;
4576 + me->core_size_rw += me->arch.got_size;
4577 + me->arch.plt_offset = me->core_size_rx;
4578 + me->core_size_rx += me->arch.plt_size;
4579 return 0;
4580 }
4581
4582 @@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4583 if (info->got_initialized == 0) {
4584 Elf_Addr *gotent;
4585
4586 - gotent = me->module_core + me->arch.got_offset +
4587 + gotent = me->module_core_rw + me->arch.got_offset +
4588 info->got_offset;
4589 *gotent = val;
4590 info->got_initialized = 1;
4591 @@ -282,7 +282,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4592 else if (r_type == R_390_GOTENT ||
4593 r_type == R_390_GOTPLTENT)
4594 *(unsigned int *) loc =
4595 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4596 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4597 else if (r_type == R_390_GOT64 ||
4598 r_type == R_390_GOTPLT64)
4599 *(unsigned long *) loc = val;
4600 @@ -296,7 +296,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4601 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4602 if (info->plt_initialized == 0) {
4603 unsigned int *ip;
4604 - ip = me->module_core + me->arch.plt_offset +
4605 + ip = me->module_core_rx + me->arch.plt_offset +
4606 info->plt_offset;
4607 #ifndef CONFIG_64BIT
4608 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4609 @@ -321,7 +321,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4610 val - loc + 0xffffUL < 0x1ffffeUL) ||
4611 (r_type == R_390_PLT32DBL &&
4612 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4613 - val = (Elf_Addr) me->module_core +
4614 + val = (Elf_Addr) me->module_core_rx +
4615 me->arch.plt_offset +
4616 info->plt_offset;
4617 val += rela->r_addend - loc;
4618 @@ -343,7 +343,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4619 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4620 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4621 val = val + rela->r_addend -
4622 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4623 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4624 if (r_type == R_390_GOTOFF16)
4625 *(unsigned short *) loc = val;
4626 else if (r_type == R_390_GOTOFF32)
4627 @@ -353,7 +353,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4628 break;
4629 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4630 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4631 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4632 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4633 rela->r_addend - loc;
4634 if (r_type == R_390_GOTPC)
4635 *(unsigned int *) loc = val;
4636 diff -urNp linux-2.6.39.1/arch/s390/kernel/process.c linux-2.6.39.1/arch/s390/kernel/process.c
4637 --- linux-2.6.39.1/arch/s390/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4638 +++ linux-2.6.39.1/arch/s390/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4639 @@ -334,39 +334,3 @@ unsigned long get_wchan(struct task_stru
4640 }
4641 return 0;
4642 }
4643 -
4644 -unsigned long arch_align_stack(unsigned long sp)
4645 -{
4646 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4647 - sp -= get_random_int() & ~PAGE_MASK;
4648 - return sp & ~0xf;
4649 -}
4650 -
4651 -static inline unsigned long brk_rnd(void)
4652 -{
4653 - /* 8MB for 32bit, 1GB for 64bit */
4654 - if (is_32bit_task())
4655 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4656 - else
4657 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4658 -}
4659 -
4660 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4661 -{
4662 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4663 -
4664 - if (ret < mm->brk)
4665 - return mm->brk;
4666 - return ret;
4667 -}
4668 -
4669 -unsigned long randomize_et_dyn(unsigned long base)
4670 -{
4671 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4672 -
4673 - if (!(current->flags & PF_RANDOMIZE))
4674 - return base;
4675 - if (ret < base)
4676 - return base;
4677 - return ret;
4678 -}
4679 diff -urNp linux-2.6.39.1/arch/s390/kernel/setup.c linux-2.6.39.1/arch/s390/kernel/setup.c
4680 --- linux-2.6.39.1/arch/s390/kernel/setup.c 2011-05-19 00:06:34.000000000 -0400
4681 +++ linux-2.6.39.1/arch/s390/kernel/setup.c 2011-05-22 19:36:30.000000000 -0400
4682 @@ -271,7 +271,7 @@ static int __init early_parse_mem(char *
4683 }
4684 early_param("mem", early_parse_mem);
4685
4686 -unsigned int user_mode = HOME_SPACE_MODE;
4687 +unsigned int user_mode = SECONDARY_SPACE_MODE;
4688 EXPORT_SYMBOL_GPL(user_mode);
4689
4690 static int set_amode_and_uaccess(unsigned long user_amode,
4691 @@ -300,17 +300,6 @@ static int set_amode_and_uaccess(unsigne
4692 }
4693 }
4694
4695 -/*
4696 - * Switch kernel/user addressing modes?
4697 - */
4698 -static int __init early_parse_switch_amode(char *p)
4699 -{
4700 - if (user_mode != SECONDARY_SPACE_MODE)
4701 - user_mode = PRIMARY_SPACE_MODE;
4702 - return 0;
4703 -}
4704 -early_param("switch_amode", early_parse_switch_amode);
4705 -
4706 static int __init early_parse_user_mode(char *p)
4707 {
4708 if (p && strcmp(p, "primary") == 0)
4709 @@ -327,20 +316,6 @@ static int __init early_parse_user_mode(
4710 }
4711 early_param("user_mode", early_parse_user_mode);
4712
4713 -#ifdef CONFIG_S390_EXEC_PROTECT
4714 -/*
4715 - * Enable execute protection?
4716 - */
4717 -static int __init early_parse_noexec(char *p)
4718 -{
4719 - if (!strncmp(p, "off", 3))
4720 - return 0;
4721 - user_mode = SECONDARY_SPACE_MODE;
4722 - return 0;
4723 -}
4724 -early_param("noexec", early_parse_noexec);
4725 -#endif /* CONFIG_S390_EXEC_PROTECT */
4726 -
4727 static void setup_addressing_mode(void)
4728 {
4729 if (user_mode == SECONDARY_SPACE_MODE) {
4730 diff -urNp linux-2.6.39.1/arch/s390/mm/maccess.c linux-2.6.39.1/arch/s390/mm/maccess.c
4731 --- linux-2.6.39.1/arch/s390/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
4732 +++ linux-2.6.39.1/arch/s390/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
4733 @@ -45,7 +45,7 @@ static long probe_kernel_write_odd(void
4734 return rc ? rc : count;
4735 }
4736
4737 -long probe_kernel_write(void *dst, void *src, size_t size)
4738 +long probe_kernel_write(void *dst, const void *src, size_t size)
4739 {
4740 long copied = 0;
4741
4742 diff -urNp linux-2.6.39.1/arch/s390/mm/mmap.c linux-2.6.39.1/arch/s390/mm/mmap.c
4743 --- linux-2.6.39.1/arch/s390/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4744 +++ linux-2.6.39.1/arch/s390/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
4745 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_str
4746 */
4747 if (mmap_is_legacy()) {
4748 mm->mmap_base = TASK_UNMAPPED_BASE;
4749 +
4750 +#ifdef CONFIG_PAX_RANDMMAP
4751 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4752 + mm->mmap_base += mm->delta_mmap;
4753 +#endif
4754 +
4755 mm->get_unmapped_area = arch_get_unmapped_area;
4756 mm->unmap_area = arch_unmap_area;
4757 } else {
4758 mm->mmap_base = mmap_base();
4759 +
4760 +#ifdef CONFIG_PAX_RANDMMAP
4761 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4762 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4763 +#endif
4764 +
4765 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4766 mm->unmap_area = arch_unmap_area_topdown;
4767 }
4768 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_str
4769 */
4770 if (mmap_is_legacy()) {
4771 mm->mmap_base = TASK_UNMAPPED_BASE;
4772 +
4773 +#ifdef CONFIG_PAX_RANDMMAP
4774 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4775 + mm->mmap_base += mm->delta_mmap;
4776 +#endif
4777 +
4778 mm->get_unmapped_area = s390_get_unmapped_area;
4779 mm->unmap_area = arch_unmap_area;
4780 } else {
4781 mm->mmap_base = mmap_base();
4782 +
4783 +#ifdef CONFIG_PAX_RANDMMAP
4784 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4785 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4786 +#endif
4787 +
4788 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4789 mm->unmap_area = arch_unmap_area_topdown;
4790 }
4791 diff -urNp linux-2.6.39.1/arch/score/include/asm/system.h linux-2.6.39.1/arch/score/include/asm/system.h
4792 --- linux-2.6.39.1/arch/score/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4793 +++ linux-2.6.39.1/arch/score/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4794 @@ -17,7 +17,7 @@ do { \
4795 #define finish_arch_switch(prev) do {} while (0)
4796
4797 typedef void (*vi_handler_t)(void);
4798 -extern unsigned long arch_align_stack(unsigned long sp);
4799 +#define arch_align_stack(x) (x)
4800
4801 #define mb() barrier()
4802 #define rmb() barrier()
4803 diff -urNp linux-2.6.39.1/arch/score/kernel/process.c linux-2.6.39.1/arch/score/kernel/process.c
4804 --- linux-2.6.39.1/arch/score/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4805 +++ linux-2.6.39.1/arch/score/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4806 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
4807
4808 return task_pt_regs(task)->cp0_epc;
4809 }
4810 -
4811 -unsigned long arch_align_stack(unsigned long sp)
4812 -{
4813 - return sp;
4814 -}
4815 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c
4816 --- linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-19 00:06:34.000000000 -0400
4817 +++ linux-2.6.39.1/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-22 19:36:30.000000000 -0400
4818 @@ -76,7 +76,7 @@ static int gapspci_write(struct pci_bus
4819 return PCIBIOS_SUCCESSFUL;
4820 }
4821
4822 -struct pci_ops gapspci_pci_ops = {
4823 +const struct pci_ops gapspci_pci_ops = {
4824 .read = gapspci_read,
4825 .write = gapspci_write,
4826 };
4827 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c
4828 --- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c 2011-05-19 00:06:34.000000000 -0400
4829 +++ linux-2.6.39.1/arch/sh/drivers/pci/ops-sh4.c 2011-05-22 19:36:30.000000000 -0400
4830 @@ -96,7 +96,7 @@ static int sh4_pci_write(struct pci_bus
4831 return PCIBIOS_SUCCESSFUL;
4832 }
4833
4834 -struct pci_ops sh4_pci_ops = {
4835 +const struct pci_ops sh4_pci_ops = {
4836 .read = sh4_pci_read,
4837 .write = sh4_pci_write,
4838 };
4839 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c
4840 --- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c 2011-05-19 00:06:34.000000000 -0400
4841 +++ linux-2.6.39.1/arch/sh/drivers/pci/ops-sh5.c 2011-05-22 19:36:30.000000000 -0400
4842 @@ -62,7 +62,7 @@ static int sh5pci_write(struct pci_bus *
4843 return PCIBIOS_SUCCESSFUL;
4844 }
4845
4846 -struct pci_ops sh5_pci_ops = {
4847 +const struct pci_ops sh5_pci_ops = {
4848 .read = sh5pci_read,
4849 .write = sh5pci_write,
4850 };
4851 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c
4852 --- linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4853 +++ linux-2.6.39.1/arch/sh/drivers/pci/ops-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4854 @@ -165,7 +165,7 @@ out:
4855 return ret;
4856 }
4857
4858 -struct pci_ops sh7786_pci_ops = {
4859 +const struct pci_ops sh7786_pci_ops = {
4860 .read = sh7786_pcie_read,
4861 .write = sh7786_pcie_write,
4862 };
4863 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c
4864 --- linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4865 +++ linux-2.6.39.1/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4866 @@ -109,7 +109,7 @@ static struct resource sh7786_pci2_resou
4867 },
4868 };
4869
4870 -extern struct pci_ops sh7786_pci_ops;
4871 +extern const struct pci_ops sh7786_pci_ops;
4872
4873 #define DEFINE_CONTROLLER(start, idx) \
4874 { \
4875 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h
4876 --- linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h 2011-05-19 00:06:34.000000000 -0400
4877 +++ linux-2.6.39.1/arch/sh/drivers/pci/pci-sh4.h 2011-05-22 19:36:30.000000000 -0400
4878 @@ -161,7 +161,7 @@
4879 #define SH4_PCIPDR 0x220 /* Port IO Data Register */
4880
4881 /* arch/sh/kernel/drivers/pci/ops-sh4.c */
4882 -extern struct pci_ops sh4_pci_ops;
4883 +extern const struct pci_ops sh4_pci_ops;
4884 int pci_fixup_pcic(struct pci_channel *chan);
4885
4886 struct sh4_pci_address_space {
4887 diff -urNp linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h
4888 --- linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h 2011-05-19 00:06:34.000000000 -0400
4889 +++ linux-2.6.39.1/arch/sh/drivers/pci/pci-sh5.h 2011-05-22 19:36:30.000000000 -0400
4890 @@ -105,6 +105,6 @@ extern unsigned long pcicr_virt;
4891 #define PCISH5_MEM_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4892 #define PCISH5_IO_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4893
4894 -extern struct pci_ops sh5_pci_ops;
4895 +extern const struct pci_ops sh5_pci_ops;
4896
4897 #endif /* __PCI_SH5_H */
4898 diff -urNp linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h
4899 --- linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
4900 +++ linux-2.6.39.1/arch/sh/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
4901 @@ -1,10 +1,10 @@
4902 #ifndef __ASM_SH_DMA_MAPPING_H
4903 #define __ASM_SH_DMA_MAPPING_H
4904
4905 -extern struct dma_map_ops *dma_ops;
4906 +extern const struct dma_map_ops *dma_ops;
4907 extern void no_iommu_init(void);
4908
4909 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4910 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
4911 {
4912 return dma_ops;
4913 }
4914 @@ -14,7 +14,7 @@ static inline struct dma_map_ops *get_dm
4915
4916 static inline int dma_supported(struct device *dev, u64 mask)
4917 {
4918 - struct dma_map_ops *ops = get_dma_ops(dev);
4919 + const struct dma_map_ops *ops = get_dma_ops(dev);
4920
4921 if (ops->dma_supported)
4922 return ops->dma_supported(dev, mask);
4923 @@ -24,7 +24,7 @@ static inline int dma_supported(struct d
4924
4925 static inline int dma_set_mask(struct device *dev, u64 mask)
4926 {
4927 - struct dma_map_ops *ops = get_dma_ops(dev);
4928 + const struct dma_map_ops *ops = get_dma_ops(dev);
4929
4930 if (!dev->dma_mask || !dma_supported(dev, mask))
4931 return -EIO;
4932 @@ -44,7 +44,7 @@ void dma_cache_sync(struct device *dev,
4933
4934 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
4935 {
4936 - struct dma_map_ops *ops = get_dma_ops(dev);
4937 + const struct dma_map_ops *ops = get_dma_ops(dev);
4938
4939 if (ops->mapping_error)
4940 return ops->mapping_error(dev, dma_addr);
4941 @@ -55,7 +55,7 @@ static inline int dma_mapping_error(stru
4942 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4943 dma_addr_t *dma_handle, gfp_t gfp)
4944 {
4945 - struct dma_map_ops *ops = get_dma_ops(dev);
4946 + const struct dma_map_ops *ops = get_dma_ops(dev);
4947 void *memory;
4948
4949 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
4950 @@ -72,7 +72,7 @@ static inline void *dma_alloc_coherent(s
4951 static inline void dma_free_coherent(struct device *dev, size_t size,
4952 void *vaddr, dma_addr_t dma_handle)
4953 {
4954 - struct dma_map_ops *ops = get_dma_ops(dev);
4955 + const struct dma_map_ops *ops = get_dma_ops(dev);
4956
4957 if (dma_release_from_coherent(dev, get_order(size), vaddr))
4958 return;
4959 diff -urNp linux-2.6.39.1/arch/sh/kernel/dma-nommu.c linux-2.6.39.1/arch/sh/kernel/dma-nommu.c
4960 --- linux-2.6.39.1/arch/sh/kernel/dma-nommu.c 2011-05-19 00:06:34.000000000 -0400
4961 +++ linux-2.6.39.1/arch/sh/kernel/dma-nommu.c 2011-05-22 19:36:30.000000000 -0400
4962 @@ -62,7 +62,7 @@ static void nommu_sync_sg(struct device
4963 }
4964 #endif
4965
4966 -struct dma_map_ops nommu_dma_ops = {
4967 +const struct dma_map_ops nommu_dma_ops = {
4968 .alloc_coherent = dma_generic_alloc_coherent,
4969 .free_coherent = dma_generic_free_coherent,
4970 .map_page = nommu_map_page,
4971 diff -urNp linux-2.6.39.1/arch/sh/kernel/kgdb.c linux-2.6.39.1/arch/sh/kernel/kgdb.c
4972 --- linux-2.6.39.1/arch/sh/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
4973 +++ linux-2.6.39.1/arch/sh/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
4974 @@ -319,7 +319,7 @@ void kgdb_arch_exit(void)
4975 unregister_die_notifier(&kgdb_notifier);
4976 }
4977
4978 -struct kgdb_arch arch_kgdb_ops = {
4979 +const struct kgdb_arch arch_kgdb_ops = {
4980 /* Breakpoint instruction: trapa #0x3c */
4981 #ifdef CONFIG_CPU_LITTLE_ENDIAN
4982 .gdb_bpt_instr = { 0x3c, 0xc3 },
4983 diff -urNp linux-2.6.39.1/arch/sh/mm/consistent.c linux-2.6.39.1/arch/sh/mm/consistent.c
4984 --- linux-2.6.39.1/arch/sh/mm/consistent.c 2011-05-19 00:06:34.000000000 -0400
4985 +++ linux-2.6.39.1/arch/sh/mm/consistent.c 2011-05-22 19:36:30.000000000 -0400
4986 @@ -22,7 +22,7 @@
4987
4988 #define PREALLOC_DMA_DEBUG_ENTRIES 4096
4989
4990 -struct dma_map_ops *dma_ops;
4991 +const struct dma_map_ops *dma_ops;
4992 EXPORT_SYMBOL(dma_ops);
4993
4994 static int __init dma_init(void)
4995 diff -urNp linux-2.6.39.1/arch/sh/mm/mmap.c linux-2.6.39.1/arch/sh/mm/mmap.c
4996 --- linux-2.6.39.1/arch/sh/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4997 +++ linux-2.6.39.1/arch/sh/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
4998 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
4999 addr = PAGE_ALIGN(addr);
5000
5001 vma = find_vma(mm, addr);
5002 - if (TASK_SIZE - len >= addr &&
5003 - (!vma || addr + len <= vma->vm_start))
5004 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5005 return addr;
5006 }
5007
5008 @@ -106,7 +105,7 @@ full_search:
5009 }
5010 return -ENOMEM;
5011 }
5012 - if (likely(!vma || addr + len <= vma->vm_start)) {
5013 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5014 /*
5015 * Remember the place where we stopped the search:
5016 */
5017 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
5018 addr = PAGE_ALIGN(addr);
5019
5020 vma = find_vma(mm, addr);
5021 - if (TASK_SIZE - len >= addr &&
5022 - (!vma || addr + len <= vma->vm_start))
5023 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5024 return addr;
5025 }
5026
5027 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
5028 /* make sure it can fit in the remaining address space */
5029 if (likely(addr > len)) {
5030 vma = find_vma(mm, addr-len);
5031 - if (!vma || addr <= vma->vm_start) {
5032 + if (check_heap_stack_gap(vma, addr - len, len)) {
5033 /* remember the address as a hint for next time */
5034 return (mm->free_area_cache = addr-len);
5035 }
5036 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
5037 if (unlikely(mm->mmap_base < len))
5038 goto bottomup;
5039
5040 - addr = mm->mmap_base-len;
5041 - if (do_colour_align)
5042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5043 + addr = mm->mmap_base - len;
5044
5045 do {
5046 + if (do_colour_align)
5047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5048 /*
5049 * Lookup failure means no vma is above this address,
5050 * else if new region fits below vma->vm_start,
5051 * return with success:
5052 */
5053 vma = find_vma(mm, addr);
5054 - if (likely(!vma || addr+len <= vma->vm_start)) {
5055 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5056 /* remember the address as a hint for next time */
5057 return (mm->free_area_cache = addr);
5058 }
5059 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
5060 mm->cached_hole_size = vma->vm_start - addr;
5061
5062 /* try just below the current vma->vm_start */
5063 - addr = vma->vm_start-len;
5064 - if (do_colour_align)
5065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5066 - } while (likely(len < vma->vm_start));
5067 + addr = skip_heap_stack_gap(vma, len);
5068 + } while (!IS_ERR_VALUE(addr));
5069
5070 bottomup:
5071 /*
5072 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h
5073 --- linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h 2011-05-19 00:06:34.000000000 -0400
5074 +++ linux-2.6.39.1/arch/sparc/include/asm/atomic_64.h 2011-05-22 19:36:30.000000000 -0400
5075 @@ -14,18 +14,40 @@
5076 #define ATOMIC64_INIT(i) { (i) }
5077
5078 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5079 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5080 +{
5081 + return v->counter;
5082 +}
5083 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5084 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5085 +{
5086 + return v->counter;
5087 +}
5088
5089 #define atomic_set(v, i) (((v)->counter) = i)
5090 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5091 +{
5092 + v->counter = i;
5093 +}
5094 #define atomic64_set(v, i) (((v)->counter) = i)
5095 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5096 +{
5097 + v->counter = i;
5098 +}
5099
5100 extern void atomic_add(int, atomic_t *);
5101 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5102 extern void atomic64_add(long, atomic64_t *);
5103 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5104 extern void atomic_sub(int, atomic_t *);
5105 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5106 extern void atomic64_sub(long, atomic64_t *);
5107 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5108
5109 extern int atomic_add_ret(int, atomic_t *);
5110 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5111 extern long atomic64_add_ret(long, atomic64_t *);
5112 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5113 extern int atomic_sub_ret(int, atomic_t *);
5114 extern long atomic64_sub_ret(long, atomic64_t *);
5115
5116 @@ -33,12 +55,24 @@ extern long atomic64_sub_ret(long, atomi
5117 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5118
5119 #define atomic_inc_return(v) atomic_add_ret(1, v)
5120 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5121 +{
5122 + return atomic_add_ret_unchecked(1, v);
5123 +}
5124 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5125 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5126 +{
5127 + return atomic64_add_ret_unchecked(1, v);
5128 +}
5129
5130 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5131 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5132
5133 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5134 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5135 +{
5136 + return atomic_add_ret_unchecked(i, v);
5137 +}
5138 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5139
5140 /*
5141 @@ -50,6 +84,7 @@ extern long atomic64_sub_ret(long, atomi
5142 * other cases.
5143 */
5144 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5145 +#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
5146 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5147
5148 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5149 @@ -59,30 +94,59 @@ extern long atomic64_sub_ret(long, atomi
5150 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5151
5152 #define atomic_inc(v) atomic_add(1, v)
5153 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5154 +{
5155 + atomic_add_unchecked(1, v);
5156 +}
5157 #define atomic64_inc(v) atomic64_add(1, v)
5158 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5159 +{
5160 + atomic64_add_unchecked(1, v);
5161 +}
5162
5163 #define atomic_dec(v) atomic_sub(1, v)
5164 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5165 +{
5166 + atomic_sub_unchecked(1, v);
5167 +}
5168 #define atomic64_dec(v) atomic64_sub(1, v)
5169 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5170 +{
5171 + atomic64_sub_unchecked(1, v);
5172 +}
5173
5174 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5175 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5176
5177 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5178 +#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5179 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5180 +#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
5181
5182 static inline int atomic_add_unless(atomic_t *v, int a, int u)
5183 {
5184 - int c, old;
5185 + int c, old, new;
5186 c = atomic_read(v);
5187 for (;;) {
5188 - if (unlikely(c == (u)))
5189 + if (unlikely(c == u))
5190 break;
5191 - old = atomic_cmpxchg((v), c, c + (a));
5192 +
5193 + asm volatile("addcc %2, %0, %0\n"
5194 +
5195 +#ifdef CONFIG_PAX_REFCOUNT
5196 + "tvs %%icc, 6\n"
5197 +#endif
5198 +
5199 + : "=r" (new)
5200 + : "0" (c), "ir" (a)
5201 + : "cc");
5202 +
5203 + old = atomic_cmpxchg(v, c, new);
5204 if (likely(old == c))
5205 break;
5206 c = old;
5207 }
5208 - return c != (u);
5209 + return c != u;
5210 }
5211
5212 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
5213 @@ -93,17 +157,28 @@ static inline int atomic_add_unless(atom
5214
5215 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5216 {
5217 - long c, old;
5218 + long c, old, new;
5219 c = atomic64_read(v);
5220 for (;;) {
5221 - if (unlikely(c == (u)))
5222 + if (unlikely(c == u))
5223 break;
5224 - old = atomic64_cmpxchg((v), c, c + (a));
5225 +
5226 + asm volatile("addcc %2, %0, %0\n"
5227 +
5228 +#ifdef CONFIG_PAX_REFCOUNT
5229 + "tvs %%xcc, 6\n"
5230 +#endif
5231 +
5232 + : "=r" (new)
5233 + : "0" (c), "ir" (a)
5234 + : "cc");
5235 +
5236 + old = atomic64_cmpxchg(v, c, new);
5237 if (likely(old == c))
5238 break;
5239 c = old;
5240 }
5241 - return c != (u);
5242 + return c != u;
5243 }
5244
5245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5246 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/cache.h linux-2.6.39.1/arch/sparc/include/asm/cache.h
5247 --- linux-2.6.39.1/arch/sparc/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
5248 +++ linux-2.6.39.1/arch/sparc/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
5249 @@ -10,7 +10,7 @@
5250 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5251
5252 #define L1_CACHE_SHIFT 5
5253 -#define L1_CACHE_BYTES 32
5254 +#define L1_CACHE_BYTES 32U
5255
5256 #ifdef CONFIG_SPARC32
5257 #define SMP_CACHE_BYTES_SHIFT 5
5258 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h
5259 --- linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
5260 +++ linux-2.6.39.1/arch/sparc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
5261 @@ -12,10 +12,10 @@ extern int dma_supported(struct device *
5262 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
5263 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
5264
5265 -extern struct dma_map_ops *dma_ops, pci32_dma_ops;
5266 +extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
5267 extern struct bus_type pci_bus_type;
5268
5269 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
5270 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
5271 {
5272 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
5273 if (dev->bus == &pci_bus_type)
5274 @@ -29,7 +29,7 @@ static inline struct dma_map_ops *get_dm
5275 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
5276 dma_addr_t *dma_handle, gfp_t flag)
5277 {
5278 - struct dma_map_ops *ops = get_dma_ops(dev);
5279 + const struct dma_map_ops *ops = get_dma_ops(dev);
5280 void *cpu_addr;
5281
5282 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
5283 @@ -40,7 +40,7 @@ static inline void *dma_alloc_coherent(s
5284 static inline void dma_free_coherent(struct device *dev, size_t size,
5285 void *cpu_addr, dma_addr_t dma_handle)
5286 {
5287 - struct dma_map_ops *ops = get_dma_ops(dev);
5288 + const struct dma_map_ops *ops = get_dma_ops(dev);
5289
5290 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
5291 ops->free_coherent(dev, size, cpu_addr, dma_handle);
5292 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/elf_32.h linux-2.6.39.1/arch/sparc/include/asm/elf_32.h
5293 --- linux-2.6.39.1/arch/sparc/include/asm/elf_32.h 2011-05-19 00:06:34.000000000 -0400
5294 +++ linux-2.6.39.1/arch/sparc/include/asm/elf_32.h 2011-05-22 19:36:30.000000000 -0400
5295 @@ -114,6 +114,13 @@ typedef struct {
5296
5297 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5298
5299 +#ifdef CONFIG_PAX_ASLR
5300 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5301 +
5302 +#define PAX_DELTA_MMAP_LEN 16
5303 +#define PAX_DELTA_STACK_LEN 16
5304 +#endif
5305 +
5306 /* This yields a mask that user programs can use to figure out what
5307 instruction set this cpu supports. This can NOT be done in userspace
5308 on Sparc. */
5309 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/elf_64.h linux-2.6.39.1/arch/sparc/include/asm/elf_64.h
5310 --- linux-2.6.39.1/arch/sparc/include/asm/elf_64.h 2011-05-19 00:06:34.000000000 -0400
5311 +++ linux-2.6.39.1/arch/sparc/include/asm/elf_64.h 2011-05-22 19:36:30.000000000 -0400
5312 @@ -162,6 +162,12 @@ typedef struct {
5313 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5314 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5315
5316 +#ifdef CONFIG_PAX_ASLR
5317 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5318 +
5319 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5320 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5321 +#endif
5322
5323 /* This yields a mask that user programs can use to figure out what
5324 instruction set this cpu supports. */
5325 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h
5326 --- linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
5327 +++ linux-2.6.39.1/arch/sparc/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
5328 @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5329 BTFIXUPDEF_INT(page_none)
5330 BTFIXUPDEF_INT(page_copy)
5331 BTFIXUPDEF_INT(page_readonly)
5332 +
5333 +#ifdef CONFIG_PAX_PAGEEXEC
5334 +BTFIXUPDEF_INT(page_shared_noexec)
5335 +BTFIXUPDEF_INT(page_copy_noexec)
5336 +BTFIXUPDEF_INT(page_readonly_noexec)
5337 +#endif
5338 +
5339 BTFIXUPDEF_INT(page_kernel)
5340
5341 #define PMD_SHIFT SUN4C_PMD_SHIFT
5342 @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
5343 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5344 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5345
5346 +#ifdef CONFIG_PAX_PAGEEXEC
5347 +extern pgprot_t PAGE_SHARED_NOEXEC;
5348 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5349 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5350 +#else
5351 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5352 +# define PAGE_COPY_NOEXEC PAGE_COPY
5353 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5354 +#endif
5355 +
5356 extern unsigned long page_kernel;
5357
5358 #ifdef MODULE
5359 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h
5360 --- linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h 2011-05-19 00:06:34.000000000 -0400
5361 +++ linux-2.6.39.1/arch/sparc/include/asm/pgtsrmmu.h 2011-05-22 19:36:30.000000000 -0400
5362 @@ -115,6 +115,13 @@
5363 SRMMU_EXEC | SRMMU_REF)
5364 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5365 SRMMU_EXEC | SRMMU_REF)
5366 +
5367 +#ifdef CONFIG_PAX_PAGEEXEC
5368 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5369 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5370 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5371 +#endif
5372 +
5373 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5374 SRMMU_DIRTY | SRMMU_REF)
5375
5376 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h
5377 --- linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h 2011-05-19 00:06:34.000000000 -0400
5378 +++ linux-2.6.39.1/arch/sparc/include/asm/spinlock_64.h 2011-05-22 19:36:30.000000000 -0400
5379 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(
5380
5381 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5382
5383 -static void inline arch_read_lock(arch_rwlock_t *lock)
5384 +static inline void arch_read_lock(arch_rwlock_t *lock)
5385 {
5386 unsigned long tmp1, tmp2;
5387
5388 __asm__ __volatile__ (
5389 "1: ldsw [%2], %0\n"
5390 " brlz,pn %0, 2f\n"
5391 -"4: add %0, 1, %1\n"
5392 +"4: addcc %0, 1, %1\n"
5393 +
5394 +#ifdef CONFIG_PAX_REFCOUNT
5395 +" tvs %%icc, 6\n"
5396 +#endif
5397 +
5398 " cas [%2], %0, %1\n"
5399 " cmp %0, %1\n"
5400 " bne,pn %%icc, 1b\n"
5401 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_r
5402 " .previous"
5403 : "=&r" (tmp1), "=&r" (tmp2)
5404 : "r" (lock)
5405 - : "memory");
5406 + : "memory", "cc");
5407 }
5408
5409 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5410 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5411 {
5412 int tmp1, tmp2;
5413
5414 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch
5415 "1: ldsw [%2], %0\n"
5416 " brlz,a,pn %0, 2f\n"
5417 " mov 0, %0\n"
5418 -" add %0, 1, %1\n"
5419 +" addcc %0, 1, %1\n"
5420 +
5421 +#ifdef CONFIG_PAX_REFCOUNT
5422 +" tvs %%icc, 6\n"
5423 +#endif
5424 +
5425 " cas [%2], %0, %1\n"
5426 " cmp %0, %1\n"
5427 " bne,pn %%icc, 1b\n"
5428 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch
5429 return tmp1;
5430 }
5431
5432 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5433 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5434 {
5435 unsigned long tmp1, tmp2;
5436
5437 __asm__ __volatile__(
5438 "1: lduw [%2], %0\n"
5439 -" sub %0, 1, %1\n"
5440 +" subcc %0, 1, %1\n"
5441 +
5442 +#ifdef CONFIG_PAX_REFCOUNT
5443 +" tvs %%icc, 6\n"
5444 +#endif
5445 +
5446 " cas [%2], %0, %1\n"
5447 " cmp %0, %1\n"
5448 " bne,pn %%xcc, 1b\n"
5449 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch
5450 : "memory");
5451 }
5452
5453 -static void inline arch_write_lock(arch_rwlock_t *lock)
5454 +static inline void arch_write_lock(arch_rwlock_t *lock)
5455 {
5456 unsigned long mask, tmp1, tmp2;
5457
5458 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_
5459 : "memory");
5460 }
5461
5462 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5463 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5464 {
5465 __asm__ __volatile__(
5466 " stw %%g0, [%0]"
5467 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arc
5468 : "memory");
5469 }
5470
5471 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5472 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5473 {
5474 unsigned long mask, tmp1, tmp2, result;
5475
5476 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h
5477 --- linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h 2011-05-19 00:06:34.000000000 -0400
5478 +++ linux-2.6.39.1/arch/sparc/include/asm/thread_info_32.h 2011-06-03 01:14:03.000000000 -0400
5479 @@ -50,6 +50,8 @@ struct thread_info {
5480 unsigned long w_saved;
5481
5482 struct restart_block restart_block;
5483 +
5484 + unsigned long lowest_stack;
5485 };
5486
5487 /*
5488 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h
5489 --- linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h 2011-05-19 00:06:34.000000000 -0400
5490 +++ linux-2.6.39.1/arch/sparc/include/asm/thread_info_64.h 2011-06-03 01:14:21.000000000 -0400
5491 @@ -63,6 +63,8 @@ struct thread_info {
5492 struct pt_regs *kern_una_regs;
5493 unsigned int kern_una_insn;
5494
5495 + unsigned long lowest_stack;
5496 +
5497 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5498 };
5499
5500 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h
5501 --- linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
5502 +++ linux-2.6.39.1/arch/sparc/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
5503 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
5504
5505 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5506 {
5507 - if (n && __access_ok((unsigned long) to, n))
5508 + if ((long)n < 0)
5509 + return n;
5510 +
5511 + if (n && __access_ok((unsigned long) to, n)) {
5512 + if (!__builtin_constant_p(n))
5513 + check_object_size(from, n, true);
5514 return __copy_user(to, (__force void __user *) from, n);
5515 - else
5516 + } else
5517 return n;
5518 }
5519
5520 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5521 {
5522 + if ((long)n < 0)
5523 + return n;
5524 +
5525 + if (!__builtin_constant_p(n))
5526 + check_object_size(from, n, true);
5527 +
5528 return __copy_user(to, (__force void __user *) from, n);
5529 }
5530
5531 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5532 {
5533 - if (n && __access_ok((unsigned long) from, n))
5534 + if ((long)n < 0)
5535 + return n;
5536 +
5537 + if (n && __access_ok((unsigned long) from, n)) {
5538 + if (!__builtin_constant_p(n))
5539 + check_object_size(to, n, false);
5540 return __copy_user((__force void __user *) to, from, n);
5541 - else
5542 + } else
5543 return n;
5544 }
5545
5546 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5547 {
5548 + if ((long)n < 0)
5549 + return n;
5550 +
5551 return __copy_user((__force void __user *) to, from, n);
5552 }
5553
5554 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h
5555 --- linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
5556 +++ linux-2.6.39.1/arch/sparc/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
5557 @@ -10,6 +10,7 @@
5558 #include <linux/compiler.h>
5559 #include <linux/string.h>
5560 #include <linux/thread_info.h>
5561 +#include <linux/kernel.h>
5562 #include <asm/asi.h>
5563 #include <asm/system.h>
5564 #include <asm/spitfire.h>
5565 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
5566 static inline unsigned long __must_check
5567 copy_from_user(void *to, const void __user *from, unsigned long size)
5568 {
5569 - unsigned long ret = ___copy_from_user(to, from, size);
5570 + unsigned long ret;
5571
5572 + if ((long)size < 0 || size > INT_MAX)
5573 + return size;
5574 +
5575 + if (!__builtin_constant_p(size))
5576 + check_object_size(to, size, false);
5577 +
5578 + ret = ___copy_from_user(to, from, size);
5579 if (unlikely(ret))
5580 ret = copy_from_user_fixup(to, from, size);
5581
5582 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
5583 static inline unsigned long __must_check
5584 copy_to_user(void __user *to, const void *from, unsigned long size)
5585 {
5586 - unsigned long ret = ___copy_to_user(to, from, size);
5587 + unsigned long ret;
5588 +
5589 + if ((long)size < 0 || size > INT_MAX)
5590 + return size;
5591 +
5592 + if (!__builtin_constant_p(size))
5593 + check_object_size(from, size, true);
5594
5595 + ret = ___copy_to_user(to, from, size);
5596 if (unlikely(ret))
5597 ret = copy_to_user_fixup(to, from, size);
5598 return ret;
5599 diff -urNp linux-2.6.39.1/arch/sparc/include/asm/uaccess.h linux-2.6.39.1/arch/sparc/include/asm/uaccess.h
5600 --- linux-2.6.39.1/arch/sparc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
5601 +++ linux-2.6.39.1/arch/sparc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
5602 @@ -1,5 +1,13 @@
5603 #ifndef ___ASM_SPARC_UACCESS_H
5604 #define ___ASM_SPARC_UACCESS_H
5605 +
5606 +#ifdef __KERNEL__
5607 +#ifndef __ASSEMBLY__
5608 +#include <linux/types.h>
5609 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5610 +#endif
5611 +#endif
5612 +
5613 #if defined(__sparc__) && defined(__arch64__)
5614 #include <asm/uaccess_64.h>
5615 #else
5616 diff -urNp linux-2.6.39.1/arch/sparc/kernel/iommu.c linux-2.6.39.1/arch/sparc/kernel/iommu.c
5617 --- linux-2.6.39.1/arch/sparc/kernel/iommu.c 2011-05-19 00:06:34.000000000 -0400
5618 +++ linux-2.6.39.1/arch/sparc/kernel/iommu.c 2011-05-22 19:36:30.000000000 -0400
5619 @@ -824,7 +824,7 @@ static void dma_4u_sync_sg_for_cpu(struc
5620 spin_unlock_irqrestore(&iommu->lock, flags);
5621 }
5622
5623 -static struct dma_map_ops sun4u_dma_ops = {
5624 +static const struct dma_map_ops sun4u_dma_ops = {
5625 .alloc_coherent = dma_4u_alloc_coherent,
5626 .free_coherent = dma_4u_free_coherent,
5627 .map_page = dma_4u_map_page,
5628 @@ -835,7 +835,7 @@ static struct dma_map_ops sun4u_dma_ops
5629 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
5630 };
5631
5632 -struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5633 +const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5634 EXPORT_SYMBOL(dma_ops);
5635
5636 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
5637 diff -urNp linux-2.6.39.1/arch/sparc/kernel/ioport.c linux-2.6.39.1/arch/sparc/kernel/ioport.c
5638 --- linux-2.6.39.1/arch/sparc/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
5639 +++ linux-2.6.39.1/arch/sparc/kernel/ioport.c 2011-05-22 19:36:30.000000000 -0400
5640 @@ -402,7 +402,7 @@ static void sbus_sync_sg_for_device(stru
5641 BUG();
5642 }
5643
5644 -struct dma_map_ops sbus_dma_ops = {
5645 +const struct dma_map_ops sbus_dma_ops = {
5646 .alloc_coherent = sbus_alloc_coherent,
5647 .free_coherent = sbus_free_coherent,
5648 .map_page = sbus_map_page,
5649 @@ -653,7 +653,7 @@ static void pci32_sync_sg_for_device(str
5650 }
5651 }
5652
5653 -struct dma_map_ops pci32_dma_ops = {
5654 +const struct dma_map_ops pci32_dma_ops = {
5655 .alloc_coherent = pci32_alloc_coherent,
5656 .free_coherent = pci32_free_coherent,
5657 .map_page = pci32_map_page,
5658 diff -urNp linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c
5659 --- linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c 2011-05-19 00:06:34.000000000 -0400
5660 +++ linux-2.6.39.1/arch/sparc/kernel/kgdb_32.c 2011-05-22 19:36:30.000000000 -0400
5661 @@ -164,7 +164,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5662 regs->npc = regs->pc + 4;
5663 }
5664
5665 -struct kgdb_arch arch_kgdb_ops = {
5666 +const struct kgdb_arch arch_kgdb_ops = {
5667 /* Breakpoint instruction: ta 0x7d */
5668 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
5669 };
5670 diff -urNp linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c
5671 --- linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c 2011-05-19 00:06:34.000000000 -0400
5672 +++ linux-2.6.39.1/arch/sparc/kernel/kgdb_64.c 2011-05-22 19:36:30.000000000 -0400
5673 @@ -187,7 +187,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5674 regs->tnpc = regs->tpc + 4;
5675 }
5676
5677 -struct kgdb_arch arch_kgdb_ops = {
5678 +const struct kgdb_arch arch_kgdb_ops = {
5679 /* Breakpoint instruction: ta 0x72 */
5680 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
5681 };
5682 diff -urNp linux-2.6.39.1/arch/sparc/kernel/Makefile linux-2.6.39.1/arch/sparc/kernel/Makefile
5683 --- linux-2.6.39.1/arch/sparc/kernel/Makefile 2011-05-19 00:06:34.000000000 -0400
5684 +++ linux-2.6.39.1/arch/sparc/kernel/Makefile 2011-05-22 19:36:30.000000000 -0400
5685 @@ -3,7 +3,7 @@
5686 #
5687
5688 asflags-y := -ansi
5689 -ccflags-y := -Werror
5690 +#ccflags-y := -Werror
5691
5692 extra-y := head_$(BITS).o
5693 extra-y += init_task.o
5694 diff -urNp linux-2.6.39.1/arch/sparc/kernel/pcic.c linux-2.6.39.1/arch/sparc/kernel/pcic.c
5695 --- linux-2.6.39.1/arch/sparc/kernel/pcic.c 2011-05-19 00:06:34.000000000 -0400
5696 +++ linux-2.6.39.1/arch/sparc/kernel/pcic.c 2011-05-22 19:36:30.000000000 -0400
5697 @@ -268,7 +268,7 @@ static int pcic_write_config(struct pci_
5698 return -EINVAL;
5699 }
5700
5701 -static struct pci_ops pcic_ops = {
5702 +static const struct pci_ops pcic_ops = {
5703 .read = pcic_read_config,
5704 .write = pcic_write_config,
5705 };
5706 diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_common.c linux-2.6.39.1/arch/sparc/kernel/pci_common.c
5707 --- linux-2.6.39.1/arch/sparc/kernel/pci_common.c 2011-05-19 00:06:34.000000000 -0400
5708 +++ linux-2.6.39.1/arch/sparc/kernel/pci_common.c 2011-05-22 19:36:30.000000000 -0400
5709 @@ -249,7 +249,7 @@ static int sun4u_write_pci_cfg(struct pc
5710 return PCIBIOS_SUCCESSFUL;
5711 }
5712
5713 -struct pci_ops sun4u_pci_ops = {
5714 +const struct pci_ops sun4u_pci_ops = {
5715 .read = sun4u_read_pci_cfg,
5716 .write = sun4u_write_pci_cfg,
5717 };
5718 @@ -310,7 +310,7 @@ static int sun4v_write_pci_cfg(struct pc
5719 return PCIBIOS_SUCCESSFUL;
5720 }
5721
5722 -struct pci_ops sun4v_pci_ops = {
5723 +const struct pci_ops sun4v_pci_ops = {
5724 .read = sun4v_read_pci_cfg,
5725 .write = sun4v_write_pci_cfg,
5726 };
5727 diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_impl.h linux-2.6.39.1/arch/sparc/kernel/pci_impl.h
5728 --- linux-2.6.39.1/arch/sparc/kernel/pci_impl.h 2011-05-19 00:06:34.000000000 -0400
5729 +++ linux-2.6.39.1/arch/sparc/kernel/pci_impl.h 2011-05-22 19:36:30.000000000 -0400
5730 @@ -175,8 +175,8 @@ extern void pci_config_write8(u8 *addr,
5731 extern void pci_config_write16(u16 *addr, u16 val);
5732 extern void pci_config_write32(u32 *addr, u32 val);
5733
5734 -extern struct pci_ops sun4u_pci_ops;
5735 -extern struct pci_ops sun4v_pci_ops;
5736 +extern const struct pci_ops sun4u_pci_ops;
5737 +extern const struct pci_ops sun4v_pci_ops;
5738
5739 extern volatile int pci_poke_in_progress;
5740 extern volatile int pci_poke_cpu;
5741 diff -urNp linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c
5742 --- linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c 2011-05-19 00:06:34.000000000 -0400
5743 +++ linux-2.6.39.1/arch/sparc/kernel/pci_sun4v.c 2011-05-22 19:36:30.000000000 -0400
5744 @@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
5745 spin_unlock_irqrestore(&iommu->lock, flags);
5746 }
5747
5748 -static struct dma_map_ops sun4v_dma_ops = {
5749 +static const struct dma_map_ops sun4v_dma_ops = {
5750 .alloc_coherent = dma_4v_alloc_coherent,
5751 .free_coherent = dma_4v_free_coherent,
5752 .map_page = dma_4v_map_page,
5753 diff -urNp linux-2.6.39.1/arch/sparc/kernel/process_32.c linux-2.6.39.1/arch/sparc/kernel/process_32.c
5754 --- linux-2.6.39.1/arch/sparc/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
5755 +++ linux-2.6.39.1/arch/sparc/kernel/process_32.c 2011-05-22 19:41:32.000000000 -0400
5756 @@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
5757 rw->ins[4], rw->ins[5],
5758 rw->ins[6],
5759 rw->ins[7]);
5760 - printk("%pS\n", (void *) rw->ins[7]);
5761 + printk("%pA\n", (void *) rw->ins[7]);
5762 rw = (struct reg_window32 *) rw->ins[6];
5763 }
5764 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5765 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
5766
5767 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5768 r->psr, r->pc, r->npc, r->y, print_tainted());
5769 - printk("PC: <%pS>\n", (void *) r->pc);
5770 + printk("PC: <%pA>\n", (void *) r->pc);
5771 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5772 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5773 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5774 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5775 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5776 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5777 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5778 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5779
5780 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5781 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5782 @@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
5783 rw = (struct reg_window32 *) fp;
5784 pc = rw->ins[7];
5785 printk("[%08lx : ", pc);
5786 - printk("%pS ] ", (void *) pc);
5787 + printk("%pA ] ", (void *) pc);
5788 fp = rw->ins[6];
5789 } while (++count < 16);
5790 printk("\n");
5791 diff -urNp linux-2.6.39.1/arch/sparc/kernel/process_64.c linux-2.6.39.1/arch/sparc/kernel/process_64.c
5792 --- linux-2.6.39.1/arch/sparc/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
5793 +++ linux-2.6.39.1/arch/sparc/kernel/process_64.c 2011-05-22 19:41:32.000000000 -0400
5794 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
5795 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5796 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5797 if (regs->tstate & TSTATE_PRIV)
5798 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5799 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5800 }
5801
5802 void show_regs(struct pt_regs *regs)
5803 {
5804 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5805 regs->tpc, regs->tnpc, regs->y, print_tainted());
5806 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5807 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5808 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5809 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5810 regs->u_regs[3]);
5811 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5812 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5813 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5814 regs->u_regs[15]);
5815 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5816 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5817 show_regwindow(regs);
5818 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5819 }
5820 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
5821 ((tp && tp->task) ? tp->task->pid : -1));
5822
5823 if (gp->tstate & TSTATE_PRIV) {
5824 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5825 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5826 (void *) gp->tpc,
5827 (void *) gp->o7,
5828 (void *) gp->i7,
5829 diff -urNp linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c
5830 --- linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c 2011-05-19 00:06:34.000000000 -0400
5831 +++ linux-2.6.39.1/arch/sparc/kernel/sys_sparc_32.c 2011-05-22 19:36:30.000000000 -0400
5832 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
5833 if (ARCH_SUN4C && len > 0x20000000)
5834 return -ENOMEM;
5835 if (!addr)
5836 - addr = TASK_UNMAPPED_BASE;
5837 + addr = current->mm->mmap_base;
5838
5839 if (flags & MAP_SHARED)
5840 addr = COLOUR_ALIGN(addr);
5841 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
5842 }
5843 if (TASK_SIZE - PAGE_SIZE - len < addr)
5844 return -ENOMEM;
5845 - if (!vmm || addr + len <= vmm->vm_start)
5846 + if (check_heap_stack_gap(vmm, addr, len))
5847 return addr;
5848 addr = vmm->vm_end;
5849 if (flags & MAP_SHARED)
5850 diff -urNp linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c
5851 --- linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c 2011-05-19 00:06:34.000000000 -0400
5852 +++ linux-2.6.39.1/arch/sparc/kernel/sys_sparc_64.c 2011-05-22 19:36:30.000000000 -0400
5853 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
5854 /* We do not accept a shared mapping if it would violate
5855 * cache aliasing constraints.
5856 */
5857 - if ((flags & MAP_SHARED) &&
5858 + if ((filp || (flags & MAP_SHARED)) &&
5859 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5860 return -EINVAL;
5861 return addr;
5862 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
5863 if (filp || (flags & MAP_SHARED))
5864 do_color_align = 1;
5865
5866 +#ifdef CONFIG_PAX_RANDMMAP
5867 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5868 +#endif
5869 +
5870 if (addr) {
5871 if (do_color_align)
5872 addr = COLOUR_ALIGN(addr, pgoff);
5873 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
5874 addr = PAGE_ALIGN(addr);
5875
5876 vma = find_vma(mm, addr);
5877 - if (task_size - len >= addr &&
5878 - (!vma || addr + len <= vma->vm_start))
5879 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5880 return addr;
5881 }
5882
5883 if (len > mm->cached_hole_size) {
5884 - start_addr = addr = mm->free_area_cache;
5885 + start_addr = addr = mm->free_area_cache;
5886 } else {
5887 - start_addr = addr = TASK_UNMAPPED_BASE;
5888 + start_addr = addr = mm->mmap_base;
5889 mm->cached_hole_size = 0;
5890 }
5891
5892 @@ -174,14 +177,14 @@ full_search:
5893 vma = find_vma(mm, VA_EXCLUDE_END);
5894 }
5895 if (unlikely(task_size < addr)) {
5896 - if (start_addr != TASK_UNMAPPED_BASE) {
5897 - start_addr = addr = TASK_UNMAPPED_BASE;
5898 + if (start_addr != mm->mmap_base) {
5899 + start_addr = addr = mm->mmap_base;
5900 mm->cached_hole_size = 0;
5901 goto full_search;
5902 }
5903 return -ENOMEM;
5904 }
5905 - if (likely(!vma || addr + len <= vma->vm_start)) {
5906 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5907 /*
5908 * Remember the place where we stopped the search:
5909 */
5910 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
5911 /* We do not accept a shared mapping if it would violate
5912 * cache aliasing constraints.
5913 */
5914 - if ((flags & MAP_SHARED) &&
5915 + if ((filp || (flags & MAP_SHARED)) &&
5916 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5917 return -EINVAL;
5918 return addr;
5919 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
5920 addr = PAGE_ALIGN(addr);
5921
5922 vma = find_vma(mm, addr);
5923 - if (task_size - len >= addr &&
5924 - (!vma || addr + len <= vma->vm_start))
5925 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5926 return addr;
5927 }
5928
5929 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
5930 /* make sure it can fit in the remaining address space */
5931 if (likely(addr > len)) {
5932 vma = find_vma(mm, addr-len);
5933 - if (!vma || addr <= vma->vm_start) {
5934 + if (check_heap_stack_gap(vma, addr - len, len)) {
5935 /* remember the address as a hint for next time */
5936 return (mm->free_area_cache = addr-len);
5937 }
5938 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct fi
5939 if (unlikely(mm->mmap_base < len))
5940 goto bottomup;
5941
5942 - addr = mm->mmap_base-len;
5943 - if (do_color_align)
5944 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5945 + addr = mm->mmap_base - len;
5946
5947 do {
5948 + if (do_color_align)
5949 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5950 /*
5951 * Lookup failure means no vma is above this address,
5952 * else if new region fits below vma->vm_start,
5953 * return with success:
5954 */
5955 vma = find_vma(mm, addr);
5956 - if (likely(!vma || addr+len <= vma->vm_start)) {
5957 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5958 /* remember the address as a hint for next time */
5959 return (mm->free_area_cache = addr);
5960 }
5961 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct fi
5962 mm->cached_hole_size = vma->vm_start - addr;
5963
5964 /* try just below the current vma->vm_start */
5965 - addr = vma->vm_start-len;
5966 - if (do_color_align)
5967 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5968 - } while (likely(len < vma->vm_start));
5969 + addr = skip_heap_stack_gap(vma, len);
5970 + } while (!IS_ERR_VALUE(addr));
5971
5972 bottomup:
5973 /*
5974 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_str
5975 gap == RLIM_INFINITY ||
5976 sysctl_legacy_va_layout) {
5977 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5978 +
5979 +#ifdef CONFIG_PAX_RANDMMAP
5980 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5981 + mm->mmap_base += mm->delta_mmap;
5982 +#endif
5983 +
5984 mm->get_unmapped_area = arch_get_unmapped_area;
5985 mm->unmap_area = arch_unmap_area;
5986 } else {
5987 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_str
5988 gap = (task_size / 6 * 5);
5989
5990 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5991 +
5992 +#ifdef CONFIG_PAX_RANDMMAP
5993 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5994 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5995 +#endif
5996 +
5997 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5998 mm->unmap_area = arch_unmap_area_topdown;
5999 }
6000 diff -urNp linux-2.6.39.1/arch/sparc/kernel/traps_32.c linux-2.6.39.1/arch/sparc/kernel/traps_32.c
6001 --- linux-2.6.39.1/arch/sparc/kernel/traps_32.c 2011-05-19 00:06:34.000000000 -0400
6002 +++ linux-2.6.39.1/arch/sparc/kernel/traps_32.c 2011-05-22 19:41:32.000000000 -0400
6003 @@ -76,7 +76,7 @@ void die_if_kernel(char *str, struct pt_
6004 count++ < 30 &&
6005 (((unsigned long) rw) >= PAGE_OFFSET) &&
6006 !(((unsigned long) rw) & 0x7)) {
6007 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6008 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6009 (void *) rw->ins[7]);
6010 rw = (struct reg_window32 *)rw->ins[6];
6011 }
6012 diff -urNp linux-2.6.39.1/arch/sparc/kernel/traps_64.c linux-2.6.39.1/arch/sparc/kernel/traps_64.c
6013 --- linux-2.6.39.1/arch/sparc/kernel/traps_64.c 2011-05-19 00:06:34.000000000 -0400
6014 +++ linux-2.6.39.1/arch/sparc/kernel/traps_64.c 2011-05-22 19:41:32.000000000 -0400
6015 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
6016 i + 1,
6017 p->trapstack[i].tstate, p->trapstack[i].tpc,
6018 p->trapstack[i].tnpc, p->trapstack[i].tt);
6019 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6020 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6021 }
6022 }
6023
6024 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
6025
6026 lvl -= 0x100;
6027 if (regs->tstate & TSTATE_PRIV) {
6028 +
6029 +#ifdef CONFIG_PAX_REFCOUNT
6030 + if (lvl == 6)
6031 + pax_report_refcount_overflow(regs);
6032 +#endif
6033 +
6034 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6035 die_if_kernel(buffer, regs);
6036 }
6037 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
6038 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6039 {
6040 char buffer[32];
6041 -
6042 +
6043 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6044 0, lvl, SIGTRAP) == NOTIFY_STOP)
6045 return;
6046
6047 +#ifdef CONFIG_PAX_REFCOUNT
6048 + if (lvl == 6)
6049 + pax_report_refcount_overflow(regs);
6050 +#endif
6051 +
6052 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6053
6054 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6055 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
6056 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6057 printk("%s" "ERROR(%d): ",
6058 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6059 - printk("TPC<%pS>\n", (void *) regs->tpc);
6060 + printk("TPC<%pA>\n", (void *) regs->tpc);
6061 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6062 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6063 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6064 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
6065 smp_processor_id(),
6066 (type & 0x1) ? 'I' : 'D',
6067 regs->tpc);
6068 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6069 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6070 panic("Irrecoverable Cheetah+ parity error.");
6071 }
6072
6073 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
6074 smp_processor_id(),
6075 (type & 0x1) ? 'I' : 'D',
6076 regs->tpc);
6077 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6078 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6079 }
6080
6081 struct sun4v_error_entry {
6082 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
6083
6084 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6085 regs->tpc, tl);
6086 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6087 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6088 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6089 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6090 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6091 (void *) regs->u_regs[UREG_I7]);
6092 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6093 "pte[%lx] error[%lx]\n",
6094 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
6095
6096 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6097 regs->tpc, tl);
6098 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6099 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6100 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6101 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6102 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6103 (void *) regs->u_regs[UREG_I7]);
6104 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6105 "pte[%lx] error[%lx]\n",
6106 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk,
6107 fp = (unsigned long)sf->fp + STACK_BIAS;
6108 }
6109
6110 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6111 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6112 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6113 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6114 int index = tsk->curr_ret_stack;
6115 if (tsk->ret_stack && index >= graph) {
6116 pc = tsk->ret_stack[index - graph].ret;
6117 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6118 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6119 graph++;
6120 }
6121 }
6122 @@ -2254,7 +2265,7 @@ void die_if_kernel(char *str, struct pt_
6123 while (rw &&
6124 count++ < 30 &&
6125 kstack_valid(tp, (unsigned long) rw)) {
6126 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6127 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6128 (void *) rw->ins[7]);
6129
6130 rw = kernel_stack_up(rw);
6131 diff -urNp linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c
6132 --- linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c 2011-05-19 00:06:34.000000000 -0400
6133 +++ linux-2.6.39.1/arch/sparc/kernel/unaligned_64.c 2011-05-22 19:41:32.000000000 -0400
6134 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs
6135 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6136
6137 if (__ratelimit(&ratelimit)) {
6138 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6139 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6140 regs->tpc, (void *) regs->tpc);
6141 }
6142 }
6143 diff -urNp linux-2.6.39.1/arch/sparc/lib/atomic_64.S linux-2.6.39.1/arch/sparc/lib/atomic_64.S
6144 --- linux-2.6.39.1/arch/sparc/lib/atomic_64.S 2011-05-19 00:06:34.000000000 -0400
6145 +++ linux-2.6.39.1/arch/sparc/lib/atomic_64.S 2011-05-22 19:36:30.000000000 -0400
6146 @@ -18,7 +18,12 @@
6147 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6148 BACKOFF_SETUP(%o2)
6149 1: lduw [%o1], %g1
6150 - add %g1, %o0, %g7
6151 + addcc %g1, %o0, %g7
6152 +
6153 +#ifdef CONFIG_PAX_REFCOUNT
6154 + tvs %icc, 6
6155 +#endif
6156 +
6157 cas [%o1], %g1, %g7
6158 cmp %g1, %g7
6159 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6160 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
6161 2: BACKOFF_SPIN(%o2, %o3, 1b)
6162 .size atomic_add, .-atomic_add
6163
6164 + .globl atomic_add_unchecked
6165 + .type atomic_add_unchecked,#function
6166 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6167 + BACKOFF_SETUP(%o2)
6168 +1: lduw [%o1], %g1
6169 + add %g1, %o0, %g7
6170 + cas [%o1], %g1, %g7
6171 + cmp %g1, %g7
6172 + bne,pn %icc, 2f
6173 + nop
6174 + retl
6175 + nop
6176 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6177 + .size atomic_add_unchecked, .-atomic_add_unchecked
6178 +
6179 .globl atomic_sub
6180 .type atomic_sub,#function
6181 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6182 BACKOFF_SETUP(%o2)
6183 1: lduw [%o1], %g1
6184 - sub %g1, %o0, %g7
6185 + subcc %g1, %o0, %g7
6186 +
6187 +#ifdef CONFIG_PAX_REFCOUNT
6188 + tvs %icc, 6
6189 +#endif
6190 +
6191 cas [%o1], %g1, %g7
6192 cmp %g1, %g7
6193 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6194 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
6195 2: BACKOFF_SPIN(%o2, %o3, 1b)
6196 .size atomic_sub, .-atomic_sub
6197
6198 + .globl atomic_sub_unchecked
6199 + .type atomic_sub_unchecked,#function
6200 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6201 + BACKOFF_SETUP(%o2)
6202 +1: lduw [%o1], %g1
6203 + sub %g1, %o0, %g7
6204 + cas [%o1], %g1, %g7
6205 + cmp %g1, %g7
6206 + bne,pn %icc, 2f
6207 + nop
6208 + retl
6209 + nop
6210 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6211 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6212 +
6213 .globl atomic_add_ret
6214 .type atomic_add_ret,#function
6215 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6216 BACKOFF_SETUP(%o2)
6217 1: lduw [%o1], %g1
6218 - add %g1, %o0, %g7
6219 + addcc %g1, %o0, %g7
6220 +
6221 +#ifdef CONFIG_PAX_REFCOUNT
6222 + tvs %icc, 6
6223 +#endif
6224 +
6225 cas [%o1], %g1, %g7
6226 cmp %g1, %g7
6227 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6228 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
6229 2: BACKOFF_SPIN(%o2, %o3, 1b)
6230 .size atomic_add_ret, .-atomic_add_ret
6231
6232 + .globl atomic_add_ret_unchecked
6233 + .type atomic_add_ret_unchecked,#function
6234 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6235 + BACKOFF_SETUP(%o2)
6236 +1: lduw [%o1], %g1
6237 + addcc %g1, %o0, %g7
6238 + cas [%o1], %g1, %g7
6239 + cmp %g1, %g7
6240 + bne,pn %icc, 2f
6241 + add %g7, %o0, %g7
6242 + sra %g7, 0, %o0
6243 + retl
6244 + nop
6245 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6246 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6247 +
6248 .globl atomic_sub_ret
6249 .type atomic_sub_ret,#function
6250 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6251 BACKOFF_SETUP(%o2)
6252 1: lduw [%o1], %g1
6253 - sub %g1, %o0, %g7
6254 + subcc %g1, %o0, %g7
6255 +
6256 +#ifdef CONFIG_PAX_REFCOUNT
6257 + tvs %icc, 6
6258 +#endif
6259 +
6260 cas [%o1], %g1, %g7
6261 cmp %g1, %g7
6262 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6263 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
6264 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6265 BACKOFF_SETUP(%o2)
6266 1: ldx [%o1], %g1
6267 - add %g1, %o0, %g7
6268 + addcc %g1, %o0, %g7
6269 +
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + tvs %xcc, 6
6272 +#endif
6273 +
6274 casx [%o1], %g1, %g7
6275 cmp %g1, %g7
6276 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6277 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
6278 2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 .size atomic64_add, .-atomic64_add
6280
6281 + .globl atomic64_add_unchecked
6282 + .type atomic64_add_unchecked,#function
6283 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6284 + BACKOFF_SETUP(%o2)
6285 +1: ldx [%o1], %g1
6286 + addcc %g1, %o0, %g7
6287 + casx [%o1], %g1, %g7
6288 + cmp %g1, %g7
6289 + bne,pn %xcc, 2f
6290 + nop
6291 + retl
6292 + nop
6293 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6294 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6295 +
6296 .globl atomic64_sub
6297 .type atomic64_sub,#function
6298 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6299 BACKOFF_SETUP(%o2)
6300 1: ldx [%o1], %g1
6301 - sub %g1, %o0, %g7
6302 + subcc %g1, %o0, %g7
6303 +
6304 +#ifdef CONFIG_PAX_REFCOUNT
6305 + tvs %xcc, 6
6306 +#endif
6307 +
6308 casx [%o1], %g1, %g7
6309 cmp %g1, %g7
6310 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6311 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
6312 2: BACKOFF_SPIN(%o2, %o3, 1b)
6313 .size atomic64_sub, .-atomic64_sub
6314
6315 + .globl atomic64_sub_unchecked
6316 + .type atomic64_sub_unchecked,#function
6317 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6318 + BACKOFF_SETUP(%o2)
6319 +1: ldx [%o1], %g1
6320 + subcc %g1, %o0, %g7
6321 + casx [%o1], %g1, %g7
6322 + cmp %g1, %g7
6323 + bne,pn %xcc, 2f
6324 + nop
6325 + retl
6326 + nop
6327 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6328 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6329 +
6330 .globl atomic64_add_ret
6331 .type atomic64_add_ret,#function
6332 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6333 BACKOFF_SETUP(%o2)
6334 1: ldx [%o1], %g1
6335 - add %g1, %o0, %g7
6336 + addcc %g1, %o0, %g7
6337 +
6338 +#ifdef CONFIG_PAX_REFCOUNT
6339 + tvs %xcc, 6
6340 +#endif
6341 +
6342 casx [%o1], %g1, %g7
6343 cmp %g1, %g7
6344 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6345 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
6346 2: BACKOFF_SPIN(%o2, %o3, 1b)
6347 .size atomic64_add_ret, .-atomic64_add_ret
6348
6349 + .globl atomic64_add_ret_unchecked
6350 + .type atomic64_add_ret_unchecked,#function
6351 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6352 + BACKOFF_SETUP(%o2)
6353 +1: ldx [%o1], %g1
6354 + addcc %g1, %o0, %g7
6355 + casx [%o1], %g1, %g7
6356 + cmp %g1, %g7
6357 + bne,pn %xcc, 2f
6358 + add %g7, %o0, %g7
6359 + mov %g7, %o0
6360 + retl
6361 + nop
6362 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6364 +
6365 .globl atomic64_sub_ret
6366 .type atomic64_sub_ret,#function
6367 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6368 BACKOFF_SETUP(%o2)
6369 1: ldx [%o1], %g1
6370 - sub %g1, %o0, %g7
6371 + subcc %g1, %o0, %g7
6372 +
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + tvs %xcc, 6
6375 +#endif
6376 +
6377 casx [%o1], %g1, %g7
6378 cmp %g1, %g7
6379 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6380 diff -urNp linux-2.6.39.1/arch/sparc/lib/ksyms.c linux-2.6.39.1/arch/sparc/lib/ksyms.c
6381 --- linux-2.6.39.1/arch/sparc/lib/ksyms.c 2011-05-19 00:06:34.000000000 -0400
6382 +++ linux-2.6.39.1/arch/sparc/lib/ksyms.c 2011-05-22 19:36:30.000000000 -0400
6383 @@ -142,12 +142,17 @@ EXPORT_SYMBOL(__downgrade_write);
6384
6385 /* Atomic counter implementation. */
6386 EXPORT_SYMBOL(atomic_add);
6387 +EXPORT_SYMBOL(atomic_add_unchecked);
6388 EXPORT_SYMBOL(atomic_add_ret);
6389 EXPORT_SYMBOL(atomic_sub);
6390 +EXPORT_SYMBOL(atomic_sub_unchecked);
6391 EXPORT_SYMBOL(atomic_sub_ret);
6392 EXPORT_SYMBOL(atomic64_add);
6393 +EXPORT_SYMBOL(atomic64_add_unchecked);
6394 EXPORT_SYMBOL(atomic64_add_ret);
6395 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6396 EXPORT_SYMBOL(atomic64_sub);
6397 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6398 EXPORT_SYMBOL(atomic64_sub_ret);
6399
6400 /* Atomic bit operations. */
6401 diff -urNp linux-2.6.39.1/arch/sparc/lib/Makefile linux-2.6.39.1/arch/sparc/lib/Makefile
6402 --- linux-2.6.39.1/arch/sparc/lib/Makefile 2011-05-19 00:06:34.000000000 -0400
6403 +++ linux-2.6.39.1/arch/sparc/lib/Makefile 2011-05-22 19:36:30.000000000 -0400
6404 @@ -2,7 +2,7 @@
6405 #
6406
6407 asflags-y := -ansi -DST_DIV0=0x02
6408 -ccflags-y := -Werror
6409 +#ccflags-y := -Werror
6410
6411 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6412 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6413 diff -urNp linux-2.6.39.1/arch/sparc/Makefile linux-2.6.39.1/arch/sparc/Makefile
6414 --- linux-2.6.39.1/arch/sparc/Makefile 2011-05-19 00:06:34.000000000 -0400
6415 +++ linux-2.6.39.1/arch/sparc/Makefile 2011-05-22 19:41:32.000000000 -0400
6416 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
6417 # Export what is needed by arch/sparc/boot/Makefile
6418 export VMLINUX_INIT VMLINUX_MAIN
6419 VMLINUX_INIT := $(head-y) $(init-y)
6420 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
6421 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
6422 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
6423 VMLINUX_MAIN += $(drivers-y) $(net-y)
6424
6425 diff -urNp linux-2.6.39.1/arch/sparc/mm/fault_32.c linux-2.6.39.1/arch/sparc/mm/fault_32.c
6426 --- linux-2.6.39.1/arch/sparc/mm/fault_32.c 2011-05-19 00:06:34.000000000 -0400
6427 +++ linux-2.6.39.1/arch/sparc/mm/fault_32.c 2011-05-22 19:36:30.000000000 -0400
6428 @@ -22,6 +22,9 @@
6429 #include <linux/interrupt.h>
6430 #include <linux/module.h>
6431 #include <linux/kdebug.h>
6432 +#include <linux/slab.h>
6433 +#include <linux/pagemap.h>
6434 +#include <linux/compiler.h>
6435
6436 #include <asm/system.h>
6437 #include <asm/page.h>
6438 @@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
6439 return safe_compute_effective_address(regs, insn);
6440 }
6441
6442 +#ifdef CONFIG_PAX_PAGEEXEC
6443 +#ifdef CONFIG_PAX_DLRESOLVE
6444 +static void pax_emuplt_close(struct vm_area_struct *vma)
6445 +{
6446 + vma->vm_mm->call_dl_resolve = 0UL;
6447 +}
6448 +
6449 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6450 +{
6451 + unsigned int *kaddr;
6452 +
6453 + vmf->page = alloc_page(GFP_HIGHUSER);
6454 + if (!vmf->page)
6455 + return VM_FAULT_OOM;
6456 +
6457 + kaddr = kmap(vmf->page);
6458 + memset(kaddr, 0, PAGE_SIZE);
6459 + kaddr[0] = 0x9DE3BFA8U; /* save */
6460 + flush_dcache_page(vmf->page);
6461 + kunmap(vmf->page);
6462 + return VM_FAULT_MAJOR;
6463 +}
6464 +
6465 +static const struct vm_operations_struct pax_vm_ops = {
6466 + .close = pax_emuplt_close,
6467 + .fault = pax_emuplt_fault
6468 +};
6469 +
6470 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6471 +{
6472 + int ret;
6473 +
6474 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6475 + vma->vm_mm = current->mm;
6476 + vma->vm_start = addr;
6477 + vma->vm_end = addr + PAGE_SIZE;
6478 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6479 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6480 + vma->vm_ops = &pax_vm_ops;
6481 +
6482 + ret = insert_vm_struct(current->mm, vma);
6483 + if (ret)
6484 + return ret;
6485 +
6486 + ++current->mm->total_vm;
6487 + return 0;
6488 +}
6489 +#endif
6490 +
6491 +/*
6492 + * PaX: decide what to do with offenders (regs->pc = fault address)
6493 + *
6494 + * returns 1 when task should be killed
6495 + * 2 when patched PLT trampoline was detected
6496 + * 3 when unpatched PLT trampoline was detected
6497 + */
6498 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6499 +{
6500 +
6501 +#ifdef CONFIG_PAX_EMUPLT
6502 + int err;
6503 +
6504 + do { /* PaX: patched PLT emulation #1 */
6505 + unsigned int sethi1, sethi2, jmpl;
6506 +
6507 + err = get_user(sethi1, (unsigned int *)regs->pc);
6508 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6509 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6510 +
6511 + if (err)
6512 + break;
6513 +
6514 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6515 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6516 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6517 + {
6518 + unsigned int addr;
6519 +
6520 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6521 + addr = regs->u_regs[UREG_G1];
6522 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6523 + regs->pc = addr;
6524 + regs->npc = addr+4;
6525 + return 2;
6526 + }
6527 + } while (0);
6528 +
6529 + { /* PaX: patched PLT emulation #2 */
6530 + unsigned int ba;
6531 +
6532 + err = get_user(ba, (unsigned int *)regs->pc);
6533 +
6534 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6535 + unsigned int addr;
6536 +
6537 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6538 + regs->pc = addr;
6539 + regs->npc = addr+4;
6540 + return 2;
6541 + }
6542 + }
6543 +
6544 + do { /* PaX: patched PLT emulation #3 */
6545 + unsigned int sethi, jmpl, nop;
6546 +
6547 + err = get_user(sethi, (unsigned int *)regs->pc);
6548 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6549 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6550 +
6551 + if (err)
6552 + break;
6553 +
6554 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6555 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6556 + nop == 0x01000000U)
6557 + {
6558 + unsigned int addr;
6559 +
6560 + addr = (sethi & 0x003FFFFFU) << 10;
6561 + regs->u_regs[UREG_G1] = addr;
6562 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6563 + regs->pc = addr;
6564 + regs->npc = addr+4;
6565 + return 2;
6566 + }
6567 + } while (0);
6568 +
6569 + do { /* PaX: unpatched PLT emulation step 1 */
6570 + unsigned int sethi, ba, nop;
6571 +
6572 + err = get_user(sethi, (unsigned int *)regs->pc);
6573 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6574 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6575 +
6576 + if (err)
6577 + break;
6578 +
6579 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6580 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6581 + nop == 0x01000000U)
6582 + {
6583 + unsigned int addr, save, call;
6584 +
6585 + if ((ba & 0xFFC00000U) == 0x30800000U)
6586 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6587 + else
6588 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6589 +
6590 + err = get_user(save, (unsigned int *)addr);
6591 + err |= get_user(call, (unsigned int *)(addr+4));
6592 + err |= get_user(nop, (unsigned int *)(addr+8));
6593 + if (err)
6594 + break;
6595 +
6596 +#ifdef CONFIG_PAX_DLRESOLVE
6597 + if (save == 0x9DE3BFA8U &&
6598 + (call & 0xC0000000U) == 0x40000000U &&
6599 + nop == 0x01000000U)
6600 + {
6601 + struct vm_area_struct *vma;
6602 + unsigned long call_dl_resolve;
6603 +
6604 + down_read(&current->mm->mmap_sem);
6605 + call_dl_resolve = current->mm->call_dl_resolve;
6606 + up_read(&current->mm->mmap_sem);
6607 + if (likely(call_dl_resolve))
6608 + goto emulate;
6609 +
6610 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6611 +
6612 + down_write(&current->mm->mmap_sem);
6613 + if (current->mm->call_dl_resolve) {
6614 + call_dl_resolve = current->mm->call_dl_resolve;
6615 + up_write(&current->mm->mmap_sem);
6616 + if (vma)
6617 + kmem_cache_free(vm_area_cachep, vma);
6618 + goto emulate;
6619 + }
6620 +
6621 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6622 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6623 + up_write(&current->mm->mmap_sem);
6624 + if (vma)
6625 + kmem_cache_free(vm_area_cachep, vma);
6626 + return 1;
6627 + }
6628 +
6629 + if (pax_insert_vma(vma, call_dl_resolve)) {
6630 + up_write(&current->mm->mmap_sem);
6631 + kmem_cache_free(vm_area_cachep, vma);
6632 + return 1;
6633 + }
6634 +
6635 + current->mm->call_dl_resolve = call_dl_resolve;
6636 + up_write(&current->mm->mmap_sem);
6637 +
6638 +emulate:
6639 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6640 + regs->pc = call_dl_resolve;
6641 + regs->npc = addr+4;
6642 + return 3;
6643 + }
6644 +#endif
6645 +
6646 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6647 + if ((save & 0xFFC00000U) == 0x05000000U &&
6648 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6649 + nop == 0x01000000U)
6650 + {
6651 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6652 + regs->u_regs[UREG_G2] = addr + 4;
6653 + addr = (save & 0x003FFFFFU) << 10;
6654 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6655 + regs->pc = addr;
6656 + regs->npc = addr+4;
6657 + return 3;
6658 + }
6659 + }
6660 + } while (0);
6661 +
6662 + do { /* PaX: unpatched PLT emulation step 2 */
6663 + unsigned int save, call, nop;
6664 +
6665 + err = get_user(save, (unsigned int *)(regs->pc-4));
6666 + err |= get_user(call, (unsigned int *)regs->pc);
6667 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6668 + if (err)
6669 + break;
6670 +
6671 + if (save == 0x9DE3BFA8U &&
6672 + (call & 0xC0000000U) == 0x40000000U &&
6673 + nop == 0x01000000U)
6674 + {
6675 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6676 +
6677 + regs->u_regs[UREG_RETPC] = regs->pc;
6678 + regs->pc = dl_resolve;
6679 + regs->npc = dl_resolve+4;
6680 + return 3;
6681 + }
6682 + } while (0);
6683 +#endif
6684 +
6685 + return 1;
6686 +}
6687 +
6688 +void pax_report_insns(void *pc, void *sp)
6689 +{
6690 + unsigned long i;
6691 +
6692 + printk(KERN_ERR "PAX: bytes at PC: ");
6693 + for (i = 0; i < 8; i++) {
6694 + unsigned int c;
6695 + if (get_user(c, (unsigned int *)pc+i))
6696 + printk(KERN_CONT "???????? ");
6697 + else
6698 + printk(KERN_CONT "%08x ", c);
6699 + }
6700 + printk("\n");
6701 +}
6702 +#endif
6703 +
6704 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6705 int text_fault)
6706 {
6707 @@ -281,6 +546,24 @@ good_area:
6708 if(!(vma->vm_flags & VM_WRITE))
6709 goto bad_area;
6710 } else {
6711 +
6712 +#ifdef CONFIG_PAX_PAGEEXEC
6713 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6714 + up_read(&mm->mmap_sem);
6715 + switch (pax_handle_fetch_fault(regs)) {
6716 +
6717 +#ifdef CONFIG_PAX_EMUPLT
6718 + case 2:
6719 + case 3:
6720 + return;
6721 +#endif
6722 +
6723 + }
6724 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6725 + do_group_exit(SIGKILL);
6726 + }
6727 +#endif
6728 +
6729 /* Allow reads even for write-only mappings */
6730 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6731 goto bad_area;
6732 diff -urNp linux-2.6.39.1/arch/sparc/mm/fault_64.c linux-2.6.39.1/arch/sparc/mm/fault_64.c
6733 --- linux-2.6.39.1/arch/sparc/mm/fault_64.c 2011-05-19 00:06:34.000000000 -0400
6734 +++ linux-2.6.39.1/arch/sparc/mm/fault_64.c 2011-05-22 19:41:32.000000000 -0400
6735 @@ -21,6 +21,9 @@
6736 #include <linux/kprobes.h>
6737 #include <linux/kdebug.h>
6738 #include <linux/percpu.h>
6739 +#include <linux/slab.h>
6740 +#include <linux/pagemap.h>
6741 +#include <linux/compiler.h>
6742
6743 #include <asm/page.h>
6744 #include <asm/pgtable.h>
6745 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
6746 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6747 regs->tpc);
6748 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6749 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6750 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6751 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6752 dump_stack();
6753 unhandled_fault(regs->tpc, current, regs);
6754 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
6755 show_regs(regs);
6756 }
6757
6758 +#ifdef CONFIG_PAX_PAGEEXEC
6759 +#ifdef CONFIG_PAX_DLRESOLVE
6760 +static void pax_emuplt_close(struct vm_area_struct *vma)
6761 +{
6762 + vma->vm_mm->call_dl_resolve = 0UL;
6763 +}
6764 +
6765 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6766 +{
6767 + unsigned int *kaddr;
6768 +
6769 + vmf->page = alloc_page(GFP_HIGHUSER);
6770 + if (!vmf->page)
6771 + return VM_FAULT_OOM;
6772 +
6773 + kaddr = kmap(vmf->page);
6774 + memset(kaddr, 0, PAGE_SIZE);
6775 + kaddr[0] = 0x9DE3BFA8U; /* save */
6776 + flush_dcache_page(vmf->page);
6777 + kunmap(vmf->page);
6778 + return VM_FAULT_MAJOR;
6779 +}
6780 +
6781 +static const struct vm_operations_struct pax_vm_ops = {
6782 + .close = pax_emuplt_close,
6783 + .fault = pax_emuplt_fault
6784 +};
6785 +
6786 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6787 +{
6788 + int ret;
6789 +
6790 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6791 + vma->vm_mm = current->mm;
6792 + vma->vm_start = addr;
6793 + vma->vm_end = addr + PAGE_SIZE;
6794 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6795 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6796 + vma->vm_ops = &pax_vm_ops;
6797 +
6798 + ret = insert_vm_struct(current->mm, vma);
6799 + if (ret)
6800 + return ret;
6801 +
6802 + ++current->mm->total_vm;
6803 + return 0;
6804 +}
6805 +#endif
6806 +
6807 +/*
6808 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6809 + *
6810 + * returns 1 when task should be killed
6811 + * 2 when patched PLT trampoline was detected
6812 + * 3 when unpatched PLT trampoline was detected
6813 + */
6814 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6815 +{
6816 +
6817 +#ifdef CONFIG_PAX_EMUPLT
6818 + int err;
6819 +
6820 + do { /* PaX: patched PLT emulation #1 */
6821 + unsigned int sethi1, sethi2, jmpl;
6822 +
6823 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6824 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6825 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6826 +
6827 + if (err)
6828 + break;
6829 +
6830 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6831 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6832 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6833 + {
6834 + unsigned long addr;
6835 +
6836 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6837 + addr = regs->u_regs[UREG_G1];
6838 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6839 +
6840 + if (test_thread_flag(TIF_32BIT))
6841 + addr &= 0xFFFFFFFFUL;
6842 +
6843 + regs->tpc = addr;
6844 + regs->tnpc = addr+4;
6845 + return 2;
6846 + }
6847 + } while (0);
6848 +
6849 + { /* PaX: patched PLT emulation #2 */
6850 + unsigned int ba;
6851 +
6852 + err = get_user(ba, (unsigned int *)regs->tpc);
6853 +
6854 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6855 + unsigned long addr;
6856 +
6857 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6858 +
6859 + if (test_thread_flag(TIF_32BIT))
6860 + addr &= 0xFFFFFFFFUL;
6861 +
6862 + regs->tpc = addr;
6863 + regs->tnpc = addr+4;
6864 + return 2;
6865 + }
6866 + }
6867 +
6868 + do { /* PaX: patched PLT emulation #3 */
6869 + unsigned int sethi, jmpl, nop;
6870 +
6871 + err = get_user(sethi, (unsigned int *)regs->tpc);
6872 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6873 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6874 +
6875 + if (err)
6876 + break;
6877 +
6878 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6879 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6880 + nop == 0x01000000U)
6881 + {
6882 + unsigned long addr;
6883 +
6884 + addr = (sethi & 0x003FFFFFU) << 10;
6885 + regs->u_regs[UREG_G1] = addr;
6886 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6887 +
6888 + if (test_thread_flag(TIF_32BIT))
6889 + addr &= 0xFFFFFFFFUL;
6890 +
6891 + regs->tpc = addr;
6892 + regs->tnpc = addr+4;
6893 + return 2;
6894 + }
6895 + } while (0);
6896 +
6897 + do { /* PaX: patched PLT emulation #4 */
6898 + unsigned int sethi, mov1, call, mov2;
6899 +
6900 + err = get_user(sethi, (unsigned int *)regs->tpc);
6901 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6902 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6903 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6904 +
6905 + if (err)
6906 + break;
6907 +
6908 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6909 + mov1 == 0x8210000FU &&
6910 + (call & 0xC0000000U) == 0x40000000U &&
6911 + mov2 == 0x9E100001U)
6912 + {
6913 + unsigned long addr;
6914 +
6915 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6916 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6917 +
6918 + if (test_thread_flag(TIF_32BIT))
6919 + addr &= 0xFFFFFFFFUL;
6920 +
6921 + regs->tpc = addr;
6922 + regs->tnpc = addr+4;
6923 + return 2;
6924 + }
6925 + } while (0);
6926 +
6927 + do { /* PaX: patched PLT emulation #5 */
6928 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6929 +
6930 + err = get_user(sethi, (unsigned int *)regs->tpc);
6931 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6932 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6933 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6934 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6935 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6936 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6937 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6938 +
6939 + if (err)
6940 + break;
6941 +
6942 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6943 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6944 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6945 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6946 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6947 + sllx == 0x83287020U &&
6948 + jmpl == 0x81C04005U &&
6949 + nop == 0x01000000U)
6950 + {
6951 + unsigned long addr;
6952 +
6953 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6954 + regs->u_regs[UREG_G1] <<= 32;
6955 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6956 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6957 + regs->tpc = addr;
6958 + regs->tnpc = addr+4;
6959 + return 2;
6960 + }
6961 + } while (0);
6962 +
6963 + do { /* PaX: patched PLT emulation #6 */
6964 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6965 +
6966 + err = get_user(sethi, (unsigned int *)regs->tpc);
6967 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6968 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6969 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6970 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6971 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6972 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6973 +
6974 + if (err)
6975 + break;
6976 +
6977 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6978 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6979 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6980 + sllx == 0x83287020U &&
6981 + (or & 0xFFFFE000U) == 0x8A116000U &&
6982 + jmpl == 0x81C04005U &&
6983 + nop == 0x01000000U)
6984 + {
6985 + unsigned long addr;
6986 +
6987 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6988 + regs->u_regs[UREG_G1] <<= 32;
6989 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6990 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6991 + regs->tpc = addr;
6992 + regs->tnpc = addr+4;
6993 + return 2;
6994 + }
6995 + } while (0);
6996 +
6997 + do { /* PaX: unpatched PLT emulation step 1 */
6998 + unsigned int sethi, ba, nop;
6999 +
7000 + err = get_user(sethi, (unsigned int *)regs->tpc);
7001 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7002 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7003 +
7004 + if (err)
7005 + break;
7006 +
7007 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7008 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7009 + nop == 0x01000000U)
7010 + {
7011 + unsigned long addr;
7012 + unsigned int save, call;
7013 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7014 +
7015 + if ((ba & 0xFFC00000U) == 0x30800000U)
7016 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7017 + else
7018 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7019 +
7020 + if (test_thread_flag(TIF_32BIT))
7021 + addr &= 0xFFFFFFFFUL;
7022 +
7023 + err = get_user(save, (unsigned int *)addr);
7024 + err |= get_user(call, (unsigned int *)(addr+4));
7025 + err |= get_user(nop, (unsigned int *)(addr+8));
7026 + if (err)
7027 + break;
7028 +
7029 +#ifdef CONFIG_PAX_DLRESOLVE
7030 + if (save == 0x9DE3BFA8U &&
7031 + (call & 0xC0000000U) == 0x40000000U &&
7032 + nop == 0x01000000U)
7033 + {
7034 + struct vm_area_struct *vma;
7035 + unsigned long call_dl_resolve;
7036 +
7037 + down_read(&current->mm->mmap_sem);
7038 + call_dl_resolve = current->mm->call_dl_resolve;
7039 + up_read(&current->mm->mmap_sem);
7040 + if (likely(call_dl_resolve))
7041 + goto emulate;
7042 +
7043 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7044 +
7045 + down_write(&current->mm->mmap_sem);
7046 + if (current->mm->call_dl_resolve) {
7047 + call_dl_resolve = current->mm->call_dl_resolve;
7048 + up_write(&current->mm->mmap_sem);
7049 + if (vma)
7050 + kmem_cache_free(vm_area_cachep, vma);
7051 + goto emulate;
7052 + }
7053 +
7054 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7055 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7056 + up_write(&current->mm->mmap_sem);
7057 + if (vma)
7058 + kmem_cache_free(vm_area_cachep, vma);
7059 + return 1;
7060 + }
7061 +
7062 + if (pax_insert_vma(vma, call_dl_resolve)) {
7063 + up_write(&current->mm->mmap_sem);
7064 + kmem_cache_free(vm_area_cachep, vma);
7065 + return 1;
7066 + }
7067 +
7068 + current->mm->call_dl_resolve = call_dl_resolve;
7069 + up_write(&current->mm->mmap_sem);
7070 +
7071 +emulate:
7072 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7073 + regs->tpc = call_dl_resolve;
7074 + regs->tnpc = addr+4;
7075 + return 3;
7076 + }
7077 +#endif
7078 +
7079 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7080 + if ((save & 0xFFC00000U) == 0x05000000U &&
7081 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7082 + nop == 0x01000000U)
7083 + {
7084 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7085 + regs->u_regs[UREG_G2] = addr + 4;
7086 + addr = (save & 0x003FFFFFU) << 10;
7087 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7088 +
7089 + if (test_thread_flag(TIF_32BIT))
7090 + addr &= 0xFFFFFFFFUL;
7091 +
7092 + regs->tpc = addr;
7093 + regs->tnpc = addr+4;
7094 + return 3;
7095 + }
7096 +
7097 + /* PaX: 64-bit PLT stub */
7098 + err = get_user(sethi1, (unsigned int *)addr);
7099 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7100 + err |= get_user(or1, (unsigned int *)(addr+8));
7101 + err |= get_user(or2, (unsigned int *)(addr+12));
7102 + err |= get_user(sllx, (unsigned int *)(addr+16));
7103 + err |= get_user(add, (unsigned int *)(addr+20));
7104 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7105 + err |= get_user(nop, (unsigned int *)(addr+28));
7106 + if (err)
7107 + break;
7108 +
7109 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7110 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7111 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7112 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7113 + sllx == 0x89293020U &&
7114 + add == 0x8A010005U &&
7115 + jmpl == 0x89C14000U &&
7116 + nop == 0x01000000U)
7117 + {
7118 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7119 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7120 + regs->u_regs[UREG_G4] <<= 32;
7121 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7122 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7123 + regs->u_regs[UREG_G4] = addr + 24;
7124 + addr = regs->u_regs[UREG_G5];
7125 + regs->tpc = addr;
7126 + regs->tnpc = addr+4;
7127 + return 3;
7128 + }
7129 + }
7130 + } while (0);
7131 +
7132 +#ifdef CONFIG_PAX_DLRESOLVE
7133 + do { /* PaX: unpatched PLT emulation step 2 */
7134 + unsigned int save, call, nop;
7135 +
7136 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7137 + err |= get_user(call, (unsigned int *)regs->tpc);
7138 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7139 + if (err)
7140 + break;
7141 +
7142 + if (save == 0x9DE3BFA8U &&
7143 + (call & 0xC0000000U) == 0x40000000U &&
7144 + nop == 0x01000000U)
7145 + {
7146 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7147 +
7148 + if (test_thread_flag(TIF_32BIT))
7149 + dl_resolve &= 0xFFFFFFFFUL;
7150 +
7151 + regs->u_regs[UREG_RETPC] = regs->tpc;
7152 + regs->tpc = dl_resolve;
7153 + regs->tnpc = dl_resolve+4;
7154 + return 3;
7155 + }
7156 + } while (0);
7157 +#endif
7158 +
7159 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7160 + unsigned int sethi, ba, nop;
7161 +
7162 + err = get_user(sethi, (unsigned int *)regs->tpc);
7163 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7164 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7165 +
7166 + if (err)
7167 + break;
7168 +
7169 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7170 + (ba & 0xFFF00000U) == 0x30600000U &&
7171 + nop == 0x01000000U)
7172 + {
7173 + unsigned long addr;
7174 +
7175 + addr = (sethi & 0x003FFFFFU) << 10;
7176 + regs->u_regs[UREG_G1] = addr;
7177 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7178 +
7179 + if (test_thread_flag(TIF_32BIT))
7180 + addr &= 0xFFFFFFFFUL;
7181 +
7182 + regs->tpc = addr;
7183 + regs->tnpc = addr+4;
7184 + return 2;
7185 + }
7186 + } while (0);
7187 +
7188 +#endif
7189 +
7190 + return 1;
7191 +}
7192 +
7193 +void pax_report_insns(void *pc, void *sp)
7194 +{
7195 + unsigned long i;
7196 +
7197 + printk(KERN_ERR "PAX: bytes at PC: ");
7198 + for (i = 0; i < 8; i++) {
7199 + unsigned int c;
7200 + if (get_user(c, (unsigned int *)pc+i))
7201 + printk(KERN_CONT "???????? ");
7202 + else
7203 + printk(KERN_CONT "%08x ", c);
7204 + }
7205 + printk("\n");
7206 +}
7207 +#endif
7208 +
7209 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7210 {
7211 struct mm_struct *mm = current->mm;
7212 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
7213 if (!vma)
7214 goto bad_area;
7215
7216 +#ifdef CONFIG_PAX_PAGEEXEC
7217 + /* PaX: detect ITLB misses on non-exec pages */
7218 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7219 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7220 + {
7221 + if (address != regs->tpc)
7222 + goto good_area;
7223 +
7224 + up_read(&mm->mmap_sem);
7225 + switch (pax_handle_fetch_fault(regs)) {
7226 +
7227 +#ifdef CONFIG_PAX_EMUPLT
7228 + case 2:
7229 + case 3:
7230 + return;
7231 +#endif
7232 +
7233 + }
7234 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7235 + do_group_exit(SIGKILL);
7236 + }
7237 +#endif
7238 +
7239 /* Pure DTLB misses do not tell us whether the fault causing
7240 * load/store/atomic was a write or not, it only says that there
7241 * was no match. So in such a case we (carefully) read the
7242 diff -urNp linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c
7243 --- linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
7244 +++ linux-2.6.39.1/arch/sparc/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
7245 @@ -68,7 +68,7 @@ full_search:
7246 }
7247 return -ENOMEM;
7248 }
7249 - if (likely(!vma || addr + len <= vma->vm_start)) {
7250 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7251 /*
7252 * Remember the place where we stopped the search:
7253 */
7254 @@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
7255 /* make sure it can fit in the remaining address space */
7256 if (likely(addr > len)) {
7257 vma = find_vma(mm, addr-len);
7258 - if (!vma || addr <= vma->vm_start) {
7259 + if (check_heap_stack_gap(vma, addr - len, len)) {
7260 /* remember the address as a hint for next time */
7261 return (mm->free_area_cache = addr-len);
7262 }
7263 @@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct
7264 if (unlikely(mm->mmap_base < len))
7265 goto bottomup;
7266
7267 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7268 + addr = mm->mmap_base - len;
7269
7270 do {
7271 + addr &= HPAGE_MASK;
7272 /*
7273 * Lookup failure means no vma is above this address,
7274 * else if new region fits below vma->vm_start,
7275 * return with success:
7276 */
7277 vma = find_vma(mm, addr);
7278 - if (likely(!vma || addr+len <= vma->vm_start)) {
7279 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7280 /* remember the address as a hint for next time */
7281 return (mm->free_area_cache = addr);
7282 }
7283 @@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct
7284 mm->cached_hole_size = vma->vm_start - addr;
7285
7286 /* try just below the current vma->vm_start */
7287 - addr = (vma->vm_start-len) & HPAGE_MASK;
7288 - } while (likely(len < vma->vm_start));
7289 + addr = skip_heap_stack_gap(vma, len);
7290 + } while (!IS_ERR_VALUE(addr));
7291
7292 bottomup:
7293 /*
7294 @@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *f
7295 if (addr) {
7296 addr = ALIGN(addr, HPAGE_SIZE);
7297 vma = find_vma(mm, addr);
7298 - if (task_size - len >= addr &&
7299 - (!vma || addr + len <= vma->vm_start))
7300 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7301 return addr;
7302 }
7303 if (mm->get_unmapped_area == arch_get_unmapped_area)
7304 diff -urNp linux-2.6.39.1/arch/sparc/mm/init_32.c linux-2.6.39.1/arch/sparc/mm/init_32.c
7305 --- linux-2.6.39.1/arch/sparc/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
7306 +++ linux-2.6.39.1/arch/sparc/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
7307 @@ -318,6 +318,9 @@ extern void device_scan(void);
7308 pgprot_t PAGE_SHARED __read_mostly;
7309 EXPORT_SYMBOL(PAGE_SHARED);
7310
7311 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7312 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7313 +
7314 void __init paging_init(void)
7315 {
7316 switch(sparc_cpu_model) {
7317 @@ -346,17 +349,17 @@ void __init paging_init(void)
7318
7319 /* Initialize the protection map with non-constant, MMU dependent values. */
7320 protection_map[0] = PAGE_NONE;
7321 - protection_map[1] = PAGE_READONLY;
7322 - protection_map[2] = PAGE_COPY;
7323 - protection_map[3] = PAGE_COPY;
7324 + protection_map[1] = PAGE_READONLY_NOEXEC;
7325 + protection_map[2] = PAGE_COPY_NOEXEC;
7326 + protection_map[3] = PAGE_COPY_NOEXEC;
7327 protection_map[4] = PAGE_READONLY;
7328 protection_map[5] = PAGE_READONLY;
7329 protection_map[6] = PAGE_COPY;
7330 protection_map[7] = PAGE_COPY;
7331 protection_map[8] = PAGE_NONE;
7332 - protection_map[9] = PAGE_READONLY;
7333 - protection_map[10] = PAGE_SHARED;
7334 - protection_map[11] = PAGE_SHARED;
7335 + protection_map[9] = PAGE_READONLY_NOEXEC;
7336 + protection_map[10] = PAGE_SHARED_NOEXEC;
7337 + protection_map[11] = PAGE_SHARED_NOEXEC;
7338 protection_map[12] = PAGE_READONLY;
7339 protection_map[13] = PAGE_READONLY;
7340 protection_map[14] = PAGE_SHARED;
7341 diff -urNp linux-2.6.39.1/arch/sparc/mm/Makefile linux-2.6.39.1/arch/sparc/mm/Makefile
7342 --- linux-2.6.39.1/arch/sparc/mm/Makefile 2011-05-19 00:06:34.000000000 -0400
7343 +++ linux-2.6.39.1/arch/sparc/mm/Makefile 2011-05-22 19:36:30.000000000 -0400
7344 @@ -2,7 +2,7 @@
7345 #
7346
7347 asflags-y := -ansi
7348 -ccflags-y := -Werror
7349 +#ccflags-y := -Werror
7350
7351 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
7352 obj-y += fault_$(BITS).o
7353 diff -urNp linux-2.6.39.1/arch/sparc/mm/srmmu.c linux-2.6.39.1/arch/sparc/mm/srmmu.c
7354 --- linux-2.6.39.1/arch/sparc/mm/srmmu.c 2011-05-19 00:06:34.000000000 -0400
7355 +++ linux-2.6.39.1/arch/sparc/mm/srmmu.c 2011-05-22 19:36:30.000000000 -0400
7356 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7357 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7358 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7359 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7360 +
7361 +#ifdef CONFIG_PAX_PAGEEXEC
7362 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7363 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7364 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7365 +#endif
7366 +
7367 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7368 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7369
7370 diff -urNp linux-2.6.39.1/arch/tile/kernel/pci.c linux-2.6.39.1/arch/tile/kernel/pci.c
7371 --- linux-2.6.39.1/arch/tile/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7372 +++ linux-2.6.39.1/arch/tile/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7373 @@ -60,7 +60,7 @@ int __write_once tile_plx_gen1;
7374 static struct pci_controller controllers[TILE_NUM_PCIE];
7375 static int num_controllers;
7376
7377 -static struct pci_ops tile_cfg_ops;
7378 +static const struct pci_ops tile_cfg_ops;
7379
7380
7381 /*
7382 @@ -564,7 +564,7 @@ static int __devinit tile_cfg_write(stru
7383 }
7384
7385
7386 -static struct pci_ops tile_cfg_ops = {
7387 +static const struct pci_ops tile_cfg_ops = {
7388 .read = tile_cfg_read,
7389 .write = tile_cfg_write,
7390 };
7391 diff -urNp linux-2.6.39.1/arch/um/include/asm/kmap_types.h linux-2.6.39.1/arch/um/include/asm/kmap_types.h
7392 --- linux-2.6.39.1/arch/um/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
7393 +++ linux-2.6.39.1/arch/um/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
7394 @@ -23,6 +23,7 @@ enum km_type {
7395 KM_IRQ1,
7396 KM_SOFTIRQ0,
7397 KM_SOFTIRQ1,
7398 + KM_CLEARPAGE,
7399 KM_TYPE_NR
7400 };
7401
7402 diff -urNp linux-2.6.39.1/arch/um/include/asm/page.h linux-2.6.39.1/arch/um/include/asm/page.h
7403 --- linux-2.6.39.1/arch/um/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
7404 +++ linux-2.6.39.1/arch/um/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
7405 @@ -14,6 +14,9 @@
7406 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7407 #define PAGE_MASK (~(PAGE_SIZE-1))
7408
7409 +#define ktla_ktva(addr) (addr)
7410 +#define ktva_ktla(addr) (addr)
7411 +
7412 #ifndef __ASSEMBLY__
7413
7414 struct page;
7415 diff -urNp linux-2.6.39.1/arch/um/kernel/process.c linux-2.6.39.1/arch/um/kernel/process.c
7416 --- linux-2.6.39.1/arch/um/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
7417 +++ linux-2.6.39.1/arch/um/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
7418 @@ -404,22 +404,6 @@ int singlestepping(void * t)
7419 return 2;
7420 }
7421
7422 -/*
7423 - * Only x86 and x86_64 have an arch_align_stack().
7424 - * All other arches have "#define arch_align_stack(x) (x)"
7425 - * in their asm/system.h
7426 - * As this is included in UML from asm-um/system-generic.h,
7427 - * we can use it to behave as the subarch does.
7428 - */
7429 -#ifndef arch_align_stack
7430 -unsigned long arch_align_stack(unsigned long sp)
7431 -{
7432 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7433 - sp -= get_random_int() % 8192;
7434 - return sp & ~0xf;
7435 -}
7436 -#endif
7437 -
7438 unsigned long get_wchan(struct task_struct *p)
7439 {
7440 unsigned long stack_page, sp, ip;
7441 diff -urNp linux-2.6.39.1/arch/um/sys-i386/syscalls.c linux-2.6.39.1/arch/um/sys-i386/syscalls.c
7442 --- linux-2.6.39.1/arch/um/sys-i386/syscalls.c 2011-05-19 00:06:34.000000000 -0400
7443 +++ linux-2.6.39.1/arch/um/sys-i386/syscalls.c 2011-05-22 19:36:30.000000000 -0400
7444 @@ -11,6 +11,21 @@
7445 #include "asm/uaccess.h"
7446 #include "asm/unistd.h"
7447
7448 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
7449 +{
7450 + unsigned long pax_task_size = TASK_SIZE;
7451 +
7452 +#ifdef CONFIG_PAX_SEGMEXEC
7453 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
7454 + pax_task_size = SEGMEXEC_TASK_SIZE;
7455 +#endif
7456 +
7457 + if (len > pax_task_size || addr > pax_task_size - len)
7458 + return -EINVAL;
7459 +
7460 + return 0;
7461 +}
7462 +
7463 /*
7464 * The prototype on i386 is:
7465 *
7466 diff -urNp linux-2.6.39.1/arch/unicore32/kernel/pci.c linux-2.6.39.1/arch/unicore32/kernel/pci.c
7467 --- linux-2.6.39.1/arch/unicore32/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7468 +++ linux-2.6.39.1/arch/unicore32/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7469 @@ -66,7 +66,7 @@ puv3_write_config(struct pci_bus *bus, u
7470 return PCIBIOS_SUCCESSFUL;
7471 }
7472
7473 -struct pci_ops pci_puv3_ops = {
7474 +const struct pci_ops pci_puv3_ops = {
7475 .read = puv3_read_config,
7476 .write = puv3_write_config,
7477 };
7478 diff -urNp linux-2.6.39.1/arch/x86/boot/bitops.h linux-2.6.39.1/arch/x86/boot/bitops.h
7479 --- linux-2.6.39.1/arch/x86/boot/bitops.h 2011-05-19 00:06:34.000000000 -0400
7480 +++ linux-2.6.39.1/arch/x86/boot/bitops.h 2011-05-22 19:36:30.000000000 -0400
7481 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int
7482 u8 v;
7483 const u32 *p = (const u32 *)addr;
7484
7485 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7486 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7487 return v;
7488 }
7489
7490 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int
7491
7492 static inline void set_bit(int nr, void *addr)
7493 {
7494 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7495 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7496 }
7497
7498 #endif /* BOOT_BITOPS_H */
7499 diff -urNp linux-2.6.39.1/arch/x86/boot/boot.h linux-2.6.39.1/arch/x86/boot/boot.h
7500 --- linux-2.6.39.1/arch/x86/boot/boot.h 2011-05-19 00:06:34.000000000 -0400
7501 +++ linux-2.6.39.1/arch/x86/boot/boot.h 2011-05-22 19:36:30.000000000 -0400
7502 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7503 static inline u16 ds(void)
7504 {
7505 u16 seg;
7506 - asm("movw %%ds,%0" : "=rm" (seg));
7507 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7508 return seg;
7509 }
7510
7511 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
7512 static inline int memcmp(const void *s1, const void *s2, size_t len)
7513 {
7514 u8 diff;
7515 - asm("repe; cmpsb; setnz %0"
7516 + asm volatile("repe; cmpsb; setnz %0"
7517 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7518 return diff;
7519 }
7520 diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/head_32.S linux-2.6.39.1/arch/x86/boot/compressed/head_32.S
7521 --- linux-2.6.39.1/arch/x86/boot/compressed/head_32.S 2011-05-19 00:06:34.000000000 -0400
7522 +++ linux-2.6.39.1/arch/x86/boot/compressed/head_32.S 2011-05-22 19:36:30.000000000 -0400
7523 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7524 notl %eax
7525 andl %eax, %ebx
7526 #else
7527 - movl $LOAD_PHYSICAL_ADDR, %ebx
7528 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7529 #endif
7530
7531 /* Target address to relocate to for decompression */
7532 @@ -162,7 +162,7 @@ relocated:
7533 * and where it was actually loaded.
7534 */
7535 movl %ebp, %ebx
7536 - subl $LOAD_PHYSICAL_ADDR, %ebx
7537 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7538 jz 2f /* Nothing to be done if loaded at compiled addr. */
7539 /*
7540 * Process relocations.
7541 @@ -170,8 +170,7 @@ relocated:
7542
7543 1: subl $4, %edi
7544 movl (%edi), %ecx
7545 - testl %ecx, %ecx
7546 - jz 2f
7547 + jecxz 2f
7548 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7549 jmp 1b
7550 2:
7551 diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/head_64.S linux-2.6.39.1/arch/x86/boot/compressed/head_64.S
7552 --- linux-2.6.39.1/arch/x86/boot/compressed/head_64.S 2011-05-19 00:06:34.000000000 -0400
7553 +++ linux-2.6.39.1/arch/x86/boot/compressed/head_64.S 2011-05-22 19:36:30.000000000 -0400
7554 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7555 notl %eax
7556 andl %eax, %ebx
7557 #else
7558 - movl $LOAD_PHYSICAL_ADDR, %ebx
7559 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7560 #endif
7561
7562 /* Target address to relocate to for decompression */
7563 @@ -233,7 +233,7 @@ ENTRY(startup_64)
7564 notq %rax
7565 andq %rax, %rbp
7566 #else
7567 - movq $LOAD_PHYSICAL_ADDR, %rbp
7568 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7569 #endif
7570
7571 /* Target address to relocate to for decompression */
7572 diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/misc.c linux-2.6.39.1/arch/x86/boot/compressed/misc.c
7573 --- linux-2.6.39.1/arch/x86/boot/compressed/misc.c 2011-05-19 00:06:34.000000000 -0400
7574 +++ linux-2.6.39.1/arch/x86/boot/compressed/misc.c 2011-05-22 19:36:30.000000000 -0400
7575 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7576 case PT_LOAD:
7577 #ifdef CONFIG_RELOCATABLE
7578 dest = output;
7579 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7580 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7581 #else
7582 dest = (void *)(phdr->p_paddr);
7583 #endif
7584 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *
7585 error("Destination address too large");
7586 #endif
7587 #ifndef CONFIG_RELOCATABLE
7588 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7589 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7590 error("Wrong destination address");
7591 #endif
7592
7593 diff -urNp linux-2.6.39.1/arch/x86/boot/compressed/relocs.c linux-2.6.39.1/arch/x86/boot/compressed/relocs.c
7594 --- linux-2.6.39.1/arch/x86/boot/compressed/relocs.c 2011-05-19 00:06:34.000000000 -0400
7595 +++ linux-2.6.39.1/arch/x86/boot/compressed/relocs.c 2011-05-22 19:36:30.000000000 -0400
7596 @@ -13,8 +13,11 @@
7597
7598 static void die(char *fmt, ...);
7599
7600 +#include "../../../../include/generated/autoconf.h"
7601 +
7602 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7603 static Elf32_Ehdr ehdr;
7604 +static Elf32_Phdr *phdr;
7605 static unsigned long reloc_count, reloc_idx;
7606 static unsigned long *relocs;
7607
7608 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7609 }
7610 }
7611
7612 +static void read_phdrs(FILE *fp)
7613 +{
7614 + unsigned int i;
7615 +
7616 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7617 + if (!phdr) {
7618 + die("Unable to allocate %d program headers\n",
7619 + ehdr.e_phnum);
7620 + }
7621 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7622 + die("Seek to %d failed: %s\n",
7623 + ehdr.e_phoff, strerror(errno));
7624 + }
7625 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7626 + die("Cannot read ELF program headers: %s\n",
7627 + strerror(errno));
7628 + }
7629 + for(i = 0; i < ehdr.e_phnum; i++) {
7630 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7631 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7632 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7633 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7634 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7635 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7636 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7637 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7638 + }
7639 +
7640 +}
7641 +
7642 static void read_shdrs(FILE *fp)
7643 {
7644 - int i;
7645 + unsigned int i;
7646 Elf32_Shdr shdr;
7647
7648 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7649 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7650
7651 static void read_strtabs(FILE *fp)
7652 {
7653 - int i;
7654 + unsigned int i;
7655 for (i = 0; i < ehdr.e_shnum; i++) {
7656 struct section *sec = &secs[i];
7657 if (sec->shdr.sh_type != SHT_STRTAB) {
7658 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7659
7660 static void read_symtabs(FILE *fp)
7661 {
7662 - int i,j;
7663 + unsigned int i,j;
7664 for (i = 0; i < ehdr.e_shnum; i++) {
7665 struct section *sec = &secs[i];
7666 if (sec->shdr.sh_type != SHT_SYMTAB) {
7667 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7668
7669 static void read_relocs(FILE *fp)
7670 {
7671 - int i,j;
7672 + unsigned int i,j;
7673 + uint32_t base;
7674 +
7675 for (i = 0; i < ehdr.e_shnum; i++) {
7676 struct section *sec = &secs[i];
7677 if (sec->shdr.sh_type != SHT_REL) {
7678 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7679 die("Cannot read symbol table: %s\n",
7680 strerror(errno));
7681 }
7682 + base = 0;
7683 + for (j = 0; j < ehdr.e_phnum; j++) {
7684 + if (phdr[j].p_type != PT_LOAD )
7685 + continue;
7686 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
7687 + continue;
7688 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7689 + break;
7690 + }
7691 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7692 Elf32_Rel *rel = &sec->reltab[j];
7693 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7694 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7695 rel->r_info = elf32_to_cpu(rel->r_info);
7696 }
7697 }
7698 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7699
7700 static void print_absolute_symbols(void)
7701 {
7702 - int i;
7703 + unsigned int i;
7704 printf("Absolute symbols\n");
7705 printf(" Num: Value Size Type Bind Visibility Name\n");
7706 for (i = 0; i < ehdr.e_shnum; i++) {
7707 struct section *sec = &secs[i];
7708 char *sym_strtab;
7709 Elf32_Sym *sh_symtab;
7710 - int j;
7711 + unsigned int j;
7712
7713 if (sec->shdr.sh_type != SHT_SYMTAB) {
7714 continue;
7715 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7716
7717 static void print_absolute_relocs(void)
7718 {
7719 - int i, printed = 0;
7720 + unsigned int i, printed = 0;
7721
7722 for (i = 0; i < ehdr.e_shnum; i++) {
7723 struct section *sec = &secs[i];
7724 struct section *sec_applies, *sec_symtab;
7725 char *sym_strtab;
7726 Elf32_Sym *sh_symtab;
7727 - int j;
7728 + unsigned int j;
7729 if (sec->shdr.sh_type != SHT_REL) {
7730 continue;
7731 }
7732 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7733
7734 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7735 {
7736 - int i;
7737 + unsigned int i;
7738 /* Walk through the relocations */
7739 for (i = 0; i < ehdr.e_shnum; i++) {
7740 char *sym_strtab;
7741 Elf32_Sym *sh_symtab;
7742 struct section *sec_applies, *sec_symtab;
7743 - int j;
7744 + unsigned int j;
7745 struct section *sec = &secs[i];
7746
7747 if (sec->shdr.sh_type != SHT_REL) {
7748 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
7749 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7750 continue;
7751 }
7752 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7753 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7754 + continue;
7755 +
7756 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7757 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7758 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7759 + continue;
7760 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7761 + continue;
7762 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7763 + continue;
7764 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7765 + continue;
7766 +#endif
7767 +
7768 switch (r_type) {
7769 case R_386_NONE:
7770 case R_386_PC32:
7771 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
7772
7773 static void emit_relocs(int as_text)
7774 {
7775 - int i;
7776 + unsigned int i;
7777 /* Count how many relocations I have and allocate space for them. */
7778 reloc_count = 0;
7779 walk_relocs(count_reloc);
7780 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7781 fname, strerror(errno));
7782 }
7783 read_ehdr(fp);
7784 + read_phdrs(fp);
7785 read_shdrs(fp);
7786 read_strtabs(fp);
7787 read_symtabs(fp);
7788 diff -urNp linux-2.6.39.1/arch/x86/boot/cpucheck.c linux-2.6.39.1/arch/x86/boot/cpucheck.c
7789 --- linux-2.6.39.1/arch/x86/boot/cpucheck.c 2011-05-19 00:06:34.000000000 -0400
7790 +++ linux-2.6.39.1/arch/x86/boot/cpucheck.c 2011-05-22 19:36:30.000000000 -0400
7791 @@ -74,7 +74,7 @@ static int has_fpu(void)
7792 u16 fcw = -1, fsw = -1;
7793 u32 cr0;
7794
7795 - asm("movl %%cr0,%0" : "=r" (cr0));
7796 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7797 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7798 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7799 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7800 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7801 {
7802 u32 f0, f1;
7803
7804 - asm("pushfl ; "
7805 + asm volatile("pushfl ; "
7806 "pushfl ; "
7807 "popl %0 ; "
7808 "movl %0,%1 ; "
7809 @@ -115,7 +115,7 @@ static void get_flags(void)
7810 set_bit(X86_FEATURE_FPU, cpu.flags);
7811
7812 if (has_eflag(X86_EFLAGS_ID)) {
7813 - asm("cpuid"
7814 + asm volatile("cpuid"
7815 : "=a" (max_intel_level),
7816 "=b" (cpu_vendor[0]),
7817 "=d" (cpu_vendor[1]),
7818 @@ -124,7 +124,7 @@ static void get_flags(void)
7819
7820 if (max_intel_level >= 0x00000001 &&
7821 max_intel_level <= 0x0000ffff) {
7822 - asm("cpuid"
7823 + asm volatile("cpuid"
7824 : "=a" (tfms),
7825 "=c" (cpu.flags[4]),
7826 "=d" (cpu.flags[0])
7827 @@ -136,7 +136,7 @@ static void get_flags(void)
7828 cpu.model += ((tfms >> 16) & 0xf) << 4;
7829 }
7830
7831 - asm("cpuid"
7832 + asm volatile("cpuid"
7833 : "=a" (max_amd_level)
7834 : "a" (0x80000000)
7835 : "ebx", "ecx", "edx");
7836 @@ -144,7 +144,7 @@ static void get_flags(void)
7837 if (max_amd_level >= 0x80000001 &&
7838 max_amd_level <= 0x8000ffff) {
7839 u32 eax = 0x80000001;
7840 - asm("cpuid"
7841 + asm volatile("cpuid"
7842 : "+a" (eax),
7843 "=c" (cpu.flags[6]),
7844 "=d" (cpu.flags[1])
7845 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7846 u32 ecx = MSR_K7_HWCR;
7847 u32 eax, edx;
7848
7849 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7850 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7851 eax &= ~(1 << 15);
7852 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7853 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7854
7855 get_flags(); /* Make sure it really did something */
7856 err = check_flags();
7857 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7858 u32 ecx = MSR_VIA_FCR;
7859 u32 eax, edx;
7860
7861 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7862 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7863 eax |= (1<<1)|(1<<7);
7864 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7865 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7866
7867 set_bit(X86_FEATURE_CX8, cpu.flags);
7868 err = check_flags();
7869 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
7870 u32 eax, edx;
7871 u32 level = 1;
7872
7873 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7874 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7875 - asm("cpuid"
7876 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7877 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7878 + asm volatile("cpuid"
7879 : "+a" (level), "=d" (cpu.flags[0])
7880 : : "ecx", "ebx");
7881 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7882 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7883
7884 err = check_flags();
7885 }
7886 diff -urNp linux-2.6.39.1/arch/x86/boot/header.S linux-2.6.39.1/arch/x86/boot/header.S
7887 --- linux-2.6.39.1/arch/x86/boot/header.S 2011-05-19 00:06:34.000000000 -0400
7888 +++ linux-2.6.39.1/arch/x86/boot/header.S 2011-05-22 19:36:30.000000000 -0400
7889 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
7890 # single linked list of
7891 # struct setup_data
7892
7893 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7894 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7895
7896 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7897 #define VO_INIT_SIZE (VO__end - VO__text)
7898 diff -urNp linux-2.6.39.1/arch/x86/boot/memory.c linux-2.6.39.1/arch/x86/boot/memory.c
7899 --- linux-2.6.39.1/arch/x86/boot/memory.c 2011-05-19 00:06:34.000000000 -0400
7900 +++ linux-2.6.39.1/arch/x86/boot/memory.c 2011-05-22 19:36:30.000000000 -0400
7901 @@ -19,7 +19,7 @@
7902
7903 static int detect_memory_e820(void)
7904 {
7905 - int count = 0;
7906 + unsigned int count = 0;
7907 struct biosregs ireg, oreg;
7908 struct e820entry *desc = boot_params.e820_map;
7909 static struct e820entry buf; /* static so it is zeroed */
7910 diff -urNp linux-2.6.39.1/arch/x86/boot/video.c linux-2.6.39.1/arch/x86/boot/video.c
7911 --- linux-2.6.39.1/arch/x86/boot/video.c 2011-05-19 00:06:34.000000000 -0400
7912 +++ linux-2.6.39.1/arch/x86/boot/video.c 2011-05-22 19:36:30.000000000 -0400
7913 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7914 static unsigned int get_entry(void)
7915 {
7916 char entry_buf[4];
7917 - int i, len = 0;
7918 + unsigned int i, len = 0;
7919 int key;
7920 unsigned int v;
7921
7922 diff -urNp linux-2.6.39.1/arch/x86/boot/video-vesa.c linux-2.6.39.1/arch/x86/boot/video-vesa.c
7923 --- linux-2.6.39.1/arch/x86/boot/video-vesa.c 2011-05-19 00:06:34.000000000 -0400
7924 +++ linux-2.6.39.1/arch/x86/boot/video-vesa.c 2011-05-22 19:36:30.000000000 -0400
7925 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7926
7927 boot_params.screen_info.vesapm_seg = oreg.es;
7928 boot_params.screen_info.vesapm_off = oreg.di;
7929 + boot_params.screen_info.vesapm_size = oreg.cx;
7930 }
7931
7932 /*
7933 diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32_aout.c linux-2.6.39.1/arch/x86/ia32/ia32_aout.c
7934 --- linux-2.6.39.1/arch/x86/ia32/ia32_aout.c 2011-05-19 00:06:34.000000000 -0400
7935 +++ linux-2.6.39.1/arch/x86/ia32/ia32_aout.c 2011-05-22 19:41:32.000000000 -0400
7936 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
7937 unsigned long dump_start, dump_size;
7938 struct user32 dump;
7939
7940 + memset(&dump, 0, sizeof(dump));
7941 +
7942 fs = get_fs();
7943 set_fs(KERNEL_DS);
7944 has_dumped = 1;
7945 diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32entry.S linux-2.6.39.1/arch/x86/ia32/ia32entry.S
7946 --- linux-2.6.39.1/arch/x86/ia32/ia32entry.S 2011-05-19 00:06:34.000000000 -0400
7947 +++ linux-2.6.39.1/arch/x86/ia32/ia32entry.S 2011-05-23 17:16:01.000000000 -0400
7948 @@ -13,6 +13,7 @@
7949 #include <asm/thread_info.h>
7950 #include <asm/segment.h>
7951 #include <asm/irqflags.h>
7952 +#include <asm/pgtable.h>
7953 #include <linux/linkage.h>
7954
7955 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7956 @@ -95,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
7957 ENDPROC(native_irq_enable_sysexit)
7958 #endif
7959
7960 + .macro pax_enter_kernel_user
7961 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7962 + call pax_enter_kernel_user
7963 +#endif
7964 + .endm
7965 +
7966 + .macro pax_exit_kernel_user
7967 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7968 + call pax_exit_kernel_user
7969 +#endif
7970 +#ifdef CONFIG_PAX_RANDKSTACK
7971 + pushq %rax
7972 + call pax_randomize_kstack
7973 + popq %rax
7974 +#endif
7975 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7976 + call pax_erase_kstack
7977 +#endif
7978 + .endm
7979 +
7980 + .macro pax_erase_kstack
7981 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7982 + call pax_erase_kstack
7983 +#endif
7984 + .endm
7985 +
7986 /*
7987 * 32bit SYSENTER instruction entry.
7988 *
7989 @@ -121,7 +148,7 @@ ENTRY(ia32_sysenter_target)
7990 CFI_REGISTER rsp,rbp
7991 SWAPGS_UNSAFE_STACK
7992 movq PER_CPU_VAR(kernel_stack), %rsp
7993 - addq $(KERNEL_STACK_OFFSET),%rsp
7994 + pax_enter_kernel_user
7995 /*
7996 * No need to follow this irqs on/off section: the syscall
7997 * disabled irqs, here we enable it straight after entry:
7998 @@ -134,7 +161,8 @@ ENTRY(ia32_sysenter_target)
7999 CFI_REL_OFFSET rsp,0
8000 pushfq_cfi
8001 /*CFI_REL_OFFSET rflags,0*/
8002 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
8003 + GET_THREAD_INFO(%r10)
8004 + movl TI_sysenter_return(%r10), %r10d
8005 CFI_REGISTER rip,r10
8006 pushq_cfi $__USER32_CS
8007 /*CFI_REL_OFFSET cs,0*/
8008 @@ -146,6 +174,12 @@ ENTRY(ia32_sysenter_target)
8009 SAVE_ARGS 0,0,1
8010 /* no need to do an access_ok check here because rbp has been
8011 32bit zero extended */
8012 +
8013 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8014 + mov $PAX_USER_SHADOW_BASE,%r10
8015 + add %r10,%rbp
8016 +#endif
8017 +
8018 1: movl (%rbp),%ebp
8019 .section __ex_table,"a"
8020 .quad 1b,ia32_badarg
8021 @@ -168,6 +202,7 @@ sysenter_dispatch:
8022 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8023 jnz sysexit_audit
8024 sysexit_from_sys_call:
8025 + pax_exit_kernel_user
8026 andl $~TS_COMPAT,TI_status(%r10)
8027 /* clear IF, that popfq doesn't enable interrupts early */
8028 andl $~0x200,EFLAGS-R11(%rsp)
8029 @@ -194,6 +229,9 @@ sysexit_from_sys_call:
8030 movl %eax,%esi /* 2nd arg: syscall number */
8031 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8032 call audit_syscall_entry
8033 +
8034 + pax_erase_kstack
8035 +
8036 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8037 cmpq $(IA32_NR_syscalls-1),%rax
8038 ja ia32_badsys
8039 @@ -246,6 +284,9 @@ sysenter_tracesys:
8040 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8041 movq %rsp,%rdi /* &pt_regs -> arg1 */
8042 call syscall_trace_enter
8043 +
8044 + pax_erase_kstack
8045 +
8046 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8047 RESTORE_REST
8048 cmpq $(IA32_NR_syscalls-1),%rax
8049 @@ -277,19 +318,24 @@ ENDPROC(ia32_sysenter_target)
8050 ENTRY(ia32_cstar_target)
8051 CFI_STARTPROC32 simple
8052 CFI_SIGNAL_FRAME
8053 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8054 + CFI_DEF_CFA rsp,0
8055 CFI_REGISTER rip,rcx
8056 /*CFI_REGISTER rflags,r11*/
8057 SWAPGS_UNSAFE_STACK
8058 movl %esp,%r8d
8059 CFI_REGISTER rsp,r8
8060 movq PER_CPU_VAR(kernel_stack),%rsp
8061 +
8062 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8063 + pax_enter_kernel_user
8064 +#endif
8065 +
8066 /*
8067 * No need to follow this irqs on/off section: the syscall
8068 * disabled irqs and here we enable it straight after entry:
8069 */
8070 ENABLE_INTERRUPTS(CLBR_NONE)
8071 - SAVE_ARGS 8,1,1
8072 + SAVE_ARGS 8*6,1,1
8073 movl %eax,%eax /* zero extension */
8074 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8075 movq %rcx,RIP-ARGOFFSET(%rsp)
8076 @@ -305,6 +351,12 @@ ENTRY(ia32_cstar_target)
8077 /* no need to do an access_ok check here because r8 has been
8078 32bit zero extended */
8079 /* hardware stack frame is complete now */
8080 +
8081 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8082 + mov $PAX_USER_SHADOW_BASE,%r10
8083 + add %r10,%r8
8084 +#endif
8085 +
8086 1: movl (%r8),%r9d
8087 .section __ex_table,"a"
8088 .quad 1b,ia32_badarg
8089 @@ -327,6 +379,7 @@ cstar_dispatch:
8090 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8091 jnz sysretl_audit
8092 sysretl_from_sys_call:
8093 + pax_exit_kernel_user
8094 andl $~TS_COMPAT,TI_status(%r10)
8095 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8096 movl RIP-ARGOFFSET(%rsp),%ecx
8097 @@ -364,6 +417,9 @@ cstar_tracesys:
8098 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8099 movq %rsp,%rdi /* &pt_regs -> arg1 */
8100 call syscall_trace_enter
8101 +
8102 + pax_erase_kstack
8103 +
8104 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8105 RESTORE_REST
8106 xchgl %ebp,%r9d
8107 @@ -409,6 +465,7 @@ ENTRY(ia32_syscall)
8108 CFI_REL_OFFSET rip,RIP-RIP
8109 PARAVIRT_ADJUST_EXCEPTION_FRAME
8110 SWAPGS
8111 + pax_enter_kernel_user
8112 /*
8113 * No need to follow this irqs on/off section: the syscall
8114 * disabled irqs and here we enable it straight after entry:
8115 @@ -441,6 +498,9 @@ ia32_tracesys:
8116 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8117 movq %rsp,%rdi /* &pt_regs -> arg1 */
8118 call syscall_trace_enter
8119 +
8120 + pax_erase_kstack
8121 +
8122 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8123 RESTORE_REST
8124 cmpq $(IA32_NR_syscalls-1),%rax
8125 diff -urNp linux-2.6.39.1/arch/x86/ia32/ia32_signal.c linux-2.6.39.1/arch/x86/ia32/ia32_signal.c
8126 --- linux-2.6.39.1/arch/x86/ia32/ia32_signal.c 2011-05-19 00:06:34.000000000 -0400
8127 +++ linux-2.6.39.1/arch/x86/ia32/ia32_signal.c 2011-05-22 19:36:30.000000000 -0400
8128 @@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
8129 sp -= frame_size;
8130 /* Align the stack pointer according to the i386 ABI,
8131 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8132 - sp = ((sp + 4) & -16ul) - 4;
8133 + sp = ((sp - 12) & -16ul) - 4;
8134 return (void __user *) sp;
8135 }
8136
8137 @@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
8138 * These are actually not used anymore, but left because some
8139 * gdb versions depend on them as a marker.
8140 */
8141 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8142 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8143 } put_user_catch(err);
8144
8145 if (err)
8146 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
8147 0xb8,
8148 __NR_ia32_rt_sigreturn,
8149 0x80cd,
8150 - 0,
8151 + 0
8152 };
8153
8154 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8155 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
8156
8157 if (ka->sa.sa_flags & SA_RESTORER)
8158 restorer = ka->sa.sa_restorer;
8159 + else if (current->mm->context.vdso)
8160 + /* Return stub is in 32bit vsyscall page */
8161 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8162 else
8163 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8164 - rt_sigreturn);
8165 + restorer = &frame->retcode;
8166 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8167
8168 /*
8169 * Not actually used anymore, but left because some gdb
8170 * versions need it.
8171 */
8172 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8173 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8174 } put_user_catch(err);
8175
8176 if (err)
8177 diff -urNp linux-2.6.39.1/arch/x86/include/asm/alternative.h linux-2.6.39.1/arch/x86/include/asm/alternative.h
8178 --- linux-2.6.39.1/arch/x86/include/asm/alternative.h 2011-05-19 00:06:34.000000000 -0400
8179 +++ linux-2.6.39.1/arch/x86/include/asm/alternative.h 2011-05-22 19:36:30.000000000 -0400
8180 @@ -94,7 +94,7 @@ static inline int alternatives_text_rese
8181 ".section .discard,\"aw\",@progbits\n" \
8182 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8183 ".previous\n" \
8184 - ".section .altinstr_replacement, \"ax\"\n" \
8185 + ".section .altinstr_replacement, \"a\"\n" \
8186 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8187 ".previous"
8188
8189 diff -urNp linux-2.6.39.1/arch/x86/include/asm/apm.h linux-2.6.39.1/arch/x86/include/asm/apm.h
8190 --- linux-2.6.39.1/arch/x86/include/asm/apm.h 2011-05-19 00:06:34.000000000 -0400
8191 +++ linux-2.6.39.1/arch/x86/include/asm/apm.h 2011-05-22 19:36:30.000000000 -0400
8192 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
8193 __asm__ __volatile__(APM_DO_ZERO_SEGS
8194 "pushl %%edi\n\t"
8195 "pushl %%ebp\n\t"
8196 - "lcall *%%cs:apm_bios_entry\n\t"
8197 + "lcall *%%ss:apm_bios_entry\n\t"
8198 "setc %%al\n\t"
8199 "popl %%ebp\n\t"
8200 "popl %%edi\n\t"
8201 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
8202 __asm__ __volatile__(APM_DO_ZERO_SEGS
8203 "pushl %%edi\n\t"
8204 "pushl %%ebp\n\t"
8205 - "lcall *%%cs:apm_bios_entry\n\t"
8206 + "lcall *%%ss:apm_bios_entry\n\t"
8207 "setc %%bl\n\t"
8208 "popl %%ebp\n\t"
8209 "popl %%edi\n\t"
8210 diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h
8211 --- linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h 2011-05-19 00:06:34.000000000 -0400
8212 +++ linux-2.6.39.1/arch/x86/include/asm/atomic64_32.h 2011-05-22 19:36:30.000000000 -0400
8213 @@ -12,6 +12,14 @@ typedef struct {
8214 u64 __aligned(8) counter;
8215 } atomic64_t;
8216
8217 +#ifdef CONFIG_PAX_REFCOUNT
8218 +typedef struct {
8219 + u64 __aligned(8) counter;
8220 +} atomic64_unchecked_t;
8221 +#else
8222 +typedef atomic64_t atomic64_unchecked_t;
8223 +#endif
8224 +
8225 #define ATOMIC64_INIT(val) { (val) }
8226
8227 #ifdef CONFIG_X86_CMPXCHG64
8228 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg
8229 }
8230
8231 /**
8232 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
8233 + * @p: pointer to type atomic64_unchecked_t
8234 + * @o: expected value
8235 + * @n: new value
8236 + *
8237 + * Atomically sets @v to @n if it was equal to @o and returns
8238 + * the old value.
8239 + */
8240 +
8241 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
8242 +{
8243 + return cmpxchg64(&v->counter, o, n);
8244 +}
8245 +
8246 +/**
8247 * atomic64_xchg - xchg atomic64 variable
8248 * @v: pointer to type atomic64_t
8249 * @n: value to assign
8250 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64
8251 }
8252
8253 /**
8254 + * atomic64_set_unchecked - set atomic64 variable
8255 + * @v: pointer to type atomic64_unchecked_t
8256 + * @n: value to assign
8257 + *
8258 + * Atomically sets the value of @v to @n.
8259 + */
8260 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
8261 +{
8262 + unsigned high = (unsigned)(i >> 32);
8263 + unsigned low = (unsigned)i;
8264 + asm volatile(ATOMIC64_ALTERNATIVE(set)
8265 + : "+b" (low), "+c" (high)
8266 + : "S" (v)
8267 + : "eax", "edx", "memory"
8268 + );
8269 +}
8270 +
8271 +/**
8272 * atomic64_read - read atomic64 variable
8273 * @v: pointer to type atomic64_t
8274 *
8275 @@ -93,6 +134,22 @@ static inline long long atomic64_read(at
8276 }
8277
8278 /**
8279 + * atomic64_read_unchecked - read atomic64 variable
8280 + * @v: pointer to type atomic64_unchecked_t
8281 + *
8282 + * Atomically reads the value of @v and returns it.
8283 + */
8284 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
8285 +{
8286 + long long r;
8287 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
8288 + : "=A" (r), "+c" (v)
8289 + : : "memory"
8290 + );
8291 + return r;
8292 + }
8293 +
8294 +/**
8295 * atomic64_add_return - add and return
8296 * @i: integer value to add
8297 * @v: pointer to type atomic64_t
8298 @@ -108,6 +165,22 @@ static inline long long atomic64_add_ret
8299 return i;
8300 }
8301
8302 +/**
8303 + * atomic64_add_return_unchecked - add and return
8304 + * @i: integer value to add
8305 + * @v: pointer to type atomic64_unchecked_t
8306 + *
8307 + * Atomically adds @i to @v and returns @i + *@v
8308 + */
8309 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
8310 +{
8311 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
8312 + : "+A" (i), "+c" (v)
8313 + : : "memory"
8314 + );
8315 + return i;
8316 +}
8317 +
8318 /*
8319 * Other variants with different arithmetic operators:
8320 */
8321 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_ret
8322 return a;
8323 }
8324
8325 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8326 +{
8327 + long long a;
8328 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
8329 + : "=A" (a)
8330 + : "S" (v)
8331 + : "memory", "ecx"
8332 + );
8333 + return a;
8334 +}
8335 +
8336 static inline long long atomic64_dec_return(atomic64_t *v)
8337 {
8338 long long a;
8339 @@ -159,6 +243,22 @@ static inline long long atomic64_add(lon
8340 }
8341
8342 /**
8343 + * atomic64_add_unchecked - add integer to atomic64 variable
8344 + * @i: integer value to add
8345 + * @v: pointer to type atomic64_unchecked_t
8346 + *
8347 + * Atomically adds @i to @v.
8348 + */
8349 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8350 +{
8351 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8352 + : "+A" (i), "+c" (v)
8353 + : : "memory"
8354 + );
8355 + return i;
8356 +}
8357 +
8358 +/**
8359 * atomic64_sub - subtract the atomic64 variable
8360 * @i: integer value to subtract
8361 * @v: pointer to type atomic64_t
8362 diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h
8363 --- linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h 2011-05-19 00:06:34.000000000 -0400
8364 +++ linux-2.6.39.1/arch/x86/include/asm/atomic64_64.h 2011-05-22 19:36:30.000000000 -0400
8365 @@ -18,7 +18,19 @@
8366 */
8367 static inline long atomic64_read(const atomic64_t *v)
8368 {
8369 - return (*(volatile long *)&(v)->counter);
8370 + return (*(volatile const long *)&(v)->counter);
8371 +}
8372 +
8373 +/**
8374 + * atomic64_read_unchecked - read atomic64 variable
8375 + * @v: pointer of type atomic64_unchecked_t
8376 + *
8377 + * Atomically reads the value of @v.
8378 + * Doesn't imply a read memory barrier.
8379 + */
8380 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8381 +{
8382 + return (*(volatile const long *)&(v)->counter);
8383 }
8384
8385 /**
8386 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
8387 }
8388
8389 /**
8390 + * atomic64_set_unchecked - set atomic64 variable
8391 + * @v: pointer to type atomic64_unchecked_t
8392 + * @i: required value
8393 + *
8394 + * Atomically sets the value of @v to @i.
8395 + */
8396 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8397 +{
8398 + v->counter = i;
8399 +}
8400 +
8401 +/**
8402 * atomic64_add - add integer to atomic64 variable
8403 * @i: integer value to add
8404 * @v: pointer to type atomic64_t
8405 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
8406 */
8407 static inline void atomic64_add(long i, atomic64_t *v)
8408 {
8409 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
8410 +
8411 +#ifdef CONFIG_PAX_REFCOUNT
8412 + "jno 0f\n"
8413 + LOCK_PREFIX "subq %1,%0\n"
8414 + "int $4\n0:\n"
8415 + _ASM_EXTABLE(0b, 0b)
8416 +#endif
8417 +
8418 + : "=m" (v->counter)
8419 + : "er" (i), "m" (v->counter));
8420 +}
8421 +
8422 +/**
8423 + * atomic64_add_unchecked - add integer to atomic64 variable
8424 + * @i: integer value to add
8425 + * @v: pointer to type atomic64_unchecked_t
8426 + *
8427 + * Atomically adds @i to @v.
8428 + */
8429 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8430 +{
8431 asm volatile(LOCK_PREFIX "addq %1,%0"
8432 : "=m" (v->counter)
8433 : "er" (i), "m" (v->counter));
8434 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
8435 */
8436 static inline void atomic64_sub(long i, atomic64_t *v)
8437 {
8438 - asm volatile(LOCK_PREFIX "subq %1,%0"
8439 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8440 +
8441 +#ifdef CONFIG_PAX_REFCOUNT
8442 + "jno 0f\n"
8443 + LOCK_PREFIX "addq %1,%0\n"
8444 + "int $4\n0:\n"
8445 + _ASM_EXTABLE(0b, 0b)
8446 +#endif
8447 +
8448 + : "=m" (v->counter)
8449 + : "er" (i), "m" (v->counter));
8450 +}
8451 +
8452 +/**
8453 + * atomic64_sub_unchecked - subtract the atomic64 variable
8454 + * @i: integer value to subtract
8455 + * @v: pointer to type atomic64_unchecked_t
8456 + *
8457 + * Atomically subtracts @i from @v.
8458 + */
8459 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8460 +{
8461 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8462 : "=m" (v->counter)
8463 : "er" (i), "m" (v->counter));
8464 }
8465 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
8466 {
8467 unsigned char c;
8468
8469 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8470 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
8471 +
8472 +#ifdef CONFIG_PAX_REFCOUNT
8473 + "jno 0f\n"
8474 + LOCK_PREFIX "addq %2,%0\n"
8475 + "int $4\n0:\n"
8476 + _ASM_EXTABLE(0b, 0b)
8477 +#endif
8478 +
8479 + "sete %1\n"
8480 : "=m" (v->counter), "=qm" (c)
8481 : "er" (i), "m" (v->counter) : "memory");
8482 return c;
8483 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
8484 */
8485 static inline void atomic64_inc(atomic64_t *v)
8486 {
8487 + asm volatile(LOCK_PREFIX "incq %0\n"
8488 +
8489 +#ifdef CONFIG_PAX_REFCOUNT
8490 + "jno 0f\n"
8491 + LOCK_PREFIX "decq %0\n"
8492 + "int $4\n0:\n"
8493 + _ASM_EXTABLE(0b, 0b)
8494 +#endif
8495 +
8496 + : "=m" (v->counter)
8497 + : "m" (v->counter));
8498 +}
8499 +
8500 +/**
8501 + * atomic64_inc_unchecked - increment atomic64 variable
8502 + * @v: pointer to type atomic64_unchecked_t
8503 + *
8504 + * Atomically increments @v by 1.
8505 + */
8506 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8507 +{
8508 asm volatile(LOCK_PREFIX "incq %0"
8509 : "=m" (v->counter)
8510 : "m" (v->counter));
8511 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
8512 */
8513 static inline void atomic64_dec(atomic64_t *v)
8514 {
8515 - asm volatile(LOCK_PREFIX "decq %0"
8516 + asm volatile(LOCK_PREFIX "decq %0\n"
8517 +
8518 +#ifdef CONFIG_PAX_REFCOUNT
8519 + "jno 0f\n"
8520 + LOCK_PREFIX "incq %0\n"
8521 + "int $4\n0:\n"
8522 + _ASM_EXTABLE(0b, 0b)
8523 +#endif
8524 +
8525 + : "=m" (v->counter)
8526 + : "m" (v->counter));
8527 +}
8528 +
8529 +/**
8530 + * atomic64_dec_unchecked - decrement atomic64 variable
8531 + * @v: pointer to type atomic64_t
8532 + *
8533 + * Atomically decrements @v by 1.
8534 + */
8535 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8536 +{
8537 + asm volatile(LOCK_PREFIX "decq %0\n"
8538 : "=m" (v->counter)
8539 : "m" (v->counter));
8540 }
8541 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
8542 {
8543 unsigned char c;
8544
8545 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
8546 + asm volatile(LOCK_PREFIX "decq %0\n"
8547 +
8548 +#ifdef CONFIG_PAX_REFCOUNT
8549 + "jno 0f\n"
8550 + LOCK_PREFIX "incq %0\n"
8551 + "int $4\n0:\n"
8552 + _ASM_EXTABLE(0b, 0b)
8553 +#endif
8554 +
8555 + "sete %1\n"
8556 : "=m" (v->counter), "=qm" (c)
8557 : "m" (v->counter) : "memory");
8558 return c != 0;
8559 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
8560 {
8561 unsigned char c;
8562
8563 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
8564 + asm volatile(LOCK_PREFIX "incq %0\n"
8565 +
8566 +#ifdef CONFIG_PAX_REFCOUNT
8567 + "jno 0f\n"
8568 + LOCK_PREFIX "decq %0\n"
8569 + "int $4\n0:\n"
8570 + _ASM_EXTABLE(0b, 0b)
8571 +#endif
8572 +
8573 + "sete %1\n"
8574 : "=m" (v->counter), "=qm" (c)
8575 : "m" (v->counter) : "memory");
8576 return c != 0;
8577 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
8578 {
8579 unsigned char c;
8580
8581 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8582 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
8583 +
8584 +#ifdef CONFIG_PAX_REFCOUNT
8585 + "jno 0f\n"
8586 + LOCK_PREFIX "subq %2,%0\n"
8587 + "int $4\n0:\n"
8588 + _ASM_EXTABLE(0b, 0b)
8589 +#endif
8590 +
8591 + "sets %1\n"
8592 : "=m" (v->counter), "=qm" (c)
8593 : "er" (i), "m" (v->counter) : "memory");
8594 return c;
8595 @@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
8596 static inline long atomic64_add_return(long i, atomic64_t *v)
8597 {
8598 long __i = i;
8599 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
8600 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
8601 +
8602 +#ifdef CONFIG_PAX_REFCOUNT
8603 + "jno 0f\n"
8604 + "movq %0, %1\n"
8605 + "int $4\n0:\n"
8606 + _ASM_EXTABLE(0b, 0b)
8607 +#endif
8608 +
8609 + : "+r" (i), "+m" (v->counter)
8610 + : : "memory");
8611 + return i + __i;
8612 +}
8613 +
8614 +/**
8615 + * atomic64_add_return_unchecked - add and return
8616 + * @i: integer value to add
8617 + * @v: pointer to type atomic64_unchecked_t
8618 + *
8619 + * Atomically adds @i to @v and returns @i + @v
8620 + */
8621 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8622 +{
8623 + long __i = i;
8624 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
8625 : "+r" (i), "+m" (v->counter)
8626 : : "memory");
8627 return i + __i;
8628 @@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
8629 }
8630
8631 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8632 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8633 +{
8634 + return atomic64_add_return_unchecked(1, v);
8635 +}
8636 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8637
8638 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8639 @@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atom
8640 return cmpxchg(&v->counter, old, new);
8641 }
8642
8643 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8644 +{
8645 + return cmpxchg(&v->counter, old, new);
8646 +}
8647 +
8648 static inline long atomic64_xchg(atomic64_t *v, long new)
8649 {
8650 return xchg(&v->counter, new);
8651 @@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic6
8652 */
8653 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8654 {
8655 - long c, old;
8656 + long c, old, new;
8657 c = atomic64_read(v);
8658 for (;;) {
8659 - if (unlikely(c == (u)))
8660 + if (unlikely(c == u))
8661 break;
8662 - old = atomic64_cmpxchg((v), c, c + (a));
8663 +
8664 + asm volatile("add %2,%0\n"
8665 +
8666 +#ifdef CONFIG_PAX_REFCOUNT
8667 + "jno 0f\n"
8668 + "sub %2,%0\n"
8669 + "int $4\n0:\n"
8670 + _ASM_EXTABLE(0b, 0b)
8671 +#endif
8672 +
8673 + : "=r" (new)
8674 + : "0" (c), "ir" (a));
8675 +
8676 + old = atomic64_cmpxchg(v, c, new);
8677 if (likely(old == c))
8678 break;
8679 c = old;
8680 }
8681 - return c != (u);
8682 + return c != u;
8683 }
8684
8685 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8686 diff -urNp linux-2.6.39.1/arch/x86/include/asm/atomic.h linux-2.6.39.1/arch/x86/include/asm/atomic.h
8687 --- linux-2.6.39.1/arch/x86/include/asm/atomic.h 2011-05-19 00:06:34.000000000 -0400
8688 +++ linux-2.6.39.1/arch/x86/include/asm/atomic.h 2011-05-22 19:36:30.000000000 -0400
8689 @@ -22,7 +22,18 @@
8690 */
8691 static inline int atomic_read(const atomic_t *v)
8692 {
8693 - return (*(volatile int *)&(v)->counter);
8694 + return (*(volatile const int *)&(v)->counter);
8695 +}
8696 +
8697 +/**
8698 + * atomic_read_unchecked - read atomic variable
8699 + * @v: pointer of type atomic_unchecked_t
8700 + *
8701 + * Atomically reads the value of @v.
8702 + */
8703 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8704 +{
8705 + return (*(volatile const int *)&(v)->counter);
8706 }
8707
8708 /**
8709 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
8710 }
8711
8712 /**
8713 + * atomic_set_unchecked - set atomic variable
8714 + * @v: pointer of type atomic_unchecked_t
8715 + * @i: required value
8716 + *
8717 + * Atomically sets the value of @v to @i.
8718 + */
8719 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8720 +{
8721 + v->counter = i;
8722 +}
8723 +
8724 +/**
8725 * atomic_add - add integer to atomic variable
8726 * @i: integer value to add
8727 * @v: pointer of type atomic_t
8728 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
8729 */
8730 static inline void atomic_add(int i, atomic_t *v)
8731 {
8732 - asm volatile(LOCK_PREFIX "addl %1,%0"
8733 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8734 +
8735 +#ifdef CONFIG_PAX_REFCOUNT
8736 + "jno 0f\n"
8737 + LOCK_PREFIX "subl %1,%0\n"
8738 + "int $4\n0:\n"
8739 + _ASM_EXTABLE(0b, 0b)
8740 +#endif
8741 +
8742 + : "+m" (v->counter)
8743 + : "ir" (i));
8744 +}
8745 +
8746 +/**
8747 + * atomic_add_unchecked - add integer to atomic variable
8748 + * @i: integer value to add
8749 + * @v: pointer of type atomic_unchecked_t
8750 + *
8751 + * Atomically adds @i to @v.
8752 + */
8753 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8754 +{
8755 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8756 : "+m" (v->counter)
8757 : "ir" (i));
8758 }
8759 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
8760 */
8761 static inline void atomic_sub(int i, atomic_t *v)
8762 {
8763 - asm volatile(LOCK_PREFIX "subl %1,%0"
8764 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8765 +
8766 +#ifdef CONFIG_PAX_REFCOUNT
8767 + "jno 0f\n"
8768 + LOCK_PREFIX "addl %1,%0\n"
8769 + "int $4\n0:\n"
8770 + _ASM_EXTABLE(0b, 0b)
8771 +#endif
8772 +
8773 + : "+m" (v->counter)
8774 + : "ir" (i));
8775 +}
8776 +
8777 +/**
8778 + * atomic_sub_unchecked - subtract integer from atomic variable
8779 + * @i: integer value to subtract
8780 + * @v: pointer of type atomic_unchecked_t
8781 + *
8782 + * Atomically subtracts @i from @v.
8783 + */
8784 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8785 +{
8786 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8787 : "+m" (v->counter)
8788 : "ir" (i));
8789 }
8790 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
8791 {
8792 unsigned char c;
8793
8794 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8795 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8796 +
8797 +#ifdef CONFIG_PAX_REFCOUNT
8798 + "jno 0f\n"
8799 + LOCK_PREFIX "addl %2,%0\n"
8800 + "int $4\n0:\n"
8801 + _ASM_EXTABLE(0b, 0b)
8802 +#endif
8803 +
8804 + "sete %1\n"
8805 : "+m" (v->counter), "=qm" (c)
8806 : "ir" (i) : "memory");
8807 return c;
8808 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
8809 */
8810 static inline void atomic_inc(atomic_t *v)
8811 {
8812 - asm volatile(LOCK_PREFIX "incl %0"
8813 + asm volatile(LOCK_PREFIX "incl %0\n"
8814 +
8815 +#ifdef CONFIG_PAX_REFCOUNT
8816 + "jno 0f\n"
8817 + LOCK_PREFIX "decl %0\n"
8818 + "int $4\n0:\n"
8819 + _ASM_EXTABLE(0b, 0b)
8820 +#endif
8821 +
8822 + : "+m" (v->counter));
8823 +}
8824 +
8825 +/**
8826 + * atomic_inc_unchecked - increment atomic variable
8827 + * @v: pointer of type atomic_unchecked_t
8828 + *
8829 + * Atomically increments @v by 1.
8830 + */
8831 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8832 +{
8833 + asm volatile(LOCK_PREFIX "incl %0\n"
8834 : "+m" (v->counter));
8835 }
8836
8837 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
8838 */
8839 static inline void atomic_dec(atomic_t *v)
8840 {
8841 - asm volatile(LOCK_PREFIX "decl %0"
8842 + asm volatile(LOCK_PREFIX "decl %0\n"
8843 +
8844 +#ifdef CONFIG_PAX_REFCOUNT
8845 + "jno 0f\n"
8846 + LOCK_PREFIX "incl %0\n"
8847 + "int $4\n0:\n"
8848 + _ASM_EXTABLE(0b, 0b)
8849 +#endif
8850 +
8851 + : "+m" (v->counter));
8852 +}
8853 +
8854 +/**
8855 + * atomic_dec_unchecked - decrement atomic variable
8856 + * @v: pointer of type atomic_unchecked_t
8857 + *
8858 + * Atomically decrements @v by 1.
8859 + */
8860 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8861 +{
8862 + asm volatile(LOCK_PREFIX "decl %0\n"
8863 : "+m" (v->counter));
8864 }
8865
8866 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
8867 {
8868 unsigned char c;
8869
8870 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8871 + asm volatile(LOCK_PREFIX "decl %0\n"
8872 +
8873 +#ifdef CONFIG_PAX_REFCOUNT
8874 + "jno 0f\n"
8875 + LOCK_PREFIX "incl %0\n"
8876 + "int $4\n0:\n"
8877 + _ASM_EXTABLE(0b, 0b)
8878 +#endif
8879 +
8880 + "sete %1\n"
8881 : "+m" (v->counter), "=qm" (c)
8882 : : "memory");
8883 return c != 0;
8884 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(at
8885 {
8886 unsigned char c;
8887
8888 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8889 + asm volatile(LOCK_PREFIX "incl %0\n"
8890 +
8891 +#ifdef CONFIG_PAX_REFCOUNT
8892 + "jno 0f\n"
8893 + LOCK_PREFIX "decl %0\n"
8894 + "int $4\n0:\n"
8895 + _ASM_EXTABLE(0b, 0b)
8896 +#endif
8897 +
8898 + "sete %1\n"
8899 + : "+m" (v->counter), "=qm" (c)
8900 + : : "memory");
8901 + return c != 0;
8902 +}
8903 +
8904 +/**
8905 + * atomic_inc_and_test_unchecked - increment and test
8906 + * @v: pointer of type atomic_unchecked_t
8907 + *
8908 + * Atomically increments @v by 1
8909 + * and returns true if the result is zero, or false for all
8910 + * other cases.
8911 + */
8912 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8913 +{
8914 + unsigned char c;
8915 +
8916 + asm volatile(LOCK_PREFIX "incl %0\n"
8917 + "sete %1\n"
8918 : "+m" (v->counter), "=qm" (c)
8919 : : "memory");
8920 return c != 0;
8921 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(in
8922 {
8923 unsigned char c;
8924
8925 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8926 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8927 +
8928 +#ifdef CONFIG_PAX_REFCOUNT
8929 + "jno 0f\n"
8930 + LOCK_PREFIX "subl %2,%0\n"
8931 + "int $4\n0:\n"
8932 + _ASM_EXTABLE(0b, 0b)
8933 +#endif
8934 +
8935 + "sets %1\n"
8936 : "+m" (v->counter), "=qm" (c)
8937 : "ir" (i) : "memory");
8938 return c;
8939 @@ -180,6 +342,46 @@ static inline int atomic_add_return(int
8940 #endif
8941 /* Modern 486+ processor */
8942 __i = i;
8943 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8944 +
8945 +#ifdef CONFIG_PAX_REFCOUNT
8946 + "jno 0f\n"
8947 + "movl %0, %1\n"
8948 + "int $4\n0:\n"
8949 + _ASM_EXTABLE(0b, 0b)
8950 +#endif
8951 +
8952 + : "+r" (i), "+m" (v->counter)
8953 + : : "memory");
8954 + return i + __i;
8955 +
8956 +#ifdef CONFIG_M386
8957 +no_xadd: /* Legacy 386 processor */
8958 + local_irq_save(flags);
8959 + __i = atomic_read(v);
8960 + atomic_set(v, i + __i);
8961 + local_irq_restore(flags);
8962 + return i + __i;
8963 +#endif
8964 +}
8965 +
8966 +/**
8967 + * atomic_add_return_unchecked - add integer and return
8968 + * @v: pointer of type atomic_unchecked_t
8969 + * @i: integer value to add
8970 + *
8971 + * Atomically adds @i to @v and returns @i + @v
8972 + */
8973 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8974 +{
8975 + int __i;
8976 +#ifdef CONFIG_M386
8977 + unsigned long flags;
8978 + if (unlikely(boot_cpu_data.x86 <= 3))
8979 + goto no_xadd;
8980 +#endif
8981 + /* Modern 486+ processor */
8982 + __i = i;
8983 asm volatile(LOCK_PREFIX "xaddl %0, %1"
8984 : "+r" (i), "+m" (v->counter)
8985 : : "memory");
8986 @@ -208,6 +410,10 @@ static inline int atomic_sub_return(int
8987 }
8988
8989 #define atomic_inc_return(v) (atomic_add_return(1, v))
8990 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8991 +{
8992 + return atomic_add_return_unchecked(1, v);
8993 +}
8994 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8995
8996 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8997 @@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_
8998 return cmpxchg(&v->counter, old, new);
8999 }
9000
9001 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9002 +{
9003 + return cmpxchg(&v->counter, old, new);
9004 +}
9005 +
9006 static inline int atomic_xchg(atomic_t *v, int new)
9007 {
9008 return xchg(&v->counter, new);
9009 }
9010
9011 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9012 +{
9013 + return xchg(&v->counter, new);
9014 +}
9015 +
9016 /**
9017 * atomic_add_unless - add unless the number is already a given value
9018 * @v: pointer of type atomic_t
9019 @@ -231,21 +447,77 @@ static inline int atomic_xchg(atomic_t *
9020 */
9021 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9022 {
9023 - int c, old;
9024 + int c, old, new;
9025 c = atomic_read(v);
9026 for (;;) {
9027 - if (unlikely(c == (u)))
9028 + if (unlikely(c == u))
9029 break;
9030 - old = atomic_cmpxchg((v), c, c + (a));
9031 +
9032 + asm volatile("addl %2,%0\n"
9033 +
9034 +#ifdef CONFIG_PAX_REFCOUNT
9035 + "jno 0f\n"
9036 + "subl %2,%0\n"
9037 + "int $4\n0:\n"
9038 + _ASM_EXTABLE(0b, 0b)
9039 +#endif
9040 +
9041 + : "=r" (new)
9042 + : "0" (c), "ir" (a));
9043 +
9044 + old = atomic_cmpxchg(v, c, new);
9045 if (likely(old == c))
9046 break;
9047 c = old;
9048 }
9049 - return c != (u);
9050 + return c != u;
9051 }
9052
9053 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9054
9055 +/**
9056 + * atomic_inc_not_zero_hint - increment if not null
9057 + * @v: pointer of type atomic_t
9058 + * @hint: probable value of the atomic before the increment
9059 + *
9060 + * This version of atomic_inc_not_zero() gives a hint of probable
9061 + * value of the atomic. This helps processor to not read the memory
9062 + * before doing the atomic read/modify/write cycle, lowering
9063 + * number of bus transactions on some arches.
9064 + *
9065 + * Returns: 0 if increment was not done, 1 otherwise.
9066 + */
9067 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9068 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9069 +{
9070 + int val, c = hint, new;
9071 +
9072 + /* sanity test, should be removed by compiler if hint is a constant */
9073 + if (!hint)
9074 + return atomic_inc_not_zero(v);
9075 +
9076 + do {
9077 + asm volatile("incl %0\n"
9078 +
9079 +#ifdef CONFIG_PAX_REFCOUNT
9080 + "jno 0f\n"
9081 + "decl %0\n"
9082 + "int $4\n0:\n"
9083 + _ASM_EXTABLE(0b, 0b)
9084 +#endif
9085 +
9086 + : "=r" (new)
9087 + : "0" (c));
9088 +
9089 + val = atomic_cmpxchg(v, c, new);
9090 + if (val == c)
9091 + return 1;
9092 + c = val;
9093 + } while (c);
9094 +
9095 + return 0;
9096 +}
9097 +
9098 /*
9099 * atomic_dec_if_positive - decrement by 1 if old value positive
9100 * @v: pointer of type atomic_t
9101 diff -urNp linux-2.6.39.1/arch/x86/include/asm/bitops.h linux-2.6.39.1/arch/x86/include/asm/bitops.h
9102 --- linux-2.6.39.1/arch/x86/include/asm/bitops.h 2011-05-19 00:06:34.000000000 -0400
9103 +++ linux-2.6.39.1/arch/x86/include/asm/bitops.h 2011-05-22 19:36:30.000000000 -0400
9104 @@ -38,7 +38,7 @@
9105 * a mask operation on a byte.
9106 */
9107 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9108 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9109 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9110 #define CONST_MASK(nr) (1 << ((nr) & 7))
9111
9112 /**
9113 diff -urNp linux-2.6.39.1/arch/x86/include/asm/boot.h linux-2.6.39.1/arch/x86/include/asm/boot.h
9114 --- linux-2.6.39.1/arch/x86/include/asm/boot.h 2011-05-19 00:06:34.000000000 -0400
9115 +++ linux-2.6.39.1/arch/x86/include/asm/boot.h 2011-05-22 19:36:30.000000000 -0400
9116 @@ -11,10 +11,15 @@
9117 #include <asm/pgtable_types.h>
9118
9119 /* Physical address where kernel should be loaded. */
9120 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9121 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9122 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9123 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9124
9125 +#ifndef __ASSEMBLY__
9126 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9127 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9128 +#endif
9129 +
9130 /* Minimum kernel alignment, as a power of two */
9131 #ifdef CONFIG_X86_64
9132 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9133 diff -urNp linux-2.6.39.1/arch/x86/include/asm/cacheflush.h linux-2.6.39.1/arch/x86/include/asm/cacheflush.h
9134 --- linux-2.6.39.1/arch/x86/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
9135 +++ linux-2.6.39.1/arch/x86/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
9136 @@ -26,7 +26,7 @@ static inline unsigned long get_page_mem
9137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9138
9139 if (pg_flags == _PGMT_DEFAULT)
9140 - return -1;
9141 + return ~0UL;
9142 else if (pg_flags == _PGMT_WC)
9143 return _PAGE_CACHE_WC;
9144 else if (pg_flags == _PGMT_UC_MINUS)
9145 diff -urNp linux-2.6.39.1/arch/x86/include/asm/cache.h linux-2.6.39.1/arch/x86/include/asm/cache.h
9146 --- linux-2.6.39.1/arch/x86/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
9147 +++ linux-2.6.39.1/arch/x86/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
9148 @@ -5,12 +5,13 @@
9149
9150 /* L1 cache line size */
9151 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9152 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9153 +#define L1_CACHE_BYTES (_AC(1,U) << L1_CACHE_SHIFT)
9154
9155 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9156 +#define __read_only __attribute__((__section__(".data..read_only")))
9157
9158 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9159 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9160 +#define INTERNODE_CACHE_BYTES (_AC(1,U) << INTERNODE_CACHE_SHIFT)
9161
9162 #ifdef CONFIG_X86_VSMP
9163 #ifdef CONFIG_SMP
9164 diff -urNp linux-2.6.39.1/arch/x86/include/asm/checksum_32.h linux-2.6.39.1/arch/x86/include/asm/checksum_32.h
9165 --- linux-2.6.39.1/arch/x86/include/asm/checksum_32.h 2011-05-19 00:06:34.000000000 -0400
9166 +++ linux-2.6.39.1/arch/x86/include/asm/checksum_32.h 2011-05-22 19:36:30.000000000 -0400
9167 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
9168 int len, __wsum sum,
9169 int *src_err_ptr, int *dst_err_ptr);
9170
9171 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9172 + int len, __wsum sum,
9173 + int *src_err_ptr, int *dst_err_ptr);
9174 +
9175 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9176 + int len, __wsum sum,
9177 + int *src_err_ptr, int *dst_err_ptr);
9178 +
9179 /*
9180 * Note: when you get a NULL pointer exception here this means someone
9181 * passed in an incorrect kernel address to one of these functions.
9182 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
9183 int *err_ptr)
9184 {
9185 might_sleep();
9186 - return csum_partial_copy_generic((__force void *)src, dst,
9187 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9188 len, sum, err_ptr, NULL);
9189 }
9190
9191 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
9192 {
9193 might_sleep();
9194 if (access_ok(VERIFY_WRITE, dst, len))
9195 - return csum_partial_copy_generic(src, (__force void *)dst,
9196 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9197 len, sum, NULL, err_ptr);
9198
9199 if (len)
9200 diff -urNp linux-2.6.39.1/arch/x86/include/asm/cpufeature.h linux-2.6.39.1/arch/x86/include/asm/cpufeature.h
9201 --- linux-2.6.39.1/arch/x86/include/asm/cpufeature.h 2011-06-03 00:04:13.000000000 -0400
9202 +++ linux-2.6.39.1/arch/x86/include/asm/cpufeature.h 2011-06-03 00:32:04.000000000 -0400
9203 @@ -351,7 +351,7 @@ static __always_inline __pure bool __sta
9204 ".section .discard,\"aw\",@progbits\n"
9205 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9206 ".previous\n"
9207 - ".section .altinstr_replacement,\"ax\"\n"
9208 + ".section .altinstr_replacement,\"a\"\n"
9209 "3: movb $1,%0\n"
9210 "4:\n"
9211 ".previous\n"
9212 diff -urNp linux-2.6.39.1/arch/x86/include/asm/desc_defs.h linux-2.6.39.1/arch/x86/include/asm/desc_defs.h
9213 --- linux-2.6.39.1/arch/x86/include/asm/desc_defs.h 2011-05-19 00:06:34.000000000 -0400
9214 +++ linux-2.6.39.1/arch/x86/include/asm/desc_defs.h 2011-05-22 19:36:30.000000000 -0400
9215 @@ -31,6 +31,12 @@ struct desc_struct {
9216 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9217 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9218 };
9219 + struct {
9220 + u16 offset_low;
9221 + u16 seg;
9222 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9223 + unsigned offset_high: 16;
9224 + } gate;
9225 };
9226 } __attribute__((packed));
9227
9228 diff -urNp linux-2.6.39.1/arch/x86/include/asm/desc.h linux-2.6.39.1/arch/x86/include/asm/desc.h
9229 --- linux-2.6.39.1/arch/x86/include/asm/desc.h 2011-05-19 00:06:34.000000000 -0400
9230 +++ linux-2.6.39.1/arch/x86/include/asm/desc.h 2011-05-22 19:36:30.000000000 -0400
9231 @@ -4,6 +4,7 @@
9232 #include <asm/desc_defs.h>
9233 #include <asm/ldt.h>
9234 #include <asm/mmu.h>
9235 +#include <asm/pgtable.h>
9236 #include <linux/smp.h>
9237
9238 static inline void fill_ldt(struct desc_struct *desc,
9239 @@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
9240 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9241 desc->type = (info->read_exec_only ^ 1) << 1;
9242 desc->type |= info->contents << 2;
9243 + desc->type |= info->seg_not_present ^ 1;
9244 desc->s = 1;
9245 desc->dpl = 0x3;
9246 desc->p = info->seg_not_present ^ 1;
9247 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
9248 }
9249
9250 extern struct desc_ptr idt_descr;
9251 -extern gate_desc idt_table[];
9252 -
9253 -struct gdt_page {
9254 - struct desc_struct gdt[GDT_ENTRIES];
9255 -} __attribute__((aligned(PAGE_SIZE)));
9256 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9257 +extern gate_desc idt_table[256];
9258
9259 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9260 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9261 {
9262 - return per_cpu(gdt_page, cpu).gdt;
9263 + return cpu_gdt_table[cpu];
9264 }
9265
9266 #ifdef CONFIG_X86_64
9267 @@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
9268 unsigned long base, unsigned dpl, unsigned flags,
9269 unsigned short seg)
9270 {
9271 - gate->a = (seg << 16) | (base & 0xffff);
9272 - gate->b = (base & 0xffff0000) |
9273 - (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9274 + gate->gate.offset_low = base;
9275 + gate->gate.seg = seg;
9276 + gate->gate.reserved = 0;
9277 + gate->gate.type = type;
9278 + gate->gate.s = 0;
9279 + gate->gate.dpl = dpl;
9280 + gate->gate.p = 1;
9281 + gate->gate.offset_high = base >> 16;
9282 }
9283
9284 #endif
9285 @@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
9286 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9287 const gate_desc *gate)
9288 {
9289 + pax_open_kernel();
9290 memcpy(&idt[entry], gate, sizeof(*gate));
9291 + pax_close_kernel();
9292 }
9293
9294 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9295 const void *desc)
9296 {
9297 + pax_open_kernel();
9298 memcpy(&ldt[entry], desc, 8);
9299 + pax_close_kernel();
9300 }
9301
9302 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9303 @@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
9304 size = sizeof(struct desc_struct);
9305 break;
9306 }
9307 +
9308 + pax_open_kernel();
9309 memcpy(&gdt[entry], desc, size);
9310 + pax_close_kernel();
9311 }
9312
9313 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9314 @@ -211,7 +221,9 @@ static inline void native_set_ldt(const
9315
9316 static inline void native_load_tr_desc(void)
9317 {
9318 + pax_open_kernel();
9319 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9320 + pax_close_kernel();
9321 }
9322
9323 static inline void native_load_gdt(const struct desc_ptr *dtr)
9324 @@ -246,8 +258,10 @@ static inline void native_load_tls(struc
9325 unsigned int i;
9326 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9327
9328 + pax_open_kernel();
9329 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9330 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9331 + pax_close_kernel();
9332 }
9333
9334 #define _LDT_empty(info) \
9335 @@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
9336 desc->limit = (limit >> 16) & 0xf;
9337 }
9338
9339 -static inline void _set_gate(int gate, unsigned type, void *addr,
9340 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9341 unsigned dpl, unsigned ist, unsigned seg)
9342 {
9343 gate_desc s;
9344 @@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
9345 * Pentium F0 0F bugfix can have resulted in the mapped
9346 * IDT being write-protected.
9347 */
9348 -static inline void set_intr_gate(unsigned int n, void *addr)
9349 +static inline void set_intr_gate(unsigned int n, const void *addr)
9350 {
9351 BUG_ON((unsigned)n > 0xFF);
9352 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9353 @@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
9354 /*
9355 * This routine sets up an interrupt gate at directory privilege level 3.
9356 */
9357 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9358 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9359 {
9360 BUG_ON((unsigned)n > 0xFF);
9361 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9362 }
9363
9364 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9365 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9366 {
9367 BUG_ON((unsigned)n > 0xFF);
9368 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9369 }
9370
9371 -static inline void set_trap_gate(unsigned int n, void *addr)
9372 +static inline void set_trap_gate(unsigned int n, const void *addr)
9373 {
9374 BUG_ON((unsigned)n > 0xFF);
9375 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9376 @@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
9377 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9378 {
9379 BUG_ON((unsigned)n > 0xFF);
9380 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9381 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9382 }
9383
9384 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9385 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9386 {
9387 BUG_ON((unsigned)n > 0xFF);
9388 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9389 }
9390
9391 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9392 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9393 {
9394 BUG_ON((unsigned)n > 0xFF);
9395 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9396 }
9397
9398 +#ifdef CONFIG_X86_32
9399 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9400 +{
9401 + struct desc_struct d;
9402 +
9403 + if (likely(limit))
9404 + limit = (limit - 1UL) >> PAGE_SHIFT;
9405 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9406 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9407 +}
9408 +#endif
9409 +
9410 #endif /* _ASM_X86_DESC_H */
9411 diff -urNp linux-2.6.39.1/arch/x86/include/asm/device.h linux-2.6.39.1/arch/x86/include/asm/device.h
9412 --- linux-2.6.39.1/arch/x86/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
9413 +++ linux-2.6.39.1/arch/x86/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
9414 @@ -6,7 +6,7 @@ struct dev_archdata {
9415 void *acpi_handle;
9416 #endif
9417 #ifdef CONFIG_X86_64
9418 -struct dma_map_ops *dma_ops;
9419 + const struct dma_map_ops *dma_ops;
9420 #endif
9421 #if defined(CONFIG_DMAR) || defined(CONFIG_AMD_IOMMU)
9422 void *iommu; /* hook for IOMMU specific extension */
9423 diff -urNp linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h
9424 --- linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
9425 +++ linux-2.6.39.1/arch/x86/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
9426 @@ -26,9 +26,9 @@ extern int iommu_merge;
9427 extern struct device x86_dma_fallback_dev;
9428 extern int panic_on_overflow;
9429
9430 -extern struct dma_map_ops *dma_ops;
9431 +extern const struct dma_map_ops *dma_ops;
9432
9433 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9434 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9435 {
9436 #ifdef CONFIG_X86_32
9437 return dma_ops;
9438 @@ -45,7 +45,7 @@ static inline struct dma_map_ops *get_dm
9439 /* Make sure we keep the same behaviour */
9440 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9441 {
9442 - struct dma_map_ops *ops = get_dma_ops(dev);
9443 + const struct dma_map_ops *ops = get_dma_ops(dev);
9444 if (ops->mapping_error)
9445 return ops->mapping_error(dev, dma_addr);
9446
9447 @@ -115,7 +115,7 @@ static inline void *
9448 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9449 gfp_t gfp)
9450 {
9451 - struct dma_map_ops *ops = get_dma_ops(dev);
9452 + const struct dma_map_ops *ops = get_dma_ops(dev);
9453 void *memory;
9454
9455 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9456 @@ -142,7 +142,7 @@ dma_alloc_coherent(struct device *dev, s
9457 static inline void dma_free_coherent(struct device *dev, size_t size,
9458 void *vaddr, dma_addr_t bus)
9459 {
9460 - struct dma_map_ops *ops = get_dma_ops(dev);
9461 + const struct dma_map_ops *ops = get_dma_ops(dev);
9462
9463 WARN_ON(irqs_disabled()); /* for portability */
9464
9465 diff -urNp linux-2.6.39.1/arch/x86/include/asm/e820.h linux-2.6.39.1/arch/x86/include/asm/e820.h
9466 --- linux-2.6.39.1/arch/x86/include/asm/e820.h 2011-05-19 00:06:34.000000000 -0400
9467 +++ linux-2.6.39.1/arch/x86/include/asm/e820.h 2011-05-22 19:36:30.000000000 -0400
9468 @@ -69,7 +69,7 @@ struct e820map {
9469 #define ISA_START_ADDRESS 0xa0000
9470 #define ISA_END_ADDRESS 0x100000
9471
9472 -#define BIOS_BEGIN 0x000a0000
9473 +#define BIOS_BEGIN 0x000c0000
9474 #define BIOS_END 0x00100000
9475
9476 #define BIOS_ROM_BASE 0xffe00000
9477 diff -urNp linux-2.6.39.1/arch/x86/include/asm/elf.h linux-2.6.39.1/arch/x86/include/asm/elf.h
9478 --- linux-2.6.39.1/arch/x86/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
9479 +++ linux-2.6.39.1/arch/x86/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
9480 @@ -237,7 +237,25 @@ extern int force_personality32;
9481 the loader. We need to make sure that it is out of the way of the program
9482 that it will "exec", and that there is sufficient room for the brk. */
9483
9484 +#ifdef CONFIG_PAX_SEGMEXEC
9485 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9486 +#else
9487 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9488 +#endif
9489 +
9490 +#ifdef CONFIG_PAX_ASLR
9491 +#ifdef CONFIG_X86_32
9492 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9493 +
9494 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9495 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9496 +#else
9497 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9498 +
9499 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9500 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9501 +#endif
9502 +#endif
9503
9504 /* This yields a mask that user programs can use to figure out what
9505 instruction set this CPU supports. This could be done in user space,
9506 @@ -291,8 +309,7 @@ do { \
9507 #define ARCH_DLINFO \
9508 do { \
9509 if (vdso_enabled) \
9510 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9511 - (unsigned long)current->mm->context.vdso); \
9512 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
9513 } while (0)
9514
9515 #define AT_SYSINFO 32
9516 @@ -303,7 +320,7 @@ do { \
9517
9518 #endif /* !CONFIG_X86_32 */
9519
9520 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9521 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9522
9523 #define VDSO_ENTRY \
9524 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9525 @@ -317,7 +334,4 @@ extern int arch_setup_additional_pages(s
9526 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9527 #define compat_arch_setup_additional_pages syscall32_setup_pages
9528
9529 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9530 -#define arch_randomize_brk arch_randomize_brk
9531 -
9532 #endif /* _ASM_X86_ELF_H */
9533 diff -urNp linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h
9534 --- linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h 2011-05-19 00:06:34.000000000 -0400
9535 +++ linux-2.6.39.1/arch/x86/include/asm/emergency-restart.h 2011-05-22 19:36:30.000000000 -0400
9536 @@ -15,6 +15,6 @@ enum reboot_type {
9537
9538 extern enum reboot_type reboot_type;
9539
9540 -extern void machine_emergency_restart(void);
9541 +extern void machine_emergency_restart(void) __noreturn;
9542
9543 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9544 diff -urNp linux-2.6.39.1/arch/x86/include/asm/futex.h linux-2.6.39.1/arch/x86/include/asm/futex.h
9545 --- linux-2.6.39.1/arch/x86/include/asm/futex.h 2011-05-19 00:06:34.000000000 -0400
9546 +++ linux-2.6.39.1/arch/x86/include/asm/futex.h 2011-05-22 19:36:30.000000000 -0400
9547 @@ -12,16 +12,18 @@
9548 #include <asm/system.h>
9549
9550 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9551 + typecheck(u32 *, uaddr); \
9552 asm volatile("1:\t" insn "\n" \
9553 "2:\t.section .fixup,\"ax\"\n" \
9554 "3:\tmov\t%3, %1\n" \
9555 "\tjmp\t2b\n" \
9556 "\t.previous\n" \
9557 _ASM_EXTABLE(1b, 3b) \
9558 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9559 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
9560 : "i" (-EFAULT), "0" (oparg), "1" (0))
9561
9562 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9563 + typecheck(u32 *, uaddr); \
9564 asm volatile("1:\tmovl %2, %0\n" \
9565 "\tmovl\t%0, %3\n" \
9566 "\t" insn "\n" \
9567 @@ -34,7 +36,7 @@
9568 _ASM_EXTABLE(1b, 4b) \
9569 _ASM_EXTABLE(2b, 4b) \
9570 : "=&a" (oldval), "=&r" (ret), \
9571 - "+m" (*uaddr), "=&r" (tem) \
9572 + "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
9573 : "r" (oparg), "i" (-EFAULT), "1" (0))
9574
9575 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9576 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
9577
9578 switch (op) {
9579 case FUTEX_OP_SET:
9580 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9581 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9582 break;
9583 case FUTEX_OP_ADD:
9584 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9585 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9586 uaddr, oparg);
9587 break;
9588 case FUTEX_OP_OR:
9589 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_i
9590 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9591 return -EFAULT;
9592
9593 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
9594 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
9595 "2:\t.section .fixup, \"ax\"\n"
9596 "3:\tmov %3, %0\n"
9597 "\tjmp 2b\n"
9598 "\t.previous\n"
9599 _ASM_EXTABLE(1b, 3b)
9600 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
9601 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
9602 : "i" (-EFAULT), "r" (newval), "1" (oldval)
9603 : "memory"
9604 );
9605 diff -urNp linux-2.6.39.1/arch/x86/include/asm/hw_irq.h linux-2.6.39.1/arch/x86/include/asm/hw_irq.h
9606 --- linux-2.6.39.1/arch/x86/include/asm/hw_irq.h 2011-05-19 00:06:34.000000000 -0400
9607 +++ linux-2.6.39.1/arch/x86/include/asm/hw_irq.h 2011-05-22 19:36:30.000000000 -0400
9608 @@ -137,8 +137,8 @@ extern void setup_ioapic_dest(void);
9609 extern void enable_IO_APIC(void);
9610
9611 /* Statistics */
9612 -extern atomic_t irq_err_count;
9613 -extern atomic_t irq_mis_count;
9614 +extern atomic_unchecked_t irq_err_count;
9615 +extern atomic_unchecked_t irq_mis_count;
9616
9617 /* EISA */
9618 extern void eisa_set_level_irq(unsigned int irq);
9619 diff -urNp linux-2.6.39.1/arch/x86/include/asm/i387.h linux-2.6.39.1/arch/x86/include/asm/i387.h
9620 --- linux-2.6.39.1/arch/x86/include/asm/i387.h 2011-05-19 00:06:34.000000000 -0400
9621 +++ linux-2.6.39.1/arch/x86/include/asm/i387.h 2011-05-22 19:36:30.000000000 -0400
9622 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
9623 {
9624 int err;
9625
9626 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9627 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9628 + fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
9629 +#endif
9630 +
9631 /* See comment in fxsave() below. */
9632 #ifdef CONFIG_AS_FXSAVEQ
9633 asm volatile("1: fxrstorq %[fx]\n\t"
9634 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i38
9635 {
9636 int err;
9637
9638 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9639 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9640 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9641 +#endif
9642 +
9643 /*
9644 * Clear the bytes not touched by the fxsave and reserved
9645 * for the SW usage.
9646 @@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu
9647 #endif /* CONFIG_X86_64 */
9648
9649 /* We need a safe address that is cheap to find and that is already
9650 - in L1 during context switch. The best choices are unfortunately
9651 - different for UP and SMP */
9652 -#ifdef CONFIG_SMP
9653 -#define safe_address (__per_cpu_offset[0])
9654 -#else
9655 -#define safe_address (kstat_cpu(0).cpustat.user)
9656 -#endif
9657 + in L1 during context switch. */
9658 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
9659
9660 /*
9661 * These must be called with preempt disabled
9662 @@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void
9663 struct thread_info *me = current_thread_info();
9664 preempt_disable();
9665 if (me->status & TS_USEDFPU)
9666 - __save_init_fpu(me->task);
9667 + __save_init_fpu(current);
9668 else
9669 clts();
9670 }
9671 diff -urNp linux-2.6.39.1/arch/x86/include/asm/io.h linux-2.6.39.1/arch/x86/include/asm/io.h
9672 --- linux-2.6.39.1/arch/x86/include/asm/io.h 2011-05-19 00:06:34.000000000 -0400
9673 +++ linux-2.6.39.1/arch/x86/include/asm/io.h 2011-05-22 19:36:30.000000000 -0400
9674 @@ -216,6 +216,17 @@ extern void set_iounmap_nonlazy(void);
9675
9676 #include <linux/vmalloc.h>
9677
9678 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9679 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9680 +{
9681 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9682 +}
9683 +
9684 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9685 +{
9686 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9687 +}
9688 +
9689 /*
9690 * Convert a virtual cached pointer to an uncached pointer
9691 */
9692 diff -urNp linux-2.6.39.1/arch/x86/include/asm/iommu.h linux-2.6.39.1/arch/x86/include/asm/iommu.h
9693 --- linux-2.6.39.1/arch/x86/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
9694 +++ linux-2.6.39.1/arch/x86/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
9695 @@ -1,7 +1,7 @@
9696 #ifndef _ASM_X86_IOMMU_H
9697 #define _ASM_X86_IOMMU_H
9698
9699 -extern struct dma_map_ops nommu_dma_ops;
9700 +extern const struct dma_map_ops nommu_dma_ops;
9701 extern int force_iommu, no_iommu;
9702 extern int iommu_detected;
9703 extern int iommu_pass_through;
9704 diff -urNp linux-2.6.39.1/arch/x86/include/asm/irqflags.h linux-2.6.39.1/arch/x86/include/asm/irqflags.h
9705 --- linux-2.6.39.1/arch/x86/include/asm/irqflags.h 2011-05-19 00:06:34.000000000 -0400
9706 +++ linux-2.6.39.1/arch/x86/include/asm/irqflags.h 2011-05-22 19:36:30.000000000 -0400
9707 @@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
9708 sti; \
9709 sysexit
9710
9711 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
9712 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9713 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
9714 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9715 +
9716 #else
9717 #define INTERRUPT_RETURN iret
9718 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9719 diff -urNp linux-2.6.39.1/arch/x86/include/asm/kprobes.h linux-2.6.39.1/arch/x86/include/asm/kprobes.h
9720 --- linux-2.6.39.1/arch/x86/include/asm/kprobes.h 2011-05-19 00:06:34.000000000 -0400
9721 +++ linux-2.6.39.1/arch/x86/include/asm/kprobes.h 2011-05-22 19:36:30.000000000 -0400
9722 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
9723 #define RELATIVEJUMP_SIZE 5
9724 #define RELATIVECALL_OPCODE 0xe8
9725 #define RELATIVE_ADDR_SIZE 4
9726 -#define MAX_STACK_SIZE 64
9727 -#define MIN_STACK_SIZE(ADDR) \
9728 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9729 - THREAD_SIZE - (unsigned long)(ADDR))) \
9730 - ? (MAX_STACK_SIZE) \
9731 - : (((unsigned long)current_thread_info()) + \
9732 - THREAD_SIZE - (unsigned long)(ADDR)))
9733 +#define MAX_STACK_SIZE 64UL
9734 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9735
9736 #define flush_insn_slot(p) do { } while (0)
9737
9738 diff -urNp linux-2.6.39.1/arch/x86/include/asm/kvm_host.h linux-2.6.39.1/arch/x86/include/asm/kvm_host.h
9739 --- linux-2.6.39.1/arch/x86/include/asm/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
9740 +++ linux-2.6.39.1/arch/x86/include/asm/kvm_host.h 2011-05-22 19:36:30.000000000 -0400
9741 @@ -419,7 +419,7 @@ struct kvm_arch {
9742 unsigned int n_used_mmu_pages;
9743 unsigned int n_requested_mmu_pages;
9744 unsigned int n_max_mmu_pages;
9745 - atomic_t invlpg_counter;
9746 + atomic_unchecked_t invlpg_counter;
9747 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
9748 /*
9749 * Hash table of struct kvm_mmu_page.
9750 @@ -599,7 +599,7 @@ struct kvm_arch_async_pf {
9751 bool direct_map;
9752 };
9753
9754 -extern struct kvm_x86_ops *kvm_x86_ops;
9755 +extern const struct kvm_x86_ops *kvm_x86_ops;
9756
9757 int kvm_mmu_module_init(void);
9758 void kvm_mmu_module_exit(void);
9759 diff -urNp linux-2.6.39.1/arch/x86/include/asm/local.h linux-2.6.39.1/arch/x86/include/asm/local.h
9760 --- linux-2.6.39.1/arch/x86/include/asm/local.h 2011-05-19 00:06:34.000000000 -0400
9761 +++ linux-2.6.39.1/arch/x86/include/asm/local.h 2011-05-22 19:36:30.000000000 -0400
9762 @@ -18,26 +18,58 @@ typedef struct {
9763
9764 static inline void local_inc(local_t *l)
9765 {
9766 - asm volatile(_ASM_INC "%0"
9767 + asm volatile(_ASM_INC "%0\n"
9768 +
9769 +#ifdef CONFIG_PAX_REFCOUNT
9770 + "jno 0f\n"
9771 + _ASM_DEC "%0\n"
9772 + "int $4\n0:\n"
9773 + _ASM_EXTABLE(0b, 0b)
9774 +#endif
9775 +
9776 : "+m" (l->a.counter));
9777 }
9778
9779 static inline void local_dec(local_t *l)
9780 {
9781 - asm volatile(_ASM_DEC "%0"
9782 + asm volatile(_ASM_DEC "%0\n"
9783 +
9784 +#ifdef CONFIG_PAX_REFCOUNT
9785 + "jno 0f\n"
9786 + _ASM_INC "%0\n"
9787 + "int $4\n0:\n"
9788 + _ASM_EXTABLE(0b, 0b)
9789 +#endif
9790 +
9791 : "+m" (l->a.counter));
9792 }
9793
9794 static inline void local_add(long i, local_t *l)
9795 {
9796 - asm volatile(_ASM_ADD "%1,%0"
9797 + asm volatile(_ASM_ADD "%1,%0\n"
9798 +
9799 +#ifdef CONFIG_PAX_REFCOUNT
9800 + "jno 0f\n"
9801 + _ASM_SUB "%1,%0\n"
9802 + "int $4\n0:\n"
9803 + _ASM_EXTABLE(0b, 0b)
9804 +#endif
9805 +
9806 : "+m" (l->a.counter)
9807 : "ir" (i));
9808 }
9809
9810 static inline void local_sub(long i, local_t *l)
9811 {
9812 - asm volatile(_ASM_SUB "%1,%0"
9813 + asm volatile(_ASM_SUB "%1,%0\n"
9814 +
9815 +#ifdef CONFIG_PAX_REFCOUNT
9816 + "jno 0f\n"
9817 + _ASM_ADD "%1,%0\n"
9818 + "int $4\n0:\n"
9819 + _ASM_EXTABLE(0b, 0b)
9820 +#endif
9821 +
9822 : "+m" (l->a.counter)
9823 : "ir" (i));
9824 }
9825 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
9826 {
9827 unsigned char c;
9828
9829 - asm volatile(_ASM_SUB "%2,%0; sete %1"
9830 + asm volatile(_ASM_SUB "%2,%0\n"
9831 +
9832 +#ifdef CONFIG_PAX_REFCOUNT
9833 + "jno 0f\n"
9834 + _ASM_ADD "%2,%0\n"
9835 + "int $4\n0:\n"
9836 + _ASM_EXTABLE(0b, 0b)
9837 +#endif
9838 +
9839 + "sete %1\n"
9840 : "+m" (l->a.counter), "=qm" (c)
9841 : "ir" (i) : "memory");
9842 return c;
9843 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
9844 {
9845 unsigned char c;
9846
9847 - asm volatile(_ASM_DEC "%0; sete %1"
9848 + asm volatile(_ASM_DEC "%0\n"
9849 +
9850 +#ifdef CONFIG_PAX_REFCOUNT
9851 + "jno 0f\n"
9852 + _ASM_INC "%0\n"
9853 + "int $4\n0:\n"
9854 + _ASM_EXTABLE(0b, 0b)
9855 +#endif
9856 +
9857 + "sete %1\n"
9858 : "+m" (l->a.counter), "=qm" (c)
9859 : : "memory");
9860 return c != 0;
9861 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
9862 {
9863 unsigned char c;
9864
9865 - asm volatile(_ASM_INC "%0; sete %1"
9866 + asm volatile(_ASM_INC "%0\n"
9867 +
9868 +#ifdef CONFIG_PAX_REFCOUNT
9869 + "jno 0f\n"
9870 + _ASM_DEC "%0\n"
9871 + "int $4\n0:\n"
9872 + _ASM_EXTABLE(0b, 0b)
9873 +#endif
9874 +
9875 + "sete %1\n"
9876 : "+m" (l->a.counter), "=qm" (c)
9877 : : "memory");
9878 return c != 0;
9879 @@ -110,7 +169,16 @@ static inline int local_add_negative(lon
9880 {
9881 unsigned char c;
9882
9883 - asm volatile(_ASM_ADD "%2,%0; sets %1"
9884 + asm volatile(_ASM_ADD "%2,%0\n"
9885 +
9886 +#ifdef CONFIG_PAX_REFCOUNT
9887 + "jno 0f\n"
9888 + _ASM_SUB "%2,%0\n"
9889 + "int $4\n0:\n"
9890 + _ASM_EXTABLE(0b, 0b)
9891 +#endif
9892 +
9893 + "sets %1\n"
9894 : "+m" (l->a.counter), "=qm" (c)
9895 : "ir" (i) : "memory");
9896 return c;
9897 @@ -133,7 +201,15 @@ static inline long local_add_return(long
9898 #endif
9899 /* Modern 486+ processor */
9900 __i = i;
9901 - asm volatile(_ASM_XADD "%0, %1;"
9902 + asm volatile(_ASM_XADD "%0, %1\n"
9903 +
9904 +#ifdef CONFIG_PAX_REFCOUNT
9905 + "jno 0f\n"
9906 + _ASM_MOV "%0,%1\n"
9907 + "int $4\n0:\n"
9908 + _ASM_EXTABLE(0b, 0b)
9909 +#endif
9910 +
9911 : "+r" (i), "+m" (l->a.counter)
9912 : : "memory");
9913 return i + __i;
9914 diff -urNp linux-2.6.39.1/arch/x86/include/asm/mce.h linux-2.6.39.1/arch/x86/include/asm/mce.h
9915 --- linux-2.6.39.1/arch/x86/include/asm/mce.h 2011-05-19 00:06:34.000000000 -0400
9916 +++ linux-2.6.39.1/arch/x86/include/asm/mce.h 2011-05-22 19:36:30.000000000 -0400
9917 @@ -198,7 +198,7 @@ int mce_notify_irq(void);
9918 void mce_notify_process(void);
9919
9920 DECLARE_PER_CPU(struct mce, injectm);
9921 -extern struct file_operations mce_chrdev_ops;
9922 +extern struct file_operations mce_chrdev_ops; /* cannot be const, see arch/x86/kernel/cpu/mcheck/mce. */
9923
9924 /*
9925 * Exception handler
9926 diff -urNp linux-2.6.39.1/arch/x86/include/asm/microcode.h linux-2.6.39.1/arch/x86/include/asm/microcode.h
9927 --- linux-2.6.39.1/arch/x86/include/asm/microcode.h 2011-05-19 00:06:34.000000000 -0400
9928 +++ linux-2.6.39.1/arch/x86/include/asm/microcode.h 2011-05-22 19:36:30.000000000 -0400
9929 @@ -12,13 +12,13 @@ struct device;
9930 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
9931
9932 struct microcode_ops {
9933 - enum ucode_state (*request_microcode_user) (int cpu,
9934 + enum ucode_state (* const request_microcode_user) (int cpu,
9935 const void __user *buf, size_t size);
9936
9937 - enum ucode_state (*request_microcode_fw) (int cpu,
9938 + enum ucode_state (* const request_microcode_fw) (int cpu,
9939 struct device *device);
9940
9941 - void (*microcode_fini_cpu) (int cpu);
9942 + void (* const microcode_fini_cpu) (int cpu);
9943
9944 /*
9945 * The generic 'microcode_core' part guarantees that
9946 @@ -38,16 +38,16 @@ struct ucode_cpu_info {
9947 extern struct ucode_cpu_info ucode_cpu_info[];
9948
9949 #ifdef CONFIG_MICROCODE_INTEL
9950 -extern struct microcode_ops * __init init_intel_microcode(void);
9951 +extern const struct microcode_ops * __init init_intel_microcode(void);
9952 #else
9953 -static inline struct microcode_ops * __init init_intel_microcode(void)
9954 +static inline const struct microcode_ops * __init init_intel_microcode(void)
9955 {
9956 return NULL;
9957 }
9958 #endif /* CONFIG_MICROCODE_INTEL */
9959
9960 #ifdef CONFIG_MICROCODE_AMD
9961 -extern struct microcode_ops * __init init_amd_microcode(void);
9962 +extern const struct microcode_ops * __init init_amd_microcode(void);
9963
9964 static inline void get_ucode_data(void *to, const u8 *from, size_t n)
9965 {
9966 @@ -55,7 +55,7 @@ static inline void get_ucode_data(void *
9967 }
9968
9969 #else
9970 -static inline struct microcode_ops * __init init_amd_microcode(void)
9971 +static inline const struct microcode_ops * __init init_amd_microcode(void)
9972 {
9973 return NULL;
9974 }
9975 diff -urNp linux-2.6.39.1/arch/x86/include/asm/mman.h linux-2.6.39.1/arch/x86/include/asm/mman.h
9976 --- linux-2.6.39.1/arch/x86/include/asm/mman.h 2011-05-19 00:06:34.000000000 -0400
9977 +++ linux-2.6.39.1/arch/x86/include/asm/mman.h 2011-05-22 19:36:30.000000000 -0400
9978 @@ -5,4 +5,14 @@
9979
9980 #include <asm-generic/mman.h>
9981
9982 +#ifdef __KERNEL__
9983 +#ifndef __ASSEMBLY__
9984 +#ifdef CONFIG_X86_32
9985 +#define arch_mmap_check i386_mmap_check
9986 +int i386_mmap_check(unsigned long addr, unsigned long len,
9987 + unsigned long flags);
9988 +#endif
9989 +#endif
9990 +#endif
9991 +
9992 #endif /* _ASM_X86_MMAN_H */
9993 diff -urNp linux-2.6.39.1/arch/x86/include/asm/mmu_context.h linux-2.6.39.1/arch/x86/include/asm/mmu_context.h
9994 --- linux-2.6.39.1/arch/x86/include/asm/mmu_context.h 2011-05-19 00:06:34.000000000 -0400
9995 +++ linux-2.6.39.1/arch/x86/include/asm/mmu_context.h 2011-05-22 19:36:30.000000000 -0400
9996 @@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
9997
9998 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9999 {
10000 +
10001 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10002 + unsigned int i;
10003 + pgd_t *pgd;
10004 +
10005 + pax_open_kernel();
10006 + pgd = get_cpu_pgd(smp_processor_id());
10007 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10008 + if (paravirt_enabled())
10009 + set_pgd(pgd+i, native_make_pgd(0));
10010 + else
10011 + pgd[i] = native_make_pgd(0);
10012 + pax_close_kernel();
10013 +#endif
10014 +
10015 #ifdef CONFIG_SMP
10016 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10017 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10018 @@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
10019 struct task_struct *tsk)
10020 {
10021 unsigned cpu = smp_processor_id();
10022 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
10023 + int tlbstate = TLBSTATE_OK;
10024 +#endif
10025
10026 if (likely(prev != next)) {
10027 #ifdef CONFIG_SMP
10028 +#ifdef CONFIG_X86_32
10029 + tlbstate = percpu_read(cpu_tlbstate.state);
10030 +#endif
10031 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10032 percpu_write(cpu_tlbstate.active_mm, next);
10033 #endif
10034 cpumask_set_cpu(cpu, mm_cpumask(next));
10035
10036 /* Re-load page tables */
10037 +#ifdef CONFIG_PAX_PER_CPU_PGD
10038 + pax_open_kernel();
10039 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10040 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10041 + pax_close_kernel();
10042 + load_cr3(get_cpu_pgd(cpu));
10043 +#else
10044 load_cr3(next->pgd);
10045 +#endif
10046
10047 /* stop flush ipis for the previous mm */
10048 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10049 @@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
10050 */
10051 if (unlikely(prev->context.ldt != next->context.ldt))
10052 load_LDT_nolock(&next->context);
10053 - }
10054 +
10055 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10056 + if (!(__supported_pte_mask & _PAGE_NX)) {
10057 + smp_mb__before_clear_bit();
10058 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10059 + smp_mb__after_clear_bit();
10060 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10061 + }
10062 +#endif
10063 +
10064 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10065 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10066 + prev->context.user_cs_limit != next->context.user_cs_limit))
10067 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10068 #ifdef CONFIG_SMP
10069 + else if (unlikely(tlbstate != TLBSTATE_OK))
10070 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10071 +#endif
10072 +#endif
10073 +
10074 + }
10075 else {
10076 +
10077 +#ifdef CONFIG_PAX_PER_CPU_PGD
10078 + pax_open_kernel();
10079 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10080 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10081 + pax_close_kernel();
10082 + load_cr3(get_cpu_pgd(cpu));
10083 +#endif
10084 +
10085 +#ifdef CONFIG_SMP
10086 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10087 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10088
10089 @@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
10090 * tlb flush IPI delivery. We must reload CR3
10091 * to make sure to use no freed page tables.
10092 */
10093 +
10094 +#ifndef CONFIG_PAX_PER_CPU_PGD
10095 load_cr3(next->pgd);
10096 +#endif
10097 +
10098 load_LDT_nolock(&next->context);
10099 +
10100 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10101 + if (!(__supported_pte_mask & _PAGE_NX))
10102 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10103 +#endif
10104 +
10105 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10106 +#ifdef CONFIG_PAX_PAGEEXEC
10107 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10108 +#endif
10109 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10110 +#endif
10111 +
10112 }
10113 - }
10114 #endif
10115 + }
10116 }
10117
10118 #define activate_mm(prev, next) \
10119 diff -urNp linux-2.6.39.1/arch/x86/include/asm/mmu.h linux-2.6.39.1/arch/x86/include/asm/mmu.h
10120 --- linux-2.6.39.1/arch/x86/include/asm/mmu.h 2011-05-19 00:06:34.000000000 -0400
10121 +++ linux-2.6.39.1/arch/x86/include/asm/mmu.h 2011-05-22 19:36:30.000000000 -0400
10122 @@ -9,10 +9,22 @@
10123 * we put the segment information here.
10124 */
10125 typedef struct {
10126 - void *ldt;
10127 + struct desc_struct *ldt;
10128 int size;
10129 struct mutex lock;
10130 - void *vdso;
10131 + unsigned long vdso;
10132 +
10133 +#ifdef CONFIG_X86_32
10134 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10135 + unsigned long user_cs_base;
10136 + unsigned long user_cs_limit;
10137 +
10138 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10139 + cpumask_t cpu_user_cs_mask;
10140 +#endif
10141 +
10142 +#endif
10143 +#endif
10144
10145 #ifdef CONFIG_X86_64
10146 /* True if mm supports a task running in 32 bit compatibility mode. */
10147 diff -urNp linux-2.6.39.1/arch/x86/include/asm/module.h linux-2.6.39.1/arch/x86/include/asm/module.h
10148 --- linux-2.6.39.1/arch/x86/include/asm/module.h 2011-05-19 00:06:34.000000000 -0400
10149 +++ linux-2.6.39.1/arch/x86/include/asm/module.h 2011-05-22 19:41:32.000000000 -0400
10150 @@ -5,6 +5,7 @@
10151
10152 #ifdef CONFIG_X86_64
10153 /* X86_64 does not define MODULE_PROC_FAMILY */
10154 +#define MODULE_PROC_FAMILY ""
10155 #elif defined CONFIG_M386
10156 #define MODULE_PROC_FAMILY "386 "
10157 #elif defined CONFIG_M486
10158 @@ -59,8 +60,30 @@
10159 #error unknown processor family
10160 #endif
10161
10162 -#ifdef CONFIG_X86_32
10163 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10164 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10165 +#define MODULE_PAX_UDEREF "UDEREF "
10166 +#else
10167 +#define MODULE_PAX_UDEREF ""
10168 +#endif
10169 +
10170 +#ifdef CONFIG_PAX_KERNEXEC
10171 +#define MODULE_PAX_KERNEXEC "KERNEXEC "
10172 +#else
10173 +#define MODULE_PAX_KERNEXEC ""
10174 #endif
10175
10176 +#ifdef CONFIG_PAX_REFCOUNT
10177 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
10178 +#else
10179 +#define MODULE_PAX_REFCOUNT ""
10180 +#endif
10181 +
10182 +#ifdef CONFIG_GRKERNSEC
10183 +#define MODULE_GRSEC "GRSECURITY "
10184 +#else
10185 +#define MODULE_GRSEC ""
10186 +#endif
10187 +
10188 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
10189 +
10190 #endif /* _ASM_X86_MODULE_H */
10191 diff -urNp linux-2.6.39.1/arch/x86/include/asm/page_64_types.h linux-2.6.39.1/arch/x86/include/asm/page_64_types.h
10192 --- linux-2.6.39.1/arch/x86/include/asm/page_64_types.h 2011-05-19 00:06:34.000000000 -0400
10193 +++ linux-2.6.39.1/arch/x86/include/asm/page_64_types.h 2011-05-22 19:36:30.000000000 -0400
10194 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10195
10196 /* duplicated to the one in bootmem.h */
10197 extern unsigned long max_pfn;
10198 -extern unsigned long phys_base;
10199 +extern const unsigned long phys_base;
10200
10201 extern unsigned long __phys_addr(unsigned long);
10202 #define __phys_reloc_hide(x) (x)
10203 diff -urNp linux-2.6.39.1/arch/x86/include/asm/paravirt.h linux-2.6.39.1/arch/x86/include/asm/paravirt.h
10204 --- linux-2.6.39.1/arch/x86/include/asm/paravirt.h 2011-05-19 00:06:34.000000000 -0400
10205 +++ linux-2.6.39.1/arch/x86/include/asm/paravirt.h 2011-05-22 19:36:30.000000000 -0400
10206 @@ -739,6 +739,21 @@ static inline void __set_fixmap(unsigned
10207 pv_mmu_ops.set_fixmap(idx, phys, flags);
10208 }
10209
10210 +#ifdef CONFIG_PAX_KERNEXEC
10211 +static inline unsigned long pax_open_kernel(void)
10212 +{
10213 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10214 +}
10215 +
10216 +static inline unsigned long pax_close_kernel(void)
10217 +{
10218 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10219 +}
10220 +#else
10221 +static inline unsigned long pax_open_kernel(void) { return 0; }
10222 +static inline unsigned long pax_close_kernel(void) { return 0; }
10223 +#endif
10224 +
10225 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10226
10227 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10228 @@ -955,7 +970,7 @@ extern void default_banner(void);
10229
10230 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10231 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10232 -#define PARA_INDIRECT(addr) *%cs:addr
10233 +#define PARA_INDIRECT(addr) *%ss:addr
10234 #endif
10235
10236 #define INTERRUPT_RETURN \
10237 @@ -1032,6 +1047,21 @@ extern void default_banner(void);
10238 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10239 CLBR_NONE, \
10240 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10241 +
10242 +#define GET_CR0_INTO_RDI \
10243 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10244 + mov %rax,%rdi
10245 +
10246 +#define SET_RDI_INTO_CR0 \
10247 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10248 +
10249 +#define GET_CR3_INTO_RDI \
10250 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10251 + mov %rax,%rdi
10252 +
10253 +#define SET_RDI_INTO_CR3 \
10254 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10255 +
10256 #endif /* CONFIG_X86_32 */
10257
10258 #endif /* __ASSEMBLY__ */
10259 diff -urNp linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h
10260 --- linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h 2011-05-19 00:06:34.000000000 -0400
10261 +++ linux-2.6.39.1/arch/x86/include/asm/paravirt_types.h 2011-05-22 19:36:30.000000000 -0400
10262 @@ -317,6 +317,12 @@ struct pv_mmu_ops {
10263 an mfn. We can tell which is which from the index. */
10264 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10265 phys_addr_t phys, pgprot_t flags);
10266 +
10267 +#ifdef CONFIG_PAX_KERNEXEC
10268 + unsigned long (*pax_open_kernel)(void);
10269 + unsigned long (*pax_close_kernel)(void);
10270 +#endif
10271 +
10272 };
10273
10274 struct arch_spinlock;
10275 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pci_x86.h linux-2.6.39.1/arch/x86/include/asm/pci_x86.h
10276 --- linux-2.6.39.1/arch/x86/include/asm/pci_x86.h 2011-05-19 00:06:34.000000000 -0400
10277 +++ linux-2.6.39.1/arch/x86/include/asm/pci_x86.h 2011-05-22 19:36:30.000000000 -0400
10278 @@ -93,16 +93,16 @@ extern int (*pcibios_enable_irq)(struct
10279 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10280
10281 struct pci_raw_ops {
10282 - int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10283 + int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10284 int reg, int len, u32 *val);
10285 - int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10286 + int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10287 int reg, int len, u32 val);
10288 };
10289
10290 -extern struct pci_raw_ops *raw_pci_ops;
10291 -extern struct pci_raw_ops *raw_pci_ext_ops;
10292 +extern const struct pci_raw_ops *raw_pci_ops;
10293 +extern const struct pci_raw_ops *raw_pci_ext_ops;
10294
10295 -extern struct pci_raw_ops pci_direct_conf1;
10296 +extern const struct pci_raw_ops pci_direct_conf1;
10297 extern bool port_cf9_safe;
10298
10299 /* arch_initcall level */
10300 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgalloc.h linux-2.6.39.1/arch/x86/include/asm/pgalloc.h
10301 --- linux-2.6.39.1/arch/x86/include/asm/pgalloc.h 2011-05-19 00:06:34.000000000 -0400
10302 +++ linux-2.6.39.1/arch/x86/include/asm/pgalloc.h 2011-05-22 19:36:30.000000000 -0400
10303 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
10304 pmd_t *pmd, pte_t *pte)
10305 {
10306 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10307 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10308 +}
10309 +
10310 +static inline void pmd_populate_user(struct mm_struct *mm,
10311 + pmd_t *pmd, pte_t *pte)
10312 +{
10313 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10314 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10315 }
10316
10317 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h
10318 --- linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h 2011-05-19 00:06:34.000000000 -0400
10319 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable-2level.h 2011-05-22 19:36:30.000000000 -0400
10320 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
10321
10322 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10323 {
10324 + pax_open_kernel();
10325 *pmdp = pmd;
10326 + pax_close_kernel();
10327 }
10328
10329 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10330 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h
10331 --- linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
10332 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
10333 @@ -25,9 +25,6 @@
10334 struct mm_struct;
10335 struct vm_area_struct;
10336
10337 -extern pgd_t swapper_pg_dir[1024];
10338 -extern pgd_t initial_page_table[1024];
10339 -
10340 static inline void pgtable_cache_init(void) { }
10341 static inline void check_pgt_cache(void) { }
10342 void paging_init(void);
10343 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
10344 # include <asm/pgtable-2level.h>
10345 #endif
10346
10347 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10348 +extern pgd_t initial_page_table[PTRS_PER_PGD];
10349 +#ifdef CONFIG_X86_PAE
10350 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10351 +#endif
10352 +
10353 #if defined(CONFIG_HIGHPTE)
10354 #define pte_offset_map(dir, address) \
10355 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10356 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
10357 /* Clear a kernel PTE and flush it from the TLB */
10358 #define kpte_clear_flush(ptep, vaddr) \
10359 do { \
10360 + pax_open_kernel(); \
10361 pte_clear(&init_mm, (vaddr), (ptep)); \
10362 + pax_close_kernel(); \
10363 __flush_tlb_one((vaddr)); \
10364 } while (0)
10365
10366 @@ -74,6 +79,9 @@ do { \
10367
10368 #endif /* !__ASSEMBLY__ */
10369
10370 +#define HAVE_ARCH_UNMAPPED_AREA
10371 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10372 +
10373 /*
10374 * kern_addr_valid() is (1) for FLATMEM and (0) for
10375 * SPARSEMEM and DISCONTIGMEM
10376 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h
10377 --- linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h 2011-05-19 00:06:34.000000000 -0400
10378 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable_32_types.h 2011-05-22 19:36:30.000000000 -0400
10379 @@ -8,7 +8,7 @@
10380 */
10381 #ifdef CONFIG_X86_PAE
10382 # include <asm/pgtable-3level_types.h>
10383 -# define PMD_SIZE (1UL << PMD_SHIFT)
10384 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10385 # define PMD_MASK (~(PMD_SIZE - 1))
10386 #else
10387 # include <asm/pgtable-2level_types.h>
10388 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
10389 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10390 #endif
10391
10392 +#ifdef CONFIG_PAX_KERNEXEC
10393 +#ifndef __ASSEMBLY__
10394 +extern unsigned char MODULES_EXEC_VADDR[];
10395 +extern unsigned char MODULES_EXEC_END[];
10396 +#endif
10397 +#include <asm/boot.h>
10398 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10399 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10400 +#else
10401 +#define ktla_ktva(addr) (addr)
10402 +#define ktva_ktla(addr) (addr)
10403 +#endif
10404 +
10405 #define MODULES_VADDR VMALLOC_START
10406 #define MODULES_END VMALLOC_END
10407 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10408 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h
10409 --- linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h 2011-05-19 00:06:34.000000000 -0400
10410 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable-3level.h 2011-05-22 19:36:30.000000000 -0400
10411 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
10412
10413 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10414 {
10415 + pax_open_kernel();
10416 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10417 + pax_close_kernel();
10418 }
10419
10420 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10421 {
10422 + pax_open_kernel();
10423 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10424 + pax_close_kernel();
10425 }
10426
10427 /*
10428 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h
10429 --- linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h 2011-05-19 00:06:34.000000000 -0400
10430 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable_64.h 2011-05-22 19:36:30.000000000 -0400
10431 @@ -16,10 +16,13 @@
10432
10433 extern pud_t level3_kernel_pgt[512];
10434 extern pud_t level3_ident_pgt[512];
10435 +extern pud_t level3_vmalloc_pgt[512];
10436 +extern pud_t level3_vmemmap_pgt[512];
10437 +extern pud_t level2_vmemmap_pgt[512];
10438 extern pmd_t level2_kernel_pgt[512];
10439 extern pmd_t level2_fixmap_pgt[512];
10440 -extern pmd_t level2_ident_pgt[512];
10441 -extern pgd_t init_level4_pgt[];
10442 +extern pmd_t level2_ident_pgt[512*2];
10443 +extern pgd_t init_level4_pgt[512];
10444
10445 #define swapper_pg_dir init_level4_pgt
10446
10447 @@ -61,7 +64,9 @@ static inline void native_set_pte_atomic
10448
10449 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10450 {
10451 + pax_open_kernel();
10452 *pmdp = pmd;
10453 + pax_close_kernel();
10454 }
10455
10456 static inline void native_pmd_clear(pmd_t *pmd)
10457 @@ -107,7 +112,9 @@ static inline void native_pud_clear(pud_
10458
10459 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10460 {
10461 + pax_open_kernel();
10462 *pgdp = pgd;
10463 + pax_close_kernel();
10464 }
10465
10466 static inline void native_pgd_clear(pgd_t *pgd)
10467 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h
10468 --- linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h 2011-05-19 00:06:34.000000000 -0400
10469 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable_64_types.h 2011-05-22 19:36:30.000000000 -0400
10470 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10471 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10472 #define MODULES_END _AC(0xffffffffff000000, UL)
10473 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10474 +#define MODULES_EXEC_VADDR MODULES_VADDR
10475 +#define MODULES_EXEC_END MODULES_END
10476 +
10477 +#define ktla_ktva(addr) (addr)
10478 +#define ktva_ktla(addr) (addr)
10479
10480 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10481 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable.h linux-2.6.39.1/arch/x86/include/asm/pgtable.h
10482 --- linux-2.6.39.1/arch/x86/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
10483 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
10484 @@ -81,12 +81,51 @@ extern struct mm_struct *pgd_page_get_mm
10485
10486 #define arch_end_context_switch(prev) do {} while(0)
10487
10488 +#define pax_open_kernel() native_pax_open_kernel()
10489 +#define pax_close_kernel() native_pax_close_kernel()
10490 #endif /* CONFIG_PARAVIRT */
10491
10492 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10493 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10494 +
10495 +#ifdef CONFIG_PAX_KERNEXEC
10496 +static inline unsigned long native_pax_open_kernel(void)
10497 +{
10498 + unsigned long cr0;
10499 +
10500 + preempt_disable();
10501 + barrier();
10502 + cr0 = read_cr0() ^ X86_CR0_WP;
10503 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10504 + write_cr0(cr0);
10505 + return cr0 ^ X86_CR0_WP;
10506 +}
10507 +
10508 +static inline unsigned long native_pax_close_kernel(void)
10509 +{
10510 + unsigned long cr0;
10511 +
10512 + cr0 = read_cr0() ^ X86_CR0_WP;
10513 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10514 + write_cr0(cr0);
10515 + barrier();
10516 + preempt_enable_no_resched();
10517 + return cr0 ^ X86_CR0_WP;
10518 +}
10519 +#else
10520 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10521 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10522 +#endif
10523 +
10524 /*
10525 * The following only work if pte_present() is true.
10526 * Undefined behaviour if not..
10527 */
10528 +static inline int pte_user(pte_t pte)
10529 +{
10530 + return pte_val(pte) & _PAGE_USER;
10531 +}
10532 +
10533 static inline int pte_dirty(pte_t pte)
10534 {
10535 return pte_flags(pte) & _PAGE_DIRTY;
10536 @@ -196,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t
10537 return pte_clear_flags(pte, _PAGE_RW);
10538 }
10539
10540 +static inline pte_t pte_mkread(pte_t pte)
10541 +{
10542 + return __pte(pte_val(pte) | _PAGE_USER);
10543 +}
10544 +
10545 static inline pte_t pte_mkexec(pte_t pte)
10546 {
10547 - return pte_clear_flags(pte, _PAGE_NX);
10548 +#ifdef CONFIG_X86_PAE
10549 + if (__supported_pte_mask & _PAGE_NX)
10550 + return pte_clear_flags(pte, _PAGE_NX);
10551 + else
10552 +#endif
10553 + return pte_set_flags(pte, _PAGE_USER);
10554 +}
10555 +
10556 +static inline pte_t pte_exprotect(pte_t pte)
10557 +{
10558 +#ifdef CONFIG_X86_PAE
10559 + if (__supported_pte_mask & _PAGE_NX)
10560 + return pte_set_flags(pte, _PAGE_NX);
10561 + else
10562 +#endif
10563 + return pte_clear_flags(pte, _PAGE_USER);
10564 }
10565
10566 static inline pte_t pte_mkdirty(pte_t pte)
10567 @@ -390,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long
10568 #endif
10569
10570 #ifndef __ASSEMBLY__
10571 +
10572 +#ifdef CONFIG_PAX_PER_CPU_PGD
10573 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10574 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10575 +{
10576 + return cpu_pgd[cpu];
10577 +}
10578 +#endif
10579 +
10580 #include <linux/mm_types.h>
10581
10582 static inline int pte_none(pte_t pte)
10583 @@ -560,7 +628,7 @@ static inline pud_t *pud_offset(pgd_t *p
10584
10585 static inline int pgd_bad(pgd_t pgd)
10586 {
10587 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10588 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10589 }
10590
10591 static inline int pgd_none(pgd_t pgd)
10592 @@ -583,7 +651,12 @@ static inline int pgd_none(pgd_t pgd)
10593 * pgd_offset() returns a (pgd_t *)
10594 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10595 */
10596 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10597 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10598 +
10599 +#ifdef CONFIG_PAX_PER_CPU_PGD
10600 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10601 +#endif
10602 +
10603 /*
10604 * a shortcut which implies the use of the kernel's pgd, instead
10605 * of a process's
10606 @@ -594,6 +667,20 @@ static inline int pgd_none(pgd_t pgd)
10607 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10608 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10609
10610 +#ifdef CONFIG_X86_32
10611 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10612 +#else
10613 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10614 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10615 +
10616 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10617 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10618 +#else
10619 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10620 +#endif
10621 +
10622 +#endif
10623 +
10624 #ifndef __ASSEMBLY__
10625
10626 extern int direct_gbpages;
10627 @@ -758,11 +845,23 @@ static inline void pmdp_set_wrprotect(st
10628 * dst and src can be on the same page, but the range must not overlap,
10629 * and must not cross a page boundary.
10630 */
10631 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10632 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10633 {
10634 - memcpy(dst, src, count * sizeof(pgd_t));
10635 + pax_open_kernel();
10636 + while (count--)
10637 + *dst++ = *src++;
10638 + pax_close_kernel();
10639 }
10640
10641 +#ifdef CONFIG_PAX_PER_CPU_PGD
10642 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10643 +#endif
10644 +
10645 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10646 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10647 +#else
10648 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10649 +#endif
10650
10651 #include <asm-generic/pgtable.h>
10652 #endif /* __ASSEMBLY__ */
10653 diff -urNp linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h
10654 --- linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h 2011-05-19 00:06:34.000000000 -0400
10655 +++ linux-2.6.39.1/arch/x86/include/asm/pgtable_types.h 2011-05-22 19:36:30.000000000 -0400
10656 @@ -16,13 +16,12 @@
10657 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10658 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10659 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10660 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10661 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10662 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10663 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10664 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10665 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10666 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10667 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
10668 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10669 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
10670 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10671
10672 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10673 @@ -40,7 +39,6 @@
10674 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10675 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10676 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10677 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10678 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10679 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10680 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10681 @@ -57,8 +55,10 @@
10682
10683 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10684 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10685 -#else
10686 +#elif defined(CONFIG_KMEMCHECK)
10687 #define _PAGE_NX (_AT(pteval_t, 0))
10688 +#else
10689 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10690 #endif
10691
10692 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10693 @@ -96,6 +96,9 @@
10694 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10695 _PAGE_ACCESSED)
10696
10697 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
10698 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
10699 +
10700 #define __PAGE_KERNEL_EXEC \
10701 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10702 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10703 @@ -106,8 +109,8 @@
10704 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10705 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10706 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10707 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10708 -#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
10709 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10710 +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
10711 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10712 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
10713 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
10714 @@ -166,8 +169,8 @@
10715 * bits are combined, this will alow user to access the high address mapped
10716 * VDSO in the presence of CONFIG_COMPAT_VDSO
10717 */
10718 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10719 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10720 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10721 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10722 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10723 #endif
10724
10725 @@ -205,7 +208,17 @@ static inline pgdval_t pgd_flags(pgd_t p
10726 {
10727 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10728 }
10729 +#endif
10730
10731 +#if PAGETABLE_LEVELS == 3
10732 +#include <asm-generic/pgtable-nopud.h>
10733 +#endif
10734 +
10735 +#if PAGETABLE_LEVELS == 2
10736 +#include <asm-generic/pgtable-nopmd.h>
10737 +#endif
10738 +
10739 +#ifndef __ASSEMBLY__
10740 #if PAGETABLE_LEVELS > 3
10741 typedef struct { pudval_t pud; } pud_t;
10742
10743 @@ -219,8 +232,6 @@ static inline pudval_t native_pud_val(pu
10744 return pud.pud;
10745 }
10746 #else
10747 -#include <asm-generic/pgtable-nopud.h>
10748 -
10749 static inline pudval_t native_pud_val(pud_t pud)
10750 {
10751 return native_pgd_val(pud.pgd);
10752 @@ -240,8 +251,6 @@ static inline pmdval_t native_pmd_val(pm
10753 return pmd.pmd;
10754 }
10755 #else
10756 -#include <asm-generic/pgtable-nopmd.h>
10757 -
10758 static inline pmdval_t native_pmd_val(pmd_t pmd)
10759 {
10760 return native_pgd_val(pmd.pud.pgd);
10761 @@ -281,7 +290,6 @@ typedef struct page *pgtable_t;
10762
10763 extern pteval_t __supported_pte_mask;
10764 extern void set_nx(void);
10765 -extern int nx_enabled;
10766
10767 #define pgprot_writecombine pgprot_writecombine
10768 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10769 diff -urNp linux-2.6.39.1/arch/x86/include/asm/processor.h linux-2.6.39.1/arch/x86/include/asm/processor.h
10770 --- linux-2.6.39.1/arch/x86/include/asm/processor.h 2011-05-19 00:06:34.000000000 -0400
10771 +++ linux-2.6.39.1/arch/x86/include/asm/processor.h 2011-05-22 19:36:30.000000000 -0400
10772 @@ -266,7 +266,7 @@ struct tss_struct {
10773
10774 } ____cacheline_aligned;
10775
10776 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10777 +extern struct tss_struct init_tss[NR_CPUS];
10778
10779 /*
10780 * Save the original ist values for checking stack pointers during debugging
10781 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(co
10782 */
10783 #define TASK_SIZE PAGE_OFFSET
10784 #define TASK_SIZE_MAX TASK_SIZE
10785 +
10786 +#ifdef CONFIG_PAX_SEGMEXEC
10787 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10788 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10789 +#else
10790 #define STACK_TOP TASK_SIZE
10791 -#define STACK_TOP_MAX STACK_TOP
10792 +#endif
10793 +
10794 +#define STACK_TOP_MAX TASK_SIZE
10795
10796 #define INIT_THREAD { \
10797 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10798 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10799 .vm86_info = NULL, \
10800 .sysenter_cs = __KERNEL_CS, \
10801 .io_bitmap_ptr = NULL, \
10802 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(co
10803 */
10804 #define INIT_TSS { \
10805 .x86_tss = { \
10806 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10807 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10808 .ss0 = __KERNEL_DS, \
10809 .ss1 = __KERNEL_CS, \
10810 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10811 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(co
10812 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10813
10814 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10815 -#define KSTK_TOP(info) \
10816 -({ \
10817 - unsigned long *__ptr = (unsigned long *)(info); \
10818 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10819 -})
10820 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10821
10822 /*
10823 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10824 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(str
10825 #define task_pt_regs(task) \
10826 ({ \
10827 struct pt_regs *__regs__; \
10828 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10829 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10830 __regs__ - 1; \
10831 })
10832
10833 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(str
10834 /*
10835 * User space process size. 47bits minus one guard page.
10836 */
10837 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10838 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10839
10840 /* This decides where the kernel will search for a free chunk of vm
10841 * space during mmap's.
10842 */
10843 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10844 - 0xc0000000 : 0xFFFFe000)
10845 + 0xc0000000 : 0xFFFFf000)
10846
10847 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10848 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10849 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(str
10850 #define STACK_TOP_MAX TASK_SIZE_MAX
10851
10852 #define INIT_THREAD { \
10853 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10854 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10855 }
10856
10857 #define INIT_TSS { \
10858 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10859 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10860 }
10861
10862 /*
10863 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs
10864 */
10865 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
10866
10867 +#ifdef CONFIG_PAX_SEGMEXEC
10868 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
10869 +#endif
10870 +
10871 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
10872
10873 /* Get/set a process' ability to use the timestamp counter instruction */
10874 diff -urNp linux-2.6.39.1/arch/x86/include/asm/ptrace.h linux-2.6.39.1/arch/x86/include/asm/ptrace.h
10875 --- linux-2.6.39.1/arch/x86/include/asm/ptrace.h 2011-05-19 00:06:34.000000000 -0400
10876 +++ linux-2.6.39.1/arch/x86/include/asm/ptrace.h 2011-05-22 19:36:30.000000000 -0400
10877 @@ -152,28 +152,29 @@ static inline unsigned long regs_return_
10878 }
10879
10880 /*
10881 - * user_mode_vm(regs) determines whether a register set came from user mode.
10882 + * user_mode(regs) determines whether a register set came from user mode.
10883 * This is true if V8086 mode was enabled OR if the register set was from
10884 * protected mode with RPL-3 CS value. This tricky test checks that with
10885 * one comparison. Many places in the kernel can bypass this full check
10886 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
10887 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
10888 + * be used.
10889 */
10890 -static inline int user_mode(struct pt_regs *regs)
10891 +static inline int user_mode_novm(struct pt_regs *regs)
10892 {
10893 #ifdef CONFIG_X86_32
10894 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
10895 #else
10896 - return !!(regs->cs & 3);
10897 + return !!(regs->cs & SEGMENT_RPL_MASK);
10898 #endif
10899 }
10900
10901 -static inline int user_mode_vm(struct pt_regs *regs)
10902 +static inline int user_mode(struct pt_regs *regs)
10903 {
10904 #ifdef CONFIG_X86_32
10905 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
10906 USER_RPL;
10907 #else
10908 - return user_mode(regs);
10909 + return user_mode_novm(regs);
10910 #endif
10911 }
10912
10913 diff -urNp linux-2.6.39.1/arch/x86/include/asm/reboot.h linux-2.6.39.1/arch/x86/include/asm/reboot.h
10914 --- linux-2.6.39.1/arch/x86/include/asm/reboot.h 2011-05-19 00:06:34.000000000 -0400
10915 +++ linux-2.6.39.1/arch/x86/include/asm/reboot.h 2011-05-22 19:36:30.000000000 -0400
10916 @@ -6,19 +6,19 @@
10917 struct pt_regs;
10918
10919 struct machine_ops {
10920 - void (*restart)(char *cmd);
10921 - void (*halt)(void);
10922 - void (*power_off)(void);
10923 + void (* __noreturn restart)(char *cmd);
10924 + void (* __noreturn halt)(void);
10925 + void (* __noreturn power_off)(void);
10926 void (*shutdown)(void);
10927 void (*crash_shutdown)(struct pt_regs *);
10928 - void (*emergency_restart)(void);
10929 + void (* __noreturn emergency_restart)(void);
10930 };
10931
10932 extern struct machine_ops machine_ops;
10933
10934 void native_machine_crash_shutdown(struct pt_regs *regs);
10935 void native_machine_shutdown(void);
10936 -void machine_real_restart(unsigned int type);
10937 +void machine_real_restart(unsigned int type) __noreturn;
10938 /* These must match dispatch_table in reboot_32.S */
10939 #define MRR_BIOS 0
10940 #define MRR_APM 1
10941 diff -urNp linux-2.6.39.1/arch/x86/include/asm/rwsem.h linux-2.6.39.1/arch/x86/include/asm/rwsem.h
10942 --- linux-2.6.39.1/arch/x86/include/asm/rwsem.h 2011-05-19 00:06:34.000000000 -0400
10943 +++ linux-2.6.39.1/arch/x86/include/asm/rwsem.h 2011-05-22 19:36:30.000000000 -0400
10944 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw
10945 {
10946 asm volatile("# beginning down_read\n\t"
10947 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10948 +
10949 +#ifdef CONFIG_PAX_REFCOUNT
10950 + "jno 0f\n"
10951 + LOCK_PREFIX _ASM_DEC "(%1)\n"
10952 + "int $4\n0:\n"
10953 + _ASM_EXTABLE(0b, 0b)
10954 +#endif
10955 +
10956 /* adds 0x00000001 */
10957 " jns 1f\n"
10958 " call call_rwsem_down_read_failed\n"
10959 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(st
10960 "1:\n\t"
10961 " mov %1,%2\n\t"
10962 " add %3,%2\n\t"
10963 +
10964 +#ifdef CONFIG_PAX_REFCOUNT
10965 + "jno 0f\n"
10966 + "sub %3,%2\n"
10967 + "int $4\n0:\n"
10968 + _ASM_EXTABLE(0b, 0b)
10969 +#endif
10970 +
10971 " jle 2f\n\t"
10972 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10973 " jnz 1b\n\t"
10974 @@ -104,6 +120,14 @@ static inline void __down_write_nested(s
10975 long tmp;
10976 asm volatile("# beginning down_write\n\t"
10977 LOCK_PREFIX " xadd %1,(%2)\n\t"
10978 +
10979 +#ifdef CONFIG_PAX_REFCOUNT
10980 + "jno 0f\n"
10981 + "mov %1,(%2)\n"
10982 + "int $4\n0:\n"
10983 + _ASM_EXTABLE(0b, 0b)
10984 +#endif
10985 +
10986 /* adds 0xffff0001, returns the old value */
10987 " test %1,%1\n\t"
10988 /* was the count 0 before? */
10989 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_s
10990 long tmp;
10991 asm volatile("# beginning __up_read\n\t"
10992 LOCK_PREFIX " xadd %1,(%2)\n\t"
10993 +
10994 +#ifdef CONFIG_PAX_REFCOUNT
10995 + "jno 0f\n"
10996 + "mov %1,(%2)\n"
10997 + "int $4\n0:\n"
10998 + _ASM_EXTABLE(0b, 0b)
10999 +#endif
11000 +
11001 /* subtracts 1, returns the old value */
11002 " jns 1f\n\t"
11003 " call call_rwsem_wake\n" /* expects old value in %edx */
11004 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_
11005 long tmp;
11006 asm volatile("# beginning __up_write\n\t"
11007 LOCK_PREFIX " xadd %1,(%2)\n\t"
11008 +
11009 +#ifdef CONFIG_PAX_REFCOUNT
11010 + "jno 0f\n"
11011 + "mov %1,(%2)\n"
11012 + "int $4\n0:\n"
11013 + _ASM_EXTABLE(0b, 0b)
11014 +#endif
11015 +
11016 /* subtracts 0xffff0001, returns the old value */
11017 " jns 1f\n\t"
11018 " call call_rwsem_wake\n" /* expects old value in %edx */
11019 @@ -176,6 +216,14 @@ static inline void __downgrade_write(str
11020 {
11021 asm volatile("# beginning __downgrade_write\n\t"
11022 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11023 +
11024 +#ifdef CONFIG_PAX_REFCOUNT
11025 + "jno 0f\n"
11026 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11027 + "int $4\n0:\n"
11028 + _ASM_EXTABLE(0b, 0b)
11029 +#endif
11030 +
11031 /*
11032 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11033 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11034 @@ -194,7 +242,15 @@ static inline void __downgrade_write(str
11035 */
11036 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11037 {
11038 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11039 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11040 +
11041 +#ifdef CONFIG_PAX_REFCOUNT
11042 + "jno 0f\n"
11043 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11044 + "int $4\n0:\n"
11045 + _ASM_EXTABLE(0b, 0b)
11046 +#endif
11047 +
11048 : "+m" (sem->count)
11049 : "er" (delta));
11050 }
11051 @@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(l
11052 {
11053 long tmp = delta;
11054
11055 - asm volatile(LOCK_PREFIX "xadd %0,%1"
11056 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11057 +
11058 +#ifdef CONFIG_PAX_REFCOUNT
11059 + "jno 0f\n"
11060 + "mov %0,%1\n"
11061 + "int $4\n0:\n"
11062 + _ASM_EXTABLE(0b, 0b)
11063 +#endif
11064 +
11065 : "+r" (tmp), "+m" (sem->count)
11066 : : "memory");
11067
11068 diff -urNp linux-2.6.39.1/arch/x86/include/asm/segment.h linux-2.6.39.1/arch/x86/include/asm/segment.h
11069 --- linux-2.6.39.1/arch/x86/include/asm/segment.h 2011-05-19 00:06:34.000000000 -0400
11070 +++ linux-2.6.39.1/arch/x86/include/asm/segment.h 2011-05-22 19:36:30.000000000 -0400
11071 @@ -64,8 +64,8 @@
11072 * 26 - ESPFIX small SS
11073 * 27 - per-cpu [ offset to per-cpu data area ]
11074 * 28 - stack_canary-20 [ for stack protector ]
11075 - * 29 - unused
11076 - * 30 - unused
11077 + * 29 - PCI BIOS CS
11078 + * 30 - PCI BIOS DS
11079 * 31 - TSS for double fault handler
11080 */
11081 #define GDT_ENTRY_TLS_MIN 6
11082 @@ -79,6 +79,8 @@
11083
11084 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11085
11086 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11087 +
11088 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11089
11090 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11091 @@ -104,6 +106,12 @@
11092 #define __KERNEL_STACK_CANARY 0
11093 #endif
11094
11095 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11096 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11097 +
11098 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11099 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11100 +
11101 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11102
11103 /*
11104 @@ -141,7 +149,7 @@
11105 */
11106
11107 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11108 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11109 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11110
11111
11112 #else
11113 @@ -165,6 +173,8 @@
11114 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11115 #define __USER32_DS __USER_DS
11116
11117 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11118 +
11119 #define GDT_ENTRY_TSS 8 /* needs two entries */
11120 #define GDT_ENTRY_LDT 10 /* needs two entries */
11121 #define GDT_ENTRY_TLS_MIN 12
11122 @@ -185,6 +195,7 @@
11123 #endif
11124
11125 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11126 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11127 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11128 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11129 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11130 diff -urNp linux-2.6.39.1/arch/x86/include/asm/smp.h linux-2.6.39.1/arch/x86/include/asm/smp.h
11131 --- linux-2.6.39.1/arch/x86/include/asm/smp.h 2011-05-19 00:06:34.000000000 -0400
11132 +++ linux-2.6.39.1/arch/x86/include/asm/smp.h 2011-05-22 19:36:30.000000000 -0400
11133 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_
11134 /* cpus sharing the last level cache: */
11135 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11136 DECLARE_PER_CPU(u16, cpu_llc_id);
11137 -DECLARE_PER_CPU(int, cpu_number);
11138 +DECLARE_PER_CPU(unsigned int, cpu_number);
11139
11140 static inline struct cpumask *cpu_sibling_mask(int cpu)
11141 {
11142 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitd
11143 extern int safe_smp_processor_id(void);
11144
11145 #elif defined(CONFIG_X86_64_SMP)
11146 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11147 -
11148 -#define stack_smp_processor_id() \
11149 -({ \
11150 - struct thread_info *ti; \
11151 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11152 - ti->cpu; \
11153 -})
11154 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11155 +#define stack_smp_processor_id() raw_smp_processor_id()
11156 #define safe_smp_processor_id() smp_processor_id()
11157
11158 #endif
11159 diff -urNp linux-2.6.39.1/arch/x86/include/asm/spinlock.h linux-2.6.39.1/arch/x86/include/asm/spinlock.h
11160 --- linux-2.6.39.1/arch/x86/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
11161 +++ linux-2.6.39.1/arch/x86/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
11162 @@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
11163 static inline void arch_read_lock(arch_rwlock_t *rw)
11164 {
11165 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11166 +
11167 +#ifdef CONFIG_PAX_REFCOUNT
11168 + "jno 0f\n"
11169 + LOCK_PREFIX " addl $1,(%0)\n"
11170 + "int $4\n0:\n"
11171 + _ASM_EXTABLE(0b, 0b)
11172 +#endif
11173 +
11174 "jns 1f\n"
11175 "call __read_lock_failed\n\t"
11176 "1:\n"
11177 @@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
11178 static inline void arch_write_lock(arch_rwlock_t *rw)
11179 {
11180 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11181 +
11182 +#ifdef CONFIG_PAX_REFCOUNT
11183 + "jno 0f\n"
11184 + LOCK_PREFIX " addl %1,(%0)\n"
11185 + "int $4\n0:\n"
11186 + _ASM_EXTABLE(0b, 0b)
11187 +#endif
11188 +
11189 "jz 1f\n"
11190 "call __write_lock_failed\n\t"
11191 "1:\n"
11192 @@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
11193
11194 static inline void arch_read_unlock(arch_rwlock_t *rw)
11195 {
11196 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11197 + asm volatile(LOCK_PREFIX "incl %0\n"
11198 +
11199 +#ifdef CONFIG_PAX_REFCOUNT
11200 + "jno 0f\n"
11201 + LOCK_PREFIX "decl %0\n"
11202 + "int $4\n0:\n"
11203 + _ASM_EXTABLE(0b, 0b)
11204 +#endif
11205 +
11206 + :"+m" (rw->lock) : : "memory");
11207 }
11208
11209 static inline void arch_write_unlock(arch_rwlock_t *rw)
11210 {
11211 - asm volatile(LOCK_PREFIX "addl %1, %0"
11212 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
11213 +
11214 +#ifdef CONFIG_PAX_REFCOUNT
11215 + "jno 0f\n"
11216 + LOCK_PREFIX "subl %1, %0\n"
11217 + "int $4\n0:\n"
11218 + _ASM_EXTABLE(0b, 0b)
11219 +#endif
11220 +
11221 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11222 }
11223
11224 diff -urNp linux-2.6.39.1/arch/x86/include/asm/stackprotector.h linux-2.6.39.1/arch/x86/include/asm/stackprotector.h
11225 --- linux-2.6.39.1/arch/x86/include/asm/stackprotector.h 2011-05-19 00:06:34.000000000 -0400
11226 +++ linux-2.6.39.1/arch/x86/include/asm/stackprotector.h 2011-05-22 19:36:30.000000000 -0400
11227 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
11228
11229 static inline void load_stack_canary_segment(void)
11230 {
11231 -#ifdef CONFIG_X86_32
11232 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11233 asm volatile ("mov %0, %%gs" : : "r" (0));
11234 #endif
11235 }
11236 diff -urNp linux-2.6.39.1/arch/x86/include/asm/stacktrace.h linux-2.6.39.1/arch/x86/include/asm/stacktrace.h
11237 --- linux-2.6.39.1/arch/x86/include/asm/stacktrace.h 2011-05-19 00:06:34.000000000 -0400
11238 +++ linux-2.6.39.1/arch/x86/include/asm/stacktrace.h 2011-05-22 19:36:30.000000000 -0400
11239 @@ -11,28 +11,20 @@
11240
11241 extern int kstack_depth_to_print;
11242
11243 -struct thread_info;
11244 +struct task_struct;
11245 struct stacktrace_ops;
11246
11247 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11248 - unsigned long *stack,
11249 - unsigned long bp,
11250 - const struct stacktrace_ops *ops,
11251 - void *data,
11252 - unsigned long *end,
11253 - int *graph);
11254 -
11255 -extern unsigned long
11256 -print_context_stack(struct thread_info *tinfo,
11257 - unsigned long *stack, unsigned long bp,
11258 - const struct stacktrace_ops *ops, void *data,
11259 - unsigned long *end, int *graph);
11260 -
11261 -extern unsigned long
11262 -print_context_stack_bp(struct thread_info *tinfo,
11263 - unsigned long *stack, unsigned long bp,
11264 - const struct stacktrace_ops *ops, void *data,
11265 - unsigned long *end, int *graph);
11266 +typedef unsigned long walk_stack_t(struct task_struct *task,
11267 + void *stack_start,
11268 + unsigned long *stack,
11269 + unsigned long bp,
11270 + const struct stacktrace_ops *ops,
11271 + void *data,
11272 + unsigned long *end,
11273 + int *graph);
11274 +
11275 +extern walk_stack_t print_context_stack;
11276 +extern walk_stack_t print_context_stack_bp;
11277
11278 /* Generic stack tracer with callbacks */
11279
11280 @@ -43,7 +35,7 @@ struct stacktrace_ops {
11281 void (*address)(void *data, unsigned long address, int reliable);
11282 /* On negative return stop dumping */
11283 int (*stack)(void *data, char *name);
11284 - walk_stack_t walk_stack;
11285 + walk_stack_t *walk_stack;
11286 };
11287
11288 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11289 diff -urNp linux-2.6.39.1/arch/x86/include/asm/system.h linux-2.6.39.1/arch/x86/include/asm/system.h
11290 --- linux-2.6.39.1/arch/x86/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
11291 +++ linux-2.6.39.1/arch/x86/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
11292 @@ -129,7 +129,7 @@ do { \
11293 "call __switch_to\n\t" \
11294 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11295 __switch_canary \
11296 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11297 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11298 "movq %%rax,%%rdi\n\t" \
11299 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11300 "jnz ret_from_fork\n\t" \
11301 @@ -140,7 +140,7 @@ do { \
11302 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11303 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11304 [_tif_fork] "i" (_TIF_FORK), \
11305 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11306 + [thread_info] "m" (current_tinfo), \
11307 [current_task] "m" (current_task) \
11308 __switch_canary_iparam \
11309 : "memory", "cc" __EXTRA_CLOBBER)
11310 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
11311 {
11312 unsigned long __limit;
11313 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11314 - return __limit + 1;
11315 + return __limit;
11316 }
11317
11318 static inline void native_clts(void)
11319 @@ -340,12 +340,12 @@ void enable_hlt(void);
11320
11321 void cpu_idle_wait(void);
11322
11323 -extern unsigned long arch_align_stack(unsigned long sp);
11324 +#define arch_align_stack(x) ((x) & ~0xfUL)
11325 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11326
11327 void default_idle(void);
11328
11329 -void stop_this_cpu(void *dummy);
11330 +void stop_this_cpu(void *dummy) __noreturn;
11331
11332 /*
11333 * Force strict CPU ordering.
11334 diff -urNp linux-2.6.39.1/arch/x86/include/asm/thread_info.h linux-2.6.39.1/arch/x86/include/asm/thread_info.h
11335 --- linux-2.6.39.1/arch/x86/include/asm/thread_info.h 2011-05-19 00:06:34.000000000 -0400
11336 +++ linux-2.6.39.1/arch/x86/include/asm/thread_info.h 2011-05-22 19:36:30.000000000 -0400
11337 @@ -10,6 +10,7 @@
11338 #include <linux/compiler.h>
11339 #include <asm/page.h>
11340 #include <asm/types.h>
11341 +#include <asm/percpu.h>
11342
11343 /*
11344 * low level task data that entry.S needs immediate access to
11345 @@ -24,7 +25,6 @@ struct exec_domain;
11346 #include <asm/atomic.h>
11347
11348 struct thread_info {
11349 - struct task_struct *task; /* main task structure */
11350 struct exec_domain *exec_domain; /* execution domain */
11351 __u32 flags; /* low level flags */
11352 __u32 status; /* thread synchronous flags */
11353 @@ -34,18 +34,12 @@ struct thread_info {
11354 mm_segment_t addr_limit;
11355 struct restart_block restart_block;
11356 void __user *sysenter_return;
11357 -#ifdef CONFIG_X86_32
11358 - unsigned long previous_esp; /* ESP of the previous stack in
11359 - case of nested (IRQ) stacks
11360 - */
11361 - __u8 supervisor_stack[0];
11362 -#endif
11363 + unsigned long lowest_stack;
11364 int uaccess_err;
11365 };
11366
11367 -#define INIT_THREAD_INFO(tsk) \
11368 +#define INIT_THREAD_INFO \
11369 { \
11370 - .task = &tsk, \
11371 .exec_domain = &default_exec_domain, \
11372 .flags = 0, \
11373 .cpu = 0, \
11374 @@ -56,7 +50,7 @@ struct thread_info {
11375 }, \
11376 }
11377
11378 -#define init_thread_info (init_thread_union.thread_info)
11379 +#define init_thread_info (init_thread_union.stack)
11380 #define init_stack (init_thread_union.stack)
11381
11382 #else /* !__ASSEMBLY__ */
11383 @@ -170,6 +164,23 @@ struct thread_info {
11384 ret; \
11385 })
11386
11387 +#ifdef __ASSEMBLY__
11388 +/* how to get the thread information struct from ASM */
11389 +#define GET_THREAD_INFO(reg) \
11390 + mov PER_CPU_VAR(current_tinfo), reg
11391 +
11392 +/* use this one if reg already contains %esp */
11393 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11394 +#else
11395 +/* how to get the thread information struct from C */
11396 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11397 +
11398 +static __always_inline struct thread_info *current_thread_info(void)
11399 +{
11400 + return percpu_read_stable(current_tinfo);
11401 +}
11402 +#endif
11403 +
11404 #ifdef CONFIG_X86_32
11405
11406 #define STACK_WARN (THREAD_SIZE/8)
11407 @@ -180,35 +191,13 @@ struct thread_info {
11408 */
11409 #ifndef __ASSEMBLY__
11410
11411 -
11412 /* how to get the current stack pointer from C */
11413 register unsigned long current_stack_pointer asm("esp") __used;
11414
11415 -/* how to get the thread information struct from C */
11416 -static inline struct thread_info *current_thread_info(void)
11417 -{
11418 - return (struct thread_info *)
11419 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11420 -}
11421 -
11422 -#else /* !__ASSEMBLY__ */
11423 -
11424 -/* how to get the thread information struct from ASM */
11425 -#define GET_THREAD_INFO(reg) \
11426 - movl $-THREAD_SIZE, reg; \
11427 - andl %esp, reg
11428 -
11429 -/* use this one if reg already contains %esp */
11430 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11431 - andl $-THREAD_SIZE, reg
11432 -
11433 #endif
11434
11435 #else /* X86_32 */
11436
11437 -#include <asm/percpu.h>
11438 -#define KERNEL_STACK_OFFSET (5*8)
11439 -
11440 /*
11441 * macros/functions for gaining access to the thread information structure
11442 * preempt_count needs to be 1 initially, until the scheduler is functional.
11443 @@ -216,21 +205,8 @@ static inline struct thread_info *curren
11444 #ifndef __ASSEMBLY__
11445 DECLARE_PER_CPU(unsigned long, kernel_stack);
11446
11447 -static inline struct thread_info *current_thread_info(void)
11448 -{
11449 - struct thread_info *ti;
11450 - ti = (void *)(percpu_read_stable(kernel_stack) +
11451 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11452 - return ti;
11453 -}
11454 -
11455 -#else /* !__ASSEMBLY__ */
11456 -
11457 -/* how to get the thread information struct from ASM */
11458 -#define GET_THREAD_INFO(reg) \
11459 - movq PER_CPU_VAR(kernel_stack),reg ; \
11460 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11461 -
11462 +/* how to get the current stack pointer from C */
11463 +register unsigned long current_stack_pointer asm("rsp") __used;
11464 #endif
11465
11466 #endif /* !X86_32 */
11467 @@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
11468 extern void free_thread_info(struct thread_info *ti);
11469 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11470 #define arch_task_cache_init arch_task_cache_init
11471 +
11472 +#define __HAVE_THREAD_FUNCTIONS
11473 +#define task_thread_info(task) (&(task)->tinfo)
11474 +#define task_stack_page(task) ((task)->stack)
11475 +#define setup_thread_stack(p, org) do {} while (0)
11476 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11477 +
11478 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11479 +extern struct task_struct *alloc_task_struct_node(int node);
11480 +extern void free_task_struct(struct task_struct *);
11481 +
11482 #endif
11483 #endif /* _ASM_X86_THREAD_INFO_H */
11484 diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h
11485 --- linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
11486 +++ linux-2.6.39.1/arch/x86/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
11487 @@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
11488 static __always_inline unsigned long __must_check
11489 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11490 {
11491 + pax_track_stack();
11492 +
11493 + if ((long)n < 0)
11494 + return n;
11495 +
11496 if (__builtin_constant_p(n)) {
11497 unsigned long ret;
11498
11499 @@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
11500 return ret;
11501 }
11502 }
11503 + if (!__builtin_constant_p(n))
11504 + check_object_size(from, n, true);
11505 return __copy_to_user_ll(to, from, n);
11506 }
11507
11508 @@ -83,12 +90,16 @@ static __always_inline unsigned long __m
11509 __copy_to_user(void __user *to, const void *from, unsigned long n)
11510 {
11511 might_fault();
11512 +
11513 return __copy_to_user_inatomic(to, from, n);
11514 }
11515
11516 static __always_inline unsigned long
11517 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11518 {
11519 + if ((long)n < 0)
11520 + return n;
11521 +
11522 /* Avoid zeroing the tail if the copy fails..
11523 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11524 * but as the zeroing behaviour is only significant when n is not
11525 @@ -138,6 +149,12 @@ static __always_inline unsigned long
11526 __copy_from_user(void *to, const void __user *from, unsigned long n)
11527 {
11528 might_fault();
11529 +
11530 + pax_track_stack();
11531 +
11532 + if ((long)n < 0)
11533 + return n;
11534 +
11535 if (__builtin_constant_p(n)) {
11536 unsigned long ret;
11537
11538 @@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
11539 return ret;
11540 }
11541 }
11542 + if (!__builtin_constant_p(n))
11543 + check_object_size(to, n, false);
11544 return __copy_from_user_ll(to, from, n);
11545 }
11546
11547 @@ -160,6 +179,10 @@ static __always_inline unsigned long __c
11548 const void __user *from, unsigned long n)
11549 {
11550 might_fault();
11551 +
11552 + if ((long)n < 0)
11553 + return n;
11554 +
11555 if (__builtin_constant_p(n)) {
11556 unsigned long ret;
11557
11558 @@ -182,15 +205,19 @@ static __always_inline unsigned long
11559 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11560 unsigned long n)
11561 {
11562 - return __copy_from_user_ll_nocache_nozero(to, from, n);
11563 -}
11564 + if ((long)n < 0)
11565 + return n;
11566
11567 -unsigned long __must_check copy_to_user(void __user *to,
11568 - const void *from, unsigned long n);
11569 -unsigned long __must_check _copy_from_user(void *to,
11570 - const void __user *from,
11571 - unsigned long n);
11572 + return __copy_from_user_ll_nocache_nozero(to, from, n);
11573 +}
11574
11575 +extern void copy_to_user_overflow(void)
11576 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11577 + __compiletime_error("copy_to_user() buffer size is not provably correct")
11578 +#else
11579 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
11580 +#endif
11581 +;
11582
11583 extern void copy_from_user_overflow(void)
11584 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11585 @@ -200,17 +227,61 @@ extern void copy_from_user_overflow(void
11586 #endif
11587 ;
11588
11589 -static inline unsigned long __must_check copy_from_user(void *to,
11590 - const void __user *from,
11591 - unsigned long n)
11592 +/**
11593 + * copy_to_user: - Copy a block of data into user space.
11594 + * @to: Destination address, in user space.
11595 + * @from: Source address, in kernel space.
11596 + * @n: Number of bytes to copy.
11597 + *
11598 + * Context: User context only. This function may sleep.
11599 + *
11600 + * Copy data from kernel space to user space.
11601 + *
11602 + * Returns number of bytes that could not be copied.
11603 + * On success, this will be zero.
11604 + */
11605 +static inline unsigned long __must_check
11606 +copy_to_user(void __user *to, const void *from, unsigned long n)
11607 +{
11608 + int sz = __compiletime_object_size(from);
11609 +
11610 + if (unlikely(sz != -1 && sz < n))
11611 + copy_to_user_overflow();
11612 + else if (access_ok(VERIFY_WRITE, to, n))
11613 + n = __copy_to_user(to, from, n);
11614 + return n;
11615 +}
11616 +
11617 +/**
11618 + * copy_from_user: - Copy a block of data from user space.
11619 + * @to: Destination address, in kernel space.
11620 + * @from: Source address, in user space.
11621 + * @n: Number of bytes to copy.
11622 + *
11623 + * Context: User context only. This function may sleep.
11624 + *
11625 + * Copy data from user space to kernel space.
11626 + *
11627 + * Returns number of bytes that could not be copied.
11628 + * On success, this will be zero.
11629 + *
11630 + * If some data could not be copied, this function will pad the copied
11631 + * data to the requested size using zero bytes.
11632 + */
11633 +static inline unsigned long __must_check
11634 +copy_from_user(void *to, const void __user *from, unsigned long n)
11635 {
11636 int sz = __compiletime_object_size(to);
11637
11638 - if (likely(sz == -1 || sz >= n))
11639 - n = _copy_from_user(to, from, n);
11640 - else
11641 + if (unlikely(sz != -1 && sz < n))
11642 copy_from_user_overflow();
11643 -
11644 + else if (access_ok(VERIFY_READ, from, n))
11645 + n = __copy_from_user(to, from, n);
11646 + else if ((long)n > 0) {
11647 + if (!__builtin_constant_p(n))
11648 + check_object_size(to, n, false);
11649 + memset(to, 0, n);
11650 + }
11651 return n;
11652 }
11653
11654 diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h
11655 --- linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
11656 +++ linux-2.6.39.1/arch/x86/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
11657 @@ -11,6 +11,9 @@
11658 #include <asm/alternative.h>
11659 #include <asm/cpufeature.h>
11660 #include <asm/page.h>
11661 +#include <asm/pgtable.h>
11662 +
11663 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
11664
11665 /*
11666 * Copy To/From Userspace
11667 @@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
11668 return ret;
11669 }
11670
11671 -__must_check unsigned long
11672 -_copy_to_user(void __user *to, const void *from, unsigned len);
11673 -__must_check unsigned long
11674 -_copy_from_user(void *to, const void __user *from, unsigned len);
11675 +static __always_inline __must_check unsigned long
11676 +__copy_to_user(void __user *to, const void *from, unsigned len);
11677 +static __always_inline __must_check unsigned long
11678 +__copy_from_user(void *to, const void __user *from, unsigned len);
11679 __must_check unsigned long
11680 copy_in_user(void __user *to, const void __user *from, unsigned len);
11681
11682 static inline unsigned long __must_check copy_from_user(void *to,
11683 const void __user *from,
11684 - unsigned long n)
11685 + unsigned n)
11686 {
11687 - int sz = __compiletime_object_size(to);
11688 -
11689 might_fault();
11690 - if (likely(sz == -1 || sz >= n))
11691 - n = _copy_from_user(to, from, n);
11692 -#ifdef CONFIG_DEBUG_VM
11693 - else
11694 - WARN(1, "Buffer overflow detected!\n");
11695 -#endif
11696 +
11697 + if (access_ok(VERIFY_READ, from, n))
11698 + n = __copy_from_user(to, from, n);
11699 + else if ((int)n > 0) {
11700 + if (!__builtin_constant_p(n))
11701 + check_object_size(to, n, false);
11702 + memset(to, 0, n);
11703 + }
11704 return n;
11705 }
11706
11707 @@ -65,110 +68,198 @@ int copy_to_user(void __user *dst, const
11708 {
11709 might_fault();
11710
11711 - return _copy_to_user(dst, src, size);
11712 + if (access_ok(VERIFY_WRITE, dst, size))
11713 + size = __copy_to_user(dst, src, size);
11714 + return size;
11715 }
11716
11717 static __always_inline __must_check
11718 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
11719 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
11720 {
11721 - int ret = 0;
11722 + int sz = __compiletime_object_size(dst);
11723 + unsigned ret = 0;
11724
11725 might_fault();
11726 - if (!__builtin_constant_p(size))
11727 - return copy_user_generic(dst, (__force void *)src, size);
11728 +
11729 + pax_track_stack();
11730 +
11731 + if ((int)size < 0)
11732 + return size;
11733 +
11734 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11735 + if (!__access_ok(VERIFY_READ, src, size))
11736 + return size;
11737 +#endif
11738 +
11739 + if (unlikely(sz != -1 && sz < size)) {
11740 +#ifdef CONFIG_DEBUG_VM
11741 + WARN(1, "Buffer overflow detected!\n");
11742 +#endif
11743 + return size;
11744 + }
11745 +
11746 + if (!__builtin_constant_p(size)) {
11747 + check_object_size(dst, size, false);
11748 +
11749 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11750 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11751 + src += PAX_USER_SHADOW_BASE;
11752 +#endif
11753 +
11754 + return copy_user_generic(dst, (__force const void *)src, size);
11755 + }
11756 switch (size) {
11757 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11758 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11759 ret, "b", "b", "=q", 1);
11760 return ret;
11761 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11762 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11763 ret, "w", "w", "=r", 2);
11764 return ret;
11765 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11766 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11767 ret, "l", "k", "=r", 4);
11768 return ret;
11769 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11770 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11771 ret, "q", "", "=r", 8);
11772 return ret;
11773 case 10:
11774 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11775 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11776 ret, "q", "", "=r", 10);
11777 if (unlikely(ret))
11778 return ret;
11779 __get_user_asm(*(u16 *)(8 + (char *)dst),
11780 - (u16 __user *)(8 + (char __user *)src),
11781 + (const u16 __user *)(8 + (const char __user *)src),
11782 ret, "w", "w", "=r", 2);
11783 return ret;
11784 case 16:
11785 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11786 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11787 ret, "q", "", "=r", 16);
11788 if (unlikely(ret))
11789 return ret;
11790 __get_user_asm(*(u64 *)(8 + (char *)dst),
11791 - (u64 __user *)(8 + (char __user *)src),
11792 + (const u64 __user *)(8 + (const char __user *)src),
11793 ret, "q", "", "=r", 8);
11794 return ret;
11795 default:
11796 - return copy_user_generic(dst, (__force void *)src, size);
11797 +
11798 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11799 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11800 + src += PAX_USER_SHADOW_BASE;
11801 +#endif
11802 +
11803 + return copy_user_generic(dst, (__force const void *)src, size);
11804 }
11805 }
11806
11807 static __always_inline __must_check
11808 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11809 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
11810 {
11811 - int ret = 0;
11812 + int sz = __compiletime_object_size(src);
11813 + unsigned ret = 0;
11814
11815 might_fault();
11816 - if (!__builtin_constant_p(size))
11817 +
11818 + pax_track_stack();
11819 +
11820 + if ((int)size < 0)
11821 + return size;
11822 +
11823 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11824 + if (!__access_ok(VERIFY_WRITE, dst, size))
11825 + return size;
11826 +#endif
11827 +
11828 + if (unlikely(sz != -1 && sz < size)) {
11829 +#ifdef CONFIG_DEBUG_VM
11830 + WARN(1, "Buffer overflow detected!\n");
11831 +#endif
11832 + return size;
11833 + }
11834 +
11835 + if (!__builtin_constant_p(size)) {
11836 + check_object_size(src, size, true);
11837 +
11838 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11839 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11840 + dst += PAX_USER_SHADOW_BASE;
11841 +#endif
11842 +
11843 return copy_user_generic((__force void *)dst, src, size);
11844 + }
11845 switch (size) {
11846 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11847 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11848 ret, "b", "b", "iq", 1);
11849 return ret;
11850 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11851 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11852 ret, "w", "w", "ir", 2);
11853 return ret;
11854 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11855 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11856 ret, "l", "k", "ir", 4);
11857 return ret;
11858 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11859 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11860 ret, "q", "", "er", 8);
11861 return ret;
11862 case 10:
11863 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11864 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11865 ret, "q", "", "er", 10);
11866 if (unlikely(ret))
11867 return ret;
11868 asm("":::"memory");
11869 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11870 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11871 ret, "w", "w", "ir", 2);
11872 return ret;
11873 case 16:
11874 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11875 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11876 ret, "q", "", "er", 16);
11877 if (unlikely(ret))
11878 return ret;
11879 asm("":::"memory");
11880 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11881 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11882 ret, "q", "", "er", 8);
11883 return ret;
11884 default:
11885 +
11886 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11887 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11888 + dst += PAX_USER_SHADOW_BASE;
11889 +#endif
11890 +
11891 return copy_user_generic((__force void *)dst, src, size);
11892 }
11893 }
11894
11895 static __always_inline __must_check
11896 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11897 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11898 {
11899 - int ret = 0;
11900 + unsigned ret = 0;
11901
11902 might_fault();
11903 - if (!__builtin_constant_p(size))
11904 +
11905 + if ((int)size < 0)
11906 + return size;
11907 +
11908 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11909 + if (!__access_ok(VERIFY_READ, src, size))
11910 + return size;
11911 + if (!__access_ok(VERIFY_WRITE, dst, size))
11912 + return size;
11913 +#endif
11914 +
11915 + if (!__builtin_constant_p(size)) {
11916 +
11917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11918 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11919 + src += PAX_USER_SHADOW_BASE;
11920 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11921 + dst += PAX_USER_SHADOW_BASE;
11922 +#endif
11923 +
11924 return copy_user_generic((__force void *)dst,
11925 - (__force void *)src, size);
11926 + (__force const void *)src, size);
11927 + }
11928 switch (size) {
11929 case 1: {
11930 u8 tmp;
11931 - __get_user_asm(tmp, (u8 __user *)src,
11932 + __get_user_asm(tmp, (const u8 __user *)src,
11933 ret, "b", "b", "=q", 1);
11934 if (likely(!ret))
11935 __put_user_asm(tmp, (u8 __user *)dst,
11936 @@ -177,7 +268,7 @@ int __copy_in_user(void __user *dst, con
11937 }
11938 case 2: {
11939 u16 tmp;
11940 - __get_user_asm(tmp, (u16 __user *)src,
11941 + __get_user_asm(tmp, (const u16 __user *)src,
11942 ret, "w", "w", "=r", 2);
11943 if (likely(!ret))
11944 __put_user_asm(tmp, (u16 __user *)dst,
11945 @@ -187,7 +278,7 @@ int __copy_in_user(void __user *dst, con
11946
11947 case 4: {
11948 u32 tmp;
11949 - __get_user_asm(tmp, (u32 __user *)src,
11950 + __get_user_asm(tmp, (const u32 __user *)src,
11951 ret, "l", "k", "=r", 4);
11952 if (likely(!ret))
11953 __put_user_asm(tmp, (u32 __user *)dst,
11954 @@ -196,7 +287,7 @@ int __copy_in_user(void __user *dst, con
11955 }
11956 case 8: {
11957 u64 tmp;
11958 - __get_user_asm(tmp, (u64 __user *)src,
11959 + __get_user_asm(tmp, (const u64 __user *)src,
11960 ret, "q", "", "=r", 8);
11961 if (likely(!ret))
11962 __put_user_asm(tmp, (u64 __user *)dst,
11963 @@ -204,8 +295,16 @@ int __copy_in_user(void __user *dst, con
11964 return ret;
11965 }
11966 default:
11967 +
11968 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11969 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11970 + src += PAX_USER_SHADOW_BASE;
11971 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11972 + dst += PAX_USER_SHADOW_BASE;
11973 +#endif
11974 +
11975 return copy_user_generic((__force void *)dst,
11976 - (__force void *)src, size);
11977 + (__force const void *)src, size);
11978 }
11979 }
11980
11981 @@ -222,33 +321,72 @@ __must_check unsigned long __clear_user(
11982 static __must_check __always_inline int
11983 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11984 {
11985 + pax_track_stack();
11986 +
11987 + if ((int)size < 0)
11988 + return size;
11989 +
11990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11991 + if (!__access_ok(VERIFY_READ, src, size))
11992 + return size;
11993 +
11994 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11995 + src += PAX_USER_SHADOW_BASE;
11996 +#endif
11997 +
11998 return copy_user_generic(dst, (__force const void *)src, size);
11999 }
12000
12001 -static __must_check __always_inline int
12002 +static __must_check __always_inline unsigned long
12003 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12004 {
12005 + if ((int)size < 0)
12006 + return size;
12007 +
12008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12009 + if (!__access_ok(VERIFY_WRITE, dst, size))
12010 + return size;
12011 +
12012 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12013 + dst += PAX_USER_SHADOW_BASE;
12014 +#endif
12015 +
12016 return copy_user_generic((__force void *)dst, src, size);
12017 }
12018
12019 -extern long __copy_user_nocache(void *dst, const void __user *src,
12020 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12021 unsigned size, int zerorest);
12022
12023 -static inline int
12024 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12025 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12026 {
12027 might_sleep();
12028 +
12029 + if ((int)size < 0)
12030 + return size;
12031 +
12032 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12033 + if (!__access_ok(VERIFY_READ, src, size))
12034 + return size;
12035 +#endif
12036 +
12037 return __copy_user_nocache(dst, src, size, 1);
12038 }
12039
12040 -static inline int
12041 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12042 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12043 unsigned size)
12044 {
12045 + if ((int)size < 0)
12046 + return size;
12047 +
12048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12049 + if (!__access_ok(VERIFY_READ, src, size))
12050 + return size;
12051 +#endif
12052 +
12053 return __copy_user_nocache(dst, src, size, 0);
12054 }
12055
12056 -unsigned long
12057 +extern unsigned long
12058 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12059
12060 #endif /* _ASM_X86_UACCESS_64_H */
12061 diff -urNp linux-2.6.39.1/arch/x86/include/asm/uaccess.h linux-2.6.39.1/arch/x86/include/asm/uaccess.h
12062 --- linux-2.6.39.1/arch/x86/include/asm/uaccess.h 2011-06-03 00:04:13.000000000 -0400
12063 +++ linux-2.6.39.1/arch/x86/include/asm/uaccess.h 2011-06-03 00:32:04.000000000 -0400
12064 @@ -8,12 +8,15 @@
12065 #include <linux/thread_info.h>
12066 #include <linux/prefetch.h>
12067 #include <linux/string.h>
12068 +#include <linux/sched.h>
12069 #include <asm/asm.h>
12070 #include <asm/page.h>
12071
12072 #define VERIFY_READ 0
12073 #define VERIFY_WRITE 1
12074
12075 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12076 +
12077 /*
12078 * The fs value determines whether argument validity checking should be
12079 * performed or not. If get_fs() == USER_DS, checking is performed, with
12080 @@ -29,7 +32,12 @@
12081
12082 #define get_ds() (KERNEL_DS)
12083 #define get_fs() (current_thread_info()->addr_limit)
12084 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12085 +void __set_fs(mm_segment_t x);
12086 +void set_fs(mm_segment_t x);
12087 +#else
12088 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12089 +#endif
12090
12091 #define segment_eq(a, b) ((a).seg == (b).seg)
12092
12093 @@ -77,7 +85,33 @@
12094 * checks that the pointer is in the user space range - after calling
12095 * this function, memory access functions may still return -EFAULT.
12096 */
12097 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12098 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12099 +#define access_ok(type, addr, size) \
12100 +({ \
12101 + long __size = size; \
12102 + unsigned long __addr = (unsigned long)addr; \
12103 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12104 + unsigned long __end_ao = __addr + __size - 1; \
12105 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12106 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12107 + while(__addr_ao <= __end_ao) { \
12108 + char __c_ao; \
12109 + __addr_ao += PAGE_SIZE; \
12110 + if (__size > PAGE_SIZE) \
12111 + cond_resched(); \
12112 + if (__get_user(__c_ao, (char __user *)__addr)) \
12113 + break; \
12114 + if (type != VERIFY_WRITE) { \
12115 + __addr = __addr_ao; \
12116 + continue; \
12117 + } \
12118 + if (__put_user(__c_ao, (char __user *)__addr)) \
12119 + break; \
12120 + __addr = __addr_ao; \
12121 + } \
12122 + } \
12123 + __ret_ao; \
12124 +})
12125
12126 /*
12127 * The exception table consists of pairs of addresses: the first is the
12128 @@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12129 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12130 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12131
12132 -
12133 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12134 +#define __copyuser_seg "gs;"
12135 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12136 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12137 +#else
12138 +#define __copyuser_seg
12139 +#define __COPYUSER_SET_ES
12140 +#define __COPYUSER_RESTORE_ES
12141 +#endif
12142
12143 #ifdef CONFIG_X86_32
12144 #define __put_user_asm_u64(x, addr, err, errret) \
12145 - asm volatile("1: movl %%eax,0(%2)\n" \
12146 - "2: movl %%edx,4(%2)\n" \
12147 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12148 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12149 "3:\n" \
12150 ".section .fixup,\"ax\"\n" \
12151 "4: movl %3,%0\n" \
12152 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12153 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12154
12155 #define __put_user_asm_ex_u64(x, addr) \
12156 - asm volatile("1: movl %%eax,0(%1)\n" \
12157 - "2: movl %%edx,4(%1)\n" \
12158 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12159 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12160 "3:\n" \
12161 _ASM_EXTABLE(1b, 2b - 1b) \
12162 _ASM_EXTABLE(2b, 3b - 2b) \
12163 @@ -374,7 +416,7 @@ do { \
12164 } while (0)
12165
12166 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12167 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12168 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12169 "2:\n" \
12170 ".section .fixup,\"ax\"\n" \
12171 "3: mov %3,%0\n" \
12172 @@ -382,7 +424,7 @@ do { \
12173 " jmp 2b\n" \
12174 ".previous\n" \
12175 _ASM_EXTABLE(1b, 3b) \
12176 - : "=r" (err), ltype(x) \
12177 + : "=r" (err), ltype (x) \
12178 : "m" (__m(addr)), "i" (errret), "0" (err))
12179
12180 #define __get_user_size_ex(x, ptr, size) \
12181 @@ -407,7 +449,7 @@ do { \
12182 } while (0)
12183
12184 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12185 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12186 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12187 "2:\n" \
12188 _ASM_EXTABLE(1b, 2b - 1b) \
12189 : ltype(x) : "m" (__m(addr)))
12190 @@ -424,13 +466,24 @@ do { \
12191 int __gu_err; \
12192 unsigned long __gu_val; \
12193 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12194 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12195 + (x) = (__typeof__(*(ptr)))__gu_val; \
12196 __gu_err; \
12197 })
12198
12199 /* FIXME: this hack is definitely wrong -AK */
12200 struct __large_struct { unsigned long buf[100]; };
12201 -#define __m(x) (*(struct __large_struct __user *)(x))
12202 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12203 +#define ____m(x) \
12204 +({ \
12205 + unsigned long ____x = (unsigned long)(x); \
12206 + if (____x < PAX_USER_SHADOW_BASE) \
12207 + ____x += PAX_USER_SHADOW_BASE; \
12208 + (void __user *)____x; \
12209 +})
12210 +#else
12211 +#define ____m(x) (x)
12212 +#endif
12213 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12214
12215 /*
12216 * Tell gcc we read from memory instead of writing: this is because
12217 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
12218 * aliasing issues.
12219 */
12220 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12221 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12222 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12223 "2:\n" \
12224 ".section .fixup,\"ax\"\n" \
12225 "3: mov %3,%0\n" \
12226 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
12227 ".previous\n" \
12228 _ASM_EXTABLE(1b, 3b) \
12229 : "=r"(err) \
12230 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12231 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12232
12233 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12234 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12235 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12236 "2:\n" \
12237 _ASM_EXTABLE(1b, 2b - 1b) \
12238 : : ltype(x), "m" (__m(addr)))
12239 @@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
12240 * On error, the variable @x is set to zero.
12241 */
12242
12243 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12244 +#define __get_user(x, ptr) get_user((x), (ptr))
12245 +#else
12246 #define __get_user(x, ptr) \
12247 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12248 +#endif
12249
12250 /**
12251 * __put_user: - Write a simple value into user space, with less checking.
12252 @@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
12253 * Returns zero on success, or -EFAULT on error.
12254 */
12255
12256 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12257 +#define __put_user(x, ptr) put_user((x), (ptr))
12258 +#else
12259 #define __put_user(x, ptr) \
12260 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12261 +#endif
12262
12263 #define __get_user_unaligned __get_user
12264 #define __put_user_unaligned __put_user
12265 @@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
12266 #define get_user_ex(x, ptr) do { \
12267 unsigned long __gue_val; \
12268 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12269 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12270 + (x) = (__typeof__(*(ptr)))__gue_val; \
12271 } while (0)
12272
12273 #ifdef CONFIG_X86_WP_WORKS_OK
12274 @@ -567,6 +628,7 @@ extern struct movsl_mask {
12275
12276 #define ARCH_HAS_NOCACHE_UACCESS 1
12277
12278 +#define ARCH_HAS_SORT_EXTABLE
12279 #ifdef CONFIG_X86_32
12280 # include "uaccess_32.h"
12281 #else
12282 diff -urNp linux-2.6.39.1/arch/x86/include/asm/vgtod.h linux-2.6.39.1/arch/x86/include/asm/vgtod.h
12283 --- linux-2.6.39.1/arch/x86/include/asm/vgtod.h 2011-05-19 00:06:34.000000000 -0400
12284 +++ linux-2.6.39.1/arch/x86/include/asm/vgtod.h 2011-05-22 19:36:30.000000000 -0400
12285 @@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12286 int sysctl_enabled;
12287 struct timezone sys_tz;
12288 struct { /* extract of a clocksource struct */
12289 + char name[8];
12290 cycle_t (*vread)(void);
12291 cycle_t cycle_last;
12292 cycle_t mask;
12293 diff -urNp linux-2.6.39.1/arch/x86/include/asm/vsyscall.h linux-2.6.39.1/arch/x86/include/asm/vsyscall.h
12294 --- linux-2.6.39.1/arch/x86/include/asm/vsyscall.h 2011-05-19 00:06:34.000000000 -0400
12295 +++ linux-2.6.39.1/arch/x86/include/asm/vsyscall.h 2011-05-22 19:36:30.000000000 -0400
12296 @@ -15,9 +15,10 @@ enum vsyscall_num {
12297
12298 #ifdef __KERNEL__
12299 #include <linux/seqlock.h>
12300 +#include <linux/getcpu.h>
12301 +#include <linux/time.h>
12302
12303 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12304 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12305
12306 /* Definitions for CONFIG_GENERIC_TIME definitions */
12307 #define __section_vsyscall_gtod_data __attribute__ \
12308 @@ -31,7 +32,6 @@ enum vsyscall_num {
12309 #define VGETCPU_LSL 2
12310
12311 extern int __vgetcpu_mode;
12312 -extern volatile unsigned long __jiffies;
12313
12314 /* kernel space (writeable) */
12315 extern int vgetcpu_mode;
12316 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12317
12318 extern void map_vsyscall(void);
12319
12320 +extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12321 +extern time_t vtime(time_t *t);
12322 +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12323 #endif /* __KERNEL__ */
12324
12325 #endif /* _ASM_X86_VSYSCALL_H */
12326 diff -urNp linux-2.6.39.1/arch/x86/include/asm/xen/pci.h linux-2.6.39.1/arch/x86/include/asm/xen/pci.h
12327 --- linux-2.6.39.1/arch/x86/include/asm/xen/pci.h 2011-05-19 00:06:34.000000000 -0400
12328 +++ linux-2.6.39.1/arch/x86/include/asm/xen/pci.h 2011-05-22 19:36:30.000000000 -0400
12329 @@ -33,7 +33,7 @@ struct xen_pci_frontend_ops {
12330 void (*disable_msix)(struct pci_dev *dev);
12331 };
12332
12333 -extern struct xen_pci_frontend_ops *xen_pci_frontend;
12334 +extern const struct xen_pci_frontend_ops *xen_pci_frontend;
12335
12336 static inline int xen_pci_frontend_enable_msi(struct pci_dev *dev,
12337 int vectors[])
12338 diff -urNp linux-2.6.39.1/arch/x86/include/asm/xsave.h linux-2.6.39.1/arch/x86/include/asm/xsave.h
12339 --- linux-2.6.39.1/arch/x86/include/asm/xsave.h 2011-05-19 00:06:34.000000000 -0400
12340 +++ linux-2.6.39.1/arch/x86/include/asm/xsave.h 2011-05-22 19:36:30.000000000 -0400
12341 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
12342 {
12343 int err;
12344
12345 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12346 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12347 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12348 +#endif
12349 +
12350 /*
12351 * Clear the xsave header first, so that reserved fields are
12352 * initialized to zero.
12353 @@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
12354 u32 lmask = mask;
12355 u32 hmask = mask >> 32;
12356
12357 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12358 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12359 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12360 +#endif
12361 +
12362 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12363 "2:\n"
12364 ".section .fixup,\"ax\"\n"
12365 diff -urNp linux-2.6.39.1/arch/x86/Kconfig linux-2.6.39.1/arch/x86/Kconfig
12366 --- linux-2.6.39.1/arch/x86/Kconfig 2011-05-19 00:06:34.000000000 -0400
12367 +++ linux-2.6.39.1/arch/x86/Kconfig 2011-05-22 19:41:32.000000000 -0400
12368 @@ -224,7 +224,7 @@ config X86_HT
12369
12370 config X86_32_LAZY_GS
12371 def_bool y
12372 - depends on X86_32 && !CC_STACKPROTECTOR
12373 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12374
12375 config ARCH_HWEIGHT_CFLAGS
12376 string
12377 @@ -1022,7 +1022,7 @@ choice
12378
12379 config NOHIGHMEM
12380 bool "off"
12381 - depends on !X86_NUMAQ
12382 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12383 ---help---
12384 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12385 However, the address space of 32-bit x86 processors is only 4
12386 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
12387
12388 config HIGHMEM4G
12389 bool "4GB"
12390 - depends on !X86_NUMAQ
12391 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12392 ---help---
12393 Select this if you have a 32-bit processor and between 1 and 4
12394 gigabytes of physical RAM.
12395 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
12396 hex
12397 default 0xB0000000 if VMSPLIT_3G_OPT
12398 default 0x80000000 if VMSPLIT_2G
12399 - default 0x78000000 if VMSPLIT_2G_OPT
12400 + default 0x70000000 if VMSPLIT_2G_OPT
12401 default 0x40000000 if VMSPLIT_1G
12402 default 0xC0000000
12403 depends on X86_32
12404 @@ -1457,7 +1457,7 @@ config ARCH_USES_PG_UNCACHED
12405
12406 config EFI
12407 bool "EFI runtime service support"
12408 - depends on ACPI
12409 + depends on ACPI && !PAX_KERNEXEC
12410 ---help---
12411 This enables the kernel to use EFI runtime services that are
12412 available (such as the EFI variable services).
12413 @@ -1487,6 +1487,7 @@ config SECCOMP
12414
12415 config CC_STACKPROTECTOR
12416 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
12417 + depends on X86_64 || !PAX_MEMORY_UDEREF
12418 ---help---
12419 This option turns on the -fstack-protector GCC feature. This
12420 feature puts, at the beginning of functions, a canary value on
12421 @@ -1544,6 +1545,7 @@ config KEXEC_JUMP
12422 config PHYSICAL_START
12423 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
12424 default "0x1000000"
12425 + range 0x400000 0x40000000
12426 ---help---
12427 This gives the physical address where the kernel is loaded.
12428
12429 @@ -1607,6 +1609,7 @@ config X86_NEED_RELOCS
12430 config PHYSICAL_ALIGN
12431 hex "Alignment value to which kernel should be aligned" if X86_32
12432 default "0x1000000"
12433 + range 0x400000 0x1000000 if PAX_KERNEXEC
12434 range 0x2000 0x1000000
12435 ---help---
12436 This value puts the alignment restrictions on physical address
12437 @@ -1638,9 +1641,10 @@ config HOTPLUG_CPU
12438 Say N if you want to disable CPU hotplug.
12439
12440 config COMPAT_VDSO
12441 - def_bool y
12442 + def_bool n
12443 prompt "Compat VDSO support"
12444 depends on X86_32 || IA32_EMULATION
12445 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
12446 ---help---
12447 Map the 32-bit VDSO to the predictable old-style address too.
12448
12449 diff -urNp linux-2.6.39.1/arch/x86/Kconfig.cpu linux-2.6.39.1/arch/x86/Kconfig.cpu
12450 --- linux-2.6.39.1/arch/x86/Kconfig.cpu 2011-05-19 00:06:34.000000000 -0400
12451 +++ linux-2.6.39.1/arch/x86/Kconfig.cpu 2011-05-22 19:36:30.000000000 -0400
12452 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
12453
12454 config X86_F00F_BUG
12455 def_bool y
12456 - depends on M586MMX || M586TSC || M586 || M486 || M386
12457 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
12458
12459 config X86_INVD_BUG
12460 def_bool y
12461 @@ -358,7 +358,7 @@ config X86_POPAD_OK
12462
12463 config X86_ALIGNMENT_16
12464 def_bool y
12465 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12466 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12467
12468 config X86_INTEL_USERCOPY
12469 def_bool y
12470 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
12471 # generates cmov.
12472 config X86_CMOV
12473 def_bool y
12474 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12475 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12476
12477 config X86_MINIMUM_CPU_FAMILY
12478 int
12479 diff -urNp linux-2.6.39.1/arch/x86/Kconfig.debug linux-2.6.39.1/arch/x86/Kconfig.debug
12480 --- linux-2.6.39.1/arch/x86/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
12481 +++ linux-2.6.39.1/arch/x86/Kconfig.debug 2011-05-22 19:36:30.000000000 -0400
12482 @@ -101,7 +101,7 @@ config X86_PTDUMP
12483 config DEBUG_RODATA
12484 bool "Write protect kernel read-only data structures"
12485 default y
12486 - depends on DEBUG_KERNEL
12487 + depends on DEBUG_KERNEL && BROKEN
12488 ---help---
12489 Mark the kernel read-only data as write-protected in the pagetables,
12490 in order to catch accidental (and incorrect) writes to such const
12491 @@ -119,7 +119,7 @@ config DEBUG_RODATA_TEST
12492
12493 config DEBUG_SET_MODULE_RONX
12494 bool "Set loadable kernel module data as NX and text as RO"
12495 - depends on MODULES
12496 + depends on MODULES && BROKEN
12497 ---help---
12498 This option helps catch unintended modifications to loadable
12499 kernel module's text and read-only data. It also prevents execution
12500 diff -urNp linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c
12501 --- linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c 2011-05-19 00:06:34.000000000 -0400
12502 +++ linux-2.6.39.1/arch/x86/kernel/acpi/sleep.c 2011-05-22 19:36:30.000000000 -0400
12503 @@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
12504 header->trampoline_segment = trampoline_address() >> 4;
12505 #ifdef CONFIG_SMP
12506 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12507 +
12508 + pax_open_kernel();
12509 early_gdt_descr.address =
12510 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12511 + pax_close_kernel();
12512 +
12513 initial_gs = per_cpu_offset(smp_processor_id());
12514 #endif
12515 initial_code = (unsigned long)wakeup_long64;
12516 diff -urNp linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S
12517 --- linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S 2011-05-19 00:06:34.000000000 -0400
12518 +++ linux-2.6.39.1/arch/x86/kernel/acpi/wakeup_32.S 2011-05-22 19:36:30.000000000 -0400
12519 @@ -30,13 +30,11 @@ wakeup_pmode_return:
12520 # and restore the stack ... but you need gdt for this to work
12521 movl saved_context_esp, %esp
12522
12523 - movl %cs:saved_magic, %eax
12524 - cmpl $0x12345678, %eax
12525 + cmpl $0x12345678, saved_magic
12526 jne bogus_magic
12527
12528 # jump to place where we left off
12529 - movl saved_eip, %eax
12530 - jmp *%eax
12531 + jmp *(saved_eip)
12532
12533 bogus_magic:
12534 jmp bogus_magic
12535 diff -urNp linux-2.6.39.1/arch/x86/kernel/alternative.c linux-2.6.39.1/arch/x86/kernel/alternative.c
12536 --- linux-2.6.39.1/arch/x86/kernel/alternative.c 2011-05-19 00:06:34.000000000 -0400
12537 +++ linux-2.6.39.1/arch/x86/kernel/alternative.c 2011-05-22 19:36:30.000000000 -0400
12538 @@ -248,7 +248,7 @@ static void alternatives_smp_lock(const
12539 if (!*poff || ptr < text || ptr >= text_end)
12540 continue;
12541 /* turn DS segment override prefix into lock prefix */
12542 - if (*ptr == 0x3e)
12543 + if (*ktla_ktva(ptr) == 0x3e)
12544 text_poke(ptr, ((unsigned char []){0xf0}), 1);
12545 };
12546 mutex_unlock(&text_mutex);
12547 @@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
12548 if (!*poff || ptr < text || ptr >= text_end)
12549 continue;
12550 /* turn lock prefix into DS segment override prefix */
12551 - if (*ptr == 0xf0)
12552 + if (*ktla_ktva(ptr) == 0xf0)
12553 text_poke(ptr, ((unsigned char []){0x3E}), 1);
12554 };
12555 mutex_unlock(&text_mutex);
12556 @@ -438,7 +438,7 @@ void __init_or_module apply_paravirt(str
12557
12558 BUG_ON(p->len > MAX_PATCH_LEN);
12559 /* prep the buffer with the original instructions */
12560 - memcpy(insnbuf, p->instr, p->len);
12561 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12562 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12563 (unsigned long)p->instr, p->len);
12564
12565 @@ -506,7 +506,7 @@ void __init alternative_instructions(voi
12566 if (smp_alt_once)
12567 free_init_pages("SMP alternatives",
12568 (unsigned long)__smp_locks,
12569 - (unsigned long)__smp_locks_end);
12570 + PAGE_ALIGN((unsigned long)__smp_locks_end));
12571
12572 restart_nmi();
12573 }
12574 @@ -523,13 +523,17 @@ void __init alternative_instructions(voi
12575 * instructions. And on the local CPU you need to be protected again NMI or MCE
12576 * handlers seeing an inconsistent instruction while you patch.
12577 */
12578 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
12579 +void *__kprobes text_poke_early(void *addr, const void *opcode,
12580 size_t len)
12581 {
12582 unsigned long flags;
12583 local_irq_save(flags);
12584 - memcpy(addr, opcode, len);
12585 +
12586 + pax_open_kernel();
12587 + memcpy(ktla_ktva(addr), opcode, len);
12588 sync_core();
12589 + pax_close_kernel();
12590 +
12591 local_irq_restore(flags);
12592 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12593 that causes hangs on some VIA CPUs. */
12594 @@ -551,36 +555,22 @@ void *__init_or_module text_poke_early(v
12595 */
12596 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12597 {
12598 - unsigned long flags;
12599 - char *vaddr;
12600 + unsigned char *vaddr = ktla_ktva(addr);
12601 struct page *pages[2];
12602 - int i;
12603 + size_t i;
12604
12605 if (!core_kernel_text((unsigned long)addr)) {
12606 - pages[0] = vmalloc_to_page(addr);
12607 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12608 + pages[0] = vmalloc_to_page(vaddr);
12609 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12610 } else {
12611 - pages[0] = virt_to_page(addr);
12612 + pages[0] = virt_to_page(vaddr);
12613 WARN_ON(!PageReserved(pages[0]));
12614 - pages[1] = virt_to_page(addr + PAGE_SIZE);
12615 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12616 }
12617 BUG_ON(!pages[0]);
12618 - local_irq_save(flags);
12619 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12620 - if (pages[1])
12621 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12622 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12623 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12624 - clear_fixmap(FIX_TEXT_POKE0);
12625 - if (pages[1])
12626 - clear_fixmap(FIX_TEXT_POKE1);
12627 - local_flush_tlb();
12628 - sync_core();
12629 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
12630 - that causes hangs on some VIA CPUs. */
12631 + text_poke_early(addr, opcode, len);
12632 for (i = 0; i < len; i++)
12633 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12634 - local_irq_restore(flags);
12635 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12636 return addr;
12637 }
12638
12639 @@ -682,9 +672,9 @@ void __kprobes text_poke_smp_batch(struc
12640 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
12641
12642 #ifdef CONFIG_X86_64
12643 -unsigned char ideal_nop5[5] = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12644 +unsigned char ideal_nop5[5] __read_only = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12645 #else
12646 -unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12647 +unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12648 #endif
12649
12650 void __init arch_init_ideal_nop5(void)
12651 diff -urNp linux-2.6.39.1/arch/x86/kernel/amd_iommu.c linux-2.6.39.1/arch/x86/kernel/amd_iommu.c
12652 --- linux-2.6.39.1/arch/x86/kernel/amd_iommu.c 2011-05-19 00:06:34.000000000 -0400
12653 +++ linux-2.6.39.1/arch/x86/kernel/amd_iommu.c 2011-05-22 19:36:30.000000000 -0400
12654 @@ -48,7 +48,7 @@ static DEFINE_SPINLOCK(iommu_pd_list_loc
12655 */
12656 static struct protection_domain *pt_domain;
12657
12658 -static struct iommu_ops amd_iommu_ops;
12659 +static const struct iommu_ops amd_iommu_ops;
12660
12661 /*
12662 * general struct to manage commands send to an IOMMU
12663 @@ -2286,7 +2286,7 @@ static void prealloc_protection_domains(
12664 }
12665 }
12666
12667 -static struct dma_map_ops amd_iommu_dma_ops = {
12668 +static const struct dma_map_ops amd_iommu_dma_ops = {
12669 .alloc_coherent = alloc_coherent,
12670 .free_coherent = free_coherent,
12671 .map_page = map_page,
12672 @@ -2582,7 +2582,7 @@ static int amd_iommu_domain_has_cap(stru
12673 return 0;
12674 }
12675
12676 -static struct iommu_ops amd_iommu_ops = {
12677 +static const struct iommu_ops amd_iommu_ops = {
12678 .domain_init = amd_iommu_domain_init,
12679 .domain_destroy = amd_iommu_domain_destroy,
12680 .attach_dev = amd_iommu_attach_device,
12681 diff -urNp linux-2.6.39.1/arch/x86/kernel/apic/apic.c linux-2.6.39.1/arch/x86/kernel/apic/apic.c
12682 --- linux-2.6.39.1/arch/x86/kernel/apic/apic.c 2011-05-19 00:06:34.000000000 -0400
12683 +++ linux-2.6.39.1/arch/x86/kernel/apic/apic.c 2011-05-22 19:36:30.000000000 -0400
12684 @@ -1821,7 +1821,7 @@ void smp_error_interrupt(struct pt_regs
12685 apic_write(APIC_ESR, 0);
12686 v1 = apic_read(APIC_ESR);
12687 ack_APIC_irq();
12688 - atomic_inc(&irq_err_count);
12689 + atomic_inc_unchecked(&irq_err_count);
12690
12691 /*
12692 * Here is what the APIC error bits mean:
12693 @@ -2204,6 +2204,8 @@ static int __cpuinit apic_cluster_num(vo
12694 u16 *bios_cpu_apicid;
12695 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
12696
12697 + pax_track_stack();
12698 +
12699 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
12700 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
12701
12702 diff -urNp linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c
12703 --- linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:04:13.000000000 -0400
12704 +++ linux-2.6.39.1/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:42:37.000000000 -0400
12705 @@ -623,7 +623,7 @@ struct IO_APIC_route_entry **alloc_ioapi
12706 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
12707 GFP_ATOMIC);
12708 if (!ioapic_entries)
12709 - return 0;
12710 + return NULL;
12711
12712 for (apic = 0; apic < nr_ioapics; apic++) {
12713 ioapic_entries[apic] =
12714 @@ -640,7 +640,7 @@ nomem:
12715 kfree(ioapic_entries[apic]);
12716 kfree(ioapic_entries);
12717
12718 - return 0;
12719 + return NULL;
12720 }
12721
12722 /*
12723 @@ -1040,7 +1040,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
12724 }
12725 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12726
12727 -void lock_vector_lock(void)
12728 +void lock_vector_lock(void) __acquires(vector_lock)
12729 {
12730 /* Used to the online set of cpus does not change
12731 * during assign_irq_vector.
12732 @@ -1048,7 +1048,7 @@ void lock_vector_lock(void)
12733 raw_spin_lock(&vector_lock);
12734 }
12735
12736 -void unlock_vector_lock(void)
12737 +void unlock_vector_lock(void) __releases(vector_lock)
12738 {
12739 raw_spin_unlock(&vector_lock);
12740 }
12741 @@ -2379,7 +2379,7 @@ static void ack_apic_edge(struct irq_dat
12742 ack_APIC_irq();
12743 }
12744
12745 -atomic_t irq_mis_count;
12746 +atomic_unchecked_t irq_mis_count;
12747
12748 /*
12749 * IO-APIC versions below 0x20 don't support EOI register.
12750 @@ -2487,7 +2487,7 @@ static void ack_apic_level(struct irq_da
12751 * at the cpu.
12752 */
12753 if (!(v & (1 << (i & 0x1f)))) {
12754 - atomic_inc(&irq_mis_count);
12755 + atomic_inc_unchecked(&irq_mis_count);
12756
12757 eoi_ioapic_irq(irq, cfg);
12758 }
12759 diff -urNp linux-2.6.39.1/arch/x86/kernel/apm_32.c linux-2.6.39.1/arch/x86/kernel/apm_32.c
12760 --- linux-2.6.39.1/arch/x86/kernel/apm_32.c 2011-05-19 00:06:34.000000000 -0400
12761 +++ linux-2.6.39.1/arch/x86/kernel/apm_32.c 2011-05-22 19:36:30.000000000 -0400
12762 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
12763 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12764 * even though they are called in protected mode.
12765 */
12766 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12767 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12768 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12769
12770 static const char driver_version[] = "1.16ac"; /* no spaces */
12771 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
12772 BUG_ON(cpu != 0);
12773 gdt = get_cpu_gdt_table(cpu);
12774 save_desc_40 = gdt[0x40 / 8];
12775 +
12776 + pax_open_kernel();
12777 gdt[0x40 / 8] = bad_bios_desc;
12778 + pax_close_kernel();
12779
12780 apm_irq_save(flags);
12781 APM_DO_SAVE_SEGS;
12782 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
12783 &call->esi);
12784 APM_DO_RESTORE_SEGS;
12785 apm_irq_restore(flags);
12786 +
12787 + pax_open_kernel();
12788 gdt[0x40 / 8] = save_desc_40;
12789 + pax_close_kernel();
12790 +
12791 put_cpu();
12792
12793 return call->eax & 0xff;
12794 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void
12795 BUG_ON(cpu != 0);
12796 gdt = get_cpu_gdt_table(cpu);
12797 save_desc_40 = gdt[0x40 / 8];
12798 +
12799 + pax_open_kernel();
12800 gdt[0x40 / 8] = bad_bios_desc;
12801 + pax_close_kernel();
12802
12803 apm_irq_save(flags);
12804 APM_DO_SAVE_SEGS;
12805 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void
12806 &call->eax);
12807 APM_DO_RESTORE_SEGS;
12808 apm_irq_restore(flags);
12809 +
12810 + pax_open_kernel();
12811 gdt[0x40 / 8] = save_desc_40;
12812 + pax_close_kernel();
12813 +
12814 put_cpu();
12815 return error;
12816 }
12817 @@ -2351,12 +2365,15 @@ static int __init apm_init(void)
12818 * code to that CPU.
12819 */
12820 gdt = get_cpu_gdt_table(0);
12821 +
12822 + pax_open_kernel();
12823 set_desc_base(&gdt[APM_CS >> 3],
12824 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12825 set_desc_base(&gdt[APM_CS_16 >> 3],
12826 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12827 set_desc_base(&gdt[APM_DS >> 3],
12828 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12829 + pax_close_kernel();
12830
12831 proc_create("apm", 0, NULL, &apm_file_ops);
12832
12833 diff -urNp linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c
12834 --- linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c 2011-05-19 00:06:34.000000000 -0400
12835 +++ linux-2.6.39.1/arch/x86/kernel/asm-offsets_64.c 2011-05-22 19:36:30.000000000 -0400
12836 @@ -69,6 +69,7 @@ int main(void)
12837 BLANK();
12838 #undef ENTRY
12839
12840 + DEFINE(TSS_size, sizeof(struct tss_struct));
12841 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12842 BLANK();
12843
12844 diff -urNp linux-2.6.39.1/arch/x86/kernel/asm-offsets.c linux-2.6.39.1/arch/x86/kernel/asm-offsets.c
12845 --- linux-2.6.39.1/arch/x86/kernel/asm-offsets.c 2011-05-19 00:06:34.000000000 -0400
12846 +++ linux-2.6.39.1/arch/x86/kernel/asm-offsets.c 2011-05-25 17:35:48.000000000 -0400
12847 @@ -33,6 +33,8 @@ void common(void) {
12848 OFFSET(TI_status, thread_info, status);
12849 OFFSET(TI_addr_limit, thread_info, addr_limit);
12850 OFFSET(TI_preempt_count, thread_info, preempt_count);
12851 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12852 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12853
12854 BLANK();
12855 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12856 @@ -53,8 +55,26 @@ void common(void) {
12857 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12858 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12859 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12860 +
12861 +#ifdef CONFIG_PAX_KERNEXEC
12862 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12863 +#endif
12864 +
12865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12866 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12867 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12868 +#ifdef CONFIG_X86_64
12869 + OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
12870 +#endif
12871 #endif
12872
12873 +#endif
12874 +
12875 + BLANK();
12876 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12877 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12878 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12879 +
12880 #ifdef CONFIG_XEN
12881 BLANK();
12882 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12883 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/amd.c linux-2.6.39.1/arch/x86/kernel/cpu/amd.c
12884 --- linux-2.6.39.1/arch/x86/kernel/cpu/amd.c 2011-06-03 00:04:13.000000000 -0400
12885 +++ linux-2.6.39.1/arch/x86/kernel/cpu/amd.c 2011-06-03 00:32:04.000000000 -0400
12886 @@ -647,7 +647,7 @@ static unsigned int __cpuinit amd_size_c
12887 unsigned int size)
12888 {
12889 /* AMD errata T13 (order #21922) */
12890 - if ((c->x86 == 6)) {
12891 + if (c->x86 == 6) {
12892 /* Duron Rev A0 */
12893 if (c->x86_model == 3 && c->x86_mask == 0)
12894 size = 64;
12895 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/common.c linux-2.6.39.1/arch/x86/kernel/cpu/common.c
12896 --- linux-2.6.39.1/arch/x86/kernel/cpu/common.c 2011-06-03 00:04:13.000000000 -0400
12897 +++ linux-2.6.39.1/arch/x86/kernel/cpu/common.c 2011-06-03 00:32:04.000000000 -0400
12898 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
12899
12900 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12901
12902 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12903 -#ifdef CONFIG_X86_64
12904 - /*
12905 - * We need valid kernel segments for data and code in long mode too
12906 - * IRET will check the segment types kkeil 2000/10/28
12907 - * Also sysret mandates a special GDT layout
12908 - *
12909 - * TLS descriptors are currently at a different place compared to i386.
12910 - * Hopefully nobody expects them at a fixed place (Wine?)
12911 - */
12912 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12913 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12914 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12915 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12916 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12917 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12918 -#else
12919 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12920 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12921 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12922 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12923 - /*
12924 - * Segments used for calling PnP BIOS have byte granularity.
12925 - * They code segments and data segments have fixed 64k limits,
12926 - * the transfer segment sizes are set at run time.
12927 - */
12928 - /* 32-bit code */
12929 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12930 - /* 16-bit code */
12931 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12932 - /* 16-bit data */
12933 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12934 - /* 16-bit data */
12935 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12936 - /* 16-bit data */
12937 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12938 - /*
12939 - * The APM segments have byte granularity and their bases
12940 - * are set at run time. All have 64k limits.
12941 - */
12942 - /* 32-bit code */
12943 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12944 - /* 16-bit code */
12945 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12946 - /* data */
12947 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12948 -
12949 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12950 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12951 - GDT_STACK_CANARY_INIT
12952 -#endif
12953 -} };
12954 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12955 -
12956 static int __init x86_xsave_setup(char *s)
12957 {
12958 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12959 @@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
12960 {
12961 struct desc_ptr gdt_descr;
12962
12963 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12964 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12965 gdt_descr.size = GDT_SIZE - 1;
12966 load_gdt(&gdt_descr);
12967 /* Reload the per-cpu base */
12968 @@ -824,6 +770,10 @@ static void __cpuinit identify_cpu(struc
12969 /* Filter out anything that depends on CPUID levels we don't have */
12970 filter_cpuid_features(c, true);
12971
12972 +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
12973 + setup_clear_cpu_cap(X86_FEATURE_SEP);
12974 +#endif
12975 +
12976 /* If the model name is still unset, do table lookup. */
12977 if (!c->x86_model_id[0]) {
12978 const char *p;
12979 @@ -1003,6 +953,9 @@ static __init int setup_disablecpuid(cha
12980 }
12981 __setup("clearcpuid=", setup_disablecpuid);
12982
12983 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12984 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
12985 +
12986 #ifdef CONFIG_X86_64
12987 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12988
12989 @@ -1018,7 +971,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
12990 EXPORT_PER_CPU_SYMBOL(current_task);
12991
12992 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12993 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12994 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12995 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12996
12997 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12998 @@ -1083,7 +1036,7 @@ struct pt_regs * __cpuinit idle_regs(str
12999 {
13000 memset(regs, 0, sizeof(struct pt_regs));
13001 regs->fs = __KERNEL_PERCPU;
13002 - regs->gs = __KERNEL_STACK_CANARY;
13003 + savesegment(gs, regs->gs);
13004
13005 return regs;
13006 }
13007 @@ -1138,7 +1091,7 @@ void __cpuinit cpu_init(void)
13008 int i;
13009
13010 cpu = stack_smp_processor_id();
13011 - t = &per_cpu(init_tss, cpu);
13012 + t = init_tss + cpu;
13013 oist = &per_cpu(orig_ist, cpu);
13014
13015 #ifdef CONFIG_NUMA
13016 @@ -1164,7 +1117,7 @@ void __cpuinit cpu_init(void)
13017 switch_to_new_gdt(cpu);
13018 loadsegment(fs, 0);
13019
13020 - load_idt((const struct desc_ptr *)&idt_descr);
13021 + load_idt(&idt_descr);
13022
13023 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13024 syscall_init();
13025 @@ -1173,7 +1126,6 @@ void __cpuinit cpu_init(void)
13026 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13027 barrier();
13028
13029 - x86_configure_nx();
13030 if (cpu != 0)
13031 enable_x2apic();
13032
13033 @@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
13034 {
13035 int cpu = smp_processor_id();
13036 struct task_struct *curr = current;
13037 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13038 + struct tss_struct *t = init_tss + cpu;
13039 struct thread_struct *thread = &curr->thread;
13040
13041 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13042 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/intel.c linux-2.6.39.1/arch/x86/kernel/cpu/intel.c
13043 --- linux-2.6.39.1/arch/x86/kernel/cpu/intel.c 2011-05-19 00:06:34.000000000 -0400
13044 +++ linux-2.6.39.1/arch/x86/kernel/cpu/intel.c 2011-05-22 19:36:30.000000000 -0400
13045 @@ -161,7 +161,7 @@ static void __cpuinit trap_init_f00f_bug
13046 * Update the IDT descriptor and reload the IDT so that
13047 * it uses the read-only mapped virtual address.
13048 */
13049 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13050 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13051 load_idt(&idt_descr);
13052 }
13053 #endif
13054 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/Makefile linux-2.6.39.1/arch/x86/kernel/cpu/Makefile
13055 --- linux-2.6.39.1/arch/x86/kernel/cpu/Makefile 2011-05-19 00:06:34.000000000 -0400
13056 +++ linux-2.6.39.1/arch/x86/kernel/cpu/Makefile 2011-05-22 19:36:30.000000000 -0400
13057 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13058 CFLAGS_REMOVE_perf_event.o = -pg
13059 endif
13060
13061 -# Make sure load_percpu_segment has no stackprotector
13062 -nostackp := $(call cc-option, -fno-stack-protector)
13063 -CFLAGS_common.o := $(nostackp)
13064 -
13065 obj-y := intel_cacheinfo.o scattered.o topology.o
13066 obj-y += proc.o capflags.o powerflags.o common.o
13067 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13068 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c
13069 --- linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-19 00:06:34.000000000 -0400
13070 +++ linux-2.6.39.1/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-22 19:36:30.000000000 -0400
13071 @@ -46,6 +46,7 @@
13072 #include <asm/ipi.h>
13073 #include <asm/mce.h>
13074 #include <asm/msr.h>
13075 +#include <asm/local.h>
13076
13077 #include "mce-internal.h"
13078
13079 @@ -220,7 +221,7 @@ static void print_mce(struct mce *m)
13080 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13081 m->cs, m->ip);
13082
13083 - if (m->cs == __KERNEL_CS)
13084 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13085 print_symbol("{%s}", m->ip);
13086 pr_cont("\n");
13087 }
13088 @@ -244,10 +245,10 @@ static void print_mce(struct mce *m)
13089
13090 #define PANIC_TIMEOUT 5 /* 5 seconds */
13091
13092 -static atomic_t mce_paniced;
13093 +static atomic_unchecked_t mce_paniced;
13094
13095 static int fake_panic;
13096 -static atomic_t mce_fake_paniced;
13097 +static atomic_unchecked_t mce_fake_paniced;
13098
13099 /* Panic in progress. Enable interrupts and wait for final IPI */
13100 static void wait_for_panic(void)
13101 @@ -271,7 +272,7 @@ static void mce_panic(char *msg, struct
13102 /*
13103 * Make sure only one CPU runs in machine check panic
13104 */
13105 - if (atomic_inc_return(&mce_paniced) > 1)
13106 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13107 wait_for_panic();
13108 barrier();
13109
13110 @@ -279,7 +280,7 @@ static void mce_panic(char *msg, struct
13111 console_verbose();
13112 } else {
13113 /* Don't log too much for fake panic */
13114 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13115 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13116 return;
13117 }
13118 /* First print corrected ones that are still unlogged */
13119 @@ -647,7 +648,7 @@ static int mce_timed_out(u64 *t)
13120 * might have been modified by someone else.
13121 */
13122 rmb();
13123 - if (atomic_read(&mce_paniced))
13124 + if (atomic_read_unchecked(&mce_paniced))
13125 wait_for_panic();
13126 if (!monarch_timeout)
13127 goto out;
13128 @@ -1461,14 +1462,14 @@ void __cpuinit mcheck_cpu_init(struct cp
13129 */
13130
13131 static DEFINE_SPINLOCK(mce_state_lock);
13132 -static int open_count; /* #times opened */
13133 +static local_t open_count; /* #times opened */
13134 static int open_exclu; /* already open exclusive? */
13135
13136 static int mce_open(struct inode *inode, struct file *file)
13137 {
13138 spin_lock(&mce_state_lock);
13139
13140 - if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13141 + if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13142 spin_unlock(&mce_state_lock);
13143
13144 return -EBUSY;
13145 @@ -1476,7 +1477,7 @@ static int mce_open(struct inode *inode,
13146
13147 if (file->f_flags & O_EXCL)
13148 open_exclu = 1;
13149 - open_count++;
13150 + local_inc(&open_count);
13151
13152 spin_unlock(&mce_state_lock);
13153
13154 @@ -1487,7 +1488,7 @@ static int mce_release(struct inode *ino
13155 {
13156 spin_lock(&mce_state_lock);
13157
13158 - open_count--;
13159 + local_dec(&open_count);
13160 open_exclu = 0;
13161
13162 spin_unlock(&mce_state_lock);
13163 @@ -2174,7 +2175,7 @@ struct dentry *mce_get_debugfs_dir(void)
13164 static void mce_reset(void)
13165 {
13166 cpu_missing = 0;
13167 - atomic_set(&mce_fake_paniced, 0);
13168 + atomic_set_unchecked(&mce_fake_paniced, 0);
13169 atomic_set(&mce_executing, 0);
13170 atomic_set(&mce_callin, 0);
13171 atomic_set(&global_nwo, 0);
13172 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c
13173 --- linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c 2011-05-19 00:06:34.000000000 -0400
13174 +++ linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/main.c 2011-05-22 19:36:30.000000000 -0400
13175 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13176 u64 size_or_mask, size_and_mask;
13177 static bool mtrr_aps_delayed_init;
13178
13179 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13180 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13181
13182 const struct mtrr_ops *mtrr_if;
13183
13184 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h
13185 --- linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-19 00:06:34.000000000 -0400
13186 +++ linux-2.6.39.1/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-22 19:36:30.000000000 -0400
13187 @@ -12,19 +12,19 @@
13188 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
13189
13190 struct mtrr_ops {
13191 - u32 vendor;
13192 - u32 use_intel_if;
13193 - void (*set)(unsigned int reg, unsigned long base,
13194 + const u32 vendor;
13195 + const u32 use_intel_if;
13196 + void (* const set)(unsigned int reg, unsigned long base,
13197 unsigned long size, mtrr_type type);
13198 - void (*set_all)(void);
13199 + void (* const set_all)(void);
13200
13201 - void (*get)(unsigned int reg, unsigned long *base,
13202 + void (* const get)(unsigned int reg, unsigned long *base,
13203 unsigned long *size, mtrr_type *type);
13204 - int (*get_free_region)(unsigned long base, unsigned long size,
13205 + int (* const get_free_region)(unsigned long base, unsigned long size,
13206 int replace_reg);
13207 - int (*validate_add_page)(unsigned long base, unsigned long size,
13208 + int (* const validate_add_page)(unsigned long base, unsigned long size,
13209 unsigned int type);
13210 - int (*have_wrcomb)(void);
13211 + int (* const have_wrcomb)(void);
13212 };
13213
13214 extern int generic_get_free_region(unsigned long base, unsigned long size,
13215 diff -urNp linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c
13216 --- linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c 2011-05-19 00:06:34.000000000 -0400
13217 +++ linux-2.6.39.1/arch/x86/kernel/cpu/perf_event.c 2011-05-22 19:36:30.000000000 -0400
13218 @@ -774,6 +774,8 @@ static int x86_schedule_events(struct cp
13219 int i, j, w, wmax, num = 0;
13220 struct hw_perf_event *hwc;
13221
13222 + pax_track_stack();
13223 +
13224 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
13225
13226 for (i = 0; i < n; i++) {
13227 @@ -1878,7 +1880,7 @@ perf_callchain_user(struct perf_callchai
13228 break;
13229
13230 perf_callchain_store(entry, frame.return_address);
13231 - fp = frame.next_frame;
13232 + fp = (__force const void __user *)frame.next_frame;
13233 }
13234 }
13235
13236 diff -urNp linux-2.6.39.1/arch/x86/kernel/crash.c linux-2.6.39.1/arch/x86/kernel/crash.c
13237 --- linux-2.6.39.1/arch/x86/kernel/crash.c 2011-05-19 00:06:34.000000000 -0400
13238 +++ linux-2.6.39.1/arch/x86/kernel/crash.c 2011-05-22 19:36:30.000000000 -0400
13239 @@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
13240 regs = args->regs;
13241
13242 #ifdef CONFIG_X86_32
13243 - if (!user_mode_vm(regs)) {
13244 + if (!user_mode(regs)) {
13245 crash_fixup_ss_esp(&fixed_regs, regs);
13246 regs = &fixed_regs;
13247 }
13248 diff -urNp linux-2.6.39.1/arch/x86/kernel/doublefault_32.c linux-2.6.39.1/arch/x86/kernel/doublefault_32.c
13249 --- linux-2.6.39.1/arch/x86/kernel/doublefault_32.c 2011-05-19 00:06:34.000000000 -0400
13250 +++ linux-2.6.39.1/arch/x86/kernel/doublefault_32.c 2011-05-22 19:36:30.000000000 -0400
13251 @@ -11,7 +11,7 @@
13252
13253 #define DOUBLEFAULT_STACKSIZE (1024)
13254 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13255 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13256 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13257
13258 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13259
13260 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13261 unsigned long gdt, tss;
13262
13263 store_gdt(&gdt_desc);
13264 - gdt = gdt_desc.address;
13265 + gdt = (unsigned long)gdt_desc.address;
13266
13267 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13268
13269 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
13270 /* 0x2 bit is always set */
13271 .flags = X86_EFLAGS_SF | 0x2,
13272 .sp = STACK_START,
13273 - .es = __USER_DS,
13274 + .es = __KERNEL_DS,
13275 .cs = __KERNEL_CS,
13276 .ss = __KERNEL_DS,
13277 - .ds = __USER_DS,
13278 + .ds = __KERNEL_DS,
13279 .fs = __KERNEL_PERCPU,
13280
13281 .__cr3 = __pa_nodebug(swapper_pg_dir),
13282 diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c
13283 --- linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c 2011-05-19 00:06:34.000000000 -0400
13284 +++ linux-2.6.39.1/arch/x86/kernel/dumpstack_32.c 2011-05-22 19:36:30.000000000 -0400
13285 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task
13286 bp = stack_frame(task, regs);
13287
13288 for (;;) {
13289 - struct thread_info *context;
13290 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13291
13292 - context = (struct thread_info *)
13293 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13294 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
13295 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13296
13297 - stack = (unsigned long *)context->previous_esp;
13298 - if (!stack)
13299 + if (stack_start == task_stack_page(task))
13300 break;
13301 + stack = *(unsigned long **)stack_start;
13302 if (ops->stack(data, "IRQ") < 0)
13303 break;
13304 touch_nmi_watchdog();
13305 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs
13306 * When in-kernel, we also print out the stack and code at the
13307 * time of the fault..
13308 */
13309 - if (!user_mode_vm(regs)) {
13310 + if (!user_mode(regs)) {
13311 unsigned int code_prologue = code_bytes * 43 / 64;
13312 unsigned int code_len = code_bytes;
13313 unsigned char c;
13314 u8 *ip;
13315 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13316
13317 printk(KERN_EMERG "Stack:\n");
13318 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
13319
13320 printk(KERN_EMERG "Code: ");
13321
13322 - ip = (u8 *)regs->ip - code_prologue;
13323 + ip = (u8 *)regs->ip - code_prologue + cs_base;
13324 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13325 /* try starting at IP */
13326 - ip = (u8 *)regs->ip;
13327 + ip = (u8 *)regs->ip + cs_base;
13328 code_len = code_len - code_prologue + 1;
13329 }
13330 for (i = 0; i < code_len; i++, ip++) {
13331 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs
13332 printk(" Bad EIP value.");
13333 break;
13334 }
13335 - if (ip == (u8 *)regs->ip)
13336 + if (ip == (u8 *)regs->ip + cs_base)
13337 printk("<%02x> ", c);
13338 else
13339 printk("%02x ", c);
13340 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
13341 {
13342 unsigned short ud2;
13343
13344 + ip = ktla_ktva(ip);
13345 if (ip < PAGE_OFFSET)
13346 return 0;
13347 if (probe_kernel_address((unsigned short *)ip, ud2))
13348 diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c
13349 --- linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c 2011-05-19 00:06:34.000000000 -0400
13350 +++ linux-2.6.39.1/arch/x86/kernel/dumpstack_64.c 2011-05-22 19:36:30.000000000 -0400
13351 @@ -147,9 +147,9 @@ void dump_trace(struct task_struct *task
13352 unsigned long *irq_stack_end =
13353 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13354 unsigned used = 0;
13355 - struct thread_info *tinfo;
13356 int graph = 0;
13357 unsigned long dummy;
13358 + void *stack_start;
13359
13360 if (!task)
13361 task = current;
13362 @@ -167,10 +167,10 @@ void dump_trace(struct task_struct *task
13363 * current stack address. If the stacks consist of nested
13364 * exceptions
13365 */
13366 - tinfo = task_thread_info(task);
13367 for (;;) {
13368 char *id;
13369 unsigned long *estack_end;
13370 +
13371 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13372 &used, &id);
13373
13374 @@ -178,7 +178,7 @@ void dump_trace(struct task_struct *task
13375 if (ops->stack(data, id) < 0)
13376 break;
13377
13378 - bp = ops->walk_stack(tinfo, stack, bp, ops,
13379 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13380 data, estack_end, &graph);
13381 ops->stack(data, "<EOE>");
13382 /*
13383 @@ -197,7 +197,7 @@ void dump_trace(struct task_struct *task
13384 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
13385 if (ops->stack(data, "IRQ") < 0)
13386 break;
13387 - bp = ops->walk_stack(tinfo, stack, bp,
13388 + bp = ops->walk_stack(task, irq_stack, stack, bp,
13389 ops, data, irq_stack_end, &graph);
13390 /*
13391 * We link to the next stack (which would be
13392 @@ -218,7 +218,8 @@ void dump_trace(struct task_struct *task
13393 /*
13394 * This handles the process stack:
13395 */
13396 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13397 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13398 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13399 put_cpu();
13400 }
13401 EXPORT_SYMBOL(dump_trace);
13402 diff -urNp linux-2.6.39.1/arch/x86/kernel/dumpstack.c linux-2.6.39.1/arch/x86/kernel/dumpstack.c
13403 --- linux-2.6.39.1/arch/x86/kernel/dumpstack.c 2011-05-19 00:06:34.000000000 -0400
13404 +++ linux-2.6.39.1/arch/x86/kernel/dumpstack.c 2011-05-22 19:41:32.000000000 -0400
13405 @@ -2,6 +2,9 @@
13406 * Copyright (C) 1991, 1992 Linus Torvalds
13407 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13408 */
13409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13410 +#define __INCLUDED_BY_HIDESYM 1
13411 +#endif
13412 #include <linux/kallsyms.h>
13413 #include <linux/kprobes.h>
13414 #include <linux/uaccess.h>
13415 @@ -35,9 +38,8 @@ void printk_address(unsigned long addres
13416 static void
13417 print_ftrace_graph_addr(unsigned long addr, void *data,
13418 const struct stacktrace_ops *ops,
13419 - struct thread_info *tinfo, int *graph)
13420 + struct task_struct *task, int *graph)
13421 {
13422 - struct task_struct *task = tinfo->task;
13423 unsigned long ret_addr;
13424 int index = task->curr_ret_stack;
13425
13426 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long ad
13427 static inline void
13428 print_ftrace_graph_addr(unsigned long addr, void *data,
13429 const struct stacktrace_ops *ops,
13430 - struct thread_info *tinfo, int *graph)
13431 + struct task_struct *task, int *graph)
13432 { }
13433 #endif
13434
13435 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long ad
13436 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13437 */
13438
13439 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13440 - void *p, unsigned int size, void *end)
13441 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13442 {
13443 - void *t = tinfo;
13444 if (end) {
13445 if (p < end && p >= (end-THREAD_SIZE))
13446 return 1;
13447 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct
13448 }
13449
13450 unsigned long
13451 -print_context_stack(struct thread_info *tinfo,
13452 +print_context_stack(struct task_struct *task, void *stack_start,
13453 unsigned long *stack, unsigned long bp,
13454 const struct stacktrace_ops *ops, void *data,
13455 unsigned long *end, int *graph)
13456 {
13457 struct stack_frame *frame = (struct stack_frame *)bp;
13458
13459 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13460 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13461 unsigned long addr;
13462
13463 addr = *stack;
13464 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *
13465 } else {
13466 ops->address(data, addr, 0);
13467 }
13468 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13469 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13470 }
13471 stack++;
13472 }
13473 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *
13474 EXPORT_SYMBOL_GPL(print_context_stack);
13475
13476 unsigned long
13477 -print_context_stack_bp(struct thread_info *tinfo,
13478 +print_context_stack_bp(struct task_struct *task, void *stack_start,
13479 unsigned long *stack, unsigned long bp,
13480 const struct stacktrace_ops *ops, void *data,
13481 unsigned long *end, int *graph)
13482 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_inf
13483 struct stack_frame *frame = (struct stack_frame *)bp;
13484 unsigned long *ret_addr = &frame->return_address;
13485
13486 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13487 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13488 unsigned long addr = *ret_addr;
13489
13490 if (!__kernel_text_address(addr))
13491 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_inf
13492 ops->address(data, addr, 1);
13493 frame = frame->next_frame;
13494 ret_addr = &frame->return_address;
13495 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13496 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13497 }
13498
13499 return (unsigned long)frame;
13500 @@ -202,7 +202,7 @@ void dump_stack(void)
13501
13502 bp = stack_frame(current, NULL);
13503 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13504 - current->pid, current->comm, print_tainted(),
13505 + task_pid_nr(current), current->comm, print_tainted(),
13506 init_utsname()->release,
13507 (int)strcspn(init_utsname()->version, " "),
13508 init_utsname()->version);
13509 @@ -238,6 +238,8 @@ unsigned __kprobes long oops_begin(void)
13510 }
13511 EXPORT_SYMBOL_GPL(oops_begin);
13512
13513 +extern void gr_handle_kernel_exploit(void);
13514 +
13515 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13516 {
13517 if (regs && kexec_should_crash(current))
13518 @@ -259,7 +261,10 @@ void __kprobes oops_end(unsigned long fl
13519 panic("Fatal exception in interrupt");
13520 if (panic_on_oops)
13521 panic("Fatal exception");
13522 - do_exit(signr);
13523 +
13524 + gr_handle_kernel_exploit();
13525 +
13526 + do_group_exit(signr);
13527 }
13528
13529 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13530 @@ -286,7 +291,7 @@ int __kprobes __die(const char *str, str
13531
13532 show_registers(regs);
13533 #ifdef CONFIG_X86_32
13534 - if (user_mode_vm(regs)) {
13535 + if (user_mode(regs)) {
13536 sp = regs->sp;
13537 ss = regs->ss & 0xffff;
13538 } else {
13539 @@ -314,7 +319,7 @@ void die(const char *str, struct pt_regs
13540 unsigned long flags = oops_begin();
13541 int sig = SIGSEGV;
13542
13543 - if (!user_mode_vm(regs))
13544 + if (!user_mode(regs))
13545 report_bug(regs->ip, regs);
13546
13547 if (__die(str, regs, err))
13548 diff -urNp linux-2.6.39.1/arch/x86/kernel/early_printk.c linux-2.6.39.1/arch/x86/kernel/early_printk.c
13549 --- linux-2.6.39.1/arch/x86/kernel/early_printk.c 2011-05-19 00:06:34.000000000 -0400
13550 +++ linux-2.6.39.1/arch/x86/kernel/early_printk.c 2011-05-22 19:36:30.000000000 -0400
13551 @@ -7,6 +7,7 @@
13552 #include <linux/pci_regs.h>
13553 #include <linux/pci_ids.h>
13554 #include <linux/errno.h>
13555 +#include <linux/sched.h>
13556 #include <asm/io.h>
13557 #include <asm/processor.h>
13558 #include <asm/fcntl.h>
13559 @@ -179,6 +180,8 @@ asmlinkage void early_printk(const char
13560 int n;
13561 va_list ap;
13562
13563 + pax_track_stack();
13564 +
13565 va_start(ap, fmt);
13566 n = vscnprintf(buf, sizeof(buf), fmt, ap);
13567 early_console->write(early_console, buf, n);
13568 diff -urNp linux-2.6.39.1/arch/x86/kernel/entry_32.S linux-2.6.39.1/arch/x86/kernel/entry_32.S
13569 --- linux-2.6.39.1/arch/x86/kernel/entry_32.S 2011-05-19 00:06:34.000000000 -0400
13570 +++ linux-2.6.39.1/arch/x86/kernel/entry_32.S 2011-05-23 17:07:00.000000000 -0400
13571 @@ -185,13 +185,146 @@
13572 /*CFI_REL_OFFSET gs, PT_GS*/
13573 .endm
13574 .macro SET_KERNEL_GS reg
13575 +
13576 +#ifdef CONFIG_CC_STACKPROTECTOR
13577 movl $(__KERNEL_STACK_CANARY), \reg
13578 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13579 + movl $(__USER_DS), \reg
13580 +#else
13581 + xorl \reg, \reg
13582 +#endif
13583 +
13584 movl \reg, %gs
13585 .endm
13586
13587 #endif /* CONFIG_X86_32_LAZY_GS */
13588
13589 -.macro SAVE_ALL
13590 +.macro pax_enter_kernel
13591 +#ifdef CONFIG_PAX_KERNEXEC
13592 + call pax_enter_kernel
13593 +#endif
13594 +.endm
13595 +
13596 +.macro pax_exit_kernel
13597 +#ifdef CONFIG_PAX_KERNEXEC
13598 + call pax_exit_kernel
13599 +#endif
13600 +.endm
13601 +
13602 +#ifdef CONFIG_PAX_KERNEXEC
13603 +ENTRY(pax_enter_kernel)
13604 +#ifdef CONFIG_PARAVIRT
13605 + pushl %eax
13606 + pushl %ecx
13607 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13608 + mov %eax, %esi
13609 +#else
13610 + mov %cr0, %esi
13611 +#endif
13612 + bts $16, %esi
13613 + jnc 1f
13614 + mov %cs, %esi
13615 + cmp $__KERNEL_CS, %esi
13616 + jz 3f
13617 + ljmp $__KERNEL_CS, $3f
13618 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13619 +2:
13620 +#ifdef CONFIG_PARAVIRT
13621 + mov %esi, %eax
13622 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13623 +#else
13624 + mov %esi, %cr0
13625 +#endif
13626 +3:
13627 +#ifdef CONFIG_PARAVIRT
13628 + popl %ecx
13629 + popl %eax
13630 +#endif
13631 + ret
13632 +ENDPROC(pax_enter_kernel)
13633 +
13634 +ENTRY(pax_exit_kernel)
13635 +#ifdef CONFIG_PARAVIRT
13636 + pushl %eax
13637 + pushl %ecx
13638 +#endif
13639 + mov %cs, %esi
13640 + cmp $__KERNEXEC_KERNEL_CS, %esi
13641 + jnz 2f
13642 +#ifdef CONFIG_PARAVIRT
13643 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13644 + mov %eax, %esi
13645 +#else
13646 + mov %cr0, %esi
13647 +#endif
13648 + btr $16, %esi
13649 + ljmp $__KERNEL_CS, $1f
13650 +1:
13651 +#ifdef CONFIG_PARAVIRT
13652 + mov %esi, %eax
13653 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13654 +#else
13655 + mov %esi, %cr0
13656 +#endif
13657 +2:
13658 +#ifdef CONFIG_PARAVIRT
13659 + popl %ecx
13660 + popl %eax
13661 +#endif
13662 + ret
13663 +ENDPROC(pax_exit_kernel)
13664 +#endif
13665 +
13666 +.macro pax_erase_kstack
13667 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13668 + call pax_erase_kstack
13669 +#endif
13670 +.endm
13671 +
13672 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13673 +/*
13674 + * ebp: thread_info
13675 + * ecx, edx: can be clobbered
13676 + */
13677 +ENTRY(pax_erase_kstack)
13678 + pushl %edi
13679 + pushl %eax
13680 +
13681 + mov TI_lowest_stack(%ebp), %edi
13682 + mov $-0xBEEF, %eax
13683 + std
13684 +
13685 +1: mov %edi, %ecx
13686 + and $THREAD_SIZE_asm - 1, %ecx
13687 + shr $2, %ecx
13688 + repne scasl
13689 + jecxz 2f
13690 +
13691 + cmp $2*16, %ecx
13692 + jc 2f
13693 +
13694 + mov $2*16, %ecx
13695 + repe scasl
13696 + jecxz 2f
13697 + jne 1b
13698 +
13699 +2: cld
13700 + mov %esp, %ecx
13701 + sub %edi, %ecx
13702 + shr $2, %ecx
13703 + rep stosl
13704 +
13705 + mov TI_task_thread_sp0(%ebp), %edi
13706 + sub $128, %edi
13707 + mov %edi, TI_lowest_stack(%ebp)
13708 +
13709 + popl %eax
13710 + popl %edi
13711 + ret
13712 +ENDPROC(pax_erase_kstack)
13713 +#endif
13714 +
13715 +.macro __SAVE_ALL _DS
13716 cld
13717 PUSH_GS
13718 pushl_cfi %fs
13719 @@ -214,7 +347,7 @@
13720 CFI_REL_OFFSET ecx, 0
13721 pushl_cfi %ebx
13722 CFI_REL_OFFSET ebx, 0
13723 - movl $(__USER_DS), %edx
13724 + movl $\_DS, %edx
13725 movl %edx, %ds
13726 movl %edx, %es
13727 movl $(__KERNEL_PERCPU), %edx
13728 @@ -222,6 +355,15 @@
13729 SET_KERNEL_GS %edx
13730 .endm
13731
13732 +.macro SAVE_ALL
13733 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13734 + __SAVE_ALL __KERNEL_DS
13735 + pax_enter_kernel
13736 +#else
13737 + __SAVE_ALL __USER_DS
13738 +#endif
13739 +.endm
13740 +
13741 .macro RESTORE_INT_REGS
13742 popl_cfi %ebx
13743 CFI_RESTORE ebx
13744 @@ -332,7 +474,15 @@ check_userspace:
13745 movb PT_CS(%esp), %al
13746 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13747 cmpl $USER_RPL, %eax
13748 +
13749 +#ifdef CONFIG_PAX_KERNEXEC
13750 + jae resume_userspace
13751 +
13752 + PAX_EXIT_KERNEL
13753 + jmp resume_kernel
13754 +#else
13755 jb resume_kernel # not returning to v8086 or userspace
13756 +#endif
13757
13758 ENTRY(resume_userspace)
13759 LOCKDEP_SYS_EXIT
13760 @@ -344,7 +494,7 @@ ENTRY(resume_userspace)
13761 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13762 # int/exception return?
13763 jne work_pending
13764 - jmp restore_all
13765 + jmp restore_all_pax
13766 END(ret_from_exception)
13767
13768 #ifdef CONFIG_PREEMPT
13769 @@ -394,23 +544,34 @@ sysenter_past_esp:
13770 /*CFI_REL_OFFSET cs, 0*/
13771 /*
13772 * Push current_thread_info()->sysenter_return to the stack.
13773 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13774 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
13775 */
13776 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13777 + pushl_cfi $0
13778 CFI_REL_OFFSET eip, 0
13779
13780 pushl_cfi %eax
13781 SAVE_ALL
13782 + GET_THREAD_INFO(%ebp)
13783 + movl TI_sysenter_return(%ebp),%ebp
13784 + movl %ebp,PT_EIP(%esp)
13785 ENABLE_INTERRUPTS(CLBR_NONE)
13786
13787 /*
13788 * Load the potential sixth argument from user stack.
13789 * Careful about security.
13790 */
13791 + movl PT_OLDESP(%esp),%ebp
13792 +
13793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13794 + mov PT_OLDSS(%esp),%ds
13795 +1: movl %ds:(%ebp),%ebp
13796 + push %ss
13797 + pop %ds
13798 +#else
13799 cmpl $__PAGE_OFFSET-3,%ebp
13800 jae syscall_fault
13801 1: movl (%ebp),%ebp
13802 +#endif
13803 +
13804 movl %ebp,PT_EBP(%esp)
13805 .section __ex_table,"a"
13806 .align 4
13807 @@ -433,12 +594,23 @@ sysenter_do_call:
13808 testl $_TIF_ALLWORK_MASK, %ecx
13809 jne sysexit_audit
13810 sysenter_exit:
13811 +
13812 +#ifdef CONFIG_PAX_RANDKSTACK
13813 + pushl_cfi %eax
13814 + call pax_randomize_kstack
13815 + popl_cfi %eax
13816 +#endif
13817 +
13818 + pax_erase_kstack
13819 +
13820 /* if something modifies registers it must also disable sysexit */
13821 movl PT_EIP(%esp), %edx
13822 movl PT_OLDESP(%esp), %ecx
13823 xorl %ebp,%ebp
13824 TRACE_IRQS_ON
13825 1: mov PT_FS(%esp), %fs
13826 +2: mov PT_DS(%esp), %ds
13827 +3: mov PT_ES(%esp), %es
13828 PTGS_TO_GS
13829 ENABLE_INTERRUPTS_SYSEXIT
13830
13831 @@ -455,6 +627,9 @@ sysenter_audit:
13832 movl %eax,%edx /* 2nd arg: syscall number */
13833 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13834 call audit_syscall_entry
13835 +
13836 + pax_erase_kstack
13837 +
13838 pushl_cfi %ebx
13839 movl PT_EAX(%esp),%eax /* reload syscall number */
13840 jmp sysenter_do_call
13841 @@ -481,11 +656,17 @@ sysexit_audit:
13842
13843 CFI_ENDPROC
13844 .pushsection .fixup,"ax"
13845 -2: movl $0,PT_FS(%esp)
13846 +4: movl $0,PT_FS(%esp)
13847 + jmp 1b
13848 +5: movl $0,PT_DS(%esp)
13849 + jmp 1b
13850 +6: movl $0,PT_ES(%esp)
13851 jmp 1b
13852 .section __ex_table,"a"
13853 .align 4
13854 - .long 1b,2b
13855 + .long 1b,4b
13856 + .long 2b,5b
13857 + .long 3b,6b
13858 .popsection
13859 PTGS_TO_GS_EX
13860 ENDPROC(ia32_sysenter_target)
13861 @@ -518,6 +699,14 @@ syscall_exit:
13862 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13863 jne syscall_exit_work
13864
13865 +restore_all_pax:
13866 +
13867 +#ifdef CONFIG_PAX_RANDKSTACK
13868 + call pax_randomize_kstack
13869 +#endif
13870 +
13871 + pax_erase_kstack
13872 +
13873 restore_all:
13874 TRACE_IRQS_IRET
13875 restore_all_notrace:
13876 @@ -577,14 +766,21 @@ ldt_ss:
13877 * compensating for the offset by changing to the ESPFIX segment with
13878 * a base address that matches for the difference.
13879 */
13880 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13881 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13882 mov %esp, %edx /* load kernel esp */
13883 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13884 mov %dx, %ax /* eax: new kernel esp */
13885 sub %eax, %edx /* offset (low word is 0) */
13886 +#ifdef CONFIG_SMP
13887 + movl PER_CPU_VAR(cpu_number), %ebx
13888 + shll $PAGE_SHIFT_asm, %ebx
13889 + addl $cpu_gdt_table, %ebx
13890 +#else
13891 + movl $cpu_gdt_table, %ebx
13892 +#endif
13893 shr $16, %edx
13894 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13895 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13896 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13897 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13898 pushl_cfi $__ESPFIX_SS
13899 pushl_cfi %eax /* new kernel esp */
13900 /* Disable interrupts, but do not irqtrace this section: we
13901 @@ -613,29 +809,23 @@ work_resched:
13902 movl TI_flags(%ebp), %ecx
13903 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13904 # than syscall tracing?
13905 - jz restore_all
13906 + jz restore_all_pax
13907 testb $_TIF_NEED_RESCHED, %cl
13908 jnz work_resched
13909
13910 work_notifysig: # deal with pending signals and
13911 # notify-resume requests
13912 + movl %esp, %eax
13913 #ifdef CONFIG_VM86
13914 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13915 - movl %esp, %eax
13916 - jne work_notifysig_v86 # returning to kernel-space or
13917 + jz 1f # returning to kernel-space or
13918 # vm86-space
13919 - xorl %edx, %edx
13920 - call do_notify_resume
13921 - jmp resume_userspace_sig
13922
13923 - ALIGN
13924 -work_notifysig_v86:
13925 pushl_cfi %ecx # save ti_flags for do_notify_resume
13926 call save_v86_state # %eax contains pt_regs pointer
13927 popl_cfi %ecx
13928 movl %eax, %esp
13929 -#else
13930 - movl %esp, %eax
13931 +1:
13932 #endif
13933 xorl %edx, %edx
13934 call do_notify_resume
13935 @@ -648,6 +838,9 @@ syscall_trace_entry:
13936 movl $-ENOSYS,PT_EAX(%esp)
13937 movl %esp, %eax
13938 call syscall_trace_enter
13939 +
13940 + pax_erase_kstack
13941 +
13942 /* What it returned is what we'll actually use. */
13943 cmpl $(nr_syscalls), %eax
13944 jnae syscall_call
13945 @@ -670,6 +863,10 @@ END(syscall_exit_work)
13946
13947 RING0_INT_FRAME # can't unwind into user space anyway
13948 syscall_fault:
13949 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13950 + push %ss
13951 + pop %ds
13952 +#endif
13953 GET_THREAD_INFO(%ebp)
13954 movl $-EFAULT,PT_EAX(%esp)
13955 jmp resume_userspace
13956 @@ -752,6 +949,36 @@ ptregs_clone:
13957 CFI_ENDPROC
13958 ENDPROC(ptregs_clone)
13959
13960 + ALIGN;
13961 +ENTRY(kernel_execve)
13962 + CFI_STARTPROC
13963 + pushl_cfi %ebp
13964 + sub $PT_OLDSS+4,%esp
13965 + pushl_cfi %edi
13966 + pushl_cfi %ecx
13967 + pushl_cfi %eax
13968 + lea 3*4(%esp),%edi
13969 + mov $PT_OLDSS/4+1,%ecx
13970 + xorl %eax,%eax
13971 + rep stosl
13972 + popl_cfi %eax
13973 + popl_cfi %ecx
13974 + popl_cfi %edi
13975 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13976 + pushl_cfi %esp
13977 + call sys_execve
13978 + add $4,%esp
13979 + CFI_ADJUST_CFA_OFFSET -4
13980 + GET_THREAD_INFO(%ebp)
13981 + test %eax,%eax
13982 + jz syscall_exit
13983 + add $PT_OLDSS+4,%esp
13984 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13985 + popl_cfi %ebp
13986 + ret
13987 + CFI_ENDPROC
13988 +ENDPROC(kernel_execve)
13989 +
13990 .macro FIXUP_ESPFIX_STACK
13991 /*
13992 * Switch back for ESPFIX stack to the normal zerobased stack
13993 @@ -761,8 +988,15 @@ ENDPROC(ptregs_clone)
13994 * normal stack and adjusts ESP with the matching offset.
13995 */
13996 /* fixup the stack */
13997 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13998 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13999 +#ifdef CONFIG_SMP
14000 + movl PER_CPU_VAR(cpu_number), %ebx
14001 + shll $PAGE_SHIFT_asm, %ebx
14002 + addl $cpu_gdt_table, %ebx
14003 +#else
14004 + movl $cpu_gdt_table, %ebx
14005 +#endif
14006 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14007 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14008 shl $16, %eax
14009 addl %esp, %eax /* the adjusted stack pointer */
14010 pushl_cfi $__KERNEL_DS
14011 @@ -1213,7 +1447,6 @@ return_to_handler:
14012 jmp *%ecx
14013 #endif
14014
14015 -.section .rodata,"a"
14016 #include "syscall_table_32.S"
14017
14018 syscall_table_size=(.-sys_call_table)
14019 @@ -1259,9 +1492,12 @@ error_code:
14020 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14021 REG_TO_PTGS %ecx
14022 SET_KERNEL_GS %ecx
14023 - movl $(__USER_DS), %ecx
14024 + movl $(__KERNEL_DS), %ecx
14025 movl %ecx, %ds
14026 movl %ecx, %es
14027 +
14028 + pax_enter_kernel
14029 +
14030 TRACE_IRQS_OFF
14031 movl %esp,%eax # pt_regs pointer
14032 call *%edi
14033 @@ -1346,6 +1582,9 @@ nmi_stack_correct:
14034 xorl %edx,%edx # zero error code
14035 movl %esp,%eax # pt_regs pointer
14036 call do_nmi
14037 +
14038 + pax_exit_kernel
14039 +
14040 jmp restore_all_notrace
14041 CFI_ENDPROC
14042
14043 @@ -1382,6 +1621,9 @@ nmi_espfix_stack:
14044 FIXUP_ESPFIX_STACK # %eax == %esp
14045 xorl %edx,%edx # zero error code
14046 call do_nmi
14047 +
14048 + pax_exit_kernel
14049 +
14050 RESTORE_REGS
14051 lss 12+4(%esp), %esp # back to espfix stack
14052 CFI_ADJUST_CFA_OFFSET -24
14053 diff -urNp linux-2.6.39.1/arch/x86/kernel/entry_64.S linux-2.6.39.1/arch/x86/kernel/entry_64.S
14054 --- linux-2.6.39.1/arch/x86/kernel/entry_64.S 2011-05-19 00:06:34.000000000 -0400
14055 +++ linux-2.6.39.1/arch/x86/kernel/entry_64.S 2011-05-23 17:10:49.000000000 -0400
14056 @@ -53,6 +53,7 @@
14057 #include <asm/paravirt.h>
14058 #include <asm/ftrace.h>
14059 #include <asm/percpu.h>
14060 +#include <asm/pgtable.h>
14061
14062 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14063 #include <linux/elf-em.h>
14064 @@ -176,6 +177,259 @@ ENTRY(native_usergs_sysret64)
14065 ENDPROC(native_usergs_sysret64)
14066 #endif /* CONFIG_PARAVIRT */
14067
14068 + .macro ljmpq sel, off
14069 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14070 + .byte 0x48; ljmp *1234f(%rip)
14071 + .pushsection .rodata
14072 + .align 16
14073 + 1234: .quad \off; .word \sel
14074 + .popsection
14075 +#else
14076 + pushq $\sel
14077 + pushq $\off
14078 + lretq
14079 +#endif
14080 + .endm
14081 +
14082 + .macro pax_enter_kernel
14083 +#ifdef CONFIG_PAX_KERNEXEC
14084 + call pax_enter_kernel
14085 +#endif
14086 + .endm
14087 +
14088 + .macro pax_exit_kernel
14089 +#ifdef CONFIG_PAX_KERNEXEC
14090 + call pax_exit_kernel
14091 +#endif
14092 + .endm
14093 +
14094 +#ifdef CONFIG_PAX_KERNEXEC
14095 +ENTRY(pax_enter_kernel)
14096 + pushq %rdi
14097 +
14098 +#ifdef CONFIG_PARAVIRT
14099 + PV_SAVE_REGS(CLBR_RDI)
14100 +#endif
14101 +
14102 + GET_CR0_INTO_RDI
14103 + bts $16,%rdi
14104 + jnc 1f
14105 + mov %cs,%edi
14106 + cmp $__KERNEL_CS,%edi
14107 + jz 3f
14108 + ljmpq __KERNEL_CS,3f
14109 +1: ljmpq __KERNEXEC_KERNEL_CS,2f
14110 +2: SET_RDI_INTO_CR0
14111 +3:
14112 +
14113 +#ifdef CONFIG_PARAVIRT
14114 + PV_RESTORE_REGS(CLBR_RDI)
14115 +#endif
14116 +
14117 + popq %rdi
14118 + retq
14119 +ENDPROC(pax_enter_kernel)
14120 +
14121 +ENTRY(pax_exit_kernel)
14122 + pushq %rdi
14123 +
14124 +#ifdef CONFIG_PARAVIRT
14125 + PV_SAVE_REGS(CLBR_RDI)
14126 +#endif
14127 +
14128 + mov %cs,%rdi
14129 + cmp $__KERNEXEC_KERNEL_CS,%edi
14130 + jnz 2f
14131 + GET_CR0_INTO_RDI
14132 + btr $16,%rdi
14133 + ljmpq __KERNEL_CS,1f
14134 +1: SET_RDI_INTO_CR0
14135 +2:
14136 +
14137 +#ifdef CONFIG_PARAVIRT
14138 + PV_RESTORE_REGS(CLBR_RDI);
14139 +#endif
14140 +
14141 + popq %rdi
14142 + retq
14143 +ENDPROC(pax_exit_kernel)
14144 +#endif
14145 +
14146 + .macro pax_enter_kernel_user
14147 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14148 + call pax_enter_kernel_user
14149 +#endif
14150 + .endm
14151 +
14152 + .macro pax_exit_kernel_user
14153 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14154 + call pax_exit_kernel_user
14155 +#endif
14156 +#ifdef CONFIG_PAX_RANDKSTACK
14157 + push %rax
14158 + call pax_randomize_kstack
14159 + pop %rax
14160 +#endif
14161 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14162 + call pax_erase_kstack
14163 +#endif
14164 + .endm
14165 +
14166 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14167 +ENTRY(pax_enter_kernel_user)
14168 + pushq %rdi
14169 + pushq %rbx
14170 +
14171 +#ifdef CONFIG_PARAVIRT
14172 + PV_SAVE_REGS(CLBR_RDI)
14173 +#endif
14174 +
14175 + GET_CR3_INTO_RDI
14176 + mov %rdi,%rbx
14177 + add $__START_KERNEL_map,%rbx
14178 + sub phys_base(%rip),%rbx
14179 +
14180 +#ifdef CONFIG_PARAVIRT
14181 + pushq %rdi
14182 + cmpl $0, pv_info+PARAVIRT_enabled
14183 + jz 1f
14184 + i = 0
14185 + .rept USER_PGD_PTRS
14186 + mov i*8(%rbx),%rsi
14187 + mov $0,%sil
14188 + lea i*8(%rbx),%rdi
14189 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14190 + i = i + 1
14191 + .endr
14192 + jmp 2f
14193 +1:
14194 +#endif
14195 +
14196 + i = 0
14197 + .rept USER_PGD_PTRS
14198 + movb $0,i*8(%rbx)
14199 + i = i + 1
14200 + .endr
14201 +
14202 +#ifdef CONFIG_PARAVIRT
14203 +2: popq %rdi
14204 +#endif
14205 + SET_RDI_INTO_CR3
14206 +
14207 +#ifdef CONFIG_PAX_KERNEXEC
14208 + GET_CR0_INTO_RDI
14209 + bts $16,%rdi
14210 + SET_RDI_INTO_CR0
14211 +#endif
14212 +
14213 +#ifdef CONFIG_PARAVIRT
14214 + PV_RESTORE_REGS(CLBR_RDI)
14215 +#endif
14216 +
14217 + popq %rbx
14218 + popq %rdi
14219 + retq
14220 +ENDPROC(pax_enter_kernel_user)
14221 +
14222 +ENTRY(pax_exit_kernel_user)
14223 + push %rdi
14224 +
14225 +#ifdef CONFIG_PARAVIRT
14226 + pushq %rbx
14227 + PV_SAVE_REGS(CLBR_RDI)
14228 +#endif
14229 +
14230 +#ifdef CONFIG_PAX_KERNEXEC
14231 + GET_CR0_INTO_RDI
14232 + btr $16,%rdi
14233 + SET_RDI_INTO_CR0
14234 +#endif
14235 +
14236 + GET_CR3_INTO_RDI
14237 + add $__START_KERNEL_map,%rdi
14238 + sub phys_base(%rip),%rdi
14239 +
14240 +#ifdef CONFIG_PARAVIRT
14241 + cmpl $0, pv_info+PARAVIRT_enabled
14242 + jz 1f
14243 + mov %rdi,%rbx
14244 + i = 0
14245 + .rept USER_PGD_PTRS
14246 + mov i*8(%rbx),%rsi
14247 + mov $0x67,%sil
14248 + lea i*8(%rbx),%rdi
14249 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14250 + i = i + 1
14251 + .endr
14252 + jmp 2f
14253 +1:
14254 +#endif
14255 +
14256 + i = 0
14257 + .rept USER_PGD_PTRS
14258 + movb $0x67,i*8(%rdi)
14259 + i = i + 1
14260 + .endr
14261 +
14262 +#ifdef CONFIG_PARAVIRT
14263 +2: PV_RESTORE_REGS(CLBR_RDI)
14264 + popq %rbx
14265 +#endif
14266 +
14267 + popq %rdi
14268 + retq
14269 +ENDPROC(pax_exit_kernel_user)
14270 +#endif
14271 +
14272 + .macro pax_erase_kstack
14273 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14274 + call pax_erase_kstack
14275 +#endif
14276 + .endm
14277 +
14278 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14279 +/*
14280 + * r10: thread_info
14281 + * rcx, rdx: can be clobbered
14282 + */
14283 +ENTRY(pax_erase_kstack)
14284 + pushq %rdi
14285 + pushq %rax
14286 +
14287 + GET_THREAD_INFO(%r10)
14288 + mov TI_lowest_stack(%r10), %rdi
14289 + mov $-0xBEEF, %rax
14290 + std
14291 +
14292 +1: mov %edi, %ecx
14293 + and $THREAD_SIZE_asm - 1, %ecx
14294 + shr $3, %ecx
14295 + repne scasq
14296 + jecxz 2f
14297 +
14298 + cmp $2*8, %ecx
14299 + jc 2f
14300 +
14301 + mov $2*8, %ecx
14302 + repe scasq
14303 + jecxz 2f
14304 + jne 1b
14305 +
14306 +2: cld
14307 + mov %esp, %ecx
14308 + sub %edi, %ecx
14309 + shr $3, %ecx
14310 + rep stosq
14311 +
14312 + mov TI_task_thread_sp0(%r10), %rdi
14313 + sub $256, %rdi
14314 + mov %rdi, TI_lowest_stack(%r10)
14315 +
14316 + popq %rax
14317 + popq %rdi
14318 + ret
14319 +ENDPROC(pax_erase_kstack)
14320 +#endif
14321
14322 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14323 #ifdef CONFIG_TRACE_IRQFLAGS
14324 @@ -318,7 +572,7 @@ ENTRY(save_args)
14325 leaq -RBP+8(%rsp),%rdi /* arg1 for handler */
14326 movq_cfi rbp, 8 /* push %rbp */
14327 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
14328 - testl $3, CS(%rdi)
14329 + testb $3, CS(%rdi)
14330 je 1f
14331 SWAPGS
14332 /*
14333 @@ -409,7 +663,7 @@ ENTRY(ret_from_fork)
14334
14335 RESTORE_REST
14336
14337 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14338 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14339 je int_ret_from_sys_call
14340
14341 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14342 @@ -455,7 +709,7 @@ END(ret_from_fork)
14343 ENTRY(system_call)
14344 CFI_STARTPROC simple
14345 CFI_SIGNAL_FRAME
14346 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14347 + CFI_DEF_CFA rsp,0
14348 CFI_REGISTER rip,rcx
14349 /*CFI_REGISTER rflags,r11*/
14350 SWAPGS_UNSAFE_STACK
14351 @@ -468,12 +722,13 @@ ENTRY(system_call_after_swapgs)
14352
14353 movq %rsp,PER_CPU_VAR(old_rsp)
14354 movq PER_CPU_VAR(kernel_stack),%rsp
14355 + pax_enter_kernel_user
14356 /*
14357 * No need to follow this irqs off/on section - it's straight
14358 * and short:
14359 */
14360 ENABLE_INTERRUPTS(CLBR_NONE)
14361 - SAVE_ARGS 8,1
14362 + SAVE_ARGS 8*6,1
14363 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14364 movq %rcx,RIP-ARGOFFSET(%rsp)
14365 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14366 @@ -502,6 +757,7 @@ sysret_check:
14367 andl %edi,%edx
14368 jnz sysret_careful
14369 CFI_REMEMBER_STATE
14370 + pax_exit_kernel_user
14371 /*
14372 * sysretq will re-enable interrupts:
14373 */
14374 @@ -560,6 +816,9 @@ auditsys:
14375 movq %rax,%rsi /* 2nd arg: syscall number */
14376 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14377 call audit_syscall_entry
14378 +
14379 + pax_erase_kstack
14380 +
14381 LOAD_ARGS 0 /* reload call-clobbered registers */
14382 jmp system_call_fastpath
14383
14384 @@ -590,6 +849,9 @@ tracesys:
14385 FIXUP_TOP_OF_STACK %rdi
14386 movq %rsp,%rdi
14387 call syscall_trace_enter
14388 +
14389 + pax_erase_kstack
14390 +
14391 /*
14392 * Reload arg registers from stack in case ptrace changed them.
14393 * We don't reload %rax because syscall_trace_enter() returned
14394 @@ -611,7 +873,7 @@ tracesys:
14395 GLOBAL(int_ret_from_sys_call)
14396 DISABLE_INTERRUPTS(CLBR_NONE)
14397 TRACE_IRQS_OFF
14398 - testl $3,CS-ARGOFFSET(%rsp)
14399 + testb $3,CS-ARGOFFSET(%rsp)
14400 je retint_restore_args
14401 movl $_TIF_ALLWORK_MASK,%edi
14402 /* edi: mask to check */
14403 @@ -793,6 +1055,16 @@ END(interrupt)
14404 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14405 call save_args
14406 PARTIAL_FRAME 0
14407 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14408 + testb $3, CS(%rdi)
14409 + jnz 1f
14410 + pax_enter_kernel
14411 + jmp 2f
14412 +1: pax_enter_kernel_user
14413 +2:
14414 +#else
14415 + pax_enter_kernel
14416 +#endif
14417 call \func
14418 .endm
14419
14420 @@ -825,7 +1097,7 @@ ret_from_intr:
14421 CFI_ADJUST_CFA_OFFSET -8
14422 exit_intr:
14423 GET_THREAD_INFO(%rcx)
14424 - testl $3,CS-ARGOFFSET(%rsp)
14425 + testb $3,CS-ARGOFFSET(%rsp)
14426 je retint_kernel
14427
14428 /* Interrupt came from user space */
14429 @@ -847,12 +1119,14 @@ retint_swapgs: /* return to user-space
14430 * The iretq could re-enable interrupts:
14431 */
14432 DISABLE_INTERRUPTS(CLBR_ANY)
14433 + pax_exit_kernel_user
14434 TRACE_IRQS_IRETQ
14435 SWAPGS
14436 jmp restore_args
14437
14438 retint_restore_args: /* return to kernel space */
14439 DISABLE_INTERRUPTS(CLBR_ANY)
14440 + pax_exit_kernel
14441 /*
14442 * The iretq could re-enable interrupts:
14443 */
14444 @@ -1027,6 +1301,16 @@ ENTRY(\sym)
14445 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14446 call error_entry
14447 DEFAULT_FRAME 0
14448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14449 + testb $3, CS(%rsp)
14450 + jnz 1f
14451 + pax_enter_kernel
14452 + jmp 2f
14453 +1: pax_enter_kernel_user
14454 +2:
14455 +#else
14456 + pax_enter_kernel
14457 +#endif
14458 movq %rsp,%rdi /* pt_regs pointer */
14459 xorl %esi,%esi /* no error code */
14460 call \do_sym
14461 @@ -1044,6 +1328,16 @@ ENTRY(\sym)
14462 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14463 call save_paranoid
14464 TRACE_IRQS_OFF
14465 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14466 + testb $3, CS(%rsp)
14467 + jnz 1f
14468 + pax_enter_kernel
14469 + jmp 2f
14470 +1: pax_enter_kernel_user
14471 +2:
14472 +#else
14473 + pax_enter_kernel
14474 +#endif
14475 movq %rsp,%rdi /* pt_regs pointer */
14476 xorl %esi,%esi /* no error code */
14477 call \do_sym
14478 @@ -1052,7 +1346,7 @@ ENTRY(\sym)
14479 END(\sym)
14480 .endm
14481
14482 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14483 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14484 .macro paranoidzeroentry_ist sym do_sym ist
14485 ENTRY(\sym)
14486 INTR_FRAME
14487 @@ -1062,8 +1356,24 @@ ENTRY(\sym)
14488 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14489 call save_paranoid
14490 TRACE_IRQS_OFF
14491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14492 + testb $3, CS(%rsp)
14493 + jnz 1f
14494 + pax_enter_kernel
14495 + jmp 2f
14496 +1: pax_enter_kernel_user
14497 +2:
14498 +#else
14499 + pax_enter_kernel
14500 +#endif
14501 movq %rsp,%rdi /* pt_regs pointer */
14502 xorl %esi,%esi /* no error code */
14503 +#ifdef CONFIG_SMP
14504 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14505 + lea init_tss(%r12), %r12
14506 +#else
14507 + lea init_tss(%rip), %r12
14508 +#endif
14509 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14510 call \do_sym
14511 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14512 @@ -1080,6 +1390,16 @@ ENTRY(\sym)
14513 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14514 call error_entry
14515 DEFAULT_FRAME 0
14516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14517 + testb $3, CS(%rsp)
14518 + jnz 1f
14519 + pax_enter_kernel
14520 + jmp 2f
14521 +1: pax_enter_kernel_user
14522 +2:
14523 +#else
14524 + pax_enter_kernel
14525 +#endif
14526 movq %rsp,%rdi /* pt_regs pointer */
14527 movq ORIG_RAX(%rsp),%rsi /* get error code */
14528 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14529 @@ -1099,6 +1419,16 @@ ENTRY(\sym)
14530 call save_paranoid
14531 DEFAULT_FRAME 0
14532 TRACE_IRQS_OFF
14533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14534 + testb $3, CS(%rsp)
14535 + jnz 1f
14536 + pax_enter_kernel
14537 + jmp 2f
14538 +1: pax_enter_kernel_user
14539 +2:
14540 +#else
14541 + pax_enter_kernel
14542 +#endif
14543 movq %rsp,%rdi /* pt_regs pointer */
14544 movq ORIG_RAX(%rsp),%rsi /* get error code */
14545 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14546 @@ -1361,14 +1691,27 @@ ENTRY(paranoid_exit)
14547 TRACE_IRQS_OFF
14548 testl %ebx,%ebx /* swapgs needed? */
14549 jnz paranoid_restore
14550 - testl $3,CS(%rsp)
14551 + testb $3,CS(%rsp)
14552 jnz paranoid_userspace
14553 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14554 + pax_exit_kernel
14555 + TRACE_IRQS_IRETQ 0
14556 + SWAPGS_UNSAFE_STACK
14557 + RESTORE_ALL 8
14558 + jmp irq_return
14559 +#endif
14560 paranoid_swapgs:
14561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14562 + pax_exit_kernel_user
14563 +#else
14564 + pax_exit_kernel
14565 +#endif
14566 TRACE_IRQS_IRETQ 0
14567 SWAPGS_UNSAFE_STACK
14568 RESTORE_ALL 8
14569 jmp irq_return
14570 paranoid_restore:
14571 + pax_exit_kernel
14572 TRACE_IRQS_IRETQ 0
14573 RESTORE_ALL 8
14574 jmp irq_return
14575 @@ -1426,7 +1769,7 @@ ENTRY(error_entry)
14576 movq_cfi r14, R14+8
14577 movq_cfi r15, R15+8
14578 xorl %ebx,%ebx
14579 - testl $3,CS+8(%rsp)
14580 + testb $3,CS+8(%rsp)
14581 je error_kernelspace
14582 error_swapgs:
14583 SWAPGS
14584 @@ -1490,6 +1833,16 @@ ENTRY(nmi)
14585 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14586 call save_paranoid
14587 DEFAULT_FRAME 0
14588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14589 + testb $3, CS(%rsp)
14590 + jnz 1f
14591 + pax_enter_kernel
14592 + jmp 2f
14593 +1: pax_enter_kernel_user
14594 +2:
14595 +#else
14596 + pax_enter_kernel
14597 +#endif
14598 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14599 movq %rsp,%rdi
14600 movq $-1,%rsi
14601 @@ -1500,11 +1853,25 @@ ENTRY(nmi)
14602 DISABLE_INTERRUPTS(CLBR_NONE)
14603 testl %ebx,%ebx /* swapgs needed? */
14604 jnz nmi_restore
14605 - testl $3,CS(%rsp)
14606 + testb $3,CS(%rsp)
14607 jnz nmi_userspace
14608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14609 + pax_exit_kernel
14610 + SWAPGS_UNSAFE_STACK
14611 + RESTORE_ALL 8
14612 + jmp irq_return
14613 +#endif
14614 nmi_swapgs:
14615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14616 + pax_exit_kernel_user
14617 +#else
14618 + pax_exit_kernel
14619 +#endif
14620 SWAPGS_UNSAFE_STACK
14621 + RESTORE_ALL 8
14622 + jmp irq_return
14623 nmi_restore:
14624 + pax_exit_kernel
14625 RESTORE_ALL 8
14626 jmp irq_return
14627 nmi_userspace:
14628 diff -urNp linux-2.6.39.1/arch/x86/kernel/ftrace.c linux-2.6.39.1/arch/x86/kernel/ftrace.c
14629 --- linux-2.6.39.1/arch/x86/kernel/ftrace.c 2011-05-19 00:06:34.000000000 -0400
14630 +++ linux-2.6.39.1/arch/x86/kernel/ftrace.c 2011-05-22 19:36:30.000000000 -0400
14631 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the
14632 static void *mod_code_newcode; /* holds the text to write to the IP */
14633
14634 static unsigned nmi_wait_count;
14635 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14636 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14637
14638 int ftrace_arch_read_dyn_info(char *buf, int size)
14639 {
14640 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14641
14642 r = snprintf(buf, size, "%u %u",
14643 nmi_wait_count,
14644 - atomic_read(&nmi_update_count));
14645 + atomic_read_unchecked(&nmi_update_count));
14646 return r;
14647 }
14648
14649 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14650
14651 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14652 smp_rmb();
14653 + pax_open_kernel();
14654 ftrace_mod_code();
14655 - atomic_inc(&nmi_update_count);
14656 + pax_close_kernel();
14657 + atomic_inc_unchecked(&nmi_update_count);
14658 }
14659 /* Must have previous changes seen before executions */
14660 smp_mb();
14661 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, uns
14662 {
14663 unsigned char replaced[MCOUNT_INSN_SIZE];
14664
14665 + ip = ktla_ktva(ip);
14666 +
14667 /*
14668 * Note: Due to modules and __init, code can
14669 * disappear and change, we need to protect against faulting
14670 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14671 unsigned char old[MCOUNT_INSN_SIZE], *new;
14672 int ret;
14673
14674 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14675 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14676 new = ftrace_call_replace(ip, (unsigned long)func);
14677 ret = ftrace_modify_code(ip, old, new);
14678
14679 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long
14680 {
14681 unsigned char code[MCOUNT_INSN_SIZE];
14682
14683 + ip = ktla_ktva(ip);
14684 +
14685 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14686 return -EFAULT;
14687
14688 diff -urNp linux-2.6.39.1/arch/x86/kernel/head32.c linux-2.6.39.1/arch/x86/kernel/head32.c
14689 --- linux-2.6.39.1/arch/x86/kernel/head32.c 2011-05-19 00:06:34.000000000 -0400
14690 +++ linux-2.6.39.1/arch/x86/kernel/head32.c 2011-05-22 19:36:30.000000000 -0400
14691 @@ -19,6 +19,7 @@
14692 #include <asm/io_apic.h>
14693 #include <asm/bios_ebda.h>
14694 #include <asm/tlbflush.h>
14695 +#include <asm/boot.h>
14696
14697 static void __init i386_default_early_setup(void)
14698 {
14699 @@ -34,7 +35,7 @@ void __init i386_start_kernel(void)
14700 {
14701 memblock_init();
14702
14703 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14704 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14705
14706 #ifdef CONFIG_BLK_DEV_INITRD
14707 /* Reserve INITRD */
14708 diff -urNp linux-2.6.39.1/arch/x86/kernel/head_32.S linux-2.6.39.1/arch/x86/kernel/head_32.S
14709 --- linux-2.6.39.1/arch/x86/kernel/head_32.S 2011-05-19 00:06:34.000000000 -0400
14710 +++ linux-2.6.39.1/arch/x86/kernel/head_32.S 2011-05-22 19:36:30.000000000 -0400
14711 @@ -25,6 +25,12 @@
14712 /* Physical address */
14713 #define pa(X) ((X) - __PAGE_OFFSET)
14714
14715 +#ifdef CONFIG_PAX_KERNEXEC
14716 +#define ta(X) (X)
14717 +#else
14718 +#define ta(X) ((X) - __PAGE_OFFSET)
14719 +#endif
14720 +
14721 /*
14722 * References to members of the new_cpu_data structure.
14723 */
14724 @@ -54,11 +60,7 @@
14725 * and small than max_low_pfn, otherwise will waste some page table entries
14726 */
14727
14728 -#if PTRS_PER_PMD > 1
14729 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14730 -#else
14731 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14732 -#endif
14733 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14734
14735 /* Number of possible pages in the lowmem region */
14736 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14737 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14738 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14739
14740 /*
14741 + * Real beginning of normal "text" segment
14742 + */
14743 +ENTRY(stext)
14744 +ENTRY(_stext)
14745 +
14746 +/*
14747 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14748 * %esi points to the real-mode code as a 32-bit pointer.
14749 * CS and DS must be 4 GB flat segments, but we don't depend on
14750 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14751 * can.
14752 */
14753 __HEAD
14754 +
14755 +#ifdef CONFIG_PAX_KERNEXEC
14756 + jmp startup_32
14757 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14758 +.fill PAGE_SIZE-5,1,0xcc
14759 +#endif
14760 +
14761 ENTRY(startup_32)
14762 movl pa(stack_start),%ecx
14763
14764 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14765 2:
14766 leal -__PAGE_OFFSET(%ecx),%esp
14767
14768 +#ifdef CONFIG_SMP
14769 + movl $pa(cpu_gdt_table),%edi
14770 + movl $__per_cpu_load,%eax
14771 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14772 + rorl $16,%eax
14773 + movb %al,__KERNEL_PERCPU + 4(%edi)
14774 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14775 + movl $__per_cpu_end - 1,%eax
14776 + subl $__per_cpu_start,%eax
14777 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14778 +#endif
14779 +
14780 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14781 + movl $NR_CPUS,%ecx
14782 + movl $pa(cpu_gdt_table),%edi
14783 +1:
14784 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14785 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14786 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14787 + addl $PAGE_SIZE_asm,%edi
14788 + loop 1b
14789 +#endif
14790 +
14791 +#ifdef CONFIG_PAX_KERNEXEC
14792 + movl $pa(boot_gdt),%edi
14793 + movl $__LOAD_PHYSICAL_ADDR,%eax
14794 + movw %ax,__BOOT_CS + 2(%edi)
14795 + rorl $16,%eax
14796 + movb %al,__BOOT_CS + 4(%edi)
14797 + movb %ah,__BOOT_CS + 7(%edi)
14798 + rorl $16,%eax
14799 +
14800 + ljmp $(__BOOT_CS),$1f
14801 +1:
14802 +
14803 + movl $NR_CPUS,%ecx
14804 + movl $pa(cpu_gdt_table),%edi
14805 + addl $__PAGE_OFFSET,%eax
14806 +1:
14807 + movw %ax,__KERNEL_CS + 2(%edi)
14808 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14809 + rorl $16,%eax
14810 + movb %al,__KERNEL_CS + 4(%edi)
14811 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14812 + movb %ah,__KERNEL_CS + 7(%edi)
14813 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14814 + rorl $16,%eax
14815 + addl $PAGE_SIZE_asm,%edi
14816 + loop 1b
14817 +#endif
14818 +
14819 /*
14820 * Clear BSS first so that there are no surprises...
14821 */
14822 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14823 movl %eax, pa(max_pfn_mapped)
14824
14825 /* Do early initialization of the fixmap area */
14826 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14827 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14828 +#ifdef CONFIG_COMPAT_VDSO
14829 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14830 +#else
14831 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14832 +#endif
14833 #else /* Not PAE */
14834
14835 page_pde_offset = (__PAGE_OFFSET >> 20);
14836 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14837 movl %eax, pa(max_pfn_mapped)
14838
14839 /* Do early initialization of the fixmap area */
14840 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14841 - movl %eax,pa(initial_page_table+0xffc)
14842 +#ifdef CONFIG_COMPAT_VDSO
14843 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14844 +#else
14845 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14846 +#endif
14847 #endif
14848
14849 #ifdef CONFIG_PARAVIRT
14850 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14851 cmpl $num_subarch_entries, %eax
14852 jae bad_subarch
14853
14854 - movl pa(subarch_entries)(,%eax,4), %eax
14855 - subl $__PAGE_OFFSET, %eax
14856 - jmp *%eax
14857 + jmp *pa(subarch_entries)(,%eax,4)
14858
14859 bad_subarch:
14860 WEAK(lguest_entry)
14861 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14862 __INITDATA
14863
14864 subarch_entries:
14865 - .long default_entry /* normal x86/PC */
14866 - .long lguest_entry /* lguest hypervisor */
14867 - .long xen_entry /* Xen hypervisor */
14868 - .long default_entry /* Moorestown MID */
14869 + .long ta(default_entry) /* normal x86/PC */
14870 + .long ta(lguest_entry) /* lguest hypervisor */
14871 + .long ta(xen_entry) /* Xen hypervisor */
14872 + .long ta(default_entry) /* Moorestown MID */
14873 num_subarch_entries = (. - subarch_entries) / 4
14874 .previous
14875 #else
14876 @@ -312,6 +382,7 @@ default_entry:
14877 orl %edx,%eax
14878 movl %eax,%cr4
14879
14880 +#ifdef CONFIG_X86_PAE
14881 testb $X86_CR4_PAE, %al # check if PAE is enabled
14882 jz 6f
14883
14884 @@ -340,6 +411,9 @@ default_entry:
14885 /* Make changes effective */
14886 wrmsr
14887
14888 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14889 +#endif
14890 +
14891 6:
14892
14893 /*
14894 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14895 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14896 movl %eax,%ss # after changing gdt.
14897
14898 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
14899 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14900 movl %eax,%ds
14901 movl %eax,%es
14902
14903 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14904 */
14905 cmpb $0,ready
14906 jne 1f
14907 - movl $gdt_page,%eax
14908 + movl $cpu_gdt_table,%eax
14909 movl $stack_canary,%ecx
14910 +#ifdef CONFIG_SMP
14911 + addl $__per_cpu_load,%ecx
14912 +#endif
14913 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14914 shrl $16, %ecx
14915 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14916 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14917 1:
14918 -#endif
14919 movl $(__KERNEL_STACK_CANARY),%eax
14920 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14921 + movl $(__USER_DS),%eax
14922 +#else
14923 + xorl %eax,%eax
14924 +#endif
14925 movl %eax,%gs
14926
14927 xorl %eax,%eax # Clear LDT
14928 @@ -558,22 +639,22 @@ early_page_fault:
14929 jmp early_fault
14930
14931 early_fault:
14932 - cld
14933 #ifdef CONFIG_PRINTK
14934 + cmpl $1,%ss:early_recursion_flag
14935 + je hlt_loop
14936 + incl %ss:early_recursion_flag
14937 + cld
14938 pusha
14939 movl $(__KERNEL_DS),%eax
14940 movl %eax,%ds
14941 movl %eax,%es
14942 - cmpl $2,early_recursion_flag
14943 - je hlt_loop
14944 - incl early_recursion_flag
14945 movl %cr2,%eax
14946 pushl %eax
14947 pushl %edx /* trapno */
14948 pushl $fault_msg
14949 call printk
14950 +; call dump_stack
14951 #endif
14952 - call dump_stack
14953 hlt_loop:
14954 hlt
14955 jmp hlt_loop
14956 @@ -581,8 +662,11 @@ hlt_loop:
14957 /* This is the default interrupt "handler" :-) */
14958 ALIGN
14959 ignore_int:
14960 - cld
14961 #ifdef CONFIG_PRINTK
14962 + cmpl $2,%ss:early_recursion_flag
14963 + je hlt_loop
14964 + incl %ss:early_recursion_flag
14965 + cld
14966 pushl %eax
14967 pushl %ecx
14968 pushl %edx
14969 @@ -591,9 +675,6 @@ ignore_int:
14970 movl $(__KERNEL_DS),%eax
14971 movl %eax,%ds
14972 movl %eax,%es
14973 - cmpl $2,early_recursion_flag
14974 - je hlt_loop
14975 - incl early_recursion_flag
14976 pushl 16(%esp)
14977 pushl 24(%esp)
14978 pushl 32(%esp)
14979 @@ -622,29 +703,43 @@ ENTRY(initial_code)
14980 /*
14981 * BSS section
14982 */
14983 -__PAGE_ALIGNED_BSS
14984 - .align PAGE_SIZE
14985 #ifdef CONFIG_X86_PAE
14986 +.section .initial_pg_pmd,"a",@progbits
14987 initial_pg_pmd:
14988 .fill 1024*KPMDS,4,0
14989 #else
14990 +.section .initial_page_table,"a",@progbits
14991 ENTRY(initial_page_table)
14992 .fill 1024,4,0
14993 #endif
14994 +.section .initial_pg_fixmap,"a",@progbits
14995 initial_pg_fixmap:
14996 .fill 1024,4,0
14997 +.section .empty_zero_page,"a",@progbits
14998 ENTRY(empty_zero_page)
14999 .fill 4096,1,0
15000 +.section .swapper_pg_dir,"a",@progbits
15001 ENTRY(swapper_pg_dir)
15002 +#ifdef CONFIG_X86_PAE
15003 + .fill 4,8,0
15004 +#else
15005 .fill 1024,4,0
15006 +#endif
15007 +
15008 +/*
15009 + * The IDT has to be page-aligned to simplify the Pentium
15010 + * F0 0F bug workaround.. We have a special link segment
15011 + * for this.
15012 + */
15013 +.section .idt,"a",@progbits
15014 +ENTRY(idt_table)
15015 + .fill 256,8,0
15016
15017 /*
15018 * This starts the data section.
15019 */
15020 #ifdef CONFIG_X86_PAE
15021 -__PAGE_ALIGNED_DATA
15022 - /* Page-aligned for the benefit of paravirt? */
15023 - .align PAGE_SIZE
15024 +.section .initial_page_table,"a",@progbits
15025 ENTRY(initial_page_table)
15026 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15027 # if KPMDS == 3
15028 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15029 # error "Kernel PMDs should be 1, 2 or 3"
15030 # endif
15031 .align PAGE_SIZE /* needs to be page-sized too */
15032 +
15033 +#ifdef CONFIG_PAX_PER_CPU_PGD
15034 +ENTRY(cpu_pgd)
15035 + .rept NR_CPUS
15036 + .fill 4,8,0
15037 + .endr
15038 +#endif
15039 +
15040 #endif
15041
15042 .data
15043 .balign 4
15044 ENTRY(stack_start)
15045 - .long init_thread_union+THREAD_SIZE
15046 + .long init_thread_union+THREAD_SIZE-8
15047 +
15048 +ready: .byte 0
15049
15050 +.section .rodata,"a",@progbits
15051 early_recursion_flag:
15052 .long 0
15053
15054 -ready: .byte 0
15055 -
15056 int_msg:
15057 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15058
15059 @@ -707,7 +811,7 @@ fault_msg:
15060 .word 0 # 32 bit align gdt_desc.address
15061 boot_gdt_descr:
15062 .word __BOOT_DS+7
15063 - .long boot_gdt - __PAGE_OFFSET
15064 + .long pa(boot_gdt)
15065
15066 .word 0 # 32-bit align idt_desc.address
15067 idt_descr:
15068 @@ -718,7 +822,7 @@ idt_descr:
15069 .word 0 # 32 bit align gdt_desc.address
15070 ENTRY(early_gdt_descr)
15071 .word GDT_ENTRIES*8-1
15072 - .long gdt_page /* Overwritten for secondary CPUs */
15073 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
15074
15075 /*
15076 * The boot_gdt must mirror the equivalent in setup.S and is
15077 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15078 .align L1_CACHE_BYTES
15079 ENTRY(boot_gdt)
15080 .fill GDT_ENTRY_BOOT_CS,8,0
15081 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15082 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15083 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15084 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15085 +
15086 + .align PAGE_SIZE_asm
15087 +ENTRY(cpu_gdt_table)
15088 + .rept NR_CPUS
15089 + .quad 0x0000000000000000 /* NULL descriptor */
15090 + .quad 0x0000000000000000 /* 0x0b reserved */
15091 + .quad 0x0000000000000000 /* 0x13 reserved */
15092 + .quad 0x0000000000000000 /* 0x1b reserved */
15093 +
15094 +#ifdef CONFIG_PAX_KERNEXEC
15095 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15096 +#else
15097 + .quad 0x0000000000000000 /* 0x20 unused */
15098 +#endif
15099 +
15100 + .quad 0x0000000000000000 /* 0x28 unused */
15101 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15102 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15103 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15104 + .quad 0x0000000000000000 /* 0x4b reserved */
15105 + .quad 0x0000000000000000 /* 0x53 reserved */
15106 + .quad 0x0000000000000000 /* 0x5b reserved */
15107 +
15108 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15109 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15110 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15111 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15112 +
15113 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15114 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15115 +
15116 + /*
15117 + * Segments used for calling PnP BIOS have byte granularity.
15118 + * The code segments and data segments have fixed 64k limits,
15119 + * the transfer segment sizes are set at run time.
15120 + */
15121 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
15122 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
15123 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
15124 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
15125 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
15126 +
15127 + /*
15128 + * The APM segments have byte granularity and their bases
15129 + * are set at run time. All have 64k limits.
15130 + */
15131 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15132 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15133 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
15134 +
15135 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15136 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15137 + .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
15138 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15139 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15140 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15141 +
15142 + /* Be sure this is zeroed to avoid false validations in Xen */
15143 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15144 + .endr
15145 diff -urNp linux-2.6.39.1/arch/x86/kernel/head_64.S linux-2.6.39.1/arch/x86/kernel/head_64.S
15146 --- linux-2.6.39.1/arch/x86/kernel/head_64.S 2011-05-19 00:06:34.000000000 -0400
15147 +++ linux-2.6.39.1/arch/x86/kernel/head_64.S 2011-05-22 19:36:30.000000000 -0400
15148 @@ -19,6 +19,7 @@
15149 #include <asm/cache.h>
15150 #include <asm/processor-flags.h>
15151 #include <asm/percpu.h>
15152 +#include <asm/cpufeature.h>
15153
15154 #ifdef CONFIG_PARAVIRT
15155 #include <asm/asm-offsets.h>
15156 @@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
15157 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15158 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15159 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15160 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15161 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15162 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15163 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15164
15165 .text
15166 __HEAD
15167 @@ -85,35 +90,22 @@ startup_64:
15168 */
15169 addq %rbp, init_level4_pgt + 0(%rip)
15170 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15171 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15172 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15173 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15174
15175 addq %rbp, level3_ident_pgt + 0(%rip)
15176 +#ifndef CONFIG_XEN
15177 + addq %rbp, level3_ident_pgt + 8(%rip)
15178 +#endif
15179
15180 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15181 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15182 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15183
15184 - addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15185 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15186 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15187
15188 - /* Add an Identity mapping if I am above 1G */
15189 - leaq _text(%rip), %rdi
15190 - andq $PMD_PAGE_MASK, %rdi
15191 -
15192 - movq %rdi, %rax
15193 - shrq $PUD_SHIFT, %rax
15194 - andq $(PTRS_PER_PUD - 1), %rax
15195 - jz ident_complete
15196 -
15197 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15198 - leaq level3_ident_pgt(%rip), %rbx
15199 - movq %rdx, 0(%rbx, %rax, 8)
15200 -
15201 - movq %rdi, %rax
15202 - shrq $PMD_SHIFT, %rax
15203 - andq $(PTRS_PER_PMD - 1), %rax
15204 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15205 - leaq level2_spare_pgt(%rip), %rbx
15206 - movq %rdx, 0(%rbx, %rax, 8)
15207 -ident_complete:
15208 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15209 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15210
15211 /*
15212 * Fixup the kernel text+data virtual addresses. Note that
15213 @@ -160,8 +152,8 @@ ENTRY(secondary_startup_64)
15214 * after the boot processor executes this code.
15215 */
15216
15217 - /* Enable PAE mode and PGE */
15218 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15219 + /* Enable PAE mode and PSE/PGE */
15220 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15221 movq %rax, %cr4
15222
15223 /* Setup early boot stage 4 level pagetables. */
15224 @@ -183,9 +175,14 @@ ENTRY(secondary_startup_64)
15225 movl $MSR_EFER, %ecx
15226 rdmsr
15227 btsl $_EFER_SCE, %eax /* Enable System Call */
15228 - btl $20,%edi /* No Execute supported? */
15229 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15230 jnc 1f
15231 btsl $_EFER_NX, %eax
15232 + leaq init_level4_pgt(%rip), %rdi
15233 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15234 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15235 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15236 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15237 1: wrmsr /* Make changes effective */
15238
15239 /* Setup cr0 */
15240 @@ -269,7 +266,7 @@ ENTRY(secondary_startup_64)
15241 bad_address:
15242 jmp bad_address
15243
15244 - .section ".init.text","ax"
15245 + __INIT
15246 #ifdef CONFIG_EARLY_PRINTK
15247 .globl early_idt_handlers
15248 early_idt_handlers:
15249 @@ -314,18 +311,23 @@ ENTRY(early_idt_handler)
15250 #endif /* EARLY_PRINTK */
15251 1: hlt
15252 jmp 1b
15253 + .previous
15254
15255 #ifdef CONFIG_EARLY_PRINTK
15256 + __INITDATA
15257 early_recursion_flag:
15258 .long 0
15259 + .previous
15260
15261 + .section .rodata,"a",@progbits
15262 early_idt_msg:
15263 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15264 early_idt_ripmsg:
15265 .asciz "RIP %s\n"
15266 -#endif /* CONFIG_EARLY_PRINTK */
15267 .previous
15268 +#endif /* CONFIG_EARLY_PRINTK */
15269
15270 + .section .rodata,"a",@progbits
15271 #define NEXT_PAGE(name) \
15272 .balign PAGE_SIZE; \
15273 ENTRY(name)
15274 @@ -338,7 +340,6 @@ ENTRY(name)
15275 i = i + 1 ; \
15276 .endr
15277
15278 - .data
15279 /*
15280 * This default setting generates an ident mapping at address 0x100000
15281 * and a mapping for the kernel that precisely maps virtual address
15282 @@ -349,13 +350,36 @@ NEXT_PAGE(init_level4_pgt)
15283 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15284 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15285 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15286 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15287 + .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
15288 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15289 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15290 .org init_level4_pgt + L4_START_KERNEL*8, 0
15291 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15292 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15293
15294 +#ifdef CONFIG_PAX_PER_CPU_PGD
15295 +NEXT_PAGE(cpu_pgd)
15296 + .rept NR_CPUS
15297 + .fill 512,8,0
15298 + .endr
15299 +#endif
15300 +
15301 NEXT_PAGE(level3_ident_pgt)
15302 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15303 +#ifdef CONFIG_XEN
15304 .fill 511,8,0
15305 +#else
15306 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15307 + .fill 510,8,0
15308 +#endif
15309 +
15310 +NEXT_PAGE(level3_vmalloc_pgt)
15311 + .fill 512,8,0
15312 +
15313 +NEXT_PAGE(level3_vmemmap_pgt)
15314 + .fill L3_VMEMMAP_START,8,0
15315 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15316
15317 NEXT_PAGE(level3_kernel_pgt)
15318 .fill L3_START_KERNEL,8,0
15319 @@ -363,20 +387,23 @@ NEXT_PAGE(level3_kernel_pgt)
15320 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15321 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15322
15323 +NEXT_PAGE(level2_vmemmap_pgt)
15324 + .fill 512,8,0
15325 +
15326 NEXT_PAGE(level2_fixmap_pgt)
15327 - .fill 506,8,0
15328 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15329 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15330 - .fill 5,8,0
15331 + .fill 507,8,0
15332 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15333 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15334 + .fill 4,8,0
15335
15336 -NEXT_PAGE(level1_fixmap_pgt)
15337 +NEXT_PAGE(level1_vsyscall_pgt)
15338 .fill 512,8,0
15339
15340 -NEXT_PAGE(level2_ident_pgt)
15341 - /* Since I easily can, map the first 1G.
15342 + /* Since I easily can, map the first 2G.
15343 * Don't set NX because code runs from these pages.
15344 */
15345 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15346 +NEXT_PAGE(level2_ident_pgt)
15347 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15348
15349 NEXT_PAGE(level2_kernel_pgt)
15350 /*
15351 @@ -389,33 +416,55 @@ NEXT_PAGE(level2_kernel_pgt)
15352 * If you want to increase this then increase MODULES_VADDR
15353 * too.)
15354 */
15355 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15356 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15357 -
15358 -NEXT_PAGE(level2_spare_pgt)
15359 - .fill 512, 8, 0
15360 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15361
15362 #undef PMDS
15363 #undef NEXT_PAGE
15364
15365 - .data
15366 + .align PAGE_SIZE
15367 +ENTRY(cpu_gdt_table)
15368 + .rept NR_CPUS
15369 + .quad 0x0000000000000000 /* NULL descriptor */
15370 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15371 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15372 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15373 + .quad 0x00cffb000000ffff /* __USER32_CS */
15374 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15375 + .quad 0x00affb000000ffff /* __USER_CS */
15376 +
15377 +#ifdef CONFIG_PAX_KERNEXEC
15378 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15379 +#else
15380 + .quad 0x0 /* unused */
15381 +#endif
15382 +
15383 + .quad 0,0 /* TSS */
15384 + .quad 0,0 /* LDT */
15385 + .quad 0,0,0 /* three TLS descriptors */
15386 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15387 + /* asm/segment.h:GDT_ENTRIES must match this */
15388 +
15389 + /* zero the remaining page */
15390 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15391 + .endr
15392 +
15393 .align 16
15394 .globl early_gdt_descr
15395 early_gdt_descr:
15396 .word GDT_ENTRIES*8-1
15397 early_gdt_descr_base:
15398 - .quad INIT_PER_CPU_VAR(gdt_page)
15399 + .quad cpu_gdt_table
15400
15401 ENTRY(phys_base)
15402 /* This must match the first entry in level2_kernel_pgt */
15403 .quad 0x0000000000000000
15404
15405 #include "../../x86/xen/xen-head.S"
15406 -
15407 - .section .bss, "aw", @nobits
15408 +
15409 + .section .rodata,"a",@progbits
15410 .align L1_CACHE_BYTES
15411 ENTRY(idt_table)
15412 - .skip IDT_ENTRIES * 16
15413 + .fill 512,8,0
15414
15415 __PAGE_ALIGNED_BSS
15416 .align PAGE_SIZE
15417 diff -urNp linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c
15418 --- linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c 2011-05-19 00:06:34.000000000 -0400
15419 +++ linux-2.6.39.1/arch/x86/kernel/i386_ksyms_32.c 2011-05-22 19:36:30.000000000 -0400
15420 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15421 EXPORT_SYMBOL(cmpxchg8b_emu);
15422 #endif
15423
15424 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15425 +
15426 /* Networking helper routines. */
15427 EXPORT_SYMBOL(csum_partial_copy_generic);
15428 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15429 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15430
15431 EXPORT_SYMBOL(__get_user_1);
15432 EXPORT_SYMBOL(__get_user_2);
15433 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15434
15435 EXPORT_SYMBOL(csum_partial);
15436 EXPORT_SYMBOL(empty_zero_page);
15437 +
15438 +#ifdef CONFIG_PAX_KERNEXEC
15439 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15440 +#endif
15441 diff -urNp linux-2.6.39.1/arch/x86/kernel/i8259.c linux-2.6.39.1/arch/x86/kernel/i8259.c
15442 --- linux-2.6.39.1/arch/x86/kernel/i8259.c 2011-05-19 00:06:34.000000000 -0400
15443 +++ linux-2.6.39.1/arch/x86/kernel/i8259.c 2011-05-22 19:36:30.000000000 -0400
15444 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15445 "spurious 8259A interrupt: IRQ%d.\n", irq);
15446 spurious_irq_mask |= irqmask;
15447 }
15448 - atomic_inc(&irq_err_count);
15449 + atomic_inc_unchecked(&irq_err_count);
15450 /*
15451 * Theoretically we do not have to handle this IRQ,
15452 * but in Linux this does not cause problems and is
15453 diff -urNp linux-2.6.39.1/arch/x86/kernel/init_task.c linux-2.6.39.1/arch/x86/kernel/init_task.c
15454 --- linux-2.6.39.1/arch/x86/kernel/init_task.c 2011-05-19 00:06:34.000000000 -0400
15455 +++ linux-2.6.39.1/arch/x86/kernel/init_task.c 2011-05-22 19:36:30.000000000 -0400
15456 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15457 * way process stacks are handled. This is done by having a special
15458 * "init_task" linker map entry..
15459 */
15460 -union thread_union init_thread_union __init_task_data =
15461 - { INIT_THREAD_INFO(init_task) };
15462 +union thread_union init_thread_union __init_task_data;
15463
15464 /*
15465 * Initial task structure.
15466 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15467 * section. Since TSS's are completely CPU-local, we want them
15468 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15469 */
15470 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15471 -
15472 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15473 +EXPORT_SYMBOL(init_tss);
15474 diff -urNp linux-2.6.39.1/arch/x86/kernel/ioport.c linux-2.6.39.1/arch/x86/kernel/ioport.c
15475 --- linux-2.6.39.1/arch/x86/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
15476 +++ linux-2.6.39.1/arch/x86/kernel/ioport.c 2011-05-22 19:41:32.000000000 -0400
15477 @@ -6,6 +6,7 @@
15478 #include <linux/sched.h>
15479 #include <linux/kernel.h>
15480 #include <linux/capability.h>
15481 +#include <linux/security.h>
15482 #include <linux/errno.h>
15483 #include <linux/types.h>
15484 #include <linux/ioport.h>
15485 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long
15486
15487 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15488 return -EINVAL;
15489 +#ifdef CONFIG_GRKERNSEC_IO
15490 + if (turn_on && grsec_disable_privio) {
15491 + gr_handle_ioperm();
15492 + return -EPERM;
15493 + }
15494 +#endif
15495 if (turn_on && !capable(CAP_SYS_RAWIO))
15496 return -EPERM;
15497
15498 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long
15499 * because the ->io_bitmap_max value must match the bitmap
15500 * contents:
15501 */
15502 - tss = &per_cpu(init_tss, get_cpu());
15503 + tss = init_tss + get_cpu();
15504
15505 if (turn_on)
15506 bitmap_clear(t->io_bitmap_ptr, from, num);
15507 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct
15508 return -EINVAL;
15509 /* Trying to gain more privileges? */
15510 if (level > old) {
15511 +#ifdef CONFIG_GRKERNSEC_IO
15512 + if (grsec_disable_privio) {
15513 + gr_handle_iopl();
15514 + return -EPERM;
15515 + }
15516 +#endif
15517 if (!capable(CAP_SYS_RAWIO))
15518 return -EPERM;
15519 }
15520 diff -urNp linux-2.6.39.1/arch/x86/kernel/irq_32.c linux-2.6.39.1/arch/x86/kernel/irq_32.c
15521 --- linux-2.6.39.1/arch/x86/kernel/irq_32.c 2011-05-19 00:06:34.000000000 -0400
15522 +++ linux-2.6.39.1/arch/x86/kernel/irq_32.c 2011-05-22 19:36:30.000000000 -0400
15523 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15524 __asm__ __volatile__("andl %%esp,%0" :
15525 "=r" (sp) : "0" (THREAD_SIZE - 1));
15526
15527 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15528 + return sp < STACK_WARN;
15529 }
15530
15531 static void print_stack_overflow(void)
15532 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(
15533 * per-CPU IRQ handling contexts (thread information and stack)
15534 */
15535 union irq_ctx {
15536 - struct thread_info tinfo;
15537 - u32 stack[THREAD_SIZE/sizeof(u32)];
15538 + unsigned long previous_esp;
15539 + u32 stack[THREAD_SIZE/sizeof(u32)];
15540 } __attribute__((aligned(THREAD_SIZE)));
15541
15542 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15543 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, vo
15544 static inline int
15545 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15546 {
15547 - union irq_ctx *curctx, *irqctx;
15548 + union irq_ctx *irqctx;
15549 u32 *isp, arg1, arg2;
15550
15551 - curctx = (union irq_ctx *) current_thread_info();
15552 irqctx = __this_cpu_read(hardirq_ctx);
15553
15554 /*
15555 @@ -87,21 +86,17 @@ execute_on_irq_stack(int overflow, struc
15556 * handler) we can't do that and just have to keep using the
15557 * current stack (which is the irq stack already after all)
15558 */
15559 - if (unlikely(curctx == irqctx))
15560 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15561 return 0;
15562
15563 /* build the stack frame on the IRQ stack */
15564 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15565 - irqctx->tinfo.task = curctx->tinfo.task;
15566 - irqctx->tinfo.previous_esp = current_stack_pointer;
15567 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15568 + irqctx->previous_esp = current_stack_pointer;
15569 + add_preempt_count(HARDIRQ_OFFSET);
15570
15571 - /*
15572 - * Copy the softirq bits in preempt_count so that the
15573 - * softirq checks work in the hardirq context.
15574 - */
15575 - irqctx->tinfo.preempt_count =
15576 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15577 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15579 + __set_fs(MAKE_MM_SEG(0));
15580 +#endif
15581
15582 if (unlikely(overflow))
15583 call_on_stack(print_stack_overflow, isp);
15584 @@ -113,6 +108,12 @@ execute_on_irq_stack(int overflow, struc
15585 : "0" (irq), "1" (desc), "2" (isp),
15586 "D" (desc->handle_irq)
15587 : "memory", "cc", "ecx");
15588 +
15589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15590 + __set_fs(current_thread_info()->addr_limit);
15591 +#endif
15592 +
15593 + sub_preempt_count(HARDIRQ_OFFSET);
15594 return 1;
15595 }
15596
15597 @@ -121,29 +122,11 @@ execute_on_irq_stack(int overflow, struc
15598 */
15599 void __cpuinit irq_ctx_init(int cpu)
15600 {
15601 - union irq_ctx *irqctx;
15602 -
15603 if (per_cpu(hardirq_ctx, cpu))
15604 return;
15605
15606 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15607 - THREAD_FLAGS,
15608 - THREAD_ORDER));
15609 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15610 - irqctx->tinfo.cpu = cpu;
15611 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15612 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15613 -
15614 - per_cpu(hardirq_ctx, cpu) = irqctx;
15615 -
15616 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15617 - THREAD_FLAGS,
15618 - THREAD_ORDER));
15619 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15620 - irqctx->tinfo.cpu = cpu;
15621 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15622 -
15623 - per_cpu(softirq_ctx, cpu) = irqctx;
15624 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15625 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15626
15627 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15628 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15629 @@ -152,7 +135,6 @@ void __cpuinit irq_ctx_init(int cpu)
15630 asmlinkage void do_softirq(void)
15631 {
15632 unsigned long flags;
15633 - struct thread_info *curctx;
15634 union irq_ctx *irqctx;
15635 u32 *isp;
15636
15637 @@ -162,15 +144,22 @@ asmlinkage void do_softirq(void)
15638 local_irq_save(flags);
15639
15640 if (local_softirq_pending()) {
15641 - curctx = current_thread_info();
15642 irqctx = __this_cpu_read(softirq_ctx);
15643 - irqctx->tinfo.task = curctx->task;
15644 - irqctx->tinfo.previous_esp = current_stack_pointer;
15645 + irqctx->previous_esp = current_stack_pointer;
15646
15647 /* build the stack frame on the softirq stack */
15648 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15649 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15650 +
15651 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15652 + __set_fs(MAKE_MM_SEG(0));
15653 +#endif
15654
15655 call_on_stack(__do_softirq, isp);
15656 +
15657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15658 + __set_fs(current_thread_info()->addr_limit);
15659 +#endif
15660 +
15661 /*
15662 * Shouldn't happen, we returned above if in_interrupt():
15663 */
15664 diff -urNp linux-2.6.39.1/arch/x86/kernel/irq.c linux-2.6.39.1/arch/x86/kernel/irq.c
15665 --- linux-2.6.39.1/arch/x86/kernel/irq.c 2011-05-19 00:06:34.000000000 -0400
15666 +++ linux-2.6.39.1/arch/x86/kernel/irq.c 2011-05-22 19:36:30.000000000 -0400
15667 @@ -17,7 +17,7 @@
15668 #include <asm/mce.h>
15669 #include <asm/hw_irq.h>
15670
15671 -atomic_t irq_err_count;
15672 +atomic_unchecked_t irq_err_count;
15673
15674 /* Function pointer for generic interrupt vector handling */
15675 void (*x86_platform_ipi_callback)(void) = NULL;
15676 @@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file
15677 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15678 seq_printf(p, " Machine check polls\n");
15679 #endif
15680 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15681 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15682 #if defined(CONFIG_X86_IO_APIC)
15683 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15684 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15685 #endif
15686 return 0;
15687 }
15688 @@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15689
15690 u64 arch_irq_stat(void)
15691 {
15692 - u64 sum = atomic_read(&irq_err_count);
15693 + u64 sum = atomic_read_unchecked(&irq_err_count);
15694
15695 #ifdef CONFIG_X86_IO_APIC
15696 - sum += atomic_read(&irq_mis_count);
15697 + sum += atomic_read_unchecked(&irq_mis_count);
15698 #endif
15699 return sum;
15700 }
15701 diff -urNp linux-2.6.39.1/arch/x86/kernel/kgdb.c linux-2.6.39.1/arch/x86/kernel/kgdb.c
15702 --- linux-2.6.39.1/arch/x86/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
15703 +++ linux-2.6.39.1/arch/x86/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
15704 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem,
15705 #ifdef CONFIG_X86_32
15706 switch (regno) {
15707 case GDB_SS:
15708 - if (!user_mode_vm(regs))
15709 + if (!user_mode(regs))
15710 *(unsigned long *)mem = __KERNEL_DS;
15711 break;
15712 case GDB_SP:
15713 - if (!user_mode_vm(regs))
15714 + if (!user_mode(regs))
15715 *(unsigned long *)mem = kernel_stack_pointer(regs);
15716 break;
15717 case GDB_GS:
15718 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vec
15719 case 'k':
15720 /* clear the trace bit */
15721 linux_regs->flags &= ~X86_EFLAGS_TF;
15722 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15723 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15724
15725 /* set the trace bit if we're stepping */
15726 if (remcomInBuffer[0] == 's') {
15727 linux_regs->flags |= X86_EFLAGS_TF;
15728 - atomic_set(&kgdb_cpu_doing_single_step,
15729 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15730 raw_smp_processor_id());
15731 }
15732
15733 @@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args
15734 return NOTIFY_DONE;
15735
15736 case DIE_DEBUG:
15737 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15738 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15739 if (user_mode(regs))
15740 return single_step_cont(regs, args);
15741 break;
15742 @@ -710,7 +710,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
15743 regs->ip = ip;
15744 }
15745
15746 -struct kgdb_arch arch_kgdb_ops = {
15747 +const struct kgdb_arch arch_kgdb_ops = {
15748 /* Breakpoint instruction: */
15749 .gdb_bpt_instr = { 0xcc },
15750 .flags = KGDB_HW_BREAKPOINT,
15751 diff -urNp linux-2.6.39.1/arch/x86/kernel/kprobes.c linux-2.6.39.1/arch/x86/kernel/kprobes.c
15752 --- linux-2.6.39.1/arch/x86/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
15753 +++ linux-2.6.39.1/arch/x86/kernel/kprobes.c 2011-05-22 19:36:30.000000000 -0400
15754 @@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
15755 } __attribute__((packed)) *insn;
15756
15757 insn = (struct __arch_relative_insn *)from;
15758 +
15759 + pax_open_kernel();
15760 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15761 insn->op = op;
15762 + pax_close_kernel();
15763 }
15764
15765 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15766 @@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
15767 kprobe_opcode_t opcode;
15768 kprobe_opcode_t *orig_opcodes = opcodes;
15769
15770 - if (search_exception_tables((unsigned long)opcodes))
15771 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15772 return 0; /* Page fault may occur on this address. */
15773
15774 retry:
15775 @@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
15776 }
15777 }
15778 insn_get_length(&insn);
15779 + pax_open_kernel();
15780 memcpy(dest, insn.kaddr, insn.length);
15781 + pax_close_kernel();
15782
15783 #ifdef CONFIG_X86_64
15784 if (insn_rip_relative(&insn)) {
15785 @@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
15786 (u8 *) dest;
15787 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15788 disp = (u8 *) dest + insn_offset_displacement(&insn);
15789 + pax_open_kernel();
15790 *(s32 *) disp = (s32) newdisp;
15791 + pax_close_kernel();
15792 }
15793 #endif
15794 return insn.length;
15795 @@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
15796 */
15797 __copy_instruction(p->ainsn.insn, p->addr, 0);
15798
15799 - if (can_boost(p->addr))
15800 + if (can_boost(ktla_ktva(p->addr)))
15801 p->ainsn.boostable = 0;
15802 else
15803 p->ainsn.boostable = -1;
15804
15805 - p->opcode = *p->addr;
15806 + p->opcode = *(ktla_ktva(p->addr));
15807 }
15808
15809 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15810 @@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
15811 * nor set current_kprobe, because it doesn't use single
15812 * stepping.
15813 */
15814 - regs->ip = (unsigned long)p->ainsn.insn;
15815 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15816 preempt_enable_no_resched();
15817 return;
15818 }
15819 @@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
15820 if (p->opcode == BREAKPOINT_INSTRUCTION)
15821 regs->ip = (unsigned long)p->addr;
15822 else
15823 - regs->ip = (unsigned long)p->ainsn.insn;
15824 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15825 }
15826
15827 /*
15828 @@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
15829 setup_singlestep(p, regs, kcb, 0);
15830 return 1;
15831 }
15832 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15833 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15834 /*
15835 * The breakpoint instruction was removed right
15836 * after we hit it. Another cpu has removed
15837 @@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
15838 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15839 {
15840 unsigned long *tos = stack_addr(regs);
15841 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15842 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15843 unsigned long orig_ip = (unsigned long)p->addr;
15844 kprobe_opcode_t *insn = p->ainsn.insn;
15845
15846 @@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
15847 struct die_args *args = data;
15848 int ret = NOTIFY_DONE;
15849
15850 - if (args->regs && user_mode_vm(args->regs))
15851 + if (args->regs && user_mode(args->regs))
15852 return ret;
15853
15854 switch (val) {
15855 @@ -1381,7 +1388,7 @@ int __kprobes arch_prepare_optimized_kpr
15856 * Verify if the address gap is in 2GB range, because this uses
15857 * a relative jump.
15858 */
15859 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15860 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15861 if (abs(rel) > 0x7fffffff)
15862 return -ERANGE;
15863
15864 @@ -1402,11 +1409,11 @@ int __kprobes arch_prepare_optimized_kpr
15865 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15866
15867 /* Set probe function call */
15868 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15869 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15870
15871 /* Set returning jmp instruction at the tail of out-of-line buffer */
15872 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15873 - (u8 *)op->kp.addr + op->optinsn.size);
15874 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15875
15876 flush_icache_range((unsigned long) buf,
15877 (unsigned long) buf + TMPL_END_IDX +
15878 @@ -1428,7 +1435,7 @@ static void __kprobes setup_optimize_kpr
15879 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15880
15881 /* Backup instructions which will be replaced by jump address */
15882 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15883 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15884 RELATIVE_ADDR_SIZE);
15885
15886 insn_buf[0] = RELATIVEJUMP_OPCODE;
15887 diff -urNp linux-2.6.39.1/arch/x86/kernel/ldt.c linux-2.6.39.1/arch/x86/kernel/ldt.c
15888 --- linux-2.6.39.1/arch/x86/kernel/ldt.c 2011-05-19 00:06:34.000000000 -0400
15889 +++ linux-2.6.39.1/arch/x86/kernel/ldt.c 2011-05-22 19:36:30.000000000 -0400
15890 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
15891 if (reload) {
15892 #ifdef CONFIG_SMP
15893 preempt_disable();
15894 - load_LDT(pc);
15895 + load_LDT_nolock(pc);
15896 if (!cpumask_equal(mm_cpumask(current->mm),
15897 cpumask_of(smp_processor_id())))
15898 smp_call_function(flush_ldt, current->mm, 1);
15899 preempt_enable();
15900 #else
15901 - load_LDT(pc);
15902 + load_LDT_nolock(pc);
15903 #endif
15904 }
15905 if (oldsize) {
15906 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
15907 return err;
15908
15909 for (i = 0; i < old->size; i++)
15910 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15911 + write_ldt_entry(new->ldt, i, old->ldt + i);
15912 return 0;
15913 }
15914
15915 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct
15916 retval = copy_ldt(&mm->context, &old_mm->context);
15917 mutex_unlock(&old_mm->context.lock);
15918 }
15919 +
15920 + if (tsk == current) {
15921 + mm->context.vdso = 0;
15922 +
15923 +#ifdef CONFIG_X86_32
15924 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15925 + mm->context.user_cs_base = 0UL;
15926 + mm->context.user_cs_limit = ~0UL;
15927 +
15928 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15929 + cpus_clear(mm->context.cpu_user_cs_mask);
15930 +#endif
15931 +
15932 +#endif
15933 +#endif
15934 +
15935 + }
15936 +
15937 return retval;
15938 }
15939
15940 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
15941 }
15942 }
15943
15944 +#ifdef CONFIG_PAX_SEGMEXEC
15945 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15946 + error = -EINVAL;
15947 + goto out_unlock;
15948 + }
15949 +#endif
15950 +
15951 fill_ldt(&ldt, &ldt_info);
15952 if (oldmode)
15953 ldt.avl = 0;
15954 diff -urNp linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c
15955 --- linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c 2011-05-19 00:06:34.000000000 -0400
15956 +++ linux-2.6.39.1/arch/x86/kernel/machine_kexec_32.c 2011-05-22 19:36:30.000000000 -0400
15957 @@ -27,7 +27,7 @@
15958 #include <asm/cacheflush.h>
15959 #include <asm/debugreg.h>
15960
15961 -static void set_idt(void *newidt, __u16 limit)
15962 +static void set_idt(struct desc_struct *newidt, __u16 limit)
15963 {
15964 struct desc_ptr curidt;
15965
15966 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
15967 }
15968
15969
15970 -static void set_gdt(void *newgdt, __u16 limit)
15971 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15972 {
15973 struct desc_ptr curgdt;
15974
15975 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15976 }
15977
15978 control_page = page_address(image->control_code_page);
15979 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15980 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15981
15982 relocate_kernel_ptr = control_page;
15983 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15984 diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_amd.c linux-2.6.39.1/arch/x86/kernel/microcode_amd.c
15985 --- linux-2.6.39.1/arch/x86/kernel/microcode_amd.c 2011-05-19 00:06:34.000000000 -0400
15986 +++ linux-2.6.39.1/arch/x86/kernel/microcode_amd.c 2011-05-22 19:36:30.000000000 -0400
15987 @@ -339,7 +339,7 @@ static void microcode_fini_cpu_amd(int c
15988 uci->mc = NULL;
15989 }
15990
15991 -static struct microcode_ops microcode_amd_ops = {
15992 +static const struct microcode_ops microcode_amd_ops = {
15993 .request_microcode_user = request_microcode_user,
15994 .request_microcode_fw = request_microcode_amd,
15995 .collect_cpu_info = collect_cpu_info_amd,
15996 @@ -347,7 +347,7 @@ static struct microcode_ops microcode_am
15997 .microcode_fini_cpu = microcode_fini_cpu_amd,
15998 };
15999
16000 -struct microcode_ops * __init init_amd_microcode(void)
16001 +const struct microcode_ops * __init init_amd_microcode(void)
16002 {
16003 return &microcode_amd_ops;
16004 }
16005 diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_core.c linux-2.6.39.1/arch/x86/kernel/microcode_core.c
16006 --- linux-2.6.39.1/arch/x86/kernel/microcode_core.c 2011-05-19 00:06:34.000000000 -0400
16007 +++ linux-2.6.39.1/arch/x86/kernel/microcode_core.c 2011-05-22 19:36:30.000000000 -0400
16008 @@ -93,7 +93,7 @@ MODULE_LICENSE("GPL");
16009
16010 #define MICROCODE_VERSION "2.00"
16011
16012 -static struct microcode_ops *microcode_ops;
16013 +static const struct microcode_ops *microcode_ops;
16014
16015 /*
16016 * Synchronization.
16017 diff -urNp linux-2.6.39.1/arch/x86/kernel/microcode_intel.c linux-2.6.39.1/arch/x86/kernel/microcode_intel.c
16018 --- linux-2.6.39.1/arch/x86/kernel/microcode_intel.c 2011-05-19 00:06:34.000000000 -0400
16019 +++ linux-2.6.39.1/arch/x86/kernel/microcode_intel.c 2011-05-22 19:36:30.000000000 -0400
16020 @@ -440,13 +440,13 @@ static enum ucode_state request_microcod
16021
16022 static int get_ucode_user(void *to, const void *from, size_t n)
16023 {
16024 - return copy_from_user(to, from, n);
16025 + return copy_from_user(to, (__force const void __user *)from, n);
16026 }
16027
16028 static enum ucode_state
16029 request_microcode_user(int cpu, const void __user *buf, size_t size)
16030 {
16031 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16032 + return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
16033 }
16034
16035 static void microcode_fini_cpu(int cpu)
16036 @@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
16037 uci->mc = NULL;
16038 }
16039
16040 -static struct microcode_ops microcode_intel_ops = {
16041 +static const struct microcode_ops microcode_intel_ops = {
16042 .request_microcode_user = request_microcode_user,
16043 .request_microcode_fw = request_microcode_fw,
16044 .collect_cpu_info = collect_cpu_info,
16045 @@ -465,7 +465,7 @@ static struct microcode_ops microcode_in
16046 .microcode_fini_cpu = microcode_fini_cpu,
16047 };
16048
16049 -struct microcode_ops * __init init_intel_microcode(void)
16050 +const struct microcode_ops * __init init_intel_microcode(void)
16051 {
16052 return &microcode_intel_ops;
16053 }
16054 diff -urNp linux-2.6.39.1/arch/x86/kernel/module.c linux-2.6.39.1/arch/x86/kernel/module.c
16055 --- linux-2.6.39.1/arch/x86/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
16056 +++ linux-2.6.39.1/arch/x86/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
16057 @@ -35,21 +35,66 @@
16058 #define DEBUGP(fmt...)
16059 #endif
16060
16061 -void *module_alloc(unsigned long size)
16062 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16063 {
16064 if (PAGE_ALIGN(size) > MODULES_LEN)
16065 return NULL;
16066 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16067 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16068 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16069 -1, __builtin_return_address(0));
16070 }
16071
16072 +void *module_alloc(unsigned long size)
16073 +{
16074 +
16075 +#ifdef CONFIG_PAX_KERNEXEC
16076 + return __module_alloc(size, PAGE_KERNEL);
16077 +#else
16078 + return __module_alloc(size, PAGE_KERNEL_EXEC);
16079 +#endif
16080 +
16081 +}
16082 +
16083 /* Free memory returned from module_alloc */
16084 void module_free(struct module *mod, void *module_region)
16085 {
16086 vfree(module_region);
16087 }
16088
16089 +#ifdef CONFIG_PAX_KERNEXEC
16090 +#ifdef CONFIG_X86_32
16091 +void *module_alloc_exec(unsigned long size)
16092 +{
16093 + struct vm_struct *area;
16094 +
16095 + if (size == 0)
16096 + return NULL;
16097 +
16098 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16099 + return area ? area->addr : NULL;
16100 +}
16101 +EXPORT_SYMBOL(module_alloc_exec);
16102 +
16103 +void module_free_exec(struct module *mod, void *module_region)
16104 +{
16105 + vunmap(module_region);
16106 +}
16107 +EXPORT_SYMBOL(module_free_exec);
16108 +#else
16109 +void module_free_exec(struct module *mod, void *module_region)
16110 +{
16111 + module_free(mod, module_region);
16112 +}
16113 +EXPORT_SYMBOL(module_free_exec);
16114 +
16115 +void *module_alloc_exec(unsigned long size)
16116 +{
16117 + return __module_alloc(size, PAGE_KERNEL_RX);
16118 +}
16119 +EXPORT_SYMBOL(module_alloc_exec);
16120 +#endif
16121 +#endif
16122 +
16123 /* We don't need anything special. */
16124 int module_frob_arch_sections(Elf_Ehdr *hdr,
16125 Elf_Shdr *sechdrs,
16126 @@ -69,14 +114,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16127 unsigned int i;
16128 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16129 Elf32_Sym *sym;
16130 - uint32_t *location;
16131 + uint32_t *plocation, location;
16132
16133 DEBUGP("Applying relocate section %u to %u\n", relsec,
16134 sechdrs[relsec].sh_info);
16135 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16136 /* This is where to make the change */
16137 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16138 - + rel[i].r_offset;
16139 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16140 + location = (uint32_t)plocation;
16141 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16142 + plocation = ktla_ktva((void *)plocation);
16143 /* This is the symbol it is referring to. Note that all
16144 undefined symbols have been resolved. */
16145 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16146 @@ -85,11 +132,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16147 switch (ELF32_R_TYPE(rel[i].r_info)) {
16148 case R_386_32:
16149 /* We add the value into the location given */
16150 - *location += sym->st_value;
16151 + pax_open_kernel();
16152 + *plocation += sym->st_value;
16153 + pax_close_kernel();
16154 break;
16155 case R_386_PC32:
16156 /* Add the value, subtract its postition */
16157 - *location += sym->st_value - (uint32_t)location;
16158 + pax_open_kernel();
16159 + *plocation += sym->st_value - location;
16160 + pax_close_kernel();
16161 break;
16162 default:
16163 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16164 @@ -145,21 +196,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
16165 case R_X86_64_NONE:
16166 break;
16167 case R_X86_64_64:
16168 + pax_open_kernel();
16169 *(u64 *)loc = val;
16170 + pax_close_kernel();
16171 break;
16172 case R_X86_64_32:
16173 + pax_open_kernel();
16174 *(u32 *)loc = val;
16175 + pax_close_kernel();
16176 if (val != *(u32 *)loc)
16177 goto overflow;
16178 break;
16179 case R_X86_64_32S:
16180 + pax_open_kernel();
16181 *(s32 *)loc = val;
16182 + pax_close_kernel();
16183 if ((s64)val != *(s32 *)loc)
16184 goto overflow;
16185 break;
16186 case R_X86_64_PC32:
16187 val -= (u64)loc;
16188 + pax_open_kernel();
16189 *(u32 *)loc = val;
16190 + pax_close_kernel();
16191 +
16192 #if 0
16193 if ((s64)val != *(s32 *)loc)
16194 goto overflow;
16195 diff -urNp linux-2.6.39.1/arch/x86/kernel/paravirt.c linux-2.6.39.1/arch/x86/kernel/paravirt.c
16196 --- linux-2.6.39.1/arch/x86/kernel/paravirt.c 2011-05-19 00:06:34.000000000 -0400
16197 +++ linux-2.6.39.1/arch/x86/kernel/paravirt.c 2011-05-22 19:36:30.000000000 -0400
16198 @@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
16199 * corresponding structure. */
16200 static void *get_call_destination(u8 type)
16201 {
16202 - struct paravirt_patch_template tmpl = {
16203 + const struct paravirt_patch_template tmpl = {
16204 .pv_init_ops = pv_init_ops,
16205 .pv_time_ops = pv_time_ops,
16206 .pv_cpu_ops = pv_cpu_ops,
16207 @@ -133,6 +133,9 @@ static void *get_call_destination(u8 typ
16208 .pv_lock_ops = pv_lock_ops,
16209 #endif
16210 };
16211 +
16212 + pax_track_stack();
16213 +
16214 return *((void **)&tmpl + type);
16215 }
16216
16217 @@ -145,14 +148,14 @@ unsigned paravirt_patch_default(u8 type,
16218 if (opfunc == NULL)
16219 /* If there's no function, patch it with a ud2a (BUG) */
16220 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16221 - else if (opfunc == _paravirt_nop)
16222 + else if (opfunc == (void *)_paravirt_nop)
16223 /* If the operation is a nop, then nop the callsite */
16224 ret = paravirt_patch_nop();
16225
16226 /* identity functions just return their single argument */
16227 - else if (opfunc == _paravirt_ident_32)
16228 + else if (opfunc == (void *)_paravirt_ident_32)
16229 ret = paravirt_patch_ident_32(insnbuf, len);
16230 - else if (opfunc == _paravirt_ident_64)
16231 + else if (opfunc == (void *)_paravirt_ident_64)
16232 ret = paravirt_patch_ident_64(insnbuf, len);
16233
16234 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16235 @@ -178,7 +181,7 @@ unsigned paravirt_patch_insns(void *insn
16236 if (insn_len > len || start == NULL)
16237 insn_len = len;
16238 else
16239 - memcpy(insnbuf, start, insn_len);
16240 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16241
16242 return insn_len;
16243 }
16244 @@ -294,22 +297,22 @@ void arch_flush_lazy_mmu_mode(void)
16245 preempt_enable();
16246 }
16247
16248 -struct pv_info pv_info = {
16249 +struct pv_info pv_info __read_only = {
16250 .name = "bare hardware",
16251 .paravirt_enabled = 0,
16252 .kernel_rpl = 0,
16253 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
16254 };
16255
16256 -struct pv_init_ops pv_init_ops = {
16257 +struct pv_init_ops pv_init_ops __read_only = {
16258 .patch = native_patch,
16259 };
16260
16261 -struct pv_time_ops pv_time_ops = {
16262 +struct pv_time_ops pv_time_ops __read_only = {
16263 .sched_clock = native_sched_clock,
16264 };
16265
16266 -struct pv_irq_ops pv_irq_ops = {
16267 +struct pv_irq_ops pv_irq_ops __read_only = {
16268 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16269 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16270 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16271 @@ -321,7 +324,7 @@ struct pv_irq_ops pv_irq_ops = {
16272 #endif
16273 };
16274
16275 -struct pv_cpu_ops pv_cpu_ops = {
16276 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16277 .cpuid = native_cpuid,
16278 .get_debugreg = native_get_debugreg,
16279 .set_debugreg = native_set_debugreg,
16280 @@ -382,7 +385,7 @@ struct pv_cpu_ops pv_cpu_ops = {
16281 .end_context_switch = paravirt_nop,
16282 };
16283
16284 -struct pv_apic_ops pv_apic_ops = {
16285 +struct pv_apic_ops pv_apic_ops __read_only = {
16286 #ifdef CONFIG_X86_LOCAL_APIC
16287 .startup_ipi_hook = paravirt_nop,
16288 #endif
16289 @@ -396,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = {
16290 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16291 #endif
16292
16293 -struct pv_mmu_ops pv_mmu_ops = {
16294 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16295
16296 .read_cr2 = native_read_cr2,
16297 .write_cr2 = native_write_cr2,
16298 @@ -465,6 +468,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16299 },
16300
16301 .set_fixmap = native_set_fixmap,
16302 +
16303 +#ifdef CONFIG_PAX_KERNEXEC
16304 + .pax_open_kernel = native_pax_open_kernel,
16305 + .pax_close_kernel = native_pax_close_kernel,
16306 +#endif
16307 +
16308 };
16309
16310 EXPORT_SYMBOL_GPL(pv_time_ops);
16311 diff -urNp linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c
16312 --- linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c 2011-05-19 00:06:34.000000000 -0400
16313 +++ linux-2.6.39.1/arch/x86/kernel/paravirt-spinlocks.c 2011-05-22 19:36:30.000000000 -0400
16314 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
16315 arch_spin_lock(lock);
16316 }
16317
16318 -struct pv_lock_ops pv_lock_ops = {
16319 +struct pv_lock_ops pv_lock_ops __read_only = {
16320 #ifdef CONFIG_SMP
16321 .spin_is_locked = __ticket_spin_is_locked,
16322 .spin_is_contended = __ticket_spin_is_contended,
16323 diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c
16324 --- linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c 2011-05-19 00:06:34.000000000 -0400
16325 +++ linux-2.6.39.1/arch/x86/kernel/pci-calgary_64.c 2011-05-22 19:36:30.000000000 -0400
16326 @@ -179,13 +179,13 @@ static void calioc2_dump_error_regs(stru
16327 static void calgary_init_bitmap_from_tce_table(struct iommu_table *tbl);
16328 static void get_tce_space_from_tar(void);
16329
16330 -static struct cal_chipset_ops calgary_chip_ops = {
16331 +static const struct cal_chipset_ops calgary_chip_ops = {
16332 .handle_quirks = calgary_handle_quirks,
16333 .tce_cache_blast = calgary_tce_cache_blast,
16334 .dump_error_regs = calgary_dump_error_regs
16335 };
16336
16337 -static struct cal_chipset_ops calioc2_chip_ops = {
16338 +static const struct cal_chipset_ops calioc2_chip_ops = {
16339 .handle_quirks = calioc2_handle_quirks,
16340 .tce_cache_blast = calioc2_tce_cache_blast,
16341 .dump_error_regs = calioc2_dump_error_regs
16342 @@ -476,7 +476,7 @@ static void calgary_free_coherent(struct
16343 free_pages((unsigned long)vaddr, get_order(size));
16344 }
16345
16346 -static struct dma_map_ops calgary_dma_ops = {
16347 +static const struct dma_map_ops calgary_dma_ops = {
16348 .alloc_coherent = calgary_alloc_coherent,
16349 .free_coherent = calgary_free_coherent,
16350 .map_sg = calgary_map_sg,
16351 diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-dma.c linux-2.6.39.1/arch/x86/kernel/pci-dma.c
16352 --- linux-2.6.39.1/arch/x86/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
16353 +++ linux-2.6.39.1/arch/x86/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
16354 @@ -16,7 +16,7 @@
16355
16356 static int forbid_dac __read_mostly;
16357
16358 -struct dma_map_ops *dma_ops = &nommu_dma_ops;
16359 +const struct dma_map_ops *dma_ops = &nommu_dma_ops;
16360 EXPORT_SYMBOL(dma_ops);
16361
16362 static int iommu_sac_force __read_mostly;
16363 @@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
16364
16365 int dma_supported(struct device *dev, u64 mask)
16366 {
16367 - struct dma_map_ops *ops = get_dma_ops(dev);
16368 + const struct dma_map_ops *ops = get_dma_ops(dev);
16369
16370 #ifdef CONFIG_PCI
16371 if (mask > 0xffffffff && forbid_dac > 0) {
16372 diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c
16373 --- linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c 2011-05-19 00:06:34.000000000 -0400
16374 +++ linux-2.6.39.1/arch/x86/kernel/pci-gart_64.c 2011-05-22 19:36:30.000000000 -0400
16375 @@ -695,7 +695,7 @@ static __init int init_amd_gatt(struct a
16376 return -1;
16377 }
16378
16379 -static struct dma_map_ops gart_dma_ops = {
16380 +static const struct dma_map_ops gart_dma_ops = {
16381 .map_sg = gart_map_sg,
16382 .unmap_sg = gart_unmap_sg,
16383 .map_page = gart_map_page,
16384 diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c
16385 --- linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c 2011-05-19 00:06:34.000000000 -0400
16386 +++ linux-2.6.39.1/arch/x86/kernel/pci-iommu_table.c 2011-05-22 19:36:30.000000000 -0400
16387 @@ -2,7 +2,7 @@
16388 #include <asm/iommu_table.h>
16389 #include <linux/string.h>
16390 #include <linux/kallsyms.h>
16391 -
16392 +#include <linux/sched.h>
16393
16394 #define DEBUG 1
16395
16396 @@ -53,6 +53,8 @@ void __init check_iommu_entries(struct i
16397 char sym_p[KSYM_SYMBOL_LEN];
16398 char sym_q[KSYM_SYMBOL_LEN];
16399
16400 + pax_track_stack();
16401 +
16402 /* Simple cyclic dependency checker. */
16403 for (p = start; p < finish; p++) {
16404 q = find_dependents_of(start, finish, p);
16405 diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-nommu.c linux-2.6.39.1/arch/x86/kernel/pci-nommu.c
16406 --- linux-2.6.39.1/arch/x86/kernel/pci-nommu.c 2011-05-19 00:06:34.000000000 -0400
16407 +++ linux-2.6.39.1/arch/x86/kernel/pci-nommu.c 2011-05-22 19:36:30.000000000 -0400
16408 @@ -95,7 +95,7 @@ static void nommu_sync_sg_for_device(str
16409 flush_write_buffers();
16410 }
16411
16412 -struct dma_map_ops nommu_dma_ops = {
16413 +const struct dma_map_ops nommu_dma_ops = {
16414 .alloc_coherent = dma_generic_alloc_coherent,
16415 .free_coherent = nommu_free_coherent,
16416 .map_sg = nommu_map_sg,
16417 diff -urNp linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c
16418 --- linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
16419 +++ linux-2.6.39.1/arch/x86/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
16420 @@ -26,7 +26,7 @@ static void *x86_swiotlb_alloc_coherent(
16421 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
16422 }
16423
16424 -static struct dma_map_ops swiotlb_dma_ops = {
16425 +static const struct dma_map_ops swiotlb_dma_ops = {
16426 .mapping_error = swiotlb_dma_mapping_error,
16427 .alloc_coherent = x86_swiotlb_alloc_coherent,
16428 .free_coherent = swiotlb_free_coherent,
16429 diff -urNp linux-2.6.39.1/arch/x86/kernel/process_32.c linux-2.6.39.1/arch/x86/kernel/process_32.c
16430 --- linux-2.6.39.1/arch/x86/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
16431 +++ linux-2.6.39.1/arch/x86/kernel/process_32.c 2011-05-22 19:36:30.000000000 -0400
16432 @@ -65,6 +65,7 @@ asmlinkage void ret_from_fork(void) __as
16433 unsigned long thread_saved_pc(struct task_struct *tsk)
16434 {
16435 return ((unsigned long *)tsk->thread.sp)[3];
16436 +//XXX return tsk->thread.eip;
16437 }
16438
16439 #ifndef CONFIG_SMP
16440 @@ -126,15 +127,14 @@ void __show_regs(struct pt_regs *regs, i
16441 unsigned long sp;
16442 unsigned short ss, gs;
16443
16444 - if (user_mode_vm(regs)) {
16445 + if (user_mode(regs)) {
16446 sp = regs->sp;
16447 ss = regs->ss & 0xffff;
16448 - gs = get_user_gs(regs);
16449 } else {
16450 sp = kernel_stack_pointer(regs);
16451 savesegment(ss, ss);
16452 - savesegment(gs, gs);
16453 }
16454 + gs = get_user_gs(regs);
16455
16456 show_regs_common();
16457
16458 @@ -196,13 +196,14 @@ int copy_thread(unsigned long clone_flag
16459 struct task_struct *tsk;
16460 int err;
16461
16462 - childregs = task_pt_regs(p);
16463 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16464 *childregs = *regs;
16465 childregs->ax = 0;
16466 childregs->sp = sp;
16467
16468 p->thread.sp = (unsigned long) childregs;
16469 p->thread.sp0 = (unsigned long) (childregs+1);
16470 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16471
16472 p->thread.ip = (unsigned long) ret_from_fork;
16473
16474 @@ -293,7 +294,7 @@ __switch_to(struct task_struct *prev_p,
16475 struct thread_struct *prev = &prev_p->thread,
16476 *next = &next_p->thread;
16477 int cpu = smp_processor_id();
16478 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16479 + struct tss_struct *tss = init_tss + cpu;
16480 bool preload_fpu;
16481
16482 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16483 @@ -328,6 +329,10 @@ __switch_to(struct task_struct *prev_p,
16484 */
16485 lazy_save_gs(prev->gs);
16486
16487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16488 + __set_fs(task_thread_info(next_p)->addr_limit);
16489 +#endif
16490 +
16491 /*
16492 * Load the per-thread Thread-Local Storage descriptor.
16493 */
16494 @@ -363,6 +368,9 @@ __switch_to(struct task_struct *prev_p,
16495 */
16496 arch_end_context_switch(next_p);
16497
16498 + percpu_write(current_task, next_p);
16499 + percpu_write(current_tinfo, &next_p->tinfo);
16500 +
16501 if (preload_fpu)
16502 __math_state_restore();
16503
16504 @@ -372,8 +380,6 @@ __switch_to(struct task_struct *prev_p,
16505 if (prev->gs | next->gs)
16506 lazy_load_gs(next->gs);
16507
16508 - percpu_write(current_task, next_p);
16509 -
16510 return prev_p;
16511 }
16512
16513 @@ -403,4 +409,3 @@ unsigned long get_wchan(struct task_stru
16514 } while (count++ < 16);
16515 return 0;
16516 }
16517 -
16518 diff -urNp linux-2.6.39.1/arch/x86/kernel/process_64.c linux-2.6.39.1/arch/x86/kernel/process_64.c
16519 --- linux-2.6.39.1/arch/x86/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
16520 +++ linux-2.6.39.1/arch/x86/kernel/process_64.c 2011-05-22 19:36:30.000000000 -0400
16521 @@ -87,7 +87,7 @@ static void __exit_idle(void)
16522 void exit_idle(void)
16523 {
16524 /* idle loop has pid 0 */
16525 - if (current->pid)
16526 + if (task_pid_nr(current))
16527 return;
16528 __exit_idle();
16529 }
16530 @@ -260,8 +260,7 @@ int copy_thread(unsigned long clone_flag
16531 struct pt_regs *childregs;
16532 struct task_struct *me = current;
16533
16534 - childregs = ((struct pt_regs *)
16535 - (THREAD_SIZE + task_stack_page(p))) - 1;
16536 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16537 *childregs = *regs;
16538
16539 childregs->ax = 0;
16540 @@ -273,6 +272,7 @@ int copy_thread(unsigned long clone_flag
16541 p->thread.sp = (unsigned long) childregs;
16542 p->thread.sp0 = (unsigned long) (childregs+1);
16543 p->thread.usersp = me->thread.usersp;
16544 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16545
16546 set_tsk_thread_flag(p, TIF_FORK);
16547
16548 @@ -376,7 +376,7 @@ __switch_to(struct task_struct *prev_p,
16549 struct thread_struct *prev = &prev_p->thread;
16550 struct thread_struct *next = &next_p->thread;
16551 int cpu = smp_processor_id();
16552 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16553 + struct tss_struct *tss = init_tss + cpu;
16554 unsigned fsindex, gsindex;
16555 bool preload_fpu;
16556
16557 @@ -472,10 +472,9 @@ __switch_to(struct task_struct *prev_p,
16558 prev->usersp = percpu_read(old_rsp);
16559 percpu_write(old_rsp, next->usersp);
16560 percpu_write(current_task, next_p);
16561 + percpu_write(current_tinfo, &next_p->tinfo);
16562
16563 - percpu_write(kernel_stack,
16564 - (unsigned long)task_stack_page(next_p) +
16565 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16566 + percpu_write(kernel_stack, next->sp0);
16567
16568 /*
16569 * Now maybe reload the debug registers and handle I/O bitmaps
16570 @@ -537,12 +536,11 @@ unsigned long get_wchan(struct task_stru
16571 if (!p || p == current || p->state == TASK_RUNNING)
16572 return 0;
16573 stack = (unsigned long)task_stack_page(p);
16574 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16575 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16576 return 0;
16577 fp = *(u64 *)(p->thread.sp);
16578 do {
16579 - if (fp < (unsigned long)stack ||
16580 - fp >= (unsigned long)stack+THREAD_SIZE)
16581 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16582 return 0;
16583 ip = *(u64 *)(fp+8);
16584 if (!in_sched_functions(ip))
16585 diff -urNp linux-2.6.39.1/arch/x86/kernel/process.c linux-2.6.39.1/arch/x86/kernel/process.c
16586 --- linux-2.6.39.1/arch/x86/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
16587 +++ linux-2.6.39.1/arch/x86/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
16588 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_stru
16589
16590 void free_thread_info(struct thread_info *ti)
16591 {
16592 - free_thread_xstate(ti->task);
16593 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16594 }
16595
16596 +static struct kmem_cache *task_struct_cachep;
16597 +
16598 void arch_task_cache_init(void)
16599 {
16600 - task_xstate_cachep =
16601 - kmem_cache_create("task_xstate", xstate_size,
16602 + /* create a slab on which task_structs can be allocated */
16603 + task_struct_cachep =
16604 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16605 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16606 +
16607 + task_xstate_cachep =
16608 + kmem_cache_create("task_xstate", xstate_size,
16609 __alignof__(union thread_xstate),
16610 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16611 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16612 +}
16613 +
16614 +struct task_struct *alloc_task_struct_node(int node)
16615 +{
16616 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16617 +}
16618 +
16619 +void free_task_struct(struct task_struct *task)
16620 +{
16621 + free_thread_xstate(task);
16622 + kmem_cache_free(task_struct_cachep, task);
16623 }
16624
16625 /*
16626 @@ -70,7 +87,7 @@ void exit_thread(void)
16627 unsigned long *bp = t->io_bitmap_ptr;
16628
16629 if (bp) {
16630 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16631 + struct tss_struct *tss = init_tss + get_cpu();
16632
16633 t->io_bitmap_ptr = NULL;
16634 clear_thread_flag(TIF_IO_BITMAP);
16635 @@ -106,7 +123,7 @@ void show_regs_common(void)
16636
16637 printk(KERN_CONT "\n");
16638 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16639 - current->pid, current->comm, print_tainted(),
16640 + task_pid_nr(current), current->comm, print_tainted(),
16641 init_utsname()->release,
16642 (int)strcspn(init_utsname()->version, " "),
16643 init_utsname()->version);
16644 @@ -120,6 +137,9 @@ void flush_thread(void)
16645 {
16646 struct task_struct *tsk = current;
16647
16648 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16649 + loadsegment(gs, 0);
16650 +#endif
16651 flush_ptrace_hw_breakpoint(tsk);
16652 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16653 /*
16654 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), voi
16655 regs.di = (unsigned long) arg;
16656
16657 #ifdef CONFIG_X86_32
16658 - regs.ds = __USER_DS;
16659 - regs.es = __USER_DS;
16660 + regs.ds = __KERNEL_DS;
16661 + regs.es = __KERNEL_DS;
16662 regs.fs = __KERNEL_PERCPU;
16663 - regs.gs = __KERNEL_STACK_CANARY;
16664 + savesegment(gs, regs.gs);
16665 #else
16666 regs.ss = __KERNEL_DS;
16667 #endif
16668 @@ -401,7 +421,7 @@ void default_idle(void)
16669 EXPORT_SYMBOL(default_idle);
16670 #endif
16671
16672 -void stop_this_cpu(void *dummy)
16673 +__noreturn void stop_this_cpu(void *dummy)
16674 {
16675 local_irq_disable();
16676 /*
16677 @@ -665,16 +685,34 @@ static int __init idle_setup(char *str)
16678 }
16679 early_param("idle", idle_setup);
16680
16681 -unsigned long arch_align_stack(unsigned long sp)
16682 +#ifdef CONFIG_PAX_RANDKSTACK
16683 +asmlinkage void pax_randomize_kstack(void)
16684 {
16685 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16686 - sp -= get_random_int() % 8192;
16687 - return sp & ~0xf;
16688 -}
16689 + struct thread_struct *thread = &current->thread;
16690 + unsigned long time;
16691
16692 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16693 -{
16694 - unsigned long range_end = mm->brk + 0x02000000;
16695 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16696 -}
16697 + if (!randomize_va_space)
16698 + return;
16699 +
16700 + rdtscl(time);
16701 +
16702 + /* P4 seems to return a 0 LSB, ignore it */
16703 +#ifdef CONFIG_MPENTIUM4
16704 + time &= 0x3EUL;
16705 + time <<= 2;
16706 +#elif defined(CONFIG_X86_64)
16707 + time &= 0xFUL;
16708 + time <<= 4;
16709 +#else
16710 + time &= 0x1FUL;
16711 + time <<= 3;
16712 +#endif
16713 +
16714 + thread->sp0 ^= time;
16715 + load_sp0(init_tss + smp_processor_id(), thread);
16716
16717 +#ifdef CONFIG_X86_64
16718 + percpu_write(kernel_stack, thread->sp0);
16719 +#endif
16720 +}
16721 +#endif
16722 diff -urNp linux-2.6.39.1/arch/x86/kernel/ptrace.c linux-2.6.39.1/arch/x86/kernel/ptrace.c
16723 --- linux-2.6.39.1/arch/x86/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
16724 +++ linux-2.6.39.1/arch/x86/kernel/ptrace.c 2011-05-22 19:36:30.000000000 -0400
16725 @@ -821,7 +821,7 @@ long arch_ptrace(struct task_struct *chi
16726 unsigned long addr, unsigned long data)
16727 {
16728 int ret;
16729 - unsigned long __user *datap = (unsigned long __user *)data;
16730 + unsigned long __user *datap = (__force unsigned long __user *)data;
16731
16732 switch (request) {
16733 /* read the word at location addr in the USER area. */
16734 @@ -906,14 +906,14 @@ long arch_ptrace(struct task_struct *chi
16735 if ((int) addr < 0)
16736 return -EIO;
16737 ret = do_get_thread_area(child, addr,
16738 - (struct user_desc __user *)data);
16739 + (__force struct user_desc __user *) data);
16740 break;
16741
16742 case PTRACE_SET_THREAD_AREA:
16743 if ((int) addr < 0)
16744 return -EIO;
16745 ret = do_set_thread_area(child, addr,
16746 - (struct user_desc __user *)data, 0);
16747 + (__force struct user_desc __user *) data, 0);
16748 break;
16749 #endif
16750
16751 @@ -1330,7 +1330,7 @@ static void fill_sigtrap_info(struct tas
16752 memset(info, 0, sizeof(*info));
16753 info->si_signo = SIGTRAP;
16754 info->si_code = si_code;
16755 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16756 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16757 }
16758
16759 void user_single_step_siginfo(struct task_struct *tsk,
16760 @@ -1363,7 +1363,7 @@ void send_sigtrap(struct task_struct *ts
16761 * We must return the syscall number to actually look up in the table.
16762 * This can be -1L to skip running any syscall at all.
16763 */
16764 -asmregparm long syscall_trace_enter(struct pt_regs *regs)
16765 +long syscall_trace_enter(struct pt_regs *regs)
16766 {
16767 long ret = 0;
16768
16769 @@ -1408,7 +1408,7 @@ asmregparm long syscall_trace_enter(stru
16770 return ret ?: regs->orig_ax;
16771 }
16772
16773 -asmregparm void syscall_trace_leave(struct pt_regs *regs)
16774 +void syscall_trace_leave(struct pt_regs *regs)
16775 {
16776 bool step;
16777
16778 diff -urNp linux-2.6.39.1/arch/x86/kernel/pvclock.c linux-2.6.39.1/arch/x86/kernel/pvclock.c
16779 --- linux-2.6.39.1/arch/x86/kernel/pvclock.c 2011-05-19 00:06:34.000000000 -0400
16780 +++ linux-2.6.39.1/arch/x86/kernel/pvclock.c 2011-05-22 19:36:30.000000000 -0400
16781 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvc
16782 return pv_tsc_khz;
16783 }
16784
16785 -static atomic64_t last_value = ATOMIC64_INIT(0);
16786 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16787
16788 void pvclock_resume(void)
16789 {
16790 - atomic64_set(&last_value, 0);
16791 + atomic64_set_unchecked(&last_value, 0);
16792 }
16793
16794 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16795 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct
16796 * updating at the same time, and one of them could be slightly behind,
16797 * making the assumption that last_value always go forward fail to hold.
16798 */
16799 - last = atomic64_read(&last_value);
16800 + last = atomic64_read_unchecked(&last_value);
16801 do {
16802 if (ret < last)
16803 return last;
16804 - last = atomic64_cmpxchg(&last_value, last, ret);
16805 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16806 } while (unlikely(last != ret));
16807
16808 return ret;
16809 diff -urNp linux-2.6.39.1/arch/x86/kernel/reboot.c linux-2.6.39.1/arch/x86/kernel/reboot.c
16810 --- linux-2.6.39.1/arch/x86/kernel/reboot.c 2011-05-19 00:06:34.000000000 -0400
16811 +++ linux-2.6.39.1/arch/x86/kernel/reboot.c 2011-05-23 17:07:00.000000000 -0400
16812 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16813 EXPORT_SYMBOL(pm_power_off);
16814
16815 static const struct desc_ptr no_idt = {};
16816 -static int reboot_mode;
16817 +static unsigned short reboot_mode;
16818 enum reboot_type reboot_type = BOOT_KBD;
16819 int reboot_force;
16820
16821 @@ -307,13 +307,17 @@ core_initcall(reboot_init);
16822 extern const unsigned char machine_real_restart_asm[];
16823 extern const u64 machine_real_restart_gdt[3];
16824
16825 -void machine_real_restart(unsigned int type)
16826 +__noreturn void machine_real_restart(unsigned int type)
16827 {
16828 void *restart_va;
16829 unsigned long restart_pa;
16830 - void (*restart_lowmem)(unsigned int);
16831 + void (* __noreturn restart_lowmem)(unsigned int);
16832 u64 *lowmem_gdt;
16833
16834 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16835 + struct desc_struct *gdt;
16836 +#endif
16837 +
16838 local_irq_disable();
16839
16840 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16841 @@ -339,14 +343,14 @@ void machine_real_restart(unsigned int t
16842 boot)". This seems like a fairly standard thing that gets set by
16843 REBOOT.COM programs, and the previous reset routine did this
16844 too. */
16845 - *((unsigned short *)0x472) = reboot_mode;
16846 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16847
16848 /* Patch the GDT in the low memory trampoline */
16849 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16850
16851 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16852 restart_pa = virt_to_phys(restart_va);
16853 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16854 + restart_lowmem = (void *)restart_pa;
16855
16856 /* GDT[0]: GDT self-pointer */
16857 lowmem_gdt[0] =
16858 @@ -357,7 +361,33 @@ void machine_real_restart(unsigned int t
16859 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16860
16861 /* Jump to the identity-mapped low memory code */
16862 +
16863 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16864 + gdt = get_cpu_gdt_table(smp_processor_id());
16865 + pax_open_kernel();
16866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16867 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16868 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16869 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16870 +#endif
16871 +#ifdef CONFIG_PAX_KERNEXEC
16872 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16873 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16874 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16875 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16876 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16877 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16878 +#endif
16879 + pax_close_kernel();
16880 +#endif
16881 +
16882 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16883 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16884 + unreachable();
16885 +#else
16886 restart_lowmem(type);
16887 +#endif
16888 +
16889 }
16890 #ifdef CONFIG_APM_MODULE
16891 EXPORT_SYMBOL(machine_real_restart);
16892 @@ -478,7 +508,7 @@ void __attribute__((weak)) mach_reboot_f
16893 {
16894 }
16895
16896 -static void native_machine_emergency_restart(void)
16897 +__noreturn static void native_machine_emergency_restart(void)
16898 {
16899 int i;
16900
16901 @@ -593,13 +623,13 @@ void native_machine_shutdown(void)
16902 #endif
16903 }
16904
16905 -static void __machine_emergency_restart(int emergency)
16906 +static __noreturn void __machine_emergency_restart(int emergency)
16907 {
16908 reboot_emergency = emergency;
16909 machine_ops.emergency_restart();
16910 }
16911
16912 -static void native_machine_restart(char *__unused)
16913 +static __noreturn void native_machine_restart(char *__unused)
16914 {
16915 printk("machine restart\n");
16916
16917 @@ -608,7 +638,7 @@ static void native_machine_restart(char
16918 __machine_emergency_restart(0);
16919 }
16920
16921 -static void native_machine_halt(void)
16922 +static __noreturn void native_machine_halt(void)
16923 {
16924 /* stop other cpus and apics */
16925 machine_shutdown();
16926 @@ -619,7 +649,7 @@ static void native_machine_halt(void)
16927 stop_this_cpu(NULL);
16928 }
16929
16930 -static void native_machine_power_off(void)
16931 +__noreturn static void native_machine_power_off(void)
16932 {
16933 if (pm_power_off) {
16934 if (!reboot_force)
16935 @@ -628,6 +658,7 @@ static void native_machine_power_off(voi
16936 }
16937 /* a fallback in case there is no PM info available */
16938 tboot_shutdown(TB_SHUTDOWN_HALT);
16939 + unreachable();
16940 }
16941
16942 struct machine_ops machine_ops = {
16943 diff -urNp linux-2.6.39.1/arch/x86/kernel/setup.c linux-2.6.39.1/arch/x86/kernel/setup.c
16944 --- linux-2.6.39.1/arch/x86/kernel/setup.c 2011-06-03 00:04:13.000000000 -0400
16945 +++ linux-2.6.39.1/arch/x86/kernel/setup.c 2011-06-03 00:32:04.000000000 -0400
16946 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16947 * area (640->1Mb) as ram even though it is not.
16948 * take them out.
16949 */
16950 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16951 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16952 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16953 }
16954
16955 @@ -775,14 +775,14 @@ void __init setup_arch(char **cmdline_p)
16956
16957 if (!boot_params.hdr.root_flags)
16958 root_mountflags &= ~MS_RDONLY;
16959 - init_mm.start_code = (unsigned long) _text;
16960 - init_mm.end_code = (unsigned long) _etext;
16961 + init_mm.start_code = ktla_ktva((unsigned long) _text);
16962 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
16963 init_mm.end_data = (unsigned long) _edata;
16964 init_mm.brk = _brk_end;
16965
16966 - code_resource.start = virt_to_phys(_text);
16967 - code_resource.end = virt_to_phys(_etext)-1;
16968 - data_resource.start = virt_to_phys(_etext);
16969 + code_resource.start = virt_to_phys(ktla_ktva(_text));
16970 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16971 + data_resource.start = virt_to_phys(_sdata);
16972 data_resource.end = virt_to_phys(_edata)-1;
16973 bss_resource.start = virt_to_phys(&__bss_start);
16974 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16975 diff -urNp linux-2.6.39.1/arch/x86/kernel/setup_percpu.c linux-2.6.39.1/arch/x86/kernel/setup_percpu.c
16976 --- linux-2.6.39.1/arch/x86/kernel/setup_percpu.c 2011-05-19 00:06:34.000000000 -0400
16977 +++ linux-2.6.39.1/arch/x86/kernel/setup_percpu.c 2011-06-03 00:54:40.000000000 -0400
16978 @@ -21,19 +21,17 @@
16979 #include <asm/cpu.h>
16980 #include <asm/stackprotector.h>
16981
16982 -DEFINE_PER_CPU(int, cpu_number);
16983 +#ifdef CONFIG_SMP
16984 +DEFINE_PER_CPU(unsigned int, cpu_number);
16985 EXPORT_PER_CPU_SYMBOL(cpu_number);
16986 +#endif
16987
16988 -#ifdef CONFIG_X86_64
16989 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16990 -#else
16991 -#define BOOT_PERCPU_OFFSET 0
16992 -#endif
16993
16994 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16995 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16996
16997 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16998 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16999 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17000 };
17001 EXPORT_SYMBOL(__per_cpu_offset);
17002 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
17003 {
17004 #ifdef CONFIG_X86_32
17005 struct desc_struct gdt;
17006 + unsigned long base = per_cpu_offset(cpu);
17007
17008 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17009 - 0x2 | DESCTYPE_S, 0x8);
17010 - gdt.s = 1;
17011 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17012 + 0x83 | DESCTYPE_S, 0xC);
17013 write_gdt_entry(get_cpu_gdt_table(cpu),
17014 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17015 #endif
17016 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
17017 /* alrighty, percpu areas up and running */
17018 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17019 for_each_possible_cpu(cpu) {
17020 +#ifdef CONFIG_CC_STACKPROTECTOR
17021 +#ifdef CONFIG_X86_32
17022 + unsigned long canary = per_cpu(stack_canary, cpu);
17023 +#endif
17024 +#endif
17025 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17026 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17027 per_cpu(cpu_number, cpu) = cpu;
17028 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17029 */
17030 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17031 #endif
17032 +#ifdef CONFIG_CC_STACKPROTECTOR
17033 +#ifdef CONFIG_X86_32
17034 + if (cpu == boot_cpu_id)
17035 + per_cpu(stack_canary, cpu) = canary;
17036 +#endif
17037 +#endif
17038 /*
17039 * Up to this point, the boot CPU has been using .init.data
17040 * area. Reload any changed state for the boot CPU.
17041 diff -urNp linux-2.6.39.1/arch/x86/kernel/signal.c linux-2.6.39.1/arch/x86/kernel/signal.c
17042 --- linux-2.6.39.1/arch/x86/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
17043 +++ linux-2.6.39.1/arch/x86/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
17044 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
17045 * Align the stack pointer according to the i386 ABI,
17046 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17047 */
17048 - sp = ((sp + 4) & -16ul) - 4;
17049 + sp = ((sp - 12) & -16ul) - 4;
17050 #else /* !CONFIG_X86_32 */
17051 sp = round_down(sp, 16) - 8;
17052 #endif
17053 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
17054 * Return an always-bogus address instead so we will die with SIGSEGV.
17055 */
17056 if (onsigstack && !likely(on_sig_stack(sp)))
17057 - return (void __user *)-1L;
17058 + return (__force void __user *)-1L;
17059
17060 /* save i387 state */
17061 if (used_math() && save_i387_xstate(*fpstate) < 0)
17062 - return (void __user *)-1L;
17063 + return (__force void __user *)-1L;
17064
17065 return (void __user *)sp;
17066 }
17067 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
17068 }
17069
17070 if (current->mm->context.vdso)
17071 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17072 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17073 else
17074 - restorer = &frame->retcode;
17075 + restorer = (void __user *)&frame->retcode;
17076 if (ka->sa.sa_flags & SA_RESTORER)
17077 restorer = ka->sa.sa_restorer;
17078
17079 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
17080 * reasons and because gdb uses it as a signature to notice
17081 * signal handler stack frames.
17082 */
17083 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17084 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17085
17086 if (err)
17087 return -EFAULT;
17088 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
17089 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17090
17091 /* Set up to return from userspace. */
17092 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17093 + if (current->mm->context.vdso)
17094 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17095 + else
17096 + restorer = (void __user *)&frame->retcode;
17097 if (ka->sa.sa_flags & SA_RESTORER)
17098 restorer = ka->sa.sa_restorer;
17099 put_user_ex(restorer, &frame->pretcode);
17100 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
17101 * reasons and because gdb uses it as a signature to notice
17102 * signal handler stack frames.
17103 */
17104 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17105 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17106 } put_user_catch(err);
17107
17108 if (err)
17109 @@ -773,6 +776,8 @@ static void do_signal(struct pt_regs *re
17110 int signr;
17111 sigset_t *oldset;
17112
17113 + pax_track_stack();
17114 +
17115 /*
17116 * We want the common case to go fast, which is why we may in certain
17117 * cases get here from kernel mode. Just return without doing anything
17118 @@ -780,7 +785,7 @@ static void do_signal(struct pt_regs *re
17119 * X86_32: vm86 regs switched out by assembly code before reaching
17120 * here, so testing against kernel CS suffices.
17121 */
17122 - if (!user_mode(regs))
17123 + if (!user_mode_novm(regs))
17124 return;
17125
17126 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
17127 diff -urNp linux-2.6.39.1/arch/x86/kernel/smpboot.c linux-2.6.39.1/arch/x86/kernel/smpboot.c
17128 --- linux-2.6.39.1/arch/x86/kernel/smpboot.c 2011-05-19 00:06:34.000000000 -0400
17129 +++ linux-2.6.39.1/arch/x86/kernel/smpboot.c 2011-05-22 19:36:30.000000000 -0400
17130 @@ -696,17 +696,20 @@ static int __cpuinit do_boot_cpu(int api
17131 set_idle_for_cpu(cpu, c_idle.idle);
17132 do_rest:
17133 per_cpu(current_task, cpu) = c_idle.idle;
17134 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17135 #ifdef CONFIG_X86_32
17136 /* Stack for startup_32 can be just as for start_secondary onwards */
17137 irq_ctx_init(cpu);
17138 #else
17139 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17140 initial_gs = per_cpu_offset(cpu);
17141 - per_cpu(kernel_stack, cpu) =
17142 - (unsigned long)task_stack_page(c_idle.idle) -
17143 - KERNEL_STACK_OFFSET + THREAD_SIZE;
17144 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17145 #endif
17146 +
17147 + pax_open_kernel();
17148 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17149 + pax_close_kernel();
17150 +
17151 initial_code = (unsigned long)start_secondary;
17152 stack_start = c_idle.idle->thread.sp;
17153
17154 @@ -848,6 +851,12 @@ int __cpuinit native_cpu_up(unsigned int
17155
17156 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17157
17158 +#ifdef CONFIG_PAX_PER_CPU_PGD
17159 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17160 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17161 + KERNEL_PGD_PTRS);
17162 +#endif
17163 +
17164 err = do_boot_cpu(apicid, cpu);
17165 if (err) {
17166 pr_debug("do_boot_cpu failed %d\n", err);
17167 diff -urNp linux-2.6.39.1/arch/x86/kernel/step.c linux-2.6.39.1/arch/x86/kernel/step.c
17168 --- linux-2.6.39.1/arch/x86/kernel/step.c 2011-05-19 00:06:34.000000000 -0400
17169 +++ linux-2.6.39.1/arch/x86/kernel/step.c 2011-05-22 19:36:30.000000000 -0400
17170 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
17171 struct desc_struct *desc;
17172 unsigned long base;
17173
17174 - seg &= ~7UL;
17175 + seg >>= 3;
17176
17177 mutex_lock(&child->mm->context.lock);
17178 - if (unlikely((seg >> 3) >= child->mm->context.size))
17179 + if (unlikely(seg >= child->mm->context.size))
17180 addr = -1L; /* bogus selector, access would fault */
17181 else {
17182 desc = child->mm->context.ldt + seg;
17183 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
17184 addr += base;
17185 }
17186 mutex_unlock(&child->mm->context.lock);
17187 - }
17188 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17189 + addr = ktla_ktva(addr);
17190
17191 return addr;
17192 }
17193 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
17194 unsigned char opcode[15];
17195 unsigned long addr = convert_ip_to_linear(child, regs);
17196
17197 + if (addr == -EINVAL)
17198 + return 0;
17199 +
17200 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17201 for (i = 0; i < copied; i++) {
17202 switch (opcode[i]) {
17203 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
17204
17205 #ifdef CONFIG_X86_64
17206 case 0x40 ... 0x4f:
17207 - if (regs->cs != __USER_CS)
17208 + if ((regs->cs & 0xffff) != __USER_CS)
17209 /* 32-bit mode: register increment */
17210 return 0;
17211 /* 64-bit mode: REX prefix */
17212 diff -urNp linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S
17213 --- linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S 2011-05-19 00:06:34.000000000 -0400
17214 +++ linux-2.6.39.1/arch/x86/kernel/syscall_table_32.S 2011-05-22 19:36:30.000000000 -0400
17215 @@ -1,3 +1,4 @@
17216 +.section .rodata,"a",@progbits
17217 ENTRY(sys_call_table)
17218 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17219 .long sys_exit
17220 diff -urNp linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c
17221 --- linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c 2011-05-19 00:06:34.000000000 -0400
17222 +++ linux-2.6.39.1/arch/x86/kernel/sys_i386_32.c 2011-05-22 19:36:30.000000000 -0400
17223 @@ -24,17 +24,224 @@
17224
17225 #include <asm/syscalls.h>
17226
17227 -/*
17228 - * Do a system call from kernel instead of calling sys_execve so we
17229 - * end up with proper pt_regs.
17230 - */
17231 -int kernel_execve(const char *filename,
17232 - const char *const argv[],
17233 - const char *const envp[])
17234 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17235 {
17236 - long __res;
17237 - asm volatile ("int $0x80"
17238 - : "=a" (__res)
17239 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17240 - return __res;
17241 + unsigned long pax_task_size = TASK_SIZE;
17242 +
17243 +#ifdef CONFIG_PAX_SEGMEXEC
17244 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17245 + pax_task_size = SEGMEXEC_TASK_SIZE;
17246 +#endif
17247 +
17248 + if (len > pax_task_size || addr > pax_task_size - len)
17249 + return -EINVAL;
17250 +
17251 + return 0;
17252 +}
17253 +
17254 +unsigned long
17255 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17256 + unsigned long len, unsigned long pgoff, unsigned long flags)
17257 +{
17258 + struct mm_struct *mm = current->mm;
17259 + struct vm_area_struct *vma;
17260 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17261 +
17262 +#ifdef CONFIG_PAX_SEGMEXEC
17263 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17264 + pax_task_size = SEGMEXEC_TASK_SIZE;
17265 +#endif
17266 +
17267 + pax_task_size -= PAGE_SIZE;
17268 +
17269 + if (len > pax_task_size)
17270 + return -ENOMEM;
17271 +
17272 + if (flags & MAP_FIXED)
17273 + return addr;
17274 +
17275 +#ifdef CONFIG_PAX_RANDMMAP
17276 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17277 +#endif
17278 +
17279 + if (addr) {
17280 + addr = PAGE_ALIGN(addr);
17281 + if (pax_task_size - len >= addr) {
17282 + vma = find_vma(mm, addr);
17283 + if (check_heap_stack_gap(vma, addr, len))
17284 + return addr;
17285 + }
17286 + }
17287 + if (len > mm->cached_hole_size) {
17288 + start_addr = addr = mm->free_area_cache;
17289 + } else {
17290 + start_addr = addr = mm->mmap_base;
17291 + mm->cached_hole_size = 0;
17292 + }
17293 +
17294 +#ifdef CONFIG_PAX_PAGEEXEC
17295 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17296 + start_addr = 0x00110000UL;
17297 +
17298 +#ifdef CONFIG_PAX_RANDMMAP
17299 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17300 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17301 +#endif
17302 +
17303 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17304 + start_addr = addr = mm->mmap_base;
17305 + else
17306 + addr = start_addr;
17307 + }
17308 +#endif
17309 +
17310 +full_search:
17311 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17312 + /* At this point: (!vma || addr < vma->vm_end). */
17313 + if (pax_task_size - len < addr) {
17314 + /*
17315 + * Start a new search - just in case we missed
17316 + * some holes.
17317 + */
17318 + if (start_addr != mm->mmap_base) {
17319 + start_addr = addr = mm->mmap_base;
17320 + mm->cached_hole_size = 0;
17321 + goto full_search;
17322 + }
17323 + return -ENOMEM;
17324 + }
17325 + if (check_heap_stack_gap(vma, addr, len))
17326 + break;
17327 + if (addr + mm->cached_hole_size < vma->vm_start)
17328 + mm->cached_hole_size = vma->vm_start - addr;
17329 + addr = vma->vm_end;
17330 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17331 + start_addr = addr = mm->mmap_base;
17332 + mm->cached_hole_size = 0;
17333 + goto full_search;
17334 + }
17335 + }
17336 +
17337 + /*
17338 + * Remember the place where we stopped the search:
17339 + */
17340 + mm->free_area_cache = addr + len;
17341 + return addr;
17342 +}
17343 +
17344 +unsigned long
17345 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17346 + const unsigned long len, const unsigned long pgoff,
17347 + const unsigned long flags)
17348 +{
17349 + struct vm_area_struct *vma;
17350 + struct mm_struct *mm = current->mm;
17351 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17352 +
17353 +#ifdef CONFIG_PAX_SEGMEXEC
17354 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17355 + pax_task_size = SEGMEXEC_TASK_SIZE;
17356 +#endif
17357 +
17358 + pax_task_size -= PAGE_SIZE;
17359 +
17360 + /* requested length too big for entire address space */
17361 + if (len > pax_task_size)
17362 + return -ENOMEM;
17363 +
17364 + if (flags & MAP_FIXED)
17365 + return addr;
17366 +
17367 +#ifdef CONFIG_PAX_PAGEEXEC
17368 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17369 + goto bottomup;
17370 +#endif
17371 +
17372 +#ifdef CONFIG_PAX_RANDMMAP
17373 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17374 +#endif
17375 +
17376 + /* requesting a specific address */
17377 + if (addr) {
17378 + addr = PAGE_ALIGN(addr);
17379 + if (pax_task_size - len >= addr) {
17380 + vma = find_vma(mm, addr);
17381 + if (check_heap_stack_gap(vma, addr, len))
17382 + return addr;
17383 + }
17384 + }
17385 +
17386 + /* check if free_area_cache is useful for us */
17387 + if (len <= mm->cached_hole_size) {
17388 + mm->cached_hole_size = 0;
17389 + mm->free_area_cache = mm->mmap_base;
17390 + }
17391 +
17392 + /* either no address requested or can't fit in requested address hole */
17393 + addr = mm->free_area_cache;
17394 +
17395 + /* make sure it can fit in the remaining address space */
17396 + if (addr > len) {
17397 + vma = find_vma(mm, addr-len);
17398 + if (check_heap_stack_gap(vma, addr - len, len))
17399 + /* remember the address as a hint for next time */
17400 + return (mm->free_area_cache = addr-len);
17401 + }
17402 +
17403 + if (mm->mmap_base < len)
17404 + goto bottomup;
17405 +
17406 + addr = mm->mmap_base-len;
17407 +
17408 + do {
17409 + /*
17410 + * Lookup failure means no vma is above this address,
17411 + * else if new region fits below vma->vm_start,
17412 + * return with success:
17413 + */
17414 + vma = find_vma(mm, addr);
17415 + if (check_heap_stack_gap(vma, addr, len))
17416 + /* remember the address as a hint for next time */
17417 + return (mm->free_area_cache = addr);
17418 +
17419 + /* remember the largest hole we saw so far */
17420 + if (addr + mm->cached_hole_size < vma->vm_start)
17421 + mm->cached_hole_size = vma->vm_start - addr;
17422 +
17423 + /* try just below the current vma->vm_start */
17424 + addr = skip_heap_stack_gap(vma, len);
17425 + } while (!IS_ERR_VALUE(addr));
17426 +
17427 +bottomup:
17428 + /*
17429 + * A failed mmap() very likely causes application failure,
17430 + * so fall back to the bottom-up function here. This scenario
17431 + * can happen with large stack limits and large mmap()
17432 + * allocations.
17433 + */
17434 +
17435 +#ifdef CONFIG_PAX_SEGMEXEC
17436 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17437 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17438 + else
17439 +#endif
17440 +
17441 + mm->mmap_base = TASK_UNMAPPED_BASE;
17442 +
17443 +#ifdef CONFIG_PAX_RANDMMAP
17444 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17445 + mm->mmap_base += mm->delta_mmap;
17446 +#endif
17447 +
17448 + mm->free_area_cache = mm->mmap_base;
17449 + mm->cached_hole_size = ~0UL;
17450 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17451 + /*
17452 + * Restore the topdown base:
17453 + */
17454 + mm->mmap_base = base;
17455 + mm->free_area_cache = base;
17456 + mm->cached_hole_size = ~0UL;
17457 +
17458 + return addr;
17459 }
17460 diff -urNp linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c
17461 --- linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c 2011-05-19 00:06:34.000000000 -0400
17462 +++ linux-2.6.39.1/arch/x86/kernel/sys_x86_64.c 2011-05-22 19:36:30.000000000 -0400
17463 @@ -32,8 +32,8 @@ out:
17464 return error;
17465 }
17466
17467 -static void find_start_end(unsigned long flags, unsigned long *begin,
17468 - unsigned long *end)
17469 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17470 + unsigned long *begin, unsigned long *end)
17471 {
17472 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17473 unsigned long new_begin;
17474 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17475 *begin = new_begin;
17476 }
17477 } else {
17478 - *begin = TASK_UNMAPPED_BASE;
17479 + *begin = mm->mmap_base;
17480 *end = TASK_SIZE;
17481 }
17482 }
17483 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17484 if (flags & MAP_FIXED)
17485 return addr;
17486
17487 - find_start_end(flags, &begin, &end);
17488 + find_start_end(mm, flags, &begin, &end);
17489
17490 if (len > end)
17491 return -ENOMEM;
17492
17493 +#ifdef CONFIG_PAX_RANDMMAP
17494 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17495 +#endif
17496 +
17497 if (addr) {
17498 addr = PAGE_ALIGN(addr);
17499 vma = find_vma(mm, addr);
17500 - if (end - len >= addr &&
17501 - (!vma || addr + len <= vma->vm_start))
17502 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17503 return addr;
17504 }
17505 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17506 @@ -106,7 +109,7 @@ full_search:
17507 }
17508 return -ENOMEM;
17509 }
17510 - if (!vma || addr + len <= vma->vm_start) {
17511 + if (check_heap_stack_gap(vma, addr, len)) {
17512 /*
17513 * Remember the place where we stopped the search:
17514 */
17515 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17516 {
17517 struct vm_area_struct *vma;
17518 struct mm_struct *mm = current->mm;
17519 - unsigned long addr = addr0;
17520 + unsigned long base = mm->mmap_base, addr = addr0;
17521
17522 /* requested length too big for entire address space */
17523 if (len > TASK_SIZE)
17524 @@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17525 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17526 goto bottomup;
17527
17528 +#ifdef CONFIG_PAX_RANDMMAP
17529 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17530 +#endif
17531 +
17532 /* requesting a specific address */
17533 if (addr) {
17534 addr = PAGE_ALIGN(addr);
17535 - vma = find_vma(mm, addr);
17536 - if (TASK_SIZE - len >= addr &&
17537 - (!vma || addr + len <= vma->vm_start))
17538 - return addr;
17539 + if (TASK_SIZE - len >= addr) {
17540 + vma = find_vma(mm, addr);
17541 + if (check_heap_stack_gap(vma, addr, len))
17542 + return addr;
17543 + }
17544 }
17545
17546 /* check if free_area_cache is useful for us */
17547 @@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17548 /* make sure it can fit in the remaining address space */
17549 if (addr > len) {
17550 vma = find_vma(mm, addr-len);
17551 - if (!vma || addr <= vma->vm_start)
17552 + if (check_heap_stack_gap(vma, addr - len, len))
17553 /* remember the address as a hint for next time */
17554 return mm->free_area_cache = addr-len;
17555 }
17556 @@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17557 * return with success:
17558 */
17559 vma = find_vma(mm, addr);
17560 - if (!vma || addr+len <= vma->vm_start)
17561 + if (check_heap_stack_gap(vma, addr, len))
17562 /* remember the address as a hint for next time */
17563 return mm->free_area_cache = addr;
17564
17565 @@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17566 mm->cached_hole_size = vma->vm_start - addr;
17567
17568 /* try just below the current vma->vm_start */
17569 - addr = vma->vm_start-len;
17570 - } while (len < vma->vm_start);
17571 + addr = skip_heap_stack_gap(vma, len);
17572 + } while (!IS_ERR_VALUE(addr));
17573
17574 bottomup:
17575 /*
17576 @@ -198,13 +206,21 @@ bottomup:
17577 * can happen with large stack limits and large mmap()
17578 * allocations.
17579 */
17580 + mm->mmap_base = TASK_UNMAPPED_BASE;
17581 +
17582 +#ifdef CONFIG_PAX_RANDMMAP
17583 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17584 + mm->mmap_base += mm->delta_mmap;
17585 +#endif
17586 +
17587 + mm->free_area_cache = mm->mmap_base;
17588 mm->cached_hole_size = ~0UL;
17589 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17590 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17591 /*
17592 * Restore the topdown base:
17593 */
17594 - mm->free_area_cache = mm->mmap_base;
17595 + mm->mmap_base = base;
17596 + mm->free_area_cache = base;
17597 mm->cached_hole_size = ~0UL;
17598
17599 return addr;
17600 diff -urNp linux-2.6.39.1/arch/x86/kernel/tboot.c linux-2.6.39.1/arch/x86/kernel/tboot.c
17601 --- linux-2.6.39.1/arch/x86/kernel/tboot.c 2011-05-19 00:06:34.000000000 -0400
17602 +++ linux-2.6.39.1/arch/x86/kernel/tboot.c 2011-05-22 19:36:30.000000000 -0400
17603 @@ -218,7 +218,7 @@ static int tboot_setup_sleep(void)
17604
17605 void tboot_shutdown(u32 shutdown_type)
17606 {
17607 - void (*shutdown)(void);
17608 + void (* __noreturn shutdown)(void);
17609
17610 if (!tboot_enabled())
17611 return;
17612 @@ -240,7 +240,7 @@ void tboot_shutdown(u32 shutdown_type)
17613
17614 switch_to_tboot_pt();
17615
17616 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17617 + shutdown = (void *)tboot->shutdown_entry;
17618 shutdown();
17619
17620 /* should not reach here */
17621 @@ -297,7 +297,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17622 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17623 }
17624
17625 -static atomic_t ap_wfs_count;
17626 +static atomic_unchecked_t ap_wfs_count;
17627
17628 static int tboot_wait_for_aps(int num_aps)
17629 {
17630 @@ -321,9 +321,9 @@ static int __cpuinit tboot_cpu_callback(
17631 {
17632 switch (action) {
17633 case CPU_DYING:
17634 - atomic_inc(&ap_wfs_count);
17635 + atomic_inc_unchecked(&ap_wfs_count);
17636 if (num_online_cpus() == 1)
17637 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17638 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17639 return NOTIFY_BAD;
17640 break;
17641 }
17642 @@ -342,7 +342,7 @@ static __init int tboot_late_init(void)
17643
17644 tboot_create_trampoline();
17645
17646 - atomic_set(&ap_wfs_count, 0);
17647 + atomic_set_unchecked(&ap_wfs_count, 0);
17648 register_hotcpu_notifier(&tboot_cpu_notifier);
17649 return 0;
17650 }
17651 diff -urNp linux-2.6.39.1/arch/x86/kernel/time.c linux-2.6.39.1/arch/x86/kernel/time.c
17652 --- linux-2.6.39.1/arch/x86/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
17653 +++ linux-2.6.39.1/arch/x86/kernel/time.c 2011-05-22 19:36:30.000000000 -0400
17654 @@ -22,17 +22,13 @@
17655 #include <asm/hpet.h>
17656 #include <asm/time.h>
17657
17658 -#ifdef CONFIG_X86_64
17659 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17660 -#endif
17661 -
17662 unsigned long profile_pc(struct pt_regs *regs)
17663 {
17664 unsigned long pc = instruction_pointer(regs);
17665
17666 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17667 + if (!user_mode(regs) && in_lock_functions(pc)) {
17668 #ifdef CONFIG_FRAME_POINTER
17669 - return *(unsigned long *)(regs->bp + sizeof(long));
17670 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17671 #else
17672 unsigned long *sp =
17673 (unsigned long *)kernel_stack_pointer(regs);
17674 @@ -41,11 +37,17 @@ unsigned long profile_pc(struct pt_regs
17675 * or above a saved flags. Eflags has bits 22-31 zero,
17676 * kernel addresses don't.
17677 */
17678 +
17679 +#ifdef CONFIG_PAX_KERNEXEC
17680 + return ktla_ktva(sp[0]);
17681 +#else
17682 if (sp[0] >> 22)
17683 return sp[0];
17684 if (sp[1] >> 22)
17685 return sp[1];
17686 #endif
17687 +
17688 +#endif
17689 }
17690 return pc;
17691 }
17692 diff -urNp linux-2.6.39.1/arch/x86/kernel/tls.c linux-2.6.39.1/arch/x86/kernel/tls.c
17693 --- linux-2.6.39.1/arch/x86/kernel/tls.c 2011-05-19 00:06:34.000000000 -0400
17694 +++ linux-2.6.39.1/arch/x86/kernel/tls.c 2011-05-22 19:36:30.000000000 -0400
17695 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17696 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17697 return -EINVAL;
17698
17699 +#ifdef CONFIG_PAX_SEGMEXEC
17700 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17701 + return -EINVAL;
17702 +#endif
17703 +
17704 set_tls_desc(p, idx, &info, 1);
17705
17706 return 0;
17707 diff -urNp linux-2.6.39.1/arch/x86/kernel/trampoline_32.S linux-2.6.39.1/arch/x86/kernel/trampoline_32.S
17708 --- linux-2.6.39.1/arch/x86/kernel/trampoline_32.S 2011-05-19 00:06:34.000000000 -0400
17709 +++ linux-2.6.39.1/arch/x86/kernel/trampoline_32.S 2011-05-22 19:36:30.000000000 -0400
17710 @@ -32,6 +32,12 @@
17711 #include <asm/segment.h>
17712 #include <asm/page_types.h>
17713
17714 +#ifdef CONFIG_PAX_KERNEXEC
17715 +#define ta(X) (X)
17716 +#else
17717 +#define ta(X) ((X) - __PAGE_OFFSET)
17718 +#endif
17719 +
17720 #ifdef CONFIG_SMP
17721
17722 .section ".x86_trampoline","a"
17723 @@ -62,7 +68,7 @@ r_base = .
17724 inc %ax # protected mode (PE) bit
17725 lmsw %ax # into protected mode
17726 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17727 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17728 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17729
17730 # These need to be in the same 64K segment as the above;
17731 # hence we don't use the boot_gdt_descr defined in head.S
17732 diff -urNp linux-2.6.39.1/arch/x86/kernel/trampoline_64.S linux-2.6.39.1/arch/x86/kernel/trampoline_64.S
17733 --- linux-2.6.39.1/arch/x86/kernel/trampoline_64.S 2011-05-19 00:06:34.000000000 -0400
17734 +++ linux-2.6.39.1/arch/x86/kernel/trampoline_64.S 2011-05-22 19:36:30.000000000 -0400
17735 @@ -90,7 +90,7 @@ startup_32:
17736 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17737 movl %eax, %ds
17738
17739 - movl $X86_CR4_PAE, %eax
17740 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17741 movl %eax, %cr4 # Enable PAE mode
17742
17743 # Setup trampoline 4 level pagetables
17744 @@ -138,7 +138,7 @@ tidt:
17745 # so the kernel can live anywhere
17746 .balign 4
17747 tgdt:
17748 - .short tgdt_end - tgdt # gdt limit
17749 + .short tgdt_end - tgdt - 1 # gdt limit
17750 .long tgdt - r_base
17751 .short 0
17752 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17753 diff -urNp linux-2.6.39.1/arch/x86/kernel/traps.c linux-2.6.39.1/arch/x86/kernel/traps.c
17754 --- linux-2.6.39.1/arch/x86/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
17755 +++ linux-2.6.39.1/arch/x86/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
17756 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17757
17758 /* Do we ignore FPU interrupts ? */
17759 char ignore_fpu_irq;
17760 -
17761 -/*
17762 - * The IDT has to be page-aligned to simplify the Pentium
17763 - * F0 0F bug workaround.
17764 - */
17765 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17766 #endif
17767
17768 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17769 @@ -117,13 +111,13 @@ static inline void preempt_conditional_c
17770 }
17771
17772 static void __kprobes
17773 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17774 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17775 long error_code, siginfo_t *info)
17776 {
17777 struct task_struct *tsk = current;
17778
17779 #ifdef CONFIG_X86_32
17780 - if (regs->flags & X86_VM_MASK) {
17781 + if (v8086_mode(regs)) {
17782 /*
17783 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17784 * On nmi (interrupt 2), do_trap should not be called.
17785 @@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str
17786 }
17787 #endif
17788
17789 - if (!user_mode(regs))
17790 + if (!user_mode_novm(regs))
17791 goto kernel_trap;
17792
17793 #ifdef CONFIG_X86_32
17794 @@ -157,7 +151,7 @@ trap_signal:
17795 printk_ratelimit()) {
17796 printk(KERN_INFO
17797 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17798 - tsk->comm, tsk->pid, str,
17799 + tsk->comm, task_pid_nr(tsk), str,
17800 regs->ip, regs->sp, error_code);
17801 print_vma_addr(" in ", regs->ip);
17802 printk("\n");
17803 @@ -174,8 +168,20 @@ kernel_trap:
17804 if (!fixup_exception(regs)) {
17805 tsk->thread.error_code = error_code;
17806 tsk->thread.trap_no = trapnr;
17807 +
17808 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17809 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17810 + str = "PAX: suspicious stack segment fault";
17811 +#endif
17812 +
17813 die(str, regs, error_code);
17814 }
17815 +
17816 +#ifdef CONFIG_PAX_REFCOUNT
17817 + if (trapnr == 4)
17818 + pax_report_refcount_overflow(regs);
17819 +#endif
17820 +
17821 return;
17822
17823 #ifdef CONFIG_X86_32
17824 @@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *re
17825 conditional_sti(regs);
17826
17827 #ifdef CONFIG_X86_32
17828 - if (regs->flags & X86_VM_MASK)
17829 + if (v8086_mode(regs))
17830 goto gp_in_vm86;
17831 #endif
17832
17833 tsk = current;
17834 - if (!user_mode(regs))
17835 + if (!user_mode_novm(regs))
17836 goto gp_in_kernel;
17837
17838 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17839 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17840 + struct mm_struct *mm = tsk->mm;
17841 + unsigned long limit;
17842 +
17843 + down_write(&mm->mmap_sem);
17844 + limit = mm->context.user_cs_limit;
17845 + if (limit < TASK_SIZE) {
17846 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17847 + up_write(&mm->mmap_sem);
17848 + return;
17849 + }
17850 + up_write(&mm->mmap_sem);
17851 + }
17852 +#endif
17853 +
17854 tsk->thread.error_code = error_code;
17855 tsk->thread.trap_no = 13;
17856
17857 @@ -304,6 +326,13 @@ gp_in_kernel:
17858 if (notify_die(DIE_GPF, "general protection fault", regs,
17859 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17860 return;
17861 +
17862 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17863 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17864 + die("PAX: suspicious general protection fault", regs, error_code);
17865 + else
17866 +#endif
17867 +
17868 die("general protection fault", regs, error_code);
17869 }
17870
17871 @@ -569,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
17872 /* It's safe to allow irq's after DR6 has been saved */
17873 preempt_conditional_sti(regs);
17874
17875 - if (regs->flags & X86_VM_MASK) {
17876 + if (v8086_mode(regs)) {
17877 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17878 error_code, 1);
17879 preempt_conditional_cli(regs);
17880 @@ -583,7 +612,7 @@ dotraplinkage void __kprobes do_debug(st
17881 * We already checked v86 mode above, so we can check for kernel mode
17882 * by just checking the CPL of CS.
17883 */
17884 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17885 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17886 tsk->thread.debugreg6 &= ~DR_STEP;
17887 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17888 regs->flags &= ~X86_EFLAGS_TF;
17889 @@ -612,7 +641,7 @@ void math_error(struct pt_regs *regs, in
17890 return;
17891 conditional_sti(regs);
17892
17893 - if (!user_mode_vm(regs))
17894 + if (!user_mode(regs))
17895 {
17896 if (!fixup_exception(regs)) {
17897 task->thread.error_code = error_code;
17898 @@ -723,7 +752,7 @@ asmlinkage void __attribute__((weak)) sm
17899 void __math_state_restore(void)
17900 {
17901 struct thread_info *thread = current_thread_info();
17902 - struct task_struct *tsk = thread->task;
17903 + struct task_struct *tsk = current;
17904
17905 /*
17906 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17907 @@ -750,8 +779,7 @@ void __math_state_restore(void)
17908 */
17909 asmlinkage void math_state_restore(void)
17910 {
17911 - struct thread_info *thread = current_thread_info();
17912 - struct task_struct *tsk = thread->task;
17913 + struct task_struct *tsk = current;
17914
17915 if (!tsk_used_math(tsk)) {
17916 local_irq_enable();
17917 diff -urNp linux-2.6.39.1/arch/x86/kernel/vm86_32.c linux-2.6.39.1/arch/x86/kernel/vm86_32.c
17918 --- linux-2.6.39.1/arch/x86/kernel/vm86_32.c 2011-05-19 00:06:34.000000000 -0400
17919 +++ linux-2.6.39.1/arch/x86/kernel/vm86_32.c 2011-05-22 19:41:32.000000000 -0400
17920 @@ -41,6 +41,7 @@
17921 #include <linux/ptrace.h>
17922 #include <linux/audit.h>
17923 #include <linux/stddef.h>
17924 +#include <linux/grsecurity.h>
17925
17926 #include <asm/uaccess.h>
17927 #include <asm/io.h>
17928 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
17929 do_exit(SIGSEGV);
17930 }
17931
17932 - tss = &per_cpu(init_tss, get_cpu());
17933 + tss = init_tss + get_cpu();
17934 current->thread.sp0 = current->thread.saved_sp0;
17935 current->thread.sysenter_cs = __KERNEL_CS;
17936 load_sp0(tss, &current->thread);
17937 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __use
17938 struct task_struct *tsk;
17939 int tmp, ret = -EPERM;
17940
17941 +#ifdef CONFIG_GRKERNSEC_VM86
17942 + if (!capable(CAP_SYS_RAWIO)) {
17943 + gr_handle_vm86();
17944 + goto out;
17945 + }
17946 +#endif
17947 +
17948 tsk = current;
17949 if (tsk->thread.saved_sp0)
17950 goto out;
17951 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned
17952 int tmp, ret;
17953 struct vm86plus_struct __user *v86;
17954
17955 +#ifdef CONFIG_GRKERNSEC_VM86
17956 + if (!capable(CAP_SYS_RAWIO)) {
17957 + gr_handle_vm86();
17958 + ret = -EPERM;
17959 + goto out;
17960 + }
17961 +#endif
17962 +
17963 tsk = current;
17964 switch (cmd) {
17965 case VM86_REQUEST_IRQ:
17966 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
17967 tsk->thread.saved_fs = info->regs32->fs;
17968 tsk->thread.saved_gs = get_user_gs(info->regs32);
17969
17970 - tss = &per_cpu(init_tss, get_cpu());
17971 + tss = init_tss + get_cpu();
17972 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17973 if (cpu_has_sep)
17974 tsk->thread.sysenter_cs = 0;
17975 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
17976 goto cannot_handle;
17977 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17978 goto cannot_handle;
17979 - intr_ptr = (unsigned long __user *) (i << 2);
17980 + intr_ptr = (__force unsigned long __user *) (i << 2);
17981 if (get_user(segoffs, intr_ptr))
17982 goto cannot_handle;
17983 if ((segoffs >> 16) == BIOSSEG)
17984 diff -urNp linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S
17985 --- linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
17986 +++ linux-2.6.39.1/arch/x86/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
17987 @@ -26,6 +26,13 @@
17988 #include <asm/page_types.h>
17989 #include <asm/cache.h>
17990 #include <asm/boot.h>
17991 +#include <asm/segment.h>
17992 +
17993 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17994 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17995 +#else
17996 +#define __KERNEL_TEXT_OFFSET 0
17997 +#endif
17998
17999 #undef i386 /* in case the preprocessor is a 32bit one */
18000
18001 @@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
18002 #ifdef CONFIG_X86_32
18003 OUTPUT_ARCH(i386)
18004 ENTRY(phys_startup_32)
18005 -jiffies = jiffies_64;
18006 #else
18007 OUTPUT_ARCH(i386:x86-64)
18008 ENTRY(phys_startup_64)
18009 -jiffies_64 = jiffies;
18010 #endif
18011
18012 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
18013 @@ -69,31 +74,46 @@ jiffies_64 = jiffies;
18014
18015 PHDRS {
18016 text PT_LOAD FLAGS(5); /* R_E */
18017 +#ifdef CONFIG_X86_32
18018 + module PT_LOAD FLAGS(5); /* R_E */
18019 +#endif
18020 +#ifdef CONFIG_XEN
18021 + rodata PT_LOAD FLAGS(5); /* R_E */
18022 +#else
18023 + rodata PT_LOAD FLAGS(4); /* R__ */
18024 +#endif
18025 data PT_LOAD FLAGS(6); /* RW_ */
18026 #ifdef CONFIG_X86_64
18027 user PT_LOAD FLAGS(5); /* R_E */
18028 +#endif
18029 + init.begin PT_LOAD FLAGS(6); /* RW_ */
18030 #ifdef CONFIG_SMP
18031 percpu PT_LOAD FLAGS(6); /* RW_ */
18032 #endif
18033 + text.init PT_LOAD FLAGS(5); /* R_E */
18034 + text.exit PT_LOAD FLAGS(5); /* R_E */
18035 init PT_LOAD FLAGS(7); /* RWE */
18036 -#endif
18037 note PT_NOTE FLAGS(0); /* ___ */
18038 }
18039
18040 SECTIONS
18041 {
18042 #ifdef CONFIG_X86_32
18043 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18044 - phys_startup_32 = startup_32 - LOAD_OFFSET;
18045 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18046 #else
18047 - . = __START_KERNEL;
18048 - phys_startup_64 = startup_64 - LOAD_OFFSET;
18049 + . = __START_KERNEL;
18050 #endif
18051
18052 /* Text and read-only data */
18053 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
18054 - _text = .;
18055 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18056 /* bootstrapping code */
18057 +#ifdef CONFIG_X86_32
18058 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18059 +#else
18060 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18061 +#endif
18062 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18063 + _text = .;
18064 HEAD_TEXT
18065 #ifdef CONFIG_X86_32
18066 . = ALIGN(PAGE_SIZE);
18067 @@ -109,13 +129,47 @@ SECTIONS
18068 IRQENTRY_TEXT
18069 *(.fixup)
18070 *(.gnu.warning)
18071 - /* End of text section */
18072 - _etext = .;
18073 } :text = 0x9090
18074
18075 - NOTES :text :note
18076 + . += __KERNEL_TEXT_OFFSET;
18077 +
18078 +#ifdef CONFIG_X86_32
18079 + . = ALIGN(PAGE_SIZE);
18080 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18081 +
18082 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18083 + MODULES_EXEC_VADDR = .;
18084 + BYTE(0)
18085 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18086 + . = ALIGN(HPAGE_SIZE);
18087 + MODULES_EXEC_END = . - 1;
18088 +#endif
18089 +
18090 + } :module
18091 +#endif
18092 +
18093 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18094 + /* End of text section */
18095 + _etext = . - __KERNEL_TEXT_OFFSET;
18096 + }
18097
18098 - EXCEPTION_TABLE(16) :text = 0x9090
18099 +#ifdef CONFIG_X86_32
18100 + . = ALIGN(PAGE_SIZE);
18101 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18102 + *(.idt)
18103 + . = ALIGN(PAGE_SIZE);
18104 + *(.empty_zero_page)
18105 + *(.initial_pg_fixmap)
18106 + *(.initial_pg_pmd)
18107 + *(.initial_page_table)
18108 + *(.swapper_pg_dir)
18109 + } :rodata
18110 +#endif
18111 +
18112 + . = ALIGN(PAGE_SIZE);
18113 + NOTES :rodata :note
18114 +
18115 + EXCEPTION_TABLE(16) :rodata
18116
18117 #if defined(CONFIG_DEBUG_RODATA)
18118 /* .text should occupy whole number of pages */
18119 @@ -127,16 +181,20 @@ SECTIONS
18120
18121 /* Data */
18122 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18123 +
18124 +#ifdef CONFIG_PAX_KERNEXEC
18125 + . = ALIGN(HPAGE_SIZE);
18126 +#else
18127 + . = ALIGN(PAGE_SIZE);
18128 +#endif
18129 +
18130 /* Start of data section */
18131 _sdata = .;
18132
18133 /* init_task */
18134 INIT_TASK_DATA(THREAD_SIZE)
18135
18136 -#ifdef CONFIG_X86_32
18137 - /* 32 bit has nosave before _edata */
18138 NOSAVE_DATA
18139 -#endif
18140
18141 PAGE_ALIGNED_DATA(PAGE_SIZE)
18142
18143 @@ -145,6 +203,8 @@ SECTIONS
18144 DATA_DATA
18145 CONSTRUCTORS
18146
18147 + jiffies = jiffies_64;
18148 +
18149 /* rarely changed data like cpu maps */
18150 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
18151
18152 @@ -199,12 +259,6 @@ SECTIONS
18153 }
18154 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18155
18156 - . = ALIGN(L1_CACHE_BYTES);
18157 - .jiffies : AT(VLOAD(.jiffies)) {
18158 - *(.jiffies)
18159 - }
18160 - jiffies = VVIRT(.jiffies);
18161 -
18162 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18163 *(.vsyscall_3)
18164 }
18165 @@ -220,12 +274,19 @@ SECTIONS
18166 #endif /* CONFIG_X86_64 */
18167
18168 /* Init code and data - will be freed after init */
18169 - . = ALIGN(PAGE_SIZE);
18170 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18171 + BYTE(0)
18172 +
18173 +#ifdef CONFIG_PAX_KERNEXEC
18174 + . = ALIGN(HPAGE_SIZE);
18175 +#else
18176 + . = ALIGN(PAGE_SIZE);
18177 +#endif
18178 +
18179 __init_begin = .; /* paired with __init_end */
18180 - }
18181 + } :init.begin
18182
18183 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18184 +#ifdef CONFIG_SMP
18185 /*
18186 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18187 * output PHDR, so the next output section - .init.text - should
18188 @@ -234,12 +295,27 @@ SECTIONS
18189 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18190 #endif
18191
18192 - INIT_TEXT_SECTION(PAGE_SIZE)
18193 -#ifdef CONFIG_X86_64
18194 - :init
18195 -#endif
18196 + . = ALIGN(PAGE_SIZE);
18197 + init_begin = .;
18198 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18199 + VMLINUX_SYMBOL(_sinittext) = .;
18200 + INIT_TEXT
18201 + VMLINUX_SYMBOL(_einittext) = .;
18202 + . = ALIGN(PAGE_SIZE);
18203 + } :text.init
18204
18205 - INIT_DATA_SECTION(16)
18206 + /*
18207 + * .exit.text is discard at runtime, not link time, to deal with
18208 + * references from .altinstructions and .eh_frame
18209 + */
18210 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18211 + EXIT_TEXT
18212 + . = ALIGN(16);
18213 + } :text.exit
18214 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18215 +
18216 + . = ALIGN(PAGE_SIZE);
18217 + INIT_DATA_SECTION(16) :init
18218
18219 /*
18220 * Code and data for a variety of lowlevel trampolines, to be
18221 @@ -306,19 +382,12 @@ SECTIONS
18222 }
18223
18224 . = ALIGN(8);
18225 - /*
18226 - * .exit.text is discard at runtime, not link time, to deal with
18227 - * references from .altinstructions and .eh_frame
18228 - */
18229 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18230 - EXIT_TEXT
18231 - }
18232
18233 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18234 EXIT_DATA
18235 }
18236
18237 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18238 +#ifndef CONFIG_SMP
18239 PERCPU(INTERNODE_CACHE_BYTES, PAGE_SIZE)
18240 #endif
18241
18242 @@ -337,16 +406,10 @@ SECTIONS
18243 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18244 __smp_locks = .;
18245 *(.smp_locks)
18246 - . = ALIGN(PAGE_SIZE);
18247 __smp_locks_end = .;
18248 + . = ALIGN(PAGE_SIZE);
18249 }
18250
18251 -#ifdef CONFIG_X86_64
18252 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18253 - NOSAVE_DATA
18254 - }
18255 -#endif
18256 -
18257 /* BSS */
18258 . = ALIGN(PAGE_SIZE);
18259 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18260 @@ -362,6 +425,7 @@ SECTIONS
18261 __brk_base = .;
18262 . += 64 * 1024; /* 64k alignment slop space */
18263 *(.brk_reservation) /* areas brk users have reserved */
18264 + . = ALIGN(HPAGE_SIZE);
18265 __brk_limit = .;
18266 }
18267
18268 @@ -388,13 +452,12 @@ SECTIONS
18269 * for the boot processor.
18270 */
18271 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18272 -INIT_PER_CPU(gdt_page);
18273 INIT_PER_CPU(irq_stack_union);
18274
18275 /*
18276 * Build-time check on the image size:
18277 */
18278 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18279 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18280 "kernel image bigger than KERNEL_IMAGE_SIZE");
18281
18282 #ifdef CONFIG_SMP
18283 diff -urNp linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c
18284 --- linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c 2011-05-19 00:06:34.000000000 -0400
18285 +++ linux-2.6.39.1/arch/x86/kernel/vsyscall_64.c 2011-05-22 19:36:30.000000000 -0400
18286 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18287
18288 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18289 /* copy vsyscall data */
18290 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18291 vsyscall_gtod_data.clock.vread = clock->vread;
18292 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18293 vsyscall_gtod_data.clock.mask = clock->mask;
18294 @@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18295 We do this here because otherwise user space would do it on
18296 its own in a likely inferior way (no access to jiffies).
18297 If you don't like it pass NULL. */
18298 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
18299 + if (tcache && tcache->blob[0] == (j = jiffies)) {
18300 p = tcache->blob[1];
18301 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18302 /* Load per CPU data from RDTSCP */
18303 diff -urNp linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c
18304 --- linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c 2011-05-19 00:06:34.000000000 -0400
18305 +++ linux-2.6.39.1/arch/x86/kernel/x8664_ksyms_64.c 2011-05-22 19:36:30.000000000 -0400
18306 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18307 EXPORT_SYMBOL(copy_user_generic_string);
18308 EXPORT_SYMBOL(copy_user_generic_unrolled);
18309 EXPORT_SYMBOL(__copy_user_nocache);
18310 -EXPORT_SYMBOL(_copy_from_user);
18311 -EXPORT_SYMBOL(_copy_to_user);
18312
18313 EXPORT_SYMBOL(copy_page);
18314 EXPORT_SYMBOL(clear_page);
18315 diff -urNp linux-2.6.39.1/arch/x86/kernel/xsave.c linux-2.6.39.1/arch/x86/kernel/xsave.c
18316 --- linux-2.6.39.1/arch/x86/kernel/xsave.c 2011-05-19 00:06:34.000000000 -0400
18317 +++ linux-2.6.39.1/arch/x86/kernel/xsave.c 2011-05-22 19:36:30.000000000 -0400
18318 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
18319 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18320 return -EINVAL;
18321
18322 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18323 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18324 fx_sw_user->extended_size -
18325 FP_XSTATE_MAGIC2_SIZE));
18326 if (err)
18327 @@ -267,7 +267,7 @@ fx_only:
18328 * the other extended state.
18329 */
18330 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18331 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18332 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18333 }
18334
18335 /*
18336 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
18337 if (use_xsave())
18338 err = restore_user_xstate(buf);
18339 else
18340 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18341 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
18342 buf);
18343 if (unlikely(err)) {
18344 /*
18345 diff -urNp linux-2.6.39.1/arch/x86/kvm/emulate.c linux-2.6.39.1/arch/x86/kvm/emulate.c
18346 --- linux-2.6.39.1/arch/x86/kvm/emulate.c 2011-05-19 00:06:34.000000000 -0400
18347 +++ linux-2.6.39.1/arch/x86/kvm/emulate.c 2011-05-22 19:36:30.000000000 -0400
18348 @@ -89,7 +89,7 @@
18349 #define Src2ImmByte (2<<29)
18350 #define Src2One (3<<29)
18351 #define Src2Imm (4<<29)
18352 -#define Src2Mask (7<<29)
18353 +#define Src2Mask (7U<<29)
18354
18355 #define X2(x...) x, x
18356 #define X3(x...) X2(x), x
18357 @@ -190,6 +190,7 @@ struct group_dual {
18358
18359 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
18360 do { \
18361 + unsigned long _tmp; \
18362 __asm__ __volatile__ ( \
18363 _PRE_EFLAGS("0", "4", "2") \
18364 _op _suffix " %"_x"3,%1; " \
18365 @@ -203,8 +204,6 @@ struct group_dual {
18366 /* Raw emulation: instruction has two explicit operands. */
18367 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18368 do { \
18369 - unsigned long _tmp; \
18370 - \
18371 switch ((_dst).bytes) { \
18372 case 2: \
18373 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
18374 @@ -220,7 +219,6 @@ struct group_dual {
18375
18376 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18377 do { \
18378 - unsigned long _tmp; \
18379 switch ((_dst).bytes) { \
18380 case 1: \
18381 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
18382 diff -urNp linux-2.6.39.1/arch/x86/kvm/lapic.c linux-2.6.39.1/arch/x86/kvm/lapic.c
18383 --- linux-2.6.39.1/arch/x86/kvm/lapic.c 2011-05-19 00:06:34.000000000 -0400
18384 +++ linux-2.6.39.1/arch/x86/kvm/lapic.c 2011-05-22 19:36:30.000000000 -0400
18385 @@ -53,7 +53,7 @@
18386 #define APIC_BUS_CYCLE_NS 1
18387
18388 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18389 -#define apic_debug(fmt, arg...)
18390 +#define apic_debug(fmt, arg...) do {} while (0)
18391
18392 #define APIC_LVT_NUM 6
18393 /* 14 is the version for Xeon and Pentium 8.4.8*/
18394 diff -urNp linux-2.6.39.1/arch/x86/kvm/mmu.c linux-2.6.39.1/arch/x86/kvm/mmu.c
18395 --- linux-2.6.39.1/arch/x86/kvm/mmu.c 2011-05-19 00:06:34.000000000 -0400
18396 +++ linux-2.6.39.1/arch/x86/kvm/mmu.c 2011-05-22 19:36:30.000000000 -0400
18397 @@ -3240,7 +3240,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18398
18399 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18400
18401 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18402 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18403
18404 /*
18405 * Assume that the pte write on a page table of the same type
18406 @@ -3275,7 +3275,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18407 smp_rmb();
18408
18409 spin_lock(&vcpu->kvm->mmu_lock);
18410 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18411 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18412 gentry = 0;
18413 kvm_mmu_free_some_pages(vcpu);
18414 ++vcpu->kvm->stat.mmu_pte_write;
18415 diff -urNp linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h
18416 --- linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h 2011-05-19 00:06:34.000000000 -0400
18417 +++ linux-2.6.39.1/arch/x86/kvm/paging_tmpl.h 2011-05-22 19:36:30.000000000 -0400
18418 @@ -552,6 +552,8 @@ static int FNAME(page_fault)(struct kvm_
18419 unsigned long mmu_seq;
18420 bool map_writable;
18421
18422 + pax_track_stack();
18423 +
18424 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18425
18426 r = mmu_topup_memory_caches(vcpu);
18427 @@ -672,7 +674,7 @@ static void FNAME(invlpg)(struct kvm_vcp
18428 if (need_flush)
18429 kvm_flush_remote_tlbs(vcpu->kvm);
18430
18431 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18432 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18433
18434 spin_unlock(&vcpu->kvm->mmu_lock);
18435
18436 diff -urNp linux-2.6.39.1/arch/x86/kvm/svm.c linux-2.6.39.1/arch/x86/kvm/svm.c
18437 --- linux-2.6.39.1/arch/x86/kvm/svm.c 2011-05-19 00:06:34.000000000 -0400
18438 +++ linux-2.6.39.1/arch/x86/kvm/svm.c 2011-05-22 19:36:30.000000000 -0400
18439 @@ -3278,7 +3278,11 @@ static void reload_tss(struct kvm_vcpu *
18440 int cpu = raw_smp_processor_id();
18441
18442 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18443 +
18444 + pax_open_kernel();
18445 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18446 + pax_close_kernel();
18447 +
18448 load_TR_desc();
18449 }
18450
18451 @@ -3656,6 +3660,10 @@ static void svm_vcpu_run(struct kvm_vcpu
18452 #endif
18453 #endif
18454
18455 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18456 + __set_fs(current_thread_info()->addr_limit);
18457 +#endif
18458 +
18459 reload_tss(vcpu);
18460
18461 local_irq_disable();
18462 @@ -3871,7 +3879,7 @@ static void svm_fpu_deactivate(struct kv
18463 update_cr0_intercept(svm);
18464 }
18465
18466 -static struct kvm_x86_ops svm_x86_ops = {
18467 +static const struct kvm_x86_ops svm_x86_ops = {
18468 .cpu_has_kvm_support = has_svm,
18469 .disabled_by_bios = is_disabled,
18470 .hardware_setup = svm_hardware_setup,
18471 diff -urNp linux-2.6.39.1/arch/x86/kvm/vmx.c linux-2.6.39.1/arch/x86/kvm/vmx.c
18472 --- linux-2.6.39.1/arch/x86/kvm/vmx.c 2011-05-19 00:06:34.000000000 -0400
18473 +++ linux-2.6.39.1/arch/x86/kvm/vmx.c 2011-05-22 19:36:30.000000000 -0400
18474 @@ -725,7 +725,11 @@ static void reload_tss(void)
18475 struct desc_struct *descs;
18476
18477 descs = (void *)gdt->address;
18478 +
18479 + pax_open_kernel();
18480 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18481 + pax_close_kernel();
18482 +
18483 load_TR_desc();
18484 }
18485
18486 @@ -1648,8 +1652,11 @@ static __init int hardware_setup(void)
18487 if (!cpu_has_vmx_flexpriority())
18488 flexpriority_enabled = 0;
18489
18490 - if (!cpu_has_vmx_tpr_shadow())
18491 - kvm_x86_ops->update_cr8_intercept = NULL;
18492 + if (!cpu_has_vmx_tpr_shadow()) {
18493 + pax_open_kernel();
18494 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18495 + pax_close_kernel();
18496 + }
18497
18498 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18499 kvm_disable_largepages();
18500 @@ -2693,7 +2700,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18501 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18502
18503 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18504 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18505 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18506 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18507 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18508 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
18509 @@ -4068,6 +4075,12 @@ static void __noclone vmx_vcpu_run(struc
18510 "jmp .Lkvm_vmx_return \n\t"
18511 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18512 ".Lkvm_vmx_return: "
18513 +
18514 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18515 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18516 + ".Lkvm_vmx_return2: "
18517 +#endif
18518 +
18519 /* Save guest registers, load host registers, keep flags */
18520 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18521 "pop %0 \n\t"
18522 @@ -4116,6 +4129,11 @@ static void __noclone vmx_vcpu_run(struc
18523 #endif
18524 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18525 [wordsize]"i"(sizeof(ulong))
18526 +
18527 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18528 + ,[cs]"i"(__KERNEL_CS)
18529 +#endif
18530 +
18531 : "cc", "memory"
18532 , R"ax", R"bx", R"di", R"si"
18533 #ifdef CONFIG_X86_64
18534 @@ -4130,7 +4148,16 @@ static void __noclone vmx_vcpu_run(struc
18535
18536 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
18537
18538 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18539 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18540 +
18541 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18542 + loadsegment(fs, __KERNEL_PERCPU);
18543 +#endif
18544 +
18545 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18546 + __set_fs(current_thread_info()->addr_limit);
18547 +#endif
18548 +
18549 vmx->launched = 1;
18550
18551 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18552 @@ -4368,7 +4395,7 @@ static void vmx_set_supported_cpuid(u32
18553 {
18554 }
18555
18556 -static struct kvm_x86_ops vmx_x86_ops = {
18557 +static const struct kvm_x86_ops vmx_x86_ops = {
18558 .cpu_has_kvm_support = cpu_has_kvm_support,
18559 .disabled_by_bios = vmx_disabled_by_bios,
18560 .hardware_setup = hardware_setup,
18561 diff -urNp linux-2.6.39.1/arch/x86/kvm/x86.c linux-2.6.39.1/arch/x86/kvm/x86.c
18562 --- linux-2.6.39.1/arch/x86/kvm/x86.c 2011-05-19 00:06:34.000000000 -0400
18563 +++ linux-2.6.39.1/arch/x86/kvm/x86.c 2011-05-22 19:36:30.000000000 -0400
18564 @@ -94,7 +94,7 @@ static void update_cr8_intercept(struct
18565 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18566 struct kvm_cpuid_entry2 __user *entries);
18567
18568 -struct kvm_x86_ops *kvm_x86_ops;
18569 +const struct kvm_x86_ops *kvm_x86_ops;
18570 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18571
18572 int ignore_msrs = 0;
18573 @@ -2050,6 +2050,8 @@ long kvm_arch_dev_ioctl(struct file *fil
18574 if (n < msr_list.nmsrs)
18575 goto out;
18576 r = -EFAULT;
18577 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18578 + goto out;
18579 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18580 num_msrs_to_save * sizeof(u32)))
18581 goto out;
18582 @@ -2217,15 +2219,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18583 struct kvm_cpuid2 *cpuid,
18584 struct kvm_cpuid_entry2 __user *entries)
18585 {
18586 - int r;
18587 + int r, i;
18588
18589 r = -E2BIG;
18590 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18591 goto out;
18592 r = -EFAULT;
18593 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18594 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18595 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18596 goto out;
18597 + for (i = 0; i < cpuid->nent; ++i) {
18598 + struct kvm_cpuid_entry2 cpuid_entry;
18599 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18600 + goto out;
18601 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18602 + }
18603 vcpu->arch.cpuid_nent = cpuid->nent;
18604 kvm_apic_set_version(vcpu);
18605 kvm_x86_ops->cpuid_update(vcpu);
18606 @@ -2240,15 +2247,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18607 struct kvm_cpuid2 *cpuid,
18608 struct kvm_cpuid_entry2 __user *entries)
18609 {
18610 - int r;
18611 + int r, i;
18612
18613 r = -E2BIG;
18614 if (cpuid->nent < vcpu->arch.cpuid_nent)
18615 goto out;
18616 r = -EFAULT;
18617 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18618 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18619 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18620 goto out;
18621 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18622 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18623 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18624 + goto out;
18625 + }
18626 return 0;
18627
18628 out:
18629 @@ -2526,7 +2537,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18630 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18631 struct kvm_interrupt *irq)
18632 {
18633 - if (irq->irq < 0 || irq->irq >= 256)
18634 + if (irq->irq >= 256)
18635 return -EINVAL;
18636 if (irqchip_in_kernel(vcpu->kvm))
18637 return -ENXIO;
18638 @@ -4672,7 +4683,7 @@ static unsigned long kvm_get_guest_ip(vo
18639 return ip;
18640 }
18641
18642 -static struct perf_guest_info_callbacks kvm_guest_cbs = {
18643 +static const struct perf_guest_info_callbacks kvm_guest_cbs = {
18644 .is_in_guest = kvm_is_in_guest,
18645 .is_user_mode = kvm_is_user_mode,
18646 .get_guest_ip = kvm_get_guest_ip,
18647 @@ -4690,10 +4701,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
18648 }
18649 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
18650
18651 -int kvm_arch_init(void *opaque)
18652 +int kvm_arch_init(const void *opaque)
18653 {
18654 int r;
18655 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18656 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18657
18658 if (kvm_x86_ops) {
18659 printk(KERN_ERR "kvm: already loaded the other module\n");
18660 diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_32.c linux-2.6.39.1/arch/x86/lib/atomic64_32.c
18661 --- linux-2.6.39.1/arch/x86/lib/atomic64_32.c 2011-05-19 00:06:34.000000000 -0400
18662 +++ linux-2.6.39.1/arch/x86/lib/atomic64_32.c 2011-05-22 19:36:30.000000000 -0400
18663 @@ -8,18 +8,30 @@
18664
18665 long long atomic64_read_cx8(long long, const atomic64_t *v);
18666 EXPORT_SYMBOL(atomic64_read_cx8);
18667 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18668 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18669 long long atomic64_set_cx8(long long, const atomic64_t *v);
18670 EXPORT_SYMBOL(atomic64_set_cx8);
18671 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18672 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18673 long long atomic64_xchg_cx8(long long, unsigned high);
18674 EXPORT_SYMBOL(atomic64_xchg_cx8);
18675 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18676 EXPORT_SYMBOL(atomic64_add_return_cx8);
18677 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18678 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18679 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18680 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18681 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18682 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18683 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18684 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18685 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18686 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18687 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18688 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18689 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18690 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18691 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18692 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18693 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18694 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18695 #ifndef CONFIG_X86_CMPXCHG64
18696 long long atomic64_read_386(long long, const atomic64_t *v);
18697 EXPORT_SYMBOL(atomic64_read_386);
18698 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18699 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18700 long long atomic64_set_386(long long, const atomic64_t *v);
18701 EXPORT_SYMBOL(atomic64_set_386);
18702 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18703 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18704 long long atomic64_xchg_386(long long, unsigned high);
18705 EXPORT_SYMBOL(atomic64_xchg_386);
18706 long long atomic64_add_return_386(long long a, atomic64_t *v);
18707 EXPORT_SYMBOL(atomic64_add_return_386);
18708 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18709 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18710 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18711 EXPORT_SYMBOL(atomic64_sub_return_386);
18712 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18713 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18714 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18715 EXPORT_SYMBOL(atomic64_inc_return_386);
18716 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18717 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18718 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18719 EXPORT_SYMBOL(atomic64_dec_return_386);
18720 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18721 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18722 long long atomic64_add_386(long long a, atomic64_t *v);
18723 EXPORT_SYMBOL(atomic64_add_386);
18724 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18725 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18726 long long atomic64_sub_386(long long a, atomic64_t *v);
18727 EXPORT_SYMBOL(atomic64_sub_386);
18728 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18729 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18730 long long atomic64_inc_386(long long a, atomic64_t *v);
18731 EXPORT_SYMBOL(atomic64_inc_386);
18732 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18733 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18734 long long atomic64_dec_386(long long a, atomic64_t *v);
18735 EXPORT_SYMBOL(atomic64_dec_386);
18736 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18737 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18738 long long atomic64_dec_if_positive_386(atomic64_t *v);
18739 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18740 int atomic64_inc_not_zero_386(atomic64_t *v);
18741 diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S
18742 --- linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S 2011-05-19 00:06:34.000000000 -0400
18743 +++ linux-2.6.39.1/arch/x86/lib/atomic64_386_32.S 2011-05-22 19:36:30.000000000 -0400
18744 @@ -48,6 +48,10 @@ BEGIN(read)
18745 movl (v), %eax
18746 movl 4(v), %edx
18747 RET_ENDP
18748 +BEGIN(read_unchecked)
18749 + movl (v), %eax
18750 + movl 4(v), %edx
18751 +RET_ENDP
18752 #undef v
18753
18754 #define v %esi
18755 @@ -55,6 +59,10 @@ BEGIN(set)
18756 movl %ebx, (v)
18757 movl %ecx, 4(v)
18758 RET_ENDP
18759 +BEGIN(set_unchecked)
18760 + movl %ebx, (v)
18761 + movl %ecx, 4(v)
18762 +RET_ENDP
18763 #undef v
18764
18765 #define v %esi
18766 @@ -70,6 +78,20 @@ RET_ENDP
18767 BEGIN(add)
18768 addl %eax, (v)
18769 adcl %edx, 4(v)
18770 +
18771 +#ifdef CONFIG_PAX_REFCOUNT
18772 + jno 0f
18773 + subl %eax, (v)
18774 + sbbl %edx, 4(v)
18775 + int $4
18776 +0:
18777 + _ASM_EXTABLE(0b, 0b)
18778 +#endif
18779 +
18780 +RET_ENDP
18781 +BEGIN(add_unchecked)
18782 + addl %eax, (v)
18783 + adcl %edx, 4(v)
18784 RET_ENDP
18785 #undef v
18786
18787 @@ -77,6 +99,24 @@ RET_ENDP
18788 BEGIN(add_return)
18789 addl (v), %eax
18790 adcl 4(v), %edx
18791 +
18792 +#ifdef CONFIG_PAX_REFCOUNT
18793 + into
18794 +1234:
18795 + _ASM_EXTABLE(1234b, 2f)
18796 +#endif
18797 +
18798 + movl %eax, (v)
18799 + movl %edx, 4(v)
18800 +
18801 +#ifdef CONFIG_PAX_REFCOUNT
18802 +2:
18803 +#endif
18804 +
18805 +RET_ENDP
18806 +BEGIN(add_return_unchecked)
18807 + addl (v), %eax
18808 + adcl 4(v), %edx
18809 movl %eax, (v)
18810 movl %edx, 4(v)
18811 RET_ENDP
18812 @@ -86,6 +126,20 @@ RET_ENDP
18813 BEGIN(sub)
18814 subl %eax, (v)
18815 sbbl %edx, 4(v)
18816 +
18817 +#ifdef CONFIG_PAX_REFCOUNT
18818 + jno 0f
18819 + addl %eax, (v)
18820 + adcl %edx, 4(v)
18821 + int $4
18822 +0:
18823 + _ASM_EXTABLE(0b, 0b)
18824 +#endif
18825 +
18826 +RET_ENDP
18827 +BEGIN(sub_unchecked)
18828 + subl %eax, (v)
18829 + sbbl %edx, 4(v)
18830 RET_ENDP
18831 #undef v
18832
18833 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18834 sbbl $0, %edx
18835 addl (v), %eax
18836 adcl 4(v), %edx
18837 +
18838 +#ifdef CONFIG_PAX_REFCOUNT
18839 + into
18840 +1234:
18841 + _ASM_EXTABLE(1234b, 2f)
18842 +#endif
18843 +
18844 + movl %eax, (v)
18845 + movl %edx, 4(v)
18846 +
18847 +#ifdef CONFIG_PAX_REFCOUNT
18848 +2:
18849 +#endif
18850 +
18851 +RET_ENDP
18852 +BEGIN(sub_return_unchecked)
18853 + negl %edx
18854 + negl %eax
18855 + sbbl $0, %edx
18856 + addl (v), %eax
18857 + adcl 4(v), %edx
18858 movl %eax, (v)
18859 movl %edx, 4(v)
18860 RET_ENDP
18861 @@ -105,6 +180,20 @@ RET_ENDP
18862 BEGIN(inc)
18863 addl $1, (v)
18864 adcl $0, 4(v)
18865 +
18866 +#ifdef CONFIG_PAX_REFCOUNT
18867 + jno 0f
18868 + subl $1, (v)
18869 + sbbl $0, 4(v)
18870 + int $4
18871 +0:
18872 + _ASM_EXTABLE(0b, 0b)
18873 +#endif
18874 +
18875 +RET_ENDP
18876 +BEGIN(inc_unchecked)
18877 + addl $1, (v)
18878 + adcl $0, 4(v)
18879 RET_ENDP
18880 #undef v
18881
18882 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18883 movl 4(v), %edx
18884 addl $1, %eax
18885 adcl $0, %edx
18886 +
18887 +#ifdef CONFIG_PAX_REFCOUNT
18888 + into
18889 +1234:
18890 + _ASM_EXTABLE(1234b, 2f)
18891 +#endif
18892 +
18893 + movl %eax, (v)
18894 + movl %edx, 4(v)
18895 +
18896 +#ifdef CONFIG_PAX_REFCOUNT
18897 +2:
18898 +#endif
18899 +
18900 +RET_ENDP
18901 +BEGIN(inc_return_unchecked)
18902 + movl (v), %eax
18903 + movl 4(v), %edx
18904 + addl $1, %eax
18905 + adcl $0, %edx
18906 movl %eax, (v)
18907 movl %edx, 4(v)
18908 RET_ENDP
18909 @@ -123,6 +232,20 @@ RET_ENDP
18910 BEGIN(dec)
18911 subl $1, (v)
18912 sbbl $0, 4(v)
18913 +
18914 +#ifdef CONFIG_PAX_REFCOUNT
18915 + jno 0f
18916 + addl $1, (v)
18917 + adcl $0, 4(v)
18918 + int $4
18919 +0:
18920 + _ASM_EXTABLE(0b, 0b)
18921 +#endif
18922 +
18923 +RET_ENDP
18924 +BEGIN(dec_unchecked)
18925 + subl $1, (v)
18926 + sbbl $0, 4(v)
18927 RET_ENDP
18928 #undef v
18929
18930 @@ -132,6 +255,26 @@ BEGIN(dec_return)
18931 movl 4(v), %edx
18932 subl $1, %eax
18933 sbbl $0, %edx
18934 +
18935 +#ifdef CONFIG_PAX_REFCOUNT
18936 + into
18937 +1234:
18938 + _ASM_EXTABLE(1234b, 2f)
18939 +#endif
18940 +
18941 + movl %eax, (v)
18942 + movl %edx, 4(v)
18943 +
18944 +#ifdef CONFIG_PAX_REFCOUNT
18945 +2:
18946 +#endif
18947 +
18948 +RET_ENDP
18949 +BEGIN(dec_return_unchecked)
18950 + movl (v), %eax
18951 + movl 4(v), %edx
18952 + subl $1, %eax
18953 + sbbl $0, %edx
18954 movl %eax, (v)
18955 movl %edx, 4(v)
18956 RET_ENDP
18957 @@ -143,6 +286,13 @@ BEGIN(add_unless)
18958 adcl %edx, %edi
18959 addl (v), %eax
18960 adcl 4(v), %edx
18961 +
18962 +#ifdef CONFIG_PAX_REFCOUNT
18963 + into
18964 +1234:
18965 + _ASM_EXTABLE(1234b, 2f)
18966 +#endif
18967 +
18968 cmpl %eax, %esi
18969 je 3f
18970 1:
18971 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18972 1:
18973 addl $1, %eax
18974 adcl $0, %edx
18975 +
18976 +#ifdef CONFIG_PAX_REFCOUNT
18977 + into
18978 +1234:
18979 + _ASM_EXTABLE(1234b, 2f)
18980 +#endif
18981 +
18982 movl %eax, (v)
18983 movl %edx, 4(v)
18984 movl $1, %eax
18985 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18986 movl 4(v), %edx
18987 subl $1, %eax
18988 sbbl $0, %edx
18989 +
18990 +#ifdef CONFIG_PAX_REFCOUNT
18991 + into
18992 +1234:
18993 + _ASM_EXTABLE(1234b, 1f)
18994 +#endif
18995 +
18996 js 1f
18997 movl %eax, (v)
18998 movl %edx, 4(v)
18999 diff -urNp linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S
19000 --- linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S 2011-05-19 00:06:34.000000000 -0400
19001 +++ linux-2.6.39.1/arch/x86/lib/atomic64_cx8_32.S 2011-05-22 19:36:30.000000000 -0400
19002 @@ -39,6 +39,14 @@ ENTRY(atomic64_read_cx8)
19003 CFI_ENDPROC
19004 ENDPROC(atomic64_read_cx8)
19005
19006 +ENTRY(atomic64_read_unchecked_cx8)
19007 + CFI_STARTPROC
19008 +
19009 + read64 %ecx
19010 + ret
19011 + CFI_ENDPROC
19012 +ENDPROC(atomic64_read_unchecked_cx8)
19013 +
19014 ENTRY(atomic64_set_cx8)
19015 CFI_STARTPROC
19016
19017 @@ -52,6 +60,19 @@ ENTRY(atomic64_set_cx8)
19018 CFI_ENDPROC
19019 ENDPROC(atomic64_set_cx8)
19020
19021 +ENTRY(atomic64_set_unchecked_cx8)
19022 + CFI_STARTPROC
19023 +
19024 +1:
19025 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
19026 + * are atomic on 586 and newer */
19027 + cmpxchg8b (%esi)
19028 + jne 1b
19029 +
19030 + ret
19031 + CFI_ENDPROC
19032 +ENDPROC(atomic64_set_unchecked_cx8)
19033 +
19034 ENTRY(atomic64_xchg_cx8)
19035 CFI_STARTPROC
19036
19037 @@ -66,8 +87,8 @@ ENTRY(atomic64_xchg_cx8)
19038 CFI_ENDPROC
19039 ENDPROC(atomic64_xchg_cx8)
19040
19041 -.macro addsub_return func ins insc
19042 -ENTRY(atomic64_\func\()_return_cx8)
19043 +.macro addsub_return func ins insc unchecked=""
19044 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19045 CFI_STARTPROC
19046 SAVE ebp
19047 SAVE ebx
19048 @@ -84,27 +105,43 @@ ENTRY(atomic64_\func\()_return_cx8)
19049 movl %edx, %ecx
19050 \ins\()l %esi, %ebx
19051 \insc\()l %edi, %ecx
19052 +
19053 +.ifb \unchecked
19054 +#ifdef CONFIG_PAX_REFCOUNT
19055 + into
19056 +2:
19057 + _ASM_EXTABLE(2b, 3f)
19058 +#endif
19059 +.endif
19060 +
19061 LOCK_PREFIX
19062 cmpxchg8b (%ebp)
19063 jne 1b
19064 -
19065 -10:
19066 movl %ebx, %eax
19067 movl %ecx, %edx
19068 +
19069 +.ifb \unchecked
19070 +#ifdef CONFIG_PAX_REFCOUNT
19071 +3:
19072 +#endif
19073 +.endif
19074 +
19075 RESTORE edi
19076 RESTORE esi
19077 RESTORE ebx
19078 RESTORE ebp
19079 ret
19080 CFI_ENDPROC
19081 -ENDPROC(atomic64_\func\()_return_cx8)
19082 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19083 .endm
19084
19085 addsub_return add add adc
19086 addsub_return sub sub sbb
19087 +addsub_return add add adc _unchecked
19088 +addsub_return sub sub sbb _unchecked
19089
19090 -.macro incdec_return func ins insc
19091 -ENTRY(atomic64_\func\()_return_cx8)
19092 +.macro incdec_return func ins insc unchecked
19093 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19094 CFI_STARTPROC
19095 SAVE ebx
19096
19097 @@ -114,21 +151,38 @@ ENTRY(atomic64_\func\()_return_cx8)
19098 movl %edx, %ecx
19099 \ins\()l $1, %ebx
19100 \insc\()l $0, %ecx
19101 +
19102 +.ifb \unchecked
19103 +#ifdef CONFIG_PAX_REFCOUNT
19104 + into
19105 +2:
19106 + _ASM_EXTABLE(2b, 3f)
19107 +#endif
19108 +.endif
19109 +
19110 LOCK_PREFIX
19111 cmpxchg8b (%esi)
19112 jne 1b
19113
19114 -10:
19115 movl %ebx, %eax
19116 movl %ecx, %edx
19117 +
19118 +.ifb \unchecked
19119 +#ifdef CONFIG_PAX_REFCOUNT
19120 +3:
19121 +#endif
19122 +.endif
19123 +
19124 RESTORE ebx
19125 ret
19126 CFI_ENDPROC
19127 -ENDPROC(atomic64_\func\()_return_cx8)
19128 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19129 .endm
19130
19131 incdec_return inc add adc
19132 incdec_return dec sub sbb
19133 +incdec_return inc add adc _unchecked
19134 +incdec_return dec sub sbb _unchecked
19135
19136 ENTRY(atomic64_dec_if_positive_cx8)
19137 CFI_STARTPROC
19138 @@ -140,6 +194,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19139 movl %edx, %ecx
19140 subl $1, %ebx
19141 sbb $0, %ecx
19142 +
19143 +#ifdef CONFIG_PAX_REFCOUNT
19144 + into
19145 +1234:
19146 + _ASM_EXTABLE(1234b, 2f)
19147 +#endif
19148 +
19149 js 2f
19150 LOCK_PREFIX
19151 cmpxchg8b (%esi)
19152 @@ -174,6 +235,13 @@ ENTRY(atomic64_add_unless_cx8)
19153 movl %edx, %ecx
19154 addl %esi, %ebx
19155 adcl %edi, %ecx
19156 +
19157 +#ifdef CONFIG_PAX_REFCOUNT
19158 + into
19159 +1234:
19160 + _ASM_EXTABLE(1234b, 3f)
19161 +#endif
19162 +
19163 LOCK_PREFIX
19164 cmpxchg8b (%ebp)
19165 jne 1b
19166 @@ -206,6 +274,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19167 movl %edx, %ecx
19168 addl $1, %ebx
19169 adcl $0, %ecx
19170 +
19171 +#ifdef CONFIG_PAX_REFCOUNT
19172 + into
19173 +1234:
19174 + _ASM_EXTABLE(1234b, 3f)
19175 +#endif
19176 +
19177 LOCK_PREFIX
19178 cmpxchg8b (%esi)
19179 jne 1b
19180 diff -urNp linux-2.6.39.1/arch/x86/lib/checksum_32.S linux-2.6.39.1/arch/x86/lib/checksum_32.S
19181 --- linux-2.6.39.1/arch/x86/lib/checksum_32.S 2011-05-19 00:06:34.000000000 -0400
19182 +++ linux-2.6.39.1/arch/x86/lib/checksum_32.S 2011-05-22 19:36:30.000000000 -0400
19183 @@ -28,7 +28,8 @@
19184 #include <linux/linkage.h>
19185 #include <asm/dwarf2.h>
19186 #include <asm/errno.h>
19187 -
19188 +#include <asm/segment.h>
19189 +
19190 /*
19191 * computes a partial checksum, e.g. for TCP/UDP fragments
19192 */
19193 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (
19194
19195 #define ARGBASE 16
19196 #define FP 12
19197 -
19198 -ENTRY(csum_partial_copy_generic)
19199 +
19200 +ENTRY(csum_partial_copy_generic_to_user)
19201 CFI_STARTPROC
19202 +
19203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19204 + pushl_cfi %gs
19205 + popl_cfi %es
19206 + jmp csum_partial_copy_generic
19207 +#endif
19208 +
19209 +ENTRY(csum_partial_copy_generic_from_user)
19210 +
19211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19212 + pushl_cfi %gs
19213 + popl_cfi %ds
19214 +#endif
19215 +
19216 +ENTRY(csum_partial_copy_generic)
19217 subl $4,%esp
19218 CFI_ADJUST_CFA_OFFSET 4
19219 pushl_cfi %edi
19220 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19221 jmp 4f
19222 SRC(1: movw (%esi), %bx )
19223 addl $2, %esi
19224 -DST( movw %bx, (%edi) )
19225 +DST( movw %bx, %es:(%edi) )
19226 addl $2, %edi
19227 addw %bx, %ax
19228 adcl $0, %eax
19229 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19230 SRC(1: movl (%esi), %ebx )
19231 SRC( movl 4(%esi), %edx )
19232 adcl %ebx, %eax
19233 -DST( movl %ebx, (%edi) )
19234 +DST( movl %ebx, %es:(%edi) )
19235 adcl %edx, %eax
19236 -DST( movl %edx, 4(%edi) )
19237 +DST( movl %edx, %es:4(%edi) )
19238
19239 SRC( movl 8(%esi), %ebx )
19240 SRC( movl 12(%esi), %edx )
19241 adcl %ebx, %eax
19242 -DST( movl %ebx, 8(%edi) )
19243 +DST( movl %ebx, %es:8(%edi) )
19244 adcl %edx, %eax
19245 -DST( movl %edx, 12(%edi) )
19246 +DST( movl %edx, %es:12(%edi) )
19247
19248 SRC( movl 16(%esi), %ebx )
19249 SRC( movl 20(%esi), %edx )
19250 adcl %ebx, %eax
19251 -DST( movl %ebx, 16(%edi) )
19252 +DST( movl %ebx, %es:16(%edi) )
19253 adcl %edx, %eax
19254 -DST( movl %edx, 20(%edi) )
19255 +DST( movl %edx, %es:20(%edi) )
19256
19257 SRC( movl 24(%esi), %ebx )
19258 SRC( movl 28(%esi), %edx )
19259 adcl %ebx, %eax
19260 -DST( movl %ebx, 24(%edi) )
19261 +DST( movl %ebx, %es:24(%edi) )
19262 adcl %edx, %eax
19263 -DST( movl %edx, 28(%edi) )
19264 +DST( movl %edx, %es:28(%edi) )
19265
19266 lea 32(%esi), %esi
19267 lea 32(%edi), %edi
19268 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19269 shrl $2, %edx # This clears CF
19270 SRC(3: movl (%esi), %ebx )
19271 adcl %ebx, %eax
19272 -DST( movl %ebx, (%edi) )
19273 +DST( movl %ebx, %es:(%edi) )
19274 lea 4(%esi), %esi
19275 lea 4(%edi), %edi
19276 dec %edx
19277 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19278 jb 5f
19279 SRC( movw (%esi), %cx )
19280 leal 2(%esi), %esi
19281 -DST( movw %cx, (%edi) )
19282 +DST( movw %cx, %es:(%edi) )
19283 leal 2(%edi), %edi
19284 je 6f
19285 shll $16,%ecx
19286 SRC(5: movb (%esi), %cl )
19287 -DST( movb %cl, (%edi) )
19288 +DST( movb %cl, %es:(%edi) )
19289 6: addl %ecx, %eax
19290 adcl $0, %eax
19291 7:
19292 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19293
19294 6001:
19295 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19296 - movl $-EFAULT, (%ebx)
19297 + movl $-EFAULT, %ss:(%ebx)
19298
19299 # zero the complete destination - computing the rest
19300 # is too much work
19301 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19302
19303 6002:
19304 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19305 - movl $-EFAULT,(%ebx)
19306 + movl $-EFAULT,%ss:(%ebx)
19307 jmp 5000b
19308
19309 .previous
19310
19311 + pushl_cfi %ss
19312 + popl_cfi %ds
19313 + pushl_cfi %ss
19314 + popl_cfi %es
19315 popl_cfi %ebx
19316 CFI_RESTORE ebx
19317 popl_cfi %esi
19318 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19319 popl_cfi %ecx # equivalent to addl $4,%esp
19320 ret
19321 CFI_ENDPROC
19322 -ENDPROC(csum_partial_copy_generic)
19323 +ENDPROC(csum_partial_copy_generic_to_user)
19324
19325 #else
19326
19327 /* Version for PentiumII/PPro */
19328
19329 #define ROUND1(x) \
19330 + nop; nop; nop; \
19331 SRC(movl x(%esi), %ebx ) ; \
19332 addl %ebx, %eax ; \
19333 - DST(movl %ebx, x(%edi) ) ;
19334 + DST(movl %ebx, %es:x(%edi)) ;
19335
19336 #define ROUND(x) \
19337 + nop; nop; nop; \
19338 SRC(movl x(%esi), %ebx ) ; \
19339 adcl %ebx, %eax ; \
19340 - DST(movl %ebx, x(%edi) ) ;
19341 + DST(movl %ebx, %es:x(%edi)) ;
19342
19343 #define ARGBASE 12
19344 -
19345 -ENTRY(csum_partial_copy_generic)
19346 +
19347 +ENTRY(csum_partial_copy_generic_to_user)
19348 CFI_STARTPROC
19349 +
19350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19351 + pushl_cfi %gs
19352 + popl_cfi %es
19353 + jmp csum_partial_copy_generic
19354 +#endif
19355 +
19356 +ENTRY(csum_partial_copy_generic_from_user)
19357 +
19358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19359 + pushl_cfi %gs
19360 + popl_cfi %ds
19361 +#endif
19362 +
19363 +ENTRY(csum_partial_copy_generic)
19364 pushl_cfi %ebx
19365 CFI_REL_OFFSET ebx, 0
19366 pushl_cfi %edi
19367 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19368 subl %ebx, %edi
19369 lea -1(%esi),%edx
19370 andl $-32,%edx
19371 - lea 3f(%ebx,%ebx), %ebx
19372 + lea 3f(%ebx,%ebx,2), %ebx
19373 testl %esi, %esi
19374 jmp *%ebx
19375 1: addl $64,%esi
19376 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19377 jb 5f
19378 SRC( movw (%esi), %dx )
19379 leal 2(%esi), %esi
19380 -DST( movw %dx, (%edi) )
19381 +DST( movw %dx, %es:(%edi) )
19382 leal 2(%edi), %edi
19383 je 6f
19384 shll $16,%edx
19385 5:
19386 SRC( movb (%esi), %dl )
19387 -DST( movb %dl, (%edi) )
19388 +DST( movb %dl, %es:(%edi) )
19389 6: addl %edx, %eax
19390 adcl $0, %eax
19391 7:
19392 .section .fixup, "ax"
19393 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19394 - movl $-EFAULT, (%ebx)
19395 + movl $-EFAULT, %ss:(%ebx)
19396 # zero the complete destination (computing the rest is too much work)
19397 movl ARGBASE+8(%esp),%edi # dst
19398 movl ARGBASE+12(%esp),%ecx # len
19399 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19400 rep; stosb
19401 jmp 7b
19402 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19403 - movl $-EFAULT, (%ebx)
19404 + movl $-EFAULT, %ss:(%ebx)
19405 jmp 7b
19406 .previous
19407
19408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19409 + pushl_cfi %ss
19410 + popl_cfi %ds
19411 + pushl_cfi %ss
19412 + popl_cfi %es
19413 +#endif
19414 +
19415 popl_cfi %esi
19416 CFI_RESTORE esi
19417 popl_cfi %edi
19418 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19419 CFI_RESTORE ebx
19420 ret
19421 CFI_ENDPROC
19422 -ENDPROC(csum_partial_copy_generic)
19423 +ENDPROC(csum_partial_copy_generic_to_user)
19424
19425 #undef ROUND
19426 #undef ROUND1
19427 diff -urNp linux-2.6.39.1/arch/x86/lib/clear_page_64.S linux-2.6.39.1/arch/x86/lib/clear_page_64.S
19428 --- linux-2.6.39.1/arch/x86/lib/clear_page_64.S 2011-05-19 00:06:34.000000000 -0400
19429 +++ linux-2.6.39.1/arch/x86/lib/clear_page_64.S 2011-05-22 19:36:30.000000000 -0400
19430 @@ -43,7 +43,7 @@ ENDPROC(clear_page)
19431
19432 #include <asm/cpufeature.h>
19433
19434 - .section .altinstr_replacement,"ax"
19435 + .section .altinstr_replacement,"a"
19436 1: .byte 0xeb /* jmp <disp8> */
19437 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19438 2:
19439 diff -urNp linux-2.6.39.1/arch/x86/lib/copy_page_64.S linux-2.6.39.1/arch/x86/lib/copy_page_64.S
19440 --- linux-2.6.39.1/arch/x86/lib/copy_page_64.S 2011-05-19 00:06:34.000000000 -0400
19441 +++ linux-2.6.39.1/arch/x86/lib/copy_page_64.S 2011-05-22 19:36:30.000000000 -0400
19442 @@ -104,7 +104,7 @@ ENDPROC(copy_page)
19443
19444 #include <asm/cpufeature.h>
19445
19446 - .section .altinstr_replacement,"ax"
19447 + .section .altinstr_replacement,"a"
19448 1: .byte 0xeb /* jmp <disp8> */
19449 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19450 2:
19451 diff -urNp linux-2.6.39.1/arch/x86/lib/copy_user_64.S linux-2.6.39.1/arch/x86/lib/copy_user_64.S
19452 --- linux-2.6.39.1/arch/x86/lib/copy_user_64.S 2011-06-03 00:04:13.000000000 -0400
19453 +++ linux-2.6.39.1/arch/x86/lib/copy_user_64.S 2011-06-03 00:32:05.000000000 -0400
19454 @@ -15,13 +15,14 @@
19455 #include <asm/asm-offsets.h>
19456 #include <asm/thread_info.h>
19457 #include <asm/cpufeature.h>
19458 +#include <asm/pgtable.h>
19459
19460 .macro ALTERNATIVE_JUMP feature,orig,alt
19461 0:
19462 .byte 0xe9 /* 32bit jump */
19463 .long \orig-1f /* by default jump to orig */
19464 1:
19465 - .section .altinstr_replacement,"ax"
19466 + .section .altinstr_replacement,"a"
19467 2: .byte 0xe9 /* near jump with 32bit immediate */
19468 .long \alt-1b /* offset */ /* or alternatively to alt */
19469 .previous
19470 @@ -64,37 +65,13 @@
19471 #endif
19472 .endm
19473
19474 -/* Standard copy_to_user with segment limit checking */
19475 -ENTRY(_copy_to_user)
19476 - CFI_STARTPROC
19477 - GET_THREAD_INFO(%rax)
19478 - movq %rdi,%rcx
19479 - addq %rdx,%rcx
19480 - jc bad_to_user
19481 - cmpq TI_addr_limit(%rax),%rcx
19482 - ja bad_to_user
19483 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19484 - CFI_ENDPROC
19485 -ENDPROC(_copy_to_user)
19486 -
19487 -/* Standard copy_from_user with segment limit checking */
19488 -ENTRY(_copy_from_user)
19489 - CFI_STARTPROC
19490 - GET_THREAD_INFO(%rax)
19491 - movq %rsi,%rcx
19492 - addq %rdx,%rcx
19493 - jc bad_from_user
19494 - cmpq TI_addr_limit(%rax),%rcx
19495 - ja bad_from_user
19496 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19497 - CFI_ENDPROC
19498 -ENDPROC(_copy_from_user)
19499 -
19500 .section .fixup,"ax"
19501 /* must zero dest */
19502 ENTRY(bad_from_user)
19503 bad_from_user:
19504 CFI_STARTPROC
19505 + testl %edx,%edx
19506 + js bad_to_user
19507 movl %edx,%ecx
19508 xorl %eax,%eax
19509 rep
19510 diff -urNp linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S
19511 --- linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S 2011-05-19 00:06:34.000000000 -0400
19512 +++ linux-2.6.39.1/arch/x86/lib/copy_user_nocache_64.S 2011-05-22 19:36:30.000000000 -0400
19513 @@ -14,6 +14,7 @@
19514 #include <asm/current.h>
19515 #include <asm/asm-offsets.h>
19516 #include <asm/thread_info.h>
19517 +#include <asm/pgtable.h>
19518
19519 .macro ALIGN_DESTINATION
19520 #ifdef FIX_ALIGNMENT
19521 @@ -50,6 +51,15 @@
19522 */
19523 ENTRY(__copy_user_nocache)
19524 CFI_STARTPROC
19525 +
19526 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19527 + mov $PAX_USER_SHADOW_BASE,%rcx
19528 + cmp %rcx,%rsi
19529 + jae 1f
19530 + add %rcx,%rsi
19531 +1:
19532 +#endif
19533 +
19534 cmpl $8,%edx
19535 jb 20f /* less then 8 bytes, go to byte copy loop */
19536 ALIGN_DESTINATION
19537 diff -urNp linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c
19538 --- linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c 2011-05-19 00:06:34.000000000 -0400
19539 +++ linux-2.6.39.1/arch/x86/lib/csum-wrappers_64.c 2011-05-22 19:36:30.000000000 -0400
19540 @@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19541 len -= 2;
19542 }
19543 }
19544 +
19545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19546 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19547 + src += PAX_USER_SHADOW_BASE;
19548 +#endif
19549 +
19550 isum = csum_partial_copy_generic((__force const void *)src,
19551 dst, len, isum, errp, NULL);
19552 if (unlikely(*errp))
19553 @@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19554 }
19555
19556 *errp = 0;
19557 +
19558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19559 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19560 + dst += PAX_USER_SHADOW_BASE;
19561 +#endif
19562 +
19563 return csum_partial_copy_generic(src, (void __force *)dst,
19564 len, isum, NULL, errp);
19565 }
19566 diff -urNp linux-2.6.39.1/arch/x86/lib/getuser.S linux-2.6.39.1/arch/x86/lib/getuser.S
19567 --- linux-2.6.39.1/arch/x86/lib/getuser.S 2011-05-19 00:06:34.000000000 -0400
19568 +++ linux-2.6.39.1/arch/x86/lib/getuser.S 2011-05-22 19:36:30.000000000 -0400
19569 @@ -33,14 +33,35 @@
19570 #include <asm/asm-offsets.h>
19571 #include <asm/thread_info.h>
19572 #include <asm/asm.h>
19573 +#include <asm/segment.h>
19574 +#include <asm/pgtable.h>
19575 +
19576 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19577 +#define __copyuser_seg gs;
19578 +#else
19579 +#define __copyuser_seg
19580 +#endif
19581
19582 .text
19583 ENTRY(__get_user_1)
19584 CFI_STARTPROC
19585 +
19586 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19587 GET_THREAD_INFO(%_ASM_DX)
19588 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19589 jae bad_get_user
19590 -1: movzb (%_ASM_AX),%edx
19591 +
19592 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19593 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19594 + cmp %_ASM_DX,%_ASM_AX
19595 + jae 1234f
19596 + add %_ASM_DX,%_ASM_AX
19597 +1234:
19598 +#endif
19599 +
19600 +#endif
19601 +
19602 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19603 xor %eax,%eax
19604 ret
19605 CFI_ENDPROC
19606 @@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19607 ENTRY(__get_user_2)
19608 CFI_STARTPROC
19609 add $1,%_ASM_AX
19610 +
19611 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19612 jc bad_get_user
19613 GET_THREAD_INFO(%_ASM_DX)
19614 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19615 jae bad_get_user
19616 -2: movzwl -1(%_ASM_AX),%edx
19617 +
19618 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19619 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19620 + cmp %_ASM_DX,%_ASM_AX
19621 + jae 1234f
19622 + add %_ASM_DX,%_ASM_AX
19623 +1234:
19624 +#endif
19625 +
19626 +#endif
19627 +
19628 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19629 xor %eax,%eax
19630 ret
19631 CFI_ENDPROC
19632 @@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19633 ENTRY(__get_user_4)
19634 CFI_STARTPROC
19635 add $3,%_ASM_AX
19636 +
19637 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19638 jc bad_get_user
19639 GET_THREAD_INFO(%_ASM_DX)
19640 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19641 jae bad_get_user
19642 -3: mov -3(%_ASM_AX),%edx
19643 +
19644 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19645 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19646 + cmp %_ASM_DX,%_ASM_AX
19647 + jae 1234f
19648 + add %_ASM_DX,%_ASM_AX
19649 +1234:
19650 +#endif
19651 +
19652 +#endif
19653 +
19654 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19655 xor %eax,%eax
19656 ret
19657 CFI_ENDPROC
19658 @@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19659 GET_THREAD_INFO(%_ASM_DX)
19660 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19661 jae bad_get_user
19662 +
19663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19664 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19665 + cmp %_ASM_DX,%_ASM_AX
19666 + jae 1234f
19667 + add %_ASM_DX,%_ASM_AX
19668 +1234:
19669 +#endif
19670 +
19671 4: movq -7(%_ASM_AX),%_ASM_DX
19672 xor %eax,%eax
19673 ret
19674 diff -urNp linux-2.6.39.1/arch/x86/lib/insn.c linux-2.6.39.1/arch/x86/lib/insn.c
19675 --- linux-2.6.39.1/arch/x86/lib/insn.c 2011-05-19 00:06:34.000000000 -0400
19676 +++ linux-2.6.39.1/arch/x86/lib/insn.c 2011-05-22 19:36:30.000000000 -0400
19677 @@ -21,6 +21,11 @@
19678 #include <linux/string.h>
19679 #include <asm/inat.h>
19680 #include <asm/insn.h>
19681 +#ifdef __KERNEL__
19682 +#include <asm/pgtable_types.h>
19683 +#else
19684 +#define ktla_ktva(addr) addr
19685 +#endif
19686
19687 #define get_next(t, insn) \
19688 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
19689 @@ -40,8 +45,8 @@
19690 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19691 {
19692 memset(insn, 0, sizeof(*insn));
19693 - insn->kaddr = kaddr;
19694 - insn->next_byte = kaddr;
19695 + insn->kaddr = ktla_ktva(kaddr);
19696 + insn->next_byte = ktla_ktva(kaddr);
19697 insn->x86_64 = x86_64 ? 1 : 0;
19698 insn->opnd_bytes = 4;
19699 if (x86_64)
19700 diff -urNp linux-2.6.39.1/arch/x86/lib/mmx_32.c linux-2.6.39.1/arch/x86/lib/mmx_32.c
19701 --- linux-2.6.39.1/arch/x86/lib/mmx_32.c 2011-05-19 00:06:34.000000000 -0400
19702 +++ linux-2.6.39.1/arch/x86/lib/mmx_32.c 2011-05-22 19:36:30.000000000 -0400
19703 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19704 {
19705 void *p;
19706 int i;
19707 + unsigned long cr0;
19708
19709 if (unlikely(in_interrupt()))
19710 return __memcpy(to, from, len);
19711 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19712 kernel_fpu_begin();
19713
19714 __asm__ __volatile__ (
19715 - "1: prefetch (%0)\n" /* This set is 28 bytes */
19716 - " prefetch 64(%0)\n"
19717 - " prefetch 128(%0)\n"
19718 - " prefetch 192(%0)\n"
19719 - " prefetch 256(%0)\n"
19720 + "1: prefetch (%1)\n" /* This set is 28 bytes */
19721 + " prefetch 64(%1)\n"
19722 + " prefetch 128(%1)\n"
19723 + " prefetch 192(%1)\n"
19724 + " prefetch 256(%1)\n"
19725 "2: \n"
19726 ".section .fixup, \"ax\"\n"
19727 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19728 + "3: \n"
19729 +
19730 +#ifdef CONFIG_PAX_KERNEXEC
19731 + " movl %%cr0, %0\n"
19732 + " movl %0, %%eax\n"
19733 + " andl $0xFFFEFFFF, %%eax\n"
19734 + " movl %%eax, %%cr0\n"
19735 +#endif
19736 +
19737 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19738 +
19739 +#ifdef CONFIG_PAX_KERNEXEC
19740 + " movl %0, %%cr0\n"
19741 +#endif
19742 +
19743 " jmp 2b\n"
19744 ".previous\n"
19745 _ASM_EXTABLE(1b, 3b)
19746 - : : "r" (from));
19747 + : "=&r" (cr0) : "r" (from) : "ax");
19748
19749 for ( ; i > 5; i--) {
19750 __asm__ __volatile__ (
19751 - "1: prefetch 320(%0)\n"
19752 - "2: movq (%0), %%mm0\n"
19753 - " movq 8(%0), %%mm1\n"
19754 - " movq 16(%0), %%mm2\n"
19755 - " movq 24(%0), %%mm3\n"
19756 - " movq %%mm0, (%1)\n"
19757 - " movq %%mm1, 8(%1)\n"
19758 - " movq %%mm2, 16(%1)\n"
19759 - " movq %%mm3, 24(%1)\n"
19760 - " movq 32(%0), %%mm0\n"
19761 - " movq 40(%0), %%mm1\n"
19762 - " movq 48(%0), %%mm2\n"
19763 - " movq 56(%0), %%mm3\n"
19764 - " movq %%mm0, 32(%1)\n"
19765 - " movq %%mm1, 40(%1)\n"
19766 - " movq %%mm2, 48(%1)\n"
19767 - " movq %%mm3, 56(%1)\n"
19768 + "1: prefetch 320(%1)\n"
19769 + "2: movq (%1), %%mm0\n"
19770 + " movq 8(%1), %%mm1\n"
19771 + " movq 16(%1), %%mm2\n"
19772 + " movq 24(%1), %%mm3\n"
19773 + " movq %%mm0, (%2)\n"
19774 + " movq %%mm1, 8(%2)\n"
19775 + " movq %%mm2, 16(%2)\n"
19776 + " movq %%mm3, 24(%2)\n"
19777 + " movq 32(%1), %%mm0\n"
19778 + " movq 40(%1), %%mm1\n"
19779 + " movq 48(%1), %%mm2\n"
19780 + " movq 56(%1), %%mm3\n"
19781 + " movq %%mm0, 32(%2)\n"
19782 + " movq %%mm1, 40(%2)\n"
19783 + " movq %%mm2, 48(%2)\n"
19784 + " movq %%mm3, 56(%2)\n"
19785 ".section .fixup, \"ax\"\n"
19786 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19787 + "3:\n"
19788 +
19789 +#ifdef CONFIG_PAX_KERNEXEC
19790 + " movl %%cr0, %0\n"
19791 + " movl %0, %%eax\n"
19792 + " andl $0xFFFEFFFF, %%eax\n"
19793 + " movl %%eax, %%cr0\n"
19794 +#endif
19795 +
19796 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19797 +
19798 +#ifdef CONFIG_PAX_KERNEXEC
19799 + " movl %0, %%cr0\n"
19800 +#endif
19801 +
19802 " jmp 2b\n"
19803 ".previous\n"
19804 _ASM_EXTABLE(1b, 3b)
19805 - : : "r" (from), "r" (to) : "memory");
19806 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19807
19808 from += 64;
19809 to += 64;
19810 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19811 static void fast_copy_page(void *to, void *from)
19812 {
19813 int i;
19814 + unsigned long cr0;
19815
19816 kernel_fpu_begin();
19817
19818 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19819 * but that is for later. -AV
19820 */
19821 __asm__ __volatile__(
19822 - "1: prefetch (%0)\n"
19823 - " prefetch 64(%0)\n"
19824 - " prefetch 128(%0)\n"
19825 - " prefetch 192(%0)\n"
19826 - " prefetch 256(%0)\n"
19827 + "1: prefetch (%1)\n"
19828 + " prefetch 64(%1)\n"
19829 + " prefetch 128(%1)\n"
19830 + " prefetch 192(%1)\n"
19831 + " prefetch 256(%1)\n"
19832 "2: \n"
19833 ".section .fixup, \"ax\"\n"
19834 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19835 + "3: \n"
19836 +
19837 +#ifdef CONFIG_PAX_KERNEXEC
19838 + " movl %%cr0, %0\n"
19839 + " movl %0, %%eax\n"
19840 + " andl $0xFFFEFFFF, %%eax\n"
19841 + " movl %%eax, %%cr0\n"
19842 +#endif
19843 +
19844 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19845 +
19846 +#ifdef CONFIG_PAX_KERNEXEC
19847 + " movl %0, %%cr0\n"
19848 +#endif
19849 +
19850 " jmp 2b\n"
19851 ".previous\n"
19852 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
19853 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19854
19855 for (i = 0; i < (4096-320)/64; i++) {
19856 __asm__ __volatile__ (
19857 - "1: prefetch 320(%0)\n"
19858 - "2: movq (%0), %%mm0\n"
19859 - " movntq %%mm0, (%1)\n"
19860 - " movq 8(%0), %%mm1\n"
19861 - " movntq %%mm1, 8(%1)\n"
19862 - " movq 16(%0), %%mm2\n"
19863 - " movntq %%mm2, 16(%1)\n"
19864 - " movq 24(%0), %%mm3\n"
19865 - " movntq %%mm3, 24(%1)\n"
19866 - " movq 32(%0), %%mm4\n"
19867 - " movntq %%mm4, 32(%1)\n"
19868 - " movq 40(%0), %%mm5\n"
19869 - " movntq %%mm5, 40(%1)\n"
19870 - " movq 48(%0), %%mm6\n"
19871 - " movntq %%mm6, 48(%1)\n"
19872 - " movq 56(%0), %%mm7\n"
19873 - " movntq %%mm7, 56(%1)\n"
19874 + "1: prefetch 320(%1)\n"
19875 + "2: movq (%1), %%mm0\n"
19876 + " movntq %%mm0, (%2)\n"
19877 + " movq 8(%1), %%mm1\n"
19878 + " movntq %%mm1, 8(%2)\n"
19879 + " movq 16(%1), %%mm2\n"
19880 + " movntq %%mm2, 16(%2)\n"
19881 + " movq 24(%1), %%mm3\n"
19882 + " movntq %%mm3, 24(%2)\n"
19883 + " movq 32(%1), %%mm4\n"
19884 + " movntq %%mm4, 32(%2)\n"
19885 + " movq 40(%1), %%mm5\n"
19886 + " movntq %%mm5, 40(%2)\n"
19887 + " movq 48(%1), %%mm6\n"
19888 + " movntq %%mm6, 48(%2)\n"
19889 + " movq 56(%1), %%mm7\n"
19890 + " movntq %%mm7, 56(%2)\n"
19891 ".section .fixup, \"ax\"\n"
19892 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19893 + "3:\n"
19894 +
19895 +#ifdef CONFIG_PAX_KERNEXEC
19896 + " movl %%cr0, %0\n"
19897 + " movl %0, %%eax\n"
19898 + " andl $0xFFFEFFFF, %%eax\n"
19899 + " movl %%eax, %%cr0\n"
19900 +#endif
19901 +
19902 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19903 +
19904 +#ifdef CONFIG_PAX_KERNEXEC
19905 + " movl %0, %%cr0\n"
19906 +#endif
19907 +
19908 " jmp 2b\n"
19909 ".previous\n"
19910 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
19911 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19912
19913 from += 64;
19914 to += 64;
19915 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
19916 static void fast_copy_page(void *to, void *from)
19917 {
19918 int i;
19919 + unsigned long cr0;
19920
19921 kernel_fpu_begin();
19922
19923 __asm__ __volatile__ (
19924 - "1: prefetch (%0)\n"
19925 - " prefetch 64(%0)\n"
19926 - " prefetch 128(%0)\n"
19927 - " prefetch 192(%0)\n"
19928 - " prefetch 256(%0)\n"
19929 + "1: prefetch (%1)\n"
19930 + " prefetch 64(%1)\n"
19931 + " prefetch 128(%1)\n"
19932 + " prefetch 192(%1)\n"
19933 + " prefetch 256(%1)\n"
19934 "2: \n"
19935 ".section .fixup, \"ax\"\n"
19936 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19937 + "3: \n"
19938 +
19939 +#ifdef CONFIG_PAX_KERNEXEC
19940 + " movl %%cr0, %0\n"
19941 + " movl %0, %%eax\n"
19942 + " andl $0xFFFEFFFF, %%eax\n"
19943 + " movl %%eax, %%cr0\n"
19944 +#endif
19945 +
19946 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19947 +
19948 +#ifdef CONFIG_PAX_KERNEXEC
19949 + " movl %0, %%cr0\n"
19950 +#endif
19951 +
19952 " jmp 2b\n"
19953 ".previous\n"
19954 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
19955 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19956
19957 for (i = 0; i < 4096/64; i++) {
19958 __asm__ __volatile__ (
19959 - "1: prefetch 320(%0)\n"
19960 - "2: movq (%0), %%mm0\n"
19961 - " movq 8(%0), %%mm1\n"
19962 - " movq 16(%0), %%mm2\n"
19963 - " movq 24(%0), %%mm3\n"
19964 - " movq %%mm0, (%1)\n"
19965 - " movq %%mm1, 8(%1)\n"
19966 - " movq %%mm2, 16(%1)\n"
19967 - " movq %%mm3, 24(%1)\n"
19968 - " movq 32(%0), %%mm0\n"
19969 - " movq 40(%0), %%mm1\n"
19970 - " movq 48(%0), %%mm2\n"
19971 - " movq 56(%0), %%mm3\n"
19972 - " movq %%mm0, 32(%1)\n"
19973 - " movq %%mm1, 40(%1)\n"
19974 - " movq %%mm2, 48(%1)\n"
19975 - " movq %%mm3, 56(%1)\n"
19976 + "1: prefetch 320(%1)\n"
19977 + "2: movq (%1), %%mm0\n"
19978 + " movq 8(%1), %%mm1\n"
19979 + " movq 16(%1), %%mm2\n"
19980 + " movq 24(%1), %%mm3\n"
19981 + " movq %%mm0, (%2)\n"
19982 + " movq %%mm1, 8(%2)\n"
19983 + " movq %%mm2, 16(%2)\n"
19984 + " movq %%mm3, 24(%2)\n"
19985 + " movq 32(%1), %%mm0\n"
19986 + " movq 40(%1), %%mm1\n"
19987 + " movq 48(%1), %%mm2\n"
19988 + " movq 56(%1), %%mm3\n"
19989 + " movq %%mm0, 32(%2)\n"
19990 + " movq %%mm1, 40(%2)\n"
19991 + " movq %%mm2, 48(%2)\n"
19992 + " movq %%mm3, 56(%2)\n"
19993 ".section .fixup, \"ax\"\n"
19994 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19995 + "3:\n"
19996 +
19997 +#ifdef CONFIG_PAX_KERNEXEC
19998 + " movl %%cr0, %0\n"
19999 + " movl %0, %%eax\n"
20000 + " andl $0xFFFEFFFF, %%eax\n"
20001 + " movl %%eax, %%cr0\n"
20002 +#endif
20003 +
20004 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20005 +
20006 +#ifdef CONFIG_PAX_KERNEXEC
20007 + " movl %0, %%cr0\n"
20008 +#endif
20009 +
20010 " jmp 2b\n"
20011 ".previous\n"
20012 _ASM_EXTABLE(1b, 3b)
20013 - : : "r" (from), "r" (to) : "memory");
20014 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20015
20016 from += 64;
20017 to += 64;
20018 diff -urNp linux-2.6.39.1/arch/x86/lib/putuser.S linux-2.6.39.1/arch/x86/lib/putuser.S
20019 --- linux-2.6.39.1/arch/x86/lib/putuser.S 2011-05-19 00:06:34.000000000 -0400
20020 +++ linux-2.6.39.1/arch/x86/lib/putuser.S 2011-05-22 19:36:30.000000000 -0400
20021 @@ -15,7 +15,8 @@
20022 #include <asm/thread_info.h>
20023 #include <asm/errno.h>
20024 #include <asm/asm.h>
20025 -
20026 +#include <asm/segment.h>
20027 +#include <asm/pgtable.h>
20028
20029 /*
20030 * __put_user_X
20031 @@ -29,52 +30,119 @@
20032 * as they get called from within inline assembly.
20033 */
20034
20035 -#define ENTER CFI_STARTPROC ; \
20036 - GET_THREAD_INFO(%_ASM_BX)
20037 +#define ENTER CFI_STARTPROC
20038 #define EXIT ret ; \
20039 CFI_ENDPROC
20040
20041 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20042 +#define _DEST %_ASM_CX,%_ASM_BX
20043 +#else
20044 +#define _DEST %_ASM_CX
20045 +#endif
20046 +
20047 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20048 +#define __copyuser_seg gs;
20049 +#else
20050 +#define __copyuser_seg
20051 +#endif
20052 +
20053 .text
20054 ENTRY(__put_user_1)
20055 ENTER
20056 +
20057 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20058 + GET_THREAD_INFO(%_ASM_BX)
20059 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20060 jae bad_put_user
20061 -1: movb %al,(%_ASM_CX)
20062 +
20063 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20064 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20065 + cmp %_ASM_BX,%_ASM_CX
20066 + jb 1234f
20067 + xor %ebx,%ebx
20068 +1234:
20069 +#endif
20070 +
20071 +#endif
20072 +
20073 +1: __copyuser_seg movb %al,(_DEST)
20074 xor %eax,%eax
20075 EXIT
20076 ENDPROC(__put_user_1)
20077
20078 ENTRY(__put_user_2)
20079 ENTER
20080 +
20081 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20082 + GET_THREAD_INFO(%_ASM_BX)
20083 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20084 sub $1,%_ASM_BX
20085 cmp %_ASM_BX,%_ASM_CX
20086 jae bad_put_user
20087 -2: movw %ax,(%_ASM_CX)
20088 +
20089 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20090 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20091 + cmp %_ASM_BX,%_ASM_CX
20092 + jb 1234f
20093 + xor %ebx,%ebx
20094 +1234:
20095 +#endif
20096 +
20097 +#endif
20098 +
20099 +2: __copyuser_seg movw %ax,(_DEST)
20100 xor %eax,%eax
20101 EXIT
20102 ENDPROC(__put_user_2)
20103
20104 ENTRY(__put_user_4)
20105 ENTER
20106 +
20107 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20108 + GET_THREAD_INFO(%_ASM_BX)
20109 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20110 sub $3,%_ASM_BX
20111 cmp %_ASM_BX,%_ASM_CX
20112 jae bad_put_user
20113 -3: movl %eax,(%_ASM_CX)
20114 +
20115 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20116 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20117 + cmp %_ASM_BX,%_ASM_CX
20118 + jb 1234f
20119 + xor %ebx,%ebx
20120 +1234:
20121 +#endif
20122 +
20123 +#endif
20124 +
20125 +3: __copyuser_seg movl %eax,(_DEST)
20126 xor %eax,%eax
20127 EXIT
20128 ENDPROC(__put_user_4)
20129
20130 ENTRY(__put_user_8)
20131 ENTER
20132 +
20133 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20134 + GET_THREAD_INFO(%_ASM_BX)
20135 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20136 sub $7,%_ASM_BX
20137 cmp %_ASM_BX,%_ASM_CX
20138 jae bad_put_user
20139 -4: mov %_ASM_AX,(%_ASM_CX)
20140 +
20141 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20142 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20143 + cmp %_ASM_BX,%_ASM_CX
20144 + jb 1234f
20145 + xor %ebx,%ebx
20146 +1234:
20147 +#endif
20148 +
20149 +#endif
20150 +
20151 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20152 #ifdef CONFIG_X86_32
20153 -5: movl %edx,4(%_ASM_CX)
20154 +5: __copyuser_seg movl %edx,4(_DEST)
20155 #endif
20156 xor %eax,%eax
20157 EXIT
20158 diff -urNp linux-2.6.39.1/arch/x86/lib/usercopy_32.c linux-2.6.39.1/arch/x86/lib/usercopy_32.c
20159 --- linux-2.6.39.1/arch/x86/lib/usercopy_32.c 2011-05-19 00:06:34.000000000 -0400
20160 +++ linux-2.6.39.1/arch/x86/lib/usercopy_32.c 2011-05-22 19:36:30.000000000 -0400
20161 @@ -43,7 +43,7 @@ do { \
20162 __asm__ __volatile__( \
20163 " testl %1,%1\n" \
20164 " jz 2f\n" \
20165 - "0: lodsb\n" \
20166 + "0: "__copyuser_seg"lodsb\n" \
20167 " stosb\n" \
20168 " testb %%al,%%al\n" \
20169 " jz 1f\n" \
20170 @@ -128,10 +128,12 @@ do { \
20171 int __d0; \
20172 might_fault(); \
20173 __asm__ __volatile__( \
20174 + __COPYUSER_SET_ES \
20175 "0: rep; stosl\n" \
20176 " movl %2,%0\n" \
20177 "1: rep; stosb\n" \
20178 "2:\n" \
20179 + __COPYUSER_RESTORE_ES \
20180 ".section .fixup,\"ax\"\n" \
20181 "3: lea 0(%2,%0,4),%0\n" \
20182 " jmp 2b\n" \
20183 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
20184 might_fault();
20185
20186 __asm__ __volatile__(
20187 + __COPYUSER_SET_ES
20188 " testl %0, %0\n"
20189 " jz 3f\n"
20190 " andl %0,%%ecx\n"
20191 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
20192 " subl %%ecx,%0\n"
20193 " addl %0,%%eax\n"
20194 "1:\n"
20195 + __COPYUSER_RESTORE_ES
20196 ".section .fixup,\"ax\"\n"
20197 "2: xorl %%eax,%%eax\n"
20198 " jmp 1b\n"
20199 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20200
20201 #ifdef CONFIG_X86_INTEL_USERCOPY
20202 static unsigned long
20203 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20204 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20205 {
20206 int d0, d1;
20207 __asm__ __volatile__(
20208 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
20209 " .align 2,0x90\n"
20210 "3: movl 0(%4), %%eax\n"
20211 "4: movl 4(%4), %%edx\n"
20212 - "5: movl %%eax, 0(%3)\n"
20213 - "6: movl %%edx, 4(%3)\n"
20214 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20215 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20216 "7: movl 8(%4), %%eax\n"
20217 "8: movl 12(%4),%%edx\n"
20218 - "9: movl %%eax, 8(%3)\n"
20219 - "10: movl %%edx, 12(%3)\n"
20220 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20221 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20222 "11: movl 16(%4), %%eax\n"
20223 "12: movl 20(%4), %%edx\n"
20224 - "13: movl %%eax, 16(%3)\n"
20225 - "14: movl %%edx, 20(%3)\n"
20226 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20227 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20228 "15: movl 24(%4), %%eax\n"
20229 "16: movl 28(%4), %%edx\n"
20230 - "17: movl %%eax, 24(%3)\n"
20231 - "18: movl %%edx, 28(%3)\n"
20232 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20233 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20234 "19: movl 32(%4), %%eax\n"
20235 "20: movl 36(%4), %%edx\n"
20236 - "21: movl %%eax, 32(%3)\n"
20237 - "22: movl %%edx, 36(%3)\n"
20238 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20239 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20240 "23: movl 40(%4), %%eax\n"
20241 "24: movl 44(%4), %%edx\n"
20242 - "25: movl %%eax, 40(%3)\n"
20243 - "26: movl %%edx, 44(%3)\n"
20244 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20245 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20246 "27: movl 48(%4), %%eax\n"
20247 "28: movl 52(%4), %%edx\n"
20248 - "29: movl %%eax, 48(%3)\n"
20249 - "30: movl %%edx, 52(%3)\n"
20250 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20251 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20252 "31: movl 56(%4), %%eax\n"
20253 "32: movl 60(%4), %%edx\n"
20254 - "33: movl %%eax, 56(%3)\n"
20255 - "34: movl %%edx, 60(%3)\n"
20256 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20257 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20258 " addl $-64, %0\n"
20259 " addl $64, %4\n"
20260 " addl $64, %3\n"
20261 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
20262 " shrl $2, %0\n"
20263 " andl $3, %%eax\n"
20264 " cld\n"
20265 + __COPYUSER_SET_ES
20266 "99: rep; movsl\n"
20267 "36: movl %%eax, %0\n"
20268 "37: rep; movsb\n"
20269 "100:\n"
20270 + __COPYUSER_RESTORE_ES
20271 + ".section .fixup,\"ax\"\n"
20272 + "101: lea 0(%%eax,%0,4),%0\n"
20273 + " jmp 100b\n"
20274 + ".previous\n"
20275 + ".section __ex_table,\"a\"\n"
20276 + " .align 4\n"
20277 + " .long 1b,100b\n"
20278 + " .long 2b,100b\n"
20279 + " .long 3b,100b\n"
20280 + " .long 4b,100b\n"
20281 + " .long 5b,100b\n"
20282 + " .long 6b,100b\n"
20283 + " .long 7b,100b\n"
20284 + " .long 8b,100b\n"
20285 + " .long 9b,100b\n"
20286 + " .long 10b,100b\n"
20287 + " .long 11b,100b\n"
20288 + " .long 12b,100b\n"
20289 + " .long 13b,100b\n"
20290 + " .long 14b,100b\n"
20291 + " .long 15b,100b\n"
20292 + " .long 16b,100b\n"
20293 + " .long 17b,100b\n"
20294 + " .long 18b,100b\n"
20295 + " .long 19b,100b\n"
20296 + " .long 20b,100b\n"
20297 + " .long 21b,100b\n"
20298 + " .long 22b,100b\n"
20299 + " .long 23b,100b\n"
20300 + " .long 24b,100b\n"
20301 + " .long 25b,100b\n"
20302 + " .long 26b,100b\n"
20303 + " .long 27b,100b\n"
20304 + " .long 28b,100b\n"
20305 + " .long 29b,100b\n"
20306 + " .long 30b,100b\n"
20307 + " .long 31b,100b\n"
20308 + " .long 32b,100b\n"
20309 + " .long 33b,100b\n"
20310 + " .long 34b,100b\n"
20311 + " .long 35b,100b\n"
20312 + " .long 36b,100b\n"
20313 + " .long 37b,100b\n"
20314 + " .long 99b,101b\n"
20315 + ".previous"
20316 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
20317 + : "1"(to), "2"(from), "0"(size)
20318 + : "eax", "edx", "memory");
20319 + return size;
20320 +}
20321 +
20322 +static unsigned long
20323 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20324 +{
20325 + int d0, d1;
20326 + __asm__ __volatile__(
20327 + " .align 2,0x90\n"
20328 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20329 + " cmpl $67, %0\n"
20330 + " jbe 3f\n"
20331 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20332 + " .align 2,0x90\n"
20333 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20334 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20335 + "5: movl %%eax, 0(%3)\n"
20336 + "6: movl %%edx, 4(%3)\n"
20337 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20338 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20339 + "9: movl %%eax, 8(%3)\n"
20340 + "10: movl %%edx, 12(%3)\n"
20341 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20342 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20343 + "13: movl %%eax, 16(%3)\n"
20344 + "14: movl %%edx, 20(%3)\n"
20345 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20346 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20347 + "17: movl %%eax, 24(%3)\n"
20348 + "18: movl %%edx, 28(%3)\n"
20349 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20350 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20351 + "21: movl %%eax, 32(%3)\n"
20352 + "22: movl %%edx, 36(%3)\n"
20353 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20354 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20355 + "25: movl %%eax, 40(%3)\n"
20356 + "26: movl %%edx, 44(%3)\n"
20357 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20358 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20359 + "29: movl %%eax, 48(%3)\n"
20360 + "30: movl %%edx, 52(%3)\n"
20361 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20362 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20363 + "33: movl %%eax, 56(%3)\n"
20364 + "34: movl %%edx, 60(%3)\n"
20365 + " addl $-64, %0\n"
20366 + " addl $64, %4\n"
20367 + " addl $64, %3\n"
20368 + " cmpl $63, %0\n"
20369 + " ja 1b\n"
20370 + "35: movl %0, %%eax\n"
20371 + " shrl $2, %0\n"
20372 + " andl $3, %%eax\n"
20373 + " cld\n"
20374 + "99: rep; "__copyuser_seg" movsl\n"
20375 + "36: movl %%eax, %0\n"
20376 + "37: rep; "__copyuser_seg" movsb\n"
20377 + "100:\n"
20378 ".section .fixup,\"ax\"\n"
20379 "101: lea 0(%%eax,%0,4),%0\n"
20380 " jmp 100b\n"
20381 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20382 int d0, d1;
20383 __asm__ __volatile__(
20384 " .align 2,0x90\n"
20385 - "0: movl 32(%4), %%eax\n"
20386 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20387 " cmpl $67, %0\n"
20388 " jbe 2f\n"
20389 - "1: movl 64(%4), %%eax\n"
20390 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20391 " .align 2,0x90\n"
20392 - "2: movl 0(%4), %%eax\n"
20393 - "21: movl 4(%4), %%edx\n"
20394 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20395 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20396 " movl %%eax, 0(%3)\n"
20397 " movl %%edx, 4(%3)\n"
20398 - "3: movl 8(%4), %%eax\n"
20399 - "31: movl 12(%4),%%edx\n"
20400 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20401 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20402 " movl %%eax, 8(%3)\n"
20403 " movl %%edx, 12(%3)\n"
20404 - "4: movl 16(%4), %%eax\n"
20405 - "41: movl 20(%4), %%edx\n"
20406 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20407 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20408 " movl %%eax, 16(%3)\n"
20409 " movl %%edx, 20(%3)\n"
20410 - "10: movl 24(%4), %%eax\n"
20411 - "51: movl 28(%4), %%edx\n"
20412 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20413 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20414 " movl %%eax, 24(%3)\n"
20415 " movl %%edx, 28(%3)\n"
20416 - "11: movl 32(%4), %%eax\n"
20417 - "61: movl 36(%4), %%edx\n"
20418 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20419 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20420 " movl %%eax, 32(%3)\n"
20421 " movl %%edx, 36(%3)\n"
20422 - "12: movl 40(%4), %%eax\n"
20423 - "71: movl 44(%4), %%edx\n"
20424 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20425 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20426 " movl %%eax, 40(%3)\n"
20427 " movl %%edx, 44(%3)\n"
20428 - "13: movl 48(%4), %%eax\n"
20429 - "81: movl 52(%4), %%edx\n"
20430 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20431 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20432 " movl %%eax, 48(%3)\n"
20433 " movl %%edx, 52(%3)\n"
20434 - "14: movl 56(%4), %%eax\n"
20435 - "91: movl 60(%4), %%edx\n"
20436 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20437 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20438 " movl %%eax, 56(%3)\n"
20439 " movl %%edx, 60(%3)\n"
20440 " addl $-64, %0\n"
20441 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20442 " shrl $2, %0\n"
20443 " andl $3, %%eax\n"
20444 " cld\n"
20445 - "6: rep; movsl\n"
20446 + "6: rep; "__copyuser_seg" movsl\n"
20447 " movl %%eax,%0\n"
20448 - "7: rep; movsb\n"
20449 + "7: rep; "__copyuser_seg" movsb\n"
20450 "8:\n"
20451 ".section .fixup,\"ax\"\n"
20452 "9: lea 0(%%eax,%0,4),%0\n"
20453 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20454
20455 __asm__ __volatile__(
20456 " .align 2,0x90\n"
20457 - "0: movl 32(%4), %%eax\n"
20458 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20459 " cmpl $67, %0\n"
20460 " jbe 2f\n"
20461 - "1: movl 64(%4), %%eax\n"
20462 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20463 " .align 2,0x90\n"
20464 - "2: movl 0(%4), %%eax\n"
20465 - "21: movl 4(%4), %%edx\n"
20466 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20467 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20468 " movnti %%eax, 0(%3)\n"
20469 " movnti %%edx, 4(%3)\n"
20470 - "3: movl 8(%4), %%eax\n"
20471 - "31: movl 12(%4),%%edx\n"
20472 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20473 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20474 " movnti %%eax, 8(%3)\n"
20475 " movnti %%edx, 12(%3)\n"
20476 - "4: movl 16(%4), %%eax\n"
20477 - "41: movl 20(%4), %%edx\n"
20478 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20479 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20480 " movnti %%eax, 16(%3)\n"
20481 " movnti %%edx, 20(%3)\n"
20482 - "10: movl 24(%4), %%eax\n"
20483 - "51: movl 28(%4), %%edx\n"
20484 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20485 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20486 " movnti %%eax, 24(%3)\n"
20487 " movnti %%edx, 28(%3)\n"
20488 - "11: movl 32(%4), %%eax\n"
20489 - "61: movl 36(%4), %%edx\n"
20490 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20491 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20492 " movnti %%eax, 32(%3)\n"
20493 " movnti %%edx, 36(%3)\n"
20494 - "12: movl 40(%4), %%eax\n"
20495 - "71: movl 44(%4), %%edx\n"
20496 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20497 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20498 " movnti %%eax, 40(%3)\n"
20499 " movnti %%edx, 44(%3)\n"
20500 - "13: movl 48(%4), %%eax\n"
20501 - "81: movl 52(%4), %%edx\n"
20502 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20503 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20504 " movnti %%eax, 48(%3)\n"
20505 " movnti %%edx, 52(%3)\n"
20506 - "14: movl 56(%4), %%eax\n"
20507 - "91: movl 60(%4), %%edx\n"
20508 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20509 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20510 " movnti %%eax, 56(%3)\n"
20511 " movnti %%edx, 60(%3)\n"
20512 " addl $-64, %0\n"
20513 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20514 " shrl $2, %0\n"
20515 " andl $3, %%eax\n"
20516 " cld\n"
20517 - "6: rep; movsl\n"
20518 + "6: rep; "__copyuser_seg" movsl\n"
20519 " movl %%eax,%0\n"
20520 - "7: rep; movsb\n"
20521 + "7: rep; "__copyuser_seg" movsb\n"
20522 "8:\n"
20523 ".section .fixup,\"ax\"\n"
20524 "9: lea 0(%%eax,%0,4),%0\n"
20525 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20526
20527 __asm__ __volatile__(
20528 " .align 2,0x90\n"
20529 - "0: movl 32(%4), %%eax\n"
20530 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20531 " cmpl $67, %0\n"
20532 " jbe 2f\n"
20533 - "1: movl 64(%4), %%eax\n"
20534 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20535 " .align 2,0x90\n"
20536 - "2: movl 0(%4), %%eax\n"
20537 - "21: movl 4(%4), %%edx\n"
20538 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20539 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20540 " movnti %%eax, 0(%3)\n"
20541 " movnti %%edx, 4(%3)\n"
20542 - "3: movl 8(%4), %%eax\n"
20543 - "31: movl 12(%4),%%edx\n"
20544 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20545 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20546 " movnti %%eax, 8(%3)\n"
20547 " movnti %%edx, 12(%3)\n"
20548 - "4: movl 16(%4), %%eax\n"
20549 - "41: movl 20(%4), %%edx\n"
20550 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20551 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20552 " movnti %%eax, 16(%3)\n"
20553 " movnti %%edx, 20(%3)\n"
20554 - "10: movl 24(%4), %%eax\n"
20555 - "51: movl 28(%4), %%edx\n"
20556 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20557 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20558 " movnti %%eax, 24(%3)\n"
20559 " movnti %%edx, 28(%3)\n"
20560 - "11: movl 32(%4), %%eax\n"
20561 - "61: movl 36(%4), %%edx\n"
20562 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20563 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20564 " movnti %%eax, 32(%3)\n"
20565 " movnti %%edx, 36(%3)\n"
20566 - "12: movl 40(%4), %%eax\n"
20567 - "71: movl 44(%4), %%edx\n"
20568 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20569 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20570 " movnti %%eax, 40(%3)\n"
20571 " movnti %%edx, 44(%3)\n"
20572 - "13: movl 48(%4), %%eax\n"
20573 - "81: movl 52(%4), %%edx\n"
20574 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20575 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20576 " movnti %%eax, 48(%3)\n"
20577 " movnti %%edx, 52(%3)\n"
20578 - "14: movl 56(%4), %%eax\n"
20579 - "91: movl 60(%4), %%edx\n"
20580 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20581 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20582 " movnti %%eax, 56(%3)\n"
20583 " movnti %%edx, 60(%3)\n"
20584 " addl $-64, %0\n"
20585 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20586 " shrl $2, %0\n"
20587 " andl $3, %%eax\n"
20588 " cld\n"
20589 - "6: rep; movsl\n"
20590 + "6: rep; "__copyuser_seg" movsl\n"
20591 " movl %%eax,%0\n"
20592 - "7: rep; movsb\n"
20593 + "7: rep; "__copyuser_seg" movsb\n"
20594 "8:\n"
20595 ".section .fixup,\"ax\"\n"
20596 "9: lea 0(%%eax,%0,4),%0\n"
20597 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20598 */
20599 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20600 unsigned long size);
20601 -unsigned long __copy_user_intel(void __user *to, const void *from,
20602 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20603 + unsigned long size);
20604 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20605 unsigned long size);
20606 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20607 const void __user *from, unsigned long size);
20608 #endif /* CONFIG_X86_INTEL_USERCOPY */
20609
20610 /* Generic arbitrary sized copy. */
20611 -#define __copy_user(to, from, size) \
20612 +#define __copy_user(to, from, size, prefix, set, restore) \
20613 do { \
20614 int __d0, __d1, __d2; \
20615 __asm__ __volatile__( \
20616 + set \
20617 " cmp $7,%0\n" \
20618 " jbe 1f\n" \
20619 " movl %1,%0\n" \
20620 " negl %0\n" \
20621 " andl $7,%0\n" \
20622 " subl %0,%3\n" \
20623 - "4: rep; movsb\n" \
20624 + "4: rep; "prefix"movsb\n" \
20625 " movl %3,%0\n" \
20626 " shrl $2,%0\n" \
20627 " andl $3,%3\n" \
20628 " .align 2,0x90\n" \
20629 - "0: rep; movsl\n" \
20630 + "0: rep; "prefix"movsl\n" \
20631 " movl %3,%0\n" \
20632 - "1: rep; movsb\n" \
20633 + "1: rep; "prefix"movsb\n" \
20634 "2:\n" \
20635 + restore \
20636 ".section .fixup,\"ax\"\n" \
20637 "5: addl %3,%0\n" \
20638 " jmp 2b\n" \
20639 @@ -682,14 +799,14 @@ do { \
20640 " negl %0\n" \
20641 " andl $7,%0\n" \
20642 " subl %0,%3\n" \
20643 - "4: rep; movsb\n" \
20644 + "4: rep; "__copyuser_seg"movsb\n" \
20645 " movl %3,%0\n" \
20646 " shrl $2,%0\n" \
20647 " andl $3,%3\n" \
20648 " .align 2,0x90\n" \
20649 - "0: rep; movsl\n" \
20650 + "0: rep; "__copyuser_seg"movsl\n" \
20651 " movl %3,%0\n" \
20652 - "1: rep; movsb\n" \
20653 + "1: rep; "__copyuser_seg"movsb\n" \
20654 "2:\n" \
20655 ".section .fixup,\"ax\"\n" \
20656 "5: addl %3,%0\n" \
20657 @@ -775,9 +892,9 @@ survive:
20658 }
20659 #endif
20660 if (movsl_is_ok(to, from, n))
20661 - __copy_user(to, from, n);
20662 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20663 else
20664 - n = __copy_user_intel(to, from, n);
20665 + n = __generic_copy_to_user_intel(to, from, n);
20666 return n;
20667 }
20668 EXPORT_SYMBOL(__copy_to_user_ll);
20669 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20670 unsigned long n)
20671 {
20672 if (movsl_is_ok(to, from, n))
20673 - __copy_user(to, from, n);
20674 + __copy_user(to, from, n, __copyuser_seg, "", "");
20675 else
20676 - n = __copy_user_intel((void __user *)to,
20677 - (const void *)from, n);
20678 + n = __generic_copy_from_user_intel(to, from, n);
20679 return n;
20680 }
20681 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20682 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocach
20683 if (n > 64 && cpu_has_xmm2)
20684 n = __copy_user_intel_nocache(to, from, n);
20685 else
20686 - __copy_user(to, from, n);
20687 + __copy_user(to, from, n, __copyuser_seg, "", "");
20688 #else
20689 - __copy_user(to, from, n);
20690 + __copy_user(to, from, n, __copyuser_seg, "", "");
20691 #endif
20692 return n;
20693 }
20694 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20695
20696 -/**
20697 - * copy_to_user: - Copy a block of data into user space.
20698 - * @to: Destination address, in user space.
20699 - * @from: Source address, in kernel space.
20700 - * @n: Number of bytes to copy.
20701 - *
20702 - * Context: User context only. This function may sleep.
20703 - *
20704 - * Copy data from kernel space to user space.
20705 - *
20706 - * Returns number of bytes that could not be copied.
20707 - * On success, this will be zero.
20708 - */
20709 -unsigned long
20710 -copy_to_user(void __user *to, const void *from, unsigned long n)
20711 +void copy_from_user_overflow(void)
20712 {
20713 - if (access_ok(VERIFY_WRITE, to, n))
20714 - n = __copy_to_user(to, from, n);
20715 - return n;
20716 + WARN(1, "Buffer overflow detected!\n");
20717 }
20718 -EXPORT_SYMBOL(copy_to_user);
20719 +EXPORT_SYMBOL(copy_from_user_overflow);
20720
20721 -/**
20722 - * copy_from_user: - Copy a block of data from user space.
20723 - * @to: Destination address, in kernel space.
20724 - * @from: Source address, in user space.
20725 - * @n: Number of bytes to copy.
20726 - *
20727 - * Context: User context only. This function may sleep.
20728 - *
20729 - * Copy data from user space to kernel space.
20730 - *
20731 - * Returns number of bytes that could not be copied.
20732 - * On success, this will be zero.
20733 - *
20734 - * If some data could not be copied, this function will pad the copied
20735 - * data to the requested size using zero bytes.
20736 - */
20737 -unsigned long
20738 -_copy_from_user(void *to, const void __user *from, unsigned long n)
20739 +void copy_to_user_overflow(void)
20740 {
20741 - if (access_ok(VERIFY_READ, from, n))
20742 - n = __copy_from_user(to, from, n);
20743 - else
20744 - memset(to, 0, n);
20745 - return n;
20746 + WARN(1, "Buffer overflow detected!\n");
20747 }
20748 -EXPORT_SYMBOL(_copy_from_user);
20749 +EXPORT_SYMBOL(copy_to_user_overflow);
20750
20751 -void copy_from_user_overflow(void)
20752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20753 +void __set_fs(mm_segment_t x)
20754 {
20755 - WARN(1, "Buffer overflow detected!\n");
20756 + switch (x.seg) {
20757 + case 0:
20758 + loadsegment(gs, 0);
20759 + break;
20760 + case TASK_SIZE_MAX:
20761 + loadsegment(gs, __USER_DS);
20762 + break;
20763 + case -1UL:
20764 + loadsegment(gs, __KERNEL_DS);
20765 + break;
20766 + default:
20767 + BUG();
20768 + }
20769 + return;
20770 }
20771 -EXPORT_SYMBOL(copy_from_user_overflow);
20772 +EXPORT_SYMBOL(__set_fs);
20773 +
20774 +void set_fs(mm_segment_t x)
20775 +{
20776 + current_thread_info()->addr_limit = x;
20777 + __set_fs(x);
20778 +}
20779 +EXPORT_SYMBOL(set_fs);
20780 +#endif
20781 diff -urNp linux-2.6.39.1/arch/x86/lib/usercopy_64.c linux-2.6.39.1/arch/x86/lib/usercopy_64.c
20782 --- linux-2.6.39.1/arch/x86/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
20783 +++ linux-2.6.39.1/arch/x86/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
20784 @@ -42,6 +42,12 @@ long
20785 __strncpy_from_user(char *dst, const char __user *src, long count)
20786 {
20787 long res;
20788 +
20789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20790 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20791 + src += PAX_USER_SHADOW_BASE;
20792 +#endif
20793 +
20794 __do_strncpy_from_user(dst, src, count, res);
20795 return res;
20796 }
20797 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20798 {
20799 long __d0;
20800 might_fault();
20801 +
20802 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20803 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20804 + addr += PAX_USER_SHADOW_BASE;
20805 +#endif
20806 +
20807 /* no memory constraint because it doesn't change any memory gcc knows
20808 about */
20809 asm volatile(
20810 @@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20811
20812 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20813 {
20814 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20815 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20816 +
20817 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20818 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20819 + to += PAX_USER_SHADOW_BASE;
20820 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20821 + from += PAX_USER_SHADOW_BASE;
20822 +#endif
20823 +
20824 return copy_user_generic((__force void *)to, (__force void *)from, len);
20825 - }
20826 - return len;
20827 + }
20828 + return len;
20829 }
20830 EXPORT_SYMBOL(copy_in_user);
20831
20832 diff -urNp linux-2.6.39.1/arch/x86/Makefile linux-2.6.39.1/arch/x86/Makefile
20833 --- linux-2.6.39.1/arch/x86/Makefile 2011-05-19 00:06:34.000000000 -0400
20834 +++ linux-2.6.39.1/arch/x86/Makefile 2011-05-22 19:36:30.000000000 -0400
20835 @@ -195,3 +195,12 @@ define archhelp
20836 echo ' FDARGS="..." arguments for the booted kernel'
20837 echo ' FDINITRD=file initrd for the booted kernel'
20838 endef
20839 +
20840 +define OLD_LD
20841 +
20842 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20843 +*** Please upgrade your binutils to 2.18 or newer
20844 +endef
20845 +
20846 +archprepare:
20847 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20848 diff -urNp linux-2.6.39.1/arch/x86/mm/extable.c linux-2.6.39.1/arch/x86/mm/extable.c
20849 --- linux-2.6.39.1/arch/x86/mm/extable.c 2011-05-19 00:06:34.000000000 -0400
20850 +++ linux-2.6.39.1/arch/x86/mm/extable.c 2011-05-22 19:36:30.000000000 -0400
20851 @@ -1,14 +1,71 @@
20852 #include <linux/module.h>
20853 #include <linux/spinlock.h>
20854 +#include <linux/sort.h>
20855 #include <asm/uaccess.h>
20856 +#include <asm/pgtable.h>
20857
20858 +/*
20859 + * The exception table needs to be sorted so that the binary
20860 + * search that we use to find entries in it works properly.
20861 + * This is used both for the kernel exception table and for
20862 + * the exception tables of modules that get loaded.
20863 + */
20864 +static int cmp_ex(const void *a, const void *b)
20865 +{
20866 + const struct exception_table_entry *x = a, *y = b;
20867 +
20868 + /* avoid overflow */
20869 + if (x->insn > y->insn)
20870 + return 1;
20871 + if (x->insn < y->insn)
20872 + return -1;
20873 + return 0;
20874 +}
20875 +
20876 +static void swap_ex(void *a, void *b, int size)
20877 +{
20878 + struct exception_table_entry t, *x = a, *y = b;
20879 +
20880 + t = *x;
20881 +
20882 + pax_open_kernel();
20883 + *x = *y;
20884 + *y = t;
20885 + pax_close_kernel();
20886 +}
20887 +
20888 +void sort_extable(struct exception_table_entry *start,
20889 + struct exception_table_entry *finish)
20890 +{
20891 + sort(start, finish - start, sizeof(struct exception_table_entry),
20892 + cmp_ex, swap_ex);
20893 +}
20894 +
20895 +#ifdef CONFIG_MODULES
20896 +/*
20897 + * If the exception table is sorted, any referring to the module init
20898 + * will be at the beginning or the end.
20899 + */
20900 +void trim_init_extable(struct module *m)
20901 +{
20902 + /*trim the beginning*/
20903 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
20904 + m->extable++;
20905 + m->num_exentries--;
20906 + }
20907 + /*trim the end*/
20908 + while (m->num_exentries &&
20909 + within_module_init(m->extable[m->num_exentries-1].insn, m))
20910 + m->num_exentries--;
20911 +}
20912 +#endif /* CONFIG_MODULES */
20913
20914 int fixup_exception(struct pt_regs *regs)
20915 {
20916 const struct exception_table_entry *fixup;
20917
20918 #ifdef CONFIG_PNPBIOS
20919 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
20920 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
20921 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
20922 extern u32 pnp_bios_is_utter_crap;
20923 pnp_bios_is_utter_crap = 1;
20924 diff -urNp linux-2.6.39.1/arch/x86/mm/fault.c linux-2.6.39.1/arch/x86/mm/fault.c
20925 --- linux-2.6.39.1/arch/x86/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
20926 +++ linux-2.6.39.1/arch/x86/mm/fault.c 2011-05-22 20:33:41.000000000 -0400
20927 @@ -12,10 +12,18 @@
20928 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
20929 #include <linux/perf_event.h> /* perf_sw_event */
20930 #include <linux/hugetlb.h> /* hstate_index_to_shift */
20931 +#include <linux/unistd.h>
20932 +#include <linux/compiler.h>
20933
20934 #include <asm/traps.h> /* dotraplinkage, ... */
20935 #include <asm/pgalloc.h> /* pgd_*(), ... */
20936 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
20937 +#include <asm/vsyscall.h>
20938 +#include <asm/tlbflush.h>
20939 +
20940 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20941 +#include <asm/stacktrace.h>
20942 +#endif
20943
20944 /*
20945 * Page fault error code bits:
20946 @@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
20947 int ret = 0;
20948
20949 /* kprobe_running() needs smp_processor_id() */
20950 - if (kprobes_built_in() && !user_mode_vm(regs)) {
20951 + if (kprobes_built_in() && !user_mode(regs)) {
20952 preempt_disable();
20953 if (kprobe_running() && kprobe_fault_handler(regs, 14))
20954 ret = 1;
20955 @@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
20956 return !instr_lo || (instr_lo>>1) == 1;
20957 case 0x00:
20958 /* Prefetch instruction is 0x0F0D or 0x0F18 */
20959 - if (probe_kernel_address(instr, opcode))
20960 + if (user_mode(regs)) {
20961 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20962 + return 0;
20963 + } else if (probe_kernel_address(instr, opcode))
20964 return 0;
20965
20966 *prefetch = (instr_lo == 0xF) &&
20967 @@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
20968 while (instr < max_instr) {
20969 unsigned char opcode;
20970
20971 - if (probe_kernel_address(instr, opcode))
20972 + if (user_mode(regs)) {
20973 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20974 + break;
20975 + } else if (probe_kernel_address(instr, opcode))
20976 break;
20977
20978 instr++;
20979 @@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
20980 force_sig_info(si_signo, &info, tsk);
20981 }
20982
20983 +#ifdef CONFIG_PAX_EMUTRAMP
20984 +static int pax_handle_fetch_fault(struct pt_regs *regs);
20985 +#endif
20986 +
20987 +#ifdef CONFIG_PAX_PAGEEXEC
20988 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
20989 +{
20990 + pgd_t *pgd;
20991 + pud_t *pud;
20992 + pmd_t *pmd;
20993 +
20994 + pgd = pgd_offset(mm, address);
20995 + if (!pgd_present(*pgd))
20996 + return NULL;
20997 + pud = pud_offset(pgd, address);
20998 + if (!pud_present(*pud))
20999 + return NULL;
21000 + pmd = pmd_offset(pud, address);
21001 + if (!pmd_present(*pmd))
21002 + return NULL;
21003 + return pmd;
21004 +}
21005 +#endif
21006 +
21007 DEFINE_SPINLOCK(pgd_lock);
21008 LIST_HEAD(pgd_list);
21009
21010 @@ -229,10 +267,22 @@ void vmalloc_sync_all(void)
21011 for (address = VMALLOC_START & PMD_MASK;
21012 address >= TASK_SIZE && address < FIXADDR_TOP;
21013 address += PMD_SIZE) {
21014 +
21015 +#ifdef CONFIG_PAX_PER_CPU_PGD
21016 + unsigned long cpu;
21017 +#else
21018 struct page *page;
21019 +#endif
21020
21021 spin_lock(&pgd_lock);
21022 +
21023 +#ifdef CONFIG_PAX_PER_CPU_PGD
21024 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21025 + pgd_t *pgd = get_cpu_pgd(cpu);
21026 + pmd_t *ret;
21027 +#else
21028 list_for_each_entry(page, &pgd_list, lru) {
21029 + pgd_t *pgd = page_address(page);
21030 spinlock_t *pgt_lock;
21031 pmd_t *ret;
21032
21033 @@ -240,8 +290,13 @@ void vmalloc_sync_all(void)
21034 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21035
21036 spin_lock(pgt_lock);
21037 - ret = vmalloc_sync_one(page_address(page), address);
21038 +#endif
21039 +
21040 + ret = vmalloc_sync_one(pgd, address);
21041 +
21042 +#ifndef CONFIG_PAX_PER_CPU_PGD
21043 spin_unlock(pgt_lock);
21044 +#endif
21045
21046 if (!ret)
21047 break;
21048 @@ -275,6 +330,11 @@ static noinline __kprobes int vmalloc_fa
21049 * an interrupt in the middle of a task switch..
21050 */
21051 pgd_paddr = read_cr3();
21052 +
21053 +#ifdef CONFIG_PAX_PER_CPU_PGD
21054 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21055 +#endif
21056 +
21057 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21058 if (!pmd_k)
21059 return -1;
21060 @@ -370,7 +430,14 @@ static noinline __kprobes int vmalloc_fa
21061 * happen within a race in page table update. In the later
21062 * case just flush:
21063 */
21064 +
21065 +#ifdef CONFIG_PAX_PER_CPU_PGD
21066 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21067 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21068 +#else
21069 pgd = pgd_offset(current->active_mm, address);
21070 +#endif
21071 +
21072 pgd_ref = pgd_offset_k(address);
21073 if (pgd_none(*pgd_ref))
21074 return -1;
21075 @@ -532,7 +599,7 @@ static int is_errata93(struct pt_regs *r
21076 static int is_errata100(struct pt_regs *regs, unsigned long address)
21077 {
21078 #ifdef CONFIG_X86_64
21079 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21080 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21081 return 1;
21082 #endif
21083 return 0;
21084 @@ -559,7 +626,7 @@ static int is_f00f_bug(struct pt_regs *r
21085 }
21086
21087 static const char nx_warning[] = KERN_CRIT
21088 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21089 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21090
21091 static void
21092 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21093 @@ -568,15 +635,26 @@ show_fault_oops(struct pt_regs *regs, un
21094 if (!oops_may_print())
21095 return;
21096
21097 - if (error_code & PF_INSTR) {
21098 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21099 unsigned int level;
21100
21101 pte_t *pte = lookup_address(address, &level);
21102
21103 if (pte && pte_present(*pte) && !pte_exec(*pte))
21104 - printk(nx_warning, current_uid());
21105 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21106 }
21107
21108 +#ifdef CONFIG_PAX_KERNEXEC
21109 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21110 + if (current->signal->curr_ip)
21111 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21112 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21113 + else
21114 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21115 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21116 + }
21117 +#endif
21118 +
21119 printk(KERN_ALERT "BUG: unable to handle kernel ");
21120 if (address < PAGE_SIZE)
21121 printk(KERN_CONT "NULL pointer dereference");
21122 @@ -701,6 +779,68 @@ __bad_area_nosemaphore(struct pt_regs *r
21123 unsigned long address, int si_code)
21124 {
21125 struct task_struct *tsk = current;
21126 + struct mm_struct *mm = tsk->mm;
21127 +
21128 +#ifdef CONFIG_X86_64
21129 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
21130 + if (regs->ip == (unsigned long)vgettimeofday) {
21131 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
21132 + return;
21133 + } else if (regs->ip == (unsigned long)vtime) {
21134 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
21135 + return;
21136 + } else if (regs->ip == (unsigned long)vgetcpu) {
21137 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
21138 + return;
21139 + }
21140 + }
21141 +#endif
21142 +
21143 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21144 + if (mm && (error_code & PF_USER)) {
21145 + unsigned long ip = regs->ip;
21146 +
21147 + if (v8086_mode(regs))
21148 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21149 +
21150 + /*
21151 + * It's possible to have interrupts off here:
21152 + */
21153 + local_irq_enable();
21154 +
21155 +#ifdef CONFIG_PAX_PAGEEXEC
21156 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
21157 + (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
21158 +
21159 +#ifdef CONFIG_PAX_EMUTRAMP
21160 + switch (pax_handle_fetch_fault(regs)) {
21161 + case 2:
21162 + return;
21163 + }
21164 +#endif
21165 +
21166 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21167 + do_group_exit(SIGKILL);
21168 + }
21169 +#endif
21170 +
21171 +#ifdef CONFIG_PAX_SEGMEXEC
21172 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
21173 +
21174 +#ifdef CONFIG_PAX_EMUTRAMP
21175 + switch (pax_handle_fetch_fault(regs)) {
21176 + case 2:
21177 + return;
21178 + }
21179 +#endif
21180 +
21181 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21182 + do_group_exit(SIGKILL);
21183 + }
21184 +#endif
21185 +
21186 + }
21187 +#endif
21188
21189 /* User mode accesses just cause a SIGSEGV */
21190 if (error_code & PF_USER) {
21191 @@ -855,6 +995,99 @@ static int spurious_fault_check(unsigned
21192 return 1;
21193 }
21194
21195 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21196 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21197 +{
21198 + pte_t *pte;
21199 + pmd_t *pmd;
21200 + spinlock_t *ptl;
21201 + unsigned char pte_mask;
21202 +
21203 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21204 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21205 + return 0;
21206 +
21207 + /* PaX: it's our fault, let's handle it if we can */
21208 +
21209 + /* PaX: take a look at read faults before acquiring any locks */
21210 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21211 + /* instruction fetch attempt from a protected page in user mode */
21212 + up_read(&mm->mmap_sem);
21213 +
21214 +#ifdef CONFIG_PAX_EMUTRAMP
21215 + switch (pax_handle_fetch_fault(regs)) {
21216 + case 2:
21217 + return 1;
21218 + }
21219 +#endif
21220 +
21221 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21222 + do_group_exit(SIGKILL);
21223 + }
21224 +
21225 + pmd = pax_get_pmd(mm, address);
21226 + if (unlikely(!pmd))
21227 + return 0;
21228 +
21229 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21230 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21231 + pte_unmap_unlock(pte, ptl);
21232 + return 0;
21233 + }
21234 +
21235 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21236 + /* write attempt to a protected page in user mode */
21237 + pte_unmap_unlock(pte, ptl);
21238 + return 0;
21239 + }
21240 +
21241 +#ifdef CONFIG_SMP
21242 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21243 +#else
21244 + if (likely(address > get_limit(regs->cs)))
21245 +#endif
21246 + {
21247 + set_pte(pte, pte_mkread(*pte));
21248 + __flush_tlb_one(address);
21249 + pte_unmap_unlock(pte, ptl);
21250 + up_read(&mm->mmap_sem);
21251 + return 1;
21252 + }
21253 +
21254 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21255 +
21256 + /*
21257 + * PaX: fill DTLB with user rights and retry
21258 + */
21259 + __asm__ __volatile__ (
21260 + "orb %2,(%1)\n"
21261 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21262 +/*
21263 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21264 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21265 + * page fault when examined during a TLB load attempt. this is true not only
21266 + * for PTEs holding a non-present entry but also present entries that will
21267 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21268 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21269 + * for our target pages since their PTEs are simply not in the TLBs at all.
21270 +
21271 + * the best thing in omitting it is that we gain around 15-20% speed in the
21272 + * fast path of the page fault handler and can get rid of tracing since we
21273 + * can no longer flush unintended entries.
21274 + */
21275 + "invlpg (%0)\n"
21276 +#endif
21277 + __copyuser_seg"testb $0,(%0)\n"
21278 + "xorb %3,(%1)\n"
21279 + :
21280 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21281 + : "memory", "cc");
21282 + pte_unmap_unlock(pte, ptl);
21283 + up_read(&mm->mmap_sem);
21284 + return 1;
21285 +}
21286 +#endif
21287 +
21288 /*
21289 * Handle a spurious fault caused by a stale TLB entry.
21290 *
21291 @@ -927,6 +1160,9 @@ int show_unhandled_signals = 1;
21292 static inline int
21293 access_error(unsigned long error_code, struct vm_area_struct *vma)
21294 {
21295 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21296 + return 1;
21297 +
21298 if (error_code & PF_WRITE) {
21299 /* write, present and write, not present: */
21300 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21301 @@ -960,19 +1196,33 @@ do_page_fault(struct pt_regs *regs, unsi
21302 {
21303 struct vm_area_struct *vma;
21304 struct task_struct *tsk;
21305 - unsigned long address;
21306 struct mm_struct *mm;
21307 int fault;
21308 int write = error_code & PF_WRITE;
21309 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
21310 (write ? FAULT_FLAG_WRITE : 0);
21311
21312 + /* Get the faulting address: */
21313 + unsigned long address = read_cr2();
21314 +
21315 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21316 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21317 + if (!search_exception_tables(regs->ip)) {
21318 + bad_area_nosemaphore(regs, error_code, address);
21319 + return;
21320 + }
21321 + if (address < PAX_USER_SHADOW_BASE) {
21322 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21323 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21324 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21325 + } else
21326 + address -= PAX_USER_SHADOW_BASE;
21327 + }
21328 +#endif
21329 +
21330 tsk = current;
21331 mm = tsk->mm;
21332
21333 - /* Get the faulting address: */
21334 - address = read_cr2();
21335 -
21336 /*
21337 * Detect and handle instructions that would cause a page fault for
21338 * both a tracked kernel page and a userspace page.
21339 @@ -1032,7 +1282,7 @@ do_page_fault(struct pt_regs *regs, unsi
21340 * User-mode registers count as a user access even for any
21341 * potential system fault or CPU buglet:
21342 */
21343 - if (user_mode_vm(regs)) {
21344 + if (user_mode(regs)) {
21345 local_irq_enable();
21346 error_code |= PF_USER;
21347 } else {
21348 @@ -1087,6 +1337,11 @@ retry:
21349 might_sleep();
21350 }
21351
21352 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21353 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21354 + return;
21355 +#endif
21356 +
21357 vma = find_vma(mm, address);
21358 if (unlikely(!vma)) {
21359 bad_area(regs, error_code, address);
21360 @@ -1098,18 +1353,24 @@ retry:
21361 bad_area(regs, error_code, address);
21362 return;
21363 }
21364 - if (error_code & PF_USER) {
21365 - /*
21366 - * Accessing the stack below %sp is always a bug.
21367 - * The large cushion allows instructions like enter
21368 - * and pusha to work. ("enter $65535, $31" pushes
21369 - * 32 pointers and then decrements %sp by 65535.)
21370 - */
21371 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21372 - bad_area(regs, error_code, address);
21373 - return;
21374 - }
21375 + /*
21376 + * Accessing the stack below %sp is always a bug.
21377 + * The large cushion allows instructions like enter
21378 + * and pusha to work. ("enter $65535, $31" pushes
21379 + * 32 pointers and then decrements %sp by 65535.)
21380 + */
21381 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21382 + bad_area(regs, error_code, address);
21383 + return;
21384 }
21385 +
21386 +#ifdef CONFIG_PAX_SEGMEXEC
21387 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21388 + bad_area(regs, error_code, address);
21389 + return;
21390 + }
21391 +#endif
21392 +
21393 if (unlikely(expand_stack(vma, address))) {
21394 bad_area(regs, error_code, address);
21395 return;
21396 @@ -1164,3 +1425,199 @@ good_area:
21397
21398 up_read(&mm->mmap_sem);
21399 }
21400 +
21401 +#ifdef CONFIG_PAX_EMUTRAMP
21402 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21403 +{
21404 + int err;
21405 +
21406 + do { /* PaX: gcc trampoline emulation #1 */
21407 + unsigned char mov1, mov2;
21408 + unsigned short jmp;
21409 + unsigned int addr1, addr2;
21410 +
21411 +#ifdef CONFIG_X86_64
21412 + if ((regs->ip + 11) >> 32)
21413 + break;
21414 +#endif
21415 +
21416 + err = get_user(mov1, (unsigned char __user *)regs->ip);
21417 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21418 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21419 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21420 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21421 +
21422 + if (err)
21423 + break;
21424 +
21425 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21426 + regs->cx = addr1;
21427 + regs->ax = addr2;
21428 + regs->ip = addr2;
21429 + return 2;
21430 + }
21431 + } while (0);
21432 +
21433 + do { /* PaX: gcc trampoline emulation #2 */
21434 + unsigned char mov, jmp;
21435 + unsigned int addr1, addr2;
21436 +
21437 +#ifdef CONFIG_X86_64
21438 + if ((regs->ip + 9) >> 32)
21439 + break;
21440 +#endif
21441 +
21442 + err = get_user(mov, (unsigned char __user *)regs->ip);
21443 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21444 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21445 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21446 +
21447 + if (err)
21448 + break;
21449 +
21450 + if (mov == 0xB9 && jmp == 0xE9) {
21451 + regs->cx = addr1;
21452 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21453 + return 2;
21454 + }
21455 + } while (0);
21456 +
21457 + return 1; /* PaX in action */
21458 +}
21459 +
21460 +#ifdef CONFIG_X86_64
21461 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21462 +{
21463 + int err;
21464 +
21465 + do { /* PaX: gcc trampoline emulation #1 */
21466 + unsigned short mov1, mov2, jmp1;
21467 + unsigned char jmp2;
21468 + unsigned int addr1;
21469 + unsigned long addr2;
21470 +
21471 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21472 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21473 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21474 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21475 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21476 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21477 +
21478 + if (err)
21479 + break;
21480 +
21481 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21482 + regs->r11 = addr1;
21483 + regs->r10 = addr2;
21484 + regs->ip = addr1;
21485 + return 2;
21486 + }
21487 + } while (0);
21488 +
21489 + do { /* PaX: gcc trampoline emulation #2 */
21490 + unsigned short mov1, mov2, jmp1;
21491 + unsigned char jmp2;
21492 + unsigned long addr1, addr2;
21493 +
21494 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21495 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21496 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21497 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21498 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21499 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21500 +
21501 + if (err)
21502 + break;
21503 +
21504 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21505 + regs->r11 = addr1;
21506 + regs->r10 = addr2;
21507 + regs->ip = addr1;
21508 + return 2;
21509 + }
21510 + } while (0);
21511 +
21512 + return 1; /* PaX in action */
21513 +}
21514 +#endif
21515 +
21516 +/*
21517 + * PaX: decide what to do with offenders (regs->ip = fault address)
21518 + *
21519 + * returns 1 when task should be killed
21520 + * 2 when gcc trampoline was detected
21521 + */
21522 +static int pax_handle_fetch_fault(struct pt_regs *regs)
21523 +{
21524 + if (v8086_mode(regs))
21525 + return 1;
21526 +
21527 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21528 + return 1;
21529 +
21530 +#ifdef CONFIG_X86_32
21531 + return pax_handle_fetch_fault_32(regs);
21532 +#else
21533 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21534 + return pax_handle_fetch_fault_32(regs);
21535 + else
21536 + return pax_handle_fetch_fault_64(regs);
21537 +#endif
21538 +}
21539 +#endif
21540 +
21541 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21542 +void pax_report_insns(void *pc, void *sp)
21543 +{
21544 + long i;
21545 +
21546 + printk(KERN_ERR "PAX: bytes at PC: ");
21547 + for (i = 0; i < 20; i++) {
21548 + unsigned char c;
21549 + if (get_user(c, (__force unsigned char __user *)pc+i))
21550 + printk(KERN_CONT "?? ");
21551 + else
21552 + printk(KERN_CONT "%02x ", c);
21553 + }
21554 + printk("\n");
21555 +
21556 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21557 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
21558 + unsigned long c;
21559 + if (get_user(c, (__force unsigned long __user *)sp+i))
21560 +#ifdef CONFIG_X86_32
21561 + printk(KERN_CONT "???????? ");
21562 +#else
21563 + printk(KERN_CONT "???????????????? ");
21564 +#endif
21565 + else
21566 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21567 + }
21568 + printk("\n");
21569 +}
21570 +#endif
21571 +
21572 +/**
21573 + * probe_kernel_write(): safely attempt to write to a location
21574 + * @dst: address to write to
21575 + * @src: pointer to the data that shall be written
21576 + * @size: size of the data chunk
21577 + *
21578 + * Safely write to address @dst from the buffer at @src. If a kernel fault
21579 + * happens, handle that and return -EFAULT.
21580 + */
21581 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21582 +{
21583 + long ret;
21584 + mm_segment_t old_fs = get_fs();
21585 +
21586 + set_fs(KERNEL_DS);
21587 + pagefault_disable();
21588 + pax_open_kernel();
21589 + ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21590 + pax_close_kernel();
21591 + pagefault_enable();
21592 + set_fs(old_fs);
21593 +
21594 + return ret ? -EFAULT : 0;
21595 +}
21596 diff -urNp linux-2.6.39.1/arch/x86/mm/gup.c linux-2.6.39.1/arch/x86/mm/gup.c
21597 --- linux-2.6.39.1/arch/x86/mm/gup.c 2011-05-19 00:06:34.000000000 -0400
21598 +++ linux-2.6.39.1/arch/x86/mm/gup.c 2011-05-22 19:36:30.000000000 -0400
21599 @@ -263,7 +263,7 @@ int __get_user_pages_fast(unsigned long
21600 addr = start;
21601 len = (unsigned long) nr_pages << PAGE_SHIFT;
21602 end = start + len;
21603 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21604 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21605 (void __user *)start, len)))
21606 return 0;
21607
21608 diff -urNp linux-2.6.39.1/arch/x86/mm/highmem_32.c linux-2.6.39.1/arch/x86/mm/highmem_32.c
21609 --- linux-2.6.39.1/arch/x86/mm/highmem_32.c 2011-05-19 00:06:34.000000000 -0400
21610 +++ linux-2.6.39.1/arch/x86/mm/highmem_32.c 2011-05-22 19:36:30.000000000 -0400
21611 @@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
21612 idx = type + KM_TYPE_NR*smp_processor_id();
21613 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21614 BUG_ON(!pte_none(*(kmap_pte-idx)));
21615 +
21616 + pax_open_kernel();
21617 set_pte(kmap_pte-idx, mk_pte(page, prot));
21618 + pax_close_kernel();
21619
21620 return (void *)vaddr;
21621 }
21622 diff -urNp linux-2.6.39.1/arch/x86/mm/hugetlbpage.c linux-2.6.39.1/arch/x86/mm/hugetlbpage.c
21623 --- linux-2.6.39.1/arch/x86/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
21624 +++ linux-2.6.39.1/arch/x86/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
21625 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
21626 struct hstate *h = hstate_file(file);
21627 struct mm_struct *mm = current->mm;
21628 struct vm_area_struct *vma;
21629 - unsigned long start_addr;
21630 + unsigned long start_addr, pax_task_size = TASK_SIZE;
21631 +
21632 +#ifdef CONFIG_PAX_SEGMEXEC
21633 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21634 + pax_task_size = SEGMEXEC_TASK_SIZE;
21635 +#endif
21636 +
21637 + pax_task_size -= PAGE_SIZE;
21638
21639 if (len > mm->cached_hole_size) {
21640 - start_addr = mm->free_area_cache;
21641 + start_addr = mm->free_area_cache;
21642 } else {
21643 - start_addr = TASK_UNMAPPED_BASE;
21644 - mm->cached_hole_size = 0;
21645 + start_addr = mm->mmap_base;
21646 + mm->cached_hole_size = 0;
21647 }
21648
21649 full_search:
21650 @@ -280,26 +287,27 @@ full_search:
21651
21652 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21653 /* At this point: (!vma || addr < vma->vm_end). */
21654 - if (TASK_SIZE - len < addr) {
21655 + if (pax_task_size - len < addr) {
21656 /*
21657 * Start a new search - just in case we missed
21658 * some holes.
21659 */
21660 - if (start_addr != TASK_UNMAPPED_BASE) {
21661 - start_addr = TASK_UNMAPPED_BASE;
21662 + if (start_addr != mm->mmap_base) {
21663 + start_addr = mm->mmap_base;
21664 mm->cached_hole_size = 0;
21665 goto full_search;
21666 }
21667 return -ENOMEM;
21668 }
21669 - if (!vma || addr + len <= vma->vm_start) {
21670 - mm->free_area_cache = addr + len;
21671 - return addr;
21672 - }
21673 + if (check_heap_stack_gap(vma, addr, len))
21674 + break;
21675 if (addr + mm->cached_hole_size < vma->vm_start)
21676 mm->cached_hole_size = vma->vm_start - addr;
21677 addr = ALIGN(vma->vm_end, huge_page_size(h));
21678 }
21679 +
21680 + mm->free_area_cache = addr + len;
21681 + return addr;
21682 }
21683
21684 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21685 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
21686 {
21687 struct hstate *h = hstate_file(file);
21688 struct mm_struct *mm = current->mm;
21689 - struct vm_area_struct *vma, *prev_vma;
21690 - unsigned long base = mm->mmap_base, addr = addr0;
21691 + struct vm_area_struct *vma;
21692 + unsigned long base = mm->mmap_base, addr;
21693 unsigned long largest_hole = mm->cached_hole_size;
21694 - int first_time = 1;
21695
21696 /* don't allow allocations above current base */
21697 if (mm->free_area_cache > base)
21698 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmappe
21699 largest_hole = 0;
21700 mm->free_area_cache = base;
21701 }
21702 -try_again:
21703 +
21704 /* make sure it can fit in the remaining address space */
21705 if (mm->free_area_cache < len)
21706 goto fail;
21707
21708 /* either no address requested or can't fit in requested address hole */
21709 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
21710 + addr = (mm->free_area_cache - len);
21711 do {
21712 + addr &= huge_page_mask(h);
21713 + vma = find_vma(mm, addr);
21714 /*
21715 * Lookup failure means no vma is above this address,
21716 * i.e. return with success:
21717 - */
21718 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21719 - return addr;
21720 -
21721 - /*
21722 * new region fits between prev_vma->vm_end and
21723 * vma->vm_start, use it:
21724 */
21725 - if (addr + len <= vma->vm_start &&
21726 - (!prev_vma || (addr >= prev_vma->vm_end))) {
21727 + if (check_heap_stack_gap(vma, addr, len)) {
21728 /* remember the address as a hint for next time */
21729 - mm->cached_hole_size = largest_hole;
21730 - return (mm->free_area_cache = addr);
21731 - } else {
21732 - /* pull free_area_cache down to the first hole */
21733 - if (mm->free_area_cache == vma->vm_end) {
21734 - mm->free_area_cache = vma->vm_start;
21735 - mm->cached_hole_size = largest_hole;
21736 - }
21737 + mm->cached_hole_size = largest_hole;
21738 + return (mm->free_area_cache = addr);
21739 + }
21740 + /* pull free_area_cache down to the first hole */
21741 + if (mm->free_area_cache == vma->vm_end) {
21742 + mm->free_area_cache = vma->vm_start;
21743 + mm->cached_hole_size = largest_hole;
21744 }
21745
21746 /* remember the largest hole we saw so far */
21747 if (addr + largest_hole < vma->vm_start)
21748 - largest_hole = vma->vm_start - addr;
21749 + largest_hole = vma->vm_start - addr;
21750
21751 /* try just below the current vma->vm_start */
21752 - addr = (vma->vm_start - len) & huge_page_mask(h);
21753 - } while (len <= vma->vm_start);
21754 + addr = skip_heap_stack_gap(vma, len);
21755 + } while (!IS_ERR_VALUE(addr));
21756
21757 fail:
21758 /*
21759 - * if hint left us with no space for the requested
21760 - * mapping then try again:
21761 - */
21762 - if (first_time) {
21763 - mm->free_area_cache = base;
21764 - largest_hole = 0;
21765 - first_time = 0;
21766 - goto try_again;
21767 - }
21768 - /*
21769 * A failed mmap() very likely causes application failure,
21770 * so fall back to the bottom-up function here. This scenario
21771 * can happen with large stack limits and large mmap()
21772 * allocations.
21773 */
21774 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21775 +
21776 +#ifdef CONFIG_PAX_SEGMEXEC
21777 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21778 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21779 + else
21780 +#endif
21781 +
21782 + mm->mmap_base = TASK_UNMAPPED_BASE;
21783 +
21784 +#ifdef CONFIG_PAX_RANDMMAP
21785 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21786 + mm->mmap_base += mm->delta_mmap;
21787 +#endif
21788 +
21789 + mm->free_area_cache = mm->mmap_base;
21790 mm->cached_hole_size = ~0UL;
21791 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21792 len, pgoff, flags);
21793 @@ -386,6 +392,7 @@ fail:
21794 /*
21795 * Restore the topdown base:
21796 */
21797 + mm->mmap_base = base;
21798 mm->free_area_cache = base;
21799 mm->cached_hole_size = ~0UL;
21800
21801 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *f
21802 struct hstate *h = hstate_file(file);
21803 struct mm_struct *mm = current->mm;
21804 struct vm_area_struct *vma;
21805 + unsigned long pax_task_size = TASK_SIZE;
21806
21807 if (len & ~huge_page_mask(h))
21808 return -EINVAL;
21809 - if (len > TASK_SIZE)
21810 +
21811 +#ifdef CONFIG_PAX_SEGMEXEC
21812 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21813 + pax_task_size = SEGMEXEC_TASK_SIZE;
21814 +#endif
21815 +
21816 + pax_task_size -= PAGE_SIZE;
21817 +
21818 + if (len > pax_task_size)
21819 return -ENOMEM;
21820
21821 if (flags & MAP_FIXED) {
21822 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *f
21823 if (addr) {
21824 addr = ALIGN(addr, huge_page_size(h));
21825 vma = find_vma(mm, addr);
21826 - if (TASK_SIZE - len >= addr &&
21827 - (!vma || addr + len <= vma->vm_start))
21828 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21829 return addr;
21830 }
21831 if (mm->get_unmapped_area == arch_get_unmapped_area)
21832 diff -urNp linux-2.6.39.1/arch/x86/mm/init_32.c linux-2.6.39.1/arch/x86/mm/init_32.c
21833 --- linux-2.6.39.1/arch/x86/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
21834 +++ linux-2.6.39.1/arch/x86/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
21835 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
21836 }
21837
21838 /*
21839 - * Creates a middle page table and puts a pointer to it in the
21840 - * given global directory entry. This only returns the gd entry
21841 - * in non-PAE compilation mode, since the middle layer is folded.
21842 - */
21843 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
21844 -{
21845 - pud_t *pud;
21846 - pmd_t *pmd_table;
21847 -
21848 -#ifdef CONFIG_X86_PAE
21849 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21850 - if (after_bootmem)
21851 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21852 - else
21853 - pmd_table = (pmd_t *)alloc_low_page();
21854 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21855 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21856 - pud = pud_offset(pgd, 0);
21857 - BUG_ON(pmd_table != pmd_offset(pud, 0));
21858 -
21859 - return pmd_table;
21860 - }
21861 -#endif
21862 - pud = pud_offset(pgd, 0);
21863 - pmd_table = pmd_offset(pud, 0);
21864 -
21865 - return pmd_table;
21866 -}
21867 -
21868 -/*
21869 * Create a page table and place a pointer to it in a middle page
21870 * directory entry:
21871 */
21872 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_ini
21873 page_table = (pte_t *)alloc_low_page();
21874
21875 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
21876 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21877 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
21878 +#else
21879 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
21880 +#endif
21881 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
21882 }
21883
21884 return pte_offset_kernel(pmd, 0);
21885 }
21886
21887 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
21888 +{
21889 + pud_t *pud;
21890 + pmd_t *pmd_table;
21891 +
21892 + pud = pud_offset(pgd, 0);
21893 + pmd_table = pmd_offset(pud, 0);
21894 +
21895 + return pmd_table;
21896 +}
21897 +
21898 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
21899 {
21900 int pgd_idx = pgd_index(vaddr);
21901 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long star
21902 int pgd_idx, pmd_idx;
21903 unsigned long vaddr;
21904 pgd_t *pgd;
21905 + pud_t *pud;
21906 pmd_t *pmd;
21907 pte_t *pte = NULL;
21908
21909 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long star
21910 pgd = pgd_base + pgd_idx;
21911
21912 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
21913 - pmd = one_md_table_init(pgd);
21914 - pmd = pmd + pmd_index(vaddr);
21915 + pud = pud_offset(pgd, vaddr);
21916 + pmd = pmd_offset(pud, vaddr);
21917 +
21918 +#ifdef CONFIG_X86_PAE
21919 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21920 +#endif
21921 +
21922 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
21923 pmd++, pmd_idx++) {
21924 pte = page_table_kmap_check(one_page_table_init(pmd),
21925 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long star
21926 }
21927 }
21928
21929 -static inline int is_kernel_text(unsigned long addr)
21930 +static inline int is_kernel_text(unsigned long start, unsigned long end)
21931 {
21932 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
21933 - return 1;
21934 - return 0;
21935 + if ((start > ktla_ktva((unsigned long)_etext) ||
21936 + end <= ktla_ktva((unsigned long)_stext)) &&
21937 + (start > ktla_ktva((unsigned long)_einittext) ||
21938 + end <= ktla_ktva((unsigned long)_sinittext)) &&
21939 +
21940 +#ifdef CONFIG_ACPI_SLEEP
21941 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
21942 +#endif
21943 +
21944 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
21945 + return 0;
21946 + return 1;
21947 }
21948
21949 /*
21950 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned lo
21951 unsigned long last_map_addr = end;
21952 unsigned long start_pfn, end_pfn;
21953 pgd_t *pgd_base = swapper_pg_dir;
21954 - int pgd_idx, pmd_idx, pte_ofs;
21955 + unsigned int pgd_idx, pmd_idx, pte_ofs;
21956 unsigned long pfn;
21957 pgd_t *pgd;
21958 + pud_t *pud;
21959 pmd_t *pmd;
21960 pte_t *pte;
21961 unsigned pages_2m, pages_4k;
21962 @@ -281,8 +282,13 @@ repeat:
21963 pfn = start_pfn;
21964 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21965 pgd = pgd_base + pgd_idx;
21966 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
21967 - pmd = one_md_table_init(pgd);
21968 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
21969 + pud = pud_offset(pgd, 0);
21970 + pmd = pmd_offset(pud, 0);
21971 +
21972 +#ifdef CONFIG_X86_PAE
21973 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21974 +#endif
21975
21976 if (pfn >= end_pfn)
21977 continue;
21978 @@ -294,14 +300,13 @@ repeat:
21979 #endif
21980 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
21981 pmd++, pmd_idx++) {
21982 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
21983 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
21984
21985 /*
21986 * Map with big pages if possible, otherwise
21987 * create normal page tables:
21988 */
21989 if (use_pse) {
21990 - unsigned int addr2;
21991 pgprot_t prot = PAGE_KERNEL_LARGE;
21992 /*
21993 * first pass will use the same initial
21994 @@ -311,11 +316,7 @@ repeat:
21995 __pgprot(PTE_IDENT_ATTR |
21996 _PAGE_PSE);
21997
21998 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
21999 - PAGE_OFFSET + PAGE_SIZE-1;
22000 -
22001 - if (is_kernel_text(addr) ||
22002 - is_kernel_text(addr2))
22003 + if (is_kernel_text(address, address + PMD_SIZE))
22004 prot = PAGE_KERNEL_LARGE_EXEC;
22005
22006 pages_2m++;
22007 @@ -332,7 +333,7 @@ repeat:
22008 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22009 pte += pte_ofs;
22010 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22011 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22012 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22013 pgprot_t prot = PAGE_KERNEL;
22014 /*
22015 * first pass will use the same initial
22016 @@ -340,7 +341,7 @@ repeat:
22017 */
22018 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22019
22020 - if (is_kernel_text(addr))
22021 + if (is_kernel_text(address, address + PAGE_SIZE))
22022 prot = PAGE_KERNEL_EXEC;
22023
22024 pages_4k++;
22025 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start
22026
22027 pud = pud_offset(pgd, va);
22028 pmd = pmd_offset(pud, va);
22029 - if (!pmd_present(*pmd))
22030 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22031 break;
22032
22033 pte = pte_offset_kernel(pmd, va);
22034 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_ran
22035
22036 static void __init pagetable_init(void)
22037 {
22038 - pgd_t *pgd_base = swapper_pg_dir;
22039 -
22040 - permanent_kmaps_init(pgd_base);
22041 + permanent_kmaps_init(swapper_pg_dir);
22042 }
22043
22044 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22045 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22046 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22047
22048 /* user-defined highmem size */
22049 @@ -754,6 +753,12 @@ void __init mem_init(void)
22050
22051 pci_iommu_alloc();
22052
22053 +#ifdef CONFIG_PAX_PER_CPU_PGD
22054 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22055 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22056 + KERNEL_PGD_PTRS);
22057 +#endif
22058 +
22059 #ifdef CONFIG_FLATMEM
22060 BUG_ON(!mem_map);
22061 #endif
22062 @@ -771,7 +776,7 @@ void __init mem_init(void)
22063 set_highmem_pages_init();
22064
22065 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22066 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22067 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22068 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22069
22070 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22071 @@ -812,10 +817,10 @@ void __init mem_init(void)
22072 ((unsigned long)&__init_end -
22073 (unsigned long)&__init_begin) >> 10,
22074
22075 - (unsigned long)&_etext, (unsigned long)&_edata,
22076 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22077 + (unsigned long)&_sdata, (unsigned long)&_edata,
22078 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22079
22080 - (unsigned long)&_text, (unsigned long)&_etext,
22081 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22082 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22083
22084 /*
22085 @@ -893,6 +898,7 @@ void set_kernel_text_rw(void)
22086 if (!kernel_set_to_readonly)
22087 return;
22088
22089 + start = ktla_ktva(start);
22090 pr_debug("Set kernel text: %lx - %lx for read write\n",
22091 start, start+size);
22092
22093 @@ -907,6 +913,7 @@ void set_kernel_text_ro(void)
22094 if (!kernel_set_to_readonly)
22095 return;
22096
22097 + start = ktla_ktva(start);
22098 pr_debug("Set kernel text: %lx - %lx for read only\n",
22099 start, start+size);
22100
22101 @@ -935,6 +942,7 @@ void mark_rodata_ro(void)
22102 unsigned long start = PFN_ALIGN(_text);
22103 unsigned long size = PFN_ALIGN(_etext) - start;
22104
22105 + start = ktla_ktva(start);
22106 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22107 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22108 size >> 10);
22109 diff -urNp linux-2.6.39.1/arch/x86/mm/init_64.c linux-2.6.39.1/arch/x86/mm/init_64.c
22110 --- linux-2.6.39.1/arch/x86/mm/init_64.c 2011-05-19 00:06:34.000000000 -0400
22111 +++ linux-2.6.39.1/arch/x86/mm/init_64.c 2011-05-22 19:36:30.000000000 -0400
22112 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpa
22113 * around without checking the pgd every time.
22114 */
22115
22116 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22117 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22118 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22119
22120 int force_personality32;
22121 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long star
22122
22123 for (address = start; address <= end; address += PGDIR_SIZE) {
22124 const pgd_t *pgd_ref = pgd_offset_k(address);
22125 +
22126 +#ifdef CONFIG_PAX_PER_CPU_PGD
22127 + unsigned long cpu;
22128 +#else
22129 struct page *page;
22130 +#endif
22131
22132 if (pgd_none(*pgd_ref))
22133 continue;
22134
22135 spin_lock(&pgd_lock);
22136 +
22137 +#ifdef CONFIG_PAX_PER_CPU_PGD
22138 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22139 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22140 +#else
22141 list_for_each_entry(page, &pgd_list, lru) {
22142 pgd_t *pgd;
22143 spinlock_t *pgt_lock;
22144 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long star
22145 /* the pgt_lock only for Xen */
22146 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22147 spin_lock(pgt_lock);
22148 +#endif
22149
22150 if (pgd_none(*pgd))
22151 set_pgd(pgd, *pgd_ref);
22152 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long star
22153 BUG_ON(pgd_page_vaddr(*pgd)
22154 != pgd_page_vaddr(*pgd_ref));
22155
22156 +#ifndef CONFIG_PAX_PER_CPU_PGD
22157 spin_unlock(pgt_lock);
22158 +#endif
22159 +
22160 }
22161 spin_unlock(&pgd_lock);
22162 }
22163 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
22164 pmd = fill_pmd(pud, vaddr);
22165 pte = fill_pte(pmd, vaddr);
22166
22167 + pax_open_kernel();
22168 set_pte(pte, new_pte);
22169 + pax_close_kernel();
22170
22171 /*
22172 * It's enough to flush this one mapping.
22173 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(
22174 pgd = pgd_offset_k((unsigned long)__va(phys));
22175 if (pgd_none(*pgd)) {
22176 pud = (pud_t *) spp_getpage();
22177 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22178 - _PAGE_USER));
22179 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22180 }
22181 pud = pud_offset(pgd, (unsigned long)__va(phys));
22182 if (pud_none(*pud)) {
22183 pmd = (pmd_t *) spp_getpage();
22184 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22185 - _PAGE_USER));
22186 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22187 }
22188 pmd = pmd_offset(pud, phys);
22189 BUG_ON(!pmd_none(*pmd));
22190 @@ -698,6 +712,12 @@ void __init mem_init(void)
22191
22192 pci_iommu_alloc();
22193
22194 +#ifdef CONFIG_PAX_PER_CPU_PGD
22195 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22196 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22197 + KERNEL_PGD_PTRS);
22198 +#endif
22199 +
22200 /* clear_bss() already clear the empty_zero_page */
22201
22202 reservedpages = 0;
22203 @@ -858,8 +878,8 @@ int kern_addr_valid(unsigned long addr)
22204 static struct vm_area_struct gate_vma = {
22205 .vm_start = VSYSCALL_START,
22206 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22207 - .vm_page_prot = PAGE_READONLY_EXEC,
22208 - .vm_flags = VM_READ | VM_EXEC
22209 + .vm_page_prot = PAGE_READONLY,
22210 + .vm_flags = VM_READ
22211 };
22212
22213 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22214 @@ -893,7 +913,7 @@ int in_gate_area_no_mm(unsigned long add
22215
22216 const char *arch_vma_name(struct vm_area_struct *vma)
22217 {
22218 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22219 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22220 return "[vdso]";
22221 if (vma == &gate_vma)
22222 return "[vsyscall]";
22223 diff -urNp linux-2.6.39.1/arch/x86/mm/init.c linux-2.6.39.1/arch/x86/mm/init.c
22224 --- linux-2.6.39.1/arch/x86/mm/init.c 2011-05-19 00:06:34.000000000 -0400
22225 +++ linux-2.6.39.1/arch/x86/mm/init.c 2011-05-23 19:01:08.000000000 -0400
22226 @@ -33,7 +33,7 @@ int direct_gbpages
22227 static void __init find_early_table_space(unsigned long end, int use_pse,
22228 int use_gbpages)
22229 {
22230 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22231 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22232 phys_addr_t base;
22233
22234 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22235 @@ -315,12 +315,25 @@ unsigned long __init_refok init_memory_m
22236 */
22237 int devmem_is_allowed(unsigned long pagenr)
22238 {
22239 - if (pagenr <= 256)
22240 +#ifndef CONFIG_GRKERNSEC_KMEM
22241 + if (!pagenr)
22242 + return 1;
22243 +#ifdef CONFIG_VM86
22244 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22245 + return 1;
22246 +#endif
22247 +#else
22248 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22249 + return 0;
22250 +#endif
22251 +
22252 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22253 return 1;
22254 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22255 return 0;
22256 if (!page_is_ram(pagenr))
22257 return 1;
22258 +
22259 return 0;
22260 }
22261
22262 @@ -375,6 +388,86 @@ void free_init_pages(char *what, unsigne
22263
22264 void free_initmem(void)
22265 {
22266 +
22267 +#ifdef CONFIG_PAX_KERNEXEC
22268 +#ifdef CONFIG_X86_32
22269 + /* PaX: limit KERNEL_CS to actual size */
22270 + unsigned long addr, limit;
22271 + struct desc_struct d;
22272 + int cpu;
22273 +
22274 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22275 + limit = (limit - 1UL) >> PAGE_SHIFT;
22276 +
22277 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22278 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
22279 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22280 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22281 + }
22282 +
22283 + /* PaX: make KERNEL_CS read-only */
22284 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22285 + if (!paravirt_enabled())
22286 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22287 +/*
22288 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22289 + pgd = pgd_offset_k(addr);
22290 + pud = pud_offset(pgd, addr);
22291 + pmd = pmd_offset(pud, addr);
22292 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22293 + }
22294 +*/
22295 +#ifdef CONFIG_X86_PAE
22296 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22297 +/*
22298 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22299 + pgd = pgd_offset_k(addr);
22300 + pud = pud_offset(pgd, addr);
22301 + pmd = pmd_offset(pud, addr);
22302 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22303 + }
22304 +*/
22305 +#endif
22306 +
22307 +#ifdef CONFIG_MODULES
22308 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22309 +#endif
22310 +
22311 +#else
22312 + pgd_t *pgd;
22313 + pud_t *pud;
22314 + pmd_t *pmd;
22315 + unsigned long addr, end;
22316 +
22317 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22318 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22319 + pgd = pgd_offset_k(addr);
22320 + pud = pud_offset(pgd, addr);
22321 + pmd = pmd_offset(pud, addr);
22322 + if (!pmd_present(*pmd))
22323 + continue;
22324 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22325 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22326 + else
22327 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22328 + }
22329 +
22330 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22331 + end = addr + KERNEL_IMAGE_SIZE;
22332 + for (; addr < end; addr += PMD_SIZE) {
22333 + pgd = pgd_offset_k(addr);
22334 + pud = pud_offset(pgd, addr);
22335 + pmd = pmd_offset(pud, addr);
22336 + if (!pmd_present(*pmd))
22337 + continue;
22338 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22339 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22340 + }
22341 +#endif
22342 +
22343 + flush_tlb_all();
22344 +#endif
22345 +
22346 free_init_pages("unused kernel memory",
22347 (unsigned long)(&__init_begin),
22348 (unsigned long)(&__init_end));
22349 diff -urNp linux-2.6.39.1/arch/x86/mm/iomap_32.c linux-2.6.39.1/arch/x86/mm/iomap_32.c
22350 --- linux-2.6.39.1/arch/x86/mm/iomap_32.c 2011-05-19 00:06:34.000000000 -0400
22351 +++ linux-2.6.39.1/arch/x86/mm/iomap_32.c 2011-05-22 19:36:30.000000000 -0400
22352 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22353 type = kmap_atomic_idx_push();
22354 idx = type + KM_TYPE_NR * smp_processor_id();
22355 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22356 +
22357 + pax_open_kernel();
22358 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22359 + pax_close_kernel();
22360 +
22361 arch_flush_lazy_mmu_mode();
22362
22363 return (void *)vaddr;
22364 diff -urNp linux-2.6.39.1/arch/x86/mm/ioremap.c linux-2.6.39.1/arch/x86/mm/ioremap.c
22365 --- linux-2.6.39.1/arch/x86/mm/ioremap.c 2011-05-19 00:06:34.000000000 -0400
22366 +++ linux-2.6.39.1/arch/x86/mm/ioremap.c 2011-05-22 19:36:30.000000000 -0400
22367 @@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
22368 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22369 int is_ram = page_is_ram(pfn);
22370
22371 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22372 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22373 return NULL;
22374 WARN_ON_ONCE(is_ram);
22375 }
22376 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
22377 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22378
22379 static __initdata int after_paging_init;
22380 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22381 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22382
22383 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22384 {
22385 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22386 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22387
22388 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22389 - memset(bm_pte, 0, sizeof(bm_pte));
22390 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
22391 + pmd_populate_user(&init_mm, pmd, bm_pte);
22392
22393 /*
22394 * The boot-ioremap range spans multiple pmds, for which
22395 diff -urNp linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c
22396 --- linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-19 00:06:34.000000000 -0400
22397 +++ linux-2.6.39.1/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-22 19:36:30.000000000 -0400
22398 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22399 * memory (e.g. tracked pages)? For now, we need this to avoid
22400 * invoking kmemcheck for PnP BIOS calls.
22401 */
22402 - if (regs->flags & X86_VM_MASK)
22403 + if (v8086_mode(regs))
22404 return false;
22405 - if (regs->cs != __KERNEL_CS)
22406 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22407 return false;
22408
22409 pte = kmemcheck_pte_lookup(address);
22410 diff -urNp linux-2.6.39.1/arch/x86/mm/mmap.c linux-2.6.39.1/arch/x86/mm/mmap.c
22411 --- linux-2.6.39.1/arch/x86/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
22412 +++ linux-2.6.39.1/arch/x86/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
22413 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22414 * Leave an at least ~128 MB hole with possible stack randomization.
22415 */
22416 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22417 -#define MAX_GAP (TASK_SIZE/6*5)
22418 +#define MAX_GAP (pax_task_size/6*5)
22419
22420 /*
22421 * True on X86_32 or when emulating IA32 on X86_64
22422 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22423 return rnd << PAGE_SHIFT;
22424 }
22425
22426 -static unsigned long mmap_base(void)
22427 +static unsigned long mmap_base(struct mm_struct *mm)
22428 {
22429 unsigned long gap = rlimit(RLIMIT_STACK);
22430 + unsigned long pax_task_size = TASK_SIZE;
22431 +
22432 +#ifdef CONFIG_PAX_SEGMEXEC
22433 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22434 + pax_task_size = SEGMEXEC_TASK_SIZE;
22435 +#endif
22436
22437 if (gap < MIN_GAP)
22438 gap = MIN_GAP;
22439 else if (gap > MAX_GAP)
22440 gap = MAX_GAP;
22441
22442 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22443 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22444 }
22445
22446 /*
22447 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22448 * does, but not when emulating X86_32
22449 */
22450 -static unsigned long mmap_legacy_base(void)
22451 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
22452 {
22453 - if (mmap_is_ia32())
22454 + if (mmap_is_ia32()) {
22455 +
22456 +#ifdef CONFIG_PAX_SEGMEXEC
22457 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22458 + return SEGMEXEC_TASK_UNMAPPED_BASE;
22459 + else
22460 +#endif
22461 +
22462 return TASK_UNMAPPED_BASE;
22463 - else
22464 + } else
22465 return TASK_UNMAPPED_BASE + mmap_rnd();
22466 }
22467
22468 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22469 void arch_pick_mmap_layout(struct mm_struct *mm)
22470 {
22471 if (mmap_is_legacy()) {
22472 - mm->mmap_base = mmap_legacy_base();
22473 + mm->mmap_base = mmap_legacy_base(mm);
22474 +
22475 +#ifdef CONFIG_PAX_RANDMMAP
22476 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22477 + mm->mmap_base += mm->delta_mmap;
22478 +#endif
22479 +
22480 mm->get_unmapped_area = arch_get_unmapped_area;
22481 mm->unmap_area = arch_unmap_area;
22482 } else {
22483 - mm->mmap_base = mmap_base();
22484 + mm->mmap_base = mmap_base(mm);
22485 +
22486 +#ifdef CONFIG_PAX_RANDMMAP
22487 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22488 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22489 +#endif
22490 +
22491 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22492 mm->unmap_area = arch_unmap_area_topdown;
22493 }
22494 diff -urNp linux-2.6.39.1/arch/x86/mm/mmio-mod.c linux-2.6.39.1/arch/x86/mm/mmio-mod.c
22495 --- linux-2.6.39.1/arch/x86/mm/mmio-mod.c 2011-05-19 00:06:34.000000000 -0400
22496 +++ linux-2.6.39.1/arch/x86/mm/mmio-mod.c 2011-05-22 19:36:30.000000000 -0400
22497 @@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p,
22498 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22499 void __iomem *addr)
22500 {
22501 - static atomic_t next_id;
22502 + static atomic_unchecked_t next_id;
22503 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22504 /* These are page-unaligned. */
22505 struct mmiotrace_map map = {
22506 @@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_
22507 .private = trace
22508 },
22509 .phys = offset,
22510 - .id = atomic_inc_return(&next_id)
22511 + .id = atomic_inc_return_unchecked(&next_id)
22512 };
22513 map.map_id = trace->id;
22514
22515 diff -urNp linux-2.6.39.1/arch/x86/mm/numa_32.c linux-2.6.39.1/arch/x86/mm/numa_32.c
22516 --- linux-2.6.39.1/arch/x86/mm/numa_32.c 2011-05-19 00:06:34.000000000 -0400
22517 +++ linux-2.6.39.1/arch/x86/mm/numa_32.c 2011-05-22 19:36:30.000000000 -0400
22518 @@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
22519 }
22520 #endif
22521
22522 -extern unsigned long find_max_low_pfn(void);
22523 extern unsigned long highend_pfn, highstart_pfn;
22524
22525 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22526 diff -urNp linux-2.6.39.1/arch/x86/mm/pageattr.c linux-2.6.39.1/arch/x86/mm/pageattr.c
22527 --- linux-2.6.39.1/arch/x86/mm/pageattr.c 2011-05-19 00:06:34.000000000 -0400
22528 +++ linux-2.6.39.1/arch/x86/mm/pageattr.c 2011-05-22 19:36:30.000000000 -0400
22529 @@ -261,7 +261,7 @@ static inline pgprot_t static_protection
22530 */
22531 #ifdef CONFIG_PCI_BIOS
22532 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22533 - pgprot_val(forbidden) |= _PAGE_NX;
22534 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22535 #endif
22536
22537 /*
22538 @@ -269,9 +269,10 @@ static inline pgprot_t static_protection
22539 * Does not cover __inittext since that is gone later on. On
22540 * 64bit we do not enforce !NX on the low mapping
22541 */
22542 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
22543 - pgprot_val(forbidden) |= _PAGE_NX;
22544 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22545 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22546
22547 +#ifdef CONFIG_DEBUG_RODATA
22548 /*
22549 * The .rodata section needs to be read-only. Using the pfn
22550 * catches all aliases.
22551 @@ -279,6 +280,7 @@ static inline pgprot_t static_protection
22552 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22553 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22554 pgprot_val(forbidden) |= _PAGE_RW;
22555 +#endif
22556
22557 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
22558 /*
22559 @@ -317,6 +319,13 @@ static inline pgprot_t static_protection
22560 }
22561 #endif
22562
22563 +#ifdef CONFIG_PAX_KERNEXEC
22564 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22565 + pgprot_val(forbidden) |= _PAGE_RW;
22566 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22567 + }
22568 +#endif
22569 +
22570 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22571
22572 return prot;
22573 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22574 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22575 {
22576 /* change init_mm */
22577 + pax_open_kernel();
22578 set_pte_atomic(kpte, pte);
22579 +
22580 #ifdef CONFIG_X86_32
22581 if (!SHARED_KERNEL_PMD) {
22582 +
22583 +#ifdef CONFIG_PAX_PER_CPU_PGD
22584 + unsigned long cpu;
22585 +#else
22586 struct page *page;
22587 +#endif
22588
22589 +#ifdef CONFIG_PAX_PER_CPU_PGD
22590 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22591 + pgd_t *pgd = get_cpu_pgd(cpu);
22592 +#else
22593 list_for_each_entry(page, &pgd_list, lru) {
22594 - pgd_t *pgd;
22595 + pgd_t *pgd = (pgd_t *)page_address(page);
22596 +#endif
22597 +
22598 pud_t *pud;
22599 pmd_t *pmd;
22600
22601 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
22602 + pgd += pgd_index(address);
22603 pud = pud_offset(pgd, address);
22604 pmd = pmd_offset(pud, address);
22605 set_pte_atomic((pte_t *)pmd, pte);
22606 }
22607 }
22608 #endif
22609 + pax_close_kernel();
22610 }
22611
22612 static int
22613 diff -urNp linux-2.6.39.1/arch/x86/mm/pageattr-test.c linux-2.6.39.1/arch/x86/mm/pageattr-test.c
22614 --- linux-2.6.39.1/arch/x86/mm/pageattr-test.c 2011-05-19 00:06:34.000000000 -0400
22615 +++ linux-2.6.39.1/arch/x86/mm/pageattr-test.c 2011-05-22 19:36:30.000000000 -0400
22616 @@ -36,7 +36,7 @@ enum {
22617
22618 static int pte_testbit(pte_t pte)
22619 {
22620 - return pte_flags(pte) & _PAGE_UNUSED1;
22621 + return pte_flags(pte) & _PAGE_CPA_TEST;
22622 }
22623
22624 struct split_state {
22625 diff -urNp linux-2.6.39.1/arch/x86/mm/pat.c linux-2.6.39.1/arch/x86/mm/pat.c
22626 --- linux-2.6.39.1/arch/x86/mm/pat.c 2011-05-19 00:06:34.000000000 -0400
22627 +++ linux-2.6.39.1/arch/x86/mm/pat.c 2011-05-22 19:36:30.000000000 -0400
22628 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
22629
22630 if (!entry) {
22631 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22632 - current->comm, current->pid, start, end);
22633 + current->comm, task_pid_nr(current), start, end);
22634 return -EINVAL;
22635 }
22636
22637 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
22638 while (cursor < to) {
22639 if (!devmem_is_allowed(pfn)) {
22640 printk(KERN_INFO
22641 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22642 - current->comm, from, to);
22643 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22644 + current->comm, from, to, cursor);
22645 return 0;
22646 }
22647 cursor += PAGE_SIZE;
22648 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
22649 printk(KERN_INFO
22650 "%s:%d ioremap_change_attr failed %s "
22651 "for %Lx-%Lx\n",
22652 - current->comm, current->pid,
22653 + current->comm, task_pid_nr(current),
22654 cattr_name(flags),
22655 base, (unsigned long long)(base + size));
22656 return -EINVAL;
22657 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
22658 if (want_flags != flags) {
22659 printk(KERN_WARNING
22660 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
22661 - current->comm, current->pid,
22662 + current->comm, task_pid_nr(current),
22663 cattr_name(want_flags),
22664 (unsigned long long)paddr,
22665 (unsigned long long)(paddr + size),
22666 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
22667 free_memtype(paddr, paddr + size);
22668 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22669 " for %Lx-%Lx, got %s\n",
22670 - current->comm, current->pid,
22671 + current->comm, task_pid_nr(current),
22672 cattr_name(want_flags),
22673 (unsigned long long)paddr,
22674 (unsigned long long)(paddr + size),
22675 diff -urNp linux-2.6.39.1/arch/x86/mm/pgtable_32.c linux-2.6.39.1/arch/x86/mm/pgtable_32.c
22676 --- linux-2.6.39.1/arch/x86/mm/pgtable_32.c 2011-05-19 00:06:34.000000000 -0400
22677 +++ linux-2.6.39.1/arch/x86/mm/pgtable_32.c 2011-05-22 19:36:30.000000000 -0400
22678 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
22679 return;
22680 }
22681 pte = pte_offset_kernel(pmd, vaddr);
22682 +
22683 + pax_open_kernel();
22684 if (pte_val(pteval))
22685 set_pte_at(&init_mm, vaddr, pte, pteval);
22686 else
22687 pte_clear(&init_mm, vaddr, pte);
22688 + pax_close_kernel();
22689
22690 /*
22691 * It's enough to flush this one mapping.
22692 diff -urNp linux-2.6.39.1/arch/x86/mm/pgtable.c linux-2.6.39.1/arch/x86/mm/pgtable.c
22693 --- linux-2.6.39.1/arch/x86/mm/pgtable.c 2011-05-19 00:06:34.000000000 -0400
22694 +++ linux-2.6.39.1/arch/x86/mm/pgtable.c 2011-05-22 19:36:30.000000000 -0400
22695 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *p
22696 list_del(&page->lru);
22697 }
22698
22699 -#define UNSHARED_PTRS_PER_PGD \
22700 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22701 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22702 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22703
22704 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22705 +{
22706 + while (count--)
22707 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22708 +}
22709 +#endif
22710 +
22711 +#ifdef CONFIG_PAX_PER_CPU_PGD
22712 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22713 +{
22714 + while (count--)
22715 +
22716 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22717 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22718 +#else
22719 + *dst++ = *src++;
22720 +#endif
22721
22722 +}
22723 +#endif
22724 +
22725 +#ifdef CONFIG_X86_64
22726 +#define pxd_t pud_t
22727 +#define pyd_t pgd_t
22728 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22729 +#define pxd_free(mm, pud) pud_free((mm), (pud))
22730 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22731 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22732 +#define PYD_SIZE PGDIR_SIZE
22733 +#else
22734 +#define pxd_t pmd_t
22735 +#define pyd_t pud_t
22736 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22737 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
22738 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22739 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
22740 +#define PYD_SIZE PUD_SIZE
22741 +#endif
22742 +
22743 +#ifdef CONFIG_PAX_PER_CPU_PGD
22744 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
22745 +static inline void pgd_dtor(pgd_t *pgd) {}
22746 +#else
22747 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
22748 {
22749 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
22750 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
22751 pgd_list_del(pgd);
22752 spin_unlock(&pgd_lock);
22753 }
22754 +#endif
22755
22756 /*
22757 * List of all pgd's needed for non-PAE so it can invalidate entries
22758 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
22759 * -- wli
22760 */
22761
22762 -#ifdef CONFIG_X86_PAE
22763 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22764 /*
22765 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22766 * updating the top-level pagetable entries to guarantee the
22767 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
22768 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22769 * and initialize the kernel pmds here.
22770 */
22771 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22772 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22773
22774 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22775 {
22776 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm,
22777 */
22778 flush_tlb_mm(mm);
22779 }
22780 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22781 +#define PREALLOCATED_PXDS USER_PGD_PTRS
22782 #else /* !CONFIG_X86_PAE */
22783
22784 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22785 -#define PREALLOCATED_PMDS 0
22786 +#define PREALLOCATED_PXDS 0
22787
22788 #endif /* CONFIG_X86_PAE */
22789
22790 -static void free_pmds(pmd_t *pmds[])
22791 +static void free_pxds(pxd_t *pxds[])
22792 {
22793 int i;
22794
22795 - for(i = 0; i < PREALLOCATED_PMDS; i++)
22796 - if (pmds[i])
22797 - free_page((unsigned long)pmds[i]);
22798 + for(i = 0; i < PREALLOCATED_PXDS; i++)
22799 + if (pxds[i])
22800 + free_page((unsigned long)pxds[i]);
22801 }
22802
22803 -static int preallocate_pmds(pmd_t *pmds[])
22804 +static int preallocate_pxds(pxd_t *pxds[])
22805 {
22806 int i;
22807 bool failed = false;
22808
22809 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
22810 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22811 - if (pmd == NULL)
22812 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
22813 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22814 + if (pxd == NULL)
22815 failed = true;
22816 - pmds[i] = pmd;
22817 + pxds[i] = pxd;
22818 }
22819
22820 if (failed) {
22821 - free_pmds(pmds);
22822 + free_pxds(pxds);
22823 return -ENOMEM;
22824 }
22825
22826 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[
22827 * preallocate which never got a corresponding vma will need to be
22828 * freed manually.
22829 */
22830 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22831 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22832 {
22833 int i;
22834
22835 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
22836 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
22837 pgd_t pgd = pgdp[i];
22838
22839 if (pgd_val(pgd) != 0) {
22840 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22841 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22842
22843 - pgdp[i] = native_make_pgd(0);
22844 + set_pgd(pgdp + i, native_make_pgd(0));
22845
22846 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22847 - pmd_free(mm, pmd);
22848 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22849 + pxd_free(mm, pxd);
22850 }
22851 }
22852 }
22853
22854 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
22855 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
22856 {
22857 - pud_t *pud;
22858 + pyd_t *pyd;
22859 unsigned long addr;
22860 int i;
22861
22862 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
22863 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
22864 return;
22865
22866 - pud = pud_offset(pgd, 0);
22867 +#ifdef CONFIG_X86_64
22868 + pyd = pyd_offset(mm, 0L);
22869 +#else
22870 + pyd = pyd_offset(pgd, 0L);
22871 +#endif
22872
22873 - for (addr = i = 0; i < PREALLOCATED_PMDS;
22874 - i++, pud++, addr += PUD_SIZE) {
22875 - pmd_t *pmd = pmds[i];
22876 + for (addr = i = 0; i < PREALLOCATED_PXDS;
22877 + i++, pyd++, addr += PYD_SIZE) {
22878 + pxd_t *pxd = pxds[i];
22879
22880 if (i >= KERNEL_PGD_BOUNDARY)
22881 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22882 - sizeof(pmd_t) * PTRS_PER_PMD);
22883 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22884 + sizeof(pxd_t) * PTRS_PER_PMD);
22885
22886 - pud_populate(mm, pud, pmd);
22887 + pyd_populate(mm, pyd, pxd);
22888 }
22889 }
22890
22891 pgd_t *pgd_alloc(struct mm_struct *mm)
22892 {
22893 pgd_t *pgd;
22894 - pmd_t *pmds[PREALLOCATED_PMDS];
22895 + pxd_t *pxds[PREALLOCATED_PXDS];
22896
22897 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
22898
22899 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22900
22901 mm->pgd = pgd;
22902
22903 - if (preallocate_pmds(pmds) != 0)
22904 + if (preallocate_pxds(pxds) != 0)
22905 goto out_free_pgd;
22906
22907 if (paravirt_pgd_alloc(mm) != 0)
22908 - goto out_free_pmds;
22909 + goto out_free_pxds;
22910
22911 /*
22912 * Make sure that pre-populating the pmds is atomic with
22913 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22914 spin_lock(&pgd_lock);
22915
22916 pgd_ctor(mm, pgd);
22917 - pgd_prepopulate_pmd(mm, pgd, pmds);
22918 + pgd_prepopulate_pxd(mm, pgd, pxds);
22919
22920 spin_unlock(&pgd_lock);
22921
22922 return pgd;
22923
22924 -out_free_pmds:
22925 - free_pmds(pmds);
22926 +out_free_pxds:
22927 + free_pxds(pxds);
22928 out_free_pgd:
22929 free_page((unsigned long)pgd);
22930 out:
22931 @@ -295,7 +344,7 @@ out:
22932
22933 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
22934 {
22935 - pgd_mop_up_pmds(mm, pgd);
22936 + pgd_mop_up_pxds(mm, pgd);
22937 pgd_dtor(pgd);
22938 paravirt_pgd_free(mm, pgd);
22939 free_page((unsigned long)pgd);
22940 diff -urNp linux-2.6.39.1/arch/x86/mm/setup_nx.c linux-2.6.39.1/arch/x86/mm/setup_nx.c
22941 --- linux-2.6.39.1/arch/x86/mm/setup_nx.c 2011-05-19 00:06:34.000000000 -0400
22942 +++ linux-2.6.39.1/arch/x86/mm/setup_nx.c 2011-05-22 19:36:30.000000000 -0400
22943 @@ -5,8 +5,10 @@
22944 #include <asm/pgtable.h>
22945 #include <asm/proto.h>
22946
22947 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22948 static int disable_nx __cpuinitdata;
22949
22950 +#ifndef CONFIG_PAX_PAGEEXEC
22951 /*
22952 * noexec = on|off
22953 *
22954 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
22955 return 0;
22956 }
22957 early_param("noexec", noexec_setup);
22958 +#endif
22959 +
22960 +#endif
22961
22962 void __cpuinit x86_configure_nx(void)
22963 {
22964 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22965 if (cpu_has_nx && !disable_nx)
22966 __supported_pte_mask |= _PAGE_NX;
22967 else
22968 +#endif
22969 __supported_pte_mask &= ~_PAGE_NX;
22970 }
22971
22972 diff -urNp linux-2.6.39.1/arch/x86/mm/tlb.c linux-2.6.39.1/arch/x86/mm/tlb.c
22973 --- linux-2.6.39.1/arch/x86/mm/tlb.c 2011-05-19 00:06:34.000000000 -0400
22974 +++ linux-2.6.39.1/arch/x86/mm/tlb.c 2011-05-22 19:36:30.000000000 -0400
22975 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
22976 BUG();
22977 cpumask_clear_cpu(cpu,
22978 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
22979 +
22980 +#ifndef CONFIG_PAX_PER_CPU_PGD
22981 load_cr3(swapper_pg_dir);
22982 +#endif
22983 +
22984 }
22985 EXPORT_SYMBOL_GPL(leave_mm);
22986
22987 diff -urNp linux-2.6.39.1/arch/x86/oprofile/backtrace.c linux-2.6.39.1/arch/x86/oprofile/backtrace.c
22988 --- linux-2.6.39.1/arch/x86/oprofile/backtrace.c 2011-05-19 00:06:34.000000000 -0400
22989 +++ linux-2.6.39.1/arch/x86/oprofile/backtrace.c 2011-05-22 19:36:30.000000000 -0400
22990 @@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
22991 struct stack_frame_ia32 *fp;
22992
22993 /* Also check accessibility of one struct frame_head beyond */
22994 - if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
22995 + if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
22996 return NULL;
22997 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
22998 return NULL;
22999 @@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
23000 {
23001 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23002
23003 - if (!user_mode_vm(regs)) {
23004 + if (!user_mode(regs)) {
23005 unsigned long stack = kernel_stack_pointer(regs);
23006 if (depth)
23007 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23008 diff -urNp linux-2.6.39.1/arch/x86/pci/ce4100.c linux-2.6.39.1/arch/x86/pci/ce4100.c
23009 --- linux-2.6.39.1/arch/x86/pci/ce4100.c 2011-05-19 00:06:34.000000000 -0400
23010 +++ linux-2.6.39.1/arch/x86/pci/ce4100.c 2011-05-22 19:36:30.000000000 -0400
23011 @@ -302,7 +302,7 @@ static int ce4100_conf_write(unsigned in
23012 return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
23013 }
23014
23015 -struct pci_raw_ops ce4100_pci_conf = {
23016 +const struct pci_raw_ops ce4100_pci_conf = {
23017 .read = ce4100_conf_read,
23018 .write = ce4100_conf_write,
23019 };
23020 diff -urNp linux-2.6.39.1/arch/x86/pci/common.c linux-2.6.39.1/arch/x86/pci/common.c
23021 --- linux-2.6.39.1/arch/x86/pci/common.c 2011-05-19 00:06:34.000000000 -0400
23022 +++ linux-2.6.39.1/arch/x86/pci/common.c 2011-05-22 19:36:30.000000000 -0400
23023 @@ -33,8 +33,8 @@ int noioapicreroute = 1;
23024 int pcibios_last_bus = -1;
23025 unsigned long pirq_table_addr;
23026 struct pci_bus *pci_root_bus;
23027 -struct pci_raw_ops *raw_pci_ops;
23028 -struct pci_raw_ops *raw_pci_ext_ops;
23029 +const struct pci_raw_ops *raw_pci_ops;
23030 +const struct pci_raw_ops *raw_pci_ext_ops;
23031
23032 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
23033 int reg, int len, u32 *val)
23034 diff -urNp linux-2.6.39.1/arch/x86/pci/direct.c linux-2.6.39.1/arch/x86/pci/direct.c
23035 --- linux-2.6.39.1/arch/x86/pci/direct.c 2011-05-19 00:06:34.000000000 -0400
23036 +++ linux-2.6.39.1/arch/x86/pci/direct.c 2011-05-22 19:36:30.000000000 -0400
23037 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
23038
23039 #undef PCI_CONF1_ADDRESS
23040
23041 -struct pci_raw_ops pci_direct_conf1 = {
23042 +const struct pci_raw_ops pci_direct_conf1 = {
23043 .read = pci_conf1_read,
23044 .write = pci_conf1_write,
23045 };
23046 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
23047
23048 #undef PCI_CONF2_ADDRESS
23049
23050 -struct pci_raw_ops pci_direct_conf2 = {
23051 +const struct pci_raw_ops pci_direct_conf2 = {
23052 .read = pci_conf2_read,
23053 .write = pci_conf2_write,
23054 };
23055 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
23056 * This should be close to trivial, but it isn't, because there are buggy
23057 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
23058 */
23059 -static int __init pci_sanity_check(struct pci_raw_ops *o)
23060 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
23061 {
23062 u32 x = 0;
23063 int year, devfn;
23064 diff -urNp linux-2.6.39.1/arch/x86/pci/fixup.c linux-2.6.39.1/arch/x86/pci/fixup.c
23065 --- linux-2.6.39.1/arch/x86/pci/fixup.c 2011-05-19 00:06:34.000000000 -0400
23066 +++ linux-2.6.39.1/arch/x86/pci/fixup.c 2011-05-22 19:36:30.000000000 -0400
23067 @@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
23068 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
23069 },
23070 },
23071 - { }
23072 + {}
23073 };
23074
23075 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
23076 diff -urNp linux-2.6.39.1/arch/x86/pci/mmconfig_32.c linux-2.6.39.1/arch/x86/pci/mmconfig_32.c
23077 --- linux-2.6.39.1/arch/x86/pci/mmconfig_32.c 2011-05-19 00:06:34.000000000 -0400
23078 +++ linux-2.6.39.1/arch/x86/pci/mmconfig_32.c 2011-05-22 19:36:30.000000000 -0400
23079 @@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
23080 return 0;
23081 }
23082
23083 -static struct pci_raw_ops pci_mmcfg = {
23084 +static const struct pci_raw_ops pci_mmcfg = {
23085 .read = pci_mmcfg_read,
23086 .write = pci_mmcfg_write,
23087 };
23088 diff -urNp linux-2.6.39.1/arch/x86/pci/mmconfig_64.c linux-2.6.39.1/arch/x86/pci/mmconfig_64.c
23089 --- linux-2.6.39.1/arch/x86/pci/mmconfig_64.c 2011-05-19 00:06:34.000000000 -0400
23090 +++ linux-2.6.39.1/arch/x86/pci/mmconfig_64.c 2011-05-22 19:36:30.000000000 -0400
23091 @@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
23092 return 0;
23093 }
23094
23095 -static struct pci_raw_ops pci_mmcfg = {
23096 +static const struct pci_raw_ops pci_mmcfg = {
23097 .read = pci_mmcfg_read,
23098 .write = pci_mmcfg_write,
23099 };
23100 diff -urNp linux-2.6.39.1/arch/x86/pci/mrst.c linux-2.6.39.1/arch/x86/pci/mrst.c
23101 --- linux-2.6.39.1/arch/x86/pci/mrst.c 2011-05-19 00:06:34.000000000 -0400
23102 +++ linux-2.6.39.1/arch/x86/pci/mrst.c 2011-05-22 19:36:30.000000000 -0400
23103 @@ -218,7 +218,7 @@ static int mrst_pci_irq_enable(struct pc
23104 return 0;
23105 }
23106
23107 -struct pci_ops pci_mrst_ops = {
23108 +const struct pci_ops pci_mrst_ops = {
23109 .read = pci_read,
23110 .write = pci_write,
23111 };
23112 diff -urNp linux-2.6.39.1/arch/x86/pci/numaq_32.c linux-2.6.39.1/arch/x86/pci/numaq_32.c
23113 --- linux-2.6.39.1/arch/x86/pci/numaq_32.c 2011-05-19 00:06:34.000000000 -0400
23114 +++ linux-2.6.39.1/arch/x86/pci/numaq_32.c 2011-05-22 19:36:30.000000000 -0400
23115 @@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
23116
23117 #undef PCI_CONF1_MQ_ADDRESS
23118
23119 -static struct pci_raw_ops pci_direct_conf1_mq = {
23120 +static const struct pci_raw_ops pci_direct_conf1_mq = {
23121 .read = pci_conf1_mq_read,
23122 .write = pci_conf1_mq_write
23123 };
23124 diff -urNp linux-2.6.39.1/arch/x86/pci/olpc.c linux-2.6.39.1/arch/x86/pci/olpc.c
23125 --- linux-2.6.39.1/arch/x86/pci/olpc.c 2011-05-19 00:06:34.000000000 -0400
23126 +++ linux-2.6.39.1/arch/x86/pci/olpc.c 2011-05-22 19:36:30.000000000 -0400
23127 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
23128 return 0;
23129 }
23130
23131 -static struct pci_raw_ops pci_olpc_conf = {
23132 +static const struct pci_raw_ops pci_olpc_conf = {
23133 .read = pci_olpc_read,
23134 .write = pci_olpc_write,
23135 };
23136 diff -urNp linux-2.6.39.1/arch/x86/pci/pcbios.c linux-2.6.39.1/arch/x86/pci/pcbios.c
23137 --- linux-2.6.39.1/arch/x86/pci/pcbios.c 2011-05-19 00:06:34.000000000 -0400
23138 +++ linux-2.6.39.1/arch/x86/pci/pcbios.c 2011-05-22 19:36:30.000000000 -0400
23139 @@ -79,50 +79,93 @@ union bios32 {
23140 static struct {
23141 unsigned long address;
23142 unsigned short segment;
23143 -} bios32_indirect = { 0, __KERNEL_CS };
23144 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23145
23146 /*
23147 * Returns the entry point for the given service, NULL on error
23148 */
23149
23150 -static unsigned long bios32_service(unsigned long service)
23151 +static unsigned long __devinit bios32_service(unsigned long service)
23152 {
23153 unsigned char return_code; /* %al */
23154 unsigned long address; /* %ebx */
23155 unsigned long length; /* %ecx */
23156 unsigned long entry; /* %edx */
23157 unsigned long flags;
23158 + struct desc_struct d, *gdt;
23159
23160 local_irq_save(flags);
23161 - __asm__("lcall *(%%edi); cld"
23162 +
23163 + gdt = get_cpu_gdt_table(smp_processor_id());
23164 +
23165 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23166 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23167 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23168 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23169 +
23170 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23171 : "=a" (return_code),
23172 "=b" (address),
23173 "=c" (length),
23174 "=d" (entry)
23175 : "0" (service),
23176 "1" (0),
23177 - "D" (&bios32_indirect));
23178 + "D" (&bios32_indirect),
23179 + "r"(__PCIBIOS_DS)
23180 + : "memory");
23181 +
23182 + pax_open_kernel();
23183 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23184 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23185 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23186 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23187 + pax_close_kernel();
23188 +
23189 local_irq_restore(flags);
23190
23191 switch (return_code) {
23192 - case 0:
23193 - return address + entry;
23194 - case 0x80: /* Not present */
23195 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23196 - return 0;
23197 - default: /* Shouldn't happen */
23198 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23199 - service, return_code);
23200 + case 0: {
23201 + int cpu;
23202 + unsigned char flags;
23203 +
23204 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23205 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23206 + printk(KERN_WARNING "bios32_service: not valid\n");
23207 return 0;
23208 + }
23209 + address = address + PAGE_OFFSET;
23210 + length += 16UL; /* some BIOSs underreport this... */
23211 + flags = 4;
23212 + if (length >= 64*1024*1024) {
23213 + length >>= PAGE_SHIFT;
23214 + flags |= 8;
23215 + }
23216 +
23217 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
23218 + gdt = get_cpu_gdt_table(cpu);
23219 + pack_descriptor(&d, address, length, 0x9b, flags);
23220 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23221 + pack_descriptor(&d, address, length, 0x93, flags);
23222 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23223 + }
23224 + return entry;
23225 + }
23226 + case 0x80: /* Not present */
23227 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23228 + return 0;
23229 + default: /* Shouldn't happen */
23230 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23231 + service, return_code);
23232 + return 0;
23233 }
23234 }
23235
23236 static struct {
23237 unsigned long address;
23238 unsigned short segment;
23239 -} pci_indirect = { 0, __KERNEL_CS };
23240 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23241
23242 -static int pci_bios_present;
23243 +static int pci_bios_present __read_only;
23244
23245 static int __devinit check_pcibios(void)
23246 {
23247 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23248 unsigned long flags, pcibios_entry;
23249
23250 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23251 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23252 + pci_indirect.address = pcibios_entry;
23253
23254 local_irq_save(flags);
23255 - __asm__(
23256 - "lcall *(%%edi); cld\n\t"
23257 + __asm__("movw %w6, %%ds\n\t"
23258 + "lcall *%%ss:(%%edi); cld\n\t"
23259 + "push %%ss\n\t"
23260 + "pop %%ds\n\t"
23261 "jc 1f\n\t"
23262 "xor %%ah, %%ah\n"
23263 "1:"
23264 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23265 "=b" (ebx),
23266 "=c" (ecx)
23267 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23268 - "D" (&pci_indirect)
23269 + "D" (&pci_indirect),
23270 + "r" (__PCIBIOS_DS)
23271 : "memory");
23272 local_irq_restore(flags);
23273
23274 @@ -188,7 +234,10 @@ static int pci_bios_read(unsigned int se
23275
23276 switch (len) {
23277 case 1:
23278 - __asm__("lcall *(%%esi); cld\n\t"
23279 + __asm__("movw %w6, %%ds\n\t"
23280 + "lcall *%%ss:(%%esi); cld\n\t"
23281 + "push %%ss\n\t"
23282 + "pop %%ds\n\t"
23283 "jc 1f\n\t"
23284 "xor %%ah, %%ah\n"
23285 "1:"
23286 @@ -197,7 +246,8 @@ static int pci_bios_read(unsigned int se
23287 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23288 "b" (bx),
23289 "D" ((long)reg),
23290 - "S" (&pci_indirect));
23291 + "S" (&pci_indirect),
23292 + "r" (__PCIBIOS_DS));
23293 /*
23294 * Zero-extend the result beyond 8 bits, do not trust the
23295 * BIOS having done it:
23296 @@ -205,7 +255,10 @@ static int pci_bios_read(unsigned int se
23297 *value &= 0xff;
23298 break;
23299 case 2:
23300 - __asm__("lcall *(%%esi); cld\n\t"
23301 + __asm__("movw %w6, %%ds\n\t"
23302 + "lcall *%%ss:(%%esi); cld\n\t"
23303 + "push %%ss\n\t"
23304 + "pop %%ds\n\t"
23305 "jc 1f\n\t"
23306 "xor %%ah, %%ah\n"
23307 "1:"
23308 @@ -214,7 +267,8 @@ static int pci_bios_read(unsigned int se
23309 : "1" (PCIBIOS_READ_CONFIG_WORD),
23310 "b" (bx),
23311 "D" ((long)reg),
23312 - "S" (&pci_indirect));
23313 + "S" (&pci_indirect),
23314 + "r" (__PCIBIOS_DS));
23315 /*
23316 * Zero-extend the result beyond 16 bits, do not trust the
23317 * BIOS having done it:
23318 @@ -222,7 +276,10 @@ static int pci_bios_read(unsigned int se
23319 *value &= 0xffff;
23320 break;
23321 case 4:
23322 - __asm__("lcall *(%%esi); cld\n\t"
23323 + __asm__("movw %w6, %%ds\n\t"
23324 + "lcall *%%ss:(%%esi); cld\n\t"
23325 + "push %%ss\n\t"
23326 + "pop %%ds\n\t"
23327 "jc 1f\n\t"
23328 "xor %%ah, %%ah\n"
23329 "1:"
23330 @@ -231,7 +288,8 @@ static int pci_bios_read(unsigned int se
23331 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23332 "b" (bx),
23333 "D" ((long)reg),
23334 - "S" (&pci_indirect));
23335 + "S" (&pci_indirect),
23336 + "r" (__PCIBIOS_DS));
23337 break;
23338 }
23339
23340 @@ -254,7 +312,10 @@ static int pci_bios_write(unsigned int s
23341
23342 switch (len) {
23343 case 1:
23344 - __asm__("lcall *(%%esi); cld\n\t"
23345 + __asm__("movw %w6, %%ds\n\t"
23346 + "lcall *%%ss:(%%esi); cld\n\t"
23347 + "push %%ss\n\t"
23348 + "pop %%ds\n\t"
23349 "jc 1f\n\t"
23350 "xor %%ah, %%ah\n"
23351 "1:"
23352 @@ -263,10 +324,14 @@ static int pci_bios_write(unsigned int s
23353 "c" (value),
23354 "b" (bx),
23355 "D" ((long)reg),
23356 - "S" (&pci_indirect));
23357 + "S" (&pci_indirect),
23358 + "r" (__PCIBIOS_DS));
23359 break;
23360 case 2:
23361 - __asm__("lcall *(%%esi); cld\n\t"
23362 + __asm__("movw %w6, %%ds\n\t"
23363 + "lcall *%%ss:(%%esi); cld\n\t"
23364 + "push %%ss\n\t"
23365 + "pop %%ds\n\t"
23366 "jc 1f\n\t"
23367 "xor %%ah, %%ah\n"
23368 "1:"
23369 @@ -275,10 +340,14 @@ static int pci_bios_write(unsigned int s
23370 "c" (value),
23371 "b" (bx),
23372 "D" ((long)reg),
23373 - "S" (&pci_indirect));
23374 + "S" (&pci_indirect),
23375 + "r" (__PCIBIOS_DS));
23376 break;
23377 case 4:
23378 - __asm__("lcall *(%%esi); cld\n\t"
23379 + __asm__("movw %w6, %%ds\n\t"
23380 + "lcall *%%ss:(%%esi); cld\n\t"
23381 + "push %%ss\n\t"
23382 + "pop %%ds\n\t"
23383 "jc 1f\n\t"
23384 "xor %%ah, %%ah\n"
23385 "1:"
23386 @@ -287,7 +356,8 @@ static int pci_bios_write(unsigned int s
23387 "c" (value),
23388 "b" (bx),
23389 "D" ((long)reg),
23390 - "S" (&pci_indirect));
23391 + "S" (&pci_indirect),
23392 + "r" (__PCIBIOS_DS));
23393 break;
23394 }
23395
23396 @@ -301,7 +371,7 @@ static int pci_bios_write(unsigned int s
23397 * Function table for BIOS32 access
23398 */
23399
23400 -static struct pci_raw_ops pci_bios_access = {
23401 +static const struct pci_raw_ops pci_bios_access = {
23402 .read = pci_bios_read,
23403 .write = pci_bios_write
23404 };
23405 @@ -310,7 +380,7 @@ static struct pci_raw_ops pci_bios_acces
23406 * Try to find PCI BIOS.
23407 */
23408
23409 -static struct pci_raw_ops * __devinit pci_find_bios(void)
23410 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
23411 {
23412 union bios32 *check;
23413 unsigned char sum;
23414 @@ -392,10 +462,13 @@ struct irq_routing_table * pcibios_get_i
23415
23416 DBG("PCI: Fetching IRQ routing table... ");
23417 __asm__("push %%es\n\t"
23418 + "movw %w8, %%ds\n\t"
23419 "push %%ds\n\t"
23420 "pop %%es\n\t"
23421 - "lcall *(%%esi); cld\n\t"
23422 + "lcall *%%ss:(%%esi); cld\n\t"
23423 "pop %%es\n\t"
23424 + "push %%ss\n\t"
23425 + "pop %%ds\n"
23426 "jc 1f\n\t"
23427 "xor %%ah, %%ah\n"
23428 "1:"
23429 @@ -406,7 +479,8 @@ struct irq_routing_table * pcibios_get_i
23430 "1" (0),
23431 "D" ((long) &opt),
23432 "S" (&pci_indirect),
23433 - "m" (opt)
23434 + "m" (opt),
23435 + "r" (__PCIBIOS_DS)
23436 : "memory");
23437 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23438 if (ret & 0xff00)
23439 @@ -430,7 +504,10 @@ int pcibios_set_irq_routing(struct pci_d
23440 {
23441 int ret;
23442
23443 - __asm__("lcall *(%%esi); cld\n\t"
23444 + __asm__("movw %w5, %%ds\n\t"
23445 + "lcall *%%ss:(%%esi); cld\n\t"
23446 + "push %%ss\n\t"
23447 + "pop %%ds\n"
23448 "jc 1f\n\t"
23449 "xor %%ah, %%ah\n"
23450 "1:"
23451 @@ -438,7 +515,8 @@ int pcibios_set_irq_routing(struct pci_d
23452 : "0" (PCIBIOS_SET_PCI_HW_INT),
23453 "b" ((dev->bus->number << 8) | dev->devfn),
23454 "c" ((irq << 8) | (pin + 10)),
23455 - "S" (&pci_indirect));
23456 + "S" (&pci_indirect),
23457 + "r" (__PCIBIOS_DS));
23458 return !(ret & 0xff00);
23459 }
23460 EXPORT_SYMBOL(pcibios_set_irq_routing);
23461 diff -urNp linux-2.6.39.1/arch/x86/pci/xen.c linux-2.6.39.1/arch/x86/pci/xen.c
23462 --- linux-2.6.39.1/arch/x86/pci/xen.c 2011-05-19 00:06:34.000000000 -0400
23463 +++ linux-2.6.39.1/arch/x86/pci/xen.c 2011-05-22 19:36:30.000000000 -0400
23464 @@ -62,7 +62,7 @@ static int acpi_register_gsi_xen_hvm(str
23465 #include <linux/msi.h>
23466 #include <asm/msidef.h>
23467
23468 -struct xen_pci_frontend_ops *xen_pci_frontend;
23469 +const struct xen_pci_frontend_ops *xen_pci_frontend;
23470 EXPORT_SYMBOL_GPL(xen_pci_frontend);
23471
23472 #define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
23473 diff -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
23474 --- linux-2.6.39.1/arch/x86/platform/efi/efi_32.c 2011-05-19 00:06:34.000000000 -0400
23475 +++ linux-2.6.39.1/arch/x86/platform/efi/efi_32.c 2011-05-22 19:36:30.000000000 -0400
23476 @@ -38,70 +38,37 @@
23477 */
23478
23479 static unsigned long efi_rt_eflags;
23480 -static pgd_t efi_bak_pg_dir_pointer[2];
23481 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
23482
23483 -void efi_call_phys_prelog(void)
23484 +void __init efi_call_phys_prelog(void)
23485 {
23486 - unsigned long cr4;
23487 - unsigned long temp;
23488 struct desc_ptr gdt_descr;
23489
23490 local_irq_save(efi_rt_eflags);
23491
23492 - /*
23493 - * If I don't have PAE, I should just duplicate two entries in page
23494 - * directory. If I have PAE, I just need to duplicate one entry in
23495 - * page directory.
23496 - */
23497 - cr4 = read_cr4_safe();
23498 -
23499 - if (cr4 & X86_CR4_PAE) {
23500 - efi_bak_pg_dir_pointer[0].pgd =
23501 - swapper_pg_dir[pgd_index(0)].pgd;
23502 - swapper_pg_dir[0].pgd =
23503 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23504 - } else {
23505 - efi_bak_pg_dir_pointer[0].pgd =
23506 - swapper_pg_dir[pgd_index(0)].pgd;
23507 - efi_bak_pg_dir_pointer[1].pgd =
23508 - swapper_pg_dir[pgd_index(0x400000)].pgd;
23509 - swapper_pg_dir[pgd_index(0)].pgd =
23510 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23511 - temp = PAGE_OFFSET + 0x400000;
23512 - swapper_pg_dir[pgd_index(0x400000)].pgd =
23513 - swapper_pg_dir[pgd_index(temp)].pgd;
23514 - }
23515 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
23516 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23517 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
23518
23519 /*
23520 * After the lock is released, the original page table is restored.
23521 */
23522 __flush_tlb_all();
23523
23524 - gdt_descr.address = __pa(get_cpu_gdt_table(0));
23525 + gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
23526 gdt_descr.size = GDT_SIZE - 1;
23527 load_gdt(&gdt_descr);
23528 }
23529
23530 -void efi_call_phys_epilog(void)
23531 +void __init efi_call_phys_epilog(void)
23532 {
23533 - unsigned long cr4;
23534 struct desc_ptr gdt_descr;
23535
23536 - gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
23537 + gdt_descr.address = get_cpu_gdt_table(0);
23538 gdt_descr.size = GDT_SIZE - 1;
23539 load_gdt(&gdt_descr);
23540
23541 - cr4 = read_cr4_safe();
23542 -
23543 - if (cr4 & X86_CR4_PAE) {
23544 - swapper_pg_dir[pgd_index(0)].pgd =
23545 - efi_bak_pg_dir_pointer[0].pgd;
23546 - } else {
23547 - swapper_pg_dir[pgd_index(0)].pgd =
23548 - efi_bak_pg_dir_pointer[0].pgd;
23549 - swapper_pg_dir[pgd_index(0x400000)].pgd =
23550 - efi_bak_pg_dir_pointer[1].pgd;
23551 - }
23552 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
23553
23554 /*
23555 * After the lock is released, the original page table is restored.
23556 diff -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
23557 --- linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S 2011-05-19 00:06:34.000000000 -0400
23558 +++ linux-2.6.39.1/arch/x86/platform/efi/efi_stub_32.S 2011-05-22 19:36:30.000000000 -0400
23559 @@ -6,6 +6,7 @@
23560 */
23561
23562 #include <linux/linkage.h>
23563 +#include <linux/init.h>
23564 #include <asm/page_types.h>
23565
23566 /*
23567 @@ -20,7 +21,7 @@
23568 * service functions will comply with gcc calling convention, too.
23569 */
23570
23571 -.text
23572 +__INIT
23573 ENTRY(efi_call_phys)
23574 /*
23575 * 0. The function can only be called in Linux kernel. So CS has been
23576 @@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
23577 * The mapping of lower virtual memory has been created in prelog and
23578 * epilog.
23579 */
23580 - movl $1f, %edx
23581 - subl $__PAGE_OFFSET, %edx
23582 - jmp *%edx
23583 + jmp 1f-__PAGE_OFFSET
23584 1:
23585
23586 /*
23587 @@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
23588 * parameter 2, ..., param n. To make things easy, we save the return
23589 * address of efi_call_phys in a global variable.
23590 */
23591 - popl %edx
23592 - movl %edx, saved_return_addr
23593 - /* get the function pointer into ECX*/
23594 - popl %ecx
23595 - movl %ecx, efi_rt_function_ptr
23596 - movl $2f, %edx
23597 - subl $__PAGE_OFFSET, %edx
23598 - pushl %edx
23599 + popl (saved_return_addr)
23600 + popl (efi_rt_function_ptr)
23601
23602 /*
23603 * 3. Clear PG bit in %CR0.
23604 @@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
23605 /*
23606 * 5. Call the physical function.
23607 */
23608 - jmp *%ecx
23609 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
23610
23611 -2:
23612 /*
23613 * 6. After EFI runtime service returns, control will return to
23614 * following instruction. We'd better readjust stack pointer first.
23615 @@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
23616 movl %cr0, %edx
23617 orl $0x80000000, %edx
23618 movl %edx, %cr0
23619 - jmp 1f
23620 -1:
23621 +
23622 /*
23623 * 8. Now restore the virtual mode from flat mode by
23624 * adding EIP with PAGE_OFFSET.
23625 */
23626 - movl $1f, %edx
23627 - jmp *%edx
23628 + jmp 1f+__PAGE_OFFSET
23629 1:
23630
23631 /*
23632 * 9. Balance the stack. And because EAX contain the return value,
23633 * we'd better not clobber it.
23634 */
23635 - leal efi_rt_function_ptr, %edx
23636 - movl (%edx), %ecx
23637 - pushl %ecx
23638 + pushl (efi_rt_function_ptr)
23639
23640 /*
23641 - * 10. Push the saved return address onto the stack and return.
23642 + * 10. Return to the saved return address.
23643 */
23644 - leal saved_return_addr, %edx
23645 - movl (%edx), %ecx
23646 - pushl %ecx
23647 - ret
23648 + jmpl *(saved_return_addr)
23649 ENDPROC(efi_call_phys)
23650 .previous
23651
23652 -.data
23653 +__INITDATA
23654 saved_return_addr:
23655 .long 0
23656 efi_rt_function_ptr:
23657 diff -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
23658 --- linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c 2011-05-19 00:06:34.000000000 -0400
23659 +++ linux-2.6.39.1/arch/x86/platform/olpc/olpc_dt.c 2011-05-22 19:36:30.000000000 -0400
23660 @@ -154,7 +154,7 @@ void * __init prom_early_alloc(unsigned
23661 return res;
23662 }
23663
23664 -static struct of_pdt_ops prom_olpc_ops __initdata = {
23665 +static const struct of_pdt_ops prom_olpc_ops = {
23666 .nextprop = olpc_dt_nextprop,
23667 .getproplen = olpc_dt_getproplen,
23668 .getproperty = olpc_dt_getproperty,
23669 diff -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
23670 --- linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c 2011-05-19 00:06:34.000000000 -0400
23671 +++ linux-2.6.39.1/arch/x86/platform/uv/tlb_uv.c 2011-05-22 19:36:30.000000000 -0400
23672 @@ -342,6 +342,8 @@ static void uv_reset_with_ipi(struct bau
23673 cpumask_t mask;
23674 struct reset_args reset_args;
23675
23676 + pax_track_stack();
23677 +
23678 reset_args.sender = sender;
23679
23680 cpus_clear(mask);
23681 diff -urNp linux-2.6.39.1/arch/x86/power/cpu.c linux-2.6.39.1/arch/x86/power/cpu.c
23682 --- linux-2.6.39.1/arch/x86/power/cpu.c 2011-05-19 00:06:34.000000000 -0400
23683 +++ linux-2.6.39.1/arch/x86/power/cpu.c 2011-05-22 19:36:30.000000000 -0400
23684 @@ -130,7 +130,7 @@ static void do_fpu_end(void)
23685 static void fix_processor_context(void)
23686 {
23687 int cpu = smp_processor_id();
23688 - struct tss_struct *t = &per_cpu(init_tss, cpu);
23689 + struct tss_struct *t = init_tss + cpu;
23690
23691 set_tss_desc(cpu, t); /*
23692 * This just modifies memory; should not be
23693 @@ -140,7 +140,9 @@ static void fix_processor_context(void)
23694 */
23695
23696 #ifdef CONFIG_X86_64
23697 + pax_open_kernel();
23698 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23699 + pax_close_kernel();
23700
23701 syscall_init(); /* This sets MSR_*STAR and related */
23702 #endif
23703 diff -urNp linux-2.6.39.1/arch/x86/vdso/Makefile linux-2.6.39.1/arch/x86/vdso/Makefile
23704 --- linux-2.6.39.1/arch/x86/vdso/Makefile 2011-05-19 00:06:34.000000000 -0400
23705 +++ linux-2.6.39.1/arch/x86/vdso/Makefile 2011-05-22 19:36:30.000000000 -0400
23706 @@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
23707 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
23708 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
23709
23710 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23711 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23712 GCOV_PROFILE := n
23713
23714 #
23715 diff -urNp linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c
23716 --- linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c 2011-05-19 00:06:34.000000000 -0400
23717 +++ linux-2.6.39.1/arch/x86/vdso/vclock_gettime.c 2011-05-22 19:36:30.000000000 -0400
23718 @@ -22,24 +22,48 @@
23719 #include <asm/hpet.h>
23720 #include <asm/unistd.h>
23721 #include <asm/io.h>
23722 +#include <asm/fixmap.h>
23723 #include "vextern.h"
23724
23725 #define gtod vdso_vsyscall_gtod_data
23726
23727 +notrace noinline long __vdso_fallback_time(long *t)
23728 +{
23729 + long secs;
23730 + asm volatile("syscall"
23731 + : "=a" (secs)
23732 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23733 + return secs;
23734 +}
23735 +
23736 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23737 {
23738 long ret;
23739 asm("syscall" : "=a" (ret) :
23740 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23741 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23742 return ret;
23743 }
23744
23745 +notrace static inline cycle_t __vdso_vread_hpet(void)
23746 +{
23747 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23748 +}
23749 +
23750 +notrace static inline cycle_t __vdso_vread_tsc(void)
23751 +{
23752 + cycle_t ret = (cycle_t)vget_cycles();
23753 +
23754 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23755 +}
23756 +
23757 notrace static inline long vgetns(void)
23758 {
23759 long v;
23760 - cycles_t (*vread)(void);
23761 - vread = gtod->clock.vread;
23762 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23763 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23764 + v = __vdso_vread_tsc();
23765 + else
23766 + v = __vdso_vread_hpet();
23767 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23768 return (v * gtod->clock.mult) >> gtod->clock.shift;
23769 }
23770
23771 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23772
23773 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23774 {
23775 - if (likely(gtod->sysctl_enabled))
23776 + if (likely(gtod->sysctl_enabled &&
23777 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23778 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23779 switch (clock) {
23780 case CLOCK_REALTIME:
23781 if (likely(gtod->clock.vread))
23782 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23783 int clock_gettime(clockid_t, struct timespec *)
23784 __attribute__((weak, alias("__vdso_clock_gettime")));
23785
23786 -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23787 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23788 {
23789 long ret;
23790 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23791 + asm("syscall" : "=a" (ret) :
23792 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23793 + return ret;
23794 +}
23795 +
23796 +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23797 +{
23798 + if (likely(gtod->sysctl_enabled &&
23799 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23800 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23801 + {
23802 if (likely(tv != NULL)) {
23803 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23804 offsetof(struct timespec, tv_nsec) ||
23805 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23806 }
23807 return 0;
23808 }
23809 - asm("syscall" : "=a" (ret) :
23810 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23811 - return ret;
23812 + return __vdso_fallback_gettimeofday(tv, tz);
23813 }
23814 int gettimeofday(struct timeval *, struct timezone *)
23815 __attribute__((weak, alias("__vdso_gettimeofday")));
23816 diff -urNp linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c
23817 --- linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c 2011-05-19 00:06:34.000000000 -0400
23818 +++ linux-2.6.39.1/arch/x86/vdso/vdso32-setup.c 2011-05-22 19:36:30.000000000 -0400
23819 @@ -25,6 +25,7 @@
23820 #include <asm/tlbflush.h>
23821 #include <asm/vdso.h>
23822 #include <asm/proto.h>
23823 +#include <asm/mman.h>
23824
23825 enum {
23826 VDSO_DISABLED = 0,
23827 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23828 void enable_sep_cpu(void)
23829 {
23830 int cpu = get_cpu();
23831 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
23832 + struct tss_struct *tss = init_tss + cpu;
23833
23834 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23835 put_cpu();
23836 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23837 gate_vma.vm_start = FIXADDR_USER_START;
23838 gate_vma.vm_end = FIXADDR_USER_END;
23839 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23840 - gate_vma.vm_page_prot = __P101;
23841 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23842 /*
23843 * Make sure the vDSO gets into every core dump.
23844 * Dumping its contents makes post-mortem fully interpretable later
23845 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23846 if (compat)
23847 addr = VDSO_HIGH_BASE;
23848 else {
23849 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23850 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23851 if (IS_ERR_VALUE(addr)) {
23852 ret = addr;
23853 goto up_fail;
23854 }
23855 }
23856
23857 - current->mm->context.vdso = (void *)addr;
23858 + current->mm->context.vdso = addr;
23859
23860 if (compat_uses_vma || !compat) {
23861 /*
23862 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
23863 }
23864
23865 current_thread_info()->sysenter_return =
23866 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23867 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23868
23869 up_fail:
23870 if (ret)
23871 - current->mm->context.vdso = NULL;
23872 + current->mm->context.vdso = 0;
23873
23874 up_write(&mm->mmap_sem);
23875
23876 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
23877
23878 const char *arch_vma_name(struct vm_area_struct *vma)
23879 {
23880 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23881 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23882 return "[vdso]";
23883 +
23884 +#ifdef CONFIG_PAX_SEGMEXEC
23885 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
23886 + return "[vdso]";
23887 +#endif
23888 +
23889 return NULL;
23890 }
23891
23892 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
23893 * Check to see if the corresponding task was created in compat vdso
23894 * mode.
23895 */
23896 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
23897 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
23898 return &gate_vma;
23899 return NULL;
23900 }
23901 diff -urNp linux-2.6.39.1/arch/x86/vdso/vdso.lds.S linux-2.6.39.1/arch/x86/vdso/vdso.lds.S
23902 --- linux-2.6.39.1/arch/x86/vdso/vdso.lds.S 2011-05-19 00:06:34.000000000 -0400
23903 +++ linux-2.6.39.1/arch/x86/vdso/vdso.lds.S 2011-05-22 19:36:30.000000000 -0400
23904 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
23905 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
23906 #include "vextern.h"
23907 #undef VEXTERN
23908 +
23909 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
23910 +VEXTERN(fallback_gettimeofday)
23911 +VEXTERN(fallback_time)
23912 +VEXTERN(getcpu)
23913 +#undef VEXTERN
23914 diff -urNp linux-2.6.39.1/arch/x86/vdso/vextern.h linux-2.6.39.1/arch/x86/vdso/vextern.h
23915 --- linux-2.6.39.1/arch/x86/vdso/vextern.h 2011-05-19 00:06:34.000000000 -0400
23916 +++ linux-2.6.39.1/arch/x86/vdso/vextern.h 2011-05-22 19:36:30.000000000 -0400
23917 @@ -11,6 +11,5 @@
23918 put into vextern.h and be referenced as a pointer with vdso prefix.
23919 The main kernel later fills in the values. */
23920
23921 -VEXTERN(jiffies)
23922 VEXTERN(vgetcpu_mode)
23923 VEXTERN(vsyscall_gtod_data)
23924 diff -urNp linux-2.6.39.1/arch/x86/vdso/vma.c linux-2.6.39.1/arch/x86/vdso/vma.c
23925 --- linux-2.6.39.1/arch/x86/vdso/vma.c 2011-05-19 00:06:34.000000000 -0400
23926 +++ linux-2.6.39.1/arch/x86/vdso/vma.c 2011-05-22 19:36:30.000000000 -0400
23927 @@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
23928 if (!vbase)
23929 goto oom;
23930
23931 - if (memcmp(vbase, "\177ELF", 4)) {
23932 + if (memcmp(vbase, ELFMAG, SELFMAG)) {
23933 printk("VDSO: I'm broken; not ELF\n");
23934 vdso_enabled = 0;
23935 }
23936 @@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
23937 goto up_fail;
23938 }
23939
23940 - current->mm->context.vdso = (void *)addr;
23941 + current->mm->context.vdso = addr;
23942
23943 ret = install_special_mapping(mm, addr, vdso_size,
23944 VM_READ|VM_EXEC|
23945 @@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
23946 VM_ALWAYSDUMP,
23947 vdso_pages);
23948 if (ret) {
23949 - current->mm->context.vdso = NULL;
23950 + current->mm->context.vdso = 0;
23951 goto up_fail;
23952 }
23953
23954 @@ -134,10 +134,3 @@ up_fail:
23955 up_write(&mm->mmap_sem);
23956 return ret;
23957 }
23958 -
23959 -static __init int vdso_setup(char *s)
23960 -{
23961 - vdso_enabled = simple_strtoul(s, NULL, 0);
23962 - return 0;
23963 -}
23964 -__setup("vdso=", vdso_setup);
23965 diff -urNp linux-2.6.39.1/arch/x86/xen/enlighten.c linux-2.6.39.1/arch/x86/xen/enlighten.c
23966 --- linux-2.6.39.1/arch/x86/xen/enlighten.c 2011-05-19 00:06:34.000000000 -0400
23967 +++ linux-2.6.39.1/arch/x86/xen/enlighten.c 2011-05-22 19:36:30.000000000 -0400
23968 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
23969
23970 struct shared_info xen_dummy_shared_info;
23971
23972 -void *xen_initial_gdt;
23973 -
23974 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
23975 __read_mostly int xen_have_vector_callback;
23976 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
23977 @@ -1010,7 +1008,7 @@ static const struct pv_apic_ops xen_apic
23978 #endif
23979 };
23980
23981 -static void xen_reboot(int reason)
23982 +static __noreturn void xen_reboot(int reason)
23983 {
23984 struct sched_shutdown r = { .reason = reason };
23985
23986 @@ -1018,17 +1016,17 @@ static void xen_reboot(int reason)
23987 BUG();
23988 }
23989
23990 -static void xen_restart(char *msg)
23991 +static __noreturn void xen_restart(char *msg)
23992 {
23993 xen_reboot(SHUTDOWN_reboot);
23994 }
23995
23996 -static void xen_emergency_restart(void)
23997 +static __noreturn void xen_emergency_restart(void)
23998 {
23999 xen_reboot(SHUTDOWN_reboot);
24000 }
24001
24002 -static void xen_machine_halt(void)
24003 +static __noreturn void xen_machine_halt(void)
24004 {
24005 xen_reboot(SHUTDOWN_poweroff);
24006 }
24007 @@ -1127,7 +1125,17 @@ asmlinkage void __init xen_start_kernel(
24008 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24009
24010 /* Work out if we support NX */
24011 - x86_configure_nx();
24012 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24013 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24014 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24015 + unsigned l, h;
24016 +
24017 + __supported_pte_mask |= _PAGE_NX;
24018 + rdmsr(MSR_EFER, l, h);
24019 + l |= EFER_NX;
24020 + wrmsr(MSR_EFER, l, h);
24021 + }
24022 +#endif
24023
24024 xen_setup_features();
24025
24026 @@ -1158,13 +1166,6 @@ asmlinkage void __init xen_start_kernel(
24027
24028 machine_ops = xen_machine_ops;
24029
24030 - /*
24031 - * The only reliable way to retain the initial address of the
24032 - * percpu gdt_page is to remember it here, so we can go and
24033 - * mark it RW later, when the initial percpu area is freed.
24034 - */
24035 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24036 -
24037 xen_smp_init();
24038
24039 #ifdef CONFIG_ACPI_NUMA
24040 diff -urNp linux-2.6.39.1/arch/x86/xen/mmu.c linux-2.6.39.1/arch/x86/xen/mmu.c
24041 --- linux-2.6.39.1/arch/x86/xen/mmu.c 2011-06-03 00:04:13.000000000 -0400
24042 +++ linux-2.6.39.1/arch/x86/xen/mmu.c 2011-06-03 00:32:05.000000000 -0400
24043 @@ -1791,6 +1791,8 @@ __init pgd_t *xen_setup_kernel_pagetable
24044 convert_pfn_mfn(init_level4_pgt);
24045 convert_pfn_mfn(level3_ident_pgt);
24046 convert_pfn_mfn(level3_kernel_pgt);
24047 + convert_pfn_mfn(level3_vmalloc_pgt);
24048 + convert_pfn_mfn(level3_vmemmap_pgt);
24049
24050 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24051 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24052 @@ -1809,7 +1811,10 @@ __init pgd_t *xen_setup_kernel_pagetable
24053 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24054 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24055 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24056 + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
24057 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24058 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24059 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24060 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24061 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24062
24063 diff -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
24064 --- linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c 2011-05-19 00:06:34.000000000 -0400
24065 +++ linux-2.6.39.1/arch/x86/xen/pci-swiotlb-xen.c 2011-05-22 19:36:30.000000000 -0400
24066 @@ -10,7 +10,7 @@
24067
24068 int xen_swiotlb __read_mostly;
24069
24070 -static struct dma_map_ops xen_swiotlb_dma_ops = {
24071 +static const struct dma_map_ops xen_swiotlb_dma_ops = {
24072 .mapping_error = xen_swiotlb_dma_mapping_error,
24073 .alloc_coherent = xen_swiotlb_alloc_coherent,
24074 .free_coherent = xen_swiotlb_free_coherent,
24075 diff -urNp linux-2.6.39.1/arch/x86/xen/smp.c linux-2.6.39.1/arch/x86/xen/smp.c
24076 --- linux-2.6.39.1/arch/x86/xen/smp.c 2011-05-19 00:06:34.000000000 -0400
24077 +++ linux-2.6.39.1/arch/x86/xen/smp.c 2011-05-22 19:36:30.000000000 -0400
24078 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
24079 {
24080 BUG_ON(smp_processor_id() != 0);
24081 native_smp_prepare_boot_cpu();
24082 -
24083 - /* We've switched to the "real" per-cpu gdt, so make sure the
24084 - old memory can be recycled */
24085 - make_lowmem_page_readwrite(xen_initial_gdt);
24086 -
24087 xen_filter_cpu_maps();
24088 xen_setup_vcpu_info_placement();
24089 }
24090 @@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
24091 gdt = get_cpu_gdt_table(cpu);
24092
24093 ctxt->flags = VGCF_IN_KERNEL;
24094 - ctxt->user_regs.ds = __USER_DS;
24095 - ctxt->user_regs.es = __USER_DS;
24096 + ctxt->user_regs.ds = __KERNEL_DS;
24097 + ctxt->user_regs.es = __KERNEL_DS;
24098 ctxt->user_regs.ss = __KERNEL_DS;
24099 #ifdef CONFIG_X86_32
24100 ctxt->user_regs.fs = __KERNEL_PERCPU;
24101 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24102 + savesegment(gs, ctxt->user_regs.gs);
24103 #else
24104 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24105 #endif
24106 @@ -315,13 +310,12 @@ static int __cpuinit xen_cpu_up(unsigned
24107 int rc;
24108
24109 per_cpu(current_task, cpu) = idle;
24110 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24111 #ifdef CONFIG_X86_32
24112 irq_ctx_init(cpu);
24113 #else
24114 clear_tsk_thread_flag(idle, TIF_FORK);
24115 - per_cpu(kernel_stack, cpu) =
24116 - (unsigned long)task_stack_page(idle) -
24117 - KERNEL_STACK_OFFSET + THREAD_SIZE;
24118 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24119 #endif
24120 xen_setup_runstate_info(cpu);
24121 xen_setup_timer(cpu);
24122 diff -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
24123 --- linux-2.6.39.1/arch/x86/xen/xen-asm_32.S 2011-05-19 00:06:34.000000000 -0400
24124 +++ linux-2.6.39.1/arch/x86/xen/xen-asm_32.S 2011-05-22 19:36:30.000000000 -0400
24125 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
24126 ESP_OFFSET=4 # bytes pushed onto stack
24127
24128 /*
24129 - * Store vcpu_info pointer for easy access. Do it this way to
24130 - * avoid having to reload %fs
24131 + * Store vcpu_info pointer for easy access.
24132 */
24133 #ifdef CONFIG_SMP
24134 - GET_THREAD_INFO(%eax)
24135 - movl TI_cpu(%eax), %eax
24136 - movl __per_cpu_offset(,%eax,4), %eax
24137 - mov xen_vcpu(%eax), %eax
24138 + push %fs
24139 + mov $(__KERNEL_PERCPU), %eax
24140 + mov %eax, %fs
24141 + mov PER_CPU_VAR(xen_vcpu), %eax
24142 + pop %fs
24143 #else
24144 movl xen_vcpu, %eax
24145 #endif
24146 diff -urNp linux-2.6.39.1/arch/x86/xen/xen-head.S linux-2.6.39.1/arch/x86/xen/xen-head.S
24147 --- linux-2.6.39.1/arch/x86/xen/xen-head.S 2011-05-19 00:06:34.000000000 -0400
24148 +++ linux-2.6.39.1/arch/x86/xen/xen-head.S 2011-05-22 19:36:30.000000000 -0400
24149 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
24150 #ifdef CONFIG_X86_32
24151 mov %esi,xen_start_info
24152 mov $init_thread_union+THREAD_SIZE,%esp
24153 +#ifdef CONFIG_SMP
24154 + movl $cpu_gdt_table,%edi
24155 + movl $__per_cpu_load,%eax
24156 + movw %ax,__KERNEL_PERCPU + 2(%edi)
24157 + rorl $16,%eax
24158 + movb %al,__KERNEL_PERCPU + 4(%edi)
24159 + movb %ah,__KERNEL_PERCPU + 7(%edi)
24160 + movl $__per_cpu_end - 1,%eax
24161 + subl $__per_cpu_start,%eax
24162 + movw %ax,__KERNEL_PERCPU + 0(%edi)
24163 +#endif
24164 #else
24165 mov %rsi,xen_start_info
24166 mov $init_thread_union+THREAD_SIZE,%rsp
24167 diff -urNp linux-2.6.39.1/arch/x86/xen/xen-ops.h linux-2.6.39.1/arch/x86/xen/xen-ops.h
24168 --- linux-2.6.39.1/arch/x86/xen/xen-ops.h 2011-05-19 00:06:34.000000000 -0400
24169 +++ linux-2.6.39.1/arch/x86/xen/xen-ops.h 2011-05-22 19:36:30.000000000 -0400
24170 @@ -10,8 +10,6 @@
24171 extern const char xen_hypervisor_callback[];
24172 extern const char xen_failsafe_callback[];
24173
24174 -extern void *xen_initial_gdt;
24175 -
24176 struct trap_info;
24177 void xen_copy_trap_info(struct trap_info *traps);
24178
24179 diff -urNp linux-2.6.39.1/block/blk-iopoll.c linux-2.6.39.1/block/blk-iopoll.c
24180 --- linux-2.6.39.1/block/blk-iopoll.c 2011-05-19 00:06:34.000000000 -0400
24181 +++ linux-2.6.39.1/block/blk-iopoll.c 2011-05-22 19:36:30.000000000 -0400
24182 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
24183 }
24184 EXPORT_SYMBOL(blk_iopoll_complete);
24185
24186 -static void blk_iopoll_softirq(struct softirq_action *h)
24187 +static void blk_iopoll_softirq(void)
24188 {
24189 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24190 int rearm = 0, budget = blk_iopoll_budget;
24191 diff -urNp linux-2.6.39.1/block/blk-map.c linux-2.6.39.1/block/blk-map.c
24192 --- linux-2.6.39.1/block/blk-map.c 2011-05-19 00:06:34.000000000 -0400
24193 +++ linux-2.6.39.1/block/blk-map.c 2011-05-22 19:36:30.000000000 -0400
24194 @@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
24195 if (!len || !kbuf)
24196 return -EINVAL;
24197
24198 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24199 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24200 if (do_copy)
24201 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24202 else
24203 diff -urNp linux-2.6.39.1/block/blk-softirq.c linux-2.6.39.1/block/blk-softirq.c
24204 --- linux-2.6.39.1/block/blk-softirq.c 2011-05-19 00:06:34.000000000 -0400
24205 +++ linux-2.6.39.1/block/blk-softirq.c 2011-05-22 19:36:30.000000000 -0400
24206 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
24207 * Softirq action handler - move entries to local list and loop over them
24208 * while passing them to the queue registered handler.
24209 */
24210 -static void blk_done_softirq(struct softirq_action *h)
24211 +static void blk_done_softirq(void)
24212 {
24213 struct list_head *cpu_list, local_list;
24214
24215 diff -urNp linux-2.6.39.1/block/bsg.c linux-2.6.39.1/block/bsg.c
24216 --- linux-2.6.39.1/block/bsg.c 2011-05-19 00:06:34.000000000 -0400
24217 +++ linux-2.6.39.1/block/bsg.c 2011-05-22 19:36:30.000000000 -0400
24218 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
24219 struct sg_io_v4 *hdr, struct bsg_device *bd,
24220 fmode_t has_write_perm)
24221 {
24222 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24223 + unsigned char *cmdptr;
24224 +
24225 if (hdr->request_len > BLK_MAX_CDB) {
24226 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24227 if (!rq->cmd)
24228 return -ENOMEM;
24229 - }
24230 + cmdptr = rq->cmd;
24231 + } else
24232 + cmdptr = tmpcmd;
24233
24234 - if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
24235 + if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
24236 hdr->request_len))
24237 return -EFAULT;
24238
24239 + if (cmdptr != rq->cmd)
24240 + memcpy(rq->cmd, cmdptr, hdr->request_len);
24241 +
24242 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24243 if (blk_verify_command(rq->cmd, has_write_perm))
24244 return -EPERM;
24245 diff -urNp linux-2.6.39.1/block/scsi_ioctl.c linux-2.6.39.1/block/scsi_ioctl.c
24246 --- linux-2.6.39.1/block/scsi_ioctl.c 2011-05-19 00:06:34.000000000 -0400
24247 +++ linux-2.6.39.1/block/scsi_ioctl.c 2011-05-22 19:36:30.000000000 -0400
24248 @@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
24249 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24250 struct sg_io_hdr *hdr, fmode_t mode)
24251 {
24252 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24253 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24254 + unsigned char *cmdptr;
24255 +
24256 + if (rq->cmd != rq->__cmd)
24257 + cmdptr = rq->cmd;
24258 + else
24259 + cmdptr = tmpcmd;
24260 +
24261 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24262 return -EFAULT;
24263 +
24264 + if (cmdptr != rq->cmd)
24265 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24266 +
24267 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24268 return -EPERM;
24269
24270 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *
24271 int err;
24272 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24273 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24274 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24275 + unsigned char *cmdptr;
24276
24277 if (!sic)
24278 return -EINVAL;
24279 @@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *
24280 */
24281 err = -EFAULT;
24282 rq->cmd_len = cmdlen;
24283 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
24284 +
24285 + if (rq->cmd != rq->__cmd)
24286 + cmdptr = rq->cmd;
24287 + else
24288 + cmdptr = tmpcmd;
24289 +
24290 + if (copy_from_user(cmdptr, sic->data, cmdlen))
24291 goto error;
24292
24293 + if (rq->cmd != cmdptr)
24294 + memcpy(rq->cmd, cmdptr, cmdlen);
24295 +
24296 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
24297 goto error;
24298
24299 diff -urNp linux-2.6.39.1/crypto/serpent.c linux-2.6.39.1/crypto/serpent.c
24300 --- linux-2.6.39.1/crypto/serpent.c 2011-05-19 00:06:34.000000000 -0400
24301 +++ linux-2.6.39.1/crypto/serpent.c 2011-05-22 19:36:30.000000000 -0400
24302 @@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24303 u32 r0,r1,r2,r3,r4;
24304 int i;
24305
24306 + pax_track_stack();
24307 +
24308 /* Copy key, add padding */
24309
24310 for (i = 0; i < keylen; ++i)
24311 diff -urNp linux-2.6.39.1/Documentation/dontdiff linux-2.6.39.1/Documentation/dontdiff
24312 --- linux-2.6.39.1/Documentation/dontdiff 2011-05-19 00:06:34.000000000 -0400
24313 +++ linux-2.6.39.1/Documentation/dontdiff 2011-05-22 19:36:30.000000000 -0400
24314 @@ -1,13 +1,16 @@
24315 *.a
24316 *.aux
24317 *.bin
24318 +*.cis
24319 *.cpio
24320 *.csp
24321 +*.dbg
24322 *.dsp
24323 *.dvi
24324 *.elf
24325 *.eps
24326 *.fw
24327 +*.gcno
24328 *.gen.S
24329 *.gif
24330 *.grep
24331 @@ -38,8 +41,10 @@
24332 *.tab.h
24333 *.tex
24334 *.ver
24335 +*.vim
24336 *.xml
24337 *_MODULES
24338 +*_reg_safe.h
24339 *_vga16.c
24340 *~
24341 *.9
24342 @@ -49,11 +54,16 @@
24343 53c700_d.h
24344 CVS
24345 ChangeSet
24346 +GPATH
24347 +GRTAGS
24348 +GSYMS
24349 +GTAGS
24350 Image
24351 Kerntypes
24352 Module.markers
24353 Module.symvers
24354 PENDING
24355 +PERF*
24356 SCCS
24357 System.map*
24358 TAGS
24359 @@ -80,8 +90,11 @@ btfixupprep
24360 build
24361 bvmlinux
24362 bzImage*
24363 +capability_names.h
24364 capflags.c
24365 classlist.h*
24366 +clut_vga16.c
24367 +common-cmds.h
24368 comp*.log
24369 compile.h*
24370 conf
24371 @@ -106,16 +119,19 @@ fore200e_mkfirm
24372 fore200e_pca_fw.c*
24373 gconf
24374 gen-devlist
24375 +gen-kdb_cmds.c
24376 gen_crc32table
24377 gen_init_cpio
24378 generated
24379 genheaders
24380 genksyms
24381 *_gray256.c
24382 +hash
24383 ihex2fw
24384 ikconfig.h*
24385 inat-tables.c
24386 initramfs_data.cpio
24387 +initramfs_data.cpio.bz2
24388 initramfs_data.cpio.gz
24389 initramfs_list
24390 int16.c
24391 @@ -125,7 +141,6 @@ int32.c
24392 int4.c
24393 int8.c
24394 kallsyms
24395 -kconfig
24396 keywords.c
24397 ksym.c*
24398 ksym.h*
24399 @@ -149,7 +164,9 @@ mkboot
24400 mkbugboot
24401 mkcpustr
24402 mkdep
24403 +mkpiggy
24404 mkprep
24405 +mkregtable
24406 mktables
24407 mktree
24408 modpost
24409 @@ -165,6 +182,7 @@ parse.h
24410 patches*
24411 pca200e.bin
24412 pca200e_ecd.bin2
24413 +perf-archive
24414 piggy.gz
24415 piggyback
24416 piggy.S
24417 @@ -180,7 +198,9 @@ r600_reg_safe.h
24418 raid6altivec*.c
24419 raid6int*.c
24420 raid6tables.c
24421 +regdb.c
24422 relocs
24423 +rlim_names.h
24424 rn50_reg_safe.h
24425 rs600_reg_safe.h
24426 rv515_reg_safe.h
24427 @@ -189,6 +209,7 @@ setup
24428 setup.bin
24429 setup.elf
24430 sImage
24431 +slabinfo
24432 sm_tbl*
24433 split-include
24434 syscalltab.h
24435 @@ -213,13 +234,17 @@ version.h*
24436 vmlinux
24437 vmlinux-*
24438 vmlinux.aout
24439 +vmlinux.bin.all
24440 +vmlinux.bin.bz2
24441 vmlinux.lds
24442 +vmlinux.relocs
24443 voffset.h
24444 vsyscall.lds
24445 vsyscall_32.lds
24446 wanxlfw.inc
24447 uImage
24448 unifdef
24449 +utsrelease.h
24450 wakeup.bin
24451 wakeup.elf
24452 wakeup.lds
24453 diff -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
24454 --- linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-19 00:06:34.000000000 -0400
24455 +++ linux-2.6.39.1/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-22 19:36:30.000000000 -0400
24456 @@ -368,7 +368,7 @@ static struct configfs_item_operations g
24457 * Note that, since no extra work is required on ->drop_item(),
24458 * no ->drop_item() is provided.
24459 */
24460 -static struct configfs_group_operations group_children_group_ops = {
24461 +static const struct configfs_group_operations group_children_group_ops = {
24462 .make_group = group_children_make_group,
24463 };
24464
24465 diff -urNp linux-2.6.39.1/Documentation/filesystems/sysfs.txt linux-2.6.39.1/Documentation/filesystems/sysfs.txt
24466 --- linux-2.6.39.1/Documentation/filesystems/sysfs.txt 2011-05-19 00:06:34.000000000 -0400
24467 +++ linux-2.6.39.1/Documentation/filesystems/sysfs.txt 2011-05-22 19:36:30.000000000 -0400
24468 @@ -125,8 +125,8 @@ set of sysfs operations for forwarding r
24469 show and store methods of the attribute owners.
24470
24471 struct sysfs_ops {
24472 - ssize_t (*show)(struct kobject *, struct attribute *, char *);
24473 - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
24474 + ssize_t (* const show)(struct kobject *, struct attribute *, char *);
24475 + ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
24476 };
24477
24478 [ Subsystems should have already defined a struct kobj_type as a
24479 diff -urNp linux-2.6.39.1/Documentation/kernel-parameters.txt linux-2.6.39.1/Documentation/kernel-parameters.txt
24480 --- linux-2.6.39.1/Documentation/kernel-parameters.txt 2011-05-19 00:06:34.000000000 -0400
24481 +++ linux-2.6.39.1/Documentation/kernel-parameters.txt 2011-05-22 19:36:30.000000000 -0400
24482 @@ -1879,6 +1879,13 @@ bytes respectively. Such letter suffixes
24483 the specified number of seconds. This is to be used if
24484 your oopses keep scrolling off the screen.
24485
24486 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24487 + virtualization environments that don't cope well with the
24488 + expand down segment used by UDEREF on X86-32 or the frequent
24489 + page table updates on X86-64.
24490 +
24491 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24492 +
24493 pcbit= [HW,ISDN]
24494
24495 pcd. [PARIDE]
24496 diff -urNp linux-2.6.39.1/drivers/acpi/acpi_ipmi.c linux-2.6.39.1/drivers/acpi/acpi_ipmi.c
24497 --- linux-2.6.39.1/drivers/acpi/acpi_ipmi.c 2011-05-19 00:06:34.000000000 -0400
24498 +++ linux-2.6.39.1/drivers/acpi/acpi_ipmi.c 2011-05-22 19:36:30.000000000 -0400
24499 @@ -70,7 +70,7 @@ struct acpi_ipmi_device {
24500 struct ipmi_driver_data {
24501 struct list_head ipmi_devices;
24502 struct ipmi_smi_watcher bmc_events;
24503 - struct ipmi_user_hndl ipmi_hndlrs;
24504 + const struct ipmi_user_hndl ipmi_hndlrs;
24505 struct mutex ipmi_lock;
24506 };
24507
24508 diff -urNp linux-2.6.39.1/drivers/acpi/apei/cper.c linux-2.6.39.1/drivers/acpi/apei/cper.c
24509 --- linux-2.6.39.1/drivers/acpi/apei/cper.c 2011-05-19 00:06:34.000000000 -0400
24510 +++ linux-2.6.39.1/drivers/acpi/apei/cper.c 2011-05-22 19:36:30.000000000 -0400
24511 @@ -38,12 +38,12 @@
24512 */
24513 u64 cper_next_record_id(void)
24514 {
24515 - static atomic64_t seq;
24516 + static atomic64_unchecked_t seq;
24517
24518 - if (!atomic64_read(&seq))
24519 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
24520 + if (!atomic64_read_unchecked(&seq))
24521 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
24522
24523 - return atomic64_inc_return(&seq);
24524 + return atomic64_inc_return_unchecked(&seq);
24525 }
24526 EXPORT_SYMBOL_GPL(cper_next_record_id);
24527
24528 diff -urNp linux-2.6.39.1/drivers/acpi/battery.c linux-2.6.39.1/drivers/acpi/battery.c
24529 --- linux-2.6.39.1/drivers/acpi/battery.c 2011-05-19 00:06:34.000000000 -0400
24530 +++ linux-2.6.39.1/drivers/acpi/battery.c 2011-05-22 19:36:30.000000000 -0400
24531 @@ -864,7 +864,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24532 }
24533
24534 static struct battery_file {
24535 - struct file_operations ops;
24536 + const struct file_operations ops;
24537 mode_t mode;
24538 const char *name;
24539 } acpi_battery_file[] = {
24540 diff -urNp linux-2.6.39.1/drivers/acpi/dock.c linux-2.6.39.1/drivers/acpi/dock.c
24541 --- linux-2.6.39.1/drivers/acpi/dock.c 2011-05-19 00:06:34.000000000 -0400
24542 +++ linux-2.6.39.1/drivers/acpi/dock.c 2011-05-22 19:36:30.000000000 -0400
24543 @@ -77,7 +77,7 @@ struct dock_dependent_device {
24544 struct list_head list;
24545 struct list_head hotplug_list;
24546 acpi_handle handle;
24547 - struct acpi_dock_ops *ops;
24548 + const struct acpi_dock_ops *ops;
24549 void *context;
24550 };
24551
24552 @@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24553 * the dock driver after _DCK is executed.
24554 */
24555 int
24556 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24557 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24558 void *context)
24559 {
24560 struct dock_dependent_device *dd;
24561 diff -urNp linux-2.6.39.1/drivers/acpi/ec_sys.c linux-2.6.39.1/drivers/acpi/ec_sys.c
24562 --- linux-2.6.39.1/drivers/acpi/ec_sys.c 2011-05-19 00:06:34.000000000 -0400
24563 +++ linux-2.6.39.1/drivers/acpi/ec_sys.c 2011-05-22 19:36:30.000000000 -0400
24564 @@ -92,7 +92,7 @@ static ssize_t acpi_ec_write_io(struct f
24565 return count;
24566 }
24567
24568 -static struct file_operations acpi_ec_io_ops = {
24569 +static const struct file_operations acpi_ec_io_ops = {
24570 .owner = THIS_MODULE,
24571 .open = acpi_ec_open_io,
24572 .read = acpi_ec_read_io,
24573 diff -urNp linux-2.6.39.1/drivers/acpi/fan.c linux-2.6.39.1/drivers/acpi/fan.c
24574 --- linux-2.6.39.1/drivers/acpi/fan.c 2011-05-19 00:06:34.000000000 -0400
24575 +++ linux-2.6.39.1/drivers/acpi/fan.c 2011-05-22 19:36:30.000000000 -0400
24576 @@ -110,7 +110,7 @@ fan_set_cur_state(struct thermal_cooling
24577 return result;
24578 }
24579
24580 -static struct thermal_cooling_device_ops fan_cooling_ops = {
24581 +static const struct thermal_cooling_device_ops fan_cooling_ops = {
24582 .get_max_state = fan_get_max_state,
24583 .get_cur_state = fan_get_cur_state,
24584 .set_cur_state = fan_set_cur_state,
24585 diff -urNp linux-2.6.39.1/drivers/acpi/power_meter.c linux-2.6.39.1/drivers/acpi/power_meter.c
24586 --- linux-2.6.39.1/drivers/acpi/power_meter.c 2011-05-19 00:06:34.000000000 -0400
24587 +++ linux-2.6.39.1/drivers/acpi/power_meter.c 2011-05-22 19:36:30.000000000 -0400
24588 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
24589 return res;
24590
24591 temp /= 1000;
24592 - if (temp < 0)
24593 - return -EINVAL;
24594
24595 mutex_lock(&resource->lock);
24596 resource->trip[attr->index - 7] = temp;
24597 diff -urNp linux-2.6.39.1/drivers/acpi/proc.c linux-2.6.39.1/drivers/acpi/proc.c
24598 --- linux-2.6.39.1/drivers/acpi/proc.c 2011-05-19 00:06:34.000000000 -0400
24599 +++ linux-2.6.39.1/drivers/acpi/proc.c 2011-05-22 19:36:30.000000000 -0400
24600 @@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct f
24601 size_t count, loff_t * ppos)
24602 {
24603 struct list_head *node, *next;
24604 - char strbuf[5];
24605 - char str[5] = "";
24606 - unsigned int len = count;
24607 -
24608 - if (len > 4)
24609 - len = 4;
24610 - if (len < 0)
24611 - return -EFAULT;
24612 + char strbuf[5] = {0};
24613
24614 - if (copy_from_user(strbuf, buffer, len))
24615 + if (count > 4)
24616 + count = 4;
24617 + if (copy_from_user(strbuf, buffer, count))
24618 return -EFAULT;
24619 - strbuf[len] = '\0';
24620 - sscanf(strbuf, "%s", str);
24621 + strbuf[count] = '\0';
24622
24623 mutex_lock(&acpi_device_lock);
24624 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24625 @@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct f
24626 if (!dev->wakeup.flags.valid)
24627 continue;
24628
24629 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
24630 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24631 if (device_can_wakeup(&dev->dev)) {
24632 bool enable = !device_may_wakeup(&dev->dev);
24633 device_set_wakeup_enable(&dev->dev, enable);
24634 diff -urNp linux-2.6.39.1/drivers/acpi/processor_driver.c linux-2.6.39.1/drivers/acpi/processor_driver.c
24635 --- linux-2.6.39.1/drivers/acpi/processor_driver.c 2011-05-19 00:06:34.000000000 -0400
24636 +++ linux-2.6.39.1/drivers/acpi/processor_driver.c 2011-05-22 19:36:30.000000000 -0400
24637 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(
24638 return 0;
24639 #endif
24640
24641 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24642 + BUG_ON(pr->id >= nr_cpu_ids);
24643
24644 /*
24645 * Buggy BIOS check
24646 diff -urNp linux-2.6.39.1/drivers/acpi/processor_idle.c linux-2.6.39.1/drivers/acpi/processor_idle.c
24647 --- linux-2.6.39.1/drivers/acpi/processor_idle.c 2011-05-19 00:06:34.000000000 -0400
24648 +++ linux-2.6.39.1/drivers/acpi/processor_idle.c 2011-05-22 19:36:30.000000000 -0400
24649 @@ -121,7 +121,7 @@ static struct dmi_system_id __cpuinitdat
24650 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
24651 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
24652 (void *)1},
24653 - {},
24654 + {}
24655 };
24656
24657
24658 diff -urNp linux-2.6.39.1/drivers/acpi/processor_thermal.c linux-2.6.39.1/drivers/acpi/processor_thermal.c
24659 --- linux-2.6.39.1/drivers/acpi/processor_thermal.c 2011-05-19 00:06:34.000000000 -0400
24660 +++ linux-2.6.39.1/drivers/acpi/processor_thermal.c 2011-05-22 19:36:30.000000000 -0400
24661 @@ -244,7 +244,7 @@ processor_set_cur_state(struct thermal_c
24662 return result;
24663 }
24664
24665 -struct thermal_cooling_device_ops processor_cooling_ops = {
24666 +const struct thermal_cooling_device_ops processor_cooling_ops = {
24667 .get_max_state = processor_get_max_state,
24668 .get_cur_state = processor_get_cur_state,
24669 .set_cur_state = processor_set_cur_state,
24670 diff -urNp linux-2.6.39.1/drivers/acpi/sysfs.c linux-2.6.39.1/drivers/acpi/sysfs.c
24671 --- linux-2.6.39.1/drivers/acpi/sysfs.c 2011-05-19 00:06:34.000000000 -0400
24672 +++ linux-2.6.39.1/drivers/acpi/sysfs.c 2011-05-22 19:36:30.000000000 -0400
24673 @@ -149,12 +149,12 @@ static int param_get_debug_level(char *b
24674 return result;
24675 }
24676
24677 -static struct kernel_param_ops param_ops_debug_layer = {
24678 +static const struct kernel_param_ops param_ops_debug_layer = {
24679 .set = param_set_uint,
24680 .get = param_get_debug_layer,
24681 };
24682
24683 -static struct kernel_param_ops param_ops_debug_level = {
24684 +static const struct kernel_param_ops param_ops_debug_level = {
24685 .set = param_set_uint,
24686 .get = param_get_debug_level,
24687 };
24688 diff -urNp linux-2.6.39.1/drivers/acpi/thermal.c linux-2.6.39.1/drivers/acpi/thermal.c
24689 --- linux-2.6.39.1/drivers/acpi/thermal.c 2011-05-19 00:06:34.000000000 -0400
24690 +++ linux-2.6.39.1/drivers/acpi/thermal.c 2011-05-22 19:36:30.000000000 -0400
24691 @@ -812,7 +812,7 @@ acpi_thermal_unbind_cooling_device(struc
24692 thermal_zone_unbind_cooling_device);
24693 }
24694
24695 -static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24696 +static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24697 .bind = acpi_thermal_bind_cooling_device,
24698 .unbind = acpi_thermal_unbind_cooling_device,
24699 .get_temp = thermal_get_temp,
24700 diff -urNp linux-2.6.39.1/drivers/acpi/video.c linux-2.6.39.1/drivers/acpi/video.c
24701 --- linux-2.6.39.1/drivers/acpi/video.c 2011-05-19 00:06:34.000000000 -0400
24702 +++ linux-2.6.39.1/drivers/acpi/video.c 2011-05-22 19:36:30.000000000 -0400
24703 @@ -308,7 +308,7 @@ video_set_cur_state(struct thermal_cooli
24704 return acpi_video_device_lcd_set_level(video, level);
24705 }
24706
24707 -static struct thermal_cooling_device_ops video_cooling_ops = {
24708 +static const struct thermal_cooling_device_ops video_cooling_ops = {
24709 .get_max_state = video_get_max_state,
24710 .get_cur_state = video_get_cur_state,
24711 .set_cur_state = video_set_cur_state,
24712 diff -urNp linux-2.6.39.1/drivers/ata/acard-ahci.c linux-2.6.39.1/drivers/ata/acard-ahci.c
24713 --- linux-2.6.39.1/drivers/ata/acard-ahci.c 2011-05-19 00:06:34.000000000 -0400
24714 +++ linux-2.6.39.1/drivers/ata/acard-ahci.c 2011-05-22 19:36:30.000000000 -0400
24715 @@ -87,7 +87,7 @@ static struct scsi_host_template acard_a
24716 AHCI_SHT("acard-ahci"),
24717 };
24718
24719 -static struct ata_port_operations acard_ops = {
24720 +static const struct ata_port_operations acard_ops = {
24721 .inherits = &ahci_ops,
24722 .qc_prep = acard_ahci_qc_prep,
24723 .qc_fill_rtf = acard_ahci_qc_fill_rtf,
24724 diff -urNp linux-2.6.39.1/drivers/ata/ahci.c linux-2.6.39.1/drivers/ata/ahci.c
24725 --- linux-2.6.39.1/drivers/ata/ahci.c 2011-05-19 00:06:34.000000000 -0400
24726 +++ linux-2.6.39.1/drivers/ata/ahci.c 2011-05-22 19:36:30.000000000 -0400
24727 @@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
24728 AHCI_SHT("ahci"),
24729 };
24730
24731 -static struct ata_port_operations ahci_vt8251_ops = {
24732 +static const struct ata_port_operations ahci_vt8251_ops = {
24733 .inherits = &ahci_ops,
24734 .hardreset = ahci_vt8251_hardreset,
24735 };
24736
24737 -static struct ata_port_operations ahci_p5wdh_ops = {
24738 +static const struct ata_port_operations ahci_p5wdh_ops = {
24739 .inherits = &ahci_ops,
24740 .hardreset = ahci_p5wdh_hardreset,
24741 };
24742
24743 -static struct ata_port_operations ahci_sb600_ops = {
24744 +static const struct ata_port_operations ahci_sb600_ops = {
24745 .inherits = &ahci_ops,
24746 .softreset = ahci_sb600_softreset,
24747 .pmp_softreset = ahci_sb600_softreset,
24748 diff -urNp linux-2.6.39.1/drivers/ata/ahci.h linux-2.6.39.1/drivers/ata/ahci.h
24749 --- linux-2.6.39.1/drivers/ata/ahci.h 2011-05-19 00:06:34.000000000 -0400
24750 +++ linux-2.6.39.1/drivers/ata/ahci.h 2011-05-22 19:36:30.000000000 -0400
24751 @@ -311,7 +311,7 @@ extern struct device_attribute *ahci_sde
24752 .shost_attrs = ahci_shost_attrs, \
24753 .sdev_attrs = ahci_sdev_attrs
24754
24755 -extern struct ata_port_operations ahci_ops;
24756 +extern const struct ata_port_operations ahci_ops;
24757
24758 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
24759 u32 opts);
24760 diff -urNp linux-2.6.39.1/drivers/ata/ata_generic.c linux-2.6.39.1/drivers/ata/ata_generic.c
24761 --- linux-2.6.39.1/drivers/ata/ata_generic.c 2011-05-19 00:06:34.000000000 -0400
24762 +++ linux-2.6.39.1/drivers/ata/ata_generic.c 2011-05-22 19:36:30.000000000 -0400
24763 @@ -101,7 +101,7 @@ static struct scsi_host_template generic
24764 ATA_BMDMA_SHT(DRV_NAME),
24765 };
24766
24767 -static struct ata_port_operations generic_port_ops = {
24768 +static const struct ata_port_operations generic_port_ops = {
24769 .inherits = &ata_bmdma_port_ops,
24770 .cable_detect = ata_cable_unknown,
24771 .set_mode = generic_set_mode,
24772 diff -urNp linux-2.6.39.1/drivers/ata/ata_piix.c linux-2.6.39.1/drivers/ata/ata_piix.c
24773 --- linux-2.6.39.1/drivers/ata/ata_piix.c 2011-05-19 00:06:34.000000000 -0400
24774 +++ linux-2.6.39.1/drivers/ata/ata_piix.c 2011-05-22 19:36:30.000000000 -0400
24775 @@ -335,12 +335,12 @@ static struct scsi_host_template piix_sh
24776 ATA_BMDMA_SHT(DRV_NAME),
24777 };
24778
24779 -static struct ata_port_operations piix_sata_ops = {
24780 +static const struct ata_port_operations piix_sata_ops = {
24781 .inherits = &ata_bmdma32_port_ops,
24782 .sff_irq_check = piix_irq_check,
24783 };
24784
24785 -static struct ata_port_operations piix_pata_ops = {
24786 +static const struct ata_port_operations piix_pata_ops = {
24787 .inherits = &piix_sata_ops,
24788 .cable_detect = ata_cable_40wire,
24789 .set_piomode = piix_set_piomode,
24790 @@ -348,12 +348,12 @@ static struct ata_port_operations piix_p
24791 .prereset = piix_pata_prereset,
24792 };
24793
24794 -static struct ata_port_operations piix_vmw_ops = {
24795 +static const struct ata_port_operations piix_vmw_ops = {
24796 .inherits = &piix_pata_ops,
24797 .bmdma_status = piix_vmw_bmdma_status,
24798 };
24799
24800 -static struct ata_port_operations ich_pata_ops = {
24801 +static const struct ata_port_operations ich_pata_ops = {
24802 .inherits = &piix_pata_ops,
24803 .cable_detect = ich_pata_cable_detect,
24804 .set_dmamode = ich_set_dmamode,
24805 @@ -369,7 +369,7 @@ static struct scsi_host_template piix_si
24806 .shost_attrs = piix_sidpr_shost_attrs,
24807 };
24808
24809 -static struct ata_port_operations piix_sidpr_sata_ops = {
24810 +static const struct ata_port_operations piix_sidpr_sata_ops = {
24811 .inherits = &piix_sata_ops,
24812 .hardreset = sata_std_hardreset,
24813 .scr_read = piix_sidpr_scr_read,
24814 diff -urNp linux-2.6.39.1/drivers/ata/libahci.c linux-2.6.39.1/drivers/ata/libahci.c
24815 --- linux-2.6.39.1/drivers/ata/libahci.c 2011-05-19 00:06:34.000000000 -0400
24816 +++ linux-2.6.39.1/drivers/ata/libahci.c 2011-05-22 19:36:30.000000000 -0400
24817 @@ -141,7 +141,7 @@ struct device_attribute *ahci_sdev_attrs
24818 };
24819 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
24820
24821 -struct ata_port_operations ahci_ops = {
24822 +const struct ata_port_operations ahci_ops = {
24823 .inherits = &sata_pmp_port_ops,
24824
24825 .qc_defer = ahci_pmp_qc_defer,
24826 diff -urNp linux-2.6.39.1/drivers/ata/libata-acpi.c linux-2.6.39.1/drivers/ata/libata-acpi.c
24827 --- linux-2.6.39.1/drivers/ata/libata-acpi.c 2011-05-19 00:06:34.000000000 -0400
24828 +++ linux-2.6.39.1/drivers/ata/libata-acpi.c 2011-05-22 19:36:30.000000000 -0400
24829 @@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
24830 ata_acpi_uevent(dev->link->ap, dev, event);
24831 }
24832
24833 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24834 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24835 .handler = ata_acpi_dev_notify_dock,
24836 .uevent = ata_acpi_dev_uevent,
24837 };
24838
24839 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24840 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24841 .handler = ata_acpi_ap_notify_dock,
24842 .uevent = ata_acpi_ap_uevent,
24843 };
24844 diff -urNp linux-2.6.39.1/drivers/ata/libata-core.c linux-2.6.39.1/drivers/ata/libata-core.c
24845 --- linux-2.6.39.1/drivers/ata/libata-core.c 2011-05-19 00:06:34.000000000 -0400
24846 +++ linux-2.6.39.1/drivers/ata/libata-core.c 2011-05-22 19:36:30.000000000 -0400
24847 @@ -4747,7 +4747,7 @@ void ata_qc_free(struct ata_queued_cmd *
24848 struct ata_port *ap;
24849 unsigned int tag;
24850
24851 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24852 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24853 ap = qc->ap;
24854
24855 qc->flags = 0;
24856 @@ -4763,7 +4763,7 @@ void __ata_qc_complete(struct ata_queued
24857 struct ata_port *ap;
24858 struct ata_link *link;
24859
24860 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24861 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24862 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
24863 ap = qc->ap;
24864 link = qc->dev->link;
24865 @@ -5756,7 +5756,7 @@ static void ata_host_stop(struct device
24866 * LOCKING:
24867 * None.
24868 */
24869 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
24870 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
24871 {
24872 static DEFINE_SPINLOCK(lock);
24873 const struct ata_port_operations *cur;
24874 @@ -5768,6 +5768,7 @@ static void ata_finalize_port_ops(struct
24875 return;
24876
24877 spin_lock(&lock);
24878 + pax_open_kernel();
24879
24880 for (cur = ops->inherits; cur; cur = cur->inherits) {
24881 void **inherit = (void **)cur;
24882 @@ -5781,8 +5782,9 @@ static void ata_finalize_port_ops(struct
24883 if (IS_ERR(*pp))
24884 *pp = NULL;
24885
24886 - ops->inherits = NULL;
24887 + ((struct ata_port_operations *)ops)->inherits = NULL;
24888
24889 + pax_close_kernel();
24890 spin_unlock(&lock);
24891 }
24892
24893 @@ -5879,7 +5881,7 @@ int ata_host_start(struct ata_host *host
24894 */
24895 /* KILLME - the only user left is ipr */
24896 void ata_host_init(struct ata_host *host, struct device *dev,
24897 - unsigned long flags, struct ata_port_operations *ops)
24898 + unsigned long flags, const struct ata_port_operations *ops)
24899 {
24900 spin_lock_init(&host->lock);
24901 mutex_init(&host->eh_mutex);
24902 @@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
24903 /* truly dummy */
24904 }
24905
24906 -struct ata_port_operations ata_dummy_port_ops = {
24907 +const struct ata_port_operations ata_dummy_port_ops = {
24908 .qc_prep = ata_noop_qc_prep,
24909 .qc_issue = ata_dummy_qc_issue,
24910 .error_handler = ata_dummy_error_handler,
24911 diff -urNp linux-2.6.39.1/drivers/ata/libata-eh.c linux-2.6.39.1/drivers/ata/libata-eh.c
24912 --- linux-2.6.39.1/drivers/ata/libata-eh.c 2011-05-19 00:06:34.000000000 -0400
24913 +++ linux-2.6.39.1/drivers/ata/libata-eh.c 2011-05-22 19:36:30.000000000 -0400
24914 @@ -2518,6 +2518,8 @@ void ata_eh_report(struct ata_port *ap)
24915 {
24916 struct ata_link *link;
24917
24918 + pax_track_stack();
24919 +
24920 ata_for_each_link(link, ap, HOST_FIRST)
24921 ata_eh_link_report(link);
24922 }
24923 @@ -3922,7 +3924,7 @@ void ata_do_eh(struct ata_port *ap, ata_
24924 */
24925 void ata_std_error_handler(struct ata_port *ap)
24926 {
24927 - struct ata_port_operations *ops = ap->ops;
24928 + const struct ata_port_operations *ops = ap->ops;
24929 ata_reset_fn_t hardreset = ops->hardreset;
24930
24931 /* ignore built-in hardreset if SCR access is not available */
24932 diff -urNp linux-2.6.39.1/drivers/ata/libata-pmp.c linux-2.6.39.1/drivers/ata/libata-pmp.c
24933 --- linux-2.6.39.1/drivers/ata/libata-pmp.c 2011-05-19 00:06:34.000000000 -0400
24934 +++ linux-2.6.39.1/drivers/ata/libata-pmp.c 2011-05-22 19:36:30.000000000 -0400
24935 @@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
24936 */
24937 static int sata_pmp_eh_recover(struct ata_port *ap)
24938 {
24939 - struct ata_port_operations *ops = ap->ops;
24940 + const struct ata_port_operations *ops = ap->ops;
24941 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
24942 struct ata_link *pmp_link = &ap->link;
24943 struct ata_device *pmp_dev = pmp_link->device;
24944 diff -urNp linux-2.6.39.1/drivers/ata/pata_acpi.c linux-2.6.39.1/drivers/ata/pata_acpi.c
24945 --- linux-2.6.39.1/drivers/ata/pata_acpi.c 2011-05-19 00:06:34.000000000 -0400
24946 +++ linux-2.6.39.1/drivers/ata/pata_acpi.c 2011-05-22 19:36:30.000000000 -0400
24947 @@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
24948 ATA_BMDMA_SHT(DRV_NAME),
24949 };
24950
24951 -static struct ata_port_operations pacpi_ops = {
24952 +static const struct ata_port_operations pacpi_ops = {
24953 .inherits = &ata_bmdma_port_ops,
24954 .qc_issue = pacpi_qc_issue,
24955 .cable_detect = pacpi_cable_detect,
24956 diff -urNp linux-2.6.39.1/drivers/ata/pata_ali.c linux-2.6.39.1/drivers/ata/pata_ali.c
24957 --- linux-2.6.39.1/drivers/ata/pata_ali.c 2011-05-19 00:06:34.000000000 -0400
24958 +++ linux-2.6.39.1/drivers/ata/pata_ali.c 2011-05-22 19:36:30.000000000 -0400
24959 @@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
24960 * Port operations for PIO only ALi
24961 */
24962
24963 -static struct ata_port_operations ali_early_port_ops = {
24964 +static const struct ata_port_operations ali_early_port_ops = {
24965 .inherits = &ata_sff_port_ops,
24966 .cable_detect = ata_cable_40wire,
24967 .set_piomode = ali_set_piomode,
24968 @@ -380,7 +380,7 @@ static const struct ata_port_operations
24969 * Port operations for DMA capable ALi without cable
24970 * detect
24971 */
24972 -static struct ata_port_operations ali_20_port_ops = {
24973 +static const struct ata_port_operations ali_20_port_ops = {
24974 .inherits = &ali_dma_base_ops,
24975 .cable_detect = ata_cable_40wire,
24976 .mode_filter = ali_20_filter,
24977 @@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
24978 /*
24979 * Port operations for DMA capable ALi with cable detect
24980 */
24981 -static struct ata_port_operations ali_c2_port_ops = {
24982 +static const struct ata_port_operations ali_c2_port_ops = {
24983 .inherits = &ali_dma_base_ops,
24984 .check_atapi_dma = ali_check_atapi_dma,
24985 .cable_detect = ali_c2_cable_detect,
24986 @@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
24987 /*
24988 * Port operations for DMA capable ALi with cable detect
24989 */
24990 -static struct ata_port_operations ali_c4_port_ops = {
24991 +static const struct ata_port_operations ali_c4_port_ops = {
24992 .inherits = &ali_dma_base_ops,
24993 .check_atapi_dma = ali_check_atapi_dma,
24994 .cable_detect = ali_c2_cable_detect,
24995 @@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
24996 /*
24997 * Port operations for DMA capable ALi with cable detect and LBA48
24998 */
24999 -static struct ata_port_operations ali_c5_port_ops = {
25000 +static const struct ata_port_operations ali_c5_port_ops = {
25001 .inherits = &ali_dma_base_ops,
25002 .check_atapi_dma = ali_check_atapi_dma,
25003 .dev_config = ali_warn_atapi_dma,
25004 diff -urNp linux-2.6.39.1/drivers/ata/pata_amd.c linux-2.6.39.1/drivers/ata/pata_amd.c
25005 --- linux-2.6.39.1/drivers/ata/pata_amd.c 2011-05-19 00:06:34.000000000 -0400
25006 +++ linux-2.6.39.1/drivers/ata/pata_amd.c 2011-05-22 19:36:31.000000000 -0400
25007 @@ -397,28 +397,28 @@ static const struct ata_port_operations
25008 .prereset = amd_pre_reset,
25009 };
25010
25011 -static struct ata_port_operations amd33_port_ops = {
25012 +static const struct ata_port_operations amd33_port_ops = {
25013 .inherits = &amd_base_port_ops,
25014 .cable_detect = ata_cable_40wire,
25015 .set_piomode = amd33_set_piomode,
25016 .set_dmamode = amd33_set_dmamode,
25017 };
25018
25019 -static struct ata_port_operations amd66_port_ops = {
25020 +static const struct ata_port_operations amd66_port_ops = {
25021 .inherits = &amd_base_port_ops,
25022 .cable_detect = ata_cable_unknown,
25023 .set_piomode = amd66_set_piomode,
25024 .set_dmamode = amd66_set_dmamode,
25025 };
25026
25027 -static struct ata_port_operations amd100_port_ops = {
25028 +static const struct ata_port_operations amd100_port_ops = {
25029 .inherits = &amd_base_port_ops,
25030 .cable_detect = ata_cable_unknown,
25031 .set_piomode = amd100_set_piomode,
25032 .set_dmamode = amd100_set_dmamode,
25033 };
25034
25035 -static struct ata_port_operations amd133_port_ops = {
25036 +static const struct ata_port_operations amd133_port_ops = {
25037 .inherits = &amd_base_port_ops,
25038 .cable_detect = amd_cable_detect,
25039 .set_piomode = amd133_set_piomode,
25040 @@ -433,13 +433,13 @@ static const struct ata_port_operations
25041 .host_stop = nv_host_stop,
25042 };
25043
25044 -static struct ata_port_operations nv100_port_ops = {
25045 +static const struct ata_port_operations nv100_port_ops = {
25046 .inherits = &nv_base_port_ops,
25047 .set_piomode = nv100_set_piomode,
25048 .set_dmamode = nv100_set_dmamode,
25049 };
25050
25051 -static struct ata_port_operations nv133_port_ops = {
25052 +static const struct ata_port_operations nv133_port_ops = {
25053 .inherits = &nv_base_port_ops,
25054 .set_piomode = nv133_set_piomode,
25055 .set_dmamode = nv133_set_dmamode,
25056 diff -urNp linux-2.6.39.1/drivers/ata/pata_arasan_cf.c linux-2.6.39.1/drivers/ata/pata_arasan_cf.c
25057 --- linux-2.6.39.1/drivers/ata/pata_arasan_cf.c 2011-05-19 00:06:34.000000000 -0400
25058 +++ linux-2.6.39.1/drivers/ata/pata_arasan_cf.c 2011-05-22 19:36:31.000000000 -0400
25059 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(str
25060 /* Handle platform specific quirks */
25061 if (pdata->quirk) {
25062 if (pdata->quirk & CF_BROKEN_PIO) {
25063 - ap->ops->set_piomode = NULL;
25064 + pax_open_kernel();
25065 + *(void**)&ap->ops->set_piomode = NULL;
25066 + pax_close_kernel();
25067 ap->pio_mask = 0;
25068 }
25069 if (pdata->quirk & CF_BROKEN_MWDMA)
25070 diff -urNp linux-2.6.39.1/drivers/ata/pata_artop.c linux-2.6.39.1/drivers/ata/pata_artop.c
25071 --- linux-2.6.39.1/drivers/ata/pata_artop.c 2011-05-19 00:06:34.000000000 -0400
25072 +++ linux-2.6.39.1/drivers/ata/pata_artop.c 2011-05-22 19:36:31.000000000 -0400
25073 @@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
25074 ATA_BMDMA_SHT(DRV_NAME),
25075 };
25076
25077 -static struct ata_port_operations artop6210_ops = {
25078 +static const struct ata_port_operations artop6210_ops = {
25079 .inherits = &ata_bmdma_port_ops,
25080 .cable_detect = ata_cable_40wire,
25081 .set_piomode = artop6210_set_piomode,
25082 @@ -321,7 +321,7 @@ static struct ata_port_operations artop6
25083 .qc_defer = artop6210_qc_defer,
25084 };
25085
25086 -static struct ata_port_operations artop6260_ops = {
25087 +static const struct ata_port_operations artop6260_ops = {
25088 .inherits = &ata_bmdma_port_ops,
25089 .cable_detect = artop6260_cable_detect,
25090 .set_piomode = artop6260_set_piomode,
25091 diff -urNp linux-2.6.39.1/drivers/ata/pata_at32.c linux-2.6.39.1/drivers/ata/pata_at32.c
25092 --- linux-2.6.39.1/drivers/ata/pata_at32.c 2011-05-19 00:06:34.000000000 -0400
25093 +++ linux-2.6.39.1/drivers/ata/pata_at32.c 2011-05-22 19:36:31.000000000 -0400
25094 @@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
25095 ATA_PIO_SHT(DRV_NAME),
25096 };
25097
25098 -static struct ata_port_operations at32_port_ops = {
25099 +static const struct ata_port_operations at32_port_ops = {
25100 .inherits = &ata_sff_port_ops,
25101 .cable_detect = ata_cable_40wire,
25102 .set_piomode = pata_at32_set_piomode,
25103 diff -urNp linux-2.6.39.1/drivers/ata/pata_at91.c linux-2.6.39.1/drivers/ata/pata_at91.c
25104 --- linux-2.6.39.1/drivers/ata/pata_at91.c 2011-05-19 00:06:34.000000000 -0400
25105 +++ linux-2.6.39.1/drivers/ata/pata_at91.c 2011-05-22 19:36:31.000000000 -0400
25106 @@ -212,7 +212,7 @@ static struct scsi_host_template pata_at
25107 ATA_PIO_SHT(DRV_NAME),
25108 };
25109
25110 -static struct ata_port_operations pata_at91_port_ops = {
25111 +static const struct ata_port_operations pata_at91_port_ops = {
25112 .inherits = &ata_sff_port_ops,
25113
25114 .sff_data_xfer = pata_at91_data_xfer_noirq,
25115 diff -urNp linux-2.6.39.1/drivers/ata/pata_atiixp.c linux-2.6.39.1/drivers/ata/pata_atiixp.c
25116 --- linux-2.6.39.1/drivers/ata/pata_atiixp.c 2011-05-19 00:06:34.000000000 -0400
25117 +++ linux-2.6.39.1/drivers/ata/pata_atiixp.c 2011-05-22 19:36:31.000000000 -0400
25118 @@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
25119 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25120 };
25121
25122 -static struct ata_port_operations atiixp_port_ops = {
25123 +static const struct ata_port_operations atiixp_port_ops = {
25124 .inherits = &ata_bmdma_port_ops,
25125
25126 .qc_prep = ata_bmdma_dumb_qc_prep,
25127 diff -urNp linux-2.6.39.1/drivers/ata/pata_atp867x.c linux-2.6.39.1/drivers/ata/pata_atp867x.c
25128 --- linux-2.6.39.1/drivers/ata/pata_atp867x.c 2011-05-19 00:06:34.000000000 -0400
25129 +++ linux-2.6.39.1/drivers/ata/pata_atp867x.c 2011-05-22 19:36:31.000000000 -0400
25130 @@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
25131 ATA_BMDMA_SHT(DRV_NAME),
25132 };
25133
25134 -static struct ata_port_operations atp867x_ops = {
25135 +static const struct ata_port_operations atp867x_ops = {
25136 .inherits = &ata_bmdma_port_ops,
25137 .cable_detect = atp867x_cable_detect,
25138 .set_piomode = atp867x_set_piomode,
25139 diff -urNp linux-2.6.39.1/drivers/ata/pata_bf54x.c linux-2.6.39.1/drivers/ata/pata_bf54x.c
25140 --- linux-2.6.39.1/drivers/ata/pata_bf54x.c 2011-05-19 00:06:34.000000000 -0400
25141 +++ linux-2.6.39.1/drivers/ata/pata_bf54x.c 2011-05-22 19:36:31.000000000 -0400
25142 @@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
25143 .dma_boundary = ATA_DMA_BOUNDARY,
25144 };
25145
25146 -static struct ata_port_operations bfin_pata_ops = {
25147 +static const struct ata_port_operations bfin_pata_ops = {
25148 .inherits = &ata_bmdma_port_ops,
25149
25150 .set_piomode = bfin_set_piomode,
25151 diff -urNp linux-2.6.39.1/drivers/ata/pata_cmd640.c linux-2.6.39.1/drivers/ata/pata_cmd640.c
25152 --- linux-2.6.39.1/drivers/ata/pata_cmd640.c 2011-05-19 00:06:34.000000000 -0400
25153 +++ linux-2.6.39.1/drivers/ata/pata_cmd640.c 2011-05-22 19:36:31.000000000 -0400
25154 @@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
25155 ATA_PIO_SHT(DRV_NAME),
25156 };
25157
25158 -static struct ata_port_operations cmd640_port_ops = {
25159 +static const struct ata_port_operations cmd640_port_ops = {
25160 .inherits = &ata_sff_port_ops,
25161 /* In theory xfer_noirq is not needed once we kill the prefetcher */
25162 .sff_data_xfer = ata_sff_data_xfer_noirq,
25163 diff -urNp linux-2.6.39.1/drivers/ata/pata_cmd64x.c linux-2.6.39.1/drivers/ata/pata_cmd64x.c
25164 --- linux-2.6.39.1/drivers/ata/pata_cmd64x.c 2011-06-03 00:04:13.000000000 -0400
25165 +++ linux-2.6.39.1/drivers/ata/pata_cmd64x.c 2011-06-03 00:32:05.000000000 -0400
25166 @@ -271,18 +271,18 @@ static const struct ata_port_operations
25167 .set_dmamode = cmd64x_set_dmamode,
25168 };
25169
25170 -static struct ata_port_operations cmd64x_port_ops = {
25171 +static const struct ata_port_operations cmd64x_port_ops = {
25172 .inherits = &cmd64x_base_ops,
25173 .cable_detect = ata_cable_40wire,
25174 };
25175
25176 -static struct ata_port_operations cmd646r1_port_ops = {
25177 +static const struct ata_port_operations cmd646r1_port_ops = {
25178 .inherits = &cmd64x_base_ops,
25179 .bmdma_stop = cmd646r1_bmdma_stop,
25180 .cable_detect = ata_cable_40wire,
25181 };
25182
25183 -static struct ata_port_operations cmd648_port_ops = {
25184 +static const struct ata_port_operations cmd648_port_ops = {
25185 .inherits = &cmd64x_base_ops,
25186 .bmdma_stop = cmd648_bmdma_stop,
25187 .cable_detect = cmd648_cable_detect,
25188 diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5520.c linux-2.6.39.1/drivers/ata/pata_cs5520.c
25189 --- linux-2.6.39.1/drivers/ata/pata_cs5520.c 2011-05-19 00:06:34.000000000 -0400
25190 +++ linux-2.6.39.1/drivers/ata/pata_cs5520.c 2011-05-22 19:36:31.000000000 -0400
25191 @@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
25192 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25193 };
25194
25195 -static struct ata_port_operations cs5520_port_ops = {
25196 +static const struct ata_port_operations cs5520_port_ops = {
25197 .inherits = &ata_bmdma_port_ops,
25198 .qc_prep = ata_bmdma_dumb_qc_prep,
25199 .cable_detect = ata_cable_40wire,
25200 diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5530.c linux-2.6.39.1/drivers/ata/pata_cs5530.c
25201 --- linux-2.6.39.1/drivers/ata/pata_cs5530.c 2011-05-19 00:06:34.000000000 -0400
25202 +++ linux-2.6.39.1/drivers/ata/pata_cs5530.c 2011-05-22 19:36:31.000000000 -0400
25203 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
25204 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25205 };
25206
25207 -static struct ata_port_operations cs5530_port_ops = {
25208 +static const struct ata_port_operations cs5530_port_ops = {
25209 .inherits = &ata_bmdma_port_ops,
25210
25211 .qc_prep = ata_bmdma_dumb_qc_prep,
25212 diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5535.c linux-2.6.39.1/drivers/ata/pata_cs5535.c
25213 --- linux-2.6.39.1/drivers/ata/pata_cs5535.c 2011-05-19 00:06:34.000000000 -0400
25214 +++ linux-2.6.39.1/drivers/ata/pata_cs5535.c 2011-05-22 19:36:31.000000000 -0400
25215 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
25216 ATA_BMDMA_SHT(DRV_NAME),
25217 };
25218
25219 -static struct ata_port_operations cs5535_port_ops = {
25220 +static const struct ata_port_operations cs5535_port_ops = {
25221 .inherits = &ata_bmdma_port_ops,
25222 .cable_detect = cs5535_cable_detect,
25223 .set_piomode = cs5535_set_piomode,
25224 diff -urNp linux-2.6.39.1/drivers/ata/pata_cs5536.c linux-2.6.39.1/drivers/ata/pata_cs5536.c
25225 --- linux-2.6.39.1/drivers/ata/pata_cs5536.c 2011-05-19 00:06:34.000000000 -0400
25226 +++ linux-2.6.39.1/drivers/ata/pata_cs5536.c 2011-05-22 19:36:31.000000000 -0400
25227 @@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
25228 ATA_BMDMA_SHT(DRV_NAME),
25229 };
25230
25231 -static struct ata_port_operations cs5536_port_ops = {
25232 +static const struct ata_port_operations cs5536_port_ops = {
25233 .inherits = &ata_bmdma32_port_ops,
25234 .cable_detect = cs5536_cable_detect,
25235 .set_piomode = cs5536_set_piomode,
25236 diff -urNp linux-2.6.39.1/drivers/ata/pata_cypress.c linux-2.6.39.1/drivers/ata/pata_cypress.c
25237 --- linux-2.6.39.1/drivers/ata/pata_cypress.c 2011-05-19 00:06:34.000000000 -0400
25238 +++ linux-2.6.39.1/drivers/ata/pata_cypress.c 2011-05-22 19:36:31.000000000 -0400
25239 @@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
25240 ATA_BMDMA_SHT(DRV_NAME),
25241 };
25242
25243 -static struct ata_port_operations cy82c693_port_ops = {
25244 +static const struct ata_port_operations cy82c693_port_ops = {
25245 .inherits = &ata_bmdma_port_ops,
25246 .cable_detect = ata_cable_40wire,
25247 .set_piomode = cy82c693_set_piomode,
25248 diff -urNp linux-2.6.39.1/drivers/ata/pata_efar.c linux-2.6.39.1/drivers/ata/pata_efar.c
25249 --- linux-2.6.39.1/drivers/ata/pata_efar.c 2011-05-19 00:06:34.000000000 -0400
25250 +++ linux-2.6.39.1/drivers/ata/pata_efar.c 2011-05-22 19:36:31.000000000 -0400
25251 @@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
25252 ATA_BMDMA_SHT(DRV_NAME),
25253 };
25254
25255 -static struct ata_port_operations efar_ops = {
25256 +static const struct ata_port_operations efar_ops = {
25257 .inherits = &ata_bmdma_port_ops,
25258 .cable_detect = efar_cable_detect,
25259 .set_piomode = efar_set_piomode,
25260 diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt366.c linux-2.6.39.1/drivers/ata/pata_hpt366.c
25261 --- linux-2.6.39.1/drivers/ata/pata_hpt366.c 2011-05-19 00:06:34.000000000 -0400
25262 +++ linux-2.6.39.1/drivers/ata/pata_hpt366.c 2011-05-22 19:36:31.000000000 -0400
25263 @@ -276,7 +276,7 @@ static struct scsi_host_template hpt36x_
25264 * Configuration for HPT366/68
25265 */
25266
25267 -static struct ata_port_operations hpt366_port_ops = {
25268 +static const struct ata_port_operations hpt366_port_ops = {
25269 .inherits = &ata_bmdma_port_ops,
25270 .cable_detect = hpt36x_cable_detect,
25271 .mode_filter = hpt366_filter,
25272 diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt37x.c linux-2.6.39.1/drivers/ata/pata_hpt37x.c
25273 --- linux-2.6.39.1/drivers/ata/pata_hpt37x.c 2011-05-19 00:06:34.000000000 -0400
25274 +++ linux-2.6.39.1/drivers/ata/pata_hpt37x.c 2011-05-22 19:36:31.000000000 -0400
25275 @@ -589,7 +589,7 @@ static struct scsi_host_template hpt37x_
25276 * Configuration for HPT370
25277 */
25278
25279 -static struct ata_port_operations hpt370_port_ops = {
25280 +static const struct ata_port_operations hpt370_port_ops = {
25281 .inherits = &ata_bmdma_port_ops,
25282
25283 .bmdma_stop = hpt370_bmdma_stop,
25284 @@ -605,7 +605,7 @@ static struct ata_port_operations hpt370
25285 * Configuration for HPT370A. Close to 370 but less filters
25286 */
25287
25288 -static struct ata_port_operations hpt370a_port_ops = {
25289 +static const struct ata_port_operations hpt370a_port_ops = {
25290 .inherits = &hpt370_port_ops,
25291 .mode_filter = hpt370a_filter,
25292 };
25293 @@ -615,7 +615,7 @@ static struct ata_port_operations hpt370
25294 * mode setting functionality.
25295 */
25296
25297 -static struct ata_port_operations hpt302_port_ops = {
25298 +static const struct ata_port_operations hpt302_port_ops = {
25299 .inherits = &ata_bmdma_port_ops,
25300
25301 .bmdma_stop = hpt37x_bmdma_stop,
25302 @@ -631,7 +631,7 @@ static struct ata_port_operations hpt302
25303 * but we have a mode filter.
25304 */
25305
25306 -static struct ata_port_operations hpt372_port_ops = {
25307 +static const struct ata_port_operations hpt372_port_ops = {
25308 .inherits = &hpt302_port_ops,
25309 .mode_filter = hpt372_filter,
25310 };
25311 @@ -641,7 +641,7 @@ static struct ata_port_operations hpt372
25312 * but we have a different cable detection procedure for function 1.
25313 */
25314
25315 -static struct ata_port_operations hpt374_fn1_port_ops = {
25316 +static const struct ata_port_operations hpt374_fn1_port_ops = {
25317 .inherits = &hpt372_port_ops,
25318 .cable_detect = hpt374_fn1_cable_detect,
25319 };
25320 diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c
25321 --- linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c 2011-05-19 00:06:34.000000000 -0400
25322 +++ linux-2.6.39.1/drivers/ata/pata_hpt3x2n.c 2011-05-22 19:36:31.000000000 -0400
25323 @@ -350,7 +350,7 @@ static struct scsi_host_template hpt3x2n
25324 * Configuration for HPT302N/371N.
25325 */
25326
25327 -static struct ata_port_operations hpt3xxn_port_ops = {
25328 +static const struct ata_port_operations hpt3xxn_port_ops = {
25329 .inherits = &ata_bmdma_port_ops,
25330
25331 .bmdma_stop = hpt3x2n_bmdma_stop,
25332 @@ -368,7 +368,7 @@ static struct ata_port_operations hpt3xx
25333 * Configuration for HPT372N. Same as 302N/371N but we have a mode filter.
25334 */
25335
25336 -static struct ata_port_operations hpt372n_port_ops = {
25337 +static const struct ata_port_operations hpt372n_port_ops = {
25338 .inherits = &hpt3xxn_port_ops,
25339 .mode_filter = &hpt372n_filter,
25340 };
25341 diff -urNp linux-2.6.39.1/drivers/ata/pata_hpt3x3.c linux-2.6.39.1/drivers/ata/pata_hpt3x3.c
25342 --- linux-2.6.39.1/drivers/ata/pata_hpt3x3.c 2011-05-19 00:06:34.000000000 -0400
25343 +++ linux-2.6.39.1/drivers/ata/pata_hpt3x3.c 2011-05-22 19:36:31.000000000 -0400
25344 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
25345 ATA_BMDMA_SHT(DRV_NAME),
25346 };
25347
25348 -static struct ata_port_operations hpt3x3_port_ops = {
25349 +static const struct ata_port_operations hpt3x3_port_ops = {
25350 .inherits = &ata_bmdma_port_ops,
25351 .cable_detect = ata_cable_40wire,
25352 .set_piomode = hpt3x3_set_piomode,
25353 diff -urNp linux-2.6.39.1/drivers/ata/pata_icside.c linux-2.6.39.1/drivers/ata/pata_icside.c
25354 --- linux-2.6.39.1/drivers/ata/pata_icside.c 2011-05-19 00:06:34.000000000 -0400
25355 +++ linux-2.6.39.1/drivers/ata/pata_icside.c 2011-05-22 19:36:31.000000000 -0400
25356 @@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
25357 }
25358 }
25359
25360 -static struct ata_port_operations pata_icside_port_ops = {
25361 +static const struct ata_port_operations pata_icside_port_ops = {
25362 .inherits = &ata_bmdma_port_ops,
25363 /* no need to build any PRD tables for DMA */
25364 .qc_prep = ata_noop_qc_prep,
25365 diff -urNp linux-2.6.39.1/drivers/ata/pata_isapnp.c linux-2.6.39.1/drivers/ata/pata_isapnp.c
25366 --- linux-2.6.39.1/drivers/ata/pata_isapnp.c 2011-05-19 00:06:34.000000000 -0400
25367 +++ linux-2.6.39.1/drivers/ata/pata_isapnp.c 2011-05-22 19:36:31.000000000 -0400
25368 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
25369 ATA_PIO_SHT(DRV_NAME),
25370 };
25371
25372 -static struct ata_port_operations isapnp_port_ops = {
25373 +static const struct ata_port_operations isapnp_port_ops = {
25374 .inherits = &ata_sff_port_ops,
25375 .cable_detect = ata_cable_40wire,
25376 };
25377
25378 -static struct ata_port_operations isapnp_noalt_port_ops = {
25379 +static const struct ata_port_operations isapnp_noalt_port_ops = {
25380 .inherits = &ata_sff_port_ops,
25381 .cable_detect = ata_cable_40wire,
25382 /* No altstatus so we don't want to use the lost interrupt poll */
25383 diff -urNp linux-2.6.39.1/drivers/ata/pata_it8213.c linux-2.6.39.1/drivers/ata/pata_it8213.c
25384 --- linux-2.6.39.1/drivers/ata/pata_it8213.c 2011-05-19 00:06:34.000000000 -0400
25385 +++ linux-2.6.39.1/drivers/ata/pata_it8213.c 2011-05-22 19:36:31.000000000 -0400
25386 @@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
25387 };
25388
25389
25390 -static struct ata_port_operations it8213_ops = {
25391 +static const struct ata_port_operations it8213_ops = {
25392 .inherits = &ata_bmdma_port_ops,
25393 .cable_detect = it8213_cable_detect,
25394 .set_piomode = it8213_set_piomode,
25395 diff -urNp linux-2.6.39.1/drivers/ata/pata_it821x.c linux-2.6.39.1/drivers/ata/pata_it821x.c
25396 --- linux-2.6.39.1/drivers/ata/pata_it821x.c 2011-05-19 00:06:34.000000000 -0400
25397 +++ linux-2.6.39.1/drivers/ata/pata_it821x.c 2011-05-22 19:36:31.000000000 -0400
25398 @@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
25399 ATA_BMDMA_SHT(DRV_NAME),
25400 };
25401
25402 -static struct ata_port_operations it821x_smart_port_ops = {
25403 +static const struct ata_port_operations it821x_smart_port_ops = {
25404 .inherits = &ata_bmdma_port_ops,
25405
25406 .check_atapi_dma= it821x_check_atapi_dma,
25407 @@ -815,7 +815,7 @@ static struct ata_port_operations it821x
25408 .port_start = it821x_port_start,
25409 };
25410
25411 -static struct ata_port_operations it821x_passthru_port_ops = {
25412 +static const struct ata_port_operations it821x_passthru_port_ops = {
25413 .inherits = &ata_bmdma_port_ops,
25414
25415 .check_atapi_dma= it821x_check_atapi_dma,
25416 @@ -831,7 +831,7 @@ static struct ata_port_operations it821x
25417 .port_start = it821x_port_start,
25418 };
25419
25420 -static struct ata_port_operations it821x_rdc_port_ops = {
25421 +static const struct ata_port_operations it821x_rdc_port_ops = {
25422 .inherits = &ata_bmdma_port_ops,
25423
25424 .check_atapi_dma= it821x_check_atapi_dma,
25425 diff -urNp linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c
25426 --- linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c 2011-05-19 00:06:34.000000000 -0400
25427 +++ linux-2.6.39.1/drivers/ata/pata_ixp4xx_cf.c 2011-05-22 19:36:31.000000000 -0400
25428 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25429 ATA_PIO_SHT(DRV_NAME),
25430 };
25431
25432 -static struct ata_port_operations ixp4xx_port_ops = {
25433 +static const struct ata_port_operations ixp4xx_port_ops = {
25434 .inherits = &ata_sff_port_ops,
25435 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25436 .cable_detect = ata_cable_40wire,
25437 diff -urNp linux-2.6.39.1/drivers/ata/pata_jmicron.c linux-2.6.39.1/drivers/ata/pata_jmicron.c
25438 --- linux-2.6.39.1/drivers/ata/pata_jmicron.c 2011-05-19 00:06:34.000000000 -0400
25439 +++ linux-2.6.39.1/drivers/ata/pata_jmicron.c 2011-05-22 19:36:31.000000000 -0400
25440 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25441 ATA_BMDMA_SHT(DRV_NAME),
25442 };
25443
25444 -static struct ata_port_operations jmicron_ops = {
25445 +static const struct ata_port_operations jmicron_ops = {
25446 .inherits = &ata_bmdma_port_ops,
25447 .prereset = jmicron_pre_reset,
25448 };
25449 diff -urNp linux-2.6.39.1/drivers/ata/pata_legacy.c linux-2.6.39.1/drivers/ata/pata_legacy.c
25450 --- linux-2.6.39.1/drivers/ata/pata_legacy.c 2011-05-19 00:06:34.000000000 -0400
25451 +++ linux-2.6.39.1/drivers/ata/pata_legacy.c 2011-05-22 19:36:31.000000000 -0400
25452 @@ -116,7 +116,7 @@ struct legacy_probe {
25453
25454 struct legacy_controller {
25455 const char *name;
25456 - struct ata_port_operations *ops;
25457 + const struct ata_port_operations *ops;
25458 unsigned int pio_mask;
25459 unsigned int flags;
25460 unsigned int pflags;
25461 @@ -239,12 +239,12 @@ static const struct ata_port_operations
25462 * pio_mask as well.
25463 */
25464
25465 -static struct ata_port_operations simple_port_ops = {
25466 +static const struct ata_port_operations simple_port_ops = {
25467 .inherits = &legacy_base_port_ops,
25468 .sff_data_xfer = ata_sff_data_xfer_noirq,
25469 };
25470
25471 -static struct ata_port_operations legacy_port_ops = {
25472 +static const struct ata_port_operations legacy_port_ops = {
25473 .inherits = &legacy_base_port_ops,
25474 .sff_data_xfer = ata_sff_data_xfer_noirq,
25475 .set_mode = legacy_set_mode,
25476 @@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
25477 return buflen;
25478 }
25479
25480 -static struct ata_port_operations pdc20230_port_ops = {
25481 +static const struct ata_port_operations pdc20230_port_ops = {
25482 .inherits = &legacy_base_port_ops,
25483 .set_piomode = pdc20230_set_piomode,
25484 .sff_data_xfer = pdc_data_xfer_vlb,
25485 @@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
25486 ioread8(ap->ioaddr.status_addr);
25487 }
25488
25489 -static struct ata_port_operations ht6560a_port_ops = {
25490 +static const struct ata_port_operations ht6560a_port_ops = {
25491 .inherits = &legacy_base_port_ops,
25492 .set_piomode = ht6560a_set_piomode,
25493 };
25494 @@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
25495 ioread8(ap->ioaddr.status_addr);
25496 }
25497
25498 -static struct ata_port_operations ht6560b_port_ops = {
25499 +static const struct ata_port_operations ht6560b_port_ops = {
25500 .inherits = &legacy_base_port_ops,
25501 .set_piomode = ht6560b_set_piomode,
25502 };
25503 @@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
25504 }
25505
25506
25507 -static struct ata_port_operations opti82c611a_port_ops = {
25508 +static const struct ata_port_operations opti82c611a_port_ops = {
25509 .inherits = &legacy_base_port_ops,
25510 .set_piomode = opti82c611a_set_piomode,
25511 };
25512 @@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
25513 return ata_sff_qc_issue(qc);
25514 }
25515
25516 -static struct ata_port_operations opti82c46x_port_ops = {
25517 +static const struct ata_port_operations opti82c46x_port_ops = {
25518 .inherits = &legacy_base_port_ops,
25519 .set_piomode = opti82c46x_set_piomode,
25520 .qc_issue = opti82c46x_qc_issue,
25521 @@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
25522 return 0;
25523 }
25524
25525 -static struct ata_port_operations qdi6500_port_ops = {
25526 +static const struct ata_port_operations qdi6500_port_ops = {
25527 .inherits = &legacy_base_port_ops,
25528 .set_piomode = qdi6500_set_piomode,
25529 .qc_issue = qdi_qc_issue,
25530 .sff_data_xfer = vlb32_data_xfer,
25531 };
25532
25533 -static struct ata_port_operations qdi6580_port_ops = {
25534 +static const struct ata_port_operations qdi6580_port_ops = {
25535 .inherits = &legacy_base_port_ops,
25536 .set_piomode = qdi6580_set_piomode,
25537 .sff_data_xfer = vlb32_data_xfer,
25538 };
25539
25540 -static struct ata_port_operations qdi6580dp_port_ops = {
25541 +static const struct ata_port_operations qdi6580dp_port_ops = {
25542 .inherits = &legacy_base_port_ops,
25543 .set_piomode = qdi6580dp_set_piomode,
25544 .qc_issue = qdi_qc_issue,
25545 @@ -872,7 +872,7 @@ static int winbond_port(struct platform_
25546 return 0;
25547 }
25548
25549 -static struct ata_port_operations winbond_port_ops = {
25550 +static const struct ata_port_operations winbond_port_ops = {
25551 .inherits = &legacy_base_port_ops,
25552 .set_piomode = winbond_set_piomode,
25553 .sff_data_xfer = vlb32_data_xfer,
25554 @@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
25555 int pio_modes = controller->pio_mask;
25556 unsigned long io = probe->port;
25557 u32 mask = (1 << probe->slot);
25558 - struct ata_port_operations *ops = controller->ops;
25559 + const struct ata_port_operations *ops = controller->ops;
25560 struct legacy_data *ld = &legacy_data[probe->slot];
25561 struct ata_host *host = NULL;
25562 struct ata_port *ap;
25563 diff -urNp linux-2.6.39.1/drivers/ata/pata_macio.c linux-2.6.39.1/drivers/ata/pata_macio.c
25564 --- linux-2.6.39.1/drivers/ata/pata_macio.c 2011-05-19 00:06:34.000000000 -0400
25565 +++ linux-2.6.39.1/drivers/ata/pata_macio.c 2011-05-22 19:36:31.000000000 -0400
25566 @@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
25567 .slave_configure = pata_macio_slave_config,
25568 };
25569
25570 -static struct ata_port_operations pata_macio_ops = {
25571 +static const struct ata_port_operations pata_macio_ops = {
25572 .inherits = &ata_bmdma_port_ops,
25573 -
25574 .freeze = pata_macio_freeze,
25575 .set_piomode = pata_macio_set_timings,
25576 .set_dmamode = pata_macio_set_timings,
25577 diff -urNp linux-2.6.39.1/drivers/ata/pata_marvell.c linux-2.6.39.1/drivers/ata/pata_marvell.c
25578 --- linux-2.6.39.1/drivers/ata/pata_marvell.c 2011-05-19 00:06:34.000000000 -0400
25579 +++ linux-2.6.39.1/drivers/ata/pata_marvell.c 2011-05-22 19:36:31.000000000 -0400
25580 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25581 ATA_BMDMA_SHT(DRV_NAME),
25582 };
25583
25584 -static struct ata_port_operations marvell_ops = {
25585 +static const struct ata_port_operations marvell_ops = {
25586 .inherits = &ata_bmdma_port_ops,
25587 .cable_detect = marvell_cable_detect,
25588 .prereset = marvell_pre_reset,
25589 diff -urNp linux-2.6.39.1/drivers/ata/pata_mpc52xx.c linux-2.6.39.1/drivers/ata/pata_mpc52xx.c
25590 --- linux-2.6.39.1/drivers/ata/pata_mpc52xx.c 2011-05-19 00:06:34.000000000 -0400
25591 +++ linux-2.6.39.1/drivers/ata/pata_mpc52xx.c 2011-05-22 19:36:31.000000000 -0400
25592 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25593 ATA_PIO_SHT(DRV_NAME),
25594 };
25595
25596 -static struct ata_port_operations mpc52xx_ata_port_ops = {
25597 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
25598 .inherits = &ata_bmdma_port_ops,
25599 .sff_dev_select = mpc52xx_ata_dev_select,
25600 .set_piomode = mpc52xx_ata_set_piomode,
25601 diff -urNp linux-2.6.39.1/drivers/ata/pata_mpiix.c linux-2.6.39.1/drivers/ata/pata_mpiix.c
25602 --- linux-2.6.39.1/drivers/ata/pata_mpiix.c 2011-05-19 00:06:34.000000000 -0400
25603 +++ linux-2.6.39.1/drivers/ata/pata_mpiix.c 2011-05-22 19:36:31.000000000 -0400
25604 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25605 ATA_PIO_SHT(DRV_NAME),
25606 };
25607
25608 -static struct ata_port_operations mpiix_port_ops = {
25609 +static const struct ata_port_operations mpiix_port_ops = {
25610 .inherits = &ata_sff_port_ops,
25611 .qc_issue = mpiix_qc_issue,
25612 .cable_detect = ata_cable_40wire,
25613 diff -urNp linux-2.6.39.1/drivers/ata/pata_netcell.c linux-2.6.39.1/drivers/ata/pata_netcell.c
25614 --- linux-2.6.39.1/drivers/ata/pata_netcell.c 2011-05-19 00:06:34.000000000 -0400
25615 +++ linux-2.6.39.1/drivers/ata/pata_netcell.c 2011-05-22 19:36:31.000000000 -0400
25616 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25617 ATA_BMDMA_SHT(DRV_NAME),
25618 };
25619
25620 -static struct ata_port_operations netcell_ops = {
25621 +static const struct ata_port_operations netcell_ops = {
25622 .inherits = &ata_bmdma_port_ops,
25623 .cable_detect = ata_cable_80wire,
25624 .read_id = netcell_read_id,
25625 diff -urNp linux-2.6.39.1/drivers/ata/pata_ninja32.c linux-2.6.39.1/drivers/ata/pata_ninja32.c
25626 --- linux-2.6.39.1/drivers/ata/pata_ninja32.c 2011-05-19 00:06:34.000000000 -0400
25627 +++ linux-2.6.39.1/drivers/ata/pata_ninja32.c 2011-05-22 19:36:31.000000000 -0400
25628 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25629 ATA_BMDMA_SHT(DRV_NAME),
25630 };
25631
25632 -static struct ata_port_operations ninja32_port_ops = {
25633 +static const struct ata_port_operations ninja32_port_ops = {
25634 .inherits = &ata_bmdma_port_ops,
25635 .sff_dev_select = ninja32_dev_select,
25636 .cable_detect = ata_cable_40wire,
25637 diff -urNp linux-2.6.39.1/drivers/ata/pata_ns87410.c linux-2.6.39.1/drivers/ata/pata_ns87410.c
25638 --- linux-2.6.39.1/drivers/ata/pata_ns87410.c 2011-05-19 00:06:34.000000000 -0400
25639 +++ linux-2.6.39.1/drivers/ata/pata_ns87410.c 2011-05-22 19:36:31.000000000 -0400
25640 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25641 ATA_PIO_SHT(DRV_NAME),
25642 };
25643
25644 -static struct ata_port_operations ns87410_port_ops = {
25645 +static const struct ata_port_operations ns87410_port_ops = {
25646 .inherits = &ata_sff_port_ops,
25647 .qc_issue = ns87410_qc_issue,
25648 .cable_detect = ata_cable_40wire,
25649 diff -urNp linux-2.6.39.1/drivers/ata/pata_ns87415.c linux-2.6.39.1/drivers/ata/pata_ns87415.c
25650 --- linux-2.6.39.1/drivers/ata/pata_ns87415.c 2011-05-19 00:06:34.000000000 -0400
25651 +++ linux-2.6.39.1/drivers/ata/pata_ns87415.c 2011-05-22 19:36:31.000000000 -0400
25652 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25653 }
25654 #endif /* 87560 SuperIO Support */
25655
25656 -static struct ata_port_operations ns87415_pata_ops = {
25657 +static const struct ata_port_operations ns87415_pata_ops = {
25658 .inherits = &ata_bmdma_port_ops,
25659
25660 .check_atapi_dma = ns87415_check_atapi_dma,
25661 @@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25662 };
25663
25664 #if defined(CONFIG_SUPERIO)
25665 -static struct ata_port_operations ns87560_pata_ops = {
25666 +static const struct ata_port_operations ns87560_pata_ops = {
25667 .inherits = &ns87415_pata_ops,
25668 .sff_tf_read = ns87560_tf_read,
25669 .sff_check_status = ns87560_check_status,
25670 diff -urNp linux-2.6.39.1/drivers/ata/pata_octeon_cf.c linux-2.6.39.1/drivers/ata/pata_octeon_cf.c
25671 --- linux-2.6.39.1/drivers/ata/pata_octeon_cf.c 2011-05-19 00:06:34.000000000 -0400
25672 +++ linux-2.6.39.1/drivers/ata/pata_octeon_cf.c 2011-05-22 19:36:31.000000000 -0400
25673 @@ -780,7 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
25674 return 0;
25675 }
25676
25677 -static struct ata_port_operations octeon_cf_ops = {
25678 +static struct ata_port_operations octeon_cf_ops = { /* cannot be const */
25679 .inherits = &ata_sff_port_ops,
25680 .check_atapi_dma = octeon_cf_check_atapi_dma,
25681 .qc_prep = ata_noop_qc_prep,
25682 diff -urNp linux-2.6.39.1/drivers/ata/pata_oldpiix.c linux-2.6.39.1/drivers/ata/pata_oldpiix.c
25683 --- linux-2.6.39.1/drivers/ata/pata_oldpiix.c 2011-05-19 00:06:34.000000000 -0400
25684 +++ linux-2.6.39.1/drivers/ata/pata_oldpiix.c 2011-05-22 19:36:31.000000000 -0400
25685 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25686 ATA_BMDMA_SHT(DRV_NAME),
25687 };
25688
25689 -static struct ata_port_operations oldpiix_pata_ops = {
25690 +static const struct ata_port_operations oldpiix_pata_ops = {
25691 .inherits = &ata_bmdma_port_ops,
25692 .qc_issue = oldpiix_qc_issue,
25693 .cable_detect = ata_cable_40wire,
25694 diff -urNp linux-2.6.39.1/drivers/ata/pata_opti.c linux-2.6.39.1/drivers/ata/pata_opti.c
25695 --- linux-2.6.39.1/drivers/ata/pata_opti.c 2011-05-19 00:06:34.000000000 -0400
25696 +++ linux-2.6.39.1/drivers/ata/pata_opti.c 2011-05-22 19:36:31.000000000 -0400
25697 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25698 ATA_PIO_SHT(DRV_NAME),
25699 };
25700
25701 -static struct ata_port_operations opti_port_ops = {
25702 +static const struct ata_port_operations opti_port_ops = {
25703 .inherits = &ata_sff_port_ops,
25704 .cable_detect = ata_cable_40wire,
25705 .set_piomode = opti_set_piomode,
25706 diff -urNp linux-2.6.39.1/drivers/ata/pata_optidma.c linux-2.6.39.1/drivers/ata/pata_optidma.c
25707 --- linux-2.6.39.1/drivers/ata/pata_optidma.c 2011-05-19 00:06:34.000000000 -0400
25708 +++ linux-2.6.39.1/drivers/ata/pata_optidma.c 2011-05-22 19:36:31.000000000 -0400
25709 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25710 ATA_BMDMA_SHT(DRV_NAME),
25711 };
25712
25713 -static struct ata_port_operations optidma_port_ops = {
25714 +static const struct ata_port_operations optidma_port_ops = {
25715 .inherits = &ata_bmdma_port_ops,
25716 .cable_detect = ata_cable_40wire,
25717 .set_piomode = optidma_set_pio_mode,
25718 @@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25719 .prereset = optidma_pre_reset,
25720 };
25721
25722 -static struct ata_port_operations optiplus_port_ops = {
25723 +static const struct ata_port_operations optiplus_port_ops = {
25724 .inherits = &optidma_port_ops,
25725 .set_piomode = optiplus_set_pio_mode,
25726 .set_dmamode = optiplus_set_dma_mode,
25727 diff -urNp linux-2.6.39.1/drivers/ata/pata_palmld.c linux-2.6.39.1/drivers/ata/pata_palmld.c
25728 --- linux-2.6.39.1/drivers/ata/pata_palmld.c 2011-05-19 00:06:34.000000000 -0400
25729 +++ linux-2.6.39.1/drivers/ata/pata_palmld.c 2011-05-22 19:36:31.000000000 -0400
25730 @@ -42,7 +42,7 @@ static struct scsi_host_template palmld_
25731 ATA_PIO_SHT(DRV_NAME),
25732 };
25733
25734 -static struct ata_port_operations palmld_port_ops = {
25735 +static const struct ata_port_operations palmld_port_ops = {
25736 .inherits = &ata_sff_port_ops,
25737 .sff_data_xfer = ata_sff_data_xfer_noirq,
25738 .cable_detect = ata_cable_40wire,
25739 diff -urNp linux-2.6.39.1/drivers/ata/pata_pcmcia.c linux-2.6.39.1/drivers/ata/pata_pcmcia.c
25740 --- linux-2.6.39.1/drivers/ata/pata_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
25741 +++ linux-2.6.39.1/drivers/ata/pata_pcmcia.c 2011-05-22 19:36:31.000000000 -0400
25742 @@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
25743 ATA_PIO_SHT(DRV_NAME),
25744 };
25745
25746 -static struct ata_port_operations pcmcia_port_ops = {
25747 +static const struct ata_port_operations pcmcia_port_ops = {
25748 .inherits = &ata_sff_port_ops,
25749 .sff_data_xfer = ata_sff_data_xfer_noirq,
25750 .cable_detect = ata_cable_40wire,
25751 .set_mode = pcmcia_set_mode,
25752 };
25753
25754 -static struct ata_port_operations pcmcia_8bit_port_ops = {
25755 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
25756 .inherits = &ata_sff_port_ops,
25757 .sff_data_xfer = ata_data_xfer_8bit,
25758 .cable_detect = ata_cable_40wire,
25759 @@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
25760 unsigned long io_base, ctl_base;
25761 void __iomem *io_addr, *ctl_addr;
25762 int n_ports = 1;
25763 - struct ata_port_operations *ops = &pcmcia_port_ops;
25764 + const struct ata_port_operations *ops = &pcmcia_port_ops;
25765
25766 /* Set up attributes in order to probe card and get resources */
25767 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
25768 diff -urNp linux-2.6.39.1/drivers/ata/pata_pdc2027x.c linux-2.6.39.1/drivers/ata/pata_pdc2027x.c
25769 --- linux-2.6.39.1/drivers/ata/pata_pdc2027x.c 2011-05-19 00:06:34.000000000 -0400
25770 +++ linux-2.6.39.1/drivers/ata/pata_pdc2027x.c 2011-05-22 19:36:31.000000000 -0400
25771 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25772 ATA_BMDMA_SHT(DRV_NAME),
25773 };
25774
25775 -static struct ata_port_operations pdc2027x_pata100_ops = {
25776 +static const struct ata_port_operations pdc2027x_pata100_ops = {
25777 .inherits = &ata_bmdma_port_ops,
25778 .check_atapi_dma = pdc2027x_check_atapi_dma,
25779 .cable_detect = pdc2027x_cable_detect,
25780 .prereset = pdc2027x_prereset,
25781 };
25782
25783 -static struct ata_port_operations pdc2027x_pata133_ops = {
25784 +static const struct ata_port_operations pdc2027x_pata133_ops = {
25785 .inherits = &pdc2027x_pata100_ops,
25786 .mode_filter = pdc2027x_mode_filter,
25787 .set_piomode = pdc2027x_set_piomode,
25788 diff -urNp linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c
25789 --- linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c 2011-05-19 00:06:34.000000000 -0400
25790 +++ linux-2.6.39.1/drivers/ata/pata_pdc202xx_old.c 2011-05-22 19:36:31.000000000 -0400
25791 @@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
25792 ATA_BMDMA_SHT(DRV_NAME),
25793 };
25794
25795 -static struct ata_port_operations pdc2024x_port_ops = {
25796 +static const struct ata_port_operations pdc2024x_port_ops = {
25797 .inherits = &ata_bmdma_port_ops,
25798
25799 .cable_detect = ata_cable_40wire,
25800 @@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
25801 .sff_irq_check = pdc202xx_irq_check,
25802 };
25803
25804 -static struct ata_port_operations pdc2026x_port_ops = {
25805 +static const struct ata_port_operations pdc2026x_port_ops = {
25806 .inherits = &pdc2024x_port_ops,
25807
25808 .check_atapi_dma = pdc2026x_check_atapi_dma,
25809 diff -urNp linux-2.6.39.1/drivers/ata/pata_piccolo.c linux-2.6.39.1/drivers/ata/pata_piccolo.c
25810 --- linux-2.6.39.1/drivers/ata/pata_piccolo.c 2011-05-19 00:06:34.000000000 -0400
25811 +++ linux-2.6.39.1/drivers/ata/pata_piccolo.c 2011-05-22 19:36:31.000000000 -0400
25812 @@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
25813 ATA_BMDMA_SHT(DRV_NAME),
25814 };
25815
25816 -static struct ata_port_operations tosh_port_ops = {
25817 +static const struct ata_port_operations tosh_port_ops = {
25818 .inherits = &ata_bmdma_port_ops,
25819 .cable_detect = ata_cable_unknown,
25820 .set_piomode = tosh_set_piomode,
25821 diff -urNp linux-2.6.39.1/drivers/ata/pata_platform.c linux-2.6.39.1/drivers/ata/pata_platform.c
25822 --- linux-2.6.39.1/drivers/ata/pata_platform.c 2011-05-19 00:06:34.000000000 -0400
25823 +++ linux-2.6.39.1/drivers/ata/pata_platform.c 2011-05-22 19:36:31.000000000 -0400
25824 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25825 ATA_PIO_SHT(DRV_NAME),
25826 };
25827
25828 -static struct ata_port_operations pata_platform_port_ops = {
25829 +static const struct ata_port_operations pata_platform_port_ops = {
25830 .inherits = &ata_sff_port_ops,
25831 .sff_data_xfer = ata_sff_data_xfer_noirq,
25832 .cable_detect = ata_cable_unknown,
25833 diff -urNp linux-2.6.39.1/drivers/ata/pata_pxa.c linux-2.6.39.1/drivers/ata/pata_pxa.c
25834 --- linux-2.6.39.1/drivers/ata/pata_pxa.c 2011-05-19 00:06:34.000000000 -0400
25835 +++ linux-2.6.39.1/drivers/ata/pata_pxa.c 2011-05-22 19:36:31.000000000 -0400
25836 @@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
25837 ATA_BMDMA_SHT(DRV_NAME),
25838 };
25839
25840 -static struct ata_port_operations pxa_ata_port_ops = {
25841 +static const struct ata_port_operations pxa_ata_port_ops = {
25842 .inherits = &ata_bmdma_port_ops,
25843 .cable_detect = ata_cable_40wire,
25844
25845 diff -urNp linux-2.6.39.1/drivers/ata/pata_qdi.c linux-2.6.39.1/drivers/ata/pata_qdi.c
25846 --- linux-2.6.39.1/drivers/ata/pata_qdi.c 2011-05-19 00:06:34.000000000 -0400
25847 +++ linux-2.6.39.1/drivers/ata/pata_qdi.c 2011-05-22 19:36:31.000000000 -0400
25848 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25849 ATA_PIO_SHT(DRV_NAME),
25850 };
25851
25852 -static struct ata_port_operations qdi6500_port_ops = {
25853 +static const struct ata_port_operations qdi6500_port_ops = {
25854 .inherits = &ata_sff_port_ops,
25855 .qc_issue = qdi_qc_issue,
25856 .sff_data_xfer = qdi_data_xfer,
25857 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
25858 .set_piomode = qdi6500_set_piomode,
25859 };
25860
25861 -static struct ata_port_operations qdi6580_port_ops = {
25862 +static const struct ata_port_operations qdi6580_port_ops = {
25863 .inherits = &qdi6500_port_ops,
25864 .set_piomode = qdi6580_set_piomode,
25865 };
25866 diff -urNp linux-2.6.39.1/drivers/ata/pata_radisys.c linux-2.6.39.1/drivers/ata/pata_radisys.c
25867 --- linux-2.6.39.1/drivers/ata/pata_radisys.c 2011-05-19 00:06:34.000000000 -0400
25868 +++ linux-2.6.39.1/drivers/ata/pata_radisys.c 2011-05-22 19:36:31.000000000 -0400
25869 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys
25870 ATA_BMDMA_SHT(DRV_NAME),
25871 };
25872
25873 -static struct ata_port_operations radisys_pata_ops = {
25874 +static const struct ata_port_operations radisys_pata_ops = {
25875 .inherits = &ata_bmdma_port_ops,
25876 .qc_issue = radisys_qc_issue,
25877 .cable_detect = ata_cable_unknown,
25878 diff -urNp linux-2.6.39.1/drivers/ata/pata_rb532_cf.c linux-2.6.39.1/drivers/ata/pata_rb532_cf.c
25879 --- linux-2.6.39.1/drivers/ata/pata_rb532_cf.c 2011-05-19 00:06:34.000000000 -0400
25880 +++ linux-2.6.39.1/drivers/ata/pata_rb532_cf.c 2011-05-22 19:36:31.000000000 -0400
25881 @@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
25882 return IRQ_HANDLED;
25883 }
25884
25885 -static struct ata_port_operations rb532_pata_port_ops = {
25886 +static const struct ata_port_operations rb532_pata_port_ops = {
25887 .inherits = &ata_sff_port_ops,
25888 .sff_data_xfer = ata_sff_data_xfer32,
25889 };
25890 diff -urNp linux-2.6.39.1/drivers/ata/pata_rdc.c linux-2.6.39.1/drivers/ata/pata_rdc.c
25891 --- linux-2.6.39.1/drivers/ata/pata_rdc.c 2011-05-19 00:06:34.000000000 -0400
25892 +++ linux-2.6.39.1/drivers/ata/pata_rdc.c 2011-05-22 19:36:31.000000000 -0400
25893 @@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
25894 pci_write_config_byte(dev, 0x48, udma_enable);
25895 }
25896
25897 -static struct ata_port_operations rdc_pata_ops = {
25898 +static const struct ata_port_operations rdc_pata_ops = {
25899 .inherits = &ata_bmdma32_port_ops,
25900 .cable_detect = rdc_pata_cable_detect,
25901 .set_piomode = rdc_set_piomode,
25902 diff -urNp linux-2.6.39.1/drivers/ata/pata_rz1000.c linux-2.6.39.1/drivers/ata/pata_rz1000.c
25903 --- linux-2.6.39.1/drivers/ata/pata_rz1000.c 2011-05-19 00:06:34.000000000 -0400
25904 +++ linux-2.6.39.1/drivers/ata/pata_rz1000.c 2011-05-22 19:36:31.000000000 -0400
25905 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
25906 ATA_PIO_SHT(DRV_NAME),
25907 };
25908
25909 -static struct ata_port_operations rz1000_port_ops = {
25910 +static const struct ata_port_operations rz1000_port_ops = {
25911 .inherits = &ata_sff_port_ops,
25912 .cable_detect = ata_cable_40wire,
25913 .set_mode = rz1000_set_mode,
25914 diff -urNp linux-2.6.39.1/drivers/ata/pata_samsung_cf.c linux-2.6.39.1/drivers/ata/pata_samsung_cf.c
25915 --- linux-2.6.39.1/drivers/ata/pata_samsung_cf.c 2011-05-19 00:06:34.000000000 -0400
25916 +++ linux-2.6.39.1/drivers/ata/pata_samsung_cf.c 2011-05-22 19:36:31.000000000 -0400
25917 @@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
25918 ATA_PIO_SHT(DRV_NAME),
25919 };
25920
25921 -static struct ata_port_operations pata_s3c_port_ops = {
25922 +static const struct ata_port_operations pata_s3c_port_ops = {
25923 .inherits = &ata_sff_port_ops,
25924 .sff_check_status = pata_s3c_check_status,
25925 .sff_check_altstatus = pata_s3c_check_altstatus,
25926 @@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
25927 .set_piomode = pata_s3c_set_piomode,
25928 };
25929
25930 -static struct ata_port_operations pata_s5p_port_ops = {
25931 +static const struct ata_port_operations pata_s5p_port_ops = {
25932 .inherits = &ata_sff_port_ops,
25933 .set_piomode = pata_s3c_set_piomode,
25934 };
25935 diff -urNp linux-2.6.39.1/drivers/ata/pata_sc1200.c linux-2.6.39.1/drivers/ata/pata_sc1200.c
25936 --- linux-2.6.39.1/drivers/ata/pata_sc1200.c 2011-05-19 00:06:34.000000000 -0400
25937 +++ linux-2.6.39.1/drivers/ata/pata_sc1200.c 2011-05-22 19:36:31.000000000 -0400
25938 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
25939 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25940 };
25941
25942 -static struct ata_port_operations sc1200_port_ops = {
25943 +static const struct ata_port_operations sc1200_port_ops = {
25944 .inherits = &ata_bmdma_port_ops,
25945 .qc_prep = ata_bmdma_dumb_qc_prep,
25946 .qc_issue = sc1200_qc_issue,
25947 diff -urNp linux-2.6.39.1/drivers/ata/pata_scc.c linux-2.6.39.1/drivers/ata/pata_scc.c
25948 --- linux-2.6.39.1/drivers/ata/pata_scc.c 2011-05-19 00:06:34.000000000 -0400
25949 +++ linux-2.6.39.1/drivers/ata/pata_scc.c 2011-05-22 19:36:31.000000000 -0400
25950 @@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
25951 ATA_BMDMA_SHT(DRV_NAME),
25952 };
25953
25954 -static struct ata_port_operations scc_pata_ops = {
25955 +static const struct ata_port_operations scc_pata_ops = {
25956 .inherits = &ata_bmdma_port_ops,
25957
25958 .set_piomode = scc_set_piomode,
25959 diff -urNp linux-2.6.39.1/drivers/ata/pata_sch.c linux-2.6.39.1/drivers/ata/pata_sch.c
25960 --- linux-2.6.39.1/drivers/ata/pata_sch.c 2011-05-19 00:06:34.000000000 -0400
25961 +++ linux-2.6.39.1/drivers/ata/pata_sch.c 2011-05-22 19:36:31.000000000 -0400
25962 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
25963 ATA_BMDMA_SHT(DRV_NAME),
25964 };
25965
25966 -static struct ata_port_operations sch_pata_ops = {
25967 +static const struct ata_port_operations sch_pata_ops = {
25968 .inherits = &ata_bmdma_port_ops,
25969 .cable_detect = ata_cable_unknown,
25970 .set_piomode = sch_set_piomode,
25971 diff -urNp linux-2.6.39.1/drivers/ata/pata_serverworks.c linux-2.6.39.1/drivers/ata/pata_serverworks.c
25972 --- linux-2.6.39.1/drivers/ata/pata_serverworks.c 2011-05-19 00:06:34.000000000 -0400
25973 +++ linux-2.6.39.1/drivers/ata/pata_serverworks.c 2011-05-22 19:36:31.000000000 -0400
25974 @@ -300,7 +300,7 @@ static struct scsi_host_template serverw
25975 ATA_BMDMA_SHT(DRV_NAME),
25976 };
25977
25978 -static struct ata_port_operations serverworks_osb4_port_ops = {
25979 +static const struct ata_port_operations serverworks_osb4_port_ops = {
25980 .inherits = &ata_bmdma_port_ops,
25981 .cable_detect = serverworks_cable_detect,
25982 .mode_filter = serverworks_osb4_filter,
25983 @@ -308,7 +308,7 @@ static struct ata_port_operations server
25984 .set_dmamode = serverworks_set_dmamode,
25985 };
25986
25987 -static struct ata_port_operations serverworks_csb_port_ops = {
25988 +static const struct ata_port_operations serverworks_csb_port_ops = {
25989 .inherits = &serverworks_osb4_port_ops,
25990 .mode_filter = serverworks_csb_filter,
25991 };
25992 diff -urNp linux-2.6.39.1/drivers/ata/pata_sil680.c linux-2.6.39.1/drivers/ata/pata_sil680.c
25993 --- linux-2.6.39.1/drivers/ata/pata_sil680.c 2011-05-19 00:06:34.000000000 -0400
25994 +++ linux-2.6.39.1/drivers/ata/pata_sil680.c 2011-05-22 19:36:31.000000000 -0400
25995 @@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
25996 ATA_BMDMA_SHT(DRV_NAME),
25997 };
25998
25999 -
26000 -static struct ata_port_operations sil680_port_ops = {
26001 +static const struct ata_port_operations sil680_port_ops = {
26002 .inherits = &ata_bmdma32_port_ops,
26003 .sff_exec_command = sil680_sff_exec_command,
26004 .sff_irq_check = sil680_sff_irq_check,
26005 diff -urNp linux-2.6.39.1/drivers/ata/pata_sis.c linux-2.6.39.1/drivers/ata/pata_sis.c
26006 --- linux-2.6.39.1/drivers/ata/pata_sis.c 2011-05-19 00:06:34.000000000 -0400
26007 +++ linux-2.6.39.1/drivers/ata/pata_sis.c 2011-05-22 19:36:31.000000000 -0400
26008 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
26009 ATA_BMDMA_SHT(DRV_NAME),
26010 };
26011
26012 -static struct ata_port_operations sis_133_for_sata_ops = {
26013 +static const struct ata_port_operations sis_133_for_sata_ops = {
26014 .inherits = &ata_bmdma_port_ops,
26015 .set_piomode = sis_133_set_piomode,
26016 .set_dmamode = sis_133_set_dmamode,
26017 .cable_detect = sis_133_cable_detect,
26018 };
26019
26020 -static struct ata_port_operations sis_base_ops = {
26021 +static const struct ata_port_operations sis_base_ops = {
26022 .inherits = &ata_bmdma_port_ops,
26023 .prereset = sis_pre_reset,
26024 };
26025
26026 -static struct ata_port_operations sis_133_ops = {
26027 +static const struct ata_port_operations sis_133_ops = {
26028 .inherits = &sis_base_ops,
26029 .set_piomode = sis_133_set_piomode,
26030 .set_dmamode = sis_133_set_dmamode,
26031 .cable_detect = sis_133_cable_detect,
26032 };
26033
26034 -static struct ata_port_operations sis_133_early_ops = {
26035 +static const struct ata_port_operations sis_133_early_ops = {
26036 .inherits = &sis_base_ops,
26037 .set_piomode = sis_100_set_piomode,
26038 .set_dmamode = sis_133_early_set_dmamode,
26039 .cable_detect = sis_66_cable_detect,
26040 };
26041
26042 -static struct ata_port_operations sis_100_ops = {
26043 +static const struct ata_port_operations sis_100_ops = {
26044 .inherits = &sis_base_ops,
26045 .set_piomode = sis_100_set_piomode,
26046 .set_dmamode = sis_100_set_dmamode,
26047 .cable_detect = sis_66_cable_detect,
26048 };
26049
26050 -static struct ata_port_operations sis_66_ops = {
26051 +static const struct ata_port_operations sis_66_ops = {
26052 .inherits = &sis_base_ops,
26053 .set_piomode = sis_old_set_piomode,
26054 .set_dmamode = sis_66_set_dmamode,
26055 .cable_detect = sis_66_cable_detect,
26056 };
26057
26058 -static struct ata_port_operations sis_old_ops = {
26059 +static const struct ata_port_operations sis_old_ops = {
26060 .inherits = &sis_base_ops,
26061 .set_piomode = sis_old_set_piomode,
26062 .set_dmamode = sis_old_set_dmamode,
26063 diff -urNp linux-2.6.39.1/drivers/ata/pata_sl82c105.c linux-2.6.39.1/drivers/ata/pata_sl82c105.c
26064 --- linux-2.6.39.1/drivers/ata/pata_sl82c105.c 2011-05-19 00:06:34.000000000 -0400
26065 +++ linux-2.6.39.1/drivers/ata/pata_sl82c105.c 2011-05-22 19:36:31.000000000 -0400
26066 @@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
26067 ATA_BMDMA_SHT(DRV_NAME),
26068 };
26069
26070 -static struct ata_port_operations sl82c105_port_ops = {
26071 +static const struct ata_port_operations sl82c105_port_ops = {
26072 .inherits = &ata_bmdma_port_ops,
26073 .qc_defer = sl82c105_qc_defer,
26074 .bmdma_start = sl82c105_bmdma_start,
26075 diff -urNp linux-2.6.39.1/drivers/ata/pata_triflex.c linux-2.6.39.1/drivers/ata/pata_triflex.c
26076 --- linux-2.6.39.1/drivers/ata/pata_triflex.c 2011-05-19 00:06:34.000000000 -0400
26077 +++ linux-2.6.39.1/drivers/ata/pata_triflex.c 2011-05-22 19:36:31.000000000 -0400
26078 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex
26079 ATA_BMDMA_SHT(DRV_NAME),
26080 };
26081
26082 -static struct ata_port_operations triflex_port_ops = {
26083 +static const struct ata_port_operations triflex_port_ops = {
26084 .inherits = &ata_bmdma_port_ops,
26085 .bmdma_start = triflex_bmdma_start,
26086 .bmdma_stop = triflex_bmdma_stop,
26087 diff -urNp linux-2.6.39.1/drivers/ata/pata_via.c linux-2.6.39.1/drivers/ata/pata_via.c
26088 --- linux-2.6.39.1/drivers/ata/pata_via.c 2011-05-19 00:06:34.000000000 -0400
26089 +++ linux-2.6.39.1/drivers/ata/pata_via.c 2011-05-22 19:36:31.000000000 -0400
26090 @@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
26091 ATA_BMDMA_SHT(DRV_NAME),
26092 };
26093
26094 -static struct ata_port_operations via_port_ops = {
26095 +static const struct ata_port_operations via_port_ops = {
26096 .inherits = &ata_bmdma_port_ops,
26097 .cable_detect = via_cable_detect,
26098 .set_piomode = via_set_piomode,
26099 @@ -452,7 +452,7 @@ static struct ata_port_operations via_po
26100 .mode_filter = via_mode_filter,
26101 };
26102
26103 -static struct ata_port_operations via_port_ops_noirq = {
26104 +static const struct ata_port_operations via_port_ops_noirq = {
26105 .inherits = &via_port_ops,
26106 .sff_data_xfer = ata_sff_data_xfer_noirq,
26107 };
26108 diff -urNp linux-2.6.39.1/drivers/ata/pdc_adma.c linux-2.6.39.1/drivers/ata/pdc_adma.c
26109 --- linux-2.6.39.1/drivers/ata/pdc_adma.c 2011-05-19 00:06:34.000000000 -0400
26110 +++ linux-2.6.39.1/drivers/ata/pdc_adma.c 2011-05-22 19:36:31.000000000 -0400
26111 @@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
26112 .dma_boundary = ADMA_DMA_BOUNDARY,
26113 };
26114
26115 -static struct ata_port_operations adma_ata_ops = {
26116 +static const struct ata_port_operations adma_ata_ops = {
26117 .inherits = &ata_sff_port_ops,
26118
26119 .lost_interrupt = ATA_OP_NULL,
26120 diff -urNp linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c
26121 --- linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c 2011-05-19 00:06:34.000000000 -0400
26122 +++ linux-2.6.39.1/drivers/ata/sata_dwc_460ex.c 2011-05-22 19:36:31.000000000 -0400
26123 @@ -1598,7 +1598,7 @@ static struct scsi_host_template sata_dw
26124 .dma_boundary = ATA_DMA_BOUNDARY,
26125 };
26126
26127 -static struct ata_port_operations sata_dwc_ops = {
26128 +static const struct ata_port_operations sata_dwc_ops = {
26129 .inherits = &ata_sff_port_ops,
26130
26131 .error_handler = sata_dwc_error_handler,
26132 diff -urNp linux-2.6.39.1/drivers/ata/sata_fsl.c linux-2.6.39.1/drivers/ata/sata_fsl.c
26133 --- linux-2.6.39.1/drivers/ata/sata_fsl.c 2011-05-19 00:06:34.000000000 -0400
26134 +++ linux-2.6.39.1/drivers/ata/sata_fsl.c 2011-05-22 19:36:31.000000000 -0400
26135 @@ -1268,7 +1268,7 @@ static struct scsi_host_template sata_fs
26136 .dma_boundary = ATA_DMA_BOUNDARY,
26137 };
26138
26139 -static struct ata_port_operations sata_fsl_ops = {
26140 +static const struct ata_port_operations sata_fsl_ops = {
26141 .inherits = &sata_pmp_port_ops,
26142
26143 .qc_defer = ata_std_qc_defer,
26144 diff -urNp linux-2.6.39.1/drivers/ata/sata_inic162x.c linux-2.6.39.1/drivers/ata/sata_inic162x.c
26145 --- linux-2.6.39.1/drivers/ata/sata_inic162x.c 2011-05-19 00:06:34.000000000 -0400
26146 +++ linux-2.6.39.1/drivers/ata/sata_inic162x.c 2011-05-22 19:36:31.000000000 -0400
26147 @@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
26148 return 0;
26149 }
26150
26151 -static struct ata_port_operations inic_port_ops = {
26152 +static const struct ata_port_operations inic_port_ops = {
26153 .inherits = &sata_port_ops,
26154
26155 .check_atapi_dma = inic_check_atapi_dma,
26156 diff -urNp linux-2.6.39.1/drivers/ata/sata_mv.c linux-2.6.39.1/drivers/ata/sata_mv.c
26157 --- linux-2.6.39.1/drivers/ata/sata_mv.c 2011-05-19 00:06:34.000000000 -0400
26158 +++ linux-2.6.39.1/drivers/ata/sata_mv.c 2011-05-22 19:36:31.000000000 -0400
26159 @@ -662,7 +662,7 @@ static struct scsi_host_template mv6_sht
26160 .dma_boundary = MV_DMA_BOUNDARY,
26161 };
26162
26163 -static struct ata_port_operations mv5_ops = {
26164 +static const struct ata_port_operations mv5_ops = {
26165 .inherits = &ata_sff_port_ops,
26166
26167 .lost_interrupt = ATA_OP_NULL,
26168 @@ -682,7 +682,7 @@ static struct ata_port_operations mv5_op
26169 .port_stop = mv_port_stop,
26170 };
26171
26172 -static struct ata_port_operations mv6_ops = {
26173 +static const struct ata_port_operations mv6_ops = {
26174 .inherits = &ata_bmdma_port_ops,
26175
26176 .lost_interrupt = ATA_OP_NULL,
26177 @@ -716,7 +716,7 @@ static struct ata_port_operations mv6_op
26178 .port_stop = mv_port_stop,
26179 };
26180
26181 -static struct ata_port_operations mv_iie_ops = {
26182 +static const struct ata_port_operations mv_iie_ops = {
26183 .inherits = &mv6_ops,
26184 .dev_config = ATA_OP_NULL,
26185 .qc_prep = mv_qc_prep_iie,
26186 diff -urNp linux-2.6.39.1/drivers/ata/sata_nv.c linux-2.6.39.1/drivers/ata/sata_nv.c
26187 --- linux-2.6.39.1/drivers/ata/sata_nv.c 2011-05-19 00:06:34.000000000 -0400
26188 +++ linux-2.6.39.1/drivers/ata/sata_nv.c 2011-05-22 19:36:31.000000000 -0400
26189 @@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
26190 * cases. Define nv_hardreset() which only kicks in for post-boot
26191 * probing and use it for all variants.
26192 */
26193 -static struct ata_port_operations nv_generic_ops = {
26194 +static const struct ata_port_operations nv_generic_ops = {
26195 .inherits = &ata_bmdma_port_ops,
26196 .lost_interrupt = ATA_OP_NULL,
26197 .scr_read = nv_scr_read,
26198 @@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
26199 .hardreset = nv_hardreset,
26200 };
26201
26202 -static struct ata_port_operations nv_nf2_ops = {
26203 +static const struct ata_port_operations nv_nf2_ops = {
26204 .inherits = &nv_generic_ops,
26205 .freeze = nv_nf2_freeze,
26206 .thaw = nv_nf2_thaw,
26207 };
26208
26209 -static struct ata_port_operations nv_ck804_ops = {
26210 +static const struct ata_port_operations nv_ck804_ops = {
26211 .inherits = &nv_generic_ops,
26212 .freeze = nv_ck804_freeze,
26213 .thaw = nv_ck804_thaw,
26214 .host_stop = nv_ck804_host_stop,
26215 };
26216
26217 -static struct ata_port_operations nv_adma_ops = {
26218 +static const struct ata_port_operations nv_adma_ops = {
26219 .inherits = &nv_ck804_ops,
26220
26221 .check_atapi_dma = nv_adma_check_atapi_dma,
26222 @@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
26223 .host_stop = nv_adma_host_stop,
26224 };
26225
26226 -static struct ata_port_operations nv_swncq_ops = {
26227 +static const struct ata_port_operations nv_swncq_ops = {
26228 .inherits = &nv_generic_ops,
26229
26230 .qc_defer = ata_std_qc_defer,
26231 diff -urNp linux-2.6.39.1/drivers/ata/sata_promise.c linux-2.6.39.1/drivers/ata/sata_promise.c
26232 --- linux-2.6.39.1/drivers/ata/sata_promise.c 2011-05-19 00:06:34.000000000 -0400
26233 +++ linux-2.6.39.1/drivers/ata/sata_promise.c 2011-05-22 19:36:31.000000000 -0400
26234 @@ -194,7 +194,7 @@ static const struct ata_port_operations
26235 .error_handler = pdc_error_handler,
26236 };
26237
26238 -static struct ata_port_operations pdc_sata_ops = {
26239 +static const struct ata_port_operations pdc_sata_ops = {
26240 .inherits = &pdc_common_ops,
26241 .cable_detect = pdc_sata_cable_detect,
26242 .freeze = pdc_sata_freeze,
26243 @@ -207,14 +207,14 @@ static struct ata_port_operations pdc_sa
26244
26245 /* First-generation chips need a more restrictive ->check_atapi_dma op,
26246 and ->freeze/thaw that ignore the hotplug controls. */
26247 -static struct ata_port_operations pdc_old_sata_ops = {
26248 +static const struct ata_port_operations pdc_old_sata_ops = {
26249 .inherits = &pdc_sata_ops,
26250 .freeze = pdc_freeze,
26251 .thaw = pdc_thaw,
26252 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
26253 };
26254
26255 -static struct ata_port_operations pdc_pata_ops = {
26256 +static const struct ata_port_operations pdc_pata_ops = {
26257 .inherits = &pdc_common_ops,
26258 .cable_detect = pdc_pata_cable_detect,
26259 .freeze = pdc_freeze,
26260 diff -urNp linux-2.6.39.1/drivers/ata/sata_qstor.c linux-2.6.39.1/drivers/ata/sata_qstor.c
26261 --- linux-2.6.39.1/drivers/ata/sata_qstor.c 2011-05-19 00:06:34.000000000 -0400
26262 +++ linux-2.6.39.1/drivers/ata/sata_qstor.c 2011-05-22 19:36:31.000000000 -0400
26263 @@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
26264 .dma_boundary = QS_DMA_BOUNDARY,
26265 };
26266
26267 -static struct ata_port_operations qs_ata_ops = {
26268 +static const struct ata_port_operations qs_ata_ops = {
26269 .inherits = &ata_sff_port_ops,
26270
26271 .check_atapi_dma = qs_check_atapi_dma,
26272 diff -urNp linux-2.6.39.1/drivers/ata/sata_sil24.c linux-2.6.39.1/drivers/ata/sata_sil24.c
26273 --- linux-2.6.39.1/drivers/ata/sata_sil24.c 2011-05-19 00:06:34.000000000 -0400
26274 +++ linux-2.6.39.1/drivers/ata/sata_sil24.c 2011-05-22 19:36:31.000000000 -0400
26275 @@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
26276 .dma_boundary = ATA_DMA_BOUNDARY,
26277 };
26278
26279 -static struct ata_port_operations sil24_ops = {
26280 +static const struct ata_port_operations sil24_ops = {
26281 .inherits = &sata_pmp_port_ops,
26282
26283 .qc_defer = sil24_qc_defer,
26284 diff -urNp linux-2.6.39.1/drivers/ata/sata_sil.c linux-2.6.39.1/drivers/ata/sata_sil.c
26285 --- linux-2.6.39.1/drivers/ata/sata_sil.c 2011-05-19 00:06:34.000000000 -0400
26286 +++ linux-2.6.39.1/drivers/ata/sata_sil.c 2011-05-22 19:36:31.000000000 -0400
26287 @@ -181,7 +181,7 @@ static struct scsi_host_template sil_sht
26288 .sg_tablesize = ATA_MAX_PRD
26289 };
26290
26291 -static struct ata_port_operations sil_ops = {
26292 +static const struct ata_port_operations sil_ops = {
26293 .inherits = &ata_bmdma32_port_ops,
26294 .dev_config = sil_dev_config,
26295 .set_mode = sil_set_mode,
26296 diff -urNp linux-2.6.39.1/drivers/ata/sata_sis.c linux-2.6.39.1/drivers/ata/sata_sis.c
26297 --- linux-2.6.39.1/drivers/ata/sata_sis.c 2011-05-19 00:06:34.000000000 -0400
26298 +++ linux-2.6.39.1/drivers/ata/sata_sis.c 2011-05-22 19:36:31.000000000 -0400
26299 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
26300 ATA_BMDMA_SHT(DRV_NAME),
26301 };
26302
26303 -static struct ata_port_operations sis_ops = {
26304 +static const struct ata_port_operations sis_ops = {
26305 .inherits = &ata_bmdma_port_ops,
26306 .scr_read = sis_scr_read,
26307 .scr_write = sis_scr_write,
26308 diff -urNp linux-2.6.39.1/drivers/ata/sata_svw.c linux-2.6.39.1/drivers/ata/sata_svw.c
26309 --- linux-2.6.39.1/drivers/ata/sata_svw.c 2011-05-19 00:06:34.000000000 -0400
26310 +++ linux-2.6.39.1/drivers/ata/sata_svw.c 2011-05-22 19:36:31.000000000 -0400
26311 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
26312 };
26313
26314
26315 -static struct ata_port_operations k2_sata_ops = {
26316 +static const struct ata_port_operations k2_sata_ops = {
26317 .inherits = &ata_bmdma_port_ops,
26318 .sff_tf_load = k2_sata_tf_load,
26319 .sff_tf_read = k2_sata_tf_read,
26320 diff -urNp linux-2.6.39.1/drivers/ata/sata_sx4.c linux-2.6.39.1/drivers/ata/sata_sx4.c
26321 --- linux-2.6.39.1/drivers/ata/sata_sx4.c 2011-05-19 00:06:34.000000000 -0400
26322 +++ linux-2.6.39.1/drivers/ata/sata_sx4.c 2011-05-22 19:36:31.000000000 -0400
26323 @@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
26324 };
26325
26326 /* TODO: inherit from base port_ops after converting to new EH */
26327 -static struct ata_port_operations pdc_20621_ops = {
26328 +static const struct ata_port_operations pdc_20621_ops = {
26329 .inherits = &ata_sff_port_ops,
26330
26331 .check_atapi_dma = pdc_check_atapi_dma,
26332 diff -urNp linux-2.6.39.1/drivers/ata/sata_uli.c linux-2.6.39.1/drivers/ata/sata_uli.c
26333 --- linux-2.6.39.1/drivers/ata/sata_uli.c 2011-05-19 00:06:34.000000000 -0400
26334 +++ linux-2.6.39.1/drivers/ata/sata_uli.c 2011-05-22 19:36:31.000000000 -0400
26335 @@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
26336 ATA_BMDMA_SHT(DRV_NAME),
26337 };
26338
26339 -static struct ata_port_operations uli_ops = {
26340 +static const struct ata_port_operations uli_ops = {
26341 .inherits = &ata_bmdma_port_ops,
26342 .scr_read = uli_scr_read,
26343 .scr_write = uli_scr_write,
26344 diff -urNp linux-2.6.39.1/drivers/ata/sata_via.c linux-2.6.39.1/drivers/ata/sata_via.c
26345 --- linux-2.6.39.1/drivers/ata/sata_via.c 2011-05-19 00:06:34.000000000 -0400
26346 +++ linux-2.6.39.1/drivers/ata/sata_via.c 2011-05-22 19:36:31.000000000 -0400
26347 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
26348 ATA_BMDMA_SHT(DRV_NAME),
26349 };
26350
26351 -static struct ata_port_operations svia_base_ops = {
26352 +static const struct ata_port_operations svia_base_ops = {
26353 .inherits = &ata_bmdma_port_ops,
26354 .sff_tf_load = svia_tf_load,
26355 };
26356
26357 -static struct ata_port_operations vt6420_sata_ops = {
26358 +static const struct ata_port_operations vt6420_sata_ops = {
26359 .inherits = &svia_base_ops,
26360 .freeze = svia_noop_freeze,
26361 .prereset = vt6420_prereset,
26362 .bmdma_start = vt6420_bmdma_start,
26363 };
26364
26365 -static struct ata_port_operations vt6421_pata_ops = {
26366 +static const struct ata_port_operations vt6421_pata_ops = {
26367 .inherits = &svia_base_ops,
26368 .cable_detect = vt6421_pata_cable_detect,
26369 .set_piomode = vt6421_set_pio_mode,
26370 .set_dmamode = vt6421_set_dma_mode,
26371 };
26372
26373 -static struct ata_port_operations vt6421_sata_ops = {
26374 +static const struct ata_port_operations vt6421_sata_ops = {
26375 .inherits = &svia_base_ops,
26376 .scr_read = svia_scr_read,
26377 .scr_write = svia_scr_write,
26378 };
26379
26380 -static struct ata_port_operations vt8251_ops = {
26381 +static const struct ata_port_operations vt8251_ops = {
26382 .inherits = &svia_base_ops,
26383 .hardreset = sata_std_hardreset,
26384 .scr_read = vt8251_scr_read,
26385 diff -urNp linux-2.6.39.1/drivers/ata/sata_vsc.c linux-2.6.39.1/drivers/ata/sata_vsc.c
26386 --- linux-2.6.39.1/drivers/ata/sata_vsc.c 2011-05-19 00:06:34.000000000 -0400
26387 +++ linux-2.6.39.1/drivers/ata/sata_vsc.c 2011-05-22 19:36:31.000000000 -0400
26388 @@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
26389 };
26390
26391
26392 -static struct ata_port_operations vsc_sata_ops = {
26393 +static const struct ata_port_operations vsc_sata_ops = {
26394 .inherits = &ata_bmdma_port_ops,
26395 /* The IRQ handling is not quite standard SFF behaviour so we
26396 cannot use the default lost interrupt handler */
26397 diff -urNp linux-2.6.39.1/drivers/atm/adummy.c linux-2.6.39.1/drivers/atm/adummy.c
26398 --- linux-2.6.39.1/drivers/atm/adummy.c 2011-05-19 00:06:34.000000000 -0400
26399 +++ linux-2.6.39.1/drivers/atm/adummy.c 2011-05-22 19:36:31.000000000 -0400
26400 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
26401 vcc->pop(vcc, skb);
26402 else
26403 dev_kfree_skb_any(skb);
26404 - atomic_inc(&vcc->stats->tx);
26405 + atomic_inc_unchecked(&vcc->stats->tx);
26406
26407 return 0;
26408 }
26409 diff -urNp linux-2.6.39.1/drivers/atm/ambassador.c linux-2.6.39.1/drivers/atm/ambassador.c
26410 --- linux-2.6.39.1/drivers/atm/ambassador.c 2011-05-19 00:06:34.000000000 -0400
26411 +++ linux-2.6.39.1/drivers/atm/ambassador.c 2011-05-22 19:36:31.000000000 -0400
26412 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
26413 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26414
26415 // VC layer stats
26416 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26417 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26418
26419 // free the descriptor
26420 kfree (tx_descr);
26421 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
26422 dump_skb ("<<<", vc, skb);
26423
26424 // VC layer stats
26425 - atomic_inc(&atm_vcc->stats->rx);
26426 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26427 __net_timestamp(skb);
26428 // end of our responsibility
26429 atm_vcc->push (atm_vcc, skb);
26430 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
26431 } else {
26432 PRINTK (KERN_INFO, "dropped over-size frame");
26433 // should we count this?
26434 - atomic_inc(&atm_vcc->stats->rx_drop);
26435 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26436 }
26437
26438 } else {
26439 @@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
26440 }
26441
26442 if (check_area (skb->data, skb->len)) {
26443 - atomic_inc(&atm_vcc->stats->tx_err);
26444 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26445 return -ENOMEM; // ?
26446 }
26447
26448 diff -urNp linux-2.6.39.1/drivers/atm/atmtcp.c linux-2.6.39.1/drivers/atm/atmtcp.c
26449 --- linux-2.6.39.1/drivers/atm/atmtcp.c 2011-05-19 00:06:34.000000000 -0400
26450 +++ linux-2.6.39.1/drivers/atm/atmtcp.c 2011-05-22 19:36:31.000000000 -0400
26451 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
26452 if (vcc->pop) vcc->pop(vcc,skb);
26453 else dev_kfree_skb(skb);
26454 if (dev_data) return 0;
26455 - atomic_inc(&vcc->stats->tx_err);
26456 + atomic_inc_unchecked(&vcc->stats->tx_err);
26457 return -ENOLINK;
26458 }
26459 size = skb->len+sizeof(struct atmtcp_hdr);
26460 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
26461 if (!new_skb) {
26462 if (vcc->pop) vcc->pop(vcc,skb);
26463 else dev_kfree_skb(skb);
26464 - atomic_inc(&vcc->stats->tx_err);
26465 + atomic_inc_unchecked(&vcc->stats->tx_err);
26466 return -ENOBUFS;
26467 }
26468 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26469 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
26470 if (vcc->pop) vcc->pop(vcc,skb);
26471 else dev_kfree_skb(skb);
26472 out_vcc->push(out_vcc,new_skb);
26473 - atomic_inc(&vcc->stats->tx);
26474 - atomic_inc(&out_vcc->stats->rx);
26475 + atomic_inc_unchecked(&vcc->stats->tx);
26476 + atomic_inc_unchecked(&out_vcc->stats->rx);
26477 return 0;
26478 }
26479
26480 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
26481 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26482 read_unlock(&vcc_sklist_lock);
26483 if (!out_vcc) {
26484 - atomic_inc(&vcc->stats->tx_err);
26485 + atomic_inc_unchecked(&vcc->stats->tx_err);
26486 goto done;
26487 }
26488 skb_pull(skb,sizeof(struct atmtcp_hdr));
26489 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
26490 __net_timestamp(new_skb);
26491 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26492 out_vcc->push(out_vcc,new_skb);
26493 - atomic_inc(&vcc->stats->tx);
26494 - atomic_inc(&out_vcc->stats->rx);
26495 + atomic_inc_unchecked(&vcc->stats->tx);
26496 + atomic_inc_unchecked(&out_vcc->stats->rx);
26497 done:
26498 if (vcc->pop) vcc->pop(vcc,skb);
26499 else dev_kfree_skb(skb);
26500 diff -urNp linux-2.6.39.1/drivers/atm/eni.c linux-2.6.39.1/drivers/atm/eni.c
26501 --- linux-2.6.39.1/drivers/atm/eni.c 2011-05-19 00:06:34.000000000 -0400
26502 +++ linux-2.6.39.1/drivers/atm/eni.c 2011-05-22 19:36:31.000000000 -0400
26503 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26504 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26505 vcc->dev->number);
26506 length = 0;
26507 - atomic_inc(&vcc->stats->rx_err);
26508 + atomic_inc_unchecked(&vcc->stats->rx_err);
26509 }
26510 else {
26511 length = ATM_CELL_SIZE-1; /* no HEC */
26512 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26513 size);
26514 }
26515 eff = length = 0;
26516 - atomic_inc(&vcc->stats->rx_err);
26517 + atomic_inc_unchecked(&vcc->stats->rx_err);
26518 }
26519 else {
26520 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26521 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26522 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26523 vcc->dev->number,vcc->vci,length,size << 2,descr);
26524 length = eff = 0;
26525 - atomic_inc(&vcc->stats->rx_err);
26526 + atomic_inc_unchecked(&vcc->stats->rx_err);
26527 }
26528 }
26529 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26530 @@ -771,7 +771,7 @@ rx_dequeued++;
26531 vcc->push(vcc,skb);
26532 pushed++;
26533 }
26534 - atomic_inc(&vcc->stats->rx);
26535 + atomic_inc_unchecked(&vcc->stats->rx);
26536 }
26537 wake_up(&eni_dev->rx_wait);
26538 }
26539 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
26540 PCI_DMA_TODEVICE);
26541 if (vcc->pop) vcc->pop(vcc,skb);
26542 else dev_kfree_skb_irq(skb);
26543 - atomic_inc(&vcc->stats->tx);
26544 + atomic_inc_unchecked(&vcc->stats->tx);
26545 wake_up(&eni_dev->tx_wait);
26546 dma_complete++;
26547 }
26548 diff -urNp linux-2.6.39.1/drivers/atm/firestream.c linux-2.6.39.1/drivers/atm/firestream.c
26549 --- linux-2.6.39.1/drivers/atm/firestream.c 2011-05-19 00:06:34.000000000 -0400
26550 +++ linux-2.6.39.1/drivers/atm/firestream.c 2011-05-22 19:36:31.000000000 -0400
26551 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct
26552 }
26553 }
26554
26555 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26556 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26557
26558 fs_dprintk (FS_DEBUG_TXMEM, "i");
26559 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26560 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_
26561 #endif
26562 skb_put (skb, qe->p1 & 0xffff);
26563 ATM_SKB(skb)->vcc = atm_vcc;
26564 - atomic_inc(&atm_vcc->stats->rx);
26565 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26566 __net_timestamp(skb);
26567 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26568 atm_vcc->push (atm_vcc, skb);
26569 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_
26570 kfree (pe);
26571 }
26572 if (atm_vcc)
26573 - atomic_inc(&atm_vcc->stats->rx_drop);
26574 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26575 break;
26576 case 0x1f: /* Reassembly abort: no buffers. */
26577 /* Silently increment error counter. */
26578 if (atm_vcc)
26579 - atomic_inc(&atm_vcc->stats->rx_drop);
26580 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26581 break;
26582 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26583 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26584 diff -urNp linux-2.6.39.1/drivers/atm/fore200e.c linux-2.6.39.1/drivers/atm/fore200e.c
26585 --- linux-2.6.39.1/drivers/atm/fore200e.c 2011-05-19 00:06:34.000000000 -0400
26586 +++ linux-2.6.39.1/drivers/atm/fore200e.c 2011-05-22 19:36:31.000000000 -0400
26587 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
26588 #endif
26589 /* check error condition */
26590 if (*entry->status & STATUS_ERROR)
26591 - atomic_inc(&vcc->stats->tx_err);
26592 + atomic_inc_unchecked(&vcc->stats->tx_err);
26593 else
26594 - atomic_inc(&vcc->stats->tx);
26595 + atomic_inc_unchecked(&vcc->stats->tx);
26596 }
26597 }
26598
26599 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
26600 if (skb == NULL) {
26601 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26602
26603 - atomic_inc(&vcc->stats->rx_drop);
26604 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26605 return -ENOMEM;
26606 }
26607
26608 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
26609
26610 dev_kfree_skb_any(skb);
26611
26612 - atomic_inc(&vcc->stats->rx_drop);
26613 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26614 return -ENOMEM;
26615 }
26616
26617 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26618
26619 vcc->push(vcc, skb);
26620 - atomic_inc(&vcc->stats->rx);
26621 + atomic_inc_unchecked(&vcc->stats->rx);
26622
26623 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26624
26625 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
26626 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26627 fore200e->atm_dev->number,
26628 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26629 - atomic_inc(&vcc->stats->rx_err);
26630 + atomic_inc_unchecked(&vcc->stats->rx_err);
26631 }
26632 }
26633
26634 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26635 goto retry_here;
26636 }
26637
26638 - atomic_inc(&vcc->stats->tx_err);
26639 + atomic_inc_unchecked(&vcc->stats->tx_err);
26640
26641 fore200e->tx_sat++;
26642 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26643 diff -urNp linux-2.6.39.1/drivers/atm/he.c linux-2.6.39.1/drivers/atm/he.c
26644 --- linux-2.6.39.1/drivers/atm/he.c 2011-05-19 00:06:34.000000000 -0400
26645 +++ linux-2.6.39.1/drivers/atm/he.c 2011-05-22 19:36:31.000000000 -0400
26646 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26647
26648 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26649 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26650 - atomic_inc(&vcc->stats->rx_drop);
26651 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26652 goto return_host_buffers;
26653 }
26654
26655 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26656 RBRQ_LEN_ERR(he_dev->rbrq_head)
26657 ? "LEN_ERR" : "",
26658 vcc->vpi, vcc->vci);
26659 - atomic_inc(&vcc->stats->rx_err);
26660 + atomic_inc_unchecked(&vcc->stats->rx_err);
26661 goto return_host_buffers;
26662 }
26663
26664 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26665 vcc->push(vcc, skb);
26666 spin_lock(&he_dev->global_lock);
26667
26668 - atomic_inc(&vcc->stats->rx);
26669 + atomic_inc_unchecked(&vcc->stats->rx);
26670
26671 return_host_buffers:
26672 ++pdus_assembled;
26673 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26674 tpd->vcc->pop(tpd->vcc, tpd->skb);
26675 else
26676 dev_kfree_skb_any(tpd->skb);
26677 - atomic_inc(&tpd->vcc->stats->tx_err);
26678 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26679 }
26680 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26681 return;
26682 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26683 vcc->pop(vcc, skb);
26684 else
26685 dev_kfree_skb_any(skb);
26686 - atomic_inc(&vcc->stats->tx_err);
26687 + atomic_inc_unchecked(&vcc->stats->tx_err);
26688 return -EINVAL;
26689 }
26690
26691 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26692 vcc->pop(vcc, skb);
26693 else
26694 dev_kfree_skb_any(skb);
26695 - atomic_inc(&vcc->stats->tx_err);
26696 + atomic_inc_unchecked(&vcc->stats->tx_err);
26697 return -EINVAL;
26698 }
26699 #endif
26700 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26701 vcc->pop(vcc, skb);
26702 else
26703 dev_kfree_skb_any(skb);
26704 - atomic_inc(&vcc->stats->tx_err);
26705 + atomic_inc_unchecked(&vcc->stats->tx_err);
26706 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26707 return -ENOMEM;
26708 }
26709 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26710 vcc->pop(vcc, skb);
26711 else
26712 dev_kfree_skb_any(skb);
26713 - atomic_inc(&vcc->stats->tx_err);
26714 + atomic_inc_unchecked(&vcc->stats->tx_err);
26715 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26716 return -ENOMEM;
26717 }
26718 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26719 __enqueue_tpd(he_dev, tpd, cid);
26720 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26721
26722 - atomic_inc(&vcc->stats->tx);
26723 + atomic_inc_unchecked(&vcc->stats->tx);
26724
26725 return 0;
26726 }
26727 diff -urNp linux-2.6.39.1/drivers/atm/horizon.c linux-2.6.39.1/drivers/atm/horizon.c
26728 --- linux-2.6.39.1/drivers/atm/horizon.c 2011-05-19 00:06:34.000000000 -0400
26729 +++ linux-2.6.39.1/drivers/atm/horizon.c 2011-05-22 19:36:31.000000000 -0400
26730 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
26731 {
26732 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26733 // VC layer stats
26734 - atomic_inc(&vcc->stats->rx);
26735 + atomic_inc_unchecked(&vcc->stats->rx);
26736 __net_timestamp(skb);
26737 // end of our responsibility
26738 vcc->push (vcc, skb);
26739 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
26740 dev->tx_iovec = NULL;
26741
26742 // VC layer stats
26743 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26744 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26745
26746 // free the skb
26747 hrz_kfree_skb (skb);
26748 diff -urNp linux-2.6.39.1/drivers/atm/idt77252.c linux-2.6.39.1/drivers/atm/idt77252.c
26749 --- linux-2.6.39.1/drivers/atm/idt77252.c 2011-05-19 00:06:34.000000000 -0400
26750 +++ linux-2.6.39.1/drivers/atm/idt77252.c 2011-05-22 19:36:31.000000000 -0400
26751 @@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
26752 else
26753 dev_kfree_skb(skb);
26754
26755 - atomic_inc(&vcc->stats->tx);
26756 + atomic_inc_unchecked(&vcc->stats->tx);
26757 }
26758
26759 atomic_dec(&scq->used);
26760 @@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
26761 if ((sb = dev_alloc_skb(64)) == NULL) {
26762 printk("%s: Can't allocate buffers for aal0.\n",
26763 card->name);
26764 - atomic_add(i, &vcc->stats->rx_drop);
26765 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26766 break;
26767 }
26768 if (!atm_charge(vcc, sb->truesize)) {
26769 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26770 card->name);
26771 - atomic_add(i - 1, &vcc->stats->rx_drop);
26772 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26773 dev_kfree_skb(sb);
26774 break;
26775 }
26776 @@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
26777 ATM_SKB(sb)->vcc = vcc;
26778 __net_timestamp(sb);
26779 vcc->push(vcc, sb);
26780 - atomic_inc(&vcc->stats->rx);
26781 + atomic_inc_unchecked(&vcc->stats->rx);
26782
26783 cell += ATM_CELL_PAYLOAD;
26784 }
26785 @@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
26786 "(CDC: %08x)\n",
26787 card->name, len, rpp->len, readl(SAR_REG_CDC));
26788 recycle_rx_pool_skb(card, rpp);
26789 - atomic_inc(&vcc->stats->rx_err);
26790 + atomic_inc_unchecked(&vcc->stats->rx_err);
26791 return;
26792 }
26793 if (stat & SAR_RSQE_CRC) {
26794 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26795 recycle_rx_pool_skb(card, rpp);
26796 - atomic_inc(&vcc->stats->rx_err);
26797 + atomic_inc_unchecked(&vcc->stats->rx_err);
26798 return;
26799 }
26800 if (skb_queue_len(&rpp->queue) > 1) {
26801 @@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
26802 RXPRINTK("%s: Can't alloc RX skb.\n",
26803 card->name);
26804 recycle_rx_pool_skb(card, rpp);
26805 - atomic_inc(&vcc->stats->rx_err);
26806 + atomic_inc_unchecked(&vcc->stats->rx_err);
26807 return;
26808 }
26809 if (!atm_charge(vcc, skb->truesize)) {
26810 @@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
26811 __net_timestamp(skb);
26812
26813 vcc->push(vcc, skb);
26814 - atomic_inc(&vcc->stats->rx);
26815 + atomic_inc_unchecked(&vcc->stats->rx);
26816
26817 return;
26818 }
26819 @@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
26820 __net_timestamp(skb);
26821
26822 vcc->push(vcc, skb);
26823 - atomic_inc(&vcc->stats->rx);
26824 + atomic_inc_unchecked(&vcc->stats->rx);
26825
26826 if (skb->truesize > SAR_FB_SIZE_3)
26827 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26828 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26829 if (vcc->qos.aal != ATM_AAL0) {
26830 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26831 card->name, vpi, vci);
26832 - atomic_inc(&vcc->stats->rx_drop);
26833 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26834 goto drop;
26835 }
26836
26837 if ((sb = dev_alloc_skb(64)) == NULL) {
26838 printk("%s: Can't allocate buffers for AAL0.\n",
26839 card->name);
26840 - atomic_inc(&vcc->stats->rx_err);
26841 + atomic_inc_unchecked(&vcc->stats->rx_err);
26842 goto drop;
26843 }
26844
26845 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26846 ATM_SKB(sb)->vcc = vcc;
26847 __net_timestamp(sb);
26848 vcc->push(vcc, sb);
26849 - atomic_inc(&vcc->stats->rx);
26850 + atomic_inc_unchecked(&vcc->stats->rx);
26851
26852 drop:
26853 skb_pull(queue, 64);
26854 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26855
26856 if (vc == NULL) {
26857 printk("%s: NULL connection in send().\n", card->name);
26858 - atomic_inc(&vcc->stats->tx_err);
26859 + atomic_inc_unchecked(&vcc->stats->tx_err);
26860 dev_kfree_skb(skb);
26861 return -EINVAL;
26862 }
26863 if (!test_bit(VCF_TX, &vc->flags)) {
26864 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
26865 - atomic_inc(&vcc->stats->tx_err);
26866 + atomic_inc_unchecked(&vcc->stats->tx_err);
26867 dev_kfree_skb(skb);
26868 return -EINVAL;
26869 }
26870 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26871 break;
26872 default:
26873 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
26874 - atomic_inc(&vcc->stats->tx_err);
26875 + atomic_inc_unchecked(&vcc->stats->tx_err);
26876 dev_kfree_skb(skb);
26877 return -EINVAL;
26878 }
26879
26880 if (skb_shinfo(skb)->nr_frags != 0) {
26881 printk("%s: No scatter-gather yet.\n", card->name);
26882 - atomic_inc(&vcc->stats->tx_err);
26883 + atomic_inc_unchecked(&vcc->stats->tx_err);
26884 dev_kfree_skb(skb);
26885 return -EINVAL;
26886 }
26887 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26888
26889 err = queue_skb(card, vc, skb, oam);
26890 if (err) {
26891 - atomic_inc(&vcc->stats->tx_err);
26892 + atomic_inc_unchecked(&vcc->stats->tx_err);
26893 dev_kfree_skb(skb);
26894 return err;
26895 }
26896 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
26897 skb = dev_alloc_skb(64);
26898 if (!skb) {
26899 printk("%s: Out of memory in send_oam().\n", card->name);
26900 - atomic_inc(&vcc->stats->tx_err);
26901 + atomic_inc_unchecked(&vcc->stats->tx_err);
26902 return -ENOMEM;
26903 }
26904 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
26905 diff -urNp linux-2.6.39.1/drivers/atm/iphase.c linux-2.6.39.1/drivers/atm/iphase.c
26906 --- linux-2.6.39.1/drivers/atm/iphase.c 2011-05-19 00:06:34.000000000 -0400
26907 +++ linux-2.6.39.1/drivers/atm/iphase.c 2011-05-22 19:36:31.000000000 -0400
26908 @@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
26909 status = (u_short) (buf_desc_ptr->desc_mode);
26910 if (status & (RX_CER | RX_PTE | RX_OFL))
26911 {
26912 - atomic_inc(&vcc->stats->rx_err);
26913 + atomic_inc_unchecked(&vcc->stats->rx_err);
26914 IF_ERR(printk("IA: bad packet, dropping it");)
26915 if (status & RX_CER) {
26916 IF_ERR(printk(" cause: packet CRC error\n");)
26917 @@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
26918 len = dma_addr - buf_addr;
26919 if (len > iadev->rx_buf_sz) {
26920 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
26921 - atomic_inc(&vcc->stats->rx_err);
26922 + atomic_inc_unchecked(&vcc->stats->rx_err);
26923 goto out_free_desc;
26924 }
26925
26926 @@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
26927 ia_vcc = INPH_IA_VCC(vcc);
26928 if (ia_vcc == NULL)
26929 {
26930 - atomic_inc(&vcc->stats->rx_err);
26931 + atomic_inc_unchecked(&vcc->stats->rx_err);
26932 dev_kfree_skb_any(skb);
26933 atm_return(vcc, atm_guess_pdu2truesize(len));
26934 goto INCR_DLE;
26935 @@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
26936 if ((length > iadev->rx_buf_sz) || (length >
26937 (skb->len - sizeof(struct cpcs_trailer))))
26938 {
26939 - atomic_inc(&vcc->stats->rx_err);
26940 + atomic_inc_unchecked(&vcc->stats->rx_err);
26941 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
26942 length, skb->len);)
26943 dev_kfree_skb_any(skb);
26944 @@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
26945
26946 IF_RX(printk("rx_dle_intr: skb push");)
26947 vcc->push(vcc,skb);
26948 - atomic_inc(&vcc->stats->rx);
26949 + atomic_inc_unchecked(&vcc->stats->rx);
26950 iadev->rx_pkt_cnt++;
26951 }
26952 INCR_DLE:
26953 @@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
26954 {
26955 struct k_sonet_stats *stats;
26956 stats = &PRIV(_ia_dev[board])->sonet_stats;
26957 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
26958 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
26959 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
26960 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
26961 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
26962 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
26963 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
26964 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
26965 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
26966 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
26967 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26968 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26969 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26970 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26971 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26972 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26973 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26974 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26975 }
26976 ia_cmds.status = 0;
26977 break;
26978 @@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
26979 if ((desc == 0) || (desc > iadev->num_tx_desc))
26980 {
26981 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26982 - atomic_inc(&vcc->stats->tx);
26983 + atomic_inc_unchecked(&vcc->stats->tx);
26984 if (vcc->pop)
26985 vcc->pop(vcc, skb);
26986 else
26987 @@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
26988 ATM_DESC(skb) = vcc->vci;
26989 skb_queue_tail(&iadev->tx_dma_q, skb);
26990
26991 - atomic_inc(&vcc->stats->tx);
26992 + atomic_inc_unchecked(&vcc->stats->tx);
26993 iadev->tx_pkt_cnt++;
26994 /* Increment transaction counter */
26995 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
26996
26997 #if 0
26998 /* add flow control logic */
26999 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27000 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27001 if (iavcc->vc_desc_cnt > 10) {
27002 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27003 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27004 diff -urNp linux-2.6.39.1/drivers/atm/lanai.c linux-2.6.39.1/drivers/atm/lanai.c
27005 --- linux-2.6.39.1/drivers/atm/lanai.c 2011-05-19 00:06:34.000000000 -0400
27006 +++ linux-2.6.39.1/drivers/atm/lanai.c 2011-05-22 19:36:31.000000000 -0400
27007 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
27008 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27009 lanai_endtx(lanai, lvcc);
27010 lanai_free_skb(lvcc->tx.atmvcc, skb);
27011 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27012 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27013 }
27014
27015 /* Try to fill the buffer - don't call unless there is backlog */
27016 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
27017 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27018 __net_timestamp(skb);
27019 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27020 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27021 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27022 out:
27023 lvcc->rx.buf.ptr = end;
27024 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27025 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
27026 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27027 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27028 lanai->stats.service_rxnotaal5++;
27029 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27030 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27031 return 0;
27032 }
27033 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27034 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
27035 int bytes;
27036 read_unlock(&vcc_sklist_lock);
27037 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27038 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27039 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27040 lvcc->stats.x.aal5.service_trash++;
27041 bytes = (SERVICE_GET_END(s) * 16) -
27042 (((unsigned long) lvcc->rx.buf.ptr) -
27043 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
27044 }
27045 if (s & SERVICE_STREAM) {
27046 read_unlock(&vcc_sklist_lock);
27047 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27048 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27049 lvcc->stats.x.aal5.service_stream++;
27050 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27051 "PDU on VCI %d!\n", lanai->number, vci);
27052 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
27053 return 0;
27054 }
27055 DPRINTK("got rx crc error on vci %d\n", vci);
27056 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27057 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27058 lvcc->stats.x.aal5.service_rxcrc++;
27059 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27060 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27061 diff -urNp linux-2.6.39.1/drivers/atm/nicstar.c linux-2.6.39.1/drivers/atm/nicstar.c
27062 --- linux-2.6.39.1/drivers/atm/nicstar.c 2011-05-19 00:06:34.000000000 -0400
27063 +++ linux-2.6.39.1/drivers/atm/nicstar.c 2011-05-22 19:36:31.000000000 -0400
27064 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
27065 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27066 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27067 card->index);
27068 - atomic_inc(&vcc->stats->tx_err);
27069 + atomic_inc_unchecked(&vcc->stats->tx_err);
27070 dev_kfree_skb_any(skb);
27071 return -EINVAL;
27072 }
27073 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
27074 if (!vc->tx) {
27075 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27076 card->index);
27077 - atomic_inc(&vcc->stats->tx_err);
27078 + atomic_inc_unchecked(&vcc->stats->tx_err);
27079 dev_kfree_skb_any(skb);
27080 return -EINVAL;
27081 }
27082 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
27083 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27084 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27085 card->index);
27086 - atomic_inc(&vcc->stats->tx_err);
27087 + atomic_inc_unchecked(&vcc->stats->tx_err);
27088 dev_kfree_skb_any(skb);
27089 return -EINVAL;
27090 }
27091
27092 if (skb_shinfo(skb)->nr_frags != 0) {
27093 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27094 - atomic_inc(&vcc->stats->tx_err);
27095 + atomic_inc_unchecked(&vcc->stats->tx_err);
27096 dev_kfree_skb_any(skb);
27097 return -EINVAL;
27098 }
27099 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
27100 }
27101
27102 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27103 - atomic_inc(&vcc->stats->tx_err);
27104 + atomic_inc_unchecked(&vcc->stats->tx_err);
27105 dev_kfree_skb_any(skb);
27106 return -EIO;
27107 }
27108 - atomic_inc(&vcc->stats->tx);
27109 + atomic_inc_unchecked(&vcc->stats->tx);
27110
27111 return 0;
27112 }
27113 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
27114 printk
27115 ("nicstar%d: Can't allocate buffers for aal0.\n",
27116 card->index);
27117 - atomic_add(i, &vcc->stats->rx_drop);
27118 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27119 break;
27120 }
27121 if (!atm_charge(vcc, sb->truesize)) {
27122 RXPRINTK
27123 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27124 card->index);
27125 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27126 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27127 dev_kfree_skb_any(sb);
27128 break;
27129 }
27130 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
27131 ATM_SKB(sb)->vcc = vcc;
27132 __net_timestamp(sb);
27133 vcc->push(vcc, sb);
27134 - atomic_inc(&vcc->stats->rx);
27135 + atomic_inc_unchecked(&vcc->stats->rx);
27136 cell += ATM_CELL_PAYLOAD;
27137 }
27138
27139 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
27140 if (iovb == NULL) {
27141 printk("nicstar%d: Out of iovec buffers.\n",
27142 card->index);
27143 - atomic_inc(&vcc->stats->rx_drop);
27144 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27145 recycle_rx_buf(card, skb);
27146 return;
27147 }
27148 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
27149 small or large buffer itself. */
27150 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27151 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27152 - atomic_inc(&vcc->stats->rx_err);
27153 + atomic_inc_unchecked(&vcc->stats->rx_err);
27154 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27155 NS_MAX_IOVECS);
27156 NS_PRV_IOVCNT(iovb) = 0;
27157 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
27158 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27159 card->index);
27160 which_list(card, skb);
27161 - atomic_inc(&vcc->stats->rx_err);
27162 + atomic_inc_unchecked(&vcc->stats->rx_err);
27163 recycle_rx_buf(card, skb);
27164 vc->rx_iov = NULL;
27165 recycle_iov_buf(card, iovb);
27166 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
27167 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27168 card->index);
27169 which_list(card, skb);
27170 - atomic_inc(&vcc->stats->rx_err);
27171 + atomic_inc_unchecked(&vcc->stats->rx_err);
27172 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27173 NS_PRV_IOVCNT(iovb));
27174 vc->rx_iov = NULL;
27175 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
27176 printk(" - PDU size mismatch.\n");
27177 else
27178 printk(".\n");
27179 - atomic_inc(&vcc->stats->rx_err);
27180 + atomic_inc_unchecked(&vcc->stats->rx_err);
27181 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27182 NS_PRV_IOVCNT(iovb));
27183 vc->rx_iov = NULL;
27184 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
27185 /* skb points to a small buffer */
27186 if (!atm_charge(vcc, skb->truesize)) {
27187 push_rxbufs(card, skb);
27188 - atomic_inc(&vcc->stats->rx_drop);
27189 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27190 } else {
27191 skb_put(skb, len);
27192 dequeue_sm_buf(card, skb);
27193 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
27194 ATM_SKB(skb)->vcc = vcc;
27195 __net_timestamp(skb);
27196 vcc->push(vcc, skb);
27197 - atomic_inc(&vcc->stats->rx);
27198 + atomic_inc_unchecked(&vcc->stats->rx);
27199 }
27200 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27201 struct sk_buff *sb;
27202 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
27203 if (len <= NS_SMBUFSIZE) {
27204 if (!atm_charge(vcc, sb->truesize)) {
27205 push_rxbufs(card, sb);
27206 - atomic_inc(&vcc->stats->rx_drop);
27207 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27208 } else {
27209 skb_put(sb, len);
27210 dequeue_sm_buf(card, sb);
27211 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
27212 ATM_SKB(sb)->vcc = vcc;
27213 __net_timestamp(sb);
27214 vcc->push(vcc, sb);
27215 - atomic_inc(&vcc->stats->rx);
27216 + atomic_inc_unchecked(&vcc->stats->rx);
27217 }
27218
27219 push_rxbufs(card, skb);
27220 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
27221
27222 if (!atm_charge(vcc, skb->truesize)) {
27223 push_rxbufs(card, skb);
27224 - atomic_inc(&vcc->stats->rx_drop);
27225 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27226 } else {
27227 dequeue_lg_buf(card, skb);
27228 #ifdef NS_USE_DESTRUCTORS
27229 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
27230 ATM_SKB(skb)->vcc = vcc;
27231 __net_timestamp(skb);
27232 vcc->push(vcc, skb);
27233 - atomic_inc(&vcc->stats->rx);
27234 + atomic_inc_unchecked(&vcc->stats->rx);
27235 }
27236
27237 push_rxbufs(card, sb);
27238 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
27239 printk
27240 ("nicstar%d: Out of huge buffers.\n",
27241 card->index);
27242 - atomic_inc(&vcc->stats->rx_drop);
27243 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27244 recycle_iovec_rx_bufs(card,
27245 (struct iovec *)
27246 iovb->data,
27247 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
27248 card->hbpool.count++;
27249 } else
27250 dev_kfree_skb_any(hb);
27251 - atomic_inc(&vcc->stats->rx_drop);
27252 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27253 } else {
27254 /* Copy the small buffer to the huge buffer */
27255 sb = (struct sk_buff *)iov->iov_base;
27256 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
27257 #endif /* NS_USE_DESTRUCTORS */
27258 __net_timestamp(hb);
27259 vcc->push(vcc, hb);
27260 - atomic_inc(&vcc->stats->rx);
27261 + atomic_inc_unchecked(&vcc->stats->rx);
27262 }
27263 }
27264
27265 diff -urNp linux-2.6.39.1/drivers/atm/solos-pci.c linux-2.6.39.1/drivers/atm/solos-pci.c
27266 --- linux-2.6.39.1/drivers/atm/solos-pci.c 2011-05-19 00:06:34.000000000 -0400
27267 +++ linux-2.6.39.1/drivers/atm/solos-pci.c 2011-05-22 19:36:31.000000000 -0400
27268 @@ -715,7 +715,7 @@ void solos_bh(unsigned long card_arg)
27269 }
27270 atm_charge(vcc, skb->truesize);
27271 vcc->push(vcc, skb);
27272 - atomic_inc(&vcc->stats->rx);
27273 + atomic_inc_unchecked(&vcc->stats->rx);
27274 break;
27275
27276 case PKT_STATUS:
27277 @@ -900,6 +900,8 @@ static int print_buffer(struct sk_buff *
27278 char msg[500];
27279 char item[10];
27280
27281 + pax_track_stack();
27282 +
27283 len = buf->len;
27284 for (i = 0; i < len; i++){
27285 if(i % 8 == 0)
27286 @@ -1009,7 +1011,7 @@ static uint32_t fpga_tx(struct solos_car
27287 vcc = SKB_CB(oldskb)->vcc;
27288
27289 if (vcc) {
27290 - atomic_inc(&vcc->stats->tx);
27291 + atomic_inc_unchecked(&vcc->stats->tx);
27292 solos_pop(vcc, oldskb);
27293 } else
27294 dev_kfree_skb_irq(oldskb);
27295 diff -urNp linux-2.6.39.1/drivers/atm/suni.c linux-2.6.39.1/drivers/atm/suni.c
27296 --- linux-2.6.39.1/drivers/atm/suni.c 2011-05-19 00:06:34.000000000 -0400
27297 +++ linux-2.6.39.1/drivers/atm/suni.c 2011-05-22 19:36:31.000000000 -0400
27298 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27299
27300
27301 #define ADD_LIMITED(s,v) \
27302 - atomic_add((v),&stats->s); \
27303 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27304 + atomic_add_unchecked((v),&stats->s); \
27305 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27306
27307
27308 static void suni_hz(unsigned long from_timer)
27309 diff -urNp linux-2.6.39.1/drivers/atm/uPD98402.c linux-2.6.39.1/drivers/atm/uPD98402.c
27310 --- linux-2.6.39.1/drivers/atm/uPD98402.c 2011-05-19 00:06:34.000000000 -0400
27311 +++ linux-2.6.39.1/drivers/atm/uPD98402.c 2011-05-22 19:36:31.000000000 -0400
27312 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
27313 struct sonet_stats tmp;
27314 int error = 0;
27315
27316 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27317 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27318 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27319 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27320 if (zero && !error) {
27321 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
27322
27323
27324 #define ADD_LIMITED(s,v) \
27325 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27326 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27327 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27328 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27329 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27330 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27331
27332
27333 static void stat_event(struct atm_dev *dev)
27334 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
27335 if (reason & uPD98402_INT_PFM) stat_event(dev);
27336 if (reason & uPD98402_INT_PCO) {
27337 (void) GET(PCOCR); /* clear interrupt cause */
27338 - atomic_add(GET(HECCT),
27339 + atomic_add_unchecked(GET(HECCT),
27340 &PRIV(dev)->sonet_stats.uncorr_hcs);
27341 }
27342 if ((reason & uPD98402_INT_RFO) &&
27343 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
27344 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27345 uPD98402_INT_LOS),PIMR); /* enable them */
27346 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27347 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27348 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27349 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27350 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27351 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27352 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27353 return 0;
27354 }
27355
27356 diff -urNp linux-2.6.39.1/drivers/atm/zatm.c linux-2.6.39.1/drivers/atm/zatm.c
27357 --- linux-2.6.39.1/drivers/atm/zatm.c 2011-05-19 00:06:34.000000000 -0400
27358 +++ linux-2.6.39.1/drivers/atm/zatm.c 2011-05-22 19:36:31.000000000 -0400
27359 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27360 }
27361 if (!size) {
27362 dev_kfree_skb_irq(skb);
27363 - if (vcc) atomic_inc(&vcc->stats->rx_err);
27364 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27365 continue;
27366 }
27367 if (!atm_charge(vcc,skb->truesize)) {
27368 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27369 skb->len = size;
27370 ATM_SKB(skb)->vcc = vcc;
27371 vcc->push(vcc,skb);
27372 - atomic_inc(&vcc->stats->rx);
27373 + atomic_inc_unchecked(&vcc->stats->rx);
27374 }
27375 zout(pos & 0xffff,MTA(mbx));
27376 #if 0 /* probably a stupid idea */
27377 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
27378 skb_queue_head(&zatm_vcc->backlog,skb);
27379 break;
27380 }
27381 - atomic_inc(&vcc->stats->tx);
27382 + atomic_inc_unchecked(&vcc->stats->tx);
27383 wake_up(&zatm_vcc->tx_wait);
27384 }
27385
27386 diff -urNp linux-2.6.39.1/drivers/base/iommu.c linux-2.6.39.1/drivers/base/iommu.c
27387 --- linux-2.6.39.1/drivers/base/iommu.c 2011-05-19 00:06:34.000000000 -0400
27388 +++ linux-2.6.39.1/drivers/base/iommu.c 2011-05-22 19:36:31.000000000 -0400
27389 @@ -23,9 +23,8 @@
27390 #include <linux/errno.h>
27391 #include <linux/iommu.h>
27392
27393 -static struct iommu_ops *iommu_ops;
27394 -
27395 -void register_iommu(struct iommu_ops *ops)
27396 +static const struct iommu_ops *iommu_ops;
27397 +void register_iommu(const struct iommu_ops *ops)
27398 {
27399 if (iommu_ops)
27400 BUG();
27401 diff -urNp linux-2.6.39.1/drivers/base/power/generic_ops.c linux-2.6.39.1/drivers/base/power/generic_ops.c
27402 --- linux-2.6.39.1/drivers/base/power/generic_ops.c 2011-05-19 00:06:34.000000000 -0400
27403 +++ linux-2.6.39.1/drivers/base/power/generic_ops.c 2011-05-22 19:36:31.000000000 -0400
27404 @@ -215,7 +215,7 @@ int pm_generic_restore(struct device *de
27405 EXPORT_SYMBOL_GPL(pm_generic_restore);
27406 #endif /* CONFIG_PM_SLEEP */
27407
27408 -struct dev_pm_ops generic_subsys_pm_ops = {
27409 +const struct dev_pm_ops generic_subsys_pm_ops = {
27410 #ifdef CONFIG_PM_SLEEP
27411 .suspend = pm_generic_suspend,
27412 .resume = pm_generic_resume,
27413 diff -urNp linux-2.6.39.1/drivers/base/power/wakeup.c linux-2.6.39.1/drivers/base/power/wakeup.c
27414 --- linux-2.6.39.1/drivers/base/power/wakeup.c 2011-05-19 00:06:34.000000000 -0400
27415 +++ linux-2.6.39.1/drivers/base/power/wakeup.c 2011-05-22 19:36:31.000000000 -0400
27416 @@ -29,14 +29,14 @@ bool events_check_enabled;
27417 * They need to be modified together atomically, so it's better to use one
27418 * atomic variable to hold them both.
27419 */
27420 -static atomic_t combined_event_count = ATOMIC_INIT(0);
27421 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27422
27423 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27424 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27425
27426 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27427 {
27428 - unsigned int comb = atomic_read(&combined_event_count);
27429 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
27430
27431 *cnt = (comb >> IN_PROGRESS_BITS);
27432 *inpr = comb & MAX_IN_PROGRESS;
27433 @@ -351,7 +351,7 @@ static void wakeup_source_activate(struc
27434 ws->last_time = ktime_get();
27435
27436 /* Increment the counter of events in progress. */
27437 - atomic_inc(&combined_event_count);
27438 + atomic_inc_unchecked(&combined_event_count);
27439 }
27440
27441 /**
27442 @@ -441,7 +441,7 @@ static void wakeup_source_deactivate(str
27443 * Increment the counter of registered wakeup events and decrement the
27444 * couter of wakeup events in progress simultaneously.
27445 */
27446 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27447 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27448 }
27449
27450 /**
27451 diff -urNp linux-2.6.39.1/drivers/block/cciss.c linux-2.6.39.1/drivers/block/cciss.c
27452 --- linux-2.6.39.1/drivers/block/cciss.c 2011-05-19 00:06:34.000000000 -0400
27453 +++ linux-2.6.39.1/drivers/block/cciss.c 2011-05-22 19:41:32.000000000 -0400
27454 @@ -103,7 +103,7 @@ MODULE_DEVICE_TABLE(pci, cciss_pci_devic
27455 * product = Marketing Name for the board
27456 * access = Address of the struct of function pointers
27457 */
27458 -static struct board_type products[] = {
27459 +static const struct board_type products[] = {
27460 {0x40700E11, "Smart Array 5300", &SA5_access},
27461 {0x40800E11, "Smart Array 5i", &SA5B_access},
27462 {0x40820E11, "Smart Array 532", &SA5B_access},
27463 @@ -1151,6 +1151,8 @@ static int cciss_ioctl32_passthru(struct
27464 int err;
27465 u32 cp;
27466
27467 + memset(&arg64, 0, sizeof(arg64));
27468 +
27469 err = 0;
27470 err |=
27471 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27472 diff -urNp linux-2.6.39.1/drivers/block/cciss.h linux-2.6.39.1/drivers/block/cciss.h
27473 --- linux-2.6.39.1/drivers/block/cciss.h 2011-05-19 00:06:34.000000000 -0400
27474 +++ linux-2.6.39.1/drivers/block/cciss.h 2011-05-22 19:36:31.000000000 -0400
27475 @@ -393,7 +393,7 @@ static bool SA5_performant_intr_pending(
27476 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
27477 }
27478
27479 -static struct access_method SA5_access = {
27480 +static const struct access_method SA5_access = {
27481 SA5_submit_command,
27482 SA5_intr_mask,
27483 SA5_fifo_full,
27484 @@ -401,7 +401,7 @@ static struct access_method SA5_access =
27485 SA5_completed,
27486 };
27487
27488 -static struct access_method SA5B_access = {
27489 +static const struct access_method SA5B_access = {
27490 SA5_submit_command,
27491 SA5B_intr_mask,
27492 SA5_fifo_full,
27493 @@ -409,7 +409,7 @@ static struct access_method SA5B_access
27494 SA5_completed,
27495 };
27496
27497 -static struct access_method SA5_performant_access = {
27498 +static const struct access_method SA5_performant_access = {
27499 SA5_submit_command,
27500 SA5_performant_intr_mask,
27501 SA5_fifo_full,
27502 @@ -420,7 +420,7 @@ static struct access_method SA5_performa
27503 struct board_type {
27504 __u32 board_id;
27505 char *product_name;
27506 - struct access_method *access;
27507 + const struct access_method *access;
27508 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
27509 };
27510
27511 diff -urNp linux-2.6.39.1/drivers/block/cpqarray.c linux-2.6.39.1/drivers/block/cpqarray.c
27512 --- linux-2.6.39.1/drivers/block/cpqarray.c 2011-05-19 00:06:34.000000000 -0400
27513 +++ linux-2.6.39.1/drivers/block/cpqarray.c 2011-05-22 19:36:31.000000000 -0400
27514 @@ -80,7 +80,7 @@ static int eisa[8];
27515 * product = Marketing Name for the board
27516 * access = Address of the struct of function pointers
27517 */
27518 -static struct board_type products[] = {
27519 +static const struct board_type products[] = {
27520 { 0x0040110E, "IDA", &smart1_access },
27521 { 0x0140110E, "IDA-2", &smart1_access },
27522 { 0x1040110E, "IAES", &smart1_access },
27523 @@ -911,6 +911,8 @@ static void do_ida_request(struct reques
27524 struct scatterlist tmp_sg[SG_MAX];
27525 int i, dir, seg;
27526
27527 + pax_track_stack();
27528 +
27529 queue_next:
27530 creq = blk_peek_request(q);
27531 if (!creq)
27532 diff -urNp linux-2.6.39.1/drivers/block/cpqarray.h linux-2.6.39.1/drivers/block/cpqarray.h
27533 --- linux-2.6.39.1/drivers/block/cpqarray.h 2011-05-19 00:06:34.000000000 -0400
27534 +++ linux-2.6.39.1/drivers/block/cpqarray.h 2011-05-22 19:36:31.000000000 -0400
27535 @@ -69,7 +69,7 @@ struct access_method {
27536 struct board_type {
27537 __u32 board_id;
27538 char *product_name;
27539 - struct access_method *access;
27540 + const struct access_method *access;
27541 };
27542
27543 struct ctlr_info {
27544 diff -urNp linux-2.6.39.1/drivers/block/DAC960.c linux-2.6.39.1/drivers/block/DAC960.c
27545 --- linux-2.6.39.1/drivers/block/DAC960.c 2011-05-19 00:06:34.000000000 -0400
27546 +++ linux-2.6.39.1/drivers/block/DAC960.c 2011-05-22 19:36:31.000000000 -0400
27547 @@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27548 unsigned long flags;
27549 int Channel, TargetID;
27550
27551 + pax_track_stack();
27552 +
27553 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27554 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27555 sizeof(DAC960_SCSI_Inquiry_T) +
27556 diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_int.h linux-2.6.39.1/drivers/block/drbd/drbd_int.h
27557 --- linux-2.6.39.1/drivers/block/drbd/drbd_int.h 2011-05-19 00:06:34.000000000 -0400
27558 +++ linux-2.6.39.1/drivers/block/drbd/drbd_int.h 2011-05-22 19:36:31.000000000 -0400
27559 @@ -736,7 +736,7 @@ struct drbd_request;
27560 struct drbd_epoch {
27561 struct list_head list;
27562 unsigned int barrier_nr;
27563 - atomic_t epoch_size; /* increased on every request added. */
27564 + atomic_unchecked_t epoch_size; /* increased on every request added. */
27565 atomic_t active; /* increased on every req. added, and dec on every finished. */
27566 unsigned long flags;
27567 };
27568 @@ -1108,7 +1108,7 @@ struct drbd_conf {
27569 void *int_dig_in;
27570 void *int_dig_vv;
27571 wait_queue_head_t seq_wait;
27572 - atomic_t packet_seq;
27573 + atomic_unchecked_t packet_seq;
27574 unsigned int peer_seq;
27575 spinlock_t peer_seq_lock;
27576 unsigned int minor;
27577 diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_main.c linux-2.6.39.1/drivers/block/drbd/drbd_main.c
27578 --- linux-2.6.39.1/drivers/block/drbd/drbd_main.c 2011-05-19 00:06:34.000000000 -0400
27579 +++ linux-2.6.39.1/drivers/block/drbd/drbd_main.c 2011-05-22 19:36:31.000000000 -0400
27580 @@ -2387,7 +2387,7 @@ static int _drbd_send_ack(struct drbd_co
27581 p.sector = sector;
27582 p.block_id = block_id;
27583 p.blksize = blksize;
27584 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
27585 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
27586
27587 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
27588 return false;
27589 @@ -2686,7 +2686,7 @@ int drbd_send_dblock(struct drbd_conf *m
27590 p.sector = cpu_to_be64(req->sector);
27591 p.block_id = (unsigned long)req;
27592 p.seq_num = cpu_to_be32(req->seq_num =
27593 - atomic_add_return(1, &mdev->packet_seq));
27594 + atomic_add_return_unchecked(1, &mdev->packet_seq));
27595
27596 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
27597
27598 @@ -2971,7 +2971,7 @@ void drbd_init_set_defaults(struct drbd_
27599 atomic_set(&mdev->unacked_cnt, 0);
27600 atomic_set(&mdev->local_cnt, 0);
27601 atomic_set(&mdev->net_cnt, 0);
27602 - atomic_set(&mdev->packet_seq, 0);
27603 + atomic_set_unchecked(&mdev->packet_seq, 0);
27604 atomic_set(&mdev->pp_in_use, 0);
27605 atomic_set(&mdev->pp_in_use_by_net, 0);
27606 atomic_set(&mdev->rs_sect_in, 0);
27607 @@ -3051,8 +3051,8 @@ void drbd_mdev_cleanup(struct drbd_conf
27608 mdev->receiver.t_state);
27609
27610 /* no need to lock it, I'm the only thread alive */
27611 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
27612 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
27613 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
27614 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
27615 mdev->al_writ_cnt =
27616 mdev->bm_writ_cnt =
27617 mdev->read_cnt =
27618 diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_nl.c linux-2.6.39.1/drivers/block/drbd/drbd_nl.c
27619 --- linux-2.6.39.1/drivers/block/drbd/drbd_nl.c 2011-05-19 00:06:34.000000000 -0400
27620 +++ linux-2.6.39.1/drivers/block/drbd/drbd_nl.c 2011-05-22 19:36:31.000000000 -0400
27621 @@ -2298,7 +2298,7 @@ static void drbd_connector_callback(stru
27622 module_put(THIS_MODULE);
27623 }
27624
27625 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27626 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27627
27628 static unsigned short *
27629 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
27630 @@ -2369,7 +2369,7 @@ void drbd_bcast_state(struct drbd_conf *
27631 cn_reply->id.idx = CN_IDX_DRBD;
27632 cn_reply->id.val = CN_VAL_DRBD;
27633
27634 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27635 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27636 cn_reply->ack = 0; /* not used here. */
27637 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27638 (int)((char *)tl - (char *)reply->tag_list);
27639 @@ -2401,7 +2401,7 @@ void drbd_bcast_ev_helper(struct drbd_co
27640 cn_reply->id.idx = CN_IDX_DRBD;
27641 cn_reply->id.val = CN_VAL_DRBD;
27642
27643 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27644 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27645 cn_reply->ack = 0; /* not used here. */
27646 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27647 (int)((char *)tl - (char *)reply->tag_list);
27648 @@ -2479,7 +2479,7 @@ void drbd_bcast_ee(struct drbd_conf *mde
27649 cn_reply->id.idx = CN_IDX_DRBD;
27650 cn_reply->id.val = CN_VAL_DRBD;
27651
27652 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
27653 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
27654 cn_reply->ack = 0; // not used here.
27655 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27656 (int)((char*)tl - (char*)reply->tag_list);
27657 @@ -2518,7 +2518,7 @@ void drbd_bcast_sync_progress(struct drb
27658 cn_reply->id.idx = CN_IDX_DRBD;
27659 cn_reply->id.val = CN_VAL_DRBD;
27660
27661 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27662 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27663 cn_reply->ack = 0; /* not used here. */
27664 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27665 (int)((char *)tl - (char *)reply->tag_list);
27666 diff -urNp linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c
27667 --- linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c 2011-05-19 00:06:34.000000000 -0400
27668 +++ linux-2.6.39.1/drivers/block/drbd/drbd_receiver.c 2011-05-22 19:36:31.000000000 -0400
27669 @@ -894,7 +894,7 @@ retry:
27670 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
27671 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
27672
27673 - atomic_set(&mdev->packet_seq, 0);
27674 + atomic_set_unchecked(&mdev->packet_seq, 0);
27675 mdev->peer_seq = 0;
27676
27677 drbd_thread_start(&mdev->asender);
27678 @@ -990,7 +990,7 @@ static enum finish_epoch drbd_may_finish
27679 do {
27680 next_epoch = NULL;
27681
27682 - epoch_size = atomic_read(&epoch->epoch_size);
27683 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
27684
27685 switch (ev & ~EV_CLEANUP) {
27686 case EV_PUT:
27687 @@ -1025,7 +1025,7 @@ static enum finish_epoch drbd_may_finish
27688 rv = FE_DESTROYED;
27689 } else {
27690 epoch->flags = 0;
27691 - atomic_set(&epoch->epoch_size, 0);
27692 + atomic_set_unchecked(&epoch->epoch_size, 0);
27693 /* atomic_set(&epoch->active, 0); is already zero */
27694 if (rv == FE_STILL_LIVE)
27695 rv = FE_RECYCLED;
27696 @@ -1196,14 +1196,14 @@ static int receive_Barrier(struct drbd_c
27697 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
27698 drbd_flush(mdev);
27699
27700 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27701 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27702 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
27703 if (epoch)
27704 break;
27705 }
27706
27707 epoch = mdev->current_epoch;
27708 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
27709 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
27710
27711 D_ASSERT(atomic_read(&epoch->active) == 0);
27712 D_ASSERT(epoch->flags == 0);
27713 @@ -1215,11 +1215,11 @@ static int receive_Barrier(struct drbd_c
27714 }
27715
27716 epoch->flags = 0;
27717 - atomic_set(&epoch->epoch_size, 0);
27718 + atomic_set_unchecked(&epoch->epoch_size, 0);
27719 atomic_set(&epoch->active, 0);
27720
27721 spin_lock(&mdev->epoch_lock);
27722 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27723 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27724 list_add(&epoch->list, &mdev->current_epoch->list);
27725 mdev->current_epoch = epoch;
27726 mdev->epochs++;
27727 @@ -1668,7 +1668,7 @@ static int receive_Data(struct drbd_conf
27728 spin_unlock(&mdev->peer_seq_lock);
27729
27730 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
27731 - atomic_inc(&mdev->current_epoch->epoch_size);
27732 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
27733 return drbd_drain_block(mdev, data_size);
27734 }
27735
27736 @@ -1694,7 +1694,7 @@ static int receive_Data(struct drbd_conf
27737
27738 spin_lock(&mdev->epoch_lock);
27739 e->epoch = mdev->current_epoch;
27740 - atomic_inc(&e->epoch->epoch_size);
27741 + atomic_inc_unchecked(&e->epoch->epoch_size);
27742 atomic_inc(&e->epoch->active);
27743 spin_unlock(&mdev->epoch_lock);
27744
27745 @@ -3905,7 +3905,7 @@ static void drbd_disconnect(struct drbd_
27746 D_ASSERT(list_empty(&mdev->done_ee));
27747
27748 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
27749 - atomic_set(&mdev->current_epoch->epoch_size, 0);
27750 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
27751 D_ASSERT(list_empty(&mdev->current_epoch->list));
27752 }
27753
27754 diff -urNp linux-2.6.39.1/drivers/block/nbd.c linux-2.6.39.1/drivers/block/nbd.c
27755 --- linux-2.6.39.1/drivers/block/nbd.c 2011-05-19 00:06:34.000000000 -0400
27756 +++ linux-2.6.39.1/drivers/block/nbd.c 2011-05-22 19:36:31.000000000 -0400
27757 @@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *
27758 struct kvec iov;
27759 sigset_t blocked, oldset;
27760
27761 + pax_track_stack();
27762 +
27763 if (unlikely(!sock)) {
27764 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27765 lo->disk->disk_name, (send ? "send" : "recv"));
27766 @@ -571,6 +573,8 @@ static void do_nbd_request(struct reques
27767 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27768 unsigned int cmd, unsigned long arg)
27769 {
27770 + pax_track_stack();
27771 +
27772 switch (cmd) {
27773 case NBD_DISCONNECT: {
27774 struct request sreq;
27775 diff -urNp linux-2.6.39.1/drivers/block/smart1,2.h linux-2.6.39.1/drivers/block/smart1,2.h
27776 --- linux-2.6.39.1/drivers/block/smart1,2.h 2011-05-19 00:06:34.000000000 -0400
27777 +++ linux-2.6.39.1/drivers/block/smart1,2.h 2011-05-22 19:36:31.000000000 -0400
27778 @@ -107,7 +107,7 @@ static unsigned long smart4_intr_pending
27779 return 0 ;
27780 }
27781
27782 -static struct access_method smart4_access = {
27783 +static const struct access_method smart4_access = {
27784 smart4_submit_command,
27785 smart4_intr_mask,
27786 smart4_fifo_full,
27787 @@ -143,7 +143,7 @@ static unsigned long smart2_intr_pending
27788 return readl(h->vaddr + INTR_PENDING);
27789 }
27790
27791 -static struct access_method smart2_access = {
27792 +static const struct access_method smart2_access = {
27793 smart2_submit_command,
27794 smart2_intr_mask,
27795 smart2_fifo_full,
27796 @@ -179,7 +179,7 @@ static unsigned long smart2e_intr_pendin
27797 return inl(h->io_mem_addr + INTR_PENDING);
27798 }
27799
27800 -static struct access_method smart2e_access = {
27801 +static const struct access_method smart2e_access = {
27802 smart2e_submit_command,
27803 smart2e_intr_mask,
27804 smart2e_fifo_full,
27805 @@ -269,7 +269,7 @@ static unsigned long smart1_intr_pending
27806 return chan;
27807 }
27808
27809 -static struct access_method smart1_access = {
27810 +static const struct access_method smart1_access = {
27811 smart1_submit_command,
27812 smart1_intr_mask,
27813 smart1_fifo_full,
27814 diff -urNp linux-2.6.39.1/drivers/block/xsysace.c linux-2.6.39.1/drivers/block/xsysace.c
27815 --- linux-2.6.39.1/drivers/block/xsysace.c 2011-05-19 00:06:34.000000000 -0400
27816 +++ linux-2.6.39.1/drivers/block/xsysace.c 2011-05-22 19:36:31.000000000 -0400
27817 @@ -262,7 +262,7 @@ static void ace_dataout_8(struct ace_dev
27818 ace->data_ptr = src;
27819 }
27820
27821 -static struct ace_reg_ops ace_reg_8_ops = {
27822 +static const struct ace_reg_ops ace_reg_8_ops = {
27823 .in = ace_in_8,
27824 .out = ace_out_8,
27825 .datain = ace_datain_8,
27826 @@ -327,14 +327,14 @@ static void ace_dataout_le16(struct ace_
27827 ace->data_ptr = src;
27828 }
27829
27830 -static struct ace_reg_ops ace_reg_be16_ops = {
27831 +static const struct ace_reg_ops ace_reg_be16_ops = {
27832 .in = ace_in_be16,
27833 .out = ace_out_be16,
27834 .datain = ace_datain_be16,
27835 .dataout = ace_dataout_be16,
27836 };
27837
27838 -static struct ace_reg_ops ace_reg_le16_ops = {
27839 +static const struct ace_reg_ops ace_reg_le16_ops = {
27840 .in = ace_in_le16,
27841 .out = ace_out_le16,
27842 .datain = ace_datain_le16,
27843 diff -urNp linux-2.6.39.1/drivers/char/agp/frontend.c linux-2.6.39.1/drivers/char/agp/frontend.c
27844 --- linux-2.6.39.1/drivers/char/agp/frontend.c 2011-05-19 00:06:34.000000000 -0400
27845 +++ linux-2.6.39.1/drivers/char/agp/frontend.c 2011-05-22 19:36:31.000000000 -0400
27846 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
27847 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27848 return -EFAULT;
27849
27850 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27851 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27852 return -EFAULT;
27853
27854 client = agp_find_client_by_pid(reserve.pid);
27855 diff -urNp linux-2.6.39.1/drivers/char/briq_panel.c linux-2.6.39.1/drivers/char/briq_panel.c
27856 --- linux-2.6.39.1/drivers/char/briq_panel.c 2011-05-19 00:06:34.000000000 -0400
27857 +++ linux-2.6.39.1/drivers/char/briq_panel.c 2011-05-22 19:41:32.000000000 -0400
27858 @@ -9,6 +9,7 @@
27859 #include <linux/types.h>
27860 #include <linux/errno.h>
27861 #include <linux/tty.h>
27862 +#include <linux/mutex.h>
27863 #include <linux/timer.h>
27864 #include <linux/kernel.h>
27865 #include <linux/wait.h>
27866 @@ -34,6 +35,7 @@ static int vfd_is_open;
27867 static unsigned char vfd[40];
27868 static int vfd_cursor;
27869 static unsigned char ledpb, led;
27870 +static DEFINE_MUTEX(vfd_mutex);
27871
27872 static void update_vfd(void)
27873 {
27874 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct f
27875 if (!vfd_is_open)
27876 return -EBUSY;
27877
27878 + mutex_lock(&vfd_mutex);
27879 for (;;) {
27880 char c;
27881 if (!indx)
27882 break;
27883 - if (get_user(c, buf))
27884 + if (get_user(c, buf)) {
27885 + mutex_unlock(&vfd_mutex);
27886 return -EFAULT;
27887 + }
27888 if (esc) {
27889 set_led(c);
27890 esc = 0;
27891 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct f
27892 buf++;
27893 }
27894 update_vfd();
27895 + mutex_unlock(&vfd_mutex);
27896
27897 return len;
27898 }
27899 diff -urNp linux-2.6.39.1/drivers/char/genrtc.c linux-2.6.39.1/drivers/char/genrtc.c
27900 --- linux-2.6.39.1/drivers/char/genrtc.c 2011-05-19 00:06:34.000000000 -0400
27901 +++ linux-2.6.39.1/drivers/char/genrtc.c 2011-05-22 19:41:32.000000000 -0400
27902 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *fi
27903 switch (cmd) {
27904
27905 case RTC_PLL_GET:
27906 + memset(&pll, 0, sizeof(pll));
27907 if (get_rtc_pll(&pll))
27908 return -EINVAL;
27909 else
27910 diff -urNp linux-2.6.39.1/drivers/char/hpet.c linux-2.6.39.1/drivers/char/hpet.c
27911 --- linux-2.6.39.1/drivers/char/hpet.c 2011-05-19 00:06:34.000000000 -0400
27912 +++ linux-2.6.39.1/drivers/char/hpet.c 2011-05-22 19:36:31.000000000 -0400
27913 @@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
27914 }
27915
27916 static int
27917 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
27918 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
27919 struct hpet_info *info)
27920 {
27921 struct hpet_timer __iomem *timer;
27922 diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c
27923 --- linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c 2011-05-19 00:06:34.000000000 -0400
27924 +++ linux-2.6.39.1/drivers/char/ipmi/ipmi_devintf.c 2011-05-22 19:36:31.000000000 -0400
27925 @@ -109,8 +109,7 @@ static int ipmi_fasync(int fd, struct fi
27926 return (result);
27927 }
27928
27929 -static struct ipmi_user_hndl ipmi_hndlrs =
27930 -{
27931 +static const struct ipmi_user_hndl ipmi_hndlrs = {
27932 .ipmi_recv_hndl = file_receive_handler,
27933 };
27934
27935 diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c
27936 --- linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c 2011-05-19 00:06:34.000000000 -0400
27937 +++ linux-2.6.39.1/drivers/char/ipmi/ipmi_msghandler.c 2011-05-22 19:36:31.000000000 -0400
27938 @@ -82,7 +82,7 @@ struct ipmi_user {
27939 struct kref refcount;
27940
27941 /* The upper layer that handles receive messages. */
27942 - struct ipmi_user_hndl *handler;
27943 + const struct ipmi_user_hndl *handler;
27944 void *handler_data;
27945
27946 /* The interface this user is bound to. */
27947 @@ -414,7 +414,7 @@ struct ipmi_smi {
27948 struct proc_dir_entry *proc_dir;
27949 char proc_dir_name[10];
27950
27951 - atomic_t stats[IPMI_NUM_STATS];
27952 + atomic_unchecked_t stats[IPMI_NUM_STATS];
27953
27954 /*
27955 * run_to_completion duplicate of smb_info, smi_info
27956 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27957
27958
27959 #define ipmi_inc_stat(intf, stat) \
27960 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27961 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27962 #define ipmi_get_stat(intf, stat) \
27963 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27964 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27965
27966 static int is_lan_addr(struct ipmi_addr *addr)
27967 {
27968 @@ -875,7 +875,7 @@ static int intf_err_seq(ipmi_smi_t int
27969
27970
27971 int ipmi_create_user(unsigned int if_num,
27972 - struct ipmi_user_hndl *handler,
27973 + const struct ipmi_user_hndl *handler,
27974 void *handler_data,
27975 ipmi_user_t *user)
27976 {
27977 @@ -2844,7 +2844,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
27978 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27979 init_waitqueue_head(&intf->waitq);
27980 for (i = 0; i < IPMI_NUM_STATS; i++)
27981 - atomic_set(&intf->stats[i], 0);
27982 + atomic_set_unchecked(&intf->stats[i], 0);
27983
27984 intf->proc_dir = NULL;
27985
27986 @@ -4196,6 +4196,8 @@ static void send_panic_events(char *str)
27987 struct ipmi_smi_msg smi_msg;
27988 struct ipmi_recv_msg recv_msg;
27989
27990 + pax_track_stack();
27991 +
27992 si = (struct ipmi_system_interface_addr *) &addr;
27993 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
27994 si->channel = IPMI_BMC_CHANNEL;
27995 diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c
27996 --- linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c 2011-05-19 00:06:34.000000000 -0400
27997 +++ linux-2.6.39.1/drivers/char/ipmi/ipmi_poweroff.c 2011-05-22 19:36:31.000000000 -0400
27998 @@ -133,7 +133,7 @@ static void receive_handler(struct ipmi_
27999 complete(comp);
28000 }
28001
28002 -static struct ipmi_user_hndl ipmi_poweroff_handler = {
28003 +static const struct ipmi_user_hndl ipmi_poweroff_handler = {
28004 .ipmi_recv_hndl = receive_handler
28005 };
28006
28007 diff -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
28008 --- linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c 2011-05-19 00:06:34.000000000 -0400
28009 +++ linux-2.6.39.1/drivers/char/ipmi/ipmi_si_intf.c 2011-05-22 19:36:31.000000000 -0400
28010 @@ -276,7 +276,7 @@ struct smi_info {
28011 unsigned char slave_addr;
28012
28013 /* Counters and things for the proc filesystem. */
28014 - atomic_t stats[SI_NUM_STATS];
28015 + atomic_unchecked_t stats[SI_NUM_STATS];
28016
28017 struct task_struct *thread;
28018
28019 @@ -285,9 +285,9 @@ struct smi_info {
28020 };
28021
28022 #define smi_inc_stat(smi, stat) \
28023 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28024 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28025 #define smi_get_stat(smi, stat) \
28026 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28027 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28028
28029 #define SI_MAX_PARMS 4
28030
28031 @@ -3198,7 +3198,7 @@ static int try_smi_init(struct smi_info
28032 atomic_set(&new_smi->req_events, 0);
28033 new_smi->run_to_completion = 0;
28034 for (i = 0; i < SI_NUM_STATS; i++)
28035 - atomic_set(&new_smi->stats[i], 0);
28036 + atomic_set_unchecked(&new_smi->stats[i], 0);
28037
28038 new_smi->interrupt_disabled = 1;
28039 atomic_set(&new_smi->stop_operation, 0);
28040 diff -urNp linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c
28041 --- linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c 2011-05-19 00:06:34.000000000 -0400
28042 +++ linux-2.6.39.1/drivers/char/ipmi/ipmi_watchdog.c 2011-05-22 19:36:31.000000000 -0400
28043 @@ -216,7 +216,7 @@ static int set_param_timeout(const char
28044 return rv;
28045 }
28046
28047 -static struct kernel_param_ops param_ops_timeout = {
28048 +static const struct kernel_param_ops param_ops_timeout = {
28049 .set = set_param_timeout,
28050 .get = param_get_int,
28051 };
28052 @@ -278,14 +278,14 @@ static int set_param_wdog_ifnum(const ch
28053 return 0;
28054 }
28055
28056 -static struct kernel_param_ops param_ops_wdog_ifnum = {
28057 +static const struct kernel_param_ops param_ops_wdog_ifnum = {
28058 .set = set_param_wdog_ifnum,
28059 .get = param_get_int,
28060 };
28061
28062 #define param_check_wdog_ifnum param_check_int
28063
28064 -static struct kernel_param_ops param_ops_str = {
28065 +static const struct kernel_param_ops param_ops_str = {
28066 .set = set_param_str,
28067 .get = get_param_str,
28068 };
28069 @@ -953,7 +953,7 @@ static void ipmi_wdog_pretimeout_handler
28070 pretimeout_since_last_heartbeat = 1;
28071 }
28072
28073 -static struct ipmi_user_hndl ipmi_hndlrs = {
28074 +static const struct ipmi_user_hndl ipmi_hndlrs = {
28075 .ipmi_recv_hndl = ipmi_wdog_msg_handler,
28076 .ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler
28077 };
28078 diff -urNp linux-2.6.39.1/drivers/char/Kconfig linux-2.6.39.1/drivers/char/Kconfig
28079 --- linux-2.6.39.1/drivers/char/Kconfig 2011-05-19 00:06:34.000000000 -0400
28080 +++ linux-2.6.39.1/drivers/char/Kconfig 2011-05-22 19:41:37.000000000 -0400
28081 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28082
28083 config DEVKMEM
28084 bool "/dev/kmem virtual device support"
28085 - default y
28086 + default n
28087 + depends on !GRKERNSEC_KMEM
28088 help
28089 Say Y here if you want to support the /dev/kmem device. The
28090 /dev/kmem device is rarely used, but can be used for certain
28091 @@ -596,6 +597,7 @@ config DEVPORT
28092 bool
28093 depends on !M68K
28094 depends on ISA || PCI
28095 + depends on !GRKERNSEC_KMEM
28096 default y
28097
28098 source "drivers/s390/char/Kconfig"
28099 diff -urNp linux-2.6.39.1/drivers/char/mem.c linux-2.6.39.1/drivers/char/mem.c
28100 --- linux-2.6.39.1/drivers/char/mem.c 2011-05-19 00:06:34.000000000 -0400
28101 +++ linux-2.6.39.1/drivers/char/mem.c 2011-05-22 19:41:37.000000000 -0400
28102 @@ -18,6 +18,7 @@
28103 #include <linux/raw.h>
28104 #include <linux/tty.h>
28105 #include <linux/capability.h>
28106 +#include <linux/security.h>
28107 #include <linux/ptrace.h>
28108 #include <linux/device.h>
28109 #include <linux/highmem.h>
28110 @@ -34,6 +35,10 @@
28111 # include <linux/efi.h>
28112 #endif
28113
28114 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28115 +extern struct file_operations grsec_fops;
28116 +#endif
28117 +
28118 static inline unsigned long size_inside_page(unsigned long start,
28119 unsigned long size)
28120 {
28121 @@ -65,9 +70,13 @@ static inline int range_is_allowed(unsig
28122
28123 while (cursor < to) {
28124 if (!devmem_is_allowed(pfn)) {
28125 +#ifdef CONFIG_GRKERNSEC_KMEM
28126 + gr_handle_mem_readwrite(from, to);
28127 +#else
28128 printk(KERN_INFO
28129 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28130 current->comm, from, to);
28131 +#endif
28132 return 0;
28133 }
28134 cursor += PAGE_SIZE;
28135 @@ -75,6 +84,11 @@ static inline int range_is_allowed(unsig
28136 }
28137 return 1;
28138 }
28139 +#elif defined(CONFIG_GRKERNSEC_KMEM)
28140 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28141 +{
28142 + return 0;
28143 +}
28144 #else
28145 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28146 {
28147 @@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *fil
28148
28149 while (count > 0) {
28150 unsigned long remaining;
28151 + char *temp;
28152
28153 sz = size_inside_page(p, count);
28154
28155 @@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *fil
28156 if (!ptr)
28157 return -EFAULT;
28158
28159 - remaining = copy_to_user(buf, ptr, sz);
28160 +#ifdef CONFIG_PAX_USERCOPY
28161 + temp = kmalloc(sz, GFP_KERNEL);
28162 + if (!temp) {
28163 + unxlate_dev_mem_ptr(p, ptr);
28164 + return -ENOMEM;
28165 + }
28166 + memcpy(temp, ptr, sz);
28167 +#else
28168 + temp = ptr;
28169 +#endif
28170 +
28171 + remaining = copy_to_user(buf, temp, sz);
28172 +
28173 +#ifdef CONFIG_PAX_USERCOPY
28174 + kfree(temp);
28175 +#endif
28176 +
28177 unxlate_dev_mem_ptr(p, ptr);
28178 if (remaining)
28179 return -EFAULT;
28180 @@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *fi
28181 size_t count, loff_t *ppos)
28182 {
28183 unsigned long p = *ppos;
28184 - ssize_t low_count, read, sz;
28185 + ssize_t low_count, read, sz, err = 0;
28186 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28187 - int err = 0;
28188
28189 read = 0;
28190 if (p < (unsigned long) high_memory) {
28191 @@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *fi
28192 }
28193 #endif
28194 while (low_count > 0) {
28195 + char *temp;
28196 +
28197 sz = size_inside_page(p, low_count);
28198
28199 /*
28200 @@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *fi
28201 */
28202 kbuf = xlate_dev_kmem_ptr((char *)p);
28203
28204 - if (copy_to_user(buf, kbuf, sz))
28205 +#ifdef CONFIG_PAX_USERCOPY
28206 + temp = kmalloc(sz, GFP_KERNEL);
28207 + if (!temp)
28208 + return -ENOMEM;
28209 + memcpy(temp, kbuf, sz);
28210 +#else
28211 + temp = kbuf;
28212 +#endif
28213 +
28214 + err = copy_to_user(buf, temp, sz);
28215 +
28216 +#ifdef CONFIG_PAX_USERCOPY
28217 + kfree(temp);
28218 +#endif
28219 +
28220 + if (err)
28221 return -EFAULT;
28222 buf += sz;
28223 p += sz;
28224 @@ -854,6 +901,9 @@ static const struct memdev {
28225 #ifdef CONFIG_CRASH_DUMP
28226 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28227 #endif
28228 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28229 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28230 +#endif
28231 };
28232
28233 static int memory_open(struct inode *inode, struct file *filp)
28234 diff -urNp linux-2.6.39.1/drivers/char/mmtimer.c linux-2.6.39.1/drivers/char/mmtimer.c
28235 --- linux-2.6.39.1/drivers/char/mmtimer.c 2011-05-19 00:06:34.000000000 -0400
28236 +++ linux-2.6.39.1/drivers/char/mmtimer.c 2011-05-22 19:36:31.000000000 -0400
28237 @@ -53,7 +53,7 @@ MODULE_LICENSE("GPL");
28238
28239 #define RTC_BITS 55 /* 55 bits for this implementation */
28240
28241 -static struct k_clock sgi_clock;
28242 +static const struct k_clock sgi_clock;
28243
28244 extern unsigned long sn_rtc_cycles_per_second;
28245
28246 @@ -772,7 +772,7 @@ static int sgi_clock_getres(const clocki
28247 return 0;
28248 }
28249
28250 -static struct k_clock sgi_clock = {
28251 +static const struct k_clock sgi_clock = {
28252 .clock_set = sgi_clock_set,
28253 .clock_get = sgi_clock_get,
28254 .clock_getres = sgi_clock_getres,
28255 diff -urNp linux-2.6.39.1/drivers/char/nvram.c linux-2.6.39.1/drivers/char/nvram.c
28256 --- linux-2.6.39.1/drivers/char/nvram.c 2011-05-19 00:06:34.000000000 -0400
28257 +++ linux-2.6.39.1/drivers/char/nvram.c 2011-05-22 19:36:31.000000000 -0400
28258 @@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
28259
28260 spin_unlock_irq(&rtc_lock);
28261
28262 - if (copy_to_user(buf, contents, tmp - contents))
28263 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28264 return -EFAULT;
28265
28266 *ppos = i;
28267 diff -urNp linux-2.6.39.1/drivers/char/random.c linux-2.6.39.1/drivers/char/random.c
28268 --- linux-2.6.39.1/drivers/char/random.c 2011-05-19 00:06:34.000000000 -0400
28269 +++ linux-2.6.39.1/drivers/char/random.c 2011-05-22 19:41:37.000000000 -0400
28270 @@ -261,8 +261,13 @@
28271 /*
28272 * Configuration information
28273 */
28274 +#ifdef CONFIG_GRKERNSEC_RANDNET
28275 +#define INPUT_POOL_WORDS 512
28276 +#define OUTPUT_POOL_WORDS 128
28277 +#else
28278 #define INPUT_POOL_WORDS 128
28279 #define OUTPUT_POOL_WORDS 32
28280 +#endif
28281 #define SEC_XFER_SIZE 512
28282 #define EXTRACT_SIZE 10
28283
28284 @@ -300,10 +305,17 @@ static struct poolinfo {
28285 int poolwords;
28286 int tap1, tap2, tap3, tap4, tap5;
28287 } poolinfo_table[] = {
28288 +#ifdef CONFIG_GRKERNSEC_RANDNET
28289 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28290 + { 512, 411, 308, 208, 104, 1 },
28291 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28292 + { 128, 103, 76, 51, 25, 1 },
28293 +#else
28294 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28295 { 128, 103, 76, 51, 25, 1 },
28296 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28297 { 32, 26, 20, 14, 7, 1 },
28298 +#endif
28299 #if 0
28300 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28301 { 2048, 1638, 1231, 819, 411, 1 },
28302 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(stru
28303
28304 extract_buf(r, tmp);
28305 i = min_t(int, nbytes, EXTRACT_SIZE);
28306 - if (copy_to_user(buf, tmp, i)) {
28307 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28308 ret = -EFAULT;
28309 break;
28310 }
28311 @@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28312 #include <linux/sysctl.h>
28313
28314 static int min_read_thresh = 8, min_write_thresh;
28315 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
28316 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28317 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28318 static char sysctl_bootid[16];
28319
28320 diff -urNp linux-2.6.39.1/drivers/char/sonypi.c linux-2.6.39.1/drivers/char/sonypi.c
28321 --- linux-2.6.39.1/drivers/char/sonypi.c 2011-05-19 00:06:34.000000000 -0400
28322 +++ linux-2.6.39.1/drivers/char/sonypi.c 2011-05-22 19:36:31.000000000 -0400
28323 @@ -55,6 +55,7 @@
28324 #include <asm/uaccess.h>
28325 #include <asm/io.h>
28326 #include <asm/system.h>
28327 +#include <asm/local.h>
28328
28329 #include <linux/sonypi.h>
28330
28331 @@ -491,7 +492,7 @@ static struct sonypi_device {
28332 spinlock_t fifo_lock;
28333 wait_queue_head_t fifo_proc_list;
28334 struct fasync_struct *fifo_async;
28335 - int open_count;
28336 + local_t open_count;
28337 int model;
28338 struct input_dev *input_jog_dev;
28339 struct input_dev *input_key_dev;
28340 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, st
28341 static int sonypi_misc_release(struct inode *inode, struct file *file)
28342 {
28343 mutex_lock(&sonypi_device.lock);
28344 - sonypi_device.open_count--;
28345 + local_dec(&sonypi_device.open_count);
28346 mutex_unlock(&sonypi_device.lock);
28347 return 0;
28348 }
28349 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode
28350 {
28351 mutex_lock(&sonypi_device.lock);
28352 /* Flush input queue on first open */
28353 - if (!sonypi_device.open_count)
28354 + if (!local_read(&sonypi_device.open_count))
28355 kfifo_reset(&sonypi_device.fifo);
28356 - sonypi_device.open_count++;
28357 + local_inc(&sonypi_device.open_count);
28358 mutex_unlock(&sonypi_device.lock);
28359
28360 return 0;
28361 diff -urNp linux-2.6.39.1/drivers/char/tpm/tpm_bios.c linux-2.6.39.1/drivers/char/tpm/tpm_bios.c
28362 --- linux-2.6.39.1/drivers/char/tpm/tpm_bios.c 2011-05-19 00:06:34.000000000 -0400
28363 +++ linux-2.6.39.1/drivers/char/tpm/tpm_bios.c 2011-05-22 19:36:31.000000000 -0400
28364 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
28365 event = addr;
28366
28367 if ((event->event_type == 0 && event->event_size == 0) ||
28368 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28369 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28370 return NULL;
28371
28372 return addr;
28373 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
28374 return NULL;
28375
28376 if ((event->event_type == 0 && event->event_size == 0) ||
28377 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28378 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28379 return NULL;
28380
28381 (*pos)++;
28382 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
28383 int i;
28384
28385 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28386 - seq_putc(m, data[i]);
28387 + if (!seq_putc(m, data[i]))
28388 + return -EFAULT;
28389
28390 return 0;
28391 }
28392 @@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
28393 log->bios_event_log_end = log->bios_event_log + len;
28394
28395 virt = acpi_os_map_memory(start, len);
28396 + if (!virt) {
28397 + kfree(log->bios_event_log);
28398 + log->bios_event_log = NULL;
28399 + return -EFAULT;
28400 + }
28401
28402 memcpy(log->bios_event_log, virt, len);
28403
28404 diff -urNp linux-2.6.39.1/drivers/char/tpm/tpm.c linux-2.6.39.1/drivers/char/tpm/tpm.c
28405 --- linux-2.6.39.1/drivers/char/tpm/tpm.c 2011-05-19 00:06:34.000000000 -0400
28406 +++ linux-2.6.39.1/drivers/char/tpm/tpm.c 2011-05-22 19:36:31.000000000 -0400
28407 @@ -411,7 +411,7 @@ static ssize_t tpm_transmit(struct tpm_c
28408 chip->vendor.req_complete_val)
28409 goto out_recv;
28410
28411 - if ((status == chip->vendor.req_canceled)) {
28412 + if (status == chip->vendor.req_canceled) {
28413 dev_err(chip->dev, "Operation Canceled\n");
28414 rc = -ECANCELED;
28415 goto out;
28416 @@ -844,6 +844,8 @@ ssize_t tpm_show_pubek(struct device *de
28417
28418 struct tpm_chip *chip = dev_get_drvdata(dev);
28419
28420 + pax_track_stack();
28421 +
28422 tpm_cmd.header.in = tpm_readpubek_header;
28423 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28424 "attempting to read the PUBEK");
28425 diff -urNp linux-2.6.39.1/drivers/char/ttyprintk.c linux-2.6.39.1/drivers/char/ttyprintk.c
28426 --- linux-2.6.39.1/drivers/char/ttyprintk.c 2011-05-19 00:06:34.000000000 -0400
28427 +++ linux-2.6.39.1/drivers/char/ttyprintk.c 2011-05-22 19:36:31.000000000 -0400
28428 @@ -170,7 +170,7 @@ static const struct tty_operations ttypr
28429 .ioctl = tpk_ioctl,
28430 };
28431
28432 -struct tty_port_operations null_ops = { };
28433 +const struct tty_port_operations null_ops = { };
28434
28435 static struct tty_driver *ttyprintk_driver;
28436
28437 diff -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
28438 --- linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-19 00:06:34.000000000 -0400
28439 +++ linux-2.6.39.1/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-22 19:36:31.000000000 -0400
28440 @@ -678,14 +678,14 @@ static int __devinit hwicap_setup(struct
28441 return retval;
28442 }
28443
28444 -static struct hwicap_driver_config buffer_icap_config = {
28445 +static const struct hwicap_driver_config buffer_icap_config = {
28446 .get_configuration = buffer_icap_get_configuration,
28447 .set_configuration = buffer_icap_set_configuration,
28448 .get_status = buffer_icap_get_status,
28449 .reset = buffer_icap_reset,
28450 };
28451
28452 -static struct hwicap_driver_config fifo_icap_config = {
28453 +static const struct hwicap_driver_config fifo_icap_config = {
28454 .get_configuration = fifo_icap_get_configuration,
28455 .set_configuration = fifo_icap_set_configuration,
28456 .get_status = fifo_icap_get_status,
28457 diff -urNp linux-2.6.39.1/drivers/crypto/hifn_795x.c linux-2.6.39.1/drivers/crypto/hifn_795x.c
28458 --- linux-2.6.39.1/drivers/crypto/hifn_795x.c 2011-05-19 00:06:34.000000000 -0400
28459 +++ linux-2.6.39.1/drivers/crypto/hifn_795x.c 2011-05-22 19:36:31.000000000 -0400
28460 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28461 0xCA, 0x34, 0x2B, 0x2E};
28462 struct scatterlist sg;
28463
28464 + pax_track_stack();
28465 +
28466 memset(src, 0, sizeof(src));
28467 memset(ctx.key, 0, sizeof(ctx.key));
28468
28469 diff -urNp linux-2.6.39.1/drivers/crypto/padlock-aes.c linux-2.6.39.1/drivers/crypto/padlock-aes.c
28470 --- linux-2.6.39.1/drivers/crypto/padlock-aes.c 2011-05-19 00:06:34.000000000 -0400
28471 +++ linux-2.6.39.1/drivers/crypto/padlock-aes.c 2011-05-22 19:36:31.000000000 -0400
28472 @@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm
28473 struct crypto_aes_ctx gen_aes;
28474 int cpu;
28475
28476 + pax_track_stack();
28477 +
28478 if (key_len % 8) {
28479 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28480 return -EINVAL;
28481 diff -urNp linux-2.6.39.1/drivers/dca/dca-core.c linux-2.6.39.1/drivers/dca/dca-core.c
28482 --- linux-2.6.39.1/drivers/dca/dca-core.c 2011-05-19 00:06:34.000000000 -0400
28483 +++ linux-2.6.39.1/drivers/dca/dca-core.c 2011-05-22 19:36:31.000000000 -0400
28484 @@ -325,7 +325,7 @@ EXPORT_SYMBOL_GPL(dca_get_tag);
28485 * @ops - pointer to struct of dca operation function pointers
28486 * @priv_size - size of extra mem to be added for provider's needs
28487 */
28488 -struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size)
28489 +struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size)
28490 {
28491 struct dca_provider *dca;
28492 int alloc_size;
28493 diff -urNp linux-2.6.39.1/drivers/dma/ioat/dca.c linux-2.6.39.1/drivers/dma/ioat/dca.c
28494 --- linux-2.6.39.1/drivers/dma/ioat/dca.c 2011-05-19 00:06:34.000000000 -0400
28495 +++ linux-2.6.39.1/drivers/dma/ioat/dca.c 2011-05-22 19:36:31.000000000 -0400
28496 @@ -234,7 +234,7 @@ static int ioat_dca_dev_managed(struct d
28497 return 0;
28498 }
28499
28500 -static struct dca_ops ioat_dca_ops = {
28501 +static const struct dca_ops ioat_dca_ops = {
28502 .add_requester = ioat_dca_add_requester,
28503 .remove_requester = ioat_dca_remove_requester,
28504 .get_tag = ioat_dca_get_tag,
28505 @@ -384,7 +384,7 @@ static u8 ioat2_dca_get_tag(struct dca_p
28506 return tag;
28507 }
28508
28509 -static struct dca_ops ioat2_dca_ops = {
28510 +static const struct dca_ops ioat2_dca_ops = {
28511 .add_requester = ioat2_dca_add_requester,
28512 .remove_requester = ioat2_dca_remove_requester,
28513 .get_tag = ioat2_dca_get_tag,
28514 @@ -579,7 +579,7 @@ static u8 ioat3_dca_get_tag(struct dca_p
28515 return tag;
28516 }
28517
28518 -static struct dca_ops ioat3_dca_ops = {
28519 +static const struct dca_ops ioat3_dca_ops = {
28520 .add_requester = ioat3_dca_add_requester,
28521 .remove_requester = ioat3_dca_remove_requester,
28522 .get_tag = ioat3_dca_get_tag,
28523 diff -urNp linux-2.6.39.1/drivers/edac/amd64_edac.h linux-2.6.39.1/drivers/edac/amd64_edac.h
28524 --- linux-2.6.39.1/drivers/edac/amd64_edac.h 2011-05-19 00:06:34.000000000 -0400
28525 +++ linux-2.6.39.1/drivers/edac/amd64_edac.h 2011-05-22 19:36:31.000000000 -0400
28526 @@ -333,7 +333,7 @@ struct chip_select {
28527 };
28528
28529 struct amd64_pvt {
28530 - struct low_ops *ops;
28531 + const struct low_ops *ops;
28532
28533 /* pci_device handles which we utilize */
28534 struct pci_dev *F1, *F2, *F3;
28535 @@ -443,7 +443,7 @@ struct low_ops {
28536 struct amd64_family_type {
28537 const char *ctl_name;
28538 u16 f1_id, f3_id;
28539 - struct low_ops ops;
28540 + const struct low_ops ops;
28541 };
28542
28543 int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
28544 diff -urNp linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c
28545 --- linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28546 +++ linux-2.6.39.1/drivers/edac/edac_mc_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28547 @@ -760,7 +760,7 @@ static void edac_inst_grp_release(struct
28548 }
28549
28550 /* Intermediate show/store table */
28551 -static struct sysfs_ops inst_grp_ops = {
28552 +static const struct sysfs_ops inst_grp_ops = {
28553 .show = inst_grp_show,
28554 .store = inst_grp_store
28555 };
28556 diff -urNp linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c
28557 --- linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28558 +++ linux-2.6.39.1/drivers/edac/edac_pci_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28559 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log
28560 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28561 static int edac_pci_poll_msec = 1000; /* one second workq period */
28562
28563 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
28564 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28565 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28566 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28567
28568 static struct kobject *edac_pci_top_main_kobj;
28569 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28570 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(str
28571 edac_printk(KERN_CRIT, EDAC_PCI,
28572 "Signaled System Error on %s\n",
28573 pci_name(dev));
28574 - atomic_inc(&pci_nonparity_count);
28575 + atomic_inc_unchecked(&pci_nonparity_count);
28576 }
28577
28578 if (status & (PCI_STATUS_PARITY)) {
28579 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(str
28580 "Master Data Parity Error on %s\n",
28581 pci_name(dev));
28582
28583 - atomic_inc(&pci_parity_count);
28584 + atomic_inc_unchecked(&pci_parity_count);
28585 }
28586
28587 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28588 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(str
28589 "Detected Parity Error on %s\n",
28590 pci_name(dev));
28591
28592 - atomic_inc(&pci_parity_count);
28593 + atomic_inc_unchecked(&pci_parity_count);
28594 }
28595 }
28596
28597 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(str
28598 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28599 "Signaled System Error on %s\n",
28600 pci_name(dev));
28601 - atomic_inc(&pci_nonparity_count);
28602 + atomic_inc_unchecked(&pci_nonparity_count);
28603 }
28604
28605 if (status & (PCI_STATUS_PARITY)) {
28606 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(str
28607 "Master Data Parity Error on "
28608 "%s\n", pci_name(dev));
28609
28610 - atomic_inc(&pci_parity_count);
28611 + atomic_inc_unchecked(&pci_parity_count);
28612 }
28613
28614 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28615 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(str
28616 "Detected Parity Error on %s\n",
28617 pci_name(dev));
28618
28619 - atomic_inc(&pci_parity_count);
28620 + atomic_inc_unchecked(&pci_parity_count);
28621 }
28622 }
28623 }
28624 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28625 if (!check_pci_errors)
28626 return;
28627
28628 - before_count = atomic_read(&pci_parity_count);
28629 + before_count = atomic_read_unchecked(&pci_parity_count);
28630
28631 /* scan all PCI devices looking for a Parity Error on devices and
28632 * bridges.
28633 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
28634 /* Only if operator has selected panic on PCI Error */
28635 if (edac_pci_get_panic_on_pe()) {
28636 /* If the count is different 'after' from 'before' */
28637 - if (before_count != atomic_read(&pci_parity_count))
28638 + if (before_count != atomic_read_unchecked(&pci_parity_count))
28639 panic("EDAC: PCI Parity Error");
28640 }
28641 }
28642 diff -urNp linux-2.6.39.1/drivers/firewire/core-cdev.c linux-2.6.39.1/drivers/firewire/core-cdev.c
28643 --- linux-2.6.39.1/drivers/firewire/core-cdev.c 2011-05-19 00:06:34.000000000 -0400
28644 +++ linux-2.6.39.1/drivers/firewire/core-cdev.c 2011-05-22 19:36:31.000000000 -0400
28645 @@ -1312,8 +1312,7 @@ static int init_iso_resource(struct clie
28646 int ret;
28647
28648 if ((request->channels == 0 && request->bandwidth == 0) ||
28649 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28650 - request->bandwidth < 0)
28651 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28652 return -EINVAL;
28653
28654 r = kmalloc(sizeof(*r), GFP_KERNEL);
28655 diff -urNp linux-2.6.39.1/drivers/firewire/core-transaction.c linux-2.6.39.1/drivers/firewire/core-transaction.c
28656 --- linux-2.6.39.1/drivers/firewire/core-transaction.c 2011-05-19 00:06:34.000000000 -0400
28657 +++ linux-2.6.39.1/drivers/firewire/core-transaction.c 2011-05-22 19:36:31.000000000 -0400
28658 @@ -36,6 +36,7 @@
28659 #include <linux/string.h>
28660 #include <linux/timer.h>
28661 #include <linux/types.h>
28662 +#include <linux/sched.h>
28663
28664 #include <asm/byteorder.h>
28665
28666 @@ -420,6 +421,8 @@ int fw_run_transaction(struct fw_card *c
28667 struct transaction_callback_data d;
28668 struct fw_transaction t;
28669
28670 + pax_track_stack();
28671 +
28672 init_timer_on_stack(&t.split_timeout_timer);
28673 init_completion(&d.done);
28674 d.payload = payload;
28675 diff -urNp linux-2.6.39.1/drivers/firmware/dmi_scan.c linux-2.6.39.1/drivers/firmware/dmi_scan.c
28676 --- linux-2.6.39.1/drivers/firmware/dmi_scan.c 2011-05-19 00:06:34.000000000 -0400
28677 +++ linux-2.6.39.1/drivers/firmware/dmi_scan.c 2011-05-22 19:36:31.000000000 -0400
28678 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
28679 }
28680 }
28681 else {
28682 - /*
28683 - * no iounmap() for that ioremap(); it would be a no-op, but
28684 - * it's so early in setup that sucker gets confused into doing
28685 - * what it shouldn't if we actually call it.
28686 - */
28687 p = dmi_ioremap(0xF0000, 0x10000);
28688 if (p == NULL)
28689 goto error;
28690 diff -urNp linux-2.6.39.1/drivers/gpio/vr41xx_giu.c linux-2.6.39.1/drivers/gpio/vr41xx_giu.c
28691 --- linux-2.6.39.1/drivers/gpio/vr41xx_giu.c 2011-05-19 00:06:34.000000000 -0400
28692 +++ linux-2.6.39.1/drivers/gpio/vr41xx_giu.c 2011-05-22 19:36:31.000000000 -0400
28693 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28694 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28695 maskl, pendl, maskh, pendh);
28696
28697 - atomic_inc(&irq_err_count);
28698 + atomic_inc_unchecked(&irq_err_count);
28699
28700 return -EINVAL;
28701 }
28702 diff -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
28703 --- linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c 2011-05-19 00:06:34.000000000 -0400
28704 +++ linux-2.6.39.1/drivers/gpu/drm/drm_crtc_helper.c 2011-05-22 19:36:31.000000000 -0400
28705 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
28706 struct drm_crtc *tmp;
28707 int crtc_mask = 1;
28708
28709 - WARN(!crtc, "checking null crtc?\n");
28710 + BUG_ON(!crtc);
28711
28712 dev = crtc->dev;
28713
28714 @@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm
28715 struct drm_encoder *encoder;
28716 bool ret = true;
28717
28718 + pax_track_stack();
28719 +
28720 crtc->enabled = drm_helper_crtc_in_use(crtc);
28721 if (!crtc->enabled)
28722 return true;
28723 diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_drv.c linux-2.6.39.1/drivers/gpu/drm/drm_drv.c
28724 --- linux-2.6.39.1/drivers/gpu/drm/drm_drv.c 2011-05-19 00:06:34.000000000 -0400
28725 +++ linux-2.6.39.1/drivers/gpu/drm/drm_drv.c 2011-05-22 19:36:31.000000000 -0400
28726 @@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
28727
28728 dev = file_priv->minor->dev;
28729 atomic_inc(&dev->ioctl_count);
28730 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28731 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28732 ++file_priv->ioctl_count;
28733
28734 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28735 diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_fops.c linux-2.6.39.1/drivers/gpu/drm/drm_fops.c
28736 --- linux-2.6.39.1/drivers/gpu/drm/drm_fops.c 2011-05-19 00:06:34.000000000 -0400
28737 +++ linux-2.6.39.1/drivers/gpu/drm/drm_fops.c 2011-05-22 19:36:31.000000000 -0400
28738 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
28739 }
28740
28741 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28742 - atomic_set(&dev->counts[i], 0);
28743 + atomic_set_unchecked(&dev->counts[i], 0);
28744
28745 dev->sigdata.lock = NULL;
28746
28747 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
28748
28749 retcode = drm_open_helper(inode, filp, dev);
28750 if (!retcode) {
28751 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28752 - if (!dev->open_count++)
28753 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28754 + if (local_inc_return(&dev->open_count) == 1)
28755 retcode = drm_setup(dev);
28756 }
28757 if (!retcode) {
28758 @@ -472,7 +472,7 @@ int drm_release(struct inode *inode, str
28759
28760 mutex_lock(&drm_global_mutex);
28761
28762 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28763 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28764
28765 if (dev->driver->preclose)
28766 dev->driver->preclose(dev, file_priv);
28767 @@ -484,7 +484,7 @@ int drm_release(struct inode *inode, str
28768 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28769 task_pid_nr(current),
28770 (long)old_encode_dev(file_priv->minor->device),
28771 - dev->open_count);
28772 + local_read(&dev->open_count));
28773
28774 /* if the master has gone away we can't do anything with the lock */
28775 if (file_priv->minor->master)
28776 @@ -565,8 +565,8 @@ int drm_release(struct inode *inode, str
28777 * End inline drm_release
28778 */
28779
28780 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28781 - if (!--dev->open_count) {
28782 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28783 + if (local_dec_and_test(&dev->open_count)) {
28784 if (atomic_read(&dev->ioctl_count)) {
28785 DRM_ERROR("Device busy: %d\n",
28786 atomic_read(&dev->ioctl_count));
28787 diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_global.c linux-2.6.39.1/drivers/gpu/drm/drm_global.c
28788 --- linux-2.6.39.1/drivers/gpu/drm/drm_global.c 2011-05-19 00:06:34.000000000 -0400
28789 +++ linux-2.6.39.1/drivers/gpu/drm/drm_global.c 2011-05-22 19:36:31.000000000 -0400
28790 @@ -36,7 +36,7 @@
28791 struct drm_global_item {
28792 struct mutex mutex;
28793 void *object;
28794 - int refcount;
28795 + atomic_t refcount;
28796 };
28797
28798 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28799 @@ -49,7 +49,7 @@ void drm_global_init(void)
28800 struct drm_global_item *item = &glob[i];
28801 mutex_init(&item->mutex);
28802 item->object = NULL;
28803 - item->refcount = 0;
28804 + atomic_set(&item->refcount, 0);
28805 }
28806 }
28807
28808 @@ -59,7 +59,7 @@ void drm_global_release(void)
28809 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28810 struct drm_global_item *item = &glob[i];
28811 BUG_ON(item->object != NULL);
28812 - BUG_ON(item->refcount != 0);
28813 + BUG_ON(atomic_read(&item->refcount) != 0);
28814 }
28815 }
28816
28817 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
28818 void *object;
28819
28820 mutex_lock(&item->mutex);
28821 - if (item->refcount == 0) {
28822 + if (atomic_read(&item->refcount) == 0) {
28823 item->object = kzalloc(ref->size, GFP_KERNEL);
28824 if (unlikely(item->object == NULL)) {
28825 ret = -ENOMEM;
28826 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
28827 goto out_err;
28828
28829 }
28830 - ++item->refcount;
28831 + atomic_inc(&item->refcount);
28832 ref->object = item->object;
28833 object = item->object;
28834 mutex_unlock(&item->mutex);
28835 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
28836 struct drm_global_item *item = &glob[ref->global_type];
28837
28838 mutex_lock(&item->mutex);
28839 - BUG_ON(item->refcount == 0);
28840 + BUG_ON(atomic_read(&item->refcount) == 0);
28841 BUG_ON(ref->object != item->object);
28842 - if (--item->refcount == 0) {
28843 + if (atomic_dec_and_test(&item->refcount)) {
28844 ref->release(ref);
28845 item->object = NULL;
28846 }
28847 diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_info.c linux-2.6.39.1/drivers/gpu/drm/drm_info.c
28848 --- linux-2.6.39.1/drivers/gpu/drm/drm_info.c 2011-05-19 00:06:34.000000000 -0400
28849 +++ linux-2.6.39.1/drivers/gpu/drm/drm_info.c 2011-05-22 19:41:37.000000000 -0400
28850 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
28851 struct drm_local_map *map;
28852 struct drm_map_list *r_list;
28853
28854 - /* Hardcoded from _DRM_FRAME_BUFFER,
28855 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28856 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28857 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28858 + static const char * const types[] = {
28859 + [_DRM_FRAME_BUFFER] = "FB",
28860 + [_DRM_REGISTERS] = "REG",
28861 + [_DRM_SHM] = "SHM",
28862 + [_DRM_AGP] = "AGP",
28863 + [_DRM_SCATTER_GATHER] = "SG",
28864 + [_DRM_CONSISTENT] = "PCI",
28865 + [_DRM_GEM] = "GEM" };
28866 const char *type;
28867 int i;
28868
28869 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
28870 map = r_list->map;
28871 if (!map)
28872 continue;
28873 - if (map->type < 0 || map->type > 5)
28874 + if (map->type >= ARRAY_SIZE(types))
28875 type = "??";
28876 else
28877 type = types[map->type];
28878 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, voi
28879 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28880 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28881 vma->vm_flags & VM_IO ? 'i' : '-',
28882 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28883 + 0);
28884 +#else
28885 vma->vm_pgoff);
28886 +#endif
28887
28888 #if defined(__i386__)
28889 pgprot = pgprot_val(vma->vm_page_prot);
28890 diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c
28891 --- linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c 2011-05-19 00:06:34.000000000 -0400
28892 +++ linux-2.6.39.1/drivers/gpu/drm/drm_ioctl.c 2011-05-22 19:36:31.000000000 -0400
28893 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev,
28894 stats->data[i].value =
28895 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28896 else
28897 - stats->data[i].value = atomic_read(&dev->counts[i]);
28898 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28899 stats->data[i].type = dev->types[i];
28900 }
28901
28902 diff -urNp linux-2.6.39.1/drivers/gpu/drm/drm_lock.c linux-2.6.39.1/drivers/gpu/drm/drm_lock.c
28903 --- linux-2.6.39.1/drivers/gpu/drm/drm_lock.c 2011-05-19 00:06:34.000000000 -0400
28904 +++ linux-2.6.39.1/drivers/gpu/drm/drm_lock.c 2011-05-22 19:36:31.000000000 -0400
28905 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
28906 if (drm_lock_take(&master->lock, lock->context)) {
28907 master->lock.file_priv = file_priv;
28908 master->lock.lock_time = jiffies;
28909 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28910 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28911 break; /* Got lock */
28912 }
28913
28914 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
28915 return -EINVAL;
28916 }
28917
28918 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28919 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28920
28921 if (drm_lock_free(&master->lock, lock->context)) {
28922 /* FIXME: Should really bail out here. */
28923 diff -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
28924 --- linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c 2011-05-19 00:06:34.000000000 -0400
28925 +++ linux-2.6.39.1/drivers/gpu/drm/i810/i810_dma.c 2011-05-22 19:36:31.000000000 -0400
28926 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_de
28927 dma->buflist[vertex->idx],
28928 vertex->discard, vertex->used);
28929
28930 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28931 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28932 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28933 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28934 sarea_priv->last_enqueue = dev_priv->counter - 1;
28935 sarea_priv->last_dispatch = (int)hw_status[5];
28936
28937 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device
28938 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28939 mc->last_render);
28940
28941 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28942 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28943 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28944 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28945 sarea_priv->last_enqueue = dev_priv->counter - 1;
28946 sarea_priv->last_dispatch = (int)hw_status[5];
28947
28948 diff -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
28949 --- linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h 2011-05-19 00:06:34.000000000 -0400
28950 +++ linux-2.6.39.1/drivers/gpu/drm/i810/i810_drv.h 2011-05-22 19:36:31.000000000 -0400
28951 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28952 int page_flipping;
28953
28954 wait_queue_head_t irq_queue;
28955 - atomic_t irq_received;
28956 - atomic_t irq_emitted;
28957 + atomic_unchecked_t irq_received;
28958 + atomic_unchecked_t irq_emitted;
28959
28960 int front_offset;
28961 } drm_i810_private_t;
28962 diff -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
28963 --- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-19 00:06:34.000000000 -0400
28964 +++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-22 19:36:31.000000000 -0400
28965 @@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
28966 }
28967 }
28968
28969 -struct intel_dvo_dev_ops ch7017_ops = {
28970 +const struct intel_dvo_dev_ops ch7017_ops = {
28971 .init = ch7017_init,
28972 .detect = ch7017_detect,
28973 .mode_valid = ch7017_mode_valid,
28974 diff -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
28975 --- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-19 00:06:34.000000000 -0400
28976 +++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-22 19:36:31.000000000 -0400
28977 @@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
28978 }
28979 }
28980
28981 -struct intel_dvo_dev_ops ch7xxx_ops = {
28982 +const struct intel_dvo_dev_ops ch7xxx_ops = {
28983 .init = ch7xxx_init,
28984 .detect = ch7xxx_detect,
28985 .mode_valid = ch7xxx_mode_valid,
28986 diff -urNp linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h
28987 --- linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h 2011-05-19 00:06:34.000000000 -0400
28988 +++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo.h 2011-05-22 19:36:31.000000000 -0400
28989 @@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
28990 *
28991 * \return singly-linked list of modes or NULL if no modes found.
28992 */
28993 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
28994 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
28995
28996 /**
28997 * Clean up driver-specific bits of the output
28998 */
28999 - void (*destroy) (struct intel_dvo_device *dvo);
29000 + void (* const destroy) (struct intel_dvo_device *dvo);
29001
29002 /**
29003 * Debugging hook to dump device registers to log file
29004 */
29005 - void (*dump_regs)(struct intel_dvo_device *dvo);
29006 + void (* const dump_regs)(struct intel_dvo_device *dvo);
29007 };
29008
29009 -extern struct intel_dvo_dev_ops sil164_ops;
29010 -extern struct intel_dvo_dev_ops ch7xxx_ops;
29011 -extern struct intel_dvo_dev_ops ivch_ops;
29012 -extern struct intel_dvo_dev_ops tfp410_ops;
29013 -extern struct intel_dvo_dev_ops ch7017_ops;
29014 +extern const struct intel_dvo_dev_ops sil164_ops;
29015 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
29016 +extern const struct intel_dvo_dev_ops ivch_ops;
29017 +extern const struct intel_dvo_dev_ops tfp410_ops;
29018 +extern const struct intel_dvo_dev_ops ch7017_ops;
29019
29020 #endif /* _INTEL_DVO_H */
29021 diff -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
29022 --- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-19 00:06:34.000000000 -0400
29023 +++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-22 19:36:31.000000000 -0400
29024 @@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
29025 }
29026 }
29027
29028 -struct intel_dvo_dev_ops ivch_ops= {
29029 +const struct intel_dvo_dev_ops ivch_ops= {
29030 .init = ivch_init,
29031 .dpms = ivch_dpms,
29032 .mode_valid = ivch_mode_valid,
29033 diff -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
29034 --- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-19 00:06:34.000000000 -0400
29035 +++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-22 19:36:31.000000000 -0400
29036 @@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
29037 }
29038 }
29039
29040 -struct intel_dvo_dev_ops sil164_ops = {
29041 +const struct intel_dvo_dev_ops sil164_ops = {
29042 .init = sil164_init,
29043 .detect = sil164_detect,
29044 .mode_valid = sil164_mode_valid,
29045 diff -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
29046 --- linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-19 00:06:34.000000000 -0400
29047 +++ linux-2.6.39.1/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-22 19:36:31.000000000 -0400
29048 @@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
29049 }
29050 }
29051
29052 -struct intel_dvo_dev_ops tfp410_ops = {
29053 +const struct intel_dvo_dev_ops tfp410_ops = {
29054 .init = tfp410_init,
29055 .detect = tfp410_detect,
29056 .mode_valid = tfp410_mode_valid,
29057 diff -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
29058 --- linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-19 00:06:34.000000000 -0400
29059 +++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-22 19:36:31.000000000 -0400
29060 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct se
29061 I915_READ(GTIMR));
29062 }
29063 seq_printf(m, "Interrupts received: %d\n",
29064 - atomic_read(&dev_priv->irq_received));
29065 + atomic_read_unchecked(&dev_priv->irq_received));
29066 for (i = 0; i < I915_NUM_RINGS; i++) {
29067 if (IS_GEN6(dev)) {
29068 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29069 diff -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
29070 --- linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c 2011-05-19 00:06:34.000000000 -0400
29071 +++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_dma.c 2011-05-22 19:36:31.000000000 -0400
29072 @@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(s
29073 bool can_switch;
29074
29075 spin_lock(&dev->count_lock);
29076 - can_switch = (dev->open_count == 0);
29077 + can_switch = (local_read(&dev->open_count) == 0);
29078 spin_unlock(&dev->count_lock);
29079 return can_switch;
29080 }
29081 diff -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
29082 --- linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c 2011-05-19 00:06:34.000000000 -0400
29083 +++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.c 2011-05-22 19:36:31.000000000 -0400
29084 @@ -679,7 +679,7 @@ static const struct dev_pm_ops i915_pm_o
29085 .restore = i915_pm_resume,
29086 };
29087
29088 -static struct vm_operations_struct i915_gem_vm_ops = {
29089 +static const struct vm_operations_struct i915_gem_vm_ops = {
29090 .fault = i915_gem_fault,
29091 .open = drm_gem_vm_open,
29092 .close = drm_gem_vm_close,
29093 diff -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
29094 --- linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h 2011-05-19 00:06:34.000000000 -0400
29095 +++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_drv.h 2011-05-22 19:36:31.000000000 -0400
29096 @@ -287,7 +287,7 @@ typedef struct drm_i915_private {
29097 int current_page;
29098 int page_flipping;
29099
29100 - atomic_t irq_received;
29101 + atomic_unchecked_t irq_received;
29102
29103 /* protects the irq masks */
29104 spinlock_t irq_lock;
29105 @@ -848,7 +848,7 @@ struct drm_i915_gem_object {
29106 * will be page flipped away on the next vblank. When it
29107 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29108 */
29109 - atomic_t pending_flip;
29110 + atomic_unchecked_t pending_flip;
29111 };
29112
29113 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29114 @@ -1232,7 +1232,7 @@ extern int intel_setup_gmbus(struct drm_
29115 extern void intel_teardown_gmbus(struct drm_device *dev);
29116 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29117 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29118 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29119 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29120 {
29121 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29122 }
29123 diff -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
29124 --- linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-19 00:06:34.000000000 -0400
29125 +++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-22 19:36:31.000000000 -0400
29126 @@ -192,7 +192,7 @@ i915_gem_object_set_to_gpu_domain(struct
29127 i915_gem_release_mmap(obj);
29128
29129 if (obj->base.pending_write_domain)
29130 - cd->flips |= atomic_read(&obj->pending_flip);
29131 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29132
29133 /* The actual obj->write_domain will be updated with
29134 * pending_write_domain after we emit the accumulated flush for all
29135 diff -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
29136 --- linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c 2011-05-19 00:06:34.000000000 -0400
29137 +++ linux-2.6.39.1/drivers/gpu/drm/i915/i915_irq.c 2011-05-22 19:36:31.000000000 -0400
29138 @@ -1101,7 +1101,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29139 int ret = IRQ_NONE, pipe;
29140 bool blc_event = false;
29141
29142 - atomic_inc(&dev_priv->irq_received);
29143 + atomic_inc_unchecked(&dev_priv->irq_received);
29144
29145 if (HAS_PCH_SPLIT(dev))
29146 return ironlake_irq_handler(dev);
29147 @@ -1655,7 +1655,7 @@ void i915_driver_irq_preinstall(struct d
29148 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29149 int pipe;
29150
29151 - atomic_set(&dev_priv->irq_received, 0);
29152 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29153
29154 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29155 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29156 diff -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
29157 --- linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c 2011-05-19 00:06:34.000000000 -0400
29158 +++ linux-2.6.39.1/drivers/gpu/drm/i915/intel_display.c 2011-05-22 19:36:31.000000000 -0400
29159 @@ -2244,7 +2244,7 @@ intel_pipe_set_base(struct drm_crtc *crt
29160
29161 wait_event(dev_priv->pending_flip_queue,
29162 atomic_read(&dev_priv->mm.wedged) ||
29163 - atomic_read(&obj->pending_flip) == 0);
29164 + atomic_read_unchecked(&obj->pending_flip) == 0);
29165
29166 /* Big Hammer, we also need to ensure that any pending
29167 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29168 @@ -2712,7 +2712,7 @@ static void intel_crtc_wait_for_pending_
29169 obj = to_intel_framebuffer(crtc->fb)->obj;
29170 dev_priv = crtc->dev->dev_private;
29171 wait_event(dev_priv->pending_flip_queue,
29172 - atomic_read(&obj->pending_flip) == 0);
29173 + atomic_read_unchecked(&obj->pending_flip) == 0);
29174 }
29175
29176 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29177 @@ -6016,7 +6016,7 @@ static void do_intel_finish_page_flip(st
29178
29179 atomic_clear_mask(1 << intel_crtc->plane,
29180 &obj->pending_flip.counter);
29181 - if (atomic_read(&obj->pending_flip) == 0)
29182 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
29183 wake_up(&dev_priv->pending_flip_queue);
29184
29185 schedule_work(&work->work);
29186 @@ -6145,7 +6145,7 @@ static int intel_crtc_page_flip(struct d
29187 /* Block clients from rendering to the new back buffer until
29188 * the flip occurs and the object is no longer visible.
29189 */
29190 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29191 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29192
29193 switch (INTEL_INFO(dev)->gen) {
29194 case 2:
29195 diff -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
29196 --- linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h 2011-05-19 00:06:34.000000000 -0400
29197 +++ linux-2.6.39.1/drivers/gpu/drm/mga/mga_drv.h 2011-05-22 19:36:31.000000000 -0400
29198 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29199 u32 clear_cmd;
29200 u32 maccess;
29201
29202 - atomic_t vbl_received; /**< Number of vblanks received. */
29203 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29204 wait_queue_head_t fence_queue;
29205 - atomic_t last_fence_retired;
29206 + atomic_unchecked_t last_fence_retired;
29207 u32 next_fence_to_post;
29208
29209 unsigned int fb_cpp;
29210 diff -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
29211 --- linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c 2011-05-19 00:06:34.000000000 -0400
29212 +++ linux-2.6.39.1/drivers/gpu/drm/mga/mga_irq.c 2011-05-22 19:36:31.000000000 -0400
29213 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29214 if (crtc != 0)
29215 return 0;
29216
29217 - return atomic_read(&dev_priv->vbl_received);
29218 + return atomic_read_unchecked(&dev_priv->vbl_received);
29219 }
29220
29221
29222 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29223 /* VBLANK interrupt */
29224 if (status & MGA_VLINEPEN) {
29225 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29226 - atomic_inc(&dev_priv->vbl_received);
29227 + atomic_inc_unchecked(&dev_priv->vbl_received);
29228 drm_handle_vblank(dev, 0);
29229 handled = 1;
29230 }
29231 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29232 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29233 MGA_WRITE(MGA_PRIMEND, prim_end);
29234
29235 - atomic_inc(&dev_priv->last_fence_retired);
29236 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
29237 DRM_WAKEUP(&dev_priv->fence_queue);
29238 handled = 1;
29239 }
29240 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_dev
29241 * using fences.
29242 */
29243 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29244 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29245 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29246 - *sequence) <= (1 << 23)));
29247
29248 *sequence = cur_fence;
29249 diff -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
29250 --- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-19 00:06:34.000000000 -0400
29251 +++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-22 19:36:31.000000000 -0400
29252 @@ -141,7 +141,7 @@ static int nouveau_dsm_get_client_id(str
29253 return VGA_SWITCHEROO_DIS;
29254 }
29255
29256 -static struct vga_switcheroo_handler nouveau_dsm_handler = {
29257 +static const struct vga_switcheroo_handler nouveau_dsm_handler = {
29258 .switchto = nouveau_dsm_switchto,
29259 .power_state = nouveau_dsm_power_state,
29260 .init = nouveau_dsm_init,
29261 diff -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
29262 --- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-19 00:06:34.000000000 -0400
29263 +++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-23 17:07:00.000000000 -0400
29264 @@ -228,7 +228,7 @@ struct nouveau_channel {
29265 struct list_head pending;
29266 uint32_t sequence;
29267 uint32_t sequence_ack;
29268 - atomic_t last_sequence_irq;
29269 + atomic_unchecked_t last_sequence_irq;
29270 } fence;
29271
29272 /* DMA push buffer */
29273 @@ -520,8 +520,8 @@ struct nouveau_vram_engine {
29274
29275 struct nouveau_engine {
29276 struct nouveau_instmem_engine instmem;
29277 - struct nouveau_mc_engine mc;
29278 - struct nouveau_timer_engine timer;
29279 + struct nouveau_mc_engine mc;
29280 + struct nouveau_timer_engine timer;
29281 struct nouveau_fb_engine fb;
29282 struct nouveau_pgraph_engine graph;
29283 struct nouveau_fifo_engine fifo;
29284 @@ -529,7 +529,7 @@ struct nouveau_engine {
29285 struct nouveau_gpio_engine gpio;
29286 struct nouveau_pm_engine pm;
29287 struct nouveau_crypt_engine crypt;
29288 - struct nouveau_vram_engine vram;
29289 + struct nouveau_vram_engine vram;
29290 };
29291
29292 struct nouveau_pll_vals {
29293 @@ -662,7 +662,7 @@ struct drm_nouveau_private {
29294 struct drm_global_reference mem_global_ref;
29295 struct ttm_bo_global_ref bo_global_ref;
29296 struct ttm_bo_device bdev;
29297 - atomic_t validate_sequence;
29298 + atomic_unchecked_t validate_sequence;
29299 } ttm;
29300
29301 struct {
29302 diff -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
29303 --- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-19 00:06:34.000000000 -0400
29304 +++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-22 19:36:31.000000000 -0400
29305 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_chan
29306 if (USE_REFCNT(dev))
29307 sequence = nvchan_rd32(chan, 0x48);
29308 else
29309 - sequence = atomic_read(&chan->fence.last_sequence_irq);
29310 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29311
29312 if (chan->fence.sequence_ack == sequence)
29313 goto out;
29314 @@ -553,7 +553,7 @@ nouveau_fence_channel_init(struct nouvea
29315 out_initialised:
29316 INIT_LIST_HEAD(&chan->fence.pending);
29317 spin_lock_init(&chan->fence.lock);
29318 - atomic_set(&chan->fence.last_sequence_irq, 0);
29319 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29320 return 0;
29321 }
29322
29323 diff -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
29324 --- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-19 00:06:34.000000000 -0400
29325 +++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-22 19:36:31.000000000 -0400
29326 @@ -249,7 +249,7 @@ validate_init(struct nouveau_channel *ch
29327 int trycnt = 0;
29328 int ret, i;
29329
29330 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29331 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29332 retry:
29333 if (++trycnt > 100000) {
29334 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29335 diff -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
29336 --- linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-19 00:06:34.000000000 -0400
29337 +++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-22 19:36:31.000000000 -0400
29338 @@ -583,7 +583,7 @@ static bool nouveau_switcheroo_can_switc
29339 bool can_switch;
29340
29341 spin_lock(&dev->count_lock);
29342 - can_switch = (dev->open_count == 0);
29343 + can_switch = (local_read(&dev->open_count) == 0);
29344 spin_unlock(&dev->count_lock);
29345 return can_switch;
29346 }
29347 diff -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
29348 --- linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-19 00:06:34.000000000 -0400
29349 +++ linux-2.6.39.1/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-22 19:36:31.000000000 -0400
29350 @@ -552,7 +552,7 @@ static int
29351 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29352 u32 class, u32 mthd, u32 data)
29353 {
29354 - atomic_set(&chan->fence.last_sequence_irq, data);
29355 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29356 return 0;
29357 }
29358
29359 diff -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
29360 --- linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c 2011-05-19 00:06:34.000000000 -0400
29361 +++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_cce.c 2011-05-22 19:36:31.000000000 -0400
29362 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29363
29364 /* GH: Simple idle check.
29365 */
29366 - atomic_set(&dev_priv->idle_count, 0);
29367 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29368
29369 /* We don't support anything other than bus-mastering ring mode,
29370 * but the ring can be in either AGP or PCI space for the ring
29371 diff -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
29372 --- linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h 2011-05-19 00:06:34.000000000 -0400
29373 +++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_drv.h 2011-05-22 19:36:31.000000000 -0400
29374 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29375 int is_pci;
29376 unsigned long cce_buffers_offset;
29377
29378 - atomic_t idle_count;
29379 + atomic_unchecked_t idle_count;
29380
29381 int page_flipping;
29382 int current_page;
29383 u32 crtc_offset;
29384 u32 crtc_offset_cntl;
29385
29386 - atomic_t vbl_received;
29387 + atomic_unchecked_t vbl_received;
29388
29389 u32 color_fmt;
29390 unsigned int front_offset;
29391 diff -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
29392 --- linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c 2011-05-19 00:06:34.000000000 -0400
29393 +++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_irq.c 2011-05-22 19:36:31.000000000 -0400
29394 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29395 if (crtc != 0)
29396 return 0;
29397
29398 - return atomic_read(&dev_priv->vbl_received);
29399 + return atomic_read_unchecked(&dev_priv->vbl_received);
29400 }
29401
29402 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29403 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29404 /* VBLANK interrupt */
29405 if (status & R128_CRTC_VBLANK_INT) {
29406 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29407 - atomic_inc(&dev_priv->vbl_received);
29408 + atomic_inc_unchecked(&dev_priv->vbl_received);
29409 drm_handle_vblank(dev, 0);
29410 return IRQ_HANDLED;
29411 }
29412 diff -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
29413 --- linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c 2011-05-19 00:06:34.000000000 -0400
29414 +++ linux-2.6.39.1/drivers/gpu/drm/r128/r128_state.c 2011-05-22 19:36:31.000000000 -0400
29415 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_priv
29416
29417 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
29418 {
29419 - if (atomic_read(&dev_priv->idle_count) == 0)
29420 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
29421 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29422 else
29423 - atomic_set(&dev_priv->idle_count, 0);
29424 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29425 }
29426
29427 #endif
29428 diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c
29429 --- linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c 2011-05-19 00:06:34.000000000 -0400
29430 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/atom.c 2011-05-22 19:36:31.000000000 -0400
29431 @@ -1245,6 +1245,8 @@ struct atom_context *atom_parse(struct c
29432 char name[512];
29433 int i;
29434
29435 + pax_track_stack();
29436 +
29437 ctx->card = card;
29438 ctx->bios = bios;
29439
29440 diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c
29441 --- linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c 2011-05-19 00:06:34.000000000 -0400
29442 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/mkregtable.c 2011-05-22 19:36:31.000000000 -0400
29443 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
29444 regex_t mask_rex;
29445 regmatch_t match[4];
29446 char buf[1024];
29447 - size_t end;
29448 + long end;
29449 int len;
29450 int done = 0;
29451 int r;
29452 unsigned o;
29453 struct offset *offset;
29454 char last_reg_s[10];
29455 - int last_reg;
29456 + unsigned long last_reg;
29457
29458 if (regcomp
29459 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29460 diff -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
29461 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-19 00:06:34.000000000 -0400
29462 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-22 19:36:31.000000000 -0400
29463 @@ -545,6 +545,8 @@ bool radeon_get_atom_connector_info_from
29464 struct radeon_gpio_rec gpio;
29465 struct radeon_hpd hpd;
29466
29467 + pax_track_stack();
29468 +
29469 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
29470 return false;
29471
29472 diff -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
29473 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-19 00:06:34.000000000 -0400
29474 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-22 19:36:31.000000000 -0400
29475 @@ -234,7 +234,7 @@ static int radeon_atpx_get_client_id(str
29476 return VGA_SWITCHEROO_DIS;
29477 }
29478
29479 -static struct vga_switcheroo_handler radeon_atpx_handler = {
29480 +static const struct vga_switcheroo_handler radeon_atpx_handler = {
29481 .switchto = radeon_atpx_switchto,
29482 .power_state = radeon_atpx_power_state,
29483 .init = radeon_atpx_init,
29484 diff -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
29485 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c 2011-05-19 00:06:34.000000000 -0400
29486 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_device.c 2011-05-22 19:36:31.000000000 -0400
29487 @@ -674,7 +674,7 @@ static bool radeon_switcheroo_can_switch
29488 bool can_switch;
29489
29490 spin_lock(&dev->count_lock);
29491 - can_switch = (dev->open_count == 0);
29492 + can_switch = (local_read(&dev->open_count) == 0);
29493 spin_unlock(&dev->count_lock);
29494 return can_switch;
29495 }
29496 diff -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
29497 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c 2011-05-19 00:06:34.000000000 -0400
29498 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_display.c 2011-05-22 19:36:31.000000000 -0400
29499 @@ -934,6 +934,8 @@ void radeon_compute_pll_legacy(struct ra
29500 uint32_t post_div;
29501 u32 pll_out_min, pll_out_max;
29502
29503 + pax_track_stack();
29504 +
29505 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
29506 freq = freq * 1000;
29507
29508 diff -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
29509 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-19 00:06:34.000000000 -0400
29510 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-22 19:36:31.000000000 -0400
29511 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
29512
29513 /* SW interrupt */
29514 wait_queue_head_t swi_queue;
29515 - atomic_t swi_emitted;
29516 + atomic_unchecked_t swi_emitted;
29517 int vblank_crtc;
29518 uint32_t irq_enable_reg;
29519 uint32_t r500_disp_irq_reg;
29520 diff -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
29521 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-19 00:06:34.000000000 -0400
29522 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-22 19:36:31.000000000 -0400
29523 @@ -49,7 +49,7 @@ int radeon_fence_emit(struct radeon_devi
29524 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29525 return 0;
29526 }
29527 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29528 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29529 if (!rdev->cp.ready) {
29530 /* FIXME: cp is not running assume everythings is done right
29531 * away
29532 @@ -352,7 +352,7 @@ int radeon_fence_driver_init(struct rade
29533 return r;
29534 }
29535 WREG32(rdev->fence_drv.scratch_reg, 0);
29536 - atomic_set(&rdev->fence_drv.seq, 0);
29537 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
29538 INIT_LIST_HEAD(&rdev->fence_drv.created);
29539 INIT_LIST_HEAD(&rdev->fence_drv.emited);
29540 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
29541 diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h
29542 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h 2011-05-19 00:06:34.000000000 -0400
29543 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon.h 2011-05-22 19:36:31.000000000 -0400
29544 @@ -189,7 +189,7 @@ extern int sumo_get_temp(struct radeon_d
29545 */
29546 struct radeon_fence_driver {
29547 uint32_t scratch_reg;
29548 - atomic_t seq;
29549 + atomic_unchecked_t seq;
29550 uint32_t last_seq;
29551 unsigned long last_jiffies;
29552 unsigned long last_timeout;
29553 diff -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
29554 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-19 00:06:34.000000000 -0400
29555 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-22 19:36:31.000000000 -0400
29556 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(str
29557 request = compat_alloc_user_space(sizeof(*request));
29558 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
29559 || __put_user(req32.param, &request->param)
29560 - || __put_user((void __user *)(unsigned long)req32.value,
29561 + || __put_user((unsigned long)req32.value,
29562 &request->value))
29563 return -EFAULT;
29564
29565 diff -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
29566 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-19 00:06:34.000000000 -0400
29567 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-22 19:36:31.000000000 -0400
29568 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
29569 unsigned int ret;
29570 RING_LOCALS;
29571
29572 - atomic_inc(&dev_priv->swi_emitted);
29573 - ret = atomic_read(&dev_priv->swi_emitted);
29574 + atomic_inc_unchecked(&dev_priv->swi_emitted);
29575 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29576
29577 BEGIN_RING(4);
29578 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29579 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
29580 drm_radeon_private_t *dev_priv =
29581 (drm_radeon_private_t *) dev->dev_private;
29582
29583 - atomic_set(&dev_priv->swi_emitted, 0);
29584 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29585 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29586
29587 dev->max_vblank_count = 0x001fffff;
29588 diff -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
29589 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c 2011-05-19 00:06:34.000000000 -0400
29590 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_state.c 2011-05-22 19:36:31.000000000 -0400
29591 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
29592 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29593 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29594
29595 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29596 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29597 sarea_priv->nbox * sizeof(depth_boxes[0])))
29598 return -EFAULT;
29599
29600 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
29601 {
29602 drm_radeon_private_t *dev_priv = dev->dev_private;
29603 drm_radeon_getparam_t *param = data;
29604 - int value;
29605 + int value = 0;
29606
29607 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29608
29609 diff -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
29610 --- linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-19 00:06:34.000000000 -0400
29611 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-22 19:36:31.000000000 -0400
29612 @@ -603,8 +603,9 @@ void radeon_ttm_set_active_vram_size(str
29613 man->size = size >> PAGE_SHIFT;
29614 }
29615
29616 -static struct vm_operations_struct radeon_ttm_vm_ops;
29617 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
29618 +extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
29619 +extern void ttm_bo_vm_open(struct vm_area_struct *vma);
29620 +extern void ttm_bo_vm_close(struct vm_area_struct *vma);
29621
29622 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29623 {
29624 @@ -612,17 +613,22 @@ static int radeon_ttm_fault(struct vm_ar
29625 struct radeon_device *rdev;
29626 int r;
29627
29628 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
29629 - if (bo == NULL) {
29630 + bo = (struct ttm_buffer_object *)vma->vm_private_data;
29631 + if (!bo)
29632 return VM_FAULT_NOPAGE;
29633 - }
29634 rdev = radeon_get_rdev(bo->bdev);
29635 mutex_lock(&rdev->vram_mutex);
29636 - r = ttm_vm_ops->fault(vma, vmf);
29637 + r = ttm_bo_vm_fault(vma, vmf);
29638 mutex_unlock(&rdev->vram_mutex);
29639 return r;
29640 }
29641
29642 +static const struct vm_operations_struct radeon_ttm_vm_ops = {
29643 + .fault = radeon_ttm_fault,
29644 + .open = ttm_bo_vm_open,
29645 + .close = ttm_bo_vm_close
29646 +};
29647 +
29648 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29649 {
29650 struct drm_file *file_priv;
29651 @@ -635,18 +641,11 @@ int radeon_mmap(struct file *filp, struc
29652
29653 file_priv = filp->private_data;
29654 rdev = file_priv->minor->dev->dev_private;
29655 - if (rdev == NULL) {
29656 + if (!rdev)
29657 return -EINVAL;
29658 - }
29659 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29660 - if (unlikely(r != 0)) {
29661 + if (r)
29662 return r;
29663 - }
29664 - if (unlikely(ttm_vm_ops == NULL)) {
29665 - ttm_vm_ops = vma->vm_ops;
29666 - radeon_ttm_vm_ops = *ttm_vm_ops;
29667 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29668 - }
29669 vma->vm_ops = &radeon_ttm_vm_ops;
29670 return 0;
29671 }
29672 diff -urNp linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c
29673 --- linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c 2011-05-19 00:06:34.000000000 -0400
29674 +++ linux-2.6.39.1/drivers/gpu/drm/radeon/rs690.c 2011-05-22 19:36:31.000000000 -0400
29675 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct
29676 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29677 rdev->pm.sideport_bandwidth.full)
29678 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29679 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29680 + read_delay_latency.full = dfixed_const(800 * 1000);
29681 read_delay_latency.full = dfixed_div(read_delay_latency,
29682 rdev->pm.igp_sideport_mclk);
29683 + a.full = dfixed_const(370);
29684 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29685 } else {
29686 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29687 rdev->pm.k8_bandwidth.full)
29688 diff -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
29689 --- linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-19 00:06:34.000000000 -0400
29690 +++ linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-22 19:36:31.000000000 -0400
29691 @@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
29692 return best_bo;
29693 }
29694
29695 -static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29696 +int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29697 {
29698 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
29699 vma->vm_private_data;
29700 - struct ttm_bo_device *bdev = bo->bdev;
29701 + struct ttm_bo_device *bdev;
29702 unsigned long page_offset;
29703 unsigned long page_last;
29704 unsigned long pfn;
29705 @@ -83,8 +83,12 @@ static int ttm_bo_vm_fault(struct vm_are
29706 int i;
29707 unsigned long address = (unsigned long)vmf->virtual_address;
29708 int retval = VM_FAULT_NOPAGE;
29709 - struct ttm_mem_type_manager *man =
29710 - &bdev->man[bo->mem.mem_type];
29711 + struct ttm_mem_type_manager *man;
29712 +
29713 + if (!bo)
29714 + return VM_FAULT_NOPAGE;
29715 + bdev = bo->bdev;
29716 + man = &bdev->man[bo->mem.mem_type];
29717
29718 /*
29719 * Work around locking order reversal in fault / nopfn
29720 @@ -219,22 +223,25 @@ out_unlock:
29721 ttm_bo_unreserve(bo);
29722 return retval;
29723 }
29724 +EXPORT_SYMBOL(ttm_bo_vm_fault);
29725
29726 -static void ttm_bo_vm_open(struct vm_area_struct *vma)
29727 +void ttm_bo_vm_open(struct vm_area_struct *vma)
29728 {
29729 struct ttm_buffer_object *bo =
29730 (struct ttm_buffer_object *)vma->vm_private_data;
29731
29732 (void)ttm_bo_reference(bo);
29733 }
29734 +EXPORT_SYMBOL(ttm_bo_vm_open);
29735
29736 -static void ttm_bo_vm_close(struct vm_area_struct *vma)
29737 +void ttm_bo_vm_close(struct vm_area_struct *vma)
29738 {
29739 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
29740
29741 ttm_bo_unref(&bo);
29742 vma->vm_private_data = NULL;
29743 }
29744 +EXPORT_SYMBOL(ttm_bo_vm_close);
29745
29746 static const struct vm_operations_struct ttm_bo_vm_ops = {
29747 .fault = ttm_bo_vm_fault,
29748 diff -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
29749 --- linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-19 00:06:34.000000000 -0400
29750 +++ linux-2.6.39.1/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-22 19:36:31.000000000 -0400
29751 @@ -397,9 +397,9 @@ static int ttm_pool_get_num_unused_pages
29752 */
29753 static int ttm_pool_mm_shrink(struct shrinker *shrink, int shrink_pages, gfp_t gfp_mask)
29754 {
29755 - static atomic_t start_pool = ATOMIC_INIT(0);
29756 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29757 unsigned i;
29758 - unsigned pool_offset = atomic_add_return(1, &start_pool);
29759 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29760 struct ttm_page_pool *pool;
29761
29762 pool_offset = pool_offset % NUM_POOLS;
29763 diff -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
29764 --- linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h 2011-05-19 00:06:34.000000000 -0400
29765 +++ linux-2.6.39.1/drivers/gpu/drm/via/via_drv.h 2011-05-22 19:36:31.000000000 -0400
29766 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29767 typedef uint32_t maskarray_t[5];
29768
29769 typedef struct drm_via_irq {
29770 - atomic_t irq_received;
29771 + atomic_unchecked_t irq_received;
29772 uint32_t pending_mask;
29773 uint32_t enable_mask;
29774 wait_queue_head_t irq_queue;
29775 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
29776 struct timeval last_vblank;
29777 int last_vblank_valid;
29778 unsigned usec_per_vblank;
29779 - atomic_t vbl_received;
29780 + atomic_unchecked_t vbl_received;
29781 drm_via_state_t hc_state;
29782 char pci_buf[VIA_PCI_BUF_SIZE];
29783 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29784 diff -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
29785 --- linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c 2011-05-19 00:06:34.000000000 -0400
29786 +++ linux-2.6.39.1/drivers/gpu/drm/via/via_irq.c 2011-05-22 19:36:31.000000000 -0400
29787 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
29788 if (crtc != 0)
29789 return 0;
29790
29791 - return atomic_read(&dev_priv->vbl_received);
29792 + return atomic_read_unchecked(&dev_priv->vbl_received);
29793 }
29794
29795 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29796 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
29797
29798 status = VIA_READ(VIA_REG_INTERRUPT);
29799 if (status & VIA_IRQ_VBLANK_PENDING) {
29800 - atomic_inc(&dev_priv->vbl_received);
29801 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29802 + atomic_inc_unchecked(&dev_priv->vbl_received);
29803 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29804 do_gettimeofday(&cur_vblank);
29805 if (dev_priv->last_vblank_valid) {
29806 dev_priv->usec_per_vblank =
29807 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29808 dev_priv->last_vblank = cur_vblank;
29809 dev_priv->last_vblank_valid = 1;
29810 }
29811 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29812 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29813 DRM_DEBUG("US per vblank is: %u\n",
29814 dev_priv->usec_per_vblank);
29815 }
29816 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29817
29818 for (i = 0; i < dev_priv->num_irqs; ++i) {
29819 if (status & cur_irq->pending_mask) {
29820 - atomic_inc(&cur_irq->irq_received);
29821 + atomic_inc_unchecked(&cur_irq->irq_received);
29822 DRM_WAKEUP(&cur_irq->irq_queue);
29823 handled = 1;
29824 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29825 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *d
29826 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29827 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29828 masks[irq][4]));
29829 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29830 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29831 } else {
29832 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29833 (((cur_irq_sequence =
29834 - atomic_read(&cur_irq->irq_received)) -
29835 + atomic_read_unchecked(&cur_irq->irq_received)) -
29836 *sequence) <= (1 << 23)));
29837 }
29838 *sequence = cur_irq_sequence;
29839 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct dr
29840 }
29841
29842 for (i = 0; i < dev_priv->num_irqs; ++i) {
29843 - atomic_set(&cur_irq->irq_received, 0);
29844 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29845 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29846 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29847 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29848 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev,
29849 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29850 case VIA_IRQ_RELATIVE:
29851 irqwait->request.sequence +=
29852 - atomic_read(&cur_irq->irq_received);
29853 + atomic_read_unchecked(&cur_irq->irq_received);
29854 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29855 case VIA_IRQ_ABSOLUTE:
29856 break;
29857 diff -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
29858 --- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-19 00:06:34.000000000 -0400
29859 +++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-22 19:36:31.000000000 -0400
29860 @@ -240,7 +240,7 @@ struct vmw_private {
29861 * Fencing and IRQs.
29862 */
29863
29864 - atomic_t fence_seq;
29865 + atomic_unchecked_t fence_seq;
29866 wait_queue_head_t fence_queue;
29867 wait_queue_head_t fifo_queue;
29868 atomic_t fence_queue_waiters;
29869 diff -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
29870 --- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-19 00:06:34.000000000 -0400
29871 +++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-22 19:36:31.000000000 -0400
29872 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev
29873 while (!vmw_lag_lt(queue, us)) {
29874 spin_lock(&queue->lock);
29875 if (list_empty(&queue->head))
29876 - sequence = atomic_read(&dev_priv->fence_seq);
29877 + sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29878 else {
29879 fence = list_first_entry(&queue->head,
29880 struct vmw_fence, head);
29881 diff -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
29882 --- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-19 00:06:34.000000000 -0400
29883 +++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-22 19:36:31.000000000 -0400
29884 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *de
29885 (unsigned int) min,
29886 (unsigned int) fifo->capabilities);
29887
29888 - atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29889 + atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
29890 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
29891 vmw_fence_queue_init(&fifo->fence_queue);
29892 return vmw_fifo_send_fence(dev_priv, &dummy);
29893 @@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_priva
29894
29895 fm = vmw_fifo_reserve(dev_priv, bytes);
29896 if (unlikely(fm == NULL)) {
29897 - *sequence = atomic_read(&dev_priv->fence_seq);
29898 + *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
29899 ret = -ENOMEM;
29900 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
29901 false, 3*HZ);
29902 @@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_priva
29903 }
29904
29905 do {
29906 - *sequence = atomic_add_return(1, &dev_priv->fence_seq);
29907 + *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
29908 } while (*sequence == 0);
29909
29910 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29911 @@ -534,7 +534,7 @@ static int vmw_fifo_vm_fault(struct vm_a
29912 return VM_FAULT_SIGBUS;
29913 }
29914
29915 -static struct vm_operations_struct vmw_fifo_vm_ops = {
29916 +static const struct vm_operations_struct vmw_fifo_vm_ops = {
29917 .fault = vmw_fifo_vm_fault,
29918 .open = NULL,
29919 .close = NULL
29920 diff -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
29921 --- linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-19 00:06:34.000000000 -0400
29922 +++ linux-2.6.39.1/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-22 19:36:31.000000000 -0400
29923 @@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_priva
29924 * emitted. Then the fence is stale and signaled.
29925 */
29926
29927 - ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
29928 + ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
29929 > VMW_FENCE_WRAP);
29930
29931 return ret;
29932 @@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private
29933
29934 if (fifo_idle)
29935 down_read(&fifo_state->rwsem);
29936 - signal_seq = atomic_read(&dev_priv->fence_seq);
29937 + signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
29938 ret = 0;
29939
29940 for (;;) {
29941 diff -urNp linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c
29942 --- linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c 2011-05-19 00:06:34.000000000 -0400
29943 +++ linux-2.6.39.1/drivers/gpu/vga/vga_switcheroo.c 2011-05-22 19:36:31.000000000 -0400
29944 @@ -53,7 +53,7 @@ struct vgasr_priv {
29945 int registered_clients;
29946 struct vga_switcheroo_client clients[VGA_SWITCHEROO_MAX_CLIENTS];
29947
29948 - struct vga_switcheroo_handler *handler;
29949 + const struct vga_switcheroo_handler *handler;
29950 };
29951
29952 static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
29953 @@ -62,7 +62,7 @@ static void vga_switcheroo_debugfs_fini(
29954 /* only one switcheroo per system */
29955 static struct vgasr_priv vgasr_priv;
29956
29957 -int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
29958 +int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler)
29959 {
29960 mutex_lock(&vgasr_mutex);
29961 if (vgasr_priv.handler) {
29962 diff -urNp linux-2.6.39.1/drivers/hid/hid-core.c linux-2.6.39.1/drivers/hid/hid-core.c
29963 --- linux-2.6.39.1/drivers/hid/hid-core.c 2011-05-19 00:06:34.000000000 -0400
29964 +++ linux-2.6.39.1/drivers/hid/hid-core.c 2011-05-22 19:36:31.000000000 -0400
29965 @@ -1888,7 +1888,7 @@ static bool hid_ignore(struct hid_device
29966
29967 int hid_add_device(struct hid_device *hdev)
29968 {
29969 - static atomic_t id = ATOMIC_INIT(0);
29970 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29971 int ret;
29972
29973 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29974 @@ -1903,7 +1903,7 @@ int hid_add_device(struct hid_device *hd
29975 /* XXX hack, any other cleaner solution after the driver core
29976 * is converted to allow more than 20 bytes as the device name? */
29977 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29978 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29979 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29980
29981 hid_debug_register(hdev, dev_name(&hdev->dev));
29982 ret = device_add(&hdev->dev);
29983 diff -urNp linux-2.6.39.1/drivers/hid/hid-picolcd.c linux-2.6.39.1/drivers/hid/hid-picolcd.c
29984 --- linux-2.6.39.1/drivers/hid/hid-picolcd.c 2011-05-19 00:06:34.000000000 -0400
29985 +++ linux-2.6.39.1/drivers/hid/hid-picolcd.c 2011-05-22 19:36:31.000000000 -0400
29986 @@ -1037,7 +1037,7 @@ static int picolcd_check_lcd_fb(struct l
29987 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
29988 }
29989
29990 -static struct lcd_ops picolcd_lcdops = {
29991 +static const struct lcd_ops picolcd_lcdops = {
29992 .get_contrast = picolcd_get_contrast,
29993 .set_contrast = picolcd_set_contrast,
29994 .check_fb = picolcd_check_lcd_fb,
29995 diff -urNp linux-2.6.39.1/drivers/hid/usbhid/hiddev.c linux-2.6.39.1/drivers/hid/usbhid/hiddev.c
29996 --- linux-2.6.39.1/drivers/hid/usbhid/hiddev.c 2011-05-19 00:06:34.000000000 -0400
29997 +++ linux-2.6.39.1/drivers/hid/usbhid/hiddev.c 2011-05-22 19:36:31.000000000 -0400
29998 @@ -613,7 +613,7 @@ static long hiddev_ioctl(struct file *fi
29999 break;
30000
30001 case HIDIOCAPPLICATION:
30002 - if (arg < 0 || arg >= hid->maxapplication)
30003 + if (arg >= hid->maxapplication)
30004 break;
30005
30006 for (i = 0; i < hid->maxcollection; i++)
30007 diff -urNp linux-2.6.39.1/drivers/hwmon/ibmaem.c linux-2.6.39.1/drivers/hwmon/ibmaem.c
30008 --- linux-2.6.39.1/drivers/hwmon/ibmaem.c 2011-05-19 00:06:34.000000000 -0400
30009 +++ linux-2.6.39.1/drivers/hwmon/ibmaem.c 2011-05-22 19:36:31.000000000 -0400
30010 @@ -238,7 +238,7 @@ struct aem_read_sensor_resp {
30011 struct aem_driver_data {
30012 struct list_head aem_devices;
30013 struct ipmi_smi_watcher bmc_events;
30014 - struct ipmi_user_hndl ipmi_hndlrs;
30015 + const struct ipmi_user_hndl ipmi_hndlrs;
30016 };
30017
30018 static void aem_register_bmc(int iface, struct device *dev);
30019 diff -urNp linux-2.6.39.1/drivers/hwmon/ibmpex.c linux-2.6.39.1/drivers/hwmon/ibmpex.c
30020 --- linux-2.6.39.1/drivers/hwmon/ibmpex.c 2011-05-19 00:06:34.000000000 -0400
30021 +++ linux-2.6.39.1/drivers/hwmon/ibmpex.c 2011-05-22 19:36:31.000000000 -0400
30022 @@ -110,7 +110,7 @@ struct ibmpex_bmc_data {
30023 struct ibmpex_driver_data {
30024 struct list_head bmc_data;
30025 struct ipmi_smi_watcher bmc_events;
30026 - struct ipmi_user_hndl ipmi_hndlrs;
30027 + const struct ipmi_user_hndl ipmi_hndlrs;
30028 };
30029
30030 static struct ibmpex_driver_data driver_data = {
30031 diff -urNp linux-2.6.39.1/drivers/hwmon/sht15.c linux-2.6.39.1/drivers/hwmon/sht15.c
30032 --- linux-2.6.39.1/drivers/hwmon/sht15.c 2011-05-19 00:06:34.000000000 -0400
30033 +++ linux-2.6.39.1/drivers/hwmon/sht15.c 2011-05-22 19:36:31.000000000 -0400
30034 @@ -113,7 +113,7 @@ struct sht15_data {
30035 int supply_uV;
30036 int supply_uV_valid;
30037 struct work_struct update_supply_work;
30038 - atomic_t interrupt_handled;
30039 + atomic_unchecked_t interrupt_handled;
30040 };
30041
30042 /**
30043 @@ -246,13 +246,13 @@ static inline int sht15_update_single_va
30044 return ret;
30045
30046 gpio_direction_input(data->pdata->gpio_data);
30047 - atomic_set(&data->interrupt_handled, 0);
30048 + atomic_set_unchecked(&data->interrupt_handled, 0);
30049
30050 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30051 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30052 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30053 /* Only relevant if the interrupt hasn't occurred. */
30054 - if (!atomic_read(&data->interrupt_handled))
30055 + if (!atomic_read_unchecked(&data->interrupt_handled))
30056 schedule_work(&data->read_work);
30057 }
30058 ret = wait_event_timeout(data->wait_queue,
30059 @@ -399,7 +399,7 @@ static irqreturn_t sht15_interrupt_fired
30060 struct sht15_data *data = d;
30061 /* First disable the interrupt */
30062 disable_irq_nosync(irq);
30063 - atomic_inc(&data->interrupt_handled);
30064 + atomic_inc_unchecked(&data->interrupt_handled);
30065 /* Then schedule a reading work struct */
30066 if (data->flag != SHT15_READING_NOTHING)
30067 schedule_work(&data->read_work);
30068 @@ -450,11 +450,11 @@ static void sht15_bh_read_data(struct wo
30069 here as could have gone low in meantime so verify
30070 it hasn't!
30071 */
30072 - atomic_set(&data->interrupt_handled, 0);
30073 + atomic_set_unchecked(&data->interrupt_handled, 0);
30074 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30075 /* If still not occurred or another handler has been scheduled */
30076 if (gpio_get_value(data->pdata->gpio_data)
30077 - || atomic_read(&data->interrupt_handled))
30078 + || atomic_read_unchecked(&data->interrupt_handled))
30079 return;
30080 }
30081 /* Read the data back from the device */
30082 diff -urNp linux-2.6.39.1/drivers/hwmon/w83791d.c linux-2.6.39.1/drivers/hwmon/w83791d.c
30083 --- linux-2.6.39.1/drivers/hwmon/w83791d.c 2011-05-19 00:06:34.000000000 -0400
30084 +++ linux-2.6.39.1/drivers/hwmon/w83791d.c 2011-05-22 19:36:31.000000000 -0400
30085 @@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
30086 struct i2c_board_info *info);
30087 static int w83791d_remove(struct i2c_client *client);
30088
30089 -static int w83791d_read(struct i2c_client *client, u8 register);
30090 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30091 +static int w83791d_read(struct i2c_client *client, u8 reg);
30092 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30093 static struct w83791d_data *w83791d_update_device(struct device *dev);
30094
30095 #ifdef DEBUG
30096 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c
30097 --- linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c 2011-05-19 00:06:34.000000000 -0400
30098 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-at91.c 2011-05-22 19:36:31.000000000 -0400
30099 @@ -181,7 +181,7 @@ static u32 at91_func(struct i2c_adapter
30100 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30101 }
30102
30103 -static struct i2c_algorithm at91_algorithm = {
30104 +static const struct i2c_algorithm at91_algorithm = {
30105 .master_xfer = at91_xfer,
30106 .functionality = at91_func,
30107 };
30108 diff -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
30109 --- linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-19 00:06:34.000000000 -0400
30110 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-22 19:36:31.000000000 -0400
30111 @@ -599,7 +599,7 @@ static u32 bfin_twi_functionality(struct
30112 I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
30113 }
30114
30115 -static struct i2c_algorithm bfin_twi_algorithm = {
30116 +static const struct i2c_algorithm bfin_twi_algorithm = {
30117 .master_xfer = bfin_twi_master_xfer,
30118 .smbus_xfer = bfin_twi_smbus_xfer,
30119 .functionality = bfin_twi_functionality,
30120 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c
30121 --- linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c 2011-05-19 00:06:34.000000000 -0400
30122 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-davinci.c 2011-05-22 19:36:31.000000000 -0400
30123 @@ -630,7 +630,7 @@ static inline void i2c_davinci_cpufreq_d
30124 }
30125 #endif
30126
30127 -static struct i2c_algorithm i2c_davinci_algo = {
30128 +static const struct i2c_algorithm i2c_davinci_algo = {
30129 .master_xfer = i2c_davinci_xfer,
30130 .functionality = i2c_davinci_func,
30131 };
30132 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c
30133 --- linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c 2011-05-19 00:06:34.000000000 -0400
30134 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-designware.c 2011-05-22 19:36:31.000000000 -0400
30135 @@ -689,7 +689,7 @@ tx_aborted:
30136 return IRQ_HANDLED;
30137 }
30138
30139 -static struct i2c_algorithm i2c_dw_algo = {
30140 +static const struct i2c_algorithm i2c_dw_algo = {
30141 .master_xfer = i2c_dw_xfer,
30142 .functionality = i2c_dw_func,
30143 };
30144 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c
30145 --- linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c 2011-05-19 00:06:34.000000000 -0400
30146 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-eg20t.c 2011-05-22 19:36:31.000000000 -0400
30147 @@ -708,7 +708,7 @@ static u32 pch_i2c_func(struct i2c_adapt
30148 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
30149 }
30150
30151 -static struct i2c_algorithm pch_algorithm = {
30152 +static const struct i2c_algorithm pch_algorithm = {
30153 .master_xfer = pch_i2c_xfer,
30154 .functionality = pch_i2c_func
30155 };
30156 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c
30157 --- linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c 2011-05-19 00:06:34.000000000 -0400
30158 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-imx.c 2011-05-22 19:36:31.000000000 -0400
30159 @@ -457,7 +457,7 @@ static u32 i2c_imx_func(struct i2c_adapt
30160 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30161 }
30162
30163 -static struct i2c_algorithm i2c_imx_algo = {
30164 +static const struct i2c_algorithm i2c_imx_algo = {
30165 .master_xfer = i2c_imx_xfer,
30166 .functionality = i2c_imx_func,
30167 };
30168 diff -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
30169 --- linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c 2011-05-19 00:06:34.000000000 -0400
30170 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-intel-mid.c 2011-05-22 19:36:31.000000000 -0400
30171 @@ -917,7 +917,7 @@ err:
30172 return IRQ_HANDLED;
30173 }
30174
30175 -static struct i2c_algorithm intel_mid_i2c_algorithm = {
30176 +static const struct i2c_algorithm intel_mid_i2c_algorithm = {
30177 .master_xfer = intel_mid_i2c_xfer,
30178 .functionality = intel_mid_i2c_func,
30179 };
30180 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c
30181 --- linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c 2011-05-19 00:06:34.000000000 -0400
30182 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-nforce2.c 2011-05-22 19:36:31.000000000 -0400
30183 @@ -303,7 +303,7 @@ static u32 nforce2_func(struct i2c_adapt
30184 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
30185 }
30186
30187 -static struct i2c_algorithm smbus_algorithm = {
30188 +static const struct i2c_algorithm smbus_algorithm = {
30189 .smbus_xfer = nforce2_access,
30190 .functionality = nforce2_func,
30191 };
30192 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c
30193 --- linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
30194 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-22 19:36:31.000000000 -0400
30195 @@ -615,7 +615,7 @@ static u32 pmcmsptwi_i2c_func(struct i2c
30196
30197 /* -- Initialization -- */
30198
30199 -static struct i2c_algorithm pmcmsptwi_algo = {
30200 +static const struct i2c_algorithm pmcmsptwi_algo = {
30201 .master_xfer = pmcmsptwi_master_xfer,
30202 .functionality = pmcmsptwi_i2c_func,
30203 };
30204 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c
30205 --- linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c 2011-05-19 00:06:34.000000000 -0400
30206 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-pnx.c 2011-05-22 19:36:31.000000000 -0400
30207 @@ -535,7 +535,7 @@ static u32 i2c_pnx_func(struct i2c_adapt
30208 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30209 }
30210
30211 -static struct i2c_algorithm pnx_algorithm = {
30212 +static const struct i2c_algorithm pnx_algorithm = {
30213 .master_xfer = i2c_pnx_xfer,
30214 .functionality = i2c_pnx_func,
30215 };
30216 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c
30217 --- linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c 2011-05-19 00:06:34.000000000 -0400
30218 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-puv3.c 2011-05-22 19:36:31.000000000 -0400
30219 @@ -176,7 +176,7 @@ static u32 puv3_i2c_func(struct i2c_adap
30220 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30221 }
30222
30223 -static struct i2c_algorithm puv3_i2c_algorithm = {
30224 +static const struct i2c_algorithm puv3_i2c_algorithm = {
30225 .master_xfer = puv3_i2c_xfer,
30226 .functionality = puv3_i2c_func,
30227 };
30228 diff -urNp linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c
30229 --- linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c 2011-05-19 00:06:34.000000000 -0400
30230 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-s6000.c 2011-05-22 19:36:31.000000000 -0400
30231 @@ -243,7 +243,7 @@ static u32 s6i2c_functionality(struct i2
30232 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30233 }
30234
30235 -static struct i2c_algorithm s6i2c_algorithm = {
30236 +static const struct i2c_algorithm s6i2c_algorithm = {
30237 .master_xfer = s6i2c_master_xfer,
30238 .functionality = s6i2c_functionality,
30239 };
30240 diff -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
30241 --- linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-19 00:06:34.000000000 -0400
30242 +++ linux-2.6.39.1/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-22 19:36:31.000000000 -0400
30243 @@ -529,7 +529,7 @@ static u32 sh_mobile_i2c_func(struct i2c
30244 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30245 }
30246
30247 -static struct i2c_algorithm sh_mobile_i2c_algorithm = {
30248 +static const struct i2c_algorithm sh_mobile_i2c_algorithm = {
30249 .functionality = sh_mobile_i2c_func,
30250 .master_xfer = sh_mobile_i2c_xfer,
30251 };
30252 diff -urNp linux-2.6.39.1/drivers/ide/ide-cd.c linux-2.6.39.1/drivers/ide/ide-cd.c
30253 --- linux-2.6.39.1/drivers/ide/ide-cd.c 2011-06-03 00:04:14.000000000 -0400
30254 +++ linux-2.6.39.1/drivers/ide/ide-cd.c 2011-06-03 00:32:05.000000000 -0400
30255 @@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_
30256 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30257 if ((unsigned long)buf & alignment
30258 || blk_rq_bytes(rq) & q->dma_pad_mask
30259 - || object_is_on_stack(buf))
30260 + || object_starts_on_stack(buf))
30261 drive->dma = 0;
30262 }
30263 }
30264 diff -urNp linux-2.6.39.1/drivers/ide/ide-floppy.c linux-2.6.39.1/drivers/ide/ide-floppy.c
30265 --- linux-2.6.39.1/drivers/ide/ide-floppy.c 2011-05-19 00:06:34.000000000 -0400
30266 +++ linux-2.6.39.1/drivers/ide/ide-floppy.c 2011-05-22 19:36:31.000000000 -0400
30267 @@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_d
30268 u8 pc_buf[256], header_len, desc_cnt;
30269 int i, rc = 1, blocks, length;
30270
30271 + pax_track_stack();
30272 +
30273 ide_debug_log(IDE_DBG_FUNC, "enter");
30274
30275 drive->bios_cyl = 0;
30276 diff -urNp linux-2.6.39.1/drivers/ide/it821x.c linux-2.6.39.1/drivers/ide/it821x.c
30277 --- linux-2.6.39.1/drivers/ide/it821x.c 2011-05-19 00:06:34.000000000 -0400
30278 +++ linux-2.6.39.1/drivers/ide/it821x.c 2011-05-22 19:36:31.000000000 -0400
30279 @@ -508,7 +508,7 @@ static void it821x_quirkproc(ide_drive_t
30280
30281 }
30282
30283 -static struct ide_dma_ops it821x_pass_through_dma_ops = {
30284 +static const struct ide_dma_ops it821x_pass_through_dma_ops = {
30285 .dma_host_set = ide_dma_host_set,
30286 .dma_setup = ide_dma_setup,
30287 .dma_start = it821x_dma_start,
30288 diff -urNp linux-2.6.39.1/drivers/ide/setup-pci.c linux-2.6.39.1/drivers/ide/setup-pci.c
30289 --- linux-2.6.39.1/drivers/ide/setup-pci.c 2011-05-19 00:06:34.000000000 -0400
30290 +++ linux-2.6.39.1/drivers/ide/setup-pci.c 2011-05-22 19:36:31.000000000 -0400
30291 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30292 int ret, i, n_ports = dev2 ? 4 : 2;
30293 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30294
30295 + pax_track_stack();
30296 +
30297 for (i = 0; i < n_ports / 2; i++) {
30298 ret = ide_setup_pci_controller(pdev[i], d, !i);
30299 if (ret < 0)
30300 diff -urNp linux-2.6.39.1/drivers/ide/trm290.c linux-2.6.39.1/drivers/ide/trm290.c
30301 --- linux-2.6.39.1/drivers/ide/trm290.c 2011-05-19 00:06:34.000000000 -0400
30302 +++ linux-2.6.39.1/drivers/ide/trm290.c 2011-05-22 19:36:31.000000000 -0400
30303 @@ -314,7 +314,7 @@ static const struct ide_tp_ops trm290_tp
30304 .output_data = ide_output_data,
30305 };
30306
30307 -static struct ide_dma_ops trm290_dma_ops = {
30308 +static const struct ide_dma_ops trm290_dma_ops = {
30309 .dma_host_set = trm290_dma_host_set,
30310 .dma_setup = trm290_dma_setup,
30311 .dma_start = trm290_dma_start,
30312 diff -urNp linux-2.6.39.1/drivers/infiniband/core/cm.c linux-2.6.39.1/drivers/infiniband/core/cm.c
30313 --- linux-2.6.39.1/drivers/infiniband/core/cm.c 2011-05-19 00:06:34.000000000 -0400
30314 +++ linux-2.6.39.1/drivers/infiniband/core/cm.c 2011-05-22 19:36:31.000000000 -0400
30315 @@ -113,7 +113,7 @@ static char const counter_group_names[CM
30316
30317 struct cm_counter_group {
30318 struct kobject obj;
30319 - atomic_long_t counter[CM_ATTR_COUNT];
30320 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30321 };
30322
30323 struct cm_counter_attribute {
30324 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
30325 struct ib_mad_send_buf *msg = NULL;
30326 int ret;
30327
30328 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30329 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30330 counter[CM_REQ_COUNTER]);
30331
30332 /* Quick state check to discard duplicate REQs. */
30333 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
30334 if (!cm_id_priv)
30335 return;
30336
30337 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30338 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30339 counter[CM_REP_COUNTER]);
30340 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30341 if (ret)
30342 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
30343 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30344 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30345 spin_unlock_irq(&cm_id_priv->lock);
30346 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30347 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30348 counter[CM_RTU_COUNTER]);
30349 goto out;
30350 }
30351 @@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_wor
30352 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30353 dreq_msg->local_comm_id);
30354 if (!cm_id_priv) {
30355 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30356 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30357 counter[CM_DREQ_COUNTER]);
30358 cm_issue_drep(work->port, work->mad_recv_wc);
30359 return -EINVAL;
30360 @@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_wor
30361 case IB_CM_MRA_REP_RCVD:
30362 break;
30363 case IB_CM_TIMEWAIT:
30364 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30365 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30366 counter[CM_DREQ_COUNTER]);
30367 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30368 goto unlock;
30369 @@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_wor
30370 cm_free_msg(msg);
30371 goto deref;
30372 case IB_CM_DREQ_RCVD:
30373 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30374 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30375 counter[CM_DREQ_COUNTER]);
30376 goto unlock;
30377 default:
30378 @@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work
30379 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30380 cm_id_priv->msg, timeout)) {
30381 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30382 - atomic_long_inc(&work->port->
30383 + atomic_long_inc_unchecked(&work->port->
30384 counter_group[CM_RECV_DUPLICATES].
30385 counter[CM_MRA_COUNTER]);
30386 goto out;
30387 @@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work
30388 break;
30389 case IB_CM_MRA_REQ_RCVD:
30390 case IB_CM_MRA_REP_RCVD:
30391 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30392 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30393 counter[CM_MRA_COUNTER]);
30394 /* fall through */
30395 default:
30396 @@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work
30397 case IB_CM_LAP_IDLE:
30398 break;
30399 case IB_CM_MRA_LAP_SENT:
30400 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30401 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30402 counter[CM_LAP_COUNTER]);
30403 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30404 goto unlock;
30405 @@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work
30406 cm_free_msg(msg);
30407 goto deref;
30408 case IB_CM_LAP_RCVD:
30409 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30410 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30411 counter[CM_LAP_COUNTER]);
30412 goto unlock;
30413 default:
30414 @@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm
30415 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30416 if (cur_cm_id_priv) {
30417 spin_unlock_irq(&cm.lock);
30418 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30419 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30420 counter[CM_SIDR_REQ_COUNTER]);
30421 goto out; /* Duplicate message. */
30422 }
30423 @@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_ma
30424 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30425 msg->retries = 1;
30426
30427 - atomic_long_add(1 + msg->retries,
30428 + atomic_long_add_unchecked(1 + msg->retries,
30429 &port->counter_group[CM_XMIT].counter[attr_index]);
30430 if (msg->retries)
30431 - atomic_long_add(msg->retries,
30432 + atomic_long_add_unchecked(msg->retries,
30433 &port->counter_group[CM_XMIT_RETRIES].
30434 counter[attr_index]);
30435
30436 @@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_ma
30437 }
30438
30439 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30440 - atomic_long_inc(&port->counter_group[CM_RECV].
30441 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30442 counter[attr_id - CM_ATTR_ID_OFFSET]);
30443
30444 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30445 @@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct ko
30446 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30447
30448 return sprintf(buf, "%ld\n",
30449 - atomic_long_read(&group->counter[cm_attr->index]));
30450 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30451 }
30452
30453 static const struct sysfs_ops cm_counter_ops = {
30454 diff -urNp linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c
30455 --- linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c 2011-05-19 00:06:34.000000000 -0400
30456 +++ linux-2.6.39.1/drivers/infiniband/core/fmr_pool.c 2011-05-22 19:36:31.000000000 -0400
30457 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
30458
30459 struct task_struct *thread;
30460
30461 - atomic_t req_ser;
30462 - atomic_t flush_ser;
30463 + atomic_unchecked_t req_ser;
30464 + atomic_unchecked_t flush_ser;
30465
30466 wait_queue_head_t force_wait;
30467 };
30468 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30469 struct ib_fmr_pool *pool = pool_ptr;
30470
30471 do {
30472 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30473 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30474 ib_fmr_batch_release(pool);
30475
30476 - atomic_inc(&pool->flush_ser);
30477 + atomic_inc_unchecked(&pool->flush_ser);
30478 wake_up_interruptible(&pool->force_wait);
30479
30480 if (pool->flush_function)
30481 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30482 }
30483
30484 set_current_state(TASK_INTERRUPTIBLE);
30485 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30486 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30487 !kthread_should_stop())
30488 schedule();
30489 __set_current_state(TASK_RUNNING);
30490 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30491 pool->dirty_watermark = params->dirty_watermark;
30492 pool->dirty_len = 0;
30493 spin_lock_init(&pool->pool_lock);
30494 - atomic_set(&pool->req_ser, 0);
30495 - atomic_set(&pool->flush_ser, 0);
30496 + atomic_set_unchecked(&pool->req_ser, 0);
30497 + atomic_set_unchecked(&pool->flush_ser, 0);
30498 init_waitqueue_head(&pool->force_wait);
30499
30500 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30501 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30502 }
30503 spin_unlock_irq(&pool->pool_lock);
30504
30505 - serial = atomic_inc_return(&pool->req_ser);
30506 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30507 wake_up_process(pool->thread);
30508
30509 if (wait_event_interruptible(pool->force_wait,
30510 - atomic_read(&pool->flush_ser) - serial >= 0))
30511 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30512 return -EINTR;
30513
30514 return 0;
30515 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30516 } else {
30517 list_add_tail(&fmr->list, &pool->dirty_list);
30518 if (++pool->dirty_len >= pool->dirty_watermark) {
30519 - atomic_inc(&pool->req_ser);
30520 + atomic_inc_unchecked(&pool->req_ser);
30521 wake_up_process(pool->thread);
30522 }
30523 }
30524 diff -urNp linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c
30525 --- linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c 2011-05-19 00:06:34.000000000 -0400
30526 +++ linux-2.6.39.1/drivers/infiniband/hw/cxgb4/mem.c 2011-05-22 19:36:31.000000000 -0400
30527 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_r
30528 int err;
30529 struct fw_ri_tpte tpt;
30530 u32 stag_idx;
30531 - static atomic_t key;
30532 + static atomic_unchecked_t key;
30533
30534 if (c4iw_fatal_error(rdev))
30535 return -EIO;
30536 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_r
30537 &rdev->resource.tpt_fifo_lock);
30538 if (!stag_idx)
30539 return -ENOMEM;
30540 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30541 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30542 }
30543 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30544 __func__, stag_state, type, pdid, stag_idx);
30545 diff -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
30546 --- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-19 00:06:34.000000000 -0400
30547 +++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-22 19:36:31.000000000 -0400
30548 @@ -175,7 +175,7 @@ static void ipath_dma_free_coherent(stru
30549 free_pages((unsigned long) cpu_addr, get_order(size));
30550 }
30551
30552 -struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30553 +const struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30554 ipath_mapping_error,
30555 ipath_dma_map_single,
30556 ipath_dma_unmap_single,
30557 diff -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
30558 --- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-19 00:06:34.000000000 -0400
30559 +++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-22 19:36:31.000000000 -0400
30560 @@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(stru
30561 struct infinipath_counters counters;
30562 struct ipath_devdata *dd;
30563
30564 + pax_track_stack();
30565 +
30566 dd = file->f_path.dentry->d_inode->i_private;
30567 dd->ipath_f_read_counters(dd, &counters);
30568
30569 diff -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
30570 --- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-19 00:06:34.000000000 -0400
30571 +++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-22 19:36:31.000000000 -0400
30572 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30573 struct ib_atomic_eth *ateth;
30574 struct ipath_ack_entry *e;
30575 u64 vaddr;
30576 - atomic64_t *maddr;
30577 + atomic64_unchecked_t *maddr;
30578 u64 sdata;
30579 u32 rkey;
30580 u8 next;
30581 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30582 IB_ACCESS_REMOTE_ATOMIC)))
30583 goto nack_acc_unlck;
30584 /* Perform atomic OP and save result. */
30585 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30586 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30587 sdata = be64_to_cpu(ateth->swap_data);
30588 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30589 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30590 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30591 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30592 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30593 be64_to_cpu(ateth->compare_data),
30594 sdata);
30595 diff -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
30596 --- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-19 00:06:34.000000000 -0400
30597 +++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-22 19:36:31.000000000 -0400
30598 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ip
30599 unsigned long flags;
30600 struct ib_wc wc;
30601 u64 sdata;
30602 - atomic64_t *maddr;
30603 + atomic64_unchecked_t *maddr;
30604 enum ib_wc_status send_status;
30605
30606 /*
30607 @@ -382,11 +382,11 @@ again:
30608 IB_ACCESS_REMOTE_ATOMIC)))
30609 goto acc_err;
30610 /* Perform atomic OP and save result. */
30611 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30612 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30613 sdata = wqe->wr.wr.atomic.compare_add;
30614 *(u64 *) sqp->s_sge.sge.vaddr =
30615 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30616 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30617 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30618 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30619 sdata, wqe->wr.wr.atomic.swap);
30620 goto send_comp;
30621 diff -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
30622 --- linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-19 00:06:34.000000000 -0400
30623 +++ linux-2.6.39.1/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-22 19:36:31.000000000 -0400
30624 @@ -931,6 +931,6 @@ extern unsigned int ib_ipath_max_srq_wrs
30625
30626 extern const u32 ib_ipath_rnr_table[];
30627
30628 -extern struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30629 +extern const struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30630
30631 #endif /* IPATH_VERBS_H */
30632 diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c
30633 --- linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c 2011-05-19 00:06:34.000000000 -0400
30634 +++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes.c 2011-05-22 19:36:31.000000000 -0400
30635 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
30636 LIST_HEAD(nes_adapter_list);
30637 static LIST_HEAD(nes_dev_list);
30638
30639 -atomic_t qps_destroyed;
30640 +atomic_unchecked_t qps_destroyed;
30641
30642 static unsigned int ee_flsh_adapter;
30643 static unsigned int sysfs_nonidx_addr;
30644 @@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(str
30645 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30646 struct nes_adapter *nesadapter = nesdev->nesadapter;
30647
30648 - atomic_inc(&qps_destroyed);
30649 + atomic_inc_unchecked(&qps_destroyed);
30650
30651 /* Free the control structures */
30652
30653 diff -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
30654 --- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c 2011-05-19 00:06:34.000000000 -0400
30655 +++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_cm.c 2011-05-22 19:36:31.000000000 -0400
30656 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30657 u32 cm_packets_retrans;
30658 u32 cm_packets_created;
30659 u32 cm_packets_received;
30660 -atomic_t cm_listens_created;
30661 -atomic_t cm_listens_destroyed;
30662 +atomic_unchecked_t cm_listens_created;
30663 +atomic_unchecked_t cm_listens_destroyed;
30664 u32 cm_backlog_drops;
30665 -atomic_t cm_loopbacks;
30666 -atomic_t cm_nodes_created;
30667 -atomic_t cm_nodes_destroyed;
30668 -atomic_t cm_accel_dropped_pkts;
30669 -atomic_t cm_resets_recvd;
30670 +atomic_unchecked_t cm_loopbacks;
30671 +atomic_unchecked_t cm_nodes_created;
30672 +atomic_unchecked_t cm_nodes_destroyed;
30673 +atomic_unchecked_t cm_accel_dropped_pkts;
30674 +atomic_unchecked_t cm_resets_recvd;
30675
30676 static inline int mini_cm_accelerated(struct nes_cm_core *,
30677 struct nes_cm_node *);
30678 @@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30679
30680 static struct nes_cm_core *g_cm_core;
30681
30682 -atomic_t cm_connects;
30683 -atomic_t cm_accepts;
30684 -atomic_t cm_disconnects;
30685 -atomic_t cm_closes;
30686 -atomic_t cm_connecteds;
30687 -atomic_t cm_connect_reqs;
30688 -atomic_t cm_rejects;
30689 +atomic_unchecked_t cm_connects;
30690 +atomic_unchecked_t cm_accepts;
30691 +atomic_unchecked_t cm_disconnects;
30692 +atomic_unchecked_t cm_closes;
30693 +atomic_unchecked_t cm_connecteds;
30694 +atomic_unchecked_t cm_connect_reqs;
30695 +atomic_unchecked_t cm_rejects;
30696
30697
30698 /**
30699 @@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(str
30700 kfree(listener);
30701 listener = NULL;
30702 ret = 0;
30703 - atomic_inc(&cm_listens_destroyed);
30704 + atomic_inc_unchecked(&cm_listens_destroyed);
30705 } else {
30706 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30707 }
30708 @@ -1240,7 +1240,7 @@ static struct nes_cm_node *make_cm_node(
30709 cm_node->rem_mac);
30710
30711 add_hte_node(cm_core, cm_node);
30712 - atomic_inc(&cm_nodes_created);
30713 + atomic_inc_unchecked(&cm_nodes_created);
30714
30715 return cm_node;
30716 }
30717 @@ -1298,7 +1298,7 @@ static int rem_ref_cm_node(struct nes_cm
30718 }
30719
30720 atomic_dec(&cm_core->node_cnt);
30721 - atomic_inc(&cm_nodes_destroyed);
30722 + atomic_inc_unchecked(&cm_nodes_destroyed);
30723 nesqp = cm_node->nesqp;
30724 if (nesqp) {
30725 nesqp->cm_node = NULL;
30726 @@ -1365,7 +1365,7 @@ static int process_options(struct nes_cm
30727
30728 static void drop_packet(struct sk_buff *skb)
30729 {
30730 - atomic_inc(&cm_accel_dropped_pkts);
30731 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30732 dev_kfree_skb_any(skb);
30733 }
30734
30735 @@ -1428,7 +1428,7 @@ static void handle_rst_pkt(struct nes_cm
30736 {
30737
30738 int reset = 0; /* whether to send reset in case of err.. */
30739 - atomic_inc(&cm_resets_recvd);
30740 + atomic_inc_unchecked(&cm_resets_recvd);
30741 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30742 " refcnt=%d\n", cm_node, cm_node->state,
30743 atomic_read(&cm_node->ref_count));
30744 @@ -2057,7 +2057,7 @@ static struct nes_cm_node *mini_cm_conne
30745 rem_ref_cm_node(cm_node->cm_core, cm_node);
30746 return NULL;
30747 }
30748 - atomic_inc(&cm_loopbacks);
30749 + atomic_inc_unchecked(&cm_loopbacks);
30750 loopbackremotenode->loopbackpartner = cm_node;
30751 loopbackremotenode->tcp_cntxt.rcv_wscale =
30752 NES_CM_DEFAULT_RCV_WND_SCALE;
30753 @@ -2332,7 +2332,7 @@ static int mini_cm_recv_pkt(struct nes_c
30754 add_ref_cm_node(cm_node);
30755 } else if (cm_node->state == NES_CM_STATE_TSA) {
30756 rem_ref_cm_node(cm_core, cm_node);
30757 - atomic_inc(&cm_accel_dropped_pkts);
30758 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30759 dev_kfree_skb_any(skb);
30760 break;
30761 }
30762 @@ -2638,7 +2638,7 @@ static int nes_cm_disconn_true(struct ne
30763
30764 if ((cm_id) && (cm_id->event_handler)) {
30765 if (issue_disconn) {
30766 - atomic_inc(&cm_disconnects);
30767 + atomic_inc_unchecked(&cm_disconnects);
30768 cm_event.event = IW_CM_EVENT_DISCONNECT;
30769 cm_event.status = disconn_status;
30770 cm_event.local_addr = cm_id->local_addr;
30771 @@ -2660,7 +2660,7 @@ static int nes_cm_disconn_true(struct ne
30772 }
30773
30774 if (issue_close) {
30775 - atomic_inc(&cm_closes);
30776 + atomic_inc_unchecked(&cm_closes);
30777 nes_disconnect(nesqp, 1);
30778
30779 cm_id->provider_data = nesqp;
30780 @@ -2791,7 +2791,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
30781
30782 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30783 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30784 - atomic_inc(&cm_accepts);
30785 + atomic_inc_unchecked(&cm_accepts);
30786
30787 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30788 netdev_refcnt_read(nesvnic->netdev));
30789 @@ -3001,7 +3001,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
30790
30791 struct nes_cm_core *cm_core;
30792
30793 - atomic_inc(&cm_rejects);
30794 + atomic_inc_unchecked(&cm_rejects);
30795 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30796 loopback = cm_node->loopbackpartner;
30797 cm_core = cm_node->cm_core;
30798 @@ -3067,7 +3067,7 @@ int nes_connect(struct iw_cm_id *cm_id,
30799 ntohl(cm_id->local_addr.sin_addr.s_addr),
30800 ntohs(cm_id->local_addr.sin_port));
30801
30802 - atomic_inc(&cm_connects);
30803 + atomic_inc_unchecked(&cm_connects);
30804 nesqp->active_conn = 1;
30805
30806 /* cache the cm_id in the qp */
30807 @@ -3173,7 +3173,7 @@ int nes_create_listen(struct iw_cm_id *c
30808 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30809 return err;
30810 }
30811 - atomic_inc(&cm_listens_created);
30812 + atomic_inc_unchecked(&cm_listens_created);
30813 }
30814
30815 cm_id->add_ref(cm_id);
30816 @@ -3278,7 +3278,7 @@ static void cm_event_connected(struct ne
30817 if (nesqp->destroyed) {
30818 return;
30819 }
30820 - atomic_inc(&cm_connecteds);
30821 + atomic_inc_unchecked(&cm_connecteds);
30822 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30823 " local port 0x%04X. jiffies = %lu.\n",
30824 nesqp->hwqp.qp_id,
30825 @@ -3493,7 +3493,7 @@ static void cm_event_reset(struct nes_cm
30826
30827 cm_id->add_ref(cm_id);
30828 ret = cm_id->event_handler(cm_id, &cm_event);
30829 - atomic_inc(&cm_closes);
30830 + atomic_inc_unchecked(&cm_closes);
30831 cm_event.event = IW_CM_EVENT_CLOSE;
30832 cm_event.status = IW_CM_EVENT_STATUS_OK;
30833 cm_event.provider_data = cm_id->provider_data;
30834 @@ -3529,7 +3529,7 @@ static void cm_event_mpa_req(struct nes_
30835 return;
30836 cm_id = cm_node->cm_id;
30837
30838 - atomic_inc(&cm_connect_reqs);
30839 + atomic_inc_unchecked(&cm_connect_reqs);
30840 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30841 cm_node, cm_id, jiffies);
30842
30843 @@ -3567,7 +3567,7 @@ static void cm_event_mpa_reject(struct n
30844 return;
30845 cm_id = cm_node->cm_id;
30846
30847 - atomic_inc(&cm_connect_reqs);
30848 + atomic_inc_unchecked(&cm_connect_reqs);
30849 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30850 cm_node, cm_id, jiffies);
30851
30852 diff -urNp linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h
30853 --- linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h 2011-05-19 00:06:34.000000000 -0400
30854 +++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes.h 2011-05-22 19:36:31.000000000 -0400
30855 @@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30856 extern unsigned int wqm_quanta;
30857 extern struct list_head nes_adapter_list;
30858
30859 -extern atomic_t cm_connects;
30860 -extern atomic_t cm_accepts;
30861 -extern atomic_t cm_disconnects;
30862 -extern atomic_t cm_closes;
30863 -extern atomic_t cm_connecteds;
30864 -extern atomic_t cm_connect_reqs;
30865 -extern atomic_t cm_rejects;
30866 -extern atomic_t mod_qp_timouts;
30867 -extern atomic_t qps_created;
30868 -extern atomic_t qps_destroyed;
30869 -extern atomic_t sw_qps_destroyed;
30870 +extern atomic_unchecked_t cm_connects;
30871 +extern atomic_unchecked_t cm_accepts;
30872 +extern atomic_unchecked_t cm_disconnects;
30873 +extern atomic_unchecked_t cm_closes;
30874 +extern atomic_unchecked_t cm_connecteds;
30875 +extern atomic_unchecked_t cm_connect_reqs;
30876 +extern atomic_unchecked_t cm_rejects;
30877 +extern atomic_unchecked_t mod_qp_timouts;
30878 +extern atomic_unchecked_t qps_created;
30879 +extern atomic_unchecked_t qps_destroyed;
30880 +extern atomic_unchecked_t sw_qps_destroyed;
30881 extern u32 mh_detected;
30882 extern u32 mh_pauses_sent;
30883 extern u32 cm_packets_sent;
30884 @@ -194,14 +194,14 @@ extern u32 cm_packets_created;
30885 extern u32 cm_packets_received;
30886 extern u32 cm_packets_dropped;
30887 extern u32 cm_packets_retrans;
30888 -extern atomic_t cm_listens_created;
30889 -extern atomic_t cm_listens_destroyed;
30890 +extern atomic_unchecked_t cm_listens_created;
30891 +extern atomic_unchecked_t cm_listens_destroyed;
30892 extern u32 cm_backlog_drops;
30893 -extern atomic_t cm_loopbacks;
30894 -extern atomic_t cm_nodes_created;
30895 -extern atomic_t cm_nodes_destroyed;
30896 -extern atomic_t cm_accel_dropped_pkts;
30897 -extern atomic_t cm_resets_recvd;
30898 +extern atomic_unchecked_t cm_loopbacks;
30899 +extern atomic_unchecked_t cm_nodes_created;
30900 +extern atomic_unchecked_t cm_nodes_destroyed;
30901 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30902 +extern atomic_unchecked_t cm_resets_recvd;
30903
30904 extern u32 int_mod_timer_init;
30905 extern u32 int_mod_cq_depth_256;
30906 diff -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
30907 --- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c 2011-05-19 00:06:34.000000000 -0400
30908 +++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_nic.c 2011-05-22 19:36:31.000000000 -0400
30909 @@ -1302,31 +1302,31 @@ static void nes_netdev_get_ethtool_stats
30910 target_stat_values[++index] = mh_detected;
30911 target_stat_values[++index] = mh_pauses_sent;
30912 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30913 - target_stat_values[++index] = atomic_read(&cm_connects);
30914 - target_stat_values[++index] = atomic_read(&cm_accepts);
30915 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30916 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30917 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30918 - target_stat_values[++index] = atomic_read(&cm_rejects);
30919 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30920 - target_stat_values[++index] = atomic_read(&qps_created);
30921 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30922 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30923 - target_stat_values[++index] = atomic_read(&cm_closes);
30924 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30925 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30926 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30927 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30928 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30929 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30930 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30931 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30932 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30933 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30934 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30935 target_stat_values[++index] = cm_packets_sent;
30936 target_stat_values[++index] = cm_packets_bounced;
30937 target_stat_values[++index] = cm_packets_created;
30938 target_stat_values[++index] = cm_packets_received;
30939 target_stat_values[++index] = cm_packets_dropped;
30940 target_stat_values[++index] = cm_packets_retrans;
30941 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30942 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30943 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30944 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30945 target_stat_values[++index] = cm_backlog_drops;
30946 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30947 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30948 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30949 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30950 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30951 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30952 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30953 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30954 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30955 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30956 target_stat_values[++index] = nesadapter->free_4kpbl;
30957 target_stat_values[++index] = nesadapter->free_256pbl;
30958 target_stat_values[++index] = int_mod_timer_init;
30959 diff -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
30960 --- linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-19 00:06:34.000000000 -0400
30961 +++ linux-2.6.39.1/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-22 19:36:31.000000000 -0400
30962 @@ -46,9 +46,9 @@
30963
30964 #include <rdma/ib_umem.h>
30965
30966 -atomic_t mod_qp_timouts;
30967 -atomic_t qps_created;
30968 -atomic_t sw_qps_destroyed;
30969 +atomic_unchecked_t mod_qp_timouts;
30970 +atomic_unchecked_t qps_created;
30971 +atomic_unchecked_t sw_qps_destroyed;
30972
30973 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30974
30975 @@ -1141,7 +1141,7 @@ static struct ib_qp *nes_create_qp(struc
30976 if (init_attr->create_flags)
30977 return ERR_PTR(-EINVAL);
30978
30979 - atomic_inc(&qps_created);
30980 + atomic_inc_unchecked(&qps_created);
30981 switch (init_attr->qp_type) {
30982 case IB_QPT_RC:
30983 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30984 @@ -1470,7 +1470,7 @@ static int nes_destroy_qp(struct ib_qp *
30985 struct iw_cm_event cm_event;
30986 int ret;
30987
30988 - atomic_inc(&sw_qps_destroyed);
30989 + atomic_inc_unchecked(&sw_qps_destroyed);
30990 nesqp->destroyed = 1;
30991
30992 /* Blow away the connection if it exists. */
30993 diff -urNp linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h
30994 --- linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h 2011-05-19 00:06:34.000000000 -0400
30995 +++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib.h 2011-05-22 19:36:31.000000000 -0400
30996 @@ -51,6 +51,7 @@
30997 #include <linux/completion.h>
30998 #include <linux/kref.h>
30999 #include <linux/sched.h>
31000 +#include <linux/slab.h>
31001
31002 #include "qib_common.h"
31003 #include "qib_verbs.h"
31004 @@ -87,7 +88,7 @@ struct qlogic_ib_stats {
31005 };
31006
31007 extern struct qlogic_ib_stats qib_stats;
31008 -extern struct pci_error_handlers qib_pci_err_handler;
31009 +extern const struct pci_error_handlers qib_pci_err_handler;
31010 extern struct pci_driver qib_driver;
31011
31012 #define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
31013 diff -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
31014 --- linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-19 00:06:34.000000000 -0400
31015 +++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-22 19:36:31.000000000 -0400
31016 @@ -75,7 +75,7 @@ static void qib_vma_close(struct vm_area
31017 kref_put(&ip->ref, qib_release_mmap_info);
31018 }
31019
31020 -static struct vm_operations_struct qib_vm_ops = {
31021 +static const struct vm_operations_struct qib_vm_ops = {
31022 .open = qib_vma_open,
31023 .close = qib_vma_close,
31024 };
31025 diff -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
31026 --- linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-19 00:06:34.000000000 -0400
31027 +++ linux-2.6.39.1/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-22 19:36:31.000000000 -0400
31028 @@ -735,7 +735,7 @@ qib_pci_resume(struct pci_dev *pdev)
31029 qib_init(dd, 1); /* same as re-init after reset */
31030 }
31031
31032 -struct pci_error_handlers qib_pci_err_handler = {
31033 +const struct pci_error_handlers qib_pci_err_handler = {
31034 .error_detected = qib_pci_error_detected,
31035 .mmio_enabled = qib_pci_mmio_enabled,
31036 .link_reset = qib_pci_link_reset,
31037 diff -urNp linux-2.6.39.1/drivers/input/gameport/gameport.c linux-2.6.39.1/drivers/input/gameport/gameport.c
31038 --- linux-2.6.39.1/drivers/input/gameport/gameport.c 2011-05-19 00:06:34.000000000 -0400
31039 +++ linux-2.6.39.1/drivers/input/gameport/gameport.c 2011-05-22 19:36:31.000000000 -0400
31040 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31041 */
31042 static void gameport_init_port(struct gameport *gameport)
31043 {
31044 - static atomic_t gameport_no = ATOMIC_INIT(0);
31045 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31046
31047 __module_get(THIS_MODULE);
31048
31049 mutex_init(&gameport->drv_mutex);
31050 device_initialize(&gameport->dev);
31051 dev_set_name(&gameport->dev, "gameport%lu",
31052 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
31053 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31054 gameport->dev.bus = &gameport_bus;
31055 gameport->dev.release = gameport_release_port;
31056 if (gameport->parent)
31057 diff -urNp linux-2.6.39.1/drivers/input/input.c linux-2.6.39.1/drivers/input/input.c
31058 --- linux-2.6.39.1/drivers/input/input.c 2011-05-19 00:06:34.000000000 -0400
31059 +++ linux-2.6.39.1/drivers/input/input.c 2011-05-22 19:36:31.000000000 -0400
31060 @@ -1815,7 +1815,7 @@ static void input_cleanse_bitmasks(struc
31061 */
31062 int input_register_device(struct input_dev *dev)
31063 {
31064 - static atomic_t input_no = ATOMIC_INIT(0);
31065 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31066 struct input_handler *handler;
31067 const char *path;
31068 int error;
31069 @@ -1852,7 +1852,7 @@ int input_register_device(struct input_d
31070 dev->setkeycode = input_default_setkeycode;
31071
31072 dev_set_name(&dev->dev, "input%ld",
31073 - (unsigned long) atomic_inc_return(&input_no) - 1);
31074 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31075
31076 error = device_add(&dev->dev);
31077 if (error)
31078 diff -urNp linux-2.6.39.1/drivers/input/joystick/sidewinder.c linux-2.6.39.1/drivers/input/joystick/sidewinder.c
31079 --- linux-2.6.39.1/drivers/input/joystick/sidewinder.c 2011-05-19 00:06:34.000000000 -0400
31080 +++ linux-2.6.39.1/drivers/input/joystick/sidewinder.c 2011-05-22 19:36:31.000000000 -0400
31081 @@ -30,6 +30,7 @@
31082 #include <linux/kernel.h>
31083 #include <linux/module.h>
31084 #include <linux/slab.h>
31085 +#include <linux/sched.h>
31086 #include <linux/init.h>
31087 #include <linux/input.h>
31088 #include <linux/gameport.h>
31089 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31090 unsigned char buf[SW_LENGTH];
31091 int i;
31092
31093 + pax_track_stack();
31094 +
31095 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31096
31097 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31098 diff -urNp linux-2.6.39.1/drivers/input/joystick/xpad.c linux-2.6.39.1/drivers/input/joystick/xpad.c
31099 --- linux-2.6.39.1/drivers/input/joystick/xpad.c 2011-05-19 00:06:34.000000000 -0400
31100 +++ linux-2.6.39.1/drivers/input/joystick/xpad.c 2011-05-22 19:36:31.000000000 -0400
31101 @@ -689,7 +689,7 @@ static void xpad_led_set(struct led_clas
31102
31103 static int xpad_led_probe(struct usb_xpad *xpad)
31104 {
31105 - static atomic_t led_seq = ATOMIC_INIT(0);
31106 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31107 long led_no;
31108 struct xpad_led *led;
31109 struct led_classdev *led_cdev;
31110 @@ -702,7 +702,7 @@ static int xpad_led_probe(struct usb_xpa
31111 if (!led)
31112 return -ENOMEM;
31113
31114 - led_no = (long)atomic_inc_return(&led_seq) - 1;
31115 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31116
31117 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31118 led->xpad = xpad;
31119 diff -urNp linux-2.6.39.1/drivers/input/mousedev.c linux-2.6.39.1/drivers/input/mousedev.c
31120 --- linux-2.6.39.1/drivers/input/mousedev.c 2011-05-19 00:06:34.000000000 -0400
31121 +++ linux-2.6.39.1/drivers/input/mousedev.c 2011-05-22 19:36:31.000000000 -0400
31122 @@ -764,7 +764,7 @@ static ssize_t mousedev_read(struct file
31123
31124 spin_unlock_irq(&client->packet_lock);
31125
31126 - if (copy_to_user(buffer, data, count))
31127 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
31128 return -EFAULT;
31129
31130 return count;
31131 diff -urNp linux-2.6.39.1/drivers/input/serio/serio.c linux-2.6.39.1/drivers/input/serio/serio.c
31132 --- linux-2.6.39.1/drivers/input/serio/serio.c 2011-05-19 00:06:34.000000000 -0400
31133 +++ linux-2.6.39.1/drivers/input/serio/serio.c 2011-05-22 19:36:31.000000000 -0400
31134 @@ -497,7 +497,7 @@ static void serio_release_port(struct de
31135 */
31136 static void serio_init_port(struct serio *serio)
31137 {
31138 - static atomic_t serio_no = ATOMIC_INIT(0);
31139 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31140
31141 __module_get(THIS_MODULE);
31142
31143 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio
31144 mutex_init(&serio->drv_mutex);
31145 device_initialize(&serio->dev);
31146 dev_set_name(&serio->dev, "serio%ld",
31147 - (long)atomic_inc_return(&serio_no) - 1);
31148 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
31149 serio->dev.bus = &serio_bus;
31150 serio->dev.release = serio_release_port;
31151 serio->dev.groups = serio_device_attr_groups;
31152 diff -urNp linux-2.6.39.1/drivers/isdn/capi/capi.c linux-2.6.39.1/drivers/isdn/capi/capi.c
31153 --- linux-2.6.39.1/drivers/isdn/capi/capi.c 2011-05-19 00:06:34.000000000 -0400
31154 +++ linux-2.6.39.1/drivers/isdn/capi/capi.c 2011-05-22 19:36:31.000000000 -0400
31155 @@ -89,8 +89,8 @@ struct capiminor {
31156
31157 struct capi20_appl *ap;
31158 u32 ncci;
31159 - atomic_t datahandle;
31160 - atomic_t msgid;
31161 + atomic_unchecked_t datahandle;
31162 + atomic_unchecked_t msgid;
31163
31164 struct tty_port port;
31165 int ttyinstop;
31166 @@ -414,7 +414,7 @@ gen_data_b3_resp_for(struct capiminor *m
31167 capimsg_setu16(s, 2, mp->ap->applid);
31168 capimsg_setu8 (s, 4, CAPI_DATA_B3);
31169 capimsg_setu8 (s, 5, CAPI_RESP);
31170 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
31171 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
31172 capimsg_setu32(s, 8, mp->ncci);
31173 capimsg_setu16(s, 12, datahandle);
31174 }
31175 @@ -547,14 +547,14 @@ static void handle_minor_send(struct cap
31176 mp->outbytes -= len;
31177 spin_unlock_bh(&mp->outlock);
31178
31179 - datahandle = atomic_inc_return(&mp->datahandle);
31180 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
31181 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
31182 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31183 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31184 capimsg_setu16(skb->data, 2, mp->ap->applid);
31185 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
31186 capimsg_setu8 (skb->data, 5, CAPI_REQ);
31187 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
31188 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
31189 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
31190 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
31191 capimsg_setu16(skb->data, 16, len); /* Data length */
31192 diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/common.c linux-2.6.39.1/drivers/isdn/gigaset/common.c
31193 --- linux-2.6.39.1/drivers/isdn/gigaset/common.c 2011-05-19 00:06:34.000000000 -0400
31194 +++ linux-2.6.39.1/drivers/isdn/gigaset/common.c 2011-05-22 19:36:31.000000000 -0400
31195 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
31196 cs->commands_pending = 0;
31197 cs->cur_at_seq = 0;
31198 cs->gotfwver = -1;
31199 - cs->open_count = 0;
31200 + local_set(&cs->open_count, 0);
31201 cs->dev = NULL;
31202 cs->tty = NULL;
31203 cs->tty_dev = NULL;
31204 diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h
31205 --- linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h 2011-05-19 00:06:34.000000000 -0400
31206 +++ linux-2.6.39.1/drivers/isdn/gigaset/gigaset.h 2011-05-22 19:36:31.000000000 -0400
31207 @@ -35,6 +35,7 @@
31208 #include <linux/tty_driver.h>
31209 #include <linux/list.h>
31210 #include <asm/atomic.h>
31211 +#include <asm/local.h>
31212
31213 #define GIG_VERSION {0, 5, 0, 0}
31214 #define GIG_COMPAT {0, 4, 0, 0}
31215 @@ -433,7 +434,7 @@ struct cardstate {
31216 spinlock_t cmdlock;
31217 unsigned curlen, cmdbytes;
31218
31219 - unsigned open_count;
31220 + local_t open_count;
31221 struct tty_struct *tty;
31222 struct tasklet_struct if_wake_tasklet;
31223 unsigned control_state;
31224 diff -urNp linux-2.6.39.1/drivers/isdn/gigaset/interface.c linux-2.6.39.1/drivers/isdn/gigaset/interface.c
31225 --- linux-2.6.39.1/drivers/isdn/gigaset/interface.c 2011-05-19 00:06:34.000000000 -0400
31226 +++ linux-2.6.39.1/drivers/isdn/gigaset/interface.c 2011-05-22 19:36:31.000000000 -0400
31227 @@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
31228 return -ERESTARTSYS;
31229 tty->driver_data = cs;
31230
31231 - ++cs->open_count;
31232 -
31233 - if (cs->open_count == 1) {
31234 + if (local_inc_return(&cs->open_count) == 1) {
31235 spin_lock_irqsave(&cs->lock, flags);
31236 cs->tty = tty;
31237 spin_unlock_irqrestore(&cs->lock, flags);
31238 @@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
31239
31240 if (!cs->connected)
31241 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31242 - else if (!cs->open_count)
31243 + else if (!local_read(&cs->open_count))
31244 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31245 else {
31246 - if (!--cs->open_count) {
31247 + if (!local_dec_return(&cs->open_count)) {
31248 spin_lock_irqsave(&cs->lock, flags);
31249 cs->tty = NULL;
31250 spin_unlock_irqrestore(&cs->lock, flags);
31251 @@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
31252 if (!cs->connected) {
31253 gig_dbg(DEBUG_IF, "not connected");
31254 retval = -ENODEV;
31255 - } else if (!cs->open_count)
31256 + } else if (!local_read(&cs->open_count))
31257 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31258 else {
31259 retval = 0;
31260 @@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
31261 retval = -ENODEV;
31262 goto done;
31263 }
31264 - if (!cs->open_count) {
31265 + if (!local_read(&cs->open_count)) {
31266 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31267 retval = -ENODEV;
31268 goto done;
31269 @@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
31270 if (!cs->connected) {
31271 gig_dbg(DEBUG_IF, "not connected");
31272 retval = -ENODEV;
31273 - } else if (!cs->open_count)
31274 + } else if (!local_read(&cs->open_count))
31275 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31276 else if (cs->mstate != MS_LOCKED) {
31277 dev_warn(cs->dev, "can't write to unlocked device\n");
31278 @@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
31279
31280 if (!cs->connected)
31281 gig_dbg(DEBUG_IF, "not connected");
31282 - else if (!cs->open_count)
31283 + else if (!local_read(&cs->open_count))
31284 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31285 else if (cs->mstate != MS_LOCKED)
31286 dev_warn(cs->dev, "can't write to unlocked device\n");
31287 @@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
31288
31289 if (!cs->connected)
31290 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31291 - else if (!cs->open_count)
31292 + else if (!local_read(&cs->open_count))
31293 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31294 else
31295 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31296 @@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
31297
31298 if (!cs->connected)
31299 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31300 - else if (!cs->open_count)
31301 + else if (!local_read(&cs->open_count))
31302 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31303 else
31304 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31305 @@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
31306 goto out;
31307 }
31308
31309 - if (!cs->open_count) {
31310 + if (!local_read(&cs->open_count)) {
31311 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31312 goto out;
31313 }
31314 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c
31315 --- linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c 2011-05-19 00:06:34.000000000 -0400
31316 +++ linux-2.6.39.1/drivers/isdn/hardware/avm/b1.c 2011-05-22 19:36:31.000000000 -0400
31317 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
31318 }
31319 if (left) {
31320 if (t4file->user) {
31321 - if (copy_from_user(buf, dp, left))
31322 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31323 return -EFAULT;
31324 } else {
31325 memcpy(buf, dp, left);
31326 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
31327 }
31328 if (left) {
31329 if (config->user) {
31330 - if (copy_from_user(buf, dp, left))
31331 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31332 return -EFAULT;
31333 } else {
31334 memcpy(buf, dp, left);
31335 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c
31336 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-19 00:06:34.000000000 -0400
31337 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-22 19:36:31.000000000 -0400
31338 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31339 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31340 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31341
31342 + pax_track_stack();
31343
31344 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31345 {
31346 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c
31347 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c 2011-05-19 00:06:34.000000000 -0400
31348 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/capifunc.c 2011-05-22 19:36:31.000000000 -0400
31349 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31350 IDI_SYNC_REQ req;
31351 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31352
31353 + pax_track_stack();
31354 +
31355 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31356
31357 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31358 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c
31359 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-19 00:06:34.000000000 -0400
31360 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-22 19:36:31.000000000 -0400
31361 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31362 IDI_SYNC_REQ req;
31363 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31364
31365 + pax_track_stack();
31366 +
31367 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31368
31369 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31370 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c
31371 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-19 00:06:34.000000000 -0400
31372 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-22 19:36:31.000000000 -0400
31373 @@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31374 IDI_SYNC_REQ req;
31375 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31376
31377 + pax_track_stack();
31378 +
31379 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31380
31381 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31382 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c
31383 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c 2011-05-19 00:06:34.000000000 -0400
31384 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/idifunc.c 2011-05-22 19:36:31.000000000 -0400
31385 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31386 IDI_SYNC_REQ req;
31387 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31388
31389 + pax_track_stack();
31390 +
31391 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31392
31393 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31394 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c
31395 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c 2011-05-19 00:06:34.000000000 -0400
31396 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/message.c 2011-05-22 19:36:31.000000000 -0400
31397 @@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31398 dword d;
31399 word w;
31400
31401 + pax_track_stack();
31402 +
31403 a = plci->adapter;
31404 Id = ((word)plci->Id<<8)|a->Id;
31405 PUT_WORD(&SS_Ind[4],0x0000);
31406 @@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31407 word j, n, w;
31408 dword d;
31409
31410 + pax_track_stack();
31411 +
31412
31413 for(i=0;i<8;i++) bp_parms[i].length = 0;
31414 for(i=0;i<2;i++) global_config[i].length = 0;
31415 @@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31416 const byte llc3[] = {4,3,2,2,6,6,0};
31417 const byte header[] = {0,2,3,3,0,0,0};
31418
31419 + pax_track_stack();
31420 +
31421 for(i=0;i<8;i++) bp_parms[i].length = 0;
31422 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31423 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31424 @@ -14760,6 +14766,8 @@ static void group_optimization(DIVA_CAPI
31425 word appl_number_group_type[MAX_APPL];
31426 PLCI *auxplci;
31427
31428 + pax_track_stack();
31429 +
31430 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31431
31432 if(!a->group_optimization_enabled)
31433 diff -urNp linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c
31434 --- linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-19 00:06:34.000000000 -0400
31435 +++ linux-2.6.39.1/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-22 19:36:31.000000000 -0400
31436 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31437 IDI_SYNC_REQ req;
31438 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31439
31440 + pax_track_stack();
31441 +
31442 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31443
31444 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31445 diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c
31446 --- linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c 2011-05-19 00:06:34.000000000 -0400
31447 +++ linux-2.6.39.1/drivers/isdn/i4l/isdn_common.c 2011-05-22 19:36:31.000000000 -0400
31448 @@ -1292,6 +1292,8 @@ isdn_ioctl(struct file *file, uint cmd,
31449 } iocpar;
31450 void __user *argp = (void __user *)arg;
31451
31452 + pax_track_stack();
31453 +
31454 #define name iocpar.name
31455 #define bname iocpar.bname
31456 #define iocts iocpar.iocts
31457 diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c
31458 --- linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c 2011-05-19 00:06:34.000000000 -0400
31459 +++ linux-2.6.39.1/drivers/isdn/i4l/isdn_net.c 2011-05-22 19:36:31.000000000 -0400
31460 @@ -400,7 +400,7 @@ isdn_net_stat_callback(int idx, isdn_ctr
31461 isdn_net_local *lp = p->local;
31462 #ifdef CONFIG_ISDN_X25
31463 struct concap_proto *cprot = lp->netdev->cprot;
31464 - struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31465 + const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31466 #endif
31467 switch (cmd) {
31468 case ISDN_STAT_BSENT:
31469 @@ -831,7 +831,7 @@ isdn_net_hangup(struct net_device *d)
31470 isdn_ctrl cmd;
31471 #ifdef CONFIG_ISDN_X25
31472 struct concap_proto *cprot = lp->netdev->cprot;
31473 - struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31474 + const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31475 #endif
31476
31477 if (lp->flags & ISDN_NET_CONNECTED) {
31478 diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c
31479 --- linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c 2011-05-19 00:06:34.000000000 -0400
31480 +++ linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.c 2011-05-22 19:36:31.000000000 -0400
31481 @@ -52,7 +52,7 @@ static int isdn_x25iface_connect_ind( st
31482 static int isdn_x25iface_disconn_ind( struct concap_proto * );
31483
31484
31485 -static struct concap_proto_ops ix25_pops = {
31486 +static const struct concap_proto_ops ix25_pops = {
31487 &isdn_x25iface_proto_new,
31488 &isdn_x25iface_proto_del,
31489 &isdn_x25iface_proto_restart,
31490 diff -urNp linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h
31491 --- linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h 2011-05-19 00:06:34.000000000 -0400
31492 +++ linux-2.6.39.1/drivers/isdn/i4l/isdn_x25iface.h 2011-05-22 19:36:31.000000000 -0400
31493 @@ -23,7 +23,7 @@
31494 #include <linux/isdn.h>
31495 #include <linux/concap.h>
31496
31497 -extern struct concap_proto_ops * isdn_x25iface_concap_proto_ops_pt;
31498 +extern const struct concap_proto_ops *isdn_x25iface_concap_proto_ops_pt;
31499 extern struct concap_proto * isdn_x25iface_proto_new(void);
31500
31501
31502 diff -urNp linux-2.6.39.1/drivers/isdn/icn/icn.c linux-2.6.39.1/drivers/isdn/icn/icn.c
31503 --- linux-2.6.39.1/drivers/isdn/icn/icn.c 2011-05-19 00:06:34.000000000 -0400
31504 +++ linux-2.6.39.1/drivers/isdn/icn/icn.c 2011-05-22 19:36:31.000000000 -0400
31505 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
31506 if (count > len)
31507 count = len;
31508 if (user) {
31509 - if (copy_from_user(msg, buf, count))
31510 + if (count > sizeof msg || copy_from_user(msg, buf, count))
31511 return -EFAULT;
31512 } else
31513 memcpy(msg, buf, count);
31514 diff -urNp linux-2.6.39.1/drivers/lguest/core.c linux-2.6.39.1/drivers/lguest/core.c
31515 --- linux-2.6.39.1/drivers/lguest/core.c 2011-05-19 00:06:34.000000000 -0400
31516 +++ linux-2.6.39.1/drivers/lguest/core.c 2011-05-22 19:36:31.000000000 -0400
31517 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
31518 * it's worked so far. The end address needs +1 because __get_vm_area
31519 * allocates an extra guard page, so we need space for that.
31520 */
31521 +
31522 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31523 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31524 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31525 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31526 +#else
31527 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31528 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31529 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31530 +#endif
31531 +
31532 if (!switcher_vma) {
31533 err = -ENOMEM;
31534 printk("lguest: could not map switcher pages high\n");
31535 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31536 * Now the Switcher is mapped at the right address, we can't fail!
31537 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31538 */
31539 - memcpy(switcher_vma->addr, start_switcher_text,
31540 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31541 end_switcher_text - start_switcher_text);
31542
31543 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31544 diff -urNp linux-2.6.39.1/drivers/lguest/lguest_device.c linux-2.6.39.1/drivers/lguest/lguest_device.c
31545 --- linux-2.6.39.1/drivers/lguest/lguest_device.c 2011-05-19 00:06:34.000000000 -0400
31546 +++ linux-2.6.39.1/drivers/lguest/lguest_device.c 2011-05-22 19:36:31.000000000 -0400
31547 @@ -374,7 +374,7 @@ error:
31548 }
31549
31550 /* The ops structure which hooks everything together. */
31551 -static struct virtio_config_ops lguest_config_ops = {
31552 +static const struct virtio_config_ops lguest_config_ops = {
31553 .get_features = lg_get_features,
31554 .finalize_features = lg_finalize_features,
31555 .get = lg_get,
31556 diff -urNp linux-2.6.39.1/drivers/lguest/x86/core.c linux-2.6.39.1/drivers/lguest/x86/core.c
31557 --- linux-2.6.39.1/drivers/lguest/x86/core.c 2011-05-19 00:06:34.000000000 -0400
31558 +++ linux-2.6.39.1/drivers/lguest/x86/core.c 2011-05-22 19:36:31.000000000 -0400
31559 @@ -59,7 +59,7 @@ static struct {
31560 /* Offset from where switcher.S was compiled to where we've copied it */
31561 static unsigned long switcher_offset(void)
31562 {
31563 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31564 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31565 }
31566
31567 /* This cpu's struct lguest_pages. */
31568 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31569 * These copies are pretty cheap, so we do them unconditionally: */
31570 /* Save the current Host top-level page directory.
31571 */
31572 +
31573 +#ifdef CONFIG_PAX_PER_CPU_PGD
31574 + pages->state.host_cr3 = read_cr3();
31575 +#else
31576 pages->state.host_cr3 = __pa(current->mm->pgd);
31577 +#endif
31578 +
31579 /*
31580 * Set up the Guest's page tables to see this CPU's pages (and no
31581 * other CPU's pages).
31582 @@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
31583 * compiled-in switcher code and the high-mapped copy we just made.
31584 */
31585 for (i = 0; i < IDT_ENTRIES; i++)
31586 - default_idt_entries[i] += switcher_offset();
31587 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31588
31589 /*
31590 * Set up the Switcher's per-cpu areas.
31591 @@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
31592 * it will be undisturbed when we switch. To change %cs and jump we
31593 * need this structure to feed to Intel's "lcall" instruction.
31594 */
31595 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31596 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31597 lguest_entry.segment = LGUEST_CS;
31598
31599 /*
31600 diff -urNp linux-2.6.39.1/drivers/lguest/x86/switcher_32.S linux-2.6.39.1/drivers/lguest/x86/switcher_32.S
31601 --- linux-2.6.39.1/drivers/lguest/x86/switcher_32.S 2011-05-19 00:06:34.000000000 -0400
31602 +++ linux-2.6.39.1/drivers/lguest/x86/switcher_32.S 2011-05-22 19:36:31.000000000 -0400
31603 @@ -87,6 +87,7 @@
31604 #include <asm/page.h>
31605 #include <asm/segment.h>
31606 #include <asm/lguest.h>
31607 +#include <asm/processor-flags.h>
31608
31609 // We mark the start of the code to copy
31610 // It's placed in .text tho it's never run here
31611 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31612 // Changes type when we load it: damn Intel!
31613 // For after we switch over our page tables
31614 // That entry will be read-only: we'd crash.
31615 +
31616 +#ifdef CONFIG_PAX_KERNEXEC
31617 + mov %cr0, %edx
31618 + xor $X86_CR0_WP, %edx
31619 + mov %edx, %cr0
31620 +#endif
31621 +
31622 movl $(GDT_ENTRY_TSS*8), %edx
31623 ltr %dx
31624
31625 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31626 // Let's clear it again for our return.
31627 // The GDT descriptor of the Host
31628 // Points to the table after two "size" bytes
31629 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31630 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31631 // Clear "used" from type field (byte 5, bit 2)
31632 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31633 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31634 +
31635 +#ifdef CONFIG_PAX_KERNEXEC
31636 + mov %cr0, %eax
31637 + xor $X86_CR0_WP, %eax
31638 + mov %eax, %cr0
31639 +#endif
31640
31641 // Once our page table's switched, the Guest is live!
31642 // The Host fades as we run this final step.
31643 @@ -295,13 +309,12 @@ deliver_to_host:
31644 // I consulted gcc, and it gave
31645 // These instructions, which I gladly credit:
31646 leal (%edx,%ebx,8), %eax
31647 - movzwl (%eax),%edx
31648 - movl 4(%eax), %eax
31649 - xorw %ax, %ax
31650 - orl %eax, %edx
31651 + movl 4(%eax), %edx
31652 + movw (%eax), %dx
31653 // Now the address of the handler's in %edx
31654 // We call it now: its "iret" drops us home.
31655 - jmp *%edx
31656 + ljmp $__KERNEL_CS, $1f
31657 +1: jmp *%edx
31658
31659 // Every interrupt can come to us here
31660 // But we must truly tell each apart.
31661 diff -urNp linux-2.6.39.1/drivers/md/dm.c linux-2.6.39.1/drivers/md/dm.c
31662 --- linux-2.6.39.1/drivers/md/dm.c 2011-05-19 00:06:34.000000000 -0400
31663 +++ linux-2.6.39.1/drivers/md/dm.c 2011-05-22 19:36:31.000000000 -0400
31664 @@ -162,9 +162,9 @@ struct mapped_device {
31665 /*
31666 * Event handling.
31667 */
31668 - atomic_t event_nr;
31669 + atomic_unchecked_t event_nr;
31670 wait_queue_head_t eventq;
31671 - atomic_t uevent_seq;
31672 + atomic_unchecked_t uevent_seq;
31673 struct list_head uevent_list;
31674 spinlock_t uevent_lock; /* Protect access to uevent_list */
31675
31676 @@ -1836,8 +1836,8 @@ static struct mapped_device *alloc_dev(i
31677 rwlock_init(&md->map_lock);
31678 atomic_set(&md->holders, 1);
31679 atomic_set(&md->open_count, 0);
31680 - atomic_set(&md->event_nr, 0);
31681 - atomic_set(&md->uevent_seq, 0);
31682 + atomic_set_unchecked(&md->event_nr, 0);
31683 + atomic_set_unchecked(&md->uevent_seq, 0);
31684 INIT_LIST_HEAD(&md->uevent_list);
31685 spin_lock_init(&md->uevent_lock);
31686
31687 @@ -1971,7 +1971,7 @@ static void event_callback(void *context
31688
31689 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31690
31691 - atomic_inc(&md->event_nr);
31692 + atomic_inc_unchecked(&md->event_nr);
31693 wake_up(&md->eventq);
31694 }
31695
31696 @@ -2547,18 +2547,18 @@ int dm_kobject_uevent(struct mapped_devi
31697
31698 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31699 {
31700 - return atomic_add_return(1, &md->uevent_seq);
31701 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31702 }
31703
31704 uint32_t dm_get_event_nr(struct mapped_device *md)
31705 {
31706 - return atomic_read(&md->event_nr);
31707 + return atomic_read_unchecked(&md->event_nr);
31708 }
31709
31710 int dm_wait_event(struct mapped_device *md, int event_nr)
31711 {
31712 return wait_event_interruptible(md->eventq,
31713 - (event_nr != atomic_read(&md->event_nr)));
31714 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31715 }
31716
31717 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31718 diff -urNp linux-2.6.39.1/drivers/md/dm-crypt.c linux-2.6.39.1/drivers/md/dm-crypt.c
31719 --- linux-2.6.39.1/drivers/md/dm-crypt.c 2011-05-19 00:06:34.000000000 -0400
31720 +++ linux-2.6.39.1/drivers/md/dm-crypt.c 2011-05-22 19:36:31.000000000 -0400
31721 @@ -138,7 +138,7 @@ struct crypt_config {
31722 char *cipher;
31723 char *cipher_string;
31724
31725 - struct crypt_iv_operations *iv_gen_ops;
31726 + const struct crypt_iv_operations *iv_gen_ops;
31727 union {
31728 struct iv_essiv_private essiv;
31729 struct iv_benbi_private benbi;
31730 @@ -620,15 +620,15 @@ static int crypt_iv_lmk_post(struct cryp
31731 return r;
31732 }
31733
31734 -static struct crypt_iv_operations crypt_iv_plain_ops = {
31735 +static const struct crypt_iv_operations crypt_iv_plain_ops = {
31736 .generator = crypt_iv_plain_gen
31737 };
31738
31739 -static struct crypt_iv_operations crypt_iv_plain64_ops = {
31740 +static const struct crypt_iv_operations crypt_iv_plain64_ops = {
31741 .generator = crypt_iv_plain64_gen
31742 };
31743
31744 -static struct crypt_iv_operations crypt_iv_essiv_ops = {
31745 +static const struct crypt_iv_operations crypt_iv_essiv_ops = {
31746 .ctr = crypt_iv_essiv_ctr,
31747 .dtr = crypt_iv_essiv_dtr,
31748 .init = crypt_iv_essiv_init,
31749 @@ -636,17 +636,17 @@ static struct crypt_iv_operations crypt_
31750 .generator = crypt_iv_essiv_gen
31751 };
31752
31753 -static struct crypt_iv_operations crypt_iv_benbi_ops = {
31754 +static const struct crypt_iv_operations crypt_iv_benbi_ops = {
31755 .ctr = crypt_iv_benbi_ctr,
31756 .dtr = crypt_iv_benbi_dtr,
31757 .generator = crypt_iv_benbi_gen
31758 };
31759
31760 -static struct crypt_iv_operations crypt_iv_null_ops = {
31761 +static const struct crypt_iv_operations crypt_iv_null_ops = {
31762 .generator = crypt_iv_null_gen
31763 };
31764
31765 -static struct crypt_iv_operations crypt_iv_lmk_ops = {
31766 +static const struct crypt_iv_operations crypt_iv_lmk_ops = {
31767 .ctr = crypt_iv_lmk_ctr,
31768 .dtr = crypt_iv_lmk_dtr,
31769 .init = crypt_iv_lmk_init,
31770 diff -urNp linux-2.6.39.1/drivers/md/dm-ioctl.c linux-2.6.39.1/drivers/md/dm-ioctl.c
31771 --- linux-2.6.39.1/drivers/md/dm-ioctl.c 2011-05-19 00:06:34.000000000 -0400
31772 +++ linux-2.6.39.1/drivers/md/dm-ioctl.c 2011-05-22 19:36:31.000000000 -0400
31773 @@ -1551,7 +1551,7 @@ static int validate_params(uint cmd, str
31774 cmd == DM_LIST_VERSIONS_CMD)
31775 return 0;
31776
31777 - if ((cmd == DM_DEV_CREATE_CMD)) {
31778 + if (cmd == DM_DEV_CREATE_CMD) {
31779 if (!*param->name) {
31780 DMWARN("name not supplied when creating device");
31781 return -EINVAL;
31782 diff -urNp linux-2.6.39.1/drivers/md/dm-raid1.c linux-2.6.39.1/drivers/md/dm-raid1.c
31783 --- linux-2.6.39.1/drivers/md/dm-raid1.c 2011-05-19 00:06:34.000000000 -0400
31784 +++ linux-2.6.39.1/drivers/md/dm-raid1.c 2011-05-22 19:36:31.000000000 -0400
31785 @@ -42,7 +42,7 @@ enum dm_raid1_error {
31786
31787 struct mirror {
31788 struct mirror_set *ms;
31789 - atomic_t error_count;
31790 + atomic_unchecked_t error_count;
31791 unsigned long error_type;
31792 struct dm_dev *dev;
31793 sector_t offset;
31794 @@ -187,7 +187,7 @@ static struct mirror *get_valid_mirror(s
31795 struct mirror *m;
31796
31797 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31798 - if (!atomic_read(&m->error_count))
31799 + if (!atomic_read_unchecked(&m->error_count))
31800 return m;
31801
31802 return NULL;
31803 @@ -219,7 +219,7 @@ static void fail_mirror(struct mirror *m
31804 * simple way to tell if a device has encountered
31805 * errors.
31806 */
31807 - atomic_inc(&m->error_count);
31808 + atomic_inc_unchecked(&m->error_count);
31809
31810 if (test_and_set_bit(error_type, &m->error_type))
31811 return;
31812 @@ -410,7 +410,7 @@ static struct mirror *choose_mirror(stru
31813 struct mirror *m = get_default_mirror(ms);
31814
31815 do {
31816 - if (likely(!atomic_read(&m->error_count)))
31817 + if (likely(!atomic_read_unchecked(&m->error_count)))
31818 return m;
31819
31820 if (m-- == ms->mirror)
31821 @@ -424,7 +424,7 @@ static int default_ok(struct mirror *m)
31822 {
31823 struct mirror *default_mirror = get_default_mirror(m->ms);
31824
31825 - return !atomic_read(&default_mirror->error_count);
31826 + return !atomic_read_unchecked(&default_mirror->error_count);
31827 }
31828
31829 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31830 @@ -561,7 +561,7 @@ static void do_reads(struct mirror_set *
31831 */
31832 if (likely(region_in_sync(ms, region, 1)))
31833 m = choose_mirror(ms, bio->bi_sector);
31834 - else if (m && atomic_read(&m->error_count))
31835 + else if (m && atomic_read_unchecked(&m->error_count))
31836 m = NULL;
31837
31838 if (likely(m))
31839 @@ -939,7 +939,7 @@ static int get_mirror(struct mirror_set
31840 }
31841
31842 ms->mirror[mirror].ms = ms;
31843 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31844 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31845 ms->mirror[mirror].error_type = 0;
31846 ms->mirror[mirror].offset = offset;
31847
31848 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_targ
31849 */
31850 static char device_status_char(struct mirror *m)
31851 {
31852 - if (!atomic_read(&(m->error_count)))
31853 + if (!atomic_read_unchecked(&(m->error_count)))
31854 return 'A';
31855
31856 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31857 diff -urNp linux-2.6.39.1/drivers/md/dm-stripe.c linux-2.6.39.1/drivers/md/dm-stripe.c
31858 --- linux-2.6.39.1/drivers/md/dm-stripe.c 2011-05-19 00:06:34.000000000 -0400
31859 +++ linux-2.6.39.1/drivers/md/dm-stripe.c 2011-05-22 19:36:31.000000000 -0400
31860 @@ -20,7 +20,7 @@ struct stripe {
31861 struct dm_dev *dev;
31862 sector_t physical_start;
31863
31864 - atomic_t error_count;
31865 + atomic_unchecked_t error_count;
31866 };
31867
31868 struct stripe_c {
31869 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *
31870 kfree(sc);
31871 return r;
31872 }
31873 - atomic_set(&(sc->stripe[i].error_count), 0);
31874 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31875 }
31876
31877 ti->private = sc;
31878 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_targe
31879 DMEMIT("%d ", sc->stripes);
31880 for (i = 0; i < sc->stripes; i++) {
31881 DMEMIT("%s ", sc->stripe[i].dev->name);
31882 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31883 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31884 'D' : 'A';
31885 }
31886 buffer[i] = '\0';
31887 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_targe
31888 */
31889 for (i = 0; i < sc->stripes; i++)
31890 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31891 - atomic_inc(&(sc->stripe[i].error_count));
31892 - if (atomic_read(&(sc->stripe[i].error_count)) <
31893 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31894 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31895 DM_IO_ERROR_THRESHOLD)
31896 schedule_work(&sc->trigger_event);
31897 }
31898 diff -urNp linux-2.6.39.1/drivers/md/dm-table.c linux-2.6.39.1/drivers/md/dm-table.c
31899 --- linux-2.6.39.1/drivers/md/dm-table.c 2011-06-03 00:04:14.000000000 -0400
31900 +++ linux-2.6.39.1/drivers/md/dm-table.c 2011-06-03 00:32:05.000000000 -0400
31901 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct
31902 if (!dev_size)
31903 return 0;
31904
31905 - if ((start >= dev_size) || (start + len > dev_size)) {
31906 + if ((start >= dev_size) || (len > dev_size - start)) {
31907 DMWARN("%s: %s too small for target: "
31908 "start=%llu, len=%llu, dev_size=%llu",
31909 dm_device_name(ti->table->md), bdevname(bdev, b),
31910 diff -urNp linux-2.6.39.1/drivers/md/md.c linux-2.6.39.1/drivers/md/md.c
31911 --- linux-2.6.39.1/drivers/md/md.c 2011-06-03 00:04:14.000000000 -0400
31912 +++ linux-2.6.39.1/drivers/md/md.c 2011-06-03 00:32:05.000000000 -0400
31913 @@ -226,10 +226,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
31914 * start build, activate spare
31915 */
31916 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31917 -static atomic_t md_event_count;
31918 +static atomic_unchecked_t md_event_count;
31919 void md_new_event(mddev_t *mddev)
31920 {
31921 - atomic_inc(&md_event_count);
31922 + atomic_inc_unchecked(&md_event_count);
31923 wake_up(&md_event_waiters);
31924 }
31925 EXPORT_SYMBOL_GPL(md_new_event);
31926 @@ -239,7 +239,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31927 */
31928 static void md_new_event_inintr(mddev_t *mddev)
31929 {
31930 - atomic_inc(&md_event_count);
31931 + atomic_inc_unchecked(&md_event_count);
31932 wake_up(&md_event_waiters);
31933 }
31934
31935 @@ -1454,7 +1454,7 @@ static int super_1_load(mdk_rdev_t *rdev
31936
31937 rdev->preferred_minor = 0xffff;
31938 rdev->data_offset = le64_to_cpu(sb->data_offset);
31939 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31940 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31941
31942 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31943 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31944 @@ -1632,7 +1632,7 @@ static void super_1_sync(mddev_t *mddev,
31945 else
31946 sb->resync_offset = cpu_to_le64(0);
31947
31948 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31949 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31950
31951 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31952 sb->size = cpu_to_le64(mddev->dev_sectors);
31953 @@ -2414,7 +2414,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
31954 static ssize_t
31955 errors_show(mdk_rdev_t *rdev, char *page)
31956 {
31957 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31958 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31959 }
31960
31961 static ssize_t
31962 @@ -2423,7 +2423,7 @@ errors_store(mdk_rdev_t *rdev, const cha
31963 char *e;
31964 unsigned long n = simple_strtoul(buf, &e, 10);
31965 if (*buf && (*e == 0 || *e == '\n')) {
31966 - atomic_set(&rdev->corrected_errors, n);
31967 + atomic_set_unchecked(&rdev->corrected_errors, n);
31968 return len;
31969 }
31970 return -EINVAL;
31971 @@ -2779,8 +2779,8 @@ void md_rdev_init(mdk_rdev_t *rdev)
31972 rdev->last_read_error.tv_sec = 0;
31973 rdev->last_read_error.tv_nsec = 0;
31974 atomic_set(&rdev->nr_pending, 0);
31975 - atomic_set(&rdev->read_errors, 0);
31976 - atomic_set(&rdev->corrected_errors, 0);
31977 + atomic_set_unchecked(&rdev->read_errors, 0);
31978 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31979
31980 INIT_LIST_HEAD(&rdev->same_set);
31981 init_waitqueue_head(&rdev->blocked_wait);
31982 @@ -6388,7 +6388,7 @@ static int md_seq_show(struct seq_file *
31983
31984 spin_unlock(&pers_lock);
31985 seq_printf(seq, "\n");
31986 - mi->event = atomic_read(&md_event_count);
31987 + mi->event = atomic_read_unchecked(&md_event_count);
31988 return 0;
31989 }
31990 if (v == (void*)2) {
31991 @@ -6477,7 +6477,7 @@ static int md_seq_show(struct seq_file *
31992 chunk_kb ? "KB" : "B");
31993 if (bitmap->file) {
31994 seq_printf(seq, ", file: ");
31995 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31996 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31997 }
31998
31999 seq_printf(seq, "\n");
32000 @@ -6511,7 +6511,7 @@ static int md_seq_open(struct inode *ino
32001 else {
32002 struct seq_file *p = file->private_data;
32003 p->private = mi;
32004 - mi->event = atomic_read(&md_event_count);
32005 + mi->event = atomic_read_unchecked(&md_event_count);
32006 }
32007 return error;
32008 }
32009 @@ -6527,7 +6527,7 @@ static unsigned int mdstat_poll(struct f
32010 /* always allow read */
32011 mask = POLLIN | POLLRDNORM;
32012
32013 - if (mi->event != atomic_read(&md_event_count))
32014 + if (mi->event != atomic_read_unchecked(&md_event_count))
32015 mask |= POLLERR | POLLPRI;
32016 return mask;
32017 }
32018 @@ -6571,7 +6571,7 @@ static int is_mddev_idle(mddev_t *mddev,
32019 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32020 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32021 (int)part_stat_read(&disk->part0, sectors[1]) -
32022 - atomic_read(&disk->sync_io);
32023 + atomic_read_unchecked(&disk->sync_io);
32024 /* sync IO will cause sync_io to increase before the disk_stats
32025 * as sync_io is counted when a request starts, and
32026 * disk_stats is counted when it completes.
32027 diff -urNp linux-2.6.39.1/drivers/md/md.h linux-2.6.39.1/drivers/md/md.h
32028 --- linux-2.6.39.1/drivers/md/md.h 2011-05-19 00:06:34.000000000 -0400
32029 +++ linux-2.6.39.1/drivers/md/md.h 2011-05-22 19:36:31.000000000 -0400
32030 @@ -97,13 +97,13 @@ struct mdk_rdev_s
32031 * only maintained for arrays that
32032 * support hot removal
32033 */
32034 - atomic_t read_errors; /* number of consecutive read errors that
32035 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
32036 * we have tried to ignore.
32037 */
32038 struct timespec last_read_error; /* monotonic time since our
32039 * last read error
32040 */
32041 - atomic_t corrected_errors; /* number of corrected read errors,
32042 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32043 * for reporting to userspace and storing
32044 * in superblock.
32045 */
32046 @@ -342,7 +342,7 @@ static inline void rdev_dec_pending(mdk_
32047
32048 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32049 {
32050 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32051 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32052 }
32053
32054 struct mdk_personality
32055 diff -urNp linux-2.6.39.1/drivers/md/raid10.c linux-2.6.39.1/drivers/md/raid10.c
32056 --- linux-2.6.39.1/drivers/md/raid10.c 2011-05-19 00:06:34.000000000 -0400
32057 +++ linux-2.6.39.1/drivers/md/raid10.c 2011-05-22 19:36:31.000000000 -0400
32058 @@ -1209,7 +1209,7 @@ static void end_sync_read(struct bio *bi
32059 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
32060 set_bit(R10BIO_Uptodate, &r10_bio->state);
32061 else {
32062 - atomic_add(r10_bio->sectors,
32063 + atomic_add_unchecked(r10_bio->sectors,
32064 &conf->mirrors[d].rdev->corrected_errors);
32065 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
32066 md_error(r10_bio->mddev,
32067 @@ -1417,7 +1417,7 @@ static void check_decay_read_errors(mdde
32068 {
32069 struct timespec cur_time_mon;
32070 unsigned long hours_since_last;
32071 - unsigned int read_errors = atomic_read(&rdev->read_errors);
32072 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32073
32074 ktime_get_ts(&cur_time_mon);
32075
32076 @@ -1439,9 +1439,9 @@ static void check_decay_read_errors(mdde
32077 * overflowing the shift of read_errors by hours_since_last.
32078 */
32079 if (hours_since_last >= 8 * sizeof(read_errors))
32080 - atomic_set(&rdev->read_errors, 0);
32081 + atomic_set_unchecked(&rdev->read_errors, 0);
32082 else
32083 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32084 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32085 }
32086
32087 /*
32088 @@ -1476,8 +1476,8 @@ static void fix_read_error(conf_t *conf,
32089 }
32090
32091 check_decay_read_errors(mddev, rdev);
32092 - atomic_inc(&rdev->read_errors);
32093 - cur_read_error_count = atomic_read(&rdev->read_errors);
32094 + atomic_inc_unchecked(&rdev->read_errors);
32095 + cur_read_error_count = atomic_read_unchecked(&rdev->read_errors);
32096 if (cur_read_error_count > max_read_errors) {
32097 rcu_read_unlock();
32098 printk(KERN_NOTICE
32099 @@ -1550,7 +1550,7 @@ static void fix_read_error(conf_t *conf,
32100 test_bit(In_sync, &rdev->flags)) {
32101 atomic_inc(&rdev->nr_pending);
32102 rcu_read_unlock();
32103 - atomic_add(s, &rdev->corrected_errors);
32104 + atomic_add_unchecked(s, &rdev->corrected_errors);
32105 if (sync_page_io(rdev,
32106 r10_bio->devs[sl].addr +
32107 sect,
32108 diff -urNp linux-2.6.39.1/drivers/md/raid1.c linux-2.6.39.1/drivers/md/raid1.c
32109 --- linux-2.6.39.1/drivers/md/raid1.c 2011-05-19 00:06:34.000000000 -0400
32110 +++ linux-2.6.39.1/drivers/md/raid1.c 2011-05-22 19:36:31.000000000 -0400
32111 @@ -1342,7 +1342,7 @@ static void sync_request_write(mddev_t *
32112 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
32113 continue;
32114 rdev = conf->mirrors[d].rdev;
32115 - atomic_add(s, &rdev->corrected_errors);
32116 + atomic_add_unchecked(s, &rdev->corrected_errors);
32117 if (sync_page_io(rdev,
32118 sect,
32119 s<<9,
32120 @@ -1488,7 +1488,7 @@ static void fix_read_error(conf_t *conf,
32121 /* Well, this device is dead */
32122 md_error(mddev, rdev);
32123 else {
32124 - atomic_add(s, &rdev->corrected_errors);
32125 + atomic_add_unchecked(s, &rdev->corrected_errors);
32126 printk(KERN_INFO
32127 "md/raid1:%s: read error corrected "
32128 "(%d sectors at %llu on %s)\n",
32129 diff -urNp linux-2.6.39.1/drivers/md/raid5.c linux-2.6.39.1/drivers/md/raid5.c
32130 --- linux-2.6.39.1/drivers/md/raid5.c 2011-05-19 00:06:34.000000000 -0400
32131 +++ linux-2.6.39.1/drivers/md/raid5.c 2011-05-22 19:36:31.000000000 -0400
32132 @@ -550,7 +550,7 @@ static void ops_run_io(struct stripe_hea
32133 bi->bi_next = NULL;
32134 if (rw == WRITE &&
32135 test_bit(R5_ReWrite, &sh->dev[i].flags))
32136 - atomic_add(STRIPE_SECTORS,
32137 + atomic_add_unchecked(STRIPE_SECTORS,
32138 &rdev->corrected_errors);
32139 generic_make_request(bi);
32140 } else {
32141 @@ -1596,15 +1596,15 @@ static void raid5_end_read_request(struc
32142 clear_bit(R5_ReadError, &sh->dev[i].flags);
32143 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32144 }
32145 - if (atomic_read(&conf->disks[i].rdev->read_errors))
32146 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
32147 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32148 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32149 } else {
32150 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32151 int retry = 0;
32152 rdev = conf->disks[i].rdev;
32153
32154 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32155 - atomic_inc(&rdev->read_errors);
32156 + atomic_inc_unchecked(&rdev->read_errors);
32157 if (conf->mddev->degraded >= conf->max_degraded)
32158 printk_rl(KERN_WARNING
32159 "md/raid:%s: read error not correctable "
32160 @@ -1622,7 +1622,7 @@ static void raid5_end_read_request(struc
32161 (unsigned long long)(sh->sector
32162 + rdev->data_offset),
32163 bdn);
32164 - else if (atomic_read(&rdev->read_errors)
32165 + else if (atomic_read_unchecked(&rdev->read_errors)
32166 > conf->max_nr_stripes)
32167 printk(KERN_WARNING
32168 "md/raid:%s: Too many read errors, failing device %s.\n",
32169 @@ -1947,6 +1947,7 @@ static sector_t compute_blocknr(struct s
32170 sector_t r_sector;
32171 struct stripe_head sh2;
32172
32173 + pax_track_stack();
32174
32175 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32176 stripe = new_sector;
32177 diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_hlp.c linux-2.6.39.1/drivers/media/common/saa7146_hlp.c
32178 --- linux-2.6.39.1/drivers/media/common/saa7146_hlp.c 2011-05-19 00:06:34.000000000 -0400
32179 +++ linux-2.6.39.1/drivers/media/common/saa7146_hlp.c 2011-05-22 19:36:31.000000000 -0400
32180 @@ -353,6 +353,8 @@ static void calculate_clipping_registers
32181
32182 int x[32], y[32], w[32], h[32];
32183
32184 + pax_track_stack();
32185 +
32186 /* clear out memory */
32187 memset(&line_list[0], 0x00, sizeof(u32)*32);
32188 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32189 diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_vbi.c linux-2.6.39.1/drivers/media/common/saa7146_vbi.c
32190 --- linux-2.6.39.1/drivers/media/common/saa7146_vbi.c 2011-05-19 00:06:34.000000000 -0400
32191 +++ linux-2.6.39.1/drivers/media/common/saa7146_vbi.c 2011-05-22 19:36:31.000000000 -0400
32192 @@ -501,7 +501,7 @@ static ssize_t vbi_read(struct file *fil
32193 return ret;
32194 }
32195
32196 -struct saa7146_use_ops saa7146_vbi_uops = {
32197 +const struct saa7146_use_ops saa7146_vbi_uops = {
32198 .init = vbi_init,
32199 .open = vbi_open,
32200 .release = vbi_close,
32201 diff -urNp linux-2.6.39.1/drivers/media/common/saa7146_video.c linux-2.6.39.1/drivers/media/common/saa7146_video.c
32202 --- linux-2.6.39.1/drivers/media/common/saa7146_video.c 2011-05-19 00:06:34.000000000 -0400
32203 +++ linux-2.6.39.1/drivers/media/common/saa7146_video.c 2011-05-22 19:36:31.000000000 -0400
32204 @@ -1420,7 +1420,7 @@ out:
32205 return ret;
32206 }
32207
32208 -struct saa7146_use_ops saa7146_video_uops = {
32209 +const struct saa7146_use_ops saa7146_video_uops = {
32210 .init = video_init,
32211 .open = video_open,
32212 .release = video_close,
32213 diff -urNp linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c
32214 --- linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c 2011-05-19 00:06:34.000000000 -0400
32215 +++ linux-2.6.39.1/drivers/media/dvb/dm1105/dm1105.c 2011-05-22 19:36:31.000000000 -0400
32216 @@ -418,7 +418,7 @@ static u32 functionality(struct i2c_adap
32217 return I2C_FUNC_I2C;
32218 }
32219
32220 -static struct i2c_algorithm dm1105_algo = {
32221 +static const struct i2c_algorithm dm1105_algo = {
32222 .master_xfer = dm1105_i2c_xfer,
32223 .functionality = functionality,
32224 };
32225 diff -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
32226 --- linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-19 00:06:34.000000000 -0400
32227 +++ linux-2.6.39.1/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-22 19:36:31.000000000 -0400
32228 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32229 u8 buf[HOST_LINK_BUF_SIZE];
32230 int i;
32231
32232 + pax_track_stack();
32233 +
32234 dprintk("%s\n", __func__);
32235
32236 /* check if we have space for a link buf in the rx_buffer */
32237 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32238 unsigned long timeout;
32239 int written;
32240
32241 + pax_track_stack();
32242 +
32243 dprintk("%s\n", __func__);
32244
32245 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32246 diff -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
32247 --- linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-19 00:06:34.000000000 -0400
32248 +++ linux-2.6.39.1/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-22 19:36:31.000000000 -0400
32249 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapt
32250 const struct dvb_device *template, void *priv, int type)
32251 {
32252 struct dvb_device *dvbdev;
32253 - struct file_operations *dvbdevfops;
32254 + struct file_operations *dvbdevfops; /* cannot be const, see this function */
32255 struct device *clsdev;
32256 int minor;
32257 int id;
32258 diff -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
32259 --- linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-19 00:06:34.000000000 -0400
32260 +++ linux-2.6.39.1/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-22 19:36:31.000000000 -0400
32261 @@ -391,6 +391,8 @@ int dib0700_download_firmware(struct usb
32262
32263 u8 buf[260];
32264
32265 + pax_track_stack();
32266 +
32267 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32268 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
32269 hx.addr, hx.len, hx.chk);
32270 diff -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
32271 --- linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-19 00:06:34.000000000 -0400
32272 +++ linux-2.6.39.1/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-22 19:36:31.000000000 -0400
32273 @@ -663,6 +663,7 @@ static int lme2510_download_firmware(str
32274 packet_size = 0x31;
32275 len_in = 1;
32276
32277 + pax_track_stack();
32278
32279 info("FRM Starting Firmware Download");
32280
32281 @@ -715,6 +716,8 @@ static void lme_coldreset(struct usb_dev
32282 int ret = 0, len_in;
32283 u8 data[512] = {0};
32284
32285 + pax_track_stack();
32286 +
32287 data[0] = 0x0a;
32288 len_in = 1;
32289 info("FRM Firmware Cold Reset");
32290 diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c
32291 --- linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:04:14.000000000 -0400
32292 +++ linux-2.6.39.1/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:32:05.000000000 -0400
32293 @@ -1945,7 +1945,7 @@ static u32 dib7000p_i2c_func(struct i2c_
32294 return I2C_FUNC_I2C;
32295 }
32296
32297 -static struct i2c_algorithm dib7090_tuner_xfer_algo = {
32298 +static const struct i2c_algorithm dib7090_tuner_xfer_algo = {
32299 .master_xfer = dib7090_tuner_xfer,
32300 .functionality = dib7000p_i2c_func,
32301 };
32302 diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c
32303 --- linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:04:14.000000000 -0400
32304 +++ linux-2.6.39.1/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:32:05.000000000 -0400
32305 @@ -1676,12 +1676,12 @@ static u32 dib9000_i2c_func(struct i2c_a
32306 return I2C_FUNC_I2C;
32307 }
32308
32309 -static struct i2c_algorithm dib9000_tuner_algo = {
32310 +static const struct i2c_algorithm dib9000_tuner_algo = {
32311 .master_xfer = dib9000_tuner_xfer,
32312 .functionality = dib9000_i2c_func,
32313 };
32314
32315 -static struct i2c_algorithm dib9000_component_bus_algo = {
32316 +static const struct i2c_algorithm dib9000_component_bus_algo = {
32317 .master_xfer = dib9000_fw_component_bus_xfer,
32318 .functionality = dib9000_i2c_func,
32319 };
32320 diff -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
32321 --- linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:04:14.000000000 -0400
32322 +++ linux-2.6.39.1/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:37:36.000000000 -0400
32323 @@ -221,12 +221,12 @@ static int dibx000_i2c_master_xfer_gpio3
32324 return num;
32325 }
32326
32327 -static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32328 +static const struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32329 .master_xfer = dibx000_i2c_master_xfer_gpio12,
32330 .functionality = dibx000_i2c_func,
32331 };
32332
32333 -static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32334 +static const struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32335 .master_xfer = dibx000_i2c_master_xfer_gpio34,
32336 .functionality = dibx000_i2c_func,
32337 };
32338 @@ -285,7 +285,7 @@ static int dibx000_i2c_gated_gpio67_xfer
32339 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32340 }
32341
32342 -static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32343 +static const struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32344 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
32345 .functionality = dibx000_i2c_func,
32346 };
32347 @@ -322,7 +322,7 @@ static int dibx000_i2c_gated_tuner_xfer(
32348 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32349 }
32350
32351 -static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32352 +static const struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32353 .master_xfer = dibx000_i2c_gated_tuner_xfer,
32354 .functionality = dibx000_i2c_func,
32355 };
32356 @@ -375,7 +375,7 @@ void dibx000_reset_i2c_master(struct dib
32357 EXPORT_SYMBOL(dibx000_reset_i2c_master);
32358
32359 static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
32360 - struct i2c_algorithm *algo, const char *name,
32361 + const struct i2c_algorithm *algo, const char *name,
32362 struct dibx000_i2c_master *mst)
32363 {
32364 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
32365 diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c
32366 --- linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c 2011-05-19 00:06:34.000000000 -0400
32367 +++ linux-2.6.39.1/drivers/media/dvb/frontends/mb86a16.c 2011-05-22 19:36:31.000000000 -0400
32368 @@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16
32369 int ret = -1;
32370 int sync;
32371
32372 + pax_track_stack();
32373 +
32374 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
32375
32376 fcp = 3000;
32377 diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c
32378 --- linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c 2011-05-19 00:06:34.000000000 -0400
32379 +++ linux-2.6.39.1/drivers/media/dvb/frontends/or51211.c 2011-05-22 19:36:31.000000000 -0400
32380 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32381 u8 tudata[585];
32382 int i;
32383
32384 + pax_track_stack();
32385 +
32386 dprintk("Firmware is %zd bytes\n",fw->size);
32387
32388 /* Get eprom data */
32389 diff -urNp linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c
32390 --- linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c 2011-05-19 00:06:34.000000000 -0400
32391 +++ linux-2.6.39.1/drivers/media/dvb/frontends/s5h1420.c 2011-05-22 19:36:31.000000000 -0400
32392 @@ -870,7 +870,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(
32393 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
32394 }
32395
32396 -static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32397 +static const struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32398 .master_xfer = s5h1420_tuner_i2c_tuner_xfer,
32399 .functionality = s5h1420_tuner_i2c_func,
32400 };
32401 diff -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
32402 --- linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-19 00:06:34.000000000 -0400
32403 +++ linux-2.6.39.1/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-22 19:36:31.000000000 -0400
32404 @@ -212,7 +212,7 @@ static u32 mantis_i2c_func(struct i2c_ad
32405 return I2C_FUNC_SMBUS_EMUL;
32406 }
32407
32408 -static struct i2c_algorithm mantis_algo = {
32409 +static const struct i2c_algorithm mantis_algo = {
32410 .master_xfer = mantis_i2c_xfer,
32411 .functionality = mantis_i2c_func,
32412 };
32413 diff -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
32414 --- linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-19 00:06:34.000000000 -0400
32415 +++ linux-2.6.39.1/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-22 19:36:31.000000000 -0400
32416 @@ -1614,7 +1614,7 @@ static int fe_send_command(struct dvb_fr
32417 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
32418 }
32419
32420 -static struct ttusbdecfe_config fe_config = {
32421 +static const struct ttusbdecfe_config fe_config = {
32422 .send_command = fe_send_command
32423 };
32424
32425 diff -urNp linux-2.6.39.1/drivers/media/radio/radio-cadet.c linux-2.6.39.1/drivers/media/radio/radio-cadet.c
32426 --- linux-2.6.39.1/drivers/media/radio/radio-cadet.c 2011-05-19 00:06:34.000000000 -0400
32427 +++ linux-2.6.39.1/drivers/media/radio/radio-cadet.c 2011-05-22 19:36:31.000000000 -0400
32428 @@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
32429 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32430 mutex_unlock(&dev->lock);
32431
32432 - if (copy_to_user(data, readbuf, i))
32433 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32434 return -EFAULT;
32435 return i;
32436 }
32437 diff -urNp linux-2.6.39.1/drivers/media/radio/radio-si4713.c linux-2.6.39.1/drivers/media/radio/radio-si4713.c
32438 --- linux-2.6.39.1/drivers/media/radio/radio-si4713.c 2011-05-19 00:06:34.000000000 -0400
32439 +++ linux-2.6.39.1/drivers/media/radio/radio-si4713.c 2011-05-22 19:36:31.000000000 -0400
32440 @@ -231,7 +231,7 @@ static long radio_si4713_default(struct
32441 ioctl, cmd, arg);
32442 }
32443
32444 -static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32445 +static const struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32446 .vidioc_enumaudout = radio_si4713_enumaudout,
32447 .vidioc_g_audout = radio_si4713_g_audout,
32448 .vidioc_s_audout = radio_si4713_s_audout,
32449 diff -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
32450 --- linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c 2011-05-19 00:06:34.000000000 -0400
32451 +++ linux-2.6.39.1/drivers/media/rc/ir-lirc-codec.c 2011-05-22 19:36:31.000000000 -0400
32452 @@ -277,7 +277,7 @@ static void ir_lirc_close(void *data)
32453 return;
32454 }
32455
32456 -static struct file_operations lirc_fops = {
32457 +static const struct file_operations lirc_fops = {
32458 .owner = THIS_MODULE,
32459 .write = ir_lirc_transmit_ir,
32460 .unlocked_ioctl = ir_lirc_ioctl,
32461 diff -urNp linux-2.6.39.1/drivers/media/rc/lirc_dev.c linux-2.6.39.1/drivers/media/rc/lirc_dev.c
32462 --- linux-2.6.39.1/drivers/media/rc/lirc_dev.c 2011-05-19 00:06:34.000000000 -0400
32463 +++ linux-2.6.39.1/drivers/media/rc/lirc_dev.c 2011-05-22 19:36:31.000000000 -0400
32464 @@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
32465 }
32466
32467
32468 -static struct file_operations lirc_dev_fops = {
32469 +static const struct file_operations lirc_dev_fops = {
32470 .owner = THIS_MODULE,
32471 .read = lirc_dev_fop_read,
32472 .write = lirc_dev_fop_write,
32473 diff -urNp linux-2.6.39.1/drivers/media/rc/rc-main.c linux-2.6.39.1/drivers/media/rc/rc-main.c
32474 --- linux-2.6.39.1/drivers/media/rc/rc-main.c 2011-05-19 00:06:34.000000000 -0400
32475 +++ linux-2.6.39.1/drivers/media/rc/rc-main.c 2011-05-22 19:36:31.000000000 -0400
32476 @@ -996,7 +996,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
32477
32478 int rc_register_device(struct rc_dev *dev)
32479 {
32480 - static atomic_t devno = ATOMIC_INIT(0);
32481 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
32482 struct rc_map *rc_map;
32483 const char *path;
32484 int rc;
32485 @@ -1019,7 +1019,7 @@ int rc_register_device(struct rc_dev *de
32486 if (dev->close)
32487 dev->input_dev->close = ir_close;
32488
32489 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
32490 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
32491 dev_set_name(&dev->dev, "rc%ld", dev->devno);
32492 dev_set_drvdata(&dev->dev, dev);
32493 rc = device_add(&dev->dev);
32494 diff -urNp linux-2.6.39.1/drivers/media/video/au0828/au0828.h linux-2.6.39.1/drivers/media/video/au0828/au0828.h
32495 --- linux-2.6.39.1/drivers/media/video/au0828/au0828.h 2011-05-19 00:06:34.000000000 -0400
32496 +++ linux-2.6.39.1/drivers/media/video/au0828/au0828.h 2011-05-22 19:36:31.000000000 -0400
32497 @@ -191,7 +191,7 @@ struct au0828_dev {
32498
32499 /* I2C */
32500 struct i2c_adapter i2c_adap;
32501 - struct i2c_algorithm i2c_algo;
32502 + struct i2c_algorithm i2c_algo;
32503 struct i2c_client i2c_client;
32504 u32 i2c_rc;
32505
32506 diff -urNp linux-2.6.39.1/drivers/media/video/cafe_ccic.c linux-2.6.39.1/drivers/media/video/cafe_ccic.c
32507 --- linux-2.6.39.1/drivers/media/video/cafe_ccic.c 2011-05-19 00:06:34.000000000 -0400
32508 +++ linux-2.6.39.1/drivers/media/video/cafe_ccic.c 2011-05-22 19:36:31.000000000 -0400
32509 @@ -520,7 +520,7 @@ static u32 cafe_smbus_func(struct i2c_ad
32510 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
32511 }
32512
32513 -static struct i2c_algorithm cafe_smbus_algo = {
32514 +static const struct i2c_algorithm cafe_smbus_algo = {
32515 .smbus_xfer = cafe_smbus_xfer,
32516 .functionality = cafe_smbus_func
32517 };
32518 diff -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
32519 --- linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-19 00:06:34.000000000 -0400
32520 +++ linux-2.6.39.1/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-22 19:36:31.000000000 -0400
32521 @@ -314,7 +314,7 @@ static struct page *snd_pcm_get_vmalloc_
32522 return vmalloc_to_page(pageptr);
32523 }
32524
32525 -static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32526 +static const struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32527 .open = snd_cx18_pcm_capture_open,
32528 .close = snd_cx18_pcm_capture_close,
32529 .ioctl = snd_cx18_pcm_ioctl,
32530 diff -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
32531 --- linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c 2011-05-19 00:06:34.000000000 -0400
32532 +++ linux-2.6.39.1/drivers/media/video/cx18/cx18-driver.c 2011-05-22 19:36:31.000000000 -0400
32533 @@ -61,7 +61,7 @@ static struct pci_device_id cx18_pci_tbl
32534
32535 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32536
32537 -static atomic_t cx18_instance = ATOMIC_INIT(0);
32538 +static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32539
32540 /* Parameter declarations */
32541 static int cardtype[CX18_MAX_CARDS];
32542 @@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32543 struct i2c_client c;
32544 u8 eedata[256];
32545
32546 + pax_track_stack();
32547 +
32548 memset(&c, 0, sizeof(c));
32549 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32550 c.adapter = &cx->i2c_adap[0];
32551 @@ -892,7 +894,7 @@ static int __devinit cx18_probe(struct p
32552 struct cx18 *cx;
32553
32554 /* FIXME - module parameter arrays constrain max instances */
32555 - i = atomic_inc_return(&cx18_instance) - 1;
32556 + i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32557 if (i >= CX18_MAX_CARDS) {
32558 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32559 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32560 diff -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
32561 --- linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32562 +++ linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32563 @@ -613,7 +613,7 @@ static struct page *snd_pcm_get_vmalloc_
32564 return vmalloc_to_page(pageptr);
32565 }
32566
32567 -static struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32568 +static const struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32569 .open = snd_cx231xx_capture_open,
32570 .close = snd_cx231xx_pcm_close,
32571 .ioctl = snd_pcm_lib_ioctl,
32572 diff -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
32573 --- linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32574 +++ linux-2.6.39.1/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32575 @@ -435,7 +435,7 @@ static u32 functionality(struct i2c_adap
32576 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32577 }
32578
32579 -static struct i2c_algorithm cx231xx_algo = {
32580 +static const struct i2c_algorithm cx231xx_algo = {
32581 .master_xfer = cx231xx_i2c_xfer,
32582 .functionality = functionality,
32583 };
32584 diff -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
32585 --- linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c 2011-05-19 00:06:34.000000000 -0400
32586 +++ linux-2.6.39.1/drivers/media/video/cx23885/cx23885-input.c 2011-05-22 19:36:31.000000000 -0400
32587 @@ -53,6 +53,8 @@ static void cx23885_input_process_measur
32588 bool handle = false;
32589 struct ir_raw_event ir_core_event[64];
32590
32591 + pax_track_stack();
32592 +
32593 do {
32594 num = 0;
32595 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
32596 diff -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
32597 --- linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c 2011-05-19 00:06:34.000000000 -0400
32598 +++ linux-2.6.39.1/drivers/media/video/cx88/cx88-alsa.c 2011-05-22 19:36:31.000000000 -0400
32599 @@ -519,7 +519,7 @@ static struct page *snd_cx88_page(struct
32600 /*
32601 * operators
32602 */
32603 -static struct snd_pcm_ops snd_cx88_pcm_ops = {
32604 +static const struct snd_pcm_ops snd_cx88_pcm_ops = {
32605 .open = snd_cx88_pcm_open,
32606 .close = snd_cx88_close,
32607 .ioctl = snd_pcm_lib_ioctl,
32608 diff -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
32609 --- linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-19 00:06:34.000000000 -0400
32610 +++ linux-2.6.39.1/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-22 19:36:31.000000000 -0400
32611 @@ -99,7 +99,7 @@ struct ccdc_hw_device {
32612 /* module owner */
32613 struct module *owner;
32614 /* hw ops */
32615 - struct ccdc_hw_ops hw_ops;
32616 + const struct ccdc_hw_ops hw_ops;
32617 };
32618
32619 /* Used by CCDC module to register & unregister with vpfe capture driver */
32620 diff -urNp linux-2.6.39.1/drivers/media/video/davinci/vpss.c linux-2.6.39.1/drivers/media/video/davinci/vpss.c
32621 --- linux-2.6.39.1/drivers/media/video/davinci/vpss.c 2011-05-19 00:06:34.000000000 -0400
32622 +++ linux-2.6.39.1/drivers/media/video/davinci/vpss.c 2011-05-22 19:36:31.000000000 -0400
32623 @@ -103,7 +103,7 @@ struct vpss_oper_config {
32624 __iomem void *vpss_regs_base1;
32625 enum vpss_platform_type platform;
32626 spinlock_t vpss_lock;
32627 - struct vpss_hw_ops hw_ops;
32628 + const struct vpss_hw_ops hw_ops;
32629 };
32630
32631 static struct vpss_oper_config oper_cfg;
32632 diff -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
32633 --- linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32634 +++ linux-2.6.39.1/drivers/media/video/em28xx/em28xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32635 @@ -432,7 +432,7 @@ static struct page *snd_pcm_get_vmalloc_
32636 return vmalloc_to_page(pageptr);
32637 }
32638
32639 -static struct snd_pcm_ops snd_em28xx_pcm_capture = {
32640 +static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
32641 .open = snd_em28xx_capture_open,
32642 .close = snd_em28xx_pcm_close,
32643 .ioctl = snd_pcm_lib_ioctl,
32644 diff -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
32645 --- linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32646 +++ linux-2.6.39.1/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32647 @@ -451,7 +451,7 @@ static u32 functionality(struct i2c_adap
32648 return I2C_FUNC_SMBUS_EMUL;
32649 }
32650
32651 -static struct i2c_algorithm em28xx_algo = {
32652 +static const struct i2c_algorithm em28xx_algo = {
32653 .master_xfer = em28xx_i2c_xfer,
32654 .functionality = functionality,
32655 };
32656 diff -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
32657 --- linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-19 00:06:34.000000000 -0400
32658 +++ linux-2.6.39.1/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-22 19:36:31.000000000 -0400
32659 @@ -179,7 +179,7 @@ static u32 hdpvr_functionality(struct i2
32660 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
32661 }
32662
32663 -static struct i2c_algorithm hdpvr_algo = {
32664 +static const struct i2c_algorithm hdpvr_algo = {
32665 .master_xfer = hdpvr_transfer,
32666 .functionality = hdpvr_functionality,
32667 };
32668 diff -urNp linux-2.6.39.1/drivers/media/video/imx074.c linux-2.6.39.1/drivers/media/video/imx074.c
32669 --- linux-2.6.39.1/drivers/media/video/imx074.c 2011-05-19 00:06:34.000000000 -0400
32670 +++ linux-2.6.39.1/drivers/media/video/imx074.c 2011-05-22 19:36:31.000000000 -0400
32671 @@ -267,7 +267,7 @@ static int imx074_g_chip_ident(struct v4
32672 return 0;
32673 }
32674
32675 -static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32676 +static const struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32677 .s_stream = imx074_s_stream,
32678 .s_mbus_fmt = imx074_s_fmt,
32679 .g_mbus_fmt = imx074_g_fmt,
32680 @@ -277,7 +277,7 @@ static struct v4l2_subdev_video_ops imx0
32681 .cropcap = imx074_cropcap,
32682 };
32683
32684 -static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32685 +static const struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32686 .g_chip_ident = imx074_g_chip_ident,
32687 };
32688
32689 diff -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
32690 --- linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c 2011-05-19 00:06:34.000000000 -0400
32691 +++ linux-2.6.39.1/drivers/media/video/ivtv/ivtv-driver.c 2011-05-22 19:36:31.000000000 -0400
32692 @@ -80,7 +80,7 @@ static struct pci_device_id ivtv_pci_tbl
32693 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32694
32695 /* ivtv instance counter */
32696 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
32697 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32698
32699 /* Parameter declarations */
32700 static int cardtype[IVTV_MAX_CARDS];
32701 diff -urNp linux-2.6.39.1/drivers/media/video/mt9m001.c linux-2.6.39.1/drivers/media/video/mt9m001.c
32702 --- linux-2.6.39.1/drivers/media/video/mt9m001.c 2011-05-19 00:06:34.000000000 -0400
32703 +++ linux-2.6.39.1/drivers/media/video/mt9m001.c 2011-05-22 19:36:31.000000000 -0400
32704 @@ -691,7 +691,7 @@ static int mt9m001_g_skip_top_lines(stru
32705 return 0;
32706 }
32707
32708 -static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32709 +static const struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32710 .g_ctrl = mt9m001_g_ctrl,
32711 .s_ctrl = mt9m001_s_ctrl,
32712 .g_chip_ident = mt9m001_g_chip_ident,
32713 @@ -714,7 +714,7 @@ static int mt9m001_enum_fmt(struct v4l2_
32714 return 0;
32715 }
32716
32717 -static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32718 +static const struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32719 .s_stream = mt9m001_s_stream,
32720 .s_mbus_fmt = mt9m001_s_fmt,
32721 .g_mbus_fmt = mt9m001_g_fmt,
32722 @@ -725,7 +725,7 @@ static struct v4l2_subdev_video_ops mt9m
32723 .enum_mbus_fmt = mt9m001_enum_fmt,
32724 };
32725
32726 -static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32727 +static const struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32728 .g_skip_top_lines = mt9m001_g_skip_top_lines,
32729 };
32730
32731 diff -urNp linux-2.6.39.1/drivers/media/video/mt9t031.c linux-2.6.39.1/drivers/media/video/mt9t031.c
32732 --- linux-2.6.39.1/drivers/media/video/mt9t031.c 2011-05-19 00:06:34.000000000 -0400
32733 +++ linux-2.6.39.1/drivers/media/video/mt9t031.c 2011-05-22 19:36:31.000000000 -0400
32734 @@ -725,7 +725,7 @@ static int mt9t031_runtime_resume(struct
32735 return 0;
32736 }
32737
32738 -static struct dev_pm_ops mt9t031_dev_pm_ops = {
32739 +static const struct dev_pm_ops mt9t031_dev_pm_ops = {
32740 .runtime_suspend = mt9t031_runtime_suspend,
32741 .runtime_resume = mt9t031_runtime_resume,
32742 };
32743 @@ -788,7 +788,7 @@ static int mt9t031_g_skip_top_lines(stru
32744 return 0;
32745 }
32746
32747 -static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32748 +static const struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32749 .g_ctrl = mt9t031_g_ctrl,
32750 .s_ctrl = mt9t031_s_ctrl,
32751 .g_chip_ident = mt9t031_g_chip_ident,
32752 @@ -808,7 +808,7 @@ static int mt9t031_enum_fmt(struct v4l2_
32753 return 0;
32754 }
32755
32756 -static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32757 +static const struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32758 .s_stream = mt9t031_s_stream,
32759 .s_mbus_fmt = mt9t031_s_fmt,
32760 .g_mbus_fmt = mt9t031_g_fmt,
32761 @@ -819,7 +819,7 @@ static struct v4l2_subdev_video_ops mt9t
32762 .enum_mbus_fmt = mt9t031_enum_fmt,
32763 };
32764
32765 -static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32766 +static const struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32767 .g_skip_top_lines = mt9t031_g_skip_top_lines,
32768 };
32769
32770 diff -urNp linux-2.6.39.1/drivers/media/video/mt9v022.c linux-2.6.39.1/drivers/media/video/mt9v022.c
32771 --- linux-2.6.39.1/drivers/media/video/mt9v022.c 2011-05-19 00:06:34.000000000 -0400
32772 +++ linux-2.6.39.1/drivers/media/video/mt9v022.c 2011-05-22 19:36:31.000000000 -0400
32773 @@ -825,7 +825,7 @@ static int mt9v022_g_skip_top_lines(stru
32774 return 0;
32775 }
32776
32777 -static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32778 +static const struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32779 .g_ctrl = mt9v022_g_ctrl,
32780 .s_ctrl = mt9v022_s_ctrl,
32781 .g_chip_ident = mt9v022_g_chip_ident,
32782 @@ -848,7 +848,7 @@ static int mt9v022_enum_fmt(struct v4l2_
32783 return 0;
32784 }
32785
32786 -static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32787 +static const struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32788 .s_stream = mt9v022_s_stream,
32789 .s_mbus_fmt = mt9v022_s_fmt,
32790 .g_mbus_fmt = mt9v022_g_fmt,
32791 @@ -859,7 +859,7 @@ static struct v4l2_subdev_video_ops mt9v
32792 .enum_mbus_fmt = mt9v022_enum_fmt,
32793 };
32794
32795 -static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32796 +static const struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32797 .g_skip_top_lines = mt9v022_g_skip_top_lines,
32798 };
32799
32800 diff -urNp linux-2.6.39.1/drivers/media/video/mx2_camera.c linux-2.6.39.1/drivers/media/video/mx2_camera.c
32801 --- linux-2.6.39.1/drivers/media/video/mx2_camera.c 2011-05-19 00:06:34.000000000 -0400
32802 +++ linux-2.6.39.1/drivers/media/video/mx2_camera.c 2011-05-22 19:36:31.000000000 -0400
32803 @@ -668,7 +668,7 @@ static void mx2_videobuf_release(struct
32804 free_buffer(vq, buf);
32805 }
32806
32807 -static struct videobuf_queue_ops mx2_videobuf_ops = {
32808 +static const struct videobuf_queue_ops mx2_videobuf_ops = {
32809 .buf_setup = mx2_videobuf_setup,
32810 .buf_prepare = mx2_videobuf_prepare,
32811 .buf_queue = mx2_videobuf_queue,
32812 diff -urNp linux-2.6.39.1/drivers/media/video/omap24xxcam.c linux-2.6.39.1/drivers/media/video/omap24xxcam.c
32813 --- linux-2.6.39.1/drivers/media/video/omap24xxcam.c 2011-05-19 00:06:34.000000000 -0400
32814 +++ linux-2.6.39.1/drivers/media/video/omap24xxcam.c 2011-05-22 19:36:31.000000000 -0400
32815 @@ -403,7 +403,7 @@ static void omap24xxcam_vbq_complete(str
32816 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32817
32818 do_gettimeofday(&vb->ts);
32819 - vb->field_count = atomic_add_return(2, &fh->field_count);
32820 + vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32821 if (csr & csr_error) {
32822 vb->state = VIDEOBUF_ERROR;
32823 if (!atomic_read(&fh->cam->in_reset)) {
32824 diff -urNp linux-2.6.39.1/drivers/media/video/omap24xxcam.h linux-2.6.39.1/drivers/media/video/omap24xxcam.h
32825 --- linux-2.6.39.1/drivers/media/video/omap24xxcam.h 2011-05-19 00:06:34.000000000 -0400
32826 +++ linux-2.6.39.1/drivers/media/video/omap24xxcam.h 2011-05-22 19:36:31.000000000 -0400
32827 @@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32828 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32829 struct videobuf_queue vbq;
32830 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32831 - atomic_t field_count; /* field counter for videobuf_buffer */
32832 + atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32833 /* accessing cam here doesn't need serialisation: it's constant */
32834 struct omap24xxcam_device *cam;
32835 };
32836 diff -urNp linux-2.6.39.1/drivers/media/video/omap3isp/isp.h linux-2.6.39.1/drivers/media/video/omap3isp/isp.h
32837 --- linux-2.6.39.1/drivers/media/video/omap3isp/isp.h 2011-05-19 00:06:34.000000000 -0400
32838 +++ linux-2.6.39.1/drivers/media/video/omap3isp/isp.h 2011-05-22 19:36:31.000000000 -0400
32839 @@ -290,7 +290,7 @@ struct isp_device {
32840
32841 struct iommu *iommu;
32842
32843 - struct isp_platform_callback platform_cb;
32844 + const struct isp_platform_callback platform_cb;
32845 };
32846
32847 #define v4l2_dev_to_isp_device(dev) \
32848 diff -urNp linux-2.6.39.1/drivers/media/video/ov2640.c linux-2.6.39.1/drivers/media/video/ov2640.c
32849 --- linux-2.6.39.1/drivers/media/video/ov2640.c 2011-05-19 00:06:34.000000000 -0400
32850 +++ linux-2.6.39.1/drivers/media/video/ov2640.c 2011-05-22 19:36:31.000000000 -0400
32851 @@ -1080,7 +1080,7 @@ static struct soc_camera_ops ov2640_ops
32852 .num_controls = ARRAY_SIZE(ov2640_controls),
32853 };
32854
32855 -static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32856 +static const struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32857 .g_ctrl = ov2640_g_ctrl,
32858 .s_ctrl = ov2640_s_ctrl,
32859 .g_chip_ident = ov2640_g_chip_ident,
32860 @@ -1090,7 +1090,7 @@ static struct v4l2_subdev_core_ops ov264
32861 #endif
32862 };
32863
32864 -static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32865 +static const struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32866 .s_stream = ov2640_s_stream,
32867 .g_mbus_fmt = ov2640_g_fmt,
32868 .s_mbus_fmt = ov2640_s_fmt,
32869 diff -urNp linux-2.6.39.1/drivers/media/video/ov772x.c linux-2.6.39.1/drivers/media/video/ov772x.c
32870 --- linux-2.6.39.1/drivers/media/video/ov772x.c 2011-05-19 00:06:34.000000000 -0400
32871 +++ linux-2.6.39.1/drivers/media/video/ov772x.c 2011-05-22 19:36:31.000000000 -0400
32872 @@ -1079,7 +1079,7 @@ static struct soc_camera_ops ov772x_ops
32873 .num_controls = ARRAY_SIZE(ov772x_controls),
32874 };
32875
32876 -static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32877 +static const struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32878 .g_ctrl = ov772x_g_ctrl,
32879 .s_ctrl = ov772x_s_ctrl,
32880 .g_chip_ident = ov772x_g_chip_ident,
32881 @@ -1099,7 +1099,7 @@ static int ov772x_enum_fmt(struct v4l2_s
32882 return 0;
32883 }
32884
32885 -static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32886 +static const struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32887 .s_stream = ov772x_s_stream,
32888 .g_mbus_fmt = ov772x_g_fmt,
32889 .s_mbus_fmt = ov772x_s_fmt,
32890 diff -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
32891 --- linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-19 00:06:34.000000000 -0400
32892 +++ linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-22 19:36:31.000000000 -0400
32893 @@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
32894 u8 *eeprom;
32895 struct tveeprom tvdata;
32896
32897 + pax_track_stack();
32898 +
32899 memset(&tvdata,0,sizeof(tvdata));
32900
32901 eeprom = pvr2_eeprom_fetch(hdw);
32902 diff -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
32903 --- linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-19 00:06:34.000000000 -0400
32904 +++ linux-2.6.39.1/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-22 19:36:31.000000000 -0400
32905 @@ -527,7 +527,7 @@ static u32 pvr2_i2c_functionality(struct
32906 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32907 }
32908
32909 -static struct i2c_algorithm pvr2_i2c_algo_template = {
32910 +static const struct i2c_algorithm pvr2_i2c_algo_template = {
32911 .master_xfer = pvr2_i2c_xfer,
32912 .functionality = pvr2_i2c_functionality,
32913 };
32914 diff -urNp linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c
32915 --- linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c 2011-05-19 00:06:34.000000000 -0400
32916 +++ linux-2.6.39.1/drivers/media/video/rj54n1cb0c.c 2011-05-22 19:36:31.000000000 -0400
32917 @@ -1327,7 +1327,7 @@ static int rj54n1_s_ctrl(struct v4l2_sub
32918 return 0;
32919 }
32920
32921 -static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
32922 +static const struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
32923 .g_ctrl = rj54n1_g_ctrl,
32924 .s_ctrl = rj54n1_s_ctrl,
32925 .g_chip_ident = rj54n1_g_chip_ident,
32926 @@ -1337,7 +1337,7 @@ static struct v4l2_subdev_core_ops rj54n
32927 #endif
32928 };
32929
32930 -static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
32931 +static const struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
32932 .s_stream = rj54n1_s_stream,
32933 .s_mbus_fmt = rj54n1_s_fmt,
32934 .g_mbus_fmt = rj54n1_g_fmt,
32935 diff -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
32936 --- linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-19 00:06:34.000000000 -0400
32937 +++ linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-22 19:36:31.000000000 -0400
32938 @@ -376,7 +376,7 @@ static void fimc_unlock(struct vb2_queue
32939 mutex_unlock(&ctx->fimc_dev->lock);
32940 }
32941
32942 -static struct vb2_ops fimc_capture_qops = {
32943 +static const struct vb2_ops fimc_capture_qops = {
32944 .queue_setup = queue_setup,
32945 .buf_prepare = buffer_prepare,
32946 .buf_queue = buffer_queue,
32947 diff -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
32948 --- linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-19 00:06:34.000000000 -0400
32949 +++ linux-2.6.39.1/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-22 19:36:31.000000000 -0400
32950 @@ -768,7 +768,7 @@ static void fimc_unlock(struct vb2_queue
32951 mutex_unlock(&ctx->fimc_dev->lock);
32952 }
32953
32954 -static struct vb2_ops fimc_qops = {
32955 +static const struct vb2_ops fimc_qops = {
32956 .queue_setup = fimc_queue_setup,
32957 .buf_prepare = fimc_buf_prepare,
32958 .buf_queue = fimc_buf_queue,
32959 diff -urNp linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c
32960 --- linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c 2011-05-19 00:06:34.000000000 -0400
32961 +++ linux-2.6.39.1/drivers/media/video/saa7134/saa6752hs.c 2011-05-22 19:36:31.000000000 -0400
32962 @@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_su
32963 unsigned char localPAT[256];
32964 unsigned char localPMT[256];
32965
32966 + pax_track_stack();
32967 +
32968 /* Set video format - must be done first as it resets other settings */
32969 set_reg8(client, 0x41, h->video_format);
32970
32971 diff -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
32972 --- linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-19 00:06:34.000000000 -0400
32973 +++ linux-2.6.39.1/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-22 19:36:31.000000000 -0400
32974 @@ -808,7 +808,7 @@ static struct page *snd_card_saa7134_pag
32975 * ALSA capture callbacks definition
32976 */
32977
32978 -static struct snd_pcm_ops snd_card_saa7134_capture_ops = {
32979 +static const struct snd_pcm_ops snd_card_saa7134_capture_ops = {
32980 .open = snd_card_saa7134_capture_open,
32981 .close = snd_card_saa7134_capture_close,
32982 .ioctl = snd_pcm_lib_ioctl,
32983 diff -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
32984 --- linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-19 00:06:34.000000000 -0400
32985 +++ linux-2.6.39.1/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-22 19:36:31.000000000 -0400
32986 @@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_d
32987 u8 tmp[512];
32988 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32989
32990 + pax_track_stack();
32991 +
32992 /* While any outstand message on the bus exists... */
32993 do {
32994
32995 @@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
32996 u8 tmp[512];
32997 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32998
32999 + pax_track_stack();
33000 +
33001 while (loop) {
33002
33003 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
33004 diff -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
33005 --- linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c 2011-05-19 00:06:34.000000000 -0400
33006 +++ linux-2.6.39.1/drivers/media/video/sh_mobile_csi2.c 2011-05-22 19:36:31.000000000 -0400
33007 @@ -127,12 +127,12 @@ static int sh_csi2_s_fmt(struct v4l2_sub
33008 return 0;
33009 }
33010
33011 -static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
33012 +static const struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
33013 .s_mbus_fmt = sh_csi2_s_fmt,
33014 .try_mbus_fmt = sh_csi2_try_fmt,
33015 };
33016
33017 -static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
33018 +static const struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
33019
33020 static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
33021 .core = &sh_csi2_subdev_core_ops,
33022 diff -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
33023 --- linux-2.6.39.1/drivers/media/video/soc_camera_platform.c 2011-05-19 00:06:34.000000000 -0400
33024 +++ linux-2.6.39.1/drivers/media/video/soc_camera_platform.c 2011-05-22 19:36:31.000000000 -0400
33025 @@ -70,7 +70,7 @@ static int soc_camera_platform_fill_fmt(
33026 return 0;
33027 }
33028
33029 -static struct v4l2_subdev_core_ops platform_subdev_core_ops;
33030 +static const struct v4l2_subdev_core_ops platform_subdev_core_ops;
33031
33032 static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
33033 enum v4l2_mbus_pixelcode *code)
33034 @@ -115,7 +115,7 @@ static int soc_camera_platform_cropcap(s
33035 return 0;
33036 }
33037
33038 -static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33039 +static const struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33040 .s_stream = soc_camera_platform_s_stream,
33041 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
33042 .cropcap = soc_camera_platform_cropcap,
33043 diff -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
33044 --- linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c 2011-05-19 00:06:34.000000000 -0400
33045 +++ linux-2.6.39.1/drivers/media/video/tlg2300/pd-alsa.c 2011-05-22 19:36:31.000000000 -0400
33046 @@ -265,7 +265,7 @@ static struct page *snd_pcm_pd_get_page(
33047 return vmalloc_to_page(pageptr);
33048 }
33049
33050 -static struct snd_pcm_ops pcm_capture_ops = {
33051 +static const struct snd_pcm_ops pcm_capture_ops = {
33052 .open = snd_pd_capture_open,
33053 .close = snd_pd_pcm_close,
33054 .ioctl = snd_pcm_lib_ioctl,
33055 diff -urNp linux-2.6.39.1/drivers/media/video/tw9910.c linux-2.6.39.1/drivers/media/video/tw9910.c
33056 --- linux-2.6.39.1/drivers/media/video/tw9910.c 2011-05-19 00:06:34.000000000 -0400
33057 +++ linux-2.6.39.1/drivers/media/video/tw9910.c 2011-05-22 19:36:31.000000000 -0400
33058 @@ -894,7 +894,7 @@ static struct soc_camera_ops tw9910_ops
33059 .enum_input = tw9910_enum_input,
33060 };
33061
33062 -static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33063 +static const struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33064 .g_chip_ident = tw9910_g_chip_ident,
33065 .s_std = tw9910_s_std,
33066 #ifdef CONFIG_VIDEO_ADV_DEBUG
33067 @@ -913,7 +913,7 @@ static int tw9910_enum_fmt(struct v4l2_s
33068 return 0;
33069 }
33070
33071 -static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33072 +static const struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33073 .s_stream = tw9910_s_stream,
33074 .g_mbus_fmt = tw9910_g_fmt,
33075 .s_mbus_fmt = tw9910_s_fmt,
33076 diff -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
33077 --- linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c 2011-05-19 00:06:34.000000000 -0400
33078 +++ linux-2.6.39.1/drivers/media/video/usbvision/usbvision-core.c 2011-05-22 19:36:31.000000000 -0400
33079 @@ -799,6 +799,8 @@ static enum parse_state usbvision_parse_
33080 unsigned char rv, gv, bv;
33081 static unsigned char *Y, *U, *V;
33082
33083 + pax_track_stack();
33084 +
33085 frame = usbvision->cur_frame;
33086 image_size = frame->frmwidth * frame->frmheight;
33087 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
33088 diff -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
33089 --- linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-19 00:06:34.000000000 -0400
33090 +++ linux-2.6.39.1/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-22 19:36:31.000000000 -0400
33091 @@ -189,7 +189,7 @@ static u32 functionality(struct i2c_adap
33092
33093 /* -----exported algorithm data: ------------------------------------- */
33094
33095 -static struct i2c_algorithm usbvision_algo = {
33096 +static const struct i2c_algorithm usbvision_algo = {
33097 .master_xfer = usbvision_i2c_xfer,
33098 .smbus_xfer = NULL,
33099 .functionality = functionality,
33100 diff -urNp linux-2.6.39.1/drivers/media/video/v4l2-device.c linux-2.6.39.1/drivers/media/video/v4l2-device.c
33101 --- linux-2.6.39.1/drivers/media/video/v4l2-device.c 2011-05-19 00:06:34.000000000 -0400
33102 +++ linux-2.6.39.1/drivers/media/video/v4l2-device.c 2011-05-22 19:36:31.000000000 -0400
33103 @@ -71,9 +71,9 @@ int v4l2_device_put(struct v4l2_device *
33104 EXPORT_SYMBOL_GPL(v4l2_device_put);
33105
33106 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
33107 - atomic_t *instance)
33108 + atomic_unchecked_t *instance)
33109 {
33110 - int num = atomic_inc_return(instance) - 1;
33111 + int num = atomic_inc_return_unchecked(instance) - 1;
33112 int len = strlen(basename);
33113
33114 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33115 diff -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
33116 --- linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c 2011-05-19 00:06:34.000000000 -0400
33117 +++ linux-2.6.39.1/drivers/media/video/videobuf-dma-sg.c 2011-05-22 19:36:31.000000000 -0400
33118 @@ -606,6 +606,8 @@ void *videobuf_sg_alloc(size_t size)
33119 {
33120 struct videobuf_queue q;
33121
33122 + pax_track_stack();
33123 +
33124 /* Required to make generic handler to call __videobuf_alloc */
33125 q.int_ops = &sg_ops;
33126
33127 diff -urNp linux-2.6.39.1/drivers/message/fusion/mptbase.c linux-2.6.39.1/drivers/message/fusion/mptbase.c
33128 --- linux-2.6.39.1/drivers/message/fusion/mptbase.c 2011-05-19 00:06:34.000000000 -0400
33129 +++ linux-2.6.39.1/drivers/message/fusion/mptbase.c 2011-05-22 19:41:37.000000000 -0400
33130 @@ -143,7 +143,7 @@ static int MptDriverClass[MPT_MAX_PRO
33131 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33132 /* Reset handler lookup table */
33133 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33134 -static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33135 +static const struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33136
33137 #ifdef CONFIG_PROC_FS
33138 static struct proc_dir_entry *mpt_proc_root_dir;
33139 @@ -772,7 +772,7 @@ mpt_reset_deregister(u8 cb_idx)
33140 * @cb_idx: MPT protocol driver index
33141 */
33142 int
33143 -mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33144 +mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33145 {
33146 MPT_ADAPTER *ioc;
33147 const struct pci_device_id *id;
33148 @@ -801,7 +801,7 @@ mpt_device_driver_register(struct mpt_pc
33149 void
33150 mpt_device_driver_deregister(u8 cb_idx)
33151 {
33152 - struct mpt_pci_driver *dd_cbfunc;
33153 + const struct mpt_pci_driver *dd_cbfunc;
33154 MPT_ADAPTER *ioc;
33155
33156 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
33157 @@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
33158 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33159 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33160
33161 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33162 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33163 +#else
33164 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33165 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33166 +#endif
33167 +
33168 /*
33169 * Rounding UP to nearest 4-kB boundary here...
33170 */
33171 diff -urNp linux-2.6.39.1/drivers/message/fusion/mptbase.h linux-2.6.39.1/drivers/message/fusion/mptbase.h
33172 --- linux-2.6.39.1/drivers/message/fusion/mptbase.h 2011-05-19 00:06:34.000000000 -0400
33173 +++ linux-2.6.39.1/drivers/message/fusion/mptbase.h 2011-05-22 19:36:31.000000000 -0400
33174 @@ -908,7 +908,7 @@ extern int mpt_event_register(u8 cb_idx
33175 extern void mpt_event_deregister(u8 cb_idx);
33176 extern int mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func);
33177 extern void mpt_reset_deregister(u8 cb_idx);
33178 -extern int mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33179 +extern int mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33180 extern void mpt_device_driver_deregister(u8 cb_idx);
33181 extern MPT_FRAME_HDR *mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc);
33182 extern void mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
33183 diff -urNp linux-2.6.39.1/drivers/message/fusion/mptctl.c linux-2.6.39.1/drivers/message/fusion/mptctl.c
33184 --- linux-2.6.39.1/drivers/message/fusion/mptctl.c 2011-05-19 00:06:34.000000000 -0400
33185 +++ linux-2.6.39.1/drivers/message/fusion/mptctl.c 2011-05-22 19:36:31.000000000 -0400
33186 @@ -3000,7 +3000,7 @@ mptctl_remove(struct pci_dev *pdev)
33187 {
33188 }
33189
33190 -static struct mpt_pci_driver mptctl_driver = {
33191 +static const struct mpt_pci_driver mptctl_driver = {
33192 .probe = mptctl_probe,
33193 .remove = mptctl_remove,
33194 };
33195 diff -urNp linux-2.6.39.1/drivers/message/fusion/mptsas.c linux-2.6.39.1/drivers/message/fusion/mptsas.c
33196 --- linux-2.6.39.1/drivers/message/fusion/mptsas.c 2011-05-19 00:06:34.000000000 -0400
33197 +++ linux-2.6.39.1/drivers/message/fusion/mptsas.c 2011-05-22 19:36:31.000000000 -0400
33198 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
33199 return 0;
33200 }
33201
33202 +static inline void
33203 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33204 +{
33205 + if (phy_info->port_details) {
33206 + phy_info->port_details->rphy = rphy;
33207 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33208 + ioc->name, rphy));
33209 + }
33210 +
33211 + if (rphy) {
33212 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33213 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33214 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33215 + ioc->name, rphy, rphy->dev.release));
33216 + }
33217 +}
33218 +
33219 /* no mutex */
33220 static void
33221 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33222 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33223 return NULL;
33224 }
33225
33226 -static inline void
33227 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33228 -{
33229 - if (phy_info->port_details) {
33230 - phy_info->port_details->rphy = rphy;
33231 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33232 - ioc->name, rphy));
33233 - }
33234 -
33235 - if (rphy) {
33236 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33237 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33238 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33239 - ioc->name, rphy, rphy->dev.release));
33240 - }
33241 -}
33242 -
33243 static inline struct sas_port *
33244 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33245 {
33246 diff -urNp linux-2.6.39.1/drivers/message/fusion/mptscsih.c linux-2.6.39.1/drivers/message/fusion/mptscsih.c
33247 --- linux-2.6.39.1/drivers/message/fusion/mptscsih.c 2011-05-19 00:06:34.000000000 -0400
33248 +++ linux-2.6.39.1/drivers/message/fusion/mptscsih.c 2011-05-22 19:36:31.000000000 -0400
33249 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33250
33251 h = shost_priv(SChost);
33252
33253 - if (h) {
33254 - if (h->info_kbuf == NULL)
33255 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33256 - return h->info_kbuf;
33257 - h->info_kbuf[0] = '\0';
33258 + if (!h)
33259 + return NULL;
33260
33261 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33262 - h->info_kbuf[size-1] = '\0';
33263 - }
33264 + if (h->info_kbuf == NULL)
33265 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33266 + return h->info_kbuf;
33267 + h->info_kbuf[0] = '\0';
33268 +
33269 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33270 + h->info_kbuf[size-1] = '\0';
33271
33272 return h->info_kbuf;
33273 }
33274 diff -urNp linux-2.6.39.1/drivers/message/i2o/i2o_config.c linux-2.6.39.1/drivers/message/i2o/i2o_config.c
33275 --- linux-2.6.39.1/drivers/message/i2o/i2o_config.c 2011-05-19 00:06:34.000000000 -0400
33276 +++ linux-2.6.39.1/drivers/message/i2o/i2o_config.c 2011-05-22 19:36:31.000000000 -0400
33277 @@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned lon
33278 struct i2o_message *msg;
33279 unsigned int iop;
33280
33281 + pax_track_stack();
33282 +
33283 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
33284 return -EFAULT;
33285
33286 diff -urNp linux-2.6.39.1/drivers/message/i2o/i2o_proc.c linux-2.6.39.1/drivers/message/i2o/i2o_proc.c
33287 --- linux-2.6.39.1/drivers/message/i2o/i2o_proc.c 2011-05-19 00:06:34.000000000 -0400
33288 +++ linux-2.6.39.1/drivers/message/i2o/i2o_proc.c 2011-05-22 19:36:31.000000000 -0400
33289 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33290 "Array Controller Device"
33291 };
33292
33293 -static char *chtostr(u8 * chars, int n)
33294 -{
33295 - char tmp[256];
33296 - tmp[0] = 0;
33297 - return strncat(tmp, (char *)chars, n);
33298 -}
33299 -
33300 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33301 char *group)
33302 {
33303 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
33304
33305 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33306 seq_printf(seq, "%-#8x", ddm_table.module_id);
33307 - seq_printf(seq, "%-29s",
33308 - chtostr(ddm_table.module_name_version, 28));
33309 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33310 seq_printf(seq, "%9d ", ddm_table.data_size);
33311 seq_printf(seq, "%8d", ddm_table.code_size);
33312
33313 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
33314
33315 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33316 seq_printf(seq, "%-#8x", dst->module_id);
33317 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33318 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33319 + seq_printf(seq, "%-.28s", dst->module_name_version);
33320 + seq_printf(seq, "%-.8s", dst->date);
33321 seq_printf(seq, "%8d ", dst->module_size);
33322 seq_printf(seq, "%8d ", dst->mpb_size);
33323 seq_printf(seq, "0x%04x", dst->module_flags);
33324 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
33325 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33326 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33327 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33328 - seq_printf(seq, "Vendor info : %s\n",
33329 - chtostr((u8 *) (work32 + 2), 16));
33330 - seq_printf(seq, "Product info : %s\n",
33331 - chtostr((u8 *) (work32 + 6), 16));
33332 - seq_printf(seq, "Description : %s\n",
33333 - chtostr((u8 *) (work32 + 10), 16));
33334 - seq_printf(seq, "Product rev. : %s\n",
33335 - chtostr((u8 *) (work32 + 14), 8));
33336 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33337 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33338 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33339 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33340
33341 seq_printf(seq, "Serial number : ");
33342 print_serial_number(seq, (u8 *) (work32 + 16),
33343 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
33344 }
33345
33346 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33347 - seq_printf(seq, "Module name : %s\n",
33348 - chtostr(result.module_name, 24));
33349 - seq_printf(seq, "Module revision : %s\n",
33350 - chtostr(result.module_rev, 8));
33351 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33352 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33353
33354 seq_printf(seq, "Serial number : ");
33355 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33356 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
33357 return 0;
33358 }
33359
33360 - seq_printf(seq, "Device name : %s\n",
33361 - chtostr(result.device_name, 64));
33362 - seq_printf(seq, "Service name : %s\n",
33363 - chtostr(result.service_name, 64));
33364 - seq_printf(seq, "Physical name : %s\n",
33365 - chtostr(result.physical_location, 64));
33366 - seq_printf(seq, "Instance number : %s\n",
33367 - chtostr(result.instance_number, 4));
33368 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33369 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33370 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33371 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33372
33373 return 0;
33374 }
33375 diff -urNp linux-2.6.39.1/drivers/message/i2o/iop.c linux-2.6.39.1/drivers/message/i2o/iop.c
33376 --- linux-2.6.39.1/drivers/message/i2o/iop.c 2011-05-19 00:06:34.000000000 -0400
33377 +++ linux-2.6.39.1/drivers/message/i2o/iop.c 2011-05-22 19:36:31.000000000 -0400
33378 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
33379
33380 spin_lock_irqsave(&c->context_list_lock, flags);
33381
33382 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33383 - atomic_inc(&c->context_list_counter);
33384 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33385 + atomic_inc_unchecked(&c->context_list_counter);
33386
33387 - entry->context = atomic_read(&c->context_list_counter);
33388 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33389
33390 list_add(&entry->list, &c->context_list);
33391
33392 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(voi
33393
33394 #if BITS_PER_LONG == 64
33395 spin_lock_init(&c->context_list_lock);
33396 - atomic_set(&c->context_list_counter, 0);
33397 + atomic_set_unchecked(&c->context_list_counter, 0);
33398 INIT_LIST_HEAD(&c->context_list);
33399 #endif
33400
33401 diff -urNp linux-2.6.39.1/drivers/mfd/ab3100-core.c linux-2.6.39.1/drivers/mfd/ab3100-core.c
33402 --- linux-2.6.39.1/drivers/mfd/ab3100-core.c 2011-05-19 00:06:34.000000000 -0400
33403 +++ linux-2.6.39.1/drivers/mfd/ab3100-core.c 2011-05-22 19:36:31.000000000 -0400
33404 @@ -385,7 +385,7 @@ static int ab3100_event_registers_startu
33405 return 0;
33406 }
33407
33408 -static struct abx500_ops ab3100_ops = {
33409 +static const struct abx500_ops ab3100_ops = {
33410 .get_chip_id = ab3100_get_chip_id,
33411 .set_register = set_register_interruptible,
33412 .get_register = get_register_interruptible,
33413 diff -urNp linux-2.6.39.1/drivers/mfd/ab3550-core.c linux-2.6.39.1/drivers/mfd/ab3550-core.c
33414 --- linux-2.6.39.1/drivers/mfd/ab3550-core.c 2011-05-19 00:06:34.000000000 -0400
33415 +++ linux-2.6.39.1/drivers/mfd/ab3550-core.c 2011-05-22 19:36:31.000000000 -0400
33416 @@ -676,7 +676,7 @@ static int ab3550_startup_irq_enabled(st
33417 return val;
33418 }
33419
33420 -static struct abx500_ops ab3550_ops = {
33421 +static const struct abx500_ops ab3550_ops = {
33422 .get_chip_id = ab3550_get_chip_id,
33423 .get_register = ab3550_get_register_interruptible,
33424 .set_register = ab3550_set_register_interruptible,
33425 diff -urNp linux-2.6.39.1/drivers/mfd/ab8500-core.c linux-2.6.39.1/drivers/mfd/ab8500-core.c
33426 --- linux-2.6.39.1/drivers/mfd/ab8500-core.c 2011-05-19 00:06:34.000000000 -0400
33427 +++ linux-2.6.39.1/drivers/mfd/ab8500-core.c 2011-05-22 19:36:31.000000000 -0400
33428 @@ -223,7 +223,7 @@ static int ab8500_mask_and_set_register(
33429
33430 }
33431
33432 -static struct abx500_ops ab8500_ops = {
33433 +static const struct abx500_ops ab8500_ops = {
33434 .get_chip_id = ab8500_get_chip_id,
33435 .get_register = ab8500_get_register,
33436 .set_register = ab8500_set_register,
33437 diff -urNp linux-2.6.39.1/drivers/mfd/abx500-core.c linux-2.6.39.1/drivers/mfd/abx500-core.c
33438 --- linux-2.6.39.1/drivers/mfd/abx500-core.c 2011-05-19 00:06:34.000000000 -0400
33439 +++ linux-2.6.39.1/drivers/mfd/abx500-core.c 2011-05-22 19:36:31.000000000 -0400
33440 @@ -18,7 +18,7 @@ struct abx500_device_entry {
33441 struct device *dev;
33442 };
33443
33444 -static void lookup_ops(struct device *dev, struct abx500_ops **ops)
33445 +static void lookup_ops(struct device *dev, const struct abx500_ops **ops)
33446 {
33447 struct abx500_device_entry *dev_entry;
33448
33449 @@ -31,7 +31,7 @@ static void lookup_ops(struct device *de
33450 }
33451 }
33452
33453 -int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
33454 +int abx500_register_ops(struct device *dev, const struct abx500_ops *ops)
33455 {
33456 struct abx500_device_entry *dev_entry;
33457
33458 @@ -65,7 +65,7 @@ EXPORT_SYMBOL(abx500_remove_ops);
33459 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
33460 u8 value)
33461 {
33462 - struct abx500_ops *ops;
33463 + const struct abx500_ops *ops;
33464
33465 lookup_ops(dev->parent, &ops);
33466 if ((ops != NULL) && (ops->set_register != NULL))
33467 @@ -78,7 +78,7 @@ EXPORT_SYMBOL(abx500_set_register_interr
33468 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
33469 u8 *value)
33470 {
33471 - struct abx500_ops *ops;
33472 + const struct abx500_ops *ops;
33473
33474 lookup_ops(dev->parent, &ops);
33475 if ((ops != NULL) && (ops->get_register != NULL))
33476 @@ -91,7 +91,7 @@ EXPORT_SYMBOL(abx500_get_register_interr
33477 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
33478 u8 first_reg, u8 *regvals, u8 numregs)
33479 {
33480 - struct abx500_ops *ops;
33481 + const struct abx500_ops *ops;
33482
33483 lookup_ops(dev->parent, &ops);
33484 if ((ops != NULL) && (ops->get_register_page != NULL))
33485 @@ -105,7 +105,7 @@ EXPORT_SYMBOL(abx500_get_register_page_i
33486 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
33487 u8 reg, u8 bitmask, u8 bitvalues)
33488 {
33489 - struct abx500_ops *ops;
33490 + const struct abx500_ops *ops;
33491
33492 lookup_ops(dev->parent, &ops);
33493 if ((ops != NULL) && (ops->mask_and_set_register != NULL))
33494 @@ -118,7 +118,7 @@ EXPORT_SYMBOL(abx500_mask_and_set_regist
33495
33496 int abx500_get_chip_id(struct device *dev)
33497 {
33498 - struct abx500_ops *ops;
33499 + const struct abx500_ops *ops;
33500
33501 lookup_ops(dev->parent, &ops);
33502 if ((ops != NULL) && (ops->get_chip_id != NULL))
33503 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(abx500_get_chip_id);
33504
33505 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
33506 {
33507 - struct abx500_ops *ops;
33508 + const struct abx500_ops *ops;
33509
33510 lookup_ops(dev->parent, &ops);
33511 if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
33512 @@ -142,7 +142,7 @@ EXPORT_SYMBOL(abx500_event_registers_sta
33513
33514 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
33515 {
33516 - struct abx500_ops *ops;
33517 + const struct abx500_ops *ops;
33518
33519 lookup_ops(dev->parent, &ops);
33520 if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
33521 diff -urNp linux-2.6.39.1/drivers/mfd/janz-cmodio.c linux-2.6.39.1/drivers/mfd/janz-cmodio.c
33522 --- linux-2.6.39.1/drivers/mfd/janz-cmodio.c 2011-05-19 00:06:34.000000000 -0400
33523 +++ linux-2.6.39.1/drivers/mfd/janz-cmodio.c 2011-05-22 19:36:31.000000000 -0400
33524 @@ -13,6 +13,7 @@
33525
33526 #include <linux/kernel.h>
33527 #include <linux/module.h>
33528 +#include <linux/slab.h>
33529 #include <linux/init.h>
33530 #include <linux/pci.h>
33531 #include <linux/interrupt.h>
33532 diff -urNp linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c
33533 --- linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c 2011-05-19 00:06:34.000000000 -0400
33534 +++ linux-2.6.39.1/drivers/mfd/mcp-sa11x0.c 2011-05-22 19:36:31.000000000 -0400
33535 @@ -128,7 +128,7 @@ static void mcp_sa11x0_disable(struct mc
33536 /*
33537 * Our methods.
33538 */
33539 -static struct mcp_ops mcp_sa11x0 = {
33540 +static const struct mcp_ops mcp_sa11x0 = {
33541 .set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
33542 .set_audio_divisor = mcp_sa11x0_set_audio_divisor,
33543 .reg_write = mcp_sa11x0_write,
33544 diff -urNp linux-2.6.39.1/drivers/mfd/wm8350-i2c.c linux-2.6.39.1/drivers/mfd/wm8350-i2c.c
33545 --- linux-2.6.39.1/drivers/mfd/wm8350-i2c.c 2011-05-19 00:06:34.000000000 -0400
33546 +++ linux-2.6.39.1/drivers/mfd/wm8350-i2c.c 2011-05-22 19:36:31.000000000 -0400
33547 @@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struc
33548 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
33549 int ret;
33550
33551 + pax_track_stack();
33552 +
33553 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
33554 return -EINVAL;
33555
33556 diff -urNp linux-2.6.39.1/drivers/misc/enclosure.c linux-2.6.39.1/drivers/misc/enclosure.c
33557 --- linux-2.6.39.1/drivers/misc/enclosure.c 2011-05-19 00:06:34.000000000 -0400
33558 +++ linux-2.6.39.1/drivers/misc/enclosure.c 2011-05-22 19:36:31.000000000 -0400
33559 @@ -161,7 +161,7 @@ enclosure_register(struct device *dev, c
33560 }
33561 EXPORT_SYMBOL_GPL(enclosure_register);
33562
33563 -static struct enclosure_component_callbacks enclosure_null_callbacks;
33564 +static const struct enclosure_component_callbacks enclosure_null_callbacks;
33565
33566 /**
33567 * enclosure_unregister - remove an enclosure
33568 diff -urNp linux-2.6.39.1/drivers/misc/kgdbts.c linux-2.6.39.1/drivers/misc/kgdbts.c
33569 --- linux-2.6.39.1/drivers/misc/kgdbts.c 2011-05-19 00:06:34.000000000 -0400
33570 +++ linux-2.6.39.1/drivers/misc/kgdbts.c 2011-05-22 19:36:31.000000000 -0400
33571 @@ -118,7 +118,7 @@
33572 } while (0)
33573 #define MAX_CONFIG_LEN 40
33574
33575 -static struct kgdb_io kgdbts_io_ops;
33576 +static const struct kgdb_io kgdbts_io_ops;
33577 static char get_buf[BUFMAX];
33578 static int get_buf_cnt;
33579 static char put_buf[BUFMAX];
33580 @@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
33581 module_put(THIS_MODULE);
33582 }
33583
33584 -static struct kgdb_io kgdbts_io_ops = {
33585 +static const struct kgdb_io kgdbts_io_ops = {
33586 .name = "kgdbts",
33587 .read_char = kgdbts_get_char,
33588 .write_char = kgdbts_put_char,
33589 diff -urNp linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c
33590 --- linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-19 00:06:34.000000000 -0400
33591 +++ linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-22 19:36:31.000000000 -0400
33592 @@ -435,7 +435,7 @@ static irqreturn_t lis302dl_interrupt(in
33593 * the lid is closed. This leads to interrupts as soon as a little move
33594 * is done.
33595 */
33596 - atomic_inc(&lis3_dev.count);
33597 + atomic_inc_unchecked(&lis3_dev.count);
33598
33599 wake_up_interruptible(&lis3_dev.misc_wait);
33600 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33601 @@ -518,7 +518,7 @@ static int lis3lv02d_misc_open(struct in
33602 if (lis3_dev.pm_dev)
33603 pm_runtime_get_sync(lis3_dev.pm_dev);
33604
33605 - atomic_set(&lis3_dev.count, 0);
33606 + atomic_set_unchecked(&lis3_dev.count, 0);
33607 return 0;
33608 }
33609
33610 @@ -545,7 +545,7 @@ static ssize_t lis3lv02d_misc_read(struc
33611 add_wait_queue(&lis3_dev.misc_wait, &wait);
33612 while (true) {
33613 set_current_state(TASK_INTERRUPTIBLE);
33614 - data = atomic_xchg(&lis3_dev.count, 0);
33615 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33616 if (data)
33617 break;
33618
33619 @@ -583,7 +583,7 @@ out:
33620 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33621 {
33622 poll_wait(file, &lis3_dev.misc_wait, wait);
33623 - if (atomic_read(&lis3_dev.count))
33624 + if (atomic_read_unchecked(&lis3_dev.count))
33625 return POLLIN | POLLRDNORM;
33626 return 0;
33627 }
33628 diff -urNp linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h
33629 --- linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-19 00:06:34.000000000 -0400
33630 +++ linux-2.6.39.1/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-22 19:36:31.000000000 -0400
33631 @@ -265,7 +265,7 @@ struct lis3lv02d {
33632 struct input_polled_dev *idev; /* input device */
33633 struct platform_device *pdev; /* platform device */
33634 struct regulator_bulk_data regulators[2];
33635 - atomic_t count; /* interrupt count after last read */
33636 + atomic_unchecked_t count; /* interrupt count after last read */
33637 union axis_conversion ac; /* hw -> logical axis */
33638 int mapped_btns[3];
33639
33640 diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c
33641 --- linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c 2011-05-19 00:06:34.000000000 -0400
33642 +++ linux-2.6.39.1/drivers/misc/sgi-gru/gruhandles.c 2011-05-22 19:36:31.000000000 -0400
33643 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
33644 unsigned long nsec;
33645
33646 nsec = CLKS2NSEC(clks);
33647 - atomic_long_inc(&mcs_op_statistics[op].count);
33648 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
33649 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33650 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33651 if (mcs_op_statistics[op].max < nsec)
33652 mcs_op_statistics[op].max = nsec;
33653 }
33654 diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c
33655 --- linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c 2011-05-19 00:06:34.000000000 -0400
33656 +++ linux-2.6.39.1/drivers/misc/sgi-gru/gruprocfs.c 2011-05-22 19:36:31.000000000 -0400
33657 @@ -32,9 +32,9 @@
33658
33659 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33660
33661 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33662 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33663 {
33664 - unsigned long val = atomic_long_read(v);
33665 + unsigned long val = atomic_long_read_unchecked(v);
33666
33667 seq_printf(s, "%16lu %s\n", val, id);
33668 }
33669 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
33670
33671 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33672 for (op = 0; op < mcsop_last; op++) {
33673 - count = atomic_long_read(&mcs_op_statistics[op].count);
33674 - total = atomic_long_read(&mcs_op_statistics[op].total);
33675 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33676 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33677 max = mcs_op_statistics[op].max;
33678 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33679 count ? total / count : 0, max);
33680 diff -urNp linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h
33681 --- linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h 2011-05-19 00:06:34.000000000 -0400
33682 +++ linux-2.6.39.1/drivers/misc/sgi-gru/grutables.h 2011-05-22 19:36:31.000000000 -0400
33683 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33684 * GRU statistics.
33685 */
33686 struct gru_stats_s {
33687 - atomic_long_t vdata_alloc;
33688 - atomic_long_t vdata_free;
33689 - atomic_long_t gts_alloc;
33690 - atomic_long_t gts_free;
33691 - atomic_long_t gms_alloc;
33692 - atomic_long_t gms_free;
33693 - atomic_long_t gts_double_allocate;
33694 - atomic_long_t assign_context;
33695 - atomic_long_t assign_context_failed;
33696 - atomic_long_t free_context;
33697 - atomic_long_t load_user_context;
33698 - atomic_long_t load_kernel_context;
33699 - atomic_long_t lock_kernel_context;
33700 - atomic_long_t unlock_kernel_context;
33701 - atomic_long_t steal_user_context;
33702 - atomic_long_t steal_kernel_context;
33703 - atomic_long_t steal_context_failed;
33704 - atomic_long_t nopfn;
33705 - atomic_long_t asid_new;
33706 - atomic_long_t asid_next;
33707 - atomic_long_t asid_wrap;
33708 - atomic_long_t asid_reuse;
33709 - atomic_long_t intr;
33710 - atomic_long_t intr_cbr;
33711 - atomic_long_t intr_tfh;
33712 - atomic_long_t intr_spurious;
33713 - atomic_long_t intr_mm_lock_failed;
33714 - atomic_long_t call_os;
33715 - atomic_long_t call_os_wait_queue;
33716 - atomic_long_t user_flush_tlb;
33717 - atomic_long_t user_unload_context;
33718 - atomic_long_t user_exception;
33719 - atomic_long_t set_context_option;
33720 - atomic_long_t check_context_retarget_intr;
33721 - atomic_long_t check_context_unload;
33722 - atomic_long_t tlb_dropin;
33723 - atomic_long_t tlb_preload_page;
33724 - atomic_long_t tlb_dropin_fail_no_asid;
33725 - atomic_long_t tlb_dropin_fail_upm;
33726 - atomic_long_t tlb_dropin_fail_invalid;
33727 - atomic_long_t tlb_dropin_fail_range_active;
33728 - atomic_long_t tlb_dropin_fail_idle;
33729 - atomic_long_t tlb_dropin_fail_fmm;
33730 - atomic_long_t tlb_dropin_fail_no_exception;
33731 - atomic_long_t tfh_stale_on_fault;
33732 - atomic_long_t mmu_invalidate_range;
33733 - atomic_long_t mmu_invalidate_page;
33734 - atomic_long_t flush_tlb;
33735 - atomic_long_t flush_tlb_gru;
33736 - atomic_long_t flush_tlb_gru_tgh;
33737 - atomic_long_t flush_tlb_gru_zero_asid;
33738 -
33739 - atomic_long_t copy_gpa;
33740 - atomic_long_t read_gpa;
33741 -
33742 - atomic_long_t mesq_receive;
33743 - atomic_long_t mesq_receive_none;
33744 - atomic_long_t mesq_send;
33745 - atomic_long_t mesq_send_failed;
33746 - atomic_long_t mesq_noop;
33747 - atomic_long_t mesq_send_unexpected_error;
33748 - atomic_long_t mesq_send_lb_overflow;
33749 - atomic_long_t mesq_send_qlimit_reached;
33750 - atomic_long_t mesq_send_amo_nacked;
33751 - atomic_long_t mesq_send_put_nacked;
33752 - atomic_long_t mesq_page_overflow;
33753 - atomic_long_t mesq_qf_locked;
33754 - atomic_long_t mesq_qf_noop_not_full;
33755 - atomic_long_t mesq_qf_switch_head_failed;
33756 - atomic_long_t mesq_qf_unexpected_error;
33757 - atomic_long_t mesq_noop_unexpected_error;
33758 - atomic_long_t mesq_noop_lb_overflow;
33759 - atomic_long_t mesq_noop_qlimit_reached;
33760 - atomic_long_t mesq_noop_amo_nacked;
33761 - atomic_long_t mesq_noop_put_nacked;
33762 - atomic_long_t mesq_noop_page_overflow;
33763 + atomic_long_unchecked_t vdata_alloc;
33764 + atomic_long_unchecked_t vdata_free;
33765 + atomic_long_unchecked_t gts_alloc;
33766 + atomic_long_unchecked_t gts_free;
33767 + atomic_long_unchecked_t gms_alloc;
33768 + atomic_long_unchecked_t gms_free;
33769 + atomic_long_unchecked_t gts_double_allocate;
33770 + atomic_long_unchecked_t assign_context;
33771 + atomic_long_unchecked_t assign_context_failed;
33772 + atomic_long_unchecked_t free_context;
33773 + atomic_long_unchecked_t load_user_context;
33774 + atomic_long_unchecked_t load_kernel_context;
33775 + atomic_long_unchecked_t lock_kernel_context;
33776 + atomic_long_unchecked_t unlock_kernel_context;
33777 + atomic_long_unchecked_t steal_user_context;
33778 + atomic_long_unchecked_t steal_kernel_context;
33779 + atomic_long_unchecked_t steal_context_failed;
33780 + atomic_long_unchecked_t nopfn;
33781 + atomic_long_unchecked_t asid_new;
33782 + atomic_long_unchecked_t asid_next;
33783 + atomic_long_unchecked_t asid_wrap;
33784 + atomic_long_unchecked_t asid_reuse;
33785 + atomic_long_unchecked_t intr;
33786 + atomic_long_unchecked_t intr_cbr;
33787 + atomic_long_unchecked_t intr_tfh;
33788 + atomic_long_unchecked_t intr_spurious;
33789 + atomic_long_unchecked_t intr_mm_lock_failed;
33790 + atomic_long_unchecked_t call_os;
33791 + atomic_long_unchecked_t call_os_wait_queue;
33792 + atomic_long_unchecked_t user_flush_tlb;
33793 + atomic_long_unchecked_t user_unload_context;
33794 + atomic_long_unchecked_t user_exception;
33795 + atomic_long_unchecked_t set_context_option;
33796 + atomic_long_unchecked_t check_context_retarget_intr;
33797 + atomic_long_unchecked_t check_context_unload;
33798 + atomic_long_unchecked_t tlb_dropin;
33799 + atomic_long_unchecked_t tlb_preload_page;
33800 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33801 + atomic_long_unchecked_t tlb_dropin_fail_upm;
33802 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
33803 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
33804 + atomic_long_unchecked_t tlb_dropin_fail_idle;
33805 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
33806 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33807 + atomic_long_unchecked_t tfh_stale_on_fault;
33808 + atomic_long_unchecked_t mmu_invalidate_range;
33809 + atomic_long_unchecked_t mmu_invalidate_page;
33810 + atomic_long_unchecked_t flush_tlb;
33811 + atomic_long_unchecked_t flush_tlb_gru;
33812 + atomic_long_unchecked_t flush_tlb_gru_tgh;
33813 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33814 +
33815 + atomic_long_unchecked_t copy_gpa;
33816 + atomic_long_unchecked_t read_gpa;
33817 +
33818 + atomic_long_unchecked_t mesq_receive;
33819 + atomic_long_unchecked_t mesq_receive_none;
33820 + atomic_long_unchecked_t mesq_send;
33821 + atomic_long_unchecked_t mesq_send_failed;
33822 + atomic_long_unchecked_t mesq_noop;
33823 + atomic_long_unchecked_t mesq_send_unexpected_error;
33824 + atomic_long_unchecked_t mesq_send_lb_overflow;
33825 + atomic_long_unchecked_t mesq_send_qlimit_reached;
33826 + atomic_long_unchecked_t mesq_send_amo_nacked;
33827 + atomic_long_unchecked_t mesq_send_put_nacked;
33828 + atomic_long_unchecked_t mesq_page_overflow;
33829 + atomic_long_unchecked_t mesq_qf_locked;
33830 + atomic_long_unchecked_t mesq_qf_noop_not_full;
33831 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
33832 + atomic_long_unchecked_t mesq_qf_unexpected_error;
33833 + atomic_long_unchecked_t mesq_noop_unexpected_error;
33834 + atomic_long_unchecked_t mesq_noop_lb_overflow;
33835 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
33836 + atomic_long_unchecked_t mesq_noop_amo_nacked;
33837 + atomic_long_unchecked_t mesq_noop_put_nacked;
33838 + atomic_long_unchecked_t mesq_noop_page_overflow;
33839
33840 };
33841
33842 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
33843 tghop_invalidate, mcsop_last};
33844
33845 struct mcs_op_statistic {
33846 - atomic_long_t count;
33847 - atomic_long_t total;
33848 + atomic_long_unchecked_t count;
33849 + atomic_long_unchecked_t total;
33850 unsigned long max;
33851 };
33852
33853 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
33854
33855 #define STAT(id) do { \
33856 if (gru_options & OPT_STATS) \
33857 - atomic_long_inc(&gru_stats.id); \
33858 + atomic_long_inc_unchecked(&gru_stats.id); \
33859 } while (0)
33860
33861 #ifdef CONFIG_SGI_GRU_DEBUG
33862 diff -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
33863 --- linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-19 00:06:34.000000000 -0400
33864 +++ linux-2.6.39.1/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-22 19:36:31.000000000 -0400
33865 @@ -2351,7 +2351,7 @@ xpc_received_payload_sn2(struct xpc_chan
33866 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33867 }
33868
33869 -static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33870 +static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33871 .setup_partitions = xpc_setup_partitions_sn2,
33872 .teardown_partitions = xpc_teardown_partitions_sn2,
33873 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33874 diff -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
33875 --- linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c 2011-05-19 00:06:34.000000000 -0400
33876 +++ linux-2.6.39.1/drivers/misc/sgi-xp/xpc_uv.c 2011-05-22 19:36:31.000000000 -0400
33877 @@ -1674,7 +1674,7 @@ xpc_received_payload_uv(struct xpc_chann
33878 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33879 }
33880
33881 -static struct xpc_arch_operations xpc_arch_ops_uv = {
33882 +static const struct xpc_arch_operations xpc_arch_ops_uv = {
33883 .setup_partitions = xpc_setup_partitions_uv,
33884 .teardown_partitions = xpc_teardown_partitions_uv,
33885 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33886 diff -urNp linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c
33887 --- linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c 2011-05-19 00:06:34.000000000 -0400
33888 +++ linux-2.6.39.1/drivers/misc/spear13xx_pcie_gadget.c 2011-05-22 19:36:31.000000000 -0400
33889 @@ -644,7 +644,7 @@ static ssize_t pcie_gadget_target_attr_s
33890 return ret;
33891 }
33892
33893 -static struct configfs_item_operations pcie_gadget_target_item_ops = {
33894 +static const struct configfs_item_operations pcie_gadget_target_item_ops = {
33895 .show_attribute = pcie_gadget_target_attr_show,
33896 .store_attribute = pcie_gadget_target_attr_store,
33897 };
33898 diff -urNp linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c
33899 --- linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c 2011-05-19 00:06:34.000000000 -0400
33900 +++ linux-2.6.39.1/drivers/mmc/host/davinci_mmc.c 2011-05-22 19:36:31.000000000 -0400
33901 @@ -1133,7 +1133,7 @@ static void mmc_davinci_enable_sdio_irq(
33902 }
33903 }
33904
33905 -static struct mmc_host_ops mmc_davinci_ops = {
33906 +static const struct mmc_host_ops mmc_davinci_ops = {
33907 .request = mmc_davinci_request,
33908 .set_ios = mmc_davinci_set_ios,
33909 .get_cd = mmc_davinci_get_cd,
33910 diff -urNp linux-2.6.39.1/drivers/mmc/host/dw_mmc.c linux-2.6.39.1/drivers/mmc/host/dw_mmc.c
33911 --- linux-2.6.39.1/drivers/mmc/host/dw_mmc.c 2011-05-19 00:06:34.000000000 -0400
33912 +++ linux-2.6.39.1/drivers/mmc/host/dw_mmc.c 2011-05-22 19:36:31.000000000 -0400
33913 @@ -417,7 +417,7 @@ static int dw_mci_idmac_init(struct dw_m
33914 return 0;
33915 }
33916
33917 -static struct dw_mci_dma_ops dw_mci_idmac_ops = {
33918 +static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
33919 .init = dw_mci_idmac_init,
33920 .start = dw_mci_idmac_start_dma,
33921 .stop = dw_mci_idmac_stop_dma,
33922 diff -urNp linux-2.6.39.1/drivers/mmc/host/s3cmci.c linux-2.6.39.1/drivers/mmc/host/s3cmci.c
33923 --- linux-2.6.39.1/drivers/mmc/host/s3cmci.c 2011-05-19 00:06:34.000000000 -0400
33924 +++ linux-2.6.39.1/drivers/mmc/host/s3cmci.c 2011-05-22 19:36:31.000000000 -0400
33925 @@ -1349,7 +1349,7 @@ static void s3cmci_enable_sdio_irq(struc
33926 s3cmci_check_sdio_irq(host);
33927 }
33928
33929 -static struct mmc_host_ops s3cmci_ops = {
33930 +static const struct mmc_host_ops s3cmci_ops = {
33931 .request = s3cmci_request,
33932 .set_ios = s3cmci_set_ios,
33933 .get_ro = s3cmci_get_ro,
33934 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c
33935 --- linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-19 00:06:34.000000000 -0400
33936 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-22 19:36:31.000000000 -0400
33937 @@ -81,7 +81,7 @@ out:
33938 host->clock = clock;
33939 }
33940
33941 -static struct sdhci_ops sdhci_cns3xxx_ops = {
33942 +static const struct sdhci_ops sdhci_cns3xxx_ops = {
33943 .get_max_clock = sdhci_cns3xxx_get_max_clk,
33944 .set_clock = sdhci_cns3xxx_set_clock,
33945 };
33946 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c
33947 --- linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c 2011-05-19 00:06:34.000000000 -0400
33948 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-dove.c 2011-05-22 19:36:31.000000000 -0400
33949 @@ -56,7 +56,7 @@ static u32 sdhci_dove_readl(struct sdhci
33950 return ret;
33951 }
33952
33953 -static struct sdhci_ops sdhci_dove_ops = {
33954 +static const struct sdhci_ops sdhci_dove_ops = {
33955 .read_w = sdhci_dove_readw,
33956 .read_l = sdhci_dove_readl,
33957 };
33958 diff -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
33959 --- linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-19 00:06:34.000000000 -0400
33960 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-22 19:36:31.000000000 -0400
33961 @@ -201,7 +201,7 @@ static unsigned int esdhc_pltfm_get_ro(s
33962 return -ENOSYS;
33963 }
33964
33965 -static struct sdhci_ops sdhci_esdhc_ops = {
33966 +static const struct sdhci_ops sdhci_esdhc_ops = {
33967 .read_l = esdhc_readl_le,
33968 .read_w = esdhc_readw_le,
33969 .write_l = esdhc_writel_le,
33970 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-of.h linux-2.6.39.1/drivers/mmc/host/sdhci-of.h
33971 --- linux-2.6.39.1/drivers/mmc/host/sdhci-of.h 2011-05-19 00:06:34.000000000 -0400
33972 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-of.h 2011-05-22 19:36:31.000000000 -0400
33973 @@ -21,7 +21,7 @@
33974
33975 struct sdhci_of_data {
33976 unsigned int quirks;
33977 - struct sdhci_ops ops;
33978 + const struct sdhci_ops ops;
33979 };
33980
33981 struct sdhci_of_host {
33982 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c
33983 --- linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c 2011-05-19 00:06:34.000000000 -0400
33984 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-pci.c 2011-05-22 19:36:31.000000000 -0400
33985 @@ -786,7 +786,7 @@ static int sdhci_pci_enable_dma(struct s
33986 return 0;
33987 }
33988
33989 -static struct sdhci_ops sdhci_pci_ops = {
33990 +static const struct sdhci_ops sdhci_pci_ops = {
33991 .enable_dma = sdhci_pci_enable_dma,
33992 };
33993
33994 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c
33995 --- linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c 2011-05-19 00:06:34.000000000 -0400
33996 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-pltfm.c 2011-05-22 19:36:31.000000000 -0400
33997 @@ -41,7 +41,7 @@
33998 * *
33999 \*****************************************************************************/
34000
34001 -static struct sdhci_ops sdhci_pltfm_ops = {
34002 +static const struct sdhci_ops sdhci_pltfm_ops = {
34003 };
34004
34005 /*****************************************************************************\
34006 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c
34007 --- linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c 2011-05-19 00:06:34.000000000 -0400
34008 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-pxa.c 2011-05-22 19:36:31.000000000 -0400
34009 @@ -69,7 +69,7 @@ static void set_clock(struct sdhci_host
34010 }
34011 }
34012
34013 -static struct sdhci_ops sdhci_pxa_ops = {
34014 +static const struct sdhci_ops sdhci_pxa_ops = {
34015 .set_clock = set_clock,
34016 };
34017
34018 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c
34019 --- linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c 2011-05-19 00:06:34.000000000 -0400
34020 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-s3c.c 2011-05-22 19:36:31.000000000 -0400
34021 @@ -309,7 +309,7 @@ static int sdhci_s3c_platform_8bit_width
34022 return 0;
34023 }
34024
34025 -static struct sdhci_ops sdhci_s3c_ops = {
34026 +static const struct sdhci_ops sdhci_s3c_ops = {
34027 .get_max_clock = sdhci_s3c_get_max_clk,
34028 .set_clock = sdhci_s3c_set_clock,
34029 .get_min_clock = sdhci_s3c_get_min_clock,
34030 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c
34031 --- linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c 2011-05-19 00:06:34.000000000 -0400
34032 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-spear.c 2011-05-22 19:36:31.000000000 -0400
34033 @@ -32,7 +32,7 @@ struct spear_sdhci {
34034 };
34035
34036 /* sdhci ops */
34037 -static struct sdhci_ops sdhci_pltfm_ops = {
34038 +static const struct sdhci_ops sdhci_pltfm_ops = {
34039 /* Nothing to do for now. */
34040 };
34041
34042 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c
34043 --- linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c 2011-05-19 00:06:34.000000000 -0400
34044 +++ linux-2.6.39.1/drivers/mmc/host/sdhci-tegra.c 2011-05-22 19:36:31.000000000 -0400
34045 @@ -242,7 +242,7 @@ static void tegra_sdhci_pltfm_exit(struc
34046 clk_put(pltfm_host->clk);
34047 }
34048
34049 -static struct sdhci_ops tegra_sdhci_ops = {
34050 +static const struct sdhci_ops tegra_sdhci_ops = {
34051 .get_ro = tegra_sdhci_get_ro,
34052 .read_l = tegra_sdhci_readl,
34053 .read_w = tegra_sdhci_readw,
34054 diff -urNp linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c
34055 --- linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c 2011-05-19 00:06:34.000000000 -0400
34056 +++ linux-2.6.39.1/drivers/mmc/host/sdricoh_cs.c 2011-05-22 19:36:31.000000000 -0400
34057 @@ -387,7 +387,7 @@ static int sdricoh_get_ro(struct mmc_hos
34058 return (status & STATUS_CARD_LOCKED);
34059 }
34060
34061 -static struct mmc_host_ops sdricoh_ops = {
34062 +static const struct mmc_host_ops sdricoh_ops = {
34063 .request = sdricoh_request,
34064 .set_ios = sdricoh_set_ios,
34065 .get_ro = sdricoh_get_ro,
34066 diff -urNp linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c
34067 --- linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c 2011-05-19 00:06:34.000000000 -0400
34068 +++ linux-2.6.39.1/drivers/mmc/host/sh_mmcif.c 2011-05-22 19:36:31.000000000 -0400
34069 @@ -872,7 +872,7 @@ static int sh_mmcif_get_cd(struct mmc_ho
34070 return p->get_cd(host->pd);
34071 }
34072
34073 -static struct mmc_host_ops sh_mmcif_ops = {
34074 +static const struct mmc_host_ops sh_mmcif_ops = {
34075 .request = sh_mmcif_request,
34076 .set_ios = sh_mmcif_set_ios,
34077 .get_cd = sh_mmcif_get_cd,
34078 diff -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
34079 --- linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-19 00:06:34.000000000 -0400
34080 +++ linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-22 19:36:31.000000000 -0400
34081 @@ -757,6 +757,8 @@ static int chip_ready (struct map_info *
34082 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
34083 unsigned long timeo = jiffies + HZ;
34084
34085 + pax_track_stack();
34086 +
34087 /* Prevent setting state FL_SYNCING for chip in suspended state. */
34088 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
34089 goto sleep;
34090 @@ -1657,6 +1659,8 @@ static int __xipram do_write_buffer(stru
34091 unsigned long initial_adr;
34092 int initial_len = len;
34093
34094 + pax_track_stack();
34095 +
34096 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
34097 adr += chip->start;
34098 initial_adr = adr;
34099 @@ -1875,6 +1879,8 @@ static int __xipram do_erase_oneblock(st
34100 int retries = 3;
34101 int ret;
34102
34103 + pax_track_stack();
34104 +
34105 adr += chip->start;
34106
34107 retry:
34108 diff -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
34109 --- linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-19 00:06:34.000000000 -0400
34110 +++ linux-2.6.39.1/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-22 19:36:31.000000000 -0400
34111 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
34112 unsigned long cmd_addr;
34113 struct cfi_private *cfi = map->fldrv_priv;
34114
34115 + pax_track_stack();
34116 +
34117 adr += chip->start;
34118
34119 /* Ensure cmd read/writes are aligned. */
34120 @@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
34121 DECLARE_WAITQUEUE(wait, current);
34122 int wbufsize, z;
34123
34124 + pax_track_stack();
34125 +
34126 /* M58LW064A requires bus alignment for buffer wriets -- saw */
34127 if (adr & (map_bankwidth(map)-1))
34128 return -EINVAL;
34129 @@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
34130 DECLARE_WAITQUEUE(wait, current);
34131 int ret = 0;
34132
34133 + pax_track_stack();
34134 +
34135 adr += chip->start;
34136
34137 /* Let's determine this according to the interleave only once */
34138 @@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
34139 unsigned long timeo = jiffies + HZ;
34140 DECLARE_WAITQUEUE(wait, current);
34141
34142 + pax_track_stack();
34143 +
34144 adr += chip->start;
34145
34146 /* Let's determine this according to the interleave only once */
34147 @@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
34148 unsigned long timeo = jiffies + HZ;
34149 DECLARE_WAITQUEUE(wait, current);
34150
34151 + pax_track_stack();
34152 +
34153 adr += chip->start;
34154
34155 /* Let's determine this according to the interleave only once */
34156 diff -urNp linux-2.6.39.1/drivers/mtd/devices/doc2000.c linux-2.6.39.1/drivers/mtd/devices/doc2000.c
34157 --- linux-2.6.39.1/drivers/mtd/devices/doc2000.c 2011-05-19 00:06:34.000000000 -0400
34158 +++ linux-2.6.39.1/drivers/mtd/devices/doc2000.c 2011-05-22 19:36:31.000000000 -0400
34159 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
34160
34161 /* The ECC will not be calculated correctly if less than 512 is written */
34162 /* DBB-
34163 - if (len != 0x200 && eccbuf)
34164 + if (len != 0x200)
34165 printk(KERN_WARNING
34166 "ECC needs a full sector write (adr: %lx size %lx)\n",
34167 (long) to, (long) len);
34168 diff -urNp linux-2.6.39.1/drivers/mtd/devices/doc2001.c linux-2.6.39.1/drivers/mtd/devices/doc2001.c
34169 --- linux-2.6.39.1/drivers/mtd/devices/doc2001.c 2011-05-19 00:06:34.000000000 -0400
34170 +++ linux-2.6.39.1/drivers/mtd/devices/doc2001.c 2011-05-22 19:36:31.000000000 -0400
34171 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
34172 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34173
34174 /* Don't allow read past end of device */
34175 - if (from >= this->totlen)
34176 + if (from >= this->totlen || !len)
34177 return -EINVAL;
34178
34179 /* Don't allow a single read to cross a 512-byte block boundary */
34180 diff -urNp linux-2.6.39.1/drivers/mtd/ftl.c linux-2.6.39.1/drivers/mtd/ftl.c
34181 --- linux-2.6.39.1/drivers/mtd/ftl.c 2011-05-19 00:06:34.000000000 -0400
34182 +++ linux-2.6.39.1/drivers/mtd/ftl.c 2011-05-22 19:36:31.000000000 -0400
34183 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
34184 loff_t offset;
34185 uint16_t srcunitswap = cpu_to_le16(srcunit);
34186
34187 + pax_track_stack();
34188 +
34189 eun = &part->EUNInfo[srcunit];
34190 xfer = &part->XferInfo[xferunit];
34191 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
34192 diff -urNp linux-2.6.39.1/drivers/mtd/inftlcore.c linux-2.6.39.1/drivers/mtd/inftlcore.c
34193 --- linux-2.6.39.1/drivers/mtd/inftlcore.c 2011-05-19 00:06:34.000000000 -0400
34194 +++ linux-2.6.39.1/drivers/mtd/inftlcore.c 2011-05-22 19:36:31.000000000 -0400
34195 @@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLr
34196 struct inftl_oob oob;
34197 size_t retlen;
34198
34199 + pax_track_stack();
34200 +
34201 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
34202 "pending=%d)\n", inftl, thisVUC, pendingblock);
34203
34204 diff -urNp linux-2.6.39.1/drivers/mtd/inftlmount.c linux-2.6.39.1/drivers/mtd/inftlmount.c
34205 --- linux-2.6.39.1/drivers/mtd/inftlmount.c 2011-05-19 00:06:34.000000000 -0400
34206 +++ linux-2.6.39.1/drivers/mtd/inftlmount.c 2011-05-22 19:36:31.000000000 -0400
34207 @@ -53,6 +53,8 @@ static int find_boot_record(struct INFTL
34208 struct INFTLPartition *ip;
34209 size_t retlen;
34210
34211 + pax_track_stack();
34212 +
34213 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
34214
34215 /*
34216 diff -urNp linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c
34217 --- linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c 2011-05-19 00:06:34.000000000 -0400
34218 +++ linux-2.6.39.1/drivers/mtd/lpddr/qinfo_probe.c 2011-05-22 19:36:31.000000000 -0400
34219 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
34220 {
34221 map_word pfow_val[4];
34222
34223 + pax_track_stack();
34224 +
34225 /* Check identification string */
34226 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
34227 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
34228 diff -urNp linux-2.6.39.1/drivers/mtd/mtdchar.c linux-2.6.39.1/drivers/mtd/mtdchar.c
34229 --- linux-2.6.39.1/drivers/mtd/mtdchar.c 2011-05-19 00:06:34.000000000 -0400
34230 +++ linux-2.6.39.1/drivers/mtd/mtdchar.c 2011-05-22 19:36:31.000000000 -0400
34231 @@ -560,6 +560,8 @@ static int mtd_ioctl(struct file *file,
34232 u_long size;
34233 struct mtd_info_user info;
34234
34235 + pax_track_stack();
34236 +
34237 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
34238
34239 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
34240 diff -urNp linux-2.6.39.1/drivers/mtd/nand/denali.c linux-2.6.39.1/drivers/mtd/nand/denali.c
34241 --- linux-2.6.39.1/drivers/mtd/nand/denali.c 2011-05-19 00:06:34.000000000 -0400
34242 +++ linux-2.6.39.1/drivers/mtd/nand/denali.c 2011-05-22 19:36:31.000000000 -0400
34243 @@ -25,6 +25,7 @@
34244 #include <linux/pci.h>
34245 #include <linux/mtd/mtd.h>
34246 #include <linux/module.h>
34247 +#include <linux/slab.h>
34248
34249 #include "denali.h"
34250
34251 diff -urNp linux-2.6.39.1/drivers/mtd/nftlcore.c linux-2.6.39.1/drivers/mtd/nftlcore.c
34252 --- linux-2.6.39.1/drivers/mtd/nftlcore.c 2011-05-19 00:06:34.000000000 -0400
34253 +++ linux-2.6.39.1/drivers/mtd/nftlcore.c 2011-05-22 19:36:31.000000000 -0400
34254 @@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLre
34255 int inplace = 1;
34256 size_t retlen;
34257
34258 + pax_track_stack();
34259 +
34260 memset(BlockMap, 0xff, sizeof(BlockMap));
34261 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
34262
34263 diff -urNp linux-2.6.39.1/drivers/mtd/nftlmount.c linux-2.6.39.1/drivers/mtd/nftlmount.c
34264 --- linux-2.6.39.1/drivers/mtd/nftlmount.c 2011-05-19 00:06:34.000000000 -0400
34265 +++ linux-2.6.39.1/drivers/mtd/nftlmount.c 2011-05-22 19:36:31.000000000 -0400
34266 @@ -24,6 +24,7 @@
34267 #include <asm/errno.h>
34268 #include <linux/delay.h>
34269 #include <linux/slab.h>
34270 +#include <linux/sched.h>
34271 #include <linux/mtd/mtd.h>
34272 #include <linux/mtd/nand.h>
34273 #include <linux/mtd/nftl.h>
34274 @@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLr
34275 struct mtd_info *mtd = nftl->mbd.mtd;
34276 unsigned int i;
34277
34278 + pax_track_stack();
34279 +
34280 /* Assume logical EraseSize == physical erasesize for starting the scan.
34281 We'll sort it out later if we find a MediaHeader which says otherwise */
34282 /* Actually, we won't. The new DiskOnChip driver has already scanned
34283 diff -urNp linux-2.6.39.1/drivers/mtd/ubi/build.c linux-2.6.39.1/drivers/mtd/ubi/build.c
34284 --- linux-2.6.39.1/drivers/mtd/ubi/build.c 2011-05-19 00:06:34.000000000 -0400
34285 +++ linux-2.6.39.1/drivers/mtd/ubi/build.c 2011-05-22 19:36:31.000000000 -0400
34286 @@ -1287,7 +1287,7 @@ module_exit(ubi_exit);
34287 static int __init bytes_str_to_int(const char *str)
34288 {
34289 char *endp;
34290 - unsigned long result;
34291 + unsigned long result, scale = 1;
34292
34293 result = simple_strtoul(str, &endp, 0);
34294 if (str == endp || result >= INT_MAX) {
34295 @@ -1298,11 +1298,11 @@ static int __init bytes_str_to_int(const
34296
34297 switch (*endp) {
34298 case 'G':
34299 - result *= 1024;
34300 + scale *= 1024;
34301 case 'M':
34302 - result *= 1024;
34303 + scale *= 1024;
34304 case 'K':
34305 - result *= 1024;
34306 + scale *= 1024;
34307 if (endp[1] == 'i' && endp[2] == 'B')
34308 endp += 2;
34309 case '\0':
34310 @@ -1313,7 +1313,13 @@ static int __init bytes_str_to_int(const
34311 return -EINVAL;
34312 }
34313
34314 - return result;
34315 + if ((intoverflow_t)result*scale >= INT_MAX) {
34316 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34317 + str);
34318 + return -EINVAL;
34319 + }
34320 +
34321 + return result*scale;
34322 }
34323
34324 /**
34325 diff -urNp linux-2.6.39.1/drivers/net/bcm63xx_enet.c linux-2.6.39.1/drivers/net/bcm63xx_enet.c
34326 --- linux-2.6.39.1/drivers/net/bcm63xx_enet.c 2011-05-19 00:06:34.000000000 -0400
34327 +++ linux-2.6.39.1/drivers/net/bcm63xx_enet.c 2011-05-22 19:36:31.000000000 -0400
34328 @@ -1469,7 +1469,7 @@ static int bcm_enet_set_pauseparam(struc
34329 return 0;
34330 }
34331
34332 -static struct ethtool_ops bcm_enet_ethtool_ops = {
34333 +static const struct ethtool_ops bcm_enet_ethtool_ops = {
34334 .get_strings = bcm_enet_get_strings,
34335 .get_sset_count = bcm_enet_get_sset_count,
34336 .get_ethtool_stats = bcm_enet_get_ethtool_stats,
34337 diff -urNp linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c
34338 --- linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34339 +++ linux-2.6.39.1/drivers/net/bna/bnad_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34340 @@ -1242,7 +1242,7 @@ bnad_get_sset_count(struct net_device *n
34341 }
34342 }
34343
34344 -static struct ethtool_ops bnad_ethtool_ops = {
34345 +static const struct ethtool_ops bnad_ethtool_ops = {
34346 .get_settings = bnad_get_settings,
34347 .set_settings = bnad_set_settings,
34348 .get_drvinfo = bnad_get_drvinfo,
34349 diff -urNp linux-2.6.39.1/drivers/net/bnx2.c linux-2.6.39.1/drivers/net/bnx2.c
34350 --- linux-2.6.39.1/drivers/net/bnx2.c 2011-05-19 00:06:34.000000000 -0400
34351 +++ linux-2.6.39.1/drivers/net/bnx2.c 2011-05-22 19:36:31.000000000 -0400
34352 @@ -5828,6 +5828,8 @@ bnx2_test_nvram(struct bnx2 *bp)
34353 int rc = 0;
34354 u32 magic, csum;
34355
34356 + pax_track_stack();
34357 +
34358 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
34359 goto test_nvram_done;
34360
34361 diff -urNp linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c
34362 --- linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34363 +++ linux-2.6.39.1/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34364 @@ -1788,6 +1788,8 @@ static int bnx2x_test_nvram(struct bnx2x
34365 int i, rc;
34366 u32 magic, crc;
34367
34368 + pax_track_stack();
34369 +
34370 if (BP_NOMCP(bp))
34371 return 0;
34372
34373 diff -urNp linux-2.6.39.1/drivers/net/chelsio/pm3393.c linux-2.6.39.1/drivers/net/chelsio/pm3393.c
34374 --- linux-2.6.39.1/drivers/net/chelsio/pm3393.c 2011-05-19 00:06:34.000000000 -0400
34375 +++ linux-2.6.39.1/drivers/net/chelsio/pm3393.c 2011-05-22 19:36:31.000000000 -0400
34376 @@ -571,7 +571,7 @@ static void pm3393_destroy(struct cmac *
34377 kfree(cmac);
34378 }
34379
34380 -static struct cmac_ops pm3393_ops = {
34381 +static const struct cmac_ops pm3393_ops = {
34382 .destroy = pm3393_destroy,
34383 .reset = pm3393_reset,
34384 .interrupt_enable = pm3393_interrupt_enable,
34385 diff -urNp linux-2.6.39.1/drivers/net/chelsio/vsc7326.c linux-2.6.39.1/drivers/net/chelsio/vsc7326.c
34386 --- linux-2.6.39.1/drivers/net/chelsio/vsc7326.c 2011-05-19 00:06:34.000000000 -0400
34387 +++ linux-2.6.39.1/drivers/net/chelsio/vsc7326.c 2011-05-22 19:36:31.000000000 -0400
34388 @@ -666,7 +666,7 @@ static void mac_destroy(struct cmac *mac
34389 kfree(mac);
34390 }
34391
34392 -static struct cmac_ops vsc7326_ops = {
34393 +static const struct cmac_ops vsc7326_ops = {
34394 .destroy = mac_destroy,
34395 .reset = mac_reset,
34396 .interrupt_handler = mac_intr_handler,
34397 diff -urNp linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c
34398 --- linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c 2011-05-19 00:06:34.000000000 -0400
34399 +++ linux-2.6.39.1/drivers/net/cxgb4/cxgb4_main.c 2011-05-22 19:36:31.000000000 -0400
34400 @@ -3428,6 +3428,8 @@ static int __devinit enable_msix(struct
34401 unsigned int nchan = adap->params.nports;
34402 struct msix_entry entries[MAX_INGQ + 1];
34403
34404 + pax_track_stack();
34405 +
34406 for (i = 0; i < ARRAY_SIZE(entries); ++i)
34407 entries[i].entry = i;
34408
34409 diff -urNp linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c
34410 --- linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c 2011-05-19 00:06:34.000000000 -0400
34411 +++ linux-2.6.39.1/drivers/net/cxgb4/t4_hw.c 2011-05-22 19:36:31.000000000 -0400
34412 @@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter
34413 u8 vpd[VPD_LEN], csum;
34414 unsigned int vpdr_len, kw_offset, id_len;
34415
34416 + pax_track_stack();
34417 +
34418 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
34419 if (ret < 0)
34420 return ret;
34421 diff -urNp linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c
34422 --- linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-19 00:06:34.000000000 -0400
34423 +++ linux-2.6.39.1/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-22 19:36:31.000000000 -0400
34424 @@ -1572,7 +1572,7 @@ static int cxgb4vf_set_tso(struct net_de
34425 return 0;
34426 }
34427
34428 -static struct ethtool_ops cxgb4vf_ethtool_ops = {
34429 +static const struct ethtool_ops cxgb4vf_ethtool_ops = {
34430 .get_settings = cxgb4vf_get_settings,
34431 .get_drvinfo = cxgb4vf_get_drvinfo,
34432 .get_msglevel = cxgb4vf_get_msglevel,
34433 diff -urNp linux-2.6.39.1/drivers/net/e1000e/82571.c linux-2.6.39.1/drivers/net/e1000e/82571.c
34434 --- linux-2.6.39.1/drivers/net/e1000e/82571.c 2011-05-19 00:06:34.000000000 -0400
34435 +++ linux-2.6.39.1/drivers/net/e1000e/82571.c 2011-05-22 19:36:31.000000000 -0400
34436 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(s
34437 {
34438 struct e1000_hw *hw = &adapter->hw;
34439 struct e1000_mac_info *mac = &hw->mac;
34440 - struct e1000_mac_operations *func = &mac->ops;
34441 + struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34442 u32 swsm = 0;
34443 u32 swsm2 = 0;
34444 bool force_clear_smbi = false;
34445 @@ -1930,7 +1930,7 @@ static void e1000_clear_hw_cntrs_82571(s
34446 er32(ICRXDMTC);
34447 }
34448
34449 -static struct e1000_mac_operations e82571_mac_ops = {
34450 +static const struct e1000_mac_operations e82571_mac_ops = {
34451 /* .check_mng_mode: mac type dependent */
34452 /* .check_for_link: media type dependent */
34453 .id_led_init = e1000e_id_led_init,
34454 @@ -1952,7 +1952,7 @@ static struct e1000_mac_operations e8257
34455 .read_mac_addr = e1000_read_mac_addr_82571,
34456 };
34457
34458 -static struct e1000_phy_operations e82_phy_ops_igp = {
34459 +static const struct e1000_phy_operations e82_phy_ops_igp = {
34460 .acquire = e1000_get_hw_semaphore_82571,
34461 .check_polarity = e1000_check_polarity_igp,
34462 .check_reset_block = e1000e_check_reset_block_generic,
34463 @@ -1970,7 +1970,7 @@ static struct e1000_phy_operations e82_p
34464 .cfg_on_link_up = NULL,
34465 };
34466
34467 -static struct e1000_phy_operations e82_phy_ops_m88 = {
34468 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
34469 .acquire = e1000_get_hw_semaphore_82571,
34470 .check_polarity = e1000_check_polarity_m88,
34471 .check_reset_block = e1000e_check_reset_block_generic,
34472 @@ -1988,7 +1988,7 @@ static struct e1000_phy_operations e82_p
34473 .cfg_on_link_up = NULL,
34474 };
34475
34476 -static struct e1000_phy_operations e82_phy_ops_bm = {
34477 +static const struct e1000_phy_operations e82_phy_ops_bm = {
34478 .acquire = e1000_get_hw_semaphore_82571,
34479 .check_polarity = e1000_check_polarity_m88,
34480 .check_reset_block = e1000e_check_reset_block_generic,
34481 @@ -2006,7 +2006,7 @@ static struct e1000_phy_operations e82_p
34482 .cfg_on_link_up = NULL,
34483 };
34484
34485 -static struct e1000_nvm_operations e82571_nvm_ops = {
34486 +static const struct e1000_nvm_operations e82571_nvm_ops = {
34487 .acquire = e1000_acquire_nvm_82571,
34488 .read = e1000e_read_nvm_eerd,
34489 .release = e1000_release_nvm_82571,
34490 diff -urNp linux-2.6.39.1/drivers/net/e1000e/e1000.h linux-2.6.39.1/drivers/net/e1000e/e1000.h
34491 --- linux-2.6.39.1/drivers/net/e1000e/e1000.h 2011-05-19 00:06:34.000000000 -0400
34492 +++ linux-2.6.39.1/drivers/net/e1000e/e1000.h 2011-05-22 19:36:31.000000000 -0400
34493 @@ -409,9 +409,9 @@ struct e1000_info {
34494 u32 pba;
34495 u32 max_hw_frame_size;
34496 s32 (*get_variants)(struct e1000_adapter *);
34497 - struct e1000_mac_operations *mac_ops;
34498 - struct e1000_phy_operations *phy_ops;
34499 - struct e1000_nvm_operations *nvm_ops;
34500 + const struct e1000_mac_operations *mac_ops;
34501 + const struct e1000_phy_operations *phy_ops;
34502 + const struct e1000_nvm_operations *nvm_ops;
34503 };
34504
34505 /* hardware capability, feature, and workaround flags */
34506 diff -urNp linux-2.6.39.1/drivers/net/e1000e/es2lan.c linux-2.6.39.1/drivers/net/e1000e/es2lan.c
34507 --- linux-2.6.39.1/drivers/net/e1000e/es2lan.c 2011-05-19 00:06:34.000000000 -0400
34508 +++ linux-2.6.39.1/drivers/net/e1000e/es2lan.c 2011-05-22 19:36:31.000000000 -0400
34509 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es
34510 {
34511 struct e1000_hw *hw = &adapter->hw;
34512 struct e1000_mac_info *mac = &hw->mac;
34513 - struct e1000_mac_operations *func = &mac->ops;
34514 + struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34515
34516 /* Set media type */
34517 switch (adapter->pdev->device) {
34518 @@ -1431,7 +1431,7 @@ static void e1000_clear_hw_cntrs_80003es
34519 er32(ICRXDMTC);
34520 }
34521
34522 -static struct e1000_mac_operations es2_mac_ops = {
34523 +static const struct e1000_mac_operations es2_mac_ops = {
34524 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
34525 .id_led_init = e1000e_id_led_init,
34526 .check_mng_mode = e1000e_check_mng_mode_generic,
34527 @@ -1453,7 +1453,7 @@ static struct e1000_mac_operations es2_m
34528 .setup_led = e1000e_setup_led_generic,
34529 };
34530
34531 -static struct e1000_phy_operations es2_phy_ops = {
34532 +static const struct e1000_phy_operations es2_phy_ops = {
34533 .acquire = e1000_acquire_phy_80003es2lan,
34534 .check_polarity = e1000_check_polarity_m88,
34535 .check_reset_block = e1000e_check_reset_block_generic,
34536 @@ -1471,7 +1471,7 @@ static struct e1000_phy_operations es2_p
34537 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34538 };
34539
34540 -static struct e1000_nvm_operations es2_nvm_ops = {
34541 +static const struct e1000_nvm_operations es2_nvm_ops = {
34542 .acquire = e1000_acquire_nvm_80003es2lan,
34543 .read = e1000e_read_nvm_eerd,
34544 .release = e1000_release_nvm_80003es2lan,
34545 diff -urNp linux-2.6.39.1/drivers/net/e1000e/hw.h linux-2.6.39.1/drivers/net/e1000e/hw.h
34546 --- linux-2.6.39.1/drivers/net/e1000e/hw.h 2011-05-19 00:06:34.000000000 -0400
34547 +++ linux-2.6.39.1/drivers/net/e1000e/hw.h 2011-05-22 19:36:31.000000000 -0400
34548 @@ -811,6 +811,7 @@ struct e1000_nvm_operations {
34549 };
34550
34551 struct e1000_mac_info {
34552 + /* cannot be const see e1000_init_mac_params_ich8lan */
34553 struct e1000_mac_operations ops;
34554 u8 addr[ETH_ALEN];
34555 u8 perm_addr[ETH_ALEN];
34556 @@ -852,6 +853,7 @@ struct e1000_mac_info {
34557 };
34558
34559 struct e1000_phy_info {
34560 + /* Cannot be const see e1000_init_phy_params_82571() */
34561 struct e1000_phy_operations ops;
34562
34563 enum e1000_phy_type type;
34564 @@ -886,6 +888,7 @@ struct e1000_phy_info {
34565 };
34566
34567 struct e1000_nvm_info {
34568 + /* cannot be const */
34569 struct e1000_nvm_operations ops;
34570
34571 enum e1000_nvm_type type;
34572 diff -urNp linux-2.6.39.1/drivers/net/e1000e/ich8lan.c linux-2.6.39.1/drivers/net/e1000e/ich8lan.c
34573 --- linux-2.6.39.1/drivers/net/e1000e/ich8lan.c 2011-05-19 00:06:34.000000000 -0400
34574 +++ linux-2.6.39.1/drivers/net/e1000e/ich8lan.c 2011-05-22 19:36:31.000000000 -0400
34575 @@ -3866,7 +3866,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34576 }
34577 }
34578
34579 -static struct e1000_mac_operations ich8_mac_ops = {
34580 +static const struct e1000_mac_operations ich8_mac_ops = {
34581 .id_led_init = e1000e_id_led_init,
34582 /* check_mng_mode dependent on mac type */
34583 .check_for_link = e1000_check_for_copper_link_ich8lan,
34584 @@ -3885,7 +3885,7 @@ static struct e1000_mac_operations ich8_
34585 /* id_led_init dependent on mac type */
34586 };
34587
34588 -static struct e1000_phy_operations ich8_phy_ops = {
34589 +static const struct e1000_phy_operations ich8_phy_ops = {
34590 .acquire = e1000_acquire_swflag_ich8lan,
34591 .check_reset_block = e1000_check_reset_block_ich8lan,
34592 .commit = NULL,
34593 @@ -3899,7 +3899,7 @@ static struct e1000_phy_operations ich8_
34594 .write_reg = e1000e_write_phy_reg_igp,
34595 };
34596
34597 -static struct e1000_nvm_operations ich8_nvm_ops = {
34598 +static const struct e1000_nvm_operations ich8_nvm_ops = {
34599 .acquire = e1000_acquire_nvm_ich8lan,
34600 .read = e1000_read_nvm_ich8lan,
34601 .release = e1000_release_nvm_ich8lan,
34602 diff -urNp linux-2.6.39.1/drivers/net/greth.c linux-2.6.39.1/drivers/net/greth.c
34603 --- linux-2.6.39.1/drivers/net/greth.c 2011-05-19 00:06:34.000000000 -0400
34604 +++ linux-2.6.39.1/drivers/net/greth.c 2011-05-22 19:36:31.000000000 -0400
34605 @@ -1192,7 +1192,7 @@ static const struct ethtool_ops greth_et
34606 .get_link = ethtool_op_get_link,
34607 };
34608
34609 -static struct net_device_ops greth_netdev_ops = {
34610 +static const struct net_device_ops greth_netdev_ops = {
34611 .ndo_open = greth_open,
34612 .ndo_stop = greth_close,
34613 .ndo_start_xmit = greth_start_xmit,
34614 diff -urNp linux-2.6.39.1/drivers/net/hamradio/6pack.c linux-2.6.39.1/drivers/net/hamradio/6pack.c
34615 --- linux-2.6.39.1/drivers/net/hamradio/6pack.c 2011-05-19 00:06:34.000000000 -0400
34616 +++ linux-2.6.39.1/drivers/net/hamradio/6pack.c 2011-05-22 19:36:31.000000000 -0400
34617 @@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct t
34618 unsigned char buf[512];
34619 int count1;
34620
34621 + pax_track_stack();
34622 +
34623 if (!count)
34624 return;
34625
34626 diff -urNp linux-2.6.39.1/drivers/net/ibm_newemac/phy.c linux-2.6.39.1/drivers/net/ibm_newemac/phy.c
34627 --- linux-2.6.39.1/drivers/net/ibm_newemac/phy.c 2011-05-19 00:06:34.000000000 -0400
34628 +++ linux-2.6.39.1/drivers/net/ibm_newemac/phy.c 2011-05-22 19:36:31.000000000 -0400
34629 @@ -273,7 +273,7 @@ static int genmii_read_link(struct mii_p
34630 }
34631
34632 /* Generic implementation for most 10/100/1000 PHYs */
34633 -static struct mii_phy_ops generic_phy_ops = {
34634 +static const struct mii_phy_ops generic_phy_ops = {
34635 .setup_aneg = genmii_setup_aneg,
34636 .setup_forced = genmii_setup_forced,
34637 .poll_link = genmii_poll_link,
34638 @@ -337,7 +337,7 @@ static int cis8201_init(struct mii_phy *
34639 return 0;
34640 }
34641
34642 -static struct mii_phy_ops cis8201_phy_ops = {
34643 +static const struct mii_phy_ops cis8201_phy_ops = {
34644 .init = cis8201_init,
34645 .setup_aneg = genmii_setup_aneg,
34646 .setup_forced = genmii_setup_forced,
34647 @@ -417,7 +417,7 @@ static int et1011c_init(struct mii_phy *
34648 return 0;
34649 }
34650
34651 -static struct mii_phy_ops et1011c_phy_ops = {
34652 +static const struct mii_phy_ops et1011c_phy_ops = {
34653 .init = et1011c_init,
34654 .setup_aneg = genmii_setup_aneg,
34655 .setup_forced = genmii_setup_forced,
34656 @@ -436,7 +436,7 @@ static struct mii_phy_def et1011c_phy_de
34657
34658
34659
34660 -static struct mii_phy_ops m88e1111_phy_ops = {
34661 +static const struct mii_phy_ops m88e1111_phy_ops = {
34662 .init = m88e1111_init,
34663 .setup_aneg = genmii_setup_aneg,
34664 .setup_forced = genmii_setup_forced,
34665 @@ -452,7 +452,7 @@ static struct mii_phy_def m88e1111_phy_d
34666 .ops = &m88e1111_phy_ops,
34667 };
34668
34669 -static struct mii_phy_ops m88e1112_phy_ops = {
34670 +static const struct mii_phy_ops m88e1112_phy_ops = {
34671 .init = m88e1112_init,
34672 .setup_aneg = genmii_setup_aneg,
34673 .setup_forced = genmii_setup_forced,
34674 diff -urNp linux-2.6.39.1/drivers/net/ibmveth.c linux-2.6.39.1/drivers/net/ibmveth.c
34675 --- linux-2.6.39.1/drivers/net/ibmveth.c 2011-05-19 00:06:34.000000000 -0400
34676 +++ linux-2.6.39.1/drivers/net/ibmveth.c 2011-05-22 19:36:31.000000000 -0400
34677 @@ -1625,7 +1625,7 @@ static struct vio_device_id ibmveth_devi
34678 };
34679 MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
34680
34681 -static struct dev_pm_ops ibmveth_pm_ops = {
34682 +static const struct dev_pm_ops ibmveth_pm_ops = {
34683 .resume = ibmveth_resume
34684 };
34685
34686 diff -urNp linux-2.6.39.1/drivers/net/igb/e1000_82575.c linux-2.6.39.1/drivers/net/igb/e1000_82575.c
34687 --- linux-2.6.39.1/drivers/net/igb/e1000_82575.c 2011-05-19 00:06:34.000000000 -0400
34688 +++ linux-2.6.39.1/drivers/net/igb/e1000_82575.c 2011-05-22 19:36:31.000000000 -0400
34689 @@ -2029,7 +2029,7 @@ out:
34690 return ret_val;
34691 }
34692
34693 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
34694 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34695 .init_hw = igb_init_hw_82575,
34696 .check_for_link = igb_check_for_link_82575,
34697 .rar_set = igb_rar_set,
34698 @@ -2037,13 +2037,13 @@ static struct e1000_mac_operations e1000
34699 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34700 };
34701
34702 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
34703 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34704 .acquire = igb_acquire_phy_82575,
34705 .get_cfg_done = igb_get_cfg_done_82575,
34706 .release = igb_release_phy_82575,
34707 };
34708
34709 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34710 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34711 .acquire = igb_acquire_nvm_82575,
34712 .read = igb_read_nvm_eerd,
34713 .release = igb_release_nvm_82575,
34714 diff -urNp linux-2.6.39.1/drivers/net/igb/e1000_hw.h linux-2.6.39.1/drivers/net/igb/e1000_hw.h
34715 --- linux-2.6.39.1/drivers/net/igb/e1000_hw.h 2011-05-19 00:06:34.000000000 -0400
34716 +++ linux-2.6.39.1/drivers/net/igb/e1000_hw.h 2011-05-22 19:36:31.000000000 -0400
34717 @@ -342,14 +342,15 @@ struct e1000_nvm_operations {
34718
34719 struct e1000_info {
34720 s32 (*get_invariants)(struct e1000_hw *);
34721 - struct e1000_mac_operations *mac_ops;
34722 - struct e1000_phy_operations *phy_ops;
34723 - struct e1000_nvm_operations *nvm_ops;
34724 + const struct e1000_mac_operations *mac_ops;
34725 + const struct e1000_phy_operations *phy_ops;
34726 + const struct e1000_nvm_operations *nvm_ops;
34727 };
34728
34729 extern const struct e1000_info e1000_82575_info;
34730
34731 struct e1000_mac_info {
34732 + /* cannot be const see igb_get_invariants_82575() */
34733 struct e1000_mac_operations ops;
34734
34735 u8 addr[6];
34736 @@ -388,6 +389,7 @@ struct e1000_mac_info {
34737 };
34738
34739 struct e1000_phy_info {
34740 + /* cannot be const see igb_get_invariants_82575() */
34741 struct e1000_phy_operations ops;
34742
34743 enum e1000_phy_type type;
34744 @@ -423,6 +425,7 @@ struct e1000_phy_info {
34745 };
34746
34747 struct e1000_nvm_info {
34748 + /* cannot be const */
34749 struct e1000_nvm_operations ops;
34750 enum e1000_nvm_type type;
34751 enum e1000_nvm_override override;
34752 diff -urNp linux-2.6.39.1/drivers/net/igbvf/vf.h linux-2.6.39.1/drivers/net/igbvf/vf.h
34753 --- linux-2.6.39.1/drivers/net/igbvf/vf.h 2011-05-19 00:06:34.000000000 -0400
34754 +++ linux-2.6.39.1/drivers/net/igbvf/vf.h 2011-05-22 19:36:31.000000000 -0400
34755 @@ -191,6 +191,7 @@ struct e1000_mac_operations {
34756 };
34757
34758 struct e1000_mac_info {
34759 + /* cannot be const see e1000_init_mac_params_vf() */
34760 struct e1000_mac_operations ops;
34761 u8 addr[6];
34762 u8 perm_addr[6];
34763 diff -urNp linux-2.6.39.1/drivers/net/irda/sh_irda.c linux-2.6.39.1/drivers/net/irda/sh_irda.c
34764 --- linux-2.6.39.1/drivers/net/irda/sh_irda.c 2011-05-19 00:06:34.000000000 -0400
34765 +++ linux-2.6.39.1/drivers/net/irda/sh_irda.c 2011-05-22 19:36:31.000000000 -0400
34766 @@ -307,7 +307,7 @@ static int xir_fte(struct sh_irda_self *
34767 return 0;
34768 }
34769
34770 -static struct sh_irda_xir_func xir_func = {
34771 +static const struct sh_irda_xir_func xir_func = {
34772 .xir_fre = xir_fre,
34773 .xir_trov = xir_trov,
34774 .xir_9 = xir_9,
34775 @@ -321,7 +321,7 @@ static struct sh_irda_xir_func xir_func
34776 *
34777 * MIR/FIR are not supported now
34778 *=====================================*/
34779 -static struct sh_irda_xir_func mfir_func = {
34780 +static const struct sh_irda_xir_func mfir_func = {
34781 .xir_fre = xir_fre,
34782 .xir_trov = xir_trov,
34783 .xir_9 = xir_9,
34784 @@ -400,7 +400,7 @@ static int sir_fte(struct sh_irda_self *
34785 return 0;
34786 }
34787
34788 -static struct sh_irda_xir_func sir_func = {
34789 +static const struct sh_irda_xir_func sir_func = {
34790 .xir_fre = sir_fre,
34791 .xir_trov = sir_trov,
34792 .xir_9 = sir_tot,
34793 @@ -411,7 +411,7 @@ static struct sh_irda_xir_func sir_func
34794 static void sh_irda_set_mode(struct sh_irda_self *self, enum sh_irda_mode mode)
34795 {
34796 struct device *dev = &self->ndev->dev;
34797 - struct sh_irda_xir_func *func;
34798 + const struct sh_irda_xir_func *func;
34799 const char *name;
34800 u16 data;
34801
34802 diff -urNp linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c
34803 --- linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c 2011-05-19 00:06:34.000000000 -0400
34804 +++ linux-2.6.39.1/drivers/net/ixgb/ixgb_main.c 2011-05-22 19:36:31.000000000 -0400
34805 @@ -1069,6 +1069,8 @@ ixgb_set_multi(struct net_device *netdev
34806 u32 rctl;
34807 int i;
34808
34809 + pax_track_stack();
34810 +
34811 /* Check for Promiscuous and All Multicast modes */
34812
34813 rctl = IXGB_READ_REG(hw, RCTL);
34814 diff -urNp linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c
34815 --- linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c 2011-05-19 00:06:34.000000000 -0400
34816 +++ linux-2.6.39.1/drivers/net/ixgb/ixgb_param.c 2011-05-22 19:36:31.000000000 -0400
34817 @@ -261,6 +261,9 @@ void __devinit
34818 ixgb_check_options(struct ixgb_adapter *adapter)
34819 {
34820 int bd = adapter->bd_number;
34821 +
34822 + pax_track_stack();
34823 +
34824 if (bd >= IXGB_MAX_NIC) {
34825 pr_notice("Warning: no configuration for board #%i\n", bd);
34826 pr_notice("Using defaults for all values\n");
34827 diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c
34828 --- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c 2011-05-19 00:06:34.000000000 -0400
34829 +++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_82599.c 2011-05-22 19:36:31.000000000 -0400
34830 @@ -2099,7 +2099,7 @@ static struct ixgbe_phy_operations phy_o
34831 .check_overtemp = &ixgbe_tn_check_overtemp,
34832 };
34833
34834 -struct ixgbe_info ixgbe_82599_info = {
34835 +const struct ixgbe_info ixgbe_82599_info = {
34836 .mac = ixgbe_mac_82599EB,
34837 .get_invariants = &ixgbe_get_invariants_82599,
34838 .mac_ops = &mac_ops_82599,
34839 diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h
34840 --- linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h 2011-05-19 00:06:34.000000000 -0400
34841 +++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe.h 2011-05-22 19:36:31.000000000 -0400
34842 @@ -493,8 +493,8 @@ enum ixgbe_boards {
34843 };
34844
34845 extern struct ixgbe_info ixgbe_82598_info;
34846 -extern struct ixgbe_info ixgbe_82599_info;
34847 -extern struct ixgbe_info ixgbe_X540_info;
34848 +extern const struct ixgbe_info ixgbe_82599_info;
34849 +extern const struct ixgbe_info ixgbe_X540_info;
34850 #ifdef CONFIG_IXGBE_DCB
34851 extern const struct dcbnl_rtnl_ops dcbnl_ops;
34852 extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
34853 diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_type.h linux-2.6.39.1/drivers/net/ixgbe/ixgbe_type.h
34854 --- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_type.h 2011-05-19 00:06:34.000000000 -0400
34855 +++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_type.h 2011-05-22 19:36:31.000000000 -0400
34856 @@ -2572,7 +2572,7 @@ struct ixgbe_phy_operations {
34857 };
34858
34859 struct ixgbe_eeprom_info {
34860 - struct ixgbe_eeprom_operations ops;
34861 + struct ixgbe_eeprom_operations ops;
34862 enum ixgbe_eeprom_type type;
34863 u32 semaphore_delay;
34864 u16 word_size;
34865 @@ -2581,7 +2581,7 @@ struct ixgbe_eeprom_info {
34866
34867 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34868 struct ixgbe_mac_info {
34869 - struct ixgbe_mac_operations ops;
34870 + struct ixgbe_mac_operations ops;
34871 enum ixgbe_mac_type type;
34872 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34873 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34874 @@ -2608,7 +2608,7 @@ struct ixgbe_mac_info {
34875 };
34876
34877 struct ixgbe_phy_info {
34878 - struct ixgbe_phy_operations ops;
34879 + struct ixgbe_phy_operations ops;
34880 struct mdio_if_info mdio;
34881 enum ixgbe_phy_type type;
34882 u32 id;
34883 diff -urNp linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c
34884 --- linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c 2011-05-19 00:06:34.000000000 -0400
34885 +++ linux-2.6.39.1/drivers/net/ixgbe/ixgbe_x540.c 2011-05-22 19:36:31.000000000 -0400
34886 @@ -727,7 +727,7 @@ static struct ixgbe_phy_operations phy_o
34887 .check_overtemp = &ixgbe_tn_check_overtemp,
34888 };
34889
34890 -struct ixgbe_info ixgbe_X540_info = {
34891 +const struct ixgbe_info ixgbe_X540_info = {
34892 .mac = ixgbe_mac_X540,
34893 .get_invariants = &ixgbe_get_invariants_X540,
34894 .mac_ops = &mac_ops_X540,
34895 diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c
34896 --- linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c 2011-05-19 00:06:34.000000000 -0400
34897 +++ linux-2.6.39.1/drivers/net/ixgbevf/ethtool.c 2011-05-22 19:36:31.000000000 -0400
34898 @@ -709,7 +709,7 @@ static int ixgbevf_nway_reset(struct net
34899 return 0;
34900 }
34901
34902 -static struct ethtool_ops ixgbevf_ethtool_ops = {
34903 +static const struct ethtool_ops ixgbevf_ethtool_ops = {
34904 .get_settings = ixgbevf_get_settings,
34905 .get_drvinfo = ixgbevf_get_drvinfo,
34906 .get_regs_len = ixgbevf_get_regs_len,
34907 diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h
34908 --- linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h 2011-05-19 00:06:34.000000000 -0400
34909 +++ linux-2.6.39.1/drivers/net/ixgbevf/ixgbevf.h 2011-05-22 19:36:31.000000000 -0400
34910 @@ -279,7 +279,7 @@ enum ixgbevf_boards {
34911
34912 extern struct ixgbevf_info ixgbevf_82599_vf_info;
34913 extern struct ixgbevf_info ixgbevf_X540_vf_info;
34914 -extern struct ixgbe_mac_operations ixgbevf_mbx_ops;
34915 +extern const struct ixgbe_mac_operations ixgbevf_mbx_ops;
34916
34917 /* needed by ethtool.c */
34918 extern char ixgbevf_driver_name[];
34919 diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/vf.c linux-2.6.39.1/drivers/net/ixgbevf/vf.c
34920 --- linux-2.6.39.1/drivers/net/ixgbevf/vf.c 2011-05-19 00:06:34.000000000 -0400
34921 +++ linux-2.6.39.1/drivers/net/ixgbevf/vf.c 2011-05-22 19:36:31.000000000 -0400
34922 @@ -368,7 +368,7 @@ static s32 ixgbevf_check_mac_link_vf(str
34923 return 0;
34924 }
34925
34926 -static struct ixgbe_mac_operations ixgbevf_mac_ops = {
34927 +static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
34928 .init_hw = ixgbevf_init_hw_vf,
34929 .reset_hw = ixgbevf_reset_hw_vf,
34930 .start_hw = ixgbevf_start_hw_vf,
34931 @@ -381,12 +381,12 @@ static struct ixgbe_mac_operations ixgbe
34932 .set_vfta = ixgbevf_set_vfta_vf,
34933 };
34934
34935 -struct ixgbevf_info ixgbevf_82599_vf_info = {
34936 +const struct ixgbevf_info ixgbevf_82599_vf_info = {
34937 .mac = ixgbe_mac_82599_vf,
34938 .mac_ops = &ixgbevf_mac_ops,
34939 };
34940
34941 -struct ixgbevf_info ixgbevf_X540_vf_info = {
34942 +const struct ixgbevf_info ixgbevf_X540_vf_info = {
34943 .mac = ixgbe_mac_X540_vf,
34944 .mac_ops = &ixgbevf_mac_ops,
34945 };
34946 diff -urNp linux-2.6.39.1/drivers/net/ixgbevf/vf.h linux-2.6.39.1/drivers/net/ixgbevf/vf.h
34947 --- linux-2.6.39.1/drivers/net/ixgbevf/vf.h 2011-05-19 00:06:34.000000000 -0400
34948 +++ linux-2.6.39.1/drivers/net/ixgbevf/vf.h 2011-05-22 19:36:31.000000000 -0400
34949 @@ -166,7 +166,7 @@ struct ixgbevf_hw_stats {
34950
34951 struct ixgbevf_info {
34952 enum ixgbe_mac_type mac;
34953 - struct ixgbe_mac_operations *mac_ops;
34954 + const struct ixgbe_mac_operations *mac_ops;
34955 };
34956
34957 #endif /* __IXGBE_VF_H__ */
34958 diff -urNp linux-2.6.39.1/drivers/net/ksz884x.c linux-2.6.39.1/drivers/net/ksz884x.c
34959 --- linux-2.6.39.1/drivers/net/ksz884x.c 2011-05-19 00:06:34.000000000 -0400
34960 +++ linux-2.6.39.1/drivers/net/ksz884x.c 2011-05-22 19:36:31.000000000 -0400
34961 @@ -6536,6 +6536,8 @@ static void netdev_get_ethtool_stats(str
34962 int rc;
34963 u64 counter[TOTAL_PORT_COUNTER_NUM];
34964
34965 + pax_track_stack();
34966 +
34967 mutex_lock(&hw_priv->lock);
34968 n = SWITCH_PORT_NUM;
34969 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
34970 @@ -6637,7 +6639,7 @@ static int netdev_set_rx_csum(struct net
34971 return 0;
34972 }
34973
34974 -static struct ethtool_ops netdev_ethtool_ops = {
34975 +static const struct ethtool_ops netdev_ethtool_ops = {
34976 .get_settings = netdev_get_settings,
34977 .set_settings = netdev_set_settings,
34978 .nway_reset = netdev_nway_reset,
34979 diff -urNp linux-2.6.39.1/drivers/net/mlx4/main.c linux-2.6.39.1/drivers/net/mlx4/main.c
34980 --- linux-2.6.39.1/drivers/net/mlx4/main.c 2011-05-19 00:06:34.000000000 -0400
34981 +++ linux-2.6.39.1/drivers/net/mlx4/main.c 2011-05-22 19:36:31.000000000 -0400
34982 @@ -40,6 +40,7 @@
34983 #include <linux/dma-mapping.h>
34984 #include <linux/slab.h>
34985 #include <linux/io-mapping.h>
34986 +#include <linux/sched.h>
34987
34988 #include <linux/mlx4/device.h>
34989 #include <linux/mlx4/doorbell.h>
34990 @@ -764,6 +765,8 @@ static int mlx4_init_hca(struct mlx4_dev
34991 u64 icm_size;
34992 int err;
34993
34994 + pax_track_stack();
34995 +
34996 err = mlx4_QUERY_FW(dev);
34997 if (err) {
34998 if (err == -EACCES)
34999 diff -urNp linux-2.6.39.1/drivers/net/netconsole.c linux-2.6.39.1/drivers/net/netconsole.c
35000 --- linux-2.6.39.1/drivers/net/netconsole.c 2011-05-19 00:06:34.000000000 -0400
35001 +++ linux-2.6.39.1/drivers/net/netconsole.c 2011-05-22 19:36:31.000000000 -0400
35002 @@ -634,7 +634,7 @@ static void drop_netconsole_target(struc
35003 config_item_put(&nt->item);
35004 }
35005
35006 -static struct configfs_group_operations netconsole_subsys_group_ops = {
35007 +static const struct configfs_group_operations netconsole_subsys_group_ops = {
35008 .make_item = make_netconsole_target,
35009 .drop_item = drop_netconsole_target,
35010 };
35011 diff -urNp linux-2.6.39.1/drivers/net/niu.c linux-2.6.39.1/drivers/net/niu.c
35012 --- linux-2.6.39.1/drivers/net/niu.c 2011-05-19 00:06:34.000000000 -0400
35013 +++ linux-2.6.39.1/drivers/net/niu.c 2011-05-22 19:36:31.000000000 -0400
35014 @@ -9067,6 +9067,8 @@ static void __devinit niu_try_msix(struc
35015 int i, num_irqs, err;
35016 u8 first_ldg;
35017
35018 + pax_track_stack();
35019 +
35020 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
35021 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
35022 ldg_num_map[i] = first_ldg + i;
35023 diff -urNp linux-2.6.39.1/drivers/net/pcnet32.c linux-2.6.39.1/drivers/net/pcnet32.c
35024 --- linux-2.6.39.1/drivers/net/pcnet32.c 2011-05-19 00:06:34.000000000 -0400
35025 +++ linux-2.6.39.1/drivers/net/pcnet32.c 2011-05-22 19:36:31.000000000 -0400
35026 @@ -82,7 +82,7 @@ static int cards_found;
35027 /*
35028 * VLB I/O addresses
35029 */
35030 -static unsigned int pcnet32_portlist[] __initdata =
35031 +static unsigned int pcnet32_portlist[] __devinitdata =
35032 { 0x300, 0x320, 0x340, 0x360, 0 };
35033
35034 static int pcnet32_debug;
35035 @@ -379,7 +379,7 @@ static int pcnet32_wio_check(unsigned lo
35036 return inw(addr + PCNET32_WIO_RAP) == 88;
35037 }
35038
35039 -static struct pcnet32_access pcnet32_wio = {
35040 +static const struct pcnet32_access pcnet32_wio = {
35041 .read_csr = pcnet32_wio_read_csr,
35042 .write_csr = pcnet32_wio_write_csr,
35043 .read_bcr = pcnet32_wio_read_bcr,
35044 @@ -434,7 +434,7 @@ static int pcnet32_dwio_check(unsigned l
35045 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88;
35046 }
35047
35048 -static struct pcnet32_access pcnet32_dwio = {
35049 +static const struct pcnet32_access pcnet32_dwio = {
35050 .read_csr = pcnet32_dwio_read_csr,
35051 .write_csr = pcnet32_dwio_write_csr,
35052 .read_bcr = pcnet32_dwio_read_bcr,
35053 @@ -1546,7 +1546,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35054 int chip_version;
35055 char *chipname;
35056 struct net_device *dev;
35057 - struct pcnet32_access *a = NULL;
35058 + const struct pcnet32_access *a = NULL;
35059 u8 promaddr[6];
35060 int ret = -ENODEV;
35061
35062 diff -urNp linux-2.6.39.1/drivers/net/ppp_generic.c linux-2.6.39.1/drivers/net/ppp_generic.c
35063 --- linux-2.6.39.1/drivers/net/ppp_generic.c 2011-05-19 00:06:34.000000000 -0400
35064 +++ linux-2.6.39.1/drivers/net/ppp_generic.c 2011-05-22 19:36:31.000000000 -0400
35065 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, st
35066 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35067 struct ppp_stats stats;
35068 struct ppp_comp_stats cstats;
35069 - char *vers;
35070
35071 switch (cmd) {
35072 case SIOCGPPPSTATS:
35073 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, st
35074 break;
35075
35076 case SIOCGPPPVER:
35077 - vers = PPP_VERSION;
35078 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35079 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35080 break;
35081 err = 0;
35082 break;
35083 diff -urNp linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h
35084 --- linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h 2011-05-19 00:06:34.000000000 -0400
35085 +++ linux-2.6.39.1/drivers/net/qlcnic/qlcnic.h 2011-05-22 19:36:31.000000000 -0400
35086 @@ -1037,7 +1037,7 @@ struct qlcnic_adapter {
35087 struct vlan_group *vlgrp;
35088 struct qlcnic_npar_info *npars;
35089 struct qlcnic_eswitch *eswitch;
35090 - struct qlcnic_nic_template *nic_ops;
35091 + const struct qlcnic_nic_template *nic_ops;
35092
35093 struct qlcnic_adapter_stats stats;
35094
35095 diff -urNp linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c
35096 --- linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c 2011-05-19 00:06:34.000000000 -0400
35097 +++ linux-2.6.39.1/drivers/net/qlcnic/qlcnic_main.c 2011-05-22 19:36:31.000000000 -0400
35098 @@ -340,13 +340,13 @@ static const struct net_device_ops qlcni
35099 #endif
35100 };
35101
35102 -static struct qlcnic_nic_template qlcnic_ops = {
35103 +static const struct qlcnic_nic_template qlcnic_ops = {
35104 .config_bridged_mode = qlcnic_config_bridged_mode,
35105 .config_led = qlcnic_config_led,
35106 .start_firmware = qlcnic_start_firmware
35107 };
35108
35109 -static struct qlcnic_nic_template qlcnic_vf_ops = {
35110 +static const struct qlcnic_nic_template qlcnic_vf_ops = {
35111 .config_bridged_mode = qlcnicvf_config_bridged_mode,
35112 .config_led = qlcnicvf_config_led,
35113 .start_firmware = qlcnicvf_start_firmware
35114 diff -urNp linux-2.6.39.1/drivers/net/qlge/qlge.h linux-2.6.39.1/drivers/net/qlge/qlge.h
35115 --- linux-2.6.39.1/drivers/net/qlge/qlge.h 2011-05-19 00:06:34.000000000 -0400
35116 +++ linux-2.6.39.1/drivers/net/qlge/qlge.h 2011-05-22 19:36:31.000000000 -0400
35117 @@ -2134,7 +2134,7 @@ struct ql_adapter {
35118 struct delayed_work mpi_idc_work;
35119 struct delayed_work mpi_core_to_log;
35120 struct completion ide_completion;
35121 - struct nic_operations *nic_ops;
35122 + const struct nic_operations *nic_ops;
35123 u16 device_id;
35124 struct timer_list timer;
35125 atomic_t lb_count;
35126 diff -urNp linux-2.6.39.1/drivers/net/qlge/qlge_main.c linux-2.6.39.1/drivers/net/qlge/qlge_main.c
35127 --- linux-2.6.39.1/drivers/net/qlge/qlge_main.c 2011-05-19 00:06:34.000000000 -0400
35128 +++ linux-2.6.39.1/drivers/net/qlge/qlge_main.c 2011-05-22 19:36:31.000000000 -0400
35129 @@ -4412,12 +4412,12 @@ error:
35130 rtnl_unlock();
35131 }
35132
35133 -static struct nic_operations qla8012_nic_ops = {
35134 +static const struct nic_operations qla8012_nic_ops = {
35135 .get_flash = ql_get_8012_flash_params,
35136 .port_initialize = ql_8012_port_initialize,
35137 };
35138
35139 -static struct nic_operations qla8000_nic_ops = {
35140 +static const struct nic_operations qla8000_nic_ops = {
35141 .get_flash = ql_get_8000_flash_params,
35142 .port_initialize = ql_8000_port_initialize,
35143 };
35144 diff -urNp linux-2.6.39.1/drivers/net/sfc/falcon.c linux-2.6.39.1/drivers/net/sfc/falcon.c
35145 --- linux-2.6.39.1/drivers/net/sfc/falcon.c 2011-05-19 00:06:34.000000000 -0400
35146 +++ linux-2.6.39.1/drivers/net/sfc/falcon.c 2011-05-22 19:36:31.000000000 -0400
35147 @@ -1703,7 +1703,7 @@ static int falcon_set_wol(struct efx_nic
35148 **************************************************************************
35149 */
35150
35151 -struct efx_nic_type falcon_a1_nic_type = {
35152 +const struct efx_nic_type falcon_a1_nic_type = {
35153 .probe = falcon_probe_nic,
35154 .remove = falcon_remove_nic,
35155 .init = falcon_init_nic,
35156 @@ -1744,7 +1744,7 @@ struct efx_nic_type falcon_a1_nic_type =
35157 .reset_world_flags = ETH_RESET_IRQ,
35158 };
35159
35160 -struct efx_nic_type falcon_b0_nic_type = {
35161 +const struct efx_nic_type falcon_b0_nic_type = {
35162 .probe = falcon_probe_nic,
35163 .remove = falcon_remove_nic,
35164 .init = falcon_init_nic,
35165 diff -urNp linux-2.6.39.1/drivers/net/sfc/mtd.c linux-2.6.39.1/drivers/net/sfc/mtd.c
35166 --- linux-2.6.39.1/drivers/net/sfc/mtd.c 2011-05-19 00:06:34.000000000 -0400
35167 +++ linux-2.6.39.1/drivers/net/sfc/mtd.c 2011-05-22 19:36:31.000000000 -0400
35168 @@ -382,7 +382,7 @@ static int falcon_mtd_sync(struct mtd_in
35169 return rc;
35170 }
35171
35172 -static struct efx_mtd_ops falcon_mtd_ops = {
35173 +static const struct efx_mtd_ops falcon_mtd_ops = {
35174 .read = falcon_mtd_read,
35175 .erase = falcon_mtd_erase,
35176 .write = falcon_mtd_write,
35177 @@ -560,7 +560,7 @@ static int siena_mtd_sync(struct mtd_inf
35178 return rc;
35179 }
35180
35181 -static struct efx_mtd_ops siena_mtd_ops = {
35182 +static const struct efx_mtd_ops siena_mtd_ops = {
35183 .read = siena_mtd_read,
35184 .erase = siena_mtd_erase,
35185 .write = siena_mtd_write,
35186 diff -urNp linux-2.6.39.1/drivers/net/sfc/nic.h linux-2.6.39.1/drivers/net/sfc/nic.h
35187 --- linux-2.6.39.1/drivers/net/sfc/nic.h 2011-05-19 00:06:34.000000000 -0400
35188 +++ linux-2.6.39.1/drivers/net/sfc/nic.h 2011-05-22 19:36:31.000000000 -0400
35189 @@ -152,9 +152,9 @@ struct siena_nic_data {
35190 int wol_filter_id;
35191 };
35192
35193 -extern struct efx_nic_type falcon_a1_nic_type;
35194 -extern struct efx_nic_type falcon_b0_nic_type;
35195 -extern struct efx_nic_type siena_a0_nic_type;
35196 +extern const struct efx_nic_type falcon_a1_nic_type;
35197 +extern const struct efx_nic_type falcon_b0_nic_type;
35198 +extern const struct efx_nic_type siena_a0_nic_type;
35199
35200 /**************************************************************************
35201 *
35202 diff -urNp linux-2.6.39.1/drivers/net/sfc/siena.c linux-2.6.39.1/drivers/net/sfc/siena.c
35203 --- linux-2.6.39.1/drivers/net/sfc/siena.c 2011-05-19 00:06:34.000000000 -0400
35204 +++ linux-2.6.39.1/drivers/net/sfc/siena.c 2011-05-22 19:36:31.000000000 -0400
35205 @@ -599,7 +599,7 @@ static void siena_init_wol(struct efx_ni
35206 **************************************************************************
35207 */
35208
35209 -struct efx_nic_type siena_a0_nic_type = {
35210 +const struct efx_nic_type siena_a0_nic_type = {
35211 .probe = siena_probe_nic,
35212 .remove = siena_remove_nic,
35213 .init = siena_init_nic,
35214 diff -urNp linux-2.6.39.1/drivers/net/sh_eth.c linux-2.6.39.1/drivers/net/sh_eth.c
35215 --- linux-2.6.39.1/drivers/net/sh_eth.c 2011-05-19 00:06:34.000000000 -0400
35216 +++ linux-2.6.39.1/drivers/net/sh_eth.c 2011-05-22 19:36:31.000000000 -0400
35217 @@ -1360,7 +1360,7 @@ static void sh_eth_get_strings(struct ne
35218 }
35219 }
35220
35221 -static struct ethtool_ops sh_eth_ethtool_ops = {
35222 +static const struct ethtool_ops sh_eth_ethtool_ops = {
35223 .get_settings = sh_eth_get_settings,
35224 .set_settings = sh_eth_set_settings,
35225 .nway_reset = sh_eth_nway_reset,
35226 diff -urNp linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c
35227 --- linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35228 +++ linux-2.6.39.1/drivers/net/stmmac/stmmac_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35229 @@ -348,7 +348,7 @@ static int stmmac_set_wol(struct net_dev
35230 return 0;
35231 }
35232
35233 -static struct ethtool_ops stmmac_ethtool_ops = {
35234 +static const struct ethtool_ops stmmac_ethtool_ops = {
35235 .begin = stmmac_check_if_running,
35236 .get_drvinfo = stmmac_ethtool_getdrvinfo,
35237 .get_settings = stmmac_ethtool_getsettings,
35238 diff -urNp linux-2.6.39.1/drivers/net/sungem_phy.c linux-2.6.39.1/drivers/net/sungem_phy.c
35239 --- linux-2.6.39.1/drivers/net/sungem_phy.c 2011-05-19 00:06:34.000000000 -0400
35240 +++ linux-2.6.39.1/drivers/net/sungem_phy.c 2011-05-22 19:36:31.000000000 -0400
35241 @@ -886,7 +886,7 @@ static int marvell_read_link(struct mii_
35242 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
35243
35244 /* Broadcom BCM 5201 */
35245 -static struct mii_phy_ops bcm5201_phy_ops = {
35246 +static const struct mii_phy_ops bcm5201_phy_ops = {
35247 .init = bcm5201_init,
35248 .suspend = bcm5201_suspend,
35249 .setup_aneg = genmii_setup_aneg,
35250 @@ -905,7 +905,7 @@ static struct mii_phy_def bcm5201_phy_de
35251 };
35252
35253 /* Broadcom BCM 5221 */
35254 -static struct mii_phy_ops bcm5221_phy_ops = {
35255 +static const struct mii_phy_ops bcm5221_phy_ops = {
35256 .suspend = bcm5221_suspend,
35257 .init = bcm5221_init,
35258 .setup_aneg = genmii_setup_aneg,
35259 @@ -924,7 +924,7 @@ static struct mii_phy_def bcm5221_phy_de
35260 };
35261
35262 /* Broadcom BCM 5241 */
35263 -static struct mii_phy_ops bcm5241_phy_ops = {
35264 +static const struct mii_phy_ops bcm5241_phy_ops = {
35265 .suspend = bcm5241_suspend,
35266 .init = bcm5241_init,
35267 .setup_aneg = genmii_setup_aneg,
35268 @@ -942,7 +942,7 @@ static struct mii_phy_def bcm5241_phy_de
35269 };
35270
35271 /* Broadcom BCM 5400 */
35272 -static struct mii_phy_ops bcm5400_phy_ops = {
35273 +static const struct mii_phy_ops bcm5400_phy_ops = {
35274 .init = bcm5400_init,
35275 .suspend = bcm5400_suspend,
35276 .setup_aneg = bcm54xx_setup_aneg,
35277 @@ -961,7 +961,7 @@ static struct mii_phy_def bcm5400_phy_de
35278 };
35279
35280 /* Broadcom BCM 5401 */
35281 -static struct mii_phy_ops bcm5401_phy_ops = {
35282 +static const struct mii_phy_ops bcm5401_phy_ops = {
35283 .init = bcm5401_init,
35284 .suspend = bcm5401_suspend,
35285 .setup_aneg = bcm54xx_setup_aneg,
35286 @@ -980,7 +980,7 @@ static struct mii_phy_def bcm5401_phy_de
35287 };
35288
35289 /* Broadcom BCM 5411 */
35290 -static struct mii_phy_ops bcm5411_phy_ops = {
35291 +static const struct mii_phy_ops bcm5411_phy_ops = {
35292 .init = bcm5411_init,
35293 .suspend = generic_suspend,
35294 .setup_aneg = bcm54xx_setup_aneg,
35295 @@ -999,7 +999,7 @@ static struct mii_phy_def bcm5411_phy_de
35296 };
35297
35298 /* Broadcom BCM 5421 */
35299 -static struct mii_phy_ops bcm5421_phy_ops = {
35300 +static const struct mii_phy_ops bcm5421_phy_ops = {
35301 .init = bcm5421_init,
35302 .suspend = generic_suspend,
35303 .setup_aneg = bcm54xx_setup_aneg,
35304 @@ -1019,7 +1019,7 @@ static struct mii_phy_def bcm5421_phy_de
35305 };
35306
35307 /* Broadcom BCM 5421 built-in K2 */
35308 -static struct mii_phy_ops bcm5421k2_phy_ops = {
35309 +static const struct mii_phy_ops bcm5421k2_phy_ops = {
35310 .init = bcm5421_init,
35311 .suspend = generic_suspend,
35312 .setup_aneg = bcm54xx_setup_aneg,
35313 @@ -1037,7 +1037,7 @@ static struct mii_phy_def bcm5421k2_phy_
35314 .ops = &bcm5421k2_phy_ops
35315 };
35316
35317 -static struct mii_phy_ops bcm5461_phy_ops = {
35318 +static const struct mii_phy_ops bcm5461_phy_ops = {
35319 .init = bcm5421_init,
35320 .suspend = generic_suspend,
35321 .setup_aneg = bcm54xx_setup_aneg,
35322 @@ -1057,7 +1057,7 @@ static struct mii_phy_def bcm5461_phy_de
35323 };
35324
35325 /* Broadcom BCM 5462 built-in Vesta */
35326 -static struct mii_phy_ops bcm5462V_phy_ops = {
35327 +static const struct mii_phy_ops bcm5462V_phy_ops = {
35328 .init = bcm5421_init,
35329 .suspend = generic_suspend,
35330 .setup_aneg = bcm54xx_setup_aneg,
35331 @@ -1076,7 +1076,7 @@ static struct mii_phy_def bcm5462V_phy_d
35332 };
35333
35334 /* Marvell 88E1101 amd 88E1111 */
35335 -static struct mii_phy_ops marvell88e1101_phy_ops = {
35336 +static const struct mii_phy_ops marvell88e1101_phy_ops = {
35337 .suspend = generic_suspend,
35338 .setup_aneg = marvell_setup_aneg,
35339 .setup_forced = marvell_setup_forced,
35340 @@ -1084,7 +1084,7 @@ static struct mii_phy_ops marvell88e1101
35341 .read_link = marvell_read_link
35342 };
35343
35344 -static struct mii_phy_ops marvell88e1111_phy_ops = {
35345 +static const struct mii_phy_ops marvell88e1111_phy_ops = {
35346 .init = marvell88e1111_init,
35347 .suspend = generic_suspend,
35348 .setup_aneg = marvell_setup_aneg,
35349 @@ -1122,7 +1122,7 @@ static struct mii_phy_def marvell88e1111
35350 };
35351
35352 /* Generic implementation for most 10/100 PHYs */
35353 -static struct mii_phy_ops generic_phy_ops = {
35354 +static const struct mii_phy_ops generic_phy_ops = {
35355 .setup_aneg = genmii_setup_aneg,
35356 .setup_forced = genmii_setup_forced,
35357 .poll_link = genmii_poll_link,
35358 diff -urNp linux-2.6.39.1/drivers/net/tg3.h linux-2.6.39.1/drivers/net/tg3.h
35359 --- linux-2.6.39.1/drivers/net/tg3.h 2011-05-19 00:06:34.000000000 -0400
35360 +++ linux-2.6.39.1/drivers/net/tg3.h 2011-05-22 19:36:31.000000000 -0400
35361 @@ -131,6 +131,7 @@
35362 #define CHIPREV_ID_5750_A0 0x4000
35363 #define CHIPREV_ID_5750_A1 0x4001
35364 #define CHIPREV_ID_5750_A3 0x4003
35365 +#define CHIPREV_ID_5750_C1 0x4201
35366 #define CHIPREV_ID_5750_C2 0x4202
35367 #define CHIPREV_ID_5752_A0_HW 0x5000
35368 #define CHIPREV_ID_5752_A0 0x6000
35369 diff -urNp linux-2.6.39.1/drivers/net/tile/tilepro.c linux-2.6.39.1/drivers/net/tile/tilepro.c
35370 --- linux-2.6.39.1/drivers/net/tile/tilepro.c 2011-05-19 00:06:34.000000000 -0400
35371 +++ linux-2.6.39.1/drivers/net/tile/tilepro.c 2011-05-22 19:36:31.000000000 -0400
35372 @@ -2263,7 +2263,7 @@ static int tile_net_get_mac(struct net_d
35373 }
35374
35375
35376 -static struct net_device_ops tile_net_ops = {
35377 +static const struct net_device_ops tile_net_ops = {
35378 .ndo_open = tile_net_open,
35379 .ndo_stop = tile_net_stop,
35380 .ndo_start_xmit = tile_net_tx,
35381 diff -urNp linux-2.6.39.1/drivers/net/tulip/de2104x.c linux-2.6.39.1/drivers/net/tulip/de2104x.c
35382 --- linux-2.6.39.1/drivers/net/tulip/de2104x.c 2011-05-19 00:06:34.000000000 -0400
35383 +++ linux-2.6.39.1/drivers/net/tulip/de2104x.c 2011-05-22 19:36:31.000000000 -0400
35384 @@ -1817,6 +1817,8 @@ static void __devinit de21041_get_srom_i
35385 struct de_srom_info_leaf *il;
35386 void *bufp;
35387
35388 + pax_track_stack();
35389 +
35390 /* download entire eeprom */
35391 for (i = 0; i < DE_EEPROM_WORDS; i++)
35392 ((__le16 *)ee_data)[i] =
35393 diff -urNp linux-2.6.39.1/drivers/net/tulip/de4x5.c linux-2.6.39.1/drivers/net/tulip/de4x5.c
35394 --- linux-2.6.39.1/drivers/net/tulip/de4x5.c 2011-05-19 00:06:34.000000000 -0400
35395 +++ linux-2.6.39.1/drivers/net/tulip/de4x5.c 2011-05-22 19:36:31.000000000 -0400
35396 @@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
35397 for (i=0; i<ETH_ALEN; i++) {
35398 tmp.addr[i] = dev->dev_addr[i];
35399 }
35400 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35401 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35402 break;
35403
35404 case DE4X5_SET_HWADDR: /* Set the hardware address */
35405 @@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
35406 spin_lock_irqsave(&lp->lock, flags);
35407 memcpy(&statbuf, &lp->pktStats, ioc->len);
35408 spin_unlock_irqrestore(&lp->lock, flags);
35409 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35410 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35411 return -EFAULT;
35412 break;
35413 }
35414 diff -urNp linux-2.6.39.1/drivers/net/usb/asix.c linux-2.6.39.1/drivers/net/usb/asix.c
35415 --- linux-2.6.39.1/drivers/net/usb/asix.c 2011-05-19 00:06:34.000000000 -0400
35416 +++ linux-2.6.39.1/drivers/net/usb/asix.c 2011-05-22 19:36:31.000000000 -0400
35417 @@ -1098,7 +1098,7 @@ out:
35418 return ret;
35419 }
35420
35421 -static struct ethtool_ops ax88178_ethtool_ops = {
35422 +static const struct ethtool_ops ax88178_ethtool_ops = {
35423 .get_drvinfo = asix_get_drvinfo,
35424 .get_link = asix_get_link,
35425 .get_msglevel = usbnet_get_msglevel,
35426 diff -urNp linux-2.6.39.1/drivers/net/usb/cdc_ncm.c linux-2.6.39.1/drivers/net/usb/cdc_ncm.c
35427 --- linux-2.6.39.1/drivers/net/usb/cdc_ncm.c 2011-05-19 00:06:34.000000000 -0400
35428 +++ linux-2.6.39.1/drivers/net/usb/cdc_ncm.c 2011-05-22 19:36:31.000000000 -0400
35429 @@ -141,7 +141,7 @@ struct cdc_ncm_ctx {
35430 static void cdc_ncm_tx_timeout(unsigned long arg);
35431 static const struct driver_info cdc_ncm_info;
35432 static struct usb_driver cdc_ncm_driver;
35433 -static struct ethtool_ops cdc_ncm_ethtool_ops;
35434 +static const struct ethtool_ops cdc_ncm_ethtool_ops;
35435
35436 static const struct usb_device_id cdc_devs[] = {
35437 { USB_INTERFACE_INFO(USB_CLASS_COMM,
35438 @@ -1257,7 +1257,7 @@ static struct usb_driver cdc_ncm_driver
35439 .supports_autosuspend = 1,
35440 };
35441
35442 -static struct ethtool_ops cdc_ncm_ethtool_ops = {
35443 +static const struct ethtool_ops cdc_ncm_ethtool_ops = {
35444 .get_drvinfo = cdc_ncm_get_drvinfo,
35445 .get_link = usbnet_get_link,
35446 .get_msglevel = usbnet_get_msglevel,
35447 diff -urNp linux-2.6.39.1/drivers/net/usb/hso.c linux-2.6.39.1/drivers/net/usb/hso.c
35448 --- linux-2.6.39.1/drivers/net/usb/hso.c 2011-05-19 00:06:34.000000000 -0400
35449 +++ linux-2.6.39.1/drivers/net/usb/hso.c 2011-05-22 19:36:31.000000000 -0400
35450 @@ -71,7 +71,7 @@
35451 #include <asm/byteorder.h>
35452 #include <linux/serial_core.h>
35453 #include <linux/serial.h>
35454 -
35455 +#include <asm/local.h>
35456
35457 #define MOD_AUTHOR "Option Wireless"
35458 #define MOD_DESCRIPTION "USB High Speed Option driver"
35459 @@ -257,7 +257,7 @@ struct hso_serial {
35460
35461 /* from usb_serial_port */
35462 struct tty_struct *tty;
35463 - int open_count;
35464 + local_t open_count;
35465 spinlock_t serial_lock;
35466
35467 int (*write_data) (struct hso_serial *serial);
35468 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_
35469 struct urb *urb;
35470
35471 urb = serial->rx_urb[0];
35472 - if (serial->open_count > 0) {
35473 + if (local_read(&serial->open_count) > 0) {
35474 count = put_rxbuf_data(urb, serial);
35475 if (count == -1)
35476 return;
35477 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_cal
35478 DUMP1(urb->transfer_buffer, urb->actual_length);
35479
35480 /* Anyone listening? */
35481 - if (serial->open_count == 0)
35482 + if (local_read(&serial->open_count) == 0)
35483 return;
35484
35485 if (status == 0) {
35486 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35487 spin_unlock_irq(&serial->serial_lock);
35488
35489 /* check for port already opened, if not set the termios */
35490 - serial->open_count++;
35491 - if (serial->open_count == 1) {
35492 + if (local_inc_return(&serial->open_count) == 1) {
35493 serial->rx_state = RX_IDLE;
35494 /* Force default termio settings */
35495 _hso_serial_set_termios(tty, NULL);
35496 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_st
35497 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35498 if (result) {
35499 hso_stop_serial_device(serial->parent);
35500 - serial->open_count--;
35501 + local_dec(&serial->open_count);
35502 kref_put(&serial->parent->ref, hso_serial_ref_free);
35503 }
35504 } else {
35505 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_
35506
35507 /* reset the rts and dtr */
35508 /* do the actual close */
35509 - serial->open_count--;
35510 + local_dec(&serial->open_count);
35511
35512 - if (serial->open_count <= 0) {
35513 - serial->open_count = 0;
35514 + if (local_read(&serial->open_count) <= 0) {
35515 + local_set(&serial->open_count, 0);
35516 spin_lock_irq(&serial->serial_lock);
35517 if (serial->tty == tty) {
35518 serial->tty->driver_data = NULL;
35519 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struc
35520
35521 /* the actual setup */
35522 spin_lock_irqsave(&serial->serial_lock, flags);
35523 - if (serial->open_count)
35524 + if (local_read(&serial->open_count))
35525 _hso_serial_set_termios(tty, old);
35526 else
35527 tty->termios = old;
35528 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *ur
35529 D1("Pending read interrupt on port %d\n", i);
35530 spin_lock(&serial->serial_lock);
35531 if (serial->rx_state == RX_IDLE &&
35532 - serial->open_count > 0) {
35533 + local_read(&serial->open_count) > 0) {
35534 /* Setup and send a ctrl req read on
35535 * port i */
35536 if (!serial->rx_urb_filled[0]) {
35537 @@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35538 /* Start all serial ports */
35539 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35540 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35541 - if (dev2ser(serial_table[i])->open_count) {
35542 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35543 result =
35544 hso_start_serial_device(serial_table[i], GFP_NOIO);
35545 hso_kick_transmit(dev2ser(serial_table[i]));
35546 diff -urNp linux-2.6.39.1/drivers/net/usb/ipheth.c linux-2.6.39.1/drivers/net/usb/ipheth.c
35547 --- linux-2.6.39.1/drivers/net/usb/ipheth.c 2011-05-19 00:06:34.000000000 -0400
35548 +++ linux-2.6.39.1/drivers/net/usb/ipheth.c 2011-05-22 19:36:31.000000000 -0400
35549 @@ -421,7 +421,7 @@ static u32 ipheth_ethtool_op_get_link(st
35550 return netif_carrier_ok(dev->net);
35551 }
35552
35553 -static struct ethtool_ops ops = {
35554 +static const struct ethtool_ops ops = {
35555 .get_link = ipheth_ethtool_op_get_link
35556 };
35557
35558 diff -urNp linux-2.6.39.1/drivers/net/usb/sierra_net.c linux-2.6.39.1/drivers/net/usb/sierra_net.c
35559 --- linux-2.6.39.1/drivers/net/usb/sierra_net.c 2011-05-19 00:06:34.000000000 -0400
35560 +++ linux-2.6.39.1/drivers/net/usb/sierra_net.c 2011-05-22 19:36:31.000000000 -0400
35561 @@ -618,7 +618,7 @@ static u32 sierra_net_get_link(struct ne
35562 return sierra_net_get_private(dev)->link_up && netif_running(net);
35563 }
35564
35565 -static struct ethtool_ops sierra_net_ethtool_ops = {
35566 +static const struct ethtool_ops sierra_net_ethtool_ops = {
35567 .get_drvinfo = sierra_net_get_drvinfo,
35568 .get_link = sierra_net_get_link,
35569 .get_msglevel = usbnet_get_msglevel,
35570 diff -urNp linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c
35571 --- linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35572 +++ linux-2.6.39.1/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35573 @@ -631,8 +631,7 @@ vmxnet3_set_rss_indir(struct net_device
35574 * Return with error code if any of the queue indices
35575 * is out of range
35576 */
35577 - if (p->ring_index[i] < 0 ||
35578 - p->ring_index[i] >= adapter->num_rx_queues)
35579 + if (p->ring_index[i] >= adapter->num_rx_queues)
35580 return -EINVAL;
35581 }
35582
35583 diff -urNp linux-2.6.39.1/drivers/net/vxge/vxge-config.h linux-2.6.39.1/drivers/net/vxge/vxge-config.h
35584 --- linux-2.6.39.1/drivers/net/vxge/vxge-config.h 2011-05-19 00:06:34.000000000 -0400
35585 +++ linux-2.6.39.1/drivers/net/vxge/vxge-config.h 2011-05-22 19:36:31.000000000 -0400
35586 @@ -834,7 +834,7 @@ struct vxge_hw_device_hw_info {
35587 struct vxge_hw_device_attr {
35588 void __iomem *bar0;
35589 struct pci_dev *pdev;
35590 - struct vxge_hw_uld_cbs uld_callbacks;
35591 + struct vxge_hw_uld_cbs uld_callbacks;
35592 };
35593
35594 #define VXGE_HW_DEVICE_LINK_STATE_SET(hldev, ls) (hldev->link_state = ls)
35595 diff -urNp linux-2.6.39.1/drivers/net/vxge/vxge-main.c linux-2.6.39.1/drivers/net/vxge/vxge-main.c
35596 --- linux-2.6.39.1/drivers/net/vxge/vxge-main.c 2011-05-19 00:06:34.000000000 -0400
35597 +++ linux-2.6.39.1/drivers/net/vxge/vxge-main.c 2011-05-22 19:36:31.000000000 -0400
35598 @@ -97,6 +97,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35599 struct sk_buff *completed[NR_SKB_COMPLETED];
35600 int more;
35601
35602 + pax_track_stack();
35603 +
35604 do {
35605 more = 0;
35606 skb_ptr = completed;
35607 @@ -1927,6 +1929,8 @@ static enum vxge_hw_status vxge_rth_conf
35608 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35609 int index;
35610
35611 + pax_track_stack();
35612 +
35613 /*
35614 * Filling
35615 * - itable with bucket numbers
35616 diff -urNp linux-2.6.39.1/drivers/net/wan/cycx_x25.c linux-2.6.39.1/drivers/net/wan/cycx_x25.c
35617 --- linux-2.6.39.1/drivers/net/wan/cycx_x25.c 2011-05-19 00:06:34.000000000 -0400
35618 +++ linux-2.6.39.1/drivers/net/wan/cycx_x25.c 2011-05-22 19:36:31.000000000 -0400
35619 @@ -1018,6 +1018,8 @@ static void hex_dump(char *msg, unsigned
35620 unsigned char hex[1024],
35621 * phex = hex;
35622
35623 + pax_track_stack();
35624 +
35625 if (len >= (sizeof(hex) / 2))
35626 len = (sizeof(hex) / 2) - 1;
35627
35628 diff -urNp linux-2.6.39.1/drivers/net/wan/lapbether.c linux-2.6.39.1/drivers/net/wan/lapbether.c
35629 --- linux-2.6.39.1/drivers/net/wan/lapbether.c 2011-05-19 00:06:34.000000000 -0400
35630 +++ linux-2.6.39.1/drivers/net/wan/lapbether.c 2011-05-22 19:36:31.000000000 -0400
35631 @@ -259,7 +259,7 @@ static int lapbeth_set_mac_address(struc
35632 }
35633
35634
35635 -static struct lapb_register_struct lapbeth_callbacks = {
35636 +static const struct lapb_register_struct lapbeth_callbacks = {
35637 .connect_confirmation = lapbeth_connected,
35638 .connect_indication = lapbeth_connected,
35639 .disconnect_confirmation = lapbeth_disconnected,
35640 diff -urNp linux-2.6.39.1/drivers/net/wan/x25_asy.c linux-2.6.39.1/drivers/net/wan/x25_asy.c
35641 --- linux-2.6.39.1/drivers/net/wan/x25_asy.c 2011-05-19 00:06:34.000000000 -0400
35642 +++ linux-2.6.39.1/drivers/net/wan/x25_asy.c 2011-05-22 19:36:31.000000000 -0400
35643 @@ -434,7 +434,7 @@ static void x25_asy_disconnected(struct
35644 netif_rx(skb);
35645 }
35646
35647 -static struct lapb_register_struct x25_asy_callbacks = {
35648 +static const struct lapb_register_struct x25_asy_callbacks = {
35649 .connect_confirmation = x25_asy_connected,
35650 .connect_indication = x25_asy_connected,
35651 .disconnect_confirmation = x25_asy_disconnected,
35652 diff -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
35653 --- linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c 2011-05-19 00:06:34.000000000 -0400
35654 +++ linux-2.6.39.1/drivers/net/wimax/i2400m/usb-fw.c 2011-05-22 19:36:31.000000000 -0400
35655 @@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35656 int do_autopm = 1;
35657 DECLARE_COMPLETION_ONSTACK(notif_completion);
35658
35659 + pax_track_stack();
35660 +
35661 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35662 i2400m, ack, ack_size);
35663 BUG_ON(_ack == i2400m->bm_ack_buf);
35664 diff -urNp linux-2.6.39.1/drivers/net/wireless/airo.c linux-2.6.39.1/drivers/net/wireless/airo.c
35665 --- linux-2.6.39.1/drivers/net/wireless/airo.c 2011-05-19 00:06:34.000000000 -0400
35666 +++ linux-2.6.39.1/drivers/net/wireless/airo.c 2011-05-22 19:36:31.000000000 -0400
35667 @@ -3001,6 +3001,8 @@ static void airo_process_scan_results (s
35668 BSSListElement * loop_net;
35669 BSSListElement * tmp_net;
35670
35671 + pax_track_stack();
35672 +
35673 /* Blow away current list of scan results */
35674 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35675 list_move_tail (&loop_net->list, &ai->network_free_list);
35676 @@ -3792,6 +3794,8 @@ static u16 setup_card(struct airo_info *
35677 WepKeyRid wkr;
35678 int rc;
35679
35680 + pax_track_stack();
35681 +
35682 memset( &mySsid, 0, sizeof( mySsid ) );
35683 kfree (ai->flash);
35684 ai->flash = NULL;
35685 @@ -4760,6 +4764,8 @@ static int proc_stats_rid_open( struct i
35686 __le32 *vals = stats.vals;
35687 int len;
35688
35689 + pax_track_stack();
35690 +
35691 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35692 return -ENOMEM;
35693 data = file->private_data;
35694 @@ -5483,6 +5489,8 @@ static int proc_BSSList_open( struct ino
35695 /* If doLoseSync is not 1, we won't do a Lose Sync */
35696 int doLoseSync = -1;
35697
35698 + pax_track_stack();
35699 +
35700 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35701 return -ENOMEM;
35702 data = file->private_data;
35703 @@ -7190,6 +7198,8 @@ static int airo_get_aplist(struct net_de
35704 int i;
35705 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35706
35707 + pax_track_stack();
35708 +
35709 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35710 if (!qual)
35711 return -ENOMEM;
35712 @@ -7750,6 +7760,8 @@ static void airo_read_wireless_stats(str
35713 CapabilityRid cap_rid;
35714 __le32 *vals = stats_rid.vals;
35715
35716 + pax_track_stack();
35717 +
35718 /* Get stats out of the card */
35719 clear_bit(JOB_WSTATS, &local->jobs);
35720 if (local->power.event) {
35721 diff -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
35722 --- linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c 2011-05-19 00:06:34.000000000 -0400
35723 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath5k/debug.c 2011-05-22 19:36:31.000000000 -0400
35724 @@ -204,6 +204,8 @@ static ssize_t read_file_beacon(struct f
35725 unsigned int v;
35726 u64 tsf;
35727
35728 + pax_track_stack();
35729 +
35730 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35731 len += snprintf(buf+len, sizeof(buf)-len,
35732 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35733 @@ -323,6 +325,8 @@ static ssize_t read_file_debug(struct fi
35734 unsigned int len = 0;
35735 unsigned int i;
35736
35737 + pax_track_stack();
35738 +
35739 len += snprintf(buf+len, sizeof(buf)-len,
35740 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35741
35742 @@ -384,6 +388,8 @@ static ssize_t read_file_antenna(struct
35743 unsigned int i;
35744 unsigned int v;
35745
35746 + pax_track_stack();
35747 +
35748 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
35749 sc->ah->ah_ant_mode);
35750 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
35751 @@ -494,6 +500,8 @@ static ssize_t read_file_misc(struct fil
35752 unsigned int len = 0;
35753 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
35754
35755 + pax_track_stack();
35756 +
35757 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
35758 sc->bssidmask);
35759 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
35760 @@ -550,6 +558,8 @@ static ssize_t read_file_frameerrors(str
35761 unsigned int len = 0;
35762 int i;
35763
35764 + pax_track_stack();
35765 +
35766 len += snprintf(buf+len, sizeof(buf)-len,
35767 "RX\n---------------------\n");
35768 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
35769 @@ -667,6 +677,8 @@ static ssize_t read_file_ani(struct file
35770 char buf[700];
35771 unsigned int len = 0;
35772
35773 + pax_track_stack();
35774 +
35775 len += snprintf(buf+len, sizeof(buf)-len,
35776 "HW has PHY error counters:\t%s\n",
35777 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
35778 @@ -827,6 +839,8 @@ static ssize_t read_file_queue(struct fi
35779 struct ath5k_buf *bf, *bf0;
35780 int i, n;
35781
35782 + pax_track_stack();
35783 +
35784 len += snprintf(buf+len, sizeof(buf)-len,
35785 "available txbuffers: %d\n", sc->txbuf_len);
35786
35787 diff -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
35788 --- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-19 00:06:34.000000000 -0400
35789 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-22 19:36:31.000000000 -0400
35790 @@ -734,6 +734,8 @@ static void ar9003_hw_tx_iq_cal(struct a
35791 s32 i, j, ip, im, nmeasurement;
35792 u8 nchains = get_streams(common->tx_chainmask);
35793
35794 + pax_track_stack();
35795 +
35796 for (ip = 0; ip < MPASS; ip++) {
35797 REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
35798 AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
35799 @@ -856,6 +858,8 @@ static void ar9003_hw_tx_iq_cal_post_pro
35800 int i, ip, im, j;
35801 int nmeasurement;
35802
35803 + pax_track_stack();
35804 +
35805 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
35806 if (ah->txchainmask & (1 << i))
35807 num_chains++;
35808 diff -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
35809 --- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-19 00:06:34.000000000 -0400
35810 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-22 19:36:31.000000000 -0400
35811 @@ -356,6 +356,8 @@ static bool create_pa_curve(u32 *data_L,
35812 int theta_low_bin = 0;
35813 int i;
35814
35815 + pax_track_stack();
35816 +
35817 /* disregard any bin that contains <= 16 samples */
35818 thresh_accum_cnt = 16;
35819 scale_factor = 5;
35820 diff -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
35821 --- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c 2011-05-19 00:06:34.000000000 -0400
35822 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/debug.c 2011-05-22 19:36:31.000000000 -0400
35823 @@ -335,6 +335,8 @@ static ssize_t read_file_interrupt(struc
35824 char buf[512];
35825 unsigned int len = 0;
35826
35827 + pax_track_stack();
35828 +
35829 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
35830 len += snprintf(buf + len, sizeof(buf) - len,
35831 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
35832 @@ -422,6 +424,8 @@ static ssize_t read_file_wiphy(struct fi
35833 u8 addr[ETH_ALEN];
35834 u32 tmp;
35835
35836 + pax_track_stack();
35837 +
35838 len += snprintf(buf + len, sizeof(buf) - len,
35839 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
35840 wiphy_name(sc->hw->wiphy),
35841 diff -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
35842 --- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-19 00:06:34.000000000 -0400
35843 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-22 19:36:31.000000000 -0400
35844 @@ -737,6 +737,8 @@ static ssize_t read_file_tgt_stats(struc
35845 unsigned int len = 0;
35846 int ret = 0;
35847
35848 + pax_track_stack();
35849 +
35850 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
35851
35852 WMI_CMD(WMI_TGT_STATS_CMDID);
35853 @@ -782,6 +784,8 @@ static ssize_t read_file_xmit(struct fil
35854 char buf[512];
35855 unsigned int len = 0;
35856
35857 + pax_track_stack();
35858 +
35859 len += snprintf(buf + len, sizeof(buf) - len,
35860 "%20s : %10u\n", "Buffers queued",
35861 priv->debug.tx_stats.buf_queued);
35862 @@ -831,6 +835,8 @@ static ssize_t read_file_recv(struct fil
35863 char buf[512];
35864 unsigned int len = 0;
35865
35866 + pax_track_stack();
35867 +
35868 len += snprintf(buf + len, sizeof(buf) - len,
35869 "%20s : %10u\n", "SKBs allocated",
35870 priv->debug.rx_stats.skb_allocated);
35871 @@ -1816,7 +1822,7 @@ static void ath9k_htc_set_coverage_class
35872 mutex_unlock(&priv->mutex);
35873 }
35874
35875 -struct ieee80211_ops ath9k_htc_ops = {
35876 +const struct ieee80211_ops ath9k_htc_ops = {
35877 .tx = ath9k_htc_tx,
35878 .start = ath9k_htc_start,
35879 .stop = ath9k_htc_stop,
35880 diff -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
35881 --- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h 2011-05-19 00:06:34.000000000 -0400
35882 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/htc.h 2011-05-22 19:36:31.000000000 -0400
35883 @@ -42,7 +42,7 @@
35884 #define TSF_TO_TU(_h, _l) \
35885 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
35886
35887 -extern struct ieee80211_ops ath9k_htc_ops;
35888 +extern const struct ieee80211_ops ath9k_htc_ops;
35889 extern int htc_modparam_nohwcrypt;
35890
35891 enum htc_phymode {
35892 diff -urNp linux-2.6.39.1/drivers/net/wireless/ath/ath9k/hw.h linux-2.6.39.1/drivers/net/wireless/ath/ath9k/hw.h
35893 --- linux-2.6.39.1/drivers/net/wireless/ath/ath9k/hw.h 2011-05-19 00:06:34.000000000 -0400
35894 +++ linux-2.6.39.1/drivers/net/wireless/ath/ath9k/hw.h 2011-05-22 19:36:31.000000000 -0400
35895 @@ -753,9 +753,7 @@ struct ath_hw {
35896 } enable_32kHz_clock;
35897
35898 /* Private to hardware code */
35899 - struct ath_hw_private_ops private_ops;
35900 - /* Accessed by the lower level driver */
35901 - struct ath_hw_ops ops;
35902 + struct ath_hw_private_ops private_ops;struct ath_hw_ops ops;
35903
35904 /* Used to program the radio on non single-chip devices */
35905 u32 *analogBank0Data;
35906 diff -urNp linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c
35907 --- linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35908 +++ linux-2.6.39.1/drivers/net/wireless/b43/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35909 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
35910 struct b43_debugfs_fops {
35911 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35912 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35913 - struct file_operations fops;
35914 + const struct file_operations fops;
35915 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35916 size_t file_struct_offset;
35917 };
35918 diff -urNp linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c
35919 --- linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35920 +++ linux-2.6.39.1/drivers/net/wireless/b43legacy/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35921 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
35922 struct b43legacy_debugfs_fops {
35923 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35924 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35925 - struct file_operations fops;
35926 + const struct file_operations fops;
35927 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35928 size_t file_struct_offset;
35929 /* Take wl->irq_lock before calling read/write? */
35930 diff -urNp linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c
35931 --- linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-19 00:06:34.000000000 -0400
35932 +++ linux-2.6.39.1/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-22 19:36:31.000000000 -0400
35933 @@ -2100,6 +2100,8 @@ static int ipw2100_set_essid(struct ipw2
35934 int err;
35935 DECLARE_SSID_BUF(ssid);
35936
35937 + pax_track_stack();
35938 +
35939 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35940
35941 if (ssid_len)
35942 @@ -5449,6 +5451,8 @@ static int ipw2100_set_key(struct ipw210
35943 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
35944 int err;
35945
35946 + pax_track_stack();
35947 +
35948 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
35949 idx, keylen, len);
35950
35951 diff -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
35952 --- linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-19 00:06:34.000000000 -0400
35953 +++ linux-2.6.39.1/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-22 19:36:31.000000000 -0400
35954 @@ -1565,6 +1565,8 @@ static void libipw_process_probe_respons
35955 unsigned long flags;
35956 DECLARE_SSID_BUF(ssid);
35957
35958 + pax_track_stack();
35959 +
35960 LIBIPW_DEBUG_SCAN("'%s' (%pM"
35961 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
35962 print_ssid(ssid, info_element->data, info_element->len),
35963 diff -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
35964 --- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-19 00:06:34.000000000 -0400
35965 +++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-22 19:36:31.000000000 -0400
35966 @@ -2630,7 +2630,7 @@ static int iwl3945_load_bsm(struct iwl_p
35967 return 0;
35968 }
35969
35970 -static struct iwl_hcmd_ops iwl3945_hcmd = {
35971 +static const struct iwl_hcmd_ops iwl3945_hcmd = {
35972 .rxon_assoc = iwl3945_send_rxon_assoc,
35973 .commit_rxon = iwl3945_commit_rxon,
35974 };
35975 @@ -2675,7 +2675,7 @@ static const struct iwl_legacy_ops iwl39
35976 .manage_ibss_station = iwl3945_manage_ibss_station,
35977 };
35978
35979 -static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
35980 +static const struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
35981 .get_hcmd_size = iwl3945_get_hcmd_size,
35982 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
35983 .request_scan = iwl3945_request_scan,
35984 diff -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
35985 --- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-19 00:06:34.000000000 -0400
35986 +++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-05-22 19:36:32.000000000 -0400
35987 @@ -1904,7 +1904,7 @@ static void iwl4965_rx_handler_setup(str
35988 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
35989 }
35990
35991 -static struct iwl_hcmd_ops iwl4965_hcmd = {
35992 +static const struct iwl_hcmd_ops iwl4965_hcmd = {
35993 .rxon_assoc = iwl4965_send_rxon_assoc,
35994 .commit_rxon = iwl4965_commit_rxon,
35995 .set_rxon_chain = iwl4965_set_rxon_chain,
35996 @@ -2056,7 +2056,7 @@ static void iwl4965_config_ap(struct iwl
35997 iwl4965_send_beacon_cmd(priv);
35998 }
35999
36000 -static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
36001 +static const struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
36002 .get_hcmd_size = iwl4965_get_hcmd_size,
36003 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
36004 .request_scan = iwl4965_request_scan,
36005 @@ -2114,7 +2114,7 @@ static const struct iwl_legacy_ops iwl49
36006 .update_bcast_stations = iwl4965_update_bcast_stations,
36007 };
36008
36009 -struct ieee80211_ops iwl4965_hw_ops = {
36010 +const struct ieee80211_ops iwl4965_hw_ops = {
36011 .tx = iwl4965_mac_tx,
36012 .start = iwl4965_mac_start,
36013 .stop = iwl4965_mac_stop,
36014 diff -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
36015 --- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-19 00:06:34.000000000 -0400
36016 +++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-22 19:36:32.000000000 -0400
36017 @@ -70,7 +70,7 @@ extern struct iwl_cfg iwl4965_cfg;
36018
36019 extern struct iwl_mod_params iwl4965_mod_params;
36020
36021 -extern struct ieee80211_ops iwl4965_hw_ops;
36022 +extern const struct ieee80211_ops iwl4965_hw_ops;
36023
36024 /* tx queue */
36025 void iwl4965_free_tfds_in_queue(struct iwl_priv *priv,
36026 diff -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
36027 --- linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36028 +++ linux-2.6.39.1/drivers/net/wireless/iwlegacy/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36029 @@ -150,7 +150,7 @@ struct iwl_lib_ops {
36030 int (*set_channel_switch)(struct iwl_priv *priv,
36031 struct ieee80211_channel_switch *ch_switch);
36032 /* power management */
36033 - struct iwl_apm_ops apm_ops;
36034 + const struct iwl_apm_ops apm_ops;
36035
36036 /* power */
36037 int (*send_tx_power) (struct iwl_priv *priv);
36038 @@ -160,12 +160,12 @@ struct iwl_lib_ops {
36039 struct iwl_eeprom_ops eeprom_ops;
36040
36041 /* temperature */
36042 - struct iwl_temp_ops temp_ops;
36043 + const struct iwl_temp_ops temp_ops;
36044 /* check for plcp health */
36045 bool (*check_plcp_health)(struct iwl_priv *priv,
36046 struct iwl_rx_packet *pkt);
36047
36048 - struct iwl_debugfs_ops debugfs_ops;
36049 + const struct iwl_debugfs_ops debugfs_ops;
36050
36051 };
36052
36053 diff -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
36054 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-19 00:06:34.000000000 -0400
36055 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-05-22 19:36:32.000000000 -0400
36056 @@ -422,11 +422,11 @@ static struct iwl_lib_ops iwl6030_lib =
36057 }
36058 };
36059
36060 -static struct iwl_nic_ops iwl6050_nic_ops = {
36061 +static const struct iwl_nic_ops iwl6050_nic_ops = {
36062 .additional_nic_config = &iwl6050_additional_nic_config,
36063 };
36064
36065 -static struct iwl_nic_ops iwl6150_nic_ops = {
36066 +static const struct iwl_nic_ops iwl6150_nic_ops = {
36067 .additional_nic_config = &iwl6150_additional_nic_config,
36068 };
36069
36070 diff -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
36071 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-19 00:06:34.000000000 -0400
36072 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-22 19:36:32.000000000 -0400
36073 @@ -109,9 +109,9 @@ extern struct iwl_cfg iwl230_bg_cfg;
36074 extern struct iwl_cfg iwl230_bgn_cfg;
36075
36076 extern struct iwl_mod_params iwlagn_mod_params;
36077 -extern struct iwl_hcmd_ops iwlagn_hcmd;
36078 -extern struct iwl_hcmd_ops iwlagn_bt_hcmd;
36079 -extern struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36080 +extern const struct iwl_hcmd_ops iwlagn_hcmd;
36081 +extern const struct iwl_hcmd_ops iwlagn_bt_hcmd;
36082 +extern const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36083
36084 extern struct ieee80211_ops iwlagn_hw_ops;
36085 extern struct ieee80211_ops iwl4965_hw_ops;
36086 diff -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
36087 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-19 00:06:34.000000000 -0400
36088 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-05-22 19:36:32.000000000 -0400
36089 @@ -363,7 +363,7 @@ static int iwlagn_set_pan_params(struct
36090 return ret;
36091 }
36092
36093 -struct iwl_hcmd_ops iwlagn_hcmd = {
36094 +const struct iwl_hcmd_ops iwlagn_hcmd = {
36095 .rxon_assoc = iwlagn_send_rxon_assoc,
36096 .commit_rxon = iwlagn_commit_rxon,
36097 .set_rxon_chain = iwlagn_set_rxon_chain,
36098 @@ -372,7 +372,7 @@ struct iwl_hcmd_ops iwlagn_hcmd = {
36099 .set_pan_params = iwlagn_set_pan_params,
36100 };
36101
36102 -struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36103 +const struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36104 .rxon_assoc = iwlagn_send_rxon_assoc,
36105 .commit_rxon = iwlagn_commit_rxon,
36106 .set_rxon_chain = iwlagn_set_rxon_chain,
36107 @@ -381,7 +381,7 @@ struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36108 .set_pan_params = iwlagn_set_pan_params,
36109 };
36110
36111 -struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36112 +const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36113 .get_hcmd_size = iwlagn_get_hcmd_size,
36114 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
36115 .gain_computation = iwlagn_gain_computation,
36116 diff -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
36117 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-19 00:06:34.000000000 -0400
36118 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-22 19:36:32.000000000 -0400
36119 @@ -883,6 +883,8 @@ static void rs_tx_status(void *priv_r, s
36120 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
36121 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
36122
36123 + pax_track_stack();
36124 +
36125 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
36126
36127 /* Treat uninitialized rate scaling data same as non-existing. */
36128 @@ -2894,6 +2896,8 @@ static void rs_fill_link_cmd(struct iwl_
36129 container_of(lq_sta, struct iwl_station_priv, lq_sta);
36130 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
36131
36132 + pax_track_stack();
36133 +
36134 /* Override starting rate (index 0) if needed for debug purposes */
36135 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
36136
36137 diff -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
36138 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-19 00:06:34.000000000 -0400
36139 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-core.h 2011-05-22 19:36:32.000000000 -0400
36140 @@ -198,28 +198,25 @@ struct iwl_lib_ops {
36141 int (*set_channel_switch)(struct iwl_priv *priv,
36142 struct ieee80211_channel_switch *ch_switch);
36143 /* power management */
36144 - struct iwl_apm_ops apm_ops;
36145 + const struct iwl_apm_ops apm_ops;
36146
36147 /* power */
36148 int (*send_tx_power) (struct iwl_priv *priv);
36149 void (*update_chain_flags)(struct iwl_priv *priv);
36150
36151 /* isr */
36152 - struct iwl_isr_ops isr_ops;
36153 + const struct iwl_isr_ops isr_ops;
36154
36155 /* eeprom operations (as defined in iwl-eeprom.h) */
36156 struct iwl_eeprom_ops eeprom_ops;
36157
36158 /* temperature */
36159 - struct iwl_temp_ops temp_ops;
36160 + const struct iwl_temp_ops temp_ops;
36161
36162 int (*txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36163 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36164
36165 - struct iwl_debugfs_ops debugfs_ops;
36166 -
36167 - /* thermal throttling */
36168 - struct iwl_tt_ops tt_ops;
36169 + const struct iwl_debugfs_ops debugfs_ops;const struct iwl_tt_ops tt_ops;
36170 };
36171
36172 struct iwl_led_ops {
36173 diff -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
36174 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-19 00:06:34.000000000 -0400
36175 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-22 19:36:32.000000000 -0400
36176 @@ -549,6 +549,8 @@ static ssize_t iwl_dbgfs_status_read(str
36177 int pos = 0;
36178 const size_t bufsz = sizeof(buf);
36179
36180 + pax_track_stack();
36181 +
36182 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
36183 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
36184 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
36185 @@ -681,6 +683,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
36186 char buf[256 * NUM_IWL_RXON_CTX];
36187 const size_t bufsz = sizeof(buf);
36188
36189 + pax_track_stack();
36190 +
36191 for_each_context(priv, ctx) {
36192 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
36193 ctx->ctxid);
36194 diff -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
36195 --- linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-19 00:06:34.000000000 -0400
36196 +++ linux-2.6.39.1/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-22 19:36:32.000000000 -0400
36197 @@ -68,8 +68,8 @@ do {
36198 } while (0)
36199
36200 #else
36201 -#define IWL_DEBUG(__priv, level, fmt, args...)
36202 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
36203 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
36204 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
36205 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
36206 const void *p, u32 len)
36207 {}
36208 diff -urNp linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c
36209 --- linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
36210 +++ linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
36211 @@ -763,7 +763,7 @@ static int iwm_cfg80211_flush_pmksa(stru
36212 }
36213
36214
36215 -static struct cfg80211_ops iwm_cfg80211_ops = {
36216 +static const struct cfg80211_ops iwm_cfg80211_ops = {
36217 .change_virtual_intf = iwm_cfg80211_change_iface,
36218 .add_key = iwm_cfg80211_add_key,
36219 .get_key = iwm_cfg80211_get_key,
36220 diff -urNp linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c
36221 --- linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36222 +++ linux-2.6.39.1/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36223 @@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
36224 int buf_len = 512;
36225 size_t len = 0;
36226
36227 + pax_track_stack();
36228 +
36229 if (*ppos != 0)
36230 return 0;
36231 if (count < sizeof(buf))
36232 diff -urNp linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c
36233 --- linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c 2011-05-19 00:06:34.000000000 -0400
36234 +++ linux-2.6.39.1/drivers/net/wireless/libertas/cfg.c 2011-05-22 19:36:32.000000000 -0400
36235 @@ -2003,7 +2003,7 @@ static int lbs_leave_ibss(struct wiphy *
36236 * Initialization
36237 */
36238
36239 -static struct cfg80211_ops lbs_cfg80211_ops = {
36240 +static const struct cfg80211_ops lbs_cfg80211_ops = {
36241 .set_channel = lbs_cfg_set_channel,
36242 .scan = lbs_cfg_scan,
36243 .connect = lbs_cfg_connect,
36244 diff -urNp linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c
36245 --- linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36246 +++ linux-2.6.39.1/drivers/net/wireless/libertas/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36247 @@ -702,7 +702,7 @@ out_unlock:
36248 struct lbs_debugfs_files {
36249 const char *name;
36250 int perm;
36251 - struct file_operations fops;
36252 + const struct file_operations fops;
36253 };
36254
36255 static const struct lbs_debugfs_files debugfs_files[] = {
36256 diff -urNp linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c
36257 --- linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c 2011-05-19 00:06:34.000000000 -0400
36258 +++ linux-2.6.39.1/drivers/net/wireless/rndis_wlan.c 2011-05-22 19:36:32.000000000 -0400
36259 @@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbn
36260
36261 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36262
36263 - if (rts_threshold < 0 || rts_threshold > 2347)
36264 + if (rts_threshold > 2347)
36265 rts_threshold = 2347;
36266
36267 tmp = cpu_to_le32(rts_threshold);
36268 diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c
36269 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c 2011-05-19 00:06:34.000000000 -0400
36270 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.c 2011-05-22 19:36:32.000000000 -0400
36271 @@ -1869,7 +1869,7 @@ int rtl_pci_resume(struct pci_dev *pdev)
36272 }
36273 EXPORT_SYMBOL(rtl_pci_resume);
36274
36275 -struct rtl_intf_ops rtl_pci_ops = {
36276 +const struct rtl_intf_ops rtl_pci_ops = {
36277 .adapter_start = rtl_pci_start,
36278 .adapter_stop = rtl_pci_stop,
36279 .adapter_tx = rtl_pci_tx,
36280 diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h
36281 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h 2011-05-19 00:06:34.000000000 -0400
36282 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/pci.h 2011-05-22 19:36:32.000000000 -0400
36283 @@ -234,7 +234,7 @@ struct rtl_pci_priv {
36284
36285 int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
36286
36287 -extern struct rtl_intf_ops rtl_pci_ops;
36288 +extern const struct rtl_intf_ops rtl_pci_ops;
36289
36290 int __devinit rtl_pci_probe(struct pci_dev *pdev,
36291 const struct pci_device_id *id);
36292 diff -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
36293 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-19 00:06:34.000000000 -0400
36294 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-22 19:36:32.000000000 -0400
36295 @@ -827,6 +827,8 @@ static bool _rtl92c_phy_sw_chnl_step_by_
36296 u8 rfpath;
36297 u8 num_total_rfpath = rtlphy->num_total_rfpath;
36298
36299 + pax_track_stack();
36300 +
36301 precommoncmdcnt = 0;
36302 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
36303 MAX_PRECMD_CNT,
36304 diff -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
36305 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-19 00:06:34.000000000 -0400
36306 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-22 19:36:32.000000000 -0400
36307 @@ -96,7 +96,7 @@ void rtl92c_deinit_sw_vars(struct ieee80
36308 }
36309 }
36310
36311 -static struct rtl_hal_ops rtl8192ce_hal_ops = {
36312 +static const struct rtl_hal_ops rtl8192ce_hal_ops = {
36313 .init_sw_vars = rtl92c_init_sw_vars,
36314 .deinit_sw_vars = rtl92c_deinit_sw_vars,
36315 .read_eeprom_info = rtl92ce_read_eeprom_info,
36316 @@ -151,7 +151,7 @@ static struct rtl_mod_params rtl92ce_mod
36317 .sw_crypto = 0,
36318 };
36319
36320 -static struct rtl_hal_cfg rtl92ce_hal_cfg = {
36321 +static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
36322 .name = "rtl92c_pci",
36323 .fw_name = "rtlwifi/rtl8192cfw.bin",
36324 .ops = &rtl8192ce_hal_ops,
36325 diff -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
36326 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-19 00:06:34.000000000 -0400
36327 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-22 19:36:32.000000000 -0400
36328 @@ -77,7 +77,7 @@ static void rtl92cu_deinit_sw_vars(struc
36329 }
36330 }
36331
36332 -static struct rtl_hal_ops rtl8192cu_hal_ops = {
36333 +static const struct rtl_hal_ops rtl8192cu_hal_ops = {
36334 .init_sw_vars = rtl92cu_init_sw_vars,
36335 .deinit_sw_vars = rtl92cu_deinit_sw_vars,
36336 .read_chip_version = rtl92c_read_chip_version,
36337 @@ -147,7 +147,7 @@ static struct rtl_hal_usbint_cfg rtl92cu
36338 .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
36339 };
36340
36341 -static struct rtl_hal_cfg rtl92cu_hal_cfg = {
36342 +static const struct rtl_hal_cfg rtl92cu_hal_cfg = {
36343 .name = "rtl92c_usb",
36344 .fw_name = "rtlwifi/rtl8192cufw.bin",
36345 .ops = &rtl8192cu_hal_ops,
36346 diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c
36347 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c 2011-05-19 00:06:34.000000000 -0400
36348 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/usb.c 2011-05-22 19:36:32.000000000 -0400
36349 @@ -913,7 +913,7 @@ static bool rtl_usb_tx_chk_waitq_insert(
36350 return false;
36351 }
36352
36353 -static struct rtl_intf_ops rtl_usb_ops = {
36354 +static const struct rtl_intf_ops rtl_usb_ops = {
36355 .adapter_start = rtl_usb_start,
36356 .adapter_stop = rtl_usb_stop,
36357 .adapter_tx = rtl_usb_tx,
36358 diff -urNp linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h
36359 --- linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h 2011-05-19 00:06:34.000000000 -0400
36360 +++ linux-2.6.39.1/drivers/net/wireless/rtlwifi/wifi.h 2011-05-22 19:36:32.000000000 -0400
36361 @@ -1447,7 +1447,7 @@ struct rtl_hal_cfg {
36362 u8 bar_id;
36363 char *name;
36364 char *fw_name;
36365 - struct rtl_hal_ops *ops;
36366 + const struct rtl_hal_ops *ops;
36367 struct rtl_mod_params *mod_params;
36368 struct rtl_hal_usbint_cfg *usb_interface_cfg;
36369
36370 @@ -1533,7 +1533,7 @@ struct rtl_priv {
36371 *intf_ops : for diff interrface usb/pcie
36372 */
36373 struct rtl_hal_cfg *cfg;
36374 - struct rtl_intf_ops *intf_ops;
36375 + const struct rtl_intf_ops *intf_ops;
36376
36377 /*this var will be set by set_bit,
36378 and was used to indicate status of
36379 diff -urNp linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c
36380 --- linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c 2011-05-19 00:06:34.000000000 -0400
36381 +++ linux-2.6.39.1/drivers/net/wireless/wl12xx/spi.c 2011-05-22 19:36:32.000000000 -0400
36382 @@ -280,6 +280,8 @@ static void wl1271_spi_raw_write(struct
36383 u32 chunk_len;
36384 int i;
36385
36386 + pax_track_stack();
36387 +
36388 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
36389
36390 spi_message_init(&m);
36391 diff -urNp linux-2.6.39.1/drivers/net/xen-netback/interface.c linux-2.6.39.1/drivers/net/xen-netback/interface.c
36392 --- linux-2.6.39.1/drivers/net/xen-netback/interface.c 2011-05-19 00:06:34.000000000 -0400
36393 +++ linux-2.6.39.1/drivers/net/xen-netback/interface.c 2011-05-22 19:36:32.000000000 -0400
36394 @@ -273,7 +273,7 @@ static void xenvif_get_strings(struct ne
36395 }
36396 }
36397
36398 -static struct ethtool_ops xenvif_ethtool_ops = {
36399 +static const struct ethtool_ops xenvif_ethtool_ops = {
36400 .get_tx_csum = ethtool_op_get_tx_csum,
36401 .set_tx_csum = xenvif_set_tx_csum,
36402 .get_sg = ethtool_op_get_sg,
36403 diff -urNp linux-2.6.39.1/drivers/net/xilinx_emaclite.c linux-2.6.39.1/drivers/net/xilinx_emaclite.c
36404 --- linux-2.6.39.1/drivers/net/xilinx_emaclite.c 2011-05-19 00:06:34.000000000 -0400
36405 +++ linux-2.6.39.1/drivers/net/xilinx_emaclite.c 2011-05-22 19:36:32.000000000 -0400
36406 @@ -1085,7 +1085,7 @@ static bool get_bool(struct platform_dev
36407 }
36408 }
36409
36410 -static struct net_device_ops xemaclite_netdev_ops;
36411 +static const struct net_device_ops xemaclite_netdev_ops;
36412
36413 /**
36414 * xemaclite_of_probe - Probe method for the Emaclite device.
36415 @@ -1264,7 +1264,7 @@ xemaclite_poll_controller(struct net_dev
36416 }
36417 #endif
36418
36419 -static struct net_device_ops xemaclite_netdev_ops = {
36420 +static const struct net_device_ops xemaclite_netdev_ops = {
36421 .ndo_open = xemaclite_open,
36422 .ndo_stop = xemaclite_close,
36423 .ndo_start_xmit = xemaclite_send,
36424 diff -urNp linux-2.6.39.1/drivers/nfc/pn544.c linux-2.6.39.1/drivers/nfc/pn544.c
36425 --- linux-2.6.39.1/drivers/nfc/pn544.c 2011-05-19 00:06:34.000000000 -0400
36426 +++ linux-2.6.39.1/drivers/nfc/pn544.c 2011-05-22 19:36:32.000000000 -0400
36427 @@ -89,7 +89,7 @@ static ssize_t pn544_test(struct device
36428
36429 static int pn544_enable(struct pn544_info *info, int mode)
36430 {
36431 - struct pn544_nfc_platform_data *pdata;
36432 + const struct pn544_nfc_platform_data *pdata;
36433 struct i2c_client *client = info->i2c_dev;
36434
36435 int r;
36436 @@ -118,7 +118,7 @@ static int pn544_enable(struct pn544_inf
36437
36438 static void pn544_disable(struct pn544_info *info)
36439 {
36440 - struct pn544_nfc_platform_data *pdata;
36441 + const struct pn544_nfc_platform_data *pdata;
36442 struct i2c_client *client = info->i2c_dev;
36443
36444 pdata = client->dev.platform_data;
36445 @@ -509,7 +509,7 @@ static long pn544_ioctl(struct file *fil
36446 struct pn544_info *info = container_of(file->private_data,
36447 struct pn544_info, miscdev);
36448 struct i2c_client *client = info->i2c_dev;
36449 - struct pn544_nfc_platform_data *pdata;
36450 + const struct pn544_nfc_platform_data *pdata;
36451 unsigned int val;
36452 int r = 0;
36453
36454 @@ -715,7 +715,7 @@ static int __devinit pn544_probe(struct
36455 const struct i2c_device_id *id)
36456 {
36457 struct pn544_info *info;
36458 - struct pn544_nfc_platform_data *pdata;
36459 + const struct pn544_nfc_platform_data *pdata;
36460 int r = 0;
36461
36462 dev_dbg(&client->dev, "%s\n", __func__);
36463 diff -urNp linux-2.6.39.1/drivers/of/pdt.c linux-2.6.39.1/drivers/of/pdt.c
36464 --- linux-2.6.39.1/drivers/of/pdt.c 2011-05-19 00:06:34.000000000 -0400
36465 +++ linux-2.6.39.1/drivers/of/pdt.c 2011-05-22 19:36:32.000000000 -0400
36466 @@ -24,7 +24,7 @@
36467 #include <linux/of_pdt.h>
36468 #include <asm/prom.h>
36469
36470 -static struct of_pdt_ops *of_pdt_prom_ops __initdata;
36471 +static const struct of_pdt_ops *of_pdt_prom_ops;
36472
36473 void __initdata (*of_pdt_build_more)(struct device_node *dp,
36474 struct device_node ***nextp);
36475 diff -urNp linux-2.6.39.1/drivers/oprofile/buffer_sync.c linux-2.6.39.1/drivers/oprofile/buffer_sync.c
36476 --- linux-2.6.39.1/drivers/oprofile/buffer_sync.c 2011-05-19 00:06:34.000000000 -0400
36477 +++ linux-2.6.39.1/drivers/oprofile/buffer_sync.c 2011-05-22 19:36:32.000000000 -0400
36478 @@ -342,7 +342,7 @@ static void add_data(struct op_entry *en
36479 if (cookie == NO_COOKIE)
36480 offset = pc;
36481 if (cookie == INVALID_COOKIE) {
36482 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36483 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36484 offset = pc;
36485 }
36486 if (cookie != last_cookie) {
36487 @@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct
36488 /* add userspace sample */
36489
36490 if (!mm) {
36491 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36492 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36493 return 0;
36494 }
36495
36496 cookie = lookup_dcookie(mm, s->eip, &offset);
36497
36498 if (cookie == INVALID_COOKIE) {
36499 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36500 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36501 return 0;
36502 }
36503
36504 @@ -562,7 +562,7 @@ void sync_buffer(int cpu)
36505 /* ignore backtraces if failed to add a sample */
36506 if (state == sb_bt_start) {
36507 state = sb_bt_ignore;
36508 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36509 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36510 }
36511 }
36512 release_mm(mm);
36513 diff -urNp linux-2.6.39.1/drivers/oprofile/event_buffer.c linux-2.6.39.1/drivers/oprofile/event_buffer.c
36514 --- linux-2.6.39.1/drivers/oprofile/event_buffer.c 2011-05-19 00:06:34.000000000 -0400
36515 +++ linux-2.6.39.1/drivers/oprofile/event_buffer.c 2011-05-22 19:36:32.000000000 -0400
36516 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36517 }
36518
36519 if (buffer_pos == buffer_size) {
36520 - atomic_inc(&oprofile_stats.event_lost_overflow);
36521 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36522 return;
36523 }
36524
36525 diff -urNp linux-2.6.39.1/drivers/oprofile/oprof.c linux-2.6.39.1/drivers/oprofile/oprof.c
36526 --- linux-2.6.39.1/drivers/oprofile/oprof.c 2011-05-19 00:06:34.000000000 -0400
36527 +++ linux-2.6.39.1/drivers/oprofile/oprof.c 2011-05-22 19:36:32.000000000 -0400
36528 @@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36529 if (oprofile_ops.switch_events())
36530 return;
36531
36532 - atomic_inc(&oprofile_stats.multiplex_counter);
36533 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36534 start_switch_worker();
36535 }
36536
36537 diff -urNp linux-2.6.39.1/drivers/oprofile/oprofilefs.c linux-2.6.39.1/drivers/oprofile/oprofilefs.c
36538 --- linux-2.6.39.1/drivers/oprofile/oprofilefs.c 2011-05-19 00:06:34.000000000 -0400
36539 +++ linux-2.6.39.1/drivers/oprofile/oprofilefs.c 2011-05-22 19:36:32.000000000 -0400
36540 @@ -186,7 +186,7 @@ static const struct file_operations atom
36541
36542
36543 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36544 - char const *name, atomic_t *val)
36545 + char const *name, atomic_unchecked_t *val)
36546 {
36547 return __oprofilefs_create_file(sb, root, name,
36548 &atomic_ro_fops, 0444, val);
36549 diff -urNp linux-2.6.39.1/drivers/oprofile/oprofile_stats.c linux-2.6.39.1/drivers/oprofile/oprofile_stats.c
36550 --- linux-2.6.39.1/drivers/oprofile/oprofile_stats.c 2011-05-19 00:06:34.000000000 -0400
36551 +++ linux-2.6.39.1/drivers/oprofile/oprofile_stats.c 2011-05-22 19:36:32.000000000 -0400
36552 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36553 cpu_buf->sample_invalid_eip = 0;
36554 }
36555
36556 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36557 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36558 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36559 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36560 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36561 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36562 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36563 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36564 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36565 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36566 }
36567
36568
36569 diff -urNp linux-2.6.39.1/drivers/oprofile/oprofile_stats.h linux-2.6.39.1/drivers/oprofile/oprofile_stats.h
36570 --- linux-2.6.39.1/drivers/oprofile/oprofile_stats.h 2011-05-19 00:06:34.000000000 -0400
36571 +++ linux-2.6.39.1/drivers/oprofile/oprofile_stats.h 2011-05-22 19:36:32.000000000 -0400
36572 @@ -13,11 +13,11 @@
36573 #include <asm/atomic.h>
36574
36575 struct oprofile_stat_struct {
36576 - atomic_t sample_lost_no_mm;
36577 - atomic_t sample_lost_no_mapping;
36578 - atomic_t bt_lost_no_mapping;
36579 - atomic_t event_lost_overflow;
36580 - atomic_t multiplex_counter;
36581 + atomic_unchecked_t sample_lost_no_mm;
36582 + atomic_unchecked_t sample_lost_no_mapping;
36583 + atomic_unchecked_t bt_lost_no_mapping;
36584 + atomic_unchecked_t event_lost_overflow;
36585 + atomic_unchecked_t multiplex_counter;
36586 };
36587
36588 extern struct oprofile_stat_struct oprofile_stats;
36589 diff -urNp linux-2.6.39.1/drivers/parisc/dino.c linux-2.6.39.1/drivers/parisc/dino.c
36590 --- linux-2.6.39.1/drivers/parisc/dino.c 2011-05-19 00:06:34.000000000 -0400
36591 +++ linux-2.6.39.1/drivers/parisc/dino.c 2011-05-22 19:36:32.000000000 -0400
36592 @@ -238,7 +238,7 @@ static int dino_cfg_write(struct pci_bus
36593 return 0;
36594 }
36595
36596 -static struct pci_ops dino_cfg_ops = {
36597 +static const struct pci_ops dino_cfg_ops = {
36598 .read = dino_cfg_read,
36599 .write = dino_cfg_write,
36600 };
36601 diff -urNp linux-2.6.39.1/drivers/parisc/lba_pci.c linux-2.6.39.1/drivers/parisc/lba_pci.c
36602 --- linux-2.6.39.1/drivers/parisc/lba_pci.c 2011-05-19 00:06:34.000000000 -0400
36603 +++ linux-2.6.39.1/drivers/parisc/lba_pci.c 2011-05-22 19:36:32.000000000 -0400
36604 @@ -468,7 +468,7 @@ static int elroy_cfg_write(struct pci_bu
36605 }
36606
36607
36608 -static struct pci_ops elroy_cfg_ops = {
36609 +static const struct pci_ops elroy_cfg_ops = {
36610 .read = elroy_cfg_read,
36611 .write = elroy_cfg_write,
36612 };
36613 @@ -541,7 +541,7 @@ static int mercury_cfg_write(struct pci_
36614 return 0;
36615 }
36616
36617 -static struct pci_ops mercury_cfg_ops = {
36618 +static const struct pci_ops mercury_cfg_ops = {
36619 .read = mercury_cfg_read,
36620 .write = mercury_cfg_write,
36621 };
36622 @@ -1405,7 +1405,7 @@ lba_driver_probe(struct parisc_device *d
36623 {
36624 struct lba_device *lba_dev;
36625 struct pci_bus *lba_bus;
36626 - struct pci_ops *cfg_ops;
36627 + const struct pci_ops *cfg_ops;
36628 u32 func_class;
36629 void *tmp_obj;
36630 char *version;
36631 diff -urNp linux-2.6.39.1/drivers/parport/procfs.c linux-2.6.39.1/drivers/parport/procfs.c
36632 --- linux-2.6.39.1/drivers/parport/procfs.c 2011-05-19 00:06:34.000000000 -0400
36633 +++ linux-2.6.39.1/drivers/parport/procfs.c 2011-05-22 19:36:32.000000000 -0400
36634 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36635
36636 *ppos += len;
36637
36638 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36639 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36640 }
36641
36642 #ifdef CONFIG_PARPORT_1284
36643 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36644
36645 *ppos += len;
36646
36647 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36648 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36649 }
36650 #endif /* IEEE1284.3 support. */
36651
36652 diff -urNp linux-2.6.39.1/drivers/pci/access.c linux-2.6.39.1/drivers/pci/access.c
36653 --- linux-2.6.39.1/drivers/pci/access.c 2011-05-19 00:06:34.000000000 -0400
36654 +++ linux-2.6.39.1/drivers/pci/access.c 2011-05-22 19:36:32.000000000 -0400
36655 @@ -74,9 +74,9 @@ EXPORT_SYMBOL(pci_bus_write_config_dword
36656 *
36657 * Return previous raw operations
36658 */
36659 -struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
36660 +const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops)
36661 {
36662 - struct pci_ops *old_ops;
36663 + const struct pci_ops *old_ops;
36664 unsigned long flags;
36665
36666 raw_spin_lock_irqsave(&pci_lock, flags);
36667 diff -urNp linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c
36668 --- linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c 2011-05-19 00:06:34.000000000 -0400
36669 +++ linux-2.6.39.1/drivers/pci/hotplug/acpiphp_glue.c 2011-05-22 19:36:32.000000000 -0400
36670 @@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
36671 }
36672
36673
36674 -static struct acpi_dock_ops acpiphp_dock_ops = {
36675 +static const struct acpi_dock_ops acpiphp_dock_ops = {
36676 .handler = handle_hotplug_event_func,
36677 };
36678
36679 diff -urNp linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c
36680 --- linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-19 00:06:34.000000000 -0400
36681 +++ linux-2.6.39.1/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-22 19:36:32.000000000 -0400
36682 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36683
36684 void compaq_nvram_init (void __iomem *rom_start)
36685 {
36686 +
36687 +#ifndef CONFIG_PAX_KERNEXEC
36688 if (rom_start) {
36689 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36690 }
36691 +#endif
36692 +
36693 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36694
36695 /* initialize our int15 lock */
36696 diff -urNp linux-2.6.39.1/drivers/pci/hotplug/shpchp.h linux-2.6.39.1/drivers/pci/hotplug/shpchp.h
36697 --- linux-2.6.39.1/drivers/pci/hotplug/shpchp.h 2011-05-19 00:06:34.000000000 -0400
36698 +++ linux-2.6.39.1/drivers/pci/hotplug/shpchp.h 2011-05-22 19:36:32.000000000 -0400
36699 @@ -86,7 +86,7 @@ struct slot {
36700 u8 presence_save;
36701 u8 pwr_save;
36702 struct controller *ctrl;
36703 - struct hpc_ops *hpc_ops;
36704 + const struct hpc_ops *hpc_ops;
36705 struct hotplug_slot *hotplug_slot;
36706 struct list_head slot_list;
36707 struct delayed_work work; /* work for button event */
36708 @@ -107,7 +107,7 @@ struct controller {
36709 int slot_num_inc; /* 1 or -1 */
36710 struct pci_dev *pci_dev;
36711 struct list_head slot_list;
36712 - struct hpc_ops *hpc_ops;
36713 + const struct hpc_ops *hpc_ops;
36714 wait_queue_head_t queue; /* sleep & wake process */
36715 u8 slot_device_offset;
36716 u32 pcix_misc2_reg; /* for amd pogo errata */
36717 diff -urNp linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c
36718 --- linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c 2011-05-19 00:06:34.000000000 -0400
36719 +++ linux-2.6.39.1/drivers/pci/hotplug/shpchp_hpc.c 2011-05-22 19:36:32.000000000 -0400
36720 @@ -910,7 +910,7 @@ static int shpc_get_max_bus_speed(struct
36721 return retval;
36722 }
36723
36724 -static struct hpc_ops shpchp_hpc_ops = {
36725 +static const struct hpc_ops shpchp_hpc_ops = {
36726 .power_on_slot = hpc_power_on_slot,
36727 .slot_enable = hpc_slot_enable,
36728 .slot_disable = hpc_slot_disable,
36729 diff -urNp linux-2.6.39.1/drivers/pci/intel-iommu.c linux-2.6.39.1/drivers/pci/intel-iommu.c
36730 --- linux-2.6.39.1/drivers/pci/intel-iommu.c 2011-05-19 00:06:34.000000000 -0400
36731 +++ linux-2.6.39.1/drivers/pci/intel-iommu.c 2011-05-22 19:36:32.000000000 -0400
36732 @@ -391,7 +391,7 @@ static int intel_iommu_strict;
36733 static DEFINE_SPINLOCK(device_domain_lock);
36734 static LIST_HEAD(device_domain_list);
36735
36736 -static struct iommu_ops intel_iommu_ops;
36737 +static const struct iommu_ops intel_iommu_ops;
36738
36739 static int __init intel_iommu_setup(char *str)
36740 {
36741 @@ -2945,7 +2945,7 @@ static int intel_mapping_error(struct de
36742 return !dma_addr;
36743 }
36744
36745 -struct dma_map_ops intel_dma_ops = {
36746 +const struct dma_map_ops intel_dma_ops = {
36747 .alloc_coherent = intel_alloc_coherent,
36748 .free_coherent = intel_free_coherent,
36749 .map_sg = intel_map_sg,
36750 @@ -3739,7 +3739,7 @@ static int intel_iommu_domain_has_cap(st
36751 return 0;
36752 }
36753
36754 -static struct iommu_ops intel_iommu_ops = {
36755 +static const struct iommu_ops intel_iommu_ops = {
36756 .domain_init = intel_iommu_domain_init,
36757 .domain_destroy = intel_iommu_domain_destroy,
36758 .attach_dev = intel_iommu_attach_device,
36759 diff -urNp linux-2.6.39.1/drivers/pci/pci-acpi.c linux-2.6.39.1/drivers/pci/pci-acpi.c
36760 --- linux-2.6.39.1/drivers/pci/pci-acpi.c 2011-05-19 00:06:34.000000000 -0400
36761 +++ linux-2.6.39.1/drivers/pci/pci-acpi.c 2011-05-22 19:36:32.000000000 -0400
36762 @@ -332,7 +332,7 @@ static int acpi_pci_run_wake(struct pci_
36763 return 0;
36764 }
36765
36766 -static struct pci_platform_pm_ops acpi_pci_platform_pm = {
36767 +static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
36768 .is_manageable = acpi_pci_power_manageable,
36769 .set_state = acpi_pci_set_power_state,
36770 .choose_state = acpi_pci_choose_state,
36771 diff -urNp linux-2.6.39.1/drivers/pci/pci.c linux-2.6.39.1/drivers/pci/pci.c
36772 --- linux-2.6.39.1/drivers/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
36773 +++ linux-2.6.39.1/drivers/pci/pci.c 2011-05-22 19:36:32.000000000 -0400
36774 @@ -480,9 +480,9 @@ pci_restore_bars(struct pci_dev *dev)
36775 pci_update_resource(dev, i);
36776 }
36777
36778 -static struct pci_platform_pm_ops *pci_platform_pm;
36779 +static const struct pci_platform_pm_ops *pci_platform_pm;
36780
36781 -int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
36782 +int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
36783 {
36784 if (!ops->is_manageable || !ops->set_state || !ops->choose_state
36785 || !ops->sleep_wake || !ops->can_wakeup)
36786 diff -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
36787 --- linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-19 00:06:34.000000000 -0400
36788 +++ linux-2.6.39.1/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-22 19:36:32.000000000 -0400
36789 @@ -239,7 +239,7 @@ static bool find_source_device(struct pc
36790 static int report_error_detected(struct pci_dev *dev, void *data)
36791 {
36792 pci_ers_result_t vote;
36793 - struct pci_error_handlers *err_handler;
36794 + const struct pci_error_handlers *err_handler;
36795 struct aer_broadcast_data *result_data;
36796 result_data = (struct aer_broadcast_data *) data;
36797
36798 @@ -273,7 +273,7 @@ static int report_error_detected(struct
36799 static int report_mmio_enabled(struct pci_dev *dev, void *data)
36800 {
36801 pci_ers_result_t vote;
36802 - struct pci_error_handlers *err_handler;
36803 + const struct pci_error_handlers *err_handler;
36804 struct aer_broadcast_data *result_data;
36805 result_data = (struct aer_broadcast_data *) data;
36806
36807 @@ -291,7 +291,7 @@ static int report_mmio_enabled(struct pc
36808 static int report_slot_reset(struct pci_dev *dev, void *data)
36809 {
36810 pci_ers_result_t vote;
36811 - struct pci_error_handlers *err_handler;
36812 + const struct pci_error_handlers *err_handler;
36813 struct aer_broadcast_data *result_data;
36814 result_data = (struct aer_broadcast_data *) data;
36815
36816 @@ -308,7 +308,7 @@ static int report_slot_reset(struct pci_
36817
36818 static int report_resume(struct pci_dev *dev, void *data)
36819 {
36820 - struct pci_error_handlers *err_handler;
36821 + const struct pci_error_handlers *err_handler;
36822
36823 dev->error_state = pci_channel_io_normal;
36824
36825 diff -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
36826 --- linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c 2011-05-19 00:06:34.000000000 -0400
36827 +++ linux-2.6.39.1/drivers/pci/pcie/aer/aer_inject.c 2011-05-22 19:36:32.000000000 -0400
36828 @@ -64,7 +64,7 @@ struct aer_error {
36829 struct pci_bus_ops {
36830 struct list_head list;
36831 struct pci_bus *bus;
36832 - struct pci_ops *ops;
36833 + const struct pci_ops *ops;
36834 };
36835
36836 static LIST_HEAD(einjected);
36837 @@ -110,7 +110,7 @@ static struct aer_error *__find_aer_erro
36838 }
36839
36840 /* inject_lock must be held before calling */
36841 -static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36842 +static const struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36843 {
36844 struct pci_bus_ops *bus_ops;
36845
36846 @@ -187,7 +187,7 @@ static int pci_read_aer(struct pci_bus *
36847 u32 *sim;
36848 struct aer_error *err;
36849 unsigned long flags;
36850 - struct pci_ops *ops;
36851 + const struct pci_ops *ops;
36852 int domain;
36853
36854 spin_lock_irqsave(&inject_lock, flags);
36855 @@ -219,7 +219,7 @@ int pci_write_aer(struct pci_bus *bus, u
36856 struct aer_error *err;
36857 unsigned long flags;
36858 int rw1cs;
36859 - struct pci_ops *ops;
36860 + const struct pci_ops *ops;
36861 int domain;
36862
36863 spin_lock_irqsave(&inject_lock, flags);
36864 @@ -254,7 +254,7 @@ static struct pci_ops pci_ops_aer = {
36865
36866 static void pci_bus_ops_init(struct pci_bus_ops *bus_ops,
36867 struct pci_bus *bus,
36868 - struct pci_ops *ops)
36869 + const struct pci_ops *ops)
36870 {
36871 INIT_LIST_HEAD(&bus_ops->list);
36872 bus_ops->bus = bus;
36873 @@ -263,7 +263,7 @@ static void pci_bus_ops_init(struct pci_
36874
36875 static int pci_bus_set_aer_ops(struct pci_bus *bus)
36876 {
36877 - struct pci_ops *ops;
36878 + const struct pci_ops *ops;
36879 struct pci_bus_ops *bus_ops;
36880 unsigned long flags;
36881
36882 diff -urNp linux-2.6.39.1/drivers/pci/pcie/aspm.c linux-2.6.39.1/drivers/pci/pcie/aspm.c
36883 --- linux-2.6.39.1/drivers/pci/pcie/aspm.c 2011-05-19 00:06:34.000000000 -0400
36884 +++ linux-2.6.39.1/drivers/pci/pcie/aspm.c 2011-05-22 19:36:32.000000000 -0400
36885 @@ -27,9 +27,9 @@
36886 #define MODULE_PARAM_PREFIX "pcie_aspm."
36887
36888 /* Note: those are not register definitions */
36889 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36890 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36891 -#define ASPM_STATE_L1 (4) /* L1 state */
36892 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36893 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36894 +#define ASPM_STATE_L1 (4U) /* L1 state */
36895 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36896 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36897
36898 diff -urNp linux-2.6.39.1/drivers/pci/pci.h linux-2.6.39.1/drivers/pci/pci.h
36899 --- linux-2.6.39.1/drivers/pci/pci.h 2011-05-19 00:06:34.000000000 -0400
36900 +++ linux-2.6.39.1/drivers/pci/pci.h 2011-05-22 19:36:32.000000000 -0400
36901 @@ -65,7 +65,7 @@ struct pci_platform_pm_ops {
36902 int (*run_wake)(struct pci_dev *dev, bool enable);
36903 };
36904
36905 -extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
36906 +extern int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
36907 extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
36908 extern void pci_disable_enabled_device(struct pci_dev *dev);
36909 extern int pci_finish_runtime_suspend(struct pci_dev *dev);
36910 diff -urNp linux-2.6.39.1/drivers/pci/probe.c linux-2.6.39.1/drivers/pci/probe.c
36911 --- linux-2.6.39.1/drivers/pci/probe.c 2011-05-19 00:06:34.000000000 -0400
36912 +++ linux-2.6.39.1/drivers/pci/probe.c 2011-05-22 19:36:32.000000000 -0400
36913 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36914 return ret;
36915 }
36916
36917 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36918 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36919 struct device_attribute *attr,
36920 char *buf)
36921 {
36922 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36923 }
36924
36925 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36926 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36927 struct device_attribute *attr,
36928 char *buf)
36929 {
36930 @@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
36931 u32 l, sz, mask;
36932 u16 orig_cmd;
36933
36934 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36935 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36936
36937 if (!dev->mmio_always_on) {
36938 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36939 @@ -1407,7 +1407,7 @@ unsigned int __devinit pci_scan_child_bu
36940 }
36941
36942 struct pci_bus * pci_create_bus(struct device *parent,
36943 - int bus, struct pci_ops *ops, void *sysdata)
36944 + int bus, const struct pci_ops *ops, void *sysdata)
36945 {
36946 int error;
36947 struct pci_bus *b, *b2;
36948 @@ -1483,7 +1483,7 @@ err_out:
36949 }
36950
36951 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
36952 - int bus, struct pci_ops *ops, void *sysdata)
36953 + int bus, const struct pci_ops *ops, void *sysdata)
36954 {
36955 struct pci_bus *b;
36956
36957 diff -urNp linux-2.6.39.1/drivers/pci/proc.c linux-2.6.39.1/drivers/pci/proc.c
36958 --- linux-2.6.39.1/drivers/pci/proc.c 2011-05-19 00:06:34.000000000 -0400
36959 +++ linux-2.6.39.1/drivers/pci/proc.c 2011-05-22 19:41:37.000000000 -0400
36960 @@ -476,7 +476,16 @@ static const struct file_operations proc
36961 static int __init pci_proc_init(void)
36962 {
36963 struct pci_dev *dev = NULL;
36964 +
36965 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36966 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36967 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36968 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36969 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36970 +#endif
36971 +#else
36972 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36973 +#endif
36974 proc_create("devices", 0, proc_bus_pci_dir,
36975 &proc_bus_pci_dev_operations);
36976 proc_initialized = 1;
36977 diff -urNp linux-2.6.39.1/drivers/pci/xen-pcifront.c linux-2.6.39.1/drivers/pci/xen-pcifront.c
36978 --- linux-2.6.39.1/drivers/pci/xen-pcifront.c 2011-05-19 00:06:34.000000000 -0400
36979 +++ linux-2.6.39.1/drivers/pci/xen-pcifront.c 2011-05-22 19:36:32.000000000 -0400
36980 @@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_
36981 struct pcifront_sd *sd = bus->sysdata;
36982 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36983
36984 + pax_track_stack();
36985 +
36986 if (verbose_request)
36987 dev_info(&pdev->xdev->dev,
36988 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
36989 @@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci
36990 struct pcifront_sd *sd = bus->sysdata;
36991 struct pcifront_device *pdev = pcifront_get_pdev(sd);
36992
36993 + pax_track_stack();
36994 +
36995 if (verbose_request)
36996 dev_info(&pdev->xdev->dev,
36997 "write dev=%04x:%02x:%02x.%01x - "
36998 @@ -236,7 +240,7 @@ static int pcifront_bus_write(struct pci
36999 return errno_to_pcibios_err(do_pci_op(pdev, &op));
37000 }
37001
37002 -struct pci_ops pcifront_bus_ops = {
37003 +const struct pci_ops pcifront_bus_ops = {
37004 .read = pcifront_bus_read,
37005 .write = pcifront_bus_write,
37006 };
37007 @@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(stru
37008 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37009 struct msi_desc *entry;
37010
37011 + pax_track_stack();
37012 +
37013 if (nvec > SH_INFO_MAX_VEC) {
37014 dev_err(&dev->dev, "too much vector for pci frontend: %x."
37015 " Increase SH_INFO_MAX_VEC.\n", nvec);
37016 @@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(st
37017 struct pcifront_sd *sd = dev->bus->sysdata;
37018 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37019
37020 + pax_track_stack();
37021 +
37022 err = do_pci_op(pdev, &op);
37023
37024 /* What should do for error ? */
37025 @@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struc
37026 struct pcifront_sd *sd = dev->bus->sysdata;
37027 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37028
37029 + pax_track_stack();
37030 +
37031 err = do_pci_op(pdev, &op);
37032 if (likely(!err)) {
37033 vector[0] = op.value;
37034 @@ -368,7 +378,7 @@ static void pci_frontend_disable_msi(str
37035 printk(KERN_DEBUG "get fake response frombackend\n");
37036 }
37037
37038 -static struct xen_pci_frontend_ops pci_frontend_ops = {
37039 +static const struct xen_pci_frontend_ops pci_frontend_ops = {
37040 .enable_msi = pci_frontend_enable_msi,
37041 .disable_msi = pci_frontend_disable_msi,
37042 .enable_msix = pci_frontend_enable_msix,
37043 diff -urNp linux-2.6.39.1/drivers/pcmcia/at91_cf.c linux-2.6.39.1/drivers/pcmcia/at91_cf.c
37044 --- linux-2.6.39.1/drivers/pcmcia/at91_cf.c 2011-05-19 00:06:34.000000000 -0400
37045 +++ linux-2.6.39.1/drivers/pcmcia/at91_cf.c 2011-05-22 19:36:32.000000000 -0400
37046 @@ -203,7 +203,7 @@ at91_cf_set_mem_map(struct pcmcia_socket
37047 return 0;
37048 }
37049
37050 -static struct pccard_operations at91_cf_ops = {
37051 +static const struct pccard_operations at91_cf_ops = {
37052 .init = at91_cf_ss_init,
37053 .suspend = at91_cf_ss_suspend,
37054 .get_status = at91_cf_get_status,
37055 diff -urNp linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c
37056 --- linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37057 +++ linux-2.6.39.1/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37058 @@ -184,7 +184,7 @@ bfin_cf_set_mem_map(struct pcmcia_socket
37059 return 0;
37060 }
37061
37062 -static struct pccard_operations bfin_cf_ops = {
37063 +static const struct pccard_operations bfin_cf_ops = {
37064 .init = bfin_cf_ss_init,
37065 .suspend = bfin_cf_ss_suspend,
37066 .get_status = bfin_cf_get_status,
37067 diff -urNp linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c
37068 --- linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c 2011-05-19 00:06:34.000000000 -0400
37069 +++ linux-2.6.39.1/drivers/pcmcia/db1xxx_ss.c 2011-05-22 19:36:32.000000000 -0400
37070 @@ -384,7 +384,7 @@ static int au1x00_pcmcia_set_mem_map(str
37071 return 0;
37072 }
37073
37074 -static struct pccard_operations db1x_pcmcia_operations = {
37075 +static const struct pccard_operations db1x_pcmcia_operations = {
37076 .init = db1x_pcmcia_sock_init,
37077 .suspend = db1x_pcmcia_sock_suspend,
37078 .get_status = db1x_pcmcia_get_status,
37079 diff -urNp linux-2.6.39.1/drivers/pcmcia/electra_cf.c linux-2.6.39.1/drivers/pcmcia/electra_cf.c
37080 --- linux-2.6.39.1/drivers/pcmcia/electra_cf.c 2011-05-19 00:06:34.000000000 -0400
37081 +++ linux-2.6.39.1/drivers/pcmcia/electra_cf.c 2011-05-22 19:36:32.000000000 -0400
37082 @@ -173,7 +173,7 @@ static int electra_cf_set_mem_map(struct
37083 return 0;
37084 }
37085
37086 -static struct pccard_operations electra_cf_ops = {
37087 +static const struct pccard_operations electra_cf_ops = {
37088 .init = electra_cf_ss_init,
37089 .get_status = electra_cf_get_status,
37090 .set_socket = electra_cf_set_socket,
37091 diff -urNp linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c
37092 --- linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c 2011-05-19 00:06:34.000000000 -0400
37093 +++ linux-2.6.39.1/drivers/pcmcia/m32r_cfc.c 2011-05-22 19:36:32.000000000 -0400
37094 @@ -674,7 +674,7 @@ static int pcc_init(struct pcmcia_socket
37095 return 0;
37096 }
37097
37098 -static struct pccard_operations pcc_operations = {
37099 +static const struct pccard_operations pcc_operations = {
37100 .init = pcc_init,
37101 .get_status = pcc_get_status,
37102 .set_socket = pcc_set_socket,
37103 diff -urNp linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c
37104 --- linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c 2011-05-19 00:06:34.000000000 -0400
37105 +++ linux-2.6.39.1/drivers/pcmcia/m32r_pcc.c 2011-05-22 19:36:32.000000000 -0400
37106 @@ -652,7 +652,7 @@ static int pcc_init(struct pcmcia_socket
37107 return 0;
37108 }
37109
37110 -static struct pccard_operations pcc_operations = {
37111 +static const struct pccard_operations pcc_operations = {
37112 .init = pcc_init,
37113 .get_status = pcc_get_status,
37114 .set_socket = pcc_set_socket,
37115 diff -urNp linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c
37116 --- linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37117 +++ linux-2.6.39.1/drivers/pcmcia/m8xx_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37118 @@ -1139,7 +1139,7 @@ static int m8xx_sock_suspend(struct pcmc
37119 return m8xx_set_socket(sock, &dead_socket);
37120 }
37121
37122 -static struct pccard_operations m8xx_services = {
37123 +static const struct pccard_operations m8xx_services = {
37124 .init = m8xx_sock_init,
37125 .suspend = m8xx_sock_suspend,
37126 .get_status = m8xx_get_status,
37127 diff -urNp linux-2.6.39.1/drivers/pcmcia/omap_cf.c linux-2.6.39.1/drivers/pcmcia/omap_cf.c
37128 --- linux-2.6.39.1/drivers/pcmcia/omap_cf.c 2011-05-19 00:06:34.000000000 -0400
37129 +++ linux-2.6.39.1/drivers/pcmcia/omap_cf.c 2011-05-22 19:36:32.000000000 -0400
37130 @@ -185,7 +185,7 @@ omap_cf_set_mem_map(struct pcmcia_socket
37131 return 0;
37132 }
37133
37134 -static struct pccard_operations omap_cf_ops = {
37135 +static const struct pccard_operations omap_cf_ops = {
37136 .init = omap_cf_ss_init,
37137 .suspend = omap_cf_ss_suspend,
37138 .get_status = omap_cf_get_status,
37139 diff -urNp linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c
37140 --- linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c 2011-05-19 00:06:34.000000000 -0400
37141 +++ linux-2.6.39.1/drivers/pcmcia/rsrc_iodyn.c 2011-05-22 19:36:32.000000000 -0400
37142 @@ -161,7 +161,7 @@ static int iodyn_find_io(struct pcmcia_s
37143 }
37144
37145
37146 -struct pccard_resource_ops pccard_iodyn_ops = {
37147 +const struct pccard_resource_ops pccard_iodyn_ops = {
37148 .validate_mem = NULL,
37149 .find_io = iodyn_find_io,
37150 .find_mem = NULL,
37151 diff -urNp linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c
37152 --- linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c 2011-05-19 00:06:34.000000000 -0400
37153 +++ linux-2.6.39.1/drivers/pcmcia/rsrc_mgr.c 2011-05-22 19:36:32.000000000 -0400
37154 @@ -57,7 +57,7 @@ static int static_find_io(struct pcmcia_
37155 }
37156
37157
37158 -struct pccard_resource_ops pccard_static_ops = {
37159 +const struct pccard_resource_ops pccard_static_ops = {
37160 .validate_mem = NULL,
37161 .find_io = static_find_io,
37162 .find_mem = NULL,
37163 diff -urNp linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c
37164 --- linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c 2011-05-19 00:06:34.000000000 -0400
37165 +++ linux-2.6.39.1/drivers/pcmcia/vrc4171_card.c 2011-05-22 19:36:32.000000000 -0400
37166 @@ -479,7 +479,7 @@ static int pccard_set_mem_map(struct pcm
37167 return 0;
37168 }
37169
37170 -static struct pccard_operations vrc4171_pccard_operations = {
37171 +static const struct pccard_operations vrc4171_pccard_operations = {
37172 .init = pccard_init,
37173 .get_status = pccard_get_status,
37174 .set_socket = pccard_set_socket,
37175 diff -urNp linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c
37176 --- linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c 2011-05-19 00:06:34.000000000 -0400
37177 +++ linux-2.6.39.1/drivers/pcmcia/vrc4173_cardu.c 2011-05-22 19:36:32.000000000 -0400
37178 @@ -384,7 +384,7 @@ static void cardu_proc_setup(unsigned in
37179 {
37180 }
37181
37182 -static struct pccard_operations cardu_operations = {
37183 +static const struct pccard_operations cardu_operations = {
37184 .init = cardu_init,
37185 .register_callback = cardu_register_callback,
37186 .inquire_socket = cardu_inquire_socket,
37187 diff -urNp linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c
37188 --- linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c 2011-05-19 00:06:34.000000000 -0400
37189 +++ linux-2.6.39.1/drivers/pcmcia/xxs1500_ss.c 2011-05-22 19:36:32.000000000 -0400
37190 @@ -196,7 +196,7 @@ static int au1x00_pcmcia_set_mem_map(str
37191 return 0;
37192 }
37193
37194 -static struct pccard_operations xxs1500_pcmcia_operations = {
37195 +static const struct pccard_operations xxs1500_pcmcia_operations = {
37196 .init = xxs1500_pcmcia_sock_init,
37197 .suspend = xxs1500_pcmcia_sock_suspend,
37198 .get_status = xxs1500_pcmcia_get_status,
37199 diff -urNp linux-2.6.39.1/drivers/platform/x86/acerhdf.c linux-2.6.39.1/drivers/platform/x86/acerhdf.c
37200 --- linux-2.6.39.1/drivers/platform/x86/acerhdf.c 2011-05-19 00:06:34.000000000 -0400
37201 +++ linux-2.6.39.1/drivers/platform/x86/acerhdf.c 2011-05-22 19:36:32.000000000 -0400
37202 @@ -406,7 +406,7 @@ static int acerhdf_get_crit_temp(struct
37203 }
37204
37205 /* bind callback functions to thermalzone */
37206 -static struct thermal_zone_device_ops acerhdf_dev_ops = {
37207 +static const struct thermal_zone_device_ops acerhdf_dev_ops = {
37208 .bind = acerhdf_bind,
37209 .unbind = acerhdf_unbind,
37210 .get_temp = acerhdf_get_ec_temp,
37211 @@ -481,7 +481,7 @@ err_out:
37212 }
37213
37214 /* bind fan callbacks to fan device */
37215 -static struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37216 +static const struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37217 .get_max_state = acerhdf_get_max_state,
37218 .get_cur_state = acerhdf_get_cur_state,
37219 .set_cur_state = acerhdf_set_cur_state,
37220 diff -urNp linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c
37221 --- linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c 2011-05-19 00:06:34.000000000 -0400
37222 +++ linux-2.6.39.1/drivers/platform/x86/ideapad-laptop.c 2011-05-22 19:36:32.000000000 -0400
37223 @@ -207,7 +207,7 @@ static int ideapad_rfk_set(void *data, b
37224 return write_ec_cmd(ideapad_handle, opcode, !blocked);
37225 }
37226
37227 -static struct rfkill_ops ideapad_rfk_ops = {
37228 +static const struct rfkill_ops ideapad_rfk_ops = {
37229 .set_block = ideapad_rfk_set,
37230 };
37231
37232 diff -urNp linux-2.6.39.1/drivers/platform/x86/intel_menlow.c linux-2.6.39.1/drivers/platform/x86/intel_menlow.c
37233 --- linux-2.6.39.1/drivers/platform/x86/intel_menlow.c 2011-05-19 00:06:34.000000000 -0400
37234 +++ linux-2.6.39.1/drivers/platform/x86/intel_menlow.c 2011-05-22 19:36:32.000000000 -0400
37235 @@ -143,7 +143,7 @@ static int memory_set_cur_bandwidth(stru
37236 return 0;
37237 }
37238
37239 -static struct thermal_cooling_device_ops memory_cooling_ops = {
37240 +static const struct thermal_cooling_device_ops memory_cooling_ops = {
37241 .get_max_state = memory_get_max_bandwidth,
37242 .get_cur_state = memory_get_cur_bandwidth,
37243 .set_cur_state = memory_set_cur_bandwidth,
37244 diff -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
37245 --- linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c 2011-05-19 00:06:34.000000000 -0400
37246 +++ linux-2.6.39.1/drivers/platform/x86/intel_mid_thermal.c 2011-05-22 19:36:32.000000000 -0400
37247 @@ -458,7 +458,7 @@ static int read_curr_temp(struct thermal
37248 }
37249
37250 /* Can't be const */
37251 -static struct thermal_zone_device_ops tzd_ops = {
37252 +static const struct thermal_zone_device_ops tzd_ops = {
37253 .get_temp = read_curr_temp,
37254 };
37255
37256 diff -urNp linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c
37257 --- linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c 2011-05-19 00:06:34.000000000 -0400
37258 +++ linux-2.6.39.1/drivers/platform/x86/samsung-laptop.c 2011-05-22 19:36:32.000000000 -0400
37259 @@ -419,7 +419,7 @@ static int rfkill_set(void *data, bool b
37260 return 0;
37261 }
37262
37263 -static struct rfkill_ops rfkill_ops = {
37264 +static const struct rfkill_ops rfkill_ops = {
37265 .set_block = rfkill_set,
37266 };
37267
37268 diff -urNp linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c
37269 --- linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c 2011-05-19 00:06:34.000000000 -0400
37270 +++ linux-2.6.39.1/drivers/pnp/pnpbios/bioscalls.c 2011-05-22 19:36:32.000000000 -0400
37271 @@ -59,7 +59,7 @@ do { \
37272 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37273 } while(0)
37274
37275 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37276 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37277 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37278
37279 /*
37280 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
37281
37282 cpu = get_cpu();
37283 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37284 +
37285 + pax_open_kernel();
37286 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37287 + pax_close_kernel();
37288
37289 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37290 spin_lock_irqsave(&pnp_bios_lock, flags);
37291 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
37292 :"memory");
37293 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37294
37295 + pax_open_kernel();
37296 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37297 + pax_close_kernel();
37298 +
37299 put_cpu();
37300
37301 /* If we get here and this is set then the PnP BIOS faulted on us. */
37302 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
37303 return status;
37304 }
37305
37306 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37307 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37308 {
37309 int i;
37310
37311 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
37312 pnp_bios_callpoint.offset = header->fields.pm16offset;
37313 pnp_bios_callpoint.segment = PNP_CS16;
37314
37315 + pax_open_kernel();
37316 +
37317 for_each_possible_cpu(i) {
37318 struct desc_struct *gdt = get_cpu_gdt_table(i);
37319 if (!gdt)
37320 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
37321 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37322 (unsigned long)__va(header->fields.pm16dseg));
37323 }
37324 +
37325 + pax_close_kernel();
37326 }
37327 diff -urNp linux-2.6.39.1/drivers/pnp/resource.c linux-2.6.39.1/drivers/pnp/resource.c
37328 --- linux-2.6.39.1/drivers/pnp/resource.c 2011-05-19 00:06:34.000000000 -0400
37329 +++ linux-2.6.39.1/drivers/pnp/resource.c 2011-05-22 19:36:32.000000000 -0400
37330 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
37331 return 1;
37332
37333 /* check if the resource is valid */
37334 - if (*irq < 0 || *irq > 15)
37335 + if (*irq > 15)
37336 return 0;
37337
37338 /* check if the resource is reserved */
37339 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
37340 return 1;
37341
37342 /* check if the resource is valid */
37343 - if (*dma < 0 || *dma == 4 || *dma > 7)
37344 + if (*dma == 4 || *dma > 7)
37345 return 0;
37346
37347 /* check if the resource is reserved */
37348 diff -urNp linux-2.6.39.1/drivers/power/max8925_power.c linux-2.6.39.1/drivers/power/max8925_power.c
37349 --- linux-2.6.39.1/drivers/power/max8925_power.c 2011-05-19 00:06:34.000000000 -0400
37350 +++ linux-2.6.39.1/drivers/power/max8925_power.c 2011-05-22 19:36:32.000000000 -0400
37351 @@ -426,7 +426,7 @@ static __devinit int max8925_power_probe
37352 {
37353 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
37354 struct max8925_platform_data *max8925_pdata;
37355 - struct max8925_power_pdata *pdata = NULL;
37356 + const struct max8925_power_pdata *pdata = NULL;
37357 struct max8925_power_info *info;
37358 int ret;
37359
37360 diff -urNp linux-2.6.39.1/drivers/regulator/core.c linux-2.6.39.1/drivers/regulator/core.c
37361 --- linux-2.6.39.1/drivers/regulator/core.c 2011-05-19 00:06:34.000000000 -0400
37362 +++ linux-2.6.39.1/drivers/regulator/core.c 2011-05-22 19:36:32.000000000 -0400
37363 @@ -2883,7 +2883,7 @@ core_initcall(regulator_init);
37364 static int __init regulator_init_complete(void)
37365 {
37366 struct regulator_dev *rdev;
37367 - struct regulator_ops *ops;
37368 + const struct regulator_ops *ops;
37369 struct regulation_constraints *c;
37370 int enabled, ret;
37371
37372 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c
37373 --- linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c 2011-05-19 00:06:34.000000000 -0400
37374 +++ linux-2.6.39.1/drivers/rtc/rtc-at32ap700x.c 2011-05-22 19:36:32.000000000 -0400
37375 @@ -187,7 +187,7 @@ static irqreturn_t at32_rtc_interrupt(in
37376 return ret;
37377 }
37378
37379 -static struct rtc_class_ops at32_rtc_ops = {
37380 +static const struct rtc_class_ops at32_rtc_ops = {
37381 .read_time = at32_rtc_readtime,
37382 .set_time = at32_rtc_settime,
37383 .read_alarm = at32_rtc_readalarm,
37384 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c
37385 --- linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c 2011-05-19 00:06:34.000000000 -0400
37386 +++ linux-2.6.39.1/drivers/rtc/rtc-au1xxx.c 2011-05-22 19:36:32.000000000 -0400
37387 @@ -57,7 +57,7 @@ static int au1xtoy_rtc_set_time(struct d
37388 return 0;
37389 }
37390
37391 -static struct rtc_class_ops au1xtoy_rtc_ops = {
37392 +static const struct rtc_class_ops au1xtoy_rtc_ops = {
37393 .read_time = au1xtoy_rtc_read_time,
37394 .set_time = au1xtoy_rtc_set_time,
37395 };
37396 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-bfin.c linux-2.6.39.1/drivers/rtc/rtc-bfin.c
37397 --- linux-2.6.39.1/drivers/rtc/rtc-bfin.c 2011-05-19 00:06:34.000000000 -0400
37398 +++ linux-2.6.39.1/drivers/rtc/rtc-bfin.c 2011-05-22 19:36:32.000000000 -0400
37399 @@ -333,7 +333,7 @@ static int bfin_rtc_proc(struct device *
37400 #undef yesno
37401 }
37402
37403 -static struct rtc_class_ops bfin_rtc_ops = {
37404 +static const struct rtc_class_ops bfin_rtc_ops = {
37405 .read_time = bfin_rtc_read_time,
37406 .set_time = bfin_rtc_set_time,
37407 .read_alarm = bfin_rtc_read_alarm,
37408 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-coh901331.c linux-2.6.39.1/drivers/rtc/rtc-coh901331.c
37409 --- linux-2.6.39.1/drivers/rtc/rtc-coh901331.c 2011-05-19 00:06:34.000000000 -0400
37410 +++ linux-2.6.39.1/drivers/rtc/rtc-coh901331.c 2011-05-22 19:36:32.000000000 -0400
37411 @@ -142,7 +142,7 @@ static int coh901331_alarm_irq_enable(st
37412 return 0;
37413 }
37414
37415 -static struct rtc_class_ops coh901331_ops = {
37416 +static const struct rtc_class_ops coh901331_ops = {
37417 .read_time = coh901331_read_time,
37418 .set_mmss = coh901331_set_mmss,
37419 .read_alarm = coh901331_read_alarm,
37420 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-davinci.c linux-2.6.39.1/drivers/rtc/rtc-davinci.c
37421 --- linux-2.6.39.1/drivers/rtc/rtc-davinci.c 2011-05-19 00:06:34.000000000 -0400
37422 +++ linux-2.6.39.1/drivers/rtc/rtc-davinci.c 2011-05-22 19:36:32.000000000 -0400
37423 @@ -469,7 +469,7 @@ static int davinci_rtc_set_alarm(struct
37424 return 0;
37425 }
37426
37427 -static struct rtc_class_ops davinci_rtc_ops = {
37428 +static const struct rtc_class_ops davinci_rtc_ops = {
37429 .ioctl = davinci_rtc_ioctl,
37430 .read_time = davinci_rtc_read_time,
37431 .set_time = davinci_rtc_set_time,
37432 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-dev.c linux-2.6.39.1/drivers/rtc/rtc-dev.c
37433 --- linux-2.6.39.1/drivers/rtc/rtc-dev.c 2011-05-19 00:06:34.000000000 -0400
37434 +++ linux-2.6.39.1/drivers/rtc/rtc-dev.c 2011-05-22 19:41:37.000000000 -0400
37435 @@ -14,6 +14,7 @@
37436 #include <linux/module.h>
37437 #include <linux/rtc.h>
37438 #include <linux/sched.h>
37439 +#include <linux/grsecurity.h>
37440 #include "rtc-core.h"
37441
37442 static dev_t rtc_devt;
37443 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *f
37444 if (copy_from_user(&tm, uarg, sizeof(tm)))
37445 return -EFAULT;
37446
37447 + gr_log_timechange();
37448 +
37449 return rtc_set_time(rtc, &tm);
37450
37451 case RTC_PIE_ON:
37452 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c
37453 --- linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c 2011-05-19 00:06:34.000000000 -0400
37454 +++ linux-2.6.39.1/drivers/rtc/rtc-dm355evm.c 2011-05-22 19:36:32.000000000 -0400
37455 @@ -115,7 +115,7 @@ static int dm355evm_rtc_set_time(struct
37456 return 0;
37457 }
37458
37459 -static struct rtc_class_ops dm355evm_rtc_ops = {
37460 +static const struct rtc_class_ops dm355evm_rtc_ops = {
37461 .read_time = dm355evm_rtc_read_time,
37462 .set_time = dm355evm_rtc_set_time,
37463 };
37464 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-ds1302.c linux-2.6.39.1/drivers/rtc/rtc-ds1302.c
37465 --- linux-2.6.39.1/drivers/rtc/rtc-ds1302.c 2011-05-19 00:06:34.000000000 -0400
37466 +++ linux-2.6.39.1/drivers/rtc/rtc-ds1302.c 2011-05-22 19:36:32.000000000 -0400
37467 @@ -199,7 +199,7 @@ static int ds1302_rtc_ioctl(struct devic
37468 return -ENOIOCTLCMD;
37469 }
37470
37471 -static struct rtc_class_ops ds1302_rtc_ops = {
37472 +static const struct rtc_class_ops ds1302_rtc_ops = {
37473 .read_time = ds1302_rtc_read_time,
37474 .set_time = ds1302_rtc_set_time,
37475 .ioctl = ds1302_rtc_ioctl,
37476 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-imxdi.c linux-2.6.39.1/drivers/rtc/rtc-imxdi.c
37477 --- linux-2.6.39.1/drivers/rtc/rtc-imxdi.c 2011-05-19 00:06:34.000000000 -0400
37478 +++ linux-2.6.39.1/drivers/rtc/rtc-imxdi.c 2011-05-22 19:36:32.000000000 -0400
37479 @@ -290,7 +290,7 @@ static int dryice_rtc_set_alarm(struct d
37480 return 0;
37481 }
37482
37483 -static struct rtc_class_ops dryice_rtc_ops = {
37484 +static const struct rtc_class_ops dryice_rtc_ops = {
37485 .read_time = dryice_rtc_read_time,
37486 .set_mmss = dryice_rtc_set_mmss,
37487 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
37488 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-jz4740.c linux-2.6.39.1/drivers/rtc/rtc-jz4740.c
37489 --- linux-2.6.39.1/drivers/rtc/rtc-jz4740.c 2011-05-19 00:06:34.000000000 -0400
37490 +++ linux-2.6.39.1/drivers/rtc/rtc-jz4740.c 2011-05-22 19:36:32.000000000 -0400
37491 @@ -174,7 +174,7 @@ static int jz4740_rtc_alarm_irq_enable(s
37492 return jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AF_IRQ, enable);
37493 }
37494
37495 -static struct rtc_class_ops jz4740_rtc_ops = {
37496 +static const struct rtc_class_ops jz4740_rtc_ops = {
37497 .read_time = jz4740_rtc_read_time,
37498 .set_mmss = jz4740_rtc_set_mmss,
37499 .read_alarm = jz4740_rtc_read_alarm,
37500 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-m41t80.c linux-2.6.39.1/drivers/rtc/rtc-m41t80.c
37501 --- linux-2.6.39.1/drivers/rtc/rtc-m41t80.c 2011-05-19 00:06:34.000000000 -0400
37502 +++ linux-2.6.39.1/drivers/rtc/rtc-m41t80.c 2011-05-22 19:36:32.000000000 -0400
37503 @@ -354,7 +354,7 @@ static int m41t80_rtc_read_alarm(struct
37504 return 0;
37505 }
37506
37507 -static struct rtc_class_ops m41t80_rtc_ops = {
37508 +static const struct rtc_class_ops m41t80_rtc_ops = {
37509 .read_time = m41t80_rtc_read_time,
37510 .set_time = m41t80_rtc_set_time,
37511 .read_alarm = m41t80_rtc_read_alarm,
37512 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-mxc.c linux-2.6.39.1/drivers/rtc/rtc-mxc.c
37513 --- linux-2.6.39.1/drivers/rtc/rtc-mxc.c 2011-05-19 00:06:34.000000000 -0400
37514 +++ linux-2.6.39.1/drivers/rtc/rtc-mxc.c 2011-05-22 19:36:32.000000000 -0400
37515 @@ -355,7 +355,7 @@ static int mxc_rtc_set_alarm(struct devi
37516 }
37517
37518 /* RTC layer */
37519 -static struct rtc_class_ops mxc_rtc_ops = {
37520 +static const struct rtc_class_ops mxc_rtc_ops = {
37521 .release = mxc_rtc_release,
37522 .read_time = mxc_rtc_read_time,
37523 .set_mmss = mxc_rtc_set_mmss,
37524 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-nuc900.c linux-2.6.39.1/drivers/rtc/rtc-nuc900.c
37525 --- linux-2.6.39.1/drivers/rtc/rtc-nuc900.c 2011-05-19 00:06:34.000000000 -0400
37526 +++ linux-2.6.39.1/drivers/rtc/rtc-nuc900.c 2011-05-22 19:36:32.000000000 -0400
37527 @@ -214,7 +214,7 @@ static int nuc900_rtc_set_alarm(struct d
37528 return 0;
37529 }
37530
37531 -static struct rtc_class_ops nuc900_rtc_ops = {
37532 +static const struct rtc_class_ops nuc900_rtc_ops = {
37533 .read_time = nuc900_rtc_read_time,
37534 .set_time = nuc900_rtc_set_time,
37535 .read_alarm = nuc900_rtc_read_alarm,
37536 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-omap.c linux-2.6.39.1/drivers/rtc/rtc-omap.c
37537 --- linux-2.6.39.1/drivers/rtc/rtc-omap.c 2011-05-19 00:06:34.000000000 -0400
37538 +++ linux-2.6.39.1/drivers/rtc/rtc-omap.c 2011-05-22 19:36:32.000000000 -0400
37539 @@ -274,7 +274,7 @@ static int omap_rtc_set_alarm(struct dev
37540 return 0;
37541 }
37542
37543 -static struct rtc_class_ops omap_rtc_ops = {
37544 +static const struct rtc_class_ops omap_rtc_ops = {
37545 .read_time = omap_rtc_read_time,
37546 .set_time = omap_rtc_set_time,
37547 .read_alarm = omap_rtc_read_alarm,
37548 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c
37549 --- linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c 2011-05-19 00:06:34.000000000 -0400
37550 +++ linux-2.6.39.1/drivers/rtc/rtc-pcf50633.c 2011-05-22 19:36:32.000000000 -0400
37551 @@ -238,7 +238,7 @@ static int pcf50633_rtc_set_alarm(struct
37552 return ret;
37553 }
37554
37555 -static struct rtc_class_ops pcf50633_rtc_ops = {
37556 +static const struct rtc_class_ops pcf50633_rtc_ops = {
37557 .read_time = pcf50633_rtc_read_time,
37558 .set_time = pcf50633_rtc_set_time,
37559 .read_alarm = pcf50633_rtc_read_alarm,
37560 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-pl031.c linux-2.6.39.1/drivers/rtc/rtc-pl031.c
37561 --- linux-2.6.39.1/drivers/rtc/rtc-pl031.c 2011-05-19 00:06:34.000000000 -0400
37562 +++ linux-2.6.39.1/drivers/rtc/rtc-pl031.c 2011-05-22 19:36:32.000000000 -0400
37563 @@ -374,7 +374,7 @@ err_req:
37564 }
37565
37566 /* Operations for the original ARM version */
37567 -static struct rtc_class_ops arm_pl031_ops = {
37568 +static const struct rtc_class_ops arm_pl031_ops = {
37569 .read_time = pl031_read_time,
37570 .set_time = pl031_set_time,
37571 .read_alarm = pl031_read_alarm,
37572 @@ -383,7 +383,7 @@ static struct rtc_class_ops arm_pl031_op
37573 };
37574
37575 /* The First ST derivative */
37576 -static struct rtc_class_ops stv1_pl031_ops = {
37577 +static const struct rtc_class_ops stv1_pl031_ops = {
37578 .read_time = pl031_read_time,
37579 .set_time = pl031_set_time,
37580 .read_alarm = pl031_read_alarm,
37581 @@ -392,7 +392,7 @@ static struct rtc_class_ops stv1_pl031_o
37582 };
37583
37584 /* And the second ST derivative */
37585 -static struct rtc_class_ops stv2_pl031_ops = {
37586 +static const struct rtc_class_ops stv2_pl031_ops = {
37587 .read_time = pl031_stv2_read_time,
37588 .set_time = pl031_stv2_set_time,
37589 .read_alarm = pl031_stv2_read_alarm,
37590 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-rx8025.c linux-2.6.39.1/drivers/rtc/rtc-rx8025.c
37591 --- linux-2.6.39.1/drivers/rtc/rtc-rx8025.c 2011-05-19 00:06:34.000000000 -0400
37592 +++ linux-2.6.39.1/drivers/rtc/rtc-rx8025.c 2011-05-22 19:36:32.000000000 -0400
37593 @@ -424,7 +424,7 @@ static int rx8025_alarm_irq_enable(struc
37594 return 0;
37595 }
37596
37597 -static struct rtc_class_ops rx8025_rtc_ops = {
37598 +static const struct rtc_class_ops rx8025_rtc_ops = {
37599 .read_time = rx8025_get_time,
37600 .set_time = rx8025_set_time,
37601 .read_alarm = rx8025_read_alarm,
37602 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-sh.c linux-2.6.39.1/drivers/rtc/rtc-sh.c
37603 --- linux-2.6.39.1/drivers/rtc/rtc-sh.c 2011-05-19 00:06:34.000000000 -0400
37604 +++ linux-2.6.39.1/drivers/rtc/rtc-sh.c 2011-05-22 19:36:32.000000000 -0400
37605 @@ -576,7 +576,7 @@ static int sh_rtc_set_alarm(struct devic
37606 return 0;
37607 }
37608
37609 -static struct rtc_class_ops sh_rtc_ops = {
37610 +static const struct rtc_class_ops sh_rtc_ops = {
37611 .read_time = sh_rtc_read_time,
37612 .set_time = sh_rtc_set_time,
37613 .read_alarm = sh_rtc_read_alarm,
37614 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c
37615 --- linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c 2011-05-19 00:06:34.000000000 -0400
37616 +++ linux-2.6.39.1/drivers/rtc/rtc-stmp3xxx.c 2011-05-22 19:36:32.000000000 -0400
37617 @@ -133,7 +133,7 @@ static int stmp3xxx_rtc_set_alarm(struct
37618 return 0;
37619 }
37620
37621 -static struct rtc_class_ops stmp3xxx_rtc_ops = {
37622 +static const struct rtc_class_ops stmp3xxx_rtc_ops = {
37623 .alarm_irq_enable =
37624 stmp3xxx_alarm_irq_enable,
37625 .read_time = stmp3xxx_rtc_gettime,
37626 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-tegra.c linux-2.6.39.1/drivers/rtc/rtc-tegra.c
37627 --- linux-2.6.39.1/drivers/rtc/rtc-tegra.c 2011-05-19 00:06:34.000000000 -0400
37628 +++ linux-2.6.39.1/drivers/rtc/rtc-tegra.c 2011-05-22 19:36:32.000000000 -0400
37629 @@ -294,7 +294,7 @@ static irqreturn_t tegra_rtc_irq_handler
37630 return IRQ_HANDLED;
37631 }
37632
37633 -static struct rtc_class_ops tegra_rtc_ops = {
37634 +static const struct rtc_class_ops tegra_rtc_ops = {
37635 .read_time = tegra_rtc_read_time,
37636 .set_time = tegra_rtc_set_time,
37637 .read_alarm = tegra_rtc_read_alarm,
37638 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-twl.c linux-2.6.39.1/drivers/rtc/rtc-twl.c
37639 --- linux-2.6.39.1/drivers/rtc/rtc-twl.c 2011-05-19 00:06:34.000000000 -0400
37640 +++ linux-2.6.39.1/drivers/rtc/rtc-twl.c 2011-05-22 19:36:32.000000000 -0400
37641 @@ -415,7 +415,7 @@ out:
37642 return ret;
37643 }
37644
37645 -static struct rtc_class_ops twl_rtc_ops = {
37646 +static const struct rtc_class_ops twl_rtc_ops = {
37647 .read_time = twl_rtc_read_time,
37648 .set_time = twl_rtc_set_time,
37649 .read_alarm = twl_rtc_read_alarm,
37650 diff -urNp linux-2.6.39.1/drivers/rtc/rtc-v3020.c linux-2.6.39.1/drivers/rtc/rtc-v3020.c
37651 --- linux-2.6.39.1/drivers/rtc/rtc-v3020.c 2011-05-19 00:06:34.000000000 -0400
37652 +++ linux-2.6.39.1/drivers/rtc/rtc-v3020.c 2011-05-22 19:36:32.000000000 -0400
37653 @@ -62,7 +62,7 @@ struct v3020 {
37654 /* GPIO access */
37655 struct v3020_gpio *gpio;
37656
37657 - struct v3020_chip_ops *ops;
37658 + const struct v3020_chip_ops *ops;
37659
37660 struct rtc_device *rtc;
37661 };
37662 @@ -100,7 +100,7 @@ static unsigned char v3020_mmio_read_bit
37663 return !!(readl(chip->ioaddress) & (1 << chip->leftshift));
37664 }
37665
37666 -static struct v3020_chip_ops v3020_mmio_ops = {
37667 +static const struct v3020_chip_ops v3020_mmio_ops = {
37668 .map_io = v3020_mmio_map,
37669 .unmap_io = v3020_mmio_unmap,
37670 .read_bit = v3020_mmio_read_bit,
37671 @@ -177,7 +177,7 @@ static unsigned char v3020_gpio_read_bit
37672 return bit;
37673 }
37674
37675 -static struct v3020_chip_ops v3020_gpio_ops = {
37676 +static const struct v3020_chip_ops v3020_gpio_ops = {
37677 .map_io = v3020_gpio_map,
37678 .unmap_io = v3020_gpio_unmap,
37679 .read_bit = v3020_gpio_read_bit,
37680 diff -urNp linux-2.6.39.1/drivers/s390/char/con3270.c linux-2.6.39.1/drivers/s390/char/con3270.c
37681 --- linux-2.6.39.1/drivers/s390/char/con3270.c 2011-05-19 00:06:34.000000000 -0400
37682 +++ linux-2.6.39.1/drivers/s390/char/con3270.c 2011-05-22 19:36:32.000000000 -0400
37683 @@ -28,7 +28,7 @@
37684 #define CON3270_OUTPUT_BUFFER_SIZE 1024
37685 #define CON3270_STRING_PAGES 4
37686
37687 -static struct raw3270_fn con3270_fn;
37688 +static const struct raw3270_fn con3270_fn;
37689
37690 /*
37691 * Main 3270 console view data structure.
37692 @@ -413,7 +413,7 @@ con3270_irq(struct con3270 *cp, struct r
37693 }
37694
37695 /* Console view to a 3270 device. */
37696 -static struct raw3270_fn con3270_fn = {
37697 +static const struct raw3270_fn con3270_fn = {
37698 .activate = con3270_activate,
37699 .deactivate = con3270_deactivate,
37700 .intv = (void *) con3270_irq
37701 diff -urNp linux-2.6.39.1/drivers/s390/char/fs3270.c linux-2.6.39.1/drivers/s390/char/fs3270.c
37702 --- linux-2.6.39.1/drivers/s390/char/fs3270.c 2011-05-19 00:06:34.000000000 -0400
37703 +++ linux-2.6.39.1/drivers/s390/char/fs3270.c 2011-05-22 19:36:32.000000000 -0400
37704 @@ -24,7 +24,7 @@
37705 #include "raw3270.h"
37706 #include "ctrlchar.h"
37707
37708 -static struct raw3270_fn fs3270_fn;
37709 +static const struct raw3270_fn fs3270_fn;
37710
37711 struct fs3270 {
37712 struct raw3270_view view;
37713 @@ -413,7 +413,7 @@ fs3270_release(struct raw3270_view *view
37714 }
37715
37716 /* View to a 3270 device. Can be console, tty or fullscreen. */
37717 -static struct raw3270_fn fs3270_fn = {
37718 +static const struct raw3270_fn fs3270_fn = {
37719 .activate = fs3270_activate,
37720 .deactivate = fs3270_deactivate,
37721 .intv = (void *) fs3270_irq,
37722 diff -urNp linux-2.6.39.1/drivers/s390/char/raw3270.c linux-2.6.39.1/drivers/s390/char/raw3270.c
37723 --- linux-2.6.39.1/drivers/s390/char/raw3270.c 2011-05-19 00:06:34.000000000 -0400
37724 +++ linux-2.6.39.1/drivers/s390/char/raw3270.c 2011-05-22 19:36:32.000000000 -0400
37725 @@ -488,7 +488,7 @@ raw3270_init_irq(struct raw3270_view *vi
37726 return RAW3270_IO_DONE;
37727 }
37728
37729 -static struct raw3270_fn raw3270_init_fn = {
37730 +static const struct raw3270_fn raw3270_init_fn = {
37731 .intv = raw3270_init_irq
37732 };
37733
37734 diff -urNp linux-2.6.39.1/drivers/s390/char/tty3270.c linux-2.6.39.1/drivers/s390/char/tty3270.c
37735 --- linux-2.6.39.1/drivers/s390/char/tty3270.c 2011-05-19 00:06:34.000000000 -0400
37736 +++ linux-2.6.39.1/drivers/s390/char/tty3270.c 2011-05-22 19:36:32.000000000 -0400
37737 @@ -37,7 +37,7 @@
37738 struct tty_driver *tty3270_driver;
37739 static int tty3270_max_index;
37740
37741 -static struct raw3270_fn tty3270_fn;
37742 +static const struct raw3270_fn tty3270_fn;
37743
37744 struct tty3270_cell {
37745 unsigned char character;
37746 @@ -834,7 +834,7 @@ tty3270_del_views(void)
37747 }
37748 }
37749
37750 -static struct raw3270_fn tty3270_fn = {
37751 +static const struct raw3270_fn tty3270_fn = {
37752 .activate = tty3270_activate,
37753 .deactivate = tty3270_deactivate,
37754 .intv = (void *) tty3270_irq,
37755 diff -urNp linux-2.6.39.1/drivers/s390/cio/qdio_debug.c linux-2.6.39.1/drivers/s390/cio/qdio_debug.c
37756 --- linux-2.6.39.1/drivers/s390/cio/qdio_debug.c 2011-05-19 00:06:34.000000000 -0400
37757 +++ linux-2.6.39.1/drivers/s390/cio/qdio_debug.c 2011-05-22 19:36:32.000000000 -0400
37758 @@ -225,7 +225,7 @@ static int qperf_seq_open(struct inode *
37759 filp->f_path.dentry->d_inode->i_private);
37760 }
37761
37762 -static struct file_operations debugfs_perf_fops = {
37763 +static const struct file_operations debugfs_perf_fops = {
37764 .owner = THIS_MODULE,
37765 .open = qperf_seq_open,
37766 .read = seq_read,
37767 diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c
37768 --- linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-19 00:06:34.000000000 -0400
37769 +++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-22 19:36:32.000000000 -0400
37770 @@ -415,7 +415,7 @@ out_free:
37771 /**
37772 * The crypto operations for a CEX2A card.
37773 */
37774 -static struct zcrypt_ops zcrypt_cex2a_ops = {
37775 +static const struct zcrypt_ops zcrypt_cex2a_ops = {
37776 .rsa_modexpo = zcrypt_cex2a_modexpo,
37777 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
37778 };
37779 diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c
37780 --- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c 2011-05-19 00:06:34.000000000 -0400
37781 +++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcica.c 2011-05-22 19:36:32.000000000 -0400
37782 @@ -347,7 +347,7 @@ out_free:
37783 /**
37784 * The crypto operations for a PCICA card.
37785 */
37786 -static struct zcrypt_ops zcrypt_pcica_ops = {
37787 +static const struct zcrypt_ops zcrypt_pcica_ops = {
37788 .rsa_modexpo = zcrypt_pcica_modexpo,
37789 .rsa_modexpo_crt = zcrypt_pcica_modexpo_crt,
37790 };
37791 diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c
37792 --- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-19 00:06:34.000000000 -0400
37793 +++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-22 19:36:32.000000000 -0400
37794 @@ -553,7 +553,7 @@ out_free:
37795 /**
37796 * The crypto operations for a PCICC card.
37797 */
37798 -static struct zcrypt_ops zcrypt_pcicc_ops = {
37799 +static const struct zcrypt_ops zcrypt_pcicc_ops = {
37800 .rsa_modexpo = zcrypt_pcicc_modexpo,
37801 .rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt,
37802 };
37803 diff -urNp linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c
37804 --- linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-19 00:06:34.000000000 -0400
37805 +++ linux-2.6.39.1/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-22 19:36:32.000000000 -0400
37806 @@ -851,13 +851,13 @@ static long zcrypt_pcixcc_rng(struct zcr
37807 /**
37808 * The crypto operations for a PCIXCC/CEX2C card.
37809 */
37810 -static struct zcrypt_ops zcrypt_pcixcc_ops = {
37811 +static const struct zcrypt_ops zcrypt_pcixcc_ops = {
37812 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37813 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37814 .send_cprb = zcrypt_pcixcc_send_cprb,
37815 };
37816
37817 -static struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37818 +static const struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37819 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37820 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37821 .send_cprb = zcrypt_pcixcc_send_cprb,
37822 diff -urNp linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c
37823 --- linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c 2011-05-19 00:06:34.000000000 -0400
37824 +++ linux-2.6.39.1/drivers/s390/kvm/kvm_virtio.c 2011-05-22 19:36:32.000000000 -0400
37825 @@ -266,7 +266,7 @@ error:
37826 /*
37827 * The config ops structure as defined by virtio config
37828 */
37829 -static struct virtio_config_ops kvm_vq_configspace_ops = {
37830 +static const struct virtio_config_ops kvm_vq_configspace_ops = {
37831 .get_features = kvm_get_features,
37832 .finalize_features = kvm_finalize_features,
37833 .get = kvm_get,
37834 diff -urNp linux-2.6.39.1/drivers/s390/net/qeth_core.h linux-2.6.39.1/drivers/s390/net/qeth_core.h
37835 --- linux-2.6.39.1/drivers/s390/net/qeth_core.h 2011-05-19 00:06:34.000000000 -0400
37836 +++ linux-2.6.39.1/drivers/s390/net/qeth_core.h 2011-05-22 19:36:32.000000000 -0400
37837 @@ -743,7 +743,7 @@ struct qeth_card {
37838 struct qeth_qdio_info qdio;
37839 struct qeth_perf_stats perf_stats;
37840 int read_or_write_problem;
37841 - struct qeth_osn_info osn_info;
37842 + const struct qeth_osn_info osn_info;
37843 struct qeth_discipline discipline;
37844 atomic_t force_alloc_skb;
37845 struct service_level qeth_service_level;
37846 diff -urNp linux-2.6.39.1/drivers/scsi/53c700.c linux-2.6.39.1/drivers/scsi/53c700.c
37847 --- linux-2.6.39.1/drivers/scsi/53c700.c 2011-05-19 00:06:34.000000000 -0400
37848 +++ linux-2.6.39.1/drivers/scsi/53c700.c 2011-05-22 19:36:32.000000000 -0400
37849 @@ -2153,7 +2153,7 @@ EXPORT_SYMBOL(NCR_700_detect);
37850 EXPORT_SYMBOL(NCR_700_release);
37851 EXPORT_SYMBOL(NCR_700_intr);
37852
37853 -static struct spi_function_template NCR_700_transport_functions = {
37854 +static struct spi_function_template NCR_700_transport_functions = {
37855 .set_period = NCR_700_set_period,
37856 .show_period = 1,
37857 .set_offset = NCR_700_set_offset,
37858 diff -urNp linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c
37859 --- linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c 2011-05-19 00:06:34.000000000 -0400
37860 +++ linux-2.6.39.1/drivers/scsi/aacraid/commctrl.c 2011-05-22 19:36:32.000000000 -0400
37861 @@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_d
37862 u32 actual_fibsize64, actual_fibsize = 0;
37863 int i;
37864
37865 + pax_track_stack();
37866
37867 if (dev->in_reset) {
37868 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
37869 diff -urNp linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c
37870 --- linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-19 00:06:34.000000000 -0400
37871 +++ linux-2.6.39.1/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-22 19:41:37.000000000 -0400
37872 @@ -486,7 +486,7 @@ static ssize_t asd_show_update_bios(stru
37873 flash_error_table[i].reason);
37874 }
37875
37876 -static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
37877 +static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
37878 asd_show_update_bios, asd_store_update_bios);
37879
37880 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
37881 diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c
37882 --- linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c 2011-05-19 00:06:34.000000000 -0400
37883 +++ linux-2.6.39.1/drivers/scsi/bfa/bfa_core.c 2011-05-22 19:36:32.000000000 -0400
37884 @@ -24,7 +24,7 @@ BFA_TRC_FILE(HAL, CORE);
37885 /*
37886 * BFA module list terminated by NULL
37887 */
37888 -static struct bfa_module_s *hal_mods[] = {
37889 +static const struct bfa_module_s *hal_mods[] = {
37890 &hal_mod_sgpg,
37891 &hal_mod_fcport,
37892 &hal_mod_fcxp,
37893 diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfad.c linux-2.6.39.1/drivers/scsi/bfa/bfad.c
37894 --- linux-2.6.39.1/drivers/scsi/bfa/bfad.c 2011-05-19 00:06:34.000000000 -0400
37895 +++ linux-2.6.39.1/drivers/scsi/bfa/bfad.c 2011-05-22 19:36:32.000000000 -0400
37896 @@ -1027,6 +1027,8 @@ bfad_start_ops(struct bfad_s *bfad) {
37897 struct bfad_vport_s *vport, *vport_new;
37898 struct bfa_fcs_driver_info_s driver_info;
37899
37900 + pax_track_stack();
37901 +
37902 /* Fill the driver_info info to fcs*/
37903 memset(&driver_info, 0, sizeof(driver_info));
37904 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
37905 diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c
37906 --- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c 2011-05-19 00:06:34.000000000 -0400
37907 +++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs.c 2011-05-22 19:36:32.000000000 -0400
37908 @@ -70,7 +70,7 @@ bfa_fcs_attach(struct bfa_fcs_s *fcs, st
37909 bfa_boolean_t min_cfg)
37910 {
37911 int i;
37912 - struct bfa_fcs_mod_s *mod;
37913 + const struct bfa_fcs_mod_s *mod;
37914
37915 fcs->bfa = bfa;
37916 fcs->bfad = bfad;
37917 @@ -93,7 +93,7 @@ void
37918 bfa_fcs_init(struct bfa_fcs_s *fcs)
37919 {
37920 int i, npbc_vports;
37921 - struct bfa_fcs_mod_s *mod;
37922 + const struct bfa_fcs_mod_s *mod;
37923 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
37924
37925 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
37926 @@ -140,7 +140,7 @@ bfa_fcs_driver_info_init(struct bfa_fcs_
37927 void
37928 bfa_fcs_exit(struct bfa_fcs_s *fcs)
37929 {
37930 - struct bfa_fcs_mod_s *mod;
37931 + const struct bfa_fcs_mod_s *mod;
37932 int nmods, i;
37933
37934 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
37935 diff -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
37936 --- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-19 00:06:34.000000000 -0400
37937 +++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-22 19:36:32.000000000 -0400
37938 @@ -1559,6 +1559,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struc
37939 u16 len, count;
37940 u16 templen;
37941
37942 + pax_track_stack();
37943 +
37944 /*
37945 * get hba attributes
37946 */
37947 @@ -1836,6 +1838,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(
37948 u8 count = 0;
37949 u16 templen;
37950
37951 + pax_track_stack();
37952 +
37953 /*
37954 * get port attributes
37955 */
37956 diff -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
37957 --- linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-19 00:06:34.000000000 -0400
37958 +++ linux-2.6.39.1/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-22 19:36:32.000000000 -0400
37959 @@ -1844,6 +1844,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fc
37960 struct fc_rpsc_speed_info_s speeds;
37961 struct bfa_port_attr_s pport_attr;
37962
37963 + pax_track_stack();
37964 +
37965 bfa_trc(port->fcs, rx_fchs->s_id);
37966 bfa_trc(port->fcs, rx_fchs->d_id);
37967
37968 diff -urNp linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h
37969 --- linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h 2011-05-19 00:06:34.000000000 -0400
37970 +++ linux-2.6.39.1/drivers/scsi/bfa/bfa_modules.h 2011-05-22 19:36:32.000000000 -0400
37971 @@ -68,8 +68,8 @@ enum {
37972 static void bfa_ ## __mod ## _stop(struct bfa_s *bfa); \
37973 static void bfa_ ## __mod ## _iocdisable(struct bfa_s *bfa); \
37974 \
37975 - extern struct bfa_module_s hal_mod_ ## __mod; \
37976 - struct bfa_module_s hal_mod_ ## __mod = { \
37977 + extern const struct bfa_module_s hal_mod_ ## __mod; \
37978 + const struct bfa_module_s hal_mod_ ## __mod = { \
37979 bfa_ ## __mod ## _meminfo, \
37980 bfa_ ## __mod ## _attach, \
37981 bfa_ ## __mod ## _detach, \
37982 @@ -116,12 +116,12 @@ struct bfa_s {
37983 };
37984
37985 extern bfa_boolean_t bfa_auto_recover;
37986 -extern struct bfa_module_s hal_mod_sgpg;
37987 -extern struct bfa_module_s hal_mod_fcport;
37988 -extern struct bfa_module_s hal_mod_fcxp;
37989 -extern struct bfa_module_s hal_mod_lps;
37990 -extern struct bfa_module_s hal_mod_uf;
37991 -extern struct bfa_module_s hal_mod_rport;
37992 -extern struct bfa_module_s hal_mod_fcpim;
37993 +extern const struct bfa_module_s hal_mod_sgpg;
37994 +extern const struct bfa_module_s hal_mod_fcport;
37995 +extern const struct bfa_module_s hal_mod_fcxp;
37996 +extern const struct bfa_module_s hal_mod_lps;
37997 +extern const struct bfa_module_s hal_mod_uf;
37998 +extern const struct bfa_module_s hal_mod_rport;
37999 +extern const struct bfa_module_s hal_mod_fcpim;
38000
38001 #endif /* __BFA_MODULES_H__ */
38002 diff -urNp linux-2.6.39.1/drivers/scsi/BusLogic.c linux-2.6.39.1/drivers/scsi/BusLogic.c
38003 --- linux-2.6.39.1/drivers/scsi/BusLogic.c 2011-05-19 00:06:34.000000000 -0400
38004 +++ linux-2.6.39.1/drivers/scsi/BusLogic.c 2011-05-22 19:36:32.000000000 -0400
38005 @@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFla
38006 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
38007 *PrototypeHostAdapter)
38008 {
38009 + pax_track_stack();
38010 +
38011 /*
38012 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
38013 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
38014 diff -urNp linux-2.6.39.1/drivers/scsi/dpt_i2o.c linux-2.6.39.1/drivers/scsi/dpt_i2o.c
38015 --- linux-2.6.39.1/drivers/scsi/dpt_i2o.c 2011-05-19 00:06:34.000000000 -0400
38016 +++ linux-2.6.39.1/drivers/scsi/dpt_i2o.c 2011-05-22 19:36:32.000000000 -0400
38017 @@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* p
38018 dma_addr_t addr;
38019 ulong flags = 0;
38020
38021 + pax_track_stack();
38022 +
38023 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
38024 // get user msg size in u32s
38025 if(get_user(size, &user_msg[0])){
38026 @@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
38027 s32 rcode;
38028 dma_addr_t addr;
38029
38030 + pax_track_stack();
38031 +
38032 memset(msg, 0 , sizeof(msg));
38033 len = scsi_bufflen(cmd);
38034 direction = 0x00000000;
38035 diff -urNp linux-2.6.39.1/drivers/scsi/eata.c linux-2.6.39.1/drivers/scsi/eata.c
38036 --- linux-2.6.39.1/drivers/scsi/eata.c 2011-05-19 00:06:34.000000000 -0400
38037 +++ linux-2.6.39.1/drivers/scsi/eata.c 2011-05-22 19:36:32.000000000 -0400
38038 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
38039 struct hostdata *ha;
38040 char name[16];
38041
38042 + pax_track_stack();
38043 +
38044 sprintf(name, "%s%d", driver_name, j);
38045
38046 if (!request_region(port_base, REGION_SIZE, driver_name)) {
38047 diff -urNp linux-2.6.39.1/drivers/scsi/esp_scsi.c linux-2.6.39.1/drivers/scsi/esp_scsi.c
38048 --- linux-2.6.39.1/drivers/scsi/esp_scsi.c 2011-05-19 00:06:34.000000000 -0400
38049 +++ linux-2.6.39.1/drivers/scsi/esp_scsi.c 2011-05-22 19:36:32.000000000 -0400
38050 @@ -2680,7 +2680,7 @@ static void esp_set_width(struct scsi_ta
38051 tp->flags |= ESP_TGT_CHECK_NEGO;
38052 }
38053
38054 -static struct spi_function_template esp_transport_ops = {
38055 +static const struct spi_function_template esp_transport_ops = {
38056 .set_offset = esp_set_offset,
38057 .show_offset = 1,
38058 .set_period = esp_set_period,
38059 diff -urNp linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c
38060 --- linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c 2011-05-19 00:06:34.000000000 -0400
38061 +++ linux-2.6.39.1/drivers/scsi/fcoe/fcoe.c 2011-05-22 19:36:32.000000000 -0400
38062 @@ -138,7 +138,7 @@ static int fcoe_vport_disable(struct fc_
38063 static void fcoe_set_vport_symbolic_name(struct fc_vport *);
38064 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
38065
38066 -static struct libfc_function_template fcoe_libfc_fcn_templ = {
38067 +static const struct libfc_function_template fcoe_libfc_fcn_templ = {
38068 .frame_send = fcoe_xmit,
38069 .ddp_setup = fcoe_ddp_setup,
38070 .ddp_done = fcoe_ddp_done,
38071 diff -urNp linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c
38072 --- linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-19 00:06:34.000000000 -0400
38073 +++ linux-2.6.39.1/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-22 19:36:32.000000000 -0400
38074 @@ -1912,7 +1912,7 @@ static void fcoe_ctlr_vn_rport_callback(
38075 mutex_unlock(&fip->ctlr_mutex);
38076 }
38077
38078 -static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38079 +static const struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38080 .event_callback = fcoe_ctlr_vn_rport_callback,
38081 };
38082
38083 @@ -2458,6 +2458,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe
38084 } buf;
38085 int rc;
38086
38087 + pax_track_stack();
38088 +
38089 fiph = (struct fip_header *)skb->data;
38090 sub = fiph->fip_subcode;
38091
38092 diff -urNp linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c
38093 --- linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c 2011-05-19 00:06:34.000000000 -0400
38094 +++ linux-2.6.39.1/drivers/scsi/fnic/fnic_main.c 2011-05-22 19:36:32.000000000 -0400
38095 @@ -69,7 +69,7 @@ module_param(fnic_log_level, int, S_IRUG
38096 MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
38097
38098
38099 -static struct libfc_function_template fnic_transport_template = {
38100 +static const struct libfc_function_template fnic_transport_template = {
38101 .frame_send = fnic_send,
38102 .lport_set_port_id = fnic_set_port_id,
38103 .fcp_abort_io = fnic_empty_scsi_cleanup,
38104 diff -urNp linux-2.6.39.1/drivers/scsi/gdth.c linux-2.6.39.1/drivers/scsi/gdth.c
38105 --- linux-2.6.39.1/drivers/scsi/gdth.c 2011-05-19 00:06:34.000000000 -0400
38106 +++ linux-2.6.39.1/drivers/scsi/gdth.c 2011-05-22 19:36:32.000000000 -0400
38107 @@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
38108 unsigned long flags;
38109 gdth_ha_str *ha;
38110
38111 + pax_track_stack();
38112 +
38113 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
38114 return -EFAULT;
38115 ha = gdth_find_ha(ldrv.ionode);
38116 @@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg
38117 gdth_ha_str *ha;
38118 int rval;
38119
38120 + pax_track_stack();
38121 +
38122 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
38123 res.number >= MAX_HDRIVES)
38124 return -EFAULT;
38125 @@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg,
38126 gdth_ha_str *ha;
38127 int rval;
38128
38129 + pax_track_stack();
38130 +
38131 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
38132 return -EFAULT;
38133 ha = gdth_find_ha(gen.ionode);
38134 @@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
38135 int i;
38136 gdth_cmd_str gdtcmd;
38137 char cmnd[MAX_COMMAND_SIZE];
38138 +
38139 + pax_track_stack();
38140 +
38141 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
38142
38143 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
38144 diff -urNp linux-2.6.39.1/drivers/scsi/gdth_proc.c linux-2.6.39.1/drivers/scsi/gdth_proc.c
38145 --- linux-2.6.39.1/drivers/scsi/gdth_proc.c 2011-05-19 00:06:34.000000000 -0400
38146 +++ linux-2.6.39.1/drivers/scsi/gdth_proc.c 2011-05-22 19:36:32.000000000 -0400
38147 @@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi
38148 u64 paddr;
38149
38150 char cmnd[MAX_COMMAND_SIZE];
38151 +
38152 + pax_track_stack();
38153 +
38154 memset(cmnd, 0xff, 12);
38155 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
38156
38157 @@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,ch
38158 gdth_hget_str *phg;
38159 char cmnd[MAX_COMMAND_SIZE];
38160
38161 + pax_track_stack();
38162 +
38163 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
38164 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
38165 if (!gdtcmd || !estr)
38166 diff -urNp linux-2.6.39.1/drivers/scsi/hosts.c linux-2.6.39.1/drivers/scsi/hosts.c
38167 --- linux-2.6.39.1/drivers/scsi/hosts.c 2011-05-19 00:06:34.000000000 -0400
38168 +++ linux-2.6.39.1/drivers/scsi/hosts.c 2011-05-22 19:36:32.000000000 -0400
38169 @@ -42,7 +42,7 @@
38170 #include "scsi_logging.h"
38171
38172
38173 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
38174 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
38175
38176
38177 static void scsi_host_cls_release(struct device *dev)
38178 @@ -354,7 +354,7 @@ struct Scsi_Host *scsi_host_alloc(struct
38179 * subtract one because we increment first then return, but we need to
38180 * know what the next host number was before increment
38181 */
38182 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38183 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38184 shost->dma_channel = 0xff;
38185
38186 /* These three are default values which can be overridden */
38187 diff -urNp linux-2.6.39.1/drivers/scsi/hpsa.h linux-2.6.39.1/drivers/scsi/hpsa.h
38188 --- linux-2.6.39.1/drivers/scsi/hpsa.h 2011-05-19 00:06:34.000000000 -0400
38189 +++ linux-2.6.39.1/drivers/scsi/hpsa.h 2011-05-22 19:36:32.000000000 -0400
38190 @@ -347,7 +347,7 @@ static struct access_method SA5_access =
38191 SA5_completed,
38192 };
38193
38194 -static struct access_method SA5_performant_access = {
38195 +static const struct access_method SA5_performant_access = {
38196 SA5_submit_command,
38197 SA5_performant_intr_mask,
38198 SA5_fifo_full,
38199 diff -urNp linux-2.6.39.1/drivers/scsi/hptiop.c linux-2.6.39.1/drivers/scsi/hptiop.c
38200 --- linux-2.6.39.1/drivers/scsi/hptiop.c 2011-05-19 00:06:34.000000000 -0400
38201 +++ linux-2.6.39.1/drivers/scsi/hptiop.c 2011-05-22 19:36:32.000000000 -0400
38202 @@ -1226,7 +1226,7 @@ static void hptiop_remove(struct pci_dev
38203 scsi_host_put(host);
38204 }
38205
38206 -static struct hptiop_adapter_ops hptiop_itl_ops = {
38207 +static const struct hptiop_adapter_ops hptiop_itl_ops = {
38208 .iop_wait_ready = iop_wait_ready_itl,
38209 .internal_memalloc = NULL,
38210 .internal_memfree = NULL,
38211 @@ -1241,7 +1241,7 @@ static struct hptiop_adapter_ops hptiop_
38212 .post_req = hptiop_post_req_itl,
38213 };
38214
38215 -static struct hptiop_adapter_ops hptiop_mv_ops = {
38216 +static const struct hptiop_adapter_ops hptiop_mv_ops = {
38217 .iop_wait_ready = iop_wait_ready_mv,
38218 .internal_memalloc = hptiop_internal_memalloc_mv,
38219 .internal_memfree = hptiop_internal_memfree_mv,
38220 diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c
38221 --- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-19 00:06:34.000000000 -0400
38222 +++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-22 19:36:32.000000000 -0400
38223 @@ -4881,7 +4881,7 @@ static struct vio_device_id ibmvfc_devic
38224 };
38225 MODULE_DEVICE_TABLE(vio, ibmvfc_device_table);
38226
38227 -static struct dev_pm_ops ibmvfc_pm_ops = {
38228 +static const struct dev_pm_ops ibmvfc_pm_ops = {
38229 .resume = ibmvfc_resume
38230 };
38231
38232 diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c
38233 --- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-19 00:06:34.000000000 -0400
38234 +++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-22 19:36:32.000000000 -0400
38235 @@ -104,7 +104,7 @@ static struct scsi_transport_template *i
38236
38237 #define IBMVSCSI_VERSION "1.5.9"
38238
38239 -static struct ibmvscsi_ops *ibmvscsi_ops;
38240 +static const struct ibmvscsi_ops *ibmvscsi_ops;
38241
38242 MODULE_DESCRIPTION("IBM Virtual SCSI");
38243 MODULE_AUTHOR("Dave Boutcher");
38244 @@ -2059,7 +2059,7 @@ static struct vio_device_id ibmvscsi_dev
38245 };
38246 MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
38247
38248 -static struct dev_pm_ops ibmvscsi_pm_ops = {
38249 +static const struct dev_pm_ops ibmvscsi_pm_ops = {
38250 .resume = ibmvscsi_resume
38251 };
38252
38253 @@ -2075,7 +2075,7 @@ static struct vio_driver ibmvscsi_driver
38254 }
38255 };
38256
38257 -static struct srp_function_template ibmvscsi_transport_functions = {
38258 +static const struct srp_function_template ibmvscsi_transport_functions = {
38259 };
38260
38261 int __init ibmvscsi_module_init(void)
38262 diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h
38263 --- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-19 00:06:34.000000000 -0400
38264 +++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-22 19:36:32.000000000 -0400
38265 @@ -127,7 +127,7 @@ struct ibmvscsi_ops {
38266 int (*resume) (struct ibmvscsi_host_data *hostdata);
38267 };
38268
38269 -extern struct ibmvscsi_ops iseriesvscsi_ops;
38270 -extern struct ibmvscsi_ops rpavscsi_ops;
38271 +extern const struct ibmvscsi_ops iseriesvscsi_ops;
38272 +extern const struct ibmvscsi_ops rpavscsi_ops;
38273
38274 #endif /* IBMVSCSI_H */
38275 diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c
38276 --- linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-19 00:06:34.000000000 -0400
38277 +++ linux-2.6.39.1/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-22 19:36:32.000000000 -0400
38278 @@ -951,7 +951,7 @@ static int get_system_info(void)
38279 return 0;
38280 }
38281
38282 -static struct srp_function_template ibmvstgt_transport_functions = {
38283 +static const struct srp_function_template ibmvstgt_transport_functions = {
38284 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
38285 .it_nexus_response = ibmvstgt_it_nexus_response,
38286 };
38287 diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c
38288 --- linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38289 +++ linux-2.6.39.1/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38290 @@ -163,7 +163,7 @@ static int iseriesvscsi_resume(struct ib
38291 return 0;
38292 }
38293
38294 -struct ibmvscsi_ops iseriesvscsi_ops = {
38295 +const struct ibmvscsi_ops iseriesvscsi_ops = {
38296 .init_crq_queue = iseriesvscsi_init_crq_queue,
38297 .release_crq_queue = iseriesvscsi_release_crq_queue,
38298 .reset_crq_queue = iseriesvscsi_reset_crq_queue,
38299 diff -urNp linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c
38300 --- linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38301 +++ linux-2.6.39.1/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38302 @@ -358,7 +358,7 @@ static int rpavscsi_resume(struct ibmvsc
38303 return 0;
38304 }
38305
38306 -struct ibmvscsi_ops rpavscsi_ops = {
38307 +const struct ibmvscsi_ops rpavscsi_ops = {
38308 .init_crq_queue = rpavscsi_init_crq_queue,
38309 .release_crq_queue = rpavscsi_release_crq_queue,
38310 .reset_crq_queue = rpavscsi_reset_crq_queue,
38311 diff -urNp linux-2.6.39.1/drivers/scsi/ipr.c linux-2.6.39.1/drivers/scsi/ipr.c
38312 --- linux-2.6.39.1/drivers/scsi/ipr.c 2011-05-19 00:06:34.000000000 -0400
38313 +++ linux-2.6.39.1/drivers/scsi/ipr.c 2011-05-22 19:36:32.000000000 -0400
38314 @@ -6210,7 +6210,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
38315 return true;
38316 }
38317
38318 -static struct ata_port_operations ipr_sata_ops = {
38319 +static const struct ata_port_operations ipr_sata_ops = {
38320 .phy_reset = ipr_ata_phy_reset,
38321 .hardreset = ipr_sata_reset,
38322 .post_internal_cmd = ipr_ata_post_internal,
38323 diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c
38324 --- linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c 2011-05-19 00:06:34.000000000 -0400
38325 +++ linux-2.6.39.1/drivers/scsi/libfc/fc_exch.c 2011-05-22 19:36:32.000000000 -0400
38326 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
38327 * all together if not used XXX
38328 */
38329 struct {
38330 - atomic_t no_free_exch;
38331 - atomic_t no_free_exch_xid;
38332 - atomic_t xid_not_found;
38333 - atomic_t xid_busy;
38334 - atomic_t seq_not_found;
38335 - atomic_t non_bls_resp;
38336 + atomic_unchecked_t no_free_exch;
38337 + atomic_unchecked_t no_free_exch_xid;
38338 + atomic_unchecked_t xid_not_found;
38339 + atomic_unchecked_t xid_busy;
38340 + atomic_unchecked_t seq_not_found;
38341 + atomic_unchecked_t non_bls_resp;
38342 } stats;
38343 };
38344
38345 @@ -700,7 +700,7 @@ static struct fc_exch *fc_exch_em_alloc(
38346 /* allocate memory for exchange */
38347 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38348 if (!ep) {
38349 - atomic_inc(&mp->stats.no_free_exch);
38350 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38351 goto out;
38352 }
38353 memset(ep, 0, sizeof(*ep));
38354 @@ -761,7 +761,7 @@ out:
38355 return ep;
38356 err:
38357 spin_unlock_bh(&pool->lock);
38358 - atomic_inc(&mp->stats.no_free_exch_xid);
38359 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38360 mempool_free(ep, mp->ep_pool);
38361 return NULL;
38362 }
38363 @@ -906,7 +906,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38364 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38365 ep = fc_exch_find(mp, xid);
38366 if (!ep) {
38367 - atomic_inc(&mp->stats.xid_not_found);
38368 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38369 reject = FC_RJT_OX_ID;
38370 goto out;
38371 }
38372 @@ -936,7 +936,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38373 ep = fc_exch_find(mp, xid);
38374 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38375 if (ep) {
38376 - atomic_inc(&mp->stats.xid_busy);
38377 + atomic_inc_unchecked(&mp->stats.xid_busy);
38378 reject = FC_RJT_RX_ID;
38379 goto rel;
38380 }
38381 @@ -947,7 +947,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38382 }
38383 xid = ep->xid; /* get our XID */
38384 } else if (!ep) {
38385 - atomic_inc(&mp->stats.xid_not_found);
38386 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38387 reject = FC_RJT_RX_ID; /* XID not found */
38388 goto out;
38389 }
38390 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38391 } else {
38392 sp = &ep->seq;
38393 if (sp->id != fh->fh_seq_id) {
38394 - atomic_inc(&mp->stats.seq_not_found);
38395 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38396 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
38397 goto rel;
38398 }
38399 @@ -1392,22 +1392,22 @@ static void fc_exch_recv_seq_resp(struct
38400
38401 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38402 if (!ep) {
38403 - atomic_inc(&mp->stats.xid_not_found);
38404 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38405 goto out;
38406 }
38407 if (ep->esb_stat & ESB_ST_COMPLETE) {
38408 - atomic_inc(&mp->stats.xid_not_found);
38409 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38410 goto rel;
38411 }
38412 if (ep->rxid == FC_XID_UNKNOWN)
38413 ep->rxid = ntohs(fh->fh_rx_id);
38414 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38415 - atomic_inc(&mp->stats.xid_not_found);
38416 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38417 goto rel;
38418 }
38419 if (ep->did != ntoh24(fh->fh_s_id) &&
38420 ep->did != FC_FID_FLOGI) {
38421 - atomic_inc(&mp->stats.xid_not_found);
38422 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38423 goto rel;
38424 }
38425 sof = fr_sof(fp);
38426 @@ -1416,7 +1416,7 @@ static void fc_exch_recv_seq_resp(struct
38427 sp->ssb_stat |= SSB_ST_RESP;
38428 sp->id = fh->fh_seq_id;
38429 } else if (sp->id != fh->fh_seq_id) {
38430 - atomic_inc(&mp->stats.seq_not_found);
38431 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38432 goto rel;
38433 }
38434
38435 @@ -1479,9 +1479,9 @@ static void fc_exch_recv_resp(struct fc_
38436 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38437
38438 if (!sp)
38439 - atomic_inc(&mp->stats.xid_not_found);
38440 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38441 else
38442 - atomic_inc(&mp->stats.non_bls_resp);
38443 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38444
38445 fc_frame_free(fp);
38446 }
38447 diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c
38448 --- linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c 2011-05-19 00:06:34.000000000 -0400
38449 +++ linux-2.6.39.1/drivers/scsi/libfc/fc_lport.c 2011-05-22 19:36:32.000000000 -0400
38450 @@ -1299,7 +1299,7 @@ static void fc_lport_enter_ns(struct fc_
38451 fc_lport_error(lport, fp);
38452 }
38453
38454 -static struct fc_rport_operations fc_lport_rport_ops = {
38455 +static const struct fc_rport_operations fc_lport_rport_ops = {
38456 .event_callback = fc_lport_rport_callback,
38457 };
38458
38459 diff -urNp linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c
38460 --- linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c 2011-05-19 00:06:34.000000000 -0400
38461 +++ linux-2.6.39.1/drivers/scsi/libfc/fc_rport.c 2011-05-22 19:36:32.000000000 -0400
38462 @@ -256,7 +256,7 @@ static void fc_rport_work(struct work_st
38463 struct fc_rport_libfc_priv *rpriv;
38464 enum fc_rport_event event;
38465 struct fc_lport *lport = rdata->local_port;
38466 - struct fc_rport_operations *rport_ops;
38467 + const struct fc_rport_operations *rport_ops;
38468 struct fc_rport_identifiers ids;
38469 struct fc_rport *rport;
38470 struct fc4_prov *prov;
38471 diff -urNp linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c
38472 --- linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c 2011-05-19 00:06:34.000000000 -0400
38473 +++ linux-2.6.39.1/drivers/scsi/libsas/sas_ata.c 2011-05-22 19:36:32.000000000 -0400
38474 @@ -307,14 +307,14 @@ static void sas_ata_post_internal(struct
38475 }
38476 }
38477
38478 -static struct ata_port_operations sas_sata_ops = {
38479 +static const struct ata_port_operations sas_sata_ops = {
38480 .prereset = ata_std_prereset,
38481 .softreset = NULL,
38482 .hardreset = sas_ata_hard_reset,
38483 .postreset = ata_std_postreset,
38484 .error_handler = ata_std_error_handler,
38485 .post_internal_cmd = sas_ata_post_internal,
38486 - .qc_defer = ata_std_qc_defer,
38487 + .qc_defer = ata_std_qc_defer,
38488 .qc_prep = ata_noop_qc_prep,
38489 .qc_issue = sas_ata_qc_issue,
38490 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38491 diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c
38492 --- linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-19 00:06:34.000000000 -0400
38493 +++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-22 19:36:32.000000000 -0400
38494 @@ -104,7 +104,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_
38495
38496 #include <linux/debugfs.h>
38497
38498 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38499 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38500 static unsigned long lpfc_debugfs_start_time = 0L;
38501
38502 /* iDiag */
38503 @@ -141,7 +141,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
38504 lpfc_debugfs_enable = 0;
38505
38506 len = 0;
38507 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38508 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38509 (lpfc_debugfs_max_disc_trc - 1);
38510 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38511 dtp = vport->disc_trc + i;
38512 @@ -202,7 +202,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
38513 lpfc_debugfs_enable = 0;
38514
38515 len = 0;
38516 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38517 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38518 (lpfc_debugfs_max_slow_ring_trc - 1);
38519 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38520 dtp = phba->slow_ring_trc + i;
38521 @@ -380,6 +380,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
38522 uint32_t *ptr;
38523 char buffer[1024];
38524
38525 + pax_track_stack();
38526 +
38527 off = 0;
38528 spin_lock_irq(&phba->hbalock);
38529
38530 @@ -617,14 +619,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
38531 !vport || !vport->disc_trc)
38532 return;
38533
38534 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38535 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38536 (lpfc_debugfs_max_disc_trc - 1);
38537 dtp = vport->disc_trc + index;
38538 dtp->fmt = fmt;
38539 dtp->data1 = data1;
38540 dtp->data2 = data2;
38541 dtp->data3 = data3;
38542 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38543 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38544 dtp->jif = jiffies;
38545 #endif
38546 return;
38547 @@ -655,14 +657,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
38548 !phba || !phba->slow_ring_trc)
38549 return;
38550
38551 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38552 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38553 (lpfc_debugfs_max_slow_ring_trc - 1);
38554 dtp = phba->slow_ring_trc + index;
38555 dtp->fmt = fmt;
38556 dtp->data1 = data1;
38557 dtp->data2 = data2;
38558 dtp->data3 = data3;
38559 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38560 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38561 dtp->jif = jiffies;
38562 #endif
38563 return;
38564 @@ -2145,7 +2147,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38565 "slow_ring buffer\n");
38566 goto debug_failed;
38567 }
38568 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38569 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38570 memset(phba->slow_ring_trc, 0,
38571 (sizeof(struct lpfc_debugfs_trc) *
38572 lpfc_debugfs_max_slow_ring_trc));
38573 @@ -2191,7 +2193,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38574 "buffer\n");
38575 goto debug_failed;
38576 }
38577 - atomic_set(&vport->disc_trc_cnt, 0);
38578 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38579
38580 snprintf(name, sizeof(name), "discovery_trace");
38581 vport->debug_disc_trc =
38582 diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h
38583 --- linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h 2011-05-19 00:06:34.000000000 -0400
38584 +++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc.h 2011-05-22 19:36:32.000000000 -0400
38585 @@ -419,7 +419,7 @@ struct lpfc_vport {
38586 struct dentry *debug_nodelist;
38587 struct dentry *vport_debugfs_root;
38588 struct lpfc_debugfs_trc *disc_trc;
38589 - atomic_t disc_trc_cnt;
38590 + atomic_unchecked_t disc_trc_cnt;
38591 #endif
38592 uint8_t stat_data_enabled;
38593 uint8_t stat_data_blocked;
38594 @@ -785,8 +785,8 @@ struct lpfc_hba {
38595 struct timer_list fabric_block_timer;
38596 unsigned long bit_flags;
38597 #define FABRIC_COMANDS_BLOCKED 0
38598 - atomic_t num_rsrc_err;
38599 - atomic_t num_cmd_success;
38600 + atomic_unchecked_t num_rsrc_err;
38601 + atomic_unchecked_t num_cmd_success;
38602 unsigned long last_rsrc_error_time;
38603 unsigned long last_ramp_down_time;
38604 unsigned long last_ramp_up_time;
38605 @@ -800,7 +800,7 @@ struct lpfc_hba {
38606 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
38607 struct dentry *debug_slow_ring_trc;
38608 struct lpfc_debugfs_trc *slow_ring_trc;
38609 - atomic_t slow_ring_trc_cnt;
38610 + atomic_unchecked_t slow_ring_trc_cnt;
38611 /* iDiag debugfs sub-directory */
38612 struct dentry *idiag_root;
38613 struct dentry *idiag_pci_cfg;
38614 diff -urNp linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c
38615 --- linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-19 00:06:34.000000000 -0400
38616 +++ linux-2.6.39.1/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-22 19:36:32.000000000 -0400
38617 @@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
38618 uint32_t evt_posted;
38619
38620 spin_lock_irqsave(&phba->hbalock, flags);
38621 - atomic_inc(&phba->num_rsrc_err);
38622 + atomic_inc_unchecked(&phba->num_rsrc_err);
38623 phba->last_rsrc_error_time = jiffies;
38624
38625 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38626 @@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
38627 unsigned long flags;
38628 struct lpfc_hba *phba = vport->phba;
38629 uint32_t evt_posted;
38630 - atomic_inc(&phba->num_cmd_success);
38631 + atomic_inc_unchecked(&phba->num_cmd_success);
38632
38633 if (vport->cfg_lun_queue_depth <= queue_depth)
38634 return;
38635 @@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38636 unsigned long num_rsrc_err, num_cmd_success;
38637 int i;
38638
38639 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38640 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38641 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38642 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38643
38644 vports = lpfc_create_vport_work_array(phba);
38645 if (vports != NULL)
38646 @@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38647 }
38648 }
38649 lpfc_destroy_vport_work_array(phba, vports);
38650 - atomic_set(&phba->num_rsrc_err, 0);
38651 - atomic_set(&phba->num_cmd_success, 0);
38652 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38653 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38654 }
38655
38656 /**
38657 @@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
38658 }
38659 }
38660 lpfc_destroy_vport_work_array(phba, vports);
38661 - atomic_set(&phba->num_rsrc_err, 0);
38662 - atomic_set(&phba->num_cmd_success, 0);
38663 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38664 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38665 }
38666
38667 /**
38668 diff -urNp linux-2.6.39.1/drivers/scsi/mac_esp.c linux-2.6.39.1/drivers/scsi/mac_esp.c
38669 --- linux-2.6.39.1/drivers/scsi/mac_esp.c 2011-05-19 00:06:34.000000000 -0400
38670 +++ linux-2.6.39.1/drivers/scsi/mac_esp.c 2011-05-22 19:36:32.000000000 -0400
38671 @@ -473,7 +473,7 @@ static irqreturn_t mac_scsi_esp_intr(int
38672 return IRQ_HANDLED;
38673 }
38674
38675 -static struct esp_driver_ops mac_esp_ops = {
38676 +static const struct esp_driver_ops mac_esp_ops = {
38677 .esp_write8 = mac_esp_write8,
38678 .esp_read8 = mac_esp_read8,
38679 .map_single = mac_esp_map_single,
38680 diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c
38681 --- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-19 00:06:34.000000000 -0400
38682 +++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-22 19:36:32.000000000 -0400
38683 @@ -3510,6 +3510,8 @@ megaraid_cmm_register(adapter_t *adapter
38684 int rval;
38685 int i;
38686
38687 + pax_track_stack();
38688 +
38689 // Allocate memory for the base list of scb for management module.
38690 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
38691
38692 diff -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
38693 --- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-19 00:06:34.000000000 -0400
38694 +++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-22 19:36:32.000000000 -0400
38695 @@ -366,7 +366,7 @@ megasas_check_reset_xscale(struct megasa
38696 return 0;
38697 }
38698
38699 -static struct megasas_instance_template megasas_instance_template_xscale = {
38700 +static const struct megasas_instance_template megasas_instance_template_xscale = {
38701
38702 .fire_cmd = megasas_fire_cmd_xscale,
38703 .enable_intr = megasas_enable_intr_xscale,
38704 @@ -497,7 +497,7 @@ megasas_check_reset_ppc(struct megasas_i
38705 {
38706 return 0;
38707 }
38708 -static struct megasas_instance_template megasas_instance_template_ppc = {
38709 +static const struct megasas_instance_template megasas_instance_template_ppc = {
38710
38711 .fire_cmd = megasas_fire_cmd_ppc,
38712 .enable_intr = megasas_enable_intr_ppc,
38713 @@ -623,7 +623,7 @@ megasas_check_reset_skinny(struct megasa
38714 return 0;
38715 }
38716
38717 -static struct megasas_instance_template megasas_instance_template_skinny = {
38718 +static const struct megasas_instance_template megasas_instance_template_skinny = {
38719
38720 .fire_cmd = megasas_fire_cmd_skinny,
38721 .enable_intr = megasas_enable_intr_skinny,
38722 @@ -810,7 +810,7 @@ megasas_check_reset_gen2(struct megasas_
38723 return 0;
38724 }
38725
38726 -static struct megasas_instance_template megasas_instance_template_gen2 = {
38727 +static const struct megasas_instance_template megasas_instance_template_gen2 = {
38728
38729 .fire_cmd = megasas_fire_cmd_gen2,
38730 .enable_intr = megasas_enable_intr_gen2,
38731 @@ -834,7 +834,7 @@ static struct megasas_instance_template
38732 /*
38733 * Template added for TB (Fusion)
38734 */
38735 -extern struct megasas_instance_template megasas_instance_template_fusion;
38736 +extern const struct megasas_instance_template megasas_instance_template_fusion;
38737
38738 /**
38739 * megasas_issue_polled - Issues a polling command
38740 diff -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
38741 --- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-19 00:06:34.000000000 -0400
38742 +++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-22 19:36:32.000000000 -0400
38743 @@ -2236,7 +2236,7 @@ void megasas_fusion_ocr_wq(struct work_s
38744 megasas_reset_fusion(instance->host);
38745 }
38746
38747 -struct megasas_instance_template megasas_instance_template_fusion = {
38748 +const struct megasas_instance_template megasas_instance_template_fusion = {
38749 .fire_cmd = megasas_fire_cmd_fusion,
38750 .enable_intr = megasas_enable_intr_fusion,
38751 .disable_intr = megasas_disable_intr_fusion,
38752 diff -urNp linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h
38753 --- linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h 2011-05-19 00:06:34.000000000 -0400
38754 +++ linux-2.6.39.1/drivers/scsi/megaraid/megaraid_sas.h 2011-05-22 19:36:32.000000000 -0400
38755 @@ -1330,7 +1330,7 @@ struct megasas_instance {
38756 atomic_t fw_outstanding;
38757 atomic_t fw_reset_no_pci_access;
38758
38759 - struct megasas_instance_template *instancet;
38760 + const struct megasas_instance_template *instancet;
38761 struct tasklet_struct isr_tasklet;
38762 struct work_struct work_init;
38763
38764 diff -urNp linux-2.6.39.1/drivers/scsi/ncr53c8xx.c linux-2.6.39.1/drivers/scsi/ncr53c8xx.c
38765 --- linux-2.6.39.1/drivers/scsi/ncr53c8xx.c 2011-05-19 00:06:34.000000000 -0400
38766 +++ linux-2.6.39.1/drivers/scsi/ncr53c8xx.c 2011-05-22 19:36:32.000000000 -0400
38767 @@ -8606,7 +8606,7 @@ static void ncr53c8xx_get_signalling(str
38768 spi_signalling(shost) = type;
38769 }
38770
38771 -static struct spi_function_template ncr53c8xx_transport_functions = {
38772 +static struct spi_function_template ncr53c8xx_transport_functions = {
38773 .set_period = ncr53c8xx_set_period,
38774 .show_period = 1,
38775 .set_offset = ncr53c8xx_set_offset,
38776 diff -urNp linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c
38777 --- linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c 2011-05-19 00:06:34.000000000 -0400
38778 +++ linux-2.6.39.1/drivers/scsi/osd/osd_initiator.c 2011-05-22 19:36:32.000000000 -0400
38779 @@ -97,6 +97,8 @@ static int _osd_get_print_system_info(st
38780 int nelem = ARRAY_SIZE(get_attrs), a = 0;
38781 int ret;
38782
38783 + pax_track_stack();
38784 +
38785 or = osd_start_request(od, GFP_KERNEL);
38786 if (!or)
38787 return -ENOMEM;
38788 diff -urNp linux-2.6.39.1/drivers/scsi/pmcraid.c linux-2.6.39.1/drivers/scsi/pmcraid.c
38789 --- linux-2.6.39.1/drivers/scsi/pmcraid.c 2011-05-19 00:06:34.000000000 -0400
38790 +++ linux-2.6.39.1/drivers/scsi/pmcraid.c 2011-05-22 19:36:32.000000000 -0400
38791 @@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct sc
38792 res->scsi_dev = scsi_dev;
38793 scsi_dev->hostdata = res;
38794 res->change_detected = 0;
38795 - atomic_set(&res->read_failures, 0);
38796 - atomic_set(&res->write_failures, 0);
38797 + atomic_set_unchecked(&res->read_failures, 0);
38798 + atomic_set_unchecked(&res->write_failures, 0);
38799 rc = 0;
38800 }
38801 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38802 @@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct
38803
38804 /* If this was a SCSI read/write command keep count of errors */
38805 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38806 - atomic_inc(&res->read_failures);
38807 + atomic_inc_unchecked(&res->read_failures);
38808 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38809 - atomic_inc(&res->write_failures);
38810 + atomic_inc_unchecked(&res->write_failures);
38811
38812 if (!RES_IS_GSCSI(res->cfg_entry) &&
38813 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38814 @@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
38815 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38816 * hrrq_id assigned here in queuecommand
38817 */
38818 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38819 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38820 pinstance->num_hrrq;
38821 cmd->cmd_done = pmcraid_io_done;
38822
38823 @@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
38824 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38825 * hrrq_id assigned here in queuecommand
38826 */
38827 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38828 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38829 pinstance->num_hrrq;
38830
38831 if (request_size) {
38832 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(stru
38833
38834 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38835 /* add resources only after host is added into system */
38836 - if (!atomic_read(&pinstance->expose_resources))
38837 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38838 return;
38839
38840 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38841 @@ -5329,8 +5329,8 @@ static int __devinit pmcraid_init_instan
38842 init_waitqueue_head(&pinstance->reset_wait_q);
38843
38844 atomic_set(&pinstance->outstanding_cmds, 0);
38845 - atomic_set(&pinstance->last_message_id, 0);
38846 - atomic_set(&pinstance->expose_resources, 0);
38847 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38848 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38849
38850 INIT_LIST_HEAD(&pinstance->free_res_q);
38851 INIT_LIST_HEAD(&pinstance->used_res_q);
38852 @@ -6045,7 +6045,7 @@ static int __devinit pmcraid_probe(
38853 /* Schedule worker thread to handle CCN and take care of adding and
38854 * removing devices to OS
38855 */
38856 - atomic_set(&pinstance->expose_resources, 1);
38857 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38858 schedule_work(&pinstance->worker_q);
38859 return rc;
38860
38861 diff -urNp linux-2.6.39.1/drivers/scsi/pmcraid.h linux-2.6.39.1/drivers/scsi/pmcraid.h
38862 --- linux-2.6.39.1/drivers/scsi/pmcraid.h 2011-05-19 00:06:34.000000000 -0400
38863 +++ linux-2.6.39.1/drivers/scsi/pmcraid.h 2011-05-22 19:36:32.000000000 -0400
38864 @@ -750,7 +750,7 @@ struct pmcraid_instance {
38865 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38866
38867 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38868 - atomic_t last_message_id;
38869 + atomic_unchecked_t last_message_id;
38870
38871 /* configuration table */
38872 struct pmcraid_config_table *cfg_table;
38873 @@ -779,7 +779,7 @@ struct pmcraid_instance {
38874 atomic_t outstanding_cmds;
38875
38876 /* should add/delete resources to mid-layer now ?*/
38877 - atomic_t expose_resources;
38878 + atomic_unchecked_t expose_resources;
38879
38880
38881
38882 @@ -815,8 +815,8 @@ struct pmcraid_resource_entry {
38883 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38884 };
38885 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38886 - atomic_t read_failures; /* count of failed READ commands */
38887 - atomic_t write_failures; /* count of failed WRITE commands */
38888 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38889 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38890
38891 /* To indicate add/delete/modify during CCN */
38892 u8 change_detected;
38893 diff -urNp linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c
38894 --- linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:04:14.000000000 -0400
38895 +++ linux-2.6.39.1/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:32:06.000000000 -0400
38896 @@ -4103,7 +4103,7 @@ static struct pci_driver qla2xxx_pci_dri
38897 .err_handler = &qla2xxx_err_handler,
38898 };
38899
38900 -static struct file_operations apidev_fops = {
38901 +static const struct file_operations apidev_fops = {
38902 .owner = THIS_MODULE,
38903 .llseek = noop_llseek,
38904 };
38905 diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h
38906 --- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h 2011-05-19 00:06:34.000000000 -0400
38907 +++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_def.h 2011-05-22 19:36:32.000000000 -0400
38908 @@ -256,7 +256,7 @@ struct ddb_entry {
38909 atomic_t retry_relogin_timer; /* Min Time between relogins
38910 * (4000 only) */
38911 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
38912 - atomic_t relogin_retry_count; /* Num of times relogin has been
38913 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38914 * retried */
38915
38916 uint16_t port;
38917 diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c
38918 --- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c 2011-05-19 00:06:34.000000000 -0400
38919 +++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_init.c 2011-05-22 19:36:32.000000000 -0400
38920 @@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_
38921 ddb_entry->fw_ddb_index = fw_ddb_index;
38922 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38923 atomic_set(&ddb_entry->relogin_timer, 0);
38924 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38925 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38926 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38927 list_add_tail(&ddb_entry->list, &ha->ddb_list);
38928 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
38929 @@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct s
38930 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
38931 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
38932 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38933 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38934 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38935 atomic_set(&ddb_entry->relogin_timer, 0);
38936 clear_bit(DF_RELOGIN, &ddb_entry->flags);
38937 iscsi_unblock_session(ddb_entry->sess);
38938 diff -urNp linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c
38939 --- linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c 2011-05-19 00:06:34.000000000 -0400
38940 +++ linux-2.6.39.1/drivers/scsi/qla4xxx/ql4_os.c 2011-05-22 19:36:32.000000000 -0400
38941 @@ -802,13 +802,13 @@ static void qla4xxx_timer(struct scsi_ql
38942 ddb_entry->fw_ddb_device_state ==
38943 DDB_DS_SESSION_FAILED) {
38944 /* Reset retry relogin timer */
38945 - atomic_inc(&ddb_entry->relogin_retry_count);
38946 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38947 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
38948 " timed out-retrying"
38949 " relogin (%d)\n",
38950 ha->host_no,
38951 ddb_entry->fw_ddb_index,
38952 - atomic_read(&ddb_entry->
38953 + atomic_read_unchecked(&ddb_entry->
38954 relogin_retry_count))
38955 );
38956 start_dpc++;
38957 diff -urNp linux-2.6.39.1/drivers/scsi/scsi.c linux-2.6.39.1/drivers/scsi/scsi.c
38958 --- linux-2.6.39.1/drivers/scsi/scsi.c 2011-05-19 00:06:34.000000000 -0400
38959 +++ linux-2.6.39.1/drivers/scsi/scsi.c 2011-05-22 19:36:32.000000000 -0400
38960 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
38961 unsigned long timeout;
38962 int rtn = 0;
38963
38964 - atomic_inc(&cmd->device->iorequest_cnt);
38965 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38966
38967 /* check if the device is still usable */
38968 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38969 diff -urNp linux-2.6.39.1/drivers/scsi/scsi_debug.c linux-2.6.39.1/drivers/scsi/scsi_debug.c
38970 --- linux-2.6.39.1/drivers/scsi/scsi_debug.c 2011-05-19 00:06:34.000000000 -0400
38971 +++ linux-2.6.39.1/drivers/scsi/scsi_debug.c 2011-05-22 19:36:32.000000000 -0400
38972 @@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_
38973 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
38974 unsigned char *cmd = (unsigned char *)scp->cmnd;
38975
38976 + pax_track_stack();
38977 +
38978 if ((errsts = check_readiness(scp, 1, devip)))
38979 return errsts;
38980 memset(arr, 0, sizeof(arr));
38981 @@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cm
38982 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
38983 unsigned char *cmd = (unsigned char *)scp->cmnd;
38984
38985 + pax_track_stack();
38986 +
38987 if ((errsts = check_readiness(scp, 1, devip)))
38988 return errsts;
38989 memset(arr, 0, sizeof(arr));
38990 diff -urNp linux-2.6.39.1/drivers/scsi/scsi_lib.c linux-2.6.39.1/drivers/scsi/scsi_lib.c
38991 --- linux-2.6.39.1/drivers/scsi/scsi_lib.c 2011-05-19 00:06:34.000000000 -0400
38992 +++ linux-2.6.39.1/drivers/scsi/scsi_lib.c 2011-05-22 19:36:32.000000000 -0400
38993 @@ -1410,7 +1410,7 @@ static void scsi_kill_request(struct req
38994 shost = sdev->host;
38995 scsi_init_cmd_errh(cmd);
38996 cmd->result = DID_NO_CONNECT << 16;
38997 - atomic_inc(&cmd->device->iorequest_cnt);
38998 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38999
39000 /*
39001 * SCSI request completion path will do scsi_device_unbusy(),
39002 @@ -1436,9 +1436,9 @@ static void scsi_softirq_done(struct req
39003
39004 INIT_LIST_HEAD(&cmd->eh_entry);
39005
39006 - atomic_inc(&cmd->device->iodone_cnt);
39007 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
39008 if (cmd->result)
39009 - atomic_inc(&cmd->device->ioerr_cnt);
39010 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39011
39012 disposition = scsi_decide_disposition(cmd);
39013 if (disposition != SUCCESS &&
39014 diff -urNp linux-2.6.39.1/drivers/scsi/scsi_sysfs.c linux-2.6.39.1/drivers/scsi/scsi_sysfs.c
39015 --- linux-2.6.39.1/drivers/scsi/scsi_sysfs.c 2011-05-19 00:06:34.000000000 -0400
39016 +++ linux-2.6.39.1/drivers/scsi/scsi_sysfs.c 2011-05-22 19:36:32.000000000 -0400
39017 @@ -621,7 +621,7 @@ show_iostat_##field(struct device *dev,
39018 char *buf) \
39019 { \
39020 struct scsi_device *sdev = to_scsi_device(dev); \
39021 - unsigned long long count = atomic_read(&sdev->field); \
39022 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39023 return snprintf(buf, 20, "0x%llx\n", count); \
39024 } \
39025 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39026 diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c
39027 --- linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c 2011-05-19 00:06:34.000000000 -0400
39028 +++ linux-2.6.39.1/drivers/scsi/scsi_transport_fc.c 2011-05-22 19:36:32.000000000 -0400
39029 @@ -485,7 +485,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_
39030 * Netlink Infrastructure
39031 */
39032
39033 -static atomic_t fc_event_seq;
39034 +static atomic_unchecked_t fc_event_seq;
39035
39036 /**
39037 * fc_get_event_number - Obtain the next sequential FC event number
39038 @@ -498,7 +498,7 @@ static atomic_t fc_event_seq;
39039 u32
39040 fc_get_event_number(void)
39041 {
39042 - return atomic_add_return(1, &fc_event_seq);
39043 + return atomic_add_return_unchecked(1, &fc_event_seq);
39044 }
39045 EXPORT_SYMBOL(fc_get_event_number);
39046
39047 @@ -646,7 +646,7 @@ static __init int fc_transport_init(void
39048 {
39049 int error;
39050
39051 - atomic_set(&fc_event_seq, 0);
39052 + atomic_set_unchecked(&fc_event_seq, 0);
39053
39054 error = transport_class_register(&fc_host_class);
39055 if (error)
39056 @@ -836,7 +836,7 @@ static int fc_str_to_dev_loss(const char
39057 char *cp;
39058
39059 *val = simple_strtoul(buf, &cp, 0);
39060 - if ((*cp && (*cp != '\n')) || (*val < 0))
39061 + if (*cp && (*cp != '\n'))
39062 return -EINVAL;
39063 /*
39064 * Check for overflow; dev_loss_tmo is u32
39065 diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c
39066 --- linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c 2011-05-19 00:06:34.000000000 -0400
39067 +++ linux-2.6.39.1/drivers/scsi/scsi_transport_iscsi.c 2011-05-22 19:36:32.000000000 -0400
39068 @@ -83,7 +83,7 @@ struct iscsi_internal {
39069 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
39070 };
39071
39072 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39073 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39074 static struct workqueue_struct *iscsi_eh_timer_workq;
39075
39076 /*
39077 @@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_s
39078 int err;
39079
39080 ihost = shost->shost_data;
39081 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39082 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39083
39084 if (id == ISCSI_MAX_TARGET) {
39085 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
39086 @@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(v
39087 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39088 ISCSI_TRANSPORT_VERSION);
39089
39090 - atomic_set(&iscsi_session_nr, 0);
39091 + atomic_set_unchecked(&iscsi_session_nr, 0);
39092
39093 err = class_register(&iscsi_transport_class);
39094 if (err)
39095 diff -urNp linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c
39096 --- linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c 2011-05-19 00:06:34.000000000 -0400
39097 +++ linux-2.6.39.1/drivers/scsi/scsi_transport_srp.c 2011-05-22 19:36:32.000000000 -0400
39098 @@ -33,7 +33,7 @@
39099 #include "scsi_transport_srp_internal.h"
39100
39101 struct srp_host_attrs {
39102 - atomic_t next_port_id;
39103 + atomic_unchecked_t next_port_id;
39104 };
39105 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39106
39107 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
39108 struct Scsi_Host *shost = dev_to_shost(dev);
39109 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39110
39111 - atomic_set(&srp_host->next_port_id, 0);
39112 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39113 return 0;
39114 }
39115
39116 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
39117 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39118 rport->roles = ids->roles;
39119
39120 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39121 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39122 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39123
39124 transport_setup_device(&rport->dev);
39125 diff -urNp linux-2.6.39.1/drivers/scsi/sg.c linux-2.6.39.1/drivers/scsi/sg.c
39126 --- linux-2.6.39.1/drivers/scsi/sg.c 2011-05-19 00:06:34.000000000 -0400
39127 +++ linux-2.6.39.1/drivers/scsi/sg.c 2011-05-22 19:36:32.000000000 -0400
39128 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
39129 const struct file_operations * fops;
39130 };
39131
39132 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
39133 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
39134 {"allow_dio", &adio_fops},
39135 {"debug", &debug_fops},
39136 {"def_reserved_size", &dressz_fops},
39137 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
39138 {
39139 int k, mask;
39140 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
39141 - struct sg_proc_leaf * leaf;
39142 + const struct sg_proc_leaf * leaf;
39143
39144 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
39145 if (!sg_proc_sgp)
39146 diff -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
39147 --- linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-19 00:06:34.000000000 -0400
39148 +++ linux-2.6.39.1/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-22 19:36:32.000000000 -0400
39149 @@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct p
39150 int do_iounmap = 0;
39151 int do_disable_device = 1;
39152
39153 + pax_track_stack();
39154 +
39155 memset(&sym_dev, 0, sizeof(sym_dev));
39156 memset(&nvram, 0, sizeof(nvram));
39157 sym_dev.pdev = pdev;
39158 diff -urNp linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c
39159 --- linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c 2011-05-19 00:06:34.000000000 -0400
39160 +++ linux-2.6.39.1/drivers/scsi/vmw_pvscsi.c 2011-05-22 19:36:32.000000000 -0400
39161 @@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const
39162 dma_addr_t base;
39163 unsigned i;
39164
39165 + pax_track_stack();
39166 +
39167 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
39168 cmd.reqRingNumPages = adapter->req_pages;
39169 cmd.cmpRingNumPages = adapter->cmp_pages;
39170 diff -urNp linux-2.6.39.1/drivers/sh/clk/cpg.c linux-2.6.39.1/drivers/sh/clk/cpg.c
39171 --- linux-2.6.39.1/drivers/sh/clk/cpg.c 2011-06-03 00:04:14.000000000 -0400
39172 +++ linux-2.6.39.1/drivers/sh/clk/cpg.c 2011-06-03 00:32:06.000000000 -0400
39173 @@ -26,7 +26,7 @@ static void sh_clk_mstp32_disable(struct
39174 clk->enable_reg);
39175 }
39176
39177 -static struct clk_ops sh_clk_mstp32_clk_ops = {
39178 +static const struct clk_ops sh_clk_mstp32_clk_ops = {
39179 .enable = sh_clk_mstp32_enable,
39180 .disable = sh_clk_mstp32_disable,
39181 .recalc = followparent_recalc,
39182 @@ -150,7 +150,7 @@ static void sh_clk_div6_disable(struct c
39183 __raw_writel(value, clk->enable_reg);
39184 }
39185
39186 -static struct clk_ops sh_clk_div6_clk_ops = {
39187 +static const struct clk_ops sh_clk_div6_clk_ops = {
39188 .recalc = sh_clk_div6_recalc,
39189 .round_rate = sh_clk_div_round_rate,
39190 .set_rate = sh_clk_div6_set_rate,
39191 @@ -158,7 +158,7 @@ static struct clk_ops sh_clk_div6_clk_op
39192 .disable = sh_clk_div6_disable,
39193 };
39194
39195 -static struct clk_ops sh_clk_div6_reparent_clk_ops = {
39196 +static const struct clk_ops sh_clk_div6_reparent_clk_ops = {
39197 .recalc = sh_clk_div6_recalc,
39198 .round_rate = sh_clk_div_round_rate,
39199 .set_rate = sh_clk_div6_set_rate,
39200 @@ -282,13 +282,13 @@ static void sh_clk_div4_disable(struct c
39201 __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
39202 }
39203
39204 -static struct clk_ops sh_clk_div4_clk_ops = {
39205 +static const struct clk_ops sh_clk_div4_clk_ops = {
39206 .recalc = sh_clk_div4_recalc,
39207 .set_rate = sh_clk_div4_set_rate,
39208 .round_rate = sh_clk_div_round_rate,
39209 };
39210
39211 -static struct clk_ops sh_clk_div4_enable_clk_ops = {
39212 +static const struct clk_ops sh_clk_div4_enable_clk_ops = {
39213 .recalc = sh_clk_div4_recalc,
39214 .set_rate = sh_clk_div4_set_rate,
39215 .round_rate = sh_clk_div_round_rate,
39216 @@ -296,7 +296,7 @@ static struct clk_ops sh_clk_div4_enable
39217 .disable = sh_clk_div4_disable,
39218 };
39219
39220 -static struct clk_ops sh_clk_div4_reparent_clk_ops = {
39221 +static const struct clk_ops sh_clk_div4_reparent_clk_ops = {
39222 .recalc = sh_clk_div4_recalc,
39223 .set_rate = sh_clk_div4_set_rate,
39224 .round_rate = sh_clk_div_round_rate,
39225 diff -urNp linux-2.6.39.1/drivers/spi/dw_spi.h linux-2.6.39.1/drivers/spi/dw_spi.h
39226 --- linux-2.6.39.1/drivers/spi/dw_spi.h 2011-05-19 00:06:34.000000000 -0400
39227 +++ linux-2.6.39.1/drivers/spi/dw_spi.h 2011-05-22 19:36:32.000000000 -0400
39228 @@ -151,7 +151,7 @@ struct dw_spi {
39229 int dma_chan_done;
39230 struct device *dma_dev;
39231 dma_addr_t dma_addr; /* phy address of the Data register */
39232 - struct dw_spi_dma_ops *dma_ops;
39233 + const struct dw_spi_dma_ops *dma_ops;
39234 void *dma_priv; /* platform relate info */
39235 struct pci_dev *dmac;
39236
39237 diff -urNp linux-2.6.39.1/drivers/spi/dw_spi_mid.c linux-2.6.39.1/drivers/spi/dw_spi_mid.c
39238 --- linux-2.6.39.1/drivers/spi/dw_spi_mid.c 2011-05-19 00:06:34.000000000 -0400
39239 +++ linux-2.6.39.1/drivers/spi/dw_spi_mid.c 2011-05-22 19:36:32.000000000 -0400
39240 @@ -180,7 +180,7 @@ static int mid_spi_dma_transfer(struct d
39241 return 0;
39242 }
39243
39244 -static struct dw_spi_dma_ops mid_dma_ops = {
39245 +static const struct dw_spi_dma_ops mid_dma_ops = {
39246 .dma_init = mid_spi_dma_init,
39247 .dma_exit = mid_spi_dma_exit,
39248 .dma_transfer = mid_spi_dma_transfer,
39249 diff -urNp linux-2.6.39.1/drivers/spi/spi.c linux-2.6.39.1/drivers/spi/spi.c
39250 --- linux-2.6.39.1/drivers/spi/spi.c 2011-05-19 00:06:34.000000000 -0400
39251 +++ linux-2.6.39.1/drivers/spi/spi.c 2011-05-22 19:36:32.000000000 -0400
39252 @@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *ma
39253 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39254
39255 /* portable code must never pass more than 32 bytes */
39256 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39257 +#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
39258
39259 static u8 *buf;
39260
39261 diff -urNp linux-2.6.39.1/drivers/ssb/driver_pcicore.c linux-2.6.39.1/drivers/ssb/driver_pcicore.c
39262 --- linux-2.6.39.1/drivers/ssb/driver_pcicore.c 2011-05-19 00:06:34.000000000 -0400
39263 +++ linux-2.6.39.1/drivers/ssb/driver_pcicore.c 2011-05-22 19:36:32.000000000 -0400
39264 @@ -223,7 +223,7 @@ static int ssb_pcicore_write_config(stru
39265 return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
39266 }
39267
39268 -static struct pci_ops ssb_pcicore_pciops = {
39269 +static const struct pci_ops ssb_pcicore_pciops = {
39270 .read = ssb_pcicore_read_config,
39271 .write = ssb_pcicore_write_config,
39272 };
39273 diff -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
39274 --- linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39275 +++ linux-2.6.39.1/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39276 @@ -1391,8 +1391,7 @@ u32 cipher_suites[] = {
39277 WLAN_CIPHER_SUITE_CCMP,
39278 };
39279
39280 -static struct
39281 -cfg80211_ops ar6k_cfg80211_ops = {
39282 +static const struct cfg80211_ops ar6k_cfg80211_ops = {
39283 .change_virtual_intf = ar6k_cfg80211_change_iface,
39284 .add_virtual_intf = ar6k_cfg80211_add_virtual_intf,
39285 .del_virtual_intf = ar6k_cfg80211_del_virtual_intf,
39286 diff -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
39287 --- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-19 00:06:34.000000000 -0400
39288 +++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-22 19:36:32.000000000 -0400
39289 @@ -857,14 +857,14 @@ static void dhd_op_if(dhd_if_t *ifp)
39290 free_netdev(ifp->net);
39291 }
39292 /* Allocate etherdev, including space for private structure */
39293 - ifp->net = alloc_etherdev(sizeof(dhd));
39294 + ifp->net = alloc_etherdev(sizeof(*dhd));
39295 if (!ifp->net) {
39296 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39297 ret = -ENOMEM;
39298 }
39299 if (ret == 0) {
39300 strcpy(ifp->net->name, ifp->name);
39301 - memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
39302 + memcpy(netdev_priv(ifp->net), dhd, sizeof(*dhd));
39303 err = dhd_net_attach(&dhd->pub, ifp->idx);
39304 if (err != 0) {
39305 DHD_ERROR(("%s: dhd_net_attach failed, "
39306 @@ -1500,7 +1500,7 @@ static void dhd_ethtool_get_drvinfo(stru
39307 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
39308 }
39309
39310 -struct ethtool_ops dhd_ethtool_ops = {
39311 +const struct ethtool_ops dhd_ethtool_ops = {
39312 .get_drvinfo = dhd_ethtool_get_drvinfo
39313 };
39314
39315 @@ -1923,7 +1923,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39316 strcpy(nv_path, nvram_path);
39317
39318 /* Allocate etherdev, including space for private structure */
39319 - net = alloc_etherdev(sizeof(dhd));
39320 + net = alloc_etherdev(sizeof(*dhd));
39321 if (!net) {
39322 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39323 goto fail;
39324 @@ -1939,7 +1939,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39325 /*
39326 * Save the dhd_info into the priv
39327 */
39328 - memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39329 + memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39330
39331 /* Set network interface name if it was provided as module parameter */
39332 if (iface_name[0]) {
39333 @@ -2056,7 +2056,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39334 /*
39335 * Save the dhd_info into the priv
39336 */
39337 - memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39338 + memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39339
39340 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
39341 g_bus = bus;
39342 @@ -2206,7 +2206,7 @@ dhd_iovar(dhd_pub_t *pub, int ifidx, cha
39343 return ret;
39344 }
39345
39346 -static struct net_device_ops dhd_ops_pri = {
39347 +static const struct net_device_ops dhd_ops_pri = {
39348 .ndo_open = dhd_open,
39349 .ndo_stop = dhd_stop,
39350 .ndo_get_stats = dhd_get_stats,
39351 diff -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
39352 --- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39353 +++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39354 @@ -2109,7 +2109,7 @@ wl_cfg80211_flush_pmksa(struct wiphy *wi
39355
39356 }
39357
39358 -static struct cfg80211_ops wl_cfg80211_ops = {
39359 +static const struct cfg80211_ops wl_cfg80211_ops = {
39360 .change_virtual_intf = wl_cfg80211_change_iface,
39361 .scan = wl_cfg80211_scan,
39362 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
39363 diff -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
39364 --- linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-19 00:06:34.000000000 -0400
39365 +++ linux-2.6.39.1/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-22 19:36:32.000000000 -0400
39366 @@ -495,7 +495,7 @@ wl_iw_get_range(struct net_device *dev,
39367 list = (wl_u32_list_t *) channels;
39368
39369 dwrq->length = sizeof(struct iw_range);
39370 - memset(range, 0, sizeof(range));
39371 + memset(range, 0, sizeof(*range));
39372
39373 range->min_nwid = range->max_nwid = 0;
39374
39375 diff -urNp linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c
39376 --- linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c 2011-05-19 00:06:34.000000000 -0400
39377 +++ linux-2.6.39.1/drivers/staging/comedi/comedi_fops.c 2011-05-22 19:36:32.000000000 -0400
39378 @@ -1445,7 +1445,7 @@ static void comedi_unmap(struct vm_area_
39379 mutex_unlock(&dev->mutex);
39380 }
39381
39382 -static struct vm_operations_struct comedi_vm_ops = {
39383 +static const struct vm_operations_struct comedi_vm_ops = {
39384 .close = comedi_unmap,
39385 };
39386
39387 diff -urNp linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c
39388 --- linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c 2011-05-19 00:06:34.000000000 -0400
39389 +++ linux-2.6.39.1/drivers/staging/cx25821/cx25821-alsa.c 2011-05-22 19:36:32.000000000 -0400
39390 @@ -586,7 +586,7 @@ static struct page *snd_cx25821_page(str
39391 /*
39392 * operators
39393 */
39394 -static struct snd_pcm_ops snd_cx25821_pcm_ops = {
39395 +static const struct snd_pcm_ops snd_cx25821_pcm_ops = {
39396 .open = snd_cx25821_pcm_open,
39397 .close = snd_cx25821_close,
39398 .ioctl = snd_pcm_lib_ioctl,
39399 diff -urNp linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c
39400 --- linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c 2011-05-19 00:06:34.000000000 -0400
39401 +++ linux-2.6.39.1/drivers/staging/cx25821/cx25821-i2c.c 2011-05-22 19:36:32.000000000 -0400
39402 @@ -282,7 +282,7 @@ static u32 cx25821_functionality(struct
39403 I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
39404 }
39405
39406 -static struct i2c_algorithm cx25821_i2c_algo_template = {
39407 +static const struct i2c_algorithm cx25821_i2c_algo_template = {
39408 .master_xfer = i2c_xfer,
39409 .functionality = cx25821_functionality,
39410 #ifdef NEED_ALGO_CONTROL
39411 diff -urNp linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c
39412 --- linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c 2011-05-19 00:06:34.000000000 -0400
39413 +++ linux-2.6.39.1/drivers/staging/et131x/et1310_tx.c 2011-05-22 19:36:32.000000000 -0400
39414 @@ -635,11 +635,11 @@ inline void et131x_free_send_packet(stru
39415 struct net_device_stats *stats = &etdev->net_stats;
39416
39417 if (tcb->flags & fMP_DEST_BROAD)
39418 - atomic_inc(&etdev->Stats.brdcstxmt);
39419 + atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
39420 else if (tcb->flags & fMP_DEST_MULTI)
39421 - atomic_inc(&etdev->Stats.multixmt);
39422 + atomic_inc_unchecked(&etdev->Stats.multixmt);
39423 else
39424 - atomic_inc(&etdev->Stats.unixmt);
39425 + atomic_inc_unchecked(&etdev->Stats.unixmt);
39426
39427 if (tcb->skb) {
39428 stats->tx_bytes += tcb->skb->len;
39429 diff -urNp linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h
39430 --- linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h 2011-05-19 00:06:34.000000000 -0400
39431 +++ linux-2.6.39.1/drivers/staging/et131x/et131x_adapter.h 2011-05-22 19:36:32.000000000 -0400
39432 @@ -110,11 +110,11 @@ typedef struct _ce_stats_t {
39433 * operations
39434 */
39435 u32 unircv; /* # multicast packets received */
39436 - atomic_t unixmt; /* # multicast packets for Tx */
39437 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
39438 u32 multircv; /* # multicast packets received */
39439 - atomic_t multixmt; /* # multicast packets for Tx */
39440 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
39441 u32 brdcstrcv; /* # broadcast packets received */
39442 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
39443 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
39444 u32 norcvbuf; /* # Rx packets discarded */
39445 u32 noxmtbuf; /* # Tx packets discarded */
39446
39447 diff -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
39448 --- linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-19 00:06:34.000000000 -0400
39449 +++ linux-2.6.39.1/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-22 19:36:32.000000000 -0400
39450 @@ -55,7 +55,7 @@ int numofmsgbuf = 0;
39451 //
39452 // Table of entry-point routines for char device
39453 //
39454 -static struct file_operations ft1000fops =
39455 +static const struct file_operations ft1000fops =
39456 {
39457 .unlocked_ioctl = ft1000_ioctl,
39458 .poll = ft1000_poll_dev,
39459 diff -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
39460 --- linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-19 00:06:34.000000000 -0400
39461 +++ linux-2.6.39.1/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-22 19:36:32.000000000 -0400
39462 @@ -221,7 +221,7 @@ module_param(rio_poll, int, 0);
39463 module_param(rio_debug, int, 0644);
39464 module_param(rio_irqmask, long, 0);
39465
39466 -static struct real_driver rio_real_driver = {
39467 +static const struct real_driver rio_real_driver = {
39468 rio_disable_tx_interrupts,
39469 rio_enable_tx_interrupts,
39470 rio_disable_rx_interrupts,
39471 diff -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
39472 --- linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c 2011-05-19 00:06:34.000000000 -0400
39473 +++ linux-2.6.39.1/drivers/staging/generic_serial/ser_a2232.c 2011-05-22 19:36:32.000000000 -0400
39474 @@ -144,7 +144,7 @@ static int a2232_open(struct tty_struct
39475 /*---------------------------------------------------------------------------
39476 * Interface from generic_serial.c back here
39477 *--------------------------------------------------------------------------*/
39478 -static struct real_driver a2232_real_driver = {
39479 +static const struct real_driver a2232_real_driver = {
39480 a2232_disable_tx_interrupts,
39481 a2232_enable_tx_interrupts,
39482 a2232_disable_rx_interrupts,
39483 diff -urNp linux-2.6.39.1/drivers/staging/generic_serial/sx.c linux-2.6.39.1/drivers/staging/generic_serial/sx.c
39484 --- linux-2.6.39.1/drivers/staging/generic_serial/sx.c 2011-05-19 00:06:34.000000000 -0400
39485 +++ linux-2.6.39.1/drivers/staging/generic_serial/sx.c 2011-05-22 19:36:32.000000000 -0400
39486 @@ -355,7 +355,7 @@ module_param(sx_irqmask, int, 0);
39487
39488 MODULE_LICENSE("GPL");
39489
39490 -static struct real_driver sx_real_driver = {
39491 +static const struct real_driver sx_real_driver = {
39492 sx_disable_tx_interrupts,
39493 sx_enable_tx_interrupts,
39494 sx_disable_rx_interrupts,
39495 diff -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
39496 --- linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c 2011-05-19 00:06:34.000000000 -0400
39497 +++ linux-2.6.39.1/drivers/staging/generic_serial/vme_scc.c 2011-05-22 19:36:32.000000000 -0400
39498 @@ -94,7 +94,7 @@ static struct scc_port scc_ports[2];
39499 * Interface from generic_serial.c back here
39500 *--------------------------------------------------------------------------*/
39501
39502 -static struct real_driver scc_real_driver = {
39503 +static const struct real_driver scc_real_driver = {
39504 scc_disable_tx_interrupts,
39505 scc_enable_tx_interrupts,
39506 scc_disable_rx_interrupts,
39507 diff -urNp linux-2.6.39.1/drivers/staging/gma500/psb_fb.c linux-2.6.39.1/drivers/staging/gma500/psb_fb.c
39508 --- linux-2.6.39.1/drivers/staging/gma500/psb_fb.c 2011-05-19 00:06:34.000000000 -0400
39509 +++ linux-2.6.39.1/drivers/staging/gma500/psb_fb.c 2011-05-22 19:36:32.000000000 -0400
39510 @@ -230,7 +230,7 @@ static void psbfb_vm_close(struct vm_are
39511 DRM_DEBUG("vm_close\n");
39512 }
39513
39514 -static struct vm_operations_struct psbfb_vm_ops = {
39515 +static const struct vm_operations_struct psbfb_vm_ops = {
39516 .fault = psbfb_vm_fault,
39517 .open = psbfb_vm_open,
39518 .close = psbfb_vm_close
39519 diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c
39520 --- linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c 2011-05-19 00:06:34.000000000 -0400
39521 +++ linux-2.6.39.1/drivers/staging/go7007/go7007-i2c.c 2011-05-22 19:36:32.000000000 -0400
39522 @@ -198,7 +198,7 @@ static u32 go7007_functionality(struct i
39523 return I2C_FUNC_SMBUS_BYTE_DATA;
39524 }
39525
39526 -static struct i2c_algorithm go7007_algo = {
39527 +static const struct i2c_algorithm go7007_algo = {
39528 .smbus_xfer = go7007_smbus_xfer,
39529 .master_xfer = go7007_i2c_master_xfer,
39530 .functionality = go7007_functionality,
39531 diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c
39532 --- linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c 2011-05-19 00:06:34.000000000 -0400
39533 +++ linux-2.6.39.1/drivers/staging/go7007/go7007-usb.c 2011-05-22 19:36:32.000000000 -0400
39534 @@ -849,7 +849,7 @@ static int go7007_usb_send_firmware(stru
39535 &transferred, timeout);
39536 }
39537
39538 -static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39539 +static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39540 .interface_reset = go7007_usb_interface_reset,
39541 .write_interrupt = go7007_usb_ezusb_write_interrupt,
39542 .read_interrupt = go7007_usb_read_interrupt,
39543 @@ -858,7 +858,7 @@ static struct go7007_hpi_ops go7007_usb_
39544 .send_firmware = go7007_usb_send_firmware,
39545 };
39546
39547 -static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39548 +static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39549 .interface_reset = go7007_usb_interface_reset,
39550 .write_interrupt = go7007_usb_onboard_write_interrupt,
39551 .read_interrupt = go7007_usb_read_interrupt,
39552 @@ -950,7 +950,7 @@ static u32 go7007_usb_functionality(stru
39553 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
39554 }
39555
39556 -static struct i2c_algorithm go7007_usb_algo = {
39557 +static const struct i2c_algorithm go7007_usb_algo = {
39558 .master_xfer = go7007_usb_i2c_master_xfer,
39559 .functionality = go7007_usb_functionality,
39560 };
39561 diff -urNp linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c
39562 --- linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c 2011-05-19 00:06:34.000000000 -0400
39563 +++ linux-2.6.39.1/drivers/staging/go7007/go7007-v4l2.c 2011-05-22 19:36:32.000000000 -0400
39564 @@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
39565 return 0;
39566 }
39567
39568 -static struct vm_operations_struct go7007_vm_ops = {
39569 +static const struct vm_operations_struct go7007_vm_ops = {
39570 .open = go7007_vm_open,
39571 .close = go7007_vm_close,
39572 .fault = go7007_vm_fault,
39573 diff -urNp linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c
39574 --- linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c 2011-05-19 00:06:34.000000000 -0400
39575 +++ linux-2.6.39.1/drivers/staging/go7007/saa7134-go7007.c 2011-05-22 19:36:32.000000000 -0400
39576 @@ -421,7 +421,7 @@ static int saa7134_go7007_send_command(s
39577
39578 }
39579
39580 -static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39581 +static const struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39582 .interface_reset = saa7134_go7007_interface_reset,
39583 .write_interrupt = saa7134_go7007_write_interrupt,
39584 .read_interrupt = saa7134_go7007_read_interrupt,
39585 diff -urNp linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c
39586 --- linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c 2011-05-19 00:06:34.000000000 -0400
39587 +++ linux-2.6.39.1/drivers/staging/go7007/snd-go7007.c 2011-05-22 19:36:32.000000000 -0400
39588 @@ -204,7 +204,7 @@ static struct page *go7007_snd_pcm_page(
39589 return vmalloc_to_page(substream->runtime->dma_area + offset);
39590 }
39591
39592 -static struct snd_pcm_ops go7007_snd_capture_ops = {
39593 +static const struct snd_pcm_ops go7007_snd_capture_ops = {
39594 .open = go7007_snd_capture_open,
39595 .close = go7007_snd_capture_close,
39596 .ioctl = snd_pcm_lib_ioctl,
39597 @@ -227,7 +227,7 @@ static int go7007_snd_free(struct snd_de
39598 return 0;
39599 }
39600
39601 -static struct snd_device_ops go7007_snd_device_ops = {
39602 +static const struct snd_device_ops go7007_snd_device_ops = {
39603 .dev_free = go7007_snd_free,
39604 };
39605
39606 diff -urNp linux-2.6.39.1/drivers/staging/hv/channel.c linux-2.6.39.1/drivers/staging/hv/channel.c
39607 --- linux-2.6.39.1/drivers/staging/hv/channel.c 2011-05-19 00:06:34.000000000 -0400
39608 +++ linux-2.6.39.1/drivers/staging/hv/channel.c 2011-05-22 19:36:32.000000000 -0400
39609 @@ -509,8 +509,8 @@ int vmbus_establish_gpadl(struct vmbus_c
39610 unsigned long flags;
39611 int ret = 0;
39612
39613 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39614 - atomic_inc(&vmbus_connection.next_gpadl_handle);
39615 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39616 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39617
39618 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39619 if (ret)
39620 diff -urNp linux-2.6.39.1/drivers/staging/hv/hv.c linux-2.6.39.1/drivers/staging/hv/hv.c
39621 --- linux-2.6.39.1/drivers/staging/hv/hv.c 2011-05-19 00:06:34.000000000 -0400
39622 +++ linux-2.6.39.1/drivers/staging/hv/hv.c 2011-05-22 19:36:32.000000000 -0400
39623 @@ -163,7 +163,7 @@ static u64 do_hypercall(u64 control, voi
39624 u64 output_address = (output) ? virt_to_phys(output) : 0;
39625 u32 output_address_hi = output_address >> 32;
39626 u32 output_address_lo = output_address & 0xFFFFFFFF;
39627 - volatile void *hypercall_page = hv_context.hypercall_page;
39628 + volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39629
39630 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
39631 control, input, output);
39632 diff -urNp linux-2.6.39.1/drivers/staging/hv/rndis_filter.c linux-2.6.39.1/drivers/staging/hv/rndis_filter.c
39633 --- linux-2.6.39.1/drivers/staging/hv/rndis_filter.c 2011-05-19 00:06:34.000000000 -0400
39634 +++ linux-2.6.39.1/drivers/staging/hv/rndis_filter.c 2011-05-22 19:36:32.000000000 -0400
39635 @@ -49,7 +49,7 @@ struct rndis_device {
39636
39637 enum rndis_device_state state;
39638 u32 link_stat;
39639 - atomic_t new_req_id;
39640 + atomic_unchecked_t new_req_id;
39641
39642 spinlock_t request_lock;
39643 struct list_head req_list;
39644 @@ -144,7 +144,7 @@ static struct rndis_request *get_rndis_r
39645 * template
39646 */
39647 set = &rndis_msg->msg.set_req;
39648 - set->req_id = atomic_inc_return(&dev->new_req_id);
39649 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39650
39651 /* Add to the request list */
39652 spin_lock_irqsave(&dev->request_lock, flags);
39653 @@ -709,7 +709,7 @@ static void rndis_filter_halt_device(str
39654
39655 /* Setup the rndis set */
39656 halt = &request->request_msg.msg.halt_req;
39657 - halt->req_id = atomic_inc_return(&dev->new_req_id);
39658 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39659
39660 /* Ignore return since this msg is optional. */
39661 rndis_filter_send_request(dev, request);
39662 diff -urNp linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c
39663 --- linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c 2011-05-19 00:06:34.000000000 -0400
39664 +++ linux-2.6.39.1/drivers/staging/hv/vmbus_drv.c 2011-05-22 19:36:32.000000000 -0400
39665 @@ -661,14 +661,14 @@ int vmbus_child_device_register(struct h
39666 {
39667 int ret = 0;
39668
39669 - static atomic_t device_num = ATOMIC_INIT(0);
39670 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39671
39672 DPRINT_DBG(VMBUS_DRV, "child device (%p) registering",
39673 child_device_obj);
39674
39675 /* Set the device name. Otherwise, device_register() will fail. */
39676 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39677 - atomic_inc_return(&device_num));
39678 + atomic_inc_return_unchecked(&device_num));
39679
39680 /* The new device belongs to this bus */
39681 child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */
39682 diff -urNp linux-2.6.39.1/drivers/staging/hv/vmbus_private.h linux-2.6.39.1/drivers/staging/hv/vmbus_private.h
39683 --- linux-2.6.39.1/drivers/staging/hv/vmbus_private.h 2011-05-19 00:06:34.000000000 -0400
39684 +++ linux-2.6.39.1/drivers/staging/hv/vmbus_private.h 2011-05-22 19:36:32.000000000 -0400
39685 @@ -58,7 +58,7 @@ enum vmbus_connect_state {
39686 struct vmbus_connection {
39687 enum vmbus_connect_state conn_state;
39688
39689 - atomic_t next_gpadl_handle;
39690 + atomic_unchecked_t next_gpadl_handle;
39691
39692 /*
39693 * Represents channel interrupts. Each bit position represents a
39694 diff -urNp linux-2.6.39.1/drivers/staging/iio/ring_generic.h linux-2.6.39.1/drivers/staging/iio/ring_generic.h
39695 --- linux-2.6.39.1/drivers/staging/iio/ring_generic.h 2011-05-19 00:06:34.000000000 -0400
39696 +++ linux-2.6.39.1/drivers/staging/iio/ring_generic.h 2011-05-25 16:55:27.000000000 -0400
39697 @@ -134,7 +134,7 @@ struct iio_ring_buffer {
39698 struct iio_handler access_handler;
39699 struct iio_event_interface ev_int;
39700 struct iio_shared_ev_pointer shared_ev_pointer;
39701 - struct iio_ring_access_funcs access;
39702 + struct iio_ring_access_funcs access;
39703 int (*preenable)(struct iio_dev *);
39704 int (*postenable)(struct iio_dev *);
39705 int (*predisable)(struct iio_dev *);
39706 diff -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
39707 --- linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-19 00:06:34.000000000 -0400
39708 +++ linux-2.6.39.1/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-22 19:36:32.000000000 -0400
39709 @@ -494,7 +494,7 @@ static int snd_intelmad_device_set(struc
39710 struct snd_intelmad *intelmaddata;
39711 struct snd_pmic_ops *scard_ops;
39712 int ret_val = 0, vendor, status;
39713 - struct intel_sst_pcm_control *pcm_control;
39714 + const struct intel_sst_pcm_control *pcm_control;
39715
39716 pr_debug("snd_intelmad_device_set called\n");
39717
39718 diff -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
39719 --- linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-19 00:06:34.000000000 -0400
39720 +++ linux-2.6.39.1/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-22 19:36:32.000000000 -0400
39721 @@ -470,7 +470,7 @@ int sst_device_control(int cmd, void *ar
39722 }
39723
39724
39725 -struct intel_sst_pcm_control pcm_ops = {
39726 +const struct intel_sst_pcm_control pcm_ops = {
39727 .open = sst_open_pcm_stream,
39728 .device_control = sst_device_control,
39729 .close = sst_close_pcm_stream,
39730 diff -urNp linux-2.6.39.1/drivers/staging/line6/capture.c linux-2.6.39.1/drivers/staging/line6/capture.c
39731 --- linux-2.6.39.1/drivers/staging/line6/capture.c 2011-05-19 00:06:34.000000000 -0400
39732 +++ linux-2.6.39.1/drivers/staging/line6/capture.c 2011-05-22 19:36:32.000000000 -0400
39733 @@ -378,7 +378,7 @@ snd_line6_capture_pointer(struct snd_pcm
39734 }
39735
39736 /* capture operators */
39737 -struct snd_pcm_ops snd_line6_capture_ops = {
39738 +const struct snd_pcm_ops snd_line6_capture_ops = {
39739 .open = snd_line6_capture_open,
39740 .close = snd_line6_capture_close,
39741 .ioctl = snd_pcm_lib_ioctl,
39742 diff -urNp linux-2.6.39.1/drivers/staging/line6/capture.h linux-2.6.39.1/drivers/staging/line6/capture.h
39743 --- linux-2.6.39.1/drivers/staging/line6/capture.h 2011-05-19 00:06:34.000000000 -0400
39744 +++ linux-2.6.39.1/drivers/staging/line6/capture.h 2011-05-22 19:36:32.000000000 -0400
39745 @@ -17,7 +17,7 @@
39746 #include "driver.h"
39747 #include "pcm.h"
39748
39749 -extern struct snd_pcm_ops snd_line6_capture_ops;
39750 +extern const struct snd_pcm_ops snd_line6_capture_ops;
39751
39752 extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
39753 int fsize);
39754 diff -urNp linux-2.6.39.1/drivers/staging/line6/midi.c linux-2.6.39.1/drivers/staging/line6/midi.c
39755 --- linux-2.6.39.1/drivers/staging/line6/midi.c 2011-05-19 00:06:34.000000000 -0400
39756 +++ linux-2.6.39.1/drivers/staging/line6/midi.c 2011-05-22 19:36:32.000000000 -0400
39757 @@ -239,14 +239,14 @@ static void line6_midi_input_trigger(str
39758 line6->line6midi->substream_receive = 0;
39759 }
39760
39761 -static struct snd_rawmidi_ops line6_midi_output_ops = {
39762 +static const struct snd_rawmidi_ops line6_midi_output_ops = {
39763 .open = line6_midi_output_open,
39764 .close = line6_midi_output_close,
39765 .trigger = line6_midi_output_trigger,
39766 .drain = line6_midi_output_drain,
39767 };
39768
39769 -static struct snd_rawmidi_ops line6_midi_input_ops = {
39770 +static const struct snd_rawmidi_ops line6_midi_input_ops = {
39771 .open = line6_midi_input_open,
39772 .close = line6_midi_input_close,
39773 .trigger = line6_midi_input_trigger,
39774 @@ -373,7 +373,7 @@ static int snd_line6_midi_free(struct sn
39775 */
39776 int line6_init_midi(struct usb_line6 *line6)
39777 {
39778 - static struct snd_device_ops midi_ops = {
39779 + static const struct snd_device_ops midi_ops = {
39780 .dev_free = snd_line6_midi_free,
39781 };
39782
39783 diff -urNp linux-2.6.39.1/drivers/staging/line6/pcm.c linux-2.6.39.1/drivers/staging/line6/pcm.c
39784 --- linux-2.6.39.1/drivers/staging/line6/pcm.c 2011-05-19 00:06:34.000000000 -0400
39785 +++ linux-2.6.39.1/drivers/staging/line6/pcm.c 2011-05-22 19:36:32.000000000 -0400
39786 @@ -384,7 +384,7 @@ void line6_pcm_disconnect(struct snd_lin
39787 int line6_init_pcm(struct usb_line6 *line6,
39788 struct line6_pcm_properties *properties)
39789 {
39790 - static struct snd_device_ops pcm_ops = {
39791 + static const struct snd_device_ops pcm_ops = {
39792 .dev_free = snd_line6_pcm_free,
39793 };
39794
39795 diff -urNp linux-2.6.39.1/drivers/staging/line6/playback.c linux-2.6.39.1/drivers/staging/line6/playback.c
39796 --- linux-2.6.39.1/drivers/staging/line6/playback.c 2011-05-19 00:06:34.000000000 -0400
39797 +++ linux-2.6.39.1/drivers/staging/line6/playback.c 2011-05-22 19:36:32.000000000 -0400
39798 @@ -536,7 +536,7 @@ snd_line6_playback_pointer(struct snd_pc
39799 }
39800
39801 /* playback operators */
39802 -struct snd_pcm_ops snd_line6_playback_ops = {
39803 +const struct snd_pcm_ops snd_line6_playback_ops = {
39804 .open = snd_line6_playback_open,
39805 .close = snd_line6_playback_close,
39806 .ioctl = snd_pcm_lib_ioctl,
39807 diff -urNp linux-2.6.39.1/drivers/staging/line6/playback.h linux-2.6.39.1/drivers/staging/line6/playback.h
39808 --- linux-2.6.39.1/drivers/staging/line6/playback.h 2011-05-19 00:06:34.000000000 -0400
39809 +++ linux-2.6.39.1/drivers/staging/line6/playback.h 2011-05-22 19:36:32.000000000 -0400
39810 @@ -27,7 +27,7 @@
39811 */
39812 #define USE_CLEAR_BUFFER_WORKAROUND 1
39813
39814 -extern struct snd_pcm_ops snd_line6_playback_ops;
39815 +extern const struct snd_pcm_ops snd_line6_playback_ops;
39816
39817 extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
39818 extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
39819 diff -urNp linux-2.6.39.1/drivers/staging/msm/staging-devices.c linux-2.6.39.1/drivers/staging/msm/staging-devices.c
39820 --- linux-2.6.39.1/drivers/staging/msm/staging-devices.c 2011-05-19 00:06:34.000000000 -0400
39821 +++ linux-2.6.39.1/drivers/staging/msm/staging-devices.c 2011-05-22 19:36:32.000000000 -0400
39822 @@ -211,7 +211,7 @@ static int msm_fb_lcdc_gpio_config(int o
39823 }
39824
39825
39826 -static struct lcdc_platform_data lcdc_pdata = {
39827 +static const struct lcdc_platform_data lcdc_pdata = {
39828 .lcdc_gpio_config = msm_fb_lcdc_gpio_config,
39829 };
39830
39831 diff -urNp linux-2.6.39.1/drivers/staging/octeon/ethernet.c linux-2.6.39.1/drivers/staging/octeon/ethernet.c
39832 --- linux-2.6.39.1/drivers/staging/octeon/ethernet.c 2011-05-19 00:06:34.000000000 -0400
39833 +++ linux-2.6.39.1/drivers/staging/octeon/ethernet.c 2011-05-22 19:36:32.000000000 -0400
39834 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_
39835 * since the RX tasklet also increments it.
39836 */
39837 #ifdef CONFIG_64BIT
39838 - atomic64_add(rx_status.dropped_packets,
39839 - (atomic64_t *)&priv->stats.rx_dropped);
39840 + atomic64_add_unchecked(rx_status.dropped_packets,
39841 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39842 #else
39843 - atomic_add(rx_status.dropped_packets,
39844 - (atomic_t *)&priv->stats.rx_dropped);
39845 + atomic_add_unchecked(rx_status.dropped_packets,
39846 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39847 #endif
39848 }
39849
39850 diff -urNp linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c
39851 --- linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c 2011-05-19 00:06:34.000000000 -0400
39852 +++ linux-2.6.39.1/drivers/staging/octeon/ethernet-rx.c 2011-05-22 19:36:32.000000000 -0400
39853 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi
39854 /* Increment RX stats for virtual ports */
39855 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39856 #ifdef CONFIG_64BIT
39857 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39858 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39859 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39860 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39861 #else
39862 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39863 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39864 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39865 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39866 #endif
39867 }
39868 netif_receive_skb(skb);
39869 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi
39870 dev->name);
39871 */
39872 #ifdef CONFIG_64BIT
39873 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39874 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39875 #else
39876 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39877 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39878 #endif
39879 dev_kfree_skb_irq(skb);
39880 }
39881 diff -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
39882 --- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-19 00:06:34.000000000 -0400
39883 +++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-22 19:36:32.000000000 -0400
39884 @@ -43,7 +43,7 @@ module_param(noinit, int, 0444);
39885 static int useaa = 1;
39886 module_param(useaa, int, 0444);
39887
39888 -static struct dcon_platform_data *pdata;
39889 +static const struct dcon_platform_data *pdata;
39890
39891 /* I2C structures */
39892
39893 diff -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
39894 --- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-19 00:06:34.000000000 -0400
39895 +++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-22 19:36:32.000000000 -0400
39896 @@ -92,11 +92,11 @@ struct dcon_platform_data {
39897 extern irqreturn_t dcon_interrupt(int irq, void *id);
39898
39899 #ifdef CONFIG_FB_OLPC_DCON_1
39900 -extern struct dcon_platform_data dcon_pdata_xo_1;
39901 +extern const struct dcon_platform_data dcon_pdata_xo_1;
39902 #endif
39903
39904 #ifdef CONFIG_FB_OLPC_DCON_1_5
39905 -extern struct dcon_platform_data dcon_pdata_xo_1_5;
39906 +extern const struct dcon_platform_data dcon_pdata_xo_1_5;
39907 #endif
39908
39909 #endif
39910 diff -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
39911 --- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-19 00:06:34.000000000 -0400
39912 +++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-22 19:36:32.000000000 -0400
39913 @@ -185,7 +185,7 @@ static u8 dcon_read_status_xo_1_5(void)
39914 return status;
39915 }
39916
39917 -struct dcon_platform_data dcon_pdata_xo_1_5 = {
39918 +const struct dcon_platform_data dcon_pdata_xo_1_5 = {
39919 .init = dcon_init_xo_1_5,
39920 .bus_stabilize_wiggle = dcon_wiggle_xo_1_5,
39921 .set_dconload = dcon_set_dconload_xo_1_5,
39922 diff -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
39923 --- linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-19 00:06:34.000000000 -0400
39924 +++ linux-2.6.39.1/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-22 19:36:32.000000000 -0400
39925 @@ -196,7 +196,7 @@ static u8 dcon_read_status_xo_1(void)
39926 return status;
39927 }
39928
39929 -struct dcon_platform_data dcon_pdata_xo_1 = {
39930 +const struct dcon_platform_data dcon_pdata_xo_1 = {
39931 .init = dcon_init_xo_1,
39932 .bus_stabilize_wiggle = dcon_wiggle_xo_1,
39933 .set_dconload = dcon_set_dconload_1,
39934 diff -urNp linux-2.6.39.1/drivers/staging/phison/phison.c linux-2.6.39.1/drivers/staging/phison/phison.c
39935 --- linux-2.6.39.1/drivers/staging/phison/phison.c 2011-05-19 00:06:34.000000000 -0400
39936 +++ linux-2.6.39.1/drivers/staging/phison/phison.c 2011-05-22 19:36:32.000000000 -0400
39937 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_
39938 ATA_BMDMA_SHT(DRV_NAME),
39939 };
39940
39941 -static struct ata_port_operations phison_ops = {
39942 +static const struct ata_port_operations phison_ops = {
39943 .inherits = &ata_bmdma_port_ops,
39944 .prereset = phison_pre_reset,
39945 };
39946 diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/inode.c linux-2.6.39.1/drivers/staging/pohmelfs/inode.c
39947 --- linux-2.6.39.1/drivers/staging/pohmelfs/inode.c 2011-05-19 00:06:34.000000000 -0400
39948 +++ linux-2.6.39.1/drivers/staging/pohmelfs/inode.c 2011-05-22 19:36:32.000000000 -0400
39949 @@ -1855,7 +1855,7 @@ static int pohmelfs_fill_super(struct su
39950 mutex_init(&psb->mcache_lock);
39951 psb->mcache_root = RB_ROOT;
39952 psb->mcache_timeout = msecs_to_jiffies(5000);
39953 - atomic_long_set(&psb->mcache_gen, 0);
39954 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
39955
39956 psb->trans_max_pages = 100;
39957
39958 @@ -1870,7 +1870,7 @@ static int pohmelfs_fill_super(struct su
39959 INIT_LIST_HEAD(&psb->crypto_ready_list);
39960 INIT_LIST_HEAD(&psb->crypto_active_list);
39961
39962 - atomic_set(&psb->trans_gen, 1);
39963 + atomic_set_unchecked(&psb->trans_gen, 1);
39964 atomic_long_set(&psb->total_inodes, 0);
39965
39966 mutex_init(&psb->state_lock);
39967 diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c
39968 --- linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c 2011-05-19 00:06:34.000000000 -0400
39969 +++ linux-2.6.39.1/drivers/staging/pohmelfs/mcache.c 2011-05-22 19:36:32.000000000 -0400
39970 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
39971 m->data = data;
39972 m->start = start;
39973 m->size = size;
39974 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
39975 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
39976
39977 mutex_lock(&psb->mcache_lock);
39978 err = pohmelfs_mcache_insert(psb, m);
39979 diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h
39980 --- linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h 2011-05-19 00:06:34.000000000 -0400
39981 +++ linux-2.6.39.1/drivers/staging/pohmelfs/netfs.h 2011-05-22 19:36:32.000000000 -0400
39982 @@ -571,14 +571,14 @@ struct pohmelfs_config;
39983 struct pohmelfs_sb {
39984 struct rb_root mcache_root;
39985 struct mutex mcache_lock;
39986 - atomic_long_t mcache_gen;
39987 + atomic_long_unchecked_t mcache_gen;
39988 unsigned long mcache_timeout;
39989
39990 unsigned int idx;
39991
39992 unsigned int trans_retries;
39993
39994 - atomic_t trans_gen;
39995 + atomic_unchecked_t trans_gen;
39996
39997 unsigned int crypto_attached_size;
39998 unsigned int crypto_align_size;
39999 diff -urNp linux-2.6.39.1/drivers/staging/pohmelfs/trans.c linux-2.6.39.1/drivers/staging/pohmelfs/trans.c
40000 --- linux-2.6.39.1/drivers/staging/pohmelfs/trans.c 2011-05-19 00:06:34.000000000 -0400
40001 +++ linux-2.6.39.1/drivers/staging/pohmelfs/trans.c 2011-05-22 19:36:32.000000000 -0400
40002 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
40003 int err;
40004 struct netfs_cmd *cmd = t->iovec.iov_base;
40005
40006 - t->gen = atomic_inc_return(&psb->trans_gen);
40007 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
40008
40009 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
40010 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
40011 diff -urNp linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c
40012 --- linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-19 00:06:34.000000000 -0400
40013 +++ linux-2.6.39.1/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-22 19:36:32.000000000 -0400
40014 @@ -87,7 +87,7 @@ static int c_show(struct seq_file *m, vo
40015 return 0;
40016 }
40017
40018 -static struct seq_operations crypto_seq_ops = {
40019 +static const struct seq_operations crypto_seq_ops = {
40020 .start = c_start,
40021 .next = c_next,
40022 .stop = c_stop,
40023 @@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
40024 return seq_open(file, &crypto_seq_ops);
40025 }
40026
40027 -static struct file_operations proc_crypto_ops = {
40028 +static const struct file_operations proc_crypto_ops = {
40029 .open = crypto_info_open,
40030 .read = seq_read,
40031 .llseek = seq_lseek,
40032 diff -urNp linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h
40033 --- linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h 2011-05-19 00:06:34.000000000 -0400
40034 +++ linux-2.6.39.1/drivers/staging/rtl8712/rtl871x_io.h 2011-05-22 19:36:32.000000000 -0400
40035 @@ -107,7 +107,7 @@ struct intf_hdl {
40036 void (*intf_hdl_unload)(u8 *priv);
40037 void (*intf_hdl_open)(u8 *priv);
40038 void (*intf_hdl_close)(u8 *priv);
40039 - struct _io_ops io_ops;
40040 + const struct _io_ops io_ops;
40041 };
40042
40043 struct reg_protocol_rd {
40044 diff -urNp linux-2.6.39.1/drivers/staging/solo6x10/g723.c linux-2.6.39.1/drivers/staging/solo6x10/g723.c
40045 --- linux-2.6.39.1/drivers/staging/solo6x10/g723.c 2011-05-19 00:06:34.000000000 -0400
40046 +++ linux-2.6.39.1/drivers/staging/solo6x10/g723.c 2011-05-22 19:36:32.000000000 -0400
40047 @@ -237,7 +237,7 @@ static int snd_solo_pcm_copy(struct snd_
40048 return 0;
40049 }
40050
40051 -static struct snd_pcm_ops snd_solo_pcm_ops = {
40052 +static const struct snd_pcm_ops snd_solo_pcm_ops = {
40053 .open = snd_solo_pcm_open,
40054 .close = snd_solo_pcm_close,
40055 .ioctl = snd_pcm_lib_ioctl,
40056 @@ -334,7 +334,7 @@ static int solo_snd_pcm_init(struct solo
40057
40058 int solo_g723_init(struct solo_dev *solo_dev)
40059 {
40060 - static struct snd_device_ops ops = { NULL };
40061 + static const struct snd_device_ops ops = { NULL };
40062 struct snd_card *card;
40063 struct snd_kcontrol_new kctl;
40064 char name[32];
40065 diff -urNp linux-2.6.39.1/drivers/staging/spectra/ffsport.c linux-2.6.39.1/drivers/staging/spectra/ffsport.c
40066 --- linux-2.6.39.1/drivers/staging/spectra/ffsport.c 2011-05-19 00:06:34.000000000 -0400
40067 +++ linux-2.6.39.1/drivers/staging/spectra/ffsport.c 2011-05-22 19:36:32.000000000 -0400
40068 @@ -604,7 +604,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
40069 return ret;
40070 }
40071
40072 -static struct block_device_operations GLOB_SBD_ops = {
40073 +static const struct block_device_operations GLOB_SBD_ops = {
40074 .owner = THIS_MODULE,
40075 .open = GLOB_SBD_open,
40076 .release = GLOB_SBD_release,
40077 diff -urNp linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c
40078 --- linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c 2011-05-19 00:06:34.000000000 -0400
40079 +++ linux-2.6.39.1/drivers/staging/tm6000/tm6000-alsa.c 2011-05-22 19:36:32.000000000 -0400
40080 @@ -380,7 +380,7 @@ static snd_pcm_uframes_t snd_tm6000_poin
40081 /*
40082 * operators
40083 */
40084 -static struct snd_pcm_ops snd_tm6000_pcm_ops = {
40085 +static const struct snd_pcm_ops snd_tm6000_pcm_ops = {
40086 .open = snd_tm6000_pcm_open,
40087 .close = snd_tm6000_close,
40088 .ioctl = snd_pcm_lib_ioctl,
40089 diff -urNp linux-2.6.39.1/drivers/staging/tty/istallion.c linux-2.6.39.1/drivers/staging/tty/istallion.c
40090 --- linux-2.6.39.1/drivers/staging/tty/istallion.c 2011-05-19 00:06:34.000000000 -0400
40091 +++ linux-2.6.39.1/drivers/staging/tty/istallion.c 2011-05-22 20:49:07.000000000 -0400
40092 @@ -186,7 +186,6 @@ static struct ktermios stli_deftermios
40093 * re-used for each stats call.
40094 */
40095 static comstats_t stli_comstats;
40096 -static combrd_t stli_brdstats;
40097 static struct asystats stli_cdkstats;
40098
40099 /*****************************************************************************/
40100 @@ -4003,6 +4002,7 @@ out:
40101
40102 static int stli_getbrdstats(combrd_t __user *bp)
40103 {
40104 + combrd_t stli_brdstats;
40105 struct stlibrd *brdp;
40106 unsigned int i;
40107
40108 @@ -4226,6 +4226,8 @@ static int stli_getportstruct(struct stl
40109 struct stliport stli_dummyport;
40110 struct stliport *portp;
40111
40112 + pax_track_stack();
40113 +
40114 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
40115 return -EFAULT;
40116 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
40117 @@ -4248,6 +4250,8 @@ static int stli_getbrdstruct(struct stli
40118 struct stlibrd stli_dummybrd;
40119 struct stlibrd *brdp;
40120
40121 + pax_track_stack();
40122 +
40123 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
40124 return -EFAULT;
40125 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
40126 diff -urNp linux-2.6.39.1/drivers/staging/tty/stallion.c linux-2.6.39.1/drivers/staging/tty/stallion.c
40127 --- linux-2.6.39.1/drivers/staging/tty/stallion.c 2011-05-19 00:06:34.000000000 -0400
40128 +++ linux-2.6.39.1/drivers/staging/tty/stallion.c 2011-05-22 19:36:32.000000000 -0400
40129 @@ -2406,6 +2406,8 @@ static int stl_getportstruct(struct stlp
40130 struct stlport stl_dummyport;
40131 struct stlport *portp;
40132
40133 + pax_track_stack();
40134 +
40135 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
40136 return -EFAULT;
40137 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
40138 diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci.h linux-2.6.39.1/drivers/staging/usbip/vhci.h
40139 --- linux-2.6.39.1/drivers/staging/usbip/vhci.h 2011-05-19 00:06:34.000000000 -0400
40140 +++ linux-2.6.39.1/drivers/staging/usbip/vhci.h 2011-05-22 19:36:32.000000000 -0400
40141 @@ -92,7 +92,7 @@ struct vhci_hcd {
40142 unsigned resuming:1;
40143 unsigned long re_timeout;
40144
40145 - atomic_t seqnum;
40146 + atomic_unchecked_t seqnum;
40147
40148 /*
40149 * NOTE:
40150 diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c
40151 --- linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c 2011-05-19 00:06:34.000000000 -0400
40152 +++ linux-2.6.39.1/drivers/staging/usbip/vhci_hcd.c 2011-05-22 19:36:32.000000000 -0400
40153 @@ -536,7 +536,7 @@ static void vhci_tx_urb(struct urb *urb)
40154 return;
40155 }
40156
40157 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40158 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40159 if (priv->seqnum == 0xffff)
40160 usbip_uinfo("seqnum max\n");
40161
40162 @@ -795,7 +795,7 @@ static int vhci_urb_dequeue(struct usb_h
40163 return -ENOMEM;
40164 }
40165
40166 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40167 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40168 if (unlink->seqnum == 0xffff)
40169 usbip_uinfo("seqnum max\n");
40170
40171 @@ -992,7 +992,7 @@ static int vhci_start(struct usb_hcd *hc
40172 vdev->rhport = rhport;
40173 }
40174
40175 - atomic_set(&vhci->seqnum, 0);
40176 + atomic_set_unchecked(&vhci->seqnum, 0);
40177 spin_lock_init(&vhci->lock);
40178
40179
40180 diff -urNp linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c
40181 --- linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c 2011-05-19 00:06:34.000000000 -0400
40182 +++ linux-2.6.39.1/drivers/staging/usbip/vhci_rx.c 2011-05-22 19:36:32.000000000 -0400
40183 @@ -81,7 +81,7 @@ static void vhci_recv_ret_submit(struct
40184 usbip_uerr("cannot find a urb of seqnum %u\n",
40185 pdu->base.seqnum);
40186 usbip_uinfo("max seqnum %d\n",
40187 - atomic_read(&the_controller->seqnum));
40188 + atomic_read_unchecked(&the_controller->seqnum));
40189 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40190 return;
40191 }
40192 diff -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
40193 --- linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c 2011-05-19 00:06:34.000000000 -0400
40194 +++ linux-2.6.39.1/drivers/staging/vme/devices/vme_user.c 2011-05-22 19:36:32.000000000 -0400
40195 @@ -138,7 +138,7 @@ static long vme_user_unlocked_ioctl(stru
40196 static int __devinit vme_user_probe(struct device *, int, int);
40197 static int __devexit vme_user_remove(struct device *, int, int);
40198
40199 -static struct file_operations vme_user_fops = {
40200 +static const struct file_operations vme_user_fops = {
40201 .open = vme_user_open,
40202 .release = vme_user_release,
40203 .read = vme_user_read,
40204 diff -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
40205 --- linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-19 00:06:34.000000000 -0400
40206 +++ linux-2.6.39.1/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-22 19:36:32.000000000 -0400
40207 @@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
40208
40209
40210 /*standard block device driver interface */
40211 -static struct block_device_operations cyasblkdev_bdops = {
40212 +static const struct block_device_operations cyasblkdev_bdops = {
40213 .open = cyasblkdev_blk_open,
40214 .release = cyasblkdev_blk_release,
40215 .ioctl = cyasblkdev_blk_ioctl,
40216 diff -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
40217 --- linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-19 00:06:34.000000000 -0400
40218 +++ linux-2.6.39.1/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-22 19:36:32.000000000 -0400
40219 @@ -474,7 +474,7 @@ static void wl_get_drvinfo(struct net_de
40220 }
40221 } // wl_get_drvinfo
40222
40223 -static struct ethtool_ops wl_ethtool_ops = {
40224 +static const struct ethtool_ops wl_ethtool_ops = {
40225 .get_drvinfo = wl_get_drvinfo,
40226 .get_link = ethtool_op_get_link,
40227 };
40228 diff -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
40229 --- linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-19 00:06:34.000000000 -0400
40230 +++ linux-2.6.39.1/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-22 19:36:32.000000000 -0400
40231 @@ -671,7 +671,7 @@ struct usbctlx_cmd_completor {
40232 hfa384x_cmdresult_t *result;
40233 };
40234
40235 -static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
40236 +static inline int usbctlx_cmd_completor_fn(const struct usbctlx_completor *head)
40237 {
40238 struct usbctlx_cmd_completor *complete;
40239
40240 @@ -705,7 +705,7 @@ struct usbctlx_rrid_completor {
40241 unsigned int riddatalen;
40242 };
40243
40244 -static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
40245 +static int usbctlx_rrid_completor_fn(const struct usbctlx_completor *head)
40246 {
40247 struct usbctlx_rrid_completor *complete;
40248 hfa384x_rridresult_t rridresult;
40249 @@ -768,7 +768,7 @@ struct usbctlx_rmem_completor {
40250 };
40251 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
40252
40253 -static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
40254 +static int usbctlx_rmem_completor_fn(const struct usbctlx_completor *head)
40255 {
40256 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
40257
40258 diff -urNp linux-2.6.39.1/drivers/staging/zcache/tmem.c linux-2.6.39.1/drivers/staging/zcache/tmem.c
40259 --- linux-2.6.39.1/drivers/staging/zcache/tmem.c 2011-05-19 00:06:34.000000000 -0400
40260 +++ linux-2.6.39.1/drivers/staging/zcache/tmem.c 2011-05-22 19:36:32.000000000 -0400
40261 @@ -39,7 +39,7 @@
40262 * A tmem host implementation must use this function to register callbacks
40263 * for memory allocation.
40264 */
40265 -static struct tmem_hostops tmem_hostops;
40266 +static const struct tmem_hostops tmem_hostops;
40267
40268 static void tmem_objnode_tree_init(void);
40269
40270 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_h
40271 * A tmem host implementation must use this function to register
40272 * callbacks for a page-accessible memory (PAM) implementation
40273 */
40274 -static struct tmem_pamops tmem_pamops;
40275 +static const struct tmem_pamops tmem_pamops;
40276
40277 void tmem_register_pamops(struct tmem_pamops *m)
40278 {
40279 diff -urNp linux-2.6.39.1/drivers/staging/zcache/zcache.c linux-2.6.39.1/drivers/staging/zcache/zcache.c
40280 --- linux-2.6.39.1/drivers/staging/zcache/zcache.c 2011-05-19 00:06:34.000000000 -0400
40281 +++ linux-2.6.39.1/drivers/staging/zcache/zcache.c 2011-05-22 19:36:32.000000000 -0400
40282 @@ -882,7 +882,7 @@ static void zcache_obj_free(struct tmem_
40283 kmem_cache_free(zcache_obj_cache, obj);
40284 }
40285
40286 -static struct tmem_hostops zcache_hostops = {
40287 +static const struct tmem_hostops zcache_hostops = {
40288 .obj_alloc = zcache_obj_alloc,
40289 .obj_free = zcache_obj_free,
40290 .objnode_alloc = zcache_objnode_alloc,
40291 @@ -987,7 +987,7 @@ static void zcache_pampd_free(void *pamp
40292 }
40293 }
40294
40295 -static struct tmem_pamops zcache_pamops = {
40296 +static const struct tmem_pamops zcache_pamops = {
40297 .create = zcache_pampd_create,
40298 .get_data = zcache_pampd_get_data,
40299 .free = zcache_pampd_free,
40300 diff -urNp linux-2.6.39.1/drivers/target/target_core_alua.c linux-2.6.39.1/drivers/target/target_core_alua.c
40301 --- linux-2.6.39.1/drivers/target/target_core_alua.c 2011-05-19 00:06:34.000000000 -0400
40302 +++ linux-2.6.39.1/drivers/target/target_core_alua.c 2011-05-22 19:36:32.000000000 -0400
40303 @@ -675,6 +675,8 @@ static int core_alua_update_tpg_primary_
40304 char path[ALUA_METADATA_PATH_LEN];
40305 int len;
40306
40307 + pax_track_stack();
40308 +
40309 memset(path, 0, ALUA_METADATA_PATH_LEN);
40310
40311 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
40312 @@ -938,6 +940,8 @@ static int core_alua_update_tpg_secondar
40313 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
40314 int len;
40315
40316 + pax_track_stack();
40317 +
40318 memset(path, 0, ALUA_METADATA_PATH_LEN);
40319 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
40320
40321 diff -urNp linux-2.6.39.1/drivers/target/target_core_cdb.c linux-2.6.39.1/drivers/target/target_core_cdb.c
40322 --- linux-2.6.39.1/drivers/target/target_core_cdb.c 2011-05-19 00:06:34.000000000 -0400
40323 +++ linux-2.6.39.1/drivers/target/target_core_cdb.c 2011-05-22 19:36:32.000000000 -0400
40324 @@ -838,6 +838,8 @@ target_emulate_modesense(struct se_cmd *
40325 int length = 0;
40326 unsigned char buf[SE_MODE_PAGE_BUF];
40327
40328 + pax_track_stack();
40329 +
40330 memset(buf, 0, SE_MODE_PAGE_BUF);
40331
40332 switch (cdb[2] & 0x3f) {
40333 diff -urNp linux-2.6.39.1/drivers/target/target_core_configfs.c linux-2.6.39.1/drivers/target/target_core_configfs.c
40334 --- linux-2.6.39.1/drivers/target/target_core_configfs.c 2011-05-19 00:06:34.000000000 -0400
40335 +++ linux-2.6.39.1/drivers/target/target_core_configfs.c 2011-05-22 19:36:32.000000000 -0400
40336 @@ -1280,6 +1280,8 @@ static ssize_t target_core_dev_pr_show_a
40337 ssize_t len = 0;
40338 int reg_count = 0, prf_isid;
40339
40340 + pax_track_stack();
40341 +
40342 if (!(su_dev->se_dev_ptr))
40343 return -ENODEV;
40344
40345 @@ -2682,7 +2684,7 @@ static void target_core_alua_drop_tg_pt_
40346 config_item_put(item);
40347 }
40348
40349 -static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40350 +static const struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40351 .make_group = &target_core_alua_create_tg_pt_gp,
40352 .drop_item = &target_core_alua_drop_tg_pt_gp,
40353 };
40354 @@ -2726,7 +2728,7 @@ static void target_core_stat_rmdir(
40355 return;
40356 }
40357
40358 -static struct configfs_group_operations target_core_stat_group_ops = {
40359 +static const struct configfs_group_operations target_core_stat_group_ops = {
40360 .make_group = &target_core_stat_mkdir,
40361 .drop_item = &target_core_stat_rmdir,
40362 };
40363 @@ -2939,7 +2941,7 @@ static void target_core_drop_subdev(
40364 mutex_unlock(&hba->hba_access_mutex);
40365 }
40366
40367 -static struct configfs_group_operations target_core_hba_group_ops = {
40368 +static const struct configfs_group_operations target_core_hba_group_ops = {
40369 .make_group = target_core_make_subdev,
40370 .drop_item = target_core_drop_subdev,
40371 };
40372 @@ -3117,7 +3119,7 @@ static void target_core_call_delhbafromt
40373 config_item_put(item);
40374 }
40375
40376 -static struct configfs_group_operations target_core_group_ops = {
40377 +static const struct configfs_group_operations target_core_group_ops = {
40378 .make_group = target_core_call_addhbatotarget,
40379 .drop_item = target_core_call_delhbafromtarget,
40380 };
40381 diff -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
40382 --- linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c 2011-05-19 00:06:34.000000000 -0400
40383 +++ linux-2.6.39.1/drivers/target/target_core_fabric_configfs.c 2011-05-22 19:36:32.000000000 -0400
40384 @@ -1174,7 +1174,7 @@ static void target_fabric_drop_wwn(
40385 config_item_put(item);
40386 }
40387
40388 -static struct configfs_group_operations target_fabric_wwn_group_ops = {
40389 +static const struct configfs_group_operations target_fabric_wwn_group_ops = {
40390 .make_group = target_fabric_make_wwn,
40391 .drop_item = target_fabric_drop_wwn,
40392 };
40393 diff -urNp linux-2.6.39.1/drivers/target/target_core_pr.c linux-2.6.39.1/drivers/target/target_core_pr.c
40394 --- linux-2.6.39.1/drivers/target/target_core_pr.c 2011-05-19 00:06:34.000000000 -0400
40395 +++ linux-2.6.39.1/drivers/target/target_core_pr.c 2011-05-22 19:36:32.000000000 -0400
40396 @@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_regi
40397 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
40398 u16 tpgt;
40399
40400 + pax_track_stack();
40401 +
40402 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
40403 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
40404 /*
40405 @@ -1861,6 +1863,8 @@ static int __core_scsi3_update_aptpl_buf
40406 ssize_t len = 0;
40407 int reg_count = 0;
40408
40409 + pax_track_stack();
40410 +
40411 memset(buf, 0, pr_aptpl_buf_len);
40412 /*
40413 * Called to clear metadata once APTPL has been deactivated.
40414 @@ -1983,6 +1987,8 @@ static int __core_scsi3_write_aptpl_to_f
40415 char path[512];
40416 int ret;
40417
40418 + pax_track_stack();
40419 +
40420 memset(iov, 0, sizeof(struct iovec));
40421 memset(path, 0, 512);
40422
40423 diff -urNp linux-2.6.39.1/drivers/target/target_core_tmr.c linux-2.6.39.1/drivers/target/target_core_tmr.c
40424 --- linux-2.6.39.1/drivers/target/target_core_tmr.c 2011-06-03 00:04:14.000000000 -0400
40425 +++ linux-2.6.39.1/drivers/target/target_core_tmr.c 2011-06-03 00:32:07.000000000 -0400
40426 @@ -263,7 +263,7 @@ int core_tmr_lun_reset(
40427 CMD_TFO(cmd)->get_task_tag(cmd), cmd->pr_res_key,
40428 T_TASK(cmd)->t_task_cdbs,
40429 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40430 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40431 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40432 atomic_read(&T_TASK(cmd)->t_transport_active),
40433 atomic_read(&T_TASK(cmd)->t_transport_stop),
40434 atomic_read(&T_TASK(cmd)->t_transport_sent));
40435 @@ -305,7 +305,7 @@ int core_tmr_lun_reset(
40436 DEBUG_LR("LUN_RESET: got t_transport_active = 1 for"
40437 " task: %p, t_fe_count: %d dev: %p\n", task,
40438 fe_count, dev);
40439 - atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40440 + atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40441 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock,
40442 flags);
40443 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40444 @@ -315,7 +315,7 @@ int core_tmr_lun_reset(
40445 }
40446 DEBUG_LR("LUN_RESET: Got t_transport_active = 0 for task: %p,"
40447 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
40448 - atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40449 + atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40450 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
40451 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40452
40453 diff -urNp linux-2.6.39.1/drivers/target/target_core_transport.c linux-2.6.39.1/drivers/target/target_core_transport.c
40454 --- linux-2.6.39.1/drivers/target/target_core_transport.c 2011-06-03 00:04:14.000000000 -0400
40455 +++ linux-2.6.39.1/drivers/target/target_core_transport.c 2011-06-03 00:32:07.000000000 -0400
40456 @@ -1681,7 +1681,7 @@ struct se_device *transport_add_device_t
40457
40458 dev->queue_depth = dev_limits->queue_depth;
40459 atomic_set(&dev->depth_left, dev->queue_depth);
40460 - atomic_set(&dev->dev_ordered_id, 0);
40461 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
40462
40463 se_dev_set_default_attribs(dev, dev_limits);
40464
40465 @@ -1882,7 +1882,7 @@ static int transport_check_alloc_task_at
40466 * Used to determine when ORDERED commands should go from
40467 * Dormant to Active status.
40468 */
40469 - cmd->se_ordered_id = atomic_inc_return(&SE_DEV(cmd)->dev_ordered_id);
40470 + cmd->se_ordered_id = atomic_inc_return_unchecked(&SE_DEV(cmd)->dev_ordered_id);
40471 smp_mb__after_atomic_inc();
40472 DEBUG_STA("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40473 cmd->se_ordered_id, cmd->sam_task_attr,
40474 @@ -2169,7 +2169,7 @@ static void transport_generic_request_fa
40475 " t_transport_active: %d t_transport_stop: %d"
40476 " t_transport_sent: %d\n", T_TASK(cmd)->t_task_cdbs,
40477 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40478 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40479 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40480 atomic_read(&T_TASK(cmd)->t_task_cdbs_ex_left),
40481 atomic_read(&T_TASK(cmd)->t_transport_active),
40482 atomic_read(&T_TASK(cmd)->t_transport_stop),
40483 @@ -2673,9 +2673,9 @@ check_depth:
40484 spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
40485 atomic_set(&task->task_active, 1);
40486 atomic_set(&task->task_sent, 1);
40487 - atomic_inc(&T_TASK(cmd)->t_task_cdbs_sent);
40488 + atomic_inc_unchecked(&T_TASK(cmd)->t_task_cdbs_sent);
40489
40490 - if (atomic_read(&T_TASK(cmd)->t_task_cdbs_sent) ==
40491 + if (atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent) ==
40492 T_TASK(cmd)->t_task_cdbs)
40493 atomic_set(&cmd->transport_sent, 1);
40494
40495 @@ -5568,7 +5568,7 @@ static void transport_generic_wait_for_t
40496 atomic_set(&T_TASK(cmd)->transport_lun_stop, 0);
40497 }
40498 if (!atomic_read(&T_TASK(cmd)->t_transport_active) ||
40499 - atomic_read(&T_TASK(cmd)->t_transport_aborted))
40500 + atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted))
40501 goto remove;
40502
40503 atomic_set(&T_TASK(cmd)->t_transport_stop, 1);
40504 @@ -5797,7 +5797,7 @@ int transport_check_aborted_status(struc
40505 {
40506 int ret = 0;
40507
40508 - if (atomic_read(&T_TASK(cmd)->t_transport_aborted) != 0) {
40509 + if (atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted) != 0) {
40510 if (!(send_status) ||
40511 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
40512 return 1;
40513 @@ -5825,7 +5825,7 @@ void transport_send_task_abort(struct se
40514 */
40515 if (cmd->data_direction == DMA_TO_DEVICE) {
40516 if (CMD_TFO(cmd)->write_pending_status(cmd) != 0) {
40517 - atomic_inc(&T_TASK(cmd)->t_transport_aborted);
40518 + atomic_inc_unchecked(&T_TASK(cmd)->t_transport_aborted);
40519 smp_mb__after_atomic_inc();
40520 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
40521 transport_new_cmd_failure(cmd);
40522 @@ -5949,7 +5949,7 @@ static void transport_processing_shutdow
40523 CMD_TFO(cmd)->get_task_tag(cmd),
40524 T_TASK(cmd)->t_task_cdbs,
40525 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40526 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40527 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40528 atomic_read(&T_TASK(cmd)->t_transport_active),
40529 atomic_read(&T_TASK(cmd)->t_transport_stop),
40530 atomic_read(&T_TASK(cmd)->t_transport_sent));
40531 diff -urNp linux-2.6.39.1/drivers/telephony/ixj.c linux-2.6.39.1/drivers/telephony/ixj.c
40532 --- linux-2.6.39.1/drivers/telephony/ixj.c 2011-05-19 00:06:34.000000000 -0400
40533 +++ linux-2.6.39.1/drivers/telephony/ixj.c 2011-05-22 19:36:32.000000000 -0400
40534 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
40535 bool mContinue;
40536 char *pIn, *pOut;
40537
40538 + pax_track_stack();
40539 +
40540 if (!SCI_Prepare(j))
40541 return 0;
40542
40543 diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_console.h linux-2.6.39.1/drivers/tty/hvc/hvc_console.h
40544 --- linux-2.6.39.1/drivers/tty/hvc/hvc_console.h 2011-05-19 00:06:34.000000000 -0400
40545 +++ linux-2.6.39.1/drivers/tty/hvc/hvc_console.h 2011-05-22 19:36:32.000000000 -0400
40546 @@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
40547 /* register a vterm for hvc tty operation (module_init or hotplug add) */
40548 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
40549 const struct hv_ops *ops, int outbuf_size);
40550 +
40551 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
40552 extern int hvc_remove(struct hvc_struct *hp);
40553
40554 diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c
40555 --- linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c 2011-05-19 00:06:34.000000000 -0400
40556 +++ linux-2.6.39.1/drivers/tty/hvc/hvc_iucv.c 2011-05-22 19:36:32.000000000 -0400
40557 @@ -1203,7 +1203,7 @@ static int param_get_vmidfilter(char *bu
40558
40559 #define param_check_vmidfilter(name, p) __param_check(name, p, void)
40560
40561 -static struct kernel_param_ops param_ops_vmidfilter = {
40562 +static const struct kernel_param_ops param_ops_vmidfilter = {
40563 .set = param_set_vmidfilter,
40564 .get = param_get_vmidfilter,
40565 };
40566 diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvcs.c linux-2.6.39.1/drivers/tty/hvc/hvcs.c
40567 --- linux-2.6.39.1/drivers/tty/hvc/hvcs.c 2011-05-19 00:06:34.000000000 -0400
40568 +++ linux-2.6.39.1/drivers/tty/hvc/hvcs.c 2011-05-22 19:36:32.000000000 -0400
40569 @@ -83,6 +83,7 @@
40570 #include <asm/hvcserver.h>
40571 #include <asm/uaccess.h>
40572 #include <asm/vio.h>
40573 +#include <asm/local.h>
40574
40575 /*
40576 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40577 @@ -270,7 +271,7 @@ struct hvcs_struct {
40578 unsigned int index;
40579
40580 struct tty_struct *tty;
40581 - int open_count;
40582 + local_t open_count;
40583
40584 /*
40585 * Used to tell the driver kernel_thread what operations need to take
40586 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(st
40587
40588 spin_lock_irqsave(&hvcsd->lock, flags);
40589
40590 - if (hvcsd->open_count > 0) {
40591 + if (local_read(&hvcsd->open_count) > 0) {
40592 spin_unlock_irqrestore(&hvcsd->lock, flags);
40593 printk(KERN_INFO "HVCS: vterm state unchanged. "
40594 "The hvcs device node is still in use.\n");
40595 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *
40596 if ((retval = hvcs_partner_connect(hvcsd)))
40597 goto error_release;
40598
40599 - hvcsd->open_count = 1;
40600 + local_set(&hvcsd->open_count, 1);
40601 hvcsd->tty = tty;
40602 tty->driver_data = hvcsd;
40603
40604 @@ -1179,7 +1180,7 @@ fast_open:
40605
40606 spin_lock_irqsave(&hvcsd->lock, flags);
40607 kref_get(&hvcsd->kref);
40608 - hvcsd->open_count++;
40609 + local_inc(&hvcsd->open_count);
40610 hvcsd->todo_mask |= HVCS_SCHED_READ;
40611 spin_unlock_irqrestore(&hvcsd->lock, flags);
40612
40613 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct
40614 hvcsd = tty->driver_data;
40615
40616 spin_lock_irqsave(&hvcsd->lock, flags);
40617 - if (--hvcsd->open_count == 0) {
40618 + if (local_dec_and_test(&hvcsd->open_count)) {
40619
40620 vio_disable_interrupts(hvcsd->vdev);
40621
40622 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct
40623 free_irq(irq, hvcsd);
40624 kref_put(&hvcsd->kref, destroy_hvcs_struct);
40625 return;
40626 - } else if (hvcsd->open_count < 0) {
40627 + } else if (local_read(&hvcsd->open_count) < 0) {
40628 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40629 " is missmanaged.\n",
40630 - hvcsd->vdev->unit_address, hvcsd->open_count);
40631 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
40632 }
40633
40634 spin_unlock_irqrestore(&hvcsd->lock, flags);
40635 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struc
40636
40637 spin_lock_irqsave(&hvcsd->lock, flags);
40638 /* Preserve this so that we know how many kref refs to put */
40639 - temp_open_count = hvcsd->open_count;
40640 + temp_open_count = local_read(&hvcsd->open_count);
40641
40642 /*
40643 * Don't kref put inside the spinlock because the destruction
40644 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struc
40645 hvcsd->tty->driver_data = NULL;
40646 hvcsd->tty = NULL;
40647
40648 - hvcsd->open_count = 0;
40649 + local_set(&hvcsd->open_count, 0);
40650
40651 /* This will drop any buffered data on the floor which is OK in a hangup
40652 * scenario. */
40653 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct
40654 * the middle of a write operation? This is a crummy place to do this
40655 * but we want to keep it all in the spinlock.
40656 */
40657 - if (hvcsd->open_count <= 0) {
40658 + if (local_read(&hvcsd->open_count) <= 0) {
40659 spin_unlock_irqrestore(&hvcsd->lock, flags);
40660 return -ENODEV;
40661 }
40662 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_st
40663 {
40664 struct hvcs_struct *hvcsd = tty->driver_data;
40665
40666 - if (!hvcsd || hvcsd->open_count <= 0)
40667 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
40668 return 0;
40669
40670 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40671 diff -urNp linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c
40672 --- linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c 2011-05-19 00:06:34.000000000 -0400
40673 +++ linux-2.6.39.1/drivers/tty/hvc/hvc_xen.c 2011-05-22 19:36:32.000000000 -0400
40674 @@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
40675 return recv;
40676 }
40677
40678 -static struct hv_ops domU_hvc_ops = {
40679 +static const struct hv_ops domU_hvc_ops = {
40680 .get_chars = domU_read_console,
40681 .put_chars = domU_write_console,
40682 .notifier_add = notifier_add_irq,
40683 @@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
40684 return len;
40685 }
40686
40687 -static struct hv_ops dom0_hvc_ops = {
40688 +static const struct hv_ops dom0_hvc_ops = {
40689 .get_chars = dom0_read_console,
40690 .put_chars = dom0_write_console,
40691 .notifier_add = notifier_add_irq,
40692 @@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
40693 static int __init xen_hvc_init(void)
40694 {
40695 struct hvc_struct *hp;
40696 - struct hv_ops *ops;
40697 + const struct hv_ops *ops;
40698
40699 if (!xen_pv_domain())
40700 return -ENODEV;
40701 @@ -205,7 +205,7 @@ static void __exit xen_hvc_fini(void)
40702
40703 static int xen_cons_init(void)
40704 {
40705 - struct hv_ops *ops;
40706 + const struct hv_ops *ops;
40707
40708 if (!xen_pv_domain())
40709 return 0;
40710 diff -urNp linux-2.6.39.1/drivers/tty/ipwireless/tty.c linux-2.6.39.1/drivers/tty/ipwireless/tty.c
40711 --- linux-2.6.39.1/drivers/tty/ipwireless/tty.c 2011-05-19 00:06:34.000000000 -0400
40712 +++ linux-2.6.39.1/drivers/tty/ipwireless/tty.c 2011-05-22 19:36:32.000000000 -0400
40713 @@ -29,6 +29,7 @@
40714 #include <linux/tty_driver.h>
40715 #include <linux/tty_flip.h>
40716 #include <linux/uaccess.h>
40717 +#include <asm/local.h>
40718
40719 #include "tty.h"
40720 #include "network.h"
40721 @@ -51,7 +52,7 @@ struct ipw_tty {
40722 int tty_type;
40723 struct ipw_network *network;
40724 struct tty_struct *linux_tty;
40725 - int open_count;
40726 + local_t open_count;
40727 unsigned int control_lines;
40728 struct mutex ipw_tty_mutex;
40729 int tx_bytes_queued;
40730 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
40731 mutex_unlock(&tty->ipw_tty_mutex);
40732 return -ENODEV;
40733 }
40734 - if (tty->open_count == 0)
40735 + if (local_read(&tty->open_count) == 0)
40736 tty->tx_bytes_queued = 0;
40737
40738 - tty->open_count++;
40739 + local_inc(&tty->open_count);
40740
40741 tty->linux_tty = linux_tty;
40742 linux_tty->driver_data = tty;
40743 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
40744
40745 static void do_ipw_close(struct ipw_tty *tty)
40746 {
40747 - tty->open_count--;
40748 -
40749 - if (tty->open_count == 0) {
40750 + if (local_dec_return(&tty->open_count) == 0) {
40751 struct tty_struct *linux_tty = tty->linux_tty;
40752
40753 if (linux_tty != NULL) {
40754 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
40755 return;
40756
40757 mutex_lock(&tty->ipw_tty_mutex);
40758 - if (tty->open_count == 0) {
40759 + if (local_read(&tty->open_count) == 0) {
40760 mutex_unlock(&tty->ipw_tty_mutex);
40761 return;
40762 }
40763 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
40764 return;
40765 }
40766
40767 - if (!tty->open_count) {
40768 + if (!local_read(&tty->open_count)) {
40769 mutex_unlock(&tty->ipw_tty_mutex);
40770 return;
40771 }
40772 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
40773 return -ENODEV;
40774
40775 mutex_lock(&tty->ipw_tty_mutex);
40776 - if (!tty->open_count) {
40777 + if (!local_read(&tty->open_count)) {
40778 mutex_unlock(&tty->ipw_tty_mutex);
40779 return -EINVAL;
40780 }
40781 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
40782 if (!tty)
40783 return -ENODEV;
40784
40785 - if (!tty->open_count)
40786 + if (!local_read(&tty->open_count))
40787 return -EINVAL;
40788
40789 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40790 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
40791 if (!tty)
40792 return 0;
40793
40794 - if (!tty->open_count)
40795 + if (!local_read(&tty->open_count))
40796 return 0;
40797
40798 return tty->tx_bytes_queued;
40799 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
40800 if (!tty)
40801 return -ENODEV;
40802
40803 - if (!tty->open_count)
40804 + if (!local_read(&tty->open_count))
40805 return -EINVAL;
40806
40807 return get_control_lines(tty);
40808 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
40809 if (!tty)
40810 return -ENODEV;
40811
40812 - if (!tty->open_count)
40813 + if (!local_read(&tty->open_count))
40814 return -EINVAL;
40815
40816 return set_control_lines(tty, set, clear);
40817 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
40818 if (!tty)
40819 return -ENODEV;
40820
40821 - if (!tty->open_count)
40822 + if (!local_read(&tty->open_count))
40823 return -EINVAL;
40824
40825 /* FIXME: Exactly how is the tty object locked here .. */
40826 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty
40827 against a parallel ioctl etc */
40828 mutex_lock(&ttyj->ipw_tty_mutex);
40829 }
40830 - while (ttyj->open_count)
40831 + while (local_read(&ttyj->open_count))
40832 do_ipw_close(ttyj);
40833 ipwireless_disassociate_network_ttys(network,
40834 ttyj->channel_idx);
40835 diff -urNp linux-2.6.39.1/drivers/tty/mxser.c linux-2.6.39.1/drivers/tty/mxser.c
40836 --- linux-2.6.39.1/drivers/tty/mxser.c 2011-05-19 00:06:34.000000000 -0400
40837 +++ linux-2.6.39.1/drivers/tty/mxser.c 2011-05-22 19:36:32.000000000 -0400
40838 @@ -2340,7 +2340,7 @@ static const struct tty_operations mxser
40839 .get_icount = mxser_get_icount,
40840 };
40841
40842 -struct tty_port_operations mxser_port_ops = {
40843 +const struct tty_port_operations mxser_port_ops = {
40844 .carrier_raised = mxser_carrier_raised,
40845 .dtr_rts = mxser_dtr_rts,
40846 .activate = mxser_activate,
40847 diff -urNp linux-2.6.39.1/drivers/tty/n_gsm.c linux-2.6.39.1/drivers/tty/n_gsm.c
40848 --- linux-2.6.39.1/drivers/tty/n_gsm.c 2011-05-19 00:06:34.000000000 -0400
40849 +++ linux-2.6.39.1/drivers/tty/n_gsm.c 2011-05-22 19:36:32.000000000 -0400
40850 @@ -1588,7 +1588,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
40851 return NULL;
40852 spin_lock_init(&dlci->lock);
40853 dlci->fifo = &dlci->_fifo;
40854 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40855 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40856 kfree(dlci);
40857 return NULL;
40858 }
40859 diff -urNp linux-2.6.39.1/drivers/tty/n_tty.c linux-2.6.39.1/drivers/tty/n_tty.c
40860 --- linux-2.6.39.1/drivers/tty/n_tty.c 2011-05-19 00:06:34.000000000 -0400
40861 +++ linux-2.6.39.1/drivers/tty/n_tty.c 2011-05-22 19:36:32.000000000 -0400
40862 @@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
40863 {
40864 *ops = tty_ldisc_N_TTY;
40865 ops->owner = NULL;
40866 - ops->refcount = ops->flags = 0;
40867 + atomic_set(&ops->refcount, 0);
40868 + ops->flags = 0;
40869 }
40870 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40871 diff -urNp linux-2.6.39.1/drivers/tty/pty.c linux-2.6.39.1/drivers/tty/pty.c
40872 --- linux-2.6.39.1/drivers/tty/pty.c 2011-05-19 00:06:34.000000000 -0400
40873 +++ linux-2.6.39.1/drivers/tty/pty.c 2011-05-22 19:36:32.000000000 -0400
40874 @@ -699,7 +699,18 @@ out:
40875 return retval;
40876 }
40877
40878 -static struct file_operations ptmx_fops;
40879 +static const struct file_operations ptmx_fops = {
40880 + .llseek = no_llseek,
40881 + .read = tty_read,
40882 + .write = tty_write,
40883 + .poll = tty_poll,
40884 + .unlocked_ioctl = tty_ioctl,
40885 + .compat_ioctl = tty_compat_ioctl,
40886 + .open = ptmx_open,
40887 + .release = tty_release,
40888 + .fasync = tty_fasync,
40889 +};
40890 +
40891
40892 static void __init unix98_pty_init(void)
40893 {
40894 @@ -752,10 +763,6 @@ static void __init unix98_pty_init(void)
40895
40896 register_sysctl_table(pty_root_table);
40897
40898 - /* Now create the /dev/ptmx special device */
40899 - tty_default_fops(&ptmx_fops);
40900 - ptmx_fops.open = ptmx_open;
40901 -
40902 cdev_init(&ptmx_cdev, &ptmx_fops);
40903 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40904 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
40905 diff -urNp linux-2.6.39.1/drivers/tty/rocket.c linux-2.6.39.1/drivers/tty/rocket.c
40906 --- linux-2.6.39.1/drivers/tty/rocket.c 2011-05-19 00:06:34.000000000 -0400
40907 +++ linux-2.6.39.1/drivers/tty/rocket.c 2011-05-22 19:36:32.000000000 -0400
40908 @@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info
40909 struct rocket_ports tmp;
40910 int board;
40911
40912 + pax_track_stack();
40913 +
40914 if (!retports)
40915 return -EFAULT;
40916 memset(&tmp, 0, sizeof (tmp));
40917 diff -urNp linux-2.6.39.1/drivers/tty/serial/21285.c linux-2.6.39.1/drivers/tty/serial/21285.c
40918 --- linux-2.6.39.1/drivers/tty/serial/21285.c 2011-05-19 00:06:34.000000000 -0400
40919 +++ linux-2.6.39.1/drivers/tty/serial/21285.c 2011-05-22 19:36:32.000000000 -0400
40920 @@ -340,7 +340,7 @@ static int serial21285_verify_port(struc
40921 return ret;
40922 }
40923
40924 -static struct uart_ops serial21285_ops = {
40925 +static const struct uart_ops serial21285_ops = {
40926 .tx_empty = serial21285_tx_empty,
40927 .get_mctrl = serial21285_get_mctrl,
40928 .set_mctrl = serial21285_set_mctrl,
40929 diff -urNp linux-2.6.39.1/drivers/tty/serial/8250.c linux-2.6.39.1/drivers/tty/serial/8250.c
40930 --- linux-2.6.39.1/drivers/tty/serial/8250.c 2011-05-19 00:06:34.000000000 -0400
40931 +++ linux-2.6.39.1/drivers/tty/serial/8250.c 2011-05-22 19:36:32.000000000 -0400
40932 @@ -2708,7 +2708,7 @@ serial8250_type(struct uart_port *port)
40933 return uart_config[type].name;
40934 }
40935
40936 -static struct uart_ops serial8250_pops = {
40937 +static const struct uart_ops serial8250_pops = {
40938 .tx_empty = serial8250_tx_empty,
40939 .set_mctrl = serial8250_set_mctrl,
40940 .get_mctrl = serial8250_get_mctrl,
40941 diff -urNp linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c
40942 --- linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c 2011-05-19 00:06:34.000000000 -0400
40943 +++ linux-2.6.39.1/drivers/tty/serial/altera_jtaguart.c 2011-05-22 19:36:32.000000000 -0400
40944 @@ -281,7 +281,7 @@ static int altera_jtaguart_verify_port(s
40945 /*
40946 * Define the basic serial functions we support.
40947 */
40948 -static struct uart_ops altera_jtaguart_ops = {
40949 +static const struct uart_ops altera_jtaguart_ops = {
40950 .tx_empty = altera_jtaguart_tx_empty,
40951 .get_mctrl = altera_jtaguart_get_mctrl,
40952 .set_mctrl = altera_jtaguart_set_mctrl,
40953 diff -urNp linux-2.6.39.1/drivers/tty/serial/altera_uart.c linux-2.6.39.1/drivers/tty/serial/altera_uart.c
40954 --- linux-2.6.39.1/drivers/tty/serial/altera_uart.c 2011-05-19 00:06:34.000000000 -0400
40955 +++ linux-2.6.39.1/drivers/tty/serial/altera_uart.c 2011-05-22 19:36:32.000000000 -0400
40956 @@ -380,7 +380,7 @@ static int altera_uart_verify_port(struc
40957 /*
40958 * Define the basic serial functions we support.
40959 */
40960 -static struct uart_ops altera_uart_ops = {
40961 +static const struct uart_ops altera_uart_ops = {
40962 .tx_empty = altera_uart_tx_empty,
40963 .get_mctrl = altera_uart_get_mctrl,
40964 .set_mctrl = altera_uart_set_mctrl,
40965 diff -urNp linux-2.6.39.1/drivers/tty/serial/amba-pl010.c linux-2.6.39.1/drivers/tty/serial/amba-pl010.c
40966 --- linux-2.6.39.1/drivers/tty/serial/amba-pl010.c 2011-05-19 00:06:34.000000000 -0400
40967 +++ linux-2.6.39.1/drivers/tty/serial/amba-pl010.c 2011-05-22 19:36:32.000000000 -0400
40968 @@ -529,7 +529,7 @@ static int pl010_verify_port(struct uart
40969 return ret;
40970 }
40971
40972 -static struct uart_ops amba_pl010_pops = {
40973 +static const struct uart_ops amba_pl010_pops = {
40974 .tx_empty = pl010_tx_empty,
40975 .set_mctrl = pl010_set_mctrl,
40976 .get_mctrl = pl010_get_mctrl,
40977 diff -urNp linux-2.6.39.1/drivers/tty/serial/amba-pl011.c linux-2.6.39.1/drivers/tty/serial/amba-pl011.c
40978 --- linux-2.6.39.1/drivers/tty/serial/amba-pl011.c 2011-05-19 00:06:34.000000000 -0400
40979 +++ linux-2.6.39.1/drivers/tty/serial/amba-pl011.c 2011-05-22 19:36:32.000000000 -0400
40980 @@ -1581,7 +1581,7 @@ static int pl010_verify_port(struct uart
40981 return ret;
40982 }
40983
40984 -static struct uart_ops amba_pl011_pops = {
40985 +static const struct uart_ops amba_pl011_pops = {
40986 .tx_empty = pl01x_tx_empty,
40987 .set_mctrl = pl011_set_mctrl,
40988 .get_mctrl = pl01x_get_mctrl,
40989 diff -urNp linux-2.6.39.1/drivers/tty/serial/apbuart.c linux-2.6.39.1/drivers/tty/serial/apbuart.c
40990 --- linux-2.6.39.1/drivers/tty/serial/apbuart.c 2011-05-19 00:06:34.000000000 -0400
40991 +++ linux-2.6.39.1/drivers/tty/serial/apbuart.c 2011-05-22 19:36:32.000000000 -0400
40992 @@ -328,7 +328,7 @@ static int apbuart_verify_port(struct ua
40993 return ret;
40994 }
40995
40996 -static struct uart_ops grlib_apbuart_ops = {
40997 +static const struct uart_ops grlib_apbuart_ops = {
40998 .tx_empty = apbuart_tx_empty,
40999 .set_mctrl = apbuart_set_mctrl,
41000 .get_mctrl = apbuart_get_mctrl,
41001 diff -urNp linux-2.6.39.1/drivers/tty/serial/atmel_serial.c linux-2.6.39.1/drivers/tty/serial/atmel_serial.c
41002 --- linux-2.6.39.1/drivers/tty/serial/atmel_serial.c 2011-05-19 00:06:34.000000000 -0400
41003 +++ linux-2.6.39.1/drivers/tty/serial/atmel_serial.c 2011-05-22 19:36:32.000000000 -0400
41004 @@ -1382,7 +1382,7 @@ atmel_ioctl(struct uart_port *port, unsi
41005
41006
41007
41008 -static struct uart_ops atmel_pops = {
41009 +static const struct uart_ops atmel_pops = {
41010 .tx_empty = atmel_tx_empty,
41011 .set_mctrl = atmel_set_mctrl,
41012 .get_mctrl = atmel_get_mctrl,
41013 diff -urNp linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c
41014 --- linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41015 +++ linux-2.6.39.1/drivers/tty/serial/bcm63xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41016 @@ -636,7 +636,7 @@ static int bcm_uart_verify_port(struct u
41017 }
41018
41019 /* serial core callbacks */
41020 -static struct uart_ops bcm_uart_ops = {
41021 +static const struct uart_ops bcm_uart_ops = {
41022 .tx_empty = bcm_uart_tx_empty,
41023 .get_mctrl = bcm_uart_get_mctrl,
41024 .set_mctrl = bcm_uart_set_mctrl,
41025 diff -urNp linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c
41026 --- linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c 2011-05-19 00:06:34.000000000 -0400
41027 +++ linux-2.6.39.1/drivers/tty/serial/bfin_5xx.c 2011-05-22 19:36:32.000000000 -0400
41028 @@ -1036,7 +1036,7 @@ static int bfin_kgdboc_port_startup(stru
41029 }
41030 #endif
41031
41032 -static struct uart_ops bfin_serial_pops = {
41033 +static const struct uart_ops bfin_serial_pops = {
41034 .tx_empty = bfin_serial_tx_empty,
41035 .set_mctrl = bfin_serial_set_mctrl,
41036 .get_mctrl = bfin_serial_get_mctrl,
41037 diff -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
41038 --- linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c 2011-05-19 00:06:34.000000000 -0400
41039 +++ linux-2.6.39.1/drivers/tty/serial/bfin_sport_uart.c 2011-05-22 19:36:32.000000000 -0400
41040 @@ -571,7 +571,7 @@ static void sport_set_termios(struct uar
41041 spin_unlock_irqrestore(&up->port.lock, flags);
41042 }
41043
41044 -struct uart_ops sport_uart_ops = {
41045 +const struct uart_ops sport_uart_ops = {
41046 .tx_empty = sport_tx_empty,
41047 .set_mctrl = sport_set_mctrl,
41048 .get_mctrl = sport_get_mctrl,
41049 diff -urNp linux-2.6.39.1/drivers/tty/serial/clps711x.c linux-2.6.39.1/drivers/tty/serial/clps711x.c
41050 --- linux-2.6.39.1/drivers/tty/serial/clps711x.c 2011-05-19 00:06:34.000000000 -0400
41051 +++ linux-2.6.39.1/drivers/tty/serial/clps711x.c 2011-05-22 19:36:32.000000000 -0400
41052 @@ -380,7 +380,7 @@ static int clps711xuart_request_port(str
41053 return 0;
41054 }
41055
41056 -static struct uart_ops clps711x_pops = {
41057 +static const struct uart_ops clps711x_pops = {
41058 .tx_empty = clps711xuart_tx_empty,
41059 .set_mctrl = clps711xuart_set_mctrl_null,
41060 .get_mctrl = clps711xuart_get_mctrl,
41061 diff -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
41062 --- linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-19 00:06:34.000000000 -0400
41063 +++ linux-2.6.39.1/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-22 19:36:32.000000000 -0400
41064 @@ -1099,7 +1099,7 @@ static void cpm_put_poll_char(struct uar
41065 }
41066 #endif /* CONFIG_CONSOLE_POLL */
41067
41068 -static struct uart_ops cpm_uart_pops = {
41069 +static const struct uart_ops cpm_uart_pops = {
41070 .tx_empty = cpm_uart_tx_empty,
41071 .set_mctrl = cpm_uart_set_mctrl,
41072 .get_mctrl = cpm_uart_get_mctrl,
41073 diff -urNp linux-2.6.39.1/drivers/tty/serial/dz.c linux-2.6.39.1/drivers/tty/serial/dz.c
41074 --- linux-2.6.39.1/drivers/tty/serial/dz.c 2011-05-19 00:06:34.000000000 -0400
41075 +++ linux-2.6.39.1/drivers/tty/serial/dz.c 2011-05-22 19:36:32.000000000 -0400
41076 @@ -746,7 +746,7 @@ static int dz_verify_port(struct uart_po
41077 return ret;
41078 }
41079
41080 -static struct uart_ops dz_ops = {
41081 +static const struct uart_ops dz_ops = {
41082 .tx_empty = dz_tx_empty,
41083 .get_mctrl = dz_get_mctrl,
41084 .set_mctrl = dz_set_mctrl,
41085 diff -urNp linux-2.6.39.1/drivers/tty/serial/imx.c linux-2.6.39.1/drivers/tty/serial/imx.c
41086 --- linux-2.6.39.1/drivers/tty/serial/imx.c 2011-05-19 00:06:34.000000000 -0400
41087 +++ linux-2.6.39.1/drivers/tty/serial/imx.c 2011-05-22 19:36:32.000000000 -0400
41088 @@ -1018,7 +1018,7 @@ imx_verify_port(struct uart_port *port,
41089 return ret;
41090 }
41091
41092 -static struct uart_ops imx_pops = {
41093 +static const struct uart_ops imx_pops = {
41094 .tx_empty = imx_tx_empty,
41095 .set_mctrl = imx_set_mctrl,
41096 .get_mctrl = imx_get_mctrl,
41097 diff -urNp linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c
41098 --- linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c 2011-05-19 00:06:34.000000000 -0400
41099 +++ linux-2.6.39.1/drivers/tty/serial/ioc3_serial.c 2011-05-22 19:36:32.000000000 -0400
41100 @@ -1874,7 +1874,7 @@ static int ic3_request_port(struct uart_
41101 }
41102
41103 /* Associate the uart functions above - given to serial core */
41104 -static struct uart_ops ioc3_ops = {
41105 +static const struct uart_ops ioc3_ops = {
41106 .tx_empty = ic3_tx_empty,
41107 .set_mctrl = ic3_set_mctrl,
41108 .get_mctrl = ic3_get_mctrl,
41109 diff -urNp linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c
41110 --- linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c 2011-05-19 00:06:34.000000000 -0400
41111 +++ linux-2.6.39.1/drivers/tty/serial/ioc4_serial.c 2011-05-22 19:36:32.000000000 -0400
41112 @@ -2593,7 +2593,7 @@ static int ic4_request_port(struct uart_
41113
41114 /* Associate the uart functions above - given to serial core */
41115
41116 -static struct uart_ops ioc4_ops = {
41117 +static const struct uart_ops ioc4_ops = {
41118 .tx_empty = ic4_tx_empty,
41119 .set_mctrl = ic4_set_mctrl,
41120 .get_mctrl = ic4_get_mctrl,
41121 diff -urNp linux-2.6.39.1/drivers/tty/serial/ip22zilog.c linux-2.6.39.1/drivers/tty/serial/ip22zilog.c
41122 --- linux-2.6.39.1/drivers/tty/serial/ip22zilog.c 2011-05-19 00:06:34.000000000 -0400
41123 +++ linux-2.6.39.1/drivers/tty/serial/ip22zilog.c 2011-05-22 19:36:32.000000000 -0400
41124 @@ -928,7 +928,7 @@ static int ip22zilog_verify_port(struct
41125 return -EINVAL;
41126 }
41127
41128 -static struct uart_ops ip22zilog_pops = {
41129 +static const struct uart_ops ip22zilog_pops = {
41130 .tx_empty = ip22zilog_tx_empty,
41131 .set_mctrl = ip22zilog_set_mctrl,
41132 .get_mctrl = ip22zilog_get_mctrl,
41133 diff -urNp linux-2.6.39.1/drivers/tty/serial/kgdboc.c linux-2.6.39.1/drivers/tty/serial/kgdboc.c
41134 --- linux-2.6.39.1/drivers/tty/serial/kgdboc.c 2011-05-19 00:06:34.000000000 -0400
41135 +++ linux-2.6.39.1/drivers/tty/serial/kgdboc.c 2011-05-22 19:36:32.000000000 -0400
41136 @@ -22,7 +22,7 @@
41137
41138 #define MAX_CONFIG_LEN 40
41139
41140 -static struct kgdb_io kgdboc_io_ops;
41141 +static struct kgdb_io kgdboc_io_ops; /* cannot be const, see configure_kgdboc() */
41142
41143 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41144 static int configured = -1;
41145 @@ -293,7 +293,7 @@ static void kgdboc_post_exp_handler(void
41146 kgdboc_restore_input();
41147 }
41148
41149 -static struct kgdb_io kgdboc_io_ops = {
41150 +static struct kgdb_io kgdboc_io_ops = { /* cannot be const, see configure_kgdboc() */
41151 .name = "kgdboc",
41152 .read_char = kgdboc_get_char,
41153 .write_char = kgdboc_put_char,
41154 diff -urNp linux-2.6.39.1/drivers/tty/serial/m32r_sio.c linux-2.6.39.1/drivers/tty/serial/m32r_sio.c
41155 --- linux-2.6.39.1/drivers/tty/serial/m32r_sio.c 2011-05-19 00:06:34.000000000 -0400
41156 +++ linux-2.6.39.1/drivers/tty/serial/m32r_sio.c 2011-05-22 19:36:32.000000000 -0400
41157 @@ -939,7 +939,7 @@ m32r_sio_type(struct uart_port *port)
41158 return uart_config[type].name;
41159 }
41160
41161 -static struct uart_ops m32r_sio_pops = {
41162 +static const struct uart_ops m32r_sio_pops = {
41163 .tx_empty = m32r_sio_tx_empty,
41164 .set_mctrl = m32r_sio_set_mctrl,
41165 .get_mctrl = m32r_sio_get_mctrl,
41166 diff -urNp linux-2.6.39.1/drivers/tty/serial/max3100.c linux-2.6.39.1/drivers/tty/serial/max3100.c
41167 --- linux-2.6.39.1/drivers/tty/serial/max3100.c 2011-05-19 00:06:34.000000000 -0400
41168 +++ linux-2.6.39.1/drivers/tty/serial/max3100.c 2011-05-22 19:36:32.000000000 -0400
41169 @@ -710,7 +710,7 @@ static void max3100_break_ctl(struct uar
41170 dev_dbg(&s->spi->dev, "%s\n", __func__);
41171 }
41172
41173 -static struct uart_ops max3100_ops = {
41174 +static const struct uart_ops max3100_ops = {
41175 .tx_empty = max3100_tx_empty,
41176 .set_mctrl = max3100_set_mctrl,
41177 .get_mctrl = max3100_get_mctrl,
41178 diff -urNp linux-2.6.39.1/drivers/tty/serial/max3107.c linux-2.6.39.1/drivers/tty/serial/max3107.c
41179 --- linux-2.6.39.1/drivers/tty/serial/max3107.c 2011-05-19 00:06:34.000000000 -0400
41180 +++ linux-2.6.39.1/drivers/tty/serial/max3107.c 2011-05-22 19:36:32.000000000 -0400
41181 @@ -910,7 +910,7 @@ static void max3107_break_ctl(struct uar
41182
41183
41184 /* Port functions */
41185 -static struct uart_ops max3107_ops = {
41186 +static const struct uart_ops max3107_ops = {
41187 .tx_empty = max3107_tx_empty,
41188 .set_mctrl = max3107_set_mctrl,
41189 .get_mctrl = max3107_get_mctrl,
41190 diff -urNp linux-2.6.39.1/drivers/tty/serial/mfd.c linux-2.6.39.1/drivers/tty/serial/mfd.c
41191 --- linux-2.6.39.1/drivers/tty/serial/mfd.c 2011-05-19 00:06:34.000000000 -0400
41192 +++ linux-2.6.39.1/drivers/tty/serial/mfd.c 2011-05-22 19:36:32.000000000 -0400
41193 @@ -1178,7 +1178,7 @@ static struct console serial_hsu_console
41194 };
41195 #endif
41196
41197 -struct uart_ops serial_hsu_pops = {
41198 +const struct uart_ops serial_hsu_pops = {
41199 .tx_empty = serial_hsu_tx_empty,
41200 .set_mctrl = serial_hsu_set_mctrl,
41201 .get_mctrl = serial_hsu_get_mctrl,
41202 diff -urNp linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c
41203 --- linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41204 +++ linux-2.6.39.1/drivers/tty/serial/mpc52xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41205 @@ -283,7 +283,7 @@ static irqreturn_t mpc52xx_psc_handle_ir
41206 return mpc5xxx_uart_process_int(port);
41207 }
41208
41209 -static struct psc_ops mpc52xx_psc_ops = {
41210 +static const struct psc_ops mpc52xx_psc_ops = {
41211 .fifo_init = mpc52xx_psc_fifo_init,
41212 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41213 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41214 @@ -304,7 +304,7 @@ static struct psc_ops mpc52xx_psc_ops =
41215 .handle_irq = mpc52xx_psc_handle_irq,
41216 };
41217
41218 -static struct psc_ops mpc5200b_psc_ops = {
41219 +static const struct psc_ops mpc5200b_psc_ops = {
41220 .fifo_init = mpc52xx_psc_fifo_init,
41221 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41222 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41223 @@ -571,7 +571,7 @@ static void mpc512x_psc_get_irq(struct u
41224 port->irq = psc_fifoc_irq;
41225 }
41226
41227 -static struct psc_ops mpc512x_psc_ops = {
41228 +static const struct psc_ops mpc512x_psc_ops = {
41229 .fifo_init = mpc512x_psc_fifo_init,
41230 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
41231 .raw_tx_rdy = mpc512x_psc_raw_tx_rdy,
41232 @@ -596,7 +596,7 @@ static struct psc_ops mpc512x_psc_ops =
41233 };
41234 #endif
41235
41236 -static struct psc_ops *psc_ops;
41237 +static const struct psc_ops *psc_ops;
41238
41239 /* ======================================================================== */
41240 /* UART operations */
41241 @@ -905,7 +905,7 @@ mpc52xx_uart_verify_port(struct uart_por
41242 }
41243
41244
41245 -static struct uart_ops mpc52xx_uart_ops = {
41246 +static const struct uart_ops mpc52xx_uart_ops = {
41247 .tx_empty = mpc52xx_uart_tx_empty,
41248 .set_mctrl = mpc52xx_uart_set_mctrl,
41249 .get_mctrl = mpc52xx_uart_get_mctrl,
41250 diff -urNp linux-2.6.39.1/drivers/tty/serial/mpsc.c linux-2.6.39.1/drivers/tty/serial/mpsc.c
41251 --- linux-2.6.39.1/drivers/tty/serial/mpsc.c 2011-05-19 00:06:34.000000000 -0400
41252 +++ linux-2.6.39.1/drivers/tty/serial/mpsc.c 2011-05-22 19:36:32.000000000 -0400
41253 @@ -1663,7 +1663,7 @@ static void mpsc_put_poll_char(struct ua
41254 }
41255 #endif
41256
41257 -static struct uart_ops mpsc_pops = {
41258 +static const struct uart_ops mpsc_pops = {
41259 .tx_empty = mpsc_tx_empty,
41260 .set_mctrl = mpsc_set_mctrl,
41261 .get_mctrl = mpsc_get_mctrl,
41262 diff -urNp linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c
41263 --- linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c 2011-05-19 00:06:34.000000000 -0400
41264 +++ linux-2.6.39.1/drivers/tty/serial/mrst_max3110.c 2011-05-22 19:36:32.000000000 -0400
41265 @@ -393,6 +393,8 @@ static void max3110_con_receive(struct u
41266 int loop = 1, num, total = 0;
41267 u8 recv_buf[512], *pbuf;
41268
41269 + pax_track_stack();
41270 +
41271 pbuf = recv_buf;
41272 do {
41273 num = max3110_read_multi(max, pbuf);
41274 @@ -726,7 +728,7 @@ static void serial_m3110_enable_ms(struc
41275 {
41276 }
41277
41278 -struct uart_ops serial_m3110_ops = {
41279 +const struct uart_ops serial_m3110_ops = {
41280 .tx_empty = serial_m3110_tx_empty,
41281 .set_mctrl = serial_m3110_set_mctrl,
41282 .get_mctrl = serial_m3110_get_mctrl,
41283 diff -urNp linux-2.6.39.1/drivers/tty/serial/msm_serial.c linux-2.6.39.1/drivers/tty/serial/msm_serial.c
41284 --- linux-2.6.39.1/drivers/tty/serial/msm_serial.c 2011-05-19 00:06:34.000000000 -0400
41285 +++ linux-2.6.39.1/drivers/tty/serial/msm_serial.c 2011-05-22 19:36:32.000000000 -0400
41286 @@ -702,7 +702,7 @@ static void msm_power(struct uart_port *
41287 }
41288 }
41289
41290 -static struct uart_ops msm_uart_pops = {
41291 +static const struct uart_ops msm_uart_pops = {
41292 .tx_empty = msm_tx_empty,
41293 .set_mctrl = msm_set_mctrl,
41294 .get_mctrl = msm_get_mctrl,
41295 diff -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
41296 --- linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c 2011-05-19 00:06:34.000000000 -0400
41297 +++ linux-2.6.39.1/drivers/tty/serial/msm_serial_hs.c 2011-05-22 19:36:32.000000000 -0400
41298 @@ -360,7 +360,7 @@ struct msm_hs_port {
41299 static struct msm_hs_port q_uart_port[UARTDM_NR];
41300 static struct platform_driver msm_serial_hs_platform_driver;
41301 static struct uart_driver msm_hs_driver;
41302 -static struct uart_ops msm_hs_ops;
41303 +static const struct uart_ops msm_hs_ops;
41304 static struct workqueue_struct *msm_hs_workqueue;
41305
41306 #define UARTDM_TO_MSM(uart_port) \
41307 @@ -1856,7 +1856,7 @@ static struct uart_driver msm_hs_driver
41308 .cons = 0,
41309 };
41310
41311 -static struct uart_ops msm_hs_ops = {
41312 +static const struct uart_ops msm_hs_ops = {
41313 .tx_empty = msm_hs_tx_empty,
41314 .set_mctrl = msm_hs_set_mctrl_locked,
41315 .get_mctrl = msm_hs_get_mctrl_locked,
41316 diff -urNp linux-2.6.39.1/drivers/tty/serial/mux.c linux-2.6.39.1/drivers/tty/serial/mux.c
41317 --- linux-2.6.39.1/drivers/tty/serial/mux.c 2011-05-19 00:06:34.000000000 -0400
41318 +++ linux-2.6.39.1/drivers/tty/serial/mux.c 2011-05-22 19:36:32.000000000 -0400
41319 @@ -442,7 +442,7 @@ static struct console mux_console = {
41320 #define MUX_CONSOLE NULL
41321 #endif
41322
41323 -static struct uart_ops mux_pops = {
41324 +static const struct uart_ops mux_pops = {
41325 .tx_empty = mux_tx_empty,
41326 .set_mctrl = mux_set_mctrl,
41327 .get_mctrl = mux_get_mctrl,
41328 diff -urNp linux-2.6.39.1/drivers/tty/serial/mxs-auart.c linux-2.6.39.1/drivers/tty/serial/mxs-auart.c
41329 --- linux-2.6.39.1/drivers/tty/serial/mxs-auart.c 2011-05-19 00:06:34.000000000 -0400
41330 +++ linux-2.6.39.1/drivers/tty/serial/mxs-auart.c 2011-05-22 19:36:32.000000000 -0400
41331 @@ -499,7 +499,7 @@ static void mxs_auart_enable_ms(struct u
41332 /* just empty */
41333 }
41334
41335 -static struct uart_ops mxs_auart_ops = {
41336 +static const struct uart_ops mxs_auart_ops = {
41337 .tx_empty = mxs_auart_tx_empty,
41338 .start_tx = mxs_auart_start_tx,
41339 .stop_tx = mxs_auart_stop_tx,
41340 diff -urNp linux-2.6.39.1/drivers/tty/serial/netx-serial.c linux-2.6.39.1/drivers/tty/serial/netx-serial.c
41341 --- linux-2.6.39.1/drivers/tty/serial/netx-serial.c 2011-05-19 00:06:34.000000000 -0400
41342 +++ linux-2.6.39.1/drivers/tty/serial/netx-serial.c 2011-05-22 19:36:32.000000000 -0400
41343 @@ -464,7 +464,7 @@ netx_verify_port(struct uart_port *port,
41344 return ret;
41345 }
41346
41347 -static struct uart_ops netx_pops = {
41348 +static const struct uart_ops netx_pops = {
41349 .tx_empty = netx_tx_empty,
41350 .set_mctrl = netx_set_mctrl,
41351 .get_mctrl = netx_get_mctrl,
41352 diff -urNp linux-2.6.39.1/drivers/tty/serial/nwpserial.c linux-2.6.39.1/drivers/tty/serial/nwpserial.c
41353 --- linux-2.6.39.1/drivers/tty/serial/nwpserial.c 2011-05-19 00:06:34.000000000 -0400
41354 +++ linux-2.6.39.1/drivers/tty/serial/nwpserial.c 2011-05-22 19:36:32.000000000 -0400
41355 @@ -303,7 +303,7 @@ static unsigned int nwpserial_tx_empty(s
41356 return ret & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
41357 }
41358
41359 -static struct uart_ops nwpserial_pops = {
41360 +static const struct uart_ops nwpserial_pops = {
41361 .tx_empty = nwpserial_tx_empty,
41362 .set_mctrl = nwpserial_set_mctrl,
41363 .get_mctrl = nwpserial_get_mctrl,
41364 diff -urNp linux-2.6.39.1/drivers/tty/serial/omap-serial.c linux-2.6.39.1/drivers/tty/serial/omap-serial.c
41365 --- linux-2.6.39.1/drivers/tty/serial/omap-serial.c 2011-05-19 00:06:34.000000000 -0400
41366 +++ linux-2.6.39.1/drivers/tty/serial/omap-serial.c 2011-05-22 19:36:32.000000000 -0400
41367 @@ -1029,7 +1029,7 @@ static inline void serial_omap_add_conso
41368
41369 #endif
41370
41371 -static struct uart_ops serial_omap_pops = {
41372 +static const struct uart_ops serial_omap_pops = {
41373 .tx_empty = serial_omap_tx_empty,
41374 .set_mctrl = serial_omap_set_mctrl,
41375 .get_mctrl = serial_omap_get_mctrl,
41376 diff -urNp linux-2.6.39.1/drivers/tty/serial/pch_uart.c linux-2.6.39.1/drivers/tty/serial/pch_uart.c
41377 --- linux-2.6.39.1/drivers/tty/serial/pch_uart.c 2011-05-19 00:06:34.000000000 -0400
41378 +++ linux-2.6.39.1/drivers/tty/serial/pch_uart.c 2011-05-22 19:36:32.000000000 -0400
41379 @@ -1351,7 +1351,7 @@ static int pch_uart_verify_port(struct u
41380 return 0;
41381 }
41382
41383 -static struct uart_ops pch_uart_ops = {
41384 +static const struct uart_ops pch_uart_ops = {
41385 .tx_empty = pch_uart_tx_empty,
41386 .set_mctrl = pch_uart_set_mctrl,
41387 .get_mctrl = pch_uart_get_mctrl,
41388 diff -urNp linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c
41389 --- linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c 2011-05-19 00:06:34.000000000 -0400
41390 +++ linux-2.6.39.1/drivers/tty/serial/pmac_zilog.c 2011-05-22 19:36:32.000000000 -0400
41391 @@ -1427,7 +1427,7 @@ static void pmz_poll_put_char(struct uar
41392
41393 #endif /* CONFIG_CONSOLE_POLL */
41394
41395 -static struct uart_ops pmz_pops = {
41396 +static const struct uart_ops pmz_pops = {
41397 .tx_empty = pmz_tx_empty,
41398 .set_mctrl = pmz_set_mctrl,
41399 .get_mctrl = pmz_get_mctrl,
41400 diff -urNp linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c
41401 --- linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c 2011-05-19 00:06:34.000000000 -0400
41402 +++ linux-2.6.39.1/drivers/tty/serial/pnx8xxx_uart.c 2011-05-22 19:36:32.000000000 -0400
41403 @@ -614,7 +614,7 @@ pnx8xxx_verify_port(struct uart_port *po
41404 return ret;
41405 }
41406
41407 -static struct uart_ops pnx8xxx_pops = {
41408 +static const struct uart_ops pnx8xxx_pops = {
41409 .tx_empty = pnx8xxx_tx_empty,
41410 .set_mctrl = pnx8xxx_set_mctrl,
41411 .get_mctrl = pnx8xxx_get_mctrl,
41412 diff -urNp linux-2.6.39.1/drivers/tty/serial/pxa.c linux-2.6.39.1/drivers/tty/serial/pxa.c
41413 --- linux-2.6.39.1/drivers/tty/serial/pxa.c 2011-05-19 00:06:34.000000000 -0400
41414 +++ linux-2.6.39.1/drivers/tty/serial/pxa.c 2011-05-22 19:36:32.000000000 -0400
41415 @@ -706,7 +706,7 @@ static struct console serial_pxa_console
41416 #define PXA_CONSOLE NULL
41417 #endif
41418
41419 -struct uart_ops serial_pxa_pops = {
41420 +const struct uart_ops serial_pxa_pops = {
41421 .tx_empty = serial_pxa_tx_empty,
41422 .set_mctrl = serial_pxa_set_mctrl,
41423 .get_mctrl = serial_pxa_get_mctrl,
41424 diff -urNp linux-2.6.39.1/drivers/tty/serial/sa1100.c linux-2.6.39.1/drivers/tty/serial/sa1100.c
41425 --- linux-2.6.39.1/drivers/tty/serial/sa1100.c 2011-05-19 00:06:34.000000000 -0400
41426 +++ linux-2.6.39.1/drivers/tty/serial/sa1100.c 2011-05-22 19:36:32.000000000 -0400
41427 @@ -577,7 +577,7 @@ sa1100_verify_port(struct uart_port *por
41428 return ret;
41429 }
41430
41431 -static struct uart_ops sa1100_pops = {
41432 +static const struct uart_ops sa1100_pops = {
41433 .tx_empty = sa1100_tx_empty,
41434 .set_mctrl = sa1100_set_mctrl,
41435 .get_mctrl = sa1100_get_mctrl,
41436 diff -urNp linux-2.6.39.1/drivers/tty/serial/samsung.c linux-2.6.39.1/drivers/tty/serial/samsung.c
41437 --- linux-2.6.39.1/drivers/tty/serial/samsung.c 2011-05-19 00:06:34.000000000 -0400
41438 +++ linux-2.6.39.1/drivers/tty/serial/samsung.c 2011-05-22 19:36:32.000000000 -0400
41439 @@ -860,7 +860,7 @@ static struct console s3c24xx_serial_con
41440 #define S3C24XX_SERIAL_CONSOLE NULL
41441 #endif
41442
41443 -static struct uart_ops s3c24xx_serial_ops = {
41444 +static const struct uart_ops s3c24xx_serial_ops = {
41445 .pm = s3c24xx_serial_pm,
41446 .tx_empty = s3c24xx_serial_tx_empty,
41447 .get_mctrl = s3c24xx_serial_get_mctrl,
41448 diff -urNp linux-2.6.39.1/drivers/tty/serial/sc26xx.c linux-2.6.39.1/drivers/tty/serial/sc26xx.c
41449 --- linux-2.6.39.1/drivers/tty/serial/sc26xx.c 2011-05-19 00:06:34.000000000 -0400
41450 +++ linux-2.6.39.1/drivers/tty/serial/sc26xx.c 2011-05-22 19:36:32.000000000 -0400
41451 @@ -515,7 +515,7 @@ static int sc26xx_verify_port(struct uar
41452 return -EINVAL;
41453 }
41454
41455 -static struct uart_ops sc26xx_ops = {
41456 +static const struct uart_ops sc26xx_ops = {
41457 .tx_empty = sc26xx_tx_empty,
41458 .set_mctrl = sc26xx_set_mctrl,
41459 .get_mctrl = sc26xx_get_mctrl,
41460 diff -urNp linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c
41461 --- linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c 2011-05-19 00:06:34.000000000 -0400
41462 +++ linux-2.6.39.1/drivers/tty/serial/serial_ks8695.c 2011-05-22 19:36:32.000000000 -0400
41463 @@ -528,7 +528,7 @@ static int ks8695uart_verify_port(struct
41464 return ret;
41465 }
41466
41467 -static struct uart_ops ks8695uart_pops = {
41468 +static const struct uart_ops ks8695uart_pops = {
41469 .tx_empty = ks8695uart_tx_empty,
41470 .set_mctrl = ks8695uart_set_mctrl,
41471 .get_mctrl = ks8695uart_get_mctrl,
41472 diff -urNp linux-2.6.39.1/drivers/tty/serial/serial_txx9.c linux-2.6.39.1/drivers/tty/serial/serial_txx9.c
41473 --- linux-2.6.39.1/drivers/tty/serial/serial_txx9.c 2011-05-19 00:06:34.000000000 -0400
41474 +++ linux-2.6.39.1/drivers/tty/serial/serial_txx9.c 2011-05-22 19:36:32.000000000 -0400
41475 @@ -857,7 +857,7 @@ serial_txx9_type(struct uart_port *port)
41476 return "txx9";
41477 }
41478
41479 -static struct uart_ops serial_txx9_pops = {
41480 +static const struct uart_ops serial_txx9_pops = {
41481 .tx_empty = serial_txx9_tx_empty,
41482 .set_mctrl = serial_txx9_set_mctrl,
41483 .get_mctrl = serial_txx9_get_mctrl,
41484 diff -urNp linux-2.6.39.1/drivers/tty/serial/sn_console.c linux-2.6.39.1/drivers/tty/serial/sn_console.c
41485 --- linux-2.6.39.1/drivers/tty/serial/sn_console.c 2011-05-19 00:06:34.000000000 -0400
41486 +++ linux-2.6.39.1/drivers/tty/serial/sn_console.c 2011-05-22 19:36:32.000000000 -0400
41487 @@ -388,7 +388,7 @@ static void snp_config_port(struct uart_
41488
41489 /* Associate the uart functions above - given to serial core */
41490
41491 -static struct uart_ops sn_console_ops = {
41492 +static const struct uart_ops sn_console_ops = {
41493 .tx_empty = snp_tx_empty,
41494 .set_mctrl = snp_set_mctrl,
41495 .get_mctrl = snp_get_mctrl,
41496 diff -urNp linux-2.6.39.1/drivers/tty/serial/sunhv.c linux-2.6.39.1/drivers/tty/serial/sunhv.c
41497 --- linux-2.6.39.1/drivers/tty/serial/sunhv.c 2011-05-19 00:06:34.000000000 -0400
41498 +++ linux-2.6.39.1/drivers/tty/serial/sunhv.c 2011-05-22 19:36:32.000000000 -0400
41499 @@ -168,12 +168,12 @@ struct sunhv_ops {
41500 int (*receive_chars)(struct uart_port *port, struct tty_struct *tty);
41501 };
41502
41503 -static struct sunhv_ops bychar_ops = {
41504 +static const struct sunhv_ops bychar_ops = {
41505 .transmit_chars = transmit_chars_putchar,
41506 .receive_chars = receive_chars_getchar,
41507 };
41508
41509 -static struct sunhv_ops bywrite_ops = {
41510 +static const struct sunhv_ops bywrite_ops = {
41511 .transmit_chars = transmit_chars_write,
41512 .receive_chars = receive_chars_read,
41513 };
41514 @@ -370,7 +370,7 @@ static int sunhv_verify_port(struct uart
41515 return -EINVAL;
41516 }
41517
41518 -static struct uart_ops sunhv_pops = {
41519 +static const struct uart_ops sunhv_pops = {
41520 .tx_empty = sunhv_tx_empty,
41521 .set_mctrl = sunhv_set_mctrl,
41522 .get_mctrl = sunhv_get_mctrl,
41523 diff -urNp linux-2.6.39.1/drivers/tty/serial/sunsab.c linux-2.6.39.1/drivers/tty/serial/sunsab.c
41524 --- linux-2.6.39.1/drivers/tty/serial/sunsab.c 2011-05-19 00:06:34.000000000 -0400
41525 +++ linux-2.6.39.1/drivers/tty/serial/sunsab.c 2011-05-22 19:36:32.000000000 -0400
41526 @@ -804,7 +804,7 @@ static int sunsab_verify_port(struct uar
41527 return -EINVAL;
41528 }
41529
41530 -static struct uart_ops sunsab_pops = {
41531 +static const struct uart_ops sunsab_pops = {
41532 .tx_empty = sunsab_tx_empty,
41533 .set_mctrl = sunsab_set_mctrl,
41534 .get_mctrl = sunsab_get_mctrl,
41535 diff -urNp linux-2.6.39.1/drivers/tty/serial/sunsu.c linux-2.6.39.1/drivers/tty/serial/sunsu.c
41536 --- linux-2.6.39.1/drivers/tty/serial/sunsu.c 2011-05-19 00:06:34.000000000 -0400
41537 +++ linux-2.6.39.1/drivers/tty/serial/sunsu.c 2011-05-22 19:36:32.000000000 -0400
41538 @@ -946,7 +946,7 @@ sunsu_type(struct uart_port *port)
41539 return uart_config[type].name;
41540 }
41541
41542 -static struct uart_ops sunsu_pops = {
41543 +static const struct uart_ops sunsu_pops = {
41544 .tx_empty = sunsu_tx_empty,
41545 .set_mctrl = sunsu_set_mctrl,
41546 .get_mctrl = sunsu_get_mctrl,
41547 diff -urNp linux-2.6.39.1/drivers/tty/serial/sunzilog.c linux-2.6.39.1/drivers/tty/serial/sunzilog.c
41548 --- linux-2.6.39.1/drivers/tty/serial/sunzilog.c 2011-05-19 00:06:34.000000000 -0400
41549 +++ linux-2.6.39.1/drivers/tty/serial/sunzilog.c 2011-05-22 19:36:32.000000000 -0400
41550 @@ -1042,7 +1042,7 @@ static void sunzilog_put_poll_char(struc
41551 }
41552 #endif /* CONFIG_CONSOLE_POLL */
41553
41554 -static struct uart_ops sunzilog_pops = {
41555 +static const struct uart_ops sunzilog_pops = {
41556 .tx_empty = sunzilog_tx_empty,
41557 .set_mctrl = sunzilog_set_mctrl,
41558 .get_mctrl = sunzilog_get_mctrl,
41559 diff -urNp linux-2.6.39.1/drivers/tty/serial/timbuart.c linux-2.6.39.1/drivers/tty/serial/timbuart.c
41560 --- linux-2.6.39.1/drivers/tty/serial/timbuart.c 2011-05-19 00:06:34.000000000 -0400
41561 +++ linux-2.6.39.1/drivers/tty/serial/timbuart.c 2011-05-22 19:36:32.000000000 -0400
41562 @@ -394,7 +394,7 @@ static int timbuart_verify_port(struct u
41563 return -EINVAL;
41564 }
41565
41566 -static struct uart_ops timbuart_ops = {
41567 +static const struct uart_ops timbuart_ops = {
41568 .tx_empty = timbuart_tx_empty,
41569 .set_mctrl = timbuart_set_mctrl,
41570 .get_mctrl = timbuart_get_mctrl,
41571 diff -urNp linux-2.6.39.1/drivers/tty/serial/uartlite.c linux-2.6.39.1/drivers/tty/serial/uartlite.c
41572 --- linux-2.6.39.1/drivers/tty/serial/uartlite.c 2011-05-19 00:06:34.000000000 -0400
41573 +++ linux-2.6.39.1/drivers/tty/serial/uartlite.c 2011-05-22 19:36:32.000000000 -0400
41574 @@ -331,7 +331,7 @@ static void ulite_put_poll_char(struct u
41575 }
41576 #endif
41577
41578 -static struct uart_ops ulite_ops = {
41579 +static const struct uart_ops ulite_ops = {
41580 .tx_empty = ulite_tx_empty,
41581 .set_mctrl = ulite_set_mctrl,
41582 .get_mctrl = ulite_get_mctrl,
41583 diff -urNp linux-2.6.39.1/drivers/tty/serial/ucc_uart.c linux-2.6.39.1/drivers/tty/serial/ucc_uart.c
41584 --- linux-2.6.39.1/drivers/tty/serial/ucc_uart.c 2011-05-19 00:06:34.000000000 -0400
41585 +++ linux-2.6.39.1/drivers/tty/serial/ucc_uart.c 2011-05-22 19:36:32.000000000 -0400
41586 @@ -1088,7 +1088,7 @@ static int qe_uart_verify_port(struct ua
41587 *
41588 * Details on these functions can be found in Documentation/serial/driver
41589 */
41590 -static struct uart_ops qe_uart_pops = {
41591 +static const struct uart_ops qe_uart_pops = {
41592 .tx_empty = qe_uart_tx_empty,
41593 .set_mctrl = qe_uart_set_mctrl,
41594 .get_mctrl = qe_uart_get_mctrl,
41595 diff -urNp linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c
41596 --- linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c 2011-05-19 00:06:34.000000000 -0400
41597 +++ linux-2.6.39.1/drivers/tty/serial/vr41xx_siu.c 2011-05-22 19:36:32.000000000 -0400
41598 @@ -683,7 +683,7 @@ static int siu_verify_port(struct uart_p
41599 return 0;
41600 }
41601
41602 -static struct uart_ops siu_uart_ops = {
41603 +static const struct uart_ops siu_uart_ops = {
41604 .tx_empty = siu_tx_empty,
41605 .set_mctrl = siu_set_mctrl,
41606 .get_mctrl = siu_get_mctrl,
41607 diff -urNp linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c
41608 --- linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c 2011-05-19 00:06:34.000000000 -0400
41609 +++ linux-2.6.39.1/drivers/tty/serial/vt8500_serial.c 2011-05-22 19:36:32.000000000 -0400
41610 @@ -519,7 +519,7 @@ static struct console vt8500_console = {
41611 #define VT8500_CONSOLE NULL
41612 #endif
41613
41614 -static struct uart_ops vt8500_uart_pops = {
41615 +static const struct uart_ops vt8500_uart_pops = {
41616 .tx_empty = vt8500_tx_empty,
41617 .set_mctrl = vt8500_set_mctrl,
41618 .get_mctrl = vt8500_get_mctrl,
41619 diff -urNp linux-2.6.39.1/drivers/tty/serial/zs.c linux-2.6.39.1/drivers/tty/serial/zs.c
41620 --- linux-2.6.39.1/drivers/tty/serial/zs.c 2011-05-19 00:06:34.000000000 -0400
41621 +++ linux-2.6.39.1/drivers/tty/serial/zs.c 2011-05-22 19:36:32.000000000 -0400
41622 @@ -1044,7 +1044,7 @@ static int zs_verify_port(struct uart_po
41623 }
41624
41625
41626 -static struct uart_ops zs_ops = {
41627 +static const struct uart_ops zs_ops = {
41628 .tx_empty = zs_tx_empty,
41629 .set_mctrl = zs_set_mctrl,
41630 .get_mctrl = zs_get_mctrl,
41631 diff -urNp linux-2.6.39.1/drivers/tty/tty_io.c linux-2.6.39.1/drivers/tty/tty_io.c
41632 --- linux-2.6.39.1/drivers/tty/tty_io.c 2011-05-19 00:06:34.000000000 -0400
41633 +++ linux-2.6.39.1/drivers/tty/tty_io.c 2011-05-22 19:36:32.000000000 -0400
41634 @@ -139,21 +139,11 @@ EXPORT_SYMBOL(tty_mutex);
41635 /* Spinlock to protect the tty->tty_files list */
41636 DEFINE_SPINLOCK(tty_files_lock);
41637
41638 -static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
41639 -static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
41640 ssize_t redirected_tty_write(struct file *, const char __user *,
41641 size_t, loff_t *);
41642 -static unsigned int tty_poll(struct file *, poll_table *);
41643 static int tty_open(struct inode *, struct file *);
41644 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
41645 -#ifdef CONFIG_COMPAT
41646 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41647 - unsigned long arg);
41648 -#else
41649 -#define tty_compat_ioctl NULL
41650 -#endif
41651 static int __tty_fasync(int fd, struct file *filp, int on);
41652 -static int tty_fasync(int fd, struct file *filp, int on);
41653 static void release_tty(struct tty_struct *tty, int idx);
41654 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41655 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41656 @@ -937,7 +927,7 @@ EXPORT_SYMBOL(start_tty);
41657 * read calls may be outstanding in parallel.
41658 */
41659
41660 -static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41661 +ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41662 loff_t *ppos)
41663 {
41664 int i;
41665 @@ -963,6 +953,8 @@ static ssize_t tty_read(struct file *fil
41666 return i;
41667 }
41668
41669 +EXPORT_SYMBOL(tty_read);
41670 +
41671 void tty_write_unlock(struct tty_struct *tty)
41672 {
41673 mutex_unlock(&tty->atomic_write_lock);
41674 @@ -1112,7 +1104,7 @@ void tty_write_message(struct tty_struct
41675 * write method will not be invoked in parallel for each device.
41676 */
41677
41678 -static ssize_t tty_write(struct file *file, const char __user *buf,
41679 +ssize_t tty_write(struct file *file, const char __user *buf,
41680 size_t count, loff_t *ppos)
41681 {
41682 struct inode *inode = file->f_path.dentry->d_inode;
41683 @@ -1138,6 +1130,8 @@ static ssize_t tty_write(struct file *fi
41684 return ret;
41685 }
41686
41687 +EXPORT_SYMBOL(tty_write);
41688 +
41689 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
41690 size_t count, loff_t *ppos)
41691 {
41692 @@ -1777,6 +1771,8 @@ int tty_release(struct inode *inode, str
41693 return 0;
41694 }
41695
41696 +EXPORT_SYMBOL(tty_release);
41697 +
41698 /**
41699 * tty_open - open a tty device
41700 * @inode: inode of device file
41701 @@ -1968,7 +1964,7 @@ got_driver:
41702 * may be re-entered freely by other callers.
41703 */
41704
41705 -static unsigned int tty_poll(struct file *filp, poll_table *wait)
41706 +unsigned int tty_poll(struct file *filp, poll_table *wait)
41707 {
41708 struct tty_struct *tty = file_tty(filp);
41709 struct tty_ldisc *ld;
41710 @@ -1984,6 +1980,8 @@ static unsigned int tty_poll(struct file
41711 return ret;
41712 }
41713
41714 +EXPORT_SYMBOL(tty_poll);
41715 +
41716 static int __tty_fasync(int fd, struct file *filp, int on)
41717 {
41718 struct tty_struct *tty = file_tty(filp);
41719 @@ -2025,7 +2023,7 @@ out:
41720 return retval;
41721 }
41722
41723 -static int tty_fasync(int fd, struct file *filp, int on)
41724 +int tty_fasync(int fd, struct file *filp, int on)
41725 {
41726 int retval;
41727 tty_lock();
41728 @@ -2034,6 +2032,8 @@ static int tty_fasync(int fd, struct fil
41729 return retval;
41730 }
41731
41732 +EXPORT_SYMBOL(tty_fasync);
41733 +
41734 /**
41735 * tiocsti - fake input character
41736 * @tty: tty to fake input into
41737 @@ -2695,8 +2695,10 @@ long tty_ioctl(struct file *file, unsign
41738 return retval;
41739 }
41740
41741 +EXPORT_SYMBOL(tty_ioctl);
41742 +
41743 #ifdef CONFIG_COMPAT
41744 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41745 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
41746 unsigned long arg)
41747 {
41748 struct inode *inode = file->f_dentry->d_inode;
41749 @@ -2720,6 +2722,9 @@ static long tty_compat_ioctl(struct file
41750
41751 return retval;
41752 }
41753 +
41754 +EXPORT_SYMBOL(tty_compat_ioctl);
41755 +
41756 #endif
41757
41758 /*
41759 @@ -3198,11 +3203,6 @@ struct tty_struct *get_current_tty(void)
41760 }
41761 EXPORT_SYMBOL_GPL(get_current_tty);
41762
41763 -void tty_default_fops(struct file_operations *fops)
41764 -{
41765 - *fops = tty_fops;
41766 -}
41767 -
41768 /*
41769 * Initialize the console device. This is called *early*, so
41770 * we can't necessarily depend on lots of kernel help here.
41771 diff -urNp linux-2.6.39.1/drivers/tty/tty_ldisc.c linux-2.6.39.1/drivers/tty/tty_ldisc.c
41772 --- linux-2.6.39.1/drivers/tty/tty_ldisc.c 2011-05-19 00:06:34.000000000 -0400
41773 +++ linux-2.6.39.1/drivers/tty/tty_ldisc.c 2011-05-22 19:36:32.000000000 -0400
41774 @@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
41775 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
41776 struct tty_ldisc_ops *ldo = ld->ops;
41777
41778 - ldo->refcount--;
41779 + atomic_dec(&ldo->refcount);
41780 module_put(ldo->owner);
41781 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41782
41783 @@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
41784 spin_lock_irqsave(&tty_ldisc_lock, flags);
41785 tty_ldiscs[disc] = new_ldisc;
41786 new_ldisc->num = disc;
41787 - new_ldisc->refcount = 0;
41788 + atomic_set(&new_ldisc->refcount, 0);
41789 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41790
41791 return ret;
41792 @@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
41793 return -EINVAL;
41794
41795 spin_lock_irqsave(&tty_ldisc_lock, flags);
41796 - if (tty_ldiscs[disc]->refcount)
41797 + if (atomic_read(&tty_ldiscs[disc]->refcount))
41798 ret = -EBUSY;
41799 else
41800 tty_ldiscs[disc] = NULL;
41801 @@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
41802 if (ldops) {
41803 ret = ERR_PTR(-EAGAIN);
41804 if (try_module_get(ldops->owner)) {
41805 - ldops->refcount++;
41806 + atomic_inc(&ldops->refcount);
41807 ret = ldops;
41808 }
41809 }
41810 @@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
41811 unsigned long flags;
41812
41813 spin_lock_irqsave(&tty_ldisc_lock, flags);
41814 - ldops->refcount--;
41815 + atomic_dec(&ldops->refcount);
41816 module_put(ldops->owner);
41817 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41818 }
41819 diff -urNp linux-2.6.39.1/drivers/tty/vt/keyboard.c linux-2.6.39.1/drivers/tty/vt/keyboard.c
41820 --- linux-2.6.39.1/drivers/tty/vt/keyboard.c 2011-05-19 00:06:34.000000000 -0400
41821 +++ linux-2.6.39.1/drivers/tty/vt/keyboard.c 2011-05-22 20:32:43.000000000 -0400
41822 @@ -658,6 +658,16 @@ static void k_spec(struct vc_data *vc, u
41823 kbd->kbdmode == VC_OFF) &&
41824 value != KVAL(K_SAK))
41825 return; /* SAK is allowed even in raw mode */
41826 +
41827 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41828 + {
41829 + void *func = fn_handler[value];
41830 + if (func == fn_show_state || func == fn_show_ptregs ||
41831 + func == fn_show_mem)
41832 + return;
41833 + }
41834 +#endif
41835 +
41836 fn_handler[value](vc);
41837 }
41838
41839 diff -urNp linux-2.6.39.1/drivers/tty/vt/vt.c linux-2.6.39.1/drivers/tty/vt/vt.c
41840 --- linux-2.6.39.1/drivers/tty/vt/vt.c 2011-05-19 00:06:34.000000000 -0400
41841 +++ linux-2.6.39.1/drivers/tty/vt/vt.c 2011-05-22 19:36:32.000000000 -0400
41842 @@ -261,7 +261,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
41843
41844 static void notify_write(struct vc_data *vc, unsigned int unicode)
41845 {
41846 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
41847 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
41848 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
41849 }
41850
41851 diff -urNp linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c
41852 --- linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c 2011-05-19 00:06:34.000000000 -0400
41853 +++ linux-2.6.39.1/drivers/tty/vt/vt_ioctl.c 2011-05-22 19:41:37.000000000 -0400
41854 @@ -209,9 +209,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41855 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41856 return -EFAULT;
41857
41858 - if (!capable(CAP_SYS_TTY_CONFIG))
41859 - perm = 0;
41860 -
41861 switch (cmd) {
41862 case KDGKBENT:
41863 key_map = key_maps[s];
41864 @@ -223,6 +220,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41865 val = (i ? K_HOLE : K_NOSUCHMAP);
41866 return put_user(val, &user_kbe->kb_value);
41867 case KDSKBENT:
41868 + if (!capable(CAP_SYS_TTY_CONFIG))
41869 + perm = 0;
41870 +
41871 if (!perm)
41872 return -EPERM;
41873 if (!i && v == K_NOSUCHMAP) {
41874 @@ -324,9 +324,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41875 int i, j, k;
41876 int ret;
41877
41878 - if (!capable(CAP_SYS_TTY_CONFIG))
41879 - perm = 0;
41880 -
41881 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41882 if (!kbs) {
41883 ret = -ENOMEM;
41884 @@ -360,6 +357,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41885 kfree(kbs);
41886 return ((p && *p) ? -EOVERFLOW : 0);
41887 case KDSKBSENT:
41888 + if (!capable(CAP_SYS_TTY_CONFIG))
41889 + perm = 0;
41890 +
41891 if (!perm) {
41892 ret = -EPERM;
41893 goto reterr;
41894 diff -urNp linux-2.6.39.1/drivers/uio/uio.c linux-2.6.39.1/drivers/uio/uio.c
41895 --- linux-2.6.39.1/drivers/uio/uio.c 2011-05-19 00:06:34.000000000 -0400
41896 +++ linux-2.6.39.1/drivers/uio/uio.c 2011-05-22 19:36:32.000000000 -0400
41897 @@ -25,6 +25,7 @@
41898 #include <linux/kobject.h>
41899 #include <linux/cdev.h>
41900 #include <linux/uio_driver.h>
41901 +#include <asm/local.h>
41902
41903 #define UIO_MAX_DEVICES (1U << MINORBITS)
41904
41905 @@ -32,10 +33,10 @@ struct uio_device {
41906 struct module *owner;
41907 struct device *dev;
41908 int minor;
41909 - atomic_t event;
41910 + atomic_unchecked_t event;
41911 struct fasync_struct *async_queue;
41912 wait_queue_head_t wait;
41913 - int vma_count;
41914 + local_t vma_count;
41915 struct uio_info *info;
41916 struct kobject *map_dir;
41917 struct kobject *portio_dir;
41918 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device
41919 struct device_attribute *attr, char *buf)
41920 {
41921 struct uio_device *idev = dev_get_drvdata(dev);
41922 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41923 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41924 }
41925
41926 static struct device_attribute uio_class_attributes[] = {
41927 @@ -402,7 +403,7 @@ void uio_event_notify(struct uio_info *i
41928 {
41929 struct uio_device *idev = info->uio_dev;
41930
41931 - atomic_inc(&idev->event);
41932 + atomic_inc_unchecked(&idev->event);
41933 wake_up_interruptible(&idev->wait);
41934 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41935 }
41936 @@ -455,7 +456,7 @@ static int uio_open(struct inode *inode,
41937 }
41938
41939 listener->dev = idev;
41940 - listener->event_count = atomic_read(&idev->event);
41941 + listener->event_count = atomic_read_unchecked(&idev->event);
41942 filep->private_data = listener;
41943
41944 if (idev->info->open) {
41945 @@ -506,7 +507,7 @@ static unsigned int uio_poll(struct file
41946 return -EIO;
41947
41948 poll_wait(filep, &idev->wait, wait);
41949 - if (listener->event_count != atomic_read(&idev->event))
41950 + if (listener->event_count != atomic_read_unchecked(&idev->event))
41951 return POLLIN | POLLRDNORM;
41952 return 0;
41953 }
41954 @@ -531,7 +532,7 @@ static ssize_t uio_read(struct file *fil
41955 do {
41956 set_current_state(TASK_INTERRUPTIBLE);
41957
41958 - event_count = atomic_read(&idev->event);
41959 + event_count = atomic_read_unchecked(&idev->event);
41960 if (event_count != listener->event_count) {
41961 if (copy_to_user(buf, &event_count, count))
41962 retval = -EFAULT;
41963 @@ -602,13 +603,13 @@ static int uio_find_mem_index(struct vm_
41964 static void uio_vma_open(struct vm_area_struct *vma)
41965 {
41966 struct uio_device *idev = vma->vm_private_data;
41967 - idev->vma_count++;
41968 + local_inc(&idev->vma_count);
41969 }
41970
41971 static void uio_vma_close(struct vm_area_struct *vma)
41972 {
41973 struct uio_device *idev = vma->vm_private_data;
41974 - idev->vma_count--;
41975 + local_dec(&idev->vma_count);
41976 }
41977
41978 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41979 @@ -819,7 +820,7 @@ int __uio_register_device(struct module
41980 idev->owner = owner;
41981 idev->info = info;
41982 init_waitqueue_head(&idev->wait);
41983 - atomic_set(&idev->event, 0);
41984 + atomic_set_unchecked(&idev->event, 0);
41985
41986 ret = uio_get_minor(idev);
41987 if (ret)
41988 diff -urNp linux-2.6.39.1/drivers/usb/atm/cxacru.c linux-2.6.39.1/drivers/usb/atm/cxacru.c
41989 --- linux-2.6.39.1/drivers/usb/atm/cxacru.c 2011-05-19 00:06:34.000000000 -0400
41990 +++ linux-2.6.39.1/drivers/usb/atm/cxacru.c 2011-05-22 19:36:32.000000000 -0400
41991 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
41992 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41993 if (ret < 2)
41994 return -EINVAL;
41995 - if (index < 0 || index > 0x7f)
41996 + if (index > 0x7f)
41997 return -EINVAL;
41998 pos += tmp;
41999
42000 diff -urNp linux-2.6.39.1/drivers/usb/atm/usbatm.c linux-2.6.39.1/drivers/usb/atm/usbatm.c
42001 --- linux-2.6.39.1/drivers/usb/atm/usbatm.c 2011-05-19 00:06:34.000000000 -0400
42002 +++ linux-2.6.39.1/drivers/usb/atm/usbatm.c 2011-05-22 19:36:32.000000000 -0400
42003 @@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
42004 if (printk_ratelimit())
42005 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42006 __func__, vpi, vci);
42007 - atomic_inc(&vcc->stats->rx_err);
42008 + atomic_inc_unchecked(&vcc->stats->rx_err);
42009 return;
42010 }
42011
42012 @@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
42013 if (length > ATM_MAX_AAL5_PDU) {
42014 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42015 __func__, length, vcc);
42016 - atomic_inc(&vcc->stats->rx_err);
42017 + atomic_inc_unchecked(&vcc->stats->rx_err);
42018 goto out;
42019 }
42020
42021 @@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
42022 if (sarb->len < pdu_length) {
42023 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42024 __func__, pdu_length, sarb->len, vcc);
42025 - atomic_inc(&vcc->stats->rx_err);
42026 + atomic_inc_unchecked(&vcc->stats->rx_err);
42027 goto out;
42028 }
42029
42030 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42031 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42032 __func__, vcc);
42033 - atomic_inc(&vcc->stats->rx_err);
42034 + atomic_inc_unchecked(&vcc->stats->rx_err);
42035 goto out;
42036 }
42037
42038 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
42039 if (printk_ratelimit())
42040 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42041 __func__, length);
42042 - atomic_inc(&vcc->stats->rx_drop);
42043 + atomic_inc_unchecked(&vcc->stats->rx_drop);
42044 goto out;
42045 }
42046
42047 @@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
42048
42049 vcc->push(vcc, skb);
42050
42051 - atomic_inc(&vcc->stats->rx);
42052 + atomic_inc_unchecked(&vcc->stats->rx);
42053 out:
42054 skb_trim(sarb, 0);
42055 }
42056 @@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
42057 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42058
42059 usbatm_pop(vcc, skb);
42060 - atomic_inc(&vcc->stats->tx);
42061 + atomic_inc_unchecked(&vcc->stats->tx);
42062
42063 skb = skb_dequeue(&instance->sndqueue);
42064 }
42065 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
42066 if (!left--)
42067 return sprintf(page,
42068 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42069 - atomic_read(&atm_dev->stats.aal5.tx),
42070 - atomic_read(&atm_dev->stats.aal5.tx_err),
42071 - atomic_read(&atm_dev->stats.aal5.rx),
42072 - atomic_read(&atm_dev->stats.aal5.rx_err),
42073 - atomic_read(&atm_dev->stats.aal5.rx_drop));
42074 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42075 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42076 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42077 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42078 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42079
42080 if (!left--) {
42081 if (instance->disconnected)
42082 diff -urNp linux-2.6.39.1/drivers/usb/core/devices.c linux-2.6.39.1/drivers/usb/core/devices.c
42083 --- linux-2.6.39.1/drivers/usb/core/devices.c 2011-05-19 00:06:34.000000000 -0400
42084 +++ linux-2.6.39.1/drivers/usb/core/devices.c 2011-05-22 19:36:32.000000000 -0400
42085 @@ -126,7 +126,7 @@ static const char *format_endpt =
42086 * time it gets called.
42087 */
42088 static struct device_connect_event {
42089 - atomic_t count;
42090 + atomic_unchecked_t count;
42091 wait_queue_head_t wait;
42092 } device_event = {
42093 .count = ATOMIC_INIT(1),
42094 @@ -164,7 +164,7 @@ static const struct class_info clas_info
42095
42096 void usbfs_conn_disc_event(void)
42097 {
42098 - atomic_add(2, &device_event.count);
42099 + atomic_add_unchecked(2, &device_event.count);
42100 wake_up(&device_event.wait);
42101 }
42102
42103 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(stru
42104
42105 poll_wait(file, &device_event.wait, wait);
42106
42107 - event_count = atomic_read(&device_event.count);
42108 + event_count = atomic_read_unchecked(&device_event.count);
42109 if (file->f_version != event_count) {
42110 file->f_version = event_count;
42111 return POLLIN | POLLRDNORM;
42112 diff -urNp linux-2.6.39.1/drivers/usb/core/hcd.c linux-2.6.39.1/drivers/usb/core/hcd.c
42113 --- linux-2.6.39.1/drivers/usb/core/hcd.c 2011-06-03 00:04:14.000000000 -0400
42114 +++ linux-2.6.39.1/drivers/usb/core/hcd.c 2011-06-03 00:32:07.000000000 -0400
42115 @@ -2574,7 +2574,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
42116
42117 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42118
42119 -struct usb_mon_operations *mon_ops;
42120 +const struct usb_mon_operations *mon_ops;
42121
42122 /*
42123 * The registration is unlocked.
42124 @@ -2584,7 +2584,7 @@ struct usb_mon_operations *mon_ops;
42125 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42126 */
42127
42128 -int usb_mon_register (struct usb_mon_operations *ops)
42129 +int usb_mon_register (const struct usb_mon_operations *ops)
42130 {
42131
42132 if (mon_ops)
42133 diff -urNp linux-2.6.39.1/drivers/usb/core/message.c linux-2.6.39.1/drivers/usb/core/message.c
42134 --- linux-2.6.39.1/drivers/usb/core/message.c 2011-05-19 00:06:34.000000000 -0400
42135 +++ linux-2.6.39.1/drivers/usb/core/message.c 2011-05-22 19:36:32.000000000 -0400
42136 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
42137 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42138 if (buf) {
42139 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42140 - if (len > 0) {
42141 - smallbuf = kmalloc(++len, GFP_NOIO);
42142 + if (len++ > 0) {
42143 + smallbuf = kmalloc(len, GFP_NOIO);
42144 if (!smallbuf)
42145 return buf;
42146 memcpy(smallbuf, buf, len);
42147 diff -urNp linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c
42148 --- linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c 2011-05-19 00:06:34.000000000 -0400
42149 +++ linux-2.6.39.1/drivers/usb/early/ehci-dbgp.c 2011-05-22 19:36:32.000000000 -0400
42150 @@ -96,7 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
42151 }
42152
42153 #ifdef CONFIG_KGDB
42154 -static struct kgdb_io kgdbdbgp_io_ops;
42155 +static struct kgdb_io kgdbdbgp_io_ops; /* cannot be const, see kgdbdbgp_parse_config */
42156 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
42157 #else
42158 #define dbgp_kgdb_mode (0)
42159 @@ -1026,7 +1026,7 @@ static void kgdbdbgp_write_char(u8 chr)
42160 early_dbgp_write(NULL, &chr, 1);
42161 }
42162
42163 -static struct kgdb_io kgdbdbgp_io_ops = {
42164 +static struct kgdb_io kgdbdbgp_io_ops = { /* cannot be const, see kgdbdbgp_parse_config() */
42165 .name = "kgdbdbgp",
42166 .read_char = kgdbdbgp_read_char,
42167 .write_char = kgdbdbgp_write_char,
42168 diff -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
42169 --- linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c 2011-05-19 00:06:34.000000000 -0400
42170 +++ linux-2.6.39.1/drivers/usb/gadget/fsl_qe_udc.c 2011-05-22 19:36:32.000000000 -0400
42171 @@ -1859,7 +1859,7 @@ out:
42172 return status;
42173 }
42174
42175 -static struct usb_ep_ops qe_ep_ops = {
42176 +static const struct usb_ep_ops qe_ep_ops = {
42177 .enable = qe_ep_enable,
42178 .disable = qe_ep_disable,
42179
42180 @@ -1928,7 +1928,7 @@ static int qe_pullup(struct usb_gadget *
42181 }
42182
42183 /* defined in usb_gadget.h */
42184 -static struct usb_gadget_ops qe_gadget_ops = {
42185 +static const struct usb_gadget_ops qe_gadget_ops = {
42186 .get_frame = qe_get_frame,
42187 .wakeup = qe_wakeup,
42188 /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */
42189 diff -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
42190 --- linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42191 +++ linux-2.6.39.1/drivers/usb/gadget/fsl_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42192 @@ -1003,7 +1003,7 @@ static void fsl_ep_fifo_flush(struct usb
42193 } while (fsl_readl(&dr_regs->endptstatus) & bits);
42194 }
42195
42196 -static struct usb_ep_ops fsl_ep_ops = {
42197 +static const struct usb_ep_ops fsl_ep_ops = {
42198 .enable = fsl_ep_enable,
42199 .disable = fsl_ep_disable,
42200
42201 @@ -1114,7 +1114,7 @@ static int fsl_pullup(struct usb_gadget
42202 }
42203
42204 /* defined in gadget.h */
42205 -static struct usb_gadget_ops fsl_gadget_ops = {
42206 +static const struct usb_gadget_ops fsl_gadget_ops = {
42207 .get_frame = fsl_get_frame,
42208 .wakeup = fsl_wakeup,
42209 /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */
42210 diff -urNp linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c
42211 --- linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c 2011-05-19 00:06:34.000000000 -0400
42212 +++ linux-2.6.39.1/drivers/usb/gadget/fusb300_udc.c 2011-05-22 19:36:32.000000000 -0400
42213 @@ -527,7 +527,7 @@ static void fusb300_fifo_flush(struct us
42214 {
42215 }
42216
42217 -static struct usb_ep_ops fusb300_ep_ops = {
42218 +static const struct usb_ep_ops fusb300_ep_ops = {
42219 .enable = fusb300_enable,
42220 .disable = fusb300_disable,
42221
42222 @@ -1570,7 +1570,7 @@ static int fusb300_udc_pullup(struct usb
42223 return 0;
42224 }
42225
42226 -static struct usb_gadget_ops fusb300_gadget_ops = {
42227 +static const struct usb_gadget_ops fusb300_gadget_ops = {
42228 .pullup = fusb300_udc_pullup,
42229 };
42230
42231 diff -urNp linux-2.6.39.1/drivers/usb/gadget/goku_udc.c linux-2.6.39.1/drivers/usb/gadget/goku_udc.c
42232 --- linux-2.6.39.1/drivers/usb/gadget/goku_udc.c 2011-05-19 00:06:34.000000000 -0400
42233 +++ linux-2.6.39.1/drivers/usb/gadget/goku_udc.c 2011-05-22 19:36:32.000000000 -0400
42234 @@ -973,7 +973,7 @@ static void goku_fifo_flush(struct usb_e
42235 command(regs, COMMAND_FIFO_CLEAR, ep->num);
42236 }
42237
42238 -static struct usb_ep_ops goku_ep_ops = {
42239 +static const struct usb_ep_ops goku_ep_ops = {
42240 .enable = goku_ep_enable,
42241 .disable = goku_ep_disable,
42242
42243 diff -urNp linux-2.6.39.1/drivers/usb/gadget/imx_udc.c linux-2.6.39.1/drivers/usb/gadget/imx_udc.c
42244 --- linux-2.6.39.1/drivers/usb/gadget/imx_udc.c 2011-05-19 00:06:34.000000000 -0400
42245 +++ linux-2.6.39.1/drivers/usb/gadget/imx_udc.c 2011-05-22 19:36:32.000000000 -0400
42246 @@ -937,7 +937,7 @@ static void imx_ep_fifo_flush(struct usb
42247 local_irq_restore(flags);
42248 }
42249
42250 -static struct usb_ep_ops imx_ep_ops = {
42251 +static const struct usb_ep_ops imx_ep_ops = {
42252 .enable = imx_ep_enable,
42253 .disable = imx_ep_disable,
42254
42255 diff -urNp linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c
42256 --- linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c 2011-05-19 00:06:34.000000000 -0400
42257 +++ linux-2.6.39.1/drivers/usb/gadget/m66592-udc.c 2011-05-22 19:36:32.000000000 -0400
42258 @@ -1437,7 +1437,7 @@ static void m66592_fifo_flush(struct usb
42259 spin_unlock_irqrestore(&ep->m66592->lock, flags);
42260 }
42261
42262 -static struct usb_ep_ops m66592_ep_ops = {
42263 +static const struct usb_ep_ops m66592_ep_ops = {
42264 .enable = m66592_enable,
42265 .disable = m66592_disable,
42266
42267 @@ -1542,7 +1542,7 @@ static int m66592_get_frame(struct usb_g
42268 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
42269 }
42270
42271 -static struct usb_gadget_ops m66592_gadget_ops = {
42272 +static const struct usb_gadget_ops m66592_gadget_ops = {
42273 .get_frame = m66592_get_frame,
42274 };
42275
42276 diff -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
42277 --- linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42278 +++ linux-2.6.39.1/drivers/usb/gadget/mv_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42279 @@ -972,7 +972,7 @@ static int mv_ep_set_wedge(struct usb_ep
42280 return mv_ep_set_halt_wedge(_ep, 1, 1);
42281 }
42282
42283 -static struct usb_ep_ops mv_ep_ops = {
42284 +static const struct usb_ep_ops mv_ep_ops = {
42285 .enable = mv_ep_enable,
42286 .disable = mv_ep_disable,
42287
42288 diff -urNp linux-2.6.39.1/drivers/usb/gadget/omap_udc.c linux-2.6.39.1/drivers/usb/gadget/omap_udc.c
42289 --- linux-2.6.39.1/drivers/usb/gadget/omap_udc.c 2011-05-19 00:06:34.000000000 -0400
42290 +++ linux-2.6.39.1/drivers/usb/gadget/omap_udc.c 2011-05-22 19:36:32.000000000 -0400
42291 @@ -1177,7 +1177,7 @@ done:
42292 return status;
42293 }
42294
42295 -static struct usb_ep_ops omap_ep_ops = {
42296 +static const struct usb_ep_ops omap_ep_ops = {
42297 .enable = omap_ep_enable,
42298 .disable = omap_ep_disable,
42299
42300 @@ -1374,7 +1374,7 @@ static int omap_pullup(struct usb_gadget
42301 return 0;
42302 }
42303
42304 -static struct usb_gadget_ops omap_gadget_ops = {
42305 +static const struct usb_gadget_ops omap_gadget_ops = {
42306 .get_frame = omap_get_frame,
42307 .wakeup = omap_wakeup,
42308 .set_selfpowered = omap_set_selfpowered,
42309 diff -urNp linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c
42310 --- linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c 2011-05-19 00:06:34.000000000 -0400
42311 +++ linux-2.6.39.1/drivers/usb/gadget/pxa25x_udc.c 2011-05-22 19:36:32.000000000 -0400
42312 @@ -896,7 +896,7 @@ static void pxa25x_ep_fifo_flush(struct
42313 }
42314
42315
42316 -static struct usb_ep_ops pxa25x_ep_ops = {
42317 +static const struct usb_ep_ops pxa25x_ep_ops = {
42318 .enable = pxa25x_ep_enable,
42319 .disable = pxa25x_ep_disable,
42320
42321 diff -urNp linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c
42322 --- linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c 2011-05-19 00:06:34.000000000 -0400
42323 +++ linux-2.6.39.1/drivers/usb/gadget/pxa27x_udc.c 2011-05-22 19:36:32.000000000 -0400
42324 @@ -1491,7 +1491,7 @@ static int pxa_ep_disable(struct usb_ep
42325 return 0;
42326 }
42327
42328 -static struct usb_ep_ops pxa_ep_ops = {
42329 +static const struct usb_ep_ops pxa_ep_ops = {
42330 .enable = pxa_ep_enable,
42331 .disable = pxa_ep_disable,
42332
42333 diff -urNp linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c
42334 --- linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c 2011-05-19 00:06:34.000000000 -0400
42335 +++ linux-2.6.39.1/drivers/usb/gadget/r8a66597-udc.c 2011-05-22 19:36:32.000000000 -0400
42336 @@ -1392,7 +1392,7 @@ static void r8a66597_fifo_flush(struct u
42337 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
42338 }
42339
42340 -static struct usb_ep_ops r8a66597_ep_ops = {
42341 +static const struct usb_ep_ops r8a66597_ep_ops = {
42342 .enable = r8a66597_enable,
42343 .disable = r8a66597_disable,
42344
42345 @@ -1497,7 +1497,7 @@ static int r8a66597_get_frame(struct usb
42346 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
42347 }
42348
42349 -static struct usb_gadget_ops r8a66597_gadget_ops = {
42350 +static const struct usb_gadget_ops r8a66597_gadget_ops = {
42351 .get_frame = r8a66597_get_frame,
42352 };
42353
42354 diff -urNp linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c
42355 --- linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c 2011-05-19 00:06:34.000000000 -0400
42356 +++ linux-2.6.39.1/drivers/usb/gadget/s3c-hsotg.c 2011-05-22 19:36:32.000000000 -0400
42357 @@ -2461,7 +2461,7 @@ static int s3c_hsotg_ep_sethalt(struct u
42358 return 0;
42359 }
42360
42361 -static struct usb_ep_ops s3c_hsotg_ep_ops = {
42362 +static const struct usb_ep_ops s3c_hsotg_ep_ops = {
42363 .enable = s3c_hsotg_ep_enable,
42364 .disable = s3c_hsotg_ep_disable,
42365 .alloc_request = s3c_hsotg_ep_alloc_request,
42366 @@ -2725,7 +2725,7 @@ static int s3c_hsotg_gadget_getframe(str
42367 return s3c_hsotg_read_frameno(to_hsotg(gadget));
42368 }
42369
42370 -static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42371 +static const struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42372 .get_frame = s3c_hsotg_gadget_getframe,
42373 };
42374
42375 diff -urNp linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c
42376 --- linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c 2011-05-19 00:06:34.000000000 -0400
42377 +++ linux-2.6.39.1/drivers/usb/gadget/uvc_queue.c 2011-05-22 19:36:32.000000000 -0400
42378 @@ -400,7 +400,7 @@ static void uvc_vm_close(struct vm_area_
42379 buffer->vma_use_count--;
42380 }
42381
42382 -static struct vm_operations_struct uvc_vm_ops = {
42383 +static const struct vm_operations_struct uvc_vm_ops = {
42384 .open = uvc_vm_open,
42385 .close = uvc_vm_close,
42386 };
42387 diff -urNp linux-2.6.39.1/drivers/usb/host/ehci-fsl.c linux-2.6.39.1/drivers/usb/host/ehci-fsl.c
42388 --- linux-2.6.39.1/drivers/usb/host/ehci-fsl.c 2011-05-19 00:06:34.000000000 -0400
42389 +++ linux-2.6.39.1/drivers/usb/host/ehci-fsl.c 2011-05-22 19:36:32.000000000 -0400
42390 @@ -380,7 +380,7 @@ static int ehci_fsl_drv_restore(struct d
42391 return 0;
42392 }
42393
42394 -static struct dev_pm_ops ehci_fsl_pm_ops = {
42395 +static const struct dev_pm_ops ehci_fsl_pm_ops = {
42396 .suspend = ehci_fsl_drv_suspend,
42397 .resume = ehci_fsl_drv_resume,
42398 .restore = ehci_fsl_drv_restore,
42399 diff -urNp linux-2.6.39.1/drivers/usb/host/xhci-mem.c linux-2.6.39.1/drivers/usb/host/xhci-mem.c
42400 --- linux-2.6.39.1/drivers/usb/host/xhci-mem.c 2011-06-03 00:04:14.000000000 -0400
42401 +++ linux-2.6.39.1/drivers/usb/host/xhci-mem.c 2011-06-03 00:32:07.000000000 -0400
42402 @@ -1670,6 +1670,8 @@ static int xhci_check_trb_in_td_math(str
42403 unsigned int num_tests;
42404 int i, ret;
42405
42406 + pax_track_stack();
42407 +
42408 num_tests = ARRAY_SIZE(simple_test_vector);
42409 for (i = 0; i < num_tests; i++) {
42410 ret = xhci_test_trb_in_td(xhci,
42411 diff -urNp linux-2.6.39.1/drivers/usb/mon/mon_main.c linux-2.6.39.1/drivers/usb/mon/mon_main.c
42412 --- linux-2.6.39.1/drivers/usb/mon/mon_main.c 2011-05-19 00:06:34.000000000 -0400
42413 +++ linux-2.6.39.1/drivers/usb/mon/mon_main.c 2011-05-22 19:36:32.000000000 -0400
42414 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42415 /*
42416 * Ops
42417 */
42418 -static struct usb_mon_operations mon_ops_0 = {
42419 +static const struct usb_mon_operations mon_ops_0 = {
42420 .urb_submit = mon_submit,
42421 .urb_submit_error = mon_submit_error,
42422 .urb_complete = mon_complete,
42423 diff -urNp linux-2.6.39.1/drivers/usb/musb/cppi_dma.h linux-2.6.39.1/drivers/usb/musb/cppi_dma.h
42424 --- linux-2.6.39.1/drivers/usb/musb/cppi_dma.h 2011-05-19 00:06:34.000000000 -0400
42425 +++ linux-2.6.39.1/drivers/usb/musb/cppi_dma.h 2011-05-22 19:36:32.000000000 -0400
42426 @@ -113,7 +113,7 @@ struct cppi_channel {
42427
42428 /* CPPI DMA controller object */
42429 struct cppi {
42430 - struct dma_controller controller;
42431 + const struct dma_controller controller;
42432 struct musb *musb;
42433 void __iomem *mregs; /* Mentor regs */
42434 void __iomem *tibase; /* TI/CPPI regs */
42435 diff -urNp linux-2.6.39.1/drivers/usb/otg/msm_otg.c linux-2.6.39.1/drivers/usb/otg/msm_otg.c
42436 --- linux-2.6.39.1/drivers/usb/otg/msm_otg.c 2011-05-19 00:06:34.000000000 -0400
42437 +++ linux-2.6.39.1/drivers/usb/otg/msm_otg.c 2011-05-22 19:36:32.000000000 -0400
42438 @@ -95,7 +95,7 @@ static int ulpi_write(struct otg_transce
42439 return 0;
42440 }
42441
42442 -static struct otg_io_access_ops msm_otg_io_ops = {
42443 +static const struct otg_io_access_ops msm_otg_io_ops = {
42444 .read = ulpi_read,
42445 .write = ulpi_write,
42446 };
42447 diff -urNp linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c
42448 --- linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c 2011-05-19 00:06:34.000000000 -0400
42449 +++ linux-2.6.39.1/drivers/usb/otg/ulpi_viewport.c 2011-05-22 19:36:32.000000000 -0400
42450 @@ -74,7 +74,7 @@ static int ulpi_viewport_write(struct ot
42451 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
42452 }
42453
42454 -struct otg_io_access_ops ulpi_viewport_access_ops = {
42455 +const struct otg_io_access_ops ulpi_viewport_access_ops = {
42456 .read = ulpi_viewport_read,
42457 .write = ulpi_viewport_write,
42458 };
42459 diff -urNp linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c
42460 --- linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c 2011-06-03 00:04:14.000000000 -0400
42461 +++ linux-2.6.39.1/drivers/usb/serial/ftdi_sio.c 2011-06-03 00:32:07.000000000 -0400
42462 @@ -104,27 +104,27 @@ static int ftdi_stmclite_probe(struct
42463 static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
42464 static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
42465
42466 -static struct ftdi_sio_quirk ftdi_jtag_quirk = {
42467 +static const struct ftdi_sio_quirk ftdi_jtag_quirk = {
42468 .probe = ftdi_jtag_probe,
42469 };
42470
42471 -static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42472 +static const struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42473 .probe = ftdi_mtxorb_hack_setup,
42474 };
42475
42476 -static struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42477 +static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42478 .probe = ftdi_NDI_device_setup,
42479 };
42480
42481 -static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42482 +static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42483 .port_probe = ftdi_USB_UIRT_setup,
42484 };
42485
42486 -static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42487 +static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42488 .port_probe = ftdi_HE_TIRA1_setup,
42489 };
42490
42491 -static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42492 +static const struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42493 .probe = ftdi_stmclite_probe,
42494 };
42495
42496 diff -urNp linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h
42497 --- linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h 2011-05-19 00:06:34.000000000 -0400
42498 +++ linux-2.6.39.1/drivers/usb/wusbcore/wa-hc.h 2011-05-22 19:36:32.000000000 -0400
42499 @@ -192,7 +192,7 @@ struct wahc {
42500 struct list_head xfer_delayed_list;
42501 spinlock_t xfer_list_lock;
42502 struct work_struct xfer_work;
42503 - atomic_t xfer_id_count;
42504 + atomic_unchecked_t xfer_id_count;
42505 };
42506
42507
42508 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
42509 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42510 spin_lock_init(&wa->xfer_list_lock);
42511 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42512 - atomic_set(&wa->xfer_id_count, 1);
42513 + atomic_set_unchecked(&wa->xfer_id_count, 1);
42514 }
42515
42516 /**
42517 diff -urNp linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c
42518 --- linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c 2011-05-19 00:06:34.000000000 -0400
42519 +++ linux-2.6.39.1/drivers/usb/wusbcore/wa-xfer.c 2011-05-22 19:36:32.000000000 -0400
42520 @@ -294,7 +294,7 @@ out:
42521 */
42522 static void wa_xfer_id_init(struct wa_xfer *xfer)
42523 {
42524 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42525 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42526 }
42527
42528 /*
42529 diff -urNp linux-2.6.39.1/drivers/vhost/vhost.c linux-2.6.39.1/drivers/vhost/vhost.c
42530 --- linux-2.6.39.1/drivers/vhost/vhost.c 2011-05-19 00:06:34.000000000 -0400
42531 +++ linux-2.6.39.1/drivers/vhost/vhost.c 2011-05-22 19:36:32.000000000 -0400
42532 @@ -580,7 +580,7 @@ static int init_used(struct vhost_virtqu
42533 return get_user(vq->last_used_idx, &used->idx);
42534 }
42535
42536 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
42537 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
42538 {
42539 struct file *eventfp, *filep = NULL,
42540 *pollstart = NULL, *pollstop = NULL;
42541 diff -urNp linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c
42542 --- linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c 2011-05-19 00:06:34.000000000 -0400
42543 +++ linux-2.6.39.1/drivers/video/backlight/corgi_lcd.c 2011-05-22 19:36:32.000000000 -0400
42544 @@ -383,7 +383,7 @@ static int corgi_lcd_get_power(struct lc
42545 return lcd->power;
42546 }
42547
42548 -static struct lcd_ops corgi_lcd_ops = {
42549 +static const struct lcd_ops corgi_lcd_ops = {
42550 .get_power = corgi_lcd_get_power,
42551 .set_power = corgi_lcd_set_power,
42552 .set_mode = corgi_lcd_set_mode,
42553 diff -urNp linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c
42554 --- linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c 2011-05-19 00:06:34.000000000 -0400
42555 +++ linux-2.6.39.1/drivers/video/backlight/cr_bllcd.c 2011-05-22 19:36:32.000000000 -0400
42556 @@ -165,7 +165,7 @@ static int cr_lcd_set_power(struct lcd_d
42557 return 0;
42558 }
42559
42560 -static struct lcd_ops cr_lcd_ops = {
42561 +static const struct lcd_ops cr_lcd_ops = {
42562 .set_power = cr_lcd_set_power,
42563 };
42564
42565 diff -urNp linux-2.6.39.1/drivers/video/backlight/ili9320.c linux-2.6.39.1/drivers/video/backlight/ili9320.c
42566 --- linux-2.6.39.1/drivers/video/backlight/ili9320.c 2011-05-19 00:06:34.000000000 -0400
42567 +++ linux-2.6.39.1/drivers/video/backlight/ili9320.c 2011-05-22 19:36:32.000000000 -0400
42568 @@ -166,7 +166,7 @@ static int ili9320_get_power(struct lcd_
42569 return lcd->power;
42570 }
42571
42572 -static struct lcd_ops ili9320_ops = {
42573 +static const struct lcd_ops ili9320_ops = {
42574 .get_power = ili9320_get_power,
42575 .set_power = ili9320_set_power,
42576 };
42577 diff -urNp linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c
42578 --- linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c 2011-05-19 00:06:34.000000000 -0400
42579 +++ linux-2.6.39.1/drivers/video/backlight/jornada720_lcd.c 2011-05-22 19:36:32.000000000 -0400
42580 @@ -87,7 +87,7 @@ static int jornada_lcd_set_power(struct
42581 return 0;
42582 }
42583
42584 -static struct lcd_ops jornada_lcd_props = {
42585 +static const struct lcd_ops jornada_lcd_props = {
42586 .get_contrast = jornada_lcd_get_contrast,
42587 .set_contrast = jornada_lcd_set_contrast,
42588 .get_power = jornada_lcd_get_power,
42589 diff -urNp linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c
42590 --- linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c 2011-05-19 00:06:34.000000000 -0400
42591 +++ linux-2.6.39.1/drivers/video/backlight/l4f00242t03.c 2011-05-22 19:36:32.000000000 -0400
42592 @@ -149,7 +149,7 @@ static int l4f00242t03_lcd_power_set(str
42593 return 0;
42594 }
42595
42596 -static struct lcd_ops l4f_ops = {
42597 +static const struct lcd_ops l4f_ops = {
42598 .set_power = l4f00242t03_lcd_power_set,
42599 .get_power = l4f00242t03_lcd_power_get,
42600 };
42601 diff -urNp linux-2.6.39.1/drivers/video/backlight/lcd.c linux-2.6.39.1/drivers/video/backlight/lcd.c
42602 --- linux-2.6.39.1/drivers/video/backlight/lcd.c 2011-05-19 00:06:34.000000000 -0400
42603 +++ linux-2.6.39.1/drivers/video/backlight/lcd.c 2011-05-22 19:36:32.000000000 -0400
42604 @@ -192,7 +192,7 @@ static struct device_attribute lcd_devic
42605 * or a pointer to the newly allocated device.
42606 */
42607 struct lcd_device *lcd_device_register(const char *name, struct device *parent,
42608 - void *devdata, struct lcd_ops *ops)
42609 + void *devdata, const struct lcd_ops *ops)
42610 {
42611 struct lcd_device *new_ld;
42612 int rc;
42613 diff -urNp linux-2.6.39.1/drivers/video/backlight/ld9040.c linux-2.6.39.1/drivers/video/backlight/ld9040.c
42614 --- linux-2.6.39.1/drivers/video/backlight/ld9040.c 2011-05-19 00:06:34.000000000 -0400
42615 +++ linux-2.6.39.1/drivers/video/backlight/ld9040.c 2011-05-22 19:36:32.000000000 -0400
42616 @@ -651,7 +651,7 @@ static int ld9040_set_brightness(struct
42617 return ret;
42618 }
42619
42620 -static struct lcd_ops ld9040_lcd_ops = {
42621 +static const struct lcd_ops ld9040_lcd_ops = {
42622 .set_power = ld9040_set_power,
42623 .get_power = ld9040_get_power,
42624 };
42625 diff -urNp linux-2.6.39.1/drivers/video/backlight/lms283gf05.c linux-2.6.39.1/drivers/video/backlight/lms283gf05.c
42626 --- linux-2.6.39.1/drivers/video/backlight/lms283gf05.c 2011-05-19 00:06:34.000000000 -0400
42627 +++ linux-2.6.39.1/drivers/video/backlight/lms283gf05.c 2011-05-22 19:36:32.000000000 -0400
42628 @@ -144,7 +144,7 @@ static int lms283gf05_power_set(struct l
42629 return 0;
42630 }
42631
42632 -static struct lcd_ops lms_ops = {
42633 +static const struct lcd_ops lms_ops = {
42634 .set_power = lms283gf05_power_set,
42635 .get_power = NULL,
42636 };
42637 diff -urNp linux-2.6.39.1/drivers/video/backlight/ltv350qv.c linux-2.6.39.1/drivers/video/backlight/ltv350qv.c
42638 --- linux-2.6.39.1/drivers/video/backlight/ltv350qv.c 2011-05-19 00:06:34.000000000 -0400
42639 +++ linux-2.6.39.1/drivers/video/backlight/ltv350qv.c 2011-05-22 19:36:32.000000000 -0400
42640 @@ -221,7 +221,7 @@ static int ltv350qv_get_power(struct lcd
42641 return lcd->power;
42642 }
42643
42644 -static struct lcd_ops ltv_ops = {
42645 +static const struct lcd_ops ltv_ops = {
42646 .get_power = ltv350qv_get_power,
42647 .set_power = ltv350qv_set_power,
42648 };
42649 diff -urNp linux-2.6.39.1/drivers/video/backlight/platform_lcd.c linux-2.6.39.1/drivers/video/backlight/platform_lcd.c
42650 --- linux-2.6.39.1/drivers/video/backlight/platform_lcd.c 2011-05-19 00:06:34.000000000 -0400
42651 +++ linux-2.6.39.1/drivers/video/backlight/platform_lcd.c 2011-05-22 19:36:32.000000000 -0400
42652 @@ -66,7 +66,7 @@ static int platform_lcd_match(struct lcd
42653 return plcd->us->parent == info->device;
42654 }
42655
42656 -static struct lcd_ops platform_lcd_ops = {
42657 +static const struct lcd_ops platform_lcd_ops = {
42658 .get_power = platform_lcd_get_power,
42659 .set_power = platform_lcd_set_power,
42660 .check_fb = platform_lcd_match,
42661 diff -urNp linux-2.6.39.1/drivers/video/backlight/s6e63m0.c linux-2.6.39.1/drivers/video/backlight/s6e63m0.c
42662 --- linux-2.6.39.1/drivers/video/backlight/s6e63m0.c 2011-05-19 00:06:34.000000000 -0400
42663 +++ linux-2.6.39.1/drivers/video/backlight/s6e63m0.c 2011-05-22 19:36:32.000000000 -0400
42664 @@ -644,7 +644,7 @@ static int s6e63m0_set_brightness(struct
42665 return ret;
42666 }
42667
42668 -static struct lcd_ops s6e63m0_lcd_ops = {
42669 +static const struct lcd_ops s6e63m0_lcd_ops = {
42670 .set_power = s6e63m0_set_power,
42671 .get_power = s6e63m0_get_power,
42672 };
42673 diff -urNp linux-2.6.39.1/drivers/video/backlight/tdo24m.c linux-2.6.39.1/drivers/video/backlight/tdo24m.c
42674 --- linux-2.6.39.1/drivers/video/backlight/tdo24m.c 2011-05-19 00:06:34.000000000 -0400
42675 +++ linux-2.6.39.1/drivers/video/backlight/tdo24m.c 2011-05-22 19:36:32.000000000 -0400
42676 @@ -322,7 +322,7 @@ static int tdo24m_set_mode(struct lcd_de
42677 return lcd->adj_mode(lcd, mode);
42678 }
42679
42680 -static struct lcd_ops tdo24m_ops = {
42681 +static const struct lcd_ops tdo24m_ops = {
42682 .get_power = tdo24m_get_power,
42683 .set_power = tdo24m_set_power,
42684 .set_mode = tdo24m_set_mode,
42685 diff -urNp linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c
42686 --- linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c 2011-05-19 00:06:34.000000000 -0400
42687 +++ linux-2.6.39.1/drivers/video/backlight/tosa_lcd.c 2011-05-22 19:36:32.000000000 -0400
42688 @@ -163,7 +163,7 @@ static int tosa_lcd_set_mode(struct lcd_
42689 return 0;
42690 }
42691
42692 -static struct lcd_ops tosa_lcd_ops = {
42693 +static const struct lcd_ops tosa_lcd_ops = {
42694 .set_power = tosa_lcd_set_power,
42695 .get_power = tosa_lcd_get_power,
42696 .set_mode = tosa_lcd_set_mode,
42697 diff -urNp linux-2.6.39.1/drivers/video/bf537-lq035.c linux-2.6.39.1/drivers/video/bf537-lq035.c
42698 --- linux-2.6.39.1/drivers/video/bf537-lq035.c 2011-05-19 00:06:34.000000000 -0400
42699 +++ linux-2.6.39.1/drivers/video/bf537-lq035.c 2011-05-22 19:36:32.000000000 -0400
42700 @@ -682,7 +682,7 @@ static int bfin_lcd_check_fb(struct lcd_
42701 return 0;
42702 }
42703
42704 -static struct lcd_ops bfin_lcd_ops = {
42705 +static const struct lcd_ops bfin_lcd_ops = {
42706 .get_power = bfin_lcd_get_power,
42707 .set_power = bfin_lcd_set_power,
42708 .get_contrast = bfin_lcd_get_contrast,
42709 diff -urNp linux-2.6.39.1/drivers/video/bf54x-lq043fb.c linux-2.6.39.1/drivers/video/bf54x-lq043fb.c
42710 --- linux-2.6.39.1/drivers/video/bf54x-lq043fb.c 2011-05-19 00:06:34.000000000 -0400
42711 +++ linux-2.6.39.1/drivers/video/bf54x-lq043fb.c 2011-05-22 19:36:32.000000000 -0400
42712 @@ -467,7 +467,7 @@ static int bfin_lcd_check_fb(struct lcd_
42713 return 0;
42714 }
42715
42716 -static struct lcd_ops bfin_lcd_ops = {
42717 +static const struct lcd_ops bfin_lcd_ops = {
42718 .get_power = bfin_lcd_get_power,
42719 .set_power = bfin_lcd_set_power,
42720 .get_contrast = bfin_lcd_get_contrast,
42721 diff -urNp linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c
42722 --- linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c 2011-05-19 00:06:34.000000000 -0400
42723 +++ linux-2.6.39.1/drivers/video/bfin-t350mcqb-fb.c 2011-05-22 19:36:32.000000000 -0400
42724 @@ -387,7 +387,7 @@ static int bfin_lcd_check_fb(struct lcd_
42725 return 0;
42726 }
42727
42728 -static struct lcd_ops bfin_lcd_ops = {
42729 +static const struct lcd_ops bfin_lcd_ops = {
42730 .get_power = bfin_lcd_get_power,
42731 .set_power = bfin_lcd_set_power,
42732 .get_contrast = bfin_lcd_get_contrast,
42733 diff -urNp linux-2.6.39.1/drivers/video/fbcmap.c linux-2.6.39.1/drivers/video/fbcmap.c
42734 --- linux-2.6.39.1/drivers/video/fbcmap.c 2011-05-19 00:06:34.000000000 -0400
42735 +++ linux-2.6.39.1/drivers/video/fbcmap.c 2011-05-22 19:36:32.000000000 -0400
42736 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
42737 rc = -ENODEV;
42738 goto out;
42739 }
42740 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42741 - !info->fbops->fb_setcmap)) {
42742 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42743 rc = -EINVAL;
42744 goto out1;
42745 }
42746 diff -urNp linux-2.6.39.1/drivers/video/fbmem.c linux-2.6.39.1/drivers/video/fbmem.c
42747 --- linux-2.6.39.1/drivers/video/fbmem.c 2011-05-19 00:06:34.000000000 -0400
42748 +++ linux-2.6.39.1/drivers/video/fbmem.c 2011-05-22 19:36:32.000000000 -0400
42749 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_in
42750 image->dx += image->width + 8;
42751 }
42752 } else if (rotate == FB_ROTATE_UD) {
42753 - for (x = 0; x < num && image->dx >= 0; x++) {
42754 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42755 info->fbops->fb_imageblit(info, image);
42756 image->dx -= image->width + 8;
42757 }
42758 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_in
42759 image->dy += image->height + 8;
42760 }
42761 } else if (rotate == FB_ROTATE_CCW) {
42762 - for (x = 0; x < num && image->dy >= 0; x++) {
42763 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42764 info->fbops->fb_imageblit(info, image);
42765 image->dy -= image->height + 8;
42766 }
42767 @@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct
42768 int flags = info->flags;
42769 int ret = 0;
42770
42771 + pax_track_stack();
42772 +
42773 if (var->activate & FB_ACTIVATE_INV_MODE) {
42774 struct fb_videomode mode1, mode2;
42775
42776 @@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *
42777 void __user *argp = (void __user *)arg;
42778 long ret = 0;
42779
42780 + pax_track_stack();
42781 +
42782 switch (cmd) {
42783 case FBIOGET_VSCREENINFO:
42784 if (!lock_fb_info(info))
42785 @@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *
42786 return -EFAULT;
42787 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42788 return -EINVAL;
42789 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42790 + if (con2fb.framebuffer >= FB_MAX)
42791 return -EINVAL;
42792 if (!registered_fb[con2fb.framebuffer])
42793 request_module("fb%d", con2fb.framebuffer);
42794 diff -urNp linux-2.6.39.1/drivers/video/geode/display_gx1.c linux-2.6.39.1/drivers/video/geode/display_gx1.c
42795 --- linux-2.6.39.1/drivers/video/geode/display_gx1.c 2011-05-19 00:06:34.000000000 -0400
42796 +++ linux-2.6.39.1/drivers/video/geode/display_gx1.c 2011-05-22 19:36:32.000000000 -0400
42797 @@ -208,7 +208,7 @@ static void gx1_set_hw_palette_reg(struc
42798 writel(val, par->dc_regs + DC_PAL_DATA);
42799 }
42800
42801 -struct geode_dc_ops gx1_dc_ops = {
42802 +const struct geode_dc_ops gx1_dc_ops = {
42803 .set_mode = gx1_set_mode,
42804 .set_palette_reg = gx1_set_hw_palette_reg,
42805 };
42806 diff -urNp linux-2.6.39.1/drivers/video/geode/display_gx1.h linux-2.6.39.1/drivers/video/geode/display_gx1.h
42807 --- linux-2.6.39.1/drivers/video/geode/display_gx1.h 2011-05-19 00:06:34.000000000 -0400
42808 +++ linux-2.6.39.1/drivers/video/geode/display_gx1.h 2011-05-22 19:36:32.000000000 -0400
42809 @@ -18,7 +18,7 @@
42810 unsigned gx1_gx_base(void);
42811 int gx1_frame_buffer_size(void);
42812
42813 -extern struct geode_dc_ops gx1_dc_ops;
42814 +extern const struct geode_dc_ops gx1_dc_ops;
42815
42816 /* GX1 configuration I/O registers */
42817
42818 diff -urNp linux-2.6.39.1/drivers/video/geode/geodefb.h linux-2.6.39.1/drivers/video/geode/geodefb.h
42819 --- linux-2.6.39.1/drivers/video/geode/geodefb.h 2011-05-19 00:06:34.000000000 -0400
42820 +++ linux-2.6.39.1/drivers/video/geode/geodefb.h 2011-05-22 19:36:32.000000000 -0400
42821 @@ -31,8 +31,8 @@ struct geodefb_par {
42822 int panel_y;
42823 void __iomem *dc_regs;
42824 void __iomem *vid_regs;
42825 - struct geode_dc_ops *dc_ops;
42826 - struct geode_vid_ops *vid_ops;
42827 + const struct geode_dc_ops *dc_ops;
42828 + const struct geode_vid_ops *vid_ops;
42829 };
42830
42831 #endif /* !__GEODEFB_H__ */
42832 diff -urNp linux-2.6.39.1/drivers/video/geode/video_cs5530.c linux-2.6.39.1/drivers/video/geode/video_cs5530.c
42833 --- linux-2.6.39.1/drivers/video/geode/video_cs5530.c 2011-05-19 00:06:34.000000000 -0400
42834 +++ linux-2.6.39.1/drivers/video/geode/video_cs5530.c 2011-05-22 19:36:32.000000000 -0400
42835 @@ -186,7 +186,7 @@ static int cs5530_blank_display(struct f
42836 return 0;
42837 }
42838
42839 -struct geode_vid_ops cs5530_vid_ops = {
42840 +const struct geode_vid_ops cs5530_vid_ops = {
42841 .set_dclk = cs5530_set_dclk_frequency,
42842 .configure_display = cs5530_configure_display,
42843 .blank_display = cs5530_blank_display,
42844 diff -urNp linux-2.6.39.1/drivers/video/geode/video_cs5530.h linux-2.6.39.1/drivers/video/geode/video_cs5530.h
42845 --- linux-2.6.39.1/drivers/video/geode/video_cs5530.h 2011-05-19 00:06:34.000000000 -0400
42846 +++ linux-2.6.39.1/drivers/video/geode/video_cs5530.h 2011-05-22 19:36:32.000000000 -0400
42847 @@ -15,7 +15,7 @@
42848 #ifndef __VIDEO_CS5530_H__
42849 #define __VIDEO_CS5530_H__
42850
42851 -extern struct geode_vid_ops cs5530_vid_ops;
42852 +extern const struct geode_vid_ops cs5530_vid_ops;
42853
42854 /* CS5530 Video device registers */
42855
42856 diff -urNp linux-2.6.39.1/drivers/video/i810/i810_accel.c linux-2.6.39.1/drivers/video/i810/i810_accel.c
42857 --- linux-2.6.39.1/drivers/video/i810/i810_accel.c 2011-05-19 00:06:34.000000000 -0400
42858 +++ linux-2.6.39.1/drivers/video/i810/i810_accel.c 2011-05-22 19:36:32.000000000 -0400
42859 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct
42860 }
42861 }
42862 printk("ringbuffer lockup!!!\n");
42863 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42864 i810_report_error(mmio);
42865 par->dev_flags |= LOCKUP;
42866 info->pixmap.scan_align = 1;
42867 diff -urNp linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c
42868 --- linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c 2011-05-19 00:06:34.000000000 -0400
42869 +++ linux-2.6.39.1/drivers/video/matrox/matroxfb_base.c 2011-05-22 19:36:32.000000000 -0400
42870 @@ -1232,7 +1232,7 @@ static struct fb_ops matroxfb_ops = {
42871 #define RSText 0x7
42872 #define RSText8 0x8
42873 /* 9-F */
42874 -static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42875 +static const struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42876 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
42877 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
42878 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
42879 diff -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
42880 --- linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c 2011-05-19 00:06:34.000000000 -0400
42881 +++ linux-2.6.39.1/drivers/video/omap/lcd_ams_delta.c 2011-05-22 19:36:32.000000000 -0400
42882 @@ -87,7 +87,7 @@ static int ams_delta_lcd_get_contrast(st
42883 return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
42884 }
42885
42886 -static struct lcd_ops ams_delta_lcd_ops = {
42887 +static const struct lcd_ops ams_delta_lcd_ops = {
42888 .get_power = ams_delta_lcd_get_power,
42889 .set_power = ams_delta_lcd_set_power,
42890 .get_contrast = ams_delta_lcd_get_contrast,
42891 diff -urNp linux-2.6.39.1/drivers/video/pxa3xx-gcu.c linux-2.6.39.1/drivers/video/pxa3xx-gcu.c
42892 --- linux-2.6.39.1/drivers/video/pxa3xx-gcu.c 2011-05-19 00:06:34.000000000 -0400
42893 +++ linux-2.6.39.1/drivers/video/pxa3xx-gcu.c 2011-05-22 19:36:32.000000000 -0400
42894 @@ -103,7 +103,7 @@ struct pxa3xx_gcu_priv {
42895 dma_addr_t shared_phys;
42896 struct resource *resource_mem;
42897 struct miscdevice misc_dev;
42898 - struct file_operations misc_fops;
42899 + const struct file_operations misc_fops;
42900 wait_queue_head_t wait_idle;
42901 wait_queue_head_t wait_free;
42902 spinlock_t spinlock;
42903 diff -urNp linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c
42904 --- linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c 2011-05-19 00:06:34.000000000 -0400
42905 +++ linux-2.6.39.1/drivers/video/sh_mobile_lcdcfb.c 2011-05-22 19:36:32.000000000 -0400
42906 @@ -245,7 +245,7 @@ static unsigned long lcdc_sys_read_data(
42907 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
42908 }
42909
42910 -struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42911 +const struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42912 lcdc_sys_write_index,
42913 lcdc_sys_write_data,
42914 lcdc_sys_read_data,
42915 diff -urNp linux-2.6.39.1/drivers/video/udlfb.c linux-2.6.39.1/drivers/video/udlfb.c
42916 --- linux-2.6.39.1/drivers/video/udlfb.c 2011-05-19 00:06:34.000000000 -0400
42917 +++ linux-2.6.39.1/drivers/video/udlfb.c 2011-05-22 19:36:32.000000000 -0400
42918 @@ -584,11 +584,11 @@ int dlfb_handle_damage(struct dlfb_data
42919 dlfb_urb_completion(urb);
42920
42921 error:
42922 - atomic_add(bytes_sent, &dev->bytes_sent);
42923 - atomic_add(bytes_identical, &dev->bytes_identical);
42924 - atomic_add(width*height*2, &dev->bytes_rendered);
42925 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42926 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42927 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42928 end_cycles = get_cycles();
42929 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42930 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42931 >> 10)), /* Kcycles */
42932 &dev->cpu_kcycles_used);
42933
42934 @@ -709,11 +709,11 @@ static void dlfb_dpy_deferred_io(struct
42935 dlfb_urb_completion(urb);
42936
42937 error:
42938 - atomic_add(bytes_sent, &dev->bytes_sent);
42939 - atomic_add(bytes_identical, &dev->bytes_identical);
42940 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42941 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42942 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42943 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42944 end_cycles = get_cycles();
42945 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42946 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42947 >> 10)), /* Kcycles */
42948 &dev->cpu_kcycles_used);
42949 }
42950 @@ -1301,7 +1301,7 @@ static ssize_t metrics_bytes_rendered_sh
42951 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42952 struct dlfb_data *dev = fb_info->par;
42953 return snprintf(buf, PAGE_SIZE, "%u\n",
42954 - atomic_read(&dev->bytes_rendered));
42955 + atomic_read_unchecked(&dev->bytes_rendered));
42956 }
42957
42958 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42959 @@ -1309,7 +1309,7 @@ static ssize_t metrics_bytes_identical_s
42960 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42961 struct dlfb_data *dev = fb_info->par;
42962 return snprintf(buf, PAGE_SIZE, "%u\n",
42963 - atomic_read(&dev->bytes_identical));
42964 + atomic_read_unchecked(&dev->bytes_identical));
42965 }
42966
42967 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42968 @@ -1317,7 +1317,7 @@ static ssize_t metrics_bytes_sent_show(s
42969 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42970 struct dlfb_data *dev = fb_info->par;
42971 return snprintf(buf, PAGE_SIZE, "%u\n",
42972 - atomic_read(&dev->bytes_sent));
42973 + atomic_read_unchecked(&dev->bytes_sent));
42974 }
42975
42976 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42977 @@ -1325,7 +1325,7 @@ static ssize_t metrics_cpu_kcycles_used_
42978 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42979 struct dlfb_data *dev = fb_info->par;
42980 return snprintf(buf, PAGE_SIZE, "%u\n",
42981 - atomic_read(&dev->cpu_kcycles_used));
42982 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42983 }
42984
42985 static ssize_t edid_show(
42986 @@ -1382,10 +1382,10 @@ static ssize_t metrics_reset_store(struc
42987 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42988 struct dlfb_data *dev = fb_info->par;
42989
42990 - atomic_set(&dev->bytes_rendered, 0);
42991 - atomic_set(&dev->bytes_identical, 0);
42992 - atomic_set(&dev->bytes_sent, 0);
42993 - atomic_set(&dev->cpu_kcycles_used, 0);
42994 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42995 + atomic_set_unchecked(&dev->bytes_identical, 0);
42996 + atomic_set_unchecked(&dev->bytes_sent, 0);
42997 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42998
42999 return count;
43000 }
43001 diff -urNp linux-2.6.39.1/drivers/video/uvesafb.c linux-2.6.39.1/drivers/video/uvesafb.c
43002 --- linux-2.6.39.1/drivers/video/uvesafb.c 2011-05-19 00:06:34.000000000 -0400
43003 +++ linux-2.6.39.1/drivers/video/uvesafb.c 2011-05-22 19:36:32.000000000 -0400
43004 @@ -19,6 +19,7 @@
43005 #include <linux/io.h>
43006 #include <linux/mutex.h>
43007 #include <linux/slab.h>
43008 +#include <linux/moduleloader.h>
43009 #include <video/edid.h>
43010 #include <video/uvesafb.h>
43011 #ifdef CONFIG_X86
43012 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
43013 NULL,
43014 };
43015
43016 - return call_usermodehelper(v86d_path, argv, envp, 1);
43017 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
43018 }
43019
43020 /*
43021 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
43022 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43023 par->pmi_setpal = par->ypan = 0;
43024 } else {
43025 +
43026 +#ifdef CONFIG_PAX_KERNEXEC
43027 +#ifdef CONFIG_MODULES
43028 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43029 +#endif
43030 + if (!par->pmi_code) {
43031 + par->pmi_setpal = par->ypan = 0;
43032 + return 0;
43033 + }
43034 +#endif
43035 +
43036 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43037 + task->t.regs.edi);
43038 +
43039 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43040 + pax_open_kernel();
43041 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43042 + pax_close_kernel();
43043 +
43044 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43045 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43046 +#else
43047 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43048 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43049 +#endif
43050 +
43051 printk(KERN_INFO "uvesafb: protected mode interface info at "
43052 "%04x:%04x\n",
43053 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43054 @@ -1821,6 +1844,11 @@ out:
43055 if (par->vbe_modes)
43056 kfree(par->vbe_modes);
43057
43058 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43059 + if (par->pmi_code)
43060 + module_free_exec(NULL, par->pmi_code);
43061 +#endif
43062 +
43063 framebuffer_release(info);
43064 return err;
43065 }
43066 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platfor
43067 kfree(par->vbe_state_orig);
43068 if (par->vbe_state_saved)
43069 kfree(par->vbe_state_saved);
43070 +
43071 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43072 + if (par->pmi_code)
43073 + module_free_exec(NULL, par->pmi_code);
43074 +#endif
43075 +
43076 }
43077
43078 framebuffer_release(info);
43079 @@ -2013,7 +2047,7 @@ static int param_set_scroll(const char *
43080
43081 return 0;
43082 }
43083 -static struct kernel_param_ops param_ops_scroll = {
43084 +static const struct kernel_param_ops param_ops_scroll = {
43085 .set = param_set_scroll,
43086 };
43087 #define param_check_scroll(name, p) __param_check(name, p, void)
43088 diff -urNp linux-2.6.39.1/drivers/video/vesafb.c linux-2.6.39.1/drivers/video/vesafb.c
43089 --- linux-2.6.39.1/drivers/video/vesafb.c 2011-05-19 00:06:34.000000000 -0400
43090 +++ linux-2.6.39.1/drivers/video/vesafb.c 2011-05-22 19:36:32.000000000 -0400
43091 @@ -9,6 +9,7 @@
43092 */
43093
43094 #include <linux/module.h>
43095 +#include <linux/moduleloader.h>
43096 #include <linux/kernel.h>
43097 #include <linux/errno.h>
43098 #include <linux/string.h>
43099 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
43100 static int vram_total __initdata; /* Set total amount of memory */
43101 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43102 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43103 -static void (*pmi_start)(void) __read_mostly;
43104 -static void (*pmi_pal) (void) __read_mostly;
43105 +static void (*pmi_start)(void) __read_only;
43106 +static void (*pmi_pal) (void) __read_only;
43107 static int depth __read_mostly;
43108 static int vga_compat __read_mostly;
43109 /* --------------------------------------------------------------------- */
43110 @@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
43111 unsigned int size_vmode;
43112 unsigned int size_remap;
43113 unsigned int size_total;
43114 + void *pmi_code = NULL;
43115
43116 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43117 return -ENODEV;
43118 @@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
43119 size_remap = size_total;
43120 vesafb_fix.smem_len = size_remap;
43121
43122 -#ifndef __i386__
43123 - screen_info.vesapm_seg = 0;
43124 -#endif
43125 -
43126 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43127 printk(KERN_WARNING
43128 "vesafb: cannot reserve video memory at 0x%lx\n",
43129 @@ -306,9 +304,21 @@ static int __init vesafb_probe(struct pl
43130 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43131 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43132
43133 +#ifdef __i386__
43134 +
43135 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43136 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
43137 + if (!pmi_code)
43138 +#elif !defined(CONFIG_PAX_KERNEXEC)
43139 + if (0)
43140 +#endif
43141 +
43142 +#endif
43143 + screen_info.vesapm_seg = 0;
43144 +
43145 if (screen_info.vesapm_seg) {
43146 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43147 - screen_info.vesapm_seg,screen_info.vesapm_off);
43148 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43149 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43150 }
43151
43152 if (screen_info.vesapm_seg < 0xc000)
43153 @@ -316,9 +326,25 @@ static int __init vesafb_probe(struct pl
43154
43155 if (ypan || pmi_setpal) {
43156 unsigned short *pmi_base;
43157 - pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43158 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43159 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43160 +
43161 + pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43162 +
43163 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43164 + pax_open_kernel();
43165 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43166 +#else
43167 + pmi_code = pmi_base;
43168 +#endif
43169 +
43170 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43171 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43172 +
43173 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43174 + pmi_start = ktva_ktla(pmi_start);
43175 + pmi_pal = ktva_ktla(pmi_pal);
43176 + pax_close_kernel();
43177 +#endif
43178 +
43179 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43180 if (pmi_base[3]) {
43181 printk(KERN_INFO "vesafb: pmi: ports = ");
43182 @@ -487,6 +513,11 @@ static int __init vesafb_probe(struct pl
43183 info->node, info->fix.id);
43184 return 0;
43185 err:
43186 +
43187 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43188 + module_free_exec(NULL, pmi_code);
43189 +#endif
43190 +
43191 if (info->screen_base)
43192 iounmap(info->screen_base);
43193 framebuffer_release(info);
43194 diff -urNp linux-2.6.39.1/drivers/virtio/virtio_balloon.c linux-2.6.39.1/drivers/virtio/virtio_balloon.c
43195 --- linux-2.6.39.1/drivers/virtio/virtio_balloon.c 2011-05-19 00:06:34.000000000 -0400
43196 +++ linux-2.6.39.1/drivers/virtio/virtio_balloon.c 2011-05-22 19:36:32.000000000 -0400
43197 @@ -176,6 +176,8 @@ static void update_balloon_stats(struct
43198 struct sysinfo i;
43199 int idx = 0;
43200
43201 + pax_track_stack();
43202 +
43203 all_vm_events(events);
43204 si_meminfo(&i);
43205
43206 diff -urNp linux-2.6.39.1/drivers/xen/gntalloc.c linux-2.6.39.1/drivers/xen/gntalloc.c
43207 --- linux-2.6.39.1/drivers/xen/gntalloc.c 2011-05-19 00:06:34.000000000 -0400
43208 +++ linux-2.6.39.1/drivers/xen/gntalloc.c 2011-05-22 19:36:32.000000000 -0400
43209 @@ -440,7 +440,7 @@ static void gntalloc_vma_close(struct vm
43210 spin_unlock(&gref_lock);
43211 }
43212
43213 -static struct vm_operations_struct gntalloc_vmops = {
43214 +static const struct vm_operations_struct gntalloc_vmops = {
43215 .close = gntalloc_vma_close,
43216 };
43217
43218 diff -urNp linux-2.6.39.1/drivers/xen/gntdev.c linux-2.6.39.1/drivers/xen/gntdev.c
43219 --- linux-2.6.39.1/drivers/xen/gntdev.c 2011-05-19 00:06:34.000000000 -0400
43220 +++ linux-2.6.39.1/drivers/xen/gntdev.c 2011-05-22 19:36:32.000000000 -0400
43221 @@ -340,7 +340,7 @@ static void gntdev_vma_close(struct vm_a
43222 gntdev_put_map(map);
43223 }
43224
43225 -static struct vm_operations_struct gntdev_vmops = {
43226 +static const struct vm_operations_struct gntdev_vmops = {
43227 .close = gntdev_vma_close,
43228 };
43229
43230 @@ -404,7 +404,7 @@ static void mn_release(struct mmu_notifi
43231 spin_unlock(&priv->lock);
43232 }
43233
43234 -struct mmu_notifier_ops gntdev_mmu_ops = {
43235 +const struct mmu_notifier_ops gntdev_mmu_ops = {
43236 .release = mn_release,
43237 .invalidate_page = mn_invl_page,
43238 .invalidate_range_start = mn_invl_range_start,
43239 diff -urNp linux-2.6.39.1/drivers/xen/xenfs/privcmd.c linux-2.6.39.1/drivers/xen/xenfs/privcmd.c
43240 --- linux-2.6.39.1/drivers/xen/xenfs/privcmd.c 2011-05-19 00:06:34.000000000 -0400
43241 +++ linux-2.6.39.1/drivers/xen/xenfs/privcmd.c 2011-05-22 19:36:32.000000000 -0400
43242 @@ -268,7 +268,7 @@ static int mmap_return_errors(void *data
43243 return put_user(*mfnp, st->user++);
43244 }
43245
43246 -static struct vm_operations_struct privcmd_vm_ops;
43247 +static const struct vm_operations_struct privcmd_vm_ops;
43248
43249 static long privcmd_ioctl_mmap_batch(void __user *udata)
43250 {
43251 @@ -369,7 +369,7 @@ static int privcmd_fault(struct vm_area_
43252 return VM_FAULT_SIGBUS;
43253 }
43254
43255 -static struct vm_operations_struct privcmd_vm_ops = {
43256 +static const struct vm_operations_struct privcmd_vm_ops = {
43257 .fault = privcmd_fault
43258 };
43259
43260 diff -urNp linux-2.6.39.1/fs/9p/vfs_inode.c linux-2.6.39.1/fs/9p/vfs_inode.c
43261 --- linux-2.6.39.1/fs/9p/vfs_inode.c 2011-05-19 00:06:34.000000000 -0400
43262 +++ linux-2.6.39.1/fs/9p/vfs_inode.c 2011-05-22 19:36:32.000000000 -0400
43263 @@ -1210,7 +1210,7 @@ static void *v9fs_vfs_follow_link(struct
43264 void
43265 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43266 {
43267 - char *s = nd_get_link(nd);
43268 + const char *s = nd_get_link(nd);
43269
43270 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
43271 IS_ERR(s) ? "<error>" : s);
43272 diff -urNp linux-2.6.39.1/fs/aio.c linux-2.6.39.1/fs/aio.c
43273 --- linux-2.6.39.1/fs/aio.c 2011-05-19 00:06:34.000000000 -0400
43274 +++ linux-2.6.39.1/fs/aio.c 2011-06-03 01:00:34.000000000 -0400
43275 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx
43276 size += sizeof(struct io_event) * nr_events;
43277 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43278
43279 - if (nr_pages < 0)
43280 + if (nr_pages <= 0)
43281 return -EINVAL;
43282
43283 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43284 @@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ct
43285 struct aio_timeout to;
43286 int retry = 0;
43287
43288 + pax_track_stack();
43289 +
43290 /* needed to zero any padding within an entry (there shouldn't be
43291 * any, but C is fun!
43292 */
43293 @@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *i
43294 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43295 {
43296 ssize_t ret;
43297 + struct iovec iovstack;
43298
43299 #ifdef CONFIG_COMPAT
43300 if (compat)
43301 ret = compat_rw_copy_check_uvector(type,
43302 (struct compat_iovec __user *)kiocb->ki_buf,
43303 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43304 + kiocb->ki_nbytes, 1, &iovstack,
43305 &kiocb->ki_iovec);
43306 else
43307 #endif
43308 ret = rw_copy_check_uvector(type,
43309 (struct iovec __user *)kiocb->ki_buf,
43310 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43311 + kiocb->ki_nbytes, 1, &iovstack,
43312 &kiocb->ki_iovec);
43313 if (ret < 0)
43314 goto out;
43315
43316 + if (kiocb->ki_iovec == &iovstack) {
43317 + kiocb->ki_inline_vec = iovstack;
43318 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
43319 + }
43320 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43321 kiocb->ki_cur_seg = 0;
43322 /* ki_nbytes/left now reflect bytes instead of segs */
43323 diff -urNp linux-2.6.39.1/fs/attr.c linux-2.6.39.1/fs/attr.c
43324 --- linux-2.6.39.1/fs/attr.c 2011-05-19 00:06:34.000000000 -0400
43325 +++ linux-2.6.39.1/fs/attr.c 2011-05-22 19:41:37.000000000 -0400
43326 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
43327 unsigned long limit;
43328
43329 limit = rlimit(RLIMIT_FSIZE);
43330 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43331 if (limit != RLIM_INFINITY && offset > limit)
43332 goto out_sig;
43333 if (offset > inode->i_sb->s_maxbytes)
43334 diff -urNp linux-2.6.39.1/fs/befs/linuxvfs.c linux-2.6.39.1/fs/befs/linuxvfs.c
43335 --- linux-2.6.39.1/fs/befs/linuxvfs.c 2011-05-19 00:06:34.000000000 -0400
43336 +++ linux-2.6.39.1/fs/befs/linuxvfs.c 2011-05-22 19:36:32.000000000 -0400
43337 @@ -498,7 +498,7 @@ static void befs_put_link(struct dentry
43338 {
43339 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43340 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43341 - char *link = nd_get_link(nd);
43342 + const char *link = nd_get_link(nd);
43343 if (!IS_ERR(link))
43344 kfree(link);
43345 }
43346 diff -urNp linux-2.6.39.1/fs/binfmt_aout.c linux-2.6.39.1/fs/binfmt_aout.c
43347 --- linux-2.6.39.1/fs/binfmt_aout.c 2011-05-19 00:06:34.000000000 -0400
43348 +++ linux-2.6.39.1/fs/binfmt_aout.c 2011-05-22 19:41:37.000000000 -0400
43349 @@ -16,6 +16,7 @@
43350 #include <linux/string.h>
43351 #include <linux/fs.h>
43352 #include <linux/file.h>
43353 +#include <linux/security.h>
43354 #include <linux/stat.h>
43355 #include <linux/fcntl.h>
43356 #include <linux/ptrace.h>
43357 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
43358 #endif
43359 # define START_STACK(u) ((void __user *)u.start_stack)
43360
43361 + memset(&dump, 0, sizeof(dump));
43362 +
43363 fs = get_fs();
43364 set_fs(KERNEL_DS);
43365 has_dumped = 1;
43366 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
43367
43368 /* If the size of the dump file exceeds the rlimit, then see what would happen
43369 if we wrote the stack, but not the data area. */
43370 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43371 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43372 dump.u_dsize = 0;
43373
43374 /* Make sure we have enough room to write the stack and data areas. */
43375 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43376 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43377 dump.u_ssize = 0;
43378
43379 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
43380 rlim = rlimit(RLIMIT_DATA);
43381 if (rlim >= RLIM_INFINITY)
43382 rlim = ~0;
43383 +
43384 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43385 if (ex.a_data + ex.a_bss > rlim)
43386 return -ENOMEM;
43387
43388 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
43389 install_exec_creds(bprm);
43390 current->flags &= ~PF_FORKNOEXEC;
43391
43392 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43393 + current->mm->pax_flags = 0UL;
43394 +#endif
43395 +
43396 +#ifdef CONFIG_PAX_PAGEEXEC
43397 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43398 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43399 +
43400 +#ifdef CONFIG_PAX_EMUTRAMP
43401 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43402 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43403 +#endif
43404 +
43405 +#ifdef CONFIG_PAX_MPROTECT
43406 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43407 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43408 +#endif
43409 +
43410 + }
43411 +#endif
43412 +
43413 if (N_MAGIC(ex) == OMAGIC) {
43414 unsigned long text_addr, map_size;
43415 loff_t pos;
43416 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
43417
43418 down_write(&current->mm->mmap_sem);
43419 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43420 - PROT_READ | PROT_WRITE | PROT_EXEC,
43421 + PROT_READ | PROT_WRITE,
43422 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43423 fd_offset + ex.a_text);
43424 up_write(&current->mm->mmap_sem);
43425 diff -urNp linux-2.6.39.1/fs/binfmt_elf.c linux-2.6.39.1/fs/binfmt_elf.c
43426 --- linux-2.6.39.1/fs/binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
43427 +++ linux-2.6.39.1/fs/binfmt_elf.c 2011-05-22 19:41:37.000000000 -0400
43428 @@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
43429 #define elf_core_dump NULL
43430 #endif
43431
43432 +#ifdef CONFIG_PAX_MPROTECT
43433 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43434 +#endif
43435 +
43436 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43437 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43438 #else
43439 @@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
43440 .load_binary = load_elf_binary,
43441 .load_shlib = load_elf_library,
43442 .core_dump = elf_core_dump,
43443 +
43444 +#ifdef CONFIG_PAX_MPROTECT
43445 + .handle_mprotect= elf_handle_mprotect,
43446 +#endif
43447 +
43448 .min_coredump = ELF_EXEC_PAGESIZE,
43449 };
43450
43451 @@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
43452
43453 static int set_brk(unsigned long start, unsigned long end)
43454 {
43455 + unsigned long e = end;
43456 +
43457 start = ELF_PAGEALIGN(start);
43458 end = ELF_PAGEALIGN(end);
43459 if (end > start) {
43460 @@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
43461 if (BAD_ADDR(addr))
43462 return addr;
43463 }
43464 - current->mm->start_brk = current->mm->brk = end;
43465 + current->mm->start_brk = current->mm->brk = e;
43466 return 0;
43467 }
43468
43469 @@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
43470 elf_addr_t __user *u_rand_bytes;
43471 const char *k_platform = ELF_PLATFORM;
43472 const char *k_base_platform = ELF_BASE_PLATFORM;
43473 - unsigned char k_rand_bytes[16];
43474 + u32 k_rand_bytes[4];
43475 int items;
43476 elf_addr_t *elf_info;
43477 int ei_index = 0;
43478 const struct cred *cred = current_cred();
43479 struct vm_area_struct *vma;
43480 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43481 +
43482 + pax_track_stack();
43483
43484 /*
43485 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43486 @@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
43487 * Generate 16 random bytes for userspace PRNG seeding.
43488 */
43489 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43490 - u_rand_bytes = (elf_addr_t __user *)
43491 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43492 + srandom32(k_rand_bytes[0] ^ random32());
43493 + srandom32(k_rand_bytes[1] ^ random32());
43494 + srandom32(k_rand_bytes[2] ^ random32());
43495 + srandom32(k_rand_bytes[3] ^ random32());
43496 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43497 + u_rand_bytes = (elf_addr_t __user *) p;
43498 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43499 return -EFAULT;
43500
43501 @@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
43502 return -EFAULT;
43503 current->mm->env_end = p;
43504
43505 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43506 +
43507 /* Put the elf_info on the stack in the right place. */
43508 sp = (elf_addr_t __user *)envp + 1;
43509 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43510 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43511 return -EFAULT;
43512 return 0;
43513 }
43514 @@ -381,10 +401,10 @@ static unsigned long load_elf_interp(str
43515 {
43516 struct elf_phdr *elf_phdata;
43517 struct elf_phdr *eppnt;
43518 - unsigned long load_addr = 0;
43519 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43520 int load_addr_set = 0;
43521 unsigned long last_bss = 0, elf_bss = 0;
43522 - unsigned long error = ~0UL;
43523 + unsigned long error = -EINVAL;
43524 unsigned long total_size;
43525 int retval, i, size;
43526
43527 @@ -430,6 +450,11 @@ static unsigned long load_elf_interp(str
43528 goto out_close;
43529 }
43530
43531 +#ifdef CONFIG_PAX_SEGMEXEC
43532 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43533 + pax_task_size = SEGMEXEC_TASK_SIZE;
43534 +#endif
43535 +
43536 eppnt = elf_phdata;
43537 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43538 if (eppnt->p_type == PT_LOAD) {
43539 @@ -473,8 +498,8 @@ static unsigned long load_elf_interp(str
43540 k = load_addr + eppnt->p_vaddr;
43541 if (BAD_ADDR(k) ||
43542 eppnt->p_filesz > eppnt->p_memsz ||
43543 - eppnt->p_memsz > TASK_SIZE ||
43544 - TASK_SIZE - eppnt->p_memsz < k) {
43545 + eppnt->p_memsz > pax_task_size ||
43546 + pax_task_size - eppnt->p_memsz < k) {
43547 error = -ENOMEM;
43548 goto out_close;
43549 }
43550 @@ -528,6 +553,193 @@ out:
43551 return error;
43552 }
43553
43554 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
43555 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
43556 +{
43557 + unsigned long pax_flags = 0UL;
43558 +
43559 +#ifdef CONFIG_PAX_PAGEEXEC
43560 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43561 + pax_flags |= MF_PAX_PAGEEXEC;
43562 +#endif
43563 +
43564 +#ifdef CONFIG_PAX_SEGMEXEC
43565 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43566 + pax_flags |= MF_PAX_SEGMEXEC;
43567 +#endif
43568 +
43569 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43570 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43571 + if ((__supported_pte_mask & _PAGE_NX))
43572 + pax_flags &= ~MF_PAX_SEGMEXEC;
43573 + else
43574 + pax_flags &= ~MF_PAX_PAGEEXEC;
43575 + }
43576 +#endif
43577 +
43578 +#ifdef CONFIG_PAX_EMUTRAMP
43579 + if (elf_phdata->p_flags & PF_EMUTRAMP)
43580 + pax_flags |= MF_PAX_EMUTRAMP;
43581 +#endif
43582 +
43583 +#ifdef CONFIG_PAX_MPROTECT
43584 + if (elf_phdata->p_flags & PF_MPROTECT)
43585 + pax_flags |= MF_PAX_MPROTECT;
43586 +#endif
43587 +
43588 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43589 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43590 + pax_flags |= MF_PAX_RANDMMAP;
43591 +#endif
43592 +
43593 + return pax_flags;
43594 +}
43595 +#endif
43596 +
43597 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43598 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
43599 +{
43600 + unsigned long pax_flags = 0UL;
43601 +
43602 +#ifdef CONFIG_PAX_PAGEEXEC
43603 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43604 + pax_flags |= MF_PAX_PAGEEXEC;
43605 +#endif
43606 +
43607 +#ifdef CONFIG_PAX_SEGMEXEC
43608 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43609 + pax_flags |= MF_PAX_SEGMEXEC;
43610 +#endif
43611 +
43612 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43613 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43614 + if ((__supported_pte_mask & _PAGE_NX))
43615 + pax_flags &= ~MF_PAX_SEGMEXEC;
43616 + else
43617 + pax_flags &= ~MF_PAX_PAGEEXEC;
43618 + }
43619 +#endif
43620 +
43621 +#ifdef CONFIG_PAX_EMUTRAMP
43622 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43623 + pax_flags |= MF_PAX_EMUTRAMP;
43624 +#endif
43625 +
43626 +#ifdef CONFIG_PAX_MPROTECT
43627 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43628 + pax_flags |= MF_PAX_MPROTECT;
43629 +#endif
43630 +
43631 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43632 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43633 + pax_flags |= MF_PAX_RANDMMAP;
43634 +#endif
43635 +
43636 + return pax_flags;
43637 +}
43638 +#endif
43639 +
43640 +#ifdef CONFIG_PAX_EI_PAX
43641 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43642 +{
43643 + unsigned long pax_flags = 0UL;
43644 +
43645 +#ifdef CONFIG_PAX_PAGEEXEC
43646 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43647 + pax_flags |= MF_PAX_PAGEEXEC;
43648 +#endif
43649 +
43650 +#ifdef CONFIG_PAX_SEGMEXEC
43651 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43652 + pax_flags |= MF_PAX_SEGMEXEC;
43653 +#endif
43654 +
43655 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43656 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43657 + if ((__supported_pte_mask & _PAGE_NX))
43658 + pax_flags &= ~MF_PAX_SEGMEXEC;
43659 + else
43660 + pax_flags &= ~MF_PAX_PAGEEXEC;
43661 + }
43662 +#endif
43663 +
43664 +#ifdef CONFIG_PAX_EMUTRAMP
43665 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43666 + pax_flags |= MF_PAX_EMUTRAMP;
43667 +#endif
43668 +
43669 +#ifdef CONFIG_PAX_MPROTECT
43670 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43671 + pax_flags |= MF_PAX_MPROTECT;
43672 +#endif
43673 +
43674 +#ifdef CONFIG_PAX_ASLR
43675 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43676 + pax_flags |= MF_PAX_RANDMMAP;
43677 +#endif
43678 +
43679 + return pax_flags;
43680 +}
43681 +#endif
43682 +
43683 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43684 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43685 +{
43686 + unsigned long pax_flags = 0UL;
43687 +
43688 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43689 + unsigned long i;
43690 + int found_flags = 0;
43691 +#endif
43692 +
43693 +#ifdef CONFIG_PAX_EI_PAX
43694 + pax_flags = pax_parse_ei_pax(elf_ex);
43695 +#endif
43696 +
43697 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43698 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43699 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43700 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43701 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43702 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43703 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43704 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43705 + return -EINVAL;
43706 +
43707 +#ifdef CONFIG_PAX_SOFTMODE
43708 + if (pax_softmode)
43709 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
43710 + else
43711 +#endif
43712 +
43713 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
43714 + found_flags = 1;
43715 + break;
43716 + }
43717 +#endif
43718 +
43719 +#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
43720 + if (found_flags == 0) {
43721 + struct elf_phdr phdr;
43722 + memset(&phdr, 0, sizeof(phdr));
43723 + phdr.p_flags = PF_NOEMUTRAMP;
43724 +#ifdef CONFIG_PAX_SOFTMODE
43725 + if (pax_softmode)
43726 + pax_flags = pax_parse_softmode(&phdr);
43727 + else
43728 +#endif
43729 + pax_flags = pax_parse_hardmode(&phdr);
43730 + }
43731 +#endif
43732 +
43733 + if (0 > pax_check_flags(&pax_flags))
43734 + return -EINVAL;
43735 +
43736 + current->mm->pax_flags = pax_flags;
43737 + return 0;
43738 +}
43739 +#endif
43740 +
43741 /*
43742 * These are the functions used to load ELF style executables and shared
43743 * libraries. There is no binary dependent code anywhere else.
43744 @@ -544,6 +756,11 @@ static unsigned long randomize_stack_top
43745 {
43746 unsigned int random_variable = 0;
43747
43748 +#ifdef CONFIG_PAX_RANDUSTACK
43749 + if (randomize_va_space)
43750 + return stack_top - current->mm->delta_stack;
43751 +#endif
43752 +
43753 if ((current->flags & PF_RANDOMIZE) &&
43754 !(current->personality & ADDR_NO_RANDOMIZE)) {
43755 random_variable = get_random_int() & STACK_RND_MASK;
43756 @@ -562,7 +779,7 @@ static int load_elf_binary(struct linux_
43757 unsigned long load_addr = 0, load_bias = 0;
43758 int load_addr_set = 0;
43759 char * elf_interpreter = NULL;
43760 - unsigned long error;
43761 + unsigned long error = 0;
43762 struct elf_phdr *elf_ppnt, *elf_phdata;
43763 unsigned long elf_bss, elf_brk;
43764 int retval, i;
43765 @@ -572,11 +789,11 @@ static int load_elf_binary(struct linux_
43766 unsigned long start_code, end_code, start_data, end_data;
43767 unsigned long reloc_func_desc __maybe_unused = 0;
43768 int executable_stack = EXSTACK_DEFAULT;
43769 - unsigned long def_flags = 0;
43770 struct {
43771 struct elfhdr elf_ex;
43772 struct elfhdr interp_elf_ex;
43773 } *loc;
43774 + unsigned long pax_task_size = TASK_SIZE;
43775
43776 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43777 if (!loc) {
43778 @@ -714,11 +931,81 @@ static int load_elf_binary(struct linux_
43779
43780 /* OK, This is the point of no return */
43781 current->flags &= ~PF_FORKNOEXEC;
43782 - current->mm->def_flags = def_flags;
43783 +
43784 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43785 + current->mm->pax_flags = 0UL;
43786 +#endif
43787 +
43788 +#ifdef CONFIG_PAX_DLRESOLVE
43789 + current->mm->call_dl_resolve = 0UL;
43790 +#endif
43791 +
43792 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43793 + current->mm->call_syscall = 0UL;
43794 +#endif
43795 +
43796 +#ifdef CONFIG_PAX_ASLR
43797 + current->mm->delta_mmap = 0UL;
43798 + current->mm->delta_stack = 0UL;
43799 +#endif
43800 +
43801 + current->mm->def_flags = 0;
43802 +
43803 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43804 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
43805 + send_sig(SIGKILL, current, 0);
43806 + goto out_free_dentry;
43807 + }
43808 +#endif
43809 +
43810 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43811 + pax_set_initial_flags(bprm);
43812 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43813 + if (pax_set_initial_flags_func)
43814 + (pax_set_initial_flags_func)(bprm);
43815 +#endif
43816 +
43817 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43818 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43819 + current->mm->context.user_cs_limit = PAGE_SIZE;
43820 + current->mm->def_flags |= VM_PAGEEXEC;
43821 + }
43822 +#endif
43823 +
43824 +#ifdef CONFIG_PAX_SEGMEXEC
43825 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43826 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43827 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43828 + pax_task_size = SEGMEXEC_TASK_SIZE;
43829 + current->mm->def_flags |= VM_NOHUGEPAGE;
43830 + }
43831 +#endif
43832 +
43833 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43834 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43835 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43836 + put_cpu();
43837 + }
43838 +#endif
43839
43840 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43841 may depend on the personality. */
43842 SET_PERSONALITY(loc->elf_ex);
43843 +
43844 +#ifdef CONFIG_PAX_ASLR
43845 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43846 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43847 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43848 + }
43849 +#endif
43850 +
43851 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43852 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43853 + executable_stack = EXSTACK_DISABLE_X;
43854 + current->personality &= ~READ_IMPLIES_EXEC;
43855 + } else
43856 +#endif
43857 +
43858 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43859 current->personality |= READ_IMPLIES_EXEC;
43860
43861 @@ -800,6 +1087,20 @@ static int load_elf_binary(struct linux_
43862 #else
43863 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43864 #endif
43865 +
43866 +#ifdef CONFIG_PAX_RANDMMAP
43867 + /* PaX: randomize base address at the default exe base if requested */
43868 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43869 +#ifdef CONFIG_SPARC64
43870 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43871 +#else
43872 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43873 +#endif
43874 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43875 + elf_flags |= MAP_FIXED;
43876 + }
43877 +#endif
43878 +
43879 }
43880
43881 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43882 @@ -832,9 +1133,9 @@ static int load_elf_binary(struct linux_
43883 * allowed task size. Note that p_filesz must always be
43884 * <= p_memsz so it is only necessary to check p_memsz.
43885 */
43886 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43887 - elf_ppnt->p_memsz > TASK_SIZE ||
43888 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43889 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43890 + elf_ppnt->p_memsz > pax_task_size ||
43891 + pax_task_size - elf_ppnt->p_memsz < k) {
43892 /* set_brk can never work. Avoid overflows. */
43893 send_sig(SIGKILL, current, 0);
43894 retval = -EINVAL;
43895 @@ -862,6 +1163,11 @@ static int load_elf_binary(struct linux_
43896 start_data += load_bias;
43897 end_data += load_bias;
43898
43899 +#ifdef CONFIG_PAX_RANDMMAP
43900 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
43901 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
43902 +#endif
43903 +
43904 /* Calling set_brk effectively mmaps the pages that we need
43905 * for the bss and break sections. We must do this before
43906 * mapping in the interpreter, to make sure it doesn't wind
43907 @@ -873,9 +1179,11 @@ static int load_elf_binary(struct linux_
43908 goto out_free_dentry;
43909 }
43910 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43911 - send_sig(SIGSEGV, current, 0);
43912 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43913 - goto out_free_dentry;
43914 + /*
43915 + * This bss-zeroing can fail if the ELF
43916 + * file specifies odd protections. So
43917 + * we don't check the return value
43918 + */
43919 }
43920
43921 if (elf_interpreter) {
43922 @@ -1090,7 +1398,7 @@ out:
43923 * Decide what to dump of a segment, part, all or none.
43924 */
43925 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43926 - unsigned long mm_flags)
43927 + unsigned long mm_flags, long signr)
43928 {
43929 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43930
43931 @@ -1124,7 +1432,7 @@ static unsigned long vma_dump_size(struc
43932 if (vma->vm_file == NULL)
43933 return 0;
43934
43935 - if (FILTER(MAPPED_PRIVATE))
43936 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43937 goto whole;
43938
43939 /*
43940 @@ -1346,9 +1654,9 @@ static void fill_auxv_note(struct memelf
43941 {
43942 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43943 int i = 0;
43944 - do
43945 + do {
43946 i += 2;
43947 - while (auxv[i - 2] != AT_NULL);
43948 + } while (auxv[i - 2] != AT_NULL);
43949 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43950 }
43951
43952 @@ -1854,14 +2162,14 @@ static void fill_extnum_info(struct elfh
43953 }
43954
43955 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43956 - unsigned long mm_flags)
43957 + struct coredump_params *cprm)
43958 {
43959 struct vm_area_struct *vma;
43960 size_t size = 0;
43961
43962 for (vma = first_vma(current, gate_vma); vma != NULL;
43963 vma = next_vma(vma, gate_vma))
43964 - size += vma_dump_size(vma, mm_flags);
43965 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43966 return size;
43967 }
43968
43969 @@ -1955,7 +2263,7 @@ static int elf_core_dump(struct coredump
43970
43971 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43972
43973 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43974 + offset += elf_core_vma_data_size(gate_vma, cprm);
43975 offset += elf_core_extra_data_size();
43976 e_shoff = offset;
43977
43978 @@ -1969,10 +2277,12 @@ static int elf_core_dump(struct coredump
43979 offset = dataoff;
43980
43981 size += sizeof(*elf);
43982 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43983 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43984 goto end_coredump;
43985
43986 size += sizeof(*phdr4note);
43987 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43988 if (size > cprm->limit
43989 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43990 goto end_coredump;
43991 @@ -1986,7 +2296,7 @@ static int elf_core_dump(struct coredump
43992 phdr.p_offset = offset;
43993 phdr.p_vaddr = vma->vm_start;
43994 phdr.p_paddr = 0;
43995 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43996 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43997 phdr.p_memsz = vma->vm_end - vma->vm_start;
43998 offset += phdr.p_filesz;
43999 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44000 @@ -1997,6 +2307,7 @@ static int elf_core_dump(struct coredump
44001 phdr.p_align = ELF_EXEC_PAGESIZE;
44002
44003 size += sizeof(phdr);
44004 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44005 if (size > cprm->limit
44006 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44007 goto end_coredump;
44008 @@ -2021,7 +2332,7 @@ static int elf_core_dump(struct coredump
44009 unsigned long addr;
44010 unsigned long end;
44011
44012 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44013 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44014
44015 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44016 struct page *page;
44017 @@ -2030,6 +2341,7 @@ static int elf_core_dump(struct coredump
44018 page = get_dump_page(addr);
44019 if (page) {
44020 void *kaddr = kmap(page);
44021 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44022 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44023 !dump_write(cprm->file, kaddr,
44024 PAGE_SIZE);
44025 @@ -2047,6 +2359,7 @@ static int elf_core_dump(struct coredump
44026
44027 if (e_phnum == PN_XNUM) {
44028 size += sizeof(*shdr4extnum);
44029 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44030 if (size > cprm->limit
44031 || !dump_write(cprm->file, shdr4extnum,
44032 sizeof(*shdr4extnum)))
44033 @@ -2067,6 +2380,97 @@ out:
44034
44035 #endif /* CONFIG_ELF_CORE */
44036
44037 +#ifdef CONFIG_PAX_MPROTECT
44038 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
44039 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44040 + * we'll remove VM_MAYWRITE for good on RELRO segments.
44041 + *
44042 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44043 + * basis because we want to allow the common case and not the special ones.
44044 + */
44045 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44046 +{
44047 + struct elfhdr elf_h;
44048 + struct elf_phdr elf_p;
44049 + unsigned long i;
44050 + unsigned long oldflags;
44051 + bool is_textrel_rw, is_textrel_rx, is_relro;
44052 +
44053 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44054 + return;
44055 +
44056 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44057 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44058 +
44059 +#ifdef CONFIG_PAX_ELFRELOCS
44060 + /* possible TEXTREL */
44061 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44062 + 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);
44063 +#else
44064 + is_textrel_rw = false;
44065 + is_textrel_rx = false;
44066 +#endif
44067 +
44068 + /* possible RELRO */
44069 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44070 +
44071 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44072 + return;
44073 +
44074 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44075 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44076 +
44077 +#ifdef CONFIG_PAX_ETEXECRELOCS
44078 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44079 +#else
44080 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44081 +#endif
44082 +
44083 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44084 + !elf_check_arch(&elf_h) ||
44085 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44086 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44087 + return;
44088 +
44089 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44090 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44091 + return;
44092 + switch (elf_p.p_type) {
44093 + case PT_DYNAMIC:
44094 + if (!is_textrel_rw && !is_textrel_rx)
44095 + continue;
44096 + i = 0UL;
44097 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44098 + elf_dyn dyn;
44099 +
44100 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44101 + return;
44102 + if (dyn.d_tag == DT_NULL)
44103 + return;
44104 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44105 + gr_log_textrel(vma);
44106 + if (is_textrel_rw)
44107 + vma->vm_flags |= VM_MAYWRITE;
44108 + else
44109 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44110 + vma->vm_flags &= ~VM_MAYWRITE;
44111 + return;
44112 + }
44113 + i++;
44114 + }
44115 + return;
44116 +
44117 + case PT_GNU_RELRO:
44118 + if (!is_relro)
44119 + continue;
44120 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44121 + vma->vm_flags &= ~VM_MAYWRITE;
44122 + return;
44123 + }
44124 + }
44125 +}
44126 +#endif
44127 +
44128 static int __init init_elf_binfmt(void)
44129 {
44130 return register_binfmt(&elf_format);
44131 diff -urNp linux-2.6.39.1/fs/binfmt_flat.c linux-2.6.39.1/fs/binfmt_flat.c
44132 --- linux-2.6.39.1/fs/binfmt_flat.c 2011-05-19 00:06:34.000000000 -0400
44133 +++ linux-2.6.39.1/fs/binfmt_flat.c 2011-05-22 19:36:32.000000000 -0400
44134 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
44135 realdatastart = (unsigned long) -ENOMEM;
44136 printk("Unable to allocate RAM for process data, errno %d\n",
44137 (int)-realdatastart);
44138 + down_write(&current->mm->mmap_sem);
44139 do_munmap(current->mm, textpos, text_len);
44140 + up_write(&current->mm->mmap_sem);
44141 ret = realdatastart;
44142 goto err;
44143 }
44144 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
44145 }
44146 if (IS_ERR_VALUE(result)) {
44147 printk("Unable to read data+bss, errno %d\n", (int)-result);
44148 + down_write(&current->mm->mmap_sem);
44149 do_munmap(current->mm, textpos, text_len);
44150 do_munmap(current->mm, realdatastart, len);
44151 + up_write(&current->mm->mmap_sem);
44152 ret = result;
44153 goto err;
44154 }
44155 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
44156 }
44157 if (IS_ERR_VALUE(result)) {
44158 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44159 + down_write(&current->mm->mmap_sem);
44160 do_munmap(current->mm, textpos, text_len + data_len + extra +
44161 MAX_SHARED_LIBS * sizeof(unsigned long));
44162 + up_write(&current->mm->mmap_sem);
44163 ret = result;
44164 goto err;
44165 }
44166 diff -urNp linux-2.6.39.1/fs/bio.c linux-2.6.39.1/fs/bio.c
44167 --- linux-2.6.39.1/fs/bio.c 2011-05-19 00:06:34.000000000 -0400
44168 +++ linux-2.6.39.1/fs/bio.c 2011-05-22 19:36:32.000000000 -0400
44169 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
44170 const int read = bio_data_dir(bio) == READ;
44171 struct bio_map_data *bmd = bio->bi_private;
44172 int i;
44173 - char *p = bmd->sgvecs[0].iov_base;
44174 + char *p = (__force char *)bmd->sgvecs[0].iov_base;
44175
44176 __bio_for_each_segment(bvec, bio, i, 0) {
44177 char *addr = page_address(bvec->bv_page);
44178 diff -urNp linux-2.6.39.1/fs/block_dev.c linux-2.6.39.1/fs/block_dev.c
44179 --- linux-2.6.39.1/fs/block_dev.c 2011-06-03 00:04:14.000000000 -0400
44180 +++ linux-2.6.39.1/fs/block_dev.c 2011-06-03 00:32:07.000000000 -0400
44181 @@ -671,7 +671,7 @@ static bool bd_may_claim(struct block_de
44182 else if (bdev->bd_contains == bdev)
44183 return true; /* is a whole device which isn't held */
44184
44185 - else if (whole->bd_holder == bd_may_claim)
44186 + else if (whole->bd_holder == (void *)bd_may_claim)
44187 return true; /* is a partition of a device that is being partitioned */
44188 else if (whole->bd_holder != NULL)
44189 return false; /* is a partition of a held device */
44190 diff -urNp linux-2.6.39.1/fs/btrfs/compression.c linux-2.6.39.1/fs/btrfs/compression.c
44191 --- linux-2.6.39.1/fs/btrfs/compression.c 2011-05-19 00:06:34.000000000 -0400
44192 +++ linux-2.6.39.1/fs/btrfs/compression.c 2011-05-22 19:36:32.000000000 -0400
44193 @@ -719,7 +719,7 @@ static int comp_num_workspace[BTRFS_COMP
44194 static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
44195 static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
44196
44197 -struct btrfs_compress_op *btrfs_compress_op[] = {
44198 +const struct btrfs_compress_op *btrfs_compress_op[] = {
44199 &btrfs_zlib_compress,
44200 &btrfs_lzo_compress,
44201 };
44202 diff -urNp linux-2.6.39.1/fs/btrfs/compression.h linux-2.6.39.1/fs/btrfs/compression.h
44203 --- linux-2.6.39.1/fs/btrfs/compression.h 2011-05-19 00:06:34.000000000 -0400
44204 +++ linux-2.6.39.1/fs/btrfs/compression.h 2011-05-22 19:36:32.000000000 -0400
44205 @@ -77,7 +77,7 @@ struct btrfs_compress_op {
44206 size_t srclen, size_t destlen);
44207 };
44208
44209 -extern struct btrfs_compress_op btrfs_zlib_compress;
44210 -extern struct btrfs_compress_op btrfs_lzo_compress;
44211 +extern const struct btrfs_compress_op btrfs_zlib_compress;
44212 +extern const struct btrfs_compress_op btrfs_lzo_compress;
44213
44214 #endif
44215 diff -urNp linux-2.6.39.1/fs/btrfs/ctree.c linux-2.6.39.1/fs/btrfs/ctree.c
44216 --- linux-2.6.39.1/fs/btrfs/ctree.c 2011-05-19 00:06:34.000000000 -0400
44217 +++ linux-2.6.39.1/fs/btrfs/ctree.c 2011-05-22 19:36:32.000000000 -0400
44218 @@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
44219 free_extent_buffer(buf);
44220 add_root_to_dirty_list(root);
44221 } else {
44222 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44223 - parent_start = parent->start;
44224 - else
44225 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44226 + if (parent)
44227 + parent_start = parent->start;
44228 + else
44229 + parent_start = 0;
44230 + } else
44231 parent_start = 0;
44232
44233 WARN_ON(trans->transid != btrfs_header_generation(parent));
44234 @@ -3647,7 +3650,6 @@ setup_items_for_insert(struct btrfs_tran
44235
44236 ret = 0;
44237 if (slot == 0) {
44238 - struct btrfs_disk_key disk_key;
44239 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
44240 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
44241 }
44242 diff -urNp linux-2.6.39.1/fs/btrfs/disk-io.c linux-2.6.39.1/fs/btrfs/disk-io.c
44243 --- linux-2.6.39.1/fs/btrfs/disk-io.c 2011-05-19 00:06:34.000000000 -0400
44244 +++ linux-2.6.39.1/fs/btrfs/disk-io.c 2011-05-22 19:36:32.000000000 -0400
44245 @@ -42,7 +42,7 @@
44246 #include "tree-log.h"
44247 #include "free-space-cache.h"
44248
44249 -static struct extent_io_ops btree_extent_io_ops;
44250 +static const struct extent_io_ops btree_extent_io_ops;
44251 static void end_workqueue_fn(struct btrfs_work *work);
44252 static void free_fs_root(struct btrfs_root *root);
44253 static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
44254 @@ -3070,7 +3070,7 @@ static int btrfs_cleanup_transaction(str
44255 return 0;
44256 }
44257
44258 -static struct extent_io_ops btree_extent_io_ops = {
44259 +static const struct extent_io_ops btree_extent_io_ops = {
44260 .write_cache_pages_lock_hook = btree_lock_page_hook,
44261 .readpage_end_io_hook = btree_readpage_end_io_hook,
44262 .submit_bio_hook = btree_submit_bio_hook,
44263 diff -urNp linux-2.6.39.1/fs/btrfs/extent_io.h linux-2.6.39.1/fs/btrfs/extent_io.h
44264 --- linux-2.6.39.1/fs/btrfs/extent_io.h 2011-05-19 00:06:34.000000000 -0400
44265 +++ linux-2.6.39.1/fs/btrfs/extent_io.h 2011-05-22 19:36:32.000000000 -0400
44266 @@ -56,36 +56,36 @@ typedef int (extent_submit_bio_hook_t)(s
44267 struct bio *bio, int mirror_num,
44268 unsigned long bio_flags, u64 bio_offset);
44269 struct extent_io_ops {
44270 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
44271 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
44272 u64 start, u64 end, int *page_started,
44273 unsigned long *nr_written);
44274 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
44275 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
44276 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
44277 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
44278 extent_submit_bio_hook_t *submit_bio_hook;
44279 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
44280 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
44281 size_t size, struct bio *bio,
44282 unsigned long bio_flags);
44283 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
44284 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
44285 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
44286 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
44287 u64 start, u64 end,
44288 struct extent_state *state);
44289 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
44290 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
44291 u64 start, u64 end,
44292 struct extent_state *state);
44293 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44294 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44295 struct extent_state *state);
44296 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44297 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44298 struct extent_state *state, int uptodate);
44299 - int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
44300 + int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
44301 int *bits);
44302 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
44303 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
44304 int *bits);
44305 - int (*merge_extent_hook)(struct inode *inode,
44306 + int (* const merge_extent_hook)(struct inode *inode,
44307 struct extent_state *new,
44308 struct extent_state *other);
44309 - int (*split_extent_hook)(struct inode *inode,
44310 + int (* const split_extent_hook)(struct inode *inode,
44311 struct extent_state *orig, u64 split);
44312 - int (*write_cache_pages_lock_hook)(struct page *page);
44313 + int (* const write_cache_pages_lock_hook)(struct page *page);
44314 };
44315
44316 struct extent_io_tree {
44317 @@ -95,7 +95,7 @@ struct extent_io_tree {
44318 u64 dirty_bytes;
44319 spinlock_t lock;
44320 spinlock_t buffer_lock;
44321 - struct extent_io_ops *ops;
44322 + const struct extent_io_ops *ops;
44323 };
44324
44325 struct extent_state {
44326 diff -urNp linux-2.6.39.1/fs/btrfs/free-space-cache.c linux-2.6.39.1/fs/btrfs/free-space-cache.c
44327 --- linux-2.6.39.1/fs/btrfs/free-space-cache.c 2011-05-19 00:06:34.000000000 -0400
44328 +++ linux-2.6.39.1/fs/btrfs/free-space-cache.c 2011-05-22 19:36:32.000000000 -0400
44329 @@ -1910,8 +1910,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44330 while(1) {
44331 if (entry->bytes < bytes ||
44332 (!entry->bitmap && entry->offset < min_start)) {
44333 - struct rb_node *node;
44334 -
44335 node = rb_next(&entry->offset_index);
44336 if (!node)
44337 break;
44338 @@ -1925,7 +1923,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44339 cluster, entry, bytes,
44340 min_start);
44341 if (ret == 0) {
44342 - struct rb_node *node;
44343 node = rb_next(&entry->offset_index);
44344 if (!node)
44345 break;
44346 diff -urNp linux-2.6.39.1/fs/btrfs/inode.c linux-2.6.39.1/fs/btrfs/inode.c
44347 --- linux-2.6.39.1/fs/btrfs/inode.c 2011-05-19 00:06:34.000000000 -0400
44348 +++ linux-2.6.39.1/fs/btrfs/inode.c 2011-05-22 20:42:42.000000000 -0400
44349 @@ -65,7 +65,7 @@ static const struct inode_operations btr
44350 static const struct address_space_operations btrfs_aops;
44351 static const struct address_space_operations btrfs_symlink_aops;
44352 static const struct file_operations btrfs_dir_file_operations;
44353 -static struct extent_io_ops btrfs_extent_io_ops;
44354 +static const struct extent_io_ops btrfs_extent_io_ops;
44355
44356 static struct kmem_cache *btrfs_inode_cachep;
44357 struct kmem_cache *btrfs_trans_handle_cachep;
44358 @@ -6947,7 +6947,7 @@ fail:
44359 return -ENOMEM;
44360 }
44361
44362 -static int btrfs_getattr(struct vfsmount *mnt,
44363 +int btrfs_getattr(struct vfsmount *mnt,
44364 struct dentry *dentry, struct kstat *stat)
44365 {
44366 struct inode *inode = dentry->d_inode;
44367 @@ -6959,6 +6959,14 @@ static int btrfs_getattr(struct vfsmount
44368 return 0;
44369 }
44370
44371 +EXPORT_SYMBOL(btrfs_getattr);
44372 +
44373 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44374 +{
44375 + return BTRFS_I(inode)->root->anon_super.s_dev;
44376 +}
44377 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44378 +
44379 /*
44380 * If a file is moved, it will inherit the cow and compression flags of the new
44381 * directory.
44382 @@ -7488,7 +7496,7 @@ static const struct file_operations btrf
44383 .fsync = btrfs_sync_file,
44384 };
44385
44386 -static struct extent_io_ops btrfs_extent_io_ops = {
44387 +static const struct extent_io_ops btrfs_extent_io_ops = {
44388 .fill_delalloc = run_delalloc_range,
44389 .submit_bio_hook = btrfs_submit_bio_hook,
44390 .merge_bio_hook = btrfs_merge_bio_hook,
44391 diff -urNp linux-2.6.39.1/fs/btrfs/ioctl.c linux-2.6.39.1/fs/btrfs/ioctl.c
44392 --- linux-2.6.39.1/fs/btrfs/ioctl.c 2011-05-19 00:06:34.000000000 -0400
44393 +++ linux-2.6.39.1/fs/btrfs/ioctl.c 2011-05-22 19:41:37.000000000 -0400
44394 @@ -2361,9 +2361,12 @@ long btrfs_ioctl_space_info(struct btrfs
44395 for (i = 0; i < num_types; i++) {
44396 struct btrfs_space_info *tmp;
44397
44398 + /* Don't copy in more than we allocated */
44399 if (!slot_count)
44400 break;
44401
44402 + slot_count--;
44403 +
44404 info = NULL;
44405 rcu_read_lock();
44406 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44407 @@ -2385,10 +2388,7 @@ long btrfs_ioctl_space_info(struct btrfs
44408 memcpy(dest, &space, sizeof(space));
44409 dest++;
44410 space_args.total_spaces++;
44411 - slot_count--;
44412 }
44413 - if (!slot_count)
44414 - break;
44415 }
44416 up_read(&info->groups_sem);
44417 }
44418 diff -urNp linux-2.6.39.1/fs/btrfs/lzo.c linux-2.6.39.1/fs/btrfs/lzo.c
44419 --- linux-2.6.39.1/fs/btrfs/lzo.c 2011-05-19 00:06:34.000000000 -0400
44420 +++ linux-2.6.39.1/fs/btrfs/lzo.c 2011-05-22 19:36:32.000000000 -0400
44421 @@ -418,7 +418,7 @@ out:
44422 return ret;
44423 }
44424
44425 -struct btrfs_compress_op btrfs_lzo_compress = {
44426 +const struct btrfs_compress_op btrfs_lzo_compress = {
44427 .alloc_workspace = lzo_alloc_workspace,
44428 .free_workspace = lzo_free_workspace,
44429 .compress_pages = lzo_compress_pages,
44430 diff -urNp linux-2.6.39.1/fs/btrfs/relocation.c linux-2.6.39.1/fs/btrfs/relocation.c
44431 --- linux-2.6.39.1/fs/btrfs/relocation.c 2011-05-19 00:06:34.000000000 -0400
44432 +++ linux-2.6.39.1/fs/btrfs/relocation.c 2011-05-22 19:36:32.000000000 -0400
44433 @@ -1239,7 +1239,7 @@ static int __update_reloc_root(struct bt
44434 }
44435 spin_unlock(&rc->reloc_root_tree.lock);
44436
44437 - BUG_ON((struct btrfs_root *)node->data != root);
44438 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44439
44440 if (!del) {
44441 spin_lock(&rc->reloc_root_tree.lock);
44442 diff -urNp linux-2.6.39.1/fs/btrfs/zlib.c linux-2.6.39.1/fs/btrfs/zlib.c
44443 --- linux-2.6.39.1/fs/btrfs/zlib.c 2011-05-19 00:06:34.000000000 -0400
44444 +++ linux-2.6.39.1/fs/btrfs/zlib.c 2011-05-22 19:36:32.000000000 -0400
44445 @@ -390,7 +390,7 @@ next:
44446 return ret;
44447 }
44448
44449 -struct btrfs_compress_op btrfs_zlib_compress = {
44450 +const struct btrfs_compress_op btrfs_zlib_compress = {
44451 .alloc_workspace = zlib_alloc_workspace,
44452 .free_workspace = zlib_free_workspace,
44453 .compress_pages = zlib_compress_pages,
44454 diff -urNp linux-2.6.39.1/fs/cachefiles/bind.c linux-2.6.39.1/fs/cachefiles/bind.c
44455 --- linux-2.6.39.1/fs/cachefiles/bind.c 2011-05-19 00:06:34.000000000 -0400
44456 +++ linux-2.6.39.1/fs/cachefiles/bind.c 2011-05-22 19:36:32.000000000 -0400
44457 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
44458 args);
44459
44460 /* start by checking things over */
44461 - ASSERT(cache->fstop_percent >= 0 &&
44462 - cache->fstop_percent < cache->fcull_percent &&
44463 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44464 cache->fcull_percent < cache->frun_percent &&
44465 cache->frun_percent < 100);
44466
44467 - ASSERT(cache->bstop_percent >= 0 &&
44468 - cache->bstop_percent < cache->bcull_percent &&
44469 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44470 cache->bcull_percent < cache->brun_percent &&
44471 cache->brun_percent < 100);
44472
44473 diff -urNp linux-2.6.39.1/fs/cachefiles/daemon.c linux-2.6.39.1/fs/cachefiles/daemon.c
44474 --- linux-2.6.39.1/fs/cachefiles/daemon.c 2011-05-19 00:06:34.000000000 -0400
44475 +++ linux-2.6.39.1/fs/cachefiles/daemon.c 2011-05-22 19:36:32.000000000 -0400
44476 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
44477 if (n > buflen)
44478 return -EMSGSIZE;
44479
44480 - if (copy_to_user(_buffer, buffer, n) != 0)
44481 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44482 return -EFAULT;
44483
44484 return n;
44485 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
44486 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44487 return -EIO;
44488
44489 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44490 + if (datalen > PAGE_SIZE - 1)
44491 return -EOPNOTSUPP;
44492
44493 /* drag the command string into the kernel so we can parse it */
44494 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
44495 if (args[0] != '%' || args[1] != '\0')
44496 return -EINVAL;
44497
44498 - if (fstop < 0 || fstop >= cache->fcull_percent)
44499 + if (fstop >= cache->fcull_percent)
44500 return cachefiles_daemon_range_error(cache, args);
44501
44502 cache->fstop_percent = fstop;
44503 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
44504 if (args[0] != '%' || args[1] != '\0')
44505 return -EINVAL;
44506
44507 - if (bstop < 0 || bstop >= cache->bcull_percent)
44508 + if (bstop >= cache->bcull_percent)
44509 return cachefiles_daemon_range_error(cache, args);
44510
44511 cache->bstop_percent = bstop;
44512 diff -urNp linux-2.6.39.1/fs/cachefiles/internal.h linux-2.6.39.1/fs/cachefiles/internal.h
44513 --- linux-2.6.39.1/fs/cachefiles/internal.h 2011-05-19 00:06:34.000000000 -0400
44514 +++ linux-2.6.39.1/fs/cachefiles/internal.h 2011-05-22 19:36:32.000000000 -0400
44515 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44516 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44517 struct rb_root active_nodes; /* active nodes (can't be culled) */
44518 rwlock_t active_lock; /* lock for active_nodes */
44519 - atomic_t gravecounter; /* graveyard uniquifier */
44520 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44521 unsigned frun_percent; /* when to stop culling (% files) */
44522 unsigned fcull_percent; /* when to start culling (% files) */
44523 unsigned fstop_percent; /* when to stop allocating (% files) */
44524 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struc
44525 * proc.c
44526 */
44527 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44528 -extern atomic_t cachefiles_lookup_histogram[HZ];
44529 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44530 -extern atomic_t cachefiles_create_histogram[HZ];
44531 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44532 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44533 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44534
44535 extern int __init cachefiles_proc_init(void);
44536 extern void cachefiles_proc_cleanup(void);
44537 static inline
44538 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44539 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44540 {
44541 unsigned long jif = jiffies - start_jif;
44542 if (jif >= HZ)
44543 jif = HZ - 1;
44544 - atomic_inc(&histogram[jif]);
44545 + atomic_inc_unchecked(&histogram[jif]);
44546 }
44547
44548 #else
44549 diff -urNp linux-2.6.39.1/fs/cachefiles/namei.c linux-2.6.39.1/fs/cachefiles/namei.c
44550 --- linux-2.6.39.1/fs/cachefiles/namei.c 2011-05-19 00:06:34.000000000 -0400
44551 +++ linux-2.6.39.1/fs/cachefiles/namei.c 2011-05-22 19:36:32.000000000 -0400
44552 @@ -318,7 +318,7 @@ try_again:
44553 /* first step is to make up a grave dentry in the graveyard */
44554 sprintf(nbuffer, "%08x%08x",
44555 (uint32_t) get_seconds(),
44556 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44557 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44558
44559 /* do the multiway lock magic */
44560 trap = lock_rename(cache->graveyard, dir);
44561 diff -urNp linux-2.6.39.1/fs/cachefiles/proc.c linux-2.6.39.1/fs/cachefiles/proc.c
44562 --- linux-2.6.39.1/fs/cachefiles/proc.c 2011-05-19 00:06:34.000000000 -0400
44563 +++ linux-2.6.39.1/fs/cachefiles/proc.c 2011-05-22 19:36:32.000000000 -0400
44564 @@ -14,9 +14,9 @@
44565 #include <linux/seq_file.h>
44566 #include "internal.h"
44567
44568 -atomic_t cachefiles_lookup_histogram[HZ];
44569 -atomic_t cachefiles_mkdir_histogram[HZ];
44570 -atomic_t cachefiles_create_histogram[HZ];
44571 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44572 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44573 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44574
44575 /*
44576 * display the latency histogram
44577 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
44578 return 0;
44579 default:
44580 index = (unsigned long) v - 3;
44581 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44582 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44583 - z = atomic_read(&cachefiles_create_histogram[index]);
44584 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44585 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44586 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44587 if (x == 0 && y == 0 && z == 0)
44588 return 0;
44589
44590 diff -urNp linux-2.6.39.1/fs/cachefiles/rdwr.c linux-2.6.39.1/fs/cachefiles/rdwr.c
44591 --- linux-2.6.39.1/fs/cachefiles/rdwr.c 2011-05-19 00:06:34.000000000 -0400
44592 +++ linux-2.6.39.1/fs/cachefiles/rdwr.c 2011-05-22 19:36:32.000000000 -0400
44593 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
44594 old_fs = get_fs();
44595 set_fs(KERNEL_DS);
44596 ret = file->f_op->write(
44597 - file, (const void __user *) data, len, &pos);
44598 + file, (__force const void __user *) data, len, &pos);
44599 set_fs(old_fs);
44600 kunmap(page);
44601 if (ret != len)
44602 diff -urNp linux-2.6.39.1/fs/ceph/addr.c linux-2.6.39.1/fs/ceph/addr.c
44603 --- linux-2.6.39.1/fs/ceph/addr.c 2011-05-19 00:06:34.000000000 -0400
44604 +++ linux-2.6.39.1/fs/ceph/addr.c 2011-05-22 19:36:32.000000000 -0400
44605 @@ -1164,7 +1164,7 @@ out:
44606 return ret;
44607 }
44608
44609 -static struct vm_operations_struct ceph_vmops = {
44610 +static const struct vm_operations_struct ceph_vmops = {
44611 .fault = filemap_fault,
44612 .page_mkwrite = ceph_page_mkwrite,
44613 };
44614 diff -urNp linux-2.6.39.1/fs/ceph/dir.c linux-2.6.39.1/fs/ceph/dir.c
44615 --- linux-2.6.39.1/fs/ceph/dir.c 2011-05-19 00:06:34.000000000 -0400
44616 +++ linux-2.6.39.1/fs/ceph/dir.c 2011-05-22 19:36:32.000000000 -0400
44617 @@ -226,7 +226,7 @@ static int ceph_readdir(struct file *fil
44618 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44619 struct ceph_mds_client *mdsc = fsc->mdsc;
44620 unsigned frag = fpos_frag(filp->f_pos);
44621 - int off = fpos_off(filp->f_pos);
44622 + unsigned int off = fpos_off(filp->f_pos);
44623 int err;
44624 u32 ftype;
44625 struct ceph_mds_reply_info_parsed *rinfo;
44626 @@ -360,7 +360,7 @@ more:
44627 rinfo = &fi->last_readdir->r_reply_info;
44628 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
44629 rinfo->dir_nr, off, fi->offset);
44630 - while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
44631 + while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
44632 u64 pos = ceph_make_fpos(frag, off);
44633 struct ceph_mds_reply_inode *in =
44634 rinfo->dir_in[off - fi->offset].in;
44635 diff -urNp linux-2.6.39.1/fs/cifs/cifs_debug.c linux-2.6.39.1/fs/cifs/cifs_debug.c
44636 --- linux-2.6.39.1/fs/cifs/cifs_debug.c 2011-05-19 00:06:34.000000000 -0400
44637 +++ linux-2.6.39.1/fs/cifs/cifs_debug.c 2011-05-22 19:36:32.000000000 -0400
44638 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(str
44639 tcon = list_entry(tmp3,
44640 struct cifsTconInfo,
44641 tcon_list);
44642 - atomic_set(&tcon->num_smbs_sent, 0);
44643 - atomic_set(&tcon->num_writes, 0);
44644 - atomic_set(&tcon->num_reads, 0);
44645 - atomic_set(&tcon->num_oplock_brks, 0);
44646 - atomic_set(&tcon->num_opens, 0);
44647 - atomic_set(&tcon->num_posixopens, 0);
44648 - atomic_set(&tcon->num_posixmkdirs, 0);
44649 - atomic_set(&tcon->num_closes, 0);
44650 - atomic_set(&tcon->num_deletes, 0);
44651 - atomic_set(&tcon->num_mkdirs, 0);
44652 - atomic_set(&tcon->num_rmdirs, 0);
44653 - atomic_set(&tcon->num_renames, 0);
44654 - atomic_set(&tcon->num_t2renames, 0);
44655 - atomic_set(&tcon->num_ffirst, 0);
44656 - atomic_set(&tcon->num_fnext, 0);
44657 - atomic_set(&tcon->num_fclose, 0);
44658 - atomic_set(&tcon->num_hardlinks, 0);
44659 - atomic_set(&tcon->num_symlinks, 0);
44660 - atomic_set(&tcon->num_locks, 0);
44661 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44662 + atomic_set_unchecked(&tcon->num_writes, 0);
44663 + atomic_set_unchecked(&tcon->num_reads, 0);
44664 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44665 + atomic_set_unchecked(&tcon->num_opens, 0);
44666 + atomic_set_unchecked(&tcon->num_posixopens, 0);
44667 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44668 + atomic_set_unchecked(&tcon->num_closes, 0);
44669 + atomic_set_unchecked(&tcon->num_deletes, 0);
44670 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
44671 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
44672 + atomic_set_unchecked(&tcon->num_renames, 0);
44673 + atomic_set_unchecked(&tcon->num_t2renames, 0);
44674 + atomic_set_unchecked(&tcon->num_ffirst, 0);
44675 + atomic_set_unchecked(&tcon->num_fnext, 0);
44676 + atomic_set_unchecked(&tcon->num_fclose, 0);
44677 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
44678 + atomic_set_unchecked(&tcon->num_symlinks, 0);
44679 + atomic_set_unchecked(&tcon->num_locks, 0);
44680 }
44681 }
44682 }
44683 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct s
44684 if (tcon->need_reconnect)
44685 seq_puts(m, "\tDISCONNECTED ");
44686 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44687 - atomic_read(&tcon->num_smbs_sent),
44688 - atomic_read(&tcon->num_oplock_brks));
44689 + atomic_read_unchecked(&tcon->num_smbs_sent),
44690 + atomic_read_unchecked(&tcon->num_oplock_brks));
44691 seq_printf(m, "\nReads: %d Bytes: %lld",
44692 - atomic_read(&tcon->num_reads),
44693 + atomic_read_unchecked(&tcon->num_reads),
44694 (long long)(tcon->bytes_read));
44695 seq_printf(m, "\nWrites: %d Bytes: %lld",
44696 - atomic_read(&tcon->num_writes),
44697 + atomic_read_unchecked(&tcon->num_writes),
44698 (long long)(tcon->bytes_written));
44699 seq_printf(m, "\nFlushes: %d",
44700 - atomic_read(&tcon->num_flushes));
44701 + atomic_read_unchecked(&tcon->num_flushes));
44702 seq_printf(m, "\nLocks: %d HardLinks: %d "
44703 "Symlinks: %d",
44704 - atomic_read(&tcon->num_locks),
44705 - atomic_read(&tcon->num_hardlinks),
44706 - atomic_read(&tcon->num_symlinks));
44707 + atomic_read_unchecked(&tcon->num_locks),
44708 + atomic_read_unchecked(&tcon->num_hardlinks),
44709 + atomic_read_unchecked(&tcon->num_symlinks));
44710 seq_printf(m, "\nOpens: %d Closes: %d "
44711 "Deletes: %d",
44712 - atomic_read(&tcon->num_opens),
44713 - atomic_read(&tcon->num_closes),
44714 - atomic_read(&tcon->num_deletes));
44715 + atomic_read_unchecked(&tcon->num_opens),
44716 + atomic_read_unchecked(&tcon->num_closes),
44717 + atomic_read_unchecked(&tcon->num_deletes));
44718 seq_printf(m, "\nPosix Opens: %d "
44719 "Posix Mkdirs: %d",
44720 - atomic_read(&tcon->num_posixopens),
44721 - atomic_read(&tcon->num_posixmkdirs));
44722 + atomic_read_unchecked(&tcon->num_posixopens),
44723 + atomic_read_unchecked(&tcon->num_posixmkdirs));
44724 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44725 - atomic_read(&tcon->num_mkdirs),
44726 - atomic_read(&tcon->num_rmdirs));
44727 + atomic_read_unchecked(&tcon->num_mkdirs),
44728 + atomic_read_unchecked(&tcon->num_rmdirs));
44729 seq_printf(m, "\nRenames: %d T2 Renames %d",
44730 - atomic_read(&tcon->num_renames),
44731 - atomic_read(&tcon->num_t2renames));
44732 + atomic_read_unchecked(&tcon->num_renames),
44733 + atomic_read_unchecked(&tcon->num_t2renames));
44734 seq_printf(m, "\nFindFirst: %d FNext %d "
44735 "FClose %d",
44736 - atomic_read(&tcon->num_ffirst),
44737 - atomic_read(&tcon->num_fnext),
44738 - atomic_read(&tcon->num_fclose));
44739 + atomic_read_unchecked(&tcon->num_ffirst),
44740 + atomic_read_unchecked(&tcon->num_fnext),
44741 + atomic_read_unchecked(&tcon->num_fclose));
44742 }
44743 }
44744 }
44745 diff -urNp linux-2.6.39.1/fs/cifs/cifsglob.h linux-2.6.39.1/fs/cifs/cifsglob.h
44746 --- linux-2.6.39.1/fs/cifs/cifsglob.h 2011-05-19 00:06:34.000000000 -0400
44747 +++ linux-2.6.39.1/fs/cifs/cifsglob.h 2011-05-22 19:36:32.000000000 -0400
44748 @@ -305,28 +305,28 @@ struct cifsTconInfo {
44749 __u16 Flags; /* optional support bits */
44750 enum statusEnum tidStatus;
44751 #ifdef CONFIG_CIFS_STATS
44752 - atomic_t num_smbs_sent;
44753 - atomic_t num_writes;
44754 - atomic_t num_reads;
44755 - atomic_t num_flushes;
44756 - atomic_t num_oplock_brks;
44757 - atomic_t num_opens;
44758 - atomic_t num_closes;
44759 - atomic_t num_deletes;
44760 - atomic_t num_mkdirs;
44761 - atomic_t num_posixopens;
44762 - atomic_t num_posixmkdirs;
44763 - atomic_t num_rmdirs;
44764 - atomic_t num_renames;
44765 - atomic_t num_t2renames;
44766 - atomic_t num_ffirst;
44767 - atomic_t num_fnext;
44768 - atomic_t num_fclose;
44769 - atomic_t num_hardlinks;
44770 - atomic_t num_symlinks;
44771 - atomic_t num_locks;
44772 - atomic_t num_acl_get;
44773 - atomic_t num_acl_set;
44774 + atomic_unchecked_t num_smbs_sent;
44775 + atomic_unchecked_t num_writes;
44776 + atomic_unchecked_t num_reads;
44777 + atomic_unchecked_t num_flushes;
44778 + atomic_unchecked_t num_oplock_brks;
44779 + atomic_unchecked_t num_opens;
44780 + atomic_unchecked_t num_closes;
44781 + atomic_unchecked_t num_deletes;
44782 + atomic_unchecked_t num_mkdirs;
44783 + atomic_unchecked_t num_posixopens;
44784 + atomic_unchecked_t num_posixmkdirs;
44785 + atomic_unchecked_t num_rmdirs;
44786 + atomic_unchecked_t num_renames;
44787 + atomic_unchecked_t num_t2renames;
44788 + atomic_unchecked_t num_ffirst;
44789 + atomic_unchecked_t num_fnext;
44790 + atomic_unchecked_t num_fclose;
44791 + atomic_unchecked_t num_hardlinks;
44792 + atomic_unchecked_t num_symlinks;
44793 + atomic_unchecked_t num_locks;
44794 + atomic_unchecked_t num_acl_get;
44795 + atomic_unchecked_t num_acl_set;
44796 #ifdef CONFIG_CIFS_STATS2
44797 unsigned long long time_writes;
44798 unsigned long long time_reads;
44799 @@ -509,7 +509,7 @@ static inline char CIFS_DIR_SEP(const st
44800 }
44801
44802 #ifdef CONFIG_CIFS_STATS
44803 -#define cifs_stats_inc atomic_inc
44804 +#define cifs_stats_inc atomic_inc_unchecked
44805
44806 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
44807 unsigned int bytes)
44808 diff -urNp linux-2.6.39.1/fs/cifs/link.c linux-2.6.39.1/fs/cifs/link.c
44809 --- linux-2.6.39.1/fs/cifs/link.c 2011-05-19 00:06:34.000000000 -0400
44810 +++ linux-2.6.39.1/fs/cifs/link.c 2011-05-22 19:36:32.000000000 -0400
44811 @@ -577,7 +577,7 @@ symlink_exit:
44812
44813 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44814 {
44815 - char *p = nd_get_link(nd);
44816 + const char *p = nd_get_link(nd);
44817 if (!IS_ERR(p))
44818 kfree(p);
44819 }
44820 diff -urNp linux-2.6.39.1/fs/coda/cache.c linux-2.6.39.1/fs/coda/cache.c
44821 --- linux-2.6.39.1/fs/coda/cache.c 2011-05-19 00:06:34.000000000 -0400
44822 +++ linux-2.6.39.1/fs/coda/cache.c 2011-05-22 19:36:32.000000000 -0400
44823 @@ -24,7 +24,7 @@
44824 #include "coda_linux.h"
44825 #include "coda_cache.h"
44826
44827 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44828 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44829
44830 /* replace or extend an acl cache hit */
44831 void coda_cache_enter(struct inode *inode, int mask)
44832 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inod
44833 struct coda_inode_info *cii = ITOC(inode);
44834
44835 spin_lock(&cii->c_lock);
44836 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44837 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44838 if (cii->c_uid != current_fsuid()) {
44839 cii->c_uid = current_fsuid();
44840 cii->c_cached_perm = mask;
44841 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode
44842 {
44843 struct coda_inode_info *cii = ITOC(inode);
44844 spin_lock(&cii->c_lock);
44845 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44846 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44847 spin_unlock(&cii->c_lock);
44848 }
44849
44850 /* remove all acl caches */
44851 void coda_cache_clear_all(struct super_block *sb)
44852 {
44853 - atomic_inc(&permission_epoch);
44854 + atomic_inc_unchecked(&permission_epoch);
44855 }
44856
44857
44858 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode
44859 spin_lock(&cii->c_lock);
44860 hit = (mask & cii->c_cached_perm) == mask &&
44861 cii->c_uid == current_fsuid() &&
44862 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44863 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44864 spin_unlock(&cii->c_lock);
44865
44866 return hit;
44867 diff -urNp linux-2.6.39.1/fs/compat_binfmt_elf.c linux-2.6.39.1/fs/compat_binfmt_elf.c
44868 --- linux-2.6.39.1/fs/compat_binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
44869 +++ linux-2.6.39.1/fs/compat_binfmt_elf.c 2011-05-22 19:36:32.000000000 -0400
44870 @@ -30,11 +30,13 @@
44871 #undef elf_phdr
44872 #undef elf_shdr
44873 #undef elf_note
44874 +#undef elf_dyn
44875 #undef elf_addr_t
44876 #define elfhdr elf32_hdr
44877 #define elf_phdr elf32_phdr
44878 #define elf_shdr elf32_shdr
44879 #define elf_note elf32_note
44880 +#define elf_dyn Elf32_Dyn
44881 #define elf_addr_t Elf32_Addr
44882
44883 /*
44884 diff -urNp linux-2.6.39.1/fs/compat.c linux-2.6.39.1/fs/compat.c
44885 --- linux-2.6.39.1/fs/compat.c 2011-05-19 00:06:34.000000000 -0400
44886 +++ linux-2.6.39.1/fs/compat.c 2011-05-22 19:41:37.000000000 -0400
44887 @@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int
44888 goto out;
44889
44890 ret = -EINVAL;
44891 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44892 + if (nr_segs > UIO_MAXIOV)
44893 goto out;
44894 if (nr_segs > fast_segs) {
44895 ret = -ENOMEM;
44896 @@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
44897
44898 struct compat_readdir_callback {
44899 struct compat_old_linux_dirent __user *dirent;
44900 + struct file * file;
44901 int result;
44902 };
44903
44904 @@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf
44905 buf->result = -EOVERFLOW;
44906 return -EOVERFLOW;
44907 }
44908 +
44909 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44910 + return 0;
44911 +
44912 buf->result++;
44913 dirent = buf->dirent;
44914 if (!access_ok(VERIFY_WRITE, dirent,
44915 @@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(u
44916
44917 buf.result = 0;
44918 buf.dirent = dirent;
44919 + buf.file = file;
44920
44921 error = vfs_readdir(file, compat_fillonedir, &buf);
44922 if (buf.result)
44923 @@ -917,6 +923,7 @@ struct compat_linux_dirent {
44924 struct compat_getdents_callback {
44925 struct compat_linux_dirent __user *current_dir;
44926 struct compat_linux_dirent __user *previous;
44927 + struct file * file;
44928 int count;
44929 int error;
44930 };
44931 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, c
44932 buf->error = -EOVERFLOW;
44933 return -EOVERFLOW;
44934 }
44935 +
44936 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44937 + return 0;
44938 +
44939 dirent = buf->previous;
44940 if (dirent) {
44941 if (__put_user(offset, &dirent->d_off))
44942 @@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsi
44943 buf.previous = NULL;
44944 buf.count = count;
44945 buf.error = 0;
44946 + buf.file = file;
44947
44948 error = vfs_readdir(file, compat_filldir, &buf);
44949 if (error >= 0)
44950 @@ -1006,6 +1018,7 @@ out:
44951 struct compat_getdents_callback64 {
44952 struct linux_dirent64 __user *current_dir;
44953 struct linux_dirent64 __user *previous;
44954 + struct file * file;
44955 int count;
44956 int error;
44957 };
44958 @@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf
44959 buf->error = -EINVAL; /* only used if we fail.. */
44960 if (reclen > buf->count)
44961 return -EINVAL;
44962 +
44963 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44964 + return 0;
44965 +
44966 dirent = buf->previous;
44967
44968 if (dirent) {
44969 @@ -1073,6 +1090,7 @@ asmlinkage long compat_sys_getdents64(un
44970 buf.previous = NULL;
44971 buf.count = count;
44972 buf.error = 0;
44973 + buf.file = file;
44974
44975 error = vfs_readdir(file, compat_filldir64, &buf);
44976 if (error >= 0)
44977 @@ -1436,6 +1454,11 @@ int compat_do_execve(char * filename,
44978 compat_uptr_t __user *envp,
44979 struct pt_regs * regs)
44980 {
44981 +#ifdef CONFIG_GRKERNSEC
44982 + struct file *old_exec_file;
44983 + struct acl_subject_label *old_acl;
44984 + struct rlimit old_rlim[RLIM_NLIMITS];
44985 +#endif
44986 struct linux_binprm *bprm;
44987 struct file *file;
44988 struct files_struct *displaced;
44989 @@ -1472,6 +1495,19 @@ int compat_do_execve(char * filename,
44990 bprm->filename = filename;
44991 bprm->interp = filename;
44992
44993 + if (gr_process_user_ban()) {
44994 + retval = -EPERM;
44995 + goto out_file;
44996 + }
44997 +
44998 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44999 + retval = -EAGAIN;
45000 + if (gr_handle_nproc())
45001 + goto out_file;
45002 + retval = -EACCES;
45003 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
45004 + goto out_file;
45005 +
45006 retval = bprm_mm_init(bprm);
45007 if (retval)
45008 goto out_file;
45009 @@ -1501,9 +1537,40 @@ int compat_do_execve(char * filename,
45010 if (retval < 0)
45011 goto out;
45012
45013 + if (!gr_tpe_allow(file)) {
45014 + retval = -EACCES;
45015 + goto out;
45016 + }
45017 +
45018 + if (gr_check_crash_exec(file)) {
45019 + retval = -EACCES;
45020 + goto out;
45021 + }
45022 +
45023 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45024 +
45025 + gr_handle_exec_args_compat(bprm, argv);
45026 +
45027 +#ifdef CONFIG_GRKERNSEC
45028 + old_acl = current->acl;
45029 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45030 + old_exec_file = current->exec_file;
45031 + get_file(file);
45032 + current->exec_file = file;
45033 +#endif
45034 +
45035 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45036 + bprm->unsafe & LSM_UNSAFE_SHARE);
45037 + if (retval < 0)
45038 + goto out_fail;
45039 +
45040 retval = search_binary_handler(bprm, regs);
45041 if (retval < 0)
45042 - goto out;
45043 + goto out_fail;
45044 +#ifdef CONFIG_GRKERNSEC
45045 + if (old_exec_file)
45046 + fput(old_exec_file);
45047 +#endif
45048
45049 /* execve succeeded */
45050 current->fs->in_exec = 0;
45051 @@ -1514,6 +1581,14 @@ int compat_do_execve(char * filename,
45052 put_files_struct(displaced);
45053 return retval;
45054
45055 +out_fail:
45056 +#ifdef CONFIG_GRKERNSEC
45057 + current->acl = old_acl;
45058 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45059 + fput(current->exec_file);
45060 + current->exec_file = old_exec_file;
45061 +#endif
45062 +
45063 out:
45064 if (bprm->mm) {
45065 acct_arg_size(bprm, 0);
45066 @@ -1681,6 +1756,8 @@ int compat_core_sys_select(int n, compat
45067 struct fdtable *fdt;
45068 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
45069
45070 + pax_track_stack();
45071 +
45072 if (n < 0)
45073 goto out_nofds;
45074
45075 diff -urNp linux-2.6.39.1/fs/compat_ioctl.c linux-2.6.39.1/fs/compat_ioctl.c
45076 --- linux-2.6.39.1/fs/compat_ioctl.c 2011-05-19 00:06:34.000000000 -0400
45077 +++ linux-2.6.39.1/fs/compat_ioctl.c 2011-05-22 19:36:32.000000000 -0400
45078 @@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
45079
45080 err = get_user(palp, &up->palette);
45081 err |= get_user(length, &up->length);
45082 + if (err)
45083 + return -EFAULT;
45084
45085 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
45086 err = put_user(compat_ptr(palp), &up_native->palette);
45087 @@ -1638,8 +1640,8 @@ asmlinkage long compat_sys_ioctl(unsigne
45088 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45089 {
45090 unsigned int a, b;
45091 - a = *(unsigned int *)p;
45092 - b = *(unsigned int *)q;
45093 + a = *(const unsigned int *)p;
45094 + b = *(const unsigned int *)q;
45095 if (a > b)
45096 return 1;
45097 if (a < b)
45098 diff -urNp linux-2.6.39.1/fs/configfs/dir.c linux-2.6.39.1/fs/configfs/dir.c
45099 --- linux-2.6.39.1/fs/configfs/dir.c 2011-05-19 00:06:34.000000000 -0400
45100 +++ linux-2.6.39.1/fs/configfs/dir.c 2011-05-22 19:36:32.000000000 -0400
45101 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file
45102 }
45103 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45104 struct configfs_dirent *next;
45105 - const char * name;
45106 + const unsigned char * name;
45107 + char d_name[sizeof(next->s_dentry->d_iname)];
45108 int len;
45109 struct inode *inode = NULL;
45110
45111 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file
45112 continue;
45113
45114 name = configfs_get_name(next);
45115 - len = strlen(name);
45116 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45117 + len = next->s_dentry->d_name.len;
45118 + memcpy(d_name, name, len);
45119 + name = d_name;
45120 + } else
45121 + len = strlen(name);
45122
45123 /*
45124 * We'll have a dentry and an inode for
45125 diff -urNp linux-2.6.39.1/fs/configfs/file.c linux-2.6.39.1/fs/configfs/file.c
45126 --- linux-2.6.39.1/fs/configfs/file.c 2011-05-19 00:06:34.000000000 -0400
45127 +++ linux-2.6.39.1/fs/configfs/file.c 2011-05-22 19:36:32.000000000 -0400
45128 @@ -215,7 +215,7 @@ static int check_perm(struct inode * ino
45129 struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent);
45130 struct configfs_attribute * attr = to_attr(file->f_path.dentry);
45131 struct configfs_buffer * buffer;
45132 - struct configfs_item_operations * ops = NULL;
45133 + struct configfs_item_operations *ops = NULL;
45134 int error = 0;
45135
45136 if (!item || !attr)
45137 diff -urNp linux-2.6.39.1/fs/configfs/item.c linux-2.6.39.1/fs/configfs/item.c
45138 --- linux-2.6.39.1/fs/configfs/item.c 2011-05-19 00:06:34.000000000 -0400
45139 +++ linux-2.6.39.1/fs/configfs/item.c 2011-05-22 19:36:32.000000000 -0400
45140 @@ -123,7 +123,7 @@ void config_item_init_type_name(struct c
45141 EXPORT_SYMBOL(config_item_init_type_name);
45142
45143 void config_group_init_type_name(struct config_group *group, const char *name,
45144 - struct config_item_type *type)
45145 + struct config_item_type *type)
45146 {
45147 config_item_set_name(&group->cg_item, name);
45148 group->cg_item.ci_type = type;
45149 diff -urNp linux-2.6.39.1/fs/dcache.c linux-2.6.39.1/fs/dcache.c
45150 --- linux-2.6.39.1/fs/dcache.c 2011-05-19 00:06:34.000000000 -0400
45151 +++ linux-2.6.39.1/fs/dcache.c 2011-05-22 19:36:32.000000000 -0400
45152 @@ -3069,7 +3069,7 @@ void __init vfs_caches_init(unsigned lon
45153 mempages -= reserve;
45154
45155 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45156 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45157 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45158
45159 dcache_init();
45160 inode_init();
45161 diff -urNp linux-2.6.39.1/fs/dlm/lockspace.c linux-2.6.39.1/fs/dlm/lockspace.c
45162 --- linux-2.6.39.1/fs/dlm/lockspace.c 2011-05-19 00:06:34.000000000 -0400
45163 +++ linux-2.6.39.1/fs/dlm/lockspace.c 2011-05-22 19:36:32.000000000 -0400
45164 @@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
45165 return 0;
45166 }
45167
45168 -static struct kset_uevent_ops dlm_uevent_ops = {
45169 +static const struct kset_uevent_ops dlm_uevent_ops = {
45170 .uevent = dlm_uevent,
45171 };
45172
45173 diff -urNp linux-2.6.39.1/fs/ecryptfs/inode.c linux-2.6.39.1/fs/ecryptfs/inode.c
45174 --- linux-2.6.39.1/fs/ecryptfs/inode.c 2011-06-03 00:04:14.000000000 -0400
45175 +++ linux-2.6.39.1/fs/ecryptfs/inode.c 2011-06-03 00:32:07.000000000 -0400
45176 @@ -623,7 +623,7 @@ static int ecryptfs_readlink_lower(struc
45177 old_fs = get_fs();
45178 set_fs(get_ds());
45179 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45180 - (char __user *)lower_buf,
45181 + (__force char __user *)lower_buf,
45182 lower_bufsiz);
45183 set_fs(old_fs);
45184 if (rc < 0)
45185 @@ -669,7 +669,7 @@ static void *ecryptfs_follow_link(struct
45186 }
45187 old_fs = get_fs();
45188 set_fs(get_ds());
45189 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
45190 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
45191 set_fs(old_fs);
45192 if (rc < 0) {
45193 kfree(buf);
45194 @@ -684,7 +684,7 @@ out:
45195 static void
45196 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45197 {
45198 - char *buf = nd_get_link(nd);
45199 + const char *buf = nd_get_link(nd);
45200 if (!IS_ERR(buf)) {
45201 /* Free the char* */
45202 kfree(buf);
45203 diff -urNp linux-2.6.39.1/fs/ecryptfs/miscdev.c linux-2.6.39.1/fs/ecryptfs/miscdev.c
45204 --- linux-2.6.39.1/fs/ecryptfs/miscdev.c 2011-05-19 00:06:34.000000000 -0400
45205 +++ linux-2.6.39.1/fs/ecryptfs/miscdev.c 2011-05-22 19:36:32.000000000 -0400
45206 @@ -328,7 +328,7 @@ check_list:
45207 goto out_unlock_msg_ctx;
45208 i = 5;
45209 if (msg_ctx->msg) {
45210 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
45211 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45212 goto out_unlock_msg_ctx;
45213 i += packet_length_size;
45214 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45215 diff -urNp linux-2.6.39.1/fs/exec.c linux-2.6.39.1/fs/exec.c
45216 --- linux-2.6.39.1/fs/exec.c 2011-05-19 00:06:34.000000000 -0400
45217 +++ linux-2.6.39.1/fs/exec.c 2011-06-03 01:37:12.000000000 -0400
45218 @@ -55,12 +55,24 @@
45219 #include <linux/fs_struct.h>
45220 #include <linux/pipe_fs_i.h>
45221 #include <linux/oom.h>
45222 +#include <linux/random.h>
45223 +#include <linux/seq_file.h>
45224 +
45225 +#ifdef CONFIG_PAX_REFCOUNT
45226 +#include <linux/kallsyms.h>
45227 +#include <linux/kdebug.h>
45228 +#endif
45229
45230 #include <asm/uaccess.h>
45231 #include <asm/mmu_context.h>
45232 #include <asm/tlb.h>
45233 #include "internal.h"
45234
45235 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45236 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45237 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45238 +#endif
45239 +
45240 int core_uses_pid;
45241 char core_pattern[CORENAME_MAX_SIZE] = "core";
45242 unsigned int core_pipe_limit;
45243 @@ -70,7 +82,7 @@ struct core_name {
45244 char *corename;
45245 int used, size;
45246 };
45247 -static atomic_t call_count = ATOMIC_INIT(1);
45248 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45249
45250 /* The maximal length of core_pattern is also specified in sysctl.c */
45251
45252 @@ -116,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __use
45253 char *tmp = getname(library);
45254 int error = PTR_ERR(tmp);
45255 static const struct open_flags uselib_flags = {
45256 - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45257 + .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45258 .acc_mode = MAY_READ | MAY_EXEC | MAY_OPEN,
45259 .intent = LOOKUP_OPEN
45260 };
45261 @@ -190,18 +202,10 @@ struct page *get_arg_page(struct linux_b
45262 int write)
45263 {
45264 struct page *page;
45265 - int ret;
45266
45267 -#ifdef CONFIG_STACK_GROWSUP
45268 - if (write) {
45269 - ret = expand_stack_downwards(bprm->vma, pos);
45270 - if (ret < 0)
45271 - return NULL;
45272 - }
45273 -#endif
45274 - ret = get_user_pages(current, bprm->mm, pos,
45275 - 1, write, 1, &page, NULL);
45276 - if (ret <= 0)
45277 + if (0 > expand_stack_downwards(bprm->vma, pos))
45278 + return NULL;
45279 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45280 return NULL;
45281
45282 if (write) {
45283 @@ -276,6 +280,11 @@ static int __bprm_mm_init(struct linux_b
45284 vma->vm_end = STACK_TOP_MAX;
45285 vma->vm_start = vma->vm_end - PAGE_SIZE;
45286 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45287 +
45288 +#ifdef CONFIG_PAX_SEGMEXEC
45289 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45290 +#endif
45291 +
45292 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45293 INIT_LIST_HEAD(&vma->anon_vma_chain);
45294
45295 @@ -290,6 +299,12 @@ static int __bprm_mm_init(struct linux_b
45296 mm->stack_vm = mm->total_vm = 1;
45297 up_write(&mm->mmap_sem);
45298 bprm->p = vma->vm_end - sizeof(void *);
45299 +
45300 +#ifdef CONFIG_PAX_RANDUSTACK
45301 + if (randomize_va_space)
45302 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
45303 +#endif
45304 +
45305 return 0;
45306 err:
45307 up_write(&mm->mmap_sem);
45308 @@ -525,7 +540,7 @@ int copy_strings_kernel(int argc, const
45309 int r;
45310 mm_segment_t oldfs = get_fs();
45311 set_fs(KERNEL_DS);
45312 - r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
45313 + r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
45314 set_fs(oldfs);
45315 return r;
45316 }
45317 @@ -555,7 +570,8 @@ static int shift_arg_pages(struct vm_are
45318 unsigned long new_end = old_end - shift;
45319 struct mmu_gather *tlb;
45320
45321 - BUG_ON(new_start > new_end);
45322 + if (new_start >= new_end || new_start < mmap_min_addr)
45323 + return -ENOMEM;
45324
45325 /*
45326 * ensure there are no vmas between where we want to go
45327 @@ -564,6 +580,10 @@ static int shift_arg_pages(struct vm_are
45328 if (vma != find_vma(mm, new_start))
45329 return -EFAULT;
45330
45331 +#ifdef CONFIG_PAX_SEGMEXEC
45332 + BUG_ON(pax_find_mirror_vma(vma));
45333 +#endif
45334 +
45335 /*
45336 * cover the whole range: [new_start, old_end)
45337 */
45338 @@ -644,10 +664,6 @@ int setup_arg_pages(struct linux_binprm
45339 stack_top = arch_align_stack(stack_top);
45340 stack_top = PAGE_ALIGN(stack_top);
45341
45342 - if (unlikely(stack_top < mmap_min_addr) ||
45343 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45344 - return -ENOMEM;
45345 -
45346 stack_shift = vma->vm_end - stack_top;
45347
45348 bprm->p -= stack_shift;
45349 @@ -659,8 +675,28 @@ int setup_arg_pages(struct linux_binprm
45350 bprm->exec -= stack_shift;
45351
45352 down_write(&mm->mmap_sem);
45353 +
45354 + /* Move stack pages down in memory. */
45355 + if (stack_shift) {
45356 + ret = shift_arg_pages(vma, stack_shift);
45357 + if (ret)
45358 + goto out_unlock;
45359 + }
45360 +
45361 vm_flags = VM_STACK_FLAGS;
45362
45363 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45364 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45365 + vm_flags &= ~VM_EXEC;
45366 +
45367 +#ifdef CONFIG_PAX_MPROTECT
45368 + if (mm->pax_flags & MF_PAX_MPROTECT)
45369 + vm_flags &= ~VM_MAYEXEC;
45370 +#endif
45371 +
45372 + }
45373 +#endif
45374 +
45375 /*
45376 * Adjust stack execute permissions; explicitly enable for
45377 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45378 @@ -679,13 +715,6 @@ int setup_arg_pages(struct linux_binprm
45379 goto out_unlock;
45380 BUG_ON(prev != vma);
45381
45382 - /* Move stack pages down in memory. */
45383 - if (stack_shift) {
45384 - ret = shift_arg_pages(vma, stack_shift);
45385 - if (ret)
45386 - goto out_unlock;
45387 - }
45388 -
45389 /* mprotect_fixup is overkill to remove the temporary stack flags */
45390 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45391
45392 @@ -725,7 +754,7 @@ struct file *open_exec(const char *name)
45393 struct file *file;
45394 int err;
45395 static const struct open_flags open_exec_flags = {
45396 - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45397 + .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45398 .acc_mode = MAY_EXEC | MAY_OPEN,
45399 .intent = LOOKUP_OPEN
45400 };
45401 @@ -766,7 +795,7 @@ int kernel_read(struct file *file, loff_
45402 old_fs = get_fs();
45403 set_fs(get_ds());
45404 /* The cast to a user pointer is valid due to the set_fs() */
45405 - result = vfs_read(file, (void __user *)addr, count, &pos);
45406 + result = vfs_read(file, (__force void __user *)addr, count, &pos);
45407 set_fs(old_fs);
45408 return result;
45409 }
45410 @@ -1188,7 +1217,7 @@ int check_unsafe_exec(struct linux_binpr
45411 }
45412 rcu_read_unlock();
45413
45414 - if (p->fs->users > n_fs) {
45415 + if (atomic_read(&p->fs->users) > n_fs) {
45416 bprm->unsafe |= LSM_UNSAFE_SHARE;
45417 } else {
45418 res = -EAGAIN;
45419 @@ -1384,6 +1413,11 @@ int do_execve(const char * filename,
45420 const char __user *const __user *envp,
45421 struct pt_regs * regs)
45422 {
45423 +#ifdef CONFIG_GRKERNSEC
45424 + struct file *old_exec_file;
45425 + struct acl_subject_label *old_acl;
45426 + struct rlimit old_rlim[RLIM_NLIMITS];
45427 +#endif
45428 struct linux_binprm *bprm;
45429 struct file *file;
45430 struct files_struct *displaced;
45431 @@ -1420,6 +1454,23 @@ int do_execve(const char * filename,
45432 bprm->filename = filename;
45433 bprm->interp = filename;
45434
45435 + if (gr_process_user_ban()) {
45436 + retval = -EPERM;
45437 + goto out_file;
45438 + }
45439 +
45440 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45441 +
45442 + if (gr_handle_nproc()) {
45443 + retval = -EAGAIN;
45444 + goto out_file;
45445 + }
45446 +
45447 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45448 + retval = -EACCES;
45449 + goto out_file;
45450 + }
45451 +
45452 retval = bprm_mm_init(bprm);
45453 if (retval)
45454 goto out_file;
45455 @@ -1449,9 +1500,40 @@ int do_execve(const char * filename,
45456 if (retval < 0)
45457 goto out;
45458
45459 + if (!gr_tpe_allow(file)) {
45460 + retval = -EACCES;
45461 + goto out;
45462 + }
45463 +
45464 + if (gr_check_crash_exec(file)) {
45465 + retval = -EACCES;
45466 + goto out;
45467 + }
45468 +
45469 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45470 +
45471 + gr_handle_exec_args(bprm, argv);
45472 +
45473 +#ifdef CONFIG_GRKERNSEC
45474 + old_acl = current->acl;
45475 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45476 + old_exec_file = current->exec_file;
45477 + get_file(file);
45478 + current->exec_file = file;
45479 +#endif
45480 +
45481 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45482 + bprm->unsafe & LSM_UNSAFE_SHARE);
45483 + if (retval < 0)
45484 + goto out_fail;
45485 +
45486 retval = search_binary_handler(bprm,regs);
45487 if (retval < 0)
45488 - goto out;
45489 + goto out_fail;
45490 +#ifdef CONFIG_GRKERNSEC
45491 + if (old_exec_file)
45492 + fput(old_exec_file);
45493 +#endif
45494
45495 /* execve succeeded */
45496 current->fs->in_exec = 0;
45497 @@ -1462,6 +1544,14 @@ int do_execve(const char * filename,
45498 put_files_struct(displaced);
45499 return retval;
45500
45501 +out_fail:
45502 +#ifdef CONFIG_GRKERNSEC
45503 + current->acl = old_acl;
45504 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45505 + fput(current->exec_file);
45506 + current->exec_file = old_exec_file;
45507 +#endif
45508 +
45509 out:
45510 if (bprm->mm) {
45511 acct_arg_size(bprm, 0);
45512 @@ -1507,7 +1597,7 @@ static int expand_corename(struct core_n
45513 {
45514 char *old_corename = cn->corename;
45515
45516 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45517 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45518 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45519
45520 if (!cn->corename) {
45521 @@ -1560,7 +1650,7 @@ static int format_corename(struct core_n
45522 int pid_in_pattern = 0;
45523 int err = 0;
45524
45525 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45526 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45527 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45528 cn->used = 0;
45529
45530 @@ -1648,6 +1738,220 @@ out:
45531 return ispipe;
45532 }
45533
45534 +int pax_check_flags(unsigned long *flags)
45535 +{
45536 + int retval = 0;
45537 +
45538 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45539 + if (*flags & MF_PAX_SEGMEXEC)
45540 + {
45541 + *flags &= ~MF_PAX_SEGMEXEC;
45542 + retval = -EINVAL;
45543 + }
45544 +#endif
45545 +
45546 + if ((*flags & MF_PAX_PAGEEXEC)
45547 +
45548 +#ifdef CONFIG_PAX_PAGEEXEC
45549 + && (*flags & MF_PAX_SEGMEXEC)
45550 +#endif
45551 +
45552 + )
45553 + {
45554 + *flags &= ~MF_PAX_PAGEEXEC;
45555 + retval = -EINVAL;
45556 + }
45557 +
45558 + if ((*flags & MF_PAX_MPROTECT)
45559 +
45560 +#ifdef CONFIG_PAX_MPROTECT
45561 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45562 +#endif
45563 +
45564 + )
45565 + {
45566 + *flags &= ~MF_PAX_MPROTECT;
45567 + retval = -EINVAL;
45568 + }
45569 +
45570 + if ((*flags & MF_PAX_EMUTRAMP)
45571 +
45572 +#ifdef CONFIG_PAX_EMUTRAMP
45573 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45574 +#endif
45575 +
45576 + )
45577 + {
45578 + *flags &= ~MF_PAX_EMUTRAMP;
45579 + retval = -EINVAL;
45580 + }
45581 +
45582 + return retval;
45583 +}
45584 +
45585 +EXPORT_SYMBOL(pax_check_flags);
45586 +
45587 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45588 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45589 +{
45590 + struct task_struct *tsk = current;
45591 + struct mm_struct *mm = current->mm;
45592 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45593 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45594 + char *path_exec = NULL;
45595 + char *path_fault = NULL;
45596 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45597 +
45598 + if (buffer_exec && buffer_fault) {
45599 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45600 +
45601 + down_read(&mm->mmap_sem);
45602 + vma = mm->mmap;
45603 + while (vma && (!vma_exec || !vma_fault)) {
45604 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45605 + vma_exec = vma;
45606 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45607 + vma_fault = vma;
45608 + vma = vma->vm_next;
45609 + }
45610 + if (vma_exec) {
45611 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45612 + if (IS_ERR(path_exec))
45613 + path_exec = "<path too long>";
45614 + else {
45615 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45616 + if (path_exec) {
45617 + *path_exec = 0;
45618 + path_exec = buffer_exec;
45619 + } else
45620 + path_exec = "<path too long>";
45621 + }
45622 + }
45623 + if (vma_fault) {
45624 + start = vma_fault->vm_start;
45625 + end = vma_fault->vm_end;
45626 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45627 + if (vma_fault->vm_file) {
45628 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45629 + if (IS_ERR(path_fault))
45630 + path_fault = "<path too long>";
45631 + else {
45632 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45633 + if (path_fault) {
45634 + *path_fault = 0;
45635 + path_fault = buffer_fault;
45636 + } else
45637 + path_fault = "<path too long>";
45638 + }
45639 + } else
45640 + path_fault = "<anonymous mapping>";
45641 + }
45642 + up_read(&mm->mmap_sem);
45643 + }
45644 + if (tsk->signal->curr_ip)
45645 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45646 + else
45647 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45648 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45649 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45650 + task_uid(tsk), task_euid(tsk), pc, sp);
45651 + free_page((unsigned long)buffer_exec);
45652 + free_page((unsigned long)buffer_fault);
45653 + pax_report_insns(pc, sp);
45654 + do_coredump(SIGKILL, SIGKILL, regs);
45655 +}
45656 +#endif
45657 +
45658 +#ifdef CONFIG_PAX_REFCOUNT
45659 +void pax_report_refcount_overflow(struct pt_regs *regs)
45660 +{
45661 + if (current->signal->curr_ip)
45662 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45663 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45664 + else
45665 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45666 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45667 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45668 + show_regs(regs);
45669 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45670 +}
45671 +#endif
45672 +
45673 +#ifdef CONFIG_PAX_USERCOPY
45674 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45675 +int object_is_on_stack(const void *obj, unsigned long len)
45676 +{
45677 + const void * const stack = task_stack_page(current);
45678 + const void * const stackend = stack + THREAD_SIZE;
45679 +
45680 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45681 + const void *frame = NULL;
45682 + const void *oldframe;
45683 +#endif
45684 +
45685 + if (obj + len < obj)
45686 + return -1;
45687 +
45688 + if (obj + len <= stack || stackend <= obj)
45689 + return 0;
45690 +
45691 + if (obj < stack || stackend < obj + len)
45692 + return -1;
45693 +
45694 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45695 + oldframe = __builtin_frame_address(1);
45696 + if (oldframe)
45697 + frame = __builtin_frame_address(2);
45698 + /*
45699 + low ----------------------------------------------> high
45700 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45701 + ^----------------^
45702 + allow copies only within here
45703 + */
45704 + while (stack <= frame && frame < stackend) {
45705 + /* if obj + len extends past the last frame, this
45706 + check won't pass and the next frame will be 0,
45707 + causing us to bail out and correctly report
45708 + the copy as invalid
45709 + */
45710 + if (obj + len <= frame)
45711 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45712 + oldframe = frame;
45713 + frame = *(const void * const *)frame;
45714 + }
45715 + return -1;
45716 +#else
45717 + return 1;
45718 +#endif
45719 +}
45720 +
45721 +
45722 +void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45723 +{
45724 + if (current->signal->curr_ip)
45725 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45726 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45727 + else
45728 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45729 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45730 + dump_stack();
45731 + gr_handle_kernel_exploit();
45732 + do_group_exit(SIGKILL);
45733 +}
45734 +#endif
45735 +
45736 +#if __GNUC__ == 4 && __GNUC_MINOR__ >= 5
45737 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45738 +void pax_track_stack_gcc(unsigned long sp)
45739 +{
45740 + if (sp < current_thread_info()->lowest_stack &&
45741 + sp > (unsigned long)task_stack_page(current))
45742 + current_thread_info()->lowest_stack = sp;
45743 +}
45744 +EXPORT_SYMBOL(pax_track_stack_gcc);
45745 +#endif
45746 +#endif
45747 +
45748 static int zap_process(struct task_struct *start, int exit_code)
45749 {
45750 struct task_struct *t;
45751 @@ -1858,17 +2162,17 @@ static void wait_for_dump_helpers(struct
45752 pipe = file->f_path.dentry->d_inode->i_pipe;
45753
45754 pipe_lock(pipe);
45755 - pipe->readers++;
45756 - pipe->writers--;
45757 + atomic_inc(&pipe->readers);
45758 + atomic_dec(&pipe->writers);
45759
45760 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45761 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45762 wake_up_interruptible_sync(&pipe->wait);
45763 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45764 pipe_wait(pipe);
45765 }
45766
45767 - pipe->readers--;
45768 - pipe->writers++;
45769 + atomic_dec(&pipe->readers);
45770 + atomic_inc(&pipe->writers);
45771 pipe_unlock(pipe);
45772
45773 }
45774 @@ -1929,7 +2233,7 @@ void do_coredump(long signr, int exit_co
45775 int retval = 0;
45776 int flag = 0;
45777 int ispipe;
45778 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45779 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45780 struct coredump_params cprm = {
45781 .signr = signr,
45782 .regs = regs,
45783 @@ -1944,6 +2248,9 @@ void do_coredump(long signr, int exit_co
45784
45785 audit_core_dumps(signr);
45786
45787 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45788 + gr_handle_brute_attach(current, cprm.mm_flags);
45789 +
45790 binfmt = mm->binfmt;
45791 if (!binfmt || !binfmt->core_dump)
45792 goto fail;
45793 @@ -1984,6 +2291,8 @@ void do_coredump(long signr, int exit_co
45794 goto fail_corename;
45795 }
45796
45797 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45798 +
45799 if (ispipe) {
45800 int dump_count;
45801 char **helper_argv;
45802 @@ -2011,7 +2320,7 @@ void do_coredump(long signr, int exit_co
45803 }
45804 cprm.limit = RLIM_INFINITY;
45805
45806 - dump_count = atomic_inc_return(&core_dump_count);
45807 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45808 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45809 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45810 task_tgid_vnr(current), current->comm);
45811 @@ -2081,7 +2390,7 @@ close_fail:
45812 filp_close(cprm.file, NULL);
45813 fail_dropcount:
45814 if (ispipe)
45815 - atomic_dec(&core_dump_count);
45816 + atomic_dec_unchecked(&core_dump_count);
45817 fail_unlock:
45818 kfree(cn.corename);
45819 fail_corename:
45820 diff -urNp linux-2.6.39.1/fs/ext2/balloc.c linux-2.6.39.1/fs/ext2/balloc.c
45821 --- linux-2.6.39.1/fs/ext2/balloc.c 2011-05-19 00:06:34.000000000 -0400
45822 +++ linux-2.6.39.1/fs/ext2/balloc.c 2011-05-22 19:41:37.000000000 -0400
45823 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
45824
45825 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45826 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45827 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45828 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45829 sbi->s_resuid != current_fsuid() &&
45830 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45831 return 0;
45832 diff -urNp linux-2.6.39.1/fs/ext3/balloc.c linux-2.6.39.1/fs/ext3/balloc.c
45833 --- linux-2.6.39.1/fs/ext3/balloc.c 2011-05-19 00:06:34.000000000 -0400
45834 +++ linux-2.6.39.1/fs/ext3/balloc.c 2011-05-22 19:41:37.000000000 -0400
45835 @@ -1441,7 +1441,7 @@ static int ext3_has_free_blocks(struct e
45836
45837 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45838 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45839 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45840 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45841 sbi->s_resuid != current_fsuid() &&
45842 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45843 return 0;
45844 diff -urNp linux-2.6.39.1/fs/ext4/balloc.c linux-2.6.39.1/fs/ext4/balloc.c
45845 --- linux-2.6.39.1/fs/ext4/balloc.c 2011-05-19 00:06:34.000000000 -0400
45846 +++ linux-2.6.39.1/fs/ext4/balloc.c 2011-05-22 19:41:37.000000000 -0400
45847 @@ -522,7 +522,7 @@ static int ext4_has_free_blocks(struct e
45848 /* Hm, nope. Are (enough) root reserved blocks available? */
45849 if (sbi->s_resuid == current_fsuid() ||
45850 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45851 - capable(CAP_SYS_RESOURCE)) {
45852 + capable_nolog(CAP_SYS_RESOURCE)) {
45853 if (free_blocks >= (nblocks + dirty_blocks))
45854 return 1;
45855 }
45856 diff -urNp linux-2.6.39.1/fs/ext4/ext4.h linux-2.6.39.1/fs/ext4/ext4.h
45857 --- linux-2.6.39.1/fs/ext4/ext4.h 2011-06-03 00:04:14.000000000 -0400
45858 +++ linux-2.6.39.1/fs/ext4/ext4.h 2011-06-03 00:32:07.000000000 -0400
45859 @@ -1166,19 +1166,19 @@ struct ext4_sb_info {
45860 unsigned long s_mb_last_start;
45861
45862 /* stats for buddy allocator */
45863 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45864 - atomic_t s_bal_success; /* we found long enough chunks */
45865 - atomic_t s_bal_allocated; /* in blocks */
45866 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45867 - atomic_t s_bal_goals; /* goal hits */
45868 - atomic_t s_bal_breaks; /* too long searches */
45869 - atomic_t s_bal_2orders; /* 2^order hits */
45870 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45871 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45872 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45873 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45874 + atomic_unchecked_t s_bal_goals; /* goal hits */
45875 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45876 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45877 spinlock_t s_bal_lock;
45878 unsigned long s_mb_buddies_generated;
45879 unsigned long long s_mb_generation_time;
45880 - atomic_t s_mb_lost_chunks;
45881 - atomic_t s_mb_preallocated;
45882 - atomic_t s_mb_discarded;
45883 + atomic_unchecked_t s_mb_lost_chunks;
45884 + atomic_unchecked_t s_mb_preallocated;
45885 + atomic_unchecked_t s_mb_discarded;
45886 atomic_t s_lock_busy;
45887
45888 /* locality groups */
45889 diff -urNp linux-2.6.39.1/fs/ext4/mballoc.c linux-2.6.39.1/fs/ext4/mballoc.c
45890 --- linux-2.6.39.1/fs/ext4/mballoc.c 2011-06-03 00:04:14.000000000 -0400
45891 +++ linux-2.6.39.1/fs/ext4/mballoc.c 2011-06-03 00:32:07.000000000 -0400
45892 @@ -1853,7 +1853,7 @@ void ext4_mb_simple_scan_group(struct ex
45893 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45894
45895 if (EXT4_SB(sb)->s_mb_stats)
45896 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45897 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45898
45899 break;
45900 }
45901 @@ -2147,7 +2147,7 @@ repeat:
45902 ac->ac_status = AC_STATUS_CONTINUE;
45903 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45904 cr = 3;
45905 - atomic_inc(&sbi->s_mb_lost_chunks);
45906 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45907 goto repeat;
45908 }
45909 }
45910 @@ -2190,6 +2190,8 @@ static int ext4_mb_seq_groups_show(struc
45911 ext4_grpblk_t counters[16];
45912 } sg;
45913
45914 + pax_track_stack();
45915 +
45916 group--;
45917 if (group == 0)
45918 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
45919 @@ -2613,25 +2615,25 @@ int ext4_mb_release(struct super_block *
45920 if (sbi->s_mb_stats) {
45921 printk(KERN_INFO
45922 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
45923 - atomic_read(&sbi->s_bal_allocated),
45924 - atomic_read(&sbi->s_bal_reqs),
45925 - atomic_read(&sbi->s_bal_success));
45926 + atomic_read_unchecked(&sbi->s_bal_allocated),
45927 + atomic_read_unchecked(&sbi->s_bal_reqs),
45928 + atomic_read_unchecked(&sbi->s_bal_success));
45929 printk(KERN_INFO
45930 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
45931 "%u 2^N hits, %u breaks, %u lost\n",
45932 - atomic_read(&sbi->s_bal_ex_scanned),
45933 - atomic_read(&sbi->s_bal_goals),
45934 - atomic_read(&sbi->s_bal_2orders),
45935 - atomic_read(&sbi->s_bal_breaks),
45936 - atomic_read(&sbi->s_mb_lost_chunks));
45937 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45938 + atomic_read_unchecked(&sbi->s_bal_goals),
45939 + atomic_read_unchecked(&sbi->s_bal_2orders),
45940 + atomic_read_unchecked(&sbi->s_bal_breaks),
45941 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45942 printk(KERN_INFO
45943 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
45944 sbi->s_mb_buddies_generated++,
45945 sbi->s_mb_generation_time);
45946 printk(KERN_INFO
45947 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
45948 - atomic_read(&sbi->s_mb_preallocated),
45949 - atomic_read(&sbi->s_mb_discarded));
45950 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45951 + atomic_read_unchecked(&sbi->s_mb_discarded));
45952 }
45953
45954 free_percpu(sbi->s_locality_groups);
45955 @@ -3107,16 +3109,16 @@ static void ext4_mb_collect_stats(struct
45956 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45957
45958 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45959 - atomic_inc(&sbi->s_bal_reqs);
45960 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45961 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45962 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45963 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45964 - atomic_inc(&sbi->s_bal_success);
45965 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45966 + atomic_inc_unchecked(&sbi->s_bal_success);
45967 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45968 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45969 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45970 - atomic_inc(&sbi->s_bal_goals);
45971 + atomic_inc_unchecked(&sbi->s_bal_goals);
45972 if (ac->ac_found > sbi->s_mb_max_to_scan)
45973 - atomic_inc(&sbi->s_bal_breaks);
45974 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45975 }
45976
45977 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45978 @@ -3514,7 +3516,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
45979 trace_ext4_mb_new_inode_pa(ac, pa);
45980
45981 ext4_mb_use_inode_pa(ac, pa);
45982 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45983 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45984
45985 ei = EXT4_I(ac->ac_inode);
45986 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45987 @@ -3574,7 +3576,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
45988 trace_ext4_mb_new_group_pa(ac, pa);
45989
45990 ext4_mb_use_group_pa(ac, pa);
45991 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45992 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45993
45994 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45995 lg = ac->ac_lg;
45996 @@ -3661,7 +3663,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
45997 * from the bitmap and continue.
45998 */
45999 }
46000 - atomic_add(free, &sbi->s_mb_discarded);
46001 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
46002
46003 return err;
46004 }
46005 @@ -3679,7 +3681,7 @@ ext4_mb_release_group_pa(struct ext4_bud
46006 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46007 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46008 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46009 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46010 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46011 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46012
46013 return 0;
46014 diff -urNp linux-2.6.39.1/fs/fcntl.c linux-2.6.39.1/fs/fcntl.c
46015 --- linux-2.6.39.1/fs/fcntl.c 2011-05-19 00:06:34.000000000 -0400
46016 +++ linux-2.6.39.1/fs/fcntl.c 2011-05-22 20:45:50.000000000 -0400
46017 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
46018 if (err)
46019 return err;
46020
46021 + if (gr_handle_chroot_fowner(pid, type))
46022 + return -ENOENT;
46023 + if (gr_check_protected_task_fowner(pid, type))
46024 + return -EACCES;
46025 +
46026 f_modown(filp, pid, type, force);
46027 return 0;
46028 }
46029 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
46030 switch (cmd) {
46031 case F_DUPFD:
46032 case F_DUPFD_CLOEXEC:
46033 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46034 if (arg >= rlimit(RLIMIT_NOFILE))
46035 break;
46036 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46037 @@ -835,14 +841,14 @@ static int __init fcntl_init(void)
46038 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
46039 * is defined as O_NONBLOCK on some platforms and not on others.
46040 */
46041 - BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
46042 + BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
46043 O_RDONLY | O_WRONLY | O_RDWR |
46044 O_CREAT | O_EXCL | O_NOCTTY |
46045 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
46046 __O_SYNC | O_DSYNC | FASYNC |
46047 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
46048 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
46049 - __FMODE_EXEC | O_PATH
46050 + __FMODE_EXEC | O_PATH | FMODE_GREXEC
46051 ));
46052
46053 fasync_cache = kmem_cache_create("fasync_cache",
46054 diff -urNp linux-2.6.39.1/fs/fifo.c linux-2.6.39.1/fs/fifo.c
46055 --- linux-2.6.39.1/fs/fifo.c 2011-05-19 00:06:34.000000000 -0400
46056 +++ linux-2.6.39.1/fs/fifo.c 2011-05-22 19:36:32.000000000 -0400
46057 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
46058 */
46059 filp->f_op = &read_pipefifo_fops;
46060 pipe->r_counter++;
46061 - if (pipe->readers++ == 0)
46062 + if (atomic_inc_return(&pipe->readers) == 1)
46063 wake_up_partner(inode);
46064
46065 - if (!pipe->writers) {
46066 + if (!atomic_read(&pipe->writers)) {
46067 if ((filp->f_flags & O_NONBLOCK)) {
46068 /* suppress POLLHUP until we have
46069 * seen a writer */
46070 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode
46071 * errno=ENXIO when there is no process reading the FIFO.
46072 */
46073 ret = -ENXIO;
46074 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46075 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46076 goto err;
46077
46078 filp->f_op = &write_pipefifo_fops;
46079 pipe->w_counter++;
46080 - if (!pipe->writers++)
46081 + if (atomic_inc_return(&pipe->writers) == 1)
46082 wake_up_partner(inode);
46083
46084 - if (!pipe->readers) {
46085 + if (!atomic_read(&pipe->readers)) {
46086 wait_for_partner(inode, &pipe->r_counter);
46087 if (signal_pending(current))
46088 goto err_wr;
46089 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode
46090 */
46091 filp->f_op = &rdwr_pipefifo_fops;
46092
46093 - pipe->readers++;
46094 - pipe->writers++;
46095 + atomic_inc(&pipe->readers);
46096 + atomic_inc(&pipe->writers);
46097 pipe->r_counter++;
46098 pipe->w_counter++;
46099 - if (pipe->readers == 1 || pipe->writers == 1)
46100 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46101 wake_up_partner(inode);
46102 break;
46103
46104 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode
46105 return 0;
46106
46107 err_rd:
46108 - if (!--pipe->readers)
46109 + if (atomic_dec_and_test(&pipe->readers))
46110 wake_up_interruptible(&pipe->wait);
46111 ret = -ERESTARTSYS;
46112 goto err;
46113
46114 err_wr:
46115 - if (!--pipe->writers)
46116 + if (atomic_dec_and_test(&pipe->writers))
46117 wake_up_interruptible(&pipe->wait);
46118 ret = -ERESTARTSYS;
46119 goto err;
46120
46121 err:
46122 - if (!pipe->readers && !pipe->writers)
46123 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46124 free_pipe_info(inode);
46125
46126 err_nocleanup:
46127 diff -urNp linux-2.6.39.1/fs/file.c linux-2.6.39.1/fs/file.c
46128 --- linux-2.6.39.1/fs/file.c 2011-05-19 00:06:34.000000000 -0400
46129 +++ linux-2.6.39.1/fs/file.c 2011-05-22 19:41:37.000000000 -0400
46130 @@ -15,6 +15,7 @@
46131 #include <linux/slab.h>
46132 #include <linux/vmalloc.h>
46133 #include <linux/file.h>
46134 +#include <linux/security.h>
46135 #include <linux/fdtable.h>
46136 #include <linux/bitops.h>
46137 #include <linux/interrupt.h>
46138 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *fi
46139 * N.B. For clone tasks sharing a files structure, this test
46140 * will limit the total number of files that can be opened.
46141 */
46142 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46143 if (nr >= rlimit(RLIMIT_NOFILE))
46144 return -EMFILE;
46145
46146 diff -urNp linux-2.6.39.1/fs/filesystems.c linux-2.6.39.1/fs/filesystems.c
46147 --- linux-2.6.39.1/fs/filesystems.c 2011-05-19 00:06:34.000000000 -0400
46148 +++ linux-2.6.39.1/fs/filesystems.c 2011-05-22 19:41:37.000000000 -0400
46149 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(con
46150 int len = dot ? dot - name : strlen(name);
46151
46152 fs = __get_fs_type(name, len);
46153 +
46154 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46155 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46156 +#else
46157 if (!fs && (request_module("%.*s", len, name) == 0))
46158 +#endif
46159 fs = __get_fs_type(name, len);
46160
46161 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46162 diff -urNp linux-2.6.39.1/fs/fscache/cookie.c linux-2.6.39.1/fs/fscache/cookie.c
46163 --- linux-2.6.39.1/fs/fscache/cookie.c 2011-05-19 00:06:34.000000000 -0400
46164 +++ linux-2.6.39.1/fs/fscache/cookie.c 2011-05-22 19:36:32.000000000 -0400
46165 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
46166 parent ? (char *) parent->def->name : "<no-parent>",
46167 def->name, netfs_data);
46168
46169 - fscache_stat(&fscache_n_acquires);
46170 + fscache_stat_unchecked(&fscache_n_acquires);
46171
46172 /* if there's no parent cookie, then we don't create one here either */
46173 if (!parent) {
46174 - fscache_stat(&fscache_n_acquires_null);
46175 + fscache_stat_unchecked(&fscache_n_acquires_null);
46176 _leave(" [no parent]");
46177 return NULL;
46178 }
46179 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
46180 /* allocate and initialise a cookie */
46181 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46182 if (!cookie) {
46183 - fscache_stat(&fscache_n_acquires_oom);
46184 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46185 _leave(" [ENOMEM]");
46186 return NULL;
46187 }
46188 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
46189
46190 switch (cookie->def->type) {
46191 case FSCACHE_COOKIE_TYPE_INDEX:
46192 - fscache_stat(&fscache_n_cookie_index);
46193 + fscache_stat_unchecked(&fscache_n_cookie_index);
46194 break;
46195 case FSCACHE_COOKIE_TYPE_DATAFILE:
46196 - fscache_stat(&fscache_n_cookie_data);
46197 + fscache_stat_unchecked(&fscache_n_cookie_data);
46198 break;
46199 default:
46200 - fscache_stat(&fscache_n_cookie_special);
46201 + fscache_stat_unchecked(&fscache_n_cookie_special);
46202 break;
46203 }
46204
46205 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
46206 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46207 atomic_dec(&parent->n_children);
46208 __fscache_cookie_put(cookie);
46209 - fscache_stat(&fscache_n_acquires_nobufs);
46210 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46211 _leave(" = NULL");
46212 return NULL;
46213 }
46214 }
46215
46216 - fscache_stat(&fscache_n_acquires_ok);
46217 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46218 _leave(" = %p", cookie);
46219 return cookie;
46220 }
46221 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
46222 cache = fscache_select_cache_for_object(cookie->parent);
46223 if (!cache) {
46224 up_read(&fscache_addremove_sem);
46225 - fscache_stat(&fscache_n_acquires_no_cache);
46226 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46227 _leave(" = -ENOMEDIUM [no cache]");
46228 return -ENOMEDIUM;
46229 }
46230 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
46231 object = cache->ops->alloc_object(cache, cookie);
46232 fscache_stat_d(&fscache_n_cop_alloc_object);
46233 if (IS_ERR(object)) {
46234 - fscache_stat(&fscache_n_object_no_alloc);
46235 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46236 ret = PTR_ERR(object);
46237 goto error;
46238 }
46239
46240 - fscache_stat(&fscache_n_object_alloc);
46241 + fscache_stat_unchecked(&fscache_n_object_alloc);
46242
46243 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46244
46245 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
46246 struct fscache_object *object;
46247 struct hlist_node *_p;
46248
46249 - fscache_stat(&fscache_n_updates);
46250 + fscache_stat_unchecked(&fscache_n_updates);
46251
46252 if (!cookie) {
46253 - fscache_stat(&fscache_n_updates_null);
46254 + fscache_stat_unchecked(&fscache_n_updates_null);
46255 _leave(" [no cookie]");
46256 return;
46257 }
46258 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
46259 struct fscache_object *object;
46260 unsigned long event;
46261
46262 - fscache_stat(&fscache_n_relinquishes);
46263 + fscache_stat_unchecked(&fscache_n_relinquishes);
46264 if (retire)
46265 - fscache_stat(&fscache_n_relinquishes_retire);
46266 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46267
46268 if (!cookie) {
46269 - fscache_stat(&fscache_n_relinquishes_null);
46270 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46271 _leave(" [no cookie]");
46272 return;
46273 }
46274 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
46275
46276 /* wait for the cookie to finish being instantiated (or to fail) */
46277 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46278 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46279 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46280 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46281 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46282 }
46283 diff -urNp linux-2.6.39.1/fs/fscache/internal.h linux-2.6.39.1/fs/fscache/internal.h
46284 --- linux-2.6.39.1/fs/fscache/internal.h 2011-05-19 00:06:34.000000000 -0400
46285 +++ linux-2.6.39.1/fs/fscache/internal.h 2011-05-22 19:36:32.000000000 -0400
46286 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46287 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46288 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46289
46290 -extern atomic_t fscache_n_op_pend;
46291 -extern atomic_t fscache_n_op_run;
46292 -extern atomic_t fscache_n_op_enqueue;
46293 -extern atomic_t fscache_n_op_deferred_release;
46294 -extern atomic_t fscache_n_op_release;
46295 -extern atomic_t fscache_n_op_gc;
46296 -extern atomic_t fscache_n_op_cancelled;
46297 -extern atomic_t fscache_n_op_rejected;
46298 -
46299 -extern atomic_t fscache_n_attr_changed;
46300 -extern atomic_t fscache_n_attr_changed_ok;
46301 -extern atomic_t fscache_n_attr_changed_nobufs;
46302 -extern atomic_t fscache_n_attr_changed_nomem;
46303 -extern atomic_t fscache_n_attr_changed_calls;
46304 -
46305 -extern atomic_t fscache_n_allocs;
46306 -extern atomic_t fscache_n_allocs_ok;
46307 -extern atomic_t fscache_n_allocs_wait;
46308 -extern atomic_t fscache_n_allocs_nobufs;
46309 -extern atomic_t fscache_n_allocs_intr;
46310 -extern atomic_t fscache_n_allocs_object_dead;
46311 -extern atomic_t fscache_n_alloc_ops;
46312 -extern atomic_t fscache_n_alloc_op_waits;
46313 -
46314 -extern atomic_t fscache_n_retrievals;
46315 -extern atomic_t fscache_n_retrievals_ok;
46316 -extern atomic_t fscache_n_retrievals_wait;
46317 -extern atomic_t fscache_n_retrievals_nodata;
46318 -extern atomic_t fscache_n_retrievals_nobufs;
46319 -extern atomic_t fscache_n_retrievals_intr;
46320 -extern atomic_t fscache_n_retrievals_nomem;
46321 -extern atomic_t fscache_n_retrievals_object_dead;
46322 -extern atomic_t fscache_n_retrieval_ops;
46323 -extern atomic_t fscache_n_retrieval_op_waits;
46324 -
46325 -extern atomic_t fscache_n_stores;
46326 -extern atomic_t fscache_n_stores_ok;
46327 -extern atomic_t fscache_n_stores_again;
46328 -extern atomic_t fscache_n_stores_nobufs;
46329 -extern atomic_t fscache_n_stores_oom;
46330 -extern atomic_t fscache_n_store_ops;
46331 -extern atomic_t fscache_n_store_calls;
46332 -extern atomic_t fscache_n_store_pages;
46333 -extern atomic_t fscache_n_store_radix_deletes;
46334 -extern atomic_t fscache_n_store_pages_over_limit;
46335 -
46336 -extern atomic_t fscache_n_store_vmscan_not_storing;
46337 -extern atomic_t fscache_n_store_vmscan_gone;
46338 -extern atomic_t fscache_n_store_vmscan_busy;
46339 -extern atomic_t fscache_n_store_vmscan_cancelled;
46340 -
46341 -extern atomic_t fscache_n_marks;
46342 -extern atomic_t fscache_n_uncaches;
46343 -
46344 -extern atomic_t fscache_n_acquires;
46345 -extern atomic_t fscache_n_acquires_null;
46346 -extern atomic_t fscache_n_acquires_no_cache;
46347 -extern atomic_t fscache_n_acquires_ok;
46348 -extern atomic_t fscache_n_acquires_nobufs;
46349 -extern atomic_t fscache_n_acquires_oom;
46350 -
46351 -extern atomic_t fscache_n_updates;
46352 -extern atomic_t fscache_n_updates_null;
46353 -extern atomic_t fscache_n_updates_run;
46354 -
46355 -extern atomic_t fscache_n_relinquishes;
46356 -extern atomic_t fscache_n_relinquishes_null;
46357 -extern atomic_t fscache_n_relinquishes_waitcrt;
46358 -extern atomic_t fscache_n_relinquishes_retire;
46359 -
46360 -extern atomic_t fscache_n_cookie_index;
46361 -extern atomic_t fscache_n_cookie_data;
46362 -extern atomic_t fscache_n_cookie_special;
46363 -
46364 -extern atomic_t fscache_n_object_alloc;
46365 -extern atomic_t fscache_n_object_no_alloc;
46366 -extern atomic_t fscache_n_object_lookups;
46367 -extern atomic_t fscache_n_object_lookups_negative;
46368 -extern atomic_t fscache_n_object_lookups_positive;
46369 -extern atomic_t fscache_n_object_lookups_timed_out;
46370 -extern atomic_t fscache_n_object_created;
46371 -extern atomic_t fscache_n_object_avail;
46372 -extern atomic_t fscache_n_object_dead;
46373 -
46374 -extern atomic_t fscache_n_checkaux_none;
46375 -extern atomic_t fscache_n_checkaux_okay;
46376 -extern atomic_t fscache_n_checkaux_update;
46377 -extern atomic_t fscache_n_checkaux_obsolete;
46378 +extern atomic_unchecked_t fscache_n_op_pend;
46379 +extern atomic_unchecked_t fscache_n_op_run;
46380 +extern atomic_unchecked_t fscache_n_op_enqueue;
46381 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46382 +extern atomic_unchecked_t fscache_n_op_release;
46383 +extern atomic_unchecked_t fscache_n_op_gc;
46384 +extern atomic_unchecked_t fscache_n_op_cancelled;
46385 +extern atomic_unchecked_t fscache_n_op_rejected;
46386 +
46387 +extern atomic_unchecked_t fscache_n_attr_changed;
46388 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46389 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46390 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46391 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46392 +
46393 +extern atomic_unchecked_t fscache_n_allocs;
46394 +extern atomic_unchecked_t fscache_n_allocs_ok;
46395 +extern atomic_unchecked_t fscache_n_allocs_wait;
46396 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46397 +extern atomic_unchecked_t fscache_n_allocs_intr;
46398 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46399 +extern atomic_unchecked_t fscache_n_alloc_ops;
46400 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46401 +
46402 +extern atomic_unchecked_t fscache_n_retrievals;
46403 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46404 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46405 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46406 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46407 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46408 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46409 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46410 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46411 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46412 +
46413 +extern atomic_unchecked_t fscache_n_stores;
46414 +extern atomic_unchecked_t fscache_n_stores_ok;
46415 +extern atomic_unchecked_t fscache_n_stores_again;
46416 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46417 +extern atomic_unchecked_t fscache_n_stores_oom;
46418 +extern atomic_unchecked_t fscache_n_store_ops;
46419 +extern atomic_unchecked_t fscache_n_store_calls;
46420 +extern atomic_unchecked_t fscache_n_store_pages;
46421 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46422 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46423 +
46424 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46425 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46426 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46427 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46428 +
46429 +extern atomic_unchecked_t fscache_n_marks;
46430 +extern atomic_unchecked_t fscache_n_uncaches;
46431 +
46432 +extern atomic_unchecked_t fscache_n_acquires;
46433 +extern atomic_unchecked_t fscache_n_acquires_null;
46434 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46435 +extern atomic_unchecked_t fscache_n_acquires_ok;
46436 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46437 +extern atomic_unchecked_t fscache_n_acquires_oom;
46438 +
46439 +extern atomic_unchecked_t fscache_n_updates;
46440 +extern atomic_unchecked_t fscache_n_updates_null;
46441 +extern atomic_unchecked_t fscache_n_updates_run;
46442 +
46443 +extern atomic_unchecked_t fscache_n_relinquishes;
46444 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46445 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46446 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46447 +
46448 +extern atomic_unchecked_t fscache_n_cookie_index;
46449 +extern atomic_unchecked_t fscache_n_cookie_data;
46450 +extern atomic_unchecked_t fscache_n_cookie_special;
46451 +
46452 +extern atomic_unchecked_t fscache_n_object_alloc;
46453 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46454 +extern atomic_unchecked_t fscache_n_object_lookups;
46455 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46456 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46457 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46458 +extern atomic_unchecked_t fscache_n_object_created;
46459 +extern atomic_unchecked_t fscache_n_object_avail;
46460 +extern atomic_unchecked_t fscache_n_object_dead;
46461 +
46462 +extern atomic_unchecked_t fscache_n_checkaux_none;
46463 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46464 +extern atomic_unchecked_t fscache_n_checkaux_update;
46465 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46466
46467 extern atomic_t fscache_n_cop_alloc_object;
46468 extern atomic_t fscache_n_cop_lookup_object;
46469 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t
46470 atomic_inc(stat);
46471 }
46472
46473 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46474 +{
46475 + atomic_inc_unchecked(stat);
46476 +}
46477 +
46478 static inline void fscache_stat_d(atomic_t *stat)
46479 {
46480 atomic_dec(stat);
46481 @@ -267,6 +272,7 @@ extern const struct file_operations fsca
46482
46483 #define __fscache_stat(stat) (NULL)
46484 #define fscache_stat(stat) do {} while (0)
46485 +#define fscache_stat_unchecked(stat) do {} while (0)
46486 #define fscache_stat_d(stat) do {} while (0)
46487 #endif
46488
46489 diff -urNp linux-2.6.39.1/fs/fscache/object.c linux-2.6.39.1/fs/fscache/object.c
46490 --- linux-2.6.39.1/fs/fscache/object.c 2011-05-19 00:06:34.000000000 -0400
46491 +++ linux-2.6.39.1/fs/fscache/object.c 2011-05-22 19:36:32.000000000 -0400
46492 @@ -128,7 +128,7 @@ static void fscache_object_state_machine
46493 /* update the object metadata on disk */
46494 case FSCACHE_OBJECT_UPDATING:
46495 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46496 - fscache_stat(&fscache_n_updates_run);
46497 + fscache_stat_unchecked(&fscache_n_updates_run);
46498 fscache_stat(&fscache_n_cop_update_object);
46499 object->cache->ops->update_object(object);
46500 fscache_stat_d(&fscache_n_cop_update_object);
46501 @@ -217,7 +217,7 @@ static void fscache_object_state_machine
46502 spin_lock(&object->lock);
46503 object->state = FSCACHE_OBJECT_DEAD;
46504 spin_unlock(&object->lock);
46505 - fscache_stat(&fscache_n_object_dead);
46506 + fscache_stat_unchecked(&fscache_n_object_dead);
46507 goto terminal_transit;
46508
46509 /* handle the parent cache of this object being withdrawn from
46510 @@ -232,7 +232,7 @@ static void fscache_object_state_machine
46511 spin_lock(&object->lock);
46512 object->state = FSCACHE_OBJECT_DEAD;
46513 spin_unlock(&object->lock);
46514 - fscache_stat(&fscache_n_object_dead);
46515 + fscache_stat_unchecked(&fscache_n_object_dead);
46516 goto terminal_transit;
46517
46518 /* complain about the object being woken up once it is
46519 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct
46520 parent->cookie->def->name, cookie->def->name,
46521 object->cache->tag->name);
46522
46523 - fscache_stat(&fscache_n_object_lookups);
46524 + fscache_stat_unchecked(&fscache_n_object_lookups);
46525 fscache_stat(&fscache_n_cop_lookup_object);
46526 ret = object->cache->ops->lookup_object(object);
46527 fscache_stat_d(&fscache_n_cop_lookup_object);
46528 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct
46529 if (ret == -ETIMEDOUT) {
46530 /* probably stuck behind another object, so move this one to
46531 * the back of the queue */
46532 - fscache_stat(&fscache_n_object_lookups_timed_out);
46533 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46534 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46535 }
46536
46537 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(stru
46538
46539 spin_lock(&object->lock);
46540 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46541 - fscache_stat(&fscache_n_object_lookups_negative);
46542 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46543
46544 /* transit here to allow write requests to begin stacking up
46545 * and read requests to begin returning ENODATA */
46546 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fsca
46547 * result, in which case there may be data available */
46548 spin_lock(&object->lock);
46549 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46550 - fscache_stat(&fscache_n_object_lookups_positive);
46551 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46552
46553 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46554
46555 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fsca
46556 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46557 } else {
46558 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46559 - fscache_stat(&fscache_n_object_created);
46560 + fscache_stat_unchecked(&fscache_n_object_created);
46561
46562 object->state = FSCACHE_OBJECT_AVAILABLE;
46563 spin_unlock(&object->lock);
46564 @@ -602,7 +602,7 @@ static void fscache_object_available(str
46565 fscache_enqueue_dependents(object);
46566
46567 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46568 - fscache_stat(&fscache_n_object_avail);
46569 + fscache_stat_unchecked(&fscache_n_object_avail);
46570
46571 _leave("");
46572 }
46573 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
46574 enum fscache_checkaux result;
46575
46576 if (!object->cookie->def->check_aux) {
46577 - fscache_stat(&fscache_n_checkaux_none);
46578 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46579 return FSCACHE_CHECKAUX_OKAY;
46580 }
46581
46582 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
46583 switch (result) {
46584 /* entry okay as is */
46585 case FSCACHE_CHECKAUX_OKAY:
46586 - fscache_stat(&fscache_n_checkaux_okay);
46587 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46588 break;
46589
46590 /* entry requires update */
46591 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46592 - fscache_stat(&fscache_n_checkaux_update);
46593 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46594 break;
46595
46596 /* entry requires deletion */
46597 case FSCACHE_CHECKAUX_OBSOLETE:
46598 - fscache_stat(&fscache_n_checkaux_obsolete);
46599 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46600 break;
46601
46602 default:
46603 diff -urNp linux-2.6.39.1/fs/fscache/operation.c linux-2.6.39.1/fs/fscache/operation.c
46604 --- linux-2.6.39.1/fs/fscache/operation.c 2011-05-19 00:06:34.000000000 -0400
46605 +++ linux-2.6.39.1/fs/fscache/operation.c 2011-05-22 19:36:32.000000000 -0400
46606 @@ -17,7 +17,7 @@
46607 #include <linux/slab.h>
46608 #include "internal.h"
46609
46610 -atomic_t fscache_op_debug_id;
46611 +atomic_unchecked_t fscache_op_debug_id;
46612 EXPORT_SYMBOL(fscache_op_debug_id);
46613
46614 /**
46615 @@ -40,7 +40,7 @@ void fscache_enqueue_operation(struct fs
46616 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46617 ASSERTCMP(atomic_read(&op->usage), >, 0);
46618
46619 - fscache_stat(&fscache_n_op_enqueue);
46620 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46621 switch (op->flags & FSCACHE_OP_TYPE) {
46622 case FSCACHE_OP_ASYNC:
46623 _debug("queue async");
46624 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscach
46625 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46626 if (op->processor)
46627 fscache_enqueue_operation(op);
46628 - fscache_stat(&fscache_n_op_run);
46629 + fscache_stat_unchecked(&fscache_n_op_run);
46630 }
46631
46632 /*
46633 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct f
46634 if (object->n_ops > 1) {
46635 atomic_inc(&op->usage);
46636 list_add_tail(&op->pend_link, &object->pending_ops);
46637 - fscache_stat(&fscache_n_op_pend);
46638 + fscache_stat_unchecked(&fscache_n_op_pend);
46639 } else if (!list_empty(&object->pending_ops)) {
46640 atomic_inc(&op->usage);
46641 list_add_tail(&op->pend_link, &object->pending_ops);
46642 - fscache_stat(&fscache_n_op_pend);
46643 + fscache_stat_unchecked(&fscache_n_op_pend);
46644 fscache_start_operations(object);
46645 } else {
46646 ASSERTCMP(object->n_in_progress, ==, 0);
46647 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct f
46648 object->n_exclusive++; /* reads and writes must wait */
46649 atomic_inc(&op->usage);
46650 list_add_tail(&op->pend_link, &object->pending_ops);
46651 - fscache_stat(&fscache_n_op_pend);
46652 + fscache_stat_unchecked(&fscache_n_op_pend);
46653 ret = 0;
46654 } else {
46655 /* not allowed to submit ops in any other state */
46656 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_obj
46657 if (object->n_exclusive > 0) {
46658 atomic_inc(&op->usage);
46659 list_add_tail(&op->pend_link, &object->pending_ops);
46660 - fscache_stat(&fscache_n_op_pend);
46661 + fscache_stat_unchecked(&fscache_n_op_pend);
46662 } else if (!list_empty(&object->pending_ops)) {
46663 atomic_inc(&op->usage);
46664 list_add_tail(&op->pend_link, &object->pending_ops);
46665 - fscache_stat(&fscache_n_op_pend);
46666 + fscache_stat_unchecked(&fscache_n_op_pend);
46667 fscache_start_operations(object);
46668 } else {
46669 ASSERTCMP(object->n_exclusive, ==, 0);
46670 @@ -227,12 +227,12 @@ int fscache_submit_op(struct fscache_obj
46671 object->n_ops++;
46672 atomic_inc(&op->usage);
46673 list_add_tail(&op->pend_link, &object->pending_ops);
46674 - fscache_stat(&fscache_n_op_pend);
46675 + fscache_stat_unchecked(&fscache_n_op_pend);
46676 ret = 0;
46677 } else if (object->state == FSCACHE_OBJECT_DYING ||
46678 object->state == FSCACHE_OBJECT_LC_DYING ||
46679 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46680 - fscache_stat(&fscache_n_op_rejected);
46681 + fscache_stat_unchecked(&fscache_n_op_rejected);
46682 ret = -ENOBUFS;
46683 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46684 fscache_report_unexpected_submission(object, op, ostate);
46685 @@ -302,7 +302,7 @@ int fscache_cancel_op(struct fscache_ope
46686
46687 ret = -EBUSY;
46688 if (!list_empty(&op->pend_link)) {
46689 - fscache_stat(&fscache_n_op_cancelled);
46690 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46691 list_del_init(&op->pend_link);
46692 object->n_ops--;
46693 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46694 @@ -341,7 +341,7 @@ void fscache_put_operation(struct fscach
46695 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46696 BUG();
46697
46698 - fscache_stat(&fscache_n_op_release);
46699 + fscache_stat_unchecked(&fscache_n_op_release);
46700
46701 if (op->release) {
46702 op->release(op);
46703 @@ -358,7 +358,7 @@ void fscache_put_operation(struct fscach
46704 * lock, and defer it otherwise */
46705 if (!spin_trylock(&object->lock)) {
46706 _debug("defer put");
46707 - fscache_stat(&fscache_n_op_deferred_release);
46708 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46709
46710 cache = object->cache;
46711 spin_lock(&cache->op_gc_list_lock);
46712 @@ -420,7 +420,7 @@ void fscache_operation_gc(struct work_st
46713
46714 _debug("GC DEFERRED REL OBJ%x OP%x",
46715 object->debug_id, op->debug_id);
46716 - fscache_stat(&fscache_n_op_gc);
46717 + fscache_stat_unchecked(&fscache_n_op_gc);
46718
46719 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46720
46721 diff -urNp linux-2.6.39.1/fs/fscache/page.c linux-2.6.39.1/fs/fscache/page.c
46722 --- linux-2.6.39.1/fs/fscache/page.c 2011-05-19 00:06:34.000000000 -0400
46723 +++ linux-2.6.39.1/fs/fscache/page.c 2011-05-22 19:36:32.000000000 -0400
46724 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct
46725 val = radix_tree_lookup(&cookie->stores, page->index);
46726 if (!val) {
46727 rcu_read_unlock();
46728 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46729 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46730 __fscache_uncache_page(cookie, page);
46731 return true;
46732 }
46733 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct
46734 spin_unlock(&cookie->stores_lock);
46735
46736 if (xpage) {
46737 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46738 - fscache_stat(&fscache_n_store_radix_deletes);
46739 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46740 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46741 ASSERTCMP(xpage, ==, page);
46742 } else {
46743 - fscache_stat(&fscache_n_store_vmscan_gone);
46744 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46745 }
46746
46747 wake_up_bit(&cookie->flags, 0);
46748 @@ -107,7 +107,7 @@ page_busy:
46749 /* we might want to wait here, but that could deadlock the allocator as
46750 * the work threads writing to the cache may all end up sleeping
46751 * on memory allocation */
46752 - fscache_stat(&fscache_n_store_vmscan_busy);
46753 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46754 return false;
46755 }
46756 EXPORT_SYMBOL(__fscache_maybe_release_page);
46757 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struc
46758 FSCACHE_COOKIE_STORING_TAG);
46759 if (!radix_tree_tag_get(&cookie->stores, page->index,
46760 FSCACHE_COOKIE_PENDING_TAG)) {
46761 - fscache_stat(&fscache_n_store_radix_deletes);
46762 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46763 xpage = radix_tree_delete(&cookie->stores, page->index);
46764 }
46765 spin_unlock(&cookie->stores_lock);
46766 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(stru
46767
46768 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46769
46770 - fscache_stat(&fscache_n_attr_changed_calls);
46771 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46772
46773 if (fscache_object_is_active(object)) {
46774 fscache_set_op_state(op, "CallFS");
46775 @@ -179,11 +179,11 @@ int __fscache_attr_changed(struct fscach
46776
46777 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46778
46779 - fscache_stat(&fscache_n_attr_changed);
46780 + fscache_stat_unchecked(&fscache_n_attr_changed);
46781
46782 op = kzalloc(sizeof(*op), GFP_KERNEL);
46783 if (!op) {
46784 - fscache_stat(&fscache_n_attr_changed_nomem);
46785 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46786 _leave(" = -ENOMEM");
46787 return -ENOMEM;
46788 }
46789 @@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
46790 if (fscache_submit_exclusive_op(object, op) < 0)
46791 goto nobufs;
46792 spin_unlock(&cookie->lock);
46793 - fscache_stat(&fscache_n_attr_changed_ok);
46794 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46795 fscache_put_operation(op);
46796 _leave(" = 0");
46797 return 0;
46798 @@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
46799 nobufs:
46800 spin_unlock(&cookie->lock);
46801 kfree(op);
46802 - fscache_stat(&fscache_n_attr_changed_nobufs);
46803 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46804 _leave(" = %d", -ENOBUFS);
46805 return -ENOBUFS;
46806 }
46807 @@ -246,7 +246,7 @@ static struct fscache_retrieval *fscache
46808 /* allocate a retrieval operation and attempt to submit it */
46809 op = kzalloc(sizeof(*op), GFP_NOIO);
46810 if (!op) {
46811 - fscache_stat(&fscache_n_retrievals_nomem);
46812 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46813 return NULL;
46814 }
46815
46816 @@ -275,13 +275,13 @@ static int fscache_wait_for_deferred_loo
46817 return 0;
46818 }
46819
46820 - fscache_stat(&fscache_n_retrievals_wait);
46821 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46822
46823 jif = jiffies;
46824 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46825 fscache_wait_bit_interruptible,
46826 TASK_INTERRUPTIBLE) != 0) {
46827 - fscache_stat(&fscache_n_retrievals_intr);
46828 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46829 _leave(" = -ERESTARTSYS");
46830 return -ERESTARTSYS;
46831 }
46832 @@ -299,8 +299,8 @@ static int fscache_wait_for_deferred_loo
46833 */
46834 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46835 struct fscache_retrieval *op,
46836 - atomic_t *stat_op_waits,
46837 - atomic_t *stat_object_dead)
46838 + atomic_unchecked_t *stat_op_waits,
46839 + atomic_unchecked_t *stat_object_dead)
46840 {
46841 int ret;
46842
46843 @@ -308,7 +308,7 @@ static int fscache_wait_for_retrieval_ac
46844 goto check_if_dead;
46845
46846 _debug(">>> WT");
46847 - fscache_stat(stat_op_waits);
46848 + fscache_stat_unchecked(stat_op_waits);
46849 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46850 fscache_wait_bit_interruptible,
46851 TASK_INTERRUPTIBLE) < 0) {
46852 @@ -325,7 +325,7 @@ static int fscache_wait_for_retrieval_ac
46853
46854 check_if_dead:
46855 if (unlikely(fscache_object_is_dead(object))) {
46856 - fscache_stat(stat_object_dead);
46857 + fscache_stat_unchecked(stat_object_dead);
46858 return -ENOBUFS;
46859 }
46860 return 0;
46861 @@ -352,7 +352,7 @@ int __fscache_read_or_alloc_page(struct
46862
46863 _enter("%p,%p,,,", cookie, page);
46864
46865 - fscache_stat(&fscache_n_retrievals);
46866 + fscache_stat_unchecked(&fscache_n_retrievals);
46867
46868 if (hlist_empty(&cookie->backing_objects))
46869 goto nobufs;
46870 @@ -386,7 +386,7 @@ int __fscache_read_or_alloc_page(struct
46871 goto nobufs_unlock;
46872 spin_unlock(&cookie->lock);
46873
46874 - fscache_stat(&fscache_n_retrieval_ops);
46875 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46876
46877 /* pin the netfs read context in case we need to do the actual netfs
46878 * read because we've encountered a cache read failure */
46879 @@ -416,15 +416,15 @@ int __fscache_read_or_alloc_page(struct
46880
46881 error:
46882 if (ret == -ENOMEM)
46883 - fscache_stat(&fscache_n_retrievals_nomem);
46884 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46885 else if (ret == -ERESTARTSYS)
46886 - fscache_stat(&fscache_n_retrievals_intr);
46887 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46888 else if (ret == -ENODATA)
46889 - fscache_stat(&fscache_n_retrievals_nodata);
46890 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46891 else if (ret < 0)
46892 - fscache_stat(&fscache_n_retrievals_nobufs);
46893 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46894 else
46895 - fscache_stat(&fscache_n_retrievals_ok);
46896 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46897
46898 fscache_put_retrieval(op);
46899 _leave(" = %d", ret);
46900 @@ -434,7 +434,7 @@ nobufs_unlock:
46901 spin_unlock(&cookie->lock);
46902 kfree(op);
46903 nobufs:
46904 - fscache_stat(&fscache_n_retrievals_nobufs);
46905 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46906 _leave(" = -ENOBUFS");
46907 return -ENOBUFS;
46908 }
46909 @@ -472,7 +472,7 @@ int __fscache_read_or_alloc_pages(struct
46910
46911 _enter("%p,,%d,,,", cookie, *nr_pages);
46912
46913 - fscache_stat(&fscache_n_retrievals);
46914 + fscache_stat_unchecked(&fscache_n_retrievals);
46915
46916 if (hlist_empty(&cookie->backing_objects))
46917 goto nobufs;
46918 @@ -503,7 +503,7 @@ int __fscache_read_or_alloc_pages(struct
46919 goto nobufs_unlock;
46920 spin_unlock(&cookie->lock);
46921
46922 - fscache_stat(&fscache_n_retrieval_ops);
46923 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46924
46925 /* pin the netfs read context in case we need to do the actual netfs
46926 * read because we've encountered a cache read failure */
46927 @@ -533,15 +533,15 @@ int __fscache_read_or_alloc_pages(struct
46928
46929 error:
46930 if (ret == -ENOMEM)
46931 - fscache_stat(&fscache_n_retrievals_nomem);
46932 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46933 else if (ret == -ERESTARTSYS)
46934 - fscache_stat(&fscache_n_retrievals_intr);
46935 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46936 else if (ret == -ENODATA)
46937 - fscache_stat(&fscache_n_retrievals_nodata);
46938 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46939 else if (ret < 0)
46940 - fscache_stat(&fscache_n_retrievals_nobufs);
46941 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46942 else
46943 - fscache_stat(&fscache_n_retrievals_ok);
46944 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46945
46946 fscache_put_retrieval(op);
46947 _leave(" = %d", ret);
46948 @@ -551,7 +551,7 @@ nobufs_unlock:
46949 spin_unlock(&cookie->lock);
46950 kfree(op);
46951 nobufs:
46952 - fscache_stat(&fscache_n_retrievals_nobufs);
46953 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46954 _leave(" = -ENOBUFS");
46955 return -ENOBUFS;
46956 }
46957 @@ -575,7 +575,7 @@ int __fscache_alloc_page(struct fscache_
46958
46959 _enter("%p,%p,,,", cookie, page);
46960
46961 - fscache_stat(&fscache_n_allocs);
46962 + fscache_stat_unchecked(&fscache_n_allocs);
46963
46964 if (hlist_empty(&cookie->backing_objects))
46965 goto nobufs;
46966 @@ -602,7 +602,7 @@ int __fscache_alloc_page(struct fscache_
46967 goto nobufs_unlock;
46968 spin_unlock(&cookie->lock);
46969
46970 - fscache_stat(&fscache_n_alloc_ops);
46971 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46972
46973 ret = fscache_wait_for_retrieval_activation(
46974 object, op,
46975 @@ -618,11 +618,11 @@ int __fscache_alloc_page(struct fscache_
46976
46977 error:
46978 if (ret == -ERESTARTSYS)
46979 - fscache_stat(&fscache_n_allocs_intr);
46980 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46981 else if (ret < 0)
46982 - fscache_stat(&fscache_n_allocs_nobufs);
46983 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46984 else
46985 - fscache_stat(&fscache_n_allocs_ok);
46986 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46987
46988 fscache_put_retrieval(op);
46989 _leave(" = %d", ret);
46990 @@ -632,7 +632,7 @@ nobufs_unlock:
46991 spin_unlock(&cookie->lock);
46992 kfree(op);
46993 nobufs:
46994 - fscache_stat(&fscache_n_allocs_nobufs);
46995 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46996 _leave(" = -ENOBUFS");
46997 return -ENOBUFS;
46998 }
46999 @@ -675,7 +675,7 @@ static void fscache_write_op(struct fsca
47000
47001 spin_lock(&cookie->stores_lock);
47002
47003 - fscache_stat(&fscache_n_store_calls);
47004 + fscache_stat_unchecked(&fscache_n_store_calls);
47005
47006 /* find a page to store */
47007 page = NULL;
47008 @@ -686,7 +686,7 @@ static void fscache_write_op(struct fsca
47009 page = results[0];
47010 _debug("gang %d [%lx]", n, page->index);
47011 if (page->index > op->store_limit) {
47012 - fscache_stat(&fscache_n_store_pages_over_limit);
47013 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47014 goto superseded;
47015 }
47016
47017 @@ -699,7 +699,7 @@ static void fscache_write_op(struct fsca
47018 spin_unlock(&object->lock);
47019
47020 fscache_set_op_state(&op->op, "Store");
47021 - fscache_stat(&fscache_n_store_pages);
47022 + fscache_stat_unchecked(&fscache_n_store_pages);
47023 fscache_stat(&fscache_n_cop_write_page);
47024 ret = object->cache->ops->write_page(op, page);
47025 fscache_stat_d(&fscache_n_cop_write_page);
47026 @@ -769,7 +769,7 @@ int __fscache_write_page(struct fscache_
47027 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47028 ASSERT(PageFsCache(page));
47029
47030 - fscache_stat(&fscache_n_stores);
47031 + fscache_stat_unchecked(&fscache_n_stores);
47032
47033 op = kzalloc(sizeof(*op), GFP_NOIO);
47034 if (!op)
47035 @@ -821,7 +821,7 @@ int __fscache_write_page(struct fscache_
47036 spin_unlock(&cookie->stores_lock);
47037 spin_unlock(&object->lock);
47038
47039 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47040 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47041 op->store_limit = object->store_limit;
47042
47043 if (fscache_submit_op(object, &op->op) < 0)
47044 @@ -829,8 +829,8 @@ int __fscache_write_page(struct fscache_
47045
47046 spin_unlock(&cookie->lock);
47047 radix_tree_preload_end();
47048 - fscache_stat(&fscache_n_store_ops);
47049 - fscache_stat(&fscache_n_stores_ok);
47050 + fscache_stat_unchecked(&fscache_n_store_ops);
47051 + fscache_stat_unchecked(&fscache_n_stores_ok);
47052
47053 /* the work queue now carries its own ref on the object */
47054 fscache_put_operation(&op->op);
47055 @@ -838,14 +838,14 @@ int __fscache_write_page(struct fscache_
47056 return 0;
47057
47058 already_queued:
47059 - fscache_stat(&fscache_n_stores_again);
47060 + fscache_stat_unchecked(&fscache_n_stores_again);
47061 already_pending:
47062 spin_unlock(&cookie->stores_lock);
47063 spin_unlock(&object->lock);
47064 spin_unlock(&cookie->lock);
47065 radix_tree_preload_end();
47066 kfree(op);
47067 - fscache_stat(&fscache_n_stores_ok);
47068 + fscache_stat_unchecked(&fscache_n_stores_ok);
47069 _leave(" = 0");
47070 return 0;
47071
47072 @@ -864,14 +864,14 @@ nobufs:
47073 spin_unlock(&cookie->lock);
47074 radix_tree_preload_end();
47075 kfree(op);
47076 - fscache_stat(&fscache_n_stores_nobufs);
47077 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47078 _leave(" = -ENOBUFS");
47079 return -ENOBUFS;
47080
47081 nomem_free:
47082 kfree(op);
47083 nomem:
47084 - fscache_stat(&fscache_n_stores_oom);
47085 + fscache_stat_unchecked(&fscache_n_stores_oom);
47086 _leave(" = -ENOMEM");
47087 return -ENOMEM;
47088 }
47089 @@ -889,7 +889,7 @@ void __fscache_uncache_page(struct fscac
47090 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47091 ASSERTCMP(page, !=, NULL);
47092
47093 - fscache_stat(&fscache_n_uncaches);
47094 + fscache_stat_unchecked(&fscache_n_uncaches);
47095
47096 /* cache withdrawal may beat us to it */
47097 if (!PageFsCache(page))
47098 @@ -942,7 +942,7 @@ void fscache_mark_pages_cached(struct fs
47099 unsigned long loop;
47100
47101 #ifdef CONFIG_FSCACHE_STATS
47102 - atomic_add(pagevec->nr, &fscache_n_marks);
47103 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47104 #endif
47105
47106 for (loop = 0; loop < pagevec->nr; loop++) {
47107 diff -urNp linux-2.6.39.1/fs/fscache/stats.c linux-2.6.39.1/fs/fscache/stats.c
47108 --- linux-2.6.39.1/fs/fscache/stats.c 2011-05-19 00:06:34.000000000 -0400
47109 +++ linux-2.6.39.1/fs/fscache/stats.c 2011-05-22 19:36:32.000000000 -0400
47110 @@ -18,95 +18,95 @@
47111 /*
47112 * operation counters
47113 */
47114 -atomic_t fscache_n_op_pend;
47115 -atomic_t fscache_n_op_run;
47116 -atomic_t fscache_n_op_enqueue;
47117 -atomic_t fscache_n_op_requeue;
47118 -atomic_t fscache_n_op_deferred_release;
47119 -atomic_t fscache_n_op_release;
47120 -atomic_t fscache_n_op_gc;
47121 -atomic_t fscache_n_op_cancelled;
47122 -atomic_t fscache_n_op_rejected;
47123 -
47124 -atomic_t fscache_n_attr_changed;
47125 -atomic_t fscache_n_attr_changed_ok;
47126 -atomic_t fscache_n_attr_changed_nobufs;
47127 -atomic_t fscache_n_attr_changed_nomem;
47128 -atomic_t fscache_n_attr_changed_calls;
47129 -
47130 -atomic_t fscache_n_allocs;
47131 -atomic_t fscache_n_allocs_ok;
47132 -atomic_t fscache_n_allocs_wait;
47133 -atomic_t fscache_n_allocs_nobufs;
47134 -atomic_t fscache_n_allocs_intr;
47135 -atomic_t fscache_n_allocs_object_dead;
47136 -atomic_t fscache_n_alloc_ops;
47137 -atomic_t fscache_n_alloc_op_waits;
47138 -
47139 -atomic_t fscache_n_retrievals;
47140 -atomic_t fscache_n_retrievals_ok;
47141 -atomic_t fscache_n_retrievals_wait;
47142 -atomic_t fscache_n_retrievals_nodata;
47143 -atomic_t fscache_n_retrievals_nobufs;
47144 -atomic_t fscache_n_retrievals_intr;
47145 -atomic_t fscache_n_retrievals_nomem;
47146 -atomic_t fscache_n_retrievals_object_dead;
47147 -atomic_t fscache_n_retrieval_ops;
47148 -atomic_t fscache_n_retrieval_op_waits;
47149 -
47150 -atomic_t fscache_n_stores;
47151 -atomic_t fscache_n_stores_ok;
47152 -atomic_t fscache_n_stores_again;
47153 -atomic_t fscache_n_stores_nobufs;
47154 -atomic_t fscache_n_stores_oom;
47155 -atomic_t fscache_n_store_ops;
47156 -atomic_t fscache_n_store_calls;
47157 -atomic_t fscache_n_store_pages;
47158 -atomic_t fscache_n_store_radix_deletes;
47159 -atomic_t fscache_n_store_pages_over_limit;
47160 -
47161 -atomic_t fscache_n_store_vmscan_not_storing;
47162 -atomic_t fscache_n_store_vmscan_gone;
47163 -atomic_t fscache_n_store_vmscan_busy;
47164 -atomic_t fscache_n_store_vmscan_cancelled;
47165 -
47166 -atomic_t fscache_n_marks;
47167 -atomic_t fscache_n_uncaches;
47168 -
47169 -atomic_t fscache_n_acquires;
47170 -atomic_t fscache_n_acquires_null;
47171 -atomic_t fscache_n_acquires_no_cache;
47172 -atomic_t fscache_n_acquires_ok;
47173 -atomic_t fscache_n_acquires_nobufs;
47174 -atomic_t fscache_n_acquires_oom;
47175 -
47176 -atomic_t fscache_n_updates;
47177 -atomic_t fscache_n_updates_null;
47178 -atomic_t fscache_n_updates_run;
47179 -
47180 -atomic_t fscache_n_relinquishes;
47181 -atomic_t fscache_n_relinquishes_null;
47182 -atomic_t fscache_n_relinquishes_waitcrt;
47183 -atomic_t fscache_n_relinquishes_retire;
47184 -
47185 -atomic_t fscache_n_cookie_index;
47186 -atomic_t fscache_n_cookie_data;
47187 -atomic_t fscache_n_cookie_special;
47188 -
47189 -atomic_t fscache_n_object_alloc;
47190 -atomic_t fscache_n_object_no_alloc;
47191 -atomic_t fscache_n_object_lookups;
47192 -atomic_t fscache_n_object_lookups_negative;
47193 -atomic_t fscache_n_object_lookups_positive;
47194 -atomic_t fscache_n_object_lookups_timed_out;
47195 -atomic_t fscache_n_object_created;
47196 -atomic_t fscache_n_object_avail;
47197 -atomic_t fscache_n_object_dead;
47198 -
47199 -atomic_t fscache_n_checkaux_none;
47200 -atomic_t fscache_n_checkaux_okay;
47201 -atomic_t fscache_n_checkaux_update;
47202 -atomic_t fscache_n_checkaux_obsolete;
47203 +atomic_unchecked_t fscache_n_op_pend;
47204 +atomic_unchecked_t fscache_n_op_run;
47205 +atomic_unchecked_t fscache_n_op_enqueue;
47206 +atomic_unchecked_t fscache_n_op_requeue;
47207 +atomic_unchecked_t fscache_n_op_deferred_release;
47208 +atomic_unchecked_t fscache_n_op_release;
47209 +atomic_unchecked_t fscache_n_op_gc;
47210 +atomic_unchecked_t fscache_n_op_cancelled;
47211 +atomic_unchecked_t fscache_n_op_rejected;
47212 +
47213 +atomic_unchecked_t fscache_n_attr_changed;
47214 +atomic_unchecked_t fscache_n_attr_changed_ok;
47215 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47216 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47217 +atomic_unchecked_t fscache_n_attr_changed_calls;
47218 +
47219 +atomic_unchecked_t fscache_n_allocs;
47220 +atomic_unchecked_t fscache_n_allocs_ok;
47221 +atomic_unchecked_t fscache_n_allocs_wait;
47222 +atomic_unchecked_t fscache_n_allocs_nobufs;
47223 +atomic_unchecked_t fscache_n_allocs_intr;
47224 +atomic_unchecked_t fscache_n_allocs_object_dead;
47225 +atomic_unchecked_t fscache_n_alloc_ops;
47226 +atomic_unchecked_t fscache_n_alloc_op_waits;
47227 +
47228 +atomic_unchecked_t fscache_n_retrievals;
47229 +atomic_unchecked_t fscache_n_retrievals_ok;
47230 +atomic_unchecked_t fscache_n_retrievals_wait;
47231 +atomic_unchecked_t fscache_n_retrievals_nodata;
47232 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47233 +atomic_unchecked_t fscache_n_retrievals_intr;
47234 +atomic_unchecked_t fscache_n_retrievals_nomem;
47235 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47236 +atomic_unchecked_t fscache_n_retrieval_ops;
47237 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47238 +
47239 +atomic_unchecked_t fscache_n_stores;
47240 +atomic_unchecked_t fscache_n_stores_ok;
47241 +atomic_unchecked_t fscache_n_stores_again;
47242 +atomic_unchecked_t fscache_n_stores_nobufs;
47243 +atomic_unchecked_t fscache_n_stores_oom;
47244 +atomic_unchecked_t fscache_n_store_ops;
47245 +atomic_unchecked_t fscache_n_store_calls;
47246 +atomic_unchecked_t fscache_n_store_pages;
47247 +atomic_unchecked_t fscache_n_store_radix_deletes;
47248 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47249 +
47250 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47251 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47252 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47253 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47254 +
47255 +atomic_unchecked_t fscache_n_marks;
47256 +atomic_unchecked_t fscache_n_uncaches;
47257 +
47258 +atomic_unchecked_t fscache_n_acquires;
47259 +atomic_unchecked_t fscache_n_acquires_null;
47260 +atomic_unchecked_t fscache_n_acquires_no_cache;
47261 +atomic_unchecked_t fscache_n_acquires_ok;
47262 +atomic_unchecked_t fscache_n_acquires_nobufs;
47263 +atomic_unchecked_t fscache_n_acquires_oom;
47264 +
47265 +atomic_unchecked_t fscache_n_updates;
47266 +atomic_unchecked_t fscache_n_updates_null;
47267 +atomic_unchecked_t fscache_n_updates_run;
47268 +
47269 +atomic_unchecked_t fscache_n_relinquishes;
47270 +atomic_unchecked_t fscache_n_relinquishes_null;
47271 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47272 +atomic_unchecked_t fscache_n_relinquishes_retire;
47273 +
47274 +atomic_unchecked_t fscache_n_cookie_index;
47275 +atomic_unchecked_t fscache_n_cookie_data;
47276 +atomic_unchecked_t fscache_n_cookie_special;
47277 +
47278 +atomic_unchecked_t fscache_n_object_alloc;
47279 +atomic_unchecked_t fscache_n_object_no_alloc;
47280 +atomic_unchecked_t fscache_n_object_lookups;
47281 +atomic_unchecked_t fscache_n_object_lookups_negative;
47282 +atomic_unchecked_t fscache_n_object_lookups_positive;
47283 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47284 +atomic_unchecked_t fscache_n_object_created;
47285 +atomic_unchecked_t fscache_n_object_avail;
47286 +atomic_unchecked_t fscache_n_object_dead;
47287 +
47288 +atomic_unchecked_t fscache_n_checkaux_none;
47289 +atomic_unchecked_t fscache_n_checkaux_okay;
47290 +atomic_unchecked_t fscache_n_checkaux_update;
47291 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47292
47293 atomic_t fscache_n_cop_alloc_object;
47294 atomic_t fscache_n_cop_lookup_object;
47295 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
47296 seq_puts(m, "FS-Cache statistics\n");
47297
47298 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47299 - atomic_read(&fscache_n_cookie_index),
47300 - atomic_read(&fscache_n_cookie_data),
47301 - atomic_read(&fscache_n_cookie_special));
47302 + atomic_read_unchecked(&fscache_n_cookie_index),
47303 + atomic_read_unchecked(&fscache_n_cookie_data),
47304 + atomic_read_unchecked(&fscache_n_cookie_special));
47305
47306 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47307 - atomic_read(&fscache_n_object_alloc),
47308 - atomic_read(&fscache_n_object_no_alloc),
47309 - atomic_read(&fscache_n_object_avail),
47310 - atomic_read(&fscache_n_object_dead));
47311 + atomic_read_unchecked(&fscache_n_object_alloc),
47312 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47313 + atomic_read_unchecked(&fscache_n_object_avail),
47314 + atomic_read_unchecked(&fscache_n_object_dead));
47315 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47316 - atomic_read(&fscache_n_checkaux_none),
47317 - atomic_read(&fscache_n_checkaux_okay),
47318 - atomic_read(&fscache_n_checkaux_update),
47319 - atomic_read(&fscache_n_checkaux_obsolete));
47320 + atomic_read_unchecked(&fscache_n_checkaux_none),
47321 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47322 + atomic_read_unchecked(&fscache_n_checkaux_update),
47323 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47324
47325 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47326 - atomic_read(&fscache_n_marks),
47327 - atomic_read(&fscache_n_uncaches));
47328 + atomic_read_unchecked(&fscache_n_marks),
47329 + atomic_read_unchecked(&fscache_n_uncaches));
47330
47331 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47332 " oom=%u\n",
47333 - atomic_read(&fscache_n_acquires),
47334 - atomic_read(&fscache_n_acquires_null),
47335 - atomic_read(&fscache_n_acquires_no_cache),
47336 - atomic_read(&fscache_n_acquires_ok),
47337 - atomic_read(&fscache_n_acquires_nobufs),
47338 - atomic_read(&fscache_n_acquires_oom));
47339 + atomic_read_unchecked(&fscache_n_acquires),
47340 + atomic_read_unchecked(&fscache_n_acquires_null),
47341 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47342 + atomic_read_unchecked(&fscache_n_acquires_ok),
47343 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47344 + atomic_read_unchecked(&fscache_n_acquires_oom));
47345
47346 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47347 - atomic_read(&fscache_n_object_lookups),
47348 - atomic_read(&fscache_n_object_lookups_negative),
47349 - atomic_read(&fscache_n_object_lookups_positive),
47350 - atomic_read(&fscache_n_object_created),
47351 - atomic_read(&fscache_n_object_lookups_timed_out));
47352 + atomic_read_unchecked(&fscache_n_object_lookups),
47353 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47354 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47355 + atomic_read_unchecked(&fscache_n_object_created),
47356 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47357
47358 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47359 - atomic_read(&fscache_n_updates),
47360 - atomic_read(&fscache_n_updates_null),
47361 - atomic_read(&fscache_n_updates_run));
47362 + atomic_read_unchecked(&fscache_n_updates),
47363 + atomic_read_unchecked(&fscache_n_updates_null),
47364 + atomic_read_unchecked(&fscache_n_updates_run));
47365
47366 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47367 - atomic_read(&fscache_n_relinquishes),
47368 - atomic_read(&fscache_n_relinquishes_null),
47369 - atomic_read(&fscache_n_relinquishes_waitcrt),
47370 - atomic_read(&fscache_n_relinquishes_retire));
47371 + atomic_read_unchecked(&fscache_n_relinquishes),
47372 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47373 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47374 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47375
47376 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47377 - atomic_read(&fscache_n_attr_changed),
47378 - atomic_read(&fscache_n_attr_changed_ok),
47379 - atomic_read(&fscache_n_attr_changed_nobufs),
47380 - atomic_read(&fscache_n_attr_changed_nomem),
47381 - atomic_read(&fscache_n_attr_changed_calls));
47382 + atomic_read_unchecked(&fscache_n_attr_changed),
47383 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47384 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47385 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47386 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47387
47388 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47389 - atomic_read(&fscache_n_allocs),
47390 - atomic_read(&fscache_n_allocs_ok),
47391 - atomic_read(&fscache_n_allocs_wait),
47392 - atomic_read(&fscache_n_allocs_nobufs),
47393 - atomic_read(&fscache_n_allocs_intr));
47394 + atomic_read_unchecked(&fscache_n_allocs),
47395 + atomic_read_unchecked(&fscache_n_allocs_ok),
47396 + atomic_read_unchecked(&fscache_n_allocs_wait),
47397 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47398 + atomic_read_unchecked(&fscache_n_allocs_intr));
47399 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47400 - atomic_read(&fscache_n_alloc_ops),
47401 - atomic_read(&fscache_n_alloc_op_waits),
47402 - atomic_read(&fscache_n_allocs_object_dead));
47403 + atomic_read_unchecked(&fscache_n_alloc_ops),
47404 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47405 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47406
47407 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47408 " int=%u oom=%u\n",
47409 - atomic_read(&fscache_n_retrievals),
47410 - atomic_read(&fscache_n_retrievals_ok),
47411 - atomic_read(&fscache_n_retrievals_wait),
47412 - atomic_read(&fscache_n_retrievals_nodata),
47413 - atomic_read(&fscache_n_retrievals_nobufs),
47414 - atomic_read(&fscache_n_retrievals_intr),
47415 - atomic_read(&fscache_n_retrievals_nomem));
47416 + atomic_read_unchecked(&fscache_n_retrievals),
47417 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47418 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47419 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47420 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47421 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47422 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47423 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47424 - atomic_read(&fscache_n_retrieval_ops),
47425 - atomic_read(&fscache_n_retrieval_op_waits),
47426 - atomic_read(&fscache_n_retrievals_object_dead));
47427 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47428 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47429 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47430
47431 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47432 - atomic_read(&fscache_n_stores),
47433 - atomic_read(&fscache_n_stores_ok),
47434 - atomic_read(&fscache_n_stores_again),
47435 - atomic_read(&fscache_n_stores_nobufs),
47436 - atomic_read(&fscache_n_stores_oom));
47437 + atomic_read_unchecked(&fscache_n_stores),
47438 + atomic_read_unchecked(&fscache_n_stores_ok),
47439 + atomic_read_unchecked(&fscache_n_stores_again),
47440 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47441 + atomic_read_unchecked(&fscache_n_stores_oom));
47442 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47443 - atomic_read(&fscache_n_store_ops),
47444 - atomic_read(&fscache_n_store_calls),
47445 - atomic_read(&fscache_n_store_pages),
47446 - atomic_read(&fscache_n_store_radix_deletes),
47447 - atomic_read(&fscache_n_store_pages_over_limit));
47448 + atomic_read_unchecked(&fscache_n_store_ops),
47449 + atomic_read_unchecked(&fscache_n_store_calls),
47450 + atomic_read_unchecked(&fscache_n_store_pages),
47451 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47452 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47453
47454 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47455 - atomic_read(&fscache_n_store_vmscan_not_storing),
47456 - atomic_read(&fscache_n_store_vmscan_gone),
47457 - atomic_read(&fscache_n_store_vmscan_busy),
47458 - atomic_read(&fscache_n_store_vmscan_cancelled));
47459 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47460 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47461 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47462 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47463
47464 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47465 - atomic_read(&fscache_n_op_pend),
47466 - atomic_read(&fscache_n_op_run),
47467 - atomic_read(&fscache_n_op_enqueue),
47468 - atomic_read(&fscache_n_op_cancelled),
47469 - atomic_read(&fscache_n_op_rejected));
47470 + atomic_read_unchecked(&fscache_n_op_pend),
47471 + atomic_read_unchecked(&fscache_n_op_run),
47472 + atomic_read_unchecked(&fscache_n_op_enqueue),
47473 + atomic_read_unchecked(&fscache_n_op_cancelled),
47474 + atomic_read_unchecked(&fscache_n_op_rejected));
47475 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47476 - atomic_read(&fscache_n_op_deferred_release),
47477 - atomic_read(&fscache_n_op_release),
47478 - atomic_read(&fscache_n_op_gc));
47479 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47480 + atomic_read_unchecked(&fscache_n_op_release),
47481 + atomic_read_unchecked(&fscache_n_op_gc));
47482
47483 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47484 atomic_read(&fscache_n_cop_alloc_object),
47485 diff -urNp linux-2.6.39.1/fs/fs_struct.c linux-2.6.39.1/fs/fs_struct.c
47486 --- linux-2.6.39.1/fs/fs_struct.c 2011-05-19 00:06:34.000000000 -0400
47487 +++ linux-2.6.39.1/fs/fs_struct.c 2011-05-22 19:41:37.000000000 -0400
47488 @@ -4,6 +4,7 @@
47489 #include <linux/path.h>
47490 #include <linux/slab.h>
47491 #include <linux/fs_struct.h>
47492 +#include <linux/grsecurity.h>
47493 #include "internal.h"
47494
47495 static inline void path_get_longterm(struct path *path)
47496 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, s
47497 old_root = fs->root;
47498 fs->root = *path;
47499 path_get_longterm(path);
47500 + gr_set_chroot_entries(current, path);
47501 write_seqcount_end(&fs->seq);
47502 spin_unlock(&fs->lock);
47503 if (old_root.dentry)
47504 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_roo
47505 && fs->root.mnt == old_root->mnt) {
47506 path_get_longterm(new_root);
47507 fs->root = *new_root;
47508 + gr_set_chroot_entries(p, new_root);
47509 count++;
47510 }
47511 if (fs->pwd.dentry == old_root->dentry
47512 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
47513 spin_lock(&fs->lock);
47514 write_seqcount_begin(&fs->seq);
47515 tsk->fs = NULL;
47516 - kill = !--fs->users;
47517 + gr_clear_chroot_entries(tsk);
47518 + kill = !atomic_dec_return(&fs->users);
47519 write_seqcount_end(&fs->seq);
47520 spin_unlock(&fs->lock);
47521 task_unlock(tsk);
47522 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct
47523 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47524 /* We don't need to lock fs - think why ;-) */
47525 if (fs) {
47526 - fs->users = 1;
47527 + atomic_set(&fs->users, 1);
47528 fs->in_exec = 0;
47529 spin_lock_init(&fs->lock);
47530 seqcount_init(&fs->seq);
47531 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct
47532 spin_lock(&old->lock);
47533 fs->root = old->root;
47534 path_get_longterm(&fs->root);
47535 + /* instead of calling gr_set_chroot_entries here,
47536 + we call it from every caller of this function
47537 + */
47538 fs->pwd = old->pwd;
47539 path_get_longterm(&fs->pwd);
47540 spin_unlock(&old->lock);
47541 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
47542
47543 task_lock(current);
47544 spin_lock(&fs->lock);
47545 - kill = !--fs->users;
47546 + kill = !atomic_dec_return(&fs->users);
47547 current->fs = new_fs;
47548 + gr_set_chroot_entries(current, &new_fs->root);
47549 spin_unlock(&fs->lock);
47550 task_unlock(current);
47551
47552 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
47553
47554 /* to be mentioned only in INIT_TASK */
47555 struct fs_struct init_fs = {
47556 - .users = 1,
47557 + .users = ATOMIC_INIT(1),
47558 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47559 .seq = SEQCNT_ZERO,
47560 .umask = 0022,
47561 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
47562 task_lock(current);
47563
47564 spin_lock(&init_fs.lock);
47565 - init_fs.users++;
47566 + atomic_inc(&init_fs.users);
47567 spin_unlock(&init_fs.lock);
47568
47569 spin_lock(&fs->lock);
47570 current->fs = &init_fs;
47571 - kill = !--fs->users;
47572 + gr_set_chroot_entries(current, &current->fs->root);
47573 + kill = !atomic_dec_return(&fs->users);
47574 spin_unlock(&fs->lock);
47575
47576 task_unlock(current);
47577 diff -urNp linux-2.6.39.1/fs/fuse/cuse.c linux-2.6.39.1/fs/fuse/cuse.c
47578 --- linux-2.6.39.1/fs/fuse/cuse.c 2011-05-19 00:06:34.000000000 -0400
47579 +++ linux-2.6.39.1/fs/fuse/cuse.c 2011-05-22 19:36:32.000000000 -0400
47580 @@ -538,8 +538,18 @@ static int cuse_channel_release(struct i
47581 return rc;
47582 }
47583
47584 -static struct file_operations cuse_channel_fops; /* initialized during init */
47585 -
47586 +static const struct file_operations cuse_channel_fops = { /* initialized during init */
47587 + .owner = THIS_MODULE,
47588 + .llseek = no_llseek,
47589 + .read = do_sync_read,
47590 + .aio_read = fuse_dev_read,
47591 + .write = do_sync_write,
47592 + .aio_write = fuse_dev_write,
47593 + .poll = fuse_dev_poll,
47594 + .open = cuse_channel_open,
47595 + .release = cuse_channel_release,
47596 + .fasync = fuse_dev_fasync,
47597 +};
47598
47599 /**************************************************************************
47600 * Misc stuff and module initializatiion
47601 @@ -585,12 +595,6 @@ static int __init cuse_init(void)
47602 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
47603 INIT_LIST_HEAD(&cuse_conntbl[i]);
47604
47605 - /* inherit and extend fuse_dev_operations */
47606 - cuse_channel_fops = fuse_dev_operations;
47607 - cuse_channel_fops.owner = THIS_MODULE;
47608 - cuse_channel_fops.open = cuse_channel_open;
47609 - cuse_channel_fops.release = cuse_channel_release;
47610 -
47611 cuse_class = class_create(THIS_MODULE, "cuse");
47612 if (IS_ERR(cuse_class))
47613 return PTR_ERR(cuse_class);
47614 diff -urNp linux-2.6.39.1/fs/fuse/dev.c linux-2.6.39.1/fs/fuse/dev.c
47615 --- linux-2.6.39.1/fs/fuse/dev.c 2011-05-19 00:06:34.000000000 -0400
47616 +++ linux-2.6.39.1/fs/fuse/dev.c 2011-05-22 19:36:32.000000000 -0400
47617 @@ -1181,7 +1181,7 @@ static ssize_t fuse_dev_do_read(struct f
47618 return err;
47619 }
47620
47621 -static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47622 +ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47623 unsigned long nr_segs, loff_t pos)
47624 {
47625 struct fuse_copy_state cs;
47626 @@ -1195,6 +1195,8 @@ static ssize_t fuse_dev_read(struct kioc
47627 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
47628 }
47629
47630 +EXPORT_SYMBOL_GPL(fuse_dev_read);
47631 +
47632 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
47633 struct pipe_buffer *buf)
47634 {
47635 @@ -1238,7 +1240,7 @@ static ssize_t fuse_dev_splice_read(stru
47636 ret = 0;
47637 pipe_lock(pipe);
47638
47639 - if (!pipe->readers) {
47640 + if (!atomic_read(&pipe->readers)) {
47641 send_sig(SIGPIPE, current, 0);
47642 if (!ret)
47643 ret = -EPIPE;
47644 @@ -1731,7 +1733,7 @@ static ssize_t fuse_dev_do_write(struct
47645 return err;
47646 }
47647
47648 -static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47649 +ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47650 unsigned long nr_segs, loff_t pos)
47651 {
47652 struct fuse_copy_state cs;
47653 @@ -1744,6 +1746,8 @@ static ssize_t fuse_dev_write(struct kio
47654 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
47655 }
47656
47657 +EXPORT_SYMBOL_GPL(fuse_dev_write);
47658 +
47659 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
47660 struct file *out, loff_t *ppos,
47661 size_t len, unsigned int flags)
47662 @@ -1822,7 +1826,7 @@ out:
47663 return ret;
47664 }
47665
47666 -static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47667 +unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47668 {
47669 unsigned mask = POLLOUT | POLLWRNORM;
47670 struct fuse_conn *fc = fuse_get_conn(file);
47671 @@ -1841,6 +1845,8 @@ static unsigned fuse_dev_poll(struct fil
47672 return mask;
47673 }
47674
47675 +EXPORT_SYMBOL_GPL(fuse_dev_poll);
47676 +
47677 /*
47678 * Abort all requests on the given list (pending or processing)
47679 *
47680 @@ -1977,7 +1983,7 @@ int fuse_dev_release(struct inode *inode
47681 }
47682 EXPORT_SYMBOL_GPL(fuse_dev_release);
47683
47684 -static int fuse_dev_fasync(int fd, struct file *file, int on)
47685 +int fuse_dev_fasync(int fd, struct file *file, int on)
47686 {
47687 struct fuse_conn *fc = fuse_get_conn(file);
47688 if (!fc)
47689 @@ -1987,6 +1993,8 @@ static int fuse_dev_fasync(int fd, struc
47690 return fasync_helper(fd, file, on, &fc->fasync);
47691 }
47692
47693 +EXPORT_SYMBOL_GPL(fuse_dev_fasync);
47694 +
47695 const struct file_operations fuse_dev_operations = {
47696 .owner = THIS_MODULE,
47697 .llseek = no_llseek,
47698 diff -urNp linux-2.6.39.1/fs/fuse/dir.c linux-2.6.39.1/fs/fuse/dir.c
47699 --- linux-2.6.39.1/fs/fuse/dir.c 2011-05-19 00:06:34.000000000 -0400
47700 +++ linux-2.6.39.1/fs/fuse/dir.c 2011-05-22 19:36:32.000000000 -0400
47701 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *de
47702 return link;
47703 }
47704
47705 -static void free_link(char *link)
47706 +static void free_link(const char *link)
47707 {
47708 if (!IS_ERR(link))
47709 free_page((unsigned long) link);
47710 diff -urNp linux-2.6.39.1/fs/fuse/fuse_i.h linux-2.6.39.1/fs/fuse/fuse_i.h
47711 --- linux-2.6.39.1/fs/fuse/fuse_i.h 2011-05-19 00:06:34.000000000 -0400
47712 +++ linux-2.6.39.1/fs/fuse/fuse_i.h 2011-05-22 19:36:32.000000000 -0400
47713 @@ -540,6 +540,16 @@ extern const struct file_operations fuse
47714
47715 extern const struct dentry_operations fuse_dentry_operations;
47716
47717 +extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47718 + unsigned long nr_segs, loff_t pos);
47719 +
47720 +extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47721 + unsigned long nr_segs, loff_t pos);
47722 +
47723 +extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
47724 +
47725 +extern int fuse_dev_fasync(int fd, struct file *file, int on);
47726 +
47727 /**
47728 * Inode to nodeid comparison.
47729 */
47730 diff -urNp linux-2.6.39.1/fs/gfs2/ops_inode.c linux-2.6.39.1/fs/gfs2/ops_inode.c
47731 --- linux-2.6.39.1/fs/gfs2/ops_inode.c 2011-05-19 00:06:34.000000000 -0400
47732 +++ linux-2.6.39.1/fs/gfs2/ops_inode.c 2011-05-22 19:36:32.000000000 -0400
47733 @@ -740,6 +740,8 @@ static int gfs2_rename(struct inode *odi
47734 unsigned int x;
47735 int error;
47736
47737 + pax_track_stack();
47738 +
47739 if (ndentry->d_inode) {
47740 nip = GFS2_I(ndentry->d_inode);
47741 if (ip == nip)
47742 @@ -1019,7 +1021,7 @@ out:
47743
47744 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47745 {
47746 - char *s = nd_get_link(nd);
47747 + const char *s = nd_get_link(nd);
47748 if (!IS_ERR(s))
47749 kfree(s);
47750 }
47751 diff -urNp linux-2.6.39.1/fs/hfsplus/catalog.c linux-2.6.39.1/fs/hfsplus/catalog.c
47752 --- linux-2.6.39.1/fs/hfsplus/catalog.c 2011-05-19 00:06:34.000000000 -0400
47753 +++ linux-2.6.39.1/fs/hfsplus/catalog.c 2011-05-22 19:36:32.000000000 -0400
47754 @@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block
47755 int err;
47756 u16 type;
47757
47758 + pax_track_stack();
47759 +
47760 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
47761 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
47762 if (err)
47763 @@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct
47764 int entry_size;
47765 int err;
47766
47767 + pax_track_stack();
47768 +
47769 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
47770 str->name, cnid, inode->i_nlink);
47771 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
47772 @@ -349,6 +353,8 @@ int hfsplus_rename_cat(u32 cnid,
47773 int entry_size, type;
47774 int err = 0;
47775
47776 + pax_track_stack();
47777 +
47778 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
47779 cnid, src_dir->i_ino, src_name->name,
47780 dst_dir->i_ino, dst_name->name);
47781 diff -urNp linux-2.6.39.1/fs/hfsplus/dir.c linux-2.6.39.1/fs/hfsplus/dir.c
47782 --- linux-2.6.39.1/fs/hfsplus/dir.c 2011-05-19 00:06:34.000000000 -0400
47783 +++ linux-2.6.39.1/fs/hfsplus/dir.c 2011-05-22 19:36:32.000000000 -0400
47784 @@ -129,6 +129,8 @@ static int hfsplus_readdir(struct file *
47785 struct hfsplus_readdir_data *rd;
47786 u16 type;
47787
47788 + pax_track_stack();
47789 +
47790 if (filp->f_pos >= inode->i_size)
47791 return 0;
47792
47793 diff -urNp linux-2.6.39.1/fs/hfsplus/inode.c linux-2.6.39.1/fs/hfsplus/inode.c
47794 --- linux-2.6.39.1/fs/hfsplus/inode.c 2011-05-19 00:06:34.000000000 -0400
47795 +++ linux-2.6.39.1/fs/hfsplus/inode.c 2011-05-22 19:36:32.000000000 -0400
47796 @@ -489,6 +489,8 @@ int hfsplus_cat_read_inode(struct inode
47797 int res = 0;
47798 u16 type;
47799
47800 + pax_track_stack();
47801 +
47802 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
47803
47804 HFSPLUS_I(inode)->linkid = 0;
47805 @@ -552,6 +554,8 @@ int hfsplus_cat_write_inode(struct inode
47806 struct hfs_find_data fd;
47807 hfsplus_cat_entry entry;
47808
47809 + pax_track_stack();
47810 +
47811 if (HFSPLUS_IS_RSRC(inode))
47812 main_inode = HFSPLUS_I(inode)->rsrc_inode;
47813
47814 diff -urNp linux-2.6.39.1/fs/hfsplus/ioctl.c linux-2.6.39.1/fs/hfsplus/ioctl.c
47815 --- linux-2.6.39.1/fs/hfsplus/ioctl.c 2011-05-19 00:06:34.000000000 -0400
47816 +++ linux-2.6.39.1/fs/hfsplus/ioctl.c 2011-05-22 19:36:32.000000000 -0400
47817 @@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dent
47818 struct hfsplus_cat_file *file;
47819 int res;
47820
47821 + pax_track_stack();
47822 +
47823 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47824 return -EOPNOTSUPP;
47825
47826 @@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *
47827 struct hfsplus_cat_file *file;
47828 ssize_t res = 0;
47829
47830 + pax_track_stack();
47831 +
47832 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47833 return -EOPNOTSUPP;
47834
47835 diff -urNp linux-2.6.39.1/fs/hfsplus/super.c linux-2.6.39.1/fs/hfsplus/super.c
47836 --- linux-2.6.39.1/fs/hfsplus/super.c 2011-05-19 00:06:34.000000000 -0400
47837 +++ linux-2.6.39.1/fs/hfsplus/super.c 2011-05-22 19:36:32.000000000 -0400
47838 @@ -340,6 +340,8 @@ static int hfsplus_fill_super(struct sup
47839 struct nls_table *nls = NULL;
47840 int err;
47841
47842 + pax_track_stack();
47843 +
47844 err = -EINVAL;
47845 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
47846 if (!sbi)
47847 diff -urNp linux-2.6.39.1/fs/hugetlbfs/inode.c linux-2.6.39.1/fs/hugetlbfs/inode.c
47848 --- linux-2.6.39.1/fs/hugetlbfs/inode.c 2011-05-19 00:06:34.000000000 -0400
47849 +++ linux-2.6.39.1/fs/hugetlbfs/inode.c 2011-05-22 19:41:37.000000000 -0400
47850 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs
47851 .kill_sb = kill_litter_super,
47852 };
47853
47854 -static struct vfsmount *hugetlbfs_vfsmount;
47855 +struct vfsmount *hugetlbfs_vfsmount;
47856
47857 static int can_do_hugetlb_shm(void)
47858 {
47859 diff -urNp linux-2.6.39.1/fs/inode.c linux-2.6.39.1/fs/inode.c
47860 --- linux-2.6.39.1/fs/inode.c 2011-05-19 00:06:34.000000000 -0400
47861 +++ linux-2.6.39.1/fs/inode.c 2011-05-22 19:36:32.000000000 -0400
47862 @@ -862,8 +862,8 @@ unsigned int get_next_ino(void)
47863
47864 #ifdef CONFIG_SMP
47865 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47866 - static atomic_t shared_last_ino;
47867 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47868 + static atomic_unchecked_t shared_last_ino;
47869 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47870
47871 res = next - LAST_INO_BATCH;
47872 }
47873 diff -urNp linux-2.6.39.1/fs/jbd/checkpoint.c linux-2.6.39.1/fs/jbd/checkpoint.c
47874 --- linux-2.6.39.1/fs/jbd/checkpoint.c 2011-05-19 00:06:34.000000000 -0400
47875 +++ linux-2.6.39.1/fs/jbd/checkpoint.c 2011-05-22 19:36:32.000000000 -0400
47876 @@ -350,6 +350,8 @@ int log_do_checkpoint(journal_t *journal
47877 tid_t this_tid;
47878 int result;
47879
47880 + pax_track_stack();
47881 +
47882 jbd_debug(1, "Start checkpoint\n");
47883
47884 /*
47885 diff -urNp linux-2.6.39.1/fs/jffs2/compr_rtime.c linux-2.6.39.1/fs/jffs2/compr_rtime.c
47886 --- linux-2.6.39.1/fs/jffs2/compr_rtime.c 2011-05-19 00:06:34.000000000 -0400
47887 +++ linux-2.6.39.1/fs/jffs2/compr_rtime.c 2011-05-22 19:36:32.000000000 -0400
47888 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
47889 int outpos = 0;
47890 int pos=0;
47891
47892 + pax_track_stack();
47893 +
47894 memset(positions,0,sizeof(positions));
47895
47896 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
47897 @@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsign
47898 int outpos = 0;
47899 int pos=0;
47900
47901 + pax_track_stack();
47902 +
47903 memset(positions,0,sizeof(positions));
47904
47905 while (outpos<destlen) {
47906 diff -urNp linux-2.6.39.1/fs/jffs2/compr_rubin.c linux-2.6.39.1/fs/jffs2/compr_rubin.c
47907 --- linux-2.6.39.1/fs/jffs2/compr_rubin.c 2011-05-19 00:06:34.000000000 -0400
47908 +++ linux-2.6.39.1/fs/jffs2/compr_rubin.c 2011-05-22 19:36:32.000000000 -0400
47909 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
47910 int ret;
47911 uint32_t mysrclen, mydstlen;
47912
47913 + pax_track_stack();
47914 +
47915 mysrclen = *sourcelen;
47916 mydstlen = *dstlen - 8;
47917
47918 diff -urNp linux-2.6.39.1/fs/jffs2/erase.c linux-2.6.39.1/fs/jffs2/erase.c
47919 --- linux-2.6.39.1/fs/jffs2/erase.c 2011-05-19 00:06:34.000000000 -0400
47920 +++ linux-2.6.39.1/fs/jffs2/erase.c 2011-05-22 19:36:32.000000000 -0400
47921 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
47922 struct jffs2_unknown_node marker = {
47923 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47924 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47925 - .totlen = cpu_to_je32(c->cleanmarker_size)
47926 + .totlen = cpu_to_je32(c->cleanmarker_size),
47927 + .hdr_crc = cpu_to_je32(0)
47928 };
47929
47930 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47931 diff -urNp linux-2.6.39.1/fs/jffs2/wbuf.c linux-2.6.39.1/fs/jffs2/wbuf.c
47932 --- linux-2.6.39.1/fs/jffs2/wbuf.c 2011-05-19 00:06:34.000000000 -0400
47933 +++ linux-2.6.39.1/fs/jffs2/wbuf.c 2011-05-22 19:36:32.000000000 -0400
47934 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
47935 {
47936 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47937 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47938 - .totlen = constant_cpu_to_je32(8)
47939 + .totlen = constant_cpu_to_je32(8),
47940 + .hdr_crc = constant_cpu_to_je32(0)
47941 };
47942
47943 /*
47944 diff -urNp linux-2.6.39.1/fs/jffs2/xattr.c linux-2.6.39.1/fs/jffs2/xattr.c
47945 --- linux-2.6.39.1/fs/jffs2/xattr.c 2011-05-19 00:06:34.000000000 -0400
47946 +++ linux-2.6.39.1/fs/jffs2/xattr.c 2011-05-22 19:36:32.000000000 -0400
47947 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
47948
47949 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
47950
47951 + pax_track_stack();
47952 +
47953 /* Phase.1 : Merge same xref */
47954 for (i=0; i < XREF_TMPHASH_SIZE; i++)
47955 xref_tmphash[i] = NULL;
47956 diff -urNp linux-2.6.39.1/fs/Kconfig.binfmt linux-2.6.39.1/fs/Kconfig.binfmt
47957 --- linux-2.6.39.1/fs/Kconfig.binfmt 2011-05-19 00:06:34.000000000 -0400
47958 +++ linux-2.6.39.1/fs/Kconfig.binfmt 2011-05-22 19:36:32.000000000 -0400
47959 @@ -86,7 +86,7 @@ config HAVE_AOUT
47960
47961 config BINFMT_AOUT
47962 tristate "Kernel support for a.out and ECOFF binaries"
47963 - depends on HAVE_AOUT
47964 + depends on HAVE_AOUT && BROKEN
47965 ---help---
47966 A.out (Assembler.OUTput) is a set of formats for libraries and
47967 executables used in the earliest versions of UNIX. Linux used
47968 diff -urNp linux-2.6.39.1/fs/libfs.c linux-2.6.39.1/fs/libfs.c
47969 --- linux-2.6.39.1/fs/libfs.c 2011-05-19 00:06:34.000000000 -0400
47970 +++ linux-2.6.39.1/fs/libfs.c 2011-05-22 19:36:32.000000000 -0400
47971 @@ -163,6 +163,9 @@ int dcache_readdir(struct file * filp, v
47972
47973 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47974 struct dentry *next;
47975 + char d_name[sizeof(next->d_iname)];
47976 + const unsigned char *name;
47977 +
47978 next = list_entry(p, struct dentry, d_u.d_child);
47979 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47980 if (!simple_positive(next)) {
47981 @@ -172,7 +175,12 @@ int dcache_readdir(struct file * filp, v
47982
47983 spin_unlock(&next->d_lock);
47984 spin_unlock(&dentry->d_lock);
47985 - if (filldir(dirent, next->d_name.name,
47986 + name = next->d_name.name;
47987 + if (name == next->d_iname) {
47988 + memcpy(d_name, name, next->d_name.len);
47989 + name = d_name;
47990 + }
47991 + if (filldir(dirent, name,
47992 next->d_name.len, filp->f_pos,
47993 next->d_inode->i_ino,
47994 dt_type(next->d_inode)) < 0)
47995 diff -urNp linux-2.6.39.1/fs/lockd/clntproc.c linux-2.6.39.1/fs/lockd/clntproc.c
47996 --- linux-2.6.39.1/fs/lockd/clntproc.c 2011-05-19 00:06:34.000000000 -0400
47997 +++ linux-2.6.39.1/fs/lockd/clntproc.c 2011-05-22 19:36:32.000000000 -0400
47998 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
47999 /*
48000 * Cookie counter for NLM requests
48001 */
48002 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48003 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48004
48005 void nlmclnt_next_cookie(struct nlm_cookie *c)
48006 {
48007 - u32 cookie = atomic_inc_return(&nlm_cookie);
48008 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48009
48010 memcpy(c->data, &cookie, 4);
48011 c->len=4;
48012 @@ -620,6 +620,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
48013 struct nlm_rqst reqst, *req;
48014 int status;
48015
48016 + pax_track_stack();
48017 +
48018 req = &reqst;
48019 memset(req, 0, sizeof(*req));
48020 locks_init_lock(&req->a_args.lock.fl);
48021 diff -urNp linux-2.6.39.1/fs/lockd/svc.c linux-2.6.39.1/fs/lockd/svc.c
48022 --- linux-2.6.39.1/fs/lockd/svc.c 2011-05-19 00:06:34.000000000 -0400
48023 +++ linux-2.6.39.1/fs/lockd/svc.c 2011-05-22 19:36:32.000000000 -0400
48024 @@ -41,7 +41,7 @@
48025
48026 static struct svc_program nlmsvc_program;
48027
48028 -struct nlmsvc_binding * nlmsvc_ops;
48029 +const struct nlmsvc_binding * nlmsvc_ops;
48030 EXPORT_SYMBOL_GPL(nlmsvc_ops);
48031
48032 static DEFINE_MUTEX(nlmsvc_mutex);
48033 diff -urNp linux-2.6.39.1/fs/locks.c linux-2.6.39.1/fs/locks.c
48034 --- linux-2.6.39.1/fs/locks.c 2011-05-19 00:06:34.000000000 -0400
48035 +++ linux-2.6.39.1/fs/locks.c 2011-05-22 19:36:32.000000000 -0400
48036 @@ -2033,16 +2033,16 @@ void locks_remove_flock(struct file *fil
48037 return;
48038
48039 if (filp->f_op && filp->f_op->flock) {
48040 - struct file_lock fl = {
48041 + struct file_lock flock = {
48042 .fl_pid = current->tgid,
48043 .fl_file = filp,
48044 .fl_flags = FL_FLOCK,
48045 .fl_type = F_UNLCK,
48046 .fl_end = OFFSET_MAX,
48047 };
48048 - filp->f_op->flock(filp, F_SETLKW, &fl);
48049 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
48050 - fl.fl_ops->fl_release_private(&fl);
48051 + filp->f_op->flock(filp, F_SETLKW, &flock);
48052 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
48053 + flock.fl_ops->fl_release_private(&flock);
48054 }
48055
48056 lock_flocks();
48057 diff -urNp linux-2.6.39.1/fs/logfs/super.c linux-2.6.39.1/fs/logfs/super.c
48058 --- linux-2.6.39.1/fs/logfs/super.c 2011-05-19 00:06:34.000000000 -0400
48059 +++ linux-2.6.39.1/fs/logfs/super.c 2011-05-22 19:36:32.000000000 -0400
48060 @@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super
48061 struct logfs_disk_super _ds1, *ds1 = &_ds1;
48062 int err, valid0, valid1;
48063
48064 + pax_track_stack();
48065 +
48066 /* read first superblock */
48067 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
48068 if (err)
48069 diff -urNp linux-2.6.39.1/fs/namei.c linux-2.6.39.1/fs/namei.c
48070 --- linux-2.6.39.1/fs/namei.c 2011-06-03 00:04:14.000000000 -0400
48071 +++ linux-2.6.39.1/fs/namei.c 2011-06-03 00:32:07.000000000 -0400
48072 @@ -237,20 +237,30 @@ int generic_permission(struct inode *ino
48073 return ret;
48074
48075 /*
48076 - * Read/write DACs are always overridable.
48077 - * Executable DACs are overridable if at least one exec bit is set.
48078 + * Searching includes executable on directories, else just read.
48079 */
48080 - if (!(mask & MAY_EXEC) || execute_ok(inode))
48081 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48082 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48083 + if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) {
48084 +#ifdef CONFIG_GRKERNSEC
48085 + if (flags & IPERM_FLAG_RCU)
48086 + return -ECHILD;
48087 +#endif
48088 + if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48089 return 0;
48090 + }
48091
48092 /*
48093 - * Searching includes executable on directories, else just read.
48094 + * Read/write DACs are always overridable.
48095 + * Executable DACs are overridable if at least one exec bit is set.
48096 */
48097 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48098 - if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
48099 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48100 + if (!(mask & MAY_EXEC) || execute_ok(inode)) {
48101 +#ifdef CONFIG_GRKERNSEC
48102 + if (flags & IPERM_FLAG_RCU)
48103 + return -ECHILD;
48104 +#endif
48105 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48106 return 0;
48107 + }
48108
48109 return -EACCES;
48110 }
48111 @@ -626,6 +636,9 @@ static inline int handle_reval_path(stru
48112 struct dentry *dentry = nd->path.dentry;
48113 int status;
48114
48115 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
48116 + return -ENOENT;
48117 +
48118 if (likely(!(nd->flags & LOOKUP_JUMPED)))
48119 return 0;
48120
48121 @@ -671,9 +684,16 @@ static inline int exec_permission(struct
48122 if (ret == -ECHILD)
48123 return ret;
48124
48125 - if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
48126 - ns_capable(ns, CAP_DAC_READ_SEARCH))
48127 + if (ns_capable_nolog(ns, CAP_DAC_OVERRIDE))
48128 goto ok;
48129 + else {
48130 +#ifdef CONFIG_GRKERNSEC
48131 + if (flags & IPERM_FLAG_RCU)
48132 + return -ECHILD;
48133 +#endif
48134 + if (ns_capable(ns, CAP_DAC_READ_SEARCH) || ns_capable(ns, CAP_DAC_OVERRIDE))
48135 + goto ok;
48136 + }
48137
48138 return ret;
48139 ok:
48140 @@ -781,11 +801,19 @@ follow_link(struct path *link, struct na
48141 return error;
48142 }
48143
48144 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48145 + dentry->d_inode, dentry, nd->path.mnt)) {
48146 + error = -EACCES;
48147 + *p = ERR_PTR(error); /* no ->put_link(), please */
48148 + path_put(&nd->path);
48149 + return error;
48150 + }
48151 +
48152 nd->last_type = LAST_BIND;
48153 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48154 error = PTR_ERR(*p);
48155 if (!IS_ERR(*p)) {
48156 - char *s = nd_get_link(nd);
48157 + const char *s = nd_get_link(nd);
48158 error = 0;
48159 if (s)
48160 error = __vfs_follow_link(nd, s);
48161 @@ -1697,6 +1725,9 @@ static int do_path_lookup(int dfd, const
48162 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48163
48164 if (likely(!retval)) {
48165 + if (*name != '/' && nd->path.dentry && nd->inode && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48166 + return -ENOENT;
48167 +
48168 if (unlikely(!audit_dummy_context())) {
48169 if (nd->path.dentry && nd->inode)
48170 audit_inode(name, nd->path.dentry);
48171 @@ -2007,6 +2038,30 @@ int vfs_create(struct inode *dir, struct
48172 return error;
48173 }
48174
48175 +/*
48176 + * Note that while the flag value (low two bits) for sys_open means:
48177 + * 00 - read-only
48178 + * 01 - write-only
48179 + * 10 - read-write
48180 + * 11 - special
48181 + * it is changed into
48182 + * 00 - no permissions needed
48183 + * 01 - read-permission
48184 + * 10 - write-permission
48185 + * 11 - read-write
48186 + * for the internal routines (ie open_namei()/follow_link() etc)
48187 + * This is more logical, and also allows the 00 "no perm needed"
48188 + * to be used for symlinks (where the permissions are checked
48189 + * later).
48190 + *
48191 +*/
48192 +static inline int open_to_namei_flags(int flag)
48193 +{
48194 + if ((flag+1) & O_ACCMODE)
48195 + flag++;
48196 + return flag;
48197 +}
48198 +
48199 static int may_open(struct path *path, int acc_mode, int flag)
48200 {
48201 struct dentry *dentry = path->dentry;
48202 @@ -2059,7 +2114,27 @@ static int may_open(struct path *path, i
48203 /*
48204 * Ensure there are no outstanding leases on the file.
48205 */
48206 - return break_lease(inode, flag);
48207 + error = break_lease(inode, flag);
48208 +
48209 + if (error)
48210 + return error;
48211 +
48212 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
48213 + error = -EPERM;
48214 + goto exit;
48215 + }
48216 +
48217 + if (gr_handle_rawio(inode)) {
48218 + error = -EPERM;
48219 + goto exit;
48220 + }
48221 +
48222 + if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
48223 + error = -EACCES;
48224 + goto exit;
48225 + }
48226 +exit:
48227 + return error;
48228 }
48229
48230 static int handle_truncate(struct file *filp)
48231 @@ -2085,30 +2160,6 @@ static int handle_truncate(struct file *
48232 }
48233
48234 /*
48235 - * Note that while the flag value (low two bits) for sys_open means:
48236 - * 00 - read-only
48237 - * 01 - write-only
48238 - * 10 - read-write
48239 - * 11 - special
48240 - * it is changed into
48241 - * 00 - no permissions needed
48242 - * 01 - read-permission
48243 - * 10 - write-permission
48244 - * 11 - read-write
48245 - * for the internal routines (ie open_namei()/follow_link() etc)
48246 - * This is more logical, and also allows the 00 "no perm needed"
48247 - * to be used for symlinks (where the permissions are checked
48248 - * later).
48249 - *
48250 -*/
48251 -static inline int open_to_namei_flags(int flag)
48252 -{
48253 - if ((flag+1) & O_ACCMODE)
48254 - flag++;
48255 - return flag;
48256 -}
48257 -
48258 -/*
48259 * Handle the last step of open()
48260 */
48261 static struct file *do_last(struct nameidata *nd, struct path *path,
48262 @@ -2117,6 +2168,7 @@ static struct file *do_last(struct namei
48263 struct dentry *dir = nd->path.dentry;
48264 struct dentry *dentry;
48265 int open_flag = op->open_flag;
48266 + int flag = open_to_namei_flags(open_flag);
48267 int will_truncate = open_flag & O_TRUNC;
48268 int want_write = 0;
48269 int acc_mode = op->acc_mode;
48270 @@ -2212,6 +2264,12 @@ static struct file *do_last(struct namei
48271 /* Negative dentry, just create the file */
48272 if (!dentry->d_inode) {
48273 int mode = op->mode;
48274 +
48275 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, flag, mode)) {
48276 + error = -EACCES;
48277 + goto exit_mutex_unlock;
48278 + }
48279 +
48280 if (!IS_POSIXACL(dir->d_inode))
48281 mode &= ~current_umask();
48282 /*
48283 @@ -2235,6 +2293,8 @@ static struct file *do_last(struct namei
48284 error = vfs_create(dir->d_inode, dentry, mode, nd);
48285 if (error)
48286 goto exit_mutex_unlock;
48287 + else
48288 + gr_handle_create(path->dentry, path->mnt);
48289 mutex_unlock(&dir->d_inode->i_mutex);
48290 dput(nd->path.dentry);
48291 nd->path.dentry = dentry;
48292 @@ -2244,6 +2304,14 @@ static struct file *do_last(struct namei
48293 /*
48294 * It already exists.
48295 */
48296 +
48297 + /* only check if O_CREAT is specified, all other checks need to go
48298 + into may_open */
48299 + if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
48300 + error = -EACCES;
48301 + goto exit_mutex_unlock;
48302 + }
48303 +
48304 mutex_unlock(&dir->d_inode->i_mutex);
48305 audit_inode(pathname, path->dentry);
48306
48307 @@ -2530,6 +2598,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48308 error = may_mknod(mode);
48309 if (error)
48310 goto out_dput;
48311 +
48312 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
48313 + error = -EPERM;
48314 + goto out_dput;
48315 + }
48316 +
48317 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
48318 + error = -EACCES;
48319 + goto out_dput;
48320 + }
48321 +
48322 error = mnt_want_write(nd.path.mnt);
48323 if (error)
48324 goto out_dput;
48325 @@ -2550,6 +2629,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48326 }
48327 out_drop_write:
48328 mnt_drop_write(nd.path.mnt);
48329 +
48330 + if (!error)
48331 + gr_handle_create(dentry, nd.path.mnt);
48332 out_dput:
48333 dput(dentry);
48334 out_unlock:
48335 @@ -2602,6 +2684,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48336 if (IS_ERR(dentry))
48337 goto out_unlock;
48338
48339 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
48340 + error = -EACCES;
48341 + goto out_dput;
48342 + }
48343 +
48344 if (!IS_POSIXACL(nd.path.dentry->d_inode))
48345 mode &= ~current_umask();
48346 error = mnt_want_write(nd.path.mnt);
48347 @@ -2613,6 +2700,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48348 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
48349 out_drop_write:
48350 mnt_drop_write(nd.path.mnt);
48351 +
48352 + if (!error)
48353 + gr_handle_create(dentry, nd.path.mnt);
48354 +
48355 out_dput:
48356 dput(dentry);
48357 out_unlock:
48358 @@ -2692,6 +2783,8 @@ static long do_rmdir(int dfd, const char
48359 char * name;
48360 struct dentry *dentry;
48361 struct nameidata nd;
48362 + ino_t saved_ino = 0;
48363 + dev_t saved_dev = 0;
48364
48365 error = user_path_parent(dfd, pathname, &nd, &name);
48366 if (error)
48367 @@ -2716,6 +2809,19 @@ static long do_rmdir(int dfd, const char
48368 error = PTR_ERR(dentry);
48369 if (IS_ERR(dentry))
48370 goto exit2;
48371 +
48372 + if (dentry->d_inode != NULL) {
48373 + if (dentry->d_inode->i_nlink <= 1) {
48374 + saved_ino = dentry->d_inode->i_ino;
48375 + saved_dev = gr_get_dev_from_dentry(dentry);
48376 + }
48377 +
48378 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48379 + error = -EACCES;
48380 + goto exit3;
48381 + }
48382 + }
48383 +
48384 error = mnt_want_write(nd.path.mnt);
48385 if (error)
48386 goto exit3;
48387 @@ -2723,6 +2829,8 @@ static long do_rmdir(int dfd, const char
48388 if (error)
48389 goto exit4;
48390 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48391 + if (!error && (saved_dev || saved_ino))
48392 + gr_handle_delete(saved_ino, saved_dev);
48393 exit4:
48394 mnt_drop_write(nd.path.mnt);
48395 exit3:
48396 @@ -2785,6 +2893,8 @@ static long do_unlinkat(int dfd, const c
48397 struct dentry *dentry;
48398 struct nameidata nd;
48399 struct inode *inode = NULL;
48400 + ino_t saved_ino = 0;
48401 + dev_t saved_dev = 0;
48402
48403 error = user_path_parent(dfd, pathname, &nd, &name);
48404 if (error)
48405 @@ -2804,8 +2914,17 @@ static long do_unlinkat(int dfd, const c
48406 if (nd.last.name[nd.last.len])
48407 goto slashes;
48408 inode = dentry->d_inode;
48409 - if (inode)
48410 + if (inode) {
48411 ihold(inode);
48412 + if (inode->i_nlink <= 1) {
48413 + saved_ino = inode->i_ino;
48414 + saved_dev = gr_get_dev_from_dentry(dentry);
48415 + }
48416 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48417 + error = -EACCES;
48418 + goto exit2;
48419 + }
48420 + }
48421 error = mnt_want_write(nd.path.mnt);
48422 if (error)
48423 goto exit2;
48424 @@ -2813,6 +2932,8 @@ static long do_unlinkat(int dfd, const c
48425 if (error)
48426 goto exit3;
48427 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48428 + if (!error && (saved_ino || saved_dev))
48429 + gr_handle_delete(saved_ino, saved_dev);
48430 exit3:
48431 mnt_drop_write(nd.path.mnt);
48432 exit2:
48433 @@ -2890,6 +3011,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
48434 if (IS_ERR(dentry))
48435 goto out_unlock;
48436
48437 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
48438 + error = -EACCES;
48439 + goto out_dput;
48440 + }
48441 +
48442 error = mnt_want_write(nd.path.mnt);
48443 if (error)
48444 goto out_dput;
48445 @@ -2897,6 +3023,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
48446 if (error)
48447 goto out_drop_write;
48448 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
48449 + if (!error)
48450 + gr_handle_create(dentry, nd.path.mnt);
48451 out_drop_write:
48452 mnt_drop_write(nd.path.mnt);
48453 out_dput:
48454 @@ -3005,6 +3133,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48455 error = PTR_ERR(new_dentry);
48456 if (IS_ERR(new_dentry))
48457 goto out_unlock;
48458 +
48459 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48460 + old_path.dentry->d_inode,
48461 + old_path.dentry->d_inode->i_mode, to)) {
48462 + error = -EACCES;
48463 + goto out_dput;
48464 + }
48465 +
48466 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
48467 + old_path.dentry, old_path.mnt, to)) {
48468 + error = -EACCES;
48469 + goto out_dput;
48470 + }
48471 +
48472 error = mnt_want_write(nd.path.mnt);
48473 if (error)
48474 goto out_dput;
48475 @@ -3012,6 +3154,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48476 if (error)
48477 goto out_drop_write;
48478 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
48479 + if (!error)
48480 + gr_handle_create(new_dentry, nd.path.mnt);
48481 out_drop_write:
48482 mnt_drop_write(nd.path.mnt);
48483 out_dput:
48484 @@ -3189,6 +3333,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48485 char *to;
48486 int error;
48487
48488 + pax_track_stack();
48489 +
48490 error = user_path_parent(olddfd, oldname, &oldnd, &from);
48491 if (error)
48492 goto exit;
48493 @@ -3245,6 +3391,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48494 if (new_dentry == trap)
48495 goto exit5;
48496
48497 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48498 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48499 + to);
48500 + if (error)
48501 + goto exit5;
48502 +
48503 error = mnt_want_write(oldnd.path.mnt);
48504 if (error)
48505 goto exit5;
48506 @@ -3254,6 +3406,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48507 goto exit6;
48508 error = vfs_rename(old_dir->d_inode, old_dentry,
48509 new_dir->d_inode, new_dentry);
48510 + if (!error)
48511 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48512 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48513 exit6:
48514 mnt_drop_write(oldnd.path.mnt);
48515 exit5:
48516 @@ -3279,6 +3434,8 @@ SYSCALL_DEFINE2(rename, const char __use
48517
48518 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48519 {
48520 + char tmpbuf[64];
48521 + const char *newlink;
48522 int len;
48523
48524 len = PTR_ERR(link);
48525 @@ -3288,7 +3445,14 @@ int vfs_readlink(struct dentry *dentry,
48526 len = strlen(link);
48527 if (len > (unsigned) buflen)
48528 len = buflen;
48529 - if (copy_to_user(buffer, link, len))
48530 +
48531 + if (len < sizeof(tmpbuf)) {
48532 + memcpy(tmpbuf, link, len);
48533 + newlink = tmpbuf;
48534 + } else
48535 + newlink = link;
48536 +
48537 + if (copy_to_user(buffer, newlink, len))
48538 len = -EFAULT;
48539 out:
48540 return len;
48541 diff -urNp linux-2.6.39.1/fs/namespace.c linux-2.6.39.1/fs/namespace.c
48542 --- linux-2.6.39.1/fs/namespace.c 2011-05-19 00:06:34.000000000 -0400
48543 +++ linux-2.6.39.1/fs/namespace.c 2011-05-22 20:43:58.000000000 -0400
48544 @@ -1328,6 +1328,9 @@ static int do_umount(struct vfsmount *mn
48545 if (!(sb->s_flags & MS_RDONLY))
48546 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48547 up_write(&sb->s_umount);
48548 +
48549 + gr_log_remount(mnt->mnt_devname, retval);
48550 +
48551 return retval;
48552 }
48553
48554 @@ -1347,6 +1350,9 @@ static int do_umount(struct vfsmount *mn
48555 br_write_unlock(vfsmount_lock);
48556 up_write(&namespace_sem);
48557 release_mounts(&umount_list);
48558 +
48559 + gr_log_unmount(mnt->mnt_devname, retval);
48560 +
48561 return retval;
48562 }
48563
48564 @@ -2338,6 +2344,16 @@ long do_mount(char *dev_name, char *dir_
48565 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48566 MS_STRICTATIME);
48567
48568 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48569 + retval = -EPERM;
48570 + goto dput_out;
48571 + }
48572 +
48573 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48574 + retval = -EPERM;
48575 + goto dput_out;
48576 + }
48577 +
48578 if (flags & MS_REMOUNT)
48579 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48580 data_page);
48581 @@ -2352,6 +2368,9 @@ long do_mount(char *dev_name, char *dir_
48582 dev_name, data_page);
48583 dput_out:
48584 path_put(&path);
48585 +
48586 + gr_log_mount(dev_name, dir_name, retval);
48587 +
48588 return retval;
48589 }
48590
48591 @@ -2575,6 +2594,11 @@ SYSCALL_DEFINE2(pivot_root, const char _
48592 if (error)
48593 goto out2;
48594
48595 + if (gr_handle_chroot_pivot()) {
48596 + error = -EPERM;
48597 + goto out2;
48598 + }
48599 +
48600 get_fs_root(current->fs, &root);
48601 error = lock_mount(&old);
48602 if (error)
48603 diff -urNp linux-2.6.39.1/fs/ncpfs/dir.c linux-2.6.39.1/fs/ncpfs/dir.c
48604 --- linux-2.6.39.1/fs/ncpfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48605 +++ linux-2.6.39.1/fs/ncpfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48606 @@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentr
48607 int res, val = 0, len;
48608 __u8 __name[NCP_MAXPATHLEN + 1];
48609
48610 + pax_track_stack();
48611 +
48612 if (dentry == dentry->d_sb->s_root)
48613 return 1;
48614
48615 @@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct
48616 int error, res, len;
48617 __u8 __name[NCP_MAXPATHLEN + 1];
48618
48619 + pax_track_stack();
48620 +
48621 error = -EIO;
48622 if (!ncp_conn_valid(server))
48623 goto finished;
48624 @@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, st
48625 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
48626 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
48627
48628 + pax_track_stack();
48629 +
48630 ncp_age_dentry(server, dentry);
48631 len = sizeof(__name);
48632 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
48633 @@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir,
48634 int error, len;
48635 __u8 __name[NCP_MAXPATHLEN + 1];
48636
48637 + pax_track_stack();
48638 +
48639 DPRINTK("ncp_mkdir: making %s/%s\n",
48640 dentry->d_parent->d_name.name, dentry->d_name.name);
48641
48642 @@ -1135,6 +1143,8 @@ static int ncp_rename(struct inode *old_
48643 int old_len, new_len;
48644 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
48645
48646 + pax_track_stack();
48647 +
48648 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
48649 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
48650 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
48651 diff -urNp linux-2.6.39.1/fs/ncpfs/inode.c linux-2.6.39.1/fs/ncpfs/inode.c
48652 --- linux-2.6.39.1/fs/ncpfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48653 +++ linux-2.6.39.1/fs/ncpfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48654 @@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_b
48655 #endif
48656 struct ncp_entry_info finfo;
48657
48658 + pax_track_stack();
48659 +
48660 data.wdog_pid = NULL;
48661 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
48662 if (!server)
48663 diff -urNp linux-2.6.39.1/fs/nfs/inode.c linux-2.6.39.1/fs/nfs/inode.c
48664 --- linux-2.6.39.1/fs/nfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48665 +++ linux-2.6.39.1/fs/nfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48666 @@ -999,16 +999,16 @@ static int nfs_size_need_update(const st
48667 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48668 }
48669
48670 -static atomic_long_t nfs_attr_generation_counter;
48671 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48672
48673 static unsigned long nfs_read_attr_generation_counter(void)
48674 {
48675 - return atomic_long_read(&nfs_attr_generation_counter);
48676 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48677 }
48678
48679 unsigned long nfs_inc_attr_generation_counter(void)
48680 {
48681 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48682 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48683 }
48684
48685 void nfs_fattr_init(struct nfs_fattr *fattr)
48686 diff -urNp linux-2.6.39.1/fs/nfs/nfs4proc.c linux-2.6.39.1/fs/nfs/nfs4proc.c
48687 --- linux-2.6.39.1/fs/nfs/nfs4proc.c 2011-06-03 00:04:14.000000000 -0400
48688 +++ linux-2.6.39.1/fs/nfs/nfs4proc.c 2011-06-03 00:32:07.000000000 -0400
48689 @@ -5845,14 +5845,14 @@ struct nfs4_state_recovery_ops nfs41_nog
48690 };
48691 #endif /* CONFIG_NFS_V4_1 */
48692
48693 -struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48694 +const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48695 .sched_state_renewal = nfs4_proc_async_renew,
48696 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
48697 .renew_lease = nfs4_proc_renew,
48698 };
48699
48700 #if defined(CONFIG_NFS_V4_1)
48701 -struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48702 +const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48703 .sched_state_renewal = nfs41_proc_async_sequence,
48704 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
48705 .renew_lease = nfs4_proc_sequence,
48706 diff -urNp linux-2.6.39.1/fs/nfsd/lockd.c linux-2.6.39.1/fs/nfsd/lockd.c
48707 --- linux-2.6.39.1/fs/nfsd/lockd.c 2011-05-19 00:06:34.000000000 -0400
48708 +++ linux-2.6.39.1/fs/nfsd/lockd.c 2011-05-22 19:36:32.000000000 -0400
48709 @@ -60,7 +60,7 @@ nlm_fclose(struct file *filp)
48710 fput(filp);
48711 }
48712
48713 -static struct nlmsvc_binding nfsd_nlm_ops = {
48714 +static const struct nlmsvc_binding nfsd_nlm_ops = {
48715 .fopen = nlm_fopen, /* open file for locking */
48716 .fclose = nlm_fclose, /* close file */
48717 };
48718 diff -urNp linux-2.6.39.1/fs/nfsd/nfs4state.c linux-2.6.39.1/fs/nfsd/nfs4state.c
48719 --- linux-2.6.39.1/fs/nfsd/nfs4state.c 2011-05-19 00:06:34.000000000 -0400
48720 +++ linux-2.6.39.1/fs/nfsd/nfs4state.c 2011-05-22 19:36:32.000000000 -0400
48721 @@ -3784,6 +3784,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
48722 unsigned int strhashval;
48723 int err;
48724
48725 + pax_track_stack();
48726 +
48727 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
48728 (long long) lock->lk_offset,
48729 (long long) lock->lk_length);
48730 diff -urNp linux-2.6.39.1/fs/nfsd/nfs4xdr.c linux-2.6.39.1/fs/nfsd/nfs4xdr.c
48731 --- linux-2.6.39.1/fs/nfsd/nfs4xdr.c 2011-05-19 00:06:34.000000000 -0400
48732 +++ linux-2.6.39.1/fs/nfsd/nfs4xdr.c 2011-05-22 19:36:32.000000000 -0400
48733 @@ -1793,6 +1793,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
48734 .dentry = dentry,
48735 };
48736
48737 + pax_track_stack();
48738 +
48739 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
48740 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
48741 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
48742 diff -urNp linux-2.6.39.1/fs/nfsd/nfsctl.c linux-2.6.39.1/fs/nfsd/nfsctl.c
48743 --- linux-2.6.39.1/fs/nfsd/nfsctl.c 2011-05-19 00:06:34.000000000 -0400
48744 +++ linux-2.6.39.1/fs/nfsd/nfsctl.c 2011-05-22 19:36:32.000000000 -0400
48745 @@ -182,7 +182,7 @@ static int export_features_open(struct i
48746 return single_open(file, export_features_show, NULL);
48747 }
48748
48749 -static struct file_operations export_features_operations = {
48750 +static const struct file_operations export_features_operations = {
48751 .open = export_features_open,
48752 .read = seq_read,
48753 .llseek = seq_lseek,
48754 diff -urNp linux-2.6.39.1/fs/nfsd/vfs.c linux-2.6.39.1/fs/nfsd/vfs.c
48755 --- linux-2.6.39.1/fs/nfsd/vfs.c 2011-05-19 00:06:34.000000000 -0400
48756 +++ linux-2.6.39.1/fs/nfsd/vfs.c 2011-05-22 19:36:32.000000000 -0400
48757 @@ -898,7 +898,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
48758 } else {
48759 oldfs = get_fs();
48760 set_fs(KERNEL_DS);
48761 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48762 + host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
48763 set_fs(oldfs);
48764 }
48765
48766 @@ -1002,7 +1002,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
48767
48768 /* Write the data. */
48769 oldfs = get_fs(); set_fs(KERNEL_DS);
48770 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48771 + host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
48772 set_fs(oldfs);
48773 if (host_err < 0)
48774 goto out_nfserr;
48775 @@ -1525,7 +1525,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
48776 */
48777
48778 oldfs = get_fs(); set_fs(KERNEL_DS);
48779 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
48780 + host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
48781 set_fs(oldfs);
48782
48783 if (host_err < 0)
48784 diff -urNp linux-2.6.39.1/fs/nilfs2/segment.c linux-2.6.39.1/fs/nilfs2/segment.c
48785 --- linux-2.6.39.1/fs/nilfs2/segment.c 2011-05-19 00:06:34.000000000 -0400
48786 +++ linux-2.6.39.1/fs/nilfs2/segment.c 2011-05-22 19:36:32.000000000 -0400
48787 @@ -555,7 +555,7 @@ static void nilfs_write_file_node_binfo(
48788 *vblocknr = binfo->bi_v.bi_vblocknr;
48789 }
48790
48791 -static struct nilfs_sc_operations nilfs_sc_file_ops = {
48792 +static const struct nilfs_sc_operations nilfs_sc_file_ops = {
48793 .collect_data = nilfs_collect_file_data,
48794 .collect_node = nilfs_collect_file_node,
48795 .collect_bmap = nilfs_collect_file_bmap,
48796 @@ -604,7 +604,7 @@ static void nilfs_write_dat_node_binfo(s
48797 *binfo_dat = binfo->bi_dat;
48798 }
48799
48800 -static struct nilfs_sc_operations nilfs_sc_dat_ops = {
48801 +static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
48802 .collect_data = nilfs_collect_dat_data,
48803 .collect_node = nilfs_collect_file_node,
48804 .collect_bmap = nilfs_collect_dat_bmap,
48805 @@ -612,7 +612,7 @@ static struct nilfs_sc_operations nilfs_
48806 .write_node_binfo = nilfs_write_dat_node_binfo,
48807 };
48808
48809 -static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48810 +static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48811 .collect_data = nilfs_collect_file_data,
48812 .collect_node = NULL,
48813 .collect_bmap = NULL,
48814 @@ -971,7 +971,7 @@ static size_t nilfs_segctor_buffer_rest(
48815
48816 static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
48817 struct inode *inode,
48818 - struct nilfs_sc_operations *sc_ops)
48819 + const struct nilfs_sc_operations *sc_ops)
48820 {
48821 LIST_HEAD(data_buffers);
48822 LIST_HEAD(node_buffers);
48823 @@ -1475,7 +1475,7 @@ nilfs_segctor_update_payload_blocknr(str
48824 sector_t blocknr;
48825 unsigned long nfinfo = segbuf->sb_sum.nfinfo;
48826 unsigned long nblocks = 0, ndatablk = 0;
48827 - struct nilfs_sc_operations *sc_op = NULL;
48828 + const struct nilfs_sc_operations *sc_op = NULL;
48829 struct nilfs_segsum_pointer ssp;
48830 struct nilfs_finfo *finfo = NULL;
48831 union nilfs_binfo binfo;
48832 diff -urNp linux-2.6.39.1/fs/notify/dnotify/dnotify.c linux-2.6.39.1/fs/notify/dnotify/dnotify.c
48833 --- linux-2.6.39.1/fs/notify/dnotify/dnotify.c 2011-05-19 00:06:34.000000000 -0400
48834 +++ linux-2.6.39.1/fs/notify/dnotify/dnotify.c 2011-05-22 19:36:32.000000000 -0400
48835 @@ -151,7 +151,7 @@ static void dnotify_free_mark(struct fsn
48836 kmem_cache_free(dnotify_mark_cache, dn_mark);
48837 }
48838
48839 -static struct fsnotify_ops dnotify_fsnotify_ops = {
48840 +static const struct fsnotify_ops dnotify_fsnotify_ops = {
48841 .handle_event = dnotify_handle_event,
48842 .should_send_event = dnotify_should_send_event,
48843 .free_group_priv = NULL,
48844 diff -urNp linux-2.6.39.1/fs/notify/notification.c linux-2.6.39.1/fs/notify/notification.c
48845 --- linux-2.6.39.1/fs/notify/notification.c 2011-05-19 00:06:34.000000000 -0400
48846 +++ linux-2.6.39.1/fs/notify/notification.c 2011-05-22 19:36:32.000000000 -0400
48847 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
48848 * get set to 0 so it will never get 'freed'
48849 */
48850 static struct fsnotify_event *q_overflow_event;
48851 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48852 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48853
48854 /**
48855 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48856 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
48857 */
48858 u32 fsnotify_get_cookie(void)
48859 {
48860 - return atomic_inc_return(&fsnotify_sync_cookie);
48861 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48862 }
48863 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48864
48865 diff -urNp linux-2.6.39.1/fs/ntfs/dir.c linux-2.6.39.1/fs/ntfs/dir.c
48866 --- linux-2.6.39.1/fs/ntfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48867 +++ linux-2.6.39.1/fs/ntfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48868 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48869 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48870 ~(s64)(ndir->itype.index.block_size - 1)));
48871 /* Bounds checks. */
48872 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48873 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48874 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48875 "inode 0x%lx or driver bug.", vdir->i_ino);
48876 goto err_out;
48877 diff -urNp linux-2.6.39.1/fs/ntfs/file.c linux-2.6.39.1/fs/ntfs/file.c
48878 --- linux-2.6.39.1/fs/ntfs/file.c 2011-05-19 00:06:34.000000000 -0400
48879 +++ linux-2.6.39.1/fs/ntfs/file.c 2011-05-22 19:36:32.000000000 -0400
48880 @@ -2222,6 +2222,6 @@ const struct inode_operations ntfs_file_
48881 #endif /* NTFS_RW */
48882 };
48883
48884 -const struct file_operations ntfs_empty_file_ops = {};
48885 +const struct file_operations ntfs_empty_file_ops __read_only;
48886
48887 -const struct inode_operations ntfs_empty_inode_ops = {};
48888 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48889 diff -urNp linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c
48890 --- linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c 2011-05-19 00:06:34.000000000 -0400
48891 +++ linux-2.6.39.1/fs/ocfs2/cluster/heartbeat.c 2011-05-22 19:36:32.000000000 -0400
48892 @@ -2261,7 +2261,7 @@ static struct configfs_item_operations o
48893 .store_attribute = o2hb_heartbeat_group_store,
48894 };
48895
48896 -static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48897 +static const struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48898 .make_item = o2hb_heartbeat_group_make_item,
48899 .drop_item = o2hb_heartbeat_group_drop_item,
48900 };
48901 diff -urNp linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c
48902 --- linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c 2011-05-19 00:06:34.000000000 -0400
48903 +++ linux-2.6.39.1/fs/ocfs2/cluster/nodemanager.c 2011-05-22 19:36:32.000000000 -0400
48904 @@ -752,7 +752,7 @@ static void o2nm_node_group_drop_item(st
48905 config_item_put(item);
48906 }
48907
48908 -static struct configfs_group_operations o2nm_node_group_group_ops = {
48909 +static const struct configfs_group_operations o2nm_node_group_group_ops = {
48910 .make_item = o2nm_node_group_make_item,
48911 .drop_item = o2nm_node_group_drop_item,
48912 };
48913 @@ -869,7 +869,7 @@ static void o2nm_cluster_group_drop_item
48914 config_item_put(item);
48915 }
48916
48917 -static struct configfs_group_operations o2nm_cluster_group_group_ops = {
48918 +static const struct configfs_group_operations o2nm_cluster_group_group_ops = {
48919 .make_group = o2nm_cluster_group_make_group,
48920 .drop_item = o2nm_cluster_group_drop_item,
48921 };
48922 diff -urNp linux-2.6.39.1/fs/ocfs2/localalloc.c linux-2.6.39.1/fs/ocfs2/localalloc.c
48923 --- linux-2.6.39.1/fs/ocfs2/localalloc.c 2011-05-19 00:06:34.000000000 -0400
48924 +++ linux-2.6.39.1/fs/ocfs2/localalloc.c 2011-05-22 19:36:32.000000000 -0400
48925 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_windo
48926 goto bail;
48927 }
48928
48929 - atomic_inc(&osb->alloc_stats.moves);
48930 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48931
48932 bail:
48933 if (handle)
48934 diff -urNp linux-2.6.39.1/fs/ocfs2/namei.c linux-2.6.39.1/fs/ocfs2/namei.c
48935 --- linux-2.6.39.1/fs/ocfs2/namei.c 2011-05-19 00:06:34.000000000 -0400
48936 +++ linux-2.6.39.1/fs/ocfs2/namei.c 2011-05-22 19:36:32.000000000 -0400
48937 @@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *ol
48938 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
48939 struct ocfs2_dir_lookup_result target_insert = { NULL, };
48940
48941 + pax_track_stack();
48942 +
48943 /* At some point it might be nice to break this function up a
48944 * bit. */
48945
48946 diff -urNp linux-2.6.39.1/fs/ocfs2/ocfs2.h linux-2.6.39.1/fs/ocfs2/ocfs2.h
48947 --- linux-2.6.39.1/fs/ocfs2/ocfs2.h 2011-05-19 00:06:34.000000000 -0400
48948 +++ linux-2.6.39.1/fs/ocfs2/ocfs2.h 2011-05-22 19:36:32.000000000 -0400
48949 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48950
48951 struct ocfs2_alloc_stats
48952 {
48953 - atomic_t moves;
48954 - atomic_t local_data;
48955 - atomic_t bitmap_data;
48956 - atomic_t bg_allocs;
48957 - atomic_t bg_extends;
48958 + atomic_unchecked_t moves;
48959 + atomic_unchecked_t local_data;
48960 + atomic_unchecked_t bitmap_data;
48961 + atomic_unchecked_t bg_allocs;
48962 + atomic_unchecked_t bg_extends;
48963 };
48964
48965 enum ocfs2_local_alloc_state
48966 diff -urNp linux-2.6.39.1/fs/ocfs2/stackglue.h linux-2.6.39.1/fs/ocfs2/stackglue.h
48967 --- linux-2.6.39.1/fs/ocfs2/stackglue.h 2011-05-19 00:06:34.000000000 -0400
48968 +++ linux-2.6.39.1/fs/ocfs2/stackglue.h 2011-05-22 19:36:32.000000000 -0400
48969 @@ -221,13 +221,13 @@ struct ocfs2_stack_operations {
48970 };
48971
48972 /*
48973 - * Each stack plugin must describe itself by registering a
48974 + * Each stack plugin must describe itself by registerin const g a
48975 * ocfs2_stack_plugin structure. This is only seen by stackglue and the
48976 * stack driver.
48977 */
48978 struct ocfs2_stack_plugin {
48979 char *sp_name;
48980 - struct ocfs2_stack_operations *sp_ops;
48981 + const struct ocfs2_stack_operations *sp_ops;
48982 struct module *sp_owner;
48983
48984 /* These are managed by the stackglue code. */
48985 diff -urNp linux-2.6.39.1/fs/ocfs2/stack_o2cb.c linux-2.6.39.1/fs/ocfs2/stack_o2cb.c
48986 --- linux-2.6.39.1/fs/ocfs2/stack_o2cb.c 2011-05-19 00:06:34.000000000 -0400
48987 +++ linux-2.6.39.1/fs/ocfs2/stack_o2cb.c 2011-05-22 19:36:32.000000000 -0400
48988 @@ -358,7 +358,7 @@ static int o2cb_cluster_this_node(unsign
48989 return 0;
48990 }
48991
48992 -static struct ocfs2_stack_operations o2cb_stack_ops = {
48993 +static const struct ocfs2_stack_operations o2cb_stack_ops = {
48994 .connect = o2cb_cluster_connect,
48995 .disconnect = o2cb_cluster_disconnect,
48996 .this_node = o2cb_cluster_this_node,
48997 @@ -369,7 +369,6 @@ static struct ocfs2_stack_operations o2c
48998 .lock_lvb = o2cb_dlm_lvb,
48999 .dump_lksb = o2cb_dump_lksb,
49000 };
49001 -
49002 static struct ocfs2_stack_plugin o2cb_stack = {
49003 .sp_name = "o2cb",
49004 .sp_ops = &o2cb_stack_ops,
49005 diff -urNp linux-2.6.39.1/fs/ocfs2/stack_user.c linux-2.6.39.1/fs/ocfs2/stack_user.c
49006 --- linux-2.6.39.1/fs/ocfs2/stack_user.c 2011-05-19 00:06:34.000000000 -0400
49007 +++ linux-2.6.39.1/fs/ocfs2/stack_user.c 2011-05-22 19:36:32.000000000 -0400
49008 @@ -399,7 +399,7 @@ static int ocfs2_control_do_setversion_m
49009 long major, minor;
49010 char *ptr = NULL;
49011 struct ocfs2_control_private *p = file->private_data;
49012 - struct ocfs2_protocol_version *max =
49013 + const struct ocfs2_protocol_version *max =
49014 &ocfs2_user_plugin.sp_max_proto;
49015
49016 if (ocfs2_control_get_handshake_state(file) !=
49017 @@ -861,7 +861,7 @@ static int user_cluster_this_node(unsign
49018 return 0;
49019 }
49020
49021 -static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
49022 +static const struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
49023 .connect = user_cluster_connect,
49024 .disconnect = user_cluster_disconnect,
49025 .this_node = user_cluster_this_node,
49026 diff -urNp linux-2.6.39.1/fs/ocfs2/suballoc.c linux-2.6.39.1/fs/ocfs2/suballoc.c
49027 --- linux-2.6.39.1/fs/ocfs2/suballoc.c 2011-05-19 00:06:34.000000000 -0400
49028 +++ linux-2.6.39.1/fs/ocfs2/suballoc.c 2011-05-22 19:36:32.000000000 -0400
49029 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(s
49030 mlog_errno(status);
49031 goto bail;
49032 }
49033 - atomic_inc(&osb->alloc_stats.bg_extends);
49034 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49035
49036 /* You should never ask for this much metadata */
49037 BUG_ON(bits_wanted >
49038 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handl
49039 mlog_errno(status);
49040 goto bail;
49041 }
49042 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49043 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49044
49045 *suballoc_loc = res.sr_bg_blkno;
49046 *suballoc_bit_start = res.sr_bit_offset;
49047 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_
49048 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49049 res->sr_bits);
49050
49051 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49052 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49053
49054 BUG_ON(res->sr_bits != 1);
49055
49056 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *hand
49057 mlog_errno(status);
49058 goto bail;
49059 }
49060 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49061 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49062
49063 BUG_ON(res.sr_bits != 1);
49064
49065 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *han
49066 cluster_start,
49067 num_clusters);
49068 if (!status)
49069 - atomic_inc(&osb->alloc_stats.local_data);
49070 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
49071 } else {
49072 if (min_clusters > (osb->bitmap_cpg - 1)) {
49073 /* The only paths asking for contiguousness
49074 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *han
49075 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49076 res.sr_bg_blkno,
49077 res.sr_bit_offset);
49078 - atomic_inc(&osb->alloc_stats.bitmap_data);
49079 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49080 *num_clusters = res.sr_bits;
49081 }
49082 }
49083 diff -urNp linux-2.6.39.1/fs/ocfs2/super.c linux-2.6.39.1/fs/ocfs2/super.c
49084 --- linux-2.6.39.1/fs/ocfs2/super.c 2011-05-19 00:06:34.000000000 -0400
49085 +++ linux-2.6.39.1/fs/ocfs2/super.c 2011-05-22 19:36:32.000000000 -0400
49086 @@ -299,11 +299,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
49087 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49088 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49089 "Stats",
49090 - atomic_read(&osb->alloc_stats.bitmap_data),
49091 - atomic_read(&osb->alloc_stats.local_data),
49092 - atomic_read(&osb->alloc_stats.bg_allocs),
49093 - atomic_read(&osb->alloc_stats.moves),
49094 - atomic_read(&osb->alloc_stats.bg_extends));
49095 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49096 + atomic_read_unchecked(&osb->alloc_stats.local_data),
49097 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49098 + atomic_read_unchecked(&osb->alloc_stats.moves),
49099 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49100
49101 out += snprintf(buf + out, len - out,
49102 "%10s => State: %u Descriptor: %llu Size: %u bits "
49103 @@ -2111,11 +2111,11 @@ static int ocfs2_initialize_super(struct
49104 spin_lock_init(&osb->osb_xattr_lock);
49105 ocfs2_init_steal_slots(osb);
49106
49107 - atomic_set(&osb->alloc_stats.moves, 0);
49108 - atomic_set(&osb->alloc_stats.local_data, 0);
49109 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49110 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49111 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49112 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49113 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49114 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49115 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49116 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49117
49118 /* Copy the blockcheck stats from the superblock probe */
49119 osb->osb_ecc_stats = *stats;
49120 diff -urNp linux-2.6.39.1/fs/ocfs2/symlink.c linux-2.6.39.1/fs/ocfs2/symlink.c
49121 --- linux-2.6.39.1/fs/ocfs2/symlink.c 2011-05-19 00:06:34.000000000 -0400
49122 +++ linux-2.6.39.1/fs/ocfs2/symlink.c 2011-05-22 19:36:32.000000000 -0400
49123 @@ -142,7 +142,7 @@ bail:
49124
49125 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49126 {
49127 - char *link = nd_get_link(nd);
49128 + const char *link = nd_get_link(nd);
49129 if (!IS_ERR(link))
49130 kfree(link);
49131 }
49132 diff -urNp linux-2.6.39.1/fs/open.c linux-2.6.39.1/fs/open.c
49133 --- linux-2.6.39.1/fs/open.c 2011-05-19 00:06:34.000000000 -0400
49134 +++ linux-2.6.39.1/fs/open.c 2011-05-22 20:46:51.000000000 -0400
49135 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
49136 error = locks_verify_truncate(inode, NULL, length);
49137 if (!error)
49138 error = security_path_truncate(&path);
49139 +
49140 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49141 + error = -EACCES;
49142 +
49143 if (!error)
49144 error = do_truncate(path.dentry, length, 0, NULL);
49145
49146 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
49147 if (__mnt_is_readonly(path.mnt))
49148 res = -EROFS;
49149
49150 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49151 + res = -EACCES;
49152 +
49153 out_path_release:
49154 path_put(&path);
49155 out:
49156 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user
49157 if (error)
49158 goto dput_and_out;
49159
49160 + gr_log_chdir(path.dentry, path.mnt);
49161 +
49162 set_fs_pwd(current->fs, &path);
49163
49164 dput_and_out:
49165 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
49166 goto out_putf;
49167
49168 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49169 +
49170 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49171 + error = -EPERM;
49172 +
49173 + if (!error)
49174 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49175 +
49176 if (!error)
49177 set_fs_pwd(current->fs, &file->f_path);
49178 out_putf:
49179 @@ -438,7 +454,18 @@ SYSCALL_DEFINE1(chroot, const char __use
49180 if (error)
49181 goto dput_and_out;
49182
49183 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49184 + goto dput_and_out;
49185 +
49186 + if (gr_handle_chroot_caps(&path)) {
49187 + error = -ENOMEM;
49188 + goto dput_and_out;
49189 + }
49190 +
49191 set_fs_root(current->fs, &path);
49192 +
49193 + gr_handle_chroot_chdir(&path);
49194 +
49195 error = 0;
49196 dput_and_out:
49197 path_put(&path);
49198 @@ -466,12 +493,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
49199 err = mnt_want_write_file(file);
49200 if (err)
49201 goto out_putf;
49202 +
49203 mutex_lock(&inode->i_mutex);
49204 +
49205 + if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
49206 + err = -EACCES;
49207 + goto out_unlock;
49208 + }
49209 +
49210 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
49211 if (err)
49212 goto out_unlock;
49213 if (mode == (mode_t) -1)
49214 mode = inode->i_mode;
49215 +
49216 + if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
49217 + err = -EACCES;
49218 + goto out_unlock;
49219 + }
49220 +
49221 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49222 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49223 err = notify_change(dentry, &newattrs);
49224 @@ -499,12 +539,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
49225 error = mnt_want_write(path.mnt);
49226 if (error)
49227 goto dput_and_out;
49228 +
49229 mutex_lock(&inode->i_mutex);
49230 +
49231 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
49232 + error = -EACCES;
49233 + goto out_unlock;
49234 + }
49235 +
49236 error = security_path_chmod(path.dentry, path.mnt, mode);
49237 if (error)
49238 goto out_unlock;
49239 if (mode == (mode_t) -1)
49240 mode = inode->i_mode;
49241 +
49242 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
49243 + error = -EACCES;
49244 + goto out_unlock;
49245 + }
49246 +
49247 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49248 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49249 error = notify_change(path.dentry, &newattrs);
49250 @@ -528,6 +581,9 @@ static int chown_common(struct path *pat
49251 int error;
49252 struct iattr newattrs;
49253
49254 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49255 + return -EACCES;
49256 +
49257 newattrs.ia_valid = ATTR_CTIME;
49258 if (user != (uid_t) -1) {
49259 newattrs.ia_valid |= ATTR_UID;
49260 @@ -998,7 +1054,10 @@ long do_sys_open(int dfd, const char __u
49261 if (!IS_ERR(tmp)) {
49262 fd = get_unused_fd_flags(flags);
49263 if (fd >= 0) {
49264 - struct file *f = do_filp_open(dfd, tmp, &op, lookup);
49265 + struct file *f;
49266 + /* don't allow to be set by userland */
49267 + flags &= ~FMODE_GREXEC;
49268 + f = do_filp_open(dfd, tmp, &op, lookup);
49269 if (IS_ERR(f)) {
49270 put_unused_fd(fd);
49271 fd = PTR_ERR(f);
49272 diff -urNp linux-2.6.39.1/fs/partitions/ldm.c linux-2.6.39.1/fs/partitions/ldm.c
49273 --- linux-2.6.39.1/fs/partitions/ldm.c 2011-06-03 00:04:14.000000000 -0400
49274 +++ linux-2.6.39.1/fs/partitions/ldm.c 2011-06-03 00:32:07.000000000 -0400
49275 @@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
49276 ldm_error ("A VBLK claims to have %d parts.", num);
49277 return false;
49278 }
49279 +
49280 if (rec >= num) {
49281 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
49282 return false;
49283 @@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
49284 goto found;
49285 }
49286
49287 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
49288 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
49289 if (!f) {
49290 ldm_crit ("Out of memory.");
49291 return false;
49292 diff -urNp linux-2.6.39.1/fs/pipe.c linux-2.6.39.1/fs/pipe.c
49293 --- linux-2.6.39.1/fs/pipe.c 2011-05-19 00:06:34.000000000 -0400
49294 +++ linux-2.6.39.1/fs/pipe.c 2011-05-22 19:41:37.000000000 -0400
49295 @@ -420,9 +420,9 @@ redo:
49296 }
49297 if (bufs) /* More to do? */
49298 continue;
49299 - if (!pipe->writers)
49300 + if (!atomic_read(&pipe->writers))
49301 break;
49302 - if (!pipe->waiting_writers) {
49303 + if (!atomic_read(&pipe->waiting_writers)) {
49304 /* syscall merging: Usually we must not sleep
49305 * if O_NONBLOCK is set, or if we got some data.
49306 * But if a writer sleeps in kernel space, then
49307 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
49308 mutex_lock(&inode->i_mutex);
49309 pipe = inode->i_pipe;
49310
49311 - if (!pipe->readers) {
49312 + if (!atomic_read(&pipe->readers)) {
49313 send_sig(SIGPIPE, current, 0);
49314 ret = -EPIPE;
49315 goto out;
49316 @@ -530,7 +530,7 @@ redo1:
49317 for (;;) {
49318 int bufs;
49319
49320 - if (!pipe->readers) {
49321 + if (!atomic_read(&pipe->readers)) {
49322 send_sig(SIGPIPE, current, 0);
49323 if (!ret)
49324 ret = -EPIPE;
49325 @@ -616,9 +616,9 @@ redo2:
49326 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49327 do_wakeup = 0;
49328 }
49329 - pipe->waiting_writers++;
49330 + atomic_inc(&pipe->waiting_writers);
49331 pipe_wait(pipe);
49332 - pipe->waiting_writers--;
49333 + atomic_dec(&pipe->waiting_writers);
49334 }
49335 out:
49336 mutex_unlock(&inode->i_mutex);
49337 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
49338 mask = 0;
49339 if (filp->f_mode & FMODE_READ) {
49340 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49341 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49342 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49343 mask |= POLLHUP;
49344 }
49345
49346 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
49347 * Most Unices do not set POLLERR for FIFOs but on Linux they
49348 * behave exactly like pipes for poll().
49349 */
49350 - if (!pipe->readers)
49351 + if (!atomic_read(&pipe->readers))
49352 mask |= POLLERR;
49353 }
49354
49355 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
49356
49357 mutex_lock(&inode->i_mutex);
49358 pipe = inode->i_pipe;
49359 - pipe->readers -= decr;
49360 - pipe->writers -= decw;
49361 + atomic_sub(decr, &pipe->readers);
49362 + atomic_sub(decw, &pipe->writers);
49363
49364 - if (!pipe->readers && !pipe->writers) {
49365 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49366 free_pipe_info(inode);
49367 } else {
49368 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49369 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
49370
49371 if (inode->i_pipe) {
49372 ret = 0;
49373 - inode->i_pipe->readers++;
49374 + atomic_inc(&inode->i_pipe->readers);
49375 }
49376
49377 mutex_unlock(&inode->i_mutex);
49378 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
49379
49380 if (inode->i_pipe) {
49381 ret = 0;
49382 - inode->i_pipe->writers++;
49383 + atomic_inc(&inode->i_pipe->writers);
49384 }
49385
49386 mutex_unlock(&inode->i_mutex);
49387 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
49388 if (inode->i_pipe) {
49389 ret = 0;
49390 if (filp->f_mode & FMODE_READ)
49391 - inode->i_pipe->readers++;
49392 + atomic_inc(&inode->i_pipe->readers);
49393 if (filp->f_mode & FMODE_WRITE)
49394 - inode->i_pipe->writers++;
49395 + atomic_inc(&inode->i_pipe->writers);
49396 }
49397
49398 mutex_unlock(&inode->i_mutex);
49399 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
49400 inode->i_pipe = NULL;
49401 }
49402
49403 -static struct vfsmount *pipe_mnt __read_mostly;
49404 +struct vfsmount *pipe_mnt __read_mostly;
49405
49406 /*
49407 * pipefs_dname() is called from d_path().
49408 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
49409 goto fail_iput;
49410 inode->i_pipe = pipe;
49411
49412 - pipe->readers = pipe->writers = 1;
49413 + atomic_set(&pipe->readers, 1);
49414 + atomic_set(&pipe->writers, 1);
49415 inode->i_fop = &rdwr_pipefifo_fops;
49416
49417 /*
49418 diff -urNp linux-2.6.39.1/fs/proc/array.c linux-2.6.39.1/fs/proc/array.c
49419 --- linux-2.6.39.1/fs/proc/array.c 2011-05-19 00:06:34.000000000 -0400
49420 +++ linux-2.6.39.1/fs/proc/array.c 2011-05-22 19:41:37.000000000 -0400
49421 @@ -60,6 +60,7 @@
49422 #include <linux/tty.h>
49423 #include <linux/string.h>
49424 #include <linux/mman.h>
49425 +#include <linux/grsecurity.h>
49426 #include <linux/proc_fs.h>
49427 #include <linux/ioport.h>
49428 #include <linux/uaccess.h>
49429 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
49430 seq_putc(m, '\n');
49431 }
49432
49433 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49434 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49435 +{
49436 + if (p->mm)
49437 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49438 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49439 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49440 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49441 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49442 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49443 + else
49444 + seq_printf(m, "PaX:\t-----\n");
49445 +}
49446 +#endif
49447 +
49448 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49449 struct pid *pid, struct task_struct *task)
49450 {
49451 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
49452 task_cpus_allowed(m, task);
49453 cpuset_task_status_allowed(m, task);
49454 task_context_switch_counts(m, task);
49455 +
49456 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49457 + task_pax(m, task);
49458 +#endif
49459 +
49460 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49461 + task_grsec_rbac(m, task);
49462 +#endif
49463 +
49464 return 0;
49465 }
49466
49467 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49468 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49469 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49470 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49471 +#endif
49472 +
49473 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49474 struct pid *pid, struct task_struct *task, int whole)
49475 {
49476 @@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
49477 cputime_t cutime, cstime, utime, stime;
49478 cputime_t cgtime, gtime;
49479 unsigned long rsslim = 0;
49480 - char tcomm[sizeof(task->comm)];
49481 + char tcomm[sizeof(task->comm)] = { 0 };
49482 unsigned long flags;
49483
49484 + pax_track_stack();
49485 +
49486 state = *get_task_state(task);
49487 vsize = eip = esp = 0;
49488 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
49489 @@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
49490 gtime = task->gtime;
49491 }
49492
49493 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49494 + if (PAX_RAND_FLAGS(mm)) {
49495 + eip = 0;
49496 + esp = 0;
49497 + wchan = 0;
49498 + }
49499 +#endif
49500 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49501 + wchan = 0;
49502 + eip =0;
49503 + esp =0;
49504 +#endif
49505 +
49506 /* scale priority and nice values from timeslices to -20..20 */
49507 /* to make it look like a "normal" Unix priority/nice value */
49508 priority = task_prio(task);
49509 @@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
49510 vsize,
49511 mm ? get_mm_rss(mm) : 0,
49512 rsslim,
49513 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49514 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
49515 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
49516 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
49517 +#else
49518 mm ? (permitted ? mm->start_code : 1) : 0,
49519 mm ? (permitted ? mm->end_code : 1) : 0,
49520 (permitted && mm) ? mm->start_stack : 0,
49521 +#endif
49522 esp,
49523 eip,
49524 /* The signal information here is obsolete.
49525 @@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
49526
49527 return 0;
49528 }
49529 +
49530 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49531 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49532 +{
49533 + u32 curr_ip = 0;
49534 + unsigned long flags;
49535 +
49536 + if (lock_task_sighand(task, &flags)) {
49537 + curr_ip = task->signal->curr_ip;
49538 + unlock_task_sighand(task, &flags);
49539 + }
49540 +
49541 + return sprintf(buffer, "%pI4\n", &curr_ip);
49542 +}
49543 +#endif
49544 diff -urNp linux-2.6.39.1/fs/proc/base.c linux-2.6.39.1/fs/proc/base.c
49545 --- linux-2.6.39.1/fs/proc/base.c 2011-05-19 00:06:34.000000000 -0400
49546 +++ linux-2.6.39.1/fs/proc/base.c 2011-05-22 21:50:17.000000000 -0400
49547 @@ -104,6 +104,22 @@ struct pid_entry {
49548 union proc_op op;
49549 };
49550
49551 +struct getdents_callback {
49552 + struct linux_dirent __user * current_dir;
49553 + struct linux_dirent __user * previous;
49554 + struct file * file;
49555 + int count;
49556 + int error;
49557 +};
49558 +
49559 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
49560 + loff_t offset, u64 ino, unsigned int d_type)
49561 +{
49562 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
49563 + buf->error = -EINVAL;
49564 + return 0;
49565 +}
49566 +
49567 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49568 .name = (NAME), \
49569 .len = sizeof(NAME) - 1, \
49570 @@ -206,6 +222,9 @@ static struct mm_struct *__check_mem_per
49571 if (task == current)
49572 return mm;
49573
49574 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
49575 + return ERR_PTR(-EPERM);
49576 +
49577 /*
49578 * If current is actively ptrace'ing, and would also be
49579 * permitted to freshly attach with ptrace now, permit it.
49580 @@ -279,6 +298,9 @@ static int proc_pid_cmdline(struct task_
49581 if (!mm->arg_end)
49582 goto out_mm; /* Shh! No looking before we're done */
49583
49584 + if (gr_acl_handle_procpidmem(task))
49585 + goto out_mm;
49586 +
49587 len = mm->arg_end - mm->arg_start;
49588
49589 if (len > PAGE_SIZE)
49590 @@ -306,12 +328,28 @@ out:
49591 return res;
49592 }
49593
49594 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49595 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49596 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49597 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49598 +#endif
49599 +
49600 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49601 {
49602 struct mm_struct *mm = mm_for_maps(task);
49603 int res = PTR_ERR(mm);
49604 if (mm && !IS_ERR(mm)) {
49605 unsigned int nwords = 0;
49606 +
49607 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49608 + /* allow if we're currently ptracing this task */
49609 + if (PAX_RAND_FLAGS(mm) &&
49610 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49611 + mmput(mm);
49612 + return res;
49613 + }
49614 +#endif
49615 +
49616 do {
49617 nwords += 2;
49618 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49619 @@ -325,7 +363,7 @@ static int proc_pid_auxv(struct task_str
49620 }
49621
49622
49623 -#ifdef CONFIG_KALLSYMS
49624 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49625 /*
49626 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49627 * Returns the resolved symbol. If that fails, simply return the address.
49628 @@ -364,7 +402,7 @@ static void unlock_trace(struct task_str
49629 mutex_unlock(&task->signal->cred_guard_mutex);
49630 }
49631
49632 -#ifdef CONFIG_STACKTRACE
49633 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49634
49635 #define MAX_STACK_TRACE_DEPTH 64
49636
49637 @@ -555,7 +593,7 @@ static int proc_pid_limits(struct task_s
49638 return count;
49639 }
49640
49641 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49642 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49643 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49644 {
49645 long nr;
49646 @@ -584,7 +622,7 @@ static int proc_pid_syscall(struct task_
49647 /************************************************************************/
49648
49649 /* permission checks */
49650 -static int proc_fd_access_allowed(struct inode *inode)
49651 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49652 {
49653 struct task_struct *task;
49654 int allowed = 0;
49655 @@ -594,7 +632,10 @@ static int proc_fd_access_allowed(struct
49656 */
49657 task = get_proc_task(inode);
49658 if (task) {
49659 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49660 + if (log)
49661 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
49662 + else
49663 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49664 put_task_struct(task);
49665 }
49666 return allowed;
49667 @@ -973,6 +1014,9 @@ static ssize_t environ_read(struct file
49668 if (!task)
49669 goto out_no_task;
49670
49671 + if (gr_acl_handle_procpidmem(task))
49672 + goto out;
49673 +
49674 ret = -ENOMEM;
49675 page = (char *)__get_free_page(GFP_TEMPORARY);
49676 if (!page)
49677 @@ -1660,7 +1704,7 @@ static void *proc_pid_follow_link(struct
49678 path_put(&nd->path);
49679
49680 /* Are we allowed to snoop on the tasks file descriptors? */
49681 - if (!proc_fd_access_allowed(inode))
49682 + if (!proc_fd_access_allowed(inode,0))
49683 goto out;
49684
49685 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
49686 @@ -1699,8 +1743,18 @@ static int proc_pid_readlink(struct dent
49687 struct path path;
49688
49689 /* Are we allowed to snoop on the tasks file descriptors? */
49690 - if (!proc_fd_access_allowed(inode))
49691 - goto out;
49692 + /* logging this is needed for learning on chromium to work properly,
49693 + but we don't want to flood the logs from 'ps' which does a readlink
49694 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49695 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49696 + */
49697 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49698 + if (!proc_fd_access_allowed(inode,0))
49699 + goto out;
49700 + } else {
49701 + if (!proc_fd_access_allowed(inode,1))
49702 + goto out;
49703 + }
49704
49705 error = PROC_I(inode)->op.proc_get_link(inode, &path);
49706 if (error)
49707 @@ -1766,7 +1820,11 @@ static struct inode *proc_pid_make_inode
49708 rcu_read_lock();
49709 cred = __task_cred(task);
49710 inode->i_uid = cred->euid;
49711 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49712 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49713 +#else
49714 inode->i_gid = cred->egid;
49715 +#endif
49716 rcu_read_unlock();
49717 }
49718 security_task_to_inode(task, inode);
49719 @@ -1784,6 +1842,9 @@ static int pid_getattr(struct vfsmount *
49720 struct inode *inode = dentry->d_inode;
49721 struct task_struct *task;
49722 const struct cred *cred;
49723 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49724 + const struct cred *tmpcred = current_cred();
49725 +#endif
49726
49727 generic_fillattr(inode, stat);
49728
49729 @@ -1791,12 +1852,34 @@ static int pid_getattr(struct vfsmount *
49730 stat->uid = 0;
49731 stat->gid = 0;
49732 task = pid_task(proc_pid(inode), PIDTYPE_PID);
49733 +
49734 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
49735 + rcu_read_unlock();
49736 + return -ENOENT;
49737 + }
49738 +
49739 if (task) {
49740 + cred = __task_cred(task);
49741 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49742 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49743 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49744 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49745 +#endif
49746 + )
49747 +#endif
49748 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49749 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49750 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49751 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49752 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49753 +#endif
49754 task_dumpable(task)) {
49755 - cred = __task_cred(task);
49756 stat->uid = cred->euid;
49757 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49758 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49759 +#else
49760 stat->gid = cred->egid;
49761 +#endif
49762 }
49763 }
49764 rcu_read_unlock();
49765 @@ -1834,11 +1917,20 @@ static int pid_revalidate(struct dentry
49766
49767 if (task) {
49768 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49769 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49770 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49771 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49772 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49773 +#endif
49774 task_dumpable(task)) {
49775 rcu_read_lock();
49776 cred = __task_cred(task);
49777 inode->i_uid = cred->euid;
49778 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49779 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49780 +#else
49781 inode->i_gid = cred->egid;
49782 +#endif
49783 rcu_read_unlock();
49784 } else {
49785 inode->i_uid = 0;
49786 @@ -1959,7 +2051,8 @@ static int proc_fd_info(struct inode *in
49787 int fd = proc_fd(inode);
49788
49789 if (task) {
49790 - files = get_files_struct(task);
49791 + if (!gr_acl_handle_procpidmem(task))
49792 + files = get_files_struct(task);
49793 put_task_struct(task);
49794 }
49795 if (files) {
49796 @@ -2219,15 +2312,25 @@ static const struct file_operations proc
49797 */
49798 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
49799 {
49800 + struct task_struct *task;
49801 int rv;
49802
49803 if (flags & IPERM_FLAG_RCU)
49804 return -ECHILD;
49805 rv = generic_permission(inode, mask, flags, NULL);
49806 - if (rv == 0)
49807 - return 0;
49808 +
49809 if (task_pid(current) == proc_pid(inode))
49810 rv = 0;
49811 +
49812 + task = get_proc_task(inode);
49813 + if (task == NULL)
49814 + return rv;
49815 +
49816 + if (gr_acl_handle_procpidmem(task))
49817 + rv = -EACCES;
49818 +
49819 + put_task_struct(task);
49820 +
49821 return rv;
49822 }
49823
49824 @@ -2337,6 +2440,9 @@ static struct dentry *proc_pident_lookup
49825 if (!task)
49826 goto out_no_task;
49827
49828 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49829 + goto out;
49830 +
49831 /*
49832 * Yes, it does not scale. And it should not. Don't add
49833 * new entries into /proc/<tgid>/ without very good reasons.
49834 @@ -2381,6 +2487,9 @@ static int proc_pident_readdir(struct fi
49835 if (!task)
49836 goto out_no_task;
49837
49838 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49839 + goto out;
49840 +
49841 ret = 0;
49842 i = filp->f_pos;
49843 switch (i) {
49844 @@ -2651,7 +2760,7 @@ static void *proc_self_follow_link(struc
49845 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49846 void *cookie)
49847 {
49848 - char *s = nd_get_link(nd);
49849 + const char *s = nd_get_link(nd);
49850 if (!IS_ERR(s))
49851 __putname(s);
49852 }
49853 @@ -2835,7 +2944,7 @@ static const struct pid_entry tgid_base_
49854 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49855 #endif
49856 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49857 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49858 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49859 INF("syscall", S_IRUGO, proc_pid_syscall),
49860 #endif
49861 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49862 @@ -2860,10 +2969,10 @@ static const struct pid_entry tgid_base_
49863 #ifdef CONFIG_SECURITY
49864 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49865 #endif
49866 -#ifdef CONFIG_KALLSYMS
49867 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49868 INF("wchan", S_IRUGO, proc_pid_wchan),
49869 #endif
49870 -#ifdef CONFIG_STACKTRACE
49871 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49872 ONE("stack", S_IRUGO, proc_pid_stack),
49873 #endif
49874 #ifdef CONFIG_SCHEDSTATS
49875 @@ -2894,6 +3003,9 @@ static const struct pid_entry tgid_base_
49876 #ifdef CONFIG_TASK_IO_ACCOUNTING
49877 INF("io", S_IRUGO, proc_tgid_io_accounting),
49878 #endif
49879 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49880 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49881 +#endif
49882 };
49883
49884 static int proc_tgid_base_readdir(struct file * filp,
49885 @@ -3019,7 +3131,14 @@ static struct dentry *proc_pid_instantia
49886 if (!inode)
49887 goto out;
49888
49889 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49890 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49891 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49892 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49893 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49894 +#else
49895 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49896 +#endif
49897 inode->i_op = &proc_tgid_base_inode_operations;
49898 inode->i_fop = &proc_tgid_base_operations;
49899 inode->i_flags|=S_IMMUTABLE;
49900 @@ -3061,7 +3180,11 @@ struct dentry *proc_pid_lookup(struct in
49901 if (!task)
49902 goto out;
49903
49904 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49905 + goto out_put_task;
49906 +
49907 result = proc_pid_instantiate(dir, dentry, task, NULL);
49908 +out_put_task:
49909 put_task_struct(task);
49910 out:
49911 return result;
49912 @@ -3126,6 +3249,11 @@ int proc_pid_readdir(struct file * filp,
49913 {
49914 unsigned int nr;
49915 struct task_struct *reaper;
49916 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49917 + const struct cred *tmpcred = current_cred();
49918 + const struct cred *itercred;
49919 +#endif
49920 + filldir_t __filldir = filldir;
49921 struct tgid_iter iter;
49922 struct pid_namespace *ns;
49923
49924 @@ -3149,8 +3277,27 @@ int proc_pid_readdir(struct file * filp,
49925 for (iter = next_tgid(ns, iter);
49926 iter.task;
49927 iter.tgid += 1, iter = next_tgid(ns, iter)) {
49928 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49929 + rcu_read_lock();
49930 + itercred = __task_cred(iter.task);
49931 +#endif
49932 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
49933 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49934 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
49935 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49936 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49937 +#endif
49938 + )
49939 +#endif
49940 + )
49941 + __filldir = &gr_fake_filldir;
49942 + else
49943 + __filldir = filldir;
49944 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49945 + rcu_read_unlock();
49946 +#endif
49947 filp->f_pos = iter.tgid + TGID_OFFSET;
49948 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
49949 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
49950 put_task_struct(iter.task);
49951 goto out;
49952 }
49953 @@ -3177,7 +3324,7 @@ static const struct pid_entry tid_base_s
49954 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49955 #endif
49956 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49957 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49958 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49959 INF("syscall", S_IRUGO, proc_pid_syscall),
49960 #endif
49961 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49962 @@ -3201,10 +3348,10 @@ static const struct pid_entry tid_base_s
49963 #ifdef CONFIG_SECURITY
49964 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49965 #endif
49966 -#ifdef CONFIG_KALLSYMS
49967 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49968 INF("wchan", S_IRUGO, proc_pid_wchan),
49969 #endif
49970 -#ifdef CONFIG_STACKTRACE
49971 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49972 ONE("stack", S_IRUGO, proc_pid_stack),
49973 #endif
49974 #ifdef CONFIG_SCHEDSTATS
49975 diff -urNp linux-2.6.39.1/fs/proc/cmdline.c linux-2.6.39.1/fs/proc/cmdline.c
49976 --- linux-2.6.39.1/fs/proc/cmdline.c 2011-05-19 00:06:34.000000000 -0400
49977 +++ linux-2.6.39.1/fs/proc/cmdline.c 2011-05-22 19:41:37.000000000 -0400
49978 @@ -23,7 +23,11 @@ static const struct file_operations cmdl
49979
49980 static int __init proc_cmdline_init(void)
49981 {
49982 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49983 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49984 +#else
49985 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49986 +#endif
49987 return 0;
49988 }
49989 module_init(proc_cmdline_init);
49990 diff -urNp linux-2.6.39.1/fs/proc/devices.c linux-2.6.39.1/fs/proc/devices.c
49991 --- linux-2.6.39.1/fs/proc/devices.c 2011-05-19 00:06:34.000000000 -0400
49992 +++ linux-2.6.39.1/fs/proc/devices.c 2011-05-22 19:41:37.000000000 -0400
49993 @@ -64,7 +64,11 @@ static const struct file_operations proc
49994
49995 static int __init proc_devices_init(void)
49996 {
49997 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49998 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49999 +#else
50000 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50001 +#endif
50002 return 0;
50003 }
50004 module_init(proc_devices_init);
50005 diff -urNp linux-2.6.39.1/fs/proc/inode.c linux-2.6.39.1/fs/proc/inode.c
50006 --- linux-2.6.39.1/fs/proc/inode.c 2011-05-19 00:06:34.000000000 -0400
50007 +++ linux-2.6.39.1/fs/proc/inode.c 2011-05-22 19:41:37.000000000 -0400
50008 @@ -433,7 +433,11 @@ struct inode *proc_get_inode(struct supe
50009 if (de->mode) {
50010 inode->i_mode = de->mode;
50011 inode->i_uid = de->uid;
50012 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50013 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
50014 +#else
50015 inode->i_gid = de->gid;
50016 +#endif
50017 }
50018 if (de->size)
50019 inode->i_size = de->size;
50020 diff -urNp linux-2.6.39.1/fs/proc/internal.h linux-2.6.39.1/fs/proc/internal.h
50021 --- linux-2.6.39.1/fs/proc/internal.h 2011-05-19 00:06:34.000000000 -0400
50022 +++ linux-2.6.39.1/fs/proc/internal.h 2011-05-22 19:41:37.000000000 -0400
50023 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
50024 struct pid *pid, struct task_struct *task);
50025 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50026 struct pid *pid, struct task_struct *task);
50027 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50028 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50029 +#endif
50030 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50031
50032 extern const struct file_operations proc_maps_operations;
50033 diff -urNp linux-2.6.39.1/fs/proc/Kconfig linux-2.6.39.1/fs/proc/Kconfig
50034 --- linux-2.6.39.1/fs/proc/Kconfig 2011-05-19 00:06:34.000000000 -0400
50035 +++ linux-2.6.39.1/fs/proc/Kconfig 2011-05-22 19:41:37.000000000 -0400
50036 @@ -30,12 +30,12 @@ config PROC_FS
50037
50038 config PROC_KCORE
50039 bool "/proc/kcore support" if !ARM
50040 - depends on PROC_FS && MMU
50041 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50042
50043 config PROC_VMCORE
50044 bool "/proc/vmcore support"
50045 - depends on PROC_FS && CRASH_DUMP
50046 - default y
50047 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50048 + default n
50049 help
50050 Exports the dump image of crashed kernel in ELF format.
50051
50052 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50053 limited in memory.
50054
50055 config PROC_PAGE_MONITOR
50056 - default y
50057 - depends on PROC_FS && MMU
50058 + default n
50059 + depends on PROC_FS && MMU && !GRKERNSEC
50060 bool "Enable /proc page monitoring" if EXPERT
50061 help
50062 Various /proc files exist to monitor process memory utilization:
50063 diff -urNp linux-2.6.39.1/fs/proc/kcore.c linux-2.6.39.1/fs/proc/kcore.c
50064 --- linux-2.6.39.1/fs/proc/kcore.c 2011-05-19 00:06:34.000000000 -0400
50065 +++ linux-2.6.39.1/fs/proc/kcore.c 2011-05-22 19:41:37.000000000 -0400
50066 @@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
50067 off_t offset = 0;
50068 struct kcore_list *m;
50069
50070 + pax_track_stack();
50071 +
50072 /* setup ELF header */
50073 elf = (struct elfhdr *) bufp;
50074 bufp += sizeof(struct elfhdr);
50075 @@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
50076 * the addresses in the elf_phdr on our list.
50077 */
50078 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50079 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50080 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50081 + if (tsz > buflen)
50082 tsz = buflen;
50083 -
50084 +
50085 while (buflen) {
50086 struct kcore_list *m;
50087
50088 @@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
50089 kfree(elf_buf);
50090 } else {
50091 if (kern_addr_valid(start)) {
50092 - unsigned long n;
50093 + char *elf_buf;
50094 + mm_segment_t oldfs;
50095
50096 - n = copy_to_user(buffer, (char *)start, tsz);
50097 - /*
50098 - * We cannot distingush between fault on source
50099 - * and fault on destination. When this happens
50100 - * we clear too and hope it will trigger the
50101 - * EFAULT again.
50102 - */
50103 - if (n) {
50104 - if (clear_user(buffer + tsz - n,
50105 - n))
50106 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50107 + if (!elf_buf)
50108 + return -ENOMEM;
50109 + oldfs = get_fs();
50110 + set_fs(KERNEL_DS);
50111 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50112 + set_fs(oldfs);
50113 + if (copy_to_user(buffer, elf_buf, tsz)) {
50114 + kfree(elf_buf);
50115 return -EFAULT;
50116 + }
50117 }
50118 + set_fs(oldfs);
50119 + kfree(elf_buf);
50120 } else {
50121 if (clear_user(buffer, tsz))
50122 return -EFAULT;
50123 @@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
50124
50125 static int open_kcore(struct inode *inode, struct file *filp)
50126 {
50127 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50128 + return -EPERM;
50129 +#endif
50130 if (!capable(CAP_SYS_RAWIO))
50131 return -EPERM;
50132 if (kcore_need_update)
50133 diff -urNp linux-2.6.39.1/fs/proc/meminfo.c linux-2.6.39.1/fs/proc/meminfo.c
50134 --- linux-2.6.39.1/fs/proc/meminfo.c 2011-05-19 00:06:34.000000000 -0400
50135 +++ linux-2.6.39.1/fs/proc/meminfo.c 2011-05-22 19:36:32.000000000 -0400
50136 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
50137 unsigned long pages[NR_LRU_LISTS];
50138 int lru;
50139
50140 + pax_track_stack();
50141 +
50142 /*
50143 * display in kilobytes.
50144 */
50145 @@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
50146 vmi.used >> 10,
50147 vmi.largest_chunk >> 10
50148 #ifdef CONFIG_MEMORY_FAILURE
50149 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50150 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50151 #endif
50152 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50153 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50154 diff -urNp linux-2.6.39.1/fs/proc/nommu.c linux-2.6.39.1/fs/proc/nommu.c
50155 --- linux-2.6.39.1/fs/proc/nommu.c 2011-05-19 00:06:34.000000000 -0400
50156 +++ linux-2.6.39.1/fs/proc/nommu.c 2011-05-22 19:36:32.000000000 -0400
50157 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
50158 if (len < 1)
50159 len = 1;
50160 seq_printf(m, "%*c", len, ' ');
50161 - seq_path(m, &file->f_path, "");
50162 + seq_path(m, &file->f_path, "\n\\");
50163 }
50164
50165 seq_putc(m, '\n');
50166 diff -urNp linux-2.6.39.1/fs/proc/proc_net.c linux-2.6.39.1/fs/proc/proc_net.c
50167 --- linux-2.6.39.1/fs/proc/proc_net.c 2011-05-19 00:06:34.000000000 -0400
50168 +++ linux-2.6.39.1/fs/proc/proc_net.c 2011-05-22 19:41:37.000000000 -0400
50169 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
50170 struct task_struct *task;
50171 struct nsproxy *ns;
50172 struct net *net = NULL;
50173 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50174 + const struct cred *cred = current_cred();
50175 +#endif
50176 +
50177 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50178 + if (cred->fsuid)
50179 + return net;
50180 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50181 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
50182 + return net;
50183 +#endif
50184
50185 rcu_read_lock();
50186 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50187 diff -urNp linux-2.6.39.1/fs/proc/proc_sysctl.c linux-2.6.39.1/fs/proc/proc_sysctl.c
50188 --- linux-2.6.39.1/fs/proc/proc_sysctl.c 2011-05-19 00:06:34.000000000 -0400
50189 +++ linux-2.6.39.1/fs/proc/proc_sysctl.c 2011-05-22 19:41:37.000000000 -0400
50190 @@ -8,6 +8,8 @@
50191 #include <linux/namei.h>
50192 #include "internal.h"
50193
50194 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
50195 +
50196 static const struct dentry_operations proc_sys_dentry_operations;
50197 static const struct file_operations proc_sys_file_operations;
50198 static const struct inode_operations proc_sys_inode_operations;
50199 @@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
50200 if (!p)
50201 goto out;
50202
50203 + if (gr_handle_sysctl(p, MAY_EXEC))
50204 + goto out;
50205 +
50206 err = ERR_PTR(-ENOMEM);
50207 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
50208 if (h)
50209 @@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
50210 if (*pos < file->f_pos)
50211 continue;
50212
50213 + if (gr_handle_sysctl(table, 0))
50214 + continue;
50215 +
50216 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
50217 if (res)
50218 return res;
50219 @@ -358,6 +366,9 @@ static int proc_sys_getattr(struct vfsmo
50220 if (IS_ERR(head))
50221 return PTR_ERR(head);
50222
50223 + if (table && gr_handle_sysctl(table, MAY_EXEC))
50224 + return -ENOENT;
50225 +
50226 generic_fillattr(inode, stat);
50227 if (table)
50228 stat->mode = (stat->mode & S_IFMT) | table->mode;
50229 diff -urNp linux-2.6.39.1/fs/proc/root.c linux-2.6.39.1/fs/proc/root.c
50230 --- linux-2.6.39.1/fs/proc/root.c 2011-05-19 00:06:34.000000000 -0400
50231 +++ linux-2.6.39.1/fs/proc/root.c 2011-05-22 19:41:37.000000000 -0400
50232 @@ -122,7 +122,15 @@ void __init proc_root_init(void)
50233 #ifdef CONFIG_PROC_DEVICETREE
50234 proc_device_tree_init();
50235 #endif
50236 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50237 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50238 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50239 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50240 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50241 +#endif
50242 +#else
50243 proc_mkdir("bus", NULL);
50244 +#endif
50245 proc_sys_init();
50246 }
50247
50248 diff -urNp linux-2.6.39.1/fs/proc/task_mmu.c linux-2.6.39.1/fs/proc/task_mmu.c
50249 --- linux-2.6.39.1/fs/proc/task_mmu.c 2011-05-19 00:06:34.000000000 -0400
50250 +++ linux-2.6.39.1/fs/proc/task_mmu.c 2011-05-22 22:43:29.000000000 -0400
50251 @@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
50252 "VmExe:\t%8lu kB\n"
50253 "VmLib:\t%8lu kB\n"
50254 "VmPTE:\t%8lu kB\n"
50255 - "VmSwap:\t%8lu kB\n",
50256 - hiwater_vm << (PAGE_SHIFT-10),
50257 + "VmSwap:\t%8lu kB\n"
50258 +
50259 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50260 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50261 +#endif
50262 +
50263 + ,hiwater_vm << (PAGE_SHIFT-10),
50264 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50265 mm->locked_vm << (PAGE_SHIFT-10),
50266 hiwater_rss << (PAGE_SHIFT-10),
50267 @@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
50268 data << (PAGE_SHIFT-10),
50269 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50270 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50271 - swap << (PAGE_SHIFT-10));
50272 + swap << (PAGE_SHIFT-10)
50273 +
50274 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50275 + , mm->context.user_cs_base, mm->context.user_cs_limit
50276 +#endif
50277 +
50278 + );
50279 }
50280
50281 unsigned long task_vsize(struct mm_struct *mm)
50282 @@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
50283 return ret;
50284 }
50285
50286 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50287 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50288 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50289 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50290 +#endif
50291 +
50292 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
50293 {
50294 struct mm_struct *mm = vma->vm_mm;
50295 @@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
50296 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50297 }
50298
50299 - /* We don't show the stack guard page in /proc/maps */
50300 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50301 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50302 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50303 +#else
50304 start = vma->vm_start;
50305 - if (stack_guard_page_start(vma, start))
50306 - start += PAGE_SIZE;
50307 end = vma->vm_end;
50308 - if (stack_guard_page_end(vma, end))
50309 - end -= PAGE_SIZE;
50310 +#endif
50311
50312 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50313 start,
50314 @@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
50315 flags & VM_WRITE ? 'w' : '-',
50316 flags & VM_EXEC ? 'x' : '-',
50317 flags & VM_MAYSHARE ? 's' : 'p',
50318 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50319 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50320 +#else
50321 pgoff,
50322 +#endif
50323 MAJOR(dev), MINOR(dev), ino, &len);
50324
50325 /*
50326 @@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
50327 */
50328 if (file) {
50329 pad_len_spaces(m, len);
50330 - seq_path(m, &file->f_path, "\n");
50331 + seq_path(m, &file->f_path, "\n\\");
50332 } else {
50333 const char *name = arch_vma_name(vma);
50334 if (!name) {
50335 @@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
50336 if (vma->vm_start <= mm->brk &&
50337 vma->vm_end >= mm->start_brk) {
50338 name = "[heap]";
50339 - } else if (vma->vm_start <= mm->start_stack &&
50340 - vma->vm_end >= mm->start_stack) {
50341 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50342 + (vma->vm_start <= mm->start_stack &&
50343 + vma->vm_end >= mm->start_stack)) {
50344 name = "[stack]";
50345 }
50346 } else {
50347 @@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
50348 };
50349
50350 memset(&mss, 0, sizeof mss);
50351 - mss.vma = vma;
50352 - /* mmap_sem is held in m_start */
50353 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50354 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50355 -
50356 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50357 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50358 +#endif
50359 + mss.vma = vma;
50360 + /* mmap_sem is held in m_start */
50361 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50362 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50363 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50364 + }
50365 +#endif
50366 show_map_vma(m, vma);
50367
50368 seq_printf(m,
50369 @@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
50370 "KernelPageSize: %8lu kB\n"
50371 "MMUPageSize: %8lu kB\n"
50372 "Locked: %8lu kB\n",
50373 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50374 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50375 +#else
50376 (vma->vm_end - vma->vm_start) >> 10,
50377 +#endif
50378 mss.resident >> 10,
50379 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50380 mss.shared_clean >> 10,
50381 diff -urNp linux-2.6.39.1/fs/proc/task_nommu.c linux-2.6.39.1/fs/proc/task_nommu.c
50382 --- linux-2.6.39.1/fs/proc/task_nommu.c 2011-05-19 00:06:34.000000000 -0400
50383 +++ linux-2.6.39.1/fs/proc/task_nommu.c 2011-05-22 19:36:32.000000000 -0400
50384 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
50385 else
50386 bytes += kobjsize(mm);
50387
50388 - if (current->fs && current->fs->users > 1)
50389 + if (current->fs && atomic_read(&current->fs->users) > 1)
50390 sbytes += kobjsize(current->fs);
50391 else
50392 bytes += kobjsize(current->fs);
50393 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
50394
50395 if (file) {
50396 pad_len_spaces(m, len);
50397 - seq_path(m, &file->f_path, "");
50398 + seq_path(m, &file->f_path, "\n\\");
50399 } else if (mm) {
50400 if (vma->vm_start <= mm->start_stack &&
50401 vma->vm_end >= mm->start_stack) {
50402 diff -urNp linux-2.6.39.1/fs/quota/netlink.c linux-2.6.39.1/fs/quota/netlink.c
50403 --- linux-2.6.39.1/fs/quota/netlink.c 2011-05-19 00:06:34.000000000 -0400
50404 +++ linux-2.6.39.1/fs/quota/netlink.c 2011-05-22 19:36:32.000000000 -0400
50405 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
50406 void quota_send_warning(short type, unsigned int id, dev_t dev,
50407 const char warntype)
50408 {
50409 - static atomic_t seq;
50410 + static atomic_unchecked_t seq;
50411 struct sk_buff *skb;
50412 void *msg_head;
50413 int ret;
50414 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
50415 "VFS: Not enough memory to send quota warning.\n");
50416 return;
50417 }
50418 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50419 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50420 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50421 if (!msg_head) {
50422 printk(KERN_ERR
50423 diff -urNp linux-2.6.39.1/fs/readdir.c linux-2.6.39.1/fs/readdir.c
50424 --- linux-2.6.39.1/fs/readdir.c 2011-05-19 00:06:34.000000000 -0400
50425 +++ linux-2.6.39.1/fs/readdir.c 2011-05-22 19:41:42.000000000 -0400
50426 @@ -17,6 +17,7 @@
50427 #include <linux/security.h>
50428 #include <linux/syscalls.h>
50429 #include <linux/unistd.h>
50430 +#include <linux/namei.h>
50431
50432 #include <asm/uaccess.h>
50433
50434 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50435
50436 struct readdir_callback {
50437 struct old_linux_dirent __user * dirent;
50438 + struct file * file;
50439 int result;
50440 };
50441
50442 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
50443 buf->result = -EOVERFLOW;
50444 return -EOVERFLOW;
50445 }
50446 +
50447 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50448 + return 0;
50449 +
50450 buf->result++;
50451 dirent = buf->dirent;
50452 if (!access_ok(VERIFY_WRITE, dirent,
50453 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
50454
50455 buf.result = 0;
50456 buf.dirent = dirent;
50457 + buf.file = file;
50458
50459 error = vfs_readdir(file, fillonedir, &buf);
50460 if (buf.result)
50461 @@ -142,6 +149,7 @@ struct linux_dirent {
50462 struct getdents_callback {
50463 struct linux_dirent __user * current_dir;
50464 struct linux_dirent __user * previous;
50465 + struct file * file;
50466 int count;
50467 int error;
50468 };
50469 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
50470 buf->error = -EOVERFLOW;
50471 return -EOVERFLOW;
50472 }
50473 +
50474 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50475 + return 0;
50476 +
50477 dirent = buf->previous;
50478 if (dirent) {
50479 if (__put_user(offset, &dirent->d_off))
50480 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
50481 buf.previous = NULL;
50482 buf.count = count;
50483 buf.error = 0;
50484 + buf.file = file;
50485
50486 error = vfs_readdir(file, filldir, &buf);
50487 if (error >= 0)
50488 @@ -229,6 +242,7 @@ out:
50489 struct getdents_callback64 {
50490 struct linux_dirent64 __user * current_dir;
50491 struct linux_dirent64 __user * previous;
50492 + struct file *file;
50493 int count;
50494 int error;
50495 };
50496 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
50497 buf->error = -EINVAL; /* only used if we fail.. */
50498 if (reclen > buf->count)
50499 return -EINVAL;
50500 +
50501 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50502 + return 0;
50503 +
50504 dirent = buf->previous;
50505 if (dirent) {
50506 if (__put_user(offset, &dirent->d_off))
50507 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
50508
50509 buf.current_dir = dirent;
50510 buf.previous = NULL;
50511 + buf.file = file;
50512 buf.count = count;
50513 buf.error = 0;
50514
50515 diff -urNp linux-2.6.39.1/fs/reiserfs/dir.c linux-2.6.39.1/fs/reiserfs/dir.c
50516 --- linux-2.6.39.1/fs/reiserfs/dir.c 2011-05-19 00:06:34.000000000 -0400
50517 +++ linux-2.6.39.1/fs/reiserfs/dir.c 2011-05-22 19:36:32.000000000 -0400
50518 @@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
50519 struct reiserfs_dir_entry de;
50520 int ret = 0;
50521
50522 + pax_track_stack();
50523 +
50524 reiserfs_write_lock(inode->i_sb);
50525
50526 reiserfs_check_lock_depth(inode->i_sb, "readdir");
50527 diff -urNp linux-2.6.39.1/fs/reiserfs/do_balan.c linux-2.6.39.1/fs/reiserfs/do_balan.c
50528 --- linux-2.6.39.1/fs/reiserfs/do_balan.c 2011-05-19 00:06:34.000000000 -0400
50529 +++ linux-2.6.39.1/fs/reiserfs/do_balan.c 2011-05-22 19:36:32.000000000 -0400
50530 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
50531 return;
50532 }
50533
50534 - atomic_inc(&(fs_generation(tb->tb_sb)));
50535 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50536 do_balance_starts(tb);
50537
50538 /* balance leaf returns 0 except if combining L R and S into
50539 diff -urNp linux-2.6.39.1/fs/reiserfs/item_ops.c linux-2.6.39.1/fs/reiserfs/item_ops.c
50540 --- linux-2.6.39.1/fs/reiserfs/item_ops.c 2011-05-19 00:06:34.000000000 -0400
50541 +++ linux-2.6.39.1/fs/reiserfs/item_ops.c 2011-05-22 19:36:32.000000000 -0400
50542 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
50543 vi->vi_index, vi->vi_type, vi->vi_ih);
50544 }
50545
50546 -static struct item_operations stat_data_ops = {
50547 +static const struct item_operations stat_data_ops = {
50548 .bytes_number = sd_bytes_number,
50549 .decrement_key = sd_decrement_key,
50550 .is_left_mergeable = sd_is_left_mergeable,
50551 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
50552 vi->vi_index, vi->vi_type, vi->vi_ih);
50553 }
50554
50555 -static struct item_operations direct_ops = {
50556 +static const struct item_operations direct_ops = {
50557 .bytes_number = direct_bytes_number,
50558 .decrement_key = direct_decrement_key,
50559 .is_left_mergeable = direct_is_left_mergeable,
50560 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
50561 vi->vi_index, vi->vi_type, vi->vi_ih);
50562 }
50563
50564 -static struct item_operations indirect_ops = {
50565 +static const struct item_operations indirect_ops = {
50566 .bytes_number = indirect_bytes_number,
50567 .decrement_key = indirect_decrement_key,
50568 .is_left_mergeable = indirect_is_left_mergeable,
50569 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
50570 printk("\n");
50571 }
50572
50573 -static struct item_operations direntry_ops = {
50574 +static const struct item_operations direntry_ops = {
50575 .bytes_number = direntry_bytes_number,
50576 .decrement_key = direntry_decrement_key,
50577 .is_left_mergeable = direntry_is_left_mergeable,
50578 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
50579 "Invalid item type observed, run fsck ASAP");
50580 }
50581
50582 -static struct item_operations errcatch_ops = {
50583 +static const struct item_operations errcatch_ops = {
50584 errcatch_bytes_number,
50585 errcatch_decrement_key,
50586 errcatch_is_left_mergeable,
50587 @@ -746,7 +746,7 @@ static struct item_operations errcatch_o
50588 #error Item types must use disk-format assigned values.
50589 #endif
50590
50591 -struct item_operations *item_ops[TYPE_ANY + 1] = {
50592 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
50593 &stat_data_ops,
50594 &indirect_ops,
50595 &direct_ops,
50596 diff -urNp linux-2.6.39.1/fs/reiserfs/journal.c linux-2.6.39.1/fs/reiserfs/journal.c
50597 --- linux-2.6.39.1/fs/reiserfs/journal.c 2011-05-19 00:06:34.000000000 -0400
50598 +++ linux-2.6.39.1/fs/reiserfs/journal.c 2011-05-22 19:36:32.000000000 -0400
50599 @@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
50600 struct buffer_head *bh;
50601 int i, j;
50602
50603 + pax_track_stack();
50604 +
50605 bh = __getblk(dev, block, bufsize);
50606 if (buffer_uptodate(bh))
50607 return (bh);
50608 diff -urNp linux-2.6.39.1/fs/reiserfs/namei.c linux-2.6.39.1/fs/reiserfs/namei.c
50609 --- linux-2.6.39.1/fs/reiserfs/namei.c 2011-05-19 00:06:34.000000000 -0400
50610 +++ linux-2.6.39.1/fs/reiserfs/namei.c 2011-05-22 19:36:32.000000000 -0400
50611 @@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
50612 unsigned long savelink = 1;
50613 struct timespec ctime;
50614
50615 + pax_track_stack();
50616 +
50617 /* three balancings: (1) old name removal, (2) new name insertion
50618 and (3) maybe "save" link insertion
50619 stat data updates: (1) old directory,
50620 diff -urNp linux-2.6.39.1/fs/reiserfs/procfs.c linux-2.6.39.1/fs/reiserfs/procfs.c
50621 --- linux-2.6.39.1/fs/reiserfs/procfs.c 2011-05-19 00:06:34.000000000 -0400
50622 +++ linux-2.6.39.1/fs/reiserfs/procfs.c 2011-05-22 19:36:32.000000000 -0400
50623 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
50624 "SMALL_TAILS " : "NO_TAILS ",
50625 replay_only(sb) ? "REPLAY_ONLY " : "",
50626 convert_reiserfs(sb) ? "CONV " : "",
50627 - atomic_read(&r->s_generation_counter),
50628 + atomic_read_unchecked(&r->s_generation_counter),
50629 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50630 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50631 SF(s_good_search_by_key_reada), SF(s_bmaps),
50632 @@ -299,6 +299,8 @@ static int show_journal(struct seq_file
50633 struct journal_params *jp = &rs->s_v1.s_journal;
50634 char b[BDEVNAME_SIZE];
50635
50636 + pax_track_stack();
50637 +
50638 seq_printf(m, /* on-disk fields */
50639 "jp_journal_1st_block: \t%i\n"
50640 "jp_journal_dev: \t%s[%x]\n"
50641 diff -urNp linux-2.6.39.1/fs/reiserfs/stree.c linux-2.6.39.1/fs/reiserfs/stree.c
50642 --- linux-2.6.39.1/fs/reiserfs/stree.c 2011-05-19 00:06:34.000000000 -0400
50643 +++ linux-2.6.39.1/fs/reiserfs/stree.c 2011-05-22 19:36:32.000000000 -0400
50644 @@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
50645 int iter = 0;
50646 #endif
50647
50648 + pax_track_stack();
50649 +
50650 BUG_ON(!th->t_trans_id);
50651
50652 init_tb_struct(th, &s_del_balance, sb, path,
50653 @@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
50654 int retval;
50655 int quota_cut_bytes = 0;
50656
50657 + pax_track_stack();
50658 +
50659 BUG_ON(!th->t_trans_id);
50660
50661 le_key2cpu_key(&cpu_key, key);
50662 @@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
50663 int quota_cut_bytes;
50664 loff_t tail_pos = 0;
50665
50666 + pax_track_stack();
50667 +
50668 BUG_ON(!th->t_trans_id);
50669
50670 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
50671 @@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
50672 int retval;
50673 int fs_gen;
50674
50675 + pax_track_stack();
50676 +
50677 BUG_ON(!th->t_trans_id);
50678
50679 fs_gen = get_generation(inode->i_sb);
50680 @@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
50681 int fs_gen = 0;
50682 int quota_bytes = 0;
50683
50684 + pax_track_stack();
50685 +
50686 BUG_ON(!th->t_trans_id);
50687
50688 if (inode) { /* Do we count quotas for item? */
50689 diff -urNp linux-2.6.39.1/fs/reiserfs/super.c linux-2.6.39.1/fs/reiserfs/super.c
50690 --- linux-2.6.39.1/fs/reiserfs/super.c 2011-05-19 00:06:34.000000000 -0400
50691 +++ linux-2.6.39.1/fs/reiserfs/super.c 2011-05-22 19:36:32.000000000 -0400
50692 @@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
50693 {.option_name = NULL}
50694 };
50695
50696 + pax_track_stack();
50697 +
50698 *blocks = 0;
50699 if (!options || !*options)
50700 /* use default configuration: create tails, journaling on, no
50701 diff -urNp linux-2.6.39.1/fs/select.c linux-2.6.39.1/fs/select.c
50702 --- linux-2.6.39.1/fs/select.c 2011-05-19 00:06:34.000000000 -0400
50703 +++ linux-2.6.39.1/fs/select.c 2011-05-22 19:41:42.000000000 -0400
50704 @@ -20,6 +20,7 @@
50705 #include <linux/module.h>
50706 #include <linux/slab.h>
50707 #include <linux/poll.h>
50708 +#include <linux/security.h>
50709 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50710 #include <linux/file.h>
50711 #include <linux/fdtable.h>
50712 @@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
50713 int retval, i, timed_out = 0;
50714 unsigned long slack = 0;
50715
50716 + pax_track_stack();
50717 +
50718 rcu_read_lock();
50719 retval = max_select_fd(n, fds);
50720 rcu_read_unlock();
50721 @@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
50722 /* Allocate small arguments on the stack to save memory and be faster */
50723 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
50724
50725 + pax_track_stack();
50726 +
50727 ret = -EINVAL;
50728 if (n < 0)
50729 goto out_nofds;
50730 @@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
50731 struct poll_list *walk = head;
50732 unsigned long todo = nfds;
50733
50734 + pax_track_stack();
50735 +
50736 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50737 if (nfds > rlimit(RLIMIT_NOFILE))
50738 return -EINVAL;
50739
50740 diff -urNp linux-2.6.39.1/fs/seq_file.c linux-2.6.39.1/fs/seq_file.c
50741 --- linux-2.6.39.1/fs/seq_file.c 2011-05-19 00:06:34.000000000 -0400
50742 +++ linux-2.6.39.1/fs/seq_file.c 2011-05-22 19:36:32.000000000 -0400
50743 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
50744 return 0;
50745 }
50746 if (!m->buf) {
50747 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50748 + m->size = PAGE_SIZE;
50749 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50750 if (!m->buf)
50751 return -ENOMEM;
50752 }
50753 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
50754 Eoverflow:
50755 m->op->stop(m, p);
50756 kfree(m->buf);
50757 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50758 + m->size <<= 1;
50759 + m->buf = kmalloc(m->size, GFP_KERNEL);
50760 return !m->buf ? -ENOMEM : -EAGAIN;
50761 }
50762
50763 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
50764 m->version = file->f_version;
50765 /* grab buffer if we didn't have one */
50766 if (!m->buf) {
50767 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50768 + m->size = PAGE_SIZE;
50769 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50770 if (!m->buf)
50771 goto Enomem;
50772 }
50773 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
50774 goto Fill;
50775 m->op->stop(m, p);
50776 kfree(m->buf);
50777 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50778 + m->size <<= 1;
50779 + m->buf = kmalloc(m->size, GFP_KERNEL);
50780 if (!m->buf)
50781 goto Enomem;
50782 m->count = 0;
50783 diff -urNp linux-2.6.39.1/fs/splice.c linux-2.6.39.1/fs/splice.c
50784 --- linux-2.6.39.1/fs/splice.c 2011-05-19 00:06:34.000000000 -0400
50785 +++ linux-2.6.39.1/fs/splice.c 2011-05-22 19:36:32.000000000 -0400
50786 @@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
50787 pipe_lock(pipe);
50788
50789 for (;;) {
50790 - if (!pipe->readers) {
50791 + if (!atomic_read(&pipe->readers)) {
50792 send_sig(SIGPIPE, current, 0);
50793 if (!ret)
50794 ret = -EPIPE;
50795 @@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
50796 do_wakeup = 0;
50797 }
50798
50799 - pipe->waiting_writers++;
50800 + atomic_inc(&pipe->waiting_writers);
50801 pipe_wait(pipe);
50802 - pipe->waiting_writers--;
50803 + atomic_dec(&pipe->waiting_writers);
50804 }
50805
50806 pipe_unlock(pipe);
50807 @@ -316,6 +316,8 @@ __generic_file_splice_read(struct file *
50808 .spd_release = spd_release_page,
50809 };
50810
50811 + pax_track_stack();
50812 +
50813 if (splice_grow_spd(pipe, &spd))
50814 return -ENOMEM;
50815
50816 @@ -556,7 +558,7 @@ static ssize_t kernel_readv(struct file
50817 old_fs = get_fs();
50818 set_fs(get_ds());
50819 /* The cast to a user pointer is valid due to the set_fs() */
50820 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50821 + res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
50822 set_fs(old_fs);
50823
50824 return res;
50825 @@ -571,7 +573,7 @@ static ssize_t kernel_write(struct file
50826 old_fs = get_fs();
50827 set_fs(get_ds());
50828 /* The cast to a user pointer is valid due to the set_fs() */
50829 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50830 + res = vfs_write(file, (__force const char __user *)buf, count, &pos);
50831 set_fs(old_fs);
50832
50833 return res;
50834 @@ -599,6 +601,8 @@ ssize_t default_file_splice_read(struct
50835 .spd_release = spd_release_page,
50836 };
50837
50838 + pax_track_stack();
50839 +
50840 if (splice_grow_spd(pipe, &spd))
50841 return -ENOMEM;
50842
50843 @@ -622,7 +626,7 @@ ssize_t default_file_splice_read(struct
50844 goto err;
50845
50846 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50847 - vec[i].iov_base = (void __user *) page_address(page);
50848 + vec[i].iov_base = (__force void __user *) page_address(page);
50849 vec[i].iov_len = this_len;
50850 spd.pages[i] = page;
50851 spd.nr_pages++;
50852 @@ -842,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50853 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50854 {
50855 while (!pipe->nrbufs) {
50856 - if (!pipe->writers)
50857 + if (!atomic_read(&pipe->writers))
50858 return 0;
50859
50860 - if (!pipe->waiting_writers && sd->num_spliced)
50861 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50862 return 0;
50863
50864 if (sd->flags & SPLICE_F_NONBLOCK)
50865 @@ -1178,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct fi
50866 * out of the pipe right after the splice_to_pipe(). So set
50867 * PIPE_READERS appropriately.
50868 */
50869 - pipe->readers = 1;
50870 + atomic_set(&pipe->readers, 1);
50871
50872 current->splice_pipe = pipe;
50873 }
50874 @@ -1615,6 +1619,8 @@ static long vmsplice_to_pipe(struct file
50875 };
50876 long ret;
50877
50878 + pax_track_stack();
50879 +
50880 pipe = get_pipe_info(file);
50881 if (!pipe)
50882 return -EBADF;
50883 @@ -1730,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_
50884 ret = -ERESTARTSYS;
50885 break;
50886 }
50887 - if (!pipe->writers)
50888 + if (!atomic_read(&pipe->writers))
50889 break;
50890 - if (!pipe->waiting_writers) {
50891 + if (!atomic_read(&pipe->waiting_writers)) {
50892 if (flags & SPLICE_F_NONBLOCK) {
50893 ret = -EAGAIN;
50894 break;
50895 @@ -1764,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_
50896 pipe_lock(pipe);
50897
50898 while (pipe->nrbufs >= pipe->buffers) {
50899 - if (!pipe->readers) {
50900 + if (!atomic_read(&pipe->readers)) {
50901 send_sig(SIGPIPE, current, 0);
50902 ret = -EPIPE;
50903 break;
50904 @@ -1777,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_
50905 ret = -ERESTARTSYS;
50906 break;
50907 }
50908 - pipe->waiting_writers++;
50909 + atomic_inc(&pipe->waiting_writers);
50910 pipe_wait(pipe);
50911 - pipe->waiting_writers--;
50912 + atomic_dec(&pipe->waiting_writers);
50913 }
50914
50915 pipe_unlock(pipe);
50916 @@ -1815,14 +1821,14 @@ retry:
50917 pipe_double_lock(ipipe, opipe);
50918
50919 do {
50920 - if (!opipe->readers) {
50921 + if (!atomic_read(&opipe->readers)) {
50922 send_sig(SIGPIPE, current, 0);
50923 if (!ret)
50924 ret = -EPIPE;
50925 break;
50926 }
50927
50928 - if (!ipipe->nrbufs && !ipipe->writers)
50929 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50930 break;
50931
50932 /*
50933 @@ -1922,7 +1928,7 @@ static int link_pipe(struct pipe_inode_i
50934 pipe_double_lock(ipipe, opipe);
50935
50936 do {
50937 - if (!opipe->readers) {
50938 + if (!atomic_read(&opipe->readers)) {
50939 send_sig(SIGPIPE, current, 0);
50940 if (!ret)
50941 ret = -EPIPE;
50942 @@ -1967,7 +1973,7 @@ static int link_pipe(struct pipe_inode_i
50943 * return EAGAIN if we have the potential of some data in the
50944 * future, otherwise just return 0
50945 */
50946 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50947 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50948 ret = -EAGAIN;
50949
50950 pipe_unlock(ipipe);
50951 diff -urNp linux-2.6.39.1/fs/sysfs/file.c linux-2.6.39.1/fs/sysfs/file.c
50952 --- linux-2.6.39.1/fs/sysfs/file.c 2011-05-19 00:06:34.000000000 -0400
50953 +++ linux-2.6.39.1/fs/sysfs/file.c 2011-05-22 19:36:32.000000000 -0400
50954 @@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
50955
50956 struct sysfs_open_dirent {
50957 atomic_t refcnt;
50958 - atomic_t event;
50959 + atomic_unchecked_t event;
50960 wait_queue_head_t poll;
50961 struct list_head buffers; /* goes through sysfs_buffer.list */
50962 };
50963 @@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
50964 if (!sysfs_get_active(attr_sd))
50965 return -ENODEV;
50966
50967 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50968 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50969 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50970
50971 sysfs_put_active(attr_sd);
50972 @@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
50973 return -ENOMEM;
50974
50975 atomic_set(&new_od->refcnt, 0);
50976 - atomic_set(&new_od->event, 1);
50977 + atomic_set_unchecked(&new_od->event, 1);
50978 init_waitqueue_head(&new_od->poll);
50979 INIT_LIST_HEAD(&new_od->buffers);
50980 goto retry;
50981 @@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
50982
50983 sysfs_put_active(attr_sd);
50984
50985 - if (buffer->event != atomic_read(&od->event))
50986 + if (buffer->event != atomic_read_unchecked(&od->event))
50987 goto trigger;
50988
50989 return DEFAULT_POLLMASK;
50990 @@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
50991
50992 od = sd->s_attr.open;
50993 if (od) {
50994 - atomic_inc(&od->event);
50995 + atomic_inc_unchecked(&od->event);
50996 wake_up_interruptible(&od->poll);
50997 }
50998
50999 diff -urNp linux-2.6.39.1/fs/sysfs/mount.c linux-2.6.39.1/fs/sysfs/mount.c
51000 --- linux-2.6.39.1/fs/sysfs/mount.c 2011-05-19 00:06:34.000000000 -0400
51001 +++ linux-2.6.39.1/fs/sysfs/mount.c 2011-05-22 19:41:42.000000000 -0400
51002 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
51003 .s_name = "",
51004 .s_count = ATOMIC_INIT(1),
51005 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
51006 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51007 + .s_mode = S_IFDIR | S_IRWXU,
51008 +#else
51009 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
51010 +#endif
51011 .s_ino = 1,
51012 };
51013
51014 diff -urNp linux-2.6.39.1/fs/sysfs/symlink.c linux-2.6.39.1/fs/sysfs/symlink.c
51015 --- linux-2.6.39.1/fs/sysfs/symlink.c 2011-05-19 00:06:34.000000000 -0400
51016 +++ linux-2.6.39.1/fs/sysfs/symlink.c 2011-05-22 19:36:32.000000000 -0400
51017 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
51018
51019 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
51020 {
51021 - char *page = nd_get_link(nd);
51022 + const char *page = nd_get_link(nd);
51023 if (!IS_ERR(page))
51024 free_page((unsigned long)page);
51025 }
51026 diff -urNp linux-2.6.39.1/fs/udf/inode.c linux-2.6.39.1/fs/udf/inode.c
51027 --- linux-2.6.39.1/fs/udf/inode.c 2011-05-19 00:06:34.000000000 -0400
51028 +++ linux-2.6.39.1/fs/udf/inode.c 2011-05-22 19:36:32.000000000 -0400
51029 @@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
51030 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
51031 int lastblock = 0;
51032
51033 + pax_track_stack();
51034 +
51035 prev_epos.offset = udf_file_entry_alloc_offset(inode);
51036 prev_epos.block = iinfo->i_location;
51037 prev_epos.bh = NULL;
51038 diff -urNp linux-2.6.39.1/fs/udf/misc.c linux-2.6.39.1/fs/udf/misc.c
51039 --- linux-2.6.39.1/fs/udf/misc.c 2011-05-19 00:06:34.000000000 -0400
51040 +++ linux-2.6.39.1/fs/udf/misc.c 2011-05-22 19:36:32.000000000 -0400
51041 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
51042
51043 u8 udf_tag_checksum(const struct tag *t)
51044 {
51045 - u8 *data = (u8 *)t;
51046 + const u8 *data = (const u8 *)t;
51047 u8 checksum = 0;
51048 int i;
51049 for (i = 0; i < sizeof(struct tag); ++i)
51050 diff -urNp linux-2.6.39.1/fs/utimes.c linux-2.6.39.1/fs/utimes.c
51051 --- linux-2.6.39.1/fs/utimes.c 2011-05-19 00:06:34.000000000 -0400
51052 +++ linux-2.6.39.1/fs/utimes.c 2011-05-22 19:41:42.000000000 -0400
51053 @@ -1,6 +1,7 @@
51054 #include <linux/compiler.h>
51055 #include <linux/file.h>
51056 #include <linux/fs.h>
51057 +#include <linux/security.h>
51058 #include <linux/linkage.h>
51059 #include <linux/mount.h>
51060 #include <linux/namei.h>
51061 @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
51062 goto mnt_drop_write_and_out;
51063 }
51064 }
51065 +
51066 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51067 + error = -EACCES;
51068 + goto mnt_drop_write_and_out;
51069 + }
51070 +
51071 mutex_lock(&inode->i_mutex);
51072 error = notify_change(path->dentry, &newattrs);
51073 mutex_unlock(&inode->i_mutex);
51074 diff -urNp linux-2.6.39.1/fs/xattr_acl.c linux-2.6.39.1/fs/xattr_acl.c
51075 --- linux-2.6.39.1/fs/xattr_acl.c 2011-05-19 00:06:34.000000000 -0400
51076 +++ linux-2.6.39.1/fs/xattr_acl.c 2011-05-22 19:36:32.000000000 -0400
51077 @@ -17,8 +17,8 @@
51078 struct posix_acl *
51079 posix_acl_from_xattr(const void *value, size_t size)
51080 {
51081 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51082 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51083 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51084 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51085 int count;
51086 struct posix_acl *acl;
51087 struct posix_acl_entry *acl_e;
51088 diff -urNp linux-2.6.39.1/fs/xattr.c linux-2.6.39.1/fs/xattr.c
51089 --- linux-2.6.39.1/fs/xattr.c 2011-05-19 00:06:34.000000000 -0400
51090 +++ linux-2.6.39.1/fs/xattr.c 2011-05-22 19:41:42.000000000 -0400
51091 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51092 * Extended attribute SET operations
51093 */
51094 static long
51095 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51096 +setxattr(struct path *path, const char __user *name, const void __user *value,
51097 size_t size, int flags)
51098 {
51099 int error;
51100 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
51101 return PTR_ERR(kvalue);
51102 }
51103
51104 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51105 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51106 + error = -EACCES;
51107 + goto out;
51108 + }
51109 +
51110 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51111 +out:
51112 kfree(kvalue);
51113 return error;
51114 }
51115 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
51116 return error;
51117 error = mnt_want_write(path.mnt);
51118 if (!error) {
51119 - error = setxattr(path.dentry, name, value, size, flags);
51120 + error = setxattr(&path, name, value, size, flags);
51121 mnt_drop_write(path.mnt);
51122 }
51123 path_put(&path);
51124 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
51125 return error;
51126 error = mnt_want_write(path.mnt);
51127 if (!error) {
51128 - error = setxattr(path.dentry, name, value, size, flags);
51129 + error = setxattr(&path, name, value, size, flags);
51130 mnt_drop_write(path.mnt);
51131 }
51132 path_put(&path);
51133 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
51134 const void __user *,value, size_t, size, int, flags)
51135 {
51136 struct file *f;
51137 - struct dentry *dentry;
51138 int error = -EBADF;
51139
51140 f = fget(fd);
51141 if (!f)
51142 return error;
51143 - dentry = f->f_path.dentry;
51144 - audit_inode(NULL, dentry);
51145 + audit_inode(NULL, f->f_path.dentry);
51146 error = mnt_want_write_file(f);
51147 if (!error) {
51148 - error = setxattr(dentry, name, value, size, flags);
51149 + error = setxattr(&f->f_path, name, value, size, flags);
51150 mnt_drop_write(f->f_path.mnt);
51151 }
51152 fput(f);
51153 diff -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
51154 --- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-19 00:06:34.000000000 -0400
51155 +++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-22 19:41:42.000000000 -0400
51156 @@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
51157 xfs_fsop_geom_t fsgeo;
51158 int error;
51159
51160 + memset(&fsgeo, 0, sizeof(fsgeo));
51161 error = xfs_fs_geometry(mp, &fsgeo, 3);
51162 if (error)
51163 return -error;
51164 diff -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
51165 --- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-19 00:06:34.000000000 -0400
51166 +++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-22 19:36:32.000000000 -0400
51167 @@ -128,7 +128,7 @@ xfs_find_handle(
51168 }
51169
51170 error = -EFAULT;
51171 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51172 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51173 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51174 goto out_put;
51175
51176 diff -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
51177 --- linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c 2011-05-19 00:06:34.000000000 -0400
51178 +++ linux-2.6.39.1/fs/xfs/linux-2.6/xfs_iops.c 2011-05-22 19:36:32.000000000 -0400
51179 @@ -437,7 +437,7 @@ xfs_vn_put_link(
51180 struct nameidata *nd,
51181 void *p)
51182 {
51183 - char *s = nd_get_link(nd);
51184 + const char *s = nd_get_link(nd);
51185
51186 if (!IS_ERR(s))
51187 kfree(s);
51188 diff -urNp linux-2.6.39.1/fs/xfs/xfs_bmap.c linux-2.6.39.1/fs/xfs/xfs_bmap.c
51189 --- linux-2.6.39.1/fs/xfs/xfs_bmap.c 2011-05-19 00:06:34.000000000 -0400
51190 +++ linux-2.6.39.1/fs/xfs/xfs_bmap.c 2011-05-22 19:36:32.000000000 -0400
51191 @@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
51192 int nmap,
51193 int ret_nmap);
51194 #else
51195 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51196 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51197 #endif /* DEBUG */
51198
51199 STATIC int
51200 diff -urNp linux-2.6.39.1/fs/xfs/xfs_dir2.c linux-2.6.39.1/fs/xfs/xfs_dir2.c
51201 --- linux-2.6.39.1/fs/xfs/xfs_dir2.c 2011-05-19 00:06:34.000000000 -0400
51202 +++ linux-2.6.39.1/fs/xfs/xfs_dir2.c 2011-05-22 19:36:32.000000000 -0400
51203 @@ -85,7 +85,7 @@ xfs_ascii_ci_compname(
51204 return result;
51205 }
51206
51207 -static struct xfs_nameops xfs_ascii_ci_nameops = {
51208 +static const struct xfs_nameops xfs_ascii_ci_nameops = {
51209 .hashname = xfs_ascii_ci_hashname,
51210 .compname = xfs_ascii_ci_compname,
51211 };
51212 diff -urNp linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c
51213 --- linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c 2011-05-19 00:06:34.000000000 -0400
51214 +++ linux-2.6.39.1/fs/xfs/xfs_dir2_sf.c 2011-05-22 19:36:32.000000000 -0400
51215 @@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
51216 }
51217
51218 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
51219 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51220 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51221 + char name[sfep->namelen];
51222 + memcpy(name, sfep->name, sfep->namelen);
51223 + if (filldir(dirent, name, sfep->namelen,
51224 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51225 + *offset = off & 0x7fffffff;
51226 + return 0;
51227 + }
51228 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51229 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51230 *offset = off & 0x7fffffff;
51231 return 0;
51232 diff -urNp linux-2.6.39.1/grsecurity/gracl_alloc.c linux-2.6.39.1/grsecurity/gracl_alloc.c
51233 --- linux-2.6.39.1/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
51234 +++ linux-2.6.39.1/grsecurity/gracl_alloc.c 2011-05-22 19:41:42.000000000 -0400
51235 @@ -0,0 +1,105 @@
51236 +#include <linux/kernel.h>
51237 +#include <linux/mm.h>
51238 +#include <linux/slab.h>
51239 +#include <linux/vmalloc.h>
51240 +#include <linux/gracl.h>
51241 +#include <linux/grsecurity.h>
51242 +
51243 +static unsigned long alloc_stack_next = 1;
51244 +static unsigned long alloc_stack_size = 1;
51245 +static void **alloc_stack;
51246 +
51247 +static __inline__ int
51248 +alloc_pop(void)
51249 +{
51250 + if (alloc_stack_next == 1)
51251 + return 0;
51252 +
51253 + kfree(alloc_stack[alloc_stack_next - 2]);
51254 +
51255 + alloc_stack_next--;
51256 +
51257 + return 1;
51258 +}
51259 +
51260 +static __inline__ int
51261 +alloc_push(void *buf)
51262 +{
51263 + if (alloc_stack_next >= alloc_stack_size)
51264 + return 1;
51265 +
51266 + alloc_stack[alloc_stack_next - 1] = buf;
51267 +
51268 + alloc_stack_next++;
51269 +
51270 + return 0;
51271 +}
51272 +
51273 +void *
51274 +acl_alloc(unsigned long len)
51275 +{
51276 + void *ret = NULL;
51277 +
51278 + if (!len || len > PAGE_SIZE)
51279 + goto out;
51280 +
51281 + ret = kmalloc(len, GFP_KERNEL);
51282 +
51283 + if (ret) {
51284 + if (alloc_push(ret)) {
51285 + kfree(ret);
51286 + ret = NULL;
51287 + }
51288 + }
51289 +
51290 +out:
51291 + return ret;
51292 +}
51293 +
51294 +void *
51295 +acl_alloc_num(unsigned long num, unsigned long len)
51296 +{
51297 + if (!len || (num > (PAGE_SIZE / len)))
51298 + return NULL;
51299 +
51300 + return acl_alloc(num * len);
51301 +}
51302 +
51303 +void
51304 +acl_free_all(void)
51305 +{
51306 + if (gr_acl_is_enabled() || !alloc_stack)
51307 + return;
51308 +
51309 + while (alloc_pop()) ;
51310 +
51311 + if (alloc_stack) {
51312 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
51313 + kfree(alloc_stack);
51314 + else
51315 + vfree(alloc_stack);
51316 + }
51317 +
51318 + alloc_stack = NULL;
51319 + alloc_stack_size = 1;
51320 + alloc_stack_next = 1;
51321 +
51322 + return;
51323 +}
51324 +
51325 +int
51326 +acl_alloc_stack_init(unsigned long size)
51327 +{
51328 + if ((size * sizeof (void *)) <= PAGE_SIZE)
51329 + alloc_stack =
51330 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
51331 + else
51332 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
51333 +
51334 + alloc_stack_size = size;
51335 +
51336 + if (!alloc_stack)
51337 + return 0;
51338 + else
51339 + return 1;
51340 +}
51341 diff -urNp linux-2.6.39.1/grsecurity/gracl.c linux-2.6.39.1/grsecurity/gracl.c
51342 --- linux-2.6.39.1/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
51343 +++ linux-2.6.39.1/grsecurity/gracl.c 2011-05-24 20:27:30.000000000 -0400
51344 @@ -0,0 +1,4103 @@
51345 +#include <linux/kernel.h>
51346 +#include <linux/module.h>
51347 +#include <linux/sched.h>
51348 +#include <linux/mm.h>
51349 +#include <linux/file.h>
51350 +#include <linux/fs.h>
51351 +#include <linux/namei.h>
51352 +#include <linux/mount.h>
51353 +#include <linux/tty.h>
51354 +#include <linux/proc_fs.h>
51355 +#include <linux/lglock.h>
51356 +#include <linux/slab.h>
51357 +#include <linux/vmalloc.h>
51358 +#include <linux/types.h>
51359 +#include <linux/sysctl.h>
51360 +#include <linux/netdevice.h>
51361 +#include <linux/ptrace.h>
51362 +#include <linux/gracl.h>
51363 +#include <linux/gralloc.h>
51364 +#include <linux/grsecurity.h>
51365 +#include <linux/grinternal.h>
51366 +#include <linux/pid_namespace.h>
51367 +#include <linux/fdtable.h>
51368 +#include <linux/percpu.h>
51369 +
51370 +#include <asm/uaccess.h>
51371 +#include <asm/errno.h>
51372 +#include <asm/mman.h>
51373 +
51374 +static struct acl_role_db acl_role_set;
51375 +static struct name_db name_set;
51376 +static struct inodev_db inodev_set;
51377 +
51378 +/* for keeping track of userspace pointers used for subjects, so we
51379 + can share references in the kernel as well
51380 +*/
51381 +
51382 +static struct path real_root;
51383 +
51384 +static struct acl_subj_map_db subj_map_set;
51385 +
51386 +static struct acl_role_label *default_role;
51387 +
51388 +static struct acl_role_label *role_list;
51389 +
51390 +static u16 acl_sp_role_value;
51391 +
51392 +extern char *gr_shared_page[4];
51393 +static DEFINE_MUTEX(gr_dev_mutex);
51394 +DEFINE_RWLOCK(gr_inode_lock);
51395 +
51396 +struct gr_arg *gr_usermode;
51397 +
51398 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51399 +
51400 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51401 +extern void gr_clear_learn_entries(void);
51402 +
51403 +#ifdef CONFIG_GRKERNSEC_RESLOG
51404 +extern void gr_log_resource(const struct task_struct *task,
51405 + const int res, const unsigned long wanted, const int gt);
51406 +#endif
51407 +
51408 +unsigned char *gr_system_salt;
51409 +unsigned char *gr_system_sum;
51410 +
51411 +static struct sprole_pw **acl_special_roles = NULL;
51412 +static __u16 num_sprole_pws = 0;
51413 +
51414 +static struct acl_role_label *kernel_role = NULL;
51415 +
51416 +static unsigned int gr_auth_attempts = 0;
51417 +static unsigned long gr_auth_expires = 0UL;
51418 +
51419 +#ifdef CONFIG_NET
51420 +extern struct vfsmount *sock_mnt;
51421 +#endif
51422 +
51423 +extern struct vfsmount *pipe_mnt;
51424 +extern struct vfsmount *shm_mnt;
51425 +#ifdef CONFIG_HUGETLBFS
51426 +extern struct vfsmount *hugetlbfs_vfsmount;
51427 +#endif
51428 +
51429 +static struct acl_object_label *fakefs_obj;
51430 +
51431 +extern int gr_init_uidset(void);
51432 +extern void gr_free_uidset(void);
51433 +extern void gr_remove_uid(uid_t uid);
51434 +extern int gr_find_uid(uid_t uid);
51435 +
51436 +DECLARE_BRLOCK(vfsmount_lock);
51437 +
51438 +__inline__ int
51439 +gr_acl_is_enabled(void)
51440 +{
51441 + return (gr_status & GR_READY);
51442 +}
51443 +
51444 +#ifdef CONFIG_BTRFS_FS
51445 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51446 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51447 +#endif
51448 +
51449 +static inline dev_t __get_dev(const struct dentry *dentry)
51450 +{
51451 +#ifdef CONFIG_BTRFS_FS
51452 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51453 + return get_btrfs_dev_from_inode(dentry->d_inode);
51454 + else
51455 +#endif
51456 + return dentry->d_inode->i_sb->s_dev;
51457 +}
51458 +
51459 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51460 +{
51461 + return __get_dev(dentry);
51462 +}
51463 +
51464 +static char gr_task_roletype_to_char(struct task_struct *task)
51465 +{
51466 + switch (task->role->roletype &
51467 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51468 + GR_ROLE_SPECIAL)) {
51469 + case GR_ROLE_DEFAULT:
51470 + return 'D';
51471 + case GR_ROLE_USER:
51472 + return 'U';
51473 + case GR_ROLE_GROUP:
51474 + return 'G';
51475 + case GR_ROLE_SPECIAL:
51476 + return 'S';
51477 + }
51478 +
51479 + return 'X';
51480 +}
51481 +
51482 +char gr_roletype_to_char(void)
51483 +{
51484 + return gr_task_roletype_to_char(current);
51485 +}
51486 +
51487 +__inline__ int
51488 +gr_acl_tpe_check(void)
51489 +{
51490 + if (unlikely(!(gr_status & GR_READY)))
51491 + return 0;
51492 + if (current->role->roletype & GR_ROLE_TPE)
51493 + return 1;
51494 + else
51495 + return 0;
51496 +}
51497 +
51498 +int
51499 +gr_handle_rawio(const struct inode *inode)
51500 +{
51501 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51502 + if (inode && S_ISBLK(inode->i_mode) &&
51503 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51504 + !capable(CAP_SYS_RAWIO))
51505 + return 1;
51506 +#endif
51507 + return 0;
51508 +}
51509 +
51510 +static int
51511 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51512 +{
51513 + if (likely(lena != lenb))
51514 + return 0;
51515 +
51516 + return !memcmp(a, b, lena);
51517 +}
51518 +
51519 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51520 +{
51521 + *buflen -= namelen;
51522 + if (*buflen < 0)
51523 + return -ENAMETOOLONG;
51524 + *buffer -= namelen;
51525 + memcpy(*buffer, str, namelen);
51526 + return 0;
51527 +}
51528 +
51529 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51530 +{
51531 + return prepend(buffer, buflen, name->name, name->len);
51532 +}
51533 +
51534 +static int prepend_path(const struct path *path, struct path *root,
51535 + char **buffer, int *buflen)
51536 +{
51537 + struct dentry *dentry = path->dentry;
51538 + struct vfsmount *vfsmnt = path->mnt;
51539 + bool slash = false;
51540 + int error = 0;
51541 +
51542 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51543 + struct dentry * parent;
51544 +
51545 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51546 + /* Global root? */
51547 + if (vfsmnt->mnt_parent == vfsmnt) {
51548 + goto out;
51549 + }
51550 + dentry = vfsmnt->mnt_mountpoint;
51551 + vfsmnt = vfsmnt->mnt_parent;
51552 + continue;
51553 + }
51554 + parent = dentry->d_parent;
51555 + prefetch(parent);
51556 + spin_lock(&dentry->d_lock);
51557 + error = prepend_name(buffer, buflen, &dentry->d_name);
51558 + spin_unlock(&dentry->d_lock);
51559 + if (!error)
51560 + error = prepend(buffer, buflen, "/", 1);
51561 + if (error)
51562 + break;
51563 +
51564 + slash = true;
51565 + dentry = parent;
51566 + }
51567 +
51568 +out:
51569 + if (!error && !slash)
51570 + error = prepend(buffer, buflen, "/", 1);
51571 +
51572 + return error;
51573 +}
51574 +
51575 +/* this must be called with vfsmount_lock and rename_lock held */
51576 +
51577 +static char *__our_d_path(const struct path *path, struct path *root,
51578 + char *buf, int buflen)
51579 +{
51580 + char *res = buf + buflen;
51581 + int error;
51582 +
51583 + prepend(&res, &buflen, "\0", 1);
51584 + error = prepend_path(path, root, &res, &buflen);
51585 + if (error)
51586 + return ERR_PTR(error);
51587 +
51588 + return res;
51589 +}
51590 +
51591 +static char *
51592 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51593 +{
51594 + char *retval;
51595 +
51596 + retval = __our_d_path(path, root, buf, buflen);
51597 + if (unlikely(IS_ERR(retval)))
51598 + retval = strcpy(buf, "<path too long>");
51599 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51600 + retval[1] = '\0';
51601 +
51602 + return retval;
51603 +}
51604 +
51605 +static char *
51606 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51607 + char *buf, int buflen)
51608 +{
51609 + struct path path;
51610 + char *res;
51611 +
51612 + path.dentry = (struct dentry *)dentry;
51613 + path.mnt = (struct vfsmount *)vfsmnt;
51614 +
51615 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51616 + by the RBAC system */
51617 + res = gen_full_path(&path, &real_root, buf, buflen);
51618 +
51619 + return res;
51620 +}
51621 +
51622 +static char *
51623 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51624 + char *buf, int buflen)
51625 +{
51626 + char *res;
51627 + struct path path;
51628 + struct path root;
51629 + struct task_struct *reaper = &init_task;
51630 +
51631 + path.dentry = (struct dentry *)dentry;
51632 + path.mnt = (struct vfsmount *)vfsmnt;
51633 +
51634 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51635 + get_fs_root(reaper->fs, &root);
51636 +
51637 + write_seqlock(&rename_lock);
51638 + br_read_lock(vfsmount_lock);
51639 + res = gen_full_path(&path, &root, buf, buflen);
51640 + br_read_unlock(vfsmount_lock);
51641 + write_sequnlock(&rename_lock);
51642 +
51643 + path_put(&root);
51644 + return res;
51645 +}
51646 +
51647 +static char *
51648 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51649 +{
51650 + char *ret;
51651 + write_seqlock(&rename_lock);
51652 + br_read_lock(vfsmount_lock);
51653 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51654 + PAGE_SIZE);
51655 + br_read_unlock(vfsmount_lock);
51656 + write_sequnlock(&rename_lock);
51657 + return ret;
51658 +}
51659 +
51660 +char *
51661 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51662 +{
51663 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51664 + PAGE_SIZE);
51665 +}
51666 +
51667 +char *
51668 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51669 +{
51670 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51671 + PAGE_SIZE);
51672 +}
51673 +
51674 +char *
51675 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51676 +{
51677 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51678 + PAGE_SIZE);
51679 +}
51680 +
51681 +char *
51682 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51683 +{
51684 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51685 + PAGE_SIZE);
51686 +}
51687 +
51688 +char *
51689 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51690 +{
51691 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51692 + PAGE_SIZE);
51693 +}
51694 +
51695 +__inline__ __u32
51696 +to_gr_audit(const __u32 reqmode)
51697 +{
51698 + /* masks off auditable permission flags, then shifts them to create
51699 + auditing flags, and adds the special case of append auditing if
51700 + we're requesting write */
51701 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51702 +}
51703 +
51704 +struct acl_subject_label *
51705 +lookup_subject_map(const struct acl_subject_label *userp)
51706 +{
51707 + unsigned int index = shash(userp, subj_map_set.s_size);
51708 + struct subject_map *match;
51709 +
51710 + match = subj_map_set.s_hash[index];
51711 +
51712 + while (match && match->user != userp)
51713 + match = match->next;
51714 +
51715 + if (match != NULL)
51716 + return match->kernel;
51717 + else
51718 + return NULL;
51719 +}
51720 +
51721 +static void
51722 +insert_subj_map_entry(struct subject_map *subjmap)
51723 +{
51724 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51725 + struct subject_map **curr;
51726 +
51727 + subjmap->prev = NULL;
51728 +
51729 + curr = &subj_map_set.s_hash[index];
51730 + if (*curr != NULL)
51731 + (*curr)->prev = subjmap;
51732 +
51733 + subjmap->next = *curr;
51734 + *curr = subjmap;
51735 +
51736 + return;
51737 +}
51738 +
51739 +static struct acl_role_label *
51740 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51741 + const gid_t gid)
51742 +{
51743 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51744 + struct acl_role_label *match;
51745 + struct role_allowed_ip *ipp;
51746 + unsigned int x;
51747 + u32 curr_ip = task->signal->curr_ip;
51748 +
51749 + task->signal->saved_ip = curr_ip;
51750 +
51751 + match = acl_role_set.r_hash[index];
51752 +
51753 + while (match) {
51754 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51755 + for (x = 0; x < match->domain_child_num; x++) {
51756 + if (match->domain_children[x] == uid)
51757 + goto found;
51758 + }
51759 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51760 + break;
51761 + match = match->next;
51762 + }
51763 +found:
51764 + if (match == NULL) {
51765 + try_group:
51766 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51767 + match = acl_role_set.r_hash[index];
51768 +
51769 + while (match) {
51770 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51771 + for (x = 0; x < match->domain_child_num; x++) {
51772 + if (match->domain_children[x] == gid)
51773 + goto found2;
51774 + }
51775 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51776 + break;
51777 + match = match->next;
51778 + }
51779 +found2:
51780 + if (match == NULL)
51781 + match = default_role;
51782 + if (match->allowed_ips == NULL)
51783 + return match;
51784 + else {
51785 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51786 + if (likely
51787 + ((ntohl(curr_ip) & ipp->netmask) ==
51788 + (ntohl(ipp->addr) & ipp->netmask)))
51789 + return match;
51790 + }
51791 + match = default_role;
51792 + }
51793 + } else if (match->allowed_ips == NULL) {
51794 + return match;
51795 + } else {
51796 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51797 + if (likely
51798 + ((ntohl(curr_ip) & ipp->netmask) ==
51799 + (ntohl(ipp->addr) & ipp->netmask)))
51800 + return match;
51801 + }
51802 + goto try_group;
51803 + }
51804 +
51805 + return match;
51806 +}
51807 +
51808 +struct acl_subject_label *
51809 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51810 + const struct acl_role_label *role)
51811 +{
51812 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51813 + struct acl_subject_label *match;
51814 +
51815 + match = role->subj_hash[index];
51816 +
51817 + while (match && (match->inode != ino || match->device != dev ||
51818 + (match->mode & GR_DELETED))) {
51819 + match = match->next;
51820 + }
51821 +
51822 + if (match && !(match->mode & GR_DELETED))
51823 + return match;
51824 + else
51825 + return NULL;
51826 +}
51827 +
51828 +struct acl_subject_label *
51829 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51830 + const struct acl_role_label *role)
51831 +{
51832 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51833 + struct acl_subject_label *match;
51834 +
51835 + match = role->subj_hash[index];
51836 +
51837 + while (match && (match->inode != ino || match->device != dev ||
51838 + !(match->mode & GR_DELETED))) {
51839 + match = match->next;
51840 + }
51841 +
51842 + if (match && (match->mode & GR_DELETED))
51843 + return match;
51844 + else
51845 + return NULL;
51846 +}
51847 +
51848 +static struct acl_object_label *
51849 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51850 + const struct acl_subject_label *subj)
51851 +{
51852 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51853 + struct acl_object_label *match;
51854 +
51855 + match = subj->obj_hash[index];
51856 +
51857 + while (match && (match->inode != ino || match->device != dev ||
51858 + (match->mode & GR_DELETED))) {
51859 + match = match->next;
51860 + }
51861 +
51862 + if (match && !(match->mode & GR_DELETED))
51863 + return match;
51864 + else
51865 + return NULL;
51866 +}
51867 +
51868 +static struct acl_object_label *
51869 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51870 + const struct acl_subject_label *subj)
51871 +{
51872 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51873 + struct acl_object_label *match;
51874 +
51875 + match = subj->obj_hash[index];
51876 +
51877 + while (match && (match->inode != ino || match->device != dev ||
51878 + !(match->mode & GR_DELETED))) {
51879 + match = match->next;
51880 + }
51881 +
51882 + if (match && (match->mode & GR_DELETED))
51883 + return match;
51884 +
51885 + match = subj->obj_hash[index];
51886 +
51887 + while (match && (match->inode != ino || match->device != dev ||
51888 + (match->mode & GR_DELETED))) {
51889 + match = match->next;
51890 + }
51891 +
51892 + if (match && !(match->mode & GR_DELETED))
51893 + return match;
51894 + else
51895 + return NULL;
51896 +}
51897 +
51898 +static struct name_entry *
51899 +lookup_name_entry(const char *name)
51900 +{
51901 + unsigned int len = strlen(name);
51902 + unsigned int key = full_name_hash(name, len);
51903 + unsigned int index = key % name_set.n_size;
51904 + struct name_entry *match;
51905 +
51906 + match = name_set.n_hash[index];
51907 +
51908 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51909 + match = match->next;
51910 +
51911 + return match;
51912 +}
51913 +
51914 +static struct name_entry *
51915 +lookup_name_entry_create(const char *name)
51916 +{
51917 + unsigned int len = strlen(name);
51918 + unsigned int key = full_name_hash(name, len);
51919 + unsigned int index = key % name_set.n_size;
51920 + struct name_entry *match;
51921 +
51922 + match = name_set.n_hash[index];
51923 +
51924 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51925 + !match->deleted))
51926 + match = match->next;
51927 +
51928 + if (match && match->deleted)
51929 + return match;
51930 +
51931 + match = name_set.n_hash[index];
51932 +
51933 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51934 + match->deleted))
51935 + match = match->next;
51936 +
51937 + if (match && !match->deleted)
51938 + return match;
51939 + else
51940 + return NULL;
51941 +}
51942 +
51943 +static struct inodev_entry *
51944 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51945 +{
51946 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51947 + struct inodev_entry *match;
51948 +
51949 + match = inodev_set.i_hash[index];
51950 +
51951 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51952 + match = match->next;
51953 +
51954 + return match;
51955 +}
51956 +
51957 +static void
51958 +insert_inodev_entry(struct inodev_entry *entry)
51959 +{
51960 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51961 + inodev_set.i_size);
51962 + struct inodev_entry **curr;
51963 +
51964 + entry->prev = NULL;
51965 +
51966 + curr = &inodev_set.i_hash[index];
51967 + if (*curr != NULL)
51968 + (*curr)->prev = entry;
51969 +
51970 + entry->next = *curr;
51971 + *curr = entry;
51972 +
51973 + return;
51974 +}
51975 +
51976 +static void
51977 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51978 +{
51979 + unsigned int index =
51980 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51981 + struct acl_role_label **curr;
51982 + struct acl_role_label *tmp;
51983 +
51984 + curr = &acl_role_set.r_hash[index];
51985 +
51986 + /* if role was already inserted due to domains and already has
51987 + a role in the same bucket as it attached, then we need to
51988 + combine these two buckets
51989 + */
51990 + if (role->next) {
51991 + tmp = role->next;
51992 + while (tmp->next)
51993 + tmp = tmp->next;
51994 + tmp->next = *curr;
51995 + } else
51996 + role->next = *curr;
51997 + *curr = role;
51998 +
51999 + return;
52000 +}
52001 +
52002 +static void
52003 +insert_acl_role_label(struct acl_role_label *role)
52004 +{
52005 + int i;
52006 +
52007 + if (role_list == NULL) {
52008 + role_list = role;
52009 + role->prev = NULL;
52010 + } else {
52011 + role->prev = role_list;
52012 + role_list = role;
52013 + }
52014 +
52015 + /* used for hash chains */
52016 + role->next = NULL;
52017 +
52018 + if (role->roletype & GR_ROLE_DOMAIN) {
52019 + for (i = 0; i < role->domain_child_num; i++)
52020 + __insert_acl_role_label(role, role->domain_children[i]);
52021 + } else
52022 + __insert_acl_role_label(role, role->uidgid);
52023 +}
52024 +
52025 +static int
52026 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52027 +{
52028 + struct name_entry **curr, *nentry;
52029 + struct inodev_entry *ientry;
52030 + unsigned int len = strlen(name);
52031 + unsigned int key = full_name_hash(name, len);
52032 + unsigned int index = key % name_set.n_size;
52033 +
52034 + curr = &name_set.n_hash[index];
52035 +
52036 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52037 + curr = &((*curr)->next);
52038 +
52039 + if (*curr != NULL)
52040 + return 1;
52041 +
52042 + nentry = acl_alloc(sizeof (struct name_entry));
52043 + if (nentry == NULL)
52044 + return 0;
52045 + ientry = acl_alloc(sizeof (struct inodev_entry));
52046 + if (ientry == NULL)
52047 + return 0;
52048 + ientry->nentry = nentry;
52049 +
52050 + nentry->key = key;
52051 + nentry->name = name;
52052 + nentry->inode = inode;
52053 + nentry->device = device;
52054 + nentry->len = len;
52055 + nentry->deleted = deleted;
52056 +
52057 + nentry->prev = NULL;
52058 + curr = &name_set.n_hash[index];
52059 + if (*curr != NULL)
52060 + (*curr)->prev = nentry;
52061 + nentry->next = *curr;
52062 + *curr = nentry;
52063 +
52064 + /* insert us into the table searchable by inode/dev */
52065 + insert_inodev_entry(ientry);
52066 +
52067 + return 1;
52068 +}
52069 +
52070 +static void
52071 +insert_acl_obj_label(struct acl_object_label *obj,
52072 + struct acl_subject_label *subj)
52073 +{
52074 + unsigned int index =
52075 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52076 + struct acl_object_label **curr;
52077 +
52078 +
52079 + obj->prev = NULL;
52080 +
52081 + curr = &subj->obj_hash[index];
52082 + if (*curr != NULL)
52083 + (*curr)->prev = obj;
52084 +
52085 + obj->next = *curr;
52086 + *curr = obj;
52087 +
52088 + return;
52089 +}
52090 +
52091 +static void
52092 +insert_acl_subj_label(struct acl_subject_label *obj,
52093 + struct acl_role_label *role)
52094 +{
52095 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52096 + struct acl_subject_label **curr;
52097 +
52098 + obj->prev = NULL;
52099 +
52100 + curr = &role->subj_hash[index];
52101 + if (*curr != NULL)
52102 + (*curr)->prev = obj;
52103 +
52104 + obj->next = *curr;
52105 + *curr = obj;
52106 +
52107 + return;
52108 +}
52109 +
52110 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52111 +
52112 +static void *
52113 +create_table(__u32 * len, int elementsize)
52114 +{
52115 + unsigned int table_sizes[] = {
52116 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52117 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52118 + 4194301, 8388593, 16777213, 33554393, 67108859
52119 + };
52120 + void *newtable = NULL;
52121 + unsigned int pwr = 0;
52122 +
52123 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52124 + table_sizes[pwr] <= *len)
52125 + pwr++;
52126 +
52127 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52128 + return newtable;
52129 +
52130 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52131 + newtable =
52132 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52133 + else
52134 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52135 +
52136 + *len = table_sizes[pwr];
52137 +
52138 + return newtable;
52139 +}
52140 +
52141 +static int
52142 +init_variables(const struct gr_arg *arg)
52143 +{
52144 + struct task_struct *reaper = &init_task;
52145 + unsigned int stacksize;
52146 +
52147 + subj_map_set.s_size = arg->role_db.num_subjects;
52148 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52149 + name_set.n_size = arg->role_db.num_objects;
52150 + inodev_set.i_size = arg->role_db.num_objects;
52151 +
52152 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52153 + !name_set.n_size || !inodev_set.i_size)
52154 + return 1;
52155 +
52156 + if (!gr_init_uidset())
52157 + return 1;
52158 +
52159 + /* set up the stack that holds allocation info */
52160 +
52161 + stacksize = arg->role_db.num_pointers + 5;
52162 +
52163 + if (!acl_alloc_stack_init(stacksize))
52164 + return 1;
52165 +
52166 + /* grab reference for the real root dentry and vfsmount */
52167 + get_fs_root(reaper->fs, &real_root);
52168 +
52169 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52170 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52171 +#endif
52172 +
52173 + fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
52174 + if (fakefs_obj == NULL)
52175 + return 1;
52176 + fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52177 +
52178 + subj_map_set.s_hash =
52179 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52180 + acl_role_set.r_hash =
52181 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52182 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52183 + inodev_set.i_hash =
52184 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52185 +
52186 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52187 + !name_set.n_hash || !inodev_set.i_hash)
52188 + return 1;
52189 +
52190 + memset(subj_map_set.s_hash, 0,
52191 + sizeof(struct subject_map *) * subj_map_set.s_size);
52192 + memset(acl_role_set.r_hash, 0,
52193 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52194 + memset(name_set.n_hash, 0,
52195 + sizeof (struct name_entry *) * name_set.n_size);
52196 + memset(inodev_set.i_hash, 0,
52197 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52198 +
52199 + return 0;
52200 +}
52201 +
52202 +/* free information not needed after startup
52203 + currently contains user->kernel pointer mappings for subjects
52204 +*/
52205 +
52206 +static void
52207 +free_init_variables(void)
52208 +{
52209 + __u32 i;
52210 +
52211 + if (subj_map_set.s_hash) {
52212 + for (i = 0; i < subj_map_set.s_size; i++) {
52213 + if (subj_map_set.s_hash[i]) {
52214 + kfree(subj_map_set.s_hash[i]);
52215 + subj_map_set.s_hash[i] = NULL;
52216 + }
52217 + }
52218 +
52219 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52220 + PAGE_SIZE)
52221 + kfree(subj_map_set.s_hash);
52222 + else
52223 + vfree(subj_map_set.s_hash);
52224 + }
52225 +
52226 + return;
52227 +}
52228 +
52229 +static void
52230 +free_variables(void)
52231 +{
52232 + struct acl_subject_label *s;
52233 + struct acl_role_label *r;
52234 + struct task_struct *task, *task2;
52235 + unsigned int x;
52236 +
52237 + gr_clear_learn_entries();
52238 +
52239 + read_lock(&tasklist_lock);
52240 + do_each_thread(task2, task) {
52241 + task->acl_sp_role = 0;
52242 + task->acl_role_id = 0;
52243 + task->acl = NULL;
52244 + task->role = NULL;
52245 + } while_each_thread(task2, task);
52246 + read_unlock(&tasklist_lock);
52247 +
52248 + /* release the reference to the real root dentry and vfsmount */
52249 + path_put(&real_root);
52250 +
52251 + /* free all object hash tables */
52252 +
52253 + FOR_EACH_ROLE_START(r)
52254 + if (r->subj_hash == NULL)
52255 + goto next_role;
52256 + FOR_EACH_SUBJECT_START(r, s, x)
52257 + if (s->obj_hash == NULL)
52258 + break;
52259 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52260 + kfree(s->obj_hash);
52261 + else
52262 + vfree(s->obj_hash);
52263 + FOR_EACH_SUBJECT_END(s, x)
52264 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52265 + if (s->obj_hash == NULL)
52266 + break;
52267 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52268 + kfree(s->obj_hash);
52269 + else
52270 + vfree(s->obj_hash);
52271 + FOR_EACH_NESTED_SUBJECT_END(s)
52272 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52273 + kfree(r->subj_hash);
52274 + else
52275 + vfree(r->subj_hash);
52276 + r->subj_hash = NULL;
52277 +next_role:
52278 + FOR_EACH_ROLE_END(r)
52279 +
52280 + acl_free_all();
52281 +
52282 + if (acl_role_set.r_hash) {
52283 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52284 + PAGE_SIZE)
52285 + kfree(acl_role_set.r_hash);
52286 + else
52287 + vfree(acl_role_set.r_hash);
52288 + }
52289 + if (name_set.n_hash) {
52290 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52291 + PAGE_SIZE)
52292 + kfree(name_set.n_hash);
52293 + else
52294 + vfree(name_set.n_hash);
52295 + }
52296 +
52297 + if (inodev_set.i_hash) {
52298 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52299 + PAGE_SIZE)
52300 + kfree(inodev_set.i_hash);
52301 + else
52302 + vfree(inodev_set.i_hash);
52303 + }
52304 +
52305 + gr_free_uidset();
52306 +
52307 + memset(&name_set, 0, sizeof (struct name_db));
52308 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52309 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52310 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52311 +
52312 + default_role = NULL;
52313 + role_list = NULL;
52314 +
52315 + return;
52316 +}
52317 +
52318 +static __u32
52319 +count_user_objs(struct acl_object_label *userp)
52320 +{
52321 + struct acl_object_label o_tmp;
52322 + __u32 num = 0;
52323 +
52324 + while (userp) {
52325 + if (copy_from_user(&o_tmp, userp,
52326 + sizeof (struct acl_object_label)))
52327 + break;
52328 +
52329 + userp = o_tmp.prev;
52330 + num++;
52331 + }
52332 +
52333 + return num;
52334 +}
52335 +
52336 +static struct acl_subject_label *
52337 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52338 +
52339 +static int
52340 +copy_user_glob(struct acl_object_label *obj)
52341 +{
52342 + struct acl_object_label *g_tmp, **guser;
52343 + unsigned int len;
52344 + char *tmp;
52345 +
52346 + if (obj->globbed == NULL)
52347 + return 0;
52348 +
52349 + guser = &obj->globbed;
52350 + while (*guser) {
52351 + g_tmp = (struct acl_object_label *)
52352 + acl_alloc(sizeof (struct acl_object_label));
52353 + if (g_tmp == NULL)
52354 + return -ENOMEM;
52355 +
52356 + if (copy_from_user(g_tmp, *guser,
52357 + sizeof (struct acl_object_label)))
52358 + return -EFAULT;
52359 +
52360 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52361 +
52362 + if (!len || len >= PATH_MAX)
52363 + return -EINVAL;
52364 +
52365 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52366 + return -ENOMEM;
52367 +
52368 + if (copy_from_user(tmp, g_tmp->filename, len))
52369 + return -EFAULT;
52370 + tmp[len-1] = '\0';
52371 + g_tmp->filename = tmp;
52372 +
52373 + *guser = g_tmp;
52374 + guser = &(g_tmp->next);
52375 + }
52376 +
52377 + return 0;
52378 +}
52379 +
52380 +static int
52381 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52382 + struct acl_role_label *role)
52383 +{
52384 + struct acl_object_label *o_tmp;
52385 + unsigned int len;
52386 + int ret;
52387 + char *tmp;
52388 +
52389 + while (userp) {
52390 + if ((o_tmp = (struct acl_object_label *)
52391 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52392 + return -ENOMEM;
52393 +
52394 + if (copy_from_user(o_tmp, userp,
52395 + sizeof (struct acl_object_label)))
52396 + return -EFAULT;
52397 +
52398 + userp = o_tmp->prev;
52399 +
52400 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52401 +
52402 + if (!len || len >= PATH_MAX)
52403 + return -EINVAL;
52404 +
52405 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52406 + return -ENOMEM;
52407 +
52408 + if (copy_from_user(tmp, o_tmp->filename, len))
52409 + return -EFAULT;
52410 + tmp[len-1] = '\0';
52411 + o_tmp->filename = tmp;
52412 +
52413 + insert_acl_obj_label(o_tmp, subj);
52414 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52415 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52416 + return -ENOMEM;
52417 +
52418 + ret = copy_user_glob(o_tmp);
52419 + if (ret)
52420 + return ret;
52421 +
52422 + if (o_tmp->nested) {
52423 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52424 + if (IS_ERR(o_tmp->nested))
52425 + return PTR_ERR(o_tmp->nested);
52426 +
52427 + /* insert into nested subject list */
52428 + o_tmp->nested->next = role->hash->first;
52429 + role->hash->first = o_tmp->nested;
52430 + }
52431 + }
52432 +
52433 + return 0;
52434 +}
52435 +
52436 +static __u32
52437 +count_user_subjs(struct acl_subject_label *userp)
52438 +{
52439 + struct acl_subject_label s_tmp;
52440 + __u32 num = 0;
52441 +
52442 + while (userp) {
52443 + if (copy_from_user(&s_tmp, userp,
52444 + sizeof (struct acl_subject_label)))
52445 + break;
52446 +
52447 + userp = s_tmp.prev;
52448 + /* do not count nested subjects against this count, since
52449 + they are not included in the hash table, but are
52450 + attached to objects. We have already counted
52451 + the subjects in userspace for the allocation
52452 + stack
52453 + */
52454 + if (!(s_tmp.mode & GR_NESTED))
52455 + num++;
52456 + }
52457 +
52458 + return num;
52459 +}
52460 +
52461 +static int
52462 +copy_user_allowedips(struct acl_role_label *rolep)
52463 +{
52464 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52465 +
52466 + ruserip = rolep->allowed_ips;
52467 +
52468 + while (ruserip) {
52469 + rlast = rtmp;
52470 +
52471 + if ((rtmp = (struct role_allowed_ip *)
52472 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52473 + return -ENOMEM;
52474 +
52475 + if (copy_from_user(rtmp, ruserip,
52476 + sizeof (struct role_allowed_ip)))
52477 + return -EFAULT;
52478 +
52479 + ruserip = rtmp->prev;
52480 +
52481 + if (!rlast) {
52482 + rtmp->prev = NULL;
52483 + rolep->allowed_ips = rtmp;
52484 + } else {
52485 + rlast->next = rtmp;
52486 + rtmp->prev = rlast;
52487 + }
52488 +
52489 + if (!ruserip)
52490 + rtmp->next = NULL;
52491 + }
52492 +
52493 + return 0;
52494 +}
52495 +
52496 +static int
52497 +copy_user_transitions(struct acl_role_label *rolep)
52498 +{
52499 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52500 +
52501 + unsigned int len;
52502 + char *tmp;
52503 +
52504 + rusertp = rolep->transitions;
52505 +
52506 + while (rusertp) {
52507 + rlast = rtmp;
52508 +
52509 + if ((rtmp = (struct role_transition *)
52510 + acl_alloc(sizeof (struct role_transition))) == NULL)
52511 + return -ENOMEM;
52512 +
52513 + if (copy_from_user(rtmp, rusertp,
52514 + sizeof (struct role_transition)))
52515 + return -EFAULT;
52516 +
52517 + rusertp = rtmp->prev;
52518 +
52519 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52520 +
52521 + if (!len || len >= GR_SPROLE_LEN)
52522 + return -EINVAL;
52523 +
52524 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52525 + return -ENOMEM;
52526 +
52527 + if (copy_from_user(tmp, rtmp->rolename, len))
52528 + return -EFAULT;
52529 + tmp[len-1] = '\0';
52530 + rtmp->rolename = tmp;
52531 +
52532 + if (!rlast) {
52533 + rtmp->prev = NULL;
52534 + rolep->transitions = rtmp;
52535 + } else {
52536 + rlast->next = rtmp;
52537 + rtmp->prev = rlast;
52538 + }
52539 +
52540 + if (!rusertp)
52541 + rtmp->next = NULL;
52542 + }
52543 +
52544 + return 0;
52545 +}
52546 +
52547 +static struct acl_subject_label *
52548 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52549 +{
52550 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52551 + unsigned int len;
52552 + char *tmp;
52553 + __u32 num_objs;
52554 + struct acl_ip_label **i_tmp, *i_utmp2;
52555 + struct gr_hash_struct ghash;
52556 + struct subject_map *subjmap;
52557 + unsigned int i_num;
52558 + int err;
52559 +
52560 + s_tmp = lookup_subject_map(userp);
52561 +
52562 + /* we've already copied this subject into the kernel, just return
52563 + the reference to it, and don't copy it over again
52564 + */
52565 + if (s_tmp)
52566 + return(s_tmp);
52567 +
52568 + if ((s_tmp = (struct acl_subject_label *)
52569 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52570 + return ERR_PTR(-ENOMEM);
52571 +
52572 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52573 + if (subjmap == NULL)
52574 + return ERR_PTR(-ENOMEM);
52575 +
52576 + subjmap->user = userp;
52577 + subjmap->kernel = s_tmp;
52578 + insert_subj_map_entry(subjmap);
52579 +
52580 + if (copy_from_user(s_tmp, userp,
52581 + sizeof (struct acl_subject_label)))
52582 + return ERR_PTR(-EFAULT);
52583 +
52584 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52585 +
52586 + if (!len || len >= PATH_MAX)
52587 + return ERR_PTR(-EINVAL);
52588 +
52589 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52590 + return ERR_PTR(-ENOMEM);
52591 +
52592 + if (copy_from_user(tmp, s_tmp->filename, len))
52593 + return ERR_PTR(-EFAULT);
52594 + tmp[len-1] = '\0';
52595 + s_tmp->filename = tmp;
52596 +
52597 + if (!strcmp(s_tmp->filename, "/"))
52598 + role->root_label = s_tmp;
52599 +
52600 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52601 + return ERR_PTR(-EFAULT);
52602 +
52603 + /* copy user and group transition tables */
52604 +
52605 + if (s_tmp->user_trans_num) {
52606 + uid_t *uidlist;
52607 +
52608 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52609 + if (uidlist == NULL)
52610 + return ERR_PTR(-ENOMEM);
52611 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52612 + return ERR_PTR(-EFAULT);
52613 +
52614 + s_tmp->user_transitions = uidlist;
52615 + }
52616 +
52617 + if (s_tmp->group_trans_num) {
52618 + gid_t *gidlist;
52619 +
52620 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52621 + if (gidlist == NULL)
52622 + return ERR_PTR(-ENOMEM);
52623 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52624 + return ERR_PTR(-EFAULT);
52625 +
52626 + s_tmp->group_transitions = gidlist;
52627 + }
52628 +
52629 + /* set up object hash table */
52630 + num_objs = count_user_objs(ghash.first);
52631 +
52632 + s_tmp->obj_hash_size = num_objs;
52633 + s_tmp->obj_hash =
52634 + (struct acl_object_label **)
52635 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52636 +
52637 + if (!s_tmp->obj_hash)
52638 + return ERR_PTR(-ENOMEM);
52639 +
52640 + memset(s_tmp->obj_hash, 0,
52641 + s_tmp->obj_hash_size *
52642 + sizeof (struct acl_object_label *));
52643 +
52644 + /* add in objects */
52645 + err = copy_user_objs(ghash.first, s_tmp, role);
52646 +
52647 + if (err)
52648 + return ERR_PTR(err);
52649 +
52650 + /* set pointer for parent subject */
52651 + if (s_tmp->parent_subject) {
52652 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52653 +
52654 + if (IS_ERR(s_tmp2))
52655 + return s_tmp2;
52656 +
52657 + s_tmp->parent_subject = s_tmp2;
52658 + }
52659 +
52660 + /* add in ip acls */
52661 +
52662 + if (!s_tmp->ip_num) {
52663 + s_tmp->ips = NULL;
52664 + goto insert;
52665 + }
52666 +
52667 + i_tmp =
52668 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52669 + sizeof (struct acl_ip_label *));
52670 +
52671 + if (!i_tmp)
52672 + return ERR_PTR(-ENOMEM);
52673 +
52674 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52675 + *(i_tmp + i_num) =
52676 + (struct acl_ip_label *)
52677 + acl_alloc(sizeof (struct acl_ip_label));
52678 + if (!*(i_tmp + i_num))
52679 + return ERR_PTR(-ENOMEM);
52680 +
52681 + if (copy_from_user
52682 + (&i_utmp2, s_tmp->ips + i_num,
52683 + sizeof (struct acl_ip_label *)))
52684 + return ERR_PTR(-EFAULT);
52685 +
52686 + if (copy_from_user
52687 + (*(i_tmp + i_num), i_utmp2,
52688 + sizeof (struct acl_ip_label)))
52689 + return ERR_PTR(-EFAULT);
52690 +
52691 + if ((*(i_tmp + i_num))->iface == NULL)
52692 + continue;
52693 +
52694 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52695 + if (!len || len >= IFNAMSIZ)
52696 + return ERR_PTR(-EINVAL);
52697 + tmp = acl_alloc(len);
52698 + if (tmp == NULL)
52699 + return ERR_PTR(-ENOMEM);
52700 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52701 + return ERR_PTR(-EFAULT);
52702 + (*(i_tmp + i_num))->iface = tmp;
52703 + }
52704 +
52705 + s_tmp->ips = i_tmp;
52706 +
52707 +insert:
52708 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52709 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52710 + return ERR_PTR(-ENOMEM);
52711 +
52712 + return s_tmp;
52713 +}
52714 +
52715 +static int
52716 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52717 +{
52718 + struct acl_subject_label s_pre;
52719 + struct acl_subject_label * ret;
52720 + int err;
52721 +
52722 + while (userp) {
52723 + if (copy_from_user(&s_pre, userp,
52724 + sizeof (struct acl_subject_label)))
52725 + return -EFAULT;
52726 +
52727 + /* do not add nested subjects here, add
52728 + while parsing objects
52729 + */
52730 +
52731 + if (s_pre.mode & GR_NESTED) {
52732 + userp = s_pre.prev;
52733 + continue;
52734 + }
52735 +
52736 + ret = do_copy_user_subj(userp, role);
52737 +
52738 + err = PTR_ERR(ret);
52739 + if (IS_ERR(ret))
52740 + return err;
52741 +
52742 + insert_acl_subj_label(ret, role);
52743 +
52744 + userp = s_pre.prev;
52745 + }
52746 +
52747 + return 0;
52748 +}
52749 +
52750 +static int
52751 +copy_user_acl(struct gr_arg *arg)
52752 +{
52753 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52754 + struct sprole_pw *sptmp;
52755 + struct gr_hash_struct *ghash;
52756 + uid_t *domainlist;
52757 + unsigned int r_num;
52758 + unsigned int len;
52759 + char *tmp;
52760 + int err = 0;
52761 + __u16 i;
52762 + __u32 num_subjs;
52763 +
52764 + /* we need a default and kernel role */
52765 + if (arg->role_db.num_roles < 2)
52766 + return -EINVAL;
52767 +
52768 + /* copy special role authentication info from userspace */
52769 +
52770 + num_sprole_pws = arg->num_sprole_pws;
52771 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52772 +
52773 + if (!acl_special_roles) {
52774 + err = -ENOMEM;
52775 + goto cleanup;
52776 + }
52777 +
52778 + for (i = 0; i < num_sprole_pws; i++) {
52779 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52780 + if (!sptmp) {
52781 + err = -ENOMEM;
52782 + goto cleanup;
52783 + }
52784 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52785 + sizeof (struct sprole_pw))) {
52786 + err = -EFAULT;
52787 + goto cleanup;
52788 + }
52789 +
52790 + len =
52791 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52792 +
52793 + if (!len || len >= GR_SPROLE_LEN) {
52794 + err = -EINVAL;
52795 + goto cleanup;
52796 + }
52797 +
52798 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52799 + err = -ENOMEM;
52800 + goto cleanup;
52801 + }
52802 +
52803 + if (copy_from_user(tmp, sptmp->rolename, len)) {
52804 + err = -EFAULT;
52805 + goto cleanup;
52806 + }
52807 + tmp[len-1] = '\0';
52808 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52809 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52810 +#endif
52811 + sptmp->rolename = tmp;
52812 + acl_special_roles[i] = sptmp;
52813 + }
52814 +
52815 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52816 +
52817 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52818 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52819 +
52820 + if (!r_tmp) {
52821 + err = -ENOMEM;
52822 + goto cleanup;
52823 + }
52824 +
52825 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52826 + sizeof (struct acl_role_label *))) {
52827 + err = -EFAULT;
52828 + goto cleanup;
52829 + }
52830 +
52831 + if (copy_from_user(r_tmp, r_utmp2,
52832 + sizeof (struct acl_role_label))) {
52833 + err = -EFAULT;
52834 + goto cleanup;
52835 + }
52836 +
52837 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52838 +
52839 + if (!len || len >= PATH_MAX) {
52840 + err = -EINVAL;
52841 + goto cleanup;
52842 + }
52843 +
52844 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52845 + err = -ENOMEM;
52846 + goto cleanup;
52847 + }
52848 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
52849 + err = -EFAULT;
52850 + goto cleanup;
52851 + }
52852 + tmp[len-1] = '\0';
52853 + r_tmp->rolename = tmp;
52854 +
52855 + if (!strcmp(r_tmp->rolename, "default")
52856 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52857 + default_role = r_tmp;
52858 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52859 + kernel_role = r_tmp;
52860 + }
52861 +
52862 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52863 + err = -ENOMEM;
52864 + goto cleanup;
52865 + }
52866 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52867 + err = -EFAULT;
52868 + goto cleanup;
52869 + }
52870 +
52871 + r_tmp->hash = ghash;
52872 +
52873 + num_subjs = count_user_subjs(r_tmp->hash->first);
52874 +
52875 + r_tmp->subj_hash_size = num_subjs;
52876 + r_tmp->subj_hash =
52877 + (struct acl_subject_label **)
52878 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52879 +
52880 + if (!r_tmp->subj_hash) {
52881 + err = -ENOMEM;
52882 + goto cleanup;
52883 + }
52884 +
52885 + err = copy_user_allowedips(r_tmp);
52886 + if (err)
52887 + goto cleanup;
52888 +
52889 + /* copy domain info */
52890 + if (r_tmp->domain_children != NULL) {
52891 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52892 + if (domainlist == NULL) {
52893 + err = -ENOMEM;
52894 + goto cleanup;
52895 + }
52896 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52897 + err = -EFAULT;
52898 + goto cleanup;
52899 + }
52900 + r_tmp->domain_children = domainlist;
52901 + }
52902 +
52903 + err = copy_user_transitions(r_tmp);
52904 + if (err)
52905 + goto cleanup;
52906 +
52907 + memset(r_tmp->subj_hash, 0,
52908 + r_tmp->subj_hash_size *
52909 + sizeof (struct acl_subject_label *));
52910 +
52911 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52912 +
52913 + if (err)
52914 + goto cleanup;
52915 +
52916 + /* set nested subject list to null */
52917 + r_tmp->hash->first = NULL;
52918 +
52919 + insert_acl_role_label(r_tmp);
52920 + }
52921 +
52922 + goto return_err;
52923 + cleanup:
52924 + free_variables();
52925 + return_err:
52926 + return err;
52927 +
52928 +}
52929 +
52930 +static int
52931 +gracl_init(struct gr_arg *args)
52932 +{
52933 + int error = 0;
52934 +
52935 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52936 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52937 +
52938 + if (init_variables(args)) {
52939 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52940 + error = -ENOMEM;
52941 + free_variables();
52942 + goto out;
52943 + }
52944 +
52945 + error = copy_user_acl(args);
52946 + free_init_variables();
52947 + if (error) {
52948 + free_variables();
52949 + goto out;
52950 + }
52951 +
52952 + if ((error = gr_set_acls(0))) {
52953 + free_variables();
52954 + goto out;
52955 + }
52956 +
52957 + pax_open_kernel();
52958 + gr_status |= GR_READY;
52959 + pax_close_kernel();
52960 +
52961 + out:
52962 + return error;
52963 +}
52964 +
52965 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52966 +
52967 +static int
52968 +glob_match(const char *p, const char *n)
52969 +{
52970 + char c;
52971 +
52972 + while ((c = *p++) != '\0') {
52973 + switch (c) {
52974 + case '?':
52975 + if (*n == '\0')
52976 + return 1;
52977 + else if (*n == '/')
52978 + return 1;
52979 + break;
52980 + case '\\':
52981 + if (*n != c)
52982 + return 1;
52983 + break;
52984 + case '*':
52985 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52986 + if (*n == '/')
52987 + return 1;
52988 + else if (c == '?') {
52989 + if (*n == '\0')
52990 + return 1;
52991 + else
52992 + ++n;
52993 + }
52994 + }
52995 + if (c == '\0') {
52996 + return 0;
52997 + } else {
52998 + const char *endp;
52999 +
53000 + if ((endp = strchr(n, '/')) == NULL)
53001 + endp = n + strlen(n);
53002 +
53003 + if (c == '[') {
53004 + for (--p; n < endp; ++n)
53005 + if (!glob_match(p, n))
53006 + return 0;
53007 + } else if (c == '/') {
53008 + while (*n != '\0' && *n != '/')
53009 + ++n;
53010 + if (*n == '/' && !glob_match(p, n + 1))
53011 + return 0;
53012 + } else {
53013 + for (--p; n < endp; ++n)
53014 + if (*n == c && !glob_match(p, n))
53015 + return 0;
53016 + }
53017 +
53018 + return 1;
53019 + }
53020 + case '[':
53021 + {
53022 + int not;
53023 + char cold;
53024 +
53025 + if (*n == '\0' || *n == '/')
53026 + return 1;
53027 +
53028 + not = (*p == '!' || *p == '^');
53029 + if (not)
53030 + ++p;
53031 +
53032 + c = *p++;
53033 + for (;;) {
53034 + unsigned char fn = (unsigned char)*n;
53035 +
53036 + if (c == '\0')
53037 + return 1;
53038 + else {
53039 + if (c == fn)
53040 + goto matched;
53041 + cold = c;
53042 + c = *p++;
53043 +
53044 + if (c == '-' && *p != ']') {
53045 + unsigned char cend = *p++;
53046 +
53047 + if (cend == '\0')
53048 + return 1;
53049 +
53050 + if (cold <= fn && fn <= cend)
53051 + goto matched;
53052 +
53053 + c = *p++;
53054 + }
53055 + }
53056 +
53057 + if (c == ']')
53058 + break;
53059 + }
53060 + if (!not)
53061 + return 1;
53062 + break;
53063 + matched:
53064 + while (c != ']') {
53065 + if (c == '\0')
53066 + return 1;
53067 +
53068 + c = *p++;
53069 + }
53070 + if (not)
53071 + return 1;
53072 + }
53073 + break;
53074 + default:
53075 + if (c != *n)
53076 + return 1;
53077 + }
53078 +
53079 + ++n;
53080 + }
53081 +
53082 + if (*n == '\0')
53083 + return 0;
53084 +
53085 + if (*n == '/')
53086 + return 0;
53087 +
53088 + return 1;
53089 +}
53090 +
53091 +static struct acl_object_label *
53092 +chk_glob_label(struct acl_object_label *globbed,
53093 + struct dentry *dentry, struct vfsmount *mnt, char **path)
53094 +{
53095 + struct acl_object_label *tmp;
53096 +
53097 + if (*path == NULL)
53098 + *path = gr_to_filename_nolock(dentry, mnt);
53099 +
53100 + tmp = globbed;
53101 +
53102 + while (tmp) {
53103 + if (!glob_match(tmp->filename, *path))
53104 + return tmp;
53105 + tmp = tmp->next;
53106 + }
53107 +
53108 + return NULL;
53109 +}
53110 +
53111 +static struct acl_object_label *
53112 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53113 + const ino_t curr_ino, const dev_t curr_dev,
53114 + const struct acl_subject_label *subj, char **path, const int checkglob)
53115 +{
53116 + struct acl_subject_label *tmpsubj;
53117 + struct acl_object_label *retval;
53118 + struct acl_object_label *retval2;
53119 +
53120 + tmpsubj = (struct acl_subject_label *) subj;
53121 + read_lock(&gr_inode_lock);
53122 + do {
53123 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53124 + if (retval) {
53125 + if (checkglob && retval->globbed) {
53126 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53127 + (struct vfsmount *)orig_mnt, path);
53128 + if (retval2)
53129 + retval = retval2;
53130 + }
53131 + break;
53132 + }
53133 + } while ((tmpsubj = tmpsubj->parent_subject));
53134 + read_unlock(&gr_inode_lock);
53135 +
53136 + return retval;
53137 +}
53138 +
53139 +static __inline__ struct acl_object_label *
53140 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53141 + struct dentry *curr_dentry,
53142 + const struct acl_subject_label *subj, char **path, const int checkglob)
53143 +{
53144 + int newglob = checkglob;
53145 + ino_t inode;
53146 + dev_t device;
53147 +
53148 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53149 + as we don't want a / * rule to match instead of the / object
53150 + don't do this for create lookups that call this function though, since they're looking up
53151 + on the parent and thus need globbing checks on all paths
53152 + */
53153 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53154 + newglob = GR_NO_GLOB;
53155 +
53156 + spin_lock(&curr_dentry->d_lock);
53157 + inode = curr_dentry->d_inode->i_ino;
53158 + device = __get_dev(curr_dentry);
53159 + spin_unlock(&curr_dentry->d_lock);
53160 +
53161 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53162 +}
53163 +
53164 +static struct acl_object_label *
53165 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53166 + const struct acl_subject_label *subj, char *path, const int checkglob)
53167 +{
53168 + struct dentry *dentry = (struct dentry *) l_dentry;
53169 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53170 + struct acl_object_label *retval;
53171 + struct dentry *parent;
53172 +
53173 + write_seqlock(&rename_lock);
53174 + br_read_lock(vfsmount_lock);
53175 +
53176 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53177 +#ifdef CONFIG_NET
53178 + mnt == sock_mnt ||
53179 +#endif
53180 +#ifdef CONFIG_HUGETLBFS
53181 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53182 +#endif
53183 + /* ignore Eric Biederman */
53184 + IS_PRIVATE(l_dentry->d_inode))) {
53185 + retval = fakefs_obj;
53186 + goto out;
53187 + }
53188 +
53189 + for (;;) {
53190 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53191 + break;
53192 +
53193 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53194 + if (mnt->mnt_parent == mnt)
53195 + break;
53196 +
53197 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53198 + if (retval != NULL)
53199 + goto out;
53200 +
53201 + dentry = mnt->mnt_mountpoint;
53202 + mnt = mnt->mnt_parent;
53203 + continue;
53204 + }
53205 +
53206 + parent = dentry->d_parent;
53207 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53208 + if (retval != NULL)
53209 + goto out;
53210 +
53211 + dentry = parent;
53212 + }
53213 +
53214 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53215 +
53216 + /* real_root is pinned so we don't have to hold a reference */
53217 + if (retval == NULL)
53218 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53219 +out:
53220 + br_read_unlock(vfsmount_lock);
53221 + write_sequnlock(&rename_lock);
53222 +
53223 + BUG_ON(retval == NULL);
53224 +
53225 + return retval;
53226 +}
53227 +
53228 +static __inline__ struct acl_object_label *
53229 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53230 + const struct acl_subject_label *subj)
53231 +{
53232 + char *path = NULL;
53233 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53234 +}
53235 +
53236 +static __inline__ struct acl_object_label *
53237 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53238 + const struct acl_subject_label *subj)
53239 +{
53240 + char *path = NULL;
53241 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53242 +}
53243 +
53244 +static __inline__ struct acl_object_label *
53245 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53246 + const struct acl_subject_label *subj, char *path)
53247 +{
53248 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53249 +}
53250 +
53251 +static struct acl_subject_label *
53252 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53253 + const struct acl_role_label *role)
53254 +{
53255 + struct dentry *dentry = (struct dentry *) l_dentry;
53256 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53257 + struct acl_subject_label *retval;
53258 + struct dentry *parent;
53259 +
53260 + write_seqlock(&rename_lock);
53261 + br_read_lock(vfsmount_lock);
53262 +
53263 + for (;;) {
53264 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53265 + break;
53266 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53267 + if (mnt->mnt_parent == mnt)
53268 + break;
53269 +
53270 + spin_lock(&dentry->d_lock);
53271 + read_lock(&gr_inode_lock);
53272 + retval =
53273 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53274 + __get_dev(dentry), role);
53275 + read_unlock(&gr_inode_lock);
53276 + spin_unlock(&dentry->d_lock);
53277 + if (retval != NULL)
53278 + goto out;
53279 +
53280 + dentry = mnt->mnt_mountpoint;
53281 + mnt = mnt->mnt_parent;
53282 + continue;
53283 + }
53284 +
53285 + spin_lock(&dentry->d_lock);
53286 + read_lock(&gr_inode_lock);
53287 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53288 + __get_dev(dentry), role);
53289 + read_unlock(&gr_inode_lock);
53290 + parent = dentry->d_parent;
53291 + spin_unlock(&dentry->d_lock);
53292 +
53293 + if (retval != NULL)
53294 + goto out;
53295 +
53296 + dentry = parent;
53297 + }
53298 +
53299 + spin_lock(&dentry->d_lock);
53300 + read_lock(&gr_inode_lock);
53301 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53302 + __get_dev(dentry), role);
53303 + read_unlock(&gr_inode_lock);
53304 + spin_unlock(&dentry->d_lock);
53305 +
53306 + if (unlikely(retval == NULL)) {
53307 + /* real_root is pinned, we don't need to hold a reference */
53308 + read_lock(&gr_inode_lock);
53309 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53310 + __get_dev(real_root.dentry), role);
53311 + read_unlock(&gr_inode_lock);
53312 + }
53313 +out:
53314 + br_read_unlock(vfsmount_lock);
53315 + write_sequnlock(&rename_lock);
53316 +
53317 + BUG_ON(retval == NULL);
53318 +
53319 + return retval;
53320 +}
53321 +
53322 +static void
53323 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53324 +{
53325 + struct task_struct *task = current;
53326 + const struct cred *cred = current_cred();
53327 +
53328 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53329 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53330 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53331 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53332 +
53333 + return;
53334 +}
53335 +
53336 +static void
53337 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53338 +{
53339 + struct task_struct *task = current;
53340 + const struct cred *cred = current_cred();
53341 +
53342 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53343 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53344 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53345 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53346 +
53347 + return;
53348 +}
53349 +
53350 +static void
53351 +gr_log_learn_id_change(const char type, const unsigned int real,
53352 + const unsigned int effective, const unsigned int fs)
53353 +{
53354 + struct task_struct *task = current;
53355 + const struct cred *cred = current_cred();
53356 +
53357 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53358 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53359 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53360 + type, real, effective, fs, &task->signal->saved_ip);
53361 +
53362 + return;
53363 +}
53364 +
53365 +__u32
53366 +gr_check_link(const struct dentry * new_dentry,
53367 + const struct dentry * parent_dentry,
53368 + const struct vfsmount * parent_mnt,
53369 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53370 +{
53371 + struct acl_object_label *obj;
53372 + __u32 oldmode, newmode;
53373 + __u32 needmode;
53374 +
53375 + if (unlikely(!(gr_status & GR_READY)))
53376 + return (GR_CREATE | GR_LINK);
53377 +
53378 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53379 + oldmode = obj->mode;
53380 +
53381 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53382 + oldmode |= (GR_CREATE | GR_LINK);
53383 +
53384 + needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
53385 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53386 + needmode |= GR_SETID | GR_AUDIT_SETID;
53387 +
53388 + newmode =
53389 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
53390 + oldmode | needmode);
53391 +
53392 + needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
53393 + GR_SETID | GR_READ | GR_FIND | GR_DELETE |
53394 + GR_INHERIT | GR_AUDIT_INHERIT);
53395 +
53396 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
53397 + goto bad;
53398 +
53399 + if ((oldmode & needmode) != needmode)
53400 + goto bad;
53401 +
53402 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53403 + if ((newmode & needmode) != needmode)
53404 + goto bad;
53405 +
53406 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53407 + return newmode;
53408 +bad:
53409 + needmode = oldmode;
53410 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53411 + needmode |= GR_SETID;
53412 +
53413 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53414 + gr_log_learn(old_dentry, old_mnt, needmode);
53415 + return (GR_CREATE | GR_LINK);
53416 + } else if (newmode & GR_SUPPRESS)
53417 + return GR_SUPPRESS;
53418 + else
53419 + return 0;
53420 +}
53421 +
53422 +__u32
53423 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53424 + const struct vfsmount * mnt)
53425 +{
53426 + __u32 retval = mode;
53427 + struct acl_subject_label *curracl;
53428 + struct acl_object_label *currobj;
53429 +
53430 + if (unlikely(!(gr_status & GR_READY)))
53431 + return (mode & ~GR_AUDITS);
53432 +
53433 + curracl = current->acl;
53434 +
53435 + currobj = chk_obj_label(dentry, mnt, curracl);
53436 + retval = currobj->mode & mode;
53437 +
53438 + /* if we're opening a specified transfer file for writing
53439 + (e.g. /dev/initctl), then transfer our role to init
53440 + */
53441 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53442 + current->role->roletype & GR_ROLE_PERSIST)) {
53443 + struct task_struct *task = init_pid_ns.child_reaper;
53444 +
53445 + if (task->role != current->role) {
53446 + task->acl_sp_role = 0;
53447 + task->acl_role_id = current->acl_role_id;
53448 + task->role = current->role;
53449 + rcu_read_lock();
53450 + read_lock(&grsec_exec_file_lock);
53451 + gr_apply_subject_to_task(task);
53452 + read_unlock(&grsec_exec_file_lock);
53453 + rcu_read_unlock();
53454 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53455 + }
53456 + }
53457 +
53458 + if (unlikely
53459 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53460 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53461 + __u32 new_mode = mode;
53462 +
53463 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53464 +
53465 + retval = new_mode;
53466 +
53467 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53468 + new_mode |= GR_INHERIT;
53469 +
53470 + if (!(mode & GR_NOLEARN))
53471 + gr_log_learn(dentry, mnt, new_mode);
53472 + }
53473 +
53474 + return retval;
53475 +}
53476 +
53477 +__u32
53478 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53479 + const struct vfsmount * mnt, const __u32 mode)
53480 +{
53481 + struct name_entry *match;
53482 + struct acl_object_label *matchpo;
53483 + struct acl_subject_label *curracl;
53484 + char *path;
53485 + __u32 retval;
53486 +
53487 + if (unlikely(!(gr_status & GR_READY)))
53488 + return (mode & ~GR_AUDITS);
53489 +
53490 + preempt_disable();
53491 + path = gr_to_filename_rbac(new_dentry, mnt);
53492 + match = lookup_name_entry_create(path);
53493 +
53494 + if (!match)
53495 + goto check_parent;
53496 +
53497 + curracl = current->acl;
53498 +
53499 + read_lock(&gr_inode_lock);
53500 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53501 + read_unlock(&gr_inode_lock);
53502 +
53503 + if (matchpo) {
53504 + if ((matchpo->mode & mode) !=
53505 + (mode & ~(GR_AUDITS | GR_SUPPRESS))
53506 + && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53507 + __u32 new_mode = mode;
53508 +
53509 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53510 +
53511 + gr_log_learn(new_dentry, mnt, new_mode);
53512 +
53513 + preempt_enable();
53514 + return new_mode;
53515 + }
53516 + preempt_enable();
53517 + return (matchpo->mode & mode);
53518 + }
53519 +
53520 + check_parent:
53521 + curracl = current->acl;
53522 +
53523 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53524 + retval = matchpo->mode & mode;
53525 +
53526 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53527 + && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53528 + __u32 new_mode = mode;
53529 +
53530 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53531 +
53532 + gr_log_learn(new_dentry, mnt, new_mode);
53533 + preempt_enable();
53534 + return new_mode;
53535 + }
53536 +
53537 + preempt_enable();
53538 + return retval;
53539 +}
53540 +
53541 +int
53542 +gr_check_hidden_task(const struct task_struct *task)
53543 +{
53544 + if (unlikely(!(gr_status & GR_READY)))
53545 + return 0;
53546 +
53547 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53548 + return 1;
53549 +
53550 + return 0;
53551 +}
53552 +
53553 +int
53554 +gr_check_protected_task(const struct task_struct *task)
53555 +{
53556 + if (unlikely(!(gr_status & GR_READY) || !task))
53557 + return 0;
53558 +
53559 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53560 + task->acl != current->acl)
53561 + return 1;
53562 +
53563 + return 0;
53564 +}
53565 +
53566 +int
53567 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53568 +{
53569 + struct task_struct *p;
53570 + int ret = 0;
53571 +
53572 + if (unlikely(!(gr_status & GR_READY) || !pid))
53573 + return ret;
53574 +
53575 + read_lock(&tasklist_lock);
53576 + do_each_pid_task(pid, type, p) {
53577 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53578 + p->acl != current->acl) {
53579 + ret = 1;
53580 + goto out;
53581 + }
53582 + } while_each_pid_task(pid, type, p);
53583 +out:
53584 + read_unlock(&tasklist_lock);
53585 +
53586 + return ret;
53587 +}
53588 +
53589 +void
53590 +gr_copy_label(struct task_struct *tsk)
53591 +{
53592 + tsk->signal->used_accept = 0;
53593 + tsk->acl_sp_role = 0;
53594 + tsk->acl_role_id = current->acl_role_id;
53595 + tsk->acl = current->acl;
53596 + tsk->role = current->role;
53597 + tsk->signal->curr_ip = current->signal->curr_ip;
53598 + tsk->signal->saved_ip = current->signal->saved_ip;
53599 + if (current->exec_file)
53600 + get_file(current->exec_file);
53601 + tsk->exec_file = current->exec_file;
53602 + tsk->is_writable = current->is_writable;
53603 + if (unlikely(current->signal->used_accept)) {
53604 + current->signal->curr_ip = 0;
53605 + current->signal->saved_ip = 0;
53606 + }
53607 +
53608 + return;
53609 +}
53610 +
53611 +static void
53612 +gr_set_proc_res(struct task_struct *task)
53613 +{
53614 + struct acl_subject_label *proc;
53615 + unsigned short i;
53616 +
53617 + proc = task->acl;
53618 +
53619 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53620 + return;
53621 +
53622 + for (i = 0; i < RLIM_NLIMITS; i++) {
53623 + if (!(proc->resmask & (1 << i)))
53624 + continue;
53625 +
53626 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53627 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53628 + }
53629 +
53630 + return;
53631 +}
53632 +
53633 +extern int __gr_process_user_ban(struct user_struct *user);
53634 +
53635 +int
53636 +gr_check_user_change(int real, int effective, int fs)
53637 +{
53638 + unsigned int i;
53639 + __u16 num;
53640 + uid_t *uidlist;
53641 + int curuid;
53642 + int realok = 0;
53643 + int effectiveok = 0;
53644 + int fsok = 0;
53645 +
53646 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53647 + struct user_struct *user;
53648 +
53649 + if (real == -1)
53650 + goto skipit;
53651 +
53652 + user = find_user(real);
53653 + if (user == NULL)
53654 + goto skipit;
53655 +
53656 + if (__gr_process_user_ban(user)) {
53657 + /* for find_user */
53658 + free_uid(user);
53659 + return 1;
53660 + }
53661 +
53662 + /* for find_user */
53663 + free_uid(user);
53664 +
53665 +skipit:
53666 +#endif
53667 +
53668 + if (unlikely(!(gr_status & GR_READY)))
53669 + return 0;
53670 +
53671 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53672 + gr_log_learn_id_change('u', real, effective, fs);
53673 +
53674 + num = current->acl->user_trans_num;
53675 + uidlist = current->acl->user_transitions;
53676 +
53677 + if (uidlist == NULL)
53678 + return 0;
53679 +
53680 + if (real == -1)
53681 + realok = 1;
53682 + if (effective == -1)
53683 + effectiveok = 1;
53684 + if (fs == -1)
53685 + fsok = 1;
53686 +
53687 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53688 + for (i = 0; i < num; i++) {
53689 + curuid = (int)uidlist[i];
53690 + if (real == curuid)
53691 + realok = 1;
53692 + if (effective == curuid)
53693 + effectiveok = 1;
53694 + if (fs == curuid)
53695 + fsok = 1;
53696 + }
53697 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53698 + for (i = 0; i < num; i++) {
53699 + curuid = (int)uidlist[i];
53700 + if (real == curuid)
53701 + break;
53702 + if (effective == curuid)
53703 + break;
53704 + if (fs == curuid)
53705 + break;
53706 + }
53707 + /* not in deny list */
53708 + if (i == num) {
53709 + realok = 1;
53710 + effectiveok = 1;
53711 + fsok = 1;
53712 + }
53713 + }
53714 +
53715 + if (realok && effectiveok && fsok)
53716 + return 0;
53717 + else {
53718 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53719 + return 1;
53720 + }
53721 +}
53722 +
53723 +int
53724 +gr_check_group_change(int real, int effective, int fs)
53725 +{
53726 + unsigned int i;
53727 + __u16 num;
53728 + gid_t *gidlist;
53729 + int curgid;
53730 + int realok = 0;
53731 + int effectiveok = 0;
53732 + int fsok = 0;
53733 +
53734 + if (unlikely(!(gr_status & GR_READY)))
53735 + return 0;
53736 +
53737 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53738 + gr_log_learn_id_change('g', real, effective, fs);
53739 +
53740 + num = current->acl->group_trans_num;
53741 + gidlist = current->acl->group_transitions;
53742 +
53743 + if (gidlist == NULL)
53744 + return 0;
53745 +
53746 + if (real == -1)
53747 + realok = 1;
53748 + if (effective == -1)
53749 + effectiveok = 1;
53750 + if (fs == -1)
53751 + fsok = 1;
53752 +
53753 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53754 + for (i = 0; i < num; i++) {
53755 + curgid = (int)gidlist[i];
53756 + if (real == curgid)
53757 + realok = 1;
53758 + if (effective == curgid)
53759 + effectiveok = 1;
53760 + if (fs == curgid)
53761 + fsok = 1;
53762 + }
53763 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53764 + for (i = 0; i < num; i++) {
53765 + curgid = (int)gidlist[i];
53766 + if (real == curgid)
53767 + break;
53768 + if (effective == curgid)
53769 + break;
53770 + if (fs == curgid)
53771 + break;
53772 + }
53773 + /* not in deny list */
53774 + if (i == num) {
53775 + realok = 1;
53776 + effectiveok = 1;
53777 + fsok = 1;
53778 + }
53779 + }
53780 +
53781 + if (realok && effectiveok && fsok)
53782 + return 0;
53783 + else {
53784 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53785 + return 1;
53786 + }
53787 +}
53788 +
53789 +void
53790 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53791 +{
53792 + struct acl_role_label *role = task->role;
53793 + struct acl_subject_label *subj = NULL;
53794 + struct acl_object_label *obj;
53795 + struct file *filp;
53796 +
53797 + if (unlikely(!(gr_status & GR_READY)))
53798 + return;
53799 +
53800 + filp = task->exec_file;
53801 +
53802 + /* kernel process, we'll give them the kernel role */
53803 + if (unlikely(!filp)) {
53804 + task->role = kernel_role;
53805 + task->acl = kernel_role->root_label;
53806 + return;
53807 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53808 + role = lookup_acl_role_label(task, uid, gid);
53809 +
53810 + /* perform subject lookup in possibly new role
53811 + we can use this result below in the case where role == task->role
53812 + */
53813 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53814 +
53815 + /* if we changed uid/gid, but result in the same role
53816 + and are using inheritance, don't lose the inherited subject
53817 + if current subject is other than what normal lookup
53818 + would result in, we arrived via inheritance, don't
53819 + lose subject
53820 + */
53821 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53822 + (subj == task->acl)))
53823 + task->acl = subj;
53824 +
53825 + task->role = role;
53826 +
53827 + task->is_writable = 0;
53828 +
53829 + /* ignore additional mmap checks for processes that are writable
53830 + by the default ACL */
53831 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53832 + if (unlikely(obj->mode & GR_WRITE))
53833 + task->is_writable = 1;
53834 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53835 + if (unlikely(obj->mode & GR_WRITE))
53836 + task->is_writable = 1;
53837 +
53838 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53839 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53840 +#endif
53841 +
53842 + gr_set_proc_res(task);
53843 +
53844 + return;
53845 +}
53846 +
53847 +int
53848 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53849 + const int unsafe_share)
53850 +{
53851 + struct task_struct *task = current;
53852 + struct acl_subject_label *newacl;
53853 + struct acl_object_label *obj;
53854 + __u32 retmode;
53855 +
53856 + if (unlikely(!(gr_status & GR_READY)))
53857 + return 0;
53858 +
53859 + newacl = chk_subj_label(dentry, mnt, task->role);
53860 +
53861 + task_lock(task);
53862 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53863 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53864 + !(task->role->roletype & GR_ROLE_GOD) &&
53865 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53866 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53867 + task_unlock(task);
53868 + if (unsafe_share)
53869 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53870 + else
53871 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53872 + return -EACCES;
53873 + }
53874 + task_unlock(task);
53875 +
53876 + obj = chk_obj_label(dentry, mnt, task->acl);
53877 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53878 +
53879 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53880 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53881 + if (obj->nested)
53882 + task->acl = obj->nested;
53883 + else
53884 + task->acl = newacl;
53885 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53886 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53887 +
53888 + task->is_writable = 0;
53889 +
53890 + /* ignore additional mmap checks for processes that are writable
53891 + by the default ACL */
53892 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53893 + if (unlikely(obj->mode & GR_WRITE))
53894 + task->is_writable = 1;
53895 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53896 + if (unlikely(obj->mode & GR_WRITE))
53897 + task->is_writable = 1;
53898 +
53899 + gr_set_proc_res(task);
53900 +
53901 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53902 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53903 +#endif
53904 + return 0;
53905 +}
53906 +
53907 +/* always called with valid inodev ptr */
53908 +static void
53909 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53910 +{
53911 + struct acl_object_label *matchpo;
53912 + struct acl_subject_label *matchps;
53913 + struct acl_subject_label *subj;
53914 + struct acl_role_label *role;
53915 + unsigned int x;
53916 +
53917 + FOR_EACH_ROLE_START(role)
53918 + FOR_EACH_SUBJECT_START(role, subj, x)
53919 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53920 + matchpo->mode |= GR_DELETED;
53921 + FOR_EACH_SUBJECT_END(subj,x)
53922 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53923 + if (subj->inode == ino && subj->device == dev)
53924 + subj->mode |= GR_DELETED;
53925 + FOR_EACH_NESTED_SUBJECT_END(subj)
53926 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53927 + matchps->mode |= GR_DELETED;
53928 + FOR_EACH_ROLE_END(role)
53929 +
53930 + inodev->nentry->deleted = 1;
53931 +
53932 + return;
53933 +}
53934 +
53935 +void
53936 +gr_handle_delete(const ino_t ino, const dev_t dev)
53937 +{
53938 + struct inodev_entry *inodev;
53939 +
53940 + if (unlikely(!(gr_status & GR_READY)))
53941 + return;
53942 +
53943 + write_lock(&gr_inode_lock);
53944 + inodev = lookup_inodev_entry(ino, dev);
53945 + if (inodev != NULL)
53946 + do_handle_delete(inodev, ino, dev);
53947 + write_unlock(&gr_inode_lock);
53948 +
53949 + return;
53950 +}
53951 +
53952 +static void
53953 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53954 + const ino_t newinode, const dev_t newdevice,
53955 + struct acl_subject_label *subj)
53956 +{
53957 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53958 + struct acl_object_label *match;
53959 +
53960 + match = subj->obj_hash[index];
53961 +
53962 + while (match && (match->inode != oldinode ||
53963 + match->device != olddevice ||
53964 + !(match->mode & GR_DELETED)))
53965 + match = match->next;
53966 +
53967 + if (match && (match->inode == oldinode)
53968 + && (match->device == olddevice)
53969 + && (match->mode & GR_DELETED)) {
53970 + if (match->prev == NULL) {
53971 + subj->obj_hash[index] = match->next;
53972 + if (match->next != NULL)
53973 + match->next->prev = NULL;
53974 + } else {
53975 + match->prev->next = match->next;
53976 + if (match->next != NULL)
53977 + match->next->prev = match->prev;
53978 + }
53979 + match->prev = NULL;
53980 + match->next = NULL;
53981 + match->inode = newinode;
53982 + match->device = newdevice;
53983 + match->mode &= ~GR_DELETED;
53984 +
53985 + insert_acl_obj_label(match, subj);
53986 + }
53987 +
53988 + return;
53989 +}
53990 +
53991 +static void
53992 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53993 + const ino_t newinode, const dev_t newdevice,
53994 + struct acl_role_label *role)
53995 +{
53996 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53997 + struct acl_subject_label *match;
53998 +
53999 + match = role->subj_hash[index];
54000 +
54001 + while (match && (match->inode != oldinode ||
54002 + match->device != olddevice ||
54003 + !(match->mode & GR_DELETED)))
54004 + match = match->next;
54005 +
54006 + if (match && (match->inode == oldinode)
54007 + && (match->device == olddevice)
54008 + && (match->mode & GR_DELETED)) {
54009 + if (match->prev == NULL) {
54010 + role->subj_hash[index] = match->next;
54011 + if (match->next != NULL)
54012 + match->next->prev = NULL;
54013 + } else {
54014 + match->prev->next = match->next;
54015 + if (match->next != NULL)
54016 + match->next->prev = match->prev;
54017 + }
54018 + match->prev = NULL;
54019 + match->next = NULL;
54020 + match->inode = newinode;
54021 + match->device = newdevice;
54022 + match->mode &= ~GR_DELETED;
54023 +
54024 + insert_acl_subj_label(match, role);
54025 + }
54026 +
54027 + return;
54028 +}
54029 +
54030 +static void
54031 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54032 + const ino_t newinode, const dev_t newdevice)
54033 +{
54034 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54035 + struct inodev_entry *match;
54036 +
54037 + match = inodev_set.i_hash[index];
54038 +
54039 + while (match && (match->nentry->inode != oldinode ||
54040 + match->nentry->device != olddevice || !match->nentry->deleted))
54041 + match = match->next;
54042 +
54043 + if (match && (match->nentry->inode == oldinode)
54044 + && (match->nentry->device == olddevice) &&
54045 + match->nentry->deleted) {
54046 + if (match->prev == NULL) {
54047 + inodev_set.i_hash[index] = match->next;
54048 + if (match->next != NULL)
54049 + match->next->prev = NULL;
54050 + } else {
54051 + match->prev->next = match->next;
54052 + if (match->next != NULL)
54053 + match->next->prev = match->prev;
54054 + }
54055 + match->prev = NULL;
54056 + match->next = NULL;
54057 + match->nentry->inode = newinode;
54058 + match->nentry->device = newdevice;
54059 + match->nentry->deleted = 0;
54060 +
54061 + insert_inodev_entry(match);
54062 + }
54063 +
54064 + return;
54065 +}
54066 +
54067 +static void
54068 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54069 + const struct vfsmount *mnt)
54070 +{
54071 + struct acl_subject_label *subj;
54072 + struct acl_role_label *role;
54073 + unsigned int x;
54074 + ino_t ino = dentry->d_inode->i_ino;
54075 + dev_t dev = __get_dev(dentry);
54076 +
54077 + FOR_EACH_ROLE_START(role)
54078 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54079 +
54080 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54081 + if ((subj->inode == ino) && (subj->device == dev)) {
54082 + subj->inode = ino;
54083 + subj->device = dev;
54084 + }
54085 + FOR_EACH_NESTED_SUBJECT_END(subj)
54086 + FOR_EACH_SUBJECT_START(role, subj, x)
54087 + update_acl_obj_label(matchn->inode, matchn->device,
54088 + ino, dev, subj);
54089 + FOR_EACH_SUBJECT_END(subj,x)
54090 + FOR_EACH_ROLE_END(role)
54091 +
54092 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54093 +
54094 + return;
54095 +}
54096 +
54097 +void
54098 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54099 +{
54100 + struct name_entry *matchn;
54101 +
54102 + if (unlikely(!(gr_status & GR_READY)))
54103 + return;
54104 +
54105 + preempt_disable();
54106 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54107 +
54108 + if (unlikely((unsigned long)matchn)) {
54109 + write_lock(&gr_inode_lock);
54110 + do_handle_create(matchn, dentry, mnt);
54111 + write_unlock(&gr_inode_lock);
54112 + }
54113 + preempt_enable();
54114 +
54115 + return;
54116 +}
54117 +
54118 +void
54119 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54120 + struct dentry *old_dentry,
54121 + struct dentry *new_dentry,
54122 + struct vfsmount *mnt, const __u8 replace)
54123 +{
54124 + struct name_entry *matchn;
54125 + struct inodev_entry *inodev;
54126 + ino_t old_ino = old_dentry->d_inode->i_ino;
54127 + dev_t old_dev = __get_dev(old_dentry);
54128 +
54129 + /* vfs_rename swaps the name and parent link for old_dentry and
54130 + new_dentry
54131 + at this point, old_dentry has the new name, parent link, and inode
54132 + for the renamed file
54133 + if a file is being replaced by a rename, new_dentry has the inode
54134 + and name for the replaced file
54135 + */
54136 +
54137 + if (unlikely(!(gr_status & GR_READY)))
54138 + return;
54139 +
54140 + preempt_disable();
54141 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54142 +
54143 + /* we wouldn't have to check d_inode if it weren't for
54144 + NFS silly-renaming
54145 + */
54146 +
54147 + write_lock(&gr_inode_lock);
54148 + if (unlikely(replace && new_dentry->d_inode)) {
54149 + ino_t new_ino = new_dentry->d_inode->i_ino;
54150 + dev_t new_dev = __get_dev(new_dentry);
54151 +
54152 + inodev = lookup_inodev_entry(new_ino, new_dev);
54153 + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
54154 + do_handle_delete(inodev, new_ino, new_dev);
54155 + }
54156 +
54157 + inodev = lookup_inodev_entry(old_ino, old_dev);
54158 + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
54159 + do_handle_delete(inodev, old_ino, old_dev);
54160 +
54161 + if (unlikely((unsigned long)matchn))
54162 + do_handle_create(matchn, old_dentry, mnt);
54163 +
54164 + write_unlock(&gr_inode_lock);
54165 + preempt_enable();
54166 +
54167 + return;
54168 +}
54169 +
54170 +static int
54171 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54172 + unsigned char **sum)
54173 +{
54174 + struct acl_role_label *r;
54175 + struct role_allowed_ip *ipp;
54176 + struct role_transition *trans;
54177 + unsigned int i;
54178 + int found = 0;
54179 + u32 curr_ip = current->signal->curr_ip;
54180 +
54181 + current->signal->saved_ip = curr_ip;
54182 +
54183 + /* check transition table */
54184 +
54185 + for (trans = current->role->transitions; trans; trans = trans->next) {
54186 + if (!strcmp(rolename, trans->rolename)) {
54187 + found = 1;
54188 + break;
54189 + }
54190 + }
54191 +
54192 + if (!found)
54193 + return 0;
54194 +
54195 + /* handle special roles that do not require authentication
54196 + and check ip */
54197 +
54198 + FOR_EACH_ROLE_START(r)
54199 + if (!strcmp(rolename, r->rolename) &&
54200 + (r->roletype & GR_ROLE_SPECIAL)) {
54201 + found = 0;
54202 + if (r->allowed_ips != NULL) {
54203 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54204 + if ((ntohl(curr_ip) & ipp->netmask) ==
54205 + (ntohl(ipp->addr) & ipp->netmask))
54206 + found = 1;
54207 + }
54208 + } else
54209 + found = 2;
54210 + if (!found)
54211 + return 0;
54212 +
54213 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54214 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54215 + *salt = NULL;
54216 + *sum = NULL;
54217 + return 1;
54218 + }
54219 + }
54220 + FOR_EACH_ROLE_END(r)
54221 +
54222 + for (i = 0; i < num_sprole_pws; i++) {
54223 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54224 + *salt = acl_special_roles[i]->salt;
54225 + *sum = acl_special_roles[i]->sum;
54226 + return 1;
54227 + }
54228 + }
54229 +
54230 + return 0;
54231 +}
54232 +
54233 +static void
54234 +assign_special_role(char *rolename)
54235 +{
54236 + struct acl_object_label *obj;
54237 + struct acl_role_label *r;
54238 + struct acl_role_label *assigned = NULL;
54239 + struct task_struct *tsk;
54240 + struct file *filp;
54241 +
54242 + FOR_EACH_ROLE_START(r)
54243 + if (!strcmp(rolename, r->rolename) &&
54244 + (r->roletype & GR_ROLE_SPECIAL)) {
54245 + assigned = r;
54246 + break;
54247 + }
54248 + FOR_EACH_ROLE_END(r)
54249 +
54250 + if (!assigned)
54251 + return;
54252 +
54253 + read_lock(&tasklist_lock);
54254 + read_lock(&grsec_exec_file_lock);
54255 +
54256 + tsk = current->real_parent;
54257 + if (tsk == NULL)
54258 + goto out_unlock;
54259 +
54260 + filp = tsk->exec_file;
54261 + if (filp == NULL)
54262 + goto out_unlock;
54263 +
54264 + tsk->is_writable = 0;
54265 +
54266 + tsk->acl_sp_role = 1;
54267 + tsk->acl_role_id = ++acl_sp_role_value;
54268 + tsk->role = assigned;
54269 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54270 +
54271 + /* ignore additional mmap checks for processes that are writable
54272 + by the default ACL */
54273 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54274 + if (unlikely(obj->mode & GR_WRITE))
54275 + tsk->is_writable = 1;
54276 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54277 + if (unlikely(obj->mode & GR_WRITE))
54278 + tsk->is_writable = 1;
54279 +
54280 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54281 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54282 +#endif
54283 +
54284 +out_unlock:
54285 + read_unlock(&grsec_exec_file_lock);
54286 + read_unlock(&tasklist_lock);
54287 + return;
54288 +}
54289 +
54290 +int gr_check_secure_terminal(struct task_struct *task)
54291 +{
54292 + struct task_struct *p, *p2, *p3;
54293 + struct files_struct *files;
54294 + struct fdtable *fdt;
54295 + struct file *our_file = NULL, *file;
54296 + int i;
54297 +
54298 + if (task->signal->tty == NULL)
54299 + return 1;
54300 +
54301 + files = get_files_struct(task);
54302 + if (files != NULL) {
54303 + rcu_read_lock();
54304 + fdt = files_fdtable(files);
54305 + for (i=0; i < fdt->max_fds; i++) {
54306 + file = fcheck_files(files, i);
54307 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54308 + get_file(file);
54309 + our_file = file;
54310 + }
54311 + }
54312 + rcu_read_unlock();
54313 + put_files_struct(files);
54314 + }
54315 +
54316 + if (our_file == NULL)
54317 + return 1;
54318 +
54319 + read_lock(&tasklist_lock);
54320 + do_each_thread(p2, p) {
54321 + files = get_files_struct(p);
54322 + if (files == NULL ||
54323 + (p->signal && p->signal->tty == task->signal->tty)) {
54324 + if (files != NULL)
54325 + put_files_struct(files);
54326 + continue;
54327 + }
54328 + rcu_read_lock();
54329 + fdt = files_fdtable(files);
54330 + for (i=0; i < fdt->max_fds; i++) {
54331 + file = fcheck_files(files, i);
54332 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54333 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54334 + p3 = task;
54335 + while (p3->pid > 0) {
54336 + if (p3 == p)
54337 + break;
54338 + p3 = p3->real_parent;
54339 + }
54340 + if (p3 == p)
54341 + break;
54342 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54343 + gr_handle_alertkill(p);
54344 + rcu_read_unlock();
54345 + put_files_struct(files);
54346 + read_unlock(&tasklist_lock);
54347 + fput(our_file);
54348 + return 0;
54349 + }
54350 + }
54351 + rcu_read_unlock();
54352 + put_files_struct(files);
54353 + } while_each_thread(p2, p);
54354 + read_unlock(&tasklist_lock);
54355 +
54356 + fput(our_file);
54357 + return 1;
54358 +}
54359 +
54360 +ssize_t
54361 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54362 +{
54363 + struct gr_arg_wrapper uwrap;
54364 + unsigned char *sprole_salt = NULL;
54365 + unsigned char *sprole_sum = NULL;
54366 + int error = sizeof (struct gr_arg_wrapper);
54367 + int error2 = 0;
54368 +
54369 + mutex_lock(&gr_dev_mutex);
54370 +
54371 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54372 + error = -EPERM;
54373 + goto out;
54374 + }
54375 +
54376 + if (count != sizeof (struct gr_arg_wrapper)) {
54377 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54378 + error = -EINVAL;
54379 + goto out;
54380 + }
54381 +
54382 +
54383 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54384 + gr_auth_expires = 0;
54385 + gr_auth_attempts = 0;
54386 + }
54387 +
54388 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54389 + error = -EFAULT;
54390 + goto out;
54391 + }
54392 +
54393 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54394 + error = -EINVAL;
54395 + goto out;
54396 + }
54397 +
54398 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54399 + error = -EFAULT;
54400 + goto out;
54401 + }
54402 +
54403 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54404 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54405 + time_after(gr_auth_expires, get_seconds())) {
54406 + error = -EBUSY;
54407 + goto out;
54408 + }
54409 +
54410 + /* if non-root trying to do anything other than use a special role,
54411 + do not attempt authentication, do not count towards authentication
54412 + locking
54413 + */
54414 +
54415 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54416 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54417 + current_uid()) {
54418 + error = -EPERM;
54419 + goto out;
54420 + }
54421 +
54422 + /* ensure pw and special role name are null terminated */
54423 +
54424 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54425 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54426 +
54427 + /* Okay.
54428 + * We have our enough of the argument structure..(we have yet
54429 + * to copy_from_user the tables themselves) . Copy the tables
54430 + * only if we need them, i.e. for loading operations. */
54431 +
54432 + switch (gr_usermode->mode) {
54433 + case GR_STATUS:
54434 + if (gr_status & GR_READY) {
54435 + error = 1;
54436 + if (!gr_check_secure_terminal(current))
54437 + error = 3;
54438 + } else
54439 + error = 2;
54440 + goto out;
54441 + case GR_SHUTDOWN:
54442 + if ((gr_status & GR_READY)
54443 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54444 + pax_open_kernel();
54445 + gr_status &= ~GR_READY;
54446 + pax_close_kernel();
54447 +
54448 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54449 + free_variables();
54450 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54451 + memset(gr_system_salt, 0, GR_SALT_LEN);
54452 + memset(gr_system_sum, 0, GR_SHA_LEN);
54453 + } else if (gr_status & GR_READY) {
54454 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54455 + error = -EPERM;
54456 + } else {
54457 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54458 + error = -EAGAIN;
54459 + }
54460 + break;
54461 + case GR_ENABLE:
54462 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54463 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54464 + else {
54465 + if (gr_status & GR_READY)
54466 + error = -EAGAIN;
54467 + else
54468 + error = error2;
54469 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54470 + }
54471 + break;
54472 + case GR_RELOAD:
54473 + if (!(gr_status & GR_READY)) {
54474 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54475 + error = -EAGAIN;
54476 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54477 + preempt_disable();
54478 +
54479 + pax_open_kernel();
54480 + gr_status &= ~GR_READY;
54481 + pax_close_kernel();
54482 +
54483 + free_variables();
54484 + if (!(error2 = gracl_init(gr_usermode))) {
54485 + preempt_enable();
54486 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54487 + } else {
54488 + preempt_enable();
54489 + error = error2;
54490 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54491 + }
54492 + } else {
54493 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54494 + error = -EPERM;
54495 + }
54496 + break;
54497 + case GR_SEGVMOD:
54498 + if (unlikely(!(gr_status & GR_READY))) {
54499 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54500 + error = -EAGAIN;
54501 + break;
54502 + }
54503 +
54504 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54505 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54506 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54507 + struct acl_subject_label *segvacl;
54508 + segvacl =
54509 + lookup_acl_subj_label(gr_usermode->segv_inode,
54510 + gr_usermode->segv_device,
54511 + current->role);
54512 + if (segvacl) {
54513 + segvacl->crashes = 0;
54514 + segvacl->expires = 0;
54515 + }
54516 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54517 + gr_remove_uid(gr_usermode->segv_uid);
54518 + }
54519 + } else {
54520 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54521 + error = -EPERM;
54522 + }
54523 + break;
54524 + case GR_SPROLE:
54525 + case GR_SPROLEPAM:
54526 + if (unlikely(!(gr_status & GR_READY))) {
54527 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54528 + error = -EAGAIN;
54529 + break;
54530 + }
54531 +
54532 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54533 + current->role->expires = 0;
54534 + current->role->auth_attempts = 0;
54535 + }
54536 +
54537 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54538 + time_after(current->role->expires, get_seconds())) {
54539 + error = -EBUSY;
54540 + goto out;
54541 + }
54542 +
54543 + if (lookup_special_role_auth
54544 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54545 + && ((!sprole_salt && !sprole_sum)
54546 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54547 + char *p = "";
54548 + assign_special_role(gr_usermode->sp_role);
54549 + read_lock(&tasklist_lock);
54550 + if (current->real_parent)
54551 + p = current->real_parent->role->rolename;
54552 + read_unlock(&tasklist_lock);
54553 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54554 + p, acl_sp_role_value);
54555 + } else {
54556 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54557 + error = -EPERM;
54558 + if(!(current->role->auth_attempts++))
54559 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54560 +
54561 + goto out;
54562 + }
54563 + break;
54564 + case GR_UNSPROLE:
54565 + if (unlikely(!(gr_status & GR_READY))) {
54566 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54567 + error = -EAGAIN;
54568 + break;
54569 + }
54570 +
54571 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54572 + char *p = "";
54573 + int i = 0;
54574 +
54575 + read_lock(&tasklist_lock);
54576 + if (current->real_parent) {
54577 + p = current->real_parent->role->rolename;
54578 + i = current->real_parent->acl_role_id;
54579 + }
54580 + read_unlock(&tasklist_lock);
54581 +
54582 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54583 + gr_set_acls(1);
54584 + } else {
54585 + error = -EPERM;
54586 + goto out;
54587 + }
54588 + break;
54589 + default:
54590 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54591 + error = -EINVAL;
54592 + break;
54593 + }
54594 +
54595 + if (error != -EPERM)
54596 + goto out;
54597 +
54598 + if(!(gr_auth_attempts++))
54599 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54600 +
54601 + out:
54602 + mutex_unlock(&gr_dev_mutex);
54603 + return error;
54604 +}
54605 +
54606 +/* must be called with
54607 + rcu_read_lock();
54608 + read_lock(&tasklist_lock);
54609 + read_lock(&grsec_exec_file_lock);
54610 +*/
54611 +int gr_apply_subject_to_task(struct task_struct *task)
54612 +{
54613 + struct acl_object_label *obj;
54614 + char *tmpname;
54615 + struct acl_subject_label *tmpsubj;
54616 + struct file *filp;
54617 + struct name_entry *nmatch;
54618 +
54619 + filp = task->exec_file;
54620 + if (filp == NULL)
54621 + return 0;
54622 +
54623 + /* the following is to apply the correct subject
54624 + on binaries running when the RBAC system
54625 + is enabled, when the binaries have been
54626 + replaced or deleted since their execution
54627 + -----
54628 + when the RBAC system starts, the inode/dev
54629 + from exec_file will be one the RBAC system
54630 + is unaware of. It only knows the inode/dev
54631 + of the present file on disk, or the absence
54632 + of it.
54633 + */
54634 + preempt_disable();
54635 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54636 +
54637 + nmatch = lookup_name_entry(tmpname);
54638 + preempt_enable();
54639 + tmpsubj = NULL;
54640 + if (nmatch) {
54641 + if (nmatch->deleted)
54642 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54643 + else
54644 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54645 + if (tmpsubj != NULL)
54646 + task->acl = tmpsubj;
54647 + }
54648 + if (tmpsubj == NULL)
54649 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54650 + task->role);
54651 + if (task->acl) {
54652 + struct acl_subject_label *curr;
54653 + curr = task->acl;
54654 +
54655 + task->is_writable = 0;
54656 + /* ignore additional mmap checks for processes that are writable
54657 + by the default ACL */
54658 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54659 + if (unlikely(obj->mode & GR_WRITE))
54660 + task->is_writable = 1;
54661 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54662 + if (unlikely(obj->mode & GR_WRITE))
54663 + task->is_writable = 1;
54664 +
54665 + gr_set_proc_res(task);
54666 +
54667 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54668 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54669 +#endif
54670 + } else {
54671 + return 1;
54672 + }
54673 +
54674 + return 0;
54675 +}
54676 +
54677 +int
54678 +gr_set_acls(const int type)
54679 +{
54680 + struct task_struct *task, *task2;
54681 + struct acl_role_label *role = current->role;
54682 + __u16 acl_role_id = current->acl_role_id;
54683 + const struct cred *cred;
54684 + int ret;
54685 +
54686 + rcu_read_lock();
54687 + read_lock(&tasklist_lock);
54688 + read_lock(&grsec_exec_file_lock);
54689 + do_each_thread(task2, task) {
54690 + /* check to see if we're called from the exit handler,
54691 + if so, only replace ACLs that have inherited the admin
54692 + ACL */
54693 +
54694 + if (type && (task->role != role ||
54695 + task->acl_role_id != acl_role_id))
54696 + continue;
54697 +
54698 + task->acl_role_id = 0;
54699 + task->acl_sp_role = 0;
54700 +
54701 + if (task->exec_file) {
54702 + cred = __task_cred(task);
54703 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54704 + ret = gr_apply_subject_to_task(task);
54705 + if (ret) {
54706 + read_unlock(&grsec_exec_file_lock);
54707 + read_unlock(&tasklist_lock);
54708 + rcu_read_unlock();
54709 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54710 + return ret;
54711 + }
54712 + } else {
54713 + // it's a kernel process
54714 + task->role = kernel_role;
54715 + task->acl = kernel_role->root_label;
54716 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54717 + task->acl->mode &= ~GR_PROCFIND;
54718 +#endif
54719 + }
54720 + } while_each_thread(task2, task);
54721 + read_unlock(&grsec_exec_file_lock);
54722 + read_unlock(&tasklist_lock);
54723 + rcu_read_unlock();
54724 +
54725 + return 0;
54726 +}
54727 +
54728 +void
54729 +gr_learn_resource(const struct task_struct *task,
54730 + const int res, const unsigned long wanted, const int gt)
54731 +{
54732 + struct acl_subject_label *acl;
54733 + const struct cred *cred;
54734 +
54735 + if (unlikely((gr_status & GR_READY) &&
54736 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54737 + goto skip_reslog;
54738 +
54739 +#ifdef CONFIG_GRKERNSEC_RESLOG
54740 + gr_log_resource(task, res, wanted, gt);
54741 +#endif
54742 + skip_reslog:
54743 +
54744 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54745 + return;
54746 +
54747 + acl = task->acl;
54748 +
54749 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54750 + !(acl->resmask & (1 << (unsigned short) res))))
54751 + return;
54752 +
54753 + if (wanted >= acl->res[res].rlim_cur) {
54754 + unsigned long res_add;
54755 +
54756 + res_add = wanted;
54757 + switch (res) {
54758 + case RLIMIT_CPU:
54759 + res_add += GR_RLIM_CPU_BUMP;
54760 + break;
54761 + case RLIMIT_FSIZE:
54762 + res_add += GR_RLIM_FSIZE_BUMP;
54763 + break;
54764 + case RLIMIT_DATA:
54765 + res_add += GR_RLIM_DATA_BUMP;
54766 + break;
54767 + case RLIMIT_STACK:
54768 + res_add += GR_RLIM_STACK_BUMP;
54769 + break;
54770 + case RLIMIT_CORE:
54771 + res_add += GR_RLIM_CORE_BUMP;
54772 + break;
54773 + case RLIMIT_RSS:
54774 + res_add += GR_RLIM_RSS_BUMP;
54775 + break;
54776 + case RLIMIT_NPROC:
54777 + res_add += GR_RLIM_NPROC_BUMP;
54778 + break;
54779 + case RLIMIT_NOFILE:
54780 + res_add += GR_RLIM_NOFILE_BUMP;
54781 + break;
54782 + case RLIMIT_MEMLOCK:
54783 + res_add += GR_RLIM_MEMLOCK_BUMP;
54784 + break;
54785 + case RLIMIT_AS:
54786 + res_add += GR_RLIM_AS_BUMP;
54787 + break;
54788 + case RLIMIT_LOCKS:
54789 + res_add += GR_RLIM_LOCKS_BUMP;
54790 + break;
54791 + case RLIMIT_SIGPENDING:
54792 + res_add += GR_RLIM_SIGPENDING_BUMP;
54793 + break;
54794 + case RLIMIT_MSGQUEUE:
54795 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54796 + break;
54797 + case RLIMIT_NICE:
54798 + res_add += GR_RLIM_NICE_BUMP;
54799 + break;
54800 + case RLIMIT_RTPRIO:
54801 + res_add += GR_RLIM_RTPRIO_BUMP;
54802 + break;
54803 + case RLIMIT_RTTIME:
54804 + res_add += GR_RLIM_RTTIME_BUMP;
54805 + break;
54806 + }
54807 +
54808 + acl->res[res].rlim_cur = res_add;
54809 +
54810 + if (wanted > acl->res[res].rlim_max)
54811 + acl->res[res].rlim_max = res_add;
54812 +
54813 + /* only log the subject filename, since resource logging is supported for
54814 + single-subject learning only */
54815 + rcu_read_lock();
54816 + cred = __task_cred(task);
54817 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54818 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54819 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54820 + "", (unsigned long) res, &task->signal->saved_ip);
54821 + rcu_read_unlock();
54822 + }
54823 +
54824 + return;
54825 +}
54826 +
54827 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54828 +void
54829 +pax_set_initial_flags(struct linux_binprm *bprm)
54830 +{
54831 + struct task_struct *task = current;
54832 + struct acl_subject_label *proc;
54833 + unsigned long flags;
54834 +
54835 + if (unlikely(!(gr_status & GR_READY)))
54836 + return;
54837 +
54838 + flags = pax_get_flags(task);
54839 +
54840 + proc = task->acl;
54841 +
54842 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54843 + flags &= ~MF_PAX_PAGEEXEC;
54844 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54845 + flags &= ~MF_PAX_SEGMEXEC;
54846 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54847 + flags &= ~MF_PAX_RANDMMAP;
54848 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54849 + flags &= ~MF_PAX_EMUTRAMP;
54850 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54851 + flags &= ~MF_PAX_MPROTECT;
54852 +
54853 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54854 + flags |= MF_PAX_PAGEEXEC;
54855 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54856 + flags |= MF_PAX_SEGMEXEC;
54857 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54858 + flags |= MF_PAX_RANDMMAP;
54859 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54860 + flags |= MF_PAX_EMUTRAMP;
54861 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54862 + flags |= MF_PAX_MPROTECT;
54863 +
54864 + pax_set_flags(task, flags);
54865 +
54866 + return;
54867 +}
54868 +#endif
54869 +
54870 +#ifdef CONFIG_SYSCTL
54871 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54872 + system to save 35kb of memory */
54873 +
54874 +/* we modify the passed in filename, but adjust it back before returning */
54875 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54876 +{
54877 + struct name_entry *nmatch;
54878 + char *p, *lastp = NULL;
54879 + struct acl_object_label *obj = NULL, *tmp;
54880 + struct acl_subject_label *tmpsubj;
54881 + char c = '\0';
54882 +
54883 + read_lock(&gr_inode_lock);
54884 +
54885 + p = name + len - 1;
54886 + do {
54887 + nmatch = lookup_name_entry(name);
54888 + if (lastp != NULL)
54889 + *lastp = c;
54890 +
54891 + if (nmatch == NULL)
54892 + goto next_component;
54893 + tmpsubj = current->acl;
54894 + do {
54895 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54896 + if (obj != NULL) {
54897 + tmp = obj->globbed;
54898 + while (tmp) {
54899 + if (!glob_match(tmp->filename, name)) {
54900 + obj = tmp;
54901 + goto found_obj;
54902 + }
54903 + tmp = tmp->next;
54904 + }
54905 + goto found_obj;
54906 + }
54907 + } while ((tmpsubj = tmpsubj->parent_subject));
54908 +next_component:
54909 + /* end case */
54910 + if (p == name)
54911 + break;
54912 +
54913 + while (*p != '/')
54914 + p--;
54915 + if (p == name)
54916 + lastp = p + 1;
54917 + else {
54918 + lastp = p;
54919 + p--;
54920 + }
54921 + c = *lastp;
54922 + *lastp = '\0';
54923 + } while (1);
54924 +found_obj:
54925 + read_unlock(&gr_inode_lock);
54926 + /* obj returned will always be non-null */
54927 + return obj;
54928 +}
54929 +
54930 +/* returns 0 when allowing, non-zero on error
54931 + op of 0 is used for readdir, so we don't log the names of hidden files
54932 +*/
54933 +__u32
54934 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54935 +{
54936 + struct ctl_table *tmp;
54937 + const char *proc_sys = "/proc/sys";
54938 + char *path;
54939 + struct acl_object_label *obj;
54940 + unsigned short len = 0, pos = 0, depth = 0, i;
54941 + __u32 err = 0;
54942 + __u32 mode = 0;
54943 +
54944 + if (unlikely(!(gr_status & GR_READY)))
54945 + return 0;
54946 +
54947 + /* for now, ignore operations on non-sysctl entries if it's not a
54948 + readdir*/
54949 + if (table->child != NULL && op != 0)
54950 + return 0;
54951 +
54952 + mode |= GR_FIND;
54953 + /* it's only a read if it's an entry, read on dirs is for readdir */
54954 + if (op & MAY_READ)
54955 + mode |= GR_READ;
54956 + if (op & MAY_WRITE)
54957 + mode |= GR_WRITE;
54958 +
54959 + preempt_disable();
54960 +
54961 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54962 +
54963 + /* it's only a read/write if it's an actual entry, not a dir
54964 + (which are opened for readdir)
54965 + */
54966 +
54967 + /* convert the requested sysctl entry into a pathname */
54968 +
54969 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54970 + len += strlen(tmp->procname);
54971 + len++;
54972 + depth++;
54973 + }
54974 +
54975 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54976 + /* deny */
54977 + goto out;
54978 + }
54979 +
54980 + memset(path, 0, PAGE_SIZE);
54981 +
54982 + memcpy(path, proc_sys, strlen(proc_sys));
54983 +
54984 + pos += strlen(proc_sys);
54985 +
54986 + for (; depth > 0; depth--) {
54987 + path[pos] = '/';
54988 + pos++;
54989 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54990 + if (depth == i) {
54991 + memcpy(path + pos, tmp->procname,
54992 + strlen(tmp->procname));
54993 + pos += strlen(tmp->procname);
54994 + }
54995 + i++;
54996 + }
54997 + }
54998 +
54999 + obj = gr_lookup_by_name(path, pos);
55000 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
55001 +
55002 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
55003 + ((err & mode) != mode))) {
55004 + __u32 new_mode = mode;
55005 +
55006 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55007 +
55008 + err = 0;
55009 + gr_log_learn_sysctl(path, new_mode);
55010 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
55011 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
55012 + err = -ENOENT;
55013 + } else if (!(err & GR_FIND)) {
55014 + err = -ENOENT;
55015 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
55016 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
55017 + path, (mode & GR_READ) ? " reading" : "",
55018 + (mode & GR_WRITE) ? " writing" : "");
55019 + err = -EACCES;
55020 + } else if ((err & mode) != mode) {
55021 + err = -EACCES;
55022 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
55023 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
55024 + path, (mode & GR_READ) ? " reading" : "",
55025 + (mode & GR_WRITE) ? " writing" : "");
55026 + err = 0;
55027 + } else
55028 + err = 0;
55029 +
55030 + out:
55031 + preempt_enable();
55032 +
55033 + return err;
55034 +}
55035 +#endif
55036 +
55037 +int
55038 +gr_handle_proc_ptrace(struct task_struct *task)
55039 +{
55040 + struct file *filp;
55041 + struct task_struct *tmp = task;
55042 + struct task_struct *curtemp = current;
55043 + __u32 retmode;
55044 +
55045 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55046 + if (unlikely(!(gr_status & GR_READY)))
55047 + return 0;
55048 +#endif
55049 +
55050 + read_lock(&tasklist_lock);
55051 + read_lock(&grsec_exec_file_lock);
55052 + filp = task->exec_file;
55053 +
55054 + while (tmp->pid > 0) {
55055 + if (tmp == curtemp)
55056 + break;
55057 + tmp = tmp->real_parent;
55058 + }
55059 +
55060 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55061 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55062 + read_unlock(&grsec_exec_file_lock);
55063 + read_unlock(&tasklist_lock);
55064 + return 1;
55065 + }
55066 +
55067 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55068 + if (!(gr_status & GR_READY)) {
55069 + read_unlock(&grsec_exec_file_lock);
55070 + read_unlock(&tasklist_lock);
55071 + return 0;
55072 + }
55073 +#endif
55074 +
55075 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55076 + read_unlock(&grsec_exec_file_lock);
55077 + read_unlock(&tasklist_lock);
55078 +
55079 + if (retmode & GR_NOPTRACE)
55080 + return 1;
55081 +
55082 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55083 + && (current->acl != task->acl || (current->acl != current->role->root_label
55084 + && current->pid != task->pid)))
55085 + return 1;
55086 +
55087 + return 0;
55088 +}
55089 +
55090 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55091 +{
55092 + if (unlikely(!(gr_status & GR_READY)))
55093 + return;
55094 +
55095 + if (!(current->role->roletype & GR_ROLE_GOD))
55096 + return;
55097 +
55098 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55099 + p->role->rolename, gr_task_roletype_to_char(p),
55100 + p->acl->filename);
55101 +}
55102 +
55103 +int
55104 +gr_handle_ptrace(struct task_struct *task, const long request)
55105 +{
55106 + struct task_struct *tmp = task;
55107 + struct task_struct *curtemp = current;
55108 + __u32 retmode;
55109 +
55110 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55111 + if (unlikely(!(gr_status & GR_READY)))
55112 + return 0;
55113 +#endif
55114 +
55115 + read_lock(&tasklist_lock);
55116 + while (tmp->pid > 0) {
55117 + if (tmp == curtemp)
55118 + break;
55119 + tmp = tmp->real_parent;
55120 + }
55121 +
55122 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55123 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55124 + read_unlock(&tasklist_lock);
55125 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55126 + return 1;
55127 + }
55128 + read_unlock(&tasklist_lock);
55129 +
55130 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55131 + if (!(gr_status & GR_READY))
55132 + return 0;
55133 +#endif
55134 +
55135 + read_lock(&grsec_exec_file_lock);
55136 + if (unlikely(!task->exec_file)) {
55137 + read_unlock(&grsec_exec_file_lock);
55138 + return 0;
55139 + }
55140 +
55141 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55142 + read_unlock(&grsec_exec_file_lock);
55143 +
55144 + if (retmode & GR_NOPTRACE) {
55145 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55146 + return 1;
55147 + }
55148 +
55149 + if (retmode & GR_PTRACERD) {
55150 + switch (request) {
55151 + case PTRACE_POKETEXT:
55152 + case PTRACE_POKEDATA:
55153 + case PTRACE_POKEUSR:
55154 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55155 + case PTRACE_SETREGS:
55156 + case PTRACE_SETFPREGS:
55157 +#endif
55158 +#ifdef CONFIG_X86
55159 + case PTRACE_SETFPXREGS:
55160 +#endif
55161 +#ifdef CONFIG_ALTIVEC
55162 + case PTRACE_SETVRREGS:
55163 +#endif
55164 + return 1;
55165 + default:
55166 + return 0;
55167 + }
55168 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55169 + !(current->role->roletype & GR_ROLE_GOD) &&
55170 + (current->acl != task->acl)) {
55171 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55172 + return 1;
55173 + }
55174 +
55175 + return 0;
55176 +}
55177 +
55178 +static int is_writable_mmap(const struct file *filp)
55179 +{
55180 + struct task_struct *task = current;
55181 + struct acl_object_label *obj, *obj2;
55182 +
55183 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55184 + !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))) {
55185 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55186 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55187 + task->role->root_label);
55188 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55189 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55190 + return 1;
55191 + }
55192 + }
55193 + return 0;
55194 +}
55195 +
55196 +int
55197 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55198 +{
55199 + __u32 mode;
55200 +
55201 + if (unlikely(!file || !(prot & PROT_EXEC)))
55202 + return 1;
55203 +
55204 + if (is_writable_mmap(file))
55205 + return 0;
55206 +
55207 + mode =
55208 + gr_search_file(file->f_path.dentry,
55209 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55210 + file->f_path.mnt);
55211 +
55212 + if (!gr_tpe_allow(file))
55213 + return 0;
55214 +
55215 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55216 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55217 + return 0;
55218 + } else if (unlikely(!(mode & GR_EXEC))) {
55219 + return 0;
55220 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55221 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55222 + return 1;
55223 + }
55224 +
55225 + return 1;
55226 +}
55227 +
55228 +int
55229 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55230 +{
55231 + __u32 mode;
55232 +
55233 + if (unlikely(!file || !(prot & PROT_EXEC)))
55234 + return 1;
55235 +
55236 + if (is_writable_mmap(file))
55237 + return 0;
55238 +
55239 + mode =
55240 + gr_search_file(file->f_path.dentry,
55241 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55242 + file->f_path.mnt);
55243 +
55244 + if (!gr_tpe_allow(file))
55245 + return 0;
55246 +
55247 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55248 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55249 + return 0;
55250 + } else if (unlikely(!(mode & GR_EXEC))) {
55251 + return 0;
55252 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55253 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55254 + return 1;
55255 + }
55256 +
55257 + return 1;
55258 +}
55259 +
55260 +void
55261 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55262 +{
55263 + unsigned long runtime;
55264 + unsigned long cputime;
55265 + unsigned int wday, cday;
55266 + __u8 whr, chr;
55267 + __u8 wmin, cmin;
55268 + __u8 wsec, csec;
55269 + struct timespec timeval;
55270 +
55271 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55272 + !(task->acl->mode & GR_PROCACCT)))
55273 + return;
55274 +
55275 + do_posix_clock_monotonic_gettime(&timeval);
55276 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55277 + wday = runtime / (3600 * 24);
55278 + runtime -= wday * (3600 * 24);
55279 + whr = runtime / 3600;
55280 + runtime -= whr * 3600;
55281 + wmin = runtime / 60;
55282 + runtime -= wmin * 60;
55283 + wsec = runtime;
55284 +
55285 + cputime = (task->utime + task->stime) / HZ;
55286 + cday = cputime / (3600 * 24);
55287 + cputime -= cday * (3600 * 24);
55288 + chr = cputime / 3600;
55289 + cputime -= chr * 3600;
55290 + cmin = cputime / 60;
55291 + cputime -= cmin * 60;
55292 + csec = cputime;
55293 +
55294 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55295 +
55296 + return;
55297 +}
55298 +
55299 +void gr_set_kernel_label(struct task_struct *task)
55300 +{
55301 + if (gr_status & GR_READY) {
55302 + task->role = kernel_role;
55303 + task->acl = kernel_role->root_label;
55304 + }
55305 + return;
55306 +}
55307 +
55308 +#ifdef CONFIG_TASKSTATS
55309 +int gr_is_taskstats_denied(int pid)
55310 +{
55311 + struct task_struct *task;
55312 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55313 + const struct cred *cred;
55314 +#endif
55315 + int ret = 0;
55316 +
55317 + /* restrict taskstats viewing to un-chrooted root users
55318 + who have the 'view' subject flag if the RBAC system is enabled
55319 + */
55320 +
55321 + rcu_read_lock();
55322 + read_lock(&tasklist_lock);
55323 + task = find_task_by_vpid(pid);
55324 + if (task) {
55325 +#ifdef CONFIG_GRKERNSEC_CHROOT
55326 + if (proc_is_chrooted(task))
55327 + ret = -EACCES;
55328 +#endif
55329 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55330 + cred = __task_cred(task);
55331 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55332 + if (cred->uid != 0)
55333 + ret = -EACCES;
55334 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55335 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55336 + ret = -EACCES;
55337 +#endif
55338 +#endif
55339 + if (gr_status & GR_READY) {
55340 + if (!(task->acl->mode & GR_VIEW))
55341 + ret = -EACCES;
55342 + }
55343 + } else
55344 + ret = -ENOENT;
55345 +
55346 + read_unlock(&tasklist_lock);
55347 + rcu_read_unlock();
55348 +
55349 + return ret;
55350 +}
55351 +#endif
55352 +
55353 +/* AUXV entries are filled via a descendant of search_binary_handler
55354 + after we've already applied the subject for the target
55355 +*/
55356 +int gr_acl_enable_at_secure(void)
55357 +{
55358 + if (unlikely(!(gr_status & GR_READY)))
55359 + return 0;
55360 +
55361 + if (current->acl->mode & GR_ATSECURE)
55362 + return 1;
55363 +
55364 + return 0;
55365 +}
55366 +
55367 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55368 +{
55369 + struct task_struct *task = current;
55370 + struct dentry *dentry = file->f_path.dentry;
55371 + struct vfsmount *mnt = file->f_path.mnt;
55372 + struct acl_object_label *obj, *tmp;
55373 + struct acl_subject_label *subj;
55374 + unsigned int bufsize;
55375 + int is_not_root;
55376 + char *path;
55377 + dev_t dev = __get_dev(dentry);
55378 +
55379 + if (unlikely(!(gr_status & GR_READY)))
55380 + return 1;
55381 +
55382 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55383 + return 1;
55384 +
55385 + /* ignore Eric Biederman */
55386 + if (IS_PRIVATE(dentry->d_inode))
55387 + return 1;
55388 +
55389 + subj = task->acl;
55390 + do {
55391 + obj = lookup_acl_obj_label(ino, dev, subj);
55392 + if (obj != NULL)
55393 + return (obj->mode & GR_FIND) ? 1 : 0;
55394 + } while ((subj = subj->parent_subject));
55395 +
55396 + /* this is purely an optimization since we're looking for an object
55397 + for the directory we're doing a readdir on
55398 + if it's possible for any globbed object to match the entry we're
55399 + filling into the directory, then the object we find here will be
55400 + an anchor point with attached globbed objects
55401 + */
55402 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55403 + if (obj->globbed == NULL)
55404 + return (obj->mode & GR_FIND) ? 1 : 0;
55405 +
55406 + is_not_root = ((obj->filename[0] == '/') &&
55407 + (obj->filename[1] == '\0')) ? 0 : 1;
55408 + bufsize = PAGE_SIZE - namelen - is_not_root;
55409 +
55410 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55411 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55412 + return 1;
55413 +
55414 + preempt_disable();
55415 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55416 + bufsize);
55417 +
55418 + bufsize = strlen(path);
55419 +
55420 + /* if base is "/", don't append an additional slash */
55421 + if (is_not_root)
55422 + *(path + bufsize) = '/';
55423 + memcpy(path + bufsize + is_not_root, name, namelen);
55424 + *(path + bufsize + namelen + is_not_root) = '\0';
55425 +
55426 + tmp = obj->globbed;
55427 + while (tmp) {
55428 + if (!glob_match(tmp->filename, path)) {
55429 + preempt_enable();
55430 + return (tmp->mode & GR_FIND) ? 1 : 0;
55431 + }
55432 + tmp = tmp->next;
55433 + }
55434 + preempt_enable();
55435 + return (obj->mode & GR_FIND) ? 1 : 0;
55436 +}
55437 +
55438 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55439 +EXPORT_SYMBOL(gr_acl_is_enabled);
55440 +#endif
55441 +EXPORT_SYMBOL(gr_learn_resource);
55442 +EXPORT_SYMBOL(gr_set_kernel_label);
55443 +#ifdef CONFIG_SECURITY
55444 +EXPORT_SYMBOL(gr_check_user_change);
55445 +EXPORT_SYMBOL(gr_check_group_change);
55446 +#endif
55447 +
55448 diff -urNp linux-2.6.39.1/grsecurity/gracl_cap.c linux-2.6.39.1/grsecurity/gracl_cap.c
55449 --- linux-2.6.39.1/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
55450 +++ linux-2.6.39.1/grsecurity/gracl_cap.c 2011-05-22 19:41:42.000000000 -0400
55451 @@ -0,0 +1,139 @@
55452 +#include <linux/kernel.h>
55453 +#include <linux/module.h>
55454 +#include <linux/sched.h>
55455 +#include <linux/gracl.h>
55456 +#include <linux/grsecurity.h>
55457 +#include <linux/grinternal.h>
55458 +
55459 +static const char *captab_log[] = {
55460 + "CAP_CHOWN",
55461 + "CAP_DAC_OVERRIDE",
55462 + "CAP_DAC_READ_SEARCH",
55463 + "CAP_FOWNER",
55464 + "CAP_FSETID",
55465 + "CAP_KILL",
55466 + "CAP_SETGID",
55467 + "CAP_SETUID",
55468 + "CAP_SETPCAP",
55469 + "CAP_LINUX_IMMUTABLE",
55470 + "CAP_NET_BIND_SERVICE",
55471 + "CAP_NET_BROADCAST",
55472 + "CAP_NET_ADMIN",
55473 + "CAP_NET_RAW",
55474 + "CAP_IPC_LOCK",
55475 + "CAP_IPC_OWNER",
55476 + "CAP_SYS_MODULE",
55477 + "CAP_SYS_RAWIO",
55478 + "CAP_SYS_CHROOT",
55479 + "CAP_SYS_PTRACE",
55480 + "CAP_SYS_PACCT",
55481 + "CAP_SYS_ADMIN",
55482 + "CAP_SYS_BOOT",
55483 + "CAP_SYS_NICE",
55484 + "CAP_SYS_RESOURCE",
55485 + "CAP_SYS_TIME",
55486 + "CAP_SYS_TTY_CONFIG",
55487 + "CAP_MKNOD",
55488 + "CAP_LEASE",
55489 + "CAP_AUDIT_WRITE",
55490 + "CAP_AUDIT_CONTROL",
55491 + "CAP_SETFCAP",
55492 + "CAP_MAC_OVERRIDE",
55493 + "CAP_MAC_ADMIN",
55494 + "CAP_SYSLOG"
55495 +};
55496 +
55497 +EXPORT_SYMBOL(gr_is_capable);
55498 +EXPORT_SYMBOL(gr_is_capable_nolog);
55499 +
55500 +int
55501 +gr_is_capable(const int cap)
55502 +{
55503 + struct task_struct *task = current;
55504 + const struct cred *cred = current_cred();
55505 + struct acl_subject_label *curracl;
55506 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55507 + kernel_cap_t cap_audit = __cap_empty_set;
55508 +
55509 + if (!gr_acl_is_enabled())
55510 + return 1;
55511 +
55512 + curracl = task->acl;
55513 +
55514 + cap_drop = curracl->cap_lower;
55515 + cap_mask = curracl->cap_mask;
55516 + cap_audit = curracl->cap_invert_audit;
55517 +
55518 + while ((curracl = curracl->parent_subject)) {
55519 + /* if the cap isn't specified in the current computed mask but is specified in the
55520 + current level subject, and is lowered in the current level subject, then add
55521 + it to the set of dropped capabilities
55522 + otherwise, add the current level subject's mask to the current computed mask
55523 + */
55524 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55525 + cap_raise(cap_mask, cap);
55526 + if (cap_raised(curracl->cap_lower, cap))
55527 + cap_raise(cap_drop, cap);
55528 + if (cap_raised(curracl->cap_invert_audit, cap))
55529 + cap_raise(cap_audit, cap);
55530 + }
55531 + }
55532 +
55533 + if (!cap_raised(cap_drop, cap)) {
55534 + if (cap_raised(cap_audit, cap))
55535 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55536 + return 1;
55537 + }
55538 +
55539 + curracl = task->acl;
55540 +
55541 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55542 + && cap_raised(cred->cap_effective, cap)) {
55543 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55544 + task->role->roletype, cred->uid,
55545 + cred->gid, task->exec_file ?
55546 + gr_to_filename(task->exec_file->f_path.dentry,
55547 + task->exec_file->f_path.mnt) : curracl->filename,
55548 + curracl->filename, 0UL,
55549 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55550 + return 1;
55551 + }
55552 +
55553 + if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55554 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55555 + return 0;
55556 +}
55557 +
55558 +int
55559 +gr_is_capable_nolog(const int cap)
55560 +{
55561 + struct acl_subject_label *curracl;
55562 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55563 +
55564 + if (!gr_acl_is_enabled())
55565 + return 1;
55566 +
55567 + curracl = current->acl;
55568 +
55569 + cap_drop = curracl->cap_lower;
55570 + cap_mask = curracl->cap_mask;
55571 +
55572 + while ((curracl = curracl->parent_subject)) {
55573 + /* if the cap isn't specified in the current computed mask but is specified in the
55574 + current level subject, and is lowered in the current level subject, then add
55575 + it to the set of dropped capabilities
55576 + otherwise, add the current level subject's mask to the current computed mask
55577 + */
55578 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55579 + cap_raise(cap_mask, cap);
55580 + if (cap_raised(curracl->cap_lower, cap))
55581 + cap_raise(cap_drop, cap);
55582 + }
55583 + }
55584 +
55585 + if (!cap_raised(cap_drop, cap))
55586 + return 1;
55587 +
55588 + return 0;
55589 +}
55590 +
55591 diff -urNp linux-2.6.39.1/grsecurity/gracl_fs.c linux-2.6.39.1/grsecurity/gracl_fs.c
55592 --- linux-2.6.39.1/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
55593 +++ linux-2.6.39.1/grsecurity/gracl_fs.c 2011-05-22 19:41:42.000000000 -0400
55594 @@ -0,0 +1,431 @@
55595 +#include <linux/kernel.h>
55596 +#include <linux/sched.h>
55597 +#include <linux/types.h>
55598 +#include <linux/fs.h>
55599 +#include <linux/file.h>
55600 +#include <linux/stat.h>
55601 +#include <linux/grsecurity.h>
55602 +#include <linux/grinternal.h>
55603 +#include <linux/gracl.h>
55604 +
55605 +__u32
55606 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55607 + const struct vfsmount * mnt)
55608 +{
55609 + __u32 mode;
55610 +
55611 + if (unlikely(!dentry->d_inode))
55612 + return GR_FIND;
55613 +
55614 + mode =
55615 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55616 +
55617 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55618 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55619 + return mode;
55620 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55621 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55622 + return 0;
55623 + } else if (unlikely(!(mode & GR_FIND)))
55624 + return 0;
55625 +
55626 + return GR_FIND;
55627 +}
55628 +
55629 +__u32
55630 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55631 + const int fmode)
55632 +{
55633 + __u32 reqmode = GR_FIND;
55634 + __u32 mode;
55635 +
55636 + if (unlikely(!dentry->d_inode))
55637 + return reqmode;
55638 +
55639 + if (unlikely(fmode & O_APPEND))
55640 + reqmode |= GR_APPEND;
55641 + else if (unlikely(fmode & FMODE_WRITE))
55642 + reqmode |= GR_WRITE;
55643 + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55644 + reqmode |= GR_READ;
55645 + if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
55646 + reqmode &= ~GR_READ;
55647 + mode =
55648 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55649 + mnt);
55650 +
55651 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55652 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55653 + reqmode & GR_READ ? " reading" : "",
55654 + reqmode & GR_WRITE ? " writing" : reqmode &
55655 + GR_APPEND ? " appending" : "");
55656 + return reqmode;
55657 + } else
55658 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55659 + {
55660 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55661 + reqmode & GR_READ ? " reading" : "",
55662 + reqmode & GR_WRITE ? " writing" : reqmode &
55663 + GR_APPEND ? " appending" : "");
55664 + return 0;
55665 + } else if (unlikely((mode & reqmode) != reqmode))
55666 + return 0;
55667 +
55668 + return reqmode;
55669 +}
55670 +
55671 +__u32
55672 +gr_acl_handle_creat(const struct dentry * dentry,
55673 + const struct dentry * p_dentry,
55674 + const struct vfsmount * p_mnt, const int fmode,
55675 + const int imode)
55676 +{
55677 + __u32 reqmode = GR_WRITE | GR_CREATE;
55678 + __u32 mode;
55679 +
55680 + if (unlikely(fmode & O_APPEND))
55681 + reqmode |= GR_APPEND;
55682 + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55683 + reqmode |= GR_READ;
55684 + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
55685 + reqmode |= GR_SETID;
55686 +
55687 + mode =
55688 + gr_check_create(dentry, p_dentry, p_mnt,
55689 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55690 +
55691 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55692 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55693 + reqmode & GR_READ ? " reading" : "",
55694 + reqmode & GR_WRITE ? " writing" : reqmode &
55695 + GR_APPEND ? " appending" : "");
55696 + return reqmode;
55697 + } else
55698 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55699 + {
55700 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55701 + reqmode & GR_READ ? " reading" : "",
55702 + reqmode & GR_WRITE ? " writing" : reqmode &
55703 + GR_APPEND ? " appending" : "");
55704 + return 0;
55705 + } else if (unlikely((mode & reqmode) != reqmode))
55706 + return 0;
55707 +
55708 + return reqmode;
55709 +}
55710 +
55711 +__u32
55712 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55713 + const int fmode)
55714 +{
55715 + __u32 mode, reqmode = GR_FIND;
55716 +
55717 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55718 + reqmode |= GR_EXEC;
55719 + if (fmode & S_IWOTH)
55720 + reqmode |= GR_WRITE;
55721 + if (fmode & S_IROTH)
55722 + reqmode |= GR_READ;
55723 +
55724 + mode =
55725 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55726 + mnt);
55727 +
55728 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55729 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55730 + reqmode & GR_READ ? " reading" : "",
55731 + reqmode & GR_WRITE ? " writing" : "",
55732 + reqmode & GR_EXEC ? " executing" : "");
55733 + return reqmode;
55734 + } else
55735 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55736 + {
55737 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55738 + reqmode & GR_READ ? " reading" : "",
55739 + reqmode & GR_WRITE ? " writing" : "",
55740 + reqmode & GR_EXEC ? " executing" : "");
55741 + return 0;
55742 + } else if (unlikely((mode & reqmode) != reqmode))
55743 + return 0;
55744 +
55745 + return reqmode;
55746 +}
55747 +
55748 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55749 +{
55750 + __u32 mode;
55751 +
55752 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55753 +
55754 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55755 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55756 + return mode;
55757 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55758 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55759 + return 0;
55760 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55761 + return 0;
55762 +
55763 + return (reqmode);
55764 +}
55765 +
55766 +__u32
55767 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55768 +{
55769 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55770 +}
55771 +
55772 +__u32
55773 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55774 +{
55775 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55776 +}
55777 +
55778 +__u32
55779 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55780 +{
55781 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55782 +}
55783 +
55784 +__u32
55785 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55786 +{
55787 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55788 +}
55789 +
55790 +__u32
55791 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55792 + mode_t mode)
55793 +{
55794 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55795 + return 1;
55796 +
55797 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55798 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55799 + GR_FCHMOD_ACL_MSG);
55800 + } else {
55801 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55802 + }
55803 +}
55804 +
55805 +__u32
55806 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55807 + mode_t mode)
55808 +{
55809 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55810 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55811 + GR_CHMOD_ACL_MSG);
55812 + } else {
55813 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55814 + }
55815 +}
55816 +
55817 +__u32
55818 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55819 +{
55820 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55821 +}
55822 +
55823 +__u32
55824 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55825 +{
55826 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55827 +}
55828 +
55829 +__u32
55830 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55831 +{
55832 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55833 +}
55834 +
55835 +__u32
55836 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55837 +{
55838 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55839 + GR_UNIXCONNECT_ACL_MSG);
55840 +}
55841 +
55842 +/* hardlinks require at minimum create permission,
55843 + any additional privilege required is based on the
55844 + privilege of the file being linked to
55845 +*/
55846 +__u32
55847 +gr_acl_handle_link(const struct dentry * new_dentry,
55848 + const struct dentry * parent_dentry,
55849 + const struct vfsmount * parent_mnt,
55850 + const struct dentry * old_dentry,
55851 + const struct vfsmount * old_mnt, const char *to)
55852 +{
55853 + __u32 mode;
55854 + __u32 needmode = GR_CREATE | GR_LINK;
55855 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55856 +
55857 + mode =
55858 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55859 + old_mnt);
55860 +
55861 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55862 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55863 + return mode;
55864 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55865 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55866 + return 0;
55867 + } else if (unlikely((mode & needmode) != needmode))
55868 + return 0;
55869 +
55870 + return 1;
55871 +}
55872 +
55873 +__u32
55874 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55875 + const struct dentry * parent_dentry,
55876 + const struct vfsmount * parent_mnt, const char *from)
55877 +{
55878 + __u32 needmode = GR_WRITE | GR_CREATE;
55879 + __u32 mode;
55880 +
55881 + mode =
55882 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55883 + GR_CREATE | GR_AUDIT_CREATE |
55884 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55885 +
55886 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55887 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55888 + return mode;
55889 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55890 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55891 + return 0;
55892 + } else if (unlikely((mode & needmode) != needmode))
55893 + return 0;
55894 +
55895 + return (GR_WRITE | GR_CREATE);
55896 +}
55897 +
55898 +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)
55899 +{
55900 + __u32 mode;
55901 +
55902 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55903 +
55904 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55905 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55906 + return mode;
55907 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55908 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55909 + return 0;
55910 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55911 + return 0;
55912 +
55913 + return (reqmode);
55914 +}
55915 +
55916 +__u32
55917 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55918 + const struct dentry * parent_dentry,
55919 + const struct vfsmount * parent_mnt,
55920 + const int mode)
55921 +{
55922 + __u32 reqmode = GR_WRITE | GR_CREATE;
55923 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55924 + reqmode |= GR_SETID;
55925 +
55926 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55927 + reqmode, GR_MKNOD_ACL_MSG);
55928 +}
55929 +
55930 +__u32
55931 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55932 + const struct dentry *parent_dentry,
55933 + const struct vfsmount *parent_mnt)
55934 +{
55935 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55936 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55937 +}
55938 +
55939 +#define RENAME_CHECK_SUCCESS(old, new) \
55940 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55941 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55942 +
55943 +int
55944 +gr_acl_handle_rename(struct dentry *new_dentry,
55945 + struct dentry *parent_dentry,
55946 + const struct vfsmount *parent_mnt,
55947 + struct dentry *old_dentry,
55948 + struct inode *old_parent_inode,
55949 + struct vfsmount *old_mnt, const char *newname)
55950 +{
55951 + __u32 comp1, comp2;
55952 + int error = 0;
55953 +
55954 + if (unlikely(!gr_acl_is_enabled()))
55955 + return 0;
55956 +
55957 + if (!new_dentry->d_inode) {
55958 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55959 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55960 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55961 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55962 + GR_DELETE | GR_AUDIT_DELETE |
55963 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55964 + GR_SUPPRESS, old_mnt);
55965 + } else {
55966 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55967 + GR_CREATE | GR_DELETE |
55968 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55969 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55970 + GR_SUPPRESS, parent_mnt);
55971 + comp2 =
55972 + gr_search_file(old_dentry,
55973 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55974 + GR_DELETE | GR_AUDIT_DELETE |
55975 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55976 + }
55977 +
55978 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55979 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55980 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55981 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55982 + && !(comp2 & GR_SUPPRESS)) {
55983 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55984 + error = -EACCES;
55985 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55986 + error = -EACCES;
55987 +
55988 + return error;
55989 +}
55990 +
55991 +void
55992 +gr_acl_handle_exit(void)
55993 +{
55994 + u16 id;
55995 + char *rolename;
55996 + struct file *exec_file;
55997 +
55998 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55999 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56000 + id = current->acl_role_id;
56001 + rolename = current->role->rolename;
56002 + gr_set_acls(1);
56003 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56004 + }
56005 +
56006 + write_lock(&grsec_exec_file_lock);
56007 + exec_file = current->exec_file;
56008 + current->exec_file = NULL;
56009 + write_unlock(&grsec_exec_file_lock);
56010 +
56011 + if (exec_file)
56012 + fput(exec_file);
56013 +}
56014 +
56015 +int
56016 +gr_acl_handle_procpidmem(const struct task_struct *task)
56017 +{
56018 + if (unlikely(!gr_acl_is_enabled()))
56019 + return 0;
56020 +
56021 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56022 + return -EACCES;
56023 +
56024 + return 0;
56025 +}
56026 diff -urNp linux-2.6.39.1/grsecurity/gracl_ip.c linux-2.6.39.1/grsecurity/gracl_ip.c
56027 --- linux-2.6.39.1/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
56028 +++ linux-2.6.39.1/grsecurity/gracl_ip.c 2011-05-22 22:47:31.000000000 -0400
56029 @@ -0,0 +1,381 @@
56030 +#include <linux/kernel.h>
56031 +#include <asm/uaccess.h>
56032 +#include <asm/errno.h>
56033 +#include <net/sock.h>
56034 +#include <linux/file.h>
56035 +#include <linux/fs.h>
56036 +#include <linux/net.h>
56037 +#include <linux/in.h>
56038 +#include <linux/skbuff.h>
56039 +#include <linux/ip.h>
56040 +#include <linux/udp.h>
56041 +#include <linux/types.h>
56042 +#include <linux/sched.h>
56043 +#include <linux/netdevice.h>
56044 +#include <linux/inetdevice.h>
56045 +#include <linux/gracl.h>
56046 +#include <linux/grsecurity.h>
56047 +#include <linux/grinternal.h>
56048 +
56049 +#define GR_BIND 0x01
56050 +#define GR_CONNECT 0x02
56051 +#define GR_INVERT 0x04
56052 +#define GR_BINDOVERRIDE 0x08
56053 +#define GR_CONNECTOVERRIDE 0x10
56054 +#define GR_SOCK_FAMILY 0x20
56055 +
56056 +static const char * gr_protocols[IPPROTO_MAX] = {
56057 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56058 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56059 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56060 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56061 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56062 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56063 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56064 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56065 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56066 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56067 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56068 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56069 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56070 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56071 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56072 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56073 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56074 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56075 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56076 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56077 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56078 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56079 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56080 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56081 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56082 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56083 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56084 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56085 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56086 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56087 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56088 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56089 + };
56090 +
56091 +static const char * gr_socktypes[SOCK_MAX] = {
56092 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56093 + "unknown:7", "unknown:8", "unknown:9", "packet"
56094 + };
56095 +
56096 +static const char * gr_sockfamilies[AF_MAX+1] = {
56097 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56098 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56099 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56100 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56101 + };
56102 +
56103 +const char *
56104 +gr_proto_to_name(unsigned char proto)
56105 +{
56106 + return gr_protocols[proto];
56107 +}
56108 +
56109 +const char *
56110 +gr_socktype_to_name(unsigned char type)
56111 +{
56112 + return gr_socktypes[type];
56113 +}
56114 +
56115 +const char *
56116 +gr_sockfamily_to_name(unsigned char family)
56117 +{
56118 + return gr_sockfamilies[family];
56119 +}
56120 +
56121 +int
56122 +gr_search_socket(const int domain, const int type, const int protocol)
56123 +{
56124 + struct acl_subject_label *curr;
56125 + const struct cred *cred = current_cred();
56126 +
56127 + if (unlikely(!gr_acl_is_enabled()))
56128 + goto exit;
56129 +
56130 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56131 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56132 + goto exit; // let the kernel handle it
56133 +
56134 + curr = current->acl;
56135 +
56136 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56137 + /* the family is allowed, if this is PF_INET allow it only if
56138 + the extra sock type/protocol checks pass */
56139 + if (domain == PF_INET)
56140 + goto inet_check;
56141 + goto exit;
56142 + } else {
56143 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56144 + __u32 fakeip = 0;
56145 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56146 + current->role->roletype, cred->uid,
56147 + cred->gid, current->exec_file ?
56148 + gr_to_filename(current->exec_file->f_path.dentry,
56149 + current->exec_file->f_path.mnt) :
56150 + curr->filename, curr->filename,
56151 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56152 + &current->signal->saved_ip);
56153 + goto exit;
56154 + }
56155 + goto exit_fail;
56156 + }
56157 +
56158 +inet_check:
56159 + /* the rest of this checking is for IPv4 only */
56160 + if (!curr->ips)
56161 + goto exit;
56162 +
56163 + if ((curr->ip_type & (1 << type)) &&
56164 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56165 + goto exit;
56166 +
56167 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56168 + /* we don't place acls on raw sockets , and sometimes
56169 + dgram/ip sockets are opened for ioctl and not
56170 + bind/connect, so we'll fake a bind learn log */
56171 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56172 + __u32 fakeip = 0;
56173 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56174 + current->role->roletype, cred->uid,
56175 + cred->gid, current->exec_file ?
56176 + gr_to_filename(current->exec_file->f_path.dentry,
56177 + current->exec_file->f_path.mnt) :
56178 + curr->filename, curr->filename,
56179 + &fakeip, 0, type,
56180 + protocol, GR_CONNECT, &current->signal->saved_ip);
56181 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56182 + __u32 fakeip = 0;
56183 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56184 + current->role->roletype, cred->uid,
56185 + cred->gid, current->exec_file ?
56186 + gr_to_filename(current->exec_file->f_path.dentry,
56187 + current->exec_file->f_path.mnt) :
56188 + curr->filename, curr->filename,
56189 + &fakeip, 0, type,
56190 + protocol, GR_BIND, &current->signal->saved_ip);
56191 + }
56192 + /* we'll log when they use connect or bind */
56193 + goto exit;
56194 + }
56195 +
56196 +exit_fail:
56197 + if (domain == PF_INET)
56198 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56199 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56200 + else
56201 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56202 + gr_socktype_to_name(type), protocol);
56203 +
56204 + return 0;
56205 +exit:
56206 + return 1;
56207 +}
56208 +
56209 +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)
56210 +{
56211 + if ((ip->mode & mode) &&
56212 + (ip_port >= ip->low) &&
56213 + (ip_port <= ip->high) &&
56214 + ((ntohl(ip_addr) & our_netmask) ==
56215 + (ntohl(our_addr) & our_netmask))
56216 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56217 + && (ip->type & (1 << type))) {
56218 + if (ip->mode & GR_INVERT)
56219 + return 2; // specifically denied
56220 + else
56221 + return 1; // allowed
56222 + }
56223 +
56224 + return 0; // not specifically allowed, may continue parsing
56225 +}
56226 +
56227 +static int
56228 +gr_search_connectbind(const int full_mode, struct sock *sk,
56229 + struct sockaddr_in *addr, const int type)
56230 +{
56231 + char iface[IFNAMSIZ] = {0};
56232 + struct acl_subject_label *curr;
56233 + struct acl_ip_label *ip;
56234 + struct inet_sock *isk;
56235 + struct net_device *dev;
56236 + struct in_device *idev;
56237 + unsigned long i;
56238 + int ret;
56239 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56240 + __u32 ip_addr = 0;
56241 + __u32 our_addr;
56242 + __u32 our_netmask;
56243 + char *p;
56244 + __u16 ip_port = 0;
56245 + const struct cred *cred = current_cred();
56246 +
56247 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56248 + return 0;
56249 +
56250 + curr = current->acl;
56251 + isk = inet_sk(sk);
56252 +
56253 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56254 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56255 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56256 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56257 + struct sockaddr_in saddr;
56258 + int err;
56259 +
56260 + saddr.sin_family = AF_INET;
56261 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56262 + saddr.sin_port = isk->inet_sport;
56263 +
56264 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56265 + if (err)
56266 + return err;
56267 +
56268 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56269 + if (err)
56270 + return err;
56271 + }
56272 +
56273 + if (!curr->ips)
56274 + return 0;
56275 +
56276 + ip_addr = addr->sin_addr.s_addr;
56277 + ip_port = ntohs(addr->sin_port);
56278 +
56279 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56280 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56281 + current->role->roletype, cred->uid,
56282 + cred->gid, current->exec_file ?
56283 + gr_to_filename(current->exec_file->f_path.dentry,
56284 + current->exec_file->f_path.mnt) :
56285 + curr->filename, curr->filename,
56286 + &ip_addr, ip_port, type,
56287 + sk->sk_protocol, mode, &current->signal->saved_ip);
56288 + return 0;
56289 + }
56290 +
56291 + for (i = 0; i < curr->ip_num; i++) {
56292 + ip = *(curr->ips + i);
56293 + if (ip->iface != NULL) {
56294 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56295 + p = strchr(iface, ':');
56296 + if (p != NULL)
56297 + *p = '\0';
56298 + dev = dev_get_by_name(sock_net(sk), iface);
56299 + if (dev == NULL)
56300 + continue;
56301 + idev = in_dev_get(dev);
56302 + if (idev == NULL) {
56303 + dev_put(dev);
56304 + continue;
56305 + }
56306 + rcu_read_lock();
56307 + for_ifa(idev) {
56308 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56309 + our_addr = ifa->ifa_address;
56310 + our_netmask = 0xffffffff;
56311 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56312 + if (ret == 1) {
56313 + rcu_read_unlock();
56314 + in_dev_put(idev);
56315 + dev_put(dev);
56316 + return 0;
56317 + } else if (ret == 2) {
56318 + rcu_read_unlock();
56319 + in_dev_put(idev);
56320 + dev_put(dev);
56321 + goto denied;
56322 + }
56323 + }
56324 + } endfor_ifa(idev);
56325 + rcu_read_unlock();
56326 + in_dev_put(idev);
56327 + dev_put(dev);
56328 + } else {
56329 + our_addr = ip->addr;
56330 + our_netmask = ip->netmask;
56331 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56332 + if (ret == 1)
56333 + return 0;
56334 + else if (ret == 2)
56335 + goto denied;
56336 + }
56337 + }
56338 +
56339 +denied:
56340 + if (mode == GR_BIND)
56341 + 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));
56342 + else if (mode == GR_CONNECT)
56343 + 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));
56344 +
56345 + return -EACCES;
56346 +}
56347 +
56348 +int
56349 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56350 +{
56351 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56352 +}
56353 +
56354 +int
56355 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56356 +{
56357 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56358 +}
56359 +
56360 +int gr_search_listen(struct socket *sock)
56361 +{
56362 + struct sock *sk = sock->sk;
56363 + struct sockaddr_in addr;
56364 +
56365 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56366 + addr.sin_port = inet_sk(sk)->inet_sport;
56367 +
56368 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56369 +}
56370 +
56371 +int gr_search_accept(struct socket *sock)
56372 +{
56373 + struct sock *sk = sock->sk;
56374 + struct sockaddr_in addr;
56375 +
56376 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56377 + addr.sin_port = inet_sk(sk)->inet_sport;
56378 +
56379 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56380 +}
56381 +
56382 +int
56383 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56384 +{
56385 + if (addr)
56386 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56387 + else {
56388 + struct sockaddr_in sin;
56389 + const struct inet_sock *inet = inet_sk(sk);
56390 +
56391 + sin.sin_addr.s_addr = inet->inet_daddr;
56392 + sin.sin_port = inet->inet_dport;
56393 +
56394 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56395 + }
56396 +}
56397 +
56398 +int
56399 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56400 +{
56401 + struct sockaddr_in sin;
56402 +
56403 + if (unlikely(skb->len < sizeof (struct udphdr)))
56404 + return 0; // skip this packet
56405 +
56406 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56407 + sin.sin_port = udp_hdr(skb)->source;
56408 +
56409 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56410 +}
56411 diff -urNp linux-2.6.39.1/grsecurity/gracl_learn.c linux-2.6.39.1/grsecurity/gracl_learn.c
56412 --- linux-2.6.39.1/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
56413 +++ linux-2.6.39.1/grsecurity/gracl_learn.c 2011-05-22 22:47:45.000000000 -0400
56414 @@ -0,0 +1,210 @@
56415 +#include <linux/kernel.h>
56416 +#include <linux/mm.h>
56417 +#include <linux/sched.h>
56418 +#include <linux/poll.h>
56419 +#include <linux/string.h>
56420 +#include <linux/file.h>
56421 +#include <linux/types.h>
56422 +#include <linux/vmalloc.h>
56423 +#include <linux/grinternal.h>
56424 +
56425 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56426 + size_t count, loff_t *ppos);
56427 +extern int gr_acl_is_enabled(void);
56428 +
56429 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56430 +static int gr_learn_attached;
56431 +
56432 +/* use a 512k buffer */
56433 +#define LEARN_BUFFER_SIZE (512 * 1024)
56434 +
56435 +static DEFINE_SPINLOCK(gr_learn_lock);
56436 +static DEFINE_MUTEX(gr_learn_user_mutex);
56437 +
56438 +/* we need to maintain two buffers, so that the kernel context of grlearn
56439 + uses a semaphore around the userspace copying, and the other kernel contexts
56440 + use a spinlock when copying into the buffer, since they cannot sleep
56441 +*/
56442 +static char *learn_buffer;
56443 +static char *learn_buffer_user;
56444 +static int learn_buffer_len;
56445 +static int learn_buffer_user_len;
56446 +
56447 +static ssize_t
56448 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56449 +{
56450 + DECLARE_WAITQUEUE(wait, current);
56451 + ssize_t retval = 0;
56452 +
56453 + add_wait_queue(&learn_wait, &wait);
56454 + set_current_state(TASK_INTERRUPTIBLE);
56455 + do {
56456 + mutex_lock(&gr_learn_user_mutex);
56457 + spin_lock(&gr_learn_lock);
56458 + if (learn_buffer_len)
56459 + break;
56460 + spin_unlock(&gr_learn_lock);
56461 + mutex_unlock(&gr_learn_user_mutex);
56462 + if (file->f_flags & O_NONBLOCK) {
56463 + retval = -EAGAIN;
56464 + goto out;
56465 + }
56466 + if (signal_pending(current)) {
56467 + retval = -ERESTARTSYS;
56468 + goto out;
56469 + }
56470 +
56471 + schedule();
56472 + } while (1);
56473 +
56474 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56475 + learn_buffer_user_len = learn_buffer_len;
56476 + retval = learn_buffer_len;
56477 + learn_buffer_len = 0;
56478 +
56479 + spin_unlock(&gr_learn_lock);
56480 +
56481 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56482 + retval = -EFAULT;
56483 +
56484 + mutex_unlock(&gr_learn_user_mutex);
56485 +out:
56486 + set_current_state(TASK_RUNNING);
56487 + remove_wait_queue(&learn_wait, &wait);
56488 + return retval;
56489 +}
56490 +
56491 +static unsigned int
56492 +poll_learn(struct file * file, poll_table * wait)
56493 +{
56494 + poll_wait(file, &learn_wait, wait);
56495 +
56496 + if (learn_buffer_len)
56497 + return (POLLIN | POLLRDNORM);
56498 +
56499 + return 0;
56500 +}
56501 +
56502 +void
56503 +gr_clear_learn_entries(void)
56504 +{
56505 + char *tmp;
56506 +
56507 + mutex_lock(&gr_learn_user_mutex);
56508 + if (learn_buffer != NULL) {
56509 + spin_lock(&gr_learn_lock);
56510 + tmp = learn_buffer;
56511 + learn_buffer = NULL;
56512 + spin_unlock(&gr_learn_lock);
56513 + vfree(learn_buffer);
56514 + }
56515 + if (learn_buffer_user != NULL) {
56516 + vfree(learn_buffer_user);
56517 + learn_buffer_user = NULL;
56518 + }
56519 + learn_buffer_len = 0;
56520 + mutex_unlock(&gr_learn_user_mutex);
56521 +
56522 + return;
56523 +}
56524 +
56525 +void
56526 +gr_add_learn_entry(const char *fmt, ...)
56527 +{
56528 + va_list args;
56529 + unsigned int len;
56530 +
56531 + if (!gr_learn_attached)
56532 + return;
56533 +
56534 + spin_lock(&gr_learn_lock);
56535 +
56536 + /* leave a gap at the end so we know when it's "full" but don't have to
56537 + compute the exact length of the string we're trying to append
56538 + */
56539 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56540 + spin_unlock(&gr_learn_lock);
56541 + wake_up_interruptible(&learn_wait);
56542 + return;
56543 + }
56544 + if (learn_buffer == NULL) {
56545 + spin_unlock(&gr_learn_lock);
56546 + return;
56547 + }
56548 +
56549 + va_start(args, fmt);
56550 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56551 + va_end(args);
56552 +
56553 + learn_buffer_len += len + 1;
56554 +
56555 + spin_unlock(&gr_learn_lock);
56556 + wake_up_interruptible(&learn_wait);
56557 +
56558 + return;
56559 +}
56560 +
56561 +static int
56562 +open_learn(struct inode *inode, struct file *file)
56563 +{
56564 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56565 + return -EBUSY;
56566 + if (file->f_mode & FMODE_READ) {
56567 + int retval = 0;
56568 + mutex_lock(&gr_learn_user_mutex);
56569 + if (learn_buffer == NULL)
56570 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56571 + if (learn_buffer_user == NULL)
56572 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56573 + if (learn_buffer == NULL) {
56574 + retval = -ENOMEM;
56575 + goto out_error;
56576 + }
56577 + if (learn_buffer_user == NULL) {
56578 + retval = -ENOMEM;
56579 + goto out_error;
56580 + }
56581 + learn_buffer_len = 0;
56582 + learn_buffer_user_len = 0;
56583 + gr_learn_attached = 1;
56584 +out_error:
56585 + mutex_unlock(&gr_learn_user_mutex);
56586 + return retval;
56587 + }
56588 + return 0;
56589 +}
56590 +
56591 +static int
56592 +close_learn(struct inode *inode, struct file *file)
56593 +{
56594 + char *tmp;
56595 +
56596 + if (file->f_mode & FMODE_READ) {
56597 + mutex_lock(&gr_learn_user_mutex);
56598 + if (learn_buffer != NULL) {
56599 + spin_lock(&gr_learn_lock);
56600 + tmp = learn_buffer;
56601 + learn_buffer = NULL;
56602 + spin_unlock(&gr_learn_lock);
56603 + vfree(tmp);
56604 + }
56605 + if (learn_buffer_user != NULL) {
56606 + vfree(learn_buffer_user);
56607 + learn_buffer_user = NULL;
56608 + }
56609 + learn_buffer_len = 0;
56610 + learn_buffer_user_len = 0;
56611 + gr_learn_attached = 0;
56612 + mutex_unlock(&gr_learn_user_mutex);
56613 + }
56614 +
56615 + return 0;
56616 +}
56617 +
56618 +const struct file_operations grsec_fops = {
56619 + .read = read_learn,
56620 + .write = write_grsec_handler,
56621 + .open = open_learn,
56622 + .release = close_learn,
56623 + .poll = poll_learn,
56624 +};
56625 diff -urNp linux-2.6.39.1/grsecurity/gracl_res.c linux-2.6.39.1/grsecurity/gracl_res.c
56626 --- linux-2.6.39.1/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
56627 +++ linux-2.6.39.1/grsecurity/gracl_res.c 2011-05-22 19:41:42.000000000 -0400
56628 @@ -0,0 +1,68 @@
56629 +#include <linux/kernel.h>
56630 +#include <linux/sched.h>
56631 +#include <linux/gracl.h>
56632 +#include <linux/grinternal.h>
56633 +
56634 +static const char *restab_log[] = {
56635 + [RLIMIT_CPU] = "RLIMIT_CPU",
56636 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56637 + [RLIMIT_DATA] = "RLIMIT_DATA",
56638 + [RLIMIT_STACK] = "RLIMIT_STACK",
56639 + [RLIMIT_CORE] = "RLIMIT_CORE",
56640 + [RLIMIT_RSS] = "RLIMIT_RSS",
56641 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56642 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56643 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56644 + [RLIMIT_AS] = "RLIMIT_AS",
56645 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56646 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56647 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56648 + [RLIMIT_NICE] = "RLIMIT_NICE",
56649 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56650 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56651 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56652 +};
56653 +
56654 +void
56655 +gr_log_resource(const struct task_struct *task,
56656 + const int res, const unsigned long wanted, const int gt)
56657 +{
56658 + const struct cred *cred;
56659 + unsigned long rlim;
56660 +
56661 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56662 + return;
56663 +
56664 + // not yet supported resource
56665 + if (unlikely(!restab_log[res]))
56666 + return;
56667 +
56668 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56669 + rlim = task_rlimit_max(task, res);
56670 + else
56671 + rlim = task_rlimit(task, res);
56672 +
56673 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56674 + return;
56675 +
56676 + rcu_read_lock();
56677 + cred = __task_cred(task);
56678 +
56679 + if (res == RLIMIT_NPROC &&
56680 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56681 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56682 + goto out_rcu_unlock;
56683 + else if (res == RLIMIT_MEMLOCK &&
56684 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56685 + goto out_rcu_unlock;
56686 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56687 + goto out_rcu_unlock;
56688 + rcu_read_unlock();
56689 +
56690 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56691 +
56692 + return;
56693 +out_rcu_unlock:
56694 + rcu_read_unlock();
56695 + return;
56696 +}
56697 diff -urNp linux-2.6.39.1/grsecurity/gracl_segv.c linux-2.6.39.1/grsecurity/gracl_segv.c
56698 --- linux-2.6.39.1/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
56699 +++ linux-2.6.39.1/grsecurity/gracl_segv.c 2011-05-22 22:47:39.000000000 -0400
56700 @@ -0,0 +1,299 @@
56701 +#include <linux/kernel.h>
56702 +#include <linux/mm.h>
56703 +#include <asm/uaccess.h>
56704 +#include <asm/errno.h>
56705 +#include <asm/mman.h>
56706 +#include <net/sock.h>
56707 +#include <linux/file.h>
56708 +#include <linux/fs.h>
56709 +#include <linux/net.h>
56710 +#include <linux/in.h>
56711 +#include <linux/slab.h>
56712 +#include <linux/types.h>
56713 +#include <linux/sched.h>
56714 +#include <linux/timer.h>
56715 +#include <linux/gracl.h>
56716 +#include <linux/grsecurity.h>
56717 +#include <linux/grinternal.h>
56718 +
56719 +static struct crash_uid *uid_set;
56720 +static unsigned short uid_used;
56721 +static DEFINE_SPINLOCK(gr_uid_lock);
56722 +extern rwlock_t gr_inode_lock;
56723 +extern struct acl_subject_label *
56724 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56725 + struct acl_role_label *role);
56726 +
56727 +#ifdef CONFIG_BTRFS_FS
56728 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56729 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56730 +#endif
56731 +
56732 +static inline dev_t __get_dev(const struct dentry *dentry)
56733 +{
56734 +#ifdef CONFIG_BTRFS_FS
56735 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56736 + return get_btrfs_dev_from_inode(dentry->d_inode);
56737 + else
56738 +#endif
56739 + return dentry->d_inode->i_sb->s_dev;
56740 +}
56741 +
56742 +int
56743 +gr_init_uidset(void)
56744 +{
56745 + uid_set =
56746 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56747 + uid_used = 0;
56748 +
56749 + return uid_set ? 1 : 0;
56750 +}
56751 +
56752 +void
56753 +gr_free_uidset(void)
56754 +{
56755 + if (uid_set)
56756 + kfree(uid_set);
56757 +
56758 + return;
56759 +}
56760 +
56761 +int
56762 +gr_find_uid(const uid_t uid)
56763 +{
56764 + struct crash_uid *tmp = uid_set;
56765 + uid_t buid;
56766 + int low = 0, high = uid_used - 1, mid;
56767 +
56768 + while (high >= low) {
56769 + mid = (low + high) >> 1;
56770 + buid = tmp[mid].uid;
56771 + if (buid == uid)
56772 + return mid;
56773 + if (buid > uid)
56774 + high = mid - 1;
56775 + if (buid < uid)
56776 + low = mid + 1;
56777 + }
56778 +
56779 + return -1;
56780 +}
56781 +
56782 +static __inline__ void
56783 +gr_insertsort(void)
56784 +{
56785 + unsigned short i, j;
56786 + struct crash_uid index;
56787 +
56788 + for (i = 1; i < uid_used; i++) {
56789 + index = uid_set[i];
56790 + j = i;
56791 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56792 + uid_set[j] = uid_set[j - 1];
56793 + j--;
56794 + }
56795 + uid_set[j] = index;
56796 + }
56797 +
56798 + return;
56799 +}
56800 +
56801 +static __inline__ void
56802 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56803 +{
56804 + int loc;
56805 +
56806 + if (uid_used == GR_UIDTABLE_MAX)
56807 + return;
56808 +
56809 + loc = gr_find_uid(uid);
56810 +
56811 + if (loc >= 0) {
56812 + uid_set[loc].expires = expires;
56813 + return;
56814 + }
56815 +
56816 + uid_set[uid_used].uid = uid;
56817 + uid_set[uid_used].expires = expires;
56818 + uid_used++;
56819 +
56820 + gr_insertsort();
56821 +
56822 + return;
56823 +}
56824 +
56825 +void
56826 +gr_remove_uid(const unsigned short loc)
56827 +{
56828 + unsigned short i;
56829 +
56830 + for (i = loc + 1; i < uid_used; i++)
56831 + uid_set[i - 1] = uid_set[i];
56832 +
56833 + uid_used--;
56834 +
56835 + return;
56836 +}
56837 +
56838 +int
56839 +gr_check_crash_uid(const uid_t uid)
56840 +{
56841 + int loc;
56842 + int ret = 0;
56843 +
56844 + if (unlikely(!gr_acl_is_enabled()))
56845 + return 0;
56846 +
56847 + spin_lock(&gr_uid_lock);
56848 + loc = gr_find_uid(uid);
56849 +
56850 + if (loc < 0)
56851 + goto out_unlock;
56852 +
56853 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56854 + gr_remove_uid(loc);
56855 + else
56856 + ret = 1;
56857 +
56858 +out_unlock:
56859 + spin_unlock(&gr_uid_lock);
56860 + return ret;
56861 +}
56862 +
56863 +static __inline__ int
56864 +proc_is_setxid(const struct cred *cred)
56865 +{
56866 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56867 + cred->uid != cred->fsuid)
56868 + return 1;
56869 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56870 + cred->gid != cred->fsgid)
56871 + return 1;
56872 +
56873 + return 0;
56874 +}
56875 +
56876 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56877 +
56878 +void
56879 +gr_handle_crash(struct task_struct *task, const int sig)
56880 +{
56881 + struct acl_subject_label *curr;
56882 + struct acl_subject_label *curr2;
56883 + struct task_struct *tsk, *tsk2;
56884 + const struct cred *cred;
56885 + const struct cred *cred2;
56886 +
56887 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56888 + return;
56889 +
56890 + if (unlikely(!gr_acl_is_enabled()))
56891 + return;
56892 +
56893 + curr = task->acl;
56894 +
56895 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56896 + return;
56897 +
56898 + if (time_before_eq(curr->expires, get_seconds())) {
56899 + curr->expires = 0;
56900 + curr->crashes = 0;
56901 + }
56902 +
56903 + curr->crashes++;
56904 +
56905 + if (!curr->expires)
56906 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56907 +
56908 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56909 + time_after(curr->expires, get_seconds())) {
56910 + rcu_read_lock();
56911 + cred = __task_cred(task);
56912 + if (cred->uid && proc_is_setxid(cred)) {
56913 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56914 + spin_lock(&gr_uid_lock);
56915 + gr_insert_uid(cred->uid, curr->expires);
56916 + spin_unlock(&gr_uid_lock);
56917 + curr->expires = 0;
56918 + curr->crashes = 0;
56919 + read_lock(&tasklist_lock);
56920 + do_each_thread(tsk2, tsk) {
56921 + cred2 = __task_cred(tsk);
56922 + if (tsk != task && cred2->uid == cred->uid)
56923 + gr_fake_force_sig(SIGKILL, tsk);
56924 + } while_each_thread(tsk2, tsk);
56925 + read_unlock(&tasklist_lock);
56926 + } else {
56927 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56928 + read_lock(&tasklist_lock);
56929 + do_each_thread(tsk2, tsk) {
56930 + if (likely(tsk != task)) {
56931 + curr2 = tsk->acl;
56932 +
56933 + if (curr2->device == curr->device &&
56934 + curr2->inode == curr->inode)
56935 + gr_fake_force_sig(SIGKILL, tsk);
56936 + }
56937 + } while_each_thread(tsk2, tsk);
56938 + read_unlock(&tasklist_lock);
56939 + }
56940 + rcu_read_unlock();
56941 + }
56942 +
56943 + return;
56944 +}
56945 +
56946 +int
56947 +gr_check_crash_exec(const struct file *filp)
56948 +{
56949 + struct acl_subject_label *curr;
56950 +
56951 + if (unlikely(!gr_acl_is_enabled()))
56952 + return 0;
56953 +
56954 + read_lock(&gr_inode_lock);
56955 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56956 + __get_dev(filp->f_path.dentry),
56957 + current->role);
56958 + read_unlock(&gr_inode_lock);
56959 +
56960 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56961 + (!curr->crashes && !curr->expires))
56962 + return 0;
56963 +
56964 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56965 + time_after(curr->expires, get_seconds()))
56966 + return 1;
56967 + else if (time_before_eq(curr->expires, get_seconds())) {
56968 + curr->crashes = 0;
56969 + curr->expires = 0;
56970 + }
56971 +
56972 + return 0;
56973 +}
56974 +
56975 +void
56976 +gr_handle_alertkill(struct task_struct *task)
56977 +{
56978 + struct acl_subject_label *curracl;
56979 + __u32 curr_ip;
56980 + struct task_struct *p, *p2;
56981 +
56982 + if (unlikely(!gr_acl_is_enabled()))
56983 + return;
56984 +
56985 + curracl = task->acl;
56986 + curr_ip = task->signal->curr_ip;
56987 +
56988 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56989 + read_lock(&tasklist_lock);
56990 + do_each_thread(p2, p) {
56991 + if (p->signal->curr_ip == curr_ip)
56992 + gr_fake_force_sig(SIGKILL, p);
56993 + } while_each_thread(p2, p);
56994 + read_unlock(&tasklist_lock);
56995 + } else if (curracl->mode & GR_KILLPROC)
56996 + gr_fake_force_sig(SIGKILL, task);
56997 +
56998 + return;
56999 +}
57000 diff -urNp linux-2.6.39.1/grsecurity/gracl_shm.c linux-2.6.39.1/grsecurity/gracl_shm.c
57001 --- linux-2.6.39.1/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
57002 +++ linux-2.6.39.1/grsecurity/gracl_shm.c 2011-05-22 19:41:42.000000000 -0400
57003 @@ -0,0 +1,40 @@
57004 +#include <linux/kernel.h>
57005 +#include <linux/mm.h>
57006 +#include <linux/sched.h>
57007 +#include <linux/file.h>
57008 +#include <linux/ipc.h>
57009 +#include <linux/gracl.h>
57010 +#include <linux/grsecurity.h>
57011 +#include <linux/grinternal.h>
57012 +
57013 +int
57014 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57015 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57016 +{
57017 + struct task_struct *task;
57018 +
57019 + if (!gr_acl_is_enabled())
57020 + return 1;
57021 +
57022 + rcu_read_lock();
57023 + read_lock(&tasklist_lock);
57024 +
57025 + task = find_task_by_vpid(shm_cprid);
57026 +
57027 + if (unlikely(!task))
57028 + task = find_task_by_vpid(shm_lapid);
57029 +
57030 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57031 + (task->pid == shm_lapid)) &&
57032 + (task->acl->mode & GR_PROTSHM) &&
57033 + (task->acl != current->acl))) {
57034 + read_unlock(&tasklist_lock);
57035 + rcu_read_unlock();
57036 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57037 + return 0;
57038 + }
57039 + read_unlock(&tasklist_lock);
57040 + rcu_read_unlock();
57041 +
57042 + return 1;
57043 +}
57044 diff -urNp linux-2.6.39.1/grsecurity/grsec_chdir.c linux-2.6.39.1/grsecurity/grsec_chdir.c
57045 --- linux-2.6.39.1/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
57046 +++ linux-2.6.39.1/grsecurity/grsec_chdir.c 2011-05-22 19:41:42.000000000 -0400
57047 @@ -0,0 +1,19 @@
57048 +#include <linux/kernel.h>
57049 +#include <linux/sched.h>
57050 +#include <linux/fs.h>
57051 +#include <linux/file.h>
57052 +#include <linux/grsecurity.h>
57053 +#include <linux/grinternal.h>
57054 +
57055 +void
57056 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57057 +{
57058 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57059 + if ((grsec_enable_chdir && grsec_enable_group &&
57060 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57061 + !grsec_enable_group)) {
57062 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57063 + }
57064 +#endif
57065 + return;
57066 +}
57067 diff -urNp linux-2.6.39.1/grsecurity/grsec_chroot.c linux-2.6.39.1/grsecurity/grsec_chroot.c
57068 --- linux-2.6.39.1/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
57069 +++ linux-2.6.39.1/grsecurity/grsec_chroot.c 2011-05-22 19:41:42.000000000 -0400
57070 @@ -0,0 +1,355 @@
57071 +#include <linux/kernel.h>
57072 +#include <linux/module.h>
57073 +#include <linux/sched.h>
57074 +#include <linux/file.h>
57075 +#include <linux/fs.h>
57076 +#include <linux/mount.h>
57077 +#include <linux/types.h>
57078 +#include <linux/pid_namespace.h>
57079 +#include <linux/grsecurity.h>
57080 +#include <linux/grinternal.h>
57081 +
57082 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57083 +{
57084 +#ifdef CONFIG_GRKERNSEC
57085 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57086 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57087 + task->gr_is_chrooted = 1;
57088 + else
57089 + task->gr_is_chrooted = 0;
57090 +
57091 + task->gr_chroot_dentry = path->dentry;
57092 +#endif
57093 + return;
57094 +}
57095 +
57096 +void gr_clear_chroot_entries(struct task_struct *task)
57097 +{
57098 +#ifdef CONFIG_GRKERNSEC
57099 + task->gr_is_chrooted = 0;
57100 + task->gr_chroot_dentry = NULL;
57101 +#endif
57102 + return;
57103 +}
57104 +
57105 +int
57106 +gr_handle_chroot_unix(struct pid *pid)
57107 +{
57108 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57109 + struct task_struct *p;
57110 +
57111 + if (unlikely(!grsec_enable_chroot_unix))
57112 + return 1;
57113 +
57114 + if (likely(!proc_is_chrooted(current)))
57115 + return 1;
57116 +
57117 + rcu_read_lock();
57118 + read_lock(&tasklist_lock);
57119 + p = pid_task(pid, PIDTYPE_PID);
57120 + if (unlikely(p && !have_same_root(current, p))) {
57121 + read_unlock(&tasklist_lock);
57122 + rcu_read_unlock();
57123 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57124 + return 0;
57125 + }
57126 + read_unlock(&tasklist_lock);
57127 + rcu_read_unlock();
57128 +#endif
57129 + return 1;
57130 +}
57131 +
57132 +int
57133 +gr_handle_chroot_nice(void)
57134 +{
57135 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57136 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57137 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57138 + return -EPERM;
57139 + }
57140 +#endif
57141 + return 0;
57142 +}
57143 +
57144 +int
57145 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57146 +{
57147 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57148 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57149 + && proc_is_chrooted(current)) {
57150 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57151 + return -EACCES;
57152 + }
57153 +#endif
57154 + return 0;
57155 +}
57156 +
57157 +int
57158 +gr_handle_chroot_rawio(const struct inode *inode)
57159 +{
57160 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57161 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57162 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57163 + return 1;
57164 +#endif
57165 + return 0;
57166 +}
57167 +
57168 +int
57169 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57170 +{
57171 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57172 + struct task_struct *p;
57173 + int ret = 0;
57174 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57175 + return ret;
57176 +
57177 + read_lock(&tasklist_lock);
57178 + do_each_pid_task(pid, type, p) {
57179 + if (!have_same_root(current, p)) {
57180 + ret = 1;
57181 + goto out;
57182 + }
57183 + } while_each_pid_task(pid, type, p);
57184 +out:
57185 + read_unlock(&tasklist_lock);
57186 + return ret;
57187 +#endif
57188 + return 0;
57189 +}
57190 +
57191 +int
57192 +gr_pid_is_chrooted(struct task_struct *p)
57193 +{
57194 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57195 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57196 + return 0;
57197 +
57198 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57199 + !have_same_root(current, p)) {
57200 + return 1;
57201 + }
57202 +#endif
57203 + return 0;
57204 +}
57205 +
57206 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57207 +
57208 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57209 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57210 +{
57211 + struct path path, currentroot;
57212 + int ret = 0;
57213 +
57214 + path.dentry = (struct dentry *)u_dentry;
57215 + path.mnt = (struct vfsmount *)u_mnt;
57216 + get_fs_root(current->fs, &currentroot);
57217 + if (path_is_under(&path, &currentroot))
57218 + ret = 1;
57219 + path_put(&currentroot);
57220 +
57221 + return ret;
57222 +}
57223 +#endif
57224 +
57225 +int
57226 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57227 +{
57228 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57229 + if (!grsec_enable_chroot_fchdir)
57230 + return 1;
57231 +
57232 + if (!proc_is_chrooted(current))
57233 + return 1;
57234 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57235 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57236 + return 0;
57237 + }
57238 +#endif
57239 + return 1;
57240 +}
57241 +
57242 +int
57243 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57244 + const time_t shm_createtime)
57245 +{
57246 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57247 + struct pid *pid = NULL;
57248 + time_t starttime;
57249 +
57250 + if (unlikely(!grsec_enable_chroot_shmat))
57251 + return 1;
57252 +
57253 + if (likely(!proc_is_chrooted(current)))
57254 + return 1;
57255 +
57256 + rcu_read_lock();
57257 + read_lock(&tasklist_lock);
57258 +
57259 + pid = find_vpid(shm_cprid);
57260 + if (pid) {
57261 + struct task_struct *p;
57262 + p = pid_task(pid, PIDTYPE_PID);
57263 + if (p == NULL)
57264 + goto unlock;
57265 + starttime = p->start_time.tv_sec;
57266 + if (unlikely(!have_same_root(current, p) &&
57267 + time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
57268 + read_unlock(&tasklist_lock);
57269 + rcu_read_unlock();
57270 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57271 + return 0;
57272 + }
57273 + } else {
57274 + pid = find_vpid(shm_lapid);
57275 + if (pid) {
57276 + struct task_struct *p;
57277 + p = pid_task(pid, PIDTYPE_PID);
57278 + if (p == NULL)
57279 + goto unlock;
57280 + if (unlikely(!have_same_root(current, p))) {
57281 + read_unlock(&tasklist_lock);
57282 + rcu_read_unlock();
57283 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57284 + return 0;
57285 + }
57286 + }
57287 + }
57288 +unlock:
57289 + read_unlock(&tasklist_lock);
57290 + rcu_read_unlock();
57291 +#endif
57292 + return 1;
57293 +}
57294 +
57295 +void
57296 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57297 +{
57298 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57299 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57300 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57301 +#endif
57302 + return;
57303 +}
57304 +
57305 +int
57306 +gr_handle_chroot_mknod(const struct dentry *dentry,
57307 + const struct vfsmount *mnt, const int mode)
57308 +{
57309 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57310 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57311 + proc_is_chrooted(current)) {
57312 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57313 + return -EPERM;
57314 + }
57315 +#endif
57316 + return 0;
57317 +}
57318 +
57319 +int
57320 +gr_handle_chroot_mount(const struct dentry *dentry,
57321 + const struct vfsmount *mnt, const char *dev_name)
57322 +{
57323 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57324 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57325 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
57326 + return -EPERM;
57327 + }
57328 +#endif
57329 + return 0;
57330 +}
57331 +
57332 +int
57333 +gr_handle_chroot_pivot(void)
57334 +{
57335 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57336 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57337 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57338 + return -EPERM;
57339 + }
57340 +#endif
57341 + return 0;
57342 +}
57343 +
57344 +int
57345 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57346 +{
57347 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57348 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57349 + !gr_is_outside_chroot(dentry, mnt)) {
57350 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57351 + return -EPERM;
57352 + }
57353 +#endif
57354 + return 0;
57355 +}
57356 +
57357 +int
57358 +gr_handle_chroot_caps(struct path *path)
57359 +{
57360 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57361 + if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
57362 + (init_task.fs->root.dentry != path->dentry) &&
57363 + (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
57364 +
57365 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57366 + const struct cred *old = current_cred();
57367 + struct cred *new = prepare_creds();
57368 + if (new == NULL)
57369 + return 1;
57370 +
57371 + new->cap_permitted = cap_drop(old->cap_permitted,
57372 + chroot_caps);
57373 + new->cap_inheritable = cap_drop(old->cap_inheritable,
57374 + chroot_caps);
57375 + new->cap_effective = cap_drop(old->cap_effective,
57376 + chroot_caps);
57377 +
57378 + commit_creds(new);
57379 +
57380 + return 0;
57381 + }
57382 +#endif
57383 + return 0;
57384 +}
57385 +
57386 +int
57387 +gr_handle_chroot_sysctl(const int op)
57388 +{
57389 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57390 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57391 + proc_is_chrooted(current))
57392 + return -EACCES;
57393 +#endif
57394 + return 0;
57395 +}
57396 +
57397 +void
57398 +gr_handle_chroot_chdir(struct path *path)
57399 +{
57400 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57401 + if (grsec_enable_chroot_chdir)
57402 + set_fs_pwd(current->fs, path);
57403 +#endif
57404 + return;
57405 +}
57406 +
57407 +int
57408 +gr_handle_chroot_chmod(const struct dentry *dentry,
57409 + const struct vfsmount *mnt, const int mode)
57410 +{
57411 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57412 + /* allow chmod +s on directories, but not files */
57413 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57414 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57415 + proc_is_chrooted(current)) {
57416 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57417 + return -EPERM;
57418 + }
57419 +#endif
57420 + return 0;
57421 +}
57422 +
57423 +#ifdef CONFIG_SECURITY
57424 +EXPORT_SYMBOL(gr_handle_chroot_caps);
57425 +#endif
57426 diff -urNp linux-2.6.39.1/grsecurity/grsec_disabled.c linux-2.6.39.1/grsecurity/grsec_disabled.c
57427 --- linux-2.6.39.1/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
57428 +++ linux-2.6.39.1/grsecurity/grsec_disabled.c 2011-05-22 19:41:42.000000000 -0400
57429 @@ -0,0 +1,447 @@
57430 +#include <linux/kernel.h>
57431 +#include <linux/module.h>
57432 +#include <linux/sched.h>
57433 +#include <linux/file.h>
57434 +#include <linux/fs.h>
57435 +#include <linux/kdev_t.h>
57436 +#include <linux/net.h>
57437 +#include <linux/in.h>
57438 +#include <linux/ip.h>
57439 +#include <linux/skbuff.h>
57440 +#include <linux/sysctl.h>
57441 +
57442 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57443 +void
57444 +pax_set_initial_flags(struct linux_binprm *bprm)
57445 +{
57446 + return;
57447 +}
57448 +#endif
57449 +
57450 +#ifdef CONFIG_SYSCTL
57451 +__u32
57452 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57453 +{
57454 + return 0;
57455 +}
57456 +#endif
57457 +
57458 +#ifdef CONFIG_TASKSTATS
57459 +int gr_is_taskstats_denied(int pid)
57460 +{
57461 + return 0;
57462 +}
57463 +#endif
57464 +
57465 +int
57466 +gr_acl_is_enabled(void)
57467 +{
57468 + return 0;
57469 +}
57470 +
57471 +int
57472 +gr_handle_rawio(const struct inode *inode)
57473 +{
57474 + return 0;
57475 +}
57476 +
57477 +void
57478 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57479 +{
57480 + return;
57481 +}
57482 +
57483 +int
57484 +gr_handle_ptrace(struct task_struct *task, const long request)
57485 +{
57486 + return 0;
57487 +}
57488 +
57489 +int
57490 +gr_handle_proc_ptrace(struct task_struct *task)
57491 +{
57492 + return 0;
57493 +}
57494 +
57495 +void
57496 +gr_learn_resource(const struct task_struct *task,
57497 + const int res, const unsigned long wanted, const int gt)
57498 +{
57499 + return;
57500 +}
57501 +
57502 +int
57503 +gr_set_acls(const int type)
57504 +{
57505 + return 0;
57506 +}
57507 +
57508 +int
57509 +gr_check_hidden_task(const struct task_struct *tsk)
57510 +{
57511 + return 0;
57512 +}
57513 +
57514 +int
57515 +gr_check_protected_task(const struct task_struct *task)
57516 +{
57517 + return 0;
57518 +}
57519 +
57520 +int
57521 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57522 +{
57523 + return 0;
57524 +}
57525 +
57526 +void
57527 +gr_copy_label(struct task_struct *tsk)
57528 +{
57529 + return;
57530 +}
57531 +
57532 +void
57533 +gr_set_pax_flags(struct task_struct *task)
57534 +{
57535 + return;
57536 +}
57537 +
57538 +int
57539 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57540 + const int unsafe_share)
57541 +{
57542 + return 0;
57543 +}
57544 +
57545 +void
57546 +gr_handle_delete(const ino_t ino, const dev_t dev)
57547 +{
57548 + return;
57549 +}
57550 +
57551 +void
57552 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57553 +{
57554 + return;
57555 +}
57556 +
57557 +void
57558 +gr_handle_crash(struct task_struct *task, const int sig)
57559 +{
57560 + return;
57561 +}
57562 +
57563 +int
57564 +gr_check_crash_exec(const struct file *filp)
57565 +{
57566 + return 0;
57567 +}
57568 +
57569 +int
57570 +gr_check_crash_uid(const uid_t uid)
57571 +{
57572 + return 0;
57573 +}
57574 +
57575 +void
57576 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57577 + struct dentry *old_dentry,
57578 + struct dentry *new_dentry,
57579 + struct vfsmount *mnt, const __u8 replace)
57580 +{
57581 + return;
57582 +}
57583 +
57584 +int
57585 +gr_search_socket(const int family, const int type, const int protocol)
57586 +{
57587 + return 1;
57588 +}
57589 +
57590 +int
57591 +gr_search_connectbind(const int mode, const struct socket *sock,
57592 + const struct sockaddr_in *addr)
57593 +{
57594 + return 0;
57595 +}
57596 +
57597 +int
57598 +gr_is_capable(const int cap)
57599 +{
57600 + return 1;
57601 +}
57602 +
57603 +int
57604 +gr_is_capable_nolog(const int cap)
57605 +{
57606 + return 1;
57607 +}
57608 +
57609 +void
57610 +gr_handle_alertkill(struct task_struct *task)
57611 +{
57612 + return;
57613 +}
57614 +
57615 +__u32
57616 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57617 +{
57618 + return 1;
57619 +}
57620 +
57621 +__u32
57622 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57623 + const struct vfsmount * mnt)
57624 +{
57625 + return 1;
57626 +}
57627 +
57628 +__u32
57629 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57630 + const int fmode)
57631 +{
57632 + return 1;
57633 +}
57634 +
57635 +__u32
57636 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57637 +{
57638 + return 1;
57639 +}
57640 +
57641 +__u32
57642 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57643 +{
57644 + return 1;
57645 +}
57646 +
57647 +int
57648 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57649 + unsigned int *vm_flags)
57650 +{
57651 + return 1;
57652 +}
57653 +
57654 +__u32
57655 +gr_acl_handle_truncate(const struct dentry * dentry,
57656 + const struct vfsmount * mnt)
57657 +{
57658 + return 1;
57659 +}
57660 +
57661 +__u32
57662 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57663 +{
57664 + return 1;
57665 +}
57666 +
57667 +__u32
57668 +gr_acl_handle_access(const struct dentry * dentry,
57669 + const struct vfsmount * mnt, const int fmode)
57670 +{
57671 + return 1;
57672 +}
57673 +
57674 +__u32
57675 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57676 + mode_t mode)
57677 +{
57678 + return 1;
57679 +}
57680 +
57681 +__u32
57682 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57683 + mode_t mode)
57684 +{
57685 + return 1;
57686 +}
57687 +
57688 +__u32
57689 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57690 +{
57691 + return 1;
57692 +}
57693 +
57694 +__u32
57695 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57696 +{
57697 + return 1;
57698 +}
57699 +
57700 +void
57701 +grsecurity_init(void)
57702 +{
57703 + return;
57704 +}
57705 +
57706 +__u32
57707 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57708 + const struct dentry * parent_dentry,
57709 + const struct vfsmount * parent_mnt,
57710 + const int mode)
57711 +{
57712 + return 1;
57713 +}
57714 +
57715 +__u32
57716 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57717 + const struct dentry * parent_dentry,
57718 + const struct vfsmount * parent_mnt)
57719 +{
57720 + return 1;
57721 +}
57722 +
57723 +__u32
57724 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57725 + const struct dentry * parent_dentry,
57726 + const struct vfsmount * parent_mnt, const char *from)
57727 +{
57728 + return 1;
57729 +}
57730 +
57731 +__u32
57732 +gr_acl_handle_link(const struct dentry * new_dentry,
57733 + const struct dentry * parent_dentry,
57734 + const struct vfsmount * parent_mnt,
57735 + const struct dentry * old_dentry,
57736 + const struct vfsmount * old_mnt, const char *to)
57737 +{
57738 + return 1;
57739 +}
57740 +
57741 +int
57742 +gr_acl_handle_rename(const struct dentry *new_dentry,
57743 + const struct dentry *parent_dentry,
57744 + const struct vfsmount *parent_mnt,
57745 + const struct dentry *old_dentry,
57746 + const struct inode *old_parent_inode,
57747 + const struct vfsmount *old_mnt, const char *newname)
57748 +{
57749 + return 0;
57750 +}
57751 +
57752 +int
57753 +gr_acl_handle_filldir(const struct file *file, const char *name,
57754 + const int namelen, const ino_t ino)
57755 +{
57756 + return 1;
57757 +}
57758 +
57759 +int
57760 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57761 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57762 +{
57763 + return 1;
57764 +}
57765 +
57766 +int
57767 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57768 +{
57769 + return 0;
57770 +}
57771 +
57772 +int
57773 +gr_search_accept(const struct socket *sock)
57774 +{
57775 + return 0;
57776 +}
57777 +
57778 +int
57779 +gr_search_listen(const struct socket *sock)
57780 +{
57781 + return 0;
57782 +}
57783 +
57784 +int
57785 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57786 +{
57787 + return 0;
57788 +}
57789 +
57790 +__u32
57791 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57792 +{
57793 + return 1;
57794 +}
57795 +
57796 +__u32
57797 +gr_acl_handle_creat(const struct dentry * dentry,
57798 + const struct dentry * p_dentry,
57799 + const struct vfsmount * p_mnt, const int fmode,
57800 + const int imode)
57801 +{
57802 + return 1;
57803 +}
57804 +
57805 +void
57806 +gr_acl_handle_exit(void)
57807 +{
57808 + return;
57809 +}
57810 +
57811 +int
57812 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57813 +{
57814 + return 1;
57815 +}
57816 +
57817 +void
57818 +gr_set_role_label(const uid_t uid, const gid_t gid)
57819 +{
57820 + return;
57821 +}
57822 +
57823 +int
57824 +gr_acl_handle_procpidmem(const struct task_struct *task)
57825 +{
57826 + return 0;
57827 +}
57828 +
57829 +int
57830 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57831 +{
57832 + return 0;
57833 +}
57834 +
57835 +int
57836 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57837 +{
57838 + return 0;
57839 +}
57840 +
57841 +void
57842 +gr_set_kernel_label(struct task_struct *task)
57843 +{
57844 + return;
57845 +}
57846 +
57847 +int
57848 +gr_check_user_change(int real, int effective, int fs)
57849 +{
57850 + return 0;
57851 +}
57852 +
57853 +int
57854 +gr_check_group_change(int real, int effective, int fs)
57855 +{
57856 + return 0;
57857 +}
57858 +
57859 +int gr_acl_enable_at_secure(void)
57860 +{
57861 + return 0;
57862 +}
57863 +
57864 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57865 +{
57866 + return dentry->d_inode->i_sb->s_dev;
57867 +}
57868 +
57869 +EXPORT_SYMBOL(gr_is_capable);
57870 +EXPORT_SYMBOL(gr_is_capable_nolog);
57871 +EXPORT_SYMBOL(gr_learn_resource);
57872 +EXPORT_SYMBOL(gr_set_kernel_label);
57873 +#ifdef CONFIG_SECURITY
57874 +EXPORT_SYMBOL(gr_check_user_change);
57875 +EXPORT_SYMBOL(gr_check_group_change);
57876 +#endif
57877 diff -urNp linux-2.6.39.1/grsecurity/grsec_exec.c linux-2.6.39.1/grsecurity/grsec_exec.c
57878 --- linux-2.6.39.1/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
57879 +++ linux-2.6.39.1/grsecurity/grsec_exec.c 2011-05-22 22:41:29.000000000 -0400
57880 @@ -0,0 +1,146 @@
57881 +#include <linux/kernel.h>
57882 +#include <linux/sched.h>
57883 +#include <linux/file.h>
57884 +#include <linux/binfmts.h>
57885 +#include <linux/fs.h>
57886 +#include <linux/types.h>
57887 +#include <linux/grdefs.h>
57888 +#include <linux/grinternal.h>
57889 +#include <linux/capability.h>
57890 +#include <linux/compat.h>
57891 +
57892 +#include <asm/uaccess.h>
57893 +
57894 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57895 +static char gr_exec_arg_buf[132];
57896 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57897 +#endif
57898 +
57899 +int
57900 +gr_handle_nproc(void)
57901 +{
57902 +#ifdef CONFIG_GRKERNSEC_EXECVE
57903 + const struct cred *cred = current_cred();
57904 + if (grsec_enable_execve && cred->user &&
57905 + (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
57906 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
57907 + gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
57908 + return -EAGAIN;
57909 + }
57910 +#endif
57911 + return 0;
57912 +}
57913 +
57914 +void
57915 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
57916 +{
57917 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57918 + char *grarg = gr_exec_arg_buf;
57919 + unsigned int i, x, execlen = 0;
57920 + char c;
57921 +
57922 + if (!((grsec_enable_execlog && grsec_enable_group &&
57923 + in_group_p(grsec_audit_gid))
57924 + || (grsec_enable_execlog && !grsec_enable_group)))
57925 + return;
57926 +
57927 + mutex_lock(&gr_exec_arg_mutex);
57928 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57929 +
57930 + if (unlikely(argv == NULL))
57931 + goto log;
57932 +
57933 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57934 + const char __user *p;
57935 + unsigned int len;
57936 +
57937 + if (copy_from_user(&p, argv + i, sizeof(p)))
57938 + goto log;
57939 + if (!p)
57940 + goto log;
57941 + len = strnlen_user(p, 128 - execlen);
57942 + if (len > 128 - execlen)
57943 + len = 128 - execlen;
57944 + else if (len > 0)
57945 + len--;
57946 + if (copy_from_user(grarg + execlen, p, len))
57947 + goto log;
57948 +
57949 + /* rewrite unprintable characters */
57950 + for (x = 0; x < len; x++) {
57951 + c = *(grarg + execlen + x);
57952 + if (c < 32 || c > 126)
57953 + *(grarg + execlen + x) = ' ';
57954 + }
57955 +
57956 + execlen += len;
57957 + *(grarg + execlen) = ' ';
57958 + *(grarg + execlen + 1) = '\0';
57959 + execlen++;
57960 + }
57961 +
57962 + log:
57963 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57964 + bprm->file->f_path.mnt, grarg);
57965 + mutex_unlock(&gr_exec_arg_mutex);
57966 +#endif
57967 + return;
57968 +}
57969 +
57970 +#ifdef CONFIG_COMPAT
57971 +void
57972 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
57973 +{
57974 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57975 + char *grarg = gr_exec_arg_buf;
57976 + unsigned int i, x, execlen = 0;
57977 + char c;
57978 +
57979 + if (!((grsec_enable_execlog && grsec_enable_group &&
57980 + in_group_p(grsec_audit_gid))
57981 + || (grsec_enable_execlog && !grsec_enable_group)))
57982 + return;
57983 +
57984 + mutex_lock(&gr_exec_arg_mutex);
57985 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57986 +
57987 + if (unlikely(argv == NULL))
57988 + goto log;
57989 +
57990 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57991 + compat_uptr_t p;
57992 + unsigned int len;
57993 +
57994 + if (get_user(p, argv + i))
57995 + goto log;
57996 + len = strnlen_user(compat_ptr(p), 128 - execlen);
57997 + if (len > 128 - execlen)
57998 + len = 128 - execlen;
57999 + else if (len > 0)
58000 + len--;
58001 + else
58002 + goto log;
58003 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
58004 + goto log;
58005 +
58006 + /* rewrite unprintable characters */
58007 + for (x = 0; x < len; x++) {
58008 + c = *(grarg + execlen + x);
58009 + if (c < 32 || c > 126)
58010 + *(grarg + execlen + x) = ' ';
58011 + }
58012 +
58013 + execlen += len;
58014 + *(grarg + execlen) = ' ';
58015 + *(grarg + execlen + 1) = '\0';
58016 + execlen++;
58017 + }
58018 +
58019 + log:
58020 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58021 + bprm->file->f_path.mnt, grarg);
58022 + mutex_unlock(&gr_exec_arg_mutex);
58023 +#endif
58024 + return;
58025 +}
58026 +#endif
58027 diff -urNp linux-2.6.39.1/grsecurity/grsec_fifo.c linux-2.6.39.1/grsecurity/grsec_fifo.c
58028 --- linux-2.6.39.1/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
58029 +++ linux-2.6.39.1/grsecurity/grsec_fifo.c 2011-05-22 19:41:42.000000000 -0400
58030 @@ -0,0 +1,24 @@
58031 +#include <linux/kernel.h>
58032 +#include <linux/sched.h>
58033 +#include <linux/fs.h>
58034 +#include <linux/file.h>
58035 +#include <linux/grinternal.h>
58036 +
58037 +int
58038 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58039 + const struct dentry *dir, const int flag, const int acc_mode)
58040 +{
58041 +#ifdef CONFIG_GRKERNSEC_FIFO
58042 + const struct cred *cred = current_cred();
58043 +
58044 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58045 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58046 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58047 + (cred->fsuid != dentry->d_inode->i_uid)) {
58048 + if (!inode_permission(dentry->d_inode, acc_mode))
58049 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58050 + return -EACCES;
58051 + }
58052 +#endif
58053 + return 0;
58054 +}
58055 diff -urNp linux-2.6.39.1/grsecurity/grsec_fork.c linux-2.6.39.1/grsecurity/grsec_fork.c
58056 --- linux-2.6.39.1/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
58057 +++ linux-2.6.39.1/grsecurity/grsec_fork.c 2011-05-22 19:41:42.000000000 -0400
58058 @@ -0,0 +1,23 @@
58059 +#include <linux/kernel.h>
58060 +#include <linux/sched.h>
58061 +#include <linux/grsecurity.h>
58062 +#include <linux/grinternal.h>
58063 +#include <linux/errno.h>
58064 +
58065 +void
58066 +gr_log_forkfail(const int retval)
58067 +{
58068 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58069 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58070 + switch (retval) {
58071 + case -EAGAIN:
58072 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58073 + break;
58074 + case -ENOMEM:
58075 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58076 + break;
58077 + }
58078 + }
58079 +#endif
58080 + return;
58081 +}
58082 diff -urNp linux-2.6.39.1/grsecurity/grsec_init.c linux-2.6.39.1/grsecurity/grsec_init.c
58083 --- linux-2.6.39.1/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
58084 +++ linux-2.6.39.1/grsecurity/grsec_init.c 2011-05-22 22:47:15.000000000 -0400
58085 @@ -0,0 +1,269 @@
58086 +#include <linux/kernel.h>
58087 +#include <linux/sched.h>
58088 +#include <linux/mm.h>
58089 +#include <linux/gracl.h>
58090 +#include <linux/slab.h>
58091 +#include <linux/vmalloc.h>
58092 +#include <linux/percpu.h>
58093 +#include <linux/module.h>
58094 +
58095 +int grsec_enable_link;
58096 +int grsec_enable_dmesg;
58097 +int grsec_enable_harden_ptrace;
58098 +int grsec_enable_fifo;
58099 +int grsec_enable_execve;
58100 +int grsec_enable_execlog;
58101 +int grsec_enable_signal;
58102 +int grsec_enable_forkfail;
58103 +int grsec_enable_audit_ptrace;
58104 +int grsec_enable_time;
58105 +int grsec_enable_audit_textrel;
58106 +int grsec_enable_group;
58107 +int grsec_audit_gid;
58108 +int grsec_enable_chdir;
58109 +int grsec_enable_mount;
58110 +int grsec_enable_rofs;
58111 +int grsec_enable_chroot_findtask;
58112 +int grsec_enable_chroot_mount;
58113 +int grsec_enable_chroot_shmat;
58114 +int grsec_enable_chroot_fchdir;
58115 +int grsec_enable_chroot_double;
58116 +int grsec_enable_chroot_pivot;
58117 +int grsec_enable_chroot_chdir;
58118 +int grsec_enable_chroot_chmod;
58119 +int grsec_enable_chroot_mknod;
58120 +int grsec_enable_chroot_nice;
58121 +int grsec_enable_chroot_execlog;
58122 +int grsec_enable_chroot_caps;
58123 +int grsec_enable_chroot_sysctl;
58124 +int grsec_enable_chroot_unix;
58125 +int grsec_enable_tpe;
58126 +int grsec_tpe_gid;
58127 +int grsec_enable_blackhole;
58128 +#ifdef CONFIG_IPV6_MODULE
58129 +EXPORT_SYMBOL(grsec_enable_blackhole);
58130 +#endif
58131 +int grsec_lastack_retries;
58132 +int grsec_enable_tpe_all;
58133 +int grsec_enable_tpe_invert;
58134 +int grsec_enable_socket_all;
58135 +int grsec_socket_all_gid;
58136 +int grsec_enable_socket_client;
58137 +int grsec_socket_client_gid;
58138 +int grsec_enable_socket_server;
58139 +int grsec_socket_server_gid;
58140 +int grsec_resource_logging;
58141 +int grsec_disable_privio;
58142 +int grsec_enable_log_rwxmaps;
58143 +int grsec_lock;
58144 +
58145 +DEFINE_SPINLOCK(grsec_alert_lock);
58146 +unsigned long grsec_alert_wtime = 0;
58147 +unsigned long grsec_alert_fyet = 0;
58148 +
58149 +DEFINE_SPINLOCK(grsec_audit_lock);
58150 +
58151 +DEFINE_RWLOCK(grsec_exec_file_lock);
58152 +
58153 +char *gr_shared_page[4];
58154 +
58155 +char *gr_alert_log_fmt;
58156 +char *gr_audit_log_fmt;
58157 +char *gr_alert_log_buf;
58158 +char *gr_audit_log_buf;
58159 +
58160 +extern struct gr_arg *gr_usermode;
58161 +extern unsigned char *gr_system_salt;
58162 +extern unsigned char *gr_system_sum;
58163 +
58164 +void __init
58165 +grsecurity_init(void)
58166 +{
58167 + int j;
58168 + /* create the per-cpu shared pages */
58169 +
58170 +#ifdef CONFIG_X86
58171 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58172 +#endif
58173 +
58174 + for (j = 0; j < 4; j++) {
58175 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58176 + if (gr_shared_page[j] == NULL) {
58177 + panic("Unable to allocate grsecurity shared page");
58178 + return;
58179 + }
58180 + }
58181 +
58182 + /* allocate log buffers */
58183 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58184 + if (!gr_alert_log_fmt) {
58185 + panic("Unable to allocate grsecurity alert log format buffer");
58186 + return;
58187 + }
58188 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58189 + if (!gr_audit_log_fmt) {
58190 + panic("Unable to allocate grsecurity audit log format buffer");
58191 + return;
58192 + }
58193 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58194 + if (!gr_alert_log_buf) {
58195 + panic("Unable to allocate grsecurity alert log buffer");
58196 + return;
58197 + }
58198 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58199 + if (!gr_audit_log_buf) {
58200 + panic("Unable to allocate grsecurity audit log buffer");
58201 + return;
58202 + }
58203 +
58204 + /* allocate memory for authentication structure */
58205 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58206 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58207 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58208 +
58209 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58210 + panic("Unable to allocate grsecurity authentication structure");
58211 + return;
58212 + }
58213 +
58214 +
58215 +#ifdef CONFIG_GRKERNSEC_IO
58216 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58217 + grsec_disable_privio = 1;
58218 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58219 + grsec_disable_privio = 1;
58220 +#else
58221 + grsec_disable_privio = 0;
58222 +#endif
58223 +#endif
58224 +
58225 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58226 + /* for backward compatibility, tpe_invert always defaults to on if
58227 + enabled in the kernel
58228 + */
58229 + grsec_enable_tpe_invert = 1;
58230 +#endif
58231 +
58232 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58233 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58234 + grsec_lock = 1;
58235 +#endif
58236 +
58237 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58238 + grsec_enable_audit_textrel = 1;
58239 +#endif
58240 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58241 + grsec_enable_log_rwxmaps = 1;
58242 +#endif
58243 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58244 + grsec_enable_group = 1;
58245 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58246 +#endif
58247 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58248 + grsec_enable_chdir = 1;
58249 +#endif
58250 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58251 + grsec_enable_harden_ptrace = 1;
58252 +#endif
58253 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58254 + grsec_enable_mount = 1;
58255 +#endif
58256 +#ifdef CONFIG_GRKERNSEC_LINK
58257 + grsec_enable_link = 1;
58258 +#endif
58259 +#ifdef CONFIG_GRKERNSEC_DMESG
58260 + grsec_enable_dmesg = 1;
58261 +#endif
58262 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58263 + grsec_enable_blackhole = 1;
58264 + grsec_lastack_retries = 4;
58265 +#endif
58266 +#ifdef CONFIG_GRKERNSEC_FIFO
58267 + grsec_enable_fifo = 1;
58268 +#endif
58269 +#ifdef CONFIG_GRKERNSEC_EXECVE
58270 + grsec_enable_execve = 1;
58271 +#endif
58272 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58273 + grsec_enable_execlog = 1;
58274 +#endif
58275 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58276 + grsec_enable_signal = 1;
58277 +#endif
58278 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58279 + grsec_enable_forkfail = 1;
58280 +#endif
58281 +#ifdef CONFIG_GRKERNSEC_TIME
58282 + grsec_enable_time = 1;
58283 +#endif
58284 +#ifdef CONFIG_GRKERNSEC_RESLOG
58285 + grsec_resource_logging = 1;
58286 +#endif
58287 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58288 + grsec_enable_chroot_findtask = 1;
58289 +#endif
58290 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58291 + grsec_enable_chroot_unix = 1;
58292 +#endif
58293 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58294 + grsec_enable_chroot_mount = 1;
58295 +#endif
58296 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58297 + grsec_enable_chroot_fchdir = 1;
58298 +#endif
58299 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58300 + grsec_enable_chroot_shmat = 1;
58301 +#endif
58302 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58303 + grsec_enable_audit_ptrace = 1;
58304 +#endif
58305 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58306 + grsec_enable_chroot_double = 1;
58307 +#endif
58308 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58309 + grsec_enable_chroot_pivot = 1;
58310 +#endif
58311 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58312 + grsec_enable_chroot_chdir = 1;
58313 +#endif
58314 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58315 + grsec_enable_chroot_chmod = 1;
58316 +#endif
58317 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58318 + grsec_enable_chroot_mknod = 1;
58319 +#endif
58320 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58321 + grsec_enable_chroot_nice = 1;
58322 +#endif
58323 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58324 + grsec_enable_chroot_execlog = 1;
58325 +#endif
58326 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58327 + grsec_enable_chroot_caps = 1;
58328 +#endif
58329 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58330 + grsec_enable_chroot_sysctl = 1;
58331 +#endif
58332 +#ifdef CONFIG_GRKERNSEC_TPE
58333 + grsec_enable_tpe = 1;
58334 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58335 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58336 + grsec_enable_tpe_all = 1;
58337 +#endif
58338 +#endif
58339 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58340 + grsec_enable_socket_all = 1;
58341 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58342 +#endif
58343 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58344 + grsec_enable_socket_client = 1;
58345 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58346 +#endif
58347 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58348 + grsec_enable_socket_server = 1;
58349 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58350 +#endif
58351 +#endif
58352 +
58353 + return;
58354 +}
58355 diff -urNp linux-2.6.39.1/grsecurity/grsec_link.c linux-2.6.39.1/grsecurity/grsec_link.c
58356 --- linux-2.6.39.1/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
58357 +++ linux-2.6.39.1/grsecurity/grsec_link.c 2011-05-22 19:41:42.000000000 -0400
58358 @@ -0,0 +1,43 @@
58359 +#include <linux/kernel.h>
58360 +#include <linux/sched.h>
58361 +#include <linux/fs.h>
58362 +#include <linux/file.h>
58363 +#include <linux/grinternal.h>
58364 +
58365 +int
58366 +gr_handle_follow_link(const struct inode *parent,
58367 + const struct inode *inode,
58368 + const struct dentry *dentry, const struct vfsmount *mnt)
58369 +{
58370 +#ifdef CONFIG_GRKERNSEC_LINK
58371 + const struct cred *cred = current_cred();
58372 +
58373 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58374 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58375 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58376 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58377 + return -EACCES;
58378 + }
58379 +#endif
58380 + return 0;
58381 +}
58382 +
58383 +int
58384 +gr_handle_hardlink(const struct dentry *dentry,
58385 + const struct vfsmount *mnt,
58386 + struct inode *inode, const int mode, const char *to)
58387 +{
58388 +#ifdef CONFIG_GRKERNSEC_LINK
58389 + const struct cred *cred = current_cred();
58390 +
58391 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58392 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58393 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58394 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58395 + !capable(CAP_FOWNER) && cred->uid) {
58396 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58397 + return -EPERM;
58398 + }
58399 +#endif
58400 + return 0;
58401 +}
58402 diff -urNp linux-2.6.39.1/grsecurity/grsec_log.c linux-2.6.39.1/grsecurity/grsec_log.c
58403 --- linux-2.6.39.1/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
58404 +++ linux-2.6.39.1/grsecurity/grsec_log.c 2011-05-22 19:41:42.000000000 -0400
58405 @@ -0,0 +1,310 @@
58406 +#include <linux/kernel.h>
58407 +#include <linux/sched.h>
58408 +#include <linux/file.h>
58409 +#include <linux/tty.h>
58410 +#include <linux/fs.h>
58411 +#include <linux/grinternal.h>
58412 +
58413 +#ifdef CONFIG_TREE_PREEMPT_RCU
58414 +#define DISABLE_PREEMPT() preempt_disable()
58415 +#define ENABLE_PREEMPT() preempt_enable()
58416 +#else
58417 +#define DISABLE_PREEMPT()
58418 +#define ENABLE_PREEMPT()
58419 +#endif
58420 +
58421 +#define BEGIN_LOCKS(x) \
58422 + DISABLE_PREEMPT(); \
58423 + rcu_read_lock(); \
58424 + read_lock(&tasklist_lock); \
58425 + read_lock(&grsec_exec_file_lock); \
58426 + if (x != GR_DO_AUDIT) \
58427 + spin_lock(&grsec_alert_lock); \
58428 + else \
58429 + spin_lock(&grsec_audit_lock)
58430 +
58431 +#define END_LOCKS(x) \
58432 + if (x != GR_DO_AUDIT) \
58433 + spin_unlock(&grsec_alert_lock); \
58434 + else \
58435 + spin_unlock(&grsec_audit_lock); \
58436 + read_unlock(&grsec_exec_file_lock); \
58437 + read_unlock(&tasklist_lock); \
58438 + rcu_read_unlock(); \
58439 + ENABLE_PREEMPT(); \
58440 + if (x == GR_DONT_AUDIT) \
58441 + gr_handle_alertkill(current)
58442 +
58443 +enum {
58444 + FLOODING,
58445 + NO_FLOODING
58446 +};
58447 +
58448 +extern char *gr_alert_log_fmt;
58449 +extern char *gr_audit_log_fmt;
58450 +extern char *gr_alert_log_buf;
58451 +extern char *gr_audit_log_buf;
58452 +
58453 +static int gr_log_start(int audit)
58454 +{
58455 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58456 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58457 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58458 +
58459 + if (audit == GR_DO_AUDIT)
58460 + goto set_fmt;
58461 +
58462 + if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
58463 + grsec_alert_wtime = jiffies;
58464 + grsec_alert_fyet = 0;
58465 + } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58466 + grsec_alert_fyet++;
58467 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58468 + grsec_alert_wtime = jiffies;
58469 + grsec_alert_fyet++;
58470 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58471 + return FLOODING;
58472 + } else return FLOODING;
58473 +
58474 +set_fmt:
58475 + memset(buf, 0, PAGE_SIZE);
58476 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58477 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58478 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58479 + } else if (current->signal->curr_ip) {
58480 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58481 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58482 + } else if (gr_acl_is_enabled()) {
58483 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58484 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58485 + } else {
58486 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58487 + strcpy(buf, fmt);
58488 + }
58489 +
58490 + return NO_FLOODING;
58491 +}
58492 +
58493 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58494 + __attribute__ ((format (printf, 2, 0)));
58495 +
58496 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58497 +{
58498 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58499 + unsigned int len = strlen(buf);
58500 +
58501 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58502 +
58503 + return;
58504 +}
58505 +
58506 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58507 + __attribute__ ((format (printf, 2, 3)));
58508 +
58509 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58510 +{
58511 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58512 + unsigned int len = strlen(buf);
58513 + va_list ap;
58514 +
58515 + va_start(ap, msg);
58516 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58517 + va_end(ap);
58518 +
58519 + return;
58520 +}
58521 +
58522 +static void gr_log_end(int audit)
58523 +{
58524 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58525 + unsigned int len = strlen(buf);
58526 +
58527 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58528 + printk("%s\n", buf);
58529 +
58530 + return;
58531 +}
58532 +
58533 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58534 +{
58535 + int logtype;
58536 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58537 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58538 + void *voidptr = NULL;
58539 + int num1 = 0, num2 = 0;
58540 + unsigned long ulong1 = 0, ulong2 = 0;
58541 + struct dentry *dentry = NULL;
58542 + struct vfsmount *mnt = NULL;
58543 + struct file *file = NULL;
58544 + struct task_struct *task = NULL;
58545 + const struct cred *cred, *pcred;
58546 + va_list ap;
58547 +
58548 + BEGIN_LOCKS(audit);
58549 + logtype = gr_log_start(audit);
58550 + if (logtype == FLOODING) {
58551 + END_LOCKS(audit);
58552 + return;
58553 + }
58554 + va_start(ap, argtypes);
58555 + switch (argtypes) {
58556 + case GR_TTYSNIFF:
58557 + task = va_arg(ap, struct task_struct *);
58558 + 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);
58559 + break;
58560 + case GR_SYSCTL_HIDDEN:
58561 + str1 = va_arg(ap, char *);
58562 + gr_log_middle_varargs(audit, msg, result, str1);
58563 + break;
58564 + case GR_RBAC:
58565 + dentry = va_arg(ap, struct dentry *);
58566 + mnt = va_arg(ap, struct vfsmount *);
58567 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58568 + break;
58569 + case GR_RBAC_STR:
58570 + dentry = va_arg(ap, struct dentry *);
58571 + mnt = va_arg(ap, struct vfsmount *);
58572 + str1 = va_arg(ap, char *);
58573 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58574 + break;
58575 + case GR_STR_RBAC:
58576 + str1 = va_arg(ap, char *);
58577 + dentry = va_arg(ap, struct dentry *);
58578 + mnt = va_arg(ap, struct vfsmount *);
58579 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58580 + break;
58581 + case GR_RBAC_MODE2:
58582 + dentry = va_arg(ap, struct dentry *);
58583 + mnt = va_arg(ap, struct vfsmount *);
58584 + str1 = va_arg(ap, char *);
58585 + str2 = va_arg(ap, char *);
58586 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58587 + break;
58588 + case GR_RBAC_MODE3:
58589 + dentry = va_arg(ap, struct dentry *);
58590 + mnt = va_arg(ap, struct vfsmount *);
58591 + str1 = va_arg(ap, char *);
58592 + str2 = va_arg(ap, char *);
58593 + str3 = va_arg(ap, char *);
58594 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58595 + break;
58596 + case GR_FILENAME:
58597 + dentry = va_arg(ap, struct dentry *);
58598 + mnt = va_arg(ap, struct vfsmount *);
58599 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58600 + break;
58601 + case GR_STR_FILENAME:
58602 + str1 = va_arg(ap, char *);
58603 + dentry = va_arg(ap, struct dentry *);
58604 + mnt = va_arg(ap, struct vfsmount *);
58605 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58606 + break;
58607 + case GR_FILENAME_STR:
58608 + dentry = va_arg(ap, struct dentry *);
58609 + mnt = va_arg(ap, struct vfsmount *);
58610 + str1 = va_arg(ap, char *);
58611 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58612 + break;
58613 + case GR_FILENAME_TWO_INT:
58614 + dentry = va_arg(ap, struct dentry *);
58615 + mnt = va_arg(ap, struct vfsmount *);
58616 + num1 = va_arg(ap, int);
58617 + num2 = va_arg(ap, int);
58618 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58619 + break;
58620 + case GR_FILENAME_TWO_INT_STR:
58621 + dentry = va_arg(ap, struct dentry *);
58622 + mnt = va_arg(ap, struct vfsmount *);
58623 + num1 = va_arg(ap, int);
58624 + num2 = va_arg(ap, int);
58625 + str1 = va_arg(ap, char *);
58626 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58627 + break;
58628 + case GR_TEXTREL:
58629 + file = va_arg(ap, struct file *);
58630 + ulong1 = va_arg(ap, unsigned long);
58631 + ulong2 = va_arg(ap, unsigned long);
58632 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58633 + break;
58634 + case GR_PTRACE:
58635 + task = va_arg(ap, struct task_struct *);
58636 + 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);
58637 + break;
58638 + case GR_RESOURCE:
58639 + task = va_arg(ap, struct task_struct *);
58640 + cred = __task_cred(task);
58641 + pcred = __task_cred(task->real_parent);
58642 + ulong1 = va_arg(ap, unsigned long);
58643 + str1 = va_arg(ap, char *);
58644 + ulong2 = va_arg(ap, unsigned long);
58645 + 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);
58646 + break;
58647 + case GR_CAP:
58648 + task = va_arg(ap, struct task_struct *);
58649 + cred = __task_cred(task);
58650 + pcred = __task_cred(task->real_parent);
58651 + str1 = va_arg(ap, char *);
58652 + 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);
58653 + break;
58654 + case GR_SIG:
58655 + str1 = va_arg(ap, char *);
58656 + voidptr = va_arg(ap, void *);
58657 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58658 + break;
58659 + case GR_SIG2:
58660 + task = va_arg(ap, struct task_struct *);
58661 + cred = __task_cred(task);
58662 + pcred = __task_cred(task->real_parent);
58663 + num1 = va_arg(ap, int);
58664 + 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);
58665 + break;
58666 + case GR_CRASH1:
58667 + task = va_arg(ap, struct task_struct *);
58668 + cred = __task_cred(task);
58669 + pcred = __task_cred(task->real_parent);
58670 + ulong1 = va_arg(ap, unsigned long);
58671 + 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);
58672 + break;
58673 + case GR_CRASH2:
58674 + task = va_arg(ap, struct task_struct *);
58675 + cred = __task_cred(task);
58676 + pcred = __task_cred(task->real_parent);
58677 + ulong1 = va_arg(ap, unsigned long);
58678 + 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);
58679 + break;
58680 + case GR_RWXMAP:
58681 + file = va_arg(ap, struct file *);
58682 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58683 + break;
58684 + case GR_PSACCT:
58685 + {
58686 + unsigned int wday, cday;
58687 + __u8 whr, chr;
58688 + __u8 wmin, cmin;
58689 + __u8 wsec, csec;
58690 + char cur_tty[64] = { 0 };
58691 + char parent_tty[64] = { 0 };
58692 +
58693 + task = va_arg(ap, struct task_struct *);
58694 + wday = va_arg(ap, unsigned int);
58695 + cday = va_arg(ap, unsigned int);
58696 + whr = va_arg(ap, int);
58697 + chr = va_arg(ap, int);
58698 + wmin = va_arg(ap, int);
58699 + cmin = va_arg(ap, int);
58700 + wsec = va_arg(ap, int);
58701 + csec = va_arg(ap, int);
58702 + ulong1 = va_arg(ap, unsigned long);
58703 + cred = __task_cred(task);
58704 + pcred = __task_cred(task->real_parent);
58705 +
58706 + 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);
58707 + }
58708 + break;
58709 + default:
58710 + gr_log_middle(audit, msg, ap);
58711 + }
58712 + va_end(ap);
58713 + gr_log_end(audit);
58714 + END_LOCKS(audit);
58715 +}
58716 diff -urNp linux-2.6.39.1/grsecurity/grsec_mem.c linux-2.6.39.1/grsecurity/grsec_mem.c
58717 --- linux-2.6.39.1/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
58718 +++ linux-2.6.39.1/grsecurity/grsec_mem.c 2011-05-22 19:41:42.000000000 -0400
58719 @@ -0,0 +1,33 @@
58720 +#include <linux/kernel.h>
58721 +#include <linux/sched.h>
58722 +#include <linux/mm.h>
58723 +#include <linux/mman.h>
58724 +#include <linux/grinternal.h>
58725 +
58726 +void
58727 +gr_handle_ioperm(void)
58728 +{
58729 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58730 + return;
58731 +}
58732 +
58733 +void
58734 +gr_handle_iopl(void)
58735 +{
58736 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58737 + return;
58738 +}
58739 +
58740 +void
58741 +gr_handle_mem_readwrite(u64 from, u64 to)
58742 +{
58743 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58744 + return;
58745 +}
58746 +
58747 +void
58748 +gr_handle_vm86(void)
58749 +{
58750 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58751 + return;
58752 +}
58753 diff -urNp linux-2.6.39.1/grsecurity/grsec_mount.c linux-2.6.39.1/grsecurity/grsec_mount.c
58754 --- linux-2.6.39.1/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
58755 +++ linux-2.6.39.1/grsecurity/grsec_mount.c 2011-05-22 19:41:42.000000000 -0400
58756 @@ -0,0 +1,62 @@
58757 +#include <linux/kernel.h>
58758 +#include <linux/sched.h>
58759 +#include <linux/mount.h>
58760 +#include <linux/grsecurity.h>
58761 +#include <linux/grinternal.h>
58762 +
58763 +void
58764 +gr_log_remount(const char *devname, const int retval)
58765 +{
58766 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58767 + if (grsec_enable_mount && (retval >= 0))
58768 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58769 +#endif
58770 + return;
58771 +}
58772 +
58773 +void
58774 +gr_log_unmount(const char *devname, const int retval)
58775 +{
58776 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58777 + if (grsec_enable_mount && (retval >= 0))
58778 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58779 +#endif
58780 + return;
58781 +}
58782 +
58783 +void
58784 +gr_log_mount(const char *from, const char *to, const int retval)
58785 +{
58786 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58787 + if (grsec_enable_mount && (retval >= 0))
58788 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
58789 +#endif
58790 + return;
58791 +}
58792 +
58793 +int
58794 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58795 +{
58796 +#ifdef CONFIG_GRKERNSEC_ROFS
58797 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58798 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58799 + return -EPERM;
58800 + } else
58801 + return 0;
58802 +#endif
58803 + return 0;
58804 +}
58805 +
58806 +int
58807 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58808 +{
58809 +#ifdef CONFIG_GRKERNSEC_ROFS
58810 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58811 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58812 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58813 + return -EPERM;
58814 + } else
58815 + return 0;
58816 +#endif
58817 + return 0;
58818 +}
58819 diff -urNp linux-2.6.39.1/grsecurity/grsec_pax.c linux-2.6.39.1/grsecurity/grsec_pax.c
58820 --- linux-2.6.39.1/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
58821 +++ linux-2.6.39.1/grsecurity/grsec_pax.c 2011-05-22 19:41:42.000000000 -0400
58822 @@ -0,0 +1,36 @@
58823 +#include <linux/kernel.h>
58824 +#include <linux/sched.h>
58825 +#include <linux/mm.h>
58826 +#include <linux/file.h>
58827 +#include <linux/grinternal.h>
58828 +#include <linux/grsecurity.h>
58829 +
58830 +void
58831 +gr_log_textrel(struct vm_area_struct * vma)
58832 +{
58833 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58834 + if (grsec_enable_audit_textrel)
58835 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58836 +#endif
58837 + return;
58838 +}
58839 +
58840 +void
58841 +gr_log_rwxmmap(struct file *file)
58842 +{
58843 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58844 + if (grsec_enable_log_rwxmaps)
58845 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58846 +#endif
58847 + return;
58848 +}
58849 +
58850 +void
58851 +gr_log_rwxmprotect(struct file *file)
58852 +{
58853 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58854 + if (grsec_enable_log_rwxmaps)
58855 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58856 +#endif
58857 + return;
58858 +}
58859 diff -urNp linux-2.6.39.1/grsecurity/grsec_ptrace.c linux-2.6.39.1/grsecurity/grsec_ptrace.c
58860 --- linux-2.6.39.1/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
58861 +++ linux-2.6.39.1/grsecurity/grsec_ptrace.c 2011-05-22 19:41:42.000000000 -0400
58862 @@ -0,0 +1,14 @@
58863 +#include <linux/kernel.h>
58864 +#include <linux/sched.h>
58865 +#include <linux/grinternal.h>
58866 +#include <linux/grsecurity.h>
58867 +
58868 +void
58869 +gr_audit_ptrace(struct task_struct *task)
58870 +{
58871 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58872 + if (grsec_enable_audit_ptrace)
58873 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58874 +#endif
58875 + return;
58876 +}
58877 diff -urNp linux-2.6.39.1/grsecurity/grsec_sig.c linux-2.6.39.1/grsecurity/grsec_sig.c
58878 --- linux-2.6.39.1/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
58879 +++ linux-2.6.39.1/grsecurity/grsec_sig.c 2011-05-22 19:41:42.000000000 -0400
58880 @@ -0,0 +1,203 @@
58881 +#include <linux/kernel.h>
58882 +#include <linux/sched.h>
58883 +#include <linux/delay.h>
58884 +#include <linux/grsecurity.h>
58885 +#include <linux/grinternal.h>
58886 +#include <linux/hardirq.h>
58887 +
58888 +char *signames[] = {
58889 + [SIGSEGV] = "Segmentation fault",
58890 + [SIGILL] = "Illegal instruction",
58891 + [SIGABRT] = "Abort",
58892 + [SIGBUS] = "Invalid alignment/Bus error"
58893 +};
58894 +
58895 +void
58896 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58897 +{
58898 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58899 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58900 + (sig == SIGABRT) || (sig == SIGBUS))) {
58901 + if (t->pid == current->pid) {
58902 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58903 + } else {
58904 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58905 + }
58906 + }
58907 +#endif
58908 + return;
58909 +}
58910 +
58911 +int
58912 +gr_handle_signal(const struct task_struct *p, const int sig)
58913 +{
58914 +#ifdef CONFIG_GRKERNSEC
58915 + if (current->pid > 1 && gr_check_protected_task(p)) {
58916 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58917 + return -EPERM;
58918 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58919 + return -EPERM;
58920 + }
58921 +#endif
58922 + return 0;
58923 +}
58924 +
58925 +#ifdef CONFIG_GRKERNSEC
58926 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58927 +
58928 +int gr_fake_force_sig(int sig, struct task_struct *t)
58929 +{
58930 + unsigned long int flags;
58931 + int ret, blocked, ignored;
58932 + struct k_sigaction *action;
58933 +
58934 + spin_lock_irqsave(&t->sighand->siglock, flags);
58935 + action = &t->sighand->action[sig-1];
58936 + ignored = action->sa.sa_handler == SIG_IGN;
58937 + blocked = sigismember(&t->blocked, sig);
58938 + if (blocked || ignored) {
58939 + action->sa.sa_handler = SIG_DFL;
58940 + if (blocked) {
58941 + sigdelset(&t->blocked, sig);
58942 + recalc_sigpending_and_wake(t);
58943 + }
58944 + }
58945 + if (action->sa.sa_handler == SIG_DFL)
58946 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58947 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58948 +
58949 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58950 +
58951 + return ret;
58952 +}
58953 +#endif
58954 +
58955 +#ifdef CONFIG_GRKERNSEC_BRUTE
58956 +#define GR_USER_BAN_TIME (15 * 60)
58957 +
58958 +static int __get_dumpable(unsigned long mm_flags)
58959 +{
58960 + int ret;
58961 +
58962 + ret = mm_flags & MMF_DUMPABLE_MASK;
58963 + return (ret >= 2) ? 2 : ret;
58964 +}
58965 +#endif
58966 +
58967 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58968 +{
58969 +#ifdef CONFIG_GRKERNSEC_BRUTE
58970 + uid_t uid = 0;
58971 +
58972 + rcu_read_lock();
58973 + read_lock(&tasklist_lock);
58974 + read_lock(&grsec_exec_file_lock);
58975 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58976 + p->real_parent->brute = 1;
58977 + else {
58978 + const struct cred *cred = __task_cred(p), *cred2;
58979 + struct task_struct *tsk, *tsk2;
58980 +
58981 + if (!__get_dumpable(mm_flags) && cred->uid) {
58982 + struct user_struct *user;
58983 +
58984 + uid = cred->uid;
58985 +
58986 + /* this is put upon execution past expiration */
58987 + user = find_user(uid);
58988 + if (user == NULL)
58989 + goto unlock;
58990 + user->banned = 1;
58991 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58992 + if (user->ban_expires == ~0UL)
58993 + user->ban_expires--;
58994 +
58995 + do_each_thread(tsk2, tsk) {
58996 + cred2 = __task_cred(tsk);
58997 + if (tsk != p && cred2->uid == uid)
58998 + gr_fake_force_sig(SIGKILL, tsk);
58999 + } while_each_thread(tsk2, tsk);
59000 + }
59001 + }
59002 +unlock:
59003 + read_unlock(&grsec_exec_file_lock);
59004 + read_unlock(&tasklist_lock);
59005 + rcu_read_unlock();
59006 +
59007 + if (uid)
59008 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
59009 +
59010 +#endif
59011 + return;
59012 +}
59013 +
59014 +void gr_handle_brute_check(void)
59015 +{
59016 +#ifdef CONFIG_GRKERNSEC_BRUTE
59017 + if (current->brute)
59018 + msleep(30 * 1000);
59019 +#endif
59020 + return;
59021 +}
59022 +
59023 +void gr_handle_kernel_exploit(void)
59024 +{
59025 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59026 + const struct cred *cred;
59027 + struct task_struct *tsk, *tsk2;
59028 + struct user_struct *user;
59029 + uid_t uid;
59030 +
59031 + if (in_irq() || in_serving_softirq() || in_nmi())
59032 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59033 +
59034 + uid = current_uid();
59035 +
59036 + if (uid == 0)
59037 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59038 + else {
59039 + /* kill all the processes of this user, hold a reference
59040 + to their creds struct, and prevent them from creating
59041 + another process until system reset
59042 + */
59043 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
59044 + /* we intentionally leak this ref */
59045 + user = get_uid(current->cred->user);
59046 + if (user) {
59047 + user->banned = 1;
59048 + user->ban_expires = ~0UL;
59049 + }
59050 +
59051 + read_lock(&tasklist_lock);
59052 + do_each_thread(tsk2, tsk) {
59053 + cred = __task_cred(tsk);
59054 + if (cred->uid == uid)
59055 + gr_fake_force_sig(SIGKILL, tsk);
59056 + } while_each_thread(tsk2, tsk);
59057 + read_unlock(&tasklist_lock);
59058 + }
59059 +#endif
59060 +}
59061 +
59062 +int __gr_process_user_ban(struct user_struct *user)
59063 +{
59064 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59065 + if (unlikely(user->banned)) {
59066 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59067 + user->banned = 0;
59068 + user->ban_expires = 0;
59069 + free_uid(user);
59070 + } else
59071 + return -EPERM;
59072 + }
59073 +#endif
59074 + return 0;
59075 +}
59076 +
59077 +int gr_process_user_ban(void)
59078 +{
59079 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59080 + return __gr_process_user_ban(current->cred->user);
59081 +#endif
59082 + return 0;
59083 +}
59084 diff -urNp linux-2.6.39.1/grsecurity/grsec_sock.c linux-2.6.39.1/grsecurity/grsec_sock.c
59085 --- linux-2.6.39.1/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
59086 +++ linux-2.6.39.1/grsecurity/grsec_sock.c 2011-05-22 20:29:21.000000000 -0400
59087 @@ -0,0 +1,244 @@
59088 +#include <linux/kernel.h>
59089 +#include <linux/module.h>
59090 +#include <linux/sched.h>
59091 +#include <linux/file.h>
59092 +#include <linux/net.h>
59093 +#include <linux/in.h>
59094 +#include <linux/ip.h>
59095 +#include <net/sock.h>
59096 +#include <net/inet_sock.h>
59097 +#include <linux/grsecurity.h>
59098 +#include <linux/grinternal.h>
59099 +#include <linux/gracl.h>
59100 +
59101 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59102 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59103 +
59104 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59105 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59106 +
59107 +#ifdef CONFIG_UNIX_MODULE
59108 +EXPORT_SYMBOL(gr_acl_handle_unix);
59109 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59110 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59111 +EXPORT_SYMBOL(gr_handle_create);
59112 +#endif
59113 +
59114 +#ifdef CONFIG_GRKERNSEC
59115 +#define gr_conn_table_size 32749
59116 +struct conn_table_entry {
59117 + struct conn_table_entry *next;
59118 + struct signal_struct *sig;
59119 +};
59120 +
59121 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59122 +DEFINE_SPINLOCK(gr_conn_table_lock);
59123 +
59124 +extern const char * gr_socktype_to_name(unsigned char type);
59125 +extern const char * gr_proto_to_name(unsigned char proto);
59126 +extern const char * gr_sockfamily_to_name(unsigned char family);
59127 +
59128 +static __inline__ int
59129 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59130 +{
59131 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59132 +}
59133 +
59134 +static __inline__ int
59135 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59136 + __u16 sport, __u16 dport)
59137 +{
59138 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59139 + sig->gr_sport == sport && sig->gr_dport == dport))
59140 + return 1;
59141 + else
59142 + return 0;
59143 +}
59144 +
59145 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59146 +{
59147 + struct conn_table_entry **match;
59148 + unsigned int index;
59149 +
59150 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59151 + sig->gr_sport, sig->gr_dport,
59152 + gr_conn_table_size);
59153 +
59154 + newent->sig = sig;
59155 +
59156 + match = &gr_conn_table[index];
59157 + newent->next = *match;
59158 + *match = newent;
59159 +
59160 + return;
59161 +}
59162 +
59163 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59164 +{
59165 + struct conn_table_entry *match, *last = NULL;
59166 + unsigned int index;
59167 +
59168 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59169 + sig->gr_sport, sig->gr_dport,
59170 + gr_conn_table_size);
59171 +
59172 + match = gr_conn_table[index];
59173 + while (match && !conn_match(match->sig,
59174 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59175 + sig->gr_dport)) {
59176 + last = match;
59177 + match = match->next;
59178 + }
59179 +
59180 + if (match) {
59181 + if (last)
59182 + last->next = match->next;
59183 + else
59184 + gr_conn_table[index] = NULL;
59185 + kfree(match);
59186 + }
59187 +
59188 + return;
59189 +}
59190 +
59191 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59192 + __u16 sport, __u16 dport)
59193 +{
59194 + struct conn_table_entry *match;
59195 + unsigned int index;
59196 +
59197 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59198 +
59199 + match = gr_conn_table[index];
59200 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59201 + match = match->next;
59202 +
59203 + if (match)
59204 + return match->sig;
59205 + else
59206 + return NULL;
59207 +}
59208 +
59209 +#endif
59210 +
59211 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59212 +{
59213 +#ifdef CONFIG_GRKERNSEC
59214 + struct signal_struct *sig = task->signal;
59215 + struct conn_table_entry *newent;
59216 +
59217 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59218 + if (newent == NULL)
59219 + return;
59220 + /* no bh lock needed since we are called with bh disabled */
59221 + spin_lock(&gr_conn_table_lock);
59222 + gr_del_task_from_ip_table_nolock(sig);
59223 + sig->gr_saddr = inet->inet_rcv_saddr;
59224 + sig->gr_daddr = inet->inet_daddr;
59225 + sig->gr_sport = inet->inet_sport;
59226 + sig->gr_dport = inet->inet_dport;
59227 + gr_add_to_task_ip_table_nolock(sig, newent);
59228 + spin_unlock(&gr_conn_table_lock);
59229 +#endif
59230 + return;
59231 +}
59232 +
59233 +void gr_del_task_from_ip_table(struct task_struct *task)
59234 +{
59235 +#ifdef CONFIG_GRKERNSEC
59236 + spin_lock_bh(&gr_conn_table_lock);
59237 + gr_del_task_from_ip_table_nolock(task->signal);
59238 + spin_unlock_bh(&gr_conn_table_lock);
59239 +#endif
59240 + return;
59241 +}
59242 +
59243 +void
59244 +gr_attach_curr_ip(const struct sock *sk)
59245 +{
59246 +#ifdef CONFIG_GRKERNSEC
59247 + struct signal_struct *p, *set;
59248 + const struct inet_sock *inet = inet_sk(sk);
59249 +
59250 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59251 + return;
59252 +
59253 + set = current->signal;
59254 +
59255 + spin_lock_bh(&gr_conn_table_lock);
59256 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59257 + inet->inet_dport, inet->inet_sport);
59258 + if (unlikely(p != NULL)) {
59259 + set->curr_ip = p->curr_ip;
59260 + set->used_accept = 1;
59261 + gr_del_task_from_ip_table_nolock(p);
59262 + spin_unlock_bh(&gr_conn_table_lock);
59263 + return;
59264 + }
59265 + spin_unlock_bh(&gr_conn_table_lock);
59266 +
59267 + set->curr_ip = inet->inet_daddr;
59268 + set->used_accept = 1;
59269 +#endif
59270 + return;
59271 +}
59272 +
59273 +int
59274 +gr_handle_sock_all(const int family, const int type, const int protocol)
59275 +{
59276 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59277 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59278 + (family != AF_UNIX)) {
59279 + if (family == AF_INET)
59280 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59281 + else
59282 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59283 + return -EACCES;
59284 + }
59285 +#endif
59286 + return 0;
59287 +}
59288 +
59289 +int
59290 +gr_handle_sock_server(const struct sockaddr *sck)
59291 +{
59292 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59293 + if (grsec_enable_socket_server &&
59294 + in_group_p(grsec_socket_server_gid) &&
59295 + sck && (sck->sa_family != AF_UNIX) &&
59296 + (sck->sa_family != AF_LOCAL)) {
59297 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59298 + return -EACCES;
59299 + }
59300 +#endif
59301 + return 0;
59302 +}
59303 +
59304 +int
59305 +gr_handle_sock_server_other(const struct sock *sck)
59306 +{
59307 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59308 + if (grsec_enable_socket_server &&
59309 + in_group_p(grsec_socket_server_gid) &&
59310 + sck && (sck->sk_family != AF_UNIX) &&
59311 + (sck->sk_family != AF_LOCAL)) {
59312 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59313 + return -EACCES;
59314 + }
59315 +#endif
59316 + return 0;
59317 +}
59318 +
59319 +int
59320 +gr_handle_sock_client(const struct sockaddr *sck)
59321 +{
59322 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59323 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59324 + sck && (sck->sa_family != AF_UNIX) &&
59325 + (sck->sa_family != AF_LOCAL)) {
59326 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59327 + return -EACCES;
59328 + }
59329 +#endif
59330 + return 0;
59331 +}
59332 diff -urNp linux-2.6.39.1/grsecurity/grsec_sysctl.c linux-2.6.39.1/grsecurity/grsec_sysctl.c
59333 --- linux-2.6.39.1/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
59334 +++ linux-2.6.39.1/grsecurity/grsec_sysctl.c 2011-05-22 19:41:42.000000000 -0400
59335 @@ -0,0 +1,433 @@
59336 +#include <linux/kernel.h>
59337 +#include <linux/sched.h>
59338 +#include <linux/sysctl.h>
59339 +#include <linux/grsecurity.h>
59340 +#include <linux/grinternal.h>
59341 +
59342 +int
59343 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59344 +{
59345 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59346 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59347 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59348 + return -EACCES;
59349 + }
59350 +#endif
59351 + return 0;
59352 +}
59353 +
59354 +#ifdef CONFIG_GRKERNSEC_ROFS
59355 +static int __maybe_unused one = 1;
59356 +#endif
59357 +
59358 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59359 +struct ctl_table grsecurity_table[] = {
59360 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59361 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59362 +#ifdef CONFIG_GRKERNSEC_IO
59363 + {
59364 + .procname = "disable_priv_io",
59365 + .data = &grsec_disable_privio,
59366 + .maxlen = sizeof(int),
59367 + .mode = 0600,
59368 + .proc_handler = &proc_dointvec,
59369 + },
59370 +#endif
59371 +#endif
59372 +#ifdef CONFIG_GRKERNSEC_LINK
59373 + {
59374 + .procname = "linking_restrictions",
59375 + .data = &grsec_enable_link,
59376 + .maxlen = sizeof(int),
59377 + .mode = 0600,
59378 + .proc_handler = &proc_dointvec,
59379 + },
59380 +#endif
59381 +#ifdef CONFIG_GRKERNSEC_FIFO
59382 + {
59383 + .procname = "fifo_restrictions",
59384 + .data = &grsec_enable_fifo,
59385 + .maxlen = sizeof(int),
59386 + .mode = 0600,
59387 + .proc_handler = &proc_dointvec,
59388 + },
59389 +#endif
59390 +#ifdef CONFIG_GRKERNSEC_EXECVE
59391 + {
59392 + .procname = "execve_limiting",
59393 + .data = &grsec_enable_execve,
59394 + .maxlen = sizeof(int),
59395 + .mode = 0600,
59396 + .proc_handler = &proc_dointvec,
59397 + },
59398 +#endif
59399 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59400 + {
59401 + .procname = "ip_blackhole",
59402 + .data = &grsec_enable_blackhole,
59403 + .maxlen = sizeof(int),
59404 + .mode = 0600,
59405 + .proc_handler = &proc_dointvec,
59406 + },
59407 + {
59408 + .procname = "lastack_retries",
59409 + .data = &grsec_lastack_retries,
59410 + .maxlen = sizeof(int),
59411 + .mode = 0600,
59412 + .proc_handler = &proc_dointvec,
59413 + },
59414 +#endif
59415 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59416 + {
59417 + .procname = "exec_logging",
59418 + .data = &grsec_enable_execlog,
59419 + .maxlen = sizeof(int),
59420 + .mode = 0600,
59421 + .proc_handler = &proc_dointvec,
59422 + },
59423 +#endif
59424 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59425 + {
59426 + .procname = "rwxmap_logging",
59427 + .data = &grsec_enable_log_rwxmaps,
59428 + .maxlen = sizeof(int),
59429 + .mode = 0600,
59430 + .proc_handler = &proc_dointvec,
59431 + },
59432 +#endif
59433 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59434 + {
59435 + .procname = "signal_logging",
59436 + .data = &grsec_enable_signal,
59437 + .maxlen = sizeof(int),
59438 + .mode = 0600,
59439 + .proc_handler = &proc_dointvec,
59440 + },
59441 +#endif
59442 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59443 + {
59444 + .procname = "forkfail_logging",
59445 + .data = &grsec_enable_forkfail,
59446 + .maxlen = sizeof(int),
59447 + .mode = 0600,
59448 + .proc_handler = &proc_dointvec,
59449 + },
59450 +#endif
59451 +#ifdef CONFIG_GRKERNSEC_TIME
59452 + {
59453 + .procname = "timechange_logging",
59454 + .data = &grsec_enable_time,
59455 + .maxlen = sizeof(int),
59456 + .mode = 0600,
59457 + .proc_handler = &proc_dointvec,
59458 + },
59459 +#endif
59460 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59461 + {
59462 + .procname = "chroot_deny_shmat",
59463 + .data = &grsec_enable_chroot_shmat,
59464 + .maxlen = sizeof(int),
59465 + .mode = 0600,
59466 + .proc_handler = &proc_dointvec,
59467 + },
59468 +#endif
59469 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59470 + {
59471 + .procname = "chroot_deny_unix",
59472 + .data = &grsec_enable_chroot_unix,
59473 + .maxlen = sizeof(int),
59474 + .mode = 0600,
59475 + .proc_handler = &proc_dointvec,
59476 + },
59477 +#endif
59478 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59479 + {
59480 + .procname = "chroot_deny_mount",
59481 + .data = &grsec_enable_chroot_mount,
59482 + .maxlen = sizeof(int),
59483 + .mode = 0600,
59484 + .proc_handler = &proc_dointvec,
59485 + },
59486 +#endif
59487 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59488 + {
59489 + .procname = "chroot_deny_fchdir",
59490 + .data = &grsec_enable_chroot_fchdir,
59491 + .maxlen = sizeof(int),
59492 + .mode = 0600,
59493 + .proc_handler = &proc_dointvec,
59494 + },
59495 +#endif
59496 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59497 + {
59498 + .procname = "chroot_deny_chroot",
59499 + .data = &grsec_enable_chroot_double,
59500 + .maxlen = sizeof(int),
59501 + .mode = 0600,
59502 + .proc_handler = &proc_dointvec,
59503 + },
59504 +#endif
59505 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59506 + {
59507 + .procname = "chroot_deny_pivot",
59508 + .data = &grsec_enable_chroot_pivot,
59509 + .maxlen = sizeof(int),
59510 + .mode = 0600,
59511 + .proc_handler = &proc_dointvec,
59512 + },
59513 +#endif
59514 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59515 + {
59516 + .procname = "chroot_enforce_chdir",
59517 + .data = &grsec_enable_chroot_chdir,
59518 + .maxlen = sizeof(int),
59519 + .mode = 0600,
59520 + .proc_handler = &proc_dointvec,
59521 + },
59522 +#endif
59523 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59524 + {
59525 + .procname = "chroot_deny_chmod",
59526 + .data = &grsec_enable_chroot_chmod,
59527 + .maxlen = sizeof(int),
59528 + .mode = 0600,
59529 + .proc_handler = &proc_dointvec,
59530 + },
59531 +#endif
59532 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59533 + {
59534 + .procname = "chroot_deny_mknod",
59535 + .data = &grsec_enable_chroot_mknod,
59536 + .maxlen = sizeof(int),
59537 + .mode = 0600,
59538 + .proc_handler = &proc_dointvec,
59539 + },
59540 +#endif
59541 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59542 + {
59543 + .procname = "chroot_restrict_nice",
59544 + .data = &grsec_enable_chroot_nice,
59545 + .maxlen = sizeof(int),
59546 + .mode = 0600,
59547 + .proc_handler = &proc_dointvec,
59548 + },
59549 +#endif
59550 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59551 + {
59552 + .procname = "chroot_execlog",
59553 + .data = &grsec_enable_chroot_execlog,
59554 + .maxlen = sizeof(int),
59555 + .mode = 0600,
59556 + .proc_handler = &proc_dointvec,
59557 + },
59558 +#endif
59559 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59560 + {
59561 + .procname = "chroot_caps",
59562 + .data = &grsec_enable_chroot_caps,
59563 + .maxlen = sizeof(int),
59564 + .mode = 0600,
59565 + .proc_handler = &proc_dointvec,
59566 + },
59567 +#endif
59568 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59569 + {
59570 + .procname = "chroot_deny_sysctl",
59571 + .data = &grsec_enable_chroot_sysctl,
59572 + .maxlen = sizeof(int),
59573 + .mode = 0600,
59574 + .proc_handler = &proc_dointvec,
59575 + },
59576 +#endif
59577 +#ifdef CONFIG_GRKERNSEC_TPE
59578 + {
59579 + .procname = "tpe",
59580 + .data = &grsec_enable_tpe,
59581 + .maxlen = sizeof(int),
59582 + .mode = 0600,
59583 + .proc_handler = &proc_dointvec,
59584 + },
59585 + {
59586 + .procname = "tpe_gid",
59587 + .data = &grsec_tpe_gid,
59588 + .maxlen = sizeof(int),
59589 + .mode = 0600,
59590 + .proc_handler = &proc_dointvec,
59591 + },
59592 +#endif
59593 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59594 + {
59595 + .procname = "tpe_invert",
59596 + .data = &grsec_enable_tpe_invert,
59597 + .maxlen = sizeof(int),
59598 + .mode = 0600,
59599 + .proc_handler = &proc_dointvec,
59600 + },
59601 +#endif
59602 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59603 + {
59604 + .procname = "tpe_restrict_all",
59605 + .data = &grsec_enable_tpe_all,
59606 + .maxlen = sizeof(int),
59607 + .mode = 0600,
59608 + .proc_handler = &proc_dointvec,
59609 + },
59610 +#endif
59611 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59612 + {
59613 + .procname = "socket_all",
59614 + .data = &grsec_enable_socket_all,
59615 + .maxlen = sizeof(int),
59616 + .mode = 0600,
59617 + .proc_handler = &proc_dointvec,
59618 + },
59619 + {
59620 + .procname = "socket_all_gid",
59621 + .data = &grsec_socket_all_gid,
59622 + .maxlen = sizeof(int),
59623 + .mode = 0600,
59624 + .proc_handler = &proc_dointvec,
59625 + },
59626 +#endif
59627 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59628 + {
59629 + .procname = "socket_client",
59630 + .data = &grsec_enable_socket_client,
59631 + .maxlen = sizeof(int),
59632 + .mode = 0600,
59633 + .proc_handler = &proc_dointvec,
59634 + },
59635 + {
59636 + .procname = "socket_client_gid",
59637 + .data = &grsec_socket_client_gid,
59638 + .maxlen = sizeof(int),
59639 + .mode = 0600,
59640 + .proc_handler = &proc_dointvec,
59641 + },
59642 +#endif
59643 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59644 + {
59645 + .procname = "socket_server",
59646 + .data = &grsec_enable_socket_server,
59647 + .maxlen = sizeof(int),
59648 + .mode = 0600,
59649 + .proc_handler = &proc_dointvec,
59650 + },
59651 + {
59652 + .procname = "socket_server_gid",
59653 + .data = &grsec_socket_server_gid,
59654 + .maxlen = sizeof(int),
59655 + .mode = 0600,
59656 + .proc_handler = &proc_dointvec,
59657 + },
59658 +#endif
59659 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59660 + {
59661 + .procname = "audit_group",
59662 + .data = &grsec_enable_group,
59663 + .maxlen = sizeof(int),
59664 + .mode = 0600,
59665 + .proc_handler = &proc_dointvec,
59666 + },
59667 + {
59668 + .procname = "audit_gid",
59669 + .data = &grsec_audit_gid,
59670 + .maxlen = sizeof(int),
59671 + .mode = 0600,
59672 + .proc_handler = &proc_dointvec,
59673 + },
59674 +#endif
59675 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59676 + {
59677 + .procname = "audit_chdir",
59678 + .data = &grsec_enable_chdir,
59679 + .maxlen = sizeof(int),
59680 + .mode = 0600,
59681 + .proc_handler = &proc_dointvec,
59682 + },
59683 +#endif
59684 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59685 + {
59686 + .procname = "audit_mount",
59687 + .data = &grsec_enable_mount,
59688 + .maxlen = sizeof(int),
59689 + .mode = 0600,
59690 + .proc_handler = &proc_dointvec,
59691 + },
59692 +#endif
59693 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59694 + {
59695 + .procname = "audit_textrel",
59696 + .data = &grsec_enable_audit_textrel,
59697 + .maxlen = sizeof(int),
59698 + .mode = 0600,
59699 + .proc_handler = &proc_dointvec,
59700 + },
59701 +#endif
59702 +#ifdef CONFIG_GRKERNSEC_DMESG
59703 + {
59704 + .procname = "dmesg",
59705 + .data = &grsec_enable_dmesg,
59706 + .maxlen = sizeof(int),
59707 + .mode = 0600,
59708 + .proc_handler = &proc_dointvec,
59709 + },
59710 +#endif
59711 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59712 + {
59713 + .procname = "chroot_findtask",
59714 + .data = &grsec_enable_chroot_findtask,
59715 + .maxlen = sizeof(int),
59716 + .mode = 0600,
59717 + .proc_handler = &proc_dointvec,
59718 + },
59719 +#endif
59720 +#ifdef CONFIG_GRKERNSEC_RESLOG
59721 + {
59722 + .procname = "resource_logging",
59723 + .data = &grsec_resource_logging,
59724 + .maxlen = sizeof(int),
59725 + .mode = 0600,
59726 + .proc_handler = &proc_dointvec,
59727 + },
59728 +#endif
59729 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59730 + {
59731 + .procname = "audit_ptrace",
59732 + .data = &grsec_enable_audit_ptrace,
59733 + .maxlen = sizeof(int),
59734 + .mode = 0600,
59735 + .proc_handler = &proc_dointvec,
59736 + },
59737 +#endif
59738 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59739 + {
59740 + .procname = "harden_ptrace",
59741 + .data = &grsec_enable_harden_ptrace,
59742 + .maxlen = sizeof(int),
59743 + .mode = 0600,
59744 + .proc_handler = &proc_dointvec,
59745 + },
59746 +#endif
59747 + {
59748 + .procname = "grsec_lock",
59749 + .data = &grsec_lock,
59750 + .maxlen = sizeof(int),
59751 + .mode = 0600,
59752 + .proc_handler = &proc_dointvec,
59753 + },
59754 +#endif
59755 +#ifdef CONFIG_GRKERNSEC_ROFS
59756 + {
59757 + .procname = "romount_protect",
59758 + .data = &grsec_enable_rofs,
59759 + .maxlen = sizeof(int),
59760 + .mode = 0600,
59761 + .proc_handler = &proc_dointvec_minmax,
59762 + .extra1 = &one,
59763 + .extra2 = &one,
59764 + },
59765 +#endif
59766 + { }
59767 +};
59768 +#endif
59769 diff -urNp linux-2.6.39.1/grsecurity/grsec_time.c linux-2.6.39.1/grsecurity/grsec_time.c
59770 --- linux-2.6.39.1/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
59771 +++ linux-2.6.39.1/grsecurity/grsec_time.c 2011-05-22 19:41:42.000000000 -0400
59772 @@ -0,0 +1,16 @@
59773 +#include <linux/kernel.h>
59774 +#include <linux/sched.h>
59775 +#include <linux/grinternal.h>
59776 +#include <linux/module.h>
59777 +
59778 +void
59779 +gr_log_timechange(void)
59780 +{
59781 +#ifdef CONFIG_GRKERNSEC_TIME
59782 + if (grsec_enable_time)
59783 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59784 +#endif
59785 + return;
59786 +}
59787 +
59788 +EXPORT_SYMBOL(gr_log_timechange);
59789 diff -urNp linux-2.6.39.1/grsecurity/grsec_tpe.c linux-2.6.39.1/grsecurity/grsec_tpe.c
59790 --- linux-2.6.39.1/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
59791 +++ linux-2.6.39.1/grsecurity/grsec_tpe.c 2011-05-22 19:41:42.000000000 -0400
59792 @@ -0,0 +1,39 @@
59793 +#include <linux/kernel.h>
59794 +#include <linux/sched.h>
59795 +#include <linux/file.h>
59796 +#include <linux/fs.h>
59797 +#include <linux/grinternal.h>
59798 +
59799 +extern int gr_acl_tpe_check(void);
59800 +
59801 +int
59802 +gr_tpe_allow(const struct file *file)
59803 +{
59804 +#ifdef CONFIG_GRKERNSEC
59805 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59806 + const struct cred *cred = current_cred();
59807 +
59808 + if (cred->uid && ((grsec_enable_tpe &&
59809 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59810 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59811 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59812 +#else
59813 + in_group_p(grsec_tpe_gid)
59814 +#endif
59815 + ) || gr_acl_tpe_check()) &&
59816 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59817 + (inode->i_mode & S_IWOTH))))) {
59818 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59819 + return 0;
59820 + }
59821 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59822 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59823 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59824 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59825 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59826 + return 0;
59827 + }
59828 +#endif
59829 +#endif
59830 + return 1;
59831 +}
59832 diff -urNp linux-2.6.39.1/grsecurity/grsum.c linux-2.6.39.1/grsecurity/grsum.c
59833 --- linux-2.6.39.1/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
59834 +++ linux-2.6.39.1/grsecurity/grsum.c 2011-05-22 19:41:42.000000000 -0400
59835 @@ -0,0 +1,61 @@
59836 +#include <linux/err.h>
59837 +#include <linux/kernel.h>
59838 +#include <linux/sched.h>
59839 +#include <linux/mm.h>
59840 +#include <linux/scatterlist.h>
59841 +#include <linux/crypto.h>
59842 +#include <linux/gracl.h>
59843 +
59844 +
59845 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59846 +#error "crypto and sha256 must be built into the kernel"
59847 +#endif
59848 +
59849 +int
59850 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59851 +{
59852 + char *p;
59853 + struct crypto_hash *tfm;
59854 + struct hash_desc desc;
59855 + struct scatterlist sg;
59856 + unsigned char temp_sum[GR_SHA_LEN];
59857 + volatile int retval = 0;
59858 + volatile int dummy = 0;
59859 + unsigned int i;
59860 +
59861 + sg_init_table(&sg, 1);
59862 +
59863 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59864 + if (IS_ERR(tfm)) {
59865 + /* should never happen, since sha256 should be built in */
59866 + return 1;
59867 + }
59868 +
59869 + desc.tfm = tfm;
59870 + desc.flags = 0;
59871 +
59872 + crypto_hash_init(&desc);
59873 +
59874 + p = salt;
59875 + sg_set_buf(&sg, p, GR_SALT_LEN);
59876 + crypto_hash_update(&desc, &sg, sg.length);
59877 +
59878 + p = entry->pw;
59879 + sg_set_buf(&sg, p, strlen(p));
59880 +
59881 + crypto_hash_update(&desc, &sg, sg.length);
59882 +
59883 + crypto_hash_final(&desc, temp_sum);
59884 +
59885 + memset(entry->pw, 0, GR_PW_LEN);
59886 +
59887 + for (i = 0; i < GR_SHA_LEN; i++)
59888 + if (sum[i] != temp_sum[i])
59889 + retval = 1;
59890 + else
59891 + dummy = 1; // waste a cycle
59892 +
59893 + crypto_free_hash(tfm);
59894 +
59895 + return retval;
59896 +}
59897 diff -urNp linux-2.6.39.1/grsecurity/Kconfig linux-2.6.39.1/grsecurity/Kconfig
59898 --- linux-2.6.39.1/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
59899 +++ linux-2.6.39.1/grsecurity/Kconfig 2011-05-22 19:41:42.000000000 -0400
59900 @@ -0,0 +1,1045 @@
59901 +#
59902 +# grecurity configuration
59903 +#
59904 +
59905 +menu "Grsecurity"
59906 +
59907 +config GRKERNSEC
59908 + bool "Grsecurity"
59909 + select CRYPTO
59910 + select CRYPTO_SHA256
59911 + help
59912 + If you say Y here, you will be able to configure many features
59913 + that will enhance the security of your system. It is highly
59914 + recommended that you say Y here and read through the help
59915 + for each option so that you fully understand the features and
59916 + can evaluate their usefulness for your machine.
59917 +
59918 +choice
59919 + prompt "Security Level"
59920 + depends on GRKERNSEC
59921 + default GRKERNSEC_CUSTOM
59922 +
59923 +config GRKERNSEC_LOW
59924 + bool "Low"
59925 + select GRKERNSEC_LINK
59926 + select GRKERNSEC_FIFO
59927 + select GRKERNSEC_EXECVE
59928 + select GRKERNSEC_RANDNET
59929 + select GRKERNSEC_DMESG
59930 + select GRKERNSEC_CHROOT
59931 + select GRKERNSEC_CHROOT_CHDIR
59932 +
59933 + help
59934 + If you choose this option, several of the grsecurity options will
59935 + be enabled that will give you greater protection against a number
59936 + of attacks, while assuring that none of your software will have any
59937 + conflicts with the additional security measures. If you run a lot
59938 + of unusual software, or you are having problems with the higher
59939 + security levels, you should say Y here. With this option, the
59940 + following features are enabled:
59941 +
59942 + - Linking restrictions
59943 + - FIFO restrictions
59944 + - Enforcing RLIMIT_NPROC on execve
59945 + - Restricted dmesg
59946 + - Enforced chdir("/") on chroot
59947 + - Runtime module disabling
59948 +
59949 +config GRKERNSEC_MEDIUM
59950 + bool "Medium"
59951 + select PAX
59952 + select PAX_EI_PAX
59953 + select PAX_PT_PAX_FLAGS
59954 + select PAX_HAVE_ACL_FLAGS
59955 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
59956 + select GRKERNSEC_CHROOT
59957 + select GRKERNSEC_CHROOT_SYSCTL
59958 + select GRKERNSEC_LINK
59959 + select GRKERNSEC_FIFO
59960 + select GRKERNSEC_EXECVE
59961 + select GRKERNSEC_DMESG
59962 + select GRKERNSEC_RANDNET
59963 + select GRKERNSEC_FORKFAIL
59964 + select GRKERNSEC_TIME
59965 + select GRKERNSEC_SIGNAL
59966 + select GRKERNSEC_CHROOT
59967 + select GRKERNSEC_CHROOT_UNIX
59968 + select GRKERNSEC_CHROOT_MOUNT
59969 + select GRKERNSEC_CHROOT_PIVOT
59970 + select GRKERNSEC_CHROOT_DOUBLE
59971 + select GRKERNSEC_CHROOT_CHDIR
59972 + select GRKERNSEC_CHROOT_MKNOD
59973 + select GRKERNSEC_PROC
59974 + select GRKERNSEC_PROC_USERGROUP
59975 + select PAX_RANDUSTACK
59976 + select PAX_ASLR
59977 + select PAX_RANDMMAP
59978 + select PAX_REFCOUNT if (X86 || SPARC64)
59979 + select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
59980 +
59981 + help
59982 + If you say Y here, several features in addition to those included
59983 + in the low additional security level will be enabled. These
59984 + features provide even more security to your system, though in rare
59985 + cases they may be incompatible with very old or poorly written
59986 + software. If you enable this option, make sure that your auth
59987 + service (identd) is running as gid 1001. With this option,
59988 + the following features (in addition to those provided in the
59989 + low additional security level) will be enabled:
59990 +
59991 + - Failed fork logging
59992 + - Time change logging
59993 + - Signal logging
59994 + - Deny mounts in chroot
59995 + - Deny double chrooting
59996 + - Deny sysctl writes in chroot
59997 + - Deny mknod in chroot
59998 + - Deny access to abstract AF_UNIX sockets out of chroot
59999 + - Deny pivot_root in chroot
60000 + - Denied writes of /dev/kmem, /dev/mem, and /dev/port
60001 + - /proc restrictions with special GID set to 10 (usually wheel)
60002 + - Address Space Layout Randomization (ASLR)
60003 + - Prevent exploitation of most refcount overflows
60004 + - Bounds checking of copying between the kernel and userland
60005 +
60006 +config GRKERNSEC_HIGH
60007 + bool "High"
60008 + select GRKERNSEC_LINK
60009 + select GRKERNSEC_FIFO
60010 + select GRKERNSEC_EXECVE
60011 + select GRKERNSEC_DMESG
60012 + select GRKERNSEC_FORKFAIL
60013 + select GRKERNSEC_TIME
60014 + select GRKERNSEC_SIGNAL
60015 + select GRKERNSEC_CHROOT
60016 + select GRKERNSEC_CHROOT_SHMAT
60017 + select GRKERNSEC_CHROOT_UNIX
60018 + select GRKERNSEC_CHROOT_MOUNT
60019 + select GRKERNSEC_CHROOT_FCHDIR
60020 + select GRKERNSEC_CHROOT_PIVOT
60021 + select GRKERNSEC_CHROOT_DOUBLE
60022 + select GRKERNSEC_CHROOT_CHDIR
60023 + select GRKERNSEC_CHROOT_MKNOD
60024 + select GRKERNSEC_CHROOT_CAPS
60025 + select GRKERNSEC_CHROOT_SYSCTL
60026 + select GRKERNSEC_CHROOT_FINDTASK
60027 + select GRKERNSEC_SYSFS_RESTRICT
60028 + select GRKERNSEC_PROC
60029 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
60030 + select GRKERNSEC_HIDESYM
60031 + select GRKERNSEC_BRUTE
60032 + select GRKERNSEC_PROC_USERGROUP
60033 + select GRKERNSEC_KMEM
60034 + select GRKERNSEC_RESLOG
60035 + select GRKERNSEC_RANDNET
60036 + select GRKERNSEC_PROC_ADD
60037 + select GRKERNSEC_CHROOT_CHMOD
60038 + select GRKERNSEC_CHROOT_NICE
60039 + select GRKERNSEC_AUDIT_MOUNT
60040 + select GRKERNSEC_MODHARDEN if (MODULES)
60041 + select GRKERNSEC_HARDEN_PTRACE
60042 + select GRKERNSEC_VM86 if (X86_32)
60043 + select GRKERNSEC_KERN_LOCKOUT if (X86)
60044 + select PAX
60045 + select PAX_RANDUSTACK
60046 + select PAX_ASLR
60047 + select PAX_RANDMMAP
60048 + select PAX_NOEXEC
60049 + select PAX_MPROTECT
60050 + select PAX_EI_PAX
60051 + select PAX_PT_PAX_FLAGS
60052 + select PAX_HAVE_ACL_FLAGS
60053 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
60054 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
60055 + select PAX_RANDKSTACK if (X86_TSC && X86)
60056 + select PAX_SEGMEXEC if (X86_32)
60057 + select PAX_PAGEEXEC
60058 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
60059 + select PAX_EMUTRAMP if (PARISC)
60060 + select PAX_EMUSIGRT if (PARISC)
60061 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
60062 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
60063 + select PAX_REFCOUNT if (X86 || SPARC64)
60064 + select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
60065 + help
60066 + If you say Y here, many of the features of grsecurity will be
60067 + enabled, which will protect you against many kinds of attacks
60068 + against your system. The heightened security comes at a cost
60069 + of an increased chance of incompatibilities with rare software
60070 + on your machine. Since this security level enables PaX, you should
60071 + view <http://pax.grsecurity.net> and read about the PaX
60072 + project. While you are there, download chpax and run it on
60073 + binaries that cause problems with PaX. Also remember that
60074 + since the /proc restrictions are enabled, you must run your
60075 + identd as gid 1001. This security level enables the following
60076 + features in addition to those listed in the low and medium
60077 + security levels:
60078 +
60079 + - Additional /proc restrictions
60080 + - Chmod restrictions in chroot
60081 + - No signals, ptrace, or viewing of processes outside of chroot
60082 + - Capability restrictions in chroot
60083 + - Deny fchdir out of chroot
60084 + - Priority restrictions in chroot
60085 + - Segmentation-based implementation of PaX
60086 + - Mprotect restrictions
60087 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
60088 + - Kernel stack randomization
60089 + - Mount/unmount/remount logging
60090 + - Kernel symbol hiding
60091 + - Prevention of memory exhaustion-based exploits
60092 + - Hardening of module auto-loading
60093 + - Ptrace restrictions
60094 + - Restricted vm86 mode
60095 + - Restricted sysfs/debugfs
60096 + - Active kernel exploit response
60097 +
60098 +config GRKERNSEC_CUSTOM
60099 + bool "Custom"
60100 + help
60101 + If you say Y here, you will be able to configure every grsecurity
60102 + option, which allows you to enable many more features that aren't
60103 + covered in the basic security levels. These additional features
60104 + include TPE, socket restrictions, and the sysctl system for
60105 + grsecurity. It is advised that you read through the help for
60106 + each option to determine its usefulness in your situation.
60107 +
60108 +endchoice
60109 +
60110 +menu "Address Space Protection"
60111 +depends on GRKERNSEC
60112 +
60113 +config GRKERNSEC_KMEM
60114 + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
60115 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60116 + help
60117 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60118 + be written to via mmap or otherwise to modify the running kernel.
60119 + /dev/port will also not be allowed to be opened. If you have module
60120 + support disabled, enabling this will close up four ways that are
60121 + currently used to insert malicious code into the running kernel.
60122 + Even with all these features enabled, we still highly recommend that
60123 + you use the RBAC system, as it is still possible for an attacker to
60124 + modify the running kernel through privileged I/O granted by ioperm/iopl.
60125 + If you are not using XFree86, you may be able to stop this additional
60126 + case by enabling the 'Disable privileged I/O' option. Though nothing
60127 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60128 + but only to video memory, which is the only writing we allow in this
60129 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60130 + not be allowed to mprotect it with PROT_WRITE later.
60131 + It is highly recommended that you say Y here if you meet all the
60132 + conditions above.
60133 +
60134 +config GRKERNSEC_VM86
60135 + bool "Restrict VM86 mode"
60136 + depends on X86_32
60137 +
60138 + help
60139 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60140 + make use of a special execution mode on 32bit x86 processors called
60141 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60142 + video cards and will still work with this option enabled. The purpose
60143 + of the option is to prevent exploitation of emulation errors in
60144 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
60145 + Nearly all users should be able to enable this option.
60146 +
60147 +config GRKERNSEC_IO
60148 + bool "Disable privileged I/O"
60149 + depends on X86
60150 + select RTC_CLASS
60151 + select RTC_INTF_DEV
60152 + select RTC_DRV_CMOS
60153 +
60154 + help
60155 + If you say Y here, all ioperm and iopl calls will return an error.
60156 + Ioperm and iopl can be used to modify the running kernel.
60157 + Unfortunately, some programs need this access to operate properly,
60158 + the most notable of which are XFree86 and hwclock. hwclock can be
60159 + remedied by having RTC support in the kernel, so real-time
60160 + clock support is enabled if this option is enabled, to ensure
60161 + that hwclock operates correctly. XFree86 still will not
60162 + operate correctly with this option enabled, so DO NOT CHOOSE Y
60163 + IF YOU USE XFree86. If you use XFree86 and you still want to
60164 + protect your kernel against modification, use the RBAC system.
60165 +
60166 +config GRKERNSEC_PROC_MEMMAP
60167 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
60168 + default y if (PAX_NOEXEC || PAX_ASLR)
60169 + depends on PAX_NOEXEC || PAX_ASLR
60170 + help
60171 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
60172 + give no information about the addresses of its mappings if
60173 + PaX features that rely on random addresses are enabled on the task.
60174 + If you use PaX it is greatly recommended that you say Y here as it
60175 + closes up a hole that makes the full ASLR useless for suid
60176 + binaries.
60177 +
60178 +config GRKERNSEC_BRUTE
60179 + bool "Deter exploit bruteforcing"
60180 + help
60181 + If you say Y here, attempts to bruteforce exploits against forking
60182 + daemons such as apache or sshd, as well as against suid/sgid binaries
60183 + will be deterred. When a child of a forking daemon is killed by PaX
60184 + or crashes due to an illegal instruction or other suspicious signal,
60185 + the parent process will be delayed 30 seconds upon every subsequent
60186 + fork until the administrator is able to assess the situation and
60187 + restart the daemon.
60188 + In the suid/sgid case, the attempt is logged, the user has all their
60189 + processes terminated, and they are prevented from executing any further
60190 + processes for 15 minutes.
60191 + It is recommended that you also enable signal logging in the auditing
60192 + section so that logs are generated when a process triggers a suspicious
60193 + signal.
60194 +
60195 +config GRKERNSEC_MODHARDEN
60196 + bool "Harden module auto-loading"
60197 + depends on MODULES
60198 + help
60199 + If you say Y here, module auto-loading in response to use of some
60200 + feature implemented by an unloaded module will be restricted to
60201 + root users. Enabling this option helps defend against attacks
60202 + by unprivileged users who abuse the auto-loading behavior to
60203 + cause a vulnerable module to load that is then exploited.
60204 +
60205 + If this option prevents a legitimate use of auto-loading for a
60206 + non-root user, the administrator can execute modprobe manually
60207 + with the exact name of the module mentioned in the alert log.
60208 + Alternatively, the administrator can add the module to the list
60209 + of modules loaded at boot by modifying init scripts.
60210 +
60211 + Modification of init scripts will most likely be needed on
60212 + Ubuntu servers with encrypted home directory support enabled,
60213 + as the first non-root user logging in will cause the ecb(aes),
60214 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
60215 +
60216 +config GRKERNSEC_HIDESYM
60217 + bool "Hide kernel symbols"
60218 + help
60219 + If you say Y here, getting information on loaded modules, and
60220 + displaying all kernel symbols through a syscall will be restricted
60221 + to users with CAP_SYS_MODULE. For software compatibility reasons,
60222 + /proc/kallsyms will be restricted to the root user. The RBAC
60223 + system can hide that entry even from root.
60224 +
60225 + This option also prevents leaking of kernel addresses through
60226 + several /proc entries.
60227 +
60228 + Note that this option is only effective provided the following
60229 + conditions are met:
60230 + 1) The kernel using grsecurity is not precompiled by some distribution
60231 + 2) You have also enabled GRKERNSEC_DMESG
60232 + 3) You are using the RBAC system and hiding other files such as your
60233 + kernel image and System.map. Alternatively, enabling this option
60234 + causes the permissions on /boot, /lib/modules, and the kernel
60235 + source directory to change at compile time to prevent
60236 + reading by non-root users.
60237 + If the above conditions are met, this option will aid in providing a
60238 + useful protection against local kernel exploitation of overflows
60239 + and arbitrary read/write vulnerabilities.
60240 +
60241 +config GRKERNSEC_KERN_LOCKOUT
60242 + bool "Active kernel exploit response"
60243 + depends on X86
60244 + help
60245 + If you say Y here, when a PaX alert is triggered due to suspicious
60246 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
60247 + or an OOPs occurs due to bad memory accesses, instead of just
60248 + terminating the offending process (and potentially allowing
60249 + a subsequent exploit from the same user), we will take one of two
60250 + actions:
60251 + If the user was root, we will panic the system
60252 + If the user was non-root, we will log the attempt, terminate
60253 + all processes owned by the user, then prevent them from creating
60254 + any new processes until the system is restarted
60255 + This deters repeated kernel exploitation/bruteforcing attempts
60256 + and is useful for later forensics.
60257 +
60258 +endmenu
60259 +menu "Role Based Access Control Options"
60260 +depends on GRKERNSEC
60261 +
60262 +config GRKERNSEC_RBAC_DEBUG
60263 + bool
60264 +
60265 +config GRKERNSEC_NO_RBAC
60266 + bool "Disable RBAC system"
60267 + help
60268 + If you say Y here, the /dev/grsec device will be removed from the kernel,
60269 + preventing the RBAC system from being enabled. You should only say Y
60270 + here if you have no intention of using the RBAC system, so as to prevent
60271 + an attacker with root access from misusing the RBAC system to hide files
60272 + and processes when loadable module support and /dev/[k]mem have been
60273 + locked down.
60274 +
60275 +config GRKERNSEC_ACL_HIDEKERN
60276 + bool "Hide kernel processes"
60277 + help
60278 + If you say Y here, all kernel threads will be hidden to all
60279 + processes but those whose subject has the "view hidden processes"
60280 + flag.
60281 +
60282 +config GRKERNSEC_ACL_MAXTRIES
60283 + int "Maximum tries before password lockout"
60284 + default 3
60285 + help
60286 + This option enforces the maximum number of times a user can attempt
60287 + to authorize themselves with the grsecurity RBAC system before being
60288 + denied the ability to attempt authorization again for a specified time.
60289 + The lower the number, the harder it will be to brute-force a password.
60290 +
60291 +config GRKERNSEC_ACL_TIMEOUT
60292 + int "Time to wait after max password tries, in seconds"
60293 + default 30
60294 + help
60295 + This option specifies the time the user must wait after attempting to
60296 + authorize to the RBAC system with the maximum number of invalid
60297 + passwords. The higher the number, the harder it will be to brute-force
60298 + a password.
60299 +
60300 +endmenu
60301 +menu "Filesystem Protections"
60302 +depends on GRKERNSEC
60303 +
60304 +config GRKERNSEC_PROC
60305 + bool "Proc restrictions"
60306 + help
60307 + If you say Y here, the permissions of the /proc filesystem
60308 + will be altered to enhance system security and privacy. You MUST
60309 + choose either a user only restriction or a user and group restriction.
60310 + Depending upon the option you choose, you can either restrict users to
60311 + see only the processes they themselves run, or choose a group that can
60312 + view all processes and files normally restricted to root if you choose
60313 + the "restrict to user only" option. NOTE: If you're running identd as
60314 + a non-root user, you will have to run it as the group you specify here.
60315 +
60316 +config GRKERNSEC_PROC_USER
60317 + bool "Restrict /proc to user only"
60318 + depends on GRKERNSEC_PROC
60319 + help
60320 + If you say Y here, non-root users will only be able to view their own
60321 + processes, and restricts them from viewing network-related information,
60322 + and viewing kernel symbol and module information.
60323 +
60324 +config GRKERNSEC_PROC_USERGROUP
60325 + bool "Allow special group"
60326 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
60327 + help
60328 + If you say Y here, you will be able to select a group that will be
60329 + able to view all processes and network-related information. If you've
60330 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
60331 + remain hidden. This option is useful if you want to run identd as
60332 + a non-root user.
60333 +
60334 +config GRKERNSEC_PROC_GID
60335 + int "GID for special group"
60336 + depends on GRKERNSEC_PROC_USERGROUP
60337 + default 1001
60338 +
60339 +config GRKERNSEC_PROC_ADD
60340 + bool "Additional restrictions"
60341 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
60342 + help
60343 + If you say Y here, additional restrictions will be placed on
60344 + /proc that keep normal users from viewing device information and
60345 + slabinfo information that could be useful for exploits.
60346 +
60347 +config GRKERNSEC_LINK
60348 + bool "Linking restrictions"
60349 + help
60350 + If you say Y here, /tmp race exploits will be prevented, since users
60351 + will no longer be able to follow symlinks owned by other users in
60352 + world-writable +t directories (e.g. /tmp), unless the owner of the
60353 + symlink is the owner of the directory. users will also not be
60354 + able to hardlink to files they do not own. If the sysctl option is
60355 + enabled, a sysctl option with name "linking_restrictions" is created.
60356 +
60357 +config GRKERNSEC_FIFO
60358 + bool "FIFO restrictions"
60359 + help
60360 + If you say Y here, users will not be able to write to FIFOs they don't
60361 + own in world-writable +t directories (e.g. /tmp), unless the owner of
60362 + the FIFO is the same owner of the directory it's held in. If the sysctl
60363 + option is enabled, a sysctl option with name "fifo_restrictions" is
60364 + created.
60365 +
60366 +config GRKERNSEC_SYSFS_RESTRICT
60367 + bool "Sysfs/debugfs restriction"
60368 + depends on SYSFS
60369 + help
60370 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
60371 + any filesystem normally mounted under it (e.g. debugfs) will only
60372 + be accessible by root. These filesystems generally provide access
60373 + to hardware and debug information that isn't appropriate for unprivileged
60374 + users of the system. Sysfs and debugfs have also become a large source
60375 + of new vulnerabilities, ranging from infoleaks to local compromise.
60376 + There has been very little oversight with an eye toward security involved
60377 + in adding new exporters of information to these filesystems, so their
60378 + use is discouraged.
60379 + This option is equivalent to a chmod 0700 of the mount paths.
60380 +
60381 +config GRKERNSEC_ROFS
60382 + bool "Runtime read-only mount protection"
60383 + help
60384 + If you say Y here, a sysctl option with name "romount_protect" will
60385 + be created. By setting this option to 1 at runtime, filesystems
60386 + will be protected in the following ways:
60387 + * No new writable mounts will be allowed
60388 + * Existing read-only mounts won't be able to be remounted read/write
60389 + * Write operations will be denied on all block devices
60390 + This option acts independently of grsec_lock: once it is set to 1,
60391 + it cannot be turned off. Therefore, please be mindful of the resulting
60392 + behavior if this option is enabled in an init script on a read-only
60393 + filesystem. This feature is mainly intended for secure embedded systems.
60394 +
60395 +config GRKERNSEC_CHROOT
60396 + bool "Chroot jail restrictions"
60397 + help
60398 + If you say Y here, you will be able to choose several options that will
60399 + make breaking out of a chrooted jail much more difficult. If you
60400 + encounter no software incompatibilities with the following options, it
60401 + is recommended that you enable each one.
60402 +
60403 +config GRKERNSEC_CHROOT_MOUNT
60404 + bool "Deny mounts"
60405 + depends on GRKERNSEC_CHROOT
60406 + help
60407 + If you say Y here, processes inside a chroot will not be able to
60408 + mount or remount filesystems. If the sysctl option is enabled, a
60409 + sysctl option with name "chroot_deny_mount" is created.
60410 +
60411 +config GRKERNSEC_CHROOT_DOUBLE
60412 + bool "Deny double-chroots"
60413 + depends on GRKERNSEC_CHROOT
60414 + help
60415 + If you say Y here, processes inside a chroot will not be able to chroot
60416 + again outside the chroot. This is a widely used method of breaking
60417 + out of a chroot jail and should not be allowed. If the sysctl
60418 + option is enabled, a sysctl option with name
60419 + "chroot_deny_chroot" is created.
60420 +
60421 +config GRKERNSEC_CHROOT_PIVOT
60422 + bool "Deny pivot_root in chroot"
60423 + depends on GRKERNSEC_CHROOT
60424 + help
60425 + If you say Y here, processes inside a chroot will not be able to use
60426 + a function called pivot_root() that was introduced in Linux 2.3.41. It
60427 + works similar to chroot in that it changes the root filesystem. This
60428 + function could be misused in a chrooted process to attempt to break out
60429 + of the chroot, and therefore should not be allowed. If the sysctl
60430 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
60431 + created.
60432 +
60433 +config GRKERNSEC_CHROOT_CHDIR
60434 + bool "Enforce chdir(\"/\") on all chroots"
60435 + depends on GRKERNSEC_CHROOT
60436 + help
60437 + If you say Y here, the current working directory of all newly-chrooted
60438 + applications will be set to the the root directory of the chroot.
60439 + The man page on chroot(2) states:
60440 + Note that this call does not change the current working
60441 + directory, so that `.' can be outside the tree rooted at
60442 + `/'. In particular, the super-user can escape from a
60443 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
60444 +
60445 + It is recommended that you say Y here, since it's not known to break
60446 + any software. If the sysctl option is enabled, a sysctl option with
60447 + name "chroot_enforce_chdir" is created.
60448 +
60449 +config GRKERNSEC_CHROOT_CHMOD
60450 + bool "Deny (f)chmod +s"
60451 + depends on GRKERNSEC_CHROOT
60452 + help
60453 + If you say Y here, processes inside a chroot will not be able to chmod
60454 + or fchmod files to make them have suid or sgid bits. This protects
60455 + against another published method of breaking a chroot. If the sysctl
60456 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
60457 + created.
60458 +
60459 +config GRKERNSEC_CHROOT_FCHDIR
60460 + bool "Deny fchdir out of chroot"
60461 + depends on GRKERNSEC_CHROOT
60462 + help
60463 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
60464 + to a file descriptor of the chrooting process that points to a directory
60465 + outside the filesystem will be stopped. If the sysctl option
60466 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
60467 +
60468 +config GRKERNSEC_CHROOT_MKNOD
60469 + bool "Deny mknod"
60470 + depends on GRKERNSEC_CHROOT
60471 + help
60472 + If you say Y here, processes inside a chroot will not be allowed to
60473 + mknod. The problem with using mknod inside a chroot is that it
60474 + would allow an attacker to create a device entry that is the same
60475 + as one on the physical root of your system, which could range from
60476 + anything from the console device to a device for your harddrive (which
60477 + they could then use to wipe the drive or steal data). It is recommended
60478 + that you say Y here, unless you run into software incompatibilities.
60479 + If the sysctl option is enabled, a sysctl option with name
60480 + "chroot_deny_mknod" is created.
60481 +
60482 +config GRKERNSEC_CHROOT_SHMAT
60483 + bool "Deny shmat() out of chroot"
60484 + depends on GRKERNSEC_CHROOT
60485 + help
60486 + If you say Y here, processes inside a chroot will not be able to attach
60487 + to shared memory segments that were created outside of the chroot jail.
60488 + It is recommended that you say Y here. If the sysctl option is enabled,
60489 + a sysctl option with name "chroot_deny_shmat" is created.
60490 +
60491 +config GRKERNSEC_CHROOT_UNIX
60492 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
60493 + depends on GRKERNSEC_CHROOT
60494 + help
60495 + If you say Y here, processes inside a chroot will not be able to
60496 + connect to abstract (meaning not belonging to a filesystem) Unix
60497 + domain sockets that were bound outside of a chroot. It is recommended
60498 + that you say Y here. If the sysctl option is enabled, a sysctl option
60499 + with name "chroot_deny_unix" is created.
60500 +
60501 +config GRKERNSEC_CHROOT_FINDTASK
60502 + bool "Protect outside processes"
60503 + depends on GRKERNSEC_CHROOT
60504 + help
60505 + If you say Y here, processes inside a chroot will not be able to
60506 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
60507 + getsid, or view any process outside of the chroot. If the sysctl
60508 + option is enabled, a sysctl option with name "chroot_findtask" is
60509 + created.
60510 +
60511 +config GRKERNSEC_CHROOT_NICE
60512 + bool "Restrict priority changes"
60513 + depends on GRKERNSEC_CHROOT
60514 + help
60515 + If you say Y here, processes inside a chroot will not be able to raise
60516 + the priority of processes in the chroot, or alter the priority of
60517 + processes outside the chroot. This provides more security than simply
60518 + removing CAP_SYS_NICE from the process' capability set. If the
60519 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
60520 + is created.
60521 +
60522 +config GRKERNSEC_CHROOT_SYSCTL
60523 + bool "Deny sysctl writes"
60524 + depends on GRKERNSEC_CHROOT
60525 + help
60526 + If you say Y here, an attacker in a chroot will not be able to
60527 + write to sysctl entries, either by sysctl(2) or through a /proc
60528 + interface. It is strongly recommended that you say Y here. If the
60529 + sysctl option is enabled, a sysctl option with name
60530 + "chroot_deny_sysctl" is created.
60531 +
60532 +config GRKERNSEC_CHROOT_CAPS
60533 + bool "Capability restrictions"
60534 + depends on GRKERNSEC_CHROOT
60535 + help
60536 + If you say Y here, the capabilities on all root processes within a
60537 + chroot jail will be lowered to stop module insertion, raw i/o,
60538 + system and net admin tasks, rebooting the system, modifying immutable
60539 + files, modifying IPC owned by another, and changing the system time.
60540 + This is left an option because it can break some apps. Disable this
60541 + if your chrooted apps are having problems performing those kinds of
60542 + tasks. If the sysctl option is enabled, a sysctl option with
60543 + name "chroot_caps" is created.
60544 +
60545 +endmenu
60546 +menu "Kernel Auditing"
60547 +depends on GRKERNSEC
60548 +
60549 +config GRKERNSEC_AUDIT_GROUP
60550 + bool "Single group for auditing"
60551 + help
60552 + If you say Y here, the exec, chdir, and (un)mount logging features
60553 + will only operate on a group you specify. This option is recommended
60554 + if you only want to watch certain users instead of having a large
60555 + amount of logs from the entire system. If the sysctl option is enabled,
60556 + a sysctl option with name "audit_group" is created.
60557 +
60558 +config GRKERNSEC_AUDIT_GID
60559 + int "GID for auditing"
60560 + depends on GRKERNSEC_AUDIT_GROUP
60561 + default 1007
60562 +
60563 +config GRKERNSEC_EXECLOG
60564 + bool "Exec logging"
60565 + help
60566 + If you say Y here, all execve() calls will be logged (since the
60567 + other exec*() calls are frontends to execve(), all execution
60568 + will be logged). Useful for shell-servers that like to keep track
60569 + of their users. If the sysctl option is enabled, a sysctl option with
60570 + name "exec_logging" is created.
60571 + WARNING: This option when enabled will produce a LOT of logs, especially
60572 + on an active system.
60573 +
60574 +config GRKERNSEC_RESLOG
60575 + bool "Resource logging"
60576 + help
60577 + If you say Y here, all attempts to overstep resource limits will
60578 + be logged with the resource name, the requested size, and the current
60579 + limit. It is highly recommended that you say Y here. If the sysctl
60580 + option is enabled, a sysctl option with name "resource_logging" is
60581 + created. If the RBAC system is enabled, the sysctl value is ignored.
60582 +
60583 +config GRKERNSEC_CHROOT_EXECLOG
60584 + bool "Log execs within chroot"
60585 + help
60586 + If you say Y here, all executions inside a chroot jail will be logged
60587 + to syslog. This can cause a large amount of logs if certain
60588 + applications (eg. djb's daemontools) are installed on the system, and
60589 + is therefore left as an option. If the sysctl option is enabled, a
60590 + sysctl option with name "chroot_execlog" is created.
60591 +
60592 +config GRKERNSEC_AUDIT_PTRACE
60593 + bool "Ptrace logging"
60594 + help
60595 + If you say Y here, all attempts to attach to a process via ptrace
60596 + will be logged. If the sysctl option is enabled, a sysctl option
60597 + with name "audit_ptrace" is created.
60598 +
60599 +config GRKERNSEC_AUDIT_CHDIR
60600 + bool "Chdir logging"
60601 + help
60602 + If you say Y here, all chdir() calls will be logged. If the sysctl
60603 + option is enabled, a sysctl option with name "audit_chdir" is created.
60604 +
60605 +config GRKERNSEC_AUDIT_MOUNT
60606 + bool "(Un)Mount logging"
60607 + help
60608 + If you say Y here, all mounts and unmounts will be logged. If the
60609 + sysctl option is enabled, a sysctl option with name "audit_mount" is
60610 + created.
60611 +
60612 +config GRKERNSEC_SIGNAL
60613 + bool "Signal logging"
60614 + help
60615 + If you say Y here, certain important signals will be logged, such as
60616 + SIGSEGV, which will as a result inform you of when a error in a program
60617 + occurred, which in some cases could mean a possible exploit attempt.
60618 + If the sysctl option is enabled, a sysctl option with name
60619 + "signal_logging" is created.
60620 +
60621 +config GRKERNSEC_FORKFAIL
60622 + bool "Fork failure logging"
60623 + help
60624 + If you say Y here, all failed fork() attempts will be logged.
60625 + This could suggest a fork bomb, or someone attempting to overstep
60626 + their process limit. If the sysctl option is enabled, a sysctl option
60627 + with name "forkfail_logging" is created.
60628 +
60629 +config GRKERNSEC_TIME
60630 + bool "Time change logging"
60631 + help
60632 + If you say Y here, any changes of the system clock will be logged.
60633 + If the sysctl option is enabled, a sysctl option with name
60634 + "timechange_logging" is created.
60635 +
60636 +config GRKERNSEC_PROC_IPADDR
60637 + bool "/proc/<pid>/ipaddr support"
60638 + help
60639 + If you say Y here, a new entry will be added to each /proc/<pid>
60640 + directory that contains the IP address of the person using the task.
60641 + The IP is carried across local TCP and AF_UNIX stream sockets.
60642 + This information can be useful for IDS/IPSes to perform remote response
60643 + to a local attack. The entry is readable by only the owner of the
60644 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
60645 + the RBAC system), and thus does not create privacy concerns.
60646 +
60647 +config GRKERNSEC_RWXMAP_LOG
60648 + bool 'Denied RWX mmap/mprotect logging'
60649 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
60650 + help
60651 + If you say Y here, calls to mmap() and mprotect() with explicit
60652 + usage of PROT_WRITE and PROT_EXEC together will be logged when
60653 + denied by the PAX_MPROTECT feature. If the sysctl option is
60654 + enabled, a sysctl option with name "rwxmap_logging" is created.
60655 +
60656 +config GRKERNSEC_AUDIT_TEXTREL
60657 + bool 'ELF text relocations logging (READ HELP)'
60658 + depends on PAX_MPROTECT
60659 + help
60660 + If you say Y here, text relocations will be logged with the filename
60661 + of the offending library or binary. The purpose of the feature is
60662 + to help Linux distribution developers get rid of libraries and
60663 + binaries that need text relocations which hinder the future progress
60664 + of PaX. Only Linux distribution developers should say Y here, and
60665 + never on a production machine, as this option creates an information
60666 + leak that could aid an attacker in defeating the randomization of
60667 + a single memory region. If the sysctl option is enabled, a sysctl
60668 + option with name "audit_textrel" is created.
60669 +
60670 +endmenu
60671 +
60672 +menu "Executable Protections"
60673 +depends on GRKERNSEC
60674 +
60675 +config GRKERNSEC_EXECVE
60676 + bool "Enforce RLIMIT_NPROC on execs"
60677 + help
60678 + If you say Y here, users with a resource limit on processes will
60679 + have the value checked during execve() calls. The current system
60680 + only checks the system limit during fork() calls. If the sysctl option
60681 + is enabled, a sysctl option with name "execve_limiting" is created.
60682 +
60683 +config GRKERNSEC_DMESG
60684 + bool "Dmesg(8) restriction"
60685 + help
60686 + If you say Y here, non-root users will not be able to use dmesg(8)
60687 + to view up to the last 4kb of messages in the kernel's log buffer.
60688 + The kernel's log buffer often contains kernel addresses and other
60689 + identifying information useful to an attacker in fingerprinting a
60690 + system for a targeted exploit.
60691 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
60692 + created.
60693 +
60694 +config GRKERNSEC_HARDEN_PTRACE
60695 + bool "Deter ptrace-based process snooping"
60696 + help
60697 + If you say Y here, TTY sniffers and other malicious monitoring
60698 + programs implemented through ptrace will be defeated. If you
60699 + have been using the RBAC system, this option has already been
60700 + enabled for several years for all users, with the ability to make
60701 + fine-grained exceptions.
60702 +
60703 + This option only affects the ability of non-root users to ptrace
60704 + processes that are not a descendent of the ptracing process.
60705 + This means that strace ./binary and gdb ./binary will still work,
60706 + but attaching to arbitrary processes will not. If the sysctl
60707 + option is enabled, a sysctl option with name "harden_ptrace" is
60708 + created.
60709 +
60710 +config GRKERNSEC_TPE
60711 + bool "Trusted Path Execution (TPE)"
60712 + help
60713 + If you say Y here, you will be able to choose a gid to add to the
60714 + supplementary groups of users you want to mark as "untrusted."
60715 + These users will not be able to execute any files that are not in
60716 + root-owned directories writable only by root. If the sysctl option
60717 + is enabled, a sysctl option with name "tpe" is created.
60718 +
60719 +config GRKERNSEC_TPE_ALL
60720 + bool "Partially restrict all non-root users"
60721 + depends on GRKERNSEC_TPE
60722 + help
60723 + If you say Y here, all non-root users will be covered under
60724 + a weaker TPE restriction. This is separate from, and in addition to,
60725 + the main TPE options that you have selected elsewhere. Thus, if a
60726 + "trusted" GID is chosen, this restriction applies to even that GID.
60727 + Under this restriction, all non-root users will only be allowed to
60728 + execute files in directories they own that are not group or
60729 + world-writable, or in directories owned by root and writable only by
60730 + root. If the sysctl option is enabled, a sysctl option with name
60731 + "tpe_restrict_all" is created.
60732 +
60733 +config GRKERNSEC_TPE_INVERT
60734 + bool "Invert GID option"
60735 + depends on GRKERNSEC_TPE
60736 + help
60737 + If you say Y here, the group you specify in the TPE configuration will
60738 + decide what group TPE restrictions will be *disabled* for. This
60739 + option is useful if you want TPE restrictions to be applied to most
60740 + users on the system. If the sysctl option is enabled, a sysctl option
60741 + with name "tpe_invert" is created. Unlike other sysctl options, this
60742 + entry will default to on for backward-compatibility.
60743 +
60744 +config GRKERNSEC_TPE_GID
60745 + int "GID for untrusted users"
60746 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
60747 + default 1005
60748 + help
60749 + Setting this GID determines what group TPE restrictions will be
60750 + *enabled* for. If the sysctl option is enabled, a sysctl option
60751 + with name "tpe_gid" is created.
60752 +
60753 +config GRKERNSEC_TPE_GID
60754 + int "GID for trusted users"
60755 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
60756 + default 1005
60757 + help
60758 + Setting this GID determines what group TPE restrictions will be
60759 + *disabled* for. If the sysctl option is enabled, a sysctl option
60760 + with name "tpe_gid" is created.
60761 +
60762 +endmenu
60763 +menu "Network Protections"
60764 +depends on GRKERNSEC
60765 +
60766 +config GRKERNSEC_RANDNET
60767 + bool "Larger entropy pools"
60768 + help
60769 + If you say Y here, the entropy pools used for many features of Linux
60770 + and grsecurity will be doubled in size. Since several grsecurity
60771 + features use additional randomness, it is recommended that you say Y
60772 + here. Saying Y here has a similar effect as modifying
60773 + /proc/sys/kernel/random/poolsize.
60774 +
60775 +config GRKERNSEC_BLACKHOLE
60776 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
60777 + help
60778 + If you say Y here, neither TCP resets nor ICMP
60779 + destination-unreachable packets will be sent in response to packets
60780 + sent to ports for which no associated listening process exists.
60781 + This feature supports both IPV4 and IPV6 and exempts the
60782 + loopback interface from blackholing. Enabling this feature
60783 + makes a host more resilient to DoS attacks and reduces network
60784 + visibility against scanners.
60785 +
60786 + The blackhole feature as-implemented is equivalent to the FreeBSD
60787 + blackhole feature, as it prevents RST responses to all packets, not
60788 + just SYNs. Under most application behavior this causes no
60789 + problems, but applications (like haproxy) may not close certain
60790 + connections in a way that cleanly terminates them on the remote
60791 + end, leaving the remote host in LAST_ACK state. Because of this
60792 + side-effect and to prevent intentional LAST_ACK DoSes, this
60793 + feature also adds automatic mitigation against such attacks.
60794 + The mitigation drastically reduces the amount of time a socket
60795 + can spend in LAST_ACK state. If you're using haproxy and not
60796 + all servers it connects to have this option enabled, consider
60797 + disabling this feature on the haproxy host.
60798 +
60799 + If the sysctl option is enabled, two sysctl options with names
60800 + "ip_blackhole" and "lastack_retries" will be created.
60801 + While "ip_blackhole" takes the standard zero/non-zero on/off
60802 + toggle, "lastack_retries" uses the same kinds of values as
60803 + "tcp_retries1" and "tcp_retries2". The default value of 4
60804 + prevents a socket from lasting more than 45 seconds in LAST_ACK
60805 + state.
60806 +
60807 +config GRKERNSEC_SOCKET
60808 + bool "Socket restrictions"
60809 + help
60810 + If you say Y here, you will be able to choose from several options.
60811 + If you assign a GID on your system and add it to the supplementary
60812 + groups of users you want to restrict socket access to, this patch
60813 + will perform up to three things, based on the option(s) you choose.
60814 +
60815 +config GRKERNSEC_SOCKET_ALL
60816 + bool "Deny any sockets to group"
60817 + depends on GRKERNSEC_SOCKET
60818 + help
60819 + If you say Y here, you will be able to choose a GID of whose users will
60820 + be unable to connect to other hosts from your machine or run server
60821 + applications from your machine. If the sysctl option is enabled, a
60822 + sysctl option with name "socket_all" is created.
60823 +
60824 +config GRKERNSEC_SOCKET_ALL_GID
60825 + int "GID to deny all sockets for"
60826 + depends on GRKERNSEC_SOCKET_ALL
60827 + default 1004
60828 + help
60829 + Here you can choose the GID to disable socket access for. Remember to
60830 + add the users you want socket access disabled for to the GID
60831 + specified here. If the sysctl option is enabled, a sysctl option
60832 + with name "socket_all_gid" is created.
60833 +
60834 +config GRKERNSEC_SOCKET_CLIENT
60835 + bool "Deny client sockets to group"
60836 + depends on GRKERNSEC_SOCKET
60837 + help
60838 + If you say Y here, you will be able to choose a GID of whose users will
60839 + be unable to connect to other hosts from your machine, but will be
60840 + able to run servers. If this option is enabled, all users in the group
60841 + you specify will have to use passive mode when initiating ftp transfers
60842 + from the shell on your machine. If the sysctl option is enabled, a
60843 + sysctl option with name "socket_client" is created.
60844 +
60845 +config GRKERNSEC_SOCKET_CLIENT_GID
60846 + int "GID to deny client sockets for"
60847 + depends on GRKERNSEC_SOCKET_CLIENT
60848 + default 1003
60849 + help
60850 + Here you can choose the GID to disable client socket access for.
60851 + Remember to add the users you want client socket access disabled for to
60852 + the GID specified here. If the sysctl option is enabled, a sysctl
60853 + option with name "socket_client_gid" is created.
60854 +
60855 +config GRKERNSEC_SOCKET_SERVER
60856 + bool "Deny server sockets to group"
60857 + depends on GRKERNSEC_SOCKET
60858 + help
60859 + If you say Y here, you will be able to choose a GID of whose users will
60860 + be unable to run server applications from your machine. If the sysctl
60861 + option is enabled, a sysctl option with name "socket_server" is created.
60862 +
60863 +config GRKERNSEC_SOCKET_SERVER_GID
60864 + int "GID to deny server sockets for"
60865 + depends on GRKERNSEC_SOCKET_SERVER
60866 + default 1002
60867 + help
60868 + Here you can choose the GID to disable server socket access for.
60869 + Remember to add the users you want server socket access disabled for to
60870 + the GID specified here. If the sysctl option is enabled, a sysctl
60871 + option with name "socket_server_gid" is created.
60872 +
60873 +endmenu
60874 +menu "Sysctl support"
60875 +depends on GRKERNSEC && SYSCTL
60876 +
60877 +config GRKERNSEC_SYSCTL
60878 + bool "Sysctl support"
60879 + help
60880 + If you say Y here, you will be able to change the options that
60881 + grsecurity runs with at bootup, without having to recompile your
60882 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
60883 + to enable (1) or disable (0) various features. All the sysctl entries
60884 + are mutable until the "grsec_lock" entry is set to a non-zero value.
60885 + All features enabled in the kernel configuration are disabled at boot
60886 + if you do not say Y to the "Turn on features by default" option.
60887 + All options should be set at startup, and the grsec_lock entry should
60888 + be set to a non-zero value after all the options are set.
60889 + *THIS IS EXTREMELY IMPORTANT*
60890 +
60891 +config GRKERNSEC_SYSCTL_DISTRO
60892 + bool "Extra sysctl support for distro makers (READ HELP)"
60893 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
60894 + help
60895 + If you say Y here, additional sysctl options will be created
60896 + for features that affect processes running as root. Therefore,
60897 + it is critical when using this option that the grsec_lock entry be
60898 + enabled after boot. Only distros with prebuilt kernel packages
60899 + with this option enabled that can ensure grsec_lock is enabled
60900 + after boot should use this option.
60901 + *Failure to set grsec_lock after boot makes all grsec features
60902 + this option covers useless*
60903 +
60904 + Currently this option creates the following sysctl entries:
60905 + "Disable Privileged I/O": "disable_priv_io"
60906 +
60907 +config GRKERNSEC_SYSCTL_ON
60908 + bool "Turn on features by default"
60909 + depends on GRKERNSEC_SYSCTL
60910 + help
60911 + If you say Y here, instead of having all features enabled in the
60912 + kernel configuration disabled at boot time, the features will be
60913 + enabled at boot time. It is recommended you say Y here unless
60914 + there is some reason you would want all sysctl-tunable features to
60915 + be disabled by default. As mentioned elsewhere, it is important
60916 + to enable the grsec_lock entry once you have finished modifying
60917 + the sysctl entries.
60918 +
60919 +endmenu
60920 +menu "Logging Options"
60921 +depends on GRKERNSEC
60922 +
60923 +config GRKERNSEC_FLOODTIME
60924 + int "Seconds in between log messages (minimum)"
60925 + default 10
60926 + help
60927 + This option allows you to enforce the number of seconds between
60928 + grsecurity log messages. The default should be suitable for most
60929 + people, however, if you choose to change it, choose a value small enough
60930 + to allow informative logs to be produced, but large enough to
60931 + prevent flooding.
60932 +
60933 +config GRKERNSEC_FLOODBURST
60934 + int "Number of messages in a burst (maximum)"
60935 + default 4
60936 + help
60937 + This option allows you to choose the maximum number of messages allowed
60938 + within the flood time interval you chose in a separate option. The
60939 + default should be suitable for most people, however if you find that
60940 + many of your logs are being interpreted as flooding, you may want to
60941 + raise this value.
60942 +
60943 +endmenu
60944 +
60945 +endmenu
60946 diff -urNp linux-2.6.39.1/grsecurity/Makefile linux-2.6.39.1/grsecurity/Makefile
60947 --- linux-2.6.39.1/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
60948 +++ linux-2.6.39.1/grsecurity/Makefile 2011-05-24 20:26:54.000000000 -0400
60949 @@ -0,0 +1,33 @@
60950 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
60951 +# during 2001-2009 it has been completely redesigned by Brad Spengler
60952 +# into an RBAC system
60953 +#
60954 +# All code in this directory and various hooks inserted throughout the kernel
60955 +# are copyright Brad Spengler - Open Source Security, Inc., and released
60956 +# under the GPL v2 or higher
60957 +
60958 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
60959 + grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
60960 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
60961 +
60962 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
60963 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
60964 + gracl_learn.o grsec_log.o
60965 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
60966 +
60967 +ifdef CONFIG_NET
60968 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
60969 +endif
60970 +
60971 +ifndef CONFIG_GRKERNSEC
60972 +obj-y += grsec_disabled.o
60973 +endif
60974 +
60975 +ifdef CONFIG_GRKERNSEC_HIDESYM
60976 +extra-y := grsec_hidesym.o
60977 +$(obj)/grsec_hidesym.o:
60978 + @-chmod -f 500 /boot
60979 + @-chmod -f 500 /lib/modules
60980 + @-chmod -f 700 .
60981 + @echo ' grsec: protected kernel image paths'
60982 +endif
60983 diff -urNp linux-2.6.39.1/include/acpi/acpi_drivers.h linux-2.6.39.1/include/acpi/acpi_drivers.h
60984 --- linux-2.6.39.1/include/acpi/acpi_drivers.h 2011-05-19 00:06:34.000000000 -0400
60985 +++ linux-2.6.39.1/include/acpi/acpi_drivers.h 2011-05-22 19:36:32.000000000 -0400
60986 @@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
60987 Dock Station
60988 -------------------------------------------------------------------------- */
60989 struct acpi_dock_ops {
60990 - acpi_notify_handler handler;
60991 - acpi_notify_handler uevent;
60992 + const acpi_notify_handler handler;
60993 + const acpi_notify_handler uevent;
60994 };
60995
60996 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
60997 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
60998 extern int register_dock_notifier(struct notifier_block *nb);
60999 extern void unregister_dock_notifier(struct notifier_block *nb);
61000 extern int register_hotplug_dock_device(acpi_handle handle,
61001 - struct acpi_dock_ops *ops,
61002 + const struct acpi_dock_ops *ops,
61003 void *context);
61004 extern void unregister_hotplug_dock_device(acpi_handle handle);
61005 #else
61006 @@ -144,7 +144,7 @@ static inline void unregister_dock_notif
61007 {
61008 }
61009 static inline int register_hotplug_dock_device(acpi_handle handle,
61010 - struct acpi_dock_ops *ops,
61011 + const struct acpi_dock_ops *ops,
61012 void *context)
61013 {
61014 return -ENODEV;
61015 diff -urNp linux-2.6.39.1/include/acpi/processor.h linux-2.6.39.1/include/acpi/processor.h
61016 --- linux-2.6.39.1/include/acpi/processor.h 2011-05-19 00:06:34.000000000 -0400
61017 +++ linux-2.6.39.1/include/acpi/processor.h 2011-05-22 19:36:32.000000000 -0400
61018 @@ -344,7 +344,7 @@ extern struct cpuidle_driver acpi_idle_d
61019
61020 /* in processor_thermal.c */
61021 int acpi_processor_get_limit_info(struct acpi_processor *pr);
61022 -extern struct thermal_cooling_device_ops processor_cooling_ops;
61023 +extern const struct thermal_cooling_device_ops processor_cooling_ops;
61024 #ifdef CONFIG_CPU_FREQ
61025 void acpi_thermal_cpufreq_init(void);
61026 void acpi_thermal_cpufreq_exit(void);
61027 diff -urNp linux-2.6.39.1/include/asm-generic/atomic-long.h linux-2.6.39.1/include/asm-generic/atomic-long.h
61028 --- linux-2.6.39.1/include/asm-generic/atomic-long.h 2011-05-19 00:06:34.000000000 -0400
61029 +++ linux-2.6.39.1/include/asm-generic/atomic-long.h 2011-05-22 19:36:32.000000000 -0400
61030 @@ -22,6 +22,12 @@
61031
61032 typedef atomic64_t atomic_long_t;
61033
61034 +#ifdef CONFIG_PAX_REFCOUNT
61035 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
61036 +#else
61037 +typedef atomic64_t atomic_long_unchecked_t;
61038 +#endif
61039 +
61040 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61041
61042 static inline long atomic_long_read(atomic_long_t *l)
61043 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
61044 return (long)atomic64_read(v);
61045 }
61046
61047 +#ifdef CONFIG_PAX_REFCOUNT
61048 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61049 +{
61050 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61051 +
61052 + return (long)atomic64_read_unchecked(v);
61053 +}
61054 +#endif
61055 +
61056 static inline void atomic_long_set(atomic_long_t *l, long i)
61057 {
61058 atomic64_t *v = (atomic64_t *)l;
61059 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
61060 atomic64_set(v, i);
61061 }
61062
61063 +#ifdef CONFIG_PAX_REFCOUNT
61064 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61065 +{
61066 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61067 +
61068 + atomic64_set_unchecked(v, i);
61069 +}
61070 +#endif
61071 +
61072 static inline void atomic_long_inc(atomic_long_t *l)
61073 {
61074 atomic64_t *v = (atomic64_t *)l;
61075 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
61076 atomic64_inc(v);
61077 }
61078
61079 +#ifdef CONFIG_PAX_REFCOUNT
61080 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61081 +{
61082 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61083 +
61084 + atomic64_inc_unchecked(v);
61085 +}
61086 +#endif
61087 +
61088 static inline void atomic_long_dec(atomic_long_t *l)
61089 {
61090 atomic64_t *v = (atomic64_t *)l;
61091 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
61092 atomic64_dec(v);
61093 }
61094
61095 +#ifdef CONFIG_PAX_REFCOUNT
61096 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61097 +{
61098 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61099 +
61100 + atomic64_dec_unchecked(v);
61101 +}
61102 +#endif
61103 +
61104 static inline void atomic_long_add(long i, atomic_long_t *l)
61105 {
61106 atomic64_t *v = (atomic64_t *)l;
61107 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long
61108 atomic64_add(i, v);
61109 }
61110
61111 +#ifdef CONFIG_PAX_REFCOUNT
61112 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61113 +{
61114 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61115 +
61116 + atomic64_add_unchecked(i, v);
61117 +}
61118 +#endif
61119 +
61120 static inline void atomic_long_sub(long i, atomic_long_t *l)
61121 {
61122 atomic64_t *v = (atomic64_t *)l;
61123 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
61124 atomic64_sub(i, v);
61125 }
61126
61127 +#ifdef CONFIG_PAX_REFCOUNT
61128 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61129 +{
61130 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61131 +
61132 + atomic64_sub_unchecked(i, v);
61133 +}
61134 +#endif
61135 +
61136 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61137 {
61138 atomic64_t *v = (atomic64_t *)l;
61139 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
61140 return (long)atomic64_inc_return(v);
61141 }
61142
61143 +#ifdef CONFIG_PAX_REFCOUNT
61144 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61145 +{
61146 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61147 +
61148 + return (long)atomic64_inc_return_unchecked(v);
61149 +}
61150 +#endif
61151 +
61152 static inline long atomic_long_dec_return(atomic_long_t *l)
61153 {
61154 atomic64_t *v = (atomic64_t *)l;
61155 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
61156
61157 typedef atomic_t atomic_long_t;
61158
61159 +#ifdef CONFIG_PAX_REFCOUNT
61160 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61161 +#else
61162 +typedef atomic_t atomic_long_unchecked_t;
61163 +#endif
61164 +
61165 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61166 static inline long atomic_long_read(atomic_long_t *l)
61167 {
61168 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
61169 return (long)atomic_read(v);
61170 }
61171
61172 +#ifdef CONFIG_PAX_REFCOUNT
61173 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61174 +{
61175 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61176 +
61177 + return (long)atomic_read_unchecked(v);
61178 +}
61179 +#endif
61180 +
61181 static inline void atomic_long_set(atomic_long_t *l, long i)
61182 {
61183 atomic_t *v = (atomic_t *)l;
61184 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
61185 atomic_set(v, i);
61186 }
61187
61188 +#ifdef CONFIG_PAX_REFCOUNT
61189 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61190 +{
61191 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61192 +
61193 + atomic_set_unchecked(v, i);
61194 +}
61195 +#endif
61196 +
61197 static inline void atomic_long_inc(atomic_long_t *l)
61198 {
61199 atomic_t *v = (atomic_t *)l;
61200 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
61201 atomic_inc(v);
61202 }
61203
61204 +#ifdef CONFIG_PAX_REFCOUNT
61205 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61206 +{
61207 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61208 +
61209 + atomic_inc_unchecked(v);
61210 +}
61211 +#endif
61212 +
61213 static inline void atomic_long_dec(atomic_long_t *l)
61214 {
61215 atomic_t *v = (atomic_t *)l;
61216 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
61217 atomic_dec(v);
61218 }
61219
61220 +#ifdef CONFIG_PAX_REFCOUNT
61221 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61222 +{
61223 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61224 +
61225 + atomic_dec_unchecked(v);
61226 +}
61227 +#endif
61228 +
61229 static inline void atomic_long_add(long i, atomic_long_t *l)
61230 {
61231 atomic_t *v = (atomic_t *)l;
61232 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long
61233 atomic_add(i, v);
61234 }
61235
61236 +#ifdef CONFIG_PAX_REFCOUNT
61237 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61238 +{
61239 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61240 +
61241 + atomic_add_unchecked(i, v);
61242 +}
61243 +#endif
61244 +
61245 static inline void atomic_long_sub(long i, atomic_long_t *l)
61246 {
61247 atomic_t *v = (atomic_t *)l;
61248 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
61249 atomic_sub(i, v);
61250 }
61251
61252 +#ifdef CONFIG_PAX_REFCOUNT
61253 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61254 +{
61255 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61256 +
61257 + atomic_sub_unchecked(i, v);
61258 +}
61259 +#endif
61260 +
61261 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61262 {
61263 atomic_t *v = (atomic_t *)l;
61264 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
61265 return (long)atomic_inc_return(v);
61266 }
61267
61268 +#ifdef CONFIG_PAX_REFCOUNT
61269 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61270 +{
61271 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61272 +
61273 + return (long)atomic_inc_return_unchecked(v);
61274 +}
61275 +#endif
61276 +
61277 static inline long atomic_long_dec_return(atomic_long_t *l)
61278 {
61279 atomic_t *v = (atomic_t *)l;
61280 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
61281
61282 #endif /* BITS_PER_LONG == 64 */
61283
61284 +#ifdef CONFIG_PAX_REFCOUNT
61285 +static inline void pax_refcount_needs_these_functions(void)
61286 +{
61287 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
61288 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61289 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61290 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61291 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61292 + atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61293 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61294 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61295 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61296 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61297 + atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61298 +
61299 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61300 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61301 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61302 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61303 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61304 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61305 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61306 +}
61307 +#else
61308 +#define atomic_read_unchecked(v) atomic_read(v)
61309 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61310 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61311 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61312 +#define atomic_inc_unchecked(v) atomic_inc(v)
61313 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61314 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61315 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61316 +#define atomic_dec_unchecked(v) atomic_dec(v)
61317 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61318 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61319 +
61320 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61321 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61322 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61323 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61324 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61325 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61326 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61327 +#endif
61328 +
61329 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61330 diff -urNp linux-2.6.39.1/include/asm-generic/cache.h linux-2.6.39.1/include/asm-generic/cache.h
61331 --- linux-2.6.39.1/include/asm-generic/cache.h 2011-05-19 00:06:34.000000000 -0400
61332 +++ linux-2.6.39.1/include/asm-generic/cache.h 2011-05-22 19:36:32.000000000 -0400
61333 @@ -6,7 +6,7 @@
61334 * cache lines need to provide their own cache.h.
61335 */
61336
61337 -#define L1_CACHE_SHIFT 5
61338 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61339 +#define L1_CACHE_SHIFT 5U
61340 +#define L1_CACHE_BYTES (1U << L1_CACHE_SHIFT)
61341
61342 #endif /* __ASM_GENERIC_CACHE_H */
61343 diff -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
61344 --- linux-2.6.39.1/include/asm-generic/dma-mapping-common.h 2011-05-19 00:06:34.000000000 -0400
61345 +++ linux-2.6.39.1/include/asm-generic/dma-mapping-common.h 2011-05-22 19:36:32.000000000 -0400
61346 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
61347 enum dma_data_direction dir,
61348 struct dma_attrs *attrs)
61349 {
61350 - struct dma_map_ops *ops = get_dma_ops(dev);
61351 + const struct dma_map_ops *ops = get_dma_ops(dev);
61352 dma_addr_t addr;
61353
61354 kmemcheck_mark_initialized(ptr, size);
61355 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
61356 enum dma_data_direction dir,
61357 struct dma_attrs *attrs)
61358 {
61359 - struct dma_map_ops *ops = get_dma_ops(dev);
61360 + const struct dma_map_ops *ops = get_dma_ops(dev);
61361
61362 BUG_ON(!valid_dma_direction(dir));
61363 if (ops->unmap_page)
61364 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
61365 int nents, enum dma_data_direction dir,
61366 struct dma_attrs *attrs)
61367 {
61368 - struct dma_map_ops *ops = get_dma_ops(dev);
61369 + const struct dma_map_ops *ops = get_dma_ops(dev);
61370 int i, ents;
61371 struct scatterlist *s;
61372
61373 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
61374 int nents, enum dma_data_direction dir,
61375 struct dma_attrs *attrs)
61376 {
61377 - struct dma_map_ops *ops = get_dma_ops(dev);
61378 + const struct dma_map_ops *ops = get_dma_ops(dev);
61379
61380 BUG_ON(!valid_dma_direction(dir));
61381 debug_dma_unmap_sg(dev, sg, nents, dir);
61382 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
61383 size_t offset, size_t size,
61384 enum dma_data_direction dir)
61385 {
61386 - struct dma_map_ops *ops = get_dma_ops(dev);
61387 + const struct dma_map_ops *ops = get_dma_ops(dev);
61388 dma_addr_t addr;
61389
61390 kmemcheck_mark_initialized(page_address(page) + offset, size);
61391 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
61392 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
61393 size_t size, enum dma_data_direction dir)
61394 {
61395 - struct dma_map_ops *ops = get_dma_ops(dev);
61396 + const struct dma_map_ops *ops = get_dma_ops(dev);
61397
61398 BUG_ON(!valid_dma_direction(dir));
61399 if (ops->unmap_page)
61400 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
61401 size_t size,
61402 enum dma_data_direction dir)
61403 {
61404 - struct dma_map_ops *ops = get_dma_ops(dev);
61405 + const struct dma_map_ops *ops = get_dma_ops(dev);
61406
61407 BUG_ON(!valid_dma_direction(dir));
61408 if (ops->sync_single_for_cpu)
61409 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
61410 dma_addr_t addr, size_t size,
61411 enum dma_data_direction dir)
61412 {
61413 - struct dma_map_ops *ops = get_dma_ops(dev);
61414 + const struct dma_map_ops *ops = get_dma_ops(dev);
61415
61416 BUG_ON(!valid_dma_direction(dir));
61417 if (ops->sync_single_for_device)
61418 @@ -139,7 +139,7 @@ static inline void
61419 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
61420 int nelems, enum dma_data_direction dir)
61421 {
61422 - struct dma_map_ops *ops = get_dma_ops(dev);
61423 + const struct dma_map_ops *ops = get_dma_ops(dev);
61424
61425 BUG_ON(!valid_dma_direction(dir));
61426 if (ops->sync_sg_for_cpu)
61427 @@ -151,7 +151,7 @@ static inline void
61428 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
61429 int nelems, enum dma_data_direction dir)
61430 {
61431 - struct dma_map_ops *ops = get_dma_ops(dev);
61432 + const struct dma_map_ops *ops = get_dma_ops(dev);
61433
61434 BUG_ON(!valid_dma_direction(dir));
61435 if (ops->sync_sg_for_device)
61436 diff -urNp linux-2.6.39.1/include/asm-generic/int-l64.h linux-2.6.39.1/include/asm-generic/int-l64.h
61437 --- linux-2.6.39.1/include/asm-generic/int-l64.h 2011-05-19 00:06:34.000000000 -0400
61438 +++ linux-2.6.39.1/include/asm-generic/int-l64.h 2011-05-22 19:36:32.000000000 -0400
61439 @@ -46,6 +46,8 @@ typedef unsigned int u32;
61440 typedef signed long s64;
61441 typedef unsigned long u64;
61442
61443 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
61444 +
61445 #define S8_C(x) x
61446 #define U8_C(x) x ## U
61447 #define S16_C(x) x
61448 diff -urNp linux-2.6.39.1/include/asm-generic/int-ll64.h linux-2.6.39.1/include/asm-generic/int-ll64.h
61449 --- linux-2.6.39.1/include/asm-generic/int-ll64.h 2011-05-19 00:06:34.000000000 -0400
61450 +++ linux-2.6.39.1/include/asm-generic/int-ll64.h 2011-05-22 19:36:32.000000000 -0400
61451 @@ -51,6 +51,8 @@ typedef unsigned int u32;
61452 typedef signed long long s64;
61453 typedef unsigned long long u64;
61454
61455 +typedef unsigned long long intoverflow_t;
61456 +
61457 #define S8_C(x) x
61458 #define U8_C(x) x ## U
61459 #define S16_C(x) x
61460 diff -urNp linux-2.6.39.1/include/asm-generic/kmap_types.h linux-2.6.39.1/include/asm-generic/kmap_types.h
61461 --- linux-2.6.39.1/include/asm-generic/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
61462 +++ linux-2.6.39.1/include/asm-generic/kmap_types.h 2011-05-22 19:36:32.000000000 -0400
61463 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
61464 KMAP_D(17) KM_NMI,
61465 KMAP_D(18) KM_NMI_PTE,
61466 KMAP_D(19) KM_KDB,
61467 +KMAP_D(20) KM_CLEARPAGE,
61468 /*
61469 * Remember to update debug_kmap_atomic() when adding new kmap types!
61470 */
61471 -KMAP_D(20) KM_TYPE_NR
61472 +KMAP_D(21) KM_TYPE_NR
61473 };
61474
61475 #undef KMAP_D
61476 diff -urNp linux-2.6.39.1/include/asm-generic/pgtable.h linux-2.6.39.1/include/asm-generic/pgtable.h
61477 --- linux-2.6.39.1/include/asm-generic/pgtable.h 2011-05-19 00:06:34.000000000 -0400
61478 +++ linux-2.6.39.1/include/asm-generic/pgtable.h 2011-05-22 19:36:32.000000000 -0400
61479 @@ -447,6 +447,14 @@ static inline int pmd_write(pmd_t pmd)
61480 #endif /* __HAVE_ARCH_PMD_WRITE */
61481 #endif
61482
61483 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61484 +static inline unsigned long pax_open_kernel(void) { return 0; }
61485 +#endif
61486 +
61487 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61488 +static inline unsigned long pax_close_kernel(void) { return 0; }
61489 +#endif
61490 +
61491 #endif /* !__ASSEMBLY__ */
61492
61493 #endif /* _ASM_GENERIC_PGTABLE_H */
61494 diff -urNp linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h
61495 --- linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h 2011-05-19 00:06:34.000000000 -0400
61496 +++ linux-2.6.39.1/include/asm-generic/pgtable-nopmd.h 2011-05-22 19:36:32.000000000 -0400
61497 @@ -1,14 +1,19 @@
61498 #ifndef _PGTABLE_NOPMD_H
61499 #define _PGTABLE_NOPMD_H
61500
61501 -#ifndef __ASSEMBLY__
61502 -
61503 #include <asm-generic/pgtable-nopud.h>
61504
61505 -struct mm_struct;
61506 -
61507 #define __PAGETABLE_PMD_FOLDED
61508
61509 +#define PMD_SHIFT PUD_SHIFT
61510 +#define PTRS_PER_PMD 1
61511 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61512 +#define PMD_MASK (~(PMD_SIZE-1))
61513 +
61514 +#ifndef __ASSEMBLY__
61515 +
61516 +struct mm_struct;
61517 +
61518 /*
61519 * Having the pmd type consist of a pud gets the size right, and allows
61520 * us to conceptually access the pud entry that this pmd is folded into
61521 @@ -16,11 +21,6 @@ struct mm_struct;
61522 */
61523 typedef struct { pud_t pud; } pmd_t;
61524
61525 -#define PMD_SHIFT PUD_SHIFT
61526 -#define PTRS_PER_PMD 1
61527 -#define PMD_SIZE (1UL << PMD_SHIFT)
61528 -#define PMD_MASK (~(PMD_SIZE-1))
61529 -
61530 /*
61531 * The "pud_xxx()" functions here are trivial for a folded two-level
61532 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61533 diff -urNp linux-2.6.39.1/include/asm-generic/pgtable-nopud.h linux-2.6.39.1/include/asm-generic/pgtable-nopud.h
61534 --- linux-2.6.39.1/include/asm-generic/pgtable-nopud.h 2011-05-19 00:06:34.000000000 -0400
61535 +++ linux-2.6.39.1/include/asm-generic/pgtable-nopud.h 2011-05-22 19:36:32.000000000 -0400
61536 @@ -1,10 +1,15 @@
61537 #ifndef _PGTABLE_NOPUD_H
61538 #define _PGTABLE_NOPUD_H
61539
61540 -#ifndef __ASSEMBLY__
61541 -
61542 #define __PAGETABLE_PUD_FOLDED
61543
61544 +#define PUD_SHIFT PGDIR_SHIFT
61545 +#define PTRS_PER_PUD 1
61546 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61547 +#define PUD_MASK (~(PUD_SIZE-1))
61548 +
61549 +#ifndef __ASSEMBLY__
61550 +
61551 /*
61552 * Having the pud type consist of a pgd gets the size right, and allows
61553 * us to conceptually access the pgd entry that this pud is folded into
61554 @@ -12,11 +17,6 @@
61555 */
61556 typedef struct { pgd_t pgd; } pud_t;
61557
61558 -#define PUD_SHIFT PGDIR_SHIFT
61559 -#define PTRS_PER_PUD 1
61560 -#define PUD_SIZE (1UL << PUD_SHIFT)
61561 -#define PUD_MASK (~(PUD_SIZE-1))
61562 -
61563 /*
61564 * The "pgd_xxx()" functions here are trivial for a folded two-level
61565 * setup: the pud is never bad, and a pud always exists (as it's folded
61566 diff -urNp linux-2.6.39.1/include/asm-generic/vmlinux.lds.h linux-2.6.39.1/include/asm-generic/vmlinux.lds.h
61567 --- linux-2.6.39.1/include/asm-generic/vmlinux.lds.h 2011-05-19 00:06:34.000000000 -0400
61568 +++ linux-2.6.39.1/include/asm-generic/vmlinux.lds.h 2011-05-22 19:36:32.000000000 -0400
61569 @@ -213,6 +213,7 @@
61570 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61571 VMLINUX_SYMBOL(__start_rodata) = .; \
61572 *(.rodata) *(.rodata.*) \
61573 + *(.data..read_only) \
61574 *(__vermagic) /* Kernel version magic */ \
61575 . = ALIGN(8); \
61576 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61577 @@ -707,14 +708,15 @@
61578 * section in the linker script will go there too. @phdr should have
61579 * a leading colon.
61580 *
61581 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61582 + * Note that this macros defines per_cpu_load as an absolute symbol.
61583 * If there is no need to put the percpu section at a predetermined
61584 * address, use PERCPU().
61585 */
61586 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61587 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61588 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61589 + per_cpu_load = .; \
61590 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61591 - LOAD_OFFSET) { \
61592 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61593 VMLINUX_SYMBOL(__per_cpu_start) = .; \
61594 *(.data..percpu..first) \
61595 . = ALIGN(PAGE_SIZE); \
61596 @@ -726,7 +728,7 @@
61597 *(.data..percpu..shared_aligned) \
61598 VMLINUX_SYMBOL(__per_cpu_end) = .; \
61599 } phdr \
61600 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61601 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61602
61603 /**
61604 * PERCPU - define output section for percpu area, simple version
61605 diff -urNp linux-2.6.39.1/include/drm/drmP.h linux-2.6.39.1/include/drm/drmP.h
61606 --- linux-2.6.39.1/include/drm/drmP.h 2011-05-19 00:06:34.000000000 -0400
61607 +++ linux-2.6.39.1/include/drm/drmP.h 2011-05-22 19:41:42.000000000 -0400
61608 @@ -73,6 +73,7 @@
61609 #include <linux/workqueue.h>
61610 #include <linux/poll.h>
61611 #include <asm/pgalloc.h>
61612 +#include <asm/local.h>
61613 #include "drm.h"
61614
61615 #include <linux/idr.h>
61616 @@ -908,7 +909,7 @@ struct drm_driver {
61617 uint32_t handle);
61618
61619 /* Driver private ops for this object */
61620 - struct vm_operations_struct *gem_vm_ops;
61621 + const struct vm_operations_struct *gem_vm_ops;
61622
61623 int major;
61624 int minor;
61625 @@ -1023,7 +1024,7 @@ struct drm_device {
61626
61627 /** \name Usage Counters */
61628 /*@{ */
61629 - int open_count; /**< Outstanding files open */
61630 + local_t open_count; /**< Outstanding files open */
61631 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61632 atomic_t vma_count; /**< Outstanding vma areas open */
61633 int buf_use; /**< Buffers in use -- cannot alloc */
61634 @@ -1034,7 +1035,7 @@ struct drm_device {
61635 /*@{ */
61636 unsigned long counters;
61637 enum drm_stat_type types[15];
61638 - atomic_t counts[15];
61639 + atomic_unchecked_t counts[15];
61640 /*@} */
61641
61642 struct list_head filelist;
61643 diff -urNp linux-2.6.39.1/include/linux/a.out.h linux-2.6.39.1/include/linux/a.out.h
61644 --- linux-2.6.39.1/include/linux/a.out.h 2011-05-19 00:06:34.000000000 -0400
61645 +++ linux-2.6.39.1/include/linux/a.out.h 2011-05-22 19:36:32.000000000 -0400
61646 @@ -39,6 +39,14 @@ enum machine_type {
61647 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61648 };
61649
61650 +/* Constants for the N_FLAGS field */
61651 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61652 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61653 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61654 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61655 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61656 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61657 +
61658 #if !defined (N_MAGIC)
61659 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61660 #endif
61661 diff -urNp linux-2.6.39.1/include/linux/atmdev.h linux-2.6.39.1/include/linux/atmdev.h
61662 --- linux-2.6.39.1/include/linux/atmdev.h 2011-05-19 00:06:34.000000000 -0400
61663 +++ linux-2.6.39.1/include/linux/atmdev.h 2011-05-22 19:36:32.000000000 -0400
61664 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61665 #endif
61666
61667 struct k_atm_aal_stats {
61668 -#define __HANDLE_ITEM(i) atomic_t i
61669 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61670 __AAL_STAT_ITEMS
61671 #undef __HANDLE_ITEM
61672 };
61673 diff -urNp linux-2.6.39.1/include/linux/binfmts.h linux-2.6.39.1/include/linux/binfmts.h
61674 --- linux-2.6.39.1/include/linux/binfmts.h 2011-05-19 00:06:34.000000000 -0400
61675 +++ linux-2.6.39.1/include/linux/binfmts.h 2011-05-22 19:36:32.000000000 -0400
61676 @@ -92,6 +92,7 @@ struct linux_binfmt {
61677 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61678 int (*load_shlib)(struct file *);
61679 int (*core_dump)(struct coredump_params *cprm);
61680 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61681 unsigned long min_coredump; /* minimal dump size */
61682 };
61683
61684 diff -urNp linux-2.6.39.1/include/linux/blkdev.h linux-2.6.39.1/include/linux/blkdev.h
61685 --- linux-2.6.39.1/include/linux/blkdev.h 2011-06-03 00:04:14.000000000 -0400
61686 +++ linux-2.6.39.1/include/linux/blkdev.h 2011-06-03 00:32:08.000000000 -0400
61687 @@ -1292,22 +1292,22 @@ queue_max_integrity_segments(struct requ
61688 #endif /* CONFIG_BLK_DEV_INTEGRITY */
61689
61690 struct block_device_operations {
61691 - int (*open) (struct block_device *, fmode_t);
61692 - int (*release) (struct gendisk *, fmode_t);
61693 - int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61694 - int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61695 - int (*direct_access) (struct block_device *, sector_t,
61696 + int (* const open) (struct block_device *, fmode_t);
61697 + int (* const release) (struct gendisk *, fmode_t);
61698 + int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61699 + int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61700 + int (* const direct_access) (struct block_device *, sector_t,
61701 void **, unsigned long *);
61702 - unsigned int (*check_events) (struct gendisk *disk,
61703 + unsigned int (* const check_events) (struct gendisk *disk,
61704 unsigned int clearing);
61705 /* ->media_changed() is DEPRECATED, use ->check_events() instead */
61706 - int (*media_changed) (struct gendisk *);
61707 - void (*unlock_native_capacity) (struct gendisk *);
61708 - int (*revalidate_disk) (struct gendisk *);
61709 - int (*getgeo)(struct block_device *, struct hd_geometry *);
61710 + int (* const media_changed) (struct gendisk *);
61711 + void (* const unlock_native_capacity) (struct gendisk *);
61712 + int (* const revalidate_disk) (struct gendisk *);
61713 + int (* const getgeo)(struct block_device *, struct hd_geometry *);
61714 /* this callback is with swap_lock and sometimes page table lock held */
61715 - void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61716 - struct module *owner;
61717 + void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
61718 + struct module * const owner;
61719 };
61720
61721 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61722 diff -urNp linux-2.6.39.1/include/linux/blktrace_api.h linux-2.6.39.1/include/linux/blktrace_api.h
61723 --- linux-2.6.39.1/include/linux/blktrace_api.h 2011-05-19 00:06:34.000000000 -0400
61724 +++ linux-2.6.39.1/include/linux/blktrace_api.h 2011-05-22 19:36:32.000000000 -0400
61725 @@ -161,7 +161,7 @@ struct blk_trace {
61726 struct dentry *dir;
61727 struct dentry *dropped_file;
61728 struct dentry *msg_file;
61729 - atomic_t dropped;
61730 + atomic_unchecked_t dropped;
61731 };
61732
61733 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61734 diff -urNp linux-2.6.39.1/include/linux/byteorder/little_endian.h linux-2.6.39.1/include/linux/byteorder/little_endian.h
61735 --- linux-2.6.39.1/include/linux/byteorder/little_endian.h 2011-05-19 00:06:34.000000000 -0400
61736 +++ linux-2.6.39.1/include/linux/byteorder/little_endian.h 2011-05-22 19:36:32.000000000 -0400
61737 @@ -42,51 +42,51 @@
61738
61739 static inline __le64 __cpu_to_le64p(const __u64 *p)
61740 {
61741 - return (__force __le64)*p;
61742 + return (__force const __le64)*p;
61743 }
61744 static inline __u64 __le64_to_cpup(const __le64 *p)
61745 {
61746 - return (__force __u64)*p;
61747 + return (__force const __u64)*p;
61748 }
61749 static inline __le32 __cpu_to_le32p(const __u32 *p)
61750 {
61751 - return (__force __le32)*p;
61752 + return (__force const __le32)*p;
61753 }
61754 static inline __u32 __le32_to_cpup(const __le32 *p)
61755 {
61756 - return (__force __u32)*p;
61757 + return (__force const __u32)*p;
61758 }
61759 static inline __le16 __cpu_to_le16p(const __u16 *p)
61760 {
61761 - return (__force __le16)*p;
61762 + return (__force const __le16)*p;
61763 }
61764 static inline __u16 __le16_to_cpup(const __le16 *p)
61765 {
61766 - return (__force __u16)*p;
61767 + return (__force const __u16)*p;
61768 }
61769 static inline __be64 __cpu_to_be64p(const __u64 *p)
61770 {
61771 - return (__force __be64)__swab64p(p);
61772 + return (__force const __be64)__swab64p(p);
61773 }
61774 static inline __u64 __be64_to_cpup(const __be64 *p)
61775 {
61776 - return __swab64p((__u64 *)p);
61777 + return __swab64p((const __u64 *)p);
61778 }
61779 static inline __be32 __cpu_to_be32p(const __u32 *p)
61780 {
61781 - return (__force __be32)__swab32p(p);
61782 + return (__force const __be32)__swab32p(p);
61783 }
61784 static inline __u32 __be32_to_cpup(const __be32 *p)
61785 {
61786 - return __swab32p((__u32 *)p);
61787 + return __swab32p((const __u32 *)p);
61788 }
61789 static inline __be16 __cpu_to_be16p(const __u16 *p)
61790 {
61791 - return (__force __be16)__swab16p(p);
61792 + return (__force const __be16)__swab16p(p);
61793 }
61794 static inline __u16 __be16_to_cpup(const __be16 *p)
61795 {
61796 - return __swab16p((__u16 *)p);
61797 + return __swab16p((const __u16 *)p);
61798 }
61799 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61800 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61801 diff -urNp linux-2.6.39.1/include/linux/cache.h linux-2.6.39.1/include/linux/cache.h
61802 --- linux-2.6.39.1/include/linux/cache.h 2011-05-19 00:06:34.000000000 -0400
61803 +++ linux-2.6.39.1/include/linux/cache.h 2011-05-22 19:36:32.000000000 -0400
61804 @@ -16,6 +16,10 @@
61805 #define __read_mostly
61806 #endif
61807
61808 +#ifndef __read_only
61809 +#define __read_only __read_mostly
61810 +#endif
61811 +
61812 #ifndef ____cacheline_aligned
61813 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61814 #endif
61815 diff -urNp linux-2.6.39.1/include/linux/capability.h linux-2.6.39.1/include/linux/capability.h
61816 --- linux-2.6.39.1/include/linux/capability.h 2011-05-19 00:06:34.000000000 -0400
61817 +++ linux-2.6.39.1/include/linux/capability.h 2011-05-22 21:02:47.000000000 -0400
61818 @@ -547,6 +547,9 @@ extern bool capable(int cap);
61819 extern bool ns_capable(struct user_namespace *ns, int cap);
61820 extern bool task_ns_capable(struct task_struct *t, int cap);
61821 extern bool nsown_capable(int cap);
61822 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
61823 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61824 +extern bool capable_nolog(int cap);
61825
61826 /* audit system wants to get cap info from files as well */
61827 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61828 diff -urNp linux-2.6.39.1/include/linux/compiler-gcc4.h linux-2.6.39.1/include/linux/compiler-gcc4.h
61829 --- linux-2.6.39.1/include/linux/compiler-gcc4.h 2011-05-19 00:06:34.000000000 -0400
61830 +++ linux-2.6.39.1/include/linux/compiler-gcc4.h 2011-05-22 19:36:32.000000000 -0400
61831 @@ -46,6 +46,11 @@
61832 #define __noclone __attribute__((__noclone__))
61833
61834 #endif
61835 +
61836 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61837 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61838 +#define __bos0(ptr) __bos((ptr), 0)
61839 +#define __bos1(ptr) __bos((ptr), 1)
61840 #endif
61841
61842 #if __GNUC_MINOR__ > 0
61843 diff -urNp linux-2.6.39.1/include/linux/compiler.h linux-2.6.39.1/include/linux/compiler.h
61844 --- linux-2.6.39.1/include/linux/compiler.h 2011-05-19 00:06:34.000000000 -0400
61845 +++ linux-2.6.39.1/include/linux/compiler.h 2011-05-22 19:36:32.000000000 -0400
61846 @@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
61847 #define __cold
61848 #endif
61849
61850 +#ifndef __alloc_size
61851 +#define __alloc_size
61852 +#endif
61853 +
61854 +#ifndef __bos
61855 +#define __bos
61856 +#endif
61857 +
61858 +#ifndef __bos0
61859 +#define __bos0
61860 +#endif
61861 +
61862 +#ifndef __bos1
61863 +#define __bos1
61864 +#endif
61865 +
61866 /* Simple shorthand for a section definition */
61867 #ifndef __section
61868 # define __section(S) __attribute__ ((__section__(#S)))
61869 @@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
61870 * use is to mediate communication between process-level code and irq/NMI
61871 * handlers, all running on the same CPU.
61872 */
61873 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61874 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61875 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61876
61877 #endif /* __LINUX_COMPILER_H */
61878 diff -urNp linux-2.6.39.1/include/linux/concap.h linux-2.6.39.1/include/linux/concap.h
61879 --- linux-2.6.39.1/include/linux/concap.h 2011-05-19 00:06:34.000000000 -0400
61880 +++ linux-2.6.39.1/include/linux/concap.h 2011-05-22 19:36:32.000000000 -0400
61881 @@ -30,7 +30,7 @@ struct concap_device_ops;
61882 struct concap_proto{
61883 struct net_device *net_dev; /* net device using our service */
61884 struct concap_device_ops *dops; /* callbacks provided by device */
61885 - struct concap_proto_ops *pops; /* callbacks provided by us */
61886 + const struct concap_proto_ops *pops; /* callbacks provided by us */
61887 spinlock_t lock;
61888 int flags;
61889 void *proto_data; /* protocol specific private data, to
61890 diff -urNp linux-2.6.39.1/include/linux/configfs.h linux-2.6.39.1/include/linux/configfs.h
61891 --- linux-2.6.39.1/include/linux/configfs.h 2011-05-19 00:06:34.000000000 -0400
61892 +++ linux-2.6.39.1/include/linux/configfs.h 2011-05-22 19:36:32.000000000 -0400
61893 @@ -82,7 +82,7 @@ extern void config_item_put(struct confi
61894 struct config_item_type {
61895 struct module *ct_owner;
61896 struct configfs_item_operations *ct_item_ops;
61897 - struct configfs_group_operations *ct_group_ops;
61898 + const struct configfs_group_operations *ct_group_ops;
61899 struct configfs_attribute **ct_attrs;
61900 };
61901
61902 diff -urNp linux-2.6.39.1/include/linux/cpuset.h linux-2.6.39.1/include/linux/cpuset.h
61903 --- linux-2.6.39.1/include/linux/cpuset.h 2011-05-19 00:06:34.000000000 -0400
61904 +++ linux-2.6.39.1/include/linux/cpuset.h 2011-05-22 19:36:32.000000000 -0400
61905 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
61906 * nodemask.
61907 */
61908 smp_mb();
61909 - --ACCESS_ONCE(current->mems_allowed_change_disable);
61910 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
61911 }
61912
61913 static inline void set_mems_allowed(nodemask_t nodemask)
61914 diff -urNp linux-2.6.39.1/include/linux/dca.h linux-2.6.39.1/include/linux/dca.h
61915 --- linux-2.6.39.1/include/linux/dca.h 2011-05-19 00:06:34.000000000 -0400
61916 +++ linux-2.6.39.1/include/linux/dca.h 2011-05-22 19:36:32.000000000 -0400
61917 @@ -34,7 +34,7 @@ void dca_unregister_notify(struct notifi
61918
61919 struct dca_provider {
61920 struct list_head node;
61921 - struct dca_ops *ops;
61922 + const struct dca_ops *ops;
61923 struct device *cd;
61924 int id;
61925 };
61926 @@ -53,7 +53,7 @@ struct dca_ops {
61927 int (*dev_managed) (struct dca_provider *, struct device *);
61928 };
61929
61930 -struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size);
61931 +struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size);
61932 void free_dca_provider(struct dca_provider *dca);
61933 int register_dca_provider(struct dca_provider *dca, struct device *dev);
61934 void unregister_dca_provider(struct dca_provider *dca, struct device *dev);
61935 diff -urNp linux-2.6.39.1/include/linux/decompress/mm.h linux-2.6.39.1/include/linux/decompress/mm.h
61936 --- linux-2.6.39.1/include/linux/decompress/mm.h 2011-05-19 00:06:34.000000000 -0400
61937 +++ linux-2.6.39.1/include/linux/decompress/mm.h 2011-05-22 19:36:33.000000000 -0400
61938 @@ -77,7 +77,7 @@ static void free(void *where)
61939 * warnings when not needed (indeed large_malloc / large_free are not
61940 * needed by inflate */
61941
61942 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61943 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61944 #define free(a) kfree(a)
61945
61946 #define large_malloc(a) vmalloc(a)
61947 diff -urNp linux-2.6.39.1/include/linux/dma-mapping.h linux-2.6.39.1/include/linux/dma-mapping.h
61948 --- linux-2.6.39.1/include/linux/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
61949 +++ linux-2.6.39.1/include/linux/dma-mapping.h 2011-05-22 19:36:33.000000000 -0400
61950 @@ -16,40 +16,40 @@ enum dma_data_direction {
61951 };
61952
61953 struct dma_map_ops {
61954 - void* (*alloc_coherent)(struct device *dev, size_t size,
61955 + void* (* const alloc_coherent)(struct device *dev, size_t size,
61956 dma_addr_t *dma_handle, gfp_t gfp);
61957 - void (*free_coherent)(struct device *dev, size_t size,
61958 + void (* const free_coherent)(struct device *dev, size_t size,
61959 void *vaddr, dma_addr_t dma_handle);
61960 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
61961 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
61962 unsigned long offset, size_t size,
61963 enum dma_data_direction dir,
61964 struct dma_attrs *attrs);
61965 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
61966 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
61967 size_t size, enum dma_data_direction dir,
61968 struct dma_attrs *attrs);
61969 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
61970 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
61971 int nents, enum dma_data_direction dir,
61972 struct dma_attrs *attrs);
61973 - void (*unmap_sg)(struct device *dev,
61974 + void (* const unmap_sg)(struct device *dev,
61975 struct scatterlist *sg, int nents,
61976 enum dma_data_direction dir,
61977 struct dma_attrs *attrs);
61978 - void (*sync_single_for_cpu)(struct device *dev,
61979 + void (* const sync_single_for_cpu)(struct device *dev,
61980 dma_addr_t dma_handle, size_t size,
61981 enum dma_data_direction dir);
61982 - void (*sync_single_for_device)(struct device *dev,
61983 + void (* const sync_single_for_device)(struct device *dev,
61984 dma_addr_t dma_handle, size_t size,
61985 enum dma_data_direction dir);
61986 - void (*sync_sg_for_cpu)(struct device *dev,
61987 + void (* const sync_sg_for_cpu)(struct device *dev,
61988 struct scatterlist *sg, int nents,
61989 enum dma_data_direction dir);
61990 - void (*sync_sg_for_device)(struct device *dev,
61991 + void (* const sync_sg_for_device)(struct device *dev,
61992 struct scatterlist *sg, int nents,
61993 enum dma_data_direction dir);
61994 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
61995 - int (*dma_supported)(struct device *dev, u64 mask);
61996 - int (*set_dma_mask)(struct device *dev, u64 mask);
61997 - int is_phys;
61998 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
61999 + int (* const dma_supported)(struct device *dev, u64 mask);
62000 + int (* set_dma_mask)(struct device *dev, u64 mask);
62001 + const int is_phys;
62002 };
62003
62004 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62005 diff -urNp linux-2.6.39.1/include/linux/elf.h linux-2.6.39.1/include/linux/elf.h
62006 --- linux-2.6.39.1/include/linux/elf.h 2011-05-19 00:06:34.000000000 -0400
62007 +++ linux-2.6.39.1/include/linux/elf.h 2011-05-22 19:36:33.000000000 -0400
62008 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
62009 #define PT_GNU_EH_FRAME 0x6474e550
62010
62011 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62012 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62013 +
62014 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62015 +
62016 +/* Constants for the e_flags field */
62017 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62018 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62019 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62020 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62021 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62022 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62023
62024 /*
62025 * Extended Numbering
62026 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
62027 #define DT_DEBUG 21
62028 #define DT_TEXTREL 22
62029 #define DT_JMPREL 23
62030 +#define DT_FLAGS 30
62031 + #define DF_TEXTREL 0x00000004
62032 #define DT_ENCODING 32
62033 #define OLD_DT_LOOS 0x60000000
62034 #define DT_LOOS 0x6000000d
62035 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
62036 #define PF_W 0x2
62037 #define PF_X 0x1
62038
62039 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62040 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62041 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62042 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62043 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62044 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62045 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62046 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62047 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62048 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62049 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62050 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62051 +
62052 typedef struct elf32_phdr{
62053 Elf32_Word p_type;
62054 Elf32_Off p_offset;
62055 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
62056 #define EI_OSABI 7
62057 #define EI_PAD 8
62058
62059 +#define EI_PAX 14
62060 +
62061 #define ELFMAG0 0x7f /* EI_MAG */
62062 #define ELFMAG1 'E'
62063 #define ELFMAG2 'L'
62064 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62065 #define elf_note elf32_note
62066 #define elf_addr_t Elf32_Off
62067 #define Elf_Half Elf32_Half
62068 +#define elf_dyn Elf32_Dyn
62069
62070 #else
62071
62072 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62073 #define elf_note elf64_note
62074 #define elf_addr_t Elf64_Off
62075 #define Elf_Half Elf64_Half
62076 +#define elf_dyn Elf64_Dyn
62077
62078 #endif
62079
62080 diff -urNp linux-2.6.39.1/include/linux/enclosure.h linux-2.6.39.1/include/linux/enclosure.h
62081 --- linux-2.6.39.1/include/linux/enclosure.h 2011-05-19 00:06:34.000000000 -0400
62082 +++ linux-2.6.39.1/include/linux/enclosure.h 2011-05-22 19:36:33.000000000 -0400
62083 @@ -98,7 +98,7 @@ struct enclosure_device {
62084 void *scratch;
62085 struct list_head node;
62086 struct device edev;
62087 - struct enclosure_component_callbacks *cb;
62088 + const struct enclosure_component_callbacks *cb;
62089 int components;
62090 struct enclosure_component component[0];
62091 };
62092 diff -urNp linux-2.6.39.1/include/linux/fscache-cache.h linux-2.6.39.1/include/linux/fscache-cache.h
62093 --- linux-2.6.39.1/include/linux/fscache-cache.h 2011-05-19 00:06:34.000000000 -0400
62094 +++ linux-2.6.39.1/include/linux/fscache-cache.h 2011-05-22 19:36:33.000000000 -0400
62095 @@ -113,7 +113,7 @@ struct fscache_operation {
62096 #endif
62097 };
62098
62099 -extern atomic_t fscache_op_debug_id;
62100 +extern atomic_unchecked_t fscache_op_debug_id;
62101 extern void fscache_op_work_func(struct work_struct *work);
62102
62103 extern void fscache_enqueue_operation(struct fscache_operation *);
62104 @@ -133,7 +133,7 @@ static inline void fscache_operation_ini
62105 {
62106 INIT_WORK(&op->work, fscache_op_work_func);
62107 atomic_set(&op->usage, 1);
62108 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62109 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62110 op->processor = processor;
62111 op->release = release;
62112 INIT_LIST_HEAD(&op->pend_link);
62113 diff -urNp linux-2.6.39.1/include/linux/fs.h linux-2.6.39.1/include/linux/fs.h
62114 --- linux-2.6.39.1/include/linux/fs.h 2011-05-19 00:06:34.000000000 -0400
62115 +++ linux-2.6.39.1/include/linux/fs.h 2011-05-22 19:41:42.000000000 -0400
62116 @@ -108,6 +108,11 @@ struct inodes_stat_t {
62117 /* File was opened by fanotify and shouldn't generate fanotify events */
62118 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
62119
62120 +/* Hack for grsec so as not to require read permission simply to execute
62121 + * a binary
62122 + */
62123 +#define FMODE_GREXEC ((__force fmode_t)0x2000000)
62124 +
62125 /*
62126 * The below are the various read and write types that we support. Some of
62127 * them include behavioral modifiers that send information down to the
62128 @@ -575,41 +580,41 @@ typedef int (*read_actor_t)(read_descrip
62129 unsigned long, unsigned long);
62130
62131 struct address_space_operations {
62132 - int (*writepage)(struct page *page, struct writeback_control *wbc);
62133 - int (*readpage)(struct file *, struct page *);
62134 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
62135 + int (* const readpage)(struct file *, struct page *);
62136
62137 /* Write back some dirty pages from this mapping. */
62138 - int (*writepages)(struct address_space *, struct writeback_control *);
62139 + int (* const writepages)(struct address_space *, struct writeback_control *);
62140
62141 /* Set a page dirty. Return true if this dirtied it */
62142 - int (*set_page_dirty)(struct page *page);
62143 + int (* const set_page_dirty)(struct page *page);
62144
62145 - int (*readpages)(struct file *filp, struct address_space *mapping,
62146 + int (* const readpages)(struct file *filp, struct address_space *mapping,
62147 struct list_head *pages, unsigned nr_pages);
62148
62149 - int (*write_begin)(struct file *, struct address_space *mapping,
62150 + int (* const write_begin)(struct file *, struct address_space *mapping,
62151 loff_t pos, unsigned len, unsigned flags,
62152 struct page **pagep, void **fsdata);
62153 - int (*write_end)(struct file *, struct address_space *mapping,
62154 + int (* const write_end)(struct file *, struct address_space *mapping,
62155 loff_t pos, unsigned len, unsigned copied,
62156 struct page *page, void *fsdata);
62157
62158 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
62159 - sector_t (*bmap)(struct address_space *, sector_t);
62160 - void (*invalidatepage) (struct page *, unsigned long);
62161 - int (*releasepage) (struct page *, gfp_t);
62162 - void (*freepage)(struct page *);
62163 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
62164 + sector_t (* const bmap)(struct address_space *, sector_t);
62165 + void (* const invalidatepage) (struct page *, unsigned long);
62166 + int (* const releasepage) (struct page *, gfp_t);
62167 + void (* const freepage)(struct page *);
62168 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
62169 loff_t offset, unsigned long nr_segs);
62170 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
62171 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
62172 void **, unsigned long *);
62173 /* migrate the contents of a page to the specified target */
62174 - int (*migratepage) (struct address_space *,
62175 + int (* const migratepage) (struct address_space *,
62176 struct page *, struct page *);
62177 - int (*launder_page) (struct page *);
62178 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
62179 + int (* const launder_page) (struct page *);
62180 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
62181 unsigned long);
62182 - int (*error_remove_page)(struct address_space *, struct page *);
62183 + int (* const error_remove_page)(struct address_space *, struct page *);
62184 };
62185
62186 extern const struct address_space_operations empty_aops;
62187 @@ -1060,17 +1065,17 @@ static inline int file_check_writeable(s
62188 typedef struct files_struct *fl_owner_t;
62189
62190 struct file_lock_operations {
62191 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62192 - void (*fl_release_private)(struct file_lock *);
62193 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62194 + void (* const fl_release_private)(struct file_lock *);
62195 };
62196
62197 struct lock_manager_operations {
62198 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
62199 - void (*fl_notify)(struct file_lock *); /* unblock callback */
62200 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
62201 - void (*fl_release_private)(struct file_lock *);
62202 - void (*fl_break)(struct file_lock *);
62203 - int (*fl_change)(struct file_lock **, int);
62204 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
62205 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
62206 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
62207 + void (* const fl_release_private)(struct file_lock *);
62208 + void (* const fl_break)(struct file_lock *);
62209 + int (* const fl_change)(struct file_lock **, int);
62210 };
62211
62212 struct lock_manager {
62213 @@ -1611,31 +1616,31 @@ extern ssize_t vfs_writev(struct file *,
62214 unsigned long, loff_t *);
62215
62216 struct super_operations {
62217 - struct inode *(*alloc_inode)(struct super_block *sb);
62218 - void (*destroy_inode)(struct inode *);
62219 + struct inode *(* const alloc_inode)(struct super_block *sb);
62220 + void (* const destroy_inode)(struct inode *);
62221
62222 - void (*dirty_inode) (struct inode *);
62223 - int (*write_inode) (struct inode *, struct writeback_control *wbc);
62224 - int (*drop_inode) (struct inode *);
62225 - void (*evict_inode) (struct inode *);
62226 - void (*put_super) (struct super_block *);
62227 - void (*write_super) (struct super_block *);
62228 - int (*sync_fs)(struct super_block *sb, int wait);
62229 - int (*freeze_fs) (struct super_block *);
62230 - int (*unfreeze_fs) (struct super_block *);
62231 - int (*statfs) (struct dentry *, struct kstatfs *);
62232 - int (*remount_fs) (struct super_block *, int *, char *);
62233 - void (*umount_begin) (struct super_block *);
62234 -
62235 - int (*show_options)(struct seq_file *, struct vfsmount *);
62236 - int (*show_devname)(struct seq_file *, struct vfsmount *);
62237 - int (*show_path)(struct seq_file *, struct vfsmount *);
62238 - int (*show_stats)(struct seq_file *, struct vfsmount *);
62239 + void (* const dirty_inode) (struct inode *);
62240 + int (* const write_inode) (struct inode *, struct writeback_control *wbc);
62241 + int (* const drop_inode) (struct inode *);
62242 + void (* const evict_inode) (struct inode *);
62243 + void (* const put_super) (struct super_block *);
62244 + void (* const write_super) (struct super_block *);
62245 + int (* const sync_fs)(struct super_block *sb, int wait);
62246 + int (* const freeze_fs) (struct super_block *);
62247 + int (* const unfreeze_fs) (struct super_block *);
62248 + int (* const statfs) (struct dentry *, struct kstatfs *);
62249 + int (* const remount_fs) (struct super_block *, int *, char *);
62250 + void (* const umount_begin) (struct super_block *);
62251 +
62252 + int (* const show_options)(struct seq_file *, struct vfsmount *);
62253 + int (* const show_devname)(struct seq_file *, struct vfsmount *);
62254 + int (* const show_path)(struct seq_file *, struct vfsmount *);
62255 + int (* const show_stats)(struct seq_file *, struct vfsmount *);
62256 #ifdef CONFIG_QUOTA
62257 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
62258 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62259 + ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
62260 + ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62261 #endif
62262 - int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62263 + int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62264 };
62265
62266 /*
62267 diff -urNp linux-2.6.39.1/include/linux/fs_struct.h linux-2.6.39.1/include/linux/fs_struct.h
62268 --- linux-2.6.39.1/include/linux/fs_struct.h 2011-05-19 00:06:34.000000000 -0400
62269 +++ linux-2.6.39.1/include/linux/fs_struct.h 2011-05-22 19:36:33.000000000 -0400
62270 @@ -6,7 +6,7 @@
62271 #include <linux/seqlock.h>
62272
62273 struct fs_struct {
62274 - int users;
62275 + atomic_t users;
62276 spinlock_t lock;
62277 seqcount_t seq;
62278 int umask;
62279 diff -urNp linux-2.6.39.1/include/linux/ftrace_event.h linux-2.6.39.1/include/linux/ftrace_event.h
62280 --- linux-2.6.39.1/include/linux/ftrace_event.h 2011-05-19 00:06:34.000000000 -0400
62281 +++ linux-2.6.39.1/include/linux/ftrace_event.h 2011-05-22 19:36:33.000000000 -0400
62282 @@ -235,7 +235,7 @@ extern int trace_define_field(struct ftr
62283 extern int trace_add_event_call(struct ftrace_event_call *call);
62284 extern void trace_remove_event_call(struct ftrace_event_call *call);
62285
62286 -#define is_signed_type(type) (((type)(-1)) < 0)
62287 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62288
62289 int trace_set_clr_event(const char *system, const char *event, int set);
62290
62291 diff -urNp linux-2.6.39.1/include/linux/ftrace.h linux-2.6.39.1/include/linux/ftrace.h
62292 --- linux-2.6.39.1/include/linux/ftrace.h 2011-05-19 00:06:34.000000000 -0400
62293 +++ linux-2.6.39.1/include/linux/ftrace.h 2011-05-22 19:36:33.000000000 -0400
62294 @@ -140,7 +140,7 @@ extern void
62295 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62296 void *data);
62297 extern void
62298 -unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
62299 +unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops);
62300 extern void unregister_ftrace_function_probe_all(char *glob);
62301
62302 extern int ftrace_text_reserved(void *start, void *end);
62303 diff -urNp linux-2.6.39.1/include/linux/genhd.h linux-2.6.39.1/include/linux/genhd.h
62304 --- linux-2.6.39.1/include/linux/genhd.h 2011-06-03 00:04:14.000000000 -0400
62305 +++ linux-2.6.39.1/include/linux/genhd.h 2011-06-03 00:32:08.000000000 -0400
62306 @@ -184,7 +184,7 @@ struct gendisk {
62307 struct kobject *slave_dir;
62308
62309 struct timer_rand_state *random;
62310 - atomic_t sync_io; /* RAID */
62311 + atomic_unchecked_t sync_io; /* RAID */
62312 struct disk_events *ev;
62313 #ifdef CONFIG_BLK_DEV_INTEGRITY
62314 struct blk_integrity *integrity;
62315 diff -urNp linux-2.6.39.1/include/linux/gracl.h linux-2.6.39.1/include/linux/gracl.h
62316 --- linux-2.6.39.1/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
62317 +++ linux-2.6.39.1/include/linux/gracl.h 2011-05-22 19:41:42.000000000 -0400
62318 @@ -0,0 +1,317 @@
62319 +#ifndef GR_ACL_H
62320 +#define GR_ACL_H
62321 +
62322 +#include <linux/grdefs.h>
62323 +#include <linux/resource.h>
62324 +#include <linux/capability.h>
62325 +#include <linux/dcache.h>
62326 +#include <asm/resource.h>
62327 +
62328 +/* Major status information */
62329 +
62330 +#define GR_VERSION "grsecurity 2.2.2"
62331 +#define GRSECURITY_VERSION 0x2202
62332 +
62333 +enum {
62334 + GR_SHUTDOWN = 0,
62335 + GR_ENABLE = 1,
62336 + GR_SPROLE = 2,
62337 + GR_RELOAD = 3,
62338 + GR_SEGVMOD = 4,
62339 + GR_STATUS = 5,
62340 + GR_UNSPROLE = 6,
62341 + GR_PASSSET = 7,
62342 + GR_SPROLEPAM = 8,
62343 +};
62344 +
62345 +/* Password setup definitions
62346 + * kernel/grhash.c */
62347 +enum {
62348 + GR_PW_LEN = 128,
62349 + GR_SALT_LEN = 16,
62350 + GR_SHA_LEN = 32,
62351 +};
62352 +
62353 +enum {
62354 + GR_SPROLE_LEN = 64,
62355 +};
62356 +
62357 +enum {
62358 + GR_NO_GLOB = 0,
62359 + GR_REG_GLOB,
62360 + GR_CREATE_GLOB
62361 +};
62362 +
62363 +#define GR_NLIMITS 32
62364 +
62365 +/* Begin Data Structures */
62366 +
62367 +struct sprole_pw {
62368 + unsigned char *rolename;
62369 + unsigned char salt[GR_SALT_LEN];
62370 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62371 +};
62372 +
62373 +struct name_entry {
62374 + __u32 key;
62375 + ino_t inode;
62376 + dev_t device;
62377 + char *name;
62378 + __u16 len;
62379 + __u8 deleted;
62380 + struct name_entry *prev;
62381 + struct name_entry *next;
62382 +};
62383 +
62384 +struct inodev_entry {
62385 + struct name_entry *nentry;
62386 + struct inodev_entry *prev;
62387 + struct inodev_entry *next;
62388 +};
62389 +
62390 +struct acl_role_db {
62391 + struct acl_role_label **r_hash;
62392 + __u32 r_size;
62393 +};
62394 +
62395 +struct inodev_db {
62396 + struct inodev_entry **i_hash;
62397 + __u32 i_size;
62398 +};
62399 +
62400 +struct name_db {
62401 + struct name_entry **n_hash;
62402 + __u32 n_size;
62403 +};
62404 +
62405 +struct crash_uid {
62406 + uid_t uid;
62407 + unsigned long expires;
62408 +};
62409 +
62410 +struct gr_hash_struct {
62411 + void **table;
62412 + void **nametable;
62413 + void *first;
62414 + __u32 table_size;
62415 + __u32 used_size;
62416 + int type;
62417 +};
62418 +
62419 +/* Userspace Grsecurity ACL data structures */
62420 +
62421 +struct acl_subject_label {
62422 + char *filename;
62423 + ino_t inode;
62424 + dev_t device;
62425 + __u32 mode;
62426 + kernel_cap_t cap_mask;
62427 + kernel_cap_t cap_lower;
62428 + kernel_cap_t cap_invert_audit;
62429 +
62430 + struct rlimit res[GR_NLIMITS];
62431 + __u32 resmask;
62432 +
62433 + __u8 user_trans_type;
62434 + __u8 group_trans_type;
62435 + uid_t *user_transitions;
62436 + gid_t *group_transitions;
62437 + __u16 user_trans_num;
62438 + __u16 group_trans_num;
62439 +
62440 + __u32 sock_families[2];
62441 + __u32 ip_proto[8];
62442 + __u32 ip_type;
62443 + struct acl_ip_label **ips;
62444 + __u32 ip_num;
62445 + __u32 inaddr_any_override;
62446 +
62447 + __u32 crashes;
62448 + unsigned long expires;
62449 +
62450 + struct acl_subject_label *parent_subject;
62451 + struct gr_hash_struct *hash;
62452 + struct acl_subject_label *prev;
62453 + struct acl_subject_label *next;
62454 +
62455 + struct acl_object_label **obj_hash;
62456 + __u32 obj_hash_size;
62457 + __u16 pax_flags;
62458 +};
62459 +
62460 +struct role_allowed_ip {
62461 + __u32 addr;
62462 + __u32 netmask;
62463 +
62464 + struct role_allowed_ip *prev;
62465 + struct role_allowed_ip *next;
62466 +};
62467 +
62468 +struct role_transition {
62469 + char *rolename;
62470 +
62471 + struct role_transition *prev;
62472 + struct role_transition *next;
62473 +};
62474 +
62475 +struct acl_role_label {
62476 + char *rolename;
62477 + uid_t uidgid;
62478 + __u16 roletype;
62479 +
62480 + __u16 auth_attempts;
62481 + unsigned long expires;
62482 +
62483 + struct acl_subject_label *root_label;
62484 + struct gr_hash_struct *hash;
62485 +
62486 + struct acl_role_label *prev;
62487 + struct acl_role_label *next;
62488 +
62489 + struct role_transition *transitions;
62490 + struct role_allowed_ip *allowed_ips;
62491 + uid_t *domain_children;
62492 + __u16 domain_child_num;
62493 +
62494 + struct acl_subject_label **subj_hash;
62495 + __u32 subj_hash_size;
62496 +};
62497 +
62498 +struct user_acl_role_db {
62499 + struct acl_role_label **r_table;
62500 + __u32 num_pointers; /* Number of allocations to track */
62501 + __u32 num_roles; /* Number of roles */
62502 + __u32 num_domain_children; /* Number of domain children */
62503 + __u32 num_subjects; /* Number of subjects */
62504 + __u32 num_objects; /* Number of objects */
62505 +};
62506 +
62507 +struct acl_object_label {
62508 + char *filename;
62509 + ino_t inode;
62510 + dev_t device;
62511 + __u32 mode;
62512 +
62513 + struct acl_subject_label *nested;
62514 + struct acl_object_label *globbed;
62515 +
62516 + /* next two structures not used */
62517 +
62518 + struct acl_object_label *prev;
62519 + struct acl_object_label *next;
62520 +};
62521 +
62522 +struct acl_ip_label {
62523 + char *iface;
62524 + __u32 addr;
62525 + __u32 netmask;
62526 + __u16 low, high;
62527 + __u8 mode;
62528 + __u32 type;
62529 + __u32 proto[8];
62530 +
62531 + /* next two structures not used */
62532 +
62533 + struct acl_ip_label *prev;
62534 + struct acl_ip_label *next;
62535 +};
62536 +
62537 +struct gr_arg {
62538 + struct user_acl_role_db role_db;
62539 + unsigned char pw[GR_PW_LEN];
62540 + unsigned char salt[GR_SALT_LEN];
62541 + unsigned char sum[GR_SHA_LEN];
62542 + unsigned char sp_role[GR_SPROLE_LEN];
62543 + struct sprole_pw *sprole_pws;
62544 + dev_t segv_device;
62545 + ino_t segv_inode;
62546 + uid_t segv_uid;
62547 + __u16 num_sprole_pws;
62548 + __u16 mode;
62549 +};
62550 +
62551 +struct gr_arg_wrapper {
62552 + struct gr_arg *arg;
62553 + __u32 version;
62554 + __u32 size;
62555 +};
62556 +
62557 +struct subject_map {
62558 + struct acl_subject_label *user;
62559 + struct acl_subject_label *kernel;
62560 + struct subject_map *prev;
62561 + struct subject_map *next;
62562 +};
62563 +
62564 +struct acl_subj_map_db {
62565 + struct subject_map **s_hash;
62566 + __u32 s_size;
62567 +};
62568 +
62569 +/* End Data Structures Section */
62570 +
62571 +/* Hash functions generated by empirical testing by Brad Spengler
62572 + Makes good use of the low bits of the inode. Generally 0-1 times
62573 + in loop for successful match. 0-3 for unsuccessful match.
62574 + Shift/add algorithm with modulus of table size and an XOR*/
62575 +
62576 +static __inline__ unsigned int
62577 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62578 +{
62579 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62580 +}
62581 +
62582 + static __inline__ unsigned int
62583 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62584 +{
62585 + return ((const unsigned long)userp % sz);
62586 +}
62587 +
62588 +static __inline__ unsigned int
62589 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62590 +{
62591 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62592 +}
62593 +
62594 +static __inline__ unsigned int
62595 +nhash(const char *name, const __u16 len, const unsigned int sz)
62596 +{
62597 + return full_name_hash((const unsigned char *)name, len) % sz;
62598 +}
62599 +
62600 +#define FOR_EACH_ROLE_START(role) \
62601 + role = role_list; \
62602 + while (role) {
62603 +
62604 +#define FOR_EACH_ROLE_END(role) \
62605 + role = role->prev; \
62606 + }
62607 +
62608 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62609 + subj = NULL; \
62610 + iter = 0; \
62611 + while (iter < role->subj_hash_size) { \
62612 + if (subj == NULL) \
62613 + subj = role->subj_hash[iter]; \
62614 + if (subj == NULL) { \
62615 + iter++; \
62616 + continue; \
62617 + }
62618 +
62619 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62620 + subj = subj->next; \
62621 + if (subj == NULL) \
62622 + iter++; \
62623 + }
62624 +
62625 +
62626 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62627 + subj = role->hash->first; \
62628 + while (subj != NULL) {
62629 +
62630 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62631 + subj = subj->next; \
62632 + }
62633 +
62634 +#endif
62635 +
62636 diff -urNp linux-2.6.39.1/include/linux/gralloc.h linux-2.6.39.1/include/linux/gralloc.h
62637 --- linux-2.6.39.1/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
62638 +++ linux-2.6.39.1/include/linux/gralloc.h 2011-05-22 19:41:42.000000000 -0400
62639 @@ -0,0 +1,9 @@
62640 +#ifndef __GRALLOC_H
62641 +#define __GRALLOC_H
62642 +
62643 +void acl_free_all(void);
62644 +int acl_alloc_stack_init(unsigned long size);
62645 +void *acl_alloc(unsigned long len);
62646 +void *acl_alloc_num(unsigned long num, unsigned long len);
62647 +
62648 +#endif
62649 diff -urNp linux-2.6.39.1/include/linux/grdefs.h linux-2.6.39.1/include/linux/grdefs.h
62650 --- linux-2.6.39.1/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
62651 +++ linux-2.6.39.1/include/linux/grdefs.h 2011-05-22 19:41:42.000000000 -0400
62652 @@ -0,0 +1,139 @@
62653 +#ifndef GRDEFS_H
62654 +#define GRDEFS_H
62655 +
62656 +/* Begin grsecurity status declarations */
62657 +
62658 +enum {
62659 + GR_READY = 0x01,
62660 + GR_STATUS_INIT = 0x00 // disabled state
62661 +};
62662 +
62663 +/* Begin ACL declarations */
62664 +
62665 +/* Role flags */
62666 +
62667 +enum {
62668 + GR_ROLE_USER = 0x0001,
62669 + GR_ROLE_GROUP = 0x0002,
62670 + GR_ROLE_DEFAULT = 0x0004,
62671 + GR_ROLE_SPECIAL = 0x0008,
62672 + GR_ROLE_AUTH = 0x0010,
62673 + GR_ROLE_NOPW = 0x0020,
62674 + GR_ROLE_GOD = 0x0040,
62675 + GR_ROLE_LEARN = 0x0080,
62676 + GR_ROLE_TPE = 0x0100,
62677 + GR_ROLE_DOMAIN = 0x0200,
62678 + GR_ROLE_PAM = 0x0400,
62679 + GR_ROLE_PERSIST = 0x0800
62680 +};
62681 +
62682 +/* ACL Subject and Object mode flags */
62683 +enum {
62684 + GR_DELETED = 0x80000000
62685 +};
62686 +
62687 +/* ACL Object-only mode flags */
62688 +enum {
62689 + GR_READ = 0x00000001,
62690 + GR_APPEND = 0x00000002,
62691 + GR_WRITE = 0x00000004,
62692 + GR_EXEC = 0x00000008,
62693 + GR_FIND = 0x00000010,
62694 + GR_INHERIT = 0x00000020,
62695 + GR_SETID = 0x00000040,
62696 + GR_CREATE = 0x00000080,
62697 + GR_DELETE = 0x00000100,
62698 + GR_LINK = 0x00000200,
62699 + GR_AUDIT_READ = 0x00000400,
62700 + GR_AUDIT_APPEND = 0x00000800,
62701 + GR_AUDIT_WRITE = 0x00001000,
62702 + GR_AUDIT_EXEC = 0x00002000,
62703 + GR_AUDIT_FIND = 0x00004000,
62704 + GR_AUDIT_INHERIT= 0x00008000,
62705 + GR_AUDIT_SETID = 0x00010000,
62706 + GR_AUDIT_CREATE = 0x00020000,
62707 + GR_AUDIT_DELETE = 0x00040000,
62708 + GR_AUDIT_LINK = 0x00080000,
62709 + GR_PTRACERD = 0x00100000,
62710 + GR_NOPTRACE = 0x00200000,
62711 + GR_SUPPRESS = 0x00400000,
62712 + GR_NOLEARN = 0x00800000,
62713 + GR_INIT_TRANSFER= 0x01000000
62714 +};
62715 +
62716 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62717 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62718 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62719 +
62720 +/* ACL subject-only mode flags */
62721 +enum {
62722 + GR_KILL = 0x00000001,
62723 + GR_VIEW = 0x00000002,
62724 + GR_PROTECTED = 0x00000004,
62725 + GR_LEARN = 0x00000008,
62726 + GR_OVERRIDE = 0x00000010,
62727 + /* just a placeholder, this mode is only used in userspace */
62728 + GR_DUMMY = 0x00000020,
62729 + GR_PROTSHM = 0x00000040,
62730 + GR_KILLPROC = 0x00000080,
62731 + GR_KILLIPPROC = 0x00000100,
62732 + /* just a placeholder, this mode is only used in userspace */
62733 + GR_NOTROJAN = 0x00000200,
62734 + GR_PROTPROCFD = 0x00000400,
62735 + GR_PROCACCT = 0x00000800,
62736 + GR_RELAXPTRACE = 0x00001000,
62737 + GR_NESTED = 0x00002000,
62738 + GR_INHERITLEARN = 0x00004000,
62739 + GR_PROCFIND = 0x00008000,
62740 + GR_POVERRIDE = 0x00010000,
62741 + GR_KERNELAUTH = 0x00020000,
62742 + GR_ATSECURE = 0x00040000
62743 +};
62744 +
62745 +enum {
62746 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62747 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62748 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62749 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62750 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62751 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62752 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62753 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62754 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62755 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62756 +};
62757 +
62758 +enum {
62759 + GR_ID_USER = 0x01,
62760 + GR_ID_GROUP = 0x02,
62761 +};
62762 +
62763 +enum {
62764 + GR_ID_ALLOW = 0x01,
62765 + GR_ID_DENY = 0x02,
62766 +};
62767 +
62768 +#define GR_CRASH_RES 31
62769 +#define GR_UIDTABLE_MAX 500
62770 +
62771 +/* begin resource learning section */
62772 +enum {
62773 + GR_RLIM_CPU_BUMP = 60,
62774 + GR_RLIM_FSIZE_BUMP = 50000,
62775 + GR_RLIM_DATA_BUMP = 10000,
62776 + GR_RLIM_STACK_BUMP = 1000,
62777 + GR_RLIM_CORE_BUMP = 10000,
62778 + GR_RLIM_RSS_BUMP = 500000,
62779 + GR_RLIM_NPROC_BUMP = 1,
62780 + GR_RLIM_NOFILE_BUMP = 5,
62781 + GR_RLIM_MEMLOCK_BUMP = 50000,
62782 + GR_RLIM_AS_BUMP = 500000,
62783 + GR_RLIM_LOCKS_BUMP = 2,
62784 + GR_RLIM_SIGPENDING_BUMP = 5,
62785 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62786 + GR_RLIM_NICE_BUMP = 1,
62787 + GR_RLIM_RTPRIO_BUMP = 1,
62788 + GR_RLIM_RTTIME_BUMP = 1000000
62789 +};
62790 +
62791 +#endif
62792 diff -urNp linux-2.6.39.1/include/linux/grinternal.h linux-2.6.39.1/include/linux/grinternal.h
62793 --- linux-2.6.39.1/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
62794 +++ linux-2.6.39.1/include/linux/grinternal.h 2011-05-22 19:41:42.000000000 -0400
62795 @@ -0,0 +1,219 @@
62796 +#ifndef __GRINTERNAL_H
62797 +#define __GRINTERNAL_H
62798 +
62799 +#ifdef CONFIG_GRKERNSEC
62800 +
62801 +#include <linux/fs.h>
62802 +#include <linux/mnt_namespace.h>
62803 +#include <linux/nsproxy.h>
62804 +#include <linux/gracl.h>
62805 +#include <linux/grdefs.h>
62806 +#include <linux/grmsg.h>
62807 +
62808 +void gr_add_learn_entry(const char *fmt, ...)
62809 + __attribute__ ((format (printf, 1, 2)));
62810 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62811 + const struct vfsmount *mnt);
62812 +__u32 gr_check_create(const struct dentry *new_dentry,
62813 + const struct dentry *parent,
62814 + const struct vfsmount *mnt, const __u32 mode);
62815 +int gr_check_protected_task(const struct task_struct *task);
62816 +__u32 to_gr_audit(const __u32 reqmode);
62817 +int gr_set_acls(const int type);
62818 +int gr_apply_subject_to_task(struct task_struct *task);
62819 +int gr_acl_is_enabled(void);
62820 +char gr_roletype_to_char(void);
62821 +
62822 +void gr_handle_alertkill(struct task_struct *task);
62823 +char *gr_to_filename(const struct dentry *dentry,
62824 + const struct vfsmount *mnt);
62825 +char *gr_to_filename1(const struct dentry *dentry,
62826 + const struct vfsmount *mnt);
62827 +char *gr_to_filename2(const struct dentry *dentry,
62828 + const struct vfsmount *mnt);
62829 +char *gr_to_filename3(const struct dentry *dentry,
62830 + const struct vfsmount *mnt);
62831 +
62832 +extern int grsec_enable_harden_ptrace;
62833 +extern int grsec_enable_link;
62834 +extern int grsec_enable_fifo;
62835 +extern int grsec_enable_execve;
62836 +extern int grsec_enable_shm;
62837 +extern int grsec_enable_execlog;
62838 +extern int grsec_enable_signal;
62839 +extern int grsec_enable_audit_ptrace;
62840 +extern int grsec_enable_forkfail;
62841 +extern int grsec_enable_time;
62842 +extern int grsec_enable_rofs;
62843 +extern int grsec_enable_chroot_shmat;
62844 +extern int grsec_enable_chroot_findtask;
62845 +extern int grsec_enable_chroot_mount;
62846 +extern int grsec_enable_chroot_double;
62847 +extern int grsec_enable_chroot_pivot;
62848 +extern int grsec_enable_chroot_chdir;
62849 +extern int grsec_enable_chroot_chmod;
62850 +extern int grsec_enable_chroot_mknod;
62851 +extern int grsec_enable_chroot_fchdir;
62852 +extern int grsec_enable_chroot_nice;
62853 +extern int grsec_enable_chroot_execlog;
62854 +extern int grsec_enable_chroot_caps;
62855 +extern int grsec_enable_chroot_sysctl;
62856 +extern int grsec_enable_chroot_unix;
62857 +extern int grsec_enable_tpe;
62858 +extern int grsec_tpe_gid;
62859 +extern int grsec_enable_tpe_all;
62860 +extern int grsec_enable_tpe_invert;
62861 +extern int grsec_enable_socket_all;
62862 +extern int grsec_socket_all_gid;
62863 +extern int grsec_enable_socket_client;
62864 +extern int grsec_socket_client_gid;
62865 +extern int grsec_enable_socket_server;
62866 +extern int grsec_socket_server_gid;
62867 +extern int grsec_audit_gid;
62868 +extern int grsec_enable_group;
62869 +extern int grsec_enable_audit_textrel;
62870 +extern int grsec_enable_log_rwxmaps;
62871 +extern int grsec_enable_mount;
62872 +extern int grsec_enable_chdir;
62873 +extern int grsec_resource_logging;
62874 +extern int grsec_enable_blackhole;
62875 +extern int grsec_lastack_retries;
62876 +extern int grsec_lock;
62877 +
62878 +extern spinlock_t grsec_alert_lock;
62879 +extern unsigned long grsec_alert_wtime;
62880 +extern unsigned long grsec_alert_fyet;
62881 +
62882 +extern spinlock_t grsec_audit_lock;
62883 +
62884 +extern rwlock_t grsec_exec_file_lock;
62885 +
62886 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62887 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62888 + (tsk)->exec_file->f_vfsmnt) : "/")
62889 +
62890 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62891 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62892 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62893 +
62894 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62895 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62896 + (tsk)->exec_file->f_vfsmnt) : "/")
62897 +
62898 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62899 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62900 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62901 +
62902 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62903 +
62904 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62905 +
62906 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62907 + (task)->pid, (cred)->uid, \
62908 + (cred)->euid, (cred)->gid, (cred)->egid, \
62909 + gr_parent_task_fullpath(task), \
62910 + (task)->real_parent->comm, (task)->real_parent->pid, \
62911 + (pcred)->uid, (pcred)->euid, \
62912 + (pcred)->gid, (pcred)->egid
62913 +
62914 +#define GR_CHROOT_CAPS {{ \
62915 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62916 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62917 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62918 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62919 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62920 + CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
62921 +
62922 +#define security_learn(normal_msg,args...) \
62923 +({ \
62924 + read_lock(&grsec_exec_file_lock); \
62925 + gr_add_learn_entry(normal_msg "\n", ## args); \
62926 + read_unlock(&grsec_exec_file_lock); \
62927 +})
62928 +
62929 +enum {
62930 + GR_DO_AUDIT,
62931 + GR_DONT_AUDIT,
62932 + /* used for non-audit messages that we shouldn't kill the task on */
62933 + GR_DONT_AUDIT_GOOD
62934 +};
62935 +
62936 +enum {
62937 + GR_TTYSNIFF,
62938 + GR_RBAC,
62939 + GR_RBAC_STR,
62940 + GR_STR_RBAC,
62941 + GR_RBAC_MODE2,
62942 + GR_RBAC_MODE3,
62943 + GR_FILENAME,
62944 + GR_SYSCTL_HIDDEN,
62945 + GR_NOARGS,
62946 + GR_ONE_INT,
62947 + GR_ONE_INT_TWO_STR,
62948 + GR_ONE_STR,
62949 + GR_STR_INT,
62950 + GR_TWO_STR_INT,
62951 + GR_TWO_INT,
62952 + GR_TWO_U64,
62953 + GR_THREE_INT,
62954 + GR_FIVE_INT_TWO_STR,
62955 + GR_TWO_STR,
62956 + GR_THREE_STR,
62957 + GR_FOUR_STR,
62958 + GR_STR_FILENAME,
62959 + GR_FILENAME_STR,
62960 + GR_FILENAME_TWO_INT,
62961 + GR_FILENAME_TWO_INT_STR,
62962 + GR_TEXTREL,
62963 + GR_PTRACE,
62964 + GR_RESOURCE,
62965 + GR_CAP,
62966 + GR_SIG,
62967 + GR_SIG2,
62968 + GR_CRASH1,
62969 + GR_CRASH2,
62970 + GR_PSACCT,
62971 + GR_RWXMAP
62972 +};
62973 +
62974 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62975 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62976 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62977 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62978 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62979 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62980 +#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)
62981 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62982 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62983 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62984 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62985 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62986 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62987 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62988 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62989 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62990 +#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)
62991 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62992 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62993 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62994 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62995 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62996 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62997 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62998 +#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)
62999 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63000 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63001 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63002 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63003 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63004 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63005 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63006 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63007 +#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)
63008 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63009 +
63010 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63011 +
63012 +#endif
63013 +
63014 +#endif
63015 diff -urNp linux-2.6.39.1/include/linux/grmsg.h linux-2.6.39.1/include/linux/grmsg.h
63016 --- linux-2.6.39.1/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
63017 +++ linux-2.6.39.1/include/linux/grmsg.h 2011-05-22 19:41:42.000000000 -0400
63018 @@ -0,0 +1,108 @@
63019 +#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"
63020 +#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"
63021 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63022 +#define GR_STOPMOD_MSG "denied modification of module state by "
63023 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63024 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63025 +#define GR_IOPERM_MSG "denied use of ioperm() by "
63026 +#define GR_IOPL_MSG "denied use of iopl() by "
63027 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63028 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63029 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63030 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63031 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63032 +#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"
63033 +#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"
63034 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63035 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63036 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63037 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63038 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63039 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63040 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63041 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63042 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63043 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63044 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63045 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63046 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63047 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63048 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63049 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63050 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63051 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63052 +#define GR_NPROC_MSG "denied overstep of process limit by "
63053 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63054 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
63055 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63056 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63057 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63058 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63059 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63060 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63061 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63062 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63063 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
63064 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63065 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63066 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63067 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63068 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63069 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63070 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63071 +#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"
63072 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
63073 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63074 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63075 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63076 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63077 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63078 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63079 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63080 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63081 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63082 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63083 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63084 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63085 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63086 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63087 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63088 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63089 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63090 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63091 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63092 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63093 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63094 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63095 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63096 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63097 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63098 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63099 +#define GR_TIME_MSG "time set by "
63100 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63101 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63102 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63103 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63104 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63105 +#define GR_BIND_MSG "denied bind() by "
63106 +#define GR_CONNECT_MSG "denied connect() by "
63107 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63108 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63109 +#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"
63110 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63111 +#define GR_CAP_ACL_MSG "use of %s denied for "
63112 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63113 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63114 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63115 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63116 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63117 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63118 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63119 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63120 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63121 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63122 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63123 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63124 +#define GR_VM86_MSG "denied use of vm86 by "
63125 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63126 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63127 diff -urNp linux-2.6.39.1/include/linux/grsecurity.h linux-2.6.39.1/include/linux/grsecurity.h
63128 --- linux-2.6.39.1/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
63129 +++ linux-2.6.39.1/include/linux/grsecurity.h 2011-05-22 19:41:42.000000000 -0400
63130 @@ -0,0 +1,212 @@
63131 +#ifndef GR_SECURITY_H
63132 +#define GR_SECURITY_H
63133 +#include <linux/fs.h>
63134 +#include <linux/fs_struct.h>
63135 +#include <linux/binfmts.h>
63136 +#include <linux/gracl.h>
63137 +#include <linux/compat.h>
63138 +
63139 +/* notify of brain-dead configs */
63140 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63141 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63142 +#endif
63143 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63144 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63145 +#endif
63146 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63147 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63148 +#endif
63149 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63150 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63151 +#endif
63152 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63153 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63154 +#endif
63155 +
63156 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63157 +void gr_handle_brute_check(void);
63158 +void gr_handle_kernel_exploit(void);
63159 +int gr_process_user_ban(void);
63160 +
63161 +char gr_roletype_to_char(void);
63162 +
63163 +int gr_acl_enable_at_secure(void);
63164 +
63165 +int gr_check_user_change(int real, int effective, int fs);
63166 +int gr_check_group_change(int real, int effective, int fs);
63167 +
63168 +void gr_del_task_from_ip_table(struct task_struct *p);
63169 +
63170 +int gr_pid_is_chrooted(struct task_struct *p);
63171 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63172 +int gr_handle_chroot_nice(void);
63173 +int gr_handle_chroot_sysctl(const int op);
63174 +int gr_handle_chroot_setpriority(struct task_struct *p,
63175 + const int niceval);
63176 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63177 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63178 + const struct vfsmount *mnt);
63179 +int gr_handle_chroot_caps(struct path *path);
63180 +void gr_handle_chroot_chdir(struct path *path);
63181 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63182 + const struct vfsmount *mnt, const int mode);
63183 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63184 + const struct vfsmount *mnt, const int mode);
63185 +int gr_handle_chroot_mount(const struct dentry *dentry,
63186 + const struct vfsmount *mnt,
63187 + const char *dev_name);
63188 +int gr_handle_chroot_pivot(void);
63189 +int gr_handle_chroot_unix(struct pid *pid);
63190 +
63191 +int gr_handle_rawio(const struct inode *inode);
63192 +int gr_handle_nproc(void);
63193 +
63194 +void gr_handle_ioperm(void);
63195 +void gr_handle_iopl(void);
63196 +
63197 +int gr_tpe_allow(const struct file *file);
63198 +
63199 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63200 +void gr_clear_chroot_entries(struct task_struct *task);
63201 +
63202 +void gr_log_forkfail(const int retval);
63203 +void gr_log_timechange(void);
63204 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63205 +void gr_log_chdir(const struct dentry *dentry,
63206 + const struct vfsmount *mnt);
63207 +void gr_log_chroot_exec(const struct dentry *dentry,
63208 + const struct vfsmount *mnt);
63209 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
63210 +#ifdef CONFIG_COMPAT
63211 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
63212 +#endif
63213 +void gr_log_remount(const char *devname, const int retval);
63214 +void gr_log_unmount(const char *devname, const int retval);
63215 +void gr_log_mount(const char *from, const char *to, const int retval);
63216 +void gr_log_textrel(struct vm_area_struct *vma);
63217 +void gr_log_rwxmmap(struct file *file);
63218 +void gr_log_rwxmprotect(struct file *file);
63219 +
63220 +int gr_handle_follow_link(const struct inode *parent,
63221 + const struct inode *inode,
63222 + const struct dentry *dentry,
63223 + const struct vfsmount *mnt);
63224 +int gr_handle_fifo(const struct dentry *dentry,
63225 + const struct vfsmount *mnt,
63226 + const struct dentry *dir, const int flag,
63227 + const int acc_mode);
63228 +int gr_handle_hardlink(const struct dentry *dentry,
63229 + const struct vfsmount *mnt,
63230 + struct inode *inode,
63231 + const int mode, const char *to);
63232 +
63233 +int gr_is_capable(const int cap);
63234 +int gr_is_capable_nolog(const int cap);
63235 +void gr_learn_resource(const struct task_struct *task, const int limit,
63236 + const unsigned long wanted, const int gt);
63237 +void gr_copy_label(struct task_struct *tsk);
63238 +void gr_handle_crash(struct task_struct *task, const int sig);
63239 +int gr_handle_signal(const struct task_struct *p, const int sig);
63240 +int gr_check_crash_uid(const uid_t uid);
63241 +int gr_check_protected_task(const struct task_struct *task);
63242 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63243 +int gr_acl_handle_mmap(const struct file *file,
63244 + const unsigned long prot);
63245 +int gr_acl_handle_mprotect(const struct file *file,
63246 + const unsigned long prot);
63247 +int gr_check_hidden_task(const struct task_struct *tsk);
63248 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63249 + const struct vfsmount *mnt);
63250 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63251 + const struct vfsmount *mnt);
63252 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63253 + const struct vfsmount *mnt, const int fmode);
63254 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
63255 + const struct vfsmount *mnt, mode_t mode);
63256 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63257 + const struct vfsmount *mnt, mode_t mode);
63258 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63259 + const struct vfsmount *mnt);
63260 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63261 + const struct vfsmount *mnt);
63262 +int gr_handle_ptrace(struct task_struct *task, const long request);
63263 +int gr_handle_proc_ptrace(struct task_struct *task);
63264 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63265 + const struct vfsmount *mnt);
63266 +int gr_check_crash_exec(const struct file *filp);
63267 +int gr_acl_is_enabled(void);
63268 +void gr_set_kernel_label(struct task_struct *task);
63269 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63270 + const gid_t gid);
63271 +int gr_set_proc_label(const struct dentry *dentry,
63272 + const struct vfsmount *mnt,
63273 + const int unsafe_share);
63274 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63275 + const struct vfsmount *mnt);
63276 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63277 + const struct vfsmount *mnt, const int fmode);
63278 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63279 + const struct dentry *p_dentry,
63280 + const struct vfsmount *p_mnt, const int fmode,
63281 + const int imode);
63282 +void gr_handle_create(const struct dentry *dentry,
63283 + const struct vfsmount *mnt);
63284 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63285 + const struct dentry *parent_dentry,
63286 + const struct vfsmount *parent_mnt,
63287 + const int mode);
63288 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63289 + const struct dentry *parent_dentry,
63290 + const struct vfsmount *parent_mnt);
63291 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63292 + const struct vfsmount *mnt);
63293 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63294 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63295 + const struct vfsmount *mnt);
63296 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63297 + const struct dentry *parent_dentry,
63298 + const struct vfsmount *parent_mnt,
63299 + const char *from);
63300 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63301 + const struct dentry *parent_dentry,
63302 + const struct vfsmount *parent_mnt,
63303 + const struct dentry *old_dentry,
63304 + const struct vfsmount *old_mnt, const char *to);
63305 +int gr_acl_handle_rename(struct dentry *new_dentry,
63306 + struct dentry *parent_dentry,
63307 + const struct vfsmount *parent_mnt,
63308 + struct dentry *old_dentry,
63309 + struct inode *old_parent_inode,
63310 + struct vfsmount *old_mnt, const char *newname);
63311 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63312 + struct dentry *old_dentry,
63313 + struct dentry *new_dentry,
63314 + struct vfsmount *mnt, const __u8 replace);
63315 +__u32 gr_check_link(const struct dentry *new_dentry,
63316 + const struct dentry *parent_dentry,
63317 + const struct vfsmount *parent_mnt,
63318 + const struct dentry *old_dentry,
63319 + const struct vfsmount *old_mnt);
63320 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63321 + const unsigned int namelen, const ino_t ino);
63322 +
63323 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63324 + const struct vfsmount *mnt);
63325 +void gr_acl_handle_exit(void);
63326 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63327 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63328 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63329 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63330 +void gr_audit_ptrace(struct task_struct *task);
63331 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63332 +
63333 +#ifdef CONFIG_GRKERNSEC
63334 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63335 +void gr_handle_vm86(void);
63336 +void gr_handle_mem_readwrite(u64 from, u64 to);
63337 +
63338 +extern int grsec_enable_dmesg;
63339 +extern int grsec_disable_privio;
63340 +#endif
63341 +
63342 +#endif
63343 diff -urNp linux-2.6.39.1/include/linux/grsock.h linux-2.6.39.1/include/linux/grsock.h
63344 --- linux-2.6.39.1/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
63345 +++ linux-2.6.39.1/include/linux/grsock.h 2011-05-22 19:41:42.000000000 -0400
63346 @@ -0,0 +1,19 @@
63347 +#ifndef __GRSOCK_H
63348 +#define __GRSOCK_H
63349 +
63350 +extern void gr_attach_curr_ip(const struct sock *sk);
63351 +extern int gr_handle_sock_all(const int family, const int type,
63352 + const int protocol);
63353 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63354 +extern int gr_handle_sock_server_other(const struct sock *sck);
63355 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63356 +extern int gr_search_connect(struct socket * sock,
63357 + struct sockaddr_in * addr);
63358 +extern int gr_search_bind(struct socket * sock,
63359 + struct sockaddr_in * addr);
63360 +extern int gr_search_listen(struct socket * sock);
63361 +extern int gr_search_accept(struct socket * sock);
63362 +extern int gr_search_socket(const int domain, const int type,
63363 + const int protocol);
63364 +
63365 +#endif
63366 diff -urNp linux-2.6.39.1/include/linux/highmem.h linux-2.6.39.1/include/linux/highmem.h
63367 --- linux-2.6.39.1/include/linux/highmem.h 2011-05-19 00:06:34.000000000 -0400
63368 +++ linux-2.6.39.1/include/linux/highmem.h 2011-05-22 19:36:33.000000000 -0400
63369 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct
63370 kunmap_atomic(kaddr, KM_USER0);
63371 }
63372
63373 +static inline void sanitize_highpage(struct page *page)
63374 +{
63375 + void *kaddr;
63376 + unsigned long flags;
63377 +
63378 + local_irq_save(flags);
63379 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
63380 + clear_page(kaddr);
63381 + kunmap_atomic(kaddr, KM_CLEARPAGE);
63382 + local_irq_restore(flags);
63383 +}
63384 +
63385 static inline void zero_user_segments(struct page *page,
63386 unsigned start1, unsigned end1,
63387 unsigned start2, unsigned end2)
63388 diff -urNp linux-2.6.39.1/include/linux/i2o.h linux-2.6.39.1/include/linux/i2o.h
63389 --- linux-2.6.39.1/include/linux/i2o.h 2011-05-19 00:06:34.000000000 -0400
63390 +++ linux-2.6.39.1/include/linux/i2o.h 2011-05-22 19:36:33.000000000 -0400
63391 @@ -564,7 +564,7 @@ struct i2o_controller {
63392 struct i2o_device *exec; /* Executive */
63393 #if BITS_PER_LONG == 64
63394 spinlock_t context_list_lock; /* lock for context_list */
63395 - atomic_t context_list_counter; /* needed for unique contexts */
63396 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63397 struct list_head context_list; /* list of context id's
63398 and pointers */
63399 #endif
63400 diff -urNp linux-2.6.39.1/include/linux/if_phonet.h linux-2.6.39.1/include/linux/if_phonet.h
63401 --- linux-2.6.39.1/include/linux/if_phonet.h 2011-05-19 00:06:34.000000000 -0400
63402 +++ linux-2.6.39.1/include/linux/if_phonet.h 2011-05-22 19:36:33.000000000 -0400
63403 @@ -13,7 +13,7 @@
63404 #define PHONET_DEV_MTU PHONET_MAX_MTU
63405
63406 #ifdef __KERNEL__
63407 -extern struct header_ops phonet_header_ops;
63408 +extern const struct header_ops phonet_header_ops;
63409 #endif
63410
63411 #endif
63412 diff -urNp linux-2.6.39.1/include/linux/init.h linux-2.6.39.1/include/linux/init.h
63413 --- linux-2.6.39.1/include/linux/init.h 2011-05-19 00:06:34.000000000 -0400
63414 +++ linux-2.6.39.1/include/linux/init.h 2011-05-22 19:36:33.000000000 -0400
63415 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
63416
63417 /* Each module must use one module_init(). */
63418 #define module_init(initfn) \
63419 - static inline initcall_t __inittest(void) \
63420 + static inline __used initcall_t __inittest(void) \
63421 { return initfn; } \
63422 int init_module(void) __attribute__((alias(#initfn)));
63423
63424 /* This is only required if you want to be unloadable. */
63425 #define module_exit(exitfn) \
63426 - static inline exitcall_t __exittest(void) \
63427 + static inline __used exitcall_t __exittest(void) \
63428 { return exitfn; } \
63429 void cleanup_module(void) __attribute__((alias(#exitfn)));
63430
63431 diff -urNp linux-2.6.39.1/include/linux/init_task.h linux-2.6.39.1/include/linux/init_task.h
63432 --- linux-2.6.39.1/include/linux/init_task.h 2011-05-19 00:06:34.000000000 -0400
63433 +++ linux-2.6.39.1/include/linux/init_task.h 2011-05-22 19:36:33.000000000 -0400
63434 @@ -83,6 +83,12 @@ extern struct group_info init_groups;
63435 #define INIT_IDS
63436 #endif
63437
63438 +#ifdef CONFIG_X86
63439 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63440 +#else
63441 +#define INIT_TASK_THREAD_INFO
63442 +#endif
63443 +
63444 /*
63445 * Because of the reduced scope of CAP_SETPCAP when filesystem
63446 * capabilities are in effect, it is safe to allow CAP_SETPCAP to
63447 @@ -163,6 +169,7 @@ extern struct cred init_cred;
63448 RCU_INIT_POINTER(.cred, &init_cred), \
63449 .comm = "swapper", \
63450 .thread = INIT_THREAD, \
63451 + INIT_TASK_THREAD_INFO \
63452 .fs = &init_fs, \
63453 .files = &init_files, \
63454 .signal = &init_signals, \
63455 diff -urNp linux-2.6.39.1/include/linux/interrupt.h linux-2.6.39.1/include/linux/interrupt.h
63456 --- linux-2.6.39.1/include/linux/interrupt.h 2011-05-19 00:06:34.000000000 -0400
63457 +++ linux-2.6.39.1/include/linux/interrupt.h 2011-05-22 19:36:33.000000000 -0400
63458 @@ -422,7 +422,7 @@ enum
63459 /* map softirq index to softirq name. update 'softirq_to_name' in
63460 * kernel/softirq.c when adding a new softirq.
63461 */
63462 -extern char *softirq_to_name[NR_SOFTIRQS];
63463 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63464
63465 /* softirq mask and active fields moved to irq_cpustat_t in
63466 * asm/hardirq.h to get better cache usage. KAO
63467 @@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
63468
63469 struct softirq_action
63470 {
63471 - void (*action)(struct softirq_action *);
63472 + void (*action)(void);
63473 };
63474
63475 asmlinkage void do_softirq(void);
63476 asmlinkage void __do_softirq(void);
63477 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63478 +extern void open_softirq(int nr, void (*action)(void));
63479 extern void softirq_init(void);
63480 static inline void __raise_softirq_irqoff(unsigned int nr)
63481 {
63482 diff -urNp linux-2.6.39.1/include/linux/iommu.h linux-2.6.39.1/include/linux/iommu.h
63483 --- linux-2.6.39.1/include/linux/iommu.h 2011-05-19 00:06:34.000000000 -0400
63484 +++ linux-2.6.39.1/include/linux/iommu.h 2011-05-22 19:36:33.000000000 -0400
63485 @@ -49,7 +49,7 @@ struct iommu_ops {
63486
63487 #ifdef CONFIG_IOMMU_API
63488
63489 -extern void register_iommu(struct iommu_ops *ops);
63490 +extern void register_iommu(const struct iommu_ops *ops);
63491 extern bool iommu_found(void);
63492 extern struct iommu_domain *iommu_domain_alloc(void);
63493 extern void iommu_domain_free(struct iommu_domain *domain);
63494 diff -urNp linux-2.6.39.1/include/linux/ipmi.h linux-2.6.39.1/include/linux/ipmi.h
63495 --- linux-2.6.39.1/include/linux/ipmi.h 2011-05-19 00:06:34.000000000 -0400
63496 +++ linux-2.6.39.1/include/linux/ipmi.h 2011-05-22 19:36:33.000000000 -0400
63497 @@ -282,7 +282,7 @@ struct ipmi_user_hndl {
63498
63499 /* Create a new user of the IPMI layer on the given interface number. */
63500 int ipmi_create_user(unsigned int if_num,
63501 - struct ipmi_user_hndl *handler,
63502 + const struct ipmi_user_hndl *handler,
63503 void *handler_data,
63504 ipmi_user_t *user);
63505
63506 diff -urNp linux-2.6.39.1/include/linux/kallsyms.h linux-2.6.39.1/include/linux/kallsyms.h
63507 --- linux-2.6.39.1/include/linux/kallsyms.h 2011-05-19 00:06:34.000000000 -0400
63508 +++ linux-2.6.39.1/include/linux/kallsyms.h 2011-05-22 22:52:54.000000000 -0400
63509 @@ -15,7 +15,8 @@
63510
63511 struct module;
63512
63513 -#ifdef CONFIG_KALLSYMS
63514 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63515 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63516 /* Lookup the address for a symbol. Returns 0 if not found. */
63517 unsigned long kallsyms_lookup_name(const char *name);
63518
63519 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
63520 /* Stupid that this does nothing, but I didn't create this mess. */
63521 #define __print_symbol(fmt, addr)
63522 #endif /*CONFIG_KALLSYMS*/
63523 +#else /* when included by kallsyms.c, vsnprintf.c, or
63524 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63525 +extern void __print_symbol(const char *fmt, unsigned long address);
63526 +extern int sprint_backtrace(char *buffer, unsigned long address);
63527 +extern int sprint_symbol(char *buffer, unsigned long address);
63528 +const char *kallsyms_lookup(unsigned long addr,
63529 + unsigned long *symbolsize,
63530 + unsigned long *offset,
63531 + char **modname, char *namebuf);
63532 +#endif
63533
63534 /* This macro allows us to keep printk typechecking */
63535 static void __check_printsym_format(const char *fmt, ...)
63536 diff -urNp linux-2.6.39.1/include/linux/kgdb.h linux-2.6.39.1/include/linux/kgdb.h
63537 --- linux-2.6.39.1/include/linux/kgdb.h 2011-05-19 00:06:34.000000000 -0400
63538 +++ linux-2.6.39.1/include/linux/kgdb.h 2011-05-22 19:36:33.000000000 -0400
63539 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63540 extern int kgdb_io_module_registered;
63541
63542 extern atomic_t kgdb_setting_breakpoint;
63543 -extern atomic_t kgdb_cpu_doing_single_step;
63544 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63545
63546 extern struct task_struct *kgdb_usethread;
63547 extern struct task_struct *kgdb_contthread;
63548 @@ -269,22 +269,22 @@ struct kgdb_arch {
63549 */
63550 struct kgdb_io {
63551 const char *name;
63552 - int (*read_char) (void);
63553 - void (*write_char) (u8);
63554 - void (*flush) (void);
63555 - int (*init) (void);
63556 - void (*pre_exception) (void);
63557 - void (*post_exception) (void);
63558 + int (* const read_char) (void);
63559 + void (* const write_char) (u8);
63560 + void (* const flush) (void);
63561 + int (* const init) (void);
63562 + void (* const pre_exception) (void);
63563 + void (* const post_exception) (void);
63564 int is_console;
63565 };
63566
63567 -extern struct kgdb_arch arch_kgdb_ops;
63568 +extern const struct kgdb_arch arch_kgdb_ops;
63569
63570 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
63571
63572 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
63573 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
63574 -extern struct kgdb_io *dbg_io_ops;
63575 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
63576 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
63577 +extern const struct kgdb_io *dbg_io_ops;
63578
63579 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
63580 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
63581 diff -urNp linux-2.6.39.1/include/linux/kmod.h linux-2.6.39.1/include/linux/kmod.h
63582 --- linux-2.6.39.1/include/linux/kmod.h 2011-05-19 00:06:34.000000000 -0400
63583 +++ linux-2.6.39.1/include/linux/kmod.h 2011-05-22 19:41:42.000000000 -0400
63584 @@ -33,6 +33,8 @@ extern char modprobe_path[]; /* for sysc
63585 * usually useless though. */
63586 extern int __request_module(bool wait, const char *name, ...) \
63587 __attribute__((format(printf, 2, 3)));
63588 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
63589 + __attribute__((format(printf, 3, 4)));
63590 #define request_module(mod...) __request_module(true, mod)
63591 #define request_module_nowait(mod...) __request_module(false, mod)
63592 #define try_then_request_module(x, mod...) \
63593 diff -urNp linux-2.6.39.1/include/linux/kvm_host.h linux-2.6.39.1/include/linux/kvm_host.h
63594 --- linux-2.6.39.1/include/linux/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
63595 +++ linux-2.6.39.1/include/linux/kvm_host.h 2011-05-22 19:36:33.000000000 -0400
63596 @@ -302,7 +302,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
63597 void vcpu_load(struct kvm_vcpu *vcpu);
63598 void vcpu_put(struct kvm_vcpu *vcpu);
63599
63600 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63601 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63602 struct module *module);
63603 void kvm_exit(void);
63604
63605 @@ -442,7 +442,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
63606 struct kvm_guest_debug *dbg);
63607 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63608
63609 -int kvm_arch_init(void *opaque);
63610 +int kvm_arch_init(const void *opaque);
63611 void kvm_arch_exit(void);
63612
63613 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63614 diff -urNp linux-2.6.39.1/include/linux/lapb.h linux-2.6.39.1/include/linux/lapb.h
63615 --- linux-2.6.39.1/include/linux/lapb.h 2011-05-19 00:06:34.000000000 -0400
63616 +++ linux-2.6.39.1/include/linux/lapb.h 2011-05-22 19:36:33.000000000 -0400
63617 @@ -44,7 +44,7 @@ struct lapb_parms_struct {
63618 unsigned int mode;
63619 };
63620
63621 -extern int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks);
63622 +extern int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks);
63623 extern int lapb_unregister(struct net_device *dev);
63624 extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms);
63625 extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
63626 diff -urNp linux-2.6.39.1/include/linux/lcd.h linux-2.6.39.1/include/linux/lcd.h
63627 --- linux-2.6.39.1/include/linux/lcd.h 2011-05-19 00:06:34.000000000 -0400
63628 +++ linux-2.6.39.1/include/linux/lcd.h 2011-05-22 19:36:33.000000000 -0400
63629 @@ -60,7 +60,7 @@ struct lcd_device {
63630 points to something in the body of that driver, it is also invalid. */
63631 struct mutex ops_lock;
63632 /* If this is NULL, the backing module is unloaded */
63633 - struct lcd_ops *ops;
63634 + const struct lcd_ops *ops;
63635 /* Serialise access to set_power method */
63636 struct mutex update_lock;
63637 /* The framebuffer notifier block */
63638 @@ -101,7 +101,7 @@ static inline void lcd_set_power(struct
63639 }
63640
63641 extern struct lcd_device *lcd_device_register(const char *name,
63642 - struct device *parent, void *devdata, struct lcd_ops *ops);
63643 + struct device *parent, void *devdata, const struct lcd_ops *ops);
63644 extern void lcd_device_unregister(struct lcd_device *ld);
63645
63646 #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
63647 diff -urNp linux-2.6.39.1/include/linux/libata.h linux-2.6.39.1/include/linux/libata.h
63648 --- linux-2.6.39.1/include/linux/libata.h 2011-05-19 00:06:34.000000000 -0400
63649 +++ linux-2.6.39.1/include/linux/libata.h 2011-05-22 19:36:33.000000000 -0400
63650 @@ -524,11 +524,11 @@ struct ata_ioports {
63651
63652 struct ata_host {
63653 spinlock_t lock;
63654 - struct device *dev;
63655 + struct device *dev;
63656 void __iomem * const *iomap;
63657 unsigned int n_ports;
63658 void *private_data;
63659 - struct ata_port_operations *ops;
63660 + const struct ata_port_operations *ops;
63661 unsigned long flags;
63662
63663 struct mutex eh_mutex;
63664 @@ -719,7 +719,7 @@ struct ata_link {
63665
63666 struct ata_port {
63667 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
63668 - struct ata_port_operations *ops;
63669 + const struct ata_port_operations *ops;
63670 spinlock_t *lock;
63671 /* Flags owned by the EH context. Only EH should touch these once the
63672 port is active */
63673 @@ -907,7 +907,7 @@ struct ata_port_info {
63674 unsigned long pio_mask;
63675 unsigned long mwdma_mask;
63676 unsigned long udma_mask;
63677 - struct ata_port_operations *port_ops;
63678 + const struct ata_port_operations *port_ops;
63679 void *private_data;
63680 };
63681
63682 @@ -931,7 +931,7 @@ extern const unsigned long sata_deb_timi
63683 extern const unsigned long sata_deb_timing_hotplug[];
63684 extern const unsigned long sata_deb_timing_long[];
63685
63686 -extern struct ata_port_operations ata_dummy_port_ops;
63687 +extern const struct ata_port_operations ata_dummy_port_ops;
63688 extern const struct ata_port_info ata_dummy_port_info;
63689
63690 static inline const unsigned long *
63691 @@ -977,7 +977,7 @@ extern int ata_host_activate(struct ata_
63692 struct scsi_host_template *sht);
63693 extern void ata_host_detach(struct ata_host *host);
63694 extern void ata_host_init(struct ata_host *, struct device *,
63695 - unsigned long, struct ata_port_operations *);
63696 + unsigned long, const struct ata_port_operations *);
63697 extern int ata_scsi_detect(struct scsi_host_template *sht);
63698 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
63699 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
63700 diff -urNp linux-2.6.39.1/include/linux/lockd/bind.h linux-2.6.39.1/include/linux/lockd/bind.h
63701 --- linux-2.6.39.1/include/linux/lockd/bind.h 2011-05-19 00:06:34.000000000 -0400
63702 +++ linux-2.6.39.1/include/linux/lockd/bind.h 2011-05-22 19:36:33.000000000 -0400
63703 @@ -23,13 +23,13 @@ struct svc_rqst;
63704 * This is the set of functions for lockd->nfsd communication
63705 */
63706 struct nlmsvc_binding {
63707 - __be32 (*fopen)(struct svc_rqst *,
63708 + __be32 (* const fopen)(struct svc_rqst *,
63709 struct nfs_fh *,
63710 struct file **);
63711 - void (*fclose)(struct file *);
63712 + void (* const fclose)(struct file *);
63713 };
63714
63715 -extern struct nlmsvc_binding * nlmsvc_ops;
63716 +extern const struct nlmsvc_binding * nlmsvc_ops;
63717
63718 /*
63719 * Similar to nfs_client_initdata, but without the NFS-specific
63720 diff -urNp linux-2.6.39.1/include/linux/mfd/abx500.h linux-2.6.39.1/include/linux/mfd/abx500.h
63721 --- linux-2.6.39.1/include/linux/mfd/abx500.h 2011-05-19 00:06:34.000000000 -0400
63722 +++ linux-2.6.39.1/include/linux/mfd/abx500.h 2011-05-22 19:36:33.000000000 -0400
63723 @@ -227,6 +227,6 @@ struct abx500_ops {
63724 int (*startup_irq_enabled) (struct device *, unsigned int);
63725 };
63726
63727 -int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63728 +int abx500_register_ops(struct device *core_dev, const struct abx500_ops *ops);
63729 void abx500_remove_ops(struct device *dev);
63730 #endif
63731 diff -urNp linux-2.6.39.1/include/linux/mm.h linux-2.6.39.1/include/linux/mm.h
63732 --- linux-2.6.39.1/include/linux/mm.h 2011-05-19 00:06:34.000000000 -0400
63733 +++ linux-2.6.39.1/include/linux/mm.h 2011-05-22 19:36:33.000000000 -0400
63734 @@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
63735
63736 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63737 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63738 +
63739 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63740 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63741 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63742 +#else
63743 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63744 +#endif
63745 +
63746 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63747 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63748
63749 @@ -1010,34 +1017,6 @@ int set_page_dirty(struct page *page);
63750 int set_page_dirty_lock(struct page *page);
63751 int clear_page_dirty_for_io(struct page *page);
63752
63753 -/* Is the vma a continuation of the stack vma above it? */
63754 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63755 -{
63756 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63757 -}
63758 -
63759 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63760 - unsigned long addr)
63761 -{
63762 - return (vma->vm_flags & VM_GROWSDOWN) &&
63763 - (vma->vm_start == addr) &&
63764 - !vma_growsdown(vma->vm_prev, addr);
63765 -}
63766 -
63767 -/* Is the vma a continuation of the stack vma below it? */
63768 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63769 -{
63770 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63771 -}
63772 -
63773 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63774 - unsigned long addr)
63775 -{
63776 - return (vma->vm_flags & VM_GROWSUP) &&
63777 - (vma->vm_end == addr) &&
63778 - !vma_growsup(vma->vm_next, addr);
63779 -}
63780 -
63781 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63782 unsigned long old_addr, struct vm_area_struct *new_vma,
63783 unsigned long new_addr, unsigned long len);
63784 @@ -1189,6 +1168,15 @@ struct shrinker {
63785 extern void register_shrinker(struct shrinker *);
63786 extern void unregister_shrinker(struct shrinker *);
63787
63788 +#ifdef CONFIG_MMU
63789 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
63790 +#else
63791 +static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63792 +{
63793 + return __pgprot(0);
63794 +}
63795 +#endif
63796 +
63797 int vma_wants_writenotify(struct vm_area_struct *vma);
63798
63799 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63800 @@ -1476,6 +1464,7 @@ out:
63801 }
63802
63803 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63804 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63805
63806 extern unsigned long do_brk(unsigned long, unsigned long);
63807
63808 @@ -1532,6 +1521,10 @@ extern struct vm_area_struct * find_vma(
63809 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63810 struct vm_area_struct **pprev);
63811
63812 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63813 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63814 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63815 +
63816 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63817 NULL if none. Assume start_addr < end_addr. */
63818 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63819 @@ -1548,15 +1541,6 @@ static inline unsigned long vma_pages(st
63820 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63821 }
63822
63823 -#ifdef CONFIG_MMU
63824 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63825 -#else
63826 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63827 -{
63828 - return __pgprot(0);
63829 -}
63830 -#endif
63831 -
63832 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63833 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63834 unsigned long pfn, unsigned long size, pgprot_t);
63835 @@ -1668,7 +1652,7 @@ extern int unpoison_memory(unsigned long
63836 extern int sysctl_memory_failure_early_kill;
63837 extern int sysctl_memory_failure_recovery;
63838 extern void shake_page(struct page *p, int access);
63839 -extern atomic_long_t mce_bad_pages;
63840 +extern atomic_long_unchecked_t mce_bad_pages;
63841 extern int soft_offline_page(struct page *page, int flags);
63842
63843 extern void dump_page(struct page *page);
63844 @@ -1682,5 +1666,11 @@ extern void copy_user_huge_page(struct p
63845 unsigned int pages_per_huge_page);
63846 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
63847
63848 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63849 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63850 +#else
63851 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63852 +#endif
63853 +
63854 #endif /* __KERNEL__ */
63855 #endif /* _LINUX_MM_H */
63856 diff -urNp linux-2.6.39.1/include/linux/mm_types.h linux-2.6.39.1/include/linux/mm_types.h
63857 --- linux-2.6.39.1/include/linux/mm_types.h 2011-05-19 00:06:34.000000000 -0400
63858 +++ linux-2.6.39.1/include/linux/mm_types.h 2011-05-22 19:36:33.000000000 -0400
63859 @@ -183,6 +183,8 @@ struct vm_area_struct {
63860 #ifdef CONFIG_NUMA
63861 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63862 #endif
63863 +
63864 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63865 };
63866
63867 struct core_thread {
63868 @@ -317,6 +319,24 @@ struct mm_struct {
63869 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63870 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
63871 #endif
63872 +
63873 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63874 + unsigned long pax_flags;
63875 +#endif
63876 +
63877 +#ifdef CONFIG_PAX_DLRESOLVE
63878 + unsigned long call_dl_resolve;
63879 +#endif
63880 +
63881 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63882 + unsigned long call_syscall;
63883 +#endif
63884 +
63885 +#ifdef CONFIG_PAX_ASLR
63886 + unsigned long delta_mmap; /* randomized offset */
63887 + unsigned long delta_stack; /* randomized offset */
63888 +#endif
63889 +
63890 };
63891
63892 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
63893 diff -urNp linux-2.6.39.1/include/linux/mmu_notifier.h linux-2.6.39.1/include/linux/mmu_notifier.h
63894 --- linux-2.6.39.1/include/linux/mmu_notifier.h 2011-05-19 00:06:34.000000000 -0400
63895 +++ linux-2.6.39.1/include/linux/mmu_notifier.h 2011-05-22 19:36:33.000000000 -0400
63896 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
63897 */
63898 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63899 ({ \
63900 - pte_t __pte; \
63901 + pte_t ___pte; \
63902 struct vm_area_struct *___vma = __vma; \
63903 unsigned long ___address = __address; \
63904 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63905 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63906 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63907 - __pte; \
63908 + ___pte; \
63909 })
63910
63911 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63912 diff -urNp linux-2.6.39.1/include/linux/mmzone.h linux-2.6.39.1/include/linux/mmzone.h
63913 --- linux-2.6.39.1/include/linux/mmzone.h 2011-05-19 00:06:34.000000000 -0400
63914 +++ linux-2.6.39.1/include/linux/mmzone.h 2011-05-22 19:36:33.000000000 -0400
63915 @@ -355,7 +355,7 @@ struct zone {
63916 unsigned long flags; /* zone flags, see below */
63917
63918 /* Zone statistics */
63919 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63920 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63921
63922 /*
63923 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63924 diff -urNp linux-2.6.39.1/include/linux/mod_devicetable.h linux-2.6.39.1/include/linux/mod_devicetable.h
63925 --- linux-2.6.39.1/include/linux/mod_devicetable.h 2011-05-19 00:06:34.000000000 -0400
63926 +++ linux-2.6.39.1/include/linux/mod_devicetable.h 2011-05-22 19:36:33.000000000 -0400
63927 @@ -12,7 +12,7 @@
63928 typedef unsigned long kernel_ulong_t;
63929 #endif
63930
63931 -#define PCI_ANY_ID (~0)
63932 +#define PCI_ANY_ID ((__u16)~0)
63933
63934 struct pci_device_id {
63935 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63936 @@ -131,7 +131,7 @@ struct usb_device_id {
63937 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63938 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63939
63940 -#define HID_ANY_ID (~0)
63941 +#define HID_ANY_ID (~0U)
63942
63943 struct hid_device_id {
63944 __u16 bus;
63945 diff -urNp linux-2.6.39.1/include/linux/module.h linux-2.6.39.1/include/linux/module.h
63946 --- linux-2.6.39.1/include/linux/module.h 2011-05-19 00:06:34.000000000 -0400
63947 +++ linux-2.6.39.1/include/linux/module.h 2011-05-22 19:36:33.000000000 -0400
63948 @@ -324,19 +324,16 @@ struct module
63949 int (*init)(void);
63950
63951 /* If this is non-NULL, vfree after init() returns */
63952 - void *module_init;
63953 + void *module_init_rx, *module_init_rw;
63954
63955 /* Here is the actual code + data, vfree'd on unload. */
63956 - void *module_core;
63957 + void *module_core_rx, *module_core_rw;
63958
63959 /* Here are the sizes of the init and core sections */
63960 - unsigned int init_size, core_size;
63961 + unsigned int init_size_rw, core_size_rw;
63962
63963 /* The size of the executable code in each section. */
63964 - unsigned int init_text_size, core_text_size;
63965 -
63966 - /* Size of RO sections of the module (text+rodata) */
63967 - unsigned int init_ro_size, core_ro_size;
63968 + unsigned int init_size_rx, core_size_rx;
63969
63970 /* Arch-specific module values */
63971 struct mod_arch_specific arch;
63972 @@ -441,16 +438,46 @@ bool is_module_address(unsigned long add
63973 bool is_module_percpu_address(unsigned long addr);
63974 bool is_module_text_address(unsigned long addr);
63975
63976 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63977 +{
63978 +
63979 +#ifdef CONFIG_PAX_KERNEXEC
63980 + if (ktla_ktva(addr) >= (unsigned long)start &&
63981 + ktla_ktva(addr) < (unsigned long)start + size)
63982 + return 1;
63983 +#endif
63984 +
63985 + return ((void *)addr >= start && (void *)addr < start + size);
63986 +}
63987 +
63988 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63989 +{
63990 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63991 +}
63992 +
63993 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63994 +{
63995 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63996 +}
63997 +
63998 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63999 +{
64000 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64001 +}
64002 +
64003 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64004 +{
64005 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64006 +}
64007 +
64008 static inline int within_module_core(unsigned long addr, struct module *mod)
64009 {
64010 - return (unsigned long)mod->module_core <= addr &&
64011 - addr < (unsigned long)mod->module_core + mod->core_size;
64012 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64013 }
64014
64015 static inline int within_module_init(unsigned long addr, struct module *mod)
64016 {
64017 - return (unsigned long)mod->module_init <= addr &&
64018 - addr < (unsigned long)mod->module_init + mod->init_size;
64019 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64020 }
64021
64022 /* Search for module by name: must hold module_mutex. */
64023 diff -urNp linux-2.6.39.1/include/linux/moduleloader.h linux-2.6.39.1/include/linux/moduleloader.h
64024 --- linux-2.6.39.1/include/linux/moduleloader.h 2011-05-19 00:06:34.000000000 -0400
64025 +++ linux-2.6.39.1/include/linux/moduleloader.h 2011-05-22 19:36:33.000000000 -0400
64026 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
64027 sections. Returns NULL on failure. */
64028 void *module_alloc(unsigned long size);
64029
64030 +#ifdef CONFIG_PAX_KERNEXEC
64031 +void *module_alloc_exec(unsigned long size);
64032 +#else
64033 +#define module_alloc_exec(x) module_alloc(x)
64034 +#endif
64035 +
64036 /* Free memory returned from module_alloc. */
64037 void module_free(struct module *mod, void *module_region);
64038
64039 +#ifdef CONFIG_PAX_KERNEXEC
64040 +void module_free_exec(struct module *mod, void *module_region);
64041 +#else
64042 +#define module_free_exec(x, y) module_free((x), (y))
64043 +#endif
64044 +
64045 /* Apply the given relocation to the (simplified) ELF. Return -error
64046 or 0. */
64047 int apply_relocate(Elf_Shdr *sechdrs,
64048 diff -urNp linux-2.6.39.1/include/linux/moduleparam.h linux-2.6.39.1/include/linux/moduleparam.h
64049 --- linux-2.6.39.1/include/linux/moduleparam.h 2011-05-19 00:06:34.000000000 -0400
64050 +++ linux-2.6.39.1/include/linux/moduleparam.h 2011-05-22 19:36:33.000000000 -0400
64051 @@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
64052 * @len is usually just sizeof(string).
64053 */
64054 #define module_param_string(name, string, len, perm) \
64055 - static const struct kparam_string __param_string_##name \
64056 + static const struct kparam_string __param_string_##name __used \
64057 = { len, string }; \
64058 __module_param_call(MODULE_PARAM_PREFIX, name, \
64059 &param_ops_string, \
64060 @@ -285,48 +285,48 @@ static inline void destroy_params(const
64061 #define __param_check(name, p, type) \
64062 static inline type *__check_##name(void) { return(p); }
64063
64064 -extern struct kernel_param_ops param_ops_byte;
64065 +extern const struct kernel_param_ops param_ops_byte;
64066 extern int param_set_byte(const char *val, const struct kernel_param *kp);
64067 extern int param_get_byte(char *buffer, const struct kernel_param *kp);
64068 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
64069
64070 -extern struct kernel_param_ops param_ops_short;
64071 +extern const struct kernel_param_ops param_ops_short;
64072 extern int param_set_short(const char *val, const struct kernel_param *kp);
64073 extern int param_get_short(char *buffer, const struct kernel_param *kp);
64074 #define param_check_short(name, p) __param_check(name, p, short)
64075
64076 -extern struct kernel_param_ops param_ops_ushort;
64077 +extern const struct kernel_param_ops param_ops_ushort;
64078 extern int param_set_ushort(const char *val, const struct kernel_param *kp);
64079 extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
64080 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
64081
64082 -extern struct kernel_param_ops param_ops_int;
64083 +extern const struct kernel_param_ops param_ops_int;
64084 extern int param_set_int(const char *val, const struct kernel_param *kp);
64085 extern int param_get_int(char *buffer, const struct kernel_param *kp);
64086 #define param_check_int(name, p) __param_check(name, p, int)
64087
64088 -extern struct kernel_param_ops param_ops_uint;
64089 +extern const struct kernel_param_ops param_ops_uint;
64090 extern int param_set_uint(const char *val, const struct kernel_param *kp);
64091 extern int param_get_uint(char *buffer, const struct kernel_param *kp);
64092 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
64093
64094 -extern struct kernel_param_ops param_ops_long;
64095 +extern const struct kernel_param_ops param_ops_long;
64096 extern int param_set_long(const char *val, const struct kernel_param *kp);
64097 extern int param_get_long(char *buffer, const struct kernel_param *kp);
64098 #define param_check_long(name, p) __param_check(name, p, long)
64099
64100 -extern struct kernel_param_ops param_ops_ulong;
64101 +extern const struct kernel_param_ops param_ops_ulong;
64102 extern int param_set_ulong(const char *val, const struct kernel_param *kp);
64103 extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
64104 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
64105
64106 -extern struct kernel_param_ops param_ops_charp;
64107 +extern const struct kernel_param_ops param_ops_charp;
64108 extern int param_set_charp(const char *val, const struct kernel_param *kp);
64109 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
64110 #define param_check_charp(name, p) __param_check(name, p, char *)
64111
64112 /* For historical reasons "bool" parameters can be (unsigned) "int". */
64113 -extern struct kernel_param_ops param_ops_bool;
64114 +extern const struct kernel_param_ops param_ops_bool;
64115 extern int param_set_bool(const char *val, const struct kernel_param *kp);
64116 extern int param_get_bool(char *buffer, const struct kernel_param *kp);
64117 #define param_check_bool(name, p) \
64118 @@ -337,7 +337,7 @@ extern int param_get_bool(char *buffer,
64119 !__same_type((p), int *)); \
64120 }
64121
64122 -extern struct kernel_param_ops param_ops_invbool;
64123 +extern const struct kernel_param_ops param_ops_invbool;
64124 extern int param_set_invbool(const char *val, const struct kernel_param *kp);
64125 extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
64126 #define param_check_invbool(name, p) __param_check(name, p, bool)
64127 @@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
64128 * module_param_named() for why this might be necessary.
64129 */
64130 #define module_param_array_named(name, array, type, nump, perm) \
64131 - static const struct kparam_array __param_arr_##name \
64132 + static const struct kparam_array __param_arr_##name __used \
64133 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
64134 sizeof(array[0]), array }; \
64135 __module_param_call(MODULE_PARAM_PREFIX, name, \
64136 @@ -379,9 +379,9 @@ extern int param_get_invbool(char *buffe
64137 __same_type(array[0], bool), perm); \
64138 __MODULE_PARM_TYPE(name, "array of " #type)
64139
64140 -extern struct kernel_param_ops param_array_ops;
64141 +extern const struct kernel_param_ops param_array_ops;
64142
64143 -extern struct kernel_param_ops param_ops_string;
64144 +extern const struct kernel_param_ops param_ops_string;
64145 extern int param_set_copystring(const char *val, const struct kernel_param *);
64146 extern int param_get_string(char *buffer, const struct kernel_param *kp);
64147
64148 diff -urNp linux-2.6.39.1/include/linux/mutex.h linux-2.6.39.1/include/linux/mutex.h
64149 --- linux-2.6.39.1/include/linux/mutex.h 2011-05-19 00:06:34.000000000 -0400
64150 +++ linux-2.6.39.1/include/linux/mutex.h 2011-05-22 19:36:33.000000000 -0400
64151 @@ -51,7 +51,7 @@ struct mutex {
64152 spinlock_t wait_lock;
64153 struct list_head wait_list;
64154 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
64155 - struct thread_info *owner;
64156 + struct task_struct *owner;
64157 #endif
64158 #ifdef CONFIG_DEBUG_MUTEXES
64159 const char *name;
64160 diff -urNp linux-2.6.39.1/include/linux/namei.h linux-2.6.39.1/include/linux/namei.h
64161 --- linux-2.6.39.1/include/linux/namei.h 2011-05-19 00:06:34.000000000 -0400
64162 +++ linux-2.6.39.1/include/linux/namei.h 2011-05-22 19:36:33.000000000 -0400
64163 @@ -24,7 +24,7 @@ struct nameidata {
64164 unsigned seq;
64165 int last_type;
64166 unsigned depth;
64167 - char *saved_names[MAX_NESTED_LINKS + 1];
64168 + const char *saved_names[MAX_NESTED_LINKS + 1];
64169
64170 /* Intent data */
64171 union {
64172 @@ -91,12 +91,12 @@ extern int follow_up(struct path *);
64173 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
64174 extern void unlock_rename(struct dentry *, struct dentry *);
64175
64176 -static inline void nd_set_link(struct nameidata *nd, char *path)
64177 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64178 {
64179 nd->saved_names[nd->depth] = path;
64180 }
64181
64182 -static inline char *nd_get_link(struct nameidata *nd)
64183 +static inline const char *nd_get_link(const struct nameidata *nd)
64184 {
64185 return nd->saved_names[nd->depth];
64186 }
64187 diff -urNp linux-2.6.39.1/include/linux/netfilter/xt_gradm.h linux-2.6.39.1/include/linux/netfilter/xt_gradm.h
64188 --- linux-2.6.39.1/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
64189 +++ linux-2.6.39.1/include/linux/netfilter/xt_gradm.h 2011-05-22 19:41:42.000000000 -0400
64190 @@ -0,0 +1,9 @@
64191 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64192 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64193 +
64194 +struct xt_gradm_mtinfo {
64195 + __u16 flags;
64196 + __u16 invflags;
64197 +};
64198 +
64199 +#endif
64200 diff -urNp linux-2.6.39.1/include/linux/oprofile.h linux-2.6.39.1/include/linux/oprofile.h
64201 --- linux-2.6.39.1/include/linux/oprofile.h 2011-05-19 00:06:34.000000000 -0400
64202 +++ linux-2.6.39.1/include/linux/oprofile.h 2011-05-22 19:36:33.000000000 -0400
64203 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
64204 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64205 char const * name, ulong * val);
64206
64207 -/** Create a file for read-only access to an atomic_t. */
64208 +/** Create a file for read-only access to an atomic_unchecked_t. */
64209 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64210 - char const * name, atomic_t * val);
64211 + char const * name, atomic_unchecked_t * val);
64212
64213 /** create a directory */
64214 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64215 diff -urNp linux-2.6.39.1/include/linux/padata.h linux-2.6.39.1/include/linux/padata.h
64216 --- linux-2.6.39.1/include/linux/padata.h 2011-05-19 00:06:34.000000000 -0400
64217 +++ linux-2.6.39.1/include/linux/padata.h 2011-05-22 19:36:33.000000000 -0400
64218 @@ -129,7 +129,7 @@ struct parallel_data {
64219 struct padata_instance *pinst;
64220 struct padata_parallel_queue __percpu *pqueue;
64221 struct padata_serial_queue __percpu *squeue;
64222 - atomic_t seq_nr;
64223 + atomic_unchecked_t seq_nr;
64224 atomic_t reorder_objects;
64225 atomic_t refcnt;
64226 unsigned int max_seq_nr;
64227 diff -urNp linux-2.6.39.1/include/linux/pci.h linux-2.6.39.1/include/linux/pci.h
64228 --- linux-2.6.39.1/include/linux/pci.h 2011-05-19 00:06:34.000000000 -0400
64229 +++ linux-2.6.39.1/include/linux/pci.h 2011-05-22 19:36:33.000000000 -0400
64230 @@ -411,7 +411,7 @@ struct pci_bus {
64231 struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
64232 struct list_head resources; /* address space routed to this bus */
64233
64234 - struct pci_ops *ops; /* configuration access functions */
64235 + const struct pci_ops *ops; /* configuration access functions */
64236 void *sysdata; /* hook for sys-specific extension */
64237 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
64238
64239 @@ -550,7 +550,7 @@ struct pci_driver {
64240 int (*resume_early) (struct pci_dev *dev);
64241 int (*resume) (struct pci_dev *dev); /* Device woken up */
64242 void (*shutdown) (struct pci_dev *dev);
64243 - struct pci_error_handlers *err_handler;
64244 + const struct pci_error_handlers *err_handler;
64245 struct device_driver driver;
64246 struct pci_dynids dynids;
64247 };
64248 @@ -639,7 +639,7 @@ void pcibios_scan_specific_bus(int busn)
64249 extern struct pci_bus *pci_find_bus(int domain, int busnr);
64250 void pci_bus_add_devices(const struct pci_bus *bus);
64251 struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
64252 - struct pci_ops *ops, void *sysdata);
64253 + const struct pci_ops *ops, void *sysdata);
64254 static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,
64255 void *sysdata)
64256 {
64257 @@ -650,7 +650,7 @@ static inline struct pci_bus * __devinit
64258 return root_bus;
64259 }
64260 struct pci_bus *pci_create_bus(struct device *parent, int bus,
64261 - struct pci_ops *ops, void *sysdata);
64262 + const struct pci_ops *ops, void *sysdata);
64263 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
64264 int busnr);
64265 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
64266 @@ -727,7 +727,7 @@ int pci_bus_write_config_word(struct pci
64267 int where, u16 val);
64268 int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
64269 int where, u32 val);
64270 -struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
64271 +const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops);
64272
64273 static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
64274 {
64275 diff -urNp linux-2.6.39.1/include/linux/perf_event.h linux-2.6.39.1/include/linux/perf_event.h
64276 --- linux-2.6.39.1/include/linux/perf_event.h 2011-05-19 00:06:34.000000000 -0400
64277 +++ linux-2.6.39.1/include/linux/perf_event.h 2011-05-22 19:36:33.000000000 -0400
64278 @@ -759,8 +759,8 @@ struct perf_event {
64279
64280 enum perf_event_active_state state;
64281 unsigned int attach_state;
64282 - local64_t count;
64283 - atomic64_t child_count;
64284 + local64_t count; /* PaX: fix it one day */
64285 + atomic64_unchecked_t child_count;
64286
64287 /*
64288 * These are the total time in nanoseconds that the event
64289 @@ -811,8 +811,8 @@ struct perf_event {
64290 * These accumulate total time (in nanoseconds) that children
64291 * events have been enabled and running, respectively.
64292 */
64293 - atomic64_t child_total_time_enabled;
64294 - atomic64_t child_total_time_running;
64295 + atomic64_unchecked_t child_total_time_enabled;
64296 + atomic64_unchecked_t child_total_time_running;
64297
64298 /*
64299 * Protect attach/detach and child_list:
64300 @@ -1090,9 +1090,9 @@ void perf_event_task_sched_out(struct ta
64301 }
64302
64303 extern void perf_event_mmap(struct vm_area_struct *vma);
64304 -extern struct perf_guest_info_callbacks *perf_guest_cbs;
64305 -extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64306 -extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64307 +extern const struct perf_guest_info_callbacks *perf_guest_cbs;
64308 +extern int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64309 +extern int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64310
64311 extern void perf_event_comm(struct task_struct *tsk);
64312 extern void perf_event_fork(struct task_struct *tsk);
64313 diff -urNp linux-2.6.39.1/include/linux/pipe_fs_i.h linux-2.6.39.1/include/linux/pipe_fs_i.h
64314 --- linux-2.6.39.1/include/linux/pipe_fs_i.h 2011-05-19 00:06:34.000000000 -0400
64315 +++ linux-2.6.39.1/include/linux/pipe_fs_i.h 2011-05-22 19:36:33.000000000 -0400
64316 @@ -46,9 +46,9 @@ struct pipe_buffer {
64317 struct pipe_inode_info {
64318 wait_queue_head_t wait;
64319 unsigned int nrbufs, curbuf, buffers;
64320 - unsigned int readers;
64321 - unsigned int writers;
64322 - unsigned int waiting_writers;
64323 + atomic_t readers;
64324 + atomic_t writers;
64325 + atomic_t waiting_writers;
64326 unsigned int r_counter;
64327 unsigned int w_counter;
64328 struct page *tmp_page;
64329 diff -urNp linux-2.6.39.1/include/linux/pm.h linux-2.6.39.1/include/linux/pm.h
64330 --- linux-2.6.39.1/include/linux/pm.h 2011-05-19 00:06:34.000000000 -0400
64331 +++ linux-2.6.39.1/include/linux/pm.h 2011-05-22 19:36:33.000000000 -0400
64332 @@ -268,7 +268,7 @@ const struct dev_pm_ops name = { \
64333 * runtime PM, make the pm member point to generic_subsys_pm_ops.
64334 */
64335 #ifdef CONFIG_PM
64336 -extern struct dev_pm_ops generic_subsys_pm_ops;
64337 +extern const struct dev_pm_ops generic_subsys_pm_ops;
64338 #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
64339 #else
64340 #define GENERIC_SUBSYS_PM_OPS NULL
64341 @@ -471,7 +471,7 @@ extern void update_pm_runtime_accounting
64342 * subsystem-level and driver-level callbacks.
64343 */
64344 struct dev_power_domain {
64345 - struct dev_pm_ops ops;
64346 + const struct dev_pm_ops ops;
64347 };
64348
64349 /*
64350 diff -urNp linux-2.6.39.1/include/linux/pm_runtime.h linux-2.6.39.1/include/linux/pm_runtime.h
64351 --- linux-2.6.39.1/include/linux/pm_runtime.h 2011-05-19 00:06:34.000000000 -0400
64352 +++ linux-2.6.39.1/include/linux/pm_runtime.h 2011-05-22 19:36:33.000000000 -0400
64353 @@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
64354
64355 static inline void pm_runtime_mark_last_busy(struct device *dev)
64356 {
64357 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64358 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64359 }
64360
64361 #else /* !CONFIG_PM_RUNTIME */
64362 diff -urNp linux-2.6.39.1/include/linux/poison.h linux-2.6.39.1/include/linux/poison.h
64363 --- linux-2.6.39.1/include/linux/poison.h 2011-05-19 00:06:34.000000000 -0400
64364 +++ linux-2.6.39.1/include/linux/poison.h 2011-05-22 19:36:33.000000000 -0400
64365 @@ -19,8 +19,8 @@
64366 * under normal circumstances, used to verify that nobody uses
64367 * non-initialized list entries.
64368 */
64369 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64370 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64371 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64372 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64373
64374 /********** include/linux/timer.h **********/
64375 /*
64376 diff -urNp linux-2.6.39.1/include/linux/posix-timers.h linux-2.6.39.1/include/linux/posix-timers.h
64377 --- linux-2.6.39.1/include/linux/posix-timers.h 2011-05-19 00:06:34.000000000 -0400
64378 +++ linux-2.6.39.1/include/linux/posix-timers.h 2011-05-22 19:36:33.000000000 -0400
64379 @@ -102,10 +102,10 @@ struct k_clock {
64380 struct itimerspec * cur_setting);
64381 };
64382
64383 -extern struct k_clock clock_posix_cpu;
64384 -extern struct k_clock clock_posix_dynamic;
64385 +extern const struct k_clock clock_posix_cpu;
64386 +extern const struct k_clock clock_posix_dynamic;
64387
64388 -void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
64389 +void posix_timers_register_clock(const clockid_t clock_id, const struct k_clock *new_clock);
64390
64391 /* function to call to trigger timer event */
64392 int posix_timer_event(struct k_itimer *timr, int si_private);
64393 diff -urNp linux-2.6.39.1/include/linux/proc_fs.h linux-2.6.39.1/include/linux/proc_fs.h
64394 --- linux-2.6.39.1/include/linux/proc_fs.h 2011-05-19 00:06:34.000000000 -0400
64395 +++ linux-2.6.39.1/include/linux/proc_fs.h 2011-05-22 19:41:42.000000000 -0400
64396 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
64397 return proc_create_data(name, mode, parent, proc_fops, NULL);
64398 }
64399
64400 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
64401 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64402 +{
64403 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64404 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64405 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64406 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64407 +#else
64408 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64409 +#endif
64410 +}
64411 +
64412 +
64413 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64414 mode_t mode, struct proc_dir_entry *base,
64415 read_proc_t *read_proc, void * data)
64416 diff -urNp linux-2.6.39.1/include/linux/ptrace.h linux-2.6.39.1/include/linux/ptrace.h
64417 --- linux-2.6.39.1/include/linux/ptrace.h 2011-05-19 00:06:34.000000000 -0400
64418 +++ linux-2.6.39.1/include/linux/ptrace.h 2011-05-22 19:41:42.000000000 -0400
64419 @@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
64420 extern void exit_ptrace(struct task_struct *tracer);
64421 #define PTRACE_MODE_READ 1
64422 #define PTRACE_MODE_ATTACH 2
64423 -/* Returns 0 on success, -errno on denial. */
64424 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
64425 /* Returns true on success, false on denial. */
64426 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
64427 +/* Returns true on success, false on denial. */
64428 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
64429
64430 static inline int ptrace_reparented(struct task_struct *child)
64431 {
64432 diff -urNp linux-2.6.39.1/include/linux/random.h linux-2.6.39.1/include/linux/random.h
64433 --- linux-2.6.39.1/include/linux/random.h 2011-05-19 00:06:34.000000000 -0400
64434 +++ linux-2.6.39.1/include/linux/random.h 2011-05-22 19:36:33.000000000 -0400
64435 @@ -80,12 +80,17 @@ void srandom32(u32 seed);
64436
64437 u32 prandom32(struct rnd_state *);
64438
64439 +static inline unsigned long pax_get_random_long(void)
64440 +{
64441 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64442 +}
64443 +
64444 /*
64445 * Handle minimum values for seeds
64446 */
64447 static inline u32 __seed(u32 x, u32 m)
64448 {
64449 - return (x < m) ? x + m : x;
64450 + return (x <= m) ? x + m + 1 : x;
64451 }
64452
64453 /**
64454 diff -urNp linux-2.6.39.1/include/linux/reboot.h linux-2.6.39.1/include/linux/reboot.h
64455 --- linux-2.6.39.1/include/linux/reboot.h 2011-05-19 00:06:34.000000000 -0400
64456 +++ linux-2.6.39.1/include/linux/reboot.h 2011-05-22 19:36:33.000000000 -0400
64457 @@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
64458 * Architecture-specific implementations of sys_reboot commands.
64459 */
64460
64461 -extern void machine_restart(char *cmd);
64462 -extern void machine_halt(void);
64463 -extern void machine_power_off(void);
64464 +extern void machine_restart(char *cmd) __noreturn;
64465 +extern void machine_halt(void) __noreturn;
64466 +extern void machine_power_off(void) __noreturn;
64467
64468 extern void machine_shutdown(void);
64469 struct pt_regs;
64470 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
64471 */
64472
64473 extern void kernel_restart_prepare(char *cmd);
64474 -extern void kernel_restart(char *cmd);
64475 -extern void kernel_halt(void);
64476 -extern void kernel_power_off(void);
64477 +extern void kernel_restart(char *cmd) __noreturn;
64478 +extern void kernel_halt(void) __noreturn;
64479 +extern void kernel_power_off(void) __noreturn;
64480
64481 extern int C_A_D; /* for sysctl */
64482 void ctrl_alt_del(void);
64483 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
64484 * Emergency restart, callable from an interrupt handler.
64485 */
64486
64487 -extern void emergency_restart(void);
64488 +extern void emergency_restart(void) __noreturn;
64489 #include <asm/emergency-restart.h>
64490
64491 #endif
64492 diff -urNp linux-2.6.39.1/include/linux/reiserfs_fs.h linux-2.6.39.1/include/linux/reiserfs_fs.h
64493 --- linux-2.6.39.1/include/linux/reiserfs_fs.h 2011-05-19 00:06:34.000000000 -0400
64494 +++ linux-2.6.39.1/include/linux/reiserfs_fs.h 2011-05-22 19:36:33.000000000 -0400
64495 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
64496 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64497
64498 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64499 -#define get_generation(s) atomic_read (&fs_generation(s))
64500 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64501 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64502 #define __fs_changed(gen,s) (gen != get_generation (s))
64503 #define fs_changed(gen,s) \
64504 @@ -1618,24 +1618,24 @@ static inline struct super_block *sb_fro
64505 */
64506
64507 struct item_operations {
64508 - int (*bytes_number) (struct item_head * ih, int block_size);
64509 - void (*decrement_key) (struct cpu_key *);
64510 - int (*is_left_mergeable) (struct reiserfs_key * ih,
64511 + int (* const bytes_number) (struct item_head * ih, int block_size);
64512 + void (* const decrement_key) (struct cpu_key *);
64513 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
64514 unsigned long bsize);
64515 - void (*print_item) (struct item_head *, char *item);
64516 - void (*check_item) (struct item_head *, char *item);
64517 + void (* const print_item) (struct item_head *, char *item);
64518 + void (* const check_item) (struct item_head *, char *item);
64519
64520 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64521 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64522 int is_affected, int insert_size);
64523 - int (*check_left) (struct virtual_item * vi, int free,
64524 + int (* const check_left) (struct virtual_item * vi, int free,
64525 int start_skip, int end_skip);
64526 - int (*check_right) (struct virtual_item * vi, int free);
64527 - int (*part_size) (struct virtual_item * vi, int from, int to);
64528 - int (*unit_num) (struct virtual_item * vi);
64529 - void (*print_vi) (struct virtual_item * vi);
64530 + int (* const check_right) (struct virtual_item * vi, int free);
64531 + int (* const part_size) (struct virtual_item * vi, int from, int to);
64532 + int (* const unit_num) (struct virtual_item * vi);
64533 + void (* const print_vi) (struct virtual_item * vi);
64534 };
64535
64536 -extern struct item_operations *item_ops[TYPE_ANY + 1];
64537 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
64538
64539 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
64540 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
64541 diff -urNp linux-2.6.39.1/include/linux/reiserfs_fs_sb.h linux-2.6.39.1/include/linux/reiserfs_fs_sb.h
64542 --- linux-2.6.39.1/include/linux/reiserfs_fs_sb.h 2011-05-19 00:06:34.000000000 -0400
64543 +++ linux-2.6.39.1/include/linux/reiserfs_fs_sb.h 2011-05-22 19:36:33.000000000 -0400
64544 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
64545 /* Comment? -Hans */
64546 wait_queue_head_t s_wait;
64547 /* To be obsoleted soon by per buffer seals.. -Hans */
64548 - atomic_t s_generation_counter; // increased by one every time the
64549 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64550 // tree gets re-balanced
64551 unsigned long s_properties; /* File system properties. Currently holds
64552 on-disk FS format */
64553 diff -urNp linux-2.6.39.1/include/linux/rmap.h linux-2.6.39.1/include/linux/rmap.h
64554 --- linux-2.6.39.1/include/linux/rmap.h 2011-05-19 00:06:34.000000000 -0400
64555 +++ linux-2.6.39.1/include/linux/rmap.h 2011-05-22 19:36:33.000000000 -0400
64556 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
64557 void anon_vma_init(void); /* create anon_vma_cachep */
64558 int anon_vma_prepare(struct vm_area_struct *);
64559 void unlink_anon_vmas(struct vm_area_struct *);
64560 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64561 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64562 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64563 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64564 void __anon_vma_link(struct vm_area_struct *);
64565
64566 static inline void anon_vma_merge(struct vm_area_struct *vma,
64567 diff -urNp linux-2.6.39.1/include/linux/sched.h linux-2.6.39.1/include/linux/sched.h
64568 --- linux-2.6.39.1/include/linux/sched.h 2011-05-19 00:06:34.000000000 -0400
64569 +++ linux-2.6.39.1/include/linux/sched.h 2011-06-03 01:35:00.000000000 -0400
64570 @@ -100,6 +100,7 @@ struct bio_list;
64571 struct fs_struct;
64572 struct perf_event_context;
64573 struct blk_plug;
64574 +struct linux_binprm;
64575
64576 /*
64577 * List of flags we want to share for kernel threads,
64578 @@ -360,7 +361,7 @@ extern signed long schedule_timeout_inte
64579 extern signed long schedule_timeout_killable(signed long timeout);
64580 extern signed long schedule_timeout_uninterruptible(signed long timeout);
64581 asmlinkage void schedule(void);
64582 -extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
64583 +extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
64584
64585 struct nsproxy;
64586 struct user_namespace;
64587 @@ -381,10 +382,13 @@ struct user_namespace;
64588 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64589
64590 extern int sysctl_max_map_count;
64591 +extern unsigned long sysctl_heap_stack_gap;
64592
64593 #include <linux/aio.h>
64594
64595 #ifdef CONFIG_MMU
64596 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64597 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64598 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64599 extern unsigned long
64600 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64601 @@ -629,6 +633,17 @@ struct signal_struct {
64602 #ifdef CONFIG_TASKSTATS
64603 struct taskstats *stats;
64604 #endif
64605 +
64606 +#ifdef CONFIG_GRKERNSEC
64607 + u32 curr_ip;
64608 + u32 saved_ip;
64609 + u32 gr_saddr;
64610 + u32 gr_daddr;
64611 + u16 gr_sport;
64612 + u16 gr_dport;
64613 + u8 used_accept:1;
64614 +#endif
64615 +
64616 #ifdef CONFIG_AUDIT
64617 unsigned audit_tty;
64618 struct tty_audit_buf *tty_audit_buf;
64619 @@ -701,6 +716,11 @@ struct user_struct {
64620 struct key *session_keyring; /* UID's default session keyring */
64621 #endif
64622
64623 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64624 + unsigned int banned;
64625 + unsigned long ban_expires;
64626 +#endif
64627 +
64628 /* Hash table maintenance information */
64629 struct hlist_node uidhash_node;
64630 uid_t uid;
64631 @@ -1310,8 +1330,8 @@ struct task_struct {
64632 struct list_head thread_group;
64633
64634 struct completion *vfork_done; /* for vfork() */
64635 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64636 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64637 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64638 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64639
64640 cputime_t utime, stime, utimescaled, stimescaled;
64641 cputime_t gtime;
64642 @@ -1327,13 +1347,6 @@ struct task_struct {
64643 struct task_cputime cputime_expires;
64644 struct list_head cpu_timers[3];
64645
64646 -/* process credentials */
64647 - const struct cred __rcu *real_cred; /* objective and real subjective task
64648 - * credentials (COW) */
64649 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64650 - * credentials (COW) */
64651 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64652 -
64653 char comm[TASK_COMM_LEN]; /* executable name excluding path
64654 - access with [gs]et_task_comm (which lock
64655 it with task_lock())
64656 @@ -1350,8 +1363,16 @@ struct task_struct {
64657 #endif
64658 /* CPU-specific state of this task */
64659 struct thread_struct thread;
64660 +/* thread_info moved to task_struct */
64661 +#ifdef CONFIG_X86
64662 + struct thread_info tinfo;
64663 +#endif
64664 /* filesystem information */
64665 struct fs_struct *fs;
64666 +
64667 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64668 + * credentials (COW) */
64669 +
64670 /* open file information */
64671 struct files_struct *files;
64672 /* namespaces */
64673 @@ -1398,6 +1419,11 @@ struct task_struct {
64674 struct rt_mutex_waiter *pi_blocked_on;
64675 #endif
64676
64677 +/* process credentials */
64678 + const struct cred __rcu *real_cred; /* objective and real subjective task
64679 + * credentials (COW) */
64680 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64681 +
64682 #ifdef CONFIG_DEBUG_MUTEXES
64683 /* mutex deadlock detection */
64684 struct mutex_waiter *blocked_on;
64685 @@ -1508,6 +1534,21 @@ struct task_struct {
64686 unsigned long default_timer_slack_ns;
64687
64688 struct list_head *scm_work_list;
64689 +
64690 +#ifdef CONFIG_GRKERNSEC
64691 + /* grsecurity */
64692 + struct dentry *gr_chroot_dentry;
64693 + struct acl_subject_label *acl;
64694 + struct acl_role_label *role;
64695 + struct file *exec_file;
64696 + u16 acl_role_id;
64697 + /* is this the task that authenticated to the special role */
64698 + u8 acl_sp_role;
64699 + u8 is_writable;
64700 + u8 brute;
64701 + u8 gr_is_chrooted;
64702 +#endif
64703 +
64704 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64705 /* Index of current stored address in ret_stack */
64706 int curr_ret_stack;
64707 @@ -1542,6 +1583,63 @@ struct task_struct {
64708 #endif
64709 };
64710
64711 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64712 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64713 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64714 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64715 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64716 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64717 +
64718 +#ifdef CONFIG_PAX_SOFTMODE
64719 +extern unsigned int pax_softmode;
64720 +#endif
64721 +
64722 +extern int pax_check_flags(unsigned long *);
64723 +
64724 +/* if tsk != current then task_lock must be held on it */
64725 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64726 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64727 +{
64728 + if (likely(tsk->mm))
64729 + return tsk->mm->pax_flags;
64730 + else
64731 + return 0UL;
64732 +}
64733 +
64734 +/* if tsk != current then task_lock must be held on it */
64735 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64736 +{
64737 + if (likely(tsk->mm)) {
64738 + tsk->mm->pax_flags = flags;
64739 + return 0;
64740 + }
64741 + return -EINVAL;
64742 +}
64743 +#endif
64744 +
64745 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64746 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64747 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64748 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64749 +#endif
64750 +
64751 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64752 +void pax_report_insns(void *pc, void *sp);
64753 +void pax_report_refcount_overflow(struct pt_regs *regs);
64754 +void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
64755 +
64756 +static inline void pax_track_stack(void)
64757 +{
64758 +#if __GNUC__ <= 3 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
64759 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
64760 + unsigned long sp = current_stack_pointer;
64761 + if (current_thread_info()->lowest_stack > sp &&
64762 + (unsigned long)task_stack_page(current) < sp)
64763 + current_thread_info()->lowest_stack = sp;
64764 +#endif
64765 +#endif
64766 +}
64767 +
64768 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64769 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64770
64771 @@ -2009,7 +2107,9 @@ void yield(void);
64772 extern struct exec_domain default_exec_domain;
64773
64774 union thread_union {
64775 +#ifndef CONFIG_X86
64776 struct thread_info thread_info;
64777 +#endif
64778 unsigned long stack[THREAD_SIZE/sizeof(long)];
64779 };
64780
64781 @@ -2179,7 +2279,7 @@ extern void __cleanup_sighand(struct sig
64782 extern void exit_itimers(struct signal_struct *);
64783 extern void flush_itimer_signals(void);
64784
64785 -extern NORET_TYPE void do_group_exit(int);
64786 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
64787
64788 extern void daemonize(const char *, ...);
64789 extern int allow_signal(int);
64790 @@ -2320,13 +2420,17 @@ static inline unsigned long *end_of_stac
64791
64792 #endif
64793
64794 -static inline int object_is_on_stack(void *obj)
64795 +static inline int object_starts_on_stack(void *obj)
64796 {
64797 - void *stack = task_stack_page(current);
64798 + const void *stack = task_stack_page(current);
64799
64800 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64801 }
64802
64803 +#ifdef CONFIG_PAX_USERCOPY
64804 +extern int object_is_on_stack(const void *obj, unsigned long len);
64805 +#endif
64806 +
64807 extern void thread_info_cache_init(void);
64808
64809 #ifdef CONFIG_DEBUG_STACK_USAGE
64810 diff -urNp linux-2.6.39.1/include/linux/screen_info.h linux-2.6.39.1/include/linux/screen_info.h
64811 --- linux-2.6.39.1/include/linux/screen_info.h 2011-05-19 00:06:34.000000000 -0400
64812 +++ linux-2.6.39.1/include/linux/screen_info.h 2011-05-22 19:36:33.000000000 -0400
64813 @@ -43,7 +43,8 @@ struct screen_info {
64814 __u16 pages; /* 0x32 */
64815 __u16 vesa_attributes; /* 0x34 */
64816 __u32 capabilities; /* 0x36 */
64817 - __u8 _reserved[6]; /* 0x3a */
64818 + __u16 vesapm_size; /* 0x3a */
64819 + __u8 _reserved[4]; /* 0x3c */
64820 } __attribute__((packed));
64821
64822 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64823 diff -urNp linux-2.6.39.1/include/linux/security.h linux-2.6.39.1/include/linux/security.h
64824 --- linux-2.6.39.1/include/linux/security.h 2011-05-19 00:06:34.000000000 -0400
64825 +++ linux-2.6.39.1/include/linux/security.h 2011-05-22 19:41:42.000000000 -0400
64826 @@ -36,6 +36,7 @@
64827 #include <linux/key.h>
64828 #include <linux/xfrm.h>
64829 #include <linux/slab.h>
64830 +#include <linux/grsecurity.h>
64831 #include <net/flow.h>
64832
64833 /* Maximum number of letters for an LSM name string */
64834 diff -urNp linux-2.6.39.1/include/linux/shm.h linux-2.6.39.1/include/linux/shm.h
64835 --- linux-2.6.39.1/include/linux/shm.h 2011-05-19 00:06:34.000000000 -0400
64836 +++ linux-2.6.39.1/include/linux/shm.h 2011-05-22 19:41:42.000000000 -0400
64837 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
64838 pid_t shm_cprid;
64839 pid_t shm_lprid;
64840 struct user_struct *mlock_user;
64841 +#ifdef CONFIG_GRKERNSEC
64842 + time_t shm_createtime;
64843 + pid_t shm_lapid;
64844 +#endif
64845 };
64846
64847 /* shm_mode upper byte flags */
64848 diff -urNp linux-2.6.39.1/include/linux/skbuff.h linux-2.6.39.1/include/linux/skbuff.h
64849 --- linux-2.6.39.1/include/linux/skbuff.h 2011-05-19 00:06:34.000000000 -0400
64850 +++ linux-2.6.39.1/include/linux/skbuff.h 2011-05-22 19:36:33.000000000 -0400
64851 @@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
64852 */
64853 static inline int skb_queue_empty(const struct sk_buff_head *list)
64854 {
64855 - return list->next == (struct sk_buff *)list;
64856 + return list->next == (const struct sk_buff *)list;
64857 }
64858
64859 /**
64860 @@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
64861 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64862 const struct sk_buff *skb)
64863 {
64864 - return skb->next == (struct sk_buff *)list;
64865 + return skb->next == (const struct sk_buff *)list;
64866 }
64867
64868 /**
64869 @@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
64870 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64871 const struct sk_buff *skb)
64872 {
64873 - return skb->prev == (struct sk_buff *)list;
64874 + return skb->prev == (const struct sk_buff *)list;
64875 }
64876
64877 /**
64878 @@ -1435,7 +1435,7 @@ static inline int pskb_network_may_pull(
64879 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64880 */
64881 #ifndef NET_SKB_PAD
64882 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64883 +#define NET_SKB_PAD max(_AC(32,U), L1_CACHE_BYTES)
64884 #endif
64885
64886 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64887 diff -urNp linux-2.6.39.1/include/linux/slab_def.h linux-2.6.39.1/include/linux/slab_def.h
64888 --- linux-2.6.39.1/include/linux/slab_def.h 2011-05-19 00:06:34.000000000 -0400
64889 +++ linux-2.6.39.1/include/linux/slab_def.h 2011-05-22 19:36:33.000000000 -0400
64890 @@ -96,10 +96,10 @@ struct kmem_cache {
64891 unsigned long node_allocs;
64892 unsigned long node_frees;
64893 unsigned long node_overflow;
64894 - atomic_t allochit;
64895 - atomic_t allocmiss;
64896 - atomic_t freehit;
64897 - atomic_t freemiss;
64898 + atomic_unchecked_t allochit;
64899 + atomic_unchecked_t allocmiss;
64900 + atomic_unchecked_t freehit;
64901 + atomic_unchecked_t freemiss;
64902
64903 /*
64904 * If debugging is enabled, then the allocator can add additional
64905 diff -urNp linux-2.6.39.1/include/linux/slab.h linux-2.6.39.1/include/linux/slab.h
64906 --- linux-2.6.39.1/include/linux/slab.h 2011-05-19 00:06:34.000000000 -0400
64907 +++ linux-2.6.39.1/include/linux/slab.h 2011-05-23 17:07:00.000000000 -0400
64908 @@ -11,12 +11,20 @@
64909
64910 #include <linux/gfp.h>
64911 #include <linux/types.h>
64912 +#include <linux/err.h>
64913
64914 /*
64915 * Flags to pass to kmem_cache_create().
64916 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64917 */
64918 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64919 +
64920 +#ifdef CONFIG_PAX_USERCOPY
64921 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64922 +#else
64923 +#define SLAB_USERCOPY 0x00000000UL
64924 +#endif
64925 +
64926 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64927 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64928 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64929 @@ -87,10 +95,13 @@
64930 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64931 * Both make kfree a no-op.
64932 */
64933 -#define ZERO_SIZE_PTR ((void *)16)
64934 +#define ZERO_SIZE_PTR \
64935 +({ \
64936 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64937 + (void *)(-MAX_ERRNO-1L); \
64938 +})
64939
64940 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64941 - (unsigned long)ZERO_SIZE_PTR)
64942 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64943
64944 /*
64945 * struct kmem_cache related prototypes
64946 @@ -141,6 +152,7 @@ void * __must_check krealloc(const void
64947 void kfree(const void *);
64948 void kzfree(const void *);
64949 size_t ksize(const void *);
64950 +void check_object_size(const void *ptr, unsigned long n, bool to);
64951
64952 /*
64953 * Allocator specific definitions. These are mainly used to establish optimized
64954 @@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
64955
64956 void __init kmem_cache_init_late(void);
64957
64958 +#define kmalloc(x, y) \
64959 +({ \
64960 + void *___retval; \
64961 + intoverflow_t ___x = (intoverflow_t)x; \
64962 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
64963 + ___retval = NULL; \
64964 + else \
64965 + ___retval = kmalloc((size_t)___x, (y)); \
64966 + ___retval; \
64967 +})
64968 +
64969 +#define kmalloc_node(x, y, z) \
64970 +({ \
64971 + void *___retval; \
64972 + intoverflow_t ___x = (intoverflow_t)x; \
64973 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
64974 + ___retval = NULL; \
64975 + else \
64976 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
64977 + ___retval; \
64978 +})
64979 +
64980 +#define kzalloc(x, y) \
64981 +({ \
64982 + void *___retval; \
64983 + intoverflow_t ___x = (intoverflow_t)x; \
64984 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
64985 + ___retval = NULL; \
64986 + else \
64987 + ___retval = kzalloc((size_t)___x, (y)); \
64988 + ___retval; \
64989 +})
64990 +
64991 +#define __krealloc(x, y, z) \
64992 +({ \
64993 + void *___retval; \
64994 + intoverflow_t ___y = (intoverflow_t)y; \
64995 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
64996 + ___retval = NULL; \
64997 + else \
64998 + ___retval = __krealloc((x), (size_t)___y, (z)); \
64999 + ___retval; \
65000 +})
65001 +
65002 +#define krealloc(x, y, z) \
65003 +({ \
65004 + void *___retval; \
65005 + intoverflow_t ___y = (intoverflow_t)y; \
65006 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
65007 + ___retval = NULL; \
65008 + else \
65009 + ___retval = krealloc((x), (size_t)___y, (z)); \
65010 + ___retval; \
65011 +})
65012 +
65013 #endif /* _LINUX_SLAB_H */
65014 diff -urNp linux-2.6.39.1/include/linux/slub_def.h linux-2.6.39.1/include/linux/slub_def.h
65015 --- linux-2.6.39.1/include/linux/slub_def.h 2011-05-19 00:06:34.000000000 -0400
65016 +++ linux-2.6.39.1/include/linux/slub_def.h 2011-05-22 19:36:33.000000000 -0400
65017 @@ -84,7 +84,7 @@ struct kmem_cache {
65018 struct kmem_cache_order_objects max;
65019 struct kmem_cache_order_objects min;
65020 gfp_t allocflags; /* gfp flags to use on each alloc */
65021 - int refcount; /* Refcount for slab cache destroy */
65022 + atomic_t refcount; /* Refcount for slab cache destroy */
65023 void (*ctor)(void *);
65024 int inuse; /* Offset to metadata */
65025 int align; /* Alignment */
65026 diff -urNp linux-2.6.39.1/include/linux/sonet.h linux-2.6.39.1/include/linux/sonet.h
65027 --- linux-2.6.39.1/include/linux/sonet.h 2011-05-19 00:06:34.000000000 -0400
65028 +++ linux-2.6.39.1/include/linux/sonet.h 2011-05-22 19:36:33.000000000 -0400
65029 @@ -61,7 +61,7 @@ struct sonet_stats {
65030 #include <asm/atomic.h>
65031
65032 struct k_sonet_stats {
65033 -#define __HANDLE_ITEM(i) atomic_t i
65034 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65035 __SONET_ITEMS
65036 #undef __HANDLE_ITEM
65037 };
65038 diff -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
65039 --- linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h 2011-05-19 00:06:34.000000000 -0400
65040 +++ linux-2.6.39.1/include/linux/ssb/ssb_driver_gige.h 2011-05-22 19:36:33.000000000 -0400
65041 @@ -44,7 +44,7 @@ struct ssb_gige {
65042
65043 /* The PCI controller device. */
65044 struct pci_controller pci_controller;
65045 - struct pci_ops pci_ops;
65046 + const struct pci_ops pci_ops;
65047 struct resource mem_resource;
65048 struct resource io_resource;
65049 };
65050 diff -urNp linux-2.6.39.1/include/linux/sunrpc/clnt.h linux-2.6.39.1/include/linux/sunrpc/clnt.h
65051 --- linux-2.6.39.1/include/linux/sunrpc/clnt.h 2011-05-19 00:06:34.000000000 -0400
65052 +++ linux-2.6.39.1/include/linux/sunrpc/clnt.h 2011-05-22 19:36:33.000000000 -0400
65053 @@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
65054 {
65055 switch (sap->sa_family) {
65056 case AF_INET:
65057 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
65058 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65059 case AF_INET6:
65060 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65061 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65062 }
65063 return 0;
65064 }
65065 @@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
65066 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65067 const struct sockaddr *src)
65068 {
65069 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65070 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65071 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65072
65073 dsin->sin_family = ssin->sin_family;
65074 @@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
65075 if (sa->sa_family != AF_INET6)
65076 return 0;
65077
65078 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65079 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65080 }
65081
65082 #endif /* __KERNEL__ */
65083 diff -urNp linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h
65084 --- linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h 2011-05-19 00:06:34.000000000 -0400
65085 +++ linux-2.6.39.1/include/linux/sunrpc/svc_rdma.h 2011-05-22 19:36:33.000000000 -0400
65086 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65087 extern unsigned int svcrdma_max_requests;
65088 extern unsigned int svcrdma_max_req_size;
65089
65090 -extern atomic_t rdma_stat_recv;
65091 -extern atomic_t rdma_stat_read;
65092 -extern atomic_t rdma_stat_write;
65093 -extern atomic_t rdma_stat_sq_starve;
65094 -extern atomic_t rdma_stat_rq_starve;
65095 -extern atomic_t rdma_stat_rq_poll;
65096 -extern atomic_t rdma_stat_rq_prod;
65097 -extern atomic_t rdma_stat_sq_poll;
65098 -extern atomic_t rdma_stat_sq_prod;
65099 +extern atomic_unchecked_t rdma_stat_recv;
65100 +extern atomic_unchecked_t rdma_stat_read;
65101 +extern atomic_unchecked_t rdma_stat_write;
65102 +extern atomic_unchecked_t rdma_stat_sq_starve;
65103 +extern atomic_unchecked_t rdma_stat_rq_starve;
65104 +extern atomic_unchecked_t rdma_stat_rq_poll;
65105 +extern atomic_unchecked_t rdma_stat_rq_prod;
65106 +extern atomic_unchecked_t rdma_stat_sq_poll;
65107 +extern atomic_unchecked_t rdma_stat_sq_prod;
65108
65109 #define RPCRDMA_VERSION 1
65110
65111 diff -urNp linux-2.6.39.1/include/linux/suspend.h linux-2.6.39.1/include/linux/suspend.h
65112 --- linux-2.6.39.1/include/linux/suspend.h 2011-05-19 00:06:34.000000000 -0400
65113 +++ linux-2.6.39.1/include/linux/suspend.h 2011-05-22 19:36:33.000000000 -0400
65114 @@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
65115 * which require special recovery actions in that situation.
65116 */
65117 struct platform_suspend_ops {
65118 - int (*valid)(suspend_state_t state);
65119 - int (*begin)(suspend_state_t state);
65120 - int (*prepare)(void);
65121 - int (*prepare_late)(void);
65122 - int (*enter)(suspend_state_t state);
65123 - void (*wake)(void);
65124 - void (*finish)(void);
65125 - void (*end)(void);
65126 - void (*recover)(void);
65127 + int (* const valid)(suspend_state_t state);
65128 + int (* const begin)(suspend_state_t state);
65129 + int (* const prepare)(void);
65130 + int (* const prepare_late)(void);
65131 + int (* const enter)(suspend_state_t state);
65132 + void (* const wake)(void);
65133 + void (* const finish)(void);
65134 + void (* const end)(void);
65135 + void (* const recover)(void);
65136 };
65137
65138 #ifdef CONFIG_SUSPEND
65139 @@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
65140 * platforms which require special recovery actions in that situation.
65141 */
65142 struct platform_hibernation_ops {
65143 - int (*begin)(void);
65144 - void (*end)(void);
65145 - int (*pre_snapshot)(void);
65146 - void (*finish)(void);
65147 - int (*prepare)(void);
65148 - int (*enter)(void);
65149 - void (*leave)(void);
65150 - int (*pre_restore)(void);
65151 - void (*restore_cleanup)(void);
65152 - void (*recover)(void);
65153 + int (* const begin)(void);
65154 + void (* const end)(void);
65155 + int (* const pre_snapshot)(void);
65156 + void (* const finish)(void);
65157 + int (* const prepare)(void);
65158 + int (* const enter)(void);
65159 + void (* const leave)(void);
65160 + int (* const pre_restore)(void);
65161 + void (* const restore_cleanup)(void);
65162 + void (* const recover)(void);
65163 };
65164
65165 #ifdef CONFIG_HIBERNATION
65166 diff -urNp linux-2.6.39.1/include/linux/sysctl.h linux-2.6.39.1/include/linux/sysctl.h
65167 --- linux-2.6.39.1/include/linux/sysctl.h 2011-05-19 00:06:34.000000000 -0400
65168 +++ linux-2.6.39.1/include/linux/sysctl.h 2011-05-22 19:41:42.000000000 -0400
65169 @@ -155,7 +155,11 @@ enum
65170 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65171 };
65172
65173 -
65174 +#ifdef CONFIG_PAX_SOFTMODE
65175 +enum {
65176 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65177 +};
65178 +#endif
65179
65180 /* CTL_VM names: */
65181 enum
65182 @@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
65183
65184 extern int proc_dostring(struct ctl_table *, int,
65185 void __user *, size_t *, loff_t *);
65186 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65187 + void __user *, size_t *, loff_t *);
65188 extern int proc_dointvec(struct ctl_table *, int,
65189 void __user *, size_t *, loff_t *);
65190 extern int proc_dointvec_minmax(struct ctl_table *, int,
65191 diff -urNp linux-2.6.39.1/include/linux/sysfs.h linux-2.6.39.1/include/linux/sysfs.h
65192 --- linux-2.6.39.1/include/linux/sysfs.h 2011-05-19 00:06:34.000000000 -0400
65193 +++ linux-2.6.39.1/include/linux/sysfs.h 2011-05-22 19:36:33.000000000 -0400
65194 @@ -110,8 +110,8 @@ struct bin_attribute {
65195 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
65196
65197 struct sysfs_ops {
65198 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
65199 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
65200 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
65201 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
65202 };
65203
65204 struct sysfs_dirent;
65205 diff -urNp linux-2.6.39.1/include/linux/tty.h linux-2.6.39.1/include/linux/tty.h
65206 --- linux-2.6.39.1/include/linux/tty.h 2011-05-19 00:06:34.000000000 -0400
65207 +++ linux-2.6.39.1/include/linux/tty.h 2011-05-22 19:36:33.000000000 -0400
65208 @@ -13,6 +13,7 @@
65209 #include <linux/tty_driver.h>
65210 #include <linux/tty_ldisc.h>
65211 #include <linux/mutex.h>
65212 +#include <linux/poll.h>
65213
65214 #include <asm/system.h>
65215
65216 @@ -466,7 +467,6 @@ extern int tty_perform_flush(struct tty_
65217 extern dev_t tty_devnum(struct tty_struct *tty);
65218 extern void proc_clear_tty(struct task_struct *p);
65219 extern struct tty_struct *get_current_tty(void);
65220 -extern void tty_default_fops(struct file_operations *fops);
65221 extern struct tty_struct *alloc_tty_struct(void);
65222 extern int tty_add_file(struct tty_struct *tty, struct file *file);
65223 extern void free_tty_struct(struct tty_struct *tty);
65224 @@ -529,6 +529,18 @@ extern void tty_ldisc_begin(void);
65225 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
65226 extern void tty_ldisc_enable(struct tty_struct *tty);
65227
65228 +/* tty_io.c */
65229 +extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
65230 +extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
65231 +extern unsigned int tty_poll(struct file *, poll_table *);
65232 +#ifdef CONFIG_COMPAT
65233 +extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
65234 + unsigned long arg);
65235 +#else
65236 +#define tty_compat_ioctl NULL
65237 +#endif
65238 +extern int tty_release(struct inode *, struct file *);
65239 +extern int tty_fasync(int fd, struct file *filp, int on);
65240
65241 /* n_tty.c */
65242 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
65243 diff -urNp linux-2.6.39.1/include/linux/tty_ldisc.h linux-2.6.39.1/include/linux/tty_ldisc.h
65244 --- linux-2.6.39.1/include/linux/tty_ldisc.h 2011-05-19 00:06:34.000000000 -0400
65245 +++ linux-2.6.39.1/include/linux/tty_ldisc.h 2011-05-22 19:36:33.000000000 -0400
65246 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
65247
65248 struct module *owner;
65249
65250 - int refcount;
65251 + atomic_t refcount;
65252 };
65253
65254 struct tty_ldisc {
65255 diff -urNp linux-2.6.39.1/include/linux/types.h linux-2.6.39.1/include/linux/types.h
65256 --- linux-2.6.39.1/include/linux/types.h 2011-05-19 00:06:34.000000000 -0400
65257 +++ linux-2.6.39.1/include/linux/types.h 2011-05-22 19:36:33.000000000 -0400
65258 @@ -213,10 +213,26 @@ typedef struct {
65259 int counter;
65260 } atomic_t;
65261
65262 +#ifdef CONFIG_PAX_REFCOUNT
65263 +typedef struct {
65264 + int counter;
65265 +} atomic_unchecked_t;
65266 +#else
65267 +typedef atomic_t atomic_unchecked_t;
65268 +#endif
65269 +
65270 #ifdef CONFIG_64BIT
65271 typedef struct {
65272 long counter;
65273 } atomic64_t;
65274 +
65275 +#ifdef CONFIG_PAX_REFCOUNT
65276 +typedef struct {
65277 + long counter;
65278 +} atomic64_unchecked_t;
65279 +#else
65280 +typedef atomic64_t atomic64_unchecked_t;
65281 +#endif
65282 #endif
65283
65284 struct list_head {
65285 diff -urNp linux-2.6.39.1/include/linux/uaccess.h linux-2.6.39.1/include/linux/uaccess.h
65286 --- linux-2.6.39.1/include/linux/uaccess.h 2011-05-19 00:06:34.000000000 -0400
65287 +++ linux-2.6.39.1/include/linux/uaccess.h 2011-05-22 19:36:33.000000000 -0400
65288 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
65289 long ret; \
65290 mm_segment_t old_fs = get_fs(); \
65291 \
65292 - set_fs(KERNEL_DS); \
65293 pagefault_disable(); \
65294 + set_fs(KERNEL_DS); \
65295 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65296 - pagefault_enable(); \
65297 set_fs(old_fs); \
65298 + pagefault_enable(); \
65299 ret; \
65300 })
65301
65302 @@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
65303 * Safely read from address @src to the buffer at @dst. If a kernel fault
65304 * happens, handle that and return -EFAULT.
65305 */
65306 -extern long probe_kernel_read(void *dst, void *src, size_t size);
65307 -extern long __probe_kernel_read(void *dst, void *src, size_t size);
65308 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
65309 +extern long __probe_kernel_read(void *dst, const void *src, size_t size);
65310
65311 /*
65312 * probe_kernel_write(): safely attempt to write to a location
65313 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
65314 * Safely write to address @dst from the buffer at @src. If a kernel fault
65315 * happens, handle that and return -EFAULT.
65316 */
65317 -extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
65318 -extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
65319 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
65320 +extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
65321
65322 #endif /* __LINUX_UACCESS_H__ */
65323 diff -urNp linux-2.6.39.1/include/linux/unaligned/access_ok.h linux-2.6.39.1/include/linux/unaligned/access_ok.h
65324 --- linux-2.6.39.1/include/linux/unaligned/access_ok.h 2011-05-19 00:06:34.000000000 -0400
65325 +++ linux-2.6.39.1/include/linux/unaligned/access_ok.h 2011-05-22 19:36:33.000000000 -0400
65326 @@ -6,32 +6,32 @@
65327
65328 static inline u16 get_unaligned_le16(const void *p)
65329 {
65330 - return le16_to_cpup((__le16 *)p);
65331 + return le16_to_cpup((const __le16 *)p);
65332 }
65333
65334 static inline u32 get_unaligned_le32(const void *p)
65335 {
65336 - return le32_to_cpup((__le32 *)p);
65337 + return le32_to_cpup((const __le32 *)p);
65338 }
65339
65340 static inline u64 get_unaligned_le64(const void *p)
65341 {
65342 - return le64_to_cpup((__le64 *)p);
65343 + return le64_to_cpup((const __le64 *)p);
65344 }
65345
65346 static inline u16 get_unaligned_be16(const void *p)
65347 {
65348 - return be16_to_cpup((__be16 *)p);
65349 + return be16_to_cpup((const __be16 *)p);
65350 }
65351
65352 static inline u32 get_unaligned_be32(const void *p)
65353 {
65354 - return be32_to_cpup((__be32 *)p);
65355 + return be32_to_cpup((const __be32 *)p);
65356 }
65357
65358 static inline u64 get_unaligned_be64(const void *p)
65359 {
65360 - return be64_to_cpup((__be64 *)p);
65361 + return be64_to_cpup((const __be64 *)p);
65362 }
65363
65364 static inline void put_unaligned_le16(u16 val, void *p)
65365 diff -urNp linux-2.6.39.1/include/linux/usb/hcd.h linux-2.6.39.1/include/linux/usb/hcd.h
65366 --- linux-2.6.39.1/include/linux/usb/hcd.h 2011-05-19 00:06:34.000000000 -0400
65367 +++ linux-2.6.39.1/include/linux/usb/hcd.h 2011-05-22 19:36:33.000000000 -0400
65368 @@ -615,7 +615,7 @@ struct usb_mon_operations {
65369 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
65370 };
65371
65372 -extern struct usb_mon_operations *mon_ops;
65373 +extern const struct usb_mon_operations *mon_ops;
65374
65375 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
65376 {
65377 @@ -637,7 +637,7 @@ static inline void usbmon_urb_complete(s
65378 (*mon_ops->urb_complete)(bus, urb, status);
65379 }
65380
65381 -int usb_mon_register(struct usb_mon_operations *ops);
65382 +int usb_mon_register(const struct usb_mon_operations *ops);
65383 void usb_mon_deregister(void);
65384
65385 #else
65386 diff -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
65387 --- linux-2.6.39.1/include/linux/usb/intel_mid_otg.h 2011-05-19 00:06:34.000000000 -0400
65388 +++ linux-2.6.39.1/include/linux/usb/intel_mid_otg.h 2011-05-22 19:36:33.000000000 -0400
65389 @@ -115,7 +115,7 @@ struct intel_mid_otg_xceiv {
65390 void __iomem *base;
65391
65392 /* ops to access ulpi */
65393 - struct iotg_ulpi_access_ops ulpi_ops;
65394 + const struct iotg_ulpi_access_ops ulpi_ops;
65395
65396 /* atomic notifier for interrupt context */
65397 struct atomic_notifier_head iotg_notifier;
65398 diff -urNp linux-2.6.39.1/include/linux/usb/ulpi.h linux-2.6.39.1/include/linux/usb/ulpi.h
65399 --- linux-2.6.39.1/include/linux/usb/ulpi.h 2011-05-19 00:06:34.000000000 -0400
65400 +++ linux-2.6.39.1/include/linux/usb/ulpi.h 2011-05-22 19:36:33.000000000 -0400
65401 @@ -186,7 +186,7 @@ struct otg_transceiver *otg_ulpi_create(
65402
65403 #ifdef CONFIG_USB_ULPI_VIEWPORT
65404 /* access ops for controllers with a viewport register */
65405 -extern struct otg_io_access_ops ulpi_viewport_access_ops;
65406 +extern const struct otg_io_access_ops ulpi_viewport_access_ops;
65407 #endif
65408
65409 #endif /* __LINUX_USB_ULPI_H */
65410 diff -urNp linux-2.6.39.1/include/linux/vga_switcheroo.h linux-2.6.39.1/include/linux/vga_switcheroo.h
65411 --- linux-2.6.39.1/include/linux/vga_switcheroo.h 2011-05-19 00:06:34.000000000 -0400
65412 +++ linux-2.6.39.1/include/linux/vga_switcheroo.h 2011-05-22 19:36:33.000000000 -0400
65413 @@ -39,7 +39,7 @@ int vga_switcheroo_register_client(struc
65414 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
65415 struct fb_info *info);
65416
65417 -int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
65418 +int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
65419 void vga_switcheroo_unregister_handler(void);
65420
65421 int vga_switcheroo_process_delayed_switch(void);
65422 @@ -52,7 +52,7 @@ static inline int vga_switcheroo_registe
65423 void (*reprobe)(struct pci_dev *dev),
65424 bool (*can_switch)(struct pci_dev *dev)) { return 0; }
65425 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
65426 -static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; }
65427 +static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
65428 static inline void vga_switcheroo_unregister_handler(void) {}
65429 static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
65430
65431 diff -urNp linux-2.6.39.1/include/linux/virtio.h linux-2.6.39.1/include/linux/virtio.h
65432 --- linux-2.6.39.1/include/linux/virtio.h 2011-05-19 00:06:34.000000000 -0400
65433 +++ linux-2.6.39.1/include/linux/virtio.h 2011-05-22 19:36:33.000000000 -0400
65434 @@ -102,7 +102,7 @@ struct virtio_device {
65435 int index;
65436 struct device dev;
65437 struct virtio_device_id id;
65438 - struct virtio_config_ops *config;
65439 + const struct virtio_config_ops *config;
65440 struct list_head vqs;
65441 /* Note that this is a Linux set_bit-style bitmap. */
65442 unsigned long features[1];
65443 diff -urNp linux-2.6.39.1/include/linux/vmalloc.h linux-2.6.39.1/include/linux/vmalloc.h
65444 --- linux-2.6.39.1/include/linux/vmalloc.h 2011-05-19 00:06:34.000000000 -0400
65445 +++ linux-2.6.39.1/include/linux/vmalloc.h 2011-05-22 19:36:33.000000000 -0400
65446 @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
65447 #define VM_MAP 0x00000004 /* vmap()ed pages */
65448 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65449 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65450 +
65451 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65452 +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
65453 +#endif
65454 +
65455 /* bits [20..32] reserved for arch specific ioremap internals */
65456
65457 /*
65458 @@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
65459 # endif
65460 #endif
65461
65462 +#define vmalloc(x) \
65463 +({ \
65464 + void *___retval; \
65465 + intoverflow_t ___x = (intoverflow_t)x; \
65466 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
65467 + ___retval = NULL; \
65468 + else \
65469 + ___retval = vmalloc((unsigned long)___x); \
65470 + ___retval; \
65471 +})
65472 +
65473 +#define vzalloc(x) \
65474 +({ \
65475 + void *___retval; \
65476 + intoverflow_t ___x = (intoverflow_t)x; \
65477 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
65478 + ___retval = NULL; \
65479 + else \
65480 + ___retval = vzalloc((unsigned long)___x); \
65481 + ___retval; \
65482 +})
65483 +
65484 +#define __vmalloc(x, y, z) \
65485 +({ \
65486 + void *___retval; \
65487 + intoverflow_t ___x = (intoverflow_t)x; \
65488 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
65489 + ___retval = NULL; \
65490 + else \
65491 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
65492 + ___retval; \
65493 +})
65494 +
65495 +#define vmalloc_user(x) \
65496 +({ \
65497 + void *___retval; \
65498 + intoverflow_t ___x = (intoverflow_t)x; \
65499 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
65500 + ___retval = NULL; \
65501 + else \
65502 + ___retval = vmalloc_user((unsigned long)___x); \
65503 + ___retval; \
65504 +})
65505 +
65506 +#define vmalloc_exec(x) \
65507 +({ \
65508 + void *___retval; \
65509 + intoverflow_t ___x = (intoverflow_t)x; \
65510 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
65511 + ___retval = NULL; \
65512 + else \
65513 + ___retval = vmalloc_exec((unsigned long)___x); \
65514 + ___retval; \
65515 +})
65516 +
65517 +#define vmalloc_node(x, y) \
65518 +({ \
65519 + void *___retval; \
65520 + intoverflow_t ___x = (intoverflow_t)x; \
65521 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
65522 + ___retval = NULL; \
65523 + else \
65524 + ___retval = vmalloc_node((unsigned long)___x, (y));\
65525 + ___retval; \
65526 +})
65527 +
65528 +#define vzalloc_node(x, y) \
65529 +({ \
65530 + void *___retval; \
65531 + intoverflow_t ___x = (intoverflow_t)x; \
65532 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
65533 + ___retval = NULL; \
65534 + else \
65535 + ___retval = vzalloc_node((unsigned long)___x, (y));\
65536 + ___retval; \
65537 +})
65538 +
65539 +#define vmalloc_32(x) \
65540 +({ \
65541 + void *___retval; \
65542 + intoverflow_t ___x = (intoverflow_t)x; \
65543 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
65544 + ___retval = NULL; \
65545 + else \
65546 + ___retval = vmalloc_32((unsigned long)___x); \
65547 + ___retval; \
65548 +})
65549 +
65550 +#define vmalloc_32_user(x) \
65551 +({ \
65552 +void *___retval; \
65553 + intoverflow_t ___x = (intoverflow_t)x; \
65554 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
65555 + ___retval = NULL; \
65556 + else \
65557 + ___retval = vmalloc_32_user((unsigned long)___x);\
65558 + ___retval; \
65559 +})
65560 +
65561 #endif /* _LINUX_VMALLOC_H */
65562 diff -urNp linux-2.6.39.1/include/linux/vmstat.h linux-2.6.39.1/include/linux/vmstat.h
65563 --- linux-2.6.39.1/include/linux/vmstat.h 2011-05-19 00:06:34.000000000 -0400
65564 +++ linux-2.6.39.1/include/linux/vmstat.h 2011-05-22 19:36:33.000000000 -0400
65565 @@ -147,18 +147,18 @@ static inline void vm_events_fold_cpu(in
65566 /*
65567 * Zone based page accounting with per cpu differentials.
65568 */
65569 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65570 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65571
65572 static inline void zone_page_state_add(long x, struct zone *zone,
65573 enum zone_stat_item item)
65574 {
65575 - atomic_long_add(x, &zone->vm_stat[item]);
65576 - atomic_long_add(x, &vm_stat[item]);
65577 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65578 + atomic_long_add_unchecked(x, &vm_stat[item]);
65579 }
65580
65581 static inline unsigned long global_page_state(enum zone_stat_item item)
65582 {
65583 - long x = atomic_long_read(&vm_stat[item]);
65584 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65585 #ifdef CONFIG_SMP
65586 if (x < 0)
65587 x = 0;
65588 @@ -169,7 +169,7 @@ static inline unsigned long global_page_
65589 static inline unsigned long zone_page_state(struct zone *zone,
65590 enum zone_stat_item item)
65591 {
65592 - long x = atomic_long_read(&zone->vm_stat[item]);
65593 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65594 #ifdef CONFIG_SMP
65595 if (x < 0)
65596 x = 0;
65597 @@ -186,7 +186,7 @@ static inline unsigned long zone_page_st
65598 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65599 enum zone_stat_item item)
65600 {
65601 - long x = atomic_long_read(&zone->vm_stat[item]);
65602 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65603
65604 #ifdef CONFIG_SMP
65605 int cpu;
65606 @@ -280,8 +280,8 @@ static inline void __mod_zone_page_state
65607
65608 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65609 {
65610 - atomic_long_inc(&zone->vm_stat[item]);
65611 - atomic_long_inc(&vm_stat[item]);
65612 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65613 + atomic_long_inc_unchecked(&vm_stat[item]);
65614 }
65615
65616 static inline void __inc_zone_page_state(struct page *page,
65617 @@ -292,8 +292,8 @@ static inline void __inc_zone_page_state
65618
65619 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65620 {
65621 - atomic_long_dec(&zone->vm_stat[item]);
65622 - atomic_long_dec(&vm_stat[item]);
65623 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65624 + atomic_long_dec_unchecked(&vm_stat[item]);
65625 }
65626
65627 static inline void __dec_zone_page_state(struct page *page,
65628 diff -urNp linux-2.6.39.1/include/media/saa7146_vv.h linux-2.6.39.1/include/media/saa7146_vv.h
65629 --- linux-2.6.39.1/include/media/saa7146_vv.h 2011-05-19 00:06:34.000000000 -0400
65630 +++ linux-2.6.39.1/include/media/saa7146_vv.h 2011-05-22 19:36:33.000000000 -0400
65631 @@ -202,13 +202,13 @@ void saa7146_set_gpio(struct saa7146_dev
65632
65633 /* from saa7146_video.c */
65634 extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
65635 -extern struct saa7146_use_ops saa7146_video_uops;
65636 +extern const struct saa7146_use_ops saa7146_video_uops;
65637 int saa7146_start_preview(struct saa7146_fh *fh);
65638 int saa7146_stop_preview(struct saa7146_fh *fh);
65639 long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
65640
65641 /* from saa7146_vbi.c */
65642 -extern struct saa7146_use_ops saa7146_vbi_uops;
65643 +extern const struct saa7146_use_ops saa7146_vbi_uops;
65644
65645 /* resource management functions */
65646 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
65647 diff -urNp linux-2.6.39.1/include/media/v4l2-device.h linux-2.6.39.1/include/media/v4l2-device.h
65648 --- linux-2.6.39.1/include/media/v4l2-device.h 2011-05-19 00:06:34.000000000 -0400
65649 +++ linux-2.6.39.1/include/media/v4l2-device.h 2011-05-22 19:36:33.000000000 -0400
65650 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(st
65651 this function returns 0. If the name ends with a digit (e.g. cx18),
65652 then the name will be set to cx18-0 since cx180 looks really odd. */
65653 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
65654 - atomic_t *instance);
65655 + atomic_unchecked_t *instance);
65656
65657 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
65658 Since the parent disappears this ensures that v4l2_dev doesn't have an
65659 diff -urNp linux-2.6.39.1/include/net/caif/cfctrl.h linux-2.6.39.1/include/net/caif/cfctrl.h
65660 --- linux-2.6.39.1/include/net/caif/cfctrl.h 2011-05-19 00:06:34.000000000 -0400
65661 +++ linux-2.6.39.1/include/net/caif/cfctrl.h 2011-05-22 19:36:33.000000000 -0400
65662 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65663 struct cfctrl {
65664 struct cfsrvl serv;
65665 struct cfctrl_rsp res;
65666 - atomic_t req_seq_no;
65667 - atomic_t rsp_seq_no;
65668 + atomic_unchecked_t req_seq_no;
65669 + atomic_unchecked_t rsp_seq_no;
65670 struct list_head list;
65671 /* Protects from simultaneous access to first_req list */
65672 spinlock_t info_list_lock;
65673 diff -urNp linux-2.6.39.1/include/net/flow.h linux-2.6.39.1/include/net/flow.h
65674 --- linux-2.6.39.1/include/net/flow.h 2011-05-19 00:06:34.000000000 -0400
65675 +++ linux-2.6.39.1/include/net/flow.h 2011-05-22 19:36:33.000000000 -0400
65676 @@ -167,6 +167,6 @@ extern struct flow_cache_object *flow_ca
65677 u8 dir, flow_resolve_t resolver, void *ctx);
65678
65679 extern void flow_cache_flush(void);
65680 -extern atomic_t flow_cache_genid;
65681 +extern atomic_unchecked_t flow_cache_genid;
65682
65683 #endif
65684 diff -urNp linux-2.6.39.1/include/net/inetpeer.h linux-2.6.39.1/include/net/inetpeer.h
65685 --- linux-2.6.39.1/include/net/inetpeer.h 2011-05-19 00:06:34.000000000 -0400
65686 +++ linux-2.6.39.1/include/net/inetpeer.h 2011-05-22 19:36:33.000000000 -0400
65687 @@ -43,8 +43,8 @@ struct inet_peer {
65688 */
65689 union {
65690 struct {
65691 - atomic_t rid; /* Frag reception counter */
65692 - atomic_t ip_id_count; /* IP ID for the next packet */
65693 + atomic_unchecked_t rid; /* Frag reception counter */
65694 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65695 __u32 tcp_ts;
65696 __u32 tcp_ts_stamp;
65697 u32 metrics[RTAX_MAX];
65698 @@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
65699 {
65700 more++;
65701 inet_peer_refcheck(p);
65702 - return atomic_add_return(more, &p->ip_id_count) - more;
65703 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
65704 }
65705
65706 #endif /* _NET_INETPEER_H */
65707 diff -urNp linux-2.6.39.1/include/net/ip_fib.h linux-2.6.39.1/include/net/ip_fib.h
65708 --- linux-2.6.39.1/include/net/ip_fib.h 2011-05-19 00:06:34.000000000 -0400
65709 +++ linux-2.6.39.1/include/net/ip_fib.h 2011-05-22 19:36:33.000000000 -0400
65710 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
65711
65712 #define FIB_RES_SADDR(net, res) \
65713 ((FIB_RES_NH(res).nh_saddr_genid == \
65714 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65715 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65716 FIB_RES_NH(res).nh_saddr : \
65717 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65718 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65719 diff -urNp linux-2.6.39.1/include/net/ip_vs.h linux-2.6.39.1/include/net/ip_vs.h
65720 --- linux-2.6.39.1/include/net/ip_vs.h 2011-05-19 00:06:34.000000000 -0400
65721 +++ linux-2.6.39.1/include/net/ip_vs.h 2011-05-22 19:36:33.000000000 -0400
65722 @@ -512,7 +512,7 @@ struct ip_vs_conn {
65723 struct ip_vs_conn *control; /* Master control connection */
65724 atomic_t n_control; /* Number of controlled ones */
65725 struct ip_vs_dest *dest; /* real server */
65726 - atomic_t in_pkts; /* incoming packet counter */
65727 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65728
65729 /* packet transmitter for different forwarding methods. If it
65730 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65731 @@ -650,7 +650,7 @@ struct ip_vs_dest {
65732 __be16 port; /* port number of the server */
65733 union nf_inet_addr addr; /* IP address of the server */
65734 volatile unsigned flags; /* dest status flags */
65735 - atomic_t conn_flags; /* flags to copy to conn */
65736 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65737 atomic_t weight; /* server weight */
65738
65739 atomic_t refcnt; /* reference counter */
65740 diff -urNp linux-2.6.39.1/include/net/irda/ircomm_tty.h linux-2.6.39.1/include/net/irda/ircomm_tty.h
65741 --- linux-2.6.39.1/include/net/irda/ircomm_tty.h 2011-05-19 00:06:34.000000000 -0400
65742 +++ linux-2.6.39.1/include/net/irda/ircomm_tty.h 2011-05-22 19:36:33.000000000 -0400
65743 @@ -35,6 +35,7 @@
65744 #include <linux/termios.h>
65745 #include <linux/timer.h>
65746 #include <linux/tty.h> /* struct tty_struct */
65747 +#include <asm/local.h>
65748
65749 #include <net/irda/irias_object.h>
65750 #include <net/irda/ircomm_core.h>
65751 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65752 unsigned short close_delay;
65753 unsigned short closing_wait; /* time to wait before closing */
65754
65755 - int open_count;
65756 - int blocked_open; /* # of blocked opens */
65757 + local_t open_count;
65758 + local_t blocked_open; /* # of blocked opens */
65759
65760 /* Protect concurent access to :
65761 * o self->open_count
65762 diff -urNp linux-2.6.39.1/include/net/iucv/af_iucv.h linux-2.6.39.1/include/net/iucv/af_iucv.h
65763 --- linux-2.6.39.1/include/net/iucv/af_iucv.h 2011-05-19 00:06:34.000000000 -0400
65764 +++ linux-2.6.39.1/include/net/iucv/af_iucv.h 2011-05-22 19:36:33.000000000 -0400
65765 @@ -87,7 +87,7 @@ struct iucv_sock {
65766 struct iucv_sock_list {
65767 struct hlist_head head;
65768 rwlock_t lock;
65769 - atomic_t autobind_name;
65770 + atomic_unchecked_t autobind_name;
65771 };
65772
65773 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65774 diff -urNp linux-2.6.39.1/include/net/neighbour.h linux-2.6.39.1/include/net/neighbour.h
65775 --- linux-2.6.39.1/include/net/neighbour.h 2011-05-19 00:06:34.000000000 -0400
65776 +++ linux-2.6.39.1/include/net/neighbour.h 2011-05-22 19:36:33.000000000 -0400
65777 @@ -118,12 +118,12 @@ struct neighbour {
65778
65779 struct neigh_ops {
65780 int family;
65781 - void (*solicit)(struct neighbour *, struct sk_buff*);
65782 - void (*error_report)(struct neighbour *, struct sk_buff*);
65783 - int (*output)(struct sk_buff*);
65784 - int (*connected_output)(struct sk_buff*);
65785 - int (*hh_output)(struct sk_buff*);
65786 - int (*queue_xmit)(struct sk_buff*);
65787 + void (* const solicit)(struct neighbour *, struct sk_buff*);
65788 + void (* const error_report)(struct neighbour *, struct sk_buff*);
65789 + int (* const output)(struct sk_buff*);
65790 + int (* const connected_output)(struct sk_buff*);
65791 + int (* const hh_output)(struct sk_buff*);
65792 + int (* const queue_xmit)(struct sk_buff*);
65793 };
65794
65795 struct pneigh_entry {
65796 diff -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
65797 --- linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h 2011-05-19 00:06:34.000000000 -0400
65798 +++ linux-2.6.39.1/include/net/netfilter/nf_conntrack_ecache.h 2011-05-22 19:36:33.000000000 -0400
65799 @@ -95,7 +95,7 @@ nf_conntrack_eventmask_report(unsigned i
65800 int report)
65801 {
65802 int ret = 0;
65803 - struct nf_ct_event_notifier *notify;
65804 + const struct nf_ct_event_notifier *notify;
65805 struct nf_conntrack_ecache *e;
65806
65807 rcu_read_lock();
65808 @@ -174,7 +174,7 @@ nf_ct_expect_event_report(enum ip_conntr
65809 u32 pid,
65810 int report)
65811 {
65812 - struct nf_exp_event_notifier *notify;
65813 + const struct nf_exp_event_notifier *notify;
65814 struct nf_conntrack_ecache *e;
65815
65816 rcu_read_lock();
65817 diff -urNp linux-2.6.39.1/include/net/netlink.h linux-2.6.39.1/include/net/netlink.h
65818 --- linux-2.6.39.1/include/net/netlink.h 2011-05-19 00:06:34.000000000 -0400
65819 +++ linux-2.6.39.1/include/net/netlink.h 2011-05-22 19:36:33.000000000 -0400
65820 @@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
65821 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65822 {
65823 if (mark)
65824 - skb_trim(skb, (unsigned char *) mark - skb->data);
65825 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65826 }
65827
65828 /**
65829 diff -urNp linux-2.6.39.1/include/net/netns/ipv4.h linux-2.6.39.1/include/net/netns/ipv4.h
65830 --- linux-2.6.39.1/include/net/netns/ipv4.h 2011-05-19 00:06:34.000000000 -0400
65831 +++ linux-2.6.39.1/include/net/netns/ipv4.h 2011-05-22 19:36:33.000000000 -0400
65832 @@ -54,8 +54,8 @@ struct netns_ipv4 {
65833 int sysctl_rt_cache_rebuild_count;
65834 int current_rt_cache_rebuild_count;
65835
65836 - atomic_t rt_genid;
65837 - atomic_t dev_addr_genid;
65838 + atomic_unchecked_t rt_genid;
65839 + atomic_unchecked_t dev_addr_genid;
65840
65841 #ifdef CONFIG_IP_MROUTE
65842 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65843 diff -urNp linux-2.6.39.1/include/net/sctp/sctp.h linux-2.6.39.1/include/net/sctp/sctp.h
65844 --- linux-2.6.39.1/include/net/sctp/sctp.h 2011-05-19 00:06:34.000000000 -0400
65845 +++ linux-2.6.39.1/include/net/sctp/sctp.h 2011-05-22 19:36:33.000000000 -0400
65846 @@ -316,9 +316,9 @@ do { \
65847
65848 #else /* SCTP_DEBUG */
65849
65850 -#define SCTP_DEBUG_PRINTK(whatever...)
65851 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65852 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65853 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65854 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65855 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65856 #define SCTP_ENABLE_DEBUG
65857 #define SCTP_DISABLE_DEBUG
65858 #define SCTP_ASSERT(expr, str, func)
65859 diff -urNp linux-2.6.39.1/include/net/sock.h linux-2.6.39.1/include/net/sock.h
65860 --- linux-2.6.39.1/include/net/sock.h 2011-05-19 00:06:34.000000000 -0400
65861 +++ linux-2.6.39.1/include/net/sock.h 2011-05-22 19:36:33.000000000 -0400
65862 @@ -277,7 +277,7 @@ struct sock {
65863 #ifdef CONFIG_RPS
65864 __u32 sk_rxhash;
65865 #endif
65866 - atomic_t sk_drops;
65867 + atomic_unchecked_t sk_drops;
65868 int sk_rcvbuf;
65869
65870 struct sk_filter __rcu *sk_filter;
65871 diff -urNp linux-2.6.39.1/include/net/tcp.h linux-2.6.39.1/include/net/tcp.h
65872 --- linux-2.6.39.1/include/net/tcp.h 2011-05-19 00:06:34.000000000 -0400
65873 +++ linux-2.6.39.1/include/net/tcp.h 2011-05-22 19:36:33.000000000 -0400
65874 @@ -1374,7 +1374,7 @@ enum tcp_seq_states {
65875 struct tcp_seq_afinfo {
65876 char *name;
65877 sa_family_t family;
65878 - struct file_operations seq_fops;
65879 + struct file_operations seq_fops; /* cannot be const */
65880 struct seq_operations seq_ops;
65881 };
65882
65883 diff -urNp linux-2.6.39.1/include/net/udp.h linux-2.6.39.1/include/net/udp.h
65884 --- linux-2.6.39.1/include/net/udp.h 2011-05-19 00:06:34.000000000 -0400
65885 +++ linux-2.6.39.1/include/net/udp.h 2011-05-22 19:36:33.000000000 -0400
65886 @@ -234,7 +234,7 @@ struct udp_seq_afinfo {
65887 char *name;
65888 sa_family_t family;
65889 struct udp_table *udp_table;
65890 - struct file_operations seq_fops;
65891 + struct file_operations seq_fops; /* cannot be const */
65892 struct seq_operations seq_ops;
65893 };
65894
65895 diff -urNp linux-2.6.39.1/include/net/xfrm.h linux-2.6.39.1/include/net/xfrm.h
65896 --- linux-2.6.39.1/include/net/xfrm.h 2011-05-19 00:06:34.000000000 -0400
65897 +++ linux-2.6.39.1/include/net/xfrm.h 2011-05-22 19:36:33.000000000 -0400
65898 @@ -505,7 +505,7 @@ struct xfrm_policy {
65899 struct timer_list timer;
65900
65901 struct flow_cache_object flo;
65902 - atomic_t genid;
65903 + atomic_unchecked_t genid;
65904 u32 priority;
65905 u32 index;
65906 struct xfrm_mark mark;
65907 diff -urNp linux-2.6.39.1/include/pcmcia/ss.h linux-2.6.39.1/include/pcmcia/ss.h
65908 --- linux-2.6.39.1/include/pcmcia/ss.h 2011-05-19 00:06:34.000000000 -0400
65909 +++ linux-2.6.39.1/include/pcmcia/ss.h 2011-05-22 19:36:33.000000000 -0400
65910 @@ -241,9 +241,9 @@ struct pcmcia_socket {
65911 * "select PCCARD_NONSTATIC" in Kconfig.
65912 *
65913 */
65914 -extern struct pccard_resource_ops pccard_static_ops;
65915 +extern const struct pccard_resource_ops pccard_static_ops;
65916 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
65917 -extern struct pccard_resource_ops pccard_iodyn_ops;
65918 +extern const struct pccard_resource_ops pccard_iodyn_ops;
65919 extern struct pccard_resource_ops pccard_nonstatic_ops;
65920 #else
65921 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
65922 diff -urNp linux-2.6.39.1/include/rdma/ib_verbs.h linux-2.6.39.1/include/rdma/ib_verbs.h
65923 --- linux-2.6.39.1/include/rdma/ib_verbs.h 2011-05-19 00:06:34.000000000 -0400
65924 +++ linux-2.6.39.1/include/rdma/ib_verbs.h 2011-05-22 19:36:33.000000000 -0400
65925 @@ -1149,7 +1149,7 @@ struct ib_device {
65926 struct ib_mad *in_mad,
65927 struct ib_mad *out_mad);
65928
65929 - struct ib_dma_mapping_ops *dma_ops;
65930 + const struct ib_dma_mapping_ops *dma_ops;
65931
65932 struct module *owner;
65933 struct device dev;
65934 diff -urNp linux-2.6.39.1/include/scsi/libfc.h linux-2.6.39.1/include/scsi/libfc.h
65935 --- linux-2.6.39.1/include/scsi/libfc.h 2011-05-19 00:06:34.000000000 -0400
65936 +++ linux-2.6.39.1/include/scsi/libfc.h 2011-05-22 19:36:33.000000000 -0400
65937 @@ -202,7 +202,7 @@ struct fc_rport_priv {
65938 struct mutex rp_mutex;
65939 struct delayed_work retry_work;
65940 enum fc_rport_event event;
65941 - struct fc_rport_operations *ops;
65942 + const struct fc_rport_operations *ops;
65943 struct list_head peers;
65944 struct work_struct event_work;
65945 u32 supported_classes;
65946 diff -urNp linux-2.6.39.1/include/scsi/scsi_device.h linux-2.6.39.1/include/scsi/scsi_device.h
65947 --- linux-2.6.39.1/include/scsi/scsi_device.h 2011-05-19 00:06:34.000000000 -0400
65948 +++ linux-2.6.39.1/include/scsi/scsi_device.h 2011-05-22 19:36:33.000000000 -0400
65949 @@ -161,9 +161,9 @@ struct scsi_device {
65950 unsigned int max_device_blocked; /* what device_blocked counts down from */
65951 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65952
65953 - atomic_t iorequest_cnt;
65954 - atomic_t iodone_cnt;
65955 - atomic_t ioerr_cnt;
65956 + atomic_unchecked_t iorequest_cnt;
65957 + atomic_unchecked_t iodone_cnt;
65958 + atomic_unchecked_t ioerr_cnt;
65959
65960 struct device sdev_gendev,
65961 sdev_dev;
65962 diff -urNp linux-2.6.39.1/include/sound/ac97_codec.h linux-2.6.39.1/include/sound/ac97_codec.h
65963 --- linux-2.6.39.1/include/sound/ac97_codec.h 2011-05-19 00:06:34.000000000 -0400
65964 +++ linux-2.6.39.1/include/sound/ac97_codec.h 2011-05-22 19:36:33.000000000 -0400
65965 @@ -424,15 +424,15 @@
65966 struct snd_ac97;
65967
65968 struct snd_ac97_build_ops {
65969 - int (*build_3d) (struct snd_ac97 *ac97);
65970 - int (*build_specific) (struct snd_ac97 *ac97);
65971 - int (*build_spdif) (struct snd_ac97 *ac97);
65972 - int (*build_post_spdif) (struct snd_ac97 *ac97);
65973 + int (* const build_3d) (struct snd_ac97 *ac97);
65974 + int (* const build_specific) (struct snd_ac97 *ac97);
65975 + int (* const build_spdif) (struct snd_ac97 *ac97);
65976 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
65977 #ifdef CONFIG_PM
65978 - void (*suspend) (struct snd_ac97 *ac97);
65979 - void (*resume) (struct snd_ac97 *ac97);
65980 + void (* const suspend) (struct snd_ac97 *ac97);
65981 + void (* const resume) (struct snd_ac97 *ac97);
65982 #endif
65983 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65984 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
65985 };
65986
65987 struct snd_ac97_bus_ops {
65988 @@ -446,7 +446,7 @@ struct snd_ac97_bus_ops {
65989
65990 struct snd_ac97_bus {
65991 /* -- lowlevel (hardware) driver specific -- */
65992 - struct snd_ac97_bus_ops *ops;
65993 + const struct snd_ac97_bus_ops *ops;
65994 void *private_data;
65995 void (*private_free) (struct snd_ac97_bus *bus);
65996 /* --- */
65997 @@ -556,7 +556,7 @@ static inline int ac97_can_spdif(struct
65998
65999 /* functions */
66000 /* create new AC97 bus */
66001 -int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
66002 +int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
66003 void *private_data, struct snd_ac97_bus **rbus);
66004 /* create mixer controls */
66005 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
66006 diff -urNp linux-2.6.39.1/include/sound/core.h linux-2.6.39.1/include/sound/core.h
66007 --- linux-2.6.39.1/include/sound/core.h 2011-05-19 00:06:34.000000000 -0400
66008 +++ linux-2.6.39.1/include/sound/core.h 2011-05-22 19:36:33.000000000 -0400
66009 @@ -88,7 +88,7 @@ struct snd_device {
66010 snd_device_state_t state; /* state of the device */
66011 snd_device_type_t type; /* device type */
66012 void *device_data; /* device structure */
66013 - struct snd_device_ops *ops; /* operations */
66014 + const struct snd_device_ops *ops; /* operations */
66015 };
66016
66017 #define snd_device(n) list_entry(n, struct snd_device, list)
66018 @@ -301,7 +301,7 @@ int snd_card_file_remove(struct snd_card
66019 /* device.c */
66020
66021 int snd_device_new(struct snd_card *card, snd_device_type_t type,
66022 - void *device_data, struct snd_device_ops *ops);
66023 + void *device_data, const struct snd_device_ops *ops);
66024 int snd_device_register(struct snd_card *card, void *device_data);
66025 int snd_device_register_all(struct snd_card *card);
66026 int snd_device_disconnect(struct snd_card *card, void *device_data);
66027 diff -urNp linux-2.6.39.1/include/sound/pcm.h linux-2.6.39.1/include/sound/pcm.h
66028 --- linux-2.6.39.1/include/sound/pcm.h 2011-05-19 00:06:34.000000000 -0400
66029 +++ linux-2.6.39.1/include/sound/pcm.h 2011-05-22 19:36:33.000000000 -0400
66030 @@ -379,7 +379,7 @@ struct snd_pcm_substream {
66031 unsigned int dma_buf_id;
66032 size_t dma_max;
66033 /* -- hardware operations -- */
66034 - struct snd_pcm_ops *ops;
66035 + const struct snd_pcm_ops *ops;
66036 /* -- runtime information -- */
66037 struct snd_pcm_runtime *runtime;
66038 /* -- timer section -- */
66039 @@ -845,7 +845,7 @@ const unsigned char *snd_pcm_format_sile
66040 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
66041 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
66042
66043 -void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
66044 +void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, const struct snd_pcm_ops *ops);
66045 void snd_pcm_set_sync(struct snd_pcm_substream *substream);
66046 int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
66047 int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
66048 diff -urNp linux-2.6.39.1/include/sound/rawmidi.h linux-2.6.39.1/include/sound/rawmidi.h
66049 --- linux-2.6.39.1/include/sound/rawmidi.h 2011-05-19 00:06:34.000000000 -0400
66050 +++ linux-2.6.39.1/include/sound/rawmidi.h 2011-05-22 19:36:33.000000000 -0400
66051 @@ -100,7 +100,7 @@ struct snd_rawmidi_substream {
66052 struct snd_rawmidi_runtime *runtime;
66053 struct pid *pid;
66054 /* hardware layer */
66055 - struct snd_rawmidi_ops *ops;
66056 + const struct snd_rawmidi_ops *ops;
66057 };
66058
66059 struct snd_rawmidi_file {
66060 @@ -127,7 +127,7 @@ struct snd_rawmidi {
66061 int ossreg;
66062 #endif
66063
66064 - struct snd_rawmidi_global_ops *ops;
66065 + const struct snd_rawmidi_global_ops *ops;
66066
66067 struct snd_rawmidi_str streams[2];
66068
66069 @@ -151,7 +151,7 @@ int snd_rawmidi_new(struct snd_card *car
66070 int output_count, int input_count,
66071 struct snd_rawmidi **rmidi);
66072 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
66073 - struct snd_rawmidi_ops *ops);
66074 + const struct snd_rawmidi_ops *ops);
66075
66076 /* callbacks */
66077
66078 diff -urNp linux-2.6.39.1/include/sound/seq_device.h linux-2.6.39.1/include/sound/seq_device.h
66079 --- linux-2.6.39.1/include/sound/seq_device.h 2011-05-19 00:06:34.000000000 -0400
66080 +++ linux-2.6.39.1/include/sound/seq_device.h 2011-05-22 19:36:33.000000000 -0400
66081 @@ -69,7 +69,7 @@ struct snd_seq_dev_ops {
66082 */
66083 void snd_seq_device_load_drivers(void);
66084 int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result);
66085 -int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize);
66086 +int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry, int argsize);
66087 int snd_seq_device_unregister_driver(char *id);
66088
66089 #define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device))
66090 diff -urNp linux-2.6.39.1/include/sound/snd_wavefront.h linux-2.6.39.1/include/sound/snd_wavefront.h
66091 --- linux-2.6.39.1/include/sound/snd_wavefront.h 2011-05-19 00:06:34.000000000 -0400
66092 +++ linux-2.6.39.1/include/sound/snd_wavefront.h 2011-05-22 19:36:33.000000000 -0400
66093 @@ -37,8 +37,8 @@ struct _snd_wavefront_midi {
66094 #define MPU_ACK 0xFE
66095 #define UART_MODE_ON 0x3F
66096
66097 -extern struct snd_rawmidi_ops snd_wavefront_midi_output;
66098 -extern struct snd_rawmidi_ops snd_wavefront_midi_input;
66099 +extern const struct snd_rawmidi_ops snd_wavefront_midi_output;
66100 +extern const struct snd_rawmidi_ops snd_wavefront_midi_input;
66101
66102 extern void snd_wavefront_midi_enable_virtual (snd_wavefront_card_t *);
66103 extern void snd_wavefront_midi_disable_virtual (snd_wavefront_card_t *);
66104 diff -urNp linux-2.6.39.1/include/sound/soc.h linux-2.6.39.1/include/sound/soc.h
66105 --- linux-2.6.39.1/include/sound/soc.h 2011-05-19 00:06:34.000000000 -0400
66106 +++ linux-2.6.39.1/include/sound/soc.h 2011-05-22 19:36:33.000000000 -0400
66107 @@ -245,7 +245,7 @@ struct snd_soc_jack_gpio;
66108
66109 typedef int (*hw_write_t)(void *,const char* ,int);
66110
66111 -extern struct snd_ac97_bus_ops soc_ac97_ops;
66112 +extern const struct snd_ac97_bus_ops soc_ac97_ops;
66113
66114 enum snd_soc_control_type {
66115 SND_SOC_CUSTOM,
66116 diff -urNp linux-2.6.39.1/include/sound/ymfpci.h linux-2.6.39.1/include/sound/ymfpci.h
66117 --- linux-2.6.39.1/include/sound/ymfpci.h 2011-05-19 00:06:34.000000000 -0400
66118 +++ linux-2.6.39.1/include/sound/ymfpci.h 2011-05-22 19:36:33.000000000 -0400
66119 @@ -358,7 +358,7 @@ struct snd_ymfpci {
66120 spinlock_t reg_lock;
66121 spinlock_t voice_lock;
66122 wait_queue_head_t interrupt_sleep;
66123 - atomic_t interrupt_sleep_count;
66124 + atomic_unchecked_t interrupt_sleep_count;
66125 struct snd_info_entry *proc_entry;
66126 const struct firmware *dsp_microcode;
66127 const struct firmware *controller_microcode;
66128 diff -urNp linux-2.6.39.1/include/target/target_core_base.h linux-2.6.39.1/include/target/target_core_base.h
66129 --- linux-2.6.39.1/include/target/target_core_base.h 2011-06-03 00:04:14.000000000 -0400
66130 +++ linux-2.6.39.1/include/target/target_core_base.h 2011-06-03 00:32:08.000000000 -0400
66131 @@ -432,8 +432,8 @@ struct se_transport_task {
66132 atomic_t t_task_cdbs_left;
66133 atomic_t t_task_cdbs_ex_left;
66134 atomic_t t_task_cdbs_timeout_left;
66135 - atomic_t t_task_cdbs_sent;
66136 - atomic_t t_transport_aborted;
66137 + atomic_unchecked_t t_task_cdbs_sent;
66138 + atomic_unchecked_t t_transport_aborted;
66139 atomic_t t_transport_active;
66140 atomic_t t_transport_complete;
66141 atomic_t t_transport_queue_active;
66142 @@ -774,7 +774,7 @@ struct se_device {
66143 atomic_t active_cmds;
66144 atomic_t simple_cmds;
66145 atomic_t depth_left;
66146 - atomic_t dev_ordered_id;
66147 + atomic_unchecked_t dev_ordered_id;
66148 atomic_t dev_tur_active;
66149 atomic_t execute_tasks;
66150 atomic_t dev_status_thr_count;
66151 diff -urNp linux-2.6.39.1/include/trace/events/irq.h linux-2.6.39.1/include/trace/events/irq.h
66152 --- linux-2.6.39.1/include/trace/events/irq.h 2011-05-19 00:06:34.000000000 -0400
66153 +++ linux-2.6.39.1/include/trace/events/irq.h 2011-05-22 19:36:33.000000000 -0400
66154 @@ -36,7 +36,7 @@ struct softirq_action;
66155 */
66156 TRACE_EVENT(irq_handler_entry,
66157
66158 - TP_PROTO(int irq, struct irqaction *action),
66159 + TP_PROTO(int irq, const struct irqaction *action),
66160
66161 TP_ARGS(irq, action),
66162
66163 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66164 */
66165 TRACE_EVENT(irq_handler_exit,
66166
66167 - TP_PROTO(int irq, struct irqaction *action, int ret),
66168 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66169
66170 TP_ARGS(irq, action, ret),
66171
66172 diff -urNp linux-2.6.39.1/include/video/udlfb.h linux-2.6.39.1/include/video/udlfb.h
66173 --- linux-2.6.39.1/include/video/udlfb.h 2011-05-19 00:06:34.000000000 -0400
66174 +++ linux-2.6.39.1/include/video/udlfb.h 2011-05-22 19:36:33.000000000 -0400
66175 @@ -51,10 +51,10 @@ struct dlfb_data {
66176 int base8;
66177 u32 pseudo_palette[256];
66178 /* blit-only rendering path metrics, exposed through sysfs */
66179 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66180 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66181 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66182 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66183 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66184 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66185 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66186 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66187 };
66188
66189 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66190 diff -urNp linux-2.6.39.1/include/video/uvesafb.h linux-2.6.39.1/include/video/uvesafb.h
66191 --- linux-2.6.39.1/include/video/uvesafb.h 2011-05-19 00:06:34.000000000 -0400
66192 +++ linux-2.6.39.1/include/video/uvesafb.h 2011-05-22 19:36:33.000000000 -0400
66193 @@ -177,6 +177,7 @@ struct uvesafb_par {
66194 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66195 u8 pmi_setpal; /* PMI for palette changes */
66196 u16 *pmi_base; /* protected mode interface location */
66197 + u8 *pmi_code; /* protected mode code location */
66198 void *pmi_start;
66199 void *pmi_pal;
66200 u8 *vbe_state_orig; /*
66201 diff -urNp linux-2.6.39.1/init/do_mounts.c linux-2.6.39.1/init/do_mounts.c
66202 --- linux-2.6.39.1/init/do_mounts.c 2011-05-19 00:06:34.000000000 -0400
66203 +++ linux-2.6.39.1/init/do_mounts.c 2011-05-22 19:36:33.000000000 -0400
66204 @@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
66205
66206 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66207 {
66208 - int err = sys_mount(name, "/root", fs, flags, data);
66209 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
66210 if (err)
66211 return err;
66212
66213 @@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
66214 va_start(args, fmt);
66215 vsprintf(buf, fmt, args);
66216 va_end(args);
66217 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66218 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66219 if (fd >= 0) {
66220 sys_ioctl(fd, FDEJECT, 0);
66221 sys_close(fd);
66222 }
66223 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66224 - fd = sys_open("/dev/console", O_RDWR, 0);
66225 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66226 if (fd >= 0) {
66227 sys_ioctl(fd, TCGETS, (long)&termios);
66228 termios.c_lflag &= ~ICANON;
66229 sys_ioctl(fd, TCSETSF, (long)&termios);
66230 - sys_read(fd, &c, 1);
66231 + sys_read(fd, (char __user *)&c, 1);
66232 termios.c_lflag |= ICANON;
66233 sys_ioctl(fd, TCSETSF, (long)&termios);
66234 sys_close(fd);
66235 @@ -488,6 +488,6 @@ void __init prepare_namespace(void)
66236 mount_root();
66237 out:
66238 devtmpfs_mount("dev");
66239 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66240 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66241 sys_chroot((const char __user __force *)".");
66242 }
66243 diff -urNp linux-2.6.39.1/init/do_mounts.h linux-2.6.39.1/init/do_mounts.h
66244 --- linux-2.6.39.1/init/do_mounts.h 2011-05-19 00:06:34.000000000 -0400
66245 +++ linux-2.6.39.1/init/do_mounts.h 2011-05-22 19:36:33.000000000 -0400
66246 @@ -15,15 +15,15 @@ extern int root_mountflags;
66247
66248 static inline int create_dev(char *name, dev_t dev)
66249 {
66250 - sys_unlink(name);
66251 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66252 + sys_unlink((__force char __user *)name);
66253 + return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
66254 }
66255
66256 #if BITS_PER_LONG == 32
66257 static inline u32 bstat(char *name)
66258 {
66259 struct stat64 stat;
66260 - if (sys_stat64(name, &stat) != 0)
66261 + if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
66262 return 0;
66263 if (!S_ISBLK(stat.st_mode))
66264 return 0;
66265 diff -urNp linux-2.6.39.1/init/do_mounts_initrd.c linux-2.6.39.1/init/do_mounts_initrd.c
66266 --- linux-2.6.39.1/init/do_mounts_initrd.c 2011-05-19 00:06:34.000000000 -0400
66267 +++ linux-2.6.39.1/init/do_mounts_initrd.c 2011-05-22 19:36:33.000000000 -0400
66268 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
66269 create_dev("/dev/root.old", Root_RAM0);
66270 /* mount initrd on rootfs' /root */
66271 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66272 - sys_mkdir("/old", 0700);
66273 - root_fd = sys_open("/", 0, 0);
66274 - old_fd = sys_open("/old", 0, 0);
66275 + sys_mkdir((__force const char __user *)"/old", 0700);
66276 + root_fd = sys_open((__force const char __user *)"/", 0, 0);
66277 + old_fd = sys_open((__force const char __user *)"/old", 0, 0);
66278 /* move initrd over / and chdir/chroot in initrd root */
66279 - sys_chdir("/root");
66280 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66281 - sys_chroot(".");
66282 + sys_chdir((__force const char __user *)"/root");
66283 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66284 + sys_chroot((__force const char __user *)".");
66285
66286 /*
66287 * In case that a resume from disk is carried out by linuxrc or one of
66288 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
66289
66290 /* move initrd to rootfs' /old */
66291 sys_fchdir(old_fd);
66292 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66293 + sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
66294 /* switch root and cwd back to / of rootfs */
66295 sys_fchdir(root_fd);
66296 - sys_chroot(".");
66297 + sys_chroot((__force const char __user *)".");
66298 sys_close(old_fd);
66299 sys_close(root_fd);
66300
66301 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66302 - sys_chdir("/old");
66303 + sys_chdir((__force const char __user *)"/old");
66304 return;
66305 }
66306
66307 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
66308 mount_root();
66309
66310 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66311 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66312 + error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
66313 if (!error)
66314 printk("okay\n");
66315 else {
66316 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66317 + int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
66318 if (error == -ENOENT)
66319 printk("/initrd does not exist. Ignored.\n");
66320 else
66321 printk("failed\n");
66322 printk(KERN_NOTICE "Unmounting old root\n");
66323 - sys_umount("/old", MNT_DETACH);
66324 + sys_umount((__force char __user *)"/old", MNT_DETACH);
66325 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66326 if (fd < 0) {
66327 error = fd;
66328 @@ -116,11 +116,11 @@ int __init initrd_load(void)
66329 * mounted in the normal path.
66330 */
66331 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66332 - sys_unlink("/initrd.image");
66333 + sys_unlink((__force const char __user *)"/initrd.image");
66334 handle_initrd();
66335 return 1;
66336 }
66337 }
66338 - sys_unlink("/initrd.image");
66339 + sys_unlink((__force const char __user *)"/initrd.image");
66340 return 0;
66341 }
66342 diff -urNp linux-2.6.39.1/init/do_mounts_md.c linux-2.6.39.1/init/do_mounts_md.c
66343 --- linux-2.6.39.1/init/do_mounts_md.c 2011-05-19 00:06:34.000000000 -0400
66344 +++ linux-2.6.39.1/init/do_mounts_md.c 2011-05-22 19:36:33.000000000 -0400
66345 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66346 partitioned ? "_d" : "", minor,
66347 md_setup_args[ent].device_names);
66348
66349 - fd = sys_open(name, 0, 0);
66350 + fd = sys_open((__force char __user *)name, 0, 0);
66351 if (fd < 0) {
66352 printk(KERN_ERR "md: open failed - cannot start "
66353 "array %s\n", name);
66354 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66355 * array without it
66356 */
66357 sys_close(fd);
66358 - fd = sys_open(name, 0, 0);
66359 + fd = sys_open((__force char __user *)name, 0, 0);
66360 sys_ioctl(fd, BLKRRPART, 0);
66361 }
66362 sys_close(fd);
66363 diff -urNp linux-2.6.39.1/init/initramfs.c linux-2.6.39.1/init/initramfs.c
66364 --- linux-2.6.39.1/init/initramfs.c 2011-05-19 00:06:34.000000000 -0400
66365 +++ linux-2.6.39.1/init/initramfs.c 2011-05-22 19:36:33.000000000 -0400
66366 @@ -74,7 +74,7 @@ static void __init free_hash(void)
66367 }
66368 }
66369
66370 -static long __init do_utime(char __user *filename, time_t mtime)
66371 +static long __init do_utime(__force char __user *filename, time_t mtime)
66372 {
66373 struct timespec t[2];
66374
66375 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
66376 struct dir_entry *de, *tmp;
66377 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66378 list_del(&de->list);
66379 - do_utime(de->name, de->mtime);
66380 + do_utime((__force char __user *)de->name, de->mtime);
66381 kfree(de->name);
66382 kfree(de);
66383 }
66384 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
66385 if (nlink >= 2) {
66386 char *old = find_link(major, minor, ino, mode, collected);
66387 if (old)
66388 - return (sys_link(old, collected) < 0) ? -1 : 1;
66389 + return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
66390 }
66391 return 0;
66392 }
66393 @@ -280,11 +280,11 @@ static void __init clean_path(char *path
66394 {
66395 struct stat st;
66396
66397 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66398 + if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
66399 if (S_ISDIR(st.st_mode))
66400 - sys_rmdir(path);
66401 + sys_rmdir((__force char __user *)path);
66402 else
66403 - sys_unlink(path);
66404 + sys_unlink((__force char __user *)path);
66405 }
66406 }
66407
66408 @@ -305,7 +305,7 @@ static int __init do_name(void)
66409 int openflags = O_WRONLY|O_CREAT;
66410 if (ml != 1)
66411 openflags |= O_TRUNC;
66412 - wfd = sys_open(collected, openflags, mode);
66413 + wfd = sys_open((__force char __user *)collected, openflags, mode);
66414
66415 if (wfd >= 0) {
66416 sys_fchown(wfd, uid, gid);
66417 @@ -317,17 +317,17 @@ static int __init do_name(void)
66418 }
66419 }
66420 } else if (S_ISDIR(mode)) {
66421 - sys_mkdir(collected, mode);
66422 - sys_chown(collected, uid, gid);
66423 - sys_chmod(collected, mode);
66424 + sys_mkdir((__force char __user *)collected, mode);
66425 + sys_chown((__force char __user *)collected, uid, gid);
66426 + sys_chmod((__force char __user *)collected, mode);
66427 dir_add(collected, mtime);
66428 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66429 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66430 if (maybe_link() == 0) {
66431 - sys_mknod(collected, mode, rdev);
66432 - sys_chown(collected, uid, gid);
66433 - sys_chmod(collected, mode);
66434 - do_utime(collected, mtime);
66435 + sys_mknod((__force char __user *)collected, mode, rdev);
66436 + sys_chown((__force char __user *)collected, uid, gid);
66437 + sys_chmod((__force char __user *)collected, mode);
66438 + do_utime((__force char __user *)collected, mtime);
66439 }
66440 }
66441 return 0;
66442 @@ -336,15 +336,15 @@ static int __init do_name(void)
66443 static int __init do_copy(void)
66444 {
66445 if (count >= body_len) {
66446 - sys_write(wfd, victim, body_len);
66447 + sys_write(wfd, (__force char __user *)victim, body_len);
66448 sys_close(wfd);
66449 - do_utime(vcollected, mtime);
66450 + do_utime((__force char __user *)vcollected, mtime);
66451 kfree(vcollected);
66452 eat(body_len);
66453 state = SkipIt;
66454 return 0;
66455 } else {
66456 - sys_write(wfd, victim, count);
66457 + sys_write(wfd, (__force char __user *)victim, count);
66458 body_len -= count;
66459 eat(count);
66460 return 1;
66461 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
66462 {
66463 collected[N_ALIGN(name_len) + body_len] = '\0';
66464 clean_path(collected, 0);
66465 - sys_symlink(collected + N_ALIGN(name_len), collected);
66466 - sys_lchown(collected, uid, gid);
66467 - do_utime(collected, mtime);
66468 + sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
66469 + sys_lchown((__force char __user *)collected, uid, gid);
66470 + do_utime((__force char __user *)collected, mtime);
66471 state = SkipIt;
66472 next_state = Reset;
66473 return 0;
66474 diff -urNp linux-2.6.39.1/init/Kconfig linux-2.6.39.1/init/Kconfig
66475 --- linux-2.6.39.1/init/Kconfig 2011-05-19 00:06:34.000000000 -0400
66476 +++ linux-2.6.39.1/init/Kconfig 2011-05-22 19:36:33.000000000 -0400
66477 @@ -1202,7 +1202,7 @@ config SLUB_DEBUG
66478
66479 config COMPAT_BRK
66480 bool "Disable heap randomization"
66481 - default y
66482 + default n
66483 help
66484 Randomizing heap placement makes heap exploits harder, but it
66485 also breaks ancient binaries (including anything libc5 based).
66486 diff -urNp linux-2.6.39.1/init/main.c linux-2.6.39.1/init/main.c
66487 --- linux-2.6.39.1/init/main.c 2011-06-03 00:04:14.000000000 -0400
66488 +++ linux-2.6.39.1/init/main.c 2011-06-03 00:32:08.000000000 -0400
66489 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
66490 extern void tc_init(void);
66491 #endif
66492
66493 +extern void grsecurity_init(void);
66494 +
66495 /*
66496 * Debug helper: via this flag we know that we are in 'early bootup code'
66497 * where only the boot processor is running with IRQ disabled. This means
66498 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char
66499
66500 __setup("reset_devices", set_reset_devices);
66501
66502 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66503 +extern char pax_enter_kernel_user[];
66504 +extern char pax_exit_kernel_user[];
66505 +extern pgdval_t clone_pgd_mask;
66506 +#endif
66507 +
66508 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66509 +static int __init setup_pax_nouderef(char *str)
66510 +{
66511 +#ifdef CONFIG_X86_32
66512 + unsigned int cpu;
66513 + struct desc_struct *gdt;
66514 +
66515 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
66516 + gdt = get_cpu_gdt_table(cpu);
66517 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66518 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66519 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66520 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66521 + }
66522 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66523 +#else
66524 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66525 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66526 + clone_pgd_mask = ~(pgdval_t)0UL;
66527 +#endif
66528 +
66529 + return 0;
66530 +}
66531 +early_param("pax_nouderef", setup_pax_nouderef);
66532 +#endif
66533 +
66534 +#ifdef CONFIG_PAX_SOFTMODE
66535 +unsigned int pax_softmode;
66536 +
66537 +static int __init setup_pax_softmode(char *str)
66538 +{
66539 + get_option(&str, &pax_softmode);
66540 + return 1;
66541 +}
66542 +__setup("pax_softmode=", setup_pax_softmode);
66543 +#endif
66544 +
66545 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66546 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66547 static const char *panic_later, *panic_param;
66548 @@ -663,6 +708,7 @@ int __init_or_module do_one_initcall(ini
66549 {
66550 int count = preempt_count();
66551 int ret;
66552 + const char *msg1 = "", *msg2 = "";
66553
66554 if (initcall_debug)
66555 ret = do_one_initcall_debug(fn);
66556 @@ -675,15 +721,15 @@ int __init_or_module do_one_initcall(ini
66557 sprintf(msgbuf, "error code %d ", ret);
66558
66559 if (preempt_count() != count) {
66560 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66561 + msg1 = " preemption imbalance";
66562 preempt_count() = count;
66563 }
66564 if (irqs_disabled()) {
66565 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66566 + msg2 = " disabled interrupts";
66567 local_irq_enable();
66568 }
66569 - if (msgbuf[0]) {
66570 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66571 + if (msgbuf[0] || *msg1 || *msg2) {
66572 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66573 }
66574
66575 return ret;
66576 @@ -801,7 +847,7 @@ static int __init kernel_init(void * unu
66577 do_basic_setup();
66578
66579 /* Open the /dev/console on the rootfs, this should never fail */
66580 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66581 + if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
66582 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66583
66584 (void) sys_dup(0);
66585 @@ -814,11 +860,13 @@ static int __init kernel_init(void * unu
66586 if (!ramdisk_execute_command)
66587 ramdisk_execute_command = "/init";
66588
66589 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66590 + if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
66591 ramdisk_execute_command = NULL;
66592 prepare_namespace();
66593 }
66594
66595 + grsecurity_init();
66596 +
66597 /*
66598 * Ok, we have completed the initial bootup, and
66599 * we're essentially up and running. Get rid of the
66600 diff -urNp linux-2.6.39.1/ipc/mqueue.c linux-2.6.39.1/ipc/mqueue.c
66601 --- linux-2.6.39.1/ipc/mqueue.c 2011-05-19 00:06:34.000000000 -0400
66602 +++ linux-2.6.39.1/ipc/mqueue.c 2011-05-22 19:41:42.000000000 -0400
66603 @@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
66604 mq_bytes = (mq_msg_tblsz +
66605 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66606
66607 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66608 spin_lock(&mq_lock);
66609 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66610 u->mq_bytes + mq_bytes >
66611 diff -urNp linux-2.6.39.1/ipc/sem.c linux-2.6.39.1/ipc/sem.c
66612 --- linux-2.6.39.1/ipc/sem.c 2011-05-19 00:06:34.000000000 -0400
66613 +++ linux-2.6.39.1/ipc/sem.c 2011-05-22 19:36:33.000000000 -0400
66614 @@ -854,6 +854,8 @@ static int semctl_main(struct ipc_namesp
66615 int nsems;
66616 struct list_head tasks;
66617
66618 + pax_track_stack();
66619 +
66620 sma = sem_lock_check(ns, semid);
66621 if (IS_ERR(sma))
66622 return PTR_ERR(sma);
66623 @@ -1301,6 +1303,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
66624 struct ipc_namespace *ns;
66625 struct list_head tasks;
66626
66627 + pax_track_stack();
66628 +
66629 ns = current->nsproxy->ipc_ns;
66630
66631 if (nsops < 1 || semid < 0)
66632 diff -urNp linux-2.6.39.1/ipc/shm.c linux-2.6.39.1/ipc/shm.c
66633 --- linux-2.6.39.1/ipc/shm.c 2011-05-19 00:06:34.000000000 -0400
66634 +++ linux-2.6.39.1/ipc/shm.c 2011-05-22 19:41:42.000000000 -0400
66635 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
66636 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66637 #endif
66638
66639 +#ifdef CONFIG_GRKERNSEC
66640 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66641 + const time_t shm_createtime, const uid_t cuid,
66642 + const int shmid);
66643 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66644 + const time_t shm_createtime);
66645 +#endif
66646 +
66647 void shm_init_ns(struct ipc_namespace *ns)
66648 {
66649 ns->shm_ctlmax = SHMMAX;
66650 @@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
66651 shp->shm_lprid = 0;
66652 shp->shm_atim = shp->shm_dtim = 0;
66653 shp->shm_ctim = get_seconds();
66654 +#ifdef CONFIG_GRKERNSEC
66655 + {
66656 + struct timespec timeval;
66657 + do_posix_clock_monotonic_gettime(&timeval);
66658 +
66659 + shp->shm_createtime = timeval.tv_sec;
66660 + }
66661 +#endif
66662 shp->shm_segsz = size;
66663 shp->shm_nattch = 0;
66664 shp->shm_file = file;
66665 @@ -762,8 +778,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
66666 case SHM_LOCK:
66667 case SHM_UNLOCK:
66668 {
66669 - struct file *uninitialized_var(shm_file);
66670 -
66671 lru_add_drain_all(); /* drain pagevecs to lru lists */
66672
66673 shp = shm_lock_check(ns, shmid);
66674 @@ -896,9 +910,21 @@ long do_shmat(int shmid, char __user *sh
66675 if (err)
66676 goto out_unlock;
66677
66678 +#ifdef CONFIG_GRKERNSEC
66679 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66680 + shp->shm_perm.cuid, shmid) ||
66681 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66682 + err = -EACCES;
66683 + goto out_unlock;
66684 + }
66685 +#endif
66686 +
66687 path = shp->shm_file->f_path;
66688 path_get(&path);
66689 shp->shm_nattch++;
66690 +#ifdef CONFIG_GRKERNSEC
66691 + shp->shm_lapid = current->pid;
66692 +#endif
66693 size = i_size_read(path.dentry->d_inode);
66694 shm_unlock(shp);
66695
66696 diff -urNp linux-2.6.39.1/kernel/acct.c linux-2.6.39.1/kernel/acct.c
66697 --- linux-2.6.39.1/kernel/acct.c 2011-05-19 00:06:34.000000000 -0400
66698 +++ linux-2.6.39.1/kernel/acct.c 2011-05-22 19:36:33.000000000 -0400
66699 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
66700 */
66701 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66702 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66703 - file->f_op->write(file, (char *)&ac,
66704 + file->f_op->write(file, (__force char __user *)&ac,
66705 sizeof(acct_t), &file->f_pos);
66706 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66707 set_fs(fs);
66708 diff -urNp linux-2.6.39.1/kernel/audit.c linux-2.6.39.1/kernel/audit.c
66709 --- linux-2.6.39.1/kernel/audit.c 2011-05-19 00:06:34.000000000 -0400
66710 +++ linux-2.6.39.1/kernel/audit.c 2011-05-22 19:36:33.000000000 -0400
66711 @@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
66712 3) suppressed due to audit_rate_limit
66713 4) suppressed due to audit_backlog_limit
66714 */
66715 -static atomic_t audit_lost = ATOMIC_INIT(0);
66716 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66717
66718 /* The netlink socket. */
66719 static struct sock *audit_sock;
66720 @@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
66721 unsigned long now;
66722 int print;
66723
66724 - atomic_inc(&audit_lost);
66725 + atomic_inc_unchecked(&audit_lost);
66726
66727 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66728
66729 @@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
66730 printk(KERN_WARNING
66731 "audit: audit_lost=%d audit_rate_limit=%d "
66732 "audit_backlog_limit=%d\n",
66733 - atomic_read(&audit_lost),
66734 + atomic_read_unchecked(&audit_lost),
66735 audit_rate_limit,
66736 audit_backlog_limit);
66737 audit_panic(message);
66738 @@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
66739 status_set.pid = audit_pid;
66740 status_set.rate_limit = audit_rate_limit;
66741 status_set.backlog_limit = audit_backlog_limit;
66742 - status_set.lost = atomic_read(&audit_lost);
66743 + status_set.lost = atomic_read_unchecked(&audit_lost);
66744 status_set.backlog = skb_queue_len(&audit_skb_queue);
66745 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66746 &status_set, sizeof(status_set));
66747 diff -urNp linux-2.6.39.1/kernel/auditsc.c linux-2.6.39.1/kernel/auditsc.c
66748 --- linux-2.6.39.1/kernel/auditsc.c 2011-05-19 00:06:34.000000000 -0400
66749 +++ linux-2.6.39.1/kernel/auditsc.c 2011-05-22 19:36:33.000000000 -0400
66750 @@ -2111,7 +2111,7 @@ int auditsc_get_stamp(struct audit_conte
66751 }
66752
66753 /* global counter which is incremented every time something logs in */
66754 -static atomic_t session_id = ATOMIC_INIT(0);
66755 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66756
66757 /**
66758 * audit_set_loginuid - set a task's audit_context loginuid
66759 @@ -2124,7 +2124,7 @@ static atomic_t session_id = ATOMIC_INIT
66760 */
66761 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
66762 {
66763 - unsigned int sessionid = atomic_inc_return(&session_id);
66764 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
66765 struct audit_context *context = task->audit_context;
66766
66767 if (context && context->in_syscall) {
66768 diff -urNp linux-2.6.39.1/kernel/capability.c linux-2.6.39.1/kernel/capability.c
66769 --- linux-2.6.39.1/kernel/capability.c 2011-05-19 00:06:34.000000000 -0400
66770 +++ linux-2.6.39.1/kernel/capability.c 2011-05-22 21:02:23.000000000 -0400
66771 @@ -206,6 +206,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
66772 * before modification is attempted and the application
66773 * fails.
66774 */
66775 + if (tocopy > ARRAY_SIZE(kdata))
66776 + return -EFAULT;
66777 +
66778 if (copy_to_user(dataptr, kdata, tocopy
66779 * sizeof(struct __user_cap_data_struct))) {
66780 return -EFAULT;
66781 @@ -378,7 +381,7 @@ bool ns_capable(struct user_namespace *n
66782 BUG();
66783 }
66784
66785 - if (security_capable(ns, current_cred(), cap) == 0) {
66786 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
66787 current->flags |= PF_SUPERPRIV;
66788 return true;
66789 }
66790 @@ -386,6 +389,27 @@ bool ns_capable(struct user_namespace *n
66791 }
66792 EXPORT_SYMBOL(ns_capable);
66793
66794 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66795 +{
66796 + if (unlikely(!cap_valid(cap))) {
66797 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66798 + BUG();
66799 + }
66800 +
66801 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
66802 + current->flags |= PF_SUPERPRIV;
66803 + return true;
66804 + }
66805 + return false;
66806 +}
66807 +EXPORT_SYMBOL(ns_capable_nolog);
66808 +
66809 +bool capable_nolog(int cap)
66810 +{
66811 + return ns_capable_nolog(&init_user_ns, cap);
66812 +}
66813 +EXPORT_SYMBOL(capable_nolog);
66814 +
66815 /**
66816 * task_ns_capable - Determine whether current task has a superior
66817 * capability targeted at a specific task's user namespace.
66818 @@ -400,6 +424,12 @@ bool task_ns_capable(struct task_struct
66819 }
66820 EXPORT_SYMBOL(task_ns_capable);
66821
66822 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
66823 +{
66824 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
66825 +}
66826 +EXPORT_SYMBOL(task_ns_capable_nolog);
66827 +
66828 /**
66829 * nsown_capable - Check superior capability to one's own user_ns
66830 * @cap: The capability in question
66831 diff -urNp linux-2.6.39.1/kernel/cgroup.c linux-2.6.39.1/kernel/cgroup.c
66832 --- linux-2.6.39.1/kernel/cgroup.c 2011-05-19 00:06:34.000000000 -0400
66833 +++ linux-2.6.39.1/kernel/cgroup.c 2011-05-22 19:36:33.000000000 -0400
66834 @@ -598,6 +598,8 @@ static struct css_set *find_css_set(
66835 struct hlist_head *hhead;
66836 struct cg_cgroup_link *link;
66837
66838 + pax_track_stack();
66839 +
66840 /* First see if we already have a cgroup group that matches
66841 * the desired set */
66842 read_lock(&css_set_lock);
66843 diff -urNp linux-2.6.39.1/kernel/compat.c linux-2.6.39.1/kernel/compat.c
66844 --- linux-2.6.39.1/kernel/compat.c 2011-05-19 00:06:34.000000000 -0400
66845 +++ linux-2.6.39.1/kernel/compat.c 2011-05-22 19:41:42.000000000 -0400
66846 @@ -13,6 +13,7 @@
66847
66848 #include <linux/linkage.h>
66849 #include <linux/compat.h>
66850 +#include <linux/module.h>
66851 #include <linux/errno.h>
66852 #include <linux/time.h>
66853 #include <linux/signal.h>
66854 diff -urNp linux-2.6.39.1/kernel/configs.c linux-2.6.39.1/kernel/configs.c
66855 --- linux-2.6.39.1/kernel/configs.c 2011-05-19 00:06:34.000000000 -0400
66856 +++ linux-2.6.39.1/kernel/configs.c 2011-05-22 19:41:42.000000000 -0400
66857 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66858 struct proc_dir_entry *entry;
66859
66860 /* create the current config file */
66861 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66862 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66863 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66864 + &ikconfig_file_ops);
66865 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66866 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66867 + &ikconfig_file_ops);
66868 +#endif
66869 +#else
66870 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66871 &ikconfig_file_ops);
66872 +#endif
66873 +
66874 if (!entry)
66875 return -ENOMEM;
66876
66877 diff -urNp linux-2.6.39.1/kernel/cred.c linux-2.6.39.1/kernel/cred.c
66878 --- linux-2.6.39.1/kernel/cred.c 2011-05-19 00:06:34.000000000 -0400
66879 +++ linux-2.6.39.1/kernel/cred.c 2011-05-22 19:41:42.000000000 -0400
66880 @@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
66881 */
66882 void __put_cred(struct cred *cred)
66883 {
66884 + pax_track_stack();
66885 +
66886 kdebug("__put_cred(%p{%d,%d})", cred,
66887 atomic_read(&cred->usage),
66888 read_cred_subscribers(cred));
66889 @@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
66890 {
66891 struct cred *cred;
66892
66893 + pax_track_stack();
66894 +
66895 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
66896 atomic_read(&tsk->cred->usage),
66897 read_cred_subscribers(tsk->cred));
66898 @@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
66899 {
66900 const struct cred *cred;
66901
66902 + pax_track_stack();
66903 +
66904 rcu_read_lock();
66905
66906 do {
66907 @@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
66908 {
66909 struct cred *new;
66910
66911 + pax_track_stack();
66912 +
66913 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
66914 if (!new)
66915 return NULL;
66916 @@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
66917 const struct cred *old;
66918 struct cred *new;
66919
66920 + pax_track_stack();
66921 +
66922 validate_process_creds();
66923
66924 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66925 @@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
66926 struct thread_group_cred *tgcred = NULL;
66927 struct cred *new;
66928
66929 + pax_track_stack();
66930 +
66931 #ifdef CONFIG_KEYS
66932 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
66933 if (!tgcred)
66934 @@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
66935 struct cred *new;
66936 int ret;
66937
66938 + pax_track_stack();
66939 +
66940 if (
66941 #ifdef CONFIG_KEYS
66942 !p->cred->thread_keyring &&
66943 @@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
66944 struct task_struct *task = current;
66945 const struct cred *old = task->real_cred;
66946
66947 + pax_track_stack();
66948 +
66949 kdebug("commit_creds(%p{%d,%d})", new,
66950 atomic_read(&new->usage),
66951 read_cred_subscribers(new));
66952 @@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
66953
66954 get_cred(new); /* we will require a ref for the subj creds too */
66955
66956 + gr_set_role_label(task, new->uid, new->gid);
66957 +
66958 /* dumpability changes */
66959 if (old->euid != new->euid ||
66960 old->egid != new->egid ||
66961 @@ -551,6 +569,8 @@ EXPORT_SYMBOL(commit_creds);
66962 */
66963 void abort_creds(struct cred *new)
66964 {
66965 + pax_track_stack();
66966 +
66967 kdebug("abort_creds(%p{%d,%d})", new,
66968 atomic_read(&new->usage),
66969 read_cred_subscribers(new));
66970 @@ -574,6 +594,8 @@ const struct cred *override_creds(const
66971 {
66972 const struct cred *old = current->cred;
66973
66974 + pax_track_stack();
66975 +
66976 kdebug("override_creds(%p{%d,%d})", new,
66977 atomic_read(&new->usage),
66978 read_cred_subscribers(new));
66979 @@ -603,6 +625,8 @@ void revert_creds(const struct cred *old
66980 {
66981 const struct cred *override = current->cred;
66982
66983 + pax_track_stack();
66984 +
66985 kdebug("revert_creds(%p{%d,%d})", old,
66986 atomic_read(&old->usage),
66987 read_cred_subscribers(old));
66988 @@ -649,6 +673,8 @@ struct cred *prepare_kernel_cred(struct
66989 const struct cred *old;
66990 struct cred *new;
66991
66992 + pax_track_stack();
66993 +
66994 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66995 if (!new)
66996 return NULL;
66997 @@ -703,6 +729,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
66998 */
66999 int set_security_override(struct cred *new, u32 secid)
67000 {
67001 + pax_track_stack();
67002 +
67003 return security_kernel_act_as(new, secid);
67004 }
67005 EXPORT_SYMBOL(set_security_override);
67006 @@ -722,6 +750,8 @@ int set_security_override_from_ctx(struc
67007 u32 secid;
67008 int ret;
67009
67010 + pax_track_stack();
67011 +
67012 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
67013 if (ret < 0)
67014 return ret;
67015 diff -urNp linux-2.6.39.1/kernel/debug/debug_core.c linux-2.6.39.1/kernel/debug/debug_core.c
67016 --- linux-2.6.39.1/kernel/debug/debug_core.c 2011-05-19 00:06:34.000000000 -0400
67017 +++ linux-2.6.39.1/kernel/debug/debug_core.c 2011-05-22 19:36:33.000000000 -0400
67018 @@ -72,7 +72,7 @@ int kgdb_io_module_registered;
67019 /* Guard for recursive entry */
67020 static int exception_level;
67021
67022 -struct kgdb_io *dbg_io_ops;
67023 +const struct kgdb_io *dbg_io_ops;
67024 static DEFINE_SPINLOCK(kgdb_registration_lock);
67025
67026 /* kgdb console driver is loaded */
67027 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
67028 */
67029 static atomic_t masters_in_kgdb;
67030 static atomic_t slaves_in_kgdb;
67031 -static atomic_t kgdb_break_tasklet_var;
67032 +static atomic_unchecked_t kgdb_break_tasklet_var;
67033 atomic_t kgdb_setting_breakpoint;
67034
67035 struct task_struct *kgdb_usethread;
67036 @@ -129,7 +129,7 @@ int kgdb_single_step;
67037 static pid_t kgdb_sstep_pid;
67038
67039 /* to keep track of the CPU which is doing the single stepping*/
67040 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67041 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67042
67043 /*
67044 * If you are debugging a problem where roundup (the collection of
67045 @@ -542,7 +542,7 @@ return_normal:
67046 * kernel will only try for the value of sstep_tries before
67047 * giving up and continuing on.
67048 */
67049 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67050 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67051 (kgdb_info[cpu].task &&
67052 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67053 atomic_set(&kgdb_active, -1);
67054 @@ -636,8 +636,8 @@ cpu_master_loop:
67055 }
67056
67057 kgdb_restore:
67058 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67059 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67060 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67061 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67062 if (kgdb_info[sstep_cpu].task)
67063 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67064 else
67065 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
67066 static void kgdb_tasklet_bpt(unsigned long ing)
67067 {
67068 kgdb_breakpoint();
67069 - atomic_set(&kgdb_break_tasklet_var, 0);
67070 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67071 }
67072
67073 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67074
67075 void kgdb_schedule_breakpoint(void)
67076 {
67077 - if (atomic_read(&kgdb_break_tasklet_var) ||
67078 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67079 atomic_read(&kgdb_active) != -1 ||
67080 atomic_read(&kgdb_setting_breakpoint))
67081 return;
67082 - atomic_inc(&kgdb_break_tasklet_var);
67083 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67084 tasklet_schedule(&kgdb_tasklet_breakpoint);
67085 }
67086 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67087 @@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
67088 *
67089 * Register it with the KGDB core.
67090 */
67091 -int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
67092 +int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
67093 {
67094 int err;
67095
67096 @@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
67097 *
67098 * Unregister it with the KGDB core.
67099 */
67100 -void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
67101 +void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
67102 {
67103 BUG_ON(kgdb_connected);
67104
67105 diff -urNp linux-2.6.39.1/kernel/debug/kdb/kdb_main.c linux-2.6.39.1/kernel/debug/kdb/kdb_main.c
67106 --- linux-2.6.39.1/kernel/debug/kdb/kdb_main.c 2011-05-19 00:06:34.000000000 -0400
67107 +++ linux-2.6.39.1/kernel/debug/kdb/kdb_main.c 2011-05-22 19:36:33.000000000 -0400
67108 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
67109 list_for_each_entry(mod, kdb_modules, list) {
67110
67111 kdb_printf("%-20s%8u 0x%p ", mod->name,
67112 - mod->core_size, (void *)mod);
67113 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67114 #ifdef CONFIG_MODULE_UNLOAD
67115 kdb_printf("%4d ", module_refcount(mod));
67116 #endif
67117 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
67118 kdb_printf(" (Loading)");
67119 else
67120 kdb_printf(" (Live)");
67121 - kdb_printf(" 0x%p", mod->module_core);
67122 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67123
67124 #ifdef CONFIG_MODULE_UNLOAD
67125 {
67126 diff -urNp linux-2.6.39.1/kernel/exit.c linux-2.6.39.1/kernel/exit.c
67127 --- linux-2.6.39.1/kernel/exit.c 2011-05-19 00:06:34.000000000 -0400
67128 +++ linux-2.6.39.1/kernel/exit.c 2011-05-22 20:02:30.000000000 -0400
67129 @@ -57,6 +57,10 @@
67130 #include <asm/pgtable.h>
67131 #include <asm/mmu_context.h>
67132
67133 +#ifdef CONFIG_GRKERNSEC
67134 +extern rwlock_t grsec_exec_file_lock;
67135 +#endif
67136 +
67137 static void exit_mm(struct task_struct * tsk);
67138
67139 static void __unhash_process(struct task_struct *p, bool group_dead)
67140 @@ -169,6 +173,8 @@ void release_task(struct task_struct * p
67141 struct task_struct *leader;
67142 int zap_leader;
67143 repeat:
67144 + gr_del_task_from_ip_table(p);
67145 +
67146 tracehook_prepare_release_task(p);
67147 /* don't need to get the RCU readlock here - the process is dead and
67148 * can't be modifying its own credentials. But shut RCU-lockdep up */
67149 @@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
67150 {
67151 write_lock_irq(&tasklist_lock);
67152
67153 +#ifdef CONFIG_GRKERNSEC
67154 + write_lock(&grsec_exec_file_lock);
67155 + if (current->exec_file) {
67156 + fput(current->exec_file);
67157 + current->exec_file = NULL;
67158 + }
67159 + write_unlock(&grsec_exec_file_lock);
67160 +#endif
67161 +
67162 ptrace_unlink(current);
67163 /* Reparent to init */
67164 current->real_parent = current->parent = kthreadd_task;
67165 list_move_tail(&current->sibling, &current->real_parent->children);
67166
67167 + gr_set_kernel_label(current);
67168 +
67169 /* Set the exit signal to SIGCHLD so we signal init on exit */
67170 current->exit_signal = SIGCHLD;
67171
67172 @@ -394,7 +411,7 @@ int allow_signal(int sig)
67173 * know it'll be handled, so that they don't get converted to
67174 * SIGKILL or just silently dropped.
67175 */
67176 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67177 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67178 recalc_sigpending();
67179 spin_unlock_irq(&current->sighand->siglock);
67180 return 0;
67181 @@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
67182 vsnprintf(current->comm, sizeof(current->comm), name, args);
67183 va_end(args);
67184
67185 +#ifdef CONFIG_GRKERNSEC
67186 + write_lock(&grsec_exec_file_lock);
67187 + if (current->exec_file) {
67188 + fput(current->exec_file);
67189 + current->exec_file = NULL;
67190 + }
67191 + write_unlock(&grsec_exec_file_lock);
67192 +#endif
67193 +
67194 + gr_set_kernel_label(current);
67195 +
67196 /*
67197 * If we were started as result of loading a module, close all of the
67198 * user space pages. We don't need them, and if we didn't close them
67199 @@ -905,15 +933,8 @@ NORET_TYPE void do_exit(long code)
67200 struct task_struct *tsk = current;
67201 int group_dead;
67202
67203 - profile_task_exit(tsk);
67204 -
67205 - WARN_ON(atomic_read(&tsk->fs_excl));
67206 - WARN_ON(blk_needs_flush_plug(tsk));
67207 -
67208 if (unlikely(in_interrupt()))
67209 panic("Aiee, killing interrupt handler!");
67210 - if (unlikely(!tsk->pid))
67211 - panic("Attempted to kill the idle task!");
67212
67213 /*
67214 * If do_exit is called because this processes oopsed, it's possible
67215 @@ -924,6 +945,14 @@ NORET_TYPE void do_exit(long code)
67216 */
67217 set_fs(USER_DS);
67218
67219 + profile_task_exit(tsk);
67220 +
67221 + WARN_ON(atomic_read(&tsk->fs_excl));
67222 + WARN_ON(blk_needs_flush_plug(tsk));
67223 +
67224 + if (unlikely(!tsk->pid))
67225 + panic("Attempted to kill the idle task!");
67226 +
67227 tracehook_report_exit(&code);
67228
67229 validate_creds_for_do_exit(tsk);
67230 @@ -984,6 +1013,9 @@ NORET_TYPE void do_exit(long code)
67231 tsk->exit_code = code;
67232 taskstats_exit(tsk, group_dead);
67233
67234 + gr_acl_handle_psacct(tsk, code);
67235 + gr_acl_handle_exit();
67236 +
67237 exit_mm(tsk);
67238
67239 if (group_dead)
67240 diff -urNp linux-2.6.39.1/kernel/fork.c linux-2.6.39.1/kernel/fork.c
67241 --- linux-2.6.39.1/kernel/fork.c 2011-05-19 00:06:34.000000000 -0400
67242 +++ linux-2.6.39.1/kernel/fork.c 2011-05-22 19:41:42.000000000 -0400
67243 @@ -287,7 +287,7 @@ static struct task_struct *dup_task_stru
67244 *stackend = STACK_END_MAGIC; /* for overflow detection */
67245
67246 #ifdef CONFIG_CC_STACKPROTECTOR
67247 - tsk->stack_canary = get_random_int();
67248 + tsk->stack_canary = pax_get_random_long();
67249 #endif
67250
67251 /* One for us, one for whoever does the "release_task()" (usually parent) */
67252 @@ -309,13 +309,78 @@ out:
67253 }
67254
67255 #ifdef CONFIG_MMU
67256 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
67257 +{
67258 + struct vm_area_struct *tmp;
67259 + unsigned long charge;
67260 + struct mempolicy *pol;
67261 + struct file *file;
67262 +
67263 + charge = 0;
67264 + if (mpnt->vm_flags & VM_ACCOUNT) {
67265 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67266 + if (security_vm_enough_memory(len))
67267 + goto fail_nomem;
67268 + charge = len;
67269 + }
67270 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67271 + if (!tmp)
67272 + goto fail_nomem;
67273 + *tmp = *mpnt;
67274 + tmp->vm_mm = mm;
67275 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67276 + pol = mpol_dup(vma_policy(mpnt));
67277 + if (IS_ERR(pol))
67278 + goto fail_nomem_policy;
67279 + vma_set_policy(tmp, pol);
67280 + if (anon_vma_fork(tmp, mpnt))
67281 + goto fail_nomem_anon_vma_fork;
67282 + tmp->vm_flags &= ~VM_LOCKED;
67283 + tmp->vm_next = tmp->vm_prev = NULL;
67284 + tmp->vm_mirror = NULL;
67285 + file = tmp->vm_file;
67286 + if (file) {
67287 + struct inode *inode = file->f_path.dentry->d_inode;
67288 + struct address_space *mapping = file->f_mapping;
67289 +
67290 + get_file(file);
67291 + if (tmp->vm_flags & VM_DENYWRITE)
67292 + atomic_dec(&inode->i_writecount);
67293 + spin_lock(&mapping->i_mmap_lock);
67294 + if (tmp->vm_flags & VM_SHARED)
67295 + mapping->i_mmap_writable++;
67296 + tmp->vm_truncate_count = mpnt->vm_truncate_count;
67297 + flush_dcache_mmap_lock(mapping);
67298 + /* insert tmp into the share list, just after mpnt */
67299 + vma_prio_tree_add(tmp, mpnt);
67300 + flush_dcache_mmap_unlock(mapping);
67301 + spin_unlock(&mapping->i_mmap_lock);
67302 + }
67303 +
67304 + /*
67305 + * Clear hugetlb-related page reserves for children. This only
67306 + * affects MAP_PRIVATE mappings. Faults generated by the child
67307 + * are not guaranteed to succeed, even if read-only
67308 + */
67309 + if (is_vm_hugetlb_page(tmp))
67310 + reset_vma_resv_huge_pages(tmp);
67311 +
67312 + return tmp;
67313 +
67314 +fail_nomem_anon_vma_fork:
67315 + mpol_put(pol);
67316 +fail_nomem_policy:
67317 + kmem_cache_free(vm_area_cachep, tmp);
67318 +fail_nomem:
67319 + vm_unacct_memory(charge);
67320 + return NULL;
67321 +}
67322 +
67323 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67324 {
67325 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67326 struct rb_node **rb_link, *rb_parent;
67327 int retval;
67328 - unsigned long charge;
67329 - struct mempolicy *pol;
67330
67331 down_write(&oldmm->mmap_sem);
67332 flush_cache_dup_mm(oldmm);
67333 @@ -327,8 +392,8 @@ static int dup_mmap(struct mm_struct *mm
67334 mm->locked_vm = 0;
67335 mm->mmap = NULL;
67336 mm->mmap_cache = NULL;
67337 - mm->free_area_cache = oldmm->mmap_base;
67338 - mm->cached_hole_size = ~0UL;
67339 + mm->free_area_cache = oldmm->free_area_cache;
67340 + mm->cached_hole_size = oldmm->cached_hole_size;
67341 mm->map_count = 0;
67342 cpumask_clear(mm_cpumask(mm));
67343 mm->mm_rb = RB_ROOT;
67344 @@ -344,8 +409,6 @@ static int dup_mmap(struct mm_struct *mm
67345
67346 prev = NULL;
67347 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67348 - struct file *file;
67349 -
67350 if (mpnt->vm_flags & VM_DONTCOPY) {
67351 long pages = vma_pages(mpnt);
67352 mm->total_vm -= pages;
67353 @@ -353,56 +416,13 @@ static int dup_mmap(struct mm_struct *mm
67354 -pages);
67355 continue;
67356 }
67357 - charge = 0;
67358 - if (mpnt->vm_flags & VM_ACCOUNT) {
67359 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67360 - if (security_vm_enough_memory(len))
67361 - goto fail_nomem;
67362 - charge = len;
67363 - }
67364 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67365 - if (!tmp)
67366 - goto fail_nomem;
67367 - *tmp = *mpnt;
67368 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67369 - pol = mpol_dup(vma_policy(mpnt));
67370 - retval = PTR_ERR(pol);
67371 - if (IS_ERR(pol))
67372 - goto fail_nomem_policy;
67373 - vma_set_policy(tmp, pol);
67374 - tmp->vm_mm = mm;
67375 - if (anon_vma_fork(tmp, mpnt))
67376 - goto fail_nomem_anon_vma_fork;
67377 - tmp->vm_flags &= ~VM_LOCKED;
67378 - tmp->vm_next = tmp->vm_prev = NULL;
67379 - file = tmp->vm_file;
67380 - if (file) {
67381 - struct inode *inode = file->f_path.dentry->d_inode;
67382 - struct address_space *mapping = file->f_mapping;
67383 -
67384 - get_file(file);
67385 - if (tmp->vm_flags & VM_DENYWRITE)
67386 - atomic_dec(&inode->i_writecount);
67387 - spin_lock(&mapping->i_mmap_lock);
67388 - if (tmp->vm_flags & VM_SHARED)
67389 - mapping->i_mmap_writable++;
67390 - tmp->vm_truncate_count = mpnt->vm_truncate_count;
67391 - flush_dcache_mmap_lock(mapping);
67392 - /* insert tmp into the share list, just after mpnt */
67393 - vma_prio_tree_add(tmp, mpnt);
67394 - flush_dcache_mmap_unlock(mapping);
67395 - spin_unlock(&mapping->i_mmap_lock);
67396 + tmp = dup_vma(mm, mpnt);
67397 + if (!tmp) {
67398 + retval = -ENOMEM;
67399 + goto out;
67400 }
67401
67402 /*
67403 - * Clear hugetlb-related page reserves for children. This only
67404 - * affects MAP_PRIVATE mappings. Faults generated by the child
67405 - * are not guaranteed to succeed, even if read-only
67406 - */
67407 - if (is_vm_hugetlb_page(tmp))
67408 - reset_vma_resv_huge_pages(tmp);
67409 -
67410 - /*
67411 * Link in the new vma and copy the page table entries.
67412 */
67413 *pprev = tmp;
67414 @@ -423,6 +443,31 @@ static int dup_mmap(struct mm_struct *mm
67415 if (retval)
67416 goto out;
67417 }
67418 +
67419 +#ifdef CONFIG_PAX_SEGMEXEC
67420 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67421 + struct vm_area_struct *mpnt_m;
67422 +
67423 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67424 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67425 +
67426 + if (!mpnt->vm_mirror)
67427 + continue;
67428 +
67429 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67430 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67431 + mpnt->vm_mirror = mpnt_m;
67432 + } else {
67433 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67434 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67435 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67436 + mpnt->vm_mirror->vm_mirror = mpnt;
67437 + }
67438 + }
67439 + BUG_ON(mpnt_m);
67440 + }
67441 +#endif
67442 +
67443 /* a new mm has just been created */
67444 arch_dup_mmap(oldmm, mm);
67445 retval = 0;
67446 @@ -431,14 +476,6 @@ out:
67447 flush_tlb_mm(oldmm);
67448 up_write(&oldmm->mmap_sem);
67449 return retval;
67450 -fail_nomem_anon_vma_fork:
67451 - mpol_put(pol);
67452 -fail_nomem_policy:
67453 - kmem_cache_free(vm_area_cachep, tmp);
67454 -fail_nomem:
67455 - retval = -ENOMEM;
67456 - vm_unacct_memory(charge);
67457 - goto out;
67458 }
67459
67460 static inline int mm_alloc_pgd(struct mm_struct * mm)
67461 @@ -785,13 +822,14 @@ static int copy_fs(unsigned long clone_f
67462 spin_unlock(&fs->lock);
67463 return -EAGAIN;
67464 }
67465 - fs->users++;
67466 + atomic_inc(&fs->users);
67467 spin_unlock(&fs->lock);
67468 return 0;
67469 }
67470 tsk->fs = copy_fs_struct(fs);
67471 if (!tsk->fs)
67472 return -ENOMEM;
67473 + gr_set_chroot_entries(tsk, &tsk->fs->root);
67474 return 0;
67475 }
67476
67477 @@ -1049,10 +1087,13 @@ static struct task_struct *copy_process(
67478 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67479 #endif
67480 retval = -EAGAIN;
67481 +
67482 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67483 +
67484 if (atomic_read(&p->real_cred->user->processes) >=
67485 task_rlimit(p, RLIMIT_NPROC)) {
67486 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67487 - p->real_cred->user != INIT_USER)
67488 + if (p->real_cred->user != INIT_USER &&
67489 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
67490 goto bad_fork_free;
67491 }
67492
67493 @@ -1200,6 +1241,8 @@ static struct task_struct *copy_process(
67494 goto bad_fork_free_pid;
67495 }
67496
67497 + gr_copy_label(p);
67498 +
67499 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67500 /*
67501 * Clear TID on mm_release()?
67502 @@ -1360,6 +1403,8 @@ bad_fork_cleanup_count:
67503 bad_fork_free:
67504 free_task(p);
67505 fork_out:
67506 + gr_log_forkfail(retval);
67507 +
67508 return ERR_PTR(retval);
67509 }
67510
67511 @@ -1448,6 +1493,8 @@ long do_fork(unsigned long clone_flags,
67512 if (clone_flags & CLONE_PARENT_SETTID)
67513 put_user(nr, parent_tidptr);
67514
67515 + gr_handle_brute_check();
67516 +
67517 if (clone_flags & CLONE_VFORK) {
67518 p->vfork_done = &vfork;
67519 init_completion(&vfork);
67520 @@ -1549,7 +1596,7 @@ static int unshare_fs(unsigned long unsh
67521 return 0;
67522
67523 /* don't need lock here; in the worst case we'll do useless copy */
67524 - if (fs->users == 1)
67525 + if (atomic_read(&fs->users) == 1)
67526 return 0;
67527
67528 *new_fsp = copy_fs_struct(fs);
67529 @@ -1636,7 +1683,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
67530 fs = current->fs;
67531 spin_lock(&fs->lock);
67532 current->fs = new_fs;
67533 - if (--fs->users)
67534 + gr_set_chroot_entries(current, &current->fs->root);
67535 + if (atomic_dec_return(&fs->users))
67536 new_fs = NULL;
67537 else
67538 new_fs = fs;
67539 diff -urNp linux-2.6.39.1/kernel/futex.c linux-2.6.39.1/kernel/futex.c
67540 --- linux-2.6.39.1/kernel/futex.c 2011-05-19 00:06:34.000000000 -0400
67541 +++ linux-2.6.39.1/kernel/futex.c 2011-05-22 22:41:57.000000000 -0400
67542 @@ -54,6 +54,7 @@
67543 #include <linux/mount.h>
67544 #include <linux/pagemap.h>
67545 #include <linux/syscalls.h>
67546 +#include <linux/ptrace.h>
67547 #include <linux/signal.h>
67548 #include <linux/module.h>
67549 #include <linux/magic.h>
67550 @@ -236,6 +237,11 @@ get_futex_key(u32 __user *uaddr, int fsh
67551 struct page *page, *page_head;
67552 int err;
67553
67554 +#ifdef CONFIG_PAX_SEGMEXEC
67555 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67556 + return -EFAULT;
67557 +#endif
67558 +
67559 /*
67560 * The futex address must be "naturally" aligned.
67561 */
67562 @@ -1833,6 +1839,8 @@ static int futex_wait(u32 __user *uaddr,
67563 struct futex_q q = futex_q_init;
67564 int ret;
67565
67566 + pax_track_stack();
67567 +
67568 if (!bitset)
67569 return -EINVAL;
67570 q.bitset = bitset;
67571 @@ -2229,6 +2237,8 @@ static int futex_wait_requeue_pi(u32 __u
67572 struct futex_q q = futex_q_init;
67573 int res, ret;
67574
67575 + pax_track_stack();
67576 +
67577 if (!bitset)
67578 return -EINVAL;
67579
67580 @@ -2401,7 +2411,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67581 {
67582 struct robust_list_head __user *head;
67583 unsigned long ret;
67584 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67585 const struct cred *cred = current_cred(), *pcred;
67586 +#endif
67587
67588 if (!futex_cmpxchg_enabled)
67589 return -ENOSYS;
67590 @@ -2417,6 +2429,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67591 if (!p)
67592 goto err_unlock;
67593 ret = -EPERM;
67594 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67595 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67596 + goto err_unlock;
67597 +#else
67598 pcred = __task_cred(p);
67599 /* If victim is in different user_ns, then uids are not
67600 comparable, so we must have CAP_SYS_PTRACE */
67601 @@ -2431,6 +2447,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67602 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67603 goto err_unlock;
67604 ok:
67605 +#endif
67606 head = p->robust_list;
67607 rcu_read_unlock();
67608 }
67609 @@ -2682,6 +2699,7 @@ static int __init futex_init(void)
67610 {
67611 u32 curval;
67612 int i;
67613 + mm_segment_t oldfs;
67614
67615 /*
67616 * This will fail and we want it. Some arch implementations do
67617 @@ -2693,8 +2711,11 @@ static int __init futex_init(void)
67618 * implementation, the non-functional ones will return
67619 * -ENOSYS.
67620 */
67621 + oldfs = get_fs();
67622 + set_fs(USER_DS);
67623 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67624 futex_cmpxchg_enabled = 1;
67625 + set_fs(oldfs);
67626
67627 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67628 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
67629 diff -urNp linux-2.6.39.1/kernel/futex_compat.c linux-2.6.39.1/kernel/futex_compat.c
67630 --- linux-2.6.39.1/kernel/futex_compat.c 2011-05-19 00:06:34.000000000 -0400
67631 +++ linux-2.6.39.1/kernel/futex_compat.c 2011-05-22 22:42:09.000000000 -0400
67632 @@ -10,6 +10,7 @@
67633 #include <linux/compat.h>
67634 #include <linux/nsproxy.h>
67635 #include <linux/futex.h>
67636 +#include <linux/ptrace.h>
67637
67638 #include <asm/uaccess.h>
67639
67640 @@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
67641 {
67642 struct compat_robust_list_head __user *head;
67643 unsigned long ret;
67644 - const struct cred *cred = current_cred(), *pcred;
67645 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67646 + const struct cred *cred = current_cred();
67647 + const struct cred *pcred;
67648 +#endif
67649
67650 if (!futex_cmpxchg_enabled)
67651 return -ENOSYS;
67652 @@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
67653 if (!p)
67654 goto err_unlock;
67655 ret = -EPERM;
67656 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67657 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67658 + goto err_unlock;
67659 +#else
67660 pcred = __task_cred(p);
67661 /* If victim is in different user_ns, then uids are not
67662 comparable, so we must have CAP_SYS_PTRACE */
67663 @@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
67664 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67665 goto err_unlock;
67666 ok:
67667 +#endif
67668 head = p->compat_robust_list;
67669 rcu_read_unlock();
67670 }
67671 diff -urNp linux-2.6.39.1/kernel/gcov/base.c linux-2.6.39.1/kernel/gcov/base.c
67672 --- linux-2.6.39.1/kernel/gcov/base.c 2011-05-19 00:06:34.000000000 -0400
67673 +++ linux-2.6.39.1/kernel/gcov/base.c 2011-05-22 19:36:33.000000000 -0400
67674 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67675 }
67676
67677 #ifdef CONFIG_MODULES
67678 -static inline int within(void *addr, void *start, unsigned long size)
67679 -{
67680 - return ((addr >= start) && (addr < start + size));
67681 -}
67682 -
67683 /* Update list and generate events when modules are unloaded. */
67684 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67685 void *data)
67686 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
67687 prev = NULL;
67688 /* Remove entries located in module from linked list. */
67689 for (info = gcov_info_head; info; info = info->next) {
67690 - if (within(info, mod->module_core, mod->core_size)) {
67691 + if (within_module_core_rw((unsigned long)info, mod)) {
67692 if (prev)
67693 prev->next = info->next;
67694 else
67695 diff -urNp linux-2.6.39.1/kernel/hrtimer.c linux-2.6.39.1/kernel/hrtimer.c
67696 --- linux-2.6.39.1/kernel/hrtimer.c 2011-05-19 00:06:34.000000000 -0400
67697 +++ linux-2.6.39.1/kernel/hrtimer.c 2011-05-22 19:36:33.000000000 -0400
67698 @@ -1383,7 +1383,7 @@ void hrtimer_peek_ahead_timers(void)
67699 local_irq_restore(flags);
67700 }
67701
67702 -static void run_hrtimer_softirq(struct softirq_action *h)
67703 +static void run_hrtimer_softirq(void)
67704 {
67705 hrtimer_peek_ahead_timers();
67706 }
67707 diff -urNp linux-2.6.39.1/kernel/jump_label.c linux-2.6.39.1/kernel/jump_label.c
67708 --- linux-2.6.39.1/kernel/jump_label.c 2011-05-19 00:06:34.000000000 -0400
67709 +++ linux-2.6.39.1/kernel/jump_label.c 2011-05-22 19:36:33.000000000 -0400
67710 @@ -49,6 +49,17 @@ void jump_label_unlock(void)
67711 mutex_unlock(&jump_label_mutex);
67712 }
67713
67714 +static void jump_label_swap(void *a, void *b, int size)
67715 +{
67716 + struct jump_entry t;
67717 +
67718 + t = *(struct jump_entry *)a;
67719 + pax_open_kernel();
67720 + *(struct jump_entry *)a = *(struct jump_entry *)b;
67721 + *(struct jump_entry *)b = t;
67722 + pax_close_kernel();
67723 +}
67724 +
67725 static int jump_label_cmp(const void *a, const void *b)
67726 {
67727 const struct jump_entry *jea = a;
67728 @@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
67729
67730 size = (((unsigned long)stop - (unsigned long)start)
67731 / sizeof(struct jump_entry));
67732 - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67733 + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
67734 }
67735
67736 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
67737 @@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
67738 count = e_module->nr_entries;
67739 iter = e_module->table;
67740 while (count--) {
67741 - if (within_module_init(iter->code, mod))
67742 + if (within_module_init(iter->code, mod)) {
67743 + pax_open_kernel();
67744 iter->key = 0;
67745 + pax_close_kernel();
67746 + }
67747 iter++;
67748 }
67749 }
67750 diff -urNp linux-2.6.39.1/kernel/kallsyms.c linux-2.6.39.1/kernel/kallsyms.c
67751 --- linux-2.6.39.1/kernel/kallsyms.c 2011-05-19 00:06:34.000000000 -0400
67752 +++ linux-2.6.39.1/kernel/kallsyms.c 2011-05-22 19:41:42.000000000 -0400
67753 @@ -11,6 +11,9 @@
67754 * Changed the compression method from stem compression to "table lookup"
67755 * compression (see scripts/kallsyms.c for a more complete description)
67756 */
67757 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67758 +#define __INCLUDED_BY_HIDESYM 1
67759 +#endif
67760 #include <linux/kallsyms.h>
67761 #include <linux/module.h>
67762 #include <linux/init.h>
67763 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
67764
67765 static inline int is_kernel_inittext(unsigned long addr)
67766 {
67767 + if (system_state != SYSTEM_BOOTING)
67768 + return 0;
67769 +
67770 if (addr >= (unsigned long)_sinittext
67771 && addr <= (unsigned long)_einittext)
67772 return 1;
67773 return 0;
67774 }
67775
67776 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67777 +#ifdef CONFIG_MODULES
67778 +static inline int is_module_text(unsigned long addr)
67779 +{
67780 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67781 + return 1;
67782 +
67783 + addr = ktla_ktva(addr);
67784 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67785 +}
67786 +#else
67787 +static inline int is_module_text(unsigned long addr)
67788 +{
67789 + return 0;
67790 +}
67791 +#endif
67792 +#endif
67793 +
67794 static inline int is_kernel_text(unsigned long addr)
67795 {
67796 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67797 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
67798
67799 static inline int is_kernel(unsigned long addr)
67800 {
67801 +
67802 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67803 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67804 + return 1;
67805 +
67806 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67807 +#else
67808 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67809 +#endif
67810 +
67811 return 1;
67812 return in_gate_area_no_mm(addr);
67813 }
67814
67815 static int is_ksym_addr(unsigned long addr)
67816 {
67817 +
67818 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67819 + if (is_module_text(addr))
67820 + return 0;
67821 +#endif
67822 +
67823 if (all_var)
67824 return is_kernel(addr);
67825
67826 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
67827
67828 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67829 {
67830 - iter->name[0] = '\0';
67831 iter->nameoff = get_symbol_offset(new_pos);
67832 iter->pos = new_pos;
67833 }
67834 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
67835 {
67836 struct kallsym_iter *iter = m->private;
67837
67838 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67839 + if (current_uid())
67840 + return 0;
67841 +#endif
67842 +
67843 /* Some debugging symbols have no name. Ignore them. */
67844 if (!iter->name[0])
67845 return 0;
67846 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
67847 struct kallsym_iter *iter;
67848 int ret;
67849
67850 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67851 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67852 if (!iter)
67853 return -ENOMEM;
67854 reset_iter(iter, 0);
67855 diff -urNp linux-2.6.39.1/kernel/kmod.c linux-2.6.39.1/kernel/kmod.c
67856 --- linux-2.6.39.1/kernel/kmod.c 2011-05-19 00:06:34.000000000 -0400
67857 +++ linux-2.6.39.1/kernel/kmod.c 2011-05-22 19:41:42.000000000 -0400
67858 @@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
67859 * If module auto-loading support is disabled then this function
67860 * becomes a no-operation.
67861 */
67862 -int __request_module(bool wait, const char *fmt, ...)
67863 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67864 {
67865 - va_list args;
67866 char module_name[MODULE_NAME_LEN];
67867 unsigned int max_modprobes;
67868 int ret;
67869 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67870 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67871 static char *envp[] = { "HOME=/",
67872 "TERM=linux",
67873 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67874 @@ -80,9 +79,7 @@ int __request_module(bool wait, const ch
67875 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67876 static int kmod_loop_msg;
67877
67878 - va_start(args, fmt);
67879 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67880 - va_end(args);
67881 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67882 if (ret >= MODULE_NAME_LEN)
67883 return -ENAMETOOLONG;
67884
67885 @@ -90,6 +87,20 @@ int __request_module(bool wait, const ch
67886 if (ret)
67887 return ret;
67888
67889 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67890 + if (!current_uid()) {
67891 + /* hack to workaround consolekit/udisks stupidity */
67892 + read_lock(&tasklist_lock);
67893 + if (!strcmp(current->comm, "mount") &&
67894 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67895 + read_unlock(&tasklist_lock);
67896 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67897 + return -EPERM;
67898 + }
67899 + read_unlock(&tasklist_lock);
67900 + }
67901 +#endif
67902 +
67903 /* If modprobe needs a service that is in a module, we get a recursive
67904 * loop. Limit the number of running kmod threads to max_threads/2 or
67905 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67906 @@ -123,6 +134,47 @@ int __request_module(bool wait, const ch
67907 atomic_dec(&kmod_concurrent);
67908 return ret;
67909 }
67910 +
67911 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67912 +{
67913 + va_list args;
67914 + int ret;
67915 +
67916 + va_start(args, fmt);
67917 + ret = ____request_module(wait, module_param, fmt, args);
67918 + va_end(args);
67919 +
67920 + return ret;
67921 +}
67922 +
67923 +int __request_module(bool wait, const char *fmt, ...)
67924 +{
67925 + va_list args;
67926 + int ret;
67927 +
67928 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67929 + if (current_uid()) {
67930 + char module_param[MODULE_NAME_LEN];
67931 +
67932 + memset(module_param, 0, sizeof(module_param));
67933 +
67934 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67935 +
67936 + va_start(args, fmt);
67937 + ret = ____request_module(wait, module_param, fmt, args);
67938 + va_end(args);
67939 +
67940 + return ret;
67941 + }
67942 +#endif
67943 +
67944 + va_start(args, fmt);
67945 + ret = ____request_module(wait, NULL, fmt, args);
67946 + va_end(args);
67947 +
67948 + return ret;
67949 +}
67950 +
67951 EXPORT_SYMBOL(__request_module);
67952 #endif /* CONFIG_MODULES */
67953
67954 diff -urNp linux-2.6.39.1/kernel/kprobes.c linux-2.6.39.1/kernel/kprobes.c
67955 --- linux-2.6.39.1/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
67956 +++ linux-2.6.39.1/kernel/kprobes.c 2011-05-22 19:36:33.000000000 -0400
67957 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
67958 * kernel image and loaded module images reside. This is required
67959 * so x86_64 can correctly handle the %rip-relative fixups.
67960 */
67961 - kip->insns = module_alloc(PAGE_SIZE);
67962 + kip->insns = module_alloc_exec(PAGE_SIZE);
67963 if (!kip->insns) {
67964 kfree(kip);
67965 return NULL;
67966 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
67967 */
67968 if (!list_is_singular(&kip->list)) {
67969 list_del(&kip->list);
67970 - module_free(NULL, kip->insns);
67971 + module_free_exec(NULL, kip->insns);
67972 kfree(kip);
67973 }
67974 return 1;
67975 @@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
67976 {
67977 int i, err = 0;
67978 unsigned long offset = 0, size = 0;
67979 - char *modname, namebuf[128];
67980 + char *modname, namebuf[KSYM_NAME_LEN];
67981 const char *symbol_name;
67982 void *addr;
67983 struct kprobe_blackpoint *kb;
67984 @@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
67985 const char *sym = NULL;
67986 unsigned int i = *(loff_t *) v;
67987 unsigned long offset = 0;
67988 - char *modname, namebuf[128];
67989 + char *modname, namebuf[KSYM_NAME_LEN];
67990
67991 head = &kprobe_table[i];
67992 preempt_disable();
67993 diff -urNp linux-2.6.39.1/kernel/lockdep.c linux-2.6.39.1/kernel/lockdep.c
67994 --- linux-2.6.39.1/kernel/lockdep.c 2011-05-19 00:06:34.000000000 -0400
67995 +++ linux-2.6.39.1/kernel/lockdep.c 2011-05-22 19:36:33.000000000 -0400
67996 @@ -571,6 +571,10 @@ static int static_obj(void *obj)
67997 end = (unsigned long) &_end,
67998 addr = (unsigned long) obj;
67999
68000 +#ifdef CONFIG_PAX_KERNEXEC
68001 + start = ktla_ktva(start);
68002 +#endif
68003 +
68004 /*
68005 * static variable?
68006 */
68007 @@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
68008 if (!static_obj(lock->key)) {
68009 debug_locks_off();
68010 printk("INFO: trying to register non-static key.\n");
68011 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68012 printk("the code is fine but needs lockdep annotation.\n");
68013 printk("turning off the locking correctness validator.\n");
68014 dump_stack();
68015 @@ -2752,7 +2757,7 @@ static int __lock_acquire(struct lockdep
68016 if (!class)
68017 return 0;
68018 }
68019 - atomic_inc((atomic_t *)&class->ops);
68020 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68021 if (very_verbose(class)) {
68022 printk("\nacquire class [%p] %s", class->key, class->name);
68023 if (class->name_version > 1)
68024 diff -urNp linux-2.6.39.1/kernel/lockdep_proc.c linux-2.6.39.1/kernel/lockdep_proc.c
68025 --- linux-2.6.39.1/kernel/lockdep_proc.c 2011-05-19 00:06:34.000000000 -0400
68026 +++ linux-2.6.39.1/kernel/lockdep_proc.c 2011-05-22 19:36:33.000000000 -0400
68027 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
68028
68029 static void print_name(struct seq_file *m, struct lock_class *class)
68030 {
68031 - char str[128];
68032 + char str[KSYM_NAME_LEN];
68033 const char *name = class->name;
68034
68035 if (!name) {
68036 diff -urNp linux-2.6.39.1/kernel/module.c linux-2.6.39.1/kernel/module.c
68037 --- linux-2.6.39.1/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
68038 +++ linux-2.6.39.1/kernel/module.c 2011-05-22 19:41:42.000000000 -0400
68039 @@ -57,6 +57,7 @@
68040 #include <linux/kmemleak.h>
68041 #include <linux/jump_label.h>
68042 #include <linux/pfn.h>
68043 +#include <linux/grsecurity.h>
68044
68045 #define CREATE_TRACE_POINTS
68046 #include <trace/events/module.h>
68047 @@ -118,7 +119,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
68048
68049 /* Bounds of module allocation, for speeding __module_address.
68050 * Protected by module_mutex. */
68051 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68052 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68053 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68054
68055 int register_module_notifier(struct notifier_block * nb)
68056 {
68057 @@ -282,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
68058 return true;
68059
68060 list_for_each_entry_rcu(mod, &modules, list) {
68061 - struct symsearch arr[] = {
68062 + struct symsearch modarr[] = {
68063 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68064 NOT_GPL_ONLY, false },
68065 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68066 @@ -304,7 +306,7 @@ bool each_symbol(bool (*fn)(const struct
68067 #endif
68068 };
68069
68070 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68071 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68072 return true;
68073 }
68074 return false;
68075 @@ -415,7 +417,7 @@ static inline void __percpu *mod_percpu(
68076 static int percpu_modalloc(struct module *mod,
68077 unsigned long size, unsigned long align)
68078 {
68079 - if (align > PAGE_SIZE) {
68080 + if (align-1 >= PAGE_SIZE) {
68081 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68082 mod->name, align, PAGE_SIZE);
68083 align = PAGE_SIZE;
68084 @@ -1143,7 +1145,7 @@ resolve_symbol_wait(struct module *mod,
68085 */
68086 #ifdef CONFIG_SYSFS
68087
68088 -#ifdef CONFIG_KALLSYMS
68089 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68090 static inline bool sect_empty(const Elf_Shdr *sect)
68091 {
68092 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68093 @@ -1612,17 +1614,17 @@ void unset_section_ro_nx(struct module *
68094 {
68095 unsigned long total_pages;
68096
68097 - if (mod->module_core == module_region) {
68098 + if (mod->module_core_rx == module_region) {
68099 /* Set core as NX+RW */
68100 - total_pages = MOD_NUMBER_OF_PAGES(mod->module_core, mod->core_size);
68101 - set_memory_nx((unsigned long)mod->module_core, total_pages);
68102 - set_memory_rw((unsigned long)mod->module_core, total_pages);
68103 + total_pages = MOD_NUMBER_OF_PAGES(mod->module_core_rx, mod->core_size_rx);
68104 + set_memory_nx((unsigned long)mod->module_core_rx, total_pages);
68105 + set_memory_rw((unsigned long)mod->module_core_rx, total_pages);
68106
68107 - } else if (mod->module_init == module_region) {
68108 + } else if (mod->module_init_rx == module_region) {
68109 /* Set init as NX+RW */
68110 - total_pages = MOD_NUMBER_OF_PAGES(mod->module_init, mod->init_size);
68111 - set_memory_nx((unsigned long)mod->module_init, total_pages);
68112 - set_memory_rw((unsigned long)mod->module_init, total_pages);
68113 + total_pages = MOD_NUMBER_OF_PAGES(mod->module_init_rx, mod->init_size_rx);
68114 + set_memory_nx((unsigned long)mod->module_init_rx, total_pages);
68115 + set_memory_rw((unsigned long)mod->module_init_rx, total_pages);
68116 }
68117 }
68118
68119 @@ -1633,14 +1635,14 @@ void set_all_modules_text_rw()
68120
68121 mutex_lock(&module_mutex);
68122 list_for_each_entry_rcu(mod, &modules, list) {
68123 - if ((mod->module_core) && (mod->core_text_size)) {
68124 - set_page_attributes(mod->module_core,
68125 - mod->module_core + mod->core_text_size,
68126 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68127 + set_page_attributes(mod->module_core_rx,
68128 + mod->module_core_rx + mod->core_size_rx,
68129 set_memory_rw);
68130 }
68131 - if ((mod->module_init) && (mod->init_text_size)) {
68132 - set_page_attributes(mod->module_init,
68133 - mod->module_init + mod->init_text_size,
68134 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68135 + set_page_attributes(mod->module_init_rx,
68136 + mod->module_init_rx + mod->init_size_rx,
68137 set_memory_rw);
68138 }
68139 }
68140 @@ -1654,14 +1656,14 @@ void set_all_modules_text_ro()
68141
68142 mutex_lock(&module_mutex);
68143 list_for_each_entry_rcu(mod, &modules, list) {
68144 - if ((mod->module_core) && (mod->core_text_size)) {
68145 - set_page_attributes(mod->module_core,
68146 - mod->module_core + mod->core_text_size,
68147 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68148 + set_page_attributes(mod->module_core_rx,
68149 + mod->module_core_rx + mod->core_size_rx,
68150 set_memory_ro);
68151 }
68152 - if ((mod->module_init) && (mod->init_text_size)) {
68153 - set_page_attributes(mod->module_init,
68154 - mod->module_init + mod->init_text_size,
68155 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68156 + set_page_attributes(mod->module_init_rx,
68157 + mod->module_init_rx + mod->init_size_rx,
68158 set_memory_ro);
68159 }
68160 }
68161 @@ -1696,17 +1698,20 @@ static void free_module(struct module *m
68162 destroy_params(mod->kp, mod->num_kp);
68163
68164 /* This may be NULL, but that's OK */
68165 - unset_section_ro_nx(mod, mod->module_init);
68166 - module_free(mod, mod->module_init);
68167 + unset_section_ro_nx(mod, mod->module_init_rx);
68168 + module_free(mod, mod->module_init_rw);
68169 + module_free_exec(mod, mod->module_init_rx);
68170 kfree(mod->args);
68171 percpu_modfree(mod);
68172
68173 /* Free lock-classes: */
68174 - lockdep_free_key_range(mod->module_core, mod->core_size);
68175 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68176 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68177
68178 /* Finally, free the core (containing the module structure) */
68179 - unset_section_ro_nx(mod, mod->module_core);
68180 - module_free(mod, mod->module_core);
68181 + unset_section_ro_nx(mod, mod->module_core_rx);
68182 + module_free_exec(mod, mod->module_core_rx);
68183 + module_free(mod, mod->module_core_rw);
68184
68185 #ifdef CONFIG_MPU
68186 update_protections(current->mm);
68187 @@ -1775,10 +1780,31 @@ static int simplify_symbols(struct modul
68188 unsigned int i;
68189 int ret = 0;
68190 const struct kernel_symbol *ksym;
68191 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68192 + int is_fs_load = 0;
68193 + int register_filesystem_found = 0;
68194 + char *p;
68195 +
68196 + p = strstr(mod->args, "grsec_modharden_fs");
68197 + if (p) {
68198 + char *endptr = p + strlen("grsec_modharden_fs");
68199 + /* copy \0 as well */
68200 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68201 + is_fs_load = 1;
68202 + }
68203 +#endif
68204
68205 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68206 const char *name = info->strtab + sym[i].st_name;
68207
68208 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68209 + /* it's a real shame this will never get ripped and copied
68210 + upstream! ;(
68211 + */
68212 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68213 + register_filesystem_found = 1;
68214 +#endif
68215 +
68216 switch (sym[i].st_shndx) {
68217 case SHN_COMMON:
68218 /* We compiled with -fno-common. These are not
68219 @@ -1799,7 +1825,9 @@ static int simplify_symbols(struct modul
68220 ksym = resolve_symbol_wait(mod, info, name);
68221 /* Ok if resolved. */
68222 if (ksym && !IS_ERR(ksym)) {
68223 + pax_open_kernel();
68224 sym[i].st_value = ksym->value;
68225 + pax_close_kernel();
68226 break;
68227 }
68228
68229 @@ -1818,11 +1846,20 @@ static int simplify_symbols(struct modul
68230 secbase = (unsigned long)mod_percpu(mod);
68231 else
68232 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68233 + pax_open_kernel();
68234 sym[i].st_value += secbase;
68235 + pax_close_kernel();
68236 break;
68237 }
68238 }
68239
68240 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68241 + if (is_fs_load && !register_filesystem_found) {
68242 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68243 + ret = -EPERM;
68244 + }
68245 +#endif
68246 +
68247 return ret;
68248 }
68249
68250 @@ -1906,22 +1943,12 @@ static void layout_sections(struct modul
68251 || s->sh_entsize != ~0UL
68252 || strstarts(sname, ".init"))
68253 continue;
68254 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68255 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68256 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68257 + else
68258 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68259 DEBUGP("\t%s\n", name);
68260 }
68261 - switch (m) {
68262 - case 0: /* executable */
68263 - mod->core_size = debug_align(mod->core_size);
68264 - mod->core_text_size = mod->core_size;
68265 - break;
68266 - case 1: /* RO: text and ro-data */
68267 - mod->core_size = debug_align(mod->core_size);
68268 - mod->core_ro_size = mod->core_size;
68269 - break;
68270 - case 3: /* whole core */
68271 - mod->core_size = debug_align(mod->core_size);
68272 - break;
68273 - }
68274 }
68275
68276 DEBUGP("Init section allocation order:\n");
68277 @@ -1935,23 +1962,13 @@ static void layout_sections(struct modul
68278 || s->sh_entsize != ~0UL
68279 || !strstarts(sname, ".init"))
68280 continue;
68281 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68282 - | INIT_OFFSET_MASK);
68283 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68284 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68285 + else
68286 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68287 + s->sh_entsize |= INIT_OFFSET_MASK;
68288 DEBUGP("\t%s\n", sname);
68289 }
68290 - switch (m) {
68291 - case 0: /* executable */
68292 - mod->init_size = debug_align(mod->init_size);
68293 - mod->init_text_size = mod->init_size;
68294 - break;
68295 - case 1: /* RO: text and ro-data */
68296 - mod->init_size = debug_align(mod->init_size);
68297 - mod->init_ro_size = mod->init_size;
68298 - break;
68299 - case 3: /* whole init */
68300 - mod->init_size = debug_align(mod->init_size);
68301 - break;
68302 - }
68303 }
68304 }
68305
68306 @@ -2119,7 +2136,7 @@ static void layout_symtab(struct module
68307
68308 /* Put symbol section at end of init part of module. */
68309 symsect->sh_flags |= SHF_ALLOC;
68310 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68311 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68312 info->index.sym) | INIT_OFFSET_MASK;
68313 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
68314
68315 @@ -2136,19 +2153,19 @@ static void layout_symtab(struct module
68316 }
68317
68318 /* Append room for core symbols at end of core part. */
68319 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68320 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68321 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68322 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68323
68324 /* Put string table section at end of init part of module. */
68325 strsect->sh_flags |= SHF_ALLOC;
68326 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68327 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68328 info->index.str) | INIT_OFFSET_MASK;
68329 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
68330
68331 /* Append room for core symbols' strings at end of core part. */
68332 - info->stroffs = mod->core_size;
68333 + info->stroffs = mod->core_size_rx;
68334 __set_bit(0, info->strmap);
68335 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
68336 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
68337 }
68338
68339 static void add_kallsyms(struct module *mod, const struct load_info *info)
68340 @@ -2164,11 +2181,13 @@ static void add_kallsyms(struct module *
68341 /* Make sure we get permanent strtab: don't use info->strtab. */
68342 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68343
68344 + pax_open_kernel();
68345 +
68346 /* Set types up while we still have access to sections. */
68347 for (i = 0; i < mod->num_symtab; i++)
68348 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68349
68350 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68351 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68352 src = mod->symtab;
68353 *dst = *src;
68354 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68355 @@ -2181,10 +2200,12 @@ static void add_kallsyms(struct module *
68356 }
68357 mod->core_num_syms = ndst;
68358
68359 - mod->core_strtab = s = mod->module_core + info->stroffs;
68360 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68361 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
68362 if (test_bit(i, info->strmap))
68363 *++s = mod->strtab[i];
68364 +
68365 + pax_close_kernel();
68366 }
68367 #else
68368 static inline void layout_symtab(struct module *mod, struct load_info *info)
68369 @@ -2213,17 +2234,33 @@ static void dynamic_debug_remove(struct
68370 ddebug_remove_module(debug->modname);
68371 }
68372
68373 -static void *module_alloc_update_bounds(unsigned long size)
68374 +static void *module_alloc_update_bounds_rw(unsigned long size)
68375 {
68376 void *ret = module_alloc(size);
68377
68378 if (ret) {
68379 mutex_lock(&module_mutex);
68380 /* Update module bounds. */
68381 - if ((unsigned long)ret < module_addr_min)
68382 - module_addr_min = (unsigned long)ret;
68383 - if ((unsigned long)ret + size > module_addr_max)
68384 - module_addr_max = (unsigned long)ret + size;
68385 + if ((unsigned long)ret < module_addr_min_rw)
68386 + module_addr_min_rw = (unsigned long)ret;
68387 + if ((unsigned long)ret + size > module_addr_max_rw)
68388 + module_addr_max_rw = (unsigned long)ret + size;
68389 + mutex_unlock(&module_mutex);
68390 + }
68391 + return ret;
68392 +}
68393 +
68394 +static void *module_alloc_update_bounds_rx(unsigned long size)
68395 +{
68396 + void *ret = module_alloc_exec(size);
68397 +
68398 + if (ret) {
68399 + mutex_lock(&module_mutex);
68400 + /* Update module bounds. */
68401 + if ((unsigned long)ret < module_addr_min_rx)
68402 + module_addr_min_rx = (unsigned long)ret;
68403 + if ((unsigned long)ret + size > module_addr_max_rx)
68404 + module_addr_max_rx = (unsigned long)ret + size;
68405 mutex_unlock(&module_mutex);
68406 }
68407 return ret;
68408 @@ -2516,7 +2553,7 @@ static int move_module(struct module *mo
68409 void *ptr;
68410
68411 /* Do the allocs. */
68412 - ptr = module_alloc_update_bounds(mod->core_size);
68413 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68414 /*
68415 * The pointer to this block is stored in the module structure
68416 * which is inside the block. Just mark it as not being a
68417 @@ -2526,23 +2563,50 @@ static int move_module(struct module *mo
68418 if (!ptr)
68419 return -ENOMEM;
68420
68421 - memset(ptr, 0, mod->core_size);
68422 - mod->module_core = ptr;
68423 + memset(ptr, 0, mod->core_size_rw);
68424 + mod->module_core_rw = ptr;
68425
68426 - ptr = module_alloc_update_bounds(mod->init_size);
68427 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68428 /*
68429 * The pointer to this block is stored in the module structure
68430 * which is inside the block. This block doesn't need to be
68431 * scanned as it contains data and code that will be freed
68432 * after the module is initialized.
68433 */
68434 - kmemleak_ignore(ptr);
68435 - if (!ptr && mod->init_size) {
68436 - module_free(mod, mod->module_core);
68437 + kmemleak_not_leak(ptr);
68438 + if (!ptr && mod->init_size_rw) {
68439 + module_free(mod, mod->module_core_rw);
68440 return -ENOMEM;
68441 }
68442 - memset(ptr, 0, mod->init_size);
68443 - mod->module_init = ptr;
68444 + memset(ptr, 0, mod->init_size_rw);
68445 + mod->module_init_rw = ptr;
68446 +
68447 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68448 + kmemleak_not_leak(ptr);
68449 + if (!ptr) {
68450 + module_free(mod, mod->module_init_rw);
68451 + module_free(mod, mod->module_core_rw);
68452 + return -ENOMEM;
68453 + }
68454 +
68455 + pax_open_kernel();
68456 + memset(ptr, 0, mod->core_size_rx);
68457 + pax_close_kernel();
68458 + mod->module_core_rx = ptr;
68459 +
68460 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68461 + kmemleak_not_leak(ptr);
68462 + if (!ptr && mod->init_size_rx) {
68463 + module_free_exec(mod, mod->module_core_rx);
68464 + module_free(mod, mod->module_init_rw);
68465 + module_free(mod, mod->module_core_rw);
68466 + return -ENOMEM;
68467 + }
68468 +
68469 + pax_open_kernel();
68470 + memset(ptr, 0, mod->init_size_rx);
68471 + pax_close_kernel();
68472 + mod->module_init_rx = ptr;
68473
68474 /* Transfer each section which specifies SHF_ALLOC */
68475 DEBUGP("final section addresses:\n");
68476 @@ -2553,16 +2617,45 @@ static int move_module(struct module *mo
68477 if (!(shdr->sh_flags & SHF_ALLOC))
68478 continue;
68479
68480 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68481 - dest = mod->module_init
68482 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68483 - else
68484 - dest = mod->module_core + shdr->sh_entsize;
68485 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68486 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68487 + dest = mod->module_init_rw
68488 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68489 + else
68490 + dest = mod->module_init_rx
68491 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68492 + } else {
68493 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68494 + dest = mod->module_core_rw + shdr->sh_entsize;
68495 + else
68496 + dest = mod->module_core_rx + shdr->sh_entsize;
68497 + }
68498 +
68499 + if (shdr->sh_type != SHT_NOBITS) {
68500 +
68501 +#ifdef CONFIG_PAX_KERNEXEC
68502 +#ifdef CONFIG_X86_64
68503 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68504 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68505 +#endif
68506 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68507 + pax_open_kernel();
68508 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68509 + pax_close_kernel();
68510 + } else
68511 +#endif
68512
68513 - if (shdr->sh_type != SHT_NOBITS)
68514 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68515 + }
68516 /* Update sh_addr to point to copy in image. */
68517 - shdr->sh_addr = (unsigned long)dest;
68518 +
68519 +#ifdef CONFIG_PAX_KERNEXEC
68520 + if (shdr->sh_flags & SHF_EXECINSTR)
68521 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68522 + else
68523 +#endif
68524 +
68525 + shdr->sh_addr = (unsigned long)dest;
68526 DEBUGP("\t0x%lx %s\n",
68527 shdr->sh_addr, info->secstrings + shdr->sh_name);
68528 }
68529 @@ -2613,12 +2706,12 @@ static void flush_module_icache(const st
68530 * Do it before processing of module parameters, so the module
68531 * can provide parameter accessor functions of its own.
68532 */
68533 - if (mod->module_init)
68534 - flush_icache_range((unsigned long)mod->module_init,
68535 - (unsigned long)mod->module_init
68536 - + mod->init_size);
68537 - flush_icache_range((unsigned long)mod->module_core,
68538 - (unsigned long)mod->module_core + mod->core_size);
68539 + if (mod->module_init_rx)
68540 + flush_icache_range((unsigned long)mod->module_init_rx,
68541 + (unsigned long)mod->module_init_rx
68542 + + mod->init_size_rx);
68543 + flush_icache_range((unsigned long)mod->module_core_rx,
68544 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68545
68546 set_fs(old_fs);
68547 }
68548 @@ -2690,8 +2783,10 @@ static void module_deallocate(struct mod
68549 {
68550 kfree(info->strmap);
68551 percpu_modfree(mod);
68552 - module_free(mod, mod->module_init);
68553 - module_free(mod, mod->module_core);
68554 + module_free_exec(mod, mod->module_init_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 }
68559
68560 static int post_relocation(struct module *mod, const struct load_info *info)
68561 @@ -2748,9 +2843,38 @@ static struct module *load_module(void _
68562 if (err)
68563 goto free_unload;
68564
68565 + /* Now copy in args */
68566 + mod->args = strndup_user(uargs, ~0UL >> 1);
68567 + if (IS_ERR(mod->args)) {
68568 + err = PTR_ERR(mod->args);
68569 + goto free_unload;
68570 + }
68571 +
68572 /* Set up MODINFO_ATTR fields */
68573 setup_modinfo(mod, &info);
68574
68575 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68576 + {
68577 + char *p, *p2;
68578 +
68579 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68580 + 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);
68581 + err = -EPERM;
68582 + goto free_modinfo;
68583 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68584 + p += strlen("grsec_modharden_normal");
68585 + p2 = strstr(p, "_");
68586 + if (p2) {
68587 + *p2 = '\0';
68588 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68589 + *p2 = '_';
68590 + }
68591 + err = -EPERM;
68592 + goto free_modinfo;
68593 + }
68594 + }
68595 +#endif
68596 +
68597 /* Fix up syms, so that st_value is a pointer to location. */
68598 err = simplify_symbols(mod, &info);
68599 if (err < 0)
68600 @@ -2766,13 +2890,6 @@ static struct module *load_module(void _
68601
68602 flush_module_icache(mod);
68603
68604 - /* Now copy in args */
68605 - mod->args = strndup_user(uargs, ~0UL >> 1);
68606 - if (IS_ERR(mod->args)) {
68607 - err = PTR_ERR(mod->args);
68608 - goto free_arch_cleanup;
68609 - }
68610 -
68611 /* Mark state as coming so strong_try_module_get() ignores us. */
68612 mod->state = MODULE_STATE_COMING;
68613
68614 @@ -2832,11 +2949,10 @@ static struct module *load_module(void _
68615 unlock:
68616 mutex_unlock(&module_mutex);
68617 synchronize_sched();
68618 - kfree(mod->args);
68619 - free_arch_cleanup:
68620 module_arch_cleanup(mod);
68621 free_modinfo:
68622 free_modinfo(mod);
68623 + kfree(mod->args);
68624 free_unload:
68625 module_unload_free(mod);
68626 free_module:
68627 @@ -2877,16 +2993,16 @@ SYSCALL_DEFINE3(init_module, void __user
68628 MODULE_STATE_COMING, mod);
68629
68630 /* Set RO and NX regions for core */
68631 - set_section_ro_nx(mod->module_core,
68632 - mod->core_text_size,
68633 - mod->core_ro_size,
68634 - mod->core_size);
68635 + set_section_ro_nx(mod->module_core_rx,
68636 + mod->core_size_rx,
68637 + mod->core_size_rx,
68638 + mod->core_size_rx);
68639
68640 /* Set RO and NX regions for init */
68641 - set_section_ro_nx(mod->module_init,
68642 - mod->init_text_size,
68643 - mod->init_ro_size,
68644 - mod->init_size);
68645 + set_section_ro_nx(mod->module_init_rx,
68646 + mod->init_size_rx,
68647 + mod->init_size_rx,
68648 + mod->init_size_rx);
68649
68650 do_mod_ctors(mod);
68651 /* Start the module */
68652 @@ -2931,11 +3047,13 @@ SYSCALL_DEFINE3(init_module, void __user
68653 mod->symtab = mod->core_symtab;
68654 mod->strtab = mod->core_strtab;
68655 #endif
68656 - unset_section_ro_nx(mod, mod->module_init);
68657 - module_free(mod, mod->module_init);
68658 - mod->module_init = NULL;
68659 - mod->init_size = 0;
68660 - mod->init_text_size = 0;
68661 + unset_section_ro_nx(mod, mod->module_init_rx);
68662 + module_free(mod, mod->module_init_rw);
68663 + module_free_exec(mod, mod->module_init_rx);
68664 + mod->module_init_rw = NULL;
68665 + mod->module_init_rx = NULL;
68666 + mod->init_size_rw = 0;
68667 + mod->init_size_rx = 0;
68668 mutex_unlock(&module_mutex);
68669
68670 return 0;
68671 @@ -2966,10 +3084,16 @@ static const char *get_ksymbol(struct mo
68672 unsigned long nextval;
68673
68674 /* At worse, next value is at end of module */
68675 - if (within_module_init(addr, mod))
68676 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68677 + if (within_module_init_rx(addr, mod))
68678 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68679 + else if (within_module_init_rw(addr, mod))
68680 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68681 + else if (within_module_core_rx(addr, mod))
68682 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68683 + else if (within_module_core_rw(addr, mod))
68684 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68685 else
68686 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68687 + return NULL;
68688
68689 /* Scan for closest preceding symbol, and next symbol. (ELF
68690 starts real symbols at 1). */
68691 @@ -3215,7 +3339,7 @@ static int m_show(struct seq_file *m, vo
68692 char buf[8];
68693
68694 seq_printf(m, "%s %u",
68695 - mod->name, mod->init_size + mod->core_size);
68696 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68697 print_unload_info(m, mod);
68698
68699 /* Informative for users. */
68700 @@ -3224,7 +3348,7 @@ static int m_show(struct seq_file *m, vo
68701 mod->state == MODULE_STATE_COMING ? "Loading":
68702 "Live");
68703 /* Used by oprofile and other similar tools. */
68704 - seq_printf(m, " 0x%pK", mod->module_core);
68705 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68706
68707 /* Taints info */
68708 if (mod->taints)
68709 @@ -3260,7 +3384,17 @@ static const struct file_operations proc
68710
68711 static int __init proc_modules_init(void)
68712 {
68713 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68714 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68715 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68716 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68717 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68718 +#else
68719 proc_create("modules", 0, NULL, &proc_modules_operations);
68720 +#endif
68721 +#else
68722 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68723 +#endif
68724 return 0;
68725 }
68726 module_init(proc_modules_init);
68727 @@ -3319,12 +3453,12 @@ struct module *__module_address(unsigned
68728 {
68729 struct module *mod;
68730
68731 - if (addr < module_addr_min || addr > module_addr_max)
68732 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68733 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68734 return NULL;
68735
68736 list_for_each_entry_rcu(mod, &modules, list)
68737 - if (within_module_core(addr, mod)
68738 - || within_module_init(addr, mod))
68739 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68740 return mod;
68741 return NULL;
68742 }
68743 @@ -3358,11 +3492,20 @@ bool is_module_text_address(unsigned lon
68744 */
68745 struct module *__module_text_address(unsigned long addr)
68746 {
68747 - struct module *mod = __module_address(addr);
68748 + struct module *mod;
68749 +
68750 +#ifdef CONFIG_X86_32
68751 + addr = ktla_ktva(addr);
68752 +#endif
68753 +
68754 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68755 + return NULL;
68756 +
68757 + mod = __module_address(addr);
68758 +
68759 if (mod) {
68760 /* Make sure it's within the text section. */
68761 - if (!within(addr, mod->module_init, mod->init_text_size)
68762 - && !within(addr, mod->module_core, mod->core_text_size))
68763 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68764 mod = NULL;
68765 }
68766 return mod;
68767 diff -urNp linux-2.6.39.1/kernel/mutex.c linux-2.6.39.1/kernel/mutex.c
68768 --- linux-2.6.39.1/kernel/mutex.c 2011-05-19 00:06:34.000000000 -0400
68769 +++ linux-2.6.39.1/kernel/mutex.c 2011-05-22 19:36:33.000000000 -0400
68770 @@ -160,7 +160,7 @@ __mutex_lock_common(struct mutex *lock,
68771 */
68772
68773 for (;;) {
68774 - struct thread_info *owner;
68775 + struct task_struct *owner;
68776
68777 /*
68778 * If we own the BKL, then don't spin. The owner of
68779 @@ -205,7 +205,7 @@ __mutex_lock_common(struct mutex *lock,
68780 spin_lock_mutex(&lock->wait_lock, flags);
68781
68782 debug_mutex_lock_common(lock, &waiter);
68783 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68784 + debug_mutex_add_waiter(lock, &waiter, task);
68785
68786 /* add waiting tasks to the end of the waitqueue (FIFO): */
68787 list_add_tail(&waiter.list, &lock->wait_list);
68788 @@ -234,8 +234,7 @@ __mutex_lock_common(struct mutex *lock,
68789 * TASK_UNINTERRUPTIBLE case.)
68790 */
68791 if (unlikely(signal_pending_state(state, task))) {
68792 - mutex_remove_waiter(lock, &waiter,
68793 - task_thread_info(task));
68794 + mutex_remove_waiter(lock, &waiter, task);
68795 mutex_release(&lock->dep_map, 1, ip);
68796 spin_unlock_mutex(&lock->wait_lock, flags);
68797
68798 @@ -256,7 +255,7 @@ __mutex_lock_common(struct mutex *lock,
68799 done:
68800 lock_acquired(&lock->dep_map, ip);
68801 /* got the lock - rejoice! */
68802 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68803 + mutex_remove_waiter(lock, &waiter, task);
68804 mutex_set_owner(lock);
68805
68806 /* set it to 0 if there are no waiters left: */
68807 diff -urNp linux-2.6.39.1/kernel/mutex-debug.c linux-2.6.39.1/kernel/mutex-debug.c
68808 --- linux-2.6.39.1/kernel/mutex-debug.c 2011-05-19 00:06:34.000000000 -0400
68809 +++ linux-2.6.39.1/kernel/mutex-debug.c 2011-05-22 19:36:33.000000000 -0400
68810 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
68811 }
68812
68813 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68814 - struct thread_info *ti)
68815 + struct task_struct *task)
68816 {
68817 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68818
68819 /* Mark the current thread as blocked on the lock: */
68820 - ti->task->blocked_on = waiter;
68821 + task->blocked_on = waiter;
68822 }
68823
68824 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68825 - struct thread_info *ti)
68826 + struct task_struct *task)
68827 {
68828 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68829 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68830 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68831 - ti->task->blocked_on = NULL;
68832 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68833 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68834 + task->blocked_on = NULL;
68835
68836 list_del_init(&waiter->list);
68837 waiter->task = NULL;
68838 @@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
68839 return;
68840
68841 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
68842 - DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
68843 + DEBUG_LOCKS_WARN_ON(lock->owner != current);
68844 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
68845 mutex_clear_owner(lock);
68846 }
68847 diff -urNp linux-2.6.39.1/kernel/mutex-debug.h linux-2.6.39.1/kernel/mutex-debug.h
68848 --- linux-2.6.39.1/kernel/mutex-debug.h 2011-05-19 00:06:34.000000000 -0400
68849 +++ linux-2.6.39.1/kernel/mutex-debug.h 2011-05-22 19:36:33.000000000 -0400
68850 @@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
68851 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68852 extern void debug_mutex_add_waiter(struct mutex *lock,
68853 struct mutex_waiter *waiter,
68854 - struct thread_info *ti);
68855 + struct task_struct *task);
68856 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68857 - struct thread_info *ti);
68858 + struct task_struct *task);
68859 extern void debug_mutex_unlock(struct mutex *lock);
68860 extern void debug_mutex_init(struct mutex *lock, const char *name,
68861 struct lock_class_key *key);
68862
68863 static inline void mutex_set_owner(struct mutex *lock)
68864 {
68865 - lock->owner = current_thread_info();
68866 + lock->owner = current;
68867 }
68868
68869 static inline void mutex_clear_owner(struct mutex *lock)
68870 diff -urNp linux-2.6.39.1/kernel/mutex.h linux-2.6.39.1/kernel/mutex.h
68871 --- linux-2.6.39.1/kernel/mutex.h 2011-05-19 00:06:34.000000000 -0400
68872 +++ linux-2.6.39.1/kernel/mutex.h 2011-05-22 19:36:33.000000000 -0400
68873 @@ -19,7 +19,7 @@
68874 #ifdef CONFIG_SMP
68875 static inline void mutex_set_owner(struct mutex *lock)
68876 {
68877 - lock->owner = current_thread_info();
68878 + lock->owner = current;
68879 }
68880
68881 static inline void mutex_clear_owner(struct mutex *lock)
68882 diff -urNp linux-2.6.39.1/kernel/padata.c linux-2.6.39.1/kernel/padata.c
68883 --- linux-2.6.39.1/kernel/padata.c 2011-05-19 00:06:34.000000000 -0400
68884 +++ linux-2.6.39.1/kernel/padata.c 2011-05-22 19:36:33.000000000 -0400
68885 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
68886 padata->pd = pd;
68887 padata->cb_cpu = cb_cpu;
68888
68889 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68890 - atomic_set(&pd->seq_nr, -1);
68891 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68892 + atomic_set_unchecked(&pd->seq_nr, -1);
68893
68894 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68895 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68896
68897 target_cpu = padata_cpu_hash(padata);
68898 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68899 @@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
68900 padata_init_pqueues(pd);
68901 padata_init_squeues(pd);
68902 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68903 - atomic_set(&pd->seq_nr, -1);
68904 + atomic_set_unchecked(&pd->seq_nr, -1);
68905 atomic_set(&pd->reorder_objects, 0);
68906 atomic_set(&pd->refcnt, 0);
68907 pd->pinst = pinst;
68908 diff -urNp linux-2.6.39.1/kernel/panic.c linux-2.6.39.1/kernel/panic.c
68909 --- linux-2.6.39.1/kernel/panic.c 2011-05-19 00:06:34.000000000 -0400
68910 +++ linux-2.6.39.1/kernel/panic.c 2011-05-22 19:41:42.000000000 -0400
68911 @@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
68912 const char *board;
68913
68914 printk(KERN_WARNING "------------[ cut here ]------------\n");
68915 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68916 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68917 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68918 if (board)
68919 printk(KERN_WARNING "Hardware name: %s\n", board);
68920 @@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68921 */
68922 void __stack_chk_fail(void)
68923 {
68924 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68925 + dump_stack();
68926 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68927 __builtin_return_address(0));
68928 }
68929 EXPORT_SYMBOL(__stack_chk_fail);
68930 diff -urNp linux-2.6.39.1/kernel/params.c linux-2.6.39.1/kernel/params.c
68931 --- linux-2.6.39.1/kernel/params.c 2011-05-19 00:06:34.000000000 -0400
68932 +++ linux-2.6.39.1/kernel/params.c 2011-05-22 19:36:33.000000000 -0400
68933 @@ -234,7 +234,7 @@ int parse_args(const char *name,
68934 { \
68935 return sprintf(buffer, format, *((type *)kp->arg)); \
68936 } \
68937 - struct kernel_param_ops param_ops_##name = { \
68938 + const struct kernel_param_ops param_ops_##name = { \
68939 .set = param_set_##name, \
68940 .get = param_get_##name, \
68941 }; \
68942 @@ -286,7 +286,7 @@ static void param_free_charp(void *arg)
68943 maybe_kfree_parameter(*((char **)arg));
68944 }
68945
68946 -struct kernel_param_ops param_ops_charp = {
68947 +const struct kernel_param_ops param_ops_charp = {
68948 .set = param_set_charp,
68949 .get = param_get_charp,
68950 .free = param_free_charp,
68951 @@ -334,7 +334,7 @@ int param_get_bool(char *buffer, const s
68952 }
68953 EXPORT_SYMBOL(param_get_bool);
68954
68955 -struct kernel_param_ops param_ops_bool = {
68956 +const struct kernel_param_ops param_ops_bool = {
68957 .set = param_set_bool,
68958 .get = param_get_bool,
68959 };
68960 @@ -362,7 +362,7 @@ int param_get_invbool(char *buffer, cons
68961 }
68962 EXPORT_SYMBOL(param_get_invbool);
68963
68964 -struct kernel_param_ops param_ops_invbool = {
68965 +const struct kernel_param_ops param_ops_invbool = {
68966 .set = param_set_invbool,
68967 .get = param_get_invbool,
68968 };
68969 @@ -460,7 +460,7 @@ static void param_array_free(void *arg)
68970 arr->ops->free(arr->elem + arr->elemsize * i);
68971 }
68972
68973 -struct kernel_param_ops param_array_ops = {
68974 +const struct kernel_param_ops param_array_ops = {
68975 .set = param_array_set,
68976 .get = param_array_get,
68977 .free = param_array_free,
68978 @@ -488,7 +488,7 @@ int param_get_string(char *buffer, const
68979 }
68980 EXPORT_SYMBOL(param_get_string);
68981
68982 -struct kernel_param_ops param_ops_string = {
68983 +const struct kernel_param_ops param_ops_string = {
68984 .set = param_set_copystring,
68985 .get = param_get_string,
68986 };
68987 diff -urNp linux-2.6.39.1/kernel/perf_event.c linux-2.6.39.1/kernel/perf_event.c
68988 --- linux-2.6.39.1/kernel/perf_event.c 2011-05-19 00:06:34.000000000 -0400
68989 +++ linux-2.6.39.1/kernel/perf_event.c 2011-05-22 19:36:33.000000000 -0400
68990 @@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
68991 return 0;
68992 }
68993
68994 -static atomic64_t perf_event_id;
68995 +static atomic64_unchecked_t perf_event_id;
68996
68997 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68998 enum event_type_t event_type);
68999 @@ -2496,7 +2496,7 @@ static void __perf_event_read(void *info
69000
69001 static inline u64 perf_event_count(struct perf_event *event)
69002 {
69003 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69004 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69005 }
69006
69007 static u64 perf_event_read(struct perf_event *event)
69008 @@ -3031,9 +3031,9 @@ u64 perf_event_read_value(struct perf_ev
69009 mutex_lock(&event->child_mutex);
69010 total += perf_event_read(event);
69011 *enabled += event->total_time_enabled +
69012 - atomic64_read(&event->child_total_time_enabled);
69013 + atomic64_read_unchecked(&event->child_total_time_enabled);
69014 *running += event->total_time_running +
69015 - atomic64_read(&event->child_total_time_running);
69016 + atomic64_read_unchecked(&event->child_total_time_running);
69017
69018 list_for_each_entry(child, &event->child_list, child_list) {
69019 total += perf_event_read(child);
69020 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct p
69021 userpg->offset -= local64_read(&event->hw.prev_count);
69022
69023 userpg->time_enabled = event->total_time_enabled +
69024 - atomic64_read(&event->child_total_time_enabled);
69025 + atomic64_read_unchecked(&event->child_total_time_enabled);
69026
69027 userpg->time_running = event->total_time_running +
69028 - atomic64_read(&event->child_total_time_running);
69029 + atomic64_read_unchecked(&event->child_total_time_running);
69030
69031 barrier();
69032 ++userpg->lock;
69033 @@ -3884,16 +3884,16 @@ static void perf_pending_event(struct ir
69034 * Later on, we might change it to a list if there is
69035 * another virtualization implementation supporting the callbacks.
69036 */
69037 -struct perf_guest_info_callbacks *perf_guest_cbs;
69038 +const struct perf_guest_info_callbacks *perf_guest_cbs;
69039
69040 -int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69041 +int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
69042 {
69043 perf_guest_cbs = cbs;
69044 return 0;
69045 }
69046 EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
69047
69048 -int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69049 +int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
69050 {
69051 perf_guest_cbs = NULL;
69052 return 0;
69053 @@ -4196,11 +4196,11 @@ static void perf_output_read_one(struct
69054 values[n++] = perf_event_count(event);
69055 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69056 values[n++] = enabled +
69057 - atomic64_read(&event->child_total_time_enabled);
69058 + atomic64_read_unchecked(&event->child_total_time_enabled);
69059 }
69060 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69061 values[n++] = running +
69062 - atomic64_read(&event->child_total_time_running);
69063 + atomic64_read_unchecked(&event->child_total_time_running);
69064 }
69065 if (read_format & PERF_FORMAT_ID)
69066 values[n++] = primary_event_id(event);
69067 @@ -6201,7 +6201,7 @@ perf_event_alloc(struct perf_event_attr
69068 event->parent = parent_event;
69069
69070 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69071 - event->id = atomic64_inc_return(&perf_event_id);
69072 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69073
69074 event->state = PERF_EVENT_STATE_INACTIVE;
69075
69076 @@ -6724,10 +6724,10 @@ static void sync_child_event(struct perf
69077 /*
69078 * Add back the child's count to the parent's count:
69079 */
69080 - atomic64_add(child_val, &parent_event->child_count);
69081 - atomic64_add(child_event->total_time_enabled,
69082 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69083 + atomic64_add_unchecked(child_event->total_time_enabled,
69084 &parent_event->child_total_time_enabled);
69085 - atomic64_add(child_event->total_time_running,
69086 + atomic64_add_unchecked(child_event->total_time_running,
69087 &parent_event->child_total_time_running);
69088
69089 /*
69090 diff -urNp linux-2.6.39.1/kernel/pid.c linux-2.6.39.1/kernel/pid.c
69091 --- linux-2.6.39.1/kernel/pid.c 2011-05-19 00:06:34.000000000 -0400
69092 +++ linux-2.6.39.1/kernel/pid.c 2011-05-22 19:41:42.000000000 -0400
69093 @@ -33,6 +33,7 @@
69094 #include <linux/rculist.h>
69095 #include <linux/bootmem.h>
69096 #include <linux/hash.h>
69097 +#include <linux/security.h>
69098 #include <linux/pid_namespace.h>
69099 #include <linux/init_task.h>
69100 #include <linux/syscalls.h>
69101 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
69102
69103 int pid_max = PID_MAX_DEFAULT;
69104
69105 -#define RESERVED_PIDS 300
69106 +#define RESERVED_PIDS 500
69107
69108 int pid_max_min = RESERVED_PIDS + 1;
69109 int pid_max_max = PID_MAX_LIMIT;
69110 @@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
69111 */
69112 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69113 {
69114 + struct task_struct *task;
69115 +
69116 rcu_lockdep_assert(rcu_read_lock_held());
69117 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69118 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69119 +
69120 + if (gr_pid_is_chrooted(task))
69121 + return NULL;
69122 +
69123 + return task;
69124 }
69125
69126 struct task_struct *find_task_by_vpid(pid_t vnr)
69127 diff -urNp linux-2.6.39.1/kernel/posix-cpu-timers.c linux-2.6.39.1/kernel/posix-cpu-timers.c
69128 --- linux-2.6.39.1/kernel/posix-cpu-timers.c 2011-05-19 00:06:34.000000000 -0400
69129 +++ linux-2.6.39.1/kernel/posix-cpu-timers.c 2011-05-22 19:41:42.000000000 -0400
69130 @@ -6,6 +6,7 @@
69131 #include <linux/posix-timers.h>
69132 #include <linux/errno.h>
69133 #include <linux/math64.h>
69134 +#include <linux/security.h>
69135 #include <asm/uaccess.h>
69136 #include <linux/kernel_stat.h>
69137 #include <trace/events/timer.h>
69138 @@ -1590,7 +1591,7 @@ static int thread_cpu_timer_create(struc
69139 return posix_cpu_timer_create(timer);
69140 }
69141
69142 -struct k_clock clock_posix_cpu = {
69143 +const struct k_clock clock_posix_cpu = {
69144 .clock_getres = posix_cpu_clock_getres,
69145 .clock_set = posix_cpu_clock_set,
69146 .clock_get = posix_cpu_clock_get,
69147 @@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
69148
69149 static __init int init_posix_cpu_timers(void)
69150 {
69151 - struct k_clock process = {
69152 + const struct k_clock process = {
69153 .clock_getres = process_cpu_clock_getres,
69154 .clock_get = process_cpu_clock_get,
69155 .timer_create = process_cpu_timer_create,
69156 .nsleep = process_cpu_nsleep,
69157 .nsleep_restart = process_cpu_nsleep_restart,
69158 };
69159 - struct k_clock thread = {
69160 + const struct k_clock thread = {
69161 .clock_getres = thread_cpu_clock_getres,
69162 .clock_get = thread_cpu_clock_get,
69163 .timer_create = thread_cpu_timer_create,
69164 diff -urNp linux-2.6.39.1/kernel/posix-timers.c linux-2.6.39.1/kernel/posix-timers.c
69165 --- linux-2.6.39.1/kernel/posix-timers.c 2011-05-19 00:06:34.000000000 -0400
69166 +++ linux-2.6.39.1/kernel/posix-timers.c 2011-05-22 20:13:41.000000000 -0400
69167 @@ -43,6 +43,7 @@
69168 #include <linux/idr.h>
69169 #include <linux/posix-clock.h>
69170 #include <linux/posix-timers.h>
69171 +#include <linux/grsecurity.h>
69172 #include <linux/syscalls.h>
69173 #include <linux/wait.h>
69174 #include <linux/workqueue.h>
69175 @@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
69176 */
69177 static __init int init_posix_timers(void)
69178 {
69179 - struct k_clock clock_realtime = {
69180 + const struct k_clock clock_realtime = {
69181 .clock_getres = hrtimer_get_res,
69182 .clock_get = posix_clock_realtime_get,
69183 .clock_set = posix_clock_realtime_set,
69184 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void
69185 .timer_get = common_timer_get,
69186 .timer_del = common_timer_del,
69187 };
69188 - struct k_clock clock_monotonic = {
69189 + const struct k_clock clock_monotonic = {
69190 .clock_getres = hrtimer_get_res,
69191 .clock_get = posix_ktime_get_ts,
69192 .nsleep = common_nsleep,
69193 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void
69194 .timer_get = common_timer_get,
69195 .timer_del = common_timer_del,
69196 };
69197 - struct k_clock clock_monotonic_raw = {
69198 + const struct k_clock clock_monotonic_raw = {
69199 .clock_getres = hrtimer_get_res,
69200 .clock_get = posix_get_monotonic_raw,
69201 };
69202 - struct k_clock clock_realtime_coarse = {
69203 + const struct k_clock clock_realtime_coarse = {
69204 .clock_getres = posix_get_coarse_res,
69205 .clock_get = posix_get_realtime_coarse,
69206 };
69207 - struct k_clock clock_monotonic_coarse = {
69208 + const struct k_clock clock_monotonic_coarse = {
69209 .clock_getres = posix_get_coarse_res,
69210 .clock_get = posix_get_monotonic_coarse,
69211 };
69212 - struct k_clock clock_boottime = {
69213 + const struct k_clock clock_boottime = {
69214 .clock_getres = hrtimer_get_res,
69215 .clock_get = posix_get_boottime,
69216 .nsleep = common_nsleep,
69217 @@ -272,6 +273,8 @@ static __init int init_posix_timers(void
69218 .timer_del = common_timer_del,
69219 };
69220
69221 + pax_track_stack();
69222 +
69223 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
69224 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
69225 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
69226 @@ -454,7 +457,7 @@ static struct pid *good_sigevent(sigeven
69227 }
69228
69229 void posix_timers_register_clock(const clockid_t clock_id,
69230 - struct k_clock *new_clock)
69231 + const struct k_clock *new_clock)
69232 {
69233 if ((unsigned) clock_id >= MAX_CLOCKS) {
69234 printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
69235 @@ -506,7 +509,7 @@ static void release_posix_timer(struct k
69236 kmem_cache_free(posix_timers_cache, tmr);
69237 }
69238
69239 -static struct k_clock *clockid_to_kclock(const clockid_t id)
69240 +static const struct k_clock *clockid_to_kclock(const clockid_t id)
69241 {
69242 if (id < 0)
69243 return (id & CLOCKFD_MASK) == CLOCKFD ?
69244 @@ -529,7 +532,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
69245 struct sigevent __user *, timer_event_spec,
69246 timer_t __user *, created_timer_id)
69247 {
69248 - struct k_clock *kc = clockid_to_kclock(which_clock);
69249 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69250 struct k_itimer *new_timer;
69251 int error, new_timer_id;
69252 sigevent_t event;
69253 @@ -714,7 +717,7 @@ SYSCALL_DEFINE2(timer_gettime, timer_t,
69254 {
69255 struct itimerspec cur_setting;
69256 struct k_itimer *timr;
69257 - struct k_clock *kc;
69258 + const struct k_clock *kc;
69259 unsigned long flags;
69260 int ret = 0;
69261
69262 @@ -822,7 +825,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t,
69263 int error = 0;
69264 unsigned long flag;
69265 struct itimerspec *rtn = old_setting ? &old_spec : NULL;
69266 - struct k_clock *kc;
69267 + const struct k_clock *kc;
69268
69269 if (!new_setting)
69270 return -EINVAL;
69271 @@ -868,7 +871,7 @@ static int common_timer_del(struct k_iti
69272
69273 static inline int timer_delete_hook(struct k_itimer *timer)
69274 {
69275 - struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69276 + const struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69277
69278 if (WARN_ON_ONCE(!kc || !kc->timer_del))
69279 return -EINVAL;
69280 @@ -947,7 +950,7 @@ void exit_itimers(struct signal_struct *
69281 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69282 const struct timespec __user *, tp)
69283 {
69284 - struct k_clock *kc = clockid_to_kclock(which_clock);
69285 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69286 struct timespec new_tp;
69287
69288 if (!kc || !kc->clock_set)
69289 @@ -956,13 +959,20 @@ SYSCALL_DEFINE2(clock_settime, const clo
69290 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69291 return -EFAULT;
69292
69293 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69294 + have their clock_set fptr set to a nosettime dummy function
69295 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69296 + call common_clock_set, which calls do_sys_settimeofday, which
69297 + we hook
69298 + */
69299 +
69300 return kc->clock_set(which_clock, &new_tp);
69301 }
69302
69303 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
69304 struct timespec __user *,tp)
69305 {
69306 - struct k_clock *kc = clockid_to_kclock(which_clock);
69307 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69308 struct timespec kernel_tp;
69309 int error;
69310
69311 @@ -980,7 +990,7 @@ SYSCALL_DEFINE2(clock_gettime, const clo
69312 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
69313 struct timex __user *, utx)
69314 {
69315 - struct k_clock *kc = clockid_to_kclock(which_clock);
69316 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69317 struct timex ktx;
69318 int err;
69319
69320 @@ -1003,7 +1013,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clo
69321 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
69322 struct timespec __user *, tp)
69323 {
69324 - struct k_clock *kc = clockid_to_kclock(which_clock);
69325 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69326 struct timespec rtn_tp;
69327 int error;
69328
69329 @@ -1033,7 +1043,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69330 const struct timespec __user *, rqtp,
69331 struct timespec __user *, rmtp)
69332 {
69333 - struct k_clock *kc = clockid_to_kclock(which_clock);
69334 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69335 struct timespec t;
69336
69337 if (!kc)
69338 @@ -1057,7 +1067,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69339 long clock_nanosleep_restart(struct restart_block *restart_block)
69340 {
69341 clockid_t which_clock = restart_block->nanosleep.index;
69342 - struct k_clock *kc = clockid_to_kclock(which_clock);
69343 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69344
69345 if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))
69346 return -EINVAL;
69347 diff -urNp linux-2.6.39.1/kernel/power/poweroff.c linux-2.6.39.1/kernel/power/poweroff.c
69348 --- linux-2.6.39.1/kernel/power/poweroff.c 2011-05-19 00:06:34.000000000 -0400
69349 +++ linux-2.6.39.1/kernel/power/poweroff.c 2011-05-22 19:36:33.000000000 -0400
69350 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
69351 .enable_mask = SYSRQ_ENABLE_BOOT,
69352 };
69353
69354 -static int pm_sysrq_init(void)
69355 +static int __init pm_sysrq_init(void)
69356 {
69357 register_sysrq_key('o', &sysrq_poweroff_op);
69358 return 0;
69359 diff -urNp linux-2.6.39.1/kernel/power/process.c linux-2.6.39.1/kernel/power/process.c
69360 --- linux-2.6.39.1/kernel/power/process.c 2011-05-19 00:06:34.000000000 -0400
69361 +++ linux-2.6.39.1/kernel/power/process.c 2011-05-22 19:36:33.000000000 -0400
69362 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
69363 u64 elapsed_csecs64;
69364 unsigned int elapsed_csecs;
69365 bool wakeup = false;
69366 + bool timedout = false;
69367
69368 do_gettimeofday(&start);
69369
69370 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
69371
69372 while (true) {
69373 todo = 0;
69374 + if (time_after(jiffies, end_time))
69375 + timedout = true;
69376 read_lock(&tasklist_lock);
69377 do_each_thread(g, p) {
69378 if (frozen(p) || !freezable(p))
69379 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
69380 * try_to_stop() after schedule() in ptrace/signal
69381 * stop sees TIF_FREEZE.
69382 */
69383 - if (!task_is_stopped_or_traced(p) &&
69384 - !freezer_should_skip(p))
69385 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69386 todo++;
69387 + if (timedout) {
69388 + printk(KERN_ERR "Task refusing to freeze:\n");
69389 + sched_show_task(p);
69390 + }
69391 + }
69392 } while_each_thread(g, p);
69393 read_unlock(&tasklist_lock);
69394
69395 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
69396 todo += wq_busy;
69397 }
69398
69399 - if (!todo || time_after(jiffies, end_time))
69400 + if (!todo || timedout)
69401 break;
69402
69403 if (pm_wakeup_pending()) {
69404 diff -urNp linux-2.6.39.1/kernel/printk.c linux-2.6.39.1/kernel/printk.c
69405 --- linux-2.6.39.1/kernel/printk.c 2011-05-19 00:06:34.000000000 -0400
69406 +++ linux-2.6.39.1/kernel/printk.c 2011-05-22 19:41:42.000000000 -0400
69407 @@ -284,12 +284,17 @@ static int check_syslog_permissions(int
69408 if (from_file && type != SYSLOG_ACTION_OPEN)
69409 return 0;
69410
69411 +#ifdef CONFIG_GRKERNSEC_DMESG
69412 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69413 + return -EPERM;
69414 +#endif
69415 +
69416 if (syslog_action_restricted(type)) {
69417 if (capable(CAP_SYSLOG))
69418 return 0;
69419 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
69420 if (capable(CAP_SYS_ADMIN)) {
69421 - WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
69422 + printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
69423 "but no CAP_SYSLOG (deprecated).\n");
69424 return 0;
69425 }
69426 diff -urNp linux-2.6.39.1/kernel/profile.c linux-2.6.39.1/kernel/profile.c
69427 --- linux-2.6.39.1/kernel/profile.c 2011-05-19 00:06:34.000000000 -0400
69428 +++ linux-2.6.39.1/kernel/profile.c 2011-05-22 19:36:33.000000000 -0400
69429 @@ -39,7 +39,7 @@ struct profile_hit {
69430 /* Oprofile timer tick hook */
69431 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69432
69433 -static atomic_t *prof_buffer;
69434 +static atomic_unchecked_t *prof_buffer;
69435 static unsigned long prof_len, prof_shift;
69436
69437 int prof_on __read_mostly;
69438 @@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
69439 hits[i].pc = 0;
69440 continue;
69441 }
69442 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69443 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69444 hits[i].hits = hits[i].pc = 0;
69445 }
69446 }
69447 @@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
69448 * Add the current hit(s) and flush the write-queue out
69449 * to the global buffer:
69450 */
69451 - atomic_add(nr_hits, &prof_buffer[pc]);
69452 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69453 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69454 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69455 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69456 hits[i].pc = hits[i].hits = 0;
69457 }
69458 out:
69459 @@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
69460 if (prof_on != type || !prof_buffer)
69461 return;
69462 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69463 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69464 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69465 }
69466 #endif /* !CONFIG_SMP */
69467 EXPORT_SYMBOL_GPL(profile_hits);
69468 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
69469 return -EFAULT;
69470 buf++; p++; count--; read++;
69471 }
69472 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69473 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69474 if (copy_to_user(buf, (void *)pnt, count))
69475 return -EFAULT;
69476 read += count;
69477 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
69478 }
69479 #endif
69480 profile_discard_flip_buffers();
69481 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69482 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69483 return count;
69484 }
69485
69486 diff -urNp linux-2.6.39.1/kernel/ptrace.c linux-2.6.39.1/kernel/ptrace.c
69487 --- linux-2.6.39.1/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
69488 +++ linux-2.6.39.1/kernel/ptrace.c 2011-05-23 17:07:00.000000000 -0400
69489 @@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
69490 return ret;
69491 }
69492
69493 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
69494 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
69495 + unsigned int log)
69496 {
69497 const struct cred *cred = current_cred(), *tcred;
69498
69499 @@ -143,7 +144,8 @@ int __ptrace_may_access(struct task_stru
69500 cred->gid == tcred->sgid &&
69501 cred->gid == tcred->gid))
69502 goto ok;
69503 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
69504 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
69505 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
69506 goto ok;
69507 rcu_read_unlock();
69508 return -EPERM;
69509 @@ -152,7 +154,9 @@ ok:
69510 smp_rmb();
69511 if (task->mm)
69512 dumpable = get_dumpable(task->mm);
69513 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
69514 + if (!dumpable &&
69515 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
69516 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
69517 return -EPERM;
69518
69519 return security_ptrace_access_check(task, mode);
69520 @@ -162,7 +166,16 @@ bool ptrace_may_access(struct task_struc
69521 {
69522 int err;
69523 task_lock(task);
69524 - err = __ptrace_may_access(task, mode);
69525 + err = __ptrace_may_access(task, mode, 0);
69526 + task_unlock(task);
69527 + return !err;
69528 +}
69529 +
69530 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
69531 +{
69532 + int err;
69533 + task_lock(task);
69534 + err = __ptrace_may_access(task, mode, 1);
69535 task_unlock(task);
69536 return !err;
69537 }
69538 @@ -189,7 +202,7 @@ static int ptrace_attach(struct task_str
69539 goto out;
69540
69541 task_lock(task);
69542 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
69543 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
69544 task_unlock(task);
69545 if (retval)
69546 goto unlock_creds;
69547 @@ -202,7 +215,7 @@ static int ptrace_attach(struct task_str
69548 goto unlock_tasklist;
69549
69550 task->ptrace = PT_PTRACED;
69551 - if (task_ns_capable(task, CAP_SYS_PTRACE))
69552 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
69553 task->ptrace |= PT_PTRACE_CAP;
69554
69555 __ptrace_link(task, current);
69556 @@ -362,6 +375,8 @@ int ptrace_readdata(struct task_struct *
69557 {
69558 int copied = 0;
69559
69560 + pax_track_stack();
69561 +
69562 while (len > 0) {
69563 char buf[128];
69564 int this_len, retval;
69565 @@ -373,7 +388,7 @@ int ptrace_readdata(struct task_struct *
69566 break;
69567 return -EIO;
69568 }
69569 - if (copy_to_user(dst, buf, retval))
69570 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69571 return -EFAULT;
69572 copied += retval;
69573 src += retval;
69574 @@ -387,6 +402,8 @@ int ptrace_writedata(struct task_struct
69575 {
69576 int copied = 0;
69577
69578 + pax_track_stack();
69579 +
69580 while (len > 0) {
69581 char buf[128];
69582 int this_len, retval;
69583 @@ -569,9 +586,11 @@ int ptrace_request(struct task_struct *c
69584 {
69585 int ret = -EIO;
69586 siginfo_t siginfo;
69587 - void __user *datavp = (void __user *) data;
69588 + void __user *datavp = (__force void __user *) data;
69589 unsigned long __user *datalp = datavp;
69590
69591 + pax_track_stack();
69592 +
69593 switch (request) {
69594 case PTRACE_PEEKTEXT:
69595 case PTRACE_PEEKDATA:
69596 @@ -717,14 +736,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
69597 goto out;
69598 }
69599
69600 + if (gr_handle_ptrace(child, request)) {
69601 + ret = -EPERM;
69602 + goto out_put_task_struct;
69603 + }
69604 +
69605 if (request == PTRACE_ATTACH) {
69606 ret = ptrace_attach(child);
69607 /*
69608 * Some architectures need to do book-keeping after
69609 * a ptrace attach.
69610 */
69611 - if (!ret)
69612 + if (!ret) {
69613 arch_ptrace_attach(child);
69614 + gr_audit_ptrace(child);
69615 + }
69616 goto out_put_task_struct;
69617 }
69618
69619 @@ -749,7 +775,7 @@ int generic_ptrace_peekdata(struct task_
69620 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69621 if (copied != sizeof(tmp))
69622 return -EIO;
69623 - return put_user(tmp, (unsigned long __user *)data);
69624 + return put_user(tmp, (__force unsigned long __user *)data);
69625 }
69626
69627 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69628 @@ -772,6 +798,8 @@ int compat_ptrace_request(struct task_st
69629 siginfo_t siginfo;
69630 int ret;
69631
69632 + pax_track_stack();
69633 +
69634 switch (request) {
69635 case PTRACE_PEEKTEXT:
69636 case PTRACE_PEEKDATA:
69637 @@ -859,14 +887,21 @@ asmlinkage long compat_sys_ptrace(compat
69638 goto out;
69639 }
69640
69641 + if (gr_handle_ptrace(child, request)) {
69642 + ret = -EPERM;
69643 + goto out_put_task_struct;
69644 + }
69645 +
69646 if (request == PTRACE_ATTACH) {
69647 ret = ptrace_attach(child);
69648 /*
69649 * Some architectures need to do book-keeping after
69650 * a ptrace attach.
69651 */
69652 - if (!ret)
69653 + if (!ret) {
69654 arch_ptrace_attach(child);
69655 + gr_audit_ptrace(child);
69656 + }
69657 goto out_put_task_struct;
69658 }
69659
69660 diff -urNp linux-2.6.39.1/kernel/rcutorture.c linux-2.6.39.1/kernel/rcutorture.c
69661 --- linux-2.6.39.1/kernel/rcutorture.c 2011-05-19 00:06:34.000000000 -0400
69662 +++ linux-2.6.39.1/kernel/rcutorture.c 2011-05-22 19:36:33.000000000 -0400
69663 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
69664 { 0 };
69665 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69666 { 0 };
69667 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69668 -static atomic_t n_rcu_torture_alloc;
69669 -static atomic_t n_rcu_torture_alloc_fail;
69670 -static atomic_t n_rcu_torture_free;
69671 -static atomic_t n_rcu_torture_mberror;
69672 -static atomic_t n_rcu_torture_error;
69673 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69674 +static atomic_unchecked_t n_rcu_torture_alloc;
69675 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69676 +static atomic_unchecked_t n_rcu_torture_free;
69677 +static atomic_unchecked_t n_rcu_torture_mberror;
69678 +static atomic_unchecked_t n_rcu_torture_error;
69679 static long n_rcu_torture_boost_ktrerror;
69680 static long n_rcu_torture_boost_rterror;
69681 static long n_rcu_torture_boost_allocerror;
69682 @@ -225,11 +225,11 @@ rcu_torture_alloc(void)
69683
69684 spin_lock_bh(&rcu_torture_lock);
69685 if (list_empty(&rcu_torture_freelist)) {
69686 - atomic_inc(&n_rcu_torture_alloc_fail);
69687 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69688 spin_unlock_bh(&rcu_torture_lock);
69689 return NULL;
69690 }
69691 - atomic_inc(&n_rcu_torture_alloc);
69692 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69693 p = rcu_torture_freelist.next;
69694 list_del_init(p);
69695 spin_unlock_bh(&rcu_torture_lock);
69696 @@ -242,7 +242,7 @@ rcu_torture_alloc(void)
69697 static void
69698 rcu_torture_free(struct rcu_torture *p)
69699 {
69700 - atomic_inc(&n_rcu_torture_free);
69701 + atomic_inc_unchecked(&n_rcu_torture_free);
69702 spin_lock_bh(&rcu_torture_lock);
69703 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69704 spin_unlock_bh(&rcu_torture_lock);
69705 @@ -362,7 +362,7 @@ rcu_torture_cb(struct rcu_head *p)
69706 i = rp->rtort_pipe_count;
69707 if (i > RCU_TORTURE_PIPE_LEN)
69708 i = RCU_TORTURE_PIPE_LEN;
69709 - atomic_inc(&rcu_torture_wcount[i]);
69710 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69711 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69712 rp->rtort_mbtest = 0;
69713 rcu_torture_free(rp);
69714 @@ -409,7 +409,7 @@ static void rcu_sync_torture_deferred_fr
69715 i = rp->rtort_pipe_count;
69716 if (i > RCU_TORTURE_PIPE_LEN)
69717 i = RCU_TORTURE_PIPE_LEN;
69718 - atomic_inc(&rcu_torture_wcount[i]);
69719 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69720 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69721 rp->rtort_mbtest = 0;
69722 list_del(&rp->rtort_free);
69723 @@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
69724 i = old_rp->rtort_pipe_count;
69725 if (i > RCU_TORTURE_PIPE_LEN)
69726 i = RCU_TORTURE_PIPE_LEN;
69727 - atomic_inc(&rcu_torture_wcount[i]);
69728 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69729 old_rp->rtort_pipe_count++;
69730 cur_ops->deferred_free(old_rp);
69731 }
69732 @@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
69733 return;
69734 }
69735 if (p->rtort_mbtest == 0)
69736 - atomic_inc(&n_rcu_torture_mberror);
69737 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69738 spin_lock(&rand_lock);
69739 cur_ops->read_delay(&rand);
69740 n_rcu_torture_timers++;
69741 @@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
69742 continue;
69743 }
69744 if (p->rtort_mbtest == 0)
69745 - atomic_inc(&n_rcu_torture_mberror);
69746 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69747 cur_ops->read_delay(&rand);
69748 preempt_disable();
69749 pipe_count = p->rtort_pipe_count;
69750 @@ -1072,10 +1072,10 @@ rcu_torture_printk(char *page)
69751 rcu_torture_current,
69752 rcu_torture_current_version,
69753 list_empty(&rcu_torture_freelist),
69754 - atomic_read(&n_rcu_torture_alloc),
69755 - atomic_read(&n_rcu_torture_alloc_fail),
69756 - atomic_read(&n_rcu_torture_free),
69757 - atomic_read(&n_rcu_torture_mberror),
69758 + atomic_read_unchecked(&n_rcu_torture_alloc),
69759 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69760 + atomic_read_unchecked(&n_rcu_torture_free),
69761 + atomic_read_unchecked(&n_rcu_torture_mberror),
69762 n_rcu_torture_boost_ktrerror,
69763 n_rcu_torture_boost_rterror,
69764 n_rcu_torture_boost_allocerror,
69765 @@ -1083,7 +1083,7 @@ rcu_torture_printk(char *page)
69766 n_rcu_torture_boost_failure,
69767 n_rcu_torture_boosts,
69768 n_rcu_torture_timers);
69769 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69770 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69771 n_rcu_torture_boost_ktrerror != 0 ||
69772 n_rcu_torture_boost_rterror != 0 ||
69773 n_rcu_torture_boost_allocerror != 0 ||
69774 @@ -1093,7 +1093,7 @@ rcu_torture_printk(char *page)
69775 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69776 if (i > 1) {
69777 cnt += sprintf(&page[cnt], "!!! ");
69778 - atomic_inc(&n_rcu_torture_error);
69779 + atomic_inc_unchecked(&n_rcu_torture_error);
69780 WARN_ON_ONCE(1);
69781 }
69782 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69783 @@ -1107,7 +1107,7 @@ rcu_torture_printk(char *page)
69784 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69785 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69786 cnt += sprintf(&page[cnt], " %d",
69787 - atomic_read(&rcu_torture_wcount[i]));
69788 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69789 }
69790 cnt += sprintf(&page[cnt], "\n");
69791 if (cur_ops->stats)
69792 @@ -1415,7 +1415,7 @@ rcu_torture_cleanup(void)
69793
69794 if (cur_ops->cleanup)
69795 cur_ops->cleanup();
69796 - if (atomic_read(&n_rcu_torture_error))
69797 + if (atomic_read_unchecked(&n_rcu_torture_error))
69798 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69799 else
69800 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
69801 @@ -1479,11 +1479,11 @@ rcu_torture_init(void)
69802
69803 rcu_torture_current = NULL;
69804 rcu_torture_current_version = 0;
69805 - atomic_set(&n_rcu_torture_alloc, 0);
69806 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69807 - atomic_set(&n_rcu_torture_free, 0);
69808 - atomic_set(&n_rcu_torture_mberror, 0);
69809 - atomic_set(&n_rcu_torture_error, 0);
69810 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69811 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69812 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69813 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69814 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69815 n_rcu_torture_boost_ktrerror = 0;
69816 n_rcu_torture_boost_rterror = 0;
69817 n_rcu_torture_boost_allocerror = 0;
69818 @@ -1491,7 +1491,7 @@ rcu_torture_init(void)
69819 n_rcu_torture_boost_failure = 0;
69820 n_rcu_torture_boosts = 0;
69821 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69822 - atomic_set(&rcu_torture_wcount[i], 0);
69823 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69824 for_each_possible_cpu(cpu) {
69825 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69826 per_cpu(rcu_torture_count, cpu)[i] = 0;
69827 diff -urNp linux-2.6.39.1/kernel/rcutree.c linux-2.6.39.1/kernel/rcutree.c
69828 --- linux-2.6.39.1/kernel/rcutree.c 2011-05-19 00:06:34.000000000 -0400
69829 +++ linux-2.6.39.1/kernel/rcutree.c 2011-05-22 19:36:33.000000000 -0400
69830 @@ -1389,7 +1389,7 @@ __rcu_process_callbacks(struct rcu_state
69831 /*
69832 * Do softirq processing for the current CPU.
69833 */
69834 -static void rcu_process_callbacks(struct softirq_action *unused)
69835 +static void rcu_process_callbacks(void)
69836 {
69837 /*
69838 * Memory references from any prior RCU read-side critical sections
69839 diff -urNp linux-2.6.39.1/kernel/rcutree_plugin.h linux-2.6.39.1/kernel/rcutree_plugin.h
69840 --- linux-2.6.39.1/kernel/rcutree_plugin.h 2011-05-19 00:06:34.000000000 -0400
69841 +++ linux-2.6.39.1/kernel/rcutree_plugin.h 2011-05-22 19:36:33.000000000 -0400
69842 @@ -730,7 +730,7 @@ void synchronize_rcu_expedited(void)
69843
69844 /* Clean up and exit. */
69845 smp_mb(); /* ensure expedited GP seen before counter increment. */
69846 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69847 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69848 unlock_mb_ret:
69849 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69850 mb_ret:
69851 @@ -1025,8 +1025,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
69852
69853 #else /* #ifndef CONFIG_SMP */
69854
69855 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69856 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69857 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69858 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69859
69860 static int synchronize_sched_expedited_cpu_stop(void *data)
69861 {
69862 @@ -1081,7 +1081,7 @@ void synchronize_sched_expedited(void)
69863 int firstsnap, s, snap, trycount = 0;
69864
69865 /* Note that atomic_inc_return() implies full memory barrier. */
69866 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69867 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69868 get_online_cpus();
69869
69870 /*
69871 @@ -1102,7 +1102,7 @@ void synchronize_sched_expedited(void)
69872 }
69873
69874 /* Check to see if someone else did our work for us. */
69875 - s = atomic_read(&sync_sched_expedited_done);
69876 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69877 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69878 smp_mb(); /* ensure test happens before caller kfree */
69879 return;
69880 @@ -1117,7 +1117,7 @@ void synchronize_sched_expedited(void)
69881 * grace period works for us.
69882 */
69883 get_online_cpus();
69884 - snap = atomic_read(&sync_sched_expedited_started) - 1;
69885 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
69886 smp_mb(); /* ensure read is before try_stop_cpus(). */
69887 }
69888
69889 @@ -1128,12 +1128,12 @@ void synchronize_sched_expedited(void)
69890 * than we did beat us to the punch.
69891 */
69892 do {
69893 - s = atomic_read(&sync_sched_expedited_done);
69894 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69895 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69896 smp_mb(); /* ensure test happens before caller kfree */
69897 break;
69898 }
69899 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69900 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69901
69902 put_online_cpus();
69903 }
69904 diff -urNp linux-2.6.39.1/kernel/relay.c linux-2.6.39.1/kernel/relay.c
69905 --- linux-2.6.39.1/kernel/relay.c 2011-05-19 00:06:34.000000000 -0400
69906 +++ linux-2.6.39.1/kernel/relay.c 2011-05-22 19:36:33.000000000 -0400
69907 @@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
69908 };
69909 ssize_t ret;
69910
69911 + pax_track_stack();
69912 +
69913 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
69914 return 0;
69915 if (splice_grow_spd(pipe, &spd))
69916 diff -urNp linux-2.6.39.1/kernel/resource.c linux-2.6.39.1/kernel/resource.c
69917 --- linux-2.6.39.1/kernel/resource.c 2011-05-19 00:06:34.000000000 -0400
69918 +++ linux-2.6.39.1/kernel/resource.c 2011-05-22 19:41:42.000000000 -0400
69919 @@ -133,8 +133,18 @@ static const struct file_operations proc
69920
69921 static int __init ioresources_init(void)
69922 {
69923 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69924 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69925 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69926 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69927 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69928 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69929 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69930 +#endif
69931 +#else
69932 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69933 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69934 +#endif
69935 return 0;
69936 }
69937 __initcall(ioresources_init);
69938 diff -urNp linux-2.6.39.1/kernel/rtmutex-tester.c linux-2.6.39.1/kernel/rtmutex-tester.c
69939 --- linux-2.6.39.1/kernel/rtmutex-tester.c 2011-05-19 00:06:34.000000000 -0400
69940 +++ linux-2.6.39.1/kernel/rtmutex-tester.c 2011-05-22 19:36:33.000000000 -0400
69941 @@ -20,7 +20,7 @@
69942 #define MAX_RT_TEST_MUTEXES 8
69943
69944 static spinlock_t rttest_lock;
69945 -static atomic_t rttest_event;
69946 +static atomic_unchecked_t rttest_event;
69947
69948 struct test_thread_data {
69949 int opcode;
69950 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
69951
69952 case RTTEST_LOCKCONT:
69953 td->mutexes[td->opdata] = 1;
69954 - td->event = atomic_add_return(1, &rttest_event);
69955 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69956 return 0;
69957
69958 case RTTEST_RESET:
69959 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
69960 return 0;
69961
69962 case RTTEST_RESETEVENT:
69963 - atomic_set(&rttest_event, 0);
69964 + atomic_set_unchecked(&rttest_event, 0);
69965 return 0;
69966
69967 default:
69968 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
69969 return ret;
69970
69971 td->mutexes[id] = 1;
69972 - td->event = atomic_add_return(1, &rttest_event);
69973 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69974 rt_mutex_lock(&mutexes[id]);
69975 - td->event = atomic_add_return(1, &rttest_event);
69976 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69977 td->mutexes[id] = 4;
69978 return 0;
69979
69980 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
69981 return ret;
69982
69983 td->mutexes[id] = 1;
69984 - td->event = atomic_add_return(1, &rttest_event);
69985 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69986 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69987 - td->event = atomic_add_return(1, &rttest_event);
69988 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69989 td->mutexes[id] = ret ? 0 : 4;
69990 return ret ? -EINTR : 0;
69991
69992 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
69993 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69994 return ret;
69995
69996 - td->event = atomic_add_return(1, &rttest_event);
69997 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69998 rt_mutex_unlock(&mutexes[id]);
69999 - td->event = atomic_add_return(1, &rttest_event);
70000 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70001 td->mutexes[id] = 0;
70002 return 0;
70003
70004 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
70005 break;
70006
70007 td->mutexes[dat] = 2;
70008 - td->event = atomic_add_return(1, &rttest_event);
70009 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70010 break;
70011
70012 default:
70013 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
70014 return;
70015
70016 td->mutexes[dat] = 3;
70017 - td->event = atomic_add_return(1, &rttest_event);
70018 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70019 break;
70020
70021 case RTTEST_LOCKNOWAIT:
70022 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
70023 return;
70024
70025 td->mutexes[dat] = 1;
70026 - td->event = atomic_add_return(1, &rttest_event);
70027 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70028 return;
70029
70030 default:
70031 diff -urNp linux-2.6.39.1/kernel/sched_autogroup.c linux-2.6.39.1/kernel/sched_autogroup.c
70032 --- linux-2.6.39.1/kernel/sched_autogroup.c 2011-05-19 00:06:34.000000000 -0400
70033 +++ linux-2.6.39.1/kernel/sched_autogroup.c 2011-05-22 19:36:33.000000000 -0400
70034 @@ -7,7 +7,7 @@
70035
70036 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70037 static struct autogroup autogroup_default;
70038 -static atomic_t autogroup_seq_nr;
70039 +static atomic_unchecked_t autogroup_seq_nr;
70040
70041 static void __init autogroup_init(struct task_struct *init_task)
70042 {
70043 @@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
70044
70045 kref_init(&ag->kref);
70046 init_rwsem(&ag->lock);
70047 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70048 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70049 ag->tg = tg;
70050 #ifdef CONFIG_RT_GROUP_SCHED
70051 /*
70052 diff -urNp linux-2.6.39.1/kernel/sched.c linux-2.6.39.1/kernel/sched.c
70053 --- linux-2.6.39.1/kernel/sched.c 2011-05-19 00:06:34.000000000 -0400
70054 +++ linux-2.6.39.1/kernel/sched.c 2011-05-23 17:07:00.000000000 -0400
70055 @@ -4078,6 +4078,8 @@ asmlinkage void __sched schedule(void)
70056 struct rq *rq;
70057 int cpu;
70058
70059 + pax_track_stack();
70060 +
70061 need_resched:
70062 preempt_disable();
70063 cpu = smp_processor_id();
70064 @@ -4165,7 +4167,7 @@ EXPORT_SYMBOL(schedule);
70065 * Look out! "owner" is an entirely speculative pointer
70066 * access and not reliable.
70067 */
70068 -int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
70069 +int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
70070 {
70071 unsigned int cpu;
70072 struct rq *rq;
70073 @@ -4179,10 +4181,10 @@ int mutex_spin_on_owner(struct mutex *lo
70074 * DEBUG_PAGEALLOC could have unmapped it if
70075 * the mutex owner just released it and exited.
70076 */
70077 - if (probe_kernel_address(&owner->cpu, cpu))
70078 + if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
70079 return 0;
70080 #else
70081 - cpu = owner->cpu;
70082 + cpu = task_thread_info(owner)->cpu;
70083 #endif
70084
70085 /*
70086 @@ -4219,7 +4221,7 @@ int mutex_spin_on_owner(struct mutex *lo
70087 /*
70088 * Is that owner really running on that cpu?
70089 */
70090 - if (task_thread_info(rq->curr) != owner || need_resched())
70091 + if (rq->curr != owner || need_resched())
70092 return 0;
70093
70094 arch_mutex_cpu_relax();
70095 @@ -4778,6 +4780,8 @@ int can_nice(const struct task_struct *p
70096 /* convert nice value [19,-20] to rlimit style value [1,40] */
70097 int nice_rlim = 20 - nice;
70098
70099 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70100 +
70101 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70102 capable(CAP_SYS_NICE));
70103 }
70104 @@ -4811,7 +4815,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70105 if (nice > 19)
70106 nice = 19;
70107
70108 - if (increment < 0 && !can_nice(current, nice))
70109 + if (increment < 0 && (!can_nice(current, nice) ||
70110 + gr_handle_chroot_nice()))
70111 return -EPERM;
70112
70113 retval = security_task_setnice(current, nice);
70114 @@ -4957,6 +4962,7 @@ recheck:
70115 unsigned long rlim_rtprio =
70116 task_rlimit(p, RLIMIT_RTPRIO);
70117
70118 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70119 /* can't set/change the rt policy */
70120 if (policy != p->policy && !rlim_rtprio)
70121 return -EPERM;
70122 @@ -7164,7 +7170,7 @@ static void init_sched_groups_power(int
70123 long power;
70124 int weight;
70125
70126 - WARN_ON(!sd || !sd->groups);
70127 + BUG_ON(!sd || !sd->groups);
70128
70129 if (cpu != group_first_cpu(sd->groups))
70130 return;
70131 diff -urNp linux-2.6.39.1/kernel/sched_fair.c linux-2.6.39.1/kernel/sched_fair.c
70132 --- linux-2.6.39.1/kernel/sched_fair.c 2011-05-19 00:06:34.000000000 -0400
70133 +++ linux-2.6.39.1/kernel/sched_fair.c 2011-05-22 19:36:33.000000000 -0400
70134 @@ -3999,7 +3999,7 @@ static void nohz_idle_balance(int this_c
70135 * run_rebalance_domains is triggered when needed from the scheduler tick.
70136 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70137 */
70138 -static void run_rebalance_domains(struct softirq_action *h)
70139 +static void run_rebalance_domains(void)
70140 {
70141 int this_cpu = smp_processor_id();
70142 struct rq *this_rq = cpu_rq(this_cpu);
70143 diff -urNp linux-2.6.39.1/kernel/signal.c linux-2.6.39.1/kernel/signal.c
70144 --- linux-2.6.39.1/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
70145 +++ linux-2.6.39.1/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
70146 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
70147
70148 int print_fatal_signals __read_mostly;
70149
70150 -static void __user *sig_handler(struct task_struct *t, int sig)
70151 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70152 {
70153 return t->sighand->action[sig - 1].sa.sa_handler;
70154 }
70155
70156 -static int sig_handler_ignored(void __user *handler, int sig)
70157 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70158 {
70159 /* Is it explicitly or implicitly ignored? */
70160 return handler == SIG_IGN ||
70161 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
70162 static int sig_task_ignored(struct task_struct *t, int sig,
70163 int from_ancestor_ns)
70164 {
70165 - void __user *handler;
70166 + __sighandler_t handler;
70167
70168 handler = sig_handler(t, sig);
70169
70170 @@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
70171 atomic_inc(&user->sigpending);
70172 rcu_read_unlock();
70173
70174 + if (!override_rlimit)
70175 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70176 +
70177 if (override_rlimit ||
70178 atomic_read(&user->sigpending) <=
70179 task_rlimit(t, RLIMIT_SIGPENDING)) {
70180 @@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
70181
70182 int unhandled_signal(struct task_struct *tsk, int sig)
70183 {
70184 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70185 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70186 if (is_global_init(tsk))
70187 return 1;
70188 if (handler != SIG_IGN && handler != SIG_DFL)
70189 @@ -693,6 +696,9 @@ static int check_kill_permission(int sig
70190 }
70191 }
70192
70193 + if (gr_handle_signal(t, sig))
70194 + return -EPERM;
70195 +
70196 return security_task_kill(t, info, sig, 0);
70197 }
70198
70199 @@ -1041,7 +1047,7 @@ __group_send_sig_info(int sig, struct si
70200 return send_signal(sig, info, p, 1);
70201 }
70202
70203 -static int
70204 +int
70205 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70206 {
70207 return send_signal(sig, info, t, 0);
70208 @@ -1078,6 +1084,7 @@ force_sig_info(int sig, struct siginfo *
70209 unsigned long int flags;
70210 int ret, blocked, ignored;
70211 struct k_sigaction *action;
70212 + int is_unhandled = 0;
70213
70214 spin_lock_irqsave(&t->sighand->siglock, flags);
70215 action = &t->sighand->action[sig-1];
70216 @@ -1092,9 +1099,18 @@ force_sig_info(int sig, struct siginfo *
70217 }
70218 if (action->sa.sa_handler == SIG_DFL)
70219 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70220 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70221 + is_unhandled = 1;
70222 ret = specific_send_sig_info(sig, info, t);
70223 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70224
70225 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70226 + normal operation */
70227 + if (is_unhandled) {
70228 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70229 + gr_handle_crash(t, sig);
70230 + }
70231 +
70232 return ret;
70233 }
70234
70235 @@ -1153,8 +1169,11 @@ int group_send_sig_info(int sig, struct
70236 ret = check_kill_permission(sig, info, p);
70237 rcu_read_unlock();
70238
70239 - if (!ret && sig)
70240 + if (!ret && sig) {
70241 ret = do_send_sig_info(sig, info, p, true);
70242 + if (!ret)
70243 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70244 + }
70245
70246 return ret;
70247 }
70248 @@ -1718,6 +1737,8 @@ void ptrace_notify(int exit_code)
70249 {
70250 siginfo_t info;
70251
70252 + pax_track_stack();
70253 +
70254 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
70255
70256 memset(&info, 0, sizeof info);
70257 diff -urNp linux-2.6.39.1/kernel/smp.c linux-2.6.39.1/kernel/smp.c
70258 --- linux-2.6.39.1/kernel/smp.c 2011-05-19 00:06:34.000000000 -0400
70259 +++ linux-2.6.39.1/kernel/smp.c 2011-05-22 19:36:33.000000000 -0400
70260 @@ -583,22 +583,22 @@ int smp_call_function(smp_call_func_t fu
70261 }
70262 EXPORT_SYMBOL(smp_call_function);
70263
70264 -void ipi_call_lock(void)
70265 +void ipi_call_lock(void) __acquires(call_function.lock)
70266 {
70267 raw_spin_lock(&call_function.lock);
70268 }
70269
70270 -void ipi_call_unlock(void)
70271 +void ipi_call_unlock(void) __releases(call_function.lock)
70272 {
70273 raw_spin_unlock(&call_function.lock);
70274 }
70275
70276 -void ipi_call_lock_irq(void)
70277 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
70278 {
70279 raw_spin_lock_irq(&call_function.lock);
70280 }
70281
70282 -void ipi_call_unlock_irq(void)
70283 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
70284 {
70285 raw_spin_unlock_irq(&call_function.lock);
70286 }
70287 diff -urNp linux-2.6.39.1/kernel/softirq.c linux-2.6.39.1/kernel/softirq.c
70288 --- linux-2.6.39.1/kernel/softirq.c 2011-05-19 00:06:34.000000000 -0400
70289 +++ linux-2.6.39.1/kernel/softirq.c 2011-05-22 19:36:33.000000000 -0400
70290 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
70291
70292 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70293
70294 -char *softirq_to_name[NR_SOFTIRQS] = {
70295 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70296 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70297 "TASKLET", "SCHED", "HRTIMER", "RCU"
70298 };
70299 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
70300
70301 asmlinkage void __do_softirq(void)
70302 {
70303 - struct softirq_action *h;
70304 + const struct softirq_action *h;
70305 __u32 pending;
70306 int max_restart = MAX_SOFTIRQ_RESTART;
70307 int cpu;
70308 @@ -235,7 +235,7 @@ restart:
70309 kstat_incr_softirqs_this_cpu(vec_nr);
70310
70311 trace_softirq_entry(vec_nr);
70312 - h->action(h);
70313 + h->action();
70314 trace_softirq_exit(vec_nr);
70315 if (unlikely(prev_count != preempt_count())) {
70316 printk(KERN_ERR "huh, entered softirq %u %s %p"
70317 @@ -377,7 +377,7 @@ void raise_softirq(unsigned int nr)
70318 local_irq_restore(flags);
70319 }
70320
70321 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70322 +void open_softirq(int nr, void (*action)(void))
70323 {
70324 softirq_vec[nr].action = action;
70325 }
70326 @@ -433,7 +433,7 @@ void __tasklet_hi_schedule_first(struct
70327
70328 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70329
70330 -static void tasklet_action(struct softirq_action *a)
70331 +static void tasklet_action(void)
70332 {
70333 struct tasklet_struct *list;
70334
70335 @@ -468,7 +468,7 @@ static void tasklet_action(struct softir
70336 }
70337 }
70338
70339 -static void tasklet_hi_action(struct softirq_action *a)
70340 +static void tasklet_hi_action(void)
70341 {
70342 struct tasklet_struct *list;
70343
70344 diff -urNp linux-2.6.39.1/kernel/sys.c linux-2.6.39.1/kernel/sys.c
70345 --- linux-2.6.39.1/kernel/sys.c 2011-05-19 00:06:34.000000000 -0400
70346 +++ linux-2.6.39.1/kernel/sys.c 2011-05-22 21:08:10.000000000 -0400
70347 @@ -154,6 +154,12 @@ static int set_one_prio(struct task_stru
70348 error = -EACCES;
70349 goto out;
70350 }
70351 +
70352 + if (gr_handle_chroot_setpriority(p, niceval)) {
70353 + error = -EACCES;
70354 + goto out;
70355 + }
70356 +
70357 no_nice = security_task_setnice(p, niceval);
70358 if (no_nice) {
70359 error = no_nice;
70360 @@ -538,6 +544,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
70361 goto error;
70362 }
70363
70364 + if (gr_check_group_change(new->gid, new->egid, -1))
70365 + goto error;
70366 +
70367 if (rgid != (gid_t) -1 ||
70368 (egid != (gid_t) -1 && egid != old->gid))
70369 new->sgid = new->egid;
70370 @@ -567,6 +576,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70371 old = current_cred();
70372
70373 retval = -EPERM;
70374 +
70375 + if (gr_check_group_change(gid, gid, gid))
70376 + goto error;
70377 +
70378 if (nsown_capable(CAP_SETGID))
70379 new->gid = new->egid = new->sgid = new->fsgid = gid;
70380 else if (gid == old->gid || gid == old->sgid)
70381 @@ -647,6 +660,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
70382 goto error;
70383 }
70384
70385 + if (gr_check_user_change(new->uid, new->euid, -1))
70386 + goto error;
70387 +
70388 if (new->uid != old->uid) {
70389 retval = set_user(new);
70390 if (retval < 0)
70391 @@ -691,6 +707,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70392 old = current_cred();
70393
70394 retval = -EPERM;
70395 +
70396 + if (gr_check_crash_uid(uid))
70397 + goto error;
70398 + if (gr_check_user_change(uid, uid, uid))
70399 + goto error;
70400 +
70401 if (nsown_capable(CAP_SETUID)) {
70402 new->suid = new->uid = uid;
70403 if (uid != old->uid) {
70404 @@ -745,6 +767,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
70405 goto error;
70406 }
70407
70408 + if (gr_check_user_change(ruid, euid, -1))
70409 + goto error;
70410 +
70411 if (ruid != (uid_t) -1) {
70412 new->uid = ruid;
70413 if (ruid != old->uid) {
70414 @@ -809,6 +834,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
70415 goto error;
70416 }
70417
70418 + if (gr_check_group_change(rgid, egid, -1))
70419 + goto error;
70420 +
70421 if (rgid != (gid_t) -1)
70422 new->gid = rgid;
70423 if (egid != (gid_t) -1)
70424 @@ -855,6 +883,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70425 old = current_cred();
70426 old_fsuid = old->fsuid;
70427
70428 + if (gr_check_user_change(-1, -1, uid))
70429 + goto error;
70430 +
70431 if (uid == old->uid || uid == old->euid ||
70432 uid == old->suid || uid == old->fsuid ||
70433 nsown_capable(CAP_SETUID)) {
70434 @@ -865,6 +896,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70435 }
70436 }
70437
70438 +error:
70439 abort_creds(new);
70440 return old_fsuid;
70441
70442 @@ -891,12 +923,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70443 if (gid == old->gid || gid == old->egid ||
70444 gid == old->sgid || gid == old->fsgid ||
70445 nsown_capable(CAP_SETGID)) {
70446 + if (gr_check_group_change(-1, -1, gid))
70447 + goto error;
70448 +
70449 if (gid != old_fsgid) {
70450 new->fsgid = gid;
70451 goto change_okay;
70452 }
70453 }
70454
70455 +error:
70456 abort_creds(new);
70457 return old_fsgid;
70458
70459 @@ -1643,7 +1679,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
70460 error = get_dumpable(me->mm);
70461 break;
70462 case PR_SET_DUMPABLE:
70463 - if (arg2 < 0 || arg2 > 1) {
70464 + if (arg2 > 1) {
70465 error = -EINVAL;
70466 break;
70467 }
70468 diff -urNp linux-2.6.39.1/kernel/sysctl.c linux-2.6.39.1/kernel/sysctl.c
70469 --- linux-2.6.39.1/kernel/sysctl.c 2011-05-19 00:06:34.000000000 -0400
70470 +++ linux-2.6.39.1/kernel/sysctl.c 2011-05-22 20:23:10.000000000 -0400
70471 @@ -84,6 +84,13 @@
70472
70473
70474 #if defined(CONFIG_SYSCTL)
70475 +#include <linux/grsecurity.h>
70476 +#include <linux/grinternal.h>
70477 +
70478 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70479 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70480 + const int op);
70481 +extern int gr_handle_chroot_sysctl(const int op);
70482
70483 /* External variables not in a header file. */
70484 extern int sysctl_overcommit_memory;
70485 @@ -196,6 +203,7 @@ static int sysrq_sysctl_handler(ctl_tabl
70486 }
70487
70488 #endif
70489 +extern struct ctl_table grsecurity_table[];
70490
70491 static struct ctl_table root_table[];
70492 static struct ctl_table_root sysctl_table_root;
70493 @@ -225,6 +233,20 @@ extern struct ctl_table epoll_table[];
70494 int sysctl_legacy_va_layout;
70495 #endif
70496
70497 +#ifdef CONFIG_PAX_SOFTMODE
70498 +static ctl_table pax_table[] = {
70499 + {
70500 + .procname = "softmode",
70501 + .data = &pax_softmode,
70502 + .maxlen = sizeof(unsigned int),
70503 + .mode = 0600,
70504 + .proc_handler = &proc_dointvec,
70505 + },
70506 +
70507 + { }
70508 +};
70509 +#endif
70510 +
70511 /* The default sysctl tables: */
70512
70513 static struct ctl_table root_table[] = {
70514 @@ -271,6 +293,22 @@ static int max_extfrag_threshold = 1000;
70515 #endif
70516
70517 static struct ctl_table kern_table[] = {
70518 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70519 + {
70520 + .procname = "grsecurity",
70521 + .mode = 0500,
70522 + .child = grsecurity_table,
70523 + },
70524 +#endif
70525 +
70526 +#ifdef CONFIG_PAX_SOFTMODE
70527 + {
70528 + .procname = "pax",
70529 + .mode = 0500,
70530 + .child = pax_table,
70531 + },
70532 +#endif
70533 +
70534 {
70535 .procname = "sched_child_runs_first",
70536 .data = &sysctl_sched_child_runs_first,
70537 @@ -545,7 +583,7 @@ static struct ctl_table kern_table[] = {
70538 .data = &modprobe_path,
70539 .maxlen = KMOD_PATH_LEN,
70540 .mode = 0644,
70541 - .proc_handler = proc_dostring,
70542 + .proc_handler = proc_dostring_modpriv,
70543 },
70544 {
70545 .procname = "modules_disabled",
70546 @@ -707,16 +745,20 @@ static struct ctl_table kern_table[] = {
70547 .extra1 = &zero,
70548 .extra2 = &one,
70549 },
70550 +#endif
70551 {
70552 .procname = "kptr_restrict",
70553 .data = &kptr_restrict,
70554 .maxlen = sizeof(int),
70555 .mode = 0644,
70556 .proc_handler = proc_dmesg_restrict,
70557 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70558 + .extra1 = &two,
70559 +#else
70560 .extra1 = &zero,
70561 +#endif
70562 .extra2 = &two,
70563 },
70564 -#endif
70565 {
70566 .procname = "ngroups_max",
70567 .data = &ngroups_max,
70568 @@ -1189,6 +1231,13 @@ static struct ctl_table vm_table[] = {
70569 .proc_handler = proc_dointvec_minmax,
70570 .extra1 = &zero,
70571 },
70572 + {
70573 + .procname = "heap_stack_gap",
70574 + .data = &sysctl_heap_stack_gap,
70575 + .maxlen = sizeof(sysctl_heap_stack_gap),
70576 + .mode = 0644,
70577 + .proc_handler = proc_doulongvec_minmax,
70578 + },
70579 #else
70580 {
70581 .procname = "nr_trim_pages",
70582 @@ -1698,6 +1747,17 @@ static int test_perm(int mode, int op)
70583 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
70584 {
70585 int mode;
70586 + int error;
70587 +
70588 + if (table->parent != NULL && table->parent->procname != NULL &&
70589 + table->procname != NULL &&
70590 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70591 + return -EACCES;
70592 + if (gr_handle_chroot_sysctl(op))
70593 + return -EACCES;
70594 + error = gr_handle_sysctl(table, op);
70595 + if (error)
70596 + return error;
70597
70598 if (root->permissions)
70599 mode = root->permissions(root, current->nsproxy, table);
70600 @@ -2102,6 +2162,16 @@ int proc_dostring(struct ctl_table *tabl
70601 buffer, lenp, ppos);
70602 }
70603
70604 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70605 + void __user *buffer, size_t *lenp, loff_t *ppos)
70606 +{
70607 + if (write && !capable(CAP_SYS_MODULE))
70608 + return -EPERM;
70609 +
70610 + return _proc_do_string(table->data, table->maxlen, write,
70611 + buffer, lenp, ppos);
70612 +}
70613 +
70614 static size_t proc_skip_spaces(char **buf)
70615 {
70616 size_t ret;
70617 @@ -2207,6 +2277,8 @@ static int proc_put_long(void __user **b
70618 len = strlen(tmp);
70619 if (len > *size)
70620 len = *size;
70621 + if (len > sizeof(tmp))
70622 + len = sizeof(tmp);
70623 if (copy_to_user(*buf, tmp, len))
70624 return -EFAULT;
70625 *size -= len;
70626 @@ -2523,8 +2595,11 @@ static int __do_proc_doulongvec_minmax(v
70627 *i = val;
70628 } else {
70629 val = convdiv * (*i) / convmul;
70630 - if (!first)
70631 + if (!first) {
70632 err = proc_put_char(&buffer, &left, '\t');
70633 + if (err)
70634 + break;
70635 + }
70636 err = proc_put_long(&buffer, &left, val, false);
70637 if (err)
70638 break;
70639 @@ -2919,6 +2994,12 @@ int proc_dostring(struct ctl_table *tabl
70640 return -ENOSYS;
70641 }
70642
70643 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70644 + void __user *buffer, size_t *lenp, loff_t *ppos)
70645 +{
70646 + return -ENOSYS;
70647 +}
70648 +
70649 int proc_dointvec(struct ctl_table *table, int write,
70650 void __user *buffer, size_t *lenp, loff_t *ppos)
70651 {
70652 @@ -2975,6 +3056,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70653 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70654 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70655 EXPORT_SYMBOL(proc_dostring);
70656 +EXPORT_SYMBOL(proc_dostring_modpriv);
70657 EXPORT_SYMBOL(proc_doulongvec_minmax);
70658 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70659 EXPORT_SYMBOL(register_sysctl_table);
70660 diff -urNp linux-2.6.39.1/kernel/sysctl_check.c linux-2.6.39.1/kernel/sysctl_check.c
70661 --- linux-2.6.39.1/kernel/sysctl_check.c 2011-05-19 00:06:34.000000000 -0400
70662 +++ linux-2.6.39.1/kernel/sysctl_check.c 2011-05-22 19:41:42.000000000 -0400
70663 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
70664 set_fail(&fail, table, "Directory with extra2");
70665 } else {
70666 if ((table->proc_handler == proc_dostring) ||
70667 + (table->proc_handler == proc_dostring_modpriv) ||
70668 (table->proc_handler == proc_dointvec) ||
70669 (table->proc_handler == proc_dointvec_minmax) ||
70670 (table->proc_handler == proc_dointvec_jiffies) ||
70671 diff -urNp linux-2.6.39.1/kernel/taskstats.c linux-2.6.39.1/kernel/taskstats.c
70672 --- linux-2.6.39.1/kernel/taskstats.c 2011-05-19 00:06:34.000000000 -0400
70673 +++ linux-2.6.39.1/kernel/taskstats.c 2011-05-22 19:41:42.000000000 -0400
70674 @@ -27,9 +27,12 @@
70675 #include <linux/cgroup.h>
70676 #include <linux/fs.h>
70677 #include <linux/file.h>
70678 +#include <linux/grsecurity.h>
70679 #include <net/genetlink.h>
70680 #include <asm/atomic.h>
70681
70682 +extern int gr_is_taskstats_denied(int pid);
70683 +
70684 /*
70685 * Maximum length of a cpumask that can be specified in
70686 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70687 @@ -549,6 +552,9 @@ err:
70688
70689 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70690 {
70691 + if (gr_is_taskstats_denied(current->pid))
70692 + return -EACCES;
70693 +
70694 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70695 return cmd_attr_register_cpumask(info);
70696 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70697 diff -urNp linux-2.6.39.1/kernel/time/posix-clock.c linux-2.6.39.1/kernel/time/posix-clock.c
70698 --- linux-2.6.39.1/kernel/time/posix-clock.c 2011-05-19 00:06:34.000000000 -0400
70699 +++ linux-2.6.39.1/kernel/time/posix-clock.c 2011-05-22 19:36:33.000000000 -0400
70700 @@ -433,7 +433,7 @@ static int pc_timer_settime(struct k_iti
70701 return err;
70702 }
70703
70704 -struct k_clock clock_posix_dynamic = {
70705 +const struct k_clock clock_posix_dynamic = {
70706 .clock_getres = pc_clock_getres,
70707 .clock_set = pc_clock_settime,
70708 .clock_get = pc_clock_gettime,
70709 diff -urNp linux-2.6.39.1/kernel/time/tick-broadcast.c linux-2.6.39.1/kernel/time/tick-broadcast.c
70710 --- linux-2.6.39.1/kernel/time/tick-broadcast.c 2011-05-19 00:06:34.000000000 -0400
70711 +++ linux-2.6.39.1/kernel/time/tick-broadcast.c 2011-05-22 19:36:33.000000000 -0400
70712 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
70713 * then clear the broadcast bit.
70714 */
70715 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70716 - int cpu = smp_processor_id();
70717 + cpu = smp_processor_id();
70718
70719 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70720 tick_broadcast_clear_oneshot(cpu);
70721 diff -urNp linux-2.6.39.1/kernel/time/timekeeping.c linux-2.6.39.1/kernel/time/timekeeping.c
70722 --- linux-2.6.39.1/kernel/time/timekeeping.c 2011-05-19 00:06:34.000000000 -0400
70723 +++ linux-2.6.39.1/kernel/time/timekeeping.c 2011-05-22 20:40:50.000000000 -0400
70724 @@ -14,6 +14,7 @@
70725 #include <linux/init.h>
70726 #include <linux/mm.h>
70727 #include <linux/sched.h>
70728 +#include <linux/grsecurity.h>
70729 #include <linux/syscore_ops.h>
70730 #include <linux/clocksource.h>
70731 #include <linux/jiffies.h>
70732 @@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
70733 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70734 return -EINVAL;
70735
70736 + gr_log_timechange();
70737 +
70738 write_seqlock_irqsave(&xtime_lock, flags);
70739
70740 timekeeping_forward_now();
70741 diff -urNp linux-2.6.39.1/kernel/time/timer_list.c linux-2.6.39.1/kernel/time/timer_list.c
70742 --- linux-2.6.39.1/kernel/time/timer_list.c 2011-05-19 00:06:34.000000000 -0400
70743 +++ linux-2.6.39.1/kernel/time/timer_list.c 2011-05-22 19:41:42.000000000 -0400
70744 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
70745
70746 static void print_name_offset(struct seq_file *m, void *sym)
70747 {
70748 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70749 + SEQ_printf(m, "<%p>", NULL);
70750 +#else
70751 char symname[KSYM_NAME_LEN];
70752
70753 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70754 SEQ_printf(m, "<%pK>", sym);
70755 else
70756 SEQ_printf(m, "%s", symname);
70757 +#endif
70758 }
70759
70760 static void
70761 @@ -112,7 +116,11 @@ next_one:
70762 static void
70763 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70764 {
70765 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70766 + SEQ_printf(m, " .base: %p\n", NULL);
70767 +#else
70768 SEQ_printf(m, " .base: %pK\n", base);
70769 +#endif
70770 SEQ_printf(m, " .index: %d\n",
70771 base->index);
70772 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70773 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
70774 {
70775 struct proc_dir_entry *pe;
70776
70777 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70778 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70779 +#else
70780 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70781 +#endif
70782 if (!pe)
70783 return -ENOMEM;
70784 return 0;
70785 diff -urNp linux-2.6.39.1/kernel/time/timer_stats.c linux-2.6.39.1/kernel/time/timer_stats.c
70786 --- linux-2.6.39.1/kernel/time/timer_stats.c 2011-05-19 00:06:34.000000000 -0400
70787 +++ linux-2.6.39.1/kernel/time/timer_stats.c 2011-05-22 19:41:42.000000000 -0400
70788 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70789 static unsigned long nr_entries;
70790 static struct entry entries[MAX_ENTRIES];
70791
70792 -static atomic_t overflow_count;
70793 +static atomic_unchecked_t overflow_count;
70794
70795 /*
70796 * The entries are in a hash-table, for fast lookup:
70797 @@ -140,7 +140,7 @@ static void reset_entries(void)
70798 nr_entries = 0;
70799 memset(entries, 0, sizeof(entries));
70800 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70801 - atomic_set(&overflow_count, 0);
70802 + atomic_set_unchecked(&overflow_count, 0);
70803 }
70804
70805 static struct entry *alloc_entry(void)
70806 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
70807 if (likely(entry))
70808 entry->count++;
70809 else
70810 - atomic_inc(&overflow_count);
70811 + atomic_inc_unchecked(&overflow_count);
70812
70813 out_unlock:
70814 raw_spin_unlock_irqrestore(lock, flags);
70815 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
70816
70817 static void print_name_offset(struct seq_file *m, unsigned long addr)
70818 {
70819 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70820 + seq_printf(m, "<%p>", NULL);
70821 +#else
70822 char symname[KSYM_NAME_LEN];
70823
70824 if (lookup_symbol_name(addr, symname) < 0)
70825 seq_printf(m, "<%p>", (void *)addr);
70826 else
70827 seq_printf(m, "%s", symname);
70828 +#endif
70829 }
70830
70831 static int tstats_show(struct seq_file *m, void *v)
70832 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
70833
70834 seq_puts(m, "Timer Stats Version: v0.2\n");
70835 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70836 - if (atomic_read(&overflow_count))
70837 + if (atomic_read_unchecked(&overflow_count))
70838 seq_printf(m, "Overflow: %d entries\n",
70839 - atomic_read(&overflow_count));
70840 + atomic_read_unchecked(&overflow_count));
70841
70842 for (i = 0; i < nr_entries; i++) {
70843 entry = entries + i;
70844 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
70845 {
70846 struct proc_dir_entry *pe;
70847
70848 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70849 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70850 +#else
70851 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70852 +#endif
70853 if (!pe)
70854 return -ENOMEM;
70855 return 0;
70856 diff -urNp linux-2.6.39.1/kernel/time.c linux-2.6.39.1/kernel/time.c
70857 --- linux-2.6.39.1/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
70858 +++ linux-2.6.39.1/kernel/time.c 2011-05-22 19:41:42.000000000 -0400
70859 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
70860 return error;
70861
70862 if (tz) {
70863 + /* we log in do_settimeofday called below, so don't log twice
70864 + */
70865 + if (!tv)
70866 + gr_log_timechange();
70867 +
70868 /* SMP safe, global irq locking makes it work. */
70869 sys_tz = *tz;
70870 update_vsyscall_tz();
70871 diff -urNp linux-2.6.39.1/kernel/timer.c linux-2.6.39.1/kernel/timer.c
70872 --- linux-2.6.39.1/kernel/timer.c 2011-05-19 00:06:34.000000000 -0400
70873 +++ linux-2.6.39.1/kernel/timer.c 2011-05-22 19:36:33.000000000 -0400
70874 @@ -1305,7 +1305,7 @@ void update_process_times(int user_tick)
70875 /*
70876 * This function runs timers and the timer-tq in bottom half context.
70877 */
70878 -static void run_timer_softirq(struct softirq_action *h)
70879 +static void run_timer_softirq(void)
70880 {
70881 struct tvec_base *base = __this_cpu_read(tvec_bases);
70882
70883 diff -urNp linux-2.6.39.1/kernel/trace/blktrace.c linux-2.6.39.1/kernel/trace/blktrace.c
70884 --- linux-2.6.39.1/kernel/trace/blktrace.c 2011-05-19 00:06:34.000000000 -0400
70885 +++ linux-2.6.39.1/kernel/trace/blktrace.c 2011-05-22 19:36:33.000000000 -0400
70886 @@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
70887 struct blk_trace *bt = filp->private_data;
70888 char buf[16];
70889
70890 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70891 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70892
70893 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70894 }
70895 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
70896 return 1;
70897
70898 bt = buf->chan->private_data;
70899 - atomic_inc(&bt->dropped);
70900 + atomic_inc_unchecked(&bt->dropped);
70901 return 0;
70902 }
70903
70904 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
70905
70906 bt->dir = dir;
70907 bt->dev = dev;
70908 - atomic_set(&bt->dropped, 0);
70909 + atomic_set_unchecked(&bt->dropped, 0);
70910
70911 ret = -EIO;
70912 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70913 diff -urNp linux-2.6.39.1/kernel/trace/ftrace.c linux-2.6.39.1/kernel/trace/ftrace.c
70914 --- linux-2.6.39.1/kernel/trace/ftrace.c 2011-06-03 00:04:14.000000000 -0400
70915 +++ linux-2.6.39.1/kernel/trace/ftrace.c 2011-06-03 00:32:08.000000000 -0400
70916 @@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
70917
70918 ip = rec->ip;
70919
70920 + ret = ftrace_arch_code_modify_prepare();
70921 + FTRACE_WARN_ON(ret);
70922 + if (ret)
70923 + return 0;
70924 +
70925 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70926 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70927 if (ret) {
70928 ftrace_bug(ret, ip);
70929 rec->flags |= FTRACE_FL_FAILED;
70930 - return 0;
70931 }
70932 - return 1;
70933 + return ret ? 0 : 1;
70934 }
70935
70936 /*
70937 @@ -2011,7 +2016,7 @@ static void ftrace_free_entry_rcu(struct
70938
70939 int
70940 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70941 - void *data)
70942 + void *data)
70943 {
70944 struct ftrace_func_probe *entry;
70945 struct ftrace_page *pg;
70946 @@ -2083,7 +2088,7 @@ enum {
70947 };
70948
70949 static void
70950 -__unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70951 +__unregister_ftrace_function_probe(char *glob, const struct ftrace_probe_ops *ops,
70952 void *data, int flags)
70953 {
70954 struct ftrace_func_probe *entry;
70955 @@ -2144,7 +2149,7 @@ unregister_ftrace_function_probe(char *g
70956 }
70957
70958 void
70959 -unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
70960 +unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops)
70961 {
70962 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
70963 }
70964 diff -urNp linux-2.6.39.1/kernel/trace/trace.c linux-2.6.39.1/kernel/trace/trace.c
70965 --- linux-2.6.39.1/kernel/trace/trace.c 2011-05-19 00:06:34.000000000 -0400
70966 +++ linux-2.6.39.1/kernel/trace/trace.c 2011-05-22 19:36:33.000000000 -0400
70967 @@ -3330,6 +3330,8 @@ static ssize_t tracing_splice_read_pipe(
70968 size_t rem;
70969 unsigned int i;
70970
70971 + pax_track_stack();
70972 +
70973 if (splice_grow_spd(pipe, &spd))
70974 return -ENOMEM;
70975
70976 @@ -3813,6 +3815,8 @@ tracing_buffers_splice_read(struct file
70977 int entries, size, i;
70978 size_t ret;
70979
70980 + pax_track_stack();
70981 +
70982 if (splice_grow_spd(pipe, &spd))
70983 return -ENOMEM;
70984
70985 @@ -3981,10 +3985,9 @@ static const struct file_operations trac
70986 };
70987 #endif
70988
70989 -static struct dentry *d_tracer;
70990 -
70991 struct dentry *tracing_init_dentry(void)
70992 {
70993 + static struct dentry *d_tracer;
70994 static int once;
70995
70996 if (d_tracer)
70997 @@ -4004,10 +4007,9 @@ struct dentry *tracing_init_dentry(void)
70998 return d_tracer;
70999 }
71000
71001 -static struct dentry *d_percpu;
71002 -
71003 struct dentry *tracing_dentry_percpu(void)
71004 {
71005 + static struct dentry *d_percpu;
71006 static int once;
71007 struct dentry *d_tracer;
71008
71009 diff -urNp linux-2.6.39.1/kernel/trace/trace_events.c linux-2.6.39.1/kernel/trace/trace_events.c
71010 --- linux-2.6.39.1/kernel/trace/trace_events.c 2011-05-19 00:06:34.000000000 -0400
71011 +++ linux-2.6.39.1/kernel/trace/trace_events.c 2011-05-22 19:36:33.000000000 -0400
71012 @@ -1241,10 +1241,10 @@ static LIST_HEAD(ftrace_module_file_list
71013 struct ftrace_module_file_ops {
71014 struct list_head list;
71015 struct module *mod;
71016 - struct file_operations id;
71017 - struct file_operations enable;
71018 - struct file_operations format;
71019 - struct file_operations filter;
71020 + struct file_operations id; /* cannot be const, see trace_create_file_ops() */
71021 + struct file_operations enable; /* cannot be const, see trace_create_file_ops() */
71022 + struct file_operations format; /* cannot be const, see trace_create_file_ops() */
71023 + struct file_operations filter; /* cannot be const, see trace_create_file_ops() */
71024 };
71025
71026 static struct ftrace_module_file_ops *
71027 diff -urNp linux-2.6.39.1/kernel/trace/trace_functions.c linux-2.6.39.1/kernel/trace/trace_functions.c
71028 --- linux-2.6.39.1/kernel/trace/trace_functions.c 2011-05-19 00:06:34.000000000 -0400
71029 +++ linux-2.6.39.1/kernel/trace/trace_functions.c 2011-05-22 19:36:33.000000000 -0400
71030 @@ -308,7 +308,7 @@ ftrace_trace_onoff_print(struct seq_file
71031 static int
71032 ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param)
71033 {
71034 - struct ftrace_probe_ops *ops;
71035 + const struct ftrace_probe_ops *ops;
71036
71037 /* we register both traceon and traceoff to this callback */
71038 if (strcmp(cmd, "traceon") == 0)
71039 diff -urNp linux-2.6.39.1/kernel/trace/trace_mmiotrace.c linux-2.6.39.1/kernel/trace/trace_mmiotrace.c
71040 --- linux-2.6.39.1/kernel/trace/trace_mmiotrace.c 2011-05-19 00:06:34.000000000 -0400
71041 +++ linux-2.6.39.1/kernel/trace/trace_mmiotrace.c 2011-05-22 19:36:33.000000000 -0400
71042 @@ -24,7 +24,7 @@ struct header_iter {
71043 static struct trace_array *mmio_trace_array;
71044 static bool overrun_detected;
71045 static unsigned long prev_overruns;
71046 -static atomic_t dropped_count;
71047 +static atomic_unchecked_t dropped_count;
71048
71049 static void mmio_reset_data(struct trace_array *tr)
71050 {
71051 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
71052
71053 static unsigned long count_overruns(struct trace_iterator *iter)
71054 {
71055 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71056 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71057 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71058
71059 if (over > prev_overruns)
71060 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
71061 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71062 sizeof(*entry), 0, pc);
71063 if (!event) {
71064 - atomic_inc(&dropped_count);
71065 + atomic_inc_unchecked(&dropped_count);
71066 return;
71067 }
71068 entry = ring_buffer_event_data(event);
71069 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
71070 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71071 sizeof(*entry), 0, pc);
71072 if (!event) {
71073 - atomic_inc(&dropped_count);
71074 + atomic_inc_unchecked(&dropped_count);
71075 return;
71076 }
71077 entry = ring_buffer_event_data(event);
71078 diff -urNp linux-2.6.39.1/kernel/trace/trace_output.c linux-2.6.39.1/kernel/trace/trace_output.c
71079 --- linux-2.6.39.1/kernel/trace/trace_output.c 2011-05-19 00:06:34.000000000 -0400
71080 +++ linux-2.6.39.1/kernel/trace/trace_output.c 2011-05-22 19:36:33.000000000 -0400
71081 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
71082
71083 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71084 if (!IS_ERR(p)) {
71085 - p = mangle_path(s->buffer + s->len, p, "\n");
71086 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71087 if (p) {
71088 s->len = p - s->buffer;
71089 return 1;
71090 diff -urNp linux-2.6.39.1/kernel/trace/trace_stack.c linux-2.6.39.1/kernel/trace/trace_stack.c
71091 --- linux-2.6.39.1/kernel/trace/trace_stack.c 2011-05-19 00:06:34.000000000 -0400
71092 +++ linux-2.6.39.1/kernel/trace/trace_stack.c 2011-05-22 19:36:33.000000000 -0400
71093 @@ -50,7 +50,7 @@ static inline void check_stack(void)
71094 return;
71095
71096 /* we do not handle interrupt stacks yet */
71097 - if (!object_is_on_stack(&this_size))
71098 + if (!object_starts_on_stack(&this_size))
71099 return;
71100
71101 local_irq_save(flags);
71102 diff -urNp linux-2.6.39.1/kernel/trace/trace_workqueue.c linux-2.6.39.1/kernel/trace/trace_workqueue.c
71103 --- linux-2.6.39.1/kernel/trace/trace_workqueue.c 2011-05-19 00:06:34.000000000 -0400
71104 +++ linux-2.6.39.1/kernel/trace/trace_workqueue.c 2011-05-22 19:36:33.000000000 -0400
71105 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
71106 int cpu;
71107 pid_t pid;
71108 /* Can be inserted from interrupt or user context, need to be atomic */
71109 - atomic_t inserted;
71110 + atomic_unchecked_t inserted;
71111 /*
71112 * Don't need to be atomic, works are serialized in a single workqueue thread
71113 * on a single CPU.
71114 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
71115 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
71116 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
71117 if (node->pid == wq_thread->pid) {
71118 - atomic_inc(&node->inserted);
71119 + atomic_inc_unchecked(&node->inserted);
71120 goto found;
71121 }
71122 }
71123 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
71124 tsk = get_pid_task(pid, PIDTYPE_PID);
71125 if (tsk) {
71126 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
71127 - atomic_read(&cws->inserted), cws->executed,
71128 + atomic_read_unchecked(&cws->inserted), cws->executed,
71129 tsk->comm);
71130 put_task_struct(tsk);
71131 }
71132 diff -urNp linux-2.6.39.1/lib/bug.c linux-2.6.39.1/lib/bug.c
71133 --- linux-2.6.39.1/lib/bug.c 2011-05-19 00:06:34.000000000 -0400
71134 +++ linux-2.6.39.1/lib/bug.c 2011-05-22 19:36:33.000000000 -0400
71135 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
71136 return BUG_TRAP_TYPE_NONE;
71137
71138 bug = find_bug(bugaddr);
71139 + if (!bug)
71140 + return BUG_TRAP_TYPE_NONE;
71141
71142 file = NULL;
71143 line = 0;
71144 diff -urNp linux-2.6.39.1/lib/debugobjects.c linux-2.6.39.1/lib/debugobjects.c
71145 --- linux-2.6.39.1/lib/debugobjects.c 2011-05-19 00:06:34.000000000 -0400
71146 +++ linux-2.6.39.1/lib/debugobjects.c 2011-05-22 19:36:33.000000000 -0400
71147 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
71148 if (limit > 4)
71149 return;
71150
71151 - is_on_stack = object_is_on_stack(addr);
71152 + is_on_stack = object_starts_on_stack(addr);
71153 if (is_on_stack == onstack)
71154 return;
71155
71156 diff -urNp linux-2.6.39.1/lib/dma-debug.c linux-2.6.39.1/lib/dma-debug.c
71157 --- linux-2.6.39.1/lib/dma-debug.c 2011-05-19 00:06:34.000000000 -0400
71158 +++ linux-2.6.39.1/lib/dma-debug.c 2011-05-22 19:36:33.000000000 -0400
71159 @@ -862,7 +862,7 @@ out:
71160
71161 static void check_for_stack(struct device *dev, void *addr)
71162 {
71163 - if (object_is_on_stack(addr))
71164 + if (object_starts_on_stack(addr))
71165 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71166 "stack [addr=%p]\n", addr);
71167 }
71168 diff -urNp linux-2.6.39.1/lib/inflate.c linux-2.6.39.1/lib/inflate.c
71169 --- linux-2.6.39.1/lib/inflate.c 2011-05-19 00:06:34.000000000 -0400
71170 +++ linux-2.6.39.1/lib/inflate.c 2011-05-22 19:36:33.000000000 -0400
71171 @@ -269,7 +269,7 @@ static void free(void *where)
71172 malloc_ptr = free_mem_ptr;
71173 }
71174 #else
71175 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71176 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71177 #define free(a) kfree(a)
71178 #endif
71179
71180 diff -urNp linux-2.6.39.1/lib/Kconfig.debug linux-2.6.39.1/lib/Kconfig.debug
71181 --- linux-2.6.39.1/lib/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
71182 +++ linux-2.6.39.1/lib/Kconfig.debug 2011-05-22 19:41:42.000000000 -0400
71183 @@ -1078,6 +1078,7 @@ config LATENCYTOP
71184 depends on DEBUG_KERNEL
71185 depends on STACKTRACE_SUPPORT
71186 depends on PROC_FS
71187 + depends on !GRKERNSEC_HIDESYM
71188 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
71189 select KALLSYMS
71190 select KALLSYMS_ALL
71191 diff -urNp linux-2.6.39.1/lib/kref.c linux-2.6.39.1/lib/kref.c
71192 --- linux-2.6.39.1/lib/kref.c 2011-05-19 00:06:34.000000000 -0400
71193 +++ linux-2.6.39.1/lib/kref.c 2011-05-22 19:36:33.000000000 -0400
71194 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
71195 */
71196 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
71197 {
71198 - WARN_ON(release == NULL);
71199 + BUG_ON(release == NULL);
71200 WARN_ON(release == (void (*)(struct kref *))kfree);
71201
71202 if (atomic_dec_and_test(&kref->refcount)) {
71203 diff -urNp linux-2.6.39.1/lib/radix-tree.c linux-2.6.39.1/lib/radix-tree.c
71204 --- linux-2.6.39.1/lib/radix-tree.c 2011-05-19 00:06:34.000000000 -0400
71205 +++ linux-2.6.39.1/lib/radix-tree.c 2011-05-22 19:36:33.000000000 -0400
71206 @@ -80,7 +80,7 @@ struct radix_tree_preload {
71207 int nr;
71208 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71209 };
71210 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71211 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71212
71213 static inline void *ptr_to_indirect(void *ptr)
71214 {
71215 diff -urNp linux-2.6.39.1/lib/vsprintf.c linux-2.6.39.1/lib/vsprintf.c
71216 --- linux-2.6.39.1/lib/vsprintf.c 2011-05-19 00:06:34.000000000 -0400
71217 +++ linux-2.6.39.1/lib/vsprintf.c 2011-05-22 20:54:59.000000000 -0400
71218 @@ -16,6 +16,9 @@
71219 * - scnprintf and vscnprintf
71220 */
71221
71222 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71223 +#define __INCLUDED_BY_HIDESYM 1
71224 +#endif
71225 #include <stdarg.h>
71226 #include <linux/module.h>
71227 #include <linux/types.h>
71228 @@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
71229 char sym[KSYM_SYMBOL_LEN];
71230 if (ext == 'B')
71231 sprint_backtrace(sym, value);
71232 - else if (ext != 'f' && ext != 's')
71233 + else if (ext != 'f' && ext != 's' && ext != 'a')
71234 sprint_symbol(sym, value);
71235 else
71236 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71237 @@ -797,7 +800,11 @@ char *uuid_string(char *buf, char *end,
71238 return string(buf, end, uuid, spec);
71239 }
71240
71241 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71242 +int kptr_restrict __read_mostly = 2;
71243 +#else
71244 int kptr_restrict __read_mostly;
71245 +#endif
71246
71247 /*
71248 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71249 @@ -811,6 +818,8 @@ int kptr_restrict __read_mostly;
71250 * - 'S' For symbolic direct pointers with offset
71251 * - 's' For symbolic direct pointers without offset
71252 * - 'B' For backtraced symbolic direct pointers with offset
71253 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71254 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71255 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71256 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71257 * - 'M' For a 6-byte MAC address, it prints the address in the
71258 @@ -855,12 +864,12 @@ char *pointer(const char *fmt, char *buf
71259 {
71260 if (!ptr && *fmt != 'K') {
71261 /*
71262 - * Print (null) with the same width as a pointer so it makes
71263 + * Print (nil) with the same width as a pointer so it makes
71264 * tabular output look nice.
71265 */
71266 if (spec.field_width == -1)
71267 spec.field_width = 2 * sizeof(void *);
71268 - return string(buf, end, "(null)", spec);
71269 + return string(buf, end, "(nil)", spec);
71270 }
71271
71272 switch (*fmt) {
71273 @@ -870,6 +879,13 @@ char *pointer(const char *fmt, char *buf
71274 /* Fallthrough */
71275 case 'S':
71276 case 's':
71277 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71278 + break;
71279 +#else
71280 + return symbol_string(buf, end, ptr, spec, *fmt);
71281 +#endif
71282 + case 'A':
71283 + case 'a':
71284 case 'B':
71285 return symbol_string(buf, end, ptr, spec, *fmt);
71286 case 'R':
71287 @@ -1632,11 +1648,11 @@ int bstr_printf(char *buf, size_t size,
71288 typeof(type) value; \
71289 if (sizeof(type) == 8) { \
71290 args = PTR_ALIGN(args, sizeof(u32)); \
71291 - *(u32 *)&value = *(u32 *)args; \
71292 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71293 + *(u32 *)&value = *(const u32 *)args; \
71294 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71295 } else { \
71296 args = PTR_ALIGN(args, sizeof(type)); \
71297 - value = *(typeof(type) *)args; \
71298 + value = *(const typeof(type) *)args; \
71299 } \
71300 args += sizeof(type); \
71301 value; \
71302 @@ -1699,7 +1715,7 @@ int bstr_printf(char *buf, size_t size,
71303 case FORMAT_TYPE_STR: {
71304 const char *str_arg = args;
71305 args += strlen(str_arg) + 1;
71306 - str = string(str, end, (char *)str_arg, spec);
71307 + str = string(str, end, str_arg, spec);
71308 break;
71309 }
71310
71311 diff -urNp linux-2.6.39.1/localversion-grsec linux-2.6.39.1/localversion-grsec
71312 --- linux-2.6.39.1/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
71313 +++ linux-2.6.39.1/localversion-grsec 2011-05-22 19:41:42.000000000 -0400
71314 @@ -0,0 +1 @@
71315 +-grsec
71316 diff -urNp linux-2.6.39.1/Makefile linux-2.6.39.1/Makefile
71317 --- linux-2.6.39.1/Makefile 2011-06-03 00:04:13.000000000 -0400
71318 +++ linux-2.6.39.1/Makefile 2011-06-03 01:27:33.000000000 -0400
71319 @@ -237,8 +237,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
71320
71321 HOSTCC = gcc
71322 HOSTCXX = g++
71323 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
71324 -HOSTCXXFLAGS = -O2
71325 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
71326 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
71327 +HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
71328
71329 # Decide whether to build built-in, modular, or both.
71330 # Normally, just do built-in.
71331 @@ -356,10 +357,12 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
71332 KBUILD_CPPFLAGS := -D__KERNEL__
71333
71334 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
71335 + -W -Wno-unused-parameter -Wno-missing-field-initializers \
71336 -fno-strict-aliasing -fno-common \
71337 -Werror-implicit-function-declaration \
71338 -Wno-format-security \
71339 -fno-delete-null-pointer-checks
71340 +KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
71341 KBUILD_AFLAGS_KERNEL :=
71342 KBUILD_CFLAGS_KERNEL :=
71343 KBUILD_AFLAGS := -D__ASSEMBLY__
71344 @@ -685,7 +688,7 @@ export mod_strip_cmd
71345
71346
71347 ifeq ($(KBUILD_EXTMOD),)
71348 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
71349 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
71350
71351 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
71352 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
71353 @@ -931,7 +934,19 @@ include/config/kernel.release: include/c
71354 # version.h and scripts_basic is processed / created.
71355
71356 # Listed in dependency order
71357 -PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
71358 +PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 pax-plugin
71359 +
71360 +ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71361 +KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0405, -fplugin=$(obj)/tools/gcc/pax_plugin.so -fplugin-arg-pax_plugin-track-lowest-sp=100)
71362 +endif
71363 +pax-plugin:
71364 +ifneq (,$(findstring pax_plugin, $(KBUILD_CFLAGS)))
71365 + $(Q)$(MAKE) $(build)=tools/gcc
71366 +else
71367 +ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71368 + $(Q)echo "warning, your gcc does not support plugins, PAX_MEMORY_STACKLEAK will be less secure"
71369 +endif
71370 +endif
71371
71372 # prepare3 is used to check if we are building in a separate output directory,
71373 # and if so do:
71374 @@ -947,7 +962,7 @@ ifneq ($(KBUILD_SRC),)
71375 endif
71376
71377 # prepare2 creates a makefile if using a separate output directory
71378 -prepare2: prepare3 outputmakefile
71379 +prepare2: prepare3 outputmakefile pax-plugin
71380
71381 prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
71382 include/config/auto.conf
71383 diff -urNp linux-2.6.39.1/mm/filemap.c linux-2.6.39.1/mm/filemap.c
71384 --- linux-2.6.39.1/mm/filemap.c 2011-05-19 00:06:34.000000000 -0400
71385 +++ linux-2.6.39.1/mm/filemap.c 2011-05-22 19:41:42.000000000 -0400
71386 @@ -1724,7 +1724,7 @@ int generic_file_mmap(struct file * file
71387 struct address_space *mapping = file->f_mapping;
71388
71389 if (!mapping->a_ops->readpage)
71390 - return -ENOEXEC;
71391 + return -ENODEV;
71392 file_accessed(file);
71393 vma->vm_ops = &generic_file_vm_ops;
71394 vma->vm_flags |= VM_CAN_NONLINEAR;
71395 @@ -2120,6 +2120,7 @@ inline int generic_write_checks(struct f
71396 *pos = i_size_read(inode);
71397
71398 if (limit != RLIM_INFINITY) {
71399 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71400 if (*pos >= limit) {
71401 send_sig(SIGXFSZ, current, 0);
71402 return -EFBIG;
71403 diff -urNp linux-2.6.39.1/mm/fremap.c linux-2.6.39.1/mm/fremap.c
71404 --- linux-2.6.39.1/mm/fremap.c 2011-05-19 00:06:34.000000000 -0400
71405 +++ linux-2.6.39.1/mm/fremap.c 2011-05-22 19:36:33.000000000 -0400
71406 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71407 retry:
71408 vma = find_vma(mm, start);
71409
71410 +#ifdef CONFIG_PAX_SEGMEXEC
71411 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71412 + goto out;
71413 +#endif
71414 +
71415 /*
71416 * Make sure the vma is shared, that it supports prefaulting,
71417 * and that the remapped range is valid and fully within
71418 @@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71419 /*
71420 * drop PG_Mlocked flag for over-mapped range
71421 */
71422 - unsigned int saved_flags = vma->vm_flags;
71423 + unsigned long saved_flags = vma->vm_flags;
71424 munlock_vma_pages_range(vma, start, start + size);
71425 vma->vm_flags = saved_flags;
71426 }
71427 diff -urNp linux-2.6.39.1/mm/highmem.c linux-2.6.39.1/mm/highmem.c
71428 --- linux-2.6.39.1/mm/highmem.c 2011-05-19 00:06:34.000000000 -0400
71429 +++ linux-2.6.39.1/mm/highmem.c 2011-05-22 19:36:33.000000000 -0400
71430 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71431 * So no dangers, even with speculative execution.
71432 */
71433 page = pte_page(pkmap_page_table[i]);
71434 + pax_open_kernel();
71435 pte_clear(&init_mm, (unsigned long)page_address(page),
71436 &pkmap_page_table[i]);
71437 -
71438 + pax_close_kernel();
71439 set_page_address(page, NULL);
71440 need_flush = 1;
71441 }
71442 @@ -186,9 +187,11 @@ start:
71443 }
71444 }
71445 vaddr = PKMAP_ADDR(last_pkmap_nr);
71446 +
71447 + pax_open_kernel();
71448 set_pte_at(&init_mm, vaddr,
71449 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71450 -
71451 + pax_close_kernel();
71452 pkmap_count[last_pkmap_nr] = 1;
71453 set_page_address(page, (void *)vaddr);
71454
71455 diff -urNp linux-2.6.39.1/mm/huge_memory.c linux-2.6.39.1/mm/huge_memory.c
71456 --- linux-2.6.39.1/mm/huge_memory.c 2011-05-19 00:06:34.000000000 -0400
71457 +++ linux-2.6.39.1/mm/huge_memory.c 2011-05-22 19:36:33.000000000 -0400
71458 @@ -702,7 +702,7 @@ out:
71459 * run pte_offset_map on the pmd, if an huge pmd could
71460 * materialize from under us from a different thread.
71461 */
71462 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71463 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71464 return VM_FAULT_OOM;
71465 /* if an huge pmd materialized from under us just retry later */
71466 if (unlikely(pmd_trans_huge(*pmd)))
71467 diff -urNp linux-2.6.39.1/mm/hugetlb.c linux-2.6.39.1/mm/hugetlb.c
71468 --- linux-2.6.39.1/mm/hugetlb.c 2011-05-19 00:06:34.000000000 -0400
71469 +++ linux-2.6.39.1/mm/hugetlb.c 2011-05-22 19:36:33.000000000 -0400
71470 @@ -2331,6 +2331,27 @@ static int unmap_ref_private(struct mm_s
71471 return 1;
71472 }
71473
71474 +#ifdef CONFIG_PAX_SEGMEXEC
71475 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71476 +{
71477 + struct mm_struct *mm = vma->vm_mm;
71478 + struct vm_area_struct *vma_m;
71479 + unsigned long address_m;
71480 + pte_t *ptep_m;
71481 +
71482 + vma_m = pax_find_mirror_vma(vma);
71483 + if (!vma_m)
71484 + return;
71485 +
71486 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71487 + address_m = address + SEGMEXEC_TASK_SIZE;
71488 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71489 + get_page(page_m);
71490 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71491 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71492 +}
71493 +#endif
71494 +
71495 /*
71496 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71497 */
71498 @@ -2432,6 +2453,11 @@ retry_avoidcopy:
71499 make_huge_pte(vma, new_page, 1));
71500 page_remove_rmap(old_page);
71501 hugepage_add_new_anon_rmap(new_page, vma, address);
71502 +
71503 +#ifdef CONFIG_PAX_SEGMEXEC
71504 + pax_mirror_huge_pte(vma, address, new_page);
71505 +#endif
71506 +
71507 /* Make the old page be freed below */
71508 new_page = old_page;
71509 mmu_notifier_invalidate_range_end(mm,
71510 @@ -2583,6 +2609,10 @@ retry:
71511 && (vma->vm_flags & VM_SHARED)));
71512 set_huge_pte_at(mm, address, ptep, new_pte);
71513
71514 +#ifdef CONFIG_PAX_SEGMEXEC
71515 + pax_mirror_huge_pte(vma, address, page);
71516 +#endif
71517 +
71518 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71519 /* Optimization, do the COW without a second fault */
71520 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71521 @@ -2612,6 +2642,10 @@ int hugetlb_fault(struct mm_struct *mm,
71522 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71523 struct hstate *h = hstate_vma(vma);
71524
71525 +#ifdef CONFIG_PAX_SEGMEXEC
71526 + struct vm_area_struct *vma_m;
71527 +#endif
71528 +
71529 ptep = huge_pte_offset(mm, address);
71530 if (ptep) {
71531 entry = huge_ptep_get(ptep);
71532 @@ -2623,6 +2657,26 @@ int hugetlb_fault(struct mm_struct *mm,
71533 VM_FAULT_SET_HINDEX(h - hstates);
71534 }
71535
71536 +#ifdef CONFIG_PAX_SEGMEXEC
71537 + vma_m = pax_find_mirror_vma(vma);
71538 + if (vma_m) {
71539 + unsigned long address_m;
71540 +
71541 + if (vma->vm_start > vma_m->vm_start) {
71542 + address_m = address;
71543 + address -= SEGMEXEC_TASK_SIZE;
71544 + vma = vma_m;
71545 + h = hstate_vma(vma);
71546 + } else
71547 + address_m = address + SEGMEXEC_TASK_SIZE;
71548 +
71549 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71550 + return VM_FAULT_OOM;
71551 + address_m &= HPAGE_MASK;
71552 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71553 + }
71554 +#endif
71555 +
71556 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71557 if (!ptep)
71558 return VM_FAULT_OOM;
71559 diff -urNp linux-2.6.39.1/mm/Kconfig linux-2.6.39.1/mm/Kconfig
71560 --- linux-2.6.39.1/mm/Kconfig 2011-05-19 00:06:34.000000000 -0400
71561 +++ linux-2.6.39.1/mm/Kconfig 2011-05-22 19:41:42.000000000 -0400
71562 @@ -240,7 +240,7 @@ config KSM
71563 config DEFAULT_MMAP_MIN_ADDR
71564 int "Low address space to protect from user allocation"
71565 depends on MMU
71566 - default 4096
71567 + default 65536
71568 help
71569 This is the portion of low virtual memory which should be protected
71570 from userspace allocation. Keeping a user from writing to low pages
71571 diff -urNp linux-2.6.39.1/mm/kmemleak.c linux-2.6.39.1/mm/kmemleak.c
71572 --- linux-2.6.39.1/mm/kmemleak.c 2011-06-03 00:04:14.000000000 -0400
71573 +++ linux-2.6.39.1/mm/kmemleak.c 2011-06-03 00:32:08.000000000 -0400
71574 @@ -357,7 +357,7 @@ static void print_unreferenced(struct se
71575
71576 for (i = 0; i < object->trace_len; i++) {
71577 void *ptr = (void *)object->trace[i];
71578 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71579 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71580 }
71581 }
71582
71583 diff -urNp linux-2.6.39.1/mm/maccess.c linux-2.6.39.1/mm/maccess.c
71584 --- linux-2.6.39.1/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
71585 +++ linux-2.6.39.1/mm/maccess.c 2011-05-22 19:36:33.000000000 -0400
71586 @@ -15,10 +15,10 @@
71587 * happens, handle that and return -EFAULT.
71588 */
71589
71590 -long __weak probe_kernel_read(void *dst, void *src, size_t size)
71591 +long __weak probe_kernel_read(void *dst, const void *src, size_t size)
71592 __attribute__((alias("__probe_kernel_read")));
71593
71594 -long __probe_kernel_read(void *dst, void *src, size_t size)
71595 +long __probe_kernel_read(void *dst, const void *src, size_t size)
71596 {
71597 long ret;
71598 mm_segment_t old_fs = get_fs();
71599 @@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
71600 * Safely write to address @dst from the buffer at @src. If a kernel fault
71601 * happens, handle that and return -EFAULT.
71602 */
71603 -long __weak probe_kernel_write(void *dst, void *src, size_t size)
71604 +long __weak probe_kernel_write(void *dst, const void *src, size_t size)
71605 __attribute__((alias("__probe_kernel_write")));
71606
71607 -long __probe_kernel_write(void *dst, void *src, size_t size)
71608 +long __probe_kernel_write(void *dst, const void *src, size_t size)
71609 {
71610 long ret;
71611 mm_segment_t old_fs = get_fs();
71612 diff -urNp linux-2.6.39.1/mm/madvise.c linux-2.6.39.1/mm/madvise.c
71613 --- linux-2.6.39.1/mm/madvise.c 2011-05-19 00:06:34.000000000 -0400
71614 +++ linux-2.6.39.1/mm/madvise.c 2011-05-22 19:36:33.000000000 -0400
71615 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
71616 pgoff_t pgoff;
71617 unsigned long new_flags = vma->vm_flags;
71618
71619 +#ifdef CONFIG_PAX_SEGMEXEC
71620 + struct vm_area_struct *vma_m;
71621 +#endif
71622 +
71623 switch (behavior) {
71624 case MADV_NORMAL:
71625 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71626 @@ -110,6 +114,13 @@ success:
71627 /*
71628 * vm_flags is protected by the mmap_sem held in write mode.
71629 */
71630 +
71631 +#ifdef CONFIG_PAX_SEGMEXEC
71632 + vma_m = pax_find_mirror_vma(vma);
71633 + if (vma_m)
71634 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71635 +#endif
71636 +
71637 vma->vm_flags = new_flags;
71638
71639 out:
71640 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
71641 struct vm_area_struct ** prev,
71642 unsigned long start, unsigned long end)
71643 {
71644 +
71645 +#ifdef CONFIG_PAX_SEGMEXEC
71646 + struct vm_area_struct *vma_m;
71647 +#endif
71648 +
71649 *prev = vma;
71650 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71651 return -EINVAL;
71652 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
71653 zap_page_range(vma, start, end - start, &details);
71654 } else
71655 zap_page_range(vma, start, end - start, NULL);
71656 +
71657 +#ifdef CONFIG_PAX_SEGMEXEC
71658 + vma_m = pax_find_mirror_vma(vma);
71659 + if (vma_m) {
71660 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71661 + struct zap_details details = {
71662 + .nonlinear_vma = vma_m,
71663 + .last_index = ULONG_MAX,
71664 + };
71665 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71666 + } else
71667 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71668 + }
71669 +#endif
71670 +
71671 return 0;
71672 }
71673
71674 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
71675 if (end < start)
71676 goto out;
71677
71678 +#ifdef CONFIG_PAX_SEGMEXEC
71679 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71680 + if (end > SEGMEXEC_TASK_SIZE)
71681 + goto out;
71682 + } else
71683 +#endif
71684 +
71685 + if (end > TASK_SIZE)
71686 + goto out;
71687 +
71688 error = 0;
71689 if (end == start)
71690 goto out;
71691 diff -urNp linux-2.6.39.1/mm/memory.c linux-2.6.39.1/mm/memory.c
71692 --- linux-2.6.39.1/mm/memory.c 2011-05-19 00:06:34.000000000 -0400
71693 +++ linux-2.6.39.1/mm/memory.c 2011-05-22 19:36:33.000000000 -0400
71694 @@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
71695 return;
71696
71697 pmd = pmd_offset(pud, start);
71698 +
71699 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71700 pud_clear(pud);
71701 pmd_free_tlb(tlb, pmd, start);
71702 +#endif
71703 +
71704 }
71705
71706 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71707 @@ -291,9 +295,12 @@ static inline void free_pud_range(struct
71708 if (end - 1 > ceiling - 1)
71709 return;
71710
71711 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71712 pud = pud_offset(pgd, start);
71713 pgd_clear(pgd);
71714 pud_free_tlb(tlb, pud, start);
71715 +#endif
71716 +
71717 }
71718
71719 /*
71720 @@ -1410,12 +1417,6 @@ no_page_table:
71721 return page;
71722 }
71723
71724 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71725 -{
71726 - return stack_guard_page_start(vma, addr) ||
71727 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71728 -}
71729 -
71730 /**
71731 * __get_user_pages() - pin user pages in memory
71732 * @tsk: task_struct of target task
71733 @@ -1488,10 +1489,10 @@ int __get_user_pages(struct task_struct
71734 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71735 i = 0;
71736
71737 - do {
71738 + while (nr_pages) {
71739 struct vm_area_struct *vma;
71740
71741 - vma = find_extend_vma(mm, start);
71742 + vma = find_vma(mm, start);
71743 if (!vma && in_gate_area(mm, start)) {
71744 unsigned long pg = start & PAGE_MASK;
71745 pgd_t *pgd;
71746 @@ -1539,7 +1540,7 @@ int __get_user_pages(struct task_struct
71747 goto next_page;
71748 }
71749
71750 - if (!vma ||
71751 + if (!vma || start < vma->vm_start ||
71752 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71753 !(vm_flags & vma->vm_flags))
71754 return i ? : -EFAULT;
71755 @@ -1566,11 +1567,6 @@ int __get_user_pages(struct task_struct
71756 int ret;
71757 unsigned int fault_flags = 0;
71758
71759 - /* For mlock, just skip the stack guard page. */
71760 - if (foll_flags & FOLL_MLOCK) {
71761 - if (stack_guard_page(vma, start))
71762 - goto next_page;
71763 - }
71764 if (foll_flags & FOLL_WRITE)
71765 fault_flags |= FAULT_FLAG_WRITE;
71766 if (nonblocking)
71767 @@ -1644,7 +1640,7 @@ next_page:
71768 start += PAGE_SIZE;
71769 nr_pages--;
71770 } while (nr_pages && start < vma->vm_end);
71771 - } while (nr_pages);
71772 + }
71773 return i;
71774 }
71775 EXPORT_SYMBOL(__get_user_pages);
71776 @@ -1795,6 +1791,10 @@ static int insert_page(struct vm_area_st
71777 page_add_file_rmap(page);
71778 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71779
71780 +#ifdef CONFIG_PAX_SEGMEXEC
71781 + pax_mirror_file_pte(vma, addr, page, ptl);
71782 +#endif
71783 +
71784 retval = 0;
71785 pte_unmap_unlock(pte, ptl);
71786 return retval;
71787 @@ -1829,10 +1829,22 @@ out:
71788 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71789 struct page *page)
71790 {
71791 +
71792 +#ifdef CONFIG_PAX_SEGMEXEC
71793 + struct vm_area_struct *vma_m;
71794 +#endif
71795 +
71796 if (addr < vma->vm_start || addr >= vma->vm_end)
71797 return -EFAULT;
71798 if (!page_count(page))
71799 return -EINVAL;
71800 +
71801 +#ifdef CONFIG_PAX_SEGMEXEC
71802 + vma_m = pax_find_mirror_vma(vma);
71803 + if (vma_m)
71804 + vma_m->vm_flags |= VM_INSERTPAGE;
71805 +#endif
71806 +
71807 vma->vm_flags |= VM_INSERTPAGE;
71808 return insert_page(vma, addr, page, vma->vm_page_prot);
71809 }
71810 @@ -1918,6 +1930,7 @@ int vm_insert_mixed(struct vm_area_struc
71811 unsigned long pfn)
71812 {
71813 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71814 + BUG_ON(vma->vm_mirror);
71815
71816 if (addr < vma->vm_start || addr >= vma->vm_end)
71817 return -EFAULT;
71818 @@ -2233,6 +2246,186 @@ static inline void cow_user_page(struct
71819 copy_user_highpage(dst, src, va, vma);
71820 }
71821
71822 +#ifdef CONFIG_PAX_SEGMEXEC
71823 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71824 +{
71825 + struct mm_struct *mm = vma->vm_mm;
71826 + spinlock_t *ptl;
71827 + pte_t *pte, entry;
71828 +
71829 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71830 + entry = *pte;
71831 + if (!pte_present(entry)) {
71832 + if (!pte_none(entry)) {
71833 + BUG_ON(pte_file(entry));
71834 + free_swap_and_cache(pte_to_swp_entry(entry));
71835 + pte_clear_not_present_full(mm, address, pte, 0);
71836 + }
71837 + } else {
71838 + struct page *page;
71839 +
71840 + flush_cache_page(vma, address, pte_pfn(entry));
71841 + entry = ptep_clear_flush(vma, address, pte);
71842 + BUG_ON(pte_dirty(entry));
71843 + page = vm_normal_page(vma, address, entry);
71844 + if (page) {
71845 + update_hiwater_rss(mm);
71846 + if (PageAnon(page))
71847 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71848 + else
71849 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71850 + page_remove_rmap(page);
71851 + page_cache_release(page);
71852 + }
71853 + }
71854 + pte_unmap_unlock(pte, ptl);
71855 +}
71856 +
71857 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71858 + *
71859 + * the ptl of the lower mapped page is held on entry and is not released on exit
71860 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71861 + */
71862 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71863 +{
71864 + struct mm_struct *mm = vma->vm_mm;
71865 + unsigned long address_m;
71866 + spinlock_t *ptl_m;
71867 + struct vm_area_struct *vma_m;
71868 + pmd_t *pmd_m;
71869 + pte_t *pte_m, entry_m;
71870 +
71871 + BUG_ON(!page_m || !PageAnon(page_m));
71872 +
71873 + vma_m = pax_find_mirror_vma(vma);
71874 + if (!vma_m)
71875 + return;
71876 +
71877 + BUG_ON(!PageLocked(page_m));
71878 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71879 + address_m = address + SEGMEXEC_TASK_SIZE;
71880 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71881 + pte_m = pte_offset_map(pmd_m, address_m);
71882 + ptl_m = pte_lockptr(mm, pmd_m);
71883 + if (ptl != ptl_m) {
71884 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71885 + if (!pte_none(*pte_m))
71886 + goto out;
71887 + }
71888 +
71889 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71890 + page_cache_get(page_m);
71891 + page_add_anon_rmap(page_m, vma_m, address_m);
71892 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71893 + set_pte_at(mm, address_m, pte_m, entry_m);
71894 + update_mmu_cache(vma_m, address_m, entry_m);
71895 +out:
71896 + if (ptl != ptl_m)
71897 + spin_unlock(ptl_m);
71898 + pte_unmap(pte_m);
71899 + unlock_page(page_m);
71900 +}
71901 +
71902 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71903 +{
71904 + struct mm_struct *mm = vma->vm_mm;
71905 + unsigned long address_m;
71906 + spinlock_t *ptl_m;
71907 + struct vm_area_struct *vma_m;
71908 + pmd_t *pmd_m;
71909 + pte_t *pte_m, entry_m;
71910 +
71911 + BUG_ON(!page_m || PageAnon(page_m));
71912 +
71913 + vma_m = pax_find_mirror_vma(vma);
71914 + if (!vma_m)
71915 + return;
71916 +
71917 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71918 + address_m = address + SEGMEXEC_TASK_SIZE;
71919 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71920 + pte_m = pte_offset_map(pmd_m, address_m);
71921 + ptl_m = pte_lockptr(mm, pmd_m);
71922 + if (ptl != ptl_m) {
71923 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71924 + if (!pte_none(*pte_m))
71925 + goto out;
71926 + }
71927 +
71928 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71929 + page_cache_get(page_m);
71930 + page_add_file_rmap(page_m);
71931 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71932 + set_pte_at(mm, address_m, pte_m, entry_m);
71933 + update_mmu_cache(vma_m, address_m, entry_m);
71934 +out:
71935 + if (ptl != ptl_m)
71936 + spin_unlock(ptl_m);
71937 + pte_unmap(pte_m);
71938 +}
71939 +
71940 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71941 +{
71942 + struct mm_struct *mm = vma->vm_mm;
71943 + unsigned long address_m;
71944 + spinlock_t *ptl_m;
71945 + struct vm_area_struct *vma_m;
71946 + pmd_t *pmd_m;
71947 + pte_t *pte_m, entry_m;
71948 +
71949 + vma_m = pax_find_mirror_vma(vma);
71950 + if (!vma_m)
71951 + return;
71952 +
71953 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71954 + address_m = address + SEGMEXEC_TASK_SIZE;
71955 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71956 + pte_m = pte_offset_map(pmd_m, address_m);
71957 + ptl_m = pte_lockptr(mm, pmd_m);
71958 + if (ptl != ptl_m) {
71959 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71960 + if (!pte_none(*pte_m))
71961 + goto out;
71962 + }
71963 +
71964 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71965 + set_pte_at(mm, address_m, pte_m, entry_m);
71966 +out:
71967 + if (ptl != ptl_m)
71968 + spin_unlock(ptl_m);
71969 + pte_unmap(pte_m);
71970 +}
71971 +
71972 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71973 +{
71974 + struct page *page_m;
71975 + pte_t entry;
71976 +
71977 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71978 + goto out;
71979 +
71980 + entry = *pte;
71981 + page_m = vm_normal_page(vma, address, entry);
71982 + if (!page_m)
71983 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71984 + else if (PageAnon(page_m)) {
71985 + if (pax_find_mirror_vma(vma)) {
71986 + pte_unmap_unlock(pte, ptl);
71987 + lock_page(page_m);
71988 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71989 + if (pte_same(entry, *pte))
71990 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71991 + else
71992 + unlock_page(page_m);
71993 + }
71994 + } else
71995 + pax_mirror_file_pte(vma, address, page_m, ptl);
71996 +
71997 +out:
71998 + pte_unmap_unlock(pte, ptl);
71999 +}
72000 +#endif
72001 +
72002 /*
72003 * This routine handles present pages, when users try to write
72004 * to a shared page. It is done by copying the page to a new address
72005 @@ -2444,6 +2637,12 @@ gotten:
72006 */
72007 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72008 if (likely(pte_same(*page_table, orig_pte))) {
72009 +
72010 +#ifdef CONFIG_PAX_SEGMEXEC
72011 + if (pax_find_mirror_vma(vma))
72012 + BUG_ON(!trylock_page(new_page));
72013 +#endif
72014 +
72015 if (old_page) {
72016 if (!PageAnon(old_page)) {
72017 dec_mm_counter_fast(mm, MM_FILEPAGES);
72018 @@ -2495,6 +2694,10 @@ gotten:
72019 page_remove_rmap(old_page);
72020 }
72021
72022 +#ifdef CONFIG_PAX_SEGMEXEC
72023 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72024 +#endif
72025 +
72026 /* Free the old page.. */
72027 new_page = old_page;
72028 ret |= VM_FAULT_WRITE;
72029 @@ -2905,6 +3108,11 @@ static int do_swap_page(struct mm_struct
72030 swap_free(entry);
72031 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72032 try_to_free_swap(page);
72033 +
72034 +#ifdef CONFIG_PAX_SEGMEXEC
72035 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72036 +#endif
72037 +
72038 unlock_page(page);
72039 if (swapcache) {
72040 /*
72041 @@ -2928,6 +3136,11 @@ static int do_swap_page(struct mm_struct
72042
72043 /* No need to invalidate - it was non-present before */
72044 update_mmu_cache(vma, address, page_table);
72045 +
72046 +#ifdef CONFIG_PAX_SEGMEXEC
72047 + pax_mirror_anon_pte(vma, address, page, ptl);
72048 +#endif
72049 +
72050 unlock:
72051 pte_unmap_unlock(page_table, ptl);
72052 out:
72053 @@ -2947,40 +3160,6 @@ out_release:
72054 }
72055
72056 /*
72057 - * This is like a special single-page "expand_{down|up}wards()",
72058 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72059 - * doesn't hit another vma.
72060 - */
72061 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72062 -{
72063 - address &= PAGE_MASK;
72064 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72065 - struct vm_area_struct *prev = vma->vm_prev;
72066 -
72067 - /*
72068 - * Is there a mapping abutting this one below?
72069 - *
72070 - * That's only ok if it's the same stack mapping
72071 - * that has gotten split..
72072 - */
72073 - if (prev && prev->vm_end == address)
72074 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72075 -
72076 - expand_stack(vma, address - PAGE_SIZE);
72077 - }
72078 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72079 - struct vm_area_struct *next = vma->vm_next;
72080 -
72081 - /* As VM_GROWSDOWN but s/below/above/ */
72082 - if (next && next->vm_start == address + PAGE_SIZE)
72083 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72084 -
72085 - expand_upwards(vma, address + PAGE_SIZE);
72086 - }
72087 - return 0;
72088 -}
72089 -
72090 -/*
72091 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72092 * but allow concurrent faults), and pte mapped but not yet locked.
72093 * We return with mmap_sem still held, but pte unmapped and unlocked.
72094 @@ -2989,27 +3168,23 @@ static int do_anonymous_page(struct mm_s
72095 unsigned long address, pte_t *page_table, pmd_t *pmd,
72096 unsigned int flags)
72097 {
72098 - struct page *page;
72099 + struct page *page = NULL;
72100 spinlock_t *ptl;
72101 pte_t entry;
72102
72103 - pte_unmap(page_table);
72104 -
72105 - /* Check if we need to add a guard page to the stack */
72106 - if (check_stack_guard_page(vma, address) < 0)
72107 - return VM_FAULT_SIGBUS;
72108 -
72109 - /* Use the zero-page for reads */
72110 if (!(flags & FAULT_FLAG_WRITE)) {
72111 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72112 vma->vm_page_prot));
72113 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72114 + ptl = pte_lockptr(mm, pmd);
72115 + spin_lock(ptl);
72116 if (!pte_none(*page_table))
72117 goto unlock;
72118 goto setpte;
72119 }
72120
72121 /* Allocate our own private page. */
72122 + pte_unmap(page_table);
72123 +
72124 if (unlikely(anon_vma_prepare(vma)))
72125 goto oom;
72126 page = alloc_zeroed_user_highpage_movable(vma, address);
72127 @@ -3028,6 +3203,11 @@ static int do_anonymous_page(struct mm_s
72128 if (!pte_none(*page_table))
72129 goto release;
72130
72131 +#ifdef CONFIG_PAX_SEGMEXEC
72132 + if (pax_find_mirror_vma(vma))
72133 + BUG_ON(!trylock_page(page));
72134 +#endif
72135 +
72136 inc_mm_counter_fast(mm, MM_ANONPAGES);
72137 page_add_new_anon_rmap(page, vma, address);
72138 setpte:
72139 @@ -3035,6 +3215,12 @@ setpte:
72140
72141 /* No need to invalidate - it was non-present before */
72142 update_mmu_cache(vma, address, page_table);
72143 +
72144 +#ifdef CONFIG_PAX_SEGMEXEC
72145 + if (page)
72146 + pax_mirror_anon_pte(vma, address, page, ptl);
72147 +#endif
72148 +
72149 unlock:
72150 pte_unmap_unlock(page_table, ptl);
72151 return 0;
72152 @@ -3172,6 +3358,12 @@ static int __do_fault(struct mm_struct *
72153 */
72154 /* Only go through if we didn't race with anybody else... */
72155 if (likely(pte_same(*page_table, orig_pte))) {
72156 +
72157 +#ifdef CONFIG_PAX_SEGMEXEC
72158 + if (anon && pax_find_mirror_vma(vma))
72159 + BUG_ON(!trylock_page(page));
72160 +#endif
72161 +
72162 flush_icache_page(vma, page);
72163 entry = mk_pte(page, vma->vm_page_prot);
72164 if (flags & FAULT_FLAG_WRITE)
72165 @@ -3191,6 +3383,14 @@ static int __do_fault(struct mm_struct *
72166
72167 /* no need to invalidate: a not-present page won't be cached */
72168 update_mmu_cache(vma, address, page_table);
72169 +
72170 +#ifdef CONFIG_PAX_SEGMEXEC
72171 + if (anon)
72172 + pax_mirror_anon_pte(vma, address, page, ptl);
72173 + else
72174 + pax_mirror_file_pte(vma, address, page, ptl);
72175 +#endif
72176 +
72177 } else {
72178 if (charged)
72179 mem_cgroup_uncharge_page(page);
72180 @@ -3338,6 +3538,12 @@ int handle_pte_fault(struct mm_struct *m
72181 if (flags & FAULT_FLAG_WRITE)
72182 flush_tlb_fix_spurious_fault(vma, address);
72183 }
72184 +
72185 +#ifdef CONFIG_PAX_SEGMEXEC
72186 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72187 + return 0;
72188 +#endif
72189 +
72190 unlock:
72191 pte_unmap_unlock(pte, ptl);
72192 return 0;
72193 @@ -3354,6 +3560,10 @@ int handle_mm_fault(struct mm_struct *mm
72194 pmd_t *pmd;
72195 pte_t *pte;
72196
72197 +#ifdef CONFIG_PAX_SEGMEXEC
72198 + struct vm_area_struct *vma_m;
72199 +#endif
72200 +
72201 __set_current_state(TASK_RUNNING);
72202
72203 count_vm_event(PGFAULT);
72204 @@ -3364,6 +3574,34 @@ int handle_mm_fault(struct mm_struct *mm
72205 if (unlikely(is_vm_hugetlb_page(vma)))
72206 return hugetlb_fault(mm, vma, address, flags);
72207
72208 +#ifdef CONFIG_PAX_SEGMEXEC
72209 + vma_m = pax_find_mirror_vma(vma);
72210 + if (vma_m) {
72211 + unsigned long address_m;
72212 + pgd_t *pgd_m;
72213 + pud_t *pud_m;
72214 + pmd_t *pmd_m;
72215 +
72216 + if (vma->vm_start > vma_m->vm_start) {
72217 + address_m = address;
72218 + address -= SEGMEXEC_TASK_SIZE;
72219 + vma = vma_m;
72220 + } else
72221 + address_m = address + SEGMEXEC_TASK_SIZE;
72222 +
72223 + pgd_m = pgd_offset(mm, address_m);
72224 + pud_m = pud_alloc(mm, pgd_m, address_m);
72225 + if (!pud_m)
72226 + return VM_FAULT_OOM;
72227 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72228 + if (!pmd_m)
72229 + return VM_FAULT_OOM;
72230 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72231 + return VM_FAULT_OOM;
72232 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72233 + }
72234 +#endif
72235 +
72236 pgd = pgd_offset(mm, address);
72237 pud = pud_alloc(mm, pgd, address);
72238 if (!pud)
72239 @@ -3393,7 +3631,7 @@ int handle_mm_fault(struct mm_struct *mm
72240 * run pte_offset_map on the pmd, if an huge pmd could
72241 * materialize from under us from a different thread.
72242 */
72243 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72244 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72245 return VM_FAULT_OOM;
72246 /* if an huge pmd materialized from under us just retry later */
72247 if (unlikely(pmd_trans_huge(*pmd)))
72248 @@ -3497,7 +3735,7 @@ static int __init gate_vma_init(void)
72249 gate_vma.vm_start = FIXADDR_USER_START;
72250 gate_vma.vm_end = FIXADDR_USER_END;
72251 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72252 - gate_vma.vm_page_prot = __P101;
72253 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72254 /*
72255 * Make sure the vDSO gets into every core dump.
72256 * Dumping its contents makes post-mortem fully interpretable later
72257 diff -urNp linux-2.6.39.1/mm/memory-failure.c linux-2.6.39.1/mm/memory-failure.c
72258 --- linux-2.6.39.1/mm/memory-failure.c 2011-05-19 00:06:34.000000000 -0400
72259 +++ linux-2.6.39.1/mm/memory-failure.c 2011-05-22 19:36:33.000000000 -0400
72260 @@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
72261
72262 int sysctl_memory_failure_recovery __read_mostly = 1;
72263
72264 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72265 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72266
72267 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72268
72269 @@ -1012,7 +1012,7 @@ int __memory_failure(unsigned long pfn,
72270 }
72271
72272 nr_pages = 1 << compound_trans_order(hpage);
72273 - atomic_long_add(nr_pages, &mce_bad_pages);
72274 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72275
72276 /*
72277 * We need/can do nothing about count=0 pages.
72278 @@ -1042,7 +1042,7 @@ int __memory_failure(unsigned long pfn,
72279 if (!PageHWPoison(hpage)
72280 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72281 || (p != hpage && TestSetPageHWPoison(hpage))) {
72282 - atomic_long_sub(nr_pages, &mce_bad_pages);
72283 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72284 return 0;
72285 }
72286 set_page_hwpoison_huge_page(hpage);
72287 @@ -1100,7 +1100,7 @@ int __memory_failure(unsigned long pfn,
72288 }
72289 if (hwpoison_filter(p)) {
72290 if (TestClearPageHWPoison(p))
72291 - atomic_long_sub(nr_pages, &mce_bad_pages);
72292 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72293 unlock_page(hpage);
72294 put_page(hpage);
72295 return 0;
72296 @@ -1226,7 +1226,7 @@ int unpoison_memory(unsigned long pfn)
72297 return 0;
72298 }
72299 if (TestClearPageHWPoison(p))
72300 - atomic_long_sub(nr_pages, &mce_bad_pages);
72301 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72302 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72303 return 0;
72304 }
72305 @@ -1240,7 +1240,7 @@ int unpoison_memory(unsigned long pfn)
72306 */
72307 if (TestClearPageHWPoison(page)) {
72308 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72309 - atomic_long_sub(nr_pages, &mce_bad_pages);
72310 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72311 freeit = 1;
72312 if (PageHuge(page))
72313 clear_page_hwpoison_huge_page(page);
72314 @@ -1353,7 +1353,7 @@ static int soft_offline_huge_page(struct
72315 }
72316 done:
72317 if (!PageHWPoison(hpage))
72318 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
72319 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
72320 set_page_hwpoison_huge_page(hpage);
72321 dequeue_hwpoisoned_huge_page(hpage);
72322 /* keep elevated page count for bad page */
72323 @@ -1482,7 +1482,7 @@ int soft_offline_page(struct page *page,
72324 return ret;
72325
72326 done:
72327 - atomic_long_add(1, &mce_bad_pages);
72328 + atomic_long_add_unchecked(1, &mce_bad_pages);
72329 SetPageHWPoison(page);
72330 /* keep elevated page count for bad page */
72331 return ret;
72332 diff -urNp linux-2.6.39.1/mm/mempolicy.c linux-2.6.39.1/mm/mempolicy.c
72333 --- linux-2.6.39.1/mm/mempolicy.c 2011-05-19 00:06:34.000000000 -0400
72334 +++ linux-2.6.39.1/mm/mempolicy.c 2011-05-22 19:41:42.000000000 -0400
72335 @@ -643,6 +643,10 @@ static int mbind_range(struct mm_struct
72336 unsigned long vmstart;
72337 unsigned long vmend;
72338
72339 +#ifdef CONFIG_PAX_SEGMEXEC
72340 + struct vm_area_struct *vma_m;
72341 +#endif
72342 +
72343 vma = find_vma_prev(mm, start, &prev);
72344 if (!vma || vma->vm_start > start)
72345 return -EFAULT;
72346 @@ -673,6 +677,16 @@ static int mbind_range(struct mm_struct
72347 err = policy_vma(vma, new_pol);
72348 if (err)
72349 goto out;
72350 +
72351 +#ifdef CONFIG_PAX_SEGMEXEC
72352 + vma_m = pax_find_mirror_vma(vma);
72353 + if (vma_m) {
72354 + err = policy_vma(vma_m, new_pol);
72355 + if (err)
72356 + goto out;
72357 + }
72358 +#endif
72359 +
72360 }
72361
72362 out:
72363 @@ -1106,6 +1120,17 @@ static long do_mbind(unsigned long start
72364
72365 if (end < start)
72366 return -EINVAL;
72367 +
72368 +#ifdef CONFIG_PAX_SEGMEXEC
72369 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72370 + if (end > SEGMEXEC_TASK_SIZE)
72371 + return -EINVAL;
72372 + } else
72373 +#endif
72374 +
72375 + if (end > TASK_SIZE)
72376 + return -EINVAL;
72377 +
72378 if (end == start)
72379 return 0;
72380
72381 @@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72382 if (!mm)
72383 goto out;
72384
72385 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72386 + if (mm != current->mm &&
72387 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72388 + err = -EPERM;
72389 + goto out;
72390 + }
72391 +#endif
72392 +
72393 /*
72394 * Check if this process has the right to modify the specified
72395 * process. The right exists if the process has administrative
72396 @@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72397 rcu_read_lock();
72398 tcred = __task_cred(task);
72399 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72400 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72401 - !capable(CAP_SYS_NICE)) {
72402 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72403 rcu_read_unlock();
72404 err = -EPERM;
72405 goto out;
72406 @@ -2634,7 +2666,7 @@ int show_numa_map(struct seq_file *m, vo
72407
72408 if (file) {
72409 seq_printf(m, " file=");
72410 - seq_path(m, &file->f_path, "\n\t= ");
72411 + seq_path(m, &file->f_path, "\n\t\\= ");
72412 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
72413 seq_printf(m, " heap");
72414 } else if (vma->vm_start <= mm->start_stack &&
72415 diff -urNp linux-2.6.39.1/mm/migrate.c linux-2.6.39.1/mm/migrate.c
72416 --- linux-2.6.39.1/mm/migrate.c 2011-05-19 00:06:34.000000000 -0400
72417 +++ linux-2.6.39.1/mm/migrate.c 2011-05-22 19:41:42.000000000 -0400
72418 @@ -1133,6 +1133,8 @@ static int do_pages_move(struct mm_struc
72419 unsigned long chunk_start;
72420 int err;
72421
72422 + pax_track_stack();
72423 +
72424 task_nodes = cpuset_mems_allowed(task);
72425
72426 err = -ENOMEM;
72427 @@ -1317,6 +1319,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72428 if (!mm)
72429 return -EINVAL;
72430
72431 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72432 + if (mm != current->mm &&
72433 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72434 + err = -EPERM;
72435 + goto out;
72436 + }
72437 +#endif
72438 +
72439 /*
72440 * Check if this process has the right to modify the specified
72441 * process. The right exists if the process has administrative
72442 @@ -1326,8 +1336,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72443 rcu_read_lock();
72444 tcred = __task_cred(task);
72445 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72446 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72447 - !capable(CAP_SYS_NICE)) {
72448 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72449 rcu_read_unlock();
72450 err = -EPERM;
72451 goto out;
72452 diff -urNp linux-2.6.39.1/mm/mlock.c linux-2.6.39.1/mm/mlock.c
72453 --- linux-2.6.39.1/mm/mlock.c 2011-05-19 00:06:34.000000000 -0400
72454 +++ linux-2.6.39.1/mm/mlock.c 2011-05-22 19:41:42.000000000 -0400
72455 @@ -13,6 +13,7 @@
72456 #include <linux/pagemap.h>
72457 #include <linux/mempolicy.h>
72458 #include <linux/syscalls.h>
72459 +#include <linux/security.h>
72460 #include <linux/sched.h>
72461 #include <linux/module.h>
72462 #include <linux/rmap.h>
72463 @@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
72464 return -EINVAL;
72465 if (end == start)
72466 return 0;
72467 + if (end > TASK_SIZE)
72468 + return -EINVAL;
72469 +
72470 vma = find_vma_prev(current->mm, start, &prev);
72471 if (!vma || vma->vm_start > start)
72472 return -ENOMEM;
72473 @@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
72474 for (nstart = start ; ; ) {
72475 unsigned int newflags;
72476
72477 +#ifdef CONFIG_PAX_SEGMEXEC
72478 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72479 + break;
72480 +#endif
72481 +
72482 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72483
72484 newflags = vma->vm_flags | VM_LOCKED;
72485 @@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
72486 lock_limit >>= PAGE_SHIFT;
72487
72488 /* check against resource limits */
72489 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72490 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72491 error = do_mlock(start, len, 1);
72492 up_write(&current->mm->mmap_sem);
72493 @@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
72494 static int do_mlockall(int flags)
72495 {
72496 struct vm_area_struct * vma, * prev = NULL;
72497 - unsigned int def_flags = 0;
72498
72499 if (flags & MCL_FUTURE)
72500 - def_flags = VM_LOCKED;
72501 - current->mm->def_flags = def_flags;
72502 + current->mm->def_flags |= VM_LOCKED;
72503 + else
72504 + current->mm->def_flags &= ~VM_LOCKED;
72505 if (flags == MCL_FUTURE)
72506 goto out;
72507
72508 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72509 - unsigned int newflags;
72510 + unsigned long newflags;
72511 +
72512 +#ifdef CONFIG_PAX_SEGMEXEC
72513 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72514 + break;
72515 +#endif
72516
72517 + BUG_ON(vma->vm_end > TASK_SIZE);
72518 newflags = vma->vm_flags | VM_LOCKED;
72519 if (!(flags & MCL_CURRENT))
72520 newflags &= ~VM_LOCKED;
72521 @@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72522 lock_limit >>= PAGE_SHIFT;
72523
72524 ret = -ENOMEM;
72525 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72526 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72527 capable(CAP_IPC_LOCK))
72528 ret = do_mlockall(flags);
72529 diff -urNp linux-2.6.39.1/mm/mmap.c linux-2.6.39.1/mm/mmap.c
72530 --- linux-2.6.39.1/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
72531 +++ linux-2.6.39.1/mm/mmap.c 2011-05-22 19:41:42.000000000 -0400
72532 @@ -46,6 +46,16 @@
72533 #define arch_rebalance_pgtables(addr, len) (addr)
72534 #endif
72535
72536 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72537 +{
72538 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72539 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72540 + up_read(&mm->mmap_sem);
72541 + BUG();
72542 + }
72543 +#endif
72544 +}
72545 +
72546 static void unmap_region(struct mm_struct *mm,
72547 struct vm_area_struct *vma, struct vm_area_struct *prev,
72548 unsigned long start, unsigned long end);
72549 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
72550 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72551 *
72552 */
72553 -pgprot_t protection_map[16] = {
72554 +pgprot_t protection_map[16] __read_only = {
72555 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72556 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72557 };
72558
72559 pgprot_t vm_get_page_prot(unsigned long vm_flags)
72560 {
72561 - return __pgprot(pgprot_val(protection_map[vm_flags &
72562 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72563 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72564 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72565 +
72566 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72567 + if (!(__supported_pte_mask & _PAGE_NX) &&
72568 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72569 + (vm_flags & (VM_READ | VM_WRITE)))
72570 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72571 +#endif
72572 +
72573 + return prot;
72574 }
72575 EXPORT_SYMBOL(vm_get_page_prot);
72576
72577 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72578 int sysctl_overcommit_ratio = 50; /* default is 50% */
72579 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72580 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72581 struct percpu_counter vm_committed_as;
72582
72583 /*
72584 @@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
72585 struct vm_area_struct *next = vma->vm_next;
72586
72587 might_sleep();
72588 + BUG_ON(vma->vm_mirror);
72589 if (vma->vm_ops && vma->vm_ops->close)
72590 vma->vm_ops->close(vma);
72591 if (vma->vm_file) {
72592 @@ -276,6 +297,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72593 * not page aligned -Ram Gupta
72594 */
72595 rlim = rlimit(RLIMIT_DATA);
72596 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72597 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72598 (mm->end_data - mm->start_data) > rlim)
72599 goto out;
72600 @@ -719,6 +741,12 @@ static int
72601 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72602 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72603 {
72604 +
72605 +#ifdef CONFIG_PAX_SEGMEXEC
72606 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72607 + return 0;
72608 +#endif
72609 +
72610 if (is_mergeable_vma(vma, file, vm_flags) &&
72611 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72612 if (vma->vm_pgoff == vm_pgoff)
72613 @@ -738,6 +766,12 @@ static int
72614 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72615 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72616 {
72617 +
72618 +#ifdef CONFIG_PAX_SEGMEXEC
72619 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72620 + return 0;
72621 +#endif
72622 +
72623 if (is_mergeable_vma(vma, file, vm_flags) &&
72624 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72625 pgoff_t vm_pglen;
72626 @@ -780,13 +814,20 @@ can_vma_merge_after(struct vm_area_struc
72627 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72628 struct vm_area_struct *prev, unsigned long addr,
72629 unsigned long end, unsigned long vm_flags,
72630 - struct anon_vma *anon_vma, struct file *file,
72631 + struct anon_vma *anon_vma, struct file *file,
72632 pgoff_t pgoff, struct mempolicy *policy)
72633 {
72634 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72635 struct vm_area_struct *area, *next;
72636 int err;
72637
72638 +#ifdef CONFIG_PAX_SEGMEXEC
72639 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72640 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72641 +
72642 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72643 +#endif
72644 +
72645 /*
72646 * We later require that vma->vm_flags == vm_flags,
72647 * so this tests vma->vm_flags & VM_SPECIAL, too.
72648 @@ -802,6 +843,15 @@ struct vm_area_struct *vma_merge(struct
72649 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72650 next = next->vm_next;
72651
72652 +#ifdef CONFIG_PAX_SEGMEXEC
72653 + if (prev)
72654 + prev_m = pax_find_mirror_vma(prev);
72655 + if (area)
72656 + area_m = pax_find_mirror_vma(area);
72657 + if (next)
72658 + next_m = pax_find_mirror_vma(next);
72659 +#endif
72660 +
72661 /*
72662 * Can it merge with the predecessor?
72663 */
72664 @@ -821,9 +871,24 @@ struct vm_area_struct *vma_merge(struct
72665 /* cases 1, 6 */
72666 err = vma_adjust(prev, prev->vm_start,
72667 next->vm_end, prev->vm_pgoff, NULL);
72668 - } else /* cases 2, 5, 7 */
72669 +
72670 +#ifdef CONFIG_PAX_SEGMEXEC
72671 + if (!err && prev_m)
72672 + err = vma_adjust(prev_m, prev_m->vm_start,
72673 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72674 +#endif
72675 +
72676 + } else { /* cases 2, 5, 7 */
72677 err = vma_adjust(prev, prev->vm_start,
72678 end, prev->vm_pgoff, NULL);
72679 +
72680 +#ifdef CONFIG_PAX_SEGMEXEC
72681 + if (!err && prev_m)
72682 + err = vma_adjust(prev_m, prev_m->vm_start,
72683 + end_m, prev_m->vm_pgoff, NULL);
72684 +#endif
72685 +
72686 + }
72687 if (err)
72688 return NULL;
72689 khugepaged_enter_vma_merge(prev);
72690 @@ -837,12 +902,27 @@ struct vm_area_struct *vma_merge(struct
72691 mpol_equal(policy, vma_policy(next)) &&
72692 can_vma_merge_before(next, vm_flags,
72693 anon_vma, file, pgoff+pglen)) {
72694 - if (prev && addr < prev->vm_end) /* case 4 */
72695 + if (prev && addr < prev->vm_end) { /* case 4 */
72696 err = vma_adjust(prev, prev->vm_start,
72697 addr, prev->vm_pgoff, NULL);
72698 - else /* cases 3, 8 */
72699 +
72700 +#ifdef CONFIG_PAX_SEGMEXEC
72701 + if (!err && prev_m)
72702 + err = vma_adjust(prev_m, prev_m->vm_start,
72703 + addr_m, prev_m->vm_pgoff, NULL);
72704 +#endif
72705 +
72706 + } else { /* cases 3, 8 */
72707 err = vma_adjust(area, addr, next->vm_end,
72708 next->vm_pgoff - pglen, NULL);
72709 +
72710 +#ifdef CONFIG_PAX_SEGMEXEC
72711 + if (!err && area_m)
72712 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72713 + next_m->vm_pgoff - pglen, NULL);
72714 +#endif
72715 +
72716 + }
72717 if (err)
72718 return NULL;
72719 khugepaged_enter_vma_merge(area);
72720 @@ -958,14 +1038,11 @@ none:
72721 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72722 struct file *file, long pages)
72723 {
72724 - const unsigned long stack_flags
72725 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72726 -
72727 if (file) {
72728 mm->shared_vm += pages;
72729 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72730 mm->exec_vm += pages;
72731 - } else if (flags & stack_flags)
72732 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72733 mm->stack_vm += pages;
72734 if (flags & (VM_RESERVED|VM_IO))
72735 mm->reserved_vm += pages;
72736 @@ -992,7 +1069,7 @@ unsigned long do_mmap_pgoff(struct file
72737 * (the exception is when the underlying filesystem is noexec
72738 * mounted, in which case we dont add PROT_EXEC.)
72739 */
72740 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72741 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72742 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72743 prot |= PROT_EXEC;
72744
72745 @@ -1018,7 +1095,7 @@ unsigned long do_mmap_pgoff(struct file
72746 /* Obtain the address to map to. we verify (or select) it and ensure
72747 * that it represents a valid section of the address space.
72748 */
72749 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72750 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72751 if (addr & ~PAGE_MASK)
72752 return addr;
72753
72754 @@ -1029,6 +1106,36 @@ unsigned long do_mmap_pgoff(struct file
72755 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72756 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72757
72758 +#ifdef CONFIG_PAX_MPROTECT
72759 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72760 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72761 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72762 + gr_log_rwxmmap(file);
72763 +
72764 +#ifdef CONFIG_PAX_EMUPLT
72765 + vm_flags &= ~VM_EXEC;
72766 +#else
72767 + return -EPERM;
72768 +#endif
72769 +
72770 + }
72771 +
72772 + if (!(vm_flags & VM_EXEC))
72773 + vm_flags &= ~VM_MAYEXEC;
72774 +#else
72775 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72776 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72777 +#endif
72778 + else
72779 + vm_flags &= ~VM_MAYWRITE;
72780 + }
72781 +#endif
72782 +
72783 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72784 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72785 + vm_flags &= ~VM_PAGEEXEC;
72786 +#endif
72787 +
72788 if (flags & MAP_LOCKED)
72789 if (!can_do_mlock())
72790 return -EPERM;
72791 @@ -1040,6 +1147,7 @@ unsigned long do_mmap_pgoff(struct file
72792 locked += mm->locked_vm;
72793 lock_limit = rlimit(RLIMIT_MEMLOCK);
72794 lock_limit >>= PAGE_SHIFT;
72795 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72796 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72797 return -EAGAIN;
72798 }
72799 @@ -1110,6 +1218,9 @@ unsigned long do_mmap_pgoff(struct file
72800 if (error)
72801 return error;
72802
72803 + if (!gr_acl_handle_mmap(file, prot))
72804 + return -EACCES;
72805 +
72806 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72807 }
72808 EXPORT_SYMBOL(do_mmap_pgoff);
72809 @@ -1187,10 +1298,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
72810 */
72811 int vma_wants_writenotify(struct vm_area_struct *vma)
72812 {
72813 - unsigned int vm_flags = vma->vm_flags;
72814 + unsigned long vm_flags = vma->vm_flags;
72815
72816 /* If it was private or non-writable, the write bit is already clear */
72817 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72818 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72819 return 0;
72820
72821 /* The backer wishes to know when pages are first written to? */
72822 @@ -1239,14 +1350,24 @@ unsigned long mmap_region(struct file *f
72823 unsigned long charged = 0;
72824 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72825
72826 +#ifdef CONFIG_PAX_SEGMEXEC
72827 + struct vm_area_struct *vma_m = NULL;
72828 +#endif
72829 +
72830 + /*
72831 + * mm->mmap_sem is required to protect against another thread
72832 + * changing the mappings in case we sleep.
72833 + */
72834 + verify_mm_writelocked(mm);
72835 +
72836 /* Clear old maps */
72837 error = -ENOMEM;
72838 -munmap_back:
72839 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72840 if (vma && vma->vm_start < addr + len) {
72841 if (do_munmap(mm, addr, len))
72842 return -ENOMEM;
72843 - goto munmap_back;
72844 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72845 + BUG_ON(vma && vma->vm_start < addr + len);
72846 }
72847
72848 /* Check against address space limit. */
72849 @@ -1295,6 +1416,16 @@ munmap_back:
72850 goto unacct_error;
72851 }
72852
72853 +#ifdef CONFIG_PAX_SEGMEXEC
72854 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72855 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72856 + if (!vma_m) {
72857 + error = -ENOMEM;
72858 + goto free_vma;
72859 + }
72860 + }
72861 +#endif
72862 +
72863 vma->vm_mm = mm;
72864 vma->vm_start = addr;
72865 vma->vm_end = addr + len;
72866 @@ -1318,6 +1449,19 @@ munmap_back:
72867 error = file->f_op->mmap(file, vma);
72868 if (error)
72869 goto unmap_and_free_vma;
72870 +
72871 +#ifdef CONFIG_PAX_SEGMEXEC
72872 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72873 + added_exe_file_vma(mm);
72874 +#endif
72875 +
72876 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72877 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72878 + vma->vm_flags |= VM_PAGEEXEC;
72879 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72880 + }
72881 +#endif
72882 +
72883 if (vm_flags & VM_EXECUTABLE)
72884 added_exe_file_vma(mm);
72885
72886 @@ -1353,6 +1497,11 @@ munmap_back:
72887 vma_link(mm, vma, prev, rb_link, rb_parent);
72888 file = vma->vm_file;
72889
72890 +#ifdef CONFIG_PAX_SEGMEXEC
72891 + if (vma_m)
72892 + BUG_ON(pax_mirror_vma(vma_m, vma));
72893 +#endif
72894 +
72895 /* Once vma denies write, undo our temporary denial count */
72896 if (correct_wcount)
72897 atomic_inc(&inode->i_writecount);
72898 @@ -1361,6 +1510,7 @@ out:
72899
72900 mm->total_vm += len >> PAGE_SHIFT;
72901 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72902 + track_exec_limit(mm, addr, addr + len, vm_flags);
72903 if (vm_flags & VM_LOCKED) {
72904 if (!mlock_vma_pages_range(vma, addr, addr + len))
72905 mm->locked_vm += (len >> PAGE_SHIFT);
72906 @@ -1378,6 +1528,12 @@ unmap_and_free_vma:
72907 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72908 charged = 0;
72909 free_vma:
72910 +
72911 +#ifdef CONFIG_PAX_SEGMEXEC
72912 + if (vma_m)
72913 + kmem_cache_free(vm_area_cachep, vma_m);
72914 +#endif
72915 +
72916 kmem_cache_free(vm_area_cachep, vma);
72917 unacct_error:
72918 if (charged)
72919 @@ -1385,6 +1541,44 @@ unacct_error:
72920 return error;
72921 }
72922
72923 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72924 +{
72925 + if (!vma) {
72926 +#ifdef CONFIG_STACK_GROWSUP
72927 + if (addr > sysctl_heap_stack_gap)
72928 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72929 + else
72930 + vma = find_vma(current->mm, 0);
72931 + if (vma && (vma->vm_flags & VM_GROWSUP))
72932 + return false;
72933 +#endif
72934 + return true;
72935 + }
72936 +
72937 + if (addr + len > vma->vm_start)
72938 + return false;
72939 +
72940 + if (vma->vm_flags & VM_GROWSDOWN)
72941 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72942 +#ifdef CONFIG_STACK_GROWSUP
72943 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72944 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72945 +#endif
72946 +
72947 + return true;
72948 +}
72949 +
72950 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72951 +{
72952 + if (vma->vm_start < len)
72953 + return -ENOMEM;
72954 + if (!(vma->vm_flags & VM_GROWSDOWN))
72955 + return vma->vm_start - len;
72956 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72957 + return vma->vm_start - len - sysctl_heap_stack_gap;
72958 + return -ENOMEM;
72959 +}
72960 +
72961 /* Get an address range which is currently unmapped.
72962 * For shmat() with addr=0.
72963 *
72964 @@ -1411,18 +1605,23 @@ arch_get_unmapped_area(struct file *filp
72965 if (flags & MAP_FIXED)
72966 return addr;
72967
72968 +#ifdef CONFIG_PAX_RANDMMAP
72969 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72970 +#endif
72971 +
72972 if (addr) {
72973 addr = PAGE_ALIGN(addr);
72974 - vma = find_vma(mm, addr);
72975 - if (TASK_SIZE - len >= addr &&
72976 - (!vma || addr + len <= vma->vm_start))
72977 - return addr;
72978 + if (TASK_SIZE - len >= addr) {
72979 + vma = find_vma(mm, addr);
72980 + if (check_heap_stack_gap(vma, addr, len))
72981 + return addr;
72982 + }
72983 }
72984 if (len > mm->cached_hole_size) {
72985 - start_addr = addr = mm->free_area_cache;
72986 + start_addr = addr = mm->free_area_cache;
72987 } else {
72988 - start_addr = addr = TASK_UNMAPPED_BASE;
72989 - mm->cached_hole_size = 0;
72990 + start_addr = addr = mm->mmap_base;
72991 + mm->cached_hole_size = 0;
72992 }
72993
72994 full_search:
72995 @@ -1433,34 +1632,40 @@ full_search:
72996 * Start a new search - just in case we missed
72997 * some holes.
72998 */
72999 - if (start_addr != TASK_UNMAPPED_BASE) {
73000 - addr = TASK_UNMAPPED_BASE;
73001 - start_addr = addr;
73002 + if (start_addr != mm->mmap_base) {
73003 + start_addr = addr = mm->mmap_base;
73004 mm->cached_hole_size = 0;
73005 goto full_search;
73006 }
73007 return -ENOMEM;
73008 }
73009 - if (!vma || addr + len <= vma->vm_start) {
73010 - /*
73011 - * Remember the place where we stopped the search:
73012 - */
73013 - mm->free_area_cache = addr + len;
73014 - return addr;
73015 - }
73016 + if (check_heap_stack_gap(vma, addr, len))
73017 + break;
73018 if (addr + mm->cached_hole_size < vma->vm_start)
73019 mm->cached_hole_size = vma->vm_start - addr;
73020 addr = vma->vm_end;
73021 }
73022 +
73023 + /*
73024 + * Remember the place where we stopped the search:
73025 + */
73026 + mm->free_area_cache = addr + len;
73027 + return addr;
73028 }
73029 #endif
73030
73031 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73032 {
73033 +
73034 +#ifdef CONFIG_PAX_SEGMEXEC
73035 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73036 + return;
73037 +#endif
73038 +
73039 /*
73040 * Is this a new hole at the lowest possible address?
73041 */
73042 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
73043 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
73044 mm->free_area_cache = addr;
73045 mm->cached_hole_size = ~0UL;
73046 }
73047 @@ -1478,7 +1683,7 @@ arch_get_unmapped_area_topdown(struct fi
73048 {
73049 struct vm_area_struct *vma;
73050 struct mm_struct *mm = current->mm;
73051 - unsigned long addr = addr0;
73052 + unsigned long base = mm->mmap_base, addr = addr0;
73053
73054 /* requested length too big for entire address space */
73055 if (len > TASK_SIZE)
73056 @@ -1487,13 +1692,18 @@ arch_get_unmapped_area_topdown(struct fi
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 /* requesting a specific address */
73065 if (addr) {
73066 addr = PAGE_ALIGN(addr);
73067 - vma = find_vma(mm, addr);
73068 - if (TASK_SIZE - len >= addr &&
73069 - (!vma || addr + len <= vma->vm_start))
73070 - return addr;
73071 + if (TASK_SIZE - len >= addr) {
73072 + vma = find_vma(mm, addr);
73073 + if (check_heap_stack_gap(vma, addr, len))
73074 + return addr;
73075 + }
73076 }
73077
73078 /* check if free_area_cache is useful for us */
73079 @@ -1508,7 +1718,7 @@ arch_get_unmapped_area_topdown(struct fi
73080 /* make sure it can fit in the remaining address space */
73081 if (addr > len) {
73082 vma = find_vma(mm, addr-len);
73083 - if (!vma || addr <= vma->vm_start)
73084 + if (check_heap_stack_gap(vma, addr - len, len))
73085 /* remember the address as a hint for next time */
73086 return (mm->free_area_cache = addr-len);
73087 }
73088 @@ -1525,7 +1735,7 @@ arch_get_unmapped_area_topdown(struct fi
73089 * return with success:
73090 */
73091 vma = find_vma(mm, addr);
73092 - if (!vma || addr+len <= vma->vm_start)
73093 + if (check_heap_stack_gap(vma, addr, len))
73094 /* remember the address as a hint for next time */
73095 return (mm->free_area_cache = addr);
73096
73097 @@ -1534,8 +1744,8 @@ arch_get_unmapped_area_topdown(struct fi
73098 mm->cached_hole_size = vma->vm_start - addr;
73099
73100 /* try just below the current vma->vm_start */
73101 - addr = vma->vm_start-len;
73102 - } while (len < vma->vm_start);
73103 + addr = skip_heap_stack_gap(vma, len);
73104 + } while (!IS_ERR_VALUE(addr));
73105
73106 bottomup:
73107 /*
73108 @@ -1544,13 +1754,21 @@ bottomup:
73109 * can happen with large stack limits and large mmap()
73110 * allocations.
73111 */
73112 + mm->mmap_base = TASK_UNMAPPED_BASE;
73113 +
73114 +#ifdef CONFIG_PAX_RANDMMAP
73115 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73116 + mm->mmap_base += mm->delta_mmap;
73117 +#endif
73118 +
73119 + mm->free_area_cache = mm->mmap_base;
73120 mm->cached_hole_size = ~0UL;
73121 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73122 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73123 /*
73124 * Restore the topdown base:
73125 */
73126 - mm->free_area_cache = mm->mmap_base;
73127 + mm->mmap_base = base;
73128 + mm->free_area_cache = base;
73129 mm->cached_hole_size = ~0UL;
73130
73131 return addr;
73132 @@ -1559,6 +1777,12 @@ bottomup:
73133
73134 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73135 {
73136 +
73137 +#ifdef CONFIG_PAX_SEGMEXEC
73138 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73139 + return;
73140 +#endif
73141 +
73142 /*
73143 * Is this a new hole at the highest possible address?
73144 */
73145 @@ -1566,8 +1790,10 @@ void arch_unmap_area_topdown(struct mm_s
73146 mm->free_area_cache = addr;
73147
73148 /* dont allow allocations above current base */
73149 - if (mm->free_area_cache > mm->mmap_base)
73150 + if (mm->free_area_cache > mm->mmap_base) {
73151 mm->free_area_cache = mm->mmap_base;
73152 + mm->cached_hole_size = ~0UL;
73153 + }
73154 }
73155
73156 unsigned long
73157 @@ -1675,6 +1901,28 @@ out:
73158 return prev ? prev->vm_next : vma;
73159 }
73160
73161 +#ifdef CONFIG_PAX_SEGMEXEC
73162 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73163 +{
73164 + struct vm_area_struct *vma_m;
73165 +
73166 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73167 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73168 + BUG_ON(vma->vm_mirror);
73169 + return NULL;
73170 + }
73171 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73172 + vma_m = vma->vm_mirror;
73173 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73174 + BUG_ON(vma->vm_file != vma_m->vm_file);
73175 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73176 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73177 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73178 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73179 + return vma_m;
73180 +}
73181 +#endif
73182 +
73183 /*
73184 * Verify that the stack growth is acceptable and
73185 * update accounting. This is shared with both the
73186 @@ -1691,6 +1939,7 @@ static int acct_stack_growth(struct vm_a
73187 return -ENOMEM;
73188
73189 /* Stack limit test */
73190 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73191 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73192 return -ENOMEM;
73193
73194 @@ -1701,6 +1950,7 @@ static int acct_stack_growth(struct vm_a
73195 locked = mm->locked_vm + grow;
73196 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73197 limit >>= PAGE_SHIFT;
73198 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73199 if (locked > limit && !capable(CAP_IPC_LOCK))
73200 return -ENOMEM;
73201 }
73202 @@ -1731,37 +1981,48 @@ static int acct_stack_growth(struct vm_a
73203 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73204 * vma is the last one with address > vma->vm_end. Have to extend vma.
73205 */
73206 +#ifndef CONFIG_IA64
73207 +static
73208 +#endif
73209 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73210 {
73211 int error;
73212 + bool locknext;
73213
73214 if (!(vma->vm_flags & VM_GROWSUP))
73215 return -EFAULT;
73216
73217 + /* Also guard against wrapping around to address 0. */
73218 + if (address < PAGE_ALIGN(address+1))
73219 + address = PAGE_ALIGN(address+1);
73220 + else
73221 + return -ENOMEM;
73222 +
73223 /*
73224 * We must make sure the anon_vma is allocated
73225 * so that the anon_vma locking is not a noop.
73226 */
73227 if (unlikely(anon_vma_prepare(vma)))
73228 return -ENOMEM;
73229 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73230 + if (locknext && anon_vma_prepare(vma->vm_next))
73231 + return -ENOMEM;
73232 vma_lock_anon_vma(vma);
73233 + if (locknext)
73234 + vma_lock_anon_vma(vma->vm_next);
73235
73236 /*
73237 * vma->vm_start/vm_end cannot change under us because the caller
73238 * is required to hold the mmap_sem in read mode. We need the
73239 - * anon_vma lock to serialize against concurrent expand_stacks.
73240 - * Also guard against wrapping around to address 0.
73241 + * anon_vma locks to serialize against concurrent expand_stacks
73242 + * and expand_upwards.
73243 */
73244 - if (address < PAGE_ALIGN(address+4))
73245 - address = PAGE_ALIGN(address+4);
73246 - else {
73247 - vma_unlock_anon_vma(vma);
73248 - return -ENOMEM;
73249 - }
73250 error = 0;
73251
73252 /* Somebody else might have raced and expanded it already */
73253 - if (address > vma->vm_end) {
73254 + 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)
73255 + error = -ENOMEM;
73256 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73257 unsigned long size, grow;
73258
73259 size = address - vma->vm_start;
73260 @@ -1776,6 +2037,8 @@ int expand_upwards(struct vm_area_struct
73261 }
73262 }
73263 }
73264 + if (locknext)
73265 + vma_unlock_anon_vma(vma->vm_next);
73266 vma_unlock_anon_vma(vma);
73267 khugepaged_enter_vma_merge(vma);
73268 return error;
73269 @@ -1789,6 +2052,8 @@ static int expand_downwards(struct vm_ar
73270 unsigned long address)
73271 {
73272 int error;
73273 + bool lockprev = false;
73274 + struct vm_area_struct *prev;
73275
73276 /*
73277 * We must make sure the anon_vma is allocated
73278 @@ -1802,6 +2067,15 @@ static int expand_downwards(struct vm_ar
73279 if (error)
73280 return error;
73281
73282 + prev = vma->vm_prev;
73283 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73284 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73285 +#endif
73286 + if (lockprev && anon_vma_prepare(prev))
73287 + return -ENOMEM;
73288 + if (lockprev)
73289 + vma_lock_anon_vma(prev);
73290 +
73291 vma_lock_anon_vma(vma);
73292
73293 /*
73294 @@ -1811,9 +2085,17 @@ static int expand_downwards(struct vm_ar
73295 */
73296
73297 /* Somebody else might have raced and expanded it already */
73298 - if (address < vma->vm_start) {
73299 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73300 + error = -ENOMEM;
73301 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73302 unsigned long size, grow;
73303
73304 +#ifdef CONFIG_PAX_SEGMEXEC
73305 + struct vm_area_struct *vma_m;
73306 +
73307 + vma_m = pax_find_mirror_vma(vma);
73308 +#endif
73309 +
73310 size = vma->vm_end - address;
73311 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73312
73313 @@ -1823,11 +2105,22 @@ static int expand_downwards(struct vm_ar
73314 if (!error) {
73315 vma->vm_start = address;
73316 vma->vm_pgoff -= grow;
73317 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73318 +
73319 +#ifdef CONFIG_PAX_SEGMEXEC
73320 + if (vma_m) {
73321 + vma_m->vm_start -= grow << PAGE_SHIFT;
73322 + vma_m->vm_pgoff -= grow;
73323 + }
73324 +#endif
73325 +
73326 perf_event_mmap(vma);
73327 }
73328 }
73329 }
73330 vma_unlock_anon_vma(vma);
73331 + if (lockprev)
73332 + vma_unlock_anon_vma(prev);
73333 khugepaged_enter_vma_merge(vma);
73334 return error;
73335 }
73336 @@ -1902,6 +2195,13 @@ static void remove_vma_list(struct mm_st
73337 do {
73338 long nrpages = vma_pages(vma);
73339
73340 +#ifdef CONFIG_PAX_SEGMEXEC
73341 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73342 + vma = remove_vma(vma);
73343 + continue;
73344 + }
73345 +#endif
73346 +
73347 mm->total_vm -= nrpages;
73348 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73349 vma = remove_vma(vma);
73350 @@ -1947,6 +2247,16 @@ detach_vmas_to_be_unmapped(struct mm_str
73351 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73352 vma->vm_prev = NULL;
73353 do {
73354 +
73355 +#ifdef CONFIG_PAX_SEGMEXEC
73356 + if (vma->vm_mirror) {
73357 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73358 + vma->vm_mirror->vm_mirror = NULL;
73359 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73360 + vma->vm_mirror = NULL;
73361 + }
73362 +#endif
73363 +
73364 rb_erase(&vma->vm_rb, &mm->mm_rb);
73365 mm->map_count--;
73366 tail_vma = vma;
73367 @@ -1975,14 +2285,33 @@ static int __split_vma(struct mm_struct
73368 struct vm_area_struct *new;
73369 int err = -ENOMEM;
73370
73371 +#ifdef CONFIG_PAX_SEGMEXEC
73372 + struct vm_area_struct *vma_m, *new_m = NULL;
73373 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73374 +#endif
73375 +
73376 if (is_vm_hugetlb_page(vma) && (addr &
73377 ~(huge_page_mask(hstate_vma(vma)))))
73378 return -EINVAL;
73379
73380 +#ifdef CONFIG_PAX_SEGMEXEC
73381 + vma_m = pax_find_mirror_vma(vma);
73382 +#endif
73383 +
73384 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73385 if (!new)
73386 goto out_err;
73387
73388 +#ifdef CONFIG_PAX_SEGMEXEC
73389 + if (vma_m) {
73390 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73391 + if (!new_m) {
73392 + kmem_cache_free(vm_area_cachep, new);
73393 + goto out_err;
73394 + }
73395 + }
73396 +#endif
73397 +
73398 /* most fields are the same, copy all, and then fixup */
73399 *new = *vma;
73400
73401 @@ -1995,6 +2324,22 @@ static int __split_vma(struct mm_struct
73402 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73403 }
73404
73405 +#ifdef CONFIG_PAX_SEGMEXEC
73406 + if (vma_m) {
73407 + *new_m = *vma_m;
73408 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73409 + new_m->vm_mirror = new;
73410 + new->vm_mirror = new_m;
73411 +
73412 + if (new_below)
73413 + new_m->vm_end = addr_m;
73414 + else {
73415 + new_m->vm_start = addr_m;
73416 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73417 + }
73418 + }
73419 +#endif
73420 +
73421 pol = mpol_dup(vma_policy(vma));
73422 if (IS_ERR(pol)) {
73423 err = PTR_ERR(pol);
73424 @@ -2020,6 +2365,42 @@ static int __split_vma(struct mm_struct
73425 else
73426 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73427
73428 +#ifdef CONFIG_PAX_SEGMEXEC
73429 + if (!err && vma_m) {
73430 + if (anon_vma_clone(new_m, vma_m))
73431 + goto out_free_mpol;
73432 +
73433 + mpol_get(pol);
73434 + vma_set_policy(new_m, pol);
73435 +
73436 + if (new_m->vm_file) {
73437 + get_file(new_m->vm_file);
73438 + if (vma_m->vm_flags & VM_EXECUTABLE)
73439 + added_exe_file_vma(mm);
73440 + }
73441 +
73442 + if (new_m->vm_ops && new_m->vm_ops->open)
73443 + new_m->vm_ops->open(new_m);
73444 +
73445 + if (new_below)
73446 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73447 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73448 + else
73449 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73450 +
73451 + if (err) {
73452 + if (new_m->vm_ops && new_m->vm_ops->close)
73453 + new_m->vm_ops->close(new_m);
73454 + if (new_m->vm_file) {
73455 + if (vma_m->vm_flags & VM_EXECUTABLE)
73456 + removed_exe_file_vma(mm);
73457 + fput(new_m->vm_file);
73458 + }
73459 + mpol_put(pol);
73460 + }
73461 + }
73462 +#endif
73463 +
73464 /* Success. */
73465 if (!err)
73466 return 0;
73467 @@ -2032,10 +2413,18 @@ static int __split_vma(struct mm_struct
73468 removed_exe_file_vma(mm);
73469 fput(new->vm_file);
73470 }
73471 - unlink_anon_vmas(new);
73472 out_free_mpol:
73473 mpol_put(pol);
73474 out_free_vma:
73475 +
73476 +#ifdef CONFIG_PAX_SEGMEXEC
73477 + if (new_m) {
73478 + unlink_anon_vmas(new_m);
73479 + kmem_cache_free(vm_area_cachep, new_m);
73480 + }
73481 +#endif
73482 +
73483 + unlink_anon_vmas(new);
73484 kmem_cache_free(vm_area_cachep, new);
73485 out_err:
73486 return err;
73487 @@ -2048,6 +2437,15 @@ static int __split_vma(struct mm_struct
73488 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73489 unsigned long addr, int new_below)
73490 {
73491 +
73492 +#ifdef CONFIG_PAX_SEGMEXEC
73493 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73494 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73495 + if (mm->map_count >= sysctl_max_map_count-1)
73496 + return -ENOMEM;
73497 + } else
73498 +#endif
73499 +
73500 if (mm->map_count >= sysctl_max_map_count)
73501 return -ENOMEM;
73502
73503 @@ -2059,11 +2457,30 @@ int split_vma(struct mm_struct *mm, stru
73504 * work. This now handles partial unmappings.
73505 * Jeremy Fitzhardinge <jeremy@goop.org>
73506 */
73507 +#ifdef CONFIG_PAX_SEGMEXEC
73508 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73509 +{
73510 + int ret = __do_munmap(mm, start, len);
73511 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73512 + return ret;
73513 +
73514 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73515 +}
73516 +
73517 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73518 +#else
73519 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73520 +#endif
73521 {
73522 unsigned long end;
73523 struct vm_area_struct *vma, *prev, *last;
73524
73525 + /*
73526 + * mm->mmap_sem is required to protect against another thread
73527 + * changing the mappings in case we sleep.
73528 + */
73529 + verify_mm_writelocked(mm);
73530 +
73531 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73532 return -EINVAL;
73533
73534 @@ -2137,6 +2554,8 @@ int do_munmap(struct mm_struct *mm, unsi
73535 /* Fix up all other VM information */
73536 remove_vma_list(mm, vma);
73537
73538 + track_exec_limit(mm, start, end, 0UL);
73539 +
73540 return 0;
73541 }
73542
73543 @@ -2149,22 +2568,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
73544
73545 profile_munmap(addr);
73546
73547 +#ifdef CONFIG_PAX_SEGMEXEC
73548 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73549 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73550 + return -EINVAL;
73551 +#endif
73552 +
73553 down_write(&mm->mmap_sem);
73554 ret = do_munmap(mm, addr, len);
73555 up_write(&mm->mmap_sem);
73556 return ret;
73557 }
73558
73559 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73560 -{
73561 -#ifdef CONFIG_DEBUG_VM
73562 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73563 - WARN_ON(1);
73564 - up_read(&mm->mmap_sem);
73565 - }
73566 -#endif
73567 -}
73568 -
73569 /*
73570 * this is really a simplified "do_mmap". it only handles
73571 * anonymous maps. eventually we may be able to do some
73572 @@ -2178,6 +2593,7 @@ unsigned long do_brk(unsigned long addr,
73573 struct rb_node ** rb_link, * rb_parent;
73574 pgoff_t pgoff = addr >> PAGE_SHIFT;
73575 int error;
73576 + unsigned long charged;
73577
73578 len = PAGE_ALIGN(len);
73579 if (!len)
73580 @@ -2189,16 +2605,30 @@ unsigned long do_brk(unsigned long addr,
73581
73582 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73583
73584 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73585 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73586 + flags &= ~VM_EXEC;
73587 +
73588 +#ifdef CONFIG_PAX_MPROTECT
73589 + if (mm->pax_flags & MF_PAX_MPROTECT)
73590 + flags &= ~VM_MAYEXEC;
73591 +#endif
73592 +
73593 + }
73594 +#endif
73595 +
73596 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73597 if (error & ~PAGE_MASK)
73598 return error;
73599
73600 + charged = len >> PAGE_SHIFT;
73601 +
73602 /*
73603 * mlock MCL_FUTURE?
73604 */
73605 if (mm->def_flags & VM_LOCKED) {
73606 unsigned long locked, lock_limit;
73607 - locked = len >> PAGE_SHIFT;
73608 + locked = charged;
73609 locked += mm->locked_vm;
73610 lock_limit = rlimit(RLIMIT_MEMLOCK);
73611 lock_limit >>= PAGE_SHIFT;
73612 @@ -2215,22 +2645,22 @@ unsigned long do_brk(unsigned long addr,
73613 /*
73614 * Clear old maps. this also does some error checking for us
73615 */
73616 - munmap_back:
73617 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73618 if (vma && vma->vm_start < addr + len) {
73619 if (do_munmap(mm, addr, len))
73620 return -ENOMEM;
73621 - goto munmap_back;
73622 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73623 + BUG_ON(vma && vma->vm_start < addr + len);
73624 }
73625
73626 /* Check against address space limits *after* clearing old maps... */
73627 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73628 + if (!may_expand_vm(mm, charged))
73629 return -ENOMEM;
73630
73631 if (mm->map_count > sysctl_max_map_count)
73632 return -ENOMEM;
73633
73634 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
73635 + if (security_vm_enough_memory(charged))
73636 return -ENOMEM;
73637
73638 /* Can we just expand an old private anonymous mapping? */
73639 @@ -2244,7 +2674,7 @@ unsigned long do_brk(unsigned long addr,
73640 */
73641 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73642 if (!vma) {
73643 - vm_unacct_memory(len >> PAGE_SHIFT);
73644 + vm_unacct_memory(charged);
73645 return -ENOMEM;
73646 }
73647
73648 @@ -2258,11 +2688,12 @@ unsigned long do_brk(unsigned long addr,
73649 vma_link(mm, vma, prev, rb_link, rb_parent);
73650 out:
73651 perf_event_mmap(vma);
73652 - mm->total_vm += len >> PAGE_SHIFT;
73653 + mm->total_vm += charged;
73654 if (flags & VM_LOCKED) {
73655 if (!mlock_vma_pages_range(vma, addr, addr + len))
73656 - mm->locked_vm += (len >> PAGE_SHIFT);
73657 + mm->locked_vm += charged;
73658 }
73659 + track_exec_limit(mm, addr, addr + len, flags);
73660 return addr;
73661 }
73662
73663 @@ -2309,8 +2740,10 @@ void exit_mmap(struct mm_struct *mm)
73664 * Walk the list again, actually closing and freeing it,
73665 * with preemption enabled, without holding any MM locks.
73666 */
73667 - while (vma)
73668 + while (vma) {
73669 + vma->vm_mirror = NULL;
73670 vma = remove_vma(vma);
73671 + }
73672
73673 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73674 }
73675 @@ -2324,6 +2757,13 @@ int insert_vm_struct(struct mm_struct *
73676 struct vm_area_struct * __vma, * prev;
73677 struct rb_node ** rb_link, * rb_parent;
73678
73679 +#ifdef CONFIG_PAX_SEGMEXEC
73680 + struct vm_area_struct *vma_m = NULL;
73681 +#endif
73682 +
73683 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
73684 + return -EPERM;
73685 +
73686 /*
73687 * The vm_pgoff of a purely anonymous vma should be irrelevant
73688 * until its first write fault, when page's anon_vma and index
73689 @@ -2346,7 +2786,22 @@ int insert_vm_struct(struct mm_struct *
73690 if ((vma->vm_flags & VM_ACCOUNT) &&
73691 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73692 return -ENOMEM;
73693 +
73694 +#ifdef CONFIG_PAX_SEGMEXEC
73695 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73696 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73697 + if (!vma_m)
73698 + return -ENOMEM;
73699 + }
73700 +#endif
73701 +
73702 vma_link(mm, vma, prev, rb_link, rb_parent);
73703 +
73704 +#ifdef CONFIG_PAX_SEGMEXEC
73705 + if (vma_m)
73706 + BUG_ON(pax_mirror_vma(vma_m, vma));
73707 +#endif
73708 +
73709 return 0;
73710 }
73711
73712 @@ -2364,6 +2819,8 @@ struct vm_area_struct *copy_vma(struct v
73713 struct rb_node **rb_link, *rb_parent;
73714 struct mempolicy *pol;
73715
73716 + BUG_ON(vma->vm_mirror);
73717 +
73718 /*
73719 * If anonymous vma has not yet been faulted, update new pgoff
73720 * to match new location, to increase its chance of merging.
73721 @@ -2413,6 +2870,39 @@ struct vm_area_struct *copy_vma(struct v
73722 kmem_cache_free(vm_area_cachep, new_vma);
73723 return NULL;
73724 }
73725 +
73726 +#ifdef CONFIG_PAX_SEGMEXEC
73727 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73728 +{
73729 + struct vm_area_struct *prev_m;
73730 + struct rb_node **rb_link_m, *rb_parent_m;
73731 + struct mempolicy *pol_m;
73732 +
73733 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73734 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73735 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73736 + *vma_m = *vma;
73737 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73738 + if (anon_vma_clone(vma_m, vma))
73739 + return -ENOMEM;
73740 + pol_m = vma_policy(vma_m);
73741 + mpol_get(pol_m);
73742 + vma_set_policy(vma_m, pol_m);
73743 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73744 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73745 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73746 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73747 + if (vma_m->vm_file)
73748 + get_file(vma_m->vm_file);
73749 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73750 + vma_m->vm_ops->open(vma_m);
73751 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73752 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73753 + vma_m->vm_mirror = vma;
73754 + vma->vm_mirror = vma_m;
73755 + return 0;
73756 +}
73757 +#endif
73758
73759 /*
73760 * Return true if the calling process may expand its vm space by the passed
73761 @@ -2424,7 +2914,7 @@ int may_expand_vm(struct mm_struct *mm,
73762 unsigned long lim;
73763
73764 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73765 -
73766 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73767 if (cur + npages > lim)
73768 return 0;
73769 return 1;
73770 @@ -2495,6 +2985,22 @@ int install_special_mapping(struct mm_st
73771 vma->vm_start = addr;
73772 vma->vm_end = addr + len;
73773
73774 +#ifdef CONFIG_PAX_MPROTECT
73775 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73776 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73777 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73778 + return -EPERM;
73779 + if (!(vm_flags & VM_EXEC))
73780 + vm_flags &= ~VM_MAYEXEC;
73781 +#else
73782 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73783 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73784 +#endif
73785 + else
73786 + vm_flags &= ~VM_MAYWRITE;
73787 + }
73788 +#endif
73789 +
73790 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73791 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73792
73793 diff -urNp linux-2.6.39.1/mm/mprotect.c linux-2.6.39.1/mm/mprotect.c
73794 --- linux-2.6.39.1/mm/mprotect.c 2011-05-19 00:06:34.000000000 -0400
73795 +++ linux-2.6.39.1/mm/mprotect.c 2011-05-22 19:41:42.000000000 -0400
73796 @@ -23,10 +23,16 @@
73797 #include <linux/mmu_notifier.h>
73798 #include <linux/migrate.h>
73799 #include <linux/perf_event.h>
73800 +
73801 +#ifdef CONFIG_PAX_MPROTECT
73802 +#include <linux/elf.h>
73803 +#endif
73804 +
73805 #include <asm/uaccess.h>
73806 #include <asm/pgtable.h>
73807 #include <asm/cacheflush.h>
73808 #include <asm/tlbflush.h>
73809 +#include <asm/mmu_context.h>
73810
73811 #ifndef pgprot_modify
73812 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73813 @@ -141,6 +147,48 @@ static void change_protection(struct vm_
73814 flush_tlb_range(vma, start, end);
73815 }
73816
73817 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73818 +/* called while holding the mmap semaphor for writing except stack expansion */
73819 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73820 +{
73821 + unsigned long oldlimit, newlimit = 0UL;
73822 +
73823 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73824 + return;
73825 +
73826 + spin_lock(&mm->page_table_lock);
73827 + oldlimit = mm->context.user_cs_limit;
73828 + if ((prot & VM_EXEC) && oldlimit < end)
73829 + /* USER_CS limit moved up */
73830 + newlimit = end;
73831 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73832 + /* USER_CS limit moved down */
73833 + newlimit = start;
73834 +
73835 + if (newlimit) {
73836 + mm->context.user_cs_limit = newlimit;
73837 +
73838 +#ifdef CONFIG_SMP
73839 + wmb();
73840 + cpus_clear(mm->context.cpu_user_cs_mask);
73841 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73842 +#endif
73843 +
73844 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73845 + }
73846 + spin_unlock(&mm->page_table_lock);
73847 + if (newlimit == end) {
73848 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73849 +
73850 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73851 + if (is_vm_hugetlb_page(vma))
73852 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73853 + else
73854 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73855 + }
73856 +}
73857 +#endif
73858 +
73859 int
73860 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73861 unsigned long start, unsigned long end, unsigned long newflags)
73862 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
73863 int error;
73864 int dirty_accountable = 0;
73865
73866 +#ifdef CONFIG_PAX_SEGMEXEC
73867 + struct vm_area_struct *vma_m = NULL;
73868 + unsigned long start_m, end_m;
73869 +
73870 + start_m = start + SEGMEXEC_TASK_SIZE;
73871 + end_m = end + SEGMEXEC_TASK_SIZE;
73872 +#endif
73873 +
73874 if (newflags == oldflags) {
73875 *pprev = vma;
73876 return 0;
73877 }
73878
73879 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73880 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73881 +
73882 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73883 + return -ENOMEM;
73884 +
73885 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73886 + return -ENOMEM;
73887 + }
73888 +
73889 /*
73890 * If we make a private mapping writable we increase our commit;
73891 * but (without finer accounting) cannot reduce our commit if we
73892 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
73893 }
73894 }
73895
73896 +#ifdef CONFIG_PAX_SEGMEXEC
73897 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73898 + if (start != vma->vm_start) {
73899 + error = split_vma(mm, vma, start, 1);
73900 + if (error)
73901 + goto fail;
73902 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73903 + *pprev = (*pprev)->vm_next;
73904 + }
73905 +
73906 + if (end != vma->vm_end) {
73907 + error = split_vma(mm, vma, end, 0);
73908 + if (error)
73909 + goto fail;
73910 + }
73911 +
73912 + if (pax_find_mirror_vma(vma)) {
73913 + error = __do_munmap(mm, start_m, end_m - start_m);
73914 + if (error)
73915 + goto fail;
73916 + } else {
73917 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73918 + if (!vma_m) {
73919 + error = -ENOMEM;
73920 + goto fail;
73921 + }
73922 + vma->vm_flags = newflags;
73923 + error = pax_mirror_vma(vma_m, vma);
73924 + if (error) {
73925 + vma->vm_flags = oldflags;
73926 + goto fail;
73927 + }
73928 + }
73929 + }
73930 +#endif
73931 +
73932 /*
73933 * First try to merge with previous and/or next vma.
73934 */
73935 @@ -204,9 +306,21 @@ success:
73936 * vm_flags and vm_page_prot are protected by the mmap_sem
73937 * held in write mode.
73938 */
73939 +
73940 +#ifdef CONFIG_PAX_SEGMEXEC
73941 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73942 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73943 +#endif
73944 +
73945 vma->vm_flags = newflags;
73946 +
73947 +#ifdef CONFIG_PAX_MPROTECT
73948 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73949 + mm->binfmt->handle_mprotect(vma, newflags);
73950 +#endif
73951 +
73952 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73953 - vm_get_page_prot(newflags));
73954 + vm_get_page_prot(vma->vm_flags));
73955
73956 if (vma_wants_writenotify(vma)) {
73957 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73958 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73959 end = start + len;
73960 if (end <= start)
73961 return -ENOMEM;
73962 +
73963 +#ifdef CONFIG_PAX_SEGMEXEC
73964 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73965 + if (end > SEGMEXEC_TASK_SIZE)
73966 + return -EINVAL;
73967 + } else
73968 +#endif
73969 +
73970 + if (end > TASK_SIZE)
73971 + return -EINVAL;
73972 +
73973 if (!arch_validate_prot(prot))
73974 return -EINVAL;
73975
73976 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73977 /*
73978 * Does the application expect PROT_READ to imply PROT_EXEC:
73979 */
73980 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73981 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73982 prot |= PROT_EXEC;
73983
73984 vm_flags = calc_vm_prot_bits(prot);
73985 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73986 if (start > vma->vm_start)
73987 prev = vma;
73988
73989 +#ifdef CONFIG_PAX_MPROTECT
73990 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73991 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73992 +#endif
73993 +
73994 for (nstart = start ; ; ) {
73995 unsigned long newflags;
73996
73997 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
73998
73999 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74000 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74001 + if (prot & (PROT_WRITE | PROT_EXEC))
74002 + gr_log_rwxmprotect(vma->vm_file);
74003 +
74004 + error = -EACCES;
74005 + goto out;
74006 + }
74007 +
74008 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74009 error = -EACCES;
74010 goto out;
74011 }
74012 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74013 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74014 if (error)
74015 goto out;
74016 +
74017 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74018 +
74019 nstart = tmp;
74020
74021 if (nstart < prev->vm_end)
74022 diff -urNp linux-2.6.39.1/mm/mremap.c linux-2.6.39.1/mm/mremap.c
74023 --- linux-2.6.39.1/mm/mremap.c 2011-05-19 00:06:34.000000000 -0400
74024 +++ linux-2.6.39.1/mm/mremap.c 2011-05-22 19:36:33.000000000 -0400
74025 @@ -114,6 +114,12 @@ static void move_ptes(struct vm_area_str
74026 continue;
74027 pte = ptep_clear_flush(vma, old_addr, old_pte);
74028 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74029 +
74030 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74031 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74032 + pte = pte_exprotect(pte);
74033 +#endif
74034 +
74035 set_pte_at(mm, new_addr, new_pte, pte);
74036 }
74037
74038 @@ -273,6 +279,11 @@ static struct vm_area_struct *vma_to_res
74039 if (is_vm_hugetlb_page(vma))
74040 goto Einval;
74041
74042 +#ifdef CONFIG_PAX_SEGMEXEC
74043 + if (pax_find_mirror_vma(vma))
74044 + goto Einval;
74045 +#endif
74046 +
74047 /* We can't remap across vm area boundaries */
74048 if (old_len > vma->vm_end - addr)
74049 goto Efault;
74050 @@ -329,20 +340,25 @@ static unsigned long mremap_to(unsigned
74051 unsigned long ret = -EINVAL;
74052 unsigned long charged = 0;
74053 unsigned long map_flags;
74054 + unsigned long pax_task_size = TASK_SIZE;
74055
74056 if (new_addr & ~PAGE_MASK)
74057 goto out;
74058
74059 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74060 +#ifdef CONFIG_PAX_SEGMEXEC
74061 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74062 + pax_task_size = SEGMEXEC_TASK_SIZE;
74063 +#endif
74064 +
74065 + pax_task_size -= PAGE_SIZE;
74066 +
74067 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74068 goto out;
74069
74070 /* Check if the location we're moving into overlaps the
74071 * old location at all, and fail if it does.
74072 */
74073 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74074 - goto out;
74075 -
74076 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74077 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74078 goto out;
74079
74080 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74081 @@ -414,6 +430,7 @@ unsigned long do_mremap(unsigned long ad
74082 struct vm_area_struct *vma;
74083 unsigned long ret = -EINVAL;
74084 unsigned long charged = 0;
74085 + unsigned long pax_task_size = TASK_SIZE;
74086
74087 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
74088 goto out;
74089 @@ -432,6 +449,17 @@ unsigned long do_mremap(unsigned long ad
74090 if (!new_len)
74091 goto out;
74092
74093 +#ifdef CONFIG_PAX_SEGMEXEC
74094 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74095 + pax_task_size = SEGMEXEC_TASK_SIZE;
74096 +#endif
74097 +
74098 + pax_task_size -= PAGE_SIZE;
74099 +
74100 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74101 + old_len > pax_task_size || addr > pax_task_size-old_len)
74102 + goto out;
74103 +
74104 if (flags & MREMAP_FIXED) {
74105 if (flags & MREMAP_MAYMOVE)
74106 ret = mremap_to(addr, old_len, new_addr, new_len);
74107 @@ -481,6 +509,7 @@ unsigned long do_mremap(unsigned long ad
74108 addr + new_len);
74109 }
74110 ret = addr;
74111 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74112 goto out;
74113 }
74114 }
74115 @@ -507,7 +536,13 @@ unsigned long do_mremap(unsigned long ad
74116 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74117 if (ret)
74118 goto out;
74119 +
74120 + map_flags = vma->vm_flags;
74121 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74122 + if (!(ret & ~PAGE_MASK)) {
74123 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74124 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74125 + }
74126 }
74127 out:
74128 if (ret & ~PAGE_MASK)
74129 diff -urNp linux-2.6.39.1/mm/nobootmem.c linux-2.6.39.1/mm/nobootmem.c
74130 --- linux-2.6.39.1/mm/nobootmem.c 2011-05-19 00:06:34.000000000 -0400
74131 +++ linux-2.6.39.1/mm/nobootmem.c 2011-05-22 19:36:33.000000000 -0400
74132 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
74133 unsigned long __init free_all_memory_core_early(int nodeid)
74134 {
74135 int i;
74136 - u64 start, end;
74137 + u64 start, end, startrange, endrange;
74138 unsigned long count = 0;
74139 - struct range *range = NULL;
74140 + struct range *range = NULL, rangerange = { 0, 0 };
74141 int nr_range;
74142
74143 nr_range = get_free_all_memory_range(&range, nodeid);
74144 + startrange = __pa(range) >> PAGE_SHIFT;
74145 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
74146
74147 for (i = 0; i < nr_range; i++) {
74148 start = range[i].start;
74149 end = range[i].end;
74150 + if (start <= endrange && startrange < end) {
74151 + BUG_ON(rangerange.start | rangerange.end);
74152 + rangerange = range[i];
74153 + continue;
74154 + }
74155 count += end - start;
74156 __free_pages_memory(start, end);
74157 }
74158 + start = rangerange.start;
74159 + end = rangerange.end;
74160 + count += end - start;
74161 + __free_pages_memory(start, end);
74162
74163 return count;
74164 }
74165 diff -urNp linux-2.6.39.1/mm/nommu.c linux-2.6.39.1/mm/nommu.c
74166 --- linux-2.6.39.1/mm/nommu.c 2011-05-19 00:06:34.000000000 -0400
74167 +++ linux-2.6.39.1/mm/nommu.c 2011-05-22 19:36:33.000000000 -0400
74168 @@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
74169 int sysctl_overcommit_ratio = 50; /* default is 50% */
74170 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74171 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74172 -int heap_stack_gap = 0;
74173
74174 atomic_long_t mmap_pages_allocated;
74175
74176 @@ -833,15 +832,6 @@ struct vm_area_struct *find_vma(struct m
74177 EXPORT_SYMBOL(find_vma);
74178
74179 /*
74180 - * find a VMA
74181 - * - we don't extend stack VMAs under NOMMU conditions
74182 - */
74183 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74184 -{
74185 - return find_vma(mm, addr);
74186 -}
74187 -
74188 -/*
74189 * expand a stack to a given address
74190 * - not supported under NOMMU conditions
74191 */
74192 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, stru
74193
74194 /* most fields are the same, copy all, and then fixup */
74195 *new = *vma;
74196 + INIT_LIST_HEAD(&new->anon_vma_chain);
74197 *region = *vma->vm_region;
74198 new->vm_region = region;
74199
74200 diff -urNp linux-2.6.39.1/mm/page_alloc.c linux-2.6.39.1/mm/page_alloc.c
74201 --- linux-2.6.39.1/mm/page_alloc.c 2011-06-03 00:04:14.000000000 -0400
74202 +++ linux-2.6.39.1/mm/page_alloc.c 2011-06-03 00:32:08.000000000 -0400
74203 @@ -650,6 +650,10 @@ static bool free_pages_prepare(struct pa
74204 int i;
74205 int bad = 0;
74206
74207 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74208 + unsigned long index = 1UL << order;
74209 +#endif
74210 +
74211 trace_mm_page_free_direct(page, order);
74212 kmemcheck_free_shadow(page, order);
74213
74214 @@ -665,6 +669,12 @@ static bool free_pages_prepare(struct pa
74215 debug_check_no_obj_freed(page_address(page),
74216 PAGE_SIZE << order);
74217 }
74218 +
74219 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74220 + for (; index; --index)
74221 + sanitize_highpage(page + index - 1);
74222 +#endif
74223 +
74224 arch_free_page(page, order);
74225 kernel_map_pages(page, 1 << order, 0);
74226
74227 @@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
74228 arch_alloc_page(page, order);
74229 kernel_map_pages(page, 1 << order, 1);
74230
74231 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74232 if (gfp_flags & __GFP_ZERO)
74233 prep_zero_page(page, order, gfp_flags);
74234 +#endif
74235
74236 if (order && (gfp_flags & __GFP_COMP))
74237 prep_compound_page(page, order);
74238 @@ -2504,6 +2516,8 @@ void __show_free_areas(unsigned int filt
74239 int cpu;
74240 struct zone *zone;
74241
74242 + pax_track_stack();
74243 +
74244 for_each_populated_zone(zone) {
74245 if (skip_free_areas_zone(filter, zone))
74246 continue;
74247 diff -urNp linux-2.6.39.1/mm/percpu.c linux-2.6.39.1/mm/percpu.c
74248 --- linux-2.6.39.1/mm/percpu.c 2011-05-19 00:06:34.000000000 -0400
74249 +++ linux-2.6.39.1/mm/percpu.c 2011-05-22 19:36:33.000000000 -0400
74250 @@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
74251 static unsigned int pcpu_last_unit_cpu __read_mostly;
74252
74253 /* the address of the first chunk which starts with the kernel static area */
74254 -void *pcpu_base_addr __read_mostly;
74255 +void *pcpu_base_addr __read_only;
74256 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74257
74258 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74259 diff -urNp linux-2.6.39.1/mm/rmap.c linux-2.6.39.1/mm/rmap.c
74260 --- linux-2.6.39.1/mm/rmap.c 2011-05-19 00:06:34.000000000 -0400
74261 +++ linux-2.6.39.1/mm/rmap.c 2011-05-22 19:36:33.000000000 -0400
74262 @@ -131,6 +131,10 @@ int anon_vma_prepare(struct vm_area_stru
74263 struct anon_vma *anon_vma = vma->anon_vma;
74264 struct anon_vma_chain *avc;
74265
74266 +#ifdef CONFIG_PAX_SEGMEXEC
74267 + struct anon_vma_chain *avc_m = NULL;
74268 +#endif
74269 +
74270 might_sleep();
74271 if (unlikely(!anon_vma)) {
74272 struct mm_struct *mm = vma->vm_mm;
74273 @@ -140,6 +144,12 @@ int anon_vma_prepare(struct vm_area_stru
74274 if (!avc)
74275 goto out_enomem;
74276
74277 +#ifdef CONFIG_PAX_SEGMEXEC
74278 + avc_m = anon_vma_chain_alloc();
74279 + if (!avc_m)
74280 + goto out_enomem_free_avc;
74281 +#endif
74282 +
74283 anon_vma = find_mergeable_anon_vma(vma);
74284 allocated = NULL;
74285 if (!anon_vma) {
74286 @@ -153,6 +163,21 @@ int anon_vma_prepare(struct vm_area_stru
74287 /* page_table_lock to protect against threads */
74288 spin_lock(&mm->page_table_lock);
74289 if (likely(!vma->anon_vma)) {
74290 +
74291 +#ifdef CONFIG_PAX_SEGMEXEC
74292 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74293 +
74294 + if (vma_m) {
74295 + BUG_ON(vma_m->anon_vma);
74296 + vma_m->anon_vma = anon_vma;
74297 + avc_m->anon_vma = anon_vma;
74298 + avc_m->vma = vma;
74299 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
74300 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
74301 + avc_m = NULL;
74302 + }
74303 +#endif
74304 +
74305 vma->anon_vma = anon_vma;
74306 avc->anon_vma = anon_vma;
74307 avc->vma = vma;
74308 @@ -166,12 +191,24 @@ int anon_vma_prepare(struct vm_area_stru
74309
74310 if (unlikely(allocated))
74311 put_anon_vma(allocated);
74312 +
74313 +#ifdef CONFIG_PAX_SEGMEXEC
74314 + if (unlikely(avc_m))
74315 + anon_vma_chain_free(avc_m);
74316 +#endif
74317 +
74318 if (unlikely(avc))
74319 anon_vma_chain_free(avc);
74320 }
74321 return 0;
74322
74323 out_enomem_free_avc:
74324 +
74325 +#ifdef CONFIG_PAX_SEGMEXEC
74326 + if (avc_m)
74327 + anon_vma_chain_free(avc_m);
74328 +#endif
74329 +
74330 anon_vma_chain_free(avc);
74331 out_enomem:
74332 return -ENOMEM;
74333 @@ -198,7 +235,7 @@ static void anon_vma_chain_link(struct v
74334 * Attach the anon_vmas from src to dst.
74335 * Returns 0 on success, -ENOMEM on failure.
74336 */
74337 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74338 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74339 {
74340 struct anon_vma_chain *avc, *pavc;
74341
74342 @@ -220,7 +257,7 @@ int anon_vma_clone(struct vm_area_struct
74343 * the corresponding VMA in the parent process is attached to.
74344 * Returns 0 on success, non-zero on failure.
74345 */
74346 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74347 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74348 {
74349 struct anon_vma_chain *avc;
74350 struct anon_vma *anon_vma;
74351 diff -urNp linux-2.6.39.1/mm/shmem.c linux-2.6.39.1/mm/shmem.c
74352 --- linux-2.6.39.1/mm/shmem.c 2011-06-03 00:04:14.000000000 -0400
74353 +++ linux-2.6.39.1/mm/shmem.c 2011-06-03 00:32:08.000000000 -0400
74354 @@ -31,7 +31,7 @@
74355 #include <linux/percpu_counter.h>
74356 #include <linux/swap.h>
74357
74358 -static struct vfsmount *shm_mnt;
74359 +struct vfsmount *shm_mnt;
74360
74361 #ifdef CONFIG_SHMEM
74362 /*
74363 @@ -1087,6 +1087,8 @@ static int shmem_writepage(struct page *
74364 goto unlock;
74365 }
74366 entry = shmem_swp_entry(info, index, NULL);
74367 + if (!entry)
74368 + goto unlock;
74369 if (entry->val) {
74370 /*
74371 * The more uptodate page coming down from a stacked
74372 @@ -1158,6 +1160,8 @@ static struct page *shmem_swapin(swp_ent
74373 struct vm_area_struct pvma;
74374 struct page *page;
74375
74376 + pax_track_stack();
74377 +
74378 spol = mpol_cond_copy(&mpol,
74379 mpol_shared_policy_lookup(&info->policy, idx));
74380
74381 @@ -2014,7 +2018,7 @@ static int shmem_symlink(struct inode *d
74382
74383 info = SHMEM_I(inode);
74384 inode->i_size = len-1;
74385 - if (len <= (char *)inode - (char *)info) {
74386 + if (len <= (char *)inode - (char *)info && len <= 64) {
74387 /* do it inline */
74388 memcpy(info, symname, len);
74389 inode->i_op = &shmem_symlink_inline_operations;
74390 @@ -2362,8 +2366,7 @@ int shmem_fill_super(struct super_block
74391 int err = -ENOMEM;
74392
74393 /* Round up to L1_CACHE_BYTES to resist false sharing */
74394 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74395 - L1_CACHE_BYTES), GFP_KERNEL);
74396 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74397 if (!sbinfo)
74398 return -ENOMEM;
74399
74400 diff -urNp linux-2.6.39.1/mm/slab.c linux-2.6.39.1/mm/slab.c
74401 --- linux-2.6.39.1/mm/slab.c 2011-05-19 00:06:34.000000000 -0400
74402 +++ linux-2.6.39.1/mm/slab.c 2011-05-22 19:41:42.000000000 -0400
74403 @@ -150,7 +150,7 @@
74404
74405 /* Legal flag mask for kmem_cache_create(). */
74406 #if DEBUG
74407 -# define CREATE_MASK (SLAB_RED_ZONE | \
74408 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74409 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74410 SLAB_CACHE_DMA | \
74411 SLAB_STORE_USER | \
74412 @@ -158,7 +158,7 @@
74413 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74414 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74415 #else
74416 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74417 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74418 SLAB_CACHE_DMA | \
74419 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74420 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74421 @@ -287,7 +287,7 @@ struct kmem_list3 {
74422 * Need this for bootstrapping a per node allocator.
74423 */
74424 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74425 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74426 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74427 #define CACHE_CACHE 0
74428 #define SIZE_AC MAX_NUMNODES
74429 #define SIZE_L3 (2 * MAX_NUMNODES)
74430 @@ -388,10 +388,10 @@ static void kmem_list3_init(struct kmem_
74431 if ((x)->max_freeable < i) \
74432 (x)->max_freeable = i; \
74433 } while (0)
74434 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74435 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74436 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74437 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74438 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74439 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74440 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74441 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74442 #else
74443 #define STATS_INC_ACTIVE(x) do { } while (0)
74444 #define STATS_DEC_ACTIVE(x) do { } while (0)
74445 @@ -537,7 +537,7 @@ static inline void *index_to_obj(struct
74446 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74447 */
74448 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74449 - const struct slab *slab, void *obj)
74450 + const struct slab *slab, const void *obj)
74451 {
74452 u32 offset = (obj - slab->s_mem);
74453 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74454 @@ -563,7 +563,7 @@ struct cache_names {
74455 static struct cache_names __initdata cache_names[] = {
74456 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74457 #include <linux/kmalloc_sizes.h>
74458 - {NULL,}
74459 + {NULL}
74460 #undef CACHE
74461 };
74462
74463 @@ -1529,7 +1529,7 @@ void __init kmem_cache_init(void)
74464 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74465 sizes[INDEX_AC].cs_size,
74466 ARCH_KMALLOC_MINALIGN,
74467 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74468 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74469 NULL);
74470
74471 if (INDEX_AC != INDEX_L3) {
74472 @@ -1537,7 +1537,7 @@ void __init kmem_cache_init(void)
74473 kmem_cache_create(names[INDEX_L3].name,
74474 sizes[INDEX_L3].cs_size,
74475 ARCH_KMALLOC_MINALIGN,
74476 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74477 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74478 NULL);
74479 }
74480
74481 @@ -1555,7 +1555,7 @@ void __init kmem_cache_init(void)
74482 sizes->cs_cachep = kmem_cache_create(names->name,
74483 sizes->cs_size,
74484 ARCH_KMALLOC_MINALIGN,
74485 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74486 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74487 NULL);
74488 }
74489 #ifdef CONFIG_ZONE_DMA
74490 @@ -4270,10 +4270,10 @@ static int s_show(struct seq_file *m, vo
74491 }
74492 /* cpu stats */
74493 {
74494 - unsigned long allochit = atomic_read(&cachep->allochit);
74495 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74496 - unsigned long freehit = atomic_read(&cachep->freehit);
74497 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74498 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74499 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74500 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74501 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74502
74503 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74504 allochit, allocmiss, freehit, freemiss);
74505 @@ -4530,15 +4530,66 @@ static const struct file_operations proc
74506
74507 static int __init slab_proc_init(void)
74508 {
74509 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
74510 + mode_t gr_mode = S_IRUGO;
74511 +
74512 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74513 + gr_mode = S_IRUSR;
74514 +#endif
74515 +
74516 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
74517 #ifdef CONFIG_DEBUG_SLAB_LEAK
74518 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74519 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
74520 #endif
74521 return 0;
74522 }
74523 module_init(slab_proc_init);
74524 #endif
74525
74526 +void check_object_size(const void *ptr, unsigned long n, bool to)
74527 +{
74528 +
74529 +#ifdef CONFIG_PAX_USERCOPY
74530 + struct page *page;
74531 + struct kmem_cache *cachep = NULL;
74532 + struct slab *slabp;
74533 + unsigned int objnr;
74534 + unsigned long offset;
74535 +
74536 + if (!n)
74537 + return;
74538 +
74539 + if (ZERO_OR_NULL_PTR(ptr))
74540 + goto report;
74541 +
74542 + if (!virt_addr_valid(ptr))
74543 + return;
74544 +
74545 + page = virt_to_head_page(ptr);
74546 +
74547 + if (!PageSlab(page)) {
74548 + if (object_is_on_stack(ptr, n) == -1)
74549 + goto report;
74550 + return;
74551 + }
74552 +
74553 + cachep = page_get_cache(page);
74554 + if (!(cachep->flags & SLAB_USERCOPY))
74555 + goto report;
74556 +
74557 + slabp = page_get_slab(page);
74558 + objnr = obj_to_index(cachep, slabp, ptr);
74559 + BUG_ON(objnr >= cachep->num);
74560 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74561 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74562 + return;
74563 +
74564 +report:
74565 + pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
74566 +#endif
74567 +
74568 +}
74569 +EXPORT_SYMBOL(check_object_size);
74570 +
74571 /**
74572 * ksize - get the actual amount of memory allocated for a given object
74573 * @objp: Pointer to the object
74574 diff -urNp linux-2.6.39.1/mm/slob.c linux-2.6.39.1/mm/slob.c
74575 --- linux-2.6.39.1/mm/slob.c 2011-05-19 00:06:34.000000000 -0400
74576 +++ linux-2.6.39.1/mm/slob.c 2011-05-22 19:36:33.000000000 -0400
74577 @@ -29,7 +29,7 @@
74578 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74579 * alloc_pages() directly, allocating compound pages so the page order
74580 * does not have to be separately tracked, and also stores the exact
74581 - * allocation size in page->private so that it can be used to accurately
74582 + * allocation size in slob_page->size so that it can be used to accurately
74583 * provide ksize(). These objects are detected in kfree() because slob_page()
74584 * is false for them.
74585 *
74586 @@ -58,6 +58,7 @@
74587 */
74588
74589 #include <linux/kernel.h>
74590 +#include <linux/sched.h>
74591 #include <linux/slab.h>
74592 #include <linux/mm.h>
74593 #include <linux/swap.h> /* struct reclaim_state */
74594 @@ -102,7 +103,8 @@ struct slob_page {
74595 unsigned long flags; /* mandatory */
74596 atomic_t _count; /* mandatory */
74597 slobidx_t units; /* free units left in page */
74598 - unsigned long pad[2];
74599 + unsigned long pad[1];
74600 + unsigned long size; /* size when >=PAGE_SIZE */
74601 slob_t *free; /* first free slob_t in page */
74602 struct list_head list; /* linked list of free pages */
74603 };
74604 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74605 */
74606 static inline int is_slob_page(struct slob_page *sp)
74607 {
74608 - return PageSlab((struct page *)sp);
74609 + return PageSlab((struct page *)sp) && !sp->size;
74610 }
74611
74612 static inline void set_slob_page(struct slob_page *sp)
74613 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
74614
74615 static inline struct slob_page *slob_page(const void *addr)
74616 {
74617 - return (struct slob_page *)virt_to_page(addr);
74618 + return (struct slob_page *)virt_to_head_page(addr);
74619 }
74620
74621 /*
74622 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
74623 /*
74624 * Return the size of a slob block.
74625 */
74626 -static slobidx_t slob_units(slob_t *s)
74627 +static slobidx_t slob_units(const slob_t *s)
74628 {
74629 if (s->units > 0)
74630 return s->units;
74631 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74632 /*
74633 * Return the next free slob block pointer after this one.
74634 */
74635 -static slob_t *slob_next(slob_t *s)
74636 +static slob_t *slob_next(const slob_t *s)
74637 {
74638 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74639 slobidx_t next;
74640 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74641 /*
74642 * Returns true if s is the last free block in its page.
74643 */
74644 -static int slob_last(slob_t *s)
74645 +static int slob_last(const slob_t *s)
74646 {
74647 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74648 }
74649 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
74650 if (!page)
74651 return NULL;
74652
74653 + set_slob_page(page);
74654 return page_address(page);
74655 }
74656
74657 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
74658 if (!b)
74659 return NULL;
74660 sp = slob_page(b);
74661 - set_slob_page(sp);
74662
74663 spin_lock_irqsave(&slob_lock, flags);
74664 sp->units = SLOB_UNITS(PAGE_SIZE);
74665 sp->free = b;
74666 + sp->size = 0;
74667 INIT_LIST_HEAD(&sp->list);
74668 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74669 set_slob_page_free(sp, slob_list);
74670 @@ -476,10 +479,9 @@ out:
74671 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74672 */
74673
74674 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74675 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74676 {
74677 - unsigned int *m;
74678 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74679 + slob_t *m;
74680 void *ret;
74681
74682 lockdep_trace_alloc(gfp);
74683 @@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
74684
74685 if (!m)
74686 return NULL;
74687 - *m = size;
74688 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74689 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74690 + m[0].units = size;
74691 + m[1].units = align;
74692 ret = (void *)m + align;
74693
74694 trace_kmalloc_node(_RET_IP_, ret,
74695 @@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
74696 gfp |= __GFP_COMP;
74697 ret = slob_new_pages(gfp, order, node);
74698 if (ret) {
74699 - struct page *page;
74700 - page = virt_to_page(ret);
74701 - page->private = size;
74702 + struct slob_page *sp;
74703 + sp = slob_page(ret);
74704 + sp->size = size;
74705 }
74706
74707 trace_kmalloc_node(_RET_IP_, ret,
74708 @@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
74709 kmemleak_alloc(ret, size, 1, gfp);
74710 return ret;
74711 }
74712 +
74713 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74714 +{
74715 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74716 +
74717 + return __kmalloc_node_align(size, gfp, node, align);
74718 +}
74719 EXPORT_SYMBOL(__kmalloc_node);
74720
74721 void kfree(const void *block)
74722 @@ -531,13 +543,81 @@ void kfree(const void *block)
74723 sp = slob_page(block);
74724 if (is_slob_page(sp)) {
74725 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74726 - unsigned int *m = (unsigned int *)(block - align);
74727 - slob_free(m, *m + align);
74728 - } else
74729 + slob_t *m = (slob_t *)(block - align);
74730 + slob_free(m, m[0].units + align);
74731 + } else {
74732 + clear_slob_page(sp);
74733 + free_slob_page(sp);
74734 + sp->size = 0;
74735 put_page(&sp->page);
74736 + }
74737 }
74738 EXPORT_SYMBOL(kfree);
74739
74740 +void check_object_size(const void *ptr, unsigned long n, bool to)
74741 +{
74742 +
74743 +#ifdef CONFIG_PAX_USERCOPY
74744 + struct slob_page *sp;
74745 + const slob_t *free;
74746 + const void *base;
74747 +
74748 + if (!n)
74749 + return;
74750 +
74751 + if (ZERO_OR_NULL_PTR(ptr))
74752 + goto report;
74753 +
74754 + if (!virt_addr_valid(ptr))
74755 + return;
74756 +
74757 + sp = slob_page(ptr);
74758 + if (!PageSlab((struct page*)sp)) {
74759 + if (object_is_on_stack(ptr, n) == -1)
74760 + goto report;
74761 + return;
74762 + }
74763 +
74764 + if (sp->size) {
74765 + base = page_address(&sp->page);
74766 + if (base <= ptr && n <= sp->size - (ptr - base))
74767 + return;
74768 + goto report;
74769 + }
74770 +
74771 + /* some tricky double walking to find the chunk */
74772 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74773 + free = sp->free;
74774 +
74775 + while (!slob_last(free) && (void *)free <= ptr) {
74776 + base = free + slob_units(free);
74777 + free = slob_next(free);
74778 + }
74779 +
74780 + while (base < (void *)free) {
74781 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74782 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74783 + int offset;
74784 +
74785 + if (ptr < base + align)
74786 + goto report;
74787 +
74788 + offset = ptr - base - align;
74789 + if (offset < m) {
74790 + if (n <= m - offset)
74791 + return;
74792 + goto report;
74793 + }
74794 + base += size;
74795 + }
74796 +
74797 +report:
74798 + pax_report_usercopy(ptr, n, to, NULL);
74799 +#endif
74800 +
74801 +}
74802 +EXPORT_SYMBOL(check_object_size);
74803 +
74804 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74805 size_t ksize(const void *block)
74806 {
74807 @@ -550,10 +630,10 @@ size_t ksize(const void *block)
74808 sp = slob_page(block);
74809 if (is_slob_page(sp)) {
74810 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74811 - unsigned int *m = (unsigned int *)(block - align);
74812 - return SLOB_UNITS(*m) * SLOB_UNIT;
74813 + slob_t *m = (slob_t *)(block - align);
74814 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74815 } else
74816 - return sp->page.private;
74817 + return sp->size;
74818 }
74819 EXPORT_SYMBOL(ksize);
74820
74821 @@ -608,17 +688,25 @@ void *kmem_cache_alloc_node(struct kmem_
74822 {
74823 void *b;
74824
74825 +#ifdef CONFIG_PAX_USERCOPY
74826 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74827 +#else
74828 if (c->size < PAGE_SIZE) {
74829 b = slob_alloc(c->size, flags, c->align, node);
74830 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74831 SLOB_UNITS(c->size) * SLOB_UNIT,
74832 flags, node);
74833 } else {
74834 + struct slob_page *sp;
74835 +
74836 b = slob_new_pages(flags, get_order(c->size), node);
74837 + sp = slob_page(b);
74838 + sp->size = c->size;
74839 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74840 PAGE_SIZE << get_order(c->size),
74841 flags, node);
74842 }
74843 +#endif
74844
74845 if (c->ctor)
74846 c->ctor(b);
74847 @@ -630,10 +718,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74848
74849 static void __kmem_cache_free(void *b, int size)
74850 {
74851 - if (size < PAGE_SIZE)
74852 + struct slob_page *sp = slob_page(b);
74853 +
74854 + if (is_slob_page(sp))
74855 slob_free(b, size);
74856 - else
74857 + else {
74858 + clear_slob_page(sp);
74859 + free_slob_page(sp);
74860 + sp->size = 0;
74861 slob_free_pages(b, get_order(size));
74862 + }
74863 }
74864
74865 static void kmem_rcu_free(struct rcu_head *head)
74866 @@ -646,14 +740,23 @@ static void kmem_rcu_free(struct rcu_hea
74867
74868 void kmem_cache_free(struct kmem_cache *c, void *b)
74869 {
74870 + int size = c->size;
74871 +
74872 +#ifdef CONFIG_PAX_USERCOPY
74873 + if (size + c->align < PAGE_SIZE) {
74874 + size += c->align;
74875 + b -= c->align;
74876 + }
74877 +#endif
74878 +
74879 kmemleak_free_recursive(b, c->flags);
74880 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74881 struct slob_rcu *slob_rcu;
74882 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74883 - slob_rcu->size = c->size;
74884 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74885 + slob_rcu->size = size;
74886 call_rcu(&slob_rcu->head, kmem_rcu_free);
74887 } else {
74888 - __kmem_cache_free(b, c->size);
74889 + __kmem_cache_free(b, size);
74890 }
74891
74892 trace_kmem_cache_free(_RET_IP_, b);
74893 diff -urNp linux-2.6.39.1/mm/slub.c linux-2.6.39.1/mm/slub.c
74894 --- linux-2.6.39.1/mm/slub.c 2011-06-03 00:04:14.000000000 -0400
74895 +++ linux-2.6.39.1/mm/slub.c 2011-06-03 00:32:08.000000000 -0400
74896 @@ -431,7 +431,7 @@ static void print_track(const char *s, s
74897 if (!t->addr)
74898 return;
74899
74900 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74901 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74902 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74903 }
74904
74905 @@ -2183,6 +2183,8 @@ void kmem_cache_free(struct kmem_cache *
74906
74907 page = virt_to_head_page(x);
74908
74909 + BUG_ON(!PageSlab(page));
74910 +
74911 slab_free(s, page, x, _RET_IP_);
74912
74913 trace_kmem_cache_free(_RET_IP_, x);
74914 @@ -2216,7 +2218,7 @@ static int slub_min_objects;
74915 * Merge control. If this is set then no merging of slab caches will occur.
74916 * (Could be removed. This was introduced to pacify the merge skeptics.)
74917 */
74918 -static int slub_nomerge;
74919 +static int slub_nomerge = 1;
74920
74921 /*
74922 * Calculate the order of allocation given an slab object size.
74923 @@ -2644,7 +2646,7 @@ static int kmem_cache_open(struct kmem_c
74924 * list to avoid pounding the page allocator excessively.
74925 */
74926 set_min_partial(s, ilog2(s->size));
74927 - s->refcount = 1;
74928 + atomic_set(&s->refcount, 1);
74929 #ifdef CONFIG_NUMA
74930 s->remote_node_defrag_ratio = 1000;
74931 #endif
74932 @@ -2750,8 +2752,7 @@ static inline int kmem_cache_close(struc
74933 void kmem_cache_destroy(struct kmem_cache *s)
74934 {
74935 down_write(&slub_lock);
74936 - s->refcount--;
74937 - if (!s->refcount) {
74938 + if (atomic_dec_and_test(&s->refcount)) {
74939 list_del(&s->list);
74940 if (kmem_cache_close(s)) {
74941 printk(KERN_ERR "SLUB %s: %s called for cache that "
74942 @@ -2961,6 +2962,46 @@ void *__kmalloc_node(size_t size, gfp_t
74943 EXPORT_SYMBOL(__kmalloc_node);
74944 #endif
74945
74946 +void check_object_size(const void *ptr, unsigned long n, bool to)
74947 +{
74948 +
74949 +#ifdef CONFIG_PAX_USERCOPY
74950 + struct page *page;
74951 + struct kmem_cache *s = NULL;
74952 + unsigned long offset;
74953 +
74954 + if (!n)
74955 + return;
74956 +
74957 + if (ZERO_OR_NULL_PTR(ptr))
74958 + goto report;
74959 +
74960 + if (!virt_addr_valid(ptr))
74961 + return;
74962 +
74963 + page = virt_to_head_page(ptr);
74964 +
74965 + if (!PageSlab(page)) {
74966 + if (object_is_on_stack(ptr, n) == -1)
74967 + goto report;
74968 + return;
74969 + }
74970 +
74971 + s = page->slab;
74972 + if (!(s->flags & SLAB_USERCOPY))
74973 + goto report;
74974 +
74975 + offset = (ptr - page_address(page)) % s->size;
74976 + if (offset <= s->objsize && n <= s->objsize - offset)
74977 + return;
74978 +
74979 +report:
74980 + pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
74981 +#endif
74982 +
74983 +}
74984 +EXPORT_SYMBOL(check_object_size);
74985 +
74986 size_t ksize(const void *object)
74987 {
74988 struct page *page;
74989 @@ -3205,7 +3246,7 @@ static void __init kmem_cache_bootstrap_
74990 int node;
74991
74992 list_add(&s->list, &slab_caches);
74993 - s->refcount = -1;
74994 + atomic_set(&s->refcount, -1);
74995
74996 for_each_node_state(node, N_NORMAL_MEMORY) {
74997 struct kmem_cache_node *n = get_node(s, node);
74998 @@ -3322,17 +3363,17 @@ void __init kmem_cache_init(void)
74999
75000 /* Caches that are not of the two-to-the-power-of size */
75001 if (KMALLOC_MIN_SIZE <= 32) {
75002 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75003 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75004 caches++;
75005 }
75006
75007 if (KMALLOC_MIN_SIZE <= 64) {
75008 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75009 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75010 caches++;
75011 }
75012
75013 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75014 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75015 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75016 caches++;
75017 }
75018
75019 @@ -3400,7 +3441,7 @@ static int slab_unmergeable(struct kmem_
75020 /*
75021 * We may have set a slab to be unmergeable during bootstrap.
75022 */
75023 - if (s->refcount < 0)
75024 + if (atomic_read(&s->refcount) < 0)
75025 return 1;
75026
75027 return 0;
75028 @@ -3459,7 +3500,7 @@ struct kmem_cache *kmem_cache_create(con
75029 down_write(&slub_lock);
75030 s = find_mergeable(size, align, flags, name, ctor);
75031 if (s) {
75032 - s->refcount++;
75033 + atomic_inc(&s->refcount);
75034 /*
75035 * Adjust the object sizes so that we clear
75036 * the complete object on kzalloc.
75037 @@ -3468,7 +3509,7 @@ struct kmem_cache *kmem_cache_create(con
75038 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75039
75040 if (sysfs_slab_alias(s, name)) {
75041 - s->refcount--;
75042 + atomic_dec(&s->refcount);
75043 goto err;
75044 }
75045 up_write(&slub_lock);
75046 @@ -4201,7 +4242,7 @@ SLAB_ATTR_RO(ctor);
75047
75048 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75049 {
75050 - return sprintf(buf, "%d\n", s->refcount - 1);
75051 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75052 }
75053 SLAB_ATTR_RO(aliases);
75054
75055 @@ -4945,7 +4986,13 @@ static const struct file_operations proc
75056
75057 static int __init slab_proc_init(void)
75058 {
75059 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
75060 + mode_t gr_mode = S_IRUGO;
75061 +
75062 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75063 + gr_mode = S_IRUSR;
75064 +#endif
75065 +
75066 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
75067 return 0;
75068 }
75069 module_init(slab_proc_init);
75070 diff -urNp linux-2.6.39.1/mm/swapfile.c linux-2.6.39.1/mm/swapfile.c
75071 --- linux-2.6.39.1/mm/swapfile.c 2011-05-19 00:06:34.000000000 -0400
75072 +++ linux-2.6.39.1/mm/swapfile.c 2011-05-22 19:36:33.000000000 -0400
75073 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
75074
75075 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75076 /* Activity counter to indicate that a swapon or swapoff has occurred */
75077 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75078 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75079
75080 static inline unsigned char swap_count(unsigned char ent)
75081 {
75082 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
75083 }
75084 filp_close(swap_file, NULL);
75085 err = 0;
75086 - atomic_inc(&proc_poll_event);
75087 + atomic_inc_unchecked(&proc_poll_event);
75088 wake_up_interruptible(&proc_poll_wait);
75089
75090 out_dput:
75091 @@ -1690,8 +1690,8 @@ static unsigned swaps_poll(struct file *
75092
75093 poll_wait(file, &proc_poll_wait, wait);
75094
75095 - if (s->event != atomic_read(&proc_poll_event)) {
75096 - s->event = atomic_read(&proc_poll_event);
75097 + if (s->event != atomic_read_unchecked(&proc_poll_event)) {
75098 + s->event = atomic_read_unchecked(&proc_poll_event);
75099 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75100 }
75101
75102 @@ -1797,7 +1797,7 @@ static int swaps_open(struct inode *inod
75103 }
75104
75105 s->seq.private = s;
75106 - s->event = atomic_read(&proc_poll_event);
75107 + s->event = atomic_read_unchecked(&proc_poll_event);
75108 return ret;
75109 }
75110
75111 @@ -2131,7 +2131,7 @@ SYSCALL_DEFINE2(swapon, const char __use
75112 (p->flags & SWP_DISCARDABLE) ? "D" : "");
75113
75114 mutex_unlock(&swapon_mutex);
75115 - atomic_inc(&proc_poll_event);
75116 + atomic_inc_unchecked(&proc_poll_event);
75117 wake_up_interruptible(&proc_poll_wait);
75118
75119 if (S_ISREG(inode->i_mode))
75120 diff -urNp linux-2.6.39.1/mm/util.c linux-2.6.39.1/mm/util.c
75121 --- linux-2.6.39.1/mm/util.c 2011-05-19 00:06:34.000000000 -0400
75122 +++ linux-2.6.39.1/mm/util.c 2011-05-23 17:07:00.000000000 -0400
75123 @@ -112,6 +112,7 @@ EXPORT_SYMBOL(memdup_user);
75124 * allocated buffer. Use this if you don't want to free the buffer immediately
75125 * like, for example, with RCU.
75126 */
75127 +#undef __krealloc
75128 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
75129 {
75130 void *ret;
75131 @@ -145,6 +146,7 @@ EXPORT_SYMBOL(__krealloc);
75132 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
75133 * %NULL pointer, the object pointed to is freed.
75134 */
75135 +#undef krealloc
75136 void *krealloc(const void *p, size_t new_size, gfp_t flags)
75137 {
75138 void *ret;
75139 @@ -219,6 +221,12 @@ EXPORT_SYMBOL(strndup_user);
75140 void arch_pick_mmap_layout(struct mm_struct *mm)
75141 {
75142 mm->mmap_base = TASK_UNMAPPED_BASE;
75143 +
75144 +#ifdef CONFIG_PAX_RANDMMAP
75145 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75146 + mm->mmap_base += mm->delta_mmap;
75147 +#endif
75148 +
75149 mm->get_unmapped_area = arch_get_unmapped_area;
75150 mm->unmap_area = arch_unmap_area;
75151 }
75152 diff -urNp linux-2.6.39.1/mm/vmalloc.c linux-2.6.39.1/mm/vmalloc.c
75153 --- linux-2.6.39.1/mm/vmalloc.c 2011-05-19 00:06:34.000000000 -0400
75154 +++ linux-2.6.39.1/mm/vmalloc.c 2011-05-22 19:36:33.000000000 -0400
75155 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
75156
75157 pte = pte_offset_kernel(pmd, addr);
75158 do {
75159 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75160 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75161 +
75162 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75163 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75164 + BUG_ON(!pte_exec(*pte));
75165 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75166 + continue;
75167 + }
75168 +#endif
75169 +
75170 + {
75171 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75172 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75173 + }
75174 } while (pte++, addr += PAGE_SIZE, addr != end);
75175 }
75176
75177 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
75178 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75179 {
75180 pte_t *pte;
75181 + int ret = -ENOMEM;
75182
75183 /*
75184 * nr is a running index into the array which helps higher level
75185 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
75186 pte = pte_alloc_kernel(pmd, addr);
75187 if (!pte)
75188 return -ENOMEM;
75189 +
75190 + pax_open_kernel();
75191 do {
75192 struct page *page = pages[*nr];
75193
75194 - if (WARN_ON(!pte_none(*pte)))
75195 - return -EBUSY;
75196 - if (WARN_ON(!page))
75197 - return -ENOMEM;
75198 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75199 + if (pgprot_val(prot) & _PAGE_NX)
75200 +#endif
75201 +
75202 + if (WARN_ON(!pte_none(*pte))) {
75203 + ret = -EBUSY;
75204 + goto out;
75205 + }
75206 + if (WARN_ON(!page)) {
75207 + ret = -ENOMEM;
75208 + goto out;
75209 + }
75210 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75211 (*nr)++;
75212 } while (pte++, addr += PAGE_SIZE, addr != end);
75213 - return 0;
75214 + ret = 0;
75215 +out:
75216 + pax_close_kernel();
75217 + return ret;
75218 }
75219
75220 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75221 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
75222 * and fall back on vmalloc() if that fails. Others
75223 * just put it in the vmalloc space.
75224 */
75225 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75226 +#ifdef CONFIG_MODULES
75227 +#ifdef MODULES_VADDR
75228 unsigned long addr = (unsigned long)x;
75229 if (addr >= MODULES_VADDR && addr < MODULES_END)
75230 return 1;
75231 #endif
75232 +
75233 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75234 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75235 + return 1;
75236 +#endif
75237 +
75238 +#endif
75239 +
75240 return is_vmalloc_addr(x);
75241 }
75242
75243 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
75244
75245 if (!pgd_none(*pgd)) {
75246 pud_t *pud = pud_offset(pgd, addr);
75247 +#ifdef CONFIG_X86
75248 + if (!pud_large(*pud))
75249 +#endif
75250 if (!pud_none(*pud)) {
75251 pmd_t *pmd = pmd_offset(pud, addr);
75252 +#ifdef CONFIG_X86
75253 + if (!pmd_large(*pmd))
75254 +#endif
75255 if (!pmd_none(*pmd)) {
75256 pte_t *ptep, pte;
75257
75258 @@ -1296,6 +1336,16 @@ static struct vm_struct *__get_vm_area_n
75259 struct vm_struct *area;
75260
75261 BUG_ON(in_interrupt());
75262 +
75263 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75264 + if (flags & VM_KERNEXEC) {
75265 + if (start != VMALLOC_START || end != VMALLOC_END)
75266 + return NULL;
75267 + start = (unsigned long)MODULES_EXEC_VADDR;
75268 + end = (unsigned long)MODULES_EXEC_END;
75269 + }
75270 +#endif
75271 +
75272 if (flags & VM_IOREMAP) {
75273 int bit = fls(size);
75274
75275 @@ -1514,6 +1564,11 @@ void *vmap(struct page **pages, unsigned
75276 if (count > totalram_pages)
75277 return NULL;
75278
75279 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75280 + if (!(pgprot_val(prot) & _PAGE_NX))
75281 + flags |= VM_KERNEXEC;
75282 +#endif
75283 +
75284 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75285 __builtin_return_address(0));
75286 if (!area)
75287 @@ -1610,6 +1665,13 @@ void *__vmalloc_node_range(unsigned long
75288 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75289 return NULL;
75290
75291 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75292 + if (!(pgprot_val(prot) & _PAGE_NX))
75293 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
75294 + node, gfp_mask, caller);
75295 + else
75296 +#endif
75297 +
75298 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
75299 gfp_mask, caller);
75300
75301 @@ -1649,6 +1711,7 @@ static void *__vmalloc_node(unsigned lon
75302 gfp_mask, prot, node, caller);
75303 }
75304
75305 +#undef __vmalloc
75306 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
75307 {
75308 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
75309 @@ -1672,6 +1735,7 @@ static inline void *__vmalloc_node_flags
75310 * For tight control over page level allocator and protection flags
75311 * use __vmalloc() instead.
75312 */
75313 +#undef vmalloc
75314 void *vmalloc(unsigned long size)
75315 {
75316 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
75317 @@ -1688,6 +1752,7 @@ EXPORT_SYMBOL(vmalloc);
75318 * For tight control over page level allocator and protection flags
75319 * use __vmalloc() instead.
75320 */
75321 +#undef vzalloc
75322 void *vzalloc(unsigned long size)
75323 {
75324 return __vmalloc_node_flags(size, -1,
75325 @@ -1702,6 +1767,7 @@ EXPORT_SYMBOL(vzalloc);
75326 * The resulting memory area is zeroed so it can be mapped to userspace
75327 * without leaking data.
75328 */
75329 +#undef vmalloc_user
75330 void *vmalloc_user(unsigned long size)
75331 {
75332 struct vm_struct *area;
75333 @@ -1729,6 +1795,7 @@ EXPORT_SYMBOL(vmalloc_user);
75334 * For tight control over page level allocator and protection flags
75335 * use __vmalloc() instead.
75336 */
75337 +#undef vmalloc_node
75338 void *vmalloc_node(unsigned long size, int node)
75339 {
75340 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75341 @@ -1748,6 +1815,7 @@ EXPORT_SYMBOL(vmalloc_node);
75342 * For tight control over page level allocator and protection flags
75343 * use __vmalloc_node() instead.
75344 */
75345 +#undef vzalloc_node
75346 void *vzalloc_node(unsigned long size, int node)
75347 {
75348 return __vmalloc_node_flags(size, node,
75349 @@ -1770,10 +1838,10 @@ EXPORT_SYMBOL(vzalloc_node);
75350 * For tight control over page level allocator and protection flags
75351 * use __vmalloc() instead.
75352 */
75353 -
75354 +#undef vmalloc_exec
75355 void *vmalloc_exec(unsigned long size)
75356 {
75357 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75358 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75359 -1, __builtin_return_address(0));
75360 }
75361
75362 @@ -1792,6 +1860,7 @@ void *vmalloc_exec(unsigned long size)
75363 * Allocate enough 32bit PA addressable pages to cover @size from the
75364 * page level allocator and map them into contiguous kernel virtual space.
75365 */
75366 +#undef vmalloc_32
75367 void *vmalloc_32(unsigned long size)
75368 {
75369 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
75370 @@ -1806,6 +1875,7 @@ EXPORT_SYMBOL(vmalloc_32);
75371 * The resulting memory area is 32bit addressable and zeroed so it can be
75372 * mapped to userspace without leaking data.
75373 */
75374 +#undef vmalloc_32_user
75375 void *vmalloc_32_user(unsigned long size)
75376 {
75377 struct vm_struct *area;
75378 @@ -2068,6 +2138,8 @@ int remap_vmalloc_range(struct vm_area_s
75379 unsigned long uaddr = vma->vm_start;
75380 unsigned long usize = vma->vm_end - vma->vm_start;
75381
75382 + BUG_ON(vma->vm_mirror);
75383 +
75384 if ((PAGE_SIZE-1) & (unsigned long)addr)
75385 return -EINVAL;
75386
75387 diff -urNp linux-2.6.39.1/mm/vmstat.c linux-2.6.39.1/mm/vmstat.c
75388 --- linux-2.6.39.1/mm/vmstat.c 2011-05-19 00:06:34.000000000 -0400
75389 +++ linux-2.6.39.1/mm/vmstat.c 2011-05-22 19:41:42.000000000 -0400
75390 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75391 *
75392 * vm_stat contains the global counters
75393 */
75394 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75395 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75396 EXPORT_SYMBOL(vm_stat);
75397
75398 #ifdef CONFIG_SMP
75399 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75400 v = p->vm_stat_diff[i];
75401 p->vm_stat_diff[i] = 0;
75402 local_irq_restore(flags);
75403 - atomic_long_add(v, &zone->vm_stat[i]);
75404 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75405 global_diff[i] += v;
75406 #ifdef CONFIG_NUMA
75407 /* 3 seconds idle till flush */
75408 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75409
75410 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75411 if (global_diff[i])
75412 - atomic_long_add(global_diff[i], &vm_stat[i]);
75413 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75414 }
75415
75416 #endif
75417 @@ -1205,10 +1205,20 @@ static int __init setup_vmstat(void)
75418 start_cpu_timer(cpu);
75419 #endif
75420 #ifdef CONFIG_PROC_FS
75421 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75422 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75423 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75424 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75425 + {
75426 + mode_t gr_mode = S_IRUGO;
75427 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75428 + gr_mode = S_IRUSR;
75429 +#endif
75430 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75431 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75432 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75433 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75434 +#else
75435 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75436 +#endif
75437 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75438 + }
75439 #endif
75440 return 0;
75441 }
75442 diff -urNp linux-2.6.39.1/net/8021q/vlan.c linux-2.6.39.1/net/8021q/vlan.c
75443 --- linux-2.6.39.1/net/8021q/vlan.c 2011-05-19 00:06:34.000000000 -0400
75444 +++ linux-2.6.39.1/net/8021q/vlan.c 2011-05-22 19:36:33.000000000 -0400
75445 @@ -592,8 +592,7 @@ static int vlan_ioctl_handler(struct net
75446 err = -EPERM;
75447 if (!capable(CAP_NET_ADMIN))
75448 break;
75449 - if ((args.u.name_type >= 0) &&
75450 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75451 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75452 struct vlan_net *vn;
75453
75454 vn = net_generic(net, vlan_net_id);
75455 diff -urNp linux-2.6.39.1/net/atm/atm_misc.c linux-2.6.39.1/net/atm/atm_misc.c
75456 --- linux-2.6.39.1/net/atm/atm_misc.c 2011-05-19 00:06:34.000000000 -0400
75457 +++ linux-2.6.39.1/net/atm/atm_misc.c 2011-05-22 19:36:33.000000000 -0400
75458 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
75459 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75460 return 1;
75461 atm_return(vcc, truesize);
75462 - atomic_inc(&vcc->stats->rx_drop);
75463 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75464 return 0;
75465 }
75466 EXPORT_SYMBOL(atm_charge);
75467 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
75468 }
75469 }
75470 atm_return(vcc, guess);
75471 - atomic_inc(&vcc->stats->rx_drop);
75472 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75473 return NULL;
75474 }
75475 EXPORT_SYMBOL(atm_alloc_charge);
75476 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75477
75478 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75479 {
75480 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75481 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75482 __SONET_ITEMS
75483 #undef __HANDLE_ITEM
75484 }
75485 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75486
75487 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75488 {
75489 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75490 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75491 __SONET_ITEMS
75492 #undef __HANDLE_ITEM
75493 }
75494 diff -urNp linux-2.6.39.1/net/atm/mpoa_caches.c linux-2.6.39.1/net/atm/mpoa_caches.c
75495 --- linux-2.6.39.1/net/atm/mpoa_caches.c 2011-05-19 00:06:34.000000000 -0400
75496 +++ linux-2.6.39.1/net/atm/mpoa_caches.c 2011-05-22 19:36:33.000000000 -0400
75497 @@ -255,6 +255,8 @@ static void check_resolving_entries(stru
75498 struct timeval now;
75499 struct k_message msg;
75500
75501 + pax_track_stack();
75502 +
75503 do_gettimeofday(&now);
75504
75505 read_lock_bh(&client->ingress_lock);
75506 diff -urNp linux-2.6.39.1/net/atm/proc.c linux-2.6.39.1/net/atm/proc.c
75507 --- linux-2.6.39.1/net/atm/proc.c 2011-05-19 00:06:34.000000000 -0400
75508 +++ linux-2.6.39.1/net/atm/proc.c 2011-05-22 19:41:42.000000000 -0400
75509 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
75510 const struct k_atm_aal_stats *stats)
75511 {
75512 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75513 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75514 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75515 - atomic_read(&stats->rx_drop));
75516 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75517 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75518 + atomic_read_unchecked(&stats->rx_drop));
75519 }
75520
75521 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75522 @@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
75523 {
75524 struct sock *sk = sk_atm(vcc);
75525
75526 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75527 + seq_printf(seq, "%p ", NULL);
75528 +#else
75529 seq_printf(seq, "%p ", vcc);
75530 +#endif
75531 +
75532 if (!vcc->dev)
75533 seq_printf(seq, "Unassigned ");
75534 else
75535 @@ -218,7 +223,11 @@ static void svc_info(struct seq_file *se
75536 {
75537 if (!vcc->dev)
75538 seq_printf(seq, sizeof(void *) == 4 ?
75539 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75540 + "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
75541 +#else
75542 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
75543 +#endif
75544 else
75545 seq_printf(seq, "%3d %3d %5d ",
75546 vcc->dev->number, vcc->vpi, vcc->vci);
75547 diff -urNp linux-2.6.39.1/net/atm/resources.c linux-2.6.39.1/net/atm/resources.c
75548 --- linux-2.6.39.1/net/atm/resources.c 2011-05-19 00:06:34.000000000 -0400
75549 +++ linux-2.6.39.1/net/atm/resources.c 2011-05-22 19:36:33.000000000 -0400
75550 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75551 static void copy_aal_stats(struct k_atm_aal_stats *from,
75552 struct atm_aal_stats *to)
75553 {
75554 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75555 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75556 __AAL_STAT_ITEMS
75557 #undef __HANDLE_ITEM
75558 }
75559 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
75560 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75561 struct atm_aal_stats *to)
75562 {
75563 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75564 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75565 __AAL_STAT_ITEMS
75566 #undef __HANDLE_ITEM
75567 }
75568 diff -urNp linux-2.6.39.1/net/batman-adv/hard-interface.c linux-2.6.39.1/net/batman-adv/hard-interface.c
75569 --- linux-2.6.39.1/net/batman-adv/hard-interface.c 2011-05-19 00:06:34.000000000 -0400
75570 +++ linux-2.6.39.1/net/batman-adv/hard-interface.c 2011-05-22 19:36:33.000000000 -0400
75571 @@ -339,8 +339,8 @@ int hardif_enable_interface(struct hard_
75572 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75573 dev_add_pack(&hard_iface->batman_adv_ptype);
75574
75575 - atomic_set(&hard_iface->seqno, 1);
75576 - atomic_set(&hard_iface->frag_seqno, 1);
75577 + atomic_set_unchecked(&hard_iface->seqno, 1);
75578 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75579 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75580 hard_iface->net_dev->name);
75581
75582 diff -urNp linux-2.6.39.1/net/batman-adv/routing.c linux-2.6.39.1/net/batman-adv/routing.c
75583 --- linux-2.6.39.1/net/batman-adv/routing.c 2011-05-19 00:06:34.000000000 -0400
75584 +++ linux-2.6.39.1/net/batman-adv/routing.c 2011-05-22 19:36:33.000000000 -0400
75585 @@ -625,7 +625,7 @@ void receive_bat_packet(struct ethhdr *e
75586 return;
75587
75588 /* could be changed by schedule_own_packet() */
75589 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75590 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75591
75592 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
75593
75594 diff -urNp linux-2.6.39.1/net/batman-adv/send.c linux-2.6.39.1/net/batman-adv/send.c
75595 --- linux-2.6.39.1/net/batman-adv/send.c 2011-05-19 00:06:34.000000000 -0400
75596 +++ linux-2.6.39.1/net/batman-adv/send.c 2011-05-22 19:36:33.000000000 -0400
75597 @@ -277,7 +277,7 @@ void schedule_own_packet(struct hard_ifa
75598
75599 /* change sequence number to network order */
75600 batman_packet->seqno =
75601 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75602 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75603
75604 if (vis_server == VIS_TYPE_SERVER_SYNC)
75605 batman_packet->flags |= VIS_SERVER;
75606 @@ -291,7 +291,7 @@ void schedule_own_packet(struct hard_ifa
75607 else
75608 batman_packet->gw_flags = 0;
75609
75610 - atomic_inc(&hard_iface->seqno);
75611 + atomic_inc_unchecked(&hard_iface->seqno);
75612
75613 slide_own_bcast_window(hard_iface);
75614 send_time = own_send_time(bat_priv);
75615 diff -urNp linux-2.6.39.1/net/batman-adv/soft-interface.c linux-2.6.39.1/net/batman-adv/soft-interface.c
75616 --- linux-2.6.39.1/net/batman-adv/soft-interface.c 2011-05-19 00:06:34.000000000 -0400
75617 +++ linux-2.6.39.1/net/batman-adv/soft-interface.c 2011-05-22 19:36:33.000000000 -0400
75618 @@ -386,7 +386,7 @@ int interface_tx(struct sk_buff *skb, st
75619
75620 /* set broadcast sequence number */
75621 bcast_packet->seqno =
75622 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75623 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75624
75625 add_bcast_packet_to_list(bat_priv, skb);
75626
75627 @@ -579,7 +579,7 @@ struct net_device *softif_create(char *n
75628 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75629
75630 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75631 - atomic_set(&bat_priv->bcast_seqno, 1);
75632 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75633 atomic_set(&bat_priv->hna_local_changed, 0);
75634
75635 bat_priv->primary_if = NULL;
75636 diff -urNp linux-2.6.39.1/net/batman-adv/types.h linux-2.6.39.1/net/batman-adv/types.h
75637 --- linux-2.6.39.1/net/batman-adv/types.h 2011-05-19 00:06:34.000000000 -0400
75638 +++ linux-2.6.39.1/net/batman-adv/types.h 2011-05-22 19:36:33.000000000 -0400
75639 @@ -38,8 +38,8 @@ struct hard_iface {
75640 int16_t if_num;
75641 char if_status;
75642 struct net_device *net_dev;
75643 - atomic_t seqno;
75644 - atomic_t frag_seqno;
75645 + atomic_unchecked_t seqno;
75646 + atomic_unchecked_t frag_seqno;
75647 unsigned char *packet_buff;
75648 int packet_len;
75649 struct kobject *hardif_obj;
75650 @@ -141,7 +141,7 @@ struct bat_priv {
75651 atomic_t orig_interval; /* uint */
75652 atomic_t hop_penalty; /* uint */
75653 atomic_t log_level; /* uint */
75654 - atomic_t bcast_seqno;
75655 + atomic_unchecked_t bcast_seqno;
75656 atomic_t bcast_queue_left;
75657 atomic_t batman_queue_left;
75658 char num_ifaces;
75659 diff -urNp linux-2.6.39.1/net/batman-adv/unicast.c linux-2.6.39.1/net/batman-adv/unicast.c
75660 --- linux-2.6.39.1/net/batman-adv/unicast.c 2011-05-19 00:06:34.000000000 -0400
75661 +++ linux-2.6.39.1/net/batman-adv/unicast.c 2011-05-22 19:36:33.000000000 -0400
75662 @@ -263,7 +263,7 @@ int frag_send_skb(struct sk_buff *skb, s
75663 frag1->flags = UNI_FRAG_HEAD | large_tail;
75664 frag2->flags = large_tail;
75665
75666 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75667 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75668 frag1->seqno = htons(seqno - 1);
75669 frag2->seqno = htons(seqno);
75670
75671 diff -urNp linux-2.6.39.1/net/bridge/br_multicast.c linux-2.6.39.1/net/bridge/br_multicast.c
75672 --- linux-2.6.39.1/net/bridge/br_multicast.c 2011-05-19 00:06:34.000000000 -0400
75673 +++ linux-2.6.39.1/net/bridge/br_multicast.c 2011-05-22 19:36:33.000000000 -0400
75674 @@ -1482,7 +1482,7 @@ static int br_multicast_ipv6_rcv(struct
75675 nexthdr = ip6h->nexthdr;
75676 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75677
75678 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75679 + if (nexthdr != IPPROTO_ICMPV6)
75680 return 0;
75681
75682 /* Okay, we found ICMPv6 header */
75683 diff -urNp linux-2.6.39.1/net/bridge/netfilter/ebtables.c linux-2.6.39.1/net/bridge/netfilter/ebtables.c
75684 --- linux-2.6.39.1/net/bridge/netfilter/ebtables.c 2011-05-19 00:06:34.000000000 -0400
75685 +++ linux-2.6.39.1/net/bridge/netfilter/ebtables.c 2011-05-22 19:36:33.000000000 -0400
75686 @@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
75687 tmp.valid_hooks = t->table->valid_hooks;
75688 }
75689 mutex_unlock(&ebt_mutex);
75690 - if (copy_to_user(user, &tmp, *len) != 0){
75691 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75692 BUGPRINT("c2u Didn't work\n");
75693 ret = -EFAULT;
75694 break;
75695 @@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
75696 int ret;
75697 void __user *pos;
75698
75699 + pax_track_stack();
75700 +
75701 memset(&tinfo, 0, sizeof(tinfo));
75702
75703 if (cmd == EBT_SO_GET_ENTRIES) {
75704 diff -urNp linux-2.6.39.1/net/caif/caif_socket.c linux-2.6.39.1/net/caif/caif_socket.c
75705 --- linux-2.6.39.1/net/caif/caif_socket.c 2011-05-19 00:06:34.000000000 -0400
75706 +++ linux-2.6.39.1/net/caif/caif_socket.c 2011-05-22 19:36:33.000000000 -0400
75707 @@ -48,18 +48,19 @@ static struct dentry *debugfsdir;
75708 #ifdef CONFIG_DEBUG_FS
75709 struct debug_fs_counter {
75710 atomic_t caif_nr_socks;
75711 - atomic_t num_connect_req;
75712 - atomic_t num_connect_resp;
75713 - atomic_t num_connect_fail_resp;
75714 - atomic_t num_disconnect;
75715 - atomic_t num_remote_shutdown_ind;
75716 - atomic_t num_tx_flow_off_ind;
75717 - atomic_t num_tx_flow_on_ind;
75718 - atomic_t num_rx_flow_off;
75719 - atomic_t num_rx_flow_on;
75720 + atomic_unchecked_t num_connect_req;
75721 + atomic_unchecked_t num_connect_resp;
75722 + atomic_unchecked_t num_connect_fail_resp;
75723 + atomic_unchecked_t num_disconnect;
75724 + atomic_unchecked_t num_remote_shutdown_ind;
75725 + atomic_unchecked_t num_tx_flow_off_ind;
75726 + atomic_unchecked_t num_tx_flow_on_ind;
75727 + atomic_unchecked_t num_rx_flow_off;
75728 + atomic_unchecked_t num_rx_flow_on;
75729 };
75730 static struct debug_fs_counter cnt;
75731 #define dbfs_atomic_inc(v) atomic_inc(v)
75732 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_unchecked(v)
75733 #define dbfs_atomic_dec(v) atomic_dec(v)
75734 #else
75735 #define dbfs_atomic_inc(v)
75736 @@ -159,7 +160,7 @@ static int caif_queue_rcv_skb(struct soc
75737 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75738 sk_rcvbuf_lowwater(cf_sk));
75739 set_rx_flow_off(cf_sk);
75740 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75741 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75742 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75743 }
75744
75745 @@ -169,7 +170,7 @@ static int caif_queue_rcv_skb(struct soc
75746 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
75747 set_rx_flow_off(cf_sk);
75748 pr_debug("sending flow OFF due to rmem_schedule\n");
75749 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75750 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75751 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75752 }
75753 skb->dev = NULL;
75754 @@ -218,21 +219,21 @@ static void caif_ctrl_cb(struct cflayer
75755 switch (flow) {
75756 case CAIF_CTRLCMD_FLOW_ON_IND:
75757 /* OK from modem to start sending again */
75758 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75759 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75760 set_tx_flow_on(cf_sk);
75761 cf_sk->sk.sk_state_change(&cf_sk->sk);
75762 break;
75763
75764 case CAIF_CTRLCMD_FLOW_OFF_IND:
75765 /* Modem asks us to shut up */
75766 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75767 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75768 set_tx_flow_off(cf_sk);
75769 cf_sk->sk.sk_state_change(&cf_sk->sk);
75770 break;
75771
75772 case CAIF_CTRLCMD_INIT_RSP:
75773 /* We're now connected */
75774 - dbfs_atomic_inc(&cnt.num_connect_resp);
75775 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75776 cf_sk->sk.sk_state = CAIF_CONNECTED;
75777 set_tx_flow_on(cf_sk);
75778 cf_sk->sk.sk_state_change(&cf_sk->sk);
75779 @@ -247,7 +248,7 @@ static void caif_ctrl_cb(struct cflayer
75780
75781 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75782 /* Connect request failed */
75783 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75784 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75785 cf_sk->sk.sk_err = ECONNREFUSED;
75786 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75787 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75788 @@ -261,7 +262,7 @@ static void caif_ctrl_cb(struct cflayer
75789
75790 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75791 /* Modem has closed this connection, or device is down. */
75792 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75793 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75794 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75795 cf_sk->sk.sk_err = ECONNRESET;
75796 set_rx_flow_on(cf_sk);
75797 @@ -281,7 +282,7 @@ static void caif_check_flow_release(stru
75798 return;
75799
75800 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75801 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75802 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75803 set_rx_flow_on(cf_sk);
75804 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75805 }
75806 @@ -864,7 +865,7 @@ static int caif_connect(struct socket *s
75807 /*ifindex = id of the interface.*/
75808 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75809
75810 - dbfs_atomic_inc(&cnt.num_connect_req);
75811 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75812 cf_sk->layer.receive = caif_sktrecv_cb;
75813 err = caif_connect_client(&cf_sk->conn_req,
75814 &cf_sk->layer, &ifindex, &headroom, &tailroom);
75815 @@ -952,7 +953,7 @@ static int caif_release(struct socket *s
75816 spin_unlock(&sk->sk_receive_queue.lock);
75817 sock->sk = NULL;
75818
75819 - dbfs_atomic_inc(&cnt.num_disconnect);
75820 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75821
75822 if (cf_sk->debugfs_socket_dir != NULL)
75823 debugfs_remove_recursive(cf_sk->debugfs_socket_dir);
75824 diff -urNp linux-2.6.39.1/net/caif/cfctrl.c linux-2.6.39.1/net/caif/cfctrl.c
75825 --- linux-2.6.39.1/net/caif/cfctrl.c 2011-05-19 00:06:34.000000000 -0400
75826 +++ linux-2.6.39.1/net/caif/cfctrl.c 2011-05-22 19:36:33.000000000 -0400
75827 @@ -9,6 +9,7 @@
75828 #include <linux/stddef.h>
75829 #include <linux/spinlock.h>
75830 #include <linux/slab.h>
75831 +#include <linux/sched.h>
75832 #include <net/caif/caif_layer.h>
75833 #include <net/caif/cfpkt.h>
75834 #include <net/caif/cfctrl.h>
75835 @@ -46,8 +47,8 @@ struct cflayer *cfctrl_create(void)
75836 dev_info.id = 0xff;
75837 memset(this, 0, sizeof(*this));
75838 cfsrvl_init(&this->serv, 0, &dev_info, false);
75839 - atomic_set(&this->req_seq_no, 1);
75840 - atomic_set(&this->rsp_seq_no, 1);
75841 + atomic_set_unchecked(&this->req_seq_no, 1);
75842 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75843 this->serv.layer.receive = cfctrl_recv;
75844 sprintf(this->serv.layer.name, "ctrl");
75845 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75846 @@ -116,8 +117,8 @@ void cfctrl_insert_req(struct cfctrl *ct
75847 struct cfctrl_request_info *req)
75848 {
75849 spin_lock(&ctrl->info_list_lock);
75850 - atomic_inc(&ctrl->req_seq_no);
75851 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75852 + atomic_inc_unchecked(&ctrl->req_seq_no);
75853 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75854 list_add_tail(&req->list, &ctrl->list);
75855 spin_unlock(&ctrl->info_list_lock);
75856 }
75857 @@ -136,7 +137,7 @@ struct cfctrl_request_info *cfctrl_remov
75858 if (p != first)
75859 pr_warn("Requests are not received in order\n");
75860
75861 - atomic_set(&ctrl->rsp_seq_no,
75862 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75863 p->sequence_no);
75864 list_del(&p->list);
75865 goto out;
75866 @@ -385,6 +386,7 @@ static int cfctrl_recv(struct cflayer *l
75867 struct cfctrl *cfctrl = container_obj(layer);
75868 struct cfctrl_request_info rsp, *req;
75869
75870 + pax_track_stack();
75871
75872 cfpkt_extr_head(pkt, &cmdrsp, 1);
75873 cmd = cmdrsp & CFCTRL_CMD_MASK;
75874 diff -urNp linux-2.6.39.1/net/can/bcm.c linux-2.6.39.1/net/can/bcm.c
75875 --- linux-2.6.39.1/net/can/bcm.c 2011-05-19 00:06:34.000000000 -0400
75876 +++ linux-2.6.39.1/net/can/bcm.c 2011-05-22 19:41:42.000000000 -0400
75877 @@ -165,9 +165,15 @@ static int bcm_proc_show(struct seq_file
75878 struct bcm_sock *bo = bcm_sk(sk);
75879 struct bcm_op *op;
75880
75881 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75882 + seq_printf(m, ">>> socket %p", NULL);
75883 + seq_printf(m, " / sk %p", NULL);
75884 + seq_printf(m, " / bo %p", NULL);
75885 +#else
75886 seq_printf(m, ">>> socket %p", sk->sk_socket);
75887 seq_printf(m, " / sk %p", sk);
75888 seq_printf(m, " / bo %p", bo);
75889 +#endif
75890 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
75891 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
75892 seq_printf(m, " <<<\n");
75893 diff -urNp linux-2.6.39.1/net/core/datagram.c linux-2.6.39.1/net/core/datagram.c
75894 --- linux-2.6.39.1/net/core/datagram.c 2011-05-19 00:06:34.000000000 -0400
75895 +++ linux-2.6.39.1/net/core/datagram.c 2011-05-22 19:36:33.000000000 -0400
75896 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
75897 }
75898
75899 kfree_skb(skb);
75900 - atomic_inc(&sk->sk_drops);
75901 + atomic_inc_unchecked(&sk->sk_drops);
75902 sk_mem_reclaim_partial(sk);
75903
75904 return err;
75905 diff -urNp linux-2.6.39.1/net/core/dev.c linux-2.6.39.1/net/core/dev.c
75906 --- linux-2.6.39.1/net/core/dev.c 2011-06-03 00:04:14.000000000 -0400
75907 +++ linux-2.6.39.1/net/core/dev.c 2011-06-03 00:32:08.000000000 -0400
75908 @@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
75909 if (no_module && capable(CAP_NET_ADMIN))
75910 no_module = request_module("netdev-%s", name);
75911 if (no_module && capable(CAP_SYS_MODULE)) {
75912 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75913 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75914 +#else
75915 if (!request_module("%s", name))
75916 pr_err("Loading kernel module for a network device "
75917 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75918 "instead\n", name);
75919 +#endif
75920 }
75921 }
75922 EXPORT_SYMBOL(dev_load);
75923 @@ -1957,7 +1961,7 @@ struct dev_gso_cb {
75924
75925 static void dev_gso_skb_destructor(struct sk_buff *skb)
75926 {
75927 - struct dev_gso_cb *cb;
75928 + const struct dev_gso_cb *cb;
75929
75930 do {
75931 struct sk_buff *nskb = skb->next;
75932 @@ -2901,7 +2905,7 @@ int netif_rx_ni(struct sk_buff *skb)
75933 }
75934 EXPORT_SYMBOL(netif_rx_ni);
75935
75936 -static void net_tx_action(struct softirq_action *h)
75937 +static void net_tx_action(void)
75938 {
75939 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75940
75941 @@ -3765,7 +3769,7 @@ void netif_napi_del(struct napi_struct *
75942 }
75943 EXPORT_SYMBOL(netif_napi_del);
75944
75945 -static void net_rx_action(struct softirq_action *h)
75946 +static void net_rx_action(void)
75947 {
75948 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75949 unsigned long time_limit = jiffies + 2;
75950 diff -urNp linux-2.6.39.1/net/core/flow.c linux-2.6.39.1/net/core/flow.c
75951 --- linux-2.6.39.1/net/core/flow.c 2011-05-19 00:06:34.000000000 -0400
75952 +++ linux-2.6.39.1/net/core/flow.c 2011-05-22 19:36:34.000000000 -0400
75953 @@ -60,7 +60,7 @@ struct flow_cache {
75954 struct timer_list rnd_timer;
75955 };
75956
75957 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75958 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75959 EXPORT_SYMBOL(flow_cache_genid);
75960 static struct flow_cache flow_cache_global;
75961 static struct kmem_cache *flow_cachep __read_mostly;
75962 @@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
75963
75964 static int flow_entry_valid(struct flow_cache_entry *fle)
75965 {
75966 - if (atomic_read(&flow_cache_genid) != fle->genid)
75967 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75968 return 0;
75969 if (fle->object && !fle->object->ops->check(fle->object))
75970 return 0;
75971 @@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
75972 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75973 fcp->hash_count++;
75974 }
75975 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75976 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75977 flo = fle->object;
75978 if (!flo)
75979 goto ret_object;
75980 @@ -274,7 +274,7 @@ nocache:
75981 }
75982 flo = resolver(net, key, family, dir, flo, ctx);
75983 if (fle) {
75984 - fle->genid = atomic_read(&flow_cache_genid);
75985 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75986 if (!IS_ERR(flo))
75987 fle->object = flo;
75988 else
75989 diff -urNp linux-2.6.39.1/net/core/skbuff.c linux-2.6.39.1/net/core/skbuff.c
75990 --- linux-2.6.39.1/net/core/skbuff.c 2011-06-03 00:04:14.000000000 -0400
75991 +++ linux-2.6.39.1/net/core/skbuff.c 2011-06-03 00:32:08.000000000 -0400
75992 @@ -1542,6 +1542,8 @@ int skb_splice_bits(struct sk_buff *skb,
75993 struct sock *sk = skb->sk;
75994 int ret = 0;
75995
75996 + pax_track_stack();
75997 +
75998 if (splice_grow_spd(pipe, &spd))
75999 return -ENOMEM;
76000
76001 diff -urNp linux-2.6.39.1/net/core/sock.c linux-2.6.39.1/net/core/sock.c
76002 --- linux-2.6.39.1/net/core/sock.c 2011-05-19 00:06:34.000000000 -0400
76003 +++ linux-2.6.39.1/net/core/sock.c 2011-05-22 19:36:34.000000000 -0400
76004 @@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76005 */
76006 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
76007 (unsigned)sk->sk_rcvbuf) {
76008 - atomic_inc(&sk->sk_drops);
76009 + atomic_inc_unchecked(&sk->sk_drops);
76010 return -ENOMEM;
76011 }
76012
76013 @@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76014 return err;
76015
76016 if (!sk_rmem_schedule(sk, skb->truesize)) {
76017 - atomic_inc(&sk->sk_drops);
76018 + atomic_inc_unchecked(&sk->sk_drops);
76019 return -ENOBUFS;
76020 }
76021
76022 @@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76023 skb_dst_force(skb);
76024
76025 spin_lock_irqsave(&list->lock, flags);
76026 - skb->dropcount = atomic_read(&sk->sk_drops);
76027 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76028 __skb_queue_tail(list, skb);
76029 spin_unlock_irqrestore(&list->lock, flags);
76030
76031 @@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
76032 skb->dev = NULL;
76033
76034 if (sk_rcvqueues_full(sk, skb)) {
76035 - atomic_inc(&sk->sk_drops);
76036 + atomic_inc_unchecked(&sk->sk_drops);
76037 goto discard_and_relse;
76038 }
76039 if (nested)
76040 @@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
76041 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76042 } else if (sk_add_backlog(sk, skb)) {
76043 bh_unlock_sock(sk);
76044 - atomic_inc(&sk->sk_drops);
76045 + atomic_inc_unchecked(&sk->sk_drops);
76046 goto discard_and_relse;
76047 }
76048
76049 @@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
76050 return -ENOTCONN;
76051 if (lv < len)
76052 return -EINVAL;
76053 - if (copy_to_user(optval, address, len))
76054 + if (len > sizeof(address) || copy_to_user(optval, address, len))
76055 return -EFAULT;
76056 goto lenout;
76057 }
76058 @@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
76059
76060 if (len > lv)
76061 len = lv;
76062 - if (copy_to_user(optval, &v, len))
76063 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76064 return -EFAULT;
76065 lenout:
76066 if (put_user(len, optlen))
76067 @@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
76068 */
76069 smp_wmb();
76070 atomic_set(&sk->sk_refcnt, 1);
76071 - atomic_set(&sk->sk_drops, 0);
76072 + atomic_set_unchecked(&sk->sk_drops, 0);
76073 }
76074 EXPORT_SYMBOL(sock_init_data);
76075
76076 diff -urNp linux-2.6.39.1/net/decnet/sysctl_net_decnet.c linux-2.6.39.1/net/decnet/sysctl_net_decnet.c
76077 --- linux-2.6.39.1/net/decnet/sysctl_net_decnet.c 2011-05-19 00:06:34.000000000 -0400
76078 +++ linux-2.6.39.1/net/decnet/sysctl_net_decnet.c 2011-05-22 19:36:34.000000000 -0400
76079 @@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
76080
76081 if (len > *lenp) len = *lenp;
76082
76083 - if (copy_to_user(buffer, addr, len))
76084 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76085 return -EFAULT;
76086
76087 *lenp = len;
76088 @@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
76089
76090 if (len > *lenp) len = *lenp;
76091
76092 - if (copy_to_user(buffer, devname, len))
76093 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76094 return -EFAULT;
76095
76096 *lenp = len;
76097 diff -urNp linux-2.6.39.1/net/econet/Kconfig linux-2.6.39.1/net/econet/Kconfig
76098 --- linux-2.6.39.1/net/econet/Kconfig 2011-05-19 00:06:34.000000000 -0400
76099 +++ linux-2.6.39.1/net/econet/Kconfig 2011-05-22 19:41:42.000000000 -0400
76100 @@ -4,7 +4,7 @@
76101
76102 config ECONET
76103 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
76104 - depends on EXPERIMENTAL && INET
76105 + depends on EXPERIMENTAL && INET && BROKEN
76106 ---help---
76107 Econet is a fairly old and slow networking protocol mainly used by
76108 Acorn computers to access file and print servers. It uses native
76109 diff -urNp linux-2.6.39.1/net/ipv4/fib_frontend.c linux-2.6.39.1/net/ipv4/fib_frontend.c
76110 --- linux-2.6.39.1/net/ipv4/fib_frontend.c 2011-05-19 00:06:34.000000000 -0400
76111 +++ linux-2.6.39.1/net/ipv4/fib_frontend.c 2011-05-22 19:36:34.000000000 -0400
76112 @@ -968,12 +968,12 @@ static int fib_inetaddr_event(struct not
76113 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76114 fib_sync_up(dev);
76115 #endif
76116 - atomic_inc(&net->ipv4.dev_addr_genid);
76117 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76118 rt_cache_flush(dev_net(dev), -1);
76119 break;
76120 case NETDEV_DOWN:
76121 fib_del_ifaddr(ifa, NULL);
76122 - atomic_inc(&net->ipv4.dev_addr_genid);
76123 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76124 if (ifa->ifa_dev->ifa_list == NULL) {
76125 /* Last address was deleted from this interface.
76126 * Disable IP.
76127 @@ -1009,7 +1009,7 @@ static int fib_netdev_event(struct notif
76128 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76129 fib_sync_up(dev);
76130 #endif
76131 - atomic_inc(&net->ipv4.dev_addr_genid);
76132 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76133 rt_cache_flush(dev_net(dev), -1);
76134 break;
76135 case NETDEV_DOWN:
76136 diff -urNp linux-2.6.39.1/net/ipv4/fib_semantics.c linux-2.6.39.1/net/ipv4/fib_semantics.c
76137 --- linux-2.6.39.1/net/ipv4/fib_semantics.c 2011-05-19 00:06:34.000000000 -0400
76138 +++ linux-2.6.39.1/net/ipv4/fib_semantics.c 2011-05-22 19:36:34.000000000 -0400
76139 @@ -701,7 +701,7 @@ __be32 fib_info_update_nh_saddr(struct n
76140 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76141 nh->nh_gw,
76142 nh->nh_parent->fib_scope);
76143 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76144 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76145
76146 return nh->nh_saddr;
76147 }
76148 diff -urNp linux-2.6.39.1/net/ipv4/inet_diag.c linux-2.6.39.1/net/ipv4/inet_diag.c
76149 --- linux-2.6.39.1/net/ipv4/inet_diag.c 2011-05-19 00:06:34.000000000 -0400
76150 +++ linux-2.6.39.1/net/ipv4/inet_diag.c 2011-05-22 19:41:42.000000000 -0400
76151 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
76152 r->idiag_retrans = 0;
76153
76154 r->id.idiag_if = sk->sk_bound_dev_if;
76155 +
76156 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76157 + r->id.idiag_cookie[0] = 0;
76158 + r->id.idiag_cookie[1] = 0;
76159 +#else
76160 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
76161 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76162 +#endif
76163
76164 r->id.idiag_sport = inet->inet_sport;
76165 r->id.idiag_dport = inet->inet_dport;
76166 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
76167 r->idiag_family = tw->tw_family;
76168 r->idiag_retrans = 0;
76169 r->id.idiag_if = tw->tw_bound_dev_if;
76170 +
76171 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76172 + r->id.idiag_cookie[0] = 0;
76173 + r->id.idiag_cookie[1] = 0;
76174 +#else
76175 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
76176 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
76177 +#endif
76178 +
76179 r->id.idiag_sport = tw->tw_sport;
76180 r->id.idiag_dport = tw->tw_dport;
76181 r->id.idiag_src[0] = tw->tw_rcv_saddr;
76182 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
76183 if (sk == NULL)
76184 goto unlock;
76185
76186 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76187 err = -ESTALE;
76188 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
76189 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
76190 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
76191 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
76192 goto out;
76193 +#endif
76194
76195 err = -ENOMEM;
76196 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
76197 @@ -582,8 +597,14 @@ static int inet_diag_fill_req(struct sk_
76198 r->idiag_retrans = req->retrans;
76199
76200 r->id.idiag_if = sk->sk_bound_dev_if;
76201 +
76202 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76203 + r->id.idiag_cookie[0] = 0;
76204 + r->id.idiag_cookie[1] = 0;
76205 +#else
76206 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
76207 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
76208 +#endif
76209
76210 tmo = req->expires - jiffies;
76211 if (tmo < 0)
76212 diff -urNp linux-2.6.39.1/net/ipv4/inet_hashtables.c linux-2.6.39.1/net/ipv4/inet_hashtables.c
76213 --- linux-2.6.39.1/net/ipv4/inet_hashtables.c 2011-05-19 00:06:34.000000000 -0400
76214 +++ linux-2.6.39.1/net/ipv4/inet_hashtables.c 2011-05-22 19:41:42.000000000 -0400
76215 @@ -18,11 +18,14 @@
76216 #include <linux/sched.h>
76217 #include <linux/slab.h>
76218 #include <linux/wait.h>
76219 +#include <linux/security.h>
76220
76221 #include <net/inet_connection_sock.h>
76222 #include <net/inet_hashtables.h>
76223 #include <net/ip.h>
76224
76225 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76226 +
76227 /*
76228 * Allocate and initialize a new local port bind bucket.
76229 * The bindhash mutex for snum's hash chain must be held here.
76230 @@ -529,6 +532,8 @@ ok:
76231 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76232 spin_unlock(&head->lock);
76233
76234 + gr_update_task_in_ip_table(current, inet_sk(sk));
76235 +
76236 if (tw) {
76237 inet_twsk_deschedule(tw, death_row);
76238 while (twrefcnt) {
76239 diff -urNp linux-2.6.39.1/net/ipv4/inetpeer.c linux-2.6.39.1/net/ipv4/inetpeer.c
76240 --- linux-2.6.39.1/net/ipv4/inetpeer.c 2011-05-19 00:06:34.000000000 -0400
76241 +++ linux-2.6.39.1/net/ipv4/inetpeer.c 2011-05-22 19:36:34.000000000 -0400
76242 @@ -467,6 +467,8 @@ struct inet_peer *inet_getpeer(struct in
76243 unsigned int sequence;
76244 int invalidated;
76245
76246 + pax_track_stack();
76247 +
76248 /* Look up for the address quickly, lockless.
76249 * Because of a concurrent writer, we might not find an existing entry.
76250 */
76251 @@ -504,8 +506,8 @@ struct inet_peer *inet_getpeer(struct in
76252 if (p) {
76253 p->daddr = *daddr;
76254 atomic_set(&p->refcnt, 1);
76255 - atomic_set(&p->rid, 0);
76256 - atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76257 + atomic_set_unchecked(&p->rid, 0);
76258 + atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76259 p->tcp_ts_stamp = 0;
76260 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
76261 p->rate_tokens = 0;
76262 diff -urNp linux-2.6.39.1/net/ipv4/ip_fragment.c linux-2.6.39.1/net/ipv4/ip_fragment.c
76263 --- linux-2.6.39.1/net/ipv4/ip_fragment.c 2011-05-19 00:06:34.000000000 -0400
76264 +++ linux-2.6.39.1/net/ipv4/ip_fragment.c 2011-05-22 19:36:34.000000000 -0400
76265 @@ -297,7 +297,7 @@ static inline int ip_frag_too_far(struct
76266 return 0;
76267
76268 start = qp->rid;
76269 - end = atomic_inc_return(&peer->rid);
76270 + end = atomic_inc_return_unchecked(&peer->rid);
76271 qp->rid = end;
76272
76273 rc = qp->q.fragments && (end - start) > max;
76274 diff -urNp linux-2.6.39.1/net/ipv4/ip_sockglue.c linux-2.6.39.1/net/ipv4/ip_sockglue.c
76275 --- linux-2.6.39.1/net/ipv4/ip_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76276 +++ linux-2.6.39.1/net/ipv4/ip_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76277 @@ -1064,6 +1064,8 @@ static int do_ip_getsockopt(struct sock
76278 int val;
76279 int len;
76280
76281 + pax_track_stack();
76282 +
76283 if (level != SOL_IP)
76284 return -EOPNOTSUPP;
76285
76286 diff -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
76287 --- linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-19 00:06:34.000000000 -0400
76288 +++ linux-2.6.39.1/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-22 19:36:34.000000000 -0400
76289 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
76290
76291 *len = 0;
76292
76293 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76294 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76295 if (*octets == NULL) {
76296 if (net_ratelimit())
76297 pr_notice("OOM in bsalg (%d)\n", __LINE__);
76298 diff -urNp linux-2.6.39.1/net/ipv4/raw.c linux-2.6.39.1/net/ipv4/raw.c
76299 --- linux-2.6.39.1/net/ipv4/raw.c 2011-05-19 00:06:34.000000000 -0400
76300 +++ linux-2.6.39.1/net/ipv4/raw.c 2011-05-22 19:41:42.000000000 -0400
76301 @@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
76302 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76303 {
76304 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76305 - atomic_inc(&sk->sk_drops);
76306 + atomic_inc_unchecked(&sk->sk_drops);
76307 kfree_skb(skb);
76308 return NET_RX_DROP;
76309 }
76310 @@ -730,15 +730,19 @@ static int raw_init(struct sock *sk)
76311
76312 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76313 {
76314 + struct icmp_filter filter;
76315 +
76316 if (optlen > sizeof(struct icmp_filter))
76317 optlen = sizeof(struct icmp_filter);
76318 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76319 + if (copy_from_user(&filter, optval, optlen))
76320 return -EFAULT;
76321 + memcpy(&raw_sk(sk)->filter, &filter, sizeof(filter));
76322 return 0;
76323 }
76324
76325 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76326 {
76327 + struct icmp_filter filter;
76328 int len, ret = -EFAULT;
76329
76330 if (get_user(len, optlen))
76331 @@ -749,8 +753,9 @@ static int raw_geticmpfilter(struct sock
76332 if (len > sizeof(struct icmp_filter))
76333 len = sizeof(struct icmp_filter);
76334 ret = -EFAULT;
76335 + memcpy(&filter, &raw_sk(sk)->filter, len);
76336 if (put_user(len, optlen) ||
76337 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76338 + copy_to_user(optval, &filter, len))
76339 goto out;
76340 ret = 0;
76341 out: return ret;
76342 @@ -978,7 +983,13 @@ static void raw_sock_seq_show(struct seq
76343 sk_wmem_alloc_get(sp),
76344 sk_rmem_alloc_get(sp),
76345 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76346 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76347 + atomic_read(&sp->sk_refcnt),
76348 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76349 + NULL,
76350 +#else
76351 + sp,
76352 +#endif
76353 + atomic_read_unchecked(&sp->sk_drops));
76354 }
76355
76356 static int raw_seq_show(struct seq_file *seq, void *v)
76357 diff -urNp linux-2.6.39.1/net/ipv4/route.c linux-2.6.39.1/net/ipv4/route.c
76358 --- linux-2.6.39.1/net/ipv4/route.c 2011-05-19 00:06:34.000000000 -0400
76359 +++ linux-2.6.39.1/net/ipv4/route.c 2011-05-22 19:36:34.000000000 -0400
76360 @@ -303,7 +303,7 @@ static inline unsigned int rt_hash(__be3
76361
76362 static inline int rt_genid(struct net *net)
76363 {
76364 - return atomic_read(&net->ipv4.rt_genid);
76365 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76366 }
76367
76368 #ifdef CONFIG_PROC_FS
76369 @@ -831,7 +831,7 @@ static void rt_cache_invalidate(struct n
76370 unsigned char shuffle;
76371
76372 get_random_bytes(&shuffle, sizeof(shuffle));
76373 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76374 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76375 }
76376
76377 /*
76378 @@ -2835,7 +2835,7 @@ static int rt_fill_info(struct net *net,
76379 rt->peer->pmtu_expires - jiffies : 0;
76380 if (rt->peer) {
76381 inet_peer_refcheck(rt->peer);
76382 - id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
76383 + id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
76384 if (rt->peer->tcp_ts_stamp) {
76385 ts = rt->peer->tcp_ts;
76386 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
76387 diff -urNp linux-2.6.39.1/net/ipv4/tcp.c linux-2.6.39.1/net/ipv4/tcp.c
76388 --- linux-2.6.39.1/net/ipv4/tcp.c 2011-05-19 00:06:34.000000000 -0400
76389 +++ linux-2.6.39.1/net/ipv4/tcp.c 2011-05-22 19:36:34.000000000 -0400
76390 @@ -2121,6 +2121,8 @@ static int do_tcp_setsockopt(struct sock
76391 int val;
76392 int err = 0;
76393
76394 + pax_track_stack();
76395 +
76396 /* These are data/string values, all the others are ints */
76397 switch (optname) {
76398 case TCP_CONGESTION: {
76399 @@ -2500,6 +2502,8 @@ static int do_tcp_getsockopt(struct sock
76400 struct tcp_sock *tp = tcp_sk(sk);
76401 int val, len;
76402
76403 + pax_track_stack();
76404 +
76405 if (get_user(len, optlen))
76406 return -EFAULT;
76407
76408 diff -urNp linux-2.6.39.1/net/ipv4/tcp_ipv4.c linux-2.6.39.1/net/ipv4/tcp_ipv4.c
76409 --- linux-2.6.39.1/net/ipv4/tcp_ipv4.c 2011-05-19 00:06:34.000000000 -0400
76410 +++ linux-2.6.39.1/net/ipv4/tcp_ipv4.c 2011-05-22 19:41:42.000000000 -0400
76411 @@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76412 int sysctl_tcp_low_latency __read_mostly;
76413 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76414
76415 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76416 +extern int grsec_enable_blackhole;
76417 +#endif
76418
76419 #ifdef CONFIG_TCP_MD5SIG
76420 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76421 @@ -1594,6 +1597,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
76422 return 0;
76423
76424 reset:
76425 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76426 + if (!grsec_enable_blackhole)
76427 +#endif
76428 tcp_v4_send_reset(rsk, skb);
76429 discard:
76430 kfree_skb(skb);
76431 @@ -1656,12 +1662,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76432 TCP_SKB_CB(skb)->sacked = 0;
76433
76434 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76435 - if (!sk)
76436 + if (!sk) {
76437 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76438 + ret = 1;
76439 +#endif
76440 goto no_tcp_socket;
76441 -
76442 + }
76443 process:
76444 - if (sk->sk_state == TCP_TIME_WAIT)
76445 + if (sk->sk_state == TCP_TIME_WAIT) {
76446 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76447 + ret = 2;
76448 +#endif
76449 goto do_time_wait;
76450 + }
76451
76452 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76453 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76454 @@ -1711,6 +1724,10 @@ no_tcp_socket:
76455 bad_packet:
76456 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76457 } else {
76458 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76459 + if (!grsec_enable_blackhole || (ret == 1 &&
76460 + (skb->dev->flags & IFF_LOOPBACK)))
76461 +#endif
76462 tcp_v4_send_reset(NULL, skb);
76463 }
76464
76465 @@ -2374,7 +2391,11 @@ static void get_openreq4(struct sock *sk
76466 0, /* non standard timer */
76467 0, /* open_requests have no inode */
76468 atomic_read(&sk->sk_refcnt),
76469 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76470 + NULL,
76471 +#else
76472 req,
76473 +#endif
76474 len);
76475 }
76476
76477 @@ -2424,7 +2445,12 @@ static void get_tcp4_sock(struct sock *s
76478 sock_i_uid(sk),
76479 icsk->icsk_probes_out,
76480 sock_i_ino(sk),
76481 - atomic_read(&sk->sk_refcnt), sk,
76482 + atomic_read(&sk->sk_refcnt),
76483 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76484 + NULL,
76485 +#else
76486 + sk,
76487 +#endif
76488 jiffies_to_clock_t(icsk->icsk_rto),
76489 jiffies_to_clock_t(icsk->icsk_ack.ato),
76490 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76491 @@ -2452,7 +2478,13 @@ static void get_timewait4_sock(struct in
76492 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
76493 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76494 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76495 - atomic_read(&tw->tw_refcnt), tw, len);
76496 + atomic_read(&tw->tw_refcnt),
76497 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76498 + NULL,
76499 +#else
76500 + tw,
76501 +#endif
76502 + len);
76503 }
76504
76505 #define TMPSZ 150
76506 diff -urNp linux-2.6.39.1/net/ipv4/tcp_minisocks.c linux-2.6.39.1/net/ipv4/tcp_minisocks.c
76507 --- linux-2.6.39.1/net/ipv4/tcp_minisocks.c 2011-05-19 00:06:34.000000000 -0400
76508 +++ linux-2.6.39.1/net/ipv4/tcp_minisocks.c 2011-05-22 19:41:42.000000000 -0400
76509 @@ -27,6 +27,10 @@
76510 #include <net/inet_common.h>
76511 #include <net/xfrm.h>
76512
76513 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76514 +extern int grsec_enable_blackhole;
76515 +#endif
76516 +
76517 int sysctl_tcp_syncookies __read_mostly = 1;
76518 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76519
76520 @@ -745,6 +749,10 @@ listen_overflow:
76521
76522 embryonic_reset:
76523 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76524 +
76525 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76526 + if (!grsec_enable_blackhole)
76527 +#endif
76528 if (!(flg & TCP_FLAG_RST))
76529 req->rsk_ops->send_reset(sk, skb);
76530
76531 diff -urNp linux-2.6.39.1/net/ipv4/tcp_output.c linux-2.6.39.1/net/ipv4/tcp_output.c
76532 --- linux-2.6.39.1/net/ipv4/tcp_output.c 2011-05-19 00:06:34.000000000 -0400
76533 +++ linux-2.6.39.1/net/ipv4/tcp_output.c 2011-05-22 19:36:34.000000000 -0400
76534 @@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
76535 int mss;
76536 int s_data_desired = 0;
76537
76538 + pax_track_stack();
76539 +
76540 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76541 s_data_desired = cvp->s_data_desired;
76542 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76543 diff -urNp linux-2.6.39.1/net/ipv4/tcp_probe.c linux-2.6.39.1/net/ipv4/tcp_probe.c
76544 --- linux-2.6.39.1/net/ipv4/tcp_probe.c 2011-05-19 00:06:34.000000000 -0400
76545 +++ linux-2.6.39.1/net/ipv4/tcp_probe.c 2011-05-22 19:36:34.000000000 -0400
76546 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
76547 if (cnt + width >= len)
76548 break;
76549
76550 - if (copy_to_user(buf + cnt, tbuf, width))
76551 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76552 return -EFAULT;
76553 cnt += width;
76554 }
76555 diff -urNp linux-2.6.39.1/net/ipv4/tcp_timer.c linux-2.6.39.1/net/ipv4/tcp_timer.c
76556 --- linux-2.6.39.1/net/ipv4/tcp_timer.c 2011-05-19 00:06:34.000000000 -0400
76557 +++ linux-2.6.39.1/net/ipv4/tcp_timer.c 2011-05-22 19:41:42.000000000 -0400
76558 @@ -22,6 +22,10 @@
76559 #include <linux/gfp.h>
76560 #include <net/tcp.h>
76561
76562 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76563 +extern int grsec_lastack_retries;
76564 +#endif
76565 +
76566 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76567 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76568 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76569 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
76570 }
76571 }
76572
76573 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76574 + if ((sk->sk_state == TCP_LAST_ACK) &&
76575 + (grsec_lastack_retries > 0) &&
76576 + (grsec_lastack_retries < retry_until))
76577 + retry_until = grsec_lastack_retries;
76578 +#endif
76579 +
76580 if (retransmits_timed_out(sk, retry_until,
76581 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76582 /* Has it gone just too far? */
76583 diff -urNp linux-2.6.39.1/net/ipv4/udp.c linux-2.6.39.1/net/ipv4/udp.c
76584 --- linux-2.6.39.1/net/ipv4/udp.c 2011-05-19 00:06:34.000000000 -0400
76585 +++ linux-2.6.39.1/net/ipv4/udp.c 2011-05-22 19:41:42.000000000 -0400
76586 @@ -86,6 +86,7 @@
76587 #include <linux/types.h>
76588 #include <linux/fcntl.h>
76589 #include <linux/module.h>
76590 +#include <linux/security.h>
76591 #include <linux/socket.h>
76592 #include <linux/sockios.h>
76593 #include <linux/igmp.h>
76594 @@ -107,6 +108,10 @@
76595 #include <net/xfrm.h>
76596 #include "udp_impl.h"
76597
76598 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76599 +extern int grsec_enable_blackhole;
76600 +#endif
76601 +
76602 struct udp_table udp_table __read_mostly;
76603 EXPORT_SYMBOL(udp_table);
76604
76605 @@ -564,6 +569,9 @@ found:
76606 return s;
76607 }
76608
76609 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76610 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76611 +
76612 /*
76613 * This routine is called by the ICMP module when it gets some
76614 * sort of error condition. If err < 0 then the socket should
76615 @@ -853,9 +861,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
76616 dport = usin->sin_port;
76617 if (dport == 0)
76618 return -EINVAL;
76619 +
76620 + err = gr_search_udp_sendmsg(sk, usin);
76621 + if (err)
76622 + return err;
76623 } else {
76624 if (sk->sk_state != TCP_ESTABLISHED)
76625 return -EDESTADDRREQ;
76626 +
76627 + err = gr_search_udp_sendmsg(sk, NULL);
76628 + if (err)
76629 + return err;
76630 +
76631 daddr = inet->inet_daddr;
76632 dport = inet->inet_dport;
76633 /* Open fast path for connected socket.
76634 @@ -1090,7 +1107,7 @@ static unsigned int first_packet_length(
76635 udp_lib_checksum_complete(skb)) {
76636 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76637 IS_UDPLITE(sk));
76638 - atomic_inc(&sk->sk_drops);
76639 + atomic_inc_unchecked(&sk->sk_drops);
76640 __skb_unlink(skb, rcvq);
76641 __skb_queue_tail(&list_kill, skb);
76642 }
76643 @@ -1176,6 +1193,10 @@ try_again:
76644 if (!skb)
76645 goto out;
76646
76647 + err = gr_search_udp_recvmsg(sk, skb);
76648 + if (err)
76649 + goto out_free;
76650 +
76651 ulen = skb->len - sizeof(struct udphdr);
76652 if (len > ulen)
76653 len = ulen;
76654 @@ -1472,7 +1493,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
76655
76656 drop:
76657 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76658 - atomic_inc(&sk->sk_drops);
76659 + atomic_inc_unchecked(&sk->sk_drops);
76660 kfree_skb(skb);
76661 return -1;
76662 }
76663 @@ -1491,7 +1512,7 @@ static void flush_stack(struct sock **st
76664 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76665
76666 if (!skb1) {
76667 - atomic_inc(&sk->sk_drops);
76668 + atomic_inc_unchecked(&sk->sk_drops);
76669 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76670 IS_UDPLITE(sk));
76671 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76672 @@ -1660,6 +1681,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
76673 goto csum_error;
76674
76675 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76676 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76677 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76678 +#endif
76679 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76680
76681 /*
76682 @@ -2087,8 +2111,13 @@ static void udp4_format_sock(struct sock
76683 sk_wmem_alloc_get(sp),
76684 sk_rmem_alloc_get(sp),
76685 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76686 - atomic_read(&sp->sk_refcnt), sp,
76687 - atomic_read(&sp->sk_drops), len);
76688 + atomic_read(&sp->sk_refcnt),
76689 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76690 + NULL,
76691 +#else
76692 + sp,
76693 +#endif
76694 + atomic_read_unchecked(&sp->sk_drops), len);
76695 }
76696
76697 int udp4_seq_show(struct seq_file *seq, void *v)
76698 diff -urNp linux-2.6.39.1/net/ipv6/inet6_connection_sock.c linux-2.6.39.1/net/ipv6/inet6_connection_sock.c
76699 --- linux-2.6.39.1/net/ipv6/inet6_connection_sock.c 2011-05-19 00:06:34.000000000 -0400
76700 +++ linux-2.6.39.1/net/ipv6/inet6_connection_sock.c 2011-05-22 19:36:34.000000000 -0400
76701 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
76702 #ifdef CONFIG_XFRM
76703 {
76704 struct rt6_info *rt = (struct rt6_info *)dst;
76705 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76706 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76707 }
76708 #endif
76709 }
76710 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
76711 #ifdef CONFIG_XFRM
76712 if (dst) {
76713 struct rt6_info *rt = (struct rt6_info *)dst;
76714 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76715 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76716 __sk_dst_reset(sk);
76717 dst = NULL;
76718 }
76719 diff -urNp linux-2.6.39.1/net/ipv6/ipv6_sockglue.c linux-2.6.39.1/net/ipv6/ipv6_sockglue.c
76720 --- linux-2.6.39.1/net/ipv6/ipv6_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76721 +++ linux-2.6.39.1/net/ipv6/ipv6_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76722 @@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
76723 int val, valbool;
76724 int retv = -ENOPROTOOPT;
76725
76726 + pax_track_stack();
76727 +
76728 if (optval == NULL)
76729 val=0;
76730 else {
76731 @@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
76732 int len;
76733 int val;
76734
76735 + pax_track_stack();
76736 +
76737 if (ip6_mroute_opt(optname))
76738 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76739
76740 diff -urNp linux-2.6.39.1/net/ipv6/raw.c linux-2.6.39.1/net/ipv6/raw.c
76741 --- linux-2.6.39.1/net/ipv6/raw.c 2011-05-19 00:06:34.000000000 -0400
76742 +++ linux-2.6.39.1/net/ipv6/raw.c 2011-05-22 19:41:42.000000000 -0400
76743 @@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
76744 {
76745 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76746 skb_checksum_complete(skb)) {
76747 - atomic_inc(&sk->sk_drops);
76748 + atomic_inc_unchecked(&sk->sk_drops);
76749 kfree_skb(skb);
76750 return NET_RX_DROP;
76751 }
76752 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76753 struct raw6_sock *rp = raw6_sk(sk);
76754
76755 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76756 - atomic_inc(&sk->sk_drops);
76757 + atomic_inc_unchecked(&sk->sk_drops);
76758 kfree_skb(skb);
76759 return NET_RX_DROP;
76760 }
76761 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76762
76763 if (inet->hdrincl) {
76764 if (skb_checksum_complete(skb)) {
76765 - atomic_inc(&sk->sk_drops);
76766 + atomic_inc_unchecked(&sk->sk_drops);
76767 kfree_skb(skb);
76768 return NET_RX_DROP;
76769 }
76770 @@ -601,7 +601,7 @@ out:
76771 return err;
76772 }
76773
76774 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76775 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76776 struct flowi6 *fl6, struct dst_entry **dstp,
76777 unsigned int flags)
76778 {
76779 @@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
76780 u16 proto;
76781 int err;
76782
76783 + pax_track_stack();
76784 +
76785 /* Rough check on arithmetic overflow,
76786 better check is made in ip6_append_data().
76787 */
76788 @@ -909,12 +911,15 @@ do_confirm:
76789 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76790 char __user *optval, int optlen)
76791 {
76792 + struct icmp6_filter filter;
76793 +
76794 switch (optname) {
76795 case ICMPV6_FILTER:
76796 if (optlen > sizeof(struct icmp6_filter))
76797 optlen = sizeof(struct icmp6_filter);
76798 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76799 + if (copy_from_user(&filter, optval, optlen))
76800 return -EFAULT;
76801 + memcpy(&raw6_sk(sk)->filter, &filter, optlen);
76802 return 0;
76803 default:
76804 return -ENOPROTOOPT;
76805 @@ -926,6 +931,7 @@ static int rawv6_seticmpfilter(struct so
76806 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76807 char __user *optval, int __user *optlen)
76808 {
76809 + struct icmp6_filter filter;
76810 int len;
76811
76812 switch (optname) {
76813 @@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
76814 len = sizeof(struct icmp6_filter);
76815 if (put_user(len, optlen))
76816 return -EFAULT;
76817 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76818 + memcpy(&filter, &raw6_sk(sk)->filter, len);
76819 + if (copy_to_user(optval, &filter, len))
76820 return -EFAULT;
76821 return 0;
76822 default:
76823 @@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
76824 0, 0L, 0,
76825 sock_i_uid(sp), 0,
76826 sock_i_ino(sp),
76827 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76828 + atomic_read(&sp->sk_refcnt),
76829 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76830 + NULL,
76831 +#else
76832 + sp,
76833 +#endif
76834 + atomic_read_unchecked(&sp->sk_drops));
76835 }
76836
76837 static int raw6_seq_show(struct seq_file *seq, void *v)
76838 diff -urNp linux-2.6.39.1/net/ipv6/tcp_ipv6.c linux-2.6.39.1/net/ipv6/tcp_ipv6.c
76839 --- linux-2.6.39.1/net/ipv6/tcp_ipv6.c 2011-05-19 00:06:34.000000000 -0400
76840 +++ linux-2.6.39.1/net/ipv6/tcp_ipv6.c 2011-05-22 19:41:42.000000000 -0400
76841 @@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
76842 }
76843 #endif
76844
76845 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76846 +extern int grsec_enable_blackhole;
76847 +#endif
76848 +
76849 static void tcp_v6_hash(struct sock *sk)
76850 {
76851 if (sk->sk_state != TCP_CLOSE) {
76852 @@ -1660,6 +1664,9 @@ static int tcp_v6_do_rcv(struct sock *sk
76853 return 0;
76854
76855 reset:
76856 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76857 + if (!grsec_enable_blackhole)
76858 +#endif
76859 tcp_v6_send_reset(sk, skb);
76860 discard:
76861 if (opt_skb)
76862 @@ -1739,12 +1746,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
76863 TCP_SKB_CB(skb)->sacked = 0;
76864
76865 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76866 - if (!sk)
76867 + if (!sk) {
76868 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76869 + ret = 1;
76870 +#endif
76871 goto no_tcp_socket;
76872 + }
76873
76874 process:
76875 - if (sk->sk_state == TCP_TIME_WAIT)
76876 + if (sk->sk_state == TCP_TIME_WAIT) {
76877 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76878 + ret = 2;
76879 +#endif
76880 goto do_time_wait;
76881 + }
76882
76883 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76884 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76885 @@ -1792,6 +1807,10 @@ no_tcp_socket:
76886 bad_packet:
76887 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76888 } else {
76889 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76890 + if (!grsec_enable_blackhole || (ret == 1 &&
76891 + (skb->dev->flags & IFF_LOOPBACK)))
76892 +#endif
76893 tcp_v6_send_reset(NULL, skb);
76894 }
76895
76896 @@ -2052,7 +2071,13 @@ static void get_openreq6(struct seq_file
76897 uid,
76898 0, /* non standard timer */
76899 0, /* open_requests have no inode */
76900 - 0, req);
76901 + 0,
76902 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76903 + NULL
76904 +#else
76905 + req
76906 +#endif
76907 + );
76908 }
76909
76910 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76911 @@ -2102,7 +2127,12 @@ static void get_tcp6_sock(struct seq_fil
76912 sock_i_uid(sp),
76913 icsk->icsk_probes_out,
76914 sock_i_ino(sp),
76915 - atomic_read(&sp->sk_refcnt), sp,
76916 + atomic_read(&sp->sk_refcnt),
76917 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76918 + NULL,
76919 +#else
76920 + sp,
76921 +#endif
76922 jiffies_to_clock_t(icsk->icsk_rto),
76923 jiffies_to_clock_t(icsk->icsk_ack.ato),
76924 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76925 @@ -2137,7 +2167,13 @@ static void get_timewait6_sock(struct se
76926 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76927 tw->tw_substate, 0, 0,
76928 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76929 - atomic_read(&tw->tw_refcnt), tw);
76930 + atomic_read(&tw->tw_refcnt),
76931 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76932 + NULL
76933 +#else
76934 + tw
76935 +#endif
76936 + );
76937 }
76938
76939 static int tcp6_seq_show(struct seq_file *seq, void *v)
76940 diff -urNp linux-2.6.39.1/net/ipv6/udp.c linux-2.6.39.1/net/ipv6/udp.c
76941 --- linux-2.6.39.1/net/ipv6/udp.c 2011-05-19 00:06:34.000000000 -0400
76942 +++ linux-2.6.39.1/net/ipv6/udp.c 2011-05-22 19:41:42.000000000 -0400
76943 @@ -50,6 +50,10 @@
76944 #include <linux/seq_file.h>
76945 #include "udp_impl.h"
76946
76947 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76948 +extern int grsec_enable_blackhole;
76949 +#endif
76950 +
76951 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76952 {
76953 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76954 @@ -545,7 +549,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
76955
76956 return 0;
76957 drop:
76958 - atomic_inc(&sk->sk_drops);
76959 + atomic_inc_unchecked(&sk->sk_drops);
76960 drop_no_sk_drops_inc:
76961 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76962 kfree_skb(skb);
76963 @@ -621,7 +625,7 @@ static void flush_stack(struct sock **st
76964 continue;
76965 }
76966 drop:
76967 - atomic_inc(&sk->sk_drops);
76968 + atomic_inc_unchecked(&sk->sk_drops);
76969 UDP6_INC_STATS_BH(sock_net(sk),
76970 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76971 UDP6_INC_STATS_BH(sock_net(sk),
76972 @@ -776,6 +780,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76973 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76974 proto == IPPROTO_UDPLITE);
76975
76976 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76977 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76978 +#endif
76979 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76980
76981 kfree_skb(skb);
76982 @@ -792,7 +799,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
76983 if (!sock_owned_by_user(sk))
76984 udpv6_queue_rcv_skb(sk, skb);
76985 else if (sk_add_backlog(sk, skb)) {
76986 - atomic_inc(&sk->sk_drops);
76987 + atomic_inc_unchecked(&sk->sk_drops);
76988 bh_unlock_sock(sk);
76989 sock_put(sk);
76990 goto discard;
76991 @@ -1403,8 +1410,13 @@ static void udp6_sock_seq_show(struct se
76992 0, 0L, 0,
76993 sock_i_uid(sp), 0,
76994 sock_i_ino(sp),
76995 - atomic_read(&sp->sk_refcnt), sp,
76996 - atomic_read(&sp->sk_drops));
76997 + atomic_read(&sp->sk_refcnt),
76998 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76999 + NULL,
77000 +#else
77001 + sp,
77002 +#endif
77003 + atomic_read_unchecked(&sp->sk_drops));
77004 }
77005
77006 int udp6_seq_show(struct seq_file *seq, void *v)
77007 diff -urNp linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c
77008 --- linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c 2011-05-19 00:06:34.000000000 -0400
77009 +++ linux-2.6.39.1/net/irda/ircomm/ircomm_tty.c 2011-05-22 19:36:34.000000000 -0400
77010 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
77011 add_wait_queue(&self->open_wait, &wait);
77012
77013 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77014 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77015 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77016
77017 /* As far as I can see, we protect open_count - Jean II */
77018 spin_lock_irqsave(&self->spinlock, flags);
77019 if (!tty_hung_up_p(filp)) {
77020 extra_count = 1;
77021 - self->open_count--;
77022 + local_dec(&self->open_count);
77023 }
77024 spin_unlock_irqrestore(&self->spinlock, flags);
77025 - self->blocked_open++;
77026 + local_inc(&self->blocked_open);
77027
77028 while (1) {
77029 if (tty->termios->c_cflag & CBAUD) {
77030 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
77031 }
77032
77033 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77034 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77035 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77036
77037 schedule();
77038 }
77039 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
77040 if (extra_count) {
77041 /* ++ is not atomic, so this should be protected - Jean II */
77042 spin_lock_irqsave(&self->spinlock, flags);
77043 - self->open_count++;
77044 + local_inc(&self->open_count);
77045 spin_unlock_irqrestore(&self->spinlock, flags);
77046 }
77047 - self->blocked_open--;
77048 + local_dec(&self->blocked_open);
77049
77050 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77051 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77052 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77053
77054 if (!retval)
77055 self->flags |= ASYNC_NORMAL_ACTIVE;
77056 @@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
77057 }
77058 /* ++ is not atomic, so this should be protected - Jean II */
77059 spin_lock_irqsave(&self->spinlock, flags);
77060 - self->open_count++;
77061 + local_inc(&self->open_count);
77062
77063 tty->driver_data = self;
77064 self->tty = tty;
77065 spin_unlock_irqrestore(&self->spinlock, flags);
77066
77067 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77068 - self->line, self->open_count);
77069 + self->line, local_read(&self->open_count));
77070
77071 /* Not really used by us, but lets do it anyway */
77072 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77073 @@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
77074 return;
77075 }
77076
77077 - if ((tty->count == 1) && (self->open_count != 1)) {
77078 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77079 /*
77080 * Uh, oh. tty->count is 1, which means that the tty
77081 * structure will be freed. state->count should always
77082 @@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
77083 */
77084 IRDA_DEBUG(0, "%s(), bad serial port count; "
77085 "tty->count is 1, state->count is %d\n", __func__ ,
77086 - self->open_count);
77087 - self->open_count = 1;
77088 + local_read(&self->open_count));
77089 + local_set(&self->open_count, 1);
77090 }
77091
77092 - if (--self->open_count < 0) {
77093 + if (local_dec_return(&self->open_count) < 0) {
77094 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77095 - __func__, self->line, self->open_count);
77096 - self->open_count = 0;
77097 + __func__, self->line, local_read(&self->open_count));
77098 + local_set(&self->open_count, 0);
77099 }
77100 - if (self->open_count) {
77101 + if (local_read(&self->open_count)) {
77102 spin_unlock_irqrestore(&self->spinlock, flags);
77103
77104 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77105 @@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
77106 tty->closing = 0;
77107 self->tty = NULL;
77108
77109 - if (self->blocked_open) {
77110 + if (local_read(&self->blocked_open)) {
77111 if (self->close_delay)
77112 schedule_timeout_interruptible(self->close_delay);
77113 wake_up_interruptible(&self->open_wait);
77114 @@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
77115 spin_lock_irqsave(&self->spinlock, flags);
77116 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77117 self->tty = NULL;
77118 - self->open_count = 0;
77119 + local_set(&self->open_count, 0);
77120 spin_unlock_irqrestore(&self->spinlock, flags);
77121
77122 wake_up_interruptible(&self->open_wait);
77123 @@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
77124 seq_putc(m, '\n');
77125
77126 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77127 - seq_printf(m, "Open count: %d\n", self->open_count);
77128 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77129 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77130 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77131
77132 diff -urNp linux-2.6.39.1/net/iucv/af_iucv.c linux-2.6.39.1/net/iucv/af_iucv.c
77133 --- linux-2.6.39.1/net/iucv/af_iucv.c 2011-05-19 00:06:34.000000000 -0400
77134 +++ linux-2.6.39.1/net/iucv/af_iucv.c 2011-05-22 19:36:34.000000000 -0400
77135 @@ -653,10 +653,10 @@ static int iucv_sock_autobind(struct soc
77136
77137 write_lock_bh(&iucv_sk_list.lock);
77138
77139 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77140 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77141 while (__iucv_get_sock_by_name(name)) {
77142 sprintf(name, "%08x",
77143 - atomic_inc_return(&iucv_sk_list.autobind_name));
77144 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77145 }
77146
77147 write_unlock_bh(&iucv_sk_list.lock);
77148 diff -urNp linux-2.6.39.1/net/key/af_key.c linux-2.6.39.1/net/key/af_key.c
77149 --- linux-2.6.39.1/net/key/af_key.c 2011-05-19 00:06:34.000000000 -0400
77150 +++ linux-2.6.39.1/net/key/af_key.c 2011-05-22 19:41:42.000000000 -0400
77151 @@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
77152 struct xfrm_migrate m[XFRM_MAX_DEPTH];
77153 struct xfrm_kmaddress k;
77154
77155 + pax_track_stack();
77156 +
77157 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
77158 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
77159 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
77160 @@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
77161 static u32 get_acqseq(void)
77162 {
77163 u32 res;
77164 - static atomic_t acqseq;
77165 + static atomic_unchecked_t acqseq;
77166
77167 do {
77168 - res = atomic_inc_return(&acqseq);
77169 + res = atomic_inc_return_unchecked(&acqseq);
77170 } while (!res);
77171 return res;
77172 }
77173 @@ -3657,7 +3659,11 @@ static int pfkey_seq_show(struct seq_fil
77174 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
77175 else
77176 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
77177 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77178 + NULL,
77179 +#else
77180 s,
77181 +#endif
77182 atomic_read(&s->sk_refcnt),
77183 sk_rmem_alloc_get(s),
77184 sk_wmem_alloc_get(s),
77185 diff -urNp linux-2.6.39.1/net/l2tp/l2tp_ip.c linux-2.6.39.1/net/l2tp/l2tp_ip.c
77186 --- linux-2.6.39.1/net/l2tp/l2tp_ip.c 2011-05-19 00:06:34.000000000 -0400
77187 +++ linux-2.6.39.1/net/l2tp/l2tp_ip.c 2011-05-22 19:36:34.000000000 -0400
77188 @@ -625,7 +625,7 @@ static struct inet_protosw l2tp_ip_proto
77189 .no_check = 0,
77190 };
77191
77192 -static struct net_protocol l2tp_ip_protocol __read_mostly = {
77193 +static const struct net_protocol l2tp_ip_protocol = {
77194 .handler = l2tp_ip_recv,
77195 };
77196
77197 diff -urNp linux-2.6.39.1/net/lapb/lapb_iface.c linux-2.6.39.1/net/lapb/lapb_iface.c
77198 --- linux-2.6.39.1/net/lapb/lapb_iface.c 2011-05-19 00:06:34.000000000 -0400
77199 +++ linux-2.6.39.1/net/lapb/lapb_iface.c 2011-05-22 19:36:34.000000000 -0400
77200 @@ -138,8 +138,7 @@ static struct lapb_cb *lapb_create_cb(vo
77201 out:
77202 return lapb;
77203 }
77204 -
77205 -int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks)
77206 +int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks)
77207 {
77208 struct lapb_cb *lapb;
77209 int rc = LAPB_BADTOKEN;
77210 diff -urNp linux-2.6.39.1/net/mac80211/cfg.c linux-2.6.39.1/net/mac80211/cfg.c
77211 --- linux-2.6.39.1/net/mac80211/cfg.c 2011-06-03 00:04:14.000000000 -0400
77212 +++ linux-2.6.39.1/net/mac80211/cfg.c 2011-06-03 00:32:08.000000000 -0400
77213 @@ -2031,7 +2031,7 @@ static void ieee80211_get_ringparam(stru
77214 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
77215 }
77216
77217 -struct cfg80211_ops mac80211_config_ops = {
77218 +const struct cfg80211_ops mac80211_config_ops = {
77219 .add_virtual_intf = ieee80211_add_iface,
77220 .del_virtual_intf = ieee80211_del_iface,
77221 .change_virtual_intf = ieee80211_change_iface,
77222 diff -urNp linux-2.6.39.1/net/mac80211/cfg.h linux-2.6.39.1/net/mac80211/cfg.h
77223 --- linux-2.6.39.1/net/mac80211/cfg.h 2011-05-19 00:06:34.000000000 -0400
77224 +++ linux-2.6.39.1/net/mac80211/cfg.h 2011-05-22 19:36:34.000000000 -0400
77225 @@ -4,6 +4,6 @@
77226 #ifndef __CFG_H
77227 #define __CFG_H
77228
77229 -extern struct cfg80211_ops mac80211_config_ops;
77230 +extern const struct cfg80211_ops mac80211_config_ops;
77231
77232 #endif /* __CFG_H */
77233 diff -urNp linux-2.6.39.1/net/mac80211/debugfs_sta.c linux-2.6.39.1/net/mac80211/debugfs_sta.c
77234 --- linux-2.6.39.1/net/mac80211/debugfs_sta.c 2011-05-19 00:06:34.000000000 -0400
77235 +++ linux-2.6.39.1/net/mac80211/debugfs_sta.c 2011-05-22 19:36:34.000000000 -0400
77236 @@ -115,6 +115,8 @@ static ssize_t sta_agg_status_read(struc
77237 struct tid_ampdu_rx *tid_rx;
77238 struct tid_ampdu_tx *tid_tx;
77239
77240 + pax_track_stack();
77241 +
77242 rcu_read_lock();
77243
77244 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
77245 @@ -215,6 +217,8 @@ static ssize_t sta_ht_capa_read(struct f
77246 struct sta_info *sta = file->private_data;
77247 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
77248
77249 + pax_track_stack();
77250 +
77251 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
77252 htc->ht_supported ? "" : "not ");
77253 if (htc->ht_supported) {
77254 diff -urNp linux-2.6.39.1/net/mac80211/ieee80211_i.h linux-2.6.39.1/net/mac80211/ieee80211_i.h
77255 --- linux-2.6.39.1/net/mac80211/ieee80211_i.h 2011-05-19 00:06:34.000000000 -0400
77256 +++ linux-2.6.39.1/net/mac80211/ieee80211_i.h 2011-05-22 19:36:34.000000000 -0400
77257 @@ -27,6 +27,7 @@
77258 #include <net/ieee80211_radiotap.h>
77259 #include <net/cfg80211.h>
77260 #include <net/mac80211.h>
77261 +#include <asm/local.h>
77262 #include "key.h"
77263 #include "sta_info.h"
77264
77265 @@ -714,7 +715,7 @@ struct ieee80211_local {
77266 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77267 spinlock_t queue_stop_reason_lock;
77268
77269 - int open_count;
77270 + local_t open_count;
77271 int monitors, cooked_mntrs;
77272 /* number of interfaces with corresponding FIF_ flags */
77273 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77274 diff -urNp linux-2.6.39.1/net/mac80211/iface.c linux-2.6.39.1/net/mac80211/iface.c
77275 --- linux-2.6.39.1/net/mac80211/iface.c 2011-05-19 00:06:34.000000000 -0400
77276 +++ linux-2.6.39.1/net/mac80211/iface.c 2011-05-22 19:36:34.000000000 -0400
77277 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
77278 break;
77279 }
77280
77281 - if (local->open_count == 0) {
77282 + if (local_read(&local->open_count) == 0) {
77283 res = drv_start(local);
77284 if (res)
77285 goto err_del_bss;
77286 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
77287 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77288
77289 if (!is_valid_ether_addr(dev->dev_addr)) {
77290 - if (!local->open_count)
77291 + if (!local_read(&local->open_count))
77292 drv_stop(local);
77293 return -EADDRNOTAVAIL;
77294 }
77295 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
77296 mutex_unlock(&local->mtx);
77297
77298 if (coming_up)
77299 - local->open_count++;
77300 + local_inc(&local->open_count);
77301
77302 if (hw_reconf_flags) {
77303 ieee80211_hw_config(local, hw_reconf_flags);
77304 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
77305 err_del_interface:
77306 drv_remove_interface(local, &sdata->vif);
77307 err_stop:
77308 - if (!local->open_count)
77309 + if (!local_read(&local->open_count))
77310 drv_stop(local);
77311 err_del_bss:
77312 sdata->bss = NULL;
77313 @@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct iee
77314 }
77315
77316 if (going_down)
77317 - local->open_count--;
77318 + local_dec(&local->open_count);
77319
77320 switch (sdata->vif.type) {
77321 case NL80211_IFTYPE_AP_VLAN:
77322 @@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct iee
77323
77324 ieee80211_recalc_ps(local, -1);
77325
77326 - if (local->open_count == 0) {
77327 + if (local_read(&local->open_count) == 0) {
77328 if (local->ops->napi_poll)
77329 napi_disable(&local->napi);
77330 ieee80211_clear_tx_pending(local);
77331 diff -urNp linux-2.6.39.1/net/mac80211/main.c linux-2.6.39.1/net/mac80211/main.c
77332 --- linux-2.6.39.1/net/mac80211/main.c 2011-05-19 00:06:34.000000000 -0400
77333 +++ linux-2.6.39.1/net/mac80211/main.c 2011-05-22 19:36:34.000000000 -0400
77334 @@ -215,7 +215,7 @@ int ieee80211_hw_config(struct ieee80211
77335 local->hw.conf.power_level = power;
77336 }
77337
77338 - if (changed && local->open_count) {
77339 + if (changed && local_read(&local->open_count)) {
77340 ret = drv_config(local, changed);
77341 /*
77342 * Goal:
77343 diff -urNp linux-2.6.39.1/net/mac80211/mlme.c linux-2.6.39.1/net/mac80211/mlme.c
77344 --- linux-2.6.39.1/net/mac80211/mlme.c 2011-06-03 00:04:14.000000000 -0400
77345 +++ linux-2.6.39.1/net/mac80211/mlme.c 2011-06-03 00:32:08.000000000 -0400
77346 @@ -1431,6 +1431,8 @@ static bool ieee80211_assoc_success(stru
77347 bool have_higher_than_11mbit = false;
77348 u16 ap_ht_cap_flags;
77349
77350 + pax_track_stack();
77351 +
77352 /* AssocResp and ReassocResp have identical structure */
77353
77354 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
77355 diff -urNp linux-2.6.39.1/net/mac80211/pm.c linux-2.6.39.1/net/mac80211/pm.c
77356 --- linux-2.6.39.1/net/mac80211/pm.c 2011-05-19 00:06:34.000000000 -0400
77357 +++ linux-2.6.39.1/net/mac80211/pm.c 2011-05-22 19:36:34.000000000 -0400
77358 @@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
77359 }
77360
77361 /* stop hardware - this must stop RX */
77362 - if (local->open_count)
77363 + if (local_read(&local->open_count))
77364 ieee80211_stop_device(local);
77365
77366 local->suspended = true;
77367 diff -urNp linux-2.6.39.1/net/mac80211/rate.c linux-2.6.39.1/net/mac80211/rate.c
77368 --- linux-2.6.39.1/net/mac80211/rate.c 2011-05-19 00:06:34.000000000 -0400
77369 +++ linux-2.6.39.1/net/mac80211/rate.c 2011-05-22 19:36:34.000000000 -0400
77370 @@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
77371
77372 ASSERT_RTNL();
77373
77374 - if (local->open_count)
77375 + if (local_read(&local->open_count))
77376 return -EBUSY;
77377
77378 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77379 diff -urNp linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c
77380 --- linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c 2011-05-19 00:06:34.000000000 -0400
77381 +++ linux-2.6.39.1/net/mac80211/rc80211_pid_debugfs.c 2011-05-22 19:36:34.000000000 -0400
77382 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
77383
77384 spin_unlock_irqrestore(&events->lock, status);
77385
77386 - if (copy_to_user(buf, pb, p))
77387 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77388 return -EFAULT;
77389
77390 return p;
77391 diff -urNp linux-2.6.39.1/net/mac80211/util.c linux-2.6.39.1/net/mac80211/util.c
77392 --- linux-2.6.39.1/net/mac80211/util.c 2011-05-19 00:06:34.000000000 -0400
77393 +++ linux-2.6.39.1/net/mac80211/util.c 2011-05-22 19:36:34.000000000 -0400
77394 @@ -1129,7 +1129,7 @@ int ieee80211_reconfig(struct ieee80211_
77395 local->resuming = true;
77396
77397 /* restart hardware */
77398 - if (local->open_count) {
77399 + if (local_read(&local->open_count)) {
77400 /*
77401 * Upon resume hardware can sometimes be goofy due to
77402 * various platform / driver / bus issues, so restarting
77403 diff -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
77404 --- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c 2011-05-19 00:06:34.000000000 -0400
77405 +++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_conn.c 2011-05-22 19:36:34.000000000 -0400
77406 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
77407 /* Increase the refcnt counter of the dest */
77408 atomic_inc(&dest->refcnt);
77409
77410 - conn_flags = atomic_read(&dest->conn_flags);
77411 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77412 if (cp->protocol != IPPROTO_UDP)
77413 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77414 /* Bind with the destination and its corresponding transmitter */
77415 @@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
77416 atomic_set(&cp->refcnt, 1);
77417
77418 atomic_set(&cp->n_control, 0);
77419 - atomic_set(&cp->in_pkts, 0);
77420 + atomic_set_unchecked(&cp->in_pkts, 0);
77421
77422 atomic_inc(&ipvs->conn_count);
77423 if (flags & IP_VS_CONN_F_NO_CPORT)
77424 @@ -1141,7 +1141,7 @@ static inline int todrop_entry(struct ip
77425
77426 /* Don't drop the entry if its number of incoming packets is not
77427 located in [0, 8] */
77428 - i = atomic_read(&cp->in_pkts);
77429 + i = atomic_read_unchecked(&cp->in_pkts);
77430 if (i > 8 || i < 0) return 0;
77431
77432 if (!todrop_rate[i]) return 0;
77433 diff -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
77434 --- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c 2011-05-19 00:06:34.000000000 -0400
77435 +++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_core.c 2011-05-22 19:36:34.000000000 -0400
77436 @@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
77437 ret = cp->packet_xmit(skb, cp, pd->pp);
77438 /* do not touch skb anymore */
77439
77440 - atomic_inc(&cp->in_pkts);
77441 + atomic_inc_unchecked(&cp->in_pkts);
77442 ip_vs_conn_put(cp);
77443 return ret;
77444 }
77445 @@ -1633,7 +1633,7 @@ ip_vs_in(unsigned int hooknum, struct sk
77446 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77447 pkts = sysctl_sync_threshold(ipvs);
77448 else
77449 - pkts = atomic_add_return(1, &cp->in_pkts);
77450 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77451
77452 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77453 cp->protocol == IPPROTO_SCTP) {
77454 diff -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
77455 --- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-19 00:06:34.000000000 -0400
77456 +++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-22 19:36:34.000000000 -0400
77457 @@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
77458 ip_vs_rs_hash(ipvs, dest);
77459 write_unlock_bh(&ipvs->rs_lock);
77460 }
77461 - atomic_set(&dest->conn_flags, conn_flags);
77462 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77463
77464 /* bind the service */
77465 if (!dest->svc) {
77466 @@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
77467 " %-7s %-6d %-10d %-10d\n",
77468 &dest->addr.in6,
77469 ntohs(dest->port),
77470 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77471 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77472 atomic_read(&dest->weight),
77473 atomic_read(&dest->activeconns),
77474 atomic_read(&dest->inactconns));
77475 @@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
77476 "%-7s %-6d %-10d %-10d\n",
77477 ntohl(dest->addr.ip),
77478 ntohs(dest->port),
77479 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77480 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77481 atomic_read(&dest->weight),
77482 atomic_read(&dest->activeconns),
77483 atomic_read(&dest->inactconns));
77484 @@ -2287,6 +2287,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
77485 struct ip_vs_dest_user *udest_compat;
77486 struct ip_vs_dest_user_kern udest;
77487
77488 + pax_track_stack();
77489 +
77490 if (!capable(CAP_NET_ADMIN))
77491 return -EPERM;
77492
77493 @@ -2501,7 +2503,7 @@ __ip_vs_get_dest_entries(struct net *net
77494
77495 entry.addr = dest->addr.ip;
77496 entry.port = dest->port;
77497 - entry.conn_flags = atomic_read(&dest->conn_flags);
77498 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77499 entry.weight = atomic_read(&dest->weight);
77500 entry.u_threshold = dest->u_threshold;
77501 entry.l_threshold = dest->l_threshold;
77502 @@ -3029,7 +3031,7 @@ static int ip_vs_genl_fill_dest(struct s
77503 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77504
77505 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77506 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77507 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77508 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77509 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77510 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77511 diff -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
77512 --- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c 2011-05-19 00:06:34.000000000 -0400
77513 +++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_sync.c 2011-05-22 19:36:34.000000000 -0400
77514 @@ -648,7 +648,7 @@ control:
77515 * i.e only increment in_pkts for Templates.
77516 */
77517 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77518 - int pkts = atomic_add_return(1, &cp->in_pkts);
77519 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77520
77521 if (pkts % sysctl_sync_period(ipvs) != 1)
77522 return;
77523 @@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
77524
77525 if (opt)
77526 memcpy(&cp->in_seq, opt, sizeof(*opt));
77527 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77528 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77529 cp->state = state;
77530 cp->old_state = cp->state;
77531 /*
77532 diff -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
77533 --- linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-19 00:06:34.000000000 -0400
77534 +++ linux-2.6.39.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-22 19:36:34.000000000 -0400
77535 @@ -1127,7 +1127,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
77536 else
77537 rc = NF_ACCEPT;
77538 /* do not touch skb anymore */
77539 - atomic_inc(&cp->in_pkts);
77540 + atomic_inc_unchecked(&cp->in_pkts);
77541 goto out;
77542 }
77543
77544 @@ -1245,7 +1245,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
77545 else
77546 rc = NF_ACCEPT;
77547 /* do not touch skb anymore */
77548 - atomic_inc(&cp->in_pkts);
77549 + atomic_inc_unchecked(&cp->in_pkts);
77550 goto out;
77551 }
77552
77553 diff -urNp linux-2.6.39.1/net/netfilter/Kconfig linux-2.6.39.1/net/netfilter/Kconfig
77554 --- linux-2.6.39.1/net/netfilter/Kconfig 2011-05-19 00:06:34.000000000 -0400
77555 +++ linux-2.6.39.1/net/netfilter/Kconfig 2011-05-22 19:41:42.000000000 -0400
77556 @@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
77557
77558 To compile it as a module, choose M here. If unsure, say N.
77559
77560 +config NETFILTER_XT_MATCH_GRADM
77561 + tristate '"gradm" match support'
77562 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77563 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77564 + ---help---
77565 + The gradm match allows to match on grsecurity RBAC being enabled.
77566 + It is useful when iptables rules are applied early on bootup to
77567 + prevent connections to the machine (except from a trusted host)
77568 + while the RBAC system is disabled.
77569 +
77570 config NETFILTER_XT_MATCH_HASHLIMIT
77571 tristate '"hashlimit" match support'
77572 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77573 diff -urNp linux-2.6.39.1/net/netfilter/Makefile linux-2.6.39.1/net/netfilter/Makefile
77574 --- linux-2.6.39.1/net/netfilter/Makefile 2011-05-19 00:06:34.000000000 -0400
77575 +++ linux-2.6.39.1/net/netfilter/Makefile 2011-05-22 20:40:16.000000000 -0400
77576 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
77577 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77578 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77579 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77580 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77581 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77582 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77583 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77584 diff -urNp linux-2.6.39.1/net/netfilter/nfnetlink_log.c linux-2.6.39.1/net/netfilter/nfnetlink_log.c
77585 --- linux-2.6.39.1/net/netfilter/nfnetlink_log.c 2011-05-19 00:06:34.000000000 -0400
77586 +++ linux-2.6.39.1/net/netfilter/nfnetlink_log.c 2011-05-22 19:36:35.000000000 -0400
77587 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77588 };
77589
77590 static DEFINE_SPINLOCK(instances_lock);
77591 -static atomic_t global_seq;
77592 +static atomic_unchecked_t global_seq;
77593
77594 #define INSTANCE_BUCKETS 16
77595 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77596 @@ -506,7 +506,7 @@ __build_packet_message(struct nfulnl_ins
77597 /* global sequence number */
77598 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77599 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77600 - htonl(atomic_inc_return(&global_seq)));
77601 + htonl(atomic_inc_return_unchecked(&global_seq)));
77602
77603 if (data_len) {
77604 struct nlattr *nla;
77605 diff -urNp linux-2.6.39.1/net/netfilter/nfnetlink_queue.c linux-2.6.39.1/net/netfilter/nfnetlink_queue.c
77606 --- linux-2.6.39.1/net/netfilter/nfnetlink_queue.c 2011-05-19 00:06:34.000000000 -0400
77607 +++ linux-2.6.39.1/net/netfilter/nfnetlink_queue.c 2011-05-22 19:36:35.000000000 -0400
77608 @@ -58,7 +58,7 @@ struct nfqnl_instance {
77609 */
77610 spinlock_t lock;
77611 unsigned int queue_total;
77612 - atomic_t id_sequence; /* 'sequence' of pkt ids */
77613 + atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
77614 struct list_head queue_list; /* packets in queue */
77615 };
77616
77617 @@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
77618 nfmsg->version = NFNETLINK_V0;
77619 nfmsg->res_id = htons(queue->queue_num);
77620
77621 - entry->id = atomic_inc_return(&queue->id_sequence);
77622 + entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
77623 pmsg.packet_id = htonl(entry->id);
77624 pmsg.hw_protocol = entskb->protocol;
77625 pmsg.hook = entry->hook;
77626 @@ -869,7 +869,7 @@ static int seq_show(struct seq_file *s,
77627 inst->peer_pid, inst->queue_total,
77628 inst->copy_mode, inst->copy_range,
77629 inst->queue_dropped, inst->queue_user_dropped,
77630 - atomic_read(&inst->id_sequence), 1);
77631 + atomic_read_unchecked(&inst->id_sequence), 1);
77632 }
77633
77634 static const struct seq_operations nfqnl_seq_ops = {
77635 diff -urNp linux-2.6.39.1/net/netfilter/xt_gradm.c linux-2.6.39.1/net/netfilter/xt_gradm.c
77636 --- linux-2.6.39.1/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
77637 +++ linux-2.6.39.1/net/netfilter/xt_gradm.c 2011-05-22 19:41:42.000000000 -0400
77638 @@ -0,0 +1,51 @@
77639 +/*
77640 + * gradm match for netfilter
77641 + * Copyright © Zbigniew Krzystolik, 2010
77642 + *
77643 + * This program is free software; you can redistribute it and/or modify
77644 + * it under the terms of the GNU General Public License; either version
77645 + * 2 or 3 as published by the Free Software Foundation.
77646 + */
77647 +#include <linux/module.h>
77648 +#include <linux/moduleparam.h>
77649 +#include <linux/skbuff.h>
77650 +#include <linux/netfilter/x_tables.h>
77651 +#include <linux/grsecurity.h>
77652 +#include <linux/netfilter/xt_gradm.h>
77653 +
77654 +static bool
77655 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77656 +{
77657 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77658 + bool retval = false;
77659 + if (gr_acl_is_enabled())
77660 + retval = true;
77661 + return retval ^ info->invflags;
77662 +}
77663 +
77664 +static struct xt_match gradm_mt_reg __read_mostly = {
77665 + .name = "gradm",
77666 + .revision = 0,
77667 + .family = NFPROTO_UNSPEC,
77668 + .match = gradm_mt,
77669 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77670 + .me = THIS_MODULE,
77671 +};
77672 +
77673 +static int __init gradm_mt_init(void)
77674 +{
77675 + return xt_register_match(&gradm_mt_reg);
77676 +}
77677 +
77678 +static void __exit gradm_mt_exit(void)
77679 +{
77680 + xt_unregister_match(&gradm_mt_reg);
77681 +}
77682 +
77683 +module_init(gradm_mt_init);
77684 +module_exit(gradm_mt_exit);
77685 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77686 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77687 +MODULE_LICENSE("GPL");
77688 +MODULE_ALIAS("ipt_gradm");
77689 +MODULE_ALIAS("ip6t_gradm");
77690 diff -urNp linux-2.6.39.1/net/netfilter/xt_statistic.c linux-2.6.39.1/net/netfilter/xt_statistic.c
77691 --- linux-2.6.39.1/net/netfilter/xt_statistic.c 2011-05-19 00:06:34.000000000 -0400
77692 +++ linux-2.6.39.1/net/netfilter/xt_statistic.c 2011-05-22 19:36:35.000000000 -0400
77693 @@ -18,7 +18,7 @@
77694 #include <linux/netfilter/x_tables.h>
77695
77696 struct xt_statistic_priv {
77697 - atomic_t count;
77698 + atomic_unchecked_t count;
77699 } ____cacheline_aligned_in_smp;
77700
77701 MODULE_LICENSE("GPL");
77702 @@ -41,9 +41,9 @@ statistic_mt(const struct sk_buff *skb,
77703 break;
77704 case XT_STATISTIC_MODE_NTH:
77705 do {
77706 - oval = atomic_read(&info->master->count);
77707 + oval = atomic_read_unchecked(&info->master->count);
77708 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77709 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77710 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77711 if (nval == 0)
77712 ret = !ret;
77713 break;
77714 @@ -63,7 +63,7 @@ static int statistic_mt_check(const stru
77715 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77716 if (info->master == NULL)
77717 return -ENOMEM;
77718 - atomic_set(&info->master->count, info->u.nth.count);
77719 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77720
77721 return 0;
77722 }
77723 diff -urNp linux-2.6.39.1/net/netlink/af_netlink.c linux-2.6.39.1/net/netlink/af_netlink.c
77724 --- linux-2.6.39.1/net/netlink/af_netlink.c 2011-05-19 00:06:34.000000000 -0400
77725 +++ linux-2.6.39.1/net/netlink/af_netlink.c 2011-05-22 19:41:42.000000000 -0400
77726 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock
77727 sk->sk_error_report(sk);
77728 }
77729 }
77730 - atomic_inc(&sk->sk_drops);
77731 + atomic_inc_unchecked(&sk->sk_drops);
77732 }
77733
77734 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77735 @@ -1992,15 +1992,23 @@ static int netlink_seq_show(struct seq_f
77736 struct netlink_sock *nlk = nlk_sk(s);
77737
77738 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
77739 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77740 + NULL,
77741 +#else
77742 s,
77743 +#endif
77744 s->sk_protocol,
77745 nlk->pid,
77746 nlk->groups ? (u32)nlk->groups[0] : 0,
77747 sk_rmem_alloc_get(s),
77748 sk_wmem_alloc_get(s),
77749 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77750 + NULL,
77751 +#else
77752 nlk->cb,
77753 +#endif
77754 atomic_read(&s->sk_refcnt),
77755 - atomic_read(&s->sk_drops),
77756 + atomic_read_unchecked(&s->sk_drops),
77757 sock_i_ino(s)
77758 );
77759
77760 diff -urNp linux-2.6.39.1/net/netrom/af_netrom.c linux-2.6.39.1/net/netrom/af_netrom.c
77761 --- linux-2.6.39.1/net/netrom/af_netrom.c 2011-05-19 00:06:34.000000000 -0400
77762 +++ linux-2.6.39.1/net/netrom/af_netrom.c 2011-05-22 19:41:42.000000000 -0400
77763 @@ -840,6 +840,7 @@ static int nr_getname(struct socket *soc
77764 struct sock *sk = sock->sk;
77765 struct nr_sock *nr = nr_sk(sk);
77766
77767 + memset(sax, 0, sizeof(*sax));
77768 lock_sock(sk);
77769 if (peer != 0) {
77770 if (sk->sk_state != TCP_ESTABLISHED) {
77771 @@ -854,7 +855,6 @@ static int nr_getname(struct socket *soc
77772 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77773 } else {
77774 sax->fsa_ax25.sax25_family = AF_NETROM;
77775 - sax->fsa_ax25.sax25_ndigis = 0;
77776 sax->fsa_ax25.sax25_call = nr->source_addr;
77777 *uaddr_len = sizeof(struct sockaddr_ax25);
77778 }
77779 diff -urNp linux-2.6.39.1/net/packet/af_packet.c linux-2.6.39.1/net/packet/af_packet.c
77780 --- linux-2.6.39.1/net/packet/af_packet.c 2011-05-19 00:06:34.000000000 -0400
77781 +++ linux-2.6.39.1/net/packet/af_packet.c 2011-05-22 19:41:42.000000000 -0400
77782 @@ -647,14 +647,14 @@ static int packet_rcv(struct sk_buff *sk
77783
77784 spin_lock(&sk->sk_receive_queue.lock);
77785 po->stats.tp_packets++;
77786 - skb->dropcount = atomic_read(&sk->sk_drops);
77787 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77788 __skb_queue_tail(&sk->sk_receive_queue, skb);
77789 spin_unlock(&sk->sk_receive_queue.lock);
77790 sk->sk_data_ready(sk, skb->len);
77791 return 0;
77792
77793 drop_n_acct:
77794 - po->stats.tp_drops = atomic_inc_return(&sk->sk_drops);
77795 + po->stats.tp_drops = atomic_inc_return_unchecked(&sk->sk_drops);
77796
77797 drop_n_restore:
77798 if (skb_head != skb->data && skb_shared(skb)) {
77799 @@ -2157,7 +2157,7 @@ static int packet_getsockopt(struct sock
77800 case PACKET_HDRLEN:
77801 if (len > sizeof(int))
77802 len = sizeof(int);
77803 - if (copy_from_user(&val, optval, len))
77804 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77805 return -EFAULT;
77806 switch (val) {
77807 case TPACKET_V1:
77808 @@ -2195,7 +2195,7 @@ static int packet_getsockopt(struct sock
77809
77810 if (put_user(len, optlen))
77811 return -EFAULT;
77812 - if (copy_to_user(optval, data, len))
77813 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77814 return -EFAULT;
77815 return 0;
77816 }
77817 @@ -2707,7 +2707,11 @@ static int packet_seq_show(struct seq_fi
77818
77819 seq_printf(seq,
77820 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
77821 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77822 + NULL,
77823 +#else
77824 s,
77825 +#endif
77826 atomic_read(&s->sk_refcnt),
77827 s->sk_type,
77828 ntohs(po->num),
77829 diff -urNp linux-2.6.39.1/net/phonet/af_phonet.c linux-2.6.39.1/net/phonet/af_phonet.c
77830 --- linux-2.6.39.1/net/phonet/af_phonet.c 2011-05-19 00:06:34.000000000 -0400
77831 +++ linux-2.6.39.1/net/phonet/af_phonet.c 2011-05-22 19:41:42.000000000 -0400
77832 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_pr
77833 {
77834 struct phonet_protocol *pp;
77835
77836 - if (protocol >= PHONET_NPROTO)
77837 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77838 return NULL;
77839
77840 rcu_read_lock();
77841 @@ -149,7 +149,7 @@ static int pn_header_parse(const struct
77842 return 1;
77843 }
77844
77845 -struct header_ops phonet_header_ops = {
77846 +const struct header_ops phonet_header_ops = {
77847 .create = pn_header_create,
77848 .parse = pn_header_parse,
77849 };
77850 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_regist
77851 {
77852 int err = 0;
77853
77854 - if (protocol >= PHONET_NPROTO)
77855 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77856 return -EINVAL;
77857
77858 err = proto_register(pp->prot, 1);
77859 diff -urNp linux-2.6.39.1/net/phonet/pep.c linux-2.6.39.1/net/phonet/pep.c
77860 --- linux-2.6.39.1/net/phonet/pep.c 2011-05-19 00:06:34.000000000 -0400
77861 +++ linux-2.6.39.1/net/phonet/pep.c 2011-05-22 19:36:35.000000000 -0400
77862 @@ -387,7 +387,7 @@ static int pipe_do_rcv(struct sock *sk,
77863
77864 case PNS_PEP_CTRL_REQ:
77865 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77866 - atomic_inc(&sk->sk_drops);
77867 + atomic_inc_unchecked(&sk->sk_drops);
77868 break;
77869 }
77870 __skb_pull(skb, 4);
77871 @@ -408,7 +408,7 @@ static int pipe_do_rcv(struct sock *sk,
77872 }
77873
77874 if (pn->rx_credits == 0) {
77875 - atomic_inc(&sk->sk_drops);
77876 + atomic_inc_unchecked(&sk->sk_drops);
77877 err = -ENOBUFS;
77878 break;
77879 }
77880 @@ -556,7 +556,7 @@ static int pipe_handler_do_rcv(struct so
77881 }
77882
77883 if (pn->rx_credits == 0) {
77884 - atomic_inc(&sk->sk_drops);
77885 + atomic_inc_unchecked(&sk->sk_drops);
77886 err = NET_RX_DROP;
77887 break;
77888 }
77889 diff -urNp linux-2.6.39.1/net/phonet/socket.c linux-2.6.39.1/net/phonet/socket.c
77890 --- linux-2.6.39.1/net/phonet/socket.c 2011-05-19 00:06:34.000000000 -0400
77891 +++ linux-2.6.39.1/net/phonet/socket.c 2011-05-22 20:39:26.000000000 -0400
77892 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_f
77893 pn->resource, sk->sk_state,
77894 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77895 sock_i_uid(sk), sock_i_ino(sk),
77896 - atomic_read(&sk->sk_refcnt), sk,
77897 - atomic_read(&sk->sk_drops), &len);
77898 + atomic_read(&sk->sk_refcnt),
77899 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77900 + NULL,
77901 +#else
77902 + sk,
77903 +#endif
77904 + atomic_read_unchecked(&sk->sk_drops), &len);
77905 }
77906 seq_printf(seq, "%*s\n", 127 - len, "");
77907 return 0;
77908 diff -urNp linux-2.6.39.1/net/rds/cong.c linux-2.6.39.1/net/rds/cong.c
77909 --- linux-2.6.39.1/net/rds/cong.c 2011-05-19 00:06:34.000000000 -0400
77910 +++ linux-2.6.39.1/net/rds/cong.c 2011-05-22 19:36:35.000000000 -0400
77911 @@ -77,7 +77,7 @@
77912 * finds that the saved generation number is smaller than the global generation
77913 * number, it wakes up the process.
77914 */
77915 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77916 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77917
77918 /*
77919 * Congestion monitoring
77920 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_con
77921 rdsdebug("waking map %p for %pI4\n",
77922 map, &map->m_addr);
77923 rds_stats_inc(s_cong_update_received);
77924 - atomic_inc(&rds_cong_generation);
77925 + atomic_inc_unchecked(&rds_cong_generation);
77926 if (waitqueue_active(&map->m_waitq))
77927 wake_up(&map->m_waitq);
77928 if (waitqueue_active(&rds_poll_waitq))
77929 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77930
77931 int rds_cong_updated_since(unsigned long *recent)
77932 {
77933 - unsigned long gen = atomic_read(&rds_cong_generation);
77934 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77935
77936 if (likely(*recent == gen))
77937 return 0;
77938 diff -urNp linux-2.6.39.1/net/rds/ib_cm.c linux-2.6.39.1/net/rds/ib_cm.c
77939 --- linux-2.6.39.1/net/rds/ib_cm.c 2011-05-19 00:06:34.000000000 -0400
77940 +++ linux-2.6.39.1/net/rds/ib_cm.c 2011-05-22 19:36:35.000000000 -0400
77941 @@ -720,7 +720,7 @@ void rds_ib_conn_shutdown(struct rds_con
77942 /* Clear the ACK state */
77943 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77944 #ifdef KERNEL_HAS_ATOMIC64
77945 - atomic64_set(&ic->i_ack_next, 0);
77946 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77947 #else
77948 ic->i_ack_next = 0;
77949 #endif
77950 diff -urNp linux-2.6.39.1/net/rds/ib.h linux-2.6.39.1/net/rds/ib.h
77951 --- linux-2.6.39.1/net/rds/ib.h 2011-05-19 00:06:34.000000000 -0400
77952 +++ linux-2.6.39.1/net/rds/ib.h 2011-05-22 19:36:35.000000000 -0400
77953 @@ -127,7 +127,7 @@ struct rds_ib_connection {
77954 /* sending acks */
77955 unsigned long i_ack_flags;
77956 #ifdef KERNEL_HAS_ATOMIC64
77957 - atomic64_t i_ack_next; /* next ACK to send */
77958 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77959 #else
77960 spinlock_t i_ack_lock; /* protect i_ack_next */
77961 u64 i_ack_next; /* next ACK to send */
77962 diff -urNp linux-2.6.39.1/net/rds/ib_recv.c linux-2.6.39.1/net/rds/ib_recv.c
77963 --- linux-2.6.39.1/net/rds/ib_recv.c 2011-05-19 00:06:34.000000000 -0400
77964 +++ linux-2.6.39.1/net/rds/ib_recv.c 2011-05-22 19:36:35.000000000 -0400
77965 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_
77966 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77967 int ack_required)
77968 {
77969 - atomic64_set(&ic->i_ack_next, seq);
77970 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77971 if (ack_required) {
77972 smp_mb__before_clear_bit();
77973 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77974 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_
77975 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77976 smp_mb__after_clear_bit();
77977
77978 - return atomic64_read(&ic->i_ack_next);
77979 + return atomic64_read_unchecked(&ic->i_ack_next);
77980 }
77981 #endif
77982
77983 diff -urNp linux-2.6.39.1/net/rds/iw_cm.c linux-2.6.39.1/net/rds/iw_cm.c
77984 --- linux-2.6.39.1/net/rds/iw_cm.c 2011-05-19 00:06:34.000000000 -0400
77985 +++ linux-2.6.39.1/net/rds/iw_cm.c 2011-05-22 19:36:35.000000000 -0400
77986 @@ -664,7 +664,7 @@ void rds_iw_conn_shutdown(struct rds_con
77987 /* Clear the ACK state */
77988 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77989 #ifdef KERNEL_HAS_ATOMIC64
77990 - atomic64_set(&ic->i_ack_next, 0);
77991 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77992 #else
77993 ic->i_ack_next = 0;
77994 #endif
77995 diff -urNp linux-2.6.39.1/net/rds/iw.h linux-2.6.39.1/net/rds/iw.h
77996 --- linux-2.6.39.1/net/rds/iw.h 2011-05-19 00:06:34.000000000 -0400
77997 +++ linux-2.6.39.1/net/rds/iw.h 2011-05-22 19:36:35.000000000 -0400
77998 @@ -133,7 +133,7 @@ struct rds_iw_connection {
77999 /* sending acks */
78000 unsigned long i_ack_flags;
78001 #ifdef KERNEL_HAS_ATOMIC64
78002 - atomic64_t i_ack_next; /* next ACK to send */
78003 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78004 #else
78005 spinlock_t i_ack_lock; /* protect i_ack_next */
78006 u64 i_ack_next; /* next ACK to send */
78007 diff -urNp linux-2.6.39.1/net/rds/iw_rdma.c linux-2.6.39.1/net/rds/iw_rdma.c
78008 --- linux-2.6.39.1/net/rds/iw_rdma.c 2011-05-19 00:06:34.000000000 -0400
78009 +++ linux-2.6.39.1/net/rds/iw_rdma.c 2011-05-22 19:36:35.000000000 -0400
78010 @@ -182,6 +182,8 @@ int rds_iw_update_cm_id(struct rds_iw_de
78011 struct rdma_cm_id *pcm_id;
78012 int rc;
78013
78014 + pax_track_stack();
78015 +
78016 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
78017 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
78018
78019 diff -urNp linux-2.6.39.1/net/rds/iw_recv.c linux-2.6.39.1/net/rds/iw_recv.c
78020 --- linux-2.6.39.1/net/rds/iw_recv.c 2011-05-19 00:06:34.000000000 -0400
78021 +++ linux-2.6.39.1/net/rds/iw_recv.c 2011-05-22 19:36:35.000000000 -0400
78022 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_
78023 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78024 int ack_required)
78025 {
78026 - atomic64_set(&ic->i_ack_next, seq);
78027 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78028 if (ack_required) {
78029 smp_mb__before_clear_bit();
78030 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78031 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_
78032 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78033 smp_mb__after_clear_bit();
78034
78035 - return atomic64_read(&ic->i_ack_next);
78036 + return atomic64_read_unchecked(&ic->i_ack_next);
78037 }
78038 #endif
78039
78040 diff -urNp linux-2.6.39.1/net/rxrpc/af_rxrpc.c linux-2.6.39.1/net/rxrpc/af_rxrpc.c
78041 --- linux-2.6.39.1/net/rxrpc/af_rxrpc.c 2011-05-19 00:06:34.000000000 -0400
78042 +++ linux-2.6.39.1/net/rxrpc/af_rxrpc.c 2011-05-22 19:36:35.000000000 -0400
78043 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_
78044 __be32 rxrpc_epoch;
78045
78046 /* current debugging ID */
78047 -atomic_t rxrpc_debug_id;
78048 +atomic_unchecked_t rxrpc_debug_id;
78049
78050 /* count of skbs currently in use */
78051 atomic_t rxrpc_n_skbs;
78052 diff -urNp linux-2.6.39.1/net/rxrpc/ar-ack.c linux-2.6.39.1/net/rxrpc/ar-ack.c
78053 --- linux-2.6.39.1/net/rxrpc/ar-ack.c 2011-05-19 00:06:34.000000000 -0400
78054 +++ linux-2.6.39.1/net/rxrpc/ar-ack.c 2011-05-22 19:36:35.000000000 -0400
78055 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_ca
78056
78057 _enter("{%d,%d,%d,%d},",
78058 call->acks_hard, call->acks_unacked,
78059 - atomic_read(&call->sequence),
78060 + atomic_read_unchecked(&call->sequence),
78061 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78062
78063 stop = 0;
78064 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_ca
78065
78066 /* each Tx packet has a new serial number */
78067 sp->hdr.serial =
78068 - htonl(atomic_inc_return(&call->conn->serial));
78069 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78070
78071 hdr = (struct rxrpc_header *) txb->head;
78072 hdr->serial = sp->hdr.serial;
78073 @@ -405,7 +405,7 @@ static void rxrpc_rotate_tx_window(struc
78074 */
78075 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78076 {
78077 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78078 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78079 }
78080
78081 /*
78082 @@ -631,7 +631,7 @@ process_further:
78083
78084 latest = ntohl(sp->hdr.serial);
78085 hard = ntohl(ack.firstPacket);
78086 - tx = atomic_read(&call->sequence);
78087 + tx = atomic_read_unchecked(&call->sequence);
78088
78089 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78090 latest,
78091 @@ -844,6 +844,8 @@ void rxrpc_process_call(struct work_stru
78092 u32 abort_code = RX_PROTOCOL_ERROR;
78093 u8 *acks = NULL;
78094
78095 + pax_track_stack();
78096 +
78097 //printk("\n--------------------\n");
78098 _enter("{%d,%s,%lx} [%lu]",
78099 call->debug_id, rxrpc_call_states[call->state], call->events,
78100 @@ -1163,7 +1165,7 @@ void rxrpc_process_call(struct work_stru
78101 goto maybe_reschedule;
78102
78103 send_ACK_with_skew:
78104 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78105 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78106 ntohl(ack.serial));
78107 send_ACK:
78108 mtu = call->conn->trans->peer->if_mtu;
78109 @@ -1175,7 +1177,7 @@ send_ACK:
78110 ackinfo.rxMTU = htonl(5692);
78111 ackinfo.jumbo_max = htonl(4);
78112
78113 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78114 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78115 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78116 ntohl(hdr.serial),
78117 ntohs(ack.maxSkew),
78118 @@ -1193,7 +1195,7 @@ send_ACK:
78119 send_message:
78120 _debug("send message");
78121
78122 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78123 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78124 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78125 send_message_2:
78126
78127 diff -urNp linux-2.6.39.1/net/rxrpc/ar-call.c linux-2.6.39.1/net/rxrpc/ar-call.c
78128 --- linux-2.6.39.1/net/rxrpc/ar-call.c 2011-05-19 00:06:34.000000000 -0400
78129 +++ linux-2.6.39.1/net/rxrpc/ar-call.c 2011-05-22 19:36:35.000000000 -0400
78130 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_ca
78131 spin_lock_init(&call->lock);
78132 rwlock_init(&call->state_lock);
78133 atomic_set(&call->usage, 1);
78134 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78135 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78136 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78137
78138 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78139 diff -urNp linux-2.6.39.1/net/rxrpc/ar-connection.c linux-2.6.39.1/net/rxrpc/ar-connection.c
78140 --- linux-2.6.39.1/net/rxrpc/ar-connection.c 2011-05-19 00:06:34.000000000 -0400
78141 +++ linux-2.6.39.1/net/rxrpc/ar-connection.c 2011-05-22 19:36:35.000000000 -0400
78142 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_al
78143 rwlock_init(&conn->lock);
78144 spin_lock_init(&conn->state_lock);
78145 atomic_set(&conn->usage, 1);
78146 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78147 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78148 conn->avail_calls = RXRPC_MAXCALLS;
78149 conn->size_align = 4;
78150 conn->header_size = sizeof(struct rxrpc_header);
78151 diff -urNp linux-2.6.39.1/net/rxrpc/ar-connevent.c linux-2.6.39.1/net/rxrpc/ar-connevent.c
78152 --- linux-2.6.39.1/net/rxrpc/ar-connevent.c 2011-05-19 00:06:34.000000000 -0400
78153 +++ linux-2.6.39.1/net/rxrpc/ar-connevent.c 2011-05-22 19:36:35.000000000 -0400
78154 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct
78155
78156 len = iov[0].iov_len + iov[1].iov_len;
78157
78158 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78159 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78160 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78161
78162 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78163 diff -urNp linux-2.6.39.1/net/rxrpc/ar-input.c linux-2.6.39.1/net/rxrpc/ar-input.c
78164 --- linux-2.6.39.1/net/rxrpc/ar-input.c 2011-05-19 00:06:34.000000000 -0400
78165 +++ linux-2.6.39.1/net/rxrpc/ar-input.c 2011-05-22 19:36:35.000000000 -0400
78166 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rx
78167 /* track the latest serial number on this connection for ACK packet
78168 * information */
78169 serial = ntohl(sp->hdr.serial);
78170 - hi_serial = atomic_read(&call->conn->hi_serial);
78171 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78172 while (serial > hi_serial)
78173 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78174 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78175 serial);
78176
78177 /* request ACK generation for any ACK or DATA packet that requests
78178 diff -urNp linux-2.6.39.1/net/rxrpc/ar-internal.h linux-2.6.39.1/net/rxrpc/ar-internal.h
78179 --- linux-2.6.39.1/net/rxrpc/ar-internal.h 2011-05-19 00:06:34.000000000 -0400
78180 +++ linux-2.6.39.1/net/rxrpc/ar-internal.h 2011-05-22 19:36:35.000000000 -0400
78181 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78182 int error; /* error code for local abort */
78183 int debug_id; /* debug ID for printks */
78184 unsigned call_counter; /* call ID counter */
78185 - atomic_t serial; /* packet serial number counter */
78186 - atomic_t hi_serial; /* highest serial number received */
78187 + atomic_unchecked_t serial; /* packet serial number counter */
78188 + atomic_unchecked_t hi_serial; /* highest serial number received */
78189 u8 avail_calls; /* number of calls available */
78190 u8 size_align; /* data size alignment (for security) */
78191 u8 header_size; /* rxrpc + security header size */
78192 @@ -346,7 +346,7 @@ struct rxrpc_call {
78193 spinlock_t lock;
78194 rwlock_t state_lock; /* lock for state transition */
78195 atomic_t usage;
78196 - atomic_t sequence; /* Tx data packet sequence counter */
78197 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78198 u32 abort_code; /* local/remote abort code */
78199 enum { /* current state of call */
78200 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78201 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(stru
78202 */
78203 extern atomic_t rxrpc_n_skbs;
78204 extern __be32 rxrpc_epoch;
78205 -extern atomic_t rxrpc_debug_id;
78206 +extern atomic_unchecked_t rxrpc_debug_id;
78207 extern struct workqueue_struct *rxrpc_workqueue;
78208
78209 /*
78210 diff -urNp linux-2.6.39.1/net/rxrpc/ar-local.c linux-2.6.39.1/net/rxrpc/ar-local.c
78211 --- linux-2.6.39.1/net/rxrpc/ar-local.c 2011-05-19 00:06:34.000000000 -0400
78212 +++ linux-2.6.39.1/net/rxrpc/ar-local.c 2011-05-22 19:36:35.000000000 -0400
78213 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(st
78214 spin_lock_init(&local->lock);
78215 rwlock_init(&local->services_lock);
78216 atomic_set(&local->usage, 1);
78217 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78218 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78219 memcpy(&local->srx, srx, sizeof(*srx));
78220 }
78221
78222 diff -urNp linux-2.6.39.1/net/rxrpc/ar-output.c linux-2.6.39.1/net/rxrpc/ar-output.c
78223 --- linux-2.6.39.1/net/rxrpc/ar-output.c 2011-05-19 00:06:34.000000000 -0400
78224 +++ linux-2.6.39.1/net/rxrpc/ar-output.c 2011-05-22 19:36:35.000000000 -0400
78225 @@ -681,9 +681,9 @@ static int rxrpc_send_data(struct kiocb
78226 sp->hdr.cid = call->cid;
78227 sp->hdr.callNumber = call->call_id;
78228 sp->hdr.seq =
78229 - htonl(atomic_inc_return(&call->sequence));
78230 + htonl(atomic_inc_return_unchecked(&call->sequence));
78231 sp->hdr.serial =
78232 - htonl(atomic_inc_return(&conn->serial));
78233 + htonl(atomic_inc_return_unchecked(&conn->serial));
78234 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78235 sp->hdr.userStatus = 0;
78236 sp->hdr.securityIndex = conn->security_ix;
78237 diff -urNp linux-2.6.39.1/net/rxrpc/ar-peer.c linux-2.6.39.1/net/rxrpc/ar-peer.c
78238 --- linux-2.6.39.1/net/rxrpc/ar-peer.c 2011-05-19 00:06:34.000000000 -0400
78239 +++ linux-2.6.39.1/net/rxrpc/ar-peer.c 2011-05-22 19:36:35.000000000 -0400
78240 @@ -71,7 +71,7 @@ static struct rxrpc_peer *rxrpc_alloc_pe
78241 INIT_LIST_HEAD(&peer->error_targets);
78242 spin_lock_init(&peer->lock);
78243 atomic_set(&peer->usage, 1);
78244 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78245 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78246 memcpy(&peer->srx, srx, sizeof(*srx));
78247
78248 rxrpc_assess_MTU_size(peer);
78249 diff -urNp linux-2.6.39.1/net/rxrpc/ar-proc.c linux-2.6.39.1/net/rxrpc/ar-proc.c
78250 --- linux-2.6.39.1/net/rxrpc/ar-proc.c 2011-05-19 00:06:34.000000000 -0400
78251 +++ linux-2.6.39.1/net/rxrpc/ar-proc.c 2011-05-22 19:36:35.000000000 -0400
78252 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(str
78253 atomic_read(&conn->usage),
78254 rxrpc_conn_states[conn->state],
78255 key_serial(conn->key),
78256 - atomic_read(&conn->serial),
78257 - atomic_read(&conn->hi_serial));
78258 + atomic_read_unchecked(&conn->serial),
78259 + atomic_read_unchecked(&conn->hi_serial));
78260
78261 return 0;
78262 }
78263 diff -urNp linux-2.6.39.1/net/rxrpc/ar-transport.c linux-2.6.39.1/net/rxrpc/ar-transport.c
78264 --- linux-2.6.39.1/net/rxrpc/ar-transport.c 2011-05-19 00:06:34.000000000 -0400
78265 +++ linux-2.6.39.1/net/rxrpc/ar-transport.c 2011-05-22 19:36:35.000000000 -0400
78266 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_all
78267 spin_lock_init(&trans->client_lock);
78268 rwlock_init(&trans->conn_lock);
78269 atomic_set(&trans->usage, 1);
78270 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78271 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78272
78273 if (peer->srx.transport.family == AF_INET) {
78274 switch (peer->srx.transport_type) {
78275 diff -urNp linux-2.6.39.1/net/rxrpc/rxkad.c linux-2.6.39.1/net/rxrpc/rxkad.c
78276 --- linux-2.6.39.1/net/rxrpc/rxkad.c 2011-05-19 00:06:34.000000000 -0400
78277 +++ linux-2.6.39.1/net/rxrpc/rxkad.c 2011-05-22 19:36:35.000000000 -0400
78278 @@ -211,6 +211,8 @@ static int rxkad_secure_packet_encrypt(c
78279 u16 check;
78280 int nsg;
78281
78282 + pax_track_stack();
78283 +
78284 sp = rxrpc_skb(skb);
78285
78286 _enter("");
78287 @@ -338,6 +340,8 @@ static int rxkad_verify_packet_auth(cons
78288 u16 check;
78289 int nsg;
78290
78291 + pax_track_stack();
78292 +
78293 _enter("");
78294
78295 sp = rxrpc_skb(skb);
78296 @@ -610,7 +614,7 @@ static int rxkad_issue_challenge(struct
78297
78298 len = iov[0].iov_len + iov[1].iov_len;
78299
78300 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78301 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78302 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78303
78304 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78305 @@ -660,7 +664,7 @@ static int rxkad_send_response(struct rx
78306
78307 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78308
78309 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78310 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78311 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78312
78313 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78314 diff -urNp linux-2.6.39.1/net/sched/em_meta.c linux-2.6.39.1/net/sched/em_meta.c
78315 --- linux-2.6.39.1/net/sched/em_meta.c 2011-05-19 00:06:34.000000000 -0400
78316 +++ linux-2.6.39.1/net/sched/em_meta.c 2011-05-22 19:36:35.000000000 -0400
78317 @@ -832,7 +832,7 @@ static int em_meta_dump(struct sk_buff *
78318 {
78319 struct meta_match *meta = (struct meta_match *) em->data;
78320 struct tcf_meta_hdr hdr;
78321 - struct meta_type_ops *ops;
78322 + const struct meta_type_ops *ops;
78323
78324 memset(&hdr, 0, sizeof(hdr));
78325 memcpy(&hdr.left, &meta->lvalue.hdr, sizeof(hdr.left));
78326 diff -urNp linux-2.6.39.1/net/sctp/proc.c linux-2.6.39.1/net/sctp/proc.c
78327 --- linux-2.6.39.1/net/sctp/proc.c 2011-05-19 00:06:34.000000000 -0400
78328 +++ linux-2.6.39.1/net/sctp/proc.c 2011-05-22 19:41:42.000000000 -0400
78329 @@ -212,7 +212,12 @@ static int sctp_eps_seq_show(struct seq_
78330 sctp_for_each_hentry(epb, node, &head->chain) {
78331 ep = sctp_ep(epb);
78332 sk = epb->sk;
78333 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
78334 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
78335 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78336 + NULL, NULL,
78337 +#else
78338 + ep, sk,
78339 +#endif
78340 sctp_sk(sk)->type, sk->sk_state, hash,
78341 epb->bind_addr.port,
78342 sock_i_uid(sk), sock_i_ino(sk));
78343 @@ -318,7 +323,12 @@ static int sctp_assocs_seq_show(struct s
78344 seq_printf(seq,
78345 "%8p %8p %-3d %-3d %-2d %-4d "
78346 "%4d %8d %8d %7d %5lu %-5d %5d ",
78347 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78348 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78349 + NULL, NULL,
78350 +#else
78351 + assoc, sk,
78352 +#endif
78353 + sctp_sk(sk)->type, sk->sk_state,
78354 assoc->state, hash,
78355 assoc->assoc_id,
78356 assoc->sndbuf_used,
78357 diff -urNp linux-2.6.39.1/net/sctp/socket.c linux-2.6.39.1/net/sctp/socket.c
78358 --- linux-2.6.39.1/net/sctp/socket.c 2011-05-19 00:06:34.000000000 -0400
78359 +++ linux-2.6.39.1/net/sctp/socket.c 2011-05-22 19:36:35.000000000 -0400
78360 @@ -4433,7 +4433,7 @@ static int sctp_getsockopt_peer_addrs(st
78361 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78362 if (space_left < addrlen)
78363 return -ENOMEM;
78364 - if (copy_to_user(to, &temp, addrlen))
78365 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78366 return -EFAULT;
78367 to += addrlen;
78368 cnt++;
78369 diff -urNp linux-2.6.39.1/net/socket.c linux-2.6.39.1/net/socket.c
78370 --- linux-2.6.39.1/net/socket.c 2011-06-03 00:04:14.000000000 -0400
78371 +++ linux-2.6.39.1/net/socket.c 2011-06-03 00:32:08.000000000 -0400
78372 @@ -88,6 +88,7 @@
78373 #include <linux/nsproxy.h>
78374 #include <linux/magic.h>
78375 #include <linux/slab.h>
78376 +#include <linux/in.h>
78377
78378 #include <asm/uaccess.h>
78379 #include <asm/unistd.h>
78380 @@ -105,6 +106,8 @@
78381 #include <linux/sockios.h>
78382 #include <linux/atalk.h>
78383
78384 +#include <linux/grsock.h>
78385 +
78386 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78387 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78388 unsigned long nr_segs, loff_t pos);
78389 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struc
78390 &sockfs_dentry_operations, SOCKFS_MAGIC);
78391 }
78392
78393 -static struct vfsmount *sock_mnt __read_mostly;
78394 +struct vfsmount *sock_mnt __read_mostly;
78395
78396 static struct file_system_type sock_fs_type = {
78397 .name = "sockfs",
78398 @@ -1179,6 +1182,8 @@ int __sock_create(struct net *net, int f
78399 return -EAFNOSUPPORT;
78400 if (type < 0 || type >= SOCK_MAX)
78401 return -EINVAL;
78402 + if (protocol < 0)
78403 + return -EINVAL;
78404
78405 /* Compatibility.
78406
78407 @@ -1311,6 +1316,16 @@ SYSCALL_DEFINE3(socket, int, family, int
78408 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78409 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78410
78411 + if(!gr_search_socket(family, type, protocol)) {
78412 + retval = -EACCES;
78413 + goto out;
78414 + }
78415 +
78416 + if (gr_handle_sock_all(family, type, protocol)) {
78417 + retval = -EACCES;
78418 + goto out;
78419 + }
78420 +
78421 retval = sock_create(family, type, protocol, &sock);
78422 if (retval < 0)
78423 goto out;
78424 @@ -1423,6 +1438,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78425 if (sock) {
78426 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78427 if (err >= 0) {
78428 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78429 + err = -EACCES;
78430 + goto error;
78431 + }
78432 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78433 + if (err)
78434 + goto error;
78435 +
78436 err = security_socket_bind(sock,
78437 (struct sockaddr *)&address,
78438 addrlen);
78439 @@ -1431,6 +1454,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78440 (struct sockaddr *)
78441 &address, addrlen);
78442 }
78443 +error:
78444 fput_light(sock->file, fput_needed);
78445 }
78446 return err;
78447 @@ -1454,10 +1478,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
78448 if ((unsigned)backlog > somaxconn)
78449 backlog = somaxconn;
78450
78451 + if (gr_handle_sock_server_other(sock->sk)) {
78452 + err = -EPERM;
78453 + goto error;
78454 + }
78455 +
78456 + err = gr_search_listen(sock);
78457 + if (err)
78458 + goto error;
78459 +
78460 err = security_socket_listen(sock, backlog);
78461 if (!err)
78462 err = sock->ops->listen(sock, backlog);
78463
78464 +error:
78465 fput_light(sock->file, fput_needed);
78466 }
78467 return err;
78468 @@ -1501,6 +1535,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78469 newsock->type = sock->type;
78470 newsock->ops = sock->ops;
78471
78472 + if (gr_handle_sock_server_other(sock->sk)) {
78473 + err = -EPERM;
78474 + sock_release(newsock);
78475 + goto out_put;
78476 + }
78477 +
78478 + err = gr_search_accept(sock);
78479 + if (err) {
78480 + sock_release(newsock);
78481 + goto out_put;
78482 + }
78483 +
78484 /*
78485 * We don't need try_module_get here, as the listening socket (sock)
78486 * has the protocol module (sock->ops->owner) held.
78487 @@ -1539,6 +1585,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78488 fd_install(newfd, newfile);
78489 err = newfd;
78490
78491 + gr_attach_curr_ip(newsock->sk);
78492 +
78493 out_put:
78494 fput_light(sock->file, fput_needed);
78495 out:
78496 @@ -1571,6 +1619,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78497 int, addrlen)
78498 {
78499 struct socket *sock;
78500 + struct sockaddr *sck;
78501 struct sockaddr_storage address;
78502 int err, fput_needed;
78503
78504 @@ -1581,6 +1630,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78505 if (err < 0)
78506 goto out_put;
78507
78508 + sck = (struct sockaddr *)&address;
78509 +
78510 + if (gr_handle_sock_client(sck)) {
78511 + err = -EACCES;
78512 + goto out_put;
78513 + }
78514 +
78515 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78516 + if (err)
78517 + goto out_put;
78518 +
78519 err =
78520 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78521 if (err)
78522 @@ -1882,6 +1942,8 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct
78523 int err, ctl_len, iov_size, total_len;
78524 int fput_needed;
78525
78526 + pax_track_stack();
78527 +
78528 err = -EFAULT;
78529 if (MSG_CMSG_COMPAT & flags) {
78530 if (get_compat_msghdr(&msg_sys, msg_compat))
78531 diff -urNp linux-2.6.39.1/net/sunrpc/sched.c linux-2.6.39.1/net/sunrpc/sched.c
78532 --- linux-2.6.39.1/net/sunrpc/sched.c 2011-05-19 00:06:34.000000000 -0400
78533 +++ linux-2.6.39.1/net/sunrpc/sched.c 2011-05-22 19:36:35.000000000 -0400
78534 @@ -234,9 +234,9 @@ static int rpc_wait_bit_killable(void *w
78535 #ifdef RPC_DEBUG
78536 static void rpc_task_set_debuginfo(struct rpc_task *task)
78537 {
78538 - static atomic_t rpc_pid;
78539 + static atomic_unchecked_t rpc_pid;
78540
78541 - task->tk_pid = atomic_inc_return(&rpc_pid);
78542 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78543 }
78544 #else
78545 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78546 diff -urNp linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma.c linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma.c
78547 --- linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-19 00:06:34.000000000 -0400
78548 +++ linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-22 19:36:35.000000000 -0400
78549 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCR
78550 static unsigned int min_max_inline = 4096;
78551 static unsigned int max_max_inline = 65536;
78552
78553 -atomic_t rdma_stat_recv;
78554 -atomic_t rdma_stat_read;
78555 -atomic_t rdma_stat_write;
78556 -atomic_t rdma_stat_sq_starve;
78557 -atomic_t rdma_stat_rq_starve;
78558 -atomic_t rdma_stat_rq_poll;
78559 -atomic_t rdma_stat_rq_prod;
78560 -atomic_t rdma_stat_sq_poll;
78561 -atomic_t rdma_stat_sq_prod;
78562 +atomic_unchecked_t rdma_stat_recv;
78563 +atomic_unchecked_t rdma_stat_read;
78564 +atomic_unchecked_t rdma_stat_write;
78565 +atomic_unchecked_t rdma_stat_sq_starve;
78566 +atomic_unchecked_t rdma_stat_rq_starve;
78567 +atomic_unchecked_t rdma_stat_rq_poll;
78568 +atomic_unchecked_t rdma_stat_rq_prod;
78569 +atomic_unchecked_t rdma_stat_sq_poll;
78570 +atomic_unchecked_t rdma_stat_sq_prod;
78571
78572 /* Temporary NFS request map and context caches */
78573 struct kmem_cache *svc_rdma_map_cachep;
78574 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *ta
78575 len -= *ppos;
78576 if (len > *lenp)
78577 len = *lenp;
78578 - if (len && copy_to_user(buffer, str_buf, len))
78579 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78580 return -EFAULT;
78581 *lenp = len;
78582 *ppos += len;
78583 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] =
78584 {
78585 .procname = "rdma_stat_read",
78586 .data = &rdma_stat_read,
78587 - .maxlen = sizeof(atomic_t),
78588 + .maxlen = sizeof(atomic_unchecked_t),
78589 .mode = 0644,
78590 .proc_handler = read_reset_stat,
78591 },
78592 {
78593 .procname = "rdma_stat_recv",
78594 .data = &rdma_stat_recv,
78595 - .maxlen = sizeof(atomic_t),
78596 + .maxlen = sizeof(atomic_unchecked_t),
78597 .mode = 0644,
78598 .proc_handler = read_reset_stat,
78599 },
78600 {
78601 .procname = "rdma_stat_write",
78602 .data = &rdma_stat_write,
78603 - .maxlen = sizeof(atomic_t),
78604 + .maxlen = sizeof(atomic_unchecked_t),
78605 .mode = 0644,
78606 .proc_handler = read_reset_stat,
78607 },
78608 {
78609 .procname = "rdma_stat_sq_starve",
78610 .data = &rdma_stat_sq_starve,
78611 - .maxlen = sizeof(atomic_t),
78612 + .maxlen = sizeof(atomic_unchecked_t),
78613 .mode = 0644,
78614 .proc_handler = read_reset_stat,
78615 },
78616 {
78617 .procname = "rdma_stat_rq_starve",
78618 .data = &rdma_stat_rq_starve,
78619 - .maxlen = sizeof(atomic_t),
78620 + .maxlen = sizeof(atomic_unchecked_t),
78621 .mode = 0644,
78622 .proc_handler = read_reset_stat,
78623 },
78624 {
78625 .procname = "rdma_stat_rq_poll",
78626 .data = &rdma_stat_rq_poll,
78627 - .maxlen = sizeof(atomic_t),
78628 + .maxlen = sizeof(atomic_unchecked_t),
78629 .mode = 0644,
78630 .proc_handler = read_reset_stat,
78631 },
78632 {
78633 .procname = "rdma_stat_rq_prod",
78634 .data = &rdma_stat_rq_prod,
78635 - .maxlen = sizeof(atomic_t),
78636 + .maxlen = sizeof(atomic_unchecked_t),
78637 .mode = 0644,
78638 .proc_handler = read_reset_stat,
78639 },
78640 {
78641 .procname = "rdma_stat_sq_poll",
78642 .data = &rdma_stat_sq_poll,
78643 - .maxlen = sizeof(atomic_t),
78644 + .maxlen = sizeof(atomic_unchecked_t),
78645 .mode = 0644,
78646 .proc_handler = read_reset_stat,
78647 },
78648 {
78649 .procname = "rdma_stat_sq_prod",
78650 .data = &rdma_stat_sq_prod,
78651 - .maxlen = sizeof(atomic_t),
78652 + .maxlen = sizeof(atomic_unchecked_t),
78653 .mode = 0644,
78654 .proc_handler = read_reset_stat,
78655 },
78656 diff -urNp linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78657 --- linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-19 00:06:34.000000000 -0400
78658 +++ linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-22 19:36:35.000000000 -0400
78659 @@ -499,7 +499,7 @@ next_sge:
78660 svc_rdma_put_context(ctxt, 0);
78661 goto out;
78662 }
78663 - atomic_inc(&rdma_stat_read);
78664 + atomic_inc_unchecked(&rdma_stat_read);
78665
78666 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78667 chl_map->ch[ch_no].count -= read_wr.num_sge;
78668 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78669 dto_q);
78670 list_del_init(&ctxt->dto_q);
78671 } else {
78672 - atomic_inc(&rdma_stat_rq_starve);
78673 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78674 clear_bit(XPT_DATA, &xprt->xpt_flags);
78675 ctxt = NULL;
78676 }
78677 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78678 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78679 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78680 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78681 - atomic_inc(&rdma_stat_recv);
78682 + atomic_inc_unchecked(&rdma_stat_recv);
78683
78684 /* Build up the XDR from the receive buffers. */
78685 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78686 diff -urNp linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_sendto.c linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78687 --- linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-19 00:06:34.000000000 -0400
78688 +++ linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-22 19:36:35.000000000 -0400
78689 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdm
78690 write_wr.wr.rdma.remote_addr = to;
78691
78692 /* Post It */
78693 - atomic_inc(&rdma_stat_write);
78694 + atomic_inc_unchecked(&rdma_stat_write);
78695 if (svc_rdma_send(xprt, &write_wr))
78696 goto err;
78697 return 0;
78698 diff -urNp linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_transport.c linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_transport.c
78699 --- linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-19 00:06:34.000000000 -0400
78700 +++ linux-2.6.39.1/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-22 19:36:35.000000000 -0400
78701 @@ -298,7 +298,7 @@ static void rq_cq_reap(struct svcxprt_rd
78702 return;
78703
78704 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78705 - atomic_inc(&rdma_stat_rq_poll);
78706 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78707
78708 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78709 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78710 @@ -320,7 +320,7 @@ static void rq_cq_reap(struct svcxprt_rd
78711 }
78712
78713 if (ctxt)
78714 - atomic_inc(&rdma_stat_rq_prod);
78715 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78716
78717 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78718 /*
78719 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rd
78720 return;
78721
78722 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78723 - atomic_inc(&rdma_stat_sq_poll);
78724 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78725 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78726 if (wc.status != IB_WC_SUCCESS)
78727 /* Close the transport */
78728 @@ -410,7 +410,7 @@ static void sq_cq_reap(struct svcxprt_rd
78729 }
78730
78731 if (ctxt)
78732 - atomic_inc(&rdma_stat_sq_prod);
78733 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78734 }
78735
78736 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78737 @@ -1271,7 +1271,7 @@ int svc_rdma_send(struct svcxprt_rdma *x
78738 spin_lock_bh(&xprt->sc_lock);
78739 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78740 spin_unlock_bh(&xprt->sc_lock);
78741 - atomic_inc(&rdma_stat_sq_starve);
78742 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78743
78744 /* See if we can opportunistically reap SQ WR to make room */
78745 sq_cq_reap(xprt);
78746 diff -urNp linux-2.6.39.1/net/sysctl_net.c linux-2.6.39.1/net/sysctl_net.c
78747 --- linux-2.6.39.1/net/sysctl_net.c 2011-05-19 00:06:34.000000000 -0400
78748 +++ linux-2.6.39.1/net/sysctl_net.c 2011-05-22 19:41:42.000000000 -0400
78749 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ct
78750 struct ctl_table *table)
78751 {
78752 /* Allow network administrator to have same access as root. */
78753 - if (capable(CAP_NET_ADMIN)) {
78754 + if (capable_nolog(CAP_NET_ADMIN)) {
78755 int mode = (table->mode >> 6) & 7;
78756 return (mode << 6) | (mode << 3) | mode;
78757 }
78758 diff -urNp linux-2.6.39.1/net/unix/af_unix.c linux-2.6.39.1/net/unix/af_unix.c
78759 --- linux-2.6.39.1/net/unix/af_unix.c 2011-05-19 00:06:34.000000000 -0400
78760 +++ linux-2.6.39.1/net/unix/af_unix.c 2011-05-22 19:41:42.000000000 -0400
78761 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(stru
78762 err = -ECONNREFUSED;
78763 if (!S_ISSOCK(inode->i_mode))
78764 goto put_fail;
78765 +
78766 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78767 + err = -EACCES;
78768 + goto put_fail;
78769 + }
78770 +
78771 u = unix_find_socket_byinode(inode);
78772 if (!u)
78773 goto put_fail;
78774 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(stru
78775 if (u) {
78776 struct dentry *dentry;
78777 dentry = unix_sk(u)->dentry;
78778 +
78779 + if (!gr_handle_chroot_unix(u->sk_peer_pid)) {
78780 + err = -EPERM;
78781 + sock_put(u);
78782 + goto fail;
78783 + }
78784 +
78785 if (dentry)
78786 touch_atime(unix_sk(u)->mnt, dentry);
78787 } else
78788 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock
78789 err = security_path_mknod(&nd.path, dentry, mode, 0);
78790 if (err)
78791 goto out_mknod_drop_write;
78792 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
78793 + err = -EACCES;
78794 + goto out_mknod_drop_write;
78795 + }
78796 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
78797 out_mknod_drop_write:
78798 mnt_drop_write(nd.path.mnt);
78799 if (err)
78800 goto out_mknod_dput;
78801 +
78802 + gr_handle_create(dentry, nd.path.mnt);
78803 +
78804 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
78805 dput(nd.path.dentry);
78806 nd.path.dentry = dentry;
78807 @@ -894,6 +914,11 @@ out_mknod_drop_write:
78808 goto out_unlock;
78809 }
78810
78811 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78812 + put_pid(sk->sk_peer_pid);
78813 + sk->sk_peer_pid = get_pid(task_tgid(current));
78814 +#endif
78815 +
78816 list = &unix_socket_table[addr->hash];
78817 } else {
78818 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
78819 @@ -2255,7 +2280,11 @@ static int unix_seq_show(struct seq_file
78820 unix_state_lock(s);
78821
78822 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
78823 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78824 + NULL,
78825 +#else
78826 s,
78827 +#endif
78828 atomic_read(&s->sk_refcnt),
78829 0,
78830 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
78831 diff -urNp linux-2.6.39.1/net/wireless/wext-core.c linux-2.6.39.1/net/wireless/wext-core.c
78832 --- linux-2.6.39.1/net/wireless/wext-core.c 2011-05-19 00:06:34.000000000 -0400
78833 +++ linux-2.6.39.1/net/wireless/wext-core.c 2011-05-22 19:36:35.000000000 -0400
78834 @@ -746,8 +746,7 @@ static int ioctl_standard_iw_point(struc
78835 */
78836
78837 /* Support for very large requests */
78838 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78839 - (user_length > descr->max_tokens)) {
78840 + if (user_length > descr->max_tokens) {
78841 /* Allow userspace to GET more than max so
78842 * we can support any size GET requests.
78843 * There is still a limit : -ENOMEM.
78844 @@ -784,22 +783,6 @@ static int ioctl_standard_iw_point(struc
78845 }
78846 }
78847
78848 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78849 - /*
78850 - * If this is a GET, but not NOMAX, it means that the extra
78851 - * data is not bounded by userspace, but by max_tokens. Thus
78852 - * set the length to max_tokens. This matches the extra data
78853 - * allocation.
78854 - * The driver should fill it with the number of tokens it
78855 - * provided, and it may check iwp->length rather than having
78856 - * knowledge of max_tokens. If the driver doesn't change the
78857 - * iwp->length, this ioctl just copies back max_token tokens
78858 - * filled with zeroes. Hopefully the driver isn't claiming
78859 - * them to be valid data.
78860 - */
78861 - iwp->length = descr->max_tokens;
78862 - }
78863 -
78864 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78865
78866 iwp->length += essid_compat;
78867 diff -urNp linux-2.6.39.1/net/xfrm/xfrm_policy.c linux-2.6.39.1/net/xfrm/xfrm_policy.c
78868 --- linux-2.6.39.1/net/xfrm/xfrm_policy.c 2011-05-19 00:06:34.000000000 -0400
78869 +++ linux-2.6.39.1/net/xfrm/xfrm_policy.c 2011-05-22 19:36:35.000000000 -0400
78870 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm
78871 {
78872 policy->walk.dead = 1;
78873
78874 - atomic_inc(&policy->genid);
78875 + atomic_inc_unchecked(&policy->genid);
78876
78877 if (del_timer(&policy->timer))
78878 xfrm_pol_put(policy);
78879 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct x
78880 hlist_add_head(&policy->bydst, chain);
78881 xfrm_pol_hold(policy);
78882 net->xfrm.policy_count[dir]++;
78883 - atomic_inc(&flow_cache_genid);
78884 + atomic_inc_unchecked(&flow_cache_genid);
78885 if (delpol)
78886 __xfrm_policy_unlink(delpol, dir);
78887 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78888 @@ -1527,7 +1527,7 @@ free_dst:
78889 goto out;
78890 }
78891
78892 -static int inline
78893 +static inline int
78894 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78895 {
78896 if (!*target) {
78897 @@ -1539,7 +1539,7 @@ xfrm_dst_alloc_copy(void **target, const
78898 return 0;
78899 }
78900
78901 -static int inline
78902 +static inline int
78903 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78904 {
78905 #ifdef CONFIG_XFRM_SUB_POLICY
78906 @@ -1551,7 +1551,7 @@ xfrm_dst_update_parent(struct dst_entry
78907 #endif
78908 }
78909
78910 -static int inline
78911 +static inline int
78912 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78913 {
78914 #ifdef CONFIG_XFRM_SUB_POLICY
78915 @@ -1645,7 +1645,7 @@ xfrm_resolve_and_create_bundle(struct xf
78916
78917 xdst->num_pols = num_pols;
78918 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78919 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78920 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78921
78922 return xdst;
78923 }
78924 @@ -2332,7 +2332,7 @@ static int xfrm_bundle_ok(struct xfrm_ds
78925 if (xdst->xfrm_genid != dst->xfrm->genid)
78926 return 0;
78927 if (xdst->num_pols > 0 &&
78928 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78929 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78930 return 0;
78931
78932 mtu = dst_mtu(dst->child);
78933 @@ -2860,7 +2860,7 @@ static int xfrm_policy_migrate(struct xf
78934 sizeof(pol->xfrm_vec[i].saddr));
78935 pol->xfrm_vec[i].encap_family = mp->new_family;
78936 /* flush bundles */
78937 - atomic_inc(&pol->genid);
78938 + atomic_inc_unchecked(&pol->genid);
78939 }
78940 }
78941
78942 diff -urNp linux-2.6.39.1/net/xfrm/xfrm_user.c linux-2.6.39.1/net/xfrm/xfrm_user.c
78943 --- linux-2.6.39.1/net/xfrm/xfrm_user.c 2011-05-19 00:06:34.000000000 -0400
78944 +++ linux-2.6.39.1/net/xfrm/xfrm_user.c 2011-05-22 19:36:35.000000000 -0400
78945 @@ -1394,6 +1394,8 @@ static int copy_to_user_tmpl(struct xfrm
78946 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
78947 int i;
78948
78949 + pax_track_stack();
78950 +
78951 if (xp->xfrm_nr == 0)
78952 return 0;
78953
78954 @@ -2062,6 +2064,8 @@ static int xfrm_do_migrate(struct sk_buf
78955 int err;
78956 int n = 0;
78957
78958 + pax_track_stack();
78959 +
78960 if (attrs[XFRMA_MIGRATE] == NULL)
78961 return -EINVAL;
78962
78963 diff -urNp linux-2.6.39.1/scripts/basic/fixdep.c linux-2.6.39.1/scripts/basic/fixdep.c
78964 --- linux-2.6.39.1/scripts/basic/fixdep.c 2011-05-19 00:06:34.000000000 -0400
78965 +++ linux-2.6.39.1/scripts/basic/fixdep.c 2011-05-22 19:36:35.000000000 -0400
78966 @@ -235,9 +235,9 @@ static void use_config(const char *m, in
78967
78968 static void parse_config_file(const char *map, size_t len)
78969 {
78970 - const int *end = (const int *) (map + len);
78971 + const unsigned int *end = (const unsigned int *) (map + len);
78972 /* start at +1, so that p can never be < map */
78973 - const int *m = (const int *) map + 1;
78974 + const unsigned int *m = (const unsigned int *) map + 1;
78975 const char *p, *q;
78976
78977 for (; m < end; m++) {
78978 @@ -405,7 +405,7 @@ static void print_deps(void)
78979 static void traps(void)
78980 {
78981 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78982 - int *p = (int *)test;
78983 + unsigned int *p = (unsigned int *)test;
78984
78985 if (*p != INT_CONF) {
78986 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78987 diff -urNp linux-2.6.39.1/scripts/dtc/flattree.c linux-2.6.39.1/scripts/dtc/flattree.c
78988 --- linux-2.6.39.1/scripts/dtc/flattree.c 2011-05-19 00:06:34.000000000 -0400
78989 +++ linux-2.6.39.1/scripts/dtc/flattree.c 2011-05-22 19:36:35.000000000 -0400
78990 @@ -104,7 +104,7 @@ static void bin_emit_property(void *e, s
78991 bin_emit_cell(e, FDT_PROP);
78992 }
78993
78994 -static struct emitter bin_emitter = {
78995 +static const struct emitter bin_emitter = {
78996 .cell = bin_emit_cell,
78997 .string = bin_emit_string,
78998 .align = bin_emit_align,
78999 @@ -230,7 +230,7 @@ static void asm_emit_property(void *e, s
79000 asm_emit_cell(e, FDT_PROP);
79001 }
79002
79003 -static struct emitter asm_emitter = {
79004 +static const struct emitter asm_emitter = {
79005 .cell = asm_emit_cell,
79006 .string = asm_emit_string,
79007 .align = asm_emit_align,
79008 diff -urNp linux-2.6.39.1/scripts/Makefile.build linux-2.6.39.1/scripts/Makefile.build
79009 --- linux-2.6.39.1/scripts/Makefile.build 2011-05-19 00:06:34.000000000 -0400
79010 +++ linux-2.6.39.1/scripts/Makefile.build 2011-06-03 01:15:00.000000000 -0400
79011 @@ -93,7 +93,7 @@ endif
79012 endif
79013
79014 # Do not include host rules unless needed
79015 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79016 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
79017 include scripts/Makefile.host
79018 endif
79019
79020 diff -urNp linux-2.6.39.1/scripts/Makefile.clean linux-2.6.39.1/scripts/Makefile.clean
79021 --- linux-2.6.39.1/scripts/Makefile.clean 2011-05-19 00:06:34.000000000 -0400
79022 +++ linux-2.6.39.1/scripts/Makefile.clean 2011-06-03 01:16:02.000000000 -0400
79023 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subd
79024 __clean-files := $(extra-y) $(always) \
79025 $(targets) $(clean-files) \
79026 $(host-progs) \
79027 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79028 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79029 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79030
79031 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79032
79033 diff -urNp linux-2.6.39.1/scripts/Makefile.host linux-2.6.39.1/scripts/Makefile.host
79034 --- linux-2.6.39.1/scripts/Makefile.host 2011-05-19 00:06:34.000000000 -0400
79035 +++ linux-2.6.39.1/scripts/Makefile.host 2011-06-03 01:17:12.000000000 -0400
79036 @@ -31,6 +31,7 @@
79037 # Note: Shared libraries consisting of C++ files are not supported
79038
79039 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79040 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79041
79042 # C code
79043 # Executables compiled from a single .c file
79044 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(hos
79045 # Shared libaries (only .c supported)
79046 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79047 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79048 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79049 # Remove .so files from "xxx-objs"
79050 host-cobjs := $(filter-out %.so,$(host-cobjs))
79051
79052 diff -urNp linux-2.6.39.1/scripts/mod/file2alias.c linux-2.6.39.1/scripts/mod/file2alias.c
79053 --- linux-2.6.39.1/scripts/mod/file2alias.c 2011-05-19 00:06:34.000000000 -0400
79054 +++ linux-2.6.39.1/scripts/mod/file2alias.c 2011-05-22 19:36:35.000000000 -0400
79055 @@ -72,7 +72,7 @@ static void device_id_check(const char *
79056 unsigned long size, unsigned long id_size,
79057 void *symval)
79058 {
79059 - int i;
79060 + unsigned int i;
79061
79062 if (size % id_size || size < id_size) {
79063 if (cross_build != 0)
79064 @@ -102,7 +102,7 @@ static void device_id_check(const char *
79065 /* USB is special because the bcdDevice can be matched against a numeric range */
79066 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79067 static void do_usb_entry(struct usb_device_id *id,
79068 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79069 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79070 unsigned char range_lo, unsigned char range_hi,
79071 unsigned char max, struct module *mod)
79072 {
79073 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *sy
79074 for (i = 0; i < count; i++) {
79075 const char *id = (char *)devs[i].id;
79076 char acpi_id[sizeof(devs[0].id)];
79077 - int j;
79078 + unsigned int j;
79079
79080 buf_printf(&mod->dev_table_buf,
79081 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79082 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *sy
79083
79084 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79085 const char *id = (char *)card->devs[j].id;
79086 - int i2, j2;
79087 + unsigned int i2, j2;
79088 int dup = 0;
79089
79090 if (!id[0])
79091 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *sy
79092 /* add an individual alias for every device entry */
79093 if (!dup) {
79094 char acpi_id[sizeof(card->devs[0].id)];
79095 - int k;
79096 + unsigned int k;
79097
79098 buf_printf(&mod->dev_table_buf,
79099 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79100 @@ -768,7 +768,7 @@ static void dmi_ascii_filter(char *d, co
79101 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79102 char *alias)
79103 {
79104 - int i, j;
79105 + unsigned int i, j;
79106
79107 sprintf(alias, "dmi*");
79108
79109 diff -urNp linux-2.6.39.1/scripts/mod/modpost.c linux-2.6.39.1/scripts/mod/modpost.c
79110 --- linux-2.6.39.1/scripts/mod/modpost.c 2011-05-19 00:06:34.000000000 -0400
79111 +++ linux-2.6.39.1/scripts/mod/modpost.c 2011-05-22 19:36:35.000000000 -0400
79112 @@ -896,6 +896,7 @@ enum mismatch {
79113 ANY_INIT_TO_ANY_EXIT,
79114 ANY_EXIT_TO_ANY_INIT,
79115 EXPORT_TO_INIT_EXIT,
79116 + DATA_TO_TEXT
79117 };
79118
79119 struct sectioncheck {
79120 @@ -1004,6 +1005,12 @@ const struct sectioncheck sectioncheck[]
79121 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79122 .mismatch = EXPORT_TO_INIT_EXIT,
79123 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79124 +},
79125 +/* Do not reference code from writable data */
79126 +{
79127 + .fromsec = { DATA_SECTIONS, NULL },
79128 + .tosec = { TEXT_SECTIONS, NULL },
79129 + .mismatch = DATA_TO_TEXT
79130 }
79131 };
79132
79133 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct e
79134 continue;
79135 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79136 continue;
79137 - if (sym->st_value == addr)
79138 - return sym;
79139 /* Find a symbol nearby - addr are maybe negative */
79140 d = sym->st_value - addr;
79141 + if (d == 0)
79142 + return sym;
79143 if (d < 0)
79144 d = addr - sym->st_value;
79145 if (d < distance) {
79146 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const ch
79147 tosym, prl_to, prl_to, tosym);
79148 free(prl_to);
79149 break;
79150 + case DATA_TO_TEXT:
79151 +/*
79152 + fprintf(stderr,
79153 + "The variable %s references\n"
79154 + "the %s %s%s%s\n",
79155 + fromsym, to, sec2annotation(tosec), tosym, to_p);
79156 +*/
79157 + break;
79158 }
79159 fprintf(stderr, "\n");
79160 }
79161 @@ -1731,7 +1746,7 @@ void __attribute__((format(printf, 2, 3)
79162 va_end(ap);
79163 }
79164
79165 -void buf_write(struct buffer *buf, const char *s, int len)
79166 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79167 {
79168 if (buf->size - buf->pos < len) {
79169 buf->size += len + SZ;
79170 @@ -1943,7 +1958,7 @@ static void write_if_changed(struct buff
79171 if (fstat(fileno(file), &st) < 0)
79172 goto close_write;
79173
79174 - if (st.st_size != b->pos)
79175 + if (st.st_size != (off_t)b->pos)
79176 goto close_write;
79177
79178 tmp = NOFAIL(malloc(b->pos));
79179 diff -urNp linux-2.6.39.1/scripts/mod/modpost.h linux-2.6.39.1/scripts/mod/modpost.h
79180 --- linux-2.6.39.1/scripts/mod/modpost.h 2011-05-19 00:06:34.000000000 -0400
79181 +++ linux-2.6.39.1/scripts/mod/modpost.h 2011-05-22 19:36:35.000000000 -0400
79182 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *e
79183
79184 struct buffer {
79185 char *p;
79186 - int pos;
79187 - int size;
79188 + unsigned int pos;
79189 + unsigned int size;
79190 };
79191
79192 void __attribute__((format(printf, 2, 3)))
79193 buf_printf(struct buffer *buf, const char *fmt, ...);
79194
79195 void
79196 -buf_write(struct buffer *buf, const char *s, int len);
79197 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79198
79199 struct module {
79200 struct module *next;
79201 diff -urNp linux-2.6.39.1/scripts/mod/sumversion.c linux-2.6.39.1/scripts/mod/sumversion.c
79202 --- linux-2.6.39.1/scripts/mod/sumversion.c 2011-05-19 00:06:34.000000000 -0400
79203 +++ linux-2.6.39.1/scripts/mod/sumversion.c 2011-05-22 19:36:35.000000000 -0400
79204 @@ -470,7 +470,7 @@ static void write_version(const char *fi
79205 goto out;
79206 }
79207
79208 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79209 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79210 warn("writing sum in %s failed: %s\n",
79211 filename, strerror(errno));
79212 goto out;
79213 diff -urNp linux-2.6.39.1/scripts/pnmtologo.c linux-2.6.39.1/scripts/pnmtologo.c
79214 --- linux-2.6.39.1/scripts/pnmtologo.c 2011-05-19 00:06:34.000000000 -0400
79215 +++ linux-2.6.39.1/scripts/pnmtologo.c 2011-05-22 19:36:35.000000000 -0400
79216 @@ -237,14 +237,14 @@ static void write_header(void)
79217 fprintf(out, " * Linux logo %s\n", logoname);
79218 fputs(" */\n\n", out);
79219 fputs("#include <linux/linux_logo.h>\n\n", out);
79220 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79221 + fprintf(out, "static unsigned char %s_data[] = {\n",
79222 logoname);
79223 }
79224
79225 static void write_footer(void)
79226 {
79227 fputs("\n};\n\n", out);
79228 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79229 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79230 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79231 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79232 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79233 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79234 fputs("\n};\n\n", out);
79235
79236 /* write logo clut */
79237 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79238 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79239 logoname);
79240 write_hex_cnt = 0;
79241 for (i = 0; i < logo_clutsize; i++) {
79242 diff -urNp linux-2.6.39.1/security/apparmor/lsm.c linux-2.6.39.1/security/apparmor/lsm.c
79243 --- linux-2.6.39.1/security/apparmor/lsm.c 2011-06-03 00:04:14.000000000 -0400
79244 +++ linux-2.6.39.1/security/apparmor/lsm.c 2011-06-03 00:32:08.000000000 -0400
79245 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struc
79246 return error;
79247 }
79248
79249 -static struct security_operations apparmor_ops = {
79250 +static struct security_operations apparmor_ops __read_only = {
79251 .name = "apparmor",
79252
79253 .ptrace_access_check = apparmor_ptrace_access_check,
79254 @@ -672,7 +672,7 @@ static struct security_operations apparm
79255 static int param_set_aabool(const char *val, const struct kernel_param *kp);
79256 static int param_get_aabool(char *buffer, const struct kernel_param *kp);
79257 #define param_check_aabool(name, p) __param_check(name, p, int)
79258 -static struct kernel_param_ops param_ops_aabool = {
79259 +static const struct kernel_param_ops param_ops_aabool = {
79260 .set = param_set_aabool,
79261 .get = param_get_aabool
79262 };
79263 @@ -680,7 +680,7 @@ static struct kernel_param_ops param_ops
79264 static int param_set_aauint(const char *val, const struct kernel_param *kp);
79265 static int param_get_aauint(char *buffer, const struct kernel_param *kp);
79266 #define param_check_aauint(name, p) __param_check(name, p, int)
79267 -static struct kernel_param_ops param_ops_aauint = {
79268 +static const struct kernel_param_ops param_ops_aauint = {
79269 .set = param_set_aauint,
79270 .get = param_get_aauint
79271 };
79272 @@ -688,7 +688,7 @@ static struct kernel_param_ops param_ops
79273 static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp);
79274 static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp);
79275 #define param_check_aalockpolicy(name, p) __param_check(name, p, int)
79276 -static struct kernel_param_ops param_ops_aalockpolicy = {
79277 +static const struct kernel_param_ops param_ops_aalockpolicy = {
79278 .set = param_set_aalockpolicy,
79279 .get = param_get_aalockpolicy
79280 };
79281 diff -urNp linux-2.6.39.1/security/commoncap.c linux-2.6.39.1/security/commoncap.c
79282 --- linux-2.6.39.1/security/commoncap.c 2011-05-19 00:06:34.000000000 -0400
79283 +++ linux-2.6.39.1/security/commoncap.c 2011-05-22 20:28:59.000000000 -0400
79284 @@ -28,6 +28,7 @@
79285 #include <linux/prctl.h>
79286 #include <linux/securebits.h>
79287 #include <linux/user_namespace.h>
79288 +#include <net/sock.h>
79289
79290 /*
79291 * If a non-root user executes a setuid-root binary in
79292 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, st
79293
79294 int cap_netlink_recv(struct sk_buff *skb, int cap)
79295 {
79296 - if (!cap_raised(current_cap(), cap))
79297 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
79298 return -EPERM;
79299 return 0;
79300 }
79301 @@ -580,6 +581,9 @@ int cap_bprm_secureexec(struct linux_bin
79302 {
79303 const struct cred *cred = current_cred();
79304
79305 + if (gr_acl_enable_at_secure())
79306 + return 1;
79307 +
79308 if (cred->uid != 0) {
79309 if (bprm->cap_effective)
79310 return 1;
79311 diff -urNp linux-2.6.39.1/security/integrity/ima/ima_api.c linux-2.6.39.1/security/integrity/ima/ima_api.c
79312 --- linux-2.6.39.1/security/integrity/ima/ima_api.c 2011-05-19 00:06:34.000000000 -0400
79313 +++ linux-2.6.39.1/security/integrity/ima/ima_api.c 2011-05-22 19:36:35.000000000 -0400
79314 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *ino
79315 int result;
79316
79317 /* can overflow, only indicator */
79318 - atomic_long_inc(&ima_htable.violations);
79319 + atomic_long_inc_unchecked(&ima_htable.violations);
79320
79321 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79322 if (!entry) {
79323 diff -urNp linux-2.6.39.1/security/integrity/ima/ima_fs.c linux-2.6.39.1/security/integrity/ima/ima_fs.c
79324 --- linux-2.6.39.1/security/integrity/ima/ima_fs.c 2011-05-19 00:06:34.000000000 -0400
79325 +++ linux-2.6.39.1/security/integrity/ima/ima_fs.c 2011-05-22 19:36:35.000000000 -0400
79326 @@ -28,12 +28,12 @@
79327 static int valid_policy = 1;
79328 #define TMPBUFLEN 12
79329 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79330 - loff_t *ppos, atomic_long_t *val)
79331 + loff_t *ppos, atomic_long_unchecked_t *val)
79332 {
79333 char tmpbuf[TMPBUFLEN];
79334 ssize_t len;
79335
79336 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79337 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79338 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79339 }
79340
79341 diff -urNp linux-2.6.39.1/security/integrity/ima/ima.h linux-2.6.39.1/security/integrity/ima/ima.h
79342 --- linux-2.6.39.1/security/integrity/ima/ima.h 2011-05-19 00:06:34.000000000 -0400
79343 +++ linux-2.6.39.1/security/integrity/ima/ima.h 2011-05-22 19:36:35.000000000 -0400
79344 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *ino
79345 extern spinlock_t ima_queue_lock;
79346
79347 struct ima_h_table {
79348 - atomic_long_t len; /* number of stored measurements in the list */
79349 - atomic_long_t violations;
79350 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79351 + atomic_long_unchecked_t violations;
79352 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79353 };
79354 extern struct ima_h_table ima_htable;
79355 diff -urNp linux-2.6.39.1/security/integrity/ima/ima_queue.c linux-2.6.39.1/security/integrity/ima/ima_queue.c
79356 --- linux-2.6.39.1/security/integrity/ima/ima_queue.c 2011-05-19 00:06:34.000000000 -0400
79357 +++ linux-2.6.39.1/security/integrity/ima/ima_queue.c 2011-05-22 19:36:35.000000000 -0400
79358 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct i
79359 INIT_LIST_HEAD(&qe->later);
79360 list_add_tail_rcu(&qe->later, &ima_measurements);
79361
79362 - atomic_long_inc(&ima_htable.len);
79363 + atomic_long_inc_unchecked(&ima_htable.len);
79364 key = ima_hash_key(entry->digest);
79365 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79366 return 0;
79367 diff -urNp linux-2.6.39.1/security/Kconfig linux-2.6.39.1/security/Kconfig
79368 --- linux-2.6.39.1/security/Kconfig 2011-05-19 00:06:34.000000000 -0400
79369 +++ linux-2.6.39.1/security/Kconfig 2011-06-03 01:13:26.000000000 -0400
79370 @@ -4,6 +4,554 @@
79371
79372 menu "Security options"
79373
79374 +source grsecurity/Kconfig
79375 +
79376 +menu "PaX"
79377 +
79378 + config ARCH_TRACK_EXEC_LIMIT
79379 + bool
79380 +
79381 + config PAX_PER_CPU_PGD
79382 + bool
79383 +
79384 + config TASK_SIZE_MAX_SHIFT
79385 + int
79386 + depends on X86_64
79387 + default 47 if !PAX_PER_CPU_PGD
79388 + default 42 if PAX_PER_CPU_PGD
79389 +
79390 + config PAX_ENABLE_PAE
79391 + bool
79392 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79393 +
79394 +config PAX
79395 + bool "Enable various PaX features"
79396 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79397 + help
79398 + This allows you to enable various PaX features. PaX adds
79399 + intrusion prevention mechanisms to the kernel that reduce
79400 + the risks posed by exploitable memory corruption bugs.
79401 +
79402 +menu "PaX Control"
79403 + depends on PAX
79404 +
79405 +config PAX_SOFTMODE
79406 + bool 'Support soft mode'
79407 + select PAX_PT_PAX_FLAGS
79408 + help
79409 + Enabling this option will allow you to run PaX in soft mode, that
79410 + is, PaX features will not be enforced by default, only on executables
79411 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
79412 + is the only way to mark executables for soft mode use.
79413 +
79414 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79415 + line option on boot. Furthermore you can control various PaX features
79416 + at runtime via the entries in /proc/sys/kernel/pax.
79417 +
79418 +config PAX_EI_PAX
79419 + bool 'Use legacy ELF header marking'
79420 + help
79421 + Enabling this option will allow you to control PaX features on
79422 + a per executable basis via the 'chpax' utility available at
79423 + http://pax.grsecurity.net/. The control flags will be read from
79424 + an otherwise reserved part of the ELF header. This marking has
79425 + numerous drawbacks (no support for soft-mode, toolchain does not
79426 + know about the non-standard use of the ELF header) therefore it
79427 + has been deprecated in favour of PT_PAX_FLAGS support.
79428 +
79429 + Note that if you enable PT_PAX_FLAGS marking support as well,
79430 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
79431 +
79432 +config PAX_PT_PAX_FLAGS
79433 + bool 'Use ELF program header marking'
79434 + help
79435 + Enabling this option will allow you to control PaX features on
79436 + a per executable basis via the 'paxctl' utility available at
79437 + http://pax.grsecurity.net/. The control flags will be read from
79438 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79439 + has the benefits of supporting both soft mode and being fully
79440 + integrated into the toolchain (the binutils patch is available
79441 + from http://pax.grsecurity.net).
79442 +
79443 + If your toolchain does not support PT_PAX_FLAGS markings,
79444 + you can create one in most cases with 'paxctl -C'.
79445 +
79446 + Note that if you enable the legacy EI_PAX marking support as well,
79447 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79448 +
79449 +choice
79450 + prompt 'MAC system integration'
79451 + default PAX_HAVE_ACL_FLAGS
79452 + help
79453 + Mandatory Access Control systems have the option of controlling
79454 + PaX flags on a per executable basis, choose the method supported
79455 + by your particular system.
79456 +
79457 + - "none": if your MAC system does not interact with PaX,
79458 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79459 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79460 +
79461 + NOTE: this option is for developers/integrators only.
79462 +
79463 + config PAX_NO_ACL_FLAGS
79464 + bool 'none'
79465 +
79466 + config PAX_HAVE_ACL_FLAGS
79467 + bool 'direct'
79468 +
79469 + config PAX_HOOK_ACL_FLAGS
79470 + bool 'hook'
79471 +endchoice
79472 +
79473 +endmenu
79474 +
79475 +menu "Non-executable pages"
79476 + depends on PAX
79477 +
79478 +config PAX_NOEXEC
79479 + bool "Enforce non-executable pages"
79480 + depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
79481 + help
79482 + By design some architectures do not allow for protecting memory
79483 + pages against execution or even if they do, Linux does not make
79484 + use of this feature. In practice this means that if a page is
79485 + readable (such as the stack or heap) it is also executable.
79486 +
79487 + There is a well known exploit technique that makes use of this
79488 + fact and a common programming mistake where an attacker can
79489 + introduce code of his choice somewhere in the attacked program's
79490 + memory (typically the stack or the heap) and then execute it.
79491 +
79492 + If the attacked program was running with different (typically
79493 + higher) privileges than that of the attacker, then he can elevate
79494 + his own privilege level (e.g. get a root shell, write to files for
79495 + which he does not have write access to, etc).
79496 +
79497 + Enabling this option will let you choose from various features
79498 + that prevent the injection and execution of 'foreign' code in
79499 + a program.
79500 +
79501 + This will also break programs that rely on the old behaviour and
79502 + expect that dynamically allocated memory via the malloc() family
79503 + of functions is executable (which it is not). Notable examples
79504 + are the XFree86 4.x server, the java runtime and wine.
79505 +
79506 +config PAX_PAGEEXEC
79507 + bool "Paging based non-executable pages"
79508 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
79509 + select S390_SWITCH_AMODE if S390
79510 + select S390_EXEC_PROTECT if S390
79511 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79512 + help
79513 + This implementation is based on the paging feature of the CPU.
79514 + On i386 without hardware non-executable bit support there is a
79515 + variable but usually low performance impact, however on Intel's
79516 + P4 core based CPUs it is very high so you should not enable this
79517 + for kernels meant to be used on such CPUs.
79518 +
79519 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79520 + with hardware non-executable bit support there is no performance
79521 + impact, on ppc the impact is negligible.
79522 +
79523 + Note that several architectures require various emulations due to
79524 + badly designed userland ABIs, this will cause a performance impact
79525 + but will disappear as soon as userland is fixed. For example, ppc
79526 + userland MUST have been built with secure-plt by a recent toolchain.
79527 +
79528 +config PAX_SEGMEXEC
79529 + bool "Segmentation based non-executable pages"
79530 + depends on PAX_NOEXEC && X86_32
79531 + help
79532 + This implementation is based on the segmentation feature of the
79533 + CPU and has a very small performance impact, however applications
79534 + will be limited to a 1.5 GB address space instead of the normal
79535 + 3 GB.
79536 +
79537 +config PAX_EMUTRAMP
79538 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79539 + default y if PARISC
79540 + help
79541 + There are some programs and libraries that for one reason or
79542 + another attempt to execute special small code snippets from
79543 + non-executable memory pages. Most notable examples are the
79544 + signal handler return code generated by the kernel itself and
79545 + the GCC trampolines.
79546 +
79547 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79548 + such programs will no longer work under your kernel.
79549 +
79550 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79551 + utilities to enable trampoline emulation for the affected programs
79552 + yet still have the protection provided by the non-executable pages.
79553 +
79554 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79555 + your system will not even boot.
79556 +
79557 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79558 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79559 + for the affected files.
79560 +
79561 + NOTE: enabling this feature *may* open up a loophole in the
79562 + protection provided by non-executable pages that an attacker
79563 + could abuse. Therefore the best solution is to not have any
79564 + files on your system that would require this option. This can
79565 + be achieved by not using libc5 (which relies on the kernel
79566 + signal handler return code) and not using or rewriting programs
79567 + that make use of the nested function implementation of GCC.
79568 + Skilled users can just fix GCC itself so that it implements
79569 + nested function calls in a way that does not interfere with PaX.
79570 +
79571 +config PAX_EMUSIGRT
79572 + bool "Automatically emulate sigreturn trampolines"
79573 + depends on PAX_EMUTRAMP && PARISC
79574 + default y
79575 + help
79576 + Enabling this option will have the kernel automatically detect
79577 + and emulate signal return trampolines executing on the stack
79578 + that would otherwise lead to task termination.
79579 +
79580 + This solution is intended as a temporary one for users with
79581 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79582 + Modula-3 runtime, etc) or executables linked to such, basically
79583 + everything that does not specify its own SA_RESTORER function in
79584 + normal executable memory like glibc 2.1+ does.
79585 +
79586 + On parisc you MUST enable this option, otherwise your system will
79587 + not even boot.
79588 +
79589 + NOTE: this feature cannot be disabled on a per executable basis
79590 + and since it *does* open up a loophole in the protection provided
79591 + by non-executable pages, the best solution is to not have any
79592 + files on your system that would require this option.
79593 +
79594 +config PAX_MPROTECT
79595 + bool "Restrict mprotect()"
79596 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79597 + help
79598 + Enabling this option will prevent programs from
79599 + - changing the executable status of memory pages that were
79600 + not originally created as executable,
79601 + - making read-only executable pages writable again,
79602 + - creating executable pages from anonymous memory,
79603 + - making read-only-after-relocations (RELRO) data pages writable again.
79604 +
79605 + You should say Y here to complete the protection provided by
79606 + the enforcement of non-executable pages.
79607 +
79608 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79609 + this feature on a per file basis.
79610 +
79611 +config PAX_MPROTECT_COMPAT
79612 + bool "Use legacy/compat protection demoting (read help)"
79613 + depends on PAX_MPROTECT
79614 + default n
79615 + help
79616 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79617 + by sending the proper error code to the application. For some broken
79618 + userland, this can cause problems with Python or other applications. The
79619 + current implementation however allows for applications like clamav to
79620 + detect if JIT compilation/execution is allowed and to fall back gracefully
79621 + to an interpreter-based mode if it does not. While we encourage everyone
79622 + to use the current implementation as-is and push upstream to fix broken
79623 + userland (note that the RWX logging option can assist with this), in some
79624 + environments this may not be possible. Having to disable MPROTECT
79625 + completely on certain binaries reduces the security benefit of PaX,
79626 + so this option is provided for those environments to revert to the old
79627 + behavior.
79628 +
79629 +config PAX_ELFRELOCS
79630 + bool "Allow ELF text relocations (read help)"
79631 + depends on PAX_MPROTECT
79632 + default n
79633 + help
79634 + Non-executable pages and mprotect() restrictions are effective
79635 + in preventing the introduction of new executable code into an
79636 + attacked task's address space. There remain only two venues
79637 + for this kind of attack: if the attacker can execute already
79638 + existing code in the attacked task then he can either have it
79639 + create and mmap() a file containing his code or have it mmap()
79640 + an already existing ELF library that does not have position
79641 + independent code in it and use mprotect() on it to make it
79642 + writable and copy his code there. While protecting against
79643 + the former approach is beyond PaX, the latter can be prevented
79644 + by having only PIC ELF libraries on one's system (which do not
79645 + need to relocate their code). If you are sure this is your case,
79646 + as is the case with all modern Linux distributions, then leave
79647 + this option disabled. You should say 'n' here.
79648 +
79649 +config PAX_ETEXECRELOCS
79650 + bool "Allow ELF ET_EXEC text relocations"
79651 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79652 + select PAX_ELFRELOCS
79653 + default y
79654 + help
79655 + On some architectures there are incorrectly created applications
79656 + that require text relocations and would not work without enabling
79657 + this option. If you are an alpha, ia64 or parisc user, you should
79658 + enable this option and disable it once you have made sure that
79659 + none of your applications need it.
79660 +
79661 +config PAX_EMUPLT
79662 + bool "Automatically emulate ELF PLT"
79663 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79664 + default y
79665 + help
79666 + Enabling this option will have the kernel automatically detect
79667 + and emulate the Procedure Linkage Table entries in ELF files.
79668 + On some architectures such entries are in writable memory, and
79669 + become non-executable leading to task termination. Therefore
79670 + it is mandatory that you enable this option on alpha, parisc,
79671 + sparc and sparc64, otherwise your system would not even boot.
79672 +
79673 + NOTE: this feature *does* open up a loophole in the protection
79674 + provided by the non-executable pages, therefore the proper
79675 + solution is to modify the toolchain to produce a PLT that does
79676 + not need to be writable.
79677 +
79678 +config PAX_DLRESOLVE
79679 + bool 'Emulate old glibc resolver stub'
79680 + depends on PAX_EMUPLT && SPARC
79681 + default n
79682 + help
79683 + This option is needed if userland has an old glibc (before 2.4)
79684 + that puts a 'save' instruction into the runtime generated resolver
79685 + stub that needs special emulation.
79686 +
79687 +config PAX_KERNEXEC
79688 + bool "Enforce non-executable kernel pages"
79689 + depends on PAX_NOEXEC && (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79690 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79691 + help
79692 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79693 + that is, enabling this option will make it harder to inject
79694 + and execute 'foreign' code in kernel memory itself.
79695 +
79696 + Note that on x86_64 kernels there is a known regression when
79697 + this feature and KVM/VMX are both enabled in the host kernel.
79698 +
79699 +config PAX_KERNEXEC_MODULE_TEXT
79700 + int "Minimum amount of memory reserved for module code"
79701 + default "4"
79702 + depends on PAX_KERNEXEC && X86_32 && MODULES
79703 + help
79704 + Due to implementation details the kernel must reserve a fixed
79705 + amount of memory for module code at compile time that cannot be
79706 + changed at runtime. Here you can specify the minimum amount
79707 + in MB that will be reserved. Due to the same implementation
79708 + details this size will always be rounded up to the next 2/4 MB
79709 + boundary (depends on PAE) so the actually available memory for
79710 + module code will usually be more than this minimum.
79711 +
79712 + The default 4 MB should be enough for most users but if you have
79713 + an excessive number of modules (e.g., most distribution configs
79714 + compile many drivers as modules) or use huge modules such as
79715 + nvidia's kernel driver, you will need to adjust this amount.
79716 + A good rule of thumb is to look at your currently loaded kernel
79717 + modules and add up their sizes.
79718 +
79719 +endmenu
79720 +
79721 +menu "Address Space Layout Randomization"
79722 + depends on PAX
79723 +
79724 +config PAX_ASLR
79725 + bool "Address Space Layout Randomization"
79726 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
79727 + help
79728 + Many if not most exploit techniques rely on the knowledge of
79729 + certain addresses in the attacked program. The following options
79730 + will allow the kernel to apply a certain amount of randomization
79731 + to specific parts of the program thereby forcing an attacker to
79732 + guess them in most cases. Any failed guess will most likely crash
79733 + the attacked program which allows the kernel to detect such attempts
79734 + and react on them. PaX itself provides no reaction mechanisms,
79735 + instead it is strongly encouraged that you make use of Nergal's
79736 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79737 + (http://www.grsecurity.net/) built-in crash detection features or
79738 + develop one yourself.
79739 +
79740 + By saying Y here you can choose to randomize the following areas:
79741 + - top of the task's kernel stack
79742 + - top of the task's userland stack
79743 + - base address for mmap() requests that do not specify one
79744 + (this includes all libraries)
79745 + - base address of the main executable
79746 +
79747 + It is strongly recommended to say Y here as address space layout
79748 + randomization has negligible impact on performance yet it provides
79749 + a very effective protection.
79750 +
79751 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79752 + this feature on a per file basis.
79753 +
79754 +config PAX_RANDKSTACK
79755 + bool "Randomize kernel stack base"
79756 + depends on PAX_ASLR && X86_TSC && X86
79757 + help
79758 + By saying Y here the kernel will randomize every task's kernel
79759 + stack on every system call. This will not only force an attacker
79760 + to guess it but also prevent him from making use of possible
79761 + leaked information about it.
79762 +
79763 + Since the kernel stack is a rather scarce resource, randomization
79764 + may cause unexpected stack overflows, therefore you should very
79765 + carefully test your system. Note that once enabled in the kernel
79766 + configuration, this feature cannot be disabled on a per file basis.
79767 +
79768 +config PAX_RANDUSTACK
79769 + bool "Randomize user stack base"
79770 + depends on PAX_ASLR
79771 + help
79772 + By saying Y here the kernel will randomize every task's userland
79773 + stack. The randomization is done in two steps where the second
79774 + one may apply a big amount of shift to the top of the stack and
79775 + cause problems for programs that want to use lots of memory (more
79776 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79777 + For this reason the second step can be controlled by 'chpax' or
79778 + 'paxctl' on a per file basis.
79779 +
79780 +config PAX_RANDMMAP
79781 + bool "Randomize mmap() base"
79782 + depends on PAX_ASLR
79783 + help
79784 + By saying Y here the kernel will use a randomized base address for
79785 + mmap() requests that do not specify one themselves. As a result
79786 + all dynamically loaded libraries will appear at random addresses
79787 + and therefore be harder to exploit by a technique where an attacker
79788 + attempts to execute library code for his purposes (e.g. spawn a
79789 + shell from an exploited program that is running at an elevated
79790 + privilege level).
79791 +
79792 + Furthermore, if a program is relinked as a dynamic ELF file, its
79793 + base address will be randomized as well, completing the full
79794 + randomization of the address space layout. Attacking such programs
79795 + becomes a guess game. You can find an example of doing this at
79796 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79797 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79798 +
79799 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79800 + feature on a per file basis.
79801 +
79802 +endmenu
79803 +
79804 +menu "Miscellaneous hardening features"
79805 +
79806 +config PAX_MEMORY_SANITIZE
79807 + bool "Sanitize all freed memory"
79808 + help
79809 + By saying Y here the kernel will erase memory pages as soon as they
79810 + are freed. This in turn reduces the lifetime of data stored in the
79811 + pages, making it less likely that sensitive information such as
79812 + passwords, cryptographic secrets, etc stay in memory for too long.
79813 +
79814 + This is especially useful for programs whose runtime is short, long
79815 + lived processes and the kernel itself benefit from this as long as
79816 + they operate on whole memory pages and ensure timely freeing of pages
79817 + that may hold sensitive information.
79818 +
79819 + The tradeoff is performance impact, on a single CPU system kernel
79820 + compilation sees a 3% slowdown, other systems and workloads may vary
79821 + and you are advised to test this feature on your expected workload
79822 + before deploying it.
79823 +
79824 + Note that this feature does not protect data stored in live pages,
79825 + e.g., process memory swapped to disk may stay there for a long time.
79826 +
79827 +config PAX_MEMORY_STACKLEAK
79828 + bool "Sanitize kernel stack"
79829 + depends on X86
79830 + help
79831 + By saying Y here the kernel will erase the kernel stack before it
79832 + returns from a system call. This in turn reduces the information
79833 + that a kernel stack leak bug can reveal.
79834 +
79835 + Note that such a bug can still leak information that was put on
79836 + the stack by the current system call (the one eventually triggering
79837 + the bug) but traces of earlier system calls on the kernel stack
79838 + cannot leak anymore.
79839 +
79840 + The tradeoff is performance impact: on a single CPU system kernel
79841 + compilation sees a 1% slowdown, other systems and workloads may vary
79842 + and you are advised to test this feature on your expected workload
79843 + before deploying it.
79844 +
79845 + Note: full support for this feature requires gcc with plugin support
79846 + so make sure your compiler is at least gcc 4.5.0 (cross compilation
79847 + is not supported). Using older gcc versions means that functions
79848 + with large enough stack frames may leave uninitialized memory behind
79849 + that may be exposed to a later syscall leaking the stack.
79850 +
79851 +config PAX_MEMORY_UDEREF
79852 + bool "Prevent invalid userland pointer dereference"
79853 + depends on X86 && !UML_X86 && !XEN
79854 + select PAX_PER_CPU_PGD if X86_64
79855 + help
79856 + By saying Y here the kernel will be prevented from dereferencing
79857 + userland pointers in contexts where the kernel expects only kernel
79858 + pointers. This is both a useful runtime debugging feature and a
79859 + security measure that prevents exploiting a class of kernel bugs.
79860 +
79861 + The tradeoff is that some virtualization solutions may experience
79862 + a huge slowdown and therefore you should not enable this feature
79863 + for kernels meant to run in such environments. Whether a given VM
79864 + solution is affected or not is best determined by simply trying it
79865 + out, the performance impact will be obvious right on boot as this
79866 + mechanism engages from very early on. A good rule of thumb is that
79867 + VMs running on CPUs without hardware virtualization support (i.e.,
79868 + the majority of IA-32 CPUs) will likely experience the slowdown.
79869 +
79870 +config PAX_REFCOUNT
79871 + bool "Prevent various kernel object reference counter overflows"
79872 + depends on GRKERNSEC && (X86 || SPARC64)
79873 + help
79874 + By saying Y here the kernel will detect and prevent overflowing
79875 + various (but not all) kinds of object reference counters. Such
79876 + overflows can normally occur due to bugs only and are often, if
79877 + not always, exploitable.
79878 +
79879 + The tradeoff is that data structures protected by an overflowed
79880 + refcount will never be freed and therefore will leak memory. Note
79881 + that this leak also happens even without this protection but in
79882 + that case the overflow can eventually trigger the freeing of the
79883 + data structure while it is still being used elsewhere, resulting
79884 + in the exploitable situation that this feature prevents.
79885 +
79886 + Since this has a negligible performance impact, you should enable
79887 + this feature.
79888 +
79889 +config PAX_USERCOPY
79890 + bool "Harden heap object copies between kernel and userland"
79891 + depends on X86 || PPC || SPARC
79892 + depends on GRKERNSEC && (SLAB || SLUB)
79893 + help
79894 + By saying Y here the kernel will enforce the size of heap objects
79895 + when they are copied in either direction between the kernel and
79896 + userland, even if only a part of the heap object is copied.
79897 +
79898 + Specifically, this checking prevents information leaking from the
79899 + kernel heap during kernel to userland copies (if the kernel heap
79900 + object is otherwise fully initialized) and prevents kernel heap
79901 + overflows during userland to kernel copies.
79902 +
79903 + Note that the current implementation provides the strictest bounds
79904 + checks for the SLUB allocator.
79905 +
79906 + Enabling this option also enables per-slab cache protection against
79907 + data in a given cache being copied into/out of via userland
79908 + accessors. Though the whitelist of regions will be reduced over
79909 + time, it notably protects important data structures like task structs.
79910 +
79911 + If frame pointers are enabled on x86, this option will also restrict
79912 + copies into and out of the kernel stack to local variables within a
79913 + single frame.
79914 +
79915 + Since this has a negligible performance impact, you should enable
79916 + this feature.
79917 +
79918 +endmenu
79919 +
79920 +endmenu
79921 +
79922 config KEYS
79923 bool "Enable access key retention support"
79924 help
79925 @@ -167,7 +715,7 @@ config INTEL_TXT
79926 config LSM_MMAP_MIN_ADDR
79927 int "Low address space for LSM to protect from user allocation"
79928 depends on SECURITY && SECURITY_SELINUX
79929 - default 65536
79930 + default 32768
79931 help
79932 This is the portion of low virtual memory which should be protected
79933 from userspace allocation. Keeping a user from writing to low pages
79934 diff -urNp linux-2.6.39.1/security/keys/keyring.c linux-2.6.39.1/security/keys/keyring.c
79935 --- linux-2.6.39.1/security/keys/keyring.c 2011-05-19 00:06:34.000000000 -0400
79936 +++ linux-2.6.39.1/security/keys/keyring.c 2011-05-22 19:36:35.000000000 -0400
79937 @@ -213,15 +213,15 @@ static long keyring_read(const struct ke
79938 ret = -EFAULT;
79939
79940 for (loop = 0; loop < klist->nkeys; loop++) {
79941 + key_serial_t serial;
79942 key = klist->keys[loop];
79943 + serial = key->serial;
79944
79945 tmp = sizeof(key_serial_t);
79946 if (tmp > buflen)
79947 tmp = buflen;
79948
79949 - if (copy_to_user(buffer,
79950 - &key->serial,
79951 - tmp) != 0)
79952 + if (copy_to_user(buffer, &serial, tmp))
79953 goto error;
79954
79955 buflen -= tmp;
79956 diff -urNp linux-2.6.39.1/security/min_addr.c linux-2.6.39.1/security/min_addr.c
79957 --- linux-2.6.39.1/security/min_addr.c 2011-05-19 00:06:34.000000000 -0400
79958 +++ linux-2.6.39.1/security/min_addr.c 2011-05-22 19:41:42.000000000 -0400
79959 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG
79960 */
79961 static void update_mmap_min_addr(void)
79962 {
79963 +#ifndef SPARC
79964 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79965 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79966 mmap_min_addr = dac_mmap_min_addr;
79967 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79968 #else
79969 mmap_min_addr = dac_mmap_min_addr;
79970 #endif
79971 +#endif
79972 }
79973
79974 /*
79975 diff -urNp linux-2.6.39.1/security/security.c linux-2.6.39.1/security/security.c
79976 --- linux-2.6.39.1/security/security.c 2011-05-19 00:06:34.000000000 -0400
79977 +++ linux-2.6.39.1/security/security.c 2011-05-22 19:41:42.000000000 -0400
79978 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURI
79979 /* things that live in capability.c */
79980 extern void __init security_fixup_ops(struct security_operations *ops);
79981
79982 -static struct security_operations *security_ops;
79983 -static struct security_operations default_security_ops = {
79984 +static struct security_operations *security_ops __read_only;
79985 +static struct security_operations default_security_ops __read_only = {
79986 .name = "default",
79987 };
79988
79989 @@ -67,7 +67,9 @@ int __init security_init(void)
79990
79991 void reset_security_ops(void)
79992 {
79993 + pax_open_kernel();
79994 security_ops = &default_security_ops;
79995 + pax_close_kernel();
79996 }
79997
79998 /* Save user chosen LSM */
79999 diff -urNp linux-2.6.39.1/security/selinux/hooks.c linux-2.6.39.1/security/selinux/hooks.c
80000 --- linux-2.6.39.1/security/selinux/hooks.c 2011-05-19 00:06:34.000000000 -0400
80001 +++ linux-2.6.39.1/security/selinux/hooks.c 2011-05-22 19:41:42.000000000 -0400
80002 @@ -93,7 +93,6 @@
80003 #define NUM_SEL_MNT_OPTS 5
80004
80005 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
80006 -extern struct security_operations *security_ops;
80007
80008 /* SECMARK reference count */
80009 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80010 @@ -5431,7 +5430,7 @@ static int selinux_key_getsecurity(struc
80011
80012 #endif
80013
80014 -static struct security_operations selinux_ops = {
80015 +static struct security_operations selinux_ops __read_only = {
80016 .name = "selinux",
80017
80018 .ptrace_access_check = selinux_ptrace_access_check,
80019 diff -urNp linux-2.6.39.1/security/selinux/include/xfrm.h linux-2.6.39.1/security/selinux/include/xfrm.h
80020 --- linux-2.6.39.1/security/selinux/include/xfrm.h 2011-05-19 00:06:34.000000000 -0400
80021 +++ linux-2.6.39.1/security/selinux/include/xfrm.h 2011-05-22 19:36:35.000000000 -0400
80022 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct s
80023
80024 static inline void selinux_xfrm_notify_policyload(void)
80025 {
80026 - atomic_inc(&flow_cache_genid);
80027 + atomic_inc_unchecked(&flow_cache_genid);
80028 }
80029 #else
80030 static inline int selinux_xfrm_enabled(void)
80031 diff -urNp linux-2.6.39.1/security/selinux/ss/services.c linux-2.6.39.1/security/selinux/ss/services.c
80032 --- linux-2.6.39.1/security/selinux/ss/services.c 2011-05-19 00:06:34.000000000 -0400
80033 +++ linux-2.6.39.1/security/selinux/ss/services.c 2011-05-22 19:36:35.000000000 -0400
80034 @@ -1806,6 +1806,8 @@ int security_load_policy(void *data, siz
80035 int rc = 0;
80036 struct policy_file file = { data, len }, *fp = &file;
80037
80038 + pax_track_stack();
80039 +
80040 if (!ss_initialized) {
80041 avtab_cache_init();
80042 rc = policydb_read(&policydb, fp);
80043 diff -urNp linux-2.6.39.1/security/smack/smack_lsm.c linux-2.6.39.1/security/smack/smack_lsm.c
80044 --- linux-2.6.39.1/security/smack/smack_lsm.c 2011-05-19 00:06:34.000000000 -0400
80045 +++ linux-2.6.39.1/security/smack/smack_lsm.c 2011-05-22 19:36:35.000000000 -0400
80046 @@ -3386,7 +3386,7 @@ static int smack_inode_getsecctx(struct
80047 return 0;
80048 }
80049
80050 -struct security_operations smack_ops = {
80051 +struct security_operations smack_ops __read_only = {
80052 .name = "smack",
80053
80054 .ptrace_access_check = smack_ptrace_access_check,
80055 diff -urNp linux-2.6.39.1/security/tomoyo/tomoyo.c linux-2.6.39.1/security/tomoyo/tomoyo.c
80056 --- linux-2.6.39.1/security/tomoyo/tomoyo.c 2011-05-19 00:06:34.000000000 -0400
80057 +++ linux-2.6.39.1/security/tomoyo/tomoyo.c 2011-05-22 19:36:35.000000000 -0400
80058 @@ -240,7 +240,7 @@ static int tomoyo_sb_pivotroot(struct pa
80059 * tomoyo_security_ops is a "struct security_operations" which is used for
80060 * registering TOMOYO.
80061 */
80062 -static struct security_operations tomoyo_security_ops = {
80063 +static struct security_operations tomoyo_security_ops __read_only = {
80064 .name = "tomoyo",
80065 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80066 .cred_prepare = tomoyo_cred_prepare,
80067 diff -urNp linux-2.6.39.1/sound/aoa/aoa.h linux-2.6.39.1/sound/aoa/aoa.h
80068 --- linux-2.6.39.1/sound/aoa/aoa.h 2011-05-19 00:06:34.000000000 -0400
80069 +++ linux-2.6.39.1/sound/aoa/aoa.h 2011-05-22 19:36:35.000000000 -0400
80070 @@ -122,8 +122,8 @@ extern struct snd_card *aoa_get_card(voi
80071 extern int aoa_snd_ctl_add(struct snd_kcontrol* control);
80072
80073 /* GPIO stuff */
80074 -extern struct gpio_methods *pmf_gpio_methods;
80075 -extern struct gpio_methods *ftr_gpio_methods;
80076 +extern const struct gpio_methods *pmf_gpio_methods;
80077 +extern const struct gpio_methods *ftr_gpio_methods;
80078 /* extern struct gpio_methods *map_gpio_methods; */
80079
80080 #endif /* __AOA_H */
80081 diff -urNp linux-2.6.39.1/sound/aoa/codecs/onyx.c linux-2.6.39.1/sound/aoa/codecs/onyx.c
80082 --- linux-2.6.39.1/sound/aoa/codecs/onyx.c 2011-05-19 00:06:34.000000000 -0400
80083 +++ linux-2.6.39.1/sound/aoa/codecs/onyx.c 2011-05-22 19:36:35.000000000 -0400
80084 @@ -54,7 +54,7 @@ struct onyx {
80085 spdif_locked:1,
80086 analog_locked:1,
80087 original_mute:2;
80088 - int open_count;
80089 + local_t open_count;
80090 struct codec_info *codec_info;
80091
80092 /* mutex serializes concurrent access to the device
80093 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_i
80094 struct onyx *onyx = cii->codec_data;
80095
80096 mutex_lock(&onyx->mutex);
80097 - onyx->open_count++;
80098 + local_inc(&onyx->open_count);
80099 mutex_unlock(&onyx->mutex);
80100
80101 return 0;
80102 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_
80103 struct onyx *onyx = cii->codec_data;
80104
80105 mutex_lock(&onyx->mutex);
80106 - onyx->open_count--;
80107 - if (!onyx->open_count)
80108 + if (local_dec_and_test(&onyx->open_count))
80109 onyx->spdif_locked = onyx->analog_locked = 0;
80110 mutex_unlock(&onyx->mutex);
80111
80112 diff -urNp linux-2.6.39.1/sound/aoa/codecs/onyx.h linux-2.6.39.1/sound/aoa/codecs/onyx.h
80113 --- linux-2.6.39.1/sound/aoa/codecs/onyx.h 2011-05-19 00:06:34.000000000 -0400
80114 +++ linux-2.6.39.1/sound/aoa/codecs/onyx.h 2011-05-22 19:36:35.000000000 -0400
80115 @@ -11,6 +11,7 @@
80116 #include <linux/i2c.h>
80117 #include <asm/pmac_low_i2c.h>
80118 #include <asm/prom.h>
80119 +#include <asm/local.h>
80120
80121 /* PCM3052 register definitions */
80122
80123 diff -urNp linux-2.6.39.1/sound/arm/aaci.c linux-2.6.39.1/sound/arm/aaci.c
80124 --- linux-2.6.39.1/sound/arm/aaci.c 2011-05-19 00:06:34.000000000 -0400
80125 +++ linux-2.6.39.1/sound/arm/aaci.c 2011-05-22 19:36:35.000000000 -0400
80126 @@ -635,7 +635,7 @@ static int aaci_pcm_playback_trigger(str
80127 return ret;
80128 }
80129
80130 -static struct snd_pcm_ops aaci_playback_ops = {
80131 +static const struct snd_pcm_ops aaci_playback_ops = {
80132 .open = aaci_pcm_open,
80133 .close = aaci_pcm_close,
80134 .ioctl = snd_pcm_lib_ioctl,
80135 @@ -738,7 +738,7 @@ static int aaci_pcm_capture_prepare(stru
80136 return 0;
80137 }
80138
80139 -static struct snd_pcm_ops aaci_capture_ops = {
80140 +static const struct snd_pcm_ops aaci_capture_ops = {
80141 .open = aaci_pcm_open,
80142 .close = aaci_pcm_close,
80143 .ioctl = snd_pcm_lib_ioctl,
80144 @@ -827,7 +827,7 @@ static struct ac97_pcm ac97_defs[] __dev
80145 }
80146 };
80147
80148 -static struct snd_ac97_bus_ops aaci_bus_ops = {
80149 +static const struct snd_ac97_bus_ops aaci_bus_ops = {
80150 .write = aaci_ac97_write,
80151 .read = aaci_ac97_read,
80152 };
80153 diff -urNp linux-2.6.39.1/sound/arm/pxa2xx-ac97.c linux-2.6.39.1/sound/arm/pxa2xx-ac97.c
80154 --- linux-2.6.39.1/sound/arm/pxa2xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
80155 +++ linux-2.6.39.1/sound/arm/pxa2xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
80156 @@ -34,7 +34,7 @@ static void pxa2xx_ac97_reset(struct snd
80157 pxa2xx_ac97_finish_reset(ac97);
80158 }
80159
80160 -static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
80161 +static const struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
80162 .read = pxa2xx_ac97_read,
80163 .write = pxa2xx_ac97_write,
80164 .reset = pxa2xx_ac97_reset,
80165 diff -urNp linux-2.6.39.1/sound/atmel/abdac.c linux-2.6.39.1/sound/atmel/abdac.c
80166 --- linux-2.6.39.1/sound/atmel/abdac.c 2011-05-19 00:06:34.000000000 -0400
80167 +++ linux-2.6.39.1/sound/atmel/abdac.c 2011-05-22 19:36:35.000000000 -0400
80168 @@ -297,7 +297,7 @@ static irqreturn_t abdac_interrupt(int i
80169 return IRQ_HANDLED;
80170 }
80171
80172 -static struct snd_pcm_ops atmel_abdac_ops = {
80173 +static const struct snd_pcm_ops atmel_abdac_ops = {
80174 .open = atmel_abdac_open,
80175 .close = atmel_abdac_close,
80176 .ioctl = snd_pcm_lib_ioctl,
80177 diff -urNp linux-2.6.39.1/sound/atmel/ac97c.c linux-2.6.39.1/sound/atmel/ac97c.c
80178 --- linux-2.6.39.1/sound/atmel/ac97c.c 2011-05-19 00:06:34.000000000 -0400
80179 +++ linux-2.6.39.1/sound/atmel/ac97c.c 2011-05-22 19:36:35.000000000 -0400
80180 @@ -626,7 +626,7 @@ atmel_ac97c_capture_pointer(struct snd_p
80181 return frames;
80182 }
80183
80184 -static struct snd_pcm_ops atmel_ac97_playback_ops = {
80185 +static const struct snd_pcm_ops atmel_ac97_playback_ops = {
80186 .open = atmel_ac97c_playback_open,
80187 .close = atmel_ac97c_playback_close,
80188 .ioctl = snd_pcm_lib_ioctl,
80189 @@ -637,7 +637,7 @@ static struct snd_pcm_ops atmel_ac97_pla
80190 .pointer = atmel_ac97c_playback_pointer,
80191 };
80192
80193 -static struct snd_pcm_ops atmel_ac97_capture_ops = {
80194 +static const struct snd_pcm_ops atmel_ac97_capture_ops = {
80195 .open = atmel_ac97c_capture_open,
80196 .close = atmel_ac97c_capture_close,
80197 .ioctl = snd_pcm_lib_ioctl,
80198 @@ -909,7 +909,7 @@ static int __devinit atmel_ac97c_probe(s
80199 struct resource *regs;
80200 struct ac97c_platform_data *pdata;
80201 struct clk *pclk;
80202 - static struct snd_ac97_bus_ops ops = {
80203 + static const struct snd_ac97_bus_ops ops = {
80204 .write = atmel_ac97c_write,
80205 .read = atmel_ac97c_read,
80206 };
80207 diff -urNp linux-2.6.39.1/sound/core/control.c linux-2.6.39.1/sound/core/control.c
80208 --- linux-2.6.39.1/sound/core/control.c 2011-05-19 00:06:34.000000000 -0400
80209 +++ linux-2.6.39.1/sound/core/control.c 2011-05-22 19:36:35.000000000 -0400
80210 @@ -1520,7 +1520,7 @@ static int snd_ctl_dev_free(struct snd_d
80211 */
80212 int snd_ctl_create(struct snd_card *card)
80213 {
80214 - static struct snd_device_ops ops = {
80215 + static const struct snd_device_ops ops = {
80216 .dev_free = snd_ctl_dev_free,
80217 .dev_register = snd_ctl_dev_register,
80218 .dev_disconnect = snd_ctl_dev_disconnect,
80219 diff -urNp linux-2.6.39.1/sound/core/device.c linux-2.6.39.1/sound/core/device.c
80220 --- linux-2.6.39.1/sound/core/device.c 2011-05-19 00:06:34.000000000 -0400
80221 +++ linux-2.6.39.1/sound/core/device.c 2011-05-22 19:36:35.000000000 -0400
80222 @@ -41,7 +41,7 @@
80223 * Returns zero if successful, or a negative error code on failure.
80224 */
80225 int snd_device_new(struct snd_card *card, snd_device_type_t type,
80226 - void *device_data, struct snd_device_ops *ops)
80227 + void *device_data, const struct snd_device_ops *ops)
80228 {
80229 struct snd_device *dev;
80230
80231 diff -urNp linux-2.6.39.1/sound/core/hwdep.c linux-2.6.39.1/sound/core/hwdep.c
80232 --- linux-2.6.39.1/sound/core/hwdep.c 2011-05-19 00:06:34.000000000 -0400
80233 +++ linux-2.6.39.1/sound/core/hwdep.c 2011-05-22 19:36:35.000000000 -0400
80234 @@ -348,7 +348,7 @@ int snd_hwdep_new(struct snd_card *card,
80235 {
80236 struct snd_hwdep *hwdep;
80237 int err;
80238 - static struct snd_device_ops ops = {
80239 + static const struct snd_device_ops ops = {
80240 .dev_free = snd_hwdep_dev_free,
80241 .dev_register = snd_hwdep_dev_register,
80242 .dev_disconnect = snd_hwdep_dev_disconnect,
80243 diff -urNp linux-2.6.39.1/sound/core/info.c linux-2.6.39.1/sound/core/info.c
80244 --- linux-2.6.39.1/sound/core/info.c 2011-05-19 00:06:34.000000000 -0400
80245 +++ linux-2.6.39.1/sound/core/info.c 2011-05-22 19:36:35.000000000 -0400
80246 @@ -897,7 +897,7 @@ static int snd_info_dev_register_entry(s
80247 int snd_card_proc_new(struct snd_card *card, const char *name,
80248 struct snd_info_entry **entryp)
80249 {
80250 - static struct snd_device_ops ops = {
80251 + static const struct snd_device_ops ops = {
80252 .dev_free = snd_info_dev_free_entry,
80253 .dev_register = snd_info_dev_register_entry,
80254 /* disconnect is done via snd_info_card_disconnect() */
80255 diff -urNp linux-2.6.39.1/sound/core/jack.c linux-2.6.39.1/sound/core/jack.c
80256 --- linux-2.6.39.1/sound/core/jack.c 2011-05-19 00:06:34.000000000 -0400
80257 +++ linux-2.6.39.1/sound/core/jack.c 2011-05-22 19:36:35.000000000 -0400
80258 @@ -105,7 +105,7 @@ int snd_jack_new(struct snd_card *card,
80259 struct snd_jack *jack;
80260 int err;
80261 int i;
80262 - static struct snd_device_ops ops = {
80263 + static const struct snd_device_ops ops = {
80264 .dev_free = snd_jack_dev_free,
80265 .dev_register = snd_jack_dev_register,
80266 };
80267 diff -urNp linux-2.6.39.1/sound/core/pcm.c linux-2.6.39.1/sound/core/pcm.c
80268 --- linux-2.6.39.1/sound/core/pcm.c 2011-05-19 00:06:34.000000000 -0400
80269 +++ linux-2.6.39.1/sound/core/pcm.c 2011-05-22 19:36:35.000000000 -0400
80270 @@ -717,7 +717,7 @@ int snd_pcm_new(struct snd_card *card, c
80271 {
80272 struct snd_pcm *pcm;
80273 int err;
80274 - static struct snd_device_ops ops = {
80275 + static const struct snd_device_ops ops = {
80276 .dev_free = snd_pcm_dev_free,
80277 .dev_register = snd_pcm_dev_register,
80278 .dev_disconnect = snd_pcm_dev_disconnect,
80279 diff -urNp linux-2.6.39.1/sound/core/pcm_lib.c linux-2.6.39.1/sound/core/pcm_lib.c
80280 --- linux-2.6.39.1/sound/core/pcm_lib.c 2011-05-19 00:06:34.000000000 -0400
80281 +++ linux-2.6.39.1/sound/core/pcm_lib.c 2011-05-22 19:36:35.000000000 -0400
80282 @@ -505,7 +505,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm
80283 *
80284 * Sets the given PCM operators to the pcm instance.
80285 */
80286 -void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, struct snd_pcm_ops *ops)
80287 +void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, const struct snd_pcm_ops *ops)
80288 {
80289 struct snd_pcm_str *stream = &pcm->streams[direction];
80290 struct snd_pcm_substream *substream;
80291 diff -urNp linux-2.6.39.1/sound/core/pcm_native.c linux-2.6.39.1/sound/core/pcm_native.c
80292 --- linux-2.6.39.1/sound/core/pcm_native.c 2011-05-19 00:06:34.000000000 -0400
80293 +++ linux-2.6.39.1/sound/core/pcm_native.c 2011-05-22 19:36:35.000000000 -0400
80294 @@ -702,7 +702,7 @@ struct action_ops {
80295 * Note: the stream state might be changed also on failure
80296 * Note2: call with calling stream lock + link lock
80297 */
80298 -static int snd_pcm_action_group(struct action_ops *ops,
80299 +static int snd_pcm_action_group(const struct action_ops *ops,
80300 struct snd_pcm_substream *substream,
80301 int state, int do_lock)
80302 {
80303 @@ -751,7 +751,7 @@ static int snd_pcm_action_group(struct a
80304 /*
80305 * Note: call with stream lock
80306 */
80307 -static int snd_pcm_action_single(struct action_ops *ops,
80308 +static int snd_pcm_action_single(const struct action_ops *ops,
80309 struct snd_pcm_substream *substream,
80310 int state)
80311 {
80312 @@ -771,7 +771,7 @@ static int snd_pcm_action_single(struct
80313 /*
80314 * Note: call with stream lock
80315 */
80316 -static int snd_pcm_action(struct action_ops *ops,
80317 +static int snd_pcm_action(const struct action_ops *ops,
80318 struct snd_pcm_substream *substream,
80319 int state)
80320 {
80321 @@ -794,7 +794,7 @@ static int snd_pcm_action(struct action_
80322 /*
80323 * Note: don't use any locks before
80324 */
80325 -static int snd_pcm_action_lock_irq(struct action_ops *ops,
80326 +static int snd_pcm_action_lock_irq(const struct action_ops *ops,
80327 struct snd_pcm_substream *substream,
80328 int state)
80329 {
80330 @@ -818,7 +818,7 @@ static int snd_pcm_action_lock_irq(struc
80331
80332 /*
80333 */
80334 -static int snd_pcm_action_nonatomic(struct action_ops *ops,
80335 +static int snd_pcm_action_nonatomic(const struct action_ops *ops,
80336 struct snd_pcm_substream *substream,
80337 int state)
80338 {
80339 @@ -877,7 +877,7 @@ static void snd_pcm_post_start(struct sn
80340 &runtime->trigger_tstamp);
80341 }
80342
80343 -static struct action_ops snd_pcm_action_start = {
80344 +static const struct action_ops snd_pcm_action_start = {
80345 .pre_action = snd_pcm_pre_start,
80346 .do_action = snd_pcm_do_start,
80347 .undo_action = snd_pcm_undo_start,
80348 @@ -928,7 +928,7 @@ static void snd_pcm_post_stop(struct snd
80349 wake_up(&runtime->tsleep);
80350 }
80351
80352 -static struct action_ops snd_pcm_action_stop = {
80353 +static const struct action_ops snd_pcm_action_stop = {
80354 .pre_action = snd_pcm_pre_stop,
80355 .do_action = snd_pcm_do_stop,
80356 .post_action = snd_pcm_post_stop
80357 @@ -1025,7 +1025,7 @@ static void snd_pcm_post_pause(struct sn
80358 }
80359 }
80360
80361 -static struct action_ops snd_pcm_action_pause = {
80362 +static const struct action_ops snd_pcm_action_pause = {
80363 .pre_action = snd_pcm_pre_pause,
80364 .do_action = snd_pcm_do_pause,
80365 .undo_action = snd_pcm_undo_pause,
80366 @@ -1076,7 +1076,7 @@ static void snd_pcm_post_suspend(struct
80367 wake_up(&runtime->tsleep);
80368 }
80369
80370 -static struct action_ops snd_pcm_action_suspend = {
80371 +static const struct action_ops snd_pcm_action_suspend = {
80372 .pre_action = snd_pcm_pre_suspend,
80373 .do_action = snd_pcm_do_suspend,
80374 .post_action = snd_pcm_post_suspend
80375 @@ -1175,7 +1175,7 @@ static void snd_pcm_post_resume(struct s
80376 runtime->status->state = runtime->status->suspended_state;
80377 }
80378
80379 -static struct action_ops snd_pcm_action_resume = {
80380 +static const struct action_ops snd_pcm_action_resume = {
80381 .pre_action = snd_pcm_pre_resume,
80382 .do_action = snd_pcm_do_resume,
80383 .undo_action = snd_pcm_undo_resume,
80384 @@ -1278,7 +1278,7 @@ static void snd_pcm_post_reset(struct sn
80385 snd_pcm_playback_silence(substream, ULONG_MAX);
80386 }
80387
80388 -static struct action_ops snd_pcm_action_reset = {
80389 +static const struct action_ops snd_pcm_action_reset = {
80390 .pre_action = snd_pcm_pre_reset,
80391 .do_action = snd_pcm_do_reset,
80392 .post_action = snd_pcm_post_reset
80393 @@ -1322,7 +1322,7 @@ static void snd_pcm_post_prepare(struct
80394 runtime->status->state = SNDRV_PCM_STATE_PREPARED;
80395 }
80396
80397 -static struct action_ops snd_pcm_action_prepare = {
80398 +static const struct action_ops snd_pcm_action_prepare = {
80399 .pre_action = snd_pcm_pre_prepare,
80400 .do_action = snd_pcm_do_prepare,
80401 .post_action = snd_pcm_post_prepare
80402 @@ -1397,7 +1397,7 @@ static void snd_pcm_post_drain_init(stru
80403 {
80404 }
80405
80406 -static struct action_ops snd_pcm_action_drain_init = {
80407 +static const struct action_ops snd_pcm_action_drain_init = {
80408 .pre_action = snd_pcm_pre_drain_init,
80409 .do_action = snd_pcm_do_drain_init,
80410 .post_action = snd_pcm_post_drain_init
80411 diff -urNp linux-2.6.39.1/sound/core/rawmidi.c linux-2.6.39.1/sound/core/rawmidi.c
80412 --- linux-2.6.39.1/sound/core/rawmidi.c 2011-05-19 00:06:34.000000000 -0400
80413 +++ linux-2.6.39.1/sound/core/rawmidi.c 2011-05-22 19:36:35.000000000 -0400
80414 @@ -1449,7 +1449,7 @@ int snd_rawmidi_new(struct snd_card *car
80415 {
80416 struct snd_rawmidi *rmidi;
80417 int err;
80418 - static struct snd_device_ops ops = {
80419 + static const struct snd_device_ops ops = {
80420 .dev_free = snd_rawmidi_dev_free,
80421 .dev_register = snd_rawmidi_dev_register,
80422 .dev_disconnect = snd_rawmidi_dev_disconnect,
80423 @@ -1654,7 +1654,7 @@ static int snd_rawmidi_dev_disconnect(st
80424 * Sets the rawmidi operators for the given stream direction.
80425 */
80426 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
80427 - struct snd_rawmidi_ops *ops)
80428 + const struct snd_rawmidi_ops *ops)
80429 {
80430 struct snd_rawmidi_substream *substream;
80431
80432 diff -urNp linux-2.6.39.1/sound/core/seq/seq_device.c linux-2.6.39.1/sound/core/seq/seq_device.c
80433 --- linux-2.6.39.1/sound/core/seq/seq_device.c 2011-05-19 00:06:34.000000000 -0400
80434 +++ linux-2.6.39.1/sound/core/seq/seq_device.c 2011-05-22 19:36:35.000000000 -0400
80435 @@ -178,7 +178,7 @@ int snd_seq_device_new(struct snd_card *
80436 struct snd_seq_device *dev;
80437 struct ops_list *ops;
80438 int err;
80439 - static struct snd_device_ops dops = {
80440 + static const struct snd_device_ops dops = {
80441 .dev_free = snd_seq_device_dev_free,
80442 .dev_register = snd_seq_device_dev_register,
80443 .dev_disconnect = snd_seq_device_dev_disconnect,
80444 @@ -307,7 +307,7 @@ static int snd_seq_device_dev_disconnect
80445 * id = driver id
80446 * entry = driver operators - duplicated to each instance
80447 */
80448 -int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80449 +int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry,
80450 int argsize)
80451 {
80452 struct ops_list *ops;
80453 diff -urNp linux-2.6.39.1/sound/core/seq/seq_midi.c linux-2.6.39.1/sound/core/seq/seq_midi.c
80454 --- linux-2.6.39.1/sound/core/seq/seq_midi.c 2011-05-19 00:06:34.000000000 -0400
80455 +++ linux-2.6.39.1/sound/core/seq/seq_midi.c 2011-05-22 19:36:35.000000000 -0400
80456 @@ -461,7 +461,7 @@ snd_seq_midisynth_unregister_port(struct
80457
80458 static int __init alsa_seq_midi_init(void)
80459 {
80460 - static struct snd_seq_dev_ops ops = {
80461 + static const struct snd_seq_dev_ops ops = {
80462 snd_seq_midisynth_register_port,
80463 snd_seq_midisynth_unregister_port,
80464 };
80465 diff -urNp linux-2.6.39.1/sound/core/seq/seq_virmidi.c linux-2.6.39.1/sound/core/seq/seq_virmidi.c
80466 --- linux-2.6.39.1/sound/core/seq/seq_virmidi.c 2011-05-19 00:06:34.000000000 -0400
80467 +++ linux-2.6.39.1/sound/core/seq/seq_virmidi.c 2011-05-22 19:36:35.000000000 -0400
80468 @@ -337,13 +337,13 @@ static int snd_virmidi_unuse(void *priva
80469 * Register functions
80470 */
80471
80472 -static struct snd_rawmidi_ops snd_virmidi_input_ops = {
80473 +static const struct snd_rawmidi_ops snd_virmidi_input_ops = {
80474 .open = snd_virmidi_input_open,
80475 .close = snd_virmidi_input_close,
80476 .trigger = snd_virmidi_input_trigger,
80477 };
80478
80479 -static struct snd_rawmidi_ops snd_virmidi_output_ops = {
80480 +static const struct snd_rawmidi_ops snd_virmidi_output_ops = {
80481 .open = snd_virmidi_output_open,
80482 .close = snd_virmidi_output_close,
80483 .trigger = snd_virmidi_output_trigger,
80484 @@ -467,7 +467,7 @@ static int snd_virmidi_dev_unregister(st
80485 /*
80486 *
80487 */
80488 -static struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
80489 +static const struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
80490 .dev_register = snd_virmidi_dev_register,
80491 .dev_unregister = snd_virmidi_dev_unregister,
80492 };
80493 diff -urNp linux-2.6.39.1/sound/core/timer.c linux-2.6.39.1/sound/core/timer.c
80494 --- linux-2.6.39.1/sound/core/timer.c 2011-05-19 00:06:34.000000000 -0400
80495 +++ linux-2.6.39.1/sound/core/timer.c 2011-05-22 19:36:35.000000000 -0400
80496 @@ -756,7 +756,7 @@ int snd_timer_new(struct snd_card *card,
80497 {
80498 struct snd_timer *timer;
80499 int err;
80500 - static struct snd_device_ops ops = {
80501 + static const struct snd_device_ops ops = {
80502 .dev_free = snd_timer_dev_free,
80503 .dev_register = snd_timer_dev_register,
80504 .dev_disconnect = snd_timer_dev_disconnect,
80505 diff -urNp linux-2.6.39.1/sound/drivers/aloop.c linux-2.6.39.1/sound/drivers/aloop.c
80506 --- linux-2.6.39.1/sound/drivers/aloop.c 2011-05-19 00:06:34.000000000 -0400
80507 +++ linux-2.6.39.1/sound/drivers/aloop.c 2011-05-22 19:36:35.000000000 -0400
80508 @@ -731,7 +731,7 @@ static int loopback_close(struct snd_pcm
80509 return 0;
80510 }
80511
80512 -static struct snd_pcm_ops loopback_playback_ops = {
80513 +static const struct snd_pcm_ops loopback_playback_ops = {
80514 .open = loopback_open,
80515 .close = loopback_close,
80516 .ioctl = snd_pcm_lib_ioctl,
80517 @@ -742,7 +742,7 @@ static struct snd_pcm_ops loopback_playb
80518 .pointer = loopback_pointer,
80519 };
80520
80521 -static struct snd_pcm_ops loopback_capture_ops = {
80522 +static const struct snd_pcm_ops loopback_capture_ops = {
80523 .open = loopback_open,
80524 .close = loopback_close,
80525 .ioctl = snd_pcm_lib_ioctl,
80526 diff -urNp linux-2.6.39.1/sound/drivers/dummy.c linux-2.6.39.1/sound/drivers/dummy.c
80527 --- linux-2.6.39.1/sound/drivers/dummy.c 2011-05-19 00:06:34.000000000 -0400
80528 +++ linux-2.6.39.1/sound/drivers/dummy.c 2011-05-22 19:36:35.000000000 -0400
80529 @@ -350,7 +350,7 @@ static void dummy_systimer_free(struct s
80530 kfree(substream->runtime->private_data);
80531 }
80532
80533 -static struct dummy_timer_ops dummy_systimer_ops = {
80534 +static const struct dummy_timer_ops dummy_systimer_ops = {
80535 .create = dummy_systimer_create,
80536 .free = dummy_systimer_free,
80537 .prepare = dummy_systimer_prepare,
80538 @@ -474,7 +474,7 @@ static void dummy_hrtimer_free(struct sn
80539 kfree(dpcm);
80540 }
80541
80542 -static struct dummy_timer_ops dummy_hrtimer_ops = {
80543 +static const struct dummy_timer_ops dummy_hrtimer_ops = {
80544 .create = dummy_hrtimer_create,
80545 .free = dummy_hrtimer_free,
80546 .prepare = dummy_hrtimer_prepare,
80547 @@ -660,7 +660,7 @@ static struct page *dummy_pcm_page(struc
80548 return virt_to_page(dummy_page[substream->stream]); /* the same page */
80549 }
80550
80551 -static struct snd_pcm_ops dummy_pcm_ops = {
80552 +static const struct snd_pcm_ops dummy_pcm_ops = {
80553 .open = dummy_pcm_open,
80554 .close = dummy_pcm_close,
80555 .ioctl = snd_pcm_lib_ioctl,
80556 @@ -671,7 +671,7 @@ static struct snd_pcm_ops dummy_pcm_ops
80557 .pointer = dummy_pcm_pointer,
80558 };
80559
80560 -static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
80561 +static const struct snd_pcm_ops dummy_pcm_ops_no_buf = {
80562 .open = dummy_pcm_open,
80563 .close = dummy_pcm_close,
80564 .ioctl = snd_pcm_lib_ioctl,
80565 @@ -689,7 +689,7 @@ static int __devinit snd_card_dummy_pcm(
80566 int substreams)
80567 {
80568 struct snd_pcm *pcm;
80569 - struct snd_pcm_ops *ops;
80570 + const struct snd_pcm_ops *ops;
80571 int err;
80572
80573 err = snd_pcm_new(dummy->card, "Dummy PCM", device,
80574 diff -urNp linux-2.6.39.1/sound/drivers/ml403-ac97cr.c linux-2.6.39.1/sound/drivers/ml403-ac97cr.c
80575 --- linux-2.6.39.1/sound/drivers/ml403-ac97cr.c 2011-05-19 00:06:34.000000000 -0400
80576 +++ linux-2.6.39.1/sound/drivers/ml403-ac97cr.c 2011-05-22 19:36:35.000000000 -0400
80577 @@ -759,7 +759,7 @@ static int snd_ml403_ac97cr_capture_clos
80578 return 0;
80579 }
80580
80581 -static struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
80582 +static const struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
80583 .open = snd_ml403_ac97cr_playback_open,
80584 .close = snd_ml403_ac97cr_playback_close,
80585 .ioctl = snd_pcm_lib_ioctl,
80586 @@ -770,7 +770,7 @@ static struct snd_pcm_ops snd_ml403_ac97
80587 .pointer = snd_ml403_ac97cr_pcm_pointer,
80588 };
80589
80590 -static struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
80591 +static const struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
80592 .open = snd_ml403_ac97cr_capture_open,
80593 .close = snd_ml403_ac97cr_capture_close,
80594 .ioctl = snd_pcm_lib_ioctl,
80595 @@ -1114,7 +1114,7 @@ snd_ml403_ac97cr_create(struct snd_card
80596 {
80597 struct snd_ml403_ac97cr *ml403_ac97cr;
80598 int err;
80599 - static struct snd_device_ops ops = {
80600 + static const struct snd_device_ops ops = {
80601 .dev_free = snd_ml403_ac97cr_dev_free,
80602 };
80603 struct resource *resource;
80604 @@ -1210,7 +1210,7 @@ snd_ml403_ac97cr_mixer(struct snd_ml403_
80605 struct snd_ac97_bus *bus;
80606 struct snd_ac97_template ac97;
80607 int err;
80608 - static struct snd_ac97_bus_ops ops = {
80609 + static const struct snd_ac97_bus_ops ops = {
80610 .write = snd_ml403_ac97cr_codec_write,
80611 .read = snd_ml403_ac97cr_codec_read,
80612 };
80613 diff -urNp linux-2.6.39.1/sound/drivers/mtpav.c linux-2.6.39.1/sound/drivers/mtpav.c
80614 --- linux-2.6.39.1/sound/drivers/mtpav.c 2011-05-19 00:06:34.000000000 -0400
80615 +++ linux-2.6.39.1/sound/drivers/mtpav.c 2011-05-22 19:36:35.000000000 -0400
80616 @@ -601,13 +601,13 @@ static int __devinit snd_mtpav_get_ISA(s
80617 /*
80618 */
80619
80620 -static struct snd_rawmidi_ops snd_mtpav_output = {
80621 +static const struct snd_rawmidi_ops snd_mtpav_output = {
80622 .open = snd_mtpav_output_open,
80623 .close = snd_mtpav_output_close,
80624 .trigger = snd_mtpav_output_trigger,
80625 };
80626
80627 -static struct snd_rawmidi_ops snd_mtpav_input = {
80628 +static const struct snd_rawmidi_ops snd_mtpav_input = {
80629 .open = snd_mtpav_input_open,
80630 .close = snd_mtpav_input_close,
80631 .trigger = snd_mtpav_input_trigger,
80632 diff -urNp linux-2.6.39.1/sound/drivers/mts64.c linux-2.6.39.1/sound/drivers/mts64.c
80633 --- linux-2.6.39.1/sound/drivers/mts64.c 2011-05-19 00:06:34.000000000 -0400
80634 +++ linux-2.6.39.1/sound/drivers/mts64.c 2011-05-22 19:36:35.000000000 -0400
80635 @@ -28,6 +28,7 @@
80636 #include <sound/initval.h>
80637 #include <sound/rawmidi.h>
80638 #include <sound/control.h>
80639 +#include <asm/local.h>
80640
80641 #define CARD_NAME "Miditerminal 4140"
80642 #define DRIVER_NAME "MTS64"
80643 @@ -66,7 +67,7 @@ struct mts64 {
80644 struct pardevice *pardev;
80645 int pardev_claimed;
80646
80647 - int open_count;
80648 + local_t open_count;
80649 int current_midi_output_port;
80650 int current_midi_input_port;
80651 u8 mode[MTS64_NUM_INPUT_PORTS];
80652 @@ -696,7 +697,7 @@ static int snd_mts64_rawmidi_open(struct
80653 {
80654 struct mts64 *mts = substream->rmidi->private_data;
80655
80656 - if (mts->open_count == 0) {
80657 + if (local_read(&mts->open_count) == 0) {
80658 /* We don't need a spinlock here, because this is just called
80659 if the device has not been opened before.
80660 So there aren't any IRQs from the device */
80661 @@ -704,7 +705,7 @@ static int snd_mts64_rawmidi_open(struct
80662
80663 msleep(50);
80664 }
80665 - ++(mts->open_count);
80666 + local_inc(&mts->open_count);
80667
80668 return 0;
80669 }
80670 @@ -714,8 +715,7 @@ static int snd_mts64_rawmidi_close(struc
80671 struct mts64 *mts = substream->rmidi->private_data;
80672 unsigned long flags;
80673
80674 - --(mts->open_count);
80675 - if (mts->open_count == 0) {
80676 + if (local_dec_return(&mts->open_count) == 0) {
80677 /* We need the spinlock_irqsave here because we can still
80678 have IRQs at this point */
80679 spin_lock_irqsave(&mts->lock, flags);
80680 @@ -724,8 +724,8 @@ static int snd_mts64_rawmidi_close(struc
80681
80682 msleep(500);
80683
80684 - } else if (mts->open_count < 0)
80685 - mts->open_count = 0;
80686 + } else if (local_read(&mts->open_count) < 0)
80687 + local_set(&mts->open_count, 0);
80688
80689 return 0;
80690 }
80691 @@ -760,13 +760,13 @@ static void snd_mts64_rawmidi_input_trig
80692 spin_unlock_irqrestore(&mts->lock, flags);
80693 }
80694
80695 -static struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
80696 +static const struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
80697 .open = snd_mts64_rawmidi_open,
80698 .close = snd_mts64_rawmidi_close,
80699 .trigger = snd_mts64_rawmidi_output_trigger
80700 };
80701
80702 -static struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
80703 +static const struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
80704 .open = snd_mts64_rawmidi_open,
80705 .close = snd_mts64_rawmidi_close,
80706 .trigger = snd_mts64_rawmidi_input_trigger
80707 diff -urNp linux-2.6.39.1/sound/drivers/pcsp/pcsp.c linux-2.6.39.1/sound/drivers/pcsp/pcsp.c
80708 --- linux-2.6.39.1/sound/drivers/pcsp/pcsp.c 2011-05-19 00:06:34.000000000 -0400
80709 +++ linux-2.6.39.1/sound/drivers/pcsp/pcsp.c 2011-05-22 19:36:35.000000000 -0400
80710 @@ -41,7 +41,7 @@ struct snd_pcsp pcsp_chip;
80711
80712 static int __devinit snd_pcsp_create(struct snd_card *card)
80713 {
80714 - static struct snd_device_ops ops = { };
80715 + static const struct snd_device_ops ops = { };
80716 struct timespec tp;
80717 int err;
80718 int div, min_div, order;
80719 diff -urNp linux-2.6.39.1/sound/drivers/pcsp/pcsp_lib.c linux-2.6.39.1/sound/drivers/pcsp/pcsp_lib.c
80720 --- linux-2.6.39.1/sound/drivers/pcsp/pcsp_lib.c 2011-05-19 00:06:34.000000000 -0400
80721 +++ linux-2.6.39.1/sound/drivers/pcsp/pcsp_lib.c 2011-05-22 19:36:35.000000000 -0400
80722 @@ -323,7 +323,7 @@ static int snd_pcsp_playback_open(struct
80723 return 0;
80724 }
80725
80726 -static struct snd_pcm_ops snd_pcsp_playback_ops = {
80727 +static const struct snd_pcm_ops snd_pcsp_playback_ops = {
80728 .open = snd_pcsp_playback_open,
80729 .close = snd_pcsp_playback_close,
80730 .ioctl = snd_pcm_lib_ioctl,
80731 diff -urNp linux-2.6.39.1/sound/drivers/portman2x4.c linux-2.6.39.1/sound/drivers/portman2x4.c
80732 --- linux-2.6.39.1/sound/drivers/portman2x4.c 2011-05-19 00:06:34.000000000 -0400
80733 +++ linux-2.6.39.1/sound/drivers/portman2x4.c 2011-05-22 19:36:35.000000000 -0400
80734 @@ -47,6 +47,7 @@
80735 #include <sound/initval.h>
80736 #include <sound/rawmidi.h>
80737 #include <sound/control.h>
80738 +#include <asm/local.h>
80739
80740 #define CARD_NAME "Portman 2x4"
80741 #define DRIVER_NAME "portman"
80742 @@ -84,7 +85,7 @@ struct portman {
80743 struct pardevice *pardev;
80744 int pardev_claimed;
80745
80746 - int open_count;
80747 + local_t open_count;
80748 int mode[PORTMAN_NUM_INPUT_PORTS];
80749 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80750 };
80751 @@ -547,13 +548,13 @@ static void snd_portman_midi_output_trig
80752 spin_unlock_irqrestore(&pm->reg_lock, flags);
80753 }
80754
80755 -static struct snd_rawmidi_ops snd_portman_midi_output = {
80756 +static const struct snd_rawmidi_ops snd_portman_midi_output = {
80757 .open = snd_portman_midi_open,
80758 .close = snd_portman_midi_close,
80759 .trigger = snd_portman_midi_output_trigger,
80760 };
80761
80762 -static struct snd_rawmidi_ops snd_portman_midi_input = {
80763 +static const struct snd_rawmidi_ops snd_portman_midi_input = {
80764 .open = snd_portman_midi_open,
80765 .close = snd_portman_midi_close,
80766 .trigger = snd_portman_midi_input_trigger,
80767 diff -urNp linux-2.6.39.1/sound/drivers/serial-u16550.c linux-2.6.39.1/sound/drivers/serial-u16550.c
80768 --- linux-2.6.39.1/sound/drivers/serial-u16550.c 2011-05-19 00:06:34.000000000 -0400
80769 +++ linux-2.6.39.1/sound/drivers/serial-u16550.c 2011-05-22 19:36:35.000000000 -0400
80770 @@ -754,15 +754,13 @@ static void snd_uart16550_output_trigger
80771 snd_uart16550_output_write(substream);
80772 }
80773
80774 -static struct snd_rawmidi_ops snd_uart16550_output =
80775 -{
80776 +static const struct snd_rawmidi_ops snd_uart16550_output = {
80777 .open = snd_uart16550_output_open,
80778 .close = snd_uart16550_output_close,
80779 .trigger = snd_uart16550_output_trigger,
80780 };
80781
80782 -static struct snd_rawmidi_ops snd_uart16550_input =
80783 -{
80784 +static const struct snd_rawmidi_ops snd_uart16550_input = {
80785 .open = snd_uart16550_input_open,
80786 .close = snd_uart16550_input_close,
80787 .trigger = snd_uart16550_input_trigger,
80788 @@ -792,7 +790,7 @@ static int __devinit snd_uart16550_creat
80789 int droponfull,
80790 struct snd_uart16550 **ruart)
80791 {
80792 - static struct snd_device_ops ops = {
80793 + static const struct snd_device_ops ops = {
80794 .dev_free = snd_uart16550_dev_free,
80795 };
80796 struct snd_uart16550 *uart;
80797 diff -urNp linux-2.6.39.1/sound/drivers/vx/vx_pcm.c linux-2.6.39.1/sound/drivers/vx/vx_pcm.c
80798 --- linux-2.6.39.1/sound/drivers/vx/vx_pcm.c 2011-05-19 00:06:34.000000000 -0400
80799 +++ linux-2.6.39.1/sound/drivers/vx/vx_pcm.c 2011-05-22 19:36:35.000000000 -0400
80800 @@ -895,7 +895,7 @@ static int vx_pcm_prepare(struct snd_pcm
80801 /*
80802 * operators for PCM playback
80803 */
80804 -static struct snd_pcm_ops vx_pcm_playback_ops = {
80805 +static const struct snd_pcm_ops vx_pcm_playback_ops = {
80806 .open = vx_pcm_playback_open,
80807 .close = vx_pcm_playback_close,
80808 .ioctl = snd_pcm_lib_ioctl,
80809 @@ -1116,7 +1116,7 @@ static snd_pcm_uframes_t vx_pcm_capture_
80810 /*
80811 * operators for PCM capture
80812 */
80813 -static struct snd_pcm_ops vx_pcm_capture_ops = {
80814 +static const struct snd_pcm_ops vx_pcm_capture_ops = {
80815 .open = vx_pcm_capture_open,
80816 .close = vx_pcm_capture_close,
80817 .ioctl = snd_pcm_lib_ioctl,
80818 diff -urNp linux-2.6.39.1/sound/firewire/amdtp.c linux-2.6.39.1/sound/firewire/amdtp.c
80819 --- linux-2.6.39.1/sound/firewire/amdtp.c 2011-05-19 00:06:34.000000000 -0400
80820 +++ linux-2.6.39.1/sound/firewire/amdtp.c 2011-05-22 19:36:35.000000000 -0400
80821 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdt
80822 ptr = s->pcm_buffer_pointer + data_blocks;
80823 if (ptr >= pcm->runtime->buffer_size)
80824 ptr -= pcm->runtime->buffer_size;
80825 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80826 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80827
80828 s->pcm_period_pointer += data_blocks;
80829 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80830 @@ -510,7 +510,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80831 */
80832 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80833 {
80834 - ACCESS_ONCE(s->source_node_id_field) =
80835 + ACCESS_ONCE_RW(s->source_node_id_field) =
80836 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80837 }
80838 EXPORT_SYMBOL(amdtp_out_stream_update);
80839 diff -urNp linux-2.6.39.1/sound/firewire/amdtp.h linux-2.6.39.1/sound/firewire/amdtp.h
80840 --- linux-2.6.39.1/sound/firewire/amdtp.h 2011-05-19 00:06:34.000000000 -0400
80841 +++ linux-2.6.39.1/sound/firewire/amdtp.h 2011-05-22 19:36:35.000000000 -0400
80842 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_
80843 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80844 struct snd_pcm_substream *pcm)
80845 {
80846 - ACCESS_ONCE(s->pcm) = pcm;
80847 + ACCESS_ONCE_RW(s->pcm) = pcm;
80848 }
80849
80850 /**
80851 diff -urNp linux-2.6.39.1/sound/i2c/i2c.c linux-2.6.39.1/sound/i2c/i2c.c
80852 --- linux-2.6.39.1/sound/i2c/i2c.c 2011-05-19 00:06:34.000000000 -0400
80853 +++ linux-2.6.39.1/sound/i2c/i2c.c 2011-05-22 19:36:35.000000000 -0400
80854 @@ -80,7 +80,7 @@ int snd_i2c_bus_create(struct snd_card *
80855 {
80856 struct snd_i2c_bus *bus;
80857 int err;
80858 - static struct snd_device_ops ops = {
80859 + static const struct snd_device_ops ops = {
80860 .dev_free = snd_i2c_bus_dev_free,
80861 };
80862
80863 diff -urNp linux-2.6.39.1/sound/i2c/other/ak4113.c linux-2.6.39.1/sound/i2c/other/ak4113.c
80864 --- linux-2.6.39.1/sound/i2c/other/ak4113.c 2011-05-19 00:06:34.000000000 -0400
80865 +++ linux-2.6.39.1/sound/i2c/other/ak4113.c 2011-05-22 19:36:35.000000000 -0400
80866 @@ -75,7 +75,7 @@ int snd_ak4113_create(struct snd_card *c
80867 struct ak4113 *chip;
80868 int err = 0;
80869 unsigned char reg;
80870 - static struct snd_device_ops ops = {
80871 + static const struct snd_device_ops ops = {
80872 .dev_free = snd_ak4113_dev_free,
80873 };
80874
80875 diff -urNp linux-2.6.39.1/sound/i2c/other/ak4114.c linux-2.6.39.1/sound/i2c/other/ak4114.c
80876 --- linux-2.6.39.1/sound/i2c/other/ak4114.c 2011-05-19 00:06:34.000000000 -0400
80877 +++ linux-2.6.39.1/sound/i2c/other/ak4114.c 2011-05-22 19:36:35.000000000 -0400
80878 @@ -86,7 +86,7 @@ int snd_ak4114_create(struct snd_card *c
80879 struct ak4114 *chip;
80880 int err = 0;
80881 unsigned char reg;
80882 - static struct snd_device_ops ops = {
80883 + static const struct snd_device_ops ops = {
80884 .dev_free = snd_ak4114_dev_free,
80885 };
80886
80887 diff -urNp linux-2.6.39.1/sound/i2c/other/ak4117.c linux-2.6.39.1/sound/i2c/other/ak4117.c
80888 --- linux-2.6.39.1/sound/i2c/other/ak4117.c 2011-05-19 00:06:34.000000000 -0400
80889 +++ linux-2.6.39.1/sound/i2c/other/ak4117.c 2011-05-22 19:36:35.000000000 -0400
80890 @@ -78,7 +78,7 @@ int snd_ak4117_create(struct snd_card *c
80891 struct ak4117 *chip;
80892 int err = 0;
80893 unsigned char reg;
80894 - static struct snd_device_ops ops = {
80895 + static const struct snd_device_ops ops = {
80896 .dev_free = snd_ak4117_dev_free,
80897 };
80898
80899 diff -urNp linux-2.6.39.1/sound/isa/ad1816a/ad1816a_lib.c linux-2.6.39.1/sound/isa/ad1816a/ad1816a_lib.c
80900 --- linux-2.6.39.1/sound/isa/ad1816a/ad1816a_lib.c 2011-05-19 00:06:34.000000000 -0400
80901 +++ linux-2.6.39.1/sound/isa/ad1816a/ad1816a_lib.c 2011-05-22 19:36:35.000000000 -0400
80902 @@ -575,7 +575,7 @@ int __devinit snd_ad1816a_create(struct
80903 unsigned long port, int irq, int dma1, int dma2,
80904 struct snd_ad1816a **rchip)
80905 {
80906 - static struct snd_device_ops ops = {
80907 + static const struct snd_device_ops ops = {
80908 .dev_free = snd_ad1816a_dev_free,
80909 };
80910 int error;
80911 diff -urNp linux-2.6.39.1/sound/isa/es1688/es1688_lib.c linux-2.6.39.1/sound/isa/es1688/es1688_lib.c
80912 --- linux-2.6.39.1/sound/isa/es1688/es1688_lib.c 2011-05-19 00:06:34.000000000 -0400
80913 +++ linux-2.6.39.1/sound/isa/es1688/es1688_lib.c 2011-05-22 19:36:35.000000000 -0400
80914 @@ -646,7 +646,7 @@ int snd_es1688_create(struct snd_card *c
80915 int dma8,
80916 unsigned short hardware)
80917 {
80918 - static struct snd_device_ops ops = {
80919 + static const struct snd_device_ops ops = {
80920 .dev_free = snd_es1688_dev_free,
80921 };
80922
80923 diff -urNp linux-2.6.39.1/sound/isa/es18xx.c linux-2.6.39.1/sound/isa/es18xx.c
80924 --- linux-2.6.39.1/sound/isa/es18xx.c 2011-05-19 00:06:34.000000000 -0400
80925 +++ linux-2.6.39.1/sound/isa/es18xx.c 2011-05-22 19:36:35.000000000 -0400
80926 @@ -1658,7 +1658,7 @@ static int __devinit snd_es18xx_probe(st
80927 return snd_es18xx_initialize(chip, mpu_port, fm_port);
80928 }
80929
80930 -static struct snd_pcm_ops snd_es18xx_playback_ops = {
80931 +static const struct snd_pcm_ops snd_es18xx_playback_ops = {
80932 .open = snd_es18xx_playback_open,
80933 .close = snd_es18xx_playback_close,
80934 .ioctl = snd_pcm_lib_ioctl,
80935 @@ -1669,7 +1669,7 @@ static struct snd_pcm_ops snd_es18xx_pla
80936 .pointer = snd_es18xx_playback_pointer,
80937 };
80938
80939 -static struct snd_pcm_ops snd_es18xx_capture_ops = {
80940 +static const struct snd_pcm_ops snd_es18xx_capture_ops = {
80941 .open = snd_es18xx_capture_open,
80942 .close = snd_es18xx_capture_close,
80943 .ioctl = snd_pcm_lib_ioctl,
80944 @@ -1784,7 +1784,7 @@ static int __devinit snd_es18xx_new_devi
80945 int irq, int dma1, int dma2)
80946 {
80947 struct snd_es18xx *chip = card->private_data;
80948 - static struct snd_device_ops ops = {
80949 + static const struct snd_device_ops ops = {
80950 .dev_free = snd_es18xx_dev_free,
80951 };
80952 int err;
80953 diff -urNp linux-2.6.39.1/sound/isa/gus/gus_main.c linux-2.6.39.1/sound/isa/gus/gus_main.c
80954 --- linux-2.6.39.1/sound/isa/gus/gus_main.c 2011-05-19 00:06:34.000000000 -0400
80955 +++ linux-2.6.39.1/sound/isa/gus/gus_main.c 2011-05-22 19:36:35.000000000 -0400
80956 @@ -139,7 +139,7 @@ int snd_gus_create(struct snd_card *card
80957 {
80958 struct snd_gus_card *gus;
80959 int err;
80960 - static struct snd_device_ops ops = {
80961 + static const struct snd_device_ops ops = {
80962 .dev_free = snd_gus_dev_free,
80963 };
80964
80965 diff -urNp linux-2.6.39.1/sound/isa/msnd/msnd.c linux-2.6.39.1/sound/isa/msnd/msnd.c
80966 --- linux-2.6.39.1/sound/isa/msnd/msnd.c 2011-05-19 00:06:34.000000000 -0400
80967 +++ linux-2.6.39.1/sound/isa/msnd/msnd.c 2011-05-22 19:36:35.000000000 -0400
80968 @@ -570,7 +570,7 @@ snd_msnd_playback_pointer(struct snd_pcm
80969 }
80970
80971
80972 -static struct snd_pcm_ops snd_msnd_playback_ops = {
80973 +static const struct snd_pcm_ops snd_msnd_playback_ops = {
80974 .open = snd_msnd_playback_open,
80975 .close = snd_msnd_playback_close,
80976 .ioctl = snd_pcm_lib_ioctl,
80977 @@ -667,7 +667,7 @@ static int snd_msnd_capture_hw_params(st
80978 }
80979
80980
80981 -static struct snd_pcm_ops snd_msnd_capture_ops = {
80982 +static const struct snd_pcm_ops snd_msnd_capture_ops = {
80983 .open = snd_msnd_capture_open,
80984 .close = snd_msnd_capture_close,
80985 .ioctl = snd_pcm_lib_ioctl,
80986 diff -urNp linux-2.6.39.1/sound/isa/msnd/msnd_midi.c linux-2.6.39.1/sound/isa/msnd/msnd_midi.c
80987 --- linux-2.6.39.1/sound/isa/msnd/msnd_midi.c 2011-05-19 00:06:34.000000000 -0400
80988 +++ linux-2.6.39.1/sound/isa/msnd/msnd_midi.c 2011-05-22 19:36:35.000000000 -0400
80989 @@ -141,7 +141,7 @@ void snd_msndmidi_input_read(void *mpuv)
80990 }
80991 EXPORT_SYMBOL(snd_msndmidi_input_read);
80992
80993 -static struct snd_rawmidi_ops snd_msndmidi_input = {
80994 +static const struct snd_rawmidi_ops snd_msndmidi_input = {
80995 .open = snd_msndmidi_input_open,
80996 .close = snd_msndmidi_input_close,
80997 .trigger = snd_msndmidi_input_trigger,
80998 diff -urNp linux-2.6.39.1/sound/isa/msnd/msnd_pinnacle.c linux-2.6.39.1/sound/isa/msnd/msnd_pinnacle.c
80999 --- linux-2.6.39.1/sound/isa/msnd/msnd_pinnacle.c 2011-05-19 00:06:34.000000000 -0400
81000 +++ linux-2.6.39.1/sound/isa/msnd/msnd_pinnacle.c 2011-05-22 19:36:35.000000000 -0400
81001 @@ -539,7 +539,7 @@ static int __devinit snd_msnd_attach(str
81002 {
81003 struct snd_msnd *chip = card->private_data;
81004 int err;
81005 - static struct snd_device_ops ops = {
81006 + static const struct snd_device_ops ops = {
81007 .dev_free = snd_msnd_dev_free,
81008 };
81009
81010 diff -urNp linux-2.6.39.1/sound/isa/sb/emu8000.c linux-2.6.39.1/sound/isa/sb/emu8000.c
81011 --- linux-2.6.39.1/sound/isa/sb/emu8000.c 2011-05-19 00:06:34.000000000 -0400
81012 +++ linux-2.6.39.1/sound/isa/sb/emu8000.c 2011-05-22 19:36:35.000000000 -0400
81013 @@ -1079,7 +1079,7 @@ snd_emu8000_new(struct snd_card *card, i
81014 struct snd_seq_device *awe;
81015 struct snd_emu8000 *hw;
81016 int err;
81017 - static struct snd_device_ops ops = {
81018 + static const struct snd_device_ops ops = {
81019 .dev_free = snd_emu8000_dev_free,
81020 };
81021
81022 diff -urNp linux-2.6.39.1/sound/isa/sb/emu8000_pcm.c linux-2.6.39.1/sound/isa/sb/emu8000_pcm.c
81023 --- linux-2.6.39.1/sound/isa/sb/emu8000_pcm.c 2011-05-19 00:06:34.000000000 -0400
81024 +++ linux-2.6.39.1/sound/isa/sb/emu8000_pcm.c 2011-05-22 19:36:35.000000000 -0400
81025 @@ -667,7 +667,7 @@ static snd_pcm_uframes_t emu8k_pcm_point
81026 }
81027
81028
81029 -static struct snd_pcm_ops emu8k_pcm_ops = {
81030 +static const struct snd_pcm_ops emu8k_pcm_ops = {
81031 .open = emu8k_pcm_open,
81032 .close = emu8k_pcm_close,
81033 .ioctl = snd_pcm_lib_ioctl,
81034 diff -urNp linux-2.6.39.1/sound/isa/sb/sb_common.c linux-2.6.39.1/sound/isa/sb/sb_common.c
81035 --- linux-2.6.39.1/sound/isa/sb/sb_common.c 2011-05-19 00:06:34.000000000 -0400
81036 +++ linux-2.6.39.1/sound/isa/sb/sb_common.c 2011-05-22 19:36:35.000000000 -0400
81037 @@ -218,7 +218,7 @@ int snd_sbdsp_create(struct snd_card *ca
81038 {
81039 struct snd_sb *chip;
81040 int err;
81041 - static struct snd_device_ops ops = {
81042 + static const struct snd_device_ops ops = {
81043 .dev_free = snd_sbdsp_dev_free,
81044 };
81045
81046 diff -urNp linux-2.6.39.1/sound/isa/wavefront/wavefront_midi.c linux-2.6.39.1/sound/isa/wavefront/wavefront_midi.c
81047 --- linux-2.6.39.1/sound/isa/wavefront/wavefront_midi.c 2011-05-19 00:06:34.000000000 -0400
81048 +++ linux-2.6.39.1/sound/isa/wavefront/wavefront_midi.c 2011-05-22 19:36:35.000000000 -0400
81049 @@ -561,14 +561,14 @@ snd_wavefront_midi_start (snd_wavefront_
81050 return 0;
81051 }
81052
81053 -struct snd_rawmidi_ops snd_wavefront_midi_output =
81054 +const struct snd_rawmidi_ops snd_wavefront_midi_output =
81055 {
81056 .open = snd_wavefront_midi_output_open,
81057 .close = snd_wavefront_midi_output_close,
81058 .trigger = snd_wavefront_midi_output_trigger,
81059 };
81060
81061 -struct snd_rawmidi_ops snd_wavefront_midi_input =
81062 +const struct snd_rawmidi_ops snd_wavefront_midi_input =
81063 {
81064 .open = snd_wavefront_midi_input_open,
81065 .close = snd_wavefront_midi_input_close,
81066 diff -urNp linux-2.6.39.1/sound/isa/wss/wss_lib.c linux-2.6.39.1/sound/isa/wss/wss_lib.c
81067 --- linux-2.6.39.1/sound/isa/wss/wss_lib.c 2011-05-19 00:06:34.000000000 -0400
81068 +++ linux-2.6.39.1/sound/isa/wss/wss_lib.c 2011-05-22 19:36:35.000000000 -0400
81069 @@ -1801,7 +1801,7 @@ int snd_wss_create(struct snd_card *card
81070 unsigned short hwshare,
81071 struct snd_wss **rchip)
81072 {
81073 - static struct snd_device_ops ops = {
81074 + static const struct snd_device_ops ops = {
81075 .dev_free = snd_wss_dev_free,
81076 };
81077 struct snd_wss *chip;
81078 diff -urNp linux-2.6.39.1/sound/mips/au1x00.c linux-2.6.39.1/sound/mips/au1x00.c
81079 --- linux-2.6.39.1/sound/mips/au1x00.c 2011-05-19 00:06:34.000000000 -0400
81080 +++ linux-2.6.39.1/sound/mips/au1x00.c 2011-05-22 19:36:35.000000000 -0400
81081 @@ -416,7 +416,7 @@ snd_au1000_pointer(struct snd_pcm_substr
81082 return bytes_to_frames(runtime,location);
81083 }
81084
81085 -static struct snd_pcm_ops snd_card_au1000_playback_ops = {
81086 +static const struct snd_pcm_ops snd_card_au1000_playback_ops = {
81087 .open = snd_au1000_playback_open,
81088 .close = snd_au1000_playback_close,
81089 .ioctl = snd_pcm_lib_ioctl,
81090 @@ -427,7 +427,7 @@ static struct snd_pcm_ops snd_card_au100
81091 .pointer = snd_au1000_pointer,
81092 };
81093
81094 -static struct snd_pcm_ops snd_card_au1000_capture_ops = {
81095 +static const struct snd_pcm_ops snd_card_au1000_capture_ops = {
81096 .open = snd_au1000_capture_open,
81097 .close = snd_au1000_capture_close,
81098 .ioctl = snd_pcm_lib_ioctl,
81099 @@ -557,7 +557,7 @@ snd_au1000_ac97_new(struct snd_au1000 *a
81100 int err;
81101 struct snd_ac97_bus *pbus;
81102 struct snd_ac97_template ac97;
81103 - static struct snd_ac97_bus_ops ops = {
81104 + static const struct snd_ac97_bus_ops ops = {
81105 .write = snd_au1000_ac97_write,
81106 .read = snd_au1000_ac97_read,
81107 };
81108 diff -urNp linux-2.6.39.1/sound/mips/hal2.c linux-2.6.39.1/sound/mips/hal2.c
81109 --- linux-2.6.39.1/sound/mips/hal2.c 2011-05-19 00:06:34.000000000 -0400
81110 +++ linux-2.6.39.1/sound/mips/hal2.c 2011-05-22 19:36:35.000000000 -0400
81111 @@ -708,7 +708,7 @@ static int hal2_capture_ack(struct snd_p
81112 return 0;
81113 }
81114
81115 -static struct snd_pcm_ops hal2_playback_ops = {
81116 +static const struct snd_pcm_ops hal2_playback_ops = {
81117 .open = hal2_playback_open,
81118 .close = hal2_playback_close,
81119 .ioctl = snd_pcm_lib_ioctl,
81120 @@ -720,7 +720,7 @@ static struct snd_pcm_ops hal2_playback_
81121 .ack = hal2_playback_ack,
81122 };
81123
81124 -static struct snd_pcm_ops hal2_capture_ops = {
81125 +static const struct snd_pcm_ops hal2_capture_ops = {
81126 .open = hal2_capture_open,
81127 .close = hal2_capture_close,
81128 .ioctl = snd_pcm_lib_ioctl,
81129 @@ -766,7 +766,7 @@ static int hal2_dev_free(struct snd_devi
81130 return 0;
81131 }
81132
81133 -static struct snd_device_ops hal2_ops = {
81134 +static const struct snd_device_ops hal2_ops = {
81135 .dev_free = hal2_dev_free,
81136 };
81137
81138 diff -urNp linux-2.6.39.1/sound/mips/sgio2audio.c linux-2.6.39.1/sound/mips/sgio2audio.c
81139 --- linux-2.6.39.1/sound/mips/sgio2audio.c 2011-05-19 00:06:34.000000000 -0400
81140 +++ linux-2.6.39.1/sound/mips/sgio2audio.c 2011-05-22 19:36:35.000000000 -0400
81141 @@ -681,7 +681,7 @@ snd_sgio2audio_pcm_pointer(struct snd_pc
81142 }
81143
81144 /* operators */
81145 -static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
81146 +static const struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
81147 .open = snd_sgio2audio_playback1_open,
81148 .close = snd_sgio2audio_pcm_close,
81149 .ioctl = snd_pcm_lib_ioctl,
81150 @@ -694,7 +694,7 @@ static struct snd_pcm_ops snd_sgio2audio
81151 .mmap = snd_pcm_lib_mmap_vmalloc,
81152 };
81153
81154 -static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
81155 +static const struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
81156 .open = snd_sgio2audio_playback2_open,
81157 .close = snd_sgio2audio_pcm_close,
81158 .ioctl = snd_pcm_lib_ioctl,
81159 @@ -707,7 +707,7 @@ static struct snd_pcm_ops snd_sgio2audio
81160 .mmap = snd_pcm_lib_mmap_vmalloc,
81161 };
81162
81163 -static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
81164 +static const struct snd_pcm_ops snd_sgio2audio_capture_ops = {
81165 .open = snd_sgio2audio_capture_open,
81166 .close = snd_sgio2audio_pcm_close,
81167 .ioctl = snd_pcm_lib_ioctl,
81168 @@ -829,7 +829,7 @@ static int snd_sgio2audio_dev_free(struc
81169 return snd_sgio2audio_free(chip);
81170 }
81171
81172 -static struct snd_device_ops ops = {
81173 +static const struct snd_device_ops ops = {
81174 .dev_free = snd_sgio2audio_dev_free,
81175 };
81176
81177 diff -urNp linux-2.6.39.1/sound/oss/ac97_codec.c linux-2.6.39.1/sound/oss/ac97_codec.c
81178 --- linux-2.6.39.1/sound/oss/ac97_codec.c 2011-05-19 00:06:34.000000000 -0400
81179 +++ linux-2.6.39.1/sound/oss/ac97_codec.c 2011-05-22 19:36:35.000000000 -0400
81180 @@ -99,23 +99,23 @@ static int generic_digital_control(struc
81181 * operations yet
81182 */
81183
81184 -static struct ac97_ops null_ops = { NULL, NULL, NULL };
81185 -static struct ac97_ops default_ops = { NULL, eapd_control, NULL };
81186 -static struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
81187 -static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
81188 -static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
81189 -static struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
81190 -static struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
81191 -static struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
81192 -static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
81193 -static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
81194 -static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
81195 -static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
81196 -static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
81197 -static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
81198 -static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
81199 -static struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
81200 -static struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
81201 +static const struct ac97_ops null_ops = { NULL, NULL, NULL };
81202 +static const struct ac97_ops default_ops = { NULL, eapd_control, NULL };
81203 +static const struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
81204 +static const struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
81205 +static const struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
81206 +static const struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
81207 +static const struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
81208 +static const struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
81209 +static const struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
81210 +static const struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
81211 +static const struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
81212 +static const struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
81213 +static const struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
81214 +static const struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
81215 +static const struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
81216 +static const struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
81217 +static const struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
81218
81219 /* sorted by vendor/device id */
81220 static const struct {
81221 diff -urNp linux-2.6.39.1/sound/oss/sb_audio.c linux-2.6.39.1/sound/oss/sb_audio.c
81222 --- linux-2.6.39.1/sound/oss/sb_audio.c 2011-05-19 00:06:34.000000000 -0400
81223 +++ linux-2.6.39.1/sound/oss/sb_audio.c 2011-05-22 19:36:35.000000000 -0400
81224 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
81225 buf16 = (signed short *)(localbuf + localoffs);
81226 while (c)
81227 {
81228 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81229 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81230 if (copy_from_user(lbuf8,
81231 userbuf+useroffs + p,
81232 locallen))
81233 diff -urNp linux-2.6.39.1/sound/oss/swarm_cs4297a.c linux-2.6.39.1/sound/oss/swarm_cs4297a.c
81234 --- linux-2.6.39.1/sound/oss/swarm_cs4297a.c 2011-05-19 00:06:34.000000000 -0400
81235 +++ linux-2.6.39.1/sound/oss/swarm_cs4297a.c 2011-05-22 19:36:35.000000000 -0400
81236 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
81237 {
81238 struct cs4297a_state *s;
81239 u32 pwr, id;
81240 - mm_segment_t fs;
81241 int rval;
81242 #ifndef CONFIG_BCM_CS4297A_CSWARM
81243 u64 cfg;
81244 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
81245 if (!rval) {
81246 char *sb1250_duart_present;
81247
81248 +#if 0
81249 + mm_segment_t fs;
81250 fs = get_fs();
81251 set_fs(KERNEL_DS);
81252 -#if 0
81253 val = SOUND_MASK_LINE;
81254 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81255 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81256 val = initvol[i].vol;
81257 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81258 }
81259 + set_fs(fs);
81260 // cs4297a_write_ac97(s, 0x18, 0x0808);
81261 #else
81262 // cs4297a_write_ac97(s, 0x5e, 0x180);
81263 cs4297a_write_ac97(s, 0x02, 0x0808);
81264 cs4297a_write_ac97(s, 0x18, 0x0808);
81265 #endif
81266 - set_fs(fs);
81267
81268 list_add(&s->list, &cs4297a_devs);
81269
81270 diff -urNp linux-2.6.39.1/sound/parisc/harmony.c linux-2.6.39.1/sound/parisc/harmony.c
81271 --- linux-2.6.39.1/sound/parisc/harmony.c 2011-05-19 00:06:34.000000000 -0400
81272 +++ linux-2.6.39.1/sound/parisc/harmony.c 2011-05-22 19:36:35.000000000 -0400
81273 @@ -596,7 +596,7 @@ snd_harmony_hw_free(struct snd_pcm_subst
81274 return snd_pcm_lib_free_pages(ss);
81275 }
81276
81277 -static struct snd_pcm_ops snd_harmony_playback_ops = {
81278 +static const struct snd_pcm_ops snd_harmony_playback_ops = {
81279 .open = snd_harmony_playback_open,
81280 .close = snd_harmony_playback_close,
81281 .ioctl = snd_pcm_lib_ioctl,
81282 @@ -607,7 +607,7 @@ static struct snd_pcm_ops snd_harmony_pl
81283 .pointer = snd_harmony_playback_pointer,
81284 };
81285
81286 -static struct snd_pcm_ops snd_harmony_capture_ops = {
81287 +static const struct snd_pcm_ops snd_harmony_capture_ops = {
81288 .open = snd_harmony_capture_open,
81289 .close = snd_harmony_capture_close,
81290 .ioctl = snd_pcm_lib_ioctl,
81291 @@ -922,7 +922,7 @@ snd_harmony_create(struct snd_card *card
81292 {
81293 int err;
81294 struct snd_harmony *h;
81295 - static struct snd_device_ops ops = {
81296 + static const struct snd_device_ops ops = {
81297 .dev_free = snd_harmony_dev_free,
81298 };
81299
81300 diff -urNp linux-2.6.39.1/sound/pci/ac97/ac97_codec.c linux-2.6.39.1/sound/pci/ac97/ac97_codec.c
81301 --- linux-2.6.39.1/sound/pci/ac97/ac97_codec.c 2011-05-19 00:06:34.000000000 -0400
81302 +++ linux-2.6.39.1/sound/pci/ac97/ac97_codec.c 2011-05-22 19:36:35.000000000 -0400
81303 @@ -1910,12 +1910,12 @@ static int ac97_reset_wait(struct snd_ac
81304 *
81305 * Returns zero if successful, or a negative error code on failure.
81306 */
81307 -int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
81308 +int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
81309 void *private_data, struct snd_ac97_bus **rbus)
81310 {
81311 int err;
81312 struct snd_ac97_bus *bus;
81313 - static struct snd_device_ops dev_ops = {
81314 + static const struct snd_device_ops dev_ops = {
81315 .dev_free = snd_ac97_bus_dev_free,
81316 };
81317
81318 @@ -2015,7 +2015,7 @@ int snd_ac97_mixer(struct snd_ac97_bus *
81319 unsigned long end_time;
81320 unsigned int reg;
81321 const struct ac97_codec_id *pid;
81322 - static struct snd_device_ops ops = {
81323 + static const struct snd_device_ops ops = {
81324 .dev_free = snd_ac97_dev_free,
81325 .dev_register = snd_ac97_dev_register,
81326 .dev_disconnect = snd_ac97_dev_disconnect,
81327 diff -urNp linux-2.6.39.1/sound/pci/ad1889.c linux-2.6.39.1/sound/pci/ad1889.c
81328 --- linux-2.6.39.1/sound/pci/ad1889.c 2011-05-19 00:06:34.000000000 -0400
81329 +++ linux-2.6.39.1/sound/pci/ad1889.c 2011-05-22 19:36:35.000000000 -0400
81330 @@ -574,7 +574,7 @@ snd_ad1889_capture_pointer(struct snd_pc
81331 return bytes_to_frames(ss->runtime, ptr);
81332 }
81333
81334 -static struct snd_pcm_ops snd_ad1889_playback_ops = {
81335 +static const struct snd_pcm_ops snd_ad1889_playback_ops = {
81336 .open = snd_ad1889_playback_open,
81337 .close = snd_ad1889_playback_close,
81338 .ioctl = snd_pcm_lib_ioctl,
81339 @@ -585,7 +585,7 @@ static struct snd_pcm_ops snd_ad1889_pla
81340 .pointer = snd_ad1889_playback_pointer,
81341 };
81342
81343 -static struct snd_pcm_ops snd_ad1889_capture_ops = {
81344 +static const struct snd_pcm_ops snd_ad1889_capture_ops = {
81345 .open = snd_ad1889_capture_open,
81346 .close = snd_ad1889_capture_close,
81347 .ioctl = snd_pcm_lib_ioctl,
81348 @@ -809,7 +809,7 @@ snd_ad1889_ac97_init(struct snd_ad1889 *
81349 {
81350 int err;
81351 struct snd_ac97_template ac97;
81352 - static struct snd_ac97_bus_ops ops = {
81353 + static const struct snd_ac97_bus_ops ops = {
81354 .write = snd_ad1889_ac97_write,
81355 .read = snd_ad1889_ac97_read,
81356 };
81357 @@ -899,7 +899,7 @@ snd_ad1889_create(struct snd_card *card,
81358 int err;
81359
81360 struct snd_ad1889 *chip;
81361 - static struct snd_device_ops ops = {
81362 + static const struct snd_device_ops ops = {
81363 .dev_free = snd_ad1889_dev_free,
81364 };
81365
81366 diff -urNp linux-2.6.39.1/sound/pci/ak4531_codec.c linux-2.6.39.1/sound/pci/ak4531_codec.c
81367 --- linux-2.6.39.1/sound/pci/ak4531_codec.c 2011-05-19 00:06:34.000000000 -0400
81368 +++ linux-2.6.39.1/sound/pci/ak4531_codec.c 2011-05-22 19:36:35.000000000 -0400
81369 @@ -389,7 +389,7 @@ int __devinit snd_ak4531_mixer(struct sn
81370 unsigned int idx;
81371 int err;
81372 struct snd_ak4531 *ak4531;
81373 - static struct snd_device_ops ops = {
81374 + static const struct snd_device_ops ops = {
81375 .dev_free = snd_ak4531_dev_free,
81376 };
81377
81378 diff -urNp linux-2.6.39.1/sound/pci/ali5451/ali5451.c linux-2.6.39.1/sound/pci/ali5451/ali5451.c
81379 --- linux-2.6.39.1/sound/pci/ali5451/ali5451.c 2011-05-19 00:06:34.000000000 -0400
81380 +++ linux-2.6.39.1/sound/pci/ali5451/ali5451.c 2011-05-22 19:36:35.000000000 -0400
81381 @@ -1847,7 +1847,7 @@ static int __devinit snd_ali_mixer(struc
81382 struct snd_ac97_template ac97;
81383 unsigned int idx;
81384 int i, err;
81385 - static struct snd_ac97_bus_ops ops = {
81386 + static const struct snd_ac97_bus_ops ops = {
81387 .write = snd_ali_codec_write,
81388 .read = snd_ali_codec_read,
81389 };
81390 @@ -2114,7 +2114,7 @@ static int __devinit snd_ali_create(stru
81391 struct snd_ali *codec;
81392 int i, err;
81393 unsigned short cmdw;
81394 - static struct snd_device_ops ops = {
81395 + static const struct snd_device_ops ops = {
81396 .dev_free = snd_ali_dev_free,
81397 };
81398
81399 diff -urNp linux-2.6.39.1/sound/pci/als300.c linux-2.6.39.1/sound/pci/als300.c
81400 --- linux-2.6.39.1/sound/pci/als300.c 2011-05-19 00:06:34.000000000 -0400
81401 +++ linux-2.6.39.1/sound/pci/als300.c 2011-05-22 19:36:35.000000000 -0400
81402 @@ -319,7 +319,7 @@ static int snd_als300_ac97(struct snd_al
81403 struct snd_ac97_bus *bus;
81404 struct snd_ac97_template ac97;
81405 int err;
81406 - static struct snd_ac97_bus_ops ops = {
81407 + static const struct snd_ac97_bus_ops ops = {
81408 .write = snd_als300_ac97_write,
81409 .read = snd_als300_ac97_read,
81410 };
81411 @@ -589,7 +589,7 @@ static snd_pcm_uframes_t snd_als300_poin
81412 return bytes_to_frames(substream->runtime, current_ptr);
81413 }
81414
81415 -static struct snd_pcm_ops snd_als300_playback_ops = {
81416 +static const struct snd_pcm_ops snd_als300_playback_ops = {
81417 .open = snd_als300_playback_open,
81418 .close = snd_als300_playback_close,
81419 .ioctl = snd_pcm_lib_ioctl,
81420 @@ -600,7 +600,7 @@ static struct snd_pcm_ops snd_als300_pla
81421 .pointer = snd_als300_pointer,
81422 };
81423
81424 -static struct snd_pcm_ops snd_als300_capture_ops = {
81425 +static const struct snd_pcm_ops snd_als300_capture_ops = {
81426 .open = snd_als300_capture_open,
81427 .close = snd_als300_capture_close,
81428 .ioctl = snd_pcm_lib_ioctl,
81429 @@ -680,7 +680,7 @@ static int __devinit snd_als300_create(s
81430 void *irq_handler;
81431 int err;
81432
81433 - static struct snd_device_ops ops = {
81434 + static const struct snd_device_ops ops = {
81435 .dev_free = snd_als300_dev_free,
81436 };
81437 *rchip = NULL;
81438 diff -urNp linux-2.6.39.1/sound/pci/als4000.c linux-2.6.39.1/sound/pci/als4000.c
81439 --- linux-2.6.39.1/sound/pci/als4000.c 2011-05-19 00:06:34.000000000 -0400
81440 +++ linux-2.6.39.1/sound/pci/als4000.c 2011-05-22 19:36:35.000000000 -0400
81441 @@ -672,7 +672,7 @@ static int snd_als4000_capture_close(str
81442
81443 /******************************************************************/
81444
81445 -static struct snd_pcm_ops snd_als4000_playback_ops = {
81446 +static const struct snd_pcm_ops snd_als4000_playback_ops = {
81447 .open = snd_als4000_playback_open,
81448 .close = snd_als4000_playback_close,
81449 .ioctl = snd_pcm_lib_ioctl,
81450 @@ -683,7 +683,7 @@ static struct snd_pcm_ops snd_als4000_pl
81451 .pointer = snd_als4000_playback_pointer
81452 };
81453
81454 -static struct snd_pcm_ops snd_als4000_capture_ops = {
81455 +static const struct snd_pcm_ops snd_als4000_capture_ops = {
81456 .open = snd_als4000_capture_open,
81457 .close = snd_als4000_capture_close,
81458 .ioctl = snd_pcm_lib_ioctl,
81459 diff -urNp linux-2.6.39.1/sound/pci/asihpi/asihpi.c linux-2.6.39.1/sound/pci/asihpi/asihpi.c
81460 --- linux-2.6.39.1/sound/pci/asihpi/asihpi.c 2011-05-19 00:06:34.000000000 -0400
81461 +++ linux-2.6.39.1/sound/pci/asihpi/asihpi.c 2011-05-22 19:36:35.000000000 -0400
81462 @@ -1067,7 +1067,7 @@ static int snd_card_asihpi_playback_sile
81463 return 0;
81464 }
81465
81466 -static struct snd_pcm_ops snd_card_asihpi_playback_ops = {
81467 +static const struct snd_pcm_ops snd_card_asihpi_playback_ops = {
81468 .open = snd_card_asihpi_playback_open,
81469 .close = snd_card_asihpi_playback_close,
81470 .ioctl = snd_card_asihpi_playback_ioctl,
81471 @@ -1080,7 +1080,7 @@ static struct snd_pcm_ops snd_card_asihp
81472 .silence = snd_card_asihpi_playback_silence,
81473 };
81474
81475 -static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
81476 +static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
81477 .open = snd_card_asihpi_playback_open,
81478 .close = snd_card_asihpi_playback_close,
81479 .ioctl = snd_card_asihpi_playback_ioctl,
81480 @@ -1268,7 +1268,7 @@ static int snd_card_asihpi_capture_copy(
81481 return 0;
81482 }
81483
81484 -static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
81485 +static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
81486 .open = snd_card_asihpi_capture_open,
81487 .close = snd_card_asihpi_capture_close,
81488 .ioctl = snd_card_asihpi_capture_ioctl,
81489 @@ -1279,7 +1279,7 @@ static struct snd_pcm_ops snd_card_asihp
81490 .pointer = snd_card_asihpi_capture_pointer,
81491 };
81492
81493 -static struct snd_pcm_ops snd_card_asihpi_capture_ops = {
81494 +static const struct snd_pcm_ops snd_card_asihpi_capture_ops = {
81495 .open = snd_card_asihpi_capture_open,
81496 .close = snd_card_asihpi_capture_close,
81497 .ioctl = snd_card_asihpi_capture_ioctl,
81498 diff -urNp linux-2.6.39.1/sound/pci/atiixp.c linux-2.6.39.1/sound/pci/atiixp.c
81499 --- linux-2.6.39.1/sound/pci/atiixp.c 2011-05-19 00:06:34.000000000 -0400
81500 +++ linux-2.6.39.1/sound/pci/atiixp.c 2011-05-22 19:36:35.000000000 -0400
81501 @@ -1148,7 +1148,7 @@ static int snd_atiixp_spdif_close(struct
81502 }
81503
81504 /* AC97 playback */
81505 -static struct snd_pcm_ops snd_atiixp_playback_ops = {
81506 +static const struct snd_pcm_ops snd_atiixp_playback_ops = {
81507 .open = snd_atiixp_playback_open,
81508 .close = snd_atiixp_playback_close,
81509 .ioctl = snd_pcm_lib_ioctl,
81510 @@ -1160,7 +1160,7 @@ static struct snd_pcm_ops snd_atiixp_pla
81511 };
81512
81513 /* AC97 capture */
81514 -static struct snd_pcm_ops snd_atiixp_capture_ops = {
81515 +static const struct snd_pcm_ops snd_atiixp_capture_ops = {
81516 .open = snd_atiixp_capture_open,
81517 .close = snd_atiixp_capture_close,
81518 .ioctl = snd_pcm_lib_ioctl,
81519 @@ -1172,7 +1172,7 @@ static struct snd_pcm_ops snd_atiixp_cap
81520 };
81521
81522 /* SPDIF playback */
81523 -static struct snd_pcm_ops snd_atiixp_spdif_ops = {
81524 +static const struct snd_pcm_ops snd_atiixp_spdif_ops = {
81525 .open = snd_atiixp_spdif_open,
81526 .close = snd_atiixp_spdif_close,
81527 .ioctl = snd_pcm_lib_ioctl,
81528 @@ -1410,7 +1410,7 @@ static int __devinit snd_atiixp_mixer_ne
81529 struct snd_ac97_template ac97;
81530 int i, err;
81531 int codec_count;
81532 - static struct snd_ac97_bus_ops ops = {
81533 + static const struct snd_ac97_bus_ops ops = {
81534 .write = snd_atiixp_ac97_write,
81535 .read = snd_atiixp_ac97_read,
81536 };
81537 @@ -1590,7 +1590,7 @@ static int __devinit snd_atiixp_create(s
81538 struct pci_dev *pci,
81539 struct atiixp **r_chip)
81540 {
81541 - static struct snd_device_ops ops = {
81542 + static const struct snd_device_ops ops = {
81543 .dev_free = snd_atiixp_dev_free,
81544 };
81545 struct atiixp *chip;
81546 diff -urNp linux-2.6.39.1/sound/pci/atiixp_modem.c linux-2.6.39.1/sound/pci/atiixp_modem.c
81547 --- linux-2.6.39.1/sound/pci/atiixp_modem.c 2011-05-19 00:06:34.000000000 -0400
81548 +++ linux-2.6.39.1/sound/pci/atiixp_modem.c 2011-05-22 19:36:35.000000000 -0400
81549 @@ -947,7 +947,7 @@ static int snd_atiixp_capture_close(stru
81550
81551
81552 /* AC97 playback */
81553 -static struct snd_pcm_ops snd_atiixp_playback_ops = {
81554 +static const struct snd_pcm_ops snd_atiixp_playback_ops = {
81555 .open = snd_atiixp_playback_open,
81556 .close = snd_atiixp_playback_close,
81557 .ioctl = snd_pcm_lib_ioctl,
81558 @@ -959,7 +959,7 @@ static struct snd_pcm_ops snd_atiixp_pla
81559 };
81560
81561 /* AC97 capture */
81562 -static struct snd_pcm_ops snd_atiixp_capture_ops = {
81563 +static const struct snd_pcm_ops snd_atiixp_capture_ops = {
81564 .open = snd_atiixp_capture_open,
81565 .close = snd_atiixp_capture_close,
81566 .ioctl = snd_pcm_lib_ioctl,
81567 @@ -1067,7 +1067,7 @@ static int __devinit snd_atiixp_mixer_ne
81568 struct snd_ac97_template ac97;
81569 int i, err;
81570 int codec_count;
81571 - static struct snd_ac97_bus_ops ops = {
81572 + static const struct snd_ac97_bus_ops ops = {
81573 .write = snd_atiixp_ac97_write,
81574 .read = snd_atiixp_ac97_read,
81575 };
81576 @@ -1226,7 +1226,7 @@ static int __devinit snd_atiixp_create(s
81577 struct pci_dev *pci,
81578 struct atiixp_modem **r_chip)
81579 {
81580 - static struct snd_device_ops ops = {
81581 + static const struct snd_device_ops ops = {
81582 .dev_free = snd_atiixp_dev_free,
81583 };
81584 struct atiixp_modem *chip;
81585 diff -urNp linux-2.6.39.1/sound/pci/au88x0/au88x0_pcm.c linux-2.6.39.1/sound/pci/au88x0/au88x0_pcm.c
81586 --- linux-2.6.39.1/sound/pci/au88x0/au88x0_pcm.c 2011-05-19 00:06:34.000000000 -0400
81587 +++ linux-2.6.39.1/sound/pci/au88x0/au88x0_pcm.c 2011-05-22 19:36:35.000000000 -0400
81588 @@ -409,7 +409,7 @@ static snd_pcm_uframes_t snd_vortex_pcm_
81589 }
81590
81591 /* operators */
81592 -static struct snd_pcm_ops snd_vortex_playback_ops = {
81593 +static const struct snd_pcm_ops snd_vortex_playback_ops = {
81594 .open = snd_vortex_pcm_open,
81595 .close = snd_vortex_pcm_close,
81596 .ioctl = snd_pcm_lib_ioctl,
81597 diff -urNp linux-2.6.39.1/sound/pci/aw2/aw2-alsa.c linux-2.6.39.1/sound/pci/aw2/aw2-alsa.c
81598 --- linux-2.6.39.1/sound/pci/aw2/aw2-alsa.c 2011-05-19 00:06:34.000000000 -0400
81599 +++ linux-2.6.39.1/sound/pci/aw2/aw2-alsa.c 2011-05-22 19:36:35.000000000 -0400
81600 @@ -178,7 +178,7 @@ static struct pci_driver driver = {
81601 };
81602
81603 /* operators for playback PCM alsa interface */
81604 -static struct snd_pcm_ops snd_aw2_playback_ops = {
81605 +static const struct snd_pcm_ops snd_aw2_playback_ops = {
81606 .open = snd_aw2_pcm_playback_open,
81607 .close = snd_aw2_pcm_playback_close,
81608 .ioctl = snd_pcm_lib_ioctl,
81609 @@ -190,7 +190,7 @@ static struct snd_pcm_ops snd_aw2_playba
81610 };
81611
81612 /* operators for capture PCM alsa interface */
81613 -static struct snd_pcm_ops snd_aw2_capture_ops = {
81614 +static const struct snd_pcm_ops snd_aw2_capture_ops = {
81615 .open = snd_aw2_pcm_capture_open,
81616 .close = snd_aw2_pcm_capture_close,
81617 .ioctl = snd_pcm_lib_ioctl,
81618 @@ -263,7 +263,7 @@ static int __devinit snd_aw2_create(stru
81619 {
81620 struct aw2 *chip;
81621 int err;
81622 - static struct snd_device_ops ops = {
81623 + static const struct snd_device_ops ops = {
81624 .dev_free = snd_aw2_dev_free,
81625 };
81626
81627 diff -urNp linux-2.6.39.1/sound/pci/azt3328.c linux-2.6.39.1/sound/pci/azt3328.c
81628 --- linux-2.6.39.1/sound/pci/azt3328.c 2011-05-19 00:06:34.000000000 -0400
81629 +++ linux-2.6.39.1/sound/pci/azt3328.c 2011-05-22 19:36:35.000000000 -0400
81630 @@ -822,7 +822,7 @@ snd_azf3328_mixer_new(struct snd_azf3328
81631 {
81632 struct snd_ac97_bus *bus;
81633 struct snd_ac97_template ac97;
81634 - static struct snd_ac97_bus_ops ops = {
81635 + static const struct snd_ac97_bus_ops ops = {
81636 .write = snd_azf3328_mixer_ac97_write,
81637 .read = snd_azf3328_mixer_ac97_read,
81638 };
81639 @@ -2179,7 +2179,7 @@ snd_azf3328_pcm_close(struct snd_pcm_sub
81640
81641 /******************************************************************/
81642
81643 -static struct snd_pcm_ops snd_azf3328_playback_ops = {
81644 +static const struct snd_pcm_ops snd_azf3328_playback_ops = {
81645 .open = snd_azf3328_pcm_playback_open,
81646 .close = snd_azf3328_pcm_close,
81647 .ioctl = snd_pcm_lib_ioctl,
81648 @@ -2190,7 +2190,7 @@ static struct snd_pcm_ops snd_azf3328_pl
81649 .pointer = snd_azf3328_pcm_pointer
81650 };
81651
81652 -static struct snd_pcm_ops snd_azf3328_capture_ops = {
81653 +static const struct snd_pcm_ops snd_azf3328_capture_ops = {
81654 .open = snd_azf3328_pcm_capture_open,
81655 .close = snd_azf3328_pcm_close,
81656 .ioctl = snd_pcm_lib_ioctl,
81657 @@ -2201,7 +2201,7 @@ static struct snd_pcm_ops snd_azf3328_ca
81658 .pointer = snd_azf3328_pcm_pointer
81659 };
81660
81661 -static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
81662 +static const struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
81663 .open = snd_azf3328_pcm_i2s_out_open,
81664 .close = snd_azf3328_pcm_close,
81665 .ioctl = snd_pcm_lib_ioctl,
81666 @@ -2497,7 +2497,7 @@ snd_azf3328_create(struct snd_card *card
81667 {
81668 struct snd_azf3328 *chip;
81669 int err;
81670 - static struct snd_device_ops ops = {
81671 + static const struct snd_device_ops ops = {
81672 .dev_free = snd_azf3328_dev_free,
81673 };
81674 u8 dma_init;
81675 diff -urNp linux-2.6.39.1/sound/pci/bt87x.c linux-2.6.39.1/sound/pci/bt87x.c
81676 --- linux-2.6.39.1/sound/pci/bt87x.c 2011-05-19 00:06:34.000000000 -0400
81677 +++ linux-2.6.39.1/sound/pci/bt87x.c 2011-05-22 19:36:35.000000000 -0400
81678 @@ -542,7 +542,7 @@ static snd_pcm_uframes_t snd_bt87x_point
81679 return (snd_pcm_uframes_t)bytes_to_frames(runtime, chip->current_line * chip->line_bytes);
81680 }
81681
81682 -static struct snd_pcm_ops snd_bt87x_pcm_ops = {
81683 +static const struct snd_pcm_ops snd_bt87x_pcm_ops = {
81684 .open = snd_bt87x_pcm_open,
81685 .close = snd_bt87x_close,
81686 .ioctl = snd_pcm_lib_ioctl,
81687 @@ -720,7 +720,7 @@ static int __devinit snd_bt87x_create(st
81688 {
81689 struct snd_bt87x *chip;
81690 int err;
81691 - static struct snd_device_ops ops = {
81692 + static const struct snd_device_ops ops = {
81693 .dev_free = snd_bt87x_dev_free
81694 };
81695
81696 diff -urNp linux-2.6.39.1/sound/pci/ca0106/ca0106_main.c linux-2.6.39.1/sound/pci/ca0106/ca0106_main.c
81697 --- linux-2.6.39.1/sound/pci/ca0106/ca0106_main.c 2011-05-19 00:06:34.000000000 -0400
81698 +++ linux-2.6.39.1/sound/pci/ca0106/ca0106_main.c 2011-05-22 19:36:35.000000000 -0400
81699 @@ -1103,7 +1103,7 @@ snd_ca0106_pcm_pointer_capture(struct sn
81700 }
81701
81702 /* operators */
81703 -static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
81704 +static const struct snd_pcm_ops snd_ca0106_playback_front_ops = {
81705 .open = snd_ca0106_pcm_open_playback_front,
81706 .close = snd_ca0106_pcm_close_playback,
81707 .ioctl = snd_pcm_lib_ioctl,
81708 @@ -1114,7 +1114,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81709 .pointer = snd_ca0106_pcm_pointer_playback,
81710 };
81711
81712 -static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
81713 +static const struct snd_pcm_ops snd_ca0106_capture_0_ops = {
81714 .open = snd_ca0106_pcm_open_0_capture,
81715 .close = snd_ca0106_pcm_close_capture,
81716 .ioctl = snd_pcm_lib_ioctl,
81717 @@ -1125,7 +1125,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81718 .pointer = snd_ca0106_pcm_pointer_capture,
81719 };
81720
81721 -static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
81722 +static const struct snd_pcm_ops snd_ca0106_capture_1_ops = {
81723 .open = snd_ca0106_pcm_open_1_capture,
81724 .close = snd_ca0106_pcm_close_capture,
81725 .ioctl = snd_pcm_lib_ioctl,
81726 @@ -1136,7 +1136,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81727 .pointer = snd_ca0106_pcm_pointer_capture,
81728 };
81729
81730 -static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
81731 +static const struct snd_pcm_ops snd_ca0106_capture_2_ops = {
81732 .open = snd_ca0106_pcm_open_2_capture,
81733 .close = snd_ca0106_pcm_close_capture,
81734 .ioctl = snd_pcm_lib_ioctl,
81735 @@ -1147,7 +1147,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81736 .pointer = snd_ca0106_pcm_pointer_capture,
81737 };
81738
81739 -static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
81740 +static const struct snd_pcm_ops snd_ca0106_capture_3_ops = {
81741 .open = snd_ca0106_pcm_open_3_capture,
81742 .close = snd_ca0106_pcm_close_capture,
81743 .ioctl = snd_pcm_lib_ioctl,
81744 @@ -1158,7 +1158,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81745 .pointer = snd_ca0106_pcm_pointer_capture,
81746 };
81747
81748 -static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
81749 +static const struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
81750 .open = snd_ca0106_pcm_open_playback_center_lfe,
81751 .close = snd_ca0106_pcm_close_playback,
81752 .ioctl = snd_pcm_lib_ioctl,
81753 @@ -1169,7 +1169,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81754 .pointer = snd_ca0106_pcm_pointer_playback,
81755 };
81756
81757 -static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
81758 +static const struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
81759 .open = snd_ca0106_pcm_open_playback_unknown,
81760 .close = snd_ca0106_pcm_close_playback,
81761 .ioctl = snd_pcm_lib_ioctl,
81762 @@ -1180,7 +1180,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81763 .pointer = snd_ca0106_pcm_pointer_playback,
81764 };
81765
81766 -static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
81767 +static const struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
81768 .open = snd_ca0106_pcm_open_playback_rear,
81769 .close = snd_ca0106_pcm_close_playback,
81770 .ioctl = snd_pcm_lib_ioctl,
81771 @@ -1223,7 +1223,7 @@ static int snd_ca0106_ac97(struct snd_ca
81772 struct snd_ac97_bus *pbus;
81773 struct snd_ac97_template ac97;
81774 int err;
81775 - static struct snd_ac97_bus_ops ops = {
81776 + static const struct snd_ac97_bus_ops ops = {
81777 .write = snd_ca0106_ac97_write,
81778 .read = snd_ca0106_ac97_read,
81779 };
81780 @@ -1629,7 +1629,7 @@ static int __devinit snd_ca0106_create(i
81781 struct snd_ca0106 *chip;
81782 struct snd_ca0106_details *c;
81783 int err;
81784 - static struct snd_device_ops ops = {
81785 + static const struct snd_device_ops ops = {
81786 .dev_free = snd_ca0106_dev_free,
81787 };
81788
81789 diff -urNp linux-2.6.39.1/sound/pci/ca0106/ca_midi.c linux-2.6.39.1/sound/pci/ca0106/ca_midi.c
81790 --- linux-2.6.39.1/sound/pci/ca0106/ca_midi.c 2011-05-19 00:06:34.000000000 -0400
81791 +++ linux-2.6.39.1/sound/pci/ca0106/ca_midi.c 2011-05-22 19:36:35.000000000 -0400
81792 @@ -255,15 +255,13 @@ static void ca_midi_output_trigger(struc
81793 }
81794 }
81795
81796 -static struct snd_rawmidi_ops ca_midi_output =
81797 -{
81798 +static const struct snd_rawmidi_ops ca_midi_output = {
81799 .open = ca_midi_output_open,
81800 .close = ca_midi_output_close,
81801 .trigger = ca_midi_output_trigger,
81802 };
81803
81804 -static struct snd_rawmidi_ops ca_midi_input =
81805 -{
81806 +static const struct snd_rawmidi_ops ca_midi_input = {
81807 .open = ca_midi_input_open,
81808 .close = ca_midi_input_close,
81809 .trigger = ca_midi_input_trigger,
81810 diff -urNp linux-2.6.39.1/sound/pci/cmipci.c linux-2.6.39.1/sound/pci/cmipci.c
81811 --- linux-2.6.39.1/sound/pci/cmipci.c 2011-05-19 00:06:34.000000000 -0400
81812 +++ linux-2.6.39.1/sound/pci/cmipci.c 2011-05-22 19:36:35.000000000 -0400
81813 @@ -1838,7 +1838,7 @@ static int snd_cmipci_capture_spdif_clos
81814 /*
81815 */
81816
81817 -static struct snd_pcm_ops snd_cmipci_playback_ops = {
81818 +static const struct snd_pcm_ops snd_cmipci_playback_ops = {
81819 .open = snd_cmipci_playback_open,
81820 .close = snd_cmipci_playback_close,
81821 .ioctl = snd_pcm_lib_ioctl,
81822 @@ -1849,7 +1849,7 @@ static struct snd_pcm_ops snd_cmipci_pla
81823 .pointer = snd_cmipci_playback_pointer,
81824 };
81825
81826 -static struct snd_pcm_ops snd_cmipci_capture_ops = {
81827 +static const struct snd_pcm_ops snd_cmipci_capture_ops = {
81828 .open = snd_cmipci_capture_open,
81829 .close = snd_cmipci_capture_close,
81830 .ioctl = snd_pcm_lib_ioctl,
81831 @@ -1860,7 +1860,7 @@ static struct snd_pcm_ops snd_cmipci_cap
81832 .pointer = snd_cmipci_capture_pointer,
81833 };
81834
81835 -static struct snd_pcm_ops snd_cmipci_playback2_ops = {
81836 +static const struct snd_pcm_ops snd_cmipci_playback2_ops = {
81837 .open = snd_cmipci_playback2_open,
81838 .close = snd_cmipci_playback2_close,
81839 .ioctl = snd_pcm_lib_ioctl,
81840 @@ -1871,7 +1871,7 @@ static struct snd_pcm_ops snd_cmipci_pla
81841 .pointer = snd_cmipci_capture_pointer, /* channel B */
81842 };
81843
81844 -static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
81845 +static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
81846 .open = snd_cmipci_playback_spdif_open,
81847 .close = snd_cmipci_playback_spdif_close,
81848 .ioctl = snd_pcm_lib_ioctl,
81849 @@ -1882,7 +1882,7 @@ static struct snd_pcm_ops snd_cmipci_pla
81850 .pointer = snd_cmipci_playback_pointer,
81851 };
81852
81853 -static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
81854 +static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
81855 .open = snd_cmipci_capture_spdif_open,
81856 .close = snd_cmipci_capture_spdif_close,
81857 .ioctl = snd_pcm_lib_ioctl,
81858 @@ -3011,7 +3011,7 @@ static int __devinit snd_cmipci_create(s
81859 {
81860 struct cmipci *cm;
81861 int err;
81862 - static struct snd_device_ops ops = {
81863 + static const struct snd_device_ops ops = {
81864 .dev_free = snd_cmipci_dev_free,
81865 };
81866 unsigned int val;
81867 diff -urNp linux-2.6.39.1/sound/pci/cs4281.c linux-2.6.39.1/sound/pci/cs4281.c
81868 --- linux-2.6.39.1/sound/pci/cs4281.c 2011-05-19 00:06:34.000000000 -0400
81869 +++ linux-2.6.39.1/sound/pci/cs4281.c 2011-05-22 19:36:35.000000000 -0400
81870 @@ -947,7 +947,7 @@ static int snd_cs4281_capture_close(stru
81871 return 0;
81872 }
81873
81874 -static struct snd_pcm_ops snd_cs4281_playback_ops = {
81875 +static const struct snd_pcm_ops snd_cs4281_playback_ops = {
81876 .open = snd_cs4281_playback_open,
81877 .close = snd_cs4281_playback_close,
81878 .ioctl = snd_pcm_lib_ioctl,
81879 @@ -958,7 +958,7 @@ static struct snd_pcm_ops snd_cs4281_pla
81880 .pointer = snd_cs4281_pointer,
81881 };
81882
81883 -static struct snd_pcm_ops snd_cs4281_capture_ops = {
81884 +static const struct snd_pcm_ops snd_cs4281_capture_ops = {
81885 .open = snd_cs4281_capture_open,
81886 .close = snd_cs4281_capture_close,
81887 .ioctl = snd_pcm_lib_ioctl,
81888 @@ -1098,7 +1098,7 @@ static int __devinit snd_cs4281_mixer(st
81889 struct snd_card *card = chip->card;
81890 struct snd_ac97_template ac97;
81891 int err;
81892 - static struct snd_ac97_bus_ops ops = {
81893 + static const struct snd_ac97_bus_ops ops = {
81894 .write = snd_cs4281_ac97_write,
81895 .read = snd_cs4281_ac97_read,
81896 };
81897 @@ -1343,7 +1343,7 @@ static int __devinit snd_cs4281_create(s
81898 struct cs4281 *chip;
81899 unsigned int tmp;
81900 int err;
81901 - static struct snd_device_ops ops = {
81902 + static const struct snd_device_ops ops = {
81903 .dev_free = snd_cs4281_dev_free,
81904 };
81905
81906 @@ -1765,15 +1765,13 @@ static void snd_cs4281_midi_output_trigg
81907 spin_unlock_irqrestore(&chip->reg_lock, flags);
81908 }
81909
81910 -static struct snd_rawmidi_ops snd_cs4281_midi_output =
81911 -{
81912 +static const struct snd_rawmidi_ops snd_cs4281_midi_output = {
81913 .open = snd_cs4281_midi_output_open,
81914 .close = snd_cs4281_midi_output_close,
81915 .trigger = snd_cs4281_midi_output_trigger,
81916 };
81917
81918 -static struct snd_rawmidi_ops snd_cs4281_midi_input =
81919 -{
81920 +static const struct snd_rawmidi_ops snd_cs4281_midi_input = {
81921 .open = snd_cs4281_midi_input_open,
81922 .close = snd_cs4281_midi_input_close,
81923 .trigger = snd_cs4281_midi_input_trigger,
81924 diff -urNp linux-2.6.39.1/sound/pci/cs46xx/cs46xx_lib.c linux-2.6.39.1/sound/pci/cs46xx/cs46xx_lib.c
81925 --- linux-2.6.39.1/sound/pci/cs46xx/cs46xx_lib.c 2011-05-19 00:06:34.000000000 -0400
81926 +++ linux-2.6.39.1/sound/pci/cs46xx/cs46xx_lib.c 2011-05-22 19:36:35.000000000 -0400
81927 @@ -3722,7 +3722,7 @@ int __devinit snd_cs46xx_create(struct s
81928 struct snd_cs46xx_region *region;
81929 struct cs_card_type *cp;
81930 u16 ss_card, ss_vendor;
81931 - static struct snd_device_ops ops = {
81932 + static const struct snd_device_ops ops = {
81933 .dev_free = snd_cs46xx_dev_free,
81934 };
81935
81936 diff -urNp linux-2.6.39.1/sound/pci/cs5530.c linux-2.6.39.1/sound/pci/cs5530.c
81937 --- linux-2.6.39.1/sound/pci/cs5530.c 2011-05-19 00:06:34.000000000 -0400
81938 +++ linux-2.6.39.1/sound/pci/cs5530.c 2011-05-22 19:36:35.000000000 -0400
81939 @@ -107,7 +107,7 @@ static int __devinit snd_cs5530_create(s
81940 void __iomem *mem;
81941 int err;
81942
81943 - static struct snd_device_ops ops = {
81944 + static const struct snd_device_ops ops = {
81945 .dev_free = snd_cs5530_dev_free,
81946 };
81947 *rchip = NULL;
81948 diff -urNp linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio.c linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio.c
81949 --- linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio.c 2011-05-19 00:06:34.000000000 -0400
81950 +++ linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio.c 2011-05-22 19:36:35.000000000 -0400
81951 @@ -150,7 +150,7 @@ static int __devinit snd_cs5535audio_mix
81952 struct snd_ac97_bus *pbus;
81953 struct snd_ac97_template ac97;
81954 int err;
81955 - static struct snd_ac97_bus_ops ops = {
81956 + static const struct snd_ac97_bus_ops ops = {
81957 .write = snd_cs5535audio_ac97_codec_write,
81958 .read = snd_cs5535audio_ac97_codec_read,
81959 };
81960 @@ -277,7 +277,7 @@ static int __devinit snd_cs5535audio_cre
81961 struct cs5535audio *cs5535au;
81962
81963 int err;
81964 - static struct snd_device_ops ops = {
81965 + static const struct snd_device_ops ops = {
81966 .dev_free = snd_cs5535audio_dev_free,
81967 };
81968
81969 diff -urNp linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio_pcm.c linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio_pcm.c
81970 --- linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio_pcm.c 2011-05-19 00:06:34.000000000 -0400
81971 +++ linux-2.6.39.1/sound/pci/cs5535audio/cs5535audio_pcm.c 2011-05-22 19:36:35.000000000 -0400
81972 @@ -380,7 +380,7 @@ static int snd_cs5535audio_capture_prepa
81973 substream->runtime->rate);
81974 }
81975
81976 -static struct snd_pcm_ops snd_cs5535audio_playback_ops = {
81977 +static const struct snd_pcm_ops snd_cs5535audio_playback_ops = {
81978 .open = snd_cs5535audio_playback_open,
81979 .close = snd_cs5535audio_playback_close,
81980 .ioctl = snd_pcm_lib_ioctl,
81981 @@ -391,7 +391,7 @@ static struct snd_pcm_ops snd_cs5535audi
81982 .pointer = snd_cs5535audio_pcm_pointer,
81983 };
81984
81985 -static struct snd_pcm_ops snd_cs5535audio_capture_ops = {
81986 +static const struct snd_pcm_ops snd_cs5535audio_capture_ops = {
81987 .open = snd_cs5535audio_capture_open,
81988 .close = snd_cs5535audio_capture_close,
81989 .ioctl = snd_pcm_lib_ioctl,
81990 diff -urNp linux-2.6.39.1/sound/pci/ctxfi/ctpcm.c linux-2.6.39.1/sound/pci/ctxfi/ctpcm.c
81991 --- linux-2.6.39.1/sound/pci/ctxfi/ctpcm.c 2011-05-19 00:06:34.000000000 -0400
81992 +++ linux-2.6.39.1/sound/pci/ctxfi/ctpcm.c 2011-05-22 19:36:35.000000000 -0400
81993 @@ -370,7 +370,7 @@ ct_pcm_capture_pointer(struct snd_pcm_su
81994 }
81995
81996 /* PCM operators for playback */
81997 -static struct snd_pcm_ops ct_pcm_playback_ops = {
81998 +static const struct snd_pcm_ops ct_pcm_playback_ops = {
81999 .open = ct_pcm_playback_open,
82000 .close = ct_pcm_playback_close,
82001 .ioctl = snd_pcm_lib_ioctl,
82002 @@ -383,7 +383,7 @@ static struct snd_pcm_ops ct_pcm_playbac
82003 };
82004
82005 /* PCM operators for capture */
82006 -static struct snd_pcm_ops ct_pcm_capture_ops = {
82007 +static const struct snd_pcm_ops ct_pcm_capture_ops = {
82008 .open = ct_pcm_capture_open,
82009 .close = ct_pcm_capture_close,
82010 .ioctl = snd_pcm_lib_ioctl,
82011 diff -urNp linux-2.6.39.1/sound/pci/echoaudio/echoaudio.c linux-2.6.39.1/sound/pci/echoaudio/echoaudio.c
82012 --- linux-2.6.39.1/sound/pci/echoaudio/echoaudio.c 2011-05-19 00:06:34.000000000 -0400
82013 +++ linux-2.6.39.1/sound/pci/echoaudio/echoaudio.c 2011-05-22 19:36:35.000000000 -0400
82014 @@ -831,7 +831,7 @@ static snd_pcm_uframes_t pcm_pointer(str
82015
82016
82017 /* pcm *_ops structures */
82018 -static struct snd_pcm_ops analog_playback_ops = {
82019 +static const struct snd_pcm_ops analog_playback_ops = {
82020 .open = pcm_analog_out_open,
82021 .close = pcm_close,
82022 .ioctl = snd_pcm_lib_ioctl,
82023 @@ -842,7 +842,7 @@ static struct snd_pcm_ops analog_playbac
82024 .pointer = pcm_pointer,
82025 .page = snd_pcm_sgbuf_ops_page,
82026 };
82027 -static struct snd_pcm_ops analog_capture_ops = {
82028 +static const struct snd_pcm_ops analog_capture_ops = {
82029 .open = pcm_analog_in_open,
82030 .close = pcm_close,
82031 .ioctl = snd_pcm_lib_ioctl,
82032 @@ -855,7 +855,7 @@ static struct snd_pcm_ops analog_capture
82033 };
82034 #ifdef ECHOCARD_HAS_DIGITAL_IO
82035 #ifndef ECHOCARD_HAS_VMIXER
82036 -static struct snd_pcm_ops digital_playback_ops = {
82037 +static const struct snd_pcm_ops digital_playback_ops = {
82038 .open = pcm_digital_out_open,
82039 .close = pcm_close,
82040 .ioctl = snd_pcm_lib_ioctl,
82041 @@ -867,7 +867,7 @@ static struct snd_pcm_ops digital_playba
82042 .page = snd_pcm_sgbuf_ops_page,
82043 };
82044 #endif /* !ECHOCARD_HAS_VMIXER */
82045 -static struct snd_pcm_ops digital_capture_ops = {
82046 +static const struct snd_pcm_ops digital_capture_ops = {
82047 .open = pcm_digital_in_open,
82048 .close = pcm_close,
82049 .ioctl = snd_pcm_lib_ioctl,
82050 @@ -1945,7 +1945,7 @@ static __devinit int snd_echo_create(str
82051 struct echoaudio *chip;
82052 int err;
82053 size_t sz;
82054 - static struct snd_device_ops ops = {
82055 + static const struct snd_device_ops ops = {
82056 .dev_free = snd_echo_dev_free,
82057 };
82058
82059 diff -urNp linux-2.6.39.1/sound/pci/echoaudio/midi.c linux-2.6.39.1/sound/pci/echoaudio/midi.c
82060 --- linux-2.6.39.1/sound/pci/echoaudio/midi.c 2011-05-19 00:06:34.000000000 -0400
82061 +++ linux-2.6.39.1/sound/pci/echoaudio/midi.c 2011-05-22 19:36:35.000000000 -0400
82062 @@ -292,13 +292,13 @@ static int snd_echo_midi_output_close(st
82063
82064
82065
82066 -static struct snd_rawmidi_ops snd_echo_midi_input = {
82067 +static const struct snd_rawmidi_ops snd_echo_midi_input = {
82068 .open = snd_echo_midi_input_open,
82069 .close = snd_echo_midi_input_close,
82070 .trigger = snd_echo_midi_input_trigger,
82071 };
82072
82073 -static struct snd_rawmidi_ops snd_echo_midi_output = {
82074 +static const struct snd_rawmidi_ops snd_echo_midi_output = {
82075 .open = snd_echo_midi_output_open,
82076 .close = snd_echo_midi_output_close,
82077 .trigger = snd_echo_midi_output_trigger,
82078 diff -urNp linux-2.6.39.1/sound/pci/emu10k1/emu10k1_main.c linux-2.6.39.1/sound/pci/emu10k1/emu10k1_main.c
82079 --- linux-2.6.39.1/sound/pci/emu10k1/emu10k1_main.c 2011-05-19 00:06:34.000000000 -0400
82080 +++ linux-2.6.39.1/sound/pci/emu10k1/emu10k1_main.c 2011-05-22 19:36:35.000000000 -0400
82081 @@ -1722,7 +1722,7 @@ int __devinit snd_emu10k1_create(struct
82082 int is_audigy;
82083 unsigned int silent_page;
82084 const struct snd_emu_chip_details *c;
82085 - static struct snd_device_ops ops = {
82086 + static const struct snd_device_ops ops = {
82087 .dev_free = snd_emu10k1_dev_free,
82088 };
82089
82090 diff -urNp linux-2.6.39.1/sound/pci/emu10k1/emu10k1x.c linux-2.6.39.1/sound/pci/emu10k1/emu10k1x.c
82091 --- linux-2.6.39.1/sound/pci/emu10k1/emu10k1x.c 2011-05-19 00:06:34.000000000 -0400
82092 +++ linux-2.6.39.1/sound/pci/emu10k1/emu10k1x.c 2011-05-22 19:36:35.000000000 -0400
82093 @@ -543,7 +543,7 @@ snd_emu10k1x_pcm_pointer(struct snd_pcm_
82094 }
82095
82096 /* operators */
82097 -static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
82098 +static const struct snd_pcm_ops snd_emu10k1x_playback_ops = {
82099 .open = snd_emu10k1x_playback_open,
82100 .close = snd_emu10k1x_playback_close,
82101 .ioctl = snd_pcm_lib_ioctl,
82102 @@ -689,7 +689,7 @@ snd_emu10k1x_pcm_pointer_capture(struct
82103 return ptr;
82104 }
82105
82106 -static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
82107 +static const struct snd_pcm_ops snd_emu10k1x_capture_ops = {
82108 .open = snd_emu10k1x_pcm_open_capture,
82109 .close = snd_emu10k1x_pcm_close_capture,
82110 .ioctl = snd_pcm_lib_ioctl,
82111 @@ -731,7 +731,7 @@ static int snd_emu10k1x_ac97(struct emu1
82112 struct snd_ac97_bus *pbus;
82113 struct snd_ac97_template ac97;
82114 int err;
82115 - static struct snd_ac97_bus_ops ops = {
82116 + static const struct snd_ac97_bus_ops ops = {
82117 .write = snd_emu10k1x_ac97_write,
82118 .read = snd_emu10k1x_ac97_read,
82119 };
82120 @@ -888,7 +888,7 @@ static int __devinit snd_emu10k1x_create
82121 struct emu10k1x *chip;
82122 int err;
82123 int ch;
82124 - static struct snd_device_ops ops = {
82125 + static const struct snd_device_ops ops = {
82126 .dev_free = snd_emu10k1x_dev_free,
82127 };
82128
82129 @@ -1465,15 +1465,13 @@ static void snd_emu10k1x_midi_output_tri
82130
82131 */
82132
82133 -static struct snd_rawmidi_ops snd_emu10k1x_midi_output =
82134 -{
82135 +static const struct snd_rawmidi_ops snd_emu10k1x_midi_output = {
82136 .open = snd_emu10k1x_midi_output_open,
82137 .close = snd_emu10k1x_midi_output_close,
82138 .trigger = snd_emu10k1x_midi_output_trigger,
82139 };
82140
82141 -static struct snd_rawmidi_ops snd_emu10k1x_midi_input =
82142 -{
82143 +static const struct snd_rawmidi_ops snd_emu10k1x_midi_input = {
82144 .open = snd_emu10k1x_midi_input_open,
82145 .close = snd_emu10k1x_midi_input_close,
82146 .trigger = snd_emu10k1x_midi_input_trigger,
82147 diff -urNp linux-2.6.39.1/sound/pci/emu10k1/p16v.c linux-2.6.39.1/sound/pci/emu10k1/p16v.c
82148 --- linux-2.6.39.1/sound/pci/emu10k1/p16v.c 2011-05-19 00:06:34.000000000 -0400
82149 +++ linux-2.6.39.1/sound/pci/emu10k1/p16v.c 2011-05-22 19:36:35.000000000 -0400
82150 @@ -601,7 +601,7 @@ snd_p16v_pcm_pointer_capture(struct snd_
82151 }
82152
82153 /* operators */
82154 -static struct snd_pcm_ops snd_p16v_playback_front_ops = {
82155 +static const struct snd_pcm_ops snd_p16v_playback_front_ops = {
82156 .open = snd_p16v_pcm_open_playback_front,
82157 .close = snd_p16v_pcm_close_playback,
82158 .ioctl = snd_pcm_lib_ioctl,
82159 @@ -612,7 +612,7 @@ static struct snd_pcm_ops snd_p16v_playb
82160 .pointer = snd_p16v_pcm_pointer_playback,
82161 };
82162
82163 -static struct snd_pcm_ops snd_p16v_capture_ops = {
82164 +static const struct snd_pcm_ops snd_p16v_capture_ops = {
82165 .open = snd_p16v_pcm_open_capture,
82166 .close = snd_p16v_pcm_close_capture,
82167 .ioctl = snd_pcm_lib_ioctl,
82168 diff -urNp linux-2.6.39.1/sound/pci/ens1370.c linux-2.6.39.1/sound/pci/ens1370.c
82169 --- linux-2.6.39.1/sound/pci/ens1370.c 2011-05-19 00:06:34.000000000 -0400
82170 +++ linux-2.6.39.1/sound/pci/ens1370.c 2011-05-22 19:36:35.000000000 -0400
82171 @@ -1225,7 +1225,7 @@ static int snd_ensoniq_capture_close(str
82172 return 0;
82173 }
82174
82175 -static struct snd_pcm_ops snd_ensoniq_playback1_ops = {
82176 +static const struct snd_pcm_ops snd_ensoniq_playback1_ops = {
82177 .open = snd_ensoniq_playback1_open,
82178 .close = snd_ensoniq_playback1_close,
82179 .ioctl = snd_pcm_lib_ioctl,
82180 @@ -1236,7 +1236,7 @@ static struct snd_pcm_ops snd_ensoniq_pl
82181 .pointer = snd_ensoniq_playback1_pointer,
82182 };
82183
82184 -static struct snd_pcm_ops snd_ensoniq_playback2_ops = {
82185 +static const struct snd_pcm_ops snd_ensoniq_playback2_ops = {
82186 .open = snd_ensoniq_playback2_open,
82187 .close = snd_ensoniq_playback2_close,
82188 .ioctl = snd_pcm_lib_ioctl,
82189 @@ -1247,7 +1247,7 @@ static struct snd_pcm_ops snd_ensoniq_pl
82190 .pointer = snd_ensoniq_playback2_pointer,
82191 };
82192
82193 -static struct snd_pcm_ops snd_ensoniq_capture_ops = {
82194 +static const struct snd_pcm_ops snd_ensoniq_capture_ops = {
82195 .open = snd_ensoniq_capture_open,
82196 .close = snd_ensoniq_capture_close,
82197 .ioctl = snd_pcm_lib_ioctl,
82198 @@ -1633,7 +1633,7 @@ static int __devinit snd_ensoniq_1371_mi
82199 struct snd_ac97_bus *pbus;
82200 struct snd_ac97_template ac97;
82201 int err;
82202 - static struct snd_ac97_bus_ops ops = {
82203 + static const struct snd_ac97_bus_ops ops = {
82204 .write = snd_es1371_codec_write,
82205 .read = snd_es1371_codec_read,
82206 .wait = snd_es1371_codec_wait,
82207 @@ -2096,7 +2096,7 @@ static int __devinit snd_ensoniq_create(
82208 {
82209 struct ensoniq *ensoniq;
82210 int err;
82211 - static struct snd_device_ops ops = {
82212 + static const struct snd_device_ops ops = {
82213 .dev_free = snd_ensoniq_dev_free,
82214 };
82215
82216 @@ -2331,15 +2331,13 @@ static void snd_ensoniq_midi_output_trig
82217 spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
82218 }
82219
82220 -static struct snd_rawmidi_ops snd_ensoniq_midi_output =
82221 -{
82222 +static const struct snd_rawmidi_ops snd_ensoniq_midi_output = {
82223 .open = snd_ensoniq_midi_output_open,
82224 .close = snd_ensoniq_midi_output_close,
82225 .trigger = snd_ensoniq_midi_output_trigger,
82226 };
82227
82228 -static struct snd_rawmidi_ops snd_ensoniq_midi_input =
82229 -{
82230 +static const struct snd_rawmidi_ops snd_ensoniq_midi_input = {
82231 .open = snd_ensoniq_midi_input_open,
82232 .close = snd_ensoniq_midi_input_close,
82233 .trigger = snd_ensoniq_midi_input_trigger,
82234 diff -urNp linux-2.6.39.1/sound/pci/es1938.c linux-2.6.39.1/sound/pci/es1938.c
82235 --- linux-2.6.39.1/sound/pci/es1938.c 2011-05-19 00:06:34.000000000 -0400
82236 +++ linux-2.6.39.1/sound/pci/es1938.c 2011-05-22 19:36:35.000000000 -0400
82237 @@ -1004,7 +1004,7 @@ static int snd_es1938_playback_close(str
82238 return 0;
82239 }
82240
82241 -static struct snd_pcm_ops snd_es1938_playback_ops = {
82242 +static const struct snd_pcm_ops snd_es1938_playback_ops = {
82243 .open = snd_es1938_playback_open,
82244 .close = snd_es1938_playback_close,
82245 .ioctl = snd_pcm_lib_ioctl,
82246 @@ -1015,7 +1015,7 @@ static struct snd_pcm_ops snd_es1938_pla
82247 .pointer = snd_es1938_playback_pointer,
82248 };
82249
82250 -static struct snd_pcm_ops snd_es1938_capture_ops = {
82251 +static const struct snd_pcm_ops snd_es1938_capture_ops = {
82252 .open = snd_es1938_capture_open,
82253 .close = snd_es1938_capture_close,
82254 .ioctl = snd_pcm_lib_ioctl,
82255 @@ -1598,7 +1598,7 @@ static int __devinit snd_es1938_create(s
82256 {
82257 struct es1938 *chip;
82258 int err;
82259 - static struct snd_device_ops ops = {
82260 + static const struct snd_device_ops ops = {
82261 .dev_free = snd_es1938_dev_free,
82262 };
82263
82264 diff -urNp linux-2.6.39.1/sound/pci/es1968.c linux-2.6.39.1/sound/pci/es1968.c
82265 --- linux-2.6.39.1/sound/pci/es1968.c 2011-05-19 00:06:34.000000000 -0400
82266 +++ linux-2.6.39.1/sound/pci/es1968.c 2011-05-22 19:36:35.000000000 -0400
82267 @@ -1682,7 +1682,7 @@ static int snd_es1968_capture_close(stru
82268 return 0;
82269 }
82270
82271 -static struct snd_pcm_ops snd_es1968_playback_ops = {
82272 +static const struct snd_pcm_ops snd_es1968_playback_ops = {
82273 .open = snd_es1968_playback_open,
82274 .close = snd_es1968_playback_close,
82275 .ioctl = snd_pcm_lib_ioctl,
82276 @@ -1693,7 +1693,7 @@ static struct snd_pcm_ops snd_es1968_pla
82277 .pointer = snd_es1968_pcm_pointer,
82278 };
82279
82280 -static struct snd_pcm_ops snd_es1968_capture_ops = {
82281 +static const struct snd_pcm_ops snd_es1968_capture_ops = {
82282 .open = snd_es1968_capture_open,
82283 .close = snd_es1968_capture_close,
82284 .ioctl = snd_pcm_lib_ioctl,
82285 @@ -2053,7 +2053,7 @@ snd_es1968_mixer(struct es1968 *chip)
82286 struct snd_ctl_elem_id elem_id;
82287 #endif
82288 int err;
82289 - static struct snd_ac97_bus_ops ops = {
82290 + static const struct snd_ac97_bus_ops ops = {
82291 .write = snd_es1968_ac97_write,
82292 .read = snd_es1968_ac97_read,
82293 };
82294 @@ -2627,7 +2627,7 @@ static int __devinit snd_es1968_create(s
82295 int do_pm,
82296 struct es1968 **chip_ret)
82297 {
82298 - static struct snd_device_ops ops = {
82299 + static const struct snd_device_ops ops = {
82300 .dev_free = snd_es1968_dev_free,
82301 };
82302 struct es1968 *chip;
82303 diff -urNp linux-2.6.39.1/sound/pci/fm801.c linux-2.6.39.1/sound/pci/fm801.c
82304 --- linux-2.6.39.1/sound/pci/fm801.c 2011-05-19 00:06:34.000000000 -0400
82305 +++ linux-2.6.39.1/sound/pci/fm801.c 2011-05-22 19:36:35.000000000 -0400
82306 @@ -662,7 +662,7 @@ static int snd_fm801_capture_close(struc
82307 return 0;
82308 }
82309
82310 -static struct snd_pcm_ops snd_fm801_playback_ops = {
82311 +static const struct snd_pcm_ops snd_fm801_playback_ops = {
82312 .open = snd_fm801_playback_open,
82313 .close = snd_fm801_playback_close,
82314 .ioctl = snd_pcm_lib_ioctl,
82315 @@ -673,7 +673,7 @@ static struct snd_pcm_ops snd_fm801_play
82316 .pointer = snd_fm801_playback_pointer,
82317 };
82318
82319 -static struct snd_pcm_ops snd_fm801_capture_ops = {
82320 +static const struct snd_pcm_ops snd_fm801_capture_ops = {
82321 .open = snd_fm801_capture_open,
82322 .close = snd_fm801_capture_close,
82323 .ioctl = snd_pcm_lib_ioctl,
82324 @@ -1236,7 +1236,7 @@ static int __devinit snd_fm801_mixer(str
82325 struct snd_ac97_template ac97;
82326 unsigned int i;
82327 int err;
82328 - static struct snd_ac97_bus_ops ops = {
82329 + static const struct snd_ac97_bus_ops ops = {
82330 .write = snd_fm801_codec_write,
82331 .read = snd_fm801_codec_read,
82332 };
82333 @@ -1396,7 +1396,7 @@ static int __devinit snd_fm801_create(st
82334 {
82335 struct fm801 *chip;
82336 int err;
82337 - static struct snd_device_ops ops = {
82338 + static const struct snd_device_ops ops = {
82339 .dev_free = snd_fm801_dev_free,
82340 };
82341
82342 diff -urNp linux-2.6.39.1/sound/pci/hda/hda_generic.c linux-2.6.39.1/sound/pci/hda/hda_generic.c
82343 --- linux-2.6.39.1/sound/pci/hda/hda_generic.c 2011-05-19 00:06:34.000000000 -0400
82344 +++ linux-2.6.39.1/sound/pci/hda/hda_generic.c 2011-05-22 19:36:35.000000000 -0400
82345 @@ -1038,7 +1038,7 @@ static int generic_check_power_status(st
82346
82347 /*
82348 */
82349 -static struct hda_codec_ops generic_patch_ops = {
82350 +static const struct hda_codec_ops generic_patch_ops = {
82351 .build_controls = build_generic_controls,
82352 .build_pcms = build_generic_pcms,
82353 .free = snd_hda_generic_free,
82354 diff -urNp linux-2.6.39.1/sound/pci/hda/hda_intel.c linux-2.6.39.1/sound/pci/hda/hda_intel.c
82355 --- linux-2.6.39.1/sound/pci/hda/hda_intel.c 2011-06-03 00:04:14.000000000 -0400
82356 +++ linux-2.6.39.1/sound/pci/hda/hda_intel.c 2011-06-03 00:32:08.000000000 -0400
82357 @@ -2459,7 +2459,7 @@ static int __devinit azx_create(struct s
82358 struct azx *chip;
82359 int i, err;
82360 unsigned short gcap;
82361 - static struct snd_device_ops ops = {
82362 + static const struct snd_device_ops ops = {
82363 .dev_free = azx_dev_free,
82364 };
82365
82366 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_ca0110.c linux-2.6.39.1/sound/pci/hda/patch_ca0110.c
82367 --- linux-2.6.39.1/sound/pci/hda/patch_ca0110.c 2011-05-19 00:06:34.000000000 -0400
82368 +++ linux-2.6.39.1/sound/pci/hda/patch_ca0110.c 2011-05-22 19:36:35.000000000 -0400
82369 @@ -389,7 +389,7 @@ static void ca0110_free(struct hda_codec
82370 kfree(codec->spec);
82371 }
82372
82373 -static struct hda_codec_ops ca0110_patch_ops = {
82374 +static const struct hda_codec_ops ca0110_patch_ops = {
82375 .build_controls = ca0110_build_controls,
82376 .build_pcms = ca0110_build_pcms,
82377 .init = ca0110_init,
82378 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_cirrus.c linux-2.6.39.1/sound/pci/hda/patch_cirrus.c
82379 --- linux-2.6.39.1/sound/pci/hda/patch_cirrus.c 2011-05-19 00:06:34.000000000 -0400
82380 +++ linux-2.6.39.1/sound/pci/hda/patch_cirrus.c 2011-05-22 19:36:35.000000000 -0400
82381 @@ -1126,7 +1126,7 @@ static void cs_unsol_event(struct hda_co
82382 }
82383 }
82384
82385 -static struct hda_codec_ops cs_patch_ops = {
82386 +static const struct hda_codec_ops cs_patch_ops = {
82387 .build_controls = cs_build_controls,
82388 .build_pcms = cs_build_pcms,
82389 .init = cs_init,
82390 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_cmedia.c linux-2.6.39.1/sound/pci/hda/patch_cmedia.c
82391 --- linux-2.6.39.1/sound/pci/hda/patch_cmedia.c 2011-05-19 00:06:34.000000000 -0400
82392 +++ linux-2.6.39.1/sound/pci/hda/patch_cmedia.c 2011-05-22 19:36:35.000000000 -0400
82393 @@ -624,7 +624,7 @@ static struct snd_pci_quirk cmi9880_cfg_
82394 {} /* terminator */
82395 };
82396
82397 -static struct hda_codec_ops cmi9880_patch_ops = {
82398 +static const struct hda_codec_ops cmi9880_patch_ops = {
82399 .build_controls = cmi9880_build_controls,
82400 .build_pcms = cmi9880_build_pcms,
82401 .init = cmi9880_init,
82402 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_conexant.c linux-2.6.39.1/sound/pci/hda/patch_conexant.c
82403 --- linux-2.6.39.1/sound/pci/hda/patch_conexant.c 2011-06-03 00:04:14.000000000 -0400
82404 +++ linux-2.6.39.1/sound/pci/hda/patch_conexant.c 2011-06-03 00:32:08.000000000 -0400
82405 @@ -546,7 +546,7 @@ static int conexant_suspend(struct hda_c
82406 }
82407 #endif
82408
82409 -static struct hda_codec_ops conexant_patch_ops = {
82410 +static const struct hda_codec_ops conexant_patch_ops = {
82411 .build_controls = conexant_build_controls,
82412 .build_pcms = conexant_build_pcms,
82413 .init = conexant_init,
82414 @@ -3792,7 +3792,7 @@ static int cx_auto_build_controls(struct
82415 return conexant_build_controls(codec);
82416 }
82417
82418 -static struct hda_codec_ops cx_auto_patch_ops = {
82419 +static const struct hda_codec_ops cx_auto_patch_ops = {
82420 .build_controls = cx_auto_build_controls,
82421 .build_pcms = conexant_build_pcms,
82422 .init = cx_auto_init,
82423 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_hdmi.c linux-2.6.39.1/sound/pci/hda/patch_hdmi.c
82424 --- linux-2.6.39.1/sound/pci/hda/patch_hdmi.c 2011-05-19 00:06:34.000000000 -0400
82425 +++ linux-2.6.39.1/sound/pci/hda/patch_hdmi.c 2011-05-22 19:36:35.000000000 -0400
82426 @@ -1124,7 +1124,7 @@ static void generic_hdmi_free(struct hda
82427 kfree(spec);
82428 }
82429
82430 -static struct hda_codec_ops generic_hdmi_patch_ops = {
82431 +static const struct hda_codec_ops generic_hdmi_patch_ops = {
82432 .init = generic_hdmi_init,
82433 .free = generic_hdmi_free,
82434 .build_pcms = generic_hdmi_build_pcms,
82435 @@ -1465,14 +1465,14 @@ static struct hda_pcm_stream nvhdmi_pcm_
82436 },
82437 };
82438
82439 -static struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
82440 +static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
82441 .build_controls = generic_hdmi_build_controls,
82442 .build_pcms = generic_hdmi_build_pcms,
82443 .init = nvhdmi_7x_init,
82444 .free = generic_hdmi_free,
82445 };
82446
82447 -static struct hda_codec_ops nvhdmi_patch_ops_2ch = {
82448 +static const struct hda_codec_ops nvhdmi_patch_ops_2ch = {
82449 .build_controls = generic_hdmi_build_controls,
82450 .build_pcms = generic_hdmi_build_pcms,
82451 .init = nvhdmi_7x_init,
82452 @@ -1599,7 +1599,7 @@ static int atihdmi_init(struct hda_codec
82453 return 0;
82454 }
82455
82456 -static struct hda_codec_ops atihdmi_patch_ops = {
82457 +static const struct hda_codec_ops atihdmi_patch_ops = {
82458 .build_controls = generic_hdmi_build_controls,
82459 .build_pcms = generic_hdmi_build_pcms,
82460 .init = atihdmi_init,
82461 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_realtek.c linux-2.6.39.1/sound/pci/hda/patch_realtek.c
82462 --- linux-2.6.39.1/sound/pci/hda/patch_realtek.c 2011-05-19 00:06:34.000000000 -0400
82463 +++ linux-2.6.39.1/sound/pci/hda/patch_realtek.c 2011-05-22 19:36:35.000000000 -0400
82464 @@ -4273,7 +4273,7 @@ static int alc_resume(struct hda_codec *
82465
82466 /*
82467 */
82468 -static struct hda_codec_ops alc_patch_ops = {
82469 +static const struct hda_codec_ops alc_patch_ops = {
82470 .build_controls = alc_build_controls,
82471 .build_pcms = alc_build_pcms,
82472 .init = alc_init,
82473 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_si3054.c linux-2.6.39.1/sound/pci/hda/patch_si3054.c
82474 --- linux-2.6.39.1/sound/pci/hda/patch_si3054.c 2011-05-19 00:06:34.000000000 -0400
82475 +++ linux-2.6.39.1/sound/pci/hda/patch_si3054.c 2011-05-22 19:36:35.000000000 -0400
82476 @@ -263,7 +263,7 @@ static void si3054_free(struct hda_codec
82477 /*
82478 */
82479
82480 -static struct hda_codec_ops si3054_patch_ops = {
82481 +static const struct hda_codec_ops si3054_patch_ops = {
82482 .build_controls = si3054_build_controls,
82483 .build_pcms = si3054_build_pcms,
82484 .init = si3054_init,
82485 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_sigmatel.c linux-2.6.39.1/sound/pci/hda/patch_sigmatel.c
82486 --- linux-2.6.39.1/sound/pci/hda/patch_sigmatel.c 2011-06-03 00:04:14.000000000 -0400
82487 +++ linux-2.6.39.1/sound/pci/hda/patch_sigmatel.c 2011-06-03 00:32:08.000000000 -0400
82488 @@ -4968,7 +4968,7 @@ static int stac92xx_suspend(struct hda_c
82489 }
82490 #endif
82491
82492 -static struct hda_codec_ops stac92xx_patch_ops = {
82493 +static const struct hda_codec_ops stac92xx_patch_ops = {
82494 .build_controls = stac92xx_build_controls,
82495 .build_pcms = stac92xx_build_pcms,
82496 .init = stac92xx_init,
82497 diff -urNp linux-2.6.39.1/sound/pci/hda/patch_via.c linux-2.6.39.1/sound/pci/hda/patch_via.c
82498 --- linux-2.6.39.1/sound/pci/hda/patch_via.c 2011-05-19 00:06:34.000000000 -0400
82499 +++ linux-2.6.39.1/sound/pci/hda/patch_via.c 2011-05-22 19:36:35.000000000 -0400
82500 @@ -2254,7 +2254,7 @@ static int via_check_power_status(struct
82501
82502 /*
82503 */
82504 -static struct hda_codec_ops via_patch_ops = {
82505 +static const struct hda_codec_ops via_patch_ops = {
82506 .build_controls = via_build_controls,
82507 .build_pcms = via_build_pcms,
82508 .init = via_init,
82509 diff -urNp linux-2.6.39.1/sound/pci/ice1712/ice1712.c linux-2.6.39.1/sound/pci/ice1712/ice1712.c
82510 --- linux-2.6.39.1/sound/pci/ice1712/ice1712.c 2011-05-19 00:06:34.000000000 -0400
82511 +++ linux-2.6.39.1/sound/pci/ice1712/ice1712.c 2011-05-22 19:36:35.000000000 -0400
82512 @@ -2541,7 +2541,7 @@ static int __devinit snd_ice1712_create(
82513 {
82514 struct snd_ice1712 *ice;
82515 int err;
82516 - static struct snd_device_ops ops = {
82517 + static const struct snd_device_ops ops = {
82518 .dev_free = snd_ice1712_dev_free,
82519 };
82520
82521 diff -urNp linux-2.6.39.1/sound/pci/ice1712/ice1724.c linux-2.6.39.1/sound/pci/ice1712/ice1724.c
82522 --- linux-2.6.39.1/sound/pci/ice1712/ice1724.c 2011-05-19 00:06:34.000000000 -0400
82523 +++ linux-2.6.39.1/sound/pci/ice1712/ice1724.c 2011-05-22 19:36:35.000000000 -0400
82524 @@ -367,7 +367,7 @@ static void vt1724_midi_output_drain(str
82525 } while (time_after(timeout, jiffies));
82526 }
82527
82528 -static struct snd_rawmidi_ops vt1724_midi_output_ops = {
82529 +static const struct snd_rawmidi_ops vt1724_midi_output_ops = {
82530 .open = vt1724_midi_output_open,
82531 .close = vt1724_midi_output_close,
82532 .trigger = vt1724_midi_output_trigger,
82533 @@ -402,7 +402,7 @@ static void vt1724_midi_input_trigger(st
82534 spin_unlock_irqrestore(&ice->reg_lock, flags);
82535 }
82536
82537 -static struct snd_rawmidi_ops vt1724_midi_input_ops = {
82538 +static const struct snd_rawmidi_ops vt1724_midi_input_ops = {
82539 .open = vt1724_midi_input_open,
82540 .close = vt1724_midi_input_close,
82541 .trigger = vt1724_midi_input_trigger,
82542 @@ -2463,7 +2463,7 @@ static int __devinit snd_vt1724_create(s
82543 {
82544 struct snd_ice1712 *ice;
82545 int err;
82546 - static struct snd_device_ops ops = {
82547 + static const struct snd_device_ops ops = {
82548 .dev_free = snd_vt1724_dev_free,
82549 };
82550
82551 diff -urNp linux-2.6.39.1/sound/pci/intel8x0.c linux-2.6.39.1/sound/pci/intel8x0.c
82552 --- linux-2.6.39.1/sound/pci/intel8x0.c 2011-05-19 00:06:34.000000000 -0400
82553 +++ linux-2.6.39.1/sound/pci/intel8x0.c 2011-05-22 19:36:35.000000000 -0400
82554 @@ -2152,12 +2152,12 @@ static int __devinit snd_intel8x0_mixer(
82555 int err;
82556 unsigned int i, codecs;
82557 unsigned int glob_sta = 0;
82558 - struct snd_ac97_bus_ops *ops;
82559 - static struct snd_ac97_bus_ops standard_bus_ops = {
82560 + const struct snd_ac97_bus_ops *ops;
82561 + static const struct snd_ac97_bus_ops standard_bus_ops = {
82562 .write = snd_intel8x0_codec_write,
82563 .read = snd_intel8x0_codec_read,
82564 };
82565 - static struct snd_ac97_bus_ops ali_bus_ops = {
82566 + static const struct snd_ac97_bus_ops ali_bus_ops = {
82567 .write = snd_intel8x0_ali_codec_write,
82568 .read = snd_intel8x0_ali_codec_read,
82569 };
82570 @@ -2921,7 +2921,7 @@ static int __devinit snd_intel8x0_create
82571 unsigned int i;
82572 unsigned int int_sta_masks;
82573 struct ichdev *ichdev;
82574 - static struct snd_device_ops ops = {
82575 + static const struct snd_device_ops ops = {
82576 .dev_free = snd_intel8x0_dev_free,
82577 };
82578
82579 diff -urNp linux-2.6.39.1/sound/pci/intel8x0m.c linux-2.6.39.1/sound/pci/intel8x0m.c
82580 --- linux-2.6.39.1/sound/pci/intel8x0m.c 2011-05-19 00:06:34.000000000 -0400
82581 +++ linux-2.6.39.1/sound/pci/intel8x0m.c 2011-05-22 19:36:35.000000000 -0400
82582 @@ -826,7 +826,7 @@ static int __devinit snd_intel8x0m_mixer
82583 struct snd_ac97 *x97;
82584 int err;
82585 unsigned int glob_sta = 0;
82586 - static struct snd_ac97_bus_ops ops = {
82587 + static const struct snd_ac97_bus_ops ops = {
82588 .write = snd_intel8x0m_codec_write,
82589 .read = snd_intel8x0m_codec_read,
82590 };
82591 @@ -1116,7 +1116,7 @@ static int __devinit snd_intel8x0m_creat
82592 unsigned int i;
82593 unsigned int int_sta_masks;
82594 struct ichdev *ichdev;
82595 - static struct snd_device_ops ops = {
82596 + static const struct snd_device_ops ops = {
82597 .dev_free = snd_intel8x0m_dev_free,
82598 };
82599 static struct ich_reg_info intel_regs[2] = {
82600 @@ -1265,7 +1265,7 @@ static struct shortname_table {
82601 { 0x5455, "ALi M5455" },
82602 { 0x746d, "AMD AMD8111" },
82603 #endif
82604 - { 0 },
82605 + { 0, },
82606 };
82607
82608 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
82609 diff -urNp linux-2.6.39.1/sound/pci/korg1212/korg1212.c linux-2.6.39.1/sound/pci/korg1212/korg1212.c
82610 --- linux-2.6.39.1/sound/pci/korg1212/korg1212.c 2011-05-19 00:06:34.000000000 -0400
82611 +++ linux-2.6.39.1/sound/pci/korg1212/korg1212.c 2011-05-22 19:36:35.000000000 -0400
82612 @@ -1682,7 +1682,7 @@ static int snd_korg1212_capture_copy(str
82613 return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2);
82614 }
82615
82616 -static struct snd_pcm_ops snd_korg1212_playback_ops = {
82617 +static const struct snd_pcm_ops snd_korg1212_playback_ops = {
82618 .open = snd_korg1212_playback_open,
82619 .close = snd_korg1212_playback_close,
82620 .ioctl = snd_korg1212_ioctl,
82621 @@ -1694,7 +1694,7 @@ static struct snd_pcm_ops snd_korg1212_p
82622 .silence = snd_korg1212_playback_silence,
82623 };
82624
82625 -static struct snd_pcm_ops snd_korg1212_capture_ops = {
82626 +static const struct snd_pcm_ops snd_korg1212_capture_ops = {
82627 .open = snd_korg1212_capture_open,
82628 .close = snd_korg1212_capture_close,
82629 .ioctl = snd_korg1212_ioctl,
82630 @@ -2164,7 +2164,7 @@ static int __devinit snd_korg1212_create
82631 struct snd_korg1212 * korg1212;
82632 const struct firmware *dsp_code;
82633
82634 - static struct snd_device_ops ops = {
82635 + static const struct snd_device_ops ops = {
82636 .dev_free = snd_korg1212_dev_free,
82637 };
82638
82639 diff -urNp linux-2.6.39.1/sound/pci/maestro3.c linux-2.6.39.1/sound/pci/maestro3.c
82640 --- linux-2.6.39.1/sound/pci/maestro3.c 2011-05-19 00:06:34.000000000 -0400
82641 +++ linux-2.6.39.1/sound/pci/maestro3.c 2011-05-22 19:36:35.000000000 -0400
82642 @@ -1926,7 +1926,7 @@ snd_m3_capture_close(struct snd_pcm_subs
82643 * create pcm instance
82644 */
82645
82646 -static struct snd_pcm_ops snd_m3_playback_ops = {
82647 +static const struct snd_pcm_ops snd_m3_playback_ops = {
82648 .open = snd_m3_playback_open,
82649 .close = snd_m3_playback_close,
82650 .ioctl = snd_pcm_lib_ioctl,
82651 @@ -1937,7 +1937,7 @@ static struct snd_pcm_ops snd_m3_playbac
82652 .pointer = snd_m3_pcm_pointer,
82653 };
82654
82655 -static struct snd_pcm_ops snd_m3_capture_ops = {
82656 +static const struct snd_pcm_ops snd_m3_capture_ops = {
82657 .open = snd_m3_capture_open,
82658 .close = snd_m3_capture_close,
82659 .ioctl = snd_pcm_lib_ioctl,
82660 @@ -2150,7 +2150,7 @@ static int __devinit snd_m3_mixer(struct
82661 struct snd_ctl_elem_id elem_id;
82662 #endif
82663 int err;
82664 - static struct snd_ac97_bus_ops ops = {
82665 + static const struct snd_ac97_bus_ops ops = {
82666 .write = snd_m3_ac97_write,
82667 .read = snd_m3_ac97_read,
82668 };
82669 @@ -2643,7 +2643,7 @@ snd_m3_create(struct snd_card *card, str
82670 struct snd_m3 *chip;
82671 int i, err;
82672 const struct snd_pci_quirk *quirk;
82673 - static struct snd_device_ops ops = {
82674 + static const struct snd_device_ops ops = {
82675 .dev_free = snd_m3_dev_free,
82676 };
82677
82678 diff -urNp linux-2.6.39.1/sound/pci/mixart/mixart.c linux-2.6.39.1/sound/pci/mixart/mixart.c
82679 --- linux-2.6.39.1/sound/pci/mixart/mixart.c 2011-05-19 00:06:34.000000000 -0400
82680 +++ linux-2.6.39.1/sound/pci/mixart/mixart.c 2011-05-22 19:36:35.000000000 -0400
82681 @@ -887,7 +887,7 @@ static snd_pcm_uframes_t snd_mixart_stre
82682
82683
82684
82685 -static struct snd_pcm_ops snd_mixart_playback_ops = {
82686 +static const struct snd_pcm_ops snd_mixart_playback_ops = {
82687 .open = snd_mixart_playback_open,
82688 .close = snd_mixart_close,
82689 .ioctl = snd_pcm_lib_ioctl,
82690 @@ -898,7 +898,7 @@ static struct snd_pcm_ops snd_mixart_pla
82691 .pointer = snd_mixart_stream_pointer,
82692 };
82693
82694 -static struct snd_pcm_ops snd_mixart_capture_ops = {
82695 +static const struct snd_pcm_ops snd_mixart_capture_ops = {
82696 .open = snd_mixart_capture_open,
82697 .close = snd_mixart_close,
82698 .ioctl = snd_pcm_lib_ioctl,
82699 @@ -1008,7 +1008,7 @@ static int __devinit snd_mixart_create(s
82700 {
82701 int err;
82702 struct snd_mixart *chip;
82703 - static struct snd_device_ops ops = {
82704 + static const struct snd_device_ops ops = {
82705 .dev_free = snd_mixart_chip_dev_free,
82706 };
82707
82708 diff -urNp linux-2.6.39.1/sound/pci/nm256/nm256.c linux-2.6.39.1/sound/pci/nm256/nm256.c
82709 --- linux-2.6.39.1/sound/pci/nm256/nm256.c 2011-05-19 00:06:34.000000000 -0400
82710 +++ linux-2.6.39.1/sound/pci/nm256/nm256.c 2011-05-22 19:36:35.000000000 -0400
82711 @@ -899,7 +899,7 @@ snd_nm256_capture_close(struct snd_pcm_s
82712 /*
82713 * create a pcm instance
82714 */
82715 -static struct snd_pcm_ops snd_nm256_playback_ops = {
82716 +static const struct snd_pcm_ops snd_nm256_playback_ops = {
82717 .open = snd_nm256_playback_open,
82718 .close = snd_nm256_playback_close,
82719 .ioctl = snd_pcm_lib_ioctl,
82720 @@ -914,7 +914,7 @@ static struct snd_pcm_ops snd_nm256_play
82721 .mmap = snd_pcm_lib_mmap_iomem,
82722 };
82723
82724 -static struct snd_pcm_ops snd_nm256_capture_ops = {
82725 +static const struct snd_pcm_ops snd_nm256_capture_ops = {
82726 .open = snd_nm256_capture_open,
82727 .close = snd_nm256_capture_close,
82728 .ioctl = snd_pcm_lib_ioctl,
82729 @@ -1301,7 +1301,7 @@ snd_nm256_mixer(struct nm256 *chip)
82730 struct snd_ac97_bus *pbus;
82731 struct snd_ac97_template ac97;
82732 int err;
82733 - static struct snd_ac97_bus_ops ops = {
82734 + static const struct snd_ac97_bus_ops ops = {
82735 .reset = snd_nm256_ac97_reset,
82736 .write = snd_nm256_ac97_write,
82737 .read = snd_nm256_ac97_read,
82738 @@ -1471,7 +1471,7 @@ snd_nm256_create(struct snd_card *card,
82739 {
82740 struct nm256 *chip;
82741 int err, pval;
82742 - static struct snd_device_ops ops = {
82743 + static const struct snd_device_ops ops = {
82744 .dev_free = snd_nm256_dev_free,
82745 };
82746 u32 addr;
82747 diff -urNp linux-2.6.39.1/sound/pci/oxygen/oxygen_pcm.c linux-2.6.39.1/sound/pci/oxygen/oxygen_pcm.c
82748 --- linux-2.6.39.1/sound/pci/oxygen/oxygen_pcm.c 2011-05-19 00:06:34.000000000 -0400
82749 +++ linux-2.6.39.1/sound/pci/oxygen/oxygen_pcm.c 2011-05-22 19:36:35.000000000 -0400
82750 @@ -606,7 +606,7 @@ static snd_pcm_uframes_t oxygen_pointer(
82751 return bytes_to_frames(runtime, curr_addr - (u32)runtime->dma_addr);
82752 }
82753
82754 -static struct snd_pcm_ops oxygen_rec_a_ops = {
82755 +static const struct snd_pcm_ops oxygen_rec_a_ops = {
82756 .open = oxygen_rec_a_open,
82757 .close = oxygen_close,
82758 .ioctl = snd_pcm_lib_ioctl,
82759 @@ -617,7 +617,7 @@ static struct snd_pcm_ops oxygen_rec_a_o
82760 .pointer = oxygen_pointer,
82761 };
82762
82763 -static struct snd_pcm_ops oxygen_rec_b_ops = {
82764 +static const struct snd_pcm_ops oxygen_rec_b_ops = {
82765 .open = oxygen_rec_b_open,
82766 .close = oxygen_close,
82767 .ioctl = snd_pcm_lib_ioctl,
82768 @@ -628,7 +628,7 @@ static struct snd_pcm_ops oxygen_rec_b_o
82769 .pointer = oxygen_pointer,
82770 };
82771
82772 -static struct snd_pcm_ops oxygen_rec_c_ops = {
82773 +static const struct snd_pcm_ops oxygen_rec_c_ops = {
82774 .open = oxygen_rec_c_open,
82775 .close = oxygen_close,
82776 .ioctl = snd_pcm_lib_ioctl,
82777 @@ -639,7 +639,7 @@ static struct snd_pcm_ops oxygen_rec_c_o
82778 .pointer = oxygen_pointer,
82779 };
82780
82781 -static struct snd_pcm_ops oxygen_spdif_ops = {
82782 +static const struct snd_pcm_ops oxygen_spdif_ops = {
82783 .open = oxygen_spdif_open,
82784 .close = oxygen_close,
82785 .ioctl = snd_pcm_lib_ioctl,
82786 @@ -650,7 +650,7 @@ static struct snd_pcm_ops oxygen_spdif_o
82787 .pointer = oxygen_pointer,
82788 };
82789
82790 -static struct snd_pcm_ops oxygen_multich_ops = {
82791 +static const struct snd_pcm_ops oxygen_multich_ops = {
82792 .open = oxygen_multich_open,
82793 .close = oxygen_close,
82794 .ioctl = snd_pcm_lib_ioctl,
82795 @@ -661,7 +661,7 @@ static struct snd_pcm_ops oxygen_multich
82796 .pointer = oxygen_pointer,
82797 };
82798
82799 -static struct snd_pcm_ops oxygen_ac97_ops = {
82800 +static const struct snd_pcm_ops oxygen_ac97_ops = {
82801 .open = oxygen_ac97_open,
82802 .close = oxygen_close,
82803 .ioctl = snd_pcm_lib_ioctl,
82804 diff -urNp linux-2.6.39.1/sound/pci/pcxhr/pcxhr.c linux-2.6.39.1/sound/pci/pcxhr/pcxhr.c
82805 --- linux-2.6.39.1/sound/pci/pcxhr/pcxhr.c 2011-05-19 00:06:34.000000000 -0400
82806 +++ linux-2.6.39.1/sound/pci/pcxhr/pcxhr.c 2011-05-22 19:36:35.000000000 -0400
82807 @@ -1121,7 +1121,7 @@ static snd_pcm_uframes_t pcxhr_stream_po
82808 }
82809
82810
82811 -static struct snd_pcm_ops pcxhr_ops = {
82812 +static const struct snd_pcm_ops pcxhr_ops = {
82813 .open = pcxhr_open,
82814 .close = pcxhr_close,
82815 .ioctl = snd_pcm_lib_ioctl,
82816 @@ -1184,7 +1184,7 @@ static int __devinit pcxhr_create(struct
82817 {
82818 int err;
82819 struct snd_pcxhr *chip;
82820 - static struct snd_device_ops ops = {
82821 + static const struct snd_device_ops ops = {
82822 .dev_free = pcxhr_chip_dev_free,
82823 };
82824
82825 diff -urNp linux-2.6.39.1/sound/pci/riptide/riptide.c linux-2.6.39.1/sound/pci/riptide/riptide.c
82826 --- linux-2.6.39.1/sound/pci/riptide/riptide.c 2011-05-19 00:06:34.000000000 -0400
82827 +++ linux-2.6.39.1/sound/pci/riptide/riptide.c 2011-05-22 19:36:35.000000000 -0400
82828 @@ -1675,7 +1675,7 @@ static int snd_riptide_capture_close(str
82829 return 0;
82830 }
82831
82832 -static struct snd_pcm_ops snd_riptide_playback_ops = {
82833 +static const struct snd_pcm_ops snd_riptide_playback_ops = {
82834 .open = snd_riptide_playback_open,
82835 .close = snd_riptide_playback_close,
82836 .ioctl = snd_pcm_lib_ioctl,
82837 @@ -1686,7 +1686,7 @@ static struct snd_pcm_ops snd_riptide_pl
82838 .trigger = snd_riptide_trigger,
82839 .pointer = snd_riptide_pointer,
82840 };
82841 -static struct snd_pcm_ops snd_riptide_capture_ops = {
82842 +static const struct snd_pcm_ops snd_riptide_capture_ops = {
82843 .open = snd_riptide_capture_open,
82844 .close = snd_riptide_capture_close,
82845 .ioctl = snd_pcm_lib_ioctl,
82846 @@ -1857,7 +1857,7 @@ snd_riptide_create(struct snd_card *card
82847 struct snd_riptide *chip;
82848 struct riptideport *hwport;
82849 int err;
82850 - static struct snd_device_ops ops = {
82851 + static const struct snd_device_ops ops = {
82852 .dev_free = snd_riptide_dev_free,
82853 };
82854
82855 @@ -1999,7 +1999,7 @@ static int __devinit snd_riptide_mixer(s
82856 struct snd_ac97_bus *pbus;
82857 struct snd_ac97_template ac97;
82858 int err = 0;
82859 - static struct snd_ac97_bus_ops ops = {
82860 + static const struct snd_ac97_bus_ops ops = {
82861 .write = snd_riptide_codec_write,
82862 .read = snd_riptide_codec_read,
82863 };
82864 diff -urNp linux-2.6.39.1/sound/pci/rme32.c linux-2.6.39.1/sound/pci/rme32.c
82865 --- linux-2.6.39.1/sound/pci/rme32.c 2011-05-19 00:06:34.000000000 -0400
82866 +++ linux-2.6.39.1/sound/pci/rme32.c 2011-05-22 19:36:35.000000000 -0400
82867 @@ -1197,7 +1197,7 @@ snd_rme32_capture_fd_pointer(struct snd_
82868 }
82869
82870 /* for halfduplex mode */
82871 -static struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
82872 +static const struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
82873 .open = snd_rme32_playback_spdif_open,
82874 .close = snd_rme32_playback_close,
82875 .ioctl = snd_pcm_lib_ioctl,
82876 @@ -1211,7 +1211,7 @@ static struct snd_pcm_ops snd_rme32_play
82877 .mmap = snd_pcm_lib_mmap_iomem,
82878 };
82879
82880 -static struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
82881 +static const struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
82882 .open = snd_rme32_capture_spdif_open,
82883 .close = snd_rme32_capture_close,
82884 .ioctl = snd_pcm_lib_ioctl,
82885 @@ -1224,7 +1224,7 @@ static struct snd_pcm_ops snd_rme32_capt
82886 .mmap = snd_pcm_lib_mmap_iomem,
82887 };
82888
82889 -static struct snd_pcm_ops snd_rme32_playback_adat_ops = {
82890 +static const struct snd_pcm_ops snd_rme32_playback_adat_ops = {
82891 .open = snd_rme32_playback_adat_open,
82892 .close = snd_rme32_playback_close,
82893 .ioctl = snd_pcm_lib_ioctl,
82894 @@ -1237,7 +1237,7 @@ static struct snd_pcm_ops snd_rme32_play
82895 .mmap = snd_pcm_lib_mmap_iomem,
82896 };
82897
82898 -static struct snd_pcm_ops snd_rme32_capture_adat_ops = {
82899 +static const struct snd_pcm_ops snd_rme32_capture_adat_ops = {
82900 .open = snd_rme32_capture_adat_open,
82901 .close = snd_rme32_capture_close,
82902 .ioctl = snd_pcm_lib_ioctl,
82903 @@ -1250,7 +1250,7 @@ static struct snd_pcm_ops snd_rme32_capt
82904 };
82905
82906 /* for fullduplex mode */
82907 -static struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
82908 +static const struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
82909 .open = snd_rme32_playback_spdif_open,
82910 .close = snd_rme32_playback_close,
82911 .ioctl = snd_pcm_lib_ioctl,
82912 @@ -1262,7 +1262,7 @@ static struct snd_pcm_ops snd_rme32_play
82913 .ack = snd_rme32_playback_fd_ack,
82914 };
82915
82916 -static struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
82917 +static const struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
82918 .open = snd_rme32_capture_spdif_open,
82919 .close = snd_rme32_capture_close,
82920 .ioctl = snd_pcm_lib_ioctl,
82921 @@ -1274,7 +1274,7 @@ static struct snd_pcm_ops snd_rme32_capt
82922 .ack = snd_rme32_capture_fd_ack,
82923 };
82924
82925 -static struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
82926 +static const struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
82927 .open = snd_rme32_playback_adat_open,
82928 .close = snd_rme32_playback_close,
82929 .ioctl = snd_pcm_lib_ioctl,
82930 @@ -1285,7 +1285,7 @@ static struct snd_pcm_ops snd_rme32_play
82931 .ack = snd_rme32_playback_fd_ack,
82932 };
82933
82934 -static struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
82935 +static const struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
82936 .open = snd_rme32_capture_adat_open,
82937 .close = snd_rme32_capture_close,
82938 .ioctl = snd_pcm_lib_ioctl,
82939 diff -urNp linux-2.6.39.1/sound/pci/rme9652/hdsp.c linux-2.6.39.1/sound/pci/rme9652/hdsp.c
82940 --- linux-2.6.39.1/sound/pci/rme9652/hdsp.c 2011-05-19 00:06:34.000000000 -0400
82941 +++ linux-2.6.39.1/sound/pci/rme9652/hdsp.c 2011-05-22 19:36:35.000000000 -0400
82942 @@ -1469,15 +1469,13 @@ static int snd_hdsp_midi_output_close(st
82943 return 0;
82944 }
82945
82946 -static struct snd_rawmidi_ops snd_hdsp_midi_output =
82947 -{
82948 +static const struct snd_rawmidi_ops snd_hdsp_midi_output = {
82949 .open = snd_hdsp_midi_output_open,
82950 .close = snd_hdsp_midi_output_close,
82951 .trigger = snd_hdsp_midi_output_trigger,
82952 };
82953
82954 -static struct snd_rawmidi_ops snd_hdsp_midi_input =
82955 -{
82956 +static const struct snd_rawmidi_ops snd_hdsp_midi_input = {
82957 .open = snd_hdsp_midi_input_open,
82958 .close = snd_hdsp_midi_input_close,
82959 .trigger = snd_hdsp_midi_input_trigger,
82960 @@ -5135,7 +5133,7 @@ static int snd_hdsp_hwdep_ioctl(struct s
82961 return 0;
82962 }
82963
82964 -static struct snd_pcm_ops snd_hdsp_playback_ops = {
82965 +static const struct snd_pcm_ops snd_hdsp_playback_ops = {
82966 .open = snd_hdsp_playback_open,
82967 .close = snd_hdsp_playback_release,
82968 .ioctl = snd_hdsp_ioctl,
82969 @@ -5147,7 +5145,7 @@ static struct snd_pcm_ops snd_hdsp_playb
82970 .silence = snd_hdsp_hw_silence,
82971 };
82972
82973 -static struct snd_pcm_ops snd_hdsp_capture_ops = {
82974 +static const struct snd_pcm_ops snd_hdsp_capture_ops = {
82975 .open = snd_hdsp_capture_open,
82976 .close = snd_hdsp_capture_release,
82977 .ioctl = snd_hdsp_ioctl,
82978 diff -urNp linux-2.6.39.1/sound/pci/rme9652/hdspm.c linux-2.6.39.1/sound/pci/rme9652/hdspm.c
82979 --- linux-2.6.39.1/sound/pci/rme9652/hdspm.c 2011-05-19 00:06:34.000000000 -0400
82980 +++ linux-2.6.39.1/sound/pci/rme9652/hdspm.c 2011-05-22 19:36:35.000000000 -0400
82981 @@ -1773,15 +1773,13 @@ static int snd_hdspm_midi_output_close(s
82982 return 0;
82983 }
82984
82985 -static struct snd_rawmidi_ops snd_hdspm_midi_output =
82986 -{
82987 +static const struct snd_rawmidi_ops snd_hdspm_midi_output = {
82988 .open = snd_hdspm_midi_output_open,
82989 .close = snd_hdspm_midi_output_close,
82990 .trigger = snd_hdspm_midi_output_trigger,
82991 };
82992
82993 -static struct snd_rawmidi_ops snd_hdspm_midi_input =
82994 -{
82995 +static const struct snd_rawmidi_ops snd_hdspm_midi_input = {
82996 .open = snd_hdspm_midi_input_open,
82997 .close = snd_hdspm_midi_input_close,
82998 .trigger = snd_hdspm_midi_input_trigger,
82999 @@ -6172,7 +6170,7 @@ static int snd_hdspm_hwdep_ioctl(struct
83000 return 0;
83001 }
83002
83003 -static struct snd_pcm_ops snd_hdspm_playback_ops = {
83004 +static const struct snd_pcm_ops snd_hdspm_playback_ops = {
83005 .open = snd_hdspm_playback_open,
83006 .close = snd_hdspm_playback_release,
83007 .ioctl = snd_hdspm_ioctl,
83008 @@ -6184,7 +6182,7 @@ static struct snd_pcm_ops snd_hdspm_play
83009 .page = snd_pcm_sgbuf_ops_page,
83010 };
83011
83012 -static struct snd_pcm_ops snd_hdspm_capture_ops = {
83013 +static const struct snd_pcm_ops snd_hdspm_capture_ops = {
83014 .open = snd_hdspm_capture_open,
83015 .close = snd_hdspm_capture_release,
83016 .ioctl = snd_hdspm_ioctl,
83017 diff -urNp linux-2.6.39.1/sound/pci/rme9652/rme9652.c linux-2.6.39.1/sound/pci/rme9652/rme9652.c
83018 --- linux-2.6.39.1/sound/pci/rme9652/rme9652.c 2011-05-19 00:06:34.000000000 -0400
83019 +++ linux-2.6.39.1/sound/pci/rme9652/rme9652.c 2011-05-22 19:36:35.000000000 -0400
83020 @@ -2391,7 +2391,7 @@ static int snd_rme9652_capture_release(s
83021 return 0;
83022 }
83023
83024 -static struct snd_pcm_ops snd_rme9652_playback_ops = {
83025 +static const struct snd_pcm_ops snd_rme9652_playback_ops = {
83026 .open = snd_rme9652_playback_open,
83027 .close = snd_rme9652_playback_release,
83028 .ioctl = snd_rme9652_ioctl,
83029 @@ -2403,7 +2403,7 @@ static struct snd_pcm_ops snd_rme9652_pl
83030 .silence = snd_rme9652_hw_silence,
83031 };
83032
83033 -static struct snd_pcm_ops snd_rme9652_capture_ops = {
83034 +static const struct snd_pcm_ops snd_rme9652_capture_ops = {
83035 .open = snd_rme9652_capture_open,
83036 .close = snd_rme9652_capture_release,
83037 .ioctl = snd_rme9652_ioctl,
83038 diff -urNp linux-2.6.39.1/sound/pci/rme96.c linux-2.6.39.1/sound/pci/rme96.c
83039 --- linux-2.6.39.1/sound/pci/rme96.c 2011-05-19 00:06:34.000000000 -0400
83040 +++ linux-2.6.39.1/sound/pci/rme96.c 2011-05-22 19:36:35.000000000 -0400
83041 @@ -1447,7 +1447,7 @@ snd_rme96_capture_pointer(struct snd_pcm
83042 return snd_rme96_capture_ptr(rme96);
83043 }
83044
83045 -static struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
83046 +static const struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
83047 .open = snd_rme96_playback_spdif_open,
83048 .close = snd_rme96_playback_close,
83049 .ioctl = snd_pcm_lib_ioctl,
83050 @@ -1460,7 +1460,7 @@ static struct snd_pcm_ops snd_rme96_play
83051 .mmap = snd_pcm_lib_mmap_iomem,
83052 };
83053
83054 -static struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
83055 +static const struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
83056 .open = snd_rme96_capture_spdif_open,
83057 .close = snd_rme96_capture_close,
83058 .ioctl = snd_pcm_lib_ioctl,
83059 @@ -1472,7 +1472,7 @@ static struct snd_pcm_ops snd_rme96_capt
83060 .mmap = snd_pcm_lib_mmap_iomem,
83061 };
83062
83063 -static struct snd_pcm_ops snd_rme96_playback_adat_ops = {
83064 +static const struct snd_pcm_ops snd_rme96_playback_adat_ops = {
83065 .open = snd_rme96_playback_adat_open,
83066 .close = snd_rme96_playback_close,
83067 .ioctl = snd_pcm_lib_ioctl,
83068 @@ -1485,7 +1485,7 @@ static struct snd_pcm_ops snd_rme96_play
83069 .mmap = snd_pcm_lib_mmap_iomem,
83070 };
83071
83072 -static struct snd_pcm_ops snd_rme96_capture_adat_ops = {
83073 +static const struct snd_pcm_ops snd_rme96_capture_adat_ops = {
83074 .open = snd_rme96_capture_adat_open,
83075 .close = snd_rme96_capture_close,
83076 .ioctl = snd_pcm_lib_ioctl,
83077 diff -urNp linux-2.6.39.1/sound/pci/sis7019.c linux-2.6.39.1/sound/pci/sis7019.c
83078 --- linux-2.6.39.1/sound/pci/sis7019.c 2011-05-19 00:06:34.000000000 -0400
83079 +++ linux-2.6.39.1/sound/pci/sis7019.c 2011-05-22 19:36:35.000000000 -0400
83080 @@ -1011,7 +1011,7 @@ static int __devinit sis_mixer_create(st
83081 {
83082 struct snd_ac97_bus *bus;
83083 struct snd_ac97_template ac97;
83084 - static struct snd_ac97_bus_ops ops = {
83085 + static const struct snd_ac97_bus_ops ops = {
83086 .write = sis_ac97_write,
83087 .read = sis_ac97_read,
83088 };
83089 @@ -1293,7 +1293,7 @@ static int __devinit sis_chip_create(str
83090 {
83091 struct sis7019 *sis = card->private_data;
83092 struct voice *voice;
83093 - static struct snd_device_ops ops = {
83094 + static const struct snd_device_ops ops = {
83095 .dev_free = sis_dev_free,
83096 };
83097 int rc;
83098 diff -urNp linux-2.6.39.1/sound/pci/sonicvibes.c linux-2.6.39.1/sound/pci/sonicvibes.c
83099 --- linux-2.6.39.1/sound/pci/sonicvibes.c 2011-05-19 00:06:34.000000000 -0400
83100 +++ linux-2.6.39.1/sound/pci/sonicvibes.c 2011-05-22 19:36:35.000000000 -0400
83101 @@ -855,7 +855,7 @@ static int snd_sonicvibes_capture_close(
83102 return 0;
83103 }
83104
83105 -static struct snd_pcm_ops snd_sonicvibes_playback_ops = {
83106 +static const struct snd_pcm_ops snd_sonicvibes_playback_ops = {
83107 .open = snd_sonicvibes_playback_open,
83108 .close = snd_sonicvibes_playback_close,
83109 .ioctl = snd_pcm_lib_ioctl,
83110 @@ -866,7 +866,7 @@ static struct snd_pcm_ops snd_sonicvibes
83111 .pointer = snd_sonicvibes_playback_pointer,
83112 };
83113
83114 -static struct snd_pcm_ops snd_sonicvibes_capture_ops = {
83115 +static const struct snd_pcm_ops snd_sonicvibes_capture_ops = {
83116 .open = snd_sonicvibes_capture_open,
83117 .close = snd_sonicvibes_capture_close,
83118 .ioctl = snd_pcm_lib_ioctl,
83119 @@ -1255,7 +1255,7 @@ static int __devinit snd_sonicvibes_crea
83120 struct sonicvibes *sonic;
83121 unsigned int dmaa, dmac;
83122 int err;
83123 - static struct snd_device_ops ops = {
83124 + static const struct snd_device_ops ops = {
83125 .dev_free = snd_sonicvibes_dev_free,
83126 };
83127
83128 diff -urNp linux-2.6.39.1/sound/pci/trident/trident_main.c linux-2.6.39.1/sound/pci/trident/trident_main.c
83129 --- linux-2.6.39.1/sound/pci/trident/trident_main.c 2011-05-19 00:06:34.000000000 -0400
83130 +++ linux-2.6.39.1/sound/pci/trident/trident_main.c 2011-05-22 19:36:35.000000000 -0400
83131 @@ -3549,7 +3549,7 @@ int __devinit snd_trident_create(struct
83132 int i, err;
83133 struct snd_trident_voice *voice;
83134 struct snd_trident_pcm_mixer *tmix;
83135 - static struct snd_device_ops ops = {
83136 + static const struct snd_device_ops ops = {
83137 .dev_free = snd_trident_dev_free,
83138 };
83139
83140 diff -urNp linux-2.6.39.1/sound/pci/via82xx.c linux-2.6.39.1/sound/pci/via82xx.c
83141 --- linux-2.6.39.1/sound/pci/via82xx.c 2011-05-19 00:06:34.000000000 -0400
83142 +++ linux-2.6.39.1/sound/pci/via82xx.c 2011-05-22 19:36:35.000000000 -0400
83143 @@ -1352,7 +1352,7 @@ static int snd_via8233_playback_close(st
83144
83145
83146 /* via686 playback callbacks */
83147 -static struct snd_pcm_ops snd_via686_playback_ops = {
83148 +static const struct snd_pcm_ops snd_via686_playback_ops = {
83149 .open = snd_via686_playback_open,
83150 .close = snd_via82xx_pcm_close,
83151 .ioctl = snd_pcm_lib_ioctl,
83152 @@ -1365,7 +1365,7 @@ static struct snd_pcm_ops snd_via686_pla
83153 };
83154
83155 /* via686 capture callbacks */
83156 -static struct snd_pcm_ops snd_via686_capture_ops = {
83157 +static const struct snd_pcm_ops snd_via686_capture_ops = {
83158 .open = snd_via82xx_capture_open,
83159 .close = snd_via82xx_pcm_close,
83160 .ioctl = snd_pcm_lib_ioctl,
83161 @@ -1378,7 +1378,7 @@ static struct snd_pcm_ops snd_via686_cap
83162 };
83163
83164 /* via823x DSX playback callbacks */
83165 -static struct snd_pcm_ops snd_via8233_playback_ops = {
83166 +static const struct snd_pcm_ops snd_via8233_playback_ops = {
83167 .open = snd_via8233_playback_open,
83168 .close = snd_via8233_playback_close,
83169 .ioctl = snd_pcm_lib_ioctl,
83170 @@ -1391,7 +1391,7 @@ static struct snd_pcm_ops snd_via8233_pl
83171 };
83172
83173 /* via823x multi-channel playback callbacks */
83174 -static struct snd_pcm_ops snd_via8233_multi_ops = {
83175 +static const struct snd_pcm_ops snd_via8233_multi_ops = {
83176 .open = snd_via8233_multi_open,
83177 .close = snd_via82xx_pcm_close,
83178 .ioctl = snd_pcm_lib_ioctl,
83179 @@ -1404,7 +1404,7 @@ static struct snd_pcm_ops snd_via8233_mu
83180 };
83181
83182 /* via823x capture callbacks */
83183 -static struct snd_pcm_ops snd_via8233_capture_ops = {
83184 +static const struct snd_pcm_ops snd_via8233_capture_ops = {
83185 .open = snd_via82xx_capture_open,
83186 .close = snd_via82xx_pcm_close,
83187 .ioctl = snd_pcm_lib_ioctl,
83188 @@ -1868,7 +1868,7 @@ static int __devinit snd_via82xx_mixer_n
83189 {
83190 struct snd_ac97_template ac97;
83191 int err;
83192 - static struct snd_ac97_bus_ops ops = {
83193 + static const struct snd_ac97_bus_ops ops = {
83194 .write = snd_via82xx_codec_write,
83195 .read = snd_via82xx_codec_read,
83196 .wait = snd_via82xx_codec_wait,
83197 @@ -2340,7 +2340,7 @@ static int __devinit snd_via82xx_create(
83198 {
83199 struct via82xx *chip;
83200 int err;
83201 - static struct snd_device_ops ops = {
83202 + static const struct snd_device_ops ops = {
83203 .dev_free = snd_via82xx_dev_free,
83204 };
83205
83206 diff -urNp linux-2.6.39.1/sound/pci/via82xx_modem.c linux-2.6.39.1/sound/pci/via82xx_modem.c
83207 --- linux-2.6.39.1/sound/pci/via82xx_modem.c 2011-05-19 00:06:34.000000000 -0400
83208 +++ linux-2.6.39.1/sound/pci/via82xx_modem.c 2011-05-22 19:36:35.000000000 -0400
83209 @@ -799,7 +799,7 @@ static int snd_via82xx_pcm_close(struct
83210
83211
83212 /* via686 playback callbacks */
83213 -static struct snd_pcm_ops snd_via686_playback_ops = {
83214 +static const struct snd_pcm_ops snd_via686_playback_ops = {
83215 .open = snd_via82xx_playback_open,
83216 .close = snd_via82xx_pcm_close,
83217 .ioctl = snd_pcm_lib_ioctl,
83218 @@ -812,7 +812,7 @@ static struct snd_pcm_ops snd_via686_pla
83219 };
83220
83221 /* via686 capture callbacks */
83222 -static struct snd_pcm_ops snd_via686_capture_ops = {
83223 +static const struct snd_pcm_ops snd_via686_capture_ops = {
83224 .open = snd_via82xx_capture_open,
83225 .close = snd_via82xx_pcm_close,
83226 .ioctl = snd_pcm_lib_ioctl,
83227 @@ -889,7 +889,7 @@ static int __devinit snd_via82xx_mixer_n
83228 {
83229 struct snd_ac97_template ac97;
83230 int err;
83231 - static struct snd_ac97_bus_ops ops = {
83232 + static const struct snd_ac97_bus_ops ops = {
83233 .write = snd_via82xx_codec_write,
83234 .read = snd_via82xx_codec_read,
83235 .wait = snd_via82xx_codec_wait,
83236 @@ -1105,7 +1105,7 @@ static int __devinit snd_via82xx_create(
83237 {
83238 struct via82xx_modem *chip;
83239 int err;
83240 - static struct snd_device_ops ops = {
83241 + static const struct snd_device_ops ops = {
83242 .dev_free = snd_via82xx_dev_free,
83243 };
83244
83245 diff -urNp linux-2.6.39.1/sound/pci/vx222/vx222.c linux-2.6.39.1/sound/pci/vx222/vx222.c
83246 --- linux-2.6.39.1/sound/pci/vx222/vx222.c 2011-05-19 00:06:34.000000000 -0400
83247 +++ linux-2.6.39.1/sound/pci/vx222/vx222.c 2011-05-22 19:36:35.000000000 -0400
83248 @@ -141,7 +141,7 @@ static int __devinit snd_vx222_create(st
83249 struct vx_core *chip;
83250 struct snd_vx222 *vx;
83251 int i, err;
83252 - static struct snd_device_ops ops = {
83253 + static const struct snd_device_ops ops = {
83254 .dev_free = snd_vx222_dev_free,
83255 };
83256 struct snd_vx_ops *vx_ops;
83257 diff -urNp linux-2.6.39.1/sound/pci/ymfpci/ymfpci_main.c linux-2.6.39.1/sound/pci/ymfpci/ymfpci_main.c
83258 --- linux-2.6.39.1/sound/pci/ymfpci/ymfpci_main.c 2011-05-19 00:06:34.000000000 -0400
83259 +++ linux-2.6.39.1/sound/pci/ymfpci/ymfpci_main.c 2011-05-22 19:36:35.000000000 -0400
83260 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct sn
83261 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
83262 break;
83263 }
83264 - if (atomic_read(&chip->interrupt_sleep_count)) {
83265 - atomic_set(&chip->interrupt_sleep_count, 0);
83266 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83267 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83268 wake_up(&chip->interrupt_sleep);
83269 }
83270 __end:
83271 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct s
83272 continue;
83273 init_waitqueue_entry(&wait, current);
83274 add_wait_queue(&chip->interrupt_sleep, &wait);
83275 - atomic_inc(&chip->interrupt_sleep_count);
83276 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
83277 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
83278 remove_wait_queue(&chip->interrupt_sleep, &wait);
83279 }
83280 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(
83281 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
83282 spin_unlock(&chip->reg_lock);
83283
83284 - if (atomic_read(&chip->interrupt_sleep_count)) {
83285 - atomic_set(&chip->interrupt_sleep_count, 0);
83286 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83287 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83288 wake_up(&chip->interrupt_sleep);
83289 }
83290 }
83291 @@ -2344,7 +2344,7 @@ int __devinit snd_ymfpci_create(struct s
83292 {
83293 struct snd_ymfpci *chip;
83294 int err;
83295 - static struct snd_device_ops ops = {
83296 + static const struct snd_device_ops ops = {
83297 .dev_free = snd_ymfpci_dev_free,
83298 };
83299
83300 @@ -2363,7 +2363,7 @@ int __devinit snd_ymfpci_create(struct s
83301 spin_lock_init(&chip->reg_lock);
83302 spin_lock_init(&chip->voice_lock);
83303 init_waitqueue_head(&chip->interrupt_sleep);
83304 - atomic_set(&chip->interrupt_sleep_count, 0);
83305 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83306 chip->card = card;
83307 chip->pci = pci;
83308 chip->irq = -1;
83309 diff -urNp linux-2.6.39.1/sound/pcmcia/pdaudiocf/pdaudiocf.c linux-2.6.39.1/sound/pcmcia/pdaudiocf/pdaudiocf.c
83310 --- linux-2.6.39.1/sound/pcmcia/pdaudiocf/pdaudiocf.c 2011-05-19 00:06:34.000000000 -0400
83311 +++ linux-2.6.39.1/sound/pcmcia/pdaudiocf/pdaudiocf.c 2011-05-22 19:36:35.000000000 -0400
83312 @@ -94,7 +94,7 @@ static int snd_pdacf_probe(struct pcmcia
83313 int i, err;
83314 struct snd_pdacf *pdacf;
83315 struct snd_card *card;
83316 - static struct snd_device_ops ops = {
83317 + static const struct snd_device_ops ops = {
83318 .dev_free = snd_pdacf_dev_free,
83319 };
83320
83321 diff -urNp linux-2.6.39.1/sound/pcmcia/vx/vxpocket.c linux-2.6.39.1/sound/pcmcia/vx/vxpocket.c
83322 --- linux-2.6.39.1/sound/pcmcia/vx/vxpocket.c 2011-05-19 00:06:34.000000000 -0400
83323 +++ linux-2.6.39.1/sound/pcmcia/vx/vxpocket.c 2011-05-22 19:36:35.000000000 -0400
83324 @@ -137,7 +137,7 @@ static int snd_vxpocket_new(struct snd_c
83325 {
83326 struct vx_core *chip;
83327 struct snd_vxpocket *vxp;
83328 - static struct snd_device_ops ops = {
83329 + static const struct snd_device_ops ops = {
83330 .dev_free = snd_vxpocket_dev_free,
83331 };
83332 int err;
83333 diff -urNp linux-2.6.39.1/sound/ppc/pmac.c linux-2.6.39.1/sound/ppc/pmac.c
83334 --- linux-2.6.39.1/sound/ppc/pmac.c 2011-05-19 00:06:34.000000000 -0400
83335 +++ linux-2.6.39.1/sound/ppc/pmac.c 2011-05-22 19:36:35.000000000 -0400
83336 @@ -1186,7 +1186,7 @@ int __devinit snd_pmac_new(struct snd_ca
83337 int i, err;
83338 unsigned int irq;
83339 unsigned long ctrl_addr, txdma_addr, rxdma_addr;
83340 - static struct snd_device_ops ops = {
83341 + static const struct snd_device_ops ops = {
83342 .dev_free = snd_pmac_dev_free,
83343 };
83344
83345 diff -urNp linux-2.6.39.1/sound/ppc/snd_ps3.c linux-2.6.39.1/sound/ppc/snd_ps3.c
83346 --- linux-2.6.39.1/sound/ppc/snd_ps3.c 2011-05-19 00:06:34.000000000 -0400
83347 +++ linux-2.6.39.1/sound/ppc/snd_ps3.c 2011-05-22 19:36:35.000000000 -0400
83348 @@ -773,7 +773,7 @@ static struct snd_kcontrol_new spdif_ctl
83349 },
83350 };
83351
83352 -static struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
83353 +static const struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
83354 .open = snd_ps3_pcm_open,
83355 .close = snd_ps3_pcm_close,
83356 .ioctl = snd_pcm_lib_ioctl,
83357 diff -urNp linux-2.6.39.1/sound/sh/aica.c linux-2.6.39.1/sound/sh/aica.c
83358 --- linux-2.6.39.1/sound/sh/aica.c 2011-05-19 00:06:34.000000000 -0400
83359 +++ linux-2.6.39.1/sound/sh/aica.c 2011-05-22 19:36:35.000000000 -0400
83360 @@ -441,7 +441,7 @@ static unsigned long snd_aicapcm_pcm_poi
83361 return readl(AICA_CONTROL_CHANNEL_SAMPLE_NUMBER);
83362 }
83363
83364 -static struct snd_pcm_ops snd_aicapcm_playback_ops = {
83365 +static const struct snd_pcm_ops snd_aicapcm_playback_ops = {
83366 .open = snd_aicapcm_pcm_open,
83367 .close = snd_aicapcm_pcm_close,
83368 .ioctl = snd_pcm_lib_ioctl,
83369 diff -urNp linux-2.6.39.1/sound/sh/sh_dac_audio.c linux-2.6.39.1/sound/sh/sh_dac_audio.c
83370 --- linux-2.6.39.1/sound/sh/sh_dac_audio.c 2011-05-19 00:06:34.000000000 -0400
83371 +++ linux-2.6.39.1/sound/sh/sh_dac_audio.c 2011-05-22 19:36:35.000000000 -0400
83372 @@ -246,7 +246,7 @@ snd_pcm_uframes_t snd_sh_dac_pcm_pointer
83373 }
83374
83375 /* pcm ops */
83376 -static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
83377 +static const struct snd_pcm_ops snd_sh_dac_pcm_ops = {
83378 .open = snd_sh_dac_pcm_open,
83379 .close = snd_sh_dac_pcm_close,
83380 .ioctl = snd_pcm_lib_ioctl,
83381 @@ -352,7 +352,7 @@ static int __devinit snd_sh_dac_create(s
83382 struct snd_sh_dac *chip;
83383 int err;
83384
83385 - static struct snd_device_ops ops = {
83386 + static const struct snd_device_ops ops = {
83387 .dev_free = snd_sh_dac_dev_free,
83388 };
83389
83390 diff -urNp linux-2.6.39.1/sound/soc/atmel/atmel-pcm.c linux-2.6.39.1/sound/soc/atmel/atmel-pcm.c
83391 --- linux-2.6.39.1/sound/soc/atmel/atmel-pcm.c 2011-05-19 00:06:34.000000000 -0400
83392 +++ linux-2.6.39.1/sound/soc/atmel/atmel-pcm.c 2011-05-22 19:36:35.000000000 -0400
83393 @@ -346,7 +346,7 @@ static int atmel_pcm_mmap(struct snd_pcm
83394 vma->vm_end - vma->vm_start, vma->vm_page_prot);
83395 }
83396
83397 -static struct snd_pcm_ops atmel_pcm_ops = {
83398 +static const struct snd_pcm_ops atmel_pcm_ops = {
83399 .open = atmel_pcm_open,
83400 .close = atmel_pcm_close,
83401 .ioctl = snd_pcm_lib_ioctl,
83402 diff -urNp linux-2.6.39.1/sound/soc/atmel/playpaq_wm8510.c linux-2.6.39.1/sound/soc/atmel/playpaq_wm8510.c
83403 --- linux-2.6.39.1/sound/soc/atmel/playpaq_wm8510.c 2011-05-19 00:06:34.000000000 -0400
83404 +++ linux-2.6.39.1/sound/soc/atmel/playpaq_wm8510.c 2011-05-22 19:36:35.000000000 -0400
83405 @@ -289,7 +289,7 @@ static int playpaq_wm8510_hw_params(stru
83406
83407
83408
83409 -static struct snd_soc_ops playpaq_wm8510_ops = {
83410 +static const struct snd_soc_ops playpaq_wm8510_ops = {
83411 .hw_params = playpaq_wm8510_hw_params,
83412 };
83413
83414 diff -urNp linux-2.6.39.1/sound/soc/atmel/sam9g20_wm8731.c linux-2.6.39.1/sound/soc/atmel/sam9g20_wm8731.c
83415 --- linux-2.6.39.1/sound/soc/atmel/sam9g20_wm8731.c 2011-05-19 00:06:34.000000000 -0400
83416 +++ linux-2.6.39.1/sound/soc/atmel/sam9g20_wm8731.c 2011-05-22 19:36:35.000000000 -0400
83417 @@ -87,7 +87,7 @@ static int at91sam9g20ek_hw_params(struc
83418 return 0;
83419 }
83420
83421 -static struct snd_soc_ops at91sam9g20ek_ops = {
83422 +static const struct snd_soc_ops at91sam9g20ek_ops = {
83423 .hw_params = at91sam9g20ek_hw_params,
83424 };
83425
83426 diff -urNp linux-2.6.39.1/sound/soc/atmel/snd-soc-afeb9260.c linux-2.6.39.1/sound/soc/atmel/snd-soc-afeb9260.c
83427 --- linux-2.6.39.1/sound/soc/atmel/snd-soc-afeb9260.c 2011-05-19 00:06:34.000000000 -0400
83428 +++ linux-2.6.39.1/sound/soc/atmel/snd-soc-afeb9260.c 2011-05-22 19:36:35.000000000 -0400
83429 @@ -81,7 +81,7 @@ static int afeb9260_hw_params(struct snd
83430 return err;
83431 }
83432
83433 -static struct snd_soc_ops afeb9260_ops = {
83434 +static const struct snd_soc_ops afeb9260_ops = {
83435 .hw_params = afeb9260_hw_params,
83436 };
83437
83438 diff -urNp linux-2.6.39.1/sound/soc/au1x/db1200.c linux-2.6.39.1/sound/soc/au1x/db1200.c
83439 --- linux-2.6.39.1/sound/soc/au1x/db1200.c 2011-05-19 00:06:34.000000000 -0400
83440 +++ linux-2.6.39.1/sound/soc/au1x/db1200.c 2011-05-22 19:36:35.000000000 -0400
83441 @@ -67,7 +67,7 @@ out:
83442 return ret;
83443 }
83444
83445 -static struct snd_soc_ops db1200_i2s_wm8731_ops = {
83446 +static const struct snd_soc_ops db1200_i2s_wm8731_ops = {
83447 .startup = db1200_i2s_startup,
83448 };
83449
83450 diff -urNp linux-2.6.39.1/sound/soc/au1x/dbdma2.c linux-2.6.39.1/sound/soc/au1x/dbdma2.c
83451 --- linux-2.6.39.1/sound/soc/au1x/dbdma2.c 2011-05-19 00:06:34.000000000 -0400
83452 +++ linux-2.6.39.1/sound/soc/au1x/dbdma2.c 2011-05-22 19:36:35.000000000 -0400
83453 @@ -303,7 +303,7 @@ static int au1xpsc_pcm_close(struct snd_
83454 return 0;
83455 }
83456
83457 -static struct snd_pcm_ops au1xpsc_pcm_ops = {
83458 +static const struct snd_pcm_ops au1xpsc_pcm_ops = {
83459 .open = au1xpsc_pcm_open,
83460 .close = au1xpsc_pcm_close,
83461 .ioctl = snd_pcm_lib_ioctl,
83462 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.c
83463 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83464 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83465 @@ -244,7 +244,7 @@ static void bf5xx_ac97_cold_reset(struct
83466 #endif
83467 }
83468
83469 -struct snd_ac97_bus_ops soc_ac97_ops = {
83470 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83471 .read = bf5xx_ac97_read,
83472 .write = bf5xx_ac97_write,
83473 .warm_reset = bf5xx_ac97_warm_reset,
83474 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.h linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.h
83475 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.h 2011-05-19 00:06:34.000000000 -0400
83476 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97.h 2011-05-22 19:36:35.000000000 -0400
83477 @@ -9,7 +9,7 @@
83478 #ifndef _BF5XX_AC97_H
83479 #define _BF5XX_AC97_H
83480
83481 -extern struct snd_ac97_bus_ops bf5xx_ac97_ops;
83482 +extern const struct snd_ac97_bus_ops bf5xx_ac97_ops;
83483 extern struct snd_ac97 *ac97;
83484 /* Frame format in memory, only support stereo currently */
83485 struct ac97_frame {
83486 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97-pcm.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97-pcm.c
83487 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97-pcm.c 2011-05-19 00:06:34.000000000 -0400
83488 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ac97-pcm.c 2011-05-22 19:36:35.000000000 -0400
83489 @@ -297,7 +297,7 @@ static int bf5xx_pcm_copy(struct snd_pcm
83490 }
83491 #endif
83492
83493 -static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
83494 +static const struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
83495 .open = bf5xx_pcm_open,
83496 .ioctl = snd_pcm_lib_ioctl,
83497 .hw_params = bf5xx_pcm_hw_params,
83498 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1836.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1836.c
83499 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1836.c 2011-05-19 00:06:34.000000000 -0400
83500 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1836.c 2011-05-22 19:36:35.000000000 -0400
83501 @@ -74,7 +74,7 @@ static int bf5xx_ad1836_hw_params(struct
83502 return 0;
83503 }
83504
83505 -static struct snd_soc_ops bf5xx_ad1836_ops = {
83506 +static const struct snd_soc_ops bf5xx_ad1836_ops = {
83507 .startup = bf5xx_ad1836_startup,
83508 .hw_params = bf5xx_ad1836_hw_params,
83509 };
83510 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad193x.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad193x.c
83511 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad193x.c 2011-05-19 00:06:34.000000000 -0400
83512 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad193x.c 2011-05-22 19:36:35.000000000 -0400
83513 @@ -88,7 +88,7 @@ static int bf5xx_ad193x_hw_params(struct
83514 return 0;
83515 }
83516
83517 -static struct snd_soc_ops bf5xx_ad193x_ops = {
83518 +static const struct snd_soc_ops bf5xx_ad193x_ops = {
83519 .startup = bf5xx_ad193x_startup,
83520 .hw_params = bf5xx_ad193x_hw_params,
83521 };
83522 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1980.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1980.c
83523 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1980.c 2011-05-19 00:06:34.000000000 -0400
83524 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad1980.c 2011-05-22 19:36:35.000000000 -0400
83525 @@ -63,7 +63,7 @@ static int bf5xx_board_startup(struct sn
83526 return 0;
83527 }
83528
83529 -static struct snd_soc_ops bf5xx_board_ops = {
83530 +static const struct snd_soc_ops bf5xx_board_ops = {
83531 .startup = bf5xx_board_startup,
83532 };
83533
83534 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad73311.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad73311.c
83535 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad73311.c 2011-05-19 00:06:34.000000000 -0400
83536 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ad73311.c 2011-05-22 19:36:35.000000000 -0400
83537 @@ -175,7 +175,7 @@ static int bf5xx_ad73311_hw_params(struc
83538 }
83539
83540
83541 -static struct snd_soc_ops bf5xx_ad73311_ops = {
83542 +static const struct snd_soc_ops bf5xx_ad73311_ops = {
83543 .startup = bf5xx_ad73311_startup,
83544 .hw_params = bf5xx_ad73311_hw_params,
83545 };
83546 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-i2s-pcm.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-i2s-pcm.c
83547 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-i2s-pcm.c 2011-05-19 00:06:34.000000000 -0400
83548 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-i2s-pcm.c 2011-05-22 19:36:35.000000000 -0400
83549 @@ -183,7 +183,7 @@ static int bf5xx_pcm_mmap(struct snd_pcm
83550 return 0 ;
83551 }
83552
83553 -static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
83554 +static const struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
83555 .open = bf5xx_pcm_open,
83556 .ioctl = snd_pcm_lib_ioctl,
83557 .hw_params = bf5xx_pcm_hw_params,
83558 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-ssm2602.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-ssm2602.c
83559 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-ssm2602.c 2011-05-19 00:06:34.000000000 -0400
83560 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-ssm2602.c 2011-05-22 19:36:35.000000000 -0400
83561 @@ -108,7 +108,7 @@ static int bf5xx_ssm2602_hw_params(struc
83562 return 0;
83563 }
83564
83565 -static struct snd_soc_ops bf5xx_ssm2602_ops = {
83566 +static const struct snd_soc_ops bf5xx_ssm2602_ops = {
83567 .startup = bf5xx_ssm2602_startup,
83568 .hw_params = bf5xx_ssm2602_hw_params,
83569 };
83570 diff -urNp linux-2.6.39.1/sound/soc/blackfin/bf5xx-tdm-pcm.c linux-2.6.39.1/sound/soc/blackfin/bf5xx-tdm-pcm.c
83571 --- linux-2.6.39.1/sound/soc/blackfin/bf5xx-tdm-pcm.c 2011-05-19 00:06:34.000000000 -0400
83572 +++ linux-2.6.39.1/sound/soc/blackfin/bf5xx-tdm-pcm.c 2011-05-22 19:36:35.000000000 -0400
83573 @@ -220,7 +220,7 @@ static int bf5xx_pcm_silence(struct snd_
83574 }
83575
83576
83577 -struct snd_pcm_ops bf5xx_pcm_tdm_ops = {
83578 +const struct snd_pcm_ops bf5xx_pcm_tdm_ops = {
83579 .open = bf5xx_pcm_open,
83580 .ioctl = snd_pcm_lib_ioctl,
83581 .hw_params = bf5xx_pcm_hw_params,
83582 diff -urNp linux-2.6.39.1/sound/soc/davinci/davinci-evm.c linux-2.6.39.1/sound/soc/davinci/davinci-evm.c
83583 --- linux-2.6.39.1/sound/soc/davinci/davinci-evm.c 2011-05-19 00:06:34.000000000 -0400
83584 +++ linux-2.6.39.1/sound/soc/davinci/davinci-evm.c 2011-05-22 19:36:35.000000000 -0400
83585 @@ -88,11 +88,11 @@ static int evm_spdif_hw_params(struct sn
83586 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
83587 }
83588
83589 -static struct snd_soc_ops evm_ops = {
83590 +static const struct snd_soc_ops evm_ops = {
83591 .hw_params = evm_hw_params,
83592 };
83593
83594 -static struct snd_soc_ops evm_spdif_ops = {
83595 +static const struct snd_soc_ops evm_spdif_ops = {
83596 .hw_params = evm_spdif_hw_params,
83597 };
83598
83599 diff -urNp linux-2.6.39.1/sound/soc/davinci/davinci-pcm.c linux-2.6.39.1/sound/soc/davinci/davinci-pcm.c
83600 --- linux-2.6.39.1/sound/soc/davinci/davinci-pcm.c 2011-05-19 00:06:34.000000000 -0400
83601 +++ linux-2.6.39.1/sound/soc/davinci/davinci-pcm.c 2011-05-22 19:36:35.000000000 -0400
83602 @@ -748,7 +748,7 @@ static int davinci_pcm_mmap(struct snd_p
83603 runtime->dma_bytes);
83604 }
83605
83606 -static struct snd_pcm_ops davinci_pcm_ops = {
83607 +static const struct snd_pcm_ops davinci_pcm_ops = {
83608 .open = davinci_pcm_open,
83609 .close = davinci_pcm_close,
83610 .ioctl = snd_pcm_lib_ioctl,
83611 diff -urNp linux-2.6.39.1/sound/soc/davinci/davinci-sffsdr.c linux-2.6.39.1/sound/soc/davinci/davinci-sffsdr.c
83612 --- linux-2.6.39.1/sound/soc/davinci/davinci-sffsdr.c 2011-05-19 00:06:34.000000000 -0400
83613 +++ linux-2.6.39.1/sound/soc/davinci/davinci-sffsdr.c 2011-05-22 19:36:35.000000000 -0400
83614 @@ -75,7 +75,7 @@ static int sffsdr_hw_params(struct snd_p
83615 #endif
83616 }
83617
83618 -static struct snd_soc_ops sffsdr_ops = {
83619 +static const struct snd_soc_ops sffsdr_ops = {
83620 .hw_params = sffsdr_hw_params,
83621 };
83622
83623 diff -urNp linux-2.6.39.1/sound/soc/ep93xx/edb93xx.c linux-2.6.39.1/sound/soc/ep93xx/edb93xx.c
83624 --- linux-2.6.39.1/sound/soc/ep93xx/edb93xx.c 2011-05-19 00:06:34.000000000 -0400
83625 +++ linux-2.6.39.1/sound/soc/ep93xx/edb93xx.c 2011-05-22 19:36:35.000000000 -0400
83626 @@ -74,7 +74,7 @@ static int edb93xx_hw_params(struct snd_
83627 SND_SOC_CLOCK_OUT);
83628 }
83629
83630 -static struct snd_soc_ops edb93xx_ops = {
83631 +static const struct snd_soc_ops edb93xx_ops = {
83632 .hw_params = edb93xx_hw_params,
83633 };
83634
83635 diff -urNp linux-2.6.39.1/sound/soc/ep93xx/ep93xx-ac97.c linux-2.6.39.1/sound/soc/ep93xx/ep93xx-ac97.c
83636 --- linux-2.6.39.1/sound/soc/ep93xx/ep93xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83637 +++ linux-2.6.39.1/sound/soc/ep93xx/ep93xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83638 @@ -239,7 +239,7 @@ static irqreturn_t ep93xx_ac97_interrupt
83639 return IRQ_HANDLED;
83640 }
83641
83642 -struct snd_ac97_bus_ops soc_ac97_ops = {
83643 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83644 .read = ep93xx_ac97_read,
83645 .write = ep93xx_ac97_write,
83646 .reset = ep93xx_ac97_cold_reset,
83647 diff -urNp linux-2.6.39.1/sound/soc/ep93xx/ep93xx-pcm.c linux-2.6.39.1/sound/soc/ep93xx/ep93xx-pcm.c
83648 --- linux-2.6.39.1/sound/soc/ep93xx/ep93xx-pcm.c 2011-05-19 00:06:34.000000000 -0400
83649 +++ linux-2.6.39.1/sound/soc/ep93xx/ep93xx-pcm.c 2011-05-22 19:36:35.000000000 -0400
83650 @@ -216,7 +216,7 @@ static int ep93xx_pcm_mmap(struct snd_pc
83651 runtime->dma_bytes);
83652 }
83653
83654 -static struct snd_pcm_ops ep93xx_pcm_ops = {
83655 +static const struct snd_pcm_ops ep93xx_pcm_ops = {
83656 .open = ep93xx_pcm_open,
83657 .close = ep93xx_pcm_close,
83658 .ioctl = snd_pcm_lib_ioctl,
83659 diff -urNp linux-2.6.39.1/sound/soc/ep93xx/snappercl15.c linux-2.6.39.1/sound/soc/ep93xx/snappercl15.c
83660 --- linux-2.6.39.1/sound/soc/ep93xx/snappercl15.c 2011-05-19 00:06:34.000000000 -0400
83661 +++ linux-2.6.39.1/sound/soc/ep93xx/snappercl15.c 2011-05-22 19:36:35.000000000 -0400
83662 @@ -55,7 +55,7 @@ static int snappercl15_hw_params(struct
83663 return 0;
83664 }
83665
83666 -static struct snd_soc_ops snappercl15_ops = {
83667 +static const struct snd_soc_ops snappercl15_ops = {
83668 .hw_params = snappercl15_hw_params,
83669 };
83670
83671 diff -urNp linux-2.6.39.1/sound/soc/fsl/fsl_dma.c linux-2.6.39.1/sound/soc/fsl/fsl_dma.c
83672 --- linux-2.6.39.1/sound/soc/fsl/fsl_dma.c 2011-05-19 00:06:34.000000000 -0400
83673 +++ linux-2.6.39.1/sound/soc/fsl/fsl_dma.c 2011-05-22 19:36:35.000000000 -0400
83674 @@ -887,7 +887,7 @@ static struct device_node *find_ssi_node
83675 return NULL;
83676 }
83677
83678 -static struct snd_pcm_ops fsl_dma_ops = {
83679 +static const struct snd_pcm_ops fsl_dma_ops = {
83680 .open = fsl_dma_open,
83681 .close = fsl_dma_close,
83682 .ioctl = snd_pcm_lib_ioctl,
83683 diff -urNp linux-2.6.39.1/sound/soc/fsl/mpc8610_hpcd.c linux-2.6.39.1/sound/soc/fsl/mpc8610_hpcd.c
83684 --- linux-2.6.39.1/sound/soc/fsl/mpc8610_hpcd.c 2011-05-19 00:06:34.000000000 -0400
83685 +++ linux-2.6.39.1/sound/soc/fsl/mpc8610_hpcd.c 2011-05-22 19:36:35.000000000 -0400
83686 @@ -175,7 +175,7 @@ static int mpc8610_hpcd_machine_remove(s
83687 /**
83688 * mpc8610_hpcd_ops: ASoC machine driver operations
83689 */
83690 -static struct snd_soc_ops mpc8610_hpcd_ops = {
83691 +static const struct snd_soc_ops mpc8610_hpcd_ops = {
83692 .startup = mpc8610_hpcd_startup,
83693 };
83694
83695 diff -urNp linux-2.6.39.1/sound/soc/fsl/p1022_ds.c linux-2.6.39.1/sound/soc/fsl/p1022_ds.c
83696 --- linux-2.6.39.1/sound/soc/fsl/p1022_ds.c 2011-05-19 00:06:34.000000000 -0400
83697 +++ linux-2.6.39.1/sound/soc/fsl/p1022_ds.c 2011-05-22 19:36:35.000000000 -0400
83698 @@ -185,7 +185,7 @@ static int p1022_ds_machine_remove(struc
83699 /**
83700 * p1022_ds_ops: ASoC machine driver operations
83701 */
83702 -static struct snd_soc_ops p1022_ds_ops = {
83703 +static const struct snd_soc_ops p1022_ds_ops = {
83704 .startup = p1022_ds_startup,
83705 };
83706
83707 diff -urNp linux-2.6.39.1/sound/soc/imx/eukrea-tlv320.c linux-2.6.39.1/sound/soc/imx/eukrea-tlv320.c
83708 --- linux-2.6.39.1/sound/soc/imx/eukrea-tlv320.c 2011-05-19 00:06:34.000000000 -0400
83709 +++ linux-2.6.39.1/sound/soc/imx/eukrea-tlv320.c 2011-05-22 19:36:35.000000000 -0400
83710 @@ -71,7 +71,7 @@ static int eukrea_tlv320_hw_params(struc
83711 return 0;
83712 }
83713
83714 -static struct snd_soc_ops eukrea_tlv320_snd_ops = {
83715 +static const struct snd_soc_ops eukrea_tlv320_snd_ops = {
83716 .hw_params = eukrea_tlv320_hw_params,
83717 };
83718
83719 diff -urNp linux-2.6.39.1/sound/soc/imx/imx-pcm-dma-mx2.c linux-2.6.39.1/sound/soc/imx/imx-pcm-dma-mx2.c
83720 --- linux-2.6.39.1/sound/soc/imx/imx-pcm-dma-mx2.c 2011-05-19 00:06:34.000000000 -0400
83721 +++ linux-2.6.39.1/sound/soc/imx/imx-pcm-dma-mx2.c 2011-05-22 19:36:35.000000000 -0400
83722 @@ -283,7 +283,7 @@ static int snd_imx_close(struct snd_pcm_
83723 return 0;
83724 }
83725
83726 -static struct snd_pcm_ops imx_pcm_ops = {
83727 +static const struct snd_pcm_ops imx_pcm_ops = {
83728 .open = snd_imx_open,
83729 .close = snd_imx_close,
83730 .ioctl = snd_pcm_lib_ioctl,
83731 diff -urNp linux-2.6.39.1/sound/soc/imx/imx-pcm-fiq.c linux-2.6.39.1/sound/soc/imx/imx-pcm-fiq.c
83732 --- linux-2.6.39.1/sound/soc/imx/imx-pcm-fiq.c 2011-05-19 00:06:34.000000000 -0400
83733 +++ linux-2.6.39.1/sound/soc/imx/imx-pcm-fiq.c 2011-05-22 19:36:35.000000000 -0400
83734 @@ -225,7 +225,7 @@ static int snd_imx_close(struct snd_pcm_
83735 return 0;
83736 }
83737
83738 -static struct snd_pcm_ops imx_pcm_ops = {
83739 +static const struct snd_pcm_ops imx_pcm_ops = {
83740 .open = snd_imx_open,
83741 .close = snd_imx_close,
83742 .ioctl = snd_pcm_lib_ioctl,
83743 diff -urNp linux-2.6.39.1/sound/soc/imx/mx27vis-aic32x4.c linux-2.6.39.1/sound/soc/imx/mx27vis-aic32x4.c
83744 --- linux-2.6.39.1/sound/soc/imx/mx27vis-aic32x4.c 2011-05-19 00:06:34.000000000 -0400
83745 +++ linux-2.6.39.1/sound/soc/imx/mx27vis-aic32x4.c 2011-05-22 19:36:35.000000000 -0400
83746 @@ -70,7 +70,7 @@ static int mx27vis_aic32x4_hw_params(str
83747 return 0;
83748 }
83749
83750 -static struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
83751 +static const struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
83752 .hw_params = mx27vis_aic32x4_hw_params,
83753 };
83754
83755 diff -urNp linux-2.6.39.1/sound/soc/imx/phycore-ac97.c linux-2.6.39.1/sound/soc/imx/phycore-ac97.c
83756 --- linux-2.6.39.1/sound/soc/imx/phycore-ac97.c 2011-05-19 00:06:34.000000000 -0400
83757 +++ linux-2.6.39.1/sound/soc/imx/phycore-ac97.c 2011-05-22 19:36:35.000000000 -0400
83758 @@ -21,7 +21,7 @@
83759
83760 static struct snd_soc_card imx_phycore;
83761
83762 -static struct snd_soc_ops imx_phycore_hifi_ops = {
83763 +static const struct snd_soc_ops imx_phycore_hifi_ops = {
83764 };
83765
83766 static struct snd_soc_dai_link imx_phycore_dai_ac97[] = {
83767 diff -urNp linux-2.6.39.1/sound/soc/imx/wm1133-ev1.c linux-2.6.39.1/sound/soc/imx/wm1133-ev1.c
83768 --- linux-2.6.39.1/sound/soc/imx/wm1133-ev1.c 2011-05-19 00:06:34.000000000 -0400
83769 +++ linux-2.6.39.1/sound/soc/imx/wm1133-ev1.c 2011-05-22 19:36:35.000000000 -0400
83770 @@ -149,7 +149,7 @@ static int wm1133_ev1_hw_params(struct s
83771 return 0;
83772 }
83773
83774 -static struct snd_soc_ops wm1133_ev1_ops = {
83775 +static const struct snd_soc_ops wm1133_ev1_ops = {
83776 .hw_params = wm1133_ev1_hw_params,
83777 };
83778
83779 diff -urNp linux-2.6.39.1/sound/soc/jz4740/jz4740-pcm.c linux-2.6.39.1/sound/soc/jz4740/jz4740-pcm.c
83780 --- linux-2.6.39.1/sound/soc/jz4740/jz4740-pcm.c 2011-05-19 00:06:34.000000000 -0400
83781 +++ linux-2.6.39.1/sound/soc/jz4740/jz4740-pcm.c 2011-05-22 19:36:35.000000000 -0400
83782 @@ -244,7 +244,7 @@ static int jz4740_pcm_mmap(struct snd_pc
83783 vma->vm_end - vma->vm_start, vma->vm_page_prot);
83784 }
83785
83786 -static struct snd_pcm_ops jz4740_pcm_ops = {
83787 +static const struct snd_pcm_ops jz4740_pcm_ops = {
83788 .open = jz4740_pcm_open,
83789 .close = jz4740_pcm_close,
83790 .ioctl = snd_pcm_lib_ioctl,
83791 diff -urNp linux-2.6.39.1/sound/soc/kirkwood/kirkwood-openrd.c linux-2.6.39.1/sound/soc/kirkwood/kirkwood-openrd.c
83792 --- linux-2.6.39.1/sound/soc/kirkwood/kirkwood-openrd.c 2011-05-19 00:06:34.000000000 -0400
83793 +++ linux-2.6.39.1/sound/soc/kirkwood/kirkwood-openrd.c 2011-05-22 19:36:35.000000000 -0400
83794 @@ -56,7 +56,7 @@ static int openrd_client_hw_params(struc
83795
83796 }
83797
83798 -static struct snd_soc_ops openrd_client_ops = {
83799 +static const struct snd_soc_ops openrd_client_ops = {
83800 .hw_params = openrd_client_hw_params,
83801 };
83802
83803 diff -urNp linux-2.6.39.1/sound/soc/kirkwood/kirkwood-t5325.c linux-2.6.39.1/sound/soc/kirkwood/kirkwood-t5325.c
83804 --- linux-2.6.39.1/sound/soc/kirkwood/kirkwood-t5325.c 2011-05-19 00:06:34.000000000 -0400
83805 +++ linux-2.6.39.1/sound/soc/kirkwood/kirkwood-t5325.c 2011-05-22 19:36:35.000000000 -0400
83806 @@ -44,7 +44,7 @@ static int t5325_hw_params(struct snd_pc
83807
83808 }
83809
83810 -static struct snd_soc_ops t5325_ops = {
83811 +static const struct snd_soc_ops t5325_ops = {
83812 .hw_params = t5325_hw_params,
83813 };
83814
83815 diff -urNp linux-2.6.39.1/sound/soc/mid-x86/sst_platform.c linux-2.6.39.1/sound/soc/mid-x86/sst_platform.c
83816 --- linux-2.6.39.1/sound/soc/mid-x86/sst_platform.c 2011-05-19 00:06:34.000000000 -0400
83817 +++ linux-2.6.39.1/sound/soc/mid-x86/sst_platform.c 2011-05-22 19:36:35.000000000 -0400
83818 @@ -381,7 +381,7 @@ static int sst_platform_pcm_hw_free(stru
83819 return snd_pcm_lib_free_pages(substream);
83820 }
83821
83822 -static struct snd_pcm_ops sst_platform_ops = {
83823 +static const struct snd_pcm_ops sst_platform_ops = {
83824 .open = sst_platform_open,
83825 .close = sst_platform_close,
83826 .ioctl = snd_pcm_lib_ioctl,
83827 diff -urNp linux-2.6.39.1/sound/soc/nuc900/nuc900-pcm.c linux-2.6.39.1/sound/soc/nuc900/nuc900-pcm.c
83828 --- linux-2.6.39.1/sound/soc/nuc900/nuc900-pcm.c 2011-05-19 00:06:34.000000000 -0400
83829 +++ linux-2.6.39.1/sound/soc/nuc900/nuc900-pcm.c 2011-05-22 19:36:35.000000000 -0400
83830 @@ -297,7 +297,7 @@ static int nuc900_dma_mmap(struct snd_pc
83831 runtime->dma_bytes);
83832 }
83833
83834 -static struct snd_pcm_ops nuc900_dma_ops = {
83835 +static const struct snd_pcm_ops nuc900_dma_ops = {
83836 .open = nuc900_dma_open,
83837 .close = nuc900_dma_close,
83838 .ioctl = snd_pcm_lib_ioctl,
83839 diff -urNp linux-2.6.39.1/sound/soc/omap/am3517evm.c linux-2.6.39.1/sound/soc/omap/am3517evm.c
83840 --- linux-2.6.39.1/sound/soc/omap/am3517evm.c 2011-05-19 00:06:34.000000000 -0400
83841 +++ linux-2.6.39.1/sound/soc/omap/am3517evm.c 2011-05-22 19:36:35.000000000 -0400
83842 @@ -88,7 +88,7 @@ static int am3517evm_hw_params(struct sn
83843 return 0;
83844 }
83845
83846 -static struct snd_soc_ops am3517evm_ops = {
83847 +static const struct snd_soc_ops am3517evm_ops = {
83848 .hw_params = am3517evm_hw_params,
83849 };
83850
83851 diff -urNp linux-2.6.39.1/sound/soc/omap/ams-delta.c linux-2.6.39.1/sound/soc/omap/ams-delta.c
83852 --- linux-2.6.39.1/sound/soc/omap/ams-delta.c 2011-05-19 00:06:34.000000000 -0400
83853 +++ linux-2.6.39.1/sound/soc/omap/ams-delta.c 2011-05-22 19:36:35.000000000 -0400
83854 @@ -420,7 +420,7 @@ static int ams_delta_hw_params(struct sn
83855 SND_SOC_DAIFMT_CBM_CFM);
83856 }
83857
83858 -static struct snd_soc_ops ams_delta_ops = {
83859 +static const struct snd_soc_ops ams_delta_ops = {
83860 .hw_params = ams_delta_hw_params,
83861 };
83862
83863 diff -urNp linux-2.6.39.1/sound/soc/omap/igep0020.c linux-2.6.39.1/sound/soc/omap/igep0020.c
83864 --- linux-2.6.39.1/sound/soc/omap/igep0020.c 2011-05-19 00:06:34.000000000 -0400
83865 +++ linux-2.6.39.1/sound/soc/omap/igep0020.c 2011-05-22 19:36:35.000000000 -0400
83866 @@ -72,7 +72,7 @@ static int igep2_hw_params(struct snd_pc
83867 return 0;
83868 }
83869
83870 -static struct snd_soc_ops igep2_ops = {
83871 +static const struct snd_soc_ops igep2_ops = {
83872 .hw_params = igep2_hw_params,
83873 };
83874
83875 diff -urNp linux-2.6.39.1/sound/soc/omap/n810.c linux-2.6.39.1/sound/soc/omap/n810.c
83876 --- linux-2.6.39.1/sound/soc/omap/n810.c 2011-05-19 00:06:34.000000000 -0400
83877 +++ linux-2.6.39.1/sound/soc/omap/n810.c 2011-05-22 19:36:35.000000000 -0400
83878 @@ -141,7 +141,7 @@ static int n810_hw_params(struct snd_pcm
83879 return err;
83880 }
83881
83882 -static struct snd_soc_ops n810_ops = {
83883 +static const struct snd_soc_ops n810_ops = {
83884 .startup = n810_startup,
83885 .hw_params = n810_hw_params,
83886 .shutdown = n810_shutdown,
83887 diff -urNp linux-2.6.39.1/sound/soc/omap/omap2evm.c linux-2.6.39.1/sound/soc/omap/omap2evm.c
83888 --- linux-2.6.39.1/sound/soc/omap/omap2evm.c 2011-05-19 00:06:34.000000000 -0400
83889 +++ linux-2.6.39.1/sound/soc/omap/omap2evm.c 2011-05-22 19:36:35.000000000 -0400
83890 @@ -74,7 +74,7 @@ static int omap2evm_hw_params(struct snd
83891 return 0;
83892 }
83893
83894 -static struct snd_soc_ops omap2evm_ops = {
83895 +static const struct snd_soc_ops omap2evm_ops = {
83896 .hw_params = omap2evm_hw_params,
83897 };
83898
83899 diff -urNp linux-2.6.39.1/sound/soc/omap/omap3beagle.c linux-2.6.39.1/sound/soc/omap/omap3beagle.c
83900 --- linux-2.6.39.1/sound/soc/omap/omap3beagle.c 2011-05-19 00:06:34.000000000 -0400
83901 +++ linux-2.6.39.1/sound/soc/omap/omap3beagle.c 2011-05-22 19:36:35.000000000 -0400
83902 @@ -82,7 +82,7 @@ static int omap3beagle_hw_params(struct
83903 return 0;
83904 }
83905
83906 -static struct snd_soc_ops omap3beagle_ops = {
83907 +static const struct snd_soc_ops omap3beagle_ops = {
83908 .hw_params = omap3beagle_hw_params,
83909 };
83910
83911 diff -urNp linux-2.6.39.1/sound/soc/omap/omap3evm.c linux-2.6.39.1/sound/soc/omap/omap3evm.c
83912 --- linux-2.6.39.1/sound/soc/omap/omap3evm.c 2011-05-19 00:06:34.000000000 -0400
83913 +++ linux-2.6.39.1/sound/soc/omap/omap3evm.c 2011-05-22 19:36:35.000000000 -0400
83914 @@ -70,7 +70,7 @@ static int omap3evm_hw_params(struct snd
83915 return 0;
83916 }
83917
83918 -static struct snd_soc_ops omap3evm_ops = {
83919 +static const struct snd_soc_ops omap3evm_ops = {
83920 .hw_params = omap3evm_hw_params,
83921 };
83922
83923 diff -urNp linux-2.6.39.1/sound/soc/omap/omap3pandora.c linux-2.6.39.1/sound/soc/omap/omap3pandora.c
83924 --- linux-2.6.39.1/sound/soc/omap/omap3pandora.c 2011-05-19 00:06:34.000000000 -0400
83925 +++ linux-2.6.39.1/sound/soc/omap/omap3pandora.c 2011-05-22 19:36:35.000000000 -0400
83926 @@ -218,7 +218,7 @@ static int omap3pandora_in_init(struct s
83927 return snd_soc_dapm_sync(dapm);
83928 }
83929
83930 -static struct snd_soc_ops omap3pandora_ops = {
83931 +static const struct snd_soc_ops omap3pandora_ops = {
83932 .hw_params = omap3pandora_hw_params,
83933 };
83934
83935 diff -urNp linux-2.6.39.1/sound/soc/omap/omap-pcm.c linux-2.6.39.1/sound/soc/omap/omap-pcm.c
83936 --- linux-2.6.39.1/sound/soc/omap/omap-pcm.c 2011-05-19 00:06:34.000000000 -0400
83937 +++ linux-2.6.39.1/sound/soc/omap/omap-pcm.c 2011-05-22 19:36:35.000000000 -0400
83938 @@ -311,7 +311,7 @@ static int omap_pcm_mmap(struct snd_pcm_
83939 runtime->dma_bytes);
83940 }
83941
83942 -static struct snd_pcm_ops omap_pcm_ops = {
83943 +static const struct snd_pcm_ops omap_pcm_ops = {
83944 .open = omap_pcm_open,
83945 .close = omap_pcm_close,
83946 .ioctl = snd_pcm_lib_ioctl,
83947 diff -urNp linux-2.6.39.1/sound/soc/omap/osk5912.c linux-2.6.39.1/sound/soc/omap/osk5912.c
83948 --- linux-2.6.39.1/sound/soc/omap/osk5912.c 2011-05-19 00:06:34.000000000 -0400
83949 +++ linux-2.6.39.1/sound/soc/omap/osk5912.c 2011-05-22 19:36:35.000000000 -0400
83950 @@ -90,7 +90,7 @@ static int osk_hw_params(struct snd_pcm_
83951 return err;
83952 }
83953
83954 -static struct snd_soc_ops osk_ops = {
83955 +static const struct snd_soc_ops osk_ops = {
83956 .startup = osk_startup,
83957 .hw_params = osk_hw_params,
83958 .shutdown = osk_shutdown,
83959 diff -urNp linux-2.6.39.1/sound/soc/omap/overo.c linux-2.6.39.1/sound/soc/omap/overo.c
83960 --- linux-2.6.39.1/sound/soc/omap/overo.c 2011-05-19 00:06:34.000000000 -0400
83961 +++ linux-2.6.39.1/sound/soc/omap/overo.c 2011-05-22 19:36:35.000000000 -0400
83962 @@ -72,7 +72,7 @@ static int overo_hw_params(struct snd_pc
83963 return 0;
83964 }
83965
83966 -static struct snd_soc_ops overo_ops = {
83967 +static const struct snd_soc_ops overo_ops = {
83968 .hw_params = overo_hw_params,
83969 };
83970
83971 diff -urNp linux-2.6.39.1/sound/soc/omap/rx51.c linux-2.6.39.1/sound/soc/omap/rx51.c
83972 --- linux-2.6.39.1/sound/soc/omap/rx51.c 2011-05-19 00:06:34.000000000 -0400
83973 +++ linux-2.6.39.1/sound/soc/omap/rx51.c 2011-05-22 19:36:35.000000000 -0400
83974 @@ -139,7 +139,7 @@ static int rx51_hw_params(struct snd_pcm
83975 SND_SOC_CLOCK_IN);
83976 }
83977
83978 -static struct snd_soc_ops rx51_ops = {
83979 +static const struct snd_soc_ops rx51_ops = {
83980 .startup = rx51_startup,
83981 .hw_params = rx51_hw_params,
83982 };
83983 diff -urNp linux-2.6.39.1/sound/soc/omap/sdp3430.c linux-2.6.39.1/sound/soc/omap/sdp3430.c
83984 --- linux-2.6.39.1/sound/soc/omap/sdp3430.c 2011-05-19 00:06:34.000000000 -0400
83985 +++ linux-2.6.39.1/sound/soc/omap/sdp3430.c 2011-05-22 19:36:35.000000000 -0400
83986 @@ -87,7 +87,7 @@ static int sdp3430_hw_params(struct snd_
83987 return 0;
83988 }
83989
83990 -static struct snd_soc_ops sdp3430_ops = {
83991 +static const struct snd_soc_ops sdp3430_ops = {
83992 .hw_params = sdp3430_hw_params,
83993 };
83994
83995 @@ -130,7 +130,7 @@ static int sdp3430_hw_voice_params(struc
83996 return 0;
83997 }
83998
83999 -static struct snd_soc_ops sdp3430_voice_ops = {
84000 +static const struct snd_soc_ops sdp3430_voice_ops = {
84001 .hw_params = sdp3430_hw_voice_params,
84002 };
84003
84004 diff -urNp linux-2.6.39.1/sound/soc/omap/sdp4430.c linux-2.6.39.1/sound/soc/omap/sdp4430.c
84005 --- linux-2.6.39.1/sound/soc/omap/sdp4430.c 2011-05-19 00:06:34.000000000 -0400
84006 +++ linux-2.6.39.1/sound/soc/omap/sdp4430.c 2011-05-22 19:36:35.000000000 -0400
84007 @@ -62,7 +62,7 @@ static int sdp4430_hw_params(struct snd_
84008 return ret;
84009 }
84010
84011 -static struct snd_soc_ops sdp4430_ops = {
84012 +static const struct snd_soc_ops sdp4430_ops = {
84013 .hw_params = sdp4430_hw_params,
84014 };
84015
84016 diff -urNp linux-2.6.39.1/sound/soc/omap/zoom2.c linux-2.6.39.1/sound/soc/omap/zoom2.c
84017 --- linux-2.6.39.1/sound/soc/omap/zoom2.c 2011-05-19 00:06:34.000000000 -0400
84018 +++ linux-2.6.39.1/sound/soc/omap/zoom2.c 2011-05-22 19:36:35.000000000 -0400
84019 @@ -78,7 +78,7 @@ static int zoom2_hw_params(struct snd_pc
84020 return 0;
84021 }
84022
84023 -static struct snd_soc_ops zoom2_ops = {
84024 +static const struct snd_soc_ops zoom2_ops = {
84025 .hw_params = zoom2_hw_params,
84026 };
84027
84028 @@ -121,7 +121,7 @@ static int zoom2_hw_voice_params(struct
84029 return 0;
84030 }
84031
84032 -static struct snd_soc_ops zoom2_voice_ops = {
84033 +static const struct snd_soc_ops zoom2_voice_ops = {
84034 .hw_params = zoom2_hw_voice_params,
84035 };
84036
84037 diff -urNp linux-2.6.39.1/sound/soc/pxa/corgi.c linux-2.6.39.1/sound/soc/pxa/corgi.c
84038 --- linux-2.6.39.1/sound/soc/pxa/corgi.c 2011-05-19 00:06:34.000000000 -0400
84039 +++ linux-2.6.39.1/sound/soc/pxa/corgi.c 2011-05-22 19:36:35.000000000 -0400
84040 @@ -169,7 +169,7 @@ static int corgi_hw_params(struct snd_pc
84041 return 0;
84042 }
84043
84044 -static struct snd_soc_ops corgi_ops = {
84045 +static const struct snd_soc_ops corgi_ops = {
84046 .startup = corgi_startup,
84047 .hw_params = corgi_hw_params,
84048 .shutdown = corgi_shutdown,
84049 diff -urNp linux-2.6.39.1/sound/soc/pxa/imote2.c linux-2.6.39.1/sound/soc/pxa/imote2.c
84050 --- linux-2.6.39.1/sound/soc/pxa/imote2.c 2011-05-19 00:06:34.000000000 -0400
84051 +++ linux-2.6.39.1/sound/soc/pxa/imote2.c 2011-05-22 19:36:35.000000000 -0400
84052 @@ -56,7 +56,7 @@ static int imote2_asoc_hw_params(struct
84053 return ret;
84054 }
84055
84056 -static struct snd_soc_ops imote2_asoc_ops = {
84057 +static const struct snd_soc_ops imote2_asoc_ops = {
84058 .hw_params = imote2_asoc_hw_params,
84059 };
84060
84061 diff -urNp linux-2.6.39.1/sound/soc/pxa/magician.c linux-2.6.39.1/sound/soc/pxa/magician.c
84062 --- linux-2.6.39.1/sound/soc/pxa/magician.c 2011-05-19 00:06:34.000000000 -0400
84063 +++ linux-2.6.39.1/sound/soc/pxa/magician.c 2011-05-22 19:36:35.000000000 -0400
84064 @@ -258,12 +258,12 @@ static int magician_capture_hw_params(st
84065 return 0;
84066 }
84067
84068 -static struct snd_soc_ops magician_capture_ops = {
84069 +static const struct snd_soc_ops magician_capture_ops = {
84070 .startup = magician_startup,
84071 .hw_params = magician_capture_hw_params,
84072 };
84073
84074 -static struct snd_soc_ops magician_playback_ops = {
84075 +static const struct snd_soc_ops magician_playback_ops = {
84076 .startup = magician_startup,
84077 .hw_params = magician_playback_hw_params,
84078 };
84079 diff -urNp linux-2.6.39.1/sound/soc/pxa/mioa701_wm9713.c linux-2.6.39.1/sound/soc/pxa/mioa701_wm9713.c
84080 --- linux-2.6.39.1/sound/soc/pxa/mioa701_wm9713.c 2011-05-19 00:06:34.000000000 -0400
84081 +++ linux-2.6.39.1/sound/soc/pxa/mioa701_wm9713.c 2011-05-22 19:36:35.000000000 -0400
84082 @@ -156,7 +156,7 @@ static int mioa701_wm9713_init(struct sn
84083 return 0;
84084 }
84085
84086 -static struct snd_soc_ops mioa701_ops;
84087 +static const struct snd_soc_ops mioa701_ops;
84088
84089 static struct snd_soc_dai_link mioa701_dai[] = {
84090 {
84091 diff -urNp linux-2.6.39.1/sound/soc/pxa/poodle.c linux-2.6.39.1/sound/soc/pxa/poodle.c
84092 --- linux-2.6.39.1/sound/soc/pxa/poodle.c 2011-05-19 00:06:34.000000000 -0400
84093 +++ linux-2.6.39.1/sound/soc/pxa/poodle.c 2011-05-22 19:36:35.000000000 -0400
84094 @@ -148,7 +148,7 @@ static int poodle_hw_params(struct snd_p
84095 return 0;
84096 }
84097
84098 -static struct snd_soc_ops poodle_ops = {
84099 +static const struct snd_soc_ops poodle_ops = {
84100 .startup = poodle_startup,
84101 .hw_params = poodle_hw_params,
84102 .shutdown = poodle_shutdown,
84103 diff -urNp linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.c linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.c
84104 --- linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
84105 +++ linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
84106 @@ -40,7 +40,7 @@ static void pxa2xx_ac97_cold_reset(struc
84107 pxa2xx_ac97_finish_reset(ac97);
84108 }
84109
84110 -struct snd_ac97_bus_ops soc_ac97_ops = {
84111 +const struct snd_ac97_bus_ops soc_ac97_ops = {
84112 .read = pxa2xx_ac97_read,
84113 .write = pxa2xx_ac97_write,
84114 .warm_reset = pxa2xx_ac97_warm_reset,
84115 diff -urNp linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.h linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.h
84116 --- linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.h 2011-05-19 00:06:34.000000000 -0400
84117 +++ linux-2.6.39.1/sound/soc/pxa/pxa2xx-ac97.h 2011-05-22 19:36:35.000000000 -0400
84118 @@ -15,6 +15,6 @@
84119 #define PXA2XX_DAI_AC97_MIC 2
84120
84121 /* platform data */
84122 -extern struct snd_ac97_bus_ops pxa2xx_ac97_ops;
84123 +extern const struct snd_ac97_bus_ops pxa2xx_ac97_ops;
84124
84125 #endif
84126 diff -urNp linux-2.6.39.1/sound/soc/pxa/raumfeld.c linux-2.6.39.1/sound/soc/pxa/raumfeld.c
84127 --- linux-2.6.39.1/sound/soc/pxa/raumfeld.c 2011-06-03 00:04:14.000000000 -0400
84128 +++ linux-2.6.39.1/sound/soc/pxa/raumfeld.c 2011-06-03 00:32:09.000000000 -0400
84129 @@ -145,7 +145,7 @@ static int raumfeld_cs4270_hw_params(str
84130 return 0;
84131 }
84132
84133 -static struct snd_soc_ops raumfeld_cs4270_ops = {
84134 +static const struct snd_soc_ops raumfeld_cs4270_ops = {
84135 .startup = raumfeld_cs4270_startup,
84136 .shutdown = raumfeld_cs4270_shutdown,
84137 .hw_params = raumfeld_cs4270_hw_params,
84138 @@ -221,7 +221,7 @@ static int raumfeld_ak4104_hw_params(str
84139 return 0;
84140 }
84141
84142 -static struct snd_soc_ops raumfeld_ak4104_ops = {
84143 +static const struct snd_soc_ops raumfeld_ak4104_ops = {
84144 .hw_params = raumfeld_ak4104_hw_params,
84145 };
84146
84147 diff -urNp linux-2.6.39.1/sound/soc/pxa/saarb.c linux-2.6.39.1/sound/soc/pxa/saarb.c
84148 --- linux-2.6.39.1/sound/soc/pxa/saarb.c 2011-05-19 00:06:34.000000000 -0400
84149 +++ linux-2.6.39.1/sound/soc/pxa/saarb.c 2011-05-22 19:36:35.000000000 -0400
84150 @@ -106,7 +106,7 @@ static int saarb_i2s_hw_params(struct sn
84151 return ret;
84152 }
84153
84154 -static struct snd_soc_ops saarb_i2s_ops = {
84155 +static const struct snd_soc_ops saarb_i2s_ops = {
84156 .hw_params = saarb_i2s_hw_params,
84157 };
84158
84159 diff -urNp linux-2.6.39.1/sound/soc/pxa/spitz.c linux-2.6.39.1/sound/soc/pxa/spitz.c
84160 --- linux-2.6.39.1/sound/soc/pxa/spitz.c 2011-05-19 00:06:34.000000000 -0400
84161 +++ linux-2.6.39.1/sound/soc/pxa/spitz.c 2011-05-22 19:36:35.000000000 -0400
84162 @@ -169,7 +169,7 @@ static int spitz_hw_params(struct snd_pc
84163 return 0;
84164 }
84165
84166 -static struct snd_soc_ops spitz_ops = {
84167 +static const struct snd_soc_ops spitz_ops = {
84168 .startup = spitz_startup,
84169 .hw_params = spitz_hw_params,
84170 };
84171 diff -urNp linux-2.6.39.1/sound/soc/pxa/tavorevb3.c linux-2.6.39.1/sound/soc/pxa/tavorevb3.c
84172 --- linux-2.6.39.1/sound/soc/pxa/tavorevb3.c 2011-05-19 00:06:34.000000000 -0400
84173 +++ linux-2.6.39.1/sound/soc/pxa/tavorevb3.c 2011-05-22 19:36:35.000000000 -0400
84174 @@ -106,7 +106,7 @@ static int evb3_i2s_hw_params(struct snd
84175 return ret;
84176 }
84177
84178 -static struct snd_soc_ops evb3_i2s_ops = {
84179 +static const struct snd_soc_ops evb3_i2s_ops = {
84180 .hw_params = evb3_i2s_hw_params,
84181 };
84182
84183 diff -urNp linux-2.6.39.1/sound/soc/pxa/tosa.c linux-2.6.39.1/sound/soc/pxa/tosa.c
84184 --- linux-2.6.39.1/sound/soc/pxa/tosa.c 2011-05-19 00:06:34.000000000 -0400
84185 +++ linux-2.6.39.1/sound/soc/pxa/tosa.c 2011-05-22 19:36:35.000000000 -0400
84186 @@ -92,7 +92,7 @@ static int tosa_startup(struct snd_pcm_s
84187 return 0;
84188 }
84189
84190 -static struct snd_soc_ops tosa_ops = {
84191 +static const struct snd_soc_ops tosa_ops = {
84192 .startup = tosa_startup,
84193 };
84194
84195 diff -urNp linux-2.6.39.1/sound/soc/pxa/z2.c linux-2.6.39.1/sound/soc/pxa/z2.c
84196 --- linux-2.6.39.1/sound/soc/pxa/z2.c 2011-05-19 00:06:34.000000000 -0400
84197 +++ linux-2.6.39.1/sound/soc/pxa/z2.c 2011-05-22 19:36:35.000000000 -0400
84198 @@ -187,7 +187,7 @@ err:
84199 return ret;
84200 }
84201
84202 -static struct snd_soc_ops z2_ops = {
84203 +static const struct snd_soc_ops z2_ops = {
84204 .hw_params = z2_hw_params,
84205 };
84206
84207 diff -urNp linux-2.6.39.1/sound/soc/pxa/zylonite.c linux-2.6.39.1/sound/soc/pxa/zylonite.c
84208 --- linux-2.6.39.1/sound/soc/pxa/zylonite.c 2011-05-19 00:06:34.000000000 -0400
84209 +++ linux-2.6.39.1/sound/soc/pxa/zylonite.c 2011-05-22 19:36:35.000000000 -0400
84210 @@ -156,7 +156,7 @@ static int zylonite_voice_hw_params(stru
84211 return 0;
84212 }
84213
84214 -static struct snd_soc_ops zylonite_voice_ops = {
84215 +static const struct snd_soc_ops zylonite_voice_ops = {
84216 .hw_params = zylonite_voice_hw_params,
84217 };
84218
84219 diff -urNp linux-2.6.39.1/sound/soc/s6000/s6000-pcm.c linux-2.6.39.1/sound/soc/s6000/s6000-pcm.c
84220 --- linux-2.6.39.1/sound/soc/s6000/s6000-pcm.c 2011-05-19 00:06:34.000000000 -0400
84221 +++ linux-2.6.39.1/sound/soc/s6000/s6000-pcm.c 2011-05-22 19:36:35.000000000 -0400
84222 @@ -420,7 +420,7 @@ static int s6000_pcm_hw_free(struct snd_
84223 return snd_pcm_lib_free_pages(substream);
84224 }
84225
84226 -static struct snd_pcm_ops s6000_pcm_ops = {
84227 +static const struct snd_pcm_ops s6000_pcm_ops = {
84228 .open = s6000_pcm_open,
84229 .close = s6000_pcm_close,
84230 .ioctl = snd_pcm_lib_ioctl,
84231 diff -urNp linux-2.6.39.1/sound/soc/s6000/s6105-ipcam.c linux-2.6.39.1/sound/soc/s6000/s6105-ipcam.c
84232 --- linux-2.6.39.1/sound/soc/s6000/s6105-ipcam.c 2011-05-19 00:06:34.000000000 -0400
84233 +++ linux-2.6.39.1/sound/soc/s6000/s6105-ipcam.c 2011-05-22 19:36:35.000000000 -0400
84234 @@ -55,7 +55,7 @@ static int s6105_hw_params(struct snd_pc
84235 return 0;
84236 }
84237
84238 -static struct snd_soc_ops s6105_ops = {
84239 +static const struct snd_soc_ops s6105_ops = {
84240 .hw_params = s6105_hw_params,
84241 };
84242
84243 diff -urNp linux-2.6.39.1/sound/soc/samsung/goni_wm8994.c linux-2.6.39.1/sound/soc/samsung/goni_wm8994.c
84244 --- linux-2.6.39.1/sound/soc/samsung/goni_wm8994.c 2011-05-19 00:06:34.000000000 -0400
84245 +++ linux-2.6.39.1/sound/soc/samsung/goni_wm8994.c 2011-05-22 19:36:35.000000000 -0400
84246 @@ -176,7 +176,7 @@ static int goni_hifi_hw_params(struct sn
84247 return 0;
84248 }
84249
84250 -static struct snd_soc_ops goni_hifi_ops = {
84251 +static const struct snd_soc_ops goni_hifi_ops = {
84252 .hw_params = goni_hifi_hw_params,
84253 };
84254
84255 @@ -227,7 +227,7 @@ static struct snd_soc_dai_driver voice_d
84256 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
84257 };
84258
84259 -static struct snd_soc_ops goni_voice_ops = {
84260 +static const struct snd_soc_ops goni_voice_ops = {
84261 .hw_params = goni_voice_hw_params,
84262 };
84263
84264 diff -urNp linux-2.6.39.1/sound/soc/samsung/h1940_uda1380.c linux-2.6.39.1/sound/soc/samsung/h1940_uda1380.c
84265 --- linux-2.6.39.1/sound/soc/samsung/h1940_uda1380.c 2011-05-19 00:06:34.000000000 -0400
84266 +++ linux-2.6.39.1/sound/soc/samsung/h1940_uda1380.c 2011-05-22 19:36:35.000000000 -0400
84267 @@ -136,7 +136,7 @@ static int h1940_hw_params(struct snd_pc
84268 return 0;
84269 }
84270
84271 -static struct snd_soc_ops h1940_ops = {
84272 +static const struct snd_soc_ops h1940_ops = {
84273 .startup = h1940_startup,
84274 .hw_params = h1940_hw_params,
84275 };
84276 diff -urNp linux-2.6.39.1/sound/soc/samsung/jive_wm8750.c linux-2.6.39.1/sound/soc/samsung/jive_wm8750.c
84277 --- linux-2.6.39.1/sound/soc/samsung/jive_wm8750.c 2011-05-19 00:06:34.000000000 -0400
84278 +++ linux-2.6.39.1/sound/soc/samsung/jive_wm8750.c 2011-05-22 19:36:35.000000000 -0400
84279 @@ -92,7 +92,7 @@ static int jive_hw_params(struct snd_pcm
84280 return 0;
84281 }
84282
84283 -static struct snd_soc_ops jive_ops = {
84284 +static const struct snd_soc_ops jive_ops = {
84285 .hw_params = jive_hw_params,
84286 };
84287
84288 diff -urNp linux-2.6.39.1/sound/soc/samsung/neo1973_wm8753.c linux-2.6.39.1/sound/soc/samsung/neo1973_wm8753.c
84289 --- linux-2.6.39.1/sound/soc/samsung/neo1973_wm8753.c 2011-05-19 00:06:34.000000000 -0400
84290 +++ linux-2.6.39.1/sound/soc/samsung/neo1973_wm8753.c 2011-05-22 19:36:35.000000000 -0400
84291 @@ -128,7 +128,7 @@ static int neo1973_hifi_hw_free(struct s
84292 /*
84293 * Neo1973 WM8753 HiFi DAI opserations.
84294 */
84295 -static struct snd_soc_ops neo1973_hifi_ops = {
84296 +static const struct snd_soc_ops neo1973_hifi_ops = {
84297 .hw_params = neo1973_hifi_hw_params,
84298 .hw_free = neo1973_hifi_hw_free,
84299 };
84300 @@ -187,7 +187,7 @@ static int neo1973_voice_hw_free(struct
84301 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
84302 }
84303
84304 -static struct snd_soc_ops neo1973_voice_ops = {
84305 +static const struct snd_soc_ops neo1973_voice_ops = {
84306 .hw_params = neo1973_voice_hw_params,
84307 .hw_free = neo1973_voice_hw_free,
84308 };
84309 diff -urNp linux-2.6.39.1/sound/soc/samsung/rx1950_uda1380.c linux-2.6.39.1/sound/soc/samsung/rx1950_uda1380.c
84310 --- linux-2.6.39.1/sound/soc/samsung/rx1950_uda1380.c 2011-05-19 00:06:34.000000000 -0400
84311 +++ linux-2.6.39.1/sound/soc/samsung/rx1950_uda1380.c 2011-05-22 19:36:35.000000000 -0400
84312 @@ -70,7 +70,7 @@ static struct snd_soc_jack_gpio hp_jack_
84313 },
84314 };
84315
84316 -static struct snd_soc_ops rx1950_ops = {
84317 +static const struct snd_soc_ops rx1950_ops = {
84318 .startup = rx1950_startup,
84319 .hw_params = rx1950_hw_params,
84320 };
84321 diff -urNp linux-2.6.39.1/sound/soc/samsung/s3c24xx_simtec.c linux-2.6.39.1/sound/soc/samsung/s3c24xx_simtec.c
84322 --- linux-2.6.39.1/sound/soc/samsung/s3c24xx_simtec.c 2011-05-19 00:06:34.000000000 -0400
84323 +++ linux-2.6.39.1/sound/soc/samsung/s3c24xx_simtec.c 2011-05-22 19:36:35.000000000 -0400
84324 @@ -228,7 +228,7 @@ static int simtec_call_startup(struct s3
84325 return 0;
84326 }
84327
84328 -static struct snd_soc_ops simtec_snd_ops = {
84329 +static const struct snd_soc_ops simtec_snd_ops = {
84330 .hw_params = simtec_hw_params,
84331 };
84332
84333 diff -urNp linux-2.6.39.1/sound/soc/samsung/s3c24xx_uda134x.c linux-2.6.39.1/sound/soc/samsung/s3c24xx_uda134x.c
84334 --- linux-2.6.39.1/sound/soc/samsung/s3c24xx_uda134x.c 2011-05-19 00:06:34.000000000 -0400
84335 +++ linux-2.6.39.1/sound/soc/samsung/s3c24xx_uda134x.c 2011-05-22 19:36:35.000000000 -0400
84336 @@ -210,7 +210,7 @@ static int s3c24xx_uda134x_hw_params(str
84337 return 0;
84338 }
84339
84340 -static struct snd_soc_ops s3c24xx_uda134x_ops = {
84341 +static const struct snd_soc_ops s3c24xx_uda134x_ops = {
84342 .startup = s3c24xx_uda134x_startup,
84343 .shutdown = s3c24xx_uda134x_shutdown,
84344 .hw_params = s3c24xx_uda134x_hw_params,
84345 diff -urNp linux-2.6.39.1/sound/soc/samsung/smartq_wm8987.c linux-2.6.39.1/sound/soc/samsung/smartq_wm8987.c
84346 --- linux-2.6.39.1/sound/soc/samsung/smartq_wm8987.c 2011-05-19 00:06:34.000000000 -0400
84347 +++ linux-2.6.39.1/sound/soc/samsung/smartq_wm8987.c 2011-05-22 19:36:35.000000000 -0400
84348 @@ -92,7 +92,7 @@ static int smartq_hifi_hw_params(struct
84349 /*
84350 * SmartQ WM8987 HiFi DAI operations.
84351 */
84352 -static struct snd_soc_ops smartq_hifi_ops = {
84353 +static const struct snd_soc_ops smartq_hifi_ops = {
84354 .hw_params = smartq_hifi_hw_params,
84355 };
84356
84357 diff -urNp linux-2.6.39.1/sound/soc/samsung/smdk_spdif.c linux-2.6.39.1/sound/soc/samsung/smdk_spdif.c
84358 --- linux-2.6.39.1/sound/soc/samsung/smdk_spdif.c 2011-05-19 00:06:34.000000000 -0400
84359 +++ linux-2.6.39.1/sound/soc/samsung/smdk_spdif.c 2011-05-22 19:36:35.000000000 -0400
84360 @@ -143,7 +143,7 @@ static int smdk_hw_params(struct snd_pcm
84361 return ret;
84362 }
84363
84364 -static struct snd_soc_ops smdk_spdif_ops = {
84365 +static const struct snd_soc_ops smdk_spdif_ops = {
84366 .hw_params = smdk_hw_params,
84367 };
84368
84369 diff -urNp linux-2.6.39.1/sound/soc/samsung/smdk_wm8580.c linux-2.6.39.1/sound/soc/samsung/smdk_wm8580.c
84370 --- linux-2.6.39.1/sound/soc/samsung/smdk_wm8580.c 2011-05-19 00:06:34.000000000 -0400
84371 +++ linux-2.6.39.1/sound/soc/samsung/smdk_wm8580.c 2011-05-22 19:36:35.000000000 -0400
84372 @@ -114,7 +114,7 @@ static int smdk_hw_params(struct snd_pcm
84373 /*
84374 * SMDK WM8580 DAI operations.
84375 */
84376 -static struct snd_soc_ops smdk_ops = {
84377 +static const struct snd_soc_ops smdk_ops = {
84378 .hw_params = smdk_hw_params,
84379 };
84380
84381 diff -urNp linux-2.6.39.1/sound/soc/sh/dma-sh7760.c linux-2.6.39.1/sound/soc/sh/dma-sh7760.c
84382 --- linux-2.6.39.1/sound/soc/sh/dma-sh7760.c 2011-05-19 00:06:34.000000000 -0400
84383 +++ linux-2.6.39.1/sound/soc/sh/dma-sh7760.c 2011-05-22 19:36:35.000000000 -0400
84384 @@ -311,7 +311,7 @@ static snd_pcm_uframes_t camelot_pos(str
84385 return bytes_to_frames(runtime, pos);
84386 }
84387
84388 -static struct snd_pcm_ops camelot_pcm_ops = {
84389 +static const struct snd_pcm_ops camelot_pcm_ops = {
84390 .open = camelot_pcm_open,
84391 .close = camelot_pcm_close,
84392 .ioctl = snd_pcm_lib_ioctl,
84393 diff -urNp linux-2.6.39.1/sound/soc/sh/hac.c linux-2.6.39.1/sound/soc/sh/hac.c
84394 --- linux-2.6.39.1/sound/soc/sh/hac.c 2011-05-19 00:06:34.000000000 -0400
84395 +++ linux-2.6.39.1/sound/soc/sh/hac.c 2011-05-22 19:36:35.000000000 -0400
84396 @@ -227,7 +227,7 @@ static void hac_ac97_coldrst(struct snd_
84397 hac_ac97_warmrst(ac97);
84398 }
84399
84400 -struct snd_ac97_bus_ops soc_ac97_ops = {
84401 +const struct snd_ac97_bus_ops soc_ac97_ops = {
84402 .read = hac_ac97_read,
84403 .write = hac_ac97_write,
84404 .reset = hac_ac97_coldrst,
84405 diff -urNp linux-2.6.39.1/sound/soc/sh/migor.c linux-2.6.39.1/sound/soc/sh/migor.c
84406 --- linux-2.6.39.1/sound/soc/sh/migor.c 2011-05-19 00:06:34.000000000 -0400
84407 +++ linux-2.6.39.1/sound/soc/sh/migor.c 2011-05-22 19:36:35.000000000 -0400
84408 @@ -108,7 +108,7 @@ static int migor_hw_free(struct snd_pcm_
84409 return 0;
84410 }
84411
84412 -static struct snd_soc_ops migor_dai_ops = {
84413 +static const struct snd_soc_ops migor_dai_ops = {
84414 .hw_params = migor_hw_params,
84415 .hw_free = migor_hw_free,
84416 };
84417 diff -urNp linux-2.6.39.1/sound/soc/sh/siu_pcm.c linux-2.6.39.1/sound/soc/sh/siu_pcm.c
84418 --- linux-2.6.39.1/sound/soc/sh/siu_pcm.c 2011-05-19 00:06:34.000000000 -0400
84419 +++ linux-2.6.39.1/sound/soc/sh/siu_pcm.c 2011-05-22 19:36:35.000000000 -0400
84420 @@ -597,7 +597,7 @@ static void siu_pcm_free(struct snd_pcm
84421 dev_dbg(pcm->card->dev, "%s\n", __func__);
84422 }
84423
84424 -static struct snd_pcm_ops siu_pcm_ops = {
84425 +static const struct snd_pcm_ops siu_pcm_ops = {
84426 .open = siu_pcm_open,
84427 .close = siu_pcm_close,
84428 .ioctl = snd_pcm_lib_ioctl,
84429 diff -urNp linux-2.6.39.1/sound/soc/tegra/harmony.c linux-2.6.39.1/sound/soc/tegra/harmony.c
84430 --- linux-2.6.39.1/sound/soc/tegra/harmony.c 2011-05-19 00:06:34.000000000 -0400
84431 +++ linux-2.6.39.1/sound/soc/tegra/harmony.c 2011-05-22 19:36:35.000000000 -0400
84432 @@ -126,7 +126,7 @@ static int harmony_asoc_hw_params(struct
84433 return 0;
84434 }
84435
84436 -static struct snd_soc_ops harmony_asoc_ops = {
84437 +static const struct snd_soc_ops harmony_asoc_ops = {
84438 .hw_params = harmony_asoc_hw_params,
84439 };
84440
84441 diff -urNp linux-2.6.39.1/sound/soc/tegra/tegra_pcm.c linux-2.6.39.1/sound/soc/tegra/tegra_pcm.c
84442 --- linux-2.6.39.1/sound/soc/tegra/tegra_pcm.c 2011-05-19 00:06:34.000000000 -0400
84443 +++ linux-2.6.39.1/sound/soc/tegra/tegra_pcm.c 2011-05-22 19:36:36.000000000 -0400
84444 @@ -277,7 +277,7 @@ static int tegra_pcm_mmap(struct snd_pcm
84445 runtime->dma_bytes);
84446 }
84447
84448 -static struct snd_pcm_ops tegra_pcm_ops = {
84449 +static const struct snd_pcm_ops tegra_pcm_ops = {
84450 .open = tegra_pcm_open,
84451 .close = tegra_pcm_close,
84452 .ioctl = snd_pcm_lib_ioctl,
84453 diff -urNp linux-2.6.39.1/sound/soc/txx9/txx9aclc.c linux-2.6.39.1/sound/soc/txx9/txx9aclc.c
84454 --- linux-2.6.39.1/sound/soc/txx9/txx9aclc.c 2011-05-19 00:06:34.000000000 -0400
84455 +++ linux-2.6.39.1/sound/soc/txx9/txx9aclc.c 2011-05-22 19:36:36.000000000 -0400
84456 @@ -272,7 +272,7 @@ static int txx9aclc_pcm_close(struct snd
84457 return 0;
84458 }
84459
84460 -static struct snd_pcm_ops txx9aclc_pcm_ops = {
84461 +static const struct snd_pcm_ops txx9aclc_pcm_ops = {
84462 .open = txx9aclc_pcm_open,
84463 .close = txx9aclc_pcm_close,
84464 .ioctl = snd_pcm_lib_ioctl,
84465 diff -urNp linux-2.6.39.1/sound/sparc/amd7930.c linux-2.6.39.1/sound/sparc/amd7930.c
84466 --- linux-2.6.39.1/sound/sparc/amd7930.c 2011-05-19 00:06:34.000000000 -0400
84467 +++ linux-2.6.39.1/sound/sparc/amd7930.c 2011-05-22 19:36:36.000000000 -0400
84468 @@ -733,7 +733,7 @@ static int snd_amd7930_hw_free(struct sn
84469 return snd_pcm_lib_free_pages(substream);
84470 }
84471
84472 -static struct snd_pcm_ops snd_amd7930_playback_ops = {
84473 +static const struct snd_pcm_ops snd_amd7930_playback_ops = {
84474 .open = snd_amd7930_playback_open,
84475 .close = snd_amd7930_playback_close,
84476 .ioctl = snd_pcm_lib_ioctl,
84477 @@ -744,7 +744,7 @@ static struct snd_pcm_ops snd_amd7930_pl
84478 .pointer = snd_amd7930_playback_pointer,
84479 };
84480
84481 -static struct snd_pcm_ops snd_amd7930_capture_ops = {
84482 +static const struct snd_pcm_ops snd_amd7930_capture_ops = {
84483 .open = snd_amd7930_capture_open,
84484 .close = snd_amd7930_capture_close,
84485 .ioctl = snd_pcm_lib_ioctl,
84486 @@ -929,7 +929,7 @@ static int snd_amd7930_dev_free(struct s
84487 return snd_amd7930_free(amd);
84488 }
84489
84490 -static struct snd_device_ops snd_amd7930_dev_ops = {
84491 +static const struct snd_device_ops snd_amd7930_dev_ops = {
84492 .dev_free = snd_amd7930_dev_free,
84493 };
84494
84495 diff -urNp linux-2.6.39.1/sound/sparc/cs4231.c linux-2.6.39.1/sound/sparc/cs4231.c
84496 --- linux-2.6.39.1/sound/sparc/cs4231.c 2011-05-19 00:06:34.000000000 -0400
84497 +++ linux-2.6.39.1/sound/sparc/cs4231.c 2011-05-22 19:36:36.000000000 -0400
84498 @@ -1196,7 +1196,7 @@ static int snd_cs4231_capture_close(stru
84499 * XXX the audio AUXIO register...
84500 */
84501
84502 -static struct snd_pcm_ops snd_cs4231_playback_ops = {
84503 +static const struct snd_pcm_ops snd_cs4231_playback_ops = {
84504 .open = snd_cs4231_playback_open,
84505 .close = snd_cs4231_playback_close,
84506 .ioctl = snd_pcm_lib_ioctl,
84507 @@ -1207,7 +1207,7 @@ static struct snd_pcm_ops snd_cs4231_pla
84508 .pointer = snd_cs4231_playback_pointer,
84509 };
84510
84511 -static struct snd_pcm_ops snd_cs4231_capture_ops = {
84512 +static const struct snd_pcm_ops snd_cs4231_capture_ops = {
84513 .open = snd_cs4231_capture_open,
84514 .close = snd_cs4231_capture_close,
84515 .ioctl = snd_pcm_lib_ioctl,
84516 @@ -1789,7 +1789,7 @@ static int snd_cs4231_sbus_dev_free(stru
84517 return snd_cs4231_sbus_free(cp);
84518 }
84519
84520 -static struct snd_device_ops snd_cs4231_sbus_dev_ops = {
84521 +static const struct snd_device_ops snd_cs4231_sbus_dev_ops = {
84522 .dev_free = snd_cs4231_sbus_dev_free,
84523 };
84524
84525 @@ -1955,7 +1955,7 @@ static int snd_cs4231_ebus_dev_free(stru
84526 return snd_cs4231_ebus_free(cp);
84527 }
84528
84529 -static struct snd_device_ops snd_cs4231_ebus_dev_ops = {
84530 +static const struct snd_device_ops snd_cs4231_ebus_dev_ops = {
84531 .dev_free = snd_cs4231_ebus_dev_free,
84532 };
84533
84534 diff -urNp linux-2.6.39.1/sound/sparc/dbri.c linux-2.6.39.1/sound/sparc/dbri.c
84535 --- linux-2.6.39.1/sound/sparc/dbri.c 2011-05-19 00:06:34.000000000 -0400
84536 +++ linux-2.6.39.1/sound/sparc/dbri.c 2011-05-22 19:36:36.000000000 -0400
84537 @@ -2205,7 +2205,7 @@ static snd_pcm_uframes_t snd_dbri_pointe
84538 return ret;
84539 }
84540
84541 -static struct snd_pcm_ops snd_dbri_ops = {
84542 +static const struct snd_pcm_ops snd_dbri_ops = {
84543 .open = snd_dbri_open,
84544 .close = snd_dbri_close,
84545 .ioctl = snd_pcm_lib_ioctl,
84546 diff -urNp linux-2.6.39.1/sound/spi/at73c213.c linux-2.6.39.1/sound/spi/at73c213.c
84547 --- linux-2.6.39.1/sound/spi/at73c213.c 2011-05-19 00:06:34.000000000 -0400
84548 +++ linux-2.6.39.1/sound/spi/at73c213.c 2011-05-22 19:36:36.000000000 -0400
84549 @@ -319,7 +319,7 @@ snd_at73c213_pcm_pointer(struct snd_pcm_
84550 return pos;
84551 }
84552
84553 -static struct snd_pcm_ops at73c213_playback_ops = {
84554 +static const struct snd_pcm_ops at73c213_playback_ops = {
84555 .open = snd_at73c213_pcm_open,
84556 .close = snd_at73c213_pcm_close,
84557 .ioctl = snd_pcm_lib_ioctl,
84558 @@ -882,7 +882,7 @@ static int snd_at73c213_dev_free(struct
84559 static int __devinit snd_at73c213_dev_init(struct snd_card *card,
84560 struct spi_device *spi)
84561 {
84562 - static struct snd_device_ops ops = {
84563 + static const struct snd_device_ops ops = {
84564 .dev_free = snd_at73c213_dev_free,
84565 };
84566 struct snd_at73c213 *chip = get_chip(card);
84567 diff -urNp linux-2.6.39.1/sound/usb/6fire/midi.c linux-2.6.39.1/sound/usb/6fire/midi.c
84568 --- linux-2.6.39.1/sound/usb/6fire/midi.c 2011-05-19 00:06:34.000000000 -0400
84569 +++ linux-2.6.39.1/sound/usb/6fire/midi.c 2011-05-22 19:36:36.000000000 -0400
84570 @@ -134,14 +134,14 @@ static void usb6fire_midi_in_trigger(
84571 spin_unlock_irqrestore(&rt->in_lock, flags);
84572 }
84573
84574 -static struct snd_rawmidi_ops out_ops = {
84575 +static const struct snd_rawmidi_ops out_ops = {
84576 .open = usb6fire_midi_out_open,
84577 .close = usb6fire_midi_out_close,
84578 .trigger = usb6fire_midi_out_trigger,
84579 .drain = usb6fire_midi_out_drain
84580 };
84581
84582 -static struct snd_rawmidi_ops in_ops = {
84583 +static const struct snd_rawmidi_ops in_ops = {
84584 .open = usb6fire_midi_in_open,
84585 .close = usb6fire_midi_in_close,
84586 .trigger = usb6fire_midi_in_trigger
84587 diff -urNp linux-2.6.39.1/sound/usb/caiaq/audio.c linux-2.6.39.1/sound/usb/caiaq/audio.c
84588 --- linux-2.6.39.1/sound/usb/caiaq/audio.c 2011-05-19 00:06:34.000000000 -0400
84589 +++ linux-2.6.39.1/sound/usb/caiaq/audio.c 2011-05-22 19:36:36.000000000 -0400
84590 @@ -322,7 +322,7 @@ snd_usb_caiaq_pcm_pointer(struct snd_pcm
84591 }
84592
84593 /* operators for both playback and capture */
84594 -static struct snd_pcm_ops snd_usb_caiaq_ops = {
84595 +static const struct snd_pcm_ops snd_usb_caiaq_ops = {
84596 .open = snd_usb_caiaq_substream_open,
84597 .close = snd_usb_caiaq_substream_close,
84598 .ioctl = snd_pcm_lib_ioctl,
84599 diff -urNp linux-2.6.39.1/sound/usb/caiaq/midi.c linux-2.6.39.1/sound/usb/caiaq/midi.c
84600 --- linux-2.6.39.1/sound/usb/caiaq/midi.c 2011-05-19 00:06:34.000000000 -0400
84601 +++ linux-2.6.39.1/sound/usb/caiaq/midi.c 2011-05-22 19:36:36.000000000 -0400
84602 @@ -100,15 +100,13 @@ static void snd_usb_caiaq_midi_output_tr
84603 }
84604
84605
84606 -static struct snd_rawmidi_ops snd_usb_caiaq_midi_output =
84607 -{
84608 +static const struct snd_rawmidi_ops snd_usb_caiaq_midi_output = {
84609 .open = snd_usb_caiaq_midi_output_open,
84610 .close = snd_usb_caiaq_midi_output_close,
84611 .trigger = snd_usb_caiaq_midi_output_trigger,
84612 };
84613
84614 -static struct snd_rawmidi_ops snd_usb_caiaq_midi_input =
84615 -{
84616 +static const struct snd_rawmidi_ops snd_usb_caiaq_midi_input = {
84617 .open = snd_usb_caiaq_midi_input_open,
84618 .close = snd_usb_caiaq_midi_input_close,
84619 .trigger = snd_usb_caiaq_midi_input_trigger,
84620 diff -urNp linux-2.6.39.1/sound/usb/card.c linux-2.6.39.1/sound/usb/card.c
84621 --- linux-2.6.39.1/sound/usb/card.c 2011-05-19 00:06:34.000000000 -0400
84622 +++ linux-2.6.39.1/sound/usb/card.c 2011-05-22 19:36:36.000000000 -0400
84623 @@ -305,7 +305,7 @@ static int snd_usb_audio_create(struct u
84624 struct snd_usb_audio *chip;
84625 int err, len;
84626 char component[14];
84627 - static struct snd_device_ops ops = {
84628 + static const struct snd_device_ops ops = {
84629 .dev_free = snd_usb_audio_dev_free,
84630 };
84631
84632 diff -urNp linux-2.6.39.1/sound/usb/midi.c linux-2.6.39.1/sound/usb/midi.c
84633 --- linux-2.6.39.1/sound/usb/midi.c 2011-05-19 00:06:34.000000000 -0400
84634 +++ linux-2.6.39.1/sound/usb/midi.c 2011-05-22 19:36:36.000000000 -0400
84635 @@ -1146,14 +1146,14 @@ static void snd_usbmidi_input_trigger(st
84636 clear_bit(substream->number, &umidi->input_triggered);
84637 }
84638
84639 -static struct snd_rawmidi_ops snd_usbmidi_output_ops = {
84640 +static const struct snd_rawmidi_ops snd_usbmidi_output_ops = {
84641 .open = snd_usbmidi_output_open,
84642 .close = snd_usbmidi_output_close,
84643 .trigger = snd_usbmidi_output_trigger,
84644 .drain = snd_usbmidi_output_drain,
84645 };
84646
84647 -static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
84648 +static const struct snd_rawmidi_ops snd_usbmidi_input_ops = {
84649 .open = snd_usbmidi_input_open,
84650 .close = snd_usbmidi_input_close,
84651 .trigger = snd_usbmidi_input_trigger
84652 diff -urNp linux-2.6.39.1/sound/usb/misc/ua101.c linux-2.6.39.1/sound/usb/misc/ua101.c
84653 --- linux-2.6.39.1/sound/usb/misc/ua101.c 2011-05-19 00:06:34.000000000 -0400
84654 +++ linux-2.6.39.1/sound/usb/misc/ua101.c 2011-05-22 19:36:36.000000000 -0400
84655 @@ -886,7 +886,7 @@ static snd_pcm_uframes_t playback_pcm_po
84656 return ua101_pcm_pointer(ua, &ua->playback);
84657 }
84658
84659 -static struct snd_pcm_ops capture_pcm_ops = {
84660 +static const struct snd_pcm_ops capture_pcm_ops = {
84661 .open = capture_pcm_open,
84662 .close = capture_pcm_close,
84663 .ioctl = snd_pcm_lib_ioctl,
84664 @@ -899,7 +899,7 @@ static struct snd_pcm_ops capture_pcm_op
84665 .mmap = snd_pcm_lib_mmap_vmalloc,
84666 };
84667
84668 -static struct snd_pcm_ops playback_pcm_ops = {
84669 +static const struct snd_pcm_ops playback_pcm_ops = {
84670 .open = playback_pcm_open,
84671 .close = playback_pcm_close,
84672 .ioctl = snd_pcm_lib_ioctl,
84673 diff -urNp linux-2.6.39.1/sound/usb/mixer.c linux-2.6.39.1/sound/usb/mixer.c
84674 --- linux-2.6.39.1/sound/usb/mixer.c 2011-05-19 00:06:34.000000000 -0400
84675 +++ linux-2.6.39.1/sound/usb/mixer.c 2011-05-22 19:36:36.000000000 -0400
84676 @@ -2201,7 +2201,7 @@ static int snd_usb_mixer_status_create(s
84677 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
84678 int ignore_error)
84679 {
84680 - static struct snd_device_ops dev_ops = {
84681 + static const struct snd_device_ops dev_ops = {
84682 .dev_free = snd_usb_mixer_dev_free
84683 };
84684 struct usb_mixer_interface *mixer;
84685 diff -urNp linux-2.6.39.1/sound/usb/pcm.c linux-2.6.39.1/sound/usb/pcm.c
84686 --- linux-2.6.39.1/sound/usb/pcm.c 2011-05-19 00:06:34.000000000 -0400
84687 +++ linux-2.6.39.1/sound/usb/pcm.c 2011-05-22 19:36:36.000000000 -0400
84688 @@ -844,7 +844,7 @@ static int snd_usb_capture_close(struct
84689 return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE);
84690 }
84691
84692 -static struct snd_pcm_ops snd_usb_playback_ops = {
84693 +static const struct snd_pcm_ops snd_usb_playback_ops = {
84694 .open = snd_usb_playback_open,
84695 .close = snd_usb_playback_close,
84696 .ioctl = snd_pcm_lib_ioctl,
84697 @@ -857,7 +857,7 @@ static struct snd_pcm_ops snd_usb_playba
84698 .mmap = snd_pcm_lib_mmap_vmalloc,
84699 };
84700
84701 -static struct snd_pcm_ops snd_usb_capture_ops = {
84702 +static const struct snd_pcm_ops snd_usb_capture_ops = {
84703 .open = snd_usb_capture_open,
84704 .close = snd_usb_capture_close,
84705 .ioctl = snd_pcm_lib_ioctl,
84706 diff -urNp linux-2.6.39.1/sound/usb/usx2y/usbusx2yaudio.c linux-2.6.39.1/sound/usb/usx2y/usbusx2yaudio.c
84707 --- linux-2.6.39.1/sound/usb/usx2y/usbusx2yaudio.c 2011-05-19 00:06:34.000000000 -0400
84708 +++ linux-2.6.39.1/sound/usb/usx2y/usbusx2yaudio.c 2011-05-22 19:36:36.000000000 -0400
84709 @@ -919,8 +919,7 @@ static int snd_usX2Y_pcm_close(struct sn
84710 }
84711
84712
84713 -static struct snd_pcm_ops snd_usX2Y_pcm_ops =
84714 -{
84715 +static const struct snd_pcm_ops snd_usX2Y_pcm_ops = {
84716 .open = snd_usX2Y_pcm_open,
84717 .close = snd_usX2Y_pcm_close,
84718 .ioctl = snd_pcm_lib_ioctl,
84719 diff -urNp linux-2.6.39.1/tools/gcc/Makefile linux-2.6.39.1/tools/gcc/Makefile
84720 --- linux-2.6.39.1/tools/gcc/Makefile 1969-12-31 19:00:00.000000000 -0500
84721 +++ linux-2.6.39.1/tools/gcc/Makefile 2011-06-03 01:19:01.000000000 -0400
84722 @@ -0,0 +1,11 @@
84723 +#CC := gcc
84724 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84725 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84726 +GCCPLUGINS_DIR := $(shell $(HOSTCC) -print-file-name=plugin)
84727 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
84728 +
84729 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
84730 +
84731 +hostlibs-y := pax_plugin.so
84732 +always := $(hostlibs-y)
84733 +pax_plugin-objs := pax_plugin.o
84734 diff -urNp linux-2.6.39.1/tools/gcc/pax_plugin.c linux-2.6.39.1/tools/gcc/pax_plugin.c
84735 --- linux-2.6.39.1/tools/gcc/pax_plugin.c 1969-12-31 19:00:00.000000000 -0500
84736 +++ linux-2.6.39.1/tools/gcc/pax_plugin.c 2011-06-03 01:28:31.000000000 -0400
84737 @@ -0,0 +1,321 @@
84738 +/*
84739 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84740 + * Licensed under the GPL v2
84741 + *
84742 + * Note: the choice of the license means that the compilation process is
84743 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84744 + * but for the kernel it doesn't matter since it doesn't link against
84745 + * any of the gcc libraries
84746 + *
84747 + * gcc plugin to help implement various PaX features
84748 + *
84749 + * - track lowest stack pointer
84750 + *
84751 + * TODO:
84752 + * - initialize all local variables
84753 + *
84754 + * BUGS:
84755 + */
84756 +#include "gcc-plugin.h"
84757 +#include "plugin-version.h"
84758 +#include "config.h"
84759 +#include "system.h"
84760 +#include "coretypes.h"
84761 +#include "tm.h"
84762 +#include "toplev.h"
84763 +#include "basic-block.h"
84764 +#include "gimple.h"
84765 +//#include "expr.h" where are you...
84766 +#include "diagnostic.h"
84767 +#include "rtl.h"
84768 +#include "emit-rtl.h"
84769 +#include "function.h"
84770 +#include "tree.h"
84771 +#include "tree-pass.h"
84772 +#include "intl.h"
84773 +
84774 +int plugin_is_GPL_compatible;
84775 +
84776 +static int track_frame_size = -1;
84777 +static const char track_function[] = "pax_track_stack_gcc";
84778 +static bool init_locals;
84779 +
84780 +static struct plugin_info pax_plugin_info = {
84781 + .version = "201106030000",
84782 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
84783 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
84784 +};
84785 +
84786 +static bool gate_pax_track_stack(void);
84787 +static unsigned int execute_pax_tree_instrument(void);
84788 +static unsigned int execute_pax_expand(void);
84789 +static unsigned int execute_pax_final(void);
84790 +
84791 +static struct gimple_opt_pass pax_tree_instrument_pass = {
84792 + .pass = {
84793 + .type = GIMPLE_PASS,
84794 + .name = "pax_tree_instrument",
84795 + .gate = gate_pax_track_stack,
84796 + .execute = execute_pax_tree_instrument,
84797 + .sub = NULL,
84798 + .next = NULL,
84799 + .static_pass_number = 0,
84800 + .tv_id = TV_NONE,
84801 + .properties_required = PROP_gimple_leh | PROP_cfg,
84802 + .properties_provided = 0,
84803 + .properties_destroyed = 0,
84804 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84805 + .todo_flags_finish = TODO_verify_stmts // | TODO_dump_func
84806 + }
84807 +};
84808 +
84809 +static struct rtl_opt_pass pax_expand_rtl_opt_pass = {
84810 + .pass = {
84811 + .type = RTL_PASS,
84812 + .name = "pax_expand",
84813 + .gate = gate_pax_track_stack,
84814 + .execute = execute_pax_expand,
84815 + .sub = NULL,
84816 + .next = NULL,
84817 + .static_pass_number = 0,
84818 + .tv_id = TV_NONE,
84819 + .properties_required = 0,
84820 + .properties_provided = 0,
84821 + .properties_destroyed = 0,
84822 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84823 + .todo_flags_finish = 0 //TODO_dump_func | TODO_ggc_collect
84824 + }
84825 +};
84826 +
84827 +static struct rtl_opt_pass pax_final_rtl_opt_pass = {
84828 + .pass = {
84829 + .type = RTL_PASS,
84830 + .name = "pax_final",
84831 + .gate = gate_pax_track_stack,
84832 + .execute = execute_pax_final,
84833 + .sub = NULL,
84834 + .next = NULL,
84835 + .static_pass_number = 0,
84836 + .tv_id = TV_NONE,
84837 + .properties_required = 0,
84838 + .properties_provided = 0,
84839 + .properties_destroyed = 0,
84840 + .todo_flags_start = 0,
84841 + .todo_flags_finish = 0
84842 + }
84843 +};
84844 +
84845 +static bool gate_pax_track_stack(void)
84846 +{
84847 + return track_frame_size >= 0;
84848 +}
84849 +
84850 +static void pax_add_instrumentation(gimple_stmt_iterator *gsi, bool before)
84851 +{
84852 + gimple call;
84853 + tree sp, decl, type;
84854 +
84855 + sp = build_int_cst_wide(ptr_type_node, 0, 0);
84856 + type = build_function_type_list(void_type_node, unsigned_type_node, NULL_TREE);
84857 + decl = build_fn_decl(track_function, type);
84858 + DECL_ASSEMBLER_NAME(decl); // for LTO
84859 + call = gimple_build_call(decl, 1, sp);
84860 + if (before)
84861 + gsi_insert_before(gsi, call, GSI_CONTINUE_LINKING);
84862 + else
84863 + gsi_insert_after(gsi, call, GSI_CONTINUE_LINKING);
84864 +}
84865 +
84866 +static unsigned int execute_pax_tree_instrument(void)
84867 +{
84868 + basic_block bb;
84869 + gimple_stmt_iterator gsi;
84870 + bool isalloca = false;
84871 +
84872 + // 1. loop through BBs and GIMPLE statements
84873 + FOR_EACH_BB(bb) {
84874 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84875 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
84876 + tree decl;
84877 + gimple stmt = gsi_stmt(gsi);
84878 +
84879 + if (!is_gimple_call(stmt))
84880 + continue;
84881 + decl = gimple_call_fndecl(stmt);
84882 + if (!decl)
84883 + continue;
84884 + if (TREE_CODE(decl) != FUNCTION_DECL)
84885 + continue;
84886 + if (!DECL_BUILT_IN(decl))
84887 + continue;
84888 + if (DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
84889 + continue;
84890 + if (DECL_FUNCTION_CODE(decl) != BUILT_IN_ALLOCA)
84891 + continue;
84892 +
84893 + // 3. insert track call after each __builtin_alloca call
84894 + pax_add_instrumentation(&gsi, false);
84895 + isalloca = true;
84896 +// print_node(stderr, "pax", decl, 4);
84897 + }
84898 + }
84899 +
84900 + // 2. if no __builtin_alloca call is found
84901 + if (isalloca)
84902 + return 0;
84903 +
84904 + // 2.1 insert track call at the beginning
84905 + bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
84906 + gsi = gsi_start_bb(bb);
84907 + pax_add_instrumentation(&gsi, true);
84908 +
84909 + return 0;
84910 +}
84911 +
84912 +static unsigned int execute_pax_expand(void)
84913 +{
84914 + rtx sp, insn;
84915 +
84916 + // 1. find pax_track_stack calls
84917 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84918 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
84919 + rtx body;
84920 +
84921 + if (!CALL_P(insn))
84922 + continue;
84923 + body = PATTERN(insn);
84924 + if (GET_CODE(body) != CALL)
84925 + continue;
84926 + body = XEXP(body, 0);
84927 + if (GET_CODE(body) != MEM)
84928 + continue;
84929 + body = XEXP(body, 0);
84930 + if (GET_CODE(body) != SYMBOL_REF)
84931 + continue;
84932 + if (strcmp(XSTR(body, 0), track_function))
84933 + continue;
84934 + // 2. fix parameter to be the stack pointer
84935 + // rtl match: (insn 6 5 7 3 (set (mem (reg 56 virtual-outgoing-args) [0 S4 A32]) (0)) -1 (nil))
84936 + // (insn 6 5 7 3 (set (reg 0 ax) (0)) -1 (nil))
84937 + // (insn 6 5 7 3 (set (reg 5 di) (0)) -1 (nil))
84938 + sp = PREV_INSN(insn);
84939 + if (!INSN_P(sp))
84940 + continue;
84941 + sp = PATTERN(sp);
84942 + if (GET_CODE(sp) != SET)
84943 + continue;
84944 + SET_SRC(sp) = stack_pointer_rtx;
84945 + }
84946 +
84947 +// print_simple_rtl(stderr, get_insns());
84948 +// print_rtl(stderr, get_insns());
84949 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
84950 +
84951 + return 0;
84952 +}
84953 +
84954 +static unsigned int execute_pax_final(void)
84955 +{
84956 + rtx sp = NULL, insn;
84957 +
84958 + // 1. find pax_track_stack calls
84959 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84960 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
84961 + rtx body;
84962 +
84963 + if (!INSN_P(insn))
84964 + continue;
84965 + body = PATTERN(insn);
84966 + if (GET_CODE(body) == SET) {
84967 + if (GET_CODE(body) == SET && SET_SRC(body) == stack_pointer_rtx)
84968 + sp = insn;
84969 + continue;
84970 + }
84971 +
84972 + if (!CALL_P(insn))
84973 + continue;
84974 + if (GET_CODE(body) != CALL)
84975 + continue;
84976 + body = XEXP(body, 0);
84977 + if (GET_CODE(body) != MEM)
84978 + continue;
84979 + body = XEXP(body, 0);
84980 + if (GET_CODE(body) != SYMBOL_REF)
84981 + continue;
84982 + if (strcmp(XSTR(body, 0), track_function))
84983 + continue;
84984 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
84985 + // 2. delete call if function frame is not big enough
84986 + if (cfun->calls_alloca)
84987 + continue;
84988 + if (get_frame_size() >= track_frame_size)
84989 + continue;
84990 + if (sp)
84991 + delete_insn_and_edges(sp);
84992 + delete_insn_and_edges(insn);
84993 + }
84994 +
84995 + return 0;
84996 +}
84997 +
84998 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84999 +{
85000 + const char * const plugin_name = plugin_info->base_name;
85001 + const int argc = plugin_info->argc;
85002 + const struct plugin_argument * const argv = plugin_info->argv;
85003 + int i;
85004 + struct register_pass_info pax_tree_instrument_pass_info = {
85005 + .pass = &pax_tree_instrument_pass.pass,
85006 +// .reference_pass_name = "tree_profile",
85007 + .reference_pass_name = "optimized",
85008 + .ref_pass_instance_number = 0,
85009 + .pos_op = PASS_POS_INSERT_AFTER
85010 + };
85011 + struct register_pass_info pax_expand_pass_info = {
85012 + .pass = &pax_expand_rtl_opt_pass.pass,
85013 + .reference_pass_name = "expand",
85014 + .ref_pass_instance_number = 0,
85015 + .pos_op = PASS_POS_INSERT_AFTER
85016 + };
85017 + struct register_pass_info pax_final_pass_info = {
85018 + .pass = &pax_final_rtl_opt_pass.pass,
85019 + .reference_pass_name = "final",
85020 + .ref_pass_instance_number = 0,
85021 + .pos_op = PASS_POS_INSERT_BEFORE
85022 + };
85023 +
85024 + if (!plugin_default_version_check(version, &gcc_version)) {
85025 + error(G_("incompatible gcc/plugin versions"));
85026 + return 1;
85027 + }
85028 +
85029 + register_callback(plugin_name, PLUGIN_INFO, NULL, &pax_plugin_info);
85030 +
85031 + for (i = 0; i < argc; ++i) {
85032 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
85033 + if (!argv[i].value) {
85034 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85035 + continue;
85036 + }
85037 + track_frame_size = atoi(argv[i].value);
85038 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
85039 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85040 + continue;
85041 + }
85042 + if (!strcmp(argv[i].key, "initialize-locals")) {
85043 + if (argv[i].value) {
85044 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85045 + continue;
85046 + }
85047 + init_locals = true;
85048 + continue;
85049 + }
85050 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85051 + }
85052 +
85053 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pax_tree_instrument_pass_info);
85054 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pax_expand_pass_info);
85055 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pax_final_pass_info);
85056 +
85057 + return 0;
85058 +}
85059 Binary files linux-2.6.39.1/tools/gcc/pax_plugin.so and linux-2.6.39.1/tools/gcc/pax_plugin.so differ
85060 diff -urNp linux-2.6.39.1/tools/perf/builtin-lock.c linux-2.6.39.1/tools/perf/builtin-lock.c
85061 --- linux-2.6.39.1/tools/perf/builtin-lock.c 2011-05-19 00:06:34.000000000 -0400
85062 +++ linux-2.6.39.1/tools/perf/builtin-lock.c 2011-05-22 19:36:36.000000000 -0400
85063 @@ -635,14 +635,14 @@ end:
85064
85065 /* lock oriented handlers */
85066 /* TODO: handlers for CPU oriented, thread oriented */
85067 -static struct trace_lock_handler report_lock_ops = {
85068 +static const struct trace_lock_handler report_lock_ops = {
85069 .acquire_event = report_lock_acquire_event,
85070 .acquired_event = report_lock_acquired_event,
85071 .contended_event = report_lock_contended_event,
85072 .release_event = report_lock_release_event,
85073 };
85074
85075 -static struct trace_lock_handler *trace_handler;
85076 +static const struct trace_lock_handler *trace_handler;
85077
85078 static void
85079 process_lock_acquire_event(void *data,
85080 diff -urNp linux-2.6.39.1/tools/perf/builtin-sched.c linux-2.6.39.1/tools/perf/builtin-sched.c
85081 --- linux-2.6.39.1/tools/perf/builtin-sched.c 2011-05-19 00:06:34.000000000 -0400
85082 +++ linux-2.6.39.1/tools/perf/builtin-sched.c 2011-05-22 19:36:36.000000000 -0400
85083 @@ -845,7 +845,7 @@ replay_fork_event(struct trace_fork_even
85084 register_pid(fork_event->child_pid, fork_event->child_comm);
85085 }
85086
85087 -static struct trace_sched_handler replay_ops = {
85088 +static const struct trace_sched_handler replay_ops = {
85089 .wakeup_event = replay_wakeup_event,
85090 .switch_event = replay_switch_event,
85091 .fork_event = replay_fork_event,
85092 @@ -1183,7 +1183,7 @@ latency_migrate_task_event(struct trace_
85093 nr_unordered_timestamps++;
85094 }
85095
85096 -static struct trace_sched_handler lat_ops = {
85097 +static const struct trace_sched_handler lat_ops = {
85098 .wakeup_event = latency_wakeup_event,
85099 .switch_event = latency_switch_event,
85100 .runtime_event = latency_runtime_event,
85101 @@ -1353,7 +1353,7 @@ static void sort_lat(void)
85102 }
85103 }
85104
85105 -static struct trace_sched_handler *trace_handler;
85106 +static const struct trace_sched_handler *trace_handler;
85107
85108 static void
85109 process_sched_wakeup_event(void *data, struct perf_session *session,
85110 @@ -1719,7 +1719,7 @@ static void __cmd_lat(void)
85111
85112 }
85113
85114 -static struct trace_sched_handler map_ops = {
85115 +static const struct trace_sched_handler map_ops = {
85116 .wakeup_event = NULL,
85117 .switch_event = map_switch_event,
85118 .runtime_event = NULL,
85119 diff -urNp linux-2.6.39.1/usr/gen_init_cpio.c linux-2.6.39.1/usr/gen_init_cpio.c
85120 --- linux-2.6.39.1/usr/gen_init_cpio.c 2011-05-19 00:06:34.000000000 -0400
85121 +++ linux-2.6.39.1/usr/gen_init_cpio.c 2011-05-22 19:36:36.000000000 -0400
85122 @@ -305,7 +305,7 @@ static int cpio_mkfile(const char *name,
85123 int retval;
85124 int rc = -1;
85125 int namesize;
85126 - int i;
85127 + unsigned int i;
85128
85129 mode |= S_IFREG;
85130
85131 @@ -394,9 +394,10 @@ static char *cpio_replace_env(char *new_
85132 *env_var = *expanded = '\0';
85133 strncat(env_var, start + 2, end - start - 2);
85134 strncat(expanded, new_location, start - new_location);
85135 - strncat(expanded, getenv(env_var), PATH_MAX);
85136 - strncat(expanded, end + 1, PATH_MAX);
85137 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
85138 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
85139 strncpy(new_location, expanded, PATH_MAX);
85140 + new_location[PATH_MAX] = 0;
85141 } else
85142 break;
85143 }
85144 diff -urNp linux-2.6.39.1/virt/kvm/kvm_main.c linux-2.6.39.1/virt/kvm/kvm_main.c
85145 --- linux-2.6.39.1/virt/kvm/kvm_main.c 2011-05-19 00:06:34.000000000 -0400
85146 +++ linux-2.6.39.1/virt/kvm/kvm_main.c 2011-05-22 19:36:36.000000000 -0400
85147 @@ -73,7 +73,7 @@ LIST_HEAD(vm_list);
85148
85149 static cpumask_var_t cpus_hardware_enabled;
85150 static int kvm_usage_count = 0;
85151 -static atomic_t hardware_enable_failed;
85152 +static atomic_unchecked_t hardware_enable_failed;
85153
85154 struct kmem_cache *kvm_vcpu_cache;
85155 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
85156 @@ -1594,7 +1594,7 @@ static int kvm_vcpu_release(struct inode
85157 return 0;
85158 }
85159
85160 -static struct file_operations kvm_vcpu_fops = {
85161 +static struct file_operations kvm_vcpu_fops = { /* cannot be const */
85162 .release = kvm_vcpu_release,
85163 .unlocked_ioctl = kvm_vcpu_ioctl,
85164 .compat_ioctl = kvm_vcpu_ioctl,
85165 @@ -2063,7 +2063,7 @@ static int kvm_vm_mmap(struct file *file
85166 return 0;
85167 }
85168
85169 -static struct file_operations kvm_vm_fops = {
85170 +static struct file_operations kvm_vm_fops = { /* cannot be const */
85171 .release = kvm_vm_release,
85172 .unlocked_ioctl = kvm_vm_ioctl,
85173 #ifdef CONFIG_COMPAT
85174 @@ -2161,7 +2161,7 @@ out:
85175 return r;
85176 }
85177
85178 -static struct file_operations kvm_chardev_ops = {
85179 +static struct file_operations kvm_chardev_ops = { /* cannot be const */
85180 .unlocked_ioctl = kvm_dev_ioctl,
85181 .compat_ioctl = kvm_dev_ioctl,
85182 .llseek = noop_llseek,
85183 @@ -2187,7 +2187,7 @@ static void hardware_enable_nolock(void
85184
85185 if (r) {
85186 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
85187 - atomic_inc(&hardware_enable_failed);
85188 + atomic_inc_unchecked(&hardware_enable_failed);
85189 printk(KERN_INFO "kvm: enabling virtualization on "
85190 "CPU%d failed\n", cpu);
85191 }
85192 @@ -2241,10 +2241,10 @@ static int hardware_enable_all(void)
85193
85194 kvm_usage_count++;
85195 if (kvm_usage_count == 1) {
85196 - atomic_set(&hardware_enable_failed, 0);
85197 + atomic_set_unchecked(&hardware_enable_failed, 0);
85198 on_each_cpu(hardware_enable_nolock, NULL, 1);
85199
85200 - if (atomic_read(&hardware_enable_failed)) {
85201 + if (atomic_read_unchecked(&hardware_enable_failed)) {
85202 hardware_disable_all_nolock();
85203 r = -EBUSY;
85204 }
85205 @@ -2509,7 +2509,7 @@ static void kvm_sched_out(struct preempt
85206 kvm_arch_vcpu_put(vcpu);
85207 }
85208
85209 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85210 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85211 struct module *module)
85212 {
85213 int r;
85214 @@ -2572,7 +2572,7 @@ int kvm_init(void *opaque, unsigned vcpu
85215 if (!vcpu_align)
85216 vcpu_align = __alignof__(struct kvm_vcpu);
85217 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
85218 - 0, NULL);
85219 + SLAB_USERCOPY, NULL);
85220 if (!kvm_vcpu_cache) {
85221 r = -ENOMEM;
85222 goto out_free_3;