]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.44-201108111959.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.44-201108111959.patch
CommitLineData
86afe592
PK
1diff -urNp linux-2.6.32.44/arch/alpha/include/asm/elf.h linux-2.6.32.44/arch/alpha/include/asm/elf.h
2--- linux-2.6.32.44/arch/alpha/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
3+++ linux-2.6.32.44/arch/alpha/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
4@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
5
6 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
7
8+#ifdef CONFIG_PAX_ASLR
9+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
10+
11+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
12+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
13+#endif
14+
15 /* $0 is set by ld.so to a pointer to a function which might be
16 registered using atexit. This provides a mean for the dynamic
17 linker to call DT_FINI functions for shared libraries that have
18diff -urNp linux-2.6.32.44/arch/alpha/include/asm/pgtable.h linux-2.6.32.44/arch/alpha/include/asm/pgtable.h
19--- linux-2.6.32.44/arch/alpha/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
20+++ linux-2.6.32.44/arch/alpha/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
21@@ -101,6 +101,17 @@ struct vm_area_struct;
22 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
23 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
24 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
25+
26+#ifdef CONFIG_PAX_PAGEEXEC
27+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
28+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
29+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
30+#else
31+# define PAGE_SHARED_NOEXEC PAGE_SHARED
32+# define PAGE_COPY_NOEXEC PAGE_COPY
33+# define PAGE_READONLY_NOEXEC PAGE_READONLY
34+#endif
35+
36 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
37
38 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
39diff -urNp linux-2.6.32.44/arch/alpha/kernel/module.c linux-2.6.32.44/arch/alpha/kernel/module.c
40--- linux-2.6.32.44/arch/alpha/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
41+++ linux-2.6.32.44/arch/alpha/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
42@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
43
44 /* The small sections were sorted to the end of the segment.
45 The following should definitely cover them. */
46- gp = (u64)me->module_core + me->core_size - 0x8000;
47+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
48 got = sechdrs[me->arch.gotsecindex].sh_addr;
49
50 for (i = 0; i < n; i++) {
51diff -urNp linux-2.6.32.44/arch/alpha/kernel/osf_sys.c linux-2.6.32.44/arch/alpha/kernel/osf_sys.c
52--- linux-2.6.32.44/arch/alpha/kernel/osf_sys.c 2011-08-09 18:35:28.000000000 -0400
53+++ linux-2.6.32.44/arch/alpha/kernel/osf_sys.c 2011-06-13 17:19:47.000000000 -0400
54@@ -1172,7 +1172,7 @@ arch_get_unmapped_area_1(unsigned long a
55 /* At this point: (!vma || addr < vma->vm_end). */
56 if (limit - len < addr)
57 return -ENOMEM;
58- if (!vma || addr + len <= vma->vm_start)
59+ if (check_heap_stack_gap(vma, addr, len))
60 return addr;
61 addr = vma->vm_end;
62 vma = vma->vm_next;
63@@ -1208,6 +1208,10 @@ arch_get_unmapped_area(struct file *filp
64 merely specific addresses, but regions of memory -- perhaps
65 this feature should be incorporated into all ports? */
66
67+#ifdef CONFIG_PAX_RANDMMAP
68+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
69+#endif
70+
71 if (addr) {
72 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
73 if (addr != (unsigned long) -ENOMEM)
74@@ -1215,8 +1219,8 @@ arch_get_unmapped_area(struct file *filp
75 }
76
77 /* Next, try allocating at TASK_UNMAPPED_BASE. */
78- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
79- len, limit);
80+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
81+
82 if (addr != (unsigned long) -ENOMEM)
83 return addr;
84
85diff -urNp linux-2.6.32.44/arch/alpha/mm/fault.c linux-2.6.32.44/arch/alpha/mm/fault.c
86--- linux-2.6.32.44/arch/alpha/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
87+++ linux-2.6.32.44/arch/alpha/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
88@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
89 __reload_thread(pcb);
90 }
91
92+#ifdef CONFIG_PAX_PAGEEXEC
93+/*
94+ * PaX: decide what to do with offenders (regs->pc = fault address)
95+ *
96+ * returns 1 when task should be killed
97+ * 2 when patched PLT trampoline was detected
98+ * 3 when unpatched PLT trampoline was detected
99+ */
100+static int pax_handle_fetch_fault(struct pt_regs *regs)
101+{
102+
103+#ifdef CONFIG_PAX_EMUPLT
104+ int err;
105+
106+ do { /* PaX: patched PLT emulation #1 */
107+ unsigned int ldah, ldq, jmp;
108+
109+ err = get_user(ldah, (unsigned int *)regs->pc);
110+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
111+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
112+
113+ if (err)
114+ break;
115+
116+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
117+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
118+ jmp == 0x6BFB0000U)
119+ {
120+ unsigned long r27, addr;
121+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
122+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
123+
124+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
125+ err = get_user(r27, (unsigned long *)addr);
126+ if (err)
127+ break;
128+
129+ regs->r27 = r27;
130+ regs->pc = r27;
131+ return 2;
132+ }
133+ } while (0);
134+
135+ do { /* PaX: patched PLT emulation #2 */
136+ unsigned int ldah, lda, br;
137+
138+ err = get_user(ldah, (unsigned int *)regs->pc);
139+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
140+ err |= get_user(br, (unsigned int *)(regs->pc+8));
141+
142+ if (err)
143+ break;
144+
145+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
146+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
147+ (br & 0xFFE00000U) == 0xC3E00000U)
148+ {
149+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
150+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
151+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
152+
153+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
154+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
155+ return 2;
156+ }
157+ } while (0);
158+
159+ do { /* PaX: unpatched PLT emulation */
160+ unsigned int br;
161+
162+ err = get_user(br, (unsigned int *)regs->pc);
163+
164+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
165+ unsigned int br2, ldq, nop, jmp;
166+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
167+
168+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
169+ err = get_user(br2, (unsigned int *)addr);
170+ err |= get_user(ldq, (unsigned int *)(addr+4));
171+ err |= get_user(nop, (unsigned int *)(addr+8));
172+ err |= get_user(jmp, (unsigned int *)(addr+12));
173+ err |= get_user(resolver, (unsigned long *)(addr+16));
174+
175+ if (err)
176+ break;
177+
178+ if (br2 == 0xC3600000U &&
179+ ldq == 0xA77B000CU &&
180+ nop == 0x47FF041FU &&
181+ jmp == 0x6B7B0000U)
182+ {
183+ regs->r28 = regs->pc+4;
184+ regs->r27 = addr+16;
185+ regs->pc = resolver;
186+ return 3;
187+ }
188+ }
189+ } while (0);
190+#endif
191+
192+ return 1;
193+}
194+
195+void pax_report_insns(void *pc, void *sp)
196+{
197+ unsigned long i;
198+
199+ printk(KERN_ERR "PAX: bytes at PC: ");
200+ for (i = 0; i < 5; i++) {
201+ unsigned int c;
202+ if (get_user(c, (unsigned int *)pc+i))
203+ printk(KERN_CONT "???????? ");
204+ else
205+ printk(KERN_CONT "%08x ", c);
206+ }
207+ printk("\n");
208+}
209+#endif
210
211 /*
212 * This routine handles page faults. It determines the address,
213@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
214 good_area:
215 si_code = SEGV_ACCERR;
216 if (cause < 0) {
217- if (!(vma->vm_flags & VM_EXEC))
218+ if (!(vma->vm_flags & VM_EXEC)) {
219+
220+#ifdef CONFIG_PAX_PAGEEXEC
221+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
222+ goto bad_area;
223+
224+ up_read(&mm->mmap_sem);
225+ switch (pax_handle_fetch_fault(regs)) {
226+
227+#ifdef CONFIG_PAX_EMUPLT
228+ case 2:
229+ case 3:
230+ return;
231+#endif
232+
233+ }
234+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
235+ do_group_exit(SIGKILL);
236+#else
237 goto bad_area;
238+#endif
239+
240+ }
241 } else if (!cause) {
242 /* Allow reads even for write-only mappings */
243 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
244diff -urNp linux-2.6.32.44/arch/arm/include/asm/elf.h linux-2.6.32.44/arch/arm/include/asm/elf.h
245--- linux-2.6.32.44/arch/arm/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
246+++ linux-2.6.32.44/arch/arm/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
247@@ -109,7 +109,14 @@ int dump_task_regs(struct task_struct *t
248 the loader. We need to make sure that it is out of the way of the program
249 that it will "exec", and that there is sufficient room for the brk. */
250
251-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
252+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
253+
254+#ifdef CONFIG_PAX_ASLR
255+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
256+
257+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
258+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
259+#endif
260
261 /* When the program starts, a1 contains a pointer to a function to be
262 registered with atexit, as per the SVR4 ABI. A value of 0 means we
263diff -urNp linux-2.6.32.44/arch/arm/include/asm/kmap_types.h linux-2.6.32.44/arch/arm/include/asm/kmap_types.h
264--- linux-2.6.32.44/arch/arm/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
265+++ linux-2.6.32.44/arch/arm/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
266@@ -19,6 +19,7 @@ enum km_type {
267 KM_SOFTIRQ0,
268 KM_SOFTIRQ1,
269 KM_L2_CACHE,
270+ KM_CLEARPAGE,
271 KM_TYPE_NR
272 };
273
274diff -urNp linux-2.6.32.44/arch/arm/include/asm/uaccess.h linux-2.6.32.44/arch/arm/include/asm/uaccess.h
275--- linux-2.6.32.44/arch/arm/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
276+++ linux-2.6.32.44/arch/arm/include/asm/uaccess.h 2011-06-29 21:02:24.000000000 -0400
277@@ -22,6 +22,8 @@
278 #define VERIFY_READ 0
279 #define VERIFY_WRITE 1
280
281+extern void check_object_size(const void *ptr, unsigned long n, bool to);
282+
283 /*
284 * The exception table consists of pairs of addresses: the first is the
285 * address of an instruction that is allowed to fault, and the second is
286@@ -387,8 +389,23 @@ do { \
287
288
289 #ifdef CONFIG_MMU
290-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
291-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
292+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
293+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
294+
295+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
296+{
297+ if (!__builtin_constant_p(n))
298+ check_object_size(to, n, false);
299+ return ___copy_from_user(to, from, n);
300+}
301+
302+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
303+{
304+ if (!__builtin_constant_p(n))
305+ check_object_size(from, n, true);
306+ return ___copy_to_user(to, from, n);
307+}
308+
309 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
310 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
311 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
312@@ -403,6 +420,9 @@ extern unsigned long __must_check __strn
313
314 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
315 {
316+ if ((long)n < 0)
317+ return n;
318+
319 if (access_ok(VERIFY_READ, from, n))
320 n = __copy_from_user(to, from, n);
321 else /* security hole - plug it */
322@@ -412,6 +432,9 @@ static inline unsigned long __must_check
323
324 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
325 {
326+ if ((long)n < 0)
327+ return n;
328+
329 if (access_ok(VERIFY_WRITE, to, n))
330 n = __copy_to_user(to, from, n);
331 return n;
332diff -urNp linux-2.6.32.44/arch/arm/kernel/armksyms.c linux-2.6.32.44/arch/arm/kernel/armksyms.c
333--- linux-2.6.32.44/arch/arm/kernel/armksyms.c 2011-03-27 14:31:47.000000000 -0400
334+++ linux-2.6.32.44/arch/arm/kernel/armksyms.c 2011-07-06 19:51:50.000000000 -0400
335@@ -118,8 +118,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
336 #ifdef CONFIG_MMU
337 EXPORT_SYMBOL(copy_page);
338
339-EXPORT_SYMBOL(__copy_from_user);
340-EXPORT_SYMBOL(__copy_to_user);
341+EXPORT_SYMBOL(___copy_from_user);
342+EXPORT_SYMBOL(___copy_to_user);
343 EXPORT_SYMBOL(__clear_user);
344
345 EXPORT_SYMBOL(__get_user_1);
346diff -urNp linux-2.6.32.44/arch/arm/kernel/kgdb.c linux-2.6.32.44/arch/arm/kernel/kgdb.c
347--- linux-2.6.32.44/arch/arm/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
348+++ linux-2.6.32.44/arch/arm/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
349@@ -190,7 +190,7 @@ void kgdb_arch_exit(void)
350 * and we handle the normal undef case within the do_undefinstr
351 * handler.
352 */
353-struct kgdb_arch arch_kgdb_ops = {
354+const struct kgdb_arch arch_kgdb_ops = {
355 #ifndef __ARMEB__
356 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
357 #else /* ! __ARMEB__ */
358diff -urNp linux-2.6.32.44/arch/arm/kernel/traps.c linux-2.6.32.44/arch/arm/kernel/traps.c
359--- linux-2.6.32.44/arch/arm/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
360+++ linux-2.6.32.44/arch/arm/kernel/traps.c 2011-06-13 21:31:18.000000000 -0400
361@@ -247,6 +247,8 @@ static void __die(const char *str, int e
362
363 DEFINE_SPINLOCK(die_lock);
364
365+extern void gr_handle_kernel_exploit(void);
366+
367 /*
368 * This function is protected against re-entrancy.
369 */
370@@ -271,6 +273,8 @@ NORET_TYPE void die(const char *str, str
371 if (panic_on_oops)
372 panic("Fatal exception");
373
374+ gr_handle_kernel_exploit();
375+
376 do_exit(SIGSEGV);
377 }
378
379diff -urNp linux-2.6.32.44/arch/arm/lib/copy_from_user.S linux-2.6.32.44/arch/arm/lib/copy_from_user.S
380--- linux-2.6.32.44/arch/arm/lib/copy_from_user.S 2011-03-27 14:31:47.000000000 -0400
381+++ linux-2.6.32.44/arch/arm/lib/copy_from_user.S 2011-06-29 20:48:38.000000000 -0400
382@@ -16,7 +16,7 @@
383 /*
384 * Prototype:
385 *
386- * size_t __copy_from_user(void *to, const void *from, size_t n)
387+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
388 *
389 * Purpose:
390 *
391@@ -84,11 +84,11 @@
392
393 .text
394
395-ENTRY(__copy_from_user)
396+ENTRY(___copy_from_user)
397
398 #include "copy_template.S"
399
400-ENDPROC(__copy_from_user)
401+ENDPROC(___copy_from_user)
402
403 .section .fixup,"ax"
404 .align 0
405diff -urNp linux-2.6.32.44/arch/arm/lib/copy_to_user.S linux-2.6.32.44/arch/arm/lib/copy_to_user.S
406--- linux-2.6.32.44/arch/arm/lib/copy_to_user.S 2011-03-27 14:31:47.000000000 -0400
407+++ linux-2.6.32.44/arch/arm/lib/copy_to_user.S 2011-06-29 20:46:49.000000000 -0400
408@@ -16,7 +16,7 @@
409 /*
410 * Prototype:
411 *
412- * size_t __copy_to_user(void *to, const void *from, size_t n)
413+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
414 *
415 * Purpose:
416 *
417@@ -88,11 +88,11 @@
418 .text
419
420 ENTRY(__copy_to_user_std)
421-WEAK(__copy_to_user)
422+WEAK(___copy_to_user)
423
424 #include "copy_template.S"
425
426-ENDPROC(__copy_to_user)
427+ENDPROC(___copy_to_user)
428
429 .section .fixup,"ax"
430 .align 0
431diff -urNp linux-2.6.32.44/arch/arm/lib/uaccess.S linux-2.6.32.44/arch/arm/lib/uaccess.S
432--- linux-2.6.32.44/arch/arm/lib/uaccess.S 2011-03-27 14:31:47.000000000 -0400
433+++ linux-2.6.32.44/arch/arm/lib/uaccess.S 2011-06-29 20:48:53.000000000 -0400
434@@ -19,7 +19,7 @@
435
436 #define PAGE_SHIFT 12
437
438-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
439+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
440 * Purpose : copy a block to user memory from kernel memory
441 * Params : to - user memory
442 * : from - kernel memory
443@@ -39,7 +39,7 @@ USER( strgtbt r3, [r0], #1) @ May fau
444 sub r2, r2, ip
445 b .Lc2u_dest_aligned
446
447-ENTRY(__copy_to_user)
448+ENTRY(___copy_to_user)
449 stmfd sp!, {r2, r4 - r7, lr}
450 cmp r2, #4
451 blt .Lc2u_not_enough
452@@ -277,14 +277,14 @@ USER( strgebt r3, [r0], #1) @ May fau
453 ldrgtb r3, [r1], #0
454 USER( strgtbt r3, [r0], #1) @ May fault
455 b .Lc2u_finished
456-ENDPROC(__copy_to_user)
457+ENDPROC(___copy_to_user)
458
459 .section .fixup,"ax"
460 .align 0
461 9001: ldmfd sp!, {r0, r4 - r7, pc}
462 .previous
463
464-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
465+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
466 * Purpose : copy a block from user memory to kernel memory
467 * Params : to - kernel memory
468 * : from - user memory
469@@ -303,7 +303,7 @@ USER( ldrgtbt r3, [r1], #1) @ May fau
470 sub r2, r2, ip
471 b .Lcfu_dest_aligned
472
473-ENTRY(__copy_from_user)
474+ENTRY(___copy_from_user)
475 stmfd sp!, {r0, r2, r4 - r7, lr}
476 cmp r2, #4
477 blt .Lcfu_not_enough
478@@ -543,7 +543,7 @@ USER( ldrgebt r3, [r1], #1) @ May fau
479 USER( ldrgtbt r3, [r1], #1) @ May fault
480 strgtb r3, [r0], #1
481 b .Lcfu_finished
482-ENDPROC(__copy_from_user)
483+ENDPROC(___copy_from_user)
484
485 .section .fixup,"ax"
486 .align 0
487diff -urNp linux-2.6.32.44/arch/arm/lib/uaccess_with_memcpy.c linux-2.6.32.44/arch/arm/lib/uaccess_with_memcpy.c
488--- linux-2.6.32.44/arch/arm/lib/uaccess_with_memcpy.c 2011-03-27 14:31:47.000000000 -0400
489+++ linux-2.6.32.44/arch/arm/lib/uaccess_with_memcpy.c 2011-06-29 20:44:35.000000000 -0400
490@@ -97,7 +97,7 @@ out:
491 }
492
493 unsigned long
494-__copy_to_user(void __user *to, const void *from, unsigned long n)
495+___copy_to_user(void __user *to, const void *from, unsigned long n)
496 {
497 /*
498 * This test is stubbed out of the main function above to keep
499diff -urNp linux-2.6.32.44/arch/arm/mach-at91/pm.c linux-2.6.32.44/arch/arm/mach-at91/pm.c
500--- linux-2.6.32.44/arch/arm/mach-at91/pm.c 2011-03-27 14:31:47.000000000 -0400
501+++ linux-2.6.32.44/arch/arm/mach-at91/pm.c 2011-04-17 15:56:45.000000000 -0400
502@@ -348,7 +348,7 @@ static void at91_pm_end(void)
503 }
504
505
506-static struct platform_suspend_ops at91_pm_ops ={
507+static const struct platform_suspend_ops at91_pm_ops ={
508 .valid = at91_pm_valid_state,
509 .begin = at91_pm_begin,
510 .enter = at91_pm_enter,
511diff -urNp linux-2.6.32.44/arch/arm/mach-omap1/pm.c linux-2.6.32.44/arch/arm/mach-omap1/pm.c
512--- linux-2.6.32.44/arch/arm/mach-omap1/pm.c 2011-03-27 14:31:47.000000000 -0400
513+++ linux-2.6.32.44/arch/arm/mach-omap1/pm.c 2011-04-17 15:56:45.000000000 -0400
514@@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq
515
516
517
518-static struct platform_suspend_ops omap_pm_ops ={
519+static const struct platform_suspend_ops omap_pm_ops ={
520 .prepare = omap_pm_prepare,
521 .enter = omap_pm_enter,
522 .finish = omap_pm_finish,
523diff -urNp linux-2.6.32.44/arch/arm/mach-omap2/pm24xx.c linux-2.6.32.44/arch/arm/mach-omap2/pm24xx.c
524--- linux-2.6.32.44/arch/arm/mach-omap2/pm24xx.c 2011-03-27 14:31:47.000000000 -0400
525+++ linux-2.6.32.44/arch/arm/mach-omap2/pm24xx.c 2011-04-17 15:56:45.000000000 -0400
526@@ -326,7 +326,7 @@ static void omap2_pm_finish(void)
527 enable_hlt();
528 }
529
530-static struct platform_suspend_ops omap_pm_ops = {
531+static const struct platform_suspend_ops omap_pm_ops = {
532 .prepare = omap2_pm_prepare,
533 .enter = omap2_pm_enter,
534 .finish = omap2_pm_finish,
535diff -urNp linux-2.6.32.44/arch/arm/mach-omap2/pm34xx.c linux-2.6.32.44/arch/arm/mach-omap2/pm34xx.c
536--- linux-2.6.32.44/arch/arm/mach-omap2/pm34xx.c 2011-03-27 14:31:47.000000000 -0400
537+++ linux-2.6.32.44/arch/arm/mach-omap2/pm34xx.c 2011-04-17 15:56:45.000000000 -0400
538@@ -401,7 +401,7 @@ static void omap3_pm_end(void)
539 return;
540 }
541
542-static struct platform_suspend_ops omap_pm_ops = {
543+static const struct platform_suspend_ops omap_pm_ops = {
544 .begin = omap3_pm_begin,
545 .end = omap3_pm_end,
546 .prepare = omap3_pm_prepare,
547diff -urNp linux-2.6.32.44/arch/arm/mach-pnx4008/pm.c linux-2.6.32.44/arch/arm/mach-pnx4008/pm.c
548--- linux-2.6.32.44/arch/arm/mach-pnx4008/pm.c 2011-03-27 14:31:47.000000000 -0400
549+++ linux-2.6.32.44/arch/arm/mach-pnx4008/pm.c 2011-04-17 15:56:45.000000000 -0400
550@@ -116,7 +116,7 @@ static int pnx4008_pm_valid(suspend_stat
551 (state == PM_SUSPEND_MEM);
552 }
553
554-static struct platform_suspend_ops pnx4008_pm_ops = {
555+static const struct platform_suspend_ops pnx4008_pm_ops = {
556 .enter = pnx4008_pm_enter,
557 .valid = pnx4008_pm_valid,
558 };
559diff -urNp linux-2.6.32.44/arch/arm/mach-pxa/pm.c linux-2.6.32.44/arch/arm/mach-pxa/pm.c
560--- linux-2.6.32.44/arch/arm/mach-pxa/pm.c 2011-03-27 14:31:47.000000000 -0400
561+++ linux-2.6.32.44/arch/arm/mach-pxa/pm.c 2011-04-17 15:56:45.000000000 -0400
562@@ -95,7 +95,7 @@ void pxa_pm_finish(void)
563 pxa_cpu_pm_fns->finish();
564 }
565
566-static struct platform_suspend_ops pxa_pm_ops = {
567+static const struct platform_suspend_ops pxa_pm_ops = {
568 .valid = pxa_pm_valid,
569 .enter = pxa_pm_enter,
570 .prepare = pxa_pm_prepare,
571diff -urNp linux-2.6.32.44/arch/arm/mach-pxa/sharpsl_pm.c linux-2.6.32.44/arch/arm/mach-pxa/sharpsl_pm.c
572--- linux-2.6.32.44/arch/arm/mach-pxa/sharpsl_pm.c 2011-03-27 14:31:47.000000000 -0400
573+++ linux-2.6.32.44/arch/arm/mach-pxa/sharpsl_pm.c 2011-04-17 15:56:45.000000000 -0400
574@@ -891,7 +891,7 @@ static void sharpsl_apm_get_power_status
575 }
576
577 #ifdef CONFIG_PM
578-static struct platform_suspend_ops sharpsl_pm_ops = {
579+static const struct platform_suspend_ops sharpsl_pm_ops = {
580 .prepare = pxa_pm_prepare,
581 .finish = pxa_pm_finish,
582 .enter = corgi_pxa_pm_enter,
583diff -urNp linux-2.6.32.44/arch/arm/mach-sa1100/pm.c linux-2.6.32.44/arch/arm/mach-sa1100/pm.c
584--- linux-2.6.32.44/arch/arm/mach-sa1100/pm.c 2011-03-27 14:31:47.000000000 -0400
585+++ linux-2.6.32.44/arch/arm/mach-sa1100/pm.c 2011-04-17 15:56:45.000000000 -0400
586@@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
587 return virt_to_phys(sp);
588 }
589
590-static struct platform_suspend_ops sa11x0_pm_ops = {
591+static const struct platform_suspend_ops sa11x0_pm_ops = {
592 .enter = sa11x0_pm_enter,
593 .valid = suspend_valid_only_mem,
594 };
595diff -urNp linux-2.6.32.44/arch/arm/mm/fault.c linux-2.6.32.44/arch/arm/mm/fault.c
596--- linux-2.6.32.44/arch/arm/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
597+++ linux-2.6.32.44/arch/arm/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
598@@ -166,6 +166,13 @@ __do_user_fault(struct task_struct *tsk,
599 }
600 #endif
601
602+#ifdef CONFIG_PAX_PAGEEXEC
603+ if (fsr & FSR_LNX_PF) {
604+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
605+ do_group_exit(SIGKILL);
606+ }
607+#endif
608+
609 tsk->thread.address = addr;
610 tsk->thread.error_code = fsr;
611 tsk->thread.trap_no = 14;
612@@ -357,6 +364,33 @@ do_page_fault(unsigned long addr, unsign
613 }
614 #endif /* CONFIG_MMU */
615
616+#ifdef CONFIG_PAX_PAGEEXEC
617+void pax_report_insns(void *pc, void *sp)
618+{
619+ long i;
620+
621+ printk(KERN_ERR "PAX: bytes at PC: ");
622+ for (i = 0; i < 20; i++) {
623+ unsigned char c;
624+ if (get_user(c, (__force unsigned char __user *)pc+i))
625+ printk(KERN_CONT "?? ");
626+ else
627+ printk(KERN_CONT "%02x ", c);
628+ }
629+ printk("\n");
630+
631+ printk(KERN_ERR "PAX: bytes at SP-4: ");
632+ for (i = -1; i < 20; i++) {
633+ unsigned long c;
634+ if (get_user(c, (__force unsigned long __user *)sp+i))
635+ printk(KERN_CONT "???????? ");
636+ else
637+ printk(KERN_CONT "%08lx ", c);
638+ }
639+ printk("\n");
640+}
641+#endif
642+
643 /*
644 * First Level Translation Fault Handler
645 *
646diff -urNp linux-2.6.32.44/arch/arm/mm/mmap.c linux-2.6.32.44/arch/arm/mm/mmap.c
647--- linux-2.6.32.44/arch/arm/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
648+++ linux-2.6.32.44/arch/arm/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
649@@ -63,6 +63,10 @@ arch_get_unmapped_area(struct file *filp
650 if (len > TASK_SIZE)
651 return -ENOMEM;
652
653+#ifdef CONFIG_PAX_RANDMMAP
654+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
655+#endif
656+
657 if (addr) {
658 if (do_align)
659 addr = COLOUR_ALIGN(addr, pgoff);
660@@ -70,15 +74,14 @@ arch_get_unmapped_area(struct file *filp
661 addr = PAGE_ALIGN(addr);
662
663 vma = find_vma(mm, addr);
664- if (TASK_SIZE - len >= addr &&
665- (!vma || addr + len <= vma->vm_start))
666+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
667 return addr;
668 }
669 if (len > mm->cached_hole_size) {
670- start_addr = addr = mm->free_area_cache;
671+ start_addr = addr = mm->free_area_cache;
672 } else {
673- start_addr = addr = TASK_UNMAPPED_BASE;
674- mm->cached_hole_size = 0;
675+ start_addr = addr = mm->mmap_base;
676+ mm->cached_hole_size = 0;
677 }
678
679 full_search:
680@@ -94,14 +97,14 @@ full_search:
681 * Start a new search - just in case we missed
682 * some holes.
683 */
684- if (start_addr != TASK_UNMAPPED_BASE) {
685- start_addr = addr = TASK_UNMAPPED_BASE;
686+ if (start_addr != mm->mmap_base) {
687+ start_addr = addr = mm->mmap_base;
688 mm->cached_hole_size = 0;
689 goto full_search;
690 }
691 return -ENOMEM;
692 }
693- if (!vma || addr + len <= vma->vm_start) {
694+ if (check_heap_stack_gap(vma, addr, len)) {
695 /*
696 * Remember the place where we stopped the search:
697 */
698diff -urNp linux-2.6.32.44/arch/arm/plat-s3c/pm.c linux-2.6.32.44/arch/arm/plat-s3c/pm.c
699--- linux-2.6.32.44/arch/arm/plat-s3c/pm.c 2011-03-27 14:31:47.000000000 -0400
700+++ linux-2.6.32.44/arch/arm/plat-s3c/pm.c 2011-04-17 15:56:45.000000000 -0400
701@@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
702 s3c_pm_check_cleanup();
703 }
704
705-static struct platform_suspend_ops s3c_pm_ops = {
706+static const struct platform_suspend_ops s3c_pm_ops = {
707 .enter = s3c_pm_enter,
708 .prepare = s3c_pm_prepare,
709 .finish = s3c_pm_finish,
710diff -urNp linux-2.6.32.44/arch/avr32/include/asm/elf.h linux-2.6.32.44/arch/avr32/include/asm/elf.h
711--- linux-2.6.32.44/arch/avr32/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
712+++ linux-2.6.32.44/arch/avr32/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
713@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
714 the loader. We need to make sure that it is out of the way of the program
715 that it will "exec", and that there is sufficient room for the brk. */
716
717-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
718+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
719
720+#ifdef CONFIG_PAX_ASLR
721+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
722+
723+#define PAX_DELTA_MMAP_LEN 15
724+#define PAX_DELTA_STACK_LEN 15
725+#endif
726
727 /* This yields a mask that user programs can use to figure out what
728 instruction set this CPU supports. This could be done in user space,
729diff -urNp linux-2.6.32.44/arch/avr32/include/asm/kmap_types.h linux-2.6.32.44/arch/avr32/include/asm/kmap_types.h
730--- linux-2.6.32.44/arch/avr32/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
731+++ linux-2.6.32.44/arch/avr32/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
732@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
733 D(11) KM_IRQ1,
734 D(12) KM_SOFTIRQ0,
735 D(13) KM_SOFTIRQ1,
736-D(14) KM_TYPE_NR
737+D(14) KM_CLEARPAGE,
738+D(15) KM_TYPE_NR
739 };
740
741 #undef D
742diff -urNp linux-2.6.32.44/arch/avr32/mach-at32ap/pm.c linux-2.6.32.44/arch/avr32/mach-at32ap/pm.c
743--- linux-2.6.32.44/arch/avr32/mach-at32ap/pm.c 2011-03-27 14:31:47.000000000 -0400
744+++ linux-2.6.32.44/arch/avr32/mach-at32ap/pm.c 2011-04-17 15:56:45.000000000 -0400
745@@ -176,7 +176,7 @@ out:
746 return 0;
747 }
748
749-static struct platform_suspend_ops avr32_pm_ops = {
750+static const struct platform_suspend_ops avr32_pm_ops = {
751 .valid = avr32_pm_valid_state,
752 .enter = avr32_pm_enter,
753 };
754diff -urNp linux-2.6.32.44/arch/avr32/mm/fault.c linux-2.6.32.44/arch/avr32/mm/fault.c
755--- linux-2.6.32.44/arch/avr32/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
756+++ linux-2.6.32.44/arch/avr32/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
757@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
758
759 int exception_trace = 1;
760
761+#ifdef CONFIG_PAX_PAGEEXEC
762+void pax_report_insns(void *pc, void *sp)
763+{
764+ unsigned long i;
765+
766+ printk(KERN_ERR "PAX: bytes at PC: ");
767+ for (i = 0; i < 20; i++) {
768+ unsigned char c;
769+ if (get_user(c, (unsigned char *)pc+i))
770+ printk(KERN_CONT "???????? ");
771+ else
772+ printk(KERN_CONT "%02x ", c);
773+ }
774+ printk("\n");
775+}
776+#endif
777+
778 /*
779 * This routine handles page faults. It determines the address and the
780 * problem, and then passes it off to one of the appropriate routines.
781@@ -157,6 +174,16 @@ bad_area:
782 up_read(&mm->mmap_sem);
783
784 if (user_mode(regs)) {
785+
786+#ifdef CONFIG_PAX_PAGEEXEC
787+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
788+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
789+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
790+ do_group_exit(SIGKILL);
791+ }
792+ }
793+#endif
794+
795 if (exception_trace && printk_ratelimit())
796 printk("%s%s[%d]: segfault at %08lx pc %08lx "
797 "sp %08lx ecr %lu\n",
798diff -urNp linux-2.6.32.44/arch/blackfin/kernel/kgdb.c linux-2.6.32.44/arch/blackfin/kernel/kgdb.c
799--- linux-2.6.32.44/arch/blackfin/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
800+++ linux-2.6.32.44/arch/blackfin/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
801@@ -428,7 +428,7 @@ int kgdb_arch_handle_exception(int vecto
802 return -1; /* this means that we do not want to exit from the handler */
803 }
804
805-struct kgdb_arch arch_kgdb_ops = {
806+const struct kgdb_arch arch_kgdb_ops = {
807 .gdb_bpt_instr = {0xa1},
808 #ifdef CONFIG_SMP
809 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
810diff -urNp linux-2.6.32.44/arch/blackfin/mach-common/pm.c linux-2.6.32.44/arch/blackfin/mach-common/pm.c
811--- linux-2.6.32.44/arch/blackfin/mach-common/pm.c 2011-03-27 14:31:47.000000000 -0400
812+++ linux-2.6.32.44/arch/blackfin/mach-common/pm.c 2011-04-17 15:56:45.000000000 -0400
813@@ -255,7 +255,7 @@ static int bfin_pm_enter(suspend_state_t
814 return 0;
815 }
816
817-struct platform_suspend_ops bfin_pm_ops = {
818+const struct platform_suspend_ops bfin_pm_ops = {
819 .enter = bfin_pm_enter,
820 .valid = bfin_pm_valid,
821 };
822diff -urNp linux-2.6.32.44/arch/frv/include/asm/kmap_types.h linux-2.6.32.44/arch/frv/include/asm/kmap_types.h
823--- linux-2.6.32.44/arch/frv/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
824+++ linux-2.6.32.44/arch/frv/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
825@@ -23,6 +23,7 @@ enum km_type {
826 KM_IRQ1,
827 KM_SOFTIRQ0,
828 KM_SOFTIRQ1,
829+ KM_CLEARPAGE,
830 KM_TYPE_NR
831 };
832
833diff -urNp linux-2.6.32.44/arch/frv/mm/elf-fdpic.c linux-2.6.32.44/arch/frv/mm/elf-fdpic.c
834--- linux-2.6.32.44/arch/frv/mm/elf-fdpic.c 2011-03-27 14:31:47.000000000 -0400
835+++ linux-2.6.32.44/arch/frv/mm/elf-fdpic.c 2011-04-17 15:56:45.000000000 -0400
836@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
837 if (addr) {
838 addr = PAGE_ALIGN(addr);
839 vma = find_vma(current->mm, addr);
840- if (TASK_SIZE - len >= addr &&
841- (!vma || addr + len <= vma->vm_start))
842+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
843 goto success;
844 }
845
846@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
847 for (; vma; vma = vma->vm_next) {
848 if (addr > limit)
849 break;
850- if (addr + len <= vma->vm_start)
851+ if (check_heap_stack_gap(vma, addr, len))
852 goto success;
853 addr = vma->vm_end;
854 }
855@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
856 for (; vma; vma = vma->vm_next) {
857 if (addr > limit)
858 break;
859- if (addr + len <= vma->vm_start)
860+ if (check_heap_stack_gap(vma, addr, len))
861 goto success;
862 addr = vma->vm_end;
863 }
864diff -urNp linux-2.6.32.44/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.32.44/arch/ia64/hp/common/hwsw_iommu.c
865--- linux-2.6.32.44/arch/ia64/hp/common/hwsw_iommu.c 2011-03-27 14:31:47.000000000 -0400
866+++ linux-2.6.32.44/arch/ia64/hp/common/hwsw_iommu.c 2011-04-17 15:56:45.000000000 -0400
867@@ -17,7 +17,7 @@
868 #include <linux/swiotlb.h>
869 #include <asm/machvec.h>
870
871-extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
872+extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
873
874 /* swiotlb declarations & definitions: */
875 extern int swiotlb_late_init_with_default_size (size_t size);
876@@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
877 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
878 }
879
880-struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
881+const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
882 {
883 if (use_swiotlb(dev))
884 return &swiotlb_dma_ops;
885diff -urNp linux-2.6.32.44/arch/ia64/hp/common/sba_iommu.c linux-2.6.32.44/arch/ia64/hp/common/sba_iommu.c
886--- linux-2.6.32.44/arch/ia64/hp/common/sba_iommu.c 2011-03-27 14:31:47.000000000 -0400
887+++ linux-2.6.32.44/arch/ia64/hp/common/sba_iommu.c 2011-04-17 15:56:45.000000000 -0400
888@@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
889 },
890 };
891
892-extern struct dma_map_ops swiotlb_dma_ops;
893+extern const struct dma_map_ops swiotlb_dma_ops;
894
895 static int __init
896 sba_init(void)
897@@ -2211,7 +2211,7 @@ sba_page_override(char *str)
898
899 __setup("sbapagesize=",sba_page_override);
900
901-struct dma_map_ops sba_dma_ops = {
902+const struct dma_map_ops sba_dma_ops = {
903 .alloc_coherent = sba_alloc_coherent,
904 .free_coherent = sba_free_coherent,
905 .map_page = sba_map_page,
906diff -urNp linux-2.6.32.44/arch/ia64/ia32/binfmt_elf32.c linux-2.6.32.44/arch/ia64/ia32/binfmt_elf32.c
907--- linux-2.6.32.44/arch/ia64/ia32/binfmt_elf32.c 2011-03-27 14:31:47.000000000 -0400
908+++ linux-2.6.32.44/arch/ia64/ia32/binfmt_elf32.c 2011-04-17 15:56:45.000000000 -0400
909@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
910
911 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
912
913+#ifdef CONFIG_PAX_ASLR
914+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
915+
916+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
917+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
918+#endif
919+
920 /* Ugly but avoids duplication */
921 #include "../../../fs/binfmt_elf.c"
922
923diff -urNp linux-2.6.32.44/arch/ia64/ia32/ia32priv.h linux-2.6.32.44/arch/ia64/ia32/ia32priv.h
924--- linux-2.6.32.44/arch/ia64/ia32/ia32priv.h 2011-03-27 14:31:47.000000000 -0400
925+++ linux-2.6.32.44/arch/ia64/ia32/ia32priv.h 2011-04-17 15:56:45.000000000 -0400
926@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
927 #define ELF_DATA ELFDATA2LSB
928 #define ELF_ARCH EM_386
929
930-#define IA32_STACK_TOP IA32_PAGE_OFFSET
931+#ifdef CONFIG_PAX_RANDUSTACK
932+#define __IA32_DELTA_STACK (current->mm->delta_stack)
933+#else
934+#define __IA32_DELTA_STACK 0UL
935+#endif
936+
937+#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
938+
939 #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
940 #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
941
942diff -urNp linux-2.6.32.44/arch/ia64/include/asm/dma-mapping.h linux-2.6.32.44/arch/ia64/include/asm/dma-mapping.h
943--- linux-2.6.32.44/arch/ia64/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
944+++ linux-2.6.32.44/arch/ia64/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
945@@ -12,7 +12,7 @@
946
947 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
948
949-extern struct dma_map_ops *dma_ops;
950+extern const struct dma_map_ops *dma_ops;
951 extern struct ia64_machine_vector ia64_mv;
952 extern void set_iommu_machvec(void);
953
954@@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct d
955 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
956 dma_addr_t *daddr, gfp_t gfp)
957 {
958- struct dma_map_ops *ops = platform_dma_get_ops(dev);
959+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
960 void *caddr;
961
962 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
963@@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(s
964 static inline void dma_free_coherent(struct device *dev, size_t size,
965 void *caddr, dma_addr_t daddr)
966 {
967- struct dma_map_ops *ops = platform_dma_get_ops(dev);
968+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
969 debug_dma_free_coherent(dev, size, caddr, daddr);
970 ops->free_coherent(dev, size, caddr, daddr);
971 }
972@@ -49,13 +49,13 @@ static inline void dma_free_coherent(str
973
974 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
975 {
976- struct dma_map_ops *ops = platform_dma_get_ops(dev);
977+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
978 return ops->mapping_error(dev, daddr);
979 }
980
981 static inline int dma_supported(struct device *dev, u64 mask)
982 {
983- struct dma_map_ops *ops = platform_dma_get_ops(dev);
984+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
985 return ops->dma_supported(dev, mask);
986 }
987
988diff -urNp linux-2.6.32.44/arch/ia64/include/asm/elf.h linux-2.6.32.44/arch/ia64/include/asm/elf.h
989--- linux-2.6.32.44/arch/ia64/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
990+++ linux-2.6.32.44/arch/ia64/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
991@@ -43,6 +43,13 @@
992 */
993 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
994
995+#ifdef CONFIG_PAX_ASLR
996+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
997+
998+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
999+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1000+#endif
1001+
1002 #define PT_IA_64_UNWIND 0x70000001
1003
1004 /* IA-64 relocations: */
1005diff -urNp linux-2.6.32.44/arch/ia64/include/asm/machvec.h linux-2.6.32.44/arch/ia64/include/asm/machvec.h
1006--- linux-2.6.32.44/arch/ia64/include/asm/machvec.h 2011-03-27 14:31:47.000000000 -0400
1007+++ linux-2.6.32.44/arch/ia64/include/asm/machvec.h 2011-04-17 15:56:45.000000000 -0400
1008@@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1009 /* DMA-mapping interface: */
1010 typedef void ia64_mv_dma_init (void);
1011 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1012-typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1013+typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1014
1015 /*
1016 * WARNING: The legacy I/O space is _architected_. Platforms are
1017@@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1018 # endif /* CONFIG_IA64_GENERIC */
1019
1020 extern void swiotlb_dma_init(void);
1021-extern struct dma_map_ops *dma_get_ops(struct device *);
1022+extern const struct dma_map_ops *dma_get_ops(struct device *);
1023
1024 /*
1025 * Define default versions so we can extend machvec for new platforms without having
1026diff -urNp linux-2.6.32.44/arch/ia64/include/asm/pgtable.h linux-2.6.32.44/arch/ia64/include/asm/pgtable.h
1027--- linux-2.6.32.44/arch/ia64/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1028+++ linux-2.6.32.44/arch/ia64/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1029@@ -12,7 +12,7 @@
1030 * David Mosberger-Tang <davidm@hpl.hp.com>
1031 */
1032
1033-
1034+#include <linux/const.h>
1035 #include <asm/mman.h>
1036 #include <asm/page.h>
1037 #include <asm/processor.h>
1038@@ -143,6 +143,17 @@
1039 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1040 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1041 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1042+
1043+#ifdef CONFIG_PAX_PAGEEXEC
1044+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1045+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1046+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1047+#else
1048+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1049+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1050+# define PAGE_COPY_NOEXEC PAGE_COPY
1051+#endif
1052+
1053 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1054 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1055 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1056diff -urNp linux-2.6.32.44/arch/ia64/include/asm/spinlock.h linux-2.6.32.44/arch/ia64/include/asm/spinlock.h
1057--- linux-2.6.32.44/arch/ia64/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
1058+++ linux-2.6.32.44/arch/ia64/include/asm/spinlock.h 2011-04-17 15:56:45.000000000 -0400
1059@@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1060 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1061
1062 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1063- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1064+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1065 }
1066
1067 static __always_inline void __ticket_spin_unlock_wait(raw_spinlock_t *lock)
1068diff -urNp linux-2.6.32.44/arch/ia64/include/asm/uaccess.h linux-2.6.32.44/arch/ia64/include/asm/uaccess.h
1069--- linux-2.6.32.44/arch/ia64/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
1070+++ linux-2.6.32.44/arch/ia64/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
1071@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1072 const void *__cu_from = (from); \
1073 long __cu_len = (n); \
1074 \
1075- if (__access_ok(__cu_to, __cu_len, get_fs())) \
1076+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1077 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1078 __cu_len; \
1079 })
1080@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1081 long __cu_len = (n); \
1082 \
1083 __chk_user_ptr(__cu_from); \
1084- if (__access_ok(__cu_from, __cu_len, get_fs())) \
1085+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1086 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1087 __cu_len; \
1088 })
1089diff -urNp linux-2.6.32.44/arch/ia64/kernel/dma-mapping.c linux-2.6.32.44/arch/ia64/kernel/dma-mapping.c
1090--- linux-2.6.32.44/arch/ia64/kernel/dma-mapping.c 2011-03-27 14:31:47.000000000 -0400
1091+++ linux-2.6.32.44/arch/ia64/kernel/dma-mapping.c 2011-04-17 15:56:45.000000000 -0400
1092@@ -3,7 +3,7 @@
1093 /* Set this to 1 if there is a HW IOMMU in the system */
1094 int iommu_detected __read_mostly;
1095
1096-struct dma_map_ops *dma_ops;
1097+const struct dma_map_ops *dma_ops;
1098 EXPORT_SYMBOL(dma_ops);
1099
1100 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1101@@ -16,7 +16,7 @@ static int __init dma_init(void)
1102 }
1103 fs_initcall(dma_init);
1104
1105-struct dma_map_ops *dma_get_ops(struct device *dev)
1106+const struct dma_map_ops *dma_get_ops(struct device *dev)
1107 {
1108 return dma_ops;
1109 }
1110diff -urNp linux-2.6.32.44/arch/ia64/kernel/module.c linux-2.6.32.44/arch/ia64/kernel/module.c
1111--- linux-2.6.32.44/arch/ia64/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
1112+++ linux-2.6.32.44/arch/ia64/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
1113@@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1114 void
1115 module_free (struct module *mod, void *module_region)
1116 {
1117- if (mod && mod->arch.init_unw_table &&
1118- module_region == mod->module_init) {
1119+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1120 unw_remove_unwind_table(mod->arch.init_unw_table);
1121 mod->arch.init_unw_table = NULL;
1122 }
1123@@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1124 }
1125
1126 static inline int
1127+in_init_rx (const struct module *mod, uint64_t addr)
1128+{
1129+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1130+}
1131+
1132+static inline int
1133+in_init_rw (const struct module *mod, uint64_t addr)
1134+{
1135+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1136+}
1137+
1138+static inline int
1139 in_init (const struct module *mod, uint64_t addr)
1140 {
1141- return addr - (uint64_t) mod->module_init < mod->init_size;
1142+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1143+}
1144+
1145+static inline int
1146+in_core_rx (const struct module *mod, uint64_t addr)
1147+{
1148+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1149+}
1150+
1151+static inline int
1152+in_core_rw (const struct module *mod, uint64_t addr)
1153+{
1154+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1155 }
1156
1157 static inline int
1158 in_core (const struct module *mod, uint64_t addr)
1159 {
1160- return addr - (uint64_t) mod->module_core < mod->core_size;
1161+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1162 }
1163
1164 static inline int
1165@@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1166 break;
1167
1168 case RV_BDREL:
1169- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1170+ if (in_init_rx(mod, val))
1171+ val -= (uint64_t) mod->module_init_rx;
1172+ else if (in_init_rw(mod, val))
1173+ val -= (uint64_t) mod->module_init_rw;
1174+ else if (in_core_rx(mod, val))
1175+ val -= (uint64_t) mod->module_core_rx;
1176+ else if (in_core_rw(mod, val))
1177+ val -= (uint64_t) mod->module_core_rw;
1178 break;
1179
1180 case RV_LTV:
1181@@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1182 * addresses have been selected...
1183 */
1184 uint64_t gp;
1185- if (mod->core_size > MAX_LTOFF)
1186+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1187 /*
1188 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1189 * at the end of the module.
1190 */
1191- gp = mod->core_size - MAX_LTOFF / 2;
1192+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1193 else
1194- gp = mod->core_size / 2;
1195- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1196+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1197+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1198 mod->arch.gp = gp;
1199 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1200 }
1201diff -urNp linux-2.6.32.44/arch/ia64/kernel/pci-dma.c linux-2.6.32.44/arch/ia64/kernel/pci-dma.c
1202--- linux-2.6.32.44/arch/ia64/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
1203+++ linux-2.6.32.44/arch/ia64/kernel/pci-dma.c 2011-04-17 15:56:45.000000000 -0400
1204@@ -43,7 +43,7 @@ struct device fallback_dev = {
1205 .dma_mask = &fallback_dev.coherent_dma_mask,
1206 };
1207
1208-extern struct dma_map_ops intel_dma_ops;
1209+extern const struct dma_map_ops intel_dma_ops;
1210
1211 static int __init pci_iommu_init(void)
1212 {
1213@@ -96,15 +96,34 @@ int iommu_dma_supported(struct device *d
1214 }
1215 EXPORT_SYMBOL(iommu_dma_supported);
1216
1217+extern void *intel_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags);
1218+extern void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
1219+extern int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1220+extern void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1221+extern dma_addr_t intel_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1222+extern void intel_unmap_page(struct device *dev, dma_addr_t dev_addr, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1223+extern int intel_mapping_error(struct device *dev, dma_addr_t dma_addr);
1224+
1225+static const struct dma_map_ops intel_iommu_dma_ops = {
1226+ /* from drivers/pci/intel-iommu.c:intel_dma_ops */
1227+ .alloc_coherent = intel_alloc_coherent,
1228+ .free_coherent = intel_free_coherent,
1229+ .map_sg = intel_map_sg,
1230+ .unmap_sg = intel_unmap_sg,
1231+ .map_page = intel_map_page,
1232+ .unmap_page = intel_unmap_page,
1233+ .mapping_error = intel_mapping_error,
1234+
1235+ .sync_single_for_cpu = machvec_dma_sync_single,
1236+ .sync_sg_for_cpu = machvec_dma_sync_sg,
1237+ .sync_single_for_device = machvec_dma_sync_single,
1238+ .sync_sg_for_device = machvec_dma_sync_sg,
1239+ .dma_supported = iommu_dma_supported,
1240+};
1241+
1242 void __init pci_iommu_alloc(void)
1243 {
1244- dma_ops = &intel_dma_ops;
1245-
1246- dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
1247- dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
1248- dma_ops->sync_single_for_device = machvec_dma_sync_single;
1249- dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
1250- dma_ops->dma_supported = iommu_dma_supported;
1251+ dma_ops = &intel_iommu_dma_ops;
1252
1253 /*
1254 * The order of these functions is important for
1255diff -urNp linux-2.6.32.44/arch/ia64/kernel/pci-swiotlb.c linux-2.6.32.44/arch/ia64/kernel/pci-swiotlb.c
1256--- linux-2.6.32.44/arch/ia64/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
1257+++ linux-2.6.32.44/arch/ia64/kernel/pci-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
1258@@ -21,7 +21,7 @@ static void *ia64_swiotlb_alloc_coherent
1259 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1260 }
1261
1262-struct dma_map_ops swiotlb_dma_ops = {
1263+const struct dma_map_ops swiotlb_dma_ops = {
1264 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1265 .free_coherent = swiotlb_free_coherent,
1266 .map_page = swiotlb_map_page,
1267diff -urNp linux-2.6.32.44/arch/ia64/kernel/sys_ia64.c linux-2.6.32.44/arch/ia64/kernel/sys_ia64.c
1268--- linux-2.6.32.44/arch/ia64/kernel/sys_ia64.c 2011-03-27 14:31:47.000000000 -0400
1269+++ linux-2.6.32.44/arch/ia64/kernel/sys_ia64.c 2011-04-17 15:56:45.000000000 -0400
1270@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1271 if (REGION_NUMBER(addr) == RGN_HPAGE)
1272 addr = 0;
1273 #endif
1274+
1275+#ifdef CONFIG_PAX_RANDMMAP
1276+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1277+ addr = mm->free_area_cache;
1278+ else
1279+#endif
1280+
1281 if (!addr)
1282 addr = mm->free_area_cache;
1283
1284@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1285 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1286 /* At this point: (!vma || addr < vma->vm_end). */
1287 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1288- if (start_addr != TASK_UNMAPPED_BASE) {
1289+ if (start_addr != mm->mmap_base) {
1290 /* Start a new search --- just in case we missed some holes. */
1291- addr = TASK_UNMAPPED_BASE;
1292+ addr = mm->mmap_base;
1293 goto full_search;
1294 }
1295 return -ENOMEM;
1296 }
1297- if (!vma || addr + len <= vma->vm_start) {
1298+ if (check_heap_stack_gap(vma, addr, len)) {
1299 /* Remember the address where we stopped this search: */
1300 mm->free_area_cache = addr + len;
1301 return addr;
1302diff -urNp linux-2.6.32.44/arch/ia64/kernel/topology.c linux-2.6.32.44/arch/ia64/kernel/topology.c
1303--- linux-2.6.32.44/arch/ia64/kernel/topology.c 2011-03-27 14:31:47.000000000 -0400
1304+++ linux-2.6.32.44/arch/ia64/kernel/topology.c 2011-04-17 15:56:45.000000000 -0400
1305@@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject
1306 return ret;
1307 }
1308
1309-static struct sysfs_ops cache_sysfs_ops = {
1310+static const struct sysfs_ops cache_sysfs_ops = {
1311 .show = cache_show
1312 };
1313
1314diff -urNp linux-2.6.32.44/arch/ia64/kernel/vmlinux.lds.S linux-2.6.32.44/arch/ia64/kernel/vmlinux.lds.S
1315--- linux-2.6.32.44/arch/ia64/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
1316+++ linux-2.6.32.44/arch/ia64/kernel/vmlinux.lds.S 2011-04-17 15:56:45.000000000 -0400
1317@@ -190,7 +190,7 @@ SECTIONS
1318 /* Per-cpu data: */
1319 . = ALIGN(PERCPU_PAGE_SIZE);
1320 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1321- __phys_per_cpu_start = __per_cpu_load;
1322+ __phys_per_cpu_start = per_cpu_load;
1323 . = __phys_per_cpu_start + PERCPU_PAGE_SIZE; /* ensure percpu data fits
1324 * into percpu page size
1325 */
1326diff -urNp linux-2.6.32.44/arch/ia64/mm/fault.c linux-2.6.32.44/arch/ia64/mm/fault.c
1327--- linux-2.6.32.44/arch/ia64/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1328+++ linux-2.6.32.44/arch/ia64/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1329@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1330 return pte_present(pte);
1331 }
1332
1333+#ifdef CONFIG_PAX_PAGEEXEC
1334+void pax_report_insns(void *pc, void *sp)
1335+{
1336+ unsigned long i;
1337+
1338+ printk(KERN_ERR "PAX: bytes at PC: ");
1339+ for (i = 0; i < 8; i++) {
1340+ unsigned int c;
1341+ if (get_user(c, (unsigned int *)pc+i))
1342+ printk(KERN_CONT "???????? ");
1343+ else
1344+ printk(KERN_CONT "%08x ", c);
1345+ }
1346+ printk("\n");
1347+}
1348+#endif
1349+
1350 void __kprobes
1351 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1352 {
1353@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1354 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1355 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1356
1357- if ((vma->vm_flags & mask) != mask)
1358+ if ((vma->vm_flags & mask) != mask) {
1359+
1360+#ifdef CONFIG_PAX_PAGEEXEC
1361+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1362+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1363+ goto bad_area;
1364+
1365+ up_read(&mm->mmap_sem);
1366+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1367+ do_group_exit(SIGKILL);
1368+ }
1369+#endif
1370+
1371 goto bad_area;
1372
1373+ }
1374+
1375 survive:
1376 /*
1377 * If for any reason at all we couldn't handle the fault, make
1378diff -urNp linux-2.6.32.44/arch/ia64/mm/hugetlbpage.c linux-2.6.32.44/arch/ia64/mm/hugetlbpage.c
1379--- linux-2.6.32.44/arch/ia64/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
1380+++ linux-2.6.32.44/arch/ia64/mm/hugetlbpage.c 2011-04-17 15:56:45.000000000 -0400
1381@@ -172,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(
1382 /* At this point: (!vmm || addr < vmm->vm_end). */
1383 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1384 return -ENOMEM;
1385- if (!vmm || (addr + len) <= vmm->vm_start)
1386+ if (check_heap_stack_gap(vmm, addr, len))
1387 return addr;
1388 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1389 }
1390diff -urNp linux-2.6.32.44/arch/ia64/mm/init.c linux-2.6.32.44/arch/ia64/mm/init.c
1391--- linux-2.6.32.44/arch/ia64/mm/init.c 2011-03-27 14:31:47.000000000 -0400
1392+++ linux-2.6.32.44/arch/ia64/mm/init.c 2011-04-17 15:56:45.000000000 -0400
1393@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1394 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1395 vma->vm_end = vma->vm_start + PAGE_SIZE;
1396 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1397+
1398+#ifdef CONFIG_PAX_PAGEEXEC
1399+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1400+ vma->vm_flags &= ~VM_EXEC;
1401+
1402+#ifdef CONFIG_PAX_MPROTECT
1403+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
1404+ vma->vm_flags &= ~VM_MAYEXEC;
1405+#endif
1406+
1407+ }
1408+#endif
1409+
1410 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1411 down_write(&current->mm->mmap_sem);
1412 if (insert_vm_struct(current->mm, vma)) {
1413diff -urNp linux-2.6.32.44/arch/ia64/sn/pci/pci_dma.c linux-2.6.32.44/arch/ia64/sn/pci/pci_dma.c
1414--- linux-2.6.32.44/arch/ia64/sn/pci/pci_dma.c 2011-03-27 14:31:47.000000000 -0400
1415+++ linux-2.6.32.44/arch/ia64/sn/pci/pci_dma.c 2011-04-17 15:56:45.000000000 -0400
1416@@ -464,7 +464,7 @@ int sn_pci_legacy_write(struct pci_bus *
1417 return ret;
1418 }
1419
1420-static struct dma_map_ops sn_dma_ops = {
1421+static const struct dma_map_ops sn_dma_ops = {
1422 .alloc_coherent = sn_dma_alloc_coherent,
1423 .free_coherent = sn_dma_free_coherent,
1424 .map_page = sn_dma_map_page,
1425diff -urNp linux-2.6.32.44/arch/m32r/lib/usercopy.c linux-2.6.32.44/arch/m32r/lib/usercopy.c
1426--- linux-2.6.32.44/arch/m32r/lib/usercopy.c 2011-03-27 14:31:47.000000000 -0400
1427+++ linux-2.6.32.44/arch/m32r/lib/usercopy.c 2011-04-17 15:56:45.000000000 -0400
1428@@ -14,6 +14,9 @@
1429 unsigned long
1430 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1431 {
1432+ if ((long)n < 0)
1433+ return n;
1434+
1435 prefetch(from);
1436 if (access_ok(VERIFY_WRITE, to, n))
1437 __copy_user(to,from,n);
1438@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1439 unsigned long
1440 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1441 {
1442+ if ((long)n < 0)
1443+ return n;
1444+
1445 prefetchw(to);
1446 if (access_ok(VERIFY_READ, from, n))
1447 __copy_user_zeroing(to,from,n);
1448diff -urNp linux-2.6.32.44/arch/mips/alchemy/devboards/pm.c linux-2.6.32.44/arch/mips/alchemy/devboards/pm.c
1449--- linux-2.6.32.44/arch/mips/alchemy/devboards/pm.c 2011-03-27 14:31:47.000000000 -0400
1450+++ linux-2.6.32.44/arch/mips/alchemy/devboards/pm.c 2011-04-17 15:56:45.000000000 -0400
1451@@ -78,7 +78,7 @@ static void db1x_pm_end(void)
1452
1453 }
1454
1455-static struct platform_suspend_ops db1x_pm_ops = {
1456+static const struct platform_suspend_ops db1x_pm_ops = {
1457 .valid = suspend_valid_only_mem,
1458 .begin = db1x_pm_begin,
1459 .enter = db1x_pm_enter,
1460diff -urNp linux-2.6.32.44/arch/mips/include/asm/elf.h linux-2.6.32.44/arch/mips/include/asm/elf.h
1461--- linux-2.6.32.44/arch/mips/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1462+++ linux-2.6.32.44/arch/mips/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1463@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
1464 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1465 #endif
1466
1467+#ifdef CONFIG_PAX_ASLR
1468+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1469+
1470+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1471+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1472+#endif
1473+
1474 #endif /* _ASM_ELF_H */
1475diff -urNp linux-2.6.32.44/arch/mips/include/asm/page.h linux-2.6.32.44/arch/mips/include/asm/page.h
1476--- linux-2.6.32.44/arch/mips/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
1477+++ linux-2.6.32.44/arch/mips/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
1478@@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
1479 #ifdef CONFIG_CPU_MIPS32
1480 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1481 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1482- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1483+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1484 #else
1485 typedef struct { unsigned long long pte; } pte_t;
1486 #define pte_val(x) ((x).pte)
1487diff -urNp linux-2.6.32.44/arch/mips/include/asm/system.h linux-2.6.32.44/arch/mips/include/asm/system.h
1488--- linux-2.6.32.44/arch/mips/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
1489+++ linux-2.6.32.44/arch/mips/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
1490@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1491 */
1492 #define __ARCH_WANT_UNLOCKED_CTXSW
1493
1494-extern unsigned long arch_align_stack(unsigned long sp);
1495+#define arch_align_stack(x) ((x) & ~0xfUL)
1496
1497 #endif /* _ASM_SYSTEM_H */
1498diff -urNp linux-2.6.32.44/arch/mips/kernel/binfmt_elfn32.c linux-2.6.32.44/arch/mips/kernel/binfmt_elfn32.c
1499--- linux-2.6.32.44/arch/mips/kernel/binfmt_elfn32.c 2011-03-27 14:31:47.000000000 -0400
1500+++ linux-2.6.32.44/arch/mips/kernel/binfmt_elfn32.c 2011-04-17 15:56:45.000000000 -0400
1501@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1502 #undef ELF_ET_DYN_BASE
1503 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1504
1505+#ifdef CONFIG_PAX_ASLR
1506+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1507+
1508+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1509+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1510+#endif
1511+
1512 #include <asm/processor.h>
1513 #include <linux/module.h>
1514 #include <linux/elfcore.h>
1515diff -urNp linux-2.6.32.44/arch/mips/kernel/binfmt_elfo32.c linux-2.6.32.44/arch/mips/kernel/binfmt_elfo32.c
1516--- linux-2.6.32.44/arch/mips/kernel/binfmt_elfo32.c 2011-03-27 14:31:47.000000000 -0400
1517+++ linux-2.6.32.44/arch/mips/kernel/binfmt_elfo32.c 2011-04-17 15:56:45.000000000 -0400
1518@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1519 #undef ELF_ET_DYN_BASE
1520 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1521
1522+#ifdef CONFIG_PAX_ASLR
1523+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1524+
1525+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1526+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1527+#endif
1528+
1529 #include <asm/processor.h>
1530
1531 /*
1532diff -urNp linux-2.6.32.44/arch/mips/kernel/kgdb.c linux-2.6.32.44/arch/mips/kernel/kgdb.c
1533--- linux-2.6.32.44/arch/mips/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
1534+++ linux-2.6.32.44/arch/mips/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
1535@@ -245,6 +245,7 @@ int kgdb_arch_handle_exception(int vecto
1536 return -1;
1537 }
1538
1539+/* cannot be const */
1540 struct kgdb_arch arch_kgdb_ops;
1541
1542 /*
1543diff -urNp linux-2.6.32.44/arch/mips/kernel/process.c linux-2.6.32.44/arch/mips/kernel/process.c
1544--- linux-2.6.32.44/arch/mips/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
1545+++ linux-2.6.32.44/arch/mips/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
1546@@ -470,15 +470,3 @@ unsigned long get_wchan(struct task_stru
1547 out:
1548 return pc;
1549 }
1550-
1551-/*
1552- * Don't forget that the stack pointer must be aligned on a 8 bytes
1553- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1554- */
1555-unsigned long arch_align_stack(unsigned long sp)
1556-{
1557- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1558- sp -= get_random_int() & ~PAGE_MASK;
1559-
1560- return sp & ALMASK;
1561-}
1562diff -urNp linux-2.6.32.44/arch/mips/kernel/syscall.c linux-2.6.32.44/arch/mips/kernel/syscall.c
1563--- linux-2.6.32.44/arch/mips/kernel/syscall.c 2011-03-27 14:31:47.000000000 -0400
1564+++ linux-2.6.32.44/arch/mips/kernel/syscall.c 2011-04-17 15:56:45.000000000 -0400
1565@@ -102,17 +102,21 @@ unsigned long arch_get_unmapped_area(str
1566 do_color_align = 0;
1567 if (filp || (flags & MAP_SHARED))
1568 do_color_align = 1;
1569+
1570+#ifdef CONFIG_PAX_RANDMMAP
1571+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1572+#endif
1573+
1574 if (addr) {
1575 if (do_color_align)
1576 addr = COLOUR_ALIGN(addr, pgoff);
1577 else
1578 addr = PAGE_ALIGN(addr);
1579 vmm = find_vma(current->mm, addr);
1580- if (task_size - len >= addr &&
1581- (!vmm || addr + len <= vmm->vm_start))
1582+ if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
1583 return addr;
1584 }
1585- addr = TASK_UNMAPPED_BASE;
1586+ addr = current->mm->mmap_base;
1587 if (do_color_align)
1588 addr = COLOUR_ALIGN(addr, pgoff);
1589 else
1590@@ -122,7 +126,7 @@ unsigned long arch_get_unmapped_area(str
1591 /* At this point: (!vmm || addr < vmm->vm_end). */
1592 if (task_size - len < addr)
1593 return -ENOMEM;
1594- if (!vmm || addr + len <= vmm->vm_start)
1595+ if (check_heap_stack_gap(vmm, addr, len))
1596 return addr;
1597 addr = vmm->vm_end;
1598 if (do_color_align)
1599diff -urNp linux-2.6.32.44/arch/mips/mm/fault.c linux-2.6.32.44/arch/mips/mm/fault.c
1600--- linux-2.6.32.44/arch/mips/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1601+++ linux-2.6.32.44/arch/mips/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1602@@ -26,6 +26,23 @@
1603 #include <asm/ptrace.h>
1604 #include <asm/highmem.h> /* For VMALLOC_END */
1605
1606+#ifdef CONFIG_PAX_PAGEEXEC
1607+void pax_report_insns(void *pc, void *sp)
1608+{
1609+ unsigned long i;
1610+
1611+ printk(KERN_ERR "PAX: bytes at PC: ");
1612+ for (i = 0; i < 5; i++) {
1613+ unsigned int c;
1614+ if (get_user(c, (unsigned int *)pc+i))
1615+ printk(KERN_CONT "???????? ");
1616+ else
1617+ printk(KERN_CONT "%08x ", c);
1618+ }
1619+ printk("\n");
1620+}
1621+#endif
1622+
1623 /*
1624 * This routine handles page faults. It determines the address,
1625 * and the problem, and then passes it off to one of the appropriate
1626diff -urNp linux-2.6.32.44/arch/parisc/include/asm/elf.h linux-2.6.32.44/arch/parisc/include/asm/elf.h
1627--- linux-2.6.32.44/arch/parisc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1628+++ linux-2.6.32.44/arch/parisc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1629@@ -343,6 +343,13 @@ struct pt_regs; /* forward declaration..
1630
1631 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1632
1633+#ifdef CONFIG_PAX_ASLR
1634+#define PAX_ELF_ET_DYN_BASE 0x10000UL
1635+
1636+#define PAX_DELTA_MMAP_LEN 16
1637+#define PAX_DELTA_STACK_LEN 16
1638+#endif
1639+
1640 /* This yields a mask that user programs can use to figure out what
1641 instruction set this CPU supports. This could be done in user space,
1642 but it's not easy, and we've already done it here. */
1643diff -urNp linux-2.6.32.44/arch/parisc/include/asm/pgtable.h linux-2.6.32.44/arch/parisc/include/asm/pgtable.h
1644--- linux-2.6.32.44/arch/parisc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1645+++ linux-2.6.32.44/arch/parisc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1646@@ -207,6 +207,17 @@
1647 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1648 #define PAGE_COPY PAGE_EXECREAD
1649 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1650+
1651+#ifdef CONFIG_PAX_PAGEEXEC
1652+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1653+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1654+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1655+#else
1656+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1657+# define PAGE_COPY_NOEXEC PAGE_COPY
1658+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1659+#endif
1660+
1661 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1662 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
1663 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
1664diff -urNp linux-2.6.32.44/arch/parisc/kernel/module.c linux-2.6.32.44/arch/parisc/kernel/module.c
1665--- linux-2.6.32.44/arch/parisc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
1666+++ linux-2.6.32.44/arch/parisc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
1667@@ -95,16 +95,38 @@
1668
1669 /* three functions to determine where in the module core
1670 * or init pieces the location is */
1671+static inline int in_init_rx(struct module *me, void *loc)
1672+{
1673+ return (loc >= me->module_init_rx &&
1674+ loc < (me->module_init_rx + me->init_size_rx));
1675+}
1676+
1677+static inline int in_init_rw(struct module *me, void *loc)
1678+{
1679+ return (loc >= me->module_init_rw &&
1680+ loc < (me->module_init_rw + me->init_size_rw));
1681+}
1682+
1683 static inline int in_init(struct module *me, void *loc)
1684 {
1685- return (loc >= me->module_init &&
1686- loc <= (me->module_init + me->init_size));
1687+ return in_init_rx(me, loc) || in_init_rw(me, loc);
1688+}
1689+
1690+static inline int in_core_rx(struct module *me, void *loc)
1691+{
1692+ return (loc >= me->module_core_rx &&
1693+ loc < (me->module_core_rx + me->core_size_rx));
1694+}
1695+
1696+static inline int in_core_rw(struct module *me, void *loc)
1697+{
1698+ return (loc >= me->module_core_rw &&
1699+ loc < (me->module_core_rw + me->core_size_rw));
1700 }
1701
1702 static inline int in_core(struct module *me, void *loc)
1703 {
1704- return (loc >= me->module_core &&
1705- loc <= (me->module_core + me->core_size));
1706+ return in_core_rx(me, loc) || in_core_rw(me, loc);
1707 }
1708
1709 static inline int in_local(struct module *me, void *loc)
1710@@ -364,13 +386,13 @@ int module_frob_arch_sections(CONST Elf_
1711 }
1712
1713 /* align things a bit */
1714- me->core_size = ALIGN(me->core_size, 16);
1715- me->arch.got_offset = me->core_size;
1716- me->core_size += gots * sizeof(struct got_entry);
1717-
1718- me->core_size = ALIGN(me->core_size, 16);
1719- me->arch.fdesc_offset = me->core_size;
1720- me->core_size += fdescs * sizeof(Elf_Fdesc);
1721+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1722+ me->arch.got_offset = me->core_size_rw;
1723+ me->core_size_rw += gots * sizeof(struct got_entry);
1724+
1725+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1726+ me->arch.fdesc_offset = me->core_size_rw;
1727+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1728
1729 me->arch.got_max = gots;
1730 me->arch.fdesc_max = fdescs;
1731@@ -388,7 +410,7 @@ static Elf64_Word get_got(struct module
1732
1733 BUG_ON(value == 0);
1734
1735- got = me->module_core + me->arch.got_offset;
1736+ got = me->module_core_rw + me->arch.got_offset;
1737 for (i = 0; got[i].addr; i++)
1738 if (got[i].addr == value)
1739 goto out;
1740@@ -406,7 +428,7 @@ static Elf64_Word get_got(struct module
1741 #ifdef CONFIG_64BIT
1742 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1743 {
1744- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1745+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1746
1747 if (!value) {
1748 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1749@@ -424,7 +446,7 @@ static Elf_Addr get_fdesc(struct module
1750
1751 /* Create new one */
1752 fdesc->addr = value;
1753- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1754+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1755 return (Elf_Addr)fdesc;
1756 }
1757 #endif /* CONFIG_64BIT */
1758@@ -848,7 +870,7 @@ register_unwind_table(struct module *me,
1759
1760 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1761 end = table + sechdrs[me->arch.unwind_section].sh_size;
1762- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1763+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1764
1765 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1766 me->arch.unwind_section, table, end, gp);
1767diff -urNp linux-2.6.32.44/arch/parisc/kernel/sys_parisc.c linux-2.6.32.44/arch/parisc/kernel/sys_parisc.c
1768--- linux-2.6.32.44/arch/parisc/kernel/sys_parisc.c 2011-03-27 14:31:47.000000000 -0400
1769+++ linux-2.6.32.44/arch/parisc/kernel/sys_parisc.c 2011-04-17 15:56:45.000000000 -0400
1770@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
1771 /* At this point: (!vma || addr < vma->vm_end). */
1772 if (TASK_SIZE - len < addr)
1773 return -ENOMEM;
1774- if (!vma || addr + len <= vma->vm_start)
1775+ if (check_heap_stack_gap(vma, addr, len))
1776 return addr;
1777 addr = vma->vm_end;
1778 }
1779@@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
1780 /* At this point: (!vma || addr < vma->vm_end). */
1781 if (TASK_SIZE - len < addr)
1782 return -ENOMEM;
1783- if (!vma || addr + len <= vma->vm_start)
1784+ if (check_heap_stack_gap(vma, addr, len))
1785 return addr;
1786 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1787 if (addr < vma->vm_end) /* handle wraparound */
1788@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1789 if (flags & MAP_FIXED)
1790 return addr;
1791 if (!addr)
1792- addr = TASK_UNMAPPED_BASE;
1793+ addr = current->mm->mmap_base;
1794
1795 if (filp) {
1796 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1797diff -urNp linux-2.6.32.44/arch/parisc/kernel/traps.c linux-2.6.32.44/arch/parisc/kernel/traps.c
1798--- linux-2.6.32.44/arch/parisc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
1799+++ linux-2.6.32.44/arch/parisc/kernel/traps.c 2011-04-17 15:56:45.000000000 -0400
1800@@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
1801
1802 down_read(&current->mm->mmap_sem);
1803 vma = find_vma(current->mm,regs->iaoq[0]);
1804- if (vma && (regs->iaoq[0] >= vma->vm_start)
1805- && (vma->vm_flags & VM_EXEC)) {
1806-
1807+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1808 fault_address = regs->iaoq[0];
1809 fault_space = regs->iasq[0];
1810
1811diff -urNp linux-2.6.32.44/arch/parisc/mm/fault.c linux-2.6.32.44/arch/parisc/mm/fault.c
1812--- linux-2.6.32.44/arch/parisc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1813+++ linux-2.6.32.44/arch/parisc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1814@@ -15,6 +15,7 @@
1815 #include <linux/sched.h>
1816 #include <linux/interrupt.h>
1817 #include <linux/module.h>
1818+#include <linux/unistd.h>
1819
1820 #include <asm/uaccess.h>
1821 #include <asm/traps.h>
1822@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1823 static unsigned long
1824 parisc_acctyp(unsigned long code, unsigned int inst)
1825 {
1826- if (code == 6 || code == 16)
1827+ if (code == 6 || code == 7 || code == 16)
1828 return VM_EXEC;
1829
1830 switch (inst & 0xf0000000) {
1831@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
1832 }
1833 #endif
1834
1835+#ifdef CONFIG_PAX_PAGEEXEC
1836+/*
1837+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1838+ *
1839+ * returns 1 when task should be killed
1840+ * 2 when rt_sigreturn trampoline was detected
1841+ * 3 when unpatched PLT trampoline was detected
1842+ */
1843+static int pax_handle_fetch_fault(struct pt_regs *regs)
1844+{
1845+
1846+#ifdef CONFIG_PAX_EMUPLT
1847+ int err;
1848+
1849+ do { /* PaX: unpatched PLT emulation */
1850+ unsigned int bl, depwi;
1851+
1852+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1853+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1854+
1855+ if (err)
1856+ break;
1857+
1858+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1859+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1860+
1861+ err = get_user(ldw, (unsigned int *)addr);
1862+ err |= get_user(bv, (unsigned int *)(addr+4));
1863+ err |= get_user(ldw2, (unsigned int *)(addr+8));
1864+
1865+ if (err)
1866+ break;
1867+
1868+ if (ldw == 0x0E801096U &&
1869+ bv == 0xEAC0C000U &&
1870+ ldw2 == 0x0E881095U)
1871+ {
1872+ unsigned int resolver, map;
1873+
1874+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1875+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1876+ if (err)
1877+ break;
1878+
1879+ regs->gr[20] = instruction_pointer(regs)+8;
1880+ regs->gr[21] = map;
1881+ regs->gr[22] = resolver;
1882+ regs->iaoq[0] = resolver | 3UL;
1883+ regs->iaoq[1] = regs->iaoq[0] + 4;
1884+ return 3;
1885+ }
1886+ }
1887+ } while (0);
1888+#endif
1889+
1890+#ifdef CONFIG_PAX_EMUTRAMP
1891+
1892+#ifndef CONFIG_PAX_EMUSIGRT
1893+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1894+ return 1;
1895+#endif
1896+
1897+ do { /* PaX: rt_sigreturn emulation */
1898+ unsigned int ldi1, ldi2, bel, nop;
1899+
1900+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1901+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1902+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1903+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1904+
1905+ if (err)
1906+ break;
1907+
1908+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1909+ ldi2 == 0x3414015AU &&
1910+ bel == 0xE4008200U &&
1911+ nop == 0x08000240U)
1912+ {
1913+ regs->gr[25] = (ldi1 & 2) >> 1;
1914+ regs->gr[20] = __NR_rt_sigreturn;
1915+ regs->gr[31] = regs->iaoq[1] + 16;
1916+ regs->sr[0] = regs->iasq[1];
1917+ regs->iaoq[0] = 0x100UL;
1918+ regs->iaoq[1] = regs->iaoq[0] + 4;
1919+ regs->iasq[0] = regs->sr[2];
1920+ regs->iasq[1] = regs->sr[2];
1921+ return 2;
1922+ }
1923+ } while (0);
1924+#endif
1925+
1926+ return 1;
1927+}
1928+
1929+void pax_report_insns(void *pc, void *sp)
1930+{
1931+ unsigned long i;
1932+
1933+ printk(KERN_ERR "PAX: bytes at PC: ");
1934+ for (i = 0; i < 5; i++) {
1935+ unsigned int c;
1936+ if (get_user(c, (unsigned int *)pc+i))
1937+ printk(KERN_CONT "???????? ");
1938+ else
1939+ printk(KERN_CONT "%08x ", c);
1940+ }
1941+ printk("\n");
1942+}
1943+#endif
1944+
1945 int fixup_exception(struct pt_regs *regs)
1946 {
1947 const struct exception_table_entry *fix;
1948@@ -192,8 +303,33 @@ good_area:
1949
1950 acc_type = parisc_acctyp(code,regs->iir);
1951
1952- if ((vma->vm_flags & acc_type) != acc_type)
1953+ if ((vma->vm_flags & acc_type) != acc_type) {
1954+
1955+#ifdef CONFIG_PAX_PAGEEXEC
1956+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
1957+ (address & ~3UL) == instruction_pointer(regs))
1958+ {
1959+ up_read(&mm->mmap_sem);
1960+ switch (pax_handle_fetch_fault(regs)) {
1961+
1962+#ifdef CONFIG_PAX_EMUPLT
1963+ case 3:
1964+ return;
1965+#endif
1966+
1967+#ifdef CONFIG_PAX_EMUTRAMP
1968+ case 2:
1969+ return;
1970+#endif
1971+
1972+ }
1973+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
1974+ do_group_exit(SIGKILL);
1975+ }
1976+#endif
1977+
1978 goto bad_area;
1979+ }
1980
1981 /*
1982 * If for any reason at all we couldn't handle the fault, make
1983diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/device.h linux-2.6.32.44/arch/powerpc/include/asm/device.h
1984--- linux-2.6.32.44/arch/powerpc/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
1985+++ linux-2.6.32.44/arch/powerpc/include/asm/device.h 2011-04-17 15:56:45.000000000 -0400
1986@@ -14,7 +14,7 @@ struct dev_archdata {
1987 struct device_node *of_node;
1988
1989 /* DMA operations on that device */
1990- struct dma_map_ops *dma_ops;
1991+ const struct dma_map_ops *dma_ops;
1992
1993 /*
1994 * When an iommu is in use, dma_data is used as a ptr to the base of the
1995diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/dma-mapping.h linux-2.6.32.44/arch/powerpc/include/asm/dma-mapping.h
1996--- linux-2.6.32.44/arch/powerpc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
1997+++ linux-2.6.32.44/arch/powerpc/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
1998@@ -69,9 +69,9 @@ static inline unsigned long device_to_ma
1999 #ifdef CONFIG_PPC64
2000 extern struct dma_map_ops dma_iommu_ops;
2001 #endif
2002-extern struct dma_map_ops dma_direct_ops;
2003+extern const struct dma_map_ops dma_direct_ops;
2004
2005-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2006+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2007 {
2008 /* We don't handle the NULL dev case for ISA for now. We could
2009 * do it via an out of line call but it is not needed for now. The
2010@@ -84,7 +84,7 @@ static inline struct dma_map_ops *get_dm
2011 return dev->archdata.dma_ops;
2012 }
2013
2014-static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
2015+static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
2016 {
2017 dev->archdata.dma_ops = ops;
2018 }
2019@@ -118,7 +118,7 @@ static inline void set_dma_offset(struct
2020
2021 static inline int dma_supported(struct device *dev, u64 mask)
2022 {
2023- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2024+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2025
2026 if (unlikely(dma_ops == NULL))
2027 return 0;
2028@@ -132,7 +132,7 @@ static inline int dma_supported(struct d
2029
2030 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2031 {
2032- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2033+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2034
2035 if (unlikely(dma_ops == NULL))
2036 return -EIO;
2037@@ -147,7 +147,7 @@ static inline int dma_set_mask(struct de
2038 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2039 dma_addr_t *dma_handle, gfp_t flag)
2040 {
2041- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2042+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2043 void *cpu_addr;
2044
2045 BUG_ON(!dma_ops);
2046@@ -162,7 +162,7 @@ static inline void *dma_alloc_coherent(s
2047 static inline void dma_free_coherent(struct device *dev, size_t size,
2048 void *cpu_addr, dma_addr_t dma_handle)
2049 {
2050- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2051+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2052
2053 BUG_ON(!dma_ops);
2054
2055@@ -173,7 +173,7 @@ static inline void dma_free_coherent(str
2056
2057 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2058 {
2059- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2060+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2061
2062 if (dma_ops->mapping_error)
2063 return dma_ops->mapping_error(dev, dma_addr);
2064diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/elf.h linux-2.6.32.44/arch/powerpc/include/asm/elf.h
2065--- linux-2.6.32.44/arch/powerpc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
2066+++ linux-2.6.32.44/arch/powerpc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
2067@@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
2068 the loader. We need to make sure that it is out of the way of the program
2069 that it will "exec", and that there is sufficient room for the brk. */
2070
2071-extern unsigned long randomize_et_dyn(unsigned long base);
2072-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2073+#define ELF_ET_DYN_BASE (0x20000000)
2074+
2075+#ifdef CONFIG_PAX_ASLR
2076+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2077+
2078+#ifdef __powerpc64__
2079+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2080+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2081+#else
2082+#define PAX_DELTA_MMAP_LEN 15
2083+#define PAX_DELTA_STACK_LEN 15
2084+#endif
2085+#endif
2086
2087 /*
2088 * Our registers are always unsigned longs, whether we're a 32 bit
2089@@ -275,9 +286,6 @@ extern int arch_setup_additional_pages(s
2090 (0x7ff >> (PAGE_SHIFT - 12)) : \
2091 (0x3ffff >> (PAGE_SHIFT - 12)))
2092
2093-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2094-#define arch_randomize_brk arch_randomize_brk
2095-
2096 #endif /* __KERNEL__ */
2097
2098 /*
2099diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/iommu.h linux-2.6.32.44/arch/powerpc/include/asm/iommu.h
2100--- linux-2.6.32.44/arch/powerpc/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
2101+++ linux-2.6.32.44/arch/powerpc/include/asm/iommu.h 2011-04-17 15:56:45.000000000 -0400
2102@@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
2103 extern void iommu_init_early_dart(void);
2104 extern void iommu_init_early_pasemi(void);
2105
2106+/* dma-iommu.c */
2107+extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2108+
2109 #ifdef CONFIG_PCI
2110 extern void pci_iommu_init(void);
2111 extern void pci_direct_iommu_init(void);
2112diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/kmap_types.h linux-2.6.32.44/arch/powerpc/include/asm/kmap_types.h
2113--- linux-2.6.32.44/arch/powerpc/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
2114+++ linux-2.6.32.44/arch/powerpc/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
2115@@ -26,6 +26,7 @@ enum km_type {
2116 KM_SOFTIRQ1,
2117 KM_PPC_SYNC_PAGE,
2118 KM_PPC_SYNC_ICACHE,
2119+ KM_CLEARPAGE,
2120 KM_TYPE_NR
2121 };
2122
2123diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/page_64.h linux-2.6.32.44/arch/powerpc/include/asm/page_64.h
2124--- linux-2.6.32.44/arch/powerpc/include/asm/page_64.h 2011-03-27 14:31:47.000000000 -0400
2125+++ linux-2.6.32.44/arch/powerpc/include/asm/page_64.h 2011-04-17 15:56:45.000000000 -0400
2126@@ -180,15 +180,18 @@ do { \
2127 * stack by default, so in the absense of a PT_GNU_STACK program header
2128 * we turn execute permission off.
2129 */
2130-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2131- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2132+#define VM_STACK_DEFAULT_FLAGS32 \
2133+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2134+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2135
2136 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2137 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2138
2139+#ifndef CONFIG_PAX_PAGEEXEC
2140 #define VM_STACK_DEFAULT_FLAGS \
2141 (test_thread_flag(TIF_32BIT) ? \
2142 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2143+#endif
2144
2145 #include <asm-generic/getorder.h>
2146
2147diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/page.h linux-2.6.32.44/arch/powerpc/include/asm/page.h
2148--- linux-2.6.32.44/arch/powerpc/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
2149+++ linux-2.6.32.44/arch/powerpc/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
2150@@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
2151 * and needs to be executable. This means the whole heap ends
2152 * up being executable.
2153 */
2154-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2155- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2156+#define VM_DATA_DEFAULT_FLAGS32 \
2157+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2158+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2159
2160 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2161 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2162@@ -145,6 +146,9 @@ extern phys_addr_t kernstart_addr;
2163 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2164 #endif
2165
2166+#define ktla_ktva(addr) (addr)
2167+#define ktva_ktla(addr) (addr)
2168+
2169 #ifndef __ASSEMBLY__
2170
2171 #undef STRICT_MM_TYPECHECKS
2172diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/pci.h linux-2.6.32.44/arch/powerpc/include/asm/pci.h
2173--- linux-2.6.32.44/arch/powerpc/include/asm/pci.h 2011-03-27 14:31:47.000000000 -0400
2174+++ linux-2.6.32.44/arch/powerpc/include/asm/pci.h 2011-04-17 15:56:45.000000000 -0400
2175@@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
2176 }
2177
2178 #ifdef CONFIG_PCI
2179-extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
2180-extern struct dma_map_ops *get_pci_dma_ops(void);
2181+extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
2182+extern const struct dma_map_ops *get_pci_dma_ops(void);
2183 #else /* CONFIG_PCI */
2184 #define set_pci_dma_ops(d)
2185 #define get_pci_dma_ops() NULL
2186diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/pgtable.h linux-2.6.32.44/arch/powerpc/include/asm/pgtable.h
2187--- linux-2.6.32.44/arch/powerpc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
2188+++ linux-2.6.32.44/arch/powerpc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
2189@@ -2,6 +2,7 @@
2190 #define _ASM_POWERPC_PGTABLE_H
2191 #ifdef __KERNEL__
2192
2193+#include <linux/const.h>
2194 #ifndef __ASSEMBLY__
2195 #include <asm/processor.h> /* For TASK_SIZE */
2196 #include <asm/mmu.h>
2197diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/pte-hash32.h linux-2.6.32.44/arch/powerpc/include/asm/pte-hash32.h
2198--- linux-2.6.32.44/arch/powerpc/include/asm/pte-hash32.h 2011-03-27 14:31:47.000000000 -0400
2199+++ linux-2.6.32.44/arch/powerpc/include/asm/pte-hash32.h 2011-04-17 15:56:45.000000000 -0400
2200@@ -21,6 +21,7 @@
2201 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2202 #define _PAGE_USER 0x004 /* usermode access allowed */
2203 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2204+#define _PAGE_EXEC _PAGE_GUARDED
2205 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2206 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2207 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2208diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/reg.h linux-2.6.32.44/arch/powerpc/include/asm/reg.h
2209--- linux-2.6.32.44/arch/powerpc/include/asm/reg.h 2011-03-27 14:31:47.000000000 -0400
2210+++ linux-2.6.32.44/arch/powerpc/include/asm/reg.h 2011-04-17 15:56:45.000000000 -0400
2211@@ -191,6 +191,7 @@
2212 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2213 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2214 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2215+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2216 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2217 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2218 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2219diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/swiotlb.h linux-2.6.32.44/arch/powerpc/include/asm/swiotlb.h
2220--- linux-2.6.32.44/arch/powerpc/include/asm/swiotlb.h 2011-03-27 14:31:47.000000000 -0400
2221+++ linux-2.6.32.44/arch/powerpc/include/asm/swiotlb.h 2011-04-17 15:56:45.000000000 -0400
2222@@ -13,7 +13,7 @@
2223
2224 #include <linux/swiotlb.h>
2225
2226-extern struct dma_map_ops swiotlb_dma_ops;
2227+extern const struct dma_map_ops swiotlb_dma_ops;
2228
2229 static inline void dma_mark_clean(void *addr, size_t size) {}
2230
2231diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/system.h linux-2.6.32.44/arch/powerpc/include/asm/system.h
2232--- linux-2.6.32.44/arch/powerpc/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
2233+++ linux-2.6.32.44/arch/powerpc/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
2234@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsi
2235 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2236 #endif
2237
2238-extern unsigned long arch_align_stack(unsigned long sp);
2239+#define arch_align_stack(x) ((x) & ~0xfUL)
2240
2241 /* Used in very early kernel initialization. */
2242 extern unsigned long reloc_offset(void);
2243diff -urNp linux-2.6.32.44/arch/powerpc/include/asm/uaccess.h linux-2.6.32.44/arch/powerpc/include/asm/uaccess.h
2244--- linux-2.6.32.44/arch/powerpc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
2245+++ linux-2.6.32.44/arch/powerpc/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
2246@@ -13,6 +13,8 @@
2247 #define VERIFY_READ 0
2248 #define VERIFY_WRITE 1
2249
2250+extern void check_object_size(const void *ptr, unsigned long n, bool to);
2251+
2252 /*
2253 * The fs value determines whether argument validity checking should be
2254 * performed or not. If get_fs() == USER_DS, checking is performed, with
2255@@ -327,52 +329,6 @@ do { \
2256 extern unsigned long __copy_tofrom_user(void __user *to,
2257 const void __user *from, unsigned long size);
2258
2259-#ifndef __powerpc64__
2260-
2261-static inline unsigned long copy_from_user(void *to,
2262- const void __user *from, unsigned long n)
2263-{
2264- unsigned long over;
2265-
2266- if (access_ok(VERIFY_READ, from, n))
2267- return __copy_tofrom_user((__force void __user *)to, from, n);
2268- if ((unsigned long)from < TASK_SIZE) {
2269- over = (unsigned long)from + n - TASK_SIZE;
2270- return __copy_tofrom_user((__force void __user *)to, from,
2271- n - over) + over;
2272- }
2273- return n;
2274-}
2275-
2276-static inline unsigned long copy_to_user(void __user *to,
2277- const void *from, unsigned long n)
2278-{
2279- unsigned long over;
2280-
2281- if (access_ok(VERIFY_WRITE, to, n))
2282- return __copy_tofrom_user(to, (__force void __user *)from, n);
2283- if ((unsigned long)to < TASK_SIZE) {
2284- over = (unsigned long)to + n - TASK_SIZE;
2285- return __copy_tofrom_user(to, (__force void __user *)from,
2286- n - over) + over;
2287- }
2288- return n;
2289-}
2290-
2291-#else /* __powerpc64__ */
2292-
2293-#define __copy_in_user(to, from, size) \
2294- __copy_tofrom_user((to), (from), (size))
2295-
2296-extern unsigned long copy_from_user(void *to, const void __user *from,
2297- unsigned long n);
2298-extern unsigned long copy_to_user(void __user *to, const void *from,
2299- unsigned long n);
2300-extern unsigned long copy_in_user(void __user *to, const void __user *from,
2301- unsigned long n);
2302-
2303-#endif /* __powerpc64__ */
2304-
2305 static inline unsigned long __copy_from_user_inatomic(void *to,
2306 const void __user *from, unsigned long n)
2307 {
2308@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
2309 if (ret == 0)
2310 return 0;
2311 }
2312+
2313+ if (!__builtin_constant_p(n))
2314+ check_object_size(to, n, false);
2315+
2316 return __copy_tofrom_user((__force void __user *)to, from, n);
2317 }
2318
2319@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
2320 if (ret == 0)
2321 return 0;
2322 }
2323+
2324+ if (!__builtin_constant_p(n))
2325+ check_object_size(from, n, true);
2326+
2327 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2328 }
2329
2330@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
2331 return __copy_to_user_inatomic(to, from, size);
2332 }
2333
2334+#ifndef __powerpc64__
2335+
2336+static inline unsigned long __must_check copy_from_user(void *to,
2337+ const void __user *from, unsigned long n)
2338+{
2339+ unsigned long over;
2340+
2341+ if ((long)n < 0)
2342+ return n;
2343+
2344+ if (access_ok(VERIFY_READ, from, n)) {
2345+ if (!__builtin_constant_p(n))
2346+ check_object_size(to, n, false);
2347+ return __copy_tofrom_user((__force void __user *)to, from, n);
2348+ }
2349+ if ((unsigned long)from < TASK_SIZE) {
2350+ over = (unsigned long)from + n - TASK_SIZE;
2351+ if (!__builtin_constant_p(n - over))
2352+ check_object_size(to, n - over, false);
2353+ return __copy_tofrom_user((__force void __user *)to, from,
2354+ n - over) + over;
2355+ }
2356+ return n;
2357+}
2358+
2359+static inline unsigned long __must_check copy_to_user(void __user *to,
2360+ const void *from, unsigned long n)
2361+{
2362+ unsigned long over;
2363+
2364+ if ((long)n < 0)
2365+ return n;
2366+
2367+ if (access_ok(VERIFY_WRITE, to, n)) {
2368+ if (!__builtin_constant_p(n))
2369+ check_object_size(from, n, true);
2370+ return __copy_tofrom_user(to, (__force void __user *)from, n);
2371+ }
2372+ if ((unsigned long)to < TASK_SIZE) {
2373+ over = (unsigned long)to + n - TASK_SIZE;
2374+ if (!__builtin_constant_p(n))
2375+ check_object_size(from, n - over, true);
2376+ return __copy_tofrom_user(to, (__force void __user *)from,
2377+ n - over) + over;
2378+ }
2379+ return n;
2380+}
2381+
2382+#else /* __powerpc64__ */
2383+
2384+#define __copy_in_user(to, from, size) \
2385+ __copy_tofrom_user((to), (from), (size))
2386+
2387+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2388+{
2389+ if ((long)n < 0 || n > INT_MAX)
2390+ return n;
2391+
2392+ if (!__builtin_constant_p(n))
2393+ check_object_size(to, n, false);
2394+
2395+ if (likely(access_ok(VERIFY_READ, from, n)))
2396+ n = __copy_from_user(to, from, n);
2397+ else
2398+ memset(to, 0, n);
2399+ return n;
2400+}
2401+
2402+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2403+{
2404+ if ((long)n < 0 || n > INT_MAX)
2405+ return n;
2406+
2407+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
2408+ if (!__builtin_constant_p(n))
2409+ check_object_size(from, n, true);
2410+ n = __copy_to_user(to, from, n);
2411+ }
2412+ return n;
2413+}
2414+
2415+extern unsigned long copy_in_user(void __user *to, const void __user *from,
2416+ unsigned long n);
2417+
2418+#endif /* __powerpc64__ */
2419+
2420 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2421
2422 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2423diff -urNp linux-2.6.32.44/arch/powerpc/kernel/cacheinfo.c linux-2.6.32.44/arch/powerpc/kernel/cacheinfo.c
2424--- linux-2.6.32.44/arch/powerpc/kernel/cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
2425+++ linux-2.6.32.44/arch/powerpc/kernel/cacheinfo.c 2011-04-17 15:56:45.000000000 -0400
2426@@ -642,7 +642,7 @@ static struct kobj_attribute *cache_inde
2427 &cache_assoc_attr,
2428 };
2429
2430-static struct sysfs_ops cache_index_ops = {
2431+static const struct sysfs_ops cache_index_ops = {
2432 .show = cache_index_show,
2433 };
2434
2435diff -urNp linux-2.6.32.44/arch/powerpc/kernel/dma.c linux-2.6.32.44/arch/powerpc/kernel/dma.c
2436--- linux-2.6.32.44/arch/powerpc/kernel/dma.c 2011-03-27 14:31:47.000000000 -0400
2437+++ linux-2.6.32.44/arch/powerpc/kernel/dma.c 2011-04-17 15:56:45.000000000 -0400
2438@@ -134,7 +134,7 @@ static inline void dma_direct_sync_singl
2439 }
2440 #endif
2441
2442-struct dma_map_ops dma_direct_ops = {
2443+const struct dma_map_ops dma_direct_ops = {
2444 .alloc_coherent = dma_direct_alloc_coherent,
2445 .free_coherent = dma_direct_free_coherent,
2446 .map_sg = dma_direct_map_sg,
2447diff -urNp linux-2.6.32.44/arch/powerpc/kernel/dma-iommu.c linux-2.6.32.44/arch/powerpc/kernel/dma-iommu.c
2448--- linux-2.6.32.44/arch/powerpc/kernel/dma-iommu.c 2011-03-27 14:31:47.000000000 -0400
2449+++ linux-2.6.32.44/arch/powerpc/kernel/dma-iommu.c 2011-04-17 15:56:45.000000000 -0400
2450@@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
2451 }
2452
2453 /* We support DMA to/from any memory page via the iommu */
2454-static int dma_iommu_dma_supported(struct device *dev, u64 mask)
2455+int dma_iommu_dma_supported(struct device *dev, u64 mask)
2456 {
2457 struct iommu_table *tbl = get_iommu_table_base(dev);
2458
2459diff -urNp linux-2.6.32.44/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.32.44/arch/powerpc/kernel/dma-swiotlb.c
2460--- linux-2.6.32.44/arch/powerpc/kernel/dma-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
2461+++ linux-2.6.32.44/arch/powerpc/kernel/dma-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
2462@@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
2463 * map_page, and unmap_page on highmem, use normal dma_ops
2464 * for everything else.
2465 */
2466-struct dma_map_ops swiotlb_dma_ops = {
2467+const struct dma_map_ops swiotlb_dma_ops = {
2468 .alloc_coherent = dma_direct_alloc_coherent,
2469 .free_coherent = dma_direct_free_coherent,
2470 .map_sg = swiotlb_map_sg_attrs,
2471diff -urNp linux-2.6.32.44/arch/powerpc/kernel/exceptions-64e.S linux-2.6.32.44/arch/powerpc/kernel/exceptions-64e.S
2472--- linux-2.6.32.44/arch/powerpc/kernel/exceptions-64e.S 2011-03-27 14:31:47.000000000 -0400
2473+++ linux-2.6.32.44/arch/powerpc/kernel/exceptions-64e.S 2011-04-17 15:56:45.000000000 -0400
2474@@ -455,6 +455,7 @@ storage_fault_common:
2475 std r14,_DAR(r1)
2476 std r15,_DSISR(r1)
2477 addi r3,r1,STACK_FRAME_OVERHEAD
2478+ bl .save_nvgprs
2479 mr r4,r14
2480 mr r5,r15
2481 ld r14,PACA_EXGEN+EX_R14(r13)
2482@@ -464,8 +465,7 @@ storage_fault_common:
2483 cmpdi r3,0
2484 bne- 1f
2485 b .ret_from_except_lite
2486-1: bl .save_nvgprs
2487- mr r5,r3
2488+1: mr r5,r3
2489 addi r3,r1,STACK_FRAME_OVERHEAD
2490 ld r4,_DAR(r1)
2491 bl .bad_page_fault
2492diff -urNp linux-2.6.32.44/arch/powerpc/kernel/exceptions-64s.S linux-2.6.32.44/arch/powerpc/kernel/exceptions-64s.S
2493--- linux-2.6.32.44/arch/powerpc/kernel/exceptions-64s.S 2011-03-27 14:31:47.000000000 -0400
2494+++ linux-2.6.32.44/arch/powerpc/kernel/exceptions-64s.S 2011-04-17 15:56:45.000000000 -0400
2495@@ -818,10 +818,10 @@ handle_page_fault:
2496 11: ld r4,_DAR(r1)
2497 ld r5,_DSISR(r1)
2498 addi r3,r1,STACK_FRAME_OVERHEAD
2499+ bl .save_nvgprs
2500 bl .do_page_fault
2501 cmpdi r3,0
2502 beq+ 13f
2503- bl .save_nvgprs
2504 mr r5,r3
2505 addi r3,r1,STACK_FRAME_OVERHEAD
2506 lwz r4,_DAR(r1)
2507diff -urNp linux-2.6.32.44/arch/powerpc/kernel/ibmebus.c linux-2.6.32.44/arch/powerpc/kernel/ibmebus.c
2508--- linux-2.6.32.44/arch/powerpc/kernel/ibmebus.c 2011-03-27 14:31:47.000000000 -0400
2509+++ linux-2.6.32.44/arch/powerpc/kernel/ibmebus.c 2011-04-17 15:56:45.000000000 -0400
2510@@ -127,7 +127,7 @@ static int ibmebus_dma_supported(struct
2511 return 1;
2512 }
2513
2514-static struct dma_map_ops ibmebus_dma_ops = {
2515+static const struct dma_map_ops ibmebus_dma_ops = {
2516 .alloc_coherent = ibmebus_alloc_coherent,
2517 .free_coherent = ibmebus_free_coherent,
2518 .map_sg = ibmebus_map_sg,
2519diff -urNp linux-2.6.32.44/arch/powerpc/kernel/kgdb.c linux-2.6.32.44/arch/powerpc/kernel/kgdb.c
2520--- linux-2.6.32.44/arch/powerpc/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
2521+++ linux-2.6.32.44/arch/powerpc/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
2522@@ -126,7 +126,7 @@ static int kgdb_handle_breakpoint(struct
2523 if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
2524 return 0;
2525
2526- if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2527+ if (*(u32 *) (regs->nip) == *(const u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2528 regs->nip += 4;
2529
2530 return 1;
2531@@ -353,7 +353,7 @@ int kgdb_arch_handle_exception(int vecto
2532 /*
2533 * Global data
2534 */
2535-struct kgdb_arch arch_kgdb_ops = {
2536+const struct kgdb_arch arch_kgdb_ops = {
2537 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
2538 };
2539
2540diff -urNp linux-2.6.32.44/arch/powerpc/kernel/module_32.c linux-2.6.32.44/arch/powerpc/kernel/module_32.c
2541--- linux-2.6.32.44/arch/powerpc/kernel/module_32.c 2011-03-27 14:31:47.000000000 -0400
2542+++ linux-2.6.32.44/arch/powerpc/kernel/module_32.c 2011-04-17 15:56:45.000000000 -0400
2543@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
2544 me->arch.core_plt_section = i;
2545 }
2546 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2547- printk("Module doesn't contain .plt or .init.plt sections.\n");
2548+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2549 return -ENOEXEC;
2550 }
2551
2552@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
2553
2554 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2555 /* Init, or core PLT? */
2556- if (location >= mod->module_core
2557- && location < mod->module_core + mod->core_size)
2558+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2559+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2560 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2561- else
2562+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2563+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2564 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2565+ else {
2566+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2567+ return ~0UL;
2568+ }
2569
2570 /* Find this entry, or if that fails, the next avail. entry */
2571 while (entry->jump[0]) {
2572diff -urNp linux-2.6.32.44/arch/powerpc/kernel/module.c linux-2.6.32.44/arch/powerpc/kernel/module.c
2573--- linux-2.6.32.44/arch/powerpc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
2574+++ linux-2.6.32.44/arch/powerpc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
2575@@ -31,11 +31,24 @@
2576
2577 LIST_HEAD(module_bug_list);
2578
2579+#ifdef CONFIG_PAX_KERNEXEC
2580 void *module_alloc(unsigned long size)
2581 {
2582 if (size == 0)
2583 return NULL;
2584
2585+ return vmalloc(size);
2586+}
2587+
2588+void *module_alloc_exec(unsigned long size)
2589+#else
2590+void *module_alloc(unsigned long size)
2591+#endif
2592+
2593+{
2594+ if (size == 0)
2595+ return NULL;
2596+
2597 return vmalloc_exec(size);
2598 }
2599
2600@@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
2601 vfree(module_region);
2602 }
2603
2604+#ifdef CONFIG_PAX_KERNEXEC
2605+void module_free_exec(struct module *mod, void *module_region)
2606+{
2607+ module_free(mod, module_region);
2608+}
2609+#endif
2610+
2611 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
2612 const Elf_Shdr *sechdrs,
2613 const char *name)
2614diff -urNp linux-2.6.32.44/arch/powerpc/kernel/pci-common.c linux-2.6.32.44/arch/powerpc/kernel/pci-common.c
2615--- linux-2.6.32.44/arch/powerpc/kernel/pci-common.c 2011-03-27 14:31:47.000000000 -0400
2616+++ linux-2.6.32.44/arch/powerpc/kernel/pci-common.c 2011-04-17 15:56:45.000000000 -0400
2617@@ -50,14 +50,14 @@ resource_size_t isa_mem_base;
2618 unsigned int ppc_pci_flags = 0;
2619
2620
2621-static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2622+static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2623
2624-void set_pci_dma_ops(struct dma_map_ops *dma_ops)
2625+void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
2626 {
2627 pci_dma_ops = dma_ops;
2628 }
2629
2630-struct dma_map_ops *get_pci_dma_ops(void)
2631+const struct dma_map_ops *get_pci_dma_ops(void)
2632 {
2633 return pci_dma_ops;
2634 }
2635diff -urNp linux-2.6.32.44/arch/powerpc/kernel/process.c linux-2.6.32.44/arch/powerpc/kernel/process.c
2636--- linux-2.6.32.44/arch/powerpc/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
2637+++ linux-2.6.32.44/arch/powerpc/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
2638@@ -539,8 +539,8 @@ void show_regs(struct pt_regs * regs)
2639 * Lookup NIP late so we have the best change of getting the
2640 * above info out without failing
2641 */
2642- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2643- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2644+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2645+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2646 #endif
2647 show_stack(current, (unsigned long *) regs->gpr[1]);
2648 if (!user_mode(regs))
2649@@ -1034,10 +1034,10 @@ void show_stack(struct task_struct *tsk,
2650 newsp = stack[0];
2651 ip = stack[STACK_FRAME_LR_SAVE];
2652 if (!firstframe || ip != lr) {
2653- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2654+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2655 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2656 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2657- printk(" (%pS)",
2658+ printk(" (%pA)",
2659 (void *)current->ret_stack[curr_frame].ret);
2660 curr_frame--;
2661 }
2662@@ -1057,7 +1057,7 @@ void show_stack(struct task_struct *tsk,
2663 struct pt_regs *regs = (struct pt_regs *)
2664 (sp + STACK_FRAME_OVERHEAD);
2665 lr = regs->link;
2666- printk("--- Exception: %lx at %pS\n LR = %pS\n",
2667+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
2668 regs->trap, (void *)regs->nip, (void *)lr);
2669 firstframe = 1;
2670 }
2671@@ -1134,58 +1134,3 @@ void thread_info_cache_init(void)
2672 }
2673
2674 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2675-
2676-unsigned long arch_align_stack(unsigned long sp)
2677-{
2678- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2679- sp -= get_random_int() & ~PAGE_MASK;
2680- return sp & ~0xf;
2681-}
2682-
2683-static inline unsigned long brk_rnd(void)
2684-{
2685- unsigned long rnd = 0;
2686-
2687- /* 8MB for 32bit, 1GB for 64bit */
2688- if (is_32bit_task())
2689- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2690- else
2691- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2692-
2693- return rnd << PAGE_SHIFT;
2694-}
2695-
2696-unsigned long arch_randomize_brk(struct mm_struct *mm)
2697-{
2698- unsigned long base = mm->brk;
2699- unsigned long ret;
2700-
2701-#ifdef CONFIG_PPC_STD_MMU_64
2702- /*
2703- * If we are using 1TB segments and we are allowed to randomise
2704- * the heap, we can put it above 1TB so it is backed by a 1TB
2705- * segment. Otherwise the heap will be in the bottom 1TB
2706- * which always uses 256MB segments and this may result in a
2707- * performance penalty.
2708- */
2709- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2710- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2711-#endif
2712-
2713- ret = PAGE_ALIGN(base + brk_rnd());
2714-
2715- if (ret < mm->brk)
2716- return mm->brk;
2717-
2718- return ret;
2719-}
2720-
2721-unsigned long randomize_et_dyn(unsigned long base)
2722-{
2723- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2724-
2725- if (ret < base)
2726- return base;
2727-
2728- return ret;
2729-}
2730diff -urNp linux-2.6.32.44/arch/powerpc/kernel/signal_32.c linux-2.6.32.44/arch/powerpc/kernel/signal_32.c
2731--- linux-2.6.32.44/arch/powerpc/kernel/signal_32.c 2011-03-27 14:31:47.000000000 -0400
2732+++ linux-2.6.32.44/arch/powerpc/kernel/signal_32.c 2011-04-17 15:56:45.000000000 -0400
2733@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
2734 /* Save user registers on the stack */
2735 frame = &rt_sf->uc.uc_mcontext;
2736 addr = frame;
2737- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2738+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2739 if (save_user_regs(regs, frame, 0, 1))
2740 goto badframe;
2741 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2742diff -urNp linux-2.6.32.44/arch/powerpc/kernel/signal_64.c linux-2.6.32.44/arch/powerpc/kernel/signal_64.c
2743--- linux-2.6.32.44/arch/powerpc/kernel/signal_64.c 2011-03-27 14:31:47.000000000 -0400
2744+++ linux-2.6.32.44/arch/powerpc/kernel/signal_64.c 2011-04-17 15:56:45.000000000 -0400
2745@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
2746 current->thread.fpscr.val = 0;
2747
2748 /* Set up to return from userspace. */
2749- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2750+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2751 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2752 } else {
2753 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2754diff -urNp linux-2.6.32.44/arch/powerpc/kernel/sys_ppc32.c linux-2.6.32.44/arch/powerpc/kernel/sys_ppc32.c
2755--- linux-2.6.32.44/arch/powerpc/kernel/sys_ppc32.c 2011-03-27 14:31:47.000000000 -0400
2756+++ linux-2.6.32.44/arch/powerpc/kernel/sys_ppc32.c 2011-04-17 15:56:45.000000000 -0400
2757@@ -563,10 +563,10 @@ asmlinkage long compat_sys_sysctl(struct
2758 if (oldlenp) {
2759 if (!error) {
2760 if (get_user(oldlen, oldlenp) ||
2761- put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
2762+ put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
2763+ copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
2764 error = -EFAULT;
2765 }
2766- copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
2767 }
2768 return error;
2769 }
2770diff -urNp linux-2.6.32.44/arch/powerpc/kernel/traps.c linux-2.6.32.44/arch/powerpc/kernel/traps.c
2771--- linux-2.6.32.44/arch/powerpc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
2772+++ linux-2.6.32.44/arch/powerpc/kernel/traps.c 2011-06-13 21:33:37.000000000 -0400
2773@@ -99,6 +99,8 @@ static void pmac_backlight_unblank(void)
2774 static inline void pmac_backlight_unblank(void) { }
2775 #endif
2776
2777+extern void gr_handle_kernel_exploit(void);
2778+
2779 int die(const char *str, struct pt_regs *regs, long err)
2780 {
2781 static struct {
2782@@ -168,6 +170,8 @@ int die(const char *str, struct pt_regs
2783 if (panic_on_oops)
2784 panic("Fatal exception");
2785
2786+ gr_handle_kernel_exploit();
2787+
2788 oops_exit();
2789 do_exit(err);
2790
2791diff -urNp linux-2.6.32.44/arch/powerpc/kernel/vdso.c linux-2.6.32.44/arch/powerpc/kernel/vdso.c
2792--- linux-2.6.32.44/arch/powerpc/kernel/vdso.c 2011-03-27 14:31:47.000000000 -0400
2793+++ linux-2.6.32.44/arch/powerpc/kernel/vdso.c 2011-04-17 15:56:45.000000000 -0400
2794@@ -36,6 +36,7 @@
2795 #include <asm/firmware.h>
2796 #include <asm/vdso.h>
2797 #include <asm/vdso_datapage.h>
2798+#include <asm/mman.h>
2799
2800 #include "setup.h"
2801
2802@@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
2803 vdso_base = VDSO32_MBASE;
2804 #endif
2805
2806- current->mm->context.vdso_base = 0;
2807+ current->mm->context.vdso_base = ~0UL;
2808
2809 /* vDSO has a problem and was disabled, just don't "enable" it for the
2810 * process
2811@@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
2812 vdso_base = get_unmapped_area(NULL, vdso_base,
2813 (vdso_pages << PAGE_SHIFT) +
2814 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2815- 0, 0);
2816+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
2817 if (IS_ERR_VALUE(vdso_base)) {
2818 rc = vdso_base;
2819 goto fail_mmapsem;
2820diff -urNp linux-2.6.32.44/arch/powerpc/kernel/vio.c linux-2.6.32.44/arch/powerpc/kernel/vio.c
2821--- linux-2.6.32.44/arch/powerpc/kernel/vio.c 2011-03-27 14:31:47.000000000 -0400
2822+++ linux-2.6.32.44/arch/powerpc/kernel/vio.c 2011-04-17 15:56:45.000000000 -0400
2823@@ -601,11 +601,12 @@ static void vio_dma_iommu_unmap_sg(struc
2824 vio_cmo_dealloc(viodev, alloc_size);
2825 }
2826
2827-struct dma_map_ops vio_dma_mapping_ops = {
2828+static const struct dma_map_ops vio_dma_mapping_ops = {
2829 .alloc_coherent = vio_dma_iommu_alloc_coherent,
2830 .free_coherent = vio_dma_iommu_free_coherent,
2831 .map_sg = vio_dma_iommu_map_sg,
2832 .unmap_sg = vio_dma_iommu_unmap_sg,
2833+ .dma_supported = dma_iommu_dma_supported,
2834 .map_page = vio_dma_iommu_map_page,
2835 .unmap_page = vio_dma_iommu_unmap_page,
2836
2837@@ -857,7 +858,6 @@ static void vio_cmo_bus_remove(struct vi
2838
2839 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
2840 {
2841- vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
2842 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
2843 }
2844
2845diff -urNp linux-2.6.32.44/arch/powerpc/lib/usercopy_64.c linux-2.6.32.44/arch/powerpc/lib/usercopy_64.c
2846--- linux-2.6.32.44/arch/powerpc/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
2847+++ linux-2.6.32.44/arch/powerpc/lib/usercopy_64.c 2011-04-17 15:56:45.000000000 -0400
2848@@ -9,22 +9,6 @@
2849 #include <linux/module.h>
2850 #include <asm/uaccess.h>
2851
2852-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2853-{
2854- if (likely(access_ok(VERIFY_READ, from, n)))
2855- n = __copy_from_user(to, from, n);
2856- else
2857- memset(to, 0, n);
2858- return n;
2859-}
2860-
2861-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2862-{
2863- if (likely(access_ok(VERIFY_WRITE, to, n)))
2864- n = __copy_to_user(to, from, n);
2865- return n;
2866-}
2867-
2868 unsigned long copy_in_user(void __user *to, const void __user *from,
2869 unsigned long n)
2870 {
2871@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
2872 return n;
2873 }
2874
2875-EXPORT_SYMBOL(copy_from_user);
2876-EXPORT_SYMBOL(copy_to_user);
2877 EXPORT_SYMBOL(copy_in_user);
2878
2879diff -urNp linux-2.6.32.44/arch/powerpc/mm/fault.c linux-2.6.32.44/arch/powerpc/mm/fault.c
2880--- linux-2.6.32.44/arch/powerpc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
2881+++ linux-2.6.32.44/arch/powerpc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
2882@@ -30,6 +30,10 @@
2883 #include <linux/kprobes.h>
2884 #include <linux/kdebug.h>
2885 #include <linux/perf_event.h>
2886+#include <linux/slab.h>
2887+#include <linux/pagemap.h>
2888+#include <linux/compiler.h>
2889+#include <linux/unistd.h>
2890
2891 #include <asm/firmware.h>
2892 #include <asm/page.h>
2893@@ -40,6 +44,7 @@
2894 #include <asm/uaccess.h>
2895 #include <asm/tlbflush.h>
2896 #include <asm/siginfo.h>
2897+#include <asm/ptrace.h>
2898
2899
2900 #ifdef CONFIG_KPROBES
2901@@ -64,6 +69,33 @@ static inline int notify_page_fault(stru
2902 }
2903 #endif
2904
2905+#ifdef CONFIG_PAX_PAGEEXEC
2906+/*
2907+ * PaX: decide what to do with offenders (regs->nip = fault address)
2908+ *
2909+ * returns 1 when task should be killed
2910+ */
2911+static int pax_handle_fetch_fault(struct pt_regs *regs)
2912+{
2913+ return 1;
2914+}
2915+
2916+void pax_report_insns(void *pc, void *sp)
2917+{
2918+ unsigned long i;
2919+
2920+ printk(KERN_ERR "PAX: bytes at PC: ");
2921+ for (i = 0; i < 5; i++) {
2922+ unsigned int c;
2923+ if (get_user(c, (unsigned int __user *)pc+i))
2924+ printk(KERN_CONT "???????? ");
2925+ else
2926+ printk(KERN_CONT "%08x ", c);
2927+ }
2928+ printk("\n");
2929+}
2930+#endif
2931+
2932 /*
2933 * Check whether the instruction at regs->nip is a store using
2934 * an update addressing form which will update r1.
2935@@ -134,7 +166,7 @@ int __kprobes do_page_fault(struct pt_re
2936 * indicate errors in DSISR but can validly be set in SRR1.
2937 */
2938 if (trap == 0x400)
2939- error_code &= 0x48200000;
2940+ error_code &= 0x58200000;
2941 else
2942 is_write = error_code & DSISR_ISSTORE;
2943 #else
2944@@ -250,7 +282,7 @@ good_area:
2945 * "undefined". Of those that can be set, this is the only
2946 * one which seems bad.
2947 */
2948- if (error_code & 0x10000000)
2949+ if (error_code & DSISR_GUARDED)
2950 /* Guarded storage error. */
2951 goto bad_area;
2952 #endif /* CONFIG_8xx */
2953@@ -265,7 +297,7 @@ good_area:
2954 * processors use the same I/D cache coherency mechanism
2955 * as embedded.
2956 */
2957- if (error_code & DSISR_PROTFAULT)
2958+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2959 goto bad_area;
2960 #endif /* CONFIG_PPC_STD_MMU */
2961
2962@@ -335,6 +367,23 @@ bad_area:
2963 bad_area_nosemaphore:
2964 /* User mode accesses cause a SIGSEGV */
2965 if (user_mode(regs)) {
2966+
2967+#ifdef CONFIG_PAX_PAGEEXEC
2968+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2969+#ifdef CONFIG_PPC_STD_MMU
2970+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2971+#else
2972+ if (is_exec && regs->nip == address) {
2973+#endif
2974+ switch (pax_handle_fetch_fault(regs)) {
2975+ }
2976+
2977+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2978+ do_group_exit(SIGKILL);
2979+ }
2980+ }
2981+#endif
2982+
2983 _exception(SIGSEGV, regs, code, address);
2984 return 0;
2985 }
2986diff -urNp linux-2.6.32.44/arch/powerpc/mm/mmap_64.c linux-2.6.32.44/arch/powerpc/mm/mmap_64.c
2987--- linux-2.6.32.44/arch/powerpc/mm/mmap_64.c 2011-03-27 14:31:47.000000000 -0400
2988+++ linux-2.6.32.44/arch/powerpc/mm/mmap_64.c 2011-04-17 15:56:45.000000000 -0400
2989@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
2990 */
2991 if (mmap_is_legacy()) {
2992 mm->mmap_base = TASK_UNMAPPED_BASE;
2993+
2994+#ifdef CONFIG_PAX_RANDMMAP
2995+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2996+ mm->mmap_base += mm->delta_mmap;
2997+#endif
2998+
2999 mm->get_unmapped_area = arch_get_unmapped_area;
3000 mm->unmap_area = arch_unmap_area;
3001 } else {
3002 mm->mmap_base = mmap_base();
3003+
3004+#ifdef CONFIG_PAX_RANDMMAP
3005+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3006+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3007+#endif
3008+
3009 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3010 mm->unmap_area = arch_unmap_area_topdown;
3011 }
3012diff -urNp linux-2.6.32.44/arch/powerpc/mm/slice.c linux-2.6.32.44/arch/powerpc/mm/slice.c
3013--- linux-2.6.32.44/arch/powerpc/mm/slice.c 2011-03-27 14:31:47.000000000 -0400
3014+++ linux-2.6.32.44/arch/powerpc/mm/slice.c 2011-04-17 15:56:45.000000000 -0400
3015@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
3016 if ((mm->task_size - len) < addr)
3017 return 0;
3018 vma = find_vma(mm, addr);
3019- return (!vma || (addr + len) <= vma->vm_start);
3020+ return check_heap_stack_gap(vma, addr, len);
3021 }
3022
3023 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3024@@ -256,7 +256,7 @@ full_search:
3025 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3026 continue;
3027 }
3028- if (!vma || addr + len <= vma->vm_start) {
3029+ if (check_heap_stack_gap(vma, addr, len)) {
3030 /*
3031 * Remember the place where we stopped the search:
3032 */
3033@@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
3034 }
3035 }
3036
3037- addr = mm->mmap_base;
3038- while (addr > len) {
3039+ if (mm->mmap_base < len)
3040+ addr = -ENOMEM;
3041+ else
3042+ addr = mm->mmap_base - len;
3043+
3044+ while (!IS_ERR_VALUE(addr)) {
3045 /* Go down by chunk size */
3046- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3047+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
3048
3049 /* Check for hit with different page size */
3050 mask = slice_range_to_mask(addr, len);
3051@@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
3052 * return with success:
3053 */
3054 vma = find_vma(mm, addr);
3055- if (!vma || (addr + len) <= vma->vm_start) {
3056+ if (check_heap_stack_gap(vma, addr, len)) {
3057 /* remember the address as a hint for next time */
3058 if (use_cache)
3059 mm->free_area_cache = addr;
3060@@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
3061 mm->cached_hole_size = vma->vm_start - addr;
3062
3063 /* try just below the current vma->vm_start */
3064- addr = vma->vm_start;
3065+ addr = skip_heap_stack_gap(vma, len);
3066 }
3067
3068 /*
3069@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
3070 if (fixed && addr > (mm->task_size - len))
3071 return -EINVAL;
3072
3073+#ifdef CONFIG_PAX_RANDMMAP
3074+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3075+ addr = 0;
3076+#endif
3077+
3078 /* If hint, make sure it matches our alignment restrictions */
3079 if (!fixed && addr) {
3080 addr = _ALIGN_UP(addr, 1ul << pshift);
3081diff -urNp linux-2.6.32.44/arch/powerpc/platforms/52xx/lite5200_pm.c linux-2.6.32.44/arch/powerpc/platforms/52xx/lite5200_pm.c
3082--- linux-2.6.32.44/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-03-27 14:31:47.000000000 -0400
3083+++ linux-2.6.32.44/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-04-17 15:56:45.000000000 -0400
3084@@ -235,7 +235,7 @@ static void lite5200_pm_end(void)
3085 lite5200_pm_target_state = PM_SUSPEND_ON;
3086 }
3087
3088-static struct platform_suspend_ops lite5200_pm_ops = {
3089+static const struct platform_suspend_ops lite5200_pm_ops = {
3090 .valid = lite5200_pm_valid,
3091 .begin = lite5200_pm_begin,
3092 .prepare = lite5200_pm_prepare,
3093diff -urNp linux-2.6.32.44/arch/powerpc/platforms/52xx/mpc52xx_pm.c linux-2.6.32.44/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3094--- linux-2.6.32.44/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-03-27 14:31:47.000000000 -0400
3095+++ linux-2.6.32.44/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-04-17 15:56:45.000000000 -0400
3096@@ -180,7 +180,7 @@ void mpc52xx_pm_finish(void)
3097 iounmap(mbar);
3098 }
3099
3100-static struct platform_suspend_ops mpc52xx_pm_ops = {
3101+static const struct platform_suspend_ops mpc52xx_pm_ops = {
3102 .valid = mpc52xx_pm_valid,
3103 .prepare = mpc52xx_pm_prepare,
3104 .enter = mpc52xx_pm_enter,
3105diff -urNp linux-2.6.32.44/arch/powerpc/platforms/83xx/suspend.c linux-2.6.32.44/arch/powerpc/platforms/83xx/suspend.c
3106--- linux-2.6.32.44/arch/powerpc/platforms/83xx/suspend.c 2011-03-27 14:31:47.000000000 -0400
3107+++ linux-2.6.32.44/arch/powerpc/platforms/83xx/suspend.c 2011-04-17 15:56:45.000000000 -0400
3108@@ -273,7 +273,7 @@ static int mpc83xx_is_pci_agent(void)
3109 return ret;
3110 }
3111
3112-static struct platform_suspend_ops mpc83xx_suspend_ops = {
3113+static const struct platform_suspend_ops mpc83xx_suspend_ops = {
3114 .valid = mpc83xx_suspend_valid,
3115 .begin = mpc83xx_suspend_begin,
3116 .enter = mpc83xx_suspend_enter,
3117diff -urNp linux-2.6.32.44/arch/powerpc/platforms/cell/iommu.c linux-2.6.32.44/arch/powerpc/platforms/cell/iommu.c
3118--- linux-2.6.32.44/arch/powerpc/platforms/cell/iommu.c 2011-03-27 14:31:47.000000000 -0400
3119+++ linux-2.6.32.44/arch/powerpc/platforms/cell/iommu.c 2011-04-17 15:56:45.000000000 -0400
3120@@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
3121
3122 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3123
3124-struct dma_map_ops dma_iommu_fixed_ops = {
3125+const struct dma_map_ops dma_iommu_fixed_ops = {
3126 .alloc_coherent = dma_fixed_alloc_coherent,
3127 .free_coherent = dma_fixed_free_coherent,
3128 .map_sg = dma_fixed_map_sg,
3129diff -urNp linux-2.6.32.44/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.32.44/arch/powerpc/platforms/ps3/system-bus.c
3130--- linux-2.6.32.44/arch/powerpc/platforms/ps3/system-bus.c 2011-03-27 14:31:47.000000000 -0400
3131+++ linux-2.6.32.44/arch/powerpc/platforms/ps3/system-bus.c 2011-04-17 15:56:45.000000000 -0400
3132@@ -694,7 +694,7 @@ static int ps3_dma_supported(struct devi
3133 return mask >= DMA_BIT_MASK(32);
3134 }
3135
3136-static struct dma_map_ops ps3_sb_dma_ops = {
3137+static const struct dma_map_ops ps3_sb_dma_ops = {
3138 .alloc_coherent = ps3_alloc_coherent,
3139 .free_coherent = ps3_free_coherent,
3140 .map_sg = ps3_sb_map_sg,
3141@@ -704,7 +704,7 @@ static struct dma_map_ops ps3_sb_dma_ops
3142 .unmap_page = ps3_unmap_page,
3143 };
3144
3145-static struct dma_map_ops ps3_ioc0_dma_ops = {
3146+static const struct dma_map_ops ps3_ioc0_dma_ops = {
3147 .alloc_coherent = ps3_alloc_coherent,
3148 .free_coherent = ps3_free_coherent,
3149 .map_sg = ps3_ioc0_map_sg,
3150diff -urNp linux-2.6.32.44/arch/powerpc/platforms/pseries/Kconfig linux-2.6.32.44/arch/powerpc/platforms/pseries/Kconfig
3151--- linux-2.6.32.44/arch/powerpc/platforms/pseries/Kconfig 2011-03-27 14:31:47.000000000 -0400
3152+++ linux-2.6.32.44/arch/powerpc/platforms/pseries/Kconfig 2011-04-17 15:56:45.000000000 -0400
3153@@ -2,6 +2,8 @@ config PPC_PSERIES
3154 depends on PPC64 && PPC_BOOK3S
3155 bool "IBM pSeries & new (POWER5-based) iSeries"
3156 select MPIC
3157+ select PCI_MSI
3158+ select XICS
3159 select PPC_I8259
3160 select PPC_RTAS
3161 select RTAS_ERROR_LOGGING
3162diff -urNp linux-2.6.32.44/arch/s390/include/asm/elf.h linux-2.6.32.44/arch/s390/include/asm/elf.h
3163--- linux-2.6.32.44/arch/s390/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
3164+++ linux-2.6.32.44/arch/s390/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
3165@@ -164,6 +164,13 @@ extern unsigned int vdso_enabled;
3166 that it will "exec", and that there is sufficient room for the brk. */
3167 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3168
3169+#ifdef CONFIG_PAX_ASLR
3170+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3171+
3172+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3173+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3174+#endif
3175+
3176 /* This yields a mask that user programs can use to figure out what
3177 instruction set this CPU supports. */
3178
3179diff -urNp linux-2.6.32.44/arch/s390/include/asm/setup.h linux-2.6.32.44/arch/s390/include/asm/setup.h
3180--- linux-2.6.32.44/arch/s390/include/asm/setup.h 2011-03-27 14:31:47.000000000 -0400
3181+++ linux-2.6.32.44/arch/s390/include/asm/setup.h 2011-04-17 15:56:45.000000000 -0400
3182@@ -50,13 +50,13 @@ extern unsigned long memory_end;
3183 void detect_memory_layout(struct mem_chunk chunk[]);
3184
3185 #ifdef CONFIG_S390_SWITCH_AMODE
3186-extern unsigned int switch_amode;
3187+#define switch_amode (1)
3188 #else
3189 #define switch_amode (0)
3190 #endif
3191
3192 #ifdef CONFIG_S390_EXEC_PROTECT
3193-extern unsigned int s390_noexec;
3194+#define s390_noexec (1)
3195 #else
3196 #define s390_noexec (0)
3197 #endif
3198diff -urNp linux-2.6.32.44/arch/s390/include/asm/uaccess.h linux-2.6.32.44/arch/s390/include/asm/uaccess.h
3199--- linux-2.6.32.44/arch/s390/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
3200+++ linux-2.6.32.44/arch/s390/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
3201@@ -232,6 +232,10 @@ static inline unsigned long __must_check
3202 copy_to_user(void __user *to, const void *from, unsigned long n)
3203 {
3204 might_fault();
3205+
3206+ if ((long)n < 0)
3207+ return n;
3208+
3209 if (access_ok(VERIFY_WRITE, to, n))
3210 n = __copy_to_user(to, from, n);
3211 return n;
3212@@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void
3213 static inline unsigned long __must_check
3214 __copy_from_user(void *to, const void __user *from, unsigned long n)
3215 {
3216+ if ((long)n < 0)
3217+ return n;
3218+
3219 if (__builtin_constant_p(n) && (n <= 256))
3220 return uaccess.copy_from_user_small(n, from, to);
3221 else
3222@@ -283,6 +290,10 @@ static inline unsigned long __must_check
3223 copy_from_user(void *to, const void __user *from, unsigned long n)
3224 {
3225 might_fault();
3226+
3227+ if ((long)n < 0)
3228+ return n;
3229+
3230 if (access_ok(VERIFY_READ, from, n))
3231 n = __copy_from_user(to, from, n);
3232 else
3233diff -urNp linux-2.6.32.44/arch/s390/Kconfig linux-2.6.32.44/arch/s390/Kconfig
3234--- linux-2.6.32.44/arch/s390/Kconfig 2011-03-27 14:31:47.000000000 -0400
3235+++ linux-2.6.32.44/arch/s390/Kconfig 2011-04-17 15:56:45.000000000 -0400
3236@@ -194,28 +194,26 @@ config AUDIT_ARCH
3237
3238 config S390_SWITCH_AMODE
3239 bool "Switch kernel/user addressing modes"
3240+ default y
3241 help
3242 This option allows to switch the addressing modes of kernel and user
3243- space. The kernel parameter switch_amode=on will enable this feature,
3244- default is disabled. Enabling this (via kernel parameter) on machines
3245- earlier than IBM System z9-109 EC/BC will reduce system performance.
3246+ space. Enabling this on machines earlier than IBM System z9-109 EC/BC
3247+ will reduce system performance.
3248
3249 Note that this option will also be selected by selecting the execute
3250- protection option below. Enabling the execute protection via the
3251- noexec kernel parameter will also switch the addressing modes,
3252- independent of the switch_amode kernel parameter.
3253+ protection option below. Enabling the execute protection will also
3254+ switch the addressing modes, independent of this option.
3255
3256
3257 config S390_EXEC_PROTECT
3258 bool "Data execute protection"
3259+ default y
3260 select S390_SWITCH_AMODE
3261 help
3262 This option allows to enable a buffer overflow protection for user
3263 space programs and it also selects the addressing mode option above.
3264- The kernel parameter noexec=on will enable this feature and also
3265- switch the addressing modes, default is disabled. Enabling this (via
3266- kernel parameter) on machines earlier than IBM System z9-109 EC/BC
3267- will reduce system performance.
3268+ Enabling this on machines earlier than IBM System z9-109 EC/BC will
3269+ reduce system performance.
3270
3271 comment "Code generation options"
3272
3273diff -urNp linux-2.6.32.44/arch/s390/kernel/module.c linux-2.6.32.44/arch/s390/kernel/module.c
3274--- linux-2.6.32.44/arch/s390/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
3275+++ linux-2.6.32.44/arch/s390/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
3276@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3277
3278 /* Increase core size by size of got & plt and set start
3279 offsets for got and plt. */
3280- me->core_size = ALIGN(me->core_size, 4);
3281- me->arch.got_offset = me->core_size;
3282- me->core_size += me->arch.got_size;
3283- me->arch.plt_offset = me->core_size;
3284- me->core_size += me->arch.plt_size;
3285+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
3286+ me->arch.got_offset = me->core_size_rw;
3287+ me->core_size_rw += me->arch.got_size;
3288+ me->arch.plt_offset = me->core_size_rx;
3289+ me->core_size_rx += me->arch.plt_size;
3290 return 0;
3291 }
3292
3293@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3294 if (info->got_initialized == 0) {
3295 Elf_Addr *gotent;
3296
3297- gotent = me->module_core + me->arch.got_offset +
3298+ gotent = me->module_core_rw + me->arch.got_offset +
3299 info->got_offset;
3300 *gotent = val;
3301 info->got_initialized = 1;
3302@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3303 else if (r_type == R_390_GOTENT ||
3304 r_type == R_390_GOTPLTENT)
3305 *(unsigned int *) loc =
3306- (val + (Elf_Addr) me->module_core - loc) >> 1;
3307+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3308 else if (r_type == R_390_GOT64 ||
3309 r_type == R_390_GOTPLT64)
3310 *(unsigned long *) loc = val;
3311@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3312 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3313 if (info->plt_initialized == 0) {
3314 unsigned int *ip;
3315- ip = me->module_core + me->arch.plt_offset +
3316+ ip = me->module_core_rx + me->arch.plt_offset +
3317 info->plt_offset;
3318 #ifndef CONFIG_64BIT
3319 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3320@@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3321 val - loc + 0xffffUL < 0x1ffffeUL) ||
3322 (r_type == R_390_PLT32DBL &&
3323 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3324- val = (Elf_Addr) me->module_core +
3325+ val = (Elf_Addr) me->module_core_rx +
3326 me->arch.plt_offset +
3327 info->plt_offset;
3328 val += rela->r_addend - loc;
3329@@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3330 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3331 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3332 val = val + rela->r_addend -
3333- ((Elf_Addr) me->module_core + me->arch.got_offset);
3334+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3335 if (r_type == R_390_GOTOFF16)
3336 *(unsigned short *) loc = val;
3337 else if (r_type == R_390_GOTOFF32)
3338@@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3339 break;
3340 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3341 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3342- val = (Elf_Addr) me->module_core + me->arch.got_offset +
3343+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3344 rela->r_addend - loc;
3345 if (r_type == R_390_GOTPC)
3346 *(unsigned int *) loc = val;
3347diff -urNp linux-2.6.32.44/arch/s390/kernel/setup.c linux-2.6.32.44/arch/s390/kernel/setup.c
3348--- linux-2.6.32.44/arch/s390/kernel/setup.c 2011-03-27 14:31:47.000000000 -0400
3349+++ linux-2.6.32.44/arch/s390/kernel/setup.c 2011-04-17 15:56:45.000000000 -0400
3350@@ -306,9 +306,6 @@ static int __init early_parse_mem(char *
3351 early_param("mem", early_parse_mem);
3352
3353 #ifdef CONFIG_S390_SWITCH_AMODE
3354-unsigned int switch_amode = 0;
3355-EXPORT_SYMBOL_GPL(switch_amode);
3356-
3357 static int set_amode_and_uaccess(unsigned long user_amode,
3358 unsigned long user32_amode)
3359 {
3360@@ -334,17 +331,6 @@ static int set_amode_and_uaccess(unsigne
3361 return 0;
3362 }
3363 }
3364-
3365-/*
3366- * Switch kernel/user addressing modes?
3367- */
3368-static int __init early_parse_switch_amode(char *p)
3369-{
3370- switch_amode = 1;
3371- return 0;
3372-}
3373-early_param("switch_amode", early_parse_switch_amode);
3374-
3375 #else /* CONFIG_S390_SWITCH_AMODE */
3376 static inline int set_amode_and_uaccess(unsigned long user_amode,
3377 unsigned long user32_amode)
3378@@ -353,24 +339,6 @@ static inline int set_amode_and_uaccess(
3379 }
3380 #endif /* CONFIG_S390_SWITCH_AMODE */
3381
3382-#ifdef CONFIG_S390_EXEC_PROTECT
3383-unsigned int s390_noexec = 0;
3384-EXPORT_SYMBOL_GPL(s390_noexec);
3385-
3386-/*
3387- * Enable execute protection?
3388- */
3389-static int __init early_parse_noexec(char *p)
3390-{
3391- if (!strncmp(p, "off", 3))
3392- return 0;
3393- switch_amode = 1;
3394- s390_noexec = 1;
3395- return 0;
3396-}
3397-early_param("noexec", early_parse_noexec);
3398-#endif /* CONFIG_S390_EXEC_PROTECT */
3399-
3400 static void setup_addressing_mode(void)
3401 {
3402 if (s390_noexec) {
3403diff -urNp linux-2.6.32.44/arch/s390/mm/mmap.c linux-2.6.32.44/arch/s390/mm/mmap.c
3404--- linux-2.6.32.44/arch/s390/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3405+++ linux-2.6.32.44/arch/s390/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
3406@@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_str
3407 */
3408 if (mmap_is_legacy()) {
3409 mm->mmap_base = TASK_UNMAPPED_BASE;
3410+
3411+#ifdef CONFIG_PAX_RANDMMAP
3412+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3413+ mm->mmap_base += mm->delta_mmap;
3414+#endif
3415+
3416 mm->get_unmapped_area = arch_get_unmapped_area;
3417 mm->unmap_area = arch_unmap_area;
3418 } else {
3419 mm->mmap_base = mmap_base();
3420+
3421+#ifdef CONFIG_PAX_RANDMMAP
3422+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3423+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3424+#endif
3425+
3426 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3427 mm->unmap_area = arch_unmap_area_topdown;
3428 }
3429@@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_str
3430 */
3431 if (mmap_is_legacy()) {
3432 mm->mmap_base = TASK_UNMAPPED_BASE;
3433+
3434+#ifdef CONFIG_PAX_RANDMMAP
3435+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3436+ mm->mmap_base += mm->delta_mmap;
3437+#endif
3438+
3439 mm->get_unmapped_area = s390_get_unmapped_area;
3440 mm->unmap_area = arch_unmap_area;
3441 } else {
3442 mm->mmap_base = mmap_base();
3443+
3444+#ifdef CONFIG_PAX_RANDMMAP
3445+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3446+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3447+#endif
3448+
3449 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3450 mm->unmap_area = arch_unmap_area_topdown;
3451 }
3452diff -urNp linux-2.6.32.44/arch/score/include/asm/system.h linux-2.6.32.44/arch/score/include/asm/system.h
3453--- linux-2.6.32.44/arch/score/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
3454+++ linux-2.6.32.44/arch/score/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
3455@@ -17,7 +17,7 @@ do { \
3456 #define finish_arch_switch(prev) do {} while (0)
3457
3458 typedef void (*vi_handler_t)(void);
3459-extern unsigned long arch_align_stack(unsigned long sp);
3460+#define arch_align_stack(x) (x)
3461
3462 #define mb() barrier()
3463 #define rmb() barrier()
3464diff -urNp linux-2.6.32.44/arch/score/kernel/process.c linux-2.6.32.44/arch/score/kernel/process.c
3465--- linux-2.6.32.44/arch/score/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
3466+++ linux-2.6.32.44/arch/score/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
3467@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
3468
3469 return task_pt_regs(task)->cp0_epc;
3470 }
3471-
3472-unsigned long arch_align_stack(unsigned long sp)
3473-{
3474- return sp;
3475-}
3476diff -urNp linux-2.6.32.44/arch/sh/boards/mach-hp6xx/pm.c linux-2.6.32.44/arch/sh/boards/mach-hp6xx/pm.c
3477--- linux-2.6.32.44/arch/sh/boards/mach-hp6xx/pm.c 2011-03-27 14:31:47.000000000 -0400
3478+++ linux-2.6.32.44/arch/sh/boards/mach-hp6xx/pm.c 2011-04-17 15:56:45.000000000 -0400
3479@@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_
3480 return 0;
3481 }
3482
3483-static struct platform_suspend_ops hp6x0_pm_ops = {
3484+static const struct platform_suspend_ops hp6x0_pm_ops = {
3485 .enter = hp6x0_pm_enter,
3486 .valid = suspend_valid_only_mem,
3487 };
3488diff -urNp linux-2.6.32.44/arch/sh/kernel/cpu/sh4/sq.c linux-2.6.32.44/arch/sh/kernel/cpu/sh4/sq.c
3489--- linux-2.6.32.44/arch/sh/kernel/cpu/sh4/sq.c 2011-03-27 14:31:47.000000000 -0400
3490+++ linux-2.6.32.44/arch/sh/kernel/cpu/sh4/sq.c 2011-04-17 15:56:46.000000000 -0400
3491@@ -327,7 +327,7 @@ static struct attribute *sq_sysfs_attrs[
3492 NULL,
3493 };
3494
3495-static struct sysfs_ops sq_sysfs_ops = {
3496+static const struct sysfs_ops sq_sysfs_ops = {
3497 .show = sq_sysfs_show,
3498 .store = sq_sysfs_store,
3499 };
3500diff -urNp linux-2.6.32.44/arch/sh/kernel/cpu/shmobile/pm.c linux-2.6.32.44/arch/sh/kernel/cpu/shmobile/pm.c
3501--- linux-2.6.32.44/arch/sh/kernel/cpu/shmobile/pm.c 2011-03-27 14:31:47.000000000 -0400
3502+++ linux-2.6.32.44/arch/sh/kernel/cpu/shmobile/pm.c 2011-04-17 15:56:46.000000000 -0400
3503@@ -58,7 +58,7 @@ static int sh_pm_enter(suspend_state_t s
3504 return 0;
3505 }
3506
3507-static struct platform_suspend_ops sh_pm_ops = {
3508+static const struct platform_suspend_ops sh_pm_ops = {
3509 .enter = sh_pm_enter,
3510 .valid = suspend_valid_only_mem,
3511 };
3512diff -urNp linux-2.6.32.44/arch/sh/kernel/kgdb.c linux-2.6.32.44/arch/sh/kernel/kgdb.c
3513--- linux-2.6.32.44/arch/sh/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
3514+++ linux-2.6.32.44/arch/sh/kernel/kgdb.c 2011-04-17 15:56:46.000000000 -0400
3515@@ -271,7 +271,7 @@ void kgdb_arch_exit(void)
3516 {
3517 }
3518
3519-struct kgdb_arch arch_kgdb_ops = {
3520+const struct kgdb_arch arch_kgdb_ops = {
3521 /* Breakpoint instruction: trapa #0x3c */
3522 #ifdef CONFIG_CPU_LITTLE_ENDIAN
3523 .gdb_bpt_instr = { 0x3c, 0xc3 },
3524diff -urNp linux-2.6.32.44/arch/sh/mm/mmap.c linux-2.6.32.44/arch/sh/mm/mmap.c
3525--- linux-2.6.32.44/arch/sh/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3526+++ linux-2.6.32.44/arch/sh/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
3527@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
3528 addr = PAGE_ALIGN(addr);
3529
3530 vma = find_vma(mm, addr);
3531- if (TASK_SIZE - len >= addr &&
3532- (!vma || addr + len <= vma->vm_start))
3533+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3534 return addr;
3535 }
3536
3537@@ -106,7 +105,7 @@ full_search:
3538 }
3539 return -ENOMEM;
3540 }
3541- if (likely(!vma || addr + len <= vma->vm_start)) {
3542+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3543 /*
3544 * Remember the place where we stopped the search:
3545 */
3546@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
3547 addr = PAGE_ALIGN(addr);
3548
3549 vma = find_vma(mm, addr);
3550- if (TASK_SIZE - len >= addr &&
3551- (!vma || addr + len <= vma->vm_start))
3552+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3553 return addr;
3554 }
3555
3556@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
3557 /* make sure it can fit in the remaining address space */
3558 if (likely(addr > len)) {
3559 vma = find_vma(mm, addr-len);
3560- if (!vma || addr <= vma->vm_start) {
3561+ if (check_heap_stack_gap(vma, addr - len, len)) {
3562 /* remember the address as a hint for next time */
3563 return (mm->free_area_cache = addr-len);
3564 }
3565@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
3566 if (unlikely(mm->mmap_base < len))
3567 goto bottomup;
3568
3569- addr = mm->mmap_base-len;
3570- if (do_colour_align)
3571- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3572+ addr = mm->mmap_base - len;
3573
3574 do {
3575+ if (do_colour_align)
3576+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3577 /*
3578 * Lookup failure means no vma is above this address,
3579 * else if new region fits below vma->vm_start,
3580 * return with success:
3581 */
3582 vma = find_vma(mm, addr);
3583- if (likely(!vma || addr+len <= vma->vm_start)) {
3584+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3585 /* remember the address as a hint for next time */
3586 return (mm->free_area_cache = addr);
3587 }
3588@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
3589 mm->cached_hole_size = vma->vm_start - addr;
3590
3591 /* try just below the current vma->vm_start */
3592- addr = vma->vm_start-len;
3593- if (do_colour_align)
3594- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3595- } while (likely(len < vma->vm_start));
3596+ addr = skip_heap_stack_gap(vma, len);
3597+ } while (!IS_ERR_VALUE(addr));
3598
3599 bottomup:
3600 /*
3601diff -urNp linux-2.6.32.44/arch/sparc/include/asm/atomic_64.h linux-2.6.32.44/arch/sparc/include/asm/atomic_64.h
3602--- linux-2.6.32.44/arch/sparc/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
3603+++ linux-2.6.32.44/arch/sparc/include/asm/atomic_64.h 2011-07-13 22:22:56.000000000 -0400
3604@@ -14,18 +14,40 @@
3605 #define ATOMIC64_INIT(i) { (i) }
3606
3607 #define atomic_read(v) ((v)->counter)
3608+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3609+{
3610+ return v->counter;
3611+}
3612 #define atomic64_read(v) ((v)->counter)
3613+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3614+{
3615+ return v->counter;
3616+}
3617
3618 #define atomic_set(v, i) (((v)->counter) = i)
3619+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3620+{
3621+ v->counter = i;
3622+}
3623 #define atomic64_set(v, i) (((v)->counter) = i)
3624+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3625+{
3626+ v->counter = i;
3627+}
3628
3629 extern void atomic_add(int, atomic_t *);
3630+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3631 extern void atomic64_add(long, atomic64_t *);
3632+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3633 extern void atomic_sub(int, atomic_t *);
3634+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3635 extern void atomic64_sub(long, atomic64_t *);
3636+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3637
3638 extern int atomic_add_ret(int, atomic_t *);
3639+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3640 extern long atomic64_add_ret(long, atomic64_t *);
3641+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3642 extern int atomic_sub_ret(int, atomic_t *);
3643 extern long atomic64_sub_ret(long, atomic64_t *);
3644
3645@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomi
3646 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3647
3648 #define atomic_inc_return(v) atomic_add_ret(1, v)
3649+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3650+{
3651+ return atomic_add_ret_unchecked(1, v);
3652+}
3653 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3654+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3655+{
3656+ return atomic64_add_ret_unchecked(1, v);
3657+}
3658
3659 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3660 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3661
3662 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3663+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3664+{
3665+ return atomic_add_ret_unchecked(i, v);
3666+}
3667 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3668+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
3669+{
3670+ return atomic64_add_ret_unchecked(i, v);
3671+}
3672
3673 /*
3674 * atomic_inc_and_test - increment and test
3675@@ -50,6 +88,7 @@ extern long atomic64_sub_ret(long, atomi
3676 * other cases.
3677 */
3678 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3679+#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
3680 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3681
3682 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3683@@ -59,30 +98,59 @@ extern long atomic64_sub_ret(long, atomi
3684 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3685
3686 #define atomic_inc(v) atomic_add(1, v)
3687+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3688+{
3689+ atomic_add_unchecked(1, v);
3690+}
3691 #define atomic64_inc(v) atomic64_add(1, v)
3692+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3693+{
3694+ atomic64_add_unchecked(1, v);
3695+}
3696
3697 #define atomic_dec(v) atomic_sub(1, v)
3698+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3699+{
3700+ atomic_sub_unchecked(1, v);
3701+}
3702 #define atomic64_dec(v) atomic64_sub(1, v)
3703+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3704+{
3705+ atomic64_sub_unchecked(1, v);
3706+}
3707
3708 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3709 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3710
3711 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3712+#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3713 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3714+#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
3715
3716 static inline int atomic_add_unless(atomic_t *v, int a, int u)
3717 {
3718- int c, old;
3719+ int c, old, new;
3720 c = atomic_read(v);
3721 for (;;) {
3722- if (unlikely(c == (u)))
3723+ if (unlikely(c == u))
3724 break;
3725- old = atomic_cmpxchg((v), c, c + (a));
3726+
3727+ asm volatile("addcc %2, %0, %0\n"
3728+
3729+#ifdef CONFIG_PAX_REFCOUNT
3730+ "tvs %%icc, 6\n"
3731+#endif
3732+
3733+ : "=r" (new)
3734+ : "0" (c), "ir" (a)
3735+ : "cc");
3736+
3737+ old = atomic_cmpxchg(v, c, new);
3738 if (likely(old == c))
3739 break;
3740 c = old;
3741 }
3742- return c != (u);
3743+ return c != u;
3744 }
3745
3746 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
3747@@ -93,17 +161,28 @@ static inline int atomic_add_unless(atom
3748
3749 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3750 {
3751- long c, old;
3752+ long c, old, new;
3753 c = atomic64_read(v);
3754 for (;;) {
3755- if (unlikely(c == (u)))
3756+ if (unlikely(c == u))
3757 break;
3758- old = atomic64_cmpxchg((v), c, c + (a));
3759+
3760+ asm volatile("addcc %2, %0, %0\n"
3761+
3762+#ifdef CONFIG_PAX_REFCOUNT
3763+ "tvs %%xcc, 6\n"
3764+#endif
3765+
3766+ : "=r" (new)
3767+ : "0" (c), "ir" (a)
3768+ : "cc");
3769+
3770+ old = atomic64_cmpxchg(v, c, new);
3771 if (likely(old == c))
3772 break;
3773 c = old;
3774 }
3775- return c != (u);
3776+ return c != u;
3777 }
3778
3779 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3780diff -urNp linux-2.6.32.44/arch/sparc/include/asm/cache.h linux-2.6.32.44/arch/sparc/include/asm/cache.h
3781--- linux-2.6.32.44/arch/sparc/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
3782+++ linux-2.6.32.44/arch/sparc/include/asm/cache.h 2011-07-06 19:53:33.000000000 -0400
3783@@ -8,7 +8,7 @@
3784 #define _SPARC_CACHE_H
3785
3786 #define L1_CACHE_SHIFT 5
3787-#define L1_CACHE_BYTES 32
3788+#define L1_CACHE_BYTES 32UL
3789 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
3790
3791 #ifdef CONFIG_SPARC32
3792diff -urNp linux-2.6.32.44/arch/sparc/include/asm/dma-mapping.h linux-2.6.32.44/arch/sparc/include/asm/dma-mapping.h
3793--- linux-2.6.32.44/arch/sparc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
3794+++ linux-2.6.32.44/arch/sparc/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
3795@@ -14,10 +14,10 @@ extern int dma_set_mask(struct device *d
3796 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
3797 #define dma_is_consistent(d, h) (1)
3798
3799-extern struct dma_map_ops *dma_ops, pci32_dma_ops;
3800+extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
3801 extern struct bus_type pci_bus_type;
3802
3803-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3804+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3805 {
3806 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
3807 if (dev->bus == &pci_bus_type)
3808@@ -31,7 +31,7 @@ static inline struct dma_map_ops *get_dm
3809 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3810 dma_addr_t *dma_handle, gfp_t flag)
3811 {
3812- struct dma_map_ops *ops = get_dma_ops(dev);
3813+ const struct dma_map_ops *ops = get_dma_ops(dev);
3814 void *cpu_addr;
3815
3816 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
3817@@ -42,7 +42,7 @@ static inline void *dma_alloc_coherent(s
3818 static inline void dma_free_coherent(struct device *dev, size_t size,
3819 void *cpu_addr, dma_addr_t dma_handle)
3820 {
3821- struct dma_map_ops *ops = get_dma_ops(dev);
3822+ const struct dma_map_ops *ops = get_dma_ops(dev);
3823
3824 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
3825 ops->free_coherent(dev, size, cpu_addr, dma_handle);
3826diff -urNp linux-2.6.32.44/arch/sparc/include/asm/elf_32.h linux-2.6.32.44/arch/sparc/include/asm/elf_32.h
3827--- linux-2.6.32.44/arch/sparc/include/asm/elf_32.h 2011-03-27 14:31:47.000000000 -0400
3828+++ linux-2.6.32.44/arch/sparc/include/asm/elf_32.h 2011-04-17 15:56:46.000000000 -0400
3829@@ -116,6 +116,13 @@ typedef struct {
3830
3831 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3832
3833+#ifdef CONFIG_PAX_ASLR
3834+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3835+
3836+#define PAX_DELTA_MMAP_LEN 16
3837+#define PAX_DELTA_STACK_LEN 16
3838+#endif
3839+
3840 /* This yields a mask that user programs can use to figure out what
3841 instruction set this cpu supports. This can NOT be done in userspace
3842 on Sparc. */
3843diff -urNp linux-2.6.32.44/arch/sparc/include/asm/elf_64.h linux-2.6.32.44/arch/sparc/include/asm/elf_64.h
3844--- linux-2.6.32.44/arch/sparc/include/asm/elf_64.h 2011-03-27 14:31:47.000000000 -0400
3845+++ linux-2.6.32.44/arch/sparc/include/asm/elf_64.h 2011-04-17 15:56:46.000000000 -0400
3846@@ -163,6 +163,12 @@ typedef struct {
3847 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3848 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3849
3850+#ifdef CONFIG_PAX_ASLR
3851+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3852+
3853+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3854+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3855+#endif
3856
3857 /* This yields a mask that user programs can use to figure out what
3858 instruction set this cpu supports. */
3859diff -urNp linux-2.6.32.44/arch/sparc/include/asm/pgtable_32.h linux-2.6.32.44/arch/sparc/include/asm/pgtable_32.h
3860--- linux-2.6.32.44/arch/sparc/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
3861+++ linux-2.6.32.44/arch/sparc/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
3862@@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3863 BTFIXUPDEF_INT(page_none)
3864 BTFIXUPDEF_INT(page_copy)
3865 BTFIXUPDEF_INT(page_readonly)
3866+
3867+#ifdef CONFIG_PAX_PAGEEXEC
3868+BTFIXUPDEF_INT(page_shared_noexec)
3869+BTFIXUPDEF_INT(page_copy_noexec)
3870+BTFIXUPDEF_INT(page_readonly_noexec)
3871+#endif
3872+
3873 BTFIXUPDEF_INT(page_kernel)
3874
3875 #define PMD_SHIFT SUN4C_PMD_SHIFT
3876@@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
3877 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3878 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3879
3880+#ifdef CONFIG_PAX_PAGEEXEC
3881+extern pgprot_t PAGE_SHARED_NOEXEC;
3882+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3883+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3884+#else
3885+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3886+# define PAGE_COPY_NOEXEC PAGE_COPY
3887+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3888+#endif
3889+
3890 extern unsigned long page_kernel;
3891
3892 #ifdef MODULE
3893diff -urNp linux-2.6.32.44/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.32.44/arch/sparc/include/asm/pgtsrmmu.h
3894--- linux-2.6.32.44/arch/sparc/include/asm/pgtsrmmu.h 2011-03-27 14:31:47.000000000 -0400
3895+++ linux-2.6.32.44/arch/sparc/include/asm/pgtsrmmu.h 2011-04-17 15:56:46.000000000 -0400
3896@@ -115,6 +115,13 @@
3897 SRMMU_EXEC | SRMMU_REF)
3898 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3899 SRMMU_EXEC | SRMMU_REF)
3900+
3901+#ifdef CONFIG_PAX_PAGEEXEC
3902+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3903+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3904+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3905+#endif
3906+
3907 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3908 SRMMU_DIRTY | SRMMU_REF)
3909
3910diff -urNp linux-2.6.32.44/arch/sparc/include/asm/spinlock_64.h linux-2.6.32.44/arch/sparc/include/asm/spinlock_64.h
3911--- linux-2.6.32.44/arch/sparc/include/asm/spinlock_64.h 2011-03-27 14:31:47.000000000 -0400
3912+++ linux-2.6.32.44/arch/sparc/include/asm/spinlock_64.h 2011-05-04 17:56:20.000000000 -0400
3913@@ -92,14 +92,19 @@ static inline void __raw_spin_lock_flags
3914
3915 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3916
3917-static void inline arch_read_lock(raw_rwlock_t *lock)
3918+static inline void arch_read_lock(raw_rwlock_t *lock)
3919 {
3920 unsigned long tmp1, tmp2;
3921
3922 __asm__ __volatile__ (
3923 "1: ldsw [%2], %0\n"
3924 " brlz,pn %0, 2f\n"
3925-"4: add %0, 1, %1\n"
3926+"4: addcc %0, 1, %1\n"
3927+
3928+#ifdef CONFIG_PAX_REFCOUNT
3929+" tvs %%icc, 6\n"
3930+#endif
3931+
3932 " cas [%2], %0, %1\n"
3933 " cmp %0, %1\n"
3934 " bne,pn %%icc, 1b\n"
3935@@ -112,7 +117,7 @@ static void inline arch_read_lock(raw_rw
3936 " .previous"
3937 : "=&r" (tmp1), "=&r" (tmp2)
3938 : "r" (lock)
3939- : "memory");
3940+ : "memory", "cc");
3941 }
3942
3943 static int inline arch_read_trylock(raw_rwlock_t *lock)
3944@@ -123,7 +128,12 @@ static int inline arch_read_trylock(raw_
3945 "1: ldsw [%2], %0\n"
3946 " brlz,a,pn %0, 2f\n"
3947 " mov 0, %0\n"
3948-" add %0, 1, %1\n"
3949+" addcc %0, 1, %1\n"
3950+
3951+#ifdef CONFIG_PAX_REFCOUNT
3952+" tvs %%icc, 6\n"
3953+#endif
3954+
3955 " cas [%2], %0, %1\n"
3956 " cmp %0, %1\n"
3957 " bne,pn %%icc, 1b\n"
3958@@ -136,13 +146,18 @@ static int inline arch_read_trylock(raw_
3959 return tmp1;
3960 }
3961
3962-static void inline arch_read_unlock(raw_rwlock_t *lock)
3963+static inline void arch_read_unlock(raw_rwlock_t *lock)
3964 {
3965 unsigned long tmp1, tmp2;
3966
3967 __asm__ __volatile__(
3968 "1: lduw [%2], %0\n"
3969-" sub %0, 1, %1\n"
3970+" subcc %0, 1, %1\n"
3971+
3972+#ifdef CONFIG_PAX_REFCOUNT
3973+" tvs %%icc, 6\n"
3974+#endif
3975+
3976 " cas [%2], %0, %1\n"
3977 " cmp %0, %1\n"
3978 " bne,pn %%xcc, 1b\n"
3979@@ -152,7 +167,7 @@ static void inline arch_read_unlock(raw_
3980 : "memory");
3981 }
3982
3983-static void inline arch_write_lock(raw_rwlock_t *lock)
3984+static inline void arch_write_lock(raw_rwlock_t *lock)
3985 {
3986 unsigned long mask, tmp1, tmp2;
3987
3988@@ -177,7 +192,7 @@ static void inline arch_write_lock(raw_r
3989 : "memory");
3990 }
3991
3992-static void inline arch_write_unlock(raw_rwlock_t *lock)
3993+static inline void arch_write_unlock(raw_rwlock_t *lock)
3994 {
3995 __asm__ __volatile__(
3996 " stw %%g0, [%0]"
3997diff -urNp linux-2.6.32.44/arch/sparc/include/asm/thread_info_32.h linux-2.6.32.44/arch/sparc/include/asm/thread_info_32.h
3998--- linux-2.6.32.44/arch/sparc/include/asm/thread_info_32.h 2011-03-27 14:31:47.000000000 -0400
3999+++ linux-2.6.32.44/arch/sparc/include/asm/thread_info_32.h 2011-06-04 20:46:01.000000000 -0400
4000@@ -50,6 +50,8 @@ struct thread_info {
4001 unsigned long w_saved;
4002
4003 struct restart_block restart_block;
4004+
4005+ unsigned long lowest_stack;
4006 };
4007
4008 /*
4009diff -urNp linux-2.6.32.44/arch/sparc/include/asm/thread_info_64.h linux-2.6.32.44/arch/sparc/include/asm/thread_info_64.h
4010--- linux-2.6.32.44/arch/sparc/include/asm/thread_info_64.h 2011-03-27 14:31:47.000000000 -0400
4011+++ linux-2.6.32.44/arch/sparc/include/asm/thread_info_64.h 2011-06-04 20:46:21.000000000 -0400
4012@@ -68,6 +68,8 @@ struct thread_info {
4013 struct pt_regs *kern_una_regs;
4014 unsigned int kern_una_insn;
4015
4016+ unsigned long lowest_stack;
4017+
4018 unsigned long fpregs[0] __attribute__ ((aligned(64)));
4019 };
4020
4021diff -urNp linux-2.6.32.44/arch/sparc/include/asm/uaccess_32.h linux-2.6.32.44/arch/sparc/include/asm/uaccess_32.h
4022--- linux-2.6.32.44/arch/sparc/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
4023+++ linux-2.6.32.44/arch/sparc/include/asm/uaccess_32.h 2011-04-17 15:56:46.000000000 -0400
4024@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
4025
4026 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4027 {
4028- if (n && __access_ok((unsigned long) to, n))
4029+ if ((long)n < 0)
4030+ return n;
4031+
4032+ if (n && __access_ok((unsigned long) to, n)) {
4033+ if (!__builtin_constant_p(n))
4034+ check_object_size(from, n, true);
4035 return __copy_user(to, (__force void __user *) from, n);
4036- else
4037+ } else
4038 return n;
4039 }
4040
4041 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4042 {
4043+ if ((long)n < 0)
4044+ return n;
4045+
4046+ if (!__builtin_constant_p(n))
4047+ check_object_size(from, n, true);
4048+
4049 return __copy_user(to, (__force void __user *) from, n);
4050 }
4051
4052 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4053 {
4054- if (n && __access_ok((unsigned long) from, n))
4055+ if ((long)n < 0)
4056+ return n;
4057+
4058+ if (n && __access_ok((unsigned long) from, n)) {
4059+ if (!__builtin_constant_p(n))
4060+ check_object_size(to, n, false);
4061 return __copy_user((__force void __user *) to, from, n);
4062- else
4063+ } else
4064 return n;
4065 }
4066
4067 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4068 {
4069+ if ((long)n < 0)
4070+ return n;
4071+
4072 return __copy_user((__force void __user *) to, from, n);
4073 }
4074
4075diff -urNp linux-2.6.32.44/arch/sparc/include/asm/uaccess_64.h linux-2.6.32.44/arch/sparc/include/asm/uaccess_64.h
4076--- linux-2.6.32.44/arch/sparc/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
4077+++ linux-2.6.32.44/arch/sparc/include/asm/uaccess_64.h 2011-04-17 15:56:46.000000000 -0400
4078@@ -9,6 +9,7 @@
4079 #include <linux/compiler.h>
4080 #include <linux/string.h>
4081 #include <linux/thread_info.h>
4082+#include <linux/kernel.h>
4083 #include <asm/asi.h>
4084 #include <asm/system.h>
4085 #include <asm/spitfire.h>
4086@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixu
4087 static inline unsigned long __must_check
4088 copy_from_user(void *to, const void __user *from, unsigned long size)
4089 {
4090- unsigned long ret = ___copy_from_user(to, from, size);
4091+ unsigned long ret;
4092
4093+ if ((long)size < 0 || size > INT_MAX)
4094+ return size;
4095+
4096+ if (!__builtin_constant_p(size))
4097+ check_object_size(to, size, false);
4098+
4099+ ret = ___copy_from_user(to, from, size);
4100 if (unlikely(ret))
4101 ret = copy_from_user_fixup(to, from, size);
4102 return ret;
4103@@ -228,8 +236,15 @@ extern unsigned long copy_to_user_fixup(
4104 static inline unsigned long __must_check
4105 copy_to_user(void __user *to, const void *from, unsigned long size)
4106 {
4107- unsigned long ret = ___copy_to_user(to, from, size);
4108+ unsigned long ret;
4109+
4110+ if ((long)size < 0 || size > INT_MAX)
4111+ return size;
4112+
4113+ if (!__builtin_constant_p(size))
4114+ check_object_size(from, size, true);
4115
4116+ ret = ___copy_to_user(to, from, size);
4117 if (unlikely(ret))
4118 ret = copy_to_user_fixup(to, from, size);
4119 return ret;
4120diff -urNp linux-2.6.32.44/arch/sparc/include/asm/uaccess.h linux-2.6.32.44/arch/sparc/include/asm/uaccess.h
4121--- linux-2.6.32.44/arch/sparc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
4122+++ linux-2.6.32.44/arch/sparc/include/asm/uaccess.h 2011-04-17 15:56:46.000000000 -0400
4123@@ -1,5 +1,13 @@
4124 #ifndef ___ASM_SPARC_UACCESS_H
4125 #define ___ASM_SPARC_UACCESS_H
4126+
4127+#ifdef __KERNEL__
4128+#ifndef __ASSEMBLY__
4129+#include <linux/types.h>
4130+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4131+#endif
4132+#endif
4133+
4134 #if defined(__sparc__) && defined(__arch64__)
4135 #include <asm/uaccess_64.h>
4136 #else
4137diff -urNp linux-2.6.32.44/arch/sparc/kernel/iommu.c linux-2.6.32.44/arch/sparc/kernel/iommu.c
4138--- linux-2.6.32.44/arch/sparc/kernel/iommu.c 2011-03-27 14:31:47.000000000 -0400
4139+++ linux-2.6.32.44/arch/sparc/kernel/iommu.c 2011-04-17 15:56:46.000000000 -0400
4140@@ -826,7 +826,7 @@ static void dma_4u_sync_sg_for_cpu(struc
4141 spin_unlock_irqrestore(&iommu->lock, flags);
4142 }
4143
4144-static struct dma_map_ops sun4u_dma_ops = {
4145+static const struct dma_map_ops sun4u_dma_ops = {
4146 .alloc_coherent = dma_4u_alloc_coherent,
4147 .free_coherent = dma_4u_free_coherent,
4148 .map_page = dma_4u_map_page,
4149@@ -837,7 +837,7 @@ static struct dma_map_ops sun4u_dma_ops
4150 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
4151 };
4152
4153-struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4154+const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4155 EXPORT_SYMBOL(dma_ops);
4156
4157 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
4158diff -urNp linux-2.6.32.44/arch/sparc/kernel/ioport.c linux-2.6.32.44/arch/sparc/kernel/ioport.c
4159--- linux-2.6.32.44/arch/sparc/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
4160+++ linux-2.6.32.44/arch/sparc/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
4161@@ -392,7 +392,7 @@ static void sbus_sync_sg_for_device(stru
4162 BUG();
4163 }
4164
4165-struct dma_map_ops sbus_dma_ops = {
4166+const struct dma_map_ops sbus_dma_ops = {
4167 .alloc_coherent = sbus_alloc_coherent,
4168 .free_coherent = sbus_free_coherent,
4169 .map_page = sbus_map_page,
4170@@ -403,7 +403,7 @@ struct dma_map_ops sbus_dma_ops = {
4171 .sync_sg_for_device = sbus_sync_sg_for_device,
4172 };
4173
4174-struct dma_map_ops *dma_ops = &sbus_dma_ops;
4175+const struct dma_map_ops *dma_ops = &sbus_dma_ops;
4176 EXPORT_SYMBOL(dma_ops);
4177
4178 static int __init sparc_register_ioport(void)
4179@@ -640,7 +640,7 @@ static void pci32_sync_sg_for_device(str
4180 }
4181 }
4182
4183-struct dma_map_ops pci32_dma_ops = {
4184+const struct dma_map_ops pci32_dma_ops = {
4185 .alloc_coherent = pci32_alloc_coherent,
4186 .free_coherent = pci32_free_coherent,
4187 .map_page = pci32_map_page,
4188diff -urNp linux-2.6.32.44/arch/sparc/kernel/kgdb_32.c linux-2.6.32.44/arch/sparc/kernel/kgdb_32.c
4189--- linux-2.6.32.44/arch/sparc/kernel/kgdb_32.c 2011-03-27 14:31:47.000000000 -0400
4190+++ linux-2.6.32.44/arch/sparc/kernel/kgdb_32.c 2011-04-17 15:56:46.000000000 -0400
4191@@ -158,7 +158,7 @@ void kgdb_arch_exit(void)
4192 {
4193 }
4194
4195-struct kgdb_arch arch_kgdb_ops = {
4196+const struct kgdb_arch arch_kgdb_ops = {
4197 /* Breakpoint instruction: ta 0x7d */
4198 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
4199 };
4200diff -urNp linux-2.6.32.44/arch/sparc/kernel/kgdb_64.c linux-2.6.32.44/arch/sparc/kernel/kgdb_64.c
4201--- linux-2.6.32.44/arch/sparc/kernel/kgdb_64.c 2011-03-27 14:31:47.000000000 -0400
4202+++ linux-2.6.32.44/arch/sparc/kernel/kgdb_64.c 2011-04-17 15:56:46.000000000 -0400
4203@@ -180,7 +180,7 @@ void kgdb_arch_exit(void)
4204 {
4205 }
4206
4207-struct kgdb_arch arch_kgdb_ops = {
4208+const struct kgdb_arch arch_kgdb_ops = {
4209 /* Breakpoint instruction: ta 0x72 */
4210 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
4211 };
4212diff -urNp linux-2.6.32.44/arch/sparc/kernel/Makefile linux-2.6.32.44/arch/sparc/kernel/Makefile
4213--- linux-2.6.32.44/arch/sparc/kernel/Makefile 2011-03-27 14:31:47.000000000 -0400
4214+++ linux-2.6.32.44/arch/sparc/kernel/Makefile 2011-04-17 15:56:46.000000000 -0400
4215@@ -3,7 +3,7 @@
4216 #
4217
4218 asflags-y := -ansi
4219-ccflags-y := -Werror
4220+#ccflags-y := -Werror
4221
4222 extra-y := head_$(BITS).o
4223 extra-y += init_task.o
4224diff -urNp linux-2.6.32.44/arch/sparc/kernel/pci_sun4v.c linux-2.6.32.44/arch/sparc/kernel/pci_sun4v.c
4225--- linux-2.6.32.44/arch/sparc/kernel/pci_sun4v.c 2011-03-27 14:31:47.000000000 -0400
4226+++ linux-2.6.32.44/arch/sparc/kernel/pci_sun4v.c 2011-04-17 15:56:46.000000000 -0400
4227@@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
4228 spin_unlock_irqrestore(&iommu->lock, flags);
4229 }
4230
4231-static struct dma_map_ops sun4v_dma_ops = {
4232+static const struct dma_map_ops sun4v_dma_ops = {
4233 .alloc_coherent = dma_4v_alloc_coherent,
4234 .free_coherent = dma_4v_free_coherent,
4235 .map_page = dma_4v_map_page,
4236diff -urNp linux-2.6.32.44/arch/sparc/kernel/process_32.c linux-2.6.32.44/arch/sparc/kernel/process_32.c
4237--- linux-2.6.32.44/arch/sparc/kernel/process_32.c 2011-03-27 14:31:47.000000000 -0400
4238+++ linux-2.6.32.44/arch/sparc/kernel/process_32.c 2011-04-17 15:56:46.000000000 -0400
4239@@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4240 rw->ins[4], rw->ins[5],
4241 rw->ins[6],
4242 rw->ins[7]);
4243- printk("%pS\n", (void *) rw->ins[7]);
4244+ printk("%pA\n", (void *) rw->ins[7]);
4245 rw = (struct reg_window32 *) rw->ins[6];
4246 }
4247 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4248@@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4249
4250 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4251 r->psr, r->pc, r->npc, r->y, print_tainted());
4252- printk("PC: <%pS>\n", (void *) r->pc);
4253+ printk("PC: <%pA>\n", (void *) r->pc);
4254 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4255 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4256 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4257 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4258 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4259 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4260- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4261+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4262
4263 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4264 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4265@@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
4266 rw = (struct reg_window32 *) fp;
4267 pc = rw->ins[7];
4268 printk("[%08lx : ", pc);
4269- printk("%pS ] ", (void *) pc);
4270+ printk("%pA ] ", (void *) pc);
4271 fp = rw->ins[6];
4272 } while (++count < 16);
4273 printk("\n");
4274diff -urNp linux-2.6.32.44/arch/sparc/kernel/process_64.c linux-2.6.32.44/arch/sparc/kernel/process_64.c
4275--- linux-2.6.32.44/arch/sparc/kernel/process_64.c 2011-03-27 14:31:47.000000000 -0400
4276+++ linux-2.6.32.44/arch/sparc/kernel/process_64.c 2011-04-17 15:56:46.000000000 -0400
4277@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
4278 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4279 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4280 if (regs->tstate & TSTATE_PRIV)
4281- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4282+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4283 }
4284
4285 void show_regs(struct pt_regs *regs)
4286 {
4287 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4288 regs->tpc, regs->tnpc, regs->y, print_tainted());
4289- printk("TPC: <%pS>\n", (void *) regs->tpc);
4290+ printk("TPC: <%pA>\n", (void *) regs->tpc);
4291 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4292 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4293 regs->u_regs[3]);
4294@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4295 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4296 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4297 regs->u_regs[15]);
4298- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4299+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4300 show_regwindow(regs);
4301 }
4302
4303@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void
4304 ((tp && tp->task) ? tp->task->pid : -1));
4305
4306 if (gp->tstate & TSTATE_PRIV) {
4307- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4308+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4309 (void *) gp->tpc,
4310 (void *) gp->o7,
4311 (void *) gp->i7,
4312diff -urNp linux-2.6.32.44/arch/sparc/kernel/sys_sparc_32.c linux-2.6.32.44/arch/sparc/kernel/sys_sparc_32.c
4313--- linux-2.6.32.44/arch/sparc/kernel/sys_sparc_32.c 2011-03-27 14:31:47.000000000 -0400
4314+++ linux-2.6.32.44/arch/sparc/kernel/sys_sparc_32.c 2011-04-17 15:56:46.000000000 -0400
4315@@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(str
4316 if (ARCH_SUN4C && len > 0x20000000)
4317 return -ENOMEM;
4318 if (!addr)
4319- addr = TASK_UNMAPPED_BASE;
4320+ addr = current->mm->mmap_base;
4321
4322 if (flags & MAP_SHARED)
4323 addr = COLOUR_ALIGN(addr);
4324@@ -72,7 +72,7 @@ unsigned long arch_get_unmapped_area(str
4325 }
4326 if (TASK_SIZE - PAGE_SIZE - len < addr)
4327 return -ENOMEM;
4328- if (!vmm || addr + len <= vmm->vm_start)
4329+ if (check_heap_stack_gap(vmm, addr, len))
4330 return addr;
4331 addr = vmm->vm_end;
4332 if (flags & MAP_SHARED)
4333diff -urNp linux-2.6.32.44/arch/sparc/kernel/sys_sparc_64.c linux-2.6.32.44/arch/sparc/kernel/sys_sparc_64.c
4334--- linux-2.6.32.44/arch/sparc/kernel/sys_sparc_64.c 2011-03-27 14:31:47.000000000 -0400
4335+++ linux-2.6.32.44/arch/sparc/kernel/sys_sparc_64.c 2011-04-17 15:56:46.000000000 -0400
4336@@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(str
4337 /* We do not accept a shared mapping if it would violate
4338 * cache aliasing constraints.
4339 */
4340- if ((flags & MAP_SHARED) &&
4341+ if ((filp || (flags & MAP_SHARED)) &&
4342 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4343 return -EINVAL;
4344 return addr;
4345@@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(str
4346 if (filp || (flags & MAP_SHARED))
4347 do_color_align = 1;
4348
4349+#ifdef CONFIG_PAX_RANDMMAP
4350+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4351+#endif
4352+
4353 if (addr) {
4354 if (do_color_align)
4355 addr = COLOUR_ALIGN(addr, pgoff);
4356@@ -147,15 +151,14 @@ unsigned long arch_get_unmapped_area(str
4357 addr = PAGE_ALIGN(addr);
4358
4359 vma = find_vma(mm, addr);
4360- if (task_size - len >= addr &&
4361- (!vma || addr + len <= vma->vm_start))
4362+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4363 return addr;
4364 }
4365
4366 if (len > mm->cached_hole_size) {
4367- start_addr = addr = mm->free_area_cache;
4368+ start_addr = addr = mm->free_area_cache;
4369 } else {
4370- start_addr = addr = TASK_UNMAPPED_BASE;
4371+ start_addr = addr = mm->mmap_base;
4372 mm->cached_hole_size = 0;
4373 }
4374
4375@@ -175,14 +178,14 @@ full_search:
4376 vma = find_vma(mm, VA_EXCLUDE_END);
4377 }
4378 if (unlikely(task_size < addr)) {
4379- if (start_addr != TASK_UNMAPPED_BASE) {
4380- start_addr = addr = TASK_UNMAPPED_BASE;
4381+ if (start_addr != mm->mmap_base) {
4382+ start_addr = addr = mm->mmap_base;
4383 mm->cached_hole_size = 0;
4384 goto full_search;
4385 }
4386 return -ENOMEM;
4387 }
4388- if (likely(!vma || addr + len <= vma->vm_start)) {
4389+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4390 /*
4391 * Remember the place where we stopped the search:
4392 */
4393@@ -216,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
4394 /* We do not accept a shared mapping if it would violate
4395 * cache aliasing constraints.
4396 */
4397- if ((flags & MAP_SHARED) &&
4398+ if ((filp || (flags & MAP_SHARED)) &&
4399 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4400 return -EINVAL;
4401 return addr;
4402@@ -237,8 +240,7 @@ arch_get_unmapped_area_topdown(struct fi
4403 addr = PAGE_ALIGN(addr);
4404
4405 vma = find_vma(mm, addr);
4406- if (task_size - len >= addr &&
4407- (!vma || addr + len <= vma->vm_start))
4408+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4409 return addr;
4410 }
4411
4412@@ -259,7 +261,7 @@ arch_get_unmapped_area_topdown(struct fi
4413 /* make sure it can fit in the remaining address space */
4414 if (likely(addr > len)) {
4415 vma = find_vma(mm, addr-len);
4416- if (!vma || addr <= vma->vm_start) {
4417+ if (check_heap_stack_gap(vma, addr - len, len)) {
4418 /* remember the address as a hint for next time */
4419 return (mm->free_area_cache = addr-len);
4420 }
4421@@ -268,18 +270,18 @@ arch_get_unmapped_area_topdown(struct fi
4422 if (unlikely(mm->mmap_base < len))
4423 goto bottomup;
4424
4425- addr = mm->mmap_base-len;
4426- if (do_color_align)
4427- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4428+ addr = mm->mmap_base - len;
4429
4430 do {
4431+ if (do_color_align)
4432+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4433 /*
4434 * Lookup failure means no vma is above this address,
4435 * else if new region fits below vma->vm_start,
4436 * return with success:
4437 */
4438 vma = find_vma(mm, addr);
4439- if (likely(!vma || addr+len <= vma->vm_start)) {
4440+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4441 /* remember the address as a hint for next time */
4442 return (mm->free_area_cache = addr);
4443 }
4444@@ -289,10 +291,8 @@ arch_get_unmapped_area_topdown(struct fi
4445 mm->cached_hole_size = vma->vm_start - addr;
4446
4447 /* try just below the current vma->vm_start */
4448- addr = vma->vm_start-len;
4449- if (do_color_align)
4450- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4451- } while (likely(len < vma->vm_start));
4452+ addr = skip_heap_stack_gap(vma, len);
4453+ } while (!IS_ERR_VALUE(addr));
4454
4455 bottomup:
4456 /*
4457@@ -384,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_str
4458 current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
4459 sysctl_legacy_va_layout) {
4460 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4461+
4462+#ifdef CONFIG_PAX_RANDMMAP
4463+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4464+ mm->mmap_base += mm->delta_mmap;
4465+#endif
4466+
4467 mm->get_unmapped_area = arch_get_unmapped_area;
4468 mm->unmap_area = arch_unmap_area;
4469 } else {
4470@@ -398,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_str
4471 gap = (task_size / 6 * 5);
4472
4473 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4474+
4475+#ifdef CONFIG_PAX_RANDMMAP
4476+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4477+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4478+#endif
4479+
4480 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4481 mm->unmap_area = arch_unmap_area_topdown;
4482 }
4483diff -urNp linux-2.6.32.44/arch/sparc/kernel/traps_32.c linux-2.6.32.44/arch/sparc/kernel/traps_32.c
4484--- linux-2.6.32.44/arch/sparc/kernel/traps_32.c 2011-03-27 14:31:47.000000000 -0400
4485+++ linux-2.6.32.44/arch/sparc/kernel/traps_32.c 2011-06-13 21:25:39.000000000 -0400
4486@@ -44,6 +44,8 @@ static void instruction_dump(unsigned lo
4487 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
4488 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
4489
4490+extern void gr_handle_kernel_exploit(void);
4491+
4492 void die_if_kernel(char *str, struct pt_regs *regs)
4493 {
4494 static int die_counter;
4495@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_
4496 count++ < 30 &&
4497 (((unsigned long) rw) >= PAGE_OFFSET) &&
4498 !(((unsigned long) rw) & 0x7)) {
4499- printk("Caller[%08lx]: %pS\n", rw->ins[7],
4500+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
4501 (void *) rw->ins[7]);
4502 rw = (struct reg_window32 *)rw->ins[6];
4503 }
4504 }
4505 printk("Instruction DUMP:");
4506 instruction_dump ((unsigned long *) regs->pc);
4507- if(regs->psr & PSR_PS)
4508+ if(regs->psr & PSR_PS) {
4509+ gr_handle_kernel_exploit();
4510 do_exit(SIGKILL);
4511+ }
4512 do_exit(SIGSEGV);
4513 }
4514
4515diff -urNp linux-2.6.32.44/arch/sparc/kernel/traps_64.c linux-2.6.32.44/arch/sparc/kernel/traps_64.c
4516--- linux-2.6.32.44/arch/sparc/kernel/traps_64.c 2011-03-27 14:31:47.000000000 -0400
4517+++ linux-2.6.32.44/arch/sparc/kernel/traps_64.c 2011-06-13 21:24:11.000000000 -0400
4518@@ -73,7 +73,7 @@ static void dump_tl1_traplog(struct tl1_
4519 i + 1,
4520 p->trapstack[i].tstate, p->trapstack[i].tpc,
4521 p->trapstack[i].tnpc, p->trapstack[i].tt);
4522- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4523+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4524 }
4525 }
4526
4527@@ -93,6 +93,12 @@ void bad_trap(struct pt_regs *regs, long
4528
4529 lvl -= 0x100;
4530 if (regs->tstate & TSTATE_PRIV) {
4531+
4532+#ifdef CONFIG_PAX_REFCOUNT
4533+ if (lvl == 6)
4534+ pax_report_refcount_overflow(regs);
4535+#endif
4536+
4537 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4538 die_if_kernel(buffer, regs);
4539 }
4540@@ -111,11 +117,16 @@ void bad_trap(struct pt_regs *regs, long
4541 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4542 {
4543 char buffer[32];
4544-
4545+
4546 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4547 0, lvl, SIGTRAP) == NOTIFY_STOP)
4548 return;
4549
4550+#ifdef CONFIG_PAX_REFCOUNT
4551+ if (lvl == 6)
4552+ pax_report_refcount_overflow(regs);
4553+#endif
4554+
4555 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4556
4557 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4558@@ -1139,7 +1150,7 @@ static void cheetah_log_errors(struct pt
4559 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4560 printk("%s" "ERROR(%d): ",
4561 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4562- printk("TPC<%pS>\n", (void *) regs->tpc);
4563+ printk("TPC<%pA>\n", (void *) regs->tpc);
4564 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4565 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4566 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4567@@ -1746,7 +1757,7 @@ void cheetah_plus_parity_error(int type,
4568 smp_processor_id(),
4569 (type & 0x1) ? 'I' : 'D',
4570 regs->tpc);
4571- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4572+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4573 panic("Irrecoverable Cheetah+ parity error.");
4574 }
4575
4576@@ -1754,7 +1765,7 @@ void cheetah_plus_parity_error(int type,
4577 smp_processor_id(),
4578 (type & 0x1) ? 'I' : 'D',
4579 regs->tpc);
4580- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4581+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4582 }
4583
4584 struct sun4v_error_entry {
4585@@ -1961,9 +1972,9 @@ void sun4v_itlb_error_report(struct pt_r
4586
4587 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4588 regs->tpc, tl);
4589- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4590+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4591 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4592- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4593+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4594 (void *) regs->u_regs[UREG_I7]);
4595 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4596 "pte[%lx] error[%lx]\n",
4597@@ -1985,9 +1996,9 @@ void sun4v_dtlb_error_report(struct pt_r
4598
4599 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4600 regs->tpc, tl);
4601- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4602+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4603 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4604- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4605+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4606 (void *) regs->u_regs[UREG_I7]);
4607 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4608 "pte[%lx] error[%lx]\n",
4609@@ -2191,7 +2202,7 @@ void show_stack(struct task_struct *tsk,
4610 fp = (unsigned long)sf->fp + STACK_BIAS;
4611 }
4612
4613- printk(" [%016lx] %pS\n", pc, (void *) pc);
4614+ printk(" [%016lx] %pA\n", pc, (void *) pc);
4615 } while (++count < 16);
4616 }
4617
4618@@ -2233,6 +2244,8 @@ static inline struct reg_window *kernel_
4619 return (struct reg_window *) (fp + STACK_BIAS);
4620 }
4621
4622+extern void gr_handle_kernel_exploit(void);
4623+
4624 void die_if_kernel(char *str, struct pt_regs *regs)
4625 {
4626 static int die_counter;
4627@@ -2260,7 +2273,7 @@ void die_if_kernel(char *str, struct pt_
4628 while (rw &&
4629 count++ < 30&&
4630 is_kernel_stack(current, rw)) {
4631- printk("Caller[%016lx]: %pS\n", rw->ins[7],
4632+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
4633 (void *) rw->ins[7]);
4634
4635 rw = kernel_stack_up(rw);
4636@@ -2273,8 +2286,11 @@ void die_if_kernel(char *str, struct pt_
4637 }
4638 user_instruction_dump ((unsigned int __user *) regs->tpc);
4639 }
4640- if (regs->tstate & TSTATE_PRIV)
4641+ if (regs->tstate & TSTATE_PRIV) {
4642+ gr_handle_kernel_exploit();
4643 do_exit(SIGKILL);
4644+ }
4645+
4646 do_exit(SIGSEGV);
4647 }
4648 EXPORT_SYMBOL(die_if_kernel);
4649diff -urNp linux-2.6.32.44/arch/sparc/kernel/una_asm_64.S linux-2.6.32.44/arch/sparc/kernel/una_asm_64.S
4650--- linux-2.6.32.44/arch/sparc/kernel/una_asm_64.S 2011-03-27 14:31:47.000000000 -0400
4651+++ linux-2.6.32.44/arch/sparc/kernel/una_asm_64.S 2011-07-13 22:20:05.000000000 -0400
4652@@ -127,7 +127,7 @@ do_int_load:
4653 wr %o5, 0x0, %asi
4654 retl
4655 mov 0, %o0
4656- .size __do_int_load, .-__do_int_load
4657+ .size do_int_load, .-do_int_load
4658
4659 .section __ex_table,"a"
4660 .word 4b, __retl_efault
4661diff -urNp linux-2.6.32.44/arch/sparc/kernel/unaligned_64.c linux-2.6.32.44/arch/sparc/kernel/unaligned_64.c
4662--- linux-2.6.32.44/arch/sparc/kernel/unaligned_64.c 2011-03-27 14:31:47.000000000 -0400
4663+++ linux-2.6.32.44/arch/sparc/kernel/unaligned_64.c 2011-04-17 15:56:46.000000000 -0400
4664@@ -288,7 +288,7 @@ static void log_unaligned(struct pt_regs
4665 if (count < 5) {
4666 last_time = jiffies;
4667 count++;
4668- printk("Kernel unaligned access at TPC[%lx] %pS\n",
4669+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
4670 regs->tpc, (void *) regs->tpc);
4671 }
4672 }
4673diff -urNp linux-2.6.32.44/arch/sparc/lib/atomic_64.S linux-2.6.32.44/arch/sparc/lib/atomic_64.S
4674--- linux-2.6.32.44/arch/sparc/lib/atomic_64.S 2011-03-27 14:31:47.000000000 -0400
4675+++ linux-2.6.32.44/arch/sparc/lib/atomic_64.S 2011-04-17 15:56:46.000000000 -0400
4676@@ -18,7 +18,12 @@
4677 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4678 BACKOFF_SETUP(%o2)
4679 1: lduw [%o1], %g1
4680- add %g1, %o0, %g7
4681+ addcc %g1, %o0, %g7
4682+
4683+#ifdef CONFIG_PAX_REFCOUNT
4684+ tvs %icc, 6
4685+#endif
4686+
4687 cas [%o1], %g1, %g7
4688 cmp %g1, %g7
4689 bne,pn %icc, 2f
4690@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
4691 2: BACKOFF_SPIN(%o2, %o3, 1b)
4692 .size atomic_add, .-atomic_add
4693
4694+ .globl atomic_add_unchecked
4695+ .type atomic_add_unchecked,#function
4696+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4697+ BACKOFF_SETUP(%o2)
4698+1: lduw [%o1], %g1
4699+ add %g1, %o0, %g7
4700+ cas [%o1], %g1, %g7
4701+ cmp %g1, %g7
4702+ bne,pn %icc, 2f
4703+ nop
4704+ retl
4705+ nop
4706+2: BACKOFF_SPIN(%o2, %o3, 1b)
4707+ .size atomic_add_unchecked, .-atomic_add_unchecked
4708+
4709 .globl atomic_sub
4710 .type atomic_sub,#function
4711 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4712 BACKOFF_SETUP(%o2)
4713 1: lduw [%o1], %g1
4714- sub %g1, %o0, %g7
4715+ subcc %g1, %o0, %g7
4716+
4717+#ifdef CONFIG_PAX_REFCOUNT
4718+ tvs %icc, 6
4719+#endif
4720+
4721 cas [%o1], %g1, %g7
4722 cmp %g1, %g7
4723 bne,pn %icc, 2f
4724@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
4725 2: BACKOFF_SPIN(%o2, %o3, 1b)
4726 .size atomic_sub, .-atomic_sub
4727
4728+ .globl atomic_sub_unchecked
4729+ .type atomic_sub_unchecked,#function
4730+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4731+ BACKOFF_SETUP(%o2)
4732+1: lduw [%o1], %g1
4733+ sub %g1, %o0, %g7
4734+ cas [%o1], %g1, %g7
4735+ cmp %g1, %g7
4736+ bne,pn %icc, 2f
4737+ nop
4738+ retl
4739+ nop
4740+2: BACKOFF_SPIN(%o2, %o3, 1b)
4741+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
4742+
4743 .globl atomic_add_ret
4744 .type atomic_add_ret,#function
4745 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4746 BACKOFF_SETUP(%o2)
4747 1: lduw [%o1], %g1
4748- add %g1, %o0, %g7
4749+ addcc %g1, %o0, %g7
4750+
4751+#ifdef CONFIG_PAX_REFCOUNT
4752+ tvs %icc, 6
4753+#endif
4754+
4755 cas [%o1], %g1, %g7
4756 cmp %g1, %g7
4757 bne,pn %icc, 2f
4758@@ -59,12 +104,33 @@ atomic_add_ret: /* %o0 = increment, %o1
4759 2: BACKOFF_SPIN(%o2, %o3, 1b)
4760 .size atomic_add_ret, .-atomic_add_ret
4761
4762+ .globl atomic_add_ret_unchecked
4763+ .type atomic_add_ret_unchecked,#function
4764+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4765+ BACKOFF_SETUP(%o2)
4766+1: lduw [%o1], %g1
4767+ addcc %g1, %o0, %g7
4768+ cas [%o1], %g1, %g7
4769+ cmp %g1, %g7
4770+ bne,pn %icc, 2f
4771+ add %g7, %o0, %g7
4772+ sra %g7, 0, %o0
4773+ retl
4774+ nop
4775+2: BACKOFF_SPIN(%o2, %o3, 1b)
4776+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4777+
4778 .globl atomic_sub_ret
4779 .type atomic_sub_ret,#function
4780 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4781 BACKOFF_SETUP(%o2)
4782 1: lduw [%o1], %g1
4783- sub %g1, %o0, %g7
4784+ subcc %g1, %o0, %g7
4785+
4786+#ifdef CONFIG_PAX_REFCOUNT
4787+ tvs %icc, 6
4788+#endif
4789+
4790 cas [%o1], %g1, %g7
4791 cmp %g1, %g7
4792 bne,pn %icc, 2f
4793@@ -80,7 +146,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
4794 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4795 BACKOFF_SETUP(%o2)
4796 1: ldx [%o1], %g1
4797- add %g1, %o0, %g7
4798+ addcc %g1, %o0, %g7
4799+
4800+#ifdef CONFIG_PAX_REFCOUNT
4801+ tvs %xcc, 6
4802+#endif
4803+
4804 casx [%o1], %g1, %g7
4805 cmp %g1, %g7
4806 bne,pn %xcc, 2f
4807@@ -90,12 +161,32 @@ atomic64_add: /* %o0 = increment, %o1 =
4808 2: BACKOFF_SPIN(%o2, %o3, 1b)
4809 .size atomic64_add, .-atomic64_add
4810
4811+ .globl atomic64_add_unchecked
4812+ .type atomic64_add_unchecked,#function
4813+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4814+ BACKOFF_SETUP(%o2)
4815+1: ldx [%o1], %g1
4816+ addcc %g1, %o0, %g7
4817+ casx [%o1], %g1, %g7
4818+ cmp %g1, %g7
4819+ bne,pn %xcc, 2f
4820+ nop
4821+ retl
4822+ nop
4823+2: BACKOFF_SPIN(%o2, %o3, 1b)
4824+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
4825+
4826 .globl atomic64_sub
4827 .type atomic64_sub,#function
4828 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4829 BACKOFF_SETUP(%o2)
4830 1: ldx [%o1], %g1
4831- sub %g1, %o0, %g7
4832+ subcc %g1, %o0, %g7
4833+
4834+#ifdef CONFIG_PAX_REFCOUNT
4835+ tvs %xcc, 6
4836+#endif
4837+
4838 casx [%o1], %g1, %g7
4839 cmp %g1, %g7
4840 bne,pn %xcc, 2f
4841@@ -105,12 +196,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
4842 2: BACKOFF_SPIN(%o2, %o3, 1b)
4843 .size atomic64_sub, .-atomic64_sub
4844
4845+ .globl atomic64_sub_unchecked
4846+ .type atomic64_sub_unchecked,#function
4847+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4848+ BACKOFF_SETUP(%o2)
4849+1: ldx [%o1], %g1
4850+ subcc %g1, %o0, %g7
4851+ casx [%o1], %g1, %g7
4852+ cmp %g1, %g7
4853+ bne,pn %xcc, 2f
4854+ nop
4855+ retl
4856+ nop
4857+2: BACKOFF_SPIN(%o2, %o3, 1b)
4858+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4859+
4860 .globl atomic64_add_ret
4861 .type atomic64_add_ret,#function
4862 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4863 BACKOFF_SETUP(%o2)
4864 1: ldx [%o1], %g1
4865- add %g1, %o0, %g7
4866+ addcc %g1, %o0, %g7
4867+
4868+#ifdef CONFIG_PAX_REFCOUNT
4869+ tvs %xcc, 6
4870+#endif
4871+
4872 casx [%o1], %g1, %g7
4873 cmp %g1, %g7
4874 bne,pn %xcc, 2f
4875@@ -121,12 +232,33 @@ atomic64_add_ret: /* %o0 = increment, %o
4876 2: BACKOFF_SPIN(%o2, %o3, 1b)
4877 .size atomic64_add_ret, .-atomic64_add_ret
4878
4879+ .globl atomic64_add_ret_unchecked
4880+ .type atomic64_add_ret_unchecked,#function
4881+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4882+ BACKOFF_SETUP(%o2)
4883+1: ldx [%o1], %g1
4884+ addcc %g1, %o0, %g7
4885+ casx [%o1], %g1, %g7
4886+ cmp %g1, %g7
4887+ bne,pn %xcc, 2f
4888+ add %g7, %o0, %g7
4889+ mov %g7, %o0
4890+ retl
4891+ nop
4892+2: BACKOFF_SPIN(%o2, %o3, 1b)
4893+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4894+
4895 .globl atomic64_sub_ret
4896 .type atomic64_sub_ret,#function
4897 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4898 BACKOFF_SETUP(%o2)
4899 1: ldx [%o1], %g1
4900- sub %g1, %o0, %g7
4901+ subcc %g1, %o0, %g7
4902+
4903+#ifdef CONFIG_PAX_REFCOUNT
4904+ tvs %xcc, 6
4905+#endif
4906+
4907 casx [%o1], %g1, %g7
4908 cmp %g1, %g7
4909 bne,pn %xcc, 2f
4910diff -urNp linux-2.6.32.44/arch/sparc/lib/ksyms.c linux-2.6.32.44/arch/sparc/lib/ksyms.c
4911--- linux-2.6.32.44/arch/sparc/lib/ksyms.c 2011-03-27 14:31:47.000000000 -0400
4912+++ linux-2.6.32.44/arch/sparc/lib/ksyms.c 2011-04-17 15:56:46.000000000 -0400
4913@@ -144,12 +144,17 @@ EXPORT_SYMBOL(__downgrade_write);
4914
4915 /* Atomic counter implementation. */
4916 EXPORT_SYMBOL(atomic_add);
4917+EXPORT_SYMBOL(atomic_add_unchecked);
4918 EXPORT_SYMBOL(atomic_add_ret);
4919 EXPORT_SYMBOL(atomic_sub);
4920+EXPORT_SYMBOL(atomic_sub_unchecked);
4921 EXPORT_SYMBOL(atomic_sub_ret);
4922 EXPORT_SYMBOL(atomic64_add);
4923+EXPORT_SYMBOL(atomic64_add_unchecked);
4924 EXPORT_SYMBOL(atomic64_add_ret);
4925+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4926 EXPORT_SYMBOL(atomic64_sub);
4927+EXPORT_SYMBOL(atomic64_sub_unchecked);
4928 EXPORT_SYMBOL(atomic64_sub_ret);
4929
4930 /* Atomic bit operations. */
4931diff -urNp linux-2.6.32.44/arch/sparc/lib/Makefile linux-2.6.32.44/arch/sparc/lib/Makefile
4932--- linux-2.6.32.44/arch/sparc/lib/Makefile 2011-03-27 14:31:47.000000000 -0400
4933+++ linux-2.6.32.44/arch/sparc/lib/Makefile 2011-05-17 19:26:34.000000000 -0400
4934@@ -2,7 +2,7 @@
4935 #
4936
4937 asflags-y := -ansi -DST_DIV0=0x02
4938-ccflags-y := -Werror
4939+#ccflags-y := -Werror
4940
4941 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4942 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4943diff -urNp linux-2.6.32.44/arch/sparc/lib/rwsem_64.S linux-2.6.32.44/arch/sparc/lib/rwsem_64.S
4944--- linux-2.6.32.44/arch/sparc/lib/rwsem_64.S 2011-03-27 14:31:47.000000000 -0400
4945+++ linux-2.6.32.44/arch/sparc/lib/rwsem_64.S 2011-04-17 15:56:46.000000000 -0400
4946@@ -11,7 +11,12 @@
4947 .globl __down_read
4948 __down_read:
4949 1: lduw [%o0], %g1
4950- add %g1, 1, %g7
4951+ addcc %g1, 1, %g7
4952+
4953+#ifdef CONFIG_PAX_REFCOUNT
4954+ tvs %icc, 6
4955+#endif
4956+
4957 cas [%o0], %g1, %g7
4958 cmp %g1, %g7
4959 bne,pn %icc, 1b
4960@@ -33,7 +38,12 @@ __down_read:
4961 .globl __down_read_trylock
4962 __down_read_trylock:
4963 1: lduw [%o0], %g1
4964- add %g1, 1, %g7
4965+ addcc %g1, 1, %g7
4966+
4967+#ifdef CONFIG_PAX_REFCOUNT
4968+ tvs %icc, 6
4969+#endif
4970+
4971 cmp %g7, 0
4972 bl,pn %icc, 2f
4973 mov 0, %o1
4974@@ -51,7 +61,12 @@ __down_write:
4975 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
4976 1:
4977 lduw [%o0], %g3
4978- add %g3, %g1, %g7
4979+ addcc %g3, %g1, %g7
4980+
4981+#ifdef CONFIG_PAX_REFCOUNT
4982+ tvs %icc, 6
4983+#endif
4984+
4985 cas [%o0], %g3, %g7
4986 cmp %g3, %g7
4987 bne,pn %icc, 1b
4988@@ -77,7 +92,12 @@ __down_write_trylock:
4989 cmp %g3, 0
4990 bne,pn %icc, 2f
4991 mov 0, %o1
4992- add %g3, %g1, %g7
4993+ addcc %g3, %g1, %g7
4994+
4995+#ifdef CONFIG_PAX_REFCOUNT
4996+ tvs %icc, 6
4997+#endif
4998+
4999 cas [%o0], %g3, %g7
5000 cmp %g3, %g7
5001 bne,pn %icc, 1b
5002@@ -90,7 +110,12 @@ __down_write_trylock:
5003 __up_read:
5004 1:
5005 lduw [%o0], %g1
5006- sub %g1, 1, %g7
5007+ subcc %g1, 1, %g7
5008+
5009+#ifdef CONFIG_PAX_REFCOUNT
5010+ tvs %icc, 6
5011+#endif
5012+
5013 cas [%o0], %g1, %g7
5014 cmp %g1, %g7
5015 bne,pn %icc, 1b
5016@@ -118,7 +143,12 @@ __up_write:
5017 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5018 1:
5019 lduw [%o0], %g3
5020- sub %g3, %g1, %g7
5021+ subcc %g3, %g1, %g7
5022+
5023+#ifdef CONFIG_PAX_REFCOUNT
5024+ tvs %icc, 6
5025+#endif
5026+
5027 cas [%o0], %g3, %g7
5028 cmp %g3, %g7
5029 bne,pn %icc, 1b
5030@@ -143,7 +173,12 @@ __downgrade_write:
5031 or %g1, %lo(RWSEM_WAITING_BIAS), %g1
5032 1:
5033 lduw [%o0], %g3
5034- sub %g3, %g1, %g7
5035+ subcc %g3, %g1, %g7
5036+
5037+#ifdef CONFIG_PAX_REFCOUNT
5038+ tvs %icc, 6
5039+#endif
5040+
5041 cas [%o0], %g3, %g7
5042 cmp %g3, %g7
5043 bne,pn %icc, 1b
5044diff -urNp linux-2.6.32.44/arch/sparc/Makefile linux-2.6.32.44/arch/sparc/Makefile
5045--- linux-2.6.32.44/arch/sparc/Makefile 2011-03-27 14:31:47.000000000 -0400
5046+++ linux-2.6.32.44/arch/sparc/Makefile 2011-04-17 15:56:46.000000000 -0400
5047@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
5048 # Export what is needed by arch/sparc/boot/Makefile
5049 export VMLINUX_INIT VMLINUX_MAIN
5050 VMLINUX_INIT := $(head-y) $(init-y)
5051-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5052+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5053 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5054 VMLINUX_MAIN += $(drivers-y) $(net-y)
5055
5056diff -urNp linux-2.6.32.44/arch/sparc/mm/fault_32.c linux-2.6.32.44/arch/sparc/mm/fault_32.c
5057--- linux-2.6.32.44/arch/sparc/mm/fault_32.c 2011-03-27 14:31:47.000000000 -0400
5058+++ linux-2.6.32.44/arch/sparc/mm/fault_32.c 2011-04-17 15:56:46.000000000 -0400
5059@@ -21,6 +21,9 @@
5060 #include <linux/interrupt.h>
5061 #include <linux/module.h>
5062 #include <linux/kdebug.h>
5063+#include <linux/slab.h>
5064+#include <linux/pagemap.h>
5065+#include <linux/compiler.h>
5066
5067 #include <asm/system.h>
5068 #include <asm/page.h>
5069@@ -167,6 +170,267 @@ static unsigned long compute_si_addr(str
5070 return safe_compute_effective_address(regs, insn);
5071 }
5072
5073+#ifdef CONFIG_PAX_PAGEEXEC
5074+#ifdef CONFIG_PAX_DLRESOLVE
5075+static void pax_emuplt_close(struct vm_area_struct *vma)
5076+{
5077+ vma->vm_mm->call_dl_resolve = 0UL;
5078+}
5079+
5080+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5081+{
5082+ unsigned int *kaddr;
5083+
5084+ vmf->page = alloc_page(GFP_HIGHUSER);
5085+ if (!vmf->page)
5086+ return VM_FAULT_OOM;
5087+
5088+ kaddr = kmap(vmf->page);
5089+ memset(kaddr, 0, PAGE_SIZE);
5090+ kaddr[0] = 0x9DE3BFA8U; /* save */
5091+ flush_dcache_page(vmf->page);
5092+ kunmap(vmf->page);
5093+ return VM_FAULT_MAJOR;
5094+}
5095+
5096+static const struct vm_operations_struct pax_vm_ops = {
5097+ .close = pax_emuplt_close,
5098+ .fault = pax_emuplt_fault
5099+};
5100+
5101+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5102+{
5103+ int ret;
5104+
5105+ vma->vm_mm = current->mm;
5106+ vma->vm_start = addr;
5107+ vma->vm_end = addr + PAGE_SIZE;
5108+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5109+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5110+ vma->vm_ops = &pax_vm_ops;
5111+
5112+ ret = insert_vm_struct(current->mm, vma);
5113+ if (ret)
5114+ return ret;
5115+
5116+ ++current->mm->total_vm;
5117+ return 0;
5118+}
5119+#endif
5120+
5121+/*
5122+ * PaX: decide what to do with offenders (regs->pc = fault address)
5123+ *
5124+ * returns 1 when task should be killed
5125+ * 2 when patched PLT trampoline was detected
5126+ * 3 when unpatched PLT trampoline was detected
5127+ */
5128+static int pax_handle_fetch_fault(struct pt_regs *regs)
5129+{
5130+
5131+#ifdef CONFIG_PAX_EMUPLT
5132+ int err;
5133+
5134+ do { /* PaX: patched PLT emulation #1 */
5135+ unsigned int sethi1, sethi2, jmpl;
5136+
5137+ err = get_user(sethi1, (unsigned int *)regs->pc);
5138+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5139+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5140+
5141+ if (err)
5142+ break;
5143+
5144+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5145+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
5146+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
5147+ {
5148+ unsigned int addr;
5149+
5150+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5151+ addr = regs->u_regs[UREG_G1];
5152+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5153+ regs->pc = addr;
5154+ regs->npc = addr+4;
5155+ return 2;
5156+ }
5157+ } while (0);
5158+
5159+ { /* PaX: patched PLT emulation #2 */
5160+ unsigned int ba;
5161+
5162+ err = get_user(ba, (unsigned int *)regs->pc);
5163+
5164+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5165+ unsigned int addr;
5166+
5167+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5168+ regs->pc = addr;
5169+ regs->npc = addr+4;
5170+ return 2;
5171+ }
5172+ }
5173+
5174+ do { /* PaX: patched PLT emulation #3 */
5175+ unsigned int sethi, jmpl, nop;
5176+
5177+ err = get_user(sethi, (unsigned int *)regs->pc);
5178+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5179+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
5180+
5181+ if (err)
5182+ break;
5183+
5184+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5185+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5186+ nop == 0x01000000U)
5187+ {
5188+ unsigned int addr;
5189+
5190+ addr = (sethi & 0x003FFFFFU) << 10;
5191+ regs->u_regs[UREG_G1] = addr;
5192+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5193+ regs->pc = addr;
5194+ regs->npc = addr+4;
5195+ return 2;
5196+ }
5197+ } while (0);
5198+
5199+ do { /* PaX: unpatched PLT emulation step 1 */
5200+ unsigned int sethi, ba, nop;
5201+
5202+ err = get_user(sethi, (unsigned int *)regs->pc);
5203+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
5204+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
5205+
5206+ if (err)
5207+ break;
5208+
5209+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5210+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5211+ nop == 0x01000000U)
5212+ {
5213+ unsigned int addr, save, call;
5214+
5215+ if ((ba & 0xFFC00000U) == 0x30800000U)
5216+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5217+ else
5218+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5219+
5220+ err = get_user(save, (unsigned int *)addr);
5221+ err |= get_user(call, (unsigned int *)(addr+4));
5222+ err |= get_user(nop, (unsigned int *)(addr+8));
5223+ if (err)
5224+ break;
5225+
5226+#ifdef CONFIG_PAX_DLRESOLVE
5227+ if (save == 0x9DE3BFA8U &&
5228+ (call & 0xC0000000U) == 0x40000000U &&
5229+ nop == 0x01000000U)
5230+ {
5231+ struct vm_area_struct *vma;
5232+ unsigned long call_dl_resolve;
5233+
5234+ down_read(&current->mm->mmap_sem);
5235+ call_dl_resolve = current->mm->call_dl_resolve;
5236+ up_read(&current->mm->mmap_sem);
5237+ if (likely(call_dl_resolve))
5238+ goto emulate;
5239+
5240+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5241+
5242+ down_write(&current->mm->mmap_sem);
5243+ if (current->mm->call_dl_resolve) {
5244+ call_dl_resolve = current->mm->call_dl_resolve;
5245+ up_write(&current->mm->mmap_sem);
5246+ if (vma)
5247+ kmem_cache_free(vm_area_cachep, vma);
5248+ goto emulate;
5249+ }
5250+
5251+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5252+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5253+ up_write(&current->mm->mmap_sem);
5254+ if (vma)
5255+ kmem_cache_free(vm_area_cachep, vma);
5256+ return 1;
5257+ }
5258+
5259+ if (pax_insert_vma(vma, call_dl_resolve)) {
5260+ up_write(&current->mm->mmap_sem);
5261+ kmem_cache_free(vm_area_cachep, vma);
5262+ return 1;
5263+ }
5264+
5265+ current->mm->call_dl_resolve = call_dl_resolve;
5266+ up_write(&current->mm->mmap_sem);
5267+
5268+emulate:
5269+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5270+ regs->pc = call_dl_resolve;
5271+ regs->npc = addr+4;
5272+ return 3;
5273+ }
5274+#endif
5275+
5276+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5277+ if ((save & 0xFFC00000U) == 0x05000000U &&
5278+ (call & 0xFFFFE000U) == 0x85C0A000U &&
5279+ nop == 0x01000000U)
5280+ {
5281+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5282+ regs->u_regs[UREG_G2] = addr + 4;
5283+ addr = (save & 0x003FFFFFU) << 10;
5284+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5285+ regs->pc = addr;
5286+ regs->npc = addr+4;
5287+ return 3;
5288+ }
5289+ }
5290+ } while (0);
5291+
5292+ do { /* PaX: unpatched PLT emulation step 2 */
5293+ unsigned int save, call, nop;
5294+
5295+ err = get_user(save, (unsigned int *)(regs->pc-4));
5296+ err |= get_user(call, (unsigned int *)regs->pc);
5297+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
5298+ if (err)
5299+ break;
5300+
5301+ if (save == 0x9DE3BFA8U &&
5302+ (call & 0xC0000000U) == 0x40000000U &&
5303+ nop == 0x01000000U)
5304+ {
5305+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5306+
5307+ regs->u_regs[UREG_RETPC] = regs->pc;
5308+ regs->pc = dl_resolve;
5309+ regs->npc = dl_resolve+4;
5310+ return 3;
5311+ }
5312+ } while (0);
5313+#endif
5314+
5315+ return 1;
5316+}
5317+
5318+void pax_report_insns(void *pc, void *sp)
5319+{
5320+ unsigned long i;
5321+
5322+ printk(KERN_ERR "PAX: bytes at PC: ");
5323+ for (i = 0; i < 8; i++) {
5324+ unsigned int c;
5325+ if (get_user(c, (unsigned int *)pc+i))
5326+ printk(KERN_CONT "???????? ");
5327+ else
5328+ printk(KERN_CONT "%08x ", c);
5329+ }
5330+ printk("\n");
5331+}
5332+#endif
5333+
5334 asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
5335 unsigned long address)
5336 {
5337@@ -231,6 +495,24 @@ good_area:
5338 if(!(vma->vm_flags & VM_WRITE))
5339 goto bad_area;
5340 } else {
5341+
5342+#ifdef CONFIG_PAX_PAGEEXEC
5343+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5344+ up_read(&mm->mmap_sem);
5345+ switch (pax_handle_fetch_fault(regs)) {
5346+
5347+#ifdef CONFIG_PAX_EMUPLT
5348+ case 2:
5349+ case 3:
5350+ return;
5351+#endif
5352+
5353+ }
5354+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5355+ do_group_exit(SIGKILL);
5356+ }
5357+#endif
5358+
5359 /* Allow reads even for write-only mappings */
5360 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5361 goto bad_area;
5362diff -urNp linux-2.6.32.44/arch/sparc/mm/fault_64.c linux-2.6.32.44/arch/sparc/mm/fault_64.c
5363--- linux-2.6.32.44/arch/sparc/mm/fault_64.c 2011-03-27 14:31:47.000000000 -0400
5364+++ linux-2.6.32.44/arch/sparc/mm/fault_64.c 2011-04-17 15:56:46.000000000 -0400
5365@@ -20,6 +20,9 @@
5366 #include <linux/kprobes.h>
5367 #include <linux/kdebug.h>
5368 #include <linux/percpu.h>
5369+#include <linux/slab.h>
5370+#include <linux/pagemap.h>
5371+#include <linux/compiler.h>
5372
5373 #include <asm/page.h>
5374 #include <asm/pgtable.h>
5375@@ -78,7 +81,7 @@ static void bad_kernel_pc(struct pt_regs
5376 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5377 regs->tpc);
5378 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5379- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5380+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5381 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5382 dump_stack();
5383 unhandled_fault(regs->tpc, current, regs);
5384@@ -249,6 +252,456 @@ static void noinline bogus_32bit_fault_a
5385 show_regs(regs);
5386 }
5387
5388+#ifdef CONFIG_PAX_PAGEEXEC
5389+#ifdef CONFIG_PAX_DLRESOLVE
5390+static void pax_emuplt_close(struct vm_area_struct *vma)
5391+{
5392+ vma->vm_mm->call_dl_resolve = 0UL;
5393+}
5394+
5395+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5396+{
5397+ unsigned int *kaddr;
5398+
5399+ vmf->page = alloc_page(GFP_HIGHUSER);
5400+ if (!vmf->page)
5401+ return VM_FAULT_OOM;
5402+
5403+ kaddr = kmap(vmf->page);
5404+ memset(kaddr, 0, PAGE_SIZE);
5405+ kaddr[0] = 0x9DE3BFA8U; /* save */
5406+ flush_dcache_page(vmf->page);
5407+ kunmap(vmf->page);
5408+ return VM_FAULT_MAJOR;
5409+}
5410+
5411+static const struct vm_operations_struct pax_vm_ops = {
5412+ .close = pax_emuplt_close,
5413+ .fault = pax_emuplt_fault
5414+};
5415+
5416+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5417+{
5418+ int ret;
5419+
5420+ vma->vm_mm = current->mm;
5421+ vma->vm_start = addr;
5422+ vma->vm_end = addr + PAGE_SIZE;
5423+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5424+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5425+ vma->vm_ops = &pax_vm_ops;
5426+
5427+ ret = insert_vm_struct(current->mm, vma);
5428+ if (ret)
5429+ return ret;
5430+
5431+ ++current->mm->total_vm;
5432+ return 0;
5433+}
5434+#endif
5435+
5436+/*
5437+ * PaX: decide what to do with offenders (regs->tpc = fault address)
5438+ *
5439+ * returns 1 when task should be killed
5440+ * 2 when patched PLT trampoline was detected
5441+ * 3 when unpatched PLT trampoline was detected
5442+ */
5443+static int pax_handle_fetch_fault(struct pt_regs *regs)
5444+{
5445+
5446+#ifdef CONFIG_PAX_EMUPLT
5447+ int err;
5448+
5449+ do { /* PaX: patched PLT emulation #1 */
5450+ unsigned int sethi1, sethi2, jmpl;
5451+
5452+ err = get_user(sethi1, (unsigned int *)regs->tpc);
5453+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5454+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5455+
5456+ if (err)
5457+ break;
5458+
5459+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5460+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
5461+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
5462+ {
5463+ unsigned long addr;
5464+
5465+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5466+ addr = regs->u_regs[UREG_G1];
5467+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5468+
5469+ if (test_thread_flag(TIF_32BIT))
5470+ addr &= 0xFFFFFFFFUL;
5471+
5472+ regs->tpc = addr;
5473+ regs->tnpc = addr+4;
5474+ return 2;
5475+ }
5476+ } while (0);
5477+
5478+ { /* PaX: patched PLT emulation #2 */
5479+ unsigned int ba;
5480+
5481+ err = get_user(ba, (unsigned int *)regs->tpc);
5482+
5483+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5484+ unsigned long addr;
5485+
5486+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5487+
5488+ if (test_thread_flag(TIF_32BIT))
5489+ addr &= 0xFFFFFFFFUL;
5490+
5491+ regs->tpc = addr;
5492+ regs->tnpc = addr+4;
5493+ return 2;
5494+ }
5495+ }
5496+
5497+ do { /* PaX: patched PLT emulation #3 */
5498+ unsigned int sethi, jmpl, nop;
5499+
5500+ err = get_user(sethi, (unsigned int *)regs->tpc);
5501+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5502+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5503+
5504+ if (err)
5505+ break;
5506+
5507+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5508+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5509+ nop == 0x01000000U)
5510+ {
5511+ unsigned long addr;
5512+
5513+ addr = (sethi & 0x003FFFFFU) << 10;
5514+ regs->u_regs[UREG_G1] = addr;
5515+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5516+
5517+ if (test_thread_flag(TIF_32BIT))
5518+ addr &= 0xFFFFFFFFUL;
5519+
5520+ regs->tpc = addr;
5521+ regs->tnpc = addr+4;
5522+ return 2;
5523+ }
5524+ } while (0);
5525+
5526+ do { /* PaX: patched PLT emulation #4 */
5527+ unsigned int sethi, mov1, call, mov2;
5528+
5529+ err = get_user(sethi, (unsigned int *)regs->tpc);
5530+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5531+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
5532+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5533+
5534+ if (err)
5535+ break;
5536+
5537+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5538+ mov1 == 0x8210000FU &&
5539+ (call & 0xC0000000U) == 0x40000000U &&
5540+ mov2 == 0x9E100001U)
5541+ {
5542+ unsigned long addr;
5543+
5544+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5545+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5546+
5547+ if (test_thread_flag(TIF_32BIT))
5548+ addr &= 0xFFFFFFFFUL;
5549+
5550+ regs->tpc = addr;
5551+ regs->tnpc = addr+4;
5552+ return 2;
5553+ }
5554+ } while (0);
5555+
5556+ do { /* PaX: patched PLT emulation #5 */
5557+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5558+
5559+ err = get_user(sethi, (unsigned int *)regs->tpc);
5560+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5561+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5562+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5563+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5564+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5565+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5566+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5567+
5568+ if (err)
5569+ break;
5570+
5571+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5572+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
5573+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5574+ (or1 & 0xFFFFE000U) == 0x82106000U &&
5575+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
5576+ sllx == 0x83287020U &&
5577+ jmpl == 0x81C04005U &&
5578+ nop == 0x01000000U)
5579+ {
5580+ unsigned long addr;
5581+
5582+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5583+ regs->u_regs[UREG_G1] <<= 32;
5584+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5585+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5586+ regs->tpc = addr;
5587+ regs->tnpc = addr+4;
5588+ return 2;
5589+ }
5590+ } while (0);
5591+
5592+ do { /* PaX: patched PLT emulation #6 */
5593+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5594+
5595+ err = get_user(sethi, (unsigned int *)regs->tpc);
5596+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5597+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5598+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5599+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
5600+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5601+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5602+
5603+ if (err)
5604+ break;
5605+
5606+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5607+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
5608+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5609+ sllx == 0x83287020U &&
5610+ (or & 0xFFFFE000U) == 0x8A116000U &&
5611+ jmpl == 0x81C04005U &&
5612+ nop == 0x01000000U)
5613+ {
5614+ unsigned long addr;
5615+
5616+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5617+ regs->u_regs[UREG_G1] <<= 32;
5618+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5619+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5620+ regs->tpc = addr;
5621+ regs->tnpc = addr+4;
5622+ return 2;
5623+ }
5624+ } while (0);
5625+
5626+ do { /* PaX: unpatched PLT emulation step 1 */
5627+ unsigned int sethi, ba, nop;
5628+
5629+ err = get_user(sethi, (unsigned int *)regs->tpc);
5630+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5631+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5632+
5633+ if (err)
5634+ break;
5635+
5636+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5637+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5638+ nop == 0x01000000U)
5639+ {
5640+ unsigned long addr;
5641+ unsigned int save, call;
5642+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5643+
5644+ if ((ba & 0xFFC00000U) == 0x30800000U)
5645+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5646+ else
5647+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5648+
5649+ if (test_thread_flag(TIF_32BIT))
5650+ addr &= 0xFFFFFFFFUL;
5651+
5652+ err = get_user(save, (unsigned int *)addr);
5653+ err |= get_user(call, (unsigned int *)(addr+4));
5654+ err |= get_user(nop, (unsigned int *)(addr+8));
5655+ if (err)
5656+ break;
5657+
5658+#ifdef CONFIG_PAX_DLRESOLVE
5659+ if (save == 0x9DE3BFA8U &&
5660+ (call & 0xC0000000U) == 0x40000000U &&
5661+ nop == 0x01000000U)
5662+ {
5663+ struct vm_area_struct *vma;
5664+ unsigned long call_dl_resolve;
5665+
5666+ down_read(&current->mm->mmap_sem);
5667+ call_dl_resolve = current->mm->call_dl_resolve;
5668+ up_read(&current->mm->mmap_sem);
5669+ if (likely(call_dl_resolve))
5670+ goto emulate;
5671+
5672+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5673+
5674+ down_write(&current->mm->mmap_sem);
5675+ if (current->mm->call_dl_resolve) {
5676+ call_dl_resolve = current->mm->call_dl_resolve;
5677+ up_write(&current->mm->mmap_sem);
5678+ if (vma)
5679+ kmem_cache_free(vm_area_cachep, vma);
5680+ goto emulate;
5681+ }
5682+
5683+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5684+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5685+ up_write(&current->mm->mmap_sem);
5686+ if (vma)
5687+ kmem_cache_free(vm_area_cachep, vma);
5688+ return 1;
5689+ }
5690+
5691+ if (pax_insert_vma(vma, call_dl_resolve)) {
5692+ up_write(&current->mm->mmap_sem);
5693+ kmem_cache_free(vm_area_cachep, vma);
5694+ return 1;
5695+ }
5696+
5697+ current->mm->call_dl_resolve = call_dl_resolve;
5698+ up_write(&current->mm->mmap_sem);
5699+
5700+emulate:
5701+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5702+ regs->tpc = call_dl_resolve;
5703+ regs->tnpc = addr+4;
5704+ return 3;
5705+ }
5706+#endif
5707+
5708+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5709+ if ((save & 0xFFC00000U) == 0x05000000U &&
5710+ (call & 0xFFFFE000U) == 0x85C0A000U &&
5711+ nop == 0x01000000U)
5712+ {
5713+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5714+ regs->u_regs[UREG_G2] = addr + 4;
5715+ addr = (save & 0x003FFFFFU) << 10;
5716+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5717+
5718+ if (test_thread_flag(TIF_32BIT))
5719+ addr &= 0xFFFFFFFFUL;
5720+
5721+ regs->tpc = addr;
5722+ regs->tnpc = addr+4;
5723+ return 3;
5724+ }
5725+
5726+ /* PaX: 64-bit PLT stub */
5727+ err = get_user(sethi1, (unsigned int *)addr);
5728+ err |= get_user(sethi2, (unsigned int *)(addr+4));
5729+ err |= get_user(or1, (unsigned int *)(addr+8));
5730+ err |= get_user(or2, (unsigned int *)(addr+12));
5731+ err |= get_user(sllx, (unsigned int *)(addr+16));
5732+ err |= get_user(add, (unsigned int *)(addr+20));
5733+ err |= get_user(jmpl, (unsigned int *)(addr+24));
5734+ err |= get_user(nop, (unsigned int *)(addr+28));
5735+ if (err)
5736+ break;
5737+
5738+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5739+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5740+ (or1 & 0xFFFFE000U) == 0x88112000U &&
5741+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
5742+ sllx == 0x89293020U &&
5743+ add == 0x8A010005U &&
5744+ jmpl == 0x89C14000U &&
5745+ nop == 0x01000000U)
5746+ {
5747+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5748+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5749+ regs->u_regs[UREG_G4] <<= 32;
5750+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5751+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5752+ regs->u_regs[UREG_G4] = addr + 24;
5753+ addr = regs->u_regs[UREG_G5];
5754+ regs->tpc = addr;
5755+ regs->tnpc = addr+4;
5756+ return 3;
5757+ }
5758+ }
5759+ } while (0);
5760+
5761+#ifdef CONFIG_PAX_DLRESOLVE
5762+ do { /* PaX: unpatched PLT emulation step 2 */
5763+ unsigned int save, call, nop;
5764+
5765+ err = get_user(save, (unsigned int *)(regs->tpc-4));
5766+ err |= get_user(call, (unsigned int *)regs->tpc);
5767+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5768+ if (err)
5769+ break;
5770+
5771+ if (save == 0x9DE3BFA8U &&
5772+ (call & 0xC0000000U) == 0x40000000U &&
5773+ nop == 0x01000000U)
5774+ {
5775+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5776+
5777+ if (test_thread_flag(TIF_32BIT))
5778+ dl_resolve &= 0xFFFFFFFFUL;
5779+
5780+ regs->u_regs[UREG_RETPC] = regs->tpc;
5781+ regs->tpc = dl_resolve;
5782+ regs->tnpc = dl_resolve+4;
5783+ return 3;
5784+ }
5785+ } while (0);
5786+#endif
5787+
5788+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5789+ unsigned int sethi, ba, nop;
5790+
5791+ err = get_user(sethi, (unsigned int *)regs->tpc);
5792+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5793+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5794+
5795+ if (err)
5796+ break;
5797+
5798+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5799+ (ba & 0xFFF00000U) == 0x30600000U &&
5800+ nop == 0x01000000U)
5801+ {
5802+ unsigned long addr;
5803+
5804+ addr = (sethi & 0x003FFFFFU) << 10;
5805+ regs->u_regs[UREG_G1] = addr;
5806+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5807+
5808+ if (test_thread_flag(TIF_32BIT))
5809+ addr &= 0xFFFFFFFFUL;
5810+
5811+ regs->tpc = addr;
5812+ regs->tnpc = addr+4;
5813+ return 2;
5814+ }
5815+ } while (0);
5816+
5817+#endif
5818+
5819+ return 1;
5820+}
5821+
5822+void pax_report_insns(void *pc, void *sp)
5823+{
5824+ unsigned long i;
5825+
5826+ printk(KERN_ERR "PAX: bytes at PC: ");
5827+ for (i = 0; i < 8; i++) {
5828+ unsigned int c;
5829+ if (get_user(c, (unsigned int *)pc+i))
5830+ printk(KERN_CONT "???????? ");
5831+ else
5832+ printk(KERN_CONT "%08x ", c);
5833+ }
5834+ printk("\n");
5835+}
5836+#endif
5837+
5838 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5839 {
5840 struct mm_struct *mm = current->mm;
5841@@ -315,6 +768,29 @@ asmlinkage void __kprobes do_sparc64_fau
5842 if (!vma)
5843 goto bad_area;
5844
5845+#ifdef CONFIG_PAX_PAGEEXEC
5846+ /* PaX: detect ITLB misses on non-exec pages */
5847+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5848+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5849+ {
5850+ if (address != regs->tpc)
5851+ goto good_area;
5852+
5853+ up_read(&mm->mmap_sem);
5854+ switch (pax_handle_fetch_fault(regs)) {
5855+
5856+#ifdef CONFIG_PAX_EMUPLT
5857+ case 2:
5858+ case 3:
5859+ return;
5860+#endif
5861+
5862+ }
5863+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5864+ do_group_exit(SIGKILL);
5865+ }
5866+#endif
5867+
5868 /* Pure DTLB misses do not tell us whether the fault causing
5869 * load/store/atomic was a write or not, it only says that there
5870 * was no match. So in such a case we (carefully) read the
5871diff -urNp linux-2.6.32.44/arch/sparc/mm/hugetlbpage.c linux-2.6.32.44/arch/sparc/mm/hugetlbpage.c
5872--- linux-2.6.32.44/arch/sparc/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
5873+++ linux-2.6.32.44/arch/sparc/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
5874@@ -69,7 +69,7 @@ full_search:
5875 }
5876 return -ENOMEM;
5877 }
5878- if (likely(!vma || addr + len <= vma->vm_start)) {
5879+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5880 /*
5881 * Remember the place where we stopped the search:
5882 */
5883@@ -108,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct
5884 /* make sure it can fit in the remaining address space */
5885 if (likely(addr > len)) {
5886 vma = find_vma(mm, addr-len);
5887- if (!vma || addr <= vma->vm_start) {
5888+ if (check_heap_stack_gap(vma, addr - len, len)) {
5889 /* remember the address as a hint for next time */
5890 return (mm->free_area_cache = addr-len);
5891 }
5892@@ -117,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct
5893 if (unlikely(mm->mmap_base < len))
5894 goto bottomup;
5895
5896- addr = (mm->mmap_base-len) & HPAGE_MASK;
5897+ addr = mm->mmap_base - len;
5898
5899 do {
5900+ addr &= HPAGE_MASK;
5901 /*
5902 * Lookup failure means no vma is above this address,
5903 * else if new region fits below vma->vm_start,
5904 * return with success:
5905 */
5906 vma = find_vma(mm, addr);
5907- if (likely(!vma || addr+len <= vma->vm_start)) {
5908+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5909 /* remember the address as a hint for next time */
5910 return (mm->free_area_cache = addr);
5911 }
5912@@ -136,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct
5913 mm->cached_hole_size = vma->vm_start - addr;
5914
5915 /* try just below the current vma->vm_start */
5916- addr = (vma->vm_start-len) & HPAGE_MASK;
5917- } while (likely(len < vma->vm_start));
5918+ addr = skip_heap_stack_gap(vma, len);
5919+ } while (!IS_ERR_VALUE(addr));
5920
5921 bottomup:
5922 /*
5923@@ -183,8 +184,7 @@ hugetlb_get_unmapped_area(struct file *f
5924 if (addr) {
5925 addr = ALIGN(addr, HPAGE_SIZE);
5926 vma = find_vma(mm, addr);
5927- if (task_size - len >= addr &&
5928- (!vma || addr + len <= vma->vm_start))
5929+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5930 return addr;
5931 }
5932 if (mm->get_unmapped_area == arch_get_unmapped_area)
5933diff -urNp linux-2.6.32.44/arch/sparc/mm/init_32.c linux-2.6.32.44/arch/sparc/mm/init_32.c
5934--- linux-2.6.32.44/arch/sparc/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
5935+++ linux-2.6.32.44/arch/sparc/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
5936@@ -317,6 +317,9 @@ extern void device_scan(void);
5937 pgprot_t PAGE_SHARED __read_mostly;
5938 EXPORT_SYMBOL(PAGE_SHARED);
5939
5940+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5941+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5942+
5943 void __init paging_init(void)
5944 {
5945 switch(sparc_cpu_model) {
5946@@ -345,17 +348,17 @@ void __init paging_init(void)
5947
5948 /* Initialize the protection map with non-constant, MMU dependent values. */
5949 protection_map[0] = PAGE_NONE;
5950- protection_map[1] = PAGE_READONLY;
5951- protection_map[2] = PAGE_COPY;
5952- protection_map[3] = PAGE_COPY;
5953+ protection_map[1] = PAGE_READONLY_NOEXEC;
5954+ protection_map[2] = PAGE_COPY_NOEXEC;
5955+ protection_map[3] = PAGE_COPY_NOEXEC;
5956 protection_map[4] = PAGE_READONLY;
5957 protection_map[5] = PAGE_READONLY;
5958 protection_map[6] = PAGE_COPY;
5959 protection_map[7] = PAGE_COPY;
5960 protection_map[8] = PAGE_NONE;
5961- protection_map[9] = PAGE_READONLY;
5962- protection_map[10] = PAGE_SHARED;
5963- protection_map[11] = PAGE_SHARED;
5964+ protection_map[9] = PAGE_READONLY_NOEXEC;
5965+ protection_map[10] = PAGE_SHARED_NOEXEC;
5966+ protection_map[11] = PAGE_SHARED_NOEXEC;
5967 protection_map[12] = PAGE_READONLY;
5968 protection_map[13] = PAGE_READONLY;
5969 protection_map[14] = PAGE_SHARED;
5970diff -urNp linux-2.6.32.44/arch/sparc/mm/Makefile linux-2.6.32.44/arch/sparc/mm/Makefile
5971--- linux-2.6.32.44/arch/sparc/mm/Makefile 2011-03-27 14:31:47.000000000 -0400
5972+++ linux-2.6.32.44/arch/sparc/mm/Makefile 2011-04-17 15:56:46.000000000 -0400
5973@@ -2,7 +2,7 @@
5974 #
5975
5976 asflags-y := -ansi
5977-ccflags-y := -Werror
5978+#ccflags-y := -Werror
5979
5980 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5981 obj-y += fault_$(BITS).o
5982diff -urNp linux-2.6.32.44/arch/sparc/mm/srmmu.c linux-2.6.32.44/arch/sparc/mm/srmmu.c
5983--- linux-2.6.32.44/arch/sparc/mm/srmmu.c 2011-03-27 14:31:47.000000000 -0400
5984+++ linux-2.6.32.44/arch/sparc/mm/srmmu.c 2011-04-17 15:56:46.000000000 -0400
5985@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5986 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5987 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5988 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5989+
5990+#ifdef CONFIG_PAX_PAGEEXEC
5991+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5992+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5993+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5994+#endif
5995+
5996 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5997 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5998
5999diff -urNp linux-2.6.32.44/arch/um/include/asm/kmap_types.h linux-2.6.32.44/arch/um/include/asm/kmap_types.h
6000--- linux-2.6.32.44/arch/um/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
6001+++ linux-2.6.32.44/arch/um/include/asm/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
6002@@ -23,6 +23,7 @@ enum km_type {
6003 KM_IRQ1,
6004 KM_SOFTIRQ0,
6005 KM_SOFTIRQ1,
6006+ KM_CLEARPAGE,
6007 KM_TYPE_NR
6008 };
6009
6010diff -urNp linux-2.6.32.44/arch/um/include/asm/page.h linux-2.6.32.44/arch/um/include/asm/page.h
6011--- linux-2.6.32.44/arch/um/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
6012+++ linux-2.6.32.44/arch/um/include/asm/page.h 2011-04-17 15:56:46.000000000 -0400
6013@@ -14,6 +14,9 @@
6014 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6015 #define PAGE_MASK (~(PAGE_SIZE-1))
6016
6017+#define ktla_ktva(addr) (addr)
6018+#define ktva_ktla(addr) (addr)
6019+
6020 #ifndef __ASSEMBLY__
6021
6022 struct page;
6023diff -urNp linux-2.6.32.44/arch/um/kernel/process.c linux-2.6.32.44/arch/um/kernel/process.c
6024--- linux-2.6.32.44/arch/um/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
6025+++ linux-2.6.32.44/arch/um/kernel/process.c 2011-04-17 15:56:46.000000000 -0400
6026@@ -393,22 +393,6 @@ int singlestepping(void * t)
6027 return 2;
6028 }
6029
6030-/*
6031- * Only x86 and x86_64 have an arch_align_stack().
6032- * All other arches have "#define arch_align_stack(x) (x)"
6033- * in their asm/system.h
6034- * As this is included in UML from asm-um/system-generic.h,
6035- * we can use it to behave as the subarch does.
6036- */
6037-#ifndef arch_align_stack
6038-unsigned long arch_align_stack(unsigned long sp)
6039-{
6040- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6041- sp -= get_random_int() % 8192;
6042- return sp & ~0xf;
6043-}
6044-#endif
6045-
6046 unsigned long get_wchan(struct task_struct *p)
6047 {
6048 unsigned long stack_page, sp, ip;
6049diff -urNp linux-2.6.32.44/arch/um/sys-i386/syscalls.c linux-2.6.32.44/arch/um/sys-i386/syscalls.c
6050--- linux-2.6.32.44/arch/um/sys-i386/syscalls.c 2011-03-27 14:31:47.000000000 -0400
6051+++ linux-2.6.32.44/arch/um/sys-i386/syscalls.c 2011-04-17 15:56:46.000000000 -0400
6052@@ -11,6 +11,21 @@
6053 #include "asm/uaccess.h"
6054 #include "asm/unistd.h"
6055
6056+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6057+{
6058+ unsigned long pax_task_size = TASK_SIZE;
6059+
6060+#ifdef CONFIG_PAX_SEGMEXEC
6061+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6062+ pax_task_size = SEGMEXEC_TASK_SIZE;
6063+#endif
6064+
6065+ if (len > pax_task_size || addr > pax_task_size - len)
6066+ return -EINVAL;
6067+
6068+ return 0;
6069+}
6070+
6071 /*
6072 * Perform the select(nd, in, out, ex, tv) and mmap() system
6073 * calls. Linux/i386 didn't use to be able to handle more than
6074diff -urNp linux-2.6.32.44/arch/x86/boot/bitops.h linux-2.6.32.44/arch/x86/boot/bitops.h
6075--- linux-2.6.32.44/arch/x86/boot/bitops.h 2011-03-27 14:31:47.000000000 -0400
6076+++ linux-2.6.32.44/arch/x86/boot/bitops.h 2011-04-17 15:56:46.000000000 -0400
6077@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
6078 u8 v;
6079 const u32 *p = (const u32 *)addr;
6080
6081- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6082+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6083 return v;
6084 }
6085
6086@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
6087
6088 static inline void set_bit(int nr, void *addr)
6089 {
6090- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6091+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6092 }
6093
6094 #endif /* BOOT_BITOPS_H */
6095diff -urNp linux-2.6.32.44/arch/x86/boot/boot.h linux-2.6.32.44/arch/x86/boot/boot.h
6096--- linux-2.6.32.44/arch/x86/boot/boot.h 2011-03-27 14:31:47.000000000 -0400
6097+++ linux-2.6.32.44/arch/x86/boot/boot.h 2011-04-17 15:56:46.000000000 -0400
6098@@ -82,7 +82,7 @@ static inline void io_delay(void)
6099 static inline u16 ds(void)
6100 {
6101 u16 seg;
6102- asm("movw %%ds,%0" : "=rm" (seg));
6103+ asm volatile("movw %%ds,%0" : "=rm" (seg));
6104 return seg;
6105 }
6106
6107@@ -178,7 +178,7 @@ static inline void wrgs32(u32 v, addr_t
6108 static inline int memcmp(const void *s1, const void *s2, size_t len)
6109 {
6110 u8 diff;
6111- asm("repe; cmpsb; setnz %0"
6112+ asm volatile("repe; cmpsb; setnz %0"
6113 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
6114 return diff;
6115 }
6116diff -urNp linux-2.6.32.44/arch/x86/boot/compressed/head_32.S linux-2.6.32.44/arch/x86/boot/compressed/head_32.S
6117--- linux-2.6.32.44/arch/x86/boot/compressed/head_32.S 2011-03-27 14:31:47.000000000 -0400
6118+++ linux-2.6.32.44/arch/x86/boot/compressed/head_32.S 2011-04-17 15:56:46.000000000 -0400
6119@@ -76,7 +76,7 @@ ENTRY(startup_32)
6120 notl %eax
6121 andl %eax, %ebx
6122 #else
6123- movl $LOAD_PHYSICAL_ADDR, %ebx
6124+ movl $____LOAD_PHYSICAL_ADDR, %ebx
6125 #endif
6126
6127 /* Target address to relocate to for decompression */
6128@@ -149,7 +149,7 @@ relocated:
6129 * and where it was actually loaded.
6130 */
6131 movl %ebp, %ebx
6132- subl $LOAD_PHYSICAL_ADDR, %ebx
6133+ subl $____LOAD_PHYSICAL_ADDR, %ebx
6134 jz 2f /* Nothing to be done if loaded at compiled addr. */
6135 /*
6136 * Process relocations.
6137@@ -157,8 +157,7 @@ relocated:
6138
6139 1: subl $4, %edi
6140 movl (%edi), %ecx
6141- testl %ecx, %ecx
6142- jz 2f
6143+ jecxz 2f
6144 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
6145 jmp 1b
6146 2:
6147diff -urNp linux-2.6.32.44/arch/x86/boot/compressed/head_64.S linux-2.6.32.44/arch/x86/boot/compressed/head_64.S
6148--- linux-2.6.32.44/arch/x86/boot/compressed/head_64.S 2011-03-27 14:31:47.000000000 -0400
6149+++ linux-2.6.32.44/arch/x86/boot/compressed/head_64.S 2011-07-01 18:53:00.000000000 -0400
6150@@ -91,7 +91,7 @@ ENTRY(startup_32)
6151 notl %eax
6152 andl %eax, %ebx
6153 #else
6154- movl $LOAD_PHYSICAL_ADDR, %ebx
6155+ movl $____LOAD_PHYSICAL_ADDR, %ebx
6156 #endif
6157
6158 /* Target address to relocate to for decompression */
6159@@ -183,7 +183,7 @@ no_longmode:
6160 hlt
6161 jmp 1b
6162
6163-#include "../../kernel/verify_cpu_64.S"
6164+#include "../../kernel/verify_cpu.S"
6165
6166 /*
6167 * Be careful here startup_64 needs to be at a predictable
6168@@ -234,7 +234,7 @@ ENTRY(startup_64)
6169 notq %rax
6170 andq %rax, %rbp
6171 #else
6172- movq $LOAD_PHYSICAL_ADDR, %rbp
6173+ movq $____LOAD_PHYSICAL_ADDR, %rbp
6174 #endif
6175
6176 /* Target address to relocate to for decompression */
6177diff -urNp linux-2.6.32.44/arch/x86/boot/compressed/Makefile linux-2.6.32.44/arch/x86/boot/compressed/Makefile
6178--- linux-2.6.32.44/arch/x86/boot/compressed/Makefile 2011-03-27 14:31:47.000000000 -0400
6179+++ linux-2.6.32.44/arch/x86/boot/compressed/Makefile 2011-08-07 14:38:34.000000000 -0400
6180@@ -13,6 +13,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=smal
6181 KBUILD_CFLAGS += $(cflags-y)
6182 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
6183 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
6184+ifdef CONSTIFY_PLUGIN
6185+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6186+endif
6187
6188 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6189 GCOV_PROFILE := n
6190diff -urNp linux-2.6.32.44/arch/x86/boot/compressed/misc.c linux-2.6.32.44/arch/x86/boot/compressed/misc.c
6191--- linux-2.6.32.44/arch/x86/boot/compressed/misc.c 2011-03-27 14:31:47.000000000 -0400
6192+++ linux-2.6.32.44/arch/x86/boot/compressed/misc.c 2011-04-17 15:56:46.000000000 -0400
6193@@ -288,7 +288,7 @@ static void parse_elf(void *output)
6194 case PT_LOAD:
6195 #ifdef CONFIG_RELOCATABLE
6196 dest = output;
6197- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6198+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6199 #else
6200 dest = (void *)(phdr->p_paddr);
6201 #endif
6202@@ -335,7 +335,7 @@ asmlinkage void decompress_kernel(void *
6203 error("Destination address too large");
6204 #endif
6205 #ifndef CONFIG_RELOCATABLE
6206- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
6207+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
6208 error("Wrong destination address");
6209 #endif
6210
6211diff -urNp linux-2.6.32.44/arch/x86/boot/compressed/mkpiggy.c linux-2.6.32.44/arch/x86/boot/compressed/mkpiggy.c
6212--- linux-2.6.32.44/arch/x86/boot/compressed/mkpiggy.c 2011-03-27 14:31:47.000000000 -0400
6213+++ linux-2.6.32.44/arch/x86/boot/compressed/mkpiggy.c 2011-04-17 15:56:46.000000000 -0400
6214@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
6215
6216 offs = (olen > ilen) ? olen - ilen : 0;
6217 offs += olen >> 12; /* Add 8 bytes for each 32K block */
6218- offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
6219+ offs += 64*1024; /* Add 64K bytes slack */
6220 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
6221
6222 printf(".section \".rodata.compressed\",\"a\",@progbits\n");
6223diff -urNp linux-2.6.32.44/arch/x86/boot/compressed/relocs.c linux-2.6.32.44/arch/x86/boot/compressed/relocs.c
6224--- linux-2.6.32.44/arch/x86/boot/compressed/relocs.c 2011-03-27 14:31:47.000000000 -0400
6225+++ linux-2.6.32.44/arch/x86/boot/compressed/relocs.c 2011-04-17 15:56:46.000000000 -0400
6226@@ -10,8 +10,11 @@
6227 #define USE_BSD
6228 #include <endian.h>
6229
6230+#include "../../../../include/linux/autoconf.h"
6231+
6232 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
6233 static Elf32_Ehdr ehdr;
6234+static Elf32_Phdr *phdr;
6235 static unsigned long reloc_count, reloc_idx;
6236 static unsigned long *relocs;
6237
6238@@ -37,7 +40,7 @@ static const char* safe_abs_relocs[] = {
6239
6240 static int is_safe_abs_reloc(const char* sym_name)
6241 {
6242- int i;
6243+ unsigned int i;
6244
6245 for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
6246 if (!strcmp(sym_name, safe_abs_relocs[i]))
6247@@ -245,9 +248,39 @@ static void read_ehdr(FILE *fp)
6248 }
6249 }
6250
6251+static void read_phdrs(FILE *fp)
6252+{
6253+ unsigned int i;
6254+
6255+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6256+ if (!phdr) {
6257+ die("Unable to allocate %d program headers\n",
6258+ ehdr.e_phnum);
6259+ }
6260+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6261+ die("Seek to %d failed: %s\n",
6262+ ehdr.e_phoff, strerror(errno));
6263+ }
6264+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6265+ die("Cannot read ELF program headers: %s\n",
6266+ strerror(errno));
6267+ }
6268+ for(i = 0; i < ehdr.e_phnum; i++) {
6269+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
6270+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
6271+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
6272+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
6273+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
6274+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
6275+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
6276+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
6277+ }
6278+
6279+}
6280+
6281 static void read_shdrs(FILE *fp)
6282 {
6283- int i;
6284+ unsigned int i;
6285 Elf32_Shdr shdr;
6286
6287 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6288@@ -282,7 +315,7 @@ static void read_shdrs(FILE *fp)
6289
6290 static void read_strtabs(FILE *fp)
6291 {
6292- int i;
6293+ unsigned int i;
6294 for (i = 0; i < ehdr.e_shnum; i++) {
6295 struct section *sec = &secs[i];
6296 if (sec->shdr.sh_type != SHT_STRTAB) {
6297@@ -307,7 +340,7 @@ static void read_strtabs(FILE *fp)
6298
6299 static void read_symtabs(FILE *fp)
6300 {
6301- int i,j;
6302+ unsigned int i,j;
6303 for (i = 0; i < ehdr.e_shnum; i++) {
6304 struct section *sec = &secs[i];
6305 if (sec->shdr.sh_type != SHT_SYMTAB) {
6306@@ -340,7 +373,9 @@ static void read_symtabs(FILE *fp)
6307
6308 static void read_relocs(FILE *fp)
6309 {
6310- int i,j;
6311+ unsigned int i,j;
6312+ uint32_t base;
6313+
6314 for (i = 0; i < ehdr.e_shnum; i++) {
6315 struct section *sec = &secs[i];
6316 if (sec->shdr.sh_type != SHT_REL) {
6317@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
6318 die("Cannot read symbol table: %s\n",
6319 strerror(errno));
6320 }
6321+ base = 0;
6322+ for (j = 0; j < ehdr.e_phnum; j++) {
6323+ if (phdr[j].p_type != PT_LOAD )
6324+ continue;
6325+ 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)
6326+ continue;
6327+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6328+ break;
6329+ }
6330 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6331 Elf32_Rel *rel = &sec->reltab[j];
6332- rel->r_offset = elf32_to_cpu(rel->r_offset);
6333+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6334 rel->r_info = elf32_to_cpu(rel->r_info);
6335 }
6336 }
6337@@ -371,14 +415,14 @@ static void read_relocs(FILE *fp)
6338
6339 static void print_absolute_symbols(void)
6340 {
6341- int i;
6342+ unsigned int i;
6343 printf("Absolute symbols\n");
6344 printf(" Num: Value Size Type Bind Visibility Name\n");
6345 for (i = 0; i < ehdr.e_shnum; i++) {
6346 struct section *sec = &secs[i];
6347 char *sym_strtab;
6348 Elf32_Sym *sh_symtab;
6349- int j;
6350+ unsigned int j;
6351
6352 if (sec->shdr.sh_type != SHT_SYMTAB) {
6353 continue;
6354@@ -406,14 +450,14 @@ static void print_absolute_symbols(void)
6355
6356 static void print_absolute_relocs(void)
6357 {
6358- int i, printed = 0;
6359+ unsigned int i, printed = 0;
6360
6361 for (i = 0; i < ehdr.e_shnum; i++) {
6362 struct section *sec = &secs[i];
6363 struct section *sec_applies, *sec_symtab;
6364 char *sym_strtab;
6365 Elf32_Sym *sh_symtab;
6366- int j;
6367+ unsigned int j;
6368 if (sec->shdr.sh_type != SHT_REL) {
6369 continue;
6370 }
6371@@ -474,13 +518,13 @@ static void print_absolute_relocs(void)
6372
6373 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6374 {
6375- int i;
6376+ unsigned int i;
6377 /* Walk through the relocations */
6378 for (i = 0; i < ehdr.e_shnum; i++) {
6379 char *sym_strtab;
6380 Elf32_Sym *sh_symtab;
6381 struct section *sec_applies, *sec_symtab;
6382- int j;
6383+ unsigned int j;
6384 struct section *sec = &secs[i];
6385
6386 if (sec->shdr.sh_type != SHT_REL) {
6387@@ -504,6 +548,21 @@ static void walk_relocs(void (*visit)(El
6388 if (sym->st_shndx == SHN_ABS) {
6389 continue;
6390 }
6391+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6392+ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6393+ continue;
6394+
6395+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6396+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6397+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6398+ continue;
6399+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6400+ continue;
6401+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6402+ continue;
6403+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6404+ continue;
6405+#endif
6406 if (r_type == R_386_NONE || r_type == R_386_PC32) {
6407 /*
6408 * NONE can be ignored and and PC relative
6409@@ -541,7 +600,7 @@ static int cmp_relocs(const void *va, co
6410
6411 static void emit_relocs(int as_text)
6412 {
6413- int i;
6414+ unsigned int i;
6415 /* Count how many relocations I have and allocate space for them. */
6416 reloc_count = 0;
6417 walk_relocs(count_reloc);
6418@@ -634,6 +693,7 @@ int main(int argc, char **argv)
6419 fname, strerror(errno));
6420 }
6421 read_ehdr(fp);
6422+ read_phdrs(fp);
6423 read_shdrs(fp);
6424 read_strtabs(fp);
6425 read_symtabs(fp);
6426diff -urNp linux-2.6.32.44/arch/x86/boot/cpucheck.c linux-2.6.32.44/arch/x86/boot/cpucheck.c
6427--- linux-2.6.32.44/arch/x86/boot/cpucheck.c 2011-03-27 14:31:47.000000000 -0400
6428+++ linux-2.6.32.44/arch/x86/boot/cpucheck.c 2011-04-17 15:56:46.000000000 -0400
6429@@ -74,7 +74,7 @@ static int has_fpu(void)
6430 u16 fcw = -1, fsw = -1;
6431 u32 cr0;
6432
6433- asm("movl %%cr0,%0" : "=r" (cr0));
6434+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
6435 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6436 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6437 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6438@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6439 {
6440 u32 f0, f1;
6441
6442- asm("pushfl ; "
6443+ asm volatile("pushfl ; "
6444 "pushfl ; "
6445 "popl %0 ; "
6446 "movl %0,%1 ; "
6447@@ -115,7 +115,7 @@ static void get_flags(void)
6448 set_bit(X86_FEATURE_FPU, cpu.flags);
6449
6450 if (has_eflag(X86_EFLAGS_ID)) {
6451- asm("cpuid"
6452+ asm volatile("cpuid"
6453 : "=a" (max_intel_level),
6454 "=b" (cpu_vendor[0]),
6455 "=d" (cpu_vendor[1]),
6456@@ -124,7 +124,7 @@ static void get_flags(void)
6457
6458 if (max_intel_level >= 0x00000001 &&
6459 max_intel_level <= 0x0000ffff) {
6460- asm("cpuid"
6461+ asm volatile("cpuid"
6462 : "=a" (tfms),
6463 "=c" (cpu.flags[4]),
6464 "=d" (cpu.flags[0])
6465@@ -136,7 +136,7 @@ static void get_flags(void)
6466 cpu.model += ((tfms >> 16) & 0xf) << 4;
6467 }
6468
6469- asm("cpuid"
6470+ asm volatile("cpuid"
6471 : "=a" (max_amd_level)
6472 : "a" (0x80000000)
6473 : "ebx", "ecx", "edx");
6474@@ -144,7 +144,7 @@ static void get_flags(void)
6475 if (max_amd_level >= 0x80000001 &&
6476 max_amd_level <= 0x8000ffff) {
6477 u32 eax = 0x80000001;
6478- asm("cpuid"
6479+ asm volatile("cpuid"
6480 : "+a" (eax),
6481 "=c" (cpu.flags[6]),
6482 "=d" (cpu.flags[1])
6483@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6484 u32 ecx = MSR_K7_HWCR;
6485 u32 eax, edx;
6486
6487- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6488+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6489 eax &= ~(1 << 15);
6490- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6491+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6492
6493 get_flags(); /* Make sure it really did something */
6494 err = check_flags();
6495@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6496 u32 ecx = MSR_VIA_FCR;
6497 u32 eax, edx;
6498
6499- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6500+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6501 eax |= (1<<1)|(1<<7);
6502- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6503+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6504
6505 set_bit(X86_FEATURE_CX8, cpu.flags);
6506 err = check_flags();
6507@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
6508 u32 eax, edx;
6509 u32 level = 1;
6510
6511- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6512- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6513- asm("cpuid"
6514+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6515+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6516+ asm volatile("cpuid"
6517 : "+a" (level), "=d" (cpu.flags[0])
6518 : : "ecx", "ebx");
6519- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6520+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6521
6522 err = check_flags();
6523 }
6524diff -urNp linux-2.6.32.44/arch/x86/boot/header.S linux-2.6.32.44/arch/x86/boot/header.S
6525--- linux-2.6.32.44/arch/x86/boot/header.S 2011-03-27 14:31:47.000000000 -0400
6526+++ linux-2.6.32.44/arch/x86/boot/header.S 2011-04-17 15:56:46.000000000 -0400
6527@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
6528 # single linked list of
6529 # struct setup_data
6530
6531-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6532+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6533
6534 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6535 #define VO_INIT_SIZE (VO__end - VO__text)
6536diff -urNp linux-2.6.32.44/arch/x86/boot/Makefile linux-2.6.32.44/arch/x86/boot/Makefile
6537--- linux-2.6.32.44/arch/x86/boot/Makefile 2011-03-27 14:31:47.000000000 -0400
6538+++ linux-2.6.32.44/arch/x86/boot/Makefile 2011-08-07 14:38:13.000000000 -0400
6539@@ -69,6 +69,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
6540 $(call cc-option, -fno-stack-protector) \
6541 $(call cc-option, -mpreferred-stack-boundary=2)
6542 KBUILD_CFLAGS += $(call cc-option, -m32)
6543+ifdef CONSTIFY_PLUGIN
6544+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6545+endif
6546 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6547 GCOV_PROFILE := n
6548
6549diff -urNp linux-2.6.32.44/arch/x86/boot/memory.c linux-2.6.32.44/arch/x86/boot/memory.c
6550--- linux-2.6.32.44/arch/x86/boot/memory.c 2011-03-27 14:31:47.000000000 -0400
6551+++ linux-2.6.32.44/arch/x86/boot/memory.c 2011-04-17 15:56:46.000000000 -0400
6552@@ -19,7 +19,7 @@
6553
6554 static int detect_memory_e820(void)
6555 {
6556- int count = 0;
6557+ unsigned int count = 0;
6558 struct biosregs ireg, oreg;
6559 struct e820entry *desc = boot_params.e820_map;
6560 static struct e820entry buf; /* static so it is zeroed */
6561diff -urNp linux-2.6.32.44/arch/x86/boot/video.c linux-2.6.32.44/arch/x86/boot/video.c
6562--- linux-2.6.32.44/arch/x86/boot/video.c 2011-03-27 14:31:47.000000000 -0400
6563+++ linux-2.6.32.44/arch/x86/boot/video.c 2011-04-17 15:56:46.000000000 -0400
6564@@ -90,7 +90,7 @@ static void store_mode_params(void)
6565 static unsigned int get_entry(void)
6566 {
6567 char entry_buf[4];
6568- int i, len = 0;
6569+ unsigned int i, len = 0;
6570 int key;
6571 unsigned int v;
6572
6573diff -urNp linux-2.6.32.44/arch/x86/boot/video-vesa.c linux-2.6.32.44/arch/x86/boot/video-vesa.c
6574--- linux-2.6.32.44/arch/x86/boot/video-vesa.c 2011-03-27 14:31:47.000000000 -0400
6575+++ linux-2.6.32.44/arch/x86/boot/video-vesa.c 2011-04-17 15:56:46.000000000 -0400
6576@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6577
6578 boot_params.screen_info.vesapm_seg = oreg.es;
6579 boot_params.screen_info.vesapm_off = oreg.di;
6580+ boot_params.screen_info.vesapm_size = oreg.cx;
6581 }
6582
6583 /*
6584diff -urNp linux-2.6.32.44/arch/x86/ia32/ia32_aout.c linux-2.6.32.44/arch/x86/ia32/ia32_aout.c
6585--- linux-2.6.32.44/arch/x86/ia32/ia32_aout.c 2011-03-27 14:31:47.000000000 -0400
6586+++ linux-2.6.32.44/arch/x86/ia32/ia32_aout.c 2011-04-17 15:56:46.000000000 -0400
6587@@ -169,6 +169,8 @@ static int aout_core_dump(long signr, st
6588 unsigned long dump_start, dump_size;
6589 struct user32 dump;
6590
6591+ memset(&dump, 0, sizeof(dump));
6592+
6593 fs = get_fs();
6594 set_fs(KERNEL_DS);
6595 has_dumped = 1;
6596@@ -218,12 +220,6 @@ static int aout_core_dump(long signr, st
6597 dump_size = dump.u_ssize << PAGE_SHIFT;
6598 DUMP_WRITE(dump_start, dump_size);
6599 }
6600- /*
6601- * Finally dump the task struct. Not be used by gdb, but
6602- * could be useful
6603- */
6604- set_fs(KERNEL_DS);
6605- DUMP_WRITE(current, sizeof(*current));
6606 end_coredump:
6607 set_fs(fs);
6608 return has_dumped;
6609diff -urNp linux-2.6.32.44/arch/x86/ia32/ia32entry.S linux-2.6.32.44/arch/x86/ia32/ia32entry.S
6610--- linux-2.6.32.44/arch/x86/ia32/ia32entry.S 2011-03-27 14:31:47.000000000 -0400
6611+++ linux-2.6.32.44/arch/x86/ia32/ia32entry.S 2011-06-04 20:29:52.000000000 -0400
6612@@ -13,6 +13,7 @@
6613 #include <asm/thread_info.h>
6614 #include <asm/segment.h>
6615 #include <asm/irqflags.h>
6616+#include <asm/pgtable.h>
6617 #include <linux/linkage.h>
6618
6619 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6620@@ -93,6 +94,30 @@ ENTRY(native_irq_enable_sysexit)
6621 ENDPROC(native_irq_enable_sysexit)
6622 #endif
6623
6624+ .macro pax_enter_kernel_user
6625+#ifdef CONFIG_PAX_MEMORY_UDEREF
6626+ call pax_enter_kernel_user
6627+#endif
6628+ .endm
6629+
6630+ .macro pax_exit_kernel_user
6631+#ifdef CONFIG_PAX_MEMORY_UDEREF
6632+ call pax_exit_kernel_user
6633+#endif
6634+#ifdef CONFIG_PAX_RANDKSTACK
6635+ pushq %rax
6636+ call pax_randomize_kstack
6637+ popq %rax
6638+#endif
6639+ pax_erase_kstack
6640+ .endm
6641+
6642+.macro pax_erase_kstack
6643+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
6644+ call pax_erase_kstack
6645+#endif
6646+.endm
6647+
6648 /*
6649 * 32bit SYSENTER instruction entry.
6650 *
6651@@ -119,7 +144,7 @@ ENTRY(ia32_sysenter_target)
6652 CFI_REGISTER rsp,rbp
6653 SWAPGS_UNSAFE_STACK
6654 movq PER_CPU_VAR(kernel_stack), %rsp
6655- addq $(KERNEL_STACK_OFFSET),%rsp
6656+ pax_enter_kernel_user
6657 /*
6658 * No need to follow this irqs on/off section: the syscall
6659 * disabled irqs, here we enable it straight after entry:
6660@@ -135,7 +160,8 @@ ENTRY(ia32_sysenter_target)
6661 pushfq
6662 CFI_ADJUST_CFA_OFFSET 8
6663 /*CFI_REL_OFFSET rflags,0*/
6664- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
6665+ GET_THREAD_INFO(%r10)
6666+ movl TI_sysenter_return(%r10), %r10d
6667 CFI_REGISTER rip,r10
6668 pushq $__USER32_CS
6669 CFI_ADJUST_CFA_OFFSET 8
6670@@ -150,6 +176,12 @@ ENTRY(ia32_sysenter_target)
6671 SAVE_ARGS 0,0,1
6672 /* no need to do an access_ok check here because rbp has been
6673 32bit zero extended */
6674+
6675+#ifdef CONFIG_PAX_MEMORY_UDEREF
6676+ mov $PAX_USER_SHADOW_BASE,%r10
6677+ add %r10,%rbp
6678+#endif
6679+
6680 1: movl (%rbp),%ebp
6681 .section __ex_table,"a"
6682 .quad 1b,ia32_badarg
6683@@ -172,6 +204,7 @@ sysenter_dispatch:
6684 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6685 jnz sysexit_audit
6686 sysexit_from_sys_call:
6687+ pax_exit_kernel_user
6688 andl $~TS_COMPAT,TI_status(%r10)
6689 /* clear IF, that popfq doesn't enable interrupts early */
6690 andl $~0x200,EFLAGS-R11(%rsp)
6691@@ -200,6 +233,9 @@ sysexit_from_sys_call:
6692 movl %eax,%esi /* 2nd arg: syscall number */
6693 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
6694 call audit_syscall_entry
6695+
6696+ pax_erase_kstack
6697+
6698 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
6699 cmpq $(IA32_NR_syscalls-1),%rax
6700 ja ia32_badsys
6701@@ -252,6 +288,9 @@ sysenter_tracesys:
6702 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
6703 movq %rsp,%rdi /* &pt_regs -> arg1 */
6704 call syscall_trace_enter
6705+
6706+ pax_erase_kstack
6707+
6708 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6709 RESTORE_REST
6710 cmpq $(IA32_NR_syscalls-1),%rax
6711@@ -283,19 +322,24 @@ ENDPROC(ia32_sysenter_target)
6712 ENTRY(ia32_cstar_target)
6713 CFI_STARTPROC32 simple
6714 CFI_SIGNAL_FRAME
6715- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
6716+ CFI_DEF_CFA rsp,0
6717 CFI_REGISTER rip,rcx
6718 /*CFI_REGISTER rflags,r11*/
6719 SWAPGS_UNSAFE_STACK
6720 movl %esp,%r8d
6721 CFI_REGISTER rsp,r8
6722 movq PER_CPU_VAR(kernel_stack),%rsp
6723+
6724+#ifdef CONFIG_PAX_MEMORY_UDEREF
6725+ pax_enter_kernel_user
6726+#endif
6727+
6728 /*
6729 * No need to follow this irqs on/off section: the syscall
6730 * disabled irqs and here we enable it straight after entry:
6731 */
6732 ENABLE_INTERRUPTS(CLBR_NONE)
6733- SAVE_ARGS 8,1,1
6734+ SAVE_ARGS 8*6,1,1
6735 movl %eax,%eax /* zero extension */
6736 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
6737 movq %rcx,RIP-ARGOFFSET(%rsp)
6738@@ -311,6 +355,12 @@ ENTRY(ia32_cstar_target)
6739 /* no need to do an access_ok check here because r8 has been
6740 32bit zero extended */
6741 /* hardware stack frame is complete now */
6742+
6743+#ifdef CONFIG_PAX_MEMORY_UDEREF
6744+ mov $PAX_USER_SHADOW_BASE,%r10
6745+ add %r10,%r8
6746+#endif
6747+
6748 1: movl (%r8),%r9d
6749 .section __ex_table,"a"
6750 .quad 1b,ia32_badarg
6751@@ -333,6 +383,7 @@ cstar_dispatch:
6752 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6753 jnz sysretl_audit
6754 sysretl_from_sys_call:
6755+ pax_exit_kernel_user
6756 andl $~TS_COMPAT,TI_status(%r10)
6757 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
6758 movl RIP-ARGOFFSET(%rsp),%ecx
6759@@ -370,6 +421,9 @@ cstar_tracesys:
6760 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6761 movq %rsp,%rdi /* &pt_regs -> arg1 */
6762 call syscall_trace_enter
6763+
6764+ pax_erase_kstack
6765+
6766 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
6767 RESTORE_REST
6768 xchgl %ebp,%r9d
6769@@ -415,6 +469,7 @@ ENTRY(ia32_syscall)
6770 CFI_REL_OFFSET rip,RIP-RIP
6771 PARAVIRT_ADJUST_EXCEPTION_FRAME
6772 SWAPGS
6773+ pax_enter_kernel_user
6774 /*
6775 * No need to follow this irqs on/off section: the syscall
6776 * disabled irqs and here we enable it straight after entry:
6777@@ -448,6 +503,9 @@ ia32_tracesys:
6778 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6779 movq %rsp,%rdi /* &pt_regs -> arg1 */
6780 call syscall_trace_enter
6781+
6782+ pax_erase_kstack
6783+
6784 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6785 RESTORE_REST
6786 cmpq $(IA32_NR_syscalls-1),%rax
6787diff -urNp linux-2.6.32.44/arch/x86/ia32/ia32_signal.c linux-2.6.32.44/arch/x86/ia32/ia32_signal.c
6788--- linux-2.6.32.44/arch/x86/ia32/ia32_signal.c 2011-03-27 14:31:47.000000000 -0400
6789+++ linux-2.6.32.44/arch/x86/ia32/ia32_signal.c 2011-04-17 15:56:46.000000000 -0400
6790@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
6791 sp -= frame_size;
6792 /* Align the stack pointer according to the i386 ABI,
6793 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6794- sp = ((sp + 4) & -16ul) - 4;
6795+ sp = ((sp - 12) & -16ul) - 4;
6796 return (void __user *) sp;
6797 }
6798
6799@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
6800 * These are actually not used anymore, but left because some
6801 * gdb versions depend on them as a marker.
6802 */
6803- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6804+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6805 } put_user_catch(err);
6806
6807 if (err)
6808@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
6809 0xb8,
6810 __NR_ia32_rt_sigreturn,
6811 0x80cd,
6812- 0,
6813+ 0
6814 };
6815
6816 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6817@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
6818
6819 if (ka->sa.sa_flags & SA_RESTORER)
6820 restorer = ka->sa.sa_restorer;
6821+ else if (current->mm->context.vdso)
6822+ /* Return stub is in 32bit vsyscall page */
6823+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6824 else
6825- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6826- rt_sigreturn);
6827+ restorer = &frame->retcode;
6828 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6829
6830 /*
6831 * Not actually used anymore, but left because some gdb
6832 * versions need it.
6833 */
6834- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6835+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6836 } put_user_catch(err);
6837
6838 if (err)
6839diff -urNp linux-2.6.32.44/arch/x86/include/asm/alternative.h linux-2.6.32.44/arch/x86/include/asm/alternative.h
6840--- linux-2.6.32.44/arch/x86/include/asm/alternative.h 2011-03-27 14:31:47.000000000 -0400
6841+++ linux-2.6.32.44/arch/x86/include/asm/alternative.h 2011-04-17 15:56:46.000000000 -0400
6842@@ -85,7 +85,7 @@ static inline void alternatives_smp_swit
6843 " .byte 662b-661b\n" /* sourcelen */ \
6844 " .byte 664f-663f\n" /* replacementlen */ \
6845 ".previous\n" \
6846- ".section .altinstr_replacement, \"ax\"\n" \
6847+ ".section .altinstr_replacement, \"a\"\n" \
6848 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
6849 ".previous"
6850
6851diff -urNp linux-2.6.32.44/arch/x86/include/asm/apm.h linux-2.6.32.44/arch/x86/include/asm/apm.h
6852--- linux-2.6.32.44/arch/x86/include/asm/apm.h 2011-03-27 14:31:47.000000000 -0400
6853+++ linux-2.6.32.44/arch/x86/include/asm/apm.h 2011-04-17 15:56:46.000000000 -0400
6854@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
6855 __asm__ __volatile__(APM_DO_ZERO_SEGS
6856 "pushl %%edi\n\t"
6857 "pushl %%ebp\n\t"
6858- "lcall *%%cs:apm_bios_entry\n\t"
6859+ "lcall *%%ss:apm_bios_entry\n\t"
6860 "setc %%al\n\t"
6861 "popl %%ebp\n\t"
6862 "popl %%edi\n\t"
6863@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
6864 __asm__ __volatile__(APM_DO_ZERO_SEGS
6865 "pushl %%edi\n\t"
6866 "pushl %%ebp\n\t"
6867- "lcall *%%cs:apm_bios_entry\n\t"
6868+ "lcall *%%ss:apm_bios_entry\n\t"
6869 "setc %%bl\n\t"
6870 "popl %%ebp\n\t"
6871 "popl %%edi\n\t"
6872diff -urNp linux-2.6.32.44/arch/x86/include/asm/atomic_32.h linux-2.6.32.44/arch/x86/include/asm/atomic_32.h
6873--- linux-2.6.32.44/arch/x86/include/asm/atomic_32.h 2011-03-27 14:31:47.000000000 -0400
6874+++ linux-2.6.32.44/arch/x86/include/asm/atomic_32.h 2011-05-04 17:56:20.000000000 -0400
6875@@ -25,6 +25,17 @@ static inline int atomic_read(const atom
6876 }
6877
6878 /**
6879+ * atomic_read_unchecked - read atomic variable
6880+ * @v: pointer of type atomic_unchecked_t
6881+ *
6882+ * Atomically reads the value of @v.
6883+ */
6884+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6885+{
6886+ return v->counter;
6887+}
6888+
6889+/**
6890 * atomic_set - set atomic variable
6891 * @v: pointer of type atomic_t
6892 * @i: required value
6893@@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *
6894 }
6895
6896 /**
6897+ * atomic_set_unchecked - set atomic variable
6898+ * @v: pointer of type atomic_unchecked_t
6899+ * @i: required value
6900+ *
6901+ * Atomically sets the value of @v to @i.
6902+ */
6903+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6904+{
6905+ v->counter = i;
6906+}
6907+
6908+/**
6909 * atomic_add - add integer to atomic variable
6910 * @i: integer value to add
6911 * @v: pointer of type atomic_t
6912@@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *
6913 */
6914 static inline void atomic_add(int i, atomic_t *v)
6915 {
6916- asm volatile(LOCK_PREFIX "addl %1,%0"
6917+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6918+
6919+#ifdef CONFIG_PAX_REFCOUNT
6920+ "jno 0f\n"
6921+ LOCK_PREFIX "subl %1,%0\n"
6922+ "int $4\n0:\n"
6923+ _ASM_EXTABLE(0b, 0b)
6924+#endif
6925+
6926+ : "+m" (v->counter)
6927+ : "ir" (i));
6928+}
6929+
6930+/**
6931+ * atomic_add_unchecked - add integer to atomic variable
6932+ * @i: integer value to add
6933+ * @v: pointer of type atomic_unchecked_t
6934+ *
6935+ * Atomically adds @i to @v.
6936+ */
6937+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6938+{
6939+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6940 : "+m" (v->counter)
6941 : "ir" (i));
6942 }
6943@@ -59,7 +104,29 @@ static inline void atomic_add(int i, ato
6944 */
6945 static inline void atomic_sub(int i, atomic_t *v)
6946 {
6947- asm volatile(LOCK_PREFIX "subl %1,%0"
6948+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
6949+
6950+#ifdef CONFIG_PAX_REFCOUNT
6951+ "jno 0f\n"
6952+ LOCK_PREFIX "addl %1,%0\n"
6953+ "int $4\n0:\n"
6954+ _ASM_EXTABLE(0b, 0b)
6955+#endif
6956+
6957+ : "+m" (v->counter)
6958+ : "ir" (i));
6959+}
6960+
6961+/**
6962+ * atomic_sub_unchecked - subtract integer from atomic variable
6963+ * @i: integer value to subtract
6964+ * @v: pointer of type atomic_unchecked_t
6965+ *
6966+ * Atomically subtracts @i from @v.
6967+ */
6968+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
6969+{
6970+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
6971 : "+m" (v->counter)
6972 : "ir" (i));
6973 }
6974@@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(in
6975 {
6976 unsigned char c;
6977
6978- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
6979+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
6980+
6981+#ifdef CONFIG_PAX_REFCOUNT
6982+ "jno 0f\n"
6983+ LOCK_PREFIX "addl %2,%0\n"
6984+ "int $4\n0:\n"
6985+ _ASM_EXTABLE(0b, 0b)
6986+#endif
6987+
6988+ "sete %1\n"
6989 : "+m" (v->counter), "=qm" (c)
6990 : "ir" (i) : "memory");
6991 return c;
6992@@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(in
6993 */
6994 static inline void atomic_inc(atomic_t *v)
6995 {
6996- asm volatile(LOCK_PREFIX "incl %0"
6997+ asm volatile(LOCK_PREFIX "incl %0\n"
6998+
6999+#ifdef CONFIG_PAX_REFCOUNT
7000+ "jno 0f\n"
7001+ LOCK_PREFIX "decl %0\n"
7002+ "int $4\n0:\n"
7003+ _ASM_EXTABLE(0b, 0b)
7004+#endif
7005+
7006+ : "+m" (v->counter));
7007+}
7008+
7009+/**
7010+ * atomic_inc_unchecked - increment atomic variable
7011+ * @v: pointer of type atomic_unchecked_t
7012+ *
7013+ * Atomically increments @v by 1.
7014+ */
7015+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7016+{
7017+ asm volatile(LOCK_PREFIX "incl %0\n"
7018 : "+m" (v->counter));
7019 }
7020
7021@@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *
7022 */
7023 static inline void atomic_dec(atomic_t *v)
7024 {
7025- asm volatile(LOCK_PREFIX "decl %0"
7026+ asm volatile(LOCK_PREFIX "decl %0\n"
7027+
7028+#ifdef CONFIG_PAX_REFCOUNT
7029+ "jno 0f\n"
7030+ LOCK_PREFIX "incl %0\n"
7031+ "int $4\n0:\n"
7032+ _ASM_EXTABLE(0b, 0b)
7033+#endif
7034+
7035+ : "+m" (v->counter));
7036+}
7037+
7038+/**
7039+ * atomic_dec_unchecked - decrement atomic variable
7040+ * @v: pointer of type atomic_unchecked_t
7041+ *
7042+ * Atomically decrements @v by 1.
7043+ */
7044+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7045+{
7046+ asm volatile(LOCK_PREFIX "decl %0\n"
7047 : "+m" (v->counter));
7048 }
7049
7050@@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(at
7051 {
7052 unsigned char c;
7053
7054- asm volatile(LOCK_PREFIX "decl %0; sete %1"
7055+ asm volatile(LOCK_PREFIX "decl %0\n"
7056+
7057+#ifdef CONFIG_PAX_REFCOUNT
7058+ "jno 0f\n"
7059+ LOCK_PREFIX "incl %0\n"
7060+ "int $4\n0:\n"
7061+ _ASM_EXTABLE(0b, 0b)
7062+#endif
7063+
7064+ "sete %1\n"
7065 : "+m" (v->counter), "=qm" (c)
7066 : : "memory");
7067 return c != 0;
7068@@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(at
7069 {
7070 unsigned char c;
7071
7072- asm volatile(LOCK_PREFIX "incl %0; sete %1"
7073+ asm volatile(LOCK_PREFIX "incl %0\n"
7074+
7075+#ifdef CONFIG_PAX_REFCOUNT
7076+ "jno 0f\n"
7077+ LOCK_PREFIX "decl %0\n"
7078+ "into\n0:\n"
7079+ _ASM_EXTABLE(0b, 0b)
7080+#endif
7081+
7082+ "sete %1\n"
7083+ : "+m" (v->counter), "=qm" (c)
7084+ : : "memory");
7085+ return c != 0;
7086+}
7087+
7088+/**
7089+ * atomic_inc_and_test_unchecked - increment and test
7090+ * @v: pointer of type atomic_unchecked_t
7091+ *
7092+ * Atomically increments @v by 1
7093+ * and returns true if the result is zero, or false for all
7094+ * other cases.
7095+ */
7096+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7097+{
7098+ unsigned char c;
7099+
7100+ asm volatile(LOCK_PREFIX "incl %0\n"
7101+ "sete %1\n"
7102 : "+m" (v->counter), "=qm" (c)
7103 : : "memory");
7104 return c != 0;
7105@@ -156,7 +309,16 @@ static inline int atomic_add_negative(in
7106 {
7107 unsigned char c;
7108
7109- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7110+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
7111+
7112+#ifdef CONFIG_PAX_REFCOUNT
7113+ "jno 0f\n"
7114+ LOCK_PREFIX "subl %2,%0\n"
7115+ "int $4\n0:\n"
7116+ _ASM_EXTABLE(0b, 0b)
7117+#endif
7118+
7119+ "sets %1\n"
7120 : "+m" (v->counter), "=qm" (c)
7121 : "ir" (i) : "memory");
7122 return c;
7123@@ -179,6 +341,46 @@ static inline int atomic_add_return(int
7124 #endif
7125 /* Modern 486+ processor */
7126 __i = i;
7127+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7128+
7129+#ifdef CONFIG_PAX_REFCOUNT
7130+ "jno 0f\n"
7131+ "movl %0, %1\n"
7132+ "int $4\n0:\n"
7133+ _ASM_EXTABLE(0b, 0b)
7134+#endif
7135+
7136+ : "+r" (i), "+m" (v->counter)
7137+ : : "memory");
7138+ return i + __i;
7139+
7140+#ifdef CONFIG_M386
7141+no_xadd: /* Legacy 386 processor */
7142+ local_irq_save(flags);
7143+ __i = atomic_read(v);
7144+ atomic_set(v, i + __i);
7145+ local_irq_restore(flags);
7146+ return i + __i;
7147+#endif
7148+}
7149+
7150+/**
7151+ * atomic_add_return_unchecked - add integer and return
7152+ * @v: pointer of type atomic_unchecked_t
7153+ * @i: integer value to add
7154+ *
7155+ * Atomically adds @i to @v and returns @i + @v
7156+ */
7157+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7158+{
7159+ int __i;
7160+#ifdef CONFIG_M386
7161+ unsigned long flags;
7162+ if (unlikely(boot_cpu_data.x86 <= 3))
7163+ goto no_xadd;
7164+#endif
7165+ /* Modern 486+ processor */
7166+ __i = i;
7167 asm volatile(LOCK_PREFIX "xaddl %0, %1"
7168 : "+r" (i), "+m" (v->counter)
7169 : : "memory");
7170@@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_
7171 return cmpxchg(&v->counter, old, new);
7172 }
7173
7174+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7175+{
7176+ return cmpxchg(&v->counter, old, new);
7177+}
7178+
7179 static inline int atomic_xchg(atomic_t *v, int new)
7180 {
7181 return xchg(&v->counter, new);
7182 }
7183
7184+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7185+{
7186+ return xchg(&v->counter, new);
7187+}
7188+
7189 /**
7190 * atomic_add_unless - add unless the number is already a given value
7191 * @v: pointer of type atomic_t
7192@@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *
7193 */
7194 static inline int atomic_add_unless(atomic_t *v, int a, int u)
7195 {
7196- int c, old;
7197+ int c, old, new;
7198 c = atomic_read(v);
7199 for (;;) {
7200- if (unlikely(c == (u)))
7201+ if (unlikely(c == u))
7202 break;
7203- old = atomic_cmpxchg((v), c, c + (a));
7204+
7205+ asm volatile("addl %2,%0\n"
7206+
7207+#ifdef CONFIG_PAX_REFCOUNT
7208+ "jno 0f\n"
7209+ "subl %2,%0\n"
7210+ "int $4\n0:\n"
7211+ _ASM_EXTABLE(0b, 0b)
7212+#endif
7213+
7214+ : "=r" (new)
7215+ : "0" (c), "ir" (a));
7216+
7217+ old = atomic_cmpxchg(v, c, new);
7218 if (likely(old == c))
7219 break;
7220 c = old;
7221 }
7222- return c != (u);
7223+ return c != u;
7224 }
7225
7226 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
7227
7228 #define atomic_inc_return(v) (atomic_add_return(1, v))
7229+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7230+{
7231+ return atomic_add_return_unchecked(1, v);
7232+}
7233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7234
7235 /* These are x86-specific, used by some header files */
7236@@ -266,9 +495,18 @@ typedef struct {
7237 u64 __aligned(8) counter;
7238 } atomic64_t;
7239
7240+#ifdef CONFIG_PAX_REFCOUNT
7241+typedef struct {
7242+ u64 __aligned(8) counter;
7243+} atomic64_unchecked_t;
7244+#else
7245+typedef atomic64_t atomic64_unchecked_t;
7246+#endif
7247+
7248 #define ATOMIC64_INIT(val) { (val) }
7249
7250 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
7251+extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
7252
7253 /**
7254 * atomic64_xchg - xchg atomic64 variable
7255@@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *
7256 * the old value.
7257 */
7258 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
7259+extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
7260
7261 /**
7262 * atomic64_set - set atomic64 variable
7263@@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr
7264 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
7265
7266 /**
7267+ * atomic64_unchecked_set - set atomic64 variable
7268+ * @ptr: pointer to type atomic64_unchecked_t
7269+ * @new_val: value to assign
7270+ *
7271+ * Atomically sets the value of @ptr to @new_val.
7272+ */
7273+extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
7274+
7275+/**
7276 * atomic64_read - read atomic64 variable
7277 * @ptr: pointer to type atomic64_t
7278 *
7279@@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64
7280 return res;
7281 }
7282
7283-extern u64 atomic64_read(atomic64_t *ptr);
7284+/**
7285+ * atomic64_read_unchecked - read atomic64 variable
7286+ * @ptr: pointer to type atomic64_unchecked_t
7287+ *
7288+ * Atomically reads the value of @ptr and returns it.
7289+ */
7290+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
7291+{
7292+ u64 res;
7293+
7294+ /*
7295+ * Note, we inline this atomic64_unchecked_t primitive because
7296+ * it only clobbers EAX/EDX and leaves the others
7297+ * untouched. We also (somewhat subtly) rely on the
7298+ * fact that cmpxchg8b returns the current 64-bit value
7299+ * of the memory location we are touching:
7300+ */
7301+ asm volatile(
7302+ "mov %%ebx, %%eax\n\t"
7303+ "mov %%ecx, %%edx\n\t"
7304+ LOCK_PREFIX "cmpxchg8b %1\n"
7305+ : "=&A" (res)
7306+ : "m" (*ptr)
7307+ );
7308+
7309+ return res;
7310+}
7311
7312 /**
7313 * atomic64_add_return - add and return
7314@@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta
7315 * Other variants with different arithmetic operators:
7316 */
7317 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
7318+extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7319 extern u64 atomic64_inc_return(atomic64_t *ptr);
7320+extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
7321 extern u64 atomic64_dec_return(atomic64_t *ptr);
7322+extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
7323
7324 /**
7325 * atomic64_add - add integer to atomic64 variable
7326@@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_
7327 extern void atomic64_add(u64 delta, atomic64_t *ptr);
7328
7329 /**
7330+ * atomic64_add_unchecked - add integer to atomic64 variable
7331+ * @delta: integer value to add
7332+ * @ptr: pointer to type atomic64_unchecked_t
7333+ *
7334+ * Atomically adds @delta to @ptr.
7335+ */
7336+extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7337+
7338+/**
7339 * atomic64_sub - subtract the atomic64 variable
7340 * @delta: integer value to subtract
7341 * @ptr: pointer to type atomic64_t
7342@@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atom
7343 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
7344
7345 /**
7346+ * atomic64_sub_unchecked - subtract the atomic64 variable
7347+ * @delta: integer value to subtract
7348+ * @ptr: pointer to type atomic64_unchecked_t
7349+ *
7350+ * Atomically subtracts @delta from @ptr.
7351+ */
7352+extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7353+
7354+/**
7355 * atomic64_sub_and_test - subtract value from variable and test result
7356 * @delta: integer value to subtract
7357 * @ptr: pointer to type atomic64_t
7358@@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 del
7359 extern void atomic64_inc(atomic64_t *ptr);
7360
7361 /**
7362+ * atomic64_inc_unchecked - increment atomic64 variable
7363+ * @ptr: pointer to type atomic64_unchecked_t
7364+ *
7365+ * Atomically increments @ptr by 1.
7366+ */
7367+extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
7368+
7369+/**
7370 * atomic64_dec - decrement atomic64 variable
7371 * @ptr: pointer to type atomic64_t
7372 *
7373@@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr
7374 extern void atomic64_dec(atomic64_t *ptr);
7375
7376 /**
7377+ * atomic64_dec_unchecked - decrement atomic64 variable
7378+ * @ptr: pointer to type atomic64_unchecked_t
7379+ *
7380+ * Atomically decrements @ptr by 1.
7381+ */
7382+extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
7383+
7384+/**
7385 * atomic64_dec_and_test - decrement and test
7386 * @ptr: pointer to type atomic64_t
7387 *
7388diff -urNp linux-2.6.32.44/arch/x86/include/asm/atomic_64.h linux-2.6.32.44/arch/x86/include/asm/atomic_64.h
7389--- linux-2.6.32.44/arch/x86/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
7390+++ linux-2.6.32.44/arch/x86/include/asm/atomic_64.h 2011-05-04 18:35:31.000000000 -0400
7391@@ -24,6 +24,17 @@ static inline int atomic_read(const atom
7392 }
7393
7394 /**
7395+ * atomic_read_unchecked - read atomic variable
7396+ * @v: pointer of type atomic_unchecked_t
7397+ *
7398+ * Atomically reads the value of @v.
7399+ */
7400+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7401+{
7402+ return v->counter;
7403+}
7404+
7405+/**
7406 * atomic_set - set atomic variable
7407 * @v: pointer of type atomic_t
7408 * @i: required value
7409@@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *
7410 }
7411
7412 /**
7413+ * atomic_set_unchecked - set atomic variable
7414+ * @v: pointer of type atomic_unchecked_t
7415+ * @i: required value
7416+ *
7417+ * Atomically sets the value of @v to @i.
7418+ */
7419+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7420+{
7421+ v->counter = i;
7422+}
7423+
7424+/**
7425 * atomic_add - add integer to atomic variable
7426 * @i: integer value to add
7427 * @v: pointer of type atomic_t
7428@@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *
7429 */
7430 static inline void atomic_add(int i, atomic_t *v)
7431 {
7432- asm volatile(LOCK_PREFIX "addl %1,%0"
7433+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7434+
7435+#ifdef CONFIG_PAX_REFCOUNT
7436+ "jno 0f\n"
7437+ LOCK_PREFIX "subl %1,%0\n"
7438+ "int $4\n0:\n"
7439+ _ASM_EXTABLE(0b, 0b)
7440+#endif
7441+
7442+ : "=m" (v->counter)
7443+ : "ir" (i), "m" (v->counter));
7444+}
7445+
7446+/**
7447+ * atomic_add_unchecked - add integer to atomic variable
7448+ * @i: integer value to add
7449+ * @v: pointer of type atomic_unchecked_t
7450+ *
7451+ * Atomically adds @i to @v.
7452+ */
7453+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7454+{
7455+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7456 : "=m" (v->counter)
7457 : "ir" (i), "m" (v->counter));
7458 }
7459@@ -58,7 +103,29 @@ static inline void atomic_add(int i, ato
7460 */
7461 static inline void atomic_sub(int i, atomic_t *v)
7462 {
7463- asm volatile(LOCK_PREFIX "subl %1,%0"
7464+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7465+
7466+#ifdef CONFIG_PAX_REFCOUNT
7467+ "jno 0f\n"
7468+ LOCK_PREFIX "addl %1,%0\n"
7469+ "int $4\n0:\n"
7470+ _ASM_EXTABLE(0b, 0b)
7471+#endif
7472+
7473+ : "=m" (v->counter)
7474+ : "ir" (i), "m" (v->counter));
7475+}
7476+
7477+/**
7478+ * atomic_sub_unchecked - subtract the atomic variable
7479+ * @i: integer value to subtract
7480+ * @v: pointer of type atomic_unchecked_t
7481+ *
7482+ * Atomically subtracts @i from @v.
7483+ */
7484+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7485+{
7486+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7487 : "=m" (v->counter)
7488 : "ir" (i), "m" (v->counter));
7489 }
7490@@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(in
7491 {
7492 unsigned char c;
7493
7494- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7495+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
7496+
7497+#ifdef CONFIG_PAX_REFCOUNT
7498+ "jno 0f\n"
7499+ LOCK_PREFIX "addl %2,%0\n"
7500+ "int $4\n0:\n"
7501+ _ASM_EXTABLE(0b, 0b)
7502+#endif
7503+
7504+ "sete %1\n"
7505 : "=m" (v->counter), "=qm" (c)
7506 : "ir" (i), "m" (v->counter) : "memory");
7507 return c;
7508@@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(in
7509 */
7510 static inline void atomic_inc(atomic_t *v)
7511 {
7512- asm volatile(LOCK_PREFIX "incl %0"
7513+ asm volatile(LOCK_PREFIX "incl %0\n"
7514+
7515+#ifdef CONFIG_PAX_REFCOUNT
7516+ "jno 0f\n"
7517+ LOCK_PREFIX "decl %0\n"
7518+ "int $4\n0:\n"
7519+ _ASM_EXTABLE(0b, 0b)
7520+#endif
7521+
7522+ : "=m" (v->counter)
7523+ : "m" (v->counter));
7524+}
7525+
7526+/**
7527+ * atomic_inc_unchecked - increment atomic variable
7528+ * @v: pointer of type atomic_unchecked_t
7529+ *
7530+ * Atomically increments @v by 1.
7531+ */
7532+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7533+{
7534+ asm volatile(LOCK_PREFIX "incl %0\n"
7535 : "=m" (v->counter)
7536 : "m" (v->counter));
7537 }
7538@@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *
7539 */
7540 static inline void atomic_dec(atomic_t *v)
7541 {
7542- asm volatile(LOCK_PREFIX "decl %0"
7543+ asm volatile(LOCK_PREFIX "decl %0\n"
7544+
7545+#ifdef CONFIG_PAX_REFCOUNT
7546+ "jno 0f\n"
7547+ LOCK_PREFIX "incl %0\n"
7548+ "int $4\n0:\n"
7549+ _ASM_EXTABLE(0b, 0b)
7550+#endif
7551+
7552+ : "=m" (v->counter)
7553+ : "m" (v->counter));
7554+}
7555+
7556+/**
7557+ * atomic_dec_unchecked - decrement atomic variable
7558+ * @v: pointer of type atomic_unchecked_t
7559+ *
7560+ * Atomically decrements @v by 1.
7561+ */
7562+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7563+{
7564+ asm volatile(LOCK_PREFIX "decl %0\n"
7565 : "=m" (v->counter)
7566 : "m" (v->counter));
7567 }
7568@@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(at
7569 {
7570 unsigned char c;
7571
7572- asm volatile(LOCK_PREFIX "decl %0; sete %1"
7573+ asm volatile(LOCK_PREFIX "decl %0\n"
7574+
7575+#ifdef CONFIG_PAX_REFCOUNT
7576+ "jno 0f\n"
7577+ LOCK_PREFIX "incl %0\n"
7578+ "int $4\n0:\n"
7579+ _ASM_EXTABLE(0b, 0b)
7580+#endif
7581+
7582+ "sete %1\n"
7583 : "=m" (v->counter), "=qm" (c)
7584 : "m" (v->counter) : "memory");
7585 return c != 0;
7586@@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(at
7587 {
7588 unsigned char c;
7589
7590- asm volatile(LOCK_PREFIX "incl %0; sete %1"
7591+ asm volatile(LOCK_PREFIX "incl %0\n"
7592+
7593+#ifdef CONFIG_PAX_REFCOUNT
7594+ "jno 0f\n"
7595+ LOCK_PREFIX "decl %0\n"
7596+ "int $4\n0:\n"
7597+ _ASM_EXTABLE(0b, 0b)
7598+#endif
7599+
7600+ "sete %1\n"
7601+ : "=m" (v->counter), "=qm" (c)
7602+ : "m" (v->counter) : "memory");
7603+ return c != 0;
7604+}
7605+
7606+/**
7607+ * atomic_inc_and_test_unchecked - increment and test
7608+ * @v: pointer of type atomic_unchecked_t
7609+ *
7610+ * Atomically increments @v by 1
7611+ * and returns true if the result is zero, or false for all
7612+ * other cases.
7613+ */
7614+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7615+{
7616+ unsigned char c;
7617+
7618+ asm volatile(LOCK_PREFIX "incl %0\n"
7619+ "sete %1\n"
7620 : "=m" (v->counter), "=qm" (c)
7621 : "m" (v->counter) : "memory");
7622 return c != 0;
7623@@ -157,7 +312,16 @@ static inline int atomic_add_negative(in
7624 {
7625 unsigned char c;
7626
7627- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7628+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
7629+
7630+#ifdef CONFIG_PAX_REFCOUNT
7631+ "jno 0f\n"
7632+ LOCK_PREFIX "subl %2,%0\n"
7633+ "int $4\n0:\n"
7634+ _ASM_EXTABLE(0b, 0b)
7635+#endif
7636+
7637+ "sets %1\n"
7638 : "=m" (v->counter), "=qm" (c)
7639 : "ir" (i), "m" (v->counter) : "memory");
7640 return c;
7641@@ -173,7 +337,31 @@ static inline int atomic_add_negative(in
7642 static inline int atomic_add_return(int i, atomic_t *v)
7643 {
7644 int __i = i;
7645- asm volatile(LOCK_PREFIX "xaddl %0, %1"
7646+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7647+
7648+#ifdef CONFIG_PAX_REFCOUNT
7649+ "jno 0f\n"
7650+ "movl %0, %1\n"
7651+ "int $4\n0:\n"
7652+ _ASM_EXTABLE(0b, 0b)
7653+#endif
7654+
7655+ : "+r" (i), "+m" (v->counter)
7656+ : : "memory");
7657+ return i + __i;
7658+}
7659+
7660+/**
7661+ * atomic_add_return_unchecked - add and return
7662+ * @i: integer value to add
7663+ * @v: pointer of type atomic_unchecked_t
7664+ *
7665+ * Atomically adds @i to @v and returns @i + @v
7666+ */
7667+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7668+{
7669+ int __i = i;
7670+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7671 : "+r" (i), "+m" (v->counter)
7672 : : "memory");
7673 return i + __i;
7674@@ -185,6 +373,10 @@ static inline int atomic_sub_return(int
7675 }
7676
7677 #define atomic_inc_return(v) (atomic_add_return(1, v))
7678+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7679+{
7680+ return atomic_add_return_unchecked(1, v);
7681+}
7682 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7683
7684 /* The 64-bit atomic type */
7685@@ -204,6 +396,18 @@ static inline long atomic64_read(const a
7686 }
7687
7688 /**
7689+ * atomic64_read_unchecked - read atomic64 variable
7690+ * @v: pointer of type atomic64_unchecked_t
7691+ *
7692+ * Atomically reads the value of @v.
7693+ * Doesn't imply a read memory barrier.
7694+ */
7695+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7696+{
7697+ return v->counter;
7698+}
7699+
7700+/**
7701 * atomic64_set - set atomic64 variable
7702 * @v: pointer to type atomic64_t
7703 * @i: required value
7704@@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64
7705 }
7706
7707 /**
7708+ * atomic64_set_unchecked - set atomic64 variable
7709+ * @v: pointer to type atomic64_unchecked_t
7710+ * @i: required value
7711+ *
7712+ * Atomically sets the value of @v to @i.
7713+ */
7714+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7715+{
7716+ v->counter = i;
7717+}
7718+
7719+/**
7720 * atomic64_add - add integer to atomic64 variable
7721 * @i: integer value to add
7722 * @v: pointer to type atomic64_t
7723@@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64
7724 */
7725 static inline void atomic64_add(long i, atomic64_t *v)
7726 {
7727+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
7728+
7729+#ifdef CONFIG_PAX_REFCOUNT
7730+ "jno 0f\n"
7731+ LOCK_PREFIX "subq %1,%0\n"
7732+ "int $4\n0:\n"
7733+ _ASM_EXTABLE(0b, 0b)
7734+#endif
7735+
7736+ : "=m" (v->counter)
7737+ : "er" (i), "m" (v->counter));
7738+}
7739+
7740+/**
7741+ * atomic64_add_unchecked - add integer to atomic64 variable
7742+ * @i: integer value to add
7743+ * @v: pointer to type atomic64_unchecked_t
7744+ *
7745+ * Atomically adds @i to @v.
7746+ */
7747+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
7748+{
7749 asm volatile(LOCK_PREFIX "addq %1,%0"
7750 : "=m" (v->counter)
7751 : "er" (i), "m" (v->counter));
7752@@ -238,7 +476,15 @@ static inline void atomic64_add(long i,
7753 */
7754 static inline void atomic64_sub(long i, atomic64_t *v)
7755 {
7756- asm volatile(LOCK_PREFIX "subq %1,%0"
7757+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
7758+
7759+#ifdef CONFIG_PAX_REFCOUNT
7760+ "jno 0f\n"
7761+ LOCK_PREFIX "addq %1,%0\n"
7762+ "int $4\n0:\n"
7763+ _ASM_EXTABLE(0b, 0b)
7764+#endif
7765+
7766 : "=m" (v->counter)
7767 : "er" (i), "m" (v->counter));
7768 }
7769@@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(
7770 {
7771 unsigned char c;
7772
7773- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
7774+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
7775+
7776+#ifdef CONFIG_PAX_REFCOUNT
7777+ "jno 0f\n"
7778+ LOCK_PREFIX "addq %2,%0\n"
7779+ "int $4\n0:\n"
7780+ _ASM_EXTABLE(0b, 0b)
7781+#endif
7782+
7783+ "sete %1\n"
7784 : "=m" (v->counter), "=qm" (c)
7785 : "er" (i), "m" (v->counter) : "memory");
7786 return c;
7787@@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(
7788 */
7789 static inline void atomic64_inc(atomic64_t *v)
7790 {
7791+ asm volatile(LOCK_PREFIX "incq %0\n"
7792+
7793+#ifdef CONFIG_PAX_REFCOUNT
7794+ "jno 0f\n"
7795+ LOCK_PREFIX "decq %0\n"
7796+ "int $4\n0:\n"
7797+ _ASM_EXTABLE(0b, 0b)
7798+#endif
7799+
7800+ : "=m" (v->counter)
7801+ : "m" (v->counter));
7802+}
7803+
7804+/**
7805+ * atomic64_inc_unchecked - increment atomic64 variable
7806+ * @v: pointer to type atomic64_unchecked_t
7807+ *
7808+ * Atomically increments @v by 1.
7809+ */
7810+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7811+{
7812 asm volatile(LOCK_PREFIX "incq %0"
7813 : "=m" (v->counter)
7814 : "m" (v->counter));
7815@@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64
7816 */
7817 static inline void atomic64_dec(atomic64_t *v)
7818 {
7819- asm volatile(LOCK_PREFIX "decq %0"
7820+ asm volatile(LOCK_PREFIX "decq %0\n"
7821+
7822+#ifdef CONFIG_PAX_REFCOUNT
7823+ "jno 0f\n"
7824+ LOCK_PREFIX "incq %0\n"
7825+ "int $4\n0:\n"
7826+ _ASM_EXTABLE(0b, 0b)
7827+#endif
7828+
7829+ : "=m" (v->counter)
7830+ : "m" (v->counter));
7831+}
7832+
7833+/**
7834+ * atomic64_dec_unchecked - decrement atomic64 variable
7835+ * @v: pointer to type atomic64_t
7836+ *
7837+ * Atomically decrements @v by 1.
7838+ */
7839+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7840+{
7841+ asm volatile(LOCK_PREFIX "decq %0\n"
7842 : "=m" (v->counter)
7843 : "m" (v->counter));
7844 }
7845@@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(
7846 {
7847 unsigned char c;
7848
7849- asm volatile(LOCK_PREFIX "decq %0; sete %1"
7850+ asm volatile(LOCK_PREFIX "decq %0\n"
7851+
7852+#ifdef CONFIG_PAX_REFCOUNT
7853+ "jno 0f\n"
7854+ LOCK_PREFIX "incq %0\n"
7855+ "int $4\n0:\n"
7856+ _ASM_EXTABLE(0b, 0b)
7857+#endif
7858+
7859+ "sete %1\n"
7860 : "=m" (v->counter), "=qm" (c)
7861 : "m" (v->counter) : "memory");
7862 return c != 0;
7863@@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(
7864 {
7865 unsigned char c;
7866
7867- asm volatile(LOCK_PREFIX "incq %0; sete %1"
7868+ asm volatile(LOCK_PREFIX "incq %0\n"
7869+
7870+#ifdef CONFIG_PAX_REFCOUNT
7871+ "jno 0f\n"
7872+ LOCK_PREFIX "decq %0\n"
7873+ "int $4\n0:\n"
7874+ _ASM_EXTABLE(0b, 0b)
7875+#endif
7876+
7877+ "sete %1\n"
7878 : "=m" (v->counter), "=qm" (c)
7879 : "m" (v->counter) : "memory");
7880 return c != 0;
7881@@ -337,7 +652,16 @@ static inline int atomic64_add_negative(
7882 {
7883 unsigned char c;
7884
7885- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
7886+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
7887+
7888+#ifdef CONFIG_PAX_REFCOUNT
7889+ "jno 0f\n"
7890+ LOCK_PREFIX "subq %2,%0\n"
7891+ "int $4\n0:\n"
7892+ _ASM_EXTABLE(0b, 0b)
7893+#endif
7894+
7895+ "sets %1\n"
7896 : "=m" (v->counter), "=qm" (c)
7897 : "er" (i), "m" (v->counter) : "memory");
7898 return c;
7899@@ -353,7 +677,31 @@ static inline int atomic64_add_negative(
7900 static inline long atomic64_add_return(long i, atomic64_t *v)
7901 {
7902 long __i = i;
7903- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
7904+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
7905+
7906+#ifdef CONFIG_PAX_REFCOUNT
7907+ "jno 0f\n"
7908+ "movq %0, %1\n"
7909+ "int $4\n0:\n"
7910+ _ASM_EXTABLE(0b, 0b)
7911+#endif
7912+
7913+ : "+r" (i), "+m" (v->counter)
7914+ : : "memory");
7915+ return i + __i;
7916+}
7917+
7918+/**
7919+ * atomic64_add_return_unchecked - add and return
7920+ * @i: integer value to add
7921+ * @v: pointer to type atomic64_unchecked_t
7922+ *
7923+ * Atomically adds @i to @v and returns @i + @v
7924+ */
7925+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7926+{
7927+ long __i = i;
7928+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
7929 : "+r" (i), "+m" (v->counter)
7930 : : "memory");
7931 return i + __i;
7932@@ -365,6 +713,10 @@ static inline long atomic64_sub_return(l
7933 }
7934
7935 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
7936+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7937+{
7938+ return atomic64_add_return_unchecked(1, v);
7939+}
7940 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
7941
7942 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7943@@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atom
7944 return cmpxchg(&v->counter, old, new);
7945 }
7946
7947+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
7948+{
7949+ return cmpxchg(&v->counter, old, new);
7950+}
7951+
7952 static inline long atomic64_xchg(atomic64_t *v, long new)
7953 {
7954 return xchg(&v->counter, new);
7955 }
7956
7957+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7958+{
7959+ return xchg(&v->counter, new);
7960+}
7961+
7962 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
7963 {
7964 return cmpxchg(&v->counter, old, new);
7965 }
7966
7967+static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7968+{
7969+ return cmpxchg(&v->counter, old, new);
7970+}
7971+
7972 static inline long atomic_xchg(atomic_t *v, int new)
7973 {
7974 return xchg(&v->counter, new);
7975 }
7976
7977+static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7978+{
7979+ return xchg(&v->counter, new);
7980+}
7981+
7982 /**
7983 * atomic_add_unless - add unless the number is a given value
7984 * @v: pointer of type atomic_t
7985@@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t
7986 */
7987 static inline int atomic_add_unless(atomic_t *v, int a, int u)
7988 {
7989- int c, old;
7990+ int c, old, new;
7991 c = atomic_read(v);
7992 for (;;) {
7993- if (unlikely(c == (u)))
7994+ if (unlikely(c == u))
7995 break;
7996- old = atomic_cmpxchg((v), c, c + (a));
7997+
7998+ asm volatile("addl %2,%0\n"
7999+
8000+#ifdef CONFIG_PAX_REFCOUNT
8001+ "jno 0f\n"
8002+ "subl %2,%0\n"
8003+ "int $4\n0:\n"
8004+ _ASM_EXTABLE(0b, 0b)
8005+#endif
8006+
8007+ : "=r" (new)
8008+ : "0" (c), "ir" (a));
8009+
8010+ old = atomic_cmpxchg(v, c, new);
8011 if (likely(old == c))
8012 break;
8013 c = old;
8014 }
8015- return c != (u);
8016+ return c != u;
8017 }
8018
8019 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8020@@ -424,17 +809,30 @@ static inline int atomic_add_unless(atom
8021 */
8022 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8023 {
8024- long c, old;
8025+ long c, old, new;
8026 c = atomic64_read(v);
8027 for (;;) {
8028- if (unlikely(c == (u)))
8029+ if (unlikely(c == u))
8030 break;
8031- old = atomic64_cmpxchg((v), c, c + (a));
8032+
8033+ asm volatile("addq %2,%0\n"
8034+
8035+#ifdef CONFIG_PAX_REFCOUNT
8036+ "jno 0f\n"
8037+ "subq %2,%0\n"
8038+ "int $4\n0:\n"
8039+ _ASM_EXTABLE(0b, 0b)
8040+#endif
8041+
8042+ : "=r" (new)
8043+ : "0" (c), "er" (a));
8044+
8045+ old = atomic64_cmpxchg(v, c, new);
8046 if (likely(old == c))
8047 break;
8048 c = old;
8049 }
8050- return c != (u);
8051+ return c != u;
8052 }
8053
8054 /**
8055diff -urNp linux-2.6.32.44/arch/x86/include/asm/bitops.h linux-2.6.32.44/arch/x86/include/asm/bitops.h
8056--- linux-2.6.32.44/arch/x86/include/asm/bitops.h 2011-03-27 14:31:47.000000000 -0400
8057+++ linux-2.6.32.44/arch/x86/include/asm/bitops.h 2011-04-17 15:56:46.000000000 -0400
8058@@ -38,7 +38,7 @@
8059 * a mask operation on a byte.
8060 */
8061 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8062-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8063+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8064 #define CONST_MASK(nr) (1 << ((nr) & 7))
8065
8066 /**
8067diff -urNp linux-2.6.32.44/arch/x86/include/asm/boot.h linux-2.6.32.44/arch/x86/include/asm/boot.h
8068--- linux-2.6.32.44/arch/x86/include/asm/boot.h 2011-03-27 14:31:47.000000000 -0400
8069+++ linux-2.6.32.44/arch/x86/include/asm/boot.h 2011-04-17 15:56:46.000000000 -0400
8070@@ -11,10 +11,15 @@
8071 #include <asm/pgtable_types.h>
8072
8073 /* Physical address where kernel should be loaded. */
8074-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8075+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8076 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8077 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8078
8079+#ifndef __ASSEMBLY__
8080+extern unsigned char __LOAD_PHYSICAL_ADDR[];
8081+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8082+#endif
8083+
8084 /* Minimum kernel alignment, as a power of two */
8085 #ifdef CONFIG_X86_64
8086 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8087diff -urNp linux-2.6.32.44/arch/x86/include/asm/cacheflush.h linux-2.6.32.44/arch/x86/include/asm/cacheflush.h
8088--- linux-2.6.32.44/arch/x86/include/asm/cacheflush.h 2011-03-27 14:31:47.000000000 -0400
8089+++ linux-2.6.32.44/arch/x86/include/asm/cacheflush.h 2011-04-17 15:56:46.000000000 -0400
8090@@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
8091 static inline unsigned long get_page_memtype(struct page *pg)
8092 {
8093 if (!PageUncached(pg) && !PageWC(pg))
8094- return -1;
8095+ return ~0UL;
8096 else if (!PageUncached(pg) && PageWC(pg))
8097 return _PAGE_CACHE_WC;
8098 else if (PageUncached(pg) && !PageWC(pg))
8099@@ -85,7 +85,7 @@ static inline void set_page_memtype(stru
8100 SetPageWC(pg);
8101 break;
8102 default:
8103- case -1:
8104+ case ~0UL:
8105 ClearPageUncached(pg);
8106 ClearPageWC(pg);
8107 break;
8108diff -urNp linux-2.6.32.44/arch/x86/include/asm/cache.h linux-2.6.32.44/arch/x86/include/asm/cache.h
8109--- linux-2.6.32.44/arch/x86/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
8110+++ linux-2.6.32.44/arch/x86/include/asm/cache.h 2011-07-06 19:53:33.000000000 -0400
8111@@ -5,9 +5,10 @@
8112
8113 /* L1 cache line size */
8114 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8115-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8116+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8117
8118 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
8119+#define __read_only __attribute__((__section__(".data.read_only")))
8120
8121 #ifdef CONFIG_X86_VSMP
8122 /* vSMP Internode cacheline shift */
8123diff -urNp linux-2.6.32.44/arch/x86/include/asm/checksum_32.h linux-2.6.32.44/arch/x86/include/asm/checksum_32.h
8124--- linux-2.6.32.44/arch/x86/include/asm/checksum_32.h 2011-03-27 14:31:47.000000000 -0400
8125+++ linux-2.6.32.44/arch/x86/include/asm/checksum_32.h 2011-04-17 15:56:46.000000000 -0400
8126@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
8127 int len, __wsum sum,
8128 int *src_err_ptr, int *dst_err_ptr);
8129
8130+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
8131+ int len, __wsum sum,
8132+ int *src_err_ptr, int *dst_err_ptr);
8133+
8134+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
8135+ int len, __wsum sum,
8136+ int *src_err_ptr, int *dst_err_ptr);
8137+
8138 /*
8139 * Note: when you get a NULL pointer exception here this means someone
8140 * passed in an incorrect kernel address to one of these functions.
8141@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
8142 int *err_ptr)
8143 {
8144 might_sleep();
8145- return csum_partial_copy_generic((__force void *)src, dst,
8146+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
8147 len, sum, err_ptr, NULL);
8148 }
8149
8150@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
8151 {
8152 might_sleep();
8153 if (access_ok(VERIFY_WRITE, dst, len))
8154- return csum_partial_copy_generic(src, (__force void *)dst,
8155+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
8156 len, sum, NULL, err_ptr);
8157
8158 if (len)
8159diff -urNp linux-2.6.32.44/arch/x86/include/asm/desc_defs.h linux-2.6.32.44/arch/x86/include/asm/desc_defs.h
8160--- linux-2.6.32.44/arch/x86/include/asm/desc_defs.h 2011-03-27 14:31:47.000000000 -0400
8161+++ linux-2.6.32.44/arch/x86/include/asm/desc_defs.h 2011-04-17 15:56:46.000000000 -0400
8162@@ -31,6 +31,12 @@ struct desc_struct {
8163 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
8164 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
8165 };
8166+ struct {
8167+ u16 offset_low;
8168+ u16 seg;
8169+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
8170+ unsigned offset_high: 16;
8171+ } gate;
8172 };
8173 } __attribute__((packed));
8174
8175diff -urNp linux-2.6.32.44/arch/x86/include/asm/desc.h linux-2.6.32.44/arch/x86/include/asm/desc.h
8176--- linux-2.6.32.44/arch/x86/include/asm/desc.h 2011-03-27 14:31:47.000000000 -0400
8177+++ linux-2.6.32.44/arch/x86/include/asm/desc.h 2011-04-23 12:56:10.000000000 -0400
8178@@ -4,6 +4,7 @@
8179 #include <asm/desc_defs.h>
8180 #include <asm/ldt.h>
8181 #include <asm/mmu.h>
8182+#include <asm/pgtable.h>
8183 #include <linux/smp.h>
8184
8185 static inline void fill_ldt(struct desc_struct *desc,
8186@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
8187 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
8188 desc->type = (info->read_exec_only ^ 1) << 1;
8189 desc->type |= info->contents << 2;
8190+ desc->type |= info->seg_not_present ^ 1;
8191 desc->s = 1;
8192 desc->dpl = 0x3;
8193 desc->p = info->seg_not_present ^ 1;
8194@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
8195 }
8196
8197 extern struct desc_ptr idt_descr;
8198-extern gate_desc idt_table[];
8199-
8200-struct gdt_page {
8201- struct desc_struct gdt[GDT_ENTRIES];
8202-} __attribute__((aligned(PAGE_SIZE)));
8203-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
8204+extern gate_desc idt_table[256];
8205
8206+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
8207 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
8208 {
8209- return per_cpu(gdt_page, cpu).gdt;
8210+ return cpu_gdt_table[cpu];
8211 }
8212
8213 #ifdef CONFIG_X86_64
8214@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
8215 unsigned long base, unsigned dpl, unsigned flags,
8216 unsigned short seg)
8217 {
8218- gate->a = (seg << 16) | (base & 0xffff);
8219- gate->b = (base & 0xffff0000) |
8220- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
8221+ gate->gate.offset_low = base;
8222+ gate->gate.seg = seg;
8223+ gate->gate.reserved = 0;
8224+ gate->gate.type = type;
8225+ gate->gate.s = 0;
8226+ gate->gate.dpl = dpl;
8227+ gate->gate.p = 1;
8228+ gate->gate.offset_high = base >> 16;
8229 }
8230
8231 #endif
8232@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
8233 static inline void native_write_idt_entry(gate_desc *idt, int entry,
8234 const gate_desc *gate)
8235 {
8236+ pax_open_kernel();
8237 memcpy(&idt[entry], gate, sizeof(*gate));
8238+ pax_close_kernel();
8239 }
8240
8241 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
8242 const void *desc)
8243 {
8244+ pax_open_kernel();
8245 memcpy(&ldt[entry], desc, 8);
8246+ pax_close_kernel();
8247 }
8248
8249 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
8250@@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
8251 size = sizeof(struct desc_struct);
8252 break;
8253 }
8254+
8255+ pax_open_kernel();
8256 memcpy(&gdt[entry], desc, size);
8257+ pax_close_kernel();
8258 }
8259
8260 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
8261@@ -211,7 +221,9 @@ static inline void native_set_ldt(const
8262
8263 static inline void native_load_tr_desc(void)
8264 {
8265+ pax_open_kernel();
8266 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
8267+ pax_close_kernel();
8268 }
8269
8270 static inline void native_load_gdt(const struct desc_ptr *dtr)
8271@@ -246,8 +258,10 @@ static inline void native_load_tls(struc
8272 unsigned int i;
8273 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
8274
8275+ pax_open_kernel();
8276 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
8277 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
8278+ pax_close_kernel();
8279 }
8280
8281 #define _LDT_empty(info) \
8282@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
8283 desc->limit = (limit >> 16) & 0xf;
8284 }
8285
8286-static inline void _set_gate(int gate, unsigned type, void *addr,
8287+static inline void _set_gate(int gate, unsigned type, const void *addr,
8288 unsigned dpl, unsigned ist, unsigned seg)
8289 {
8290 gate_desc s;
8291@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
8292 * Pentium F0 0F bugfix can have resulted in the mapped
8293 * IDT being write-protected.
8294 */
8295-static inline void set_intr_gate(unsigned int n, void *addr)
8296+static inline void set_intr_gate(unsigned int n, const void *addr)
8297 {
8298 BUG_ON((unsigned)n > 0xFF);
8299 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
8300@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
8301 /*
8302 * This routine sets up an interrupt gate at directory privilege level 3.
8303 */
8304-static inline void set_system_intr_gate(unsigned int n, void *addr)
8305+static inline void set_system_intr_gate(unsigned int n, const void *addr)
8306 {
8307 BUG_ON((unsigned)n > 0xFF);
8308 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
8309 }
8310
8311-static inline void set_system_trap_gate(unsigned int n, void *addr)
8312+static inline void set_system_trap_gate(unsigned int n, const void *addr)
8313 {
8314 BUG_ON((unsigned)n > 0xFF);
8315 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8316 }
8317
8318-static inline void set_trap_gate(unsigned int n, void *addr)
8319+static inline void set_trap_gate(unsigned int n, const void *addr)
8320 {
8321 BUG_ON((unsigned)n > 0xFF);
8322 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8323@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
8324 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8325 {
8326 BUG_ON((unsigned)n > 0xFF);
8327- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8328+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8329 }
8330
8331-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8332+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8333 {
8334 BUG_ON((unsigned)n > 0xFF);
8335 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8336 }
8337
8338-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8339+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8340 {
8341 BUG_ON((unsigned)n > 0xFF);
8342 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8343 }
8344
8345+#ifdef CONFIG_X86_32
8346+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8347+{
8348+ struct desc_struct d;
8349+
8350+ if (likely(limit))
8351+ limit = (limit - 1UL) >> PAGE_SHIFT;
8352+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
8353+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8354+}
8355+#endif
8356+
8357 #endif /* _ASM_X86_DESC_H */
8358diff -urNp linux-2.6.32.44/arch/x86/include/asm/device.h linux-2.6.32.44/arch/x86/include/asm/device.h
8359--- linux-2.6.32.44/arch/x86/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
8360+++ linux-2.6.32.44/arch/x86/include/asm/device.h 2011-04-17 15:56:46.000000000 -0400
8361@@ -6,7 +6,7 @@ struct dev_archdata {
8362 void *acpi_handle;
8363 #endif
8364 #ifdef CONFIG_X86_64
8365-struct dma_map_ops *dma_ops;
8366+ const struct dma_map_ops *dma_ops;
8367 #endif
8368 #ifdef CONFIG_DMAR
8369 void *iommu; /* hook for IOMMU specific extension */
8370diff -urNp linux-2.6.32.44/arch/x86/include/asm/dma-mapping.h linux-2.6.32.44/arch/x86/include/asm/dma-mapping.h
8371--- linux-2.6.32.44/arch/x86/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
8372+++ linux-2.6.32.44/arch/x86/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
8373@@ -25,9 +25,9 @@ extern int iommu_merge;
8374 extern struct device x86_dma_fallback_dev;
8375 extern int panic_on_overflow;
8376
8377-extern struct dma_map_ops *dma_ops;
8378+extern const struct dma_map_ops *dma_ops;
8379
8380-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
8381+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
8382 {
8383 #ifdef CONFIG_X86_32
8384 return dma_ops;
8385@@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dm
8386 /* Make sure we keep the same behaviour */
8387 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
8388 {
8389- struct dma_map_ops *ops = get_dma_ops(dev);
8390+ const struct dma_map_ops *ops = get_dma_ops(dev);
8391 if (ops->mapping_error)
8392 return ops->mapping_error(dev, dma_addr);
8393
8394@@ -122,7 +122,7 @@ static inline void *
8395 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
8396 gfp_t gfp)
8397 {
8398- struct dma_map_ops *ops = get_dma_ops(dev);
8399+ const struct dma_map_ops *ops = get_dma_ops(dev);
8400 void *memory;
8401
8402 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
8403@@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, s
8404 static inline void dma_free_coherent(struct device *dev, size_t size,
8405 void *vaddr, dma_addr_t bus)
8406 {
8407- struct dma_map_ops *ops = get_dma_ops(dev);
8408+ const struct dma_map_ops *ops = get_dma_ops(dev);
8409
8410 WARN_ON(irqs_disabled()); /* for portability */
8411
8412diff -urNp linux-2.6.32.44/arch/x86/include/asm/e820.h linux-2.6.32.44/arch/x86/include/asm/e820.h
8413--- linux-2.6.32.44/arch/x86/include/asm/e820.h 2011-03-27 14:31:47.000000000 -0400
8414+++ linux-2.6.32.44/arch/x86/include/asm/e820.h 2011-04-17 15:56:46.000000000 -0400
8415@@ -133,7 +133,7 @@ extern char *default_machine_specific_me
8416 #define ISA_END_ADDRESS 0x100000
8417 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
8418
8419-#define BIOS_BEGIN 0x000a0000
8420+#define BIOS_BEGIN 0x000c0000
8421 #define BIOS_END 0x00100000
8422
8423 #ifdef __KERNEL__
8424diff -urNp linux-2.6.32.44/arch/x86/include/asm/elf.h linux-2.6.32.44/arch/x86/include/asm/elf.h
8425--- linux-2.6.32.44/arch/x86/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
8426+++ linux-2.6.32.44/arch/x86/include/asm/elf.h 2011-04-17 15:56:46.000000000 -0400
8427@@ -257,7 +257,25 @@ extern int force_personality32;
8428 the loader. We need to make sure that it is out of the way of the program
8429 that it will "exec", and that there is sufficient room for the brk. */
8430
8431+#ifdef CONFIG_PAX_SEGMEXEC
8432+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8433+#else
8434 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8435+#endif
8436+
8437+#ifdef CONFIG_PAX_ASLR
8438+#ifdef CONFIG_X86_32
8439+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8440+
8441+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8442+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8443+#else
8444+#define PAX_ELF_ET_DYN_BASE 0x400000UL
8445+
8446+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8447+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8448+#endif
8449+#endif
8450
8451 /* This yields a mask that user programs can use to figure out what
8452 instruction set this CPU supports. This could be done in user space,
8453@@ -311,8 +329,7 @@ do { \
8454 #define ARCH_DLINFO \
8455 do { \
8456 if (vdso_enabled) \
8457- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8458- (unsigned long)current->mm->context.vdso); \
8459+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
8460 } while (0)
8461
8462 #define AT_SYSINFO 32
8463@@ -323,7 +340,7 @@ do { \
8464
8465 #endif /* !CONFIG_X86_32 */
8466
8467-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8468+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8469
8470 #define VDSO_ENTRY \
8471 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8472@@ -337,7 +354,4 @@ extern int arch_setup_additional_pages(s
8473 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8474 #define compat_arch_setup_additional_pages syscall32_setup_pages
8475
8476-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8477-#define arch_randomize_brk arch_randomize_brk
8478-
8479 #endif /* _ASM_X86_ELF_H */
8480diff -urNp linux-2.6.32.44/arch/x86/include/asm/emergency-restart.h linux-2.6.32.44/arch/x86/include/asm/emergency-restart.h
8481--- linux-2.6.32.44/arch/x86/include/asm/emergency-restart.h 2011-03-27 14:31:47.000000000 -0400
8482+++ linux-2.6.32.44/arch/x86/include/asm/emergency-restart.h 2011-05-22 23:02:06.000000000 -0400
8483@@ -15,6 +15,6 @@ enum reboot_type {
8484
8485 extern enum reboot_type reboot_type;
8486
8487-extern void machine_emergency_restart(void);
8488+extern void machine_emergency_restart(void) __noreturn;
8489
8490 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8491diff -urNp linux-2.6.32.44/arch/x86/include/asm/futex.h linux-2.6.32.44/arch/x86/include/asm/futex.h
8492--- linux-2.6.32.44/arch/x86/include/asm/futex.h 2011-03-27 14:31:47.000000000 -0400
8493+++ linux-2.6.32.44/arch/x86/include/asm/futex.h 2011-04-17 15:56:46.000000000 -0400
8494@@ -12,16 +12,18 @@
8495 #include <asm/system.h>
8496
8497 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8498+ typecheck(u32 *, uaddr); \
8499 asm volatile("1:\t" insn "\n" \
8500 "2:\t.section .fixup,\"ax\"\n" \
8501 "3:\tmov\t%3, %1\n" \
8502 "\tjmp\t2b\n" \
8503 "\t.previous\n" \
8504 _ASM_EXTABLE(1b, 3b) \
8505- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8506+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
8507 : "i" (-EFAULT), "0" (oparg), "1" (0))
8508
8509 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8510+ typecheck(u32 *, uaddr); \
8511 asm volatile("1:\tmovl %2, %0\n" \
8512 "\tmovl\t%0, %3\n" \
8513 "\t" insn "\n" \
8514@@ -34,10 +36,10 @@
8515 _ASM_EXTABLE(1b, 4b) \
8516 _ASM_EXTABLE(2b, 4b) \
8517 : "=&a" (oldval), "=&r" (ret), \
8518- "+m" (*uaddr), "=&r" (tem) \
8519+ "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
8520 : "r" (oparg), "i" (-EFAULT), "1" (0))
8521
8522-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
8523+static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8524 {
8525 int op = (encoded_op >> 28) & 7;
8526 int cmp = (encoded_op >> 24) & 15;
8527@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
8528
8529 switch (op) {
8530 case FUTEX_OP_SET:
8531- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8532+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8533 break;
8534 case FUTEX_OP_ADD:
8535- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8536+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8537 uaddr, oparg);
8538 break;
8539 case FUTEX_OP_OR:
8540@@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser
8541 return ret;
8542 }
8543
8544-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
8545+static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
8546 int newval)
8547 {
8548
8549@@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_i
8550 return -ENOSYS;
8551 #endif
8552
8553- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
8554+ if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8555 return -EFAULT;
8556
8557- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
8558+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
8559 "2:\t.section .fixup, \"ax\"\n"
8560 "3:\tmov %2, %0\n"
8561 "\tjmp 2b\n"
8562 "\t.previous\n"
8563 _ASM_EXTABLE(1b, 3b)
8564- : "=a" (oldval), "+m" (*uaddr)
8565+ : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
8566 : "i" (-EFAULT), "r" (newval), "0" (oldval)
8567 : "memory"
8568 );
8569diff -urNp linux-2.6.32.44/arch/x86/include/asm/hw_irq.h linux-2.6.32.44/arch/x86/include/asm/hw_irq.h
8570--- linux-2.6.32.44/arch/x86/include/asm/hw_irq.h 2011-03-27 14:31:47.000000000 -0400
8571+++ linux-2.6.32.44/arch/x86/include/asm/hw_irq.h 2011-05-04 17:56:28.000000000 -0400
8572@@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
8573 extern void enable_IO_APIC(void);
8574
8575 /* Statistics */
8576-extern atomic_t irq_err_count;
8577-extern atomic_t irq_mis_count;
8578+extern atomic_unchecked_t irq_err_count;
8579+extern atomic_unchecked_t irq_mis_count;
8580
8581 /* EISA */
8582 extern void eisa_set_level_irq(unsigned int irq);
8583diff -urNp linux-2.6.32.44/arch/x86/include/asm/i387.h linux-2.6.32.44/arch/x86/include/asm/i387.h
8584--- linux-2.6.32.44/arch/x86/include/asm/i387.h 2011-03-27 14:31:47.000000000 -0400
8585+++ linux-2.6.32.44/arch/x86/include/asm/i387.h 2011-04-17 15:56:46.000000000 -0400
8586@@ -60,6 +60,11 @@ static inline int fxrstor_checking(struc
8587 {
8588 int err;
8589
8590+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8591+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8592+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
8593+#endif
8594+
8595 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
8596 "2:\n"
8597 ".section .fixup,\"ax\"\n"
8598@@ -105,6 +110,11 @@ static inline int fxsave_user(struct i38
8599 {
8600 int err;
8601
8602+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8603+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8604+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8605+#endif
8606+
8607 asm volatile("1: rex64/fxsave (%[fx])\n\t"
8608 "2:\n"
8609 ".section .fixup,\"ax\"\n"
8610@@ -195,13 +205,8 @@ static inline int fxrstor_checking(struc
8611 }
8612
8613 /* We need a safe address that is cheap to find and that is already
8614- in L1 during context switch. The best choices are unfortunately
8615- different for UP and SMP */
8616-#ifdef CONFIG_SMP
8617-#define safe_address (__per_cpu_offset[0])
8618-#else
8619-#define safe_address (kstat_cpu(0).cpustat.user)
8620-#endif
8621+ in L1 during context switch. */
8622+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
8623
8624 /*
8625 * These must be called with preempt disabled
8626@@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void
8627 struct thread_info *me = current_thread_info();
8628 preempt_disable();
8629 if (me->status & TS_USEDFPU)
8630- __save_init_fpu(me->task);
8631+ __save_init_fpu(current);
8632 else
8633 clts();
8634 }
8635diff -urNp linux-2.6.32.44/arch/x86/include/asm/io_32.h linux-2.6.32.44/arch/x86/include/asm/io_32.h
8636--- linux-2.6.32.44/arch/x86/include/asm/io_32.h 2011-03-27 14:31:47.000000000 -0400
8637+++ linux-2.6.32.44/arch/x86/include/asm/io_32.h 2011-04-17 15:56:46.000000000 -0400
8638@@ -3,6 +3,7 @@
8639
8640 #include <linux/string.h>
8641 #include <linux/compiler.h>
8642+#include <asm/processor.h>
8643
8644 /*
8645 * This file contains the definitions for the x86 IO instructions
8646@@ -42,6 +43,17 @@
8647
8648 #ifdef __KERNEL__
8649
8650+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8651+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8652+{
8653+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8654+}
8655+
8656+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8657+{
8658+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8659+}
8660+
8661 #include <asm-generic/iomap.h>
8662
8663 #include <linux/vmalloc.h>
8664diff -urNp linux-2.6.32.44/arch/x86/include/asm/io_64.h linux-2.6.32.44/arch/x86/include/asm/io_64.h
8665--- linux-2.6.32.44/arch/x86/include/asm/io_64.h 2011-03-27 14:31:47.000000000 -0400
8666+++ linux-2.6.32.44/arch/x86/include/asm/io_64.h 2011-04-17 15:56:46.000000000 -0400
8667@@ -140,6 +140,17 @@ __OUTS(l)
8668
8669 #include <linux/vmalloc.h>
8670
8671+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8672+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8673+{
8674+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8675+}
8676+
8677+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8678+{
8679+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8680+}
8681+
8682 #include <asm-generic/iomap.h>
8683
8684 void __memcpy_fromio(void *, unsigned long, unsigned);
8685diff -urNp linux-2.6.32.44/arch/x86/include/asm/iommu.h linux-2.6.32.44/arch/x86/include/asm/iommu.h
8686--- linux-2.6.32.44/arch/x86/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
8687+++ linux-2.6.32.44/arch/x86/include/asm/iommu.h 2011-04-17 15:56:46.000000000 -0400
8688@@ -3,7 +3,7 @@
8689
8690 extern void pci_iommu_shutdown(void);
8691 extern void no_iommu_init(void);
8692-extern struct dma_map_ops nommu_dma_ops;
8693+extern const struct dma_map_ops nommu_dma_ops;
8694 extern int force_iommu, no_iommu;
8695 extern int iommu_detected;
8696 extern int iommu_pass_through;
8697diff -urNp linux-2.6.32.44/arch/x86/include/asm/irqflags.h linux-2.6.32.44/arch/x86/include/asm/irqflags.h
8698--- linux-2.6.32.44/arch/x86/include/asm/irqflags.h 2011-03-27 14:31:47.000000000 -0400
8699+++ linux-2.6.32.44/arch/x86/include/asm/irqflags.h 2011-04-17 15:56:46.000000000 -0400
8700@@ -142,6 +142,11 @@ static inline unsigned long __raw_local_
8701 sti; \
8702 sysexit
8703
8704+#define GET_CR0_INTO_RDI mov %cr0, %rdi
8705+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8706+#define GET_CR3_INTO_RDI mov %cr3, %rdi
8707+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8708+
8709 #else
8710 #define INTERRUPT_RETURN iret
8711 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8712diff -urNp linux-2.6.32.44/arch/x86/include/asm/kprobes.h linux-2.6.32.44/arch/x86/include/asm/kprobes.h
8713--- linux-2.6.32.44/arch/x86/include/asm/kprobes.h 2011-03-27 14:31:47.000000000 -0400
8714+++ linux-2.6.32.44/arch/x86/include/asm/kprobes.h 2011-04-23 12:56:12.000000000 -0400
8715@@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
8716 #define BREAKPOINT_INSTRUCTION 0xcc
8717 #define RELATIVEJUMP_INSTRUCTION 0xe9
8718 #define MAX_INSN_SIZE 16
8719-#define MAX_STACK_SIZE 64
8720-#define MIN_STACK_SIZE(ADDR) \
8721- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8722- THREAD_SIZE - (unsigned long)(ADDR))) \
8723- ? (MAX_STACK_SIZE) \
8724- : (((unsigned long)current_thread_info()) + \
8725- THREAD_SIZE - (unsigned long)(ADDR)))
8726+#define MAX_STACK_SIZE 64UL
8727+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8728
8729 #define flush_insn_slot(p) do { } while (0)
8730
8731diff -urNp linux-2.6.32.44/arch/x86/include/asm/kvm_host.h linux-2.6.32.44/arch/x86/include/asm/kvm_host.h
8732--- linux-2.6.32.44/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:01.000000000 -0400
8733+++ linux-2.6.32.44/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:26.000000000 -0400
8734@@ -536,7 +536,7 @@ struct kvm_x86_ops {
8735 const struct trace_print_flags *exit_reasons_str;
8736 };
8737
8738-extern struct kvm_x86_ops *kvm_x86_ops;
8739+extern const struct kvm_x86_ops *kvm_x86_ops;
8740
8741 int kvm_mmu_module_init(void);
8742 void kvm_mmu_module_exit(void);
8743diff -urNp linux-2.6.32.44/arch/x86/include/asm/local.h linux-2.6.32.44/arch/x86/include/asm/local.h
8744--- linux-2.6.32.44/arch/x86/include/asm/local.h 2011-03-27 14:31:47.000000000 -0400
8745+++ linux-2.6.32.44/arch/x86/include/asm/local.h 2011-04-17 15:56:46.000000000 -0400
8746@@ -18,26 +18,58 @@ typedef struct {
8747
8748 static inline void local_inc(local_t *l)
8749 {
8750- asm volatile(_ASM_INC "%0"
8751+ asm volatile(_ASM_INC "%0\n"
8752+
8753+#ifdef CONFIG_PAX_REFCOUNT
8754+ "jno 0f\n"
8755+ _ASM_DEC "%0\n"
8756+ "int $4\n0:\n"
8757+ _ASM_EXTABLE(0b, 0b)
8758+#endif
8759+
8760 : "+m" (l->a.counter));
8761 }
8762
8763 static inline void local_dec(local_t *l)
8764 {
8765- asm volatile(_ASM_DEC "%0"
8766+ asm volatile(_ASM_DEC "%0\n"
8767+
8768+#ifdef CONFIG_PAX_REFCOUNT
8769+ "jno 0f\n"
8770+ _ASM_INC "%0\n"
8771+ "int $4\n0:\n"
8772+ _ASM_EXTABLE(0b, 0b)
8773+#endif
8774+
8775 : "+m" (l->a.counter));
8776 }
8777
8778 static inline void local_add(long i, local_t *l)
8779 {
8780- asm volatile(_ASM_ADD "%1,%0"
8781+ asm volatile(_ASM_ADD "%1,%0\n"
8782+
8783+#ifdef CONFIG_PAX_REFCOUNT
8784+ "jno 0f\n"
8785+ _ASM_SUB "%1,%0\n"
8786+ "int $4\n0:\n"
8787+ _ASM_EXTABLE(0b, 0b)
8788+#endif
8789+
8790 : "+m" (l->a.counter)
8791 : "ir" (i));
8792 }
8793
8794 static inline void local_sub(long i, local_t *l)
8795 {
8796- asm volatile(_ASM_SUB "%1,%0"
8797+ asm volatile(_ASM_SUB "%1,%0\n"
8798+
8799+#ifdef CONFIG_PAX_REFCOUNT
8800+ "jno 0f\n"
8801+ _ASM_ADD "%1,%0\n"
8802+ "int $4\n0:\n"
8803+ _ASM_EXTABLE(0b, 0b)
8804+#endif
8805+
8806 : "+m" (l->a.counter)
8807 : "ir" (i));
8808 }
8809@@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
8810 {
8811 unsigned char c;
8812
8813- asm volatile(_ASM_SUB "%2,%0; sete %1"
8814+ asm volatile(_ASM_SUB "%2,%0\n"
8815+
8816+#ifdef CONFIG_PAX_REFCOUNT
8817+ "jno 0f\n"
8818+ _ASM_ADD "%2,%0\n"
8819+ "int $4\n0:\n"
8820+ _ASM_EXTABLE(0b, 0b)
8821+#endif
8822+
8823+ "sete %1\n"
8824 : "+m" (l->a.counter), "=qm" (c)
8825 : "ir" (i) : "memory");
8826 return c;
8827@@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
8828 {
8829 unsigned char c;
8830
8831- asm volatile(_ASM_DEC "%0; sete %1"
8832+ asm volatile(_ASM_DEC "%0\n"
8833+
8834+#ifdef CONFIG_PAX_REFCOUNT
8835+ "jno 0f\n"
8836+ _ASM_INC "%0\n"
8837+ "int $4\n0:\n"
8838+ _ASM_EXTABLE(0b, 0b)
8839+#endif
8840+
8841+ "sete %1\n"
8842 : "+m" (l->a.counter), "=qm" (c)
8843 : : "memory");
8844 return c != 0;
8845@@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
8846 {
8847 unsigned char c;
8848
8849- asm volatile(_ASM_INC "%0; sete %1"
8850+ asm volatile(_ASM_INC "%0\n"
8851+
8852+#ifdef CONFIG_PAX_REFCOUNT
8853+ "jno 0f\n"
8854+ _ASM_DEC "%0\n"
8855+ "int $4\n0:\n"
8856+ _ASM_EXTABLE(0b, 0b)
8857+#endif
8858+
8859+ "sete %1\n"
8860 : "+m" (l->a.counter), "=qm" (c)
8861 : : "memory");
8862 return c != 0;
8863@@ -110,7 +169,16 @@ static inline int local_add_negative(lon
8864 {
8865 unsigned char c;
8866
8867- asm volatile(_ASM_ADD "%2,%0; sets %1"
8868+ asm volatile(_ASM_ADD "%2,%0\n"
8869+
8870+#ifdef CONFIG_PAX_REFCOUNT
8871+ "jno 0f\n"
8872+ _ASM_SUB "%2,%0\n"
8873+ "int $4\n0:\n"
8874+ _ASM_EXTABLE(0b, 0b)
8875+#endif
8876+
8877+ "sets %1\n"
8878 : "+m" (l->a.counter), "=qm" (c)
8879 : "ir" (i) : "memory");
8880 return c;
8881@@ -133,7 +201,15 @@ static inline long local_add_return(long
8882 #endif
8883 /* Modern 486+ processor */
8884 __i = i;
8885- asm volatile(_ASM_XADD "%0, %1;"
8886+ asm volatile(_ASM_XADD "%0, %1\n"
8887+
8888+#ifdef CONFIG_PAX_REFCOUNT
8889+ "jno 0f\n"
8890+ _ASM_MOV "%0,%1\n"
8891+ "int $4\n0:\n"
8892+ _ASM_EXTABLE(0b, 0b)
8893+#endif
8894+
8895 : "+r" (i), "+m" (l->a.counter)
8896 : : "memory");
8897 return i + __i;
8898diff -urNp linux-2.6.32.44/arch/x86/include/asm/microcode.h linux-2.6.32.44/arch/x86/include/asm/microcode.h
8899--- linux-2.6.32.44/arch/x86/include/asm/microcode.h 2011-03-27 14:31:47.000000000 -0400
8900+++ linux-2.6.32.44/arch/x86/include/asm/microcode.h 2011-04-17 15:56:46.000000000 -0400
8901@@ -12,13 +12,13 @@ struct device;
8902 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
8903
8904 struct microcode_ops {
8905- enum ucode_state (*request_microcode_user) (int cpu,
8906+ enum ucode_state (* const request_microcode_user) (int cpu,
8907 const void __user *buf, size_t size);
8908
8909- enum ucode_state (*request_microcode_fw) (int cpu,
8910+ enum ucode_state (* const request_microcode_fw) (int cpu,
8911 struct device *device);
8912
8913- void (*microcode_fini_cpu) (int cpu);
8914+ void (* const microcode_fini_cpu) (int cpu);
8915
8916 /*
8917 * The generic 'microcode_core' part guarantees that
8918@@ -38,18 +38,18 @@ struct ucode_cpu_info {
8919 extern struct ucode_cpu_info ucode_cpu_info[];
8920
8921 #ifdef CONFIG_MICROCODE_INTEL
8922-extern struct microcode_ops * __init init_intel_microcode(void);
8923+extern const struct microcode_ops * __init init_intel_microcode(void);
8924 #else
8925-static inline struct microcode_ops * __init init_intel_microcode(void)
8926+static inline const struct microcode_ops * __init init_intel_microcode(void)
8927 {
8928 return NULL;
8929 }
8930 #endif /* CONFIG_MICROCODE_INTEL */
8931
8932 #ifdef CONFIG_MICROCODE_AMD
8933-extern struct microcode_ops * __init init_amd_microcode(void);
8934+extern const struct microcode_ops * __init init_amd_microcode(void);
8935 #else
8936-static inline struct microcode_ops * __init init_amd_microcode(void)
8937+static inline const struct microcode_ops * __init init_amd_microcode(void)
8938 {
8939 return NULL;
8940 }
8941diff -urNp linux-2.6.32.44/arch/x86/include/asm/mman.h linux-2.6.32.44/arch/x86/include/asm/mman.h
8942--- linux-2.6.32.44/arch/x86/include/asm/mman.h 2011-03-27 14:31:47.000000000 -0400
8943+++ linux-2.6.32.44/arch/x86/include/asm/mman.h 2011-04-17 15:56:46.000000000 -0400
8944@@ -5,4 +5,14 @@
8945
8946 #include <asm-generic/mman.h>
8947
8948+#ifdef __KERNEL__
8949+#ifndef __ASSEMBLY__
8950+#ifdef CONFIG_X86_32
8951+#define arch_mmap_check i386_mmap_check
8952+int i386_mmap_check(unsigned long addr, unsigned long len,
8953+ unsigned long flags);
8954+#endif
8955+#endif
8956+#endif
8957+
8958 #endif /* _ASM_X86_MMAN_H */
8959diff -urNp linux-2.6.32.44/arch/x86/include/asm/mmu_context.h linux-2.6.32.44/arch/x86/include/asm/mmu_context.h
8960--- linux-2.6.32.44/arch/x86/include/asm/mmu_context.h 2011-03-27 14:31:47.000000000 -0400
8961+++ linux-2.6.32.44/arch/x86/include/asm/mmu_context.h 2011-04-17 15:56:46.000000000 -0400
8962@@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
8963
8964 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
8965 {
8966+
8967+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8968+ unsigned int i;
8969+ pgd_t *pgd;
8970+
8971+ pax_open_kernel();
8972+ pgd = get_cpu_pgd(smp_processor_id());
8973+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
8974+ if (paravirt_enabled())
8975+ set_pgd(pgd+i, native_make_pgd(0));
8976+ else
8977+ pgd[i] = native_make_pgd(0);
8978+ pax_close_kernel();
8979+#endif
8980+
8981 #ifdef CONFIG_SMP
8982 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
8983 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
8984@@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
8985 struct task_struct *tsk)
8986 {
8987 unsigned cpu = smp_processor_id();
8988+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
8989+ int tlbstate = TLBSTATE_OK;
8990+#endif
8991
8992 if (likely(prev != next)) {
8993 #ifdef CONFIG_SMP
8994+#ifdef CONFIG_X86_32
8995+ tlbstate = percpu_read(cpu_tlbstate.state);
8996+#endif
8997 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8998 percpu_write(cpu_tlbstate.active_mm, next);
8999 #endif
9000 cpumask_set_cpu(cpu, mm_cpumask(next));
9001
9002 /* Re-load page tables */
9003+#ifdef CONFIG_PAX_PER_CPU_PGD
9004+ pax_open_kernel();
9005+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9006+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9007+ pax_close_kernel();
9008+ load_cr3(get_cpu_pgd(cpu));
9009+#else
9010 load_cr3(next->pgd);
9011+#endif
9012
9013 /* stop flush ipis for the previous mm */
9014 cpumask_clear_cpu(cpu, mm_cpumask(prev));
9015@@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
9016 */
9017 if (unlikely(prev->context.ldt != next->context.ldt))
9018 load_LDT_nolock(&next->context);
9019- }
9020+
9021+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9022+ if (!nx_enabled) {
9023+ smp_mb__before_clear_bit();
9024+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
9025+ smp_mb__after_clear_bit();
9026+ cpu_set(cpu, next->context.cpu_user_cs_mask);
9027+ }
9028+#endif
9029+
9030+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9031+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
9032+ prev->context.user_cs_limit != next->context.user_cs_limit))
9033+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9034 #ifdef CONFIG_SMP
9035+ else if (unlikely(tlbstate != TLBSTATE_OK))
9036+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9037+#endif
9038+#endif
9039+
9040+ }
9041 else {
9042+
9043+#ifdef CONFIG_PAX_PER_CPU_PGD
9044+ pax_open_kernel();
9045+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9046+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9047+ pax_close_kernel();
9048+ load_cr3(get_cpu_pgd(cpu));
9049+#endif
9050+
9051+#ifdef CONFIG_SMP
9052 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9053 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
9054
9055@@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
9056 * tlb flush IPI delivery. We must reload CR3
9057 * to make sure to use no freed page tables.
9058 */
9059+
9060+#ifndef CONFIG_PAX_PER_CPU_PGD
9061 load_cr3(next->pgd);
9062+#endif
9063+
9064 load_LDT_nolock(&next->context);
9065+
9066+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9067+ if (!nx_enabled)
9068+ cpu_set(cpu, next->context.cpu_user_cs_mask);
9069+#endif
9070+
9071+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9072+#ifdef CONFIG_PAX_PAGEEXEC
9073+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
9074+#endif
9075+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9076+#endif
9077+
9078 }
9079- }
9080 #endif
9081+ }
9082 }
9083
9084 #define activate_mm(prev, next) \
9085diff -urNp linux-2.6.32.44/arch/x86/include/asm/mmu.h linux-2.6.32.44/arch/x86/include/asm/mmu.h
9086--- linux-2.6.32.44/arch/x86/include/asm/mmu.h 2011-03-27 14:31:47.000000000 -0400
9087+++ linux-2.6.32.44/arch/x86/include/asm/mmu.h 2011-04-17 15:56:46.000000000 -0400
9088@@ -9,10 +9,23 @@
9089 * we put the segment information here.
9090 */
9091 typedef struct {
9092- void *ldt;
9093+ struct desc_struct *ldt;
9094 int size;
9095 struct mutex lock;
9096- void *vdso;
9097+ unsigned long vdso;
9098+
9099+#ifdef CONFIG_X86_32
9100+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
9101+ unsigned long user_cs_base;
9102+ unsigned long user_cs_limit;
9103+
9104+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9105+ cpumask_t cpu_user_cs_mask;
9106+#endif
9107+
9108+#endif
9109+#endif
9110+
9111 } mm_context_t;
9112
9113 #ifdef CONFIG_SMP
9114diff -urNp linux-2.6.32.44/arch/x86/include/asm/module.h linux-2.6.32.44/arch/x86/include/asm/module.h
9115--- linux-2.6.32.44/arch/x86/include/asm/module.h 2011-03-27 14:31:47.000000000 -0400
9116+++ linux-2.6.32.44/arch/x86/include/asm/module.h 2011-04-23 13:18:57.000000000 -0400
9117@@ -5,6 +5,7 @@
9118
9119 #ifdef CONFIG_X86_64
9120 /* X86_64 does not define MODULE_PROC_FAMILY */
9121+#define MODULE_PROC_FAMILY ""
9122 #elif defined CONFIG_M386
9123 #define MODULE_PROC_FAMILY "386 "
9124 #elif defined CONFIG_M486
9125@@ -59,13 +60,36 @@
9126 #error unknown processor family
9127 #endif
9128
9129-#ifdef CONFIG_X86_32
9130-# ifdef CONFIG_4KSTACKS
9131-# define MODULE_STACKSIZE "4KSTACKS "
9132-# else
9133-# define MODULE_STACKSIZE ""
9134-# endif
9135-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
9136+#ifdef CONFIG_PAX_MEMORY_UDEREF
9137+#define MODULE_PAX_UDEREF "UDEREF "
9138+#else
9139+#define MODULE_PAX_UDEREF ""
9140+#endif
9141+
9142+#ifdef CONFIG_PAX_KERNEXEC
9143+#define MODULE_PAX_KERNEXEC "KERNEXEC "
9144+#else
9145+#define MODULE_PAX_KERNEXEC ""
9146+#endif
9147+
9148+#ifdef CONFIG_PAX_REFCOUNT
9149+#define MODULE_PAX_REFCOUNT "REFCOUNT "
9150+#else
9151+#define MODULE_PAX_REFCOUNT ""
9152 #endif
9153
9154+#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
9155+#define MODULE_STACKSIZE "4KSTACKS "
9156+#else
9157+#define MODULE_STACKSIZE ""
9158+#endif
9159+
9160+#ifdef CONFIG_GRKERNSEC
9161+#define MODULE_GRSEC "GRSECURITY "
9162+#else
9163+#define MODULE_GRSEC ""
9164+#endif
9165+
9166+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
9167+
9168 #endif /* _ASM_X86_MODULE_H */
9169diff -urNp linux-2.6.32.44/arch/x86/include/asm/page_64_types.h linux-2.6.32.44/arch/x86/include/asm/page_64_types.h
9170--- linux-2.6.32.44/arch/x86/include/asm/page_64_types.h 2011-03-27 14:31:47.000000000 -0400
9171+++ linux-2.6.32.44/arch/x86/include/asm/page_64_types.h 2011-04-17 15:56:46.000000000 -0400
9172@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
9173
9174 /* duplicated to the one in bootmem.h */
9175 extern unsigned long max_pfn;
9176-extern unsigned long phys_base;
9177+extern const unsigned long phys_base;
9178
9179 extern unsigned long __phys_addr(unsigned long);
9180 #define __phys_reloc_hide(x) (x)
9181diff -urNp linux-2.6.32.44/arch/x86/include/asm/paravirt.h linux-2.6.32.44/arch/x86/include/asm/paravirt.h
9182--- linux-2.6.32.44/arch/x86/include/asm/paravirt.h 2011-03-27 14:31:47.000000000 -0400
9183+++ linux-2.6.32.44/arch/x86/include/asm/paravirt.h 2011-04-17 15:56:46.000000000 -0400
9184@@ -729,6 +729,21 @@ static inline void __set_fixmap(unsigned
9185 pv_mmu_ops.set_fixmap(idx, phys, flags);
9186 }
9187
9188+#ifdef CONFIG_PAX_KERNEXEC
9189+static inline unsigned long pax_open_kernel(void)
9190+{
9191+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
9192+}
9193+
9194+static inline unsigned long pax_close_kernel(void)
9195+{
9196+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
9197+}
9198+#else
9199+static inline unsigned long pax_open_kernel(void) { return 0; }
9200+static inline unsigned long pax_close_kernel(void) { return 0; }
9201+#endif
9202+
9203 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
9204
9205 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
9206@@ -945,7 +960,7 @@ extern void default_banner(void);
9207
9208 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
9209 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
9210-#define PARA_INDIRECT(addr) *%cs:addr
9211+#define PARA_INDIRECT(addr) *%ss:addr
9212 #endif
9213
9214 #define INTERRUPT_RETURN \
9215@@ -1022,6 +1037,21 @@ extern void default_banner(void);
9216 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
9217 CLBR_NONE, \
9218 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
9219+
9220+#define GET_CR0_INTO_RDI \
9221+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
9222+ mov %rax,%rdi
9223+
9224+#define SET_RDI_INTO_CR0 \
9225+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
9226+
9227+#define GET_CR3_INTO_RDI \
9228+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
9229+ mov %rax,%rdi
9230+
9231+#define SET_RDI_INTO_CR3 \
9232+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
9233+
9234 #endif /* CONFIG_X86_32 */
9235
9236 #endif /* __ASSEMBLY__ */
9237diff -urNp linux-2.6.32.44/arch/x86/include/asm/paravirt_types.h linux-2.6.32.44/arch/x86/include/asm/paravirt_types.h
9238--- linux-2.6.32.44/arch/x86/include/asm/paravirt_types.h 2011-03-27 14:31:47.000000000 -0400
9239+++ linux-2.6.32.44/arch/x86/include/asm/paravirt_types.h 2011-08-05 20:33:55.000000000 -0400
9240@@ -78,19 +78,19 @@ struct pv_init_ops {
9241 */
9242 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
9243 unsigned long addr, unsigned len);
9244-};
9245+} __no_const;
9246
9247
9248 struct pv_lazy_ops {
9249 /* Set deferred update mode, used for batching operations. */
9250 void (*enter)(void);
9251 void (*leave)(void);
9252-};
9253+} __no_const;
9254
9255 struct pv_time_ops {
9256 unsigned long long (*sched_clock)(void);
9257 unsigned long (*get_tsc_khz)(void);
9258-};
9259+} __no_const;
9260
9261 struct pv_cpu_ops {
9262 /* hooks for various privileged instructions */
9263@@ -186,7 +186,7 @@ struct pv_cpu_ops {
9264
9265 void (*start_context_switch)(struct task_struct *prev);
9266 void (*end_context_switch)(struct task_struct *next);
9267-};
9268+} __no_const;
9269
9270 struct pv_irq_ops {
9271 /*
9272@@ -217,7 +217,7 @@ struct pv_apic_ops {
9273 unsigned long start_eip,
9274 unsigned long start_esp);
9275 #endif
9276-};
9277+} __no_const;
9278
9279 struct pv_mmu_ops {
9280 unsigned long (*read_cr2)(void);
9281@@ -316,6 +316,12 @@ struct pv_mmu_ops {
9282 an mfn. We can tell which is which from the index. */
9283 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
9284 phys_addr_t phys, pgprot_t flags);
9285+
9286+#ifdef CONFIG_PAX_KERNEXEC
9287+ unsigned long (*pax_open_kernel)(void);
9288+ unsigned long (*pax_close_kernel)(void);
9289+#endif
9290+
9291 };
9292
9293 struct raw_spinlock;
9294@@ -326,7 +332,7 @@ struct pv_lock_ops {
9295 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
9296 int (*spin_trylock)(struct raw_spinlock *lock);
9297 void (*spin_unlock)(struct raw_spinlock *lock);
9298-};
9299+} __no_const;
9300
9301 /* This contains all the paravirt structures: we get a convenient
9302 * number for each function using the offset which we use to indicate
9303diff -urNp linux-2.6.32.44/arch/x86/include/asm/pci_x86.h linux-2.6.32.44/arch/x86/include/asm/pci_x86.h
9304--- linux-2.6.32.44/arch/x86/include/asm/pci_x86.h 2011-03-27 14:31:47.000000000 -0400
9305+++ linux-2.6.32.44/arch/x86/include/asm/pci_x86.h 2011-04-17 15:56:46.000000000 -0400
9306@@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct
9307 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
9308
9309 struct pci_raw_ops {
9310- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
9311+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
9312 int reg, int len, u32 *val);
9313- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
9314+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
9315 int reg, int len, u32 val);
9316 };
9317
9318-extern struct pci_raw_ops *raw_pci_ops;
9319-extern struct pci_raw_ops *raw_pci_ext_ops;
9320+extern const struct pci_raw_ops *raw_pci_ops;
9321+extern const struct pci_raw_ops *raw_pci_ext_ops;
9322
9323-extern struct pci_raw_ops pci_direct_conf1;
9324+extern const struct pci_raw_ops pci_direct_conf1;
9325 extern bool port_cf9_safe;
9326
9327 /* arch_initcall level */
9328diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgalloc.h linux-2.6.32.44/arch/x86/include/asm/pgalloc.h
9329--- linux-2.6.32.44/arch/x86/include/asm/pgalloc.h 2011-03-27 14:31:47.000000000 -0400
9330+++ linux-2.6.32.44/arch/x86/include/asm/pgalloc.h 2011-04-17 15:56:46.000000000 -0400
9331@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
9332 pmd_t *pmd, pte_t *pte)
9333 {
9334 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9335+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
9336+}
9337+
9338+static inline void pmd_populate_user(struct mm_struct *mm,
9339+ pmd_t *pmd, pte_t *pte)
9340+{
9341+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9342 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
9343 }
9344
9345diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable-2level.h linux-2.6.32.44/arch/x86/include/asm/pgtable-2level.h
9346--- linux-2.6.32.44/arch/x86/include/asm/pgtable-2level.h 2011-03-27 14:31:47.000000000 -0400
9347+++ linux-2.6.32.44/arch/x86/include/asm/pgtable-2level.h 2011-04-17 15:56:46.000000000 -0400
9348@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
9349
9350 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9351 {
9352+ pax_open_kernel();
9353 *pmdp = pmd;
9354+ pax_close_kernel();
9355 }
9356
9357 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9358diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable_32.h linux-2.6.32.44/arch/x86/include/asm/pgtable_32.h
9359--- linux-2.6.32.44/arch/x86/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
9360+++ linux-2.6.32.44/arch/x86/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
9361@@ -26,9 +26,6 @@
9362 struct mm_struct;
9363 struct vm_area_struct;
9364
9365-extern pgd_t swapper_pg_dir[1024];
9366-extern pgd_t trampoline_pg_dir[1024];
9367-
9368 static inline void pgtable_cache_init(void) { }
9369 static inline void check_pgt_cache(void) { }
9370 void paging_init(void);
9371@@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, u
9372 # include <asm/pgtable-2level.h>
9373 #endif
9374
9375+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9376+extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
9377+#ifdef CONFIG_X86_PAE
9378+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9379+#endif
9380+
9381 #if defined(CONFIG_HIGHPTE)
9382 #define __KM_PTE \
9383 (in_nmi() ? KM_NMI_PTE : \
9384@@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, u
9385 /* Clear a kernel PTE and flush it from the TLB */
9386 #define kpte_clear_flush(ptep, vaddr) \
9387 do { \
9388+ pax_open_kernel(); \
9389 pte_clear(&init_mm, (vaddr), (ptep)); \
9390+ pax_close_kernel(); \
9391 __flush_tlb_one((vaddr)); \
9392 } while (0)
9393
9394@@ -85,6 +90,9 @@ do { \
9395
9396 #endif /* !__ASSEMBLY__ */
9397
9398+#define HAVE_ARCH_UNMAPPED_AREA
9399+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9400+
9401 /*
9402 * kern_addr_valid() is (1) for FLATMEM and (0) for
9403 * SPARSEMEM and DISCONTIGMEM
9404diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable_32_types.h linux-2.6.32.44/arch/x86/include/asm/pgtable_32_types.h
9405--- linux-2.6.32.44/arch/x86/include/asm/pgtable_32_types.h 2011-03-27 14:31:47.000000000 -0400
9406+++ linux-2.6.32.44/arch/x86/include/asm/pgtable_32_types.h 2011-04-17 15:56:46.000000000 -0400
9407@@ -8,7 +8,7 @@
9408 */
9409 #ifdef CONFIG_X86_PAE
9410 # include <asm/pgtable-3level_types.h>
9411-# define PMD_SIZE (1UL << PMD_SHIFT)
9412+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9413 # define PMD_MASK (~(PMD_SIZE - 1))
9414 #else
9415 # include <asm/pgtable-2level_types.h>
9416@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
9417 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9418 #endif
9419
9420+#ifdef CONFIG_PAX_KERNEXEC
9421+#ifndef __ASSEMBLY__
9422+extern unsigned char MODULES_EXEC_VADDR[];
9423+extern unsigned char MODULES_EXEC_END[];
9424+#endif
9425+#include <asm/boot.h>
9426+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9427+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9428+#else
9429+#define ktla_ktva(addr) (addr)
9430+#define ktva_ktla(addr) (addr)
9431+#endif
9432+
9433 #define MODULES_VADDR VMALLOC_START
9434 #define MODULES_END VMALLOC_END
9435 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9436diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable-3level.h linux-2.6.32.44/arch/x86/include/asm/pgtable-3level.h
9437--- linux-2.6.32.44/arch/x86/include/asm/pgtable-3level.h 2011-03-27 14:31:47.000000000 -0400
9438+++ linux-2.6.32.44/arch/x86/include/asm/pgtable-3level.h 2011-04-17 15:56:46.000000000 -0400
9439@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
9440
9441 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9442 {
9443+ pax_open_kernel();
9444 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9445+ pax_close_kernel();
9446 }
9447
9448 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9449 {
9450+ pax_open_kernel();
9451 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9452+ pax_close_kernel();
9453 }
9454
9455 /*
9456diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable_64.h linux-2.6.32.44/arch/x86/include/asm/pgtable_64.h
9457--- linux-2.6.32.44/arch/x86/include/asm/pgtable_64.h 2011-03-27 14:31:47.000000000 -0400
9458+++ linux-2.6.32.44/arch/x86/include/asm/pgtable_64.h 2011-04-17 15:56:46.000000000 -0400
9459@@ -16,10 +16,13 @@
9460
9461 extern pud_t level3_kernel_pgt[512];
9462 extern pud_t level3_ident_pgt[512];
9463+extern pud_t level3_vmalloc_pgt[512];
9464+extern pud_t level3_vmemmap_pgt[512];
9465+extern pud_t level2_vmemmap_pgt[512];
9466 extern pmd_t level2_kernel_pgt[512];
9467 extern pmd_t level2_fixmap_pgt[512];
9468-extern pmd_t level2_ident_pgt[512];
9469-extern pgd_t init_level4_pgt[];
9470+extern pmd_t level2_ident_pgt[512*2];
9471+extern pgd_t init_level4_pgt[512];
9472
9473 #define swapper_pg_dir init_level4_pgt
9474
9475@@ -74,7 +77,9 @@ static inline pte_t native_ptep_get_and_
9476
9477 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9478 {
9479+ pax_open_kernel();
9480 *pmdp = pmd;
9481+ pax_close_kernel();
9482 }
9483
9484 static inline void native_pmd_clear(pmd_t *pmd)
9485@@ -94,7 +99,9 @@ static inline void native_pud_clear(pud_
9486
9487 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9488 {
9489+ pax_open_kernel();
9490 *pgdp = pgd;
9491+ pax_close_kernel();
9492 }
9493
9494 static inline void native_pgd_clear(pgd_t *pgd)
9495diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable_64_types.h linux-2.6.32.44/arch/x86/include/asm/pgtable_64_types.h
9496--- linux-2.6.32.44/arch/x86/include/asm/pgtable_64_types.h 2011-03-27 14:31:47.000000000 -0400
9497+++ linux-2.6.32.44/arch/x86/include/asm/pgtable_64_types.h 2011-04-17 15:56:46.000000000 -0400
9498@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9499 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9500 #define MODULES_END _AC(0xffffffffff000000, UL)
9501 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9502+#define MODULES_EXEC_VADDR MODULES_VADDR
9503+#define MODULES_EXEC_END MODULES_END
9504+
9505+#define ktla_ktva(addr) (addr)
9506+#define ktva_ktla(addr) (addr)
9507
9508 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9509diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable.h linux-2.6.32.44/arch/x86/include/asm/pgtable.h
9510--- linux-2.6.32.44/arch/x86/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
9511+++ linux-2.6.32.44/arch/x86/include/asm/pgtable.h 2011-04-17 15:56:46.000000000 -0400
9512@@ -74,12 +74,51 @@ extern struct list_head pgd_list;
9513
9514 #define arch_end_context_switch(prev) do {} while(0)
9515
9516+#define pax_open_kernel() native_pax_open_kernel()
9517+#define pax_close_kernel() native_pax_close_kernel()
9518 #endif /* CONFIG_PARAVIRT */
9519
9520+#define __HAVE_ARCH_PAX_OPEN_KERNEL
9521+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9522+
9523+#ifdef CONFIG_PAX_KERNEXEC
9524+static inline unsigned long native_pax_open_kernel(void)
9525+{
9526+ unsigned long cr0;
9527+
9528+ preempt_disable();
9529+ barrier();
9530+ cr0 = read_cr0() ^ X86_CR0_WP;
9531+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
9532+ write_cr0(cr0);
9533+ return cr0 ^ X86_CR0_WP;
9534+}
9535+
9536+static inline unsigned long native_pax_close_kernel(void)
9537+{
9538+ unsigned long cr0;
9539+
9540+ cr0 = read_cr0() ^ X86_CR0_WP;
9541+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9542+ write_cr0(cr0);
9543+ barrier();
9544+ preempt_enable_no_resched();
9545+ return cr0 ^ X86_CR0_WP;
9546+}
9547+#else
9548+static inline unsigned long native_pax_open_kernel(void) { return 0; }
9549+static inline unsigned long native_pax_close_kernel(void) { return 0; }
9550+#endif
9551+
9552 /*
9553 * The following only work if pte_present() is true.
9554 * Undefined behaviour if not..
9555 */
9556+static inline int pte_user(pte_t pte)
9557+{
9558+ return pte_val(pte) & _PAGE_USER;
9559+}
9560+
9561 static inline int pte_dirty(pte_t pte)
9562 {
9563 return pte_flags(pte) & _PAGE_DIRTY;
9564@@ -167,9 +206,29 @@ static inline pte_t pte_wrprotect(pte_t
9565 return pte_clear_flags(pte, _PAGE_RW);
9566 }
9567
9568+static inline pte_t pte_mkread(pte_t pte)
9569+{
9570+ return __pte(pte_val(pte) | _PAGE_USER);
9571+}
9572+
9573 static inline pte_t pte_mkexec(pte_t pte)
9574 {
9575- return pte_clear_flags(pte, _PAGE_NX);
9576+#ifdef CONFIG_X86_PAE
9577+ if (__supported_pte_mask & _PAGE_NX)
9578+ return pte_clear_flags(pte, _PAGE_NX);
9579+ else
9580+#endif
9581+ return pte_set_flags(pte, _PAGE_USER);
9582+}
9583+
9584+static inline pte_t pte_exprotect(pte_t pte)
9585+{
9586+#ifdef CONFIG_X86_PAE
9587+ if (__supported_pte_mask & _PAGE_NX)
9588+ return pte_set_flags(pte, _PAGE_NX);
9589+ else
9590+#endif
9591+ return pte_clear_flags(pte, _PAGE_USER);
9592 }
9593
9594 static inline pte_t pte_mkdirty(pte_t pte)
9595@@ -302,6 +361,15 @@ pte_t *populate_extra_pte(unsigned long
9596 #endif
9597
9598 #ifndef __ASSEMBLY__
9599+
9600+#ifdef CONFIG_PAX_PER_CPU_PGD
9601+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9602+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9603+{
9604+ return cpu_pgd[cpu];
9605+}
9606+#endif
9607+
9608 #include <linux/mm_types.h>
9609
9610 static inline int pte_none(pte_t pte)
9611@@ -472,7 +540,7 @@ static inline pud_t *pud_offset(pgd_t *p
9612
9613 static inline int pgd_bad(pgd_t pgd)
9614 {
9615- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9616+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9617 }
9618
9619 static inline int pgd_none(pgd_t pgd)
9620@@ -495,7 +563,12 @@ static inline int pgd_none(pgd_t pgd)
9621 * pgd_offset() returns a (pgd_t *)
9622 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9623 */
9624-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9625+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9626+
9627+#ifdef CONFIG_PAX_PER_CPU_PGD
9628+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9629+#endif
9630+
9631 /*
9632 * a shortcut which implies the use of the kernel's pgd, instead
9633 * of a process's
9634@@ -506,6 +579,20 @@ static inline int pgd_none(pgd_t pgd)
9635 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9636 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9637
9638+#ifdef CONFIG_X86_32
9639+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9640+#else
9641+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9642+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9643+
9644+#ifdef CONFIG_PAX_MEMORY_UDEREF
9645+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9646+#else
9647+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9648+#endif
9649+
9650+#endif
9651+
9652 #ifndef __ASSEMBLY__
9653
9654 extern int direct_gbpages;
9655@@ -611,11 +698,23 @@ static inline void ptep_set_wrprotect(st
9656 * dst and src can be on the same page, but the range must not overlap,
9657 * and must not cross a page boundary.
9658 */
9659-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9660+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9661 {
9662- memcpy(dst, src, count * sizeof(pgd_t));
9663+ pax_open_kernel();
9664+ while (count--)
9665+ *dst++ = *src++;
9666+ pax_close_kernel();
9667 }
9668
9669+#ifdef CONFIG_PAX_PER_CPU_PGD
9670+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9671+#endif
9672+
9673+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9674+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9675+#else
9676+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9677+#endif
9678
9679 #include <asm-generic/pgtable.h>
9680 #endif /* __ASSEMBLY__ */
9681diff -urNp linux-2.6.32.44/arch/x86/include/asm/pgtable_types.h linux-2.6.32.44/arch/x86/include/asm/pgtable_types.h
9682--- linux-2.6.32.44/arch/x86/include/asm/pgtable_types.h 2011-03-27 14:31:47.000000000 -0400
9683+++ linux-2.6.32.44/arch/x86/include/asm/pgtable_types.h 2011-04-17 15:56:46.000000000 -0400
9684@@ -16,12 +16,11 @@
9685 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9686 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9687 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9688-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9689+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9690 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9691 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9692 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9693-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9694-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9695+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9696 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9697
9698 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9699@@ -39,7 +38,6 @@
9700 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9701 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9702 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9703-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9704 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9705 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9706 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9707@@ -55,8 +53,10 @@
9708
9709 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9710 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9711-#else
9712+#elif defined(CONFIG_KMEMCHECK)
9713 #define _PAGE_NX (_AT(pteval_t, 0))
9714+#else
9715+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9716 #endif
9717
9718 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9719@@ -93,6 +93,9 @@
9720 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9721 _PAGE_ACCESSED)
9722
9723+#define PAGE_READONLY_NOEXEC PAGE_READONLY
9724+#define PAGE_SHARED_NOEXEC PAGE_SHARED
9725+
9726 #define __PAGE_KERNEL_EXEC \
9727 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9728 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9729@@ -103,8 +106,8 @@
9730 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9731 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9732 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9733-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9734-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
9735+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9736+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
9737 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9738 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
9739 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
9740@@ -163,8 +166,8 @@
9741 * bits are combined, this will alow user to access the high address mapped
9742 * VDSO in the presence of CONFIG_COMPAT_VDSO
9743 */
9744-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9745-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9746+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9747+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9748 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9749 #endif
9750
9751@@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t p
9752 {
9753 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9754 }
9755+#endif
9756
9757+#if PAGETABLE_LEVELS == 3
9758+#include <asm-generic/pgtable-nopud.h>
9759+#endif
9760+
9761+#if PAGETABLE_LEVELS == 2
9762+#include <asm-generic/pgtable-nopmd.h>
9763+#endif
9764+
9765+#ifndef __ASSEMBLY__
9766 #if PAGETABLE_LEVELS > 3
9767 typedef struct { pudval_t pud; } pud_t;
9768
9769@@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pu
9770 return pud.pud;
9771 }
9772 #else
9773-#include <asm-generic/pgtable-nopud.h>
9774-
9775 static inline pudval_t native_pud_val(pud_t pud)
9776 {
9777 return native_pgd_val(pud.pgd);
9778@@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pm
9779 return pmd.pmd;
9780 }
9781 #else
9782-#include <asm-generic/pgtable-nopmd.h>
9783-
9784 static inline pmdval_t native_pmd_val(pmd_t pmd)
9785 {
9786 return native_pgd_val(pmd.pud.pgd);
9787@@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
9788
9789 extern pteval_t __supported_pte_mask;
9790 extern void set_nx(void);
9791+
9792+#ifdef CONFIG_X86_32
9793+#ifdef CONFIG_X86_PAE
9794 extern int nx_enabled;
9795+#else
9796+#define nx_enabled (0)
9797+#endif
9798+#else
9799+#define nx_enabled (1)
9800+#endif
9801
9802 #define pgprot_writecombine pgprot_writecombine
9803 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9804diff -urNp linux-2.6.32.44/arch/x86/include/asm/processor.h linux-2.6.32.44/arch/x86/include/asm/processor.h
9805--- linux-2.6.32.44/arch/x86/include/asm/processor.h 2011-04-22 19:16:29.000000000 -0400
9806+++ linux-2.6.32.44/arch/x86/include/asm/processor.h 2011-05-11 18:25:15.000000000 -0400
9807@@ -272,7 +272,7 @@ struct tss_struct {
9808
9809 } ____cacheline_aligned;
9810
9811-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
9812+extern struct tss_struct init_tss[NR_CPUS];
9813
9814 /*
9815 * Save the original ist values for checking stack pointers during debugging
9816@@ -888,11 +888,18 @@ static inline void spin_lock_prefetch(co
9817 */
9818 #define TASK_SIZE PAGE_OFFSET
9819 #define TASK_SIZE_MAX TASK_SIZE
9820+
9821+#ifdef CONFIG_PAX_SEGMEXEC
9822+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
9823+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
9824+#else
9825 #define STACK_TOP TASK_SIZE
9826-#define STACK_TOP_MAX STACK_TOP
9827+#endif
9828+
9829+#define STACK_TOP_MAX TASK_SIZE
9830
9831 #define INIT_THREAD { \
9832- .sp0 = sizeof(init_stack) + (long)&init_stack, \
9833+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9834 .vm86_info = NULL, \
9835 .sysenter_cs = __KERNEL_CS, \
9836 .io_bitmap_ptr = NULL, \
9837@@ -906,7 +913,7 @@ static inline void spin_lock_prefetch(co
9838 */
9839 #define INIT_TSS { \
9840 .x86_tss = { \
9841- .sp0 = sizeof(init_stack) + (long)&init_stack, \
9842+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9843 .ss0 = __KERNEL_DS, \
9844 .ss1 = __KERNEL_CS, \
9845 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
9846@@ -917,11 +924,7 @@ static inline void spin_lock_prefetch(co
9847 extern unsigned long thread_saved_pc(struct task_struct *tsk);
9848
9849 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
9850-#define KSTK_TOP(info) \
9851-({ \
9852- unsigned long *__ptr = (unsigned long *)(info); \
9853- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
9854-})
9855+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
9856
9857 /*
9858 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
9859@@ -936,7 +939,7 @@ extern unsigned long thread_saved_pc(str
9860 #define task_pt_regs(task) \
9861 ({ \
9862 struct pt_regs *__regs__; \
9863- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
9864+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
9865 __regs__ - 1; \
9866 })
9867
9868@@ -946,13 +949,13 @@ extern unsigned long thread_saved_pc(str
9869 /*
9870 * User space process size. 47bits minus one guard page.
9871 */
9872-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
9873+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
9874
9875 /* This decides where the kernel will search for a free chunk of vm
9876 * space during mmap's.
9877 */
9878 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
9879- 0xc0000000 : 0xFFFFe000)
9880+ 0xc0000000 : 0xFFFFf000)
9881
9882 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
9883 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
9884@@ -963,11 +966,11 @@ extern unsigned long thread_saved_pc(str
9885 #define STACK_TOP_MAX TASK_SIZE_MAX
9886
9887 #define INIT_THREAD { \
9888- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9889+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9890 }
9891
9892 #define INIT_TSS { \
9893- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9894+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9895 }
9896
9897 /*
9898@@ -989,6 +992,10 @@ extern void start_thread(struct pt_regs
9899 */
9900 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
9901
9902+#ifdef CONFIG_PAX_SEGMEXEC
9903+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
9904+#endif
9905+
9906 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
9907
9908 /* Get/set a process' ability to use the timestamp counter instruction */
9909diff -urNp linux-2.6.32.44/arch/x86/include/asm/ptrace.h linux-2.6.32.44/arch/x86/include/asm/ptrace.h
9910--- linux-2.6.32.44/arch/x86/include/asm/ptrace.h 2011-03-27 14:31:47.000000000 -0400
9911+++ linux-2.6.32.44/arch/x86/include/asm/ptrace.h 2011-04-17 15:56:46.000000000 -0400
9912@@ -151,28 +151,29 @@ static inline unsigned long regs_return_
9913 }
9914
9915 /*
9916- * user_mode_vm(regs) determines whether a register set came from user mode.
9917+ * user_mode(regs) determines whether a register set came from user mode.
9918 * This is true if V8086 mode was enabled OR if the register set was from
9919 * protected mode with RPL-3 CS value. This tricky test checks that with
9920 * one comparison. Many places in the kernel can bypass this full check
9921- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
9922+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
9923+ * be used.
9924 */
9925-static inline int user_mode(struct pt_regs *regs)
9926+static inline int user_mode_novm(struct pt_regs *regs)
9927 {
9928 #ifdef CONFIG_X86_32
9929 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
9930 #else
9931- return !!(regs->cs & 3);
9932+ return !!(regs->cs & SEGMENT_RPL_MASK);
9933 #endif
9934 }
9935
9936-static inline int user_mode_vm(struct pt_regs *regs)
9937+static inline int user_mode(struct pt_regs *regs)
9938 {
9939 #ifdef CONFIG_X86_32
9940 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
9941 USER_RPL;
9942 #else
9943- return user_mode(regs);
9944+ return user_mode_novm(regs);
9945 #endif
9946 }
9947
9948diff -urNp linux-2.6.32.44/arch/x86/include/asm/reboot.h linux-2.6.32.44/arch/x86/include/asm/reboot.h
9949--- linux-2.6.32.44/arch/x86/include/asm/reboot.h 2011-03-27 14:31:47.000000000 -0400
9950+++ linux-2.6.32.44/arch/x86/include/asm/reboot.h 2011-08-05 20:33:55.000000000 -0400
9951@@ -6,19 +6,19 @@
9952 struct pt_regs;
9953
9954 struct machine_ops {
9955- void (*restart)(char *cmd);
9956- void (*halt)(void);
9957- void (*power_off)(void);
9958+ void (* __noreturn restart)(char *cmd);
9959+ void (* __noreturn halt)(void);
9960+ void (* __noreturn power_off)(void);
9961 void (*shutdown)(void);
9962 void (*crash_shutdown)(struct pt_regs *);
9963- void (*emergency_restart)(void);
9964-};
9965+ void (* __noreturn emergency_restart)(void);
9966+} __no_const;
9967
9968 extern struct machine_ops machine_ops;
9969
9970 void native_machine_crash_shutdown(struct pt_regs *regs);
9971 void native_machine_shutdown(void);
9972-void machine_real_restart(const unsigned char *code, int length);
9973+void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
9974
9975 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
9976 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
9977diff -urNp linux-2.6.32.44/arch/x86/include/asm/rwsem.h linux-2.6.32.44/arch/x86/include/asm/rwsem.h
9978--- linux-2.6.32.44/arch/x86/include/asm/rwsem.h 2011-03-27 14:31:47.000000000 -0400
9979+++ linux-2.6.32.44/arch/x86/include/asm/rwsem.h 2011-04-17 15:56:46.000000000 -0400
9980@@ -118,6 +118,14 @@ static inline void __down_read(struct rw
9981 {
9982 asm volatile("# beginning down_read\n\t"
9983 LOCK_PREFIX _ASM_INC "(%1)\n\t"
9984+
9985+#ifdef CONFIG_PAX_REFCOUNT
9986+ "jno 0f\n"
9987+ LOCK_PREFIX _ASM_DEC "(%1)\n\t"
9988+ "int $4\n0:\n"
9989+ _ASM_EXTABLE(0b, 0b)
9990+#endif
9991+
9992 /* adds 0x00000001, returns the old value */
9993 " jns 1f\n"
9994 " call call_rwsem_down_read_failed\n"
9995@@ -139,6 +147,14 @@ static inline int __down_read_trylock(st
9996 "1:\n\t"
9997 " mov %1,%2\n\t"
9998 " add %3,%2\n\t"
9999+
10000+#ifdef CONFIG_PAX_REFCOUNT
10001+ "jno 0f\n"
10002+ "sub %3,%2\n"
10003+ "int $4\n0:\n"
10004+ _ASM_EXTABLE(0b, 0b)
10005+#endif
10006+
10007 " jle 2f\n\t"
10008 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10009 " jnz 1b\n\t"
10010@@ -160,6 +176,14 @@ static inline void __down_write_nested(s
10011 tmp = RWSEM_ACTIVE_WRITE_BIAS;
10012 asm volatile("# beginning down_write\n\t"
10013 LOCK_PREFIX " xadd %1,(%2)\n\t"
10014+
10015+#ifdef CONFIG_PAX_REFCOUNT
10016+ "jno 0f\n"
10017+ "mov %1,(%2)\n"
10018+ "int $4\n0:\n"
10019+ _ASM_EXTABLE(0b, 0b)
10020+#endif
10021+
10022 /* subtract 0x0000ffff, returns the old value */
10023 " test %1,%1\n\t"
10024 /* was the count 0 before? */
10025@@ -198,6 +222,14 @@ static inline void __up_read(struct rw_s
10026 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
10027 asm volatile("# beginning __up_read\n\t"
10028 LOCK_PREFIX " xadd %1,(%2)\n\t"
10029+
10030+#ifdef CONFIG_PAX_REFCOUNT
10031+ "jno 0f\n"
10032+ "mov %1,(%2)\n"
10033+ "int $4\n0:\n"
10034+ _ASM_EXTABLE(0b, 0b)
10035+#endif
10036+
10037 /* subtracts 1, returns the old value */
10038 " jns 1f\n\t"
10039 " call call_rwsem_wake\n"
10040@@ -216,6 +248,14 @@ static inline void __up_write(struct rw_
10041 rwsem_count_t tmp;
10042 asm volatile("# beginning __up_write\n\t"
10043 LOCK_PREFIX " xadd %1,(%2)\n\t"
10044+
10045+#ifdef CONFIG_PAX_REFCOUNT
10046+ "jno 0f\n"
10047+ "mov %1,(%2)\n"
10048+ "int $4\n0:\n"
10049+ _ASM_EXTABLE(0b, 0b)
10050+#endif
10051+
10052 /* tries to transition
10053 0xffff0001 -> 0x00000000 */
10054 " jz 1f\n"
10055@@ -234,6 +274,14 @@ static inline void __downgrade_write(str
10056 {
10057 asm volatile("# beginning __downgrade_write\n\t"
10058 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
10059+
10060+#ifdef CONFIG_PAX_REFCOUNT
10061+ "jno 0f\n"
10062+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
10063+ "int $4\n0:\n"
10064+ _ASM_EXTABLE(0b, 0b)
10065+#endif
10066+
10067 /*
10068 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
10069 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
10070@@ -253,7 +301,15 @@ static inline void __downgrade_write(str
10071 static inline void rwsem_atomic_add(rwsem_count_t delta,
10072 struct rw_semaphore *sem)
10073 {
10074- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
10075+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
10076+
10077+#ifdef CONFIG_PAX_REFCOUNT
10078+ "jno 0f\n"
10079+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
10080+ "int $4\n0:\n"
10081+ _ASM_EXTABLE(0b, 0b)
10082+#endif
10083+
10084 : "+m" (sem->count)
10085 : "er" (delta));
10086 }
10087@@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic
10088 {
10089 rwsem_count_t tmp = delta;
10090
10091- asm volatile(LOCK_PREFIX "xadd %0,%1"
10092+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
10093+
10094+#ifdef CONFIG_PAX_REFCOUNT
10095+ "jno 0f\n"
10096+ "mov %0,%1\n"
10097+ "int $4\n0:\n"
10098+ _ASM_EXTABLE(0b, 0b)
10099+#endif
10100+
10101 : "+r" (tmp), "+m" (sem->count)
10102 : : "memory");
10103
10104diff -urNp linux-2.6.32.44/arch/x86/include/asm/segment.h linux-2.6.32.44/arch/x86/include/asm/segment.h
10105--- linux-2.6.32.44/arch/x86/include/asm/segment.h 2011-03-27 14:31:47.000000000 -0400
10106+++ linux-2.6.32.44/arch/x86/include/asm/segment.h 2011-04-17 15:56:46.000000000 -0400
10107@@ -62,8 +62,8 @@
10108 * 26 - ESPFIX small SS
10109 * 27 - per-cpu [ offset to per-cpu data area ]
10110 * 28 - stack_canary-20 [ for stack protector ]
10111- * 29 - unused
10112- * 30 - unused
10113+ * 29 - PCI BIOS CS
10114+ * 30 - PCI BIOS DS
10115 * 31 - TSS for double fault handler
10116 */
10117 #define GDT_ENTRY_TLS_MIN 6
10118@@ -77,6 +77,8 @@
10119
10120 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
10121
10122+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
10123+
10124 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
10125
10126 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
10127@@ -88,7 +90,7 @@
10128 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
10129 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
10130
10131-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
10132+#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
10133 #ifdef CONFIG_SMP
10134 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
10135 #else
10136@@ -102,6 +104,12 @@
10137 #define __KERNEL_STACK_CANARY 0
10138 #endif
10139
10140+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
10141+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
10142+
10143+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
10144+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
10145+
10146 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
10147
10148 /*
10149@@ -139,7 +147,7 @@
10150 */
10151
10152 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
10153-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
10154+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
10155
10156
10157 #else
10158@@ -163,6 +171,8 @@
10159 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
10160 #define __USER32_DS __USER_DS
10161
10162+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
10163+
10164 #define GDT_ENTRY_TSS 8 /* needs two entries */
10165 #define GDT_ENTRY_LDT 10 /* needs two entries */
10166 #define GDT_ENTRY_TLS_MIN 12
10167@@ -183,6 +193,7 @@
10168 #endif
10169
10170 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
10171+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
10172 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
10173 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
10174 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
10175diff -urNp linux-2.6.32.44/arch/x86/include/asm/smp.h linux-2.6.32.44/arch/x86/include/asm/smp.h
10176--- linux-2.6.32.44/arch/x86/include/asm/smp.h 2011-03-27 14:31:47.000000000 -0400
10177+++ linux-2.6.32.44/arch/x86/include/asm/smp.h 2011-08-05 20:33:55.000000000 -0400
10178@@ -24,7 +24,7 @@ extern unsigned int num_processors;
10179 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
10180 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
10181 DECLARE_PER_CPU(u16, cpu_llc_id);
10182-DECLARE_PER_CPU(int, cpu_number);
10183+DECLARE_PER_CPU(unsigned int, cpu_number);
10184
10185 static inline struct cpumask *cpu_sibling_mask(int cpu)
10186 {
10187@@ -40,10 +40,7 @@ DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_ap
10188 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
10189
10190 /* Static state in head.S used to set up a CPU */
10191-extern struct {
10192- void *sp;
10193- unsigned short ss;
10194-} stack_start;
10195+extern unsigned long stack_start; /* Initial stack pointer address */
10196
10197 struct smp_ops {
10198 void (*smp_prepare_boot_cpu)(void);
10199@@ -60,7 +57,7 @@ struct smp_ops {
10200
10201 void (*send_call_func_ipi)(const struct cpumask *mask);
10202 void (*send_call_func_single_ipi)(int cpu);
10203-};
10204+} __no_const;
10205
10206 /* Globals due to paravirt */
10207 extern void set_cpu_sibling_map(int cpu);
10208@@ -175,14 +172,8 @@ extern unsigned disabled_cpus __cpuinitd
10209 extern int safe_smp_processor_id(void);
10210
10211 #elif defined(CONFIG_X86_64_SMP)
10212-#define raw_smp_processor_id() (percpu_read(cpu_number))
10213-
10214-#define stack_smp_processor_id() \
10215-({ \
10216- struct thread_info *ti; \
10217- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
10218- ti->cpu; \
10219-})
10220+#define raw_smp_processor_id() (percpu_read(cpu_number))
10221+#define stack_smp_processor_id() raw_smp_processor_id()
10222 #define safe_smp_processor_id() smp_processor_id()
10223
10224 #endif
10225diff -urNp linux-2.6.32.44/arch/x86/include/asm/spinlock.h linux-2.6.32.44/arch/x86/include/asm/spinlock.h
10226--- linux-2.6.32.44/arch/x86/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
10227+++ linux-2.6.32.44/arch/x86/include/asm/spinlock.h 2011-04-17 15:56:46.000000000 -0400
10228@@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(r
10229 static inline void __raw_read_lock(raw_rwlock_t *rw)
10230 {
10231 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
10232+
10233+#ifdef CONFIG_PAX_REFCOUNT
10234+ "jno 0f\n"
10235+ LOCK_PREFIX " addl $1,(%0)\n"
10236+ "int $4\n0:\n"
10237+ _ASM_EXTABLE(0b, 0b)
10238+#endif
10239+
10240 "jns 1f\n"
10241 "call __read_lock_failed\n\t"
10242 "1:\n"
10243@@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_r
10244 static inline void __raw_write_lock(raw_rwlock_t *rw)
10245 {
10246 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
10247+
10248+#ifdef CONFIG_PAX_REFCOUNT
10249+ "jno 0f\n"
10250+ LOCK_PREFIX " addl %1,(%0)\n"
10251+ "int $4\n0:\n"
10252+ _ASM_EXTABLE(0b, 0b)
10253+#endif
10254+
10255 "jz 1f\n"
10256 "call __write_lock_failed\n\t"
10257 "1:\n"
10258@@ -286,12 +302,29 @@ static inline int __raw_write_trylock(ra
10259
10260 static inline void __raw_read_unlock(raw_rwlock_t *rw)
10261 {
10262- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
10263+ asm volatile(LOCK_PREFIX "incl %0\n"
10264+
10265+#ifdef CONFIG_PAX_REFCOUNT
10266+ "jno 0f\n"
10267+ LOCK_PREFIX "decl %0\n"
10268+ "int $4\n0:\n"
10269+ _ASM_EXTABLE(0b, 0b)
10270+#endif
10271+
10272+ :"+m" (rw->lock) : : "memory");
10273 }
10274
10275 static inline void __raw_write_unlock(raw_rwlock_t *rw)
10276 {
10277- asm volatile(LOCK_PREFIX "addl %1, %0"
10278+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
10279+
10280+#ifdef CONFIG_PAX_REFCOUNT
10281+ "jno 0f\n"
10282+ LOCK_PREFIX "subl %1, %0\n"
10283+ "int $4\n0:\n"
10284+ _ASM_EXTABLE(0b, 0b)
10285+#endif
10286+
10287 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
10288 }
10289
10290diff -urNp linux-2.6.32.44/arch/x86/include/asm/stackprotector.h linux-2.6.32.44/arch/x86/include/asm/stackprotector.h
10291--- linux-2.6.32.44/arch/x86/include/asm/stackprotector.h 2011-03-27 14:31:47.000000000 -0400
10292+++ linux-2.6.32.44/arch/x86/include/asm/stackprotector.h 2011-07-06 19:53:33.000000000 -0400
10293@@ -48,7 +48,7 @@
10294 * head_32 for boot CPU and setup_per_cpu_areas() for others.
10295 */
10296 #define GDT_STACK_CANARY_INIT \
10297- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
10298+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
10299
10300 /*
10301 * Initialize the stackprotector canary value.
10302@@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
10303
10304 static inline void load_stack_canary_segment(void)
10305 {
10306-#ifdef CONFIG_X86_32
10307+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
10308 asm volatile ("mov %0, %%gs" : : "r" (0));
10309 #endif
10310 }
10311diff -urNp linux-2.6.32.44/arch/x86/include/asm/system.h linux-2.6.32.44/arch/x86/include/asm/system.h
10312--- linux-2.6.32.44/arch/x86/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
10313+++ linux-2.6.32.44/arch/x86/include/asm/system.h 2011-05-22 23:02:03.000000000 -0400
10314@@ -132,7 +132,7 @@ do { \
10315 "thread_return:\n\t" \
10316 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
10317 __switch_canary \
10318- "movq %P[thread_info](%%rsi),%%r8\n\t" \
10319+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
10320 "movq %%rax,%%rdi\n\t" \
10321 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
10322 "jnz ret_from_fork\n\t" \
10323@@ -143,7 +143,7 @@ do { \
10324 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
10325 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
10326 [_tif_fork] "i" (_TIF_FORK), \
10327- [thread_info] "i" (offsetof(struct task_struct, stack)), \
10328+ [thread_info] "m" (per_cpu_var(current_tinfo)), \
10329 [current_task] "m" (per_cpu_var(current_task)) \
10330 __switch_canary_iparam \
10331 : "memory", "cc" __EXTRA_CLOBBER)
10332@@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
10333 {
10334 unsigned long __limit;
10335 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
10336- return __limit + 1;
10337+ return __limit;
10338 }
10339
10340 static inline void native_clts(void)
10341@@ -340,12 +340,12 @@ void enable_hlt(void);
10342
10343 void cpu_idle_wait(void);
10344
10345-extern unsigned long arch_align_stack(unsigned long sp);
10346+#define arch_align_stack(x) ((x) & ~0xfUL)
10347 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
10348
10349 void default_idle(void);
10350
10351-void stop_this_cpu(void *dummy);
10352+void stop_this_cpu(void *dummy) __noreturn;
10353
10354 /*
10355 * Force strict CPU ordering.
10356diff -urNp linux-2.6.32.44/arch/x86/include/asm/thread_info.h linux-2.6.32.44/arch/x86/include/asm/thread_info.h
10357--- linux-2.6.32.44/arch/x86/include/asm/thread_info.h 2011-03-27 14:31:47.000000000 -0400
10358+++ linux-2.6.32.44/arch/x86/include/asm/thread_info.h 2011-05-17 19:26:34.000000000 -0400
10359@@ -10,6 +10,7 @@
10360 #include <linux/compiler.h>
10361 #include <asm/page.h>
10362 #include <asm/types.h>
10363+#include <asm/percpu.h>
10364
10365 /*
10366 * low level task data that entry.S needs immediate access to
10367@@ -24,7 +25,6 @@ struct exec_domain;
10368 #include <asm/atomic.h>
10369
10370 struct thread_info {
10371- struct task_struct *task; /* main task structure */
10372 struct exec_domain *exec_domain; /* execution domain */
10373 __u32 flags; /* low level flags */
10374 __u32 status; /* thread synchronous flags */
10375@@ -34,18 +34,12 @@ struct thread_info {
10376 mm_segment_t addr_limit;
10377 struct restart_block restart_block;
10378 void __user *sysenter_return;
10379-#ifdef CONFIG_X86_32
10380- unsigned long previous_esp; /* ESP of the previous stack in
10381- case of nested (IRQ) stacks
10382- */
10383- __u8 supervisor_stack[0];
10384-#endif
10385+ unsigned long lowest_stack;
10386 int uaccess_err;
10387 };
10388
10389-#define INIT_THREAD_INFO(tsk) \
10390+#define INIT_THREAD_INFO \
10391 { \
10392- .task = &tsk, \
10393 .exec_domain = &default_exec_domain, \
10394 .flags = 0, \
10395 .cpu = 0, \
10396@@ -56,7 +50,7 @@ struct thread_info {
10397 }, \
10398 }
10399
10400-#define init_thread_info (init_thread_union.thread_info)
10401+#define init_thread_info (init_thread_union.stack)
10402 #define init_stack (init_thread_union.stack)
10403
10404 #else /* !__ASSEMBLY__ */
10405@@ -163,6 +157,23 @@ struct thread_info {
10406 #define alloc_thread_info(tsk) \
10407 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
10408
10409+#ifdef __ASSEMBLY__
10410+/* how to get the thread information struct from ASM */
10411+#define GET_THREAD_INFO(reg) \
10412+ mov PER_CPU_VAR(current_tinfo), reg
10413+
10414+/* use this one if reg already contains %esp */
10415+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10416+#else
10417+/* how to get the thread information struct from C */
10418+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10419+
10420+static __always_inline struct thread_info *current_thread_info(void)
10421+{
10422+ return percpu_read_stable(current_tinfo);
10423+}
10424+#endif
10425+
10426 #ifdef CONFIG_X86_32
10427
10428 #define STACK_WARN (THREAD_SIZE/8)
10429@@ -173,35 +184,13 @@ struct thread_info {
10430 */
10431 #ifndef __ASSEMBLY__
10432
10433-
10434 /* how to get the current stack pointer from C */
10435 register unsigned long current_stack_pointer asm("esp") __used;
10436
10437-/* how to get the thread information struct from C */
10438-static inline struct thread_info *current_thread_info(void)
10439-{
10440- return (struct thread_info *)
10441- (current_stack_pointer & ~(THREAD_SIZE - 1));
10442-}
10443-
10444-#else /* !__ASSEMBLY__ */
10445-
10446-/* how to get the thread information struct from ASM */
10447-#define GET_THREAD_INFO(reg) \
10448- movl $-THREAD_SIZE, reg; \
10449- andl %esp, reg
10450-
10451-/* use this one if reg already contains %esp */
10452-#define GET_THREAD_INFO_WITH_ESP(reg) \
10453- andl $-THREAD_SIZE, reg
10454-
10455 #endif
10456
10457 #else /* X86_32 */
10458
10459-#include <asm/percpu.h>
10460-#define KERNEL_STACK_OFFSET (5*8)
10461-
10462 /*
10463 * macros/functions for gaining access to the thread information structure
10464 * preempt_count needs to be 1 initially, until the scheduler is functional.
10465@@ -209,21 +198,8 @@ static inline struct thread_info *curren
10466 #ifndef __ASSEMBLY__
10467 DECLARE_PER_CPU(unsigned long, kernel_stack);
10468
10469-static inline struct thread_info *current_thread_info(void)
10470-{
10471- struct thread_info *ti;
10472- ti = (void *)(percpu_read_stable(kernel_stack) +
10473- KERNEL_STACK_OFFSET - THREAD_SIZE);
10474- return ti;
10475-}
10476-
10477-#else /* !__ASSEMBLY__ */
10478-
10479-/* how to get the thread information struct from ASM */
10480-#define GET_THREAD_INFO(reg) \
10481- movq PER_CPU_VAR(kernel_stack),reg ; \
10482- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10483-
10484+/* how to get the current stack pointer from C */
10485+register unsigned long current_stack_pointer asm("rsp") __used;
10486 #endif
10487
10488 #endif /* !X86_32 */
10489@@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
10490 extern void free_thread_info(struct thread_info *ti);
10491 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10492 #define arch_task_cache_init arch_task_cache_init
10493+
10494+#define __HAVE_THREAD_FUNCTIONS
10495+#define task_thread_info(task) (&(task)->tinfo)
10496+#define task_stack_page(task) ((task)->stack)
10497+#define setup_thread_stack(p, org) do {} while (0)
10498+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10499+
10500+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10501+extern struct task_struct *alloc_task_struct(void);
10502+extern void free_task_struct(struct task_struct *);
10503+
10504 #endif
10505 #endif /* _ASM_X86_THREAD_INFO_H */
10506diff -urNp linux-2.6.32.44/arch/x86/include/asm/uaccess_32.h linux-2.6.32.44/arch/x86/include/asm/uaccess_32.h
10507--- linux-2.6.32.44/arch/x86/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
10508+++ linux-2.6.32.44/arch/x86/include/asm/uaccess_32.h 2011-05-16 21:46:57.000000000 -0400
10509@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
10510 static __always_inline unsigned long __must_check
10511 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10512 {
10513+ pax_track_stack();
10514+
10515+ if ((long)n < 0)
10516+ return n;
10517+
10518 if (__builtin_constant_p(n)) {
10519 unsigned long ret;
10520
10521@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
10522 return ret;
10523 }
10524 }
10525+ if (!__builtin_constant_p(n))
10526+ check_object_size(from, n, true);
10527 return __copy_to_user_ll(to, from, n);
10528 }
10529
10530@@ -83,12 +90,16 @@ static __always_inline unsigned long __m
10531 __copy_to_user(void __user *to, const void *from, unsigned long n)
10532 {
10533 might_fault();
10534+
10535 return __copy_to_user_inatomic(to, from, n);
10536 }
10537
10538 static __always_inline unsigned long
10539 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
10540 {
10541+ if ((long)n < 0)
10542+ return n;
10543+
10544 /* Avoid zeroing the tail if the copy fails..
10545 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
10546 * but as the zeroing behaviour is only significant when n is not
10547@@ -138,6 +149,12 @@ static __always_inline unsigned long
10548 __copy_from_user(void *to, const void __user *from, unsigned long n)
10549 {
10550 might_fault();
10551+
10552+ pax_track_stack();
10553+
10554+ if ((long)n < 0)
10555+ return n;
10556+
10557 if (__builtin_constant_p(n)) {
10558 unsigned long ret;
10559
10560@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
10561 return ret;
10562 }
10563 }
10564+ if (!__builtin_constant_p(n))
10565+ check_object_size(to, n, false);
10566 return __copy_from_user_ll(to, from, n);
10567 }
10568
10569@@ -160,6 +179,10 @@ static __always_inline unsigned long __c
10570 const void __user *from, unsigned long n)
10571 {
10572 might_fault();
10573+
10574+ if ((long)n < 0)
10575+ return n;
10576+
10577 if (__builtin_constant_p(n)) {
10578 unsigned long ret;
10579
10580@@ -182,14 +205,62 @@ static __always_inline unsigned long
10581 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
10582 unsigned long n)
10583 {
10584- return __copy_from_user_ll_nocache_nozero(to, from, n);
10585+ if ((long)n < 0)
10586+ return n;
10587+
10588+ return __copy_from_user_ll_nocache_nozero(to, from, n);
10589+}
10590+
10591+/**
10592+ * copy_to_user: - Copy a block of data into user space.
10593+ * @to: Destination address, in user space.
10594+ * @from: Source address, in kernel space.
10595+ * @n: Number of bytes to copy.
10596+ *
10597+ * Context: User context only. This function may sleep.
10598+ *
10599+ * Copy data from kernel space to user space.
10600+ *
10601+ * Returns number of bytes that could not be copied.
10602+ * On success, this will be zero.
10603+ */
10604+static __always_inline unsigned long __must_check
10605+copy_to_user(void __user *to, const void *from, unsigned long n)
10606+{
10607+ if (access_ok(VERIFY_WRITE, to, n))
10608+ n = __copy_to_user(to, from, n);
10609+ return n;
10610+}
10611+
10612+/**
10613+ * copy_from_user: - Copy a block of data from user space.
10614+ * @to: Destination address, in kernel space.
10615+ * @from: Source address, in user space.
10616+ * @n: Number of bytes to copy.
10617+ *
10618+ * Context: User context only. This function may sleep.
10619+ *
10620+ * Copy data from user space to kernel space.
10621+ *
10622+ * Returns number of bytes that could not be copied.
10623+ * On success, this will be zero.
10624+ *
10625+ * If some data could not be copied, this function will pad the copied
10626+ * data to the requested size using zero bytes.
10627+ */
10628+static __always_inline unsigned long __must_check
10629+copy_from_user(void *to, const void __user *from, unsigned long n)
10630+{
10631+ if (access_ok(VERIFY_READ, from, n))
10632+ n = __copy_from_user(to, from, n);
10633+ else if ((long)n > 0) {
10634+ if (!__builtin_constant_p(n))
10635+ check_object_size(to, n, false);
10636+ memset(to, 0, n);
10637+ }
10638+ return n;
10639 }
10640
10641-unsigned long __must_check copy_to_user(void __user *to,
10642- const void *from, unsigned long n);
10643-unsigned long __must_check copy_from_user(void *to,
10644- const void __user *from,
10645- unsigned long n);
10646 long __must_check strncpy_from_user(char *dst, const char __user *src,
10647 long count);
10648 long __must_check __strncpy_from_user(char *dst,
10649diff -urNp linux-2.6.32.44/arch/x86/include/asm/uaccess_64.h linux-2.6.32.44/arch/x86/include/asm/uaccess_64.h
10650--- linux-2.6.32.44/arch/x86/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
10651+++ linux-2.6.32.44/arch/x86/include/asm/uaccess_64.h 2011-05-16 21:46:57.000000000 -0400
10652@@ -9,6 +9,9 @@
10653 #include <linux/prefetch.h>
10654 #include <linux/lockdep.h>
10655 #include <asm/page.h>
10656+#include <asm/pgtable.h>
10657+
10658+#define set_fs(x) (current_thread_info()->addr_limit = (x))
10659
10660 /*
10661 * Copy To/From Userspace
10662@@ -19,113 +22,203 @@ __must_check unsigned long
10663 copy_user_generic(void *to, const void *from, unsigned len);
10664
10665 __must_check unsigned long
10666-copy_to_user(void __user *to, const void *from, unsigned len);
10667-__must_check unsigned long
10668-copy_from_user(void *to, const void __user *from, unsigned len);
10669-__must_check unsigned long
10670 copy_in_user(void __user *to, const void __user *from, unsigned len);
10671
10672 static __always_inline __must_check
10673-int __copy_from_user(void *dst, const void __user *src, unsigned size)
10674+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
10675 {
10676- int ret = 0;
10677+ unsigned ret = 0;
10678
10679 might_fault();
10680- if (!__builtin_constant_p(size))
10681- return copy_user_generic(dst, (__force void *)src, size);
10682+
10683+ if ((int)size < 0)
10684+ return size;
10685+
10686+#ifdef CONFIG_PAX_MEMORY_UDEREF
10687+ if (!__access_ok(VERIFY_READ, src, size))
10688+ return size;
10689+#endif
10690+
10691+ if (!__builtin_constant_p(size)) {
10692+ check_object_size(dst, size, false);
10693+
10694+#ifdef CONFIG_PAX_MEMORY_UDEREF
10695+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10696+ src += PAX_USER_SHADOW_BASE;
10697+#endif
10698+
10699+ return copy_user_generic(dst, (__force const void *)src, size);
10700+ }
10701 switch (size) {
10702- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
10703+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
10704 ret, "b", "b", "=q", 1);
10705 return ret;
10706- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
10707+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
10708 ret, "w", "w", "=r", 2);
10709 return ret;
10710- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
10711+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
10712 ret, "l", "k", "=r", 4);
10713 return ret;
10714- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
10715+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10716 ret, "q", "", "=r", 8);
10717 return ret;
10718 case 10:
10719- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10720+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10721 ret, "q", "", "=r", 10);
10722 if (unlikely(ret))
10723 return ret;
10724 __get_user_asm(*(u16 *)(8 + (char *)dst),
10725- (u16 __user *)(8 + (char __user *)src),
10726+ (const u16 __user *)(8 + (const char __user *)src),
10727 ret, "w", "w", "=r", 2);
10728 return ret;
10729 case 16:
10730- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10731+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10732 ret, "q", "", "=r", 16);
10733 if (unlikely(ret))
10734 return ret;
10735 __get_user_asm(*(u64 *)(8 + (char *)dst),
10736- (u64 __user *)(8 + (char __user *)src),
10737+ (const u64 __user *)(8 + (const char __user *)src),
10738 ret, "q", "", "=r", 8);
10739 return ret;
10740 default:
10741- return copy_user_generic(dst, (__force void *)src, size);
10742+
10743+#ifdef CONFIG_PAX_MEMORY_UDEREF
10744+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10745+ src += PAX_USER_SHADOW_BASE;
10746+#endif
10747+
10748+ return copy_user_generic(dst, (__force const void *)src, size);
10749 }
10750 }
10751
10752 static __always_inline __must_check
10753-int __copy_to_user(void __user *dst, const void *src, unsigned size)
10754+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
10755 {
10756- int ret = 0;
10757+ unsigned ret = 0;
10758
10759 might_fault();
10760- if (!__builtin_constant_p(size))
10761+
10762+ pax_track_stack();
10763+
10764+ if ((int)size < 0)
10765+ return size;
10766+
10767+#ifdef CONFIG_PAX_MEMORY_UDEREF
10768+ if (!__access_ok(VERIFY_WRITE, dst, size))
10769+ return size;
10770+#endif
10771+
10772+ if (!__builtin_constant_p(size)) {
10773+ check_object_size(src, size, true);
10774+
10775+#ifdef CONFIG_PAX_MEMORY_UDEREF
10776+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10777+ dst += PAX_USER_SHADOW_BASE;
10778+#endif
10779+
10780 return copy_user_generic((__force void *)dst, src, size);
10781+ }
10782 switch (size) {
10783- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
10784+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
10785 ret, "b", "b", "iq", 1);
10786 return ret;
10787- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
10788+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
10789 ret, "w", "w", "ir", 2);
10790 return ret;
10791- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
10792+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
10793 ret, "l", "k", "ir", 4);
10794 return ret;
10795- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
10796+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10797 ret, "q", "", "er", 8);
10798 return ret;
10799 case 10:
10800- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
10801+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10802 ret, "q", "", "er", 10);
10803 if (unlikely(ret))
10804 return ret;
10805 asm("":::"memory");
10806- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
10807+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
10808 ret, "w", "w", "ir", 2);
10809 return ret;
10810 case 16:
10811- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
10812+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10813 ret, "q", "", "er", 16);
10814 if (unlikely(ret))
10815 return ret;
10816 asm("":::"memory");
10817- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
10818+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
10819 ret, "q", "", "er", 8);
10820 return ret;
10821 default:
10822+
10823+#ifdef CONFIG_PAX_MEMORY_UDEREF
10824+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10825+ dst += PAX_USER_SHADOW_BASE;
10826+#endif
10827+
10828 return copy_user_generic((__force void *)dst, src, size);
10829 }
10830 }
10831
10832 static __always_inline __must_check
10833-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
10834+unsigned long copy_to_user(void __user *to, const void *from, unsigned len)
10835+{
10836+ if (access_ok(VERIFY_WRITE, to, len))
10837+ len = __copy_to_user(to, from, len);
10838+ return len;
10839+}
10840+
10841+static __always_inline __must_check
10842+unsigned long copy_from_user(void *to, const void __user *from, unsigned len)
10843+{
10844+ if ((int)len < 0)
10845+ return len;
10846+
10847+ if (access_ok(VERIFY_READ, from, len))
10848+ len = __copy_from_user(to, from, len);
10849+ else if ((int)len > 0) {
10850+ if (!__builtin_constant_p(len))
10851+ check_object_size(to, len, false);
10852+ memset(to, 0, len);
10853+ }
10854+ return len;
10855+}
10856+
10857+static __always_inline __must_check
10858+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
10859 {
10860- int ret = 0;
10861+ unsigned ret = 0;
10862
10863 might_fault();
10864- if (!__builtin_constant_p(size))
10865+
10866+ pax_track_stack();
10867+
10868+ if ((int)size < 0)
10869+ return size;
10870+
10871+#ifdef CONFIG_PAX_MEMORY_UDEREF
10872+ if (!__access_ok(VERIFY_READ, src, size))
10873+ return size;
10874+ if (!__access_ok(VERIFY_WRITE, dst, size))
10875+ return size;
10876+#endif
10877+
10878+ if (!__builtin_constant_p(size)) {
10879+
10880+#ifdef CONFIG_PAX_MEMORY_UDEREF
10881+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10882+ src += PAX_USER_SHADOW_BASE;
10883+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10884+ dst += PAX_USER_SHADOW_BASE;
10885+#endif
10886+
10887 return copy_user_generic((__force void *)dst,
10888- (__force void *)src, size);
10889+ (__force const void *)src, size);
10890+ }
10891 switch (size) {
10892 case 1: {
10893 u8 tmp;
10894- __get_user_asm(tmp, (u8 __user *)src,
10895+ __get_user_asm(tmp, (const u8 __user *)src,
10896 ret, "b", "b", "=q", 1);
10897 if (likely(!ret))
10898 __put_user_asm(tmp, (u8 __user *)dst,
10899@@ -134,7 +227,7 @@ int __copy_in_user(void __user *dst, con
10900 }
10901 case 2: {
10902 u16 tmp;
10903- __get_user_asm(tmp, (u16 __user *)src,
10904+ __get_user_asm(tmp, (const u16 __user *)src,
10905 ret, "w", "w", "=r", 2);
10906 if (likely(!ret))
10907 __put_user_asm(tmp, (u16 __user *)dst,
10908@@ -144,7 +237,7 @@ int __copy_in_user(void __user *dst, con
10909
10910 case 4: {
10911 u32 tmp;
10912- __get_user_asm(tmp, (u32 __user *)src,
10913+ __get_user_asm(tmp, (const u32 __user *)src,
10914 ret, "l", "k", "=r", 4);
10915 if (likely(!ret))
10916 __put_user_asm(tmp, (u32 __user *)dst,
10917@@ -153,7 +246,7 @@ int __copy_in_user(void __user *dst, con
10918 }
10919 case 8: {
10920 u64 tmp;
10921- __get_user_asm(tmp, (u64 __user *)src,
10922+ __get_user_asm(tmp, (const u64 __user *)src,
10923 ret, "q", "", "=r", 8);
10924 if (likely(!ret))
10925 __put_user_asm(tmp, (u64 __user *)dst,
10926@@ -161,8 +254,16 @@ int __copy_in_user(void __user *dst, con
10927 return ret;
10928 }
10929 default:
10930+
10931+#ifdef CONFIG_PAX_MEMORY_UDEREF
10932+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10933+ src += PAX_USER_SHADOW_BASE;
10934+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10935+ dst += PAX_USER_SHADOW_BASE;
10936+#endif
10937+
10938 return copy_user_generic((__force void *)dst,
10939- (__force void *)src, size);
10940+ (__force const void *)src, size);
10941 }
10942 }
10943
10944@@ -176,33 +277,75 @@ __must_check long strlen_user(const char
10945 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
10946 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
10947
10948-__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
10949- unsigned size);
10950+static __must_check __always_inline unsigned long
10951+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
10952+{
10953+ pax_track_stack();
10954+
10955+ if ((int)size < 0)
10956+ return size;
10957
10958-static __must_check __always_inline int
10959+#ifdef CONFIG_PAX_MEMORY_UDEREF
10960+ if (!__access_ok(VERIFY_READ, src, size))
10961+ return size;
10962+
10963+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10964+ src += PAX_USER_SHADOW_BASE;
10965+#endif
10966+
10967+ return copy_user_generic(dst, (__force const void *)src, size);
10968+}
10969+
10970+static __must_check __always_inline unsigned long
10971 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
10972 {
10973+ if ((int)size < 0)
10974+ return size;
10975+
10976+#ifdef CONFIG_PAX_MEMORY_UDEREF
10977+ if (!__access_ok(VERIFY_WRITE, dst, size))
10978+ return size;
10979+
10980+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10981+ dst += PAX_USER_SHADOW_BASE;
10982+#endif
10983+
10984 return copy_user_generic((__force void *)dst, src, size);
10985 }
10986
10987-extern long __copy_user_nocache(void *dst, const void __user *src,
10988+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
10989 unsigned size, int zerorest);
10990
10991-static inline int
10992-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
10993+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
10994 {
10995 might_sleep();
10996+
10997+ if ((int)size < 0)
10998+ return size;
10999+
11000+#ifdef CONFIG_PAX_MEMORY_UDEREF
11001+ if (!__access_ok(VERIFY_READ, src, size))
11002+ return size;
11003+#endif
11004+
11005 return __copy_user_nocache(dst, src, size, 1);
11006 }
11007
11008-static inline int
11009-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11010+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11011 unsigned size)
11012 {
11013+ if ((int)size < 0)
11014+ return size;
11015+
11016+#ifdef CONFIG_PAX_MEMORY_UDEREF
11017+ if (!__access_ok(VERIFY_READ, src, size))
11018+ return size;
11019+#endif
11020+
11021 return __copy_user_nocache(dst, src, size, 0);
11022 }
11023
11024-unsigned long
11025+extern unsigned long
11026 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
11027
11028 #endif /* _ASM_X86_UACCESS_64_H */
11029diff -urNp linux-2.6.32.44/arch/x86/include/asm/uaccess.h linux-2.6.32.44/arch/x86/include/asm/uaccess.h
11030--- linux-2.6.32.44/arch/x86/include/asm/uaccess.h 2011-06-25 12:55:34.000000000 -0400
11031+++ linux-2.6.32.44/arch/x86/include/asm/uaccess.h 2011-06-25 12:56:37.000000000 -0400
11032@@ -8,12 +8,15 @@
11033 #include <linux/thread_info.h>
11034 #include <linux/prefetch.h>
11035 #include <linux/string.h>
11036+#include <linux/sched.h>
11037 #include <asm/asm.h>
11038 #include <asm/page.h>
11039
11040 #define VERIFY_READ 0
11041 #define VERIFY_WRITE 1
11042
11043+extern void check_object_size(const void *ptr, unsigned long n, bool to);
11044+
11045 /*
11046 * The fs value determines whether argument validity checking should be
11047 * performed or not. If get_fs() == USER_DS, checking is performed, with
11048@@ -29,7 +32,12 @@
11049
11050 #define get_ds() (KERNEL_DS)
11051 #define get_fs() (current_thread_info()->addr_limit)
11052+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11053+void __set_fs(mm_segment_t x);
11054+void set_fs(mm_segment_t x);
11055+#else
11056 #define set_fs(x) (current_thread_info()->addr_limit = (x))
11057+#endif
11058
11059 #define segment_eq(a, b) ((a).seg == (b).seg)
11060
11061@@ -77,7 +85,33 @@
11062 * checks that the pointer is in the user space range - after calling
11063 * this function, memory access functions may still return -EFAULT.
11064 */
11065-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11066+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11067+#define access_ok(type, addr, size) \
11068+({ \
11069+ long __size = size; \
11070+ unsigned long __addr = (unsigned long)addr; \
11071+ unsigned long __addr_ao = __addr & PAGE_MASK; \
11072+ unsigned long __end_ao = __addr + __size - 1; \
11073+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
11074+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
11075+ while(__addr_ao <= __end_ao) { \
11076+ char __c_ao; \
11077+ __addr_ao += PAGE_SIZE; \
11078+ if (__size > PAGE_SIZE) \
11079+ cond_resched(); \
11080+ if (__get_user(__c_ao, (char __user *)__addr)) \
11081+ break; \
11082+ if (type != VERIFY_WRITE) { \
11083+ __addr = __addr_ao; \
11084+ continue; \
11085+ } \
11086+ if (__put_user(__c_ao, (char __user *)__addr)) \
11087+ break; \
11088+ __addr = __addr_ao; \
11089+ } \
11090+ } \
11091+ __ret_ao; \
11092+})
11093
11094 /*
11095 * The exception table consists of pairs of addresses: the first is the
11096@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
11097 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
11098 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
11099
11100-
11101+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11102+#define __copyuser_seg "gs;"
11103+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
11104+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
11105+#else
11106+#define __copyuser_seg
11107+#define __COPYUSER_SET_ES
11108+#define __COPYUSER_RESTORE_ES
11109+#endif
11110
11111 #ifdef CONFIG_X86_32
11112 #define __put_user_asm_u64(x, addr, err, errret) \
11113- asm volatile("1: movl %%eax,0(%2)\n" \
11114- "2: movl %%edx,4(%2)\n" \
11115+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
11116+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
11117 "3:\n" \
11118 ".section .fixup,\"ax\"\n" \
11119 "4: movl %3,%0\n" \
11120@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
11121 : "A" (x), "r" (addr), "i" (errret), "0" (err))
11122
11123 #define __put_user_asm_ex_u64(x, addr) \
11124- asm volatile("1: movl %%eax,0(%1)\n" \
11125- "2: movl %%edx,4(%1)\n" \
11126+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
11127+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
11128 "3:\n" \
11129 _ASM_EXTABLE(1b, 2b - 1b) \
11130 _ASM_EXTABLE(2b, 3b - 2b) \
11131@@ -374,7 +416,7 @@ do { \
11132 } while (0)
11133
11134 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11135- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
11136+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
11137 "2:\n" \
11138 ".section .fixup,\"ax\"\n" \
11139 "3: mov %3,%0\n" \
11140@@ -382,7 +424,7 @@ do { \
11141 " jmp 2b\n" \
11142 ".previous\n" \
11143 _ASM_EXTABLE(1b, 3b) \
11144- : "=r" (err), ltype(x) \
11145+ : "=r" (err), ltype (x) \
11146 : "m" (__m(addr)), "i" (errret), "0" (err))
11147
11148 #define __get_user_size_ex(x, ptr, size) \
11149@@ -407,7 +449,7 @@ do { \
11150 } while (0)
11151
11152 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
11153- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
11154+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
11155 "2:\n" \
11156 _ASM_EXTABLE(1b, 2b - 1b) \
11157 : ltype(x) : "m" (__m(addr)))
11158@@ -424,13 +466,24 @@ do { \
11159 int __gu_err; \
11160 unsigned long __gu_val; \
11161 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
11162- (x) = (__force __typeof__(*(ptr)))__gu_val; \
11163+ (x) = (__typeof__(*(ptr)))__gu_val; \
11164 __gu_err; \
11165 })
11166
11167 /* FIXME: this hack is definitely wrong -AK */
11168 struct __large_struct { unsigned long buf[100]; };
11169-#define __m(x) (*(struct __large_struct __user *)(x))
11170+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11171+#define ____m(x) \
11172+({ \
11173+ unsigned long ____x = (unsigned long)(x); \
11174+ if (____x < PAX_USER_SHADOW_BASE) \
11175+ ____x += PAX_USER_SHADOW_BASE; \
11176+ (void __user *)____x; \
11177+})
11178+#else
11179+#define ____m(x) (x)
11180+#endif
11181+#define __m(x) (*(struct __large_struct __user *)____m(x))
11182
11183 /*
11184 * Tell gcc we read from memory instead of writing: this is because
11185@@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
11186 * aliasing issues.
11187 */
11188 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11189- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
11190+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
11191 "2:\n" \
11192 ".section .fixup,\"ax\"\n" \
11193 "3: mov %3,%0\n" \
11194@@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
11195 ".previous\n" \
11196 _ASM_EXTABLE(1b, 3b) \
11197 : "=r"(err) \
11198- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
11199+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
11200
11201 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
11202- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
11203+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
11204 "2:\n" \
11205 _ASM_EXTABLE(1b, 2b - 1b) \
11206 : : ltype(x), "m" (__m(addr)))
11207@@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
11208 * On error, the variable @x is set to zero.
11209 */
11210
11211+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11212+#define __get_user(x, ptr) get_user((x), (ptr))
11213+#else
11214 #define __get_user(x, ptr) \
11215 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
11216+#endif
11217
11218 /**
11219 * __put_user: - Write a simple value into user space, with less checking.
11220@@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
11221 * Returns zero on success, or -EFAULT on error.
11222 */
11223
11224+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11225+#define __put_user(x, ptr) put_user((x), (ptr))
11226+#else
11227 #define __put_user(x, ptr) \
11228 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
11229+#endif
11230
11231 #define __get_user_unaligned __get_user
11232 #define __put_user_unaligned __put_user
11233@@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
11234 #define get_user_ex(x, ptr) do { \
11235 unsigned long __gue_val; \
11236 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
11237- (x) = (__force __typeof__(*(ptr)))__gue_val; \
11238+ (x) = (__typeof__(*(ptr)))__gue_val; \
11239 } while (0)
11240
11241 #ifdef CONFIG_X86_WP_WORKS_OK
11242@@ -567,6 +628,7 @@ extern struct movsl_mask {
11243
11244 #define ARCH_HAS_NOCACHE_UACCESS 1
11245
11246+#define ARCH_HAS_SORT_EXTABLE
11247 #ifdef CONFIG_X86_32
11248 # include "uaccess_32.h"
11249 #else
11250diff -urNp linux-2.6.32.44/arch/x86/include/asm/vgtod.h linux-2.6.32.44/arch/x86/include/asm/vgtod.h
11251--- linux-2.6.32.44/arch/x86/include/asm/vgtod.h 2011-03-27 14:31:47.000000000 -0400
11252+++ linux-2.6.32.44/arch/x86/include/asm/vgtod.h 2011-04-17 15:56:46.000000000 -0400
11253@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
11254 int sysctl_enabled;
11255 struct timezone sys_tz;
11256 struct { /* extract of a clocksource struct */
11257+ char name[8];
11258 cycle_t (*vread)(void);
11259 cycle_t cycle_last;
11260 cycle_t mask;
11261diff -urNp linux-2.6.32.44/arch/x86/include/asm/vmi.h linux-2.6.32.44/arch/x86/include/asm/vmi.h
11262--- linux-2.6.32.44/arch/x86/include/asm/vmi.h 2011-03-27 14:31:47.000000000 -0400
11263+++ linux-2.6.32.44/arch/x86/include/asm/vmi.h 2011-04-17 15:56:46.000000000 -0400
11264@@ -191,6 +191,7 @@ struct vrom_header {
11265 u8 reserved[96]; /* Reserved for headers */
11266 char vmi_init[8]; /* VMI_Init jump point */
11267 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
11268+ char rom_data[8048]; /* rest of the option ROM */
11269 } __attribute__((packed));
11270
11271 struct pnp_header {
11272diff -urNp linux-2.6.32.44/arch/x86/include/asm/vmi_time.h linux-2.6.32.44/arch/x86/include/asm/vmi_time.h
11273--- linux-2.6.32.44/arch/x86/include/asm/vmi_time.h 2011-03-27 14:31:47.000000000 -0400
11274+++ linux-2.6.32.44/arch/x86/include/asm/vmi_time.h 2011-08-05 20:33:55.000000000 -0400
11275@@ -43,7 +43,7 @@ extern struct vmi_timer_ops {
11276 int (*wallclock_updated)(void);
11277 void (*set_alarm)(u32 flags, u64 expiry, u64 period);
11278 void (*cancel_alarm)(u32 flags);
11279-} vmi_timer_ops;
11280+} __no_const vmi_timer_ops;
11281
11282 /* Prototypes */
11283 extern void __init vmi_time_init(void);
11284diff -urNp linux-2.6.32.44/arch/x86/include/asm/vsyscall.h linux-2.6.32.44/arch/x86/include/asm/vsyscall.h
11285--- linux-2.6.32.44/arch/x86/include/asm/vsyscall.h 2011-03-27 14:31:47.000000000 -0400
11286+++ linux-2.6.32.44/arch/x86/include/asm/vsyscall.h 2011-04-17 15:56:46.000000000 -0400
11287@@ -15,9 +15,10 @@ enum vsyscall_num {
11288
11289 #ifdef __KERNEL__
11290 #include <linux/seqlock.h>
11291+#include <linux/getcpu.h>
11292+#include <linux/time.h>
11293
11294 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
11295-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
11296
11297 /* Definitions for CONFIG_GENERIC_TIME definitions */
11298 #define __section_vsyscall_gtod_data __attribute__ \
11299@@ -31,7 +32,6 @@ enum vsyscall_num {
11300 #define VGETCPU_LSL 2
11301
11302 extern int __vgetcpu_mode;
11303-extern volatile unsigned long __jiffies;
11304
11305 /* kernel space (writeable) */
11306 extern int vgetcpu_mode;
11307@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
11308
11309 extern void map_vsyscall(void);
11310
11311+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
11312+extern time_t vtime(time_t *t);
11313+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
11314 #endif /* __KERNEL__ */
11315
11316 #endif /* _ASM_X86_VSYSCALL_H */
11317diff -urNp linux-2.6.32.44/arch/x86/include/asm/x86_init.h linux-2.6.32.44/arch/x86/include/asm/x86_init.h
11318--- linux-2.6.32.44/arch/x86/include/asm/x86_init.h 2011-03-27 14:31:47.000000000 -0400
11319+++ linux-2.6.32.44/arch/x86/include/asm/x86_init.h 2011-08-05 20:33:55.000000000 -0400
11320@@ -28,7 +28,7 @@ struct x86_init_mpparse {
11321 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
11322 void (*find_smp_config)(unsigned int reserve);
11323 void (*get_smp_config)(unsigned int early);
11324-};
11325+} __no_const;
11326
11327 /**
11328 * struct x86_init_resources - platform specific resource related ops
11329@@ -42,7 +42,7 @@ struct x86_init_resources {
11330 void (*probe_roms)(void);
11331 void (*reserve_resources)(void);
11332 char *(*memory_setup)(void);
11333-};
11334+} __no_const;
11335
11336 /**
11337 * struct x86_init_irqs - platform specific interrupt setup
11338@@ -55,7 +55,7 @@ struct x86_init_irqs {
11339 void (*pre_vector_init)(void);
11340 void (*intr_init)(void);
11341 void (*trap_init)(void);
11342-};
11343+} __no_const;
11344
11345 /**
11346 * struct x86_init_oem - oem platform specific customizing functions
11347@@ -65,7 +65,7 @@ struct x86_init_irqs {
11348 struct x86_init_oem {
11349 void (*arch_setup)(void);
11350 void (*banner)(void);
11351-};
11352+} __no_const;
11353
11354 /**
11355 * struct x86_init_paging - platform specific paging functions
11356@@ -75,7 +75,7 @@ struct x86_init_oem {
11357 struct x86_init_paging {
11358 void (*pagetable_setup_start)(pgd_t *base);
11359 void (*pagetable_setup_done)(pgd_t *base);
11360-};
11361+} __no_const;
11362
11363 /**
11364 * struct x86_init_timers - platform specific timer setup
11365@@ -88,7 +88,7 @@ struct x86_init_timers {
11366 void (*setup_percpu_clockev)(void);
11367 void (*tsc_pre_init)(void);
11368 void (*timer_init)(void);
11369-};
11370+} __no_const;
11371
11372 /**
11373 * struct x86_init_ops - functions for platform specific setup
11374@@ -101,7 +101,7 @@ struct x86_init_ops {
11375 struct x86_init_oem oem;
11376 struct x86_init_paging paging;
11377 struct x86_init_timers timers;
11378-};
11379+} __no_const;
11380
11381 /**
11382 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
11383@@ -109,7 +109,7 @@ struct x86_init_ops {
11384 */
11385 struct x86_cpuinit_ops {
11386 void (*setup_percpu_clockev)(void);
11387-};
11388+} __no_const;
11389
11390 /**
11391 * struct x86_platform_ops - platform specific runtime functions
11392@@ -121,7 +121,7 @@ struct x86_platform_ops {
11393 unsigned long (*calibrate_tsc)(void);
11394 unsigned long (*get_wallclock)(void);
11395 int (*set_wallclock)(unsigned long nowtime);
11396-};
11397+} __no_const;
11398
11399 extern struct x86_init_ops x86_init;
11400 extern struct x86_cpuinit_ops x86_cpuinit;
11401diff -urNp linux-2.6.32.44/arch/x86/include/asm/xsave.h linux-2.6.32.44/arch/x86/include/asm/xsave.h
11402--- linux-2.6.32.44/arch/x86/include/asm/xsave.h 2011-03-27 14:31:47.000000000 -0400
11403+++ linux-2.6.32.44/arch/x86/include/asm/xsave.h 2011-04-17 15:56:46.000000000 -0400
11404@@ -56,6 +56,12 @@ static inline int xrstor_checking(struct
11405 static inline int xsave_user(struct xsave_struct __user *buf)
11406 {
11407 int err;
11408+
11409+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11410+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
11411+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
11412+#endif
11413+
11414 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
11415 "2:\n"
11416 ".section .fixup,\"ax\"\n"
11417@@ -82,6 +88,11 @@ static inline int xrestore_user(struct x
11418 u32 lmask = mask;
11419 u32 hmask = mask >> 32;
11420
11421+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11422+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
11423+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
11424+#endif
11425+
11426 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
11427 "2:\n"
11428 ".section .fixup,\"ax\"\n"
11429diff -urNp linux-2.6.32.44/arch/x86/Kconfig linux-2.6.32.44/arch/x86/Kconfig
11430--- linux-2.6.32.44/arch/x86/Kconfig 2011-03-27 14:31:47.000000000 -0400
11431+++ linux-2.6.32.44/arch/x86/Kconfig 2011-04-17 15:56:46.000000000 -0400
11432@@ -223,7 +223,7 @@ config X86_TRAMPOLINE
11433
11434 config X86_32_LAZY_GS
11435 def_bool y
11436- depends on X86_32 && !CC_STACKPROTECTOR
11437+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11438
11439 config KTIME_SCALAR
11440 def_bool X86_32
11441@@ -1008,7 +1008,7 @@ choice
11442
11443 config NOHIGHMEM
11444 bool "off"
11445- depends on !X86_NUMAQ
11446+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11447 ---help---
11448 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11449 However, the address space of 32-bit x86 processors is only 4
11450@@ -1045,7 +1045,7 @@ config NOHIGHMEM
11451
11452 config HIGHMEM4G
11453 bool "4GB"
11454- depends on !X86_NUMAQ
11455+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11456 ---help---
11457 Select this if you have a 32-bit processor and between 1 and 4
11458 gigabytes of physical RAM.
11459@@ -1099,7 +1099,7 @@ config PAGE_OFFSET
11460 hex
11461 default 0xB0000000 if VMSPLIT_3G_OPT
11462 default 0x80000000 if VMSPLIT_2G
11463- default 0x78000000 if VMSPLIT_2G_OPT
11464+ default 0x70000000 if VMSPLIT_2G_OPT
11465 default 0x40000000 if VMSPLIT_1G
11466 default 0xC0000000
11467 depends on X86_32
11468@@ -1430,7 +1430,7 @@ config ARCH_USES_PG_UNCACHED
11469
11470 config EFI
11471 bool "EFI runtime service support"
11472- depends on ACPI
11473+ depends on ACPI && !PAX_KERNEXEC
11474 ---help---
11475 This enables the kernel to use EFI runtime services that are
11476 available (such as the EFI variable services).
11477@@ -1460,6 +1460,7 @@ config SECCOMP
11478
11479 config CC_STACKPROTECTOR
11480 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
11481+ depends on X86_64 || !PAX_MEMORY_UDEREF
11482 ---help---
11483 This option turns on the -fstack-protector GCC feature. This
11484 feature puts, at the beginning of functions, a canary value on
11485@@ -1517,6 +1518,7 @@ config KEXEC_JUMP
11486 config PHYSICAL_START
11487 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
11488 default "0x1000000"
11489+ range 0x400000 0x40000000
11490 ---help---
11491 This gives the physical address where the kernel is loaded.
11492
11493@@ -1581,6 +1583,7 @@ config PHYSICAL_ALIGN
11494 hex
11495 prompt "Alignment value to which kernel should be aligned" if X86_32
11496 default "0x1000000"
11497+ range 0x400000 0x1000000 if PAX_KERNEXEC
11498 range 0x2000 0x1000000
11499 ---help---
11500 This value puts the alignment restrictions on physical address
11501@@ -1612,9 +1615,10 @@ config HOTPLUG_CPU
11502 Say N if you want to disable CPU hotplug.
11503
11504 config COMPAT_VDSO
11505- def_bool y
11506+ def_bool n
11507 prompt "Compat VDSO support"
11508 depends on X86_32 || IA32_EMULATION
11509+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
11510 ---help---
11511 Map the 32-bit VDSO to the predictable old-style address too.
11512 ---help---
11513diff -urNp linux-2.6.32.44/arch/x86/Kconfig.cpu linux-2.6.32.44/arch/x86/Kconfig.cpu
11514--- linux-2.6.32.44/arch/x86/Kconfig.cpu 2011-03-27 14:31:47.000000000 -0400
11515+++ linux-2.6.32.44/arch/x86/Kconfig.cpu 2011-04-17 15:56:46.000000000 -0400
11516@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
11517
11518 config X86_F00F_BUG
11519 def_bool y
11520- depends on M586MMX || M586TSC || M586 || M486 || M386
11521+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
11522
11523 config X86_WP_WORKS_OK
11524 def_bool y
11525@@ -360,7 +360,7 @@ config X86_POPAD_OK
11526
11527 config X86_ALIGNMENT_16
11528 def_bool y
11529- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11530+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11531
11532 config X86_INTEL_USERCOPY
11533 def_bool y
11534@@ -406,7 +406,7 @@ config X86_CMPXCHG64
11535 # generates cmov.
11536 config X86_CMOV
11537 def_bool y
11538- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
11539+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
11540
11541 config X86_MINIMUM_CPU_FAMILY
11542 int
11543diff -urNp linux-2.6.32.44/arch/x86/Kconfig.debug linux-2.6.32.44/arch/x86/Kconfig.debug
11544--- linux-2.6.32.44/arch/x86/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
11545+++ linux-2.6.32.44/arch/x86/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
11546@@ -99,7 +99,7 @@ config X86_PTDUMP
11547 config DEBUG_RODATA
11548 bool "Write protect kernel read-only data structures"
11549 default y
11550- depends on DEBUG_KERNEL
11551+ depends on DEBUG_KERNEL && BROKEN
11552 ---help---
11553 Mark the kernel read-only data as write-protected in the pagetables,
11554 in order to catch accidental (and incorrect) writes to such const
11555diff -urNp linux-2.6.32.44/arch/x86/kernel/acpi/realmode/Makefile linux-2.6.32.44/arch/x86/kernel/acpi/realmode/Makefile
11556--- linux-2.6.32.44/arch/x86/kernel/acpi/realmode/Makefile 2011-03-27 14:31:47.000000000 -0400
11557+++ linux-2.6.32.44/arch/x86/kernel/acpi/realmode/Makefile 2011-08-07 14:38:58.000000000 -0400
11558@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
11559 $(call cc-option, -fno-stack-protector) \
11560 $(call cc-option, -mpreferred-stack-boundary=2)
11561 KBUILD_CFLAGS += $(call cc-option, -m32)
11562+ifdef CONSTIFY_PLUGIN
11563+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
11564+endif
11565 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11566 GCOV_PROFILE := n
11567
11568diff -urNp linux-2.6.32.44/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.32.44/arch/x86/kernel/acpi/realmode/wakeup.S
11569--- linux-2.6.32.44/arch/x86/kernel/acpi/realmode/wakeup.S 2011-03-27 14:31:47.000000000 -0400
11570+++ linux-2.6.32.44/arch/x86/kernel/acpi/realmode/wakeup.S 2011-07-01 18:53:40.000000000 -0400
11571@@ -91,6 +91,9 @@ _start:
11572 /* Do any other stuff... */
11573
11574 #ifndef CONFIG_64BIT
11575+ /* Recheck NX bit overrides (64bit path does this in trampoline) */
11576+ call verify_cpu
11577+
11578 /* This could also be done in C code... */
11579 movl pmode_cr3, %eax
11580 movl %eax, %cr3
11581@@ -104,7 +107,7 @@ _start:
11582 movl %eax, %ecx
11583 orl %edx, %ecx
11584 jz 1f
11585- movl $0xc0000080, %ecx
11586+ mov $MSR_EFER, %ecx
11587 wrmsr
11588 1:
11589
11590@@ -114,6 +117,7 @@ _start:
11591 movl pmode_cr0, %eax
11592 movl %eax, %cr0
11593 jmp pmode_return
11594+# include "../../verify_cpu.S"
11595 #else
11596 pushw $0
11597 pushw trampoline_segment
11598diff -urNp linux-2.6.32.44/arch/x86/kernel/acpi/sleep.c linux-2.6.32.44/arch/x86/kernel/acpi/sleep.c
11599--- linux-2.6.32.44/arch/x86/kernel/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
11600+++ linux-2.6.32.44/arch/x86/kernel/acpi/sleep.c 2011-07-01 19:01:34.000000000 -0400
11601@@ -11,11 +11,12 @@
11602 #include <linux/cpumask.h>
11603 #include <asm/segment.h>
11604 #include <asm/desc.h>
11605+#include <asm/e820.h>
11606
11607 #include "realmode/wakeup.h"
11608 #include "sleep.h"
11609
11610-unsigned long acpi_wakeup_address;
11611+unsigned long acpi_wakeup_address = 0x2000;
11612 unsigned long acpi_realmode_flags;
11613
11614 /* address in low memory of the wakeup routine. */
11615@@ -98,9 +99,13 @@ int acpi_save_state_mem(void)
11616 #else /* CONFIG_64BIT */
11617 header->trampoline_segment = setup_trampoline() >> 4;
11618 #ifdef CONFIG_SMP
11619- stack_start.sp = temp_stack + sizeof(temp_stack);
11620+ stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
11621+
11622+ pax_open_kernel();
11623 early_gdt_descr.address =
11624 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11625+ pax_close_kernel();
11626+
11627 initial_gs = per_cpu_offset(smp_processor_id());
11628 #endif
11629 initial_code = (unsigned long)wakeup_long64;
11630@@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
11631 return;
11632 }
11633
11634- acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
11635-
11636- if (!acpi_realmode) {
11637- printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
11638- return;
11639- }
11640-
11641- acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
11642+ reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
11643+ acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
11644 }
11645
11646
11647diff -urNp linux-2.6.32.44/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.32.44/arch/x86/kernel/acpi/wakeup_32.S
11648--- linux-2.6.32.44/arch/x86/kernel/acpi/wakeup_32.S 2011-03-27 14:31:47.000000000 -0400
11649+++ linux-2.6.32.44/arch/x86/kernel/acpi/wakeup_32.S 2011-04-17 15:56:46.000000000 -0400
11650@@ -30,13 +30,11 @@ wakeup_pmode_return:
11651 # and restore the stack ... but you need gdt for this to work
11652 movl saved_context_esp, %esp
11653
11654- movl %cs:saved_magic, %eax
11655- cmpl $0x12345678, %eax
11656+ cmpl $0x12345678, saved_magic
11657 jne bogus_magic
11658
11659 # jump to place where we left off
11660- movl saved_eip, %eax
11661- jmp *%eax
11662+ jmp *(saved_eip)
11663
11664 bogus_magic:
11665 jmp bogus_magic
11666diff -urNp linux-2.6.32.44/arch/x86/kernel/alternative.c linux-2.6.32.44/arch/x86/kernel/alternative.c
11667--- linux-2.6.32.44/arch/x86/kernel/alternative.c 2011-03-27 14:31:47.000000000 -0400
11668+++ linux-2.6.32.44/arch/x86/kernel/alternative.c 2011-04-17 15:56:46.000000000 -0400
11669@@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(str
11670
11671 BUG_ON(p->len > MAX_PATCH_LEN);
11672 /* prep the buffer with the original instructions */
11673- memcpy(insnbuf, p->instr, p->len);
11674+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11675 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11676 (unsigned long)p->instr, p->len);
11677
11678@@ -475,7 +475,7 @@ void __init alternative_instructions(voi
11679 if (smp_alt_once)
11680 free_init_pages("SMP alternatives",
11681 (unsigned long)__smp_locks,
11682- (unsigned long)__smp_locks_end);
11683+ PAGE_ALIGN((unsigned long)__smp_locks_end));
11684
11685 restart_nmi();
11686 }
11687@@ -492,13 +492,17 @@ void __init alternative_instructions(voi
11688 * instructions. And on the local CPU you need to be protected again NMI or MCE
11689 * handlers seeing an inconsistent instruction while you patch.
11690 */
11691-static void *__init_or_module text_poke_early(void *addr, const void *opcode,
11692+static void *__kprobes text_poke_early(void *addr, const void *opcode,
11693 size_t len)
11694 {
11695 unsigned long flags;
11696 local_irq_save(flags);
11697- memcpy(addr, opcode, len);
11698+
11699+ pax_open_kernel();
11700+ memcpy(ktla_ktva(addr), opcode, len);
11701 sync_core();
11702+ pax_close_kernel();
11703+
11704 local_irq_restore(flags);
11705 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11706 that causes hangs on some VIA CPUs. */
11707@@ -520,35 +524,21 @@ static void *__init_or_module text_poke_
11708 */
11709 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11710 {
11711- unsigned long flags;
11712- char *vaddr;
11713+ unsigned char *vaddr = ktla_ktva(addr);
11714 struct page *pages[2];
11715- int i;
11716+ size_t i;
11717
11718 if (!core_kernel_text((unsigned long)addr)) {
11719- pages[0] = vmalloc_to_page(addr);
11720- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11721+ pages[0] = vmalloc_to_page(vaddr);
11722+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11723 } else {
11724- pages[0] = virt_to_page(addr);
11725+ pages[0] = virt_to_page(vaddr);
11726 WARN_ON(!PageReserved(pages[0]));
11727- pages[1] = virt_to_page(addr + PAGE_SIZE);
11728+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11729 }
11730 BUG_ON(!pages[0]);
11731- local_irq_save(flags);
11732- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11733- if (pages[1])
11734- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11735- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11736- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11737- clear_fixmap(FIX_TEXT_POKE0);
11738- if (pages[1])
11739- clear_fixmap(FIX_TEXT_POKE1);
11740- local_flush_tlb();
11741- sync_core();
11742- /* Could also do a CLFLUSH here to speed up CPU recovery; but
11743- that causes hangs on some VIA CPUs. */
11744+ text_poke_early(addr, opcode, len);
11745 for (i = 0; i < len; i++)
11746- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11747- local_irq_restore(flags);
11748+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11749 return addr;
11750 }
11751diff -urNp linux-2.6.32.44/arch/x86/kernel/amd_iommu.c linux-2.6.32.44/arch/x86/kernel/amd_iommu.c
11752--- linux-2.6.32.44/arch/x86/kernel/amd_iommu.c 2011-03-27 14:31:47.000000000 -0400
11753+++ linux-2.6.32.44/arch/x86/kernel/amd_iommu.c 2011-04-17 15:56:46.000000000 -0400
11754@@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(
11755 }
11756 }
11757
11758-static struct dma_map_ops amd_iommu_dma_ops = {
11759+static const struct dma_map_ops amd_iommu_dma_ops = {
11760 .alloc_coherent = alloc_coherent,
11761 .free_coherent = free_coherent,
11762 .map_page = map_page,
11763diff -urNp linux-2.6.32.44/arch/x86/kernel/apic/apic.c linux-2.6.32.44/arch/x86/kernel/apic/apic.c
11764--- linux-2.6.32.44/arch/x86/kernel/apic/apic.c 2011-03-27 14:31:47.000000000 -0400
11765+++ linux-2.6.32.44/arch/x86/kernel/apic/apic.c 2011-05-16 21:46:57.000000000 -0400
11766@@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs
11767 apic_write(APIC_ESR, 0);
11768 v1 = apic_read(APIC_ESR);
11769 ack_APIC_irq();
11770- atomic_inc(&irq_err_count);
11771+ atomic_inc_unchecked(&irq_err_count);
11772
11773 /*
11774 * Here is what the APIC error bits mean:
11775@@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(vo
11776 u16 *bios_cpu_apicid;
11777 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
11778
11779+ pax_track_stack();
11780+
11781 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
11782 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
11783
11784diff -urNp linux-2.6.32.44/arch/x86/kernel/apic/io_apic.c linux-2.6.32.44/arch/x86/kernel/apic/io_apic.c
11785--- linux-2.6.32.44/arch/x86/kernel/apic/io_apic.c 2011-03-27 14:31:47.000000000 -0400
11786+++ linux-2.6.32.44/arch/x86/kernel/apic/io_apic.c 2011-05-04 17:56:20.000000000 -0400
11787@@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapi
11788 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
11789 GFP_ATOMIC);
11790 if (!ioapic_entries)
11791- return 0;
11792+ return NULL;
11793
11794 for (apic = 0; apic < nr_ioapics; apic++) {
11795 ioapic_entries[apic] =
11796@@ -733,7 +733,7 @@ nomem:
11797 kfree(ioapic_entries[apic]);
11798 kfree(ioapic_entries);
11799
11800- return 0;
11801+ return NULL;
11802 }
11803
11804 /*
11805@@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
11806 }
11807 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
11808
11809-void lock_vector_lock(void)
11810+void lock_vector_lock(void) __acquires(vector_lock)
11811 {
11812 /* Used to the online set of cpus does not change
11813 * during assign_irq_vector.
11814@@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
11815 spin_lock(&vector_lock);
11816 }
11817
11818-void unlock_vector_lock(void)
11819+void unlock_vector_lock(void) __releases(vector_lock)
11820 {
11821 spin_unlock(&vector_lock);
11822 }
11823@@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int i
11824 ack_APIC_irq();
11825 }
11826
11827-atomic_t irq_mis_count;
11828+atomic_unchecked_t irq_mis_count;
11829
11830 static void ack_apic_level(unsigned int irq)
11831 {
11832@@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int
11833
11834 /* Tail end of version 0x11 I/O APIC bug workaround */
11835 if (!(v & (1 << (i & 0x1f)))) {
11836- atomic_inc(&irq_mis_count);
11837+ atomic_inc_unchecked(&irq_mis_count);
11838 spin_lock(&ioapic_lock);
11839 __mask_and_edge_IO_APIC_irq(cfg);
11840 __unmask_and_level_IO_APIC_irq(cfg);
11841diff -urNp linux-2.6.32.44/arch/x86/kernel/apm_32.c linux-2.6.32.44/arch/x86/kernel/apm_32.c
11842--- linux-2.6.32.44/arch/x86/kernel/apm_32.c 2011-03-27 14:31:47.000000000 -0400
11843+++ linux-2.6.32.44/arch/x86/kernel/apm_32.c 2011-04-23 12:56:10.000000000 -0400
11844@@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
11845 * This is for buggy BIOS's that refer to (real mode) segment 0x40
11846 * even though they are called in protected mode.
11847 */
11848-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
11849+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
11850 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
11851
11852 static const char driver_version[] = "1.16ac"; /* no spaces */
11853@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
11854 BUG_ON(cpu != 0);
11855 gdt = get_cpu_gdt_table(cpu);
11856 save_desc_40 = gdt[0x40 / 8];
11857+
11858+ pax_open_kernel();
11859 gdt[0x40 / 8] = bad_bios_desc;
11860+ pax_close_kernel();
11861
11862 apm_irq_save(flags);
11863 APM_DO_SAVE_SEGS;
11864@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
11865 &call->esi);
11866 APM_DO_RESTORE_SEGS;
11867 apm_irq_restore(flags);
11868+
11869+ pax_open_kernel();
11870 gdt[0x40 / 8] = save_desc_40;
11871+ pax_close_kernel();
11872+
11873 put_cpu();
11874
11875 return call->eax & 0xff;
11876@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void
11877 BUG_ON(cpu != 0);
11878 gdt = get_cpu_gdt_table(cpu);
11879 save_desc_40 = gdt[0x40 / 8];
11880+
11881+ pax_open_kernel();
11882 gdt[0x40 / 8] = bad_bios_desc;
11883+ pax_close_kernel();
11884
11885 apm_irq_save(flags);
11886 APM_DO_SAVE_SEGS;
11887@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void
11888 &call->eax);
11889 APM_DO_RESTORE_SEGS;
11890 apm_irq_restore(flags);
11891+
11892+ pax_open_kernel();
11893 gdt[0x40 / 8] = save_desc_40;
11894+ pax_close_kernel();
11895+
11896 put_cpu();
11897 return error;
11898 }
11899@@ -975,7 +989,7 @@ recalc:
11900
11901 static void apm_power_off(void)
11902 {
11903- unsigned char po_bios_call[] = {
11904+ const unsigned char po_bios_call[] = {
11905 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
11906 0x8e, 0xd0, /* movw ax,ss */
11907 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
11908@@ -2357,12 +2371,15 @@ static int __init apm_init(void)
11909 * code to that CPU.
11910 */
11911 gdt = get_cpu_gdt_table(0);
11912+
11913+ pax_open_kernel();
11914 set_desc_base(&gdt[APM_CS >> 3],
11915 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
11916 set_desc_base(&gdt[APM_CS_16 >> 3],
11917 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
11918 set_desc_base(&gdt[APM_DS >> 3],
11919 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
11920+ pax_close_kernel();
11921
11922 proc_create("apm", 0, NULL, &apm_file_ops);
11923
11924diff -urNp linux-2.6.32.44/arch/x86/kernel/asm-offsets_32.c linux-2.6.32.44/arch/x86/kernel/asm-offsets_32.c
11925--- linux-2.6.32.44/arch/x86/kernel/asm-offsets_32.c 2011-03-27 14:31:47.000000000 -0400
11926+++ linux-2.6.32.44/arch/x86/kernel/asm-offsets_32.c 2011-05-16 21:46:57.000000000 -0400
11927@@ -51,7 +51,6 @@ void foo(void)
11928 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
11929 BLANK();
11930
11931- OFFSET(TI_task, thread_info, task);
11932 OFFSET(TI_exec_domain, thread_info, exec_domain);
11933 OFFSET(TI_flags, thread_info, flags);
11934 OFFSET(TI_status, thread_info, status);
11935@@ -60,6 +59,8 @@ void foo(void)
11936 OFFSET(TI_restart_block, thread_info, restart_block);
11937 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
11938 OFFSET(TI_cpu, thread_info, cpu);
11939+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
11940+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11941 BLANK();
11942
11943 OFFSET(GDS_size, desc_ptr, size);
11944@@ -99,6 +100,7 @@ void foo(void)
11945
11946 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
11947 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
11948+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
11949 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
11950 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
11951 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
11952@@ -115,6 +117,11 @@ void foo(void)
11953 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
11954 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
11955 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
11956+
11957+#ifdef CONFIG_PAX_KERNEXEC
11958+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
11959+#endif
11960+
11961 #endif
11962
11963 #ifdef CONFIG_XEN
11964diff -urNp linux-2.6.32.44/arch/x86/kernel/asm-offsets_64.c linux-2.6.32.44/arch/x86/kernel/asm-offsets_64.c
11965--- linux-2.6.32.44/arch/x86/kernel/asm-offsets_64.c 2011-03-27 14:31:47.000000000 -0400
11966+++ linux-2.6.32.44/arch/x86/kernel/asm-offsets_64.c 2011-05-16 21:46:57.000000000 -0400
11967@@ -44,6 +44,8 @@ int main(void)
11968 ENTRY(addr_limit);
11969 ENTRY(preempt_count);
11970 ENTRY(status);
11971+ ENTRY(lowest_stack);
11972+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11973 #ifdef CONFIG_IA32_EMULATION
11974 ENTRY(sysenter_return);
11975 #endif
11976@@ -63,6 +65,18 @@ int main(void)
11977 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
11978 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
11979 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
11980+
11981+#ifdef CONFIG_PAX_KERNEXEC
11982+ OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
11983+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
11984+#endif
11985+
11986+#ifdef CONFIG_PAX_MEMORY_UDEREF
11987+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
11988+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
11989+ OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
11990+#endif
11991+
11992 #endif
11993
11994
11995@@ -115,6 +129,7 @@ int main(void)
11996 ENTRY(cr8);
11997 BLANK();
11998 #undef ENTRY
11999+ DEFINE(TSS_size, sizeof(struct tss_struct));
12000 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
12001 BLANK();
12002 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
12003@@ -130,6 +145,7 @@ int main(void)
12004
12005 BLANK();
12006 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12007+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12008 #ifdef CONFIG_XEN
12009 BLANK();
12010 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12011diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/amd.c linux-2.6.32.44/arch/x86/kernel/cpu/amd.c
12012--- linux-2.6.32.44/arch/x86/kernel/cpu/amd.c 2011-06-25 12:55:34.000000000 -0400
12013+++ linux-2.6.32.44/arch/x86/kernel/cpu/amd.c 2011-06-25 12:56:37.000000000 -0400
12014@@ -602,7 +602,7 @@ static unsigned int __cpuinit amd_size_c
12015 unsigned int size)
12016 {
12017 /* AMD errata T13 (order #21922) */
12018- if ((c->x86 == 6)) {
12019+ if (c->x86 == 6) {
12020 /* Duron Rev A0 */
12021 if (c->x86_model == 3 && c->x86_mask == 0)
12022 size = 64;
12023diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/common.c linux-2.6.32.44/arch/x86/kernel/cpu/common.c
12024--- linux-2.6.32.44/arch/x86/kernel/cpu/common.c 2011-03-27 14:31:47.000000000 -0400
12025+++ linux-2.6.32.44/arch/x86/kernel/cpu/common.c 2011-05-11 18:25:15.000000000 -0400
12026@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
12027
12028 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12029
12030-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12031-#ifdef CONFIG_X86_64
12032- /*
12033- * We need valid kernel segments for data and code in long mode too
12034- * IRET will check the segment types kkeil 2000/10/28
12035- * Also sysret mandates a special GDT layout
12036- *
12037- * TLS descriptors are currently at a different place compared to i386.
12038- * Hopefully nobody expects them at a fixed place (Wine?)
12039- */
12040- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12041- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12042- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12043- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12044- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12045- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12046-#else
12047- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12048- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12049- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12050- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12051- /*
12052- * Segments used for calling PnP BIOS have byte granularity.
12053- * They code segments and data segments have fixed 64k limits,
12054- * the transfer segment sizes are set at run time.
12055- */
12056- /* 32-bit code */
12057- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12058- /* 16-bit code */
12059- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12060- /* 16-bit data */
12061- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12062- /* 16-bit data */
12063- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12064- /* 16-bit data */
12065- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12066- /*
12067- * The APM segments have byte granularity and their bases
12068- * are set at run time. All have 64k limits.
12069- */
12070- /* 32-bit code */
12071- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12072- /* 16-bit code */
12073- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12074- /* data */
12075- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12076-
12077- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12078- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12079- GDT_STACK_CANARY_INIT
12080-#endif
12081-} };
12082-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12083-
12084 static int __init x86_xsave_setup(char *s)
12085 {
12086 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12087@@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
12088 {
12089 struct desc_ptr gdt_descr;
12090
12091- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12092+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12093 gdt_descr.size = GDT_SIZE - 1;
12094 load_gdt(&gdt_descr);
12095 /* Reload the per-cpu base */
12096@@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struc
12097 /* Filter out anything that depends on CPUID levels we don't have */
12098 filter_cpuid_features(c, true);
12099
12100+#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
12101+ setup_clear_cpu_cap(X86_FEATURE_SEP);
12102+#endif
12103+
12104 /* If the model name is still unset, do table lookup. */
12105 if (!c->x86_model_id[0]) {
12106 const char *p;
12107@@ -980,6 +930,9 @@ static __init int setup_disablecpuid(cha
12108 }
12109 __setup("clearcpuid=", setup_disablecpuid);
12110
12111+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12112+EXPORT_PER_CPU_SYMBOL(current_tinfo);
12113+
12114 #ifdef CONFIG_X86_64
12115 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12116
12117@@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
12118 EXPORT_PER_CPU_SYMBOL(current_task);
12119
12120 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12121- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12122+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12123 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12124
12125 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12126@@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(str
12127 {
12128 memset(regs, 0, sizeof(struct pt_regs));
12129 regs->fs = __KERNEL_PERCPU;
12130- regs->gs = __KERNEL_STACK_CANARY;
12131+ savesegment(gs, regs->gs);
12132
12133 return regs;
12134 }
12135@@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
12136 int i;
12137
12138 cpu = stack_smp_processor_id();
12139- t = &per_cpu(init_tss, cpu);
12140+ t = init_tss + cpu;
12141 orig_ist = &per_cpu(orig_ist, cpu);
12142
12143 #ifdef CONFIG_NUMA
12144@@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
12145 switch_to_new_gdt(cpu);
12146 loadsegment(fs, 0);
12147
12148- load_idt((const struct desc_ptr *)&idt_descr);
12149+ load_idt(&idt_descr);
12150
12151 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12152 syscall_init();
12153@@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
12154 wrmsrl(MSR_KERNEL_GS_BASE, 0);
12155 barrier();
12156
12157- check_efer();
12158 if (cpu != 0)
12159 enable_x2apic();
12160
12161@@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
12162 {
12163 int cpu = smp_processor_id();
12164 struct task_struct *curr = current;
12165- struct tss_struct *t = &per_cpu(init_tss, cpu);
12166+ struct tss_struct *t = init_tss + cpu;
12167 struct thread_struct *thread = &curr->thread;
12168
12169 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
12170diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/intel.c linux-2.6.32.44/arch/x86/kernel/cpu/intel.c
12171--- linux-2.6.32.44/arch/x86/kernel/cpu/intel.c 2011-03-27 14:31:47.000000000 -0400
12172+++ linux-2.6.32.44/arch/x86/kernel/cpu/intel.c 2011-04-17 15:56:46.000000000 -0400
12173@@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug
12174 * Update the IDT descriptor and reload the IDT so that
12175 * it uses the read-only mapped virtual address.
12176 */
12177- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
12178+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
12179 load_idt(&idt_descr);
12180 }
12181 #endif
12182diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/intel_cacheinfo.c linux-2.6.32.44/arch/x86/kernel/cpu/intel_cacheinfo.c
12183--- linux-2.6.32.44/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
12184+++ linux-2.6.32.44/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-04-17 15:56:46.000000000 -0400
12185@@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kob
12186 return ret;
12187 }
12188
12189-static struct sysfs_ops sysfs_ops = {
12190+static const struct sysfs_ops sysfs_ops = {
12191 .show = show,
12192 .store = store,
12193 };
12194diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/Makefile linux-2.6.32.44/arch/x86/kernel/cpu/Makefile
12195--- linux-2.6.32.44/arch/x86/kernel/cpu/Makefile 2011-03-27 14:31:47.000000000 -0400
12196+++ linux-2.6.32.44/arch/x86/kernel/cpu/Makefile 2011-04-17 15:56:46.000000000 -0400
12197@@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
12198 CFLAGS_REMOVE_common.o = -pg
12199 endif
12200
12201-# Make sure load_percpu_segment has no stackprotector
12202-nostackp := $(call cc-option, -fno-stack-protector)
12203-CFLAGS_common.o := $(nostackp)
12204-
12205 obj-y := intel_cacheinfo.o addon_cpuid_features.o
12206 obj-y += proc.o capflags.o powerflags.o common.o
12207 obj-y += vmware.o hypervisor.o sched.o
12208diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce_amd.c linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce_amd.c
12209--- linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:56:59.000000000 -0400
12210+++ linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:57:13.000000000 -0400
12211@@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kob
12212 return ret;
12213 }
12214
12215-static struct sysfs_ops threshold_ops = {
12216+static const struct sysfs_ops threshold_ops = {
12217 .show = show,
12218 .store = store,
12219 };
12220diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce.c
12221--- linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce.c 2011-03-27 14:31:47.000000000 -0400
12222+++ linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-04 17:56:20.000000000 -0400
12223@@ -43,6 +43,7 @@
12224 #include <asm/ipi.h>
12225 #include <asm/mce.h>
12226 #include <asm/msr.h>
12227+#include <asm/local.h>
12228
12229 #include "mce-internal.h"
12230
12231@@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
12232 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
12233 m->cs, m->ip);
12234
12235- if (m->cs == __KERNEL_CS)
12236+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
12237 print_symbol("{%s}", m->ip);
12238 pr_cont("\n");
12239 }
12240@@ -221,10 +222,10 @@ static void print_mce_tail(void)
12241
12242 #define PANIC_TIMEOUT 5 /* 5 seconds */
12243
12244-static atomic_t mce_paniced;
12245+static atomic_unchecked_t mce_paniced;
12246
12247 static int fake_panic;
12248-static atomic_t mce_fake_paniced;
12249+static atomic_unchecked_t mce_fake_paniced;
12250
12251 /* Panic in progress. Enable interrupts and wait for final IPI */
12252 static void wait_for_panic(void)
12253@@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct
12254 /*
12255 * Make sure only one CPU runs in machine check panic
12256 */
12257- if (atomic_inc_return(&mce_paniced) > 1)
12258+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
12259 wait_for_panic();
12260 barrier();
12261
12262@@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct
12263 console_verbose();
12264 } else {
12265 /* Don't log too much for fake panic */
12266- if (atomic_inc_return(&mce_fake_paniced) > 1)
12267+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
12268 return;
12269 }
12270 print_mce_head();
12271@@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
12272 * might have been modified by someone else.
12273 */
12274 rmb();
12275- if (atomic_read(&mce_paniced))
12276+ if (atomic_read_unchecked(&mce_paniced))
12277 wait_for_panic();
12278 if (!monarch_timeout)
12279 goto out;
12280@@ -1429,14 +1430,14 @@ void __cpuinit mcheck_init(struct cpuinf
12281 */
12282
12283 static DEFINE_SPINLOCK(mce_state_lock);
12284-static int open_count; /* #times opened */
12285+static local_t open_count; /* #times opened */
12286 static int open_exclu; /* already open exclusive? */
12287
12288 static int mce_open(struct inode *inode, struct file *file)
12289 {
12290 spin_lock(&mce_state_lock);
12291
12292- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
12293+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
12294 spin_unlock(&mce_state_lock);
12295
12296 return -EBUSY;
12297@@ -1444,7 +1445,7 @@ static int mce_open(struct inode *inode,
12298
12299 if (file->f_flags & O_EXCL)
12300 open_exclu = 1;
12301- open_count++;
12302+ local_inc(&open_count);
12303
12304 spin_unlock(&mce_state_lock);
12305
12306@@ -1455,7 +1456,7 @@ static int mce_release(struct inode *ino
12307 {
12308 spin_lock(&mce_state_lock);
12309
12310- open_count--;
12311+ local_dec(&open_count);
12312 open_exclu = 0;
12313
12314 spin_unlock(&mce_state_lock);
12315@@ -2082,7 +2083,7 @@ struct dentry *mce_get_debugfs_dir(void)
12316 static void mce_reset(void)
12317 {
12318 cpu_missing = 0;
12319- atomic_set(&mce_fake_paniced, 0);
12320+ atomic_set_unchecked(&mce_fake_paniced, 0);
12321 atomic_set(&mce_executing, 0);
12322 atomic_set(&mce_callin, 0);
12323 atomic_set(&global_nwo, 0);
12324diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce-inject.c linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce-inject.c
12325--- linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-03-27 14:31:47.000000000 -0400
12326+++ linux-2.6.32.44/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-08-05 20:33:55.000000000 -0400
12327@@ -211,7 +211,9 @@ static ssize_t mce_write(struct file *fi
12328 static int inject_init(void)
12329 {
12330 printk(KERN_INFO "Machine check injector initialized\n");
12331- mce_chrdev_ops.write = mce_write;
12332+ pax_open_kernel();
12333+ *(void **)&mce_chrdev_ops.write = mce_write;
12334+ pax_close_kernel();
12335 register_die_notifier(&mce_raise_nb);
12336 return 0;
12337 }
12338diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/amd.c linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/amd.c
12339--- linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/amd.c 2011-03-27 14:31:47.000000000 -0400
12340+++ linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/amd.c 2011-04-17 15:56:46.000000000 -0400
12341@@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base
12342 return 0;
12343 }
12344
12345-static struct mtrr_ops amd_mtrr_ops = {
12346+static const struct mtrr_ops amd_mtrr_ops = {
12347 .vendor = X86_VENDOR_AMD,
12348 .set = amd_set_mtrr,
12349 .get = amd_get_mtrr,
12350diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/centaur.c linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/centaur.c
12351--- linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/centaur.c 2011-03-27 14:31:47.000000000 -0400
12352+++ linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/centaur.c 2011-04-17 15:56:46.000000000 -0400
12353@@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long
12354 return 0;
12355 }
12356
12357-static struct mtrr_ops centaur_mtrr_ops = {
12358+static const struct mtrr_ops centaur_mtrr_ops = {
12359 .vendor = X86_VENDOR_CENTAUR,
12360 .set = centaur_set_mcr,
12361 .get = centaur_get_mcr,
12362diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/cyrix.c linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/cyrix.c
12363--- linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-03-27 14:31:47.000000000 -0400
12364+++ linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-04-17 15:56:46.000000000 -0400
12365@@ -265,7 +265,7 @@ static void cyrix_set_all(void)
12366 post_set();
12367 }
12368
12369-static struct mtrr_ops cyrix_mtrr_ops = {
12370+static const struct mtrr_ops cyrix_mtrr_ops = {
12371 .vendor = X86_VENDOR_CYRIX,
12372 .set_all = cyrix_set_all,
12373 .set = cyrix_set_arr,
12374diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/generic.c
12375--- linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/generic.c 2011-03-27 14:31:47.000000000 -0400
12376+++ linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/generic.c 2011-04-23 12:56:10.000000000 -0400
12377@@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
12378 /*
12379 * Generic structure...
12380 */
12381-struct mtrr_ops generic_mtrr_ops = {
12382+const struct mtrr_ops generic_mtrr_ops = {
12383 .use_intel_if = 1,
12384 .set_all = generic_set_all,
12385 .get = generic_get_mtrr,
12386diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/main.c
12387--- linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:00:52.000000000 -0400
12388+++ linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:03:05.000000000 -0400
12389@@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
12390 u64 size_or_mask, size_and_mask;
12391 static bool mtrr_aps_delayed_init;
12392
12393-static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12394+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12395
12396-struct mtrr_ops *mtrr_if;
12397+const struct mtrr_ops *mtrr_if;
12398
12399 static void set_mtrr(unsigned int reg, unsigned long base,
12400 unsigned long size, mtrr_type type);
12401
12402-void set_mtrr_ops(struct mtrr_ops *ops)
12403+void set_mtrr_ops(const struct mtrr_ops *ops)
12404 {
12405 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
12406 mtrr_ops[ops->vendor] = ops;
12407diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/mtrr.h
12408--- linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-03-27 14:31:47.000000000 -0400
12409+++ linux-2.6.32.44/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-04-17 15:56:46.000000000 -0400
12410@@ -12,19 +12,19 @@
12411 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
12412
12413 struct mtrr_ops {
12414- u32 vendor;
12415- u32 use_intel_if;
12416- void (*set)(unsigned int reg, unsigned long base,
12417+ const u32 vendor;
12418+ const u32 use_intel_if;
12419+ void (* const set)(unsigned int reg, unsigned long base,
12420 unsigned long size, mtrr_type type);
12421- void (*set_all)(void);
12422+ void (* const set_all)(void);
12423
12424- void (*get)(unsigned int reg, unsigned long *base,
12425+ void (* const get)(unsigned int reg, unsigned long *base,
12426 unsigned long *size, mtrr_type *type);
12427- int (*get_free_region)(unsigned long base, unsigned long size,
12428+ int (* const get_free_region)(unsigned long base, unsigned long size,
12429 int replace_reg);
12430- int (*validate_add_page)(unsigned long base, unsigned long size,
12431+ int (* const validate_add_page)(unsigned long base, unsigned long size,
12432 unsigned int type);
12433- int (*have_wrcomb)(void);
12434+ int (* const have_wrcomb)(void);
12435 };
12436
12437 extern int generic_get_free_region(unsigned long base, unsigned long size,
12438@@ -32,7 +32,7 @@ extern int generic_get_free_region(unsig
12439 extern int generic_validate_add_page(unsigned long base, unsigned long size,
12440 unsigned int type);
12441
12442-extern struct mtrr_ops generic_mtrr_ops;
12443+extern const struct mtrr_ops generic_mtrr_ops;
12444
12445 extern int positive_have_wrcomb(void);
12446
12447@@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int in
12448 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
12449 void get_mtrr_state(void);
12450
12451-extern void set_mtrr_ops(struct mtrr_ops *ops);
12452+extern void set_mtrr_ops(const struct mtrr_ops *ops);
12453
12454 extern u64 size_or_mask, size_and_mask;
12455-extern struct mtrr_ops *mtrr_if;
12456+extern const struct mtrr_ops *mtrr_if;
12457
12458 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
12459 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
12460diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/perfctr-watchdog.c linux-2.6.32.44/arch/x86/kernel/cpu/perfctr-watchdog.c
12461--- linux-2.6.32.44/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-03-27 14:31:47.000000000 -0400
12462+++ linux-2.6.32.44/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-04-17 15:56:46.000000000 -0400
12463@@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
12464
12465 /* Interface defining a CPU specific perfctr watchdog */
12466 struct wd_ops {
12467- int (*reserve)(void);
12468- void (*unreserve)(void);
12469- int (*setup)(unsigned nmi_hz);
12470- void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
12471- void (*stop)(void);
12472+ int (* const reserve)(void);
12473+ void (* const unreserve)(void);
12474+ int (* const setup)(unsigned nmi_hz);
12475+ void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
12476+ void (* const stop)(void);
12477 unsigned perfctr;
12478 unsigned evntsel;
12479 u64 checkbit;
12480@@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
12481 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
12482 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
12483
12484+/* cannot be const */
12485 static struct wd_ops intel_arch_wd_ops;
12486
12487 static int setup_intel_arch_watchdog(unsigned nmi_hz)
12488@@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(uns
12489 return 1;
12490 }
12491
12492+/* cannot be const */
12493 static struct wd_ops intel_arch_wd_ops __read_mostly = {
12494 .reserve = single_msr_reserve,
12495 .unreserve = single_msr_unreserve,
12496diff -urNp linux-2.6.32.44/arch/x86/kernel/cpu/perf_event.c linux-2.6.32.44/arch/x86/kernel/cpu/perf_event.c
12497--- linux-2.6.32.44/arch/x86/kernel/cpu/perf_event.c 2011-03-27 14:31:47.000000000 -0400
12498+++ linux-2.6.32.44/arch/x86/kernel/cpu/perf_event.c 2011-05-04 17:56:20.000000000 -0400
12499@@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event
12500 * count to the generic event atomically:
12501 */
12502 again:
12503- prev_raw_count = atomic64_read(&hwc->prev_count);
12504+ prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
12505 rdmsrl(hwc->event_base + idx, new_raw_count);
12506
12507- if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
12508+ if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
12509 new_raw_count) != prev_raw_count)
12510 goto again;
12511
12512@@ -741,7 +741,7 @@ again:
12513 delta = (new_raw_count << shift) - (prev_raw_count << shift);
12514 delta >>= shift;
12515
12516- atomic64_add(delta, &event->count);
12517+ atomic64_add_unchecked(delta, &event->count);
12518 atomic64_sub(delta, &hwc->period_left);
12519
12520 return new_raw_count;
12521@@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_ev
12522 * The hw event starts counting from this event offset,
12523 * mark it to be able to extra future deltas:
12524 */
12525- atomic64_set(&hwc->prev_count, (u64)-left);
12526+ atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
12527
12528 err = checking_wrmsrl(hwc->event_base + idx,
12529 (u64)(-left) & x86_pmu.event_mask);
12530@@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs
12531 break;
12532
12533 callchain_store(entry, frame.return_address);
12534- fp = frame.next_frame;
12535+ fp = (__force const void __user *)frame.next_frame;
12536 }
12537 }
12538
12539diff -urNp linux-2.6.32.44/arch/x86/kernel/crash.c linux-2.6.32.44/arch/x86/kernel/crash.c
12540--- linux-2.6.32.44/arch/x86/kernel/crash.c 2011-03-27 14:31:47.000000000 -0400
12541+++ linux-2.6.32.44/arch/x86/kernel/crash.c 2011-04-17 15:56:46.000000000 -0400
12542@@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu,
12543 regs = args->regs;
12544
12545 #ifdef CONFIG_X86_32
12546- if (!user_mode_vm(regs)) {
12547+ if (!user_mode(regs)) {
12548 crash_fixup_ss_esp(&fixed_regs, regs);
12549 regs = &fixed_regs;
12550 }
12551diff -urNp linux-2.6.32.44/arch/x86/kernel/doublefault_32.c linux-2.6.32.44/arch/x86/kernel/doublefault_32.c
12552--- linux-2.6.32.44/arch/x86/kernel/doublefault_32.c 2011-03-27 14:31:47.000000000 -0400
12553+++ linux-2.6.32.44/arch/x86/kernel/doublefault_32.c 2011-04-17 15:56:46.000000000 -0400
12554@@ -11,7 +11,7 @@
12555
12556 #define DOUBLEFAULT_STACKSIZE (1024)
12557 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12558-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12559+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12560
12561 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12562
12563@@ -21,7 +21,7 @@ static void doublefault_fn(void)
12564 unsigned long gdt, tss;
12565
12566 store_gdt(&gdt_desc);
12567- gdt = gdt_desc.address;
12568+ gdt = (unsigned long)gdt_desc.address;
12569
12570 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12571
12572@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
12573 /* 0x2 bit is always set */
12574 .flags = X86_EFLAGS_SF | 0x2,
12575 .sp = STACK_START,
12576- .es = __USER_DS,
12577+ .es = __KERNEL_DS,
12578 .cs = __KERNEL_CS,
12579 .ss = __KERNEL_DS,
12580- .ds = __USER_DS,
12581+ .ds = __KERNEL_DS,
12582 .fs = __KERNEL_PERCPU,
12583
12584 .__cr3 = __pa_nodebug(swapper_pg_dir),
12585diff -urNp linux-2.6.32.44/arch/x86/kernel/dumpstack_32.c linux-2.6.32.44/arch/x86/kernel/dumpstack_32.c
12586--- linux-2.6.32.44/arch/x86/kernel/dumpstack_32.c 2011-03-27 14:31:47.000000000 -0400
12587+++ linux-2.6.32.44/arch/x86/kernel/dumpstack_32.c 2011-04-17 15:56:46.000000000 -0400
12588@@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task
12589 #endif
12590
12591 for (;;) {
12592- struct thread_info *context;
12593+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12594+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12595
12596- context = (struct thread_info *)
12597- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12598- bp = print_context_stack(context, stack, bp, ops,
12599- data, NULL, &graph);
12600-
12601- stack = (unsigned long *)context->previous_esp;
12602- if (!stack)
12603+ if (stack_start == task_stack_page(task))
12604 break;
12605+ stack = *(unsigned long **)stack_start;
12606 if (ops->stack(data, "IRQ") < 0)
12607 break;
12608 touch_nmi_watchdog();
12609@@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs
12610 * When in-kernel, we also print out the stack and code at the
12611 * time of the fault..
12612 */
12613- if (!user_mode_vm(regs)) {
12614+ if (!user_mode(regs)) {
12615 unsigned int code_prologue = code_bytes * 43 / 64;
12616 unsigned int code_len = code_bytes;
12617 unsigned char c;
12618 u8 *ip;
12619+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12620
12621 printk(KERN_EMERG "Stack:\n");
12622 show_stack_log_lvl(NULL, regs, &regs->sp,
12623@@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs
12624
12625 printk(KERN_EMERG "Code: ");
12626
12627- ip = (u8 *)regs->ip - code_prologue;
12628+ ip = (u8 *)regs->ip - code_prologue + cs_base;
12629 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12630 /* try starting at IP */
12631- ip = (u8 *)regs->ip;
12632+ ip = (u8 *)regs->ip + cs_base;
12633 code_len = code_len - code_prologue + 1;
12634 }
12635 for (i = 0; i < code_len; i++, ip++) {
12636@@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs
12637 printk(" Bad EIP value.");
12638 break;
12639 }
12640- if (ip == (u8 *)regs->ip)
12641+ if (ip == (u8 *)regs->ip + cs_base)
12642 printk("<%02x> ", c);
12643 else
12644 printk("%02x ", c);
12645@@ -149,6 +146,7 @@ int is_valid_bugaddr(unsigned long ip)
12646 {
12647 unsigned short ud2;
12648
12649+ ip = ktla_ktva(ip);
12650 if (ip < PAGE_OFFSET)
12651 return 0;
12652 if (probe_kernel_address((unsigned short *)ip, ud2))
12653diff -urNp linux-2.6.32.44/arch/x86/kernel/dumpstack_64.c linux-2.6.32.44/arch/x86/kernel/dumpstack_64.c
12654--- linux-2.6.32.44/arch/x86/kernel/dumpstack_64.c 2011-03-27 14:31:47.000000000 -0400
12655+++ linux-2.6.32.44/arch/x86/kernel/dumpstack_64.c 2011-04-17 15:56:46.000000000 -0400
12656@@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task
12657 unsigned long *irq_stack_end =
12658 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12659 unsigned used = 0;
12660- struct thread_info *tinfo;
12661 int graph = 0;
12662+ void *stack_start;
12663
12664 if (!task)
12665 task = current;
12666@@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task
12667 * current stack address. If the stacks consist of nested
12668 * exceptions
12669 */
12670- tinfo = task_thread_info(task);
12671 for (;;) {
12672 char *id;
12673 unsigned long *estack_end;
12674+
12675 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12676 &used, &id);
12677
12678@@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task
12679 if (ops->stack(data, id) < 0)
12680 break;
12681
12682- bp = print_context_stack(tinfo, stack, bp, ops,
12683+ bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12684 data, estack_end, &graph);
12685 ops->stack(data, "<EOE>");
12686 /*
12687@@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task
12688 if (stack >= irq_stack && stack < irq_stack_end) {
12689 if (ops->stack(data, "IRQ") < 0)
12690 break;
12691- bp = print_context_stack(tinfo, stack, bp,
12692+ bp = print_context_stack(task, irq_stack, stack, bp,
12693 ops, data, irq_stack_end, &graph);
12694 /*
12695 * We link to the next stack (which would be
12696@@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task
12697 /*
12698 * This handles the process stack:
12699 */
12700- bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12701+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12702+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12703 put_cpu();
12704 }
12705 EXPORT_SYMBOL(dump_trace);
12706diff -urNp linux-2.6.32.44/arch/x86/kernel/dumpstack.c linux-2.6.32.44/arch/x86/kernel/dumpstack.c
12707--- linux-2.6.32.44/arch/x86/kernel/dumpstack.c 2011-03-27 14:31:47.000000000 -0400
12708+++ linux-2.6.32.44/arch/x86/kernel/dumpstack.c 2011-04-17 15:56:46.000000000 -0400
12709@@ -2,6 +2,9 @@
12710 * Copyright (C) 1991, 1992 Linus Torvalds
12711 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12712 */
12713+#ifdef CONFIG_GRKERNSEC_HIDESYM
12714+#define __INCLUDED_BY_HIDESYM 1
12715+#endif
12716 #include <linux/kallsyms.h>
12717 #include <linux/kprobes.h>
12718 #include <linux/uaccess.h>
12719@@ -28,7 +31,7 @@ static int die_counter;
12720
12721 void printk_address(unsigned long address, int reliable)
12722 {
12723- printk(" [<%p>] %s%pS\n", (void *) address,
12724+ printk(" [<%p>] %s%pA\n", (void *) address,
12725 reliable ? "" : "? ", (void *) address);
12726 }
12727
12728@@ -36,9 +39,8 @@ void printk_address(unsigned long addres
12729 static void
12730 print_ftrace_graph_addr(unsigned long addr, void *data,
12731 const struct stacktrace_ops *ops,
12732- struct thread_info *tinfo, int *graph)
12733+ struct task_struct *task, int *graph)
12734 {
12735- struct task_struct *task = tinfo->task;
12736 unsigned long ret_addr;
12737 int index = task->curr_ret_stack;
12738
12739@@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long ad
12740 static inline void
12741 print_ftrace_graph_addr(unsigned long addr, void *data,
12742 const struct stacktrace_ops *ops,
12743- struct thread_info *tinfo, int *graph)
12744+ struct task_struct *task, int *graph)
12745 { }
12746 #endif
12747
12748@@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long ad
12749 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12750 */
12751
12752-static inline int valid_stack_ptr(struct thread_info *tinfo,
12753- void *p, unsigned int size, void *end)
12754+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12755 {
12756- void *t = tinfo;
12757 if (end) {
12758 if (p < end && p >= (end-THREAD_SIZE))
12759 return 1;
12760@@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct
12761 }
12762
12763 unsigned long
12764-print_context_stack(struct thread_info *tinfo,
12765+print_context_stack(struct task_struct *task, void *stack_start,
12766 unsigned long *stack, unsigned long bp,
12767 const struct stacktrace_ops *ops, void *data,
12768 unsigned long *end, int *graph)
12769 {
12770 struct stack_frame *frame = (struct stack_frame *)bp;
12771
12772- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12773+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12774 unsigned long addr;
12775
12776 addr = *stack;
12777@@ -103,7 +103,7 @@ print_context_stack(struct thread_info *
12778 } else {
12779 ops->address(data, addr, 0);
12780 }
12781- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12782+ print_ftrace_graph_addr(addr, data, ops, task, graph);
12783 }
12784 stack++;
12785 }
12786@@ -180,7 +180,7 @@ void dump_stack(void)
12787 #endif
12788
12789 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12790- current->pid, current->comm, print_tainted(),
12791+ task_pid_nr(current), current->comm, print_tainted(),
12792 init_utsname()->release,
12793 (int)strcspn(init_utsname()->version, " "),
12794 init_utsname()->version);
12795@@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
12796 return flags;
12797 }
12798
12799+extern void gr_handle_kernel_exploit(void);
12800+
12801 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12802 {
12803 if (regs && kexec_should_crash(current))
12804@@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long fl
12805 panic("Fatal exception in interrupt");
12806 if (panic_on_oops)
12807 panic("Fatal exception");
12808- do_exit(signr);
12809+
12810+ gr_handle_kernel_exploit();
12811+
12812+ do_group_exit(signr);
12813 }
12814
12815 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12816@@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs
12817 unsigned long flags = oops_begin();
12818 int sig = SIGSEGV;
12819
12820- if (!user_mode_vm(regs))
12821+ if (!user_mode(regs))
12822 report_bug(regs->ip, regs);
12823
12824 if (__die(str, regs, err))
12825diff -urNp linux-2.6.32.44/arch/x86/kernel/dumpstack.h linux-2.6.32.44/arch/x86/kernel/dumpstack.h
12826--- linux-2.6.32.44/arch/x86/kernel/dumpstack.h 2011-03-27 14:31:47.000000000 -0400
12827+++ linux-2.6.32.44/arch/x86/kernel/dumpstack.h 2011-04-23 13:25:26.000000000 -0400
12828@@ -15,7 +15,7 @@
12829 #endif
12830
12831 extern unsigned long
12832-print_context_stack(struct thread_info *tinfo,
12833+print_context_stack(struct task_struct *task, void *stack_start,
12834 unsigned long *stack, unsigned long bp,
12835 const struct stacktrace_ops *ops, void *data,
12836 unsigned long *end, int *graph);
12837diff -urNp linux-2.6.32.44/arch/x86/kernel/e820.c linux-2.6.32.44/arch/x86/kernel/e820.c
12838--- linux-2.6.32.44/arch/x86/kernel/e820.c 2011-03-27 14:31:47.000000000 -0400
12839+++ linux-2.6.32.44/arch/x86/kernel/e820.c 2011-04-17 15:56:46.000000000 -0400
12840@@ -733,7 +733,7 @@ struct early_res {
12841 };
12842 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
12843 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
12844- {}
12845+ { 0, 0, {0}, 0 }
12846 };
12847
12848 static int __init find_overlapped_early(u64 start, u64 end)
12849diff -urNp linux-2.6.32.44/arch/x86/kernel/early_printk.c linux-2.6.32.44/arch/x86/kernel/early_printk.c
12850--- linux-2.6.32.44/arch/x86/kernel/early_printk.c 2011-03-27 14:31:47.000000000 -0400
12851+++ linux-2.6.32.44/arch/x86/kernel/early_printk.c 2011-05-16 21:46:57.000000000 -0400
12852@@ -7,6 +7,7 @@
12853 #include <linux/pci_regs.h>
12854 #include <linux/pci_ids.h>
12855 #include <linux/errno.h>
12856+#include <linux/sched.h>
12857 #include <asm/io.h>
12858 #include <asm/processor.h>
12859 #include <asm/fcntl.h>
12860@@ -170,6 +171,8 @@ asmlinkage void early_printk(const char
12861 int n;
12862 va_list ap;
12863
12864+ pax_track_stack();
12865+
12866 va_start(ap, fmt);
12867 n = vscnprintf(buf, sizeof(buf), fmt, ap);
12868 early_console->write(early_console, buf, n);
12869diff -urNp linux-2.6.32.44/arch/x86/kernel/efi_32.c linux-2.6.32.44/arch/x86/kernel/efi_32.c
12870--- linux-2.6.32.44/arch/x86/kernel/efi_32.c 2011-03-27 14:31:47.000000000 -0400
12871+++ linux-2.6.32.44/arch/x86/kernel/efi_32.c 2011-04-17 15:56:46.000000000 -0400
12872@@ -38,70 +38,38 @@
12873 */
12874
12875 static unsigned long efi_rt_eflags;
12876-static pgd_t efi_bak_pg_dir_pointer[2];
12877+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
12878
12879-void efi_call_phys_prelog(void)
12880+void __init efi_call_phys_prelog(void)
12881 {
12882- unsigned long cr4;
12883- unsigned long temp;
12884 struct desc_ptr gdt_descr;
12885
12886 local_irq_save(efi_rt_eflags);
12887
12888- /*
12889- * If I don't have PAE, I should just duplicate two entries in page
12890- * directory. If I have PAE, I just need to duplicate one entry in
12891- * page directory.
12892- */
12893- cr4 = read_cr4_safe();
12894
12895- if (cr4 & X86_CR4_PAE) {
12896- efi_bak_pg_dir_pointer[0].pgd =
12897- swapper_pg_dir[pgd_index(0)].pgd;
12898- swapper_pg_dir[0].pgd =
12899- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
12900- } else {
12901- efi_bak_pg_dir_pointer[0].pgd =
12902- swapper_pg_dir[pgd_index(0)].pgd;
12903- efi_bak_pg_dir_pointer[1].pgd =
12904- swapper_pg_dir[pgd_index(0x400000)].pgd;
12905- swapper_pg_dir[pgd_index(0)].pgd =
12906- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
12907- temp = PAGE_OFFSET + 0x400000;
12908- swapper_pg_dir[pgd_index(0x400000)].pgd =
12909- swapper_pg_dir[pgd_index(temp)].pgd;
12910- }
12911+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
12912+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
12913+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
12914
12915 /*
12916 * After the lock is released, the original page table is restored.
12917 */
12918 __flush_tlb_all();
12919
12920- gdt_descr.address = __pa(get_cpu_gdt_table(0));
12921+ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
12922 gdt_descr.size = GDT_SIZE - 1;
12923 load_gdt(&gdt_descr);
12924 }
12925
12926-void efi_call_phys_epilog(void)
12927+void __init efi_call_phys_epilog(void)
12928 {
12929- unsigned long cr4;
12930 struct desc_ptr gdt_descr;
12931
12932- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
12933+ gdt_descr.address = get_cpu_gdt_table(0);
12934 gdt_descr.size = GDT_SIZE - 1;
12935 load_gdt(&gdt_descr);
12936
12937- cr4 = read_cr4_safe();
12938-
12939- if (cr4 & X86_CR4_PAE) {
12940- swapper_pg_dir[pgd_index(0)].pgd =
12941- efi_bak_pg_dir_pointer[0].pgd;
12942- } else {
12943- swapper_pg_dir[pgd_index(0)].pgd =
12944- efi_bak_pg_dir_pointer[0].pgd;
12945- swapper_pg_dir[pgd_index(0x400000)].pgd =
12946- efi_bak_pg_dir_pointer[1].pgd;
12947- }
12948+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
12949
12950 /*
12951 * After the lock is released, the original page table is restored.
12952diff -urNp linux-2.6.32.44/arch/x86/kernel/efi_stub_32.S linux-2.6.32.44/arch/x86/kernel/efi_stub_32.S
12953--- linux-2.6.32.44/arch/x86/kernel/efi_stub_32.S 2011-03-27 14:31:47.000000000 -0400
12954+++ linux-2.6.32.44/arch/x86/kernel/efi_stub_32.S 2011-04-17 15:56:46.000000000 -0400
12955@@ -6,6 +6,7 @@
12956 */
12957
12958 #include <linux/linkage.h>
12959+#include <linux/init.h>
12960 #include <asm/page_types.h>
12961
12962 /*
12963@@ -20,7 +21,7 @@
12964 * service functions will comply with gcc calling convention, too.
12965 */
12966
12967-.text
12968+__INIT
12969 ENTRY(efi_call_phys)
12970 /*
12971 * 0. The function can only be called in Linux kernel. So CS has been
12972@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
12973 * The mapping of lower virtual memory has been created in prelog and
12974 * epilog.
12975 */
12976- movl $1f, %edx
12977- subl $__PAGE_OFFSET, %edx
12978- jmp *%edx
12979+ jmp 1f-__PAGE_OFFSET
12980 1:
12981
12982 /*
12983@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
12984 * parameter 2, ..., param n. To make things easy, we save the return
12985 * address of efi_call_phys in a global variable.
12986 */
12987- popl %edx
12988- movl %edx, saved_return_addr
12989- /* get the function pointer into ECX*/
12990- popl %ecx
12991- movl %ecx, efi_rt_function_ptr
12992- movl $2f, %edx
12993- subl $__PAGE_OFFSET, %edx
12994- pushl %edx
12995+ popl (saved_return_addr)
12996+ popl (efi_rt_function_ptr)
12997
12998 /*
12999 * 3. Clear PG bit in %CR0.
13000@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
13001 /*
13002 * 5. Call the physical function.
13003 */
13004- jmp *%ecx
13005+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
13006
13007-2:
13008 /*
13009 * 6. After EFI runtime service returns, control will return to
13010 * following instruction. We'd better readjust stack pointer first.
13011@@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
13012 movl %cr0, %edx
13013 orl $0x80000000, %edx
13014 movl %edx, %cr0
13015- jmp 1f
13016-1:
13017+
13018 /*
13019 * 8. Now restore the virtual mode from flat mode by
13020 * adding EIP with PAGE_OFFSET.
13021 */
13022- movl $1f, %edx
13023- jmp *%edx
13024+ jmp 1f+__PAGE_OFFSET
13025 1:
13026
13027 /*
13028 * 9. Balance the stack. And because EAX contain the return value,
13029 * we'd better not clobber it.
13030 */
13031- leal efi_rt_function_ptr, %edx
13032- movl (%edx), %ecx
13033- pushl %ecx
13034+ pushl (efi_rt_function_ptr)
13035
13036 /*
13037- * 10. Push the saved return address onto the stack and return.
13038+ * 10. Return to the saved return address.
13039 */
13040- leal saved_return_addr, %edx
13041- movl (%edx), %ecx
13042- pushl %ecx
13043- ret
13044+ jmpl *(saved_return_addr)
13045 ENDPROC(efi_call_phys)
13046 .previous
13047
13048-.data
13049+__INITDATA
13050 saved_return_addr:
13051 .long 0
13052 efi_rt_function_ptr:
13053diff -urNp linux-2.6.32.44/arch/x86/kernel/entry_32.S linux-2.6.32.44/arch/x86/kernel/entry_32.S
13054--- linux-2.6.32.44/arch/x86/kernel/entry_32.S 2011-03-27 14:31:47.000000000 -0400
13055+++ linux-2.6.32.44/arch/x86/kernel/entry_32.S 2011-05-22 23:02:03.000000000 -0400
13056@@ -185,13 +185,146 @@
13057 /*CFI_REL_OFFSET gs, PT_GS*/
13058 .endm
13059 .macro SET_KERNEL_GS reg
13060+
13061+#ifdef CONFIG_CC_STACKPROTECTOR
13062 movl $(__KERNEL_STACK_CANARY), \reg
13063+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13064+ movl $(__USER_DS), \reg
13065+#else
13066+ xorl \reg, \reg
13067+#endif
13068+
13069 movl \reg, %gs
13070 .endm
13071
13072 #endif /* CONFIG_X86_32_LAZY_GS */
13073
13074-.macro SAVE_ALL
13075+.macro pax_enter_kernel
13076+#ifdef CONFIG_PAX_KERNEXEC
13077+ call pax_enter_kernel
13078+#endif
13079+.endm
13080+
13081+.macro pax_exit_kernel
13082+#ifdef CONFIG_PAX_KERNEXEC
13083+ call pax_exit_kernel
13084+#endif
13085+.endm
13086+
13087+#ifdef CONFIG_PAX_KERNEXEC
13088+ENTRY(pax_enter_kernel)
13089+#ifdef CONFIG_PARAVIRT
13090+ pushl %eax
13091+ pushl %ecx
13092+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13093+ mov %eax, %esi
13094+#else
13095+ mov %cr0, %esi
13096+#endif
13097+ bts $16, %esi
13098+ jnc 1f
13099+ mov %cs, %esi
13100+ cmp $__KERNEL_CS, %esi
13101+ jz 3f
13102+ ljmp $__KERNEL_CS, $3f
13103+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13104+2:
13105+#ifdef CONFIG_PARAVIRT
13106+ mov %esi, %eax
13107+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13108+#else
13109+ mov %esi, %cr0
13110+#endif
13111+3:
13112+#ifdef CONFIG_PARAVIRT
13113+ popl %ecx
13114+ popl %eax
13115+#endif
13116+ ret
13117+ENDPROC(pax_enter_kernel)
13118+
13119+ENTRY(pax_exit_kernel)
13120+#ifdef CONFIG_PARAVIRT
13121+ pushl %eax
13122+ pushl %ecx
13123+#endif
13124+ mov %cs, %esi
13125+ cmp $__KERNEXEC_KERNEL_CS, %esi
13126+ jnz 2f
13127+#ifdef CONFIG_PARAVIRT
13128+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13129+ mov %eax, %esi
13130+#else
13131+ mov %cr0, %esi
13132+#endif
13133+ btr $16, %esi
13134+ ljmp $__KERNEL_CS, $1f
13135+1:
13136+#ifdef CONFIG_PARAVIRT
13137+ mov %esi, %eax
13138+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13139+#else
13140+ mov %esi, %cr0
13141+#endif
13142+2:
13143+#ifdef CONFIG_PARAVIRT
13144+ popl %ecx
13145+ popl %eax
13146+#endif
13147+ ret
13148+ENDPROC(pax_exit_kernel)
13149+#endif
13150+
13151+.macro pax_erase_kstack
13152+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13153+ call pax_erase_kstack
13154+#endif
13155+.endm
13156+
13157+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13158+/*
13159+ * ebp: thread_info
13160+ * ecx, edx: can be clobbered
13161+ */
13162+ENTRY(pax_erase_kstack)
13163+ pushl %edi
13164+ pushl %eax
13165+
13166+ mov TI_lowest_stack(%ebp), %edi
13167+ mov $-0xBEEF, %eax
13168+ std
13169+
13170+1: mov %edi, %ecx
13171+ and $THREAD_SIZE_asm - 1, %ecx
13172+ shr $2, %ecx
13173+ repne scasl
13174+ jecxz 2f
13175+
13176+ cmp $2*16, %ecx
13177+ jc 2f
13178+
13179+ mov $2*16, %ecx
13180+ repe scasl
13181+ jecxz 2f
13182+ jne 1b
13183+
13184+2: cld
13185+ mov %esp, %ecx
13186+ sub %edi, %ecx
13187+ shr $2, %ecx
13188+ rep stosl
13189+
13190+ mov TI_task_thread_sp0(%ebp), %edi
13191+ sub $128, %edi
13192+ mov %edi, TI_lowest_stack(%ebp)
13193+
13194+ popl %eax
13195+ popl %edi
13196+ ret
13197+ENDPROC(pax_erase_kstack)
13198+#endif
13199+
13200+.macro __SAVE_ALL _DS
13201 cld
13202 PUSH_GS
13203 pushl %fs
13204@@ -224,7 +357,7 @@
13205 pushl %ebx
13206 CFI_ADJUST_CFA_OFFSET 4
13207 CFI_REL_OFFSET ebx, 0
13208- movl $(__USER_DS), %edx
13209+ movl $\_DS, %edx
13210 movl %edx, %ds
13211 movl %edx, %es
13212 movl $(__KERNEL_PERCPU), %edx
13213@@ -232,6 +365,15 @@
13214 SET_KERNEL_GS %edx
13215 .endm
13216
13217+.macro SAVE_ALL
13218+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13219+ __SAVE_ALL __KERNEL_DS
13220+ pax_enter_kernel
13221+#else
13222+ __SAVE_ALL __USER_DS
13223+#endif
13224+.endm
13225+
13226 .macro RESTORE_INT_REGS
13227 popl %ebx
13228 CFI_ADJUST_CFA_OFFSET -4
13229@@ -352,7 +494,15 @@ check_userspace:
13230 movb PT_CS(%esp), %al
13231 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13232 cmpl $USER_RPL, %eax
13233+
13234+#ifdef CONFIG_PAX_KERNEXEC
13235+ jae resume_userspace
13236+
13237+ PAX_EXIT_KERNEL
13238+ jmp resume_kernel
13239+#else
13240 jb resume_kernel # not returning to v8086 or userspace
13241+#endif
13242
13243 ENTRY(resume_userspace)
13244 LOCKDEP_SYS_EXIT
13245@@ -364,7 +514,7 @@ ENTRY(resume_userspace)
13246 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13247 # int/exception return?
13248 jne work_pending
13249- jmp restore_all
13250+ jmp restore_all_pax
13251 END(ret_from_exception)
13252
13253 #ifdef CONFIG_PREEMPT
13254@@ -414,25 +564,36 @@ sysenter_past_esp:
13255 /*CFI_REL_OFFSET cs, 0*/
13256 /*
13257 * Push current_thread_info()->sysenter_return to the stack.
13258- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13259- * pushed above; +8 corresponds to copy_thread's esp0 setting.
13260 */
13261- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
13262+ pushl $0
13263 CFI_ADJUST_CFA_OFFSET 4
13264 CFI_REL_OFFSET eip, 0
13265
13266 pushl %eax
13267 CFI_ADJUST_CFA_OFFSET 4
13268 SAVE_ALL
13269+ GET_THREAD_INFO(%ebp)
13270+ movl TI_sysenter_return(%ebp),%ebp
13271+ movl %ebp,PT_EIP(%esp)
13272 ENABLE_INTERRUPTS(CLBR_NONE)
13273
13274 /*
13275 * Load the potential sixth argument from user stack.
13276 * Careful about security.
13277 */
13278+ movl PT_OLDESP(%esp),%ebp
13279+
13280+#ifdef CONFIG_PAX_MEMORY_UDEREF
13281+ mov PT_OLDSS(%esp),%ds
13282+1: movl %ds:(%ebp),%ebp
13283+ push %ss
13284+ pop %ds
13285+#else
13286 cmpl $__PAGE_OFFSET-3,%ebp
13287 jae syscall_fault
13288 1: movl (%ebp),%ebp
13289+#endif
13290+
13291 movl %ebp,PT_EBP(%esp)
13292 .section __ex_table,"a"
13293 .align 4
13294@@ -455,12 +616,23 @@ sysenter_do_call:
13295 testl $_TIF_ALLWORK_MASK, %ecx
13296 jne sysexit_audit
13297 sysenter_exit:
13298+
13299+#ifdef CONFIG_PAX_RANDKSTACK
13300+ pushl_cfi %eax
13301+ call pax_randomize_kstack
13302+ popl_cfi %eax
13303+#endif
13304+
13305+ pax_erase_kstack
13306+
13307 /* if something modifies registers it must also disable sysexit */
13308 movl PT_EIP(%esp), %edx
13309 movl PT_OLDESP(%esp), %ecx
13310 xorl %ebp,%ebp
13311 TRACE_IRQS_ON
13312 1: mov PT_FS(%esp), %fs
13313+2: mov PT_DS(%esp), %ds
13314+3: mov PT_ES(%esp), %es
13315 PTGS_TO_GS
13316 ENABLE_INTERRUPTS_SYSEXIT
13317
13318@@ -477,6 +649,9 @@ sysenter_audit:
13319 movl %eax,%edx /* 2nd arg: syscall number */
13320 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13321 call audit_syscall_entry
13322+
13323+ pax_erase_kstack
13324+
13325 pushl %ebx
13326 CFI_ADJUST_CFA_OFFSET 4
13327 movl PT_EAX(%esp),%eax /* reload syscall number */
13328@@ -504,11 +679,17 @@ sysexit_audit:
13329
13330 CFI_ENDPROC
13331 .pushsection .fixup,"ax"
13332-2: movl $0,PT_FS(%esp)
13333+4: movl $0,PT_FS(%esp)
13334+ jmp 1b
13335+5: movl $0,PT_DS(%esp)
13336+ jmp 1b
13337+6: movl $0,PT_ES(%esp)
13338 jmp 1b
13339 .section __ex_table,"a"
13340 .align 4
13341- .long 1b,2b
13342+ .long 1b,4b
13343+ .long 2b,5b
13344+ .long 3b,6b
13345 .popsection
13346 PTGS_TO_GS_EX
13347 ENDPROC(ia32_sysenter_target)
13348@@ -538,6 +719,14 @@ syscall_exit:
13349 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13350 jne syscall_exit_work
13351
13352+restore_all_pax:
13353+
13354+#ifdef CONFIG_PAX_RANDKSTACK
13355+ call pax_randomize_kstack
13356+#endif
13357+
13358+ pax_erase_kstack
13359+
13360 restore_all:
13361 TRACE_IRQS_IRET
13362 restore_all_notrace:
13363@@ -602,7 +791,13 @@ ldt_ss:
13364 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13365 mov %dx, %ax /* eax: new kernel esp */
13366 sub %eax, %edx /* offset (low word is 0) */
13367- PER_CPU(gdt_page, %ebx)
13368+#ifdef CONFIG_SMP
13369+ movl PER_CPU_VAR(cpu_number), %ebx
13370+ shll $PAGE_SHIFT_asm, %ebx
13371+ addl $cpu_gdt_table, %ebx
13372+#else
13373+ movl $cpu_gdt_table, %ebx
13374+#endif
13375 shr $16, %edx
13376 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
13377 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
13378@@ -636,31 +831,25 @@ work_resched:
13379 movl TI_flags(%ebp), %ecx
13380 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13381 # than syscall tracing?
13382- jz restore_all
13383+ jz restore_all_pax
13384 testb $_TIF_NEED_RESCHED, %cl
13385 jnz work_resched
13386
13387 work_notifysig: # deal with pending signals and
13388 # notify-resume requests
13389+ movl %esp, %eax
13390 #ifdef CONFIG_VM86
13391 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13392- movl %esp, %eax
13393- jne work_notifysig_v86 # returning to kernel-space or
13394+ jz 1f # returning to kernel-space or
13395 # vm86-space
13396- xorl %edx, %edx
13397- call do_notify_resume
13398- jmp resume_userspace_sig
13399
13400- ALIGN
13401-work_notifysig_v86:
13402 pushl %ecx # save ti_flags for do_notify_resume
13403 CFI_ADJUST_CFA_OFFSET 4
13404 call save_v86_state # %eax contains pt_regs pointer
13405 popl %ecx
13406 CFI_ADJUST_CFA_OFFSET -4
13407 movl %eax, %esp
13408-#else
13409- movl %esp, %eax
13410+1:
13411 #endif
13412 xorl %edx, %edx
13413 call do_notify_resume
13414@@ -673,6 +862,9 @@ syscall_trace_entry:
13415 movl $-ENOSYS,PT_EAX(%esp)
13416 movl %esp, %eax
13417 call syscall_trace_enter
13418+
13419+ pax_erase_kstack
13420+
13421 /* What it returned is what we'll actually use. */
13422 cmpl $(nr_syscalls), %eax
13423 jnae syscall_call
13424@@ -695,6 +887,10 @@ END(syscall_exit_work)
13425
13426 RING0_INT_FRAME # can't unwind into user space anyway
13427 syscall_fault:
13428+#ifdef CONFIG_PAX_MEMORY_UDEREF
13429+ push %ss
13430+ pop %ds
13431+#endif
13432 GET_THREAD_INFO(%ebp)
13433 movl $-EFAULT,PT_EAX(%esp)
13434 jmp resume_userspace
13435@@ -726,6 +922,33 @@ PTREGSCALL(rt_sigreturn)
13436 PTREGSCALL(vm86)
13437 PTREGSCALL(vm86old)
13438
13439+ ALIGN;
13440+ENTRY(kernel_execve)
13441+ push %ebp
13442+ sub $PT_OLDSS+4,%esp
13443+ push %edi
13444+ push %ecx
13445+ push %eax
13446+ lea 3*4(%esp),%edi
13447+ mov $PT_OLDSS/4+1,%ecx
13448+ xorl %eax,%eax
13449+ rep stosl
13450+ pop %eax
13451+ pop %ecx
13452+ pop %edi
13453+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13454+ mov %eax,PT_EBX(%esp)
13455+ mov %edx,PT_ECX(%esp)
13456+ mov %ecx,PT_EDX(%esp)
13457+ mov %esp,%eax
13458+ call sys_execve
13459+ GET_THREAD_INFO(%ebp)
13460+ test %eax,%eax
13461+ jz syscall_exit
13462+ add $PT_OLDSS+4,%esp
13463+ pop %ebp
13464+ ret
13465+
13466 .macro FIXUP_ESPFIX_STACK
13467 /*
13468 * Switch back for ESPFIX stack to the normal zerobased stack
13469@@ -735,7 +958,13 @@ PTREGSCALL(vm86old)
13470 * normal stack and adjusts ESP with the matching offset.
13471 */
13472 /* fixup the stack */
13473- PER_CPU(gdt_page, %ebx)
13474+#ifdef CONFIG_SMP
13475+ movl PER_CPU_VAR(cpu_number), %ebx
13476+ shll $PAGE_SHIFT_asm, %ebx
13477+ addl $cpu_gdt_table, %ebx
13478+#else
13479+ movl $cpu_gdt_table, %ebx
13480+#endif
13481 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
13482 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
13483 shl $16, %eax
13484@@ -1198,7 +1427,6 @@ return_to_handler:
13485 ret
13486 #endif
13487
13488-.section .rodata,"a"
13489 #include "syscall_table_32.S"
13490
13491 syscall_table_size=(.-sys_call_table)
13492@@ -1255,9 +1483,12 @@ error_code:
13493 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13494 REG_TO_PTGS %ecx
13495 SET_KERNEL_GS %ecx
13496- movl $(__USER_DS), %ecx
13497+ movl $(__KERNEL_DS), %ecx
13498 movl %ecx, %ds
13499 movl %ecx, %es
13500+
13501+ pax_enter_kernel
13502+
13503 TRACE_IRQS_OFF
13504 movl %esp,%eax # pt_regs pointer
13505 call *%edi
13506@@ -1351,6 +1582,9 @@ nmi_stack_correct:
13507 xorl %edx,%edx # zero error code
13508 movl %esp,%eax # pt_regs pointer
13509 call do_nmi
13510+
13511+ pax_exit_kernel
13512+
13513 jmp restore_all_notrace
13514 CFI_ENDPROC
13515
13516@@ -1391,6 +1625,9 @@ nmi_espfix_stack:
13517 FIXUP_ESPFIX_STACK # %eax == %esp
13518 xorl %edx,%edx # zero error code
13519 call do_nmi
13520+
13521+ pax_exit_kernel
13522+
13523 RESTORE_REGS
13524 lss 12+4(%esp), %esp # back to espfix stack
13525 CFI_ADJUST_CFA_OFFSET -24
13526diff -urNp linux-2.6.32.44/arch/x86/kernel/entry_64.S linux-2.6.32.44/arch/x86/kernel/entry_64.S
13527--- linux-2.6.32.44/arch/x86/kernel/entry_64.S 2011-03-27 14:31:47.000000000 -0400
13528+++ linux-2.6.32.44/arch/x86/kernel/entry_64.S 2011-06-04 20:30:53.000000000 -0400
13529@@ -53,6 +53,7 @@
13530 #include <asm/paravirt.h>
13531 #include <asm/ftrace.h>
13532 #include <asm/percpu.h>
13533+#include <asm/pgtable.h>
13534
13535 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13536 #include <linux/elf-em.h>
13537@@ -174,6 +175,257 @@ ENTRY(native_usergs_sysret64)
13538 ENDPROC(native_usergs_sysret64)
13539 #endif /* CONFIG_PARAVIRT */
13540
13541+ .macro ljmpq sel, off
13542+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13543+ .byte 0x48; ljmp *1234f(%rip)
13544+ .pushsection .rodata
13545+ .align 16
13546+ 1234: .quad \off; .word \sel
13547+ .popsection
13548+#else
13549+ pushq $\sel
13550+ pushq $\off
13551+ lretq
13552+#endif
13553+ .endm
13554+
13555+ .macro pax_enter_kernel
13556+#ifdef CONFIG_PAX_KERNEXEC
13557+ call pax_enter_kernel
13558+#endif
13559+ .endm
13560+
13561+ .macro pax_exit_kernel
13562+#ifdef CONFIG_PAX_KERNEXEC
13563+ call pax_exit_kernel
13564+#endif
13565+ .endm
13566+
13567+#ifdef CONFIG_PAX_KERNEXEC
13568+ENTRY(pax_enter_kernel)
13569+ pushq %rdi
13570+
13571+#ifdef CONFIG_PARAVIRT
13572+ PV_SAVE_REGS(CLBR_RDI)
13573+#endif
13574+
13575+ GET_CR0_INTO_RDI
13576+ bts $16,%rdi
13577+ jnc 1f
13578+ mov %cs,%edi
13579+ cmp $__KERNEL_CS,%edi
13580+ jz 3f
13581+ ljmpq __KERNEL_CS,3f
13582+1: ljmpq __KERNEXEC_KERNEL_CS,2f
13583+2: SET_RDI_INTO_CR0
13584+3:
13585+
13586+#ifdef CONFIG_PARAVIRT
13587+ PV_RESTORE_REGS(CLBR_RDI)
13588+#endif
13589+
13590+ popq %rdi
13591+ retq
13592+ENDPROC(pax_enter_kernel)
13593+
13594+ENTRY(pax_exit_kernel)
13595+ pushq %rdi
13596+
13597+#ifdef CONFIG_PARAVIRT
13598+ PV_SAVE_REGS(CLBR_RDI)
13599+#endif
13600+
13601+ mov %cs,%rdi
13602+ cmp $__KERNEXEC_KERNEL_CS,%edi
13603+ jnz 2f
13604+ GET_CR0_INTO_RDI
13605+ btr $16,%rdi
13606+ ljmpq __KERNEL_CS,1f
13607+1: SET_RDI_INTO_CR0
13608+2:
13609+
13610+#ifdef CONFIG_PARAVIRT
13611+ PV_RESTORE_REGS(CLBR_RDI);
13612+#endif
13613+
13614+ popq %rdi
13615+ retq
13616+ENDPROC(pax_exit_kernel)
13617+#endif
13618+
13619+ .macro pax_enter_kernel_user
13620+#ifdef CONFIG_PAX_MEMORY_UDEREF
13621+ call pax_enter_kernel_user
13622+#endif
13623+ .endm
13624+
13625+ .macro pax_exit_kernel_user
13626+#ifdef CONFIG_PAX_MEMORY_UDEREF
13627+ call pax_exit_kernel_user
13628+#endif
13629+#ifdef CONFIG_PAX_RANDKSTACK
13630+ push %rax
13631+ call pax_randomize_kstack
13632+ pop %rax
13633+#endif
13634+ pax_erase_kstack
13635+ .endm
13636+
13637+#ifdef CONFIG_PAX_MEMORY_UDEREF
13638+ENTRY(pax_enter_kernel_user)
13639+ pushq %rdi
13640+ pushq %rbx
13641+
13642+#ifdef CONFIG_PARAVIRT
13643+ PV_SAVE_REGS(CLBR_RDI)
13644+#endif
13645+
13646+ GET_CR3_INTO_RDI
13647+ mov %rdi,%rbx
13648+ add $__START_KERNEL_map,%rbx
13649+ sub phys_base(%rip),%rbx
13650+
13651+#ifdef CONFIG_PARAVIRT
13652+ pushq %rdi
13653+ cmpl $0, pv_info+PARAVIRT_enabled
13654+ jz 1f
13655+ i = 0
13656+ .rept USER_PGD_PTRS
13657+ mov i*8(%rbx),%rsi
13658+ mov $0,%sil
13659+ lea i*8(%rbx),%rdi
13660+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
13661+ i = i + 1
13662+ .endr
13663+ jmp 2f
13664+1:
13665+#endif
13666+
13667+ i = 0
13668+ .rept USER_PGD_PTRS
13669+ movb $0,i*8(%rbx)
13670+ i = i + 1
13671+ .endr
13672+
13673+#ifdef CONFIG_PARAVIRT
13674+2: popq %rdi
13675+#endif
13676+ SET_RDI_INTO_CR3
13677+
13678+#ifdef CONFIG_PAX_KERNEXEC
13679+ GET_CR0_INTO_RDI
13680+ bts $16,%rdi
13681+ SET_RDI_INTO_CR0
13682+#endif
13683+
13684+#ifdef CONFIG_PARAVIRT
13685+ PV_RESTORE_REGS(CLBR_RDI)
13686+#endif
13687+
13688+ popq %rbx
13689+ popq %rdi
13690+ retq
13691+ENDPROC(pax_enter_kernel_user)
13692+
13693+ENTRY(pax_exit_kernel_user)
13694+ push %rdi
13695+
13696+#ifdef CONFIG_PARAVIRT
13697+ pushq %rbx
13698+ PV_SAVE_REGS(CLBR_RDI)
13699+#endif
13700+
13701+#ifdef CONFIG_PAX_KERNEXEC
13702+ GET_CR0_INTO_RDI
13703+ btr $16,%rdi
13704+ SET_RDI_INTO_CR0
13705+#endif
13706+
13707+ GET_CR3_INTO_RDI
13708+ add $__START_KERNEL_map,%rdi
13709+ sub phys_base(%rip),%rdi
13710+
13711+#ifdef CONFIG_PARAVIRT
13712+ cmpl $0, pv_info+PARAVIRT_enabled
13713+ jz 1f
13714+ mov %rdi,%rbx
13715+ i = 0
13716+ .rept USER_PGD_PTRS
13717+ mov i*8(%rbx),%rsi
13718+ mov $0x67,%sil
13719+ lea i*8(%rbx),%rdi
13720+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
13721+ i = i + 1
13722+ .endr
13723+ jmp 2f
13724+1:
13725+#endif
13726+
13727+ i = 0
13728+ .rept USER_PGD_PTRS
13729+ movb $0x67,i*8(%rdi)
13730+ i = i + 1
13731+ .endr
13732+
13733+#ifdef CONFIG_PARAVIRT
13734+2: PV_RESTORE_REGS(CLBR_RDI)
13735+ popq %rbx
13736+#endif
13737+
13738+ popq %rdi
13739+ retq
13740+ENDPROC(pax_exit_kernel_user)
13741+#endif
13742+
13743+.macro pax_erase_kstack
13744+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13745+ call pax_erase_kstack
13746+#endif
13747+.endm
13748+
13749+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13750+/*
13751+ * r10: thread_info
13752+ * rcx, rdx: can be clobbered
13753+ */
13754+ENTRY(pax_erase_kstack)
13755+ pushq %rdi
13756+ pushq %rax
13757+
13758+ GET_THREAD_INFO(%r10)
13759+ mov TI_lowest_stack(%r10), %rdi
13760+ mov $-0xBEEF, %rax
13761+ std
13762+
13763+1: mov %edi, %ecx
13764+ and $THREAD_SIZE_asm - 1, %ecx
13765+ shr $3, %ecx
13766+ repne scasq
13767+ jecxz 2f
13768+
13769+ cmp $2*8, %ecx
13770+ jc 2f
13771+
13772+ mov $2*8, %ecx
13773+ repe scasq
13774+ jecxz 2f
13775+ jne 1b
13776+
13777+2: cld
13778+ mov %esp, %ecx
13779+ sub %edi, %ecx
13780+ shr $3, %ecx
13781+ rep stosq
13782+
13783+ mov TI_task_thread_sp0(%r10), %rdi
13784+ sub $256, %rdi
13785+ mov %rdi, TI_lowest_stack(%r10)
13786+
13787+ popq %rax
13788+ popq %rdi
13789+ ret
13790+ENDPROC(pax_erase_kstack)
13791+#endif
13792
13793 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
13794 #ifdef CONFIG_TRACE_IRQFLAGS
13795@@ -317,7 +569,7 @@ ENTRY(save_args)
13796 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
13797 movq_cfi rbp, 8 /* push %rbp */
13798 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
13799- testl $3, CS(%rdi)
13800+ testb $3, CS(%rdi)
13801 je 1f
13802 SWAPGS
13803 /*
13804@@ -409,7 +661,7 @@ ENTRY(ret_from_fork)
13805
13806 RESTORE_REST
13807
13808- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13809+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13810 je int_ret_from_sys_call
13811
13812 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
13813@@ -455,7 +707,7 @@ END(ret_from_fork)
13814 ENTRY(system_call)
13815 CFI_STARTPROC simple
13816 CFI_SIGNAL_FRAME
13817- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13818+ CFI_DEF_CFA rsp,0
13819 CFI_REGISTER rip,rcx
13820 /*CFI_REGISTER rflags,r11*/
13821 SWAPGS_UNSAFE_STACK
13822@@ -468,12 +720,13 @@ ENTRY(system_call_after_swapgs)
13823
13824 movq %rsp,PER_CPU_VAR(old_rsp)
13825 movq PER_CPU_VAR(kernel_stack),%rsp
13826+ pax_enter_kernel_user
13827 /*
13828 * No need to follow this irqs off/on section - it's straight
13829 * and short:
13830 */
13831 ENABLE_INTERRUPTS(CLBR_NONE)
13832- SAVE_ARGS 8,1
13833+ SAVE_ARGS 8*6,1
13834 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13835 movq %rcx,RIP-ARGOFFSET(%rsp)
13836 CFI_REL_OFFSET rip,RIP-ARGOFFSET
13837@@ -502,6 +755,7 @@ sysret_check:
13838 andl %edi,%edx
13839 jnz sysret_careful
13840 CFI_REMEMBER_STATE
13841+ pax_exit_kernel_user
13842 /*
13843 * sysretq will re-enable interrupts:
13844 */
13845@@ -562,6 +816,9 @@ auditsys:
13846 movq %rax,%rsi /* 2nd arg: syscall number */
13847 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
13848 call audit_syscall_entry
13849+
13850+ pax_erase_kstack
13851+
13852 LOAD_ARGS 0 /* reload call-clobbered registers */
13853 jmp system_call_fastpath
13854
13855@@ -592,6 +849,9 @@ tracesys:
13856 FIXUP_TOP_OF_STACK %rdi
13857 movq %rsp,%rdi
13858 call syscall_trace_enter
13859+
13860+ pax_erase_kstack
13861+
13862 /*
13863 * Reload arg registers from stack in case ptrace changed them.
13864 * We don't reload %rax because syscall_trace_enter() returned
13865@@ -613,7 +873,7 @@ tracesys:
13866 GLOBAL(int_ret_from_sys_call)
13867 DISABLE_INTERRUPTS(CLBR_NONE)
13868 TRACE_IRQS_OFF
13869- testl $3,CS-ARGOFFSET(%rsp)
13870+ testb $3,CS-ARGOFFSET(%rsp)
13871 je retint_restore_args
13872 movl $_TIF_ALLWORK_MASK,%edi
13873 /* edi: mask to check */
13874@@ -800,6 +1060,16 @@ END(interrupt)
13875 CFI_ADJUST_CFA_OFFSET 10*8
13876 call save_args
13877 PARTIAL_FRAME 0
13878+#ifdef CONFIG_PAX_MEMORY_UDEREF
13879+ testb $3, CS(%rdi)
13880+ jnz 1f
13881+ pax_enter_kernel
13882+ jmp 2f
13883+1: pax_enter_kernel_user
13884+2:
13885+#else
13886+ pax_enter_kernel
13887+#endif
13888 call \func
13889 .endm
13890
13891@@ -822,7 +1092,7 @@ ret_from_intr:
13892 CFI_ADJUST_CFA_OFFSET -8
13893 exit_intr:
13894 GET_THREAD_INFO(%rcx)
13895- testl $3,CS-ARGOFFSET(%rsp)
13896+ testb $3,CS-ARGOFFSET(%rsp)
13897 je retint_kernel
13898
13899 /* Interrupt came from user space */
13900@@ -844,12 +1114,14 @@ retint_swapgs: /* return to user-space
13901 * The iretq could re-enable interrupts:
13902 */
13903 DISABLE_INTERRUPTS(CLBR_ANY)
13904+ pax_exit_kernel_user
13905 TRACE_IRQS_IRETQ
13906 SWAPGS
13907 jmp restore_args
13908
13909 retint_restore_args: /* return to kernel space */
13910 DISABLE_INTERRUPTS(CLBR_ANY)
13911+ pax_exit_kernel
13912 /*
13913 * The iretq could re-enable interrupts:
13914 */
13915@@ -1032,6 +1304,16 @@ ENTRY(\sym)
13916 CFI_ADJUST_CFA_OFFSET 15*8
13917 call error_entry
13918 DEFAULT_FRAME 0
13919+#ifdef CONFIG_PAX_MEMORY_UDEREF
13920+ testb $3, CS(%rsp)
13921+ jnz 1f
13922+ pax_enter_kernel
13923+ jmp 2f
13924+1: pax_enter_kernel_user
13925+2:
13926+#else
13927+ pax_enter_kernel
13928+#endif
13929 movq %rsp,%rdi /* pt_regs pointer */
13930 xorl %esi,%esi /* no error code */
13931 call \do_sym
13932@@ -1049,6 +1331,16 @@ ENTRY(\sym)
13933 subq $15*8, %rsp
13934 call save_paranoid
13935 TRACE_IRQS_OFF
13936+#ifdef CONFIG_PAX_MEMORY_UDEREF
13937+ testb $3, CS(%rsp)
13938+ jnz 1f
13939+ pax_enter_kernel
13940+ jmp 2f
13941+1: pax_enter_kernel_user
13942+2:
13943+#else
13944+ pax_enter_kernel
13945+#endif
13946 movq %rsp,%rdi /* pt_regs pointer */
13947 xorl %esi,%esi /* no error code */
13948 call \do_sym
13949@@ -1066,9 +1358,24 @@ ENTRY(\sym)
13950 subq $15*8, %rsp
13951 call save_paranoid
13952 TRACE_IRQS_OFF
13953+#ifdef CONFIG_PAX_MEMORY_UDEREF
13954+ testb $3, CS(%rsp)
13955+ jnz 1f
13956+ pax_enter_kernel
13957+ jmp 2f
13958+1: pax_enter_kernel_user
13959+2:
13960+#else
13961+ pax_enter_kernel
13962+#endif
13963 movq %rsp,%rdi /* pt_regs pointer */
13964 xorl %esi,%esi /* no error code */
13965- PER_CPU(init_tss, %rbp)
13966+#ifdef CONFIG_SMP
13967+ imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
13968+ lea init_tss(%rbp), %rbp
13969+#else
13970+ lea init_tss(%rip), %rbp
13971+#endif
13972 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
13973 call \do_sym
13974 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
13975@@ -1085,6 +1392,16 @@ ENTRY(\sym)
13976 CFI_ADJUST_CFA_OFFSET 15*8
13977 call error_entry
13978 DEFAULT_FRAME 0
13979+#ifdef CONFIG_PAX_MEMORY_UDEREF
13980+ testb $3, CS(%rsp)
13981+ jnz 1f
13982+ pax_enter_kernel
13983+ jmp 2f
13984+1: pax_enter_kernel_user
13985+2:
13986+#else
13987+ pax_enter_kernel
13988+#endif
13989 movq %rsp,%rdi /* pt_regs pointer */
13990 movq ORIG_RAX(%rsp),%rsi /* get error code */
13991 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
13992@@ -1104,6 +1421,16 @@ ENTRY(\sym)
13993 call save_paranoid
13994 DEFAULT_FRAME 0
13995 TRACE_IRQS_OFF
13996+#ifdef CONFIG_PAX_MEMORY_UDEREF
13997+ testb $3, CS(%rsp)
13998+ jnz 1f
13999+ pax_enter_kernel
14000+ jmp 2f
14001+1: pax_enter_kernel_user
14002+2:
14003+#else
14004+ pax_enter_kernel
14005+#endif
14006 movq %rsp,%rdi /* pt_regs pointer */
14007 movq ORIG_RAX(%rsp),%rsi /* get error code */
14008 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14009@@ -1405,14 +1732,27 @@ ENTRY(paranoid_exit)
14010 TRACE_IRQS_OFF
14011 testl %ebx,%ebx /* swapgs needed? */
14012 jnz paranoid_restore
14013- testl $3,CS(%rsp)
14014+ testb $3,CS(%rsp)
14015 jnz paranoid_userspace
14016+#ifdef CONFIG_PAX_MEMORY_UDEREF
14017+ pax_exit_kernel
14018+ TRACE_IRQS_IRETQ 0
14019+ SWAPGS_UNSAFE_STACK
14020+ RESTORE_ALL 8
14021+ jmp irq_return
14022+#endif
14023 paranoid_swapgs:
14024+#ifdef CONFIG_PAX_MEMORY_UDEREF
14025+ pax_exit_kernel_user
14026+#else
14027+ pax_exit_kernel
14028+#endif
14029 TRACE_IRQS_IRETQ 0
14030 SWAPGS_UNSAFE_STACK
14031 RESTORE_ALL 8
14032 jmp irq_return
14033 paranoid_restore:
14034+ pax_exit_kernel
14035 TRACE_IRQS_IRETQ 0
14036 RESTORE_ALL 8
14037 jmp irq_return
14038@@ -1470,7 +1810,7 @@ ENTRY(error_entry)
14039 movq_cfi r14, R14+8
14040 movq_cfi r15, R15+8
14041 xorl %ebx,%ebx
14042- testl $3,CS+8(%rsp)
14043+ testb $3,CS+8(%rsp)
14044 je error_kernelspace
14045 error_swapgs:
14046 SWAPGS
14047@@ -1529,6 +1869,16 @@ ENTRY(nmi)
14048 CFI_ADJUST_CFA_OFFSET 15*8
14049 call save_paranoid
14050 DEFAULT_FRAME 0
14051+#ifdef CONFIG_PAX_MEMORY_UDEREF
14052+ testb $3, CS(%rsp)
14053+ jnz 1f
14054+ pax_enter_kernel
14055+ jmp 2f
14056+1: pax_enter_kernel_user
14057+2:
14058+#else
14059+ pax_enter_kernel
14060+#endif
14061 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14062 movq %rsp,%rdi
14063 movq $-1,%rsi
14064@@ -1539,11 +1889,25 @@ ENTRY(nmi)
14065 DISABLE_INTERRUPTS(CLBR_NONE)
14066 testl %ebx,%ebx /* swapgs needed? */
14067 jnz nmi_restore
14068- testl $3,CS(%rsp)
14069+ testb $3,CS(%rsp)
14070 jnz nmi_userspace
14071+#ifdef CONFIG_PAX_MEMORY_UDEREF
14072+ pax_exit_kernel
14073+ SWAPGS_UNSAFE_STACK
14074+ RESTORE_ALL 8
14075+ jmp irq_return
14076+#endif
14077 nmi_swapgs:
14078+#ifdef CONFIG_PAX_MEMORY_UDEREF
14079+ pax_exit_kernel_user
14080+#else
14081+ pax_exit_kernel
14082+#endif
14083 SWAPGS_UNSAFE_STACK
14084+ RESTORE_ALL 8
14085+ jmp irq_return
14086 nmi_restore:
14087+ pax_exit_kernel
14088 RESTORE_ALL 8
14089 jmp irq_return
14090 nmi_userspace:
14091diff -urNp linux-2.6.32.44/arch/x86/kernel/ftrace.c linux-2.6.32.44/arch/x86/kernel/ftrace.c
14092--- linux-2.6.32.44/arch/x86/kernel/ftrace.c 2011-03-27 14:31:47.000000000 -0400
14093+++ linux-2.6.32.44/arch/x86/kernel/ftrace.c 2011-05-04 17:56:20.000000000 -0400
14094@@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the
14095 static void *mod_code_newcode; /* holds the text to write to the IP */
14096
14097 static unsigned nmi_wait_count;
14098-static atomic_t nmi_update_count = ATOMIC_INIT(0);
14099+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14100
14101 int ftrace_arch_read_dyn_info(char *buf, int size)
14102 {
14103@@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14104
14105 r = snprintf(buf, size, "%u %u",
14106 nmi_wait_count,
14107- atomic_read(&nmi_update_count));
14108+ atomic_read_unchecked(&nmi_update_count));
14109 return r;
14110 }
14111
14112@@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
14113 {
14114 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14115 smp_rmb();
14116+ pax_open_kernel();
14117 ftrace_mod_code();
14118- atomic_inc(&nmi_update_count);
14119+ pax_close_kernel();
14120+ atomic_inc_unchecked(&nmi_update_count);
14121 }
14122 /* Must have previous changes seen before executions */
14123 smp_mb();
14124@@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, voi
14125
14126
14127
14128-static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
14129+static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
14130
14131 static unsigned char *ftrace_nop_replace(void)
14132 {
14133@@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, uns
14134 {
14135 unsigned char replaced[MCOUNT_INSN_SIZE];
14136
14137+ ip = ktla_ktva(ip);
14138+
14139 /*
14140 * Note: Due to modules and __init, code can
14141 * disappear and change, we need to protect against faulting
14142@@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14143 unsigned char old[MCOUNT_INSN_SIZE], *new;
14144 int ret;
14145
14146- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14147+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14148 new = ftrace_call_replace(ip, (unsigned long)func);
14149 ret = ftrace_modify_code(ip, old, new);
14150
14151@@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *da
14152 switch (faulted) {
14153 case 0:
14154 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
14155- memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
14156+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
14157 break;
14158 case 1:
14159 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
14160- memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
14161+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
14162 break;
14163 case 2:
14164 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
14165- memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
14166+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
14167 break;
14168 }
14169
14170@@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long
14171 {
14172 unsigned char code[MCOUNT_INSN_SIZE];
14173
14174+ ip = ktla_ktva(ip);
14175+
14176 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14177 return -EFAULT;
14178
14179diff -urNp linux-2.6.32.44/arch/x86/kernel/head32.c linux-2.6.32.44/arch/x86/kernel/head32.c
14180--- linux-2.6.32.44/arch/x86/kernel/head32.c 2011-03-27 14:31:47.000000000 -0400
14181+++ linux-2.6.32.44/arch/x86/kernel/head32.c 2011-04-17 15:56:46.000000000 -0400
14182@@ -16,6 +16,7 @@
14183 #include <asm/apic.h>
14184 #include <asm/io_apic.h>
14185 #include <asm/bios_ebda.h>
14186+#include <asm/boot.h>
14187
14188 static void __init i386_default_early_setup(void)
14189 {
14190@@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
14191 {
14192 reserve_trampoline_memory();
14193
14194- reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14195+ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14196
14197 #ifdef CONFIG_BLK_DEV_INITRD
14198 /* Reserve INITRD */
14199diff -urNp linux-2.6.32.44/arch/x86/kernel/head_32.S linux-2.6.32.44/arch/x86/kernel/head_32.S
14200--- linux-2.6.32.44/arch/x86/kernel/head_32.S 2011-03-27 14:31:47.000000000 -0400
14201+++ linux-2.6.32.44/arch/x86/kernel/head_32.S 2011-07-06 19:53:33.000000000 -0400
14202@@ -19,10 +19,17 @@
14203 #include <asm/setup.h>
14204 #include <asm/processor-flags.h>
14205 #include <asm/percpu.h>
14206+#include <asm/msr-index.h>
14207
14208 /* Physical address */
14209 #define pa(X) ((X) - __PAGE_OFFSET)
14210
14211+#ifdef CONFIG_PAX_KERNEXEC
14212+#define ta(X) (X)
14213+#else
14214+#define ta(X) ((X) - __PAGE_OFFSET)
14215+#endif
14216+
14217 /*
14218 * References to members of the new_cpu_data structure.
14219 */
14220@@ -52,11 +59,7 @@
14221 * and small than max_low_pfn, otherwise will waste some page table entries
14222 */
14223
14224-#if PTRS_PER_PMD > 1
14225-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14226-#else
14227-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14228-#endif
14229+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14230
14231 /* Enough space to fit pagetables for the low memory linear map */
14232 MAPPING_BEYOND_END = \
14233@@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14234 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14235
14236 /*
14237+ * Real beginning of normal "text" segment
14238+ */
14239+ENTRY(stext)
14240+ENTRY(_stext)
14241+
14242+/*
14243 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14244 * %esi points to the real-mode code as a 32-bit pointer.
14245 * CS and DS must be 4 GB flat segments, but we don't depend on
14246@@ -80,7 +89,16 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14247 * can.
14248 */
14249 __HEAD
14250+
14251+#ifdef CONFIG_PAX_KERNEXEC
14252+ jmp startup_32
14253+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14254+.fill PAGE_SIZE-5,1,0xcc
14255+#endif
14256+
14257 ENTRY(startup_32)
14258+ movl pa(stack_start),%ecx
14259+
14260 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
14261 us to not reload segments */
14262 testb $(1<<6), BP_loadflags(%esi)
14263@@ -95,7 +113,60 @@ ENTRY(startup_32)
14264 movl %eax,%es
14265 movl %eax,%fs
14266 movl %eax,%gs
14267+ movl %eax,%ss
14268 2:
14269+ leal -__PAGE_OFFSET(%ecx),%esp
14270+
14271+#ifdef CONFIG_SMP
14272+ movl $pa(cpu_gdt_table),%edi
14273+ movl $__per_cpu_load,%eax
14274+ movw %ax,__KERNEL_PERCPU + 2(%edi)
14275+ rorl $16,%eax
14276+ movb %al,__KERNEL_PERCPU + 4(%edi)
14277+ movb %ah,__KERNEL_PERCPU + 7(%edi)
14278+ movl $__per_cpu_end - 1,%eax
14279+ subl $__per_cpu_start,%eax
14280+ movw %ax,__KERNEL_PERCPU + 0(%edi)
14281+#endif
14282+
14283+#ifdef CONFIG_PAX_MEMORY_UDEREF
14284+ movl $NR_CPUS,%ecx
14285+ movl $pa(cpu_gdt_table),%edi
14286+1:
14287+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14288+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14289+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14290+ addl $PAGE_SIZE_asm,%edi
14291+ loop 1b
14292+#endif
14293+
14294+#ifdef CONFIG_PAX_KERNEXEC
14295+ movl $pa(boot_gdt),%edi
14296+ movl $__LOAD_PHYSICAL_ADDR,%eax
14297+ movw %ax,__BOOT_CS + 2(%edi)
14298+ rorl $16,%eax
14299+ movb %al,__BOOT_CS + 4(%edi)
14300+ movb %ah,__BOOT_CS + 7(%edi)
14301+ rorl $16,%eax
14302+
14303+ ljmp $(__BOOT_CS),$1f
14304+1:
14305+
14306+ movl $NR_CPUS,%ecx
14307+ movl $pa(cpu_gdt_table),%edi
14308+ addl $__PAGE_OFFSET,%eax
14309+1:
14310+ movw %ax,__KERNEL_CS + 2(%edi)
14311+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14312+ rorl $16,%eax
14313+ movb %al,__KERNEL_CS + 4(%edi)
14314+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14315+ movb %ah,__KERNEL_CS + 7(%edi)
14316+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14317+ rorl $16,%eax
14318+ addl $PAGE_SIZE_asm,%edi
14319+ loop 1b
14320+#endif
14321
14322 /*
14323 * Clear BSS first so that there are no surprises...
14324@@ -140,9 +211,7 @@ ENTRY(startup_32)
14325 cmpl $num_subarch_entries, %eax
14326 jae bad_subarch
14327
14328- movl pa(subarch_entries)(,%eax,4), %eax
14329- subl $__PAGE_OFFSET, %eax
14330- jmp *%eax
14331+ jmp *pa(subarch_entries)(,%eax,4)
14332
14333 bad_subarch:
14334 WEAK(lguest_entry)
14335@@ -154,10 +223,10 @@ WEAK(xen_entry)
14336 __INITDATA
14337
14338 subarch_entries:
14339- .long default_entry /* normal x86/PC */
14340- .long lguest_entry /* lguest hypervisor */
14341- .long xen_entry /* Xen hypervisor */
14342- .long default_entry /* Moorestown MID */
14343+ .long ta(default_entry) /* normal x86/PC */
14344+ .long ta(lguest_entry) /* lguest hypervisor */
14345+ .long ta(xen_entry) /* Xen hypervisor */
14346+ .long ta(default_entry) /* Moorestown MID */
14347 num_subarch_entries = (. - subarch_entries) / 4
14348 .previous
14349 #endif /* CONFIG_PARAVIRT */
14350@@ -218,8 +287,11 @@ default_entry:
14351 movl %eax, pa(max_pfn_mapped)
14352
14353 /* Do early initialization of the fixmap area */
14354- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
14355- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
14356+#ifdef CONFIG_COMPAT_VDSO
14357+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
14358+#else
14359+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
14360+#endif
14361 #else /* Not PAE */
14362
14363 page_pde_offset = (__PAGE_OFFSET >> 20);
14364@@ -249,8 +321,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14365 movl %eax, pa(max_pfn_mapped)
14366
14367 /* Do early initialization of the fixmap area */
14368- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
14369- movl %eax,pa(swapper_pg_dir+0xffc)
14370+#ifdef CONFIG_COMPAT_VDSO
14371+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
14372+#else
14373+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
14374+#endif
14375 #endif
14376 jmp 3f
14377 /*
14378@@ -272,6 +347,9 @@ ENTRY(startup_32_smp)
14379 movl %eax,%es
14380 movl %eax,%fs
14381 movl %eax,%gs
14382+ movl pa(stack_start),%ecx
14383+ movl %eax,%ss
14384+ leal -__PAGE_OFFSET(%ecx),%esp
14385 #endif /* CONFIG_SMP */
14386 3:
14387
14388@@ -297,6 +375,7 @@ ENTRY(startup_32_smp)
14389 orl %edx,%eax
14390 movl %eax,%cr4
14391
14392+#ifdef CONFIG_X86_PAE
14393 btl $5, %eax # check if PAE is enabled
14394 jnc 6f
14395
14396@@ -305,6 +384,10 @@ ENTRY(startup_32_smp)
14397 cpuid
14398 cmpl $0x80000000, %eax
14399 jbe 6f
14400+
14401+ /* Clear bogus XD_DISABLE bits */
14402+ call verify_cpu
14403+
14404 mov $0x80000001, %eax
14405 cpuid
14406 /* Execute Disable bit supported? */
14407@@ -312,13 +395,17 @@ ENTRY(startup_32_smp)
14408 jnc 6f
14409
14410 /* Setup EFER (Extended Feature Enable Register) */
14411- movl $0xc0000080, %ecx
14412+ movl $MSR_EFER, %ecx
14413 rdmsr
14414
14415 btsl $11, %eax
14416 /* Make changes effective */
14417 wrmsr
14418
14419+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14420+ movl $1,pa(nx_enabled)
14421+#endif
14422+
14423 6:
14424
14425 /*
14426@@ -331,8 +418,8 @@ ENTRY(startup_32_smp)
14427 movl %eax,%cr0 /* ..and set paging (PG) bit */
14428 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
14429 1:
14430- /* Set up the stack pointer */
14431- lss stack_start,%esp
14432+ /* Shift the stack pointer to a virtual address */
14433+ addl $__PAGE_OFFSET, %esp
14434
14435 /*
14436 * Initialize eflags. Some BIOS's leave bits like NT set. This would
14437@@ -344,9 +431,7 @@ ENTRY(startup_32_smp)
14438
14439 #ifdef CONFIG_SMP
14440 cmpb $0, ready
14441- jz 1f /* Initial CPU cleans BSS */
14442- jmp checkCPUtype
14443-1:
14444+ jnz checkCPUtype
14445 #endif /* CONFIG_SMP */
14446
14447 /*
14448@@ -424,7 +509,7 @@ is386: movl $2,%ecx # set MP
14449 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14450 movl %eax,%ss # after changing gdt.
14451
14452- movl $(__USER_DS),%eax # DS/ES contains default USER segment
14453+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14454 movl %eax,%ds
14455 movl %eax,%es
14456
14457@@ -438,15 +523,22 @@ is386: movl $2,%ecx # set MP
14458 */
14459 cmpb $0,ready
14460 jne 1f
14461- movl $per_cpu__gdt_page,%eax
14462+ movl $cpu_gdt_table,%eax
14463 movl $per_cpu__stack_canary,%ecx
14464+#ifdef CONFIG_SMP
14465+ addl $__per_cpu_load,%ecx
14466+#endif
14467 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14468 shrl $16, %ecx
14469 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14470 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14471 1:
14472-#endif
14473 movl $(__KERNEL_STACK_CANARY),%eax
14474+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14475+ movl $(__USER_DS),%eax
14476+#else
14477+ xorl %eax,%eax
14478+#endif
14479 movl %eax,%gs
14480
14481 xorl %eax,%eax # Clear LDT
14482@@ -454,14 +546,7 @@ is386: movl $2,%ecx # set MP
14483
14484 cld # gcc2 wants the direction flag cleared at all times
14485 pushl $0 # fake return address for unwinder
14486-#ifdef CONFIG_SMP
14487- movb ready, %cl
14488 movb $1, ready
14489- cmpb $0,%cl # the first CPU calls start_kernel
14490- je 1f
14491- movl (stack_start), %esp
14492-1:
14493-#endif /* CONFIG_SMP */
14494 jmp *(initial_code)
14495
14496 /*
14497@@ -546,22 +631,22 @@ early_page_fault:
14498 jmp early_fault
14499
14500 early_fault:
14501- cld
14502 #ifdef CONFIG_PRINTK
14503+ cmpl $1,%ss:early_recursion_flag
14504+ je hlt_loop
14505+ incl %ss:early_recursion_flag
14506+ cld
14507 pusha
14508 movl $(__KERNEL_DS),%eax
14509 movl %eax,%ds
14510 movl %eax,%es
14511- cmpl $2,early_recursion_flag
14512- je hlt_loop
14513- incl early_recursion_flag
14514 movl %cr2,%eax
14515 pushl %eax
14516 pushl %edx /* trapno */
14517 pushl $fault_msg
14518 call printk
14519+; call dump_stack
14520 #endif
14521- call dump_stack
14522 hlt_loop:
14523 hlt
14524 jmp hlt_loop
14525@@ -569,8 +654,11 @@ hlt_loop:
14526 /* This is the default interrupt "handler" :-) */
14527 ALIGN
14528 ignore_int:
14529- cld
14530 #ifdef CONFIG_PRINTK
14531+ cmpl $2,%ss:early_recursion_flag
14532+ je hlt_loop
14533+ incl %ss:early_recursion_flag
14534+ cld
14535 pushl %eax
14536 pushl %ecx
14537 pushl %edx
14538@@ -579,9 +667,6 @@ ignore_int:
14539 movl $(__KERNEL_DS),%eax
14540 movl %eax,%ds
14541 movl %eax,%es
14542- cmpl $2,early_recursion_flag
14543- je hlt_loop
14544- incl early_recursion_flag
14545 pushl 16(%esp)
14546 pushl 24(%esp)
14547 pushl 32(%esp)
14548@@ -600,6 +685,8 @@ ignore_int:
14549 #endif
14550 iret
14551
14552+#include "verify_cpu.S"
14553+
14554 __REFDATA
14555 .align 4
14556 ENTRY(initial_code)
14557@@ -610,31 +697,47 @@ ENTRY(initial_page_table)
14558 /*
14559 * BSS section
14560 */
14561-__PAGE_ALIGNED_BSS
14562- .align PAGE_SIZE_asm
14563 #ifdef CONFIG_X86_PAE
14564+.section .swapper_pg_pmd,"a",@progbits
14565 swapper_pg_pmd:
14566 .fill 1024*KPMDS,4,0
14567 #else
14568+.section .swapper_pg_dir,"a",@progbits
14569 ENTRY(swapper_pg_dir)
14570 .fill 1024,4,0
14571 #endif
14572+.section .swapper_pg_fixmap,"a",@progbits
14573 swapper_pg_fixmap:
14574 .fill 1024,4,0
14575 #ifdef CONFIG_X86_TRAMPOLINE
14576+.section .trampoline_pg_dir,"a",@progbits
14577 ENTRY(trampoline_pg_dir)
14578+#ifdef CONFIG_X86_PAE
14579+ .fill 4,8,0
14580+#else
14581 .fill 1024,4,0
14582 #endif
14583+#endif
14584+
14585+.section .empty_zero_page,"a",@progbits
14586 ENTRY(empty_zero_page)
14587 .fill 4096,1,0
14588
14589 /*
14590+ * The IDT has to be page-aligned to simplify the Pentium
14591+ * F0 0F bug workaround.. We have a special link segment
14592+ * for this.
14593+ */
14594+.section .idt,"a",@progbits
14595+ENTRY(idt_table)
14596+ .fill 256,8,0
14597+
14598+/*
14599 * This starts the data section.
14600 */
14601 #ifdef CONFIG_X86_PAE
14602-__PAGE_ALIGNED_DATA
14603- /* Page-aligned for the benefit of paravirt? */
14604- .align PAGE_SIZE_asm
14605+.section .swapper_pg_dir,"a",@progbits
14606+
14607 ENTRY(swapper_pg_dir)
14608 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
14609 # if KPMDS == 3
14610@@ -653,15 +756,24 @@ ENTRY(swapper_pg_dir)
14611 # error "Kernel PMDs should be 1, 2 or 3"
14612 # endif
14613 .align PAGE_SIZE_asm /* needs to be page-sized too */
14614+
14615+#ifdef CONFIG_PAX_PER_CPU_PGD
14616+ENTRY(cpu_pgd)
14617+ .rept NR_CPUS
14618+ .fill 4,8,0
14619+ .endr
14620+#endif
14621+
14622 #endif
14623
14624 .data
14625+.balign 4
14626 ENTRY(stack_start)
14627- .long init_thread_union+THREAD_SIZE
14628- .long __BOOT_DS
14629+ .long init_thread_union+THREAD_SIZE-8
14630
14631 ready: .byte 0
14632
14633+.section .rodata,"a",@progbits
14634 early_recursion_flag:
14635 .long 0
14636
14637@@ -697,7 +809,7 @@ fault_msg:
14638 .word 0 # 32 bit align gdt_desc.address
14639 boot_gdt_descr:
14640 .word __BOOT_DS+7
14641- .long boot_gdt - __PAGE_OFFSET
14642+ .long pa(boot_gdt)
14643
14644 .word 0 # 32-bit align idt_desc.address
14645 idt_descr:
14646@@ -708,7 +820,7 @@ idt_descr:
14647 .word 0 # 32 bit align gdt_desc.address
14648 ENTRY(early_gdt_descr)
14649 .word GDT_ENTRIES*8-1
14650- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
14651+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
14652
14653 /*
14654 * The boot_gdt must mirror the equivalent in setup.S and is
14655@@ -717,5 +829,65 @@ ENTRY(early_gdt_descr)
14656 .align L1_CACHE_BYTES
14657 ENTRY(boot_gdt)
14658 .fill GDT_ENTRY_BOOT_CS,8,0
14659- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
14660- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
14661+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
14662+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
14663+
14664+ .align PAGE_SIZE_asm
14665+ENTRY(cpu_gdt_table)
14666+ .rept NR_CPUS
14667+ .quad 0x0000000000000000 /* NULL descriptor */
14668+ .quad 0x0000000000000000 /* 0x0b reserved */
14669+ .quad 0x0000000000000000 /* 0x13 reserved */
14670+ .quad 0x0000000000000000 /* 0x1b reserved */
14671+
14672+#ifdef CONFIG_PAX_KERNEXEC
14673+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
14674+#else
14675+ .quad 0x0000000000000000 /* 0x20 unused */
14676+#endif
14677+
14678+ .quad 0x0000000000000000 /* 0x28 unused */
14679+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
14680+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
14681+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
14682+ .quad 0x0000000000000000 /* 0x4b reserved */
14683+ .quad 0x0000000000000000 /* 0x53 reserved */
14684+ .quad 0x0000000000000000 /* 0x5b reserved */
14685+
14686+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
14687+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
14688+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
14689+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
14690+
14691+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
14692+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
14693+
14694+ /*
14695+ * Segments used for calling PnP BIOS have byte granularity.
14696+ * The code segments and data segments have fixed 64k limits,
14697+ * the transfer segment sizes are set at run time.
14698+ */
14699+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
14700+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
14701+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
14702+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
14703+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
14704+
14705+ /*
14706+ * The APM segments have byte granularity and their bases
14707+ * are set at run time. All have 64k limits.
14708+ */
14709+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
14710+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
14711+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
14712+
14713+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
14714+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
14715+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
14716+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
14717+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
14718+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
14719+
14720+ /* Be sure this is zeroed to avoid false validations in Xen */
14721+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
14722+ .endr
14723diff -urNp linux-2.6.32.44/arch/x86/kernel/head_64.S linux-2.6.32.44/arch/x86/kernel/head_64.S
14724--- linux-2.6.32.44/arch/x86/kernel/head_64.S 2011-03-27 14:31:47.000000000 -0400
14725+++ linux-2.6.32.44/arch/x86/kernel/head_64.S 2011-04-17 15:56:46.000000000 -0400
14726@@ -19,6 +19,7 @@
14727 #include <asm/cache.h>
14728 #include <asm/processor-flags.h>
14729 #include <asm/percpu.h>
14730+#include <asm/cpufeature.h>
14731
14732 #ifdef CONFIG_PARAVIRT
14733 #include <asm/asm-offsets.h>
14734@@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
14735 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
14736 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
14737 L3_START_KERNEL = pud_index(__START_KERNEL_map)
14738+L4_VMALLOC_START = pgd_index(VMALLOC_START)
14739+L3_VMALLOC_START = pud_index(VMALLOC_START)
14740+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
14741+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
14742
14743 .text
14744 __HEAD
14745@@ -85,35 +90,22 @@ startup_64:
14746 */
14747 addq %rbp, init_level4_pgt + 0(%rip)
14748 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
14749+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
14750+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
14751 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
14752
14753 addq %rbp, level3_ident_pgt + 0(%rip)
14754+#ifndef CONFIG_XEN
14755+ addq %rbp, level3_ident_pgt + 8(%rip)
14756+#endif
14757
14758- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
14759- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
14760+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
14761
14762- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14763+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
14764+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
14765
14766- /* Add an Identity mapping if I am above 1G */
14767- leaq _text(%rip), %rdi
14768- andq $PMD_PAGE_MASK, %rdi
14769-
14770- movq %rdi, %rax
14771- shrq $PUD_SHIFT, %rax
14772- andq $(PTRS_PER_PUD - 1), %rax
14773- jz ident_complete
14774-
14775- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
14776- leaq level3_ident_pgt(%rip), %rbx
14777- movq %rdx, 0(%rbx, %rax, 8)
14778-
14779- movq %rdi, %rax
14780- shrq $PMD_SHIFT, %rax
14781- andq $(PTRS_PER_PMD - 1), %rax
14782- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
14783- leaq level2_spare_pgt(%rip), %rbx
14784- movq %rdx, 0(%rbx, %rax, 8)
14785-ident_complete:
14786+ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14787+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
14788
14789 /*
14790 * Fixup the kernel text+data virtual addresses. Note that
14791@@ -161,8 +153,8 @@ ENTRY(secondary_startup_64)
14792 * after the boot processor executes this code.
14793 */
14794
14795- /* Enable PAE mode and PGE */
14796- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
14797+ /* Enable PAE mode and PSE/PGE */
14798+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
14799 movq %rax, %cr4
14800
14801 /* Setup early boot stage 4 level pagetables. */
14802@@ -184,9 +176,13 @@ ENTRY(secondary_startup_64)
14803 movl $MSR_EFER, %ecx
14804 rdmsr
14805 btsl $_EFER_SCE, %eax /* Enable System Call */
14806- btl $20,%edi /* No Execute supported? */
14807+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
14808 jnc 1f
14809 btsl $_EFER_NX, %eax
14810+ leaq init_level4_pgt(%rip), %rdi
14811+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
14812+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
14813+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
14814 1: wrmsr /* Make changes effective */
14815
14816 /* Setup cr0 */
14817@@ -262,16 +258,16 @@ ENTRY(secondary_startup_64)
14818 .quad x86_64_start_kernel
14819 ENTRY(initial_gs)
14820 .quad INIT_PER_CPU_VAR(irq_stack_union)
14821- __FINITDATA
14822
14823 ENTRY(stack_start)
14824 .quad init_thread_union+THREAD_SIZE-8
14825 .word 0
14826+ __FINITDATA
14827
14828 bad_address:
14829 jmp bad_address
14830
14831- .section ".init.text","ax"
14832+ __INIT
14833 #ifdef CONFIG_EARLY_PRINTK
14834 .globl early_idt_handlers
14835 early_idt_handlers:
14836@@ -316,18 +312,23 @@ ENTRY(early_idt_handler)
14837 #endif /* EARLY_PRINTK */
14838 1: hlt
14839 jmp 1b
14840+ .previous
14841
14842 #ifdef CONFIG_EARLY_PRINTK
14843+ __INITDATA
14844 early_recursion_flag:
14845 .long 0
14846+ .previous
14847
14848+ .section .rodata,"a",@progbits
14849 early_idt_msg:
14850 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
14851 early_idt_ripmsg:
14852 .asciz "RIP %s\n"
14853-#endif /* CONFIG_EARLY_PRINTK */
14854 .previous
14855+#endif /* CONFIG_EARLY_PRINTK */
14856
14857+ .section .rodata,"a",@progbits
14858 #define NEXT_PAGE(name) \
14859 .balign PAGE_SIZE; \
14860 ENTRY(name)
14861@@ -350,13 +351,36 @@ NEXT_PAGE(init_level4_pgt)
14862 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14863 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
14864 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14865+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
14866+ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
14867+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
14868+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
14869 .org init_level4_pgt + L4_START_KERNEL*8, 0
14870 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
14871 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
14872
14873+#ifdef CONFIG_PAX_PER_CPU_PGD
14874+NEXT_PAGE(cpu_pgd)
14875+ .rept NR_CPUS
14876+ .fill 512,8,0
14877+ .endr
14878+#endif
14879+
14880 NEXT_PAGE(level3_ident_pgt)
14881 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14882+#ifdef CONFIG_XEN
14883 .fill 511,8,0
14884+#else
14885+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
14886+ .fill 510,8,0
14887+#endif
14888+
14889+NEXT_PAGE(level3_vmalloc_pgt)
14890+ .fill 512,8,0
14891+
14892+NEXT_PAGE(level3_vmemmap_pgt)
14893+ .fill L3_VMEMMAP_START,8,0
14894+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
14895
14896 NEXT_PAGE(level3_kernel_pgt)
14897 .fill L3_START_KERNEL,8,0
14898@@ -364,20 +388,23 @@ NEXT_PAGE(level3_kernel_pgt)
14899 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
14900 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
14901
14902+NEXT_PAGE(level2_vmemmap_pgt)
14903+ .fill 512,8,0
14904+
14905 NEXT_PAGE(level2_fixmap_pgt)
14906- .fill 506,8,0
14907- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
14908- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
14909- .fill 5,8,0
14910+ .fill 507,8,0
14911+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
14912+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
14913+ .fill 4,8,0
14914
14915-NEXT_PAGE(level1_fixmap_pgt)
14916+NEXT_PAGE(level1_vsyscall_pgt)
14917 .fill 512,8,0
14918
14919-NEXT_PAGE(level2_ident_pgt)
14920- /* Since I easily can, map the first 1G.
14921+ /* Since I easily can, map the first 2G.
14922 * Don't set NX because code runs from these pages.
14923 */
14924- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
14925+NEXT_PAGE(level2_ident_pgt)
14926+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
14927
14928 NEXT_PAGE(level2_kernel_pgt)
14929 /*
14930@@ -390,33 +417,55 @@ NEXT_PAGE(level2_kernel_pgt)
14931 * If you want to increase this then increase MODULES_VADDR
14932 * too.)
14933 */
14934- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
14935- KERNEL_IMAGE_SIZE/PMD_SIZE)
14936-
14937-NEXT_PAGE(level2_spare_pgt)
14938- .fill 512, 8, 0
14939+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
14940
14941 #undef PMDS
14942 #undef NEXT_PAGE
14943
14944- .data
14945+ .align PAGE_SIZE
14946+ENTRY(cpu_gdt_table)
14947+ .rept NR_CPUS
14948+ .quad 0x0000000000000000 /* NULL descriptor */
14949+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
14950+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
14951+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
14952+ .quad 0x00cffb000000ffff /* __USER32_CS */
14953+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
14954+ .quad 0x00affb000000ffff /* __USER_CS */
14955+
14956+#ifdef CONFIG_PAX_KERNEXEC
14957+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
14958+#else
14959+ .quad 0x0 /* unused */
14960+#endif
14961+
14962+ .quad 0,0 /* TSS */
14963+ .quad 0,0 /* LDT */
14964+ .quad 0,0,0 /* three TLS descriptors */
14965+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
14966+ /* asm/segment.h:GDT_ENTRIES must match this */
14967+
14968+ /* zero the remaining page */
14969+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
14970+ .endr
14971+
14972 .align 16
14973 .globl early_gdt_descr
14974 early_gdt_descr:
14975 .word GDT_ENTRIES*8-1
14976 early_gdt_descr_base:
14977- .quad INIT_PER_CPU_VAR(gdt_page)
14978+ .quad cpu_gdt_table
14979
14980 ENTRY(phys_base)
14981 /* This must match the first entry in level2_kernel_pgt */
14982 .quad 0x0000000000000000
14983
14984 #include "../../x86/xen/xen-head.S"
14985-
14986- .section .bss, "aw", @nobits
14987+
14988+ .section .rodata,"a",@progbits
14989 .align L1_CACHE_BYTES
14990 ENTRY(idt_table)
14991- .skip IDT_ENTRIES * 16
14992+ .fill 512,8,0
14993
14994 __PAGE_ALIGNED_BSS
14995 .align PAGE_SIZE
14996diff -urNp linux-2.6.32.44/arch/x86/kernel/i386_ksyms_32.c linux-2.6.32.44/arch/x86/kernel/i386_ksyms_32.c
14997--- linux-2.6.32.44/arch/x86/kernel/i386_ksyms_32.c 2011-03-27 14:31:47.000000000 -0400
14998+++ linux-2.6.32.44/arch/x86/kernel/i386_ksyms_32.c 2011-04-17 15:56:46.000000000 -0400
14999@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15000 EXPORT_SYMBOL(cmpxchg8b_emu);
15001 #endif
15002
15003+EXPORT_SYMBOL_GPL(cpu_gdt_table);
15004+
15005 /* Networking helper routines. */
15006 EXPORT_SYMBOL(csum_partial_copy_generic);
15007+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15008+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15009
15010 EXPORT_SYMBOL(__get_user_1);
15011 EXPORT_SYMBOL(__get_user_2);
15012@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15013
15014 EXPORT_SYMBOL(csum_partial);
15015 EXPORT_SYMBOL(empty_zero_page);
15016+
15017+#ifdef CONFIG_PAX_KERNEXEC
15018+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15019+#endif
15020diff -urNp linux-2.6.32.44/arch/x86/kernel/i8259.c linux-2.6.32.44/arch/x86/kernel/i8259.c
15021--- linux-2.6.32.44/arch/x86/kernel/i8259.c 2011-03-27 14:31:47.000000000 -0400
15022+++ linux-2.6.32.44/arch/x86/kernel/i8259.c 2011-05-04 17:56:28.000000000 -0400
15023@@ -208,7 +208,7 @@ spurious_8259A_irq:
15024 "spurious 8259A interrupt: IRQ%d.\n", irq);
15025 spurious_irq_mask |= irqmask;
15026 }
15027- atomic_inc(&irq_err_count);
15028+ atomic_inc_unchecked(&irq_err_count);
15029 /*
15030 * Theoretically we do not have to handle this IRQ,
15031 * but in Linux this does not cause problems and is
15032diff -urNp linux-2.6.32.44/arch/x86/kernel/init_task.c linux-2.6.32.44/arch/x86/kernel/init_task.c
15033--- linux-2.6.32.44/arch/x86/kernel/init_task.c 2011-03-27 14:31:47.000000000 -0400
15034+++ linux-2.6.32.44/arch/x86/kernel/init_task.c 2011-04-17 15:56:46.000000000 -0400
15035@@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15036 * way process stacks are handled. This is done by having a special
15037 * "init_task" linker map entry..
15038 */
15039-union thread_union init_thread_union __init_task_data =
15040- { INIT_THREAD_INFO(init_task) };
15041+union thread_union init_thread_union __init_task_data;
15042
15043 /*
15044 * Initial task structure.
15045@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15046 * section. Since TSS's are completely CPU-local, we want them
15047 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15048 */
15049-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15050-
15051+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15052+EXPORT_SYMBOL(init_tss);
15053diff -urNp linux-2.6.32.44/arch/x86/kernel/ioport.c linux-2.6.32.44/arch/x86/kernel/ioport.c
15054--- linux-2.6.32.44/arch/x86/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
15055+++ linux-2.6.32.44/arch/x86/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
15056@@ -6,6 +6,7 @@
15057 #include <linux/sched.h>
15058 #include <linux/kernel.h>
15059 #include <linux/capability.h>
15060+#include <linux/security.h>
15061 #include <linux/errno.h>
15062 #include <linux/types.h>
15063 #include <linux/ioport.h>
15064@@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long
15065
15066 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15067 return -EINVAL;
15068+#ifdef CONFIG_GRKERNSEC_IO
15069+ if (turn_on && grsec_disable_privio) {
15070+ gr_handle_ioperm();
15071+ return -EPERM;
15072+ }
15073+#endif
15074 if (turn_on && !capable(CAP_SYS_RAWIO))
15075 return -EPERM;
15076
15077@@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
15078 * because the ->io_bitmap_max value must match the bitmap
15079 * contents:
15080 */
15081- tss = &per_cpu(init_tss, get_cpu());
15082+ tss = init_tss + get_cpu();
15083
15084 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
15085
15086@@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, s
15087 return -EINVAL;
15088 /* Trying to gain more privileges? */
15089 if (level > old) {
15090+#ifdef CONFIG_GRKERNSEC_IO
15091+ if (grsec_disable_privio) {
15092+ gr_handle_iopl();
15093+ return -EPERM;
15094+ }
15095+#endif
15096 if (!capable(CAP_SYS_RAWIO))
15097 return -EPERM;
15098 }
15099diff -urNp linux-2.6.32.44/arch/x86/kernel/irq_32.c linux-2.6.32.44/arch/x86/kernel/irq_32.c
15100--- linux-2.6.32.44/arch/x86/kernel/irq_32.c 2011-03-27 14:31:47.000000000 -0400
15101+++ linux-2.6.32.44/arch/x86/kernel/irq_32.c 2011-07-06 19:53:33.000000000 -0400
15102@@ -35,7 +35,7 @@ static int check_stack_overflow(void)
15103 __asm__ __volatile__("andl %%esp,%0" :
15104 "=r" (sp) : "0" (THREAD_SIZE - 1));
15105
15106- return sp < (sizeof(struct thread_info) + STACK_WARN);
15107+ return sp < STACK_WARN;
15108 }
15109
15110 static void print_stack_overflow(void)
15111@@ -54,9 +54,9 @@ static inline void print_stack_overflow(
15112 * per-CPU IRQ handling contexts (thread information and stack)
15113 */
15114 union irq_ctx {
15115- struct thread_info tinfo;
15116- u32 stack[THREAD_SIZE/sizeof(u32)];
15117-} __attribute__((aligned(PAGE_SIZE)));
15118+ unsigned long previous_esp;
15119+ u32 stack[THREAD_SIZE/sizeof(u32)];
15120+} __attribute__((aligned(THREAD_SIZE)));
15121
15122 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15123 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
15124@@ -78,10 +78,9 @@ static void call_on_stack(void *func, vo
15125 static inline int
15126 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15127 {
15128- union irq_ctx *curctx, *irqctx;
15129+ union irq_ctx *irqctx;
15130 u32 *isp, arg1, arg2;
15131
15132- curctx = (union irq_ctx *) current_thread_info();
15133 irqctx = __get_cpu_var(hardirq_ctx);
15134
15135 /*
15136@@ -90,21 +89,16 @@ execute_on_irq_stack(int overflow, struc
15137 * handler) we can't do that and just have to keep using the
15138 * current stack (which is the irq stack already after all)
15139 */
15140- if (unlikely(curctx == irqctx))
15141+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15142 return 0;
15143
15144 /* build the stack frame on the IRQ stack */
15145- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15146- irqctx->tinfo.task = curctx->tinfo.task;
15147- irqctx->tinfo.previous_esp = current_stack_pointer;
15148+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15149+ irqctx->previous_esp = current_stack_pointer;
15150
15151- /*
15152- * Copy the softirq bits in preempt_count so that the
15153- * softirq checks work in the hardirq context.
15154- */
15155- irqctx->tinfo.preempt_count =
15156- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15157- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15158+#ifdef CONFIG_PAX_MEMORY_UDEREF
15159+ __set_fs(MAKE_MM_SEG(0));
15160+#endif
15161
15162 if (unlikely(overflow))
15163 call_on_stack(print_stack_overflow, isp);
15164@@ -116,6 +110,11 @@ execute_on_irq_stack(int overflow, struc
15165 : "0" (irq), "1" (desc), "2" (isp),
15166 "D" (desc->handle_irq)
15167 : "memory", "cc", "ecx");
15168+
15169+#ifdef CONFIG_PAX_MEMORY_UDEREF
15170+ __set_fs(current_thread_info()->addr_limit);
15171+#endif
15172+
15173 return 1;
15174 }
15175
15176@@ -124,28 +123,11 @@ execute_on_irq_stack(int overflow, struc
15177 */
15178 void __cpuinit irq_ctx_init(int cpu)
15179 {
15180- union irq_ctx *irqctx;
15181-
15182 if (per_cpu(hardirq_ctx, cpu))
15183 return;
15184
15185- irqctx = &per_cpu(hardirq_stack, cpu);
15186- irqctx->tinfo.task = NULL;
15187- irqctx->tinfo.exec_domain = NULL;
15188- irqctx->tinfo.cpu = cpu;
15189- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15190- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15191-
15192- per_cpu(hardirq_ctx, cpu) = irqctx;
15193-
15194- irqctx = &per_cpu(softirq_stack, cpu);
15195- irqctx->tinfo.task = NULL;
15196- irqctx->tinfo.exec_domain = NULL;
15197- irqctx->tinfo.cpu = cpu;
15198- irqctx->tinfo.preempt_count = 0;
15199- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15200-
15201- per_cpu(softirq_ctx, cpu) = irqctx;
15202+ per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
15203+ per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
15204
15205 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15206 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15207@@ -159,7 +141,6 @@ void irq_ctx_exit(int cpu)
15208 asmlinkage void do_softirq(void)
15209 {
15210 unsigned long flags;
15211- struct thread_info *curctx;
15212 union irq_ctx *irqctx;
15213 u32 *isp;
15214
15215@@ -169,15 +150,22 @@ asmlinkage void do_softirq(void)
15216 local_irq_save(flags);
15217
15218 if (local_softirq_pending()) {
15219- curctx = current_thread_info();
15220 irqctx = __get_cpu_var(softirq_ctx);
15221- irqctx->tinfo.task = curctx->task;
15222- irqctx->tinfo.previous_esp = current_stack_pointer;
15223+ irqctx->previous_esp = current_stack_pointer;
15224
15225 /* build the stack frame on the softirq stack */
15226- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15227+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15228+
15229+#ifdef CONFIG_PAX_MEMORY_UDEREF
15230+ __set_fs(MAKE_MM_SEG(0));
15231+#endif
15232
15233 call_on_stack(__do_softirq, isp);
15234+
15235+#ifdef CONFIG_PAX_MEMORY_UDEREF
15236+ __set_fs(current_thread_info()->addr_limit);
15237+#endif
15238+
15239 /*
15240 * Shouldnt happen, we returned above if in_interrupt():
15241 */
15242diff -urNp linux-2.6.32.44/arch/x86/kernel/irq.c linux-2.6.32.44/arch/x86/kernel/irq.c
15243--- linux-2.6.32.44/arch/x86/kernel/irq.c 2011-03-27 14:31:47.000000000 -0400
15244+++ linux-2.6.32.44/arch/x86/kernel/irq.c 2011-05-04 17:56:28.000000000 -0400
15245@@ -15,7 +15,7 @@
15246 #include <asm/mce.h>
15247 #include <asm/hw_irq.h>
15248
15249-atomic_t irq_err_count;
15250+atomic_unchecked_t irq_err_count;
15251
15252 /* Function pointer for generic interrupt vector handling */
15253 void (*generic_interrupt_extension)(void) = NULL;
15254@@ -114,9 +114,9 @@ static int show_other_interrupts(struct
15255 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15256 seq_printf(p, " Machine check polls\n");
15257 #endif
15258- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15259+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15260 #if defined(CONFIG_X86_IO_APIC)
15261- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15262+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15263 #endif
15264 return 0;
15265 }
15266@@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15267
15268 u64 arch_irq_stat(void)
15269 {
15270- u64 sum = atomic_read(&irq_err_count);
15271+ u64 sum = atomic_read_unchecked(&irq_err_count);
15272
15273 #ifdef CONFIG_X86_IO_APIC
15274- sum += atomic_read(&irq_mis_count);
15275+ sum += atomic_read_unchecked(&irq_mis_count);
15276 #endif
15277 return sum;
15278 }
15279diff -urNp linux-2.6.32.44/arch/x86/kernel/kgdb.c linux-2.6.32.44/arch/x86/kernel/kgdb.c
15280--- linux-2.6.32.44/arch/x86/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
15281+++ linux-2.6.32.44/arch/x86/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
15282@@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vec
15283
15284 /* clear the trace bit */
15285 linux_regs->flags &= ~X86_EFLAGS_TF;
15286- atomic_set(&kgdb_cpu_doing_single_step, -1);
15287+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15288
15289 /* set the trace bit if we're stepping */
15290 if (remcomInBuffer[0] == 's') {
15291 linux_regs->flags |= X86_EFLAGS_TF;
15292 kgdb_single_step = 1;
15293- atomic_set(&kgdb_cpu_doing_single_step,
15294+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15295 raw_smp_processor_id());
15296 }
15297
15298@@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args
15299 break;
15300
15301 case DIE_DEBUG:
15302- if (atomic_read(&kgdb_cpu_doing_single_step) ==
15303+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
15304 raw_smp_processor_id()) {
15305 if (user_mode(regs))
15306 return single_step_cont(regs, args);
15307@@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception
15308 return instruction_pointer(regs);
15309 }
15310
15311-struct kgdb_arch arch_kgdb_ops = {
15312+const struct kgdb_arch arch_kgdb_ops = {
15313 /* Breakpoint instruction: */
15314 .gdb_bpt_instr = { 0xcc },
15315 .flags = KGDB_HW_BREAKPOINT,
15316diff -urNp linux-2.6.32.44/arch/x86/kernel/kprobes.c linux-2.6.32.44/arch/x86/kernel/kprobes.c
15317--- linux-2.6.32.44/arch/x86/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
15318+++ linux-2.6.32.44/arch/x86/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
15319@@ -166,9 +166,13 @@ static void __kprobes set_jmp_op(void *f
15320 char op;
15321 s32 raddr;
15322 } __attribute__((packed)) * jop;
15323- jop = (struct __arch_jmp_op *)from;
15324+
15325+ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
15326+
15327+ pax_open_kernel();
15328 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
15329 jop->op = RELATIVEJUMP_INSTRUCTION;
15330+ pax_close_kernel();
15331 }
15332
15333 /*
15334@@ -193,7 +197,7 @@ static int __kprobes can_boost(kprobe_op
15335 kprobe_opcode_t opcode;
15336 kprobe_opcode_t *orig_opcodes = opcodes;
15337
15338- if (search_exception_tables((unsigned long)opcodes))
15339+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15340 return 0; /* Page fault may occur on this address. */
15341
15342 retry:
15343@@ -337,7 +341,9 @@ static void __kprobes fix_riprel(struct
15344 disp = (u8 *) p->addr + *((s32 *) insn) -
15345 (u8 *) p->ainsn.insn;
15346 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
15347+ pax_open_kernel();
15348 *(s32 *)insn = (s32) disp;
15349+ pax_close_kernel();
15350 }
15351 }
15352 #endif
15353@@ -345,16 +351,18 @@ static void __kprobes fix_riprel(struct
15354
15355 static void __kprobes arch_copy_kprobe(struct kprobe *p)
15356 {
15357- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
15358+ pax_open_kernel();
15359+ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
15360+ pax_close_kernel();
15361
15362 fix_riprel(p);
15363
15364- if (can_boost(p->addr))
15365+ if (can_boost(ktla_ktva(p->addr)))
15366 p->ainsn.boostable = 0;
15367 else
15368 p->ainsn.boostable = -1;
15369
15370- p->opcode = *p->addr;
15371+ p->opcode = *(ktla_ktva(p->addr));
15372 }
15373
15374 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15375@@ -432,7 +440,7 @@ static void __kprobes prepare_singlestep
15376 if (p->opcode == BREAKPOINT_INSTRUCTION)
15377 regs->ip = (unsigned long)p->addr;
15378 else
15379- regs->ip = (unsigned long)p->ainsn.insn;
15380+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15381 }
15382
15383 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
15384@@ -453,7 +461,7 @@ static void __kprobes setup_singlestep(s
15385 if (p->ainsn.boostable == 1 && !p->post_handler) {
15386 /* Boost up -- we can execute copied instructions directly */
15387 reset_current_kprobe();
15388- regs->ip = (unsigned long)p->ainsn.insn;
15389+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15390 preempt_enable_no_resched();
15391 return;
15392 }
15393@@ -523,7 +531,7 @@ static int __kprobes kprobe_handler(stru
15394 struct kprobe_ctlblk *kcb;
15395
15396 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
15397- if (*addr != BREAKPOINT_INSTRUCTION) {
15398+ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15399 /*
15400 * The breakpoint instruction was removed right
15401 * after we hit it. Another cpu has removed
15402@@ -775,7 +783,7 @@ static void __kprobes resume_execution(s
15403 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15404 {
15405 unsigned long *tos = stack_addr(regs);
15406- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15407+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15408 unsigned long orig_ip = (unsigned long)p->addr;
15409 kprobe_opcode_t *insn = p->ainsn.insn;
15410
15411@@ -958,7 +966,7 @@ int __kprobes kprobe_exceptions_notify(s
15412 struct die_args *args = data;
15413 int ret = NOTIFY_DONE;
15414
15415- if (args->regs && user_mode_vm(args->regs))
15416+ if (args->regs && user_mode(args->regs))
15417 return ret;
15418
15419 switch (val) {
15420diff -urNp linux-2.6.32.44/arch/x86/kernel/ldt.c linux-2.6.32.44/arch/x86/kernel/ldt.c
15421--- linux-2.6.32.44/arch/x86/kernel/ldt.c 2011-03-27 14:31:47.000000000 -0400
15422+++ linux-2.6.32.44/arch/x86/kernel/ldt.c 2011-04-17 15:56:46.000000000 -0400
15423@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, i
15424 if (reload) {
15425 #ifdef CONFIG_SMP
15426 preempt_disable();
15427- load_LDT(pc);
15428+ load_LDT_nolock(pc);
15429 if (!cpumask_equal(mm_cpumask(current->mm),
15430 cpumask_of(smp_processor_id())))
15431 smp_call_function(flush_ldt, current->mm, 1);
15432 preempt_enable();
15433 #else
15434- load_LDT(pc);
15435+ load_LDT_nolock(pc);
15436 #endif
15437 }
15438 if (oldsize) {
15439@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t
15440 return err;
15441
15442 for (i = 0; i < old->size; i++)
15443- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15444+ write_ldt_entry(new->ldt, i, old->ldt + i);
15445 return 0;
15446 }
15447
15448@@ -115,6 +115,24 @@ int init_new_context(struct task_struct
15449 retval = copy_ldt(&mm->context, &old_mm->context);
15450 mutex_unlock(&old_mm->context.lock);
15451 }
15452+
15453+ if (tsk == current) {
15454+ mm->context.vdso = 0;
15455+
15456+#ifdef CONFIG_X86_32
15457+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15458+ mm->context.user_cs_base = 0UL;
15459+ mm->context.user_cs_limit = ~0UL;
15460+
15461+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15462+ cpus_clear(mm->context.cpu_user_cs_mask);
15463+#endif
15464+
15465+#endif
15466+#endif
15467+
15468+ }
15469+
15470 return retval;
15471 }
15472
15473@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, u
15474 }
15475 }
15476
15477+#ifdef CONFIG_PAX_SEGMEXEC
15478+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15479+ error = -EINVAL;
15480+ goto out_unlock;
15481+ }
15482+#endif
15483+
15484 fill_ldt(&ldt, &ldt_info);
15485 if (oldmode)
15486 ldt.avl = 0;
15487diff -urNp linux-2.6.32.44/arch/x86/kernel/machine_kexec_32.c linux-2.6.32.44/arch/x86/kernel/machine_kexec_32.c
15488--- linux-2.6.32.44/arch/x86/kernel/machine_kexec_32.c 2011-03-27 14:31:47.000000000 -0400
15489+++ linux-2.6.32.44/arch/x86/kernel/machine_kexec_32.c 2011-04-17 15:56:46.000000000 -0400
15490@@ -26,7 +26,7 @@
15491 #include <asm/system.h>
15492 #include <asm/cacheflush.h>
15493
15494-static void set_idt(void *newidt, __u16 limit)
15495+static void set_idt(struct desc_struct *newidt, __u16 limit)
15496 {
15497 struct desc_ptr curidt;
15498
15499@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16
15500 }
15501
15502
15503-static void set_gdt(void *newgdt, __u16 limit)
15504+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15505 {
15506 struct desc_ptr curgdt;
15507
15508@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15509 }
15510
15511 control_page = page_address(image->control_code_page);
15512- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15513+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15514
15515 relocate_kernel_ptr = control_page;
15516 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15517diff -urNp linux-2.6.32.44/arch/x86/kernel/microcode_amd.c linux-2.6.32.44/arch/x86/kernel/microcode_amd.c
15518--- linux-2.6.32.44/arch/x86/kernel/microcode_amd.c 2011-04-17 17:00:52.000000000 -0400
15519+++ linux-2.6.32.44/arch/x86/kernel/microcode_amd.c 2011-04-17 17:03:05.000000000 -0400
15520@@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int c
15521 uci->mc = NULL;
15522 }
15523
15524-static struct microcode_ops microcode_amd_ops = {
15525+static const struct microcode_ops microcode_amd_ops = {
15526 .request_microcode_user = request_microcode_user,
15527 .request_microcode_fw = request_microcode_fw,
15528 .collect_cpu_info = collect_cpu_info_amd,
15529@@ -372,7 +372,7 @@ static struct microcode_ops microcode_am
15530 .microcode_fini_cpu = microcode_fini_cpu_amd,
15531 };
15532
15533-struct microcode_ops * __init init_amd_microcode(void)
15534+const struct microcode_ops * __init init_amd_microcode(void)
15535 {
15536 return &microcode_amd_ops;
15537 }
15538diff -urNp linux-2.6.32.44/arch/x86/kernel/microcode_core.c linux-2.6.32.44/arch/x86/kernel/microcode_core.c
15539--- linux-2.6.32.44/arch/x86/kernel/microcode_core.c 2011-03-27 14:31:47.000000000 -0400
15540+++ linux-2.6.32.44/arch/x86/kernel/microcode_core.c 2011-04-17 15:56:46.000000000 -0400
15541@@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
15542
15543 #define MICROCODE_VERSION "2.00"
15544
15545-static struct microcode_ops *microcode_ops;
15546+static const struct microcode_ops *microcode_ops;
15547
15548 /*
15549 * Synchronization.
15550diff -urNp linux-2.6.32.44/arch/x86/kernel/microcode_intel.c linux-2.6.32.44/arch/x86/kernel/microcode_intel.c
15551--- linux-2.6.32.44/arch/x86/kernel/microcode_intel.c 2011-03-27 14:31:47.000000000 -0400
15552+++ linux-2.6.32.44/arch/x86/kernel/microcode_intel.c 2011-04-17 15:56:46.000000000 -0400
15553@@ -443,13 +443,13 @@ static enum ucode_state request_microcod
15554
15555 static int get_ucode_user(void *to, const void *from, size_t n)
15556 {
15557- return copy_from_user(to, from, n);
15558+ return copy_from_user(to, (__force const void __user *)from, n);
15559 }
15560
15561 static enum ucode_state
15562 request_microcode_user(int cpu, const void __user *buf, size_t size)
15563 {
15564- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
15565+ return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
15566 }
15567
15568 static void microcode_fini_cpu(int cpu)
15569@@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
15570 uci->mc = NULL;
15571 }
15572
15573-static struct microcode_ops microcode_intel_ops = {
15574+static const struct microcode_ops microcode_intel_ops = {
15575 .request_microcode_user = request_microcode_user,
15576 .request_microcode_fw = request_microcode_fw,
15577 .collect_cpu_info = collect_cpu_info,
15578@@ -468,7 +468,7 @@ static struct microcode_ops microcode_in
15579 .microcode_fini_cpu = microcode_fini_cpu,
15580 };
15581
15582-struct microcode_ops * __init init_intel_microcode(void)
15583+const struct microcode_ops * __init init_intel_microcode(void)
15584 {
15585 return &microcode_intel_ops;
15586 }
15587diff -urNp linux-2.6.32.44/arch/x86/kernel/module.c linux-2.6.32.44/arch/x86/kernel/module.c
15588--- linux-2.6.32.44/arch/x86/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
15589+++ linux-2.6.32.44/arch/x86/kernel/module.c 2011-04-17 15:56:46.000000000 -0400
15590@@ -34,7 +34,7 @@
15591 #define DEBUGP(fmt...)
15592 #endif
15593
15594-void *module_alloc(unsigned long size)
15595+static void *__module_alloc(unsigned long size, pgprot_t prot)
15596 {
15597 struct vm_struct *area;
15598
15599@@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
15600 if (!area)
15601 return NULL;
15602
15603- return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
15604- PAGE_KERNEL_EXEC);
15605+ return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
15606+}
15607+
15608+void *module_alloc(unsigned long size)
15609+{
15610+
15611+#ifdef CONFIG_PAX_KERNEXEC
15612+ return __module_alloc(size, PAGE_KERNEL);
15613+#else
15614+ return __module_alloc(size, PAGE_KERNEL_EXEC);
15615+#endif
15616+
15617 }
15618
15619 /* Free memory returned from module_alloc */
15620@@ -58,6 +68,40 @@ void module_free(struct module *mod, voi
15621 vfree(module_region);
15622 }
15623
15624+#ifdef CONFIG_PAX_KERNEXEC
15625+#ifdef CONFIG_X86_32
15626+void *module_alloc_exec(unsigned long size)
15627+{
15628+ struct vm_struct *area;
15629+
15630+ if (size == 0)
15631+ return NULL;
15632+
15633+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
15634+ return area ? area->addr : NULL;
15635+}
15636+EXPORT_SYMBOL(module_alloc_exec);
15637+
15638+void module_free_exec(struct module *mod, void *module_region)
15639+{
15640+ vunmap(module_region);
15641+}
15642+EXPORT_SYMBOL(module_free_exec);
15643+#else
15644+void module_free_exec(struct module *mod, void *module_region)
15645+{
15646+ module_free(mod, module_region);
15647+}
15648+EXPORT_SYMBOL(module_free_exec);
15649+
15650+void *module_alloc_exec(unsigned long size)
15651+{
15652+ return __module_alloc(size, PAGE_KERNEL_RX);
15653+}
15654+EXPORT_SYMBOL(module_alloc_exec);
15655+#endif
15656+#endif
15657+
15658 /* We don't need anything special. */
15659 int module_frob_arch_sections(Elf_Ehdr *hdr,
15660 Elf_Shdr *sechdrs,
15661@@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15662 unsigned int i;
15663 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
15664 Elf32_Sym *sym;
15665- uint32_t *location;
15666+ uint32_t *plocation, location;
15667
15668 DEBUGP("Applying relocate section %u to %u\n", relsec,
15669 sechdrs[relsec].sh_info);
15670 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
15671 /* This is where to make the change */
15672- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
15673- + rel[i].r_offset;
15674+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
15675+ location = (uint32_t)plocation;
15676+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
15677+ plocation = ktla_ktva((void *)plocation);
15678 /* This is the symbol it is referring to. Note that all
15679 undefined symbols have been resolved. */
15680 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
15681@@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15682 switch (ELF32_R_TYPE(rel[i].r_info)) {
15683 case R_386_32:
15684 /* We add the value into the location given */
15685- *location += sym->st_value;
15686+ pax_open_kernel();
15687+ *plocation += sym->st_value;
15688+ pax_close_kernel();
15689 break;
15690 case R_386_PC32:
15691 /* Add the value, subtract its postition */
15692- *location += sym->st_value - (uint32_t)location;
15693+ pax_open_kernel();
15694+ *plocation += sym->st_value - location;
15695+ pax_close_kernel();
15696 break;
15697 default:
15698 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
15699@@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
15700 case R_X86_64_NONE:
15701 break;
15702 case R_X86_64_64:
15703+ pax_open_kernel();
15704 *(u64 *)loc = val;
15705+ pax_close_kernel();
15706 break;
15707 case R_X86_64_32:
15708+ pax_open_kernel();
15709 *(u32 *)loc = val;
15710+ pax_close_kernel();
15711 if (val != *(u32 *)loc)
15712 goto overflow;
15713 break;
15714 case R_X86_64_32S:
15715+ pax_open_kernel();
15716 *(s32 *)loc = val;
15717+ pax_close_kernel();
15718 if ((s64)val != *(s32 *)loc)
15719 goto overflow;
15720 break;
15721 case R_X86_64_PC32:
15722 val -= (u64)loc;
15723+ pax_open_kernel();
15724 *(u32 *)loc = val;
15725+ pax_close_kernel();
15726+
15727 #if 0
15728 if ((s64)val != *(s32 *)loc)
15729 goto overflow;
15730diff -urNp linux-2.6.32.44/arch/x86/kernel/paravirt.c linux-2.6.32.44/arch/x86/kernel/paravirt.c
15731--- linux-2.6.32.44/arch/x86/kernel/paravirt.c 2011-03-27 14:31:47.000000000 -0400
15732+++ linux-2.6.32.44/arch/x86/kernel/paravirt.c 2011-08-05 20:33:55.000000000 -0400
15733@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
15734 {
15735 return x;
15736 }
15737+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
15738+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
15739+#endif
15740
15741 void __init default_banner(void)
15742 {
15743@@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbu
15744 * corresponding structure. */
15745 static void *get_call_destination(u8 type)
15746 {
15747- struct paravirt_patch_template tmpl = {
15748+ const struct paravirt_patch_template tmpl = {
15749 .pv_init_ops = pv_init_ops,
15750 .pv_time_ops = pv_time_ops,
15751 .pv_cpu_ops = pv_cpu_ops,
15752@@ -133,6 +136,8 @@ static void *get_call_destination(u8 typ
15753 .pv_lock_ops = pv_lock_ops,
15754 #endif
15755 };
15756+
15757+ pax_track_stack();
15758 return *((void **)&tmpl + type);
15759 }
15760
15761@@ -145,15 +150,19 @@ unsigned paravirt_patch_default(u8 type,
15762 if (opfunc == NULL)
15763 /* If there's no function, patch it with a ud2a (BUG) */
15764 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
15765- else if (opfunc == _paravirt_nop)
15766+ else if (opfunc == (void *)_paravirt_nop)
15767 /* If the operation is a nop, then nop the callsite */
15768 ret = paravirt_patch_nop();
15769
15770 /* identity functions just return their single argument */
15771- else if (opfunc == _paravirt_ident_32)
15772+ else if (opfunc == (void *)_paravirt_ident_32)
15773 ret = paravirt_patch_ident_32(insnbuf, len);
15774- else if (opfunc == _paravirt_ident_64)
15775+ else if (opfunc == (void *)_paravirt_ident_64)
15776+ ret = paravirt_patch_ident_64(insnbuf, len);
15777+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
15778+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
15779 ret = paravirt_patch_ident_64(insnbuf, len);
15780+#endif
15781
15782 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
15783 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
15784@@ -178,7 +187,7 @@ unsigned paravirt_patch_insns(void *insn
15785 if (insn_len > len || start == NULL)
15786 insn_len = len;
15787 else
15788- memcpy(insnbuf, start, insn_len);
15789+ memcpy(insnbuf, ktla_ktva(start), insn_len);
15790
15791 return insn_len;
15792 }
15793@@ -294,22 +303,22 @@ void arch_flush_lazy_mmu_mode(void)
15794 preempt_enable();
15795 }
15796
15797-struct pv_info pv_info = {
15798+struct pv_info pv_info __read_only = {
15799 .name = "bare hardware",
15800 .paravirt_enabled = 0,
15801 .kernel_rpl = 0,
15802 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
15803 };
15804
15805-struct pv_init_ops pv_init_ops = {
15806+struct pv_init_ops pv_init_ops __read_only = {
15807 .patch = native_patch,
15808 };
15809
15810-struct pv_time_ops pv_time_ops = {
15811+struct pv_time_ops pv_time_ops __read_only = {
15812 .sched_clock = native_sched_clock,
15813 };
15814
15815-struct pv_irq_ops pv_irq_ops = {
15816+struct pv_irq_ops pv_irq_ops __read_only = {
15817 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
15818 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
15819 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
15820@@ -321,7 +330,7 @@ struct pv_irq_ops pv_irq_ops = {
15821 #endif
15822 };
15823
15824-struct pv_cpu_ops pv_cpu_ops = {
15825+struct pv_cpu_ops pv_cpu_ops __read_only = {
15826 .cpuid = native_cpuid,
15827 .get_debugreg = native_get_debugreg,
15828 .set_debugreg = native_set_debugreg,
15829@@ -382,21 +391,26 @@ struct pv_cpu_ops pv_cpu_ops = {
15830 .end_context_switch = paravirt_nop,
15831 };
15832
15833-struct pv_apic_ops pv_apic_ops = {
15834+struct pv_apic_ops pv_apic_ops __read_only = {
15835 #ifdef CONFIG_X86_LOCAL_APIC
15836 .startup_ipi_hook = paravirt_nop,
15837 #endif
15838 };
15839
15840-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
15841+#ifdef CONFIG_X86_32
15842+#ifdef CONFIG_X86_PAE
15843+/* 64-bit pagetable entries */
15844+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
15845+#else
15846 /* 32-bit pagetable entries */
15847 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
15848+#endif
15849 #else
15850 /* 64-bit pagetable entries */
15851 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
15852 #endif
15853
15854-struct pv_mmu_ops pv_mmu_ops = {
15855+struct pv_mmu_ops pv_mmu_ops __read_only = {
15856
15857 .read_cr2 = native_read_cr2,
15858 .write_cr2 = native_write_cr2,
15859@@ -467,6 +481,12 @@ struct pv_mmu_ops pv_mmu_ops = {
15860 },
15861
15862 .set_fixmap = native_set_fixmap,
15863+
15864+#ifdef CONFIG_PAX_KERNEXEC
15865+ .pax_open_kernel = native_pax_open_kernel,
15866+ .pax_close_kernel = native_pax_close_kernel,
15867+#endif
15868+
15869 };
15870
15871 EXPORT_SYMBOL_GPL(pv_time_ops);
15872diff -urNp linux-2.6.32.44/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.32.44/arch/x86/kernel/paravirt-spinlocks.c
15873--- linux-2.6.32.44/arch/x86/kernel/paravirt-spinlocks.c 2011-03-27 14:31:47.000000000 -0400
15874+++ linux-2.6.32.44/arch/x86/kernel/paravirt-spinlocks.c 2011-04-17 15:56:46.000000000 -0400
15875@@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *
15876 __raw_spin_lock(lock);
15877 }
15878
15879-struct pv_lock_ops pv_lock_ops = {
15880+struct pv_lock_ops pv_lock_ops __read_only = {
15881 #ifdef CONFIG_SMP
15882 .spin_is_locked = __ticket_spin_is_locked,
15883 .spin_is_contended = __ticket_spin_is_contended,
15884diff -urNp linux-2.6.32.44/arch/x86/kernel/pci-calgary_64.c linux-2.6.32.44/arch/x86/kernel/pci-calgary_64.c
15885--- linux-2.6.32.44/arch/x86/kernel/pci-calgary_64.c 2011-03-27 14:31:47.000000000 -0400
15886+++ linux-2.6.32.44/arch/x86/kernel/pci-calgary_64.c 2011-04-17 15:56:46.000000000 -0400
15887@@ -477,7 +477,7 @@ static void calgary_free_coherent(struct
15888 free_pages((unsigned long)vaddr, get_order(size));
15889 }
15890
15891-static struct dma_map_ops calgary_dma_ops = {
15892+static const struct dma_map_ops calgary_dma_ops = {
15893 .alloc_coherent = calgary_alloc_coherent,
15894 .free_coherent = calgary_free_coherent,
15895 .map_sg = calgary_map_sg,
15896diff -urNp linux-2.6.32.44/arch/x86/kernel/pci-dma.c linux-2.6.32.44/arch/x86/kernel/pci-dma.c
15897--- linux-2.6.32.44/arch/x86/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
15898+++ linux-2.6.32.44/arch/x86/kernel/pci-dma.c 2011-04-17 15:56:46.000000000 -0400
15899@@ -14,7 +14,7 @@
15900
15901 static int forbid_dac __read_mostly;
15902
15903-struct dma_map_ops *dma_ops;
15904+const struct dma_map_ops *dma_ops;
15905 EXPORT_SYMBOL(dma_ops);
15906
15907 static int iommu_sac_force __read_mostly;
15908@@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
15909
15910 int dma_supported(struct device *dev, u64 mask)
15911 {
15912- struct dma_map_ops *ops = get_dma_ops(dev);
15913+ const struct dma_map_ops *ops = get_dma_ops(dev);
15914
15915 #ifdef CONFIG_PCI
15916 if (mask > 0xffffffff && forbid_dac > 0) {
15917diff -urNp linux-2.6.32.44/arch/x86/kernel/pci-gart_64.c linux-2.6.32.44/arch/x86/kernel/pci-gart_64.c
15918--- linux-2.6.32.44/arch/x86/kernel/pci-gart_64.c 2011-03-27 14:31:47.000000000 -0400
15919+++ linux-2.6.32.44/arch/x86/kernel/pci-gart_64.c 2011-04-17 15:56:46.000000000 -0400
15920@@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct ag
15921 return -1;
15922 }
15923
15924-static struct dma_map_ops gart_dma_ops = {
15925+static const struct dma_map_ops gart_dma_ops = {
15926 .map_sg = gart_map_sg,
15927 .unmap_sg = gart_unmap_sg,
15928 .map_page = gart_map_page,
15929diff -urNp linux-2.6.32.44/arch/x86/kernel/pci-nommu.c linux-2.6.32.44/arch/x86/kernel/pci-nommu.c
15930--- linux-2.6.32.44/arch/x86/kernel/pci-nommu.c 2011-03-27 14:31:47.000000000 -0400
15931+++ linux-2.6.32.44/arch/x86/kernel/pci-nommu.c 2011-04-17 15:56:46.000000000 -0400
15932@@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(str
15933 flush_write_buffers();
15934 }
15935
15936-struct dma_map_ops nommu_dma_ops = {
15937+const struct dma_map_ops nommu_dma_ops = {
15938 .alloc_coherent = dma_generic_alloc_coherent,
15939 .free_coherent = nommu_free_coherent,
15940 .map_sg = nommu_map_sg,
15941diff -urNp linux-2.6.32.44/arch/x86/kernel/pci-swiotlb.c linux-2.6.32.44/arch/x86/kernel/pci-swiotlb.c
15942--- linux-2.6.32.44/arch/x86/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
15943+++ linux-2.6.32.44/arch/x86/kernel/pci-swiotlb.c 2011-04-17 15:56:46.000000000 -0400
15944@@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(
15945 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
15946 }
15947
15948-static struct dma_map_ops swiotlb_dma_ops = {
15949+static const struct dma_map_ops swiotlb_dma_ops = {
15950 .mapping_error = swiotlb_dma_mapping_error,
15951 .alloc_coherent = x86_swiotlb_alloc_coherent,
15952 .free_coherent = swiotlb_free_coherent,
15953diff -urNp linux-2.6.32.44/arch/x86/kernel/process_32.c linux-2.6.32.44/arch/x86/kernel/process_32.c
15954--- linux-2.6.32.44/arch/x86/kernel/process_32.c 2011-06-25 12:55:34.000000000 -0400
15955+++ linux-2.6.32.44/arch/x86/kernel/process_32.c 2011-06-25 12:56:37.000000000 -0400
15956@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __as
15957 unsigned long thread_saved_pc(struct task_struct *tsk)
15958 {
15959 return ((unsigned long *)tsk->thread.sp)[3];
15960+//XXX return tsk->thread.eip;
15961 }
15962
15963 #ifndef CONFIG_SMP
15964@@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, i
15965 unsigned short ss, gs;
15966 const char *board;
15967
15968- if (user_mode_vm(regs)) {
15969+ if (user_mode(regs)) {
15970 sp = regs->sp;
15971 ss = regs->ss & 0xffff;
15972- gs = get_user_gs(regs);
15973 } else {
15974 sp = (unsigned long) (&regs->sp);
15975 savesegment(ss, ss);
15976- savesegment(gs, gs);
15977 }
15978+ gs = get_user_gs(regs);
15979
15980 printk("\n");
15981
15982@@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), voi
15983 regs.bx = (unsigned long) fn;
15984 regs.dx = (unsigned long) arg;
15985
15986- regs.ds = __USER_DS;
15987- regs.es = __USER_DS;
15988+ regs.ds = __KERNEL_DS;
15989+ regs.es = __KERNEL_DS;
15990 regs.fs = __KERNEL_PERCPU;
15991- regs.gs = __KERNEL_STACK_CANARY;
15992+ savesegment(gs, regs.gs);
15993 regs.orig_ax = -1;
15994 regs.ip = (unsigned long) kernel_thread_helper;
15995 regs.cs = __KERNEL_CS | get_kernel_rpl();
15996@@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flag
15997 struct task_struct *tsk;
15998 int err;
15999
16000- childregs = task_pt_regs(p);
16001+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16002 *childregs = *regs;
16003 childregs->ax = 0;
16004 childregs->sp = sp;
16005
16006 p->thread.sp = (unsigned long) childregs;
16007 p->thread.sp0 = (unsigned long) (childregs+1);
16008+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16009
16010 p->thread.ip = (unsigned long) ret_from_fork;
16011
16012@@ -345,7 +346,7 @@ __switch_to(struct task_struct *prev_p,
16013 struct thread_struct *prev = &prev_p->thread,
16014 *next = &next_p->thread;
16015 int cpu = smp_processor_id();
16016- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16017+ struct tss_struct *tss = init_tss + cpu;
16018 bool preload_fpu;
16019
16020 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16021@@ -380,6 +381,10 @@ __switch_to(struct task_struct *prev_p,
16022 */
16023 lazy_save_gs(prev->gs);
16024
16025+#ifdef CONFIG_PAX_MEMORY_UDEREF
16026+ __set_fs(task_thread_info(next_p)->addr_limit);
16027+#endif
16028+
16029 /*
16030 * Load the per-thread Thread-Local Storage descriptor.
16031 */
16032@@ -415,6 +420,9 @@ __switch_to(struct task_struct *prev_p,
16033 */
16034 arch_end_context_switch(next_p);
16035
16036+ percpu_write(current_task, next_p);
16037+ percpu_write(current_tinfo, &next_p->tinfo);
16038+
16039 if (preload_fpu)
16040 __math_state_restore();
16041
16042@@ -424,8 +432,6 @@ __switch_to(struct task_struct *prev_p,
16043 if (prev->gs | next->gs)
16044 lazy_load_gs(next->gs);
16045
16046- percpu_write(current_task, next_p);
16047-
16048 return prev_p;
16049 }
16050
16051@@ -495,4 +501,3 @@ unsigned long get_wchan(struct task_stru
16052 } while (count++ < 16);
16053 return 0;
16054 }
16055-
16056diff -urNp linux-2.6.32.44/arch/x86/kernel/process_64.c linux-2.6.32.44/arch/x86/kernel/process_64.c
16057--- linux-2.6.32.44/arch/x86/kernel/process_64.c 2011-06-25 12:55:34.000000000 -0400
16058+++ linux-2.6.32.44/arch/x86/kernel/process_64.c 2011-06-25 12:56:37.000000000 -0400
16059@@ -91,7 +91,7 @@ static void __exit_idle(void)
16060 void exit_idle(void)
16061 {
16062 /* idle loop has pid 0 */
16063- if (current->pid)
16064+ if (task_pid_nr(current))
16065 return;
16066 __exit_idle();
16067 }
16068@@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, i
16069 if (!board)
16070 board = "";
16071 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
16072- current->pid, current->comm, print_tainted(),
16073+ task_pid_nr(current), current->comm, print_tainted(),
16074 init_utsname()->release,
16075 (int)strcspn(init_utsname()->version, " "),
16076 init_utsname()->version, board);
16077@@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flag
16078 struct pt_regs *childregs;
16079 struct task_struct *me = current;
16080
16081- childregs = ((struct pt_regs *)
16082- (THREAD_SIZE + task_stack_page(p))) - 1;
16083+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16084 *childregs = *regs;
16085
16086 childregs->ax = 0;
16087@@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flag
16088 p->thread.sp = (unsigned long) childregs;
16089 p->thread.sp0 = (unsigned long) (childregs+1);
16090 p->thread.usersp = me->thread.usersp;
16091+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16092
16093 set_tsk_thread_flag(p, TIF_FORK);
16094
16095@@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p,
16096 struct thread_struct *prev = &prev_p->thread;
16097 struct thread_struct *next = &next_p->thread;
16098 int cpu = smp_processor_id();
16099- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16100+ struct tss_struct *tss = init_tss + cpu;
16101 unsigned fsindex, gsindex;
16102 bool preload_fpu;
16103
16104@@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p,
16105 prev->usersp = percpu_read(old_rsp);
16106 percpu_write(old_rsp, next->usersp);
16107 percpu_write(current_task, next_p);
16108+ percpu_write(current_tinfo, &next_p->tinfo);
16109
16110- percpu_write(kernel_stack,
16111- (unsigned long)task_stack_page(next_p) +
16112- THREAD_SIZE - KERNEL_STACK_OFFSET);
16113+ percpu_write(kernel_stack, next->sp0);
16114
16115 /*
16116 * Now maybe reload the debug registers and handle I/O bitmaps
16117@@ -559,12 +558,11 @@ unsigned long get_wchan(struct task_stru
16118 if (!p || p == current || p->state == TASK_RUNNING)
16119 return 0;
16120 stack = (unsigned long)task_stack_page(p);
16121- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16122+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16123 return 0;
16124 fp = *(u64 *)(p->thread.sp);
16125 do {
16126- if (fp < (unsigned long)stack ||
16127- fp >= (unsigned long)stack+THREAD_SIZE)
16128+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16129 return 0;
16130 ip = *(u64 *)(fp+8);
16131 if (!in_sched_functions(ip))
16132diff -urNp linux-2.6.32.44/arch/x86/kernel/process.c linux-2.6.32.44/arch/x86/kernel/process.c
16133--- linux-2.6.32.44/arch/x86/kernel/process.c 2011-04-22 19:16:29.000000000 -0400
16134+++ linux-2.6.32.44/arch/x86/kernel/process.c 2011-05-22 23:02:03.000000000 -0400
16135@@ -51,16 +51,33 @@ void free_thread_xstate(struct task_stru
16136
16137 void free_thread_info(struct thread_info *ti)
16138 {
16139- free_thread_xstate(ti->task);
16140 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16141 }
16142
16143+static struct kmem_cache *task_struct_cachep;
16144+
16145 void arch_task_cache_init(void)
16146 {
16147- task_xstate_cachep =
16148- kmem_cache_create("task_xstate", xstate_size,
16149+ /* create a slab on which task_structs can be allocated */
16150+ task_struct_cachep =
16151+ kmem_cache_create("task_struct", sizeof(struct task_struct),
16152+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16153+
16154+ task_xstate_cachep =
16155+ kmem_cache_create("task_xstate", xstate_size,
16156 __alignof__(union thread_xstate),
16157- SLAB_PANIC | SLAB_NOTRACK, NULL);
16158+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16159+}
16160+
16161+struct task_struct *alloc_task_struct(void)
16162+{
16163+ return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
16164+}
16165+
16166+void free_task_struct(struct task_struct *task)
16167+{
16168+ free_thread_xstate(task);
16169+ kmem_cache_free(task_struct_cachep, task);
16170 }
16171
16172 /*
16173@@ -73,7 +90,7 @@ void exit_thread(void)
16174 unsigned long *bp = t->io_bitmap_ptr;
16175
16176 if (bp) {
16177- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16178+ struct tss_struct *tss = init_tss + get_cpu();
16179
16180 t->io_bitmap_ptr = NULL;
16181 clear_thread_flag(TIF_IO_BITMAP);
16182@@ -93,6 +110,9 @@ void flush_thread(void)
16183
16184 clear_tsk_thread_flag(tsk, TIF_DEBUG);
16185
16186+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16187+ loadsegment(gs, 0);
16188+#endif
16189 tsk->thread.debugreg0 = 0;
16190 tsk->thread.debugreg1 = 0;
16191 tsk->thread.debugreg2 = 0;
16192@@ -307,7 +327,7 @@ void default_idle(void)
16193 EXPORT_SYMBOL(default_idle);
16194 #endif
16195
16196-void stop_this_cpu(void *dummy)
16197+__noreturn void stop_this_cpu(void *dummy)
16198 {
16199 local_irq_disable();
16200 /*
16201@@ -568,16 +588,35 @@ static int __init idle_setup(char *str)
16202 }
16203 early_param("idle", idle_setup);
16204
16205-unsigned long arch_align_stack(unsigned long sp)
16206+#ifdef CONFIG_PAX_RANDKSTACK
16207+asmlinkage void pax_randomize_kstack(void)
16208 {
16209- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16210- sp -= get_random_int() % 8192;
16211- return sp & ~0xf;
16212-}
16213+ struct thread_struct *thread = &current->thread;
16214+ unsigned long time;
16215
16216-unsigned long arch_randomize_brk(struct mm_struct *mm)
16217-{
16218- unsigned long range_end = mm->brk + 0x02000000;
16219- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16220+ if (!randomize_va_space)
16221+ return;
16222+
16223+ rdtscl(time);
16224+
16225+ /* P4 seems to return a 0 LSB, ignore it */
16226+#ifdef CONFIG_MPENTIUM4
16227+ time &= 0x3EUL;
16228+ time <<= 2;
16229+#elif defined(CONFIG_X86_64)
16230+ time &= 0xFUL;
16231+ time <<= 4;
16232+#else
16233+ time &= 0x1FUL;
16234+ time <<= 3;
16235+#endif
16236+
16237+ thread->sp0 ^= time;
16238+ load_sp0(init_tss + smp_processor_id(), thread);
16239+
16240+#ifdef CONFIG_X86_64
16241+ percpu_write(kernel_stack, thread->sp0);
16242+#endif
16243 }
16244+#endif
16245
16246diff -urNp linux-2.6.32.44/arch/x86/kernel/ptrace.c linux-2.6.32.44/arch/x86/kernel/ptrace.c
16247--- linux-2.6.32.44/arch/x86/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
16248+++ linux-2.6.32.44/arch/x86/kernel/ptrace.c 2011-04-17 15:56:46.000000000 -0400
16249@@ -925,7 +925,7 @@ static const struct user_regset_view use
16250 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
16251 {
16252 int ret;
16253- unsigned long __user *datap = (unsigned long __user *)data;
16254+ unsigned long __user *datap = (__force unsigned long __user *)data;
16255
16256 switch (request) {
16257 /* read the word at location addr in the USER area. */
16258@@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *chi
16259 if (addr < 0)
16260 return -EIO;
16261 ret = do_get_thread_area(child, addr,
16262- (struct user_desc __user *) data);
16263+ (__force struct user_desc __user *) data);
16264 break;
16265
16266 case PTRACE_SET_THREAD_AREA:
16267 if (addr < 0)
16268 return -EIO;
16269 ret = do_set_thread_area(child, addr,
16270- (struct user_desc __user *) data, 0);
16271+ (__force struct user_desc __user *) data, 0);
16272 break;
16273 #endif
16274
16275@@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *chi
16276 #ifdef CONFIG_X86_PTRACE_BTS
16277 case PTRACE_BTS_CONFIG:
16278 ret = ptrace_bts_config
16279- (child, data, (struct ptrace_bts_config __user *)addr);
16280+ (child, data, (__force struct ptrace_bts_config __user *)addr);
16281 break;
16282
16283 case PTRACE_BTS_STATUS:
16284 ret = ptrace_bts_status
16285- (child, data, (struct ptrace_bts_config __user *)addr);
16286+ (child, data, (__force struct ptrace_bts_config __user *)addr);
16287 break;
16288
16289 case PTRACE_BTS_SIZE:
16290@@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *chi
16291
16292 case PTRACE_BTS_GET:
16293 ret = ptrace_bts_read_record
16294- (child, data, (struct bts_struct __user *) addr);
16295+ (child, data, (__force struct bts_struct __user *) addr);
16296 break;
16297
16298 case PTRACE_BTS_CLEAR:
16299@@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *chi
16300
16301 case PTRACE_BTS_DRAIN:
16302 ret = ptrace_bts_drain
16303- (child, data, (struct bts_struct __user *) addr);
16304+ (child, data, (__force struct bts_struct __user *) addr);
16305 break;
16306 #endif /* CONFIG_X86_PTRACE_BTS */
16307
16308@@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *ts
16309 info.si_code = si_code;
16310
16311 /* User-mode ip? */
16312- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
16313+ info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
16314
16315 /* Send us the fake SIGTRAP */
16316 force_sig_info(SIGTRAP, &info, tsk);
16317@@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *ts
16318 * We must return the syscall number to actually look up in the table.
16319 * This can be -1L to skip running any syscall at all.
16320 */
16321-asmregparm long syscall_trace_enter(struct pt_regs *regs)
16322+long syscall_trace_enter(struct pt_regs *regs)
16323 {
16324 long ret = 0;
16325
16326@@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(stru
16327 return ret ?: regs->orig_ax;
16328 }
16329
16330-asmregparm void syscall_trace_leave(struct pt_regs *regs)
16331+void syscall_trace_leave(struct pt_regs *regs)
16332 {
16333 if (unlikely(current->audit_context))
16334 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
16335diff -urNp linux-2.6.32.44/arch/x86/kernel/reboot.c linux-2.6.32.44/arch/x86/kernel/reboot.c
16336--- linux-2.6.32.44/arch/x86/kernel/reboot.c 2011-08-09 18:35:28.000000000 -0400
16337+++ linux-2.6.32.44/arch/x86/kernel/reboot.c 2011-08-09 18:33:59.000000000 -0400
16338@@ -33,7 +33,7 @@ void (*pm_power_off)(void);
16339 EXPORT_SYMBOL(pm_power_off);
16340
16341 static const struct desc_ptr no_idt = {};
16342-static int reboot_mode;
16343+static unsigned short reboot_mode;
16344 enum reboot_type reboot_type = BOOT_KBD;
16345 int reboot_force;
16346
16347@@ -292,12 +292,12 @@ core_initcall(reboot_init);
16348 controller to pulse the CPU reset line, which is more thorough, but
16349 doesn't work with at least one type of 486 motherboard. It is easy
16350 to stop this code working; hence the copious comments. */
16351-static const unsigned long long
16352-real_mode_gdt_entries [3] =
16353+static struct desc_struct
16354+real_mode_gdt_entries [3] __read_only =
16355 {
16356- 0x0000000000000000ULL, /* Null descriptor */
16357- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
16358- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
16359+ GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
16360+ GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
16361+ GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
16362 };
16363
16364 static const struct desc_ptr
16365@@ -346,7 +346,7 @@ static const unsigned char jump_to_bios
16366 * specified by the code and length parameters.
16367 * We assume that length will aways be less that 100!
16368 */
16369-void machine_real_restart(const unsigned char *code, int length)
16370+__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
16371 {
16372 local_irq_disable();
16373
16374@@ -366,8 +366,8 @@ void machine_real_restart(const unsigned
16375 /* Remap the kernel at virtual address zero, as well as offset zero
16376 from the kernel segment. This assumes the kernel segment starts at
16377 virtual address PAGE_OFFSET. */
16378- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16379- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
16380+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16381+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
16382
16383 /*
16384 * Use `swapper_pg_dir' as our page directory.
16385@@ -379,16 +379,15 @@ void machine_real_restart(const unsigned
16386 boot)". This seems like a fairly standard thing that gets set by
16387 REBOOT.COM programs, and the previous reset routine did this
16388 too. */
16389- *((unsigned short *)0x472) = reboot_mode;
16390+ *(unsigned short *)(__va(0x472)) = reboot_mode;
16391
16392 /* For the switch to real mode, copy some code to low memory. It has
16393 to be in the first 64k because it is running in 16-bit mode, and it
16394 has to have the same physical and virtual address, because it turns
16395 off paging. Copy it near the end of the first page, out of the way
16396 of BIOS variables. */
16397- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
16398- real_mode_switch, sizeof (real_mode_switch));
16399- memcpy((void *)(0x1000 - 100), code, length);
16400+ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
16401+ memcpy(__va(0x1000 - 100), code, length);
16402
16403 /* Set up the IDT for real mode. */
16404 load_idt(&real_mode_idt);
16405@@ -416,6 +415,7 @@ void machine_real_restart(const unsigned
16406 __asm__ __volatile__ ("ljmp $0x0008,%0"
16407 :
16408 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
16409+ do { } while (1);
16410 }
16411 #ifdef CONFIG_APM_MODULE
16412 EXPORT_SYMBOL(machine_real_restart);
16413@@ -544,7 +544,7 @@ void __attribute__((weak)) mach_reboot_f
16414 {
16415 }
16416
16417-static void native_machine_emergency_restart(void)
16418+__noreturn static void native_machine_emergency_restart(void)
16419 {
16420 int i;
16421
16422@@ -659,13 +659,13 @@ void native_machine_shutdown(void)
16423 #endif
16424 }
16425
16426-static void __machine_emergency_restart(int emergency)
16427+static __noreturn void __machine_emergency_restart(int emergency)
16428 {
16429 reboot_emergency = emergency;
16430 machine_ops.emergency_restart();
16431 }
16432
16433-static void native_machine_restart(char *__unused)
16434+static __noreturn void native_machine_restart(char *__unused)
16435 {
16436 printk("machine restart\n");
16437
16438@@ -674,7 +674,7 @@ static void native_machine_restart(char
16439 __machine_emergency_restart(0);
16440 }
16441
16442-static void native_machine_halt(void)
16443+static __noreturn void native_machine_halt(void)
16444 {
16445 /* stop other cpus and apics */
16446 machine_shutdown();
16447@@ -685,7 +685,7 @@ static void native_machine_halt(void)
16448 stop_this_cpu(NULL);
16449 }
16450
16451-static void native_machine_power_off(void)
16452+__noreturn static void native_machine_power_off(void)
16453 {
16454 if (pm_power_off) {
16455 if (!reboot_force)
16456@@ -694,6 +694,7 @@ static void native_machine_power_off(voi
16457 }
16458 /* a fallback in case there is no PM info available */
16459 tboot_shutdown(TB_SHUTDOWN_HALT);
16460+ do { } while (1);
16461 }
16462
16463 struct machine_ops machine_ops = {
16464diff -urNp linux-2.6.32.44/arch/x86/kernel/setup.c linux-2.6.32.44/arch/x86/kernel/setup.c
16465--- linux-2.6.32.44/arch/x86/kernel/setup.c 2011-04-17 17:00:52.000000000 -0400
16466+++ linux-2.6.32.44/arch/x86/kernel/setup.c 2011-04-17 17:03:05.000000000 -0400
16467@@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
16468
16469 if (!boot_params.hdr.root_flags)
16470 root_mountflags &= ~MS_RDONLY;
16471- init_mm.start_code = (unsigned long) _text;
16472- init_mm.end_code = (unsigned long) _etext;
16473+ init_mm.start_code = ktla_ktva((unsigned long) _text);
16474+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
16475 init_mm.end_data = (unsigned long) _edata;
16476 init_mm.brk = _brk_end;
16477
16478- code_resource.start = virt_to_phys(_text);
16479- code_resource.end = virt_to_phys(_etext)-1;
16480- data_resource.start = virt_to_phys(_etext);
16481+ code_resource.start = virt_to_phys(ktla_ktva(_text));
16482+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16483+ data_resource.start = virt_to_phys(_sdata);
16484 data_resource.end = virt_to_phys(_edata)-1;
16485 bss_resource.start = virt_to_phys(&__bss_start);
16486 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16487diff -urNp linux-2.6.32.44/arch/x86/kernel/setup_percpu.c linux-2.6.32.44/arch/x86/kernel/setup_percpu.c
16488--- linux-2.6.32.44/arch/x86/kernel/setup_percpu.c 2011-03-27 14:31:47.000000000 -0400
16489+++ linux-2.6.32.44/arch/x86/kernel/setup_percpu.c 2011-06-04 20:36:29.000000000 -0400
16490@@ -25,19 +25,17 @@
16491 # define DBG(x...)
16492 #endif
16493
16494-DEFINE_PER_CPU(int, cpu_number);
16495+#ifdef CONFIG_SMP
16496+DEFINE_PER_CPU(unsigned int, cpu_number);
16497 EXPORT_PER_CPU_SYMBOL(cpu_number);
16498+#endif
16499
16500-#ifdef CONFIG_X86_64
16501 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16502-#else
16503-#define BOOT_PERCPU_OFFSET 0
16504-#endif
16505
16506 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16507 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16508
16509-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16510+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16511 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
16512 };
16513 EXPORT_SYMBOL(__per_cpu_offset);
16514@@ -159,10 +157,10 @@ static inline void setup_percpu_segment(
16515 {
16516 #ifdef CONFIG_X86_32
16517 struct desc_struct gdt;
16518+ unsigned long base = per_cpu_offset(cpu);
16519
16520- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
16521- 0x2 | DESCTYPE_S, 0x8);
16522- gdt.s = 1;
16523+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
16524+ 0x83 | DESCTYPE_S, 0xC);
16525 write_gdt_entry(get_cpu_gdt_table(cpu),
16526 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
16527 #endif
16528@@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
16529 /* alrighty, percpu areas up and running */
16530 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
16531 for_each_possible_cpu(cpu) {
16532+#ifdef CONFIG_CC_STACKPROTECTOR
16533+#ifdef CONFIG_X86_32
16534+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
16535+#endif
16536+#endif
16537 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
16538 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
16539 per_cpu(cpu_number, cpu) = cpu;
16540@@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
16541 early_per_cpu_map(x86_cpu_to_node_map, cpu);
16542 #endif
16543 #endif
16544+#ifdef CONFIG_CC_STACKPROTECTOR
16545+#ifdef CONFIG_X86_32
16546+ if (!cpu)
16547+ per_cpu(stack_canary.canary, cpu) = canary;
16548+#endif
16549+#endif
16550 /*
16551 * Up to this point, the boot CPU has been using .data.init
16552 * area. Reload any changed state for the boot CPU.
16553diff -urNp linux-2.6.32.44/arch/x86/kernel/signal.c linux-2.6.32.44/arch/x86/kernel/signal.c
16554--- linux-2.6.32.44/arch/x86/kernel/signal.c 2011-03-27 14:31:47.000000000 -0400
16555+++ linux-2.6.32.44/arch/x86/kernel/signal.c 2011-05-22 23:02:03.000000000 -0400
16556@@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsi
16557 * Align the stack pointer according to the i386 ABI,
16558 * i.e. so that on function entry ((sp + 4) & 15) == 0.
16559 */
16560- sp = ((sp + 4) & -16ul) - 4;
16561+ sp = ((sp - 12) & -16ul) - 4;
16562 #else /* !CONFIG_X86_32 */
16563 sp = round_down(sp, 16) - 8;
16564 #endif
16565@@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, str
16566 * Return an always-bogus address instead so we will die with SIGSEGV.
16567 */
16568 if (onsigstack && !likely(on_sig_stack(sp)))
16569- return (void __user *)-1L;
16570+ return (__force void __user *)-1L;
16571
16572 /* save i387 state */
16573 if (used_math() && save_i387_xstate(*fpstate) < 0)
16574- return (void __user *)-1L;
16575+ return (__force void __user *)-1L;
16576
16577 return (void __user *)sp;
16578 }
16579@@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigactio
16580 }
16581
16582 if (current->mm->context.vdso)
16583- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16584+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16585 else
16586- restorer = &frame->retcode;
16587+ restorer = (void __user *)&frame->retcode;
16588 if (ka->sa.sa_flags & SA_RESTORER)
16589 restorer = ka->sa.sa_restorer;
16590
16591@@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigactio
16592 * reasons and because gdb uses it as a signature to notice
16593 * signal handler stack frames.
16594 */
16595- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
16596+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
16597
16598 if (err)
16599 return -EFAULT;
16600@@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, str
16601 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
16602
16603 /* Set up to return from userspace. */
16604- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16605+ if (current->mm->context.vdso)
16606+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16607+ else
16608+ restorer = (void __user *)&frame->retcode;
16609 if (ka->sa.sa_flags & SA_RESTORER)
16610 restorer = ka->sa.sa_restorer;
16611 put_user_ex(restorer, &frame->pretcode);
16612@@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, str
16613 * reasons and because gdb uses it as a signature to notice
16614 * signal handler stack frames.
16615 */
16616- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
16617+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
16618 } put_user_catch(err);
16619
16620 if (err)
16621@@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *re
16622 int signr;
16623 sigset_t *oldset;
16624
16625+ pax_track_stack();
16626+
16627 /*
16628 * We want the common case to go fast, which is why we may in certain
16629 * cases get here from kernel mode. Just return without doing anything
16630@@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *re
16631 * X86_32: vm86 regs switched out by assembly code before reaching
16632 * here, so testing against kernel CS suffices.
16633 */
16634- if (!user_mode(regs))
16635+ if (!user_mode_novm(regs))
16636 return;
16637
16638 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
16639diff -urNp linux-2.6.32.44/arch/x86/kernel/smpboot.c linux-2.6.32.44/arch/x86/kernel/smpboot.c
16640--- linux-2.6.32.44/arch/x86/kernel/smpboot.c 2011-03-27 14:31:47.000000000 -0400
16641+++ linux-2.6.32.44/arch/x86/kernel/smpboot.c 2011-07-01 19:10:03.000000000 -0400
16642@@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct
16643 */
16644 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
16645
16646-void cpu_hotplug_driver_lock()
16647+void cpu_hotplug_driver_lock(void)
16648 {
16649- mutex_lock(&x86_cpu_hotplug_driver_mutex);
16650+ mutex_lock(&x86_cpu_hotplug_driver_mutex);
16651 }
16652
16653-void cpu_hotplug_driver_unlock()
16654+void cpu_hotplug_driver_unlock(void)
16655 {
16656- mutex_unlock(&x86_cpu_hotplug_driver_mutex);
16657+ mutex_unlock(&x86_cpu_hotplug_driver_mutex);
16658 }
16659
16660 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
16661@@ -625,7 +625,7 @@ wakeup_secondary_cpu_via_init(int phys_a
16662 * target processor state.
16663 */
16664 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
16665- (unsigned long)stack_start.sp);
16666+ stack_start);
16667
16668 /*
16669 * Run STARTUP IPI loop.
16670@@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int api
16671 set_idle_for_cpu(cpu, c_idle.idle);
16672 do_rest:
16673 per_cpu(current_task, cpu) = c_idle.idle;
16674+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
16675 #ifdef CONFIG_X86_32
16676 /* Stack for startup_32 can be just as for start_secondary onwards */
16677 irq_ctx_init(cpu);
16678@@ -750,13 +751,15 @@ do_rest:
16679 #else
16680 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
16681 initial_gs = per_cpu_offset(cpu);
16682- per_cpu(kernel_stack, cpu) =
16683- (unsigned long)task_stack_page(c_idle.idle) -
16684- KERNEL_STACK_OFFSET + THREAD_SIZE;
16685+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
16686 #endif
16687+
16688+ pax_open_kernel();
16689 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16690+ pax_close_kernel();
16691+
16692 initial_code = (unsigned long)start_secondary;
16693- stack_start.sp = (void *) c_idle.idle->thread.sp;
16694+ stack_start = c_idle.idle->thread.sp;
16695
16696 /* start_ip had better be page-aligned! */
16697 start_ip = setup_trampoline();
16698@@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int
16699
16700 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
16701
16702+#ifdef CONFIG_PAX_PER_CPU_PGD
16703+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
16704+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16705+ KERNEL_PGD_PTRS);
16706+#endif
16707+
16708 err = do_boot_cpu(apicid, cpu);
16709
16710 if (err) {
16711diff -urNp linux-2.6.32.44/arch/x86/kernel/step.c linux-2.6.32.44/arch/x86/kernel/step.c
16712--- linux-2.6.32.44/arch/x86/kernel/step.c 2011-03-27 14:31:47.000000000 -0400
16713+++ linux-2.6.32.44/arch/x86/kernel/step.c 2011-04-17 15:56:46.000000000 -0400
16714@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
16715 struct desc_struct *desc;
16716 unsigned long base;
16717
16718- seg &= ~7UL;
16719+ seg >>= 3;
16720
16721 mutex_lock(&child->mm->context.lock);
16722- if (unlikely((seg >> 3) >= child->mm->context.size))
16723+ if (unlikely(seg >= child->mm->context.size))
16724 addr = -1L; /* bogus selector, access would fault */
16725 else {
16726 desc = child->mm->context.ldt + seg;
16727@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
16728 addr += base;
16729 }
16730 mutex_unlock(&child->mm->context.lock);
16731- }
16732+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
16733+ addr = ktla_ktva(addr);
16734
16735 return addr;
16736 }
16737@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
16738 unsigned char opcode[15];
16739 unsigned long addr = convert_ip_to_linear(child, regs);
16740
16741+ if (addr == -EINVAL)
16742+ return 0;
16743+
16744 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
16745 for (i = 0; i < copied; i++) {
16746 switch (opcode[i]) {
16747@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
16748
16749 #ifdef CONFIG_X86_64
16750 case 0x40 ... 0x4f:
16751- if (regs->cs != __USER_CS)
16752+ if ((regs->cs & 0xffff) != __USER_CS)
16753 /* 32-bit mode: register increment */
16754 return 0;
16755 /* 64-bit mode: REX prefix */
16756diff -urNp linux-2.6.32.44/arch/x86/kernel/syscall_table_32.S linux-2.6.32.44/arch/x86/kernel/syscall_table_32.S
16757--- linux-2.6.32.44/arch/x86/kernel/syscall_table_32.S 2011-03-27 14:31:47.000000000 -0400
16758+++ linux-2.6.32.44/arch/x86/kernel/syscall_table_32.S 2011-04-17 15:56:46.000000000 -0400
16759@@ -1,3 +1,4 @@
16760+.section .rodata,"a",@progbits
16761 ENTRY(sys_call_table)
16762 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
16763 .long sys_exit
16764diff -urNp linux-2.6.32.44/arch/x86/kernel/sys_i386_32.c linux-2.6.32.44/arch/x86/kernel/sys_i386_32.c
16765--- linux-2.6.32.44/arch/x86/kernel/sys_i386_32.c 2011-03-27 14:31:47.000000000 -0400
16766+++ linux-2.6.32.44/arch/x86/kernel/sys_i386_32.c 2011-04-17 15:56:46.000000000 -0400
16767@@ -24,6 +24,21 @@
16768
16769 #include <asm/syscalls.h>
16770
16771+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
16772+{
16773+ unsigned long pax_task_size = TASK_SIZE;
16774+
16775+#ifdef CONFIG_PAX_SEGMEXEC
16776+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
16777+ pax_task_size = SEGMEXEC_TASK_SIZE;
16778+#endif
16779+
16780+ if (len > pax_task_size || addr > pax_task_size - len)
16781+ return -EINVAL;
16782+
16783+ return 0;
16784+}
16785+
16786 /*
16787 * Perform the select(nd, in, out, ex, tv) and mmap() system
16788 * calls. Linux/i386 didn't use to be able to handle more than
16789@@ -58,6 +73,212 @@ out:
16790 return err;
16791 }
16792
16793+unsigned long
16794+arch_get_unmapped_area(struct file *filp, unsigned long addr,
16795+ unsigned long len, unsigned long pgoff, unsigned long flags)
16796+{
16797+ struct mm_struct *mm = current->mm;
16798+ struct vm_area_struct *vma;
16799+ unsigned long start_addr, pax_task_size = TASK_SIZE;
16800+
16801+#ifdef CONFIG_PAX_SEGMEXEC
16802+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16803+ pax_task_size = SEGMEXEC_TASK_SIZE;
16804+#endif
16805+
16806+ pax_task_size -= PAGE_SIZE;
16807+
16808+ if (len > pax_task_size)
16809+ return -ENOMEM;
16810+
16811+ if (flags & MAP_FIXED)
16812+ return addr;
16813+
16814+#ifdef CONFIG_PAX_RANDMMAP
16815+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16816+#endif
16817+
16818+ if (addr) {
16819+ addr = PAGE_ALIGN(addr);
16820+ if (pax_task_size - len >= addr) {
16821+ vma = find_vma(mm, addr);
16822+ if (check_heap_stack_gap(vma, addr, len))
16823+ return addr;
16824+ }
16825+ }
16826+ if (len > mm->cached_hole_size) {
16827+ start_addr = addr = mm->free_area_cache;
16828+ } else {
16829+ start_addr = addr = mm->mmap_base;
16830+ mm->cached_hole_size = 0;
16831+ }
16832+
16833+#ifdef CONFIG_PAX_PAGEEXEC
16834+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
16835+ start_addr = 0x00110000UL;
16836+
16837+#ifdef CONFIG_PAX_RANDMMAP
16838+ if (mm->pax_flags & MF_PAX_RANDMMAP)
16839+ start_addr += mm->delta_mmap & 0x03FFF000UL;
16840+#endif
16841+
16842+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
16843+ start_addr = addr = mm->mmap_base;
16844+ else
16845+ addr = start_addr;
16846+ }
16847+#endif
16848+
16849+full_search:
16850+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
16851+ /* At this point: (!vma || addr < vma->vm_end). */
16852+ if (pax_task_size - len < addr) {
16853+ /*
16854+ * Start a new search - just in case we missed
16855+ * some holes.
16856+ */
16857+ if (start_addr != mm->mmap_base) {
16858+ start_addr = addr = mm->mmap_base;
16859+ mm->cached_hole_size = 0;
16860+ goto full_search;
16861+ }
16862+ return -ENOMEM;
16863+ }
16864+ if (check_heap_stack_gap(vma, addr, len))
16865+ break;
16866+ if (addr + mm->cached_hole_size < vma->vm_start)
16867+ mm->cached_hole_size = vma->vm_start - addr;
16868+ addr = vma->vm_end;
16869+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
16870+ start_addr = addr = mm->mmap_base;
16871+ mm->cached_hole_size = 0;
16872+ goto full_search;
16873+ }
16874+ }
16875+
16876+ /*
16877+ * Remember the place where we stopped the search:
16878+ */
16879+ mm->free_area_cache = addr + len;
16880+ return addr;
16881+}
16882+
16883+unsigned long
16884+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
16885+ const unsigned long len, const unsigned long pgoff,
16886+ const unsigned long flags)
16887+{
16888+ struct vm_area_struct *vma;
16889+ struct mm_struct *mm = current->mm;
16890+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
16891+
16892+#ifdef CONFIG_PAX_SEGMEXEC
16893+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16894+ pax_task_size = SEGMEXEC_TASK_SIZE;
16895+#endif
16896+
16897+ pax_task_size -= PAGE_SIZE;
16898+
16899+ /* requested length too big for entire address space */
16900+ if (len > pax_task_size)
16901+ return -ENOMEM;
16902+
16903+ if (flags & MAP_FIXED)
16904+ return addr;
16905+
16906+#ifdef CONFIG_PAX_PAGEEXEC
16907+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
16908+ goto bottomup;
16909+#endif
16910+
16911+#ifdef CONFIG_PAX_RANDMMAP
16912+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16913+#endif
16914+
16915+ /* requesting a specific address */
16916+ if (addr) {
16917+ addr = PAGE_ALIGN(addr);
16918+ if (pax_task_size - len >= addr) {
16919+ vma = find_vma(mm, addr);
16920+ if (check_heap_stack_gap(vma, addr, len))
16921+ return addr;
16922+ }
16923+ }
16924+
16925+ /* check if free_area_cache is useful for us */
16926+ if (len <= mm->cached_hole_size) {
16927+ mm->cached_hole_size = 0;
16928+ mm->free_area_cache = mm->mmap_base;
16929+ }
16930+
16931+ /* either no address requested or can't fit in requested address hole */
16932+ addr = mm->free_area_cache;
16933+
16934+ /* make sure it can fit in the remaining address space */
16935+ if (addr > len) {
16936+ vma = find_vma(mm, addr-len);
16937+ if (check_heap_stack_gap(vma, addr - len, len))
16938+ /* remember the address as a hint for next time */
16939+ return (mm->free_area_cache = addr-len);
16940+ }
16941+
16942+ if (mm->mmap_base < len)
16943+ goto bottomup;
16944+
16945+ addr = mm->mmap_base-len;
16946+
16947+ do {
16948+ /*
16949+ * Lookup failure means no vma is above this address,
16950+ * else if new region fits below vma->vm_start,
16951+ * return with success:
16952+ */
16953+ vma = find_vma(mm, addr);
16954+ if (check_heap_stack_gap(vma, addr, len))
16955+ /* remember the address as a hint for next time */
16956+ return (mm->free_area_cache = addr);
16957+
16958+ /* remember the largest hole we saw so far */
16959+ if (addr + mm->cached_hole_size < vma->vm_start)
16960+ mm->cached_hole_size = vma->vm_start - addr;
16961+
16962+ /* try just below the current vma->vm_start */
16963+ addr = skip_heap_stack_gap(vma, len);
16964+ } while (!IS_ERR_VALUE(addr));
16965+
16966+bottomup:
16967+ /*
16968+ * A failed mmap() very likely causes application failure,
16969+ * so fall back to the bottom-up function here. This scenario
16970+ * can happen with large stack limits and large mmap()
16971+ * allocations.
16972+ */
16973+
16974+#ifdef CONFIG_PAX_SEGMEXEC
16975+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16976+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
16977+ else
16978+#endif
16979+
16980+ mm->mmap_base = TASK_UNMAPPED_BASE;
16981+
16982+#ifdef CONFIG_PAX_RANDMMAP
16983+ if (mm->pax_flags & MF_PAX_RANDMMAP)
16984+ mm->mmap_base += mm->delta_mmap;
16985+#endif
16986+
16987+ mm->free_area_cache = mm->mmap_base;
16988+ mm->cached_hole_size = ~0UL;
16989+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
16990+ /*
16991+ * Restore the topdown base:
16992+ */
16993+ mm->mmap_base = base;
16994+ mm->free_area_cache = base;
16995+ mm->cached_hole_size = ~0UL;
16996+
16997+ return addr;
16998+}
16999
17000 struct sel_arg_struct {
17001 unsigned long n;
17002@@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int fi
17003 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
17004 case SEMTIMEDOP:
17005 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
17006- (const struct timespec __user *)fifth);
17007+ (__force const struct timespec __user *)fifth);
17008
17009 case SEMGET:
17010 return sys_semget(first, second, third);
17011@@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int fi
17012 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
17013 if (ret)
17014 return ret;
17015- return put_user(raddr, (ulong __user *) third);
17016+ return put_user(raddr, (__force ulong __user *) third);
17017 }
17018 case 1: /* iBCS2 emulator entry point */
17019 if (!segment_eq(get_fs(), get_ds()))
17020@@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldol
17021
17022 return error;
17023 }
17024-
17025-
17026-/*
17027- * Do a system call from kernel instead of calling sys_execve so we
17028- * end up with proper pt_regs.
17029- */
17030-int kernel_execve(const char *filename, char *const argv[], char *const envp[])
17031-{
17032- long __res;
17033- asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
17034- : "=a" (__res)
17035- : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
17036- return __res;
17037-}
17038diff -urNp linux-2.6.32.44/arch/x86/kernel/sys_x86_64.c linux-2.6.32.44/arch/x86/kernel/sys_x86_64.c
17039--- linux-2.6.32.44/arch/x86/kernel/sys_x86_64.c 2011-03-27 14:31:47.000000000 -0400
17040+++ linux-2.6.32.44/arch/x86/kernel/sys_x86_64.c 2011-04-17 15:56:46.000000000 -0400
17041@@ -32,8 +32,8 @@ out:
17042 return error;
17043 }
17044
17045-static void find_start_end(unsigned long flags, unsigned long *begin,
17046- unsigned long *end)
17047+static void find_start_end(struct mm_struct *mm, unsigned long flags,
17048+ unsigned long *begin, unsigned long *end)
17049 {
17050 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17051 unsigned long new_begin;
17052@@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17053 *begin = new_begin;
17054 }
17055 } else {
17056- *begin = TASK_UNMAPPED_BASE;
17057+ *begin = mm->mmap_base;
17058 *end = TASK_SIZE;
17059 }
17060 }
17061@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17062 if (flags & MAP_FIXED)
17063 return addr;
17064
17065- find_start_end(flags, &begin, &end);
17066+ find_start_end(mm, flags, &begin, &end);
17067
17068 if (len > end)
17069 return -ENOMEM;
17070
17071+#ifdef CONFIG_PAX_RANDMMAP
17072+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17073+#endif
17074+
17075 if (addr) {
17076 addr = PAGE_ALIGN(addr);
17077 vma = find_vma(mm, addr);
17078- if (end - len >= addr &&
17079- (!vma || addr + len <= vma->vm_start))
17080+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17081 return addr;
17082 }
17083 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17084@@ -106,7 +109,7 @@ full_search:
17085 }
17086 return -ENOMEM;
17087 }
17088- if (!vma || addr + len <= vma->vm_start) {
17089+ if (check_heap_stack_gap(vma, addr, len)) {
17090 /*
17091 * Remember the place where we stopped the search:
17092 */
17093@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17094 {
17095 struct vm_area_struct *vma;
17096 struct mm_struct *mm = current->mm;
17097- unsigned long addr = addr0;
17098+ unsigned long base = mm->mmap_base, addr = addr0;
17099
17100 /* requested length too big for entire address space */
17101 if (len > TASK_SIZE)
17102@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17103 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17104 goto bottomup;
17105
17106+#ifdef CONFIG_PAX_RANDMMAP
17107+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17108+#endif
17109+
17110 /* requesting a specific address */
17111 if (addr) {
17112 addr = PAGE_ALIGN(addr);
17113- vma = find_vma(mm, addr);
17114- if (TASK_SIZE - len >= addr &&
17115- (!vma || addr + len <= vma->vm_start))
17116- return addr;
17117+ if (TASK_SIZE - len >= addr) {
17118+ vma = find_vma(mm, addr);
17119+ if (check_heap_stack_gap(vma, addr, len))
17120+ return addr;
17121+ }
17122 }
17123
17124 /* check if free_area_cache is useful for us */
17125@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17126 /* make sure it can fit in the remaining address space */
17127 if (addr > len) {
17128 vma = find_vma(mm, addr-len);
17129- if (!vma || addr <= vma->vm_start)
17130+ if (check_heap_stack_gap(vma, addr - len, len))
17131 /* remember the address as a hint for next time */
17132 return mm->free_area_cache = addr-len;
17133 }
17134@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17135 * return with success:
17136 */
17137 vma = find_vma(mm, addr);
17138- if (!vma || addr+len <= vma->vm_start)
17139+ if (check_heap_stack_gap(vma, addr, len))
17140 /* remember the address as a hint for next time */
17141 return mm->free_area_cache = addr;
17142
17143@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17144 mm->cached_hole_size = vma->vm_start - addr;
17145
17146 /* try just below the current vma->vm_start */
17147- addr = vma->vm_start-len;
17148- } while (len < vma->vm_start);
17149+ addr = skip_heap_stack_gap(vma, len);
17150+ } while (!IS_ERR_VALUE(addr));
17151
17152 bottomup:
17153 /*
17154@@ -198,13 +206,21 @@ bottomup:
17155 * can happen with large stack limits and large mmap()
17156 * allocations.
17157 */
17158+ mm->mmap_base = TASK_UNMAPPED_BASE;
17159+
17160+#ifdef CONFIG_PAX_RANDMMAP
17161+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17162+ mm->mmap_base += mm->delta_mmap;
17163+#endif
17164+
17165+ mm->free_area_cache = mm->mmap_base;
17166 mm->cached_hole_size = ~0UL;
17167- mm->free_area_cache = TASK_UNMAPPED_BASE;
17168 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17169 /*
17170 * Restore the topdown base:
17171 */
17172- mm->free_area_cache = mm->mmap_base;
17173+ mm->mmap_base = base;
17174+ mm->free_area_cache = base;
17175 mm->cached_hole_size = ~0UL;
17176
17177 return addr;
17178diff -urNp linux-2.6.32.44/arch/x86/kernel/tboot.c linux-2.6.32.44/arch/x86/kernel/tboot.c
17179--- linux-2.6.32.44/arch/x86/kernel/tboot.c 2011-03-27 14:31:47.000000000 -0400
17180+++ linux-2.6.32.44/arch/x86/kernel/tboot.c 2011-05-22 23:02:03.000000000 -0400
17181@@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
17182
17183 void tboot_shutdown(u32 shutdown_type)
17184 {
17185- void (*shutdown)(void);
17186+ void (* __noreturn shutdown)(void);
17187
17188 if (!tboot_enabled())
17189 return;
17190@@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
17191
17192 switch_to_tboot_pt();
17193
17194- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17195+ shutdown = (void *)tboot->shutdown_entry;
17196 shutdown();
17197
17198 /* should not reach here */
17199@@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17200 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17201 }
17202
17203-static atomic_t ap_wfs_count;
17204+static atomic_unchecked_t ap_wfs_count;
17205
17206 static int tboot_wait_for_aps(int num_aps)
17207 {
17208@@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(
17209 {
17210 switch (action) {
17211 case CPU_DYING:
17212- atomic_inc(&ap_wfs_count);
17213+ atomic_inc_unchecked(&ap_wfs_count);
17214 if (num_online_cpus() == 1)
17215- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17216+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17217 return NOTIFY_BAD;
17218 break;
17219 }
17220@@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
17221
17222 tboot_create_trampoline();
17223
17224- atomic_set(&ap_wfs_count, 0);
17225+ atomic_set_unchecked(&ap_wfs_count, 0);
17226 register_hotcpu_notifier(&tboot_cpu_notifier);
17227 return 0;
17228 }
17229diff -urNp linux-2.6.32.44/arch/x86/kernel/time.c linux-2.6.32.44/arch/x86/kernel/time.c
17230--- linux-2.6.32.44/arch/x86/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
17231+++ linux-2.6.32.44/arch/x86/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
17232@@ -26,17 +26,13 @@
17233 int timer_ack;
17234 #endif
17235
17236-#ifdef CONFIG_X86_64
17237-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17238-#endif
17239-
17240 unsigned long profile_pc(struct pt_regs *regs)
17241 {
17242 unsigned long pc = instruction_pointer(regs);
17243
17244- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17245+ if (!user_mode(regs) && in_lock_functions(pc)) {
17246 #ifdef CONFIG_FRAME_POINTER
17247- return *(unsigned long *)(regs->bp + sizeof(long));
17248+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17249 #else
17250 unsigned long *sp =
17251 (unsigned long *)kernel_stack_pointer(regs);
17252@@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
17253 * or above a saved flags. Eflags has bits 22-31 zero,
17254 * kernel addresses don't.
17255 */
17256+
17257+#ifdef CONFIG_PAX_KERNEXEC
17258+ return ktla_ktva(sp[0]);
17259+#else
17260 if (sp[0] >> 22)
17261 return sp[0];
17262 if (sp[1] >> 22)
17263 return sp[1];
17264 #endif
17265+
17266+#endif
17267 }
17268 return pc;
17269 }
17270diff -urNp linux-2.6.32.44/arch/x86/kernel/tls.c linux-2.6.32.44/arch/x86/kernel/tls.c
17271--- linux-2.6.32.44/arch/x86/kernel/tls.c 2011-03-27 14:31:47.000000000 -0400
17272+++ linux-2.6.32.44/arch/x86/kernel/tls.c 2011-04-17 15:56:46.000000000 -0400
17273@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17274 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17275 return -EINVAL;
17276
17277+#ifdef CONFIG_PAX_SEGMEXEC
17278+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17279+ return -EINVAL;
17280+#endif
17281+
17282 set_tls_desc(p, idx, &info, 1);
17283
17284 return 0;
17285diff -urNp linux-2.6.32.44/arch/x86/kernel/trampoline_32.S linux-2.6.32.44/arch/x86/kernel/trampoline_32.S
17286--- linux-2.6.32.44/arch/x86/kernel/trampoline_32.S 2011-03-27 14:31:47.000000000 -0400
17287+++ linux-2.6.32.44/arch/x86/kernel/trampoline_32.S 2011-04-17 15:56:46.000000000 -0400
17288@@ -32,6 +32,12 @@
17289 #include <asm/segment.h>
17290 #include <asm/page_types.h>
17291
17292+#ifdef CONFIG_PAX_KERNEXEC
17293+#define ta(X) (X)
17294+#else
17295+#define ta(X) ((X) - __PAGE_OFFSET)
17296+#endif
17297+
17298 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
17299 __CPUINITRODATA
17300 .code16
17301@@ -60,7 +66,7 @@ r_base = .
17302 inc %ax # protected mode (PE) bit
17303 lmsw %ax # into protected mode
17304 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17305- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17306+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
17307
17308 # These need to be in the same 64K segment as the above;
17309 # hence we don't use the boot_gdt_descr defined in head.S
17310diff -urNp linux-2.6.32.44/arch/x86/kernel/trampoline_64.S linux-2.6.32.44/arch/x86/kernel/trampoline_64.S
17311--- linux-2.6.32.44/arch/x86/kernel/trampoline_64.S 2011-03-27 14:31:47.000000000 -0400
17312+++ linux-2.6.32.44/arch/x86/kernel/trampoline_64.S 2011-07-01 18:53:26.000000000 -0400
17313@@ -91,7 +91,7 @@ startup_32:
17314 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17315 movl %eax, %ds
17316
17317- movl $X86_CR4_PAE, %eax
17318+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17319 movl %eax, %cr4 # Enable PAE mode
17320
17321 # Setup trampoline 4 level pagetables
17322@@ -127,7 +127,7 @@ startup_64:
17323 no_longmode:
17324 hlt
17325 jmp no_longmode
17326-#include "verify_cpu_64.S"
17327+#include "verify_cpu.S"
17328
17329 # Careful these need to be in the same 64K segment as the above;
17330 tidt:
17331@@ -138,7 +138,7 @@ tidt:
17332 # so the kernel can live anywhere
17333 .balign 4
17334 tgdt:
17335- .short tgdt_end - tgdt # gdt limit
17336+ .short tgdt_end - tgdt - 1 # gdt limit
17337 .long tgdt - r_base
17338 .short 0
17339 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17340diff -urNp linux-2.6.32.44/arch/x86/kernel/traps.c linux-2.6.32.44/arch/x86/kernel/traps.c
17341--- linux-2.6.32.44/arch/x86/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
17342+++ linux-2.6.32.44/arch/x86/kernel/traps.c 2011-07-06 19:53:33.000000000 -0400
17343@@ -69,12 +69,6 @@ asmlinkage int system_call(void);
17344
17345 /* Do we ignore FPU interrupts ? */
17346 char ignore_fpu_irq;
17347-
17348-/*
17349- * The IDT has to be page-aligned to simplify the Pentium
17350- * F0 0F bug workaround.
17351- */
17352-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17353 #endif
17354
17355 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17356@@ -112,19 +106,19 @@ static inline void preempt_conditional_c
17357 static inline void
17358 die_if_kernel(const char *str, struct pt_regs *regs, long err)
17359 {
17360- if (!user_mode_vm(regs))
17361+ if (!user_mode(regs))
17362 die(str, regs, err);
17363 }
17364 #endif
17365
17366 static void __kprobes
17367-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17368+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17369 long error_code, siginfo_t *info)
17370 {
17371 struct task_struct *tsk = current;
17372
17373 #ifdef CONFIG_X86_32
17374- if (regs->flags & X86_VM_MASK) {
17375+ if (v8086_mode(regs)) {
17376 /*
17377 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17378 * On nmi (interrupt 2), do_trap should not be called.
17379@@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str
17380 }
17381 #endif
17382
17383- if (!user_mode(regs))
17384+ if (!user_mode_novm(regs))
17385 goto kernel_trap;
17386
17387 #ifdef CONFIG_X86_32
17388@@ -158,7 +152,7 @@ trap_signal:
17389 printk_ratelimit()) {
17390 printk(KERN_INFO
17391 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17392- tsk->comm, tsk->pid, str,
17393+ tsk->comm, task_pid_nr(tsk), str,
17394 regs->ip, regs->sp, error_code);
17395 print_vma_addr(" in ", regs->ip);
17396 printk("\n");
17397@@ -175,8 +169,20 @@ kernel_trap:
17398 if (!fixup_exception(regs)) {
17399 tsk->thread.error_code = error_code;
17400 tsk->thread.trap_no = trapnr;
17401+
17402+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17403+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17404+ str = "PAX: suspicious stack segment fault";
17405+#endif
17406+
17407 die(str, regs, error_code);
17408 }
17409+
17410+#ifdef CONFIG_PAX_REFCOUNT
17411+ if (trapnr == 4)
17412+ pax_report_refcount_overflow(regs);
17413+#endif
17414+
17415 return;
17416
17417 #ifdef CONFIG_X86_32
17418@@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *re
17419 conditional_sti(regs);
17420
17421 #ifdef CONFIG_X86_32
17422- if (regs->flags & X86_VM_MASK)
17423+ if (v8086_mode(regs))
17424 goto gp_in_vm86;
17425 #endif
17426
17427 tsk = current;
17428- if (!user_mode(regs))
17429+ if (!user_mode_novm(regs))
17430 goto gp_in_kernel;
17431
17432+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17433+ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17434+ struct mm_struct *mm = tsk->mm;
17435+ unsigned long limit;
17436+
17437+ down_write(&mm->mmap_sem);
17438+ limit = mm->context.user_cs_limit;
17439+ if (limit < TASK_SIZE) {
17440+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17441+ up_write(&mm->mmap_sem);
17442+ return;
17443+ }
17444+ up_write(&mm->mmap_sem);
17445+ }
17446+#endif
17447+
17448 tsk->thread.error_code = error_code;
17449 tsk->thread.trap_no = 13;
17450
17451@@ -305,6 +327,13 @@ gp_in_kernel:
17452 if (notify_die(DIE_GPF, "general protection fault", regs,
17453 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17454 return;
17455+
17456+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17457+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17458+ die("PAX: suspicious general protection fault", regs, error_code);
17459+ else
17460+#endif
17461+
17462 die("general protection fault", regs, error_code);
17463 }
17464
17465@@ -435,6 +464,17 @@ static notrace __kprobes void default_do
17466 dotraplinkage notrace __kprobes void
17467 do_nmi(struct pt_regs *regs, long error_code)
17468 {
17469+
17470+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17471+ if (!user_mode(regs)) {
17472+ unsigned long cs = regs->cs & 0xFFFF;
17473+ unsigned long ip = ktva_ktla(regs->ip);
17474+
17475+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17476+ regs->ip = ip;
17477+ }
17478+#endif
17479+
17480 nmi_enter();
17481
17482 inc_irq_stat(__nmi_count);
17483@@ -558,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
17484 }
17485
17486 #ifdef CONFIG_X86_32
17487- if (regs->flags & X86_VM_MASK)
17488+ if (v8086_mode(regs))
17489 goto debug_vm86;
17490 #endif
17491
17492@@ -570,7 +610,7 @@ dotraplinkage void __kprobes do_debug(st
17493 * kernel space (but re-enable TF when returning to user mode).
17494 */
17495 if (condition & DR_STEP) {
17496- if (!user_mode(regs))
17497+ if (!user_mode_novm(regs))
17498 goto clear_TF_reenable;
17499 }
17500
17501@@ -757,7 +797,7 @@ do_simd_coprocessor_error(struct pt_regs
17502 * Handle strange cache flush from user space exception
17503 * in all other cases. This is undocumented behaviour.
17504 */
17505- if (regs->flags & X86_VM_MASK) {
17506+ if (v8086_mode(regs)) {
17507 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
17508 return;
17509 }
17510@@ -798,7 +838,7 @@ asmlinkage void __attribute__((weak)) sm
17511 void __math_state_restore(void)
17512 {
17513 struct thread_info *thread = current_thread_info();
17514- struct task_struct *tsk = thread->task;
17515+ struct task_struct *tsk = current;
17516
17517 /*
17518 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17519@@ -825,8 +865,7 @@ void __math_state_restore(void)
17520 */
17521 asmlinkage void math_state_restore(void)
17522 {
17523- struct thread_info *thread = current_thread_info();
17524- struct task_struct *tsk = thread->task;
17525+ struct task_struct *tsk = current;
17526
17527 if (!tsk_used_math(tsk)) {
17528 local_irq_enable();
17529diff -urNp linux-2.6.32.44/arch/x86/kernel/verify_cpu_64.S linux-2.6.32.44/arch/x86/kernel/verify_cpu_64.S
17530--- linux-2.6.32.44/arch/x86/kernel/verify_cpu_64.S 2011-03-27 14:31:47.000000000 -0400
17531+++ linux-2.6.32.44/arch/x86/kernel/verify_cpu_64.S 1969-12-31 19:00:00.000000000 -0500
17532@@ -1,105 +0,0 @@
17533-/*
17534- *
17535- * verify_cpu.S - Code for cpu long mode and SSE verification. This
17536- * code has been borrowed from boot/setup.S and was introduced by
17537- * Andi Kleen.
17538- *
17539- * Copyright (c) 2007 Andi Kleen (ak@suse.de)
17540- * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
17541- * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
17542- *
17543- * This source code is licensed under the GNU General Public License,
17544- * Version 2. See the file COPYING for more details.
17545- *
17546- * This is a common code for verification whether CPU supports
17547- * long mode and SSE or not. It is not called directly instead this
17548- * file is included at various places and compiled in that context.
17549- * Following are the current usage.
17550- *
17551- * This file is included by both 16bit and 32bit code.
17552- *
17553- * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
17554- * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
17555- * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
17556- * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
17557- *
17558- * verify_cpu, returns the status of cpu check in register %eax.
17559- * 0: Success 1: Failure
17560- *
17561- * The caller needs to check for the error code and take the action
17562- * appropriately. Either display a message or halt.
17563- */
17564-
17565-#include <asm/cpufeature.h>
17566-
17567-verify_cpu:
17568- pushfl # Save caller passed flags
17569- pushl $0 # Kill any dangerous flags
17570- popfl
17571-
17572- pushfl # standard way to check for cpuid
17573- popl %eax
17574- movl %eax,%ebx
17575- xorl $0x200000,%eax
17576- pushl %eax
17577- popfl
17578- pushfl
17579- popl %eax
17580- cmpl %eax,%ebx
17581- jz verify_cpu_no_longmode # cpu has no cpuid
17582-
17583- movl $0x0,%eax # See if cpuid 1 is implemented
17584- cpuid
17585- cmpl $0x1,%eax
17586- jb verify_cpu_no_longmode # no cpuid 1
17587-
17588- xor %di,%di
17589- cmpl $0x68747541,%ebx # AuthenticAMD
17590- jnz verify_cpu_noamd
17591- cmpl $0x69746e65,%edx
17592- jnz verify_cpu_noamd
17593- cmpl $0x444d4163,%ecx
17594- jnz verify_cpu_noamd
17595- mov $1,%di # cpu is from AMD
17596-
17597-verify_cpu_noamd:
17598- movl $0x1,%eax # Does the cpu have what it takes
17599- cpuid
17600- andl $REQUIRED_MASK0,%edx
17601- xorl $REQUIRED_MASK0,%edx
17602- jnz verify_cpu_no_longmode
17603-
17604- movl $0x80000000,%eax # See if extended cpuid is implemented
17605- cpuid
17606- cmpl $0x80000001,%eax
17607- jb verify_cpu_no_longmode # no extended cpuid
17608-
17609- movl $0x80000001,%eax # Does the cpu have what it takes
17610- cpuid
17611- andl $REQUIRED_MASK1,%edx
17612- xorl $REQUIRED_MASK1,%edx
17613- jnz verify_cpu_no_longmode
17614-
17615-verify_cpu_sse_test:
17616- movl $1,%eax
17617- cpuid
17618- andl $SSE_MASK,%edx
17619- cmpl $SSE_MASK,%edx
17620- je verify_cpu_sse_ok
17621- test %di,%di
17622- jz verify_cpu_no_longmode # only try to force SSE on AMD
17623- movl $0xc0010015,%ecx # HWCR
17624- rdmsr
17625- btr $15,%eax # enable SSE
17626- wrmsr
17627- xor %di,%di # don't loop
17628- jmp verify_cpu_sse_test # try again
17629-
17630-verify_cpu_no_longmode:
17631- popfl # Restore caller passed flags
17632- movl $1,%eax
17633- ret
17634-verify_cpu_sse_ok:
17635- popfl # Restore caller passed flags
17636- xorl %eax, %eax
17637- ret
17638diff -urNp linux-2.6.32.44/arch/x86/kernel/verify_cpu.S linux-2.6.32.44/arch/x86/kernel/verify_cpu.S
17639--- linux-2.6.32.44/arch/x86/kernel/verify_cpu.S 1969-12-31 19:00:00.000000000 -0500
17640+++ linux-2.6.32.44/arch/x86/kernel/verify_cpu.S 2011-07-01 18:28:42.000000000 -0400
17641@@ -0,0 +1,140 @@
17642+/*
17643+ *
17644+ * verify_cpu.S - Code for cpu long mode and SSE verification. This
17645+ * code has been borrowed from boot/setup.S and was introduced by
17646+ * Andi Kleen.
17647+ *
17648+ * Copyright (c) 2007 Andi Kleen (ak@suse.de)
17649+ * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
17650+ * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
17651+ * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com)
17652+ *
17653+ * This source code is licensed under the GNU General Public License,
17654+ * Version 2. See the file COPYING for more details.
17655+ *
17656+ * This is a common code for verification whether CPU supports
17657+ * long mode and SSE or not. It is not called directly instead this
17658+ * file is included at various places and compiled in that context.
17659+ * This file is expected to run in 32bit code. Currently:
17660+ *
17661+ * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17662+ * arch/x86/kernel/trampoline_64.S: secondary processor verification
17663+ * arch/x86/kernel/head_32.S: processor startup
17664+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
17665+ *
17666+ * verify_cpu, returns the status of longmode and SSE in register %eax.
17667+ * 0: Success 1: Failure
17668+ *
17669+ * On Intel, the XD_DISABLE flag will be cleared as a side-effect.
17670+ *
17671+ * The caller needs to check for the error code and take the action
17672+ * appropriately. Either display a message or halt.
17673+ */
17674+
17675+#include <asm/cpufeature.h>
17676+#include <asm/msr-index.h>
17677+
17678+verify_cpu:
17679+ pushfl # Save caller passed flags
17680+ pushl $0 # Kill any dangerous flags
17681+ popfl
17682+
17683+ pushfl # standard way to check for cpuid
17684+ popl %eax
17685+ movl %eax,%ebx
17686+ xorl $0x200000,%eax
17687+ pushl %eax
17688+ popfl
17689+ pushfl
17690+ popl %eax
17691+ cmpl %eax,%ebx
17692+ jz verify_cpu_no_longmode # cpu has no cpuid
17693+
17694+ movl $0x0,%eax # See if cpuid 1 is implemented
17695+ cpuid
17696+ cmpl $0x1,%eax
17697+ jb verify_cpu_no_longmode # no cpuid 1
17698+
17699+ xor %di,%di
17700+ cmpl $0x68747541,%ebx # AuthenticAMD
17701+ jnz verify_cpu_noamd
17702+ cmpl $0x69746e65,%edx
17703+ jnz verify_cpu_noamd
17704+ cmpl $0x444d4163,%ecx
17705+ jnz verify_cpu_noamd
17706+ mov $1,%di # cpu is from AMD
17707+ jmp verify_cpu_check
17708+
17709+verify_cpu_noamd:
17710+ cmpl $0x756e6547,%ebx # GenuineIntel?
17711+ jnz verify_cpu_check
17712+ cmpl $0x49656e69,%edx
17713+ jnz verify_cpu_check
17714+ cmpl $0x6c65746e,%ecx
17715+ jnz verify_cpu_check
17716+
17717+ # only call IA32_MISC_ENABLE when:
17718+ # family > 6 || (family == 6 && model >= 0xd)
17719+ movl $0x1, %eax # check CPU family and model
17720+ cpuid
17721+ movl %eax, %ecx
17722+
17723+ andl $0x0ff00f00, %eax # mask family and extended family
17724+ shrl $8, %eax
17725+ cmpl $6, %eax
17726+ ja verify_cpu_clear_xd # family > 6, ok
17727+ jb verify_cpu_check # family < 6, skip
17728+
17729+ andl $0x000f00f0, %ecx # mask model and extended model
17730+ shrl $4, %ecx
17731+ cmpl $0xd, %ecx
17732+ jb verify_cpu_check # family == 6, model < 0xd, skip
17733+
17734+verify_cpu_clear_xd:
17735+ movl $MSR_IA32_MISC_ENABLE, %ecx
17736+ rdmsr
17737+ btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE
17738+ jnc verify_cpu_check # only write MSR if bit was changed
17739+ wrmsr
17740+
17741+verify_cpu_check:
17742+ movl $0x1,%eax # Does the cpu have what it takes
17743+ cpuid
17744+ andl $REQUIRED_MASK0,%edx
17745+ xorl $REQUIRED_MASK0,%edx
17746+ jnz verify_cpu_no_longmode
17747+
17748+ movl $0x80000000,%eax # See if extended cpuid is implemented
17749+ cpuid
17750+ cmpl $0x80000001,%eax
17751+ jb verify_cpu_no_longmode # no extended cpuid
17752+
17753+ movl $0x80000001,%eax # Does the cpu have what it takes
17754+ cpuid
17755+ andl $REQUIRED_MASK1,%edx
17756+ xorl $REQUIRED_MASK1,%edx
17757+ jnz verify_cpu_no_longmode
17758+
17759+verify_cpu_sse_test:
17760+ movl $1,%eax
17761+ cpuid
17762+ andl $SSE_MASK,%edx
17763+ cmpl $SSE_MASK,%edx
17764+ je verify_cpu_sse_ok
17765+ test %di,%di
17766+ jz verify_cpu_no_longmode # only try to force SSE on AMD
17767+ movl $MSR_K7_HWCR,%ecx
17768+ rdmsr
17769+ btr $15,%eax # enable SSE
17770+ wrmsr
17771+ xor %di,%di # don't loop
17772+ jmp verify_cpu_sse_test # try again
17773+
17774+verify_cpu_no_longmode:
17775+ popfl # Restore caller passed flags
17776+ movl $1,%eax
17777+ ret
17778+verify_cpu_sse_ok:
17779+ popfl # Restore caller passed flags
17780+ xorl %eax, %eax
17781+ ret
17782diff -urNp linux-2.6.32.44/arch/x86/kernel/vm86_32.c linux-2.6.32.44/arch/x86/kernel/vm86_32.c
17783--- linux-2.6.32.44/arch/x86/kernel/vm86_32.c 2011-03-27 14:31:47.000000000 -0400
17784+++ linux-2.6.32.44/arch/x86/kernel/vm86_32.c 2011-04-17 15:56:46.000000000 -0400
17785@@ -41,6 +41,7 @@
17786 #include <linux/ptrace.h>
17787 #include <linux/audit.h>
17788 #include <linux/stddef.h>
17789+#include <linux/grsecurity.h>
17790
17791 #include <asm/uaccess.h>
17792 #include <asm/io.h>
17793@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
17794 do_exit(SIGSEGV);
17795 }
17796
17797- tss = &per_cpu(init_tss, get_cpu());
17798+ tss = init_tss + get_cpu();
17799 current->thread.sp0 = current->thread.saved_sp0;
17800 current->thread.sysenter_cs = __KERNEL_CS;
17801 load_sp0(tss, &current->thread);
17802@@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
17803 struct task_struct *tsk;
17804 int tmp, ret = -EPERM;
17805
17806+#ifdef CONFIG_GRKERNSEC_VM86
17807+ if (!capable(CAP_SYS_RAWIO)) {
17808+ gr_handle_vm86();
17809+ goto out;
17810+ }
17811+#endif
17812+
17813 tsk = current;
17814 if (tsk->thread.saved_sp0)
17815 goto out;
17816@@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
17817 int tmp, ret;
17818 struct vm86plus_struct __user *v86;
17819
17820+#ifdef CONFIG_GRKERNSEC_VM86
17821+ if (!capable(CAP_SYS_RAWIO)) {
17822+ gr_handle_vm86();
17823+ ret = -EPERM;
17824+ goto out;
17825+ }
17826+#endif
17827+
17828 tsk = current;
17829 switch (regs->bx) {
17830 case VM86_REQUEST_IRQ:
17831@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
17832 tsk->thread.saved_fs = info->regs32->fs;
17833 tsk->thread.saved_gs = get_user_gs(info->regs32);
17834
17835- tss = &per_cpu(init_tss, get_cpu());
17836+ tss = init_tss + get_cpu();
17837 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17838 if (cpu_has_sep)
17839 tsk->thread.sysenter_cs = 0;
17840@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
17841 goto cannot_handle;
17842 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17843 goto cannot_handle;
17844- intr_ptr = (unsigned long __user *) (i << 2);
17845+ intr_ptr = (__force unsigned long __user *) (i << 2);
17846 if (get_user(segoffs, intr_ptr))
17847 goto cannot_handle;
17848 if ((segoffs >> 16) == BIOSSEG)
17849diff -urNp linux-2.6.32.44/arch/x86/kernel/vmi_32.c linux-2.6.32.44/arch/x86/kernel/vmi_32.c
17850--- linux-2.6.32.44/arch/x86/kernel/vmi_32.c 2011-03-27 14:31:47.000000000 -0400
17851+++ linux-2.6.32.44/arch/x86/kernel/vmi_32.c 2011-08-05 20:33:55.000000000 -0400
17852@@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1)))
17853 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
17854
17855 #define call_vrom_func(rom,func) \
17856- (((VROMFUNC *)(rom->func))())
17857+ (((VROMFUNC *)(ktva_ktla(rom.func)))())
17858
17859 #define call_vrom_long_func(rom,func,arg) \
17860- (((VROMLONGFUNC *)(rom->func)) (arg))
17861+({\
17862+ u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
17863+ struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
17864+ __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
17865+ __reloc;\
17866+})
17867
17868-static struct vrom_header *vmi_rom;
17869+static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
17870 static int disable_pge;
17871 static int disable_pse;
17872 static int disable_sep;
17873@@ -76,10 +81,10 @@ static struct {
17874 void (*set_initial_ap_state)(int, int);
17875 void (*halt)(void);
17876 void (*set_lazy_mode)(int mode);
17877-} vmi_ops;
17878+} __no_const vmi_ops __read_only;
17879
17880 /* Cached VMI operations */
17881-struct vmi_timer_ops vmi_timer_ops;
17882+struct vmi_timer_ops vmi_timer_ops __read_only;
17883
17884 /*
17885 * VMI patching routines.
17886@@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
17887 static inline void patch_offset(void *insnbuf,
17888 unsigned long ip, unsigned long dest)
17889 {
17890- *(unsigned long *)(insnbuf+1) = dest-ip-5;
17891+ *(unsigned long *)(insnbuf+1) = dest-ip-5;
17892 }
17893
17894 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
17895@@ -102,6 +107,7 @@ static unsigned patch_internal(int call,
17896 {
17897 u64 reloc;
17898 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
17899+
17900 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
17901 switch(rel->type) {
17902 case VMI_RELOCATION_CALL_REL:
17903@@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud
17904
17905 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
17906 {
17907- const pte_t pte = { .pte = 0 };
17908+ const pte_t pte = __pte(0ULL);
17909 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
17910 }
17911
17912 static void vmi_pmd_clear(pmd_t *pmd)
17913 {
17914- const pte_t pte = { .pte = 0 };
17915+ const pte_t pte = __pte(0ULL);
17916 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
17917 }
17918 #endif
17919@@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, un
17920 ap.ss = __KERNEL_DS;
17921 ap.esp = (unsigned long) start_esp;
17922
17923- ap.ds = __USER_DS;
17924- ap.es = __USER_DS;
17925+ ap.ds = __KERNEL_DS;
17926+ ap.es = __KERNEL_DS;
17927 ap.fs = __KERNEL_PERCPU;
17928- ap.gs = __KERNEL_STACK_CANARY;
17929+ savesegment(gs, ap.gs);
17930
17931 ap.eflags = 0;
17932
17933@@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
17934 paravirt_leave_lazy_mmu();
17935 }
17936
17937+#ifdef CONFIG_PAX_KERNEXEC
17938+static unsigned long vmi_pax_open_kernel(void)
17939+{
17940+ return 0;
17941+}
17942+
17943+static unsigned long vmi_pax_close_kernel(void)
17944+{
17945+ return 0;
17946+}
17947+#endif
17948+
17949 static inline int __init check_vmi_rom(struct vrom_header *rom)
17950 {
17951 struct pci_header *pci;
17952@@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(s
17953 return 0;
17954 if (rom->vrom_signature != VMI_SIGNATURE)
17955 return 0;
17956+ if (rom->rom_length * 512 > sizeof(*rom)) {
17957+ printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
17958+ return 0;
17959+ }
17960 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
17961 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
17962 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
17963@@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(v
17964 struct vrom_header *romstart;
17965 romstart = (struct vrom_header *)isa_bus_to_virt(base);
17966 if (check_vmi_rom(romstart)) {
17967- vmi_rom = romstart;
17968+ vmi_rom = *romstart;
17969 return 1;
17970 }
17971 }
17972@@ -836,6 +858,11 @@ static inline int __init activate_vmi(vo
17973
17974 para_fill(pv_irq_ops.safe_halt, Halt);
17975
17976+#ifdef CONFIG_PAX_KERNEXEC
17977+ pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
17978+ pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
17979+#endif
17980+
17981 /*
17982 * Alternative instruction rewriting doesn't happen soon enough
17983 * to convert VMI_IRET to a call instead of a jump; so we have
17984@@ -853,16 +880,16 @@ static inline int __init activate_vmi(vo
17985
17986 void __init vmi_init(void)
17987 {
17988- if (!vmi_rom)
17989+ if (!vmi_rom.rom_signature)
17990 probe_vmi_rom();
17991 else
17992- check_vmi_rom(vmi_rom);
17993+ check_vmi_rom(&vmi_rom);
17994
17995 /* In case probing for or validating the ROM failed, basil */
17996- if (!vmi_rom)
17997+ if (!vmi_rom.rom_signature)
17998 return;
17999
18000- reserve_top_address(-vmi_rom->virtual_top);
18001+ reserve_top_address(-vmi_rom.virtual_top);
18002
18003 #ifdef CONFIG_X86_IO_APIC
18004 /* This is virtual hardware; timer routing is wired correctly */
18005@@ -874,7 +901,7 @@ void __init vmi_activate(void)
18006 {
18007 unsigned long flags;
18008
18009- if (!vmi_rom)
18010+ if (!vmi_rom.rom_signature)
18011 return;
18012
18013 local_irq_save(flags);
18014diff -urNp linux-2.6.32.44/arch/x86/kernel/vmlinux.lds.S linux-2.6.32.44/arch/x86/kernel/vmlinux.lds.S
18015--- linux-2.6.32.44/arch/x86/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
18016+++ linux-2.6.32.44/arch/x86/kernel/vmlinux.lds.S 2011-04-17 15:56:46.000000000 -0400
18017@@ -26,6 +26,13 @@
18018 #include <asm/page_types.h>
18019 #include <asm/cache.h>
18020 #include <asm/boot.h>
18021+#include <asm/segment.h>
18022+
18023+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18024+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
18025+#else
18026+#define __KERNEL_TEXT_OFFSET 0
18027+#endif
18028
18029 #undef i386 /* in case the preprocessor is a 32bit one */
18030
18031@@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
18032 #ifdef CONFIG_X86_32
18033 OUTPUT_ARCH(i386)
18034 ENTRY(phys_startup_32)
18035-jiffies = jiffies_64;
18036 #else
18037 OUTPUT_ARCH(i386:x86-64)
18038 ENTRY(phys_startup_64)
18039-jiffies_64 = jiffies;
18040 #endif
18041
18042 PHDRS {
18043 text PT_LOAD FLAGS(5); /* R_E */
18044- data PT_LOAD FLAGS(7); /* RWE */
18045+#ifdef CONFIG_X86_32
18046+ module PT_LOAD FLAGS(5); /* R_E */
18047+#endif
18048+#ifdef CONFIG_XEN
18049+ rodata PT_LOAD FLAGS(5); /* R_E */
18050+#else
18051+ rodata PT_LOAD FLAGS(4); /* R__ */
18052+#endif
18053+ data PT_LOAD FLAGS(6); /* RW_ */
18054 #ifdef CONFIG_X86_64
18055 user PT_LOAD FLAGS(5); /* R_E */
18056+#endif
18057+ init.begin PT_LOAD FLAGS(6); /* RW_ */
18058 #ifdef CONFIG_SMP
18059 percpu PT_LOAD FLAGS(6); /* RW_ */
18060 #endif
18061+ text.init PT_LOAD FLAGS(5); /* R_E */
18062+ text.exit PT_LOAD FLAGS(5); /* R_E */
18063 init PT_LOAD FLAGS(7); /* RWE */
18064-#endif
18065 note PT_NOTE FLAGS(0); /* ___ */
18066 }
18067
18068 SECTIONS
18069 {
18070 #ifdef CONFIG_X86_32
18071- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18072- phys_startup_32 = startup_32 - LOAD_OFFSET;
18073+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18074 #else
18075- . = __START_KERNEL;
18076- phys_startup_64 = startup_64 - LOAD_OFFSET;
18077+ . = __START_KERNEL;
18078 #endif
18079
18080 /* Text and read-only data */
18081- .text : AT(ADDR(.text) - LOAD_OFFSET) {
18082- _text = .;
18083+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18084 /* bootstrapping code */
18085+#ifdef CONFIG_X86_32
18086+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18087+#else
18088+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18089+#endif
18090+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18091+ _text = .;
18092 HEAD_TEXT
18093 #ifdef CONFIG_X86_32
18094 . = ALIGN(PAGE_SIZE);
18095@@ -82,28 +102,71 @@ SECTIONS
18096 IRQENTRY_TEXT
18097 *(.fixup)
18098 *(.gnu.warning)
18099- /* End of text section */
18100- _etext = .;
18101 } :text = 0x9090
18102
18103- NOTES :text :note
18104+ . += __KERNEL_TEXT_OFFSET;
18105+
18106+#ifdef CONFIG_X86_32
18107+ . = ALIGN(PAGE_SIZE);
18108+ .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
18109+ *(.vmi.rom)
18110+ } :module
18111+
18112+ . = ALIGN(PAGE_SIZE);
18113+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18114+
18115+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18116+ MODULES_EXEC_VADDR = .;
18117+ BYTE(0)
18118+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18119+ . = ALIGN(HPAGE_SIZE);
18120+ MODULES_EXEC_END = . - 1;
18121+#endif
18122+
18123+ } :module
18124+#endif
18125
18126- EXCEPTION_TABLE(16) :text = 0x9090
18127+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18128+ /* End of text section */
18129+ _etext = . - __KERNEL_TEXT_OFFSET;
18130+ }
18131+
18132+#ifdef CONFIG_X86_32
18133+ . = ALIGN(PAGE_SIZE);
18134+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18135+ *(.idt)
18136+ . = ALIGN(PAGE_SIZE);
18137+ *(.empty_zero_page)
18138+ *(.swapper_pg_fixmap)
18139+ *(.swapper_pg_pmd)
18140+ *(.swapper_pg_dir)
18141+ *(.trampoline_pg_dir)
18142+ } :rodata
18143+#endif
18144+
18145+ . = ALIGN(PAGE_SIZE);
18146+ NOTES :rodata :note
18147+
18148+ EXCEPTION_TABLE(16) :rodata
18149
18150 RO_DATA(PAGE_SIZE)
18151
18152 /* Data */
18153 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18154+
18155+#ifdef CONFIG_PAX_KERNEXEC
18156+ . = ALIGN(HPAGE_SIZE);
18157+#else
18158+ . = ALIGN(PAGE_SIZE);
18159+#endif
18160+
18161 /* Start of data section */
18162 _sdata = .;
18163
18164 /* init_task */
18165 INIT_TASK_DATA(THREAD_SIZE)
18166
18167-#ifdef CONFIG_X86_32
18168- /* 32 bit has nosave before _edata */
18169 NOSAVE_DATA
18170-#endif
18171
18172 PAGE_ALIGNED_DATA(PAGE_SIZE)
18173
18174@@ -112,6 +175,8 @@ SECTIONS
18175 DATA_DATA
18176 CONSTRUCTORS
18177
18178+ jiffies = jiffies_64;
18179+
18180 /* rarely changed data like cpu maps */
18181 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
18182
18183@@ -166,12 +231,6 @@ SECTIONS
18184 }
18185 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18186
18187- . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
18188- .jiffies : AT(VLOAD(.jiffies)) {
18189- *(.jiffies)
18190- }
18191- jiffies = VVIRT(.jiffies);
18192-
18193 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18194 *(.vsyscall_3)
18195 }
18196@@ -187,12 +246,19 @@ SECTIONS
18197 #endif /* CONFIG_X86_64 */
18198
18199 /* Init code and data - will be freed after init */
18200- . = ALIGN(PAGE_SIZE);
18201 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18202+ BYTE(0)
18203+
18204+#ifdef CONFIG_PAX_KERNEXEC
18205+ . = ALIGN(HPAGE_SIZE);
18206+#else
18207+ . = ALIGN(PAGE_SIZE);
18208+#endif
18209+
18210 __init_begin = .; /* paired with __init_end */
18211- }
18212+ } :init.begin
18213
18214-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18215+#ifdef CONFIG_SMP
18216 /*
18217 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18218 * output PHDR, so the next output section - .init.text - should
18219@@ -201,12 +267,27 @@ SECTIONS
18220 PERCPU_VADDR(0, :percpu)
18221 #endif
18222
18223- INIT_TEXT_SECTION(PAGE_SIZE)
18224-#ifdef CONFIG_X86_64
18225- :init
18226-#endif
18227+ . = ALIGN(PAGE_SIZE);
18228+ init_begin = .;
18229+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18230+ VMLINUX_SYMBOL(_sinittext) = .;
18231+ INIT_TEXT
18232+ VMLINUX_SYMBOL(_einittext) = .;
18233+ . = ALIGN(PAGE_SIZE);
18234+ } :text.init
18235
18236- INIT_DATA_SECTION(16)
18237+ /*
18238+ * .exit.text is discard at runtime, not link time, to deal with
18239+ * references from .altinstructions and .eh_frame
18240+ */
18241+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18242+ EXIT_TEXT
18243+ . = ALIGN(16);
18244+ } :text.exit
18245+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18246+
18247+ . = ALIGN(PAGE_SIZE);
18248+ INIT_DATA_SECTION(16) :init
18249
18250 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
18251 __x86_cpu_dev_start = .;
18252@@ -232,19 +313,11 @@ SECTIONS
18253 *(.altinstr_replacement)
18254 }
18255
18256- /*
18257- * .exit.text is discard at runtime, not link time, to deal with
18258- * references from .altinstructions and .eh_frame
18259- */
18260- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18261- EXIT_TEXT
18262- }
18263-
18264 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18265 EXIT_DATA
18266 }
18267
18268-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18269+#ifndef CONFIG_SMP
18270 PERCPU(PAGE_SIZE)
18271 #endif
18272
18273@@ -267,12 +340,6 @@ SECTIONS
18274 . = ALIGN(PAGE_SIZE);
18275 }
18276
18277-#ifdef CONFIG_X86_64
18278- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18279- NOSAVE_DATA
18280- }
18281-#endif
18282-
18283 /* BSS */
18284 . = ALIGN(PAGE_SIZE);
18285 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18286@@ -288,6 +355,7 @@ SECTIONS
18287 __brk_base = .;
18288 . += 64 * 1024; /* 64k alignment slop space */
18289 *(.brk_reservation) /* areas brk users have reserved */
18290+ . = ALIGN(HPAGE_SIZE);
18291 __brk_limit = .;
18292 }
18293
18294@@ -316,13 +384,12 @@ SECTIONS
18295 * for the boot processor.
18296 */
18297 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
18298-INIT_PER_CPU(gdt_page);
18299 INIT_PER_CPU(irq_stack_union);
18300
18301 /*
18302 * Build-time check on the image size:
18303 */
18304-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18305+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18306 "kernel image bigger than KERNEL_IMAGE_SIZE");
18307
18308 #ifdef CONFIG_SMP
18309diff -urNp linux-2.6.32.44/arch/x86/kernel/vsyscall_64.c linux-2.6.32.44/arch/x86/kernel/vsyscall_64.c
18310--- linux-2.6.32.44/arch/x86/kernel/vsyscall_64.c 2011-03-27 14:31:47.000000000 -0400
18311+++ linux-2.6.32.44/arch/x86/kernel/vsyscall_64.c 2011-04-23 12:56:10.000000000 -0400
18312@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18313
18314 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18315 /* copy vsyscall data */
18316+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18317 vsyscall_gtod_data.clock.vread = clock->vread;
18318 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18319 vsyscall_gtod_data.clock.mask = clock->mask;
18320@@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18321 We do this here because otherwise user space would do it on
18322 its own in a likely inferior way (no access to jiffies).
18323 If you don't like it pass NULL. */
18324- if (tcache && tcache->blob[0] == (j = __jiffies)) {
18325+ if (tcache && tcache->blob[0] == (j = jiffies)) {
18326 p = tcache->blob[1];
18327 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18328 /* Load per CPU data from RDTSCP */
18329diff -urNp linux-2.6.32.44/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.32.44/arch/x86/kernel/x8664_ksyms_64.c
18330--- linux-2.6.32.44/arch/x86/kernel/x8664_ksyms_64.c 2011-03-27 14:31:47.000000000 -0400
18331+++ linux-2.6.32.44/arch/x86/kernel/x8664_ksyms_64.c 2011-04-17 15:56:46.000000000 -0400
18332@@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
18333
18334 EXPORT_SYMBOL(copy_user_generic);
18335 EXPORT_SYMBOL(__copy_user_nocache);
18336-EXPORT_SYMBOL(copy_from_user);
18337-EXPORT_SYMBOL(copy_to_user);
18338 EXPORT_SYMBOL(__copy_from_user_inatomic);
18339
18340 EXPORT_SYMBOL(copy_page);
18341diff -urNp linux-2.6.32.44/arch/x86/kernel/xsave.c linux-2.6.32.44/arch/x86/kernel/xsave.c
18342--- linux-2.6.32.44/arch/x86/kernel/xsave.c 2011-03-27 14:31:47.000000000 -0400
18343+++ linux-2.6.32.44/arch/x86/kernel/xsave.c 2011-04-17 15:56:46.000000000 -0400
18344@@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_
18345 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18346 return -1;
18347
18348- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18349+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18350 fx_sw_user->extended_size -
18351 FP_XSTATE_MAGIC2_SIZE));
18352 /*
18353@@ -196,7 +196,7 @@ fx_only:
18354 * the other extended state.
18355 */
18356 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18357- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18358+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18359 }
18360
18361 /*
18362@@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf
18363 if (task_thread_info(tsk)->status & TS_XSAVE)
18364 err = restore_user_xstate(buf);
18365 else
18366- err = fxrstor_checking((__force struct i387_fxsave_struct *)
18367+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
18368 buf);
18369 if (unlikely(err)) {
18370 /*
18371diff -urNp linux-2.6.32.44/arch/x86/kvm/emulate.c linux-2.6.32.44/arch/x86/kvm/emulate.c
18372--- linux-2.6.32.44/arch/x86/kvm/emulate.c 2011-03-27 14:31:47.000000000 -0400
18373+++ linux-2.6.32.44/arch/x86/kvm/emulate.c 2011-04-17 15:56:46.000000000 -0400
18374@@ -81,8 +81,8 @@
18375 #define Src2CL (1<<29)
18376 #define Src2ImmByte (2<<29)
18377 #define Src2One (3<<29)
18378-#define Src2Imm16 (4<<29)
18379-#define Src2Mask (7<<29)
18380+#define Src2Imm16 (4U<<29)
18381+#define Src2Mask (7U<<29)
18382
18383 enum {
18384 Group1_80, Group1_81, Group1_82, Group1_83,
18385@@ -411,6 +411,7 @@ static u32 group2_table[] = {
18386
18387 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
18388 do { \
18389+ unsigned long _tmp; \
18390 __asm__ __volatile__ ( \
18391 _PRE_EFLAGS("0", "4", "2") \
18392 _op _suffix " %"_x"3,%1; " \
18393@@ -424,8 +425,6 @@ static u32 group2_table[] = {
18394 /* Raw emulation: instruction has two explicit operands. */
18395 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18396 do { \
18397- unsigned long _tmp; \
18398- \
18399 switch ((_dst).bytes) { \
18400 case 2: \
18401 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
18402@@ -441,7 +440,6 @@ static u32 group2_table[] = {
18403
18404 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18405 do { \
18406- unsigned long _tmp; \
18407 switch ((_dst).bytes) { \
18408 case 1: \
18409 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
18410diff -urNp linux-2.6.32.44/arch/x86/kvm/lapic.c linux-2.6.32.44/arch/x86/kvm/lapic.c
18411--- linux-2.6.32.44/arch/x86/kvm/lapic.c 2011-03-27 14:31:47.000000000 -0400
18412+++ linux-2.6.32.44/arch/x86/kvm/lapic.c 2011-04-17 15:56:46.000000000 -0400
18413@@ -52,7 +52,7 @@
18414 #define APIC_BUS_CYCLE_NS 1
18415
18416 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18417-#define apic_debug(fmt, arg...)
18418+#define apic_debug(fmt, arg...) do {} while (0)
18419
18420 #define APIC_LVT_NUM 6
18421 /* 14 is the version for Xeon and Pentium 8.4.8*/
18422diff -urNp linux-2.6.32.44/arch/x86/kvm/paging_tmpl.h linux-2.6.32.44/arch/x86/kvm/paging_tmpl.h
18423--- linux-2.6.32.44/arch/x86/kvm/paging_tmpl.h 2011-03-27 14:31:47.000000000 -0400
18424+++ linux-2.6.32.44/arch/x86/kvm/paging_tmpl.h 2011-05-16 21:46:57.000000000 -0400
18425@@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_
18426 int level = PT_PAGE_TABLE_LEVEL;
18427 unsigned long mmu_seq;
18428
18429+ pax_track_stack();
18430+
18431 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18432 kvm_mmu_audit(vcpu, "pre page fault");
18433
18434diff -urNp linux-2.6.32.44/arch/x86/kvm/svm.c linux-2.6.32.44/arch/x86/kvm/svm.c
18435--- linux-2.6.32.44/arch/x86/kvm/svm.c 2011-03-27 14:31:47.000000000 -0400
18436+++ linux-2.6.32.44/arch/x86/kvm/svm.c 2011-08-05 20:33:55.000000000 -0400
18437@@ -2485,7 +2485,11 @@ static void reload_tss(struct kvm_vcpu *
18438 int cpu = raw_smp_processor_id();
18439
18440 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
18441+
18442+ pax_open_kernel();
18443 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
18444+ pax_close_kernel();
18445+
18446 load_TR_desc();
18447 }
18448
18449@@ -2946,7 +2950,7 @@ static bool svm_gb_page_enable(void)
18450 return true;
18451 }
18452
18453-static struct kvm_x86_ops svm_x86_ops = {
18454+static const struct kvm_x86_ops svm_x86_ops = {
18455 .cpu_has_kvm_support = has_svm,
18456 .disabled_by_bios = is_disabled,
18457 .hardware_setup = svm_hardware_setup,
18458diff -urNp linux-2.6.32.44/arch/x86/kvm/vmx.c linux-2.6.32.44/arch/x86/kvm/vmx.c
18459--- linux-2.6.32.44/arch/x86/kvm/vmx.c 2011-03-27 14:31:47.000000000 -0400
18460+++ linux-2.6.32.44/arch/x86/kvm/vmx.c 2011-05-04 17:56:20.000000000 -0400
18461@@ -570,7 +570,11 @@ static void reload_tss(void)
18462
18463 kvm_get_gdt(&gdt);
18464 descs = (void *)gdt.base;
18465+
18466+ pax_open_kernel();
18467 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18468+ pax_close_kernel();
18469+
18470 load_TR_desc();
18471 }
18472
18473@@ -1409,8 +1413,11 @@ static __init int hardware_setup(void)
18474 if (!cpu_has_vmx_flexpriority())
18475 flexpriority_enabled = 0;
18476
18477- if (!cpu_has_vmx_tpr_shadow())
18478- kvm_x86_ops->update_cr8_intercept = NULL;
18479+ if (!cpu_has_vmx_tpr_shadow()) {
18480+ pax_open_kernel();
18481+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18482+ pax_close_kernel();
18483+ }
18484
18485 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18486 kvm_disable_largepages();
18487@@ -2361,7 +2368,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18488 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
18489
18490 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18491- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18492+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18493 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18494 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18495 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
18496@@ -3717,6 +3724,12 @@ static void vmx_vcpu_run(struct kvm_vcpu
18497 "jmp .Lkvm_vmx_return \n\t"
18498 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18499 ".Lkvm_vmx_return: "
18500+
18501+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18502+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18503+ ".Lkvm_vmx_return2: "
18504+#endif
18505+
18506 /* Save guest registers, load host registers, keep flags */
18507 "xchg %0, (%%"R"sp) \n\t"
18508 "mov %%"R"ax, %c[rax](%0) \n\t"
18509@@ -3763,8 +3776,13 @@ static void vmx_vcpu_run(struct kvm_vcpu
18510 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
18511 #endif
18512 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
18513+
18514+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18515+ ,[cs]"i"(__KERNEL_CS)
18516+#endif
18517+
18518 : "cc", "memory"
18519- , R"bx", R"di", R"si"
18520+ , R"ax", R"bx", R"di", R"si"
18521 #ifdef CONFIG_X86_64
18522 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
18523 #endif
18524@@ -3781,7 +3799,16 @@ static void vmx_vcpu_run(struct kvm_vcpu
18525 if (vmx->rmode.irq.pending)
18526 fixup_rmode_irq(vmx);
18527
18528- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18529+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18530+
18531+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18532+ loadsegment(fs, __KERNEL_PERCPU);
18533+#endif
18534+
18535+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18536+ __set_fs(current_thread_info()->addr_limit);
18537+#endif
18538+
18539 vmx->launched = 1;
18540
18541 vmx_complete_interrupts(vmx);
18542@@ -3956,7 +3983,7 @@ static bool vmx_gb_page_enable(void)
18543 return false;
18544 }
18545
18546-static struct kvm_x86_ops vmx_x86_ops = {
18547+static const struct kvm_x86_ops vmx_x86_ops = {
18548 .cpu_has_kvm_support = cpu_has_kvm_support,
18549 .disabled_by_bios = vmx_disabled_by_bios,
18550 .hardware_setup = hardware_setup,
18551diff -urNp linux-2.6.32.44/arch/x86/kvm/x86.c linux-2.6.32.44/arch/x86/kvm/x86.c
18552--- linux-2.6.32.44/arch/x86/kvm/x86.c 2011-05-10 22:12:01.000000000 -0400
18553+++ linux-2.6.32.44/arch/x86/kvm/x86.c 2011-05-10 22:12:26.000000000 -0400
18554@@ -82,7 +82,7 @@ static void update_cr8_intercept(struct
18555 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18556 struct kvm_cpuid_entry2 __user *entries);
18557
18558-struct kvm_x86_ops *kvm_x86_ops;
18559+const struct kvm_x86_ops *kvm_x86_ops;
18560 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18561
18562 int ignore_msrs = 0;
18563@@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18564 struct kvm_cpuid2 *cpuid,
18565 struct kvm_cpuid_entry2 __user *entries)
18566 {
18567- int r;
18568+ int r, i;
18569
18570 r = -E2BIG;
18571 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18572 goto out;
18573 r = -EFAULT;
18574- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18575- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18576+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18577 goto out;
18578+ for (i = 0; i < cpuid->nent; ++i) {
18579+ struct kvm_cpuid_entry2 cpuid_entry;
18580+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18581+ goto out;
18582+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
18583+ }
18584 vcpu->arch.cpuid_nent = cpuid->nent;
18585 kvm_apic_set_version(vcpu);
18586 return 0;
18587@@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18588 struct kvm_cpuid2 *cpuid,
18589 struct kvm_cpuid_entry2 __user *entries)
18590 {
18591- int r;
18592+ int r, i;
18593
18594 vcpu_load(vcpu);
18595 r = -E2BIG;
18596 if (cpuid->nent < vcpu->arch.cpuid_nent)
18597 goto out;
18598 r = -EFAULT;
18599- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18600- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18601+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18602 goto out;
18603+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18604+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18605+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18606+ goto out;
18607+ }
18608 return 0;
18609
18610 out:
18611@@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18612 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18613 struct kvm_interrupt *irq)
18614 {
18615- if (irq->irq < 0 || irq->irq >= 256)
18616+ if (irq->irq >= 256)
18617 return -EINVAL;
18618 if (irqchip_in_kernel(vcpu->kvm))
18619 return -ENXIO;
18620@@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cp
18621 .notifier_call = kvmclock_cpufreq_notifier
18622 };
18623
18624-int kvm_arch_init(void *opaque)
18625+int kvm_arch_init(const void *opaque)
18626 {
18627 int r, cpu;
18628- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18629+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18630
18631 if (kvm_x86_ops) {
18632 printk(KERN_ERR "kvm: already loaded the other module\n");
18633diff -urNp linux-2.6.32.44/arch/x86/lguest/boot.c linux-2.6.32.44/arch/x86/lguest/boot.c
18634--- linux-2.6.32.44/arch/x86/lguest/boot.c 2011-03-27 14:31:47.000000000 -0400
18635+++ linux-2.6.32.44/arch/x86/lguest/boot.c 2011-08-05 20:33:55.000000000 -0400
18636@@ -1172,9 +1172,10 @@ static __init int early_put_chars(u32 vt
18637 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18638 * Launcher to reboot us.
18639 */
18640-static void lguest_restart(char *reason)
18641+static __noreturn void lguest_restart(char *reason)
18642 {
18643 kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART);
18644+ BUG();
18645 }
18646
18647 /*G:050
18648diff -urNp linux-2.6.32.44/arch/x86/lib/atomic64_32.c linux-2.6.32.44/arch/x86/lib/atomic64_32.c
18649--- linux-2.6.32.44/arch/x86/lib/atomic64_32.c 2011-03-27 14:31:47.000000000 -0400
18650+++ linux-2.6.32.44/arch/x86/lib/atomic64_32.c 2011-05-04 17:56:28.000000000 -0400
18651@@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u6
18652 }
18653 EXPORT_SYMBOL(atomic64_cmpxchg);
18654
18655+u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
18656+{
18657+ return cmpxchg8b(&ptr->counter, old_val, new_val);
18658+}
18659+EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
18660+
18661 /**
18662 * atomic64_xchg - xchg atomic64 variable
18663 * @ptr: pointer to type atomic64_t
18664@@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 n
18665 EXPORT_SYMBOL(atomic64_xchg);
18666
18667 /**
18668+ * atomic64_xchg_unchecked - xchg atomic64 variable
18669+ * @ptr: pointer to type atomic64_unchecked_t
18670+ * @new_val: value to assign
18671+ *
18672+ * Atomically xchgs the value of @ptr to @new_val and returns
18673+ * the old value.
18674+ */
18675+u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
18676+{
18677+ /*
18678+ * Try first with a (possibly incorrect) assumption about
18679+ * what we have there. We'll do two loops most likely,
18680+ * but we'll get an ownership MESI transaction straight away
18681+ * instead of a read transaction followed by a
18682+ * flush-for-ownership transaction:
18683+ */
18684+ u64 old_val, real_val = 0;
18685+
18686+ do {
18687+ old_val = real_val;
18688+
18689+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
18690+
18691+ } while (real_val != old_val);
18692+
18693+ return old_val;
18694+}
18695+EXPORT_SYMBOL(atomic64_xchg_unchecked);
18696+
18697+/**
18698 * atomic64_set - set atomic64 variable
18699 * @ptr: pointer to type atomic64_t
18700 * @new_val: value to assign
18701@@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 n
18702 EXPORT_SYMBOL(atomic64_set);
18703
18704 /**
18705-EXPORT_SYMBOL(atomic64_read);
18706+ * atomic64_unchecked_set - set atomic64 variable
18707+ * @ptr: pointer to type atomic64_unchecked_t
18708+ * @new_val: value to assign
18709+ *
18710+ * Atomically sets the value of @ptr to @new_val.
18711+ */
18712+void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
18713+{
18714+ atomic64_xchg_unchecked(ptr, new_val);
18715+}
18716+EXPORT_SYMBOL(atomic64_set_unchecked);
18717+
18718+/**
18719 * atomic64_add_return - add and return
18720 * @delta: integer value to add
18721 * @ptr: pointer to type atomic64_t
18722@@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 del
18723 }
18724 EXPORT_SYMBOL(atomic64_add_return);
18725
18726+/**
18727+ * atomic64_add_return_unchecked - add and return
18728+ * @delta: integer value to add
18729+ * @ptr: pointer to type atomic64_unchecked_t
18730+ *
18731+ * Atomically adds @delta to @ptr and returns @delta + *@ptr
18732+ */
18733+noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18734+{
18735+ /*
18736+ * Try first with a (possibly incorrect) assumption about
18737+ * what we have there. We'll do two loops most likely,
18738+ * but we'll get an ownership MESI transaction straight away
18739+ * instead of a read transaction followed by a
18740+ * flush-for-ownership transaction:
18741+ */
18742+ u64 old_val, new_val, real_val = 0;
18743+
18744+ do {
18745+ old_val = real_val;
18746+ new_val = old_val + delta;
18747+
18748+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
18749+
18750+ } while (real_val != old_val);
18751+
18752+ return new_val;
18753+}
18754+EXPORT_SYMBOL(atomic64_add_return_unchecked);
18755+
18756 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
18757 {
18758 return atomic64_add_return(-delta, ptr);
18759 }
18760 EXPORT_SYMBOL(atomic64_sub_return);
18761
18762+u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18763+{
18764+ return atomic64_add_return_unchecked(-delta, ptr);
18765+}
18766+EXPORT_SYMBOL(atomic64_sub_return_unchecked);
18767+
18768 u64 atomic64_inc_return(atomic64_t *ptr)
18769 {
18770 return atomic64_add_return(1, ptr);
18771 }
18772 EXPORT_SYMBOL(atomic64_inc_return);
18773
18774+u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
18775+{
18776+ return atomic64_add_return_unchecked(1, ptr);
18777+}
18778+EXPORT_SYMBOL(atomic64_inc_return_unchecked);
18779+
18780 u64 atomic64_dec_return(atomic64_t *ptr)
18781 {
18782 return atomic64_sub_return(1, ptr);
18783 }
18784 EXPORT_SYMBOL(atomic64_dec_return);
18785
18786+u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
18787+{
18788+ return atomic64_sub_return_unchecked(1, ptr);
18789+}
18790+EXPORT_SYMBOL(atomic64_dec_return_unchecked);
18791+
18792 /**
18793 * atomic64_add - add integer to atomic64 variable
18794 * @delta: integer value to add
18795@@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t
18796 EXPORT_SYMBOL(atomic64_add);
18797
18798 /**
18799+ * atomic64_add_unchecked - add integer to atomic64 variable
18800+ * @delta: integer value to add
18801+ * @ptr: pointer to type atomic64_unchecked_t
18802+ *
18803+ * Atomically adds @delta to @ptr.
18804+ */
18805+void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18806+{
18807+ atomic64_add_return_unchecked(delta, ptr);
18808+}
18809+EXPORT_SYMBOL(atomic64_add_unchecked);
18810+
18811+/**
18812 * atomic64_sub - subtract the atomic64 variable
18813 * @delta: integer value to subtract
18814 * @ptr: pointer to type atomic64_t
18815@@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t
18816 EXPORT_SYMBOL(atomic64_sub);
18817
18818 /**
18819+ * atomic64_sub_unchecked - subtract the atomic64 variable
18820+ * @delta: integer value to subtract
18821+ * @ptr: pointer to type atomic64_unchecked_t
18822+ *
18823+ * Atomically subtracts @delta from @ptr.
18824+ */
18825+void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18826+{
18827+ atomic64_add_unchecked(-delta, ptr);
18828+}
18829+EXPORT_SYMBOL(atomic64_sub_unchecked);
18830+
18831+/**
18832 * atomic64_sub_and_test - subtract value from variable and test result
18833 * @delta: integer value to subtract
18834 * @ptr: pointer to type atomic64_t
18835@@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
18836 EXPORT_SYMBOL(atomic64_inc);
18837
18838 /**
18839+ * atomic64_inc_unchecked - increment atomic64 variable
18840+ * @ptr: pointer to type atomic64_unchecked_t
18841+ *
18842+ * Atomically increments @ptr by 1.
18843+ */
18844+void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
18845+{
18846+ atomic64_add_unchecked(1, ptr);
18847+}
18848+EXPORT_SYMBOL(atomic64_inc_unchecked);
18849+
18850+/**
18851 * atomic64_dec - decrement atomic64 variable
18852 * @ptr: pointer to type atomic64_t
18853 *
18854@@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
18855 EXPORT_SYMBOL(atomic64_dec);
18856
18857 /**
18858+ * atomic64_dec_unchecked - decrement atomic64 variable
18859+ * @ptr: pointer to type atomic64_unchecked_t
18860+ *
18861+ * Atomically decrements @ptr by 1.
18862+ */
18863+void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
18864+{
18865+ atomic64_sub_unchecked(1, ptr);
18866+}
18867+EXPORT_SYMBOL(atomic64_dec_unchecked);
18868+
18869+/**
18870 * atomic64_dec_and_test - decrement and test
18871 * @ptr: pointer to type atomic64_t
18872 *
18873diff -urNp linux-2.6.32.44/arch/x86/lib/checksum_32.S linux-2.6.32.44/arch/x86/lib/checksum_32.S
18874--- linux-2.6.32.44/arch/x86/lib/checksum_32.S 2011-03-27 14:31:47.000000000 -0400
18875+++ linux-2.6.32.44/arch/x86/lib/checksum_32.S 2011-04-17 15:56:46.000000000 -0400
18876@@ -28,7 +28,8 @@
18877 #include <linux/linkage.h>
18878 #include <asm/dwarf2.h>
18879 #include <asm/errno.h>
18880-
18881+#include <asm/segment.h>
18882+
18883 /*
18884 * computes a partial checksum, e.g. for TCP/UDP fragments
18885 */
18886@@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (
18887
18888 #define ARGBASE 16
18889 #define FP 12
18890-
18891-ENTRY(csum_partial_copy_generic)
18892+
18893+ENTRY(csum_partial_copy_generic_to_user)
18894 CFI_STARTPROC
18895+
18896+#ifdef CONFIG_PAX_MEMORY_UDEREF
18897+ pushl %gs
18898+ CFI_ADJUST_CFA_OFFSET 4
18899+ popl %es
18900+ CFI_ADJUST_CFA_OFFSET -4
18901+ jmp csum_partial_copy_generic
18902+#endif
18903+
18904+ENTRY(csum_partial_copy_generic_from_user)
18905+
18906+#ifdef CONFIG_PAX_MEMORY_UDEREF
18907+ pushl %gs
18908+ CFI_ADJUST_CFA_OFFSET 4
18909+ popl %ds
18910+ CFI_ADJUST_CFA_OFFSET -4
18911+#endif
18912+
18913+ENTRY(csum_partial_copy_generic)
18914 subl $4,%esp
18915 CFI_ADJUST_CFA_OFFSET 4
18916 pushl %edi
18917@@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
18918 jmp 4f
18919 SRC(1: movw (%esi), %bx )
18920 addl $2, %esi
18921-DST( movw %bx, (%edi) )
18922+DST( movw %bx, %es:(%edi) )
18923 addl $2, %edi
18924 addw %bx, %ax
18925 adcl $0, %eax
18926@@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
18927 SRC(1: movl (%esi), %ebx )
18928 SRC( movl 4(%esi), %edx )
18929 adcl %ebx, %eax
18930-DST( movl %ebx, (%edi) )
18931+DST( movl %ebx, %es:(%edi) )
18932 adcl %edx, %eax
18933-DST( movl %edx, 4(%edi) )
18934+DST( movl %edx, %es:4(%edi) )
18935
18936 SRC( movl 8(%esi), %ebx )
18937 SRC( movl 12(%esi), %edx )
18938 adcl %ebx, %eax
18939-DST( movl %ebx, 8(%edi) )
18940+DST( movl %ebx, %es:8(%edi) )
18941 adcl %edx, %eax
18942-DST( movl %edx, 12(%edi) )
18943+DST( movl %edx, %es:12(%edi) )
18944
18945 SRC( movl 16(%esi), %ebx )
18946 SRC( movl 20(%esi), %edx )
18947 adcl %ebx, %eax
18948-DST( movl %ebx, 16(%edi) )
18949+DST( movl %ebx, %es:16(%edi) )
18950 adcl %edx, %eax
18951-DST( movl %edx, 20(%edi) )
18952+DST( movl %edx, %es:20(%edi) )
18953
18954 SRC( movl 24(%esi), %ebx )
18955 SRC( movl 28(%esi), %edx )
18956 adcl %ebx, %eax
18957-DST( movl %ebx, 24(%edi) )
18958+DST( movl %ebx, %es:24(%edi) )
18959 adcl %edx, %eax
18960-DST( movl %edx, 28(%edi) )
18961+DST( movl %edx, %es:28(%edi) )
18962
18963 lea 32(%esi), %esi
18964 lea 32(%edi), %edi
18965@@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
18966 shrl $2, %edx # This clears CF
18967 SRC(3: movl (%esi), %ebx )
18968 adcl %ebx, %eax
18969-DST( movl %ebx, (%edi) )
18970+DST( movl %ebx, %es:(%edi) )
18971 lea 4(%esi), %esi
18972 lea 4(%edi), %edi
18973 dec %edx
18974@@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
18975 jb 5f
18976 SRC( movw (%esi), %cx )
18977 leal 2(%esi), %esi
18978-DST( movw %cx, (%edi) )
18979+DST( movw %cx, %es:(%edi) )
18980 leal 2(%edi), %edi
18981 je 6f
18982 shll $16,%ecx
18983 SRC(5: movb (%esi), %cl )
18984-DST( movb %cl, (%edi) )
18985+DST( movb %cl, %es:(%edi) )
18986 6: addl %ecx, %eax
18987 adcl $0, %eax
18988 7:
18989@@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
18990
18991 6001:
18992 movl ARGBASE+20(%esp), %ebx # src_err_ptr
18993- movl $-EFAULT, (%ebx)
18994+ movl $-EFAULT, %ss:(%ebx)
18995
18996 # zero the complete destination - computing the rest
18997 # is too much work
18998@@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
18999
19000 6002:
19001 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19002- movl $-EFAULT,(%ebx)
19003+ movl $-EFAULT,%ss:(%ebx)
19004 jmp 5000b
19005
19006 .previous
19007
19008+ pushl %ss
19009+ CFI_ADJUST_CFA_OFFSET 4
19010+ popl %ds
19011+ CFI_ADJUST_CFA_OFFSET -4
19012+ pushl %ss
19013+ CFI_ADJUST_CFA_OFFSET 4
19014+ popl %es
19015+ CFI_ADJUST_CFA_OFFSET -4
19016 popl %ebx
19017 CFI_ADJUST_CFA_OFFSET -4
19018 CFI_RESTORE ebx
19019@@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
19020 CFI_ADJUST_CFA_OFFSET -4
19021 ret
19022 CFI_ENDPROC
19023-ENDPROC(csum_partial_copy_generic)
19024+ENDPROC(csum_partial_copy_generic_to_user)
19025
19026 #else
19027
19028 /* Version for PentiumII/PPro */
19029
19030 #define ROUND1(x) \
19031+ nop; nop; nop; \
19032 SRC(movl x(%esi), %ebx ) ; \
19033 addl %ebx, %eax ; \
19034- DST(movl %ebx, x(%edi) ) ;
19035+ DST(movl %ebx, %es:x(%edi)) ;
19036
19037 #define ROUND(x) \
19038+ nop; nop; nop; \
19039 SRC(movl x(%esi), %ebx ) ; \
19040 adcl %ebx, %eax ; \
19041- DST(movl %ebx, x(%edi) ) ;
19042+ DST(movl %ebx, %es:x(%edi)) ;
19043
19044 #define ARGBASE 12
19045-
19046-ENTRY(csum_partial_copy_generic)
19047+
19048+ENTRY(csum_partial_copy_generic_to_user)
19049 CFI_STARTPROC
19050+
19051+#ifdef CONFIG_PAX_MEMORY_UDEREF
19052+ pushl %gs
19053+ CFI_ADJUST_CFA_OFFSET 4
19054+ popl %es
19055+ CFI_ADJUST_CFA_OFFSET -4
19056+ jmp csum_partial_copy_generic
19057+#endif
19058+
19059+ENTRY(csum_partial_copy_generic_from_user)
19060+
19061+#ifdef CONFIG_PAX_MEMORY_UDEREF
19062+ pushl %gs
19063+ CFI_ADJUST_CFA_OFFSET 4
19064+ popl %ds
19065+ CFI_ADJUST_CFA_OFFSET -4
19066+#endif
19067+
19068+ENTRY(csum_partial_copy_generic)
19069 pushl %ebx
19070 CFI_ADJUST_CFA_OFFSET 4
19071 CFI_REL_OFFSET ebx, 0
19072@@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
19073 subl %ebx, %edi
19074 lea -1(%esi),%edx
19075 andl $-32,%edx
19076- lea 3f(%ebx,%ebx), %ebx
19077+ lea 3f(%ebx,%ebx,2), %ebx
19078 testl %esi, %esi
19079 jmp *%ebx
19080 1: addl $64,%esi
19081@@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
19082 jb 5f
19083 SRC( movw (%esi), %dx )
19084 leal 2(%esi), %esi
19085-DST( movw %dx, (%edi) )
19086+DST( movw %dx, %es:(%edi) )
19087 leal 2(%edi), %edi
19088 je 6f
19089 shll $16,%edx
19090 5:
19091 SRC( movb (%esi), %dl )
19092-DST( movb %dl, (%edi) )
19093+DST( movb %dl, %es:(%edi) )
19094 6: addl %edx, %eax
19095 adcl $0, %eax
19096 7:
19097 .section .fixup, "ax"
19098 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19099- movl $-EFAULT, (%ebx)
19100+ movl $-EFAULT, %ss:(%ebx)
19101 # zero the complete destination (computing the rest is too much work)
19102 movl ARGBASE+8(%esp),%edi # dst
19103 movl ARGBASE+12(%esp),%ecx # len
19104@@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
19105 rep; stosb
19106 jmp 7b
19107 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19108- movl $-EFAULT, (%ebx)
19109+ movl $-EFAULT, %ss:(%ebx)
19110 jmp 7b
19111 .previous
19112
19113+#ifdef CONFIG_PAX_MEMORY_UDEREF
19114+ pushl %ss
19115+ CFI_ADJUST_CFA_OFFSET 4
19116+ popl %ds
19117+ CFI_ADJUST_CFA_OFFSET -4
19118+ pushl %ss
19119+ CFI_ADJUST_CFA_OFFSET 4
19120+ popl %es
19121+ CFI_ADJUST_CFA_OFFSET -4
19122+#endif
19123+
19124 popl %esi
19125 CFI_ADJUST_CFA_OFFSET -4
19126 CFI_RESTORE esi
19127@@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
19128 CFI_RESTORE ebx
19129 ret
19130 CFI_ENDPROC
19131-ENDPROC(csum_partial_copy_generic)
19132+ENDPROC(csum_partial_copy_generic_to_user)
19133
19134 #undef ROUND
19135 #undef ROUND1
19136diff -urNp linux-2.6.32.44/arch/x86/lib/clear_page_64.S linux-2.6.32.44/arch/x86/lib/clear_page_64.S
19137--- linux-2.6.32.44/arch/x86/lib/clear_page_64.S 2011-03-27 14:31:47.000000000 -0400
19138+++ linux-2.6.32.44/arch/x86/lib/clear_page_64.S 2011-04-17 15:56:46.000000000 -0400
19139@@ -43,7 +43,7 @@ ENDPROC(clear_page)
19140
19141 #include <asm/cpufeature.h>
19142
19143- .section .altinstr_replacement,"ax"
19144+ .section .altinstr_replacement,"a"
19145 1: .byte 0xeb /* jmp <disp8> */
19146 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19147 2:
19148diff -urNp linux-2.6.32.44/arch/x86/lib/copy_page_64.S linux-2.6.32.44/arch/x86/lib/copy_page_64.S
19149--- linux-2.6.32.44/arch/x86/lib/copy_page_64.S 2011-03-27 14:31:47.000000000 -0400
19150+++ linux-2.6.32.44/arch/x86/lib/copy_page_64.S 2011-04-17 15:56:46.000000000 -0400
19151@@ -104,7 +104,7 @@ ENDPROC(copy_page)
19152
19153 #include <asm/cpufeature.h>
19154
19155- .section .altinstr_replacement,"ax"
19156+ .section .altinstr_replacement,"a"
19157 1: .byte 0xeb /* jmp <disp8> */
19158 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19159 2:
19160diff -urNp linux-2.6.32.44/arch/x86/lib/copy_user_64.S linux-2.6.32.44/arch/x86/lib/copy_user_64.S
19161--- linux-2.6.32.44/arch/x86/lib/copy_user_64.S 2011-06-25 12:55:34.000000000 -0400
19162+++ linux-2.6.32.44/arch/x86/lib/copy_user_64.S 2011-06-25 12:56:37.000000000 -0400
19163@@ -15,13 +15,14 @@
19164 #include <asm/asm-offsets.h>
19165 #include <asm/thread_info.h>
19166 #include <asm/cpufeature.h>
19167+#include <asm/pgtable.h>
19168
19169 .macro ALTERNATIVE_JUMP feature,orig,alt
19170 0:
19171 .byte 0xe9 /* 32bit jump */
19172 .long \orig-1f /* by default jump to orig */
19173 1:
19174- .section .altinstr_replacement,"ax"
19175+ .section .altinstr_replacement,"a"
19176 2: .byte 0xe9 /* near jump with 32bit immediate */
19177 .long \alt-1b /* offset */ /* or alternatively to alt */
19178 .previous
19179@@ -64,49 +65,19 @@
19180 #endif
19181 .endm
19182
19183-/* Standard copy_to_user with segment limit checking */
19184-ENTRY(copy_to_user)
19185- CFI_STARTPROC
19186- GET_THREAD_INFO(%rax)
19187- movq %rdi,%rcx
19188- addq %rdx,%rcx
19189- jc bad_to_user
19190- cmpq TI_addr_limit(%rax),%rcx
19191- ja bad_to_user
19192- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19193- CFI_ENDPROC
19194-ENDPROC(copy_to_user)
19195-
19196-/* Standard copy_from_user with segment limit checking */
19197-ENTRY(copy_from_user)
19198- CFI_STARTPROC
19199- GET_THREAD_INFO(%rax)
19200- movq %rsi,%rcx
19201- addq %rdx,%rcx
19202- jc bad_from_user
19203- cmpq TI_addr_limit(%rax),%rcx
19204- ja bad_from_user
19205- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19206- CFI_ENDPROC
19207-ENDPROC(copy_from_user)
19208-
19209 ENTRY(copy_user_generic)
19210 CFI_STARTPROC
19211 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19212 CFI_ENDPROC
19213 ENDPROC(copy_user_generic)
19214
19215-ENTRY(__copy_from_user_inatomic)
19216- CFI_STARTPROC
19217- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19218- CFI_ENDPROC
19219-ENDPROC(__copy_from_user_inatomic)
19220-
19221 .section .fixup,"ax"
19222 /* must zero dest */
19223 ENTRY(bad_from_user)
19224 bad_from_user:
19225 CFI_STARTPROC
19226+ testl %edx,%edx
19227+ js bad_to_user
19228 movl %edx,%ecx
19229 xorl %eax,%eax
19230 rep
19231diff -urNp linux-2.6.32.44/arch/x86/lib/copy_user_nocache_64.S linux-2.6.32.44/arch/x86/lib/copy_user_nocache_64.S
19232--- linux-2.6.32.44/arch/x86/lib/copy_user_nocache_64.S 2011-03-27 14:31:47.000000000 -0400
19233+++ linux-2.6.32.44/arch/x86/lib/copy_user_nocache_64.S 2011-04-17 15:56:46.000000000 -0400
19234@@ -14,6 +14,7 @@
19235 #include <asm/current.h>
19236 #include <asm/asm-offsets.h>
19237 #include <asm/thread_info.h>
19238+#include <asm/pgtable.h>
19239
19240 .macro ALIGN_DESTINATION
19241 #ifdef FIX_ALIGNMENT
19242@@ -50,6 +51,15 @@
19243 */
19244 ENTRY(__copy_user_nocache)
19245 CFI_STARTPROC
19246+
19247+#ifdef CONFIG_PAX_MEMORY_UDEREF
19248+ mov $PAX_USER_SHADOW_BASE,%rcx
19249+ cmp %rcx,%rsi
19250+ jae 1f
19251+ add %rcx,%rsi
19252+1:
19253+#endif
19254+
19255 cmpl $8,%edx
19256 jb 20f /* less then 8 bytes, go to byte copy loop */
19257 ALIGN_DESTINATION
19258diff -urNp linux-2.6.32.44/arch/x86/lib/csum-wrappers_64.c linux-2.6.32.44/arch/x86/lib/csum-wrappers_64.c
19259--- linux-2.6.32.44/arch/x86/lib/csum-wrappers_64.c 2011-03-27 14:31:47.000000000 -0400
19260+++ linux-2.6.32.44/arch/x86/lib/csum-wrappers_64.c 2011-05-04 17:56:20.000000000 -0400
19261@@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19262 len -= 2;
19263 }
19264 }
19265+
19266+#ifdef CONFIG_PAX_MEMORY_UDEREF
19267+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19268+ src += PAX_USER_SHADOW_BASE;
19269+#endif
19270+
19271 isum = csum_partial_copy_generic((__force const void *)src,
19272 dst, len, isum, errp, NULL);
19273 if (unlikely(*errp))
19274@@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19275 }
19276
19277 *errp = 0;
19278+
19279+#ifdef CONFIG_PAX_MEMORY_UDEREF
19280+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19281+ dst += PAX_USER_SHADOW_BASE;
19282+#endif
19283+
19284 return csum_partial_copy_generic(src, (void __force *)dst,
19285 len, isum, NULL, errp);
19286 }
19287diff -urNp linux-2.6.32.44/arch/x86/lib/getuser.S linux-2.6.32.44/arch/x86/lib/getuser.S
19288--- linux-2.6.32.44/arch/x86/lib/getuser.S 2011-03-27 14:31:47.000000000 -0400
19289+++ linux-2.6.32.44/arch/x86/lib/getuser.S 2011-04-17 15:56:46.000000000 -0400
19290@@ -33,14 +33,35 @@
19291 #include <asm/asm-offsets.h>
19292 #include <asm/thread_info.h>
19293 #include <asm/asm.h>
19294+#include <asm/segment.h>
19295+#include <asm/pgtable.h>
19296+
19297+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19298+#define __copyuser_seg gs;
19299+#else
19300+#define __copyuser_seg
19301+#endif
19302
19303 .text
19304 ENTRY(__get_user_1)
19305 CFI_STARTPROC
19306+
19307+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19308 GET_THREAD_INFO(%_ASM_DX)
19309 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19310 jae bad_get_user
19311-1: movzb (%_ASM_AX),%edx
19312+
19313+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19314+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19315+ cmp %_ASM_DX,%_ASM_AX
19316+ jae 1234f
19317+ add %_ASM_DX,%_ASM_AX
19318+1234:
19319+#endif
19320+
19321+#endif
19322+
19323+1: __copyuser_seg movzb (%_ASM_AX),%edx
19324 xor %eax,%eax
19325 ret
19326 CFI_ENDPROC
19327@@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19328 ENTRY(__get_user_2)
19329 CFI_STARTPROC
19330 add $1,%_ASM_AX
19331+
19332+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19333 jc bad_get_user
19334 GET_THREAD_INFO(%_ASM_DX)
19335 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19336 jae bad_get_user
19337-2: movzwl -1(%_ASM_AX),%edx
19338+
19339+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19340+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19341+ cmp %_ASM_DX,%_ASM_AX
19342+ jae 1234f
19343+ add %_ASM_DX,%_ASM_AX
19344+1234:
19345+#endif
19346+
19347+#endif
19348+
19349+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19350 xor %eax,%eax
19351 ret
19352 CFI_ENDPROC
19353@@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19354 ENTRY(__get_user_4)
19355 CFI_STARTPROC
19356 add $3,%_ASM_AX
19357+
19358+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19359 jc bad_get_user
19360 GET_THREAD_INFO(%_ASM_DX)
19361 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19362 jae bad_get_user
19363-3: mov -3(%_ASM_AX),%edx
19364+
19365+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19366+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19367+ cmp %_ASM_DX,%_ASM_AX
19368+ jae 1234f
19369+ add %_ASM_DX,%_ASM_AX
19370+1234:
19371+#endif
19372+
19373+#endif
19374+
19375+3: __copyuser_seg mov -3(%_ASM_AX),%edx
19376 xor %eax,%eax
19377 ret
19378 CFI_ENDPROC
19379@@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19380 GET_THREAD_INFO(%_ASM_DX)
19381 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19382 jae bad_get_user
19383+
19384+#ifdef CONFIG_PAX_MEMORY_UDEREF
19385+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19386+ cmp %_ASM_DX,%_ASM_AX
19387+ jae 1234f
19388+ add %_ASM_DX,%_ASM_AX
19389+1234:
19390+#endif
19391+
19392 4: movq -7(%_ASM_AX),%_ASM_DX
19393 xor %eax,%eax
19394 ret
19395diff -urNp linux-2.6.32.44/arch/x86/lib/memcpy_64.S linux-2.6.32.44/arch/x86/lib/memcpy_64.S
19396--- linux-2.6.32.44/arch/x86/lib/memcpy_64.S 2011-03-27 14:31:47.000000000 -0400
19397+++ linux-2.6.32.44/arch/x86/lib/memcpy_64.S 2011-04-17 15:56:46.000000000 -0400
19398@@ -128,7 +128,7 @@ ENDPROC(__memcpy)
19399 * It is also a lot simpler. Use this when possible:
19400 */
19401
19402- .section .altinstr_replacement, "ax"
19403+ .section .altinstr_replacement, "a"
19404 1: .byte 0xeb /* jmp <disp8> */
19405 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
19406 2:
19407diff -urNp linux-2.6.32.44/arch/x86/lib/memset_64.S linux-2.6.32.44/arch/x86/lib/memset_64.S
19408--- linux-2.6.32.44/arch/x86/lib/memset_64.S 2011-03-27 14:31:47.000000000 -0400
19409+++ linux-2.6.32.44/arch/x86/lib/memset_64.S 2011-04-17 15:56:46.000000000 -0400
19410@@ -118,7 +118,7 @@ ENDPROC(__memset)
19411
19412 #include <asm/cpufeature.h>
19413
19414- .section .altinstr_replacement,"ax"
19415+ .section .altinstr_replacement,"a"
19416 1: .byte 0xeb /* jmp <disp8> */
19417 .byte (memset_c - memset) - (2f - 1b) /* offset */
19418 2:
19419diff -urNp linux-2.6.32.44/arch/x86/lib/mmx_32.c linux-2.6.32.44/arch/x86/lib/mmx_32.c
19420--- linux-2.6.32.44/arch/x86/lib/mmx_32.c 2011-03-27 14:31:47.000000000 -0400
19421+++ linux-2.6.32.44/arch/x86/lib/mmx_32.c 2011-04-17 15:56:46.000000000 -0400
19422@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19423 {
19424 void *p;
19425 int i;
19426+ unsigned long cr0;
19427
19428 if (unlikely(in_interrupt()))
19429 return __memcpy(to, from, len);
19430@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19431 kernel_fpu_begin();
19432
19433 __asm__ __volatile__ (
19434- "1: prefetch (%0)\n" /* This set is 28 bytes */
19435- " prefetch 64(%0)\n"
19436- " prefetch 128(%0)\n"
19437- " prefetch 192(%0)\n"
19438- " prefetch 256(%0)\n"
19439+ "1: prefetch (%1)\n" /* This set is 28 bytes */
19440+ " prefetch 64(%1)\n"
19441+ " prefetch 128(%1)\n"
19442+ " prefetch 192(%1)\n"
19443+ " prefetch 256(%1)\n"
19444 "2: \n"
19445 ".section .fixup, \"ax\"\n"
19446- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19447+ "3: \n"
19448+
19449+#ifdef CONFIG_PAX_KERNEXEC
19450+ " movl %%cr0, %0\n"
19451+ " movl %0, %%eax\n"
19452+ " andl $0xFFFEFFFF, %%eax\n"
19453+ " movl %%eax, %%cr0\n"
19454+#endif
19455+
19456+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19457+
19458+#ifdef CONFIG_PAX_KERNEXEC
19459+ " movl %0, %%cr0\n"
19460+#endif
19461+
19462 " jmp 2b\n"
19463 ".previous\n"
19464 _ASM_EXTABLE(1b, 3b)
19465- : : "r" (from));
19466+ : "=&r" (cr0) : "r" (from) : "ax");
19467
19468 for ( ; i > 5; i--) {
19469 __asm__ __volatile__ (
19470- "1: prefetch 320(%0)\n"
19471- "2: movq (%0), %%mm0\n"
19472- " movq 8(%0), %%mm1\n"
19473- " movq 16(%0), %%mm2\n"
19474- " movq 24(%0), %%mm3\n"
19475- " movq %%mm0, (%1)\n"
19476- " movq %%mm1, 8(%1)\n"
19477- " movq %%mm2, 16(%1)\n"
19478- " movq %%mm3, 24(%1)\n"
19479- " movq 32(%0), %%mm0\n"
19480- " movq 40(%0), %%mm1\n"
19481- " movq 48(%0), %%mm2\n"
19482- " movq 56(%0), %%mm3\n"
19483- " movq %%mm0, 32(%1)\n"
19484- " movq %%mm1, 40(%1)\n"
19485- " movq %%mm2, 48(%1)\n"
19486- " movq %%mm3, 56(%1)\n"
19487+ "1: prefetch 320(%1)\n"
19488+ "2: movq (%1), %%mm0\n"
19489+ " movq 8(%1), %%mm1\n"
19490+ " movq 16(%1), %%mm2\n"
19491+ " movq 24(%1), %%mm3\n"
19492+ " movq %%mm0, (%2)\n"
19493+ " movq %%mm1, 8(%2)\n"
19494+ " movq %%mm2, 16(%2)\n"
19495+ " movq %%mm3, 24(%2)\n"
19496+ " movq 32(%1), %%mm0\n"
19497+ " movq 40(%1), %%mm1\n"
19498+ " movq 48(%1), %%mm2\n"
19499+ " movq 56(%1), %%mm3\n"
19500+ " movq %%mm0, 32(%2)\n"
19501+ " movq %%mm1, 40(%2)\n"
19502+ " movq %%mm2, 48(%2)\n"
19503+ " movq %%mm3, 56(%2)\n"
19504 ".section .fixup, \"ax\"\n"
19505- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19506+ "3:\n"
19507+
19508+#ifdef CONFIG_PAX_KERNEXEC
19509+ " movl %%cr0, %0\n"
19510+ " movl %0, %%eax\n"
19511+ " andl $0xFFFEFFFF, %%eax\n"
19512+ " movl %%eax, %%cr0\n"
19513+#endif
19514+
19515+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19516+
19517+#ifdef CONFIG_PAX_KERNEXEC
19518+ " movl %0, %%cr0\n"
19519+#endif
19520+
19521 " jmp 2b\n"
19522 ".previous\n"
19523 _ASM_EXTABLE(1b, 3b)
19524- : : "r" (from), "r" (to) : "memory");
19525+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19526
19527 from += 64;
19528 to += 64;
19529@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19530 static void fast_copy_page(void *to, void *from)
19531 {
19532 int i;
19533+ unsigned long cr0;
19534
19535 kernel_fpu_begin();
19536
19537@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19538 * but that is for later. -AV
19539 */
19540 __asm__ __volatile__(
19541- "1: prefetch (%0)\n"
19542- " prefetch 64(%0)\n"
19543- " prefetch 128(%0)\n"
19544- " prefetch 192(%0)\n"
19545- " prefetch 256(%0)\n"
19546+ "1: prefetch (%1)\n"
19547+ " prefetch 64(%1)\n"
19548+ " prefetch 128(%1)\n"
19549+ " prefetch 192(%1)\n"
19550+ " prefetch 256(%1)\n"
19551 "2: \n"
19552 ".section .fixup, \"ax\"\n"
19553- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19554+ "3: \n"
19555+
19556+#ifdef CONFIG_PAX_KERNEXEC
19557+ " movl %%cr0, %0\n"
19558+ " movl %0, %%eax\n"
19559+ " andl $0xFFFEFFFF, %%eax\n"
19560+ " movl %%eax, %%cr0\n"
19561+#endif
19562+
19563+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19564+
19565+#ifdef CONFIG_PAX_KERNEXEC
19566+ " movl %0, %%cr0\n"
19567+#endif
19568+
19569 " jmp 2b\n"
19570 ".previous\n"
19571- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19572+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19573
19574 for (i = 0; i < (4096-320)/64; i++) {
19575 __asm__ __volatile__ (
19576- "1: prefetch 320(%0)\n"
19577- "2: movq (%0), %%mm0\n"
19578- " movntq %%mm0, (%1)\n"
19579- " movq 8(%0), %%mm1\n"
19580- " movntq %%mm1, 8(%1)\n"
19581- " movq 16(%0), %%mm2\n"
19582- " movntq %%mm2, 16(%1)\n"
19583- " movq 24(%0), %%mm3\n"
19584- " movntq %%mm3, 24(%1)\n"
19585- " movq 32(%0), %%mm4\n"
19586- " movntq %%mm4, 32(%1)\n"
19587- " movq 40(%0), %%mm5\n"
19588- " movntq %%mm5, 40(%1)\n"
19589- " movq 48(%0), %%mm6\n"
19590- " movntq %%mm6, 48(%1)\n"
19591- " movq 56(%0), %%mm7\n"
19592- " movntq %%mm7, 56(%1)\n"
19593+ "1: prefetch 320(%1)\n"
19594+ "2: movq (%1), %%mm0\n"
19595+ " movntq %%mm0, (%2)\n"
19596+ " movq 8(%1), %%mm1\n"
19597+ " movntq %%mm1, 8(%2)\n"
19598+ " movq 16(%1), %%mm2\n"
19599+ " movntq %%mm2, 16(%2)\n"
19600+ " movq 24(%1), %%mm3\n"
19601+ " movntq %%mm3, 24(%2)\n"
19602+ " movq 32(%1), %%mm4\n"
19603+ " movntq %%mm4, 32(%2)\n"
19604+ " movq 40(%1), %%mm5\n"
19605+ " movntq %%mm5, 40(%2)\n"
19606+ " movq 48(%1), %%mm6\n"
19607+ " movntq %%mm6, 48(%2)\n"
19608+ " movq 56(%1), %%mm7\n"
19609+ " movntq %%mm7, 56(%2)\n"
19610 ".section .fixup, \"ax\"\n"
19611- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19612+ "3:\n"
19613+
19614+#ifdef CONFIG_PAX_KERNEXEC
19615+ " movl %%cr0, %0\n"
19616+ " movl %0, %%eax\n"
19617+ " andl $0xFFFEFFFF, %%eax\n"
19618+ " movl %%eax, %%cr0\n"
19619+#endif
19620+
19621+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19622+
19623+#ifdef CONFIG_PAX_KERNEXEC
19624+ " movl %0, %%cr0\n"
19625+#endif
19626+
19627 " jmp 2b\n"
19628 ".previous\n"
19629- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
19630+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19631
19632 from += 64;
19633 to += 64;
19634@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
19635 static void fast_copy_page(void *to, void *from)
19636 {
19637 int i;
19638+ unsigned long cr0;
19639
19640 kernel_fpu_begin();
19641
19642 __asm__ __volatile__ (
19643- "1: prefetch (%0)\n"
19644- " prefetch 64(%0)\n"
19645- " prefetch 128(%0)\n"
19646- " prefetch 192(%0)\n"
19647- " prefetch 256(%0)\n"
19648+ "1: prefetch (%1)\n"
19649+ " prefetch 64(%1)\n"
19650+ " prefetch 128(%1)\n"
19651+ " prefetch 192(%1)\n"
19652+ " prefetch 256(%1)\n"
19653 "2: \n"
19654 ".section .fixup, \"ax\"\n"
19655- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19656+ "3: \n"
19657+
19658+#ifdef CONFIG_PAX_KERNEXEC
19659+ " movl %%cr0, %0\n"
19660+ " movl %0, %%eax\n"
19661+ " andl $0xFFFEFFFF, %%eax\n"
19662+ " movl %%eax, %%cr0\n"
19663+#endif
19664+
19665+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19666+
19667+#ifdef CONFIG_PAX_KERNEXEC
19668+ " movl %0, %%cr0\n"
19669+#endif
19670+
19671 " jmp 2b\n"
19672 ".previous\n"
19673- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19674+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19675
19676 for (i = 0; i < 4096/64; i++) {
19677 __asm__ __volatile__ (
19678- "1: prefetch 320(%0)\n"
19679- "2: movq (%0), %%mm0\n"
19680- " movq 8(%0), %%mm1\n"
19681- " movq 16(%0), %%mm2\n"
19682- " movq 24(%0), %%mm3\n"
19683- " movq %%mm0, (%1)\n"
19684- " movq %%mm1, 8(%1)\n"
19685- " movq %%mm2, 16(%1)\n"
19686- " movq %%mm3, 24(%1)\n"
19687- " movq 32(%0), %%mm0\n"
19688- " movq 40(%0), %%mm1\n"
19689- " movq 48(%0), %%mm2\n"
19690- " movq 56(%0), %%mm3\n"
19691- " movq %%mm0, 32(%1)\n"
19692- " movq %%mm1, 40(%1)\n"
19693- " movq %%mm2, 48(%1)\n"
19694- " movq %%mm3, 56(%1)\n"
19695+ "1: prefetch 320(%1)\n"
19696+ "2: movq (%1), %%mm0\n"
19697+ " movq 8(%1), %%mm1\n"
19698+ " movq 16(%1), %%mm2\n"
19699+ " movq 24(%1), %%mm3\n"
19700+ " movq %%mm0, (%2)\n"
19701+ " movq %%mm1, 8(%2)\n"
19702+ " movq %%mm2, 16(%2)\n"
19703+ " movq %%mm3, 24(%2)\n"
19704+ " movq 32(%1), %%mm0\n"
19705+ " movq 40(%1), %%mm1\n"
19706+ " movq 48(%1), %%mm2\n"
19707+ " movq 56(%1), %%mm3\n"
19708+ " movq %%mm0, 32(%2)\n"
19709+ " movq %%mm1, 40(%2)\n"
19710+ " movq %%mm2, 48(%2)\n"
19711+ " movq %%mm3, 56(%2)\n"
19712 ".section .fixup, \"ax\"\n"
19713- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19714+ "3:\n"
19715+
19716+#ifdef CONFIG_PAX_KERNEXEC
19717+ " movl %%cr0, %0\n"
19718+ " movl %0, %%eax\n"
19719+ " andl $0xFFFEFFFF, %%eax\n"
19720+ " movl %%eax, %%cr0\n"
19721+#endif
19722+
19723+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19724+
19725+#ifdef CONFIG_PAX_KERNEXEC
19726+ " movl %0, %%cr0\n"
19727+#endif
19728+
19729 " jmp 2b\n"
19730 ".previous\n"
19731 _ASM_EXTABLE(1b, 3b)
19732- : : "r" (from), "r" (to) : "memory");
19733+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19734
19735 from += 64;
19736 to += 64;
19737diff -urNp linux-2.6.32.44/arch/x86/lib/putuser.S linux-2.6.32.44/arch/x86/lib/putuser.S
19738--- linux-2.6.32.44/arch/x86/lib/putuser.S 2011-03-27 14:31:47.000000000 -0400
19739+++ linux-2.6.32.44/arch/x86/lib/putuser.S 2011-04-17 15:56:46.000000000 -0400
19740@@ -15,7 +15,8 @@
19741 #include <asm/thread_info.h>
19742 #include <asm/errno.h>
19743 #include <asm/asm.h>
19744-
19745+#include <asm/segment.h>
19746+#include <asm/pgtable.h>
19747
19748 /*
19749 * __put_user_X
19750@@ -29,52 +30,119 @@
19751 * as they get called from within inline assembly.
19752 */
19753
19754-#define ENTER CFI_STARTPROC ; \
19755- GET_THREAD_INFO(%_ASM_BX)
19756+#define ENTER CFI_STARTPROC
19757 #define EXIT ret ; \
19758 CFI_ENDPROC
19759
19760+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19761+#define _DEST %_ASM_CX,%_ASM_BX
19762+#else
19763+#define _DEST %_ASM_CX
19764+#endif
19765+
19766+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19767+#define __copyuser_seg gs;
19768+#else
19769+#define __copyuser_seg
19770+#endif
19771+
19772 .text
19773 ENTRY(__put_user_1)
19774 ENTER
19775+
19776+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19777+ GET_THREAD_INFO(%_ASM_BX)
19778 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
19779 jae bad_put_user
19780-1: movb %al,(%_ASM_CX)
19781+
19782+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19783+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19784+ cmp %_ASM_BX,%_ASM_CX
19785+ jb 1234f
19786+ xor %ebx,%ebx
19787+1234:
19788+#endif
19789+
19790+#endif
19791+
19792+1: __copyuser_seg movb %al,(_DEST)
19793 xor %eax,%eax
19794 EXIT
19795 ENDPROC(__put_user_1)
19796
19797 ENTRY(__put_user_2)
19798 ENTER
19799+
19800+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19801+ GET_THREAD_INFO(%_ASM_BX)
19802 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
19803 sub $1,%_ASM_BX
19804 cmp %_ASM_BX,%_ASM_CX
19805 jae bad_put_user
19806-2: movw %ax,(%_ASM_CX)
19807+
19808+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19809+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19810+ cmp %_ASM_BX,%_ASM_CX
19811+ jb 1234f
19812+ xor %ebx,%ebx
19813+1234:
19814+#endif
19815+
19816+#endif
19817+
19818+2: __copyuser_seg movw %ax,(_DEST)
19819 xor %eax,%eax
19820 EXIT
19821 ENDPROC(__put_user_2)
19822
19823 ENTRY(__put_user_4)
19824 ENTER
19825+
19826+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19827+ GET_THREAD_INFO(%_ASM_BX)
19828 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
19829 sub $3,%_ASM_BX
19830 cmp %_ASM_BX,%_ASM_CX
19831 jae bad_put_user
19832-3: movl %eax,(%_ASM_CX)
19833+
19834+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19835+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19836+ cmp %_ASM_BX,%_ASM_CX
19837+ jb 1234f
19838+ xor %ebx,%ebx
19839+1234:
19840+#endif
19841+
19842+#endif
19843+
19844+3: __copyuser_seg movl %eax,(_DEST)
19845 xor %eax,%eax
19846 EXIT
19847 ENDPROC(__put_user_4)
19848
19849 ENTRY(__put_user_8)
19850 ENTER
19851+
19852+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19853+ GET_THREAD_INFO(%_ASM_BX)
19854 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
19855 sub $7,%_ASM_BX
19856 cmp %_ASM_BX,%_ASM_CX
19857 jae bad_put_user
19858-4: mov %_ASM_AX,(%_ASM_CX)
19859+
19860+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19861+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19862+ cmp %_ASM_BX,%_ASM_CX
19863+ jb 1234f
19864+ xor %ebx,%ebx
19865+1234:
19866+#endif
19867+
19868+#endif
19869+
19870+4: __copyuser_seg mov %_ASM_AX,(_DEST)
19871 #ifdef CONFIG_X86_32
19872-5: movl %edx,4(%_ASM_CX)
19873+5: __copyuser_seg movl %edx,4(_DEST)
19874 #endif
19875 xor %eax,%eax
19876 EXIT
19877diff -urNp linux-2.6.32.44/arch/x86/lib/usercopy_32.c linux-2.6.32.44/arch/x86/lib/usercopy_32.c
19878--- linux-2.6.32.44/arch/x86/lib/usercopy_32.c 2011-03-27 14:31:47.000000000 -0400
19879+++ linux-2.6.32.44/arch/x86/lib/usercopy_32.c 2011-04-23 21:12:28.000000000 -0400
19880@@ -43,7 +43,7 @@ do { \
19881 __asm__ __volatile__( \
19882 " testl %1,%1\n" \
19883 " jz 2f\n" \
19884- "0: lodsb\n" \
19885+ "0: "__copyuser_seg"lodsb\n" \
19886 " stosb\n" \
19887 " testb %%al,%%al\n" \
19888 " jz 1f\n" \
19889@@ -128,10 +128,12 @@ do { \
19890 int __d0; \
19891 might_fault(); \
19892 __asm__ __volatile__( \
19893+ __COPYUSER_SET_ES \
19894 "0: rep; stosl\n" \
19895 " movl %2,%0\n" \
19896 "1: rep; stosb\n" \
19897 "2:\n" \
19898+ __COPYUSER_RESTORE_ES \
19899 ".section .fixup,\"ax\"\n" \
19900 "3: lea 0(%2,%0,4),%0\n" \
19901 " jmp 2b\n" \
19902@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
19903 might_fault();
19904
19905 __asm__ __volatile__(
19906+ __COPYUSER_SET_ES
19907 " testl %0, %0\n"
19908 " jz 3f\n"
19909 " andl %0,%%ecx\n"
19910@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
19911 " subl %%ecx,%0\n"
19912 " addl %0,%%eax\n"
19913 "1:\n"
19914+ __COPYUSER_RESTORE_ES
19915 ".section .fixup,\"ax\"\n"
19916 "2: xorl %%eax,%%eax\n"
19917 " jmp 1b\n"
19918@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
19919
19920 #ifdef CONFIG_X86_INTEL_USERCOPY
19921 static unsigned long
19922-__copy_user_intel(void __user *to, const void *from, unsigned long size)
19923+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
19924 {
19925 int d0, d1;
19926 __asm__ __volatile__(
19927@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
19928 " .align 2,0x90\n"
19929 "3: movl 0(%4), %%eax\n"
19930 "4: movl 4(%4), %%edx\n"
19931- "5: movl %%eax, 0(%3)\n"
19932- "6: movl %%edx, 4(%3)\n"
19933+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
19934+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
19935 "7: movl 8(%4), %%eax\n"
19936 "8: movl 12(%4),%%edx\n"
19937- "9: movl %%eax, 8(%3)\n"
19938- "10: movl %%edx, 12(%3)\n"
19939+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
19940+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
19941 "11: movl 16(%4), %%eax\n"
19942 "12: movl 20(%4), %%edx\n"
19943- "13: movl %%eax, 16(%3)\n"
19944- "14: movl %%edx, 20(%3)\n"
19945+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
19946+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
19947 "15: movl 24(%4), %%eax\n"
19948 "16: movl 28(%4), %%edx\n"
19949- "17: movl %%eax, 24(%3)\n"
19950- "18: movl %%edx, 28(%3)\n"
19951+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
19952+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
19953 "19: movl 32(%4), %%eax\n"
19954 "20: movl 36(%4), %%edx\n"
19955- "21: movl %%eax, 32(%3)\n"
19956- "22: movl %%edx, 36(%3)\n"
19957+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
19958+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
19959 "23: movl 40(%4), %%eax\n"
19960 "24: movl 44(%4), %%edx\n"
19961- "25: movl %%eax, 40(%3)\n"
19962- "26: movl %%edx, 44(%3)\n"
19963+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
19964+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
19965 "27: movl 48(%4), %%eax\n"
19966 "28: movl 52(%4), %%edx\n"
19967- "29: movl %%eax, 48(%3)\n"
19968- "30: movl %%edx, 52(%3)\n"
19969+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
19970+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
19971 "31: movl 56(%4), %%eax\n"
19972 "32: movl 60(%4), %%edx\n"
19973- "33: movl %%eax, 56(%3)\n"
19974- "34: movl %%edx, 60(%3)\n"
19975+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
19976+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
19977 " addl $-64, %0\n"
19978 " addl $64, %4\n"
19979 " addl $64, %3\n"
19980@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
19981 " shrl $2, %0\n"
19982 " andl $3, %%eax\n"
19983 " cld\n"
19984+ __COPYUSER_SET_ES
19985 "99: rep; movsl\n"
19986 "36: movl %%eax, %0\n"
19987 "37: rep; movsb\n"
19988 "100:\n"
19989+ __COPYUSER_RESTORE_ES
19990+ ".section .fixup,\"ax\"\n"
19991+ "101: lea 0(%%eax,%0,4),%0\n"
19992+ " jmp 100b\n"
19993+ ".previous\n"
19994+ ".section __ex_table,\"a\"\n"
19995+ " .align 4\n"
19996+ " .long 1b,100b\n"
19997+ " .long 2b,100b\n"
19998+ " .long 3b,100b\n"
19999+ " .long 4b,100b\n"
20000+ " .long 5b,100b\n"
20001+ " .long 6b,100b\n"
20002+ " .long 7b,100b\n"
20003+ " .long 8b,100b\n"
20004+ " .long 9b,100b\n"
20005+ " .long 10b,100b\n"
20006+ " .long 11b,100b\n"
20007+ " .long 12b,100b\n"
20008+ " .long 13b,100b\n"
20009+ " .long 14b,100b\n"
20010+ " .long 15b,100b\n"
20011+ " .long 16b,100b\n"
20012+ " .long 17b,100b\n"
20013+ " .long 18b,100b\n"
20014+ " .long 19b,100b\n"
20015+ " .long 20b,100b\n"
20016+ " .long 21b,100b\n"
20017+ " .long 22b,100b\n"
20018+ " .long 23b,100b\n"
20019+ " .long 24b,100b\n"
20020+ " .long 25b,100b\n"
20021+ " .long 26b,100b\n"
20022+ " .long 27b,100b\n"
20023+ " .long 28b,100b\n"
20024+ " .long 29b,100b\n"
20025+ " .long 30b,100b\n"
20026+ " .long 31b,100b\n"
20027+ " .long 32b,100b\n"
20028+ " .long 33b,100b\n"
20029+ " .long 34b,100b\n"
20030+ " .long 35b,100b\n"
20031+ " .long 36b,100b\n"
20032+ " .long 37b,100b\n"
20033+ " .long 99b,101b\n"
20034+ ".previous"
20035+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
20036+ : "1"(to), "2"(from), "0"(size)
20037+ : "eax", "edx", "memory");
20038+ return size;
20039+}
20040+
20041+static unsigned long
20042+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20043+{
20044+ int d0, d1;
20045+ __asm__ __volatile__(
20046+ " .align 2,0x90\n"
20047+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20048+ " cmpl $67, %0\n"
20049+ " jbe 3f\n"
20050+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20051+ " .align 2,0x90\n"
20052+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20053+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20054+ "5: movl %%eax, 0(%3)\n"
20055+ "6: movl %%edx, 4(%3)\n"
20056+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20057+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20058+ "9: movl %%eax, 8(%3)\n"
20059+ "10: movl %%edx, 12(%3)\n"
20060+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20061+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20062+ "13: movl %%eax, 16(%3)\n"
20063+ "14: movl %%edx, 20(%3)\n"
20064+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20065+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20066+ "17: movl %%eax, 24(%3)\n"
20067+ "18: movl %%edx, 28(%3)\n"
20068+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20069+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20070+ "21: movl %%eax, 32(%3)\n"
20071+ "22: movl %%edx, 36(%3)\n"
20072+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20073+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20074+ "25: movl %%eax, 40(%3)\n"
20075+ "26: movl %%edx, 44(%3)\n"
20076+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20077+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20078+ "29: movl %%eax, 48(%3)\n"
20079+ "30: movl %%edx, 52(%3)\n"
20080+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20081+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20082+ "33: movl %%eax, 56(%3)\n"
20083+ "34: movl %%edx, 60(%3)\n"
20084+ " addl $-64, %0\n"
20085+ " addl $64, %4\n"
20086+ " addl $64, %3\n"
20087+ " cmpl $63, %0\n"
20088+ " ja 1b\n"
20089+ "35: movl %0, %%eax\n"
20090+ " shrl $2, %0\n"
20091+ " andl $3, %%eax\n"
20092+ " cld\n"
20093+ "99: rep; "__copyuser_seg" movsl\n"
20094+ "36: movl %%eax, %0\n"
20095+ "37: rep; "__copyuser_seg" movsb\n"
20096+ "100:\n"
20097 ".section .fixup,\"ax\"\n"
20098 "101: lea 0(%%eax,%0,4),%0\n"
20099 " jmp 100b\n"
20100@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20101 int d0, d1;
20102 __asm__ __volatile__(
20103 " .align 2,0x90\n"
20104- "0: movl 32(%4), %%eax\n"
20105+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20106 " cmpl $67, %0\n"
20107 " jbe 2f\n"
20108- "1: movl 64(%4), %%eax\n"
20109+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20110 " .align 2,0x90\n"
20111- "2: movl 0(%4), %%eax\n"
20112- "21: movl 4(%4), %%edx\n"
20113+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20114+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20115 " movl %%eax, 0(%3)\n"
20116 " movl %%edx, 4(%3)\n"
20117- "3: movl 8(%4), %%eax\n"
20118- "31: movl 12(%4),%%edx\n"
20119+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20120+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20121 " movl %%eax, 8(%3)\n"
20122 " movl %%edx, 12(%3)\n"
20123- "4: movl 16(%4), %%eax\n"
20124- "41: movl 20(%4), %%edx\n"
20125+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20126+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20127 " movl %%eax, 16(%3)\n"
20128 " movl %%edx, 20(%3)\n"
20129- "10: movl 24(%4), %%eax\n"
20130- "51: movl 28(%4), %%edx\n"
20131+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20132+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20133 " movl %%eax, 24(%3)\n"
20134 " movl %%edx, 28(%3)\n"
20135- "11: movl 32(%4), %%eax\n"
20136- "61: movl 36(%4), %%edx\n"
20137+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20138+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20139 " movl %%eax, 32(%3)\n"
20140 " movl %%edx, 36(%3)\n"
20141- "12: movl 40(%4), %%eax\n"
20142- "71: movl 44(%4), %%edx\n"
20143+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20144+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20145 " movl %%eax, 40(%3)\n"
20146 " movl %%edx, 44(%3)\n"
20147- "13: movl 48(%4), %%eax\n"
20148- "81: movl 52(%4), %%edx\n"
20149+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20150+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20151 " movl %%eax, 48(%3)\n"
20152 " movl %%edx, 52(%3)\n"
20153- "14: movl 56(%4), %%eax\n"
20154- "91: movl 60(%4), %%edx\n"
20155+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20156+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20157 " movl %%eax, 56(%3)\n"
20158 " movl %%edx, 60(%3)\n"
20159 " addl $-64, %0\n"
20160@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20161 " shrl $2, %0\n"
20162 " andl $3, %%eax\n"
20163 " cld\n"
20164- "6: rep; movsl\n"
20165+ "6: rep; "__copyuser_seg" movsl\n"
20166 " movl %%eax,%0\n"
20167- "7: rep; movsb\n"
20168+ "7: rep; "__copyuser_seg" movsb\n"
20169 "8:\n"
20170 ".section .fixup,\"ax\"\n"
20171 "9: lea 0(%%eax,%0,4),%0\n"
20172@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20173
20174 __asm__ __volatile__(
20175 " .align 2,0x90\n"
20176- "0: movl 32(%4), %%eax\n"
20177+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20178 " cmpl $67, %0\n"
20179 " jbe 2f\n"
20180- "1: movl 64(%4), %%eax\n"
20181+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20182 " .align 2,0x90\n"
20183- "2: movl 0(%4), %%eax\n"
20184- "21: movl 4(%4), %%edx\n"
20185+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20186+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20187 " movnti %%eax, 0(%3)\n"
20188 " movnti %%edx, 4(%3)\n"
20189- "3: movl 8(%4), %%eax\n"
20190- "31: movl 12(%4),%%edx\n"
20191+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20192+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20193 " movnti %%eax, 8(%3)\n"
20194 " movnti %%edx, 12(%3)\n"
20195- "4: movl 16(%4), %%eax\n"
20196- "41: movl 20(%4), %%edx\n"
20197+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20198+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20199 " movnti %%eax, 16(%3)\n"
20200 " movnti %%edx, 20(%3)\n"
20201- "10: movl 24(%4), %%eax\n"
20202- "51: movl 28(%4), %%edx\n"
20203+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20204+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20205 " movnti %%eax, 24(%3)\n"
20206 " movnti %%edx, 28(%3)\n"
20207- "11: movl 32(%4), %%eax\n"
20208- "61: movl 36(%4), %%edx\n"
20209+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20210+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20211 " movnti %%eax, 32(%3)\n"
20212 " movnti %%edx, 36(%3)\n"
20213- "12: movl 40(%4), %%eax\n"
20214- "71: movl 44(%4), %%edx\n"
20215+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20216+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20217 " movnti %%eax, 40(%3)\n"
20218 " movnti %%edx, 44(%3)\n"
20219- "13: movl 48(%4), %%eax\n"
20220- "81: movl 52(%4), %%edx\n"
20221+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20222+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20223 " movnti %%eax, 48(%3)\n"
20224 " movnti %%edx, 52(%3)\n"
20225- "14: movl 56(%4), %%eax\n"
20226- "91: movl 60(%4), %%edx\n"
20227+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20228+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20229 " movnti %%eax, 56(%3)\n"
20230 " movnti %%edx, 60(%3)\n"
20231 " addl $-64, %0\n"
20232@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20233 " shrl $2, %0\n"
20234 " andl $3, %%eax\n"
20235 " cld\n"
20236- "6: rep; movsl\n"
20237+ "6: rep; "__copyuser_seg" movsl\n"
20238 " movl %%eax,%0\n"
20239- "7: rep; movsb\n"
20240+ "7: rep; "__copyuser_seg" movsb\n"
20241 "8:\n"
20242 ".section .fixup,\"ax\"\n"
20243 "9: lea 0(%%eax,%0,4),%0\n"
20244@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20245
20246 __asm__ __volatile__(
20247 " .align 2,0x90\n"
20248- "0: movl 32(%4), %%eax\n"
20249+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20250 " cmpl $67, %0\n"
20251 " jbe 2f\n"
20252- "1: movl 64(%4), %%eax\n"
20253+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20254 " .align 2,0x90\n"
20255- "2: movl 0(%4), %%eax\n"
20256- "21: movl 4(%4), %%edx\n"
20257+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20258+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20259 " movnti %%eax, 0(%3)\n"
20260 " movnti %%edx, 4(%3)\n"
20261- "3: movl 8(%4), %%eax\n"
20262- "31: movl 12(%4),%%edx\n"
20263+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20264+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20265 " movnti %%eax, 8(%3)\n"
20266 " movnti %%edx, 12(%3)\n"
20267- "4: movl 16(%4), %%eax\n"
20268- "41: movl 20(%4), %%edx\n"
20269+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20270+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20271 " movnti %%eax, 16(%3)\n"
20272 " movnti %%edx, 20(%3)\n"
20273- "10: movl 24(%4), %%eax\n"
20274- "51: movl 28(%4), %%edx\n"
20275+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20276+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20277 " movnti %%eax, 24(%3)\n"
20278 " movnti %%edx, 28(%3)\n"
20279- "11: movl 32(%4), %%eax\n"
20280- "61: movl 36(%4), %%edx\n"
20281+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20282+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20283 " movnti %%eax, 32(%3)\n"
20284 " movnti %%edx, 36(%3)\n"
20285- "12: movl 40(%4), %%eax\n"
20286- "71: movl 44(%4), %%edx\n"
20287+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20288+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20289 " movnti %%eax, 40(%3)\n"
20290 " movnti %%edx, 44(%3)\n"
20291- "13: movl 48(%4), %%eax\n"
20292- "81: movl 52(%4), %%edx\n"
20293+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20294+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20295 " movnti %%eax, 48(%3)\n"
20296 " movnti %%edx, 52(%3)\n"
20297- "14: movl 56(%4), %%eax\n"
20298- "91: movl 60(%4), %%edx\n"
20299+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20300+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20301 " movnti %%eax, 56(%3)\n"
20302 " movnti %%edx, 60(%3)\n"
20303 " addl $-64, %0\n"
20304@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20305 " shrl $2, %0\n"
20306 " andl $3, %%eax\n"
20307 " cld\n"
20308- "6: rep; movsl\n"
20309+ "6: rep; "__copyuser_seg" movsl\n"
20310 " movl %%eax,%0\n"
20311- "7: rep; movsb\n"
20312+ "7: rep; "__copyuser_seg" movsb\n"
20313 "8:\n"
20314 ".section .fixup,\"ax\"\n"
20315 "9: lea 0(%%eax,%0,4),%0\n"
20316@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20317 */
20318 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20319 unsigned long size);
20320-unsigned long __copy_user_intel(void __user *to, const void *from,
20321+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20322+ unsigned long size);
20323+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20324 unsigned long size);
20325 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20326 const void __user *from, unsigned long size);
20327 #endif /* CONFIG_X86_INTEL_USERCOPY */
20328
20329 /* Generic arbitrary sized copy. */
20330-#define __copy_user(to, from, size) \
20331+#define __copy_user(to, from, size, prefix, set, restore) \
20332 do { \
20333 int __d0, __d1, __d2; \
20334 __asm__ __volatile__( \
20335+ set \
20336 " cmp $7,%0\n" \
20337 " jbe 1f\n" \
20338 " movl %1,%0\n" \
20339 " negl %0\n" \
20340 " andl $7,%0\n" \
20341 " subl %0,%3\n" \
20342- "4: rep; movsb\n" \
20343+ "4: rep; "prefix"movsb\n" \
20344 " movl %3,%0\n" \
20345 " shrl $2,%0\n" \
20346 " andl $3,%3\n" \
20347 " .align 2,0x90\n" \
20348- "0: rep; movsl\n" \
20349+ "0: rep; "prefix"movsl\n" \
20350 " movl %3,%0\n" \
20351- "1: rep; movsb\n" \
20352+ "1: rep; "prefix"movsb\n" \
20353 "2:\n" \
20354+ restore \
20355 ".section .fixup,\"ax\"\n" \
20356 "5: addl %3,%0\n" \
20357 " jmp 2b\n" \
20358@@ -682,14 +799,14 @@ do { \
20359 " negl %0\n" \
20360 " andl $7,%0\n" \
20361 " subl %0,%3\n" \
20362- "4: rep; movsb\n" \
20363+ "4: rep; "__copyuser_seg"movsb\n" \
20364 " movl %3,%0\n" \
20365 " shrl $2,%0\n" \
20366 " andl $3,%3\n" \
20367 " .align 2,0x90\n" \
20368- "0: rep; movsl\n" \
20369+ "0: rep; "__copyuser_seg"movsl\n" \
20370 " movl %3,%0\n" \
20371- "1: rep; movsb\n" \
20372+ "1: rep; "__copyuser_seg"movsb\n" \
20373 "2:\n" \
20374 ".section .fixup,\"ax\"\n" \
20375 "5: addl %3,%0\n" \
20376@@ -775,9 +892,9 @@ survive:
20377 }
20378 #endif
20379 if (movsl_is_ok(to, from, n))
20380- __copy_user(to, from, n);
20381+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20382 else
20383- n = __copy_user_intel(to, from, n);
20384+ n = __generic_copy_to_user_intel(to, from, n);
20385 return n;
20386 }
20387 EXPORT_SYMBOL(__copy_to_user_ll);
20388@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20389 unsigned long n)
20390 {
20391 if (movsl_is_ok(to, from, n))
20392- __copy_user(to, from, n);
20393+ __copy_user(to, from, n, __copyuser_seg, "", "");
20394 else
20395- n = __copy_user_intel((void __user *)to,
20396- (const void *)from, n);
20397+ n = __generic_copy_from_user_intel(to, from, n);
20398 return n;
20399 }
20400 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20401@@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocach
20402 if (n > 64 && cpu_has_xmm2)
20403 n = __copy_user_intel_nocache(to, from, n);
20404 else
20405- __copy_user(to, from, n);
20406+ __copy_user(to, from, n, __copyuser_seg, "", "");
20407 #else
20408- __copy_user(to, from, n);
20409+ __copy_user(to, from, n, __copyuser_seg, "", "");
20410 #endif
20411 return n;
20412 }
20413 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20414
20415-/**
20416- * copy_to_user: - Copy a block of data into user space.
20417- * @to: Destination address, in user space.
20418- * @from: Source address, in kernel space.
20419- * @n: Number of bytes to copy.
20420- *
20421- * Context: User context only. This function may sleep.
20422- *
20423- * Copy data from kernel space to user space.
20424- *
20425- * Returns number of bytes that could not be copied.
20426- * On success, this will be zero.
20427- */
20428-unsigned long
20429-copy_to_user(void __user *to, const void *from, unsigned long n)
20430+#ifdef CONFIG_PAX_MEMORY_UDEREF
20431+void __set_fs(mm_segment_t x)
20432 {
20433- if (access_ok(VERIFY_WRITE, to, n))
20434- n = __copy_to_user(to, from, n);
20435- return n;
20436+ switch (x.seg) {
20437+ case 0:
20438+ loadsegment(gs, 0);
20439+ break;
20440+ case TASK_SIZE_MAX:
20441+ loadsegment(gs, __USER_DS);
20442+ break;
20443+ case -1UL:
20444+ loadsegment(gs, __KERNEL_DS);
20445+ break;
20446+ default:
20447+ BUG();
20448+ }
20449+ return;
20450 }
20451-EXPORT_SYMBOL(copy_to_user);
20452+EXPORT_SYMBOL(__set_fs);
20453
20454-/**
20455- * copy_from_user: - Copy a block of data from user space.
20456- * @to: Destination address, in kernel space.
20457- * @from: Source address, in user space.
20458- * @n: Number of bytes to copy.
20459- *
20460- * Context: User context only. This function may sleep.
20461- *
20462- * Copy data from user space to kernel space.
20463- *
20464- * Returns number of bytes that could not be copied.
20465- * On success, this will be zero.
20466- *
20467- * If some data could not be copied, this function will pad the copied
20468- * data to the requested size using zero bytes.
20469- */
20470-unsigned long
20471-copy_from_user(void *to, const void __user *from, unsigned long n)
20472+void set_fs(mm_segment_t x)
20473 {
20474- if (access_ok(VERIFY_READ, from, n))
20475- n = __copy_from_user(to, from, n);
20476- else
20477- memset(to, 0, n);
20478- return n;
20479+ current_thread_info()->addr_limit = x;
20480+ __set_fs(x);
20481 }
20482-EXPORT_SYMBOL(copy_from_user);
20483+EXPORT_SYMBOL(set_fs);
20484+#endif
20485diff -urNp linux-2.6.32.44/arch/x86/lib/usercopy_64.c linux-2.6.32.44/arch/x86/lib/usercopy_64.c
20486--- linux-2.6.32.44/arch/x86/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
20487+++ linux-2.6.32.44/arch/x86/lib/usercopy_64.c 2011-05-04 17:56:20.000000000 -0400
20488@@ -42,6 +42,12 @@ long
20489 __strncpy_from_user(char *dst, const char __user *src, long count)
20490 {
20491 long res;
20492+
20493+#ifdef CONFIG_PAX_MEMORY_UDEREF
20494+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20495+ src += PAX_USER_SHADOW_BASE;
20496+#endif
20497+
20498 __do_strncpy_from_user(dst, src, count, res);
20499 return res;
20500 }
20501@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20502 {
20503 long __d0;
20504 might_fault();
20505+
20506+#ifdef CONFIG_PAX_MEMORY_UDEREF
20507+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20508+ addr += PAX_USER_SHADOW_BASE;
20509+#endif
20510+
20511 /* no memory constraint because it doesn't change any memory gcc knows
20512 about */
20513 asm volatile(
20514@@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20515
20516 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20517 {
20518- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20519+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20520+
20521+#ifdef CONFIG_PAX_MEMORY_UDEREF
20522+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20523+ to += PAX_USER_SHADOW_BASE;
20524+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20525+ from += PAX_USER_SHADOW_BASE;
20526+#endif
20527+
20528 return copy_user_generic((__force void *)to, (__force void *)from, len);
20529- }
20530- return len;
20531+ }
20532+ return len;
20533 }
20534 EXPORT_SYMBOL(copy_in_user);
20535
20536diff -urNp linux-2.6.32.44/arch/x86/Makefile linux-2.6.32.44/arch/x86/Makefile
20537--- linux-2.6.32.44/arch/x86/Makefile 2011-03-27 14:31:47.000000000 -0400
20538+++ linux-2.6.32.44/arch/x86/Makefile 2011-07-19 18:16:02.000000000 -0400
20539@@ -44,6 +44,7 @@ ifeq ($(CONFIG_X86_32),y)
20540 else
20541 BITS := 64
20542 UTS_MACHINE := x86_64
20543+ biarch := $(call cc-option,-m64)
20544 CHECKFLAGS += -D__x86_64__ -m64
20545
20546 KBUILD_AFLAGS += -m64
20547@@ -189,3 +190,12 @@ define archhelp
20548 echo ' FDARGS="..." arguments for the booted kernel'
20549 echo ' FDINITRD=file initrd for the booted kernel'
20550 endef
20551+
20552+define OLD_LD
20553+
20554+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20555+*** Please upgrade your binutils to 2.18 or newer
20556+endef
20557+
20558+archprepare:
20559+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20560diff -urNp linux-2.6.32.44/arch/x86/mm/extable.c linux-2.6.32.44/arch/x86/mm/extable.c
20561--- linux-2.6.32.44/arch/x86/mm/extable.c 2011-03-27 14:31:47.000000000 -0400
20562+++ linux-2.6.32.44/arch/x86/mm/extable.c 2011-04-17 15:56:46.000000000 -0400
20563@@ -1,14 +1,71 @@
20564 #include <linux/module.h>
20565 #include <linux/spinlock.h>
20566+#include <linux/sort.h>
20567 #include <asm/uaccess.h>
20568+#include <asm/pgtable.h>
20569
20570+/*
20571+ * The exception table needs to be sorted so that the binary
20572+ * search that we use to find entries in it works properly.
20573+ * This is used both for the kernel exception table and for
20574+ * the exception tables of modules that get loaded.
20575+ */
20576+static int cmp_ex(const void *a, const void *b)
20577+{
20578+ const struct exception_table_entry *x = a, *y = b;
20579+
20580+ /* avoid overflow */
20581+ if (x->insn > y->insn)
20582+ return 1;
20583+ if (x->insn < y->insn)
20584+ return -1;
20585+ return 0;
20586+}
20587+
20588+static void swap_ex(void *a, void *b, int size)
20589+{
20590+ struct exception_table_entry t, *x = a, *y = b;
20591+
20592+ t = *x;
20593+
20594+ pax_open_kernel();
20595+ *x = *y;
20596+ *y = t;
20597+ pax_close_kernel();
20598+}
20599+
20600+void sort_extable(struct exception_table_entry *start,
20601+ struct exception_table_entry *finish)
20602+{
20603+ sort(start, finish - start, sizeof(struct exception_table_entry),
20604+ cmp_ex, swap_ex);
20605+}
20606+
20607+#ifdef CONFIG_MODULES
20608+/*
20609+ * If the exception table is sorted, any referring to the module init
20610+ * will be at the beginning or the end.
20611+ */
20612+void trim_init_extable(struct module *m)
20613+{
20614+ /*trim the beginning*/
20615+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
20616+ m->extable++;
20617+ m->num_exentries--;
20618+ }
20619+ /*trim the end*/
20620+ while (m->num_exentries &&
20621+ within_module_init(m->extable[m->num_exentries-1].insn, m))
20622+ m->num_exentries--;
20623+}
20624+#endif /* CONFIG_MODULES */
20625
20626 int fixup_exception(struct pt_regs *regs)
20627 {
20628 const struct exception_table_entry *fixup;
20629
20630 #ifdef CONFIG_PNPBIOS
20631- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
20632+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
20633 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
20634 extern u32 pnp_bios_is_utter_crap;
20635 pnp_bios_is_utter_crap = 1;
20636diff -urNp linux-2.6.32.44/arch/x86/mm/fault.c linux-2.6.32.44/arch/x86/mm/fault.c
20637--- linux-2.6.32.44/arch/x86/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
20638+++ linux-2.6.32.44/arch/x86/mm/fault.c 2011-06-06 17:35:16.000000000 -0400
20639@@ -11,10 +11,19 @@
20640 #include <linux/kprobes.h> /* __kprobes, ... */
20641 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
20642 #include <linux/perf_event.h> /* perf_sw_event */
20643+#include <linux/unistd.h>
20644+#include <linux/compiler.h>
20645
20646 #include <asm/traps.h> /* dotraplinkage, ... */
20647 #include <asm/pgalloc.h> /* pgd_*(), ... */
20648 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
20649+#include <asm/vsyscall.h>
20650+#include <asm/tlbflush.h>
20651+
20652+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20653+#include <asm/stacktrace.h>
20654+#include "../kernel/dumpstack.h"
20655+#endif
20656
20657 /*
20658 * Page fault error code bits:
20659@@ -51,7 +60,7 @@ static inline int notify_page_fault(stru
20660 int ret = 0;
20661
20662 /* kprobe_running() needs smp_processor_id() */
20663- if (kprobes_built_in() && !user_mode_vm(regs)) {
20664+ if (kprobes_built_in() && !user_mode(regs)) {
20665 preempt_disable();
20666 if (kprobe_running() && kprobe_fault_handler(regs, 14))
20667 ret = 1;
20668@@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *re
20669 return !instr_lo || (instr_lo>>1) == 1;
20670 case 0x00:
20671 /* Prefetch instruction is 0x0F0D or 0x0F18 */
20672- if (probe_kernel_address(instr, opcode))
20673+ if (user_mode(regs)) {
20674+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20675+ return 0;
20676+ } else if (probe_kernel_address(instr, opcode))
20677 return 0;
20678
20679 *prefetch = (instr_lo == 0xF) &&
20680@@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsign
20681 while (instr < max_instr) {
20682 unsigned char opcode;
20683
20684- if (probe_kernel_address(instr, opcode))
20685+ if (user_mode(regs)) {
20686+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20687+ break;
20688+ } else if (probe_kernel_address(instr, opcode))
20689 break;
20690
20691 instr++;
20692@@ -172,6 +187,30 @@ force_sig_info_fault(int si_signo, int s
20693 force_sig_info(si_signo, &info, tsk);
20694 }
20695
20696+#ifdef CONFIG_PAX_EMUTRAMP
20697+static int pax_handle_fetch_fault(struct pt_regs *regs);
20698+#endif
20699+
20700+#ifdef CONFIG_PAX_PAGEEXEC
20701+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
20702+{
20703+ pgd_t *pgd;
20704+ pud_t *pud;
20705+ pmd_t *pmd;
20706+
20707+ pgd = pgd_offset(mm, address);
20708+ if (!pgd_present(*pgd))
20709+ return NULL;
20710+ pud = pud_offset(pgd, address);
20711+ if (!pud_present(*pud))
20712+ return NULL;
20713+ pmd = pmd_offset(pud, address);
20714+ if (!pmd_present(*pmd))
20715+ return NULL;
20716+ return pmd;
20717+}
20718+#endif
20719+
20720 DEFINE_SPINLOCK(pgd_lock);
20721 LIST_HEAD(pgd_list);
20722
20723@@ -224,11 +263,24 @@ void vmalloc_sync_all(void)
20724 address += PMD_SIZE) {
20725
20726 unsigned long flags;
20727+
20728+#ifdef CONFIG_PAX_PER_CPU_PGD
20729+ unsigned long cpu;
20730+#else
20731 struct page *page;
20732+#endif
20733
20734 spin_lock_irqsave(&pgd_lock, flags);
20735+
20736+#ifdef CONFIG_PAX_PER_CPU_PGD
20737+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
20738+ pgd_t *pgd = get_cpu_pgd(cpu);
20739+#else
20740 list_for_each_entry(page, &pgd_list, lru) {
20741- if (!vmalloc_sync_one(page_address(page), address))
20742+ pgd_t *pgd = page_address(page);
20743+#endif
20744+
20745+ if (!vmalloc_sync_one(pgd, address))
20746 break;
20747 }
20748 spin_unlock_irqrestore(&pgd_lock, flags);
20749@@ -258,6 +310,11 @@ static noinline int vmalloc_fault(unsign
20750 * an interrupt in the middle of a task switch..
20751 */
20752 pgd_paddr = read_cr3();
20753+
20754+#ifdef CONFIG_PAX_PER_CPU_PGD
20755+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
20756+#endif
20757+
20758 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
20759 if (!pmd_k)
20760 return -1;
20761@@ -332,15 +389,27 @@ void vmalloc_sync_all(void)
20762
20763 const pgd_t *pgd_ref = pgd_offset_k(address);
20764 unsigned long flags;
20765+
20766+#ifdef CONFIG_PAX_PER_CPU_PGD
20767+ unsigned long cpu;
20768+#else
20769 struct page *page;
20770+#endif
20771
20772 if (pgd_none(*pgd_ref))
20773 continue;
20774
20775 spin_lock_irqsave(&pgd_lock, flags);
20776+
20777+#ifdef CONFIG_PAX_PER_CPU_PGD
20778+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
20779+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
20780+#else
20781 list_for_each_entry(page, &pgd_list, lru) {
20782 pgd_t *pgd;
20783 pgd = (pgd_t *)page_address(page) + pgd_index(address);
20784+#endif
20785+
20786 if (pgd_none(*pgd))
20787 set_pgd(pgd, *pgd_ref);
20788 else
20789@@ -373,7 +442,14 @@ static noinline int vmalloc_fault(unsign
20790 * happen within a race in page table update. In the later
20791 * case just flush:
20792 */
20793+
20794+#ifdef CONFIG_PAX_PER_CPU_PGD
20795+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
20796+ pgd = pgd_offset_cpu(smp_processor_id(), address);
20797+#else
20798 pgd = pgd_offset(current->active_mm, address);
20799+#endif
20800+
20801 pgd_ref = pgd_offset_k(address);
20802 if (pgd_none(*pgd_ref))
20803 return -1;
20804@@ -535,7 +611,7 @@ static int is_errata93(struct pt_regs *r
20805 static int is_errata100(struct pt_regs *regs, unsigned long address)
20806 {
20807 #ifdef CONFIG_X86_64
20808- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
20809+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
20810 return 1;
20811 #endif
20812 return 0;
20813@@ -562,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *r
20814 }
20815
20816 static const char nx_warning[] = KERN_CRIT
20817-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
20818+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
20819
20820 static void
20821 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
20822@@ -571,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, un
20823 if (!oops_may_print())
20824 return;
20825
20826- if (error_code & PF_INSTR) {
20827+ if (nx_enabled && (error_code & PF_INSTR)) {
20828 unsigned int level;
20829
20830 pte_t *pte = lookup_address(address, &level);
20831
20832 if (pte && pte_present(*pte) && !pte_exec(*pte))
20833- printk(nx_warning, current_uid());
20834+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
20835 }
20836
20837+#ifdef CONFIG_PAX_KERNEXEC
20838+ if (init_mm.start_code <= address && address < init_mm.end_code) {
20839+ if (current->signal->curr_ip)
20840+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
20841+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
20842+ else
20843+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
20844+ current->comm, task_pid_nr(current), current_uid(), current_euid());
20845+ }
20846+#endif
20847+
20848 printk(KERN_ALERT "BUG: unable to handle kernel ");
20849 if (address < PAGE_SIZE)
20850 printk(KERN_CONT "NULL pointer dereference");
20851@@ -704,6 +791,68 @@ __bad_area_nosemaphore(struct pt_regs *r
20852 unsigned long address, int si_code)
20853 {
20854 struct task_struct *tsk = current;
20855+ struct mm_struct *mm = tsk->mm;
20856+
20857+#ifdef CONFIG_X86_64
20858+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
20859+ if (regs->ip == (unsigned long)vgettimeofday) {
20860+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
20861+ return;
20862+ } else if (regs->ip == (unsigned long)vtime) {
20863+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
20864+ return;
20865+ } else if (regs->ip == (unsigned long)vgetcpu) {
20866+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
20867+ return;
20868+ }
20869+ }
20870+#endif
20871+
20872+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20873+ if (mm && (error_code & PF_USER)) {
20874+ unsigned long ip = regs->ip;
20875+
20876+ if (v8086_mode(regs))
20877+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
20878+
20879+ /*
20880+ * It's possible to have interrupts off here:
20881+ */
20882+ local_irq_enable();
20883+
20884+#ifdef CONFIG_PAX_PAGEEXEC
20885+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
20886+ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
20887+
20888+#ifdef CONFIG_PAX_EMUTRAMP
20889+ switch (pax_handle_fetch_fault(regs)) {
20890+ case 2:
20891+ return;
20892+ }
20893+#endif
20894+
20895+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
20896+ do_group_exit(SIGKILL);
20897+ }
20898+#endif
20899+
20900+#ifdef CONFIG_PAX_SEGMEXEC
20901+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
20902+
20903+#ifdef CONFIG_PAX_EMUTRAMP
20904+ switch (pax_handle_fetch_fault(regs)) {
20905+ case 2:
20906+ return;
20907+ }
20908+#endif
20909+
20910+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
20911+ do_group_exit(SIGKILL);
20912+ }
20913+#endif
20914+
20915+ }
20916+#endif
20917
20918 /* User mode accesses just cause a SIGSEGV */
20919 if (error_code & PF_USER) {
20920@@ -857,6 +1006,99 @@ static int spurious_fault_check(unsigned
20921 return 1;
20922 }
20923
20924+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20925+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
20926+{
20927+ pte_t *pte;
20928+ pmd_t *pmd;
20929+ spinlock_t *ptl;
20930+ unsigned char pte_mask;
20931+
20932+ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
20933+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
20934+ return 0;
20935+
20936+ /* PaX: it's our fault, let's handle it if we can */
20937+
20938+ /* PaX: take a look at read faults before acquiring any locks */
20939+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
20940+ /* instruction fetch attempt from a protected page in user mode */
20941+ up_read(&mm->mmap_sem);
20942+
20943+#ifdef CONFIG_PAX_EMUTRAMP
20944+ switch (pax_handle_fetch_fault(regs)) {
20945+ case 2:
20946+ return 1;
20947+ }
20948+#endif
20949+
20950+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
20951+ do_group_exit(SIGKILL);
20952+ }
20953+
20954+ pmd = pax_get_pmd(mm, address);
20955+ if (unlikely(!pmd))
20956+ return 0;
20957+
20958+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
20959+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
20960+ pte_unmap_unlock(pte, ptl);
20961+ return 0;
20962+ }
20963+
20964+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
20965+ /* write attempt to a protected page in user mode */
20966+ pte_unmap_unlock(pte, ptl);
20967+ return 0;
20968+ }
20969+
20970+#ifdef CONFIG_SMP
20971+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
20972+#else
20973+ if (likely(address > get_limit(regs->cs)))
20974+#endif
20975+ {
20976+ set_pte(pte, pte_mkread(*pte));
20977+ __flush_tlb_one(address);
20978+ pte_unmap_unlock(pte, ptl);
20979+ up_read(&mm->mmap_sem);
20980+ return 1;
20981+ }
20982+
20983+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
20984+
20985+ /*
20986+ * PaX: fill DTLB with user rights and retry
20987+ */
20988+ __asm__ __volatile__ (
20989+ "orb %2,(%1)\n"
20990+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
20991+/*
20992+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
20993+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
20994+ * page fault when examined during a TLB load attempt. this is true not only
20995+ * for PTEs holding a non-present entry but also present entries that will
20996+ * raise a page fault (such as those set up by PaX, or the copy-on-write
20997+ * mechanism). in effect it means that we do *not* need to flush the TLBs
20998+ * for our target pages since their PTEs are simply not in the TLBs at all.
20999+
21000+ * the best thing in omitting it is that we gain around 15-20% speed in the
21001+ * fast path of the page fault handler and can get rid of tracing since we
21002+ * can no longer flush unintended entries.
21003+ */
21004+ "invlpg (%0)\n"
21005+#endif
21006+ __copyuser_seg"testb $0,(%0)\n"
21007+ "xorb %3,(%1)\n"
21008+ :
21009+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21010+ : "memory", "cc");
21011+ pte_unmap_unlock(pte, ptl);
21012+ up_read(&mm->mmap_sem);
21013+ return 1;
21014+}
21015+#endif
21016+
21017 /*
21018 * Handle a spurious fault caused by a stale TLB entry.
21019 *
21020@@ -923,6 +1165,9 @@ int show_unhandled_signals = 1;
21021 static inline int
21022 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
21023 {
21024+ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21025+ return 1;
21026+
21027 if (write) {
21028 /* write, present and write, not present: */
21029 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21030@@ -956,17 +1201,31 @@ do_page_fault(struct pt_regs *regs, unsi
21031 {
21032 struct vm_area_struct *vma;
21033 struct task_struct *tsk;
21034- unsigned long address;
21035 struct mm_struct *mm;
21036 int write;
21037 int fault;
21038
21039+ /* Get the faulting address: */
21040+ unsigned long address = read_cr2();
21041+
21042+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21043+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21044+ if (!search_exception_tables(regs->ip)) {
21045+ bad_area_nosemaphore(regs, error_code, address);
21046+ return;
21047+ }
21048+ if (address < PAX_USER_SHADOW_BASE) {
21049+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21050+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21051+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21052+ } else
21053+ address -= PAX_USER_SHADOW_BASE;
21054+ }
21055+#endif
21056+
21057 tsk = current;
21058 mm = tsk->mm;
21059
21060- /* Get the faulting address: */
21061- address = read_cr2();
21062-
21063 /*
21064 * Detect and handle instructions that would cause a page fault for
21065 * both a tracked kernel page and a userspace page.
21066@@ -1026,7 +1285,7 @@ do_page_fault(struct pt_regs *regs, unsi
21067 * User-mode registers count as a user access even for any
21068 * potential system fault or CPU buglet:
21069 */
21070- if (user_mode_vm(regs)) {
21071+ if (user_mode(regs)) {
21072 local_irq_enable();
21073 error_code |= PF_USER;
21074 } else {
21075@@ -1080,6 +1339,11 @@ do_page_fault(struct pt_regs *regs, unsi
21076 might_sleep();
21077 }
21078
21079+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21080+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21081+ return;
21082+#endif
21083+
21084 vma = find_vma(mm, address);
21085 if (unlikely(!vma)) {
21086 bad_area(regs, error_code, address);
21087@@ -1091,18 +1355,24 @@ do_page_fault(struct pt_regs *regs, unsi
21088 bad_area(regs, error_code, address);
21089 return;
21090 }
21091- if (error_code & PF_USER) {
21092- /*
21093- * Accessing the stack below %sp is always a bug.
21094- * The large cushion allows instructions like enter
21095- * and pusha to work. ("enter $65535, $31" pushes
21096- * 32 pointers and then decrements %sp by 65535.)
21097- */
21098- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21099- bad_area(regs, error_code, address);
21100- return;
21101- }
21102+ /*
21103+ * Accessing the stack below %sp is always a bug.
21104+ * The large cushion allows instructions like enter
21105+ * and pusha to work. ("enter $65535, $31" pushes
21106+ * 32 pointers and then decrements %sp by 65535.)
21107+ */
21108+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21109+ bad_area(regs, error_code, address);
21110+ return;
21111+ }
21112+
21113+#ifdef CONFIG_PAX_SEGMEXEC
21114+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21115+ bad_area(regs, error_code, address);
21116+ return;
21117 }
21118+#endif
21119+
21120 if (unlikely(expand_stack(vma, address))) {
21121 bad_area(regs, error_code, address);
21122 return;
21123@@ -1146,3 +1416,199 @@ good_area:
21124
21125 up_read(&mm->mmap_sem);
21126 }
21127+
21128+#ifdef CONFIG_PAX_EMUTRAMP
21129+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21130+{
21131+ int err;
21132+
21133+ do { /* PaX: gcc trampoline emulation #1 */
21134+ unsigned char mov1, mov2;
21135+ unsigned short jmp;
21136+ unsigned int addr1, addr2;
21137+
21138+#ifdef CONFIG_X86_64
21139+ if ((regs->ip + 11) >> 32)
21140+ break;
21141+#endif
21142+
21143+ err = get_user(mov1, (unsigned char __user *)regs->ip);
21144+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21145+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21146+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21147+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21148+
21149+ if (err)
21150+ break;
21151+
21152+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21153+ regs->cx = addr1;
21154+ regs->ax = addr2;
21155+ regs->ip = addr2;
21156+ return 2;
21157+ }
21158+ } while (0);
21159+
21160+ do { /* PaX: gcc trampoline emulation #2 */
21161+ unsigned char mov, jmp;
21162+ unsigned int addr1, addr2;
21163+
21164+#ifdef CONFIG_X86_64
21165+ if ((regs->ip + 9) >> 32)
21166+ break;
21167+#endif
21168+
21169+ err = get_user(mov, (unsigned char __user *)regs->ip);
21170+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21171+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21172+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21173+
21174+ if (err)
21175+ break;
21176+
21177+ if (mov == 0xB9 && jmp == 0xE9) {
21178+ regs->cx = addr1;
21179+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21180+ return 2;
21181+ }
21182+ } while (0);
21183+
21184+ return 1; /* PaX in action */
21185+}
21186+
21187+#ifdef CONFIG_X86_64
21188+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21189+{
21190+ int err;
21191+
21192+ do { /* PaX: gcc trampoline emulation #1 */
21193+ unsigned short mov1, mov2, jmp1;
21194+ unsigned char jmp2;
21195+ unsigned int addr1;
21196+ unsigned long addr2;
21197+
21198+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21199+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21200+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21201+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21202+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21203+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21204+
21205+ if (err)
21206+ break;
21207+
21208+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21209+ regs->r11 = addr1;
21210+ regs->r10 = addr2;
21211+ regs->ip = addr1;
21212+ return 2;
21213+ }
21214+ } while (0);
21215+
21216+ do { /* PaX: gcc trampoline emulation #2 */
21217+ unsigned short mov1, mov2, jmp1;
21218+ unsigned char jmp2;
21219+ unsigned long addr1, addr2;
21220+
21221+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21222+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21223+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21224+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21225+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21226+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21227+
21228+ if (err)
21229+ break;
21230+
21231+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21232+ regs->r11 = addr1;
21233+ regs->r10 = addr2;
21234+ regs->ip = addr1;
21235+ return 2;
21236+ }
21237+ } while (0);
21238+
21239+ return 1; /* PaX in action */
21240+}
21241+#endif
21242+
21243+/*
21244+ * PaX: decide what to do with offenders (regs->ip = fault address)
21245+ *
21246+ * returns 1 when task should be killed
21247+ * 2 when gcc trampoline was detected
21248+ */
21249+static int pax_handle_fetch_fault(struct pt_regs *regs)
21250+{
21251+ if (v8086_mode(regs))
21252+ return 1;
21253+
21254+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21255+ return 1;
21256+
21257+#ifdef CONFIG_X86_32
21258+ return pax_handle_fetch_fault_32(regs);
21259+#else
21260+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21261+ return pax_handle_fetch_fault_32(regs);
21262+ else
21263+ return pax_handle_fetch_fault_64(regs);
21264+#endif
21265+}
21266+#endif
21267+
21268+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21269+void pax_report_insns(void *pc, void *sp)
21270+{
21271+ long i;
21272+
21273+ printk(KERN_ERR "PAX: bytes at PC: ");
21274+ for (i = 0; i < 20; i++) {
21275+ unsigned char c;
21276+ if (get_user(c, (__force unsigned char __user *)pc+i))
21277+ printk(KERN_CONT "?? ");
21278+ else
21279+ printk(KERN_CONT "%02x ", c);
21280+ }
21281+ printk("\n");
21282+
21283+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21284+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
21285+ unsigned long c;
21286+ if (get_user(c, (__force unsigned long __user *)sp+i))
21287+#ifdef CONFIG_X86_32
21288+ printk(KERN_CONT "???????? ");
21289+#else
21290+ printk(KERN_CONT "???????????????? ");
21291+#endif
21292+ else
21293+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21294+ }
21295+ printk("\n");
21296+}
21297+#endif
21298+
21299+/**
21300+ * probe_kernel_write(): safely attempt to write to a location
21301+ * @dst: address to write to
21302+ * @src: pointer to the data that shall be written
21303+ * @size: size of the data chunk
21304+ *
21305+ * Safely write to address @dst from the buffer at @src. If a kernel fault
21306+ * happens, handle that and return -EFAULT.
21307+ */
21308+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21309+{
21310+ long ret;
21311+ mm_segment_t old_fs = get_fs();
21312+
21313+ set_fs(KERNEL_DS);
21314+ pagefault_disable();
21315+ pax_open_kernel();
21316+ ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21317+ pax_close_kernel();
21318+ pagefault_enable();
21319+ set_fs(old_fs);
21320+
21321+ return ret ? -EFAULT : 0;
21322+}
21323diff -urNp linux-2.6.32.44/arch/x86/mm/gup.c linux-2.6.32.44/arch/x86/mm/gup.c
21324--- linux-2.6.32.44/arch/x86/mm/gup.c 2011-03-27 14:31:47.000000000 -0400
21325+++ linux-2.6.32.44/arch/x86/mm/gup.c 2011-04-17 15:56:46.000000000 -0400
21326@@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long
21327 addr = start;
21328 len = (unsigned long) nr_pages << PAGE_SHIFT;
21329 end = start + len;
21330- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21331+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21332 (void __user *)start, len)))
21333 return 0;
21334
21335diff -urNp linux-2.6.32.44/arch/x86/mm/highmem_32.c linux-2.6.32.44/arch/x86/mm/highmem_32.c
21336--- linux-2.6.32.44/arch/x86/mm/highmem_32.c 2011-03-27 14:31:47.000000000 -0400
21337+++ linux-2.6.32.44/arch/x86/mm/highmem_32.c 2011-04-17 15:56:46.000000000 -0400
21338@@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page
21339 idx = type + KM_TYPE_NR*smp_processor_id();
21340 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21341 BUG_ON(!pte_none(*(kmap_pte-idx)));
21342+
21343+ pax_open_kernel();
21344 set_pte(kmap_pte-idx, mk_pte(page, prot));
21345+ pax_close_kernel();
21346
21347 return (void *)vaddr;
21348 }
21349diff -urNp linux-2.6.32.44/arch/x86/mm/hugetlbpage.c linux-2.6.32.44/arch/x86/mm/hugetlbpage.c
21350--- linux-2.6.32.44/arch/x86/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
21351+++ linux-2.6.32.44/arch/x86/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
21352@@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmappe
21353 struct hstate *h = hstate_file(file);
21354 struct mm_struct *mm = current->mm;
21355 struct vm_area_struct *vma;
21356- unsigned long start_addr;
21357+ unsigned long start_addr, pax_task_size = TASK_SIZE;
21358+
21359+#ifdef CONFIG_PAX_SEGMEXEC
21360+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21361+ pax_task_size = SEGMEXEC_TASK_SIZE;
21362+#endif
21363+
21364+ pax_task_size -= PAGE_SIZE;
21365
21366 if (len > mm->cached_hole_size) {
21367- start_addr = mm->free_area_cache;
21368+ start_addr = mm->free_area_cache;
21369 } else {
21370- start_addr = TASK_UNMAPPED_BASE;
21371- mm->cached_hole_size = 0;
21372+ start_addr = mm->mmap_base;
21373+ mm->cached_hole_size = 0;
21374 }
21375
21376 full_search:
21377@@ -281,26 +288,27 @@ full_search:
21378
21379 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21380 /* At this point: (!vma || addr < vma->vm_end). */
21381- if (TASK_SIZE - len < addr) {
21382+ if (pax_task_size - len < addr) {
21383 /*
21384 * Start a new search - just in case we missed
21385 * some holes.
21386 */
21387- if (start_addr != TASK_UNMAPPED_BASE) {
21388- start_addr = TASK_UNMAPPED_BASE;
21389+ if (start_addr != mm->mmap_base) {
21390+ start_addr = mm->mmap_base;
21391 mm->cached_hole_size = 0;
21392 goto full_search;
21393 }
21394 return -ENOMEM;
21395 }
21396- if (!vma || addr + len <= vma->vm_start) {
21397- mm->free_area_cache = addr + len;
21398- return addr;
21399- }
21400+ if (check_heap_stack_gap(vma, addr, len))
21401+ break;
21402 if (addr + mm->cached_hole_size < vma->vm_start)
21403 mm->cached_hole_size = vma->vm_start - addr;
21404 addr = ALIGN(vma->vm_end, huge_page_size(h));
21405 }
21406+
21407+ mm->free_area_cache = addr + len;
21408+ return addr;
21409 }
21410
21411 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21412@@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmappe
21413 {
21414 struct hstate *h = hstate_file(file);
21415 struct mm_struct *mm = current->mm;
21416- struct vm_area_struct *vma, *prev_vma;
21417- unsigned long base = mm->mmap_base, addr = addr0;
21418+ struct vm_area_struct *vma;
21419+ unsigned long base = mm->mmap_base, addr;
21420 unsigned long largest_hole = mm->cached_hole_size;
21421- int first_time = 1;
21422
21423 /* don't allow allocations above current base */
21424 if (mm->free_area_cache > base)
21425@@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmappe
21426 largest_hole = 0;
21427 mm->free_area_cache = base;
21428 }
21429-try_again:
21430+
21431 /* make sure it can fit in the remaining address space */
21432 if (mm->free_area_cache < len)
21433 goto fail;
21434
21435 /* either no address requested or cant fit in requested address hole */
21436- addr = (mm->free_area_cache - len) & huge_page_mask(h);
21437+ addr = (mm->free_area_cache - len);
21438 do {
21439+ addr &= huge_page_mask(h);
21440+ vma = find_vma(mm, addr);
21441 /*
21442 * Lookup failure means no vma is above this address,
21443 * i.e. return with success:
21444- */
21445- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21446- return addr;
21447-
21448- /*
21449 * new region fits between prev_vma->vm_end and
21450 * vma->vm_start, use it:
21451 */
21452- if (addr + len <= vma->vm_start &&
21453- (!prev_vma || (addr >= prev_vma->vm_end))) {
21454+ if (check_heap_stack_gap(vma, addr, len)) {
21455 /* remember the address as a hint for next time */
21456- mm->cached_hole_size = largest_hole;
21457- return (mm->free_area_cache = addr);
21458- } else {
21459- /* pull free_area_cache down to the first hole */
21460- if (mm->free_area_cache == vma->vm_end) {
21461- mm->free_area_cache = vma->vm_start;
21462- mm->cached_hole_size = largest_hole;
21463- }
21464+ mm->cached_hole_size = largest_hole;
21465+ return (mm->free_area_cache = addr);
21466+ }
21467+ /* pull free_area_cache down to the first hole */
21468+ if (mm->free_area_cache == vma->vm_end) {
21469+ mm->free_area_cache = vma->vm_start;
21470+ mm->cached_hole_size = largest_hole;
21471 }
21472
21473 /* remember the largest hole we saw so far */
21474 if (addr + largest_hole < vma->vm_start)
21475- largest_hole = vma->vm_start - addr;
21476+ largest_hole = vma->vm_start - addr;
21477
21478 /* try just below the current vma->vm_start */
21479- addr = (vma->vm_start - len) & huge_page_mask(h);
21480- } while (len <= vma->vm_start);
21481+ addr = skip_heap_stack_gap(vma, len);
21482+ } while (!IS_ERR_VALUE(addr));
21483
21484 fail:
21485 /*
21486- * if hint left us with no space for the requested
21487- * mapping then try again:
21488- */
21489- if (first_time) {
21490- mm->free_area_cache = base;
21491- largest_hole = 0;
21492- first_time = 0;
21493- goto try_again;
21494- }
21495- /*
21496 * A failed mmap() very likely causes application failure,
21497 * so fall back to the bottom-up function here. This scenario
21498 * can happen with large stack limits and large mmap()
21499 * allocations.
21500 */
21501- mm->free_area_cache = TASK_UNMAPPED_BASE;
21502+
21503+#ifdef CONFIG_PAX_SEGMEXEC
21504+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21505+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21506+ else
21507+#endif
21508+
21509+ mm->mmap_base = TASK_UNMAPPED_BASE;
21510+
21511+#ifdef CONFIG_PAX_RANDMMAP
21512+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21513+ mm->mmap_base += mm->delta_mmap;
21514+#endif
21515+
21516+ mm->free_area_cache = mm->mmap_base;
21517 mm->cached_hole_size = ~0UL;
21518 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21519 len, pgoff, flags);
21520@@ -387,6 +393,7 @@ fail:
21521 /*
21522 * Restore the topdown base:
21523 */
21524+ mm->mmap_base = base;
21525 mm->free_area_cache = base;
21526 mm->cached_hole_size = ~0UL;
21527
21528@@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *f
21529 struct hstate *h = hstate_file(file);
21530 struct mm_struct *mm = current->mm;
21531 struct vm_area_struct *vma;
21532+ unsigned long pax_task_size = TASK_SIZE;
21533
21534 if (len & ~huge_page_mask(h))
21535 return -EINVAL;
21536- if (len > TASK_SIZE)
21537+
21538+#ifdef CONFIG_PAX_SEGMEXEC
21539+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21540+ pax_task_size = SEGMEXEC_TASK_SIZE;
21541+#endif
21542+
21543+ pax_task_size -= PAGE_SIZE;
21544+
21545+ if (len > pax_task_size)
21546 return -ENOMEM;
21547
21548 if (flags & MAP_FIXED) {
21549@@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *f
21550 if (addr) {
21551 addr = ALIGN(addr, huge_page_size(h));
21552 vma = find_vma(mm, addr);
21553- if (TASK_SIZE - len >= addr &&
21554- (!vma || addr + len <= vma->vm_start))
21555+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21556 return addr;
21557 }
21558 if (mm->get_unmapped_area == arch_get_unmapped_area)
21559diff -urNp linux-2.6.32.44/arch/x86/mm/init_32.c linux-2.6.32.44/arch/x86/mm/init_32.c
21560--- linux-2.6.32.44/arch/x86/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
21561+++ linux-2.6.32.44/arch/x86/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
21562@@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
21563 }
21564
21565 /*
21566- * Creates a middle page table and puts a pointer to it in the
21567- * given global directory entry. This only returns the gd entry
21568- * in non-PAE compilation mode, since the middle layer is folded.
21569- */
21570-static pmd_t * __init one_md_table_init(pgd_t *pgd)
21571-{
21572- pud_t *pud;
21573- pmd_t *pmd_table;
21574-
21575-#ifdef CONFIG_X86_PAE
21576- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21577- if (after_bootmem)
21578- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21579- else
21580- pmd_table = (pmd_t *)alloc_low_page();
21581- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21582- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21583- pud = pud_offset(pgd, 0);
21584- BUG_ON(pmd_table != pmd_offset(pud, 0));
21585-
21586- return pmd_table;
21587- }
21588-#endif
21589- pud = pud_offset(pgd, 0);
21590- pmd_table = pmd_offset(pud, 0);
21591-
21592- return pmd_table;
21593-}
21594-
21595-/*
21596 * Create a page table and place a pointer to it in a middle page
21597 * directory entry:
21598 */
21599@@ -121,13 +91,28 @@ static pte_t * __init one_page_table_ini
21600 page_table = (pte_t *)alloc_low_page();
21601
21602 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
21603+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21604+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
21605+#else
21606 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
21607+#endif
21608 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
21609 }
21610
21611 return pte_offset_kernel(pmd, 0);
21612 }
21613
21614+static pmd_t * __init one_md_table_init(pgd_t *pgd)
21615+{
21616+ pud_t *pud;
21617+ pmd_t *pmd_table;
21618+
21619+ pud = pud_offset(pgd, 0);
21620+ pmd_table = pmd_offset(pud, 0);
21621+
21622+ return pmd_table;
21623+}
21624+
21625 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
21626 {
21627 int pgd_idx = pgd_index(vaddr);
21628@@ -201,6 +186,7 @@ page_table_range_init(unsigned long star
21629 int pgd_idx, pmd_idx;
21630 unsigned long vaddr;
21631 pgd_t *pgd;
21632+ pud_t *pud;
21633 pmd_t *pmd;
21634 pte_t *pte = NULL;
21635
21636@@ -210,8 +196,13 @@ page_table_range_init(unsigned long star
21637 pgd = pgd_base + pgd_idx;
21638
21639 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
21640- pmd = one_md_table_init(pgd);
21641- pmd = pmd + pmd_index(vaddr);
21642+ pud = pud_offset(pgd, vaddr);
21643+ pmd = pmd_offset(pud, vaddr);
21644+
21645+#ifdef CONFIG_X86_PAE
21646+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21647+#endif
21648+
21649 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
21650 pmd++, pmd_idx++) {
21651 pte = page_table_kmap_check(one_page_table_init(pmd),
21652@@ -223,11 +214,20 @@ page_table_range_init(unsigned long star
21653 }
21654 }
21655
21656-static inline int is_kernel_text(unsigned long addr)
21657+static inline int is_kernel_text(unsigned long start, unsigned long end)
21658 {
21659- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
21660- return 1;
21661- return 0;
21662+ if ((start > ktla_ktva((unsigned long)_etext) ||
21663+ end <= ktla_ktva((unsigned long)_stext)) &&
21664+ (start > ktla_ktva((unsigned long)_einittext) ||
21665+ end <= ktla_ktva((unsigned long)_sinittext)) &&
21666+
21667+#ifdef CONFIG_ACPI_SLEEP
21668+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
21669+#endif
21670+
21671+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
21672+ return 0;
21673+ return 1;
21674 }
21675
21676 /*
21677@@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned lo
21678 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
21679 unsigned long start_pfn, end_pfn;
21680 pgd_t *pgd_base = swapper_pg_dir;
21681- int pgd_idx, pmd_idx, pte_ofs;
21682+ unsigned int pgd_idx, pmd_idx, pte_ofs;
21683 unsigned long pfn;
21684 pgd_t *pgd;
21685+ pud_t *pud;
21686 pmd_t *pmd;
21687 pte_t *pte;
21688 unsigned pages_2m, pages_4k;
21689@@ -278,8 +279,13 @@ repeat:
21690 pfn = start_pfn;
21691 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21692 pgd = pgd_base + pgd_idx;
21693- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
21694- pmd = one_md_table_init(pgd);
21695+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
21696+ pud = pud_offset(pgd, 0);
21697+ pmd = pmd_offset(pud, 0);
21698+
21699+#ifdef CONFIG_X86_PAE
21700+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21701+#endif
21702
21703 if (pfn >= end_pfn)
21704 continue;
21705@@ -291,14 +297,13 @@ repeat:
21706 #endif
21707 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
21708 pmd++, pmd_idx++) {
21709- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
21710+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
21711
21712 /*
21713 * Map with big pages if possible, otherwise
21714 * create normal page tables:
21715 */
21716 if (use_pse) {
21717- unsigned int addr2;
21718 pgprot_t prot = PAGE_KERNEL_LARGE;
21719 /*
21720 * first pass will use the same initial
21721@@ -308,11 +313,7 @@ repeat:
21722 __pgprot(PTE_IDENT_ATTR |
21723 _PAGE_PSE);
21724
21725- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
21726- PAGE_OFFSET + PAGE_SIZE-1;
21727-
21728- if (is_kernel_text(addr) ||
21729- is_kernel_text(addr2))
21730+ if (is_kernel_text(address, address + PMD_SIZE))
21731 prot = PAGE_KERNEL_LARGE_EXEC;
21732
21733 pages_2m++;
21734@@ -329,7 +330,7 @@ repeat:
21735 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21736 pte += pte_ofs;
21737 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
21738- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
21739+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
21740 pgprot_t prot = PAGE_KERNEL;
21741 /*
21742 * first pass will use the same initial
21743@@ -337,7 +338,7 @@ repeat:
21744 */
21745 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
21746
21747- if (is_kernel_text(addr))
21748+ if (is_kernel_text(address, address + PAGE_SIZE))
21749 prot = PAGE_KERNEL_EXEC;
21750
21751 pages_4k++;
21752@@ -489,7 +490,7 @@ void __init native_pagetable_setup_start
21753
21754 pud = pud_offset(pgd, va);
21755 pmd = pmd_offset(pud, va);
21756- if (!pmd_present(*pmd))
21757+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
21758 break;
21759
21760 pte = pte_offset_kernel(pmd, va);
21761@@ -541,9 +542,7 @@ void __init early_ioremap_page_table_ran
21762
21763 static void __init pagetable_init(void)
21764 {
21765- pgd_t *pgd_base = swapper_pg_dir;
21766-
21767- permanent_kmaps_init(pgd_base);
21768+ permanent_kmaps_init(swapper_pg_dir);
21769 }
21770
21771 #ifdef CONFIG_ACPI_SLEEP
21772@@ -551,12 +550,12 @@ static void __init pagetable_init(void)
21773 * ACPI suspend needs this for resume, because things like the intel-agp
21774 * driver might have split up a kernel 4MB mapping.
21775 */
21776-char swsusp_pg_dir[PAGE_SIZE]
21777+pgd_t swsusp_pg_dir[PTRS_PER_PGD]
21778 __attribute__ ((aligned(PAGE_SIZE)));
21779
21780 static inline void save_pg_dir(void)
21781 {
21782- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
21783+ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
21784 }
21785 #else /* !CONFIG_ACPI_SLEEP */
21786 static inline void save_pg_dir(void)
21787@@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
21788 flush_tlb_all();
21789 }
21790
21791-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
21792+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
21793 EXPORT_SYMBOL_GPL(__supported_pte_mask);
21794
21795 /* user-defined highmem size */
21796@@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void
21797 * Initialize the boot-time allocator (with low memory only):
21798 */
21799 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
21800- bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
21801+ bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
21802 PAGE_SIZE);
21803 if (bootmap == -1L)
21804 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
21805@@ -864,6 +863,12 @@ void __init mem_init(void)
21806
21807 pci_iommu_alloc();
21808
21809+#ifdef CONFIG_PAX_PER_CPU_PGD
21810+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
21811+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21812+ KERNEL_PGD_PTRS);
21813+#endif
21814+
21815 #ifdef CONFIG_FLATMEM
21816 BUG_ON(!mem_map);
21817 #endif
21818@@ -881,7 +886,7 @@ void __init mem_init(void)
21819 set_highmem_pages_init();
21820
21821 codesize = (unsigned long) &_etext - (unsigned long) &_text;
21822- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
21823+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
21824 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
21825
21826 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
21827@@ -923,10 +928,10 @@ void __init mem_init(void)
21828 ((unsigned long)&__init_end -
21829 (unsigned long)&__init_begin) >> 10,
21830
21831- (unsigned long)&_etext, (unsigned long)&_edata,
21832- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
21833+ (unsigned long)&_sdata, (unsigned long)&_edata,
21834+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
21835
21836- (unsigned long)&_text, (unsigned long)&_etext,
21837+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
21838 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
21839
21840 /*
21841@@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
21842 if (!kernel_set_to_readonly)
21843 return;
21844
21845+ start = ktla_ktva(start);
21846 pr_debug("Set kernel text: %lx - %lx for read write\n",
21847 start, start+size);
21848
21849@@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
21850 if (!kernel_set_to_readonly)
21851 return;
21852
21853+ start = ktla_ktva(start);
21854 pr_debug("Set kernel text: %lx - %lx for read only\n",
21855 start, start+size);
21856
21857@@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
21858 unsigned long start = PFN_ALIGN(_text);
21859 unsigned long size = PFN_ALIGN(_etext) - start;
21860
21861+ start = ktla_ktva(start);
21862 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
21863 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
21864 size >> 10);
21865diff -urNp linux-2.6.32.44/arch/x86/mm/init_64.c linux-2.6.32.44/arch/x86/mm/init_64.c
21866--- linux-2.6.32.44/arch/x86/mm/init_64.c 2011-04-17 17:00:52.000000000 -0400
21867+++ linux-2.6.32.44/arch/x86/mm/init_64.c 2011-04-17 17:03:05.000000000 -0400
21868@@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
21869 pmd = fill_pmd(pud, vaddr);
21870 pte = fill_pte(pmd, vaddr);
21871
21872+ pax_open_kernel();
21873 set_pte(pte, new_pte);
21874+ pax_close_kernel();
21875
21876 /*
21877 * It's enough to flush this one mapping.
21878@@ -223,14 +225,12 @@ static void __init __init_extra_mapping(
21879 pgd = pgd_offset_k((unsigned long)__va(phys));
21880 if (pgd_none(*pgd)) {
21881 pud = (pud_t *) spp_getpage();
21882- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
21883- _PAGE_USER));
21884+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
21885 }
21886 pud = pud_offset(pgd, (unsigned long)__va(phys));
21887 if (pud_none(*pud)) {
21888 pmd = (pmd_t *) spp_getpage();
21889- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
21890- _PAGE_USER));
21891+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
21892 }
21893 pmd = pmd_offset(pud, phys);
21894 BUG_ON(!pmd_none(*pmd));
21895@@ -675,6 +675,12 @@ void __init mem_init(void)
21896
21897 pci_iommu_alloc();
21898
21899+#ifdef CONFIG_PAX_PER_CPU_PGD
21900+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
21901+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21902+ KERNEL_PGD_PTRS);
21903+#endif
21904+
21905 /* clear_bss() already clear the empty_zero_page */
21906
21907 reservedpages = 0;
21908@@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
21909 static struct vm_area_struct gate_vma = {
21910 .vm_start = VSYSCALL_START,
21911 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
21912- .vm_page_prot = PAGE_READONLY_EXEC,
21913- .vm_flags = VM_READ | VM_EXEC
21914+ .vm_page_prot = PAGE_READONLY,
21915+ .vm_flags = VM_READ
21916 };
21917
21918 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
21919@@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long a
21920
21921 const char *arch_vma_name(struct vm_area_struct *vma)
21922 {
21923- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
21924+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
21925 return "[vdso]";
21926 if (vma == &gate_vma)
21927 return "[vsyscall]";
21928diff -urNp linux-2.6.32.44/arch/x86/mm/init.c linux-2.6.32.44/arch/x86/mm/init.c
21929--- linux-2.6.32.44/arch/x86/mm/init.c 2011-04-17 17:00:52.000000000 -0400
21930+++ linux-2.6.32.44/arch/x86/mm/init.c 2011-06-07 19:06:09.000000000 -0400
21931@@ -69,11 +69,7 @@ static void __init find_early_table_spac
21932 * cause a hotspot and fill up ZONE_DMA. The page tables
21933 * need roughly 0.5KB per GB.
21934 */
21935-#ifdef CONFIG_X86_32
21936- start = 0x7000;
21937-#else
21938- start = 0x8000;
21939-#endif
21940+ start = 0x100000;
21941 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
21942 tables, PAGE_SIZE);
21943 if (e820_table_start == -1UL)
21944@@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_m
21945 #endif
21946
21947 set_nx();
21948- if (nx_enabled)
21949+ if (nx_enabled && cpu_has_nx)
21950 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
21951
21952 /* Enable PSE if available */
21953@@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_m
21954 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
21955 * mmio resources as well as potential bios/acpi data regions.
21956 */
21957+
21958 int devmem_is_allowed(unsigned long pagenr)
21959 {
21960+#ifdef CONFIG_GRKERNSEC_KMEM
21961+ /* allow BDA */
21962+ if (!pagenr)
21963+ return 1;
21964+ /* allow EBDA */
21965+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
21966+ return 1;
21967+ /* allow ISA/video mem */
21968+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
21969+ return 1;
21970+ /* throw out everything else below 1MB */
21971+ if (pagenr <= 256)
21972+ return 0;
21973+#else
21974 if (pagenr <= 256)
21975 return 1;
21976+#endif
21977+
21978 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
21979 return 0;
21980 if (!page_is_ram(pagenr))
21981@@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigne
21982
21983 void free_initmem(void)
21984 {
21985+
21986+#ifdef CONFIG_PAX_KERNEXEC
21987+#ifdef CONFIG_X86_32
21988+ /* PaX: limit KERNEL_CS to actual size */
21989+ unsigned long addr, limit;
21990+ struct desc_struct d;
21991+ int cpu;
21992+
21993+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
21994+ limit = (limit - 1UL) >> PAGE_SHIFT;
21995+
21996+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
21997+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
21998+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
21999+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22000+ }
22001+
22002+ /* PaX: make KERNEL_CS read-only */
22003+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22004+ if (!paravirt_enabled())
22005+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22006+/*
22007+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22008+ pgd = pgd_offset_k(addr);
22009+ pud = pud_offset(pgd, addr);
22010+ pmd = pmd_offset(pud, addr);
22011+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22012+ }
22013+*/
22014+#ifdef CONFIG_X86_PAE
22015+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22016+/*
22017+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22018+ pgd = pgd_offset_k(addr);
22019+ pud = pud_offset(pgd, addr);
22020+ pmd = pmd_offset(pud, addr);
22021+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22022+ }
22023+*/
22024+#endif
22025+
22026+#ifdef CONFIG_MODULES
22027+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22028+#endif
22029+
22030+#else
22031+ pgd_t *pgd;
22032+ pud_t *pud;
22033+ pmd_t *pmd;
22034+ unsigned long addr, end;
22035+
22036+ /* PaX: make kernel code/rodata read-only, rest non-executable */
22037+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22038+ pgd = pgd_offset_k(addr);
22039+ pud = pud_offset(pgd, addr);
22040+ pmd = pmd_offset(pud, addr);
22041+ if (!pmd_present(*pmd))
22042+ continue;
22043+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22044+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22045+ else
22046+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22047+ }
22048+
22049+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22050+ end = addr + KERNEL_IMAGE_SIZE;
22051+ for (; addr < end; addr += PMD_SIZE) {
22052+ pgd = pgd_offset_k(addr);
22053+ pud = pud_offset(pgd, addr);
22054+ pmd = pmd_offset(pud, addr);
22055+ if (!pmd_present(*pmd))
22056+ continue;
22057+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22058+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22059+ }
22060+#endif
22061+
22062+ flush_tlb_all();
22063+#endif
22064+
22065 free_init_pages("unused kernel memory",
22066 (unsigned long)(&__init_begin),
22067 (unsigned long)(&__init_end));
22068diff -urNp linux-2.6.32.44/arch/x86/mm/iomap_32.c linux-2.6.32.44/arch/x86/mm/iomap_32.c
22069--- linux-2.6.32.44/arch/x86/mm/iomap_32.c 2011-03-27 14:31:47.000000000 -0400
22070+++ linux-2.6.32.44/arch/x86/mm/iomap_32.c 2011-04-17 15:56:46.000000000 -0400
22071@@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22072 debug_kmap_atomic(type);
22073 idx = type + KM_TYPE_NR * smp_processor_id();
22074 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22075+
22076+ pax_open_kernel();
22077 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22078+ pax_close_kernel();
22079+
22080 arch_flush_lazy_mmu_mode();
22081
22082 return (void *)vaddr;
22083diff -urNp linux-2.6.32.44/arch/x86/mm/ioremap.c linux-2.6.32.44/arch/x86/mm/ioremap.c
22084--- linux-2.6.32.44/arch/x86/mm/ioremap.c 2011-03-27 14:31:47.000000000 -0400
22085+++ linux-2.6.32.44/arch/x86/mm/ioremap.c 2011-04-17 15:56:46.000000000 -0400
22086@@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
22087 * Second special case: Some BIOSen report the PC BIOS
22088 * area (640->1Mb) as ram even though it is not.
22089 */
22090- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
22091- pagenr < (BIOS_END >> PAGE_SHIFT))
22092+ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
22093+ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22094 return 0;
22095
22096 for (i = 0; i < e820.nr_map; i++) {
22097@@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(re
22098 /*
22099 * Don't allow anybody to remap normal RAM that we're using..
22100 */
22101- for (pfn = phys_addr >> PAGE_SHIFT;
22102- (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
22103- pfn++) {
22104-
22105+ for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
22106 int is_ram = page_is_ram(pfn);
22107
22108- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22109+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22110 return NULL;
22111 WARN_ON_ONCE(is_ram);
22112 }
22113@@ -407,7 +404,7 @@ static int __init early_ioremap_debug_se
22114 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22115
22116 static __initdata int after_paging_init;
22117-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22118+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22119
22120 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22121 {
22122@@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
22123 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22124
22125 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22126- memset(bm_pte, 0, sizeof(bm_pte));
22127- pmd_populate_kernel(&init_mm, pmd, bm_pte);
22128+ pmd_populate_user(&init_mm, pmd, bm_pte);
22129
22130 /*
22131 * The boot-ioremap range spans multiple pmds, for which
22132diff -urNp linux-2.6.32.44/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.32.44/arch/x86/mm/kmemcheck/kmemcheck.c
22133--- linux-2.6.32.44/arch/x86/mm/kmemcheck/kmemcheck.c 2011-03-27 14:31:47.000000000 -0400
22134+++ linux-2.6.32.44/arch/x86/mm/kmemcheck/kmemcheck.c 2011-04-17 15:56:46.000000000 -0400
22135@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22136 * memory (e.g. tracked pages)? For now, we need this to avoid
22137 * invoking kmemcheck for PnP BIOS calls.
22138 */
22139- if (regs->flags & X86_VM_MASK)
22140+ if (v8086_mode(regs))
22141 return false;
22142- if (regs->cs != __KERNEL_CS)
22143+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22144 return false;
22145
22146 pte = kmemcheck_pte_lookup(address);
22147diff -urNp linux-2.6.32.44/arch/x86/mm/mmap.c linux-2.6.32.44/arch/x86/mm/mmap.c
22148--- linux-2.6.32.44/arch/x86/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
22149+++ linux-2.6.32.44/arch/x86/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
22150@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22151 * Leave an at least ~128 MB hole with possible stack randomization.
22152 */
22153 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22154-#define MAX_GAP (TASK_SIZE/6*5)
22155+#define MAX_GAP (pax_task_size/6*5)
22156
22157 /*
22158 * True on X86_32 or when emulating IA32 on X86_64
22159@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22160 return rnd << PAGE_SHIFT;
22161 }
22162
22163-static unsigned long mmap_base(void)
22164+static unsigned long mmap_base(struct mm_struct *mm)
22165 {
22166 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
22167+ unsigned long pax_task_size = TASK_SIZE;
22168+
22169+#ifdef CONFIG_PAX_SEGMEXEC
22170+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22171+ pax_task_size = SEGMEXEC_TASK_SIZE;
22172+#endif
22173
22174 if (gap < MIN_GAP)
22175 gap = MIN_GAP;
22176 else if (gap > MAX_GAP)
22177 gap = MAX_GAP;
22178
22179- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22180+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22181 }
22182
22183 /*
22184 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22185 * does, but not when emulating X86_32
22186 */
22187-static unsigned long mmap_legacy_base(void)
22188+static unsigned long mmap_legacy_base(struct mm_struct *mm)
22189 {
22190- if (mmap_is_ia32())
22191+ if (mmap_is_ia32()) {
22192+
22193+#ifdef CONFIG_PAX_SEGMEXEC
22194+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22195+ return SEGMEXEC_TASK_UNMAPPED_BASE;
22196+ else
22197+#endif
22198+
22199 return TASK_UNMAPPED_BASE;
22200- else
22201+ } else
22202 return TASK_UNMAPPED_BASE + mmap_rnd();
22203 }
22204
22205@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22206 void arch_pick_mmap_layout(struct mm_struct *mm)
22207 {
22208 if (mmap_is_legacy()) {
22209- mm->mmap_base = mmap_legacy_base();
22210+ mm->mmap_base = mmap_legacy_base(mm);
22211+
22212+#ifdef CONFIG_PAX_RANDMMAP
22213+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22214+ mm->mmap_base += mm->delta_mmap;
22215+#endif
22216+
22217 mm->get_unmapped_area = arch_get_unmapped_area;
22218 mm->unmap_area = arch_unmap_area;
22219 } else {
22220- mm->mmap_base = mmap_base();
22221+ mm->mmap_base = mmap_base(mm);
22222+
22223+#ifdef CONFIG_PAX_RANDMMAP
22224+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22225+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22226+#endif
22227+
22228 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22229 mm->unmap_area = arch_unmap_area_topdown;
22230 }
22231diff -urNp linux-2.6.32.44/arch/x86/mm/mmio-mod.c linux-2.6.32.44/arch/x86/mm/mmio-mod.c
22232--- linux-2.6.32.44/arch/x86/mm/mmio-mod.c 2011-03-27 14:31:47.000000000 -0400
22233+++ linux-2.6.32.44/arch/x86/mm/mmio-mod.c 2011-07-06 19:53:33.000000000 -0400
22234@@ -193,7 +193,7 @@ static void pre(struct kmmio_probe *p, s
22235 break;
22236 default:
22237 {
22238- unsigned char *ip = (unsigned char *)instptr;
22239+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
22240 my_trace->opcode = MMIO_UNKNOWN_OP;
22241 my_trace->width = 0;
22242 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
22243@@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p,
22244 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22245 void __iomem *addr)
22246 {
22247- static atomic_t next_id;
22248+ static atomic_unchecked_t next_id;
22249 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22250 /* These are page-unaligned. */
22251 struct mmiotrace_map map = {
22252@@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_
22253 .private = trace
22254 },
22255 .phys = offset,
22256- .id = atomic_inc_return(&next_id)
22257+ .id = atomic_inc_return_unchecked(&next_id)
22258 };
22259 map.map_id = trace->id;
22260
22261diff -urNp linux-2.6.32.44/arch/x86/mm/numa_32.c linux-2.6.32.44/arch/x86/mm/numa_32.c
22262--- linux-2.6.32.44/arch/x86/mm/numa_32.c 2011-03-27 14:31:47.000000000 -0400
22263+++ linux-2.6.32.44/arch/x86/mm/numa_32.c 2011-04-17 15:56:46.000000000 -0400
22264@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
22265 }
22266 #endif
22267
22268-extern unsigned long find_max_low_pfn(void);
22269 extern unsigned long highend_pfn, highstart_pfn;
22270
22271 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22272diff -urNp linux-2.6.32.44/arch/x86/mm/pageattr.c linux-2.6.32.44/arch/x86/mm/pageattr.c
22273--- linux-2.6.32.44/arch/x86/mm/pageattr.c 2011-03-27 14:31:47.000000000 -0400
22274+++ linux-2.6.32.44/arch/x86/mm/pageattr.c 2011-04-17 15:56:46.000000000 -0400
22275@@ -261,16 +261,17 @@ static inline pgprot_t static_protection
22276 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
22277 */
22278 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22279- pgprot_val(forbidden) |= _PAGE_NX;
22280+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22281
22282 /*
22283 * The kernel text needs to be executable for obvious reasons
22284 * Does not cover __inittext since that is gone later on. On
22285 * 64bit we do not enforce !NX on the low mapping
22286 */
22287- if (within(address, (unsigned long)_text, (unsigned long)_etext))
22288- pgprot_val(forbidden) |= _PAGE_NX;
22289+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22290+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22291
22292+#ifdef CONFIG_DEBUG_RODATA
22293 /*
22294 * The .rodata section needs to be read-only. Using the pfn
22295 * catches all aliases.
22296@@ -278,6 +279,14 @@ static inline pgprot_t static_protection
22297 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22298 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22299 pgprot_val(forbidden) |= _PAGE_RW;
22300+#endif
22301+
22302+#ifdef CONFIG_PAX_KERNEXEC
22303+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22304+ pgprot_val(forbidden) |= _PAGE_RW;
22305+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22306+ }
22307+#endif
22308
22309 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22310
22311@@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22312 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22313 {
22314 /* change init_mm */
22315+ pax_open_kernel();
22316 set_pte_atomic(kpte, pte);
22317+
22318 #ifdef CONFIG_X86_32
22319 if (!SHARED_KERNEL_PMD) {
22320+
22321+#ifdef CONFIG_PAX_PER_CPU_PGD
22322+ unsigned long cpu;
22323+#else
22324 struct page *page;
22325+#endif
22326
22327+#ifdef CONFIG_PAX_PER_CPU_PGD
22328+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22329+ pgd_t *pgd = get_cpu_pgd(cpu);
22330+#else
22331 list_for_each_entry(page, &pgd_list, lru) {
22332- pgd_t *pgd;
22333+ pgd_t *pgd = (pgd_t *)page_address(page);
22334+#endif
22335+
22336 pud_t *pud;
22337 pmd_t *pmd;
22338
22339- pgd = (pgd_t *)page_address(page) + pgd_index(address);
22340+ pgd += pgd_index(address);
22341 pud = pud_offset(pgd, address);
22342 pmd = pmd_offset(pud, address);
22343 set_pte_atomic((pte_t *)pmd, pte);
22344 }
22345 }
22346 #endif
22347+ pax_close_kernel();
22348 }
22349
22350 static int
22351diff -urNp linux-2.6.32.44/arch/x86/mm/pageattr-test.c linux-2.6.32.44/arch/x86/mm/pageattr-test.c
22352--- linux-2.6.32.44/arch/x86/mm/pageattr-test.c 2011-03-27 14:31:47.000000000 -0400
22353+++ linux-2.6.32.44/arch/x86/mm/pageattr-test.c 2011-04-17 15:56:46.000000000 -0400
22354@@ -36,7 +36,7 @@ enum {
22355
22356 static int pte_testbit(pte_t pte)
22357 {
22358- return pte_flags(pte) & _PAGE_UNUSED1;
22359+ return pte_flags(pte) & _PAGE_CPA_TEST;
22360 }
22361
22362 struct split_state {
22363diff -urNp linux-2.6.32.44/arch/x86/mm/pat.c linux-2.6.32.44/arch/x86/mm/pat.c
22364--- linux-2.6.32.44/arch/x86/mm/pat.c 2011-03-27 14:31:47.000000000 -0400
22365+++ linux-2.6.32.44/arch/x86/mm/pat.c 2011-04-17 15:56:46.000000000 -0400
22366@@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct
22367
22368 conflict:
22369 printk(KERN_INFO "%s:%d conflicting memory types "
22370- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
22371+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
22372 new->end, cattr_name(new->type), cattr_name(entry->type));
22373 return -EBUSY;
22374 }
22375@@ -559,7 +559,7 @@ unlock_ret:
22376
22377 if (err) {
22378 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22379- current->comm, current->pid, start, end);
22380+ current->comm, task_pid_nr(current), start, end);
22381 }
22382
22383 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
22384@@ -689,8 +689,8 @@ static inline int range_is_allowed(unsig
22385 while (cursor < to) {
22386 if (!devmem_is_allowed(pfn)) {
22387 printk(KERN_INFO
22388- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22389- current->comm, from, to);
22390+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22391+ current->comm, from, to, cursor);
22392 return 0;
22393 }
22394 cursor += PAGE_SIZE;
22395@@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, un
22396 printk(KERN_INFO
22397 "%s:%d ioremap_change_attr failed %s "
22398 "for %Lx-%Lx\n",
22399- current->comm, current->pid,
22400+ current->comm, task_pid_nr(current),
22401 cattr_name(flags),
22402 base, (unsigned long long)(base + size));
22403 return -EINVAL;
22404@@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr,
22405 free_memtype(paddr, paddr + size);
22406 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22407 " for %Lx-%Lx, got %s\n",
22408- current->comm, current->pid,
22409+ current->comm, task_pid_nr(current),
22410 cattr_name(want_flags),
22411 (unsigned long long)paddr,
22412 (unsigned long long)(paddr + size),
22413diff -urNp linux-2.6.32.44/arch/x86/mm/pf_in.c linux-2.6.32.44/arch/x86/mm/pf_in.c
22414--- linux-2.6.32.44/arch/x86/mm/pf_in.c 2011-03-27 14:31:47.000000000 -0400
22415+++ linux-2.6.32.44/arch/x86/mm/pf_in.c 2011-07-06 19:53:33.000000000 -0400
22416@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned l
22417 int i;
22418 enum reason_type rv = OTHERS;
22419
22420- p = (unsigned char *)ins_addr;
22421+ p = (unsigned char *)ktla_ktva(ins_addr);
22422 p += skip_prefix(p, &prf);
22423 p += get_opcode(p, &opcode);
22424
22425@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(un
22426 struct prefix_bits prf;
22427 int i;
22428
22429- p = (unsigned char *)ins_addr;
22430+ p = (unsigned char *)ktla_ktva(ins_addr);
22431 p += skip_prefix(p, &prf);
22432 p += get_opcode(p, &opcode);
22433
22434@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned
22435 struct prefix_bits prf;
22436 int i;
22437
22438- p = (unsigned char *)ins_addr;
22439+ p = (unsigned char *)ktla_ktva(ins_addr);
22440 p += skip_prefix(p, &prf);
22441 p += get_opcode(p, &opcode);
22442
22443@@ -417,7 +417,7 @@ unsigned long get_ins_reg_val(unsigned l
22444 int i;
22445 unsigned long rv;
22446
22447- p = (unsigned char *)ins_addr;
22448+ p = (unsigned char *)ktla_ktva(ins_addr);
22449 p += skip_prefix(p, &prf);
22450 p += get_opcode(p, &opcode);
22451 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
22452@@ -472,7 +472,7 @@ unsigned long get_ins_imm_val(unsigned l
22453 int i;
22454 unsigned long rv;
22455
22456- p = (unsigned char *)ins_addr;
22457+ p = (unsigned char *)ktla_ktva(ins_addr);
22458 p += skip_prefix(p, &prf);
22459 p += get_opcode(p, &opcode);
22460 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
22461diff -urNp linux-2.6.32.44/arch/x86/mm/pgtable_32.c linux-2.6.32.44/arch/x86/mm/pgtable_32.c
22462--- linux-2.6.32.44/arch/x86/mm/pgtable_32.c 2011-03-27 14:31:47.000000000 -0400
22463+++ linux-2.6.32.44/arch/x86/mm/pgtable_32.c 2011-04-17 15:56:46.000000000 -0400
22464@@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr,
22465 return;
22466 }
22467 pte = pte_offset_kernel(pmd, vaddr);
22468+
22469+ pax_open_kernel();
22470 if (pte_val(pteval))
22471 set_pte_at(&init_mm, vaddr, pte, pteval);
22472 else
22473 pte_clear(&init_mm, vaddr, pte);
22474+ pax_close_kernel();
22475
22476 /*
22477 * It's enough to flush this one mapping.
22478diff -urNp linux-2.6.32.44/arch/x86/mm/pgtable.c linux-2.6.32.44/arch/x86/mm/pgtable.c
22479--- linux-2.6.32.44/arch/x86/mm/pgtable.c 2011-03-27 14:31:47.000000000 -0400
22480+++ linux-2.6.32.44/arch/x86/mm/pgtable.c 2011-05-11 18:25:15.000000000 -0400
22481@@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *p
22482 list_del(&page->lru);
22483 }
22484
22485-#define UNSHARED_PTRS_PER_PGD \
22486- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22487+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22488+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22489
22490+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22491+{
22492+ while (count--)
22493+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22494+}
22495+#endif
22496+
22497+#ifdef CONFIG_PAX_PER_CPU_PGD
22498+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22499+{
22500+ while (count--)
22501+
22502+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22503+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22504+#else
22505+ *dst++ = *src++;
22506+#endif
22507+
22508+}
22509+#endif
22510+
22511+#ifdef CONFIG_X86_64
22512+#define pxd_t pud_t
22513+#define pyd_t pgd_t
22514+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22515+#define pxd_free(mm, pud) pud_free((mm), (pud))
22516+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22517+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22518+#define PYD_SIZE PGDIR_SIZE
22519+#else
22520+#define pxd_t pmd_t
22521+#define pyd_t pud_t
22522+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22523+#define pxd_free(mm, pud) pmd_free((mm), (pud))
22524+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22525+#define pyd_offset(mm ,address) pud_offset((mm), (address))
22526+#define PYD_SIZE PUD_SIZE
22527+#endif
22528+
22529+#ifdef CONFIG_PAX_PER_CPU_PGD
22530+static inline void pgd_ctor(pgd_t *pgd) {}
22531+static inline void pgd_dtor(pgd_t *pgd) {}
22532+#else
22533 static void pgd_ctor(pgd_t *pgd)
22534 {
22535 /* If the pgd points to a shared pagetable level (either the
22536@@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
22537 pgd_list_del(pgd);
22538 spin_unlock_irqrestore(&pgd_lock, flags);
22539 }
22540+#endif
22541
22542 /*
22543 * List of all pgd's needed for non-PAE so it can invalidate entries
22544@@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
22545 * -- wli
22546 */
22547
22548-#ifdef CONFIG_X86_PAE
22549+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22550 /*
22551 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22552 * updating the top-level pagetable entries to guarantee the
22553@@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
22554 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22555 * and initialize the kernel pmds here.
22556 */
22557-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22558+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22559
22560 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22561 {
22562@@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm,
22563 */
22564 flush_tlb_mm(mm);
22565 }
22566+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22567+#define PREALLOCATED_PXDS USER_PGD_PTRS
22568 #else /* !CONFIG_X86_PAE */
22569
22570 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22571-#define PREALLOCATED_PMDS 0
22572+#define PREALLOCATED_PXDS 0
22573
22574 #endif /* CONFIG_X86_PAE */
22575
22576-static void free_pmds(pmd_t *pmds[])
22577+static void free_pxds(pxd_t *pxds[])
22578 {
22579 int i;
22580
22581- for(i = 0; i < PREALLOCATED_PMDS; i++)
22582- if (pmds[i])
22583- free_page((unsigned long)pmds[i]);
22584+ for(i = 0; i < PREALLOCATED_PXDS; i++)
22585+ if (pxds[i])
22586+ free_page((unsigned long)pxds[i]);
22587 }
22588
22589-static int preallocate_pmds(pmd_t *pmds[])
22590+static int preallocate_pxds(pxd_t *pxds[])
22591 {
22592 int i;
22593 bool failed = false;
22594
22595- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22596- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22597- if (pmd == NULL)
22598+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22599+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22600+ if (pxd == NULL)
22601 failed = true;
22602- pmds[i] = pmd;
22603+ pxds[i] = pxd;
22604 }
22605
22606 if (failed) {
22607- free_pmds(pmds);
22608+ free_pxds(pxds);
22609 return -ENOMEM;
22610 }
22611
22612@@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[
22613 * preallocate which never got a corresponding vma will need to be
22614 * freed manually.
22615 */
22616-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22617+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22618 {
22619 int i;
22620
22621- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22622+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22623 pgd_t pgd = pgdp[i];
22624
22625 if (pgd_val(pgd) != 0) {
22626- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22627+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22628
22629- pgdp[i] = native_make_pgd(0);
22630+ set_pgd(pgdp + i, native_make_pgd(0));
22631
22632- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22633- pmd_free(mm, pmd);
22634+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22635+ pxd_free(mm, pxd);
22636 }
22637 }
22638 }
22639
22640-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
22641+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
22642 {
22643- pud_t *pud;
22644+ pyd_t *pyd;
22645 unsigned long addr;
22646 int i;
22647
22648- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
22649+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
22650 return;
22651
22652- pud = pud_offset(pgd, 0);
22653+#ifdef CONFIG_X86_64
22654+ pyd = pyd_offset(mm, 0L);
22655+#else
22656+ pyd = pyd_offset(pgd, 0L);
22657+#endif
22658
22659- for (addr = i = 0; i < PREALLOCATED_PMDS;
22660- i++, pud++, addr += PUD_SIZE) {
22661- pmd_t *pmd = pmds[i];
22662+ for (addr = i = 0; i < PREALLOCATED_PXDS;
22663+ i++, pyd++, addr += PYD_SIZE) {
22664+ pxd_t *pxd = pxds[i];
22665
22666 if (i >= KERNEL_PGD_BOUNDARY)
22667- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22668- sizeof(pmd_t) * PTRS_PER_PMD);
22669+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22670+ sizeof(pxd_t) * PTRS_PER_PMD);
22671
22672- pud_populate(mm, pud, pmd);
22673+ pyd_populate(mm, pyd, pxd);
22674 }
22675 }
22676
22677 pgd_t *pgd_alloc(struct mm_struct *mm)
22678 {
22679 pgd_t *pgd;
22680- pmd_t *pmds[PREALLOCATED_PMDS];
22681+ pxd_t *pxds[PREALLOCATED_PXDS];
22682+
22683 unsigned long flags;
22684
22685 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
22686@@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22687
22688 mm->pgd = pgd;
22689
22690- if (preallocate_pmds(pmds) != 0)
22691+ if (preallocate_pxds(pxds) != 0)
22692 goto out_free_pgd;
22693
22694 if (paravirt_pgd_alloc(mm) != 0)
22695- goto out_free_pmds;
22696+ goto out_free_pxds;
22697
22698 /*
22699 * Make sure that pre-populating the pmds is atomic with
22700@@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22701 spin_lock_irqsave(&pgd_lock, flags);
22702
22703 pgd_ctor(pgd);
22704- pgd_prepopulate_pmd(mm, pgd, pmds);
22705+ pgd_prepopulate_pxd(mm, pgd, pxds);
22706
22707 spin_unlock_irqrestore(&pgd_lock, flags);
22708
22709 return pgd;
22710
22711-out_free_pmds:
22712- free_pmds(pmds);
22713+out_free_pxds:
22714+ free_pxds(pxds);
22715 out_free_pgd:
22716 free_page((unsigned long)pgd);
22717 out:
22718@@ -287,7 +338,7 @@ out:
22719
22720 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
22721 {
22722- pgd_mop_up_pmds(mm, pgd);
22723+ pgd_mop_up_pxds(mm, pgd);
22724 pgd_dtor(pgd);
22725 paravirt_pgd_free(mm, pgd);
22726 free_page((unsigned long)pgd);
22727diff -urNp linux-2.6.32.44/arch/x86/mm/setup_nx.c linux-2.6.32.44/arch/x86/mm/setup_nx.c
22728--- linux-2.6.32.44/arch/x86/mm/setup_nx.c 2011-03-27 14:31:47.000000000 -0400
22729+++ linux-2.6.32.44/arch/x86/mm/setup_nx.c 2011-04-17 15:56:46.000000000 -0400
22730@@ -4,11 +4,10 @@
22731
22732 #include <asm/pgtable.h>
22733
22734+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22735 int nx_enabled;
22736
22737-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22738-static int disable_nx __cpuinitdata;
22739-
22740+#ifndef CONFIG_PAX_PAGEEXEC
22741 /*
22742 * noexec = on|off
22743 *
22744@@ -22,32 +21,26 @@ static int __init noexec_setup(char *str
22745 if (!str)
22746 return -EINVAL;
22747 if (!strncmp(str, "on", 2)) {
22748- __supported_pte_mask |= _PAGE_NX;
22749- disable_nx = 0;
22750+ nx_enabled = 1;
22751 } else if (!strncmp(str, "off", 3)) {
22752- disable_nx = 1;
22753- __supported_pte_mask &= ~_PAGE_NX;
22754+ nx_enabled = 0;
22755 }
22756 return 0;
22757 }
22758 early_param("noexec", noexec_setup);
22759 #endif
22760+#endif
22761
22762 #ifdef CONFIG_X86_PAE
22763 void __init set_nx(void)
22764 {
22765- unsigned int v[4], l, h;
22766+ if (!nx_enabled && cpu_has_nx) {
22767+ unsigned l, h;
22768
22769- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
22770- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
22771-
22772- if ((v[3] & (1 << 20)) && !disable_nx) {
22773- rdmsr(MSR_EFER, l, h);
22774- l |= EFER_NX;
22775- wrmsr(MSR_EFER, l, h);
22776- nx_enabled = 1;
22777- __supported_pte_mask |= _PAGE_NX;
22778- }
22779+ __supported_pte_mask &= ~_PAGE_NX;
22780+ rdmsr(MSR_EFER, l, h);
22781+ l &= ~EFER_NX;
22782+ wrmsr(MSR_EFER, l, h);
22783 }
22784 }
22785 #else
22786@@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
22787 unsigned long efer;
22788
22789 rdmsrl(MSR_EFER, efer);
22790- if (!(efer & EFER_NX) || disable_nx)
22791+ if (!(efer & EFER_NX) || !nx_enabled)
22792 __supported_pte_mask &= ~_PAGE_NX;
22793 }
22794 #endif
22795diff -urNp linux-2.6.32.44/arch/x86/mm/tlb.c linux-2.6.32.44/arch/x86/mm/tlb.c
22796--- linux-2.6.32.44/arch/x86/mm/tlb.c 2011-03-27 14:31:47.000000000 -0400
22797+++ linux-2.6.32.44/arch/x86/mm/tlb.c 2011-04-23 12:56:10.000000000 -0400
22798@@ -61,7 +61,11 @@ void leave_mm(int cpu)
22799 BUG();
22800 cpumask_clear_cpu(cpu,
22801 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
22802+
22803+#ifndef CONFIG_PAX_PER_CPU_PGD
22804 load_cr3(swapper_pg_dir);
22805+#endif
22806+
22807 }
22808 EXPORT_SYMBOL_GPL(leave_mm);
22809
22810diff -urNp linux-2.6.32.44/arch/x86/oprofile/backtrace.c linux-2.6.32.44/arch/x86/oprofile/backtrace.c
22811--- linux-2.6.32.44/arch/x86/oprofile/backtrace.c 2011-03-27 14:31:47.000000000 -0400
22812+++ linux-2.6.32.44/arch/x86/oprofile/backtrace.c 2011-04-17 15:56:46.000000000 -0400
22813@@ -57,7 +57,7 @@ static struct frame_head *dump_user_back
22814 struct frame_head bufhead[2];
22815
22816 /* Also check accessibility of one struct frame_head beyond */
22817- if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
22818+ if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
22819 return NULL;
22820 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
22821 return NULL;
22822@@ -77,7 +77,7 @@ x86_backtrace(struct pt_regs * const reg
22823 {
22824 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
22825
22826- if (!user_mode_vm(regs)) {
22827+ if (!user_mode(regs)) {
22828 unsigned long stack = kernel_stack_pointer(regs);
22829 if (depth)
22830 dump_trace(NULL, regs, (unsigned long *)stack, 0,
22831diff -urNp linux-2.6.32.44/arch/x86/oprofile/op_model_p4.c linux-2.6.32.44/arch/x86/oprofile/op_model_p4.c
22832--- linux-2.6.32.44/arch/x86/oprofile/op_model_p4.c 2011-03-27 14:31:47.000000000 -0400
22833+++ linux-2.6.32.44/arch/x86/oprofile/op_model_p4.c 2011-04-17 15:56:46.000000000 -0400
22834@@ -50,7 +50,7 @@ static inline void setup_num_counters(vo
22835 #endif
22836 }
22837
22838-static int inline addr_increment(void)
22839+static inline int addr_increment(void)
22840 {
22841 #ifdef CONFIG_SMP
22842 return smp_num_siblings == 2 ? 2 : 1;
22843diff -urNp linux-2.6.32.44/arch/x86/pci/common.c linux-2.6.32.44/arch/x86/pci/common.c
22844--- linux-2.6.32.44/arch/x86/pci/common.c 2011-03-27 14:31:47.000000000 -0400
22845+++ linux-2.6.32.44/arch/x86/pci/common.c 2011-04-23 12:56:10.000000000 -0400
22846@@ -31,8 +31,8 @@ int noioapicreroute = 1;
22847 int pcibios_last_bus = -1;
22848 unsigned long pirq_table_addr;
22849 struct pci_bus *pci_root_bus;
22850-struct pci_raw_ops *raw_pci_ops;
22851-struct pci_raw_ops *raw_pci_ext_ops;
22852+const struct pci_raw_ops *raw_pci_ops;
22853+const struct pci_raw_ops *raw_pci_ext_ops;
22854
22855 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
22856 int reg, int len, u32 *val)
22857diff -urNp linux-2.6.32.44/arch/x86/pci/direct.c linux-2.6.32.44/arch/x86/pci/direct.c
22858--- linux-2.6.32.44/arch/x86/pci/direct.c 2011-03-27 14:31:47.000000000 -0400
22859+++ linux-2.6.32.44/arch/x86/pci/direct.c 2011-04-17 15:56:46.000000000 -0400
22860@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
22861
22862 #undef PCI_CONF1_ADDRESS
22863
22864-struct pci_raw_ops pci_direct_conf1 = {
22865+const struct pci_raw_ops pci_direct_conf1 = {
22866 .read = pci_conf1_read,
22867 .write = pci_conf1_write,
22868 };
22869@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
22870
22871 #undef PCI_CONF2_ADDRESS
22872
22873-struct pci_raw_ops pci_direct_conf2 = {
22874+const struct pci_raw_ops pci_direct_conf2 = {
22875 .read = pci_conf2_read,
22876 .write = pci_conf2_write,
22877 };
22878@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
22879 * This should be close to trivial, but it isn't, because there are buggy
22880 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
22881 */
22882-static int __init pci_sanity_check(struct pci_raw_ops *o)
22883+static int __init pci_sanity_check(const struct pci_raw_ops *o)
22884 {
22885 u32 x = 0;
22886 int year, devfn;
22887diff -urNp linux-2.6.32.44/arch/x86/pci/mmconfig_32.c linux-2.6.32.44/arch/x86/pci/mmconfig_32.c
22888--- linux-2.6.32.44/arch/x86/pci/mmconfig_32.c 2011-03-27 14:31:47.000000000 -0400
22889+++ linux-2.6.32.44/arch/x86/pci/mmconfig_32.c 2011-04-17 15:56:46.000000000 -0400
22890@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int
22891 return 0;
22892 }
22893
22894-static struct pci_raw_ops pci_mmcfg = {
22895+static const struct pci_raw_ops pci_mmcfg = {
22896 .read = pci_mmcfg_read,
22897 .write = pci_mmcfg_write,
22898 };
22899diff -urNp linux-2.6.32.44/arch/x86/pci/mmconfig_64.c linux-2.6.32.44/arch/x86/pci/mmconfig_64.c
22900--- linux-2.6.32.44/arch/x86/pci/mmconfig_64.c 2011-03-27 14:31:47.000000000 -0400
22901+++ linux-2.6.32.44/arch/x86/pci/mmconfig_64.c 2011-04-17 15:56:46.000000000 -0400
22902@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int
22903 return 0;
22904 }
22905
22906-static struct pci_raw_ops pci_mmcfg = {
22907+static const struct pci_raw_ops pci_mmcfg = {
22908 .read = pci_mmcfg_read,
22909 .write = pci_mmcfg_write,
22910 };
22911diff -urNp linux-2.6.32.44/arch/x86/pci/numaq_32.c linux-2.6.32.44/arch/x86/pci/numaq_32.c
22912--- linux-2.6.32.44/arch/x86/pci/numaq_32.c 2011-03-27 14:31:47.000000000 -0400
22913+++ linux-2.6.32.44/arch/x86/pci/numaq_32.c 2011-04-17 15:56:46.000000000 -0400
22914@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned i
22915
22916 #undef PCI_CONF1_MQ_ADDRESS
22917
22918-static struct pci_raw_ops pci_direct_conf1_mq = {
22919+static const struct pci_raw_ops pci_direct_conf1_mq = {
22920 .read = pci_conf1_mq_read,
22921 .write = pci_conf1_mq_write
22922 };
22923diff -urNp linux-2.6.32.44/arch/x86/pci/olpc.c linux-2.6.32.44/arch/x86/pci/olpc.c
22924--- linux-2.6.32.44/arch/x86/pci/olpc.c 2011-03-27 14:31:47.000000000 -0400
22925+++ linux-2.6.32.44/arch/x86/pci/olpc.c 2011-04-17 15:56:46.000000000 -0400
22926@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
22927 return 0;
22928 }
22929
22930-static struct pci_raw_ops pci_olpc_conf = {
22931+static const struct pci_raw_ops pci_olpc_conf = {
22932 .read = pci_olpc_read,
22933 .write = pci_olpc_write,
22934 };
22935diff -urNp linux-2.6.32.44/arch/x86/pci/pcbios.c linux-2.6.32.44/arch/x86/pci/pcbios.c
22936--- linux-2.6.32.44/arch/x86/pci/pcbios.c 2011-03-27 14:31:47.000000000 -0400
22937+++ linux-2.6.32.44/arch/x86/pci/pcbios.c 2011-04-17 15:56:46.000000000 -0400
22938@@ -56,50 +56,93 @@ union bios32 {
22939 static struct {
22940 unsigned long address;
22941 unsigned short segment;
22942-} bios32_indirect = { 0, __KERNEL_CS };
22943+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
22944
22945 /*
22946 * Returns the entry point for the given service, NULL on error
22947 */
22948
22949-static unsigned long bios32_service(unsigned long service)
22950+static unsigned long __devinit bios32_service(unsigned long service)
22951 {
22952 unsigned char return_code; /* %al */
22953 unsigned long address; /* %ebx */
22954 unsigned long length; /* %ecx */
22955 unsigned long entry; /* %edx */
22956 unsigned long flags;
22957+ struct desc_struct d, *gdt;
22958
22959 local_irq_save(flags);
22960- __asm__("lcall *(%%edi); cld"
22961+
22962+ gdt = get_cpu_gdt_table(smp_processor_id());
22963+
22964+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
22965+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
22966+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
22967+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
22968+
22969+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
22970 : "=a" (return_code),
22971 "=b" (address),
22972 "=c" (length),
22973 "=d" (entry)
22974 : "0" (service),
22975 "1" (0),
22976- "D" (&bios32_indirect));
22977+ "D" (&bios32_indirect),
22978+ "r"(__PCIBIOS_DS)
22979+ : "memory");
22980+
22981+ pax_open_kernel();
22982+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
22983+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
22984+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
22985+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
22986+ pax_close_kernel();
22987+
22988 local_irq_restore(flags);
22989
22990 switch (return_code) {
22991- case 0:
22992- return address + entry;
22993- case 0x80: /* Not present */
22994- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
22995- return 0;
22996- default: /* Shouldn't happen */
22997- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
22998- service, return_code);
22999+ case 0: {
23000+ int cpu;
23001+ unsigned char flags;
23002+
23003+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23004+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23005+ printk(KERN_WARNING "bios32_service: not valid\n");
23006 return 0;
23007+ }
23008+ address = address + PAGE_OFFSET;
23009+ length += 16UL; /* some BIOSs underreport this... */
23010+ flags = 4;
23011+ if (length >= 64*1024*1024) {
23012+ length >>= PAGE_SHIFT;
23013+ flags |= 8;
23014+ }
23015+
23016+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
23017+ gdt = get_cpu_gdt_table(cpu);
23018+ pack_descriptor(&d, address, length, 0x9b, flags);
23019+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23020+ pack_descriptor(&d, address, length, 0x93, flags);
23021+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23022+ }
23023+ return entry;
23024+ }
23025+ case 0x80: /* Not present */
23026+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23027+ return 0;
23028+ default: /* Shouldn't happen */
23029+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23030+ service, return_code);
23031+ return 0;
23032 }
23033 }
23034
23035 static struct {
23036 unsigned long address;
23037 unsigned short segment;
23038-} pci_indirect = { 0, __KERNEL_CS };
23039+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23040
23041-static int pci_bios_present;
23042+static int pci_bios_present __read_only;
23043
23044 static int __devinit check_pcibios(void)
23045 {
23046@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
23047 unsigned long flags, pcibios_entry;
23048
23049 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23050- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23051+ pci_indirect.address = pcibios_entry;
23052
23053 local_irq_save(flags);
23054- __asm__(
23055- "lcall *(%%edi); cld\n\t"
23056+ __asm__("movw %w6, %%ds\n\t"
23057+ "lcall *%%ss:(%%edi); cld\n\t"
23058+ "push %%ss\n\t"
23059+ "pop %%ds\n\t"
23060 "jc 1f\n\t"
23061 "xor %%ah, %%ah\n"
23062 "1:"
23063@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
23064 "=b" (ebx),
23065 "=c" (ecx)
23066 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23067- "D" (&pci_indirect)
23068+ "D" (&pci_indirect),
23069+ "r" (__PCIBIOS_DS)
23070 : "memory");
23071 local_irq_restore(flags);
23072
23073@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int se
23074
23075 switch (len) {
23076 case 1:
23077- __asm__("lcall *(%%esi); cld\n\t"
23078+ __asm__("movw %w6, %%ds\n\t"
23079+ "lcall *%%ss:(%%esi); cld\n\t"
23080+ "push %%ss\n\t"
23081+ "pop %%ds\n\t"
23082 "jc 1f\n\t"
23083 "xor %%ah, %%ah\n"
23084 "1:"
23085@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int se
23086 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23087 "b" (bx),
23088 "D" ((long)reg),
23089- "S" (&pci_indirect));
23090+ "S" (&pci_indirect),
23091+ "r" (__PCIBIOS_DS));
23092 /*
23093 * Zero-extend the result beyond 8 bits, do not trust the
23094 * BIOS having done it:
23095@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int se
23096 *value &= 0xff;
23097 break;
23098 case 2:
23099- __asm__("lcall *(%%esi); cld\n\t"
23100+ __asm__("movw %w6, %%ds\n\t"
23101+ "lcall *%%ss:(%%esi); cld\n\t"
23102+ "push %%ss\n\t"
23103+ "pop %%ds\n\t"
23104 "jc 1f\n\t"
23105 "xor %%ah, %%ah\n"
23106 "1:"
23107@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int se
23108 : "1" (PCIBIOS_READ_CONFIG_WORD),
23109 "b" (bx),
23110 "D" ((long)reg),
23111- "S" (&pci_indirect));
23112+ "S" (&pci_indirect),
23113+ "r" (__PCIBIOS_DS));
23114 /*
23115 * Zero-extend the result beyond 16 bits, do not trust the
23116 * BIOS having done it:
23117@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int se
23118 *value &= 0xffff;
23119 break;
23120 case 4:
23121- __asm__("lcall *(%%esi); cld\n\t"
23122+ __asm__("movw %w6, %%ds\n\t"
23123+ "lcall *%%ss:(%%esi); cld\n\t"
23124+ "push %%ss\n\t"
23125+ "pop %%ds\n\t"
23126 "jc 1f\n\t"
23127 "xor %%ah, %%ah\n"
23128 "1:"
23129@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int se
23130 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23131 "b" (bx),
23132 "D" ((long)reg),
23133- "S" (&pci_indirect));
23134+ "S" (&pci_indirect),
23135+ "r" (__PCIBIOS_DS));
23136 break;
23137 }
23138
23139@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int s
23140
23141 switch (len) {
23142 case 1:
23143- __asm__("lcall *(%%esi); cld\n\t"
23144+ __asm__("movw %w6, %%ds\n\t"
23145+ "lcall *%%ss:(%%esi); cld\n\t"
23146+ "push %%ss\n\t"
23147+ "pop %%ds\n\t"
23148 "jc 1f\n\t"
23149 "xor %%ah, %%ah\n"
23150 "1:"
23151@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int s
23152 "c" (value),
23153 "b" (bx),
23154 "D" ((long)reg),
23155- "S" (&pci_indirect));
23156+ "S" (&pci_indirect),
23157+ "r" (__PCIBIOS_DS));
23158 break;
23159 case 2:
23160- __asm__("lcall *(%%esi); cld\n\t"
23161+ __asm__("movw %w6, %%ds\n\t"
23162+ "lcall *%%ss:(%%esi); cld\n\t"
23163+ "push %%ss\n\t"
23164+ "pop %%ds\n\t"
23165 "jc 1f\n\t"
23166 "xor %%ah, %%ah\n"
23167 "1:"
23168@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int s
23169 "c" (value),
23170 "b" (bx),
23171 "D" ((long)reg),
23172- "S" (&pci_indirect));
23173+ "S" (&pci_indirect),
23174+ "r" (__PCIBIOS_DS));
23175 break;
23176 case 4:
23177- __asm__("lcall *(%%esi); cld\n\t"
23178+ __asm__("movw %w6, %%ds\n\t"
23179+ "lcall *%%ss:(%%esi); cld\n\t"
23180+ "push %%ss\n\t"
23181+ "pop %%ds\n\t"
23182 "jc 1f\n\t"
23183 "xor %%ah, %%ah\n"
23184 "1:"
23185@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int s
23186 "c" (value),
23187 "b" (bx),
23188 "D" ((long)reg),
23189- "S" (&pci_indirect));
23190+ "S" (&pci_indirect),
23191+ "r" (__PCIBIOS_DS));
23192 break;
23193 }
23194
23195@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int s
23196 * Function table for BIOS32 access
23197 */
23198
23199-static struct pci_raw_ops pci_bios_access = {
23200+static const struct pci_raw_ops pci_bios_access = {
23201 .read = pci_bios_read,
23202 .write = pci_bios_write
23203 };
23204@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_acces
23205 * Try to find PCI BIOS.
23206 */
23207
23208-static struct pci_raw_ops * __devinit pci_find_bios(void)
23209+static const struct pci_raw_ops * __devinit pci_find_bios(void)
23210 {
23211 union bios32 *check;
23212 unsigned char sum;
23213@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_i
23214
23215 DBG("PCI: Fetching IRQ routing table... ");
23216 __asm__("push %%es\n\t"
23217+ "movw %w8, %%ds\n\t"
23218 "push %%ds\n\t"
23219 "pop %%es\n\t"
23220- "lcall *(%%esi); cld\n\t"
23221+ "lcall *%%ss:(%%esi); cld\n\t"
23222 "pop %%es\n\t"
23223+ "push %%ss\n\t"
23224+ "pop %%ds\n"
23225 "jc 1f\n\t"
23226 "xor %%ah, %%ah\n"
23227 "1:"
23228@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_i
23229 "1" (0),
23230 "D" ((long) &opt),
23231 "S" (&pci_indirect),
23232- "m" (opt)
23233+ "m" (opt),
23234+ "r" (__PCIBIOS_DS)
23235 : "memory");
23236 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23237 if (ret & 0xff00)
23238@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_d
23239 {
23240 int ret;
23241
23242- __asm__("lcall *(%%esi); cld\n\t"
23243+ __asm__("movw %w5, %%ds\n\t"
23244+ "lcall *%%ss:(%%esi); cld\n\t"
23245+ "push %%ss\n\t"
23246+ "pop %%ds\n"
23247 "jc 1f\n\t"
23248 "xor %%ah, %%ah\n"
23249 "1:"
23250@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_d
23251 : "0" (PCIBIOS_SET_PCI_HW_INT),
23252 "b" ((dev->bus->number << 8) | dev->devfn),
23253 "c" ((irq << 8) | (pin + 10)),
23254- "S" (&pci_indirect));
23255+ "S" (&pci_indirect),
23256+ "r" (__PCIBIOS_DS));
23257 return !(ret & 0xff00);
23258 }
23259 EXPORT_SYMBOL(pcibios_set_irq_routing);
23260diff -urNp linux-2.6.32.44/arch/x86/power/cpu.c linux-2.6.32.44/arch/x86/power/cpu.c
23261--- linux-2.6.32.44/arch/x86/power/cpu.c 2011-03-27 14:31:47.000000000 -0400
23262+++ linux-2.6.32.44/arch/x86/power/cpu.c 2011-04-17 15:56:46.000000000 -0400
23263@@ -129,7 +129,7 @@ static void do_fpu_end(void)
23264 static void fix_processor_context(void)
23265 {
23266 int cpu = smp_processor_id();
23267- struct tss_struct *t = &per_cpu(init_tss, cpu);
23268+ struct tss_struct *t = init_tss + cpu;
23269
23270 set_tss_desc(cpu, t); /*
23271 * This just modifies memory; should not be
23272@@ -139,7 +139,9 @@ static void fix_processor_context(void)
23273 */
23274
23275 #ifdef CONFIG_X86_64
23276+ pax_open_kernel();
23277 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23278+ pax_close_kernel();
23279
23280 syscall_init(); /* This sets MSR_*STAR and related */
23281 #endif
23282diff -urNp linux-2.6.32.44/arch/x86/vdso/Makefile linux-2.6.32.44/arch/x86/vdso/Makefile
23283--- linux-2.6.32.44/arch/x86/vdso/Makefile 2011-03-27 14:31:47.000000000 -0400
23284+++ linux-2.6.32.44/arch/x86/vdso/Makefile 2011-04-17 15:56:46.000000000 -0400
23285@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
23286 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
23287 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
23288
23289-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23290+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23291 GCOV_PROFILE := n
23292
23293 #
23294diff -urNp linux-2.6.32.44/arch/x86/vdso/vclock_gettime.c linux-2.6.32.44/arch/x86/vdso/vclock_gettime.c
23295--- linux-2.6.32.44/arch/x86/vdso/vclock_gettime.c 2011-03-27 14:31:47.000000000 -0400
23296+++ linux-2.6.32.44/arch/x86/vdso/vclock_gettime.c 2011-04-17 15:56:46.000000000 -0400
23297@@ -22,24 +22,48 @@
23298 #include <asm/hpet.h>
23299 #include <asm/unistd.h>
23300 #include <asm/io.h>
23301+#include <asm/fixmap.h>
23302 #include "vextern.h"
23303
23304 #define gtod vdso_vsyscall_gtod_data
23305
23306+notrace noinline long __vdso_fallback_time(long *t)
23307+{
23308+ long secs;
23309+ asm volatile("syscall"
23310+ : "=a" (secs)
23311+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23312+ return secs;
23313+}
23314+
23315 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23316 {
23317 long ret;
23318 asm("syscall" : "=a" (ret) :
23319- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23320+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23321 return ret;
23322 }
23323
23324+notrace static inline cycle_t __vdso_vread_hpet(void)
23325+{
23326+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23327+}
23328+
23329+notrace static inline cycle_t __vdso_vread_tsc(void)
23330+{
23331+ cycle_t ret = (cycle_t)vget_cycles();
23332+
23333+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23334+}
23335+
23336 notrace static inline long vgetns(void)
23337 {
23338 long v;
23339- cycles_t (*vread)(void);
23340- vread = gtod->clock.vread;
23341- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23342+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23343+ v = __vdso_vread_tsc();
23344+ else
23345+ v = __vdso_vread_hpet();
23346+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23347 return (v * gtod->clock.mult) >> gtod->clock.shift;
23348 }
23349
23350@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23351
23352 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23353 {
23354- if (likely(gtod->sysctl_enabled))
23355+ if (likely(gtod->sysctl_enabled &&
23356+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23357+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23358 switch (clock) {
23359 case CLOCK_REALTIME:
23360 if (likely(gtod->clock.vread))
23361@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23362 int clock_gettime(clockid_t, struct timespec *)
23363 __attribute__((weak, alias("__vdso_clock_gettime")));
23364
23365-notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23366+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23367 {
23368 long ret;
23369- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23370+ asm("syscall" : "=a" (ret) :
23371+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23372+ return ret;
23373+}
23374+
23375+notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23376+{
23377+ if (likely(gtod->sysctl_enabled &&
23378+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23379+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23380+ {
23381 if (likely(tv != NULL)) {
23382 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23383 offsetof(struct timespec, tv_nsec) ||
23384@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23385 }
23386 return 0;
23387 }
23388- asm("syscall" : "=a" (ret) :
23389- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23390- return ret;
23391+ return __vdso_fallback_gettimeofday(tv, tz);
23392 }
23393 int gettimeofday(struct timeval *, struct timezone *)
23394 __attribute__((weak, alias("__vdso_gettimeofday")));
23395diff -urNp linux-2.6.32.44/arch/x86/vdso/vdso32-setup.c linux-2.6.32.44/arch/x86/vdso/vdso32-setup.c
23396--- linux-2.6.32.44/arch/x86/vdso/vdso32-setup.c 2011-03-27 14:31:47.000000000 -0400
23397+++ linux-2.6.32.44/arch/x86/vdso/vdso32-setup.c 2011-04-23 12:56:10.000000000 -0400
23398@@ -25,6 +25,7 @@
23399 #include <asm/tlbflush.h>
23400 #include <asm/vdso.h>
23401 #include <asm/proto.h>
23402+#include <asm/mman.h>
23403
23404 enum {
23405 VDSO_DISABLED = 0,
23406@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23407 void enable_sep_cpu(void)
23408 {
23409 int cpu = get_cpu();
23410- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23411+ struct tss_struct *tss = init_tss + cpu;
23412
23413 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23414 put_cpu();
23415@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23416 gate_vma.vm_start = FIXADDR_USER_START;
23417 gate_vma.vm_end = FIXADDR_USER_END;
23418 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23419- gate_vma.vm_page_prot = __P101;
23420+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23421 /*
23422 * Make sure the vDSO gets into every core dump.
23423 * Dumping its contents makes post-mortem fully interpretable later
23424@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23425 if (compat)
23426 addr = VDSO_HIGH_BASE;
23427 else {
23428- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23429+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23430 if (IS_ERR_VALUE(addr)) {
23431 ret = addr;
23432 goto up_fail;
23433 }
23434 }
23435
23436- current->mm->context.vdso = (void *)addr;
23437+ current->mm->context.vdso = addr;
23438
23439 if (compat_uses_vma || !compat) {
23440 /*
23441@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
23442 }
23443
23444 current_thread_info()->sysenter_return =
23445- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23446+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23447
23448 up_fail:
23449 if (ret)
23450- current->mm->context.vdso = NULL;
23451+ current->mm->context.vdso = 0;
23452
23453 up_write(&mm->mmap_sem);
23454
23455@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
23456
23457 const char *arch_vma_name(struct vm_area_struct *vma)
23458 {
23459- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23460+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23461 return "[vdso]";
23462+
23463+#ifdef CONFIG_PAX_SEGMEXEC
23464+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
23465+ return "[vdso]";
23466+#endif
23467+
23468 return NULL;
23469 }
23470
23471@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
23472 struct mm_struct *mm = tsk->mm;
23473
23474 /* Check to see if this task was created in compat vdso mode */
23475- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
23476+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
23477 return &gate_vma;
23478 return NULL;
23479 }
23480diff -urNp linux-2.6.32.44/arch/x86/vdso/vdso.lds.S linux-2.6.32.44/arch/x86/vdso/vdso.lds.S
23481--- linux-2.6.32.44/arch/x86/vdso/vdso.lds.S 2011-03-27 14:31:47.000000000 -0400
23482+++ linux-2.6.32.44/arch/x86/vdso/vdso.lds.S 2011-06-06 17:35:35.000000000 -0400
23483@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
23484 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
23485 #include "vextern.h"
23486 #undef VEXTERN
23487+
23488+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
23489+VEXTERN(fallback_gettimeofday)
23490+VEXTERN(fallback_time)
23491+VEXTERN(getcpu)
23492+#undef VEXTERN
23493diff -urNp linux-2.6.32.44/arch/x86/vdso/vextern.h linux-2.6.32.44/arch/x86/vdso/vextern.h
23494--- linux-2.6.32.44/arch/x86/vdso/vextern.h 2011-03-27 14:31:47.000000000 -0400
23495+++ linux-2.6.32.44/arch/x86/vdso/vextern.h 2011-04-17 15:56:46.000000000 -0400
23496@@ -11,6 +11,5 @@
23497 put into vextern.h and be referenced as a pointer with vdso prefix.
23498 The main kernel later fills in the values. */
23499
23500-VEXTERN(jiffies)
23501 VEXTERN(vgetcpu_mode)
23502 VEXTERN(vsyscall_gtod_data)
23503diff -urNp linux-2.6.32.44/arch/x86/vdso/vma.c linux-2.6.32.44/arch/x86/vdso/vma.c
23504--- linux-2.6.32.44/arch/x86/vdso/vma.c 2011-03-27 14:31:47.000000000 -0400
23505+++ linux-2.6.32.44/arch/x86/vdso/vma.c 2011-04-17 15:56:46.000000000 -0400
23506@@ -57,7 +57,7 @@ static int __init init_vdso_vars(void)
23507 if (!vbase)
23508 goto oom;
23509
23510- if (memcmp(vbase, "\177ELF", 4)) {
23511+ if (memcmp(vbase, ELFMAG, SELFMAG)) {
23512 printk("VDSO: I'm broken; not ELF\n");
23513 vdso_enabled = 0;
23514 }
23515@@ -66,6 +66,7 @@ static int __init init_vdso_vars(void)
23516 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
23517 #include "vextern.h"
23518 #undef VEXTERN
23519+ vunmap(vbase);
23520 return 0;
23521
23522 oom:
23523@@ -116,7 +117,7 @@ int arch_setup_additional_pages(struct l
23524 goto up_fail;
23525 }
23526
23527- current->mm->context.vdso = (void *)addr;
23528+ current->mm->context.vdso = addr;
23529
23530 ret = install_special_mapping(mm, addr, vdso_size,
23531 VM_READ|VM_EXEC|
23532@@ -124,7 +125,7 @@ int arch_setup_additional_pages(struct l
23533 VM_ALWAYSDUMP,
23534 vdso_pages);
23535 if (ret) {
23536- current->mm->context.vdso = NULL;
23537+ current->mm->context.vdso = 0;
23538 goto up_fail;
23539 }
23540
23541@@ -132,10 +133,3 @@ up_fail:
23542 up_write(&mm->mmap_sem);
23543 return ret;
23544 }
23545-
23546-static __init int vdso_setup(char *s)
23547-{
23548- vdso_enabled = simple_strtoul(s, NULL, 0);
23549- return 0;
23550-}
23551-__setup("vdso=", vdso_setup);
23552diff -urNp linux-2.6.32.44/arch/x86/xen/enlighten.c linux-2.6.32.44/arch/x86/xen/enlighten.c
23553--- linux-2.6.32.44/arch/x86/xen/enlighten.c 2011-03-27 14:31:47.000000000 -0400
23554+++ linux-2.6.32.44/arch/x86/xen/enlighten.c 2011-05-22 23:02:03.000000000 -0400
23555@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
23556
23557 struct shared_info xen_dummy_shared_info;
23558
23559-void *xen_initial_gdt;
23560-
23561 /*
23562 * Point at some empty memory to start with. We map the real shared_info
23563 * page as soon as fixmap is up and running.
23564@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_des
23565
23566 preempt_disable();
23567
23568- start = __get_cpu_var(idt_desc).address;
23569+ start = (unsigned long)__get_cpu_var(idt_desc).address;
23570 end = start + __get_cpu_var(idt_desc).size + 1;
23571
23572 xen_mc_flush();
23573@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic
23574 #endif
23575 };
23576
23577-static void xen_reboot(int reason)
23578+static __noreturn void xen_reboot(int reason)
23579 {
23580 struct sched_shutdown r = { .reason = reason };
23581
23582@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
23583 BUG();
23584 }
23585
23586-static void xen_restart(char *msg)
23587+static __noreturn void xen_restart(char *msg)
23588 {
23589 xen_reboot(SHUTDOWN_reboot);
23590 }
23591
23592-static void xen_emergency_restart(void)
23593+static __noreturn void xen_emergency_restart(void)
23594 {
23595 xen_reboot(SHUTDOWN_reboot);
23596 }
23597
23598-static void xen_machine_halt(void)
23599+static __noreturn void xen_machine_halt(void)
23600 {
23601 xen_reboot(SHUTDOWN_poweroff);
23602 }
23603@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(
23604 */
23605 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
23606
23607-#ifdef CONFIG_X86_64
23608 /* Work out if we support NX */
23609- check_efer();
23610+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23611+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
23612+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
23613+ unsigned l, h;
23614+
23615+#ifdef CONFIG_X86_PAE
23616+ nx_enabled = 1;
23617+#endif
23618+ __supported_pte_mask |= _PAGE_NX;
23619+ rdmsr(MSR_EFER, l, h);
23620+ l |= EFER_NX;
23621+ wrmsr(MSR_EFER, l, h);
23622+ }
23623 #endif
23624
23625 xen_setup_features();
23626@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(
23627
23628 machine_ops = xen_machine_ops;
23629
23630- /*
23631- * The only reliable way to retain the initial address of the
23632- * percpu gdt_page is to remember it here, so we can go and
23633- * mark it RW later, when the initial percpu area is freed.
23634- */
23635- xen_initial_gdt = &per_cpu(gdt_page, 0);
23636-
23637 xen_smp_init();
23638
23639 pgd = (pgd_t *)xen_start_info->pt_base;
23640diff -urNp linux-2.6.32.44/arch/x86/xen/mmu.c linux-2.6.32.44/arch/x86/xen/mmu.c
23641--- linux-2.6.32.44/arch/x86/xen/mmu.c 2011-07-13 17:23:04.000000000 -0400
23642+++ linux-2.6.32.44/arch/x86/xen/mmu.c 2011-07-13 17:23:18.000000000 -0400
23643@@ -1719,6 +1719,8 @@ __init pgd_t *xen_setup_kernel_pagetable
23644 convert_pfn_mfn(init_level4_pgt);
23645 convert_pfn_mfn(level3_ident_pgt);
23646 convert_pfn_mfn(level3_kernel_pgt);
23647+ convert_pfn_mfn(level3_vmalloc_pgt);
23648+ convert_pfn_mfn(level3_vmemmap_pgt);
23649
23650 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
23651 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
23652@@ -1737,7 +1739,10 @@ __init pgd_t *xen_setup_kernel_pagetable
23653 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
23654 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
23655 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
23656+ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
23657+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
23658 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
23659+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
23660 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
23661 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
23662
23663diff -urNp linux-2.6.32.44/arch/x86/xen/smp.c linux-2.6.32.44/arch/x86/xen/smp.c
23664--- linux-2.6.32.44/arch/x86/xen/smp.c 2011-03-27 14:31:47.000000000 -0400
23665+++ linux-2.6.32.44/arch/x86/xen/smp.c 2011-05-11 18:25:15.000000000 -0400
23666@@ -167,11 +167,6 @@ static void __init xen_smp_prepare_boot_
23667 {
23668 BUG_ON(smp_processor_id() != 0);
23669 native_smp_prepare_boot_cpu();
23670-
23671- /* We've switched to the "real" per-cpu gdt, so make sure the
23672- old memory can be recycled */
23673- make_lowmem_page_readwrite(xen_initial_gdt);
23674-
23675 xen_setup_vcpu_info_placement();
23676 }
23677
23678@@ -231,12 +226,12 @@ cpu_initialize_context(unsigned int cpu,
23679 gdt = get_cpu_gdt_table(cpu);
23680
23681 ctxt->flags = VGCF_IN_KERNEL;
23682- ctxt->user_regs.ds = __USER_DS;
23683- ctxt->user_regs.es = __USER_DS;
23684+ ctxt->user_regs.ds = __KERNEL_DS;
23685+ ctxt->user_regs.es = __KERNEL_DS;
23686 ctxt->user_regs.ss = __KERNEL_DS;
23687 #ifdef CONFIG_X86_32
23688 ctxt->user_regs.fs = __KERNEL_PERCPU;
23689- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
23690+ savesegment(gs, ctxt->user_regs.gs);
23691 #else
23692 ctxt->gs_base_kernel = per_cpu_offset(cpu);
23693 #endif
23694@@ -287,13 +282,12 @@ static int __cpuinit xen_cpu_up(unsigned
23695 int rc;
23696
23697 per_cpu(current_task, cpu) = idle;
23698+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23699 #ifdef CONFIG_X86_32
23700 irq_ctx_init(cpu);
23701 #else
23702 clear_tsk_thread_flag(idle, TIF_FORK);
23703- per_cpu(kernel_stack, cpu) =
23704- (unsigned long)task_stack_page(idle) -
23705- KERNEL_STACK_OFFSET + THREAD_SIZE;
23706+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23707 #endif
23708 xen_setup_runstate_info(cpu);
23709 xen_setup_timer(cpu);
23710diff -urNp linux-2.6.32.44/arch/x86/xen/xen-asm_32.S linux-2.6.32.44/arch/x86/xen/xen-asm_32.S
23711--- linux-2.6.32.44/arch/x86/xen/xen-asm_32.S 2011-03-27 14:31:47.000000000 -0400
23712+++ linux-2.6.32.44/arch/x86/xen/xen-asm_32.S 2011-04-22 19:13:13.000000000 -0400
23713@@ -83,14 +83,14 @@ ENTRY(xen_iret)
23714 ESP_OFFSET=4 # bytes pushed onto stack
23715
23716 /*
23717- * Store vcpu_info pointer for easy access. Do it this way to
23718- * avoid having to reload %fs
23719+ * Store vcpu_info pointer for easy access.
23720 */
23721 #ifdef CONFIG_SMP
23722- GET_THREAD_INFO(%eax)
23723- movl TI_cpu(%eax), %eax
23724- movl __per_cpu_offset(,%eax,4), %eax
23725- mov per_cpu__xen_vcpu(%eax), %eax
23726+ push %fs
23727+ mov $(__KERNEL_PERCPU), %eax
23728+ mov %eax, %fs
23729+ mov PER_CPU_VAR(xen_vcpu), %eax
23730+ pop %fs
23731 #else
23732 movl per_cpu__xen_vcpu, %eax
23733 #endif
23734diff -urNp linux-2.6.32.44/arch/x86/xen/xen-head.S linux-2.6.32.44/arch/x86/xen/xen-head.S
23735--- linux-2.6.32.44/arch/x86/xen/xen-head.S 2011-03-27 14:31:47.000000000 -0400
23736+++ linux-2.6.32.44/arch/x86/xen/xen-head.S 2011-04-17 15:56:46.000000000 -0400
23737@@ -19,6 +19,17 @@ ENTRY(startup_xen)
23738 #ifdef CONFIG_X86_32
23739 mov %esi,xen_start_info
23740 mov $init_thread_union+THREAD_SIZE,%esp
23741+#ifdef CONFIG_SMP
23742+ movl $cpu_gdt_table,%edi
23743+ movl $__per_cpu_load,%eax
23744+ movw %ax,__KERNEL_PERCPU + 2(%edi)
23745+ rorl $16,%eax
23746+ movb %al,__KERNEL_PERCPU + 4(%edi)
23747+ movb %ah,__KERNEL_PERCPU + 7(%edi)
23748+ movl $__per_cpu_end - 1,%eax
23749+ subl $__per_cpu_start,%eax
23750+ movw %ax,__KERNEL_PERCPU + 0(%edi)
23751+#endif
23752 #else
23753 mov %rsi,xen_start_info
23754 mov $init_thread_union+THREAD_SIZE,%rsp
23755diff -urNp linux-2.6.32.44/arch/x86/xen/xen-ops.h linux-2.6.32.44/arch/x86/xen/xen-ops.h
23756--- linux-2.6.32.44/arch/x86/xen/xen-ops.h 2011-03-27 14:31:47.000000000 -0400
23757+++ linux-2.6.32.44/arch/x86/xen/xen-ops.h 2011-04-17 15:56:46.000000000 -0400
23758@@ -10,8 +10,6 @@
23759 extern const char xen_hypervisor_callback[];
23760 extern const char xen_failsafe_callback[];
23761
23762-extern void *xen_initial_gdt;
23763-
23764 struct trap_info;
23765 void xen_copy_trap_info(struct trap_info *traps);
23766
23767diff -urNp linux-2.6.32.44/block/blk-integrity.c linux-2.6.32.44/block/blk-integrity.c
23768--- linux-2.6.32.44/block/blk-integrity.c 2011-03-27 14:31:47.000000000 -0400
23769+++ linux-2.6.32.44/block/blk-integrity.c 2011-04-17 15:56:46.000000000 -0400
23770@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs
23771 NULL,
23772 };
23773
23774-static struct sysfs_ops integrity_ops = {
23775+static const struct sysfs_ops integrity_ops = {
23776 .show = &integrity_attr_show,
23777 .store = &integrity_attr_store,
23778 };
23779diff -urNp linux-2.6.32.44/block/blk-iopoll.c linux-2.6.32.44/block/blk-iopoll.c
23780--- linux-2.6.32.44/block/blk-iopoll.c 2011-03-27 14:31:47.000000000 -0400
23781+++ linux-2.6.32.44/block/blk-iopoll.c 2011-04-17 15:56:46.000000000 -0400
23782@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
23783 }
23784 EXPORT_SYMBOL(blk_iopoll_complete);
23785
23786-static void blk_iopoll_softirq(struct softirq_action *h)
23787+static void blk_iopoll_softirq(void)
23788 {
23789 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
23790 int rearm = 0, budget = blk_iopoll_budget;
23791diff -urNp linux-2.6.32.44/block/blk-map.c linux-2.6.32.44/block/blk-map.c
23792--- linux-2.6.32.44/block/blk-map.c 2011-03-27 14:31:47.000000000 -0400
23793+++ linux-2.6.32.44/block/blk-map.c 2011-04-18 16:57:33.000000000 -0400
23794@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct requ
23795 * direct dma. else, set up kernel bounce buffers
23796 */
23797 uaddr = (unsigned long) ubuf;
23798- if (blk_rq_aligned(q, ubuf, len) && !map_data)
23799+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
23800 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
23801 else
23802 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
23803@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_q
23804 for (i = 0; i < iov_count; i++) {
23805 unsigned long uaddr = (unsigned long)iov[i].iov_base;
23806
23807+ if (!iov[i].iov_len)
23808+ return -EINVAL;
23809+
23810 if (uaddr & queue_dma_alignment(q)) {
23811 unaligned = 1;
23812 break;
23813 }
23814- if (!iov[i].iov_len)
23815- return -EINVAL;
23816 }
23817
23818 if (unaligned || (q->dma_pad_mask & len) || map_data)
23819@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue
23820 if (!len || !kbuf)
23821 return -EINVAL;
23822
23823- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
23824+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
23825 if (do_copy)
23826 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
23827 else
23828diff -urNp linux-2.6.32.44/block/blk-softirq.c linux-2.6.32.44/block/blk-softirq.c
23829--- linux-2.6.32.44/block/blk-softirq.c 2011-03-27 14:31:47.000000000 -0400
23830+++ linux-2.6.32.44/block/blk-softirq.c 2011-04-17 15:56:46.000000000 -0400
23831@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
23832 * Softirq action handler - move entries to local list and loop over them
23833 * while passing them to the queue registered handler.
23834 */
23835-static void blk_done_softirq(struct softirq_action *h)
23836+static void blk_done_softirq(void)
23837 {
23838 struct list_head *cpu_list, local_list;
23839
23840diff -urNp linux-2.6.32.44/block/blk-sysfs.c linux-2.6.32.44/block/blk-sysfs.c
23841--- linux-2.6.32.44/block/blk-sysfs.c 2011-05-10 22:12:01.000000000 -0400
23842+++ linux-2.6.32.44/block/blk-sysfs.c 2011-05-10 22:12:26.000000000 -0400
23843@@ -414,7 +414,7 @@ static void blk_release_queue(struct kob
23844 kmem_cache_free(blk_requestq_cachep, q);
23845 }
23846
23847-static struct sysfs_ops queue_sysfs_ops = {
23848+static const struct sysfs_ops queue_sysfs_ops = {
23849 .show = queue_attr_show,
23850 .store = queue_attr_store,
23851 };
23852diff -urNp linux-2.6.32.44/block/bsg.c linux-2.6.32.44/block/bsg.c
23853--- linux-2.6.32.44/block/bsg.c 2011-03-27 14:31:47.000000000 -0400
23854+++ linux-2.6.32.44/block/bsg.c 2011-04-17 15:56:46.000000000 -0400
23855@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
23856 struct sg_io_v4 *hdr, struct bsg_device *bd,
23857 fmode_t has_write_perm)
23858 {
23859+ unsigned char tmpcmd[sizeof(rq->__cmd)];
23860+ unsigned char *cmdptr;
23861+
23862 if (hdr->request_len > BLK_MAX_CDB) {
23863 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
23864 if (!rq->cmd)
23865 return -ENOMEM;
23866- }
23867+ cmdptr = rq->cmd;
23868+ } else
23869+ cmdptr = tmpcmd;
23870
23871- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
23872+ if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
23873 hdr->request_len))
23874 return -EFAULT;
23875
23876+ if (cmdptr != rq->cmd)
23877+ memcpy(rq->cmd, cmdptr, hdr->request_len);
23878+
23879 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
23880 if (blk_verify_command(rq->cmd, has_write_perm))
23881 return -EPERM;
23882diff -urNp linux-2.6.32.44/block/elevator.c linux-2.6.32.44/block/elevator.c
23883--- linux-2.6.32.44/block/elevator.c 2011-03-27 14:31:47.000000000 -0400
23884+++ linux-2.6.32.44/block/elevator.c 2011-04-17 15:56:46.000000000 -0400
23885@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, str
23886 return error;
23887 }
23888
23889-static struct sysfs_ops elv_sysfs_ops = {
23890+static const struct sysfs_ops elv_sysfs_ops = {
23891 .show = elv_attr_show,
23892 .store = elv_attr_store,
23893 };
23894diff -urNp linux-2.6.32.44/block/scsi_ioctl.c linux-2.6.32.44/block/scsi_ioctl.c
23895--- linux-2.6.32.44/block/scsi_ioctl.c 2011-03-27 14:31:47.000000000 -0400
23896+++ linux-2.6.32.44/block/scsi_ioctl.c 2011-04-23 13:28:22.000000000 -0400
23897@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
23898 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
23899 struct sg_io_hdr *hdr, fmode_t mode)
23900 {
23901- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
23902+ unsigned char tmpcmd[sizeof(rq->__cmd)];
23903+ unsigned char *cmdptr;
23904+
23905+ if (rq->cmd != rq->__cmd)
23906+ cmdptr = rq->cmd;
23907+ else
23908+ cmdptr = tmpcmd;
23909+
23910+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
23911 return -EFAULT;
23912+
23913+ if (cmdptr != rq->cmd)
23914+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
23915+
23916 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
23917 return -EPERM;
23918
23919@@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *
23920 int err;
23921 unsigned int in_len, out_len, bytes, opcode, cmdlen;
23922 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
23923+ unsigned char tmpcmd[sizeof(rq->__cmd)];
23924+ unsigned char *cmdptr;
23925
23926 if (!sic)
23927 return -EINVAL;
23928@@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *
23929 */
23930 err = -EFAULT;
23931 rq->cmd_len = cmdlen;
23932- if (copy_from_user(rq->cmd, sic->data, cmdlen))
23933+
23934+ if (rq->cmd != rq->__cmd)
23935+ cmdptr = rq->cmd;
23936+ else
23937+ cmdptr = tmpcmd;
23938+
23939+ if (copy_from_user(cmdptr, sic->data, cmdlen))
23940 goto error;
23941
23942+ if (rq->cmd != cmdptr)
23943+ memcpy(rq->cmd, cmdptr, cmdlen);
23944+
23945 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
23946 goto error;
23947
23948diff -urNp linux-2.6.32.44/crypto/cryptd.c linux-2.6.32.44/crypto/cryptd.c
23949--- linux-2.6.32.44/crypto/cryptd.c 2011-03-27 14:31:47.000000000 -0400
23950+++ linux-2.6.32.44/crypto/cryptd.c 2011-08-05 20:33:55.000000000 -0400
23951@@ -214,7 +214,7 @@ static int cryptd_blkcipher_enqueue(stru
23952 struct cryptd_queue *queue;
23953
23954 queue = cryptd_get_queue(crypto_ablkcipher_tfm(tfm));
23955- rctx->complete = req->base.complete;
23956+ *(void **)&rctx->complete = req->base.complete;
23957 req->base.complete = complete;
23958
23959 return cryptd_enqueue_request(queue, &req->base);
23960diff -urNp linux-2.6.32.44/crypto/gf128mul.c linux-2.6.32.44/crypto/gf128mul.c
23961--- linux-2.6.32.44/crypto/gf128mul.c 2011-03-27 14:31:47.000000000 -0400
23962+++ linux-2.6.32.44/crypto/gf128mul.c 2011-07-06 19:53:33.000000000 -0400
23963@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128
23964 for (i = 0; i < 7; ++i)
23965 gf128mul_x_lle(&p[i + 1], &p[i]);
23966
23967- memset(r, 0, sizeof(r));
23968+ memset(r, 0, sizeof(*r));
23969 for (i = 0;;) {
23970 u8 ch = ((u8 *)b)[15 - i];
23971
23972@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128
23973 for (i = 0; i < 7; ++i)
23974 gf128mul_x_bbe(&p[i + 1], &p[i]);
23975
23976- memset(r, 0, sizeof(r));
23977+ memset(r, 0, sizeof(*r));
23978 for (i = 0;;) {
23979 u8 ch = ((u8 *)b)[i];
23980
23981diff -urNp linux-2.6.32.44/crypto/md5.c linux-2.6.32.44/crypto/md5.c
23982--- linux-2.6.32.44/crypto/md5.c 2011-03-27 14:31:47.000000000 -0400
23983+++ linux-2.6.32.44/crypto/md5.c 2011-08-07 19:48:09.000000000 -0400
23984@@ -20,6 +20,7 @@
23985 #include <linux/module.h>
23986 #include <linux/string.h>
23987 #include <linux/types.h>
23988+#include <linux/cryptohash.h>
23989 #include <asm/byteorder.h>
23990
23991 #define MD5_DIGEST_SIZE 16
23992@@ -27,103 +28,12 @@
23993 #define MD5_BLOCK_WORDS 16
23994 #define MD5_HASH_WORDS 4
23995
23996-#define F1(x, y, z) (z ^ (x & (y ^ z)))
23997-#define F2(x, y, z) F1(z, x, y)
23998-#define F3(x, y, z) (x ^ y ^ z)
23999-#define F4(x, y, z) (y ^ (x | ~z))
24000-
24001-#define MD5STEP(f, w, x, y, z, in, s) \
24002- (w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x)
24003-
24004 struct md5_ctx {
24005 u32 hash[MD5_HASH_WORDS];
24006 u32 block[MD5_BLOCK_WORDS];
24007 u64 byte_count;
24008 };
24009
24010-static void md5_transform(u32 *hash, u32 const *in)
24011-{
24012- u32 a, b, c, d;
24013-
24014- a = hash[0];
24015- b = hash[1];
24016- c = hash[2];
24017- d = hash[3];
24018-
24019- MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
24020- MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
24021- MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
24022- MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
24023- MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
24024- MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
24025- MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
24026- MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
24027- MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
24028- MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
24029- MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
24030- MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
24031- MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
24032- MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
24033- MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
24034- MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
24035-
24036- MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
24037- MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
24038- MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
24039- MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
24040- MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
24041- MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
24042- MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
24043- MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
24044- MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
24045- MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
24046- MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
24047- MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
24048- MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
24049- MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
24050- MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
24051- MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
24052-
24053- MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
24054- MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
24055- MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
24056- MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
24057- MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
24058- MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
24059- MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
24060- MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
24061- MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
24062- MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
24063- MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
24064- MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
24065- MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
24066- MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
24067- MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
24068- MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
24069-
24070- MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
24071- MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
24072- MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
24073- MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
24074- MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
24075- MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
24076- MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
24077- MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
24078- MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
24079- MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
24080- MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
24081- MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
24082- MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
24083- MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
24084- MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
24085- MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
24086-
24087- hash[0] += a;
24088- hash[1] += b;
24089- hash[2] += c;
24090- hash[3] += d;
24091-}
24092-
24093 /* XXX: this stuff can be optimized */
24094 static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
24095 {
24096diff -urNp linux-2.6.32.44/crypto/serpent.c linux-2.6.32.44/crypto/serpent.c
24097--- linux-2.6.32.44/crypto/serpent.c 2011-03-27 14:31:47.000000000 -0400
24098+++ linux-2.6.32.44/crypto/serpent.c 2011-05-16 21:46:57.000000000 -0400
24099@@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24100 u32 r0,r1,r2,r3,r4;
24101 int i;
24102
24103+ pax_track_stack();
24104+
24105 /* Copy key, add padding */
24106
24107 for (i = 0; i < keylen; ++i)
24108diff -urNp linux-2.6.32.44/Documentation/dontdiff linux-2.6.32.44/Documentation/dontdiff
24109--- linux-2.6.32.44/Documentation/dontdiff 2011-03-27 14:31:47.000000000 -0400
24110+++ linux-2.6.32.44/Documentation/dontdiff 2011-05-18 20:09:36.000000000 -0400
24111@@ -1,13 +1,16 @@
24112 *.a
24113 *.aux
24114 *.bin
24115+*.cis
24116 *.cpio
24117 *.csp
24118+*.dbg
24119 *.dsp
24120 *.dvi
24121 *.elf
24122 *.eps
24123 *.fw
24124+*.gcno
24125 *.gen.S
24126 *.gif
24127 *.grep
24128@@ -38,8 +41,10 @@
24129 *.tab.h
24130 *.tex
24131 *.ver
24132+*.vim
24133 *.xml
24134 *_MODULES
24135+*_reg_safe.h
24136 *_vga16.c
24137 *~
24138 *.9
24139@@ -49,11 +54,16 @@
24140 53c700_d.h
24141 CVS
24142 ChangeSet
24143+GPATH
24144+GRTAGS
24145+GSYMS
24146+GTAGS
24147 Image
24148 Kerntypes
24149 Module.markers
24150 Module.symvers
24151 PENDING
24152+PERF*
24153 SCCS
24154 System.map*
24155 TAGS
24156@@ -76,7 +86,11 @@ btfixupprep
24157 build
24158 bvmlinux
24159 bzImage*
24160+capability_names.h
24161+capflags.c
24162 classlist.h*
24163+clut_vga16.c
24164+common-cmds.h
24165 comp*.log
24166 compile.h*
24167 conf
24168@@ -103,13 +117,14 @@ gen_crc32table
24169 gen_init_cpio
24170 genksyms
24171 *_gray256.c
24172+hash
24173 ihex2fw
24174 ikconfig.h*
24175 initramfs_data.cpio
24176+initramfs_data.cpio.bz2
24177 initramfs_data.cpio.gz
24178 initramfs_list
24179 kallsyms
24180-kconfig
24181 keywords.c
24182 ksym.c*
24183 ksym.h*
24184@@ -133,7 +148,9 @@ mkboot
24185 mkbugboot
24186 mkcpustr
24187 mkdep
24188+mkpiggy
24189 mkprep
24190+mkregtable
24191 mktables
24192 mktree
24193 modpost
24194@@ -149,6 +166,7 @@ patches*
24195 pca200e.bin
24196 pca200e_ecd.bin2
24197 piggy.gz
24198+piggy.S
24199 piggyback
24200 pnmtologo
24201 ppc_defs.h*
24202@@ -157,12 +175,15 @@ qconf
24203 raid6altivec*.c
24204 raid6int*.c
24205 raid6tables.c
24206+regdb.c
24207 relocs
24208+rlim_names.h
24209 series
24210 setup
24211 setup.bin
24212 setup.elf
24213 sImage
24214+slabinfo
24215 sm_tbl*
24216 split-include
24217 syscalltab.h
24218@@ -186,14 +207,20 @@ version.h*
24219 vmlinux
24220 vmlinux-*
24221 vmlinux.aout
24222+vmlinux.bin.all
24223+vmlinux.bin.bz2
24224 vmlinux.lds
24225+vmlinux.relocs
24226+voffset.h
24227 vsyscall.lds
24228 vsyscall_32.lds
24229 wanxlfw.inc
24230 uImage
24231 unifdef
24232+utsrelease.h
24233 wakeup.bin
24234 wakeup.elf
24235 wakeup.lds
24236 zImage*
24237 zconf.hash.c
24238+zoffset.h
24239diff -urNp linux-2.6.32.44/Documentation/kernel-parameters.txt linux-2.6.32.44/Documentation/kernel-parameters.txt
24240--- linux-2.6.32.44/Documentation/kernel-parameters.txt 2011-03-27 14:31:47.000000000 -0400
24241+++ linux-2.6.32.44/Documentation/kernel-parameters.txt 2011-04-17 15:56:45.000000000 -0400
24242@@ -1837,6 +1837,13 @@ and is between 256 and 4096 characters.
24243 the specified number of seconds. This is to be used if
24244 your oopses keep scrolling off the screen.
24245
24246+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24247+ virtualization environments that don't cope well with the
24248+ expand down segment used by UDEREF on X86-32 or the frequent
24249+ page table updates on X86-64.
24250+
24251+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24252+
24253 pcbit= [HW,ISDN]
24254
24255 pcd. [PARIDE]
24256diff -urNp linux-2.6.32.44/drivers/acpi/acpi_pad.c linux-2.6.32.44/drivers/acpi/acpi_pad.c
24257--- linux-2.6.32.44/drivers/acpi/acpi_pad.c 2011-03-27 14:31:47.000000000 -0400
24258+++ linux-2.6.32.44/drivers/acpi/acpi_pad.c 2011-04-17 15:56:46.000000000 -0400
24259@@ -30,7 +30,7 @@
24260 #include <acpi/acpi_bus.h>
24261 #include <acpi/acpi_drivers.h>
24262
24263-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
24264+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
24265 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
24266 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
24267 static DEFINE_MUTEX(isolated_cpus_lock);
24268diff -urNp linux-2.6.32.44/drivers/acpi/battery.c linux-2.6.32.44/drivers/acpi/battery.c
24269--- linux-2.6.32.44/drivers/acpi/battery.c 2011-03-27 14:31:47.000000000 -0400
24270+++ linux-2.6.32.44/drivers/acpi/battery.c 2011-04-17 15:56:46.000000000 -0400
24271@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24272 }
24273
24274 static struct battery_file {
24275- struct file_operations ops;
24276+ const struct file_operations ops;
24277 mode_t mode;
24278 const char *name;
24279 } acpi_battery_file[] = {
24280diff -urNp linux-2.6.32.44/drivers/acpi/dock.c linux-2.6.32.44/drivers/acpi/dock.c
24281--- linux-2.6.32.44/drivers/acpi/dock.c 2011-03-27 14:31:47.000000000 -0400
24282+++ linux-2.6.32.44/drivers/acpi/dock.c 2011-04-17 15:56:46.000000000 -0400
24283@@ -77,7 +77,7 @@ struct dock_dependent_device {
24284 struct list_head list;
24285 struct list_head hotplug_list;
24286 acpi_handle handle;
24287- struct acpi_dock_ops *ops;
24288+ const struct acpi_dock_ops *ops;
24289 void *context;
24290 };
24291
24292@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24293 * the dock driver after _DCK is executed.
24294 */
24295 int
24296-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24297+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24298 void *context)
24299 {
24300 struct dock_dependent_device *dd;
24301diff -urNp linux-2.6.32.44/drivers/acpi/osl.c linux-2.6.32.44/drivers/acpi/osl.c
24302--- linux-2.6.32.44/drivers/acpi/osl.c 2011-03-27 14:31:47.000000000 -0400
24303+++ linux-2.6.32.44/drivers/acpi/osl.c 2011-04-17 15:56:46.000000000 -0400
24304@@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_addres
24305 void __iomem *virt_addr;
24306
24307 virt_addr = ioremap(phys_addr, width);
24308+ if (!virt_addr)
24309+ return AE_NO_MEMORY;
24310 if (!value)
24311 value = &dummy;
24312
24313@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_addre
24314 void __iomem *virt_addr;
24315
24316 virt_addr = ioremap(phys_addr, width);
24317+ if (!virt_addr)
24318+ return AE_NO_MEMORY;
24319
24320 switch (width) {
24321 case 8:
24322diff -urNp linux-2.6.32.44/drivers/acpi/power_meter.c linux-2.6.32.44/drivers/acpi/power_meter.c
24323--- linux-2.6.32.44/drivers/acpi/power_meter.c 2011-03-27 14:31:47.000000000 -0400
24324+++ linux-2.6.32.44/drivers/acpi/power_meter.c 2011-04-17 15:56:46.000000000 -0400
24325@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *d
24326 return res;
24327
24328 temp /= 1000;
24329- if (temp < 0)
24330- return -EINVAL;
24331
24332 mutex_lock(&resource->lock);
24333 resource->trip[attr->index - 7] = temp;
24334diff -urNp linux-2.6.32.44/drivers/acpi/proc.c linux-2.6.32.44/drivers/acpi/proc.c
24335--- linux-2.6.32.44/drivers/acpi/proc.c 2011-03-27 14:31:47.000000000 -0400
24336+++ linux-2.6.32.44/drivers/acpi/proc.c 2011-04-17 15:56:46.000000000 -0400
24337@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct f
24338 size_t count, loff_t * ppos)
24339 {
24340 struct list_head *node, *next;
24341- char strbuf[5];
24342- char str[5] = "";
24343- unsigned int len = count;
24344+ char strbuf[5] = {0};
24345 struct acpi_device *found_dev = NULL;
24346
24347- if (len > 4)
24348- len = 4;
24349- if (len < 0)
24350- return -EFAULT;
24351+ if (count > 4)
24352+ count = 4;
24353
24354- if (copy_from_user(strbuf, buffer, len))
24355+ if (copy_from_user(strbuf, buffer, count))
24356 return -EFAULT;
24357- strbuf[len] = '\0';
24358- sscanf(strbuf, "%s", str);
24359+ strbuf[count] = '\0';
24360
24361 mutex_lock(&acpi_device_lock);
24362 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24363@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct f
24364 if (!dev->wakeup.flags.valid)
24365 continue;
24366
24367- if (!strncmp(dev->pnp.bus_id, str, 4)) {
24368+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24369 dev->wakeup.state.enabled =
24370 dev->wakeup.state.enabled ? 0 : 1;
24371 found_dev = dev;
24372diff -urNp linux-2.6.32.44/drivers/acpi/processor_core.c linux-2.6.32.44/drivers/acpi/processor_core.c
24373--- linux-2.6.32.44/drivers/acpi/processor_core.c 2011-03-27 14:31:47.000000000 -0400
24374+++ linux-2.6.32.44/drivers/acpi/processor_core.c 2011-04-17 15:56:46.000000000 -0400
24375@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(
24376 return 0;
24377 }
24378
24379- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24380+ BUG_ON(pr->id >= nr_cpu_ids);
24381
24382 /*
24383 * Buggy BIOS check
24384diff -urNp linux-2.6.32.44/drivers/acpi/sbshc.c linux-2.6.32.44/drivers/acpi/sbshc.c
24385--- linux-2.6.32.44/drivers/acpi/sbshc.c 2011-03-27 14:31:47.000000000 -0400
24386+++ linux-2.6.32.44/drivers/acpi/sbshc.c 2011-04-17 15:56:46.000000000 -0400
24387@@ -17,7 +17,7 @@
24388
24389 #define PREFIX "ACPI: "
24390
24391-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
24392+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
24393 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
24394
24395 struct acpi_smb_hc {
24396diff -urNp linux-2.6.32.44/drivers/acpi/sleep.c linux-2.6.32.44/drivers/acpi/sleep.c
24397--- linux-2.6.32.44/drivers/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
24398+++ linux-2.6.32.44/drivers/acpi/sleep.c 2011-04-17 15:56:46.000000000 -0400
24399@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(susp
24400 }
24401 }
24402
24403-static struct platform_suspend_ops acpi_suspend_ops = {
24404+static const struct platform_suspend_ops acpi_suspend_ops = {
24405 .valid = acpi_suspend_state_valid,
24406 .begin = acpi_suspend_begin,
24407 .prepare_late = acpi_pm_prepare,
24408@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspen
24409 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
24410 * been requested.
24411 */
24412-static struct platform_suspend_ops acpi_suspend_ops_old = {
24413+static const struct platform_suspend_ops acpi_suspend_ops_old = {
24414 .valid = acpi_suspend_state_valid,
24415 .begin = acpi_suspend_begin_old,
24416 .prepare_late = acpi_pm_disable_gpes,
24417@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
24418 acpi_enable_all_runtime_gpes();
24419 }
24420
24421-static struct platform_hibernation_ops acpi_hibernation_ops = {
24422+static const struct platform_hibernation_ops acpi_hibernation_ops = {
24423 .begin = acpi_hibernation_begin,
24424 .end = acpi_pm_end,
24425 .pre_snapshot = acpi_hibernation_pre_snapshot,
24426@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot
24427 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
24428 * been requested.
24429 */
24430-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
24431+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
24432 .begin = acpi_hibernation_begin_old,
24433 .end = acpi_pm_end,
24434 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
24435diff -urNp linux-2.6.32.44/drivers/acpi/video.c linux-2.6.32.44/drivers/acpi/video.c
24436--- linux-2.6.32.44/drivers/acpi/video.c 2011-03-27 14:31:47.000000000 -0400
24437+++ linux-2.6.32.44/drivers/acpi/video.c 2011-04-17 15:56:46.000000000 -0400
24438@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(str
24439 vd->brightness->levels[request_level]);
24440 }
24441
24442-static struct backlight_ops acpi_backlight_ops = {
24443+static const struct backlight_ops acpi_backlight_ops = {
24444 .get_brightness = acpi_video_get_brightness,
24445 .update_status = acpi_video_set_brightness,
24446 };
24447diff -urNp linux-2.6.32.44/drivers/ata/ahci.c linux-2.6.32.44/drivers/ata/ahci.c
24448--- linux-2.6.32.44/drivers/ata/ahci.c 2011-03-27 14:31:47.000000000 -0400
24449+++ linux-2.6.32.44/drivers/ata/ahci.c 2011-04-23 12:56:10.000000000 -0400
24450@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sh
24451 .sdev_attrs = ahci_sdev_attrs,
24452 };
24453
24454-static struct ata_port_operations ahci_ops = {
24455+static const struct ata_port_operations ahci_ops = {
24456 .inherits = &sata_pmp_port_ops,
24457
24458 .qc_defer = sata_pmp_qc_defer_cmd_switch,
24459@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_o
24460 .port_stop = ahci_port_stop,
24461 };
24462
24463-static struct ata_port_operations ahci_vt8251_ops = {
24464+static const struct ata_port_operations ahci_vt8251_ops = {
24465 .inherits = &ahci_ops,
24466 .hardreset = ahci_vt8251_hardreset,
24467 };
24468
24469-static struct ata_port_operations ahci_p5wdh_ops = {
24470+static const struct ata_port_operations ahci_p5wdh_ops = {
24471 .inherits = &ahci_ops,
24472 .hardreset = ahci_p5wdh_hardreset,
24473 };
24474
24475-static struct ata_port_operations ahci_sb600_ops = {
24476+static const struct ata_port_operations ahci_sb600_ops = {
24477 .inherits = &ahci_ops,
24478 .softreset = ahci_sb600_softreset,
24479 .pmp_softreset = ahci_sb600_softreset,
24480diff -urNp linux-2.6.32.44/drivers/ata/ata_generic.c linux-2.6.32.44/drivers/ata/ata_generic.c
24481--- linux-2.6.32.44/drivers/ata/ata_generic.c 2011-03-27 14:31:47.000000000 -0400
24482+++ linux-2.6.32.44/drivers/ata/ata_generic.c 2011-04-17 15:56:46.000000000 -0400
24483@@ -104,7 +104,7 @@ static struct scsi_host_template generic
24484 ATA_BMDMA_SHT(DRV_NAME),
24485 };
24486
24487-static struct ata_port_operations generic_port_ops = {
24488+static const struct ata_port_operations generic_port_ops = {
24489 .inherits = &ata_bmdma_port_ops,
24490 .cable_detect = ata_cable_unknown,
24491 .set_mode = generic_set_mode,
24492diff -urNp linux-2.6.32.44/drivers/ata/ata_piix.c linux-2.6.32.44/drivers/ata/ata_piix.c
24493--- linux-2.6.32.44/drivers/ata/ata_piix.c 2011-03-27 14:31:47.000000000 -0400
24494+++ linux-2.6.32.44/drivers/ata/ata_piix.c 2011-04-23 12:56:10.000000000 -0400
24495@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sh
24496 ATA_BMDMA_SHT(DRV_NAME),
24497 };
24498
24499-static struct ata_port_operations piix_pata_ops = {
24500+static const struct ata_port_operations piix_pata_ops = {
24501 .inherits = &ata_bmdma32_port_ops,
24502 .cable_detect = ata_cable_40wire,
24503 .set_piomode = piix_set_piomode,
24504@@ -326,22 +326,22 @@ static struct ata_port_operations piix_p
24505 .prereset = piix_pata_prereset,
24506 };
24507
24508-static struct ata_port_operations piix_vmw_ops = {
24509+static const struct ata_port_operations piix_vmw_ops = {
24510 .inherits = &piix_pata_ops,
24511 .bmdma_status = piix_vmw_bmdma_status,
24512 };
24513
24514-static struct ata_port_operations ich_pata_ops = {
24515+static const struct ata_port_operations ich_pata_ops = {
24516 .inherits = &piix_pata_ops,
24517 .cable_detect = ich_pata_cable_detect,
24518 .set_dmamode = ich_set_dmamode,
24519 };
24520
24521-static struct ata_port_operations piix_sata_ops = {
24522+static const struct ata_port_operations piix_sata_ops = {
24523 .inherits = &ata_bmdma_port_ops,
24524 };
24525
24526-static struct ata_port_operations piix_sidpr_sata_ops = {
24527+static const struct ata_port_operations piix_sidpr_sata_ops = {
24528 .inherits = &piix_sata_ops,
24529 .hardreset = sata_std_hardreset,
24530 .scr_read = piix_sidpr_scr_read,
24531diff -urNp linux-2.6.32.44/drivers/ata/libata-acpi.c linux-2.6.32.44/drivers/ata/libata-acpi.c
24532--- linux-2.6.32.44/drivers/ata/libata-acpi.c 2011-03-27 14:31:47.000000000 -0400
24533+++ linux-2.6.32.44/drivers/ata/libata-acpi.c 2011-04-17 15:56:46.000000000 -0400
24534@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_han
24535 ata_acpi_uevent(dev->link->ap, dev, event);
24536 }
24537
24538-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24539+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24540 .handler = ata_acpi_dev_notify_dock,
24541 .uevent = ata_acpi_dev_uevent,
24542 };
24543
24544-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24545+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24546 .handler = ata_acpi_ap_notify_dock,
24547 .uevent = ata_acpi_ap_uevent,
24548 };
24549diff -urNp linux-2.6.32.44/drivers/ata/libata-core.c linux-2.6.32.44/drivers/ata/libata-core.c
24550--- linux-2.6.32.44/drivers/ata/libata-core.c 2011-03-27 14:31:47.000000000 -0400
24551+++ linux-2.6.32.44/drivers/ata/libata-core.c 2011-08-05 20:33:55.000000000 -0400
24552@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *
24553 struct ata_port *ap;
24554 unsigned int tag;
24555
24556- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24557+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24558 ap = qc->ap;
24559
24560 qc->flags = 0;
24561@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued
24562 struct ata_port *ap;
24563 struct ata_link *link;
24564
24565- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24566+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24567 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
24568 ap = qc->ap;
24569 link = qc->dev->link;
24570@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device
24571 * LOCKING:
24572 * None.
24573 */
24574-static void ata_finalize_port_ops(struct ata_port_operations *ops)
24575+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
24576 {
24577 static DEFINE_SPINLOCK(lock);
24578 const struct ata_port_operations *cur;
24579@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct
24580 return;
24581
24582 spin_lock(&lock);
24583+ pax_open_kernel();
24584
24585 for (cur = ops->inherits; cur; cur = cur->inherits) {
24586 void **inherit = (void **)cur;
24587@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct
24588 if (IS_ERR(*pp))
24589 *pp = NULL;
24590
24591- ops->inherits = NULL;
24592+ *(struct ata_port_operations **)&ops->inherits = NULL;
24593
24594+ pax_close_kernel();
24595 spin_unlock(&lock);
24596 }
24597
24598@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host
24599 */
24600 /* KILLME - the only user left is ipr */
24601 void ata_host_init(struct ata_host *host, struct device *dev,
24602- unsigned long flags, struct ata_port_operations *ops)
24603+ unsigned long flags, const struct ata_port_operations *ops)
24604 {
24605 spin_lock_init(&host->lock);
24606 host->dev = dev;
24607@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(stru
24608 /* truly dummy */
24609 }
24610
24611-struct ata_port_operations ata_dummy_port_ops = {
24612+const struct ata_port_operations ata_dummy_port_ops = {
24613 .qc_prep = ata_noop_qc_prep,
24614 .qc_issue = ata_dummy_qc_issue,
24615 .error_handler = ata_dummy_error_handler,
24616diff -urNp linux-2.6.32.44/drivers/ata/libata-eh.c linux-2.6.32.44/drivers/ata/libata-eh.c
24617--- linux-2.6.32.44/drivers/ata/libata-eh.c 2011-08-09 18:35:28.000000000 -0400
24618+++ linux-2.6.32.44/drivers/ata/libata-eh.c 2011-08-09 18:33:59.000000000 -0400
24619@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
24620 {
24621 struct ata_link *link;
24622
24623+ pax_track_stack();
24624+
24625 ata_for_each_link(link, ap, HOST_FIRST)
24626 ata_eh_link_report(link);
24627 }
24628@@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_
24629 */
24630 void ata_std_error_handler(struct ata_port *ap)
24631 {
24632- struct ata_port_operations *ops = ap->ops;
24633+ const struct ata_port_operations *ops = ap->ops;
24634 ata_reset_fn_t hardreset = ops->hardreset;
24635
24636 /* ignore built-in hardreset if SCR access is not available */
24637diff -urNp linux-2.6.32.44/drivers/ata/libata-pmp.c linux-2.6.32.44/drivers/ata/libata-pmp.c
24638--- linux-2.6.32.44/drivers/ata/libata-pmp.c 2011-03-27 14:31:47.000000000 -0400
24639+++ linux-2.6.32.44/drivers/ata/libata-pmp.c 2011-04-17 15:56:46.000000000 -0400
24640@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(str
24641 */
24642 static int sata_pmp_eh_recover(struct ata_port *ap)
24643 {
24644- struct ata_port_operations *ops = ap->ops;
24645+ const struct ata_port_operations *ops = ap->ops;
24646 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
24647 struct ata_link *pmp_link = &ap->link;
24648 struct ata_device *pmp_dev = pmp_link->device;
24649diff -urNp linux-2.6.32.44/drivers/ata/pata_acpi.c linux-2.6.32.44/drivers/ata/pata_acpi.c
24650--- linux-2.6.32.44/drivers/ata/pata_acpi.c 2011-03-27 14:31:47.000000000 -0400
24651+++ linux-2.6.32.44/drivers/ata/pata_acpi.c 2011-04-17 15:56:46.000000000 -0400
24652@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_s
24653 ATA_BMDMA_SHT(DRV_NAME),
24654 };
24655
24656-static struct ata_port_operations pacpi_ops = {
24657+static const struct ata_port_operations pacpi_ops = {
24658 .inherits = &ata_bmdma_port_ops,
24659 .qc_issue = pacpi_qc_issue,
24660 .cable_detect = pacpi_cable_detect,
24661diff -urNp linux-2.6.32.44/drivers/ata/pata_ali.c linux-2.6.32.44/drivers/ata/pata_ali.c
24662--- linux-2.6.32.44/drivers/ata/pata_ali.c 2011-03-27 14:31:47.000000000 -0400
24663+++ linux-2.6.32.44/drivers/ata/pata_ali.c 2011-04-17 15:56:46.000000000 -0400
24664@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht
24665 * Port operations for PIO only ALi
24666 */
24667
24668-static struct ata_port_operations ali_early_port_ops = {
24669+static const struct ata_port_operations ali_early_port_ops = {
24670 .inherits = &ata_sff_port_ops,
24671 .cable_detect = ata_cable_40wire,
24672 .set_piomode = ali_set_piomode,
24673@@ -382,7 +382,7 @@ static const struct ata_port_operations
24674 * Port operations for DMA capable ALi without cable
24675 * detect
24676 */
24677-static struct ata_port_operations ali_20_port_ops = {
24678+static const struct ata_port_operations ali_20_port_ops = {
24679 .inherits = &ali_dma_base_ops,
24680 .cable_detect = ata_cable_40wire,
24681 .mode_filter = ali_20_filter,
24682@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20
24683 /*
24684 * Port operations for DMA capable ALi with cable detect
24685 */
24686-static struct ata_port_operations ali_c2_port_ops = {
24687+static const struct ata_port_operations ali_c2_port_ops = {
24688 .inherits = &ali_dma_base_ops,
24689 .check_atapi_dma = ali_check_atapi_dma,
24690 .cable_detect = ali_c2_cable_detect,
24691@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2
24692 /*
24693 * Port operations for DMA capable ALi with cable detect
24694 */
24695-static struct ata_port_operations ali_c4_port_ops = {
24696+static const struct ata_port_operations ali_c4_port_ops = {
24697 .inherits = &ali_dma_base_ops,
24698 .check_atapi_dma = ali_check_atapi_dma,
24699 .cable_detect = ali_c2_cable_detect,
24700@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4
24701 /*
24702 * Port operations for DMA capable ALi with cable detect and LBA48
24703 */
24704-static struct ata_port_operations ali_c5_port_ops = {
24705+static const struct ata_port_operations ali_c5_port_ops = {
24706 .inherits = &ali_dma_base_ops,
24707 .check_atapi_dma = ali_check_atapi_dma,
24708 .dev_config = ali_warn_atapi_dma,
24709diff -urNp linux-2.6.32.44/drivers/ata/pata_amd.c linux-2.6.32.44/drivers/ata/pata_amd.c
24710--- linux-2.6.32.44/drivers/ata/pata_amd.c 2011-03-27 14:31:47.000000000 -0400
24711+++ linux-2.6.32.44/drivers/ata/pata_amd.c 2011-04-17 15:56:46.000000000 -0400
24712@@ -397,28 +397,28 @@ static const struct ata_port_operations
24713 .prereset = amd_pre_reset,
24714 };
24715
24716-static struct ata_port_operations amd33_port_ops = {
24717+static const struct ata_port_operations amd33_port_ops = {
24718 .inherits = &amd_base_port_ops,
24719 .cable_detect = ata_cable_40wire,
24720 .set_piomode = amd33_set_piomode,
24721 .set_dmamode = amd33_set_dmamode,
24722 };
24723
24724-static struct ata_port_operations amd66_port_ops = {
24725+static const struct ata_port_operations amd66_port_ops = {
24726 .inherits = &amd_base_port_ops,
24727 .cable_detect = ata_cable_unknown,
24728 .set_piomode = amd66_set_piomode,
24729 .set_dmamode = amd66_set_dmamode,
24730 };
24731
24732-static struct ata_port_operations amd100_port_ops = {
24733+static const struct ata_port_operations amd100_port_ops = {
24734 .inherits = &amd_base_port_ops,
24735 .cable_detect = ata_cable_unknown,
24736 .set_piomode = amd100_set_piomode,
24737 .set_dmamode = amd100_set_dmamode,
24738 };
24739
24740-static struct ata_port_operations amd133_port_ops = {
24741+static const struct ata_port_operations amd133_port_ops = {
24742 .inherits = &amd_base_port_ops,
24743 .cable_detect = amd_cable_detect,
24744 .set_piomode = amd133_set_piomode,
24745@@ -433,13 +433,13 @@ static const struct ata_port_operations
24746 .host_stop = nv_host_stop,
24747 };
24748
24749-static struct ata_port_operations nv100_port_ops = {
24750+static const struct ata_port_operations nv100_port_ops = {
24751 .inherits = &nv_base_port_ops,
24752 .set_piomode = nv100_set_piomode,
24753 .set_dmamode = nv100_set_dmamode,
24754 };
24755
24756-static struct ata_port_operations nv133_port_ops = {
24757+static const struct ata_port_operations nv133_port_ops = {
24758 .inherits = &nv_base_port_ops,
24759 .set_piomode = nv133_set_piomode,
24760 .set_dmamode = nv133_set_dmamode,
24761diff -urNp linux-2.6.32.44/drivers/ata/pata_artop.c linux-2.6.32.44/drivers/ata/pata_artop.c
24762--- linux-2.6.32.44/drivers/ata/pata_artop.c 2011-03-27 14:31:47.000000000 -0400
24763+++ linux-2.6.32.44/drivers/ata/pata_artop.c 2011-04-17 15:56:46.000000000 -0400
24764@@ -311,7 +311,7 @@ static struct scsi_host_template artop_s
24765 ATA_BMDMA_SHT(DRV_NAME),
24766 };
24767
24768-static struct ata_port_operations artop6210_ops = {
24769+static const struct ata_port_operations artop6210_ops = {
24770 .inherits = &ata_bmdma_port_ops,
24771 .cable_detect = ata_cable_40wire,
24772 .set_piomode = artop6210_set_piomode,
24773@@ -320,7 +320,7 @@ static struct ata_port_operations artop6
24774 .qc_defer = artop6210_qc_defer,
24775 };
24776
24777-static struct ata_port_operations artop6260_ops = {
24778+static const struct ata_port_operations artop6260_ops = {
24779 .inherits = &ata_bmdma_port_ops,
24780 .cable_detect = artop6260_cable_detect,
24781 .set_piomode = artop6260_set_piomode,
24782diff -urNp linux-2.6.32.44/drivers/ata/pata_at32.c linux-2.6.32.44/drivers/ata/pata_at32.c
24783--- linux-2.6.32.44/drivers/ata/pata_at32.c 2011-03-27 14:31:47.000000000 -0400
24784+++ linux-2.6.32.44/drivers/ata/pata_at32.c 2011-04-17 15:56:46.000000000 -0400
24785@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sh
24786 ATA_PIO_SHT(DRV_NAME),
24787 };
24788
24789-static struct ata_port_operations at32_port_ops = {
24790+static const struct ata_port_operations at32_port_ops = {
24791 .inherits = &ata_sff_port_ops,
24792 .cable_detect = ata_cable_40wire,
24793 .set_piomode = pata_at32_set_piomode,
24794diff -urNp linux-2.6.32.44/drivers/ata/pata_at91.c linux-2.6.32.44/drivers/ata/pata_at91.c
24795--- linux-2.6.32.44/drivers/ata/pata_at91.c 2011-03-27 14:31:47.000000000 -0400
24796+++ linux-2.6.32.44/drivers/ata/pata_at91.c 2011-04-17 15:56:46.000000000 -0400
24797@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at
24798 ATA_PIO_SHT(DRV_NAME),
24799 };
24800
24801-static struct ata_port_operations pata_at91_port_ops = {
24802+static const struct ata_port_operations pata_at91_port_ops = {
24803 .inherits = &ata_sff_port_ops,
24804
24805 .sff_data_xfer = pata_at91_data_xfer_noirq,
24806diff -urNp linux-2.6.32.44/drivers/ata/pata_atiixp.c linux-2.6.32.44/drivers/ata/pata_atiixp.c
24807--- linux-2.6.32.44/drivers/ata/pata_atiixp.c 2011-03-27 14:31:47.000000000 -0400
24808+++ linux-2.6.32.44/drivers/ata/pata_atiixp.c 2011-04-17 15:56:46.000000000 -0400
24809@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_
24810 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24811 };
24812
24813-static struct ata_port_operations atiixp_port_ops = {
24814+static const struct ata_port_operations atiixp_port_ops = {
24815 .inherits = &ata_bmdma_port_ops,
24816
24817 .qc_prep = ata_sff_dumb_qc_prep,
24818diff -urNp linux-2.6.32.44/drivers/ata/pata_atp867x.c linux-2.6.32.44/drivers/ata/pata_atp867x.c
24819--- linux-2.6.32.44/drivers/ata/pata_atp867x.c 2011-03-27 14:31:47.000000000 -0400
24820+++ linux-2.6.32.44/drivers/ata/pata_atp867x.c 2011-04-17 15:56:46.000000000 -0400
24821@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x
24822 ATA_BMDMA_SHT(DRV_NAME),
24823 };
24824
24825-static struct ata_port_operations atp867x_ops = {
24826+static const struct ata_port_operations atp867x_ops = {
24827 .inherits = &ata_bmdma_port_ops,
24828 .cable_detect = atp867x_cable_detect,
24829 .set_piomode = atp867x_set_piomode,
24830diff -urNp linux-2.6.32.44/drivers/ata/pata_bf54x.c linux-2.6.32.44/drivers/ata/pata_bf54x.c
24831--- linux-2.6.32.44/drivers/ata/pata_bf54x.c 2011-03-27 14:31:47.000000000 -0400
24832+++ linux-2.6.32.44/drivers/ata/pata_bf54x.c 2011-04-17 15:56:46.000000000 -0400
24833@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sh
24834 .dma_boundary = ATA_DMA_BOUNDARY,
24835 };
24836
24837-static struct ata_port_operations bfin_pata_ops = {
24838+static const struct ata_port_operations bfin_pata_ops = {
24839 .inherits = &ata_sff_port_ops,
24840
24841 .set_piomode = bfin_set_piomode,
24842diff -urNp linux-2.6.32.44/drivers/ata/pata_cmd640.c linux-2.6.32.44/drivers/ata/pata_cmd640.c
24843--- linux-2.6.32.44/drivers/ata/pata_cmd640.c 2011-03-27 14:31:47.000000000 -0400
24844+++ linux-2.6.32.44/drivers/ata/pata_cmd640.c 2011-04-17 15:56:46.000000000 -0400
24845@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_
24846 ATA_BMDMA_SHT(DRV_NAME),
24847 };
24848
24849-static struct ata_port_operations cmd640_port_ops = {
24850+static const struct ata_port_operations cmd640_port_ops = {
24851 .inherits = &ata_bmdma_port_ops,
24852 /* In theory xfer_noirq is not needed once we kill the prefetcher */
24853 .sff_data_xfer = ata_sff_data_xfer_noirq,
24854diff -urNp linux-2.6.32.44/drivers/ata/pata_cmd64x.c linux-2.6.32.44/drivers/ata/pata_cmd64x.c
24855--- linux-2.6.32.44/drivers/ata/pata_cmd64x.c 2011-06-25 12:55:34.000000000 -0400
24856+++ linux-2.6.32.44/drivers/ata/pata_cmd64x.c 2011-06-25 12:56:37.000000000 -0400
24857@@ -271,18 +271,18 @@ static const struct ata_port_operations
24858 .set_dmamode = cmd64x_set_dmamode,
24859 };
24860
24861-static struct ata_port_operations cmd64x_port_ops = {
24862+static const struct ata_port_operations cmd64x_port_ops = {
24863 .inherits = &cmd64x_base_ops,
24864 .cable_detect = ata_cable_40wire,
24865 };
24866
24867-static struct ata_port_operations cmd646r1_port_ops = {
24868+static const struct ata_port_operations cmd646r1_port_ops = {
24869 .inherits = &cmd64x_base_ops,
24870 .bmdma_stop = cmd646r1_bmdma_stop,
24871 .cable_detect = ata_cable_40wire,
24872 };
24873
24874-static struct ata_port_operations cmd648_port_ops = {
24875+static const struct ata_port_operations cmd648_port_ops = {
24876 .inherits = &cmd64x_base_ops,
24877 .bmdma_stop = cmd648_bmdma_stop,
24878 .cable_detect = cmd648_cable_detect,
24879diff -urNp linux-2.6.32.44/drivers/ata/pata_cs5520.c linux-2.6.32.44/drivers/ata/pata_cs5520.c
24880--- linux-2.6.32.44/drivers/ata/pata_cs5520.c 2011-03-27 14:31:47.000000000 -0400
24881+++ linux-2.6.32.44/drivers/ata/pata_cs5520.c 2011-04-17 15:56:46.000000000 -0400
24882@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_
24883 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24884 };
24885
24886-static struct ata_port_operations cs5520_port_ops = {
24887+static const struct ata_port_operations cs5520_port_ops = {
24888 .inherits = &ata_bmdma_port_ops,
24889 .qc_prep = ata_sff_dumb_qc_prep,
24890 .cable_detect = ata_cable_40wire,
24891diff -urNp linux-2.6.32.44/drivers/ata/pata_cs5530.c linux-2.6.32.44/drivers/ata/pata_cs5530.c
24892--- linux-2.6.32.44/drivers/ata/pata_cs5530.c 2011-03-27 14:31:47.000000000 -0400
24893+++ linux-2.6.32.44/drivers/ata/pata_cs5530.c 2011-04-17 15:56:46.000000000 -0400
24894@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
24895 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24896 };
24897
24898-static struct ata_port_operations cs5530_port_ops = {
24899+static const struct ata_port_operations cs5530_port_ops = {
24900 .inherits = &ata_bmdma_port_ops,
24901
24902 .qc_prep = ata_sff_dumb_qc_prep,
24903diff -urNp linux-2.6.32.44/drivers/ata/pata_cs5535.c linux-2.6.32.44/drivers/ata/pata_cs5535.c
24904--- linux-2.6.32.44/drivers/ata/pata_cs5535.c 2011-03-27 14:31:47.000000000 -0400
24905+++ linux-2.6.32.44/drivers/ata/pata_cs5535.c 2011-04-17 15:56:46.000000000 -0400
24906@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
24907 ATA_BMDMA_SHT(DRV_NAME),
24908 };
24909
24910-static struct ata_port_operations cs5535_port_ops = {
24911+static const struct ata_port_operations cs5535_port_ops = {
24912 .inherits = &ata_bmdma_port_ops,
24913 .cable_detect = cs5535_cable_detect,
24914 .set_piomode = cs5535_set_piomode,
24915diff -urNp linux-2.6.32.44/drivers/ata/pata_cs5536.c linux-2.6.32.44/drivers/ata/pata_cs5536.c
24916--- linux-2.6.32.44/drivers/ata/pata_cs5536.c 2011-03-27 14:31:47.000000000 -0400
24917+++ linux-2.6.32.44/drivers/ata/pata_cs5536.c 2011-04-17 15:56:46.000000000 -0400
24918@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_
24919 ATA_BMDMA_SHT(DRV_NAME),
24920 };
24921
24922-static struct ata_port_operations cs5536_port_ops = {
24923+static const struct ata_port_operations cs5536_port_ops = {
24924 .inherits = &ata_bmdma_port_ops,
24925 .cable_detect = cs5536_cable_detect,
24926 .set_piomode = cs5536_set_piomode,
24927diff -urNp linux-2.6.32.44/drivers/ata/pata_cypress.c linux-2.6.32.44/drivers/ata/pata_cypress.c
24928--- linux-2.6.32.44/drivers/ata/pata_cypress.c 2011-03-27 14:31:47.000000000 -0400
24929+++ linux-2.6.32.44/drivers/ata/pata_cypress.c 2011-04-17 15:56:46.000000000 -0400
24930@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c69
24931 ATA_BMDMA_SHT(DRV_NAME),
24932 };
24933
24934-static struct ata_port_operations cy82c693_port_ops = {
24935+static const struct ata_port_operations cy82c693_port_ops = {
24936 .inherits = &ata_bmdma_port_ops,
24937 .cable_detect = ata_cable_40wire,
24938 .set_piomode = cy82c693_set_piomode,
24939diff -urNp linux-2.6.32.44/drivers/ata/pata_efar.c linux-2.6.32.44/drivers/ata/pata_efar.c
24940--- linux-2.6.32.44/drivers/ata/pata_efar.c 2011-03-27 14:31:47.000000000 -0400
24941+++ linux-2.6.32.44/drivers/ata/pata_efar.c 2011-04-17 15:56:46.000000000 -0400
24942@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sh
24943 ATA_BMDMA_SHT(DRV_NAME),
24944 };
24945
24946-static struct ata_port_operations efar_ops = {
24947+static const struct ata_port_operations efar_ops = {
24948 .inherits = &ata_bmdma_port_ops,
24949 .cable_detect = efar_cable_detect,
24950 .set_piomode = efar_set_piomode,
24951diff -urNp linux-2.6.32.44/drivers/ata/pata_hpt366.c linux-2.6.32.44/drivers/ata/pata_hpt366.c
24952--- linux-2.6.32.44/drivers/ata/pata_hpt366.c 2011-06-25 12:55:34.000000000 -0400
24953+++ linux-2.6.32.44/drivers/ata/pata_hpt366.c 2011-06-25 12:56:37.000000000 -0400
24954@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_
24955 * Configuration for HPT366/68
24956 */
24957
24958-static struct ata_port_operations hpt366_port_ops = {
24959+static const struct ata_port_operations hpt366_port_ops = {
24960 .inherits = &ata_bmdma_port_ops,
24961 .cable_detect = hpt36x_cable_detect,
24962 .mode_filter = hpt366_filter,
24963diff -urNp linux-2.6.32.44/drivers/ata/pata_hpt37x.c linux-2.6.32.44/drivers/ata/pata_hpt37x.c
24964--- linux-2.6.32.44/drivers/ata/pata_hpt37x.c 2011-06-25 12:55:34.000000000 -0400
24965+++ linux-2.6.32.44/drivers/ata/pata_hpt37x.c 2011-06-25 12:56:37.000000000 -0400
24966@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_
24967 * Configuration for HPT370
24968 */
24969
24970-static struct ata_port_operations hpt370_port_ops = {
24971+static const struct ata_port_operations hpt370_port_ops = {
24972 .inherits = &ata_bmdma_port_ops,
24973
24974 .bmdma_stop = hpt370_bmdma_stop,
24975@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370
24976 * Configuration for HPT370A. Close to 370 but less filters
24977 */
24978
24979-static struct ata_port_operations hpt370a_port_ops = {
24980+static const struct ata_port_operations hpt370a_port_ops = {
24981 .inherits = &hpt370_port_ops,
24982 .mode_filter = hpt370a_filter,
24983 };
24984@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370
24985 * and DMA mode setting functionality.
24986 */
24987
24988-static struct ata_port_operations hpt372_port_ops = {
24989+static const struct ata_port_operations hpt372_port_ops = {
24990 .inherits = &ata_bmdma_port_ops,
24991
24992 .bmdma_stop = hpt37x_bmdma_stop,
24993@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372
24994 * but we have a different cable detection procedure for function 1.
24995 */
24996
24997-static struct ata_port_operations hpt374_fn1_port_ops = {
24998+static const struct ata_port_operations hpt374_fn1_port_ops = {
24999 .inherits = &hpt372_port_ops,
25000 .prereset = hpt374_fn1_pre_reset,
25001 };
25002diff -urNp linux-2.6.32.44/drivers/ata/pata_hpt3x2n.c linux-2.6.32.44/drivers/ata/pata_hpt3x2n.c
25003--- linux-2.6.32.44/drivers/ata/pata_hpt3x2n.c 2011-06-25 12:55:34.000000000 -0400
25004+++ linux-2.6.32.44/drivers/ata/pata_hpt3x2n.c 2011-06-25 12:56:37.000000000 -0400
25005@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n
25006 * Configuration for HPT3x2n.
25007 */
25008
25009-static struct ata_port_operations hpt3x2n_port_ops = {
25010+static const struct ata_port_operations hpt3x2n_port_ops = {
25011 .inherits = &ata_bmdma_port_ops,
25012
25013 .bmdma_stop = hpt3x2n_bmdma_stop,
25014diff -urNp linux-2.6.32.44/drivers/ata/pata_hpt3x3.c linux-2.6.32.44/drivers/ata/pata_hpt3x3.c
25015--- linux-2.6.32.44/drivers/ata/pata_hpt3x3.c 2011-03-27 14:31:47.000000000 -0400
25016+++ linux-2.6.32.44/drivers/ata/pata_hpt3x3.c 2011-04-17 15:56:46.000000000 -0400
25017@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
25018 ATA_BMDMA_SHT(DRV_NAME),
25019 };
25020
25021-static struct ata_port_operations hpt3x3_port_ops = {
25022+static const struct ata_port_operations hpt3x3_port_ops = {
25023 .inherits = &ata_bmdma_port_ops,
25024 .cable_detect = ata_cable_40wire,
25025 .set_piomode = hpt3x3_set_piomode,
25026diff -urNp linux-2.6.32.44/drivers/ata/pata_icside.c linux-2.6.32.44/drivers/ata/pata_icside.c
25027--- linux-2.6.32.44/drivers/ata/pata_icside.c 2011-03-27 14:31:47.000000000 -0400
25028+++ linux-2.6.32.44/drivers/ata/pata_icside.c 2011-04-17 15:56:46.000000000 -0400
25029@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct
25030 }
25031 }
25032
25033-static struct ata_port_operations pata_icside_port_ops = {
25034+static const struct ata_port_operations pata_icside_port_ops = {
25035 .inherits = &ata_sff_port_ops,
25036 /* no need to build any PRD tables for DMA */
25037 .qc_prep = ata_noop_qc_prep,
25038diff -urNp linux-2.6.32.44/drivers/ata/pata_isapnp.c linux-2.6.32.44/drivers/ata/pata_isapnp.c
25039--- linux-2.6.32.44/drivers/ata/pata_isapnp.c 2011-03-27 14:31:47.000000000 -0400
25040+++ linux-2.6.32.44/drivers/ata/pata_isapnp.c 2011-04-17 15:56:46.000000000 -0400
25041@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
25042 ATA_PIO_SHT(DRV_NAME),
25043 };
25044
25045-static struct ata_port_operations isapnp_port_ops = {
25046+static const struct ata_port_operations isapnp_port_ops = {
25047 .inherits = &ata_sff_port_ops,
25048 .cable_detect = ata_cable_40wire,
25049 };
25050
25051-static struct ata_port_operations isapnp_noalt_port_ops = {
25052+static const struct ata_port_operations isapnp_noalt_port_ops = {
25053 .inherits = &ata_sff_port_ops,
25054 .cable_detect = ata_cable_40wire,
25055 /* No altstatus so we don't want to use the lost interrupt poll */
25056diff -urNp linux-2.6.32.44/drivers/ata/pata_it8213.c linux-2.6.32.44/drivers/ata/pata_it8213.c
25057--- linux-2.6.32.44/drivers/ata/pata_it8213.c 2011-03-27 14:31:47.000000000 -0400
25058+++ linux-2.6.32.44/drivers/ata/pata_it8213.c 2011-04-17 15:56:46.000000000 -0400
25059@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_
25060 };
25061
25062
25063-static struct ata_port_operations it8213_ops = {
25064+static const struct ata_port_operations it8213_ops = {
25065 .inherits = &ata_bmdma_port_ops,
25066 .cable_detect = it8213_cable_detect,
25067 .set_piomode = it8213_set_piomode,
25068diff -urNp linux-2.6.32.44/drivers/ata/pata_it821x.c linux-2.6.32.44/drivers/ata/pata_it821x.c
25069--- linux-2.6.32.44/drivers/ata/pata_it821x.c 2011-03-27 14:31:47.000000000 -0400
25070+++ linux-2.6.32.44/drivers/ata/pata_it821x.c 2011-04-17 15:56:46.000000000 -0400
25071@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_
25072 ATA_BMDMA_SHT(DRV_NAME),
25073 };
25074
25075-static struct ata_port_operations it821x_smart_port_ops = {
25076+static const struct ata_port_operations it821x_smart_port_ops = {
25077 .inherits = &ata_bmdma_port_ops,
25078
25079 .check_atapi_dma= it821x_check_atapi_dma,
25080@@ -814,7 +814,7 @@ static struct ata_port_operations it821x
25081 .port_start = it821x_port_start,
25082 };
25083
25084-static struct ata_port_operations it821x_passthru_port_ops = {
25085+static const struct ata_port_operations it821x_passthru_port_ops = {
25086 .inherits = &ata_bmdma_port_ops,
25087
25088 .check_atapi_dma= it821x_check_atapi_dma,
25089@@ -830,7 +830,7 @@ static struct ata_port_operations it821x
25090 .port_start = it821x_port_start,
25091 };
25092
25093-static struct ata_port_operations it821x_rdc_port_ops = {
25094+static const struct ata_port_operations it821x_rdc_port_ops = {
25095 .inherits = &ata_bmdma_port_ops,
25096
25097 .check_atapi_dma= it821x_check_atapi_dma,
25098diff -urNp linux-2.6.32.44/drivers/ata/pata_ixp4xx_cf.c linux-2.6.32.44/drivers/ata/pata_ixp4xx_cf.c
25099--- linux-2.6.32.44/drivers/ata/pata_ixp4xx_cf.c 2011-03-27 14:31:47.000000000 -0400
25100+++ linux-2.6.32.44/drivers/ata/pata_ixp4xx_cf.c 2011-04-17 15:56:46.000000000 -0400
25101@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25102 ATA_PIO_SHT(DRV_NAME),
25103 };
25104
25105-static struct ata_port_operations ixp4xx_port_ops = {
25106+static const struct ata_port_operations ixp4xx_port_ops = {
25107 .inherits = &ata_sff_port_ops,
25108 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25109 .cable_detect = ata_cable_40wire,
25110diff -urNp linux-2.6.32.44/drivers/ata/pata_jmicron.c linux-2.6.32.44/drivers/ata/pata_jmicron.c
25111--- linux-2.6.32.44/drivers/ata/pata_jmicron.c 2011-03-27 14:31:47.000000000 -0400
25112+++ linux-2.6.32.44/drivers/ata/pata_jmicron.c 2011-04-17 15:56:46.000000000 -0400
25113@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25114 ATA_BMDMA_SHT(DRV_NAME),
25115 };
25116
25117-static struct ata_port_operations jmicron_ops = {
25118+static const struct ata_port_operations jmicron_ops = {
25119 .inherits = &ata_bmdma_port_ops,
25120 .prereset = jmicron_pre_reset,
25121 };
25122diff -urNp linux-2.6.32.44/drivers/ata/pata_legacy.c linux-2.6.32.44/drivers/ata/pata_legacy.c
25123--- linux-2.6.32.44/drivers/ata/pata_legacy.c 2011-03-27 14:31:47.000000000 -0400
25124+++ linux-2.6.32.44/drivers/ata/pata_legacy.c 2011-04-17 15:56:46.000000000 -0400
25125@@ -106,7 +106,7 @@ struct legacy_probe {
25126
25127 struct legacy_controller {
25128 const char *name;
25129- struct ata_port_operations *ops;
25130+ const struct ata_port_operations *ops;
25131 unsigned int pio_mask;
25132 unsigned int flags;
25133 unsigned int pflags;
25134@@ -223,12 +223,12 @@ static const struct ata_port_operations
25135 * pio_mask as well.
25136 */
25137
25138-static struct ata_port_operations simple_port_ops = {
25139+static const struct ata_port_operations simple_port_ops = {
25140 .inherits = &legacy_base_port_ops,
25141 .sff_data_xfer = ata_sff_data_xfer_noirq,
25142 };
25143
25144-static struct ata_port_operations legacy_port_ops = {
25145+static const struct ata_port_operations legacy_port_ops = {
25146 .inherits = &legacy_base_port_ops,
25147 .sff_data_xfer = ata_sff_data_xfer_noirq,
25148 .set_mode = legacy_set_mode,
25149@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(st
25150 return buflen;
25151 }
25152
25153-static struct ata_port_operations pdc20230_port_ops = {
25154+static const struct ata_port_operations pdc20230_port_ops = {
25155 .inherits = &legacy_base_port_ops,
25156 .set_piomode = pdc20230_set_piomode,
25157 .sff_data_xfer = pdc_data_xfer_vlb,
25158@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct a
25159 ioread8(ap->ioaddr.status_addr);
25160 }
25161
25162-static struct ata_port_operations ht6560a_port_ops = {
25163+static const struct ata_port_operations ht6560a_port_ops = {
25164 .inherits = &legacy_base_port_ops,
25165 .set_piomode = ht6560a_set_piomode,
25166 };
25167@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct a
25168 ioread8(ap->ioaddr.status_addr);
25169 }
25170
25171-static struct ata_port_operations ht6560b_port_ops = {
25172+static const struct ata_port_operations ht6560b_port_ops = {
25173 .inherits = &legacy_base_port_ops,
25174 .set_piomode = ht6560b_set_piomode,
25175 };
25176@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(stru
25177 }
25178
25179
25180-static struct ata_port_operations opti82c611a_port_ops = {
25181+static const struct ata_port_operations opti82c611a_port_ops = {
25182 .inherits = &legacy_base_port_ops,
25183 .set_piomode = opti82c611a_set_piomode,
25184 };
25185@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(
25186 return ata_sff_qc_issue(qc);
25187 }
25188
25189-static struct ata_port_operations opti82c46x_port_ops = {
25190+static const struct ata_port_operations opti82c46x_port_ops = {
25191 .inherits = &legacy_base_port_ops,
25192 .set_piomode = opti82c46x_set_piomode,
25193 .qc_issue = opti82c46x_qc_issue,
25194@@ -771,20 +771,20 @@ static int qdi_port(struct platform_devi
25195 return 0;
25196 }
25197
25198-static struct ata_port_operations qdi6500_port_ops = {
25199+static const struct ata_port_operations qdi6500_port_ops = {
25200 .inherits = &legacy_base_port_ops,
25201 .set_piomode = qdi6500_set_piomode,
25202 .qc_issue = qdi_qc_issue,
25203 .sff_data_xfer = vlb32_data_xfer,
25204 };
25205
25206-static struct ata_port_operations qdi6580_port_ops = {
25207+static const struct ata_port_operations qdi6580_port_ops = {
25208 .inherits = &legacy_base_port_ops,
25209 .set_piomode = qdi6580_set_piomode,
25210 .sff_data_xfer = vlb32_data_xfer,
25211 };
25212
25213-static struct ata_port_operations qdi6580dp_port_ops = {
25214+static const struct ata_port_operations qdi6580dp_port_ops = {
25215 .inherits = &legacy_base_port_ops,
25216 .set_piomode = qdi6580dp_set_piomode,
25217 .sff_data_xfer = vlb32_data_xfer,
25218@@ -855,7 +855,7 @@ static int winbond_port(struct platform_
25219 return 0;
25220 }
25221
25222-static struct ata_port_operations winbond_port_ops = {
25223+static const struct ata_port_operations winbond_port_ops = {
25224 .inherits = &legacy_base_port_ops,
25225 .set_piomode = winbond_set_piomode,
25226 .sff_data_xfer = vlb32_data_xfer,
25227@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct
25228 int pio_modes = controller->pio_mask;
25229 unsigned long io = probe->port;
25230 u32 mask = (1 << probe->slot);
25231- struct ata_port_operations *ops = controller->ops;
25232+ const struct ata_port_operations *ops = controller->ops;
25233 struct legacy_data *ld = &legacy_data[probe->slot];
25234 struct ata_host *host = NULL;
25235 struct ata_port *ap;
25236diff -urNp linux-2.6.32.44/drivers/ata/pata_marvell.c linux-2.6.32.44/drivers/ata/pata_marvell.c
25237--- linux-2.6.32.44/drivers/ata/pata_marvell.c 2011-03-27 14:31:47.000000000 -0400
25238+++ linux-2.6.32.44/drivers/ata/pata_marvell.c 2011-04-17 15:56:46.000000000 -0400
25239@@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25240 ATA_BMDMA_SHT(DRV_NAME),
25241 };
25242
25243-static struct ata_port_operations marvell_ops = {
25244+static const struct ata_port_operations marvell_ops = {
25245 .inherits = &ata_bmdma_port_ops,
25246 .cable_detect = marvell_cable_detect,
25247 .prereset = marvell_pre_reset,
25248diff -urNp linux-2.6.32.44/drivers/ata/pata_mpc52xx.c linux-2.6.32.44/drivers/ata/pata_mpc52xx.c
25249--- linux-2.6.32.44/drivers/ata/pata_mpc52xx.c 2011-03-27 14:31:47.000000000 -0400
25250+++ linux-2.6.32.44/drivers/ata/pata_mpc52xx.c 2011-04-17 15:56:46.000000000 -0400
25251@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25252 ATA_PIO_SHT(DRV_NAME),
25253 };
25254
25255-static struct ata_port_operations mpc52xx_ata_port_ops = {
25256+static const struct ata_port_operations mpc52xx_ata_port_ops = {
25257 .inherits = &ata_bmdma_port_ops,
25258 .sff_dev_select = mpc52xx_ata_dev_select,
25259 .set_piomode = mpc52xx_ata_set_piomode,
25260diff -urNp linux-2.6.32.44/drivers/ata/pata_mpiix.c linux-2.6.32.44/drivers/ata/pata_mpiix.c
25261--- linux-2.6.32.44/drivers/ata/pata_mpiix.c 2011-03-27 14:31:47.000000000 -0400
25262+++ linux-2.6.32.44/drivers/ata/pata_mpiix.c 2011-04-17 15:56:46.000000000 -0400
25263@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25264 ATA_PIO_SHT(DRV_NAME),
25265 };
25266
25267-static struct ata_port_operations mpiix_port_ops = {
25268+static const struct ata_port_operations mpiix_port_ops = {
25269 .inherits = &ata_sff_port_ops,
25270 .qc_issue = mpiix_qc_issue,
25271 .cable_detect = ata_cable_40wire,
25272diff -urNp linux-2.6.32.44/drivers/ata/pata_netcell.c linux-2.6.32.44/drivers/ata/pata_netcell.c
25273--- linux-2.6.32.44/drivers/ata/pata_netcell.c 2011-03-27 14:31:47.000000000 -0400
25274+++ linux-2.6.32.44/drivers/ata/pata_netcell.c 2011-04-17 15:56:46.000000000 -0400
25275@@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25276 ATA_BMDMA_SHT(DRV_NAME),
25277 };
25278
25279-static struct ata_port_operations netcell_ops = {
25280+static const struct ata_port_operations netcell_ops = {
25281 .inherits = &ata_bmdma_port_ops,
25282 .cable_detect = ata_cable_80wire,
25283 .read_id = netcell_read_id,
25284diff -urNp linux-2.6.32.44/drivers/ata/pata_ninja32.c linux-2.6.32.44/drivers/ata/pata_ninja32.c
25285--- linux-2.6.32.44/drivers/ata/pata_ninja32.c 2011-03-27 14:31:47.000000000 -0400
25286+++ linux-2.6.32.44/drivers/ata/pata_ninja32.c 2011-04-17 15:56:46.000000000 -0400
25287@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25288 ATA_BMDMA_SHT(DRV_NAME),
25289 };
25290
25291-static struct ata_port_operations ninja32_port_ops = {
25292+static const struct ata_port_operations ninja32_port_ops = {
25293 .inherits = &ata_bmdma_port_ops,
25294 .sff_dev_select = ninja32_dev_select,
25295 .cable_detect = ata_cable_40wire,
25296diff -urNp linux-2.6.32.44/drivers/ata/pata_ns87410.c linux-2.6.32.44/drivers/ata/pata_ns87410.c
25297--- linux-2.6.32.44/drivers/ata/pata_ns87410.c 2011-03-27 14:31:47.000000000 -0400
25298+++ linux-2.6.32.44/drivers/ata/pata_ns87410.c 2011-04-17 15:56:46.000000000 -0400
25299@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25300 ATA_PIO_SHT(DRV_NAME),
25301 };
25302
25303-static struct ata_port_operations ns87410_port_ops = {
25304+static const struct ata_port_operations ns87410_port_ops = {
25305 .inherits = &ata_sff_port_ops,
25306 .qc_issue = ns87410_qc_issue,
25307 .cable_detect = ata_cable_40wire,
25308diff -urNp linux-2.6.32.44/drivers/ata/pata_ns87415.c linux-2.6.32.44/drivers/ata/pata_ns87415.c
25309--- linux-2.6.32.44/drivers/ata/pata_ns87415.c 2011-03-27 14:31:47.000000000 -0400
25310+++ linux-2.6.32.44/drivers/ata/pata_ns87415.c 2011-04-17 15:56:46.000000000 -0400
25311@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25312 }
25313 #endif /* 87560 SuperIO Support */
25314
25315-static struct ata_port_operations ns87415_pata_ops = {
25316+static const struct ata_port_operations ns87415_pata_ops = {
25317 .inherits = &ata_bmdma_port_ops,
25318
25319 .check_atapi_dma = ns87415_check_atapi_dma,
25320@@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25321 };
25322
25323 #if defined(CONFIG_SUPERIO)
25324-static struct ata_port_operations ns87560_pata_ops = {
25325+static const struct ata_port_operations ns87560_pata_ops = {
25326 .inherits = &ns87415_pata_ops,
25327 .sff_tf_read = ns87560_tf_read,
25328 .sff_check_status = ns87560_check_status,
25329diff -urNp linux-2.6.32.44/drivers/ata/pata_octeon_cf.c linux-2.6.32.44/drivers/ata/pata_octeon_cf.c
25330--- linux-2.6.32.44/drivers/ata/pata_octeon_cf.c 2011-03-27 14:31:47.000000000 -0400
25331+++ linux-2.6.32.44/drivers/ata/pata_octeon_cf.c 2011-04-17 15:56:46.000000000 -0400
25332@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(s
25333 return 0;
25334 }
25335
25336+/* cannot be const */
25337 static struct ata_port_operations octeon_cf_ops = {
25338 .inherits = &ata_sff_port_ops,
25339 .check_atapi_dma = octeon_cf_check_atapi_dma,
25340diff -urNp linux-2.6.32.44/drivers/ata/pata_oldpiix.c linux-2.6.32.44/drivers/ata/pata_oldpiix.c
25341--- linux-2.6.32.44/drivers/ata/pata_oldpiix.c 2011-03-27 14:31:47.000000000 -0400
25342+++ linux-2.6.32.44/drivers/ata/pata_oldpiix.c 2011-04-17 15:56:46.000000000 -0400
25343@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25344 ATA_BMDMA_SHT(DRV_NAME),
25345 };
25346
25347-static struct ata_port_operations oldpiix_pata_ops = {
25348+static const struct ata_port_operations oldpiix_pata_ops = {
25349 .inherits = &ata_bmdma_port_ops,
25350 .qc_issue = oldpiix_qc_issue,
25351 .cable_detect = ata_cable_40wire,
25352diff -urNp linux-2.6.32.44/drivers/ata/pata_opti.c linux-2.6.32.44/drivers/ata/pata_opti.c
25353--- linux-2.6.32.44/drivers/ata/pata_opti.c 2011-03-27 14:31:47.000000000 -0400
25354+++ linux-2.6.32.44/drivers/ata/pata_opti.c 2011-04-17 15:56:46.000000000 -0400
25355@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25356 ATA_PIO_SHT(DRV_NAME),
25357 };
25358
25359-static struct ata_port_operations opti_port_ops = {
25360+static const struct ata_port_operations opti_port_ops = {
25361 .inherits = &ata_sff_port_ops,
25362 .cable_detect = ata_cable_40wire,
25363 .set_piomode = opti_set_piomode,
25364diff -urNp linux-2.6.32.44/drivers/ata/pata_optidma.c linux-2.6.32.44/drivers/ata/pata_optidma.c
25365--- linux-2.6.32.44/drivers/ata/pata_optidma.c 2011-03-27 14:31:47.000000000 -0400
25366+++ linux-2.6.32.44/drivers/ata/pata_optidma.c 2011-04-17 15:56:46.000000000 -0400
25367@@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25368 ATA_BMDMA_SHT(DRV_NAME),
25369 };
25370
25371-static struct ata_port_operations optidma_port_ops = {
25372+static const struct ata_port_operations optidma_port_ops = {
25373 .inherits = &ata_bmdma_port_ops,
25374 .cable_detect = ata_cable_40wire,
25375 .set_piomode = optidma_set_pio_mode,
25376@@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25377 .prereset = optidma_pre_reset,
25378 };
25379
25380-static struct ata_port_operations optiplus_port_ops = {
25381+static const struct ata_port_operations optiplus_port_ops = {
25382 .inherits = &optidma_port_ops,
25383 .set_piomode = optiplus_set_pio_mode,
25384 .set_dmamode = optiplus_set_dma_mode,
25385diff -urNp linux-2.6.32.44/drivers/ata/pata_palmld.c linux-2.6.32.44/drivers/ata/pata_palmld.c
25386--- linux-2.6.32.44/drivers/ata/pata_palmld.c 2011-03-27 14:31:47.000000000 -0400
25387+++ linux-2.6.32.44/drivers/ata/pata_palmld.c 2011-04-17 15:56:46.000000000 -0400
25388@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_
25389 ATA_PIO_SHT(DRV_NAME),
25390 };
25391
25392-static struct ata_port_operations palmld_port_ops = {
25393+static const struct ata_port_operations palmld_port_ops = {
25394 .inherits = &ata_sff_port_ops,
25395 .sff_data_xfer = ata_sff_data_xfer_noirq,
25396 .cable_detect = ata_cable_40wire,
25397diff -urNp linux-2.6.32.44/drivers/ata/pata_pcmcia.c linux-2.6.32.44/drivers/ata/pata_pcmcia.c
25398--- linux-2.6.32.44/drivers/ata/pata_pcmcia.c 2011-03-27 14:31:47.000000000 -0400
25399+++ linux-2.6.32.44/drivers/ata/pata_pcmcia.c 2011-04-17 15:56:46.000000000 -0400
25400@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_
25401 ATA_PIO_SHT(DRV_NAME),
25402 };
25403
25404-static struct ata_port_operations pcmcia_port_ops = {
25405+static const struct ata_port_operations pcmcia_port_ops = {
25406 .inherits = &ata_sff_port_ops,
25407 .sff_data_xfer = ata_sff_data_xfer_noirq,
25408 .cable_detect = ata_cable_40wire,
25409 .set_mode = pcmcia_set_mode,
25410 };
25411
25412-static struct ata_port_operations pcmcia_8bit_port_ops = {
25413+static const struct ata_port_operations pcmcia_8bit_port_ops = {
25414 .inherits = &ata_sff_port_ops,
25415 .sff_data_xfer = ata_data_xfer_8bit,
25416 .cable_detect = ata_cable_40wire,
25417@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia
25418 unsigned long io_base, ctl_base;
25419 void __iomem *io_addr, *ctl_addr;
25420 int n_ports = 1;
25421- struct ata_port_operations *ops = &pcmcia_port_ops;
25422+ const struct ata_port_operations *ops = &pcmcia_port_ops;
25423
25424 info = kzalloc(sizeof(*info), GFP_KERNEL);
25425 if (info == NULL)
25426diff -urNp linux-2.6.32.44/drivers/ata/pata_pdc2027x.c linux-2.6.32.44/drivers/ata/pata_pdc2027x.c
25427--- linux-2.6.32.44/drivers/ata/pata_pdc2027x.c 2011-03-27 14:31:47.000000000 -0400
25428+++ linux-2.6.32.44/drivers/ata/pata_pdc2027x.c 2011-04-17 15:56:46.000000000 -0400
25429@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25430 ATA_BMDMA_SHT(DRV_NAME),
25431 };
25432
25433-static struct ata_port_operations pdc2027x_pata100_ops = {
25434+static const struct ata_port_operations pdc2027x_pata100_ops = {
25435 .inherits = &ata_bmdma_port_ops,
25436 .check_atapi_dma = pdc2027x_check_atapi_dma,
25437 .cable_detect = pdc2027x_cable_detect,
25438 .prereset = pdc2027x_prereset,
25439 };
25440
25441-static struct ata_port_operations pdc2027x_pata133_ops = {
25442+static const struct ata_port_operations pdc2027x_pata133_ops = {
25443 .inherits = &pdc2027x_pata100_ops,
25444 .mode_filter = pdc2027x_mode_filter,
25445 .set_piomode = pdc2027x_set_piomode,
25446diff -urNp linux-2.6.32.44/drivers/ata/pata_pdc202xx_old.c linux-2.6.32.44/drivers/ata/pata_pdc202xx_old.c
25447--- linux-2.6.32.44/drivers/ata/pata_pdc202xx_old.c 2011-03-27 14:31:47.000000000 -0400
25448+++ linux-2.6.32.44/drivers/ata/pata_pdc202xx_old.c 2011-04-17 15:56:46.000000000 -0400
25449@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202x
25450 ATA_BMDMA_SHT(DRV_NAME),
25451 };
25452
25453-static struct ata_port_operations pdc2024x_port_ops = {
25454+static const struct ata_port_operations pdc2024x_port_ops = {
25455 .inherits = &ata_bmdma_port_ops,
25456
25457 .cable_detect = ata_cable_40wire,
25458@@ -284,7 +284,7 @@ static struct ata_port_operations pdc202
25459 .sff_exec_command = pdc202xx_exec_command,
25460 };
25461
25462-static struct ata_port_operations pdc2026x_port_ops = {
25463+static const struct ata_port_operations pdc2026x_port_ops = {
25464 .inherits = &pdc2024x_port_ops,
25465
25466 .check_atapi_dma = pdc2026x_check_atapi_dma,
25467diff -urNp linux-2.6.32.44/drivers/ata/pata_platform.c linux-2.6.32.44/drivers/ata/pata_platform.c
25468--- linux-2.6.32.44/drivers/ata/pata_platform.c 2011-03-27 14:31:47.000000000 -0400
25469+++ linux-2.6.32.44/drivers/ata/pata_platform.c 2011-04-17 15:56:46.000000000 -0400
25470@@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25471 ATA_PIO_SHT(DRV_NAME),
25472 };
25473
25474-static struct ata_port_operations pata_platform_port_ops = {
25475+static const struct ata_port_operations pata_platform_port_ops = {
25476 .inherits = &ata_sff_port_ops,
25477 .sff_data_xfer = ata_sff_data_xfer_noirq,
25478 .cable_detect = ata_cable_unknown,
25479diff -urNp linux-2.6.32.44/drivers/ata/pata_qdi.c linux-2.6.32.44/drivers/ata/pata_qdi.c
25480--- linux-2.6.32.44/drivers/ata/pata_qdi.c 2011-03-27 14:31:47.000000000 -0400
25481+++ linux-2.6.32.44/drivers/ata/pata_qdi.c 2011-04-17 15:56:46.000000000 -0400
25482@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25483 ATA_PIO_SHT(DRV_NAME),
25484 };
25485
25486-static struct ata_port_operations qdi6500_port_ops = {
25487+static const struct ata_port_operations qdi6500_port_ops = {
25488 .inherits = &ata_sff_port_ops,
25489 .qc_issue = qdi_qc_issue,
25490 .sff_data_xfer = qdi_data_xfer,
25491@@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
25492 .set_piomode = qdi6500_set_piomode,
25493 };
25494
25495-static struct ata_port_operations qdi6580_port_ops = {
25496+static const struct ata_port_operations qdi6580_port_ops = {
25497 .inherits = &qdi6500_port_ops,
25498 .set_piomode = qdi6580_set_piomode,
25499 };
25500diff -urNp linux-2.6.32.44/drivers/ata/pata_radisys.c linux-2.6.32.44/drivers/ata/pata_radisys.c
25501--- linux-2.6.32.44/drivers/ata/pata_radisys.c 2011-03-27 14:31:47.000000000 -0400
25502+++ linux-2.6.32.44/drivers/ata/pata_radisys.c 2011-04-17 15:56:46.000000000 -0400
25503@@ -187,7 +187,7 @@ static struct scsi_host_template radisys
25504 ATA_BMDMA_SHT(DRV_NAME),
25505 };
25506
25507-static struct ata_port_operations radisys_pata_ops = {
25508+static const struct ata_port_operations radisys_pata_ops = {
25509 .inherits = &ata_bmdma_port_ops,
25510 .qc_issue = radisys_qc_issue,
25511 .cable_detect = ata_cable_unknown,
25512diff -urNp linux-2.6.32.44/drivers/ata/pata_rb532_cf.c linux-2.6.32.44/drivers/ata/pata_rb532_cf.c
25513--- linux-2.6.32.44/drivers/ata/pata_rb532_cf.c 2011-03-27 14:31:47.000000000 -0400
25514+++ linux-2.6.32.44/drivers/ata/pata_rb532_cf.c 2011-04-17 15:56:46.000000000 -0400
25515@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handle
25516 return IRQ_HANDLED;
25517 }
25518
25519-static struct ata_port_operations rb532_pata_port_ops = {
25520+static const struct ata_port_operations rb532_pata_port_ops = {
25521 .inherits = &ata_sff_port_ops,
25522 .sff_data_xfer = ata_sff_data_xfer32,
25523 };
25524diff -urNp linux-2.6.32.44/drivers/ata/pata_rdc.c linux-2.6.32.44/drivers/ata/pata_rdc.c
25525--- linux-2.6.32.44/drivers/ata/pata_rdc.c 2011-03-27 14:31:47.000000000 -0400
25526+++ linux-2.6.32.44/drivers/ata/pata_rdc.c 2011-04-17 15:56:46.000000000 -0400
25527@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_p
25528 pci_write_config_byte(dev, 0x48, udma_enable);
25529 }
25530
25531-static struct ata_port_operations rdc_pata_ops = {
25532+static const struct ata_port_operations rdc_pata_ops = {
25533 .inherits = &ata_bmdma32_port_ops,
25534 .cable_detect = rdc_pata_cable_detect,
25535 .set_piomode = rdc_set_piomode,
25536diff -urNp linux-2.6.32.44/drivers/ata/pata_rz1000.c linux-2.6.32.44/drivers/ata/pata_rz1000.c
25537--- linux-2.6.32.44/drivers/ata/pata_rz1000.c 2011-03-27 14:31:47.000000000 -0400
25538+++ linux-2.6.32.44/drivers/ata/pata_rz1000.c 2011-04-17 15:56:46.000000000 -0400
25539@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
25540 ATA_PIO_SHT(DRV_NAME),
25541 };
25542
25543-static struct ata_port_operations rz1000_port_ops = {
25544+static const struct ata_port_operations rz1000_port_ops = {
25545 .inherits = &ata_sff_port_ops,
25546 .cable_detect = ata_cable_40wire,
25547 .set_mode = rz1000_set_mode,
25548diff -urNp linux-2.6.32.44/drivers/ata/pata_sc1200.c linux-2.6.32.44/drivers/ata/pata_sc1200.c
25549--- linux-2.6.32.44/drivers/ata/pata_sc1200.c 2011-03-27 14:31:47.000000000 -0400
25550+++ linux-2.6.32.44/drivers/ata/pata_sc1200.c 2011-04-17 15:56:46.000000000 -0400
25551@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
25552 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25553 };
25554
25555-static struct ata_port_operations sc1200_port_ops = {
25556+static const struct ata_port_operations sc1200_port_ops = {
25557 .inherits = &ata_bmdma_port_ops,
25558 .qc_prep = ata_sff_dumb_qc_prep,
25559 .qc_issue = sc1200_qc_issue,
25560diff -urNp linux-2.6.32.44/drivers/ata/pata_scc.c linux-2.6.32.44/drivers/ata/pata_scc.c
25561--- linux-2.6.32.44/drivers/ata/pata_scc.c 2011-03-27 14:31:47.000000000 -0400
25562+++ linux-2.6.32.44/drivers/ata/pata_scc.c 2011-04-17 15:56:46.000000000 -0400
25563@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht
25564 ATA_BMDMA_SHT(DRV_NAME),
25565 };
25566
25567-static struct ata_port_operations scc_pata_ops = {
25568+static const struct ata_port_operations scc_pata_ops = {
25569 .inherits = &ata_bmdma_port_ops,
25570
25571 .set_piomode = scc_set_piomode,
25572diff -urNp linux-2.6.32.44/drivers/ata/pata_sch.c linux-2.6.32.44/drivers/ata/pata_sch.c
25573--- linux-2.6.32.44/drivers/ata/pata_sch.c 2011-03-27 14:31:47.000000000 -0400
25574+++ linux-2.6.32.44/drivers/ata/pata_sch.c 2011-04-17 15:56:46.000000000 -0400
25575@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
25576 ATA_BMDMA_SHT(DRV_NAME),
25577 };
25578
25579-static struct ata_port_operations sch_pata_ops = {
25580+static const struct ata_port_operations sch_pata_ops = {
25581 .inherits = &ata_bmdma_port_ops,
25582 .cable_detect = ata_cable_unknown,
25583 .set_piomode = sch_set_piomode,
25584diff -urNp linux-2.6.32.44/drivers/ata/pata_serverworks.c linux-2.6.32.44/drivers/ata/pata_serverworks.c
25585--- linux-2.6.32.44/drivers/ata/pata_serverworks.c 2011-03-27 14:31:47.000000000 -0400
25586+++ linux-2.6.32.44/drivers/ata/pata_serverworks.c 2011-04-17 15:56:46.000000000 -0400
25587@@ -299,7 +299,7 @@ static struct scsi_host_template serverw
25588 ATA_BMDMA_SHT(DRV_NAME),
25589 };
25590
25591-static struct ata_port_operations serverworks_osb4_port_ops = {
25592+static const struct ata_port_operations serverworks_osb4_port_ops = {
25593 .inherits = &ata_bmdma_port_ops,
25594 .cable_detect = serverworks_cable_detect,
25595 .mode_filter = serverworks_osb4_filter,
25596@@ -307,7 +307,7 @@ static struct ata_port_operations server
25597 .set_dmamode = serverworks_set_dmamode,
25598 };
25599
25600-static struct ata_port_operations serverworks_csb_port_ops = {
25601+static const struct ata_port_operations serverworks_csb_port_ops = {
25602 .inherits = &serverworks_osb4_port_ops,
25603 .mode_filter = serverworks_csb_filter,
25604 };
25605diff -urNp linux-2.6.32.44/drivers/ata/pata_sil680.c linux-2.6.32.44/drivers/ata/pata_sil680.c
25606--- linux-2.6.32.44/drivers/ata/pata_sil680.c 2011-06-25 12:55:34.000000000 -0400
25607+++ linux-2.6.32.44/drivers/ata/pata_sil680.c 2011-06-25 12:56:37.000000000 -0400
25608@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_
25609 ATA_BMDMA_SHT(DRV_NAME),
25610 };
25611
25612-static struct ata_port_operations sil680_port_ops = {
25613+static const struct ata_port_operations sil680_port_ops = {
25614 .inherits = &ata_bmdma32_port_ops,
25615 .cable_detect = sil680_cable_detect,
25616 .set_piomode = sil680_set_piomode,
25617diff -urNp linux-2.6.32.44/drivers/ata/pata_sis.c linux-2.6.32.44/drivers/ata/pata_sis.c
25618--- linux-2.6.32.44/drivers/ata/pata_sis.c 2011-03-27 14:31:47.000000000 -0400
25619+++ linux-2.6.32.44/drivers/ata/pata_sis.c 2011-04-17 15:56:46.000000000 -0400
25620@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
25621 ATA_BMDMA_SHT(DRV_NAME),
25622 };
25623
25624-static struct ata_port_operations sis_133_for_sata_ops = {
25625+static const struct ata_port_operations sis_133_for_sata_ops = {
25626 .inherits = &ata_bmdma_port_ops,
25627 .set_piomode = sis_133_set_piomode,
25628 .set_dmamode = sis_133_set_dmamode,
25629 .cable_detect = sis_133_cable_detect,
25630 };
25631
25632-static struct ata_port_operations sis_base_ops = {
25633+static const struct ata_port_operations sis_base_ops = {
25634 .inherits = &ata_bmdma_port_ops,
25635 .prereset = sis_pre_reset,
25636 };
25637
25638-static struct ata_port_operations sis_133_ops = {
25639+static const struct ata_port_operations sis_133_ops = {
25640 .inherits = &sis_base_ops,
25641 .set_piomode = sis_133_set_piomode,
25642 .set_dmamode = sis_133_set_dmamode,
25643 .cable_detect = sis_133_cable_detect,
25644 };
25645
25646-static struct ata_port_operations sis_133_early_ops = {
25647+static const struct ata_port_operations sis_133_early_ops = {
25648 .inherits = &sis_base_ops,
25649 .set_piomode = sis_100_set_piomode,
25650 .set_dmamode = sis_133_early_set_dmamode,
25651 .cable_detect = sis_66_cable_detect,
25652 };
25653
25654-static struct ata_port_operations sis_100_ops = {
25655+static const struct ata_port_operations sis_100_ops = {
25656 .inherits = &sis_base_ops,
25657 .set_piomode = sis_100_set_piomode,
25658 .set_dmamode = sis_100_set_dmamode,
25659 .cable_detect = sis_66_cable_detect,
25660 };
25661
25662-static struct ata_port_operations sis_66_ops = {
25663+static const struct ata_port_operations sis_66_ops = {
25664 .inherits = &sis_base_ops,
25665 .set_piomode = sis_old_set_piomode,
25666 .set_dmamode = sis_66_set_dmamode,
25667 .cable_detect = sis_66_cable_detect,
25668 };
25669
25670-static struct ata_port_operations sis_old_ops = {
25671+static const struct ata_port_operations sis_old_ops = {
25672 .inherits = &sis_base_ops,
25673 .set_piomode = sis_old_set_piomode,
25674 .set_dmamode = sis_old_set_dmamode,
25675diff -urNp linux-2.6.32.44/drivers/ata/pata_sl82c105.c linux-2.6.32.44/drivers/ata/pata_sl82c105.c
25676--- linux-2.6.32.44/drivers/ata/pata_sl82c105.c 2011-03-27 14:31:47.000000000 -0400
25677+++ linux-2.6.32.44/drivers/ata/pata_sl82c105.c 2011-04-17 15:56:46.000000000 -0400
25678@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c10
25679 ATA_BMDMA_SHT(DRV_NAME),
25680 };
25681
25682-static struct ata_port_operations sl82c105_port_ops = {
25683+static const struct ata_port_operations sl82c105_port_ops = {
25684 .inherits = &ata_bmdma_port_ops,
25685 .qc_defer = sl82c105_qc_defer,
25686 .bmdma_start = sl82c105_bmdma_start,
25687diff -urNp linux-2.6.32.44/drivers/ata/pata_triflex.c linux-2.6.32.44/drivers/ata/pata_triflex.c
25688--- linux-2.6.32.44/drivers/ata/pata_triflex.c 2011-03-27 14:31:47.000000000 -0400
25689+++ linux-2.6.32.44/drivers/ata/pata_triflex.c 2011-04-17 15:56:46.000000000 -0400
25690@@ -178,7 +178,7 @@ static struct scsi_host_template triflex
25691 ATA_BMDMA_SHT(DRV_NAME),
25692 };
25693
25694-static struct ata_port_operations triflex_port_ops = {
25695+static const struct ata_port_operations triflex_port_ops = {
25696 .inherits = &ata_bmdma_port_ops,
25697 .bmdma_start = triflex_bmdma_start,
25698 .bmdma_stop = triflex_bmdma_stop,
25699diff -urNp linux-2.6.32.44/drivers/ata/pata_via.c linux-2.6.32.44/drivers/ata/pata_via.c
25700--- linux-2.6.32.44/drivers/ata/pata_via.c 2011-03-27 14:31:47.000000000 -0400
25701+++ linux-2.6.32.44/drivers/ata/pata_via.c 2011-04-17 15:56:46.000000000 -0400
25702@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht
25703 ATA_BMDMA_SHT(DRV_NAME),
25704 };
25705
25706-static struct ata_port_operations via_port_ops = {
25707+static const struct ata_port_operations via_port_ops = {
25708 .inherits = &ata_bmdma_port_ops,
25709 .cable_detect = via_cable_detect,
25710 .set_piomode = via_set_piomode,
25711@@ -429,7 +429,7 @@ static struct ata_port_operations via_po
25712 .port_start = via_port_start,
25713 };
25714
25715-static struct ata_port_operations via_port_ops_noirq = {
25716+static const struct ata_port_operations via_port_ops_noirq = {
25717 .inherits = &via_port_ops,
25718 .sff_data_xfer = ata_sff_data_xfer_noirq,
25719 };
25720diff -urNp linux-2.6.32.44/drivers/ata/pata_winbond.c linux-2.6.32.44/drivers/ata/pata_winbond.c
25721--- linux-2.6.32.44/drivers/ata/pata_winbond.c 2011-03-27 14:31:47.000000000 -0400
25722+++ linux-2.6.32.44/drivers/ata/pata_winbond.c 2011-04-17 15:56:46.000000000 -0400
25723@@ -125,7 +125,7 @@ static struct scsi_host_template winbond
25724 ATA_PIO_SHT(DRV_NAME),
25725 };
25726
25727-static struct ata_port_operations winbond_port_ops = {
25728+static const struct ata_port_operations winbond_port_ops = {
25729 .inherits = &ata_sff_port_ops,
25730 .sff_data_xfer = winbond_data_xfer,
25731 .cable_detect = ata_cable_40wire,
25732diff -urNp linux-2.6.32.44/drivers/ata/pdc_adma.c linux-2.6.32.44/drivers/ata/pdc_adma.c
25733--- linux-2.6.32.44/drivers/ata/pdc_adma.c 2011-03-27 14:31:47.000000000 -0400
25734+++ linux-2.6.32.44/drivers/ata/pdc_adma.c 2011-04-17 15:56:46.000000000 -0400
25735@@ -145,7 +145,7 @@ static struct scsi_host_template adma_at
25736 .dma_boundary = ADMA_DMA_BOUNDARY,
25737 };
25738
25739-static struct ata_port_operations adma_ata_ops = {
25740+static const struct ata_port_operations adma_ata_ops = {
25741 .inherits = &ata_sff_port_ops,
25742
25743 .lost_interrupt = ATA_OP_NULL,
25744diff -urNp linux-2.6.32.44/drivers/ata/sata_fsl.c linux-2.6.32.44/drivers/ata/sata_fsl.c
25745--- linux-2.6.32.44/drivers/ata/sata_fsl.c 2011-03-27 14:31:47.000000000 -0400
25746+++ linux-2.6.32.44/drivers/ata/sata_fsl.c 2011-04-17 15:56:46.000000000 -0400
25747@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fs
25748 .dma_boundary = ATA_DMA_BOUNDARY,
25749 };
25750
25751-static struct ata_port_operations sata_fsl_ops = {
25752+static const struct ata_port_operations sata_fsl_ops = {
25753 .inherits = &sata_pmp_port_ops,
25754
25755 .qc_defer = ata_std_qc_defer,
25756diff -urNp linux-2.6.32.44/drivers/ata/sata_inic162x.c linux-2.6.32.44/drivers/ata/sata_inic162x.c
25757--- linux-2.6.32.44/drivers/ata/sata_inic162x.c 2011-03-27 14:31:47.000000000 -0400
25758+++ linux-2.6.32.44/drivers/ata/sata_inic162x.c 2011-04-17 15:56:46.000000000 -0400
25759@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_po
25760 return 0;
25761 }
25762
25763-static struct ata_port_operations inic_port_ops = {
25764+static const struct ata_port_operations inic_port_ops = {
25765 .inherits = &sata_port_ops,
25766
25767 .check_atapi_dma = inic_check_atapi_dma,
25768diff -urNp linux-2.6.32.44/drivers/ata/sata_mv.c linux-2.6.32.44/drivers/ata/sata_mv.c
25769--- linux-2.6.32.44/drivers/ata/sata_mv.c 2011-03-27 14:31:47.000000000 -0400
25770+++ linux-2.6.32.44/drivers/ata/sata_mv.c 2011-04-17 15:56:46.000000000 -0400
25771@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht
25772 .dma_boundary = MV_DMA_BOUNDARY,
25773 };
25774
25775-static struct ata_port_operations mv5_ops = {
25776+static const struct ata_port_operations mv5_ops = {
25777 .inherits = &ata_sff_port_ops,
25778
25779 .lost_interrupt = ATA_OP_NULL,
25780@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_op
25781 .port_stop = mv_port_stop,
25782 };
25783
25784-static struct ata_port_operations mv6_ops = {
25785+static const struct ata_port_operations mv6_ops = {
25786 .inherits = &mv5_ops,
25787 .dev_config = mv6_dev_config,
25788 .scr_read = mv_scr_read,
25789@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_op
25790 .bmdma_status = mv_bmdma_status,
25791 };
25792
25793-static struct ata_port_operations mv_iie_ops = {
25794+static const struct ata_port_operations mv_iie_ops = {
25795 .inherits = &mv6_ops,
25796 .dev_config = ATA_OP_NULL,
25797 .qc_prep = mv_qc_prep_iie,
25798diff -urNp linux-2.6.32.44/drivers/ata/sata_nv.c linux-2.6.32.44/drivers/ata/sata_nv.c
25799--- linux-2.6.32.44/drivers/ata/sata_nv.c 2011-03-27 14:31:47.000000000 -0400
25800+++ linux-2.6.32.44/drivers/ata/sata_nv.c 2011-04-17 15:56:46.000000000 -0400
25801@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swnc
25802 * cases. Define nv_hardreset() which only kicks in for post-boot
25803 * probing and use it for all variants.
25804 */
25805-static struct ata_port_operations nv_generic_ops = {
25806+static const struct ata_port_operations nv_generic_ops = {
25807 .inherits = &ata_bmdma_port_ops,
25808 .lost_interrupt = ATA_OP_NULL,
25809 .scr_read = nv_scr_read,
25810@@ -472,20 +472,20 @@ static struct ata_port_operations nv_gen
25811 .hardreset = nv_hardreset,
25812 };
25813
25814-static struct ata_port_operations nv_nf2_ops = {
25815+static const struct ata_port_operations nv_nf2_ops = {
25816 .inherits = &nv_generic_ops,
25817 .freeze = nv_nf2_freeze,
25818 .thaw = nv_nf2_thaw,
25819 };
25820
25821-static struct ata_port_operations nv_ck804_ops = {
25822+static const struct ata_port_operations nv_ck804_ops = {
25823 .inherits = &nv_generic_ops,
25824 .freeze = nv_ck804_freeze,
25825 .thaw = nv_ck804_thaw,
25826 .host_stop = nv_ck804_host_stop,
25827 };
25828
25829-static struct ata_port_operations nv_adma_ops = {
25830+static const struct ata_port_operations nv_adma_ops = {
25831 .inherits = &nv_ck804_ops,
25832
25833 .check_atapi_dma = nv_adma_check_atapi_dma,
25834@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adm
25835 .host_stop = nv_adma_host_stop,
25836 };
25837
25838-static struct ata_port_operations nv_swncq_ops = {
25839+static const struct ata_port_operations nv_swncq_ops = {
25840 .inherits = &nv_generic_ops,
25841
25842 .qc_defer = ata_std_qc_defer,
25843diff -urNp linux-2.6.32.44/drivers/ata/sata_promise.c linux-2.6.32.44/drivers/ata/sata_promise.c
25844--- linux-2.6.32.44/drivers/ata/sata_promise.c 2011-03-27 14:31:47.000000000 -0400
25845+++ linux-2.6.32.44/drivers/ata/sata_promise.c 2011-04-17 15:56:46.000000000 -0400
25846@@ -195,7 +195,7 @@ static const struct ata_port_operations
25847 .error_handler = pdc_error_handler,
25848 };
25849
25850-static struct ata_port_operations pdc_sata_ops = {
25851+static const struct ata_port_operations pdc_sata_ops = {
25852 .inherits = &pdc_common_ops,
25853 .cable_detect = pdc_sata_cable_detect,
25854 .freeze = pdc_sata_freeze,
25855@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sa
25856
25857 /* First-generation chips need a more restrictive ->check_atapi_dma op,
25858 and ->freeze/thaw that ignore the hotplug controls. */
25859-static struct ata_port_operations pdc_old_sata_ops = {
25860+static const struct ata_port_operations pdc_old_sata_ops = {
25861 .inherits = &pdc_sata_ops,
25862 .freeze = pdc_freeze,
25863 .thaw = pdc_thaw,
25864 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
25865 };
25866
25867-static struct ata_port_operations pdc_pata_ops = {
25868+static const struct ata_port_operations pdc_pata_ops = {
25869 .inherits = &pdc_common_ops,
25870 .cable_detect = pdc_pata_cable_detect,
25871 .freeze = pdc_freeze,
25872diff -urNp linux-2.6.32.44/drivers/ata/sata_qstor.c linux-2.6.32.44/drivers/ata/sata_qstor.c
25873--- linux-2.6.32.44/drivers/ata/sata_qstor.c 2011-03-27 14:31:47.000000000 -0400
25874+++ linux-2.6.32.44/drivers/ata/sata_qstor.c 2011-04-17 15:56:46.000000000 -0400
25875@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_
25876 .dma_boundary = QS_DMA_BOUNDARY,
25877 };
25878
25879-static struct ata_port_operations qs_ata_ops = {
25880+static const struct ata_port_operations qs_ata_ops = {
25881 .inherits = &ata_sff_port_ops,
25882
25883 .check_atapi_dma = qs_check_atapi_dma,
25884diff -urNp linux-2.6.32.44/drivers/ata/sata_sil24.c linux-2.6.32.44/drivers/ata/sata_sil24.c
25885--- linux-2.6.32.44/drivers/ata/sata_sil24.c 2011-03-27 14:31:47.000000000 -0400
25886+++ linux-2.6.32.44/drivers/ata/sata_sil24.c 2011-04-17 15:56:46.000000000 -0400
25887@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
25888 .dma_boundary = ATA_DMA_BOUNDARY,
25889 };
25890
25891-static struct ata_port_operations sil24_ops = {
25892+static const struct ata_port_operations sil24_ops = {
25893 .inherits = &sata_pmp_port_ops,
25894
25895 .qc_defer = sil24_qc_defer,
25896diff -urNp linux-2.6.32.44/drivers/ata/sata_sil.c linux-2.6.32.44/drivers/ata/sata_sil.c
25897--- linux-2.6.32.44/drivers/ata/sata_sil.c 2011-03-27 14:31:47.000000000 -0400
25898+++ linux-2.6.32.44/drivers/ata/sata_sil.c 2011-04-17 15:56:46.000000000 -0400
25899@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht
25900 .sg_tablesize = ATA_MAX_PRD
25901 };
25902
25903-static struct ata_port_operations sil_ops = {
25904+static const struct ata_port_operations sil_ops = {
25905 .inherits = &ata_bmdma32_port_ops,
25906 .dev_config = sil_dev_config,
25907 .set_mode = sil_set_mode,
25908diff -urNp linux-2.6.32.44/drivers/ata/sata_sis.c linux-2.6.32.44/drivers/ata/sata_sis.c
25909--- linux-2.6.32.44/drivers/ata/sata_sis.c 2011-03-27 14:31:47.000000000 -0400
25910+++ linux-2.6.32.44/drivers/ata/sata_sis.c 2011-04-17 15:56:46.000000000 -0400
25911@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
25912 ATA_BMDMA_SHT(DRV_NAME),
25913 };
25914
25915-static struct ata_port_operations sis_ops = {
25916+static const struct ata_port_operations sis_ops = {
25917 .inherits = &ata_bmdma_port_ops,
25918 .scr_read = sis_scr_read,
25919 .scr_write = sis_scr_write,
25920diff -urNp linux-2.6.32.44/drivers/ata/sata_svw.c linux-2.6.32.44/drivers/ata/sata_svw.c
25921--- linux-2.6.32.44/drivers/ata/sata_svw.c 2011-03-27 14:31:47.000000000 -0400
25922+++ linux-2.6.32.44/drivers/ata/sata_svw.c 2011-04-17 15:56:46.000000000 -0400
25923@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
25924 };
25925
25926
25927-static struct ata_port_operations k2_sata_ops = {
25928+static const struct ata_port_operations k2_sata_ops = {
25929 .inherits = &ata_bmdma_port_ops,
25930 .sff_tf_load = k2_sata_tf_load,
25931 .sff_tf_read = k2_sata_tf_read,
25932diff -urNp linux-2.6.32.44/drivers/ata/sata_sx4.c linux-2.6.32.44/drivers/ata/sata_sx4.c
25933--- linux-2.6.32.44/drivers/ata/sata_sx4.c 2011-03-27 14:31:47.000000000 -0400
25934+++ linux-2.6.32.44/drivers/ata/sata_sx4.c 2011-04-17 15:56:46.000000000 -0400
25935@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sat
25936 };
25937
25938 /* TODO: inherit from base port_ops after converting to new EH */
25939-static struct ata_port_operations pdc_20621_ops = {
25940+static const struct ata_port_operations pdc_20621_ops = {
25941 .inherits = &ata_sff_port_ops,
25942
25943 .check_atapi_dma = pdc_check_atapi_dma,
25944diff -urNp linux-2.6.32.44/drivers/ata/sata_uli.c linux-2.6.32.44/drivers/ata/sata_uli.c
25945--- linux-2.6.32.44/drivers/ata/sata_uli.c 2011-03-27 14:31:47.000000000 -0400
25946+++ linux-2.6.32.44/drivers/ata/sata_uli.c 2011-04-17 15:56:46.000000000 -0400
25947@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht
25948 ATA_BMDMA_SHT(DRV_NAME),
25949 };
25950
25951-static struct ata_port_operations uli_ops = {
25952+static const struct ata_port_operations uli_ops = {
25953 .inherits = &ata_bmdma_port_ops,
25954 .scr_read = uli_scr_read,
25955 .scr_write = uli_scr_write,
25956diff -urNp linux-2.6.32.44/drivers/ata/sata_via.c linux-2.6.32.44/drivers/ata/sata_via.c
25957--- linux-2.6.32.44/drivers/ata/sata_via.c 2011-05-10 22:12:01.000000000 -0400
25958+++ linux-2.6.32.44/drivers/ata/sata_via.c 2011-05-10 22:15:08.000000000 -0400
25959@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
25960 ATA_BMDMA_SHT(DRV_NAME),
25961 };
25962
25963-static struct ata_port_operations svia_base_ops = {
25964+static const struct ata_port_operations svia_base_ops = {
25965 .inherits = &ata_bmdma_port_ops,
25966 .sff_tf_load = svia_tf_load,
25967 };
25968
25969-static struct ata_port_operations vt6420_sata_ops = {
25970+static const struct ata_port_operations vt6420_sata_ops = {
25971 .inherits = &svia_base_ops,
25972 .freeze = svia_noop_freeze,
25973 .prereset = vt6420_prereset,
25974 .bmdma_start = vt6420_bmdma_start,
25975 };
25976
25977-static struct ata_port_operations vt6421_pata_ops = {
25978+static const struct ata_port_operations vt6421_pata_ops = {
25979 .inherits = &svia_base_ops,
25980 .cable_detect = vt6421_pata_cable_detect,
25981 .set_piomode = vt6421_set_pio_mode,
25982 .set_dmamode = vt6421_set_dma_mode,
25983 };
25984
25985-static struct ata_port_operations vt6421_sata_ops = {
25986+static const struct ata_port_operations vt6421_sata_ops = {
25987 .inherits = &svia_base_ops,
25988 .scr_read = svia_scr_read,
25989 .scr_write = svia_scr_write,
25990 };
25991
25992-static struct ata_port_operations vt8251_ops = {
25993+static const struct ata_port_operations vt8251_ops = {
25994 .inherits = &svia_base_ops,
25995 .hardreset = sata_std_hardreset,
25996 .scr_read = vt8251_scr_read,
25997diff -urNp linux-2.6.32.44/drivers/ata/sata_vsc.c linux-2.6.32.44/drivers/ata/sata_vsc.c
25998--- linux-2.6.32.44/drivers/ata/sata_vsc.c 2011-03-27 14:31:47.000000000 -0400
25999+++ linux-2.6.32.44/drivers/ata/sata_vsc.c 2011-04-17 15:56:46.000000000 -0400
26000@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sat
26001 };
26002
26003
26004-static struct ata_port_operations vsc_sata_ops = {
26005+static const struct ata_port_operations vsc_sata_ops = {
26006 .inherits = &ata_bmdma_port_ops,
26007 /* The IRQ handling is not quite standard SFF behaviour so we
26008 cannot use the default lost interrupt handler */
26009diff -urNp linux-2.6.32.44/drivers/atm/adummy.c linux-2.6.32.44/drivers/atm/adummy.c
26010--- linux-2.6.32.44/drivers/atm/adummy.c 2011-03-27 14:31:47.000000000 -0400
26011+++ linux-2.6.32.44/drivers/atm/adummy.c 2011-04-17 15:56:46.000000000 -0400
26012@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct
26013 vcc->pop(vcc, skb);
26014 else
26015 dev_kfree_skb_any(skb);
26016- atomic_inc(&vcc->stats->tx);
26017+ atomic_inc_unchecked(&vcc->stats->tx);
26018
26019 return 0;
26020 }
26021diff -urNp linux-2.6.32.44/drivers/atm/ambassador.c linux-2.6.32.44/drivers/atm/ambassador.c
26022--- linux-2.6.32.44/drivers/atm/ambassador.c 2011-03-27 14:31:47.000000000 -0400
26023+++ linux-2.6.32.44/drivers/atm/ambassador.c 2011-04-17 15:56:46.000000000 -0400
26024@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev,
26025 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26026
26027 // VC layer stats
26028- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26029+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26030
26031 // free the descriptor
26032 kfree (tx_descr);
26033@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev,
26034 dump_skb ("<<<", vc, skb);
26035
26036 // VC layer stats
26037- atomic_inc(&atm_vcc->stats->rx);
26038+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26039 __net_timestamp(skb);
26040 // end of our responsability
26041 atm_vcc->push (atm_vcc, skb);
26042@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev,
26043 } else {
26044 PRINTK (KERN_INFO, "dropped over-size frame");
26045 // should we count this?
26046- atomic_inc(&atm_vcc->stats->rx_drop);
26047+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26048 }
26049
26050 } else {
26051@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * at
26052 }
26053
26054 if (check_area (skb->data, skb->len)) {
26055- atomic_inc(&atm_vcc->stats->tx_err);
26056+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26057 return -ENOMEM; // ?
26058 }
26059
26060diff -urNp linux-2.6.32.44/drivers/atm/atmtcp.c linux-2.6.32.44/drivers/atm/atmtcp.c
26061--- linux-2.6.32.44/drivers/atm/atmtcp.c 2011-03-27 14:31:47.000000000 -0400
26062+++ linux-2.6.32.44/drivers/atm/atmtcp.c 2011-04-17 15:56:46.000000000 -0400
26063@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc
26064 if (vcc->pop) vcc->pop(vcc,skb);
26065 else dev_kfree_skb(skb);
26066 if (dev_data) return 0;
26067- atomic_inc(&vcc->stats->tx_err);
26068+ atomic_inc_unchecked(&vcc->stats->tx_err);
26069 return -ENOLINK;
26070 }
26071 size = skb->len+sizeof(struct atmtcp_hdr);
26072@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc
26073 if (!new_skb) {
26074 if (vcc->pop) vcc->pop(vcc,skb);
26075 else dev_kfree_skb(skb);
26076- atomic_inc(&vcc->stats->tx_err);
26077+ atomic_inc_unchecked(&vcc->stats->tx_err);
26078 return -ENOBUFS;
26079 }
26080 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26081@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc
26082 if (vcc->pop) vcc->pop(vcc,skb);
26083 else dev_kfree_skb(skb);
26084 out_vcc->push(out_vcc,new_skb);
26085- atomic_inc(&vcc->stats->tx);
26086- atomic_inc(&out_vcc->stats->rx);
26087+ atomic_inc_unchecked(&vcc->stats->tx);
26088+ atomic_inc_unchecked(&out_vcc->stats->rx);
26089 return 0;
26090 }
26091
26092@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc
26093 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26094 read_unlock(&vcc_sklist_lock);
26095 if (!out_vcc) {
26096- atomic_inc(&vcc->stats->tx_err);
26097+ atomic_inc_unchecked(&vcc->stats->tx_err);
26098 goto done;
26099 }
26100 skb_pull(skb,sizeof(struct atmtcp_hdr));
26101@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc
26102 __net_timestamp(new_skb);
26103 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26104 out_vcc->push(out_vcc,new_skb);
26105- atomic_inc(&vcc->stats->tx);
26106- atomic_inc(&out_vcc->stats->rx);
26107+ atomic_inc_unchecked(&vcc->stats->tx);
26108+ atomic_inc_unchecked(&out_vcc->stats->rx);
26109 done:
26110 if (vcc->pop) vcc->pop(vcc,skb);
26111 else dev_kfree_skb(skb);
26112diff -urNp linux-2.6.32.44/drivers/atm/eni.c linux-2.6.32.44/drivers/atm/eni.c
26113--- linux-2.6.32.44/drivers/atm/eni.c 2011-03-27 14:31:47.000000000 -0400
26114+++ linux-2.6.32.44/drivers/atm/eni.c 2011-04-17 15:56:46.000000000 -0400
26115@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26116 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26117 vcc->dev->number);
26118 length = 0;
26119- atomic_inc(&vcc->stats->rx_err);
26120+ atomic_inc_unchecked(&vcc->stats->rx_err);
26121 }
26122 else {
26123 length = ATM_CELL_SIZE-1; /* no HEC */
26124@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26125 size);
26126 }
26127 eff = length = 0;
26128- atomic_inc(&vcc->stats->rx_err);
26129+ atomic_inc_unchecked(&vcc->stats->rx_err);
26130 }
26131 else {
26132 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26133@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26134 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26135 vcc->dev->number,vcc->vci,length,size << 2,descr);
26136 length = eff = 0;
26137- atomic_inc(&vcc->stats->rx_err);
26138+ atomic_inc_unchecked(&vcc->stats->rx_err);
26139 }
26140 }
26141 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26142@@ -770,7 +770,7 @@ rx_dequeued++;
26143 vcc->push(vcc,skb);
26144 pushed++;
26145 }
26146- atomic_inc(&vcc->stats->rx);
26147+ atomic_inc_unchecked(&vcc->stats->rx);
26148 }
26149 wake_up(&eni_dev->rx_wait);
26150 }
26151@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *d
26152 PCI_DMA_TODEVICE);
26153 if (vcc->pop) vcc->pop(vcc,skb);
26154 else dev_kfree_skb_irq(skb);
26155- atomic_inc(&vcc->stats->tx);
26156+ atomic_inc_unchecked(&vcc->stats->tx);
26157 wake_up(&eni_dev->tx_wait);
26158 dma_complete++;
26159 }
26160diff -urNp linux-2.6.32.44/drivers/atm/firestream.c linux-2.6.32.44/drivers/atm/firestream.c
26161--- linux-2.6.32.44/drivers/atm/firestream.c 2011-03-27 14:31:47.000000000 -0400
26162+++ linux-2.6.32.44/drivers/atm/firestream.c 2011-04-17 15:56:46.000000000 -0400
26163@@ -748,7 +748,7 @@ static void process_txdone_queue (struct
26164 }
26165 }
26166
26167- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26168+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26169
26170 fs_dprintk (FS_DEBUG_TXMEM, "i");
26171 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26172@@ -815,7 +815,7 @@ static void process_incoming (struct fs_
26173 #endif
26174 skb_put (skb, qe->p1 & 0xffff);
26175 ATM_SKB(skb)->vcc = atm_vcc;
26176- atomic_inc(&atm_vcc->stats->rx);
26177+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26178 __net_timestamp(skb);
26179 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26180 atm_vcc->push (atm_vcc, skb);
26181@@ -836,12 +836,12 @@ static void process_incoming (struct fs_
26182 kfree (pe);
26183 }
26184 if (atm_vcc)
26185- atomic_inc(&atm_vcc->stats->rx_drop);
26186+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26187 break;
26188 case 0x1f: /* Reassembly abort: no buffers. */
26189 /* Silently increment error counter. */
26190 if (atm_vcc)
26191- atomic_inc(&atm_vcc->stats->rx_drop);
26192+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26193 break;
26194 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26195 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26196diff -urNp linux-2.6.32.44/drivers/atm/fore200e.c linux-2.6.32.44/drivers/atm/fore200e.c
26197--- linux-2.6.32.44/drivers/atm/fore200e.c 2011-03-27 14:31:47.000000000 -0400
26198+++ linux-2.6.32.44/drivers/atm/fore200e.c 2011-04-17 15:56:46.000000000 -0400
26199@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200
26200 #endif
26201 /* check error condition */
26202 if (*entry->status & STATUS_ERROR)
26203- atomic_inc(&vcc->stats->tx_err);
26204+ atomic_inc_unchecked(&vcc->stats->tx_err);
26205 else
26206- atomic_inc(&vcc->stats->tx);
26207+ atomic_inc_unchecked(&vcc->stats->tx);
26208 }
26209 }
26210
26211@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore2
26212 if (skb == NULL) {
26213 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26214
26215- atomic_inc(&vcc->stats->rx_drop);
26216+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26217 return -ENOMEM;
26218 }
26219
26220@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore2
26221
26222 dev_kfree_skb_any(skb);
26223
26224- atomic_inc(&vcc->stats->rx_drop);
26225+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26226 return -ENOMEM;
26227 }
26228
26229 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26230
26231 vcc->push(vcc, skb);
26232- atomic_inc(&vcc->stats->rx);
26233+ atomic_inc_unchecked(&vcc->stats->rx);
26234
26235 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26236
26237@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200
26238 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26239 fore200e->atm_dev->number,
26240 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26241- atomic_inc(&vcc->stats->rx_err);
26242+ atomic_inc_unchecked(&vcc->stats->rx_err);
26243 }
26244 }
26245
26246@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26247 goto retry_here;
26248 }
26249
26250- atomic_inc(&vcc->stats->tx_err);
26251+ atomic_inc_unchecked(&vcc->stats->tx_err);
26252
26253 fore200e->tx_sat++;
26254 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26255diff -urNp linux-2.6.32.44/drivers/atm/he.c linux-2.6.32.44/drivers/atm/he.c
26256--- linux-2.6.32.44/drivers/atm/he.c 2011-03-27 14:31:47.000000000 -0400
26257+++ linux-2.6.32.44/drivers/atm/he.c 2011-04-17 15:56:46.000000000 -0400
26258@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26259
26260 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26261 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26262- atomic_inc(&vcc->stats->rx_drop);
26263+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26264 goto return_host_buffers;
26265 }
26266
26267@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26268 RBRQ_LEN_ERR(he_dev->rbrq_head)
26269 ? "LEN_ERR" : "",
26270 vcc->vpi, vcc->vci);
26271- atomic_inc(&vcc->stats->rx_err);
26272+ atomic_inc_unchecked(&vcc->stats->rx_err);
26273 goto return_host_buffers;
26274 }
26275
26276@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26277 vcc->push(vcc, skb);
26278 spin_lock(&he_dev->global_lock);
26279
26280- atomic_inc(&vcc->stats->rx);
26281+ atomic_inc_unchecked(&vcc->stats->rx);
26282
26283 return_host_buffers:
26284 ++pdus_assembled;
26285@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26286 tpd->vcc->pop(tpd->vcc, tpd->skb);
26287 else
26288 dev_kfree_skb_any(tpd->skb);
26289- atomic_inc(&tpd->vcc->stats->tx_err);
26290+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26291 }
26292 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26293 return;
26294@@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26295 vcc->pop(vcc, skb);
26296 else
26297 dev_kfree_skb_any(skb);
26298- atomic_inc(&vcc->stats->tx_err);
26299+ atomic_inc_unchecked(&vcc->stats->tx_err);
26300 return -EINVAL;
26301 }
26302
26303@@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26304 vcc->pop(vcc, skb);
26305 else
26306 dev_kfree_skb_any(skb);
26307- atomic_inc(&vcc->stats->tx_err);
26308+ atomic_inc_unchecked(&vcc->stats->tx_err);
26309 return -EINVAL;
26310 }
26311 #endif
26312@@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26313 vcc->pop(vcc, skb);
26314 else
26315 dev_kfree_skb_any(skb);
26316- atomic_inc(&vcc->stats->tx_err);
26317+ atomic_inc_unchecked(&vcc->stats->tx_err);
26318 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26319 return -ENOMEM;
26320 }
26321@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26322 vcc->pop(vcc, skb);
26323 else
26324 dev_kfree_skb_any(skb);
26325- atomic_inc(&vcc->stats->tx_err);
26326+ atomic_inc_unchecked(&vcc->stats->tx_err);
26327 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26328 return -ENOMEM;
26329 }
26330@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26331 __enqueue_tpd(he_dev, tpd, cid);
26332 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26333
26334- atomic_inc(&vcc->stats->tx);
26335+ atomic_inc_unchecked(&vcc->stats->tx);
26336
26337 return 0;
26338 }
26339diff -urNp linux-2.6.32.44/drivers/atm/horizon.c linux-2.6.32.44/drivers/atm/horizon.c
26340--- linux-2.6.32.44/drivers/atm/horizon.c 2011-03-27 14:31:47.000000000 -0400
26341+++ linux-2.6.32.44/drivers/atm/horizon.c 2011-04-17 15:56:46.000000000 -0400
26342@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev,
26343 {
26344 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26345 // VC layer stats
26346- atomic_inc(&vcc->stats->rx);
26347+ atomic_inc_unchecked(&vcc->stats->rx);
26348 __net_timestamp(skb);
26349 // end of our responsability
26350 vcc->push (vcc, skb);
26351@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const
26352 dev->tx_iovec = NULL;
26353
26354 // VC layer stats
26355- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26356+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26357
26358 // free the skb
26359 hrz_kfree_skb (skb);
26360diff -urNp linux-2.6.32.44/drivers/atm/idt77252.c linux-2.6.32.44/drivers/atm/idt77252.c
26361--- linux-2.6.32.44/drivers/atm/idt77252.c 2011-03-27 14:31:47.000000000 -0400
26362+++ linux-2.6.32.44/drivers/atm/idt77252.c 2011-04-17 15:56:46.000000000 -0400
26363@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, str
26364 else
26365 dev_kfree_skb(skb);
26366
26367- atomic_inc(&vcc->stats->tx);
26368+ atomic_inc_unchecked(&vcc->stats->tx);
26369 }
26370
26371 atomic_dec(&scq->used);
26372@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, st
26373 if ((sb = dev_alloc_skb(64)) == NULL) {
26374 printk("%s: Can't allocate buffers for aal0.\n",
26375 card->name);
26376- atomic_add(i, &vcc->stats->rx_drop);
26377+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
26378 break;
26379 }
26380 if (!atm_charge(vcc, sb->truesize)) {
26381 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26382 card->name);
26383- atomic_add(i - 1, &vcc->stats->rx_drop);
26384+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26385 dev_kfree_skb(sb);
26386 break;
26387 }
26388@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, st
26389 ATM_SKB(sb)->vcc = vcc;
26390 __net_timestamp(sb);
26391 vcc->push(vcc, sb);
26392- atomic_inc(&vcc->stats->rx);
26393+ atomic_inc_unchecked(&vcc->stats->rx);
26394
26395 cell += ATM_CELL_PAYLOAD;
26396 }
26397@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, st
26398 "(CDC: %08x)\n",
26399 card->name, len, rpp->len, readl(SAR_REG_CDC));
26400 recycle_rx_pool_skb(card, rpp);
26401- atomic_inc(&vcc->stats->rx_err);
26402+ atomic_inc_unchecked(&vcc->stats->rx_err);
26403 return;
26404 }
26405 if (stat & SAR_RSQE_CRC) {
26406 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26407 recycle_rx_pool_skb(card, rpp);
26408- atomic_inc(&vcc->stats->rx_err);
26409+ atomic_inc_unchecked(&vcc->stats->rx_err);
26410 return;
26411 }
26412 if (skb_queue_len(&rpp->queue) > 1) {
26413@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, st
26414 RXPRINTK("%s: Can't alloc RX skb.\n",
26415 card->name);
26416 recycle_rx_pool_skb(card, rpp);
26417- atomic_inc(&vcc->stats->rx_err);
26418+ atomic_inc_unchecked(&vcc->stats->rx_err);
26419 return;
26420 }
26421 if (!atm_charge(vcc, skb->truesize)) {
26422@@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, st
26423 __net_timestamp(skb);
26424
26425 vcc->push(vcc, skb);
26426- atomic_inc(&vcc->stats->rx);
26427+ atomic_inc_unchecked(&vcc->stats->rx);
26428
26429 return;
26430 }
26431@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, st
26432 __net_timestamp(skb);
26433
26434 vcc->push(vcc, skb);
26435- atomic_inc(&vcc->stats->rx);
26436+ atomic_inc_unchecked(&vcc->stats->rx);
26437
26438 if (skb->truesize > SAR_FB_SIZE_3)
26439 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26440@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26441 if (vcc->qos.aal != ATM_AAL0) {
26442 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26443 card->name, vpi, vci);
26444- atomic_inc(&vcc->stats->rx_drop);
26445+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26446 goto drop;
26447 }
26448
26449 if ((sb = dev_alloc_skb(64)) == NULL) {
26450 printk("%s: Can't allocate buffers for AAL0.\n",
26451 card->name);
26452- atomic_inc(&vcc->stats->rx_err);
26453+ atomic_inc_unchecked(&vcc->stats->rx_err);
26454 goto drop;
26455 }
26456
26457@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26458 ATM_SKB(sb)->vcc = vcc;
26459 __net_timestamp(sb);
26460 vcc->push(vcc, sb);
26461- atomic_inc(&vcc->stats->rx);
26462+ atomic_inc_unchecked(&vcc->stats->rx);
26463
26464 drop:
26465 skb_pull(queue, 64);
26466@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26467
26468 if (vc == NULL) {
26469 printk("%s: NULL connection in send().\n", card->name);
26470- atomic_inc(&vcc->stats->tx_err);
26471+ atomic_inc_unchecked(&vcc->stats->tx_err);
26472 dev_kfree_skb(skb);
26473 return -EINVAL;
26474 }
26475 if (!test_bit(VCF_TX, &vc->flags)) {
26476 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
26477- atomic_inc(&vcc->stats->tx_err);
26478+ atomic_inc_unchecked(&vcc->stats->tx_err);
26479 dev_kfree_skb(skb);
26480 return -EINVAL;
26481 }
26482@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26483 break;
26484 default:
26485 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
26486- atomic_inc(&vcc->stats->tx_err);
26487+ atomic_inc_unchecked(&vcc->stats->tx_err);
26488 dev_kfree_skb(skb);
26489 return -EINVAL;
26490 }
26491
26492 if (skb_shinfo(skb)->nr_frags != 0) {
26493 printk("%s: No scatter-gather yet.\n", card->name);
26494- atomic_inc(&vcc->stats->tx_err);
26495+ atomic_inc_unchecked(&vcc->stats->tx_err);
26496 dev_kfree_skb(skb);
26497 return -EINVAL;
26498 }
26499@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26500
26501 err = queue_skb(card, vc, skb, oam);
26502 if (err) {
26503- atomic_inc(&vcc->stats->tx_err);
26504+ atomic_inc_unchecked(&vcc->stats->tx_err);
26505 dev_kfree_skb(skb);
26506 return err;
26507 }
26508@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
26509 skb = dev_alloc_skb(64);
26510 if (!skb) {
26511 printk("%s: Out of memory in send_oam().\n", card->name);
26512- atomic_inc(&vcc->stats->tx_err);
26513+ atomic_inc_unchecked(&vcc->stats->tx_err);
26514 return -ENOMEM;
26515 }
26516 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
26517diff -urNp linux-2.6.32.44/drivers/atm/iphase.c linux-2.6.32.44/drivers/atm/iphase.c
26518--- linux-2.6.32.44/drivers/atm/iphase.c 2011-03-27 14:31:47.000000000 -0400
26519+++ linux-2.6.32.44/drivers/atm/iphase.c 2011-04-17 15:56:46.000000000 -0400
26520@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
26521 status = (u_short) (buf_desc_ptr->desc_mode);
26522 if (status & (RX_CER | RX_PTE | RX_OFL))
26523 {
26524- atomic_inc(&vcc->stats->rx_err);
26525+ atomic_inc_unchecked(&vcc->stats->rx_err);
26526 IF_ERR(printk("IA: bad packet, dropping it");)
26527 if (status & RX_CER) {
26528 IF_ERR(printk(" cause: packet CRC error\n");)
26529@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
26530 len = dma_addr - buf_addr;
26531 if (len > iadev->rx_buf_sz) {
26532 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
26533- atomic_inc(&vcc->stats->rx_err);
26534+ atomic_inc_unchecked(&vcc->stats->rx_err);
26535 goto out_free_desc;
26536 }
26537
26538@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *
26539 ia_vcc = INPH_IA_VCC(vcc);
26540 if (ia_vcc == NULL)
26541 {
26542- atomic_inc(&vcc->stats->rx_err);
26543+ atomic_inc_unchecked(&vcc->stats->rx_err);
26544 dev_kfree_skb_any(skb);
26545 atm_return(vcc, atm_guess_pdu2truesize(len));
26546 goto INCR_DLE;
26547@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *
26548 if ((length > iadev->rx_buf_sz) || (length >
26549 (skb->len - sizeof(struct cpcs_trailer))))
26550 {
26551- atomic_inc(&vcc->stats->rx_err);
26552+ atomic_inc_unchecked(&vcc->stats->rx_err);
26553 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
26554 length, skb->len);)
26555 dev_kfree_skb_any(skb);
26556@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *
26557
26558 IF_RX(printk("rx_dle_intr: skb push");)
26559 vcc->push(vcc,skb);
26560- atomic_inc(&vcc->stats->rx);
26561+ atomic_inc_unchecked(&vcc->stats->rx);
26562 iadev->rx_pkt_cnt++;
26563 }
26564 INCR_DLE:
26565@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev,
26566 {
26567 struct k_sonet_stats *stats;
26568 stats = &PRIV(_ia_dev[board])->sonet_stats;
26569- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
26570- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
26571- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
26572- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
26573- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
26574- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
26575- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
26576- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
26577- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
26578+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
26579+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26580+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26581+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26582+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26583+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26584+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26585+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26586+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26587 }
26588 ia_cmds.status = 0;
26589 break;
26590@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
26591 if ((desc == 0) || (desc > iadev->num_tx_desc))
26592 {
26593 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26594- atomic_inc(&vcc->stats->tx);
26595+ atomic_inc_unchecked(&vcc->stats->tx);
26596 if (vcc->pop)
26597 vcc->pop(vcc, skb);
26598 else
26599@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
26600 ATM_DESC(skb) = vcc->vci;
26601 skb_queue_tail(&iadev->tx_dma_q, skb);
26602
26603- atomic_inc(&vcc->stats->tx);
26604+ atomic_inc_unchecked(&vcc->stats->tx);
26605 iadev->tx_pkt_cnt++;
26606 /* Increment transaction counter */
26607 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
26608
26609 #if 0
26610 /* add flow control logic */
26611- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
26612+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
26613 if (iavcc->vc_desc_cnt > 10) {
26614 vcc->tx_quota = vcc->tx_quota * 3 / 4;
26615 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
26616diff -urNp linux-2.6.32.44/drivers/atm/lanai.c linux-2.6.32.44/drivers/atm/lanai.c
26617--- linux-2.6.32.44/drivers/atm/lanai.c 2011-03-27 14:31:47.000000000 -0400
26618+++ linux-2.6.32.44/drivers/atm/lanai.c 2011-04-17 15:56:46.000000000 -0400
26619@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct l
26620 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
26621 lanai_endtx(lanai, lvcc);
26622 lanai_free_skb(lvcc->tx.atmvcc, skb);
26623- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
26624+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
26625 }
26626
26627 /* Try to fill the buffer - don't call unless there is backlog */
26628@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc
26629 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
26630 __net_timestamp(skb);
26631 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
26632- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
26633+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
26634 out:
26635 lvcc->rx.buf.ptr = end;
26636 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
26637@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_d
26638 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
26639 "vcc %d\n", lanai->number, (unsigned int) s, vci);
26640 lanai->stats.service_rxnotaal5++;
26641- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26642+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26643 return 0;
26644 }
26645 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
26646@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_d
26647 int bytes;
26648 read_unlock(&vcc_sklist_lock);
26649 DPRINTK("got trashed rx pdu on vci %d\n", vci);
26650- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26651+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26652 lvcc->stats.x.aal5.service_trash++;
26653 bytes = (SERVICE_GET_END(s) * 16) -
26654 (((unsigned long) lvcc->rx.buf.ptr) -
26655@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_d
26656 }
26657 if (s & SERVICE_STREAM) {
26658 read_unlock(&vcc_sklist_lock);
26659- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26660+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26661 lvcc->stats.x.aal5.service_stream++;
26662 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
26663 "PDU on VCI %d!\n", lanai->number, vci);
26664@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_d
26665 return 0;
26666 }
26667 DPRINTK("got rx crc error on vci %d\n", vci);
26668- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26669+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26670 lvcc->stats.x.aal5.service_rxcrc++;
26671 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
26672 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
26673diff -urNp linux-2.6.32.44/drivers/atm/nicstar.c linux-2.6.32.44/drivers/atm/nicstar.c
26674--- linux-2.6.32.44/drivers/atm/nicstar.c 2011-03-27 14:31:47.000000000 -0400
26675+++ linux-2.6.32.44/drivers/atm/nicstar.c 2011-04-17 15:56:46.000000000 -0400
26676@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc,
26677 if ((vc = (vc_map *) vcc->dev_data) == NULL)
26678 {
26679 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
26680- atomic_inc(&vcc->stats->tx_err);
26681+ atomic_inc_unchecked(&vcc->stats->tx_err);
26682 dev_kfree_skb_any(skb);
26683 return -EINVAL;
26684 }
26685@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc,
26686 if (!vc->tx)
26687 {
26688 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
26689- atomic_inc(&vcc->stats->tx_err);
26690+ atomic_inc_unchecked(&vcc->stats->tx_err);
26691 dev_kfree_skb_any(skb);
26692 return -EINVAL;
26693 }
26694@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc,
26695 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
26696 {
26697 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
26698- atomic_inc(&vcc->stats->tx_err);
26699+ atomic_inc_unchecked(&vcc->stats->tx_err);
26700 dev_kfree_skb_any(skb);
26701 return -EINVAL;
26702 }
26703@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc,
26704 if (skb_shinfo(skb)->nr_frags != 0)
26705 {
26706 printk("nicstar%d: No scatter-gather yet.\n", card->index);
26707- atomic_inc(&vcc->stats->tx_err);
26708+ atomic_inc_unchecked(&vcc->stats->tx_err);
26709 dev_kfree_skb_any(skb);
26710 return -EINVAL;
26711 }
26712@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc,
26713
26714 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
26715 {
26716- atomic_inc(&vcc->stats->tx_err);
26717+ atomic_inc_unchecked(&vcc->stats->tx_err);
26718 dev_kfree_skb_any(skb);
26719 return -EIO;
26720 }
26721- atomic_inc(&vcc->stats->tx);
26722+ atomic_inc_unchecked(&vcc->stats->tx);
26723
26724 return 0;
26725 }
26726@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_
26727 {
26728 printk("nicstar%d: Can't allocate buffers for aal0.\n",
26729 card->index);
26730- atomic_add(i,&vcc->stats->rx_drop);
26731+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
26732 break;
26733 }
26734 if (!atm_charge(vcc, sb->truesize))
26735 {
26736 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
26737 card->index);
26738- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
26739+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
26740 dev_kfree_skb_any(sb);
26741 break;
26742 }
26743@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_
26744 ATM_SKB(sb)->vcc = vcc;
26745 __net_timestamp(sb);
26746 vcc->push(vcc, sb);
26747- atomic_inc(&vcc->stats->rx);
26748+ atomic_inc_unchecked(&vcc->stats->rx);
26749 cell += ATM_CELL_PAYLOAD;
26750 }
26751
26752@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_
26753 if (iovb == NULL)
26754 {
26755 printk("nicstar%d: Out of iovec buffers.\n", card->index);
26756- atomic_inc(&vcc->stats->rx_drop);
26757+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26758 recycle_rx_buf(card, skb);
26759 return;
26760 }
26761@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_
26762 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
26763 {
26764 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26765- atomic_inc(&vcc->stats->rx_err);
26766+ atomic_inc_unchecked(&vcc->stats->rx_err);
26767 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
26768 NS_SKB(iovb)->iovcnt = 0;
26769 iovb->len = 0;
26770@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_
26771 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
26772 card->index);
26773 which_list(card, skb);
26774- atomic_inc(&vcc->stats->rx_err);
26775+ atomic_inc_unchecked(&vcc->stats->rx_err);
26776 recycle_rx_buf(card, skb);
26777 vc->rx_iov = NULL;
26778 recycle_iov_buf(card, iovb);
26779@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_
26780 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
26781 card->index);
26782 which_list(card, skb);
26783- atomic_inc(&vcc->stats->rx_err);
26784+ atomic_inc_unchecked(&vcc->stats->rx_err);
26785 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
26786 NS_SKB(iovb)->iovcnt);
26787 vc->rx_iov = NULL;
26788@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_
26789 printk(" - PDU size mismatch.\n");
26790 else
26791 printk(".\n");
26792- atomic_inc(&vcc->stats->rx_err);
26793+ atomic_inc_unchecked(&vcc->stats->rx_err);
26794 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
26795 NS_SKB(iovb)->iovcnt);
26796 vc->rx_iov = NULL;
26797@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_
26798 if (!atm_charge(vcc, skb->truesize))
26799 {
26800 push_rxbufs(card, skb);
26801- atomic_inc(&vcc->stats->rx_drop);
26802+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26803 }
26804 else
26805 {
26806@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_
26807 ATM_SKB(skb)->vcc = vcc;
26808 __net_timestamp(skb);
26809 vcc->push(vcc, skb);
26810- atomic_inc(&vcc->stats->rx);
26811+ atomic_inc_unchecked(&vcc->stats->rx);
26812 }
26813 }
26814 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
26815@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_
26816 if (!atm_charge(vcc, sb->truesize))
26817 {
26818 push_rxbufs(card, sb);
26819- atomic_inc(&vcc->stats->rx_drop);
26820+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26821 }
26822 else
26823 {
26824@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_
26825 ATM_SKB(sb)->vcc = vcc;
26826 __net_timestamp(sb);
26827 vcc->push(vcc, sb);
26828- atomic_inc(&vcc->stats->rx);
26829+ atomic_inc_unchecked(&vcc->stats->rx);
26830 }
26831
26832 push_rxbufs(card, skb);
26833@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_
26834 if (!atm_charge(vcc, skb->truesize))
26835 {
26836 push_rxbufs(card, skb);
26837- atomic_inc(&vcc->stats->rx_drop);
26838+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26839 }
26840 else
26841 {
26842@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_
26843 ATM_SKB(skb)->vcc = vcc;
26844 __net_timestamp(skb);
26845 vcc->push(vcc, skb);
26846- atomic_inc(&vcc->stats->rx);
26847+ atomic_inc_unchecked(&vcc->stats->rx);
26848 }
26849
26850 push_rxbufs(card, sb);
26851@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_
26852 if (hb == NULL)
26853 {
26854 printk("nicstar%d: Out of huge buffers.\n", card->index);
26855- atomic_inc(&vcc->stats->rx_drop);
26856+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26857 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
26858 NS_SKB(iovb)->iovcnt);
26859 vc->rx_iov = NULL;
26860@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_
26861 }
26862 else
26863 dev_kfree_skb_any(hb);
26864- atomic_inc(&vcc->stats->rx_drop);
26865+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26866 }
26867 else
26868 {
26869@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_
26870 #endif /* NS_USE_DESTRUCTORS */
26871 __net_timestamp(hb);
26872 vcc->push(vcc, hb);
26873- atomic_inc(&vcc->stats->rx);
26874+ atomic_inc_unchecked(&vcc->stats->rx);
26875 }
26876 }
26877
26878diff -urNp linux-2.6.32.44/drivers/atm/solos-pci.c linux-2.6.32.44/drivers/atm/solos-pci.c
26879--- linux-2.6.32.44/drivers/atm/solos-pci.c 2011-04-17 17:00:52.000000000 -0400
26880+++ linux-2.6.32.44/drivers/atm/solos-pci.c 2011-05-16 21:46:57.000000000 -0400
26881@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
26882 }
26883 atm_charge(vcc, skb->truesize);
26884 vcc->push(vcc, skb);
26885- atomic_inc(&vcc->stats->rx);
26886+ atomic_inc_unchecked(&vcc->stats->rx);
26887 break;
26888
26889 case PKT_STATUS:
26890@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *
26891 char msg[500];
26892 char item[10];
26893
26894+ pax_track_stack();
26895+
26896 len = buf->len;
26897 for (i = 0; i < len; i++){
26898 if(i % 8 == 0)
26899@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_car
26900 vcc = SKB_CB(oldskb)->vcc;
26901
26902 if (vcc) {
26903- atomic_inc(&vcc->stats->tx);
26904+ atomic_inc_unchecked(&vcc->stats->tx);
26905 solos_pop(vcc, oldskb);
26906 } else
26907 dev_kfree_skb_irq(oldskb);
26908diff -urNp linux-2.6.32.44/drivers/atm/suni.c linux-2.6.32.44/drivers/atm/suni.c
26909--- linux-2.6.32.44/drivers/atm/suni.c 2011-03-27 14:31:47.000000000 -0400
26910+++ linux-2.6.32.44/drivers/atm/suni.c 2011-04-17 15:56:46.000000000 -0400
26911@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26912
26913
26914 #define ADD_LIMITED(s,v) \
26915- atomic_add((v),&stats->s); \
26916- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26917+ atomic_add_unchecked((v),&stats->s); \
26918+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26919
26920
26921 static void suni_hz(unsigned long from_timer)
26922diff -urNp linux-2.6.32.44/drivers/atm/uPD98402.c linux-2.6.32.44/drivers/atm/uPD98402.c
26923--- linux-2.6.32.44/drivers/atm/uPD98402.c 2011-03-27 14:31:47.000000000 -0400
26924+++ linux-2.6.32.44/drivers/atm/uPD98402.c 2011-04-17 15:56:46.000000000 -0400
26925@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *d
26926 struct sonet_stats tmp;
26927 int error = 0;
26928
26929- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26930+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26931 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26932 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26933 if (zero && !error) {
26934@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev
26935
26936
26937 #define ADD_LIMITED(s,v) \
26938- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26939- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26940- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26941+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26942+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26943+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26944
26945
26946 static void stat_event(struct atm_dev *dev)
26947@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev
26948 if (reason & uPD98402_INT_PFM) stat_event(dev);
26949 if (reason & uPD98402_INT_PCO) {
26950 (void) GET(PCOCR); /* clear interrupt cause */
26951- atomic_add(GET(HECCT),
26952+ atomic_add_unchecked(GET(HECCT),
26953 &PRIV(dev)->sonet_stats.uncorr_hcs);
26954 }
26955 if ((reason & uPD98402_INT_RFO) &&
26956@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev
26957 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26958 uPD98402_INT_LOS),PIMR); /* enable them */
26959 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26960- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26961- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26962- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26963+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26964+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26965+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26966 return 0;
26967 }
26968
26969diff -urNp linux-2.6.32.44/drivers/atm/zatm.c linux-2.6.32.44/drivers/atm/zatm.c
26970--- linux-2.6.32.44/drivers/atm/zatm.c 2011-03-27 14:31:47.000000000 -0400
26971+++ linux-2.6.32.44/drivers/atm/zatm.c 2011-04-17 15:56:46.000000000 -0400
26972@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
26973 }
26974 if (!size) {
26975 dev_kfree_skb_irq(skb);
26976- if (vcc) atomic_inc(&vcc->stats->rx_err);
26977+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26978 continue;
26979 }
26980 if (!atm_charge(vcc,skb->truesize)) {
26981@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
26982 skb->len = size;
26983 ATM_SKB(skb)->vcc = vcc;
26984 vcc->push(vcc,skb);
26985- atomic_inc(&vcc->stats->rx);
26986+ atomic_inc_unchecked(&vcc->stats->rx);
26987 }
26988 zout(pos & 0xffff,MTA(mbx));
26989 #if 0 /* probably a stupid idea */
26990@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
26991 skb_queue_head(&zatm_vcc->backlog,skb);
26992 break;
26993 }
26994- atomic_inc(&vcc->stats->tx);
26995+ atomic_inc_unchecked(&vcc->stats->tx);
26996 wake_up(&zatm_vcc->tx_wait);
26997 }
26998
26999diff -urNp linux-2.6.32.44/drivers/base/bus.c linux-2.6.32.44/drivers/base/bus.c
27000--- linux-2.6.32.44/drivers/base/bus.c 2011-03-27 14:31:47.000000000 -0400
27001+++ linux-2.6.32.44/drivers/base/bus.c 2011-04-17 15:56:46.000000000 -0400
27002@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kob
27003 return ret;
27004 }
27005
27006-static struct sysfs_ops driver_sysfs_ops = {
27007+static const struct sysfs_ops driver_sysfs_ops = {
27008 .show = drv_attr_show,
27009 .store = drv_attr_store,
27010 };
27011@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kob
27012 return ret;
27013 }
27014
27015-static struct sysfs_ops bus_sysfs_ops = {
27016+static const struct sysfs_ops bus_sysfs_ops = {
27017 .show = bus_attr_show,
27018 .store = bus_attr_store,
27019 };
27020@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset
27021 return 0;
27022 }
27023
27024-static struct kset_uevent_ops bus_uevent_ops = {
27025+static const struct kset_uevent_ops bus_uevent_ops = {
27026 .filter = bus_uevent_filter,
27027 };
27028
27029diff -urNp linux-2.6.32.44/drivers/base/class.c linux-2.6.32.44/drivers/base/class.c
27030--- linux-2.6.32.44/drivers/base/class.c 2011-03-27 14:31:47.000000000 -0400
27031+++ linux-2.6.32.44/drivers/base/class.c 2011-04-17 15:56:46.000000000 -0400
27032@@ -63,7 +63,7 @@ static void class_release(struct kobject
27033 kfree(cp);
27034 }
27035
27036-static struct sysfs_ops class_sysfs_ops = {
27037+static const struct sysfs_ops class_sysfs_ops = {
27038 .show = class_attr_show,
27039 .store = class_attr_store,
27040 };
27041diff -urNp linux-2.6.32.44/drivers/base/core.c linux-2.6.32.44/drivers/base/core.c
27042--- linux-2.6.32.44/drivers/base/core.c 2011-03-27 14:31:47.000000000 -0400
27043+++ linux-2.6.32.44/drivers/base/core.c 2011-04-17 15:56:46.000000000 -0400
27044@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kob
27045 return ret;
27046 }
27047
27048-static struct sysfs_ops dev_sysfs_ops = {
27049+static const struct sysfs_ops dev_sysfs_ops = {
27050 .show = dev_attr_show,
27051 .store = dev_attr_store,
27052 };
27053@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset,
27054 return retval;
27055 }
27056
27057-static struct kset_uevent_ops device_uevent_ops = {
27058+static const struct kset_uevent_ops device_uevent_ops = {
27059 .filter = dev_uevent_filter,
27060 .name = dev_uevent_name,
27061 .uevent = dev_uevent,
27062diff -urNp linux-2.6.32.44/drivers/base/memory.c linux-2.6.32.44/drivers/base/memory.c
27063--- linux-2.6.32.44/drivers/base/memory.c 2011-03-27 14:31:47.000000000 -0400
27064+++ linux-2.6.32.44/drivers/base/memory.c 2011-04-17 15:56:46.000000000 -0400
27065@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *ks
27066 return retval;
27067 }
27068
27069-static struct kset_uevent_ops memory_uevent_ops = {
27070+static const struct kset_uevent_ops memory_uevent_ops = {
27071 .name = memory_uevent_name,
27072 .uevent = memory_uevent,
27073 };
27074diff -urNp linux-2.6.32.44/drivers/base/sys.c linux-2.6.32.44/drivers/base/sys.c
27075--- linux-2.6.32.44/drivers/base/sys.c 2011-03-27 14:31:47.000000000 -0400
27076+++ linux-2.6.32.44/drivers/base/sys.c 2011-04-17 15:56:46.000000000 -0400
27077@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struc
27078 return -EIO;
27079 }
27080
27081-static struct sysfs_ops sysfs_ops = {
27082+static const struct sysfs_ops sysfs_ops = {
27083 .show = sysdev_show,
27084 .store = sysdev_store,
27085 };
27086@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct
27087 return -EIO;
27088 }
27089
27090-static struct sysfs_ops sysfs_class_ops = {
27091+static const struct sysfs_ops sysfs_class_ops = {
27092 .show = sysdev_class_show,
27093 .store = sysdev_class_store,
27094 };
27095diff -urNp linux-2.6.32.44/drivers/block/cciss.c linux-2.6.32.44/drivers/block/cciss.c
27096--- linux-2.6.32.44/drivers/block/cciss.c 2011-03-27 14:31:47.000000000 -0400
27097+++ linux-2.6.32.44/drivers/block/cciss.c 2011-08-05 20:33:55.000000000 -0400
27098@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct
27099 int err;
27100 u32 cp;
27101
27102+ memset(&arg64, 0, sizeof(arg64));
27103+
27104 err = 0;
27105 err |=
27106 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27107@@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ct
27108 /* Wait (up to 20 seconds) for a command to complete */
27109
27110 for (i = 20 * HZ; i > 0; i--) {
27111- done = hba[ctlr]->access.command_completed(hba[ctlr]);
27112+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
27113 if (done == FIFO_EMPTY)
27114 schedule_timeout_uninterruptible(1);
27115 else
27116@@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h,
27117 resend_cmd1:
27118
27119 /* Disable interrupt on the board. */
27120- h->access.set_intr_mask(h, CCISS_INTR_OFF);
27121+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
27122
27123 /* Make sure there is room in the command FIFO */
27124 /* Actually it should be completely empty at this time */
27125@@ -2884,13 +2886,13 @@ resend_cmd1:
27126 /* tape side of the driver. */
27127 for (i = 200000; i > 0; i--) {
27128 /* if fifo isn't full go */
27129- if (!(h->access.fifo_full(h)))
27130+ if (!(h->access->fifo_full(h)))
27131 break;
27132 udelay(10);
27133 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
27134 " waiting!\n", h->ctlr);
27135 }
27136- h->access.submit_command(h, c); /* Send the cmd */
27137+ h->access->submit_command(h, c); /* Send the cmd */
27138 do {
27139 complete = pollcomplete(h->ctlr);
27140
27141@@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
27142 while (!hlist_empty(&h->reqQ)) {
27143 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
27144 /* can't do anything if fifo is full */
27145- if ((h->access.fifo_full(h))) {
27146+ if ((h->access->fifo_full(h))) {
27147 printk(KERN_WARNING "cciss: fifo full\n");
27148 break;
27149 }
27150@@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
27151 h->Qdepth--;
27152
27153 /* Tell the controller execute command */
27154- h->access.submit_command(h, c);
27155+ h->access->submit_command(h, c);
27156
27157 /* Put job onto the completed Q */
27158 addQ(&h->cmpQ, c);
27159@@ -3393,17 +3395,17 @@ startio:
27160
27161 static inline unsigned long get_next_completion(ctlr_info_t *h)
27162 {
27163- return h->access.command_completed(h);
27164+ return h->access->command_completed(h);
27165 }
27166
27167 static inline int interrupt_pending(ctlr_info_t *h)
27168 {
27169- return h->access.intr_pending(h);
27170+ return h->access->intr_pending(h);
27171 }
27172
27173 static inline long interrupt_not_for_us(ctlr_info_t *h)
27174 {
27175- return (((h->access.intr_pending(h) == 0) ||
27176+ return (((h->access->intr_pending(h) == 0) ||
27177 (h->interrupts_enabled == 0)));
27178 }
27179
27180@@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr
27181 */
27182 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
27183 c->product_name = products[prod_index].product_name;
27184- c->access = *(products[prod_index].access);
27185+ c->access = products[prod_index].access;
27186 c->nr_cmds = c->max_commands - 4;
27187 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
27188 (readb(&c->cfgtable->Signature[1]) != 'I') ||
27189@@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(stru
27190 }
27191
27192 /* make sure the board interrupts are off */
27193- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
27194+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
27195 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
27196 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
27197 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
27198@@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(stru
27199 cciss_scsi_setup(i);
27200
27201 /* Turn the interrupts on so we can service requests */
27202- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
27203+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
27204
27205 /* Get the firmware version */
27206 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
27207diff -urNp linux-2.6.32.44/drivers/block/cciss.h linux-2.6.32.44/drivers/block/cciss.h
27208--- linux-2.6.32.44/drivers/block/cciss.h 2011-08-09 18:35:28.000000000 -0400
27209+++ linux-2.6.32.44/drivers/block/cciss.h 2011-08-09 18:33:59.000000000 -0400
27210@@ -90,7 +90,7 @@ struct ctlr_info
27211 // information about each logical volume
27212 drive_info_struct *drv[CISS_MAX_LUN];
27213
27214- struct access_method access;
27215+ struct access_method *access;
27216
27217 /* queue and queue Info */
27218 struct hlist_head reqQ;
27219diff -urNp linux-2.6.32.44/drivers/block/cpqarray.c linux-2.6.32.44/drivers/block/cpqarray.c
27220--- linux-2.6.32.44/drivers/block/cpqarray.c 2011-03-27 14:31:47.000000000 -0400
27221+++ linux-2.6.32.44/drivers/block/cpqarray.c 2011-08-05 20:33:55.000000000 -0400
27222@@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr
27223 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
27224 goto Enomem4;
27225 }
27226- hba[i]->access.set_intr_mask(hba[i], 0);
27227+ hba[i]->access->set_intr_mask(hba[i], 0);
27228 if (request_irq(hba[i]->intr, do_ida_intr,
27229 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
27230 {
27231@@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr
27232 add_timer(&hba[i]->timer);
27233
27234 /* Enable IRQ now that spinlock and rate limit timer are set up */
27235- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27236+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27237
27238 for(j=0; j<NWD; j++) {
27239 struct gendisk *disk = ida_gendisk[i][j];
27240@@ -695,7 +695,7 @@ DBGINFO(
27241 for(i=0; i<NR_PRODUCTS; i++) {
27242 if (board_id == products[i].board_id) {
27243 c->product_name = products[i].product_name;
27244- c->access = *(products[i].access);
27245+ c->access = products[i].access;
27246 break;
27247 }
27248 }
27249@@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(v
27250 hba[ctlr]->intr = intr;
27251 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
27252 hba[ctlr]->product_name = products[j].product_name;
27253- hba[ctlr]->access = *(products[j].access);
27254+ hba[ctlr]->access = products[j].access;
27255 hba[ctlr]->ctlr = ctlr;
27256 hba[ctlr]->board_id = board_id;
27257 hba[ctlr]->pci_dev = NULL; /* not PCI */
27258@@ -896,6 +896,8 @@ static void do_ida_request(struct reques
27259 struct scatterlist tmp_sg[SG_MAX];
27260 int i, dir, seg;
27261
27262+ pax_track_stack();
27263+
27264 if (blk_queue_plugged(q))
27265 goto startio;
27266
27267@@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
27268
27269 while((c = h->reqQ) != NULL) {
27270 /* Can't do anything if we're busy */
27271- if (h->access.fifo_full(h) == 0)
27272+ if (h->access->fifo_full(h) == 0)
27273 return;
27274
27275 /* Get the first entry from the request Q */
27276@@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
27277 h->Qdepth--;
27278
27279 /* Tell the controller to do our bidding */
27280- h->access.submit_command(h, c);
27281+ h->access->submit_command(h, c);
27282
27283 /* Get onto the completion Q */
27284 addQ(&h->cmpQ, c);
27285@@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq,
27286 unsigned long flags;
27287 __u32 a,a1;
27288
27289- istat = h->access.intr_pending(h);
27290+ istat = h->access->intr_pending(h);
27291 /* Is this interrupt for us? */
27292 if (istat == 0)
27293 return IRQ_NONE;
27294@@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq,
27295 */
27296 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
27297 if (istat & FIFO_NOT_EMPTY) {
27298- while((a = h->access.command_completed(h))) {
27299+ while((a = h->access->command_completed(h))) {
27300 a1 = a; a &= ~3;
27301 if ((c = h->cmpQ) == NULL)
27302 {
27303@@ -1434,11 +1436,11 @@ static int sendcmd(
27304 /*
27305 * Disable interrupt
27306 */
27307- info_p->access.set_intr_mask(info_p, 0);
27308+ info_p->access->set_intr_mask(info_p, 0);
27309 /* Make sure there is room in the command FIFO */
27310 /* Actually it should be completely empty at this time. */
27311 for (i = 200000; i > 0; i--) {
27312- temp = info_p->access.fifo_full(info_p);
27313+ temp = info_p->access->fifo_full(info_p);
27314 if (temp != 0) {
27315 break;
27316 }
27317@@ -1451,7 +1453,7 @@ DBG(
27318 /*
27319 * Send the cmd
27320 */
27321- info_p->access.submit_command(info_p, c);
27322+ info_p->access->submit_command(info_p, c);
27323 complete = pollcomplete(ctlr);
27324
27325 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
27326@@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t
27327 * we check the new geometry. Then turn interrupts back on when
27328 * we're done.
27329 */
27330- host->access.set_intr_mask(host, 0);
27331+ host->access->set_intr_mask(host, 0);
27332 getgeometry(ctlr);
27333- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
27334+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
27335
27336 for(i=0; i<NWD; i++) {
27337 struct gendisk *disk = ida_gendisk[ctlr][i];
27338@@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
27339 /* Wait (up to 2 seconds) for a command to complete */
27340
27341 for (i = 200000; i > 0; i--) {
27342- done = hba[ctlr]->access.command_completed(hba[ctlr]);
27343+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
27344 if (done == 0) {
27345 udelay(10); /* a short fixed delay */
27346 } else
27347diff -urNp linux-2.6.32.44/drivers/block/cpqarray.h linux-2.6.32.44/drivers/block/cpqarray.h
27348--- linux-2.6.32.44/drivers/block/cpqarray.h 2011-03-27 14:31:47.000000000 -0400
27349+++ linux-2.6.32.44/drivers/block/cpqarray.h 2011-08-05 20:33:55.000000000 -0400
27350@@ -99,7 +99,7 @@ struct ctlr_info {
27351 drv_info_t drv[NWD];
27352 struct proc_dir_entry *proc;
27353
27354- struct access_method access;
27355+ struct access_method *access;
27356
27357 cmdlist_t *reqQ;
27358 cmdlist_t *cmpQ;
27359diff -urNp linux-2.6.32.44/drivers/block/DAC960.c linux-2.6.32.44/drivers/block/DAC960.c
27360--- linux-2.6.32.44/drivers/block/DAC960.c 2011-03-27 14:31:47.000000000 -0400
27361+++ linux-2.6.32.44/drivers/block/DAC960.c 2011-05-16 21:46:57.000000000 -0400
27362@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27363 unsigned long flags;
27364 int Channel, TargetID;
27365
27366+ pax_track_stack();
27367+
27368 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27369 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27370 sizeof(DAC960_SCSI_Inquiry_T) +
27371diff -urNp linux-2.6.32.44/drivers/block/nbd.c linux-2.6.32.44/drivers/block/nbd.c
27372--- linux-2.6.32.44/drivers/block/nbd.c 2011-06-25 12:55:34.000000000 -0400
27373+++ linux-2.6.32.44/drivers/block/nbd.c 2011-06-25 12:56:37.000000000 -0400
27374@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *
27375 struct kvec iov;
27376 sigset_t blocked, oldset;
27377
27378+ pax_track_stack();
27379+
27380 if (unlikely(!sock)) {
27381 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27382 lo->disk->disk_name, (send ? "send" : "recv"));
27383@@ -569,6 +571,8 @@ static void do_nbd_request(struct reques
27384 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27385 unsigned int cmd, unsigned long arg)
27386 {
27387+ pax_track_stack();
27388+
27389 switch (cmd) {
27390 case NBD_DISCONNECT: {
27391 struct request sreq;
27392diff -urNp linux-2.6.32.44/drivers/block/pktcdvd.c linux-2.6.32.44/drivers/block/pktcdvd.c
27393--- linux-2.6.32.44/drivers/block/pktcdvd.c 2011-03-27 14:31:47.000000000 -0400
27394+++ linux-2.6.32.44/drivers/block/pktcdvd.c 2011-04-17 15:56:46.000000000 -0400
27395@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kob
27396 return len;
27397 }
27398
27399-static struct sysfs_ops kobj_pkt_ops = {
27400+static const struct sysfs_ops kobj_pkt_ops = {
27401 .show = kobj_pkt_show,
27402 .store = kobj_pkt_store
27403 };
27404diff -urNp linux-2.6.32.44/drivers/char/agp/frontend.c linux-2.6.32.44/drivers/char/agp/frontend.c
27405--- linux-2.6.32.44/drivers/char/agp/frontend.c 2011-03-27 14:31:47.000000000 -0400
27406+++ linux-2.6.32.44/drivers/char/agp/frontend.c 2011-04-17 15:56:46.000000000 -0400
27407@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
27408 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27409 return -EFAULT;
27410
27411- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27412+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27413 return -EFAULT;
27414
27415 client = agp_find_client_by_pid(reserve.pid);
27416diff -urNp linux-2.6.32.44/drivers/char/briq_panel.c linux-2.6.32.44/drivers/char/briq_panel.c
27417--- linux-2.6.32.44/drivers/char/briq_panel.c 2011-03-27 14:31:47.000000000 -0400
27418+++ linux-2.6.32.44/drivers/char/briq_panel.c 2011-04-18 19:48:57.000000000 -0400
27419@@ -10,6 +10,7 @@
27420 #include <linux/types.h>
27421 #include <linux/errno.h>
27422 #include <linux/tty.h>
27423+#include <linux/mutex.h>
27424 #include <linux/timer.h>
27425 #include <linux/kernel.h>
27426 #include <linux/wait.h>
27427@@ -36,6 +37,7 @@ static int vfd_is_open;
27428 static unsigned char vfd[40];
27429 static int vfd_cursor;
27430 static unsigned char ledpb, led;
27431+static DEFINE_MUTEX(vfd_mutex);
27432
27433 static void update_vfd(void)
27434 {
27435@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct f
27436 if (!vfd_is_open)
27437 return -EBUSY;
27438
27439+ mutex_lock(&vfd_mutex);
27440 for (;;) {
27441 char c;
27442 if (!indx)
27443 break;
27444- if (get_user(c, buf))
27445+ if (get_user(c, buf)) {
27446+ mutex_unlock(&vfd_mutex);
27447 return -EFAULT;
27448+ }
27449 if (esc) {
27450 set_led(c);
27451 esc = 0;
27452@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct f
27453 buf++;
27454 }
27455 update_vfd();
27456+ mutex_unlock(&vfd_mutex);
27457
27458 return len;
27459 }
27460diff -urNp linux-2.6.32.44/drivers/char/genrtc.c linux-2.6.32.44/drivers/char/genrtc.c
27461--- linux-2.6.32.44/drivers/char/genrtc.c 2011-03-27 14:31:47.000000000 -0400
27462+++ linux-2.6.32.44/drivers/char/genrtc.c 2011-04-18 19:45:42.000000000 -0400
27463@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *i
27464 switch (cmd) {
27465
27466 case RTC_PLL_GET:
27467+ memset(&pll, 0, sizeof(pll));
27468 if (get_rtc_pll(&pll))
27469 return -EINVAL;
27470 else
27471diff -urNp linux-2.6.32.44/drivers/char/hpet.c linux-2.6.32.44/drivers/char/hpet.c
27472--- linux-2.6.32.44/drivers/char/hpet.c 2011-03-27 14:31:47.000000000 -0400
27473+++ linux-2.6.32.44/drivers/char/hpet.c 2011-04-23 12:56:11.000000000 -0400
27474@@ -430,7 +430,7 @@ static int hpet_release(struct inode *in
27475 return 0;
27476 }
27477
27478-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
27479+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
27480
27481 static int
27482 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
27483@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_di
27484 }
27485
27486 static int
27487-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
27488+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
27489 {
27490 struct hpet_timer __iomem *timer;
27491 struct hpet __iomem *hpet;
27492@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp,
27493 {
27494 struct hpet_info info;
27495
27496+ memset(&info, 0, sizeof(info));
27497+
27498 if (devp->hd_ireqfreq)
27499 info.hi_ireqfreq =
27500 hpet_time_div(hpetp, devp->hd_ireqfreq);
27501- else
27502- info.hi_ireqfreq = 0;
27503 info.hi_flags =
27504 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
27505 info.hi_hpet = hpetp->hp_which;
27506diff -urNp linux-2.6.32.44/drivers/char/hvc_beat.c linux-2.6.32.44/drivers/char/hvc_beat.c
27507--- linux-2.6.32.44/drivers/char/hvc_beat.c 2011-03-27 14:31:47.000000000 -0400
27508+++ linux-2.6.32.44/drivers/char/hvc_beat.c 2011-04-17 15:56:46.000000000 -0400
27509@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t v
27510 return cnt;
27511 }
27512
27513-static struct hv_ops hvc_beat_get_put_ops = {
27514+static const struct hv_ops hvc_beat_get_put_ops = {
27515 .get_chars = hvc_beat_get_chars,
27516 .put_chars = hvc_beat_put_chars,
27517 };
27518diff -urNp linux-2.6.32.44/drivers/char/hvc_console.c linux-2.6.32.44/drivers/char/hvc_console.c
27519--- linux-2.6.32.44/drivers/char/hvc_console.c 2011-03-27 14:31:47.000000000 -0400
27520+++ linux-2.6.32.44/drivers/char/hvc_console.c 2011-04-17 15:56:46.000000000 -0400
27521@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_ind
27522 * console interfaces but can still be used as a tty device. This has to be
27523 * static because kmalloc will not work during early console init.
27524 */
27525-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
27526+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
27527 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
27528 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
27529
27530@@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kr
27531 * vty adapters do NOT get an hvc_instantiate() callback since they
27532 * appear after early console init.
27533 */
27534-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
27535+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
27536 {
27537 struct hvc_struct *hp;
27538
27539@@ -756,7 +756,7 @@ static const struct tty_operations hvc_o
27540 };
27541
27542 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
27543- struct hv_ops *ops, int outbuf_size)
27544+ const struct hv_ops *ops, int outbuf_size)
27545 {
27546 struct hvc_struct *hp;
27547 int i;
27548diff -urNp linux-2.6.32.44/drivers/char/hvc_console.h linux-2.6.32.44/drivers/char/hvc_console.h
27549--- linux-2.6.32.44/drivers/char/hvc_console.h 2011-03-27 14:31:47.000000000 -0400
27550+++ linux-2.6.32.44/drivers/char/hvc_console.h 2011-04-17 15:56:46.000000000 -0400
27551@@ -55,7 +55,7 @@ struct hvc_struct {
27552 int outbuf_size;
27553 int n_outbuf;
27554 uint32_t vtermno;
27555- struct hv_ops *ops;
27556+ const struct hv_ops *ops;
27557 int irq_requested;
27558 int data;
27559 struct winsize ws;
27560@@ -76,11 +76,11 @@ struct hv_ops {
27561 };
27562
27563 /* Register a vterm and a slot index for use as a console (console_init) */
27564-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
27565+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
27566
27567 /* register a vterm for hvc tty operation (module_init or hotplug add) */
27568 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
27569- struct hv_ops *ops, int outbuf_size);
27570+ const struct hv_ops *ops, int outbuf_size);
27571 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
27572 extern int hvc_remove(struct hvc_struct *hp);
27573
27574diff -urNp linux-2.6.32.44/drivers/char/hvc_iseries.c linux-2.6.32.44/drivers/char/hvc_iseries.c
27575--- linux-2.6.32.44/drivers/char/hvc_iseries.c 2011-03-27 14:31:47.000000000 -0400
27576+++ linux-2.6.32.44/drivers/char/hvc_iseries.c 2011-04-17 15:56:46.000000000 -0400
27577@@ -197,7 +197,7 @@ done:
27578 return sent;
27579 }
27580
27581-static struct hv_ops hvc_get_put_ops = {
27582+static const struct hv_ops hvc_get_put_ops = {
27583 .get_chars = get_chars,
27584 .put_chars = put_chars,
27585 .notifier_add = notifier_add_irq,
27586diff -urNp linux-2.6.32.44/drivers/char/hvc_iucv.c linux-2.6.32.44/drivers/char/hvc_iucv.c
27587--- linux-2.6.32.44/drivers/char/hvc_iucv.c 2011-03-27 14:31:47.000000000 -0400
27588+++ linux-2.6.32.44/drivers/char/hvc_iucv.c 2011-04-17 15:56:46.000000000 -0400
27589@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(stru
27590
27591
27592 /* HVC operations */
27593-static struct hv_ops hvc_iucv_ops = {
27594+static const struct hv_ops hvc_iucv_ops = {
27595 .get_chars = hvc_iucv_get_chars,
27596 .put_chars = hvc_iucv_put_chars,
27597 .notifier_add = hvc_iucv_notifier_add,
27598diff -urNp linux-2.6.32.44/drivers/char/hvc_rtas.c linux-2.6.32.44/drivers/char/hvc_rtas.c
27599--- linux-2.6.32.44/drivers/char/hvc_rtas.c 2011-03-27 14:31:47.000000000 -0400
27600+++ linux-2.6.32.44/drivers/char/hvc_rtas.c 2011-04-17 15:56:46.000000000 -0400
27601@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_
27602 return i;
27603 }
27604
27605-static struct hv_ops hvc_rtas_get_put_ops = {
27606+static const struct hv_ops hvc_rtas_get_put_ops = {
27607 .get_chars = hvc_rtas_read_console,
27608 .put_chars = hvc_rtas_write_console,
27609 };
27610diff -urNp linux-2.6.32.44/drivers/char/hvcs.c linux-2.6.32.44/drivers/char/hvcs.c
27611--- linux-2.6.32.44/drivers/char/hvcs.c 2011-03-27 14:31:47.000000000 -0400
27612+++ linux-2.6.32.44/drivers/char/hvcs.c 2011-04-17 15:56:46.000000000 -0400
27613@@ -82,6 +82,7 @@
27614 #include <asm/hvcserver.h>
27615 #include <asm/uaccess.h>
27616 #include <asm/vio.h>
27617+#include <asm/local.h>
27618
27619 /*
27620 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
27621@@ -269,7 +270,7 @@ struct hvcs_struct {
27622 unsigned int index;
27623
27624 struct tty_struct *tty;
27625- int open_count;
27626+ local_t open_count;
27627
27628 /*
27629 * Used to tell the driver kernel_thread what operations need to take
27630@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(st
27631
27632 spin_lock_irqsave(&hvcsd->lock, flags);
27633
27634- if (hvcsd->open_count > 0) {
27635+ if (local_read(&hvcsd->open_count) > 0) {
27636 spin_unlock_irqrestore(&hvcsd->lock, flags);
27637 printk(KERN_INFO "HVCS: vterm state unchanged. "
27638 "The hvcs device node is still in use.\n");
27639@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *
27640 if ((retval = hvcs_partner_connect(hvcsd)))
27641 goto error_release;
27642
27643- hvcsd->open_count = 1;
27644+ local_set(&hvcsd->open_count, 1);
27645 hvcsd->tty = tty;
27646 tty->driver_data = hvcsd;
27647
27648@@ -1169,7 +1170,7 @@ fast_open:
27649
27650 spin_lock_irqsave(&hvcsd->lock, flags);
27651 kref_get(&hvcsd->kref);
27652- hvcsd->open_count++;
27653+ local_inc(&hvcsd->open_count);
27654 hvcsd->todo_mask |= HVCS_SCHED_READ;
27655 spin_unlock_irqrestore(&hvcsd->lock, flags);
27656
27657@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct
27658 hvcsd = tty->driver_data;
27659
27660 spin_lock_irqsave(&hvcsd->lock, flags);
27661- if (--hvcsd->open_count == 0) {
27662+ if (local_dec_and_test(&hvcsd->open_count)) {
27663
27664 vio_disable_interrupts(hvcsd->vdev);
27665
27666@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct
27667 free_irq(irq, hvcsd);
27668 kref_put(&hvcsd->kref, destroy_hvcs_struct);
27669 return;
27670- } else if (hvcsd->open_count < 0) {
27671+ } else if (local_read(&hvcsd->open_count) < 0) {
27672 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
27673 " is missmanaged.\n",
27674- hvcsd->vdev->unit_address, hvcsd->open_count);
27675+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
27676 }
27677
27678 spin_unlock_irqrestore(&hvcsd->lock, flags);
27679@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struc
27680
27681 spin_lock_irqsave(&hvcsd->lock, flags);
27682 /* Preserve this so that we know how many kref refs to put */
27683- temp_open_count = hvcsd->open_count;
27684+ temp_open_count = local_read(&hvcsd->open_count);
27685
27686 /*
27687 * Don't kref put inside the spinlock because the destruction
27688@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struc
27689 hvcsd->tty->driver_data = NULL;
27690 hvcsd->tty = NULL;
27691
27692- hvcsd->open_count = 0;
27693+ local_set(&hvcsd->open_count, 0);
27694
27695 /* This will drop any buffered data on the floor which is OK in a hangup
27696 * scenario. */
27697@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct
27698 * the middle of a write operation? This is a crummy place to do this
27699 * but we want to keep it all in the spinlock.
27700 */
27701- if (hvcsd->open_count <= 0) {
27702+ if (local_read(&hvcsd->open_count) <= 0) {
27703 spin_unlock_irqrestore(&hvcsd->lock, flags);
27704 return -ENODEV;
27705 }
27706@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_st
27707 {
27708 struct hvcs_struct *hvcsd = tty->driver_data;
27709
27710- if (!hvcsd || hvcsd->open_count <= 0)
27711+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
27712 return 0;
27713
27714 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
27715diff -urNp linux-2.6.32.44/drivers/char/hvc_udbg.c linux-2.6.32.44/drivers/char/hvc_udbg.c
27716--- linux-2.6.32.44/drivers/char/hvc_udbg.c 2011-03-27 14:31:47.000000000 -0400
27717+++ linux-2.6.32.44/drivers/char/hvc_udbg.c 2011-04-17 15:56:46.000000000 -0400
27718@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno
27719 return i;
27720 }
27721
27722-static struct hv_ops hvc_udbg_ops = {
27723+static const struct hv_ops hvc_udbg_ops = {
27724 .get_chars = hvc_udbg_get,
27725 .put_chars = hvc_udbg_put,
27726 };
27727diff -urNp linux-2.6.32.44/drivers/char/hvc_vio.c linux-2.6.32.44/drivers/char/hvc_vio.c
27728--- linux-2.6.32.44/drivers/char/hvc_vio.c 2011-03-27 14:31:47.000000000 -0400
27729+++ linux-2.6.32.44/drivers/char/hvc_vio.c 2011-04-17 15:56:46.000000000 -0400
27730@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t v
27731 return got;
27732 }
27733
27734-static struct hv_ops hvc_get_put_ops = {
27735+static const struct hv_ops hvc_get_put_ops = {
27736 .get_chars = filtered_get_chars,
27737 .put_chars = hvc_put_chars,
27738 .notifier_add = notifier_add_irq,
27739diff -urNp linux-2.6.32.44/drivers/char/hvc_xen.c linux-2.6.32.44/drivers/char/hvc_xen.c
27740--- linux-2.6.32.44/drivers/char/hvc_xen.c 2011-03-27 14:31:47.000000000 -0400
27741+++ linux-2.6.32.44/drivers/char/hvc_xen.c 2011-04-17 15:56:46.000000000 -0400
27742@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno
27743 return recv;
27744 }
27745
27746-static struct hv_ops hvc_ops = {
27747+static const struct hv_ops hvc_ops = {
27748 .get_chars = read_console,
27749 .put_chars = write_console,
27750 .notifier_add = notifier_add_irq,
27751diff -urNp linux-2.6.32.44/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.32.44/drivers/char/ipmi/ipmi_msghandler.c
27752--- linux-2.6.32.44/drivers/char/ipmi/ipmi_msghandler.c 2011-03-27 14:31:47.000000000 -0400
27753+++ linux-2.6.32.44/drivers/char/ipmi/ipmi_msghandler.c 2011-05-16 21:46:57.000000000 -0400
27754@@ -414,7 +414,7 @@ struct ipmi_smi {
27755 struct proc_dir_entry *proc_dir;
27756 char proc_dir_name[10];
27757
27758- atomic_t stats[IPMI_NUM_STATS];
27759+ atomic_unchecked_t stats[IPMI_NUM_STATS];
27760
27761 /*
27762 * run_to_completion duplicate of smb_info, smi_info
27763@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27764
27765
27766 #define ipmi_inc_stat(intf, stat) \
27767- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27768+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27769 #define ipmi_get_stat(intf, stat) \
27770- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27771+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27772
27773 static int is_lan_addr(struct ipmi_addr *addr)
27774 {
27775@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
27776 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27777 init_waitqueue_head(&intf->waitq);
27778 for (i = 0; i < IPMI_NUM_STATS; i++)
27779- atomic_set(&intf->stats[i], 0);
27780+ atomic_set_unchecked(&intf->stats[i], 0);
27781
27782 intf->proc_dir = NULL;
27783
27784@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
27785 struct ipmi_smi_msg smi_msg;
27786 struct ipmi_recv_msg recv_msg;
27787
27788+ pax_track_stack();
27789+
27790 si = (struct ipmi_system_interface_addr *) &addr;
27791 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
27792 si->channel = IPMI_BMC_CHANNEL;
27793diff -urNp linux-2.6.32.44/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.32.44/drivers/char/ipmi/ipmi_si_intf.c
27794--- linux-2.6.32.44/drivers/char/ipmi/ipmi_si_intf.c 2011-03-27 14:31:47.000000000 -0400
27795+++ linux-2.6.32.44/drivers/char/ipmi/ipmi_si_intf.c 2011-04-17 15:56:46.000000000 -0400
27796@@ -277,7 +277,7 @@ struct smi_info {
27797 unsigned char slave_addr;
27798
27799 /* Counters and things for the proc filesystem. */
27800- atomic_t stats[SI_NUM_STATS];
27801+ atomic_unchecked_t stats[SI_NUM_STATS];
27802
27803 struct task_struct *thread;
27804
27805@@ -285,9 +285,9 @@ struct smi_info {
27806 };
27807
27808 #define smi_inc_stat(smi, stat) \
27809- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27810+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27811 #define smi_get_stat(smi, stat) \
27812- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27813+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27814
27815 #define SI_MAX_PARMS 4
27816
27817@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info
27818 atomic_set(&new_smi->req_events, 0);
27819 new_smi->run_to_completion = 0;
27820 for (i = 0; i < SI_NUM_STATS; i++)
27821- atomic_set(&new_smi->stats[i], 0);
27822+ atomic_set_unchecked(&new_smi->stats[i], 0);
27823
27824 new_smi->interrupt_disabled = 0;
27825 atomic_set(&new_smi->stop_operation, 0);
27826diff -urNp linux-2.6.32.44/drivers/char/istallion.c linux-2.6.32.44/drivers/char/istallion.c
27827--- linux-2.6.32.44/drivers/char/istallion.c 2011-03-27 14:31:47.000000000 -0400
27828+++ linux-2.6.32.44/drivers/char/istallion.c 2011-05-16 21:46:57.000000000 -0400
27829@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios
27830 * re-used for each stats call.
27831 */
27832 static comstats_t stli_comstats;
27833-static combrd_t stli_brdstats;
27834 static struct asystats stli_cdkstats;
27835
27836 /*****************************************************************************/
27837@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __u
27838 {
27839 struct stlibrd *brdp;
27840 unsigned int i;
27841+ combrd_t stli_brdstats;
27842
27843 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
27844 return -EFAULT;
27845@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stl
27846 struct stliport stli_dummyport;
27847 struct stliport *portp;
27848
27849+ pax_track_stack();
27850+
27851 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
27852 return -EFAULT;
27853 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
27854@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stli
27855 struct stlibrd stli_dummybrd;
27856 struct stlibrd *brdp;
27857
27858+ pax_track_stack();
27859+
27860 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
27861 return -EFAULT;
27862 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
27863diff -urNp linux-2.6.32.44/drivers/char/Kconfig linux-2.6.32.44/drivers/char/Kconfig
27864--- linux-2.6.32.44/drivers/char/Kconfig 2011-03-27 14:31:47.000000000 -0400
27865+++ linux-2.6.32.44/drivers/char/Kconfig 2011-04-18 19:20:15.000000000 -0400
27866@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
27867
27868 config DEVKMEM
27869 bool "/dev/kmem virtual device support"
27870- default y
27871+ default n
27872+ depends on !GRKERNSEC_KMEM
27873 help
27874 Say Y here if you want to support the /dev/kmem device. The
27875 /dev/kmem device is rarely used, but can be used for certain
27876@@ -1114,6 +1115,7 @@ config DEVPORT
27877 bool
27878 depends on !M68K
27879 depends on ISA || PCI
27880+ depends on !GRKERNSEC_KMEM
27881 default y
27882
27883 source "drivers/s390/char/Kconfig"
27884diff -urNp linux-2.6.32.44/drivers/char/keyboard.c linux-2.6.32.44/drivers/char/keyboard.c
27885--- linux-2.6.32.44/drivers/char/keyboard.c 2011-03-27 14:31:47.000000000 -0400
27886+++ linux-2.6.32.44/drivers/char/keyboard.c 2011-04-17 15:56:46.000000000 -0400
27887@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
27888 kbd->kbdmode == VC_MEDIUMRAW) &&
27889 value != KVAL(K_SAK))
27890 return; /* SAK is allowed even in raw mode */
27891+
27892+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
27893+ {
27894+ void *func = fn_handler[value];
27895+ if (func == fn_show_state || func == fn_show_ptregs ||
27896+ func == fn_show_mem)
27897+ return;
27898+ }
27899+#endif
27900+
27901 fn_handler[value](vc);
27902 }
27903
27904@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_
27905 .evbit = { BIT_MASK(EV_SND) },
27906 },
27907
27908- { }, /* Terminating entry */
27909+ { 0 }, /* Terminating entry */
27910 };
27911
27912 MODULE_DEVICE_TABLE(input, kbd_ids);
27913diff -urNp linux-2.6.32.44/drivers/char/mem.c linux-2.6.32.44/drivers/char/mem.c
27914--- linux-2.6.32.44/drivers/char/mem.c 2011-03-27 14:31:47.000000000 -0400
27915+++ linux-2.6.32.44/drivers/char/mem.c 2011-04-17 15:56:46.000000000 -0400
27916@@ -18,6 +18,7 @@
27917 #include <linux/raw.h>
27918 #include <linux/tty.h>
27919 #include <linux/capability.h>
27920+#include <linux/security.h>
27921 #include <linux/ptrace.h>
27922 #include <linux/device.h>
27923 #include <linux/highmem.h>
27924@@ -35,6 +36,10 @@
27925 # include <linux/efi.h>
27926 #endif
27927
27928+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27929+extern struct file_operations grsec_fops;
27930+#endif
27931+
27932 static inline unsigned long size_inside_page(unsigned long start,
27933 unsigned long size)
27934 {
27935@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsig
27936
27937 while (cursor < to) {
27938 if (!devmem_is_allowed(pfn)) {
27939+#ifdef CONFIG_GRKERNSEC_KMEM
27940+ gr_handle_mem_readwrite(from, to);
27941+#else
27942 printk(KERN_INFO
27943 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27944 current->comm, from, to);
27945+#endif
27946 return 0;
27947 }
27948 cursor += PAGE_SIZE;
27949@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsig
27950 }
27951 return 1;
27952 }
27953+#elif defined(CONFIG_GRKERNSEC_KMEM)
27954+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27955+{
27956+ return 0;
27957+}
27958 #else
27959 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27960 {
27961@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * fi
27962 #endif
27963
27964 while (count > 0) {
27965+ char *temp;
27966+
27967 /*
27968 * Handle first page in case it's not aligned
27969 */
27970@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * fi
27971 if (!ptr)
27972 return -EFAULT;
27973
27974- if (copy_to_user(buf, ptr, sz)) {
27975+#ifdef CONFIG_PAX_USERCOPY
27976+ temp = kmalloc(sz, GFP_KERNEL);
27977+ if (!temp) {
27978+ unxlate_dev_mem_ptr(p, ptr);
27979+ return -ENOMEM;
27980+ }
27981+ memcpy(temp, ptr, sz);
27982+#else
27983+ temp = ptr;
27984+#endif
27985+
27986+ if (copy_to_user(buf, temp, sz)) {
27987+
27988+#ifdef CONFIG_PAX_USERCOPY
27989+ kfree(temp);
27990+#endif
27991+
27992 unxlate_dev_mem_ptr(p, ptr);
27993 return -EFAULT;
27994 }
27995
27996+#ifdef CONFIG_PAX_USERCOPY
27997+ kfree(temp);
27998+#endif
27999+
28000 unxlate_dev_mem_ptr(p, ptr);
28001
28002 buf += sz;
28003@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *fi
28004 size_t count, loff_t *ppos)
28005 {
28006 unsigned long p = *ppos;
28007- ssize_t low_count, read, sz;
28008+ ssize_t low_count, read, sz, err = 0;
28009 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28010- int err = 0;
28011
28012 read = 0;
28013 if (p < (unsigned long) high_memory) {
28014@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *fi
28015 }
28016 #endif
28017 while (low_count > 0) {
28018+ char *temp;
28019+
28020 sz = size_inside_page(p, low_count);
28021
28022 /*
28023@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *fi
28024 */
28025 kbuf = xlate_dev_kmem_ptr((char *)p);
28026
28027- if (copy_to_user(buf, kbuf, sz))
28028+#ifdef CONFIG_PAX_USERCOPY
28029+ temp = kmalloc(sz, GFP_KERNEL);
28030+ if (!temp)
28031+ return -ENOMEM;
28032+ memcpy(temp, kbuf, sz);
28033+#else
28034+ temp = kbuf;
28035+#endif
28036+
28037+ err = copy_to_user(buf, temp, sz);
28038+
28039+#ifdef CONFIG_PAX_USERCOPY
28040+ kfree(temp);
28041+#endif
28042+
28043+ if (err)
28044 return -EFAULT;
28045 buf += sz;
28046 p += sz;
28047@@ -889,6 +941,9 @@ static const struct memdev {
28048 #ifdef CONFIG_CRASH_DUMP
28049 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28050 #endif
28051+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28052+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28053+#endif
28054 };
28055
28056 static int memory_open(struct inode *inode, struct file *filp)
28057diff -urNp linux-2.6.32.44/drivers/char/pcmcia/ipwireless/tty.c linux-2.6.32.44/drivers/char/pcmcia/ipwireless/tty.c
28058--- linux-2.6.32.44/drivers/char/pcmcia/ipwireless/tty.c 2011-03-27 14:31:47.000000000 -0400
28059+++ linux-2.6.32.44/drivers/char/pcmcia/ipwireless/tty.c 2011-04-17 15:56:46.000000000 -0400
28060@@ -29,6 +29,7 @@
28061 #include <linux/tty_driver.h>
28062 #include <linux/tty_flip.h>
28063 #include <linux/uaccess.h>
28064+#include <asm/local.h>
28065
28066 #include "tty.h"
28067 #include "network.h"
28068@@ -51,7 +52,7 @@ struct ipw_tty {
28069 int tty_type;
28070 struct ipw_network *network;
28071 struct tty_struct *linux_tty;
28072- int open_count;
28073+ local_t open_count;
28074 unsigned int control_lines;
28075 struct mutex ipw_tty_mutex;
28076 int tx_bytes_queued;
28077@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
28078 mutex_unlock(&tty->ipw_tty_mutex);
28079 return -ENODEV;
28080 }
28081- if (tty->open_count == 0)
28082+ if (local_read(&tty->open_count) == 0)
28083 tty->tx_bytes_queued = 0;
28084
28085- tty->open_count++;
28086+ local_inc(&tty->open_count);
28087
28088 tty->linux_tty = linux_tty;
28089 linux_tty->driver_data = tty;
28090@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
28091
28092 static void do_ipw_close(struct ipw_tty *tty)
28093 {
28094- tty->open_count--;
28095-
28096- if (tty->open_count == 0) {
28097+ if (local_dec_return(&tty->open_count) == 0) {
28098 struct tty_struct *linux_tty = tty->linux_tty;
28099
28100 if (linux_tty != NULL) {
28101@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
28102 return;
28103
28104 mutex_lock(&tty->ipw_tty_mutex);
28105- if (tty->open_count == 0) {
28106+ if (local_read(&tty->open_count) == 0) {
28107 mutex_unlock(&tty->ipw_tty_mutex);
28108 return;
28109 }
28110@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
28111 return;
28112 }
28113
28114- if (!tty->open_count) {
28115+ if (!local_read(&tty->open_count)) {
28116 mutex_unlock(&tty->ipw_tty_mutex);
28117 return;
28118 }
28119@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
28120 return -ENODEV;
28121
28122 mutex_lock(&tty->ipw_tty_mutex);
28123- if (!tty->open_count) {
28124+ if (!local_read(&tty->open_count)) {
28125 mutex_unlock(&tty->ipw_tty_mutex);
28126 return -EINVAL;
28127 }
28128@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
28129 if (!tty)
28130 return -ENODEV;
28131
28132- if (!tty->open_count)
28133+ if (!local_read(&tty->open_count))
28134 return -EINVAL;
28135
28136 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
28137@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
28138 if (!tty)
28139 return 0;
28140
28141- if (!tty->open_count)
28142+ if (!local_read(&tty->open_count))
28143 return 0;
28144
28145 return tty->tx_bytes_queued;
28146@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
28147 if (!tty)
28148 return -ENODEV;
28149
28150- if (!tty->open_count)
28151+ if (!local_read(&tty->open_count))
28152 return -EINVAL;
28153
28154 return get_control_lines(tty);
28155@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
28156 if (!tty)
28157 return -ENODEV;
28158
28159- if (!tty->open_count)
28160+ if (!local_read(&tty->open_count))
28161 return -EINVAL;
28162
28163 return set_control_lines(tty, set, clear);
28164@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
28165 if (!tty)
28166 return -ENODEV;
28167
28168- if (!tty->open_count)
28169+ if (!local_read(&tty->open_count))
28170 return -EINVAL;
28171
28172 /* FIXME: Exactly how is the tty object locked here .. */
28173@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty
28174 against a parallel ioctl etc */
28175 mutex_lock(&ttyj->ipw_tty_mutex);
28176 }
28177- while (ttyj->open_count)
28178+ while (local_read(&ttyj->open_count))
28179 do_ipw_close(ttyj);
28180 ipwireless_disassociate_network_ttys(network,
28181 ttyj->channel_idx);
28182diff -urNp linux-2.6.32.44/drivers/char/pty.c linux-2.6.32.44/drivers/char/pty.c
28183--- linux-2.6.32.44/drivers/char/pty.c 2011-03-27 14:31:47.000000000 -0400
28184+++ linux-2.6.32.44/drivers/char/pty.c 2011-08-05 20:33:55.000000000 -0400
28185@@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
28186 register_sysctl_table(pty_root_table);
28187
28188 /* Now create the /dev/ptmx special device */
28189+ pax_open_kernel();
28190 tty_default_fops(&ptmx_fops);
28191- ptmx_fops.open = ptmx_open;
28192+ *(void **)&ptmx_fops.open = ptmx_open;
28193+ pax_close_kernel();
28194
28195 cdev_init(&ptmx_cdev, &ptmx_fops);
28196 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
28197diff -urNp linux-2.6.32.44/drivers/char/random.c linux-2.6.32.44/drivers/char/random.c
28198--- linux-2.6.32.44/drivers/char/random.c 2011-03-27 14:31:47.000000000 -0400
28199+++ linux-2.6.32.44/drivers/char/random.c 2011-08-07 19:48:09.000000000 -0400
28200@@ -254,8 +254,13 @@
28201 /*
28202 * Configuration information
28203 */
28204+#ifdef CONFIG_GRKERNSEC_RANDNET
28205+#define INPUT_POOL_WORDS 512
28206+#define OUTPUT_POOL_WORDS 128
28207+#else
28208 #define INPUT_POOL_WORDS 128
28209 #define OUTPUT_POOL_WORDS 32
28210+#endif
28211 #define SEC_XFER_SIZE 512
28212
28213 /*
28214@@ -292,10 +297,17 @@ static struct poolinfo {
28215 int poolwords;
28216 int tap1, tap2, tap3, tap4, tap5;
28217 } poolinfo_table[] = {
28218+#ifdef CONFIG_GRKERNSEC_RANDNET
28219+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28220+ { 512, 411, 308, 208, 104, 1 },
28221+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28222+ { 128, 103, 76, 51, 25, 1 },
28223+#else
28224 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28225 { 128, 103, 76, 51, 25, 1 },
28226 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28227 { 32, 26, 20, 14, 7, 1 },
28228+#endif
28229 #if 0
28230 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28231 { 2048, 1638, 1231, 819, 411, 1 },
28232@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28233 #include <linux/sysctl.h>
28234
28235 static int min_read_thresh = 8, min_write_thresh;
28236-static int max_read_thresh = INPUT_POOL_WORDS * 32;
28237+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28238 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28239 static char sysctl_bootid[16];
28240
28241@@ -1339,330 +1351,14 @@ ctl_table random_table[] = {
28242 };
28243 #endif /* CONFIG_SYSCTL */
28244
28245-/********************************************************************
28246- *
28247- * Random funtions for networking
28248- *
28249- ********************************************************************/
28250-
28251-/*
28252- * TCP initial sequence number picking. This uses the random number
28253- * generator to pick an initial secret value. This value is hashed
28254- * along with the TCP endpoint information to provide a unique
28255- * starting point for each pair of TCP endpoints. This defeats
28256- * attacks which rely on guessing the initial TCP sequence number.
28257- * This algorithm was suggested by Steve Bellovin.
28258- *
28259- * Using a very strong hash was taking an appreciable amount of the total
28260- * TCP connection establishment time, so this is a weaker hash,
28261- * compensated for by changing the secret periodically.
28262- */
28263-
28264-/* F, G and H are basic MD4 functions: selection, majority, parity */
28265-#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
28266-#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
28267-#define H(x, y, z) ((x) ^ (y) ^ (z))
28268-
28269-/*
28270- * The generic round function. The application is so specific that
28271- * we don't bother protecting all the arguments with parens, as is generally
28272- * good macro practice, in favor of extra legibility.
28273- * Rotation is separate from addition to prevent recomputation
28274- */
28275-#define ROUND(f, a, b, c, d, x, s) \
28276- (a += f(b, c, d) + x, a = (a << s) | (a >> (32 - s)))
28277-#define K1 0
28278-#define K2 013240474631UL
28279-#define K3 015666365641UL
28280-
28281-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
28282-
28283-static __u32 twothirdsMD4Transform(__u32 const buf[4], __u32 const in[12])
28284-{
28285- __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
28286-
28287- /* Round 1 */
28288- ROUND(F, a, b, c, d, in[ 0] + K1, 3);
28289- ROUND(F, d, a, b, c, in[ 1] + K1, 7);
28290- ROUND(F, c, d, a, b, in[ 2] + K1, 11);
28291- ROUND(F, b, c, d, a, in[ 3] + K1, 19);
28292- ROUND(F, a, b, c, d, in[ 4] + K1, 3);
28293- ROUND(F, d, a, b, c, in[ 5] + K1, 7);
28294- ROUND(F, c, d, a, b, in[ 6] + K1, 11);
28295- ROUND(F, b, c, d, a, in[ 7] + K1, 19);
28296- ROUND(F, a, b, c, d, in[ 8] + K1, 3);
28297- ROUND(F, d, a, b, c, in[ 9] + K1, 7);
28298- ROUND(F, c, d, a, b, in[10] + K1, 11);
28299- ROUND(F, b, c, d, a, in[11] + K1, 19);
28300-
28301- /* Round 2 */
28302- ROUND(G, a, b, c, d, in[ 1] + K2, 3);
28303- ROUND(G, d, a, b, c, in[ 3] + K2, 5);
28304- ROUND(G, c, d, a, b, in[ 5] + K2, 9);
28305- ROUND(G, b, c, d, a, in[ 7] + K2, 13);
28306- ROUND(G, a, b, c, d, in[ 9] + K2, 3);
28307- ROUND(G, d, a, b, c, in[11] + K2, 5);
28308- ROUND(G, c, d, a, b, in[ 0] + K2, 9);
28309- ROUND(G, b, c, d, a, in[ 2] + K2, 13);
28310- ROUND(G, a, b, c, d, in[ 4] + K2, 3);
28311- ROUND(G, d, a, b, c, in[ 6] + K2, 5);
28312- ROUND(G, c, d, a, b, in[ 8] + K2, 9);
28313- ROUND(G, b, c, d, a, in[10] + K2, 13);
28314-
28315- /* Round 3 */
28316- ROUND(H, a, b, c, d, in[ 3] + K3, 3);
28317- ROUND(H, d, a, b, c, in[ 7] + K3, 9);
28318- ROUND(H, c, d, a, b, in[11] + K3, 11);
28319- ROUND(H, b, c, d, a, in[ 2] + K3, 15);
28320- ROUND(H, a, b, c, d, in[ 6] + K3, 3);
28321- ROUND(H, d, a, b, c, in[10] + K3, 9);
28322- ROUND(H, c, d, a, b, in[ 1] + K3, 11);
28323- ROUND(H, b, c, d, a, in[ 5] + K3, 15);
28324- ROUND(H, a, b, c, d, in[ 9] + K3, 3);
28325- ROUND(H, d, a, b, c, in[ 0] + K3, 9);
28326- ROUND(H, c, d, a, b, in[ 4] + K3, 11);
28327- ROUND(H, b, c, d, a, in[ 8] + K3, 15);
28328-
28329- return buf[1] + b; /* "most hashed" word */
28330- /* Alternative: return sum of all words? */
28331-}
28332-#endif
28333-
28334-#undef ROUND
28335-#undef F
28336-#undef G
28337-#undef H
28338-#undef K1
28339-#undef K2
28340-#undef K3
28341-
28342-/* This should not be decreased so low that ISNs wrap too fast. */
28343-#define REKEY_INTERVAL (300 * HZ)
28344-/*
28345- * Bit layout of the tcp sequence numbers (before adding current time):
28346- * bit 24-31: increased after every key exchange
28347- * bit 0-23: hash(source,dest)
28348- *
28349- * The implementation is similar to the algorithm described
28350- * in the Appendix of RFC 1185, except that
28351- * - it uses a 1 MHz clock instead of a 250 kHz clock
28352- * - it performs a rekey every 5 minutes, which is equivalent
28353- * to a (source,dest) tulple dependent forward jump of the
28354- * clock by 0..2^(HASH_BITS+1)
28355- *
28356- * Thus the average ISN wraparound time is 68 minutes instead of
28357- * 4.55 hours.
28358- *
28359- * SMP cleanup and lock avoidance with poor man's RCU.
28360- * Manfred Spraul <manfred@colorfullife.com>
28361- *
28362- */
28363-#define COUNT_BITS 8
28364-#define COUNT_MASK ((1 << COUNT_BITS) - 1)
28365-#define HASH_BITS 24
28366-#define HASH_MASK ((1 << HASH_BITS) - 1)
28367-
28368-static struct keydata {
28369- __u32 count; /* already shifted to the final position */
28370- __u32 secret[12];
28371-} ____cacheline_aligned ip_keydata[2];
28372-
28373-static unsigned int ip_cnt;
28374-
28375-static void rekey_seq_generator(struct work_struct *work);
28376-
28377-static DECLARE_DELAYED_WORK(rekey_work, rekey_seq_generator);
28378-
28379-/*
28380- * Lock avoidance:
28381- * The ISN generation runs lockless - it's just a hash over random data.
28382- * State changes happen every 5 minutes when the random key is replaced.
28383- * Synchronization is performed by having two copies of the hash function
28384- * state and rekey_seq_generator always updates the inactive copy.
28385- * The copy is then activated by updating ip_cnt.
28386- * The implementation breaks down if someone blocks the thread
28387- * that processes SYN requests for more than 5 minutes. Should never
28388- * happen, and even if that happens only a not perfectly compliant
28389- * ISN is generated, nothing fatal.
28390- */
28391-static void rekey_seq_generator(struct work_struct *work)
28392-{
28393- struct keydata *keyptr = &ip_keydata[1 ^ (ip_cnt & 1)];
28394-
28395- get_random_bytes(keyptr->secret, sizeof(keyptr->secret));
28396- keyptr->count = (ip_cnt & COUNT_MASK) << HASH_BITS;
28397- smp_wmb();
28398- ip_cnt++;
28399- schedule_delayed_work(&rekey_work,
28400- round_jiffies_relative(REKEY_INTERVAL));
28401-}
28402-
28403-static inline struct keydata *get_keyptr(void)
28404-{
28405- struct keydata *keyptr = &ip_keydata[ip_cnt & 1];
28406-
28407- smp_rmb();
28408-
28409- return keyptr;
28410-}
28411-
28412-static __init int seqgen_init(void)
28413+static u32 random_int_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
28414+static int __init random_int_secret_init(void)
28415 {
28416- rekey_seq_generator(NULL);
28417+ get_random_bytes(random_int_secret, sizeof(random_int_secret));
28418 return 0;
28419 }
28420-late_initcall(seqgen_init);
28421-
28422-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
28423-__u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
28424- __be16 sport, __be16 dport)
28425-{
28426- __u32 seq;
28427- __u32 hash[12];
28428- struct keydata *keyptr = get_keyptr();
28429-
28430- /* The procedure is the same as for IPv4, but addresses are longer.
28431- * Thus we must use twothirdsMD4Transform.
28432- */
28433-
28434- memcpy(hash, saddr, 16);
28435- hash[4] = ((__force u16)sport << 16) + (__force u16)dport;
28436- memcpy(&hash[5], keyptr->secret, sizeof(__u32) * 7);
28437-
28438- seq = twothirdsMD4Transform((const __u32 *)daddr, hash) & HASH_MASK;
28439- seq += keyptr->count;
28440-
28441- seq += ktime_to_ns(ktime_get_real());
28442-
28443- return seq;
28444-}
28445-EXPORT_SYMBOL(secure_tcpv6_sequence_number);
28446-#endif
28447-
28448-/* The code below is shamelessly stolen from secure_tcp_sequence_number().
28449- * All blames to Andrey V. Savochkin <saw@msu.ru>.
28450- */
28451-__u32 secure_ip_id(__be32 daddr)
28452-{
28453- struct keydata *keyptr;
28454- __u32 hash[4];
28455-
28456- keyptr = get_keyptr();
28457-
28458- /*
28459- * Pick a unique starting offset for each IP destination.
28460- * The dest ip address is placed in the starting vector,
28461- * which is then hashed with random data.
28462- */
28463- hash[0] = (__force __u32)daddr;
28464- hash[1] = keyptr->secret[9];
28465- hash[2] = keyptr->secret[10];
28466- hash[3] = keyptr->secret[11];
28467-
28468- return half_md4_transform(hash, keyptr->secret);
28469-}
28470-
28471-#ifdef CONFIG_INET
28472-
28473-__u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
28474- __be16 sport, __be16 dport)
28475-{
28476- __u32 seq;
28477- __u32 hash[4];
28478- struct keydata *keyptr = get_keyptr();
28479-
28480- /*
28481- * Pick a unique starting offset for each TCP connection endpoints
28482- * (saddr, daddr, sport, dport).
28483- * Note that the words are placed into the starting vector, which is
28484- * then mixed with a partial MD4 over random data.
28485- */
28486- hash[0] = (__force u32)saddr;
28487- hash[1] = (__force u32)daddr;
28488- hash[2] = ((__force u16)sport << 16) + (__force u16)dport;
28489- hash[3] = keyptr->secret[11];
28490-
28491- seq = half_md4_transform(hash, keyptr->secret) & HASH_MASK;
28492- seq += keyptr->count;
28493- /*
28494- * As close as possible to RFC 793, which
28495- * suggests using a 250 kHz clock.
28496- * Further reading shows this assumes 2 Mb/s networks.
28497- * For 10 Mb/s Ethernet, a 1 MHz clock is appropriate.
28498- * For 10 Gb/s Ethernet, a 1 GHz clock should be ok, but
28499- * we also need to limit the resolution so that the u32 seq
28500- * overlaps less than one time per MSL (2 minutes).
28501- * Choosing a clock of 64 ns period is OK. (period of 274 s)
28502- */
28503- seq += ktime_to_ns(ktime_get_real()) >> 6;
28504-
28505- return seq;
28506-}
28507-
28508-/* Generate secure starting point for ephemeral IPV4 transport port search */
28509-u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport)
28510-{
28511- struct keydata *keyptr = get_keyptr();
28512- u32 hash[4];
28513-
28514- /*
28515- * Pick a unique starting offset for each ephemeral port search
28516- * (saddr, daddr, dport) and 48bits of random data.
28517- */
28518- hash[0] = (__force u32)saddr;
28519- hash[1] = (__force u32)daddr;
28520- hash[2] = (__force u32)dport ^ keyptr->secret[10];
28521- hash[3] = keyptr->secret[11];
28522-
28523- return half_md4_transform(hash, keyptr->secret);
28524-}
28525-EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral);
28526-
28527-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
28528-u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
28529- __be16 dport)
28530-{
28531- struct keydata *keyptr = get_keyptr();
28532- u32 hash[12];
28533-
28534- memcpy(hash, saddr, 16);
28535- hash[4] = (__force u32)dport;
28536- memcpy(&hash[5], keyptr->secret, sizeof(__u32) * 7);
28537-
28538- return twothirdsMD4Transform((const __u32 *)daddr, hash);
28539-}
28540-#endif
28541-
28542-#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
28543-/* Similar to secure_tcp_sequence_number but generate a 48 bit value
28544- * bit's 32-47 increase every key exchange
28545- * 0-31 hash(source, dest)
28546- */
28547-u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
28548- __be16 sport, __be16 dport)
28549-{
28550- u64 seq;
28551- __u32 hash[4];
28552- struct keydata *keyptr = get_keyptr();
28553-
28554- hash[0] = (__force u32)saddr;
28555- hash[1] = (__force u32)daddr;
28556- hash[2] = ((__force u16)sport << 16) + (__force u16)dport;
28557- hash[3] = keyptr->secret[11];
28558-
28559- seq = half_md4_transform(hash, keyptr->secret);
28560- seq |= ((u64)keyptr->count) << (32 - HASH_BITS);
28561-
28562- seq += ktime_to_ns(ktime_get_real());
28563- seq &= (1ull << 48) - 1;
28564-
28565- return seq;
28566-}
28567-EXPORT_SYMBOL(secure_dccp_sequence_number);
28568-#endif
28569-
28570-#endif /* CONFIG_INET */
28571
28572+late_initcall(random_int_secret_init);
28573
28574 /*
28575 * Get a random word for internal kernel use only. Similar to urandom but
28576@@ -1670,17 +1366,16 @@ EXPORT_SYMBOL(secure_dccp_sequence_numbe
28577 * value is not cryptographically secure but for several uses the cost of
28578 * depleting entropy is too high
28579 */
28580-DEFINE_PER_CPU(__u32 [4], get_random_int_hash);
28581+DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash);
28582 unsigned int get_random_int(void)
28583 {
28584- struct keydata *keyptr;
28585 __u32 *hash = get_cpu_var(get_random_int_hash);
28586- int ret;
28587+ unsigned int ret;
28588
28589- keyptr = get_keyptr();
28590 hash[0] += current->pid + jiffies + get_cycles();
28591
28592- ret = half_md4_transform(hash, keyptr->secret);
28593+ md5_transform(hash, random_int_secret);
28594+ ret = hash[0];
28595 put_cpu_var(get_random_int_hash);
28596
28597 return ret;
28598diff -urNp linux-2.6.32.44/drivers/char/rocket.c linux-2.6.32.44/drivers/char/rocket.c
28599--- linux-2.6.32.44/drivers/char/rocket.c 2011-03-27 14:31:47.000000000 -0400
28600+++ linux-2.6.32.44/drivers/char/rocket.c 2011-05-16 21:46:57.000000000 -0400
28601@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info
28602 struct rocket_ports tmp;
28603 int board;
28604
28605+ pax_track_stack();
28606+
28607 if (!retports)
28608 return -EFAULT;
28609 memset(&tmp, 0, sizeof (tmp));
28610diff -urNp linux-2.6.32.44/drivers/char/sonypi.c linux-2.6.32.44/drivers/char/sonypi.c
28611--- linux-2.6.32.44/drivers/char/sonypi.c 2011-03-27 14:31:47.000000000 -0400
28612+++ linux-2.6.32.44/drivers/char/sonypi.c 2011-04-17 15:56:46.000000000 -0400
28613@@ -55,6 +55,7 @@
28614 #include <asm/uaccess.h>
28615 #include <asm/io.h>
28616 #include <asm/system.h>
28617+#include <asm/local.h>
28618
28619 #include <linux/sonypi.h>
28620
28621@@ -491,7 +492,7 @@ static struct sonypi_device {
28622 spinlock_t fifo_lock;
28623 wait_queue_head_t fifo_proc_list;
28624 struct fasync_struct *fifo_async;
28625- int open_count;
28626+ local_t open_count;
28627 int model;
28628 struct input_dev *input_jog_dev;
28629 struct input_dev *input_key_dev;
28630@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, st
28631 static int sonypi_misc_release(struct inode *inode, struct file *file)
28632 {
28633 mutex_lock(&sonypi_device.lock);
28634- sonypi_device.open_count--;
28635+ local_dec(&sonypi_device.open_count);
28636 mutex_unlock(&sonypi_device.lock);
28637 return 0;
28638 }
28639@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode
28640 lock_kernel();
28641 mutex_lock(&sonypi_device.lock);
28642 /* Flush input queue on first open */
28643- if (!sonypi_device.open_count)
28644+ if (!local_read(&sonypi_device.open_count))
28645 kfifo_reset(sonypi_device.fifo);
28646- sonypi_device.open_count++;
28647+ local_inc(&sonypi_device.open_count);
28648 mutex_unlock(&sonypi_device.lock);
28649 unlock_kernel();
28650 return 0;
28651diff -urNp linux-2.6.32.44/drivers/char/stallion.c linux-2.6.32.44/drivers/char/stallion.c
28652--- linux-2.6.32.44/drivers/char/stallion.c 2011-03-27 14:31:47.000000000 -0400
28653+++ linux-2.6.32.44/drivers/char/stallion.c 2011-05-16 21:46:57.000000000 -0400
28654@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlp
28655 struct stlport stl_dummyport;
28656 struct stlport *portp;
28657
28658+ pax_track_stack();
28659+
28660 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
28661 return -EFAULT;
28662 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
28663diff -urNp linux-2.6.32.44/drivers/char/tpm/tpm_bios.c linux-2.6.32.44/drivers/char/tpm/tpm_bios.c
28664--- linux-2.6.32.44/drivers/char/tpm/tpm_bios.c 2011-03-27 14:31:47.000000000 -0400
28665+++ linux-2.6.32.44/drivers/char/tpm/tpm_bios.c 2011-04-17 15:56:46.000000000 -0400
28666@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start
28667 event = addr;
28668
28669 if ((event->event_type == 0 && event->event_size == 0) ||
28670- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28671+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28672 return NULL;
28673
28674 return addr;
28675@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(
28676 return NULL;
28677
28678 if ((event->event_type == 0 && event->event_size == 0) ||
28679- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28680+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28681 return NULL;
28682
28683 (*pos)++;
28684@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_
28685 int i;
28686
28687 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28688- seq_putc(m, data[i]);
28689+ if (!seq_putc(m, data[i]))
28690+ return -EFAULT;
28691
28692 return 0;
28693 }
28694@@ -409,6 +410,11 @@ static int read_log(struct tpm_bios_log
28695 log->bios_event_log_end = log->bios_event_log + len;
28696
28697 virt = acpi_os_map_memory(start, len);
28698+ if (!virt) {
28699+ kfree(log->bios_event_log);
28700+ log->bios_event_log = NULL;
28701+ return -EFAULT;
28702+ }
28703
28704 memcpy(log->bios_event_log, virt, len);
28705
28706diff -urNp linux-2.6.32.44/drivers/char/tpm/tpm.c linux-2.6.32.44/drivers/char/tpm/tpm.c
28707--- linux-2.6.32.44/drivers/char/tpm/tpm.c 2011-04-17 17:00:52.000000000 -0400
28708+++ linux-2.6.32.44/drivers/char/tpm/tpm.c 2011-05-16 21:46:57.000000000 -0400
28709@@ -402,7 +402,7 @@ static ssize_t tpm_transmit(struct tpm_c
28710 chip->vendor.req_complete_val)
28711 goto out_recv;
28712
28713- if ((status == chip->vendor.req_canceled)) {
28714+ if (status == chip->vendor.req_canceled) {
28715 dev_err(chip->dev, "Operation Canceled\n");
28716 rc = -ECANCELED;
28717 goto out;
28718@@ -821,6 +821,8 @@ ssize_t tpm_show_pubek(struct device *de
28719
28720 struct tpm_chip *chip = dev_get_drvdata(dev);
28721
28722+ pax_track_stack();
28723+
28724 tpm_cmd.header.in = tpm_readpubek_header;
28725 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28726 "attempting to read the PUBEK");
28727diff -urNp linux-2.6.32.44/drivers/char/tty_io.c linux-2.6.32.44/drivers/char/tty_io.c
28728--- linux-2.6.32.44/drivers/char/tty_io.c 2011-03-27 14:31:47.000000000 -0400
28729+++ linux-2.6.32.44/drivers/char/tty_io.c 2011-08-05 20:33:55.000000000 -0400
28730@@ -2582,8 +2582,10 @@ long tty_ioctl(struct file *file, unsign
28731 return retval;
28732 }
28733
28734+EXPORT_SYMBOL(tty_ioctl);
28735+
28736 #ifdef CONFIG_COMPAT
28737-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
28738+long tty_compat_ioctl(struct file *file, unsigned int cmd,
28739 unsigned long arg)
28740 {
28741 struct inode *inode = file->f_dentry->d_inode;
28742@@ -2607,6 +2609,8 @@ static long tty_compat_ioctl(struct file
28743
28744 return retval;
28745 }
28746+
28747+EXPORT_SYMBOL(tty_compat_ioctl);
28748 #endif
28749
28750 /*
28751@@ -3052,7 +3056,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
28752
28753 void tty_default_fops(struct file_operations *fops)
28754 {
28755- *fops = tty_fops;
28756+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
28757 }
28758
28759 /*
28760diff -urNp linux-2.6.32.44/drivers/char/tty_ldisc.c linux-2.6.32.44/drivers/char/tty_ldisc.c
28761--- linux-2.6.32.44/drivers/char/tty_ldisc.c 2011-07-13 17:23:04.000000000 -0400
28762+++ linux-2.6.32.44/drivers/char/tty_ldisc.c 2011-07-13 17:23:18.000000000 -0400
28763@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
28764 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
28765 struct tty_ldisc_ops *ldo = ld->ops;
28766
28767- ldo->refcount--;
28768+ atomic_dec(&ldo->refcount);
28769 module_put(ldo->owner);
28770 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
28771
28772@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
28773 spin_lock_irqsave(&tty_ldisc_lock, flags);
28774 tty_ldiscs[disc] = new_ldisc;
28775 new_ldisc->num = disc;
28776- new_ldisc->refcount = 0;
28777+ atomic_set(&new_ldisc->refcount, 0);
28778 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
28779
28780 return ret;
28781@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
28782 return -EINVAL;
28783
28784 spin_lock_irqsave(&tty_ldisc_lock, flags);
28785- if (tty_ldiscs[disc]->refcount)
28786+ if (atomic_read(&tty_ldiscs[disc]->refcount))
28787 ret = -EBUSY;
28788 else
28789 tty_ldiscs[disc] = NULL;
28790@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
28791 if (ldops) {
28792 ret = ERR_PTR(-EAGAIN);
28793 if (try_module_get(ldops->owner)) {
28794- ldops->refcount++;
28795+ atomic_inc(&ldops->refcount);
28796 ret = ldops;
28797 }
28798 }
28799@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
28800 unsigned long flags;
28801
28802 spin_lock_irqsave(&tty_ldisc_lock, flags);
28803- ldops->refcount--;
28804+ atomic_dec(&ldops->refcount);
28805 module_put(ldops->owner);
28806 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
28807 }
28808diff -urNp linux-2.6.32.44/drivers/char/virtio_console.c linux-2.6.32.44/drivers/char/virtio_console.c
28809--- linux-2.6.32.44/drivers/char/virtio_console.c 2011-03-27 14:31:47.000000000 -0400
28810+++ linux-2.6.32.44/drivers/char/virtio_console.c 2011-08-05 20:33:55.000000000 -0400
28811@@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *
28812 * virtqueue, so we let the drivers do some boutique early-output thing. */
28813 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
28814 {
28815- virtio_cons.put_chars = put_chars;
28816+ pax_open_kernel();
28817+ *(void **)&virtio_cons.put_chars = put_chars;
28818+ pax_close_kernel();
28819 return hvc_instantiate(0, 0, &virtio_cons);
28820 }
28821
28822@@ -213,11 +215,13 @@ static int __devinit virtcons_probe(stru
28823 out_vq = vqs[1];
28824
28825 /* Start using the new console output. */
28826- virtio_cons.get_chars = get_chars;
28827- virtio_cons.put_chars = put_chars;
28828- virtio_cons.notifier_add = notifier_add_vio;
28829- virtio_cons.notifier_del = notifier_del_vio;
28830- virtio_cons.notifier_hangup = notifier_del_vio;
28831+ pax_open_kernel();
28832+ *(void **)&virtio_cons.get_chars = get_chars;
28833+ *(void **)&virtio_cons.put_chars = put_chars;
28834+ *(void **)&virtio_cons.notifier_add = notifier_add_vio;
28835+ *(void **)&virtio_cons.notifier_del = notifier_del_vio;
28836+ *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
28837+ pax_close_kernel();
28838
28839 /* The first argument of hvc_alloc() is the virtual console number, so
28840 * we use zero. The second argument is the parameter for the
28841diff -urNp linux-2.6.32.44/drivers/char/vt.c linux-2.6.32.44/drivers/char/vt.c
28842--- linux-2.6.32.44/drivers/char/vt.c 2011-03-27 14:31:47.000000000 -0400
28843+++ linux-2.6.32.44/drivers/char/vt.c 2011-04-17 15:56:46.000000000 -0400
28844@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
28845
28846 static void notify_write(struct vc_data *vc, unsigned int unicode)
28847 {
28848- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
28849+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
28850 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
28851 }
28852
28853diff -urNp linux-2.6.32.44/drivers/char/vt_ioctl.c linux-2.6.32.44/drivers/char/vt_ioctl.c
28854--- linux-2.6.32.44/drivers/char/vt_ioctl.c 2011-03-27 14:31:47.000000000 -0400
28855+++ linux-2.6.32.44/drivers/char/vt_ioctl.c 2011-04-17 15:56:46.000000000 -0400
28856@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28857 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
28858 return -EFAULT;
28859
28860- if (!capable(CAP_SYS_TTY_CONFIG))
28861- perm = 0;
28862-
28863 switch (cmd) {
28864 case KDGKBENT:
28865 key_map = key_maps[s];
28866@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28867 val = (i ? K_HOLE : K_NOSUCHMAP);
28868 return put_user(val, &user_kbe->kb_value);
28869 case KDSKBENT:
28870+ if (!capable(CAP_SYS_TTY_CONFIG))
28871+ perm = 0;
28872+
28873 if (!perm)
28874 return -EPERM;
28875+
28876 if (!i && v == K_NOSUCHMAP) {
28877 /* deallocate map */
28878 key_map = key_maps[s];
28879@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28880 int i, j, k;
28881 int ret;
28882
28883- if (!capable(CAP_SYS_TTY_CONFIG))
28884- perm = 0;
28885-
28886 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
28887 if (!kbs) {
28888 ret = -ENOMEM;
28889@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28890 kfree(kbs);
28891 return ((p && *p) ? -EOVERFLOW : 0);
28892 case KDSKBSENT:
28893+ if (!capable(CAP_SYS_TTY_CONFIG))
28894+ perm = 0;
28895+
28896 if (!perm) {
28897 ret = -EPERM;
28898 goto reterr;
28899diff -urNp linux-2.6.32.44/drivers/cpufreq/cpufreq.c linux-2.6.32.44/drivers/cpufreq/cpufreq.c
28900--- linux-2.6.32.44/drivers/cpufreq/cpufreq.c 2011-06-25 12:55:34.000000000 -0400
28901+++ linux-2.6.32.44/drivers/cpufreq/cpufreq.c 2011-06-25 12:56:37.000000000 -0400
28902@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct
28903 complete(&policy->kobj_unregister);
28904 }
28905
28906-static struct sysfs_ops sysfs_ops = {
28907+static const struct sysfs_ops sysfs_ops = {
28908 .show = show,
28909 .store = store,
28910 };
28911diff -urNp linux-2.6.32.44/drivers/cpuidle/sysfs.c linux-2.6.32.44/drivers/cpuidle/sysfs.c
28912--- linux-2.6.32.44/drivers/cpuidle/sysfs.c 2011-03-27 14:31:47.000000000 -0400
28913+++ linux-2.6.32.44/drivers/cpuidle/sysfs.c 2011-04-17 15:56:46.000000000 -0400
28914@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobj
28915 return ret;
28916 }
28917
28918-static struct sysfs_ops cpuidle_sysfs_ops = {
28919+static const struct sysfs_ops cpuidle_sysfs_ops = {
28920 .show = cpuidle_show,
28921 .store = cpuidle_store,
28922 };
28923@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct
28924 return ret;
28925 }
28926
28927-static struct sysfs_ops cpuidle_state_sysfs_ops = {
28928+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
28929 .show = cpuidle_state_show,
28930 };
28931
28932@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpui
28933 .release = cpuidle_state_sysfs_release,
28934 };
28935
28936-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
28937+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
28938 {
28939 kobject_put(&device->kobjs[i]->kobj);
28940 wait_for_completion(&device->kobjs[i]->kobj_unregister);
28941diff -urNp linux-2.6.32.44/drivers/crypto/hifn_795x.c linux-2.6.32.44/drivers/crypto/hifn_795x.c
28942--- linux-2.6.32.44/drivers/crypto/hifn_795x.c 2011-03-27 14:31:47.000000000 -0400
28943+++ linux-2.6.32.44/drivers/crypto/hifn_795x.c 2011-05-16 21:46:57.000000000 -0400
28944@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28945 0xCA, 0x34, 0x2B, 0x2E};
28946 struct scatterlist sg;
28947
28948+ pax_track_stack();
28949+
28950 memset(src, 0, sizeof(src));
28951 memset(ctx.key, 0, sizeof(ctx.key));
28952
28953diff -urNp linux-2.6.32.44/drivers/crypto/padlock-aes.c linux-2.6.32.44/drivers/crypto/padlock-aes.c
28954--- linux-2.6.32.44/drivers/crypto/padlock-aes.c 2011-03-27 14:31:47.000000000 -0400
28955+++ linux-2.6.32.44/drivers/crypto/padlock-aes.c 2011-05-16 21:46:57.000000000 -0400
28956@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm
28957 struct crypto_aes_ctx gen_aes;
28958 int cpu;
28959
28960+ pax_track_stack();
28961+
28962 if (key_len % 8) {
28963 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28964 return -EINVAL;
28965diff -urNp linux-2.6.32.44/drivers/dma/ioat/dma.c linux-2.6.32.44/drivers/dma/ioat/dma.c
28966--- linux-2.6.32.44/drivers/dma/ioat/dma.c 2011-03-27 14:31:47.000000000 -0400
28967+++ linux-2.6.32.44/drivers/dma/ioat/dma.c 2011-04-17 15:56:46.000000000 -0400
28968@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, str
28969 return entry->show(&chan->common, page);
28970 }
28971
28972-struct sysfs_ops ioat_sysfs_ops = {
28973+const struct sysfs_ops ioat_sysfs_ops = {
28974 .show = ioat_attr_show,
28975 };
28976
28977diff -urNp linux-2.6.32.44/drivers/dma/ioat/dma.h linux-2.6.32.44/drivers/dma/ioat/dma.h
28978--- linux-2.6.32.44/drivers/dma/ioat/dma.h 2011-03-27 14:31:47.000000000 -0400
28979+++ linux-2.6.32.44/drivers/dma/ioat/dma.h 2011-04-17 15:56:46.000000000 -0400
28980@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_c
28981 unsigned long *phys_complete);
28982 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
28983 void ioat_kobject_del(struct ioatdma_device *device);
28984-extern struct sysfs_ops ioat_sysfs_ops;
28985+extern const struct sysfs_ops ioat_sysfs_ops;
28986 extern struct ioat_sysfs_entry ioat_version_attr;
28987 extern struct ioat_sysfs_entry ioat_cap_attr;
28988 #endif /* IOATDMA_H */
28989diff -urNp linux-2.6.32.44/drivers/edac/edac_device_sysfs.c linux-2.6.32.44/drivers/edac/edac_device_sysfs.c
28990--- linux-2.6.32.44/drivers/edac/edac_device_sysfs.c 2011-03-27 14:31:47.000000000 -0400
28991+++ linux-2.6.32.44/drivers/edac/edac_device_sysfs.c 2011-04-17 15:56:46.000000000 -0400
28992@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(s
28993 }
28994
28995 /* edac_dev file operations for an 'ctl_info' */
28996-static struct sysfs_ops device_ctl_info_ops = {
28997+static const struct sysfs_ops device_ctl_info_ops = {
28998 .show = edac_dev_ctl_info_show,
28999 .store = edac_dev_ctl_info_store
29000 };
29001@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(s
29002 }
29003
29004 /* edac_dev file operations for an 'instance' */
29005-static struct sysfs_ops device_instance_ops = {
29006+static const struct sysfs_ops device_instance_ops = {
29007 .show = edac_dev_instance_show,
29008 .store = edac_dev_instance_store
29009 };
29010@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(stru
29011 }
29012
29013 /* edac_dev file operations for a 'block' */
29014-static struct sysfs_ops device_block_ops = {
29015+static const struct sysfs_ops device_block_ops = {
29016 .show = edac_dev_block_show,
29017 .store = edac_dev_block_store
29018 };
29019diff -urNp linux-2.6.32.44/drivers/edac/edac_mc_sysfs.c linux-2.6.32.44/drivers/edac/edac_mc_sysfs.c
29020--- linux-2.6.32.44/drivers/edac/edac_mc_sysfs.c 2011-03-27 14:31:47.000000000 -0400
29021+++ linux-2.6.32.44/drivers/edac/edac_mc_sysfs.c 2011-04-17 15:56:46.000000000 -0400
29022@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kob
29023 return -EIO;
29024 }
29025
29026-static struct sysfs_ops csrowfs_ops = {
29027+static const struct sysfs_ops csrowfs_ops = {
29028 .show = csrowdev_show,
29029 .store = csrowdev_store
29030 };
29031@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobje
29032 }
29033
29034 /* Intermediate show/store table */
29035-static struct sysfs_ops mci_ops = {
29036+static const struct sysfs_ops mci_ops = {
29037 .show = mcidev_show,
29038 .store = mcidev_store
29039 };
29040diff -urNp linux-2.6.32.44/drivers/edac/edac_pci_sysfs.c linux-2.6.32.44/drivers/edac/edac_pci_sysfs.c
29041--- linux-2.6.32.44/drivers/edac/edac_pci_sysfs.c 2011-03-27 14:31:47.000000000 -0400
29042+++ linux-2.6.32.44/drivers/edac/edac_pci_sysfs.c 2011-05-04 17:56:20.000000000 -0400
29043@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log
29044 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29045 static int edac_pci_poll_msec = 1000; /* one second workq period */
29046
29047-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29048-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29049+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29050+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29051
29052 static struct kobject *edac_pci_top_main_kobj;
29053 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29054@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(s
29055 }
29056
29057 /* fs_ops table */
29058-static struct sysfs_ops pci_instance_ops = {
29059+static const struct sysfs_ops pci_instance_ops = {
29060 .show = edac_pci_instance_show,
29061 .store = edac_pci_instance_store
29062 };
29063@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct
29064 return -EIO;
29065 }
29066
29067-static struct sysfs_ops edac_pci_sysfs_ops = {
29068+static const struct sysfs_ops edac_pci_sysfs_ops = {
29069 .show = edac_pci_dev_show,
29070 .store = edac_pci_dev_store
29071 };
29072@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(str
29073 edac_printk(KERN_CRIT, EDAC_PCI,
29074 "Signaled System Error on %s\n",
29075 pci_name(dev));
29076- atomic_inc(&pci_nonparity_count);
29077+ atomic_inc_unchecked(&pci_nonparity_count);
29078 }
29079
29080 if (status & (PCI_STATUS_PARITY)) {
29081@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(str
29082 "Master Data Parity Error on %s\n",
29083 pci_name(dev));
29084
29085- atomic_inc(&pci_parity_count);
29086+ atomic_inc_unchecked(&pci_parity_count);
29087 }
29088
29089 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29090@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(str
29091 "Detected Parity Error on %s\n",
29092 pci_name(dev));
29093
29094- atomic_inc(&pci_parity_count);
29095+ atomic_inc_unchecked(&pci_parity_count);
29096 }
29097 }
29098
29099@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(str
29100 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29101 "Signaled System Error on %s\n",
29102 pci_name(dev));
29103- atomic_inc(&pci_nonparity_count);
29104+ atomic_inc_unchecked(&pci_nonparity_count);
29105 }
29106
29107 if (status & (PCI_STATUS_PARITY)) {
29108@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(str
29109 "Master Data Parity Error on "
29110 "%s\n", pci_name(dev));
29111
29112- atomic_inc(&pci_parity_count);
29113+ atomic_inc_unchecked(&pci_parity_count);
29114 }
29115
29116 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29117@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(str
29118 "Detected Parity Error on %s\n",
29119 pci_name(dev));
29120
29121- atomic_inc(&pci_parity_count);
29122+ atomic_inc_unchecked(&pci_parity_count);
29123 }
29124 }
29125 }
29126@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
29127 if (!check_pci_errors)
29128 return;
29129
29130- before_count = atomic_read(&pci_parity_count);
29131+ before_count = atomic_read_unchecked(&pci_parity_count);
29132
29133 /* scan all PCI devices looking for a Parity Error on devices and
29134 * bridges.
29135@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
29136 /* Only if operator has selected panic on PCI Error */
29137 if (edac_pci_get_panic_on_pe()) {
29138 /* If the count is different 'after' from 'before' */
29139- if (before_count != atomic_read(&pci_parity_count))
29140+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29141 panic("EDAC: PCI Parity Error");
29142 }
29143 }
29144diff -urNp linux-2.6.32.44/drivers/firewire/core-card.c linux-2.6.32.44/drivers/firewire/core-card.c
29145--- linux-2.6.32.44/drivers/firewire/core-card.c 2011-03-27 14:31:47.000000000 -0400
29146+++ linux-2.6.32.44/drivers/firewire/core-card.c 2011-08-05 20:33:55.000000000 -0400
29147@@ -569,8 +569,10 @@ void fw_core_remove_card(struct fw_card
29148 mutex_unlock(&card_mutex);
29149
29150 /* Switch off most of the card driver interface. */
29151- dummy_driver.free_iso_context = card->driver->free_iso_context;
29152- dummy_driver.stop_iso = card->driver->stop_iso;
29153+ pax_open_kernel();
29154+ *(void **)&dummy_driver.free_iso_context = card->driver->free_iso_context;
29155+ *(void **)&dummy_driver.stop_iso = card->driver->stop_iso;
29156+ pax_close_kernel();
29157 card->driver = &dummy_driver;
29158
29159 fw_destroy_nodes(card);
29160diff -urNp linux-2.6.32.44/drivers/firewire/core-cdev.c linux-2.6.32.44/drivers/firewire/core-cdev.c
29161--- linux-2.6.32.44/drivers/firewire/core-cdev.c 2011-03-27 14:31:47.000000000 -0400
29162+++ linux-2.6.32.44/drivers/firewire/core-cdev.c 2011-04-17 15:56:46.000000000 -0400
29163@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct clie
29164 int ret;
29165
29166 if ((request->channels == 0 && request->bandwidth == 0) ||
29167- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29168- request->bandwidth < 0)
29169+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29170 return -EINVAL;
29171
29172 r = kmalloc(sizeof(*r), GFP_KERNEL);
29173diff -urNp linux-2.6.32.44/drivers/firewire/core-transaction.c linux-2.6.32.44/drivers/firewire/core-transaction.c
29174--- linux-2.6.32.44/drivers/firewire/core-transaction.c 2011-03-27 14:31:47.000000000 -0400
29175+++ linux-2.6.32.44/drivers/firewire/core-transaction.c 2011-05-16 21:46:57.000000000 -0400
29176@@ -36,6 +36,7 @@
29177 #include <linux/string.h>
29178 #include <linux/timer.h>
29179 #include <linux/types.h>
29180+#include <linux/sched.h>
29181
29182 #include <asm/byteorder.h>
29183
29184@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *c
29185 struct transaction_callback_data d;
29186 struct fw_transaction t;
29187
29188+ pax_track_stack();
29189+
29190 init_completion(&d.done);
29191 d.payload = payload;
29192 fw_send_request(card, &t, tcode, destination_id, generation, speed,
29193diff -urNp linux-2.6.32.44/drivers/firmware/dmi_scan.c linux-2.6.32.44/drivers/firmware/dmi_scan.c
29194--- linux-2.6.32.44/drivers/firmware/dmi_scan.c 2011-03-27 14:31:47.000000000 -0400
29195+++ linux-2.6.32.44/drivers/firmware/dmi_scan.c 2011-04-17 15:56:46.000000000 -0400
29196@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
29197 }
29198 }
29199 else {
29200- /*
29201- * no iounmap() for that ioremap(); it would be a no-op, but
29202- * it's so early in setup that sucker gets confused into doing
29203- * what it shouldn't if we actually call it.
29204- */
29205 p = dmi_ioremap(0xF0000, 0x10000);
29206 if (p == NULL)
29207 goto error;
29208diff -urNp linux-2.6.32.44/drivers/firmware/edd.c linux-2.6.32.44/drivers/firmware/edd.c
29209--- linux-2.6.32.44/drivers/firmware/edd.c 2011-03-27 14:31:47.000000000 -0400
29210+++ linux-2.6.32.44/drivers/firmware/edd.c 2011-04-17 15:56:46.000000000 -0400
29211@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, str
29212 return ret;
29213 }
29214
29215-static struct sysfs_ops edd_attr_ops = {
29216+static const struct sysfs_ops edd_attr_ops = {
29217 .show = edd_attr_show,
29218 };
29219
29220diff -urNp linux-2.6.32.44/drivers/firmware/efivars.c linux-2.6.32.44/drivers/firmware/efivars.c
29221--- linux-2.6.32.44/drivers/firmware/efivars.c 2011-03-27 14:31:47.000000000 -0400
29222+++ linux-2.6.32.44/drivers/firmware/efivars.c 2011-04-17 15:56:46.000000000 -0400
29223@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct
29224 return ret;
29225 }
29226
29227-static struct sysfs_ops efivar_attr_ops = {
29228+static const struct sysfs_ops efivar_attr_ops = {
29229 .show = efivar_attr_show,
29230 .store = efivar_attr_store,
29231 };
29232diff -urNp linux-2.6.32.44/drivers/firmware/iscsi_ibft.c linux-2.6.32.44/drivers/firmware/iscsi_ibft.c
29233--- linux-2.6.32.44/drivers/firmware/iscsi_ibft.c 2011-03-27 14:31:47.000000000 -0400
29234+++ linux-2.6.32.44/drivers/firmware/iscsi_ibft.c 2011-04-17 15:56:46.000000000 -0400
29235@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struc
29236 return ret;
29237 }
29238
29239-static struct sysfs_ops ibft_attr_ops = {
29240+static const struct sysfs_ops ibft_attr_ops = {
29241 .show = ibft_show_attribute,
29242 };
29243
29244diff -urNp linux-2.6.32.44/drivers/firmware/memmap.c linux-2.6.32.44/drivers/firmware/memmap.c
29245--- linux-2.6.32.44/drivers/firmware/memmap.c 2011-03-27 14:31:47.000000000 -0400
29246+++ linux-2.6.32.44/drivers/firmware/memmap.c 2011-04-17 15:56:46.000000000 -0400
29247@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
29248 NULL
29249 };
29250
29251-static struct sysfs_ops memmap_attr_ops = {
29252+static const struct sysfs_ops memmap_attr_ops = {
29253 .show = memmap_attr_show,
29254 };
29255
29256diff -urNp linux-2.6.32.44/drivers/gpio/vr41xx_giu.c linux-2.6.32.44/drivers/gpio/vr41xx_giu.c
29257--- linux-2.6.32.44/drivers/gpio/vr41xx_giu.c 2011-03-27 14:31:47.000000000 -0400
29258+++ linux-2.6.32.44/drivers/gpio/vr41xx_giu.c 2011-05-04 17:56:28.000000000 -0400
29259@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29260 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29261 maskl, pendl, maskh, pendh);
29262
29263- atomic_inc(&irq_err_count);
29264+ atomic_inc_unchecked(&irq_err_count);
29265
29266 return -EINVAL;
29267 }
29268diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.32.44/drivers/gpu/drm/drm_crtc_helper.c
29269--- linux-2.6.32.44/drivers/gpu/drm/drm_crtc_helper.c 2011-03-27 14:31:47.000000000 -0400
29270+++ linux-2.6.32.44/drivers/gpu/drm/drm_crtc_helper.c 2011-05-16 21:46:57.000000000 -0400
29271@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct d
29272 struct drm_crtc *tmp;
29273 int crtc_mask = 1;
29274
29275- WARN(!crtc, "checking null crtc?");
29276+ BUG_ON(!crtc);
29277
29278 dev = crtc->dev;
29279
29280@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm
29281
29282 adjusted_mode = drm_mode_duplicate(dev, mode);
29283
29284+ pax_track_stack();
29285+
29286 crtc->enabled = drm_helper_crtc_in_use(crtc);
29287
29288 if (!crtc->enabled)
29289diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_drv.c linux-2.6.32.44/drivers/gpu/drm/drm_drv.c
29290--- linux-2.6.32.44/drivers/gpu/drm/drm_drv.c 2011-03-27 14:31:47.000000000 -0400
29291+++ linux-2.6.32.44/drivers/gpu/drm/drm_drv.c 2011-04-17 15:56:46.000000000 -0400
29292@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struc
29293 char *kdata = NULL;
29294
29295 atomic_inc(&dev->ioctl_count);
29296- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29297+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29298 ++file_priv->ioctl_count;
29299
29300 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29301diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_fops.c linux-2.6.32.44/drivers/gpu/drm/drm_fops.c
29302--- linux-2.6.32.44/drivers/gpu/drm/drm_fops.c 2011-03-27 14:31:47.000000000 -0400
29303+++ linux-2.6.32.44/drivers/gpu/drm/drm_fops.c 2011-04-17 15:56:46.000000000 -0400
29304@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device *
29305 }
29306
29307 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29308- atomic_set(&dev->counts[i], 0);
29309+ atomic_set_unchecked(&dev->counts[i], 0);
29310
29311 dev->sigdata.lock = NULL;
29312
29313@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct
29314
29315 retcode = drm_open_helper(inode, filp, dev);
29316 if (!retcode) {
29317- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29318+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29319 spin_lock(&dev->count_lock);
29320- if (!dev->open_count++) {
29321+ if (local_inc_return(&dev->open_count) == 1) {
29322 spin_unlock(&dev->count_lock);
29323 retcode = drm_setup(dev);
29324 goto out;
29325@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, str
29326
29327 lock_kernel();
29328
29329- DRM_DEBUG("open_count = %d\n", dev->open_count);
29330+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
29331
29332 if (dev->driver->preclose)
29333 dev->driver->preclose(dev, file_priv);
29334@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, str
29335 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29336 task_pid_nr(current),
29337 (long)old_encode_dev(file_priv->minor->device),
29338- dev->open_count);
29339+ local_read(&dev->open_count));
29340
29341 /* if the master has gone away we can't do anything with the lock */
29342 if (file_priv->minor->master)
29343@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, str
29344 * End inline drm_release
29345 */
29346
29347- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29348+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29349 spin_lock(&dev->count_lock);
29350- if (!--dev->open_count) {
29351+ if (local_dec_and_test(&dev->open_count)) {
29352 if (atomic_read(&dev->ioctl_count)) {
29353 DRM_ERROR("Device busy: %d\n",
29354 atomic_read(&dev->ioctl_count));
29355diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_gem.c linux-2.6.32.44/drivers/gpu/drm/drm_gem.c
29356--- linux-2.6.32.44/drivers/gpu/drm/drm_gem.c 2011-03-27 14:31:47.000000000 -0400
29357+++ linux-2.6.32.44/drivers/gpu/drm/drm_gem.c 2011-04-17 15:56:46.000000000 -0400
29358@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
29359 spin_lock_init(&dev->object_name_lock);
29360 idr_init(&dev->object_name_idr);
29361 atomic_set(&dev->object_count, 0);
29362- atomic_set(&dev->object_memory, 0);
29363+ atomic_set_unchecked(&dev->object_memory, 0);
29364 atomic_set(&dev->pin_count, 0);
29365- atomic_set(&dev->pin_memory, 0);
29366+ atomic_set_unchecked(&dev->pin_memory, 0);
29367 atomic_set(&dev->gtt_count, 0);
29368- atomic_set(&dev->gtt_memory, 0);
29369+ atomic_set_unchecked(&dev->gtt_memory, 0);
29370
29371 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
29372 if (!mm) {
29373@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *
29374 goto fput;
29375 }
29376 atomic_inc(&dev->object_count);
29377- atomic_add(obj->size, &dev->object_memory);
29378+ atomic_add_unchecked(obj->size, &dev->object_memory);
29379 return obj;
29380 fput:
29381 fput(obj->filp);
29382@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
29383
29384 fput(obj->filp);
29385 atomic_dec(&dev->object_count);
29386- atomic_sub(obj->size, &dev->object_memory);
29387+ atomic_sub_unchecked(obj->size, &dev->object_memory);
29388 kfree(obj);
29389 }
29390 EXPORT_SYMBOL(drm_gem_object_free);
29391diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_info.c linux-2.6.32.44/drivers/gpu/drm/drm_info.c
29392--- linux-2.6.32.44/drivers/gpu/drm/drm_info.c 2011-03-27 14:31:47.000000000 -0400
29393+++ linux-2.6.32.44/drivers/gpu/drm/drm_info.c 2011-04-17 15:56:46.000000000 -0400
29394@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
29395 struct drm_local_map *map;
29396 struct drm_map_list *r_list;
29397
29398- /* Hardcoded from _DRM_FRAME_BUFFER,
29399- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29400- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29401- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29402+ static const char * const types[] = {
29403+ [_DRM_FRAME_BUFFER] = "FB",
29404+ [_DRM_REGISTERS] = "REG",
29405+ [_DRM_SHM] = "SHM",
29406+ [_DRM_AGP] = "AGP",
29407+ [_DRM_SCATTER_GATHER] = "SG",
29408+ [_DRM_CONSISTENT] = "PCI",
29409+ [_DRM_GEM] = "GEM" };
29410 const char *type;
29411 int i;
29412
29413@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
29414 map = r_list->map;
29415 if (!map)
29416 continue;
29417- if (map->type < 0 || map->type > 5)
29418+ if (map->type >= ARRAY_SIZE(types))
29419 type = "??";
29420 else
29421 type = types[map->type];
29422@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file
29423 struct drm_device *dev = node->minor->dev;
29424
29425 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
29426- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
29427+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
29428 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
29429- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
29430- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
29431+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
29432+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
29433 seq_printf(m, "%d gtt total\n", dev->gtt_total);
29434 return 0;
29435 }
29436@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, voi
29437 mutex_lock(&dev->struct_mutex);
29438 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
29439 atomic_read(&dev->vma_count),
29440+#ifdef CONFIG_GRKERNSEC_HIDESYM
29441+ NULL, 0);
29442+#else
29443 high_memory, (u64)virt_to_phys(high_memory));
29444+#endif
29445
29446 list_for_each_entry(pt, &dev->vmalist, head) {
29447 vma = pt->vma;
29448@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, voi
29449 continue;
29450 seq_printf(m,
29451 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
29452- pt->pid, vma->vm_start, vma->vm_end,
29453+ pt->pid,
29454+#ifdef CONFIG_GRKERNSEC_HIDESYM
29455+ 0, 0,
29456+#else
29457+ vma->vm_start, vma->vm_end,
29458+#endif
29459 vma->vm_flags & VM_READ ? 'r' : '-',
29460 vma->vm_flags & VM_WRITE ? 'w' : '-',
29461 vma->vm_flags & VM_EXEC ? 'x' : '-',
29462 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29463 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29464 vma->vm_flags & VM_IO ? 'i' : '-',
29465+#ifdef CONFIG_GRKERNSEC_HIDESYM
29466+ 0);
29467+#else
29468 vma->vm_pgoff);
29469+#endif
29470
29471 #if defined(__i386__)
29472 pgprot = pgprot_val(vma->vm_page_prot);
29473diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_ioctl.c linux-2.6.32.44/drivers/gpu/drm/drm_ioctl.c
29474--- linux-2.6.32.44/drivers/gpu/drm/drm_ioctl.c 2011-03-27 14:31:47.000000000 -0400
29475+++ linux-2.6.32.44/drivers/gpu/drm/drm_ioctl.c 2011-04-17 15:56:46.000000000 -0400
29476@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev,
29477 stats->data[i].value =
29478 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29479 else
29480- stats->data[i].value = atomic_read(&dev->counts[i]);
29481+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29482 stats->data[i].type = dev->types[i];
29483 }
29484
29485diff -urNp linux-2.6.32.44/drivers/gpu/drm/drm_lock.c linux-2.6.32.44/drivers/gpu/drm/drm_lock.c
29486--- linux-2.6.32.44/drivers/gpu/drm/drm_lock.c 2011-03-27 14:31:47.000000000 -0400
29487+++ linux-2.6.32.44/drivers/gpu/drm/drm_lock.c 2011-04-17 15:56:46.000000000 -0400
29488@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, voi
29489 if (drm_lock_take(&master->lock, lock->context)) {
29490 master->lock.file_priv = file_priv;
29491 master->lock.lock_time = jiffies;
29492- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29493+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29494 break; /* Got lock */
29495 }
29496
29497@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, v
29498 return -EINVAL;
29499 }
29500
29501- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29502+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29503
29504 /* kernel_context_switch isn't used by any of the x86 drm
29505 * modules but is required by the Sparc driver.
29506diff -urNp linux-2.6.32.44/drivers/gpu/drm/i810/i810_dma.c linux-2.6.32.44/drivers/gpu/drm/i810/i810_dma.c
29507--- linux-2.6.32.44/drivers/gpu/drm/i810/i810_dma.c 2011-03-27 14:31:47.000000000 -0400
29508+++ linux-2.6.32.44/drivers/gpu/drm/i810/i810_dma.c 2011-04-17 15:56:46.000000000 -0400
29509@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_de
29510 dma->buflist[vertex->idx],
29511 vertex->discard, vertex->used);
29512
29513- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29514- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29515+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29516+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29517 sarea_priv->last_enqueue = dev_priv->counter - 1;
29518 sarea_priv->last_dispatch = (int)hw_status[5];
29519
29520@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device
29521 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29522 mc->last_render);
29523
29524- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29525- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29526+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29527+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29528 sarea_priv->last_enqueue = dev_priv->counter - 1;
29529 sarea_priv->last_dispatch = (int)hw_status[5];
29530
29531diff -urNp linux-2.6.32.44/drivers/gpu/drm/i810/i810_drv.h linux-2.6.32.44/drivers/gpu/drm/i810/i810_drv.h
29532--- linux-2.6.32.44/drivers/gpu/drm/i810/i810_drv.h 2011-03-27 14:31:47.000000000 -0400
29533+++ linux-2.6.32.44/drivers/gpu/drm/i810/i810_drv.h 2011-05-04 17:56:28.000000000 -0400
29534@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29535 int page_flipping;
29536
29537 wait_queue_head_t irq_queue;
29538- atomic_t irq_received;
29539- atomic_t irq_emitted;
29540+ atomic_unchecked_t irq_received;
29541+ atomic_unchecked_t irq_emitted;
29542
29543 int front_offset;
29544 } drm_i810_private_t;
29545diff -urNp linux-2.6.32.44/drivers/gpu/drm/i830/i830_drv.h linux-2.6.32.44/drivers/gpu/drm/i830/i830_drv.h
29546--- linux-2.6.32.44/drivers/gpu/drm/i830/i830_drv.h 2011-03-27 14:31:47.000000000 -0400
29547+++ linux-2.6.32.44/drivers/gpu/drm/i830/i830_drv.h 2011-05-04 17:56:28.000000000 -0400
29548@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
29549 int page_flipping;
29550
29551 wait_queue_head_t irq_queue;
29552- atomic_t irq_received;
29553- atomic_t irq_emitted;
29554+ atomic_unchecked_t irq_received;
29555+ atomic_unchecked_t irq_emitted;
29556
29557 int use_mi_batchbuffer_start;
29558
29559diff -urNp linux-2.6.32.44/drivers/gpu/drm/i830/i830_irq.c linux-2.6.32.44/drivers/gpu/drm/i830/i830_irq.c
29560--- linux-2.6.32.44/drivers/gpu/drm/i830/i830_irq.c 2011-03-27 14:31:47.000000000 -0400
29561+++ linux-2.6.32.44/drivers/gpu/drm/i830/i830_irq.c 2011-05-04 17:56:28.000000000 -0400
29562@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_
29563
29564 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
29565
29566- atomic_inc(&dev_priv->irq_received);
29567+ atomic_inc_unchecked(&dev_priv->irq_received);
29568 wake_up_interruptible(&dev_priv->irq_queue);
29569
29570 return IRQ_HANDLED;
29571@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_devi
29572
29573 DRM_DEBUG("%s\n", __func__);
29574
29575- atomic_inc(&dev_priv->irq_emitted);
29576+ atomic_inc_unchecked(&dev_priv->irq_emitted);
29577
29578 BEGIN_LP_RING(2);
29579 OUT_RING(0);
29580 OUT_RING(GFX_OP_USER_INTERRUPT);
29581 ADVANCE_LP_RING();
29582
29583- return atomic_read(&dev_priv->irq_emitted);
29584+ return atomic_read_unchecked(&dev_priv->irq_emitted);
29585 }
29586
29587 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
29588@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_devi
29589
29590 DRM_DEBUG("%s\n", __func__);
29591
29592- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
29593+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
29594 return 0;
29595
29596 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
29597@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_devi
29598
29599 for (;;) {
29600 __set_current_state(TASK_INTERRUPTIBLE);
29601- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
29602+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
29603 break;
29604 if ((signed)(end - jiffies) <= 0) {
29605 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
29606@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct d
29607 I830_WRITE16(I830REG_HWSTAM, 0xffff);
29608 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
29609 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
29610- atomic_set(&dev_priv->irq_received, 0);
29611- atomic_set(&dev_priv->irq_emitted, 0);
29612+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29613+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
29614 init_waitqueue_head(&dev_priv->irq_queue);
29615 }
29616
29617diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7017.c
29618--- linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7017.c 2011-03-27 14:31:47.000000000 -0400
29619+++ linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7017.c 2011-04-17 15:56:46.000000000 -0400
29620@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_
29621 }
29622 }
29623
29624-struct intel_dvo_dev_ops ch7017_ops = {
29625+const struct intel_dvo_dev_ops ch7017_ops = {
29626 .init = ch7017_init,
29627 .detect = ch7017_detect,
29628 .mode_valid = ch7017_mode_valid,
29629diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7xxx.c
29630--- linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-03-27 14:31:47.000000000 -0400
29631+++ linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-04-17 15:56:46.000000000 -0400
29632@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_
29633 }
29634 }
29635
29636-struct intel_dvo_dev_ops ch7xxx_ops = {
29637+const struct intel_dvo_dev_ops ch7xxx_ops = {
29638 .init = ch7xxx_init,
29639 .detect = ch7xxx_detect,
29640 .mode_valid = ch7xxx_mode_valid,
29641diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/dvo.h linux-2.6.32.44/drivers/gpu/drm/i915/dvo.h
29642--- linux-2.6.32.44/drivers/gpu/drm/i915/dvo.h 2011-03-27 14:31:47.000000000 -0400
29643+++ linux-2.6.32.44/drivers/gpu/drm/i915/dvo.h 2011-04-17 15:56:46.000000000 -0400
29644@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
29645 *
29646 * \return singly-linked list of modes or NULL if no modes found.
29647 */
29648- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
29649+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
29650
29651 /**
29652 * Clean up driver-specific bits of the output
29653 */
29654- void (*destroy) (struct intel_dvo_device *dvo);
29655+ void (* const destroy) (struct intel_dvo_device *dvo);
29656
29657 /**
29658 * Debugging hook to dump device registers to log file
29659 */
29660- void (*dump_regs)(struct intel_dvo_device *dvo);
29661+ void (* const dump_regs)(struct intel_dvo_device *dvo);
29662 };
29663
29664-extern struct intel_dvo_dev_ops sil164_ops;
29665-extern struct intel_dvo_dev_ops ch7xxx_ops;
29666-extern struct intel_dvo_dev_ops ivch_ops;
29667-extern struct intel_dvo_dev_ops tfp410_ops;
29668-extern struct intel_dvo_dev_ops ch7017_ops;
29669+extern const struct intel_dvo_dev_ops sil164_ops;
29670+extern const struct intel_dvo_dev_ops ch7xxx_ops;
29671+extern const struct intel_dvo_dev_ops ivch_ops;
29672+extern const struct intel_dvo_dev_ops tfp410_ops;
29673+extern const struct intel_dvo_dev_ops ch7017_ops;
29674
29675 #endif /* _INTEL_DVO_H */
29676diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ivch.c
29677--- linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ivch.c 2011-03-27 14:31:47.000000000 -0400
29678+++ linux-2.6.32.44/drivers/gpu/drm/i915/dvo_ivch.c 2011-04-17 15:56:46.000000000 -0400
29679@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dv
29680 }
29681 }
29682
29683-struct intel_dvo_dev_ops ivch_ops= {
29684+const struct intel_dvo_dev_ops ivch_ops= {
29685 .init = ivch_init,
29686 .dpms = ivch_dpms,
29687 .save = ivch_save,
29688diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.32.44/drivers/gpu/drm/i915/dvo_sil164.c
29689--- linux-2.6.32.44/drivers/gpu/drm/i915/dvo_sil164.c 2011-03-27 14:31:47.000000000 -0400
29690+++ linux-2.6.32.44/drivers/gpu/drm/i915/dvo_sil164.c 2011-04-17 15:56:46.000000000 -0400
29691@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_
29692 }
29693 }
29694
29695-struct intel_dvo_dev_ops sil164_ops = {
29696+const struct intel_dvo_dev_ops sil164_ops = {
29697 .init = sil164_init,
29698 .detect = sil164_detect,
29699 .mode_valid = sil164_mode_valid,
29700diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.32.44/drivers/gpu/drm/i915/dvo_tfp410.c
29701--- linux-2.6.32.44/drivers/gpu/drm/i915/dvo_tfp410.c 2011-03-27 14:31:47.000000000 -0400
29702+++ linux-2.6.32.44/drivers/gpu/drm/i915/dvo_tfp410.c 2011-04-17 15:56:46.000000000 -0400
29703@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_
29704 }
29705 }
29706
29707-struct intel_dvo_dev_ops tfp410_ops = {
29708+const struct intel_dvo_dev_ops tfp410_ops = {
29709 .init = tfp410_init,
29710 .detect = tfp410_detect,
29711 .mode_valid = tfp410_mode_valid,
29712diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.32.44/drivers/gpu/drm/i915/i915_debugfs.c
29713--- linux-2.6.32.44/drivers/gpu/drm/i915/i915_debugfs.c 2011-03-27 14:31:47.000000000 -0400
29714+++ linux-2.6.32.44/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-04 17:56:28.000000000 -0400
29715@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct se
29716 I915_READ(GTIMR));
29717 }
29718 seq_printf(m, "Interrupts received: %d\n",
29719- atomic_read(&dev_priv->irq_received));
29720+ atomic_read_unchecked(&dev_priv->irq_received));
29721 if (dev_priv->hw_status_page != NULL) {
29722 seq_printf(m, "Current sequence: %d\n",
29723 i915_get_gem_seqno(dev));
29724diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.c linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.c
29725--- linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.c 2011-03-27 14:31:47.000000000 -0400
29726+++ linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.c 2011-04-17 15:56:46.000000000 -0400
29727@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
29728 return i915_resume(dev);
29729 }
29730
29731-static struct vm_operations_struct i915_gem_vm_ops = {
29732+static const struct vm_operations_struct i915_gem_vm_ops = {
29733 .fault = i915_gem_fault,
29734 .open = drm_gem_vm_open,
29735 .close = drm_gem_vm_close,
29736diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.h linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.h
29737--- linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.h 2011-03-27 14:31:47.000000000 -0400
29738+++ linux-2.6.32.44/drivers/gpu/drm/i915/i915_drv.h 2011-08-05 20:33:55.000000000 -0400
29739@@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
29740 /* display clock increase/decrease */
29741 /* pll clock increase/decrease */
29742 /* clock gating init */
29743-};
29744+} __no_const;
29745
29746 typedef struct drm_i915_private {
29747 struct drm_device *dev;
29748@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
29749 int page_flipping;
29750
29751 wait_queue_head_t irq_queue;
29752- atomic_t irq_received;
29753+ atomic_unchecked_t irq_received;
29754 /** Protects user_irq_refcount and irq_mask_reg */
29755 spinlock_t user_irq_lock;
29756 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
29757diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/i915_gem.c linux-2.6.32.44/drivers/gpu/drm/i915/i915_gem.c
29758--- linux-2.6.32.44/drivers/gpu/drm/i915/i915_gem.c 2011-03-27 14:31:47.000000000 -0400
29759+++ linux-2.6.32.44/drivers/gpu/drm/i915/i915_gem.c 2011-04-17 15:56:46.000000000 -0400
29760@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_d
29761
29762 args->aper_size = dev->gtt_total;
29763 args->aper_available_size = (args->aper_size -
29764- atomic_read(&dev->pin_memory));
29765+ atomic_read_unchecked(&dev->pin_memory));
29766
29767 return 0;
29768 }
29769@@ -492,6 +492,11 @@ i915_gem_pread_ioctl(struct drm_device *
29770 return -EINVAL;
29771 }
29772
29773+ if (!access_ok(VERIFY_WRITE, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
29774+ drm_gem_object_unreference(obj);
29775+ return -EFAULT;
29776+ }
29777+
29778 if (i915_gem_object_needs_bit17_swizzle(obj)) {
29779 ret = i915_gem_shmem_pread_slow(dev, obj, args, file_priv);
29780 } else {
29781@@ -965,6 +970,11 @@ i915_gem_pwrite_ioctl(struct drm_device
29782 return -EINVAL;
29783 }
29784
29785+ if (!access_ok(VERIFY_READ, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
29786+ drm_gem_object_unreference(obj);
29787+ return -EFAULT;
29788+ }
29789+
29790 /* We can only do the GTT pwrite on untiled buffers, as otherwise
29791 * it would end up going through the fenced access, and we'll get
29792 * different detiling behavior between reading and writing.
29793@@ -2054,7 +2064,7 @@ i915_gem_object_unbind(struct drm_gem_ob
29794
29795 if (obj_priv->gtt_space) {
29796 atomic_dec(&dev->gtt_count);
29797- atomic_sub(obj->size, &dev->gtt_memory);
29798+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
29799
29800 drm_mm_put_block(obj_priv->gtt_space);
29801 obj_priv->gtt_space = NULL;
29802@@ -2697,7 +2707,7 @@ i915_gem_object_bind_to_gtt(struct drm_g
29803 goto search_free;
29804 }
29805 atomic_inc(&dev->gtt_count);
29806- atomic_add(obj->size, &dev->gtt_memory);
29807+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
29808
29809 /* Assert that the object is not currently in any GPU domain. As it
29810 * wasn't in the GTT, there shouldn't be any way it could have been in
29811@@ -3751,9 +3761,9 @@ i915_gem_execbuffer(struct drm_device *d
29812 "%d/%d gtt bytes\n",
29813 atomic_read(&dev->object_count),
29814 atomic_read(&dev->pin_count),
29815- atomic_read(&dev->object_memory),
29816- atomic_read(&dev->pin_memory),
29817- atomic_read(&dev->gtt_memory),
29818+ atomic_read_unchecked(&dev->object_memory),
29819+ atomic_read_unchecked(&dev->pin_memory),
29820+ atomic_read_unchecked(&dev->gtt_memory),
29821 dev->gtt_total);
29822 }
29823 goto err;
29824@@ -3985,7 +3995,7 @@ i915_gem_object_pin(struct drm_gem_objec
29825 */
29826 if (obj_priv->pin_count == 1) {
29827 atomic_inc(&dev->pin_count);
29828- atomic_add(obj->size, &dev->pin_memory);
29829+ atomic_add_unchecked(obj->size, &dev->pin_memory);
29830 if (!obj_priv->active &&
29831 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
29832 !list_empty(&obj_priv->list))
29833@@ -4018,7 +4028,7 @@ i915_gem_object_unpin(struct drm_gem_obj
29834 list_move_tail(&obj_priv->list,
29835 &dev_priv->mm.inactive_list);
29836 atomic_dec(&dev->pin_count);
29837- atomic_sub(obj->size, &dev->pin_memory);
29838+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
29839 }
29840 i915_verify_inactive(dev, __FILE__, __LINE__);
29841 }
29842diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/i915_irq.c linux-2.6.32.44/drivers/gpu/drm/i915/i915_irq.c
29843--- linux-2.6.32.44/drivers/gpu/drm/i915/i915_irq.c 2011-03-27 14:31:47.000000000 -0400
29844+++ linux-2.6.32.44/drivers/gpu/drm/i915/i915_irq.c 2011-05-04 17:56:28.000000000 -0400
29845@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29846 int irq_received;
29847 int ret = IRQ_NONE;
29848
29849- atomic_inc(&dev_priv->irq_received);
29850+ atomic_inc_unchecked(&dev_priv->irq_received);
29851
29852 if (IS_IGDNG(dev))
29853 return igdng_irq_handler(dev);
29854@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct d
29855 {
29856 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29857
29858- atomic_set(&dev_priv->irq_received, 0);
29859+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29860
29861 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29862 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29863diff -urNp linux-2.6.32.44/drivers/gpu/drm/i915/intel_sdvo.c linux-2.6.32.44/drivers/gpu/drm/i915/intel_sdvo.c
29864--- linux-2.6.32.44/drivers/gpu/drm/i915/intel_sdvo.c 2011-03-27 14:31:47.000000000 -0400
29865+++ linux-2.6.32.44/drivers/gpu/drm/i915/intel_sdvo.c 2011-08-05 20:33:55.000000000 -0400
29866@@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *
29867 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
29868
29869 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
29870- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
29871+ pax_open_kernel();
29872+ *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
29873+ pax_close_kernel();
29874
29875 /* Read the regs to test if we can talk to the device */
29876 for (i = 0; i < 0x40; i++) {
29877diff -urNp linux-2.6.32.44/drivers/gpu/drm/mga/mga_drv.h linux-2.6.32.44/drivers/gpu/drm/mga/mga_drv.h
29878--- linux-2.6.32.44/drivers/gpu/drm/mga/mga_drv.h 2011-03-27 14:31:47.000000000 -0400
29879+++ linux-2.6.32.44/drivers/gpu/drm/mga/mga_drv.h 2011-05-04 17:56:28.000000000 -0400
29880@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29881 u32 clear_cmd;
29882 u32 maccess;
29883
29884- atomic_t vbl_received; /**< Number of vblanks received. */
29885+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29886 wait_queue_head_t fence_queue;
29887- atomic_t last_fence_retired;
29888+ atomic_unchecked_t last_fence_retired;
29889 u32 next_fence_to_post;
29890
29891 unsigned int fb_cpp;
29892diff -urNp linux-2.6.32.44/drivers/gpu/drm/mga/mga_irq.c linux-2.6.32.44/drivers/gpu/drm/mga/mga_irq.c
29893--- linux-2.6.32.44/drivers/gpu/drm/mga/mga_irq.c 2011-03-27 14:31:47.000000000 -0400
29894+++ linux-2.6.32.44/drivers/gpu/drm/mga/mga_irq.c 2011-05-04 17:56:28.000000000 -0400
29895@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29896 if (crtc != 0)
29897 return 0;
29898
29899- return atomic_read(&dev_priv->vbl_received);
29900+ return atomic_read_unchecked(&dev_priv->vbl_received);
29901 }
29902
29903
29904@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29905 /* VBLANK interrupt */
29906 if (status & MGA_VLINEPEN) {
29907 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29908- atomic_inc(&dev_priv->vbl_received);
29909+ atomic_inc_unchecked(&dev_priv->vbl_received);
29910 drm_handle_vblank(dev, 0);
29911 handled = 1;
29912 }
29913@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29914 MGA_WRITE(MGA_PRIMEND, prim_end);
29915 }
29916
29917- atomic_inc(&dev_priv->last_fence_retired);
29918+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
29919 DRM_WAKEUP(&dev_priv->fence_queue);
29920 handled = 1;
29921 }
29922@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_dev
29923 * using fences.
29924 */
29925 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29926- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29927+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29928 - *sequence) <= (1 << 23)));
29929
29930 *sequence = cur_fence;
29931diff -urNp linux-2.6.32.44/drivers/gpu/drm/r128/r128_cce.c linux-2.6.32.44/drivers/gpu/drm/r128/r128_cce.c
29932--- linux-2.6.32.44/drivers/gpu/drm/r128/r128_cce.c 2011-03-27 14:31:47.000000000 -0400
29933+++ linux-2.6.32.44/drivers/gpu/drm/r128/r128_cce.c 2011-05-04 17:56:28.000000000 -0400
29934@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29935
29936 /* GH: Simple idle check.
29937 */
29938- atomic_set(&dev_priv->idle_count, 0);
29939+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29940
29941 /* We don't support anything other than bus-mastering ring mode,
29942 * but the ring can be in either AGP or PCI space for the ring
29943diff -urNp linux-2.6.32.44/drivers/gpu/drm/r128/r128_drv.h linux-2.6.32.44/drivers/gpu/drm/r128/r128_drv.h
29944--- linux-2.6.32.44/drivers/gpu/drm/r128/r128_drv.h 2011-03-27 14:31:47.000000000 -0400
29945+++ linux-2.6.32.44/drivers/gpu/drm/r128/r128_drv.h 2011-05-04 17:56:28.000000000 -0400
29946@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29947 int is_pci;
29948 unsigned long cce_buffers_offset;
29949
29950- atomic_t idle_count;
29951+ atomic_unchecked_t idle_count;
29952
29953 int page_flipping;
29954 int current_page;
29955 u32 crtc_offset;
29956 u32 crtc_offset_cntl;
29957
29958- atomic_t vbl_received;
29959+ atomic_unchecked_t vbl_received;
29960
29961 u32 color_fmt;
29962 unsigned int front_offset;
29963diff -urNp linux-2.6.32.44/drivers/gpu/drm/r128/r128_irq.c linux-2.6.32.44/drivers/gpu/drm/r128/r128_irq.c
29964--- linux-2.6.32.44/drivers/gpu/drm/r128/r128_irq.c 2011-03-27 14:31:47.000000000 -0400
29965+++ linux-2.6.32.44/drivers/gpu/drm/r128/r128_irq.c 2011-05-04 17:56:28.000000000 -0400
29966@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29967 if (crtc != 0)
29968 return 0;
29969
29970- return atomic_read(&dev_priv->vbl_received);
29971+ return atomic_read_unchecked(&dev_priv->vbl_received);
29972 }
29973
29974 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29975@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29976 /* VBLANK interrupt */
29977 if (status & R128_CRTC_VBLANK_INT) {
29978 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29979- atomic_inc(&dev_priv->vbl_received);
29980+ atomic_inc_unchecked(&dev_priv->vbl_received);
29981 drm_handle_vblank(dev, 0);
29982 return IRQ_HANDLED;
29983 }
29984diff -urNp linux-2.6.32.44/drivers/gpu/drm/r128/r128_state.c linux-2.6.32.44/drivers/gpu/drm/r128/r128_state.c
29985--- linux-2.6.32.44/drivers/gpu/drm/r128/r128_state.c 2011-03-27 14:31:47.000000000 -0400
29986+++ linux-2.6.32.44/drivers/gpu/drm/r128/r128_state.c 2011-05-04 17:56:28.000000000 -0400
29987@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_priv
29988
29989 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
29990 {
29991- if (atomic_read(&dev_priv->idle_count) == 0) {
29992+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
29993 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29994 } else {
29995- atomic_set(&dev_priv->idle_count, 0);
29996+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29997 }
29998 }
29999
30000diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/atom.c linux-2.6.32.44/drivers/gpu/drm/radeon/atom.c
30001--- linux-2.6.32.44/drivers/gpu/drm/radeon/atom.c 2011-05-10 22:12:01.000000000 -0400
30002+++ linux-2.6.32.44/drivers/gpu/drm/radeon/atom.c 2011-05-16 21:46:57.000000000 -0400
30003@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct c
30004 char name[512];
30005 int i;
30006
30007+ pax_track_stack();
30008+
30009 ctx->card = card;
30010 ctx->bios = bios;
30011
30012diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.32.44/drivers/gpu/drm/radeon/mkregtable.c
30013--- linux-2.6.32.44/drivers/gpu/drm/radeon/mkregtable.c 2011-03-27 14:31:47.000000000 -0400
30014+++ linux-2.6.32.44/drivers/gpu/drm/radeon/mkregtable.c 2011-04-17 15:56:46.000000000 -0400
30015@@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
30016 regex_t mask_rex;
30017 regmatch_t match[4];
30018 char buf[1024];
30019- size_t end;
30020+ long end;
30021 int len;
30022 int done = 0;
30023 int r;
30024 unsigned o;
30025 struct offset *offset;
30026 char last_reg_s[10];
30027- int last_reg;
30028+ unsigned long last_reg;
30029
30030 if (regcomp
30031 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30032diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_atombios.c
30033--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_atombios.c 2011-03-27 14:31:47.000000000 -0400
30034+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-16 21:46:57.000000000 -0400
30035@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from
30036 bool linkb;
30037 struct radeon_i2c_bus_rec ddc_bus;
30038
30039+ pax_track_stack();
30040+
30041 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
30042
30043 if (data_offset == 0)
30044@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_o
30045 }
30046 }
30047
30048-struct bios_connector {
30049+static struct bios_connector {
30050 bool valid;
30051 uint16_t line_mux;
30052 uint16_t devices;
30053 int connector_type;
30054 struct radeon_i2c_bus_rec ddc_bus;
30055-};
30056+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
30057
30058 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
30059 drm_device
30060@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from
30061 uint8_t dac;
30062 union atom_supported_devices *supported_devices;
30063 int i, j;
30064- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
30065
30066 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
30067
30068diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_display.c
30069--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_display.c 2011-03-27 14:31:47.000000000 -0400
30070+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_display.c 2011-04-17 15:56:46.000000000 -0400
30071@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pl
30072
30073 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
30074 error = freq - current_freq;
30075- error = error < 0 ? 0xffffffff : error;
30076+ error = (int32_t)error < 0 ? 0xffffffff : error;
30077 } else
30078 error = abs(current_freq - freq);
30079 vco_diff = abs(vco - best_vco);
30080diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_drv.h
30081--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_drv.h 2011-03-27 14:31:47.000000000 -0400
30082+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-04 17:56:28.000000000 -0400
30083@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
30084
30085 /* SW interrupt */
30086 wait_queue_head_t swi_queue;
30087- atomic_t swi_emitted;
30088+ atomic_unchecked_t swi_emitted;
30089 int vblank_crtc;
30090 uint32_t irq_enable_reg;
30091 uint32_t r500_disp_irq_reg;
30092diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_fence.c
30093--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_fence.c 2011-03-27 14:31:47.000000000 -0400
30094+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-04 17:56:28.000000000 -0400
30095@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_devi
30096 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
30097 return 0;
30098 }
30099- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
30100+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
30101 if (!rdev->cp.ready) {
30102 /* FIXME: cp is not running assume everythings is done right
30103 * away
30104@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct rade
30105 return r;
30106 }
30107 WREG32(rdev->fence_drv.scratch_reg, 0);
30108- atomic_set(&rdev->fence_drv.seq, 0);
30109+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
30110 INIT_LIST_HEAD(&rdev->fence_drv.created);
30111 INIT_LIST_HEAD(&rdev->fence_drv.emited);
30112 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
30113diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon.h linux-2.6.32.44/drivers/gpu/drm/radeon/radeon.h
30114--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon.h 2011-03-27 14:31:47.000000000 -0400
30115+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon.h 2011-08-05 20:33:55.000000000 -0400
30116@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device
30117 */
30118 struct radeon_fence_driver {
30119 uint32_t scratch_reg;
30120- atomic_t seq;
30121+ atomic_unchecked_t seq;
30122 uint32_t last_seq;
30123 unsigned long count_timeout;
30124 wait_queue_head_t queue;
30125@@ -640,7 +640,7 @@ struct radeon_asic {
30126 uint32_t offset, uint32_t obj_size);
30127 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
30128 void (*bandwidth_update)(struct radeon_device *rdev);
30129-};
30130+} __no_const;
30131
30132 /*
30133 * Asic structures
30134diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ioc32.c
30135--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-03-27 14:31:47.000000000 -0400
30136+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-04-23 13:57:24.000000000 -0400
30137@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(str
30138 request = compat_alloc_user_space(sizeof(*request));
30139 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30140 || __put_user(req32.param, &request->param)
30141- || __put_user((void __user *)(unsigned long)req32.value,
30142+ || __put_user((unsigned long)req32.value,
30143 &request->value))
30144 return -EFAULT;
30145
30146diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_irq.c
30147--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_irq.c 2011-03-27 14:31:47.000000000 -0400
30148+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-04 17:56:28.000000000 -0400
30149@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
30150 unsigned int ret;
30151 RING_LOCALS;
30152
30153- atomic_inc(&dev_priv->swi_emitted);
30154- ret = atomic_read(&dev_priv->swi_emitted);
30155+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30156+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30157
30158 BEGIN_RING(4);
30159 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30160@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
30161 drm_radeon_private_t *dev_priv =
30162 (drm_radeon_private_t *) dev->dev_private;
30163
30164- atomic_set(&dev_priv->swi_emitted, 0);
30165+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30166 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30167
30168 dev->max_vblank_count = 0x001fffff;
30169diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_state.c
30170--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_state.c 2011-03-27 14:31:47.000000000 -0400
30171+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_state.c 2011-04-17 15:56:46.000000000 -0400
30172@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm
30173 {
30174 drm_radeon_private_t *dev_priv = dev->dev_private;
30175 drm_radeon_getparam_t *param = data;
30176- int value;
30177+ int value = 0;
30178
30179 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30180
30181diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ttm.c
30182--- linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ttm.c 2011-03-27 14:31:47.000000000 -0400
30183+++ linux-2.6.32.44/drivers/gpu/drm/radeon/radeon_ttm.c 2011-04-17 15:56:46.000000000 -0400
30184@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_devic
30185 DRM_INFO("radeon: ttm finalized\n");
30186 }
30187
30188-static struct vm_operations_struct radeon_ttm_vm_ops;
30189-static const struct vm_operations_struct *ttm_vm_ops = NULL;
30190-
30191-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
30192-{
30193- struct ttm_buffer_object *bo;
30194- int r;
30195-
30196- bo = (struct ttm_buffer_object *)vma->vm_private_data;
30197- if (bo == NULL) {
30198- return VM_FAULT_NOPAGE;
30199- }
30200- r = ttm_vm_ops->fault(vma, vmf);
30201- return r;
30202-}
30203-
30204 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30205 {
30206 struct drm_file *file_priv;
30207 struct radeon_device *rdev;
30208- int r;
30209
30210 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
30211 return drm_mmap(filp, vma);
30212@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struc
30213
30214 file_priv = (struct drm_file *)filp->private_data;
30215 rdev = file_priv->minor->dev->dev_private;
30216- if (rdev == NULL) {
30217+ if (!rdev)
30218 return -EINVAL;
30219- }
30220- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
30221- if (unlikely(r != 0)) {
30222- return r;
30223- }
30224- if (unlikely(ttm_vm_ops == NULL)) {
30225- ttm_vm_ops = vma->vm_ops;
30226- radeon_ttm_vm_ops = *ttm_vm_ops;
30227- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30228- }
30229- vma->vm_ops = &radeon_ttm_vm_ops;
30230- return 0;
30231+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
30232 }
30233
30234
30235diff -urNp linux-2.6.32.44/drivers/gpu/drm/radeon/rs690.c linux-2.6.32.44/drivers/gpu/drm/radeon/rs690.c
30236--- linux-2.6.32.44/drivers/gpu/drm/radeon/rs690.c 2011-03-27 14:31:47.000000000 -0400
30237+++ linux-2.6.32.44/drivers/gpu/drm/radeon/rs690.c 2011-04-17 15:56:46.000000000 -0400
30238@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct
30239 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30240 rdev->pm.sideport_bandwidth.full)
30241 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30242- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
30243+ read_delay_latency.full = rfixed_const(800 * 1000);
30244 read_delay_latency.full = rfixed_div(read_delay_latency,
30245 rdev->pm.igp_sideport_mclk);
30246+ a.full = rfixed_const(370);
30247+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
30248 } else {
30249 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30250 rdev->pm.k8_bandwidth.full)
30251diff -urNp linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo.c linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo.c
30252--- linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo.c 2011-03-27 14:31:47.000000000 -0400
30253+++ linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo.c 2011-04-23 12:56:11.000000000 -0400
30254@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_a
30255 NULL
30256 };
30257
30258-static struct sysfs_ops ttm_bo_global_ops = {
30259+static const struct sysfs_ops ttm_bo_global_ops = {
30260 .show = &ttm_bo_global_show
30261 };
30262
30263diff -urNp linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo_vm.c
30264--- linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-03-27 14:31:47.000000000 -0400
30265+++ linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-04-17 15:56:46.000000000 -0400
30266@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_are
30267 {
30268 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
30269 vma->vm_private_data;
30270- struct ttm_bo_device *bdev = bo->bdev;
30271+ struct ttm_bo_device *bdev;
30272 unsigned long bus_base;
30273 unsigned long bus_offset;
30274 unsigned long bus_size;
30275@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_are
30276 unsigned long address = (unsigned long)vmf->virtual_address;
30277 int retval = VM_FAULT_NOPAGE;
30278
30279+ if (!bo)
30280+ return VM_FAULT_NOPAGE;
30281+ bdev = bo->bdev;
30282+
30283 /*
30284 * Work around locking order reversal in fault / nopfn
30285 * between mmap_sem and bo_reserve: Perform a trylock operation
30286diff -urNp linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_global.c linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_global.c
30287--- linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_global.c 2011-03-27 14:31:47.000000000 -0400
30288+++ linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_global.c 2011-04-17 15:56:46.000000000 -0400
30289@@ -36,7 +36,7 @@
30290 struct ttm_global_item {
30291 struct mutex mutex;
30292 void *object;
30293- int refcount;
30294+ atomic_t refcount;
30295 };
30296
30297 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
30298@@ -49,7 +49,7 @@ void ttm_global_init(void)
30299 struct ttm_global_item *item = &glob[i];
30300 mutex_init(&item->mutex);
30301 item->object = NULL;
30302- item->refcount = 0;
30303+ atomic_set(&item->refcount, 0);
30304 }
30305 }
30306
30307@@ -59,7 +59,7 @@ void ttm_global_release(void)
30308 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
30309 struct ttm_global_item *item = &glob[i];
30310 BUG_ON(item->object != NULL);
30311- BUG_ON(item->refcount != 0);
30312+ BUG_ON(atomic_read(&item->refcount) != 0);
30313 }
30314 }
30315
30316@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_globa
30317 void *object;
30318
30319 mutex_lock(&item->mutex);
30320- if (item->refcount == 0) {
30321+ if (atomic_read(&item->refcount) == 0) {
30322 item->object = kzalloc(ref->size, GFP_KERNEL);
30323 if (unlikely(item->object == NULL)) {
30324 ret = -ENOMEM;
30325@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_globa
30326 goto out_err;
30327
30328 }
30329- ++item->refcount;
30330+ atomic_inc(&item->refcount);
30331 ref->object = item->object;
30332 object = item->object;
30333 mutex_unlock(&item->mutex);
30334@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_gl
30335 struct ttm_global_item *item = &glob[ref->global_type];
30336
30337 mutex_lock(&item->mutex);
30338- BUG_ON(item->refcount == 0);
30339+ BUG_ON(atomic_read(&item->refcount) == 0);
30340 BUG_ON(ref->object != item->object);
30341- if (--item->refcount == 0) {
30342+ if (atomic_dec_and_test(&item->refcount)) {
30343 ref->release(ref);
30344 item->object = NULL;
30345 }
30346diff -urNp linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_memory.c linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_memory.c
30347--- linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_memory.c 2011-03-27 14:31:47.000000000 -0400
30348+++ linux-2.6.32.44/drivers/gpu/drm/ttm/ttm_memory.c 2011-04-17 15:56:46.000000000 -0400
30349@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_at
30350 NULL
30351 };
30352
30353-static struct sysfs_ops ttm_mem_zone_ops = {
30354+static const struct sysfs_ops ttm_mem_zone_ops = {
30355 .show = &ttm_mem_zone_show,
30356 .store = &ttm_mem_zone_store
30357 };
30358diff -urNp linux-2.6.32.44/drivers/gpu/drm/via/via_drv.h linux-2.6.32.44/drivers/gpu/drm/via/via_drv.h
30359--- linux-2.6.32.44/drivers/gpu/drm/via/via_drv.h 2011-03-27 14:31:47.000000000 -0400
30360+++ linux-2.6.32.44/drivers/gpu/drm/via/via_drv.h 2011-05-04 17:56:28.000000000 -0400
30361@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30362 typedef uint32_t maskarray_t[5];
30363
30364 typedef struct drm_via_irq {
30365- atomic_t irq_received;
30366+ atomic_unchecked_t irq_received;
30367 uint32_t pending_mask;
30368 uint32_t enable_mask;
30369 wait_queue_head_t irq_queue;
30370@@ -75,7 +75,7 @@ typedef struct drm_via_private {
30371 struct timeval last_vblank;
30372 int last_vblank_valid;
30373 unsigned usec_per_vblank;
30374- atomic_t vbl_received;
30375+ atomic_unchecked_t vbl_received;
30376 drm_via_state_t hc_state;
30377 char pci_buf[VIA_PCI_BUF_SIZE];
30378 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30379diff -urNp linux-2.6.32.44/drivers/gpu/drm/via/via_irq.c linux-2.6.32.44/drivers/gpu/drm/via/via_irq.c
30380--- linux-2.6.32.44/drivers/gpu/drm/via/via_irq.c 2011-03-27 14:31:47.000000000 -0400
30381+++ linux-2.6.32.44/drivers/gpu/drm/via/via_irq.c 2011-05-04 17:56:28.000000000 -0400
30382@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
30383 if (crtc != 0)
30384 return 0;
30385
30386- return atomic_read(&dev_priv->vbl_received);
30387+ return atomic_read_unchecked(&dev_priv->vbl_received);
30388 }
30389
30390 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30391@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
30392
30393 status = VIA_READ(VIA_REG_INTERRUPT);
30394 if (status & VIA_IRQ_VBLANK_PENDING) {
30395- atomic_inc(&dev_priv->vbl_received);
30396- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30397+ atomic_inc_unchecked(&dev_priv->vbl_received);
30398+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30399 do_gettimeofday(&cur_vblank);
30400 if (dev_priv->last_vblank_valid) {
30401 dev_priv->usec_per_vblank =
30402@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
30403 dev_priv->last_vblank = cur_vblank;
30404 dev_priv->last_vblank_valid = 1;
30405 }
30406- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30407+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30408 DRM_DEBUG("US per vblank is: %u\n",
30409 dev_priv->usec_per_vblank);
30410 }
30411@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
30412
30413 for (i = 0; i < dev_priv->num_irqs; ++i) {
30414 if (status & cur_irq->pending_mask) {
30415- atomic_inc(&cur_irq->irq_received);
30416+ atomic_inc_unchecked(&cur_irq->irq_received);
30417 DRM_WAKEUP(&cur_irq->irq_queue);
30418 handled = 1;
30419 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
30420@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device *
30421 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30422 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30423 masks[irq][4]));
30424- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30425+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30426 } else {
30427 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30428 (((cur_irq_sequence =
30429- atomic_read(&cur_irq->irq_received)) -
30430+ atomic_read_unchecked(&cur_irq->irq_received)) -
30431 *sequence) <= (1 << 23)));
30432 }
30433 *sequence = cur_irq_sequence;
30434@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct dr
30435 }
30436
30437 for (i = 0; i < dev_priv->num_irqs; ++i) {
30438- atomic_set(&cur_irq->irq_received, 0);
30439+ atomic_set_unchecked(&cur_irq->irq_received, 0);
30440 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30441 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30442 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30443@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev,
30444 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30445 case VIA_IRQ_RELATIVE:
30446 irqwait->request.sequence +=
30447- atomic_read(&cur_irq->irq_received);
30448+ atomic_read_unchecked(&cur_irq->irq_received);
30449 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30450 case VIA_IRQ_ABSOLUTE:
30451 break;
30452diff -urNp linux-2.6.32.44/drivers/hid/hid-core.c linux-2.6.32.44/drivers/hid/hid-core.c
30453--- linux-2.6.32.44/drivers/hid/hid-core.c 2011-05-10 22:12:01.000000000 -0400
30454+++ linux-2.6.32.44/drivers/hid/hid-core.c 2011-05-10 22:12:32.000000000 -0400
30455@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device
30456
30457 int hid_add_device(struct hid_device *hdev)
30458 {
30459- static atomic_t id = ATOMIC_INIT(0);
30460+ static atomic_unchecked_t id = ATOMIC_INIT(0);
30461 int ret;
30462
30463 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30464@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hd
30465 /* XXX hack, any other cleaner solution after the driver core
30466 * is converted to allow more than 20 bytes as the device name? */
30467 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30468- hdev->vendor, hdev->product, atomic_inc_return(&id));
30469+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30470
30471 ret = device_add(&hdev->dev);
30472 if (!ret)
30473diff -urNp linux-2.6.32.44/drivers/hid/usbhid/hiddev.c linux-2.6.32.44/drivers/hid/usbhid/hiddev.c
30474--- linux-2.6.32.44/drivers/hid/usbhid/hiddev.c 2011-03-27 14:31:47.000000000 -0400
30475+++ linux-2.6.32.44/drivers/hid/usbhid/hiddev.c 2011-04-17 15:56:46.000000000 -0400
30476@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *fi
30477 return put_user(HID_VERSION, (int __user *)arg);
30478
30479 case HIDIOCAPPLICATION:
30480- if (arg < 0 || arg >= hid->maxapplication)
30481+ if (arg >= hid->maxapplication)
30482 return -EINVAL;
30483
30484 for (i = 0; i < hid->maxcollection; i++)
30485diff -urNp linux-2.6.32.44/drivers/hwmon/lis3lv02d.c linux-2.6.32.44/drivers/hwmon/lis3lv02d.c
30486--- linux-2.6.32.44/drivers/hwmon/lis3lv02d.c 2011-03-27 14:31:47.000000000 -0400
30487+++ linux-2.6.32.44/drivers/hwmon/lis3lv02d.c 2011-05-04 17:56:28.000000000 -0400
30488@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(in
30489 * the lid is closed. This leads to interrupts as soon as a little move
30490 * is done.
30491 */
30492- atomic_inc(&lis3_dev.count);
30493+ atomic_inc_unchecked(&lis3_dev.count);
30494
30495 wake_up_interruptible(&lis3_dev.misc_wait);
30496 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
30497@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct in
30498 if (test_and_set_bit(0, &lis3_dev.misc_opened))
30499 return -EBUSY; /* already open */
30500
30501- atomic_set(&lis3_dev.count, 0);
30502+ atomic_set_unchecked(&lis3_dev.count, 0);
30503
30504 /*
30505 * The sensor can generate interrupts for free-fall and direction
30506@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struc
30507 add_wait_queue(&lis3_dev.misc_wait, &wait);
30508 while (true) {
30509 set_current_state(TASK_INTERRUPTIBLE);
30510- data = atomic_xchg(&lis3_dev.count, 0);
30511+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
30512 if (data)
30513 break;
30514
30515@@ -244,7 +244,7 @@ out:
30516 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
30517 {
30518 poll_wait(file, &lis3_dev.misc_wait, wait);
30519- if (atomic_read(&lis3_dev.count))
30520+ if (atomic_read_unchecked(&lis3_dev.count))
30521 return POLLIN | POLLRDNORM;
30522 return 0;
30523 }
30524diff -urNp linux-2.6.32.44/drivers/hwmon/lis3lv02d.h linux-2.6.32.44/drivers/hwmon/lis3lv02d.h
30525--- linux-2.6.32.44/drivers/hwmon/lis3lv02d.h 2011-03-27 14:31:47.000000000 -0400
30526+++ linux-2.6.32.44/drivers/hwmon/lis3lv02d.h 2011-05-04 17:56:28.000000000 -0400
30527@@ -201,7 +201,7 @@ struct lis3lv02d {
30528
30529 struct input_polled_dev *idev; /* input device */
30530 struct platform_device *pdev; /* platform device */
30531- atomic_t count; /* interrupt count after last read */
30532+ atomic_unchecked_t count; /* interrupt count after last read */
30533 int xcalib; /* calibrated null value for x */
30534 int ycalib; /* calibrated null value for y */
30535 int zcalib; /* calibrated null value for z */
30536diff -urNp linux-2.6.32.44/drivers/hwmon/sht15.c linux-2.6.32.44/drivers/hwmon/sht15.c
30537--- linux-2.6.32.44/drivers/hwmon/sht15.c 2011-03-27 14:31:47.000000000 -0400
30538+++ linux-2.6.32.44/drivers/hwmon/sht15.c 2011-05-04 17:56:28.000000000 -0400
30539@@ -112,7 +112,7 @@ struct sht15_data {
30540 int supply_uV;
30541 int supply_uV_valid;
30542 struct work_struct update_supply_work;
30543- atomic_t interrupt_handled;
30544+ atomic_unchecked_t interrupt_handled;
30545 };
30546
30547 /**
30548@@ -245,13 +245,13 @@ static inline int sht15_update_single_va
30549 return ret;
30550
30551 gpio_direction_input(data->pdata->gpio_data);
30552- atomic_set(&data->interrupt_handled, 0);
30553+ atomic_set_unchecked(&data->interrupt_handled, 0);
30554
30555 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30556 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30557 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30558 /* Only relevant if the interrupt hasn't occured. */
30559- if (!atomic_read(&data->interrupt_handled))
30560+ if (!atomic_read_unchecked(&data->interrupt_handled))
30561 schedule_work(&data->read_work);
30562 }
30563 ret = wait_event_timeout(data->wait_queue,
30564@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired
30565 struct sht15_data *data = d;
30566 /* First disable the interrupt */
30567 disable_irq_nosync(irq);
30568- atomic_inc(&data->interrupt_handled);
30569+ atomic_inc_unchecked(&data->interrupt_handled);
30570 /* Then schedule a reading work struct */
30571 if (data->flag != SHT15_READING_NOTHING)
30572 schedule_work(&data->read_work);
30573@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct wo
30574 here as could have gone low in meantime so verify
30575 it hasn't!
30576 */
30577- atomic_set(&data->interrupt_handled, 0);
30578+ atomic_set_unchecked(&data->interrupt_handled, 0);
30579 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30580 /* If still not occured or another handler has been scheduled */
30581 if (gpio_get_value(data->pdata->gpio_data)
30582- || atomic_read(&data->interrupt_handled))
30583+ || atomic_read_unchecked(&data->interrupt_handled))
30584 return;
30585 }
30586 /* Read the data back from the device */
30587diff -urNp linux-2.6.32.44/drivers/hwmon/w83791d.c linux-2.6.32.44/drivers/hwmon/w83791d.c
30588--- linux-2.6.32.44/drivers/hwmon/w83791d.c 2011-03-27 14:31:47.000000000 -0400
30589+++ linux-2.6.32.44/drivers/hwmon/w83791d.c 2011-04-17 15:56:46.000000000 -0400
30590@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_cli
30591 struct i2c_board_info *info);
30592 static int w83791d_remove(struct i2c_client *client);
30593
30594-static int w83791d_read(struct i2c_client *client, u8 register);
30595-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30596+static int w83791d_read(struct i2c_client *client, u8 reg);
30597+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30598 static struct w83791d_data *w83791d_update_device(struct device *dev);
30599
30600 #ifdef DEBUG
30601diff -urNp linux-2.6.32.44/drivers/i2c/busses/i2c-amd756-s4882.c linux-2.6.32.44/drivers/i2c/busses/i2c-amd756-s4882.c
30602--- linux-2.6.32.44/drivers/i2c/busses/i2c-amd756-s4882.c 2011-03-27 14:31:47.000000000 -0400
30603+++ linux-2.6.32.44/drivers/i2c/busses/i2c-amd756-s4882.c 2011-08-05 20:33:55.000000000 -0400
30604@@ -189,23 +189,23 @@ static int __init amd756_s4882_init(void
30605 }
30606
30607 /* Fill in the new structures */
30608- s4882_algo[0] = *(amd756_smbus.algo);
30609- s4882_algo[0].smbus_xfer = amd756_access_virt0;
30610+ memcpy((void *)&s4882_algo[0], amd756_smbus.algo, sizeof(s4882_algo[0]));
30611+ *(void **)&s4882_algo[0].smbus_xfer = amd756_access_virt0;
30612 s4882_adapter[0] = amd756_smbus;
30613 s4882_adapter[0].algo = s4882_algo;
30614- s4882_adapter[0].dev.parent = amd756_smbus.dev.parent;
30615+ *(void **)&s4882_adapter[0].dev.parent = amd756_smbus.dev.parent;
30616 for (i = 1; i < 5; i++) {
30617- s4882_algo[i] = *(amd756_smbus.algo);
30618+ memcpy((void *)&s4882_algo[i], amd756_smbus.algo, sizeof(s4882_algo[i]));
30619 s4882_adapter[i] = amd756_smbus;
30620 snprintf(s4882_adapter[i].name, sizeof(s4882_adapter[i].name),
30621 "SMBus 8111 adapter (CPU%d)", i-1);
30622 s4882_adapter[i].algo = s4882_algo+i;
30623 s4882_adapter[i].dev.parent = amd756_smbus.dev.parent;
30624 }
30625- s4882_algo[1].smbus_xfer = amd756_access_virt1;
30626- s4882_algo[2].smbus_xfer = amd756_access_virt2;
30627- s4882_algo[3].smbus_xfer = amd756_access_virt3;
30628- s4882_algo[4].smbus_xfer = amd756_access_virt4;
30629+ *(void **)&s4882_algo[1].smbus_xfer = amd756_access_virt1;
30630+ *(void **)&s4882_algo[2].smbus_xfer = amd756_access_virt2;
30631+ *(void **)&s4882_algo[3].smbus_xfer = amd756_access_virt3;
30632+ *(void **)&s4882_algo[4].smbus_xfer = amd756_access_virt4;
30633
30634 /* Register virtual adapters */
30635 for (i = 0; i < 5; i++) {
30636diff -urNp linux-2.6.32.44/drivers/i2c/busses/i2c-nforce2-s4985.c linux-2.6.32.44/drivers/i2c/busses/i2c-nforce2-s4985.c
30637--- linux-2.6.32.44/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-03-27 14:31:47.000000000 -0400
30638+++ linux-2.6.32.44/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-08-05 20:33:55.000000000 -0400
30639@@ -184,23 +184,23 @@ static int __init nforce2_s4985_init(voi
30640 }
30641
30642 /* Fill in the new structures */
30643- s4985_algo[0] = *(nforce2_smbus->algo);
30644- s4985_algo[0].smbus_xfer = nforce2_access_virt0;
30645+ memcpy((void *)&s4985_algo[0], nforce2_smbus->algo, sizeof(s4985_algo[0]));
30646+ *(void **)&s4985_algo[0].smbus_xfer = nforce2_access_virt0;
30647 s4985_adapter[0] = *nforce2_smbus;
30648 s4985_adapter[0].algo = s4985_algo;
30649 s4985_adapter[0].dev.parent = nforce2_smbus->dev.parent;
30650 for (i = 1; i < 5; i++) {
30651- s4985_algo[i] = *(nforce2_smbus->algo);
30652+ memcpy((void *)&s4985_algo[i], nforce2_smbus->algo, sizeof(s4985_algo[i]));
30653 s4985_adapter[i] = *nforce2_smbus;
30654 snprintf(s4985_adapter[i].name, sizeof(s4985_adapter[i].name),
30655 "SMBus nForce2 adapter (CPU%d)", i - 1);
30656 s4985_adapter[i].algo = s4985_algo + i;
30657 s4985_adapter[i].dev.parent = nforce2_smbus->dev.parent;
30658 }
30659- s4985_algo[1].smbus_xfer = nforce2_access_virt1;
30660- s4985_algo[2].smbus_xfer = nforce2_access_virt2;
30661- s4985_algo[3].smbus_xfer = nforce2_access_virt3;
30662- s4985_algo[4].smbus_xfer = nforce2_access_virt4;
30663+ *(void **)&s4985_algo[1].smbus_xfer = nforce2_access_virt1;
30664+ *(void **)&s4985_algo[2].smbus_xfer = nforce2_access_virt2;
30665+ *(void **)&s4985_algo[3].smbus_xfer = nforce2_access_virt3;
30666+ *(void **)&s4985_algo[4].smbus_xfer = nforce2_access_virt4;
30667
30668 /* Register virtual adapters */
30669 for (i = 0; i < 5; i++) {
30670diff -urNp linux-2.6.32.44/drivers/ide/ide-cd.c linux-2.6.32.44/drivers/ide/ide-cd.c
30671--- linux-2.6.32.44/drivers/ide/ide-cd.c 2011-03-27 14:31:47.000000000 -0400
30672+++ linux-2.6.32.44/drivers/ide/ide-cd.c 2011-04-17 15:56:46.000000000 -0400
30673@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_
30674 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30675 if ((unsigned long)buf & alignment
30676 || blk_rq_bytes(rq) & q->dma_pad_mask
30677- || object_is_on_stack(buf))
30678+ || object_starts_on_stack(buf))
30679 drive->dma = 0;
30680 }
30681 }
30682diff -urNp linux-2.6.32.44/drivers/ide/ide-floppy.c linux-2.6.32.44/drivers/ide/ide-floppy.c
30683--- linux-2.6.32.44/drivers/ide/ide-floppy.c 2011-03-27 14:31:47.000000000 -0400
30684+++ linux-2.6.32.44/drivers/ide/ide-floppy.c 2011-05-16 21:46:57.000000000 -0400
30685@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_d
30686 u8 pc_buf[256], header_len, desc_cnt;
30687 int i, rc = 1, blocks, length;
30688
30689+ pax_track_stack();
30690+
30691 ide_debug_log(IDE_DBG_FUNC, "enter");
30692
30693 drive->bios_cyl = 0;
30694diff -urNp linux-2.6.32.44/drivers/ide/setup-pci.c linux-2.6.32.44/drivers/ide/setup-pci.c
30695--- linux-2.6.32.44/drivers/ide/setup-pci.c 2011-03-27 14:31:47.000000000 -0400
30696+++ linux-2.6.32.44/drivers/ide/setup-pci.c 2011-05-16 21:46:57.000000000 -0400
30697@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30698 int ret, i, n_ports = dev2 ? 4 : 2;
30699 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30700
30701+ pax_track_stack();
30702+
30703 for (i = 0; i < n_ports / 2; i++) {
30704 ret = ide_setup_pci_controller(pdev[i], d, !i);
30705 if (ret < 0)
30706diff -urNp linux-2.6.32.44/drivers/ieee1394/dv1394.c linux-2.6.32.44/drivers/ieee1394/dv1394.c
30707--- linux-2.6.32.44/drivers/ieee1394/dv1394.c 2011-03-27 14:31:47.000000000 -0400
30708+++ linux-2.6.32.44/drivers/ieee1394/dv1394.c 2011-04-23 12:56:11.000000000 -0400
30709@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
30710 based upon DIF section and sequence
30711 */
30712
30713-static void inline
30714+static inline void
30715 frame_put_packet (struct frame *f, struct packet *p)
30716 {
30717 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
30718diff -urNp linux-2.6.32.44/drivers/ieee1394/hosts.c linux-2.6.32.44/drivers/ieee1394/hosts.c
30719--- linux-2.6.32.44/drivers/ieee1394/hosts.c 2011-03-27 14:31:47.000000000 -0400
30720+++ linux-2.6.32.44/drivers/ieee1394/hosts.c 2011-04-17 15:56:46.000000000 -0400
30721@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
30722 }
30723
30724 static struct hpsb_host_driver dummy_driver = {
30725+ .name = "dummy",
30726 .transmit_packet = dummy_transmit_packet,
30727 .devctl = dummy_devctl,
30728 .isoctl = dummy_isoctl
30729diff -urNp linux-2.6.32.44/drivers/ieee1394/init_ohci1394_dma.c linux-2.6.32.44/drivers/ieee1394/init_ohci1394_dma.c
30730--- linux-2.6.32.44/drivers/ieee1394/init_ohci1394_dma.c 2011-03-27 14:31:47.000000000 -0400
30731+++ linux-2.6.32.44/drivers/ieee1394/init_ohci1394_dma.c 2011-04-17 15:56:46.000000000 -0400
30732@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_con
30733 for (func = 0; func < 8; func++) {
30734 u32 class = read_pci_config(num,slot,func,
30735 PCI_CLASS_REVISION);
30736- if ((class == 0xffffffff))
30737+ if (class == 0xffffffff)
30738 continue; /* No device at this func */
30739
30740 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
30741diff -urNp linux-2.6.32.44/drivers/ieee1394/ohci1394.c linux-2.6.32.44/drivers/ieee1394/ohci1394.c
30742--- linux-2.6.32.44/drivers/ieee1394/ohci1394.c 2011-03-27 14:31:47.000000000 -0400
30743+++ linux-2.6.32.44/drivers/ieee1394/ohci1394.c 2011-04-23 12:56:11.000000000 -0400
30744@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
30745 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
30746
30747 /* Module Parameters */
30748-static int phys_dma = 1;
30749+static int phys_dma;
30750 module_param(phys_dma, int, 0444);
30751-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
30752+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
30753
30754 static void dma_trm_tasklet(unsigned long data);
30755 static void dma_trm_reset(struct dma_trm_ctx *d);
30756diff -urNp linux-2.6.32.44/drivers/ieee1394/sbp2.c linux-2.6.32.44/drivers/ieee1394/sbp2.c
30757--- linux-2.6.32.44/drivers/ieee1394/sbp2.c 2011-03-27 14:31:47.000000000 -0400
30758+++ linux-2.6.32.44/drivers/ieee1394/sbp2.c 2011-04-23 12:56:11.000000000 -0400
30759@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
30760 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
30761 MODULE_LICENSE("GPL");
30762
30763-static int sbp2_module_init(void)
30764+static int __init sbp2_module_init(void)
30765 {
30766 int ret;
30767
30768diff -urNp linux-2.6.32.44/drivers/infiniband/core/cm.c linux-2.6.32.44/drivers/infiniband/core/cm.c
30769--- linux-2.6.32.44/drivers/infiniband/core/cm.c 2011-03-27 14:31:47.000000000 -0400
30770+++ linux-2.6.32.44/drivers/infiniband/core/cm.c 2011-04-17 15:56:46.000000000 -0400
30771@@ -112,7 +112,7 @@ static char const counter_group_names[CM
30772
30773 struct cm_counter_group {
30774 struct kobject obj;
30775- atomic_long_t counter[CM_ATTR_COUNT];
30776+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30777 };
30778
30779 struct cm_counter_attribute {
30780@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm
30781 struct ib_mad_send_buf *msg = NULL;
30782 int ret;
30783
30784- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30785+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30786 counter[CM_REQ_COUNTER]);
30787
30788 /* Quick state check to discard duplicate REQs. */
30789@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm
30790 if (!cm_id_priv)
30791 return;
30792
30793- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30794+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30795 counter[CM_REP_COUNTER]);
30796 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30797 if (ret)
30798@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work
30799 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30800 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30801 spin_unlock_irq(&cm_id_priv->lock);
30802- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30803+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30804 counter[CM_RTU_COUNTER]);
30805 goto out;
30806 }
30807@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_wor
30808 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30809 dreq_msg->local_comm_id);
30810 if (!cm_id_priv) {
30811- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30812+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30813 counter[CM_DREQ_COUNTER]);
30814 cm_issue_drep(work->port, work->mad_recv_wc);
30815 return -EINVAL;
30816@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_wor
30817 case IB_CM_MRA_REP_RCVD:
30818 break;
30819 case IB_CM_TIMEWAIT:
30820- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30821+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30822 counter[CM_DREQ_COUNTER]);
30823 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30824 goto unlock;
30825@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_wor
30826 cm_free_msg(msg);
30827 goto deref;
30828 case IB_CM_DREQ_RCVD:
30829- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30830+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30831 counter[CM_DREQ_COUNTER]);
30832 goto unlock;
30833 default:
30834@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work
30835 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30836 cm_id_priv->msg, timeout)) {
30837 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30838- atomic_long_inc(&work->port->
30839+ atomic_long_inc_unchecked(&work->port->
30840 counter_group[CM_RECV_DUPLICATES].
30841 counter[CM_MRA_COUNTER]);
30842 goto out;
30843@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work
30844 break;
30845 case IB_CM_MRA_REQ_RCVD:
30846 case IB_CM_MRA_REP_RCVD:
30847- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30848+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30849 counter[CM_MRA_COUNTER]);
30850 /* fall through */
30851 default:
30852@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work
30853 case IB_CM_LAP_IDLE:
30854 break;
30855 case IB_CM_MRA_LAP_SENT:
30856- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30857+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30858 counter[CM_LAP_COUNTER]);
30859 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30860 goto unlock;
30861@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work
30862 cm_free_msg(msg);
30863 goto deref;
30864 case IB_CM_LAP_RCVD:
30865- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30866+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30867 counter[CM_LAP_COUNTER]);
30868 goto unlock;
30869 default:
30870@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm
30871 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30872 if (cur_cm_id_priv) {
30873 spin_unlock_irq(&cm.lock);
30874- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30875+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30876 counter[CM_SIDR_REQ_COUNTER]);
30877 goto out; /* Duplicate message. */
30878 }
30879@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_ma
30880 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30881 msg->retries = 1;
30882
30883- atomic_long_add(1 + msg->retries,
30884+ atomic_long_add_unchecked(1 + msg->retries,
30885 &port->counter_group[CM_XMIT].counter[attr_index]);
30886 if (msg->retries)
30887- atomic_long_add(msg->retries,
30888+ atomic_long_add_unchecked(msg->retries,
30889 &port->counter_group[CM_XMIT_RETRIES].
30890 counter[attr_index]);
30891
30892@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_ma
30893 }
30894
30895 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30896- atomic_long_inc(&port->counter_group[CM_RECV].
30897+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30898 counter[attr_id - CM_ATTR_ID_OFFSET]);
30899
30900 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30901@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct ko
30902 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30903
30904 return sprintf(buf, "%ld\n",
30905- atomic_long_read(&group->counter[cm_attr->index]));
30906+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30907 }
30908
30909-static struct sysfs_ops cm_counter_ops = {
30910+static const struct sysfs_ops cm_counter_ops = {
30911 .show = cm_show_counter
30912 };
30913
30914diff -urNp linux-2.6.32.44/drivers/infiniband/core/fmr_pool.c linux-2.6.32.44/drivers/infiniband/core/fmr_pool.c
30915--- linux-2.6.32.44/drivers/infiniband/core/fmr_pool.c 2011-03-27 14:31:47.000000000 -0400
30916+++ linux-2.6.32.44/drivers/infiniband/core/fmr_pool.c 2011-05-04 17:56:28.000000000 -0400
30917@@ -97,8 +97,8 @@ struct ib_fmr_pool {
30918
30919 struct task_struct *thread;
30920
30921- atomic_t req_ser;
30922- atomic_t flush_ser;
30923+ atomic_unchecked_t req_ser;
30924+ atomic_unchecked_t flush_ser;
30925
30926 wait_queue_head_t force_wait;
30927 };
30928@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30929 struct ib_fmr_pool *pool = pool_ptr;
30930
30931 do {
30932- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30933+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30934 ib_fmr_batch_release(pool);
30935
30936- atomic_inc(&pool->flush_ser);
30937+ atomic_inc_unchecked(&pool->flush_ser);
30938 wake_up_interruptible(&pool->force_wait);
30939
30940 if (pool->flush_function)
30941@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30942 }
30943
30944 set_current_state(TASK_INTERRUPTIBLE);
30945- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30946+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30947 !kthread_should_stop())
30948 schedule();
30949 __set_current_state(TASK_RUNNING);
30950@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30951 pool->dirty_watermark = params->dirty_watermark;
30952 pool->dirty_len = 0;
30953 spin_lock_init(&pool->pool_lock);
30954- atomic_set(&pool->req_ser, 0);
30955- atomic_set(&pool->flush_ser, 0);
30956+ atomic_set_unchecked(&pool->req_ser, 0);
30957+ atomic_set_unchecked(&pool->flush_ser, 0);
30958 init_waitqueue_head(&pool->force_wait);
30959
30960 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30961@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30962 }
30963 spin_unlock_irq(&pool->pool_lock);
30964
30965- serial = atomic_inc_return(&pool->req_ser);
30966+ serial = atomic_inc_return_unchecked(&pool->req_ser);
30967 wake_up_process(pool->thread);
30968
30969 if (wait_event_interruptible(pool->force_wait,
30970- atomic_read(&pool->flush_ser) - serial >= 0))
30971+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30972 return -EINTR;
30973
30974 return 0;
30975@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30976 } else {
30977 list_add_tail(&fmr->list, &pool->dirty_list);
30978 if (++pool->dirty_len >= pool->dirty_watermark) {
30979- atomic_inc(&pool->req_ser);
30980+ atomic_inc_unchecked(&pool->req_ser);
30981 wake_up_process(pool->thread);
30982 }
30983 }
30984diff -urNp linux-2.6.32.44/drivers/infiniband/core/sysfs.c linux-2.6.32.44/drivers/infiniband/core/sysfs.c
30985--- linux-2.6.32.44/drivers/infiniband/core/sysfs.c 2011-03-27 14:31:47.000000000 -0400
30986+++ linux-2.6.32.44/drivers/infiniband/core/sysfs.c 2011-04-17 15:56:46.000000000 -0400
30987@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kob
30988 return port_attr->show(p, port_attr, buf);
30989 }
30990
30991-static struct sysfs_ops port_sysfs_ops = {
30992+static const struct sysfs_ops port_sysfs_ops = {
30993 .show = port_attr_show
30994 };
30995
30996diff -urNp linux-2.6.32.44/drivers/infiniband/core/uverbs_marshall.c linux-2.6.32.44/drivers/infiniband/core/uverbs_marshall.c
30997--- linux-2.6.32.44/drivers/infiniband/core/uverbs_marshall.c 2011-03-27 14:31:47.000000000 -0400
30998+++ linux-2.6.32.44/drivers/infiniband/core/uverbs_marshall.c 2011-04-17 15:56:46.000000000 -0400
30999@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_u
31000 dst->grh.sgid_index = src->grh.sgid_index;
31001 dst->grh.hop_limit = src->grh.hop_limit;
31002 dst->grh.traffic_class = src->grh.traffic_class;
31003+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
31004 dst->dlid = src->dlid;
31005 dst->sl = src->sl;
31006 dst->src_path_bits = src->src_path_bits;
31007 dst->static_rate = src->static_rate;
31008 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
31009 dst->port_num = src->port_num;
31010+ dst->reserved = 0;
31011 }
31012 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
31013
31014 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
31015 struct ib_qp_attr *src)
31016 {
31017+ dst->qp_state = src->qp_state;
31018 dst->cur_qp_state = src->cur_qp_state;
31019 dst->path_mtu = src->path_mtu;
31020 dst->path_mig_state = src->path_mig_state;
31021@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_u
31022 dst->rnr_retry = src->rnr_retry;
31023 dst->alt_port_num = src->alt_port_num;
31024 dst->alt_timeout = src->alt_timeout;
31025+ memset(dst->reserved, 0, sizeof(dst->reserved));
31026 }
31027 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
31028
31029diff -urNp linux-2.6.32.44/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.32.44/drivers/infiniband/hw/ipath/ipath_fs.c
31030--- linux-2.6.32.44/drivers/infiniband/hw/ipath/ipath_fs.c 2011-03-27 14:31:47.000000000 -0400
31031+++ linux-2.6.32.44/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-16 21:46:57.000000000 -0400
31032@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(stru
31033 struct infinipath_counters counters;
31034 struct ipath_devdata *dd;
31035
31036+ pax_track_stack();
31037+
31038 dd = file->f_path.dentry->d_inode->i_private;
31039 dd->ipath_f_read_counters(dd, &counters);
31040
31041diff -urNp linux-2.6.32.44/drivers/infiniband/hw/nes/nes.c linux-2.6.32.44/drivers/infiniband/hw/nes/nes.c
31042--- linux-2.6.32.44/drivers/infiniband/hw/nes/nes.c 2011-03-27 14:31:47.000000000 -0400
31043+++ linux-2.6.32.44/drivers/infiniband/hw/nes/nes.c 2011-05-04 17:56:28.000000000 -0400
31044@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
31045 LIST_HEAD(nes_adapter_list);
31046 static LIST_HEAD(nes_dev_list);
31047
31048-atomic_t qps_destroyed;
31049+atomic_unchecked_t qps_destroyed;
31050
31051 static unsigned int ee_flsh_adapter;
31052 static unsigned int sysfs_nonidx_addr;
31053@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(str
31054 struct nes_adapter *nesadapter = nesdev->nesadapter;
31055 u32 qp_id;
31056
31057- atomic_inc(&qps_destroyed);
31058+ atomic_inc_unchecked(&qps_destroyed);
31059
31060 /* Free the control structures */
31061
31062diff -urNp linux-2.6.32.44/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.32.44/drivers/infiniband/hw/nes/nes_cm.c
31063--- linux-2.6.32.44/drivers/infiniband/hw/nes/nes_cm.c 2011-03-27 14:31:47.000000000 -0400
31064+++ linux-2.6.32.44/drivers/infiniband/hw/nes/nes_cm.c 2011-05-04 17:56:28.000000000 -0400
31065@@ -69,11 +69,11 @@ u32 cm_packets_received;
31066 u32 cm_listens_created;
31067 u32 cm_listens_destroyed;
31068 u32 cm_backlog_drops;
31069-atomic_t cm_loopbacks;
31070-atomic_t cm_nodes_created;
31071-atomic_t cm_nodes_destroyed;
31072-atomic_t cm_accel_dropped_pkts;
31073-atomic_t cm_resets_recvd;
31074+atomic_unchecked_t cm_loopbacks;
31075+atomic_unchecked_t cm_nodes_created;
31076+atomic_unchecked_t cm_nodes_destroyed;
31077+atomic_unchecked_t cm_accel_dropped_pkts;
31078+atomic_unchecked_t cm_resets_recvd;
31079
31080 static inline int mini_cm_accelerated(struct nes_cm_core *,
31081 struct nes_cm_node *);
31082@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
31083
31084 static struct nes_cm_core *g_cm_core;
31085
31086-atomic_t cm_connects;
31087-atomic_t cm_accepts;
31088-atomic_t cm_disconnects;
31089-atomic_t cm_closes;
31090-atomic_t cm_connecteds;
31091-atomic_t cm_connect_reqs;
31092-atomic_t cm_rejects;
31093+atomic_unchecked_t cm_connects;
31094+atomic_unchecked_t cm_accepts;
31095+atomic_unchecked_t cm_disconnects;
31096+atomic_unchecked_t cm_closes;
31097+atomic_unchecked_t cm_connecteds;
31098+atomic_unchecked_t cm_connect_reqs;
31099+atomic_unchecked_t cm_rejects;
31100
31101
31102 /**
31103@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(
31104 cm_node->rem_mac);
31105
31106 add_hte_node(cm_core, cm_node);
31107- atomic_inc(&cm_nodes_created);
31108+ atomic_inc_unchecked(&cm_nodes_created);
31109
31110 return cm_node;
31111 }
31112@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm
31113 }
31114
31115 atomic_dec(&cm_core->node_cnt);
31116- atomic_inc(&cm_nodes_destroyed);
31117+ atomic_inc_unchecked(&cm_nodes_destroyed);
31118 nesqp = cm_node->nesqp;
31119 if (nesqp) {
31120 nesqp->cm_node = NULL;
31121@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm
31122
31123 static void drop_packet(struct sk_buff *skb)
31124 {
31125- atomic_inc(&cm_accel_dropped_pkts);
31126+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
31127 dev_kfree_skb_any(skb);
31128 }
31129
31130@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm
31131
31132 int reset = 0; /* whether to send reset in case of err.. */
31133 int passive_state;
31134- atomic_inc(&cm_resets_recvd);
31135+ atomic_inc_unchecked(&cm_resets_recvd);
31136 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
31137 " refcnt=%d\n", cm_node, cm_node->state,
31138 atomic_read(&cm_node->ref_count));
31139@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_conne
31140 rem_ref_cm_node(cm_node->cm_core, cm_node);
31141 return NULL;
31142 }
31143- atomic_inc(&cm_loopbacks);
31144+ atomic_inc_unchecked(&cm_loopbacks);
31145 loopbackremotenode->loopbackpartner = cm_node;
31146 loopbackremotenode->tcp_cntxt.rcv_wscale =
31147 NES_CM_DEFAULT_RCV_WND_SCALE;
31148@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_c
31149 add_ref_cm_node(cm_node);
31150 } else if (cm_node->state == NES_CM_STATE_TSA) {
31151 rem_ref_cm_node(cm_core, cm_node);
31152- atomic_inc(&cm_accel_dropped_pkts);
31153+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
31154 dev_kfree_skb_any(skb);
31155 break;
31156 }
31157@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct ne
31158
31159 if ((cm_id) && (cm_id->event_handler)) {
31160 if (issue_disconn) {
31161- atomic_inc(&cm_disconnects);
31162+ atomic_inc_unchecked(&cm_disconnects);
31163 cm_event.event = IW_CM_EVENT_DISCONNECT;
31164 cm_event.status = disconn_status;
31165 cm_event.local_addr = cm_id->local_addr;
31166@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct ne
31167 }
31168
31169 if (issue_close) {
31170- atomic_inc(&cm_closes);
31171+ atomic_inc_unchecked(&cm_closes);
31172 nes_disconnect(nesqp, 1);
31173
31174 cm_id->provider_data = nesqp;
31175@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
31176
31177 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
31178 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
31179- atomic_inc(&cm_accepts);
31180+ atomic_inc_unchecked(&cm_accepts);
31181
31182 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
31183 atomic_read(&nesvnic->netdev->refcnt));
31184@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
31185
31186 struct nes_cm_core *cm_core;
31187
31188- atomic_inc(&cm_rejects);
31189+ atomic_inc_unchecked(&cm_rejects);
31190 cm_node = (struct nes_cm_node *) cm_id->provider_data;
31191 loopback = cm_node->loopbackpartner;
31192 cm_core = cm_node->cm_core;
31193@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id,
31194 ntohl(cm_id->local_addr.sin_addr.s_addr),
31195 ntohs(cm_id->local_addr.sin_port));
31196
31197- atomic_inc(&cm_connects);
31198+ atomic_inc_unchecked(&cm_connects);
31199 nesqp->active_conn = 1;
31200
31201 /* cache the cm_id in the qp */
31202@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct ne
31203 if (nesqp->destroyed) {
31204 return;
31205 }
31206- atomic_inc(&cm_connecteds);
31207+ atomic_inc_unchecked(&cm_connecteds);
31208 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
31209 " local port 0x%04X. jiffies = %lu.\n",
31210 nesqp->hwqp.qp_id,
31211@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm
31212
31213 ret = cm_id->event_handler(cm_id, &cm_event);
31214 cm_id->add_ref(cm_id);
31215- atomic_inc(&cm_closes);
31216+ atomic_inc_unchecked(&cm_closes);
31217 cm_event.event = IW_CM_EVENT_CLOSE;
31218 cm_event.status = IW_CM_EVENT_STATUS_OK;
31219 cm_event.provider_data = cm_id->provider_data;
31220@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_
31221 return;
31222 cm_id = cm_node->cm_id;
31223
31224- atomic_inc(&cm_connect_reqs);
31225+ atomic_inc_unchecked(&cm_connect_reqs);
31226 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31227 cm_node, cm_id, jiffies);
31228
31229@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct n
31230 return;
31231 cm_id = cm_node->cm_id;
31232
31233- atomic_inc(&cm_connect_reqs);
31234+ atomic_inc_unchecked(&cm_connect_reqs);
31235 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31236 cm_node, cm_id, jiffies);
31237
31238diff -urNp linux-2.6.32.44/drivers/infiniband/hw/nes/nes.h linux-2.6.32.44/drivers/infiniband/hw/nes/nes.h
31239--- linux-2.6.32.44/drivers/infiniband/hw/nes/nes.h 2011-03-27 14:31:47.000000000 -0400
31240+++ linux-2.6.32.44/drivers/infiniband/hw/nes/nes.h 2011-05-04 17:56:28.000000000 -0400
31241@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
31242 extern unsigned int wqm_quanta;
31243 extern struct list_head nes_adapter_list;
31244
31245-extern atomic_t cm_connects;
31246-extern atomic_t cm_accepts;
31247-extern atomic_t cm_disconnects;
31248-extern atomic_t cm_closes;
31249-extern atomic_t cm_connecteds;
31250-extern atomic_t cm_connect_reqs;
31251-extern atomic_t cm_rejects;
31252-extern atomic_t mod_qp_timouts;
31253-extern atomic_t qps_created;
31254-extern atomic_t qps_destroyed;
31255-extern atomic_t sw_qps_destroyed;
31256+extern atomic_unchecked_t cm_connects;
31257+extern atomic_unchecked_t cm_accepts;
31258+extern atomic_unchecked_t cm_disconnects;
31259+extern atomic_unchecked_t cm_closes;
31260+extern atomic_unchecked_t cm_connecteds;
31261+extern atomic_unchecked_t cm_connect_reqs;
31262+extern atomic_unchecked_t cm_rejects;
31263+extern atomic_unchecked_t mod_qp_timouts;
31264+extern atomic_unchecked_t qps_created;
31265+extern atomic_unchecked_t qps_destroyed;
31266+extern atomic_unchecked_t sw_qps_destroyed;
31267 extern u32 mh_detected;
31268 extern u32 mh_pauses_sent;
31269 extern u32 cm_packets_sent;
31270@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
31271 extern u32 cm_listens_created;
31272 extern u32 cm_listens_destroyed;
31273 extern u32 cm_backlog_drops;
31274-extern atomic_t cm_loopbacks;
31275-extern atomic_t cm_nodes_created;
31276-extern atomic_t cm_nodes_destroyed;
31277-extern atomic_t cm_accel_dropped_pkts;
31278-extern atomic_t cm_resets_recvd;
31279+extern atomic_unchecked_t cm_loopbacks;
31280+extern atomic_unchecked_t cm_nodes_created;
31281+extern atomic_unchecked_t cm_nodes_destroyed;
31282+extern atomic_unchecked_t cm_accel_dropped_pkts;
31283+extern atomic_unchecked_t cm_resets_recvd;
31284
31285 extern u32 int_mod_timer_init;
31286 extern u32 int_mod_cq_depth_256;
31287diff -urNp linux-2.6.32.44/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.32.44/drivers/infiniband/hw/nes/nes_nic.c
31288--- linux-2.6.32.44/drivers/infiniband/hw/nes/nes_nic.c 2011-03-27 14:31:47.000000000 -0400
31289+++ linux-2.6.32.44/drivers/infiniband/hw/nes/nes_nic.c 2011-05-04 17:56:28.000000000 -0400
31290@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats
31291 target_stat_values[++index] = mh_detected;
31292 target_stat_values[++index] = mh_pauses_sent;
31293 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31294- target_stat_values[++index] = atomic_read(&cm_connects);
31295- target_stat_values[++index] = atomic_read(&cm_accepts);
31296- target_stat_values[++index] = atomic_read(&cm_disconnects);
31297- target_stat_values[++index] = atomic_read(&cm_connecteds);
31298- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31299- target_stat_values[++index] = atomic_read(&cm_rejects);
31300- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31301- target_stat_values[++index] = atomic_read(&qps_created);
31302- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31303- target_stat_values[++index] = atomic_read(&qps_destroyed);
31304- target_stat_values[++index] = atomic_read(&cm_closes);
31305+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31306+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31307+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31308+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31309+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31310+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31311+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31312+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31313+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31314+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31315+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31316 target_stat_values[++index] = cm_packets_sent;
31317 target_stat_values[++index] = cm_packets_bounced;
31318 target_stat_values[++index] = cm_packets_created;
31319@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats
31320 target_stat_values[++index] = cm_listens_created;
31321 target_stat_values[++index] = cm_listens_destroyed;
31322 target_stat_values[++index] = cm_backlog_drops;
31323- target_stat_values[++index] = atomic_read(&cm_loopbacks);
31324- target_stat_values[++index] = atomic_read(&cm_nodes_created);
31325- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31326- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31327- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31328+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31329+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31330+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31331+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31332+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31333 target_stat_values[++index] = int_mod_timer_init;
31334 target_stat_values[++index] = int_mod_cq_depth_1;
31335 target_stat_values[++index] = int_mod_cq_depth_4;
31336diff -urNp linux-2.6.32.44/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.32.44/drivers/infiniband/hw/nes/nes_verbs.c
31337--- linux-2.6.32.44/drivers/infiniband/hw/nes/nes_verbs.c 2011-03-27 14:31:47.000000000 -0400
31338+++ linux-2.6.32.44/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-04 17:56:28.000000000 -0400
31339@@ -45,9 +45,9 @@
31340
31341 #include <rdma/ib_umem.h>
31342
31343-atomic_t mod_qp_timouts;
31344-atomic_t qps_created;
31345-atomic_t sw_qps_destroyed;
31346+atomic_unchecked_t mod_qp_timouts;
31347+atomic_unchecked_t qps_created;
31348+atomic_unchecked_t sw_qps_destroyed;
31349
31350 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31351
31352@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struc
31353 if (init_attr->create_flags)
31354 return ERR_PTR(-EINVAL);
31355
31356- atomic_inc(&qps_created);
31357+ atomic_inc_unchecked(&qps_created);
31358 switch (init_attr->qp_type) {
31359 case IB_QPT_RC:
31360 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31361@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *
31362 struct iw_cm_event cm_event;
31363 int ret;
31364
31365- atomic_inc(&sw_qps_destroyed);
31366+ atomic_inc_unchecked(&sw_qps_destroyed);
31367 nesqp->destroyed = 1;
31368
31369 /* Blow away the connection if it exists. */
31370diff -urNp linux-2.6.32.44/drivers/input/gameport/gameport.c linux-2.6.32.44/drivers/input/gameport/gameport.c
31371--- linux-2.6.32.44/drivers/input/gameport/gameport.c 2011-03-27 14:31:47.000000000 -0400
31372+++ linux-2.6.32.44/drivers/input/gameport/gameport.c 2011-05-04 17:56:28.000000000 -0400
31373@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
31374 */
31375 static void gameport_init_port(struct gameport *gameport)
31376 {
31377- static atomic_t gameport_no = ATOMIC_INIT(0);
31378+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31379
31380 __module_get(THIS_MODULE);
31381
31382 mutex_init(&gameport->drv_mutex);
31383 device_initialize(&gameport->dev);
31384- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
31385+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31386 gameport->dev.bus = &gameport_bus;
31387 gameport->dev.release = gameport_release_port;
31388 if (gameport->parent)
31389diff -urNp linux-2.6.32.44/drivers/input/input.c linux-2.6.32.44/drivers/input/input.c
31390--- linux-2.6.32.44/drivers/input/input.c 2011-03-27 14:31:47.000000000 -0400
31391+++ linux-2.6.32.44/drivers/input/input.c 2011-05-04 17:56:28.000000000 -0400
31392@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
31393 */
31394 int input_register_device(struct input_dev *dev)
31395 {
31396- static atomic_t input_no = ATOMIC_INIT(0);
31397+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31398 struct input_handler *handler;
31399 const char *path;
31400 int error;
31401@@ -1585,7 +1585,7 @@ int input_register_device(struct input_d
31402 dev->setkeycode = input_default_setkeycode;
31403
31404 dev_set_name(&dev->dev, "input%ld",
31405- (unsigned long) atomic_inc_return(&input_no) - 1);
31406+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31407
31408 error = device_add(&dev->dev);
31409 if (error)
31410diff -urNp linux-2.6.32.44/drivers/input/joystick/sidewinder.c linux-2.6.32.44/drivers/input/joystick/sidewinder.c
31411--- linux-2.6.32.44/drivers/input/joystick/sidewinder.c 2011-03-27 14:31:47.000000000 -0400
31412+++ linux-2.6.32.44/drivers/input/joystick/sidewinder.c 2011-05-18 20:09:36.000000000 -0400
31413@@ -30,6 +30,7 @@
31414 #include <linux/kernel.h>
31415 #include <linux/module.h>
31416 #include <linux/slab.h>
31417+#include <linux/sched.h>
31418 #include <linux/init.h>
31419 #include <linux/input.h>
31420 #include <linux/gameport.h>
31421@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31422 unsigned char buf[SW_LENGTH];
31423 int i;
31424
31425+ pax_track_stack();
31426+
31427 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31428
31429 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31430diff -urNp linux-2.6.32.44/drivers/input/joystick/xpad.c linux-2.6.32.44/drivers/input/joystick/xpad.c
31431--- linux-2.6.32.44/drivers/input/joystick/xpad.c 2011-03-27 14:31:47.000000000 -0400
31432+++ linux-2.6.32.44/drivers/input/joystick/xpad.c 2011-05-04 17:56:28.000000000 -0400
31433@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_clas
31434
31435 static int xpad_led_probe(struct usb_xpad *xpad)
31436 {
31437- static atomic_t led_seq = ATOMIC_INIT(0);
31438+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31439 long led_no;
31440 struct xpad_led *led;
31441 struct led_classdev *led_cdev;
31442@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpa
31443 if (!led)
31444 return -ENOMEM;
31445
31446- led_no = (long)atomic_inc_return(&led_seq) - 1;
31447+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31448
31449 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31450 led->xpad = xpad;
31451diff -urNp linux-2.6.32.44/drivers/input/serio/serio.c linux-2.6.32.44/drivers/input/serio/serio.c
31452--- linux-2.6.32.44/drivers/input/serio/serio.c 2011-03-27 14:31:47.000000000 -0400
31453+++ linux-2.6.32.44/drivers/input/serio/serio.c 2011-05-04 17:56:28.000000000 -0400
31454@@ -527,7 +527,7 @@ static void serio_release_port(struct de
31455 */
31456 static void serio_init_port(struct serio *serio)
31457 {
31458- static atomic_t serio_no = ATOMIC_INIT(0);
31459+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31460
31461 __module_get(THIS_MODULE);
31462
31463@@ -536,7 +536,7 @@ static void serio_init_port(struct serio
31464 mutex_init(&serio->drv_mutex);
31465 device_initialize(&serio->dev);
31466 dev_set_name(&serio->dev, "serio%ld",
31467- (long)atomic_inc_return(&serio_no) - 1);
31468+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
31469 serio->dev.bus = &serio_bus;
31470 serio->dev.release = serio_release_port;
31471 if (serio->parent) {
31472diff -urNp linux-2.6.32.44/drivers/isdn/gigaset/common.c linux-2.6.32.44/drivers/isdn/gigaset/common.c
31473--- linux-2.6.32.44/drivers/isdn/gigaset/common.c 2011-03-27 14:31:47.000000000 -0400
31474+++ linux-2.6.32.44/drivers/isdn/gigaset/common.c 2011-04-17 15:56:46.000000000 -0400
31475@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct
31476 cs->commands_pending = 0;
31477 cs->cur_at_seq = 0;
31478 cs->gotfwver = -1;
31479- cs->open_count = 0;
31480+ local_set(&cs->open_count, 0);
31481 cs->dev = NULL;
31482 cs->tty = NULL;
31483 cs->tty_dev = NULL;
31484diff -urNp linux-2.6.32.44/drivers/isdn/gigaset/gigaset.h linux-2.6.32.44/drivers/isdn/gigaset/gigaset.h
31485--- linux-2.6.32.44/drivers/isdn/gigaset/gigaset.h 2011-03-27 14:31:47.000000000 -0400
31486+++ linux-2.6.32.44/drivers/isdn/gigaset/gigaset.h 2011-04-17 15:56:46.000000000 -0400
31487@@ -34,6 +34,7 @@
31488 #include <linux/tty_driver.h>
31489 #include <linux/list.h>
31490 #include <asm/atomic.h>
31491+#include <asm/local.h>
31492
31493 #define GIG_VERSION {0,5,0,0}
31494 #define GIG_COMPAT {0,4,0,0}
31495@@ -446,7 +447,7 @@ struct cardstate {
31496 spinlock_t cmdlock;
31497 unsigned curlen, cmdbytes;
31498
31499- unsigned open_count;
31500+ local_t open_count;
31501 struct tty_struct *tty;
31502 struct tasklet_struct if_wake_tasklet;
31503 unsigned control_state;
31504diff -urNp linux-2.6.32.44/drivers/isdn/gigaset/interface.c linux-2.6.32.44/drivers/isdn/gigaset/interface.c
31505--- linux-2.6.32.44/drivers/isdn/gigaset/interface.c 2011-03-27 14:31:47.000000000 -0400
31506+++ linux-2.6.32.44/drivers/isdn/gigaset/interface.c 2011-04-17 15:56:46.000000000 -0400
31507@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tt
31508 return -ERESTARTSYS; // FIXME -EINTR?
31509 tty->driver_data = cs;
31510
31511- ++cs->open_count;
31512-
31513- if (cs->open_count == 1) {
31514+ if (local_inc_return(&cs->open_count) == 1) {
31515 spin_lock_irqsave(&cs->lock, flags);
31516 cs->tty = tty;
31517 spin_unlock_irqrestore(&cs->lock, flags);
31518@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *
31519
31520 if (!cs->connected)
31521 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31522- else if (!cs->open_count)
31523+ else if (!local_read(&cs->open_count))
31524 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31525 else {
31526- if (!--cs->open_count) {
31527+ if (!local_dec_return(&cs->open_count)) {
31528 spin_lock_irqsave(&cs->lock, flags);
31529 cs->tty = NULL;
31530 spin_unlock_irqrestore(&cs->lock, flags);
31531@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *t
31532 if (!cs->connected) {
31533 gig_dbg(DEBUG_IF, "not connected");
31534 retval = -ENODEV;
31535- } else if (!cs->open_count)
31536+ } else if (!local_read(&cs->open_count))
31537 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31538 else {
31539 retval = 0;
31540@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *t
31541 if (!cs->connected) {
31542 gig_dbg(DEBUG_IF, "not connected");
31543 retval = -ENODEV;
31544- } else if (!cs->open_count)
31545+ } else if (!local_read(&cs->open_count))
31546 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31547 else if (cs->mstate != MS_LOCKED) {
31548 dev_warn(cs->dev, "can't write to unlocked device\n");
31549@@ -395,7 +393,7 @@ static int if_write_room(struct tty_stru
31550 if (!cs->connected) {
31551 gig_dbg(DEBUG_IF, "not connected");
31552 retval = -ENODEV;
31553- } else if (!cs->open_count)
31554+ } else if (!local_read(&cs->open_count))
31555 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31556 else if (cs->mstate != MS_LOCKED) {
31557 dev_warn(cs->dev, "can't write to unlocked device\n");
31558@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty
31559
31560 if (!cs->connected)
31561 gig_dbg(DEBUG_IF, "not connected");
31562- else if (!cs->open_count)
31563+ else if (!local_read(&cs->open_count))
31564 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31565 else if (cs->mstate != MS_LOCKED)
31566 dev_warn(cs->dev, "can't write to unlocked device\n");
31567@@ -453,7 +451,7 @@ static void if_throttle(struct tty_struc
31568
31569 if (!cs->connected)
31570 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31571- else if (!cs->open_count)
31572+ else if (!local_read(&cs->open_count))
31573 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31574 else {
31575 //FIXME
31576@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_str
31577
31578 if (!cs->connected)
31579 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31580- else if (!cs->open_count)
31581+ else if (!local_read(&cs->open_count))
31582 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31583 else {
31584 //FIXME
31585@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_st
31586 goto out;
31587 }
31588
31589- if (!cs->open_count) {
31590+ if (!local_read(&cs->open_count)) {
31591 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31592 goto out;
31593 }
31594diff -urNp linux-2.6.32.44/drivers/isdn/hardware/avm/b1.c linux-2.6.32.44/drivers/isdn/hardware/avm/b1.c
31595--- linux-2.6.32.44/drivers/isdn/hardware/avm/b1.c 2011-03-27 14:31:47.000000000 -0400
31596+++ linux-2.6.32.44/drivers/isdn/hardware/avm/b1.c 2011-04-17 15:56:46.000000000 -0400
31597@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capilo
31598 }
31599 if (left) {
31600 if (t4file->user) {
31601- if (copy_from_user(buf, dp, left))
31602+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31603 return -EFAULT;
31604 } else {
31605 memcpy(buf, dp, left);
31606@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capilo
31607 }
31608 if (left) {
31609 if (config->user) {
31610- if (copy_from_user(buf, dp, left))
31611+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31612 return -EFAULT;
31613 } else {
31614 memcpy(buf, dp, left);
31615diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.32.44/drivers/isdn/hardware/eicon/capidtmf.c
31616--- linux-2.6.32.44/drivers/isdn/hardware/eicon/capidtmf.c 2011-03-27 14:31:47.000000000 -0400
31617+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-16 21:46:57.000000000 -0400
31618@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31619 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31620 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31621
31622+ pax_track_stack();
31623
31624 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31625 {
31626diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.32.44/drivers/isdn/hardware/eicon/capifunc.c
31627--- linux-2.6.32.44/drivers/isdn/hardware/eicon/capifunc.c 2011-03-27 14:31:47.000000000 -0400
31628+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/capifunc.c 2011-05-16 21:46:57.000000000 -0400
31629@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31630 IDI_SYNC_REQ req;
31631 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31632
31633+ pax_track_stack();
31634+
31635 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31636
31637 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31638diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.32.44/drivers/isdn/hardware/eicon/diddfunc.c
31639--- linux-2.6.32.44/drivers/isdn/hardware/eicon/diddfunc.c 2011-03-27 14:31:47.000000000 -0400
31640+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-16 21:46:57.000000000 -0400
31641@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31642 IDI_SYNC_REQ req;
31643 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31644
31645+ pax_track_stack();
31646+
31647 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31648
31649 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31650diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.32.44/drivers/isdn/hardware/eicon/divasfunc.c
31651--- linux-2.6.32.44/drivers/isdn/hardware/eicon/divasfunc.c 2011-03-27 14:31:47.000000000 -0400
31652+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-16 21:46:57.000000000 -0400
31653@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31654 IDI_SYNC_REQ req;
31655 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31656
31657+ pax_track_stack();
31658+
31659 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31660
31661 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31662diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/divasync.h linux-2.6.32.44/drivers/isdn/hardware/eicon/divasync.h
31663--- linux-2.6.32.44/drivers/isdn/hardware/eicon/divasync.h 2011-03-27 14:31:47.000000000 -0400
31664+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/divasync.h 2011-08-05 20:33:55.000000000 -0400
31665@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
31666 } diva_didd_add_adapter_t;
31667 typedef struct _diva_didd_remove_adapter {
31668 IDI_CALL p_request;
31669-} diva_didd_remove_adapter_t;
31670+} __no_const diva_didd_remove_adapter_t;
31671 typedef struct _diva_didd_read_adapter_array {
31672 void * buffer;
31673 dword length;
31674diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.32.44/drivers/isdn/hardware/eicon/idifunc.c
31675--- linux-2.6.32.44/drivers/isdn/hardware/eicon/idifunc.c 2011-03-27 14:31:47.000000000 -0400
31676+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/idifunc.c 2011-05-16 21:46:57.000000000 -0400
31677@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31678 IDI_SYNC_REQ req;
31679 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31680
31681+ pax_track_stack();
31682+
31683 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31684
31685 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31686diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/message.c linux-2.6.32.44/drivers/isdn/hardware/eicon/message.c
31687--- linux-2.6.32.44/drivers/isdn/hardware/eicon/message.c 2011-03-27 14:31:47.000000000 -0400
31688+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/message.c 2011-05-16 21:46:57.000000000 -0400
31689@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31690 dword d;
31691 word w;
31692
31693+ pax_track_stack();
31694+
31695 a = plci->adapter;
31696 Id = ((word)plci->Id<<8)|a->Id;
31697 PUT_WORD(&SS_Ind[4],0x0000);
31698@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31699 word j, n, w;
31700 dword d;
31701
31702+ pax_track_stack();
31703+
31704
31705 for(i=0;i<8;i++) bp_parms[i].length = 0;
31706 for(i=0;i<2;i++) global_config[i].length = 0;
31707@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31708 const byte llc3[] = {4,3,2,2,6,6,0};
31709 const byte header[] = {0,2,3,3,0,0,0};
31710
31711+ pax_track_stack();
31712+
31713 for(i=0;i<8;i++) bp_parms[i].length = 0;
31714 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31715 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31716@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI
31717 word appl_number_group_type[MAX_APPL];
31718 PLCI *auxplci;
31719
31720+ pax_track_stack();
31721+
31722 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31723
31724 if(!a->group_optimization_enabled)
31725diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.32.44/drivers/isdn/hardware/eicon/mntfunc.c
31726--- linux-2.6.32.44/drivers/isdn/hardware/eicon/mntfunc.c 2011-03-27 14:31:47.000000000 -0400
31727+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-16 21:46:57.000000000 -0400
31728@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31729 IDI_SYNC_REQ req;
31730 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31731
31732+ pax_track_stack();
31733+
31734 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31735
31736 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31737diff -urNp linux-2.6.32.44/drivers/isdn/hardware/eicon/xdi_adapter.h linux-2.6.32.44/drivers/isdn/hardware/eicon/xdi_adapter.h
31738--- linux-2.6.32.44/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-03-27 14:31:47.000000000 -0400
31739+++ linux-2.6.32.44/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-08-05 20:33:55.000000000 -0400
31740@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
31741 typedef struct _diva_os_idi_adapter_interface {
31742 diva_init_card_proc_t cleanup_adapter_proc;
31743 diva_cmd_card_proc_t cmd_proc;
31744-} diva_os_idi_adapter_interface_t;
31745+} __no_const diva_os_idi_adapter_interface_t;
31746
31747 typedef struct _diva_os_xdi_adapter {
31748 struct list_head link;
31749diff -urNp linux-2.6.32.44/drivers/isdn/i4l/isdn_common.c linux-2.6.32.44/drivers/isdn/i4l/isdn_common.c
31750--- linux-2.6.32.44/drivers/isdn/i4l/isdn_common.c 2011-03-27 14:31:47.000000000 -0400
31751+++ linux-2.6.32.44/drivers/isdn/i4l/isdn_common.c 2011-05-16 21:46:57.000000000 -0400
31752@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct f
31753 } iocpar;
31754 void __user *argp = (void __user *)arg;
31755
31756+ pax_track_stack();
31757+
31758 #define name iocpar.name
31759 #define bname iocpar.bname
31760 #define iocts iocpar.iocts
31761diff -urNp linux-2.6.32.44/drivers/isdn/icn/icn.c linux-2.6.32.44/drivers/isdn/icn/icn.c
31762--- linux-2.6.32.44/drivers/isdn/icn/icn.c 2011-03-27 14:31:47.000000000 -0400
31763+++ linux-2.6.32.44/drivers/isdn/icn/icn.c 2011-04-17 15:56:46.000000000 -0400
31764@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len
31765 if (count > len)
31766 count = len;
31767 if (user) {
31768- if (copy_from_user(msg, buf, count))
31769+ if (count > sizeof msg || copy_from_user(msg, buf, count))
31770 return -EFAULT;
31771 } else
31772 memcpy(msg, buf, count);
31773diff -urNp linux-2.6.32.44/drivers/isdn/mISDN/socket.c linux-2.6.32.44/drivers/isdn/mISDN/socket.c
31774--- linux-2.6.32.44/drivers/isdn/mISDN/socket.c 2011-03-27 14:31:47.000000000 -0400
31775+++ linux-2.6.32.44/drivers/isdn/mISDN/socket.c 2011-04-17 15:56:46.000000000 -0400
31776@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, uns
31777 if (dev) {
31778 struct mISDN_devinfo di;
31779
31780+ memset(&di, 0, sizeof(di));
31781 di.id = dev->id;
31782 di.Dprotocols = dev->Dprotocols;
31783 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
31784@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, uns
31785 if (dev) {
31786 struct mISDN_devinfo di;
31787
31788+ memset(&di, 0, sizeof(di));
31789 di.id = dev->id;
31790 di.Dprotocols = dev->Dprotocols;
31791 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
31792diff -urNp linux-2.6.32.44/drivers/isdn/sc/interrupt.c linux-2.6.32.44/drivers/isdn/sc/interrupt.c
31793--- linux-2.6.32.44/drivers/isdn/sc/interrupt.c 2011-03-27 14:31:47.000000000 -0400
31794+++ linux-2.6.32.44/drivers/isdn/sc/interrupt.c 2011-04-17 15:56:46.000000000 -0400
31795@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy,
31796 }
31797 else if(callid>=0x0000 && callid<=0x7FFF)
31798 {
31799+ int len;
31800+
31801 pr_debug("%s: Got Incoming Call\n",
31802 sc_adapter[card]->devicename);
31803- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
31804- strcpy(setup.eazmsn,
31805- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
31806+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
31807+ sizeof(setup.phone));
31808+ if (len >= sizeof(setup.phone))
31809+ continue;
31810+ len = strlcpy(setup.eazmsn,
31811+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
31812+ sizeof(setup.eazmsn));
31813+ if (len >= sizeof(setup.eazmsn))
31814+ continue;
31815 setup.si1 = 7;
31816 setup.si2 = 0;
31817 setup.plan = 0;
31818@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy,
31819 * Handle a GetMyNumber Rsp
31820 */
31821 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
31822- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
31823+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
31824+ rcvmsg.msg_data.byte_array,
31825+ sizeof(rcvmsg.msg_data.byte_array));
31826 continue;
31827 }
31828
31829diff -urNp linux-2.6.32.44/drivers/lguest/core.c linux-2.6.32.44/drivers/lguest/core.c
31830--- linux-2.6.32.44/drivers/lguest/core.c 2011-03-27 14:31:47.000000000 -0400
31831+++ linux-2.6.32.44/drivers/lguest/core.c 2011-04-17 15:56:46.000000000 -0400
31832@@ -91,9 +91,17 @@ static __init int map_switcher(void)
31833 * it's worked so far. The end address needs +1 because __get_vm_area
31834 * allocates an extra guard page, so we need space for that.
31835 */
31836+
31837+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31838+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31839+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31840+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31841+#else
31842 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31843 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31844 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31845+#endif
31846+
31847 if (!switcher_vma) {
31848 err = -ENOMEM;
31849 printk("lguest: could not map switcher pages high\n");
31850@@ -118,7 +126,7 @@ static __init int map_switcher(void)
31851 * Now the Switcher is mapped at the right address, we can't fail!
31852 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31853 */
31854- memcpy(switcher_vma->addr, start_switcher_text,
31855+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31856 end_switcher_text - start_switcher_text);
31857
31858 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31859diff -urNp linux-2.6.32.44/drivers/lguest/x86/core.c linux-2.6.32.44/drivers/lguest/x86/core.c
31860--- linux-2.6.32.44/drivers/lguest/x86/core.c 2011-03-27 14:31:47.000000000 -0400
31861+++ linux-2.6.32.44/drivers/lguest/x86/core.c 2011-04-17 15:56:46.000000000 -0400
31862@@ -59,7 +59,7 @@ static struct {
31863 /* Offset from where switcher.S was compiled to where we've copied it */
31864 static unsigned long switcher_offset(void)
31865 {
31866- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31867+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31868 }
31869
31870 /* This cpu's struct lguest_pages. */
31871@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31872 * These copies are pretty cheap, so we do them unconditionally: */
31873 /* Save the current Host top-level page directory.
31874 */
31875+
31876+#ifdef CONFIG_PAX_PER_CPU_PGD
31877+ pages->state.host_cr3 = read_cr3();
31878+#else
31879 pages->state.host_cr3 = __pa(current->mm->pgd);
31880+#endif
31881+
31882 /*
31883 * Set up the Guest's page tables to see this CPU's pages (and no
31884 * other CPU's pages).
31885@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
31886 * compiled-in switcher code and the high-mapped copy we just made.
31887 */
31888 for (i = 0; i < IDT_ENTRIES; i++)
31889- default_idt_entries[i] += switcher_offset();
31890+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31891
31892 /*
31893 * Set up the Switcher's per-cpu areas.
31894@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
31895 * it will be undisturbed when we switch. To change %cs and jump we
31896 * need this structure to feed to Intel's "lcall" instruction.
31897 */
31898- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31899+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31900 lguest_entry.segment = LGUEST_CS;
31901
31902 /*
31903diff -urNp linux-2.6.32.44/drivers/lguest/x86/switcher_32.S linux-2.6.32.44/drivers/lguest/x86/switcher_32.S
31904--- linux-2.6.32.44/drivers/lguest/x86/switcher_32.S 2011-03-27 14:31:47.000000000 -0400
31905+++ linux-2.6.32.44/drivers/lguest/x86/switcher_32.S 2011-04-17 15:56:46.000000000 -0400
31906@@ -87,6 +87,7 @@
31907 #include <asm/page.h>
31908 #include <asm/segment.h>
31909 #include <asm/lguest.h>
31910+#include <asm/processor-flags.h>
31911
31912 // We mark the start of the code to copy
31913 // It's placed in .text tho it's never run here
31914@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31915 // Changes type when we load it: damn Intel!
31916 // For after we switch over our page tables
31917 // That entry will be read-only: we'd crash.
31918+
31919+#ifdef CONFIG_PAX_KERNEXEC
31920+ mov %cr0, %edx
31921+ xor $X86_CR0_WP, %edx
31922+ mov %edx, %cr0
31923+#endif
31924+
31925 movl $(GDT_ENTRY_TSS*8), %edx
31926 ltr %dx
31927
31928@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31929 // Let's clear it again for our return.
31930 // The GDT descriptor of the Host
31931 // Points to the table after two "size" bytes
31932- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31933+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31934 // Clear "used" from type field (byte 5, bit 2)
31935- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31936+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31937+
31938+#ifdef CONFIG_PAX_KERNEXEC
31939+ mov %cr0, %eax
31940+ xor $X86_CR0_WP, %eax
31941+ mov %eax, %cr0
31942+#endif
31943
31944 // Once our page table's switched, the Guest is live!
31945 // The Host fades as we run this final step.
31946@@ -295,13 +309,12 @@ deliver_to_host:
31947 // I consulted gcc, and it gave
31948 // These instructions, which I gladly credit:
31949 leal (%edx,%ebx,8), %eax
31950- movzwl (%eax),%edx
31951- movl 4(%eax), %eax
31952- xorw %ax, %ax
31953- orl %eax, %edx
31954+ movl 4(%eax), %edx
31955+ movw (%eax), %dx
31956 // Now the address of the handler's in %edx
31957 // We call it now: its "iret" drops us home.
31958- jmp *%edx
31959+ ljmp $__KERNEL_CS, $1f
31960+1: jmp *%edx
31961
31962 // Every interrupt can come to us here
31963 // But we must truly tell each apart.
31964diff -urNp linux-2.6.32.44/drivers/macintosh/via-pmu-backlight.c linux-2.6.32.44/drivers/macintosh/via-pmu-backlight.c
31965--- linux-2.6.32.44/drivers/macintosh/via-pmu-backlight.c 2011-03-27 14:31:47.000000000 -0400
31966+++ linux-2.6.32.44/drivers/macintosh/via-pmu-backlight.c 2011-04-17 15:56:46.000000000 -0400
31967@@ -15,7 +15,7 @@
31968
31969 #define MAX_PMU_LEVEL 0xFF
31970
31971-static struct backlight_ops pmu_backlight_data;
31972+static const struct backlight_ops pmu_backlight_data;
31973 static DEFINE_SPINLOCK(pmu_backlight_lock);
31974 static int sleeping, uses_pmu_bl;
31975 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
31976@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(
31977 return bd->props.brightness;
31978 }
31979
31980-static struct backlight_ops pmu_backlight_data = {
31981+static const struct backlight_ops pmu_backlight_data = {
31982 .get_brightness = pmu_backlight_get_brightness,
31983 .update_status = pmu_backlight_update_status,
31984
31985diff -urNp linux-2.6.32.44/drivers/macintosh/via-pmu.c linux-2.6.32.44/drivers/macintosh/via-pmu.c
31986--- linux-2.6.32.44/drivers/macintosh/via-pmu.c 2011-03-27 14:31:47.000000000 -0400
31987+++ linux-2.6.32.44/drivers/macintosh/via-pmu.c 2011-04-17 15:56:46.000000000 -0400
31988@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state
31989 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
31990 }
31991
31992-static struct platform_suspend_ops pmu_pm_ops = {
31993+static const struct platform_suspend_ops pmu_pm_ops = {
31994 .enter = powerbook_sleep,
31995 .valid = pmu_sleep_valid,
31996 };
31997diff -urNp linux-2.6.32.44/drivers/md/dm.c linux-2.6.32.44/drivers/md/dm.c
31998--- linux-2.6.32.44/drivers/md/dm.c 2011-08-09 18:35:29.000000000 -0400
31999+++ linux-2.6.32.44/drivers/md/dm.c 2011-08-09 18:33:59.000000000 -0400
32000@@ -165,9 +165,9 @@ struct mapped_device {
32001 /*
32002 * Event handling.
32003 */
32004- atomic_t event_nr;
32005+ atomic_unchecked_t event_nr;
32006 wait_queue_head_t eventq;
32007- atomic_t uevent_seq;
32008+ atomic_unchecked_t uevent_seq;
32009 struct list_head uevent_list;
32010 spinlock_t uevent_lock; /* Protect access to uevent_list */
32011
32012@@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(i
32013 rwlock_init(&md->map_lock);
32014 atomic_set(&md->holders, 1);
32015 atomic_set(&md->open_count, 0);
32016- atomic_set(&md->event_nr, 0);
32017- atomic_set(&md->uevent_seq, 0);
32018+ atomic_set_unchecked(&md->event_nr, 0);
32019+ atomic_set_unchecked(&md->uevent_seq, 0);
32020 INIT_LIST_HEAD(&md->uevent_list);
32021 spin_lock_init(&md->uevent_lock);
32022
32023@@ -1927,7 +1927,7 @@ static void event_callback(void *context
32024
32025 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
32026
32027- atomic_inc(&md->event_nr);
32028+ atomic_inc_unchecked(&md->event_nr);
32029 wake_up(&md->eventq);
32030 }
32031
32032@@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_dev
32033
32034 uint32_t dm_next_uevent_seq(struct mapped_device *md)
32035 {
32036- return atomic_add_return(1, &md->uevent_seq);
32037+ return atomic_add_return_unchecked(1, &md->uevent_seq);
32038 }
32039
32040 uint32_t dm_get_event_nr(struct mapped_device *md)
32041 {
32042- return atomic_read(&md->event_nr);
32043+ return atomic_read_unchecked(&md->event_nr);
32044 }
32045
32046 int dm_wait_event(struct mapped_device *md, int event_nr)
32047 {
32048 return wait_event_interruptible(md->eventq,
32049- (event_nr != atomic_read(&md->event_nr)));
32050+ (event_nr != atomic_read_unchecked(&md->event_nr)));
32051 }
32052
32053 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
32054diff -urNp linux-2.6.32.44/drivers/md/dm-ioctl.c linux-2.6.32.44/drivers/md/dm-ioctl.c
32055--- linux-2.6.32.44/drivers/md/dm-ioctl.c 2011-03-27 14:31:47.000000000 -0400
32056+++ linux-2.6.32.44/drivers/md/dm-ioctl.c 2011-04-17 15:56:46.000000000 -0400
32057@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, str
32058 cmd == DM_LIST_VERSIONS_CMD)
32059 return 0;
32060
32061- if ((cmd == DM_DEV_CREATE_CMD)) {
32062+ if (cmd == DM_DEV_CREATE_CMD) {
32063 if (!*param->name) {
32064 DMWARN("name not supplied when creating device");
32065 return -EINVAL;
32066diff -urNp linux-2.6.32.44/drivers/md/dm-raid1.c linux-2.6.32.44/drivers/md/dm-raid1.c
32067--- linux-2.6.32.44/drivers/md/dm-raid1.c 2011-03-27 14:31:47.000000000 -0400
32068+++ linux-2.6.32.44/drivers/md/dm-raid1.c 2011-05-04 17:56:28.000000000 -0400
32069@@ -41,7 +41,7 @@ enum dm_raid1_error {
32070
32071 struct mirror {
32072 struct mirror_set *ms;
32073- atomic_t error_count;
32074+ atomic_unchecked_t error_count;
32075 unsigned long error_type;
32076 struct dm_dev *dev;
32077 sector_t offset;
32078@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m
32079 * simple way to tell if a device has encountered
32080 * errors.
32081 */
32082- atomic_inc(&m->error_count);
32083+ atomic_inc_unchecked(&m->error_count);
32084
32085 if (test_and_set_bit(error_type, &m->error_type))
32086 return;
32087@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m
32088 }
32089
32090 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
32091- if (!atomic_read(&new->error_count)) {
32092+ if (!atomic_read_unchecked(&new->error_count)) {
32093 set_default_mirror(new);
32094 break;
32095 }
32096@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(stru
32097 struct mirror *m = get_default_mirror(ms);
32098
32099 do {
32100- if (likely(!atomic_read(&m->error_count)))
32101+ if (likely(!atomic_read_unchecked(&m->error_count)))
32102 return m;
32103
32104 if (m-- == ms->mirror)
32105@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
32106 {
32107 struct mirror *default_mirror = get_default_mirror(m->ms);
32108
32109- return !atomic_read(&default_mirror->error_count);
32110+ return !atomic_read_unchecked(&default_mirror->error_count);
32111 }
32112
32113 static int mirror_available(struct mirror_set *ms, struct bio *bio)
32114@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *
32115 */
32116 if (likely(region_in_sync(ms, region, 1)))
32117 m = choose_mirror(ms, bio->bi_sector);
32118- else if (m && atomic_read(&m->error_count))
32119+ else if (m && atomic_read_unchecked(&m->error_count))
32120 m = NULL;
32121
32122 if (likely(m))
32123@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set
32124 }
32125
32126 ms->mirror[mirror].ms = ms;
32127- atomic_set(&(ms->mirror[mirror].error_count), 0);
32128+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
32129 ms->mirror[mirror].error_type = 0;
32130 ms->mirror[mirror].offset = offset;
32131
32132@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_targ
32133 */
32134 static char device_status_char(struct mirror *m)
32135 {
32136- if (!atomic_read(&(m->error_count)))
32137+ if (!atomic_read_unchecked(&(m->error_count)))
32138 return 'A';
32139
32140 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
32141diff -urNp linux-2.6.32.44/drivers/md/dm-stripe.c linux-2.6.32.44/drivers/md/dm-stripe.c
32142--- linux-2.6.32.44/drivers/md/dm-stripe.c 2011-03-27 14:31:47.000000000 -0400
32143+++ linux-2.6.32.44/drivers/md/dm-stripe.c 2011-05-04 17:56:28.000000000 -0400
32144@@ -20,7 +20,7 @@ struct stripe {
32145 struct dm_dev *dev;
32146 sector_t physical_start;
32147
32148- atomic_t error_count;
32149+ atomic_unchecked_t error_count;
32150 };
32151
32152 struct stripe_c {
32153@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *
32154 kfree(sc);
32155 return r;
32156 }
32157- atomic_set(&(sc->stripe[i].error_count), 0);
32158+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32159 }
32160
32161 ti->private = sc;
32162@@ -257,7 +257,7 @@ static int stripe_status(struct dm_targe
32163 DMEMIT("%d ", sc->stripes);
32164 for (i = 0; i < sc->stripes; i++) {
32165 DMEMIT("%s ", sc->stripe[i].dev->name);
32166- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32167+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32168 'D' : 'A';
32169 }
32170 buffer[i] = '\0';
32171@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_targe
32172 */
32173 for (i = 0; i < sc->stripes; i++)
32174 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32175- atomic_inc(&(sc->stripe[i].error_count));
32176- if (atomic_read(&(sc->stripe[i].error_count)) <
32177+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
32178+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32179 DM_IO_ERROR_THRESHOLD)
32180 queue_work(kstriped, &sc->kstriped_ws);
32181 }
32182diff -urNp linux-2.6.32.44/drivers/md/dm-sysfs.c linux-2.6.32.44/drivers/md/dm-sysfs.c
32183--- linux-2.6.32.44/drivers/md/dm-sysfs.c 2011-03-27 14:31:47.000000000 -0400
32184+++ linux-2.6.32.44/drivers/md/dm-sysfs.c 2011-04-17 15:56:46.000000000 -0400
32185@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
32186 NULL,
32187 };
32188
32189-static struct sysfs_ops dm_sysfs_ops = {
32190+static const struct sysfs_ops dm_sysfs_ops = {
32191 .show = dm_attr_show,
32192 };
32193
32194diff -urNp linux-2.6.32.44/drivers/md/dm-table.c linux-2.6.32.44/drivers/md/dm-table.c
32195--- linux-2.6.32.44/drivers/md/dm-table.c 2011-06-25 12:55:34.000000000 -0400
32196+++ linux-2.6.32.44/drivers/md/dm-table.c 2011-06-25 12:56:37.000000000 -0400
32197@@ -376,7 +376,7 @@ static int device_area_is_invalid(struct
32198 if (!dev_size)
32199 return 0;
32200
32201- if ((start >= dev_size) || (start + len > dev_size)) {
32202+ if ((start >= dev_size) || (len > dev_size - start)) {
32203 DMWARN("%s: %s too small for target: "
32204 "start=%llu, len=%llu, dev_size=%llu",
32205 dm_device_name(ti->table->md), bdevname(bdev, b),
32206diff -urNp linux-2.6.32.44/drivers/md/md.c linux-2.6.32.44/drivers/md/md.c
32207--- linux-2.6.32.44/drivers/md/md.c 2011-07-13 17:23:04.000000000 -0400
32208+++ linux-2.6.32.44/drivers/md/md.c 2011-07-13 17:23:18.000000000 -0400
32209@@ -153,10 +153,10 @@ static int start_readonly;
32210 * start build, activate spare
32211 */
32212 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32213-static atomic_t md_event_count;
32214+static atomic_unchecked_t md_event_count;
32215 void md_new_event(mddev_t *mddev)
32216 {
32217- atomic_inc(&md_event_count);
32218+ atomic_inc_unchecked(&md_event_count);
32219 wake_up(&md_event_waiters);
32220 }
32221 EXPORT_SYMBOL_GPL(md_new_event);
32222@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32223 */
32224 static void md_new_event_inintr(mddev_t *mddev)
32225 {
32226- atomic_inc(&md_event_count);
32227+ atomic_inc_unchecked(&md_event_count);
32228 wake_up(&md_event_waiters);
32229 }
32230
32231@@ -1218,7 +1218,7 @@ static int super_1_load(mdk_rdev_t *rdev
32232
32233 rdev->preferred_minor = 0xffff;
32234 rdev->data_offset = le64_to_cpu(sb->data_offset);
32235- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32236+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32237
32238 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32239 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32240@@ -1392,7 +1392,7 @@ static void super_1_sync(mddev_t *mddev,
32241 else
32242 sb->resync_offset = cpu_to_le64(0);
32243
32244- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32245+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32246
32247 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32248 sb->size = cpu_to_le64(mddev->dev_sectors);
32249@@ -2214,7 +2214,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
32250 static ssize_t
32251 errors_show(mdk_rdev_t *rdev, char *page)
32252 {
32253- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32254+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32255 }
32256
32257 static ssize_t
32258@@ -2223,7 +2223,7 @@ errors_store(mdk_rdev_t *rdev, const cha
32259 char *e;
32260 unsigned long n = simple_strtoul(buf, &e, 10);
32261 if (*buf && (*e == 0 || *e == '\n')) {
32262- atomic_set(&rdev->corrected_errors, n);
32263+ atomic_set_unchecked(&rdev->corrected_errors, n);
32264 return len;
32265 }
32266 return -EINVAL;
32267@@ -2517,7 +2517,7 @@ static void rdev_free(struct kobject *ko
32268 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
32269 kfree(rdev);
32270 }
32271-static struct sysfs_ops rdev_sysfs_ops = {
32272+static const struct sysfs_ops rdev_sysfs_ops = {
32273 .show = rdev_attr_show,
32274 .store = rdev_attr_store,
32275 };
32276@@ -2566,8 +2566,8 @@ static mdk_rdev_t *md_import_device(dev_
32277 rdev->data_offset = 0;
32278 rdev->sb_events = 0;
32279 atomic_set(&rdev->nr_pending, 0);
32280- atomic_set(&rdev->read_errors, 0);
32281- atomic_set(&rdev->corrected_errors, 0);
32282+ atomic_set_unchecked(&rdev->read_errors, 0);
32283+ atomic_set_unchecked(&rdev->corrected_errors, 0);
32284
32285 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
32286 if (!size) {
32287@@ -3887,7 +3887,7 @@ static void md_free(struct kobject *ko)
32288 kfree(mddev);
32289 }
32290
32291-static struct sysfs_ops md_sysfs_ops = {
32292+static const struct sysfs_ops md_sysfs_ops = {
32293 .show = md_attr_show,
32294 .store = md_attr_store,
32295 };
32296@@ -4474,7 +4474,8 @@ out:
32297 err = 0;
32298 blk_integrity_unregister(disk);
32299 md_new_event(mddev);
32300- sysfs_notify_dirent(mddev->sysfs_state);
32301+ if (mddev->sysfs_state)
32302+ sysfs_notify_dirent(mddev->sysfs_state);
32303 return err;
32304 }
32305
32306@@ -5954,7 +5955,7 @@ static int md_seq_show(struct seq_file *
32307
32308 spin_unlock(&pers_lock);
32309 seq_printf(seq, "\n");
32310- mi->event = atomic_read(&md_event_count);
32311+ mi->event = atomic_read_unchecked(&md_event_count);
32312 return 0;
32313 }
32314 if (v == (void*)2) {
32315@@ -6043,7 +6044,7 @@ static int md_seq_show(struct seq_file *
32316 chunk_kb ? "KB" : "B");
32317 if (bitmap->file) {
32318 seq_printf(seq, ", file: ");
32319- seq_path(seq, &bitmap->file->f_path, " \t\n");
32320+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32321 }
32322
32323 seq_printf(seq, "\n");
32324@@ -6077,7 +6078,7 @@ static int md_seq_open(struct inode *ino
32325 else {
32326 struct seq_file *p = file->private_data;
32327 p->private = mi;
32328- mi->event = atomic_read(&md_event_count);
32329+ mi->event = atomic_read_unchecked(&md_event_count);
32330 }
32331 return error;
32332 }
32333@@ -6093,7 +6094,7 @@ static unsigned int mdstat_poll(struct f
32334 /* always allow read */
32335 mask = POLLIN | POLLRDNORM;
32336
32337- if (mi->event != atomic_read(&md_event_count))
32338+ if (mi->event != atomic_read_unchecked(&md_event_count))
32339 mask |= POLLERR | POLLPRI;
32340 return mask;
32341 }
32342@@ -6137,7 +6138,7 @@ static int is_mddev_idle(mddev_t *mddev,
32343 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32344 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32345 (int)part_stat_read(&disk->part0, sectors[1]) -
32346- atomic_read(&disk->sync_io);
32347+ atomic_read_unchecked(&disk->sync_io);
32348 /* sync IO will cause sync_io to increase before the disk_stats
32349 * as sync_io is counted when a request starts, and
32350 * disk_stats is counted when it completes.
32351diff -urNp linux-2.6.32.44/drivers/md/md.h linux-2.6.32.44/drivers/md/md.h
32352--- linux-2.6.32.44/drivers/md/md.h 2011-03-27 14:31:47.000000000 -0400
32353+++ linux-2.6.32.44/drivers/md/md.h 2011-05-04 17:56:20.000000000 -0400
32354@@ -94,10 +94,10 @@ struct mdk_rdev_s
32355 * only maintained for arrays that
32356 * support hot removal
32357 */
32358- atomic_t read_errors; /* number of consecutive read errors that
32359+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
32360 * we have tried to ignore.
32361 */
32362- atomic_t corrected_errors; /* number of corrected read errors,
32363+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32364 * for reporting to userspace and storing
32365 * in superblock.
32366 */
32367@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_
32368
32369 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32370 {
32371- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32372+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32373 }
32374
32375 struct mdk_personality
32376diff -urNp linux-2.6.32.44/drivers/md/raid10.c linux-2.6.32.44/drivers/md/raid10.c
32377--- linux-2.6.32.44/drivers/md/raid10.c 2011-03-27 14:31:47.000000000 -0400
32378+++ linux-2.6.32.44/drivers/md/raid10.c 2011-05-04 17:56:28.000000000 -0400
32379@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bi
32380 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
32381 set_bit(R10BIO_Uptodate, &r10_bio->state);
32382 else {
32383- atomic_add(r10_bio->sectors,
32384+ atomic_add_unchecked(r10_bio->sectors,
32385 &conf->mirrors[d].rdev->corrected_errors);
32386 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
32387 md_error(r10_bio->mddev,
32388@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf,
32389 test_bit(In_sync, &rdev->flags)) {
32390 atomic_inc(&rdev->nr_pending);
32391 rcu_read_unlock();
32392- atomic_add(s, &rdev->corrected_errors);
32393+ atomic_add_unchecked(s, &rdev->corrected_errors);
32394 if (sync_page_io(rdev->bdev,
32395 r10_bio->devs[sl].addr +
32396 sect + rdev->data_offset,
32397diff -urNp linux-2.6.32.44/drivers/md/raid1.c linux-2.6.32.44/drivers/md/raid1.c
32398--- linux-2.6.32.44/drivers/md/raid1.c 2011-03-27 14:31:47.000000000 -0400
32399+++ linux-2.6.32.44/drivers/md/raid1.c 2011-05-04 17:56:28.000000000 -0400
32400@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *
32401 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
32402 continue;
32403 rdev = conf->mirrors[d].rdev;
32404- atomic_add(s, &rdev->corrected_errors);
32405+ atomic_add_unchecked(s, &rdev->corrected_errors);
32406 if (sync_page_io(rdev->bdev,
32407 sect + rdev->data_offset,
32408 s<<9,
32409@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf,
32410 /* Well, this device is dead */
32411 md_error(mddev, rdev);
32412 else {
32413- atomic_add(s, &rdev->corrected_errors);
32414+ atomic_add_unchecked(s, &rdev->corrected_errors);
32415 printk(KERN_INFO
32416 "raid1:%s: read error corrected "
32417 "(%d sectors at %llu on %s)\n",
32418diff -urNp linux-2.6.32.44/drivers/md/raid5.c linux-2.6.32.44/drivers/md/raid5.c
32419--- linux-2.6.32.44/drivers/md/raid5.c 2011-06-25 12:55:34.000000000 -0400
32420+++ linux-2.6.32.44/drivers/md/raid5.c 2011-06-25 12:58:39.000000000 -0400
32421@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_hea
32422 bi->bi_next = NULL;
32423 if ((rw & WRITE) &&
32424 test_bit(R5_ReWrite, &sh->dev[i].flags))
32425- atomic_add(STRIPE_SECTORS,
32426+ atomic_add_unchecked(STRIPE_SECTORS,
32427 &rdev->corrected_errors);
32428 generic_make_request(bi);
32429 } else {
32430@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struc
32431 clear_bit(R5_ReadError, &sh->dev[i].flags);
32432 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32433 }
32434- if (atomic_read(&conf->disks[i].rdev->read_errors))
32435- atomic_set(&conf->disks[i].rdev->read_errors, 0);
32436+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32437+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32438 } else {
32439 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32440 int retry = 0;
32441 rdev = conf->disks[i].rdev;
32442
32443 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32444- atomic_inc(&rdev->read_errors);
32445+ atomic_inc_unchecked(&rdev->read_errors);
32446 if (conf->mddev->degraded >= conf->max_degraded)
32447 printk_rl(KERN_WARNING
32448 "raid5:%s: read error not correctable "
32449@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struc
32450 (unsigned long long)(sh->sector
32451 + rdev->data_offset),
32452 bdn);
32453- else if (atomic_read(&rdev->read_errors)
32454+ else if (atomic_read_unchecked(&rdev->read_errors)
32455 > conf->max_nr_stripes)
32456 printk(KERN_WARNING
32457 "raid5:%s: Too many read errors, failing device %s.\n",
32458@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct s
32459 sector_t r_sector;
32460 struct stripe_head sh2;
32461
32462+ pax_track_stack();
32463
32464 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32465 stripe = new_sector;
32466diff -urNp linux-2.6.32.44/drivers/media/common/saa7146_fops.c linux-2.6.32.44/drivers/media/common/saa7146_fops.c
32467--- linux-2.6.32.44/drivers/media/common/saa7146_fops.c 2011-03-27 14:31:47.000000000 -0400
32468+++ linux-2.6.32.44/drivers/media/common/saa7146_fops.c 2011-08-05 20:33:55.000000000 -0400
32469@@ -458,7 +458,7 @@ int saa7146_vv_init(struct saa7146_dev*
32470 ERR(("out of memory. aborting.\n"));
32471 return -ENOMEM;
32472 }
32473- ext_vv->ops = saa7146_video_ioctl_ops;
32474+ memcpy((void *)&ext_vv->ops, &saa7146_video_ioctl_ops, sizeof(saa7146_video_ioctl_ops));
32475 ext_vv->core_ops = &saa7146_video_ioctl_ops;
32476
32477 DEB_EE(("dev:%p\n",dev));
32478diff -urNp linux-2.6.32.44/drivers/media/common/saa7146_hlp.c linux-2.6.32.44/drivers/media/common/saa7146_hlp.c
32479--- linux-2.6.32.44/drivers/media/common/saa7146_hlp.c 2011-03-27 14:31:47.000000000 -0400
32480+++ linux-2.6.32.44/drivers/media/common/saa7146_hlp.c 2011-05-16 21:46:57.000000000 -0400
32481@@ -353,6 +353,8 @@ static void calculate_clipping_registers
32482
32483 int x[32], y[32], w[32], h[32];
32484
32485+ pax_track_stack();
32486+
32487 /* clear out memory */
32488 memset(&line_list[0], 0x00, sizeof(u32)*32);
32489 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32490diff -urNp linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
32491--- linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-03-27 14:31:47.000000000 -0400
32492+++ linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-16 21:46:57.000000000 -0400
32493@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32494 u8 buf[HOST_LINK_BUF_SIZE];
32495 int i;
32496
32497+ pax_track_stack();
32498+
32499 dprintk("%s\n", __func__);
32500
32501 /* check if we have space for a link buf in the rx_buffer */
32502@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32503 unsigned long timeout;
32504 int written;
32505
32506+ pax_track_stack();
32507+
32508 dprintk("%s\n", __func__);
32509
32510 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32511diff -urNp linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_demux.h linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_demux.h
32512--- linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_demux.h 2011-03-27 14:31:47.000000000 -0400
32513+++ linux-2.6.32.44/drivers/media/dvb/dvb-core/dvb_demux.h 2011-08-05 20:33:55.000000000 -0400
32514@@ -71,7 +71,7 @@ struct dvb_demux_feed {
32515 union {
32516 dmx_ts_cb ts;
32517 dmx_section_cb sec;
32518- } cb;
32519+ } __no_const cb;
32520
32521 struct dvb_demux *demux;
32522 void *priv;
32523diff -urNp linux-2.6.32.44/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.32.44/drivers/media/dvb/dvb-core/dvbdev.c
32524--- linux-2.6.32.44/drivers/media/dvb/dvb-core/dvbdev.c 2011-03-27 14:31:47.000000000 -0400
32525+++ linux-2.6.32.44/drivers/media/dvb/dvb-core/dvbdev.c 2011-08-05 20:33:55.000000000 -0400
32526@@ -228,8 +228,8 @@ int dvb_register_device(struct dvb_adapt
32527 dvbdev->fops = dvbdevfops;
32528 init_waitqueue_head (&dvbdev->wait_queue);
32529
32530- memcpy(dvbdevfops, template->fops, sizeof(struct file_operations));
32531- dvbdevfops->owner = adap->module;
32532+ memcpy((void *)dvbdevfops, template->fops, sizeof(struct file_operations));
32533+ *(void **)&dvbdevfops->owner = adap->module;
32534
32535 list_add_tail (&dvbdev->list_head, &adap->device_list);
32536
32537diff -urNp linux-2.6.32.44/drivers/media/dvb/dvb-usb/cxusb.c linux-2.6.32.44/drivers/media/dvb/dvb-usb/cxusb.c
32538--- linux-2.6.32.44/drivers/media/dvb/dvb-usb/cxusb.c 2011-03-27 14:31:47.000000000 -0400
32539+++ linux-2.6.32.44/drivers/media/dvb/dvb-usb/cxusb.c 2011-08-05 20:33:55.000000000 -0400
32540@@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_di
32541 struct dib0700_adapter_state {
32542 int (*set_param_save) (struct dvb_frontend *,
32543 struct dvb_frontend_parameters *);
32544-};
32545+} __no_const;
32546
32547 static int dib7070_set_param_override(struct dvb_frontend *fe,
32548 struct dvb_frontend_parameters *fep)
32549diff -urNp linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_core.c
32550--- linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-03-27 14:31:47.000000000 -0400
32551+++ linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-16 21:46:57.000000000 -0400
32552@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb
32553
32554 u8 buf[260];
32555
32556+ pax_track_stack();
32557+
32558 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32559 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
32560
32561diff -urNp linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_devices.c linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_devices.c
32562--- linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_devices.c 2011-05-10 22:12:01.000000000 -0400
32563+++ linux-2.6.32.44/drivers/media/dvb/dvb-usb/dib0700_devices.c 2011-08-05 20:33:55.000000000 -0400
32564@@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "
32565
32566 struct dib0700_adapter_state {
32567 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
32568-};
32569+} __no_const;
32570
32571 /* Hauppauge Nova-T 500 (aka Bristol)
32572 * has a LNA on GPIO0 which is enabled by setting 1 */
32573diff -urNp linux-2.6.32.44/drivers/media/dvb/frontends/dib3000.h linux-2.6.32.44/drivers/media/dvb/frontends/dib3000.h
32574--- linux-2.6.32.44/drivers/media/dvb/frontends/dib3000.h 2011-03-27 14:31:47.000000000 -0400
32575+++ linux-2.6.32.44/drivers/media/dvb/frontends/dib3000.h 2011-08-05 20:33:55.000000000 -0400
32576@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
32577 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
32578 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
32579 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
32580-};
32581+} __no_const;
32582
32583 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
32584 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
32585diff -urNp linux-2.6.32.44/drivers/media/dvb/frontends/or51211.c linux-2.6.32.44/drivers/media/dvb/frontends/or51211.c
32586--- linux-2.6.32.44/drivers/media/dvb/frontends/or51211.c 2011-03-27 14:31:47.000000000 -0400
32587+++ linux-2.6.32.44/drivers/media/dvb/frontends/or51211.c 2011-05-16 21:46:57.000000000 -0400
32588@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32589 u8 tudata[585];
32590 int i;
32591
32592+ pax_track_stack();
32593+
32594 dprintk("Firmware is %zd bytes\n",fw->size);
32595
32596 /* Get eprom data */
32597diff -urNp linux-2.6.32.44/drivers/media/dvb/ttpci/av7110_v4l.c linux-2.6.32.44/drivers/media/dvb/ttpci/av7110_v4l.c
32598--- linux-2.6.32.44/drivers/media/dvb/ttpci/av7110_v4l.c 2011-03-27 14:31:47.000000000 -0400
32599+++ linux-2.6.32.44/drivers/media/dvb/ttpci/av7110_v4l.c 2011-08-05 20:33:55.000000000 -0400
32600@@ -796,18 +796,18 @@ int av7110_init_v4l(struct av7110 *av711
32601 ERR(("cannot init capture device. skipping.\n"));
32602 return -ENODEV;
32603 }
32604- vv_data->ops.vidioc_enum_input = vidioc_enum_input;
32605- vv_data->ops.vidioc_g_input = vidioc_g_input;
32606- vv_data->ops.vidioc_s_input = vidioc_s_input;
32607- vv_data->ops.vidioc_g_tuner = vidioc_g_tuner;
32608- vv_data->ops.vidioc_s_tuner = vidioc_s_tuner;
32609- vv_data->ops.vidioc_g_frequency = vidioc_g_frequency;
32610- vv_data->ops.vidioc_s_frequency = vidioc_s_frequency;
32611- vv_data->ops.vidioc_g_audio = vidioc_g_audio;
32612- vv_data->ops.vidioc_s_audio = vidioc_s_audio;
32613- vv_data->ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
32614- vv_data->ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
32615- vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
32616+ *(void **)&vv_data->ops.vidioc_enum_input = vidioc_enum_input;
32617+ *(void **)&vv_data->ops.vidioc_g_input = vidioc_g_input;
32618+ *(void **)&vv_data->ops.vidioc_s_input = vidioc_s_input;
32619+ *(void **)&vv_data->ops.vidioc_g_tuner = vidioc_g_tuner;
32620+ *(void **)&vv_data->ops.vidioc_s_tuner = vidioc_s_tuner;
32621+ *(void **)&vv_data->ops.vidioc_g_frequency = vidioc_g_frequency;
32622+ *(void **)&vv_data->ops.vidioc_s_frequency = vidioc_s_frequency;
32623+ *(void **)&vv_data->ops.vidioc_g_audio = vidioc_g_audio;
32624+ *(void **)&vv_data->ops.vidioc_s_audio = vidioc_s_audio;
32625+ *(void **)&vv_data->ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
32626+ *(void **)&vv_data->ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
32627+ *(void **)&vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
32628
32629 if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
32630 ERR(("cannot register capture device. skipping.\n"));
32631diff -urNp linux-2.6.32.44/drivers/media/dvb/ttpci/budget-av.c linux-2.6.32.44/drivers/media/dvb/ttpci/budget-av.c
32632--- linux-2.6.32.44/drivers/media/dvb/ttpci/budget-av.c 2011-03-27 14:31:47.000000000 -0400
32633+++ linux-2.6.32.44/drivers/media/dvb/ttpci/budget-av.c 2011-08-05 20:33:55.000000000 -0400
32634@@ -1477,9 +1477,9 @@ static int budget_av_attach(struct saa71
32635 ERR(("cannot init vv subsystem.\n"));
32636 return err;
32637 }
32638- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32639- vv_data.ops.vidioc_g_input = vidioc_g_input;
32640- vv_data.ops.vidioc_s_input = vidioc_s_input;
32641+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32642+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32643+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32644
32645 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) {
32646 /* fixme: proper cleanup here */
32647diff -urNp linux-2.6.32.44/drivers/media/radio/radio-cadet.c linux-2.6.32.44/drivers/media/radio/radio-cadet.c
32648--- linux-2.6.32.44/drivers/media/radio/radio-cadet.c 2011-03-27 14:31:47.000000000 -0400
32649+++ linux-2.6.32.44/drivers/media/radio/radio-cadet.c 2011-04-17 15:56:46.000000000 -0400
32650@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *f
32651 while (i < count && dev->rdsin != dev->rdsout)
32652 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32653
32654- if (copy_to_user(data, readbuf, i))
32655+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32656 return -EFAULT;
32657 return i;
32658 }
32659diff -urNp linux-2.6.32.44/drivers/media/video/cx18/cx18-driver.c linux-2.6.32.44/drivers/media/video/cx18/cx18-driver.c
32660--- linux-2.6.32.44/drivers/media/video/cx18/cx18-driver.c 2011-03-27 14:31:47.000000000 -0400
32661+++ linux-2.6.32.44/drivers/media/video/cx18/cx18-driver.c 2011-05-16 21:46:57.000000000 -0400
32662@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl
32663
32664 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32665
32666-static atomic_t cx18_instance = ATOMIC_INIT(0);
32667+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32668
32669 /* Parameter declarations */
32670 static int cardtype[CX18_MAX_CARDS];
32671@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32672 struct i2c_client c;
32673 u8 eedata[256];
32674
32675+ pax_track_stack();
32676+
32677 memset(&c, 0, sizeof(c));
32678 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32679 c.adapter = &cx->i2c_adap[0];
32680@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct p
32681 struct cx18 *cx;
32682
32683 /* FIXME - module parameter arrays constrain max instances */
32684- i = atomic_inc_return(&cx18_instance) - 1;
32685+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32686 if (i >= CX18_MAX_CARDS) {
32687 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32688 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32689diff -urNp linux-2.6.32.44/drivers/media/video/hexium_gemini.c linux-2.6.32.44/drivers/media/video/hexium_gemini.c
32690--- linux-2.6.32.44/drivers/media/video/hexium_gemini.c 2011-03-27 14:31:47.000000000 -0400
32691+++ linux-2.6.32.44/drivers/media/video/hexium_gemini.c 2011-08-05 20:33:55.000000000 -0400
32692@@ -394,12 +394,12 @@ static int hexium_attach(struct saa7146_
32693 hexium->cur_input = 0;
32694
32695 saa7146_vv_init(dev, &vv_data);
32696- vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32697- vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32698- vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32699- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32700- vv_data.ops.vidioc_g_input = vidioc_g_input;
32701- vv_data.ops.vidioc_s_input = vidioc_s_input;
32702+ *(void **)&vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32703+ *(void **)&vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32704+ *(void **)&vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32705+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32706+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32707+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32708 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER)) {
32709 printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n");
32710 return -1;
32711diff -urNp linux-2.6.32.44/drivers/media/video/hexium_orion.c linux-2.6.32.44/drivers/media/video/hexium_orion.c
32712--- linux-2.6.32.44/drivers/media/video/hexium_orion.c 2011-03-27 14:31:47.000000000 -0400
32713+++ linux-2.6.32.44/drivers/media/video/hexium_orion.c 2011-08-05 20:33:55.000000000 -0400
32714@@ -369,9 +369,9 @@ static int hexium_attach(struct saa7146_
32715 DEB_EE((".\n"));
32716
32717 saa7146_vv_init(dev, &vv_data);
32718- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32719- vv_data.ops.vidioc_g_input = vidioc_g_input;
32720- vv_data.ops.vidioc_s_input = vidioc_s_input;
32721+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32722+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32723+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32724 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium orion", VFL_TYPE_GRABBER)) {
32725 printk("hexium_orion: cannot register capture v4l2 device. skipping.\n");
32726 return -1;
32727diff -urNp linux-2.6.32.44/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.32.44/drivers/media/video/ivtv/ivtv-driver.c
32728--- linux-2.6.32.44/drivers/media/video/ivtv/ivtv-driver.c 2011-03-27 14:31:47.000000000 -0400
32729+++ linux-2.6.32.44/drivers/media/video/ivtv/ivtv-driver.c 2011-05-04 17:56:28.000000000 -0400
32730@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl
32731 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32732
32733 /* ivtv instance counter */
32734-static atomic_t ivtv_instance = ATOMIC_INIT(0);
32735+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32736
32737 /* Parameter declarations */
32738 static int cardtype[IVTV_MAX_CARDS];
32739diff -urNp linux-2.6.32.44/drivers/media/video/mxb.c linux-2.6.32.44/drivers/media/video/mxb.c
32740--- linux-2.6.32.44/drivers/media/video/mxb.c 2011-03-27 14:31:47.000000000 -0400
32741+++ linux-2.6.32.44/drivers/media/video/mxb.c 2011-08-05 20:33:55.000000000 -0400
32742@@ -703,23 +703,23 @@ static int mxb_attach(struct saa7146_dev
32743 already did this in "mxb_vl42_probe" */
32744
32745 saa7146_vv_init(dev, &vv_data);
32746- vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32747- vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32748- vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32749- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32750- vv_data.ops.vidioc_g_input = vidioc_g_input;
32751- vv_data.ops.vidioc_s_input = vidioc_s_input;
32752- vv_data.ops.vidioc_g_tuner = vidioc_g_tuner;
32753- vv_data.ops.vidioc_s_tuner = vidioc_s_tuner;
32754- vv_data.ops.vidioc_g_frequency = vidioc_g_frequency;
32755- vv_data.ops.vidioc_s_frequency = vidioc_s_frequency;
32756- vv_data.ops.vidioc_g_audio = vidioc_g_audio;
32757- vv_data.ops.vidioc_s_audio = vidioc_s_audio;
32758+ *(void **)&vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32759+ *(void **)&vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32760+ *(void **)&vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32761+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32762+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32763+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32764+ *(void **)&vv_data.ops.vidioc_g_tuner = vidioc_g_tuner;
32765+ *(void **)&vv_data.ops.vidioc_s_tuner = vidioc_s_tuner;
32766+ *(void **)&vv_data.ops.vidioc_g_frequency = vidioc_g_frequency;
32767+ *(void **)&vv_data.ops.vidioc_s_frequency = vidioc_s_frequency;
32768+ *(void **)&vv_data.ops.vidioc_g_audio = vidioc_g_audio;
32769+ *(void **)&vv_data.ops.vidioc_s_audio = vidioc_s_audio;
32770 #ifdef CONFIG_VIDEO_ADV_DEBUG
32771- vv_data.ops.vidioc_g_register = vidioc_g_register;
32772- vv_data.ops.vidioc_s_register = vidioc_s_register;
32773+ *(void **)&vv_data.ops.vidioc_g_register = vidioc_g_register;
32774+ *(void **)&vv_data.ops.vidioc_s_register = vidioc_s_register;
32775 #endif
32776- vv_data.ops.vidioc_default = vidioc_default;
32777+ *(void **)&vv_data.ops.vidioc_default = vidioc_default;
32778 if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
32779 ERR(("cannot register capture v4l2 device. skipping.\n"));
32780 return -1;
32781diff -urNp linux-2.6.32.44/drivers/media/video/omap24xxcam.c linux-2.6.32.44/drivers/media/video/omap24xxcam.c
32782--- linux-2.6.32.44/drivers/media/video/omap24xxcam.c 2011-03-27 14:31:47.000000000 -0400
32783+++ linux-2.6.32.44/drivers/media/video/omap24xxcam.c 2011-05-04 17:56:28.000000000 -0400
32784@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(str
32785 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32786
32787 do_gettimeofday(&vb->ts);
32788- vb->field_count = atomic_add_return(2, &fh->field_count);
32789+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32790 if (csr & csr_error) {
32791 vb->state = VIDEOBUF_ERROR;
32792 if (!atomic_read(&fh->cam->in_reset)) {
32793diff -urNp linux-2.6.32.44/drivers/media/video/omap24xxcam.h linux-2.6.32.44/drivers/media/video/omap24xxcam.h
32794--- linux-2.6.32.44/drivers/media/video/omap24xxcam.h 2011-03-27 14:31:47.000000000 -0400
32795+++ linux-2.6.32.44/drivers/media/video/omap24xxcam.h 2011-05-04 17:56:28.000000000 -0400
32796@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32797 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32798 struct videobuf_queue vbq;
32799 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32800- atomic_t field_count; /* field counter for videobuf_buffer */
32801+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32802 /* accessing cam here doesn't need serialisation: it's constant */
32803 struct omap24xxcam_device *cam;
32804 };
32805diff -urNp linux-2.6.32.44/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.32.44/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32806--- linux-2.6.32.44/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-03-27 14:31:47.000000000 -0400
32807+++ linux-2.6.32.44/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-16 21:46:57.000000000 -0400
32808@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
32809 u8 *eeprom;
32810 struct tveeprom tvdata;
32811
32812+ pax_track_stack();
32813+
32814 memset(&tvdata,0,sizeof(tvdata));
32815
32816 eeprom = pvr2_eeprom_fetch(hdw);
32817diff -urNp linux-2.6.32.44/drivers/media/video/saa7134/saa6752hs.c linux-2.6.32.44/drivers/media/video/saa7134/saa6752hs.c
32818--- linux-2.6.32.44/drivers/media/video/saa7134/saa6752hs.c 2011-03-27 14:31:47.000000000 -0400
32819+++ linux-2.6.32.44/drivers/media/video/saa7134/saa6752hs.c 2011-05-16 21:46:57.000000000 -0400
32820@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_su
32821 unsigned char localPAT[256];
32822 unsigned char localPMT[256];
32823
32824+ pax_track_stack();
32825+
32826 /* Set video format - must be done first as it resets other settings */
32827 set_reg8(client, 0x41, h->video_format);
32828
32829diff -urNp linux-2.6.32.44/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.32.44/drivers/media/video/saa7164/saa7164-cmd.c
32830--- linux-2.6.32.44/drivers/media/video/saa7164/saa7164-cmd.c 2011-03-27 14:31:47.000000000 -0400
32831+++ linux-2.6.32.44/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-16 21:46:57.000000000 -0400
32832@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_d
32833 wait_queue_head_t *q = 0;
32834 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32835
32836+ pax_track_stack();
32837+
32838 /* While any outstand message on the bus exists... */
32839 do {
32840
32841@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
32842 u8 tmp[512];
32843 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32844
32845+ pax_track_stack();
32846+
32847 while (loop) {
32848
32849 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
32850diff -urNp linux-2.6.32.44/drivers/media/video/usbvideo/ibmcam.c linux-2.6.32.44/drivers/media/video/usbvideo/ibmcam.c
32851--- linux-2.6.32.44/drivers/media/video/usbvideo/ibmcam.c 2011-03-27 14:31:47.000000000 -0400
32852+++ linux-2.6.32.44/drivers/media/video/usbvideo/ibmcam.c 2011-08-05 20:33:55.000000000 -0400
32853@@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] =
32854 static int __init ibmcam_init(void)
32855 {
32856 struct usbvideo_cb cbTbl;
32857- memset(&cbTbl, 0, sizeof(cbTbl));
32858- cbTbl.probe = ibmcam_probe;
32859- cbTbl.setupOnOpen = ibmcam_setup_on_open;
32860- cbTbl.videoStart = ibmcam_video_start;
32861- cbTbl.videoStop = ibmcam_video_stop;
32862- cbTbl.processData = ibmcam_ProcessIsocData;
32863- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32864- cbTbl.adjustPicture = ibmcam_adjust_picture;
32865- cbTbl.getFPS = ibmcam_calculate_fps;
32866+ memset((void *)&cbTbl, 0, sizeof(cbTbl));
32867+ *(void **)&cbTbl.probe = ibmcam_probe;
32868+ *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
32869+ *(void **)&cbTbl.videoStart = ibmcam_video_start;
32870+ *(void **)&cbTbl.videoStop = ibmcam_video_stop;
32871+ *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
32872+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32873+ *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
32874+ *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
32875 return usbvideo_register(
32876 &cams,
32877 MAX_IBMCAM,
32878diff -urNp linux-2.6.32.44/drivers/media/video/usbvideo/konicawc.c linux-2.6.32.44/drivers/media/video/usbvideo/konicawc.c
32879--- linux-2.6.32.44/drivers/media/video/usbvideo/konicawc.c 2011-03-27 14:31:47.000000000 -0400
32880+++ linux-2.6.32.44/drivers/media/video/usbvideo/konicawc.c 2011-08-05 20:33:55.000000000 -0400
32881@@ -225,7 +225,7 @@ static void konicawc_register_input(stru
32882 int error;
32883
32884 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
32885- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32886+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32887
32888 cam->input = input_dev = input_allocate_device();
32889 if (!input_dev) {
32890@@ -935,16 +935,16 @@ static int __init konicawc_init(void)
32891 struct usbvideo_cb cbTbl;
32892 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
32893 DRIVER_DESC "\n");
32894- memset(&cbTbl, 0, sizeof(cbTbl));
32895- cbTbl.probe = konicawc_probe;
32896- cbTbl.setupOnOpen = konicawc_setup_on_open;
32897- cbTbl.processData = konicawc_process_isoc;
32898- cbTbl.getFPS = konicawc_calculate_fps;
32899- cbTbl.setVideoMode = konicawc_set_video_mode;
32900- cbTbl.startDataPump = konicawc_start_data;
32901- cbTbl.stopDataPump = konicawc_stop_data;
32902- cbTbl.adjustPicture = konicawc_adjust_picture;
32903- cbTbl.userFree = konicawc_free_uvd;
32904+ memset((void * )&cbTbl, 0, sizeof(cbTbl));
32905+ *(void **)&cbTbl.probe = konicawc_probe;
32906+ *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
32907+ *(void **)&cbTbl.processData = konicawc_process_isoc;
32908+ *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
32909+ *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
32910+ *(void **)&cbTbl.startDataPump = konicawc_start_data;
32911+ *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
32912+ *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
32913+ *(void **)&cbTbl.userFree = konicawc_free_uvd;
32914 return usbvideo_register(
32915 &cams,
32916 MAX_CAMERAS,
32917diff -urNp linux-2.6.32.44/drivers/media/video/usbvideo/quickcam_messenger.c linux-2.6.32.44/drivers/media/video/usbvideo/quickcam_messenger.c
32918--- linux-2.6.32.44/drivers/media/video/usbvideo/quickcam_messenger.c 2011-03-27 14:31:47.000000000 -0400
32919+++ linux-2.6.32.44/drivers/media/video/usbvideo/quickcam_messenger.c 2011-04-17 15:56:46.000000000 -0400
32920@@ -89,7 +89,7 @@ static void qcm_register_input(struct qc
32921 int error;
32922
32923 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
32924- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32925+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32926
32927 cam->input = input_dev = input_allocate_device();
32928 if (!input_dev) {
32929diff -urNp linux-2.6.32.44/drivers/media/video/usbvideo/ultracam.c linux-2.6.32.44/drivers/media/video/usbvideo/ultracam.c
32930--- linux-2.6.32.44/drivers/media/video/usbvideo/ultracam.c 2011-03-27 14:31:47.000000000 -0400
32931+++ linux-2.6.32.44/drivers/media/video/usbvideo/ultracam.c 2011-08-05 20:33:55.000000000 -0400
32932@@ -655,14 +655,14 @@ static int __init ultracam_init(void)
32933 {
32934 struct usbvideo_cb cbTbl;
32935 memset(&cbTbl, 0, sizeof(cbTbl));
32936- cbTbl.probe = ultracam_probe;
32937- cbTbl.setupOnOpen = ultracam_setup_on_open;
32938- cbTbl.videoStart = ultracam_video_start;
32939- cbTbl.videoStop = ultracam_video_stop;
32940- cbTbl.processData = ultracam_ProcessIsocData;
32941- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32942- cbTbl.adjustPicture = ultracam_adjust_picture;
32943- cbTbl.getFPS = ultracam_calculate_fps;
32944+ *(void **)&cbTbl.probe = ultracam_probe;
32945+ *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
32946+ *(void **)&cbTbl.videoStart = ultracam_video_start;
32947+ *(void **)&cbTbl.videoStop = ultracam_video_stop;
32948+ *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
32949+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32950+ *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
32951+ *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
32952 return usbvideo_register(
32953 &cams,
32954 MAX_CAMERAS,
32955diff -urNp linux-2.6.32.44/drivers/media/video/usbvideo/usbvideo.c linux-2.6.32.44/drivers/media/video/usbvideo/usbvideo.c
32956--- linux-2.6.32.44/drivers/media/video/usbvideo/usbvideo.c 2011-03-27 14:31:47.000000000 -0400
32957+++ linux-2.6.32.44/drivers/media/video/usbvideo/usbvideo.c 2011-08-05 20:33:55.000000000 -0400
32958@@ -697,15 +697,15 @@ int usbvideo_register(
32959 __func__, cams, base_size, num_cams);
32960
32961 /* Copy callbacks, apply defaults for those that are not set */
32962- memmove(&cams->cb, cbTbl, sizeof(cams->cb));
32963+ memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
32964 if (cams->cb.getFrame == NULL)
32965- cams->cb.getFrame = usbvideo_GetFrame;
32966+ *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
32967 if (cams->cb.disconnect == NULL)
32968- cams->cb.disconnect = usbvideo_Disconnect;
32969+ *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
32970 if (cams->cb.startDataPump == NULL)
32971- cams->cb.startDataPump = usbvideo_StartDataPump;
32972+ *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
32973 if (cams->cb.stopDataPump == NULL)
32974- cams->cb.stopDataPump = usbvideo_StopDataPump;
32975+ *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
32976
32977 cams->num_cameras = num_cams;
32978 cams->cam = (struct uvd *) &cams[1];
32979diff -urNp linux-2.6.32.44/drivers/media/video/usbvision/usbvision-core.c linux-2.6.32.44/drivers/media/video/usbvision/usbvision-core.c
32980--- linux-2.6.32.44/drivers/media/video/usbvision/usbvision-core.c 2011-03-27 14:31:47.000000000 -0400
32981+++ linux-2.6.32.44/drivers/media/video/usbvision/usbvision-core.c 2011-05-16 21:46:57.000000000 -0400
32982@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_c
32983 unsigned char rv, gv, bv;
32984 static unsigned char *Y, *U, *V;
32985
32986+ pax_track_stack();
32987+
32988 frame = usbvision->curFrame;
32989 imageSize = frame->frmwidth * frame->frmheight;
32990 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
32991diff -urNp linux-2.6.32.44/drivers/media/video/v4l2-device.c linux-2.6.32.44/drivers/media/video/v4l2-device.c
32992--- linux-2.6.32.44/drivers/media/video/v4l2-device.c 2011-03-27 14:31:47.000000000 -0400
32993+++ linux-2.6.32.44/drivers/media/video/v4l2-device.c 2011-05-04 17:56:28.000000000 -0400
32994@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *
32995 EXPORT_SYMBOL_GPL(v4l2_device_register);
32996
32997 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
32998- atomic_t *instance)
32999+ atomic_unchecked_t *instance)
33000 {
33001- int num = atomic_inc_return(instance) - 1;
33002+ int num = atomic_inc_return_unchecked(instance) - 1;
33003 int len = strlen(basename);
33004
33005 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33006diff -urNp linux-2.6.32.44/drivers/media/video/videobuf-dma-sg.c linux-2.6.32.44/drivers/media/video/videobuf-dma-sg.c
33007--- linux-2.6.32.44/drivers/media/video/videobuf-dma-sg.c 2011-03-27 14:31:47.000000000 -0400
33008+++ linux-2.6.32.44/drivers/media/video/videobuf-dma-sg.c 2011-05-16 21:46:57.000000000 -0400
33009@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
33010 {
33011 struct videobuf_queue q;
33012
33013+ pax_track_stack();
33014+
33015 /* Required to make generic handler to call __videobuf_alloc */
33016 q.int_ops = &sg_ops;
33017
33018diff -urNp linux-2.6.32.44/drivers/message/fusion/mptbase.c linux-2.6.32.44/drivers/message/fusion/mptbase.c
33019--- linux-2.6.32.44/drivers/message/fusion/mptbase.c 2011-03-27 14:31:47.000000000 -0400
33020+++ linux-2.6.32.44/drivers/message/fusion/mptbase.c 2011-04-17 15:56:46.000000000 -0400
33021@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **s
33022 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33023 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33024
33025+#ifdef CONFIG_GRKERNSEC_HIDESYM
33026+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33027+ NULL, NULL);
33028+#else
33029 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33030 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33031+#endif
33032+
33033 /*
33034 * Rounding UP to nearest 4-kB boundary here...
33035 */
33036diff -urNp linux-2.6.32.44/drivers/message/fusion/mptsas.c linux-2.6.32.44/drivers/message/fusion/mptsas.c
33037--- linux-2.6.32.44/drivers/message/fusion/mptsas.c 2011-03-27 14:31:47.000000000 -0400
33038+++ linux-2.6.32.44/drivers/message/fusion/mptsas.c 2011-04-17 15:56:46.000000000 -0400
33039@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devin
33040 return 0;
33041 }
33042
33043+static inline void
33044+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33045+{
33046+ if (phy_info->port_details) {
33047+ phy_info->port_details->rphy = rphy;
33048+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33049+ ioc->name, rphy));
33050+ }
33051+
33052+ if (rphy) {
33053+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33054+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33055+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33056+ ioc->name, rphy, rphy->dev.release));
33057+ }
33058+}
33059+
33060 /* no mutex */
33061 static void
33062 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33063@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33064 return NULL;
33065 }
33066
33067-static inline void
33068-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33069-{
33070- if (phy_info->port_details) {
33071- phy_info->port_details->rphy = rphy;
33072- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33073- ioc->name, rphy));
33074- }
33075-
33076- if (rphy) {
33077- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33078- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33079- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33080- ioc->name, rphy, rphy->dev.release));
33081- }
33082-}
33083-
33084 static inline struct sas_port *
33085 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33086 {
33087diff -urNp linux-2.6.32.44/drivers/message/fusion/mptscsih.c linux-2.6.32.44/drivers/message/fusion/mptscsih.c
33088--- linux-2.6.32.44/drivers/message/fusion/mptscsih.c 2011-03-27 14:31:47.000000000 -0400
33089+++ linux-2.6.32.44/drivers/message/fusion/mptscsih.c 2011-04-17 15:56:46.000000000 -0400
33090@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33091
33092 h = shost_priv(SChost);
33093
33094- if (h) {
33095- if (h->info_kbuf == NULL)
33096- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33097- return h->info_kbuf;
33098- h->info_kbuf[0] = '\0';
33099+ if (!h)
33100+ return NULL;
33101
33102- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33103- h->info_kbuf[size-1] = '\0';
33104- }
33105+ if (h->info_kbuf == NULL)
33106+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33107+ return h->info_kbuf;
33108+ h->info_kbuf[0] = '\0';
33109+
33110+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33111+ h->info_kbuf[size-1] = '\0';
33112
33113 return h->info_kbuf;
33114 }
33115diff -urNp linux-2.6.32.44/drivers/message/i2o/i2o_config.c linux-2.6.32.44/drivers/message/i2o/i2o_config.c
33116--- linux-2.6.32.44/drivers/message/i2o/i2o_config.c 2011-03-27 14:31:47.000000000 -0400
33117+++ linux-2.6.32.44/drivers/message/i2o/i2o_config.c 2011-05-16 21:46:57.000000000 -0400
33118@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned lon
33119 struct i2o_message *msg;
33120 unsigned int iop;
33121
33122+ pax_track_stack();
33123+
33124 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
33125 return -EFAULT;
33126
33127diff -urNp linux-2.6.32.44/drivers/message/i2o/i2o_proc.c linux-2.6.32.44/drivers/message/i2o/i2o_proc.c
33128--- linux-2.6.32.44/drivers/message/i2o/i2o_proc.c 2011-03-27 14:31:47.000000000 -0400
33129+++ linux-2.6.32.44/drivers/message/i2o/i2o_proc.c 2011-04-17 15:56:46.000000000 -0400
33130@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
33131 "Array Controller Device"
33132 };
33133
33134-static char *chtostr(u8 * chars, int n)
33135-{
33136- char tmp[256];
33137- tmp[0] = 0;
33138- return strncat(tmp, (char *)chars, n);
33139-}
33140-
33141 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33142 char *group)
33143 {
33144@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct
33145
33146 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33147 seq_printf(seq, "%-#8x", ddm_table.module_id);
33148- seq_printf(seq, "%-29s",
33149- chtostr(ddm_table.module_name_version, 28));
33150+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33151 seq_printf(seq, "%9d ", ddm_table.data_size);
33152 seq_printf(seq, "%8d", ddm_table.code_size);
33153
33154@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(s
33155
33156 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33157 seq_printf(seq, "%-#8x", dst->module_id);
33158- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33159- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33160+ seq_printf(seq, "%-.28s", dst->module_name_version);
33161+ seq_printf(seq, "%-.8s", dst->date);
33162 seq_printf(seq, "%8d ", dst->module_size);
33163 seq_printf(seq, "%8d ", dst->mpb_size);
33164 seq_printf(seq, "0x%04x", dst->module_flags);
33165@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(str
33166 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33167 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33168 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33169- seq_printf(seq, "Vendor info : %s\n",
33170- chtostr((u8 *) (work32 + 2), 16));
33171- seq_printf(seq, "Product info : %s\n",
33172- chtostr((u8 *) (work32 + 6), 16));
33173- seq_printf(seq, "Description : %s\n",
33174- chtostr((u8 *) (work32 + 10), 16));
33175- seq_printf(seq, "Product rev. : %s\n",
33176- chtostr((u8 *) (work32 + 14), 8));
33177+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33178+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33179+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33180+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33181
33182 seq_printf(seq, "Serial number : ");
33183 print_serial_number(seq, (u8 *) (work32 + 16),
33184@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(str
33185 }
33186
33187 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33188- seq_printf(seq, "Module name : %s\n",
33189- chtostr(result.module_name, 24));
33190- seq_printf(seq, "Module revision : %s\n",
33191- chtostr(result.module_rev, 8));
33192+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33193+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33194
33195 seq_printf(seq, "Serial number : ");
33196 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33197@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq
33198 return 0;
33199 }
33200
33201- seq_printf(seq, "Device name : %s\n",
33202- chtostr(result.device_name, 64));
33203- seq_printf(seq, "Service name : %s\n",
33204- chtostr(result.service_name, 64));
33205- seq_printf(seq, "Physical name : %s\n",
33206- chtostr(result.physical_location, 64));
33207- seq_printf(seq, "Instance number : %s\n",
33208- chtostr(result.instance_number, 4));
33209+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
33210+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
33211+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33212+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33213
33214 return 0;
33215 }
33216diff -urNp linux-2.6.32.44/drivers/message/i2o/iop.c linux-2.6.32.44/drivers/message/i2o/iop.c
33217--- linux-2.6.32.44/drivers/message/i2o/iop.c 2011-03-27 14:31:47.000000000 -0400
33218+++ linux-2.6.32.44/drivers/message/i2o/iop.c 2011-05-04 17:56:28.000000000 -0400
33219@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
33220
33221 spin_lock_irqsave(&c->context_list_lock, flags);
33222
33223- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33224- atomic_inc(&c->context_list_counter);
33225+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33226+ atomic_inc_unchecked(&c->context_list_counter);
33227
33228- entry->context = atomic_read(&c->context_list_counter);
33229+ entry->context = atomic_read_unchecked(&c->context_list_counter);
33230
33231 list_add(&entry->list, &c->context_list);
33232
33233@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(voi
33234
33235 #if BITS_PER_LONG == 64
33236 spin_lock_init(&c->context_list_lock);
33237- atomic_set(&c->context_list_counter, 0);
33238+ atomic_set_unchecked(&c->context_list_counter, 0);
33239 INIT_LIST_HEAD(&c->context_list);
33240 #endif
33241
33242diff -urNp linux-2.6.32.44/drivers/mfd/wm8350-i2c.c linux-2.6.32.44/drivers/mfd/wm8350-i2c.c
33243--- linux-2.6.32.44/drivers/mfd/wm8350-i2c.c 2011-03-27 14:31:47.000000000 -0400
33244+++ linux-2.6.32.44/drivers/mfd/wm8350-i2c.c 2011-05-16 21:46:57.000000000 -0400
33245@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struc
33246 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
33247 int ret;
33248
33249+ pax_track_stack();
33250+
33251 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
33252 return -EINVAL;
33253
33254diff -urNp linux-2.6.32.44/drivers/misc/kgdbts.c linux-2.6.32.44/drivers/misc/kgdbts.c
33255--- linux-2.6.32.44/drivers/misc/kgdbts.c 2011-03-27 14:31:47.000000000 -0400
33256+++ linux-2.6.32.44/drivers/misc/kgdbts.c 2011-04-17 15:56:46.000000000 -0400
33257@@ -118,7 +118,7 @@
33258 } while (0)
33259 #define MAX_CONFIG_LEN 40
33260
33261-static struct kgdb_io kgdbts_io_ops;
33262+static const struct kgdb_io kgdbts_io_ops;
33263 static char get_buf[BUFMAX];
33264 static int get_buf_cnt;
33265 static char put_buf[BUFMAX];
33266@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void
33267 module_put(THIS_MODULE);
33268 }
33269
33270-static struct kgdb_io kgdbts_io_ops = {
33271+static const struct kgdb_io kgdbts_io_ops = {
33272 .name = "kgdbts",
33273 .read_char = kgdbts_get_char,
33274 .write_char = kgdbts_put_char,
33275diff -urNp linux-2.6.32.44/drivers/misc/sgi-gru/gruhandles.c linux-2.6.32.44/drivers/misc/sgi-gru/gruhandles.c
33276--- linux-2.6.32.44/drivers/misc/sgi-gru/gruhandles.c 2011-03-27 14:31:47.000000000 -0400
33277+++ linux-2.6.32.44/drivers/misc/sgi-gru/gruhandles.c 2011-04-17 15:56:46.000000000 -0400
33278@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistic
33279
33280 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
33281 {
33282- atomic_long_inc(&mcs_op_statistics[op].count);
33283- atomic_long_add(clks, &mcs_op_statistics[op].total);
33284+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33285+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
33286 if (mcs_op_statistics[op].max < clks)
33287 mcs_op_statistics[op].max = clks;
33288 }
33289diff -urNp linux-2.6.32.44/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.32.44/drivers/misc/sgi-gru/gruprocfs.c
33290--- linux-2.6.32.44/drivers/misc/sgi-gru/gruprocfs.c 2011-03-27 14:31:47.000000000 -0400
33291+++ linux-2.6.32.44/drivers/misc/sgi-gru/gruprocfs.c 2011-04-17 15:56:46.000000000 -0400
33292@@ -32,9 +32,9 @@
33293
33294 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33295
33296-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33297+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33298 {
33299- unsigned long val = atomic_long_read(v);
33300+ unsigned long val = atomic_long_read_unchecked(v);
33301
33302 if (val)
33303 seq_printf(s, "%16lu %s\n", val, id);
33304@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct se
33305 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
33306
33307 for (op = 0; op < mcsop_last; op++) {
33308- count = atomic_long_read(&mcs_op_statistics[op].count);
33309- total = atomic_long_read(&mcs_op_statistics[op].total);
33310+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33311+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33312 max = mcs_op_statistics[op].max;
33313 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33314 count ? total / count : 0, max);
33315diff -urNp linux-2.6.32.44/drivers/misc/sgi-gru/grutables.h linux-2.6.32.44/drivers/misc/sgi-gru/grutables.h
33316--- linux-2.6.32.44/drivers/misc/sgi-gru/grutables.h 2011-03-27 14:31:47.000000000 -0400
33317+++ linux-2.6.32.44/drivers/misc/sgi-gru/grutables.h 2011-04-17 15:56:46.000000000 -0400
33318@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
33319 * GRU statistics.
33320 */
33321 struct gru_stats_s {
33322- atomic_long_t vdata_alloc;
33323- atomic_long_t vdata_free;
33324- atomic_long_t gts_alloc;
33325- atomic_long_t gts_free;
33326- atomic_long_t vdata_double_alloc;
33327- atomic_long_t gts_double_allocate;
33328- atomic_long_t assign_context;
33329- atomic_long_t assign_context_failed;
33330- atomic_long_t free_context;
33331- atomic_long_t load_user_context;
33332- atomic_long_t load_kernel_context;
33333- atomic_long_t lock_kernel_context;
33334- atomic_long_t unlock_kernel_context;
33335- atomic_long_t steal_user_context;
33336- atomic_long_t steal_kernel_context;
33337- atomic_long_t steal_context_failed;
33338- atomic_long_t nopfn;
33339- atomic_long_t break_cow;
33340- atomic_long_t asid_new;
33341- atomic_long_t asid_next;
33342- atomic_long_t asid_wrap;
33343- atomic_long_t asid_reuse;
33344- atomic_long_t intr;
33345- atomic_long_t intr_mm_lock_failed;
33346- atomic_long_t call_os;
33347- atomic_long_t call_os_offnode_reference;
33348- atomic_long_t call_os_check_for_bug;
33349- atomic_long_t call_os_wait_queue;
33350- atomic_long_t user_flush_tlb;
33351- atomic_long_t user_unload_context;
33352- atomic_long_t user_exception;
33353- atomic_long_t set_context_option;
33354- atomic_long_t migrate_check;
33355- atomic_long_t migrated_retarget;
33356- atomic_long_t migrated_unload;
33357- atomic_long_t migrated_unload_delay;
33358- atomic_long_t migrated_nopfn_retarget;
33359- atomic_long_t migrated_nopfn_unload;
33360- atomic_long_t tlb_dropin;
33361- atomic_long_t tlb_dropin_fail_no_asid;
33362- atomic_long_t tlb_dropin_fail_upm;
33363- atomic_long_t tlb_dropin_fail_invalid;
33364- atomic_long_t tlb_dropin_fail_range_active;
33365- atomic_long_t tlb_dropin_fail_idle;
33366- atomic_long_t tlb_dropin_fail_fmm;
33367- atomic_long_t tlb_dropin_fail_no_exception;
33368- atomic_long_t tlb_dropin_fail_no_exception_war;
33369- atomic_long_t tfh_stale_on_fault;
33370- atomic_long_t mmu_invalidate_range;
33371- atomic_long_t mmu_invalidate_page;
33372- atomic_long_t mmu_clear_flush_young;
33373- atomic_long_t flush_tlb;
33374- atomic_long_t flush_tlb_gru;
33375- atomic_long_t flush_tlb_gru_tgh;
33376- atomic_long_t flush_tlb_gru_zero_asid;
33377-
33378- atomic_long_t copy_gpa;
33379-
33380- atomic_long_t mesq_receive;
33381- atomic_long_t mesq_receive_none;
33382- atomic_long_t mesq_send;
33383- atomic_long_t mesq_send_failed;
33384- atomic_long_t mesq_noop;
33385- atomic_long_t mesq_send_unexpected_error;
33386- atomic_long_t mesq_send_lb_overflow;
33387- atomic_long_t mesq_send_qlimit_reached;
33388- atomic_long_t mesq_send_amo_nacked;
33389- atomic_long_t mesq_send_put_nacked;
33390- atomic_long_t mesq_qf_not_full;
33391- atomic_long_t mesq_qf_locked;
33392- atomic_long_t mesq_qf_noop_not_full;
33393- atomic_long_t mesq_qf_switch_head_failed;
33394- atomic_long_t mesq_qf_unexpected_error;
33395- atomic_long_t mesq_noop_unexpected_error;
33396- atomic_long_t mesq_noop_lb_overflow;
33397- atomic_long_t mesq_noop_qlimit_reached;
33398- atomic_long_t mesq_noop_amo_nacked;
33399- atomic_long_t mesq_noop_put_nacked;
33400+ atomic_long_unchecked_t vdata_alloc;
33401+ atomic_long_unchecked_t vdata_free;
33402+ atomic_long_unchecked_t gts_alloc;
33403+ atomic_long_unchecked_t gts_free;
33404+ atomic_long_unchecked_t vdata_double_alloc;
33405+ atomic_long_unchecked_t gts_double_allocate;
33406+ atomic_long_unchecked_t assign_context;
33407+ atomic_long_unchecked_t assign_context_failed;
33408+ atomic_long_unchecked_t free_context;
33409+ atomic_long_unchecked_t load_user_context;
33410+ atomic_long_unchecked_t load_kernel_context;
33411+ atomic_long_unchecked_t lock_kernel_context;
33412+ atomic_long_unchecked_t unlock_kernel_context;
33413+ atomic_long_unchecked_t steal_user_context;
33414+ atomic_long_unchecked_t steal_kernel_context;
33415+ atomic_long_unchecked_t steal_context_failed;
33416+ atomic_long_unchecked_t nopfn;
33417+ atomic_long_unchecked_t break_cow;
33418+ atomic_long_unchecked_t asid_new;
33419+ atomic_long_unchecked_t asid_next;
33420+ atomic_long_unchecked_t asid_wrap;
33421+ atomic_long_unchecked_t asid_reuse;
33422+ atomic_long_unchecked_t intr;
33423+ atomic_long_unchecked_t intr_mm_lock_failed;
33424+ atomic_long_unchecked_t call_os;
33425+ atomic_long_unchecked_t call_os_offnode_reference;
33426+ atomic_long_unchecked_t call_os_check_for_bug;
33427+ atomic_long_unchecked_t call_os_wait_queue;
33428+ atomic_long_unchecked_t user_flush_tlb;
33429+ atomic_long_unchecked_t user_unload_context;
33430+ atomic_long_unchecked_t user_exception;
33431+ atomic_long_unchecked_t set_context_option;
33432+ atomic_long_unchecked_t migrate_check;
33433+ atomic_long_unchecked_t migrated_retarget;
33434+ atomic_long_unchecked_t migrated_unload;
33435+ atomic_long_unchecked_t migrated_unload_delay;
33436+ atomic_long_unchecked_t migrated_nopfn_retarget;
33437+ atomic_long_unchecked_t migrated_nopfn_unload;
33438+ atomic_long_unchecked_t tlb_dropin;
33439+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33440+ atomic_long_unchecked_t tlb_dropin_fail_upm;
33441+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
33442+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
33443+ atomic_long_unchecked_t tlb_dropin_fail_idle;
33444+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
33445+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33446+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
33447+ atomic_long_unchecked_t tfh_stale_on_fault;
33448+ atomic_long_unchecked_t mmu_invalidate_range;
33449+ atomic_long_unchecked_t mmu_invalidate_page;
33450+ atomic_long_unchecked_t mmu_clear_flush_young;
33451+ atomic_long_unchecked_t flush_tlb;
33452+ atomic_long_unchecked_t flush_tlb_gru;
33453+ atomic_long_unchecked_t flush_tlb_gru_tgh;
33454+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33455+
33456+ atomic_long_unchecked_t copy_gpa;
33457+
33458+ atomic_long_unchecked_t mesq_receive;
33459+ atomic_long_unchecked_t mesq_receive_none;
33460+ atomic_long_unchecked_t mesq_send;
33461+ atomic_long_unchecked_t mesq_send_failed;
33462+ atomic_long_unchecked_t mesq_noop;
33463+ atomic_long_unchecked_t mesq_send_unexpected_error;
33464+ atomic_long_unchecked_t mesq_send_lb_overflow;
33465+ atomic_long_unchecked_t mesq_send_qlimit_reached;
33466+ atomic_long_unchecked_t mesq_send_amo_nacked;
33467+ atomic_long_unchecked_t mesq_send_put_nacked;
33468+ atomic_long_unchecked_t mesq_qf_not_full;
33469+ atomic_long_unchecked_t mesq_qf_locked;
33470+ atomic_long_unchecked_t mesq_qf_noop_not_full;
33471+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
33472+ atomic_long_unchecked_t mesq_qf_unexpected_error;
33473+ atomic_long_unchecked_t mesq_noop_unexpected_error;
33474+ atomic_long_unchecked_t mesq_noop_lb_overflow;
33475+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
33476+ atomic_long_unchecked_t mesq_noop_amo_nacked;
33477+ atomic_long_unchecked_t mesq_noop_put_nacked;
33478
33479 };
33480
33481@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start
33482 cchop_deallocate, tghop_invalidate, mcsop_last};
33483
33484 struct mcs_op_statistic {
33485- atomic_long_t count;
33486- atomic_long_t total;
33487+ atomic_long_unchecked_t count;
33488+ atomic_long_unchecked_t total;
33489 unsigned long max;
33490 };
33491
33492@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_st
33493
33494 #define STAT(id) do { \
33495 if (gru_options & OPT_STATS) \
33496- atomic_long_inc(&gru_stats.id); \
33497+ atomic_long_inc_unchecked(&gru_stats.id); \
33498 } while (0)
33499
33500 #ifdef CONFIG_SGI_GRU_DEBUG
33501diff -urNp linux-2.6.32.44/drivers/misc/sgi-xp/xpc.h linux-2.6.32.44/drivers/misc/sgi-xp/xpc.h
33502--- linux-2.6.32.44/drivers/misc/sgi-xp/xpc.h 2011-03-27 14:31:47.000000000 -0400
33503+++ linux-2.6.32.44/drivers/misc/sgi-xp/xpc.h 2011-08-05 20:33:55.000000000 -0400
33504@@ -876,7 +876,7 @@ extern struct xpc_registration xpc_regis
33505 /* found in xpc_main.c */
33506 extern struct device *xpc_part;
33507 extern struct device *xpc_chan;
33508-extern struct xpc_arch_operations xpc_arch_ops;
33509+extern const struct xpc_arch_operations xpc_arch_ops;
33510 extern int xpc_disengage_timelimit;
33511 extern int xpc_disengage_timedout;
33512 extern int xpc_activate_IRQ_rcvd;
33513diff -urNp linux-2.6.32.44/drivers/misc/sgi-xp/xpc_main.c linux-2.6.32.44/drivers/misc/sgi-xp/xpc_main.c
33514--- linux-2.6.32.44/drivers/misc/sgi-xp/xpc_main.c 2011-03-27 14:31:47.000000000 -0400
33515+++ linux-2.6.32.44/drivers/misc/sgi-xp/xpc_main.c 2011-08-05 20:33:55.000000000 -0400
33516@@ -169,7 +169,7 @@ static struct notifier_block xpc_die_not
33517 .notifier_call = xpc_system_die,
33518 };
33519
33520-struct xpc_arch_operations xpc_arch_ops;
33521+const struct xpc_arch_operations xpc_arch_ops;
33522
33523 /*
33524 * Timer function to enforce the timelimit on the partition disengage.
33525diff -urNp linux-2.6.32.44/drivers/misc/sgi-xp/xpc_sn2.c linux-2.6.32.44/drivers/misc/sgi-xp/xpc_sn2.c
33526--- linux-2.6.32.44/drivers/misc/sgi-xp/xpc_sn2.c 2011-03-27 14:31:47.000000000 -0400
33527+++ linux-2.6.32.44/drivers/misc/sgi-xp/xpc_sn2.c 2011-08-05 20:33:55.000000000 -0400
33528@@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_chan
33529 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33530 }
33531
33532-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33533+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33534 .setup_partitions = xpc_setup_partitions_sn2,
33535 .teardown_partitions = xpc_teardown_partitions_sn2,
33536 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33537@@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
33538 int ret;
33539 size_t buf_size;
33540
33541- xpc_arch_ops = xpc_arch_ops_sn2;
33542+ pax_open_kernel();
33543+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
33544+ pax_close_kernel();
33545
33546 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
33547 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
33548diff -urNp linux-2.6.32.44/drivers/misc/sgi-xp/xpc_uv.c linux-2.6.32.44/drivers/misc/sgi-xp/xpc_uv.c
33549--- linux-2.6.32.44/drivers/misc/sgi-xp/xpc_uv.c 2011-03-27 14:31:47.000000000 -0400
33550+++ linux-2.6.32.44/drivers/misc/sgi-xp/xpc_uv.c 2011-08-05 20:33:55.000000000 -0400
33551@@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_chann
33552 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33553 }
33554
33555-static struct xpc_arch_operations xpc_arch_ops_uv = {
33556+static const struct xpc_arch_operations xpc_arch_ops_uv = {
33557 .setup_partitions = xpc_setup_partitions_uv,
33558 .teardown_partitions = xpc_teardown_partitions_uv,
33559 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33560@@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_ar
33561 int
33562 xpc_init_uv(void)
33563 {
33564- xpc_arch_ops = xpc_arch_ops_uv;
33565+ pax_open_kernel();
33566+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
33567+ pax_close_kernel();
33568
33569 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
33570 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
33571diff -urNp linux-2.6.32.44/drivers/misc/sgi-xp/xp.h linux-2.6.32.44/drivers/misc/sgi-xp/xp.h
33572--- linux-2.6.32.44/drivers/misc/sgi-xp/xp.h 2011-03-27 14:31:47.000000000 -0400
33573+++ linux-2.6.32.44/drivers/misc/sgi-xp/xp.h 2011-08-05 20:33:55.000000000 -0400
33574@@ -289,7 +289,7 @@ struct xpc_interface {
33575 xpc_notify_func, void *);
33576 void (*received) (short, int, void *);
33577 enum xp_retval (*partid_to_nasids) (short, void *);
33578-};
33579+} __no_const;
33580
33581 extern struct xpc_interface xpc_interface;
33582
33583diff -urNp linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0001.c
33584--- linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0001.c 2011-03-27 14:31:47.000000000 -0400
33585+++ linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-16 21:46:57.000000000 -0400
33586@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *
33587 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
33588 unsigned long timeo = jiffies + HZ;
33589
33590+ pax_track_stack();
33591+
33592 /* Prevent setting state FL_SYNCING for chip in suspended state. */
33593 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
33594 goto sleep;
33595@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(stru
33596 unsigned long initial_adr;
33597 int initial_len = len;
33598
33599+ pax_track_stack();
33600+
33601 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
33602 adr += chip->start;
33603 initial_adr = adr;
33604@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(st
33605 int retries = 3;
33606 int ret;
33607
33608+ pax_track_stack();
33609+
33610 adr += chip->start;
33611
33612 retry:
33613diff -urNp linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0020.c
33614--- linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0020.c 2011-03-27 14:31:47.000000000 -0400
33615+++ linux-2.6.32.44/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-16 21:46:57.000000000 -0400
33616@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
33617 unsigned long cmd_addr;
33618 struct cfi_private *cfi = map->fldrv_priv;
33619
33620+ pax_track_stack();
33621+
33622 adr += chip->start;
33623
33624 /* Ensure cmd read/writes are aligned. */
33625@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
33626 DECLARE_WAITQUEUE(wait, current);
33627 int wbufsize, z;
33628
33629+ pax_track_stack();
33630+
33631 /* M58LW064A requires bus alignment for buffer wriets -- saw */
33632 if (adr & (map_bankwidth(map)-1))
33633 return -EINVAL;
33634@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
33635 DECLARE_WAITQUEUE(wait, current);
33636 int ret = 0;
33637
33638+ pax_track_stack();
33639+
33640 adr += chip->start;
33641
33642 /* Let's determine this according to the interleave only once */
33643@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
33644 unsigned long timeo = jiffies + HZ;
33645 DECLARE_WAITQUEUE(wait, current);
33646
33647+ pax_track_stack();
33648+
33649 adr += chip->start;
33650
33651 /* Let's determine this according to the interleave only once */
33652@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
33653 unsigned long timeo = jiffies + HZ;
33654 DECLARE_WAITQUEUE(wait, current);
33655
33656+ pax_track_stack();
33657+
33658 adr += chip->start;
33659
33660 /* Let's determine this according to the interleave only once */
33661diff -urNp linux-2.6.32.44/drivers/mtd/devices/doc2000.c linux-2.6.32.44/drivers/mtd/devices/doc2000.c
33662--- linux-2.6.32.44/drivers/mtd/devices/doc2000.c 2011-03-27 14:31:47.000000000 -0400
33663+++ linux-2.6.32.44/drivers/mtd/devices/doc2000.c 2011-04-17 15:56:46.000000000 -0400
33664@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
33665
33666 /* The ECC will not be calculated correctly if less than 512 is written */
33667 /* DBB-
33668- if (len != 0x200 && eccbuf)
33669+ if (len != 0x200)
33670 printk(KERN_WARNING
33671 "ECC needs a full sector write (adr: %lx size %lx)\n",
33672 (long) to, (long) len);
33673diff -urNp linux-2.6.32.44/drivers/mtd/devices/doc2001.c linux-2.6.32.44/drivers/mtd/devices/doc2001.c
33674--- linux-2.6.32.44/drivers/mtd/devices/doc2001.c 2011-03-27 14:31:47.000000000 -0400
33675+++ linux-2.6.32.44/drivers/mtd/devices/doc2001.c 2011-04-17 15:56:46.000000000 -0400
33676@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
33677 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
33678
33679 /* Don't allow read past end of device */
33680- if (from >= this->totlen)
33681+ if (from >= this->totlen || !len)
33682 return -EINVAL;
33683
33684 /* Don't allow a single read to cross a 512-byte block boundary */
33685diff -urNp linux-2.6.32.44/drivers/mtd/ftl.c linux-2.6.32.44/drivers/mtd/ftl.c
33686--- linux-2.6.32.44/drivers/mtd/ftl.c 2011-03-27 14:31:47.000000000 -0400
33687+++ linux-2.6.32.44/drivers/mtd/ftl.c 2011-05-16 21:46:57.000000000 -0400
33688@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
33689 loff_t offset;
33690 uint16_t srcunitswap = cpu_to_le16(srcunit);
33691
33692+ pax_track_stack();
33693+
33694 eun = &part->EUNInfo[srcunit];
33695 xfer = &part->XferInfo[xferunit];
33696 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
33697diff -urNp linux-2.6.32.44/drivers/mtd/inftlcore.c linux-2.6.32.44/drivers/mtd/inftlcore.c
33698--- linux-2.6.32.44/drivers/mtd/inftlcore.c 2011-03-27 14:31:47.000000000 -0400
33699+++ linux-2.6.32.44/drivers/mtd/inftlcore.c 2011-05-16 21:46:57.000000000 -0400
33700@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLr
33701 struct inftl_oob oob;
33702 size_t retlen;
33703
33704+ pax_track_stack();
33705+
33706 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
33707 "pending=%d)\n", inftl, thisVUC, pendingblock);
33708
33709diff -urNp linux-2.6.32.44/drivers/mtd/inftlmount.c linux-2.6.32.44/drivers/mtd/inftlmount.c
33710--- linux-2.6.32.44/drivers/mtd/inftlmount.c 2011-03-27 14:31:47.000000000 -0400
33711+++ linux-2.6.32.44/drivers/mtd/inftlmount.c 2011-05-16 21:46:57.000000000 -0400
33712@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTL
33713 struct INFTLPartition *ip;
33714 size_t retlen;
33715
33716+ pax_track_stack();
33717+
33718 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
33719
33720 /*
33721diff -urNp linux-2.6.32.44/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.32.44/drivers/mtd/lpddr/qinfo_probe.c
33722--- linux-2.6.32.44/drivers/mtd/lpddr/qinfo_probe.c 2011-03-27 14:31:47.000000000 -0400
33723+++ linux-2.6.32.44/drivers/mtd/lpddr/qinfo_probe.c 2011-05-16 21:46:57.000000000 -0400
33724@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
33725 {
33726 map_word pfow_val[4];
33727
33728+ pax_track_stack();
33729+
33730 /* Check identification string */
33731 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
33732 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
33733diff -urNp linux-2.6.32.44/drivers/mtd/mtdchar.c linux-2.6.32.44/drivers/mtd/mtdchar.c
33734--- linux-2.6.32.44/drivers/mtd/mtdchar.c 2011-03-27 14:31:47.000000000 -0400
33735+++ linux-2.6.32.44/drivers/mtd/mtdchar.c 2011-05-16 21:46:57.000000000 -0400
33736@@ -460,6 +460,8 @@ static int mtd_ioctl(struct inode *inode
33737 u_long size;
33738 struct mtd_info_user info;
33739
33740+ pax_track_stack();
33741+
33742 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
33743
33744 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
33745diff -urNp linux-2.6.32.44/drivers/mtd/nftlcore.c linux-2.6.32.44/drivers/mtd/nftlcore.c
33746--- linux-2.6.32.44/drivers/mtd/nftlcore.c 2011-03-27 14:31:47.000000000 -0400
33747+++ linux-2.6.32.44/drivers/mtd/nftlcore.c 2011-05-16 21:46:57.000000000 -0400
33748@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLre
33749 int inplace = 1;
33750 size_t retlen;
33751
33752+ pax_track_stack();
33753+
33754 memset(BlockMap, 0xff, sizeof(BlockMap));
33755 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
33756
33757diff -urNp linux-2.6.32.44/drivers/mtd/nftlmount.c linux-2.6.32.44/drivers/mtd/nftlmount.c
33758--- linux-2.6.32.44/drivers/mtd/nftlmount.c 2011-03-27 14:31:47.000000000 -0400
33759+++ linux-2.6.32.44/drivers/mtd/nftlmount.c 2011-05-18 20:09:37.000000000 -0400
33760@@ -23,6 +23,7 @@
33761 #include <asm/errno.h>
33762 #include <linux/delay.h>
33763 #include <linux/slab.h>
33764+#include <linux/sched.h>
33765 #include <linux/mtd/mtd.h>
33766 #include <linux/mtd/nand.h>
33767 #include <linux/mtd/nftl.h>
33768@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLr
33769 struct mtd_info *mtd = nftl->mbd.mtd;
33770 unsigned int i;
33771
33772+ pax_track_stack();
33773+
33774 /* Assume logical EraseSize == physical erasesize for starting the scan.
33775 We'll sort it out later if we find a MediaHeader which says otherwise */
33776 /* Actually, we won't. The new DiskOnChip driver has already scanned
33777diff -urNp linux-2.6.32.44/drivers/mtd/ubi/build.c linux-2.6.32.44/drivers/mtd/ubi/build.c
33778--- linux-2.6.32.44/drivers/mtd/ubi/build.c 2011-03-27 14:31:47.000000000 -0400
33779+++ linux-2.6.32.44/drivers/mtd/ubi/build.c 2011-04-17 15:56:46.000000000 -0400
33780@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
33781 static int __init bytes_str_to_int(const char *str)
33782 {
33783 char *endp;
33784- unsigned long result;
33785+ unsigned long result, scale = 1;
33786
33787 result = simple_strtoul(str, &endp, 0);
33788 if (str == endp || result >= INT_MAX) {
33789@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const
33790
33791 switch (*endp) {
33792 case 'G':
33793- result *= 1024;
33794+ scale *= 1024;
33795 case 'M':
33796- result *= 1024;
33797+ scale *= 1024;
33798 case 'K':
33799- result *= 1024;
33800+ scale *= 1024;
33801 if (endp[1] == 'i' && endp[2] == 'B')
33802 endp += 2;
33803 case '\0':
33804@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const
33805 return -EINVAL;
33806 }
33807
33808- return result;
33809+ if ((intoverflow_t)result*scale >= INT_MAX) {
33810+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33811+ str);
33812+ return -EINVAL;
33813+ }
33814+
33815+ return result*scale;
33816 }
33817
33818 /**
33819diff -urNp linux-2.6.32.44/drivers/net/bnx2.c linux-2.6.32.44/drivers/net/bnx2.c
33820--- linux-2.6.32.44/drivers/net/bnx2.c 2011-03-27 14:31:47.000000000 -0400
33821+++ linux-2.6.32.44/drivers/net/bnx2.c 2011-05-16 21:46:57.000000000 -0400
33822@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
33823 int rc = 0;
33824 u32 magic, csum;
33825
33826+ pax_track_stack();
33827+
33828 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
33829 goto test_nvram_done;
33830
33831diff -urNp linux-2.6.32.44/drivers/net/cxgb3/l2t.h linux-2.6.32.44/drivers/net/cxgb3/l2t.h
33832--- linux-2.6.32.44/drivers/net/cxgb3/l2t.h 2011-03-27 14:31:47.000000000 -0400
33833+++ linux-2.6.32.44/drivers/net/cxgb3/l2t.h 2011-08-05 20:33:55.000000000 -0400
33834@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)
33835 */
33836 struct l2t_skb_cb {
33837 arp_failure_handler_func arp_failure_handler;
33838-};
33839+} __no_const;
33840
33841 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33842
33843diff -urNp linux-2.6.32.44/drivers/net/cxgb3/t3_hw.c linux-2.6.32.44/drivers/net/cxgb3/t3_hw.c
33844--- linux-2.6.32.44/drivers/net/cxgb3/t3_hw.c 2011-03-27 14:31:47.000000000 -0400
33845+++ linux-2.6.32.44/drivers/net/cxgb3/t3_hw.c 2011-05-16 21:46:57.000000000 -0400
33846@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter
33847 int i, addr, ret;
33848 struct t3_vpd vpd;
33849
33850+ pax_track_stack();
33851+
33852 /*
33853 * Card information is normally at VPD_BASE but some early cards had
33854 * it at 0.
33855diff -urNp linux-2.6.32.44/drivers/net/e1000e/82571.c linux-2.6.32.44/drivers/net/e1000e/82571.c
33856--- linux-2.6.32.44/drivers/net/e1000e/82571.c 2011-03-27 14:31:47.000000000 -0400
33857+++ linux-2.6.32.44/drivers/net/e1000e/82571.c 2011-08-05 20:33:55.000000000 -0400
33858@@ -245,22 +245,22 @@ static s32 e1000_init_mac_params_82571(s
33859 /* check for link */
33860 switch (hw->phy.media_type) {
33861 case e1000_media_type_copper:
33862- func->setup_physical_interface = e1000_setup_copper_link_82571;
33863- func->check_for_link = e1000e_check_for_copper_link;
33864- func->get_link_up_info = e1000e_get_speed_and_duplex_copper;
33865+ *(void **)&func->setup_physical_interface = e1000_setup_copper_link_82571;
33866+ *(void **)&func->check_for_link = e1000e_check_for_copper_link;
33867+ *(void **)&func->get_link_up_info = e1000e_get_speed_and_duplex_copper;
33868 break;
33869 case e1000_media_type_fiber:
33870- func->setup_physical_interface =
33871+ *(void **)&func->setup_physical_interface =
33872 e1000_setup_fiber_serdes_link_82571;
33873- func->check_for_link = e1000e_check_for_fiber_link;
33874- func->get_link_up_info =
33875+ *(void **)&func->check_for_link = e1000e_check_for_fiber_link;
33876+ *(void **)&func->get_link_up_info =
33877 e1000e_get_speed_and_duplex_fiber_serdes;
33878 break;
33879 case e1000_media_type_internal_serdes:
33880- func->setup_physical_interface =
33881+ *(void **)&func->setup_physical_interface =
33882 e1000_setup_fiber_serdes_link_82571;
33883- func->check_for_link = e1000_check_for_serdes_link_82571;
33884- func->get_link_up_info =
33885+ *(void **)&func->check_for_link = e1000_check_for_serdes_link_82571;
33886+ *(void **)&func->get_link_up_info =
33887 e1000e_get_speed_and_duplex_fiber_serdes;
33888 break;
33889 default:
33890@@ -271,12 +271,12 @@ static s32 e1000_init_mac_params_82571(s
33891 switch (hw->mac.type) {
33892 case e1000_82574:
33893 case e1000_82583:
33894- func->check_mng_mode = e1000_check_mng_mode_82574;
33895- func->led_on = e1000_led_on_82574;
33896+ *(void **)&func->check_mng_mode = e1000_check_mng_mode_82574;
33897+ *(void **)&func->led_on = e1000_led_on_82574;
33898 break;
33899 default:
33900- func->check_mng_mode = e1000e_check_mng_mode_generic;
33901- func->led_on = e1000e_led_on_generic;
33902+ *(void **)&func->check_mng_mode = e1000e_check_mng_mode_generic;
33903+ *(void **)&func->led_on = e1000e_led_on_generic;
33904 break;
33905 }
33906
33907@@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(s
33908 temp = er32(ICRXDMTC);
33909 }
33910
33911-static struct e1000_mac_operations e82571_mac_ops = {
33912+static const struct e1000_mac_operations e82571_mac_ops = {
33913 /* .check_mng_mode: mac type dependent */
33914 /* .check_for_link: media type dependent */
33915 .id_led_init = e1000e_id_led_init,
33916@@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e8257
33917 .setup_led = e1000e_setup_led_generic,
33918 };
33919
33920-static struct e1000_phy_operations e82_phy_ops_igp = {
33921+static const struct e1000_phy_operations e82_phy_ops_igp = {
33922 .acquire_phy = e1000_get_hw_semaphore_82571,
33923 .check_reset_block = e1000e_check_reset_block_generic,
33924 .commit_phy = NULL,
33925@@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_p
33926 .cfg_on_link_up = NULL,
33927 };
33928
33929-static struct e1000_phy_operations e82_phy_ops_m88 = {
33930+static const struct e1000_phy_operations e82_phy_ops_m88 = {
33931 .acquire_phy = e1000_get_hw_semaphore_82571,
33932 .check_reset_block = e1000e_check_reset_block_generic,
33933 .commit_phy = e1000e_phy_sw_reset,
33934@@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_p
33935 .cfg_on_link_up = NULL,
33936 };
33937
33938-static struct e1000_phy_operations e82_phy_ops_bm = {
33939+static const struct e1000_phy_operations e82_phy_ops_bm = {
33940 .acquire_phy = e1000_get_hw_semaphore_82571,
33941 .check_reset_block = e1000e_check_reset_block_generic,
33942 .commit_phy = e1000e_phy_sw_reset,
33943@@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_p
33944 .cfg_on_link_up = NULL,
33945 };
33946
33947-static struct e1000_nvm_operations e82571_nvm_ops = {
33948+static const struct e1000_nvm_operations e82571_nvm_ops = {
33949 .acquire_nvm = e1000_acquire_nvm_82571,
33950 .read_nvm = e1000e_read_nvm_eerd,
33951 .release_nvm = e1000_release_nvm_82571,
33952diff -urNp linux-2.6.32.44/drivers/net/e1000e/e1000.h linux-2.6.32.44/drivers/net/e1000e/e1000.h
33953--- linux-2.6.32.44/drivers/net/e1000e/e1000.h 2011-03-27 14:31:47.000000000 -0400
33954+++ linux-2.6.32.44/drivers/net/e1000e/e1000.h 2011-04-17 15:56:46.000000000 -0400
33955@@ -375,9 +375,9 @@ struct e1000_info {
33956 u32 pba;
33957 u32 max_hw_frame_size;
33958 s32 (*get_variants)(struct e1000_adapter *);
33959- struct e1000_mac_operations *mac_ops;
33960- struct e1000_phy_operations *phy_ops;
33961- struct e1000_nvm_operations *nvm_ops;
33962+ const struct e1000_mac_operations *mac_ops;
33963+ const struct e1000_phy_operations *phy_ops;
33964+ const struct e1000_nvm_operations *nvm_ops;
33965 };
33966
33967 /* hardware capability, feature, and workaround flags */
33968diff -urNp linux-2.6.32.44/drivers/net/e1000e/es2lan.c linux-2.6.32.44/drivers/net/e1000e/es2lan.c
33969--- linux-2.6.32.44/drivers/net/e1000e/es2lan.c 2011-03-27 14:31:47.000000000 -0400
33970+++ linux-2.6.32.44/drivers/net/e1000e/es2lan.c 2011-08-05 20:33:55.000000000 -0400
33971@@ -229,16 +229,16 @@ static s32 e1000_init_mac_params_80003es
33972 /* check for link */
33973 switch (hw->phy.media_type) {
33974 case e1000_media_type_copper:
33975- func->setup_physical_interface = e1000_setup_copper_link_80003es2lan;
33976- func->check_for_link = e1000e_check_for_copper_link;
33977+ *(void **)&func->setup_physical_interface = e1000_setup_copper_link_80003es2lan;
33978+ *(void **)&func->check_for_link = e1000e_check_for_copper_link;
33979 break;
33980 case e1000_media_type_fiber:
33981- func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33982- func->check_for_link = e1000e_check_for_fiber_link;
33983+ *(void **)&func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33984+ *(void **)&func->check_for_link = e1000e_check_for_fiber_link;
33985 break;
33986 case e1000_media_type_internal_serdes:
33987- func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33988- func->check_for_link = e1000e_check_for_serdes_link;
33989+ *(void **)&func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33990+ *(void **)&func->check_for_link = e1000e_check_for_serdes_link;
33991 break;
33992 default:
33993 return -E1000_ERR_CONFIG;
33994@@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es
33995 temp = er32(ICRXDMTC);
33996 }
33997
33998-static struct e1000_mac_operations es2_mac_ops = {
33999+static const struct e1000_mac_operations es2_mac_ops = {
34000 .id_led_init = e1000e_id_led_init,
34001 .check_mng_mode = e1000e_check_mng_mode_generic,
34002 /* check_for_link dependent on media type */
34003@@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_m
34004 .setup_led = e1000e_setup_led_generic,
34005 };
34006
34007-static struct e1000_phy_operations es2_phy_ops = {
34008+static const struct e1000_phy_operations es2_phy_ops = {
34009 .acquire_phy = e1000_acquire_phy_80003es2lan,
34010 .check_reset_block = e1000e_check_reset_block_generic,
34011 .commit_phy = e1000e_phy_sw_reset,
34012@@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_p
34013 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34014 };
34015
34016-static struct e1000_nvm_operations es2_nvm_ops = {
34017+static const struct e1000_nvm_operations es2_nvm_ops = {
34018 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
34019 .read_nvm = e1000e_read_nvm_eerd,
34020 .release_nvm = e1000_release_nvm_80003es2lan,
34021diff -urNp linux-2.6.32.44/drivers/net/e1000e/hw.h linux-2.6.32.44/drivers/net/e1000e/hw.h
34022--- linux-2.6.32.44/drivers/net/e1000e/hw.h 2011-03-27 14:31:47.000000000 -0400
34023+++ linux-2.6.32.44/drivers/net/e1000e/hw.h 2011-04-17 15:56:46.000000000 -0400
34024@@ -756,34 +756,34 @@ struct e1000_mac_operations {
34025
34026 /* Function pointers for the PHY. */
34027 struct e1000_phy_operations {
34028- s32 (*acquire_phy)(struct e1000_hw *);
34029- s32 (*check_polarity)(struct e1000_hw *);
34030- s32 (*check_reset_block)(struct e1000_hw *);
34031- s32 (*commit_phy)(struct e1000_hw *);
34032- s32 (*force_speed_duplex)(struct e1000_hw *);
34033- s32 (*get_cfg_done)(struct e1000_hw *hw);
34034- s32 (*get_cable_length)(struct e1000_hw *);
34035- s32 (*get_phy_info)(struct e1000_hw *);
34036- s32 (*read_phy_reg)(struct e1000_hw *, u32, u16 *);
34037- s32 (*read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
34038- void (*release_phy)(struct e1000_hw *);
34039- s32 (*reset_phy)(struct e1000_hw *);
34040- s32 (*set_d0_lplu_state)(struct e1000_hw *, bool);
34041- s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34042- s32 (*write_phy_reg)(struct e1000_hw *, u32, u16);
34043- s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
34044- s32 (*cfg_on_link_up)(struct e1000_hw *);
34045+ s32 (* acquire_phy)(struct e1000_hw *);
34046+ s32 (* check_polarity)(struct e1000_hw *);
34047+ s32 (* check_reset_block)(struct e1000_hw *);
34048+ s32 (* commit_phy)(struct e1000_hw *);
34049+ s32 (* force_speed_duplex)(struct e1000_hw *);
34050+ s32 (* get_cfg_done)(struct e1000_hw *hw);
34051+ s32 (* get_cable_length)(struct e1000_hw *);
34052+ s32 (* get_phy_info)(struct e1000_hw *);
34053+ s32 (* read_phy_reg)(struct e1000_hw *, u32, u16 *);
34054+ s32 (* read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
34055+ void (* release_phy)(struct e1000_hw *);
34056+ s32 (* reset_phy)(struct e1000_hw *);
34057+ s32 (* set_d0_lplu_state)(struct e1000_hw *, bool);
34058+ s32 (* set_d3_lplu_state)(struct e1000_hw *, bool);
34059+ s32 (* write_phy_reg)(struct e1000_hw *, u32, u16);
34060+ s32 (* write_phy_reg_locked)(struct e1000_hw *, u32, u16);
34061+ s32 (* cfg_on_link_up)(struct e1000_hw *);
34062 };
34063
34064 /* Function pointers for the NVM. */
34065 struct e1000_nvm_operations {
34066- s32 (*acquire_nvm)(struct e1000_hw *);
34067- s32 (*read_nvm)(struct e1000_hw *, u16, u16, u16 *);
34068- void (*release_nvm)(struct e1000_hw *);
34069- s32 (*update_nvm)(struct e1000_hw *);
34070- s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34071- s32 (*validate_nvm)(struct e1000_hw *);
34072- s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
34073+ s32 (* const acquire_nvm)(struct e1000_hw *);
34074+ s32 (* const read_nvm)(struct e1000_hw *, u16, u16, u16 *);
34075+ void (* const release_nvm)(struct e1000_hw *);
34076+ s32 (* const update_nvm)(struct e1000_hw *);
34077+ s32 (* const valid_led_default)(struct e1000_hw *, u16 *);
34078+ s32 (* const validate_nvm)(struct e1000_hw *);
34079+ s32 (* const write_nvm)(struct e1000_hw *, u16, u16, u16 *);
34080 };
34081
34082 struct e1000_mac_info {
34083diff -urNp linux-2.6.32.44/drivers/net/e1000e/ich8lan.c linux-2.6.32.44/drivers/net/e1000e/ich8lan.c
34084--- linux-2.6.32.44/drivers/net/e1000e/ich8lan.c 2011-05-10 22:12:01.000000000 -0400
34085+++ linux-2.6.32.44/drivers/net/e1000e/ich8lan.c 2011-08-05 20:33:55.000000000 -0400
34086@@ -265,13 +265,13 @@ static s32 e1000_init_phy_params_pchlan(
34087 phy->addr = 1;
34088 phy->reset_delay_us = 100;
34089
34090- phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
34091- phy->ops.read_phy_reg = e1000_read_phy_reg_hv;
34092- phy->ops.read_phy_reg_locked = e1000_read_phy_reg_hv_locked;
34093- phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
34094- phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
34095- phy->ops.write_phy_reg = e1000_write_phy_reg_hv;
34096- phy->ops.write_phy_reg_locked = e1000_write_phy_reg_hv_locked;
34097+ *(void **)&phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
34098+ *(void **)&phy->ops.read_phy_reg = e1000_read_phy_reg_hv;
34099+ *(void **)&phy->ops.read_phy_reg_locked = e1000_read_phy_reg_hv_locked;
34100+ *(void **)&phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
34101+ *(void **)&phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
34102+ *(void **)&phy->ops.write_phy_reg = e1000_write_phy_reg_hv;
34103+ *(void **)&phy->ops.write_phy_reg_locked = e1000_write_phy_reg_hv_locked;
34104 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
34105
34106 /*
34107@@ -289,12 +289,12 @@ static s32 e1000_init_phy_params_pchlan(
34108 phy->type = e1000e_get_phy_type_from_id(phy->id);
34109
34110 if (phy->type == e1000_phy_82577) {
34111- phy->ops.check_polarity = e1000_check_polarity_82577;
34112- phy->ops.force_speed_duplex =
34113+ *(void **)&phy->ops.check_polarity = e1000_check_polarity_82577;
34114+ *(void **)&phy->ops.force_speed_duplex =
34115 e1000_phy_force_speed_duplex_82577;
34116- phy->ops.get_cable_length = e1000_get_cable_length_82577;
34117- phy->ops.get_phy_info = e1000_get_phy_info_82577;
34118- phy->ops.commit_phy = e1000e_phy_sw_reset;
34119+ *(void **)&phy->ops.get_cable_length = e1000_get_cable_length_82577;
34120+ *(void **)&phy->ops.get_phy_info = e1000_get_phy_info_82577;
34121+ *(void **)&phy->ops.commit_phy = e1000e_phy_sw_reset;
34122 }
34123
34124 out:
34125@@ -322,8 +322,8 @@ static s32 e1000_init_phy_params_ich8lan
34126 */
34127 ret_val = e1000e_determine_phy_address(hw);
34128 if (ret_val) {
34129- hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
34130- hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
34131+ *(void **)&hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
34132+ *(void **)&hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
34133 ret_val = e1000e_determine_phy_address(hw);
34134 if (ret_val)
34135 return ret_val;
34136@@ -343,8 +343,8 @@ static s32 e1000_init_phy_params_ich8lan
34137 case IGP03E1000_E_PHY_ID:
34138 phy->type = e1000_phy_igp_3;
34139 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
34140- phy->ops.read_phy_reg_locked = e1000e_read_phy_reg_igp_locked;
34141- phy->ops.write_phy_reg_locked = e1000e_write_phy_reg_igp_locked;
34142+ *(void **)&phy->ops.read_phy_reg_locked = e1000e_read_phy_reg_igp_locked;
34143+ *(void **)&phy->ops.write_phy_reg_locked = e1000e_write_phy_reg_igp_locked;
34144 break;
34145 case IFE_E_PHY_ID:
34146 case IFE_PLUS_E_PHY_ID:
34147@@ -355,16 +355,16 @@ static s32 e1000_init_phy_params_ich8lan
34148 case BME1000_E_PHY_ID:
34149 phy->type = e1000_phy_bm;
34150 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
34151- hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
34152- hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
34153- hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
34154+ *(void **)&hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
34155+ *(void **)&hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
34156+ *(void **)&hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
34157 break;
34158 default:
34159 return -E1000_ERR_PHY;
34160 break;
34161 }
34162
34163- phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
34164+ *(void **)&phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
34165
34166 return 0;
34167 }
34168@@ -455,25 +455,25 @@ static s32 e1000_init_mac_params_ich8lan
34169 case e1000_ich9lan:
34170 case e1000_ich10lan:
34171 /* ID LED init */
34172- mac->ops.id_led_init = e1000e_id_led_init;
34173+ *(void **)&mac->ops.id_led_init = e1000e_id_led_init;
34174 /* setup LED */
34175- mac->ops.setup_led = e1000e_setup_led_generic;
34176+ *(void **)&mac->ops.setup_led = e1000e_setup_led_generic;
34177 /* cleanup LED */
34178- mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
34179+ *(void **)&mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
34180 /* turn on/off LED */
34181- mac->ops.led_on = e1000_led_on_ich8lan;
34182- mac->ops.led_off = e1000_led_off_ich8lan;
34183+ *(void **)&mac->ops.led_on = e1000_led_on_ich8lan;
34184+ *(void **)&mac->ops.led_off = e1000_led_off_ich8lan;
34185 break;
34186 case e1000_pchlan:
34187 /* ID LED init */
34188- mac->ops.id_led_init = e1000_id_led_init_pchlan;
34189+ *(void **)&mac->ops.id_led_init = e1000_id_led_init_pchlan;
34190 /* setup LED */
34191- mac->ops.setup_led = e1000_setup_led_pchlan;
34192+ *(void **)&mac->ops.setup_led = e1000_setup_led_pchlan;
34193 /* cleanup LED */
34194- mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
34195+ *(void **)&mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
34196 /* turn on/off LED */
34197- mac->ops.led_on = e1000_led_on_pchlan;
34198- mac->ops.led_off = e1000_led_off_pchlan;
34199+ *(void **)&mac->ops.led_on = e1000_led_on_pchlan;
34200+ *(void **)&mac->ops.led_off = e1000_led_off_pchlan;
34201 break;
34202 default:
34203 break;
34204@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34205 }
34206 }
34207
34208-static struct e1000_mac_operations ich8_mac_ops = {
34209+static const struct e1000_mac_operations ich8_mac_ops = {
34210 .id_led_init = e1000e_id_led_init,
34211 .check_mng_mode = e1000_check_mng_mode_ich8lan,
34212 .check_for_link = e1000_check_for_copper_link_ich8lan,
34213@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_
34214 /* id_led_init dependent on mac type */
34215 };
34216
34217-static struct e1000_phy_operations ich8_phy_ops = {
34218+static const struct e1000_phy_operations ich8_phy_ops = {
34219 .acquire_phy = e1000_acquire_swflag_ich8lan,
34220 .check_reset_block = e1000_check_reset_block_ich8lan,
34221 .commit_phy = NULL,
34222@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_
34223 .write_phy_reg = e1000e_write_phy_reg_igp,
34224 };
34225
34226-static struct e1000_nvm_operations ich8_nvm_ops = {
34227+static const struct e1000_nvm_operations ich8_nvm_ops = {
34228 .acquire_nvm = e1000_acquire_nvm_ich8lan,
34229 .read_nvm = e1000_read_nvm_ich8lan,
34230 .release_nvm = e1000_release_nvm_ich8lan,
34231diff -urNp linux-2.6.32.44/drivers/net/e1000e/netdev.c linux-2.6.32.44/drivers/net/e1000e/netdev.c
34232--- linux-2.6.32.44/drivers/net/e1000e/netdev.c 2011-03-27 14:31:47.000000000 -0400
34233+++ linux-2.6.32.44/drivers/net/e1000e/netdev.c 2011-08-05 20:33:55.000000000 -0400
34234@@ -5071,9 +5071,9 @@ static int __devinit e1000_probe(struct
34235
34236 err = -EIO;
34237
34238- memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
34239- memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
34240- memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
34241+ memcpy((void *)&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
34242+ memcpy((void *)&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
34243+ memcpy((void *)&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
34244
34245 err = ei->get_variants(adapter);
34246 if (err)
34247diff -urNp linux-2.6.32.44/drivers/net/hamradio/6pack.c linux-2.6.32.44/drivers/net/hamradio/6pack.c
34248--- linux-2.6.32.44/drivers/net/hamradio/6pack.c 2011-07-13 17:23:04.000000000 -0400
34249+++ linux-2.6.32.44/drivers/net/hamradio/6pack.c 2011-07-13 17:23:18.000000000 -0400
34250@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct t
34251 unsigned char buf[512];
34252 int count1;
34253
34254+ pax_track_stack();
34255+
34256 if (!count)
34257 return;
34258
34259diff -urNp linux-2.6.32.44/drivers/net/ibmveth.c linux-2.6.32.44/drivers/net/ibmveth.c
34260--- linux-2.6.32.44/drivers/net/ibmveth.c 2011-03-27 14:31:47.000000000 -0400
34261+++ linux-2.6.32.44/drivers/net/ibmveth.c 2011-04-17 15:56:46.000000000 -0400
34262@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attr
34263 NULL,
34264 };
34265
34266-static struct sysfs_ops veth_pool_ops = {
34267+static const struct sysfs_ops veth_pool_ops = {
34268 .show = veth_pool_show,
34269 .store = veth_pool_store,
34270 };
34271diff -urNp linux-2.6.32.44/drivers/net/igb/e1000_82575.c linux-2.6.32.44/drivers/net/igb/e1000_82575.c
34272--- linux-2.6.32.44/drivers/net/igb/e1000_82575.c 2011-03-27 14:31:47.000000000 -0400
34273+++ linux-2.6.32.44/drivers/net/igb/e1000_82575.c 2011-08-05 20:33:55.000000000 -0400
34274@@ -135,7 +135,7 @@ static s32 igb_get_invariants_82575(stru
34275 ? true : false;
34276
34277 /* physical interface link setup */
34278- mac->ops.setup_physical_interface =
34279+ *(void **)&mac->ops.setup_physical_interface =
34280 (hw->phy.media_type == e1000_media_type_copper)
34281 ? igb_setup_copper_link_82575
34282 : igb_setup_serdes_link_82575;
34283@@ -191,13 +191,13 @@ static s32 igb_get_invariants_82575(stru
34284
34285 /* PHY function pointers */
34286 if (igb_sgmii_active_82575(hw)) {
34287- phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
34288- phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
34289- phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
34290+ *(void **)&phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
34291+ *(void **)&phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
34292+ *(void **)&phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
34293 } else {
34294- phy->ops.reset = igb_phy_hw_reset;
34295- phy->ops.read_reg = igb_read_phy_reg_igp;
34296- phy->ops.write_reg = igb_write_phy_reg_igp;
34297+ *(void **)&phy->ops.reset = igb_phy_hw_reset;
34298+ *(void **)&phy->ops.read_reg = igb_read_phy_reg_igp;
34299+ *(void **)&phy->ops.write_reg = igb_write_phy_reg_igp;
34300 }
34301
34302 /* set lan id */
34303@@ -213,17 +213,17 @@ static s32 igb_get_invariants_82575(stru
34304 switch (phy->id) {
34305 case M88E1111_I_PHY_ID:
34306 phy->type = e1000_phy_m88;
34307- phy->ops.get_phy_info = igb_get_phy_info_m88;
34308- phy->ops.get_cable_length = igb_get_cable_length_m88;
34309- phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
34310+ *(void **)&phy->ops.get_phy_info = igb_get_phy_info_m88;
34311+ *(void **)&phy->ops.get_cable_length = igb_get_cable_length_m88;
34312+ *(void **)&phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
34313 break;
34314 case IGP03E1000_E_PHY_ID:
34315 phy->type = e1000_phy_igp_3;
34316- phy->ops.get_phy_info = igb_get_phy_info_igp;
34317- phy->ops.get_cable_length = igb_get_cable_length_igp_2;
34318- phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
34319- phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
34320- phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
34321+ *(void **)&phy->ops.get_phy_info = igb_get_phy_info_igp;
34322+ *(void **)&phy->ops.get_cable_length = igb_get_cable_length_igp_2;
34323+ *(void **)&phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
34324+ *(void **)&phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
34325+ *(void **)&phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
34326 break;
34327 default:
34328 return -E1000_ERR_PHY;
34329@@ -1410,7 +1410,7 @@ void igb_vmdq_set_replication_pf(struct
34330 wr32(E1000_VT_CTL, vt_ctl);
34331 }
34332
34333-static struct e1000_mac_operations e1000_mac_ops_82575 = {
34334+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34335 .reset_hw = igb_reset_hw_82575,
34336 .init_hw = igb_init_hw_82575,
34337 .check_for_link = igb_check_for_link_82575,
34338@@ -1419,13 +1419,13 @@ static struct e1000_mac_operations e1000
34339 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34340 };
34341
34342-static struct e1000_phy_operations e1000_phy_ops_82575 = {
34343+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34344 .acquire = igb_acquire_phy_82575,
34345 .get_cfg_done = igb_get_cfg_done_82575,
34346 .release = igb_release_phy_82575,
34347 };
34348
34349-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34350+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34351 .acquire = igb_acquire_nvm_82575,
34352 .read = igb_read_nvm_eerd,
34353 .release = igb_release_nvm_82575,
34354diff -urNp linux-2.6.32.44/drivers/net/igb/e1000_hw.h linux-2.6.32.44/drivers/net/igb/e1000_hw.h
34355--- linux-2.6.32.44/drivers/net/igb/e1000_hw.h 2011-03-27 14:31:47.000000000 -0400
34356+++ linux-2.6.32.44/drivers/net/igb/e1000_hw.h 2011-04-17 15:56:46.000000000 -0400
34357@@ -305,17 +305,17 @@ struct e1000_phy_operations {
34358 };
34359
34360 struct e1000_nvm_operations {
34361- s32 (*acquire)(struct e1000_hw *);
34362- s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
34363- void (*release)(struct e1000_hw *);
34364- s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34365+ s32 (* const acquire)(struct e1000_hw *);
34366+ s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
34367+ void (* const release)(struct e1000_hw *);
34368+ s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
34369 };
34370
34371 struct e1000_info {
34372 s32 (*get_invariants)(struct e1000_hw *);
34373- struct e1000_mac_operations *mac_ops;
34374- struct e1000_phy_operations *phy_ops;
34375- struct e1000_nvm_operations *nvm_ops;
34376+ const struct e1000_mac_operations *mac_ops;
34377+ const struct e1000_phy_operations *phy_ops;
34378+ const struct e1000_nvm_operations *nvm_ops;
34379 };
34380
34381 extern const struct e1000_info e1000_82575_info;
34382diff -urNp linux-2.6.32.44/drivers/net/igb/e1000_mbx.c linux-2.6.32.44/drivers/net/igb/e1000_mbx.c
34383--- linux-2.6.32.44/drivers/net/igb/e1000_mbx.c 2011-03-27 14:31:47.000000000 -0400
34384+++ linux-2.6.32.44/drivers/net/igb/e1000_mbx.c 2011-08-05 20:33:55.000000000 -0400
34385@@ -414,13 +414,13 @@ s32 igb_init_mbx_params_pf(struct e1000_
34386
34387 mbx->size = E1000_VFMAILBOX_SIZE;
34388
34389- mbx->ops.read = igb_read_mbx_pf;
34390- mbx->ops.write = igb_write_mbx_pf;
34391- mbx->ops.read_posted = igb_read_posted_mbx;
34392- mbx->ops.write_posted = igb_write_posted_mbx;
34393- mbx->ops.check_for_msg = igb_check_for_msg_pf;
34394- mbx->ops.check_for_ack = igb_check_for_ack_pf;
34395- mbx->ops.check_for_rst = igb_check_for_rst_pf;
34396+ *(void **)&mbx->ops.read = igb_read_mbx_pf;
34397+ *(void **)&mbx->ops.write = igb_write_mbx_pf;
34398+ *(void **)&mbx->ops.read_posted = igb_read_posted_mbx;
34399+ *(void **)&mbx->ops.write_posted = igb_write_posted_mbx;
34400+ *(void **)&mbx->ops.check_for_msg = igb_check_for_msg_pf;
34401+ *(void **)&mbx->ops.check_for_ack = igb_check_for_ack_pf;
34402+ *(void **)&mbx->ops.check_for_rst = igb_check_for_rst_pf;
34403
34404 mbx->stats.msgs_tx = 0;
34405 mbx->stats.msgs_rx = 0;
34406diff -urNp linux-2.6.32.44/drivers/net/igb/igb_main.c linux-2.6.32.44/drivers/net/igb/igb_main.c
34407--- linux-2.6.32.44/drivers/net/igb/igb_main.c 2011-03-27 14:31:47.000000000 -0400
34408+++ linux-2.6.32.44/drivers/net/igb/igb_main.c 2011-08-05 20:33:55.000000000 -0400
34409@@ -1295,9 +1295,9 @@ static int __devinit igb_probe(struct pc
34410 /* setup the private structure */
34411 hw->back = adapter;
34412 /* Copy the default MAC, PHY and NVM function pointers */
34413- memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
34414- memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
34415- memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
34416+ memcpy((void *)&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
34417+ memcpy((void *)&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
34418+ memcpy((void *)&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
34419 /* Initialize skew-specific constants */
34420 err = ei->get_invariants(hw);
34421 if (err)
34422diff -urNp linux-2.6.32.44/drivers/net/igbvf/mbx.c linux-2.6.32.44/drivers/net/igbvf/mbx.c
34423--- linux-2.6.32.44/drivers/net/igbvf/mbx.c 2011-03-27 14:31:47.000000000 -0400
34424+++ linux-2.6.32.44/drivers/net/igbvf/mbx.c 2011-08-05 20:33:55.000000000 -0400
34425@@ -331,13 +331,13 @@ s32 e1000_init_mbx_params_vf(struct e100
34426
34427 mbx->size = E1000_VFMAILBOX_SIZE;
34428
34429- mbx->ops.read = e1000_read_mbx_vf;
34430- mbx->ops.write = e1000_write_mbx_vf;
34431- mbx->ops.read_posted = e1000_read_posted_mbx;
34432- mbx->ops.write_posted = e1000_write_posted_mbx;
34433- mbx->ops.check_for_msg = e1000_check_for_msg_vf;
34434- mbx->ops.check_for_ack = e1000_check_for_ack_vf;
34435- mbx->ops.check_for_rst = e1000_check_for_rst_vf;
34436+ *(void **)&mbx->ops.read = e1000_read_mbx_vf;
34437+ *(void **)&mbx->ops.write = e1000_write_mbx_vf;
34438+ *(void **)&mbx->ops.read_posted = e1000_read_posted_mbx;
34439+ *(void **)&mbx->ops.write_posted = e1000_write_posted_mbx;
34440+ *(void **)&mbx->ops.check_for_msg = e1000_check_for_msg_vf;
34441+ *(void **)&mbx->ops.check_for_ack = e1000_check_for_ack_vf;
34442+ *(void **)&mbx->ops.check_for_rst = e1000_check_for_rst_vf;
34443
34444 mbx->stats.msgs_tx = 0;
34445 mbx->stats.msgs_rx = 0;
34446diff -urNp linux-2.6.32.44/drivers/net/igbvf/vf.c linux-2.6.32.44/drivers/net/igbvf/vf.c
34447--- linux-2.6.32.44/drivers/net/igbvf/vf.c 2011-03-27 14:31:47.000000000 -0400
34448+++ linux-2.6.32.44/drivers/net/igbvf/vf.c 2011-08-05 20:33:55.000000000 -0400
34449@@ -55,21 +55,21 @@ static s32 e1000_init_mac_params_vf(stru
34450
34451 /* Function pointers */
34452 /* reset */
34453- mac->ops.reset_hw = e1000_reset_hw_vf;
34454+ *(void **)&mac->ops.reset_hw = e1000_reset_hw_vf;
34455 /* hw initialization */
34456- mac->ops.init_hw = e1000_init_hw_vf;
34457+ *(void **)&mac->ops.init_hw = e1000_init_hw_vf;
34458 /* check for link */
34459- mac->ops.check_for_link = e1000_check_for_link_vf;
34460+ *(void **)&mac->ops.check_for_link = e1000_check_for_link_vf;
34461 /* link info */
34462- mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
34463+ *(void **)&mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
34464 /* multicast address update */
34465- mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
34466+ *(void **)&mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
34467 /* set mac address */
34468- mac->ops.rar_set = e1000_rar_set_vf;
34469+ *(void **)&mac->ops.rar_set = e1000_rar_set_vf;
34470 /* read mac address */
34471- mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
34472+ *(void **)&mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
34473 /* set vlan filter table array */
34474- mac->ops.set_vfta = e1000_set_vfta_vf;
34475+ *(void **)&mac->ops.set_vfta = e1000_set_vfta_vf;
34476
34477 return E1000_SUCCESS;
34478 }
34479@@ -80,8 +80,8 @@ static s32 e1000_init_mac_params_vf(stru
34480 **/
34481 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
34482 {
34483- hw->mac.ops.init_params = e1000_init_mac_params_vf;
34484- hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
34485+ *(void **)&hw->mac.ops.init_params = e1000_init_mac_params_vf;
34486+ *(void **)&hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
34487 }
34488
34489 /**
34490diff -urNp linux-2.6.32.44/drivers/net/iseries_veth.c linux-2.6.32.44/drivers/net/iseries_veth.c
34491--- linux-2.6.32.44/drivers/net/iseries_veth.c 2011-03-27 14:31:47.000000000 -0400
34492+++ linux-2.6.32.44/drivers/net/iseries_veth.c 2011-04-17 15:56:46.000000000 -0400
34493@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_defaul
34494 NULL
34495 };
34496
34497-static struct sysfs_ops veth_cnx_sysfs_ops = {
34498+static const struct sysfs_ops veth_cnx_sysfs_ops = {
34499 .show = veth_cnx_attribute_show
34500 };
34501
34502@@ -441,7 +441,7 @@ static struct attribute *veth_port_defau
34503 NULL
34504 };
34505
34506-static struct sysfs_ops veth_port_sysfs_ops = {
34507+static const struct sysfs_ops veth_port_sysfs_ops = {
34508 .show = veth_port_attribute_show
34509 };
34510
34511diff -urNp linux-2.6.32.44/drivers/net/ixgb/ixgb_main.c linux-2.6.32.44/drivers/net/ixgb/ixgb_main.c
34512--- linux-2.6.32.44/drivers/net/ixgb/ixgb_main.c 2011-03-27 14:31:47.000000000 -0400
34513+++ linux-2.6.32.44/drivers/net/ixgb/ixgb_main.c 2011-05-16 21:46:57.000000000 -0400
34514@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev
34515 u32 rctl;
34516 int i;
34517
34518+ pax_track_stack();
34519+
34520 /* Check for Promiscuous and All Multicast modes */
34521
34522 rctl = IXGB_READ_REG(hw, RCTL);
34523diff -urNp linux-2.6.32.44/drivers/net/ixgb/ixgb_param.c linux-2.6.32.44/drivers/net/ixgb/ixgb_param.c
34524--- linux-2.6.32.44/drivers/net/ixgb/ixgb_param.c 2011-03-27 14:31:47.000000000 -0400
34525+++ linux-2.6.32.44/drivers/net/ixgb/ixgb_param.c 2011-05-16 21:46:57.000000000 -0400
34526@@ -260,6 +260,9 @@ void __devinit
34527 ixgb_check_options(struct ixgb_adapter *adapter)
34528 {
34529 int bd = adapter->bd_number;
34530+
34531+ pax_track_stack();
34532+
34533 if (bd >= IXGB_MAX_NIC) {
34534 printk(KERN_NOTICE
34535 "Warning: no configuration for board #%i\n", bd);
34536diff -urNp linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82598.c linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82598.c
34537--- linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82598.c 2011-03-27 14:31:47.000000000 -0400
34538+++ linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82598.c 2011-08-05 20:33:55.000000000 -0400
34539@@ -154,19 +154,19 @@ static s32 ixgbe_init_phy_ops_82598(stru
34540
34541 /* Overwrite the link function pointers if copper PHY */
34542 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
34543- mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
34544- mac->ops.get_link_capabilities =
34545+ *(void **)&mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
34546+ *(void **)&mac->ops.get_link_capabilities =
34547 &ixgbe_get_copper_link_capabilities_82598;
34548 }
34549
34550 switch (hw->phy.type) {
34551 case ixgbe_phy_tn:
34552- phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34553- phy->ops.get_firmware_version =
34554+ *(void **)&phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34555+ *(void **)&phy->ops.get_firmware_version =
34556 &ixgbe_get_phy_firmware_version_tnx;
34557 break;
34558 case ixgbe_phy_nl:
34559- phy->ops.reset = &ixgbe_reset_phy_nl;
34560+ *(void **)&phy->ops.reset = &ixgbe_reset_phy_nl;
34561
34562 /* Call SFP+ identify routine to get the SFP+ module type */
34563 ret_val = phy->ops.identify_sfp(hw);
34564diff -urNp linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82599.c
34565--- linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82599.c 2011-03-27 14:31:47.000000000 -0400
34566+++ linux-2.6.32.44/drivers/net/ixgbe/ixgbe_82599.c 2011-08-05 20:33:55.000000000 -0400
34567@@ -62,9 +62,9 @@ static void ixgbe_init_mac_link_ops_8259
34568 struct ixgbe_mac_info *mac = &hw->mac;
34569 if (hw->phy.multispeed_fiber) {
34570 /* Set up dual speed SFP+ support */
34571- mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
34572+ *(void **)&mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
34573 } else {
34574- mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
34575+ *(void **)&mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
34576 }
34577 }
34578
34579@@ -76,7 +76,7 @@ static s32 ixgbe_setup_sfp_modules_82599
34580 if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
34581 ixgbe_init_mac_link_ops_82599(hw);
34582
34583- hw->phy.ops.reset = NULL;
34584+ *(void **)&hw->phy.ops.reset = NULL;
34585
34586 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
34587 &data_offset);
34588@@ -171,16 +171,16 @@ static s32 ixgbe_init_phy_ops_82599(stru
34589
34590 /* If copper media, overwrite with copper function pointers */
34591 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
34592- mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
34593- mac->ops.get_link_capabilities =
34594+ *(void **)&mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
34595+ *(void **)&mac->ops.get_link_capabilities =
34596 &ixgbe_get_copper_link_capabilities_82599;
34597 }
34598
34599 /* Set necessary function pointers based on phy type */
34600 switch (hw->phy.type) {
34601 case ixgbe_phy_tn:
34602- phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34603- phy->ops.get_firmware_version =
34604+ *(void **)&phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34605+ *(void **)&phy->ops.get_firmware_version =
34606 &ixgbe_get_phy_firmware_version_tnx;
34607 break;
34608 default:
34609diff -urNp linux-2.6.32.44/drivers/net/ixgbe/ixgbe_main.c linux-2.6.32.44/drivers/net/ixgbe/ixgbe_main.c
34610--- linux-2.6.32.44/drivers/net/ixgbe/ixgbe_main.c 2011-03-27 14:31:47.000000000 -0400
34611+++ linux-2.6.32.44/drivers/net/ixgbe/ixgbe_main.c 2011-08-05 20:33:55.000000000 -0400
34612@@ -5638,18 +5638,18 @@ static int __devinit ixgbe_probe(struct
34613 adapter->bd_number = cards_found;
34614
34615 /* Setup hw api */
34616- memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
34617+ memcpy((void *)&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
34618 hw->mac.type = ii->mac;
34619
34620 /* EEPROM */
34621- memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
34622+ memcpy((void *)&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
34623 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
34624 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
34625 if (!(eec & (1 << 8)))
34626- hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
34627+ *(void **)&hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
34628
34629 /* PHY */
34630- memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
34631+ memcpy((void *)&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
34632 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
34633 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
34634 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
34635diff -urNp linux-2.6.32.44/drivers/net/mlx4/main.c linux-2.6.32.44/drivers/net/mlx4/main.c
34636--- linux-2.6.32.44/drivers/net/mlx4/main.c 2011-03-27 14:31:47.000000000 -0400
34637+++ linux-2.6.32.44/drivers/net/mlx4/main.c 2011-05-18 20:09:37.000000000 -0400
34638@@ -38,6 +38,7 @@
34639 #include <linux/errno.h>
34640 #include <linux/pci.h>
34641 #include <linux/dma-mapping.h>
34642+#include <linux/sched.h>
34643
34644 #include <linux/mlx4/device.h>
34645 #include <linux/mlx4/doorbell.h>
34646@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev
34647 u64 icm_size;
34648 int err;
34649
34650+ pax_track_stack();
34651+
34652 err = mlx4_QUERY_FW(dev);
34653 if (err) {
34654 if (err == -EACCES)
34655diff -urNp linux-2.6.32.44/drivers/net/niu.c linux-2.6.32.44/drivers/net/niu.c
34656--- linux-2.6.32.44/drivers/net/niu.c 2011-05-10 22:12:01.000000000 -0400
34657+++ linux-2.6.32.44/drivers/net/niu.c 2011-05-16 21:46:57.000000000 -0400
34658@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struc
34659 int i, num_irqs, err;
34660 u8 first_ldg;
34661
34662+ pax_track_stack();
34663+
34664 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
34665 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
34666 ldg_num_map[i] = first_ldg + i;
34667diff -urNp linux-2.6.32.44/drivers/net/pcnet32.c linux-2.6.32.44/drivers/net/pcnet32.c
34668--- linux-2.6.32.44/drivers/net/pcnet32.c 2011-03-27 14:31:47.000000000 -0400
34669+++ linux-2.6.32.44/drivers/net/pcnet32.c 2011-08-05 20:33:55.000000000 -0400
34670@@ -79,7 +79,7 @@ static int cards_found;
34671 /*
34672 * VLB I/O addresses
34673 */
34674-static unsigned int pcnet32_portlist[] __initdata =
34675+static unsigned int pcnet32_portlist[] __devinitdata =
34676 { 0x300, 0x320, 0x340, 0x360, 0 };
34677
34678 static int pcnet32_debug = 0;
34679@@ -267,7 +267,7 @@ struct pcnet32_private {
34680 struct sk_buff **rx_skbuff;
34681 dma_addr_t *tx_dma_addr;
34682 dma_addr_t *rx_dma_addr;
34683- struct pcnet32_access a;
34684+ struct pcnet32_access *a;
34685 spinlock_t lock; /* Guard lock */
34686 unsigned int cur_rx, cur_tx; /* The next free ring entry */
34687 unsigned int rx_ring_size; /* current rx ring size */
34688@@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct n
34689 u16 val;
34690
34691 netif_wake_queue(dev);
34692- val = lp->a.read_csr(ioaddr, CSR3);
34693+ val = lp->a->read_csr(ioaddr, CSR3);
34694 val &= 0x00ff;
34695- lp->a.write_csr(ioaddr, CSR3, val);
34696+ lp->a->write_csr(ioaddr, CSR3, val);
34697 napi_enable(&lp->napi);
34698 }
34699
34700@@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_d
34701 r = mii_link_ok(&lp->mii_if);
34702 } else if (lp->chip_version >= PCNET32_79C970A) {
34703 ulong ioaddr = dev->base_addr; /* card base I/O address */
34704- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
34705+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
34706 } else { /* can not detect link on really old chips */
34707 r = 1;
34708 }
34709@@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct
34710 pcnet32_netif_stop(dev);
34711
34712 spin_lock_irqsave(&lp->lock, flags);
34713- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34714+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34715
34716 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
34717
34718@@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct
34719 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
34720 {
34721 struct pcnet32_private *lp = netdev_priv(dev);
34722- struct pcnet32_access *a = &lp->a; /* access to registers */
34723+ struct pcnet32_access *a = lp->a; /* access to registers */
34724 ulong ioaddr = dev->base_addr; /* card base I/O address */
34725 struct sk_buff *skb; /* sk buff */
34726 int x, i; /* counters */
34727@@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct
34728 pcnet32_netif_stop(dev);
34729
34730 spin_lock_irqsave(&lp->lock, flags);
34731- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34732+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34733
34734 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
34735
34736 /* Reset the PCNET32 */
34737- lp->a.reset(ioaddr);
34738- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34739+ lp->a->reset(ioaddr);
34740+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34741
34742 /* switch pcnet32 to 32bit mode */
34743- lp->a.write_bcr(ioaddr, 20, 2);
34744+ lp->a->write_bcr(ioaddr, 20, 2);
34745
34746 /* purge & init rings but don't actually restart */
34747 pcnet32_restart(dev, 0x0000);
34748
34749- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34750+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34751
34752 /* Initialize Transmit buffers. */
34753 size = data_len + 15;
34754@@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct
34755
34756 /* set int loopback in CSR15 */
34757 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
34758- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
34759+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
34760
34761 teststatus = cpu_to_le16(0x8000);
34762- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
34763+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
34764
34765 /* Check status of descriptors */
34766 for (x = 0; x < numbuffs; x++) {
34767@@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct
34768 }
34769 }
34770
34771- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34772+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34773 wmb();
34774 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
34775 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
34776@@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct
34777 pcnet32_restart(dev, CSR0_NORMAL);
34778 } else {
34779 pcnet32_purge_rx_ring(dev);
34780- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
34781+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
34782 }
34783 spin_unlock_irqrestore(&lp->lock, flags);
34784
34785@@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct
34786 static void pcnet32_led_blink_callback(struct net_device *dev)
34787 {
34788 struct pcnet32_private *lp = netdev_priv(dev);
34789- struct pcnet32_access *a = &lp->a;
34790+ struct pcnet32_access *a = lp->a;
34791 ulong ioaddr = dev->base_addr;
34792 unsigned long flags;
34793 int i;
34794@@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(s
34795 static int pcnet32_phys_id(struct net_device *dev, u32 data)
34796 {
34797 struct pcnet32_private *lp = netdev_priv(dev);
34798- struct pcnet32_access *a = &lp->a;
34799+ struct pcnet32_access *a = lp->a;
34800 ulong ioaddr = dev->base_addr;
34801 unsigned long flags;
34802 int i, regs[4];
34803@@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_de
34804 {
34805 int csr5;
34806 struct pcnet32_private *lp = netdev_priv(dev);
34807- struct pcnet32_access *a = &lp->a;
34808+ struct pcnet32_access *a = lp->a;
34809 ulong ioaddr = dev->base_addr;
34810 int ticks;
34811
34812@@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_stru
34813 spin_lock_irqsave(&lp->lock, flags);
34814 if (pcnet32_tx(dev)) {
34815 /* reset the chip to clear the error condition, then restart */
34816- lp->a.reset(ioaddr);
34817- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34818+ lp->a->reset(ioaddr);
34819+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34820 pcnet32_restart(dev, CSR0_START);
34821 netif_wake_queue(dev);
34822 }
34823@@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_stru
34824 __napi_complete(napi);
34825
34826 /* clear interrupt masks */
34827- val = lp->a.read_csr(ioaddr, CSR3);
34828+ val = lp->a->read_csr(ioaddr, CSR3);
34829 val &= 0x00ff;
34830- lp->a.write_csr(ioaddr, CSR3, val);
34831+ lp->a->write_csr(ioaddr, CSR3, val);
34832
34833 /* Set interrupt enable. */
34834- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
34835+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
34836
34837 spin_unlock_irqrestore(&lp->lock, flags);
34838 }
34839@@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_
34840 int i, csr0;
34841 u16 *buff = ptr;
34842 struct pcnet32_private *lp = netdev_priv(dev);
34843- struct pcnet32_access *a = &lp->a;
34844+ struct pcnet32_access *a = lp->a;
34845 ulong ioaddr = dev->base_addr;
34846 unsigned long flags;
34847
34848@@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_
34849 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
34850 if (lp->phymask & (1 << j)) {
34851 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
34852- lp->a.write_bcr(ioaddr, 33,
34853+ lp->a->write_bcr(ioaddr, 33,
34854 (j << 5) | i);
34855- *buff++ = lp->a.read_bcr(ioaddr, 34);
34856+ *buff++ = lp->a->read_bcr(ioaddr, 34);
34857 }
34858 }
34859 }
34860@@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int
34861 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
34862 lp->options |= PCNET32_PORT_FD;
34863
34864- lp->a = *a;
34865+ lp->a = a;
34866
34867 /* prior to register_netdev, dev->name is not yet correct */
34868 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
34869@@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int
34870 if (lp->mii) {
34871 /* lp->phycount and lp->phymask are set to 0 by memset above */
34872
34873- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
34874+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
34875 /* scan for PHYs */
34876 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
34877 unsigned short id1, id2;
34878@@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int
34879 "Found PHY %04x:%04x at address %d.\n",
34880 id1, id2, i);
34881 }
34882- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
34883+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
34884 if (lp->phycount > 1) {
34885 lp->options |= PCNET32_PORT_MII;
34886 }
34887@@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_devic
34888 }
34889
34890 /* Reset the PCNET32 */
34891- lp->a.reset(ioaddr);
34892+ lp->a->reset(ioaddr);
34893
34894 /* switch pcnet32 to 32bit mode */
34895- lp->a.write_bcr(ioaddr, 20, 2);
34896+ lp->a->write_bcr(ioaddr, 20, 2);
34897
34898 if (netif_msg_ifup(lp))
34899 printk(KERN_DEBUG
34900@@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_devic
34901 (u32) (lp->init_dma_addr));
34902
34903 /* set/reset autoselect bit */
34904- val = lp->a.read_bcr(ioaddr, 2) & ~2;
34905+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
34906 if (lp->options & PCNET32_PORT_ASEL)
34907 val |= 2;
34908- lp->a.write_bcr(ioaddr, 2, val);
34909+ lp->a->write_bcr(ioaddr, 2, val);
34910
34911 /* handle full duplex setting */
34912 if (lp->mii_if.full_duplex) {
34913- val = lp->a.read_bcr(ioaddr, 9) & ~3;
34914+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
34915 if (lp->options & PCNET32_PORT_FD) {
34916 val |= 1;
34917 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
34918@@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_devic
34919 if (lp->chip_version == 0x2627)
34920 val |= 3;
34921 }
34922- lp->a.write_bcr(ioaddr, 9, val);
34923+ lp->a->write_bcr(ioaddr, 9, val);
34924 }
34925
34926 /* set/reset GPSI bit in test register */
34927- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
34928+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
34929 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
34930 val |= 0x10;
34931- lp->a.write_csr(ioaddr, 124, val);
34932+ lp->a->write_csr(ioaddr, 124, val);
34933
34934 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
34935 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
34936@@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_devic
34937 * duplex, and/or enable auto negotiation, and clear DANAS
34938 */
34939 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
34940- lp->a.write_bcr(ioaddr, 32,
34941- lp->a.read_bcr(ioaddr, 32) | 0x0080);
34942+ lp->a->write_bcr(ioaddr, 32,
34943+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
34944 /* disable Auto Negotiation, set 10Mpbs, HD */
34945- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
34946+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
34947 if (lp->options & PCNET32_PORT_FD)
34948 val |= 0x10;
34949 if (lp->options & PCNET32_PORT_100)
34950 val |= 0x08;
34951- lp->a.write_bcr(ioaddr, 32, val);
34952+ lp->a->write_bcr(ioaddr, 32, val);
34953 } else {
34954 if (lp->options & PCNET32_PORT_ASEL) {
34955- lp->a.write_bcr(ioaddr, 32,
34956- lp->a.read_bcr(ioaddr,
34957+ lp->a->write_bcr(ioaddr, 32,
34958+ lp->a->read_bcr(ioaddr,
34959 32) | 0x0080);
34960 /* enable auto negotiate, setup, disable fd */
34961- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
34962+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
34963 val |= 0x20;
34964- lp->a.write_bcr(ioaddr, 32, val);
34965+ lp->a->write_bcr(ioaddr, 32, val);
34966 }
34967 }
34968 } else {
34969@@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_devic
34970 * There is really no good other way to handle multiple PHYs
34971 * other than turning off all automatics
34972 */
34973- val = lp->a.read_bcr(ioaddr, 2);
34974- lp->a.write_bcr(ioaddr, 2, val & ~2);
34975- val = lp->a.read_bcr(ioaddr, 32);
34976- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
34977+ val = lp->a->read_bcr(ioaddr, 2);
34978+ lp->a->write_bcr(ioaddr, 2, val & ~2);
34979+ val = lp->a->read_bcr(ioaddr, 32);
34980+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
34981
34982 if (!(lp->options & PCNET32_PORT_ASEL)) {
34983 /* setup ecmd */
34984@@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_devic
34985 ecmd.speed =
34986 lp->
34987 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
34988- bcr9 = lp->a.read_bcr(ioaddr, 9);
34989+ bcr9 = lp->a->read_bcr(ioaddr, 9);
34990
34991 if (lp->options & PCNET32_PORT_FD) {
34992 ecmd.duplex = DUPLEX_FULL;
34993@@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_devic
34994 ecmd.duplex = DUPLEX_HALF;
34995 bcr9 |= ~(1 << 0);
34996 }
34997- lp->a.write_bcr(ioaddr, 9, bcr9);
34998+ lp->a->write_bcr(ioaddr, 9, bcr9);
34999 }
35000
35001 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
35002@@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_devic
35003
35004 #ifdef DO_DXSUFLO
35005 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
35006- val = lp->a.read_csr(ioaddr, CSR3);
35007+ val = lp->a->read_csr(ioaddr, CSR3);
35008 val |= 0x40;
35009- lp->a.write_csr(ioaddr, CSR3, val);
35010+ lp->a->write_csr(ioaddr, CSR3, val);
35011 }
35012 #endif
35013
35014@@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_devic
35015 napi_enable(&lp->napi);
35016
35017 /* Re-initialize the PCNET32, and start it when done. */
35018- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
35019- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
35020+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
35021+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
35022
35023- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35024- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
35025+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
35026+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
35027
35028 netif_start_queue(dev);
35029
35030@@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_devic
35031
35032 i = 0;
35033 while (i++ < 100)
35034- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
35035+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
35036 break;
35037 /*
35038 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
35039 * reports that doing so triggers a bug in the '974.
35040 */
35041- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
35042+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
35043
35044 if (netif_msg_ifup(lp))
35045 printk(KERN_DEBUG
35046 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
35047 dev->name, i,
35048 (u32) (lp->init_dma_addr),
35049- lp->a.read_csr(ioaddr, CSR0));
35050+ lp->a->read_csr(ioaddr, CSR0));
35051
35052 spin_unlock_irqrestore(&lp->lock, flags);
35053
35054@@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_devic
35055 * Switch back to 16bit mode to avoid problems with dumb
35056 * DOS packet driver after a warm reboot
35057 */
35058- lp->a.write_bcr(ioaddr, 20, 4);
35059+ lp->a->write_bcr(ioaddr, 20, 4);
35060
35061 err_free_irq:
35062 spin_unlock_irqrestore(&lp->lock, flags);
35063@@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_d
35064
35065 /* wait for stop */
35066 for (i = 0; i < 100; i++)
35067- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
35068+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
35069 break;
35070
35071 if (i >= 100 && netif_msg_drv(lp))
35072@@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_d
35073 return;
35074
35075 /* ReInit Ring */
35076- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
35077+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
35078 i = 0;
35079 while (i++ < 1000)
35080- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
35081+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
35082 break;
35083
35084- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
35085+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
35086 }
35087
35088 static void pcnet32_tx_timeout(struct net_device *dev)
35089@@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct ne
35090 if (pcnet32_debug & NETIF_MSG_DRV)
35091 printk(KERN_ERR
35092 "%s: transmit timed out, status %4.4x, resetting.\n",
35093- dev->name, lp->a.read_csr(ioaddr, CSR0));
35094- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
35095+ dev->name, lp->a->read_csr(ioaddr, CSR0));
35096+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
35097 dev->stats.tx_errors++;
35098 if (netif_msg_tx_err(lp)) {
35099 int i;
35100@@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(st
35101 if (netif_msg_tx_queued(lp)) {
35102 printk(KERN_DEBUG
35103 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
35104- dev->name, lp->a.read_csr(ioaddr, CSR0));
35105+ dev->name, lp->a->read_csr(ioaddr, CSR0));
35106 }
35107
35108 /* Default status -- will not enable Successful-TxDone
35109@@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(st
35110 dev->stats.tx_bytes += skb->len;
35111
35112 /* Trigger an immediate send poll. */
35113- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
35114+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
35115
35116 dev->trans_start = jiffies;
35117
35118@@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
35119
35120 spin_lock(&lp->lock);
35121
35122- csr0 = lp->a.read_csr(ioaddr, CSR0);
35123+ csr0 = lp->a->read_csr(ioaddr, CSR0);
35124 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
35125 if (csr0 == 0xffff) {
35126 break; /* PCMCIA remove happened */
35127 }
35128 /* Acknowledge all of the current interrupt sources ASAP. */
35129- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
35130+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
35131
35132 if (netif_msg_intr(lp))
35133 printk(KERN_DEBUG
35134 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
35135- dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
35136+ dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
35137
35138 /* Log misc errors. */
35139 if (csr0 & 0x4000)
35140@@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
35141 if (napi_schedule_prep(&lp->napi)) {
35142 u16 val;
35143 /* set interrupt masks */
35144- val = lp->a.read_csr(ioaddr, CSR3);
35145+ val = lp->a->read_csr(ioaddr, CSR3);
35146 val |= 0x5f00;
35147- lp->a.write_csr(ioaddr, CSR3, val);
35148+ lp->a->write_csr(ioaddr, CSR3, val);
35149
35150 __napi_schedule(&lp->napi);
35151 break;
35152 }
35153- csr0 = lp->a.read_csr(ioaddr, CSR0);
35154+ csr0 = lp->a->read_csr(ioaddr, CSR0);
35155 }
35156
35157 if (netif_msg_intr(lp))
35158 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
35159- dev->name, lp->a.read_csr(ioaddr, CSR0));
35160+ dev->name, lp->a->read_csr(ioaddr, CSR0));
35161
35162 spin_unlock(&lp->lock);
35163
35164@@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_devi
35165
35166 spin_lock_irqsave(&lp->lock, flags);
35167
35168- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
35169+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
35170
35171 if (netif_msg_ifdown(lp))
35172 printk(KERN_DEBUG
35173 "%s: Shutting down ethercard, status was %2.2x.\n",
35174- dev->name, lp->a.read_csr(ioaddr, CSR0));
35175+ dev->name, lp->a->read_csr(ioaddr, CSR0));
35176
35177 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
35178- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
35179+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
35180
35181 /*
35182 * Switch back to 16bit mode to avoid problems with dumb
35183 * DOS packet driver after a warm reboot
35184 */
35185- lp->a.write_bcr(ioaddr, 20, 4);
35186+ lp->a->write_bcr(ioaddr, 20, 4);
35187
35188 spin_unlock_irqrestore(&lp->lock, flags);
35189
35190@@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_
35191 unsigned long flags;
35192
35193 spin_lock_irqsave(&lp->lock, flags);
35194- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
35195+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
35196 spin_unlock_irqrestore(&lp->lock, flags);
35197
35198 return &dev->stats;
35199@@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struc
35200 if (dev->flags & IFF_ALLMULTI) {
35201 ib->filter[0] = cpu_to_le32(~0U);
35202 ib->filter[1] = cpu_to_le32(~0U);
35203- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
35204- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
35205- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
35206- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
35207+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
35208+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
35209+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
35210+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
35211 return;
35212 }
35213 /* clear the multicast filter */
35214@@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struc
35215 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
35216 }
35217 for (i = 0; i < 4; i++)
35218- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
35219+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
35220 le16_to_cpu(mcast_table[i]));
35221 return;
35222 }
35223@@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(s
35224
35225 spin_lock_irqsave(&lp->lock, flags);
35226 suspended = pcnet32_suspend(dev, &flags, 0);
35227- csr15 = lp->a.read_csr(ioaddr, CSR15);
35228+ csr15 = lp->a->read_csr(ioaddr, CSR15);
35229 if (dev->flags & IFF_PROMISC) {
35230 /* Log any net taps. */
35231 if (netif_msg_hw(lp))
35232@@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(s
35233 lp->init_block->mode =
35234 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
35235 7);
35236- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
35237+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
35238 } else {
35239 lp->init_block->mode =
35240 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
35241- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
35242+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
35243 pcnet32_load_multicast(dev);
35244 }
35245
35246 if (suspended) {
35247 int csr5;
35248 /* clear SUSPEND (SPND) - CSR5 bit 0 */
35249- csr5 = lp->a.read_csr(ioaddr, CSR5);
35250- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
35251+ csr5 = lp->a->read_csr(ioaddr, CSR5);
35252+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
35253 } else {
35254- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
35255+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
35256 pcnet32_restart(dev, CSR0_NORMAL);
35257 netif_wake_queue(dev);
35258 }
35259@@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *
35260 if (!lp->mii)
35261 return 0;
35262
35263- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35264- val_out = lp->a.read_bcr(ioaddr, 34);
35265+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35266+ val_out = lp->a->read_bcr(ioaddr, 34);
35267
35268 return val_out;
35269 }
35270@@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device
35271 if (!lp->mii)
35272 return;
35273
35274- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35275- lp->a.write_bcr(ioaddr, 34, val);
35276+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
35277+ lp->a->write_bcr(ioaddr, 34, val);
35278 }
35279
35280 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35281@@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct n
35282 curr_link = mii_link_ok(&lp->mii_if);
35283 } else {
35284 ulong ioaddr = dev->base_addr; /* card base I/O address */
35285- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
35286+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
35287 }
35288 if (!curr_link) {
35289 if (prev_link || verbose) {
35290@@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct n
35291 (ecmd.duplex ==
35292 DUPLEX_FULL) ? "full" : "half");
35293 }
35294- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
35295+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
35296 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
35297 if (lp->mii_if.full_duplex)
35298 bcr9 |= (1 << 0);
35299 else
35300 bcr9 &= ~(1 << 0);
35301- lp->a.write_bcr(dev->base_addr, 9, bcr9);
35302+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
35303 }
35304 } else {
35305 if (netif_msg_link(lp))
35306diff -urNp linux-2.6.32.44/drivers/net/tg3.h linux-2.6.32.44/drivers/net/tg3.h
35307--- linux-2.6.32.44/drivers/net/tg3.h 2011-03-27 14:31:47.000000000 -0400
35308+++ linux-2.6.32.44/drivers/net/tg3.h 2011-04-17 15:56:46.000000000 -0400
35309@@ -95,6 +95,7 @@
35310 #define CHIPREV_ID_5750_A0 0x4000
35311 #define CHIPREV_ID_5750_A1 0x4001
35312 #define CHIPREV_ID_5750_A3 0x4003
35313+#define CHIPREV_ID_5750_C1 0x4201
35314 #define CHIPREV_ID_5750_C2 0x4202
35315 #define CHIPREV_ID_5752_A0_HW 0x5000
35316 #define CHIPREV_ID_5752_A0 0x6000
35317diff -urNp linux-2.6.32.44/drivers/net/tokenring/abyss.c linux-2.6.32.44/drivers/net/tokenring/abyss.c
35318--- linux-2.6.32.44/drivers/net/tokenring/abyss.c 2011-03-27 14:31:47.000000000 -0400
35319+++ linux-2.6.32.44/drivers/net/tokenring/abyss.c 2011-08-05 20:33:55.000000000 -0400
35320@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver =
35321
35322 static int __init abyss_init (void)
35323 {
35324- abyss_netdev_ops = tms380tr_netdev_ops;
35325+ pax_open_kernel();
35326+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35327
35328- abyss_netdev_ops.ndo_open = abyss_open;
35329- abyss_netdev_ops.ndo_stop = abyss_close;
35330+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35331+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35332+ pax_close_kernel();
35333
35334 return pci_register_driver(&abyss_driver);
35335 }
35336diff -urNp linux-2.6.32.44/drivers/net/tokenring/madgemc.c linux-2.6.32.44/drivers/net/tokenring/madgemc.c
35337--- linux-2.6.32.44/drivers/net/tokenring/madgemc.c 2011-03-27 14:31:47.000000000 -0400
35338+++ linux-2.6.32.44/drivers/net/tokenring/madgemc.c 2011-08-05 20:33:55.000000000 -0400
35339@@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver
35340
35341 static int __init madgemc_init (void)
35342 {
35343- madgemc_netdev_ops = tms380tr_netdev_ops;
35344- madgemc_netdev_ops.ndo_open = madgemc_open;
35345- madgemc_netdev_ops.ndo_stop = madgemc_close;
35346+ pax_open_kernel();
35347+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35348+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35349+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35350+ pax_close_kernel();
35351
35352 return mca_register_driver (&madgemc_driver);
35353 }
35354diff -urNp linux-2.6.32.44/drivers/net/tokenring/proteon.c linux-2.6.32.44/drivers/net/tokenring/proteon.c
35355--- linux-2.6.32.44/drivers/net/tokenring/proteon.c 2011-03-27 14:31:47.000000000 -0400
35356+++ linux-2.6.32.44/drivers/net/tokenring/proteon.c 2011-08-05 20:33:55.000000000 -0400
35357@@ -353,9 +353,11 @@ static int __init proteon_init(void)
35358 struct platform_device *pdev;
35359 int i, num = 0, err = 0;
35360
35361- proteon_netdev_ops = tms380tr_netdev_ops;
35362- proteon_netdev_ops.ndo_open = proteon_open;
35363- proteon_netdev_ops.ndo_stop = tms380tr_close;
35364+ pax_open_kernel();
35365+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35366+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35367+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35368+ pax_close_kernel();
35369
35370 err = platform_driver_register(&proteon_driver);
35371 if (err)
35372diff -urNp linux-2.6.32.44/drivers/net/tokenring/skisa.c linux-2.6.32.44/drivers/net/tokenring/skisa.c
35373--- linux-2.6.32.44/drivers/net/tokenring/skisa.c 2011-03-27 14:31:47.000000000 -0400
35374+++ linux-2.6.32.44/drivers/net/tokenring/skisa.c 2011-08-05 20:33:55.000000000 -0400
35375@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35376 struct platform_device *pdev;
35377 int i, num = 0, err = 0;
35378
35379- sk_isa_netdev_ops = tms380tr_netdev_ops;
35380- sk_isa_netdev_ops.ndo_open = sk_isa_open;
35381- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35382+ pax_open_kernel();
35383+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35384+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35385+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35386+ pax_close_kernel();
35387
35388 err = platform_driver_register(&sk_isa_driver);
35389 if (err)
35390diff -urNp linux-2.6.32.44/drivers/net/tulip/de2104x.c linux-2.6.32.44/drivers/net/tulip/de2104x.c
35391--- linux-2.6.32.44/drivers/net/tulip/de2104x.c 2011-03-27 14:31:47.000000000 -0400
35392+++ linux-2.6.32.44/drivers/net/tulip/de2104x.c 2011-05-16 21:46:57.000000000 -0400
35393@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_i
35394 struct de_srom_info_leaf *il;
35395 void *bufp;
35396
35397+ pax_track_stack();
35398+
35399 /* download entire eeprom */
35400 for (i = 0; i < DE_EEPROM_WORDS; i++)
35401 ((__le16 *)ee_data)[i] =
35402diff -urNp linux-2.6.32.44/drivers/net/tulip/de4x5.c linux-2.6.32.44/drivers/net/tulip/de4x5.c
35403--- linux-2.6.32.44/drivers/net/tulip/de4x5.c 2011-03-27 14:31:47.000000000 -0400
35404+++ linux-2.6.32.44/drivers/net/tulip/de4x5.c 2011-04-17 15:56:46.000000000 -0400
35405@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, stru
35406 for (i=0; i<ETH_ALEN; i++) {
35407 tmp.addr[i] = dev->dev_addr[i];
35408 }
35409- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35410+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35411 break;
35412
35413 case DE4X5_SET_HWADDR: /* Set the hardware address */
35414@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, stru
35415 spin_lock_irqsave(&lp->lock, flags);
35416 memcpy(&statbuf, &lp->pktStats, ioc->len);
35417 spin_unlock_irqrestore(&lp->lock, flags);
35418- if (copy_to_user(ioc->data, &statbuf, ioc->len))
35419+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35420 return -EFAULT;
35421 break;
35422 }
35423diff -urNp linux-2.6.32.44/drivers/net/usb/hso.c linux-2.6.32.44/drivers/net/usb/hso.c
35424--- linux-2.6.32.44/drivers/net/usb/hso.c 2011-03-27 14:31:47.000000000 -0400
35425+++ linux-2.6.32.44/drivers/net/usb/hso.c 2011-04-17 15:56:46.000000000 -0400
35426@@ -71,7 +71,7 @@
35427 #include <asm/byteorder.h>
35428 #include <linux/serial_core.h>
35429 #include <linux/serial.h>
35430-
35431+#include <asm/local.h>
35432
35433 #define DRIVER_VERSION "1.2"
35434 #define MOD_AUTHOR "Option Wireless"
35435@@ -258,7 +258,7 @@ struct hso_serial {
35436
35437 /* from usb_serial_port */
35438 struct tty_struct *tty;
35439- int open_count;
35440+ local_t open_count;
35441 spinlock_t serial_lock;
35442
35443 int (*write_data) (struct hso_serial *serial);
35444@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_
35445 struct urb *urb;
35446
35447 urb = serial->rx_urb[0];
35448- if (serial->open_count > 0) {
35449+ if (local_read(&serial->open_count) > 0) {
35450 count = put_rxbuf_data(urb, serial);
35451 if (count == -1)
35452 return;
35453@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_cal
35454 DUMP1(urb->transfer_buffer, urb->actual_length);
35455
35456 /* Anyone listening? */
35457- if (serial->open_count == 0)
35458+ if (local_read(&serial->open_count) == 0)
35459 return;
35460
35461 if (status == 0) {
35462@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35463 spin_unlock_irq(&serial->serial_lock);
35464
35465 /* check for port already opened, if not set the termios */
35466- serial->open_count++;
35467- if (serial->open_count == 1) {
35468+ if (local_inc_return(&serial->open_count) == 1) {
35469 tty->low_latency = 1;
35470 serial->rx_state = RX_IDLE;
35471 /* Force default termio settings */
35472@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_st
35473 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35474 if (result) {
35475 hso_stop_serial_device(serial->parent);
35476- serial->open_count--;
35477+ local_dec(&serial->open_count);
35478 kref_put(&serial->parent->ref, hso_serial_ref_free);
35479 }
35480 } else {
35481@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_
35482
35483 /* reset the rts and dtr */
35484 /* do the actual close */
35485- serial->open_count--;
35486+ local_dec(&serial->open_count);
35487
35488- if (serial->open_count <= 0) {
35489- serial->open_count = 0;
35490+ if (local_read(&serial->open_count) <= 0) {
35491+ local_set(&serial->open_count, 0);
35492 spin_lock_irq(&serial->serial_lock);
35493 if (serial->tty == tty) {
35494 serial->tty->driver_data = NULL;
35495@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struc
35496
35497 /* the actual setup */
35498 spin_lock_irqsave(&serial->serial_lock, flags);
35499- if (serial->open_count)
35500+ if (local_read(&serial->open_count))
35501 _hso_serial_set_termios(tty, old);
35502 else
35503 tty->termios = old;
35504@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35505 /* Start all serial ports */
35506 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35507 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35508- if (dev2ser(serial_table[i])->open_count) {
35509+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35510 result =
35511 hso_start_serial_device(serial_table[i], GFP_NOIO);
35512 hso_kick_transmit(dev2ser(serial_table[i]));
35513diff -urNp linux-2.6.32.44/drivers/net/vxge/vxge-config.h linux-2.6.32.44/drivers/net/vxge/vxge-config.h
35514--- linux-2.6.32.44/drivers/net/vxge/vxge-config.h 2011-03-27 14:31:47.000000000 -0400
35515+++ linux-2.6.32.44/drivers/net/vxge/vxge-config.h 2011-08-05 20:33:55.000000000 -0400
35516@@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
35517 void (*link_down)(struct __vxge_hw_device *devh);
35518 void (*crit_err)(struct __vxge_hw_device *devh,
35519 enum vxge_hw_event type, u64 ext_data);
35520-};
35521+} __no_const;
35522
35523 /*
35524 * struct __vxge_hw_blockpool_entry - Block private data structure
35525diff -urNp linux-2.6.32.44/drivers/net/vxge/vxge-main.c linux-2.6.32.44/drivers/net/vxge/vxge-main.c
35526--- linux-2.6.32.44/drivers/net/vxge/vxge-main.c 2011-03-27 14:31:47.000000000 -0400
35527+++ linux-2.6.32.44/drivers/net/vxge/vxge-main.c 2011-05-16 21:46:57.000000000 -0400
35528@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35529 struct sk_buff *completed[NR_SKB_COMPLETED];
35530 int more;
35531
35532+ pax_track_stack();
35533+
35534 do {
35535 more = 0;
35536 skb_ptr = completed;
35537@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_conf
35538 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35539 int index;
35540
35541+ pax_track_stack();
35542+
35543 /*
35544 * Filling
35545 * - itable with bucket numbers
35546diff -urNp linux-2.6.32.44/drivers/net/vxge/vxge-traffic.h linux-2.6.32.44/drivers/net/vxge/vxge-traffic.h
35547--- linux-2.6.32.44/drivers/net/vxge/vxge-traffic.h 2011-03-27 14:31:47.000000000 -0400
35548+++ linux-2.6.32.44/drivers/net/vxge/vxge-traffic.h 2011-08-05 20:33:55.000000000 -0400
35549@@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
35550 struct vxge_hw_mempool_dma *dma_object,
35551 u32 index,
35552 u32 is_last);
35553-};
35554+} __no_const;
35555
35556 void
35557 __vxge_hw_mempool_destroy(
35558diff -urNp linux-2.6.32.44/drivers/net/wan/cycx_x25.c linux-2.6.32.44/drivers/net/wan/cycx_x25.c
35559--- linux-2.6.32.44/drivers/net/wan/cycx_x25.c 2011-03-27 14:31:47.000000000 -0400
35560+++ linux-2.6.32.44/drivers/net/wan/cycx_x25.c 2011-05-16 21:46:57.000000000 -0400
35561@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned
35562 unsigned char hex[1024],
35563 * phex = hex;
35564
35565+ pax_track_stack();
35566+
35567 if (len >= (sizeof(hex) / 2))
35568 len = (sizeof(hex) / 2) - 1;
35569
35570diff -urNp linux-2.6.32.44/drivers/net/wan/hdlc_x25.c linux-2.6.32.44/drivers/net/wan/hdlc_x25.c
35571--- linux-2.6.32.44/drivers/net/wan/hdlc_x25.c 2011-03-27 14:31:47.000000000 -0400
35572+++ linux-2.6.32.44/drivers/net/wan/hdlc_x25.c 2011-08-05 20:33:55.000000000 -0400
35573@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_bu
35574
35575 static int x25_open(struct net_device *dev)
35576 {
35577- struct lapb_register_struct cb;
35578+ static struct lapb_register_struct cb = {
35579+ .connect_confirmation = x25_connected,
35580+ .connect_indication = x25_connected,
35581+ .disconnect_confirmation = x25_disconnected,
35582+ .disconnect_indication = x25_disconnected,
35583+ .data_indication = x25_data_indication,
35584+ .data_transmit = x25_data_transmit
35585+ };
35586 int result;
35587
35588- cb.connect_confirmation = x25_connected;
35589- cb.connect_indication = x25_connected;
35590- cb.disconnect_confirmation = x25_disconnected;
35591- cb.disconnect_indication = x25_disconnected;
35592- cb.data_indication = x25_data_indication;
35593- cb.data_transmit = x25_data_transmit;
35594-
35595 result = lapb_register(dev, &cb);
35596 if (result != LAPB_OK)
35597 return result;
35598diff -urNp linux-2.6.32.44/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.32.44/drivers/net/wimax/i2400m/usb-fw.c
35599--- linux-2.6.32.44/drivers/net/wimax/i2400m/usb-fw.c 2011-03-27 14:31:47.000000000 -0400
35600+++ linux-2.6.32.44/drivers/net/wimax/i2400m/usb-fw.c 2011-05-16 21:46:57.000000000 -0400
35601@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35602 int do_autopm = 1;
35603 DECLARE_COMPLETION_ONSTACK(notif_completion);
35604
35605+ pax_track_stack();
35606+
35607 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35608 i2400m, ack, ack_size);
35609 BUG_ON(_ack == i2400m->bm_ack_buf);
35610diff -urNp linux-2.6.32.44/drivers/net/wireless/airo.c linux-2.6.32.44/drivers/net/wireless/airo.c
35611--- linux-2.6.32.44/drivers/net/wireless/airo.c 2011-03-27 14:31:47.000000000 -0400
35612+++ linux-2.6.32.44/drivers/net/wireless/airo.c 2011-05-16 21:46:57.000000000 -0400
35613@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (s
35614 BSSListElement * loop_net;
35615 BSSListElement * tmp_net;
35616
35617+ pax_track_stack();
35618+
35619 /* Blow away current list of scan results */
35620 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35621 list_move_tail (&loop_net->list, &ai->network_free_list);
35622@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *
35623 WepKeyRid wkr;
35624 int rc;
35625
35626+ pax_track_stack();
35627+
35628 memset( &mySsid, 0, sizeof( mySsid ) );
35629 kfree (ai->flash);
35630 ai->flash = NULL;
35631@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct i
35632 __le32 *vals = stats.vals;
35633 int len;
35634
35635+ pax_track_stack();
35636+
35637 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35638 return -ENOMEM;
35639 data = (struct proc_data *)file->private_data;
35640@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct ino
35641 /* If doLoseSync is not 1, we won't do a Lose Sync */
35642 int doLoseSync = -1;
35643
35644+ pax_track_stack();
35645+
35646 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35647 return -ENOMEM;
35648 data = (struct proc_data *)file->private_data;
35649@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_de
35650 int i;
35651 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35652
35653+ pax_track_stack();
35654+
35655 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35656 if (!qual)
35657 return -ENOMEM;
35658@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(str
35659 CapabilityRid cap_rid;
35660 __le32 *vals = stats_rid.vals;
35661
35662+ pax_track_stack();
35663+
35664 /* Get stats out of the card */
35665 clear_bit(JOB_WSTATS, &local->jobs);
35666 if (local->power.event) {
35667diff -urNp linux-2.6.32.44/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.32.44/drivers/net/wireless/ath/ath5k/debug.c
35668--- linux-2.6.32.44/drivers/net/wireless/ath/ath5k/debug.c 2011-03-27 14:31:47.000000000 -0400
35669+++ linux-2.6.32.44/drivers/net/wireless/ath/ath5k/debug.c 2011-05-16 21:46:57.000000000 -0400
35670@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct f
35671 unsigned int v;
35672 u64 tsf;
35673
35674+ pax_track_stack();
35675+
35676 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35677 len += snprintf(buf+len, sizeof(buf)-len,
35678 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35679@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct fi
35680 unsigned int len = 0;
35681 unsigned int i;
35682
35683+ pax_track_stack();
35684+
35685 len += snprintf(buf+len, sizeof(buf)-len,
35686 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35687
35688diff -urNp linux-2.6.32.44/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.32.44/drivers/net/wireless/ath/ath9k/debug.c
35689--- linux-2.6.32.44/drivers/net/wireless/ath/ath9k/debug.c 2011-03-27 14:31:47.000000000 -0400
35690+++ linux-2.6.32.44/drivers/net/wireless/ath/ath9k/debug.c 2011-05-16 21:46:57.000000000 -0400
35691@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struc
35692 char buf[512];
35693 unsigned int len = 0;
35694
35695+ pax_track_stack();
35696+
35697 len += snprintf(buf + len, sizeof(buf) - len,
35698 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
35699 len += snprintf(buf + len, sizeof(buf) - len,
35700@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct fi
35701 int i;
35702 u8 addr[ETH_ALEN];
35703
35704+ pax_track_stack();
35705+
35706 len += snprintf(buf + len, sizeof(buf) - len,
35707 "primary: %s (%s chan=%d ht=%d)\n",
35708 wiphy_name(sc->pri_wiphy->hw->wiphy),
35709diff -urNp linux-2.6.32.44/drivers/net/wireless/b43/debugfs.c linux-2.6.32.44/drivers/net/wireless/b43/debugfs.c
35710--- linux-2.6.32.44/drivers/net/wireless/b43/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35711+++ linux-2.6.32.44/drivers/net/wireless/b43/debugfs.c 2011-04-17 15:56:46.000000000 -0400
35712@@ -43,7 +43,7 @@ static struct dentry *rootdir;
35713 struct b43_debugfs_fops {
35714 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35715 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35716- struct file_operations fops;
35717+ const struct file_operations fops;
35718 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35719 size_t file_struct_offset;
35720 };
35721diff -urNp linux-2.6.32.44/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.32.44/drivers/net/wireless/b43legacy/debugfs.c
35722--- linux-2.6.32.44/drivers/net/wireless/b43legacy/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35723+++ linux-2.6.32.44/drivers/net/wireless/b43legacy/debugfs.c 2011-04-17 15:56:46.000000000 -0400
35724@@ -44,7 +44,7 @@ static struct dentry *rootdir;
35725 struct b43legacy_debugfs_fops {
35726 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35727 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35728- struct file_operations fops;
35729+ const struct file_operations fops;
35730 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35731 size_t file_struct_offset;
35732 /* Take wl->irq_lock before calling read/write? */
35733diff -urNp linux-2.6.32.44/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.32.44/drivers/net/wireless/ipw2x00/ipw2100.c
35734--- linux-2.6.32.44/drivers/net/wireless/ipw2x00/ipw2100.c 2011-03-27 14:31:47.000000000 -0400
35735+++ linux-2.6.32.44/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-16 21:46:57.000000000 -0400
35736@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2
35737 int err;
35738 DECLARE_SSID_BUF(ssid);
35739
35740+ pax_track_stack();
35741+
35742 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35743
35744 if (ssid_len)
35745@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw210
35746 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
35747 int err;
35748
35749+ pax_track_stack();
35750+
35751 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
35752 idx, keylen, len);
35753
35754diff -urNp linux-2.6.32.44/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.32.44/drivers/net/wireless/ipw2x00/libipw_rx.c
35755--- linux-2.6.32.44/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-03-27 14:31:47.000000000 -0400
35756+++ linux-2.6.32.44/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-16 21:46:57.000000000 -0400
35757@@ -1566,6 +1566,8 @@ static void libipw_process_probe_respons
35758 unsigned long flags;
35759 DECLARE_SSID_BUF(ssid);
35760
35761+ pax_track_stack();
35762+
35763 LIBIPW_DEBUG_SCAN("'%s' (%pM"
35764 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
35765 print_ssid(ssid, info_element->data, info_element->len),
35766diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-1000.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-1000.c
35767--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-03-27 14:31:47.000000000 -0400
35768+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-04-17 15:56:46.000000000 -0400
35769@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib =
35770 },
35771 };
35772
35773-static struct iwl_ops iwl1000_ops = {
35774+static const struct iwl_ops iwl1000_ops = {
35775 .ucode = &iwl5000_ucode,
35776 .lib = &iwl1000_lib,
35777 .hcmd = &iwl5000_hcmd,
35778diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl3945-base.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl3945-base.c
35779--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl3945-base.c 2011-03-27 14:31:47.000000000 -0400
35780+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl3945-base.c 2011-08-05 20:33:55.000000000 -0400
35781@@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_
35782 */
35783 if (iwl3945_mod_params.disable_hw_scan) {
35784 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
35785- iwl3945_hw_ops.hw_scan = NULL;
35786+ pax_open_kernel();
35787+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
35788+ pax_close_kernel();
35789 }
35790
35791
35792diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-3945.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-3945.c
35793--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-03-27 14:31:47.000000000 -0400
35794+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-04-17 15:56:46.000000000 -0400
35795@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945
35796 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
35797 };
35798
35799-static struct iwl_ops iwl3945_ops = {
35800+static const struct iwl_ops iwl3945_ops = {
35801 .ucode = &iwl3945_ucode,
35802 .lib = &iwl3945_lib,
35803 .hcmd = &iwl3945_hcmd,
35804diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-4965.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-4965.c
35805--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-03-27 14:31:47.000000000 -0400
35806+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-04-17 15:56:46.000000000 -0400
35807@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib =
35808 },
35809 };
35810
35811-static struct iwl_ops iwl4965_ops = {
35812+static const struct iwl_ops iwl4965_ops = {
35813 .ucode = &iwl4965_ucode,
35814 .lib = &iwl4965_lib,
35815 .hcmd = &iwl4965_hcmd,
35816diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-5000.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-5000.c
35817--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-06-25 12:55:34.000000000 -0400
35818+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-06-25 12:56:37.000000000 -0400
35819@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib =
35820 },
35821 };
35822
35823-struct iwl_ops iwl5000_ops = {
35824+const struct iwl_ops iwl5000_ops = {
35825 .ucode = &iwl5000_ucode,
35826 .lib = &iwl5000_lib,
35827 .hcmd = &iwl5000_hcmd,
35828 .utils = &iwl5000_hcmd_utils,
35829 };
35830
35831-static struct iwl_ops iwl5150_ops = {
35832+static const struct iwl_ops iwl5150_ops = {
35833 .ucode = &iwl5000_ucode,
35834 .lib = &iwl5150_lib,
35835 .hcmd = &iwl5000_hcmd,
35836diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-6000.c
35837--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-03-27 14:31:47.000000000 -0400
35838+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-04-17 15:56:46.000000000 -0400
35839@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000
35840 .calc_rssi = iwl5000_calc_rssi,
35841 };
35842
35843-static struct iwl_ops iwl6000_ops = {
35844+static const struct iwl_ops iwl6000_ops = {
35845 .ucode = &iwl5000_ucode,
35846 .lib = &iwl6000_lib,
35847 .hcmd = &iwl5000_hcmd,
35848diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn.c
35849--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn.c 2011-03-27 14:31:47.000000000 -0400
35850+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn.c 2011-08-05 20:33:55.000000000 -0400
35851@@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev
35852 if (iwl_debug_level & IWL_DL_INFO)
35853 dev_printk(KERN_DEBUG, &(pdev->dev),
35854 "Disabling hw_scan\n");
35855- iwl_hw_ops.hw_scan = NULL;
35856+ pax_open_kernel();
35857+ *(void **)&iwl_hw_ops.hw_scan = NULL;
35858+ pax_close_kernel();
35859 }
35860
35861 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
35862diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
35863--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-03-27 14:31:47.000000000 -0400
35864+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-16 21:46:57.000000000 -0400
35865@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, s
35866 u8 active_index = 0;
35867 s32 tpt = 0;
35868
35869+ pax_track_stack();
35870+
35871 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
35872
35873 if (!ieee80211_is_data(hdr->frame_control) ||
35874@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_
35875 u8 valid_tx_ant = 0;
35876 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
35877
35878+ pax_track_stack();
35879+
35880 /* Override starting rate (index 0) if needed for debug purposes */
35881 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
35882
35883diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35884--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-03-27 14:31:47.000000000 -0400
35885+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-16 21:46:57.000000000 -0400
35886@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(str
35887 int pos = 0;
35888 const size_t bufsz = sizeof(buf);
35889
35890+ pax_track_stack();
35891+
35892 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
35893 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
35894 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
35895@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
35896 const size_t bufsz = sizeof(buf);
35897 ssize_t ret;
35898
35899+ pax_track_stack();
35900+
35901 for (i = 0; i < AC_NUM; i++) {
35902 pos += scnprintf(buf + pos, bufsz - pos,
35903 "\tcw_min\tcw_max\taifsn\ttxop\n");
35904diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debug.h
35905--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-03-27 14:31:47.000000000 -0400
35906+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-04-17 15:56:46.000000000 -0400
35907@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_pri
35908 #endif
35909
35910 #else
35911-#define IWL_DEBUG(__priv, level, fmt, args...)
35912-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
35913+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
35914+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
35915 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
35916 void *p, u32 len)
35917 {}
35918diff -urNp linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-dev.h linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-dev.h
35919--- linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-03-27 14:31:47.000000000 -0400
35920+++ linux-2.6.32.44/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-04-17 15:56:46.000000000 -0400
35921@@ -68,7 +68,7 @@ struct iwl_tx_queue;
35922
35923 /* shared structures from iwl-5000.c */
35924 extern struct iwl_mod_params iwl50_mod_params;
35925-extern struct iwl_ops iwl5000_ops;
35926+extern const struct iwl_ops iwl5000_ops;
35927 extern struct iwl_ucode_ops iwl5000_ucode;
35928 extern struct iwl_lib_ops iwl5000_lib;
35929 extern struct iwl_hcmd_ops iwl5000_hcmd;
35930diff -urNp linux-2.6.32.44/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.32.44/drivers/net/wireless/iwmc3200wifi/debugfs.c
35931--- linux-2.6.32.44/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35932+++ linux-2.6.32.44/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-16 21:46:57.000000000 -0400
35933@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
35934 int buf_len = 512;
35935 size_t len = 0;
35936
35937+ pax_track_stack();
35938+
35939 if (*ppos != 0)
35940 return 0;
35941 if (count < sizeof(buf))
35942diff -urNp linux-2.6.32.44/drivers/net/wireless/libertas/debugfs.c linux-2.6.32.44/drivers/net/wireless/libertas/debugfs.c
35943--- linux-2.6.32.44/drivers/net/wireless/libertas/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35944+++ linux-2.6.32.44/drivers/net/wireless/libertas/debugfs.c 2011-04-17 15:56:46.000000000 -0400
35945@@ -708,7 +708,7 @@ out_unlock:
35946 struct lbs_debugfs_files {
35947 const char *name;
35948 int perm;
35949- struct file_operations fops;
35950+ const struct file_operations fops;
35951 };
35952
35953 static const struct lbs_debugfs_files debugfs_files[] = {
35954diff -urNp linux-2.6.32.44/drivers/net/wireless/rndis_wlan.c linux-2.6.32.44/drivers/net/wireless/rndis_wlan.c
35955--- linux-2.6.32.44/drivers/net/wireless/rndis_wlan.c 2011-03-27 14:31:47.000000000 -0400
35956+++ linux-2.6.32.44/drivers/net/wireless/rndis_wlan.c 2011-04-17 15:56:46.000000000 -0400
35957@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbn
35958
35959 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
35960
35961- if (rts_threshold < 0 || rts_threshold > 2347)
35962+ if (rts_threshold > 2347)
35963 rts_threshold = 2347;
35964
35965 tmp = cpu_to_le32(rts_threshold);
35966diff -urNp linux-2.6.32.44/drivers/oprofile/buffer_sync.c linux-2.6.32.44/drivers/oprofile/buffer_sync.c
35967--- linux-2.6.32.44/drivers/oprofile/buffer_sync.c 2011-03-27 14:31:47.000000000 -0400
35968+++ linux-2.6.32.44/drivers/oprofile/buffer_sync.c 2011-04-17 15:56:46.000000000 -0400
35969@@ -341,7 +341,7 @@ static void add_data(struct op_entry *en
35970 if (cookie == NO_COOKIE)
35971 offset = pc;
35972 if (cookie == INVALID_COOKIE) {
35973- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35974+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35975 offset = pc;
35976 }
35977 if (cookie != last_cookie) {
35978@@ -385,14 +385,14 @@ add_sample(struct mm_struct *mm, struct
35979 /* add userspace sample */
35980
35981 if (!mm) {
35982- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35983+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35984 return 0;
35985 }
35986
35987 cookie = lookup_dcookie(mm, s->eip, &offset);
35988
35989 if (cookie == INVALID_COOKIE) {
35990- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35991+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35992 return 0;
35993 }
35994
35995@@ -561,7 +561,7 @@ void sync_buffer(int cpu)
35996 /* ignore backtraces if failed to add a sample */
35997 if (state == sb_bt_start) {
35998 state = sb_bt_ignore;
35999- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36000+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36001 }
36002 }
36003 release_mm(mm);
36004diff -urNp linux-2.6.32.44/drivers/oprofile/event_buffer.c linux-2.6.32.44/drivers/oprofile/event_buffer.c
36005--- linux-2.6.32.44/drivers/oprofile/event_buffer.c 2011-03-27 14:31:47.000000000 -0400
36006+++ linux-2.6.32.44/drivers/oprofile/event_buffer.c 2011-04-17 15:56:46.000000000 -0400
36007@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36008 }
36009
36010 if (buffer_pos == buffer_size) {
36011- atomic_inc(&oprofile_stats.event_lost_overflow);
36012+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36013 return;
36014 }
36015
36016diff -urNp linux-2.6.32.44/drivers/oprofile/oprof.c linux-2.6.32.44/drivers/oprofile/oprof.c
36017--- linux-2.6.32.44/drivers/oprofile/oprof.c 2011-03-27 14:31:47.000000000 -0400
36018+++ linux-2.6.32.44/drivers/oprofile/oprof.c 2011-04-17 15:56:46.000000000 -0400
36019@@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36020 if (oprofile_ops.switch_events())
36021 return;
36022
36023- atomic_inc(&oprofile_stats.multiplex_counter);
36024+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36025 start_switch_worker();
36026 }
36027
36028diff -urNp linux-2.6.32.44/drivers/oprofile/oprofilefs.c linux-2.6.32.44/drivers/oprofile/oprofilefs.c
36029--- linux-2.6.32.44/drivers/oprofile/oprofilefs.c 2011-03-27 14:31:47.000000000 -0400
36030+++ linux-2.6.32.44/drivers/oprofile/oprofilefs.c 2011-04-17 15:56:46.000000000 -0400
36031@@ -187,7 +187,7 @@ static const struct file_operations atom
36032
36033
36034 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36035- char const *name, atomic_t *val)
36036+ char const *name, atomic_unchecked_t *val)
36037 {
36038 struct dentry *d = __oprofilefs_create_file(sb, root, name,
36039 &atomic_ro_fops, 0444);
36040diff -urNp linux-2.6.32.44/drivers/oprofile/oprofile_stats.c linux-2.6.32.44/drivers/oprofile/oprofile_stats.c
36041--- linux-2.6.32.44/drivers/oprofile/oprofile_stats.c 2011-03-27 14:31:47.000000000 -0400
36042+++ linux-2.6.32.44/drivers/oprofile/oprofile_stats.c 2011-04-17 15:56:46.000000000 -0400
36043@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36044 cpu_buf->sample_invalid_eip = 0;
36045 }
36046
36047- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36048- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36049- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36050- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36051- atomic_set(&oprofile_stats.multiplex_counter, 0);
36052+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36053+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36054+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36055+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36056+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36057 }
36058
36059
36060diff -urNp linux-2.6.32.44/drivers/oprofile/oprofile_stats.h linux-2.6.32.44/drivers/oprofile/oprofile_stats.h
36061--- linux-2.6.32.44/drivers/oprofile/oprofile_stats.h 2011-03-27 14:31:47.000000000 -0400
36062+++ linux-2.6.32.44/drivers/oprofile/oprofile_stats.h 2011-04-17 15:56:46.000000000 -0400
36063@@ -13,11 +13,11 @@
36064 #include <asm/atomic.h>
36065
36066 struct oprofile_stat_struct {
36067- atomic_t sample_lost_no_mm;
36068- atomic_t sample_lost_no_mapping;
36069- atomic_t bt_lost_no_mapping;
36070- atomic_t event_lost_overflow;
36071- atomic_t multiplex_counter;
36072+ atomic_unchecked_t sample_lost_no_mm;
36073+ atomic_unchecked_t sample_lost_no_mapping;
36074+ atomic_unchecked_t bt_lost_no_mapping;
36075+ atomic_unchecked_t event_lost_overflow;
36076+ atomic_unchecked_t multiplex_counter;
36077 };
36078
36079 extern struct oprofile_stat_struct oprofile_stats;
36080diff -urNp linux-2.6.32.44/drivers/parisc/pdc_stable.c linux-2.6.32.44/drivers/parisc/pdc_stable.c
36081--- linux-2.6.32.44/drivers/parisc/pdc_stable.c 2011-03-27 14:31:47.000000000 -0400
36082+++ linux-2.6.32.44/drivers/parisc/pdc_stable.c 2011-04-17 15:56:46.000000000 -0400
36083@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj
36084 return ret;
36085 }
36086
36087-static struct sysfs_ops pdcspath_attr_ops = {
36088+static const struct sysfs_ops pdcspath_attr_ops = {
36089 .show = pdcspath_attr_show,
36090 .store = pdcspath_attr_store,
36091 };
36092diff -urNp linux-2.6.32.44/drivers/parport/procfs.c linux-2.6.32.44/drivers/parport/procfs.c
36093--- linux-2.6.32.44/drivers/parport/procfs.c 2011-03-27 14:31:47.000000000 -0400
36094+++ linux-2.6.32.44/drivers/parport/procfs.c 2011-04-17 15:56:46.000000000 -0400
36095@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36096
36097 *ppos += len;
36098
36099- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36100+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36101 }
36102
36103 #ifdef CONFIG_PARPORT_1284
36104@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36105
36106 *ppos += len;
36107
36108- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36109+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36110 }
36111 #endif /* IEEE1284.3 support. */
36112
36113diff -urNp linux-2.6.32.44/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.32.44/drivers/pci/hotplug/acpiphp_glue.c
36114--- linux-2.6.32.44/drivers/pci/hotplug/acpiphp_glue.c 2011-03-27 14:31:47.000000000 -0400
36115+++ linux-2.6.32.44/drivers/pci/hotplug/acpiphp_glue.c 2011-04-17 15:56:46.000000000 -0400
36116@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notif
36117 }
36118
36119
36120-static struct acpi_dock_ops acpiphp_dock_ops = {
36121+static const struct acpi_dock_ops acpiphp_dock_ops = {
36122 .handler = handle_hotplug_event_func,
36123 };
36124
36125diff -urNp linux-2.6.32.44/drivers/pci/hotplug/cpci_hotplug.h linux-2.6.32.44/drivers/pci/hotplug/cpci_hotplug.h
36126--- linux-2.6.32.44/drivers/pci/hotplug/cpci_hotplug.h 2011-03-27 14:31:47.000000000 -0400
36127+++ linux-2.6.32.44/drivers/pci/hotplug/cpci_hotplug.h 2011-08-05 20:33:55.000000000 -0400
36128@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36129 int (*hardware_test) (struct slot* slot, u32 value);
36130 u8 (*get_power) (struct slot* slot);
36131 int (*set_power) (struct slot* slot, int value);
36132-};
36133+} __no_const;
36134
36135 struct cpci_hp_controller {
36136 unsigned int irq;
36137diff -urNp linux-2.6.32.44/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.32.44/drivers/pci/hotplug/cpqphp_nvram.c
36138--- linux-2.6.32.44/drivers/pci/hotplug/cpqphp_nvram.c 2011-03-27 14:31:47.000000000 -0400
36139+++ linux-2.6.32.44/drivers/pci/hotplug/cpqphp_nvram.c 2011-04-17 15:56:46.000000000 -0400
36140@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36141
36142 void compaq_nvram_init (void __iomem *rom_start)
36143 {
36144+
36145+#ifndef CONFIG_PAX_KERNEXEC
36146 if (rom_start) {
36147 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36148 }
36149+#endif
36150+
36151 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36152
36153 /* initialize our int15 lock */
36154diff -urNp linux-2.6.32.44/drivers/pci/hotplug/fakephp.c linux-2.6.32.44/drivers/pci/hotplug/fakephp.c
36155--- linux-2.6.32.44/drivers/pci/hotplug/fakephp.c 2011-03-27 14:31:47.000000000 -0400
36156+++ linux-2.6.32.44/drivers/pci/hotplug/fakephp.c 2011-04-17 15:56:46.000000000 -0400
36157@@ -73,7 +73,7 @@ static void legacy_release(struct kobjec
36158 }
36159
36160 static struct kobj_type legacy_ktype = {
36161- .sysfs_ops = &(struct sysfs_ops){
36162+ .sysfs_ops = &(const struct sysfs_ops){
36163 .store = legacy_store, .show = legacy_show
36164 },
36165 .release = &legacy_release,
36166diff -urNp linux-2.6.32.44/drivers/pci/intel-iommu.c linux-2.6.32.44/drivers/pci/intel-iommu.c
36167--- linux-2.6.32.44/drivers/pci/intel-iommu.c 2011-05-10 22:12:01.000000000 -0400
36168+++ linux-2.6.32.44/drivers/pci/intel-iommu.c 2011-05-10 22:12:33.000000000 -0400
36169@@ -2643,7 +2643,7 @@ error:
36170 return 0;
36171 }
36172
36173-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
36174+dma_addr_t intel_map_page(struct device *dev, struct page *page,
36175 unsigned long offset, size_t size,
36176 enum dma_data_direction dir,
36177 struct dma_attrs *attrs)
36178@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain
36179 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
36180 }
36181
36182-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
36183+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
36184 size_t size, enum dma_data_direction dir,
36185 struct dma_attrs *attrs)
36186 {
36187@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct devi
36188 }
36189 }
36190
36191-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
36192+void *intel_alloc_coherent(struct device *hwdev, size_t size,
36193 dma_addr_t *dma_handle, gfp_t flags)
36194 {
36195 void *vaddr;
36196@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct
36197 return NULL;
36198 }
36199
36200-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
36201+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
36202 dma_addr_t dma_handle)
36203 {
36204 int order;
36205@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct d
36206 free_pages((unsigned long)vaddr, order);
36207 }
36208
36209-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
36210+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
36211 int nelems, enum dma_data_direction dir,
36212 struct dma_attrs *attrs)
36213 {
36214@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(str
36215 return nelems;
36216 }
36217
36218-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
36219+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
36220 enum dma_data_direction dir, struct dma_attrs *attrs)
36221 {
36222 int i;
36223@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *h
36224 return nelems;
36225 }
36226
36227-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
36228+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
36229 {
36230 return !dma_addr;
36231 }
36232
36233-struct dma_map_ops intel_dma_ops = {
36234+const struct dma_map_ops intel_dma_ops = {
36235 .alloc_coherent = intel_alloc_coherent,
36236 .free_coherent = intel_free_coherent,
36237 .map_sg = intel_map_sg,
36238diff -urNp linux-2.6.32.44/drivers/pci/pcie/aspm.c linux-2.6.32.44/drivers/pci/pcie/aspm.c
36239--- linux-2.6.32.44/drivers/pci/pcie/aspm.c 2011-03-27 14:31:47.000000000 -0400
36240+++ linux-2.6.32.44/drivers/pci/pcie/aspm.c 2011-04-17 15:56:46.000000000 -0400
36241@@ -27,9 +27,9 @@
36242 #define MODULE_PARAM_PREFIX "pcie_aspm."
36243
36244 /* Note: those are not register definitions */
36245-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36246-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36247-#define ASPM_STATE_L1 (4) /* L1 state */
36248+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36249+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36250+#define ASPM_STATE_L1 (4U) /* L1 state */
36251 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36252 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36253
36254diff -urNp linux-2.6.32.44/drivers/pci/probe.c linux-2.6.32.44/drivers/pci/probe.c
36255--- linux-2.6.32.44/drivers/pci/probe.c 2011-03-27 14:31:47.000000000 -0400
36256+++ linux-2.6.32.44/drivers/pci/probe.c 2011-04-17 15:56:46.000000000 -0400
36257@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36258 return ret;
36259 }
36260
36261-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36262+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36263 struct device_attribute *attr,
36264 char *buf)
36265 {
36266 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36267 }
36268
36269-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36270+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36271 struct device_attribute *attr,
36272 char *buf)
36273 {
36274diff -urNp linux-2.6.32.44/drivers/pci/proc.c linux-2.6.32.44/drivers/pci/proc.c
36275--- linux-2.6.32.44/drivers/pci/proc.c 2011-03-27 14:31:47.000000000 -0400
36276+++ linux-2.6.32.44/drivers/pci/proc.c 2011-04-17 15:56:46.000000000 -0400
36277@@ -480,7 +480,16 @@ static const struct file_operations proc
36278 static int __init pci_proc_init(void)
36279 {
36280 struct pci_dev *dev = NULL;
36281+
36282+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36283+#ifdef CONFIG_GRKERNSEC_PROC_USER
36284+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36285+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36286+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36287+#endif
36288+#else
36289 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36290+#endif
36291 proc_create("devices", 0, proc_bus_pci_dir,
36292 &proc_bus_pci_dev_operations);
36293 proc_initialized = 1;
36294diff -urNp linux-2.6.32.44/drivers/pci/slot.c linux-2.6.32.44/drivers/pci/slot.c
36295--- linux-2.6.32.44/drivers/pci/slot.c 2011-03-27 14:31:47.000000000 -0400
36296+++ linux-2.6.32.44/drivers/pci/slot.c 2011-04-17 15:56:46.000000000 -0400
36297@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struc
36298 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
36299 }
36300
36301-static struct sysfs_ops pci_slot_sysfs_ops = {
36302+static const struct sysfs_ops pci_slot_sysfs_ops = {
36303 .show = pci_slot_attr_show,
36304 .store = pci_slot_attr_store,
36305 };
36306diff -urNp linux-2.6.32.44/drivers/pcmcia/pcmcia_ioctl.c linux-2.6.32.44/drivers/pcmcia/pcmcia_ioctl.c
36307--- linux-2.6.32.44/drivers/pcmcia/pcmcia_ioctl.c 2011-03-27 14:31:47.000000000 -0400
36308+++ linux-2.6.32.44/drivers/pcmcia/pcmcia_ioctl.c 2011-04-17 15:56:46.000000000 -0400
36309@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode
36310 return -EFAULT;
36311 }
36312 }
36313- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
36314+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
36315 if (!buf)
36316 return -ENOMEM;
36317
36318diff -urNp linux-2.6.32.44/drivers/platform/x86/acer-wmi.c linux-2.6.32.44/drivers/platform/x86/acer-wmi.c
36319--- linux-2.6.32.44/drivers/platform/x86/acer-wmi.c 2011-03-27 14:31:47.000000000 -0400
36320+++ linux-2.6.32.44/drivers/platform/x86/acer-wmi.c 2011-04-17 15:56:46.000000000 -0400
36321@@ -918,7 +918,7 @@ static int update_bl_status(struct backl
36322 return 0;
36323 }
36324
36325-static struct backlight_ops acer_bl_ops = {
36326+static const struct backlight_ops acer_bl_ops = {
36327 .get_brightness = read_brightness,
36328 .update_status = update_bl_status,
36329 };
36330diff -urNp linux-2.6.32.44/drivers/platform/x86/asus_acpi.c linux-2.6.32.44/drivers/platform/x86/asus_acpi.c
36331--- linux-2.6.32.44/drivers/platform/x86/asus_acpi.c 2011-03-27 14:31:47.000000000 -0400
36332+++ linux-2.6.32.44/drivers/platform/x86/asus_acpi.c 2011-04-17 15:56:46.000000000 -0400
36333@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_
36334 return 0;
36335 }
36336
36337-static struct backlight_ops asus_backlight_data = {
36338+static const struct backlight_ops asus_backlight_data = {
36339 .get_brightness = read_brightness,
36340 .update_status = set_brightness_status,
36341 };
36342diff -urNp linux-2.6.32.44/drivers/platform/x86/asus-laptop.c linux-2.6.32.44/drivers/platform/x86/asus-laptop.c
36343--- linux-2.6.32.44/drivers/platform/x86/asus-laptop.c 2011-03-27 14:31:47.000000000 -0400
36344+++ linux-2.6.32.44/drivers/platform/x86/asus-laptop.c 2011-04-17 15:56:46.000000000 -0400
36345@@ -250,7 +250,7 @@ static struct backlight_device *asus_bac
36346 */
36347 static int read_brightness(struct backlight_device *bd);
36348 static int update_bl_status(struct backlight_device *bd);
36349-static struct backlight_ops asusbl_ops = {
36350+static const struct backlight_ops asusbl_ops = {
36351 .get_brightness = read_brightness,
36352 .update_status = update_bl_status,
36353 };
36354diff -urNp linux-2.6.32.44/drivers/platform/x86/compal-laptop.c linux-2.6.32.44/drivers/platform/x86/compal-laptop.c
36355--- linux-2.6.32.44/drivers/platform/x86/compal-laptop.c 2011-03-27 14:31:47.000000000 -0400
36356+++ linux-2.6.32.44/drivers/platform/x86/compal-laptop.c 2011-04-17 15:56:46.000000000 -0400
36357@@ -163,7 +163,7 @@ static int bl_update_status(struct backl
36358 return set_lcd_level(b->props.brightness);
36359 }
36360
36361-static struct backlight_ops compalbl_ops = {
36362+static const struct backlight_ops compalbl_ops = {
36363 .get_brightness = bl_get_brightness,
36364 .update_status = bl_update_status,
36365 };
36366diff -urNp linux-2.6.32.44/drivers/platform/x86/dell-laptop.c linux-2.6.32.44/drivers/platform/x86/dell-laptop.c
36367--- linux-2.6.32.44/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:01.000000000 -0400
36368+++ linux-2.6.32.44/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:33.000000000 -0400
36369@@ -318,7 +318,7 @@ static int dell_get_intensity(struct bac
36370 return buffer.output[1];
36371 }
36372
36373-static struct backlight_ops dell_ops = {
36374+static const struct backlight_ops dell_ops = {
36375 .get_brightness = dell_get_intensity,
36376 .update_status = dell_send_intensity,
36377 };
36378diff -urNp linux-2.6.32.44/drivers/platform/x86/eeepc-laptop.c linux-2.6.32.44/drivers/platform/x86/eeepc-laptop.c
36379--- linux-2.6.32.44/drivers/platform/x86/eeepc-laptop.c 2011-03-27 14:31:47.000000000 -0400
36380+++ linux-2.6.32.44/drivers/platform/x86/eeepc-laptop.c 2011-04-17 15:56:46.000000000 -0400
36381@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device
36382 */
36383 static int read_brightness(struct backlight_device *bd);
36384 static int update_bl_status(struct backlight_device *bd);
36385-static struct backlight_ops eeepcbl_ops = {
36386+static const struct backlight_ops eeepcbl_ops = {
36387 .get_brightness = read_brightness,
36388 .update_status = update_bl_status,
36389 };
36390diff -urNp linux-2.6.32.44/drivers/platform/x86/fujitsu-laptop.c linux-2.6.32.44/drivers/platform/x86/fujitsu-laptop.c
36391--- linux-2.6.32.44/drivers/platform/x86/fujitsu-laptop.c 2011-03-27 14:31:47.000000000 -0400
36392+++ linux-2.6.32.44/drivers/platform/x86/fujitsu-laptop.c 2011-04-17 15:56:46.000000000 -0400
36393@@ -436,7 +436,7 @@ static int bl_update_status(struct backl
36394 return ret;
36395 }
36396
36397-static struct backlight_ops fujitsubl_ops = {
36398+static const struct backlight_ops fujitsubl_ops = {
36399 .get_brightness = bl_get_brightness,
36400 .update_status = bl_update_status,
36401 };
36402diff -urNp linux-2.6.32.44/drivers/platform/x86/msi-laptop.c linux-2.6.32.44/drivers/platform/x86/msi-laptop.c
36403--- linux-2.6.32.44/drivers/platform/x86/msi-laptop.c 2011-03-27 14:31:47.000000000 -0400
36404+++ linux-2.6.32.44/drivers/platform/x86/msi-laptop.c 2011-04-17 15:56:46.000000000 -0400
36405@@ -161,7 +161,7 @@ static int bl_update_status(struct backl
36406 return set_lcd_level(b->props.brightness);
36407 }
36408
36409-static struct backlight_ops msibl_ops = {
36410+static const struct backlight_ops msibl_ops = {
36411 .get_brightness = bl_get_brightness,
36412 .update_status = bl_update_status,
36413 };
36414diff -urNp linux-2.6.32.44/drivers/platform/x86/panasonic-laptop.c linux-2.6.32.44/drivers/platform/x86/panasonic-laptop.c
36415--- linux-2.6.32.44/drivers/platform/x86/panasonic-laptop.c 2011-03-27 14:31:47.000000000 -0400
36416+++ linux-2.6.32.44/drivers/platform/x86/panasonic-laptop.c 2011-04-17 15:56:46.000000000 -0400
36417@@ -352,7 +352,7 @@ static int bl_set_status(struct backligh
36418 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
36419 }
36420
36421-static struct backlight_ops pcc_backlight_ops = {
36422+static const struct backlight_ops pcc_backlight_ops = {
36423 .get_brightness = bl_get,
36424 .update_status = bl_set_status,
36425 };
36426diff -urNp linux-2.6.32.44/drivers/platform/x86/sony-laptop.c linux-2.6.32.44/drivers/platform/x86/sony-laptop.c
36427--- linux-2.6.32.44/drivers/platform/x86/sony-laptop.c 2011-03-27 14:31:47.000000000 -0400
36428+++ linux-2.6.32.44/drivers/platform/x86/sony-laptop.c 2011-04-17 15:56:46.000000000 -0400
36429@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness
36430 }
36431
36432 static struct backlight_device *sony_backlight_device;
36433-static struct backlight_ops sony_backlight_ops = {
36434+static const struct backlight_ops sony_backlight_ops = {
36435 .update_status = sony_backlight_update_status,
36436 .get_brightness = sony_backlight_get_brightness,
36437 };
36438diff -urNp linux-2.6.32.44/drivers/platform/x86/thinkpad_acpi.c linux-2.6.32.44/drivers/platform/x86/thinkpad_acpi.c
36439--- linux-2.6.32.44/drivers/platform/x86/thinkpad_acpi.c 2011-03-27 14:31:47.000000000 -0400
36440+++ linux-2.6.32.44/drivers/platform/x86/thinkpad_acpi.c 2011-08-05 20:33:55.000000000 -0400
36441@@ -2137,7 +2137,7 @@ static int hotkey_mask_get(void)
36442 return 0;
36443 }
36444
36445-void static hotkey_mask_warn_incomplete_mask(void)
36446+static void hotkey_mask_warn_incomplete_mask(void)
36447 {
36448 /* log only what the user can fix... */
36449 const u32 wantedmask = hotkey_driver_mask &
36450@@ -6122,7 +6122,7 @@ static void tpacpi_brightness_notify_cha
36451 BACKLIGHT_UPDATE_HOTKEY);
36452 }
36453
36454-static struct backlight_ops ibm_backlight_data = {
36455+static const struct backlight_ops ibm_backlight_data = {
36456 .get_brightness = brightness_get,
36457 .update_status = brightness_update_status,
36458 };
36459diff -urNp linux-2.6.32.44/drivers/platform/x86/toshiba_acpi.c linux-2.6.32.44/drivers/platform/x86/toshiba_acpi.c
36460--- linux-2.6.32.44/drivers/platform/x86/toshiba_acpi.c 2011-03-27 14:31:47.000000000 -0400
36461+++ linux-2.6.32.44/drivers/platform/x86/toshiba_acpi.c 2011-04-17 15:56:46.000000000 -0400
36462@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
36463 return AE_OK;
36464 }
36465
36466-static struct backlight_ops toshiba_backlight_data = {
36467+static const struct backlight_ops toshiba_backlight_data = {
36468 .get_brightness = get_lcd,
36469 .update_status = set_lcd_status,
36470 };
36471diff -urNp linux-2.6.32.44/drivers/pnp/pnpbios/bioscalls.c linux-2.6.32.44/drivers/pnp/pnpbios/bioscalls.c
36472--- linux-2.6.32.44/drivers/pnp/pnpbios/bioscalls.c 2011-03-27 14:31:47.000000000 -0400
36473+++ linux-2.6.32.44/drivers/pnp/pnpbios/bioscalls.c 2011-04-17 15:56:46.000000000 -0400
36474@@ -60,7 +60,7 @@ do { \
36475 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36476 } while(0)
36477
36478-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36479+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36480 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36481
36482 /*
36483@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func
36484
36485 cpu = get_cpu();
36486 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36487+
36488+ pax_open_kernel();
36489 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36490+ pax_close_kernel();
36491
36492 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36493 spin_lock_irqsave(&pnp_bios_lock, flags);
36494@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func
36495 :"memory");
36496 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36497
36498+ pax_open_kernel();
36499 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36500+ pax_close_kernel();
36501+
36502 put_cpu();
36503
36504 /* If we get here and this is set then the PnP BIOS faulted on us. */
36505@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 n
36506 return status;
36507 }
36508
36509-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36510+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36511 {
36512 int i;
36513
36514@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_i
36515 pnp_bios_callpoint.offset = header->fields.pm16offset;
36516 pnp_bios_callpoint.segment = PNP_CS16;
36517
36518+ pax_open_kernel();
36519+
36520 for_each_possible_cpu(i) {
36521 struct desc_struct *gdt = get_cpu_gdt_table(i);
36522 if (!gdt)
36523@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_i
36524 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36525 (unsigned long)__va(header->fields.pm16dseg));
36526 }
36527+
36528+ pax_close_kernel();
36529 }
36530diff -urNp linux-2.6.32.44/drivers/pnp/resource.c linux-2.6.32.44/drivers/pnp/resource.c
36531--- linux-2.6.32.44/drivers/pnp/resource.c 2011-03-27 14:31:47.000000000 -0400
36532+++ linux-2.6.32.44/drivers/pnp/resource.c 2011-04-17 15:56:46.000000000 -0400
36533@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
36534 return 1;
36535
36536 /* check if the resource is valid */
36537- if (*irq < 0 || *irq > 15)
36538+ if (*irq > 15)
36539 return 0;
36540
36541 /* check if the resource is reserved */
36542@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
36543 return 1;
36544
36545 /* check if the resource is valid */
36546- if (*dma < 0 || *dma == 4 || *dma > 7)
36547+ if (*dma == 4 || *dma > 7)
36548 return 0;
36549
36550 /* check if the resource is reserved */
36551diff -urNp linux-2.6.32.44/drivers/power/bq27x00_battery.c linux-2.6.32.44/drivers/power/bq27x00_battery.c
36552--- linux-2.6.32.44/drivers/power/bq27x00_battery.c 2011-03-27 14:31:47.000000000 -0400
36553+++ linux-2.6.32.44/drivers/power/bq27x00_battery.c 2011-08-05 20:33:55.000000000 -0400
36554@@ -44,7 +44,7 @@ struct bq27x00_device_info;
36555 struct bq27x00_access_methods {
36556 int (*read)(u8 reg, int *rt_value, int b_single,
36557 struct bq27x00_device_info *di);
36558-};
36559+} __no_const;
36560
36561 struct bq27x00_device_info {
36562 struct device *dev;
36563diff -urNp linux-2.6.32.44/drivers/rtc/rtc-dev.c linux-2.6.32.44/drivers/rtc/rtc-dev.c
36564--- linux-2.6.32.44/drivers/rtc/rtc-dev.c 2011-03-27 14:31:47.000000000 -0400
36565+++ linux-2.6.32.44/drivers/rtc/rtc-dev.c 2011-04-17 15:56:46.000000000 -0400
36566@@ -14,6 +14,7 @@
36567 #include <linux/module.h>
36568 #include <linux/rtc.h>
36569 #include <linux/sched.h>
36570+#include <linux/grsecurity.h>
36571 #include "rtc-core.h"
36572
36573 static dev_t rtc_devt;
36574@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *f
36575 if (copy_from_user(&tm, uarg, sizeof(tm)))
36576 return -EFAULT;
36577
36578+ gr_log_timechange();
36579+
36580 return rtc_set_time(rtc, &tm);
36581
36582 case RTC_PIE_ON:
36583diff -urNp linux-2.6.32.44/drivers/s390/cio/qdio_perf.c linux-2.6.32.44/drivers/s390/cio/qdio_perf.c
36584--- linux-2.6.32.44/drivers/s390/cio/qdio_perf.c 2011-03-27 14:31:47.000000000 -0400
36585+++ linux-2.6.32.44/drivers/s390/cio/qdio_perf.c 2011-04-17 15:56:46.000000000 -0400
36586@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_
36587 static int qdio_perf_proc_show(struct seq_file *m, void *v)
36588 {
36589 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
36590- (long)atomic_long_read(&perf_stats.qdio_int));
36591+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
36592 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
36593- (long)atomic_long_read(&perf_stats.pci_int));
36594+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
36595 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
36596- (long)atomic_long_read(&perf_stats.thin_int));
36597+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
36598 seq_printf(m, "\n");
36599 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
36600- (long)atomic_long_read(&perf_stats.tasklet_inbound));
36601+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
36602 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
36603- (long)atomic_long_read(&perf_stats.tasklet_outbound));
36604+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
36605 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
36606- (long)atomic_long_read(&perf_stats.tasklet_thinint),
36607- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
36608+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
36609+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
36610 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
36611- (long)atomic_long_read(&perf_stats.thinint_inbound),
36612- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
36613+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
36614+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
36615 seq_printf(m, "\n");
36616 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
36617- (long)atomic_long_read(&perf_stats.siga_in));
36618+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
36619 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
36620- (long)atomic_long_read(&perf_stats.siga_out));
36621+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
36622 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
36623- (long)atomic_long_read(&perf_stats.siga_sync));
36624+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
36625 seq_printf(m, "\n");
36626 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
36627- (long)atomic_long_read(&perf_stats.inbound_handler));
36628+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
36629 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
36630- (long)atomic_long_read(&perf_stats.outbound_handler));
36631+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
36632 seq_printf(m, "\n");
36633 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
36634- (long)atomic_long_read(&perf_stats.fast_requeue));
36635+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
36636 seq_printf(m, "Number of outbound target full condition\t: %li\n",
36637- (long)atomic_long_read(&perf_stats.outbound_target_full));
36638+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
36639 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
36640- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
36641+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
36642 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
36643- (long)atomic_long_read(&perf_stats.debug_stop_polling));
36644+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
36645 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
36646- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
36647+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
36648 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
36649- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
36650- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
36651+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
36652+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
36653 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
36654- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
36655- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
36656+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
36657+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
36658 seq_printf(m, "\n");
36659 return 0;
36660 }
36661diff -urNp linux-2.6.32.44/drivers/s390/cio/qdio_perf.h linux-2.6.32.44/drivers/s390/cio/qdio_perf.h
36662--- linux-2.6.32.44/drivers/s390/cio/qdio_perf.h 2011-03-27 14:31:47.000000000 -0400
36663+++ linux-2.6.32.44/drivers/s390/cio/qdio_perf.h 2011-04-17 15:56:46.000000000 -0400
36664@@ -13,46 +13,46 @@
36665
36666 struct qdio_perf_stats {
36667 /* interrupt handler calls */
36668- atomic_long_t qdio_int;
36669- atomic_long_t pci_int;
36670- atomic_long_t thin_int;
36671+ atomic_long_unchecked_t qdio_int;
36672+ atomic_long_unchecked_t pci_int;
36673+ atomic_long_unchecked_t thin_int;
36674
36675 /* tasklet runs */
36676- atomic_long_t tasklet_inbound;
36677- atomic_long_t tasklet_outbound;
36678- atomic_long_t tasklet_thinint;
36679- atomic_long_t tasklet_thinint_loop;
36680- atomic_long_t thinint_inbound;
36681- atomic_long_t thinint_inbound_loop;
36682- atomic_long_t thinint_inbound_loop2;
36683+ atomic_long_unchecked_t tasklet_inbound;
36684+ atomic_long_unchecked_t tasklet_outbound;
36685+ atomic_long_unchecked_t tasklet_thinint;
36686+ atomic_long_unchecked_t tasklet_thinint_loop;
36687+ atomic_long_unchecked_t thinint_inbound;
36688+ atomic_long_unchecked_t thinint_inbound_loop;
36689+ atomic_long_unchecked_t thinint_inbound_loop2;
36690
36691 /* signal adapter calls */
36692- atomic_long_t siga_out;
36693- atomic_long_t siga_in;
36694- atomic_long_t siga_sync;
36695+ atomic_long_unchecked_t siga_out;
36696+ atomic_long_unchecked_t siga_in;
36697+ atomic_long_unchecked_t siga_sync;
36698
36699 /* misc */
36700- atomic_long_t inbound_handler;
36701- atomic_long_t outbound_handler;
36702- atomic_long_t fast_requeue;
36703- atomic_long_t outbound_target_full;
36704+ atomic_long_unchecked_t inbound_handler;
36705+ atomic_long_unchecked_t outbound_handler;
36706+ atomic_long_unchecked_t fast_requeue;
36707+ atomic_long_unchecked_t outbound_target_full;
36708
36709 /* for debugging */
36710- atomic_long_t debug_tl_out_timer;
36711- atomic_long_t debug_stop_polling;
36712- atomic_long_t debug_eqbs_all;
36713- atomic_long_t debug_eqbs_incomplete;
36714- atomic_long_t debug_sqbs_all;
36715- atomic_long_t debug_sqbs_incomplete;
36716+ atomic_long_unchecked_t debug_tl_out_timer;
36717+ atomic_long_unchecked_t debug_stop_polling;
36718+ atomic_long_unchecked_t debug_eqbs_all;
36719+ atomic_long_unchecked_t debug_eqbs_incomplete;
36720+ atomic_long_unchecked_t debug_sqbs_all;
36721+ atomic_long_unchecked_t debug_sqbs_incomplete;
36722 };
36723
36724 extern struct qdio_perf_stats perf_stats;
36725 extern int qdio_performance_stats;
36726
36727-static inline void qdio_perf_stat_inc(atomic_long_t *count)
36728+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
36729 {
36730 if (qdio_performance_stats)
36731- atomic_long_inc(count);
36732+ atomic_long_inc_unchecked(count);
36733 }
36734
36735 int qdio_setup_perf_stats(void);
36736diff -urNp linux-2.6.32.44/drivers/scsi/aacraid/aacraid.h linux-2.6.32.44/drivers/scsi/aacraid/aacraid.h
36737--- linux-2.6.32.44/drivers/scsi/aacraid/aacraid.h 2011-03-27 14:31:47.000000000 -0400
36738+++ linux-2.6.32.44/drivers/scsi/aacraid/aacraid.h 2011-08-05 20:33:55.000000000 -0400
36739@@ -471,7 +471,7 @@ struct adapter_ops
36740 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36741 /* Administrative operations */
36742 int (*adapter_comm)(struct aac_dev * dev, int comm);
36743-};
36744+} __no_const;
36745
36746 /*
36747 * Define which interrupt handler needs to be installed
36748diff -urNp linux-2.6.32.44/drivers/scsi/aacraid/commctrl.c linux-2.6.32.44/drivers/scsi/aacraid/commctrl.c
36749--- linux-2.6.32.44/drivers/scsi/aacraid/commctrl.c 2011-03-27 14:31:47.000000000 -0400
36750+++ linux-2.6.32.44/drivers/scsi/aacraid/commctrl.c 2011-05-16 21:46:57.000000000 -0400
36751@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_d
36752 u32 actual_fibsize64, actual_fibsize = 0;
36753 int i;
36754
36755+ pax_track_stack();
36756
36757 if (dev->in_reset) {
36758 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
36759diff -urNp linux-2.6.32.44/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.32.44/drivers/scsi/aic94xx/aic94xx_init.c
36760--- linux-2.6.32.44/drivers/scsi/aic94xx/aic94xx_init.c 2011-03-27 14:31:47.000000000 -0400
36761+++ linux-2.6.32.44/drivers/scsi/aic94xx/aic94xx_init.c 2011-04-17 15:56:46.000000000 -0400
36762@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(stru
36763 flash_error_table[i].reason);
36764 }
36765
36766-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
36767+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
36768 asd_show_update_bios, asd_store_update_bios);
36769
36770 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
36771diff -urNp linux-2.6.32.44/drivers/scsi/bfa/bfa_iocfc.h linux-2.6.32.44/drivers/scsi/bfa/bfa_iocfc.h
36772--- linux-2.6.32.44/drivers/scsi/bfa/bfa_iocfc.h 2011-03-27 14:31:47.000000000 -0400
36773+++ linux-2.6.32.44/drivers/scsi/bfa/bfa_iocfc.h 2011-08-05 20:33:55.000000000 -0400
36774@@ -61,7 +61,7 @@ struct bfa_hwif_s {
36775 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
36776 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
36777 u32 *nvecs, u32 *maxvec);
36778-};
36779+} __no_const;
36780 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36781
36782 struct bfa_iocfc_s {
36783diff -urNp linux-2.6.32.44/drivers/scsi/bfa/bfa_ioc.h linux-2.6.32.44/drivers/scsi/bfa/bfa_ioc.h
36784--- linux-2.6.32.44/drivers/scsi/bfa/bfa_ioc.h 2011-03-27 14:31:47.000000000 -0400
36785+++ linux-2.6.32.44/drivers/scsi/bfa/bfa_ioc.h 2011-08-05 20:33:55.000000000 -0400
36786@@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
36787 bfa_ioc_disable_cbfn_t disable_cbfn;
36788 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36789 bfa_ioc_reset_cbfn_t reset_cbfn;
36790-};
36791+} __no_const;
36792
36793 /**
36794 * Heartbeat failure notification queue element.
36795diff -urNp linux-2.6.32.44/drivers/scsi/BusLogic.c linux-2.6.32.44/drivers/scsi/BusLogic.c
36796--- linux-2.6.32.44/drivers/scsi/BusLogic.c 2011-03-27 14:31:47.000000000 -0400
36797+++ linux-2.6.32.44/drivers/scsi/BusLogic.c 2011-05-16 21:46:57.000000000 -0400
36798@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFla
36799 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
36800 *PrototypeHostAdapter)
36801 {
36802+ pax_track_stack();
36803+
36804 /*
36805 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
36806 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
36807diff -urNp linux-2.6.32.44/drivers/scsi/dpt_i2o.c linux-2.6.32.44/drivers/scsi/dpt_i2o.c
36808--- linux-2.6.32.44/drivers/scsi/dpt_i2o.c 2011-03-27 14:31:47.000000000 -0400
36809+++ linux-2.6.32.44/drivers/scsi/dpt_i2o.c 2011-05-16 21:46:57.000000000 -0400
36810@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* p
36811 dma_addr_t addr;
36812 ulong flags = 0;
36813
36814+ pax_track_stack();
36815+
36816 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
36817 // get user msg size in u32s
36818 if(get_user(size, &user_msg[0])){
36819@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
36820 s32 rcode;
36821 dma_addr_t addr;
36822
36823+ pax_track_stack();
36824+
36825 memset(msg, 0 , sizeof(msg));
36826 len = scsi_bufflen(cmd);
36827 direction = 0x00000000;
36828diff -urNp linux-2.6.32.44/drivers/scsi/eata.c linux-2.6.32.44/drivers/scsi/eata.c
36829--- linux-2.6.32.44/drivers/scsi/eata.c 2011-03-27 14:31:47.000000000 -0400
36830+++ linux-2.6.32.44/drivers/scsi/eata.c 2011-05-16 21:46:57.000000000 -0400
36831@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
36832 struct hostdata *ha;
36833 char name[16];
36834
36835+ pax_track_stack();
36836+
36837 sprintf(name, "%s%d", driver_name, j);
36838
36839 if (!request_region(port_base, REGION_SIZE, driver_name)) {
36840diff -urNp linux-2.6.32.44/drivers/scsi/fcoe/libfcoe.c linux-2.6.32.44/drivers/scsi/fcoe/libfcoe.c
36841--- linux-2.6.32.44/drivers/scsi/fcoe/libfcoe.c 2011-03-27 14:31:47.000000000 -0400
36842+++ linux-2.6.32.44/drivers/scsi/fcoe/libfcoe.c 2011-05-16 21:46:57.000000000 -0400
36843@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fc
36844 size_t rlen;
36845 size_t dlen;
36846
36847+ pax_track_stack();
36848+
36849 fiph = (struct fip_header *)skb->data;
36850 sub = fiph->fip_subcode;
36851 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
36852diff -urNp linux-2.6.32.44/drivers/scsi/fnic/fnic_main.c linux-2.6.32.44/drivers/scsi/fnic/fnic_main.c
36853--- linux-2.6.32.44/drivers/scsi/fnic/fnic_main.c 2011-03-27 14:31:47.000000000 -0400
36854+++ linux-2.6.32.44/drivers/scsi/fnic/fnic_main.c 2011-08-05 20:33:55.000000000 -0400
36855@@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct p
36856 /* Start local port initiatialization */
36857
36858 lp->link_up = 0;
36859- lp->tt = fnic_transport_template;
36860+ memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
36861
36862 lp->max_retry_count = fnic->config.flogi_retries;
36863 lp->max_rport_retry_count = fnic->config.plogi_retries;
36864diff -urNp linux-2.6.32.44/drivers/scsi/gdth.c linux-2.6.32.44/drivers/scsi/gdth.c
36865--- linux-2.6.32.44/drivers/scsi/gdth.c 2011-03-27 14:31:47.000000000 -0400
36866+++ linux-2.6.32.44/drivers/scsi/gdth.c 2011-05-16 21:46:57.000000000 -0400
36867@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
36868 ulong flags;
36869 gdth_ha_str *ha;
36870
36871+ pax_track_stack();
36872+
36873 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
36874 return -EFAULT;
36875 ha = gdth_find_ha(ldrv.ionode);
36876@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg
36877 gdth_ha_str *ha;
36878 int rval;
36879
36880+ pax_track_stack();
36881+
36882 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
36883 res.number >= MAX_HDRIVES)
36884 return -EFAULT;
36885@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg,
36886 gdth_ha_str *ha;
36887 int rval;
36888
36889+ pax_track_stack();
36890+
36891 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
36892 return -EFAULT;
36893 ha = gdth_find_ha(gen.ionode);
36894@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
36895 int i;
36896 gdth_cmd_str gdtcmd;
36897 char cmnd[MAX_COMMAND_SIZE];
36898+
36899+ pax_track_stack();
36900+
36901 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
36902
36903 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
36904diff -urNp linux-2.6.32.44/drivers/scsi/gdth_proc.c linux-2.6.32.44/drivers/scsi/gdth_proc.c
36905--- linux-2.6.32.44/drivers/scsi/gdth_proc.c 2011-03-27 14:31:47.000000000 -0400
36906+++ linux-2.6.32.44/drivers/scsi/gdth_proc.c 2011-05-16 21:46:57.000000000 -0400
36907@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi
36908 ulong64 paddr;
36909
36910 char cmnd[MAX_COMMAND_SIZE];
36911+
36912+ pax_track_stack();
36913+
36914 memset(cmnd, 0xff, 12);
36915 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
36916
36917@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,ch
36918 gdth_hget_str *phg;
36919 char cmnd[MAX_COMMAND_SIZE];
36920
36921+ pax_track_stack();
36922+
36923 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
36924 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
36925 if (!gdtcmd || !estr)
36926diff -urNp linux-2.6.32.44/drivers/scsi/hosts.c linux-2.6.32.44/drivers/scsi/hosts.c
36927--- linux-2.6.32.44/drivers/scsi/hosts.c 2011-03-27 14:31:47.000000000 -0400
36928+++ linux-2.6.32.44/drivers/scsi/hosts.c 2011-05-04 17:56:28.000000000 -0400
36929@@ -40,7 +40,7 @@
36930 #include "scsi_logging.h"
36931
36932
36933-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36934+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36935
36936
36937 static void scsi_host_cls_release(struct device *dev)
36938@@ -344,7 +344,7 @@ struct Scsi_Host *scsi_host_alloc(struct
36939 * subtract one because we increment first then return, but we need to
36940 * know what the next host number was before increment
36941 */
36942- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36943+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36944 shost->dma_channel = 0xff;
36945
36946 /* These three are default values which can be overridden */
36947diff -urNp linux-2.6.32.44/drivers/scsi/ipr.c linux-2.6.32.44/drivers/scsi/ipr.c
36948--- linux-2.6.32.44/drivers/scsi/ipr.c 2011-03-27 14:31:47.000000000 -0400
36949+++ linux-2.6.32.44/drivers/scsi/ipr.c 2011-04-17 15:56:46.000000000 -0400
36950@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
36951 return true;
36952 }
36953
36954-static struct ata_port_operations ipr_sata_ops = {
36955+static const struct ata_port_operations ipr_sata_ops = {
36956 .phy_reset = ipr_ata_phy_reset,
36957 .hardreset = ipr_sata_reset,
36958 .post_internal_cmd = ipr_ata_post_internal,
36959diff -urNp linux-2.6.32.44/drivers/scsi/ips.h linux-2.6.32.44/drivers/scsi/ips.h
36960--- linux-2.6.32.44/drivers/scsi/ips.h 2011-03-27 14:31:47.000000000 -0400
36961+++ linux-2.6.32.44/drivers/scsi/ips.h 2011-08-05 20:33:55.000000000 -0400
36962@@ -1027,7 +1027,7 @@ typedef struct {
36963 int (*intr)(struct ips_ha *);
36964 void (*enableint)(struct ips_ha *);
36965 uint32_t (*statupd)(struct ips_ha *);
36966-} ips_hw_func_t;
36967+} __no_const ips_hw_func_t;
36968
36969 typedef struct ips_ha {
36970 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36971diff -urNp linux-2.6.32.44/drivers/scsi/libfc/fc_disc.c linux-2.6.32.44/drivers/scsi/libfc/fc_disc.c
36972--- linux-2.6.32.44/drivers/scsi/libfc/fc_disc.c 2011-03-27 14:31:47.000000000 -0400
36973+++ linux-2.6.32.44/drivers/scsi/libfc/fc_disc.c 2011-08-05 20:33:55.000000000 -0400
36974@@ -715,16 +715,16 @@ int fc_disc_init(struct fc_lport *lport)
36975 struct fc_disc *disc;
36976
36977 if (!lport->tt.disc_start)
36978- lport->tt.disc_start = fc_disc_start;
36979+ *(void **)&lport->tt.disc_start = fc_disc_start;
36980
36981 if (!lport->tt.disc_stop)
36982- lport->tt.disc_stop = fc_disc_stop;
36983+ *(void **)&lport->tt.disc_stop = fc_disc_stop;
36984
36985 if (!lport->tt.disc_stop_final)
36986- lport->tt.disc_stop_final = fc_disc_stop_final;
36987+ *(void **)&lport->tt.disc_stop_final = fc_disc_stop_final;
36988
36989 if (!lport->tt.disc_recv_req)
36990- lport->tt.disc_recv_req = fc_disc_recv_req;
36991+ *(void **)&lport->tt.disc_recv_req = fc_disc_recv_req;
36992
36993 disc = &lport->disc;
36994 INIT_DELAYED_WORK(&disc->disc_work, fc_disc_timeout);
36995diff -urNp linux-2.6.32.44/drivers/scsi/libfc/fc_elsct.c linux-2.6.32.44/drivers/scsi/libfc/fc_elsct.c
36996--- linux-2.6.32.44/drivers/scsi/libfc/fc_elsct.c 2011-03-27 14:31:47.000000000 -0400
36997+++ linux-2.6.32.44/drivers/scsi/libfc/fc_elsct.c 2011-08-05 20:33:55.000000000 -0400
36998@@ -67,7 +67,7 @@ static struct fc_seq *fc_elsct_send(stru
36999 int fc_elsct_init(struct fc_lport *lport)
37000 {
37001 if (!lport->tt.elsct_send)
37002- lport->tt.elsct_send = fc_elsct_send;
37003+ *(void **)&lport->tt.elsct_send = fc_elsct_send;
37004
37005 return 0;
37006 }
37007diff -urNp linux-2.6.32.44/drivers/scsi/libfc/fc_exch.c linux-2.6.32.44/drivers/scsi/libfc/fc_exch.c
37008--- linux-2.6.32.44/drivers/scsi/libfc/fc_exch.c 2011-03-27 14:31:47.000000000 -0400
37009+++ linux-2.6.32.44/drivers/scsi/libfc/fc_exch.c 2011-08-05 20:33:55.000000000 -0400
37010@@ -86,12 +86,12 @@ struct fc_exch_mgr {
37011 * all together if not used XXX
37012 */
37013 struct {
37014- atomic_t no_free_exch;
37015- atomic_t no_free_exch_xid;
37016- atomic_t xid_not_found;
37017- atomic_t xid_busy;
37018- atomic_t seq_not_found;
37019- atomic_t non_bls_resp;
37020+ atomic_unchecked_t no_free_exch;
37021+ atomic_unchecked_t no_free_exch_xid;
37022+ atomic_unchecked_t xid_not_found;
37023+ atomic_unchecked_t xid_busy;
37024+ atomic_unchecked_t seq_not_found;
37025+ atomic_unchecked_t non_bls_resp;
37026 } stats;
37027 };
37028 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
37029@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(
37030 /* allocate memory for exchange */
37031 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37032 if (!ep) {
37033- atomic_inc(&mp->stats.no_free_exch);
37034+ atomic_inc_unchecked(&mp->stats.no_free_exch);
37035 goto out;
37036 }
37037 memset(ep, 0, sizeof(*ep));
37038@@ -557,7 +557,7 @@ out:
37039 return ep;
37040 err:
37041 spin_unlock_bh(&pool->lock);
37042- atomic_inc(&mp->stats.no_free_exch_xid);
37043+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37044 mempool_free(ep, mp->ep_pool);
37045 return NULL;
37046 }
37047@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37048 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37049 ep = fc_exch_find(mp, xid);
37050 if (!ep) {
37051- atomic_inc(&mp->stats.xid_not_found);
37052+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37053 reject = FC_RJT_OX_ID;
37054 goto out;
37055 }
37056@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37057 ep = fc_exch_find(mp, xid);
37058 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37059 if (ep) {
37060- atomic_inc(&mp->stats.xid_busy);
37061+ atomic_inc_unchecked(&mp->stats.xid_busy);
37062 reject = FC_RJT_RX_ID;
37063 goto rel;
37064 }
37065@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37066 }
37067 xid = ep->xid; /* get our XID */
37068 } else if (!ep) {
37069- atomic_inc(&mp->stats.xid_not_found);
37070+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37071 reject = FC_RJT_RX_ID; /* XID not found */
37072 goto out;
37073 }
37074@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_look
37075 } else {
37076 sp = &ep->seq;
37077 if (sp->id != fh->fh_seq_id) {
37078- atomic_inc(&mp->stats.seq_not_found);
37079+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37080 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
37081 goto rel;
37082 }
37083@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct
37084
37085 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37086 if (!ep) {
37087- atomic_inc(&mp->stats.xid_not_found);
37088+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37089 goto out;
37090 }
37091 if (ep->esb_stat & ESB_ST_COMPLETE) {
37092- atomic_inc(&mp->stats.xid_not_found);
37093+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37094 goto out;
37095 }
37096 if (ep->rxid == FC_XID_UNKNOWN)
37097 ep->rxid = ntohs(fh->fh_rx_id);
37098 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37099- atomic_inc(&mp->stats.xid_not_found);
37100+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37101 goto rel;
37102 }
37103 if (ep->did != ntoh24(fh->fh_s_id) &&
37104 ep->did != FC_FID_FLOGI) {
37105- atomic_inc(&mp->stats.xid_not_found);
37106+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37107 goto rel;
37108 }
37109 sof = fr_sof(fp);
37110@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct
37111 } else {
37112 sp = &ep->seq;
37113 if (sp->id != fh->fh_seq_id) {
37114- atomic_inc(&mp->stats.seq_not_found);
37115+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37116 goto rel;
37117 }
37118 }
37119@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_
37120 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37121
37122 if (!sp)
37123- atomic_inc(&mp->stats.xid_not_found);
37124+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37125 else
37126- atomic_inc(&mp->stats.non_bls_resp);
37127+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
37128
37129 fc_frame_free(fp);
37130 }
37131@@ -2027,25 +2027,25 @@ EXPORT_SYMBOL(fc_exch_recv);
37132 int fc_exch_init(struct fc_lport *lp)
37133 {
37134 if (!lp->tt.seq_start_next)
37135- lp->tt.seq_start_next = fc_seq_start_next;
37136+ *(void **)&lp->tt.seq_start_next = fc_seq_start_next;
37137
37138 if (!lp->tt.exch_seq_send)
37139- lp->tt.exch_seq_send = fc_exch_seq_send;
37140+ *(void **)&lp->tt.exch_seq_send = fc_exch_seq_send;
37141
37142 if (!lp->tt.seq_send)
37143- lp->tt.seq_send = fc_seq_send;
37144+ *(void **)&lp->tt.seq_send = fc_seq_send;
37145
37146 if (!lp->tt.seq_els_rsp_send)
37147- lp->tt.seq_els_rsp_send = fc_seq_els_rsp_send;
37148+ *(void **)&lp->tt.seq_els_rsp_send = fc_seq_els_rsp_send;
37149
37150 if (!lp->tt.exch_done)
37151- lp->tt.exch_done = fc_exch_done;
37152+ *(void **)&lp->tt.exch_done = fc_exch_done;
37153
37154 if (!lp->tt.exch_mgr_reset)
37155- lp->tt.exch_mgr_reset = fc_exch_mgr_reset;
37156+ *(void **)&lp->tt.exch_mgr_reset = fc_exch_mgr_reset;
37157
37158 if (!lp->tt.seq_exch_abort)
37159- lp->tt.seq_exch_abort = fc_seq_exch_abort;
37160+ *(void **)&lp->tt.seq_exch_abort = fc_seq_exch_abort;
37161
37162 /*
37163 * Initialize fc_cpu_mask and fc_cpu_order. The
37164diff -urNp linux-2.6.32.44/drivers/scsi/libfc/fc_fcp.c linux-2.6.32.44/drivers/scsi/libfc/fc_fcp.c
37165--- linux-2.6.32.44/drivers/scsi/libfc/fc_fcp.c 2011-03-27 14:31:47.000000000 -0400
37166+++ linux-2.6.32.44/drivers/scsi/libfc/fc_fcp.c 2011-08-05 20:33:55.000000000 -0400
37167@@ -2105,13 +2105,13 @@ int fc_fcp_init(struct fc_lport *lp)
37168 struct fc_fcp_internal *si;
37169
37170 if (!lp->tt.fcp_cmd_send)
37171- lp->tt.fcp_cmd_send = fc_fcp_cmd_send;
37172+ *(void **)&lp->tt.fcp_cmd_send = fc_fcp_cmd_send;
37173
37174 if (!lp->tt.fcp_cleanup)
37175- lp->tt.fcp_cleanup = fc_fcp_cleanup;
37176+ *(void **)&lp->tt.fcp_cleanup = fc_fcp_cleanup;
37177
37178 if (!lp->tt.fcp_abort_io)
37179- lp->tt.fcp_abort_io = fc_fcp_abort_io;
37180+ *(void **)&lp->tt.fcp_abort_io = fc_fcp_abort_io;
37181
37182 si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL);
37183 if (!si)
37184diff -urNp linux-2.6.32.44/drivers/scsi/libfc/fc_lport.c linux-2.6.32.44/drivers/scsi/libfc/fc_lport.c
37185--- linux-2.6.32.44/drivers/scsi/libfc/fc_lport.c 2011-03-27 14:31:47.000000000 -0400
37186+++ linux-2.6.32.44/drivers/scsi/libfc/fc_lport.c 2011-08-05 20:33:55.000000000 -0400
37187@@ -569,7 +569,7 @@ int fc_lport_destroy(struct fc_lport *lp
37188 mutex_lock(&lport->lp_mutex);
37189 lport->state = LPORT_ST_DISABLED;
37190 lport->link_up = 0;
37191- lport->tt.frame_send = fc_frame_drop;
37192+ *(void **)&lport->tt.frame_send = fc_frame_drop;
37193 mutex_unlock(&lport->lp_mutex);
37194
37195 lport->tt.fcp_abort_io(lport);
37196@@ -1477,10 +1477,10 @@ EXPORT_SYMBOL(fc_lport_config);
37197 int fc_lport_init(struct fc_lport *lport)
37198 {
37199 if (!lport->tt.lport_recv)
37200- lport->tt.lport_recv = fc_lport_recv_req;
37201+ *(void **)&lport->tt.lport_recv = fc_lport_recv_req;
37202
37203 if (!lport->tt.lport_reset)
37204- lport->tt.lport_reset = fc_lport_reset;
37205+ *(void **)&lport->tt.lport_reset = fc_lport_reset;
37206
37207 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
37208 fc_host_node_name(lport->host) = lport->wwnn;
37209diff -urNp linux-2.6.32.44/drivers/scsi/libfc/fc_rport.c linux-2.6.32.44/drivers/scsi/libfc/fc_rport.c
37210--- linux-2.6.32.44/drivers/scsi/libfc/fc_rport.c 2011-03-27 14:31:47.000000000 -0400
37211+++ linux-2.6.32.44/drivers/scsi/libfc/fc_rport.c 2011-08-05 20:33:55.000000000 -0400
37212@@ -1566,25 +1566,25 @@ static void fc_rport_flush_queue(void)
37213 int fc_rport_init(struct fc_lport *lport)
37214 {
37215 if (!lport->tt.rport_lookup)
37216- lport->tt.rport_lookup = fc_rport_lookup;
37217+ *(void **)&lport->tt.rport_lookup = fc_rport_lookup;
37218
37219 if (!lport->tt.rport_create)
37220- lport->tt.rport_create = fc_rport_create;
37221+ *(void **)&lport->tt.rport_create = fc_rport_create;
37222
37223 if (!lport->tt.rport_login)
37224- lport->tt.rport_login = fc_rport_login;
37225+ *(void **)&lport->tt.rport_login = fc_rport_login;
37226
37227 if (!lport->tt.rport_logoff)
37228- lport->tt.rport_logoff = fc_rport_logoff;
37229+ *(void **)&lport->tt.rport_logoff = fc_rport_logoff;
37230
37231 if (!lport->tt.rport_recv_req)
37232- lport->tt.rport_recv_req = fc_rport_recv_req;
37233+ *(void **)&lport->tt.rport_recv_req = fc_rport_recv_req;
37234
37235 if (!lport->tt.rport_flush_queue)
37236- lport->tt.rport_flush_queue = fc_rport_flush_queue;
37237+ *(void **)&lport->tt.rport_flush_queue = fc_rport_flush_queue;
37238
37239 if (!lport->tt.rport_destroy)
37240- lport->tt.rport_destroy = fc_rport_destroy;
37241+ *(void **)&lport->tt.rport_destroy = fc_rport_destroy;
37242
37243 return 0;
37244 }
37245diff -urNp linux-2.6.32.44/drivers/scsi/libsas/sas_ata.c linux-2.6.32.44/drivers/scsi/libsas/sas_ata.c
37246--- linux-2.6.32.44/drivers/scsi/libsas/sas_ata.c 2011-03-27 14:31:47.000000000 -0400
37247+++ linux-2.6.32.44/drivers/scsi/libsas/sas_ata.c 2011-04-23 12:56:11.000000000 -0400
37248@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_l
37249 }
37250 }
37251
37252-static struct ata_port_operations sas_sata_ops = {
37253+static const struct ata_port_operations sas_sata_ops = {
37254 .phy_reset = sas_ata_phy_reset,
37255 .post_internal_cmd = sas_ata_post_internal,
37256 .qc_defer = ata_std_qc_defer,
37257diff -urNp linux-2.6.32.44/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.32.44/drivers/scsi/lpfc/lpfc_debugfs.c
37258--- linux-2.6.32.44/drivers/scsi/lpfc/lpfc_debugfs.c 2011-03-27 14:31:47.000000000 -0400
37259+++ linux-2.6.32.44/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-16 21:46:57.000000000 -0400
37260@@ -124,7 +124,7 @@ struct lpfc_debug {
37261 int len;
37262 };
37263
37264-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37265+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37266 static unsigned long lpfc_debugfs_start_time = 0L;
37267
37268 /**
37269@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
37270 lpfc_debugfs_enable = 0;
37271
37272 len = 0;
37273- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37274+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37275 (lpfc_debugfs_max_disc_trc - 1);
37276 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37277 dtp = vport->disc_trc + i;
37278@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
37279 lpfc_debugfs_enable = 0;
37280
37281 len = 0;
37282- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37283+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37284 (lpfc_debugfs_max_slow_ring_trc - 1);
37285 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37286 dtp = phba->slow_ring_trc + i;
37287@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
37288 uint32_t *ptr;
37289 char buffer[1024];
37290
37291+ pax_track_stack();
37292+
37293 off = 0;
37294 spin_lock_irq(&phba->hbalock);
37295
37296@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
37297 !vport || !vport->disc_trc)
37298 return;
37299
37300- index = atomic_inc_return(&vport->disc_trc_cnt) &
37301+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37302 (lpfc_debugfs_max_disc_trc - 1);
37303 dtp = vport->disc_trc + index;
37304 dtp->fmt = fmt;
37305 dtp->data1 = data1;
37306 dtp->data2 = data2;
37307 dtp->data3 = data3;
37308- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37309+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37310 dtp->jif = jiffies;
37311 #endif
37312 return;
37313@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
37314 !phba || !phba->slow_ring_trc)
37315 return;
37316
37317- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37318+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37319 (lpfc_debugfs_max_slow_ring_trc - 1);
37320 dtp = phba->slow_ring_trc + index;
37321 dtp->fmt = fmt;
37322 dtp->data1 = data1;
37323 dtp->data2 = data2;
37324 dtp->data3 = data3;
37325- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37326+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37327 dtp->jif = jiffies;
37328 #endif
37329 return;
37330@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
37331 "slow_ring buffer\n");
37332 goto debug_failed;
37333 }
37334- atomic_set(&phba->slow_ring_trc_cnt, 0);
37335+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37336 memset(phba->slow_ring_trc, 0,
37337 (sizeof(struct lpfc_debugfs_trc) *
37338 lpfc_debugfs_max_slow_ring_trc));
37339@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
37340 "buffer\n");
37341 goto debug_failed;
37342 }
37343- atomic_set(&vport->disc_trc_cnt, 0);
37344+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37345
37346 snprintf(name, sizeof(name), "discovery_trace");
37347 vport->debug_disc_trc =
37348diff -urNp linux-2.6.32.44/drivers/scsi/lpfc/lpfc.h linux-2.6.32.44/drivers/scsi/lpfc/lpfc.h
37349--- linux-2.6.32.44/drivers/scsi/lpfc/lpfc.h 2011-03-27 14:31:47.000000000 -0400
37350+++ linux-2.6.32.44/drivers/scsi/lpfc/lpfc.h 2011-05-04 17:56:28.000000000 -0400
37351@@ -400,7 +400,7 @@ struct lpfc_vport {
37352 struct dentry *debug_nodelist;
37353 struct dentry *vport_debugfs_root;
37354 struct lpfc_debugfs_trc *disc_trc;
37355- atomic_t disc_trc_cnt;
37356+ atomic_unchecked_t disc_trc_cnt;
37357 #endif
37358 uint8_t stat_data_enabled;
37359 uint8_t stat_data_blocked;
37360@@ -725,8 +725,8 @@ struct lpfc_hba {
37361 struct timer_list fabric_block_timer;
37362 unsigned long bit_flags;
37363 #define FABRIC_COMANDS_BLOCKED 0
37364- atomic_t num_rsrc_err;
37365- atomic_t num_cmd_success;
37366+ atomic_unchecked_t num_rsrc_err;
37367+ atomic_unchecked_t num_cmd_success;
37368 unsigned long last_rsrc_error_time;
37369 unsigned long last_ramp_down_time;
37370 unsigned long last_ramp_up_time;
37371@@ -740,7 +740,7 @@ struct lpfc_hba {
37372 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
37373 struct dentry *debug_slow_ring_trc;
37374 struct lpfc_debugfs_trc *slow_ring_trc;
37375- atomic_t slow_ring_trc_cnt;
37376+ atomic_unchecked_t slow_ring_trc_cnt;
37377 #endif
37378
37379 /* Used for deferred freeing of ELS data buffers */
37380diff -urNp linux-2.6.32.44/drivers/scsi/lpfc/lpfc_init.c linux-2.6.32.44/drivers/scsi/lpfc/lpfc_init.c
37381--- linux-2.6.32.44/drivers/scsi/lpfc/lpfc_init.c 2011-03-27 14:31:47.000000000 -0400
37382+++ linux-2.6.32.44/drivers/scsi/lpfc/lpfc_init.c 2011-08-05 20:33:55.000000000 -0400
37383@@ -8021,8 +8021,10 @@ lpfc_init(void)
37384 printk(LPFC_COPYRIGHT "\n");
37385
37386 if (lpfc_enable_npiv) {
37387- lpfc_transport_functions.vport_create = lpfc_vport_create;
37388- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37389+ pax_open_kernel();
37390+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37391+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37392+ pax_close_kernel();
37393 }
37394 lpfc_transport_template =
37395 fc_attach_transport(&lpfc_transport_functions);
37396diff -urNp linux-2.6.32.44/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.32.44/drivers/scsi/lpfc/lpfc_scsi.c
37397--- linux-2.6.32.44/drivers/scsi/lpfc/lpfc_scsi.c 2011-03-27 14:31:47.000000000 -0400
37398+++ linux-2.6.32.44/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-04 17:56:28.000000000 -0400
37399@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
37400 uint32_t evt_posted;
37401
37402 spin_lock_irqsave(&phba->hbalock, flags);
37403- atomic_inc(&phba->num_rsrc_err);
37404+ atomic_inc_unchecked(&phba->num_rsrc_err);
37405 phba->last_rsrc_error_time = jiffies;
37406
37407 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37408@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
37409 unsigned long flags;
37410 struct lpfc_hba *phba = vport->phba;
37411 uint32_t evt_posted;
37412- atomic_inc(&phba->num_cmd_success);
37413+ atomic_inc_unchecked(&phba->num_cmd_success);
37414
37415 if (vport->cfg_lun_queue_depth <= queue_depth)
37416 return;
37417@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
37418 int i;
37419 struct lpfc_rport_data *rdata;
37420
37421- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37422- num_cmd_success = atomic_read(&phba->num_cmd_success);
37423+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37424+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37425
37426 vports = lpfc_create_vport_work_array(phba);
37427 if (vports != NULL)
37428@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
37429 }
37430 }
37431 lpfc_destroy_vport_work_array(phba, vports);
37432- atomic_set(&phba->num_rsrc_err, 0);
37433- atomic_set(&phba->num_cmd_success, 0);
37434+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37435+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37436 }
37437
37438 /**
37439@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
37440 }
37441 }
37442 lpfc_destroy_vport_work_array(phba, vports);
37443- atomic_set(&phba->num_rsrc_err, 0);
37444- atomic_set(&phba->num_cmd_success, 0);
37445+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37446+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37447 }
37448
37449 /**
37450diff -urNp linux-2.6.32.44/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.32.44/drivers/scsi/megaraid/megaraid_mbox.c
37451--- linux-2.6.32.44/drivers/scsi/megaraid/megaraid_mbox.c 2011-03-27 14:31:47.000000000 -0400
37452+++ linux-2.6.32.44/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-16 21:46:57.000000000 -0400
37453@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter
37454 int rval;
37455 int i;
37456
37457+ pax_track_stack();
37458+
37459 // Allocate memory for the base list of scb for management module.
37460 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
37461
37462diff -urNp linux-2.6.32.44/drivers/scsi/osd/osd_initiator.c linux-2.6.32.44/drivers/scsi/osd/osd_initiator.c
37463--- linux-2.6.32.44/drivers/scsi/osd/osd_initiator.c 2011-03-27 14:31:47.000000000 -0400
37464+++ linux-2.6.32.44/drivers/scsi/osd/osd_initiator.c 2011-05-16 21:46:57.000000000 -0400
37465@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct
37466 int nelem = ARRAY_SIZE(get_attrs), a = 0;
37467 int ret;
37468
37469+ pax_track_stack();
37470+
37471 or = osd_start_request(od, GFP_KERNEL);
37472 if (!or)
37473 return -ENOMEM;
37474diff -urNp linux-2.6.32.44/drivers/scsi/pmcraid.c linux-2.6.32.44/drivers/scsi/pmcraid.c
37475--- linux-2.6.32.44/drivers/scsi/pmcraid.c 2011-08-09 18:35:29.000000000 -0400
37476+++ linux-2.6.32.44/drivers/scsi/pmcraid.c 2011-08-09 18:33:59.000000000 -0400
37477@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct sc
37478 res->scsi_dev = scsi_dev;
37479 scsi_dev->hostdata = res;
37480 res->change_detected = 0;
37481- atomic_set(&res->read_failures, 0);
37482- atomic_set(&res->write_failures, 0);
37483+ atomic_set_unchecked(&res->read_failures, 0);
37484+ atomic_set_unchecked(&res->write_failures, 0);
37485 rc = 0;
37486 }
37487 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37488@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct
37489
37490 /* If this was a SCSI read/write command keep count of errors */
37491 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37492- atomic_inc(&res->read_failures);
37493+ atomic_inc_unchecked(&res->read_failures);
37494 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37495- atomic_inc(&res->write_failures);
37496+ atomic_inc_unchecked(&res->write_failures);
37497
37498 if (!RES_IS_GSCSI(res->cfg_entry) &&
37499 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37500@@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(stru
37501
37502 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37503 /* add resources only after host is added into system */
37504- if (!atomic_read(&pinstance->expose_resources))
37505+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37506 return;
37507
37508 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
37509@@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instan
37510 init_waitqueue_head(&pinstance->reset_wait_q);
37511
37512 atomic_set(&pinstance->outstanding_cmds, 0);
37513- atomic_set(&pinstance->expose_resources, 0);
37514+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37515
37516 INIT_LIST_HEAD(&pinstance->free_res_q);
37517 INIT_LIST_HEAD(&pinstance->used_res_q);
37518@@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
37519 /* Schedule worker thread to handle CCN and take care of adding and
37520 * removing devices to OS
37521 */
37522- atomic_set(&pinstance->expose_resources, 1);
37523+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37524 schedule_work(&pinstance->worker_q);
37525 return rc;
37526
37527diff -urNp linux-2.6.32.44/drivers/scsi/pmcraid.h linux-2.6.32.44/drivers/scsi/pmcraid.h
37528--- linux-2.6.32.44/drivers/scsi/pmcraid.h 2011-03-27 14:31:47.000000000 -0400
37529+++ linux-2.6.32.44/drivers/scsi/pmcraid.h 2011-05-04 17:56:28.000000000 -0400
37530@@ -690,7 +690,7 @@ struct pmcraid_instance {
37531 atomic_t outstanding_cmds;
37532
37533 /* should add/delete resources to mid-layer now ?*/
37534- atomic_t expose_resources;
37535+ atomic_unchecked_t expose_resources;
37536
37537 /* Tasklet to handle deferred processing */
37538 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
37539@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
37540 struct list_head queue; /* link to "to be exposed" resources */
37541 struct pmcraid_config_table_entry cfg_entry;
37542 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37543- atomic_t read_failures; /* count of failed READ commands */
37544- atomic_t write_failures; /* count of failed WRITE commands */
37545+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37546+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37547
37548 /* To indicate add/delete/modify during CCN */
37549 u8 change_detected;
37550diff -urNp linux-2.6.32.44/drivers/scsi/qla2xxx/qla_def.h linux-2.6.32.44/drivers/scsi/qla2xxx/qla_def.h
37551--- linux-2.6.32.44/drivers/scsi/qla2xxx/qla_def.h 2011-03-27 14:31:47.000000000 -0400
37552+++ linux-2.6.32.44/drivers/scsi/qla2xxx/qla_def.h 2011-08-05 20:33:55.000000000 -0400
37553@@ -2089,7 +2089,7 @@ struct isp_operations {
37554
37555 int (*get_flash_version) (struct scsi_qla_host *, void *);
37556 int (*start_scsi) (srb_t *);
37557-};
37558+} __no_const;
37559
37560 /* MSI-X Support *************************************************************/
37561
37562diff -urNp linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_def.h
37563--- linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_def.h 2011-03-27 14:31:47.000000000 -0400
37564+++ linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_def.h 2011-05-04 17:56:28.000000000 -0400
37565@@ -240,7 +240,7 @@ struct ddb_entry {
37566 atomic_t retry_relogin_timer; /* Min Time between relogins
37567 * (4000 only) */
37568 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
37569- atomic_t relogin_retry_count; /* Num of times relogin has been
37570+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37571 * retried */
37572
37573 uint16_t port;
37574diff -urNp linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_init.c
37575--- linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_init.c 2011-03-27 14:31:47.000000000 -0400
37576+++ linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_init.c 2011-05-04 17:56:28.000000000 -0400
37577@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_
37578 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
37579 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37580 atomic_set(&ddb_entry->relogin_timer, 0);
37581- atomic_set(&ddb_entry->relogin_retry_count, 0);
37582+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37583 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
37584 list_add_tail(&ddb_entry->list, &ha->ddb_list);
37585 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
37586@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct s
37587 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
37588 atomic_set(&ddb_entry->port_down_timer,
37589 ha->port_down_retry_count);
37590- atomic_set(&ddb_entry->relogin_retry_count, 0);
37591+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37592 atomic_set(&ddb_entry->relogin_timer, 0);
37593 clear_bit(DF_RELOGIN, &ddb_entry->flags);
37594 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
37595diff -urNp linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_os.c
37596--- linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_os.c 2011-03-27 14:31:47.000000000 -0400
37597+++ linux-2.6.32.44/drivers/scsi/qla4xxx/ql4_os.c 2011-05-04 17:56:28.000000000 -0400
37598@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_ql
37599 ddb_entry->fw_ddb_device_state ==
37600 DDB_DS_SESSION_FAILED) {
37601 /* Reset retry relogin timer */
37602- atomic_inc(&ddb_entry->relogin_retry_count);
37603+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37604 DEBUG2(printk("scsi%ld: index[%d] relogin"
37605 " timed out-retrying"
37606 " relogin (%d)\n",
37607 ha->host_no,
37608 ddb_entry->fw_ddb_index,
37609- atomic_read(&ddb_entry->
37610+ atomic_read_unchecked(&ddb_entry->
37611 relogin_retry_count))
37612 );
37613 start_dpc++;
37614diff -urNp linux-2.6.32.44/drivers/scsi/scsi.c linux-2.6.32.44/drivers/scsi/scsi.c
37615--- linux-2.6.32.44/drivers/scsi/scsi.c 2011-03-27 14:31:47.000000000 -0400
37616+++ linux-2.6.32.44/drivers/scsi/scsi.c 2011-05-04 17:56:28.000000000 -0400
37617@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
37618 unsigned long timeout;
37619 int rtn = 0;
37620
37621- atomic_inc(&cmd->device->iorequest_cnt);
37622+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37623
37624 /* check if the device is still usable */
37625 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37626diff -urNp linux-2.6.32.44/drivers/scsi/scsi_debug.c linux-2.6.32.44/drivers/scsi/scsi_debug.c
37627--- linux-2.6.32.44/drivers/scsi/scsi_debug.c 2011-03-27 14:31:47.000000000 -0400
37628+++ linux-2.6.32.44/drivers/scsi/scsi_debug.c 2011-05-16 21:46:57.000000000 -0400
37629@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_
37630 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
37631 unsigned char *cmd = (unsigned char *)scp->cmnd;
37632
37633+ pax_track_stack();
37634+
37635 if ((errsts = check_readiness(scp, 1, devip)))
37636 return errsts;
37637 memset(arr, 0, sizeof(arr));
37638@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cm
37639 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
37640 unsigned char *cmd = (unsigned char *)scp->cmnd;
37641
37642+ pax_track_stack();
37643+
37644 if ((errsts = check_readiness(scp, 1, devip)))
37645 return errsts;
37646 memset(arr, 0, sizeof(arr));
37647diff -urNp linux-2.6.32.44/drivers/scsi/scsi_lib.c linux-2.6.32.44/drivers/scsi/scsi_lib.c
37648--- linux-2.6.32.44/drivers/scsi/scsi_lib.c 2011-05-10 22:12:01.000000000 -0400
37649+++ linux-2.6.32.44/drivers/scsi/scsi_lib.c 2011-05-10 22:12:33.000000000 -0400
37650@@ -1384,7 +1384,7 @@ static void scsi_kill_request(struct req
37651
37652 scsi_init_cmd_errh(cmd);
37653 cmd->result = DID_NO_CONNECT << 16;
37654- atomic_inc(&cmd->device->iorequest_cnt);
37655+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37656
37657 /*
37658 * SCSI request completion path will do scsi_device_unbusy(),
37659@@ -1415,9 +1415,9 @@ static void scsi_softirq_done(struct req
37660 */
37661 cmd->serial_number = 0;
37662
37663- atomic_inc(&cmd->device->iodone_cnt);
37664+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37665 if (cmd->result)
37666- atomic_inc(&cmd->device->ioerr_cnt);
37667+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37668
37669 disposition = scsi_decide_disposition(cmd);
37670 if (disposition != SUCCESS &&
37671diff -urNp linux-2.6.32.44/drivers/scsi/scsi_sysfs.c linux-2.6.32.44/drivers/scsi/scsi_sysfs.c
37672--- linux-2.6.32.44/drivers/scsi/scsi_sysfs.c 2011-06-25 12:55:34.000000000 -0400
37673+++ linux-2.6.32.44/drivers/scsi/scsi_sysfs.c 2011-06-25 12:56:37.000000000 -0400
37674@@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev,
37675 char *buf) \
37676 { \
37677 struct scsi_device *sdev = to_scsi_device(dev); \
37678- unsigned long long count = atomic_read(&sdev->field); \
37679+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37680 return snprintf(buf, 20, "0x%llx\n", count); \
37681 } \
37682 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37683diff -urNp linux-2.6.32.44/drivers/scsi/scsi_transport_fc.c linux-2.6.32.44/drivers/scsi/scsi_transport_fc.c
37684--- linux-2.6.32.44/drivers/scsi/scsi_transport_fc.c 2011-03-27 14:31:47.000000000 -0400
37685+++ linux-2.6.32.44/drivers/scsi/scsi_transport_fc.c 2011-05-04 17:56:28.000000000 -0400
37686@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
37687 * Netlink Infrastructure
37688 */
37689
37690-static atomic_t fc_event_seq;
37691+static atomic_unchecked_t fc_event_seq;
37692
37693 /**
37694 * fc_get_event_number - Obtain the next sequential FC event number
37695@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
37696 u32
37697 fc_get_event_number(void)
37698 {
37699- return atomic_add_return(1, &fc_event_seq);
37700+ return atomic_add_return_unchecked(1, &fc_event_seq);
37701 }
37702 EXPORT_SYMBOL(fc_get_event_number);
37703
37704@@ -641,7 +641,7 @@ static __init int fc_transport_init(void
37705 {
37706 int error;
37707
37708- atomic_set(&fc_event_seq, 0);
37709+ atomic_set_unchecked(&fc_event_seq, 0);
37710
37711 error = transport_class_register(&fc_host_class);
37712 if (error)
37713diff -urNp linux-2.6.32.44/drivers/scsi/scsi_transport_iscsi.c linux-2.6.32.44/drivers/scsi/scsi_transport_iscsi.c
37714--- linux-2.6.32.44/drivers/scsi/scsi_transport_iscsi.c 2011-03-27 14:31:47.000000000 -0400
37715+++ linux-2.6.32.44/drivers/scsi/scsi_transport_iscsi.c 2011-05-04 17:56:28.000000000 -0400
37716@@ -81,7 +81,7 @@ struct iscsi_internal {
37717 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
37718 };
37719
37720-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37721+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37722 static struct workqueue_struct *iscsi_eh_timer_workq;
37723
37724 /*
37725@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_s
37726 int err;
37727
37728 ihost = shost->shost_data;
37729- session->sid = atomic_add_return(1, &iscsi_session_nr);
37730+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37731
37732 if (id == ISCSI_MAX_TARGET) {
37733 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
37734@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(v
37735 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37736 ISCSI_TRANSPORT_VERSION);
37737
37738- atomic_set(&iscsi_session_nr, 0);
37739+ atomic_set_unchecked(&iscsi_session_nr, 0);
37740
37741 err = class_register(&iscsi_transport_class);
37742 if (err)
37743diff -urNp linux-2.6.32.44/drivers/scsi/scsi_transport_srp.c linux-2.6.32.44/drivers/scsi/scsi_transport_srp.c
37744--- linux-2.6.32.44/drivers/scsi/scsi_transport_srp.c 2011-03-27 14:31:47.000000000 -0400
37745+++ linux-2.6.32.44/drivers/scsi/scsi_transport_srp.c 2011-05-04 17:56:28.000000000 -0400
37746@@ -33,7 +33,7 @@
37747 #include "scsi_transport_srp_internal.h"
37748
37749 struct srp_host_attrs {
37750- atomic_t next_port_id;
37751+ atomic_unchecked_t next_port_id;
37752 };
37753 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37754
37755@@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
37756 struct Scsi_Host *shost = dev_to_shost(dev);
37757 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37758
37759- atomic_set(&srp_host->next_port_id, 0);
37760+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37761 return 0;
37762 }
37763
37764@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
37765 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37766 rport->roles = ids->roles;
37767
37768- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37769+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37770 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37771
37772 transport_setup_device(&rport->dev);
37773diff -urNp linux-2.6.32.44/drivers/scsi/sg.c linux-2.6.32.44/drivers/scsi/sg.c
37774--- linux-2.6.32.44/drivers/scsi/sg.c 2011-03-27 14:31:47.000000000 -0400
37775+++ linux-2.6.32.44/drivers/scsi/sg.c 2011-04-17 15:56:46.000000000 -0400
37776@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
37777 const struct file_operations * fops;
37778 };
37779
37780-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37781+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37782 {"allow_dio", &adio_fops},
37783 {"debug", &debug_fops},
37784 {"def_reserved_size", &dressz_fops},
37785@@ -2307,7 +2307,7 @@ sg_proc_init(void)
37786 {
37787 int k, mask;
37788 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
37789- struct sg_proc_leaf * leaf;
37790+ const struct sg_proc_leaf * leaf;
37791
37792 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
37793 if (!sg_proc_sgp)
37794diff -urNp linux-2.6.32.44/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.32.44/drivers/scsi/sym53c8xx_2/sym_glue.c
37795--- linux-2.6.32.44/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-03-27 14:31:47.000000000 -0400
37796+++ linux-2.6.32.44/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-16 21:46:57.000000000 -0400
37797@@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct p
37798 int do_iounmap = 0;
37799 int do_disable_device = 1;
37800
37801+ pax_track_stack();
37802+
37803 memset(&sym_dev, 0, sizeof(sym_dev));
37804 memset(&nvram, 0, sizeof(nvram));
37805 sym_dev.pdev = pdev;
37806diff -urNp linux-2.6.32.44/drivers/serial/kgdboc.c linux-2.6.32.44/drivers/serial/kgdboc.c
37807--- linux-2.6.32.44/drivers/serial/kgdboc.c 2011-03-27 14:31:47.000000000 -0400
37808+++ linux-2.6.32.44/drivers/serial/kgdboc.c 2011-04-17 15:56:46.000000000 -0400
37809@@ -18,7 +18,7 @@
37810
37811 #define MAX_CONFIG_LEN 40
37812
37813-static struct kgdb_io kgdboc_io_ops;
37814+static const struct kgdb_io kgdboc_io_ops;
37815
37816 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37817 static int configured = -1;
37818@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void
37819 module_put(THIS_MODULE);
37820 }
37821
37822-static struct kgdb_io kgdboc_io_ops = {
37823+static const struct kgdb_io kgdboc_io_ops = {
37824 .name = "kgdboc",
37825 .read_char = kgdboc_get_char,
37826 .write_char = kgdboc_put_char,
37827diff -urNp linux-2.6.32.44/drivers/spi/spi.c linux-2.6.32.44/drivers/spi/spi.c
37828--- linux-2.6.32.44/drivers/spi/spi.c 2011-03-27 14:31:47.000000000 -0400
37829+++ linux-2.6.32.44/drivers/spi/spi.c 2011-05-04 17:56:28.000000000 -0400
37830@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, str
37831 EXPORT_SYMBOL_GPL(spi_sync);
37832
37833 /* portable code must never pass more than 32 bytes */
37834-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37835+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
37836
37837 static u8 *buf;
37838
37839diff -urNp linux-2.6.32.44/drivers/ssb/driver_gige.c linux-2.6.32.44/drivers/ssb/driver_gige.c
37840--- linux-2.6.32.44/drivers/ssb/driver_gige.c 2011-03-27 14:31:47.000000000 -0400
37841+++ linux-2.6.32.44/drivers/ssb/driver_gige.c 2011-08-05 20:33:55.000000000 -0400
37842@@ -180,8 +180,8 @@ static int ssb_gige_probe(struct ssb_dev
37843 dev->pci_controller.io_resource = &dev->io_resource;
37844 dev->pci_controller.mem_resource = &dev->mem_resource;
37845 dev->pci_controller.io_map_base = 0x800;
37846- dev->pci_ops.read = ssb_gige_pci_read_config;
37847- dev->pci_ops.write = ssb_gige_pci_write_config;
37848+ *(void **)&dev->pci_ops.read = ssb_gige_pci_read_config;
37849+ *(void **)&dev->pci_ops.write = ssb_gige_pci_write_config;
37850
37851 dev->io_resource.name = SSB_GIGE_IO_RES_NAME;
37852 dev->io_resource.start = 0x800;
37853diff -urNp linux-2.6.32.44/drivers/staging/android/binder.c linux-2.6.32.44/drivers/staging/android/binder.c
37854--- linux-2.6.32.44/drivers/staging/android/binder.c 2011-03-27 14:31:47.000000000 -0400
37855+++ linux-2.6.32.44/drivers/staging/android/binder.c 2011-04-17 15:56:46.000000000 -0400
37856@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_a
37857 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
37858 }
37859
37860-static struct vm_operations_struct binder_vm_ops = {
37861+static const struct vm_operations_struct binder_vm_ops = {
37862 .open = binder_vma_open,
37863 .close = binder_vma_close,
37864 };
37865diff -urNp linux-2.6.32.44/drivers/staging/b3dfg/b3dfg.c linux-2.6.32.44/drivers/staging/b3dfg/b3dfg.c
37866--- linux-2.6.32.44/drivers/staging/b3dfg/b3dfg.c 2011-03-27 14:31:47.000000000 -0400
37867+++ linux-2.6.32.44/drivers/staging/b3dfg/b3dfg.c 2011-04-17 15:56:46.000000000 -0400
37868@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_are
37869 return VM_FAULT_NOPAGE;
37870 }
37871
37872-static struct vm_operations_struct b3dfg_vm_ops = {
37873+static const struct vm_operations_struct b3dfg_vm_ops = {
37874 .fault = b3dfg_vma_fault,
37875 };
37876
37877@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp,
37878 return r;
37879 }
37880
37881-static struct file_operations b3dfg_fops = {
37882+static const struct file_operations b3dfg_fops = {
37883 .owner = THIS_MODULE,
37884 .open = b3dfg_open,
37885 .release = b3dfg_release,
37886diff -urNp linux-2.6.32.44/drivers/staging/comedi/comedi_fops.c linux-2.6.32.44/drivers/staging/comedi/comedi_fops.c
37887--- linux-2.6.32.44/drivers/staging/comedi/comedi_fops.c 2011-08-09 18:35:29.000000000 -0400
37888+++ linux-2.6.32.44/drivers/staging/comedi/comedi_fops.c 2011-08-09 18:34:00.000000000 -0400
37889@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct
37890 mutex_unlock(&dev->mutex);
37891 }
37892
37893-static struct vm_operations_struct comedi_vm_ops = {
37894+static const struct vm_operations_struct comedi_vm_ops = {
37895 .close = comedi_unmap,
37896 };
37897
37898diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/adsp_driver.c linux-2.6.32.44/drivers/staging/dream/qdsp5/adsp_driver.c
37899--- linux-2.6.32.44/drivers/staging/dream/qdsp5/adsp_driver.c 2011-03-27 14:31:47.000000000 -0400
37900+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/adsp_driver.c 2011-04-17 15:56:46.000000000 -0400
37901@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_devi
37902 static dev_t adsp_devno;
37903 static struct class *adsp_class;
37904
37905-static struct file_operations adsp_fops = {
37906+static const struct file_operations adsp_fops = {
37907 .owner = THIS_MODULE,
37908 .open = adsp_open,
37909 .unlocked_ioctl = adsp_ioctl,
37910diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_aac.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_aac.c
37911--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_aac.c 2011-03-27 14:31:47.000000000 -0400
37912+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_aac.c 2011-04-17 15:56:46.000000000 -0400
37913@@ -1022,7 +1022,7 @@ done:
37914 return rc;
37915 }
37916
37917-static struct file_operations audio_aac_fops = {
37918+static const struct file_operations audio_aac_fops = {
37919 .owner = THIS_MODULE,
37920 .open = audio_open,
37921 .release = audio_release,
37922diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_amrnb.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_amrnb.c
37923--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-03-27 14:31:47.000000000 -0400
37924+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-04-17 15:56:46.000000000 -0400
37925@@ -833,7 +833,7 @@ done:
37926 return rc;
37927 }
37928
37929-static struct file_operations audio_amrnb_fops = {
37930+static const struct file_operations audio_amrnb_fops = {
37931 .owner = THIS_MODULE,
37932 .open = audamrnb_open,
37933 .release = audamrnb_release,
37934diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_evrc.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_evrc.c
37935--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_evrc.c 2011-03-27 14:31:47.000000000 -0400
37936+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_evrc.c 2011-04-17 15:56:46.000000000 -0400
37937@@ -805,7 +805,7 @@ dma_fail:
37938 return rc;
37939 }
37940
37941-static struct file_operations audio_evrc_fops = {
37942+static const struct file_operations audio_evrc_fops = {
37943 .owner = THIS_MODULE,
37944 .open = audevrc_open,
37945 .release = audevrc_release,
37946diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_in.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_in.c
37947--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_in.c 2011-03-27 14:31:47.000000000 -0400
37948+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_in.c 2011-04-17 15:56:46.000000000 -0400
37949@@ -913,7 +913,7 @@ static int audpre_open(struct inode *ino
37950 return 0;
37951 }
37952
37953-static struct file_operations audio_fops = {
37954+static const struct file_operations audio_fops = {
37955 .owner = THIS_MODULE,
37956 .open = audio_in_open,
37957 .release = audio_in_release,
37958@@ -922,7 +922,7 @@ static struct file_operations audio_fops
37959 .unlocked_ioctl = audio_in_ioctl,
37960 };
37961
37962-static struct file_operations audpre_fops = {
37963+static const struct file_operations audpre_fops = {
37964 .owner = THIS_MODULE,
37965 .open = audpre_open,
37966 .unlocked_ioctl = audpre_ioctl,
37967diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_mp3.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_mp3.c
37968--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_mp3.c 2011-03-27 14:31:47.000000000 -0400
37969+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_mp3.c 2011-04-17 15:56:46.000000000 -0400
37970@@ -941,7 +941,7 @@ done:
37971 return rc;
37972 }
37973
37974-static struct file_operations audio_mp3_fops = {
37975+static const struct file_operations audio_mp3_fops = {
37976 .owner = THIS_MODULE,
37977 .open = audio_open,
37978 .release = audio_release,
37979diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_out.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_out.c
37980--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_out.c 2011-03-27 14:31:47.000000000 -0400
37981+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_out.c 2011-04-17 15:56:46.000000000 -0400
37982@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inod
37983 return 0;
37984 }
37985
37986-static struct file_operations audio_fops = {
37987+static const struct file_operations audio_fops = {
37988 .owner = THIS_MODULE,
37989 .open = audio_open,
37990 .release = audio_release,
37991@@ -819,7 +819,7 @@ static struct file_operations audio_fops
37992 .unlocked_ioctl = audio_ioctl,
37993 };
37994
37995-static struct file_operations audpp_fops = {
37996+static const struct file_operations audpp_fops = {
37997 .owner = THIS_MODULE,
37998 .open = audpp_open,
37999 .unlocked_ioctl = audpp_ioctl,
38000diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_qcelp.c linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_qcelp.c
38001--- linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-03-27 14:31:47.000000000 -0400
38002+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-04-17 15:56:46.000000000 -0400
38003@@ -816,7 +816,7 @@ err:
38004 return rc;
38005 }
38006
38007-static struct file_operations audio_qcelp_fops = {
38008+static const struct file_operations audio_qcelp_fops = {
38009 .owner = THIS_MODULE,
38010 .open = audqcelp_open,
38011 .release = audqcelp_release,
38012diff -urNp linux-2.6.32.44/drivers/staging/dream/qdsp5/snd.c linux-2.6.32.44/drivers/staging/dream/qdsp5/snd.c
38013--- linux-2.6.32.44/drivers/staging/dream/qdsp5/snd.c 2011-03-27 14:31:47.000000000 -0400
38014+++ linux-2.6.32.44/drivers/staging/dream/qdsp5/snd.c 2011-04-17 15:56:46.000000000 -0400
38015@@ -242,7 +242,7 @@ err:
38016 return rc;
38017 }
38018
38019-static struct file_operations snd_fops = {
38020+static const struct file_operations snd_fops = {
38021 .owner = THIS_MODULE,
38022 .open = snd_open,
38023 .release = snd_release,
38024diff -urNp linux-2.6.32.44/drivers/staging/dream/smd/smd_qmi.c linux-2.6.32.44/drivers/staging/dream/smd/smd_qmi.c
38025--- linux-2.6.32.44/drivers/staging/dream/smd/smd_qmi.c 2011-03-27 14:31:47.000000000 -0400
38026+++ linux-2.6.32.44/drivers/staging/dream/smd/smd_qmi.c 2011-04-17 15:56:46.000000000 -0400
38027@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip,
38028 return 0;
38029 }
38030
38031-static struct file_operations qmi_fops = {
38032+static const struct file_operations qmi_fops = {
38033 .owner = THIS_MODULE,
38034 .read = qmi_read,
38035 .write = qmi_write,
38036diff -urNp linux-2.6.32.44/drivers/staging/dream/smd/smd_rpcrouter_device.c linux-2.6.32.44/drivers/staging/dream/smd/smd_rpcrouter_device.c
38037--- linux-2.6.32.44/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-03-27 14:31:47.000000000 -0400
38038+++ linux-2.6.32.44/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-04-17 15:56:46.000000000 -0400
38039@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file
38040 return rc;
38041 }
38042
38043-static struct file_operations rpcrouter_server_fops = {
38044+static const struct file_operations rpcrouter_server_fops = {
38045 .owner = THIS_MODULE,
38046 .open = rpcrouter_open,
38047 .release = rpcrouter_release,
38048@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_
38049 .unlocked_ioctl = rpcrouter_ioctl,
38050 };
38051
38052-static struct file_operations rpcrouter_router_fops = {
38053+static const struct file_operations rpcrouter_router_fops = {
38054 .owner = THIS_MODULE,
38055 .open = rpcrouter_open,
38056 .release = rpcrouter_release,
38057diff -urNp linux-2.6.32.44/drivers/staging/dst/dcore.c linux-2.6.32.44/drivers/staging/dst/dcore.c
38058--- linux-2.6.32.44/drivers/staging/dst/dcore.c 2011-03-27 14:31:47.000000000 -0400
38059+++ linux-2.6.32.44/drivers/staging/dst/dcore.c 2011-04-17 15:56:46.000000000 -0400
38060@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendi
38061 return 0;
38062 }
38063
38064-static struct block_device_operations dst_blk_ops = {
38065+static const struct block_device_operations dst_blk_ops = {
38066 .open = dst_bdev_open,
38067 .release = dst_bdev_release,
38068 .owner = THIS_MODULE,
38069@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(s
38070 n->size = ctl->size;
38071
38072 atomic_set(&n->refcnt, 1);
38073- atomic_long_set(&n->gen, 0);
38074+ atomic_long_set_unchecked(&n->gen, 0);
38075 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
38076
38077 err = dst_node_sysfs_init(n);
38078diff -urNp linux-2.6.32.44/drivers/staging/dst/trans.c linux-2.6.32.44/drivers/staging/dst/trans.c
38079--- linux-2.6.32.44/drivers/staging/dst/trans.c 2011-03-27 14:31:47.000000000 -0400
38080+++ linux-2.6.32.44/drivers/staging/dst/trans.c 2011-04-17 15:56:46.000000000 -0400
38081@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n,
38082 t->error = 0;
38083 t->retries = 0;
38084 atomic_set(&t->refcnt, 1);
38085- t->gen = atomic_long_inc_return(&n->gen);
38086+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
38087
38088 t->enc = bio_data_dir(bio);
38089 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
38090diff -urNp linux-2.6.32.44/drivers/staging/et131x/et1310_tx.c linux-2.6.32.44/drivers/staging/et131x/et1310_tx.c
38091--- linux-2.6.32.44/drivers/staging/et131x/et1310_tx.c 2011-03-27 14:31:47.000000000 -0400
38092+++ linux-2.6.32.44/drivers/staging/et131x/et1310_tx.c 2011-05-04 17:56:28.000000000 -0400
38093@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(stru
38094 struct net_device_stats *stats = &etdev->net_stats;
38095
38096 if (pMpTcb->Flags & fMP_DEST_BROAD)
38097- atomic_inc(&etdev->Stats.brdcstxmt);
38098+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
38099 else if (pMpTcb->Flags & fMP_DEST_MULTI)
38100- atomic_inc(&etdev->Stats.multixmt);
38101+ atomic_inc_unchecked(&etdev->Stats.multixmt);
38102 else
38103- atomic_inc(&etdev->Stats.unixmt);
38104+ atomic_inc_unchecked(&etdev->Stats.unixmt);
38105
38106 if (pMpTcb->Packet) {
38107 stats->tx_bytes += pMpTcb->Packet->len;
38108diff -urNp linux-2.6.32.44/drivers/staging/et131x/et131x_adapter.h linux-2.6.32.44/drivers/staging/et131x/et131x_adapter.h
38109--- linux-2.6.32.44/drivers/staging/et131x/et131x_adapter.h 2011-03-27 14:31:47.000000000 -0400
38110+++ linux-2.6.32.44/drivers/staging/et131x/et131x_adapter.h 2011-05-04 17:56:28.000000000 -0400
38111@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
38112 * operations
38113 */
38114 u32 unircv; /* # multicast packets received */
38115- atomic_t unixmt; /* # multicast packets for Tx */
38116+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
38117 u32 multircv; /* # multicast packets received */
38118- atomic_t multixmt; /* # multicast packets for Tx */
38119+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
38120 u32 brdcstrcv; /* # broadcast packets received */
38121- atomic_t brdcstxmt; /* # broadcast packets for Tx */
38122+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
38123 u32 norcvbuf; /* # Rx packets discarded */
38124 u32 noxmtbuf; /* # Tx packets discarded */
38125
38126diff -urNp linux-2.6.32.44/drivers/staging/go7007/go7007-v4l2.c linux-2.6.32.44/drivers/staging/go7007/go7007-v4l2.c
38127--- linux-2.6.32.44/drivers/staging/go7007/go7007-v4l2.c 2011-03-27 14:31:47.000000000 -0400
38128+++ linux-2.6.32.44/drivers/staging/go7007/go7007-v4l2.c 2011-04-17 15:56:46.000000000 -0400
38129@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_are
38130 return 0;
38131 }
38132
38133-static struct vm_operations_struct go7007_vm_ops = {
38134+static const struct vm_operations_struct go7007_vm_ops = {
38135 .open = go7007_vm_open,
38136 .close = go7007_vm_close,
38137 .fault = go7007_vm_fault,
38138diff -urNp linux-2.6.32.44/drivers/staging/hv/blkvsc_drv.c linux-2.6.32.44/drivers/staging/hv/blkvsc_drv.c
38139--- linux-2.6.32.44/drivers/staging/hv/blkvsc_drv.c 2011-03-27 14:31:47.000000000 -0400
38140+++ linux-2.6.32.44/drivers/staging/hv/blkvsc_drv.c 2011-04-17 15:56:46.000000000 -0400
38141@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKV
38142 /* The one and only one */
38143 static struct blkvsc_driver_context g_blkvsc_drv;
38144
38145-static struct block_device_operations block_ops = {
38146+static const struct block_device_operations block_ops = {
38147 .owner = THIS_MODULE,
38148 .open = blkvsc_open,
38149 .release = blkvsc_release,
38150diff -urNp linux-2.6.32.44/drivers/staging/hv/Channel.c linux-2.6.32.44/drivers/staging/hv/Channel.c
38151--- linux-2.6.32.44/drivers/staging/hv/Channel.c 2011-04-17 17:00:52.000000000 -0400
38152+++ linux-2.6.32.44/drivers/staging/hv/Channel.c 2011-05-04 17:56:28.000000000 -0400
38153@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vm
38154
38155 DPRINT_ENTER(VMBUS);
38156
38157- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
38158- atomic_inc(&gVmbusConnection.NextGpadlHandle);
38159+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
38160+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
38161
38162 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
38163 ASSERT(msgInfo != NULL);
38164diff -urNp linux-2.6.32.44/drivers/staging/hv/Hv.c linux-2.6.32.44/drivers/staging/hv/Hv.c
38165--- linux-2.6.32.44/drivers/staging/hv/Hv.c 2011-03-27 14:31:47.000000000 -0400
38166+++ linux-2.6.32.44/drivers/staging/hv/Hv.c 2011-04-17 15:56:46.000000000 -0400
38167@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, vo
38168 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
38169 u32 outputAddressHi = outputAddress >> 32;
38170 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
38171- volatile void *hypercallPage = gHvContext.HypercallPage;
38172+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
38173
38174 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
38175 Control, Input, Output);
38176diff -urNp linux-2.6.32.44/drivers/staging/hv/vmbus_drv.c linux-2.6.32.44/drivers/staging/hv/vmbus_drv.c
38177--- linux-2.6.32.44/drivers/staging/hv/vmbus_drv.c 2011-03-27 14:31:47.000000000 -0400
38178+++ linux-2.6.32.44/drivers/staging/hv/vmbus_drv.c 2011-05-04 17:56:28.000000000 -0400
38179@@ -532,7 +532,7 @@ static int vmbus_child_device_register(s
38180 to_device_context(root_device_obj);
38181 struct device_context *child_device_ctx =
38182 to_device_context(child_device_obj);
38183- static atomic_t device_num = ATOMIC_INIT(0);
38184+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
38185
38186 DPRINT_ENTER(VMBUS_DRV);
38187
38188@@ -541,7 +541,7 @@ static int vmbus_child_device_register(s
38189
38190 /* Set the device name. Otherwise, device_register() will fail. */
38191 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
38192- atomic_inc_return(&device_num));
38193+ atomic_inc_return_unchecked(&device_num));
38194
38195 /* The new device belongs to this bus */
38196 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
38197diff -urNp linux-2.6.32.44/drivers/staging/hv/VmbusPrivate.h linux-2.6.32.44/drivers/staging/hv/VmbusPrivate.h
38198--- linux-2.6.32.44/drivers/staging/hv/VmbusPrivate.h 2011-04-17 17:00:52.000000000 -0400
38199+++ linux-2.6.32.44/drivers/staging/hv/VmbusPrivate.h 2011-05-04 17:56:28.000000000 -0400
38200@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
38201 struct VMBUS_CONNECTION {
38202 enum VMBUS_CONNECT_STATE ConnectState;
38203
38204- atomic_t NextGpadlHandle;
38205+ atomic_unchecked_t NextGpadlHandle;
38206
38207 /*
38208 * Represents channel interrupts. Each bit position represents a
38209diff -urNp linux-2.6.32.44/drivers/staging/octeon/ethernet.c linux-2.6.32.44/drivers/staging/octeon/ethernet.c
38210--- linux-2.6.32.44/drivers/staging/octeon/ethernet.c 2011-03-27 14:31:47.000000000 -0400
38211+++ linux-2.6.32.44/drivers/staging/octeon/ethernet.c 2011-05-04 17:56:28.000000000 -0400
38212@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_
38213 * since the RX tasklet also increments it.
38214 */
38215 #ifdef CONFIG_64BIT
38216- atomic64_add(rx_status.dropped_packets,
38217- (atomic64_t *)&priv->stats.rx_dropped);
38218+ atomic64_add_unchecked(rx_status.dropped_packets,
38219+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38220 #else
38221- atomic_add(rx_status.dropped_packets,
38222- (atomic_t *)&priv->stats.rx_dropped);
38223+ atomic_add_unchecked(rx_status.dropped_packets,
38224+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
38225 #endif
38226 }
38227
38228diff -urNp linux-2.6.32.44/drivers/staging/octeon/ethernet-rx.c linux-2.6.32.44/drivers/staging/octeon/ethernet-rx.c
38229--- linux-2.6.32.44/drivers/staging/octeon/ethernet-rx.c 2011-03-27 14:31:47.000000000 -0400
38230+++ linux-2.6.32.44/drivers/staging/octeon/ethernet-rx.c 2011-05-04 17:56:28.000000000 -0400
38231@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long un
38232 /* Increment RX stats for virtual ports */
38233 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38234 #ifdef CONFIG_64BIT
38235- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38236- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38237+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38238+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38239 #else
38240- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38241- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38242+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38243+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38244 #endif
38245 }
38246 netif_receive_skb(skb);
38247@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long un
38248 dev->name);
38249 */
38250 #ifdef CONFIG_64BIT
38251- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38252+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
38253 #else
38254- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38255+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
38256 #endif
38257 dev_kfree_skb_irq(skb);
38258 }
38259diff -urNp linux-2.6.32.44/drivers/staging/panel/panel.c linux-2.6.32.44/drivers/staging/panel/panel.c
38260--- linux-2.6.32.44/drivers/staging/panel/panel.c 2011-03-27 14:31:47.000000000 -0400
38261+++ linux-2.6.32.44/drivers/staging/panel/panel.c 2011-04-17 15:56:46.000000000 -0400
38262@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *ino
38263 return 0;
38264 }
38265
38266-static struct file_operations lcd_fops = {
38267+static const struct file_operations lcd_fops = {
38268 .write = lcd_write,
38269 .open = lcd_open,
38270 .release = lcd_release,
38271@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *
38272 return 0;
38273 }
38274
38275-static struct file_operations keypad_fops = {
38276+static const struct file_operations keypad_fops = {
38277 .read = keypad_read, /* read */
38278 .open = keypad_open, /* open */
38279 .release = keypad_release, /* close */
38280diff -urNp linux-2.6.32.44/drivers/staging/phison/phison.c linux-2.6.32.44/drivers/staging/phison/phison.c
38281--- linux-2.6.32.44/drivers/staging/phison/phison.c 2011-03-27 14:31:47.000000000 -0400
38282+++ linux-2.6.32.44/drivers/staging/phison/phison.c 2011-04-17 15:56:46.000000000 -0400
38283@@ -43,7 +43,7 @@ static struct scsi_host_template phison_
38284 ATA_BMDMA_SHT(DRV_NAME),
38285 };
38286
38287-static struct ata_port_operations phison_ops = {
38288+static const struct ata_port_operations phison_ops = {
38289 .inherits = &ata_bmdma_port_ops,
38290 .prereset = phison_pre_reset,
38291 };
38292diff -urNp linux-2.6.32.44/drivers/staging/poch/poch.c linux-2.6.32.44/drivers/staging/poch/poch.c
38293--- linux-2.6.32.44/drivers/staging/poch/poch.c 2011-03-27 14:31:47.000000000 -0400
38294+++ linux-2.6.32.44/drivers/staging/poch/poch.c 2011-04-17 15:56:46.000000000 -0400
38295@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inod
38296 return 0;
38297 }
38298
38299-static struct file_operations poch_fops = {
38300+static const struct file_operations poch_fops = {
38301 .owner = THIS_MODULE,
38302 .open = poch_open,
38303 .release = poch_release,
38304diff -urNp linux-2.6.32.44/drivers/staging/pohmelfs/inode.c linux-2.6.32.44/drivers/staging/pohmelfs/inode.c
38305--- linux-2.6.32.44/drivers/staging/pohmelfs/inode.c 2011-03-27 14:31:47.000000000 -0400
38306+++ linux-2.6.32.44/drivers/staging/pohmelfs/inode.c 2011-05-04 17:56:20.000000000 -0400
38307@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct su
38308 mutex_init(&psb->mcache_lock);
38309 psb->mcache_root = RB_ROOT;
38310 psb->mcache_timeout = msecs_to_jiffies(5000);
38311- atomic_long_set(&psb->mcache_gen, 0);
38312+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
38313
38314 psb->trans_max_pages = 100;
38315
38316@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct su
38317 INIT_LIST_HEAD(&psb->crypto_ready_list);
38318 INIT_LIST_HEAD(&psb->crypto_active_list);
38319
38320- atomic_set(&psb->trans_gen, 1);
38321+ atomic_set_unchecked(&psb->trans_gen, 1);
38322 atomic_long_set(&psb->total_inodes, 0);
38323
38324 mutex_init(&psb->state_lock);
38325diff -urNp linux-2.6.32.44/drivers/staging/pohmelfs/mcache.c linux-2.6.32.44/drivers/staging/pohmelfs/mcache.c
38326--- linux-2.6.32.44/drivers/staging/pohmelfs/mcache.c 2011-03-27 14:31:47.000000000 -0400
38327+++ linux-2.6.32.44/drivers/staging/pohmelfs/mcache.c 2011-04-17 15:56:46.000000000 -0400
38328@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
38329 m->data = data;
38330 m->start = start;
38331 m->size = size;
38332- m->gen = atomic_long_inc_return(&psb->mcache_gen);
38333+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
38334
38335 mutex_lock(&psb->mcache_lock);
38336 err = pohmelfs_mcache_insert(psb, m);
38337diff -urNp linux-2.6.32.44/drivers/staging/pohmelfs/netfs.h linux-2.6.32.44/drivers/staging/pohmelfs/netfs.h
38338--- linux-2.6.32.44/drivers/staging/pohmelfs/netfs.h 2011-03-27 14:31:47.000000000 -0400
38339+++ linux-2.6.32.44/drivers/staging/pohmelfs/netfs.h 2011-05-04 17:56:20.000000000 -0400
38340@@ -570,14 +570,14 @@ struct pohmelfs_config;
38341 struct pohmelfs_sb {
38342 struct rb_root mcache_root;
38343 struct mutex mcache_lock;
38344- atomic_long_t mcache_gen;
38345+ atomic_long_unchecked_t mcache_gen;
38346 unsigned long mcache_timeout;
38347
38348 unsigned int idx;
38349
38350 unsigned int trans_retries;
38351
38352- atomic_t trans_gen;
38353+ atomic_unchecked_t trans_gen;
38354
38355 unsigned int crypto_attached_size;
38356 unsigned int crypto_align_size;
38357diff -urNp linux-2.6.32.44/drivers/staging/pohmelfs/trans.c linux-2.6.32.44/drivers/staging/pohmelfs/trans.c
38358--- linux-2.6.32.44/drivers/staging/pohmelfs/trans.c 2011-03-27 14:31:47.000000000 -0400
38359+++ linux-2.6.32.44/drivers/staging/pohmelfs/trans.c 2011-05-04 17:56:28.000000000 -0400
38360@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
38361 int err;
38362 struct netfs_cmd *cmd = t->iovec.iov_base;
38363
38364- t->gen = atomic_inc_return(&psb->trans_gen);
38365+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
38366
38367 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
38368 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
38369diff -urNp linux-2.6.32.44/drivers/staging/sep/sep_driver.c linux-2.6.32.44/drivers/staging/sep/sep_driver.c
38370--- linux-2.6.32.44/drivers/staging/sep/sep_driver.c 2011-03-27 14:31:47.000000000 -0400
38371+++ linux-2.6.32.44/drivers/staging/sep/sep_driver.c 2011-04-17 15:56:46.000000000 -0400
38372@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver
38373 static dev_t sep_devno;
38374
38375 /* the files operations structure of the driver */
38376-static struct file_operations sep_file_operations = {
38377+static const struct file_operations sep_file_operations = {
38378 .owner = THIS_MODULE,
38379 .ioctl = sep_ioctl,
38380 .poll = sep_poll,
38381diff -urNp linux-2.6.32.44/drivers/staging/usbip/vhci.h linux-2.6.32.44/drivers/staging/usbip/vhci.h
38382--- linux-2.6.32.44/drivers/staging/usbip/vhci.h 2011-03-27 14:31:47.000000000 -0400
38383+++ linux-2.6.32.44/drivers/staging/usbip/vhci.h 2011-05-04 17:56:28.000000000 -0400
38384@@ -92,7 +92,7 @@ struct vhci_hcd {
38385 unsigned resuming:1;
38386 unsigned long re_timeout;
38387
38388- atomic_t seqnum;
38389+ atomic_unchecked_t seqnum;
38390
38391 /*
38392 * NOTE:
38393diff -urNp linux-2.6.32.44/drivers/staging/usbip/vhci_hcd.c linux-2.6.32.44/drivers/staging/usbip/vhci_hcd.c
38394--- linux-2.6.32.44/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:01.000000000 -0400
38395+++ linux-2.6.32.44/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:33.000000000 -0400
38396@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
38397 return;
38398 }
38399
38400- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38401+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38402 if (priv->seqnum == 0xffff)
38403 usbip_uinfo("seqnum max\n");
38404
38405@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_h
38406 return -ENOMEM;
38407 }
38408
38409- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38410+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38411 if (unlink->seqnum == 0xffff)
38412 usbip_uinfo("seqnum max\n");
38413
38414@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hc
38415 vdev->rhport = rhport;
38416 }
38417
38418- atomic_set(&vhci->seqnum, 0);
38419+ atomic_set_unchecked(&vhci->seqnum, 0);
38420 spin_lock_init(&vhci->lock);
38421
38422
38423diff -urNp linux-2.6.32.44/drivers/staging/usbip/vhci_rx.c linux-2.6.32.44/drivers/staging/usbip/vhci_rx.c
38424--- linux-2.6.32.44/drivers/staging/usbip/vhci_rx.c 2011-04-17 17:00:52.000000000 -0400
38425+++ linux-2.6.32.44/drivers/staging/usbip/vhci_rx.c 2011-05-04 17:56:28.000000000 -0400
38426@@ -78,7 +78,7 @@ static void vhci_recv_ret_submit(struct
38427 usbip_uerr("cannot find a urb of seqnum %u\n",
38428 pdu->base.seqnum);
38429 usbip_uinfo("max seqnum %d\n",
38430- atomic_read(&the_controller->seqnum));
38431+ atomic_read_unchecked(&the_controller->seqnum));
38432 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38433 return;
38434 }
38435diff -urNp linux-2.6.32.44/drivers/staging/vme/devices/vme_user.c linux-2.6.32.44/drivers/staging/vme/devices/vme_user.c
38436--- linux-2.6.32.44/drivers/staging/vme/devices/vme_user.c 2011-03-27 14:31:47.000000000 -0400
38437+++ linux-2.6.32.44/drivers/staging/vme/devices/vme_user.c 2011-04-17 15:56:46.000000000 -0400
38438@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *
38439 static int __init vme_user_probe(struct device *, int, int);
38440 static int __exit vme_user_remove(struct device *, int, int);
38441
38442-static struct file_operations vme_user_fops = {
38443+static const struct file_operations vme_user_fops = {
38444 .open = vme_user_open,
38445 .release = vme_user_release,
38446 .read = vme_user_read,
38447diff -urNp linux-2.6.32.44/drivers/telephony/ixj.c linux-2.6.32.44/drivers/telephony/ixj.c
38448--- linux-2.6.32.44/drivers/telephony/ixj.c 2011-03-27 14:31:47.000000000 -0400
38449+++ linux-2.6.32.44/drivers/telephony/ixj.c 2011-05-16 21:46:57.000000000 -0400
38450@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
38451 bool mContinue;
38452 char *pIn, *pOut;
38453
38454+ pax_track_stack();
38455+
38456 if (!SCI_Prepare(j))
38457 return 0;
38458
38459diff -urNp linux-2.6.32.44/drivers/uio/uio.c linux-2.6.32.44/drivers/uio/uio.c
38460--- linux-2.6.32.44/drivers/uio/uio.c 2011-03-27 14:31:47.000000000 -0400
38461+++ linux-2.6.32.44/drivers/uio/uio.c 2011-05-04 17:56:20.000000000 -0400
38462@@ -23,6 +23,7 @@
38463 #include <linux/string.h>
38464 #include <linux/kobject.h>
38465 #include <linux/uio_driver.h>
38466+#include <asm/local.h>
38467
38468 #define UIO_MAX_DEVICES 255
38469
38470@@ -30,10 +31,10 @@ struct uio_device {
38471 struct module *owner;
38472 struct device *dev;
38473 int minor;
38474- atomic_t event;
38475+ atomic_unchecked_t event;
38476 struct fasync_struct *async_queue;
38477 wait_queue_head_t wait;
38478- int vma_count;
38479+ local_t vma_count;
38480 struct uio_info *info;
38481 struct kobject *map_dir;
38482 struct kobject *portio_dir;
38483@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobj
38484 return entry->show(mem, buf);
38485 }
38486
38487-static struct sysfs_ops map_sysfs_ops = {
38488+static const struct sysfs_ops map_sysfs_ops = {
38489 .show = map_type_show,
38490 };
38491
38492@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct k
38493 return entry->show(port, buf);
38494 }
38495
38496-static struct sysfs_ops portio_sysfs_ops = {
38497+static const struct sysfs_ops portio_sysfs_ops = {
38498 .show = portio_type_show,
38499 };
38500
38501@@ -255,7 +256,7 @@ static ssize_t show_event(struct device
38502 struct uio_device *idev = dev_get_drvdata(dev);
38503 if (idev)
38504 return sprintf(buf, "%u\n",
38505- (unsigned int)atomic_read(&idev->event));
38506+ (unsigned int)atomic_read_unchecked(&idev->event));
38507 else
38508 return -ENODEV;
38509 }
38510@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *i
38511 {
38512 struct uio_device *idev = info->uio_dev;
38513
38514- atomic_inc(&idev->event);
38515+ atomic_inc_unchecked(&idev->event);
38516 wake_up_interruptible(&idev->wait);
38517 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38518 }
38519@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode,
38520 }
38521
38522 listener->dev = idev;
38523- listener->event_count = atomic_read(&idev->event);
38524+ listener->event_count = atomic_read_unchecked(&idev->event);
38525 filep->private_data = listener;
38526
38527 if (idev->info->open) {
38528@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file
38529 return -EIO;
38530
38531 poll_wait(filep, &idev->wait, wait);
38532- if (listener->event_count != atomic_read(&idev->event))
38533+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38534 return POLLIN | POLLRDNORM;
38535 return 0;
38536 }
38537@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *fil
38538 do {
38539 set_current_state(TASK_INTERRUPTIBLE);
38540
38541- event_count = atomic_read(&idev->event);
38542+ event_count = atomic_read_unchecked(&idev->event);
38543 if (event_count != listener->event_count) {
38544 if (copy_to_user(buf, &event_count, count))
38545 retval = -EFAULT;
38546@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_
38547 static void uio_vma_open(struct vm_area_struct *vma)
38548 {
38549 struct uio_device *idev = vma->vm_private_data;
38550- idev->vma_count++;
38551+ local_inc(&idev->vma_count);
38552 }
38553
38554 static void uio_vma_close(struct vm_area_struct *vma)
38555 {
38556 struct uio_device *idev = vma->vm_private_data;
38557- idev->vma_count--;
38558+ local_dec(&idev->vma_count);
38559 }
38560
38561 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38562@@ -840,7 +841,7 @@ int __uio_register_device(struct module
38563 idev->owner = owner;
38564 idev->info = info;
38565 init_waitqueue_head(&idev->wait);
38566- atomic_set(&idev->event, 0);
38567+ atomic_set_unchecked(&idev->event, 0);
38568
38569 ret = uio_get_minor(idev);
38570 if (ret)
38571diff -urNp linux-2.6.32.44/drivers/usb/atm/usbatm.c linux-2.6.32.44/drivers/usb/atm/usbatm.c
38572--- linux-2.6.32.44/drivers/usb/atm/usbatm.c 2011-03-27 14:31:47.000000000 -0400
38573+++ linux-2.6.32.44/drivers/usb/atm/usbatm.c 2011-04-17 15:56:46.000000000 -0400
38574@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(stru
38575 if (printk_ratelimit())
38576 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38577 __func__, vpi, vci);
38578- atomic_inc(&vcc->stats->rx_err);
38579+ atomic_inc_unchecked(&vcc->stats->rx_err);
38580 return;
38581 }
38582
38583@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(stru
38584 if (length > ATM_MAX_AAL5_PDU) {
38585 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38586 __func__, length, vcc);
38587- atomic_inc(&vcc->stats->rx_err);
38588+ atomic_inc_unchecked(&vcc->stats->rx_err);
38589 goto out;
38590 }
38591
38592@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(stru
38593 if (sarb->len < pdu_length) {
38594 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38595 __func__, pdu_length, sarb->len, vcc);
38596- atomic_inc(&vcc->stats->rx_err);
38597+ atomic_inc_unchecked(&vcc->stats->rx_err);
38598 goto out;
38599 }
38600
38601 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38602 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38603 __func__, vcc);
38604- atomic_inc(&vcc->stats->rx_err);
38605+ atomic_inc_unchecked(&vcc->stats->rx_err);
38606 goto out;
38607 }
38608
38609@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(stru
38610 if (printk_ratelimit())
38611 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38612 __func__, length);
38613- atomic_inc(&vcc->stats->rx_drop);
38614+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38615 goto out;
38616 }
38617
38618@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(stru
38619
38620 vcc->push(vcc, skb);
38621
38622- atomic_inc(&vcc->stats->rx);
38623+ atomic_inc_unchecked(&vcc->stats->rx);
38624 out:
38625 skb_trim(sarb, 0);
38626 }
38627@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned l
38628 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38629
38630 usbatm_pop(vcc, skb);
38631- atomic_inc(&vcc->stats->tx);
38632+ atomic_inc_unchecked(&vcc->stats->tx);
38633
38634 skb = skb_dequeue(&instance->sndqueue);
38635 }
38636@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct a
38637 if (!left--)
38638 return sprintf(page,
38639 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38640- atomic_read(&atm_dev->stats.aal5.tx),
38641- atomic_read(&atm_dev->stats.aal5.tx_err),
38642- atomic_read(&atm_dev->stats.aal5.rx),
38643- atomic_read(&atm_dev->stats.aal5.rx_err),
38644- atomic_read(&atm_dev->stats.aal5.rx_drop));
38645+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38646+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38647+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38648+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38649+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38650
38651 if (!left--) {
38652 if (instance->disconnected)
38653diff -urNp linux-2.6.32.44/drivers/usb/class/cdc-wdm.c linux-2.6.32.44/drivers/usb/class/cdc-wdm.c
38654--- linux-2.6.32.44/drivers/usb/class/cdc-wdm.c 2011-03-27 14:31:47.000000000 -0400
38655+++ linux-2.6.32.44/drivers/usb/class/cdc-wdm.c 2011-04-17 15:56:46.000000000 -0400
38656@@ -314,7 +314,7 @@ static ssize_t wdm_write
38657 if (r < 0)
38658 goto outnp;
38659
38660- if (!file->f_flags && O_NONBLOCK)
38661+ if (!(file->f_flags & O_NONBLOCK))
38662 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
38663 &desc->flags));
38664 else
38665diff -urNp linux-2.6.32.44/drivers/usb/core/hcd.c linux-2.6.32.44/drivers/usb/core/hcd.c
38666--- linux-2.6.32.44/drivers/usb/core/hcd.c 2011-03-27 14:31:47.000000000 -0400
38667+++ linux-2.6.32.44/drivers/usb/core/hcd.c 2011-04-17 15:56:46.000000000 -0400
38668@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
38669
38670 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
38671
38672-struct usb_mon_operations *mon_ops;
38673+const struct usb_mon_operations *mon_ops;
38674
38675 /*
38676 * The registration is unlocked.
38677@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
38678 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
38679 */
38680
38681-int usb_mon_register (struct usb_mon_operations *ops)
38682+int usb_mon_register (const struct usb_mon_operations *ops)
38683 {
38684
38685 if (mon_ops)
38686diff -urNp linux-2.6.32.44/drivers/usb/core/hcd.h linux-2.6.32.44/drivers/usb/core/hcd.h
38687--- linux-2.6.32.44/drivers/usb/core/hcd.h 2011-03-27 14:31:47.000000000 -0400
38688+++ linux-2.6.32.44/drivers/usb/core/hcd.h 2011-04-17 15:56:46.000000000 -0400
38689@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) {
38690 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
38691
38692 struct usb_mon_operations {
38693- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
38694- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
38695- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
38696+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
38697+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
38698+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
38699 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
38700 };
38701
38702-extern struct usb_mon_operations *mon_ops;
38703+extern const struct usb_mon_operations *mon_ops;
38704
38705 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
38706 {
38707@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(s
38708 (*mon_ops->urb_complete)(bus, urb, status);
38709 }
38710
38711-int usb_mon_register(struct usb_mon_operations *ops);
38712+int usb_mon_register(const struct usb_mon_operations *ops);
38713 void usb_mon_deregister(void);
38714
38715 #else
38716diff -urNp linux-2.6.32.44/drivers/usb/core/message.c linux-2.6.32.44/drivers/usb/core/message.c
38717--- linux-2.6.32.44/drivers/usb/core/message.c 2011-03-27 14:31:47.000000000 -0400
38718+++ linux-2.6.32.44/drivers/usb/core/message.c 2011-04-17 15:56:46.000000000 -0400
38719@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device
38720 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
38721 if (buf) {
38722 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
38723- if (len > 0) {
38724- smallbuf = kmalloc(++len, GFP_NOIO);
38725+ if (len++ > 0) {
38726+ smallbuf = kmalloc(len, GFP_NOIO);
38727 if (!smallbuf)
38728 return buf;
38729 memcpy(smallbuf, buf, len);
38730diff -urNp linux-2.6.32.44/drivers/usb/misc/appledisplay.c linux-2.6.32.44/drivers/usb/misc/appledisplay.c
38731--- linux-2.6.32.44/drivers/usb/misc/appledisplay.c 2011-03-27 14:31:47.000000000 -0400
38732+++ linux-2.6.32.44/drivers/usb/misc/appledisplay.c 2011-04-17 15:56:46.000000000 -0400
38733@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightnes
38734 return pdata->msgdata[1];
38735 }
38736
38737-static struct backlight_ops appledisplay_bl_data = {
38738+static const struct backlight_ops appledisplay_bl_data = {
38739 .get_brightness = appledisplay_bl_get_brightness,
38740 .update_status = appledisplay_bl_update_status,
38741 };
38742diff -urNp linux-2.6.32.44/drivers/usb/mon/mon_main.c linux-2.6.32.44/drivers/usb/mon/mon_main.c
38743--- linux-2.6.32.44/drivers/usb/mon/mon_main.c 2011-03-27 14:31:47.000000000 -0400
38744+++ linux-2.6.32.44/drivers/usb/mon/mon_main.c 2011-04-17 15:56:46.000000000 -0400
38745@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
38746 /*
38747 * Ops
38748 */
38749-static struct usb_mon_operations mon_ops_0 = {
38750+static const struct usb_mon_operations mon_ops_0 = {
38751 .urb_submit = mon_submit,
38752 .urb_submit_error = mon_submit_error,
38753 .urb_complete = mon_complete,
38754diff -urNp linux-2.6.32.44/drivers/usb/wusbcore/wa-hc.h linux-2.6.32.44/drivers/usb/wusbcore/wa-hc.h
38755--- linux-2.6.32.44/drivers/usb/wusbcore/wa-hc.h 2011-03-27 14:31:47.000000000 -0400
38756+++ linux-2.6.32.44/drivers/usb/wusbcore/wa-hc.h 2011-05-04 17:56:28.000000000 -0400
38757@@ -192,7 +192,7 @@ struct wahc {
38758 struct list_head xfer_delayed_list;
38759 spinlock_t xfer_list_lock;
38760 struct work_struct xfer_work;
38761- atomic_t xfer_id_count;
38762+ atomic_unchecked_t xfer_id_count;
38763 };
38764
38765
38766@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
38767 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38768 spin_lock_init(&wa->xfer_list_lock);
38769 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38770- atomic_set(&wa->xfer_id_count, 1);
38771+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38772 }
38773
38774 /**
38775diff -urNp linux-2.6.32.44/drivers/usb/wusbcore/wa-xfer.c linux-2.6.32.44/drivers/usb/wusbcore/wa-xfer.c
38776--- linux-2.6.32.44/drivers/usb/wusbcore/wa-xfer.c 2011-03-27 14:31:47.000000000 -0400
38777+++ linux-2.6.32.44/drivers/usb/wusbcore/wa-xfer.c 2011-05-04 17:56:28.000000000 -0400
38778@@ -293,7 +293,7 @@ out:
38779 */
38780 static void wa_xfer_id_init(struct wa_xfer *xfer)
38781 {
38782- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38783+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38784 }
38785
38786 /*
38787diff -urNp linux-2.6.32.44/drivers/uwb/wlp/messages.c linux-2.6.32.44/drivers/uwb/wlp/messages.c
38788--- linux-2.6.32.44/drivers/uwb/wlp/messages.c 2011-03-27 14:31:47.000000000 -0400
38789+++ linux-2.6.32.44/drivers/uwb/wlp/messages.c 2011-04-17 15:56:46.000000000 -0400
38790@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct
38791 size_t len = skb->len;
38792 size_t used;
38793 ssize_t result;
38794- struct wlp_nonce enonce, rnonce;
38795+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
38796 enum wlp_assc_error assc_err;
38797 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
38798 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
38799diff -urNp linux-2.6.32.44/drivers/uwb/wlp/sysfs.c linux-2.6.32.44/drivers/uwb/wlp/sysfs.c
38800--- linux-2.6.32.44/drivers/uwb/wlp/sysfs.c 2011-03-27 14:31:47.000000000 -0400
38801+++ linux-2.6.32.44/drivers/uwb/wlp/sysfs.c 2011-04-17 15:56:46.000000000 -0400
38802@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobjec
38803 return ret;
38804 }
38805
38806-static
38807-struct sysfs_ops wss_sysfs_ops = {
38808+static const struct sysfs_ops wss_sysfs_ops = {
38809 .show = wlp_wss_attr_show,
38810 .store = wlp_wss_attr_store,
38811 };
38812diff -urNp linux-2.6.32.44/drivers/video/atmel_lcdfb.c linux-2.6.32.44/drivers/video/atmel_lcdfb.c
38813--- linux-2.6.32.44/drivers/video/atmel_lcdfb.c 2011-03-27 14:31:47.000000000 -0400
38814+++ linux-2.6.32.44/drivers/video/atmel_lcdfb.c 2011-04-17 15:56:46.000000000 -0400
38815@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struc
38816 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
38817 }
38818
38819-static struct backlight_ops atmel_lcdc_bl_ops = {
38820+static const struct backlight_ops atmel_lcdc_bl_ops = {
38821 .update_status = atmel_bl_update_status,
38822 .get_brightness = atmel_bl_get_brightness,
38823 };
38824diff -urNp linux-2.6.32.44/drivers/video/aty/aty128fb.c linux-2.6.32.44/drivers/video/aty/aty128fb.c
38825--- linux-2.6.32.44/drivers/video/aty/aty128fb.c 2011-03-27 14:31:47.000000000 -0400
38826+++ linux-2.6.32.44/drivers/video/aty/aty128fb.c 2011-04-17 15:56:46.000000000 -0400
38827@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(stru
38828 return bd->props.brightness;
38829 }
38830
38831-static struct backlight_ops aty128_bl_data = {
38832+static const struct backlight_ops aty128_bl_data = {
38833 .get_brightness = aty128_bl_get_brightness,
38834 .update_status = aty128_bl_update_status,
38835 };
38836diff -urNp linux-2.6.32.44/drivers/video/aty/atyfb_base.c linux-2.6.32.44/drivers/video/aty/atyfb_base.c
38837--- linux-2.6.32.44/drivers/video/aty/atyfb_base.c 2011-03-27 14:31:47.000000000 -0400
38838+++ linux-2.6.32.44/drivers/video/aty/atyfb_base.c 2011-04-17 15:56:46.000000000 -0400
38839@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct
38840 return bd->props.brightness;
38841 }
38842
38843-static struct backlight_ops aty_bl_data = {
38844+static const struct backlight_ops aty_bl_data = {
38845 .get_brightness = aty_bl_get_brightness,
38846 .update_status = aty_bl_update_status,
38847 };
38848diff -urNp linux-2.6.32.44/drivers/video/aty/radeon_backlight.c linux-2.6.32.44/drivers/video/aty/radeon_backlight.c
38849--- linux-2.6.32.44/drivers/video/aty/radeon_backlight.c 2011-03-27 14:31:47.000000000 -0400
38850+++ linux-2.6.32.44/drivers/video/aty/radeon_backlight.c 2011-04-17 15:56:46.000000000 -0400
38851@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(stru
38852 return bd->props.brightness;
38853 }
38854
38855-static struct backlight_ops radeon_bl_data = {
38856+static const struct backlight_ops radeon_bl_data = {
38857 .get_brightness = radeon_bl_get_brightness,
38858 .update_status = radeon_bl_update_status,
38859 };
38860diff -urNp linux-2.6.32.44/drivers/video/backlight/adp5520_bl.c linux-2.6.32.44/drivers/video/backlight/adp5520_bl.c
38861--- linux-2.6.32.44/drivers/video/backlight/adp5520_bl.c 2011-03-27 14:31:47.000000000 -0400
38862+++ linux-2.6.32.44/drivers/video/backlight/adp5520_bl.c 2011-04-17 15:56:46.000000000 -0400
38863@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(str
38864 return error ? data->current_brightness : reg_val;
38865 }
38866
38867-static struct backlight_ops adp5520_bl_ops = {
38868+static const struct backlight_ops adp5520_bl_ops = {
38869 .update_status = adp5520_bl_update_status,
38870 .get_brightness = adp5520_bl_get_brightness,
38871 };
38872diff -urNp linux-2.6.32.44/drivers/video/backlight/adx_bl.c linux-2.6.32.44/drivers/video/backlight/adx_bl.c
38873--- linux-2.6.32.44/drivers/video/backlight/adx_bl.c 2011-03-27 14:31:47.000000000 -0400
38874+++ linux-2.6.32.44/drivers/video/backlight/adx_bl.c 2011-04-17 15:56:46.000000000 -0400
38875@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct
38876 return 1;
38877 }
38878
38879-static struct backlight_ops adx_backlight_ops = {
38880+static const struct backlight_ops adx_backlight_ops = {
38881 .options = 0,
38882 .update_status = adx_backlight_update_status,
38883 .get_brightness = adx_backlight_get_brightness,
38884diff -urNp linux-2.6.32.44/drivers/video/backlight/atmel-pwm-bl.c linux-2.6.32.44/drivers/video/backlight/atmel-pwm-bl.c
38885--- linux-2.6.32.44/drivers/video/backlight/atmel-pwm-bl.c 2011-03-27 14:31:47.000000000 -0400
38886+++ linux-2.6.32.44/drivers/video/backlight/atmel-pwm-bl.c 2011-04-17 15:56:46.000000000 -0400
38887@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct
38888 return pwm_channel_enable(&pwmbl->pwmc);
38889 }
38890
38891-static struct backlight_ops atmel_pwm_bl_ops = {
38892+static const struct backlight_ops atmel_pwm_bl_ops = {
38893 .get_brightness = atmel_pwm_bl_get_intensity,
38894 .update_status = atmel_pwm_bl_set_intensity,
38895 };
38896diff -urNp linux-2.6.32.44/drivers/video/backlight/backlight.c linux-2.6.32.44/drivers/video/backlight/backlight.c
38897--- linux-2.6.32.44/drivers/video/backlight/backlight.c 2011-03-27 14:31:47.000000000 -0400
38898+++ linux-2.6.32.44/drivers/video/backlight/backlight.c 2011-04-17 15:56:46.000000000 -0400
38899@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
38900 * ERR_PTR() or a pointer to the newly allocated device.
38901 */
38902 struct backlight_device *backlight_device_register(const char *name,
38903- struct device *parent, void *devdata, struct backlight_ops *ops)
38904+ struct device *parent, void *devdata, const struct backlight_ops *ops)
38905 {
38906 struct backlight_device *new_bd;
38907 int rc;
38908diff -urNp linux-2.6.32.44/drivers/video/backlight/corgi_lcd.c linux-2.6.32.44/drivers/video/backlight/corgi_lcd.c
38909--- linux-2.6.32.44/drivers/video/backlight/corgi_lcd.c 2011-03-27 14:31:47.000000000 -0400
38910+++ linux-2.6.32.44/drivers/video/backlight/corgi_lcd.c 2011-04-17 15:56:46.000000000 -0400
38911@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit
38912 }
38913 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
38914
38915-static struct backlight_ops corgi_bl_ops = {
38916+static const struct backlight_ops corgi_bl_ops = {
38917 .get_brightness = corgi_bl_get_intensity,
38918 .update_status = corgi_bl_update_status,
38919 };
38920diff -urNp linux-2.6.32.44/drivers/video/backlight/cr_bllcd.c linux-2.6.32.44/drivers/video/backlight/cr_bllcd.c
38921--- linux-2.6.32.44/drivers/video/backlight/cr_bllcd.c 2011-03-27 14:31:47.000000000 -0400
38922+++ linux-2.6.32.44/drivers/video/backlight/cr_bllcd.c 2011-04-17 15:56:46.000000000 -0400
38923@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(st
38924 return intensity;
38925 }
38926
38927-static struct backlight_ops cr_backlight_ops = {
38928+static const struct backlight_ops cr_backlight_ops = {
38929 .get_brightness = cr_backlight_get_intensity,
38930 .update_status = cr_backlight_set_intensity,
38931 };
38932diff -urNp linux-2.6.32.44/drivers/video/backlight/da903x_bl.c linux-2.6.32.44/drivers/video/backlight/da903x_bl.c
38933--- linux-2.6.32.44/drivers/video/backlight/da903x_bl.c 2011-03-27 14:31:47.000000000 -0400
38934+++ linux-2.6.32.44/drivers/video/backlight/da903x_bl.c 2011-04-17 15:56:46.000000000 -0400
38935@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightne
38936 return data->current_brightness;
38937 }
38938
38939-static struct backlight_ops da903x_backlight_ops = {
38940+static const struct backlight_ops da903x_backlight_ops = {
38941 .update_status = da903x_backlight_update_status,
38942 .get_brightness = da903x_backlight_get_brightness,
38943 };
38944diff -urNp linux-2.6.32.44/drivers/video/backlight/generic_bl.c linux-2.6.32.44/drivers/video/backlight/generic_bl.c
38945--- linux-2.6.32.44/drivers/video/backlight/generic_bl.c 2011-03-27 14:31:47.000000000 -0400
38946+++ linux-2.6.32.44/drivers/video/backlight/generic_bl.c 2011-04-17 15:56:46.000000000 -0400
38947@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
38948 }
38949 EXPORT_SYMBOL(corgibl_limit_intensity);
38950
38951-static struct backlight_ops genericbl_ops = {
38952+static const struct backlight_ops genericbl_ops = {
38953 .options = BL_CORE_SUSPENDRESUME,
38954 .get_brightness = genericbl_get_intensity,
38955 .update_status = genericbl_send_intensity,
38956diff -urNp linux-2.6.32.44/drivers/video/backlight/hp680_bl.c linux-2.6.32.44/drivers/video/backlight/hp680_bl.c
38957--- linux-2.6.32.44/drivers/video/backlight/hp680_bl.c 2011-03-27 14:31:47.000000000 -0400
38958+++ linux-2.6.32.44/drivers/video/backlight/hp680_bl.c 2011-04-17 15:56:46.000000000 -0400
38959@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct
38960 return current_intensity;
38961 }
38962
38963-static struct backlight_ops hp680bl_ops = {
38964+static const struct backlight_ops hp680bl_ops = {
38965 .get_brightness = hp680bl_get_intensity,
38966 .update_status = hp680bl_set_intensity,
38967 };
38968diff -urNp linux-2.6.32.44/drivers/video/backlight/jornada720_bl.c linux-2.6.32.44/drivers/video/backlight/jornada720_bl.c
38969--- linux-2.6.32.44/drivers/video/backlight/jornada720_bl.c 2011-03-27 14:31:47.000000000 -0400
38970+++ linux-2.6.32.44/drivers/video/backlight/jornada720_bl.c 2011-04-17 15:56:46.000000000 -0400
38971@@ -93,7 +93,7 @@ out:
38972 return ret;
38973 }
38974
38975-static struct backlight_ops jornada_bl_ops = {
38976+static const struct backlight_ops jornada_bl_ops = {
38977 .get_brightness = jornada_bl_get_brightness,
38978 .update_status = jornada_bl_update_status,
38979 .options = BL_CORE_SUSPENDRESUME,
38980diff -urNp linux-2.6.32.44/drivers/video/backlight/kb3886_bl.c linux-2.6.32.44/drivers/video/backlight/kb3886_bl.c
38981--- linux-2.6.32.44/drivers/video/backlight/kb3886_bl.c 2011-03-27 14:31:47.000000000 -0400
38982+++ linux-2.6.32.44/drivers/video/backlight/kb3886_bl.c 2011-04-17 15:56:46.000000000 -0400
38983@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct
38984 return kb3886bl_intensity;
38985 }
38986
38987-static struct backlight_ops kb3886bl_ops = {
38988+static const struct backlight_ops kb3886bl_ops = {
38989 .get_brightness = kb3886bl_get_intensity,
38990 .update_status = kb3886bl_send_intensity,
38991 };
38992diff -urNp linux-2.6.32.44/drivers/video/backlight/locomolcd.c linux-2.6.32.44/drivers/video/backlight/locomolcd.c
38993--- linux-2.6.32.44/drivers/video/backlight/locomolcd.c 2011-03-27 14:31:47.000000000 -0400
38994+++ linux-2.6.32.44/drivers/video/backlight/locomolcd.c 2011-04-17 15:56:46.000000000 -0400
38995@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struc
38996 return current_intensity;
38997 }
38998
38999-static struct backlight_ops locomobl_data = {
39000+static const struct backlight_ops locomobl_data = {
39001 .get_brightness = locomolcd_get_intensity,
39002 .update_status = locomolcd_set_intensity,
39003 };
39004diff -urNp linux-2.6.32.44/drivers/video/backlight/mbp_nvidia_bl.c linux-2.6.32.44/drivers/video/backlight/mbp_nvidia_bl.c
39005--- linux-2.6.32.44/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:01.000000000 -0400
39006+++ linux-2.6.32.44/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:33.000000000 -0400
39007@@ -33,7 +33,7 @@ struct dmi_match_data {
39008 unsigned long iostart;
39009 unsigned long iolen;
39010 /* Backlight operations structure. */
39011- struct backlight_ops backlight_ops;
39012+ const struct backlight_ops backlight_ops;
39013 };
39014
39015 /* Module parameters. */
39016diff -urNp linux-2.6.32.44/drivers/video/backlight/omap1_bl.c linux-2.6.32.44/drivers/video/backlight/omap1_bl.c
39017--- linux-2.6.32.44/drivers/video/backlight/omap1_bl.c 2011-03-27 14:31:47.000000000 -0400
39018+++ linux-2.6.32.44/drivers/video/backlight/omap1_bl.c 2011-04-17 15:56:46.000000000 -0400
39019@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct b
39020 return bl->current_intensity;
39021 }
39022
39023-static struct backlight_ops omapbl_ops = {
39024+static const struct backlight_ops omapbl_ops = {
39025 .get_brightness = omapbl_get_intensity,
39026 .update_status = omapbl_update_status,
39027 };
39028diff -urNp linux-2.6.32.44/drivers/video/backlight/progear_bl.c linux-2.6.32.44/drivers/video/backlight/progear_bl.c
39029--- linux-2.6.32.44/drivers/video/backlight/progear_bl.c 2011-03-27 14:31:47.000000000 -0400
39030+++ linux-2.6.32.44/drivers/video/backlight/progear_bl.c 2011-04-17 15:56:46.000000000 -0400
39031@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struc
39032 return intensity - HW_LEVEL_MIN;
39033 }
39034
39035-static struct backlight_ops progearbl_ops = {
39036+static const struct backlight_ops progearbl_ops = {
39037 .get_brightness = progearbl_get_intensity,
39038 .update_status = progearbl_set_intensity,
39039 };
39040diff -urNp linux-2.6.32.44/drivers/video/backlight/pwm_bl.c linux-2.6.32.44/drivers/video/backlight/pwm_bl.c
39041--- linux-2.6.32.44/drivers/video/backlight/pwm_bl.c 2011-03-27 14:31:47.000000000 -0400
39042+++ linux-2.6.32.44/drivers/video/backlight/pwm_bl.c 2011-04-17 15:56:46.000000000 -0400
39043@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(
39044 return bl->props.brightness;
39045 }
39046
39047-static struct backlight_ops pwm_backlight_ops = {
39048+static const struct backlight_ops pwm_backlight_ops = {
39049 .update_status = pwm_backlight_update_status,
39050 .get_brightness = pwm_backlight_get_brightness,
39051 };
39052diff -urNp linux-2.6.32.44/drivers/video/backlight/tosa_bl.c linux-2.6.32.44/drivers/video/backlight/tosa_bl.c
39053--- linux-2.6.32.44/drivers/video/backlight/tosa_bl.c 2011-03-27 14:31:47.000000000 -0400
39054+++ linux-2.6.32.44/drivers/video/backlight/tosa_bl.c 2011-04-17 15:56:46.000000000 -0400
39055@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct
39056 return props->brightness;
39057 }
39058
39059-static struct backlight_ops bl_ops = {
39060+static const struct backlight_ops bl_ops = {
39061 .get_brightness = tosa_bl_get_brightness,
39062 .update_status = tosa_bl_update_status,
39063 };
39064diff -urNp linux-2.6.32.44/drivers/video/backlight/wm831x_bl.c linux-2.6.32.44/drivers/video/backlight/wm831x_bl.c
39065--- linux-2.6.32.44/drivers/video/backlight/wm831x_bl.c 2011-03-27 14:31:47.000000000 -0400
39066+++ linux-2.6.32.44/drivers/video/backlight/wm831x_bl.c 2011-04-17 15:56:46.000000000 -0400
39067@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightne
39068 return data->current_brightness;
39069 }
39070
39071-static struct backlight_ops wm831x_backlight_ops = {
39072+static const struct backlight_ops wm831x_backlight_ops = {
39073 .options = BL_CORE_SUSPENDRESUME,
39074 .update_status = wm831x_backlight_update_status,
39075 .get_brightness = wm831x_backlight_get_brightness,
39076diff -urNp linux-2.6.32.44/drivers/video/bf54x-lq043fb.c linux-2.6.32.44/drivers/video/bf54x-lq043fb.c
39077--- linux-2.6.32.44/drivers/video/bf54x-lq043fb.c 2011-03-27 14:31:47.000000000 -0400
39078+++ linux-2.6.32.44/drivers/video/bf54x-lq043fb.c 2011-04-17 15:56:46.000000000 -0400
39079@@ -463,7 +463,7 @@ static int bl_get_brightness(struct back
39080 return 0;
39081 }
39082
39083-static struct backlight_ops bfin_lq043fb_bl_ops = {
39084+static const struct backlight_ops bfin_lq043fb_bl_ops = {
39085 .get_brightness = bl_get_brightness,
39086 };
39087
39088diff -urNp linux-2.6.32.44/drivers/video/bfin-t350mcqb-fb.c linux-2.6.32.44/drivers/video/bfin-t350mcqb-fb.c
39089--- linux-2.6.32.44/drivers/video/bfin-t350mcqb-fb.c 2011-03-27 14:31:47.000000000 -0400
39090+++ linux-2.6.32.44/drivers/video/bfin-t350mcqb-fb.c 2011-04-17 15:56:46.000000000 -0400
39091@@ -381,7 +381,7 @@ static int bl_get_brightness(struct back
39092 return 0;
39093 }
39094
39095-static struct backlight_ops bfin_lq043fb_bl_ops = {
39096+static const struct backlight_ops bfin_lq043fb_bl_ops = {
39097 .get_brightness = bl_get_brightness,
39098 };
39099
39100diff -urNp linux-2.6.32.44/drivers/video/fbcmap.c linux-2.6.32.44/drivers/video/fbcmap.c
39101--- linux-2.6.32.44/drivers/video/fbcmap.c 2011-03-27 14:31:47.000000000 -0400
39102+++ linux-2.6.32.44/drivers/video/fbcmap.c 2011-04-17 15:56:46.000000000 -0400
39103@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user
39104 rc = -ENODEV;
39105 goto out;
39106 }
39107- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39108- !info->fbops->fb_setcmap)) {
39109+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39110 rc = -EINVAL;
39111 goto out1;
39112 }
39113diff -urNp linux-2.6.32.44/drivers/video/fbmem.c linux-2.6.32.44/drivers/video/fbmem.c
39114--- linux-2.6.32.44/drivers/video/fbmem.c 2011-03-27 14:31:47.000000000 -0400
39115+++ linux-2.6.32.44/drivers/video/fbmem.c 2011-05-16 21:46:57.000000000 -0400
39116@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_in
39117 image->dx += image->width + 8;
39118 }
39119 } else if (rotate == FB_ROTATE_UD) {
39120- for (x = 0; x < num && image->dx >= 0; x++) {
39121+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39122 info->fbops->fb_imageblit(info, image);
39123 image->dx -= image->width + 8;
39124 }
39125@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_in
39126 image->dy += image->height + 8;
39127 }
39128 } else if (rotate == FB_ROTATE_CCW) {
39129- for (x = 0; x < num && image->dy >= 0; x++) {
39130+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39131 info->fbops->fb_imageblit(info, image);
39132 image->dy -= image->height + 8;
39133 }
39134@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct
39135 int flags = info->flags;
39136 int ret = 0;
39137
39138+ pax_track_stack();
39139+
39140 if (var->activate & FB_ACTIVATE_INV_MODE) {
39141 struct fb_videomode mode1, mode2;
39142
39143@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *
39144 void __user *argp = (void __user *)arg;
39145 long ret = 0;
39146
39147+ pax_track_stack();
39148+
39149 switch (cmd) {
39150 case FBIOGET_VSCREENINFO:
39151 if (!lock_fb_info(info))
39152@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *
39153 return -EFAULT;
39154 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39155 return -EINVAL;
39156- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39157+ if (con2fb.framebuffer >= FB_MAX)
39158 return -EINVAL;
39159 if (!registered_fb[con2fb.framebuffer])
39160 request_module("fb%d", con2fb.framebuffer);
39161diff -urNp linux-2.6.32.44/drivers/video/i810/i810_accel.c linux-2.6.32.44/drivers/video/i810/i810_accel.c
39162--- linux-2.6.32.44/drivers/video/i810/i810_accel.c 2011-03-27 14:31:47.000000000 -0400
39163+++ linux-2.6.32.44/drivers/video/i810/i810_accel.c 2011-04-17 15:56:46.000000000 -0400
39164@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
39165 }
39166 }
39167 printk("ringbuffer lockup!!!\n");
39168+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39169 i810_report_error(mmio);
39170 par->dev_flags |= LOCKUP;
39171 info->pixmap.scan_align = 1;
39172diff -urNp linux-2.6.32.44/drivers/video/nvidia/nv_backlight.c linux-2.6.32.44/drivers/video/nvidia/nv_backlight.c
39173--- linux-2.6.32.44/drivers/video/nvidia/nv_backlight.c 2011-03-27 14:31:47.000000000 -0400
39174+++ linux-2.6.32.44/drivers/video/nvidia/nv_backlight.c 2011-04-17 15:56:46.000000000 -0400
39175@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(stru
39176 return bd->props.brightness;
39177 }
39178
39179-static struct backlight_ops nvidia_bl_ops = {
39180+static const struct backlight_ops nvidia_bl_ops = {
39181 .get_brightness = nvidia_bl_get_brightness,
39182 .update_status = nvidia_bl_update_status,
39183 };
39184diff -urNp linux-2.6.32.44/drivers/video/riva/fbdev.c linux-2.6.32.44/drivers/video/riva/fbdev.c
39185--- linux-2.6.32.44/drivers/video/riva/fbdev.c 2011-03-27 14:31:47.000000000 -0400
39186+++ linux-2.6.32.44/drivers/video/riva/fbdev.c 2011-04-17 15:56:46.000000000 -0400
39187@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct
39188 return bd->props.brightness;
39189 }
39190
39191-static struct backlight_ops riva_bl_ops = {
39192+static const struct backlight_ops riva_bl_ops = {
39193 .get_brightness = riva_bl_get_brightness,
39194 .update_status = riva_bl_update_status,
39195 };
39196diff -urNp linux-2.6.32.44/drivers/video/uvesafb.c linux-2.6.32.44/drivers/video/uvesafb.c
39197--- linux-2.6.32.44/drivers/video/uvesafb.c 2011-03-27 14:31:47.000000000 -0400
39198+++ linux-2.6.32.44/drivers/video/uvesafb.c 2011-04-17 15:56:46.000000000 -0400
39199@@ -18,6 +18,7 @@
39200 #include <linux/fb.h>
39201 #include <linux/io.h>
39202 #include <linux/mutex.h>
39203+#include <linux/moduleloader.h>
39204 #include <video/edid.h>
39205 #include <video/uvesafb.h>
39206 #ifdef CONFIG_X86
39207@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
39208 NULL,
39209 };
39210
39211- return call_usermodehelper(v86d_path, argv, envp, 1);
39212+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
39213 }
39214
39215 /*
39216@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(
39217 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
39218 par->pmi_setpal = par->ypan = 0;
39219 } else {
39220+
39221+#ifdef CONFIG_PAX_KERNEXEC
39222+#ifdef CONFIG_MODULES
39223+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
39224+#endif
39225+ if (!par->pmi_code) {
39226+ par->pmi_setpal = par->ypan = 0;
39227+ return 0;
39228+ }
39229+#endif
39230+
39231 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
39232 + task->t.regs.edi);
39233+
39234+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39235+ pax_open_kernel();
39236+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
39237+ pax_close_kernel();
39238+
39239+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
39240+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
39241+#else
39242 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
39243 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
39244+#endif
39245+
39246 printk(KERN_INFO "uvesafb: protected mode interface info at "
39247 "%04x:%04x\n",
39248 (u16)task->t.regs.es, (u16)task->t.regs.edi);
39249@@ -1799,6 +1822,11 @@ out:
39250 if (par->vbe_modes)
39251 kfree(par->vbe_modes);
39252
39253+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39254+ if (par->pmi_code)
39255+ module_free_exec(NULL, par->pmi_code);
39256+#endif
39257+
39258 framebuffer_release(info);
39259 return err;
39260 }
39261@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platfor
39262 kfree(par->vbe_state_orig);
39263 if (par->vbe_state_saved)
39264 kfree(par->vbe_state_saved);
39265+
39266+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39267+ if (par->pmi_code)
39268+ module_free_exec(NULL, par->pmi_code);
39269+#endif
39270+
39271 }
39272
39273 framebuffer_release(info);
39274diff -urNp linux-2.6.32.44/drivers/video/vesafb.c linux-2.6.32.44/drivers/video/vesafb.c
39275--- linux-2.6.32.44/drivers/video/vesafb.c 2011-03-27 14:31:47.000000000 -0400
39276+++ linux-2.6.32.44/drivers/video/vesafb.c 2011-08-05 20:33:55.000000000 -0400
39277@@ -9,6 +9,7 @@
39278 */
39279
39280 #include <linux/module.h>
39281+#include <linux/moduleloader.h>
39282 #include <linux/kernel.h>
39283 #include <linux/errno.h>
39284 #include <linux/string.h>
39285@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
39286 static int vram_total __initdata; /* Set total amount of memory */
39287 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
39288 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
39289-static void (*pmi_start)(void) __read_mostly;
39290-static void (*pmi_pal) (void) __read_mostly;
39291+static void (*pmi_start)(void) __read_only;
39292+static void (*pmi_pal) (void) __read_only;
39293 static int depth __read_mostly;
39294 static int vga_compat __read_mostly;
39295 /* --------------------------------------------------------------------- */
39296@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct pl
39297 unsigned int size_vmode;
39298 unsigned int size_remap;
39299 unsigned int size_total;
39300+ void *pmi_code = NULL;
39301
39302 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
39303 return -ENODEV;
39304@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct pl
39305 size_remap = size_total;
39306 vesafb_fix.smem_len = size_remap;
39307
39308-#ifndef __i386__
39309- screen_info.vesapm_seg = 0;
39310-#endif
39311-
39312 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
39313 printk(KERN_WARNING
39314 "vesafb: cannot reserve video memory at 0x%lx\n",
39315@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct pl
39316 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
39317 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
39318
39319+#ifdef __i386__
39320+
39321+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39322+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
39323+ if (!pmi_code)
39324+#elif !defined(CONFIG_PAX_KERNEXEC)
39325+ if (0)
39326+#endif
39327+
39328+#endif
39329+ screen_info.vesapm_seg = 0;
39330+
39331 if (screen_info.vesapm_seg) {
39332- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
39333- screen_info.vesapm_seg,screen_info.vesapm_off);
39334+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
39335+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
39336 }
39337
39338 if (screen_info.vesapm_seg < 0xc000)
39339@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct pl
39340
39341 if (ypan || pmi_setpal) {
39342 unsigned short *pmi_base;
39343+
39344 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
39345- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
39346- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
39347+
39348+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39349+ pax_open_kernel();
39350+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
39351+#else
39352+ pmi_code = pmi_base;
39353+#endif
39354+
39355+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
39356+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
39357+
39358+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39359+ pmi_start = ktva_ktla(pmi_start);
39360+ pmi_pal = ktva_ktla(pmi_pal);
39361+ pax_close_kernel();
39362+#endif
39363+
39364 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
39365 if (pmi_base[3]) {
39366 printk(KERN_INFO "vesafb: pmi: ports = ");
39367@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct pl
39368 info->node, info->fix.id);
39369 return 0;
39370 err:
39371+
39372+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39373+ module_free_exec(NULL, pmi_code);
39374+#endif
39375+
39376 if (info->screen_base)
39377 iounmap(info->screen_base);
39378 framebuffer_release(info);
39379diff -urNp linux-2.6.32.44/drivers/xen/sys-hypervisor.c linux-2.6.32.44/drivers/xen/sys-hypervisor.c
39380--- linux-2.6.32.44/drivers/xen/sys-hypervisor.c 2011-03-27 14:31:47.000000000 -0400
39381+++ linux-2.6.32.44/drivers/xen/sys-hypervisor.c 2011-04-17 15:56:46.000000000 -0400
39382@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct ko
39383 return 0;
39384 }
39385
39386-static struct sysfs_ops hyp_sysfs_ops = {
39387+static const struct sysfs_ops hyp_sysfs_ops = {
39388 .show = hyp_sysfs_show,
39389 .store = hyp_sysfs_store,
39390 };
39391diff -urNp linux-2.6.32.44/fs/9p/vfs_inode.c linux-2.6.32.44/fs/9p/vfs_inode.c
39392--- linux-2.6.32.44/fs/9p/vfs_inode.c 2011-03-27 14:31:47.000000000 -0400
39393+++ linux-2.6.32.44/fs/9p/vfs_inode.c 2011-04-17 15:56:46.000000000 -0400
39394@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct
39395 static void
39396 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39397 {
39398- char *s = nd_get_link(nd);
39399+ const char *s = nd_get_link(nd);
39400
39401 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
39402 IS_ERR(s) ? "<error>" : s);
39403diff -urNp linux-2.6.32.44/fs/aio.c linux-2.6.32.44/fs/aio.c
39404--- linux-2.6.32.44/fs/aio.c 2011-03-27 14:31:47.000000000 -0400
39405+++ linux-2.6.32.44/fs/aio.c 2011-06-04 20:40:21.000000000 -0400
39406@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx
39407 size += sizeof(struct io_event) * nr_events;
39408 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
39409
39410- if (nr_pages < 0)
39411+ if (nr_pages <= 0)
39412 return -EINVAL;
39413
39414 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
39415@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ct
39416 struct aio_timeout to;
39417 int retry = 0;
39418
39419+ pax_track_stack();
39420+
39421 /* needed to zero any padding within an entry (there shouldn't be
39422 * any, but C is fun!
39423 */
39424@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *i
39425 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
39426 {
39427 ssize_t ret;
39428+ struct iovec iovstack;
39429
39430 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
39431 kiocb->ki_nbytes, 1,
39432- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
39433+ &iovstack, &kiocb->ki_iovec);
39434 if (ret < 0)
39435 goto out;
39436
39437+ if (kiocb->ki_iovec == &iovstack) {
39438+ kiocb->ki_inline_vec = iovstack;
39439+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
39440+ }
39441 kiocb->ki_nr_segs = kiocb->ki_nbytes;
39442 kiocb->ki_cur_seg = 0;
39443 /* ki_nbytes/left now reflect bytes instead of segs */
39444diff -urNp linux-2.6.32.44/fs/attr.c linux-2.6.32.44/fs/attr.c
39445--- linux-2.6.32.44/fs/attr.c 2011-03-27 14:31:47.000000000 -0400
39446+++ linux-2.6.32.44/fs/attr.c 2011-04-17 15:56:46.000000000 -0400
39447@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode
39448 unsigned long limit;
39449
39450 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
39451+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
39452 if (limit != RLIM_INFINITY && offset > limit)
39453 goto out_sig;
39454 if (offset > inode->i_sb->s_maxbytes)
39455diff -urNp linux-2.6.32.44/fs/autofs/root.c linux-2.6.32.44/fs/autofs/root.c
39456--- linux-2.6.32.44/fs/autofs/root.c 2011-03-27 14:31:47.000000000 -0400
39457+++ linux-2.6.32.44/fs/autofs/root.c 2011-04-17 15:56:46.000000000 -0400
39458@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct in
39459 set_bit(n,sbi->symlink_bitmap);
39460 sl = &sbi->symlink[n];
39461 sl->len = strlen(symname);
39462- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
39463+ slsize = sl->len+1;
39464+ sl->data = kmalloc(slsize, GFP_KERNEL);
39465 if (!sl->data) {
39466 clear_bit(n,sbi->symlink_bitmap);
39467 unlock_kernel();
39468diff -urNp linux-2.6.32.44/fs/autofs4/symlink.c linux-2.6.32.44/fs/autofs4/symlink.c
39469--- linux-2.6.32.44/fs/autofs4/symlink.c 2011-03-27 14:31:47.000000000 -0400
39470+++ linux-2.6.32.44/fs/autofs4/symlink.c 2011-04-17 15:56:46.000000000 -0400
39471@@ -15,7 +15,7 @@
39472 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
39473 {
39474 struct autofs_info *ino = autofs4_dentry_ino(dentry);
39475- nd_set_link(nd, (char *)ino->u.symlink);
39476+ nd_set_link(nd, ino->u.symlink);
39477 return NULL;
39478 }
39479
39480diff -urNp linux-2.6.32.44/fs/befs/linuxvfs.c linux-2.6.32.44/fs/befs/linuxvfs.c
39481--- linux-2.6.32.44/fs/befs/linuxvfs.c 2011-03-27 14:31:47.000000000 -0400
39482+++ linux-2.6.32.44/fs/befs/linuxvfs.c 2011-04-17 15:56:46.000000000 -0400
39483@@ -493,7 +493,7 @@ static void befs_put_link(struct dentry
39484 {
39485 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
39486 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
39487- char *link = nd_get_link(nd);
39488+ const char *link = nd_get_link(nd);
39489 if (!IS_ERR(link))
39490 kfree(link);
39491 }
39492diff -urNp linux-2.6.32.44/fs/binfmt_aout.c linux-2.6.32.44/fs/binfmt_aout.c
39493--- linux-2.6.32.44/fs/binfmt_aout.c 2011-03-27 14:31:47.000000000 -0400
39494+++ linux-2.6.32.44/fs/binfmt_aout.c 2011-04-17 15:56:46.000000000 -0400
39495@@ -16,6 +16,7 @@
39496 #include <linux/string.h>
39497 #include <linux/fs.h>
39498 #include <linux/file.h>
39499+#include <linux/security.h>
39500 #include <linux/stat.h>
39501 #include <linux/fcntl.h>
39502 #include <linux/ptrace.h>
39503@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, st
39504 #endif
39505 # define START_STACK(u) (u.start_stack)
39506
39507+ memset(&dump, 0, sizeof(dump));
39508+
39509 fs = get_fs();
39510 set_fs(KERNEL_DS);
39511 has_dumped = 1;
39512@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, st
39513
39514 /* If the size of the dump file exceeds the rlimit, then see what would happen
39515 if we wrote the stack, but not the data area. */
39516+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
39517 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
39518 dump.u_dsize = 0;
39519
39520 /* Make sure we have enough room to write the stack and data areas. */
39521+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
39522 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
39523 dump.u_ssize = 0;
39524
39525@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, st
39526 dump_size = dump.u_ssize << PAGE_SHIFT;
39527 DUMP_WRITE(dump_start,dump_size);
39528 }
39529-/* Finally dump the task struct. Not be used by gdb, but could be useful */
39530- set_fs(KERNEL_DS);
39531- DUMP_WRITE(current,sizeof(*current));
39532+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
39533 end_coredump:
39534 set_fs(fs);
39535 return has_dumped;
39536@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux
39537 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
39538 if (rlim >= RLIM_INFINITY)
39539 rlim = ~0;
39540+
39541+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
39542 if (ex.a_data + ex.a_bss > rlim)
39543 return -ENOMEM;
39544
39545@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux
39546 install_exec_creds(bprm);
39547 current->flags &= ~PF_FORKNOEXEC;
39548
39549+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39550+ current->mm->pax_flags = 0UL;
39551+#endif
39552+
39553+#ifdef CONFIG_PAX_PAGEEXEC
39554+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
39555+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
39556+
39557+#ifdef CONFIG_PAX_EMUTRAMP
39558+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
39559+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
39560+#endif
39561+
39562+#ifdef CONFIG_PAX_MPROTECT
39563+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
39564+ current->mm->pax_flags |= MF_PAX_MPROTECT;
39565+#endif
39566+
39567+ }
39568+#endif
39569+
39570 if (N_MAGIC(ex) == OMAGIC) {
39571 unsigned long text_addr, map_size;
39572 loff_t pos;
39573@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux
39574
39575 down_write(&current->mm->mmap_sem);
39576 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
39577- PROT_READ | PROT_WRITE | PROT_EXEC,
39578+ PROT_READ | PROT_WRITE,
39579 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
39580 fd_offset + ex.a_text);
39581 up_write(&current->mm->mmap_sem);
39582diff -urNp linux-2.6.32.44/fs/binfmt_elf.c linux-2.6.32.44/fs/binfmt_elf.c
39583--- linux-2.6.32.44/fs/binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
39584+++ linux-2.6.32.44/fs/binfmt_elf.c 2011-05-16 21:46:57.000000000 -0400
39585@@ -50,6 +50,10 @@ static int elf_core_dump(long signr, str
39586 #define elf_core_dump NULL
39587 #endif
39588
39589+#ifdef CONFIG_PAX_MPROTECT
39590+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
39591+#endif
39592+
39593 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
39594 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
39595 #else
39596@@ -69,6 +73,11 @@ static struct linux_binfmt elf_format =
39597 .load_binary = load_elf_binary,
39598 .load_shlib = load_elf_library,
39599 .core_dump = elf_core_dump,
39600+
39601+#ifdef CONFIG_PAX_MPROTECT
39602+ .handle_mprotect= elf_handle_mprotect,
39603+#endif
39604+
39605 .min_coredump = ELF_EXEC_PAGESIZE,
39606 .hasvdso = 1
39607 };
39608@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
39609
39610 static int set_brk(unsigned long start, unsigned long end)
39611 {
39612+ unsigned long e = end;
39613+
39614 start = ELF_PAGEALIGN(start);
39615 end = ELF_PAGEALIGN(end);
39616 if (end > start) {
39617@@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
39618 if (BAD_ADDR(addr))
39619 return addr;
39620 }
39621- current->mm->start_brk = current->mm->brk = end;
39622+ current->mm->start_brk = current->mm->brk = e;
39623 return 0;
39624 }
39625
39626@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
39627 elf_addr_t __user *u_rand_bytes;
39628 const char *k_platform = ELF_PLATFORM;
39629 const char *k_base_platform = ELF_BASE_PLATFORM;
39630- unsigned char k_rand_bytes[16];
39631+ u32 k_rand_bytes[4];
39632 int items;
39633 elf_addr_t *elf_info;
39634 int ei_index = 0;
39635 const struct cred *cred = current_cred();
39636 struct vm_area_struct *vma;
39637+ unsigned long saved_auxv[AT_VECTOR_SIZE];
39638+
39639+ pax_track_stack();
39640
39641 /*
39642 * In some cases (e.g. Hyper-Threading), we want to avoid L1
39643@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
39644 * Generate 16 random bytes for userspace PRNG seeding.
39645 */
39646 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
39647- u_rand_bytes = (elf_addr_t __user *)
39648- STACK_ALLOC(p, sizeof(k_rand_bytes));
39649+ srandom32(k_rand_bytes[0] ^ random32());
39650+ srandom32(k_rand_bytes[1] ^ random32());
39651+ srandom32(k_rand_bytes[2] ^ random32());
39652+ srandom32(k_rand_bytes[3] ^ random32());
39653+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
39654+ u_rand_bytes = (elf_addr_t __user *) p;
39655 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
39656 return -EFAULT;
39657
39658@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
39659 return -EFAULT;
39660 current->mm->env_end = p;
39661
39662+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
39663+
39664 /* Put the elf_info on the stack in the right place. */
39665 sp = (elf_addr_t __user *)envp + 1;
39666- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
39667+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
39668 return -EFAULT;
39669 return 0;
39670 }
39671@@ -385,10 +405,10 @@ static unsigned long load_elf_interp(str
39672 {
39673 struct elf_phdr *elf_phdata;
39674 struct elf_phdr *eppnt;
39675- unsigned long load_addr = 0;
39676+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
39677 int load_addr_set = 0;
39678 unsigned long last_bss = 0, elf_bss = 0;
39679- unsigned long error = ~0UL;
39680+ unsigned long error = -EINVAL;
39681 unsigned long total_size;
39682 int retval, i, size;
39683
39684@@ -434,6 +454,11 @@ static unsigned long load_elf_interp(str
39685 goto out_close;
39686 }
39687
39688+#ifdef CONFIG_PAX_SEGMEXEC
39689+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
39690+ pax_task_size = SEGMEXEC_TASK_SIZE;
39691+#endif
39692+
39693 eppnt = elf_phdata;
39694 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
39695 if (eppnt->p_type == PT_LOAD) {
39696@@ -477,8 +502,8 @@ static unsigned long load_elf_interp(str
39697 k = load_addr + eppnt->p_vaddr;
39698 if (BAD_ADDR(k) ||
39699 eppnt->p_filesz > eppnt->p_memsz ||
39700- eppnt->p_memsz > TASK_SIZE ||
39701- TASK_SIZE - eppnt->p_memsz < k) {
39702+ eppnt->p_memsz > pax_task_size ||
39703+ pax_task_size - eppnt->p_memsz < k) {
39704 error = -ENOMEM;
39705 goto out_close;
39706 }
39707@@ -532,6 +557,194 @@ out:
39708 return error;
39709 }
39710
39711+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
39712+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
39713+{
39714+ unsigned long pax_flags = 0UL;
39715+
39716+#ifdef CONFIG_PAX_PAGEEXEC
39717+ if (elf_phdata->p_flags & PF_PAGEEXEC)
39718+ pax_flags |= MF_PAX_PAGEEXEC;
39719+#endif
39720+
39721+#ifdef CONFIG_PAX_SEGMEXEC
39722+ if (elf_phdata->p_flags & PF_SEGMEXEC)
39723+ pax_flags |= MF_PAX_SEGMEXEC;
39724+#endif
39725+
39726+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39727+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39728+ if (nx_enabled)
39729+ pax_flags &= ~MF_PAX_SEGMEXEC;
39730+ else
39731+ pax_flags &= ~MF_PAX_PAGEEXEC;
39732+ }
39733+#endif
39734+
39735+#ifdef CONFIG_PAX_EMUTRAMP
39736+ if (elf_phdata->p_flags & PF_EMUTRAMP)
39737+ pax_flags |= MF_PAX_EMUTRAMP;
39738+#endif
39739+
39740+#ifdef CONFIG_PAX_MPROTECT
39741+ if (elf_phdata->p_flags & PF_MPROTECT)
39742+ pax_flags |= MF_PAX_MPROTECT;
39743+#endif
39744+
39745+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39746+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
39747+ pax_flags |= MF_PAX_RANDMMAP;
39748+#endif
39749+
39750+ return pax_flags;
39751+}
39752+#endif
39753+
39754+#ifdef CONFIG_PAX_PT_PAX_FLAGS
39755+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
39756+{
39757+ unsigned long pax_flags = 0UL;
39758+
39759+#ifdef CONFIG_PAX_PAGEEXEC
39760+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
39761+ pax_flags |= MF_PAX_PAGEEXEC;
39762+#endif
39763+
39764+#ifdef CONFIG_PAX_SEGMEXEC
39765+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
39766+ pax_flags |= MF_PAX_SEGMEXEC;
39767+#endif
39768+
39769+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39770+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39771+ if (nx_enabled)
39772+ pax_flags &= ~MF_PAX_SEGMEXEC;
39773+ else
39774+ pax_flags &= ~MF_PAX_PAGEEXEC;
39775+ }
39776+#endif
39777+
39778+#ifdef CONFIG_PAX_EMUTRAMP
39779+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
39780+ pax_flags |= MF_PAX_EMUTRAMP;
39781+#endif
39782+
39783+#ifdef CONFIG_PAX_MPROTECT
39784+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
39785+ pax_flags |= MF_PAX_MPROTECT;
39786+#endif
39787+
39788+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39789+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
39790+ pax_flags |= MF_PAX_RANDMMAP;
39791+#endif
39792+
39793+ return pax_flags;
39794+}
39795+#endif
39796+
39797+#ifdef CONFIG_PAX_EI_PAX
39798+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
39799+{
39800+ unsigned long pax_flags = 0UL;
39801+
39802+#ifdef CONFIG_PAX_PAGEEXEC
39803+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
39804+ pax_flags |= MF_PAX_PAGEEXEC;
39805+#endif
39806+
39807+#ifdef CONFIG_PAX_SEGMEXEC
39808+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
39809+ pax_flags |= MF_PAX_SEGMEXEC;
39810+#endif
39811+
39812+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39813+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39814+ if (nx_enabled)
39815+ pax_flags &= ~MF_PAX_SEGMEXEC;
39816+ else
39817+ pax_flags &= ~MF_PAX_PAGEEXEC;
39818+ }
39819+#endif
39820+
39821+#ifdef CONFIG_PAX_EMUTRAMP
39822+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
39823+ pax_flags |= MF_PAX_EMUTRAMP;
39824+#endif
39825+
39826+#ifdef CONFIG_PAX_MPROTECT
39827+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
39828+ pax_flags |= MF_PAX_MPROTECT;
39829+#endif
39830+
39831+#ifdef CONFIG_PAX_ASLR
39832+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
39833+ pax_flags |= MF_PAX_RANDMMAP;
39834+#endif
39835+
39836+ return pax_flags;
39837+}
39838+#endif
39839+
39840+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
39841+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
39842+{
39843+ unsigned long pax_flags = 0UL;
39844+
39845+#ifdef CONFIG_PAX_PT_PAX_FLAGS
39846+ unsigned long i;
39847+ int found_flags = 0;
39848+#endif
39849+
39850+#ifdef CONFIG_PAX_EI_PAX
39851+ pax_flags = pax_parse_ei_pax(elf_ex);
39852+#endif
39853+
39854+#ifdef CONFIG_PAX_PT_PAX_FLAGS
39855+ for (i = 0UL; i < elf_ex->e_phnum; i++)
39856+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
39857+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
39858+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
39859+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
39860+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
39861+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
39862+ return -EINVAL;
39863+
39864+#ifdef CONFIG_PAX_SOFTMODE
39865+ if (pax_softmode)
39866+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
39867+ else
39868+#endif
39869+
39870+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
39871+ found_flags = 1;
39872+ break;
39873+ }
39874+#endif
39875+
39876+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
39877+ if (found_flags == 0) {
39878+ struct elf_phdr phdr;
39879+ memset(&phdr, 0, sizeof(phdr));
39880+ phdr.p_flags = PF_NOEMUTRAMP;
39881+#ifdef CONFIG_PAX_SOFTMODE
39882+ if (pax_softmode)
39883+ pax_flags = pax_parse_softmode(&phdr);
39884+ else
39885+#endif
39886+ pax_flags = pax_parse_hardmode(&phdr);
39887+ }
39888+#endif
39889+
39890+
39891+ if (0 > pax_check_flags(&pax_flags))
39892+ return -EINVAL;
39893+
39894+ current->mm->pax_flags = pax_flags;
39895+ return 0;
39896+}
39897+#endif
39898+
39899 /*
39900 * These are the functions used to load ELF style executables and shared
39901 * libraries. There is no binary dependent code anywhere else.
39902@@ -548,6 +761,11 @@ static unsigned long randomize_stack_top
39903 {
39904 unsigned int random_variable = 0;
39905
39906+#ifdef CONFIG_PAX_RANDUSTACK
39907+ if (randomize_va_space)
39908+ return stack_top - current->mm->delta_stack;
39909+#endif
39910+
39911 if ((current->flags & PF_RANDOMIZE) &&
39912 !(current->personality & ADDR_NO_RANDOMIZE)) {
39913 random_variable = get_random_int() & STACK_RND_MASK;
39914@@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_
39915 unsigned long load_addr = 0, load_bias = 0;
39916 int load_addr_set = 0;
39917 char * elf_interpreter = NULL;
39918- unsigned long error;
39919+ unsigned long error = 0;
39920 struct elf_phdr *elf_ppnt, *elf_phdata;
39921 unsigned long elf_bss, elf_brk;
39922 int retval, i;
39923@@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_
39924 unsigned long start_code, end_code, start_data, end_data;
39925 unsigned long reloc_func_desc = 0;
39926 int executable_stack = EXSTACK_DEFAULT;
39927- unsigned long def_flags = 0;
39928 struct {
39929 struct elfhdr elf_ex;
39930 struct elfhdr interp_elf_ex;
39931 } *loc;
39932+ unsigned long pax_task_size = TASK_SIZE;
39933
39934 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
39935 if (!loc) {
39936@@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_
39937
39938 /* OK, This is the point of no return */
39939 current->flags &= ~PF_FORKNOEXEC;
39940- current->mm->def_flags = def_flags;
39941+
39942+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39943+ current->mm->pax_flags = 0UL;
39944+#endif
39945+
39946+#ifdef CONFIG_PAX_DLRESOLVE
39947+ current->mm->call_dl_resolve = 0UL;
39948+#endif
39949+
39950+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
39951+ current->mm->call_syscall = 0UL;
39952+#endif
39953+
39954+#ifdef CONFIG_PAX_ASLR
39955+ current->mm->delta_mmap = 0UL;
39956+ current->mm->delta_stack = 0UL;
39957+#endif
39958+
39959+ current->mm->def_flags = 0;
39960+
39961+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
39962+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
39963+ send_sig(SIGKILL, current, 0);
39964+ goto out_free_dentry;
39965+ }
39966+#endif
39967+
39968+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
39969+ pax_set_initial_flags(bprm);
39970+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
39971+ if (pax_set_initial_flags_func)
39972+ (pax_set_initial_flags_func)(bprm);
39973+#endif
39974+
39975+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
39976+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
39977+ current->mm->context.user_cs_limit = PAGE_SIZE;
39978+ current->mm->def_flags |= VM_PAGEEXEC;
39979+ }
39980+#endif
39981+
39982+#ifdef CONFIG_PAX_SEGMEXEC
39983+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
39984+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
39985+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
39986+ pax_task_size = SEGMEXEC_TASK_SIZE;
39987+ }
39988+#endif
39989+
39990+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
39991+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39992+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
39993+ put_cpu();
39994+ }
39995+#endif
39996
39997 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
39998 may depend on the personality. */
39999 SET_PERSONALITY(loc->elf_ex);
40000+
40001+#ifdef CONFIG_PAX_ASLR
40002+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
40003+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
40004+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
40005+ }
40006+#endif
40007+
40008+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
40009+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40010+ executable_stack = EXSTACK_DISABLE_X;
40011+ current->personality &= ~READ_IMPLIES_EXEC;
40012+ } else
40013+#endif
40014+
40015 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
40016 current->personality |= READ_IMPLIES_EXEC;
40017
40018@@ -804,6 +1091,20 @@ static int load_elf_binary(struct linux_
40019 #else
40020 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
40021 #endif
40022+
40023+#ifdef CONFIG_PAX_RANDMMAP
40024+ /* PaX: randomize base address at the default exe base if requested */
40025+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
40026+#ifdef CONFIG_SPARC64
40027+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
40028+#else
40029+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
40030+#endif
40031+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
40032+ elf_flags |= MAP_FIXED;
40033+ }
40034+#endif
40035+
40036 }
40037
40038 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
40039@@ -836,9 +1137,9 @@ static int load_elf_binary(struct linux_
40040 * allowed task size. Note that p_filesz must always be
40041 * <= p_memsz so it is only necessary to check p_memsz.
40042 */
40043- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40044- elf_ppnt->p_memsz > TASK_SIZE ||
40045- TASK_SIZE - elf_ppnt->p_memsz < k) {
40046+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40047+ elf_ppnt->p_memsz > pax_task_size ||
40048+ pax_task_size - elf_ppnt->p_memsz < k) {
40049 /* set_brk can never work. Avoid overflows. */
40050 send_sig(SIGKILL, current, 0);
40051 retval = -EINVAL;
40052@@ -866,6 +1167,11 @@ static int load_elf_binary(struct linux_
40053 start_data += load_bias;
40054 end_data += load_bias;
40055
40056+#ifdef CONFIG_PAX_RANDMMAP
40057+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
40058+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
40059+#endif
40060+
40061 /* Calling set_brk effectively mmaps the pages that we need
40062 * for the bss and break sections. We must do this before
40063 * mapping in the interpreter, to make sure it doesn't wind
40064@@ -877,9 +1183,11 @@ static int load_elf_binary(struct linux_
40065 goto out_free_dentry;
40066 }
40067 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
40068- send_sig(SIGSEGV, current, 0);
40069- retval = -EFAULT; /* Nobody gets to see this, but.. */
40070- goto out_free_dentry;
40071+ /*
40072+ * This bss-zeroing can fail if the ELF
40073+ * file specifies odd protections. So
40074+ * we don't check the return value
40075+ */
40076 }
40077
40078 if (elf_interpreter) {
40079@@ -1112,8 +1420,10 @@ static int dump_seek(struct file *file,
40080 unsigned long n = off;
40081 if (n > PAGE_SIZE)
40082 n = PAGE_SIZE;
40083- if (!dump_write(file, buf, n))
40084+ if (!dump_write(file, buf, n)) {
40085+ free_page((unsigned long)buf);
40086 return 0;
40087+ }
40088 off -= n;
40089 }
40090 free_page((unsigned long)buf);
40091@@ -1125,7 +1435,7 @@ static int dump_seek(struct file *file,
40092 * Decide what to dump of a segment, part, all or none.
40093 */
40094 static unsigned long vma_dump_size(struct vm_area_struct *vma,
40095- unsigned long mm_flags)
40096+ unsigned long mm_flags, long signr)
40097 {
40098 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
40099
40100@@ -1159,7 +1469,7 @@ static unsigned long vma_dump_size(struc
40101 if (vma->vm_file == NULL)
40102 return 0;
40103
40104- if (FILTER(MAPPED_PRIVATE))
40105+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
40106 goto whole;
40107
40108 /*
40109@@ -1255,8 +1565,11 @@ static int writenote(struct memelfnote *
40110 #undef DUMP_WRITE
40111
40112 #define DUMP_WRITE(addr, nr) \
40113+ do { \
40114+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
40115 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
40116- goto end_coredump;
40117+ goto end_coredump; \
40118+ } while (0);
40119
40120 static void fill_elf_header(struct elfhdr *elf, int segs,
40121 u16 machine, u32 flags, u8 osabi)
40122@@ -1385,9 +1698,9 @@ static void fill_auxv_note(struct memelf
40123 {
40124 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
40125 int i = 0;
40126- do
40127+ do {
40128 i += 2;
40129- while (auxv[i - 2] != AT_NULL);
40130+ } while (auxv[i - 2] != AT_NULL);
40131 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
40132 }
40133
40134@@ -1973,7 +2286,7 @@ static int elf_core_dump(long signr, str
40135 phdr.p_offset = offset;
40136 phdr.p_vaddr = vma->vm_start;
40137 phdr.p_paddr = 0;
40138- phdr.p_filesz = vma_dump_size(vma, mm_flags);
40139+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
40140 phdr.p_memsz = vma->vm_end - vma->vm_start;
40141 offset += phdr.p_filesz;
40142 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
40143@@ -2006,7 +2319,7 @@ static int elf_core_dump(long signr, str
40144 unsigned long addr;
40145 unsigned long end;
40146
40147- end = vma->vm_start + vma_dump_size(vma, mm_flags);
40148+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
40149
40150 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
40151 struct page *page;
40152@@ -2015,6 +2328,7 @@ static int elf_core_dump(long signr, str
40153 page = get_dump_page(addr);
40154 if (page) {
40155 void *kaddr = kmap(page);
40156+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
40157 stop = ((size += PAGE_SIZE) > limit) ||
40158 !dump_write(file, kaddr, PAGE_SIZE);
40159 kunmap(page);
40160@@ -2042,6 +2356,97 @@ out:
40161
40162 #endif /* USE_ELF_CORE_DUMP */
40163
40164+#ifdef CONFIG_PAX_MPROTECT
40165+/* PaX: non-PIC ELF libraries need relocations on their executable segments
40166+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
40167+ * we'll remove VM_MAYWRITE for good on RELRO segments.
40168+ *
40169+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
40170+ * basis because we want to allow the common case and not the special ones.
40171+ */
40172+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
40173+{
40174+ struct elfhdr elf_h;
40175+ struct elf_phdr elf_p;
40176+ unsigned long i;
40177+ unsigned long oldflags;
40178+ bool is_textrel_rw, is_textrel_rx, is_relro;
40179+
40180+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
40181+ return;
40182+
40183+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
40184+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
40185+
40186+#ifdef CONFIG_PAX_ELFRELOCS
40187+ /* possible TEXTREL */
40188+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
40189+ 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);
40190+#else
40191+ is_textrel_rw = false;
40192+ is_textrel_rx = false;
40193+#endif
40194+
40195+ /* possible RELRO */
40196+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
40197+
40198+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
40199+ return;
40200+
40201+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
40202+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
40203+
40204+#ifdef CONFIG_PAX_ETEXECRELOCS
40205+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40206+#else
40207+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
40208+#endif
40209+
40210+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40211+ !elf_check_arch(&elf_h) ||
40212+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
40213+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
40214+ return;
40215+
40216+ for (i = 0UL; i < elf_h.e_phnum; i++) {
40217+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
40218+ return;
40219+ switch (elf_p.p_type) {
40220+ case PT_DYNAMIC:
40221+ if (!is_textrel_rw && !is_textrel_rx)
40222+ continue;
40223+ i = 0UL;
40224+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
40225+ elf_dyn dyn;
40226+
40227+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
40228+ return;
40229+ if (dyn.d_tag == DT_NULL)
40230+ return;
40231+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
40232+ gr_log_textrel(vma);
40233+ if (is_textrel_rw)
40234+ vma->vm_flags |= VM_MAYWRITE;
40235+ else
40236+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
40237+ vma->vm_flags &= ~VM_MAYWRITE;
40238+ return;
40239+ }
40240+ i++;
40241+ }
40242+ return;
40243+
40244+ case PT_GNU_RELRO:
40245+ if (!is_relro)
40246+ continue;
40247+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
40248+ vma->vm_flags &= ~VM_MAYWRITE;
40249+ return;
40250+ }
40251+ }
40252+}
40253+#endif
40254+
40255 static int __init init_elf_binfmt(void)
40256 {
40257 return register_binfmt(&elf_format);
40258diff -urNp linux-2.6.32.44/fs/binfmt_flat.c linux-2.6.32.44/fs/binfmt_flat.c
40259--- linux-2.6.32.44/fs/binfmt_flat.c 2011-03-27 14:31:47.000000000 -0400
40260+++ linux-2.6.32.44/fs/binfmt_flat.c 2011-04-17 15:56:46.000000000 -0400
40261@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_b
40262 realdatastart = (unsigned long) -ENOMEM;
40263 printk("Unable to allocate RAM for process data, errno %d\n",
40264 (int)-realdatastart);
40265+ down_write(&current->mm->mmap_sem);
40266 do_munmap(current->mm, textpos, text_len);
40267+ up_write(&current->mm->mmap_sem);
40268 ret = realdatastart;
40269 goto err;
40270 }
40271@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_b
40272 }
40273 if (IS_ERR_VALUE(result)) {
40274 printk("Unable to read data+bss, errno %d\n", (int)-result);
40275+ down_write(&current->mm->mmap_sem);
40276 do_munmap(current->mm, textpos, text_len);
40277 do_munmap(current->mm, realdatastart, data_len + extra);
40278+ up_write(&current->mm->mmap_sem);
40279 ret = result;
40280 goto err;
40281 }
40282@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_b
40283 }
40284 if (IS_ERR_VALUE(result)) {
40285 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
40286+ down_write(&current->mm->mmap_sem);
40287 do_munmap(current->mm, textpos, text_len + data_len + extra +
40288 MAX_SHARED_LIBS * sizeof(unsigned long));
40289+ up_write(&current->mm->mmap_sem);
40290 ret = result;
40291 goto err;
40292 }
40293diff -urNp linux-2.6.32.44/fs/bio.c linux-2.6.32.44/fs/bio.c
40294--- linux-2.6.32.44/fs/bio.c 2011-03-27 14:31:47.000000000 -0400
40295+++ linux-2.6.32.44/fs/bio.c 2011-04-17 15:56:46.000000000 -0400
40296@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_cr
40297
40298 i = 0;
40299 while (i < bio_slab_nr) {
40300- struct bio_slab *bslab = &bio_slabs[i];
40301+ bslab = &bio_slabs[i];
40302
40303 if (!bslab->slab && entry == -1)
40304 entry = i;
40305@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct b
40306 const int read = bio_data_dir(bio) == READ;
40307 struct bio_map_data *bmd = bio->bi_private;
40308 int i;
40309- char *p = bmd->sgvecs[0].iov_base;
40310+ char *p = (__force char *)bmd->sgvecs[0].iov_base;
40311
40312 __bio_for_each_segment(bvec, bio, i, 0) {
40313 char *addr = page_address(bvec->bv_page);
40314diff -urNp linux-2.6.32.44/fs/block_dev.c linux-2.6.32.44/fs/block_dev.c
40315--- linux-2.6.32.44/fs/block_dev.c 2011-08-09 18:35:29.000000000 -0400
40316+++ linux-2.6.32.44/fs/block_dev.c 2011-08-09 18:34:00.000000000 -0400
40317@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev,
40318 else if (bdev->bd_contains == bdev)
40319 res = 0; /* is a whole device which isn't held */
40320
40321- else if (bdev->bd_contains->bd_holder == bd_claim)
40322+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
40323 res = 0; /* is a partition of a device that is being partitioned */
40324 else if (bdev->bd_contains->bd_holder != NULL)
40325 res = -EBUSY; /* is a partition of a held device */
40326diff -urNp linux-2.6.32.44/fs/btrfs/ctree.c linux-2.6.32.44/fs/btrfs/ctree.c
40327--- linux-2.6.32.44/fs/btrfs/ctree.c 2011-03-27 14:31:47.000000000 -0400
40328+++ linux-2.6.32.44/fs/btrfs/ctree.c 2011-04-17 15:56:46.000000000 -0400
40329@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
40330 free_extent_buffer(buf);
40331 add_root_to_dirty_list(root);
40332 } else {
40333- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
40334- parent_start = parent->start;
40335- else
40336+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
40337+ if (parent)
40338+ parent_start = parent->start;
40339+ else
40340+ parent_start = 0;
40341+ } else
40342 parent_start = 0;
40343
40344 WARN_ON(trans->transid != btrfs_header_generation(parent));
40345@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_tran
40346
40347 ret = 0;
40348 if (slot == 0) {
40349- struct btrfs_disk_key disk_key;
40350 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
40351 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
40352 }
40353diff -urNp linux-2.6.32.44/fs/btrfs/disk-io.c linux-2.6.32.44/fs/btrfs/disk-io.c
40354--- linux-2.6.32.44/fs/btrfs/disk-io.c 2011-04-17 17:00:52.000000000 -0400
40355+++ linux-2.6.32.44/fs/btrfs/disk-io.c 2011-04-17 17:03:11.000000000 -0400
40356@@ -39,7 +39,7 @@
40357 #include "tree-log.h"
40358 #include "free-space-cache.h"
40359
40360-static struct extent_io_ops btree_extent_io_ops;
40361+static const struct extent_io_ops btree_extent_io_ops;
40362 static void end_workqueue_fn(struct btrfs_work *work);
40363 static void free_fs_root(struct btrfs_root *root);
40364
40365@@ -2607,7 +2607,7 @@ out:
40366 return 0;
40367 }
40368
40369-static struct extent_io_ops btree_extent_io_ops = {
40370+static const struct extent_io_ops btree_extent_io_ops = {
40371 .write_cache_pages_lock_hook = btree_lock_page_hook,
40372 .readpage_end_io_hook = btree_readpage_end_io_hook,
40373 .submit_bio_hook = btree_submit_bio_hook,
40374diff -urNp linux-2.6.32.44/fs/btrfs/extent_io.h linux-2.6.32.44/fs/btrfs/extent_io.h
40375--- linux-2.6.32.44/fs/btrfs/extent_io.h 2011-03-27 14:31:47.000000000 -0400
40376+++ linux-2.6.32.44/fs/btrfs/extent_io.h 2011-04-17 15:56:46.000000000 -0400
40377@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(s
40378 struct bio *bio, int mirror_num,
40379 unsigned long bio_flags);
40380 struct extent_io_ops {
40381- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
40382+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
40383 u64 start, u64 end, int *page_started,
40384 unsigned long *nr_written);
40385- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
40386- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
40387+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
40388+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
40389 extent_submit_bio_hook_t *submit_bio_hook;
40390- int (*merge_bio_hook)(struct page *page, unsigned long offset,
40391+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
40392 size_t size, struct bio *bio,
40393 unsigned long bio_flags);
40394- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
40395- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
40396+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
40397+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
40398 u64 start, u64 end,
40399 struct extent_state *state);
40400- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
40401+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
40402 u64 start, u64 end,
40403 struct extent_state *state);
40404- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
40405+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
40406 struct extent_state *state);
40407- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
40408+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
40409 struct extent_state *state, int uptodate);
40410- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
40411+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
40412 unsigned long old, unsigned long bits);
40413- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
40414+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
40415 unsigned long bits);
40416- int (*merge_extent_hook)(struct inode *inode,
40417+ int (* const merge_extent_hook)(struct inode *inode,
40418 struct extent_state *new,
40419 struct extent_state *other);
40420- int (*split_extent_hook)(struct inode *inode,
40421+ int (* const split_extent_hook)(struct inode *inode,
40422 struct extent_state *orig, u64 split);
40423- int (*write_cache_pages_lock_hook)(struct page *page);
40424+ int (* const write_cache_pages_lock_hook)(struct page *page);
40425 };
40426
40427 struct extent_io_tree {
40428@@ -88,7 +88,7 @@ struct extent_io_tree {
40429 u64 dirty_bytes;
40430 spinlock_t lock;
40431 spinlock_t buffer_lock;
40432- struct extent_io_ops *ops;
40433+ const struct extent_io_ops *ops;
40434 };
40435
40436 struct extent_state {
40437diff -urNp linux-2.6.32.44/fs/btrfs/extent-tree.c linux-2.6.32.44/fs/btrfs/extent-tree.c
40438--- linux-2.6.32.44/fs/btrfs/extent-tree.c 2011-03-27 14:31:47.000000000 -0400
40439+++ linux-2.6.32.44/fs/btrfs/extent-tree.c 2011-06-12 06:39:08.000000000 -0400
40440@@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(
40441 u64 group_start = group->key.objectid;
40442 new_extents = kmalloc(sizeof(*new_extents),
40443 GFP_NOFS);
40444+ if (!new_extents) {
40445+ ret = -ENOMEM;
40446+ goto out;
40447+ }
40448 nr_extents = 1;
40449 ret = get_new_locations(reloc_inode,
40450 extent_key,
40451diff -urNp linux-2.6.32.44/fs/btrfs/free-space-cache.c linux-2.6.32.44/fs/btrfs/free-space-cache.c
40452--- linux-2.6.32.44/fs/btrfs/free-space-cache.c 2011-03-27 14:31:47.000000000 -0400
40453+++ linux-2.6.32.44/fs/btrfs/free-space-cache.c 2011-04-17 15:56:46.000000000 -0400
40454@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
40455
40456 while(1) {
40457 if (entry->bytes < bytes || entry->offset < min_start) {
40458- struct rb_node *node;
40459-
40460 node = rb_next(&entry->offset_index);
40461 if (!node)
40462 break;
40463@@ -1226,7 +1224,7 @@ again:
40464 */
40465 while (entry->bitmap || found_bitmap ||
40466 (!entry->bitmap && entry->bytes < min_bytes)) {
40467- struct rb_node *node = rb_next(&entry->offset_index);
40468+ node = rb_next(&entry->offset_index);
40469
40470 if (entry->bitmap && entry->bytes > bytes + empty_size) {
40471 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
40472diff -urNp linux-2.6.32.44/fs/btrfs/inode.c linux-2.6.32.44/fs/btrfs/inode.c
40473--- linux-2.6.32.44/fs/btrfs/inode.c 2011-03-27 14:31:47.000000000 -0400
40474+++ linux-2.6.32.44/fs/btrfs/inode.c 2011-06-12 06:39:58.000000000 -0400
40475@@ -63,7 +63,7 @@ static const struct inode_operations btr
40476 static const struct address_space_operations btrfs_aops;
40477 static const struct address_space_operations btrfs_symlink_aops;
40478 static const struct file_operations btrfs_dir_file_operations;
40479-static struct extent_io_ops btrfs_extent_io_ops;
40480+static const struct extent_io_ops btrfs_extent_io_ops;
40481
40482 static struct kmem_cache *btrfs_inode_cachep;
40483 struct kmem_cache *btrfs_trans_handle_cachep;
40484@@ -925,6 +925,7 @@ static int cow_file_range_async(struct i
40485 1, 0, NULL, GFP_NOFS);
40486 while (start < end) {
40487 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
40488+ BUG_ON(!async_cow);
40489 async_cow->inode = inode;
40490 async_cow->root = root;
40491 async_cow->locked_page = locked_page;
40492@@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(st
40493 inline_size = btrfs_file_extent_inline_item_len(leaf,
40494 btrfs_item_nr(leaf, path->slots[0]));
40495 tmp = kmalloc(inline_size, GFP_NOFS);
40496+ if (!tmp)
40497+ return -ENOMEM;
40498 ptr = btrfs_file_extent_inline_start(item);
40499
40500 read_extent_buffer(leaf, tmp, ptr, inline_size);
40501@@ -5410,7 +5413,7 @@ fail:
40502 return -ENOMEM;
40503 }
40504
40505-static int btrfs_getattr(struct vfsmount *mnt,
40506+int btrfs_getattr(struct vfsmount *mnt,
40507 struct dentry *dentry, struct kstat *stat)
40508 {
40509 struct inode *inode = dentry->d_inode;
40510@@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount
40511 return 0;
40512 }
40513
40514+EXPORT_SYMBOL(btrfs_getattr);
40515+
40516+dev_t get_btrfs_dev_from_inode(struct inode *inode)
40517+{
40518+ return BTRFS_I(inode)->root->anon_super.s_dev;
40519+}
40520+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
40521+
40522 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
40523 struct inode *new_dir, struct dentry *new_dentry)
40524 {
40525@@ -5972,7 +5983,7 @@ static const struct file_operations btrf
40526 .fsync = btrfs_sync_file,
40527 };
40528
40529-static struct extent_io_ops btrfs_extent_io_ops = {
40530+static const struct extent_io_ops btrfs_extent_io_ops = {
40531 .fill_delalloc = run_delalloc_range,
40532 .submit_bio_hook = btrfs_submit_bio_hook,
40533 .merge_bio_hook = btrfs_merge_bio_hook,
40534diff -urNp linux-2.6.32.44/fs/btrfs/relocation.c linux-2.6.32.44/fs/btrfs/relocation.c
40535--- linux-2.6.32.44/fs/btrfs/relocation.c 2011-03-27 14:31:47.000000000 -0400
40536+++ linux-2.6.32.44/fs/btrfs/relocation.c 2011-04-17 15:56:46.000000000 -0400
40537@@ -884,7 +884,7 @@ static int __update_reloc_root(struct bt
40538 }
40539 spin_unlock(&rc->reloc_root_tree.lock);
40540
40541- BUG_ON((struct btrfs_root *)node->data != root);
40542+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
40543
40544 if (!del) {
40545 spin_lock(&rc->reloc_root_tree.lock);
40546diff -urNp linux-2.6.32.44/fs/btrfs/sysfs.c linux-2.6.32.44/fs/btrfs/sysfs.c
40547--- linux-2.6.32.44/fs/btrfs/sysfs.c 2011-03-27 14:31:47.000000000 -0400
40548+++ linux-2.6.32.44/fs/btrfs/sysfs.c 2011-04-17 15:56:46.000000000 -0400
40549@@ -164,12 +164,12 @@ static void btrfs_root_release(struct ko
40550 complete(&root->kobj_unregister);
40551 }
40552
40553-static struct sysfs_ops btrfs_super_attr_ops = {
40554+static const struct sysfs_ops btrfs_super_attr_ops = {
40555 .show = btrfs_super_attr_show,
40556 .store = btrfs_super_attr_store,
40557 };
40558
40559-static struct sysfs_ops btrfs_root_attr_ops = {
40560+static const struct sysfs_ops btrfs_root_attr_ops = {
40561 .show = btrfs_root_attr_show,
40562 .store = btrfs_root_attr_store,
40563 };
40564diff -urNp linux-2.6.32.44/fs/buffer.c linux-2.6.32.44/fs/buffer.c
40565--- linux-2.6.32.44/fs/buffer.c 2011-03-27 14:31:47.000000000 -0400
40566+++ linux-2.6.32.44/fs/buffer.c 2011-04-17 15:56:46.000000000 -0400
40567@@ -25,6 +25,7 @@
40568 #include <linux/percpu.h>
40569 #include <linux/slab.h>
40570 #include <linux/capability.h>
40571+#include <linux/security.h>
40572 #include <linux/blkdev.h>
40573 #include <linux/file.h>
40574 #include <linux/quotaops.h>
40575diff -urNp linux-2.6.32.44/fs/cachefiles/bind.c linux-2.6.32.44/fs/cachefiles/bind.c
40576--- linux-2.6.32.44/fs/cachefiles/bind.c 2011-03-27 14:31:47.000000000 -0400
40577+++ linux-2.6.32.44/fs/cachefiles/bind.c 2011-04-17 15:56:46.000000000 -0400
40578@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
40579 args);
40580
40581 /* start by checking things over */
40582- ASSERT(cache->fstop_percent >= 0 &&
40583- cache->fstop_percent < cache->fcull_percent &&
40584+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
40585 cache->fcull_percent < cache->frun_percent &&
40586 cache->frun_percent < 100);
40587
40588- ASSERT(cache->bstop_percent >= 0 &&
40589- cache->bstop_percent < cache->bcull_percent &&
40590+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
40591 cache->bcull_percent < cache->brun_percent &&
40592 cache->brun_percent < 100);
40593
40594diff -urNp linux-2.6.32.44/fs/cachefiles/daemon.c linux-2.6.32.44/fs/cachefiles/daemon.c
40595--- linux-2.6.32.44/fs/cachefiles/daemon.c 2011-03-27 14:31:47.000000000 -0400
40596+++ linux-2.6.32.44/fs/cachefiles/daemon.c 2011-04-17 15:56:46.000000000 -0400
40597@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(s
40598 if (test_bit(CACHEFILES_DEAD, &cache->flags))
40599 return -EIO;
40600
40601- if (datalen < 0 || datalen > PAGE_SIZE - 1)
40602+ if (datalen > PAGE_SIZE - 1)
40603 return -EOPNOTSUPP;
40604
40605 /* drag the command string into the kernel so we can parse it */
40606@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struc
40607 if (args[0] != '%' || args[1] != '\0')
40608 return -EINVAL;
40609
40610- if (fstop < 0 || fstop >= cache->fcull_percent)
40611+ if (fstop >= cache->fcull_percent)
40612 return cachefiles_daemon_range_error(cache, args);
40613
40614 cache->fstop_percent = fstop;
40615@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struc
40616 if (args[0] != '%' || args[1] != '\0')
40617 return -EINVAL;
40618
40619- if (bstop < 0 || bstop >= cache->bcull_percent)
40620+ if (bstop >= cache->bcull_percent)
40621 return cachefiles_daemon_range_error(cache, args);
40622
40623 cache->bstop_percent = bstop;
40624diff -urNp linux-2.6.32.44/fs/cachefiles/internal.h linux-2.6.32.44/fs/cachefiles/internal.h
40625--- linux-2.6.32.44/fs/cachefiles/internal.h 2011-03-27 14:31:47.000000000 -0400
40626+++ linux-2.6.32.44/fs/cachefiles/internal.h 2011-05-04 17:56:28.000000000 -0400
40627@@ -56,7 +56,7 @@ struct cachefiles_cache {
40628 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
40629 struct rb_root active_nodes; /* active nodes (can't be culled) */
40630 rwlock_t active_lock; /* lock for active_nodes */
40631- atomic_t gravecounter; /* graveyard uniquifier */
40632+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
40633 unsigned frun_percent; /* when to stop culling (% files) */
40634 unsigned fcull_percent; /* when to start culling (% files) */
40635 unsigned fstop_percent; /* when to stop allocating (% files) */
40636@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struc
40637 * proc.c
40638 */
40639 #ifdef CONFIG_CACHEFILES_HISTOGRAM
40640-extern atomic_t cachefiles_lookup_histogram[HZ];
40641-extern atomic_t cachefiles_mkdir_histogram[HZ];
40642-extern atomic_t cachefiles_create_histogram[HZ];
40643+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40644+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40645+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
40646
40647 extern int __init cachefiles_proc_init(void);
40648 extern void cachefiles_proc_cleanup(void);
40649 static inline
40650-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
40651+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
40652 {
40653 unsigned long jif = jiffies - start_jif;
40654 if (jif >= HZ)
40655 jif = HZ - 1;
40656- atomic_inc(&histogram[jif]);
40657+ atomic_inc_unchecked(&histogram[jif]);
40658 }
40659
40660 #else
40661diff -urNp linux-2.6.32.44/fs/cachefiles/namei.c linux-2.6.32.44/fs/cachefiles/namei.c
40662--- linux-2.6.32.44/fs/cachefiles/namei.c 2011-03-27 14:31:47.000000000 -0400
40663+++ linux-2.6.32.44/fs/cachefiles/namei.c 2011-05-04 17:56:28.000000000 -0400
40664@@ -250,7 +250,7 @@ try_again:
40665 /* first step is to make up a grave dentry in the graveyard */
40666 sprintf(nbuffer, "%08x%08x",
40667 (uint32_t) get_seconds(),
40668- (uint32_t) atomic_inc_return(&cache->gravecounter));
40669+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
40670
40671 /* do the multiway lock magic */
40672 trap = lock_rename(cache->graveyard, dir);
40673diff -urNp linux-2.6.32.44/fs/cachefiles/proc.c linux-2.6.32.44/fs/cachefiles/proc.c
40674--- linux-2.6.32.44/fs/cachefiles/proc.c 2011-03-27 14:31:47.000000000 -0400
40675+++ linux-2.6.32.44/fs/cachefiles/proc.c 2011-05-04 17:56:28.000000000 -0400
40676@@ -14,9 +14,9 @@
40677 #include <linux/seq_file.h>
40678 #include "internal.h"
40679
40680-atomic_t cachefiles_lookup_histogram[HZ];
40681-atomic_t cachefiles_mkdir_histogram[HZ];
40682-atomic_t cachefiles_create_histogram[HZ];
40683+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40684+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40685+atomic_unchecked_t cachefiles_create_histogram[HZ];
40686
40687 /*
40688 * display the latency histogram
40689@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
40690 return 0;
40691 default:
40692 index = (unsigned long) v - 3;
40693- x = atomic_read(&cachefiles_lookup_histogram[index]);
40694- y = atomic_read(&cachefiles_mkdir_histogram[index]);
40695- z = atomic_read(&cachefiles_create_histogram[index]);
40696+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
40697+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
40698+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
40699 if (x == 0 && y == 0 && z == 0)
40700 return 0;
40701
40702diff -urNp linux-2.6.32.44/fs/cachefiles/rdwr.c linux-2.6.32.44/fs/cachefiles/rdwr.c
40703--- linux-2.6.32.44/fs/cachefiles/rdwr.c 2011-03-27 14:31:47.000000000 -0400
40704+++ linux-2.6.32.44/fs/cachefiles/rdwr.c 2011-04-17 15:56:46.000000000 -0400
40705@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache
40706 old_fs = get_fs();
40707 set_fs(KERNEL_DS);
40708 ret = file->f_op->write(
40709- file, (const void __user *) data, len, &pos);
40710+ file, (__force const void __user *) data, len, &pos);
40711 set_fs(old_fs);
40712 kunmap(page);
40713 if (ret != len)
40714diff -urNp linux-2.6.32.44/fs/cifs/cifs_debug.c linux-2.6.32.44/fs/cifs/cifs_debug.c
40715--- linux-2.6.32.44/fs/cifs/cifs_debug.c 2011-03-27 14:31:47.000000000 -0400
40716+++ linux-2.6.32.44/fs/cifs/cifs_debug.c 2011-05-04 17:56:28.000000000 -0400
40717@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(str
40718 tcon = list_entry(tmp3,
40719 struct cifsTconInfo,
40720 tcon_list);
40721- atomic_set(&tcon->num_smbs_sent, 0);
40722- atomic_set(&tcon->num_writes, 0);
40723- atomic_set(&tcon->num_reads, 0);
40724- atomic_set(&tcon->num_oplock_brks, 0);
40725- atomic_set(&tcon->num_opens, 0);
40726- atomic_set(&tcon->num_posixopens, 0);
40727- atomic_set(&tcon->num_posixmkdirs, 0);
40728- atomic_set(&tcon->num_closes, 0);
40729- atomic_set(&tcon->num_deletes, 0);
40730- atomic_set(&tcon->num_mkdirs, 0);
40731- atomic_set(&tcon->num_rmdirs, 0);
40732- atomic_set(&tcon->num_renames, 0);
40733- atomic_set(&tcon->num_t2renames, 0);
40734- atomic_set(&tcon->num_ffirst, 0);
40735- atomic_set(&tcon->num_fnext, 0);
40736- atomic_set(&tcon->num_fclose, 0);
40737- atomic_set(&tcon->num_hardlinks, 0);
40738- atomic_set(&tcon->num_symlinks, 0);
40739- atomic_set(&tcon->num_locks, 0);
40740+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
40741+ atomic_set_unchecked(&tcon->num_writes, 0);
40742+ atomic_set_unchecked(&tcon->num_reads, 0);
40743+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
40744+ atomic_set_unchecked(&tcon->num_opens, 0);
40745+ atomic_set_unchecked(&tcon->num_posixopens, 0);
40746+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
40747+ atomic_set_unchecked(&tcon->num_closes, 0);
40748+ atomic_set_unchecked(&tcon->num_deletes, 0);
40749+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
40750+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
40751+ atomic_set_unchecked(&tcon->num_renames, 0);
40752+ atomic_set_unchecked(&tcon->num_t2renames, 0);
40753+ atomic_set_unchecked(&tcon->num_ffirst, 0);
40754+ atomic_set_unchecked(&tcon->num_fnext, 0);
40755+ atomic_set_unchecked(&tcon->num_fclose, 0);
40756+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
40757+ atomic_set_unchecked(&tcon->num_symlinks, 0);
40758+ atomic_set_unchecked(&tcon->num_locks, 0);
40759 }
40760 }
40761 }
40762@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct s
40763 if (tcon->need_reconnect)
40764 seq_puts(m, "\tDISCONNECTED ");
40765 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
40766- atomic_read(&tcon->num_smbs_sent),
40767- atomic_read(&tcon->num_oplock_brks));
40768+ atomic_read_unchecked(&tcon->num_smbs_sent),
40769+ atomic_read_unchecked(&tcon->num_oplock_brks));
40770 seq_printf(m, "\nReads: %d Bytes: %lld",
40771- atomic_read(&tcon->num_reads),
40772+ atomic_read_unchecked(&tcon->num_reads),
40773 (long long)(tcon->bytes_read));
40774 seq_printf(m, "\nWrites: %d Bytes: %lld",
40775- atomic_read(&tcon->num_writes),
40776+ atomic_read_unchecked(&tcon->num_writes),
40777 (long long)(tcon->bytes_written));
40778 seq_printf(m, "\nFlushes: %d",
40779- atomic_read(&tcon->num_flushes));
40780+ atomic_read_unchecked(&tcon->num_flushes));
40781 seq_printf(m, "\nLocks: %d HardLinks: %d "
40782 "Symlinks: %d",
40783- atomic_read(&tcon->num_locks),
40784- atomic_read(&tcon->num_hardlinks),
40785- atomic_read(&tcon->num_symlinks));
40786+ atomic_read_unchecked(&tcon->num_locks),
40787+ atomic_read_unchecked(&tcon->num_hardlinks),
40788+ atomic_read_unchecked(&tcon->num_symlinks));
40789 seq_printf(m, "\nOpens: %d Closes: %d "
40790 "Deletes: %d",
40791- atomic_read(&tcon->num_opens),
40792- atomic_read(&tcon->num_closes),
40793- atomic_read(&tcon->num_deletes));
40794+ atomic_read_unchecked(&tcon->num_opens),
40795+ atomic_read_unchecked(&tcon->num_closes),
40796+ atomic_read_unchecked(&tcon->num_deletes));
40797 seq_printf(m, "\nPosix Opens: %d "
40798 "Posix Mkdirs: %d",
40799- atomic_read(&tcon->num_posixopens),
40800- atomic_read(&tcon->num_posixmkdirs));
40801+ atomic_read_unchecked(&tcon->num_posixopens),
40802+ atomic_read_unchecked(&tcon->num_posixmkdirs));
40803 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
40804- atomic_read(&tcon->num_mkdirs),
40805- atomic_read(&tcon->num_rmdirs));
40806+ atomic_read_unchecked(&tcon->num_mkdirs),
40807+ atomic_read_unchecked(&tcon->num_rmdirs));
40808 seq_printf(m, "\nRenames: %d T2 Renames %d",
40809- atomic_read(&tcon->num_renames),
40810- atomic_read(&tcon->num_t2renames));
40811+ atomic_read_unchecked(&tcon->num_renames),
40812+ atomic_read_unchecked(&tcon->num_t2renames));
40813 seq_printf(m, "\nFindFirst: %d FNext %d "
40814 "FClose %d",
40815- atomic_read(&tcon->num_ffirst),
40816- atomic_read(&tcon->num_fnext),
40817- atomic_read(&tcon->num_fclose));
40818+ atomic_read_unchecked(&tcon->num_ffirst),
40819+ atomic_read_unchecked(&tcon->num_fnext),
40820+ atomic_read_unchecked(&tcon->num_fclose));
40821 }
40822 }
40823 }
40824diff -urNp linux-2.6.32.44/fs/cifs/cifsglob.h linux-2.6.32.44/fs/cifs/cifsglob.h
40825--- linux-2.6.32.44/fs/cifs/cifsglob.h 2011-08-09 18:35:29.000000000 -0400
40826+++ linux-2.6.32.44/fs/cifs/cifsglob.h 2011-08-09 18:34:00.000000000 -0400
40827@@ -252,28 +252,28 @@ struct cifsTconInfo {
40828 __u16 Flags; /* optional support bits */
40829 enum statusEnum tidStatus;
40830 #ifdef CONFIG_CIFS_STATS
40831- atomic_t num_smbs_sent;
40832- atomic_t num_writes;
40833- atomic_t num_reads;
40834- atomic_t num_flushes;
40835- atomic_t num_oplock_brks;
40836- atomic_t num_opens;
40837- atomic_t num_closes;
40838- atomic_t num_deletes;
40839- atomic_t num_mkdirs;
40840- atomic_t num_posixopens;
40841- atomic_t num_posixmkdirs;
40842- atomic_t num_rmdirs;
40843- atomic_t num_renames;
40844- atomic_t num_t2renames;
40845- atomic_t num_ffirst;
40846- atomic_t num_fnext;
40847- atomic_t num_fclose;
40848- atomic_t num_hardlinks;
40849- atomic_t num_symlinks;
40850- atomic_t num_locks;
40851- atomic_t num_acl_get;
40852- atomic_t num_acl_set;
40853+ atomic_unchecked_t num_smbs_sent;
40854+ atomic_unchecked_t num_writes;
40855+ atomic_unchecked_t num_reads;
40856+ atomic_unchecked_t num_flushes;
40857+ atomic_unchecked_t num_oplock_brks;
40858+ atomic_unchecked_t num_opens;
40859+ atomic_unchecked_t num_closes;
40860+ atomic_unchecked_t num_deletes;
40861+ atomic_unchecked_t num_mkdirs;
40862+ atomic_unchecked_t num_posixopens;
40863+ atomic_unchecked_t num_posixmkdirs;
40864+ atomic_unchecked_t num_rmdirs;
40865+ atomic_unchecked_t num_renames;
40866+ atomic_unchecked_t num_t2renames;
40867+ atomic_unchecked_t num_ffirst;
40868+ atomic_unchecked_t num_fnext;
40869+ atomic_unchecked_t num_fclose;
40870+ atomic_unchecked_t num_hardlinks;
40871+ atomic_unchecked_t num_symlinks;
40872+ atomic_unchecked_t num_locks;
40873+ atomic_unchecked_t num_acl_get;
40874+ atomic_unchecked_t num_acl_set;
40875 #ifdef CONFIG_CIFS_STATS2
40876 unsigned long long time_writes;
40877 unsigned long long time_reads;
40878@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const st
40879 }
40880
40881 #ifdef CONFIG_CIFS_STATS
40882-#define cifs_stats_inc atomic_inc
40883+#define cifs_stats_inc atomic_inc_unchecked
40884
40885 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
40886 unsigned int bytes)
40887diff -urNp linux-2.6.32.44/fs/cifs/link.c linux-2.6.32.44/fs/cifs/link.c
40888--- linux-2.6.32.44/fs/cifs/link.c 2011-03-27 14:31:47.000000000 -0400
40889+++ linux-2.6.32.44/fs/cifs/link.c 2011-04-17 15:56:46.000000000 -0400
40890@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct
40891
40892 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
40893 {
40894- char *p = nd_get_link(nd);
40895+ const char *p = nd_get_link(nd);
40896 if (!IS_ERR(p))
40897 kfree(p);
40898 }
40899diff -urNp linux-2.6.32.44/fs/coda/cache.c linux-2.6.32.44/fs/coda/cache.c
40900--- linux-2.6.32.44/fs/coda/cache.c 2011-03-27 14:31:47.000000000 -0400
40901+++ linux-2.6.32.44/fs/coda/cache.c 2011-05-04 17:56:28.000000000 -0400
40902@@ -24,14 +24,14 @@
40903 #include <linux/coda_fs_i.h>
40904 #include <linux/coda_cache.h>
40905
40906-static atomic_t permission_epoch = ATOMIC_INIT(0);
40907+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
40908
40909 /* replace or extend an acl cache hit */
40910 void coda_cache_enter(struct inode *inode, int mask)
40911 {
40912 struct coda_inode_info *cii = ITOC(inode);
40913
40914- cii->c_cached_epoch = atomic_read(&permission_epoch);
40915+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
40916 if (cii->c_uid != current_fsuid()) {
40917 cii->c_uid = current_fsuid();
40918 cii->c_cached_perm = mask;
40919@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inod
40920 void coda_cache_clear_inode(struct inode *inode)
40921 {
40922 struct coda_inode_info *cii = ITOC(inode);
40923- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
40924+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
40925 }
40926
40927 /* remove all acl caches */
40928 void coda_cache_clear_all(struct super_block *sb)
40929 {
40930- atomic_inc(&permission_epoch);
40931+ atomic_inc_unchecked(&permission_epoch);
40932 }
40933
40934
40935@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode
40936
40937 hit = (mask & cii->c_cached_perm) == mask &&
40938 cii->c_uid == current_fsuid() &&
40939- cii->c_cached_epoch == atomic_read(&permission_epoch);
40940+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
40941
40942 return hit;
40943 }
40944diff -urNp linux-2.6.32.44/fs/compat_binfmt_elf.c linux-2.6.32.44/fs/compat_binfmt_elf.c
40945--- linux-2.6.32.44/fs/compat_binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
40946+++ linux-2.6.32.44/fs/compat_binfmt_elf.c 2011-04-17 15:56:46.000000000 -0400
40947@@ -29,10 +29,12 @@
40948 #undef elfhdr
40949 #undef elf_phdr
40950 #undef elf_note
40951+#undef elf_dyn
40952 #undef elf_addr_t
40953 #define elfhdr elf32_hdr
40954 #define elf_phdr elf32_phdr
40955 #define elf_note elf32_note
40956+#define elf_dyn Elf32_Dyn
40957 #define elf_addr_t Elf32_Addr
40958
40959 /*
40960diff -urNp linux-2.6.32.44/fs/compat.c linux-2.6.32.44/fs/compat.c
40961--- linux-2.6.32.44/fs/compat.c 2011-04-17 17:00:52.000000000 -0400
40962+++ linux-2.6.32.44/fs/compat.c 2011-08-11 19:56:56.000000000 -0400
40963@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
40964
40965 struct compat_readdir_callback {
40966 struct compat_old_linux_dirent __user *dirent;
40967+ struct file * file;
40968 int result;
40969 };
40970
40971@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf
40972 buf->result = -EOVERFLOW;
40973 return -EOVERFLOW;
40974 }
40975+
40976+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
40977+ return 0;
40978+
40979 buf->result++;
40980 dirent = buf->dirent;
40981 if (!access_ok(VERIFY_WRITE, dirent,
40982@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(u
40983
40984 buf.result = 0;
40985 buf.dirent = dirent;
40986+ buf.file = file;
40987
40988 error = vfs_readdir(file, compat_fillonedir, &buf);
40989 if (buf.result)
40990@@ -899,6 +905,7 @@ struct compat_linux_dirent {
40991 struct compat_getdents_callback {
40992 struct compat_linux_dirent __user *current_dir;
40993 struct compat_linux_dirent __user *previous;
40994+ struct file * file;
40995 int count;
40996 int error;
40997 };
40998@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, c
40999 buf->error = -EOVERFLOW;
41000 return -EOVERFLOW;
41001 }
41002+
41003+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41004+ return 0;
41005+
41006 dirent = buf->previous;
41007 if (dirent) {
41008 if (__put_user(offset, &dirent->d_off))
41009@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsi
41010 buf.previous = NULL;
41011 buf.count = count;
41012 buf.error = 0;
41013+ buf.file = file;
41014
41015 error = vfs_readdir(file, compat_filldir, &buf);
41016 if (error >= 0)
41017@@ -987,6 +999,7 @@ out:
41018 struct compat_getdents_callback64 {
41019 struct linux_dirent64 __user *current_dir;
41020 struct linux_dirent64 __user *previous;
41021+ struct file * file;
41022 int count;
41023 int error;
41024 };
41025@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf
41026 buf->error = -EINVAL; /* only used if we fail.. */
41027 if (reclen > buf->count)
41028 return -EINVAL;
41029+
41030+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41031+ return 0;
41032+
41033 dirent = buf->previous;
41034
41035 if (dirent) {
41036@@ -1054,6 +1071,7 @@ asmlinkage long compat_sys_getdents64(un
41037 buf.previous = NULL;
41038 buf.count = count;
41039 buf.error = 0;
41040+ buf.file = file;
41041
41042 error = vfs_readdir(file, compat_filldir64, &buf);
41043 if (error >= 0)
41044@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(in
41045 * verify all the pointers
41046 */
41047 ret = -EINVAL;
41048- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
41049+ if (nr_segs > UIO_MAXIOV)
41050 goto out;
41051 if (!file->f_op)
41052 goto out;
41053@@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
41054 compat_uptr_t __user *envp,
41055 struct pt_regs * regs)
41056 {
41057+#ifdef CONFIG_GRKERNSEC
41058+ struct file *old_exec_file;
41059+ struct acl_subject_label *old_acl;
41060+ struct rlimit old_rlim[RLIM_NLIMITS];
41061+#endif
41062 struct linux_binprm *bprm;
41063 struct file *file;
41064 struct files_struct *displaced;
41065 bool clear_in_exec;
41066 int retval;
41067+ const struct cred *cred = current_cred();
41068+
41069+ /*
41070+ * We move the actual failure in case of RLIMIT_NPROC excess from
41071+ * set*uid() to execve() because too many poorly written programs
41072+ * don't check setuid() return code. Here we additionally recheck
41073+ * whether NPROC limit is still exceeded.
41074+ */
41075+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
41076+
41077+ if ((current->flags & PF_NPROC_EXCEEDED) &&
41078+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
41079+ retval = -EAGAIN;
41080+ goto out_ret;
41081+ }
41082+
41083+ /* We're below the limit (still or again), so we don't want to make
41084+ * further execve() calls fail. */
41085+ current->flags &= ~PF_NPROC_EXCEEDED;
41086
41087 retval = unshare_files(&displaced);
41088 if (retval)
41089@@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
41090 bprm->filename = filename;
41091 bprm->interp = filename;
41092
41093+ if (gr_process_user_ban()) {
41094+ retval = -EPERM;
41095+ goto out_file;
41096+ }
41097+
41098+ retval = -EACCES;
41099+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
41100+ goto out_file;
41101+
41102 retval = bprm_mm_init(bprm);
41103 if (retval)
41104 goto out_file;
41105@@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
41106 if (retval < 0)
41107 goto out;
41108
41109+ if (!gr_tpe_allow(file)) {
41110+ retval = -EACCES;
41111+ goto out;
41112+ }
41113+
41114+ if (gr_check_crash_exec(file)) {
41115+ retval = -EACCES;
41116+ goto out;
41117+ }
41118+
41119+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
41120+
41121+ gr_handle_exec_args_compat(bprm, argv);
41122+
41123+#ifdef CONFIG_GRKERNSEC
41124+ old_acl = current->acl;
41125+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
41126+ old_exec_file = current->exec_file;
41127+ get_file(file);
41128+ current->exec_file = file;
41129+#endif
41130+
41131+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
41132+ bprm->unsafe & LSM_UNSAFE_SHARE);
41133+ if (retval < 0)
41134+ goto out_fail;
41135+
41136 retval = search_binary_handler(bprm, regs);
41137 if (retval < 0)
41138- goto out;
41139+ goto out_fail;
41140+#ifdef CONFIG_GRKERNSEC
41141+ if (old_exec_file)
41142+ fput(old_exec_file);
41143+#endif
41144
41145 /* execve succeeded */
41146 current->fs->in_exec = 0;
41147@@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
41148 put_files_struct(displaced);
41149 return retval;
41150
41151+out_fail:
41152+#ifdef CONFIG_GRKERNSEC
41153+ current->acl = old_acl;
41154+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
41155+ fput(current->exec_file);
41156+ current->exec_file = old_exec_file;
41157+#endif
41158+
41159 out:
41160 if (bprm->mm) {
41161 acct_arg_size(bprm, 0);
41162@@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat
41163 struct fdtable *fdt;
41164 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
41165
41166+ pax_track_stack();
41167+
41168 if (n < 0)
41169 goto out_nofds;
41170
41171diff -urNp linux-2.6.32.44/fs/compat_ioctl.c linux-2.6.32.44/fs/compat_ioctl.c
41172--- linux-2.6.32.44/fs/compat_ioctl.c 2011-03-27 14:31:47.000000000 -0400
41173+++ linux-2.6.32.44/fs/compat_ioctl.c 2011-04-23 12:56:11.000000000 -0400
41174@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsi
41175 up = (struct compat_video_spu_palette __user *) arg;
41176 err = get_user(palp, &up->palette);
41177 err |= get_user(length, &up->length);
41178+ if (err)
41179+ return -EFAULT;
41180
41181 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
41182 err = put_user(compat_ptr(palp), &up_native->palette);
41183diff -urNp linux-2.6.32.44/fs/configfs/dir.c linux-2.6.32.44/fs/configfs/dir.c
41184--- linux-2.6.32.44/fs/configfs/dir.c 2011-03-27 14:31:47.000000000 -0400
41185+++ linux-2.6.32.44/fs/configfs/dir.c 2011-05-11 18:25:15.000000000 -0400
41186@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file
41187 }
41188 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
41189 struct configfs_dirent *next;
41190- const char * name;
41191+ const unsigned char * name;
41192+ char d_name[sizeof(next->s_dentry->d_iname)];
41193 int len;
41194
41195 next = list_entry(p, struct configfs_dirent,
41196@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file
41197 continue;
41198
41199 name = configfs_get_name(next);
41200- len = strlen(name);
41201+ if (next->s_dentry && name == next->s_dentry->d_iname) {
41202+ len = next->s_dentry->d_name.len;
41203+ memcpy(d_name, name, len);
41204+ name = d_name;
41205+ } else
41206+ len = strlen(name);
41207 if (next->s_dentry)
41208 ino = next->s_dentry->d_inode->i_ino;
41209 else
41210diff -urNp linux-2.6.32.44/fs/dcache.c linux-2.6.32.44/fs/dcache.c
41211--- linux-2.6.32.44/fs/dcache.c 2011-03-27 14:31:47.000000000 -0400
41212+++ linux-2.6.32.44/fs/dcache.c 2011-04-23 13:32:21.000000000 -0400
41213@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
41214
41215 static struct kmem_cache *dentry_cache __read_mostly;
41216
41217-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
41218-
41219 /*
41220 * This is the single most critical data structure when it comes
41221 * to the dcache: the hashtable for lookups. Somebody should try
41222@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned lon
41223 mempages -= reserve;
41224
41225 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
41226- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
41227+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
41228
41229 dcache_init();
41230 inode_init();
41231diff -urNp linux-2.6.32.44/fs/dlm/lockspace.c linux-2.6.32.44/fs/dlm/lockspace.c
41232--- linux-2.6.32.44/fs/dlm/lockspace.c 2011-03-27 14:31:47.000000000 -0400
41233+++ linux-2.6.32.44/fs/dlm/lockspace.c 2011-04-17 15:56:46.000000000 -0400
41234@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struc
41235 kfree(ls);
41236 }
41237
41238-static struct sysfs_ops dlm_attr_ops = {
41239+static const struct sysfs_ops dlm_attr_ops = {
41240 .show = dlm_attr_show,
41241 .store = dlm_attr_store,
41242 };
41243diff -urNp linux-2.6.32.44/fs/ecryptfs/inode.c linux-2.6.32.44/fs/ecryptfs/inode.c
41244--- linux-2.6.32.44/fs/ecryptfs/inode.c 2011-03-27 14:31:47.000000000 -0400
41245+++ linux-2.6.32.44/fs/ecryptfs/inode.c 2011-04-17 15:56:46.000000000 -0400
41246@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struc
41247 old_fs = get_fs();
41248 set_fs(get_ds());
41249 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
41250- (char __user *)lower_buf,
41251+ (__force char __user *)lower_buf,
41252 lower_bufsiz);
41253 set_fs(old_fs);
41254 if (rc < 0)
41255@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct
41256 }
41257 old_fs = get_fs();
41258 set_fs(get_ds());
41259- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
41260+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
41261 set_fs(old_fs);
41262 if (rc < 0)
41263 goto out_free;
41264diff -urNp linux-2.6.32.44/fs/exec.c linux-2.6.32.44/fs/exec.c
41265--- linux-2.6.32.44/fs/exec.c 2011-06-25 12:55:34.000000000 -0400
41266+++ linux-2.6.32.44/fs/exec.c 2011-08-11 19:56:19.000000000 -0400
41267@@ -56,12 +56,24 @@
41268 #include <linux/fsnotify.h>
41269 #include <linux/fs_struct.h>
41270 #include <linux/pipe_fs_i.h>
41271+#include <linux/random.h>
41272+#include <linux/seq_file.h>
41273+
41274+#ifdef CONFIG_PAX_REFCOUNT
41275+#include <linux/kallsyms.h>
41276+#include <linux/kdebug.h>
41277+#endif
41278
41279 #include <asm/uaccess.h>
41280 #include <asm/mmu_context.h>
41281 #include <asm/tlb.h>
41282 #include "internal.h"
41283
41284+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
41285+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
41286+EXPORT_SYMBOL(pax_set_initial_flags_func);
41287+#endif
41288+
41289 int core_uses_pid;
41290 char core_pattern[CORENAME_MAX_SIZE] = "core";
41291 unsigned int core_pipe_limit;
41292@@ -115,7 +127,7 @@ SYSCALL_DEFINE1(uselib, const char __use
41293 goto out;
41294
41295 file = do_filp_open(AT_FDCWD, tmp,
41296- O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
41297+ O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
41298 MAY_READ | MAY_EXEC | MAY_OPEN);
41299 putname(tmp);
41300 error = PTR_ERR(file);
41301@@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_b
41302 int write)
41303 {
41304 struct page *page;
41305- int ret;
41306
41307-#ifdef CONFIG_STACK_GROWSUP
41308- if (write) {
41309- ret = expand_stack_downwards(bprm->vma, pos);
41310- if (ret < 0)
41311- return NULL;
41312- }
41313-#endif
41314- ret = get_user_pages(current, bprm->mm, pos,
41315- 1, write, 1, &page, NULL);
41316- if (ret <= 0)
41317+ if (0 > expand_stack_downwards(bprm->vma, pos))
41318+ return NULL;
41319+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
41320 return NULL;
41321
41322 if (write) {
41323@@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_b
41324 vma->vm_end = STACK_TOP_MAX;
41325 vma->vm_start = vma->vm_end - PAGE_SIZE;
41326 vma->vm_flags = VM_STACK_FLAGS;
41327+
41328+#ifdef CONFIG_PAX_SEGMEXEC
41329+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
41330+#endif
41331+
41332 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
41333
41334 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
41335@@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_b
41336 mm->stack_vm = mm->total_vm = 1;
41337 up_write(&mm->mmap_sem);
41338 bprm->p = vma->vm_end - sizeof(void *);
41339+
41340+#ifdef CONFIG_PAX_RANDUSTACK
41341+ if (randomize_va_space)
41342+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
41343+#endif
41344+
41345 return 0;
41346 err:
41347 up_write(&mm->mmap_sem);
41348@@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char **
41349 int r;
41350 mm_segment_t oldfs = get_fs();
41351 set_fs(KERNEL_DS);
41352- r = copy_strings(argc, (char __user * __user *)argv, bprm);
41353+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
41354 set_fs(oldfs);
41355 return r;
41356 }
41357@@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_are
41358 unsigned long new_end = old_end - shift;
41359 struct mmu_gather *tlb;
41360
41361- BUG_ON(new_start > new_end);
41362+ if (new_start >= new_end || new_start < mmap_min_addr)
41363+ return -ENOMEM;
41364
41365 /*
41366 * ensure there are no vmas between where we want to go
41367@@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_are
41368 if (vma != find_vma(mm, new_start))
41369 return -EFAULT;
41370
41371+#ifdef CONFIG_PAX_SEGMEXEC
41372+ BUG_ON(pax_find_mirror_vma(vma));
41373+#endif
41374+
41375 /*
41376 * cover the whole range: [new_start, old_end)
41377 */
41378@@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm
41379 stack_top = arch_align_stack(stack_top);
41380 stack_top = PAGE_ALIGN(stack_top);
41381
41382- if (unlikely(stack_top < mmap_min_addr) ||
41383- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
41384- return -ENOMEM;
41385-
41386 stack_shift = vma->vm_end - stack_top;
41387
41388 bprm->p -= stack_shift;
41389@@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm
41390 bprm->exec -= stack_shift;
41391
41392 down_write(&mm->mmap_sem);
41393+
41394+ /* Move stack pages down in memory. */
41395+ if (stack_shift) {
41396+ ret = shift_arg_pages(vma, stack_shift);
41397+ if (ret)
41398+ goto out_unlock;
41399+ }
41400+
41401 vm_flags = VM_STACK_FLAGS;
41402
41403 /*
41404@@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm
41405 vm_flags &= ~VM_EXEC;
41406 vm_flags |= mm->def_flags;
41407
41408+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41409+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41410+ vm_flags &= ~VM_EXEC;
41411+
41412+#ifdef CONFIG_PAX_MPROTECT
41413+ if (mm->pax_flags & MF_PAX_MPROTECT)
41414+ vm_flags &= ~VM_MAYEXEC;
41415+#endif
41416+
41417+ }
41418+#endif
41419+
41420 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
41421 vm_flags);
41422 if (ret)
41423 goto out_unlock;
41424 BUG_ON(prev != vma);
41425
41426- /* Move stack pages down in memory. */
41427- if (stack_shift) {
41428- ret = shift_arg_pages(vma, stack_shift);
41429- if (ret)
41430- goto out_unlock;
41431- }
41432-
41433 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
41434 stack_size = vma->vm_end - vma->vm_start;
41435 /*
41436@@ -707,7 +736,7 @@ struct file *open_exec(const char *name)
41437 int err;
41438
41439 file = do_filp_open(AT_FDCWD, name,
41440- O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
41441+ O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
41442 MAY_EXEC | MAY_OPEN);
41443 if (IS_ERR(file))
41444 goto out;
41445@@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_
41446 old_fs = get_fs();
41447 set_fs(get_ds());
41448 /* The cast to a user pointer is valid due to the set_fs() */
41449- result = vfs_read(file, (void __user *)addr, count, &pos);
41450+ result = vfs_read(file, (__force void __user *)addr, count, &pos);
41451 set_fs(old_fs);
41452 return result;
41453 }
41454@@ -1152,7 +1181,7 @@ int check_unsafe_exec(struct linux_binpr
41455 }
41456 rcu_read_unlock();
41457
41458- if (p->fs->users > n_fs) {
41459+ if (atomic_read(&p->fs->users) > n_fs) {
41460 bprm->unsafe |= LSM_UNSAFE_SHARE;
41461 } else {
41462 res = -EAGAIN;
41463@@ -1347,11 +1376,35 @@ int do_execve(char * filename,
41464 char __user *__user *envp,
41465 struct pt_regs * regs)
41466 {
41467+#ifdef CONFIG_GRKERNSEC
41468+ struct file *old_exec_file;
41469+ struct acl_subject_label *old_acl;
41470+ struct rlimit old_rlim[RLIM_NLIMITS];
41471+#endif
41472 struct linux_binprm *bprm;
41473 struct file *file;
41474 struct files_struct *displaced;
41475 bool clear_in_exec;
41476 int retval;
41477+ const struct cred *cred = current_cred();
41478+
41479+ /*
41480+ * We move the actual failure in case of RLIMIT_NPROC excess from
41481+ * set*uid() to execve() because too many poorly written programs
41482+ * don't check setuid() return code. Here we additionally recheck
41483+ * whether NPROC limit is still exceeded.
41484+ */
41485+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
41486+
41487+ if ((current->flags & PF_NPROC_EXCEEDED) &&
41488+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
41489+ retval = -EAGAIN;
41490+ goto out_ret;
41491+ }
41492+
41493+ /* We're below the limit (still or again), so we don't want to make
41494+ * further execve() calls fail. */
41495+ current->flags &= ~PF_NPROC_EXCEEDED;
41496
41497 retval = unshare_files(&displaced);
41498 if (retval)
41499@@ -1383,6 +1436,16 @@ int do_execve(char * filename,
41500 bprm->filename = filename;
41501 bprm->interp = filename;
41502
41503+ if (gr_process_user_ban()) {
41504+ retval = -EPERM;
41505+ goto out_file;
41506+ }
41507+
41508+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
41509+ retval = -EACCES;
41510+ goto out_file;
41511+ }
41512+
41513 retval = bprm_mm_init(bprm);
41514 if (retval)
41515 goto out_file;
41516@@ -1412,10 +1475,41 @@ int do_execve(char * filename,
41517 if (retval < 0)
41518 goto out;
41519
41520+ if (!gr_tpe_allow(file)) {
41521+ retval = -EACCES;
41522+ goto out;
41523+ }
41524+
41525+ if (gr_check_crash_exec(file)) {
41526+ retval = -EACCES;
41527+ goto out;
41528+ }
41529+
41530+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
41531+
41532+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
41533+
41534+#ifdef CONFIG_GRKERNSEC
41535+ old_acl = current->acl;
41536+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
41537+ old_exec_file = current->exec_file;
41538+ get_file(file);
41539+ current->exec_file = file;
41540+#endif
41541+
41542+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
41543+ bprm->unsafe & LSM_UNSAFE_SHARE);
41544+ if (retval < 0)
41545+ goto out_fail;
41546+
41547 current->flags &= ~PF_KTHREAD;
41548 retval = search_binary_handler(bprm,regs);
41549 if (retval < 0)
41550- goto out;
41551+ goto out_fail;
41552+#ifdef CONFIG_GRKERNSEC
41553+ if (old_exec_file)
41554+ fput(old_exec_file);
41555+#endif
41556
41557 /* execve succeeded */
41558 current->fs->in_exec = 0;
41559@@ -1426,6 +1520,14 @@ int do_execve(char * filename,
41560 put_files_struct(displaced);
41561 return retval;
41562
41563+out_fail:
41564+#ifdef CONFIG_GRKERNSEC
41565+ current->acl = old_acl;
41566+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
41567+ fput(current->exec_file);
41568+ current->exec_file = old_exec_file;
41569+#endif
41570+
41571 out:
41572 if (bprm->mm) {
41573 acct_arg_size(bprm, 0);
41574@@ -1591,6 +1693,220 @@ out:
41575 return ispipe;
41576 }
41577
41578+int pax_check_flags(unsigned long *flags)
41579+{
41580+ int retval = 0;
41581+
41582+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
41583+ if (*flags & MF_PAX_SEGMEXEC)
41584+ {
41585+ *flags &= ~MF_PAX_SEGMEXEC;
41586+ retval = -EINVAL;
41587+ }
41588+#endif
41589+
41590+ if ((*flags & MF_PAX_PAGEEXEC)
41591+
41592+#ifdef CONFIG_PAX_PAGEEXEC
41593+ && (*flags & MF_PAX_SEGMEXEC)
41594+#endif
41595+
41596+ )
41597+ {
41598+ *flags &= ~MF_PAX_PAGEEXEC;
41599+ retval = -EINVAL;
41600+ }
41601+
41602+ if ((*flags & MF_PAX_MPROTECT)
41603+
41604+#ifdef CONFIG_PAX_MPROTECT
41605+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41606+#endif
41607+
41608+ )
41609+ {
41610+ *flags &= ~MF_PAX_MPROTECT;
41611+ retval = -EINVAL;
41612+ }
41613+
41614+ if ((*flags & MF_PAX_EMUTRAMP)
41615+
41616+#ifdef CONFIG_PAX_EMUTRAMP
41617+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41618+#endif
41619+
41620+ )
41621+ {
41622+ *flags &= ~MF_PAX_EMUTRAMP;
41623+ retval = -EINVAL;
41624+ }
41625+
41626+ return retval;
41627+}
41628+
41629+EXPORT_SYMBOL(pax_check_flags);
41630+
41631+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41632+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
41633+{
41634+ struct task_struct *tsk = current;
41635+ struct mm_struct *mm = current->mm;
41636+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
41637+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
41638+ char *path_exec = NULL;
41639+ char *path_fault = NULL;
41640+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
41641+
41642+ if (buffer_exec && buffer_fault) {
41643+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
41644+
41645+ down_read(&mm->mmap_sem);
41646+ vma = mm->mmap;
41647+ while (vma && (!vma_exec || !vma_fault)) {
41648+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
41649+ vma_exec = vma;
41650+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
41651+ vma_fault = vma;
41652+ vma = vma->vm_next;
41653+ }
41654+ if (vma_exec) {
41655+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
41656+ if (IS_ERR(path_exec))
41657+ path_exec = "<path too long>";
41658+ else {
41659+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
41660+ if (path_exec) {
41661+ *path_exec = 0;
41662+ path_exec = buffer_exec;
41663+ } else
41664+ path_exec = "<path too long>";
41665+ }
41666+ }
41667+ if (vma_fault) {
41668+ start = vma_fault->vm_start;
41669+ end = vma_fault->vm_end;
41670+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
41671+ if (vma_fault->vm_file) {
41672+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
41673+ if (IS_ERR(path_fault))
41674+ path_fault = "<path too long>";
41675+ else {
41676+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
41677+ if (path_fault) {
41678+ *path_fault = 0;
41679+ path_fault = buffer_fault;
41680+ } else
41681+ path_fault = "<path too long>";
41682+ }
41683+ } else
41684+ path_fault = "<anonymous mapping>";
41685+ }
41686+ up_read(&mm->mmap_sem);
41687+ }
41688+ if (tsk->signal->curr_ip)
41689+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
41690+ else
41691+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
41692+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
41693+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
41694+ task_uid(tsk), task_euid(tsk), pc, sp);
41695+ free_page((unsigned long)buffer_exec);
41696+ free_page((unsigned long)buffer_fault);
41697+ pax_report_insns(pc, sp);
41698+ do_coredump(SIGKILL, SIGKILL, regs);
41699+}
41700+#endif
41701+
41702+#ifdef CONFIG_PAX_REFCOUNT
41703+void pax_report_refcount_overflow(struct pt_regs *regs)
41704+{
41705+ if (current->signal->curr_ip)
41706+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
41707+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
41708+ else
41709+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
41710+ current->comm, task_pid_nr(current), current_uid(), current_euid());
41711+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
41712+ show_regs(regs);
41713+ force_sig_specific(SIGKILL, current);
41714+}
41715+#endif
41716+
41717+#ifdef CONFIG_PAX_USERCOPY
41718+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
41719+int object_is_on_stack(const void *obj, unsigned long len)
41720+{
41721+ const void * const stack = task_stack_page(current);
41722+ const void * const stackend = stack + THREAD_SIZE;
41723+
41724+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
41725+ const void *frame = NULL;
41726+ const void *oldframe;
41727+#endif
41728+
41729+ if (obj + len < obj)
41730+ return -1;
41731+
41732+ if (obj + len <= stack || stackend <= obj)
41733+ return 0;
41734+
41735+ if (obj < stack || stackend < obj + len)
41736+ return -1;
41737+
41738+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
41739+ oldframe = __builtin_frame_address(1);
41740+ if (oldframe)
41741+ frame = __builtin_frame_address(2);
41742+ /*
41743+ low ----------------------------------------------> high
41744+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
41745+ ^----------------^
41746+ allow copies only within here
41747+ */
41748+ while (stack <= frame && frame < stackend) {
41749+ /* if obj + len extends past the last frame, this
41750+ check won't pass and the next frame will be 0,
41751+ causing us to bail out and correctly report
41752+ the copy as invalid
41753+ */
41754+ if (obj + len <= frame)
41755+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
41756+ oldframe = frame;
41757+ frame = *(const void * const *)frame;
41758+ }
41759+ return -1;
41760+#else
41761+ return 1;
41762+#endif
41763+}
41764+
41765+
41766+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
41767+{
41768+ if (current->signal->curr_ip)
41769+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
41770+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
41771+ else
41772+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
41773+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
41774+
41775+ dump_stack();
41776+ gr_handle_kernel_exploit();
41777+ do_group_exit(SIGKILL);
41778+}
41779+#endif
41780+
41781+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
41782+void pax_track_stack(void)
41783+{
41784+ unsigned long sp = (unsigned long)&sp;
41785+ if (sp < current_thread_info()->lowest_stack &&
41786+ sp > (unsigned long)task_stack_page(current))
41787+ current_thread_info()->lowest_stack = sp;
41788+}
41789+EXPORT_SYMBOL(pax_track_stack);
41790+#endif
41791+
41792 static int zap_process(struct task_struct *start)
41793 {
41794 struct task_struct *t;
41795@@ -1793,17 +2109,17 @@ static void wait_for_dump_helpers(struct
41796 pipe = file->f_path.dentry->d_inode->i_pipe;
41797
41798 pipe_lock(pipe);
41799- pipe->readers++;
41800- pipe->writers--;
41801+ atomic_inc(&pipe->readers);
41802+ atomic_dec(&pipe->writers);
41803
41804- while ((pipe->readers > 1) && (!signal_pending(current))) {
41805+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
41806 wake_up_interruptible_sync(&pipe->wait);
41807 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
41808 pipe_wait(pipe);
41809 }
41810
41811- pipe->readers--;
41812- pipe->writers++;
41813+ atomic_dec(&pipe->readers);
41814+ atomic_inc(&pipe->writers);
41815 pipe_unlock(pipe);
41816
41817 }
41818@@ -1826,10 +2142,13 @@ void do_coredump(long signr, int exit_co
41819 char **helper_argv = NULL;
41820 int helper_argc = 0;
41821 int dump_count = 0;
41822- static atomic_t core_dump_count = ATOMIC_INIT(0);
41823+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
41824
41825 audit_core_dumps(signr);
41826
41827+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
41828+ gr_handle_brute_attach(current, mm->flags);
41829+
41830 binfmt = mm->binfmt;
41831 if (!binfmt || !binfmt->core_dump)
41832 goto fail;
41833@@ -1874,6 +2193,8 @@ void do_coredump(long signr, int exit_co
41834 */
41835 clear_thread_flag(TIF_SIGPENDING);
41836
41837+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
41838+
41839 /*
41840 * lock_kernel() because format_corename() is controlled by sysctl, which
41841 * uses lock_kernel()
41842@@ -1908,7 +2229,7 @@ void do_coredump(long signr, int exit_co
41843 goto fail_unlock;
41844 }
41845
41846- dump_count = atomic_inc_return(&core_dump_count);
41847+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
41848 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
41849 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
41850 task_tgid_vnr(current), current->comm);
41851@@ -1972,7 +2293,7 @@ close_fail:
41852 filp_close(file, NULL);
41853 fail_dropcount:
41854 if (dump_count)
41855- atomic_dec(&core_dump_count);
41856+ atomic_dec_unchecked(&core_dump_count);
41857 fail_unlock:
41858 if (helper_argv)
41859 argv_free(helper_argv);
41860diff -urNp linux-2.6.32.44/fs/ext2/balloc.c linux-2.6.32.44/fs/ext2/balloc.c
41861--- linux-2.6.32.44/fs/ext2/balloc.c 2011-03-27 14:31:47.000000000 -0400
41862+++ linux-2.6.32.44/fs/ext2/balloc.c 2011-04-17 15:56:46.000000000 -0400
41863@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
41864
41865 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
41866 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
41867- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
41868+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
41869 sbi->s_resuid != current_fsuid() &&
41870 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
41871 return 0;
41872diff -urNp linux-2.6.32.44/fs/ext3/balloc.c linux-2.6.32.44/fs/ext3/balloc.c
41873--- linux-2.6.32.44/fs/ext3/balloc.c 2011-03-27 14:31:47.000000000 -0400
41874+++ linux-2.6.32.44/fs/ext3/balloc.c 2011-04-17 15:56:46.000000000 -0400
41875@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
41876
41877 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
41878 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
41879- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
41880+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
41881 sbi->s_resuid != current_fsuid() &&
41882 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
41883 return 0;
41884diff -urNp linux-2.6.32.44/fs/ext4/balloc.c linux-2.6.32.44/fs/ext4/balloc.c
41885--- linux-2.6.32.44/fs/ext4/balloc.c 2011-03-27 14:31:47.000000000 -0400
41886+++ linux-2.6.32.44/fs/ext4/balloc.c 2011-04-17 15:56:46.000000000 -0400
41887@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_
41888 /* Hm, nope. Are (enough) root reserved blocks available? */
41889 if (sbi->s_resuid == current_fsuid() ||
41890 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
41891- capable(CAP_SYS_RESOURCE)) {
41892+ capable_nolog(CAP_SYS_RESOURCE)) {
41893 if (free_blocks >= (nblocks + dirty_blocks))
41894 return 1;
41895 }
41896diff -urNp linux-2.6.32.44/fs/ext4/ext4.h linux-2.6.32.44/fs/ext4/ext4.h
41897--- linux-2.6.32.44/fs/ext4/ext4.h 2011-03-27 14:31:47.000000000 -0400
41898+++ linux-2.6.32.44/fs/ext4/ext4.h 2011-04-17 15:56:46.000000000 -0400
41899@@ -1078,19 +1078,19 @@ struct ext4_sb_info {
41900
41901 /* stats for buddy allocator */
41902 spinlock_t s_mb_pa_lock;
41903- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
41904- atomic_t s_bal_success; /* we found long enough chunks */
41905- atomic_t s_bal_allocated; /* in blocks */
41906- atomic_t s_bal_ex_scanned; /* total extents scanned */
41907- atomic_t s_bal_goals; /* goal hits */
41908- atomic_t s_bal_breaks; /* too long searches */
41909- atomic_t s_bal_2orders; /* 2^order hits */
41910+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
41911+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
41912+ atomic_unchecked_t s_bal_allocated; /* in blocks */
41913+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
41914+ atomic_unchecked_t s_bal_goals; /* goal hits */
41915+ atomic_unchecked_t s_bal_breaks; /* too long searches */
41916+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
41917 spinlock_t s_bal_lock;
41918 unsigned long s_mb_buddies_generated;
41919 unsigned long long s_mb_generation_time;
41920- atomic_t s_mb_lost_chunks;
41921- atomic_t s_mb_preallocated;
41922- atomic_t s_mb_discarded;
41923+ atomic_unchecked_t s_mb_lost_chunks;
41924+ atomic_unchecked_t s_mb_preallocated;
41925+ atomic_unchecked_t s_mb_discarded;
41926 atomic_t s_lock_busy;
41927
41928 /* locality groups */
41929diff -urNp linux-2.6.32.44/fs/ext4/mballoc.c linux-2.6.32.44/fs/ext4/mballoc.c
41930--- linux-2.6.32.44/fs/ext4/mballoc.c 2011-06-25 12:55:34.000000000 -0400
41931+++ linux-2.6.32.44/fs/ext4/mballoc.c 2011-06-25 12:56:37.000000000 -0400
41932@@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ex
41933 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
41934
41935 if (EXT4_SB(sb)->s_mb_stats)
41936- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
41937+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
41938
41939 break;
41940 }
41941@@ -2131,7 +2131,7 @@ repeat:
41942 ac->ac_status = AC_STATUS_CONTINUE;
41943 ac->ac_flags |= EXT4_MB_HINT_FIRST;
41944 cr = 3;
41945- atomic_inc(&sbi->s_mb_lost_chunks);
41946+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
41947 goto repeat;
41948 }
41949 }
41950@@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struc
41951 ext4_grpblk_t counters[16];
41952 } sg;
41953
41954+ pax_track_stack();
41955+
41956 group--;
41957 if (group == 0)
41958 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
41959@@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *
41960 if (sbi->s_mb_stats) {
41961 printk(KERN_INFO
41962 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
41963- atomic_read(&sbi->s_bal_allocated),
41964- atomic_read(&sbi->s_bal_reqs),
41965- atomic_read(&sbi->s_bal_success));
41966+ atomic_read_unchecked(&sbi->s_bal_allocated),
41967+ atomic_read_unchecked(&sbi->s_bal_reqs),
41968+ atomic_read_unchecked(&sbi->s_bal_success));
41969 printk(KERN_INFO
41970 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
41971 "%u 2^N hits, %u breaks, %u lost\n",
41972- atomic_read(&sbi->s_bal_ex_scanned),
41973- atomic_read(&sbi->s_bal_goals),
41974- atomic_read(&sbi->s_bal_2orders),
41975- atomic_read(&sbi->s_bal_breaks),
41976- atomic_read(&sbi->s_mb_lost_chunks));
41977+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
41978+ atomic_read_unchecked(&sbi->s_bal_goals),
41979+ atomic_read_unchecked(&sbi->s_bal_2orders),
41980+ atomic_read_unchecked(&sbi->s_bal_breaks),
41981+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
41982 printk(KERN_INFO
41983 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
41984 sbi->s_mb_buddies_generated++,
41985 sbi->s_mb_generation_time);
41986 printk(KERN_INFO
41987 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
41988- atomic_read(&sbi->s_mb_preallocated),
41989- atomic_read(&sbi->s_mb_discarded));
41990+ atomic_read_unchecked(&sbi->s_mb_preallocated),
41991+ atomic_read_unchecked(&sbi->s_mb_discarded));
41992 }
41993
41994 free_percpu(sbi->s_locality_groups);
41995@@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct
41996 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
41997
41998 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
41999- atomic_inc(&sbi->s_bal_reqs);
42000- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42001+ atomic_inc_unchecked(&sbi->s_bal_reqs);
42002+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42003 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
42004- atomic_inc(&sbi->s_bal_success);
42005- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
42006+ atomic_inc_unchecked(&sbi->s_bal_success);
42007+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
42008 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
42009 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
42010- atomic_inc(&sbi->s_bal_goals);
42011+ atomic_inc_unchecked(&sbi->s_bal_goals);
42012 if (ac->ac_found > sbi->s_mb_max_to_scan)
42013- atomic_inc(&sbi->s_bal_breaks);
42014+ atomic_inc_unchecked(&sbi->s_bal_breaks);
42015 }
42016
42017 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
42018@@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
42019 trace_ext4_mb_new_inode_pa(ac, pa);
42020
42021 ext4_mb_use_inode_pa(ac, pa);
42022- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42023+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42024
42025 ei = EXT4_I(ac->ac_inode);
42026 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42027@@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
42028 trace_ext4_mb_new_group_pa(ac, pa);
42029
42030 ext4_mb_use_group_pa(ac, pa);
42031- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42032+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42033
42034 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42035 lg = ac->ac_lg;
42036@@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
42037 * from the bitmap and continue.
42038 */
42039 }
42040- atomic_add(free, &sbi->s_mb_discarded);
42041+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
42042
42043 return err;
42044 }
42045@@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_bud
42046 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
42047 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
42048 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
42049- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42050+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42051
42052 if (ac) {
42053 ac->ac_sb = sb;
42054diff -urNp linux-2.6.32.44/fs/ext4/super.c linux-2.6.32.44/fs/ext4/super.c
42055--- linux-2.6.32.44/fs/ext4/super.c 2011-03-27 14:31:47.000000000 -0400
42056+++ linux-2.6.32.44/fs/ext4/super.c 2011-04-17 15:56:46.000000000 -0400
42057@@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobje
42058 }
42059
42060
42061-static struct sysfs_ops ext4_attr_ops = {
42062+static const struct sysfs_ops ext4_attr_ops = {
42063 .show = ext4_attr_show,
42064 .store = ext4_attr_store,
42065 };
42066diff -urNp linux-2.6.32.44/fs/fcntl.c linux-2.6.32.44/fs/fcntl.c
42067--- linux-2.6.32.44/fs/fcntl.c 2011-03-27 14:31:47.000000000 -0400
42068+++ linux-2.6.32.44/fs/fcntl.c 2011-04-17 15:56:46.000000000 -0400
42069@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct
42070 if (err)
42071 return err;
42072
42073+ if (gr_handle_chroot_fowner(pid, type))
42074+ return -ENOENT;
42075+ if (gr_check_protected_task_fowner(pid, type))
42076+ return -EACCES;
42077+
42078 f_modown(filp, pid, type, force);
42079 return 0;
42080 }
42081@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned in
42082 switch (cmd) {
42083 case F_DUPFD:
42084 case F_DUPFD_CLOEXEC:
42085+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
42086 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
42087 break;
42088 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
42089diff -urNp linux-2.6.32.44/fs/fifo.c linux-2.6.32.44/fs/fifo.c
42090--- linux-2.6.32.44/fs/fifo.c 2011-03-27 14:31:47.000000000 -0400
42091+++ linux-2.6.32.44/fs/fifo.c 2011-04-17 15:56:46.000000000 -0400
42092@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode
42093 */
42094 filp->f_op = &read_pipefifo_fops;
42095 pipe->r_counter++;
42096- if (pipe->readers++ == 0)
42097+ if (atomic_inc_return(&pipe->readers) == 1)
42098 wake_up_partner(inode);
42099
42100- if (!pipe->writers) {
42101+ if (!atomic_read(&pipe->writers)) {
42102 if ((filp->f_flags & O_NONBLOCK)) {
42103 /* suppress POLLHUP until we have
42104 * seen a writer */
42105@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode
42106 * errno=ENXIO when there is no process reading the FIFO.
42107 */
42108 ret = -ENXIO;
42109- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
42110+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
42111 goto err;
42112
42113 filp->f_op = &write_pipefifo_fops;
42114 pipe->w_counter++;
42115- if (!pipe->writers++)
42116+ if (atomic_inc_return(&pipe->writers) == 1)
42117 wake_up_partner(inode);
42118
42119- if (!pipe->readers) {
42120+ if (!atomic_read(&pipe->readers)) {
42121 wait_for_partner(inode, &pipe->r_counter);
42122 if (signal_pending(current))
42123 goto err_wr;
42124@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode
42125 */
42126 filp->f_op = &rdwr_pipefifo_fops;
42127
42128- pipe->readers++;
42129- pipe->writers++;
42130+ atomic_inc(&pipe->readers);
42131+ atomic_inc(&pipe->writers);
42132 pipe->r_counter++;
42133 pipe->w_counter++;
42134- if (pipe->readers == 1 || pipe->writers == 1)
42135+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
42136 wake_up_partner(inode);
42137 break;
42138
42139@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode
42140 return 0;
42141
42142 err_rd:
42143- if (!--pipe->readers)
42144+ if (atomic_dec_and_test(&pipe->readers))
42145 wake_up_interruptible(&pipe->wait);
42146 ret = -ERESTARTSYS;
42147 goto err;
42148
42149 err_wr:
42150- if (!--pipe->writers)
42151+ if (atomic_dec_and_test(&pipe->writers))
42152 wake_up_interruptible(&pipe->wait);
42153 ret = -ERESTARTSYS;
42154 goto err;
42155
42156 err:
42157- if (!pipe->readers && !pipe->writers)
42158+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
42159 free_pipe_info(inode);
42160
42161 err_nocleanup:
42162diff -urNp linux-2.6.32.44/fs/file.c linux-2.6.32.44/fs/file.c
42163--- linux-2.6.32.44/fs/file.c 2011-03-27 14:31:47.000000000 -0400
42164+++ linux-2.6.32.44/fs/file.c 2011-04-17 15:56:46.000000000 -0400
42165@@ -14,6 +14,7 @@
42166 #include <linux/slab.h>
42167 #include <linux/vmalloc.h>
42168 #include <linux/file.h>
42169+#include <linux/security.h>
42170 #include <linux/fdtable.h>
42171 #include <linux/bitops.h>
42172 #include <linux/interrupt.h>
42173@@ -257,6 +258,8 @@ int expand_files(struct files_struct *fi
42174 * N.B. For clone tasks sharing a files structure, this test
42175 * will limit the total number of files that can be opened.
42176 */
42177+
42178+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
42179 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
42180 return -EMFILE;
42181
42182diff -urNp linux-2.6.32.44/fs/filesystems.c linux-2.6.32.44/fs/filesystems.c
42183--- linux-2.6.32.44/fs/filesystems.c 2011-03-27 14:31:47.000000000 -0400
42184+++ linux-2.6.32.44/fs/filesystems.c 2011-04-17 15:56:46.000000000 -0400
42185@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(con
42186 int len = dot ? dot - name : strlen(name);
42187
42188 fs = __get_fs_type(name, len);
42189+
42190+#ifdef CONFIG_GRKERNSEC_MODHARDEN
42191+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
42192+#else
42193 if (!fs && (request_module("%.*s", len, name) == 0))
42194+#endif
42195 fs = __get_fs_type(name, len);
42196
42197 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
42198diff -urNp linux-2.6.32.44/fs/fscache/cookie.c linux-2.6.32.44/fs/fscache/cookie.c
42199--- linux-2.6.32.44/fs/fscache/cookie.c 2011-03-27 14:31:47.000000000 -0400
42200+++ linux-2.6.32.44/fs/fscache/cookie.c 2011-05-04 17:56:28.000000000 -0400
42201@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
42202 parent ? (char *) parent->def->name : "<no-parent>",
42203 def->name, netfs_data);
42204
42205- fscache_stat(&fscache_n_acquires);
42206+ fscache_stat_unchecked(&fscache_n_acquires);
42207
42208 /* if there's no parent cookie, then we don't create one here either */
42209 if (!parent) {
42210- fscache_stat(&fscache_n_acquires_null);
42211+ fscache_stat_unchecked(&fscache_n_acquires_null);
42212 _leave(" [no parent]");
42213 return NULL;
42214 }
42215@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
42216 /* allocate and initialise a cookie */
42217 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
42218 if (!cookie) {
42219- fscache_stat(&fscache_n_acquires_oom);
42220+ fscache_stat_unchecked(&fscache_n_acquires_oom);
42221 _leave(" [ENOMEM]");
42222 return NULL;
42223 }
42224@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
42225
42226 switch (cookie->def->type) {
42227 case FSCACHE_COOKIE_TYPE_INDEX:
42228- fscache_stat(&fscache_n_cookie_index);
42229+ fscache_stat_unchecked(&fscache_n_cookie_index);
42230 break;
42231 case FSCACHE_COOKIE_TYPE_DATAFILE:
42232- fscache_stat(&fscache_n_cookie_data);
42233+ fscache_stat_unchecked(&fscache_n_cookie_data);
42234 break;
42235 default:
42236- fscache_stat(&fscache_n_cookie_special);
42237+ fscache_stat_unchecked(&fscache_n_cookie_special);
42238 break;
42239 }
42240
42241@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
42242 if (fscache_acquire_non_index_cookie(cookie) < 0) {
42243 atomic_dec(&parent->n_children);
42244 __fscache_cookie_put(cookie);
42245- fscache_stat(&fscache_n_acquires_nobufs);
42246+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
42247 _leave(" = NULL");
42248 return NULL;
42249 }
42250 }
42251
42252- fscache_stat(&fscache_n_acquires_ok);
42253+ fscache_stat_unchecked(&fscache_n_acquires_ok);
42254 _leave(" = %p", cookie);
42255 return cookie;
42256 }
42257@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
42258 cache = fscache_select_cache_for_object(cookie->parent);
42259 if (!cache) {
42260 up_read(&fscache_addremove_sem);
42261- fscache_stat(&fscache_n_acquires_no_cache);
42262+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
42263 _leave(" = -ENOMEDIUM [no cache]");
42264 return -ENOMEDIUM;
42265 }
42266@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
42267 object = cache->ops->alloc_object(cache, cookie);
42268 fscache_stat_d(&fscache_n_cop_alloc_object);
42269 if (IS_ERR(object)) {
42270- fscache_stat(&fscache_n_object_no_alloc);
42271+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
42272 ret = PTR_ERR(object);
42273 goto error;
42274 }
42275
42276- fscache_stat(&fscache_n_object_alloc);
42277+ fscache_stat_unchecked(&fscache_n_object_alloc);
42278
42279 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
42280
42281@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
42282 struct fscache_object *object;
42283 struct hlist_node *_p;
42284
42285- fscache_stat(&fscache_n_updates);
42286+ fscache_stat_unchecked(&fscache_n_updates);
42287
42288 if (!cookie) {
42289- fscache_stat(&fscache_n_updates_null);
42290+ fscache_stat_unchecked(&fscache_n_updates_null);
42291 _leave(" [no cookie]");
42292 return;
42293 }
42294@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
42295 struct fscache_object *object;
42296 unsigned long event;
42297
42298- fscache_stat(&fscache_n_relinquishes);
42299+ fscache_stat_unchecked(&fscache_n_relinquishes);
42300 if (retire)
42301- fscache_stat(&fscache_n_relinquishes_retire);
42302+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
42303
42304 if (!cookie) {
42305- fscache_stat(&fscache_n_relinquishes_null);
42306+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
42307 _leave(" [no cookie]");
42308 return;
42309 }
42310@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
42311
42312 /* wait for the cookie to finish being instantiated (or to fail) */
42313 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
42314- fscache_stat(&fscache_n_relinquishes_waitcrt);
42315+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
42316 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
42317 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
42318 }
42319diff -urNp linux-2.6.32.44/fs/fscache/internal.h linux-2.6.32.44/fs/fscache/internal.h
42320--- linux-2.6.32.44/fs/fscache/internal.h 2011-03-27 14:31:47.000000000 -0400
42321+++ linux-2.6.32.44/fs/fscache/internal.h 2011-05-04 17:56:28.000000000 -0400
42322@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
42323 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
42324 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
42325
42326-extern atomic_t fscache_n_op_pend;
42327-extern atomic_t fscache_n_op_run;
42328-extern atomic_t fscache_n_op_enqueue;
42329-extern atomic_t fscache_n_op_deferred_release;
42330-extern atomic_t fscache_n_op_release;
42331-extern atomic_t fscache_n_op_gc;
42332-extern atomic_t fscache_n_op_cancelled;
42333-extern atomic_t fscache_n_op_rejected;
42334-
42335-extern atomic_t fscache_n_attr_changed;
42336-extern atomic_t fscache_n_attr_changed_ok;
42337-extern atomic_t fscache_n_attr_changed_nobufs;
42338-extern atomic_t fscache_n_attr_changed_nomem;
42339-extern atomic_t fscache_n_attr_changed_calls;
42340-
42341-extern atomic_t fscache_n_allocs;
42342-extern atomic_t fscache_n_allocs_ok;
42343-extern atomic_t fscache_n_allocs_wait;
42344-extern atomic_t fscache_n_allocs_nobufs;
42345-extern atomic_t fscache_n_allocs_intr;
42346-extern atomic_t fscache_n_allocs_object_dead;
42347-extern atomic_t fscache_n_alloc_ops;
42348-extern atomic_t fscache_n_alloc_op_waits;
42349-
42350-extern atomic_t fscache_n_retrievals;
42351-extern atomic_t fscache_n_retrievals_ok;
42352-extern atomic_t fscache_n_retrievals_wait;
42353-extern atomic_t fscache_n_retrievals_nodata;
42354-extern atomic_t fscache_n_retrievals_nobufs;
42355-extern atomic_t fscache_n_retrievals_intr;
42356-extern atomic_t fscache_n_retrievals_nomem;
42357-extern atomic_t fscache_n_retrievals_object_dead;
42358-extern atomic_t fscache_n_retrieval_ops;
42359-extern atomic_t fscache_n_retrieval_op_waits;
42360-
42361-extern atomic_t fscache_n_stores;
42362-extern atomic_t fscache_n_stores_ok;
42363-extern atomic_t fscache_n_stores_again;
42364-extern atomic_t fscache_n_stores_nobufs;
42365-extern atomic_t fscache_n_stores_oom;
42366-extern atomic_t fscache_n_store_ops;
42367-extern atomic_t fscache_n_store_calls;
42368-extern atomic_t fscache_n_store_pages;
42369-extern atomic_t fscache_n_store_radix_deletes;
42370-extern atomic_t fscache_n_store_pages_over_limit;
42371-
42372-extern atomic_t fscache_n_store_vmscan_not_storing;
42373-extern atomic_t fscache_n_store_vmscan_gone;
42374-extern atomic_t fscache_n_store_vmscan_busy;
42375-extern atomic_t fscache_n_store_vmscan_cancelled;
42376-
42377-extern atomic_t fscache_n_marks;
42378-extern atomic_t fscache_n_uncaches;
42379-
42380-extern atomic_t fscache_n_acquires;
42381-extern atomic_t fscache_n_acquires_null;
42382-extern atomic_t fscache_n_acquires_no_cache;
42383-extern atomic_t fscache_n_acquires_ok;
42384-extern atomic_t fscache_n_acquires_nobufs;
42385-extern atomic_t fscache_n_acquires_oom;
42386-
42387-extern atomic_t fscache_n_updates;
42388-extern atomic_t fscache_n_updates_null;
42389-extern atomic_t fscache_n_updates_run;
42390-
42391-extern atomic_t fscache_n_relinquishes;
42392-extern atomic_t fscache_n_relinquishes_null;
42393-extern atomic_t fscache_n_relinquishes_waitcrt;
42394-extern atomic_t fscache_n_relinquishes_retire;
42395-
42396-extern atomic_t fscache_n_cookie_index;
42397-extern atomic_t fscache_n_cookie_data;
42398-extern atomic_t fscache_n_cookie_special;
42399-
42400-extern atomic_t fscache_n_object_alloc;
42401-extern atomic_t fscache_n_object_no_alloc;
42402-extern atomic_t fscache_n_object_lookups;
42403-extern atomic_t fscache_n_object_lookups_negative;
42404-extern atomic_t fscache_n_object_lookups_positive;
42405-extern atomic_t fscache_n_object_lookups_timed_out;
42406-extern atomic_t fscache_n_object_created;
42407-extern atomic_t fscache_n_object_avail;
42408-extern atomic_t fscache_n_object_dead;
42409-
42410-extern atomic_t fscache_n_checkaux_none;
42411-extern atomic_t fscache_n_checkaux_okay;
42412-extern atomic_t fscache_n_checkaux_update;
42413-extern atomic_t fscache_n_checkaux_obsolete;
42414+extern atomic_unchecked_t fscache_n_op_pend;
42415+extern atomic_unchecked_t fscache_n_op_run;
42416+extern atomic_unchecked_t fscache_n_op_enqueue;
42417+extern atomic_unchecked_t fscache_n_op_deferred_release;
42418+extern atomic_unchecked_t fscache_n_op_release;
42419+extern atomic_unchecked_t fscache_n_op_gc;
42420+extern atomic_unchecked_t fscache_n_op_cancelled;
42421+extern atomic_unchecked_t fscache_n_op_rejected;
42422+
42423+extern atomic_unchecked_t fscache_n_attr_changed;
42424+extern atomic_unchecked_t fscache_n_attr_changed_ok;
42425+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
42426+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
42427+extern atomic_unchecked_t fscache_n_attr_changed_calls;
42428+
42429+extern atomic_unchecked_t fscache_n_allocs;
42430+extern atomic_unchecked_t fscache_n_allocs_ok;
42431+extern atomic_unchecked_t fscache_n_allocs_wait;
42432+extern atomic_unchecked_t fscache_n_allocs_nobufs;
42433+extern atomic_unchecked_t fscache_n_allocs_intr;
42434+extern atomic_unchecked_t fscache_n_allocs_object_dead;
42435+extern atomic_unchecked_t fscache_n_alloc_ops;
42436+extern atomic_unchecked_t fscache_n_alloc_op_waits;
42437+
42438+extern atomic_unchecked_t fscache_n_retrievals;
42439+extern atomic_unchecked_t fscache_n_retrievals_ok;
42440+extern atomic_unchecked_t fscache_n_retrievals_wait;
42441+extern atomic_unchecked_t fscache_n_retrievals_nodata;
42442+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
42443+extern atomic_unchecked_t fscache_n_retrievals_intr;
42444+extern atomic_unchecked_t fscache_n_retrievals_nomem;
42445+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
42446+extern atomic_unchecked_t fscache_n_retrieval_ops;
42447+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
42448+
42449+extern atomic_unchecked_t fscache_n_stores;
42450+extern atomic_unchecked_t fscache_n_stores_ok;
42451+extern atomic_unchecked_t fscache_n_stores_again;
42452+extern atomic_unchecked_t fscache_n_stores_nobufs;
42453+extern atomic_unchecked_t fscache_n_stores_oom;
42454+extern atomic_unchecked_t fscache_n_store_ops;
42455+extern atomic_unchecked_t fscache_n_store_calls;
42456+extern atomic_unchecked_t fscache_n_store_pages;
42457+extern atomic_unchecked_t fscache_n_store_radix_deletes;
42458+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
42459+
42460+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
42461+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
42462+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
42463+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
42464+
42465+extern atomic_unchecked_t fscache_n_marks;
42466+extern atomic_unchecked_t fscache_n_uncaches;
42467+
42468+extern atomic_unchecked_t fscache_n_acquires;
42469+extern atomic_unchecked_t fscache_n_acquires_null;
42470+extern atomic_unchecked_t fscache_n_acquires_no_cache;
42471+extern atomic_unchecked_t fscache_n_acquires_ok;
42472+extern atomic_unchecked_t fscache_n_acquires_nobufs;
42473+extern atomic_unchecked_t fscache_n_acquires_oom;
42474+
42475+extern atomic_unchecked_t fscache_n_updates;
42476+extern atomic_unchecked_t fscache_n_updates_null;
42477+extern atomic_unchecked_t fscache_n_updates_run;
42478+
42479+extern atomic_unchecked_t fscache_n_relinquishes;
42480+extern atomic_unchecked_t fscache_n_relinquishes_null;
42481+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
42482+extern atomic_unchecked_t fscache_n_relinquishes_retire;
42483+
42484+extern atomic_unchecked_t fscache_n_cookie_index;
42485+extern atomic_unchecked_t fscache_n_cookie_data;
42486+extern atomic_unchecked_t fscache_n_cookie_special;
42487+
42488+extern atomic_unchecked_t fscache_n_object_alloc;
42489+extern atomic_unchecked_t fscache_n_object_no_alloc;
42490+extern atomic_unchecked_t fscache_n_object_lookups;
42491+extern atomic_unchecked_t fscache_n_object_lookups_negative;
42492+extern atomic_unchecked_t fscache_n_object_lookups_positive;
42493+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
42494+extern atomic_unchecked_t fscache_n_object_created;
42495+extern atomic_unchecked_t fscache_n_object_avail;
42496+extern atomic_unchecked_t fscache_n_object_dead;
42497+
42498+extern atomic_unchecked_t fscache_n_checkaux_none;
42499+extern atomic_unchecked_t fscache_n_checkaux_okay;
42500+extern atomic_unchecked_t fscache_n_checkaux_update;
42501+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
42502
42503 extern atomic_t fscache_n_cop_alloc_object;
42504 extern atomic_t fscache_n_cop_lookup_object;
42505@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t
42506 atomic_inc(stat);
42507 }
42508
42509+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
42510+{
42511+ atomic_inc_unchecked(stat);
42512+}
42513+
42514 static inline void fscache_stat_d(atomic_t *stat)
42515 {
42516 atomic_dec(stat);
42517@@ -259,6 +264,7 @@ extern const struct file_operations fsca
42518
42519 #define __fscache_stat(stat) (NULL)
42520 #define fscache_stat(stat) do {} while (0)
42521+#define fscache_stat_unchecked(stat) do {} while (0)
42522 #define fscache_stat_d(stat) do {} while (0)
42523 #endif
42524
42525diff -urNp linux-2.6.32.44/fs/fscache/object.c linux-2.6.32.44/fs/fscache/object.c
42526--- linux-2.6.32.44/fs/fscache/object.c 2011-03-27 14:31:47.000000000 -0400
42527+++ linux-2.6.32.44/fs/fscache/object.c 2011-05-04 17:56:28.000000000 -0400
42528@@ -144,7 +144,7 @@ static void fscache_object_state_machine
42529 /* update the object metadata on disk */
42530 case FSCACHE_OBJECT_UPDATING:
42531 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
42532- fscache_stat(&fscache_n_updates_run);
42533+ fscache_stat_unchecked(&fscache_n_updates_run);
42534 fscache_stat(&fscache_n_cop_update_object);
42535 object->cache->ops->update_object(object);
42536 fscache_stat_d(&fscache_n_cop_update_object);
42537@@ -233,7 +233,7 @@ static void fscache_object_state_machine
42538 spin_lock(&object->lock);
42539 object->state = FSCACHE_OBJECT_DEAD;
42540 spin_unlock(&object->lock);
42541- fscache_stat(&fscache_n_object_dead);
42542+ fscache_stat_unchecked(&fscache_n_object_dead);
42543 goto terminal_transit;
42544
42545 /* handle the parent cache of this object being withdrawn from
42546@@ -248,7 +248,7 @@ static void fscache_object_state_machine
42547 spin_lock(&object->lock);
42548 object->state = FSCACHE_OBJECT_DEAD;
42549 spin_unlock(&object->lock);
42550- fscache_stat(&fscache_n_object_dead);
42551+ fscache_stat_unchecked(&fscache_n_object_dead);
42552 goto terminal_transit;
42553
42554 /* complain about the object being woken up once it is
42555@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct
42556 parent->cookie->def->name, cookie->def->name,
42557 object->cache->tag->name);
42558
42559- fscache_stat(&fscache_n_object_lookups);
42560+ fscache_stat_unchecked(&fscache_n_object_lookups);
42561 fscache_stat(&fscache_n_cop_lookup_object);
42562 ret = object->cache->ops->lookup_object(object);
42563 fscache_stat_d(&fscache_n_cop_lookup_object);
42564@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct
42565 if (ret == -ETIMEDOUT) {
42566 /* probably stuck behind another object, so move this one to
42567 * the back of the queue */
42568- fscache_stat(&fscache_n_object_lookups_timed_out);
42569+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
42570 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
42571 }
42572
42573@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(stru
42574
42575 spin_lock(&object->lock);
42576 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
42577- fscache_stat(&fscache_n_object_lookups_negative);
42578+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
42579
42580 /* transit here to allow write requests to begin stacking up
42581 * and read requests to begin returning ENODATA */
42582@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fsca
42583 * result, in which case there may be data available */
42584 spin_lock(&object->lock);
42585 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
42586- fscache_stat(&fscache_n_object_lookups_positive);
42587+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
42588
42589 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
42590
42591@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fsca
42592 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
42593 } else {
42594 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
42595- fscache_stat(&fscache_n_object_created);
42596+ fscache_stat_unchecked(&fscache_n_object_created);
42597
42598 object->state = FSCACHE_OBJECT_AVAILABLE;
42599 spin_unlock(&object->lock);
42600@@ -633,7 +633,7 @@ static void fscache_object_available(str
42601 fscache_enqueue_dependents(object);
42602
42603 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
42604- fscache_stat(&fscache_n_object_avail);
42605+ fscache_stat_unchecked(&fscache_n_object_avail);
42606
42607 _leave("");
42608 }
42609@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
42610 enum fscache_checkaux result;
42611
42612 if (!object->cookie->def->check_aux) {
42613- fscache_stat(&fscache_n_checkaux_none);
42614+ fscache_stat_unchecked(&fscache_n_checkaux_none);
42615 return FSCACHE_CHECKAUX_OKAY;
42616 }
42617
42618@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
42619 switch (result) {
42620 /* entry okay as is */
42621 case FSCACHE_CHECKAUX_OKAY:
42622- fscache_stat(&fscache_n_checkaux_okay);
42623+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
42624 break;
42625
42626 /* entry requires update */
42627 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
42628- fscache_stat(&fscache_n_checkaux_update);
42629+ fscache_stat_unchecked(&fscache_n_checkaux_update);
42630 break;
42631
42632 /* entry requires deletion */
42633 case FSCACHE_CHECKAUX_OBSOLETE:
42634- fscache_stat(&fscache_n_checkaux_obsolete);
42635+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
42636 break;
42637
42638 default:
42639diff -urNp linux-2.6.32.44/fs/fscache/operation.c linux-2.6.32.44/fs/fscache/operation.c
42640--- linux-2.6.32.44/fs/fscache/operation.c 2011-03-27 14:31:47.000000000 -0400
42641+++ linux-2.6.32.44/fs/fscache/operation.c 2011-05-04 17:56:28.000000000 -0400
42642@@ -16,7 +16,7 @@
42643 #include <linux/seq_file.h>
42644 #include "internal.h"
42645
42646-atomic_t fscache_op_debug_id;
42647+atomic_unchecked_t fscache_op_debug_id;
42648 EXPORT_SYMBOL(fscache_op_debug_id);
42649
42650 /**
42651@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fs
42652 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
42653 ASSERTCMP(atomic_read(&op->usage), >, 0);
42654
42655- fscache_stat(&fscache_n_op_enqueue);
42656+ fscache_stat_unchecked(&fscache_n_op_enqueue);
42657 switch (op->flags & FSCACHE_OP_TYPE) {
42658 case FSCACHE_OP_FAST:
42659 _debug("queue fast");
42660@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscach
42661 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
42662 if (op->processor)
42663 fscache_enqueue_operation(op);
42664- fscache_stat(&fscache_n_op_run);
42665+ fscache_stat_unchecked(&fscache_n_op_run);
42666 }
42667
42668 /*
42669@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct f
42670 if (object->n_ops > 0) {
42671 atomic_inc(&op->usage);
42672 list_add_tail(&op->pend_link, &object->pending_ops);
42673- fscache_stat(&fscache_n_op_pend);
42674+ fscache_stat_unchecked(&fscache_n_op_pend);
42675 } else if (!list_empty(&object->pending_ops)) {
42676 atomic_inc(&op->usage);
42677 list_add_tail(&op->pend_link, &object->pending_ops);
42678- fscache_stat(&fscache_n_op_pend);
42679+ fscache_stat_unchecked(&fscache_n_op_pend);
42680 fscache_start_operations(object);
42681 } else {
42682 ASSERTCMP(object->n_in_progress, ==, 0);
42683@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct f
42684 object->n_exclusive++; /* reads and writes must wait */
42685 atomic_inc(&op->usage);
42686 list_add_tail(&op->pend_link, &object->pending_ops);
42687- fscache_stat(&fscache_n_op_pend);
42688+ fscache_stat_unchecked(&fscache_n_op_pend);
42689 ret = 0;
42690 } else {
42691 /* not allowed to submit ops in any other state */
42692@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_obj
42693 if (object->n_exclusive > 0) {
42694 atomic_inc(&op->usage);
42695 list_add_tail(&op->pend_link, &object->pending_ops);
42696- fscache_stat(&fscache_n_op_pend);
42697+ fscache_stat_unchecked(&fscache_n_op_pend);
42698 } else if (!list_empty(&object->pending_ops)) {
42699 atomic_inc(&op->usage);
42700 list_add_tail(&op->pend_link, &object->pending_ops);
42701- fscache_stat(&fscache_n_op_pend);
42702+ fscache_stat_unchecked(&fscache_n_op_pend);
42703 fscache_start_operations(object);
42704 } else {
42705 ASSERTCMP(object->n_exclusive, ==, 0);
42706@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_obj
42707 object->n_ops++;
42708 atomic_inc(&op->usage);
42709 list_add_tail(&op->pend_link, &object->pending_ops);
42710- fscache_stat(&fscache_n_op_pend);
42711+ fscache_stat_unchecked(&fscache_n_op_pend);
42712 ret = 0;
42713 } else if (object->state == FSCACHE_OBJECT_DYING ||
42714 object->state == FSCACHE_OBJECT_LC_DYING ||
42715 object->state == FSCACHE_OBJECT_WITHDRAWING) {
42716- fscache_stat(&fscache_n_op_rejected);
42717+ fscache_stat_unchecked(&fscache_n_op_rejected);
42718 ret = -ENOBUFS;
42719 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
42720 fscache_report_unexpected_submission(object, op, ostate);
42721@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_ope
42722
42723 ret = -EBUSY;
42724 if (!list_empty(&op->pend_link)) {
42725- fscache_stat(&fscache_n_op_cancelled);
42726+ fscache_stat_unchecked(&fscache_n_op_cancelled);
42727 list_del_init(&op->pend_link);
42728 object->n_ops--;
42729 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
42730@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscach
42731 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
42732 BUG();
42733
42734- fscache_stat(&fscache_n_op_release);
42735+ fscache_stat_unchecked(&fscache_n_op_release);
42736
42737 if (op->release) {
42738 op->release(op);
42739@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscach
42740 * lock, and defer it otherwise */
42741 if (!spin_trylock(&object->lock)) {
42742 _debug("defer put");
42743- fscache_stat(&fscache_n_op_deferred_release);
42744+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
42745
42746 cache = object->cache;
42747 spin_lock(&cache->op_gc_list_lock);
42748@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_st
42749
42750 _debug("GC DEFERRED REL OBJ%x OP%x",
42751 object->debug_id, op->debug_id);
42752- fscache_stat(&fscache_n_op_gc);
42753+ fscache_stat_unchecked(&fscache_n_op_gc);
42754
42755 ASSERTCMP(atomic_read(&op->usage), ==, 0);
42756
42757diff -urNp linux-2.6.32.44/fs/fscache/page.c linux-2.6.32.44/fs/fscache/page.c
42758--- linux-2.6.32.44/fs/fscache/page.c 2011-03-27 14:31:47.000000000 -0400
42759+++ linux-2.6.32.44/fs/fscache/page.c 2011-05-04 17:56:28.000000000 -0400
42760@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct
42761 val = radix_tree_lookup(&cookie->stores, page->index);
42762 if (!val) {
42763 rcu_read_unlock();
42764- fscache_stat(&fscache_n_store_vmscan_not_storing);
42765+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
42766 __fscache_uncache_page(cookie, page);
42767 return true;
42768 }
42769@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct
42770 spin_unlock(&cookie->stores_lock);
42771
42772 if (xpage) {
42773- fscache_stat(&fscache_n_store_vmscan_cancelled);
42774- fscache_stat(&fscache_n_store_radix_deletes);
42775+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
42776+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
42777 ASSERTCMP(xpage, ==, page);
42778 } else {
42779- fscache_stat(&fscache_n_store_vmscan_gone);
42780+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
42781 }
42782
42783 wake_up_bit(&cookie->flags, 0);
42784@@ -106,7 +106,7 @@ page_busy:
42785 /* we might want to wait here, but that could deadlock the allocator as
42786 * the slow-work threads writing to the cache may all end up sleeping
42787 * on memory allocation */
42788- fscache_stat(&fscache_n_store_vmscan_busy);
42789+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
42790 return false;
42791 }
42792 EXPORT_SYMBOL(__fscache_maybe_release_page);
42793@@ -130,7 +130,7 @@ static void fscache_end_page_write(struc
42794 FSCACHE_COOKIE_STORING_TAG);
42795 if (!radix_tree_tag_get(&cookie->stores, page->index,
42796 FSCACHE_COOKIE_PENDING_TAG)) {
42797- fscache_stat(&fscache_n_store_radix_deletes);
42798+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
42799 xpage = radix_tree_delete(&cookie->stores, page->index);
42800 }
42801 spin_unlock(&cookie->stores_lock);
42802@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(stru
42803
42804 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
42805
42806- fscache_stat(&fscache_n_attr_changed_calls);
42807+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
42808
42809 if (fscache_object_is_active(object)) {
42810 fscache_set_op_state(op, "CallFS");
42811@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscach
42812
42813 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
42814
42815- fscache_stat(&fscache_n_attr_changed);
42816+ fscache_stat_unchecked(&fscache_n_attr_changed);
42817
42818 op = kzalloc(sizeof(*op), GFP_KERNEL);
42819 if (!op) {
42820- fscache_stat(&fscache_n_attr_changed_nomem);
42821+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
42822 _leave(" = -ENOMEM");
42823 return -ENOMEM;
42824 }
42825@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
42826 if (fscache_submit_exclusive_op(object, op) < 0)
42827 goto nobufs;
42828 spin_unlock(&cookie->lock);
42829- fscache_stat(&fscache_n_attr_changed_ok);
42830+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
42831 fscache_put_operation(op);
42832 _leave(" = 0");
42833 return 0;
42834@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
42835 nobufs:
42836 spin_unlock(&cookie->lock);
42837 kfree(op);
42838- fscache_stat(&fscache_n_attr_changed_nobufs);
42839+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
42840 _leave(" = %d", -ENOBUFS);
42841 return -ENOBUFS;
42842 }
42843@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache
42844 /* allocate a retrieval operation and attempt to submit it */
42845 op = kzalloc(sizeof(*op), GFP_NOIO);
42846 if (!op) {
42847- fscache_stat(&fscache_n_retrievals_nomem);
42848+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
42849 return NULL;
42850 }
42851
42852@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_loo
42853 return 0;
42854 }
42855
42856- fscache_stat(&fscache_n_retrievals_wait);
42857+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
42858
42859 jif = jiffies;
42860 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
42861 fscache_wait_bit_interruptible,
42862 TASK_INTERRUPTIBLE) != 0) {
42863- fscache_stat(&fscache_n_retrievals_intr);
42864+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
42865 _leave(" = -ERESTARTSYS");
42866 return -ERESTARTSYS;
42867 }
42868@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_loo
42869 */
42870 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
42871 struct fscache_retrieval *op,
42872- atomic_t *stat_op_waits,
42873- atomic_t *stat_object_dead)
42874+ atomic_unchecked_t *stat_op_waits,
42875+ atomic_unchecked_t *stat_object_dead)
42876 {
42877 int ret;
42878
42879@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_ac
42880 goto check_if_dead;
42881
42882 _debug(">>> WT");
42883- fscache_stat(stat_op_waits);
42884+ fscache_stat_unchecked(stat_op_waits);
42885 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
42886 fscache_wait_bit_interruptible,
42887 TASK_INTERRUPTIBLE) < 0) {
42888@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_ac
42889
42890 check_if_dead:
42891 if (unlikely(fscache_object_is_dead(object))) {
42892- fscache_stat(stat_object_dead);
42893+ fscache_stat_unchecked(stat_object_dead);
42894 return -ENOBUFS;
42895 }
42896 return 0;
42897@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct
42898
42899 _enter("%p,%p,,,", cookie, page);
42900
42901- fscache_stat(&fscache_n_retrievals);
42902+ fscache_stat_unchecked(&fscache_n_retrievals);
42903
42904 if (hlist_empty(&cookie->backing_objects))
42905 goto nobufs;
42906@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct
42907 goto nobufs_unlock;
42908 spin_unlock(&cookie->lock);
42909
42910- fscache_stat(&fscache_n_retrieval_ops);
42911+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
42912
42913 /* pin the netfs read context in case we need to do the actual netfs
42914 * read because we've encountered a cache read failure */
42915@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct
42916
42917 error:
42918 if (ret == -ENOMEM)
42919- fscache_stat(&fscache_n_retrievals_nomem);
42920+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
42921 else if (ret == -ERESTARTSYS)
42922- fscache_stat(&fscache_n_retrievals_intr);
42923+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
42924 else if (ret == -ENODATA)
42925- fscache_stat(&fscache_n_retrievals_nodata);
42926+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
42927 else if (ret < 0)
42928- fscache_stat(&fscache_n_retrievals_nobufs);
42929+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42930 else
42931- fscache_stat(&fscache_n_retrievals_ok);
42932+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
42933
42934 fscache_put_retrieval(op);
42935 _leave(" = %d", ret);
42936@@ -453,7 +453,7 @@ nobufs_unlock:
42937 spin_unlock(&cookie->lock);
42938 kfree(op);
42939 nobufs:
42940- fscache_stat(&fscache_n_retrievals_nobufs);
42941+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42942 _leave(" = -ENOBUFS");
42943 return -ENOBUFS;
42944 }
42945@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct
42946
42947 _enter("%p,,%d,,,", cookie, *nr_pages);
42948
42949- fscache_stat(&fscache_n_retrievals);
42950+ fscache_stat_unchecked(&fscache_n_retrievals);
42951
42952 if (hlist_empty(&cookie->backing_objects))
42953 goto nobufs;
42954@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct
42955 goto nobufs_unlock;
42956 spin_unlock(&cookie->lock);
42957
42958- fscache_stat(&fscache_n_retrieval_ops);
42959+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
42960
42961 /* pin the netfs read context in case we need to do the actual netfs
42962 * read because we've encountered a cache read failure */
42963@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct
42964
42965 error:
42966 if (ret == -ENOMEM)
42967- fscache_stat(&fscache_n_retrievals_nomem);
42968+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
42969 else if (ret == -ERESTARTSYS)
42970- fscache_stat(&fscache_n_retrievals_intr);
42971+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
42972 else if (ret == -ENODATA)
42973- fscache_stat(&fscache_n_retrievals_nodata);
42974+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
42975 else if (ret < 0)
42976- fscache_stat(&fscache_n_retrievals_nobufs);
42977+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42978 else
42979- fscache_stat(&fscache_n_retrievals_ok);
42980+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
42981
42982 fscache_put_retrieval(op);
42983 _leave(" = %d", ret);
42984@@ -570,7 +570,7 @@ nobufs_unlock:
42985 spin_unlock(&cookie->lock);
42986 kfree(op);
42987 nobufs:
42988- fscache_stat(&fscache_n_retrievals_nobufs);
42989+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42990 _leave(" = -ENOBUFS");
42991 return -ENOBUFS;
42992 }
42993@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_
42994
42995 _enter("%p,%p,,,", cookie, page);
42996
42997- fscache_stat(&fscache_n_allocs);
42998+ fscache_stat_unchecked(&fscache_n_allocs);
42999
43000 if (hlist_empty(&cookie->backing_objects))
43001 goto nobufs;
43002@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_
43003 goto nobufs_unlock;
43004 spin_unlock(&cookie->lock);
43005
43006- fscache_stat(&fscache_n_alloc_ops);
43007+ fscache_stat_unchecked(&fscache_n_alloc_ops);
43008
43009 ret = fscache_wait_for_retrieval_activation(
43010 object, op,
43011@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_
43012
43013 error:
43014 if (ret == -ERESTARTSYS)
43015- fscache_stat(&fscache_n_allocs_intr);
43016+ fscache_stat_unchecked(&fscache_n_allocs_intr);
43017 else if (ret < 0)
43018- fscache_stat(&fscache_n_allocs_nobufs);
43019+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43020 else
43021- fscache_stat(&fscache_n_allocs_ok);
43022+ fscache_stat_unchecked(&fscache_n_allocs_ok);
43023
43024 fscache_put_retrieval(op);
43025 _leave(" = %d", ret);
43026@@ -651,7 +651,7 @@ nobufs_unlock:
43027 spin_unlock(&cookie->lock);
43028 kfree(op);
43029 nobufs:
43030- fscache_stat(&fscache_n_allocs_nobufs);
43031+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43032 _leave(" = -ENOBUFS");
43033 return -ENOBUFS;
43034 }
43035@@ -694,7 +694,7 @@ static void fscache_write_op(struct fsca
43036
43037 spin_lock(&cookie->stores_lock);
43038
43039- fscache_stat(&fscache_n_store_calls);
43040+ fscache_stat_unchecked(&fscache_n_store_calls);
43041
43042 /* find a page to store */
43043 page = NULL;
43044@@ -705,7 +705,7 @@ static void fscache_write_op(struct fsca
43045 page = results[0];
43046 _debug("gang %d [%lx]", n, page->index);
43047 if (page->index > op->store_limit) {
43048- fscache_stat(&fscache_n_store_pages_over_limit);
43049+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
43050 goto superseded;
43051 }
43052
43053@@ -721,7 +721,7 @@ static void fscache_write_op(struct fsca
43054
43055 if (page) {
43056 fscache_set_op_state(&op->op, "Store");
43057- fscache_stat(&fscache_n_store_pages);
43058+ fscache_stat_unchecked(&fscache_n_store_pages);
43059 fscache_stat(&fscache_n_cop_write_page);
43060 ret = object->cache->ops->write_page(op, page);
43061 fscache_stat_d(&fscache_n_cop_write_page);
43062@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_
43063 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43064 ASSERT(PageFsCache(page));
43065
43066- fscache_stat(&fscache_n_stores);
43067+ fscache_stat_unchecked(&fscache_n_stores);
43068
43069 op = kzalloc(sizeof(*op), GFP_NOIO);
43070 if (!op)
43071@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_
43072 spin_unlock(&cookie->stores_lock);
43073 spin_unlock(&object->lock);
43074
43075- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
43076+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
43077 op->store_limit = object->store_limit;
43078
43079 if (fscache_submit_op(object, &op->op) < 0)
43080@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_
43081
43082 spin_unlock(&cookie->lock);
43083 radix_tree_preload_end();
43084- fscache_stat(&fscache_n_store_ops);
43085- fscache_stat(&fscache_n_stores_ok);
43086+ fscache_stat_unchecked(&fscache_n_store_ops);
43087+ fscache_stat_unchecked(&fscache_n_stores_ok);
43088
43089 /* the slow work queue now carries its own ref on the object */
43090 fscache_put_operation(&op->op);
43091@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_
43092 return 0;
43093
43094 already_queued:
43095- fscache_stat(&fscache_n_stores_again);
43096+ fscache_stat_unchecked(&fscache_n_stores_again);
43097 already_pending:
43098 spin_unlock(&cookie->stores_lock);
43099 spin_unlock(&object->lock);
43100 spin_unlock(&cookie->lock);
43101 radix_tree_preload_end();
43102 kfree(op);
43103- fscache_stat(&fscache_n_stores_ok);
43104+ fscache_stat_unchecked(&fscache_n_stores_ok);
43105 _leave(" = 0");
43106 return 0;
43107
43108@@ -886,14 +886,14 @@ nobufs:
43109 spin_unlock(&cookie->lock);
43110 radix_tree_preload_end();
43111 kfree(op);
43112- fscache_stat(&fscache_n_stores_nobufs);
43113+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
43114 _leave(" = -ENOBUFS");
43115 return -ENOBUFS;
43116
43117 nomem_free:
43118 kfree(op);
43119 nomem:
43120- fscache_stat(&fscache_n_stores_oom);
43121+ fscache_stat_unchecked(&fscache_n_stores_oom);
43122 _leave(" = -ENOMEM");
43123 return -ENOMEM;
43124 }
43125@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscac
43126 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43127 ASSERTCMP(page, !=, NULL);
43128
43129- fscache_stat(&fscache_n_uncaches);
43130+ fscache_stat_unchecked(&fscache_n_uncaches);
43131
43132 /* cache withdrawal may beat us to it */
43133 if (!PageFsCache(page))
43134@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fs
43135 unsigned long loop;
43136
43137 #ifdef CONFIG_FSCACHE_STATS
43138- atomic_add(pagevec->nr, &fscache_n_marks);
43139+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
43140 #endif
43141
43142 for (loop = 0; loop < pagevec->nr; loop++) {
43143diff -urNp linux-2.6.32.44/fs/fscache/stats.c linux-2.6.32.44/fs/fscache/stats.c
43144--- linux-2.6.32.44/fs/fscache/stats.c 2011-03-27 14:31:47.000000000 -0400
43145+++ linux-2.6.32.44/fs/fscache/stats.c 2011-05-04 17:56:28.000000000 -0400
43146@@ -18,95 +18,95 @@
43147 /*
43148 * operation counters
43149 */
43150-atomic_t fscache_n_op_pend;
43151-atomic_t fscache_n_op_run;
43152-atomic_t fscache_n_op_enqueue;
43153-atomic_t fscache_n_op_requeue;
43154-atomic_t fscache_n_op_deferred_release;
43155-atomic_t fscache_n_op_release;
43156-atomic_t fscache_n_op_gc;
43157-atomic_t fscache_n_op_cancelled;
43158-atomic_t fscache_n_op_rejected;
43159-
43160-atomic_t fscache_n_attr_changed;
43161-atomic_t fscache_n_attr_changed_ok;
43162-atomic_t fscache_n_attr_changed_nobufs;
43163-atomic_t fscache_n_attr_changed_nomem;
43164-atomic_t fscache_n_attr_changed_calls;
43165-
43166-atomic_t fscache_n_allocs;
43167-atomic_t fscache_n_allocs_ok;
43168-atomic_t fscache_n_allocs_wait;
43169-atomic_t fscache_n_allocs_nobufs;
43170-atomic_t fscache_n_allocs_intr;
43171-atomic_t fscache_n_allocs_object_dead;
43172-atomic_t fscache_n_alloc_ops;
43173-atomic_t fscache_n_alloc_op_waits;
43174-
43175-atomic_t fscache_n_retrievals;
43176-atomic_t fscache_n_retrievals_ok;
43177-atomic_t fscache_n_retrievals_wait;
43178-atomic_t fscache_n_retrievals_nodata;
43179-atomic_t fscache_n_retrievals_nobufs;
43180-atomic_t fscache_n_retrievals_intr;
43181-atomic_t fscache_n_retrievals_nomem;
43182-atomic_t fscache_n_retrievals_object_dead;
43183-atomic_t fscache_n_retrieval_ops;
43184-atomic_t fscache_n_retrieval_op_waits;
43185-
43186-atomic_t fscache_n_stores;
43187-atomic_t fscache_n_stores_ok;
43188-atomic_t fscache_n_stores_again;
43189-atomic_t fscache_n_stores_nobufs;
43190-atomic_t fscache_n_stores_oom;
43191-atomic_t fscache_n_store_ops;
43192-atomic_t fscache_n_store_calls;
43193-atomic_t fscache_n_store_pages;
43194-atomic_t fscache_n_store_radix_deletes;
43195-atomic_t fscache_n_store_pages_over_limit;
43196-
43197-atomic_t fscache_n_store_vmscan_not_storing;
43198-atomic_t fscache_n_store_vmscan_gone;
43199-atomic_t fscache_n_store_vmscan_busy;
43200-atomic_t fscache_n_store_vmscan_cancelled;
43201-
43202-atomic_t fscache_n_marks;
43203-atomic_t fscache_n_uncaches;
43204-
43205-atomic_t fscache_n_acquires;
43206-atomic_t fscache_n_acquires_null;
43207-atomic_t fscache_n_acquires_no_cache;
43208-atomic_t fscache_n_acquires_ok;
43209-atomic_t fscache_n_acquires_nobufs;
43210-atomic_t fscache_n_acquires_oom;
43211-
43212-atomic_t fscache_n_updates;
43213-atomic_t fscache_n_updates_null;
43214-atomic_t fscache_n_updates_run;
43215-
43216-atomic_t fscache_n_relinquishes;
43217-atomic_t fscache_n_relinquishes_null;
43218-atomic_t fscache_n_relinquishes_waitcrt;
43219-atomic_t fscache_n_relinquishes_retire;
43220-
43221-atomic_t fscache_n_cookie_index;
43222-atomic_t fscache_n_cookie_data;
43223-atomic_t fscache_n_cookie_special;
43224-
43225-atomic_t fscache_n_object_alloc;
43226-atomic_t fscache_n_object_no_alloc;
43227-atomic_t fscache_n_object_lookups;
43228-atomic_t fscache_n_object_lookups_negative;
43229-atomic_t fscache_n_object_lookups_positive;
43230-atomic_t fscache_n_object_lookups_timed_out;
43231-atomic_t fscache_n_object_created;
43232-atomic_t fscache_n_object_avail;
43233-atomic_t fscache_n_object_dead;
43234-
43235-atomic_t fscache_n_checkaux_none;
43236-atomic_t fscache_n_checkaux_okay;
43237-atomic_t fscache_n_checkaux_update;
43238-atomic_t fscache_n_checkaux_obsolete;
43239+atomic_unchecked_t fscache_n_op_pend;
43240+atomic_unchecked_t fscache_n_op_run;
43241+atomic_unchecked_t fscache_n_op_enqueue;
43242+atomic_unchecked_t fscache_n_op_requeue;
43243+atomic_unchecked_t fscache_n_op_deferred_release;
43244+atomic_unchecked_t fscache_n_op_release;
43245+atomic_unchecked_t fscache_n_op_gc;
43246+atomic_unchecked_t fscache_n_op_cancelled;
43247+atomic_unchecked_t fscache_n_op_rejected;
43248+
43249+atomic_unchecked_t fscache_n_attr_changed;
43250+atomic_unchecked_t fscache_n_attr_changed_ok;
43251+atomic_unchecked_t fscache_n_attr_changed_nobufs;
43252+atomic_unchecked_t fscache_n_attr_changed_nomem;
43253+atomic_unchecked_t fscache_n_attr_changed_calls;
43254+
43255+atomic_unchecked_t fscache_n_allocs;
43256+atomic_unchecked_t fscache_n_allocs_ok;
43257+atomic_unchecked_t fscache_n_allocs_wait;
43258+atomic_unchecked_t fscache_n_allocs_nobufs;
43259+atomic_unchecked_t fscache_n_allocs_intr;
43260+atomic_unchecked_t fscache_n_allocs_object_dead;
43261+atomic_unchecked_t fscache_n_alloc_ops;
43262+atomic_unchecked_t fscache_n_alloc_op_waits;
43263+
43264+atomic_unchecked_t fscache_n_retrievals;
43265+atomic_unchecked_t fscache_n_retrievals_ok;
43266+atomic_unchecked_t fscache_n_retrievals_wait;
43267+atomic_unchecked_t fscache_n_retrievals_nodata;
43268+atomic_unchecked_t fscache_n_retrievals_nobufs;
43269+atomic_unchecked_t fscache_n_retrievals_intr;
43270+atomic_unchecked_t fscache_n_retrievals_nomem;
43271+atomic_unchecked_t fscache_n_retrievals_object_dead;
43272+atomic_unchecked_t fscache_n_retrieval_ops;
43273+atomic_unchecked_t fscache_n_retrieval_op_waits;
43274+
43275+atomic_unchecked_t fscache_n_stores;
43276+atomic_unchecked_t fscache_n_stores_ok;
43277+atomic_unchecked_t fscache_n_stores_again;
43278+atomic_unchecked_t fscache_n_stores_nobufs;
43279+atomic_unchecked_t fscache_n_stores_oom;
43280+atomic_unchecked_t fscache_n_store_ops;
43281+atomic_unchecked_t fscache_n_store_calls;
43282+atomic_unchecked_t fscache_n_store_pages;
43283+atomic_unchecked_t fscache_n_store_radix_deletes;
43284+atomic_unchecked_t fscache_n_store_pages_over_limit;
43285+
43286+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
43287+atomic_unchecked_t fscache_n_store_vmscan_gone;
43288+atomic_unchecked_t fscache_n_store_vmscan_busy;
43289+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
43290+
43291+atomic_unchecked_t fscache_n_marks;
43292+atomic_unchecked_t fscache_n_uncaches;
43293+
43294+atomic_unchecked_t fscache_n_acquires;
43295+atomic_unchecked_t fscache_n_acquires_null;
43296+atomic_unchecked_t fscache_n_acquires_no_cache;
43297+atomic_unchecked_t fscache_n_acquires_ok;
43298+atomic_unchecked_t fscache_n_acquires_nobufs;
43299+atomic_unchecked_t fscache_n_acquires_oom;
43300+
43301+atomic_unchecked_t fscache_n_updates;
43302+atomic_unchecked_t fscache_n_updates_null;
43303+atomic_unchecked_t fscache_n_updates_run;
43304+
43305+atomic_unchecked_t fscache_n_relinquishes;
43306+atomic_unchecked_t fscache_n_relinquishes_null;
43307+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
43308+atomic_unchecked_t fscache_n_relinquishes_retire;
43309+
43310+atomic_unchecked_t fscache_n_cookie_index;
43311+atomic_unchecked_t fscache_n_cookie_data;
43312+atomic_unchecked_t fscache_n_cookie_special;
43313+
43314+atomic_unchecked_t fscache_n_object_alloc;
43315+atomic_unchecked_t fscache_n_object_no_alloc;
43316+atomic_unchecked_t fscache_n_object_lookups;
43317+atomic_unchecked_t fscache_n_object_lookups_negative;
43318+atomic_unchecked_t fscache_n_object_lookups_positive;
43319+atomic_unchecked_t fscache_n_object_lookups_timed_out;
43320+atomic_unchecked_t fscache_n_object_created;
43321+atomic_unchecked_t fscache_n_object_avail;
43322+atomic_unchecked_t fscache_n_object_dead;
43323+
43324+atomic_unchecked_t fscache_n_checkaux_none;
43325+atomic_unchecked_t fscache_n_checkaux_okay;
43326+atomic_unchecked_t fscache_n_checkaux_update;
43327+atomic_unchecked_t fscache_n_checkaux_obsolete;
43328
43329 atomic_t fscache_n_cop_alloc_object;
43330 atomic_t fscache_n_cop_lookup_object;
43331@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
43332 seq_puts(m, "FS-Cache statistics\n");
43333
43334 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
43335- atomic_read(&fscache_n_cookie_index),
43336- atomic_read(&fscache_n_cookie_data),
43337- atomic_read(&fscache_n_cookie_special));
43338+ atomic_read_unchecked(&fscache_n_cookie_index),
43339+ atomic_read_unchecked(&fscache_n_cookie_data),
43340+ atomic_read_unchecked(&fscache_n_cookie_special));
43341
43342 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
43343- atomic_read(&fscache_n_object_alloc),
43344- atomic_read(&fscache_n_object_no_alloc),
43345- atomic_read(&fscache_n_object_avail),
43346- atomic_read(&fscache_n_object_dead));
43347+ atomic_read_unchecked(&fscache_n_object_alloc),
43348+ atomic_read_unchecked(&fscache_n_object_no_alloc),
43349+ atomic_read_unchecked(&fscache_n_object_avail),
43350+ atomic_read_unchecked(&fscache_n_object_dead));
43351 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
43352- atomic_read(&fscache_n_checkaux_none),
43353- atomic_read(&fscache_n_checkaux_okay),
43354- atomic_read(&fscache_n_checkaux_update),
43355- atomic_read(&fscache_n_checkaux_obsolete));
43356+ atomic_read_unchecked(&fscache_n_checkaux_none),
43357+ atomic_read_unchecked(&fscache_n_checkaux_okay),
43358+ atomic_read_unchecked(&fscache_n_checkaux_update),
43359+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
43360
43361 seq_printf(m, "Pages : mrk=%u unc=%u\n",
43362- atomic_read(&fscache_n_marks),
43363- atomic_read(&fscache_n_uncaches));
43364+ atomic_read_unchecked(&fscache_n_marks),
43365+ atomic_read_unchecked(&fscache_n_uncaches));
43366
43367 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
43368 " oom=%u\n",
43369- atomic_read(&fscache_n_acquires),
43370- atomic_read(&fscache_n_acquires_null),
43371- atomic_read(&fscache_n_acquires_no_cache),
43372- atomic_read(&fscache_n_acquires_ok),
43373- atomic_read(&fscache_n_acquires_nobufs),
43374- atomic_read(&fscache_n_acquires_oom));
43375+ atomic_read_unchecked(&fscache_n_acquires),
43376+ atomic_read_unchecked(&fscache_n_acquires_null),
43377+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
43378+ atomic_read_unchecked(&fscache_n_acquires_ok),
43379+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
43380+ atomic_read_unchecked(&fscache_n_acquires_oom));
43381
43382 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
43383- atomic_read(&fscache_n_object_lookups),
43384- atomic_read(&fscache_n_object_lookups_negative),
43385- atomic_read(&fscache_n_object_lookups_positive),
43386- atomic_read(&fscache_n_object_lookups_timed_out),
43387- atomic_read(&fscache_n_object_created));
43388+ atomic_read_unchecked(&fscache_n_object_lookups),
43389+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
43390+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
43391+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
43392+ atomic_read_unchecked(&fscache_n_object_created));
43393
43394 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
43395- atomic_read(&fscache_n_updates),
43396- atomic_read(&fscache_n_updates_null),
43397- atomic_read(&fscache_n_updates_run));
43398+ atomic_read_unchecked(&fscache_n_updates),
43399+ atomic_read_unchecked(&fscache_n_updates_null),
43400+ atomic_read_unchecked(&fscache_n_updates_run));
43401
43402 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
43403- atomic_read(&fscache_n_relinquishes),
43404- atomic_read(&fscache_n_relinquishes_null),
43405- atomic_read(&fscache_n_relinquishes_waitcrt),
43406- atomic_read(&fscache_n_relinquishes_retire));
43407+ atomic_read_unchecked(&fscache_n_relinquishes),
43408+ atomic_read_unchecked(&fscache_n_relinquishes_null),
43409+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
43410+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
43411
43412 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
43413- atomic_read(&fscache_n_attr_changed),
43414- atomic_read(&fscache_n_attr_changed_ok),
43415- atomic_read(&fscache_n_attr_changed_nobufs),
43416- atomic_read(&fscache_n_attr_changed_nomem),
43417- atomic_read(&fscache_n_attr_changed_calls));
43418+ atomic_read_unchecked(&fscache_n_attr_changed),
43419+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
43420+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
43421+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
43422+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
43423
43424 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
43425- atomic_read(&fscache_n_allocs),
43426- atomic_read(&fscache_n_allocs_ok),
43427- atomic_read(&fscache_n_allocs_wait),
43428- atomic_read(&fscache_n_allocs_nobufs),
43429- atomic_read(&fscache_n_allocs_intr));
43430+ atomic_read_unchecked(&fscache_n_allocs),
43431+ atomic_read_unchecked(&fscache_n_allocs_ok),
43432+ atomic_read_unchecked(&fscache_n_allocs_wait),
43433+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
43434+ atomic_read_unchecked(&fscache_n_allocs_intr));
43435 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
43436- atomic_read(&fscache_n_alloc_ops),
43437- atomic_read(&fscache_n_alloc_op_waits),
43438- atomic_read(&fscache_n_allocs_object_dead));
43439+ atomic_read_unchecked(&fscache_n_alloc_ops),
43440+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
43441+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
43442
43443 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
43444 " int=%u oom=%u\n",
43445- atomic_read(&fscache_n_retrievals),
43446- atomic_read(&fscache_n_retrievals_ok),
43447- atomic_read(&fscache_n_retrievals_wait),
43448- atomic_read(&fscache_n_retrievals_nodata),
43449- atomic_read(&fscache_n_retrievals_nobufs),
43450- atomic_read(&fscache_n_retrievals_intr),
43451- atomic_read(&fscache_n_retrievals_nomem));
43452+ atomic_read_unchecked(&fscache_n_retrievals),
43453+ atomic_read_unchecked(&fscache_n_retrievals_ok),
43454+ atomic_read_unchecked(&fscache_n_retrievals_wait),
43455+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
43456+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
43457+ atomic_read_unchecked(&fscache_n_retrievals_intr),
43458+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
43459 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
43460- atomic_read(&fscache_n_retrieval_ops),
43461- atomic_read(&fscache_n_retrieval_op_waits),
43462- atomic_read(&fscache_n_retrievals_object_dead));
43463+ atomic_read_unchecked(&fscache_n_retrieval_ops),
43464+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
43465+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
43466
43467 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
43468- atomic_read(&fscache_n_stores),
43469- atomic_read(&fscache_n_stores_ok),
43470- atomic_read(&fscache_n_stores_again),
43471- atomic_read(&fscache_n_stores_nobufs),
43472- atomic_read(&fscache_n_stores_oom));
43473+ atomic_read_unchecked(&fscache_n_stores),
43474+ atomic_read_unchecked(&fscache_n_stores_ok),
43475+ atomic_read_unchecked(&fscache_n_stores_again),
43476+ atomic_read_unchecked(&fscache_n_stores_nobufs),
43477+ atomic_read_unchecked(&fscache_n_stores_oom));
43478 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
43479- atomic_read(&fscache_n_store_ops),
43480- atomic_read(&fscache_n_store_calls),
43481- atomic_read(&fscache_n_store_pages),
43482- atomic_read(&fscache_n_store_radix_deletes),
43483- atomic_read(&fscache_n_store_pages_over_limit));
43484+ atomic_read_unchecked(&fscache_n_store_ops),
43485+ atomic_read_unchecked(&fscache_n_store_calls),
43486+ atomic_read_unchecked(&fscache_n_store_pages),
43487+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
43488+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
43489
43490 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
43491- atomic_read(&fscache_n_store_vmscan_not_storing),
43492- atomic_read(&fscache_n_store_vmscan_gone),
43493- atomic_read(&fscache_n_store_vmscan_busy),
43494- atomic_read(&fscache_n_store_vmscan_cancelled));
43495+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
43496+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
43497+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
43498+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
43499
43500 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
43501- atomic_read(&fscache_n_op_pend),
43502- atomic_read(&fscache_n_op_run),
43503- atomic_read(&fscache_n_op_enqueue),
43504- atomic_read(&fscache_n_op_cancelled),
43505- atomic_read(&fscache_n_op_rejected));
43506+ atomic_read_unchecked(&fscache_n_op_pend),
43507+ atomic_read_unchecked(&fscache_n_op_run),
43508+ atomic_read_unchecked(&fscache_n_op_enqueue),
43509+ atomic_read_unchecked(&fscache_n_op_cancelled),
43510+ atomic_read_unchecked(&fscache_n_op_rejected));
43511 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
43512- atomic_read(&fscache_n_op_deferred_release),
43513- atomic_read(&fscache_n_op_release),
43514- atomic_read(&fscache_n_op_gc));
43515+ atomic_read_unchecked(&fscache_n_op_deferred_release),
43516+ atomic_read_unchecked(&fscache_n_op_release),
43517+ atomic_read_unchecked(&fscache_n_op_gc));
43518
43519 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
43520 atomic_read(&fscache_n_cop_alloc_object),
43521diff -urNp linux-2.6.32.44/fs/fs_struct.c linux-2.6.32.44/fs/fs_struct.c
43522--- linux-2.6.32.44/fs/fs_struct.c 2011-03-27 14:31:47.000000000 -0400
43523+++ linux-2.6.32.44/fs/fs_struct.c 2011-04-17 15:56:46.000000000 -0400
43524@@ -4,6 +4,7 @@
43525 #include <linux/path.h>
43526 #include <linux/slab.h>
43527 #include <linux/fs_struct.h>
43528+#include <linux/grsecurity.h>
43529
43530 /*
43531 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
43532@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, s
43533 old_root = fs->root;
43534 fs->root = *path;
43535 path_get(path);
43536+ gr_set_chroot_entries(current, path);
43537 write_unlock(&fs->lock);
43538 if (old_root.dentry)
43539 path_put(&old_root);
43540@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_roo
43541 && fs->root.mnt == old_root->mnt) {
43542 path_get(new_root);
43543 fs->root = *new_root;
43544+ gr_set_chroot_entries(p, new_root);
43545 count++;
43546 }
43547 if (fs->pwd.dentry == old_root->dentry
43548@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
43549 task_lock(tsk);
43550 write_lock(&fs->lock);
43551 tsk->fs = NULL;
43552- kill = !--fs->users;
43553+ gr_clear_chroot_entries(tsk);
43554+ kill = !atomic_dec_return(&fs->users);
43555 write_unlock(&fs->lock);
43556 task_unlock(tsk);
43557 if (kill)
43558@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct
43559 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
43560 /* We don't need to lock fs - think why ;-) */
43561 if (fs) {
43562- fs->users = 1;
43563+ atomic_set(&fs->users, 1);
43564 fs->in_exec = 0;
43565 rwlock_init(&fs->lock);
43566 fs->umask = old->umask;
43567@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
43568
43569 task_lock(current);
43570 write_lock(&fs->lock);
43571- kill = !--fs->users;
43572+ kill = !atomic_dec_return(&fs->users);
43573 current->fs = new_fs;
43574+ gr_set_chroot_entries(current, &new_fs->root);
43575 write_unlock(&fs->lock);
43576 task_unlock(current);
43577
43578@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
43579
43580 /* to be mentioned only in INIT_TASK */
43581 struct fs_struct init_fs = {
43582- .users = 1,
43583+ .users = ATOMIC_INIT(1),
43584 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
43585 .umask = 0022,
43586 };
43587@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
43588 task_lock(current);
43589
43590 write_lock(&init_fs.lock);
43591- init_fs.users++;
43592+ atomic_inc(&init_fs.users);
43593 write_unlock(&init_fs.lock);
43594
43595 write_lock(&fs->lock);
43596 current->fs = &init_fs;
43597- kill = !--fs->users;
43598+ gr_set_chroot_entries(current, &current->fs->root);
43599+ kill = !atomic_dec_return(&fs->users);
43600 write_unlock(&fs->lock);
43601
43602 task_unlock(current);
43603diff -urNp linux-2.6.32.44/fs/fuse/cuse.c linux-2.6.32.44/fs/fuse/cuse.c
43604--- linux-2.6.32.44/fs/fuse/cuse.c 2011-03-27 14:31:47.000000000 -0400
43605+++ linux-2.6.32.44/fs/fuse/cuse.c 2011-08-05 20:33:55.000000000 -0400
43606@@ -576,10 +576,12 @@ static int __init cuse_init(void)
43607 INIT_LIST_HEAD(&cuse_conntbl[i]);
43608
43609 /* inherit and extend fuse_dev_operations */
43610- cuse_channel_fops = fuse_dev_operations;
43611- cuse_channel_fops.owner = THIS_MODULE;
43612- cuse_channel_fops.open = cuse_channel_open;
43613- cuse_channel_fops.release = cuse_channel_release;
43614+ pax_open_kernel();
43615+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
43616+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
43617+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
43618+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
43619+ pax_close_kernel();
43620
43621 cuse_class = class_create(THIS_MODULE, "cuse");
43622 if (IS_ERR(cuse_class))
43623diff -urNp linux-2.6.32.44/fs/fuse/dev.c linux-2.6.32.44/fs/fuse/dev.c
43624--- linux-2.6.32.44/fs/fuse/dev.c 2011-03-27 14:31:47.000000000 -0400
43625+++ linux-2.6.32.44/fs/fuse/dev.c 2011-08-05 20:33:55.000000000 -0400
43626@@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struc
43627 {
43628 struct fuse_notify_inval_entry_out outarg;
43629 int err = -EINVAL;
43630- char buf[FUSE_NAME_MAX+1];
43631+ char *buf = NULL;
43632 struct qstr name;
43633
43634 if (size < sizeof(outarg))
43635@@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struc
43636 if (outarg.namelen > FUSE_NAME_MAX)
43637 goto err;
43638
43639+ err = -ENOMEM;
43640+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
43641+ if (!buf)
43642+ goto err;
43643+
43644 name.name = buf;
43645 name.len = outarg.namelen;
43646 err = fuse_copy_one(cs, buf, outarg.namelen + 1);
43647@@ -910,17 +915,15 @@ static int fuse_notify_inval_entry(struc
43648
43649 down_read(&fc->killsb);
43650 err = -ENOENT;
43651- if (!fc->sb)
43652- goto err_unlock;
43653-
43654- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
43655-
43656-err_unlock:
43657+ if (fc->sb)
43658+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
43659 up_read(&fc->killsb);
43660+ kfree(buf);
43661 return err;
43662
43663 err:
43664 fuse_copy_finish(cs);
43665+ kfree(buf);
43666 return err;
43667 }
43668
43669diff -urNp linux-2.6.32.44/fs/fuse/dir.c linux-2.6.32.44/fs/fuse/dir.c
43670--- linux-2.6.32.44/fs/fuse/dir.c 2011-03-27 14:31:47.000000000 -0400
43671+++ linux-2.6.32.44/fs/fuse/dir.c 2011-04-17 15:56:46.000000000 -0400
43672@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *de
43673 return link;
43674 }
43675
43676-static void free_link(char *link)
43677+static void free_link(const char *link)
43678 {
43679 if (!IS_ERR(link))
43680 free_page((unsigned long) link);
43681diff -urNp linux-2.6.32.44/fs/gfs2/ops_inode.c linux-2.6.32.44/fs/gfs2/ops_inode.c
43682--- linux-2.6.32.44/fs/gfs2/ops_inode.c 2011-03-27 14:31:47.000000000 -0400
43683+++ linux-2.6.32.44/fs/gfs2/ops_inode.c 2011-05-16 21:46:57.000000000 -0400
43684@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odi
43685 unsigned int x;
43686 int error;
43687
43688+ pax_track_stack();
43689+
43690 if (ndentry->d_inode) {
43691 nip = GFS2_I(ndentry->d_inode);
43692 if (ip == nip)
43693diff -urNp linux-2.6.32.44/fs/gfs2/sys.c linux-2.6.32.44/fs/gfs2/sys.c
43694--- linux-2.6.32.44/fs/gfs2/sys.c 2011-03-27 14:31:47.000000000 -0400
43695+++ linux-2.6.32.44/fs/gfs2/sys.c 2011-04-17 15:56:46.000000000 -0400
43696@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct ko
43697 return a->store ? a->store(sdp, buf, len) : len;
43698 }
43699
43700-static struct sysfs_ops gfs2_attr_ops = {
43701+static const struct sysfs_ops gfs2_attr_ops = {
43702 .show = gfs2_attr_show,
43703 .store = gfs2_attr_store,
43704 };
43705@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset
43706 return 0;
43707 }
43708
43709-static struct kset_uevent_ops gfs2_uevent_ops = {
43710+static const struct kset_uevent_ops gfs2_uevent_ops = {
43711 .uevent = gfs2_uevent,
43712 };
43713
43714diff -urNp linux-2.6.32.44/fs/hfsplus/catalog.c linux-2.6.32.44/fs/hfsplus/catalog.c
43715--- linux-2.6.32.44/fs/hfsplus/catalog.c 2011-03-27 14:31:47.000000000 -0400
43716+++ linux-2.6.32.44/fs/hfsplus/catalog.c 2011-05-16 21:46:57.000000000 -0400
43717@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block
43718 int err;
43719 u16 type;
43720
43721+ pax_track_stack();
43722+
43723 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
43724 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
43725 if (err)
43726@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct
43727 int entry_size;
43728 int err;
43729
43730+ pax_track_stack();
43731+
43732 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
43733 sb = dir->i_sb;
43734 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
43735@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
43736 int entry_size, type;
43737 int err = 0;
43738
43739+ pax_track_stack();
43740+
43741 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
43742 dst_dir->i_ino, dst_name->name);
43743 sb = src_dir->i_sb;
43744diff -urNp linux-2.6.32.44/fs/hfsplus/dir.c linux-2.6.32.44/fs/hfsplus/dir.c
43745--- linux-2.6.32.44/fs/hfsplus/dir.c 2011-03-27 14:31:47.000000000 -0400
43746+++ linux-2.6.32.44/fs/hfsplus/dir.c 2011-05-16 21:46:57.000000000 -0400
43747@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *
43748 struct hfsplus_readdir_data *rd;
43749 u16 type;
43750
43751+ pax_track_stack();
43752+
43753 if (filp->f_pos >= inode->i_size)
43754 return 0;
43755
43756diff -urNp linux-2.6.32.44/fs/hfsplus/inode.c linux-2.6.32.44/fs/hfsplus/inode.c
43757--- linux-2.6.32.44/fs/hfsplus/inode.c 2011-03-27 14:31:47.000000000 -0400
43758+++ linux-2.6.32.44/fs/hfsplus/inode.c 2011-05-16 21:46:57.000000000 -0400
43759@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode
43760 int res = 0;
43761 u16 type;
43762
43763+ pax_track_stack();
43764+
43765 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
43766
43767 HFSPLUS_I(inode).dev = 0;
43768@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode
43769 struct hfs_find_data fd;
43770 hfsplus_cat_entry entry;
43771
43772+ pax_track_stack();
43773+
43774 if (HFSPLUS_IS_RSRC(inode))
43775 main_inode = HFSPLUS_I(inode).rsrc_inode;
43776
43777diff -urNp linux-2.6.32.44/fs/hfsplus/ioctl.c linux-2.6.32.44/fs/hfsplus/ioctl.c
43778--- linux-2.6.32.44/fs/hfsplus/ioctl.c 2011-03-27 14:31:47.000000000 -0400
43779+++ linux-2.6.32.44/fs/hfsplus/ioctl.c 2011-05-16 21:46:57.000000000 -0400
43780@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dent
43781 struct hfsplus_cat_file *file;
43782 int res;
43783
43784+ pax_track_stack();
43785+
43786 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
43787 return -EOPNOTSUPP;
43788
43789@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *
43790 struct hfsplus_cat_file *file;
43791 ssize_t res = 0;
43792
43793+ pax_track_stack();
43794+
43795 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
43796 return -EOPNOTSUPP;
43797
43798diff -urNp linux-2.6.32.44/fs/hfsplus/super.c linux-2.6.32.44/fs/hfsplus/super.c
43799--- linux-2.6.32.44/fs/hfsplus/super.c 2011-03-27 14:31:47.000000000 -0400
43800+++ linux-2.6.32.44/fs/hfsplus/super.c 2011-05-16 21:46:57.000000000 -0400
43801@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct sup
43802 struct nls_table *nls = NULL;
43803 int err = -EINVAL;
43804
43805+ pax_track_stack();
43806+
43807 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
43808 if (!sbi)
43809 return -ENOMEM;
43810diff -urNp linux-2.6.32.44/fs/hugetlbfs/inode.c linux-2.6.32.44/fs/hugetlbfs/inode.c
43811--- linux-2.6.32.44/fs/hugetlbfs/inode.c 2011-03-27 14:31:47.000000000 -0400
43812+++ linux-2.6.32.44/fs/hugetlbfs/inode.c 2011-04-17 15:56:46.000000000 -0400
43813@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs
43814 .kill_sb = kill_litter_super,
43815 };
43816
43817-static struct vfsmount *hugetlbfs_vfsmount;
43818+struct vfsmount *hugetlbfs_vfsmount;
43819
43820 static int can_do_hugetlb_shm(void)
43821 {
43822diff -urNp linux-2.6.32.44/fs/ioctl.c linux-2.6.32.44/fs/ioctl.c
43823--- linux-2.6.32.44/fs/ioctl.c 2011-03-27 14:31:47.000000000 -0400
43824+++ linux-2.6.32.44/fs/ioctl.c 2011-04-17 15:56:46.000000000 -0400
43825@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiema
43826 u64 phys, u64 len, u32 flags)
43827 {
43828 struct fiemap_extent extent;
43829- struct fiemap_extent *dest = fieinfo->fi_extents_start;
43830+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
43831
43832 /* only count the extents */
43833 if (fieinfo->fi_extents_max == 0) {
43834@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *fil
43835
43836 fieinfo.fi_flags = fiemap.fm_flags;
43837 fieinfo.fi_extents_max = fiemap.fm_extent_count;
43838- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
43839+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
43840
43841 if (fiemap.fm_extent_count != 0 &&
43842 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
43843@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *fil
43844 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
43845 fiemap.fm_flags = fieinfo.fi_flags;
43846 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
43847- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
43848+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
43849 error = -EFAULT;
43850
43851 return error;
43852diff -urNp linux-2.6.32.44/fs/jbd/checkpoint.c linux-2.6.32.44/fs/jbd/checkpoint.c
43853--- linux-2.6.32.44/fs/jbd/checkpoint.c 2011-03-27 14:31:47.000000000 -0400
43854+++ linux-2.6.32.44/fs/jbd/checkpoint.c 2011-05-16 21:46:57.000000000 -0400
43855@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal
43856 tid_t this_tid;
43857 int result;
43858
43859+ pax_track_stack();
43860+
43861 jbd_debug(1, "Start checkpoint\n");
43862
43863 /*
43864diff -urNp linux-2.6.32.44/fs/jffs2/compr_rtime.c linux-2.6.32.44/fs/jffs2/compr_rtime.c
43865--- linux-2.6.32.44/fs/jffs2/compr_rtime.c 2011-03-27 14:31:47.000000000 -0400
43866+++ linux-2.6.32.44/fs/jffs2/compr_rtime.c 2011-05-16 21:46:57.000000000 -0400
43867@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
43868 int outpos = 0;
43869 int pos=0;
43870
43871+ pax_track_stack();
43872+
43873 memset(positions,0,sizeof(positions));
43874
43875 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
43876@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsign
43877 int outpos = 0;
43878 int pos=0;
43879
43880+ pax_track_stack();
43881+
43882 memset(positions,0,sizeof(positions));
43883
43884 while (outpos<destlen) {
43885diff -urNp linux-2.6.32.44/fs/jffs2/compr_rubin.c linux-2.6.32.44/fs/jffs2/compr_rubin.c
43886--- linux-2.6.32.44/fs/jffs2/compr_rubin.c 2011-03-27 14:31:47.000000000 -0400
43887+++ linux-2.6.32.44/fs/jffs2/compr_rubin.c 2011-05-16 21:46:57.000000000 -0400
43888@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
43889 int ret;
43890 uint32_t mysrclen, mydstlen;
43891
43892+ pax_track_stack();
43893+
43894 mysrclen = *sourcelen;
43895 mydstlen = *dstlen - 8;
43896
43897diff -urNp linux-2.6.32.44/fs/jffs2/erase.c linux-2.6.32.44/fs/jffs2/erase.c
43898--- linux-2.6.32.44/fs/jffs2/erase.c 2011-03-27 14:31:47.000000000 -0400
43899+++ linux-2.6.32.44/fs/jffs2/erase.c 2011-04-17 15:56:46.000000000 -0400
43900@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(stru
43901 struct jffs2_unknown_node marker = {
43902 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
43903 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
43904- .totlen = cpu_to_je32(c->cleanmarker_size)
43905+ .totlen = cpu_to_je32(c->cleanmarker_size),
43906+ .hdr_crc = cpu_to_je32(0)
43907 };
43908
43909 jffs2_prealloc_raw_node_refs(c, jeb, 1);
43910diff -urNp linux-2.6.32.44/fs/jffs2/wbuf.c linux-2.6.32.44/fs/jffs2/wbuf.c
43911--- linux-2.6.32.44/fs/jffs2/wbuf.c 2011-03-27 14:31:47.000000000 -0400
43912+++ linux-2.6.32.44/fs/jffs2/wbuf.c 2011-04-17 15:56:46.000000000 -0400
43913@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
43914 {
43915 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
43916 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
43917- .totlen = constant_cpu_to_je32(8)
43918+ .totlen = constant_cpu_to_je32(8),
43919+ .hdr_crc = constant_cpu_to_je32(0)
43920 };
43921
43922 /*
43923diff -urNp linux-2.6.32.44/fs/jffs2/xattr.c linux-2.6.32.44/fs/jffs2/xattr.c
43924--- linux-2.6.32.44/fs/jffs2/xattr.c 2011-03-27 14:31:47.000000000 -0400
43925+++ linux-2.6.32.44/fs/jffs2/xattr.c 2011-05-16 21:46:57.000000000 -0400
43926@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
43927
43928 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
43929
43930+ pax_track_stack();
43931+
43932 /* Phase.1 : Merge same xref */
43933 for (i=0; i < XREF_TMPHASH_SIZE; i++)
43934 xref_tmphash[i] = NULL;
43935diff -urNp linux-2.6.32.44/fs/jfs/super.c linux-2.6.32.44/fs/jfs/super.c
43936--- linux-2.6.32.44/fs/jfs/super.c 2011-03-27 14:31:47.000000000 -0400
43937+++ linux-2.6.32.44/fs/jfs/super.c 2011-06-07 18:06:04.000000000 -0400
43938@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
43939
43940 jfs_inode_cachep =
43941 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
43942- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
43943+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
43944 init_once);
43945 if (jfs_inode_cachep == NULL)
43946 return -ENOMEM;
43947diff -urNp linux-2.6.32.44/fs/Kconfig.binfmt linux-2.6.32.44/fs/Kconfig.binfmt
43948--- linux-2.6.32.44/fs/Kconfig.binfmt 2011-03-27 14:31:47.000000000 -0400
43949+++ linux-2.6.32.44/fs/Kconfig.binfmt 2011-04-17 15:56:46.000000000 -0400
43950@@ -86,7 +86,7 @@ config HAVE_AOUT
43951
43952 config BINFMT_AOUT
43953 tristate "Kernel support for a.out and ECOFF binaries"
43954- depends on HAVE_AOUT
43955+ depends on HAVE_AOUT && BROKEN
43956 ---help---
43957 A.out (Assembler.OUTput) is a set of formats for libraries and
43958 executables used in the earliest versions of UNIX. Linux used
43959diff -urNp linux-2.6.32.44/fs/libfs.c linux-2.6.32.44/fs/libfs.c
43960--- linux-2.6.32.44/fs/libfs.c 2011-03-27 14:31:47.000000000 -0400
43961+++ linux-2.6.32.44/fs/libfs.c 2011-05-11 18:25:15.000000000 -0400
43962@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, v
43963
43964 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
43965 struct dentry *next;
43966+ char d_name[sizeof(next->d_iname)];
43967+ const unsigned char *name;
43968+
43969 next = list_entry(p, struct dentry, d_u.d_child);
43970 if (d_unhashed(next) || !next->d_inode)
43971 continue;
43972
43973 spin_unlock(&dcache_lock);
43974- if (filldir(dirent, next->d_name.name,
43975+ name = next->d_name.name;
43976+ if (name == next->d_iname) {
43977+ memcpy(d_name, name, next->d_name.len);
43978+ name = d_name;
43979+ }
43980+ if (filldir(dirent, name,
43981 next->d_name.len, filp->f_pos,
43982 next->d_inode->i_ino,
43983 dt_type(next->d_inode)) < 0)
43984diff -urNp linux-2.6.32.44/fs/lockd/clntproc.c linux-2.6.32.44/fs/lockd/clntproc.c
43985--- linux-2.6.32.44/fs/lockd/clntproc.c 2011-03-27 14:31:47.000000000 -0400
43986+++ linux-2.6.32.44/fs/lockd/clntproc.c 2011-05-16 21:46:57.000000000 -0400
43987@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
43988 /*
43989 * Cookie counter for NLM requests
43990 */
43991-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
43992+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
43993
43994 void nlmclnt_next_cookie(struct nlm_cookie *c)
43995 {
43996- u32 cookie = atomic_inc_return(&nlm_cookie);
43997+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
43998
43999 memcpy(c->data, &cookie, 4);
44000 c->len=4;
44001@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
44002 struct nlm_rqst reqst, *req;
44003 int status;
44004
44005+ pax_track_stack();
44006+
44007 req = &reqst;
44008 memset(req, 0, sizeof(*req));
44009 locks_init_lock(&req->a_args.lock.fl);
44010diff -urNp linux-2.6.32.44/fs/lockd/svc.c linux-2.6.32.44/fs/lockd/svc.c
44011--- linux-2.6.32.44/fs/lockd/svc.c 2011-03-27 14:31:47.000000000 -0400
44012+++ linux-2.6.32.44/fs/lockd/svc.c 2011-04-17 15:56:46.000000000 -0400
44013@@ -43,7 +43,7 @@
44014
44015 static struct svc_program nlmsvc_program;
44016
44017-struct nlmsvc_binding * nlmsvc_ops;
44018+const struct nlmsvc_binding * nlmsvc_ops;
44019 EXPORT_SYMBOL_GPL(nlmsvc_ops);
44020
44021 static DEFINE_MUTEX(nlmsvc_mutex);
44022diff -urNp linux-2.6.32.44/fs/locks.c linux-2.6.32.44/fs/locks.c
44023--- linux-2.6.32.44/fs/locks.c 2011-03-27 14:31:47.000000000 -0400
44024+++ linux-2.6.32.44/fs/locks.c 2011-07-06 19:47:11.000000000 -0400
44025@@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
44026
44027 static struct kmem_cache *filelock_cache __read_mostly;
44028
44029+static void locks_init_lock_always(struct file_lock *fl)
44030+{
44031+ fl->fl_next = NULL;
44032+ fl->fl_fasync = NULL;
44033+ fl->fl_owner = NULL;
44034+ fl->fl_pid = 0;
44035+ fl->fl_nspid = NULL;
44036+ fl->fl_file = NULL;
44037+ fl->fl_flags = 0;
44038+ fl->fl_type = 0;
44039+ fl->fl_start = fl->fl_end = 0;
44040+}
44041+
44042 /* Allocate an empty lock structure. */
44043 static struct file_lock *locks_alloc_lock(void)
44044 {
44045- return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
44046+ struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
44047+
44048+ if (fl)
44049+ locks_init_lock_always(fl);
44050+
44051+ return fl;
44052 }
44053
44054 void locks_release_private(struct file_lock *fl)
44055@@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *f
44056 INIT_LIST_HEAD(&fl->fl_link);
44057 INIT_LIST_HEAD(&fl->fl_block);
44058 init_waitqueue_head(&fl->fl_wait);
44059- fl->fl_next = NULL;
44060- fl->fl_fasync = NULL;
44061- fl->fl_owner = NULL;
44062- fl->fl_pid = 0;
44063- fl->fl_nspid = NULL;
44064- fl->fl_file = NULL;
44065- fl->fl_flags = 0;
44066- fl->fl_type = 0;
44067- fl->fl_start = fl->fl_end = 0;
44068 fl->fl_ops = NULL;
44069 fl->fl_lmops = NULL;
44070+ locks_init_lock_always(fl);
44071 }
44072
44073 EXPORT_SYMBOL(locks_init_lock);
44074@@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *fil
44075 return;
44076
44077 if (filp->f_op && filp->f_op->flock) {
44078- struct file_lock fl = {
44079+ struct file_lock flock = {
44080 .fl_pid = current->tgid,
44081 .fl_file = filp,
44082 .fl_flags = FL_FLOCK,
44083 .fl_type = F_UNLCK,
44084 .fl_end = OFFSET_MAX,
44085 };
44086- filp->f_op->flock(filp, F_SETLKW, &fl);
44087- if (fl.fl_ops && fl.fl_ops->fl_release_private)
44088- fl.fl_ops->fl_release_private(&fl);
44089+ filp->f_op->flock(filp, F_SETLKW, &flock);
44090+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
44091+ flock.fl_ops->fl_release_private(&flock);
44092 }
44093
44094 lock_kernel();
44095diff -urNp linux-2.6.32.44/fs/mbcache.c linux-2.6.32.44/fs/mbcache.c
44096--- linux-2.6.32.44/fs/mbcache.c 2011-03-27 14:31:47.000000000 -0400
44097+++ linux-2.6.32.44/fs/mbcache.c 2011-08-05 20:33:55.000000000 -0400
44098@@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct
44099 if (!cache)
44100 goto fail;
44101 cache->c_name = name;
44102- cache->c_op.free = NULL;
44103+ *(void **)&cache->c_op.free = NULL;
44104 if (cache_op)
44105- cache->c_op.free = cache_op->free;
44106+ *(void **)&cache->c_op.free = cache_op->free;
44107 atomic_set(&cache->c_entry_count, 0);
44108 cache->c_bucket_bits = bucket_bits;
44109 #ifdef MB_CACHE_INDEXES_COUNT
44110diff -urNp linux-2.6.32.44/fs/namei.c linux-2.6.32.44/fs/namei.c
44111--- linux-2.6.32.44/fs/namei.c 2011-03-27 14:31:47.000000000 -0400
44112+++ linux-2.6.32.44/fs/namei.c 2011-05-16 21:46:57.000000000 -0400
44113@@ -224,14 +224,6 @@ int generic_permission(struct inode *ino
44114 return ret;
44115
44116 /*
44117- * Read/write DACs are always overridable.
44118- * Executable DACs are overridable if at least one exec bit is set.
44119- */
44120- if (!(mask & MAY_EXEC) || execute_ok(inode))
44121- if (capable(CAP_DAC_OVERRIDE))
44122- return 0;
44123-
44124- /*
44125 * Searching includes executable on directories, else just read.
44126 */
44127 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44128@@ -239,6 +231,14 @@ int generic_permission(struct inode *ino
44129 if (capable(CAP_DAC_READ_SEARCH))
44130 return 0;
44131
44132+ /*
44133+ * Read/write DACs are always overridable.
44134+ * Executable DACs are overridable if at least one exec bit is set.
44135+ */
44136+ if (!(mask & MAY_EXEC) || execute_ok(inode))
44137+ if (capable(CAP_DAC_OVERRIDE))
44138+ return 0;
44139+
44140 return -EACCES;
44141 }
44142
44143@@ -458,7 +458,8 @@ static int exec_permission_lite(struct i
44144 if (!ret)
44145 goto ok;
44146
44147- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
44148+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
44149+ capable(CAP_DAC_OVERRIDE))
44150 goto ok;
44151
44152 return ret;
44153@@ -638,7 +639,7 @@ static __always_inline int __do_follow_l
44154 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
44155 error = PTR_ERR(cookie);
44156 if (!IS_ERR(cookie)) {
44157- char *s = nd_get_link(nd);
44158+ const char *s = nd_get_link(nd);
44159 error = 0;
44160 if (s)
44161 error = __vfs_follow_link(nd, s);
44162@@ -669,6 +670,13 @@ static inline int do_follow_link(struct
44163 err = security_inode_follow_link(path->dentry, nd);
44164 if (err)
44165 goto loop;
44166+
44167+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
44168+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
44169+ err = -EACCES;
44170+ goto loop;
44171+ }
44172+
44173 current->link_count++;
44174 current->total_link_count++;
44175 nd->depth++;
44176@@ -1016,11 +1024,18 @@ return_reval:
44177 break;
44178 }
44179 return_base:
44180+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44181+ path_put(&nd->path);
44182+ return -ENOENT;
44183+ }
44184 return 0;
44185 out_dput:
44186 path_put_conditional(&next, nd);
44187 break;
44188 }
44189+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
44190+ err = -ENOENT;
44191+
44192 path_put(&nd->path);
44193 return_err:
44194 return err;
44195@@ -1091,13 +1106,20 @@ static int do_path_lookup(int dfd, const
44196 int retval = path_init(dfd, name, flags, nd);
44197 if (!retval)
44198 retval = path_walk(name, nd);
44199- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
44200- nd->path.dentry->d_inode))
44201- audit_inode(name, nd->path.dentry);
44202+
44203+ if (likely(!retval)) {
44204+ if (nd->path.dentry && nd->path.dentry->d_inode) {
44205+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
44206+ retval = -ENOENT;
44207+ if (!audit_dummy_context())
44208+ audit_inode(name, nd->path.dentry);
44209+ }
44210+ }
44211 if (nd->root.mnt) {
44212 path_put(&nd->root);
44213 nd->root.mnt = NULL;
44214 }
44215+
44216 return retval;
44217 }
44218
44219@@ -1576,6 +1598,20 @@ int may_open(struct path *path, int acc_
44220 if (error)
44221 goto err_out;
44222
44223+
44224+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
44225+ error = -EPERM;
44226+ goto err_out;
44227+ }
44228+ if (gr_handle_rawio(inode)) {
44229+ error = -EPERM;
44230+ goto err_out;
44231+ }
44232+ if (!gr_acl_handle_open(dentry, path->mnt, flag)) {
44233+ error = -EACCES;
44234+ goto err_out;
44235+ }
44236+
44237 if (flag & O_TRUNC) {
44238 error = get_write_access(inode);
44239 if (error)
44240@@ -1621,12 +1657,19 @@ static int __open_namei_create(struct na
44241 int error;
44242 struct dentry *dir = nd->path.dentry;
44243
44244+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
44245+ error = -EACCES;
44246+ goto out_unlock;
44247+ }
44248+
44249 if (!IS_POSIXACL(dir->d_inode))
44250 mode &= ~current_umask();
44251 error = security_path_mknod(&nd->path, path->dentry, mode, 0);
44252 if (error)
44253 goto out_unlock;
44254 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
44255+ if (!error)
44256+ gr_handle_create(path->dentry, nd->path.mnt);
44257 out_unlock:
44258 mutex_unlock(&dir->d_inode->i_mutex);
44259 dput(nd->path.dentry);
44260@@ -1709,6 +1752,22 @@ struct file *do_filp_open(int dfd, const
44261 &nd, flag);
44262 if (error)
44263 return ERR_PTR(error);
44264+
44265+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
44266+ error = -EPERM;
44267+ goto exit;
44268+ }
44269+
44270+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
44271+ error = -EPERM;
44272+ goto exit;
44273+ }
44274+
44275+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
44276+ error = -EACCES;
44277+ goto exit;
44278+ }
44279+
44280 goto ok;
44281 }
44282
44283@@ -1795,6 +1854,14 @@ do_last:
44284 /*
44285 * It already exists.
44286 */
44287+
44288+ /* only check if O_CREAT is specified, all other checks need
44289+ to go into may_open */
44290+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
44291+ error = -EACCES;
44292+ goto exit_mutex_unlock;
44293+ }
44294+
44295 mutex_unlock(&dir->d_inode->i_mutex);
44296 audit_inode(pathname, path.dentry);
44297
44298@@ -1887,6 +1954,13 @@ do_link:
44299 error = security_inode_follow_link(path.dentry, &nd);
44300 if (error)
44301 goto exit_dput;
44302+
44303+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
44304+ path.dentry, nd.path.mnt)) {
44305+ error = -EACCES;
44306+ goto exit_dput;
44307+ }
44308+
44309 error = __do_follow_link(&path, &nd);
44310 if (error) {
44311 /* Does someone understand code flow here? Or it is only
44312@@ -2061,6 +2135,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
44313 error = may_mknod(mode);
44314 if (error)
44315 goto out_dput;
44316+
44317+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
44318+ error = -EPERM;
44319+ goto out_dput;
44320+ }
44321+
44322+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
44323+ error = -EACCES;
44324+ goto out_dput;
44325+ }
44326+
44327 error = mnt_want_write(nd.path.mnt);
44328 if (error)
44329 goto out_dput;
44330@@ -2081,6 +2166,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
44331 }
44332 out_drop_write:
44333 mnt_drop_write(nd.path.mnt);
44334+
44335+ if (!error)
44336+ gr_handle_create(dentry, nd.path.mnt);
44337 out_dput:
44338 dput(dentry);
44339 out_unlock:
44340@@ -2134,6 +2222,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
44341 if (IS_ERR(dentry))
44342 goto out_unlock;
44343
44344+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
44345+ error = -EACCES;
44346+ goto out_dput;
44347+ }
44348+
44349 if (!IS_POSIXACL(nd.path.dentry->d_inode))
44350 mode &= ~current_umask();
44351 error = mnt_want_write(nd.path.mnt);
44352@@ -2145,6 +2238,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
44353 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
44354 out_drop_write:
44355 mnt_drop_write(nd.path.mnt);
44356+
44357+ if (!error)
44358+ gr_handle_create(dentry, nd.path.mnt);
44359+
44360 out_dput:
44361 dput(dentry);
44362 out_unlock:
44363@@ -2226,6 +2323,8 @@ static long do_rmdir(int dfd, const char
44364 char * name;
44365 struct dentry *dentry;
44366 struct nameidata nd;
44367+ ino_t saved_ino = 0;
44368+ dev_t saved_dev = 0;
44369
44370 error = user_path_parent(dfd, pathname, &nd, &name);
44371 if (error)
44372@@ -2250,6 +2349,19 @@ static long do_rmdir(int dfd, const char
44373 error = PTR_ERR(dentry);
44374 if (IS_ERR(dentry))
44375 goto exit2;
44376+
44377+ if (dentry->d_inode != NULL) {
44378+ if (dentry->d_inode->i_nlink <= 1) {
44379+ saved_ino = dentry->d_inode->i_ino;
44380+ saved_dev = gr_get_dev_from_dentry(dentry);
44381+ }
44382+
44383+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
44384+ error = -EACCES;
44385+ goto exit3;
44386+ }
44387+ }
44388+
44389 error = mnt_want_write(nd.path.mnt);
44390 if (error)
44391 goto exit3;
44392@@ -2257,6 +2369,8 @@ static long do_rmdir(int dfd, const char
44393 if (error)
44394 goto exit4;
44395 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
44396+ if (!error && (saved_dev || saved_ino))
44397+ gr_handle_delete(saved_ino, saved_dev);
44398 exit4:
44399 mnt_drop_write(nd.path.mnt);
44400 exit3:
44401@@ -2318,6 +2432,8 @@ static long do_unlinkat(int dfd, const c
44402 struct dentry *dentry;
44403 struct nameidata nd;
44404 struct inode *inode = NULL;
44405+ ino_t saved_ino = 0;
44406+ dev_t saved_dev = 0;
44407
44408 error = user_path_parent(dfd, pathname, &nd, &name);
44409 if (error)
44410@@ -2337,8 +2453,19 @@ static long do_unlinkat(int dfd, const c
44411 if (nd.last.name[nd.last.len])
44412 goto slashes;
44413 inode = dentry->d_inode;
44414- if (inode)
44415+ if (inode) {
44416+ if (inode->i_nlink <= 1) {
44417+ saved_ino = inode->i_ino;
44418+ saved_dev = gr_get_dev_from_dentry(dentry);
44419+ }
44420+
44421 atomic_inc(&inode->i_count);
44422+
44423+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
44424+ error = -EACCES;
44425+ goto exit2;
44426+ }
44427+ }
44428 error = mnt_want_write(nd.path.mnt);
44429 if (error)
44430 goto exit2;
44431@@ -2346,6 +2473,8 @@ static long do_unlinkat(int dfd, const c
44432 if (error)
44433 goto exit3;
44434 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
44435+ if (!error && (saved_ino || saved_dev))
44436+ gr_handle_delete(saved_ino, saved_dev);
44437 exit3:
44438 mnt_drop_write(nd.path.mnt);
44439 exit2:
44440@@ -2424,6 +2553,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
44441 if (IS_ERR(dentry))
44442 goto out_unlock;
44443
44444+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
44445+ error = -EACCES;
44446+ goto out_dput;
44447+ }
44448+
44449 error = mnt_want_write(nd.path.mnt);
44450 if (error)
44451 goto out_dput;
44452@@ -2431,6 +2565,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
44453 if (error)
44454 goto out_drop_write;
44455 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
44456+ if (!error)
44457+ gr_handle_create(dentry, nd.path.mnt);
44458 out_drop_write:
44459 mnt_drop_write(nd.path.mnt);
44460 out_dput:
44461@@ -2524,6 +2660,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
44462 error = PTR_ERR(new_dentry);
44463 if (IS_ERR(new_dentry))
44464 goto out_unlock;
44465+
44466+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
44467+ old_path.dentry->d_inode,
44468+ old_path.dentry->d_inode->i_mode, to)) {
44469+ error = -EACCES;
44470+ goto out_dput;
44471+ }
44472+
44473+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
44474+ old_path.dentry, old_path.mnt, to)) {
44475+ error = -EACCES;
44476+ goto out_dput;
44477+ }
44478+
44479 error = mnt_want_write(nd.path.mnt);
44480 if (error)
44481 goto out_dput;
44482@@ -2531,6 +2681,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
44483 if (error)
44484 goto out_drop_write;
44485 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
44486+ if (!error)
44487+ gr_handle_create(new_dentry, nd.path.mnt);
44488 out_drop_write:
44489 mnt_drop_write(nd.path.mnt);
44490 out_dput:
44491@@ -2708,6 +2860,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
44492 char *to;
44493 int error;
44494
44495+ pax_track_stack();
44496+
44497 error = user_path_parent(olddfd, oldname, &oldnd, &from);
44498 if (error)
44499 goto exit;
44500@@ -2764,6 +2918,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
44501 if (new_dentry == trap)
44502 goto exit5;
44503
44504+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
44505+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
44506+ to);
44507+ if (error)
44508+ goto exit5;
44509+
44510 error = mnt_want_write(oldnd.path.mnt);
44511 if (error)
44512 goto exit5;
44513@@ -2773,6 +2933,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
44514 goto exit6;
44515 error = vfs_rename(old_dir->d_inode, old_dentry,
44516 new_dir->d_inode, new_dentry);
44517+ if (!error)
44518+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
44519+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
44520 exit6:
44521 mnt_drop_write(oldnd.path.mnt);
44522 exit5:
44523@@ -2798,6 +2961,8 @@ SYSCALL_DEFINE2(rename, const char __use
44524
44525 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
44526 {
44527+ char tmpbuf[64];
44528+ const char *newlink;
44529 int len;
44530
44531 len = PTR_ERR(link);
44532@@ -2807,7 +2972,14 @@ int vfs_readlink(struct dentry *dentry,
44533 len = strlen(link);
44534 if (len > (unsigned) buflen)
44535 len = buflen;
44536- if (copy_to_user(buffer, link, len))
44537+
44538+ if (len < sizeof(tmpbuf)) {
44539+ memcpy(tmpbuf, link, len);
44540+ newlink = tmpbuf;
44541+ } else
44542+ newlink = link;
44543+
44544+ if (copy_to_user(buffer, newlink, len))
44545 len = -EFAULT;
44546 out:
44547 return len;
44548diff -urNp linux-2.6.32.44/fs/namespace.c linux-2.6.32.44/fs/namespace.c
44549--- linux-2.6.32.44/fs/namespace.c 2011-03-27 14:31:47.000000000 -0400
44550+++ linux-2.6.32.44/fs/namespace.c 2011-04-17 15:56:46.000000000 -0400
44551@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mn
44552 if (!(sb->s_flags & MS_RDONLY))
44553 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
44554 up_write(&sb->s_umount);
44555+
44556+ gr_log_remount(mnt->mnt_devname, retval);
44557+
44558 return retval;
44559 }
44560
44561@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mn
44562 security_sb_umount_busy(mnt);
44563 up_write(&namespace_sem);
44564 release_mounts(&umount_list);
44565+
44566+ gr_log_unmount(mnt->mnt_devname, retval);
44567+
44568 return retval;
44569 }
44570
44571@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_
44572 if (retval)
44573 goto dput_out;
44574
44575+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
44576+ retval = -EPERM;
44577+ goto dput_out;
44578+ }
44579+
44580+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
44581+ retval = -EPERM;
44582+ goto dput_out;
44583+ }
44584+
44585 if (flags & MS_REMOUNT)
44586 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
44587 data_page);
44588@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_
44589 dev_name, data_page);
44590 dput_out:
44591 path_put(&path);
44592+
44593+ gr_log_mount(dev_name, dir_name, retval);
44594+
44595 return retval;
44596 }
44597
44598@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char _
44599 goto out1;
44600 }
44601
44602+ if (gr_handle_chroot_pivot()) {
44603+ error = -EPERM;
44604+ path_put(&old);
44605+ goto out1;
44606+ }
44607+
44608 read_lock(&current->fs->lock);
44609 root = current->fs->root;
44610 path_get(&current->fs->root);
44611diff -urNp linux-2.6.32.44/fs/ncpfs/dir.c linux-2.6.32.44/fs/ncpfs/dir.c
44612--- linux-2.6.32.44/fs/ncpfs/dir.c 2011-03-27 14:31:47.000000000 -0400
44613+++ linux-2.6.32.44/fs/ncpfs/dir.c 2011-05-16 21:46:57.000000000 -0400
44614@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *den
44615 int res, val = 0, len;
44616 __u8 __name[NCP_MAXPATHLEN + 1];
44617
44618+ pax_track_stack();
44619+
44620 parent = dget_parent(dentry);
44621 dir = parent->d_inode;
44622
44623@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct
44624 int error, res, len;
44625 __u8 __name[NCP_MAXPATHLEN + 1];
44626
44627+ pax_track_stack();
44628+
44629 lock_kernel();
44630 error = -EIO;
44631 if (!ncp_conn_valid(server))
44632@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, st
44633 int error, result, len;
44634 int opmode;
44635 __u8 __name[NCP_MAXPATHLEN + 1];
44636-
44637+
44638 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
44639 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
44640
44641+ pax_track_stack();
44642+
44643 error = -EIO;
44644 lock_kernel();
44645 if (!ncp_conn_valid(server))
44646@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir,
44647 int error, len;
44648 __u8 __name[NCP_MAXPATHLEN + 1];
44649
44650+ pax_track_stack();
44651+
44652 DPRINTK("ncp_mkdir: making %s/%s\n",
44653 dentry->d_parent->d_name.name, dentry->d_name.name);
44654
44655@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir,
44656 if (!ncp_conn_valid(server))
44657 goto out;
44658
44659+ pax_track_stack();
44660+
44661 ncp_age_dentry(server, dentry);
44662 len = sizeof(__name);
44663 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
44664@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_
44665 int old_len, new_len;
44666 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
44667
44668+ pax_track_stack();
44669+
44670 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
44671 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
44672 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
44673diff -urNp linux-2.6.32.44/fs/ncpfs/inode.c linux-2.6.32.44/fs/ncpfs/inode.c
44674--- linux-2.6.32.44/fs/ncpfs/inode.c 2011-03-27 14:31:47.000000000 -0400
44675+++ linux-2.6.32.44/fs/ncpfs/inode.c 2011-05-16 21:46:57.000000000 -0400
44676@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_b
44677 #endif
44678 struct ncp_entry_info finfo;
44679
44680+ pax_track_stack();
44681+
44682 data.wdog_pid = NULL;
44683 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
44684 if (!server)
44685diff -urNp linux-2.6.32.44/fs/nfs/inode.c linux-2.6.32.44/fs/nfs/inode.c
44686--- linux-2.6.32.44/fs/nfs/inode.c 2011-05-10 22:12:01.000000000 -0400
44687+++ linux-2.6.32.44/fs/nfs/inode.c 2011-07-06 19:53:33.000000000 -0400
44688@@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct
44689 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
44690 nfsi->attrtimeo_timestamp = jiffies;
44691
44692- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
44693+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
44694 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
44695 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
44696 else
44697@@ -973,16 +973,16 @@ static int nfs_size_need_update(const st
44698 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
44699 }
44700
44701-static atomic_long_t nfs_attr_generation_counter;
44702+static atomic_long_unchecked_t nfs_attr_generation_counter;
44703
44704 static unsigned long nfs_read_attr_generation_counter(void)
44705 {
44706- return atomic_long_read(&nfs_attr_generation_counter);
44707+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
44708 }
44709
44710 unsigned long nfs_inc_attr_generation_counter(void)
44711 {
44712- return atomic_long_inc_return(&nfs_attr_generation_counter);
44713+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
44714 }
44715
44716 void nfs_fattr_init(struct nfs_fattr *fattr)
44717diff -urNp linux-2.6.32.44/fs/nfsd/lockd.c linux-2.6.32.44/fs/nfsd/lockd.c
44718--- linux-2.6.32.44/fs/nfsd/lockd.c 2011-04-17 17:00:52.000000000 -0400
44719+++ linux-2.6.32.44/fs/nfsd/lockd.c 2011-04-17 17:03:15.000000000 -0400
44720@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
44721 fput(filp);
44722 }
44723
44724-static struct nlmsvc_binding nfsd_nlm_ops = {
44725+static const struct nlmsvc_binding nfsd_nlm_ops = {
44726 .fopen = nlm_fopen, /* open file for locking */
44727 .fclose = nlm_fclose, /* close file */
44728 };
44729diff -urNp linux-2.6.32.44/fs/nfsd/nfs4state.c linux-2.6.32.44/fs/nfsd/nfs4state.c
44730--- linux-2.6.32.44/fs/nfsd/nfs4state.c 2011-03-27 14:31:47.000000000 -0400
44731+++ linux-2.6.32.44/fs/nfsd/nfs4state.c 2011-05-16 21:46:57.000000000 -0400
44732@@ -3457,6 +3457,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
44733 unsigned int cmd;
44734 int err;
44735
44736+ pax_track_stack();
44737+
44738 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
44739 (long long) lock->lk_offset,
44740 (long long) lock->lk_length);
44741diff -urNp linux-2.6.32.44/fs/nfsd/nfs4xdr.c linux-2.6.32.44/fs/nfsd/nfs4xdr.c
44742--- linux-2.6.32.44/fs/nfsd/nfs4xdr.c 2011-03-27 14:31:47.000000000 -0400
44743+++ linux-2.6.32.44/fs/nfsd/nfs4xdr.c 2011-05-16 21:46:57.000000000 -0400
44744@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
44745 struct nfsd4_compoundres *resp = rqstp->rq_resp;
44746 u32 minorversion = resp->cstate.minorversion;
44747
44748+ pax_track_stack();
44749+
44750 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
44751 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
44752 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
44753diff -urNp linux-2.6.32.44/fs/nfsd/vfs.c linux-2.6.32.44/fs/nfsd/vfs.c
44754--- linux-2.6.32.44/fs/nfsd/vfs.c 2011-05-10 22:12:01.000000000 -0400
44755+++ linux-2.6.32.44/fs/nfsd/vfs.c 2011-05-10 22:12:33.000000000 -0400
44756@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
44757 } else {
44758 oldfs = get_fs();
44759 set_fs(KERNEL_DS);
44760- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
44761+ host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
44762 set_fs(oldfs);
44763 }
44764
44765@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
44766
44767 /* Write the data. */
44768 oldfs = get_fs(); set_fs(KERNEL_DS);
44769- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
44770+ host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
44771 set_fs(oldfs);
44772 if (host_err < 0)
44773 goto out_nfserr;
44774@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
44775 */
44776
44777 oldfs = get_fs(); set_fs(KERNEL_DS);
44778- host_err = inode->i_op->readlink(dentry, buf, *lenp);
44779+ host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
44780 set_fs(oldfs);
44781
44782 if (host_err < 0)
44783diff -urNp linux-2.6.32.44/fs/nilfs2/ioctl.c linux-2.6.32.44/fs/nilfs2/ioctl.c
44784--- linux-2.6.32.44/fs/nilfs2/ioctl.c 2011-03-27 14:31:47.000000000 -0400
44785+++ linux-2.6.32.44/fs/nilfs2/ioctl.c 2011-05-04 17:56:28.000000000 -0400
44786@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(st
44787 unsigned int cmd, void __user *argp)
44788 {
44789 struct nilfs_argv argv[5];
44790- const static size_t argsz[5] = {
44791+ static const size_t argsz[5] = {
44792 sizeof(struct nilfs_vdesc),
44793 sizeof(struct nilfs_period),
44794 sizeof(__u64),
44795diff -urNp linux-2.6.32.44/fs/notify/dnotify/dnotify.c linux-2.6.32.44/fs/notify/dnotify/dnotify.c
44796--- linux-2.6.32.44/fs/notify/dnotify/dnotify.c 2011-03-27 14:31:47.000000000 -0400
44797+++ linux-2.6.32.44/fs/notify/dnotify/dnotify.c 2011-04-17 15:56:46.000000000 -0400
44798@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsn
44799 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
44800 }
44801
44802-static struct fsnotify_ops dnotify_fsnotify_ops = {
44803+static const struct fsnotify_ops dnotify_fsnotify_ops = {
44804 .handle_event = dnotify_handle_event,
44805 .should_send_event = dnotify_should_send_event,
44806 .free_group_priv = NULL,
44807diff -urNp linux-2.6.32.44/fs/notify/notification.c linux-2.6.32.44/fs/notify/notification.c
44808--- linux-2.6.32.44/fs/notify/notification.c 2011-03-27 14:31:47.000000000 -0400
44809+++ linux-2.6.32.44/fs/notify/notification.c 2011-05-04 17:56:28.000000000 -0400
44810@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
44811 * get set to 0 so it will never get 'freed'
44812 */
44813 static struct fsnotify_event q_overflow_event;
44814-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44815+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44816
44817 /**
44818 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
44819@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
44820 */
44821 u32 fsnotify_get_cookie(void)
44822 {
44823- return atomic_inc_return(&fsnotify_sync_cookie);
44824+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
44825 }
44826 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
44827
44828diff -urNp linux-2.6.32.44/fs/ntfs/dir.c linux-2.6.32.44/fs/ntfs/dir.c
44829--- linux-2.6.32.44/fs/ntfs/dir.c 2011-03-27 14:31:47.000000000 -0400
44830+++ linux-2.6.32.44/fs/ntfs/dir.c 2011-04-17 15:56:46.000000000 -0400
44831@@ -1328,7 +1328,7 @@ find_next_index_buffer:
44832 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
44833 ~(s64)(ndir->itype.index.block_size - 1)));
44834 /* Bounds checks. */
44835- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44836+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44837 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
44838 "inode 0x%lx or driver bug.", vdir->i_ino);
44839 goto err_out;
44840diff -urNp linux-2.6.32.44/fs/ntfs/file.c linux-2.6.32.44/fs/ntfs/file.c
44841--- linux-2.6.32.44/fs/ntfs/file.c 2011-03-27 14:31:47.000000000 -0400
44842+++ linux-2.6.32.44/fs/ntfs/file.c 2011-04-17 15:56:46.000000000 -0400
44843@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_
44844 #endif /* NTFS_RW */
44845 };
44846
44847-const struct file_operations ntfs_empty_file_ops = {};
44848+const struct file_operations ntfs_empty_file_ops __read_only;
44849
44850-const struct inode_operations ntfs_empty_inode_ops = {};
44851+const struct inode_operations ntfs_empty_inode_ops __read_only;
44852diff -urNp linux-2.6.32.44/fs/ocfs2/cluster/masklog.c linux-2.6.32.44/fs/ocfs2/cluster/masklog.c
44853--- linux-2.6.32.44/fs/ocfs2/cluster/masklog.c 2011-03-27 14:31:47.000000000 -0400
44854+++ linux-2.6.32.44/fs/ocfs2/cluster/masklog.c 2011-04-17 15:56:46.000000000 -0400
44855@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject
44856 return mlog_mask_store(mlog_attr->mask, buf, count);
44857 }
44858
44859-static struct sysfs_ops mlog_attr_ops = {
44860+static const struct sysfs_ops mlog_attr_ops = {
44861 .show = mlog_show,
44862 .store = mlog_store,
44863 };
44864diff -urNp linux-2.6.32.44/fs/ocfs2/localalloc.c linux-2.6.32.44/fs/ocfs2/localalloc.c
44865--- linux-2.6.32.44/fs/ocfs2/localalloc.c 2011-03-27 14:31:47.000000000 -0400
44866+++ linux-2.6.32.44/fs/ocfs2/localalloc.c 2011-04-17 15:56:46.000000000 -0400
44867@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_windo
44868 goto bail;
44869 }
44870
44871- atomic_inc(&osb->alloc_stats.moves);
44872+ atomic_inc_unchecked(&osb->alloc_stats.moves);
44873
44874 status = 0;
44875 bail:
44876diff -urNp linux-2.6.32.44/fs/ocfs2/namei.c linux-2.6.32.44/fs/ocfs2/namei.c
44877--- linux-2.6.32.44/fs/ocfs2/namei.c 2011-03-27 14:31:47.000000000 -0400
44878+++ linux-2.6.32.44/fs/ocfs2/namei.c 2011-05-16 21:46:57.000000000 -0400
44879@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *ol
44880 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
44881 struct ocfs2_dir_lookup_result target_insert = { NULL, };
44882
44883+ pax_track_stack();
44884+
44885 /* At some point it might be nice to break this function up a
44886 * bit. */
44887
44888diff -urNp linux-2.6.32.44/fs/ocfs2/ocfs2.h linux-2.6.32.44/fs/ocfs2/ocfs2.h
44889--- linux-2.6.32.44/fs/ocfs2/ocfs2.h 2011-03-27 14:31:47.000000000 -0400
44890+++ linux-2.6.32.44/fs/ocfs2/ocfs2.h 2011-04-17 15:56:46.000000000 -0400
44891@@ -217,11 +217,11 @@ enum ocfs2_vol_state
44892
44893 struct ocfs2_alloc_stats
44894 {
44895- atomic_t moves;
44896- atomic_t local_data;
44897- atomic_t bitmap_data;
44898- atomic_t bg_allocs;
44899- atomic_t bg_extends;
44900+ atomic_unchecked_t moves;
44901+ atomic_unchecked_t local_data;
44902+ atomic_unchecked_t bitmap_data;
44903+ atomic_unchecked_t bg_allocs;
44904+ atomic_unchecked_t bg_extends;
44905 };
44906
44907 enum ocfs2_local_alloc_state
44908diff -urNp linux-2.6.32.44/fs/ocfs2/suballoc.c linux-2.6.32.44/fs/ocfs2/suballoc.c
44909--- linux-2.6.32.44/fs/ocfs2/suballoc.c 2011-03-27 14:31:47.000000000 -0400
44910+++ linux-2.6.32.44/fs/ocfs2/suballoc.c 2011-04-17 15:56:46.000000000 -0400
44911@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(s
44912 mlog_errno(status);
44913 goto bail;
44914 }
44915- atomic_inc(&osb->alloc_stats.bg_extends);
44916+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
44917
44918 /* You should never ask for this much metadata */
44919 BUG_ON(bits_wanted >
44920@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_su
44921 mlog_errno(status);
44922 goto bail;
44923 }
44924- atomic_inc(&osb->alloc_stats.bg_allocs);
44925+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
44926
44927 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
44928 ac->ac_bits_given += (*num_bits);
44929@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_s
44930 mlog_errno(status);
44931 goto bail;
44932 }
44933- atomic_inc(&osb->alloc_stats.bg_allocs);
44934+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
44935
44936 BUG_ON(num_bits != 1);
44937
44938@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
44939 cluster_start,
44940 num_clusters);
44941 if (!status)
44942- atomic_inc(&osb->alloc_stats.local_data);
44943+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
44944 } else {
44945 if (min_clusters > (osb->bitmap_cpg - 1)) {
44946 /* The only paths asking for contiguousness
44947@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
44948 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
44949 bg_blkno,
44950 bg_bit_off);
44951- atomic_inc(&osb->alloc_stats.bitmap_data);
44952+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
44953 }
44954 }
44955 if (status < 0) {
44956diff -urNp linux-2.6.32.44/fs/ocfs2/super.c linux-2.6.32.44/fs/ocfs2/super.c
44957--- linux-2.6.32.44/fs/ocfs2/super.c 2011-03-27 14:31:47.000000000 -0400
44958+++ linux-2.6.32.44/fs/ocfs2/super.c 2011-04-17 15:56:46.000000000 -0400
44959@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
44960 "%10s => GlobalAllocs: %d LocalAllocs: %d "
44961 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
44962 "Stats",
44963- atomic_read(&osb->alloc_stats.bitmap_data),
44964- atomic_read(&osb->alloc_stats.local_data),
44965- atomic_read(&osb->alloc_stats.bg_allocs),
44966- atomic_read(&osb->alloc_stats.moves),
44967- atomic_read(&osb->alloc_stats.bg_extends));
44968+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
44969+ atomic_read_unchecked(&osb->alloc_stats.local_data),
44970+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
44971+ atomic_read_unchecked(&osb->alloc_stats.moves),
44972+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
44973
44974 out += snprintf(buf + out, len - out,
44975 "%10s => State: %u Descriptor: %llu Size: %u bits "
44976@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct
44977 spin_lock_init(&osb->osb_xattr_lock);
44978 ocfs2_init_inode_steal_slot(osb);
44979
44980- atomic_set(&osb->alloc_stats.moves, 0);
44981- atomic_set(&osb->alloc_stats.local_data, 0);
44982- atomic_set(&osb->alloc_stats.bitmap_data, 0);
44983- atomic_set(&osb->alloc_stats.bg_allocs, 0);
44984- atomic_set(&osb->alloc_stats.bg_extends, 0);
44985+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
44986+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
44987+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
44988+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
44989+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
44990
44991 /* Copy the blockcheck stats from the superblock probe */
44992 osb->osb_ecc_stats = *stats;
44993diff -urNp linux-2.6.32.44/fs/open.c linux-2.6.32.44/fs/open.c
44994--- linux-2.6.32.44/fs/open.c 2011-03-27 14:31:47.000000000 -0400
44995+++ linux-2.6.32.44/fs/open.c 2011-04-17 15:56:46.000000000 -0400
44996@@ -275,6 +275,10 @@ static long do_sys_truncate(const char _
44997 error = locks_verify_truncate(inode, NULL, length);
44998 if (!error)
44999 error = security_path_truncate(&path, length, 0);
45000+
45001+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
45002+ error = -EACCES;
45003+
45004 if (!error) {
45005 vfs_dq_init(inode);
45006 error = do_truncate(path.dentry, length, 0, NULL);
45007@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
45008 if (__mnt_is_readonly(path.mnt))
45009 res = -EROFS;
45010
45011+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
45012+ res = -EACCES;
45013+
45014 out_path_release:
45015 path_put(&path);
45016 out:
45017@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user
45018 if (error)
45019 goto dput_and_out;
45020
45021+ gr_log_chdir(path.dentry, path.mnt);
45022+
45023 set_fs_pwd(current->fs, &path);
45024
45025 dput_and_out:
45026@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
45027 goto out_putf;
45028
45029 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
45030+
45031+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
45032+ error = -EPERM;
45033+
45034+ if (!error)
45035+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
45036+
45037 if (!error)
45038 set_fs_pwd(current->fs, &file->f_path);
45039 out_putf:
45040@@ -588,7 +604,18 @@ SYSCALL_DEFINE1(chroot, const char __use
45041 if (!capable(CAP_SYS_CHROOT))
45042 goto dput_and_out;
45043
45044+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
45045+ goto dput_and_out;
45046+
45047+ if (gr_handle_chroot_caps(&path)) {
45048+ error = -ENOMEM;
45049+ goto dput_and_out;
45050+ }
45051+
45052 set_fs_root(current->fs, &path);
45053+
45054+ gr_handle_chroot_chdir(&path);
45055+
45056 error = 0;
45057 dput_and_out:
45058 path_put(&path);
45059@@ -616,12 +643,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
45060 err = mnt_want_write_file(file);
45061 if (err)
45062 goto out_putf;
45063+
45064 mutex_lock(&inode->i_mutex);
45065+
45066+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
45067+ err = -EACCES;
45068+ goto out_unlock;
45069+ }
45070+
45071 if (mode == (mode_t) -1)
45072 mode = inode->i_mode;
45073+
45074+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
45075+ err = -EPERM;
45076+ goto out_unlock;
45077+ }
45078+
45079 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
45080 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
45081 err = notify_change(dentry, &newattrs);
45082+
45083+out_unlock:
45084 mutex_unlock(&inode->i_mutex);
45085 mnt_drop_write(file->f_path.mnt);
45086 out_putf:
45087@@ -645,12 +687,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
45088 error = mnt_want_write(path.mnt);
45089 if (error)
45090 goto dput_and_out;
45091+
45092 mutex_lock(&inode->i_mutex);
45093+
45094+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
45095+ error = -EACCES;
45096+ goto out_unlock;
45097+ }
45098+
45099 if (mode == (mode_t) -1)
45100 mode = inode->i_mode;
45101+
45102+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
45103+ error = -EACCES;
45104+ goto out_unlock;
45105+ }
45106+
45107 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
45108 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
45109 error = notify_change(path.dentry, &newattrs);
45110+
45111+out_unlock:
45112 mutex_unlock(&inode->i_mutex);
45113 mnt_drop_write(path.mnt);
45114 dput_and_out:
45115@@ -664,12 +721,15 @@ SYSCALL_DEFINE2(chmod, const char __user
45116 return sys_fchmodat(AT_FDCWD, filename, mode);
45117 }
45118
45119-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
45120+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
45121 {
45122 struct inode *inode = dentry->d_inode;
45123 int error;
45124 struct iattr newattrs;
45125
45126+ if (!gr_acl_handle_chown(dentry, mnt))
45127+ return -EACCES;
45128+
45129 newattrs.ia_valid = ATTR_CTIME;
45130 if (user != (uid_t) -1) {
45131 newattrs.ia_valid |= ATTR_UID;
45132@@ -700,7 +760,7 @@ SYSCALL_DEFINE3(chown, const char __user
45133 error = mnt_want_write(path.mnt);
45134 if (error)
45135 goto out_release;
45136- error = chown_common(path.dentry, user, group);
45137+ error = chown_common(path.dentry, user, group, path.mnt);
45138 mnt_drop_write(path.mnt);
45139 out_release:
45140 path_put(&path);
45141@@ -725,7 +785,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
45142 error = mnt_want_write(path.mnt);
45143 if (error)
45144 goto out_release;
45145- error = chown_common(path.dentry, user, group);
45146+ error = chown_common(path.dentry, user, group, path.mnt);
45147 mnt_drop_write(path.mnt);
45148 out_release:
45149 path_put(&path);
45150@@ -744,7 +804,7 @@ SYSCALL_DEFINE3(lchown, const char __use
45151 error = mnt_want_write(path.mnt);
45152 if (error)
45153 goto out_release;
45154- error = chown_common(path.dentry, user, group);
45155+ error = chown_common(path.dentry, user, group, path.mnt);
45156 mnt_drop_write(path.mnt);
45157 out_release:
45158 path_put(&path);
45159@@ -767,7 +827,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd
45160 goto out_fput;
45161 dentry = file->f_path.dentry;
45162 audit_inode(NULL, dentry);
45163- error = chown_common(dentry, user, group);
45164+ error = chown_common(dentry, user, group, file->f_path.mnt);
45165 mnt_drop_write(file->f_path.mnt);
45166 out_fput:
45167 fput(file);
45168@@ -1036,7 +1096,10 @@ long do_sys_open(int dfd, const char __u
45169 if (!IS_ERR(tmp)) {
45170 fd = get_unused_fd_flags(flags);
45171 if (fd >= 0) {
45172- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
45173+ struct file *f;
45174+ /* don't allow to be set by userland */
45175+ flags &= ~FMODE_GREXEC;
45176+ f = do_filp_open(dfd, tmp, flags, mode, 0);
45177 if (IS_ERR(f)) {
45178 put_unused_fd(fd);
45179 fd = PTR_ERR(f);
45180diff -urNp linux-2.6.32.44/fs/partitions/ldm.c linux-2.6.32.44/fs/partitions/ldm.c
45181--- linux-2.6.32.44/fs/partitions/ldm.c 2011-06-25 12:55:34.000000000 -0400
45182+++ linux-2.6.32.44/fs/partitions/ldm.c 2011-06-25 12:56:37.000000000 -0400
45183@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
45184 ldm_error ("A VBLK claims to have %d parts.", num);
45185 return false;
45186 }
45187+
45188 if (rec >= num) {
45189 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
45190 return false;
45191@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
45192 goto found;
45193 }
45194
45195- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
45196+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
45197 if (!f) {
45198 ldm_crit ("Out of memory.");
45199 return false;
45200diff -urNp linux-2.6.32.44/fs/partitions/mac.c linux-2.6.32.44/fs/partitions/mac.c
45201--- linux-2.6.32.44/fs/partitions/mac.c 2011-03-27 14:31:47.000000000 -0400
45202+++ linux-2.6.32.44/fs/partitions/mac.c 2011-04-17 15:56:46.000000000 -0400
45203@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitio
45204 return 0; /* not a MacOS disk */
45205 }
45206 blocks_in_map = be32_to_cpu(part->map_count);
45207+ printk(" [mac]");
45208 if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
45209 put_dev_sector(sect);
45210 return 0;
45211 }
45212- printk(" [mac]");
45213 for (slot = 1; slot <= blocks_in_map; ++slot) {
45214 int pos = slot * secsize;
45215 put_dev_sector(sect);
45216diff -urNp linux-2.6.32.44/fs/pipe.c linux-2.6.32.44/fs/pipe.c
45217--- linux-2.6.32.44/fs/pipe.c 2011-03-27 14:31:47.000000000 -0400
45218+++ linux-2.6.32.44/fs/pipe.c 2011-04-23 13:37:17.000000000 -0400
45219@@ -401,9 +401,9 @@ redo:
45220 }
45221 if (bufs) /* More to do? */
45222 continue;
45223- if (!pipe->writers)
45224+ if (!atomic_read(&pipe->writers))
45225 break;
45226- if (!pipe->waiting_writers) {
45227+ if (!atomic_read(&pipe->waiting_writers)) {
45228 /* syscall merging: Usually we must not sleep
45229 * if O_NONBLOCK is set, or if we got some data.
45230 * But if a writer sleeps in kernel space, then
45231@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const str
45232 mutex_lock(&inode->i_mutex);
45233 pipe = inode->i_pipe;
45234
45235- if (!pipe->readers) {
45236+ if (!atomic_read(&pipe->readers)) {
45237 send_sig(SIGPIPE, current, 0);
45238 ret = -EPIPE;
45239 goto out;
45240@@ -511,7 +511,7 @@ redo1:
45241 for (;;) {
45242 int bufs;
45243
45244- if (!pipe->readers) {
45245+ if (!atomic_read(&pipe->readers)) {
45246 send_sig(SIGPIPE, current, 0);
45247 if (!ret)
45248 ret = -EPIPE;
45249@@ -597,9 +597,9 @@ redo2:
45250 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45251 do_wakeup = 0;
45252 }
45253- pipe->waiting_writers++;
45254+ atomic_inc(&pipe->waiting_writers);
45255 pipe_wait(pipe);
45256- pipe->waiting_writers--;
45257+ atomic_dec(&pipe->waiting_writers);
45258 }
45259 out:
45260 mutex_unlock(&inode->i_mutex);
45261@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table
45262 mask = 0;
45263 if (filp->f_mode & FMODE_READ) {
45264 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
45265- if (!pipe->writers && filp->f_version != pipe->w_counter)
45266+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
45267 mask |= POLLHUP;
45268 }
45269
45270@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table
45271 * Most Unices do not set POLLERR for FIFOs but on Linux they
45272 * behave exactly like pipes for poll().
45273 */
45274- if (!pipe->readers)
45275+ if (!atomic_read(&pipe->readers))
45276 mask |= POLLERR;
45277 }
45278
45279@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int de
45280
45281 mutex_lock(&inode->i_mutex);
45282 pipe = inode->i_pipe;
45283- pipe->readers -= decr;
45284- pipe->writers -= decw;
45285+ atomic_sub(decr, &pipe->readers);
45286+ atomic_sub(decw, &pipe->writers);
45287
45288- if (!pipe->readers && !pipe->writers) {
45289+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
45290 free_pipe_info(inode);
45291 } else {
45292 wake_up_interruptible_sync(&pipe->wait);
45293@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, stru
45294
45295 if (inode->i_pipe) {
45296 ret = 0;
45297- inode->i_pipe->readers++;
45298+ atomic_inc(&inode->i_pipe->readers);
45299 }
45300
45301 mutex_unlock(&inode->i_mutex);
45302@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, str
45303
45304 if (inode->i_pipe) {
45305 ret = 0;
45306- inode->i_pipe->writers++;
45307+ atomic_inc(&inode->i_pipe->writers);
45308 }
45309
45310 mutex_unlock(&inode->i_mutex);
45311@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, stru
45312 if (inode->i_pipe) {
45313 ret = 0;
45314 if (filp->f_mode & FMODE_READ)
45315- inode->i_pipe->readers++;
45316+ atomic_inc(&inode->i_pipe->readers);
45317 if (filp->f_mode & FMODE_WRITE)
45318- inode->i_pipe->writers++;
45319+ atomic_inc(&inode->i_pipe->writers);
45320 }
45321
45322 mutex_unlock(&inode->i_mutex);
45323@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
45324 inode->i_pipe = NULL;
45325 }
45326
45327-static struct vfsmount *pipe_mnt __read_mostly;
45328+struct vfsmount *pipe_mnt __read_mostly;
45329 static int pipefs_delete_dentry(struct dentry *dentry)
45330 {
45331 /*
45332@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(voi
45333 goto fail_iput;
45334 inode->i_pipe = pipe;
45335
45336- pipe->readers = pipe->writers = 1;
45337+ atomic_set(&pipe->readers, 1);
45338+ atomic_set(&pipe->writers, 1);
45339 inode->i_fop = &rdwr_pipefifo_fops;
45340
45341 /*
45342diff -urNp linux-2.6.32.44/fs/proc/array.c linux-2.6.32.44/fs/proc/array.c
45343--- linux-2.6.32.44/fs/proc/array.c 2011-03-27 14:31:47.000000000 -0400
45344+++ linux-2.6.32.44/fs/proc/array.c 2011-05-16 21:46:57.000000000 -0400
45345@@ -60,6 +60,7 @@
45346 #include <linux/tty.h>
45347 #include <linux/string.h>
45348 #include <linux/mman.h>
45349+#include <linux/grsecurity.h>
45350 #include <linux/proc_fs.h>
45351 #include <linux/ioport.h>
45352 #include <linux/uaccess.h>
45353@@ -321,6 +322,21 @@ static inline void task_context_switch_c
45354 p->nivcsw);
45355 }
45356
45357+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45358+static inline void task_pax(struct seq_file *m, struct task_struct *p)
45359+{
45360+ if (p->mm)
45361+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
45362+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
45363+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
45364+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
45365+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
45366+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
45367+ else
45368+ seq_printf(m, "PaX:\t-----\n");
45369+}
45370+#endif
45371+
45372 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45373 struct pid *pid, struct task_struct *task)
45374 {
45375@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m,
45376 task_cap(m, task);
45377 cpuset_task_status_allowed(m, task);
45378 task_context_switch_counts(m, task);
45379+
45380+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45381+ task_pax(m, task);
45382+#endif
45383+
45384+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
45385+ task_grsec_rbac(m, task);
45386+#endif
45387+
45388 return 0;
45389 }
45390
45391+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45392+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45393+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
45394+ _mm->pax_flags & MF_PAX_SEGMEXEC))
45395+#endif
45396+
45397 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45398 struct pid *pid, struct task_struct *task, int whole)
45399 {
45400@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file
45401 cputime_t cutime, cstime, utime, stime;
45402 cputime_t cgtime, gtime;
45403 unsigned long rsslim = 0;
45404- char tcomm[sizeof(task->comm)];
45405+ char tcomm[sizeof(task->comm)] = { 0 };
45406 unsigned long flags;
45407
45408+ pax_track_stack();
45409+
45410 state = *get_task_state(task);
45411 vsize = eip = esp = 0;
45412 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
45413@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file
45414 gtime = task_gtime(task);
45415 }
45416
45417+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45418+ if (PAX_RAND_FLAGS(mm)) {
45419+ eip = 0;
45420+ esp = 0;
45421+ wchan = 0;
45422+ }
45423+#endif
45424+#ifdef CONFIG_GRKERNSEC_HIDESYM
45425+ wchan = 0;
45426+ eip =0;
45427+ esp =0;
45428+#endif
45429+
45430 /* scale priority and nice values from timeslices to -20..20 */
45431 /* to make it look like a "normal" Unix priority/nice value */
45432 priority = task_prio(task);
45433@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file
45434 vsize,
45435 mm ? get_mm_rss(mm) : 0,
45436 rsslim,
45437+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45438+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
45439+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
45440+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
45441+#else
45442 mm ? (permitted ? mm->start_code : 1) : 0,
45443 mm ? (permitted ? mm->end_code : 1) : 0,
45444 (permitted && mm) ? mm->start_stack : 0,
45445+#endif
45446 esp,
45447 eip,
45448 /* The signal information here is obsolete.
45449@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, s
45450
45451 return 0;
45452 }
45453+
45454+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45455+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
45456+{
45457+ u32 curr_ip = 0;
45458+ unsigned long flags;
45459+
45460+ if (lock_task_sighand(task, &flags)) {
45461+ curr_ip = task->signal->curr_ip;
45462+ unlock_task_sighand(task, &flags);
45463+ }
45464+
45465+ return sprintf(buffer, "%pI4\n", &curr_ip);
45466+}
45467+#endif
45468diff -urNp linux-2.6.32.44/fs/proc/base.c linux-2.6.32.44/fs/proc/base.c
45469--- linux-2.6.32.44/fs/proc/base.c 2011-08-09 18:35:30.000000000 -0400
45470+++ linux-2.6.32.44/fs/proc/base.c 2011-08-09 18:34:33.000000000 -0400
45471@@ -102,6 +102,22 @@ struct pid_entry {
45472 union proc_op op;
45473 };
45474
45475+struct getdents_callback {
45476+ struct linux_dirent __user * current_dir;
45477+ struct linux_dirent __user * previous;
45478+ struct file * file;
45479+ int count;
45480+ int error;
45481+};
45482+
45483+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
45484+ loff_t offset, u64 ino, unsigned int d_type)
45485+{
45486+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
45487+ buf->error = -EINVAL;
45488+ return 0;
45489+}
45490+
45491 #define NOD(NAME, MODE, IOP, FOP, OP) { \
45492 .name = (NAME), \
45493 .len = sizeof(NAME) - 1, \
45494@@ -213,6 +229,9 @@ static int check_mem_permission(struct t
45495 if (task == current)
45496 return 0;
45497
45498+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
45499+ return -EPERM;
45500+
45501 /*
45502 * If current is actively ptrace'ing, and would also be
45503 * permitted to freshly attach with ptrace now, permit it.
45504@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_
45505 if (!mm->arg_end)
45506 goto out_mm; /* Shh! No looking before we're done */
45507
45508+ if (gr_acl_handle_procpidmem(task))
45509+ goto out_mm;
45510+
45511 len = mm->arg_end - mm->arg_start;
45512
45513 if (len > PAGE_SIZE)
45514@@ -287,12 +309,28 @@ out:
45515 return res;
45516 }
45517
45518+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45519+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45520+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
45521+ _mm->pax_flags & MF_PAX_SEGMEXEC))
45522+#endif
45523+
45524 static int proc_pid_auxv(struct task_struct *task, char *buffer)
45525 {
45526 int res = 0;
45527 struct mm_struct *mm = get_task_mm(task);
45528 if (mm) {
45529 unsigned int nwords = 0;
45530+
45531+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45532+ /* allow if we're currently ptracing this task */
45533+ if (PAX_RAND_FLAGS(mm) &&
45534+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
45535+ mmput(mm);
45536+ return res;
45537+ }
45538+#endif
45539+
45540 do {
45541 nwords += 2;
45542 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
45543@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_str
45544 }
45545
45546
45547-#ifdef CONFIG_KALLSYMS
45548+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45549 /*
45550 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
45551 * Returns the resolved symbol. If that fails, simply return the address.
45552@@ -328,7 +366,7 @@ static int proc_pid_wchan(struct task_st
45553 }
45554 #endif /* CONFIG_KALLSYMS */
45555
45556-#ifdef CONFIG_STACKTRACE
45557+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45558
45559 #define MAX_STACK_TRACE_DEPTH 64
45560
45561@@ -522,7 +560,7 @@ static int proc_pid_limits(struct task_s
45562 return count;
45563 }
45564
45565-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45566+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45567 static int proc_pid_syscall(struct task_struct *task, char *buffer)
45568 {
45569 long nr;
45570@@ -547,7 +585,7 @@ static int proc_pid_syscall(struct task_
45571 /************************************************************************/
45572
45573 /* permission checks */
45574-static int proc_fd_access_allowed(struct inode *inode)
45575+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
45576 {
45577 struct task_struct *task;
45578 int allowed = 0;
45579@@ -557,7 +595,10 @@ static int proc_fd_access_allowed(struct
45580 */
45581 task = get_proc_task(inode);
45582 if (task) {
45583- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45584+ if (log)
45585+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
45586+ else
45587+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45588 put_task_struct(task);
45589 }
45590 return allowed;
45591@@ -936,6 +977,9 @@ static ssize_t environ_read(struct file
45592 if (!task)
45593 goto out_no_task;
45594
45595+ if (gr_acl_handle_procpidmem(task))
45596+ goto out;
45597+
45598 if (!ptrace_may_access(task, PTRACE_MODE_READ))
45599 goto out;
45600
45601@@ -1350,7 +1394,7 @@ static void *proc_pid_follow_link(struct
45602 path_put(&nd->path);
45603
45604 /* Are we allowed to snoop on the tasks file descriptors? */
45605- if (!proc_fd_access_allowed(inode))
45606+ if (!proc_fd_access_allowed(inode,0))
45607 goto out;
45608
45609 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
45610@@ -1390,8 +1434,18 @@ static int proc_pid_readlink(struct dent
45611 struct path path;
45612
45613 /* Are we allowed to snoop on the tasks file descriptors? */
45614- if (!proc_fd_access_allowed(inode))
45615- goto out;
45616+ /* logging this is needed for learning on chromium to work properly,
45617+ but we don't want to flood the logs from 'ps' which does a readlink
45618+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
45619+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
45620+ */
45621+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
45622+ if (!proc_fd_access_allowed(inode,0))
45623+ goto out;
45624+ } else {
45625+ if (!proc_fd_access_allowed(inode,1))
45626+ goto out;
45627+ }
45628
45629 error = PROC_I(inode)->op.proc_get_link(inode, &path);
45630 if (error)
45631@@ -1456,7 +1510,11 @@ static struct inode *proc_pid_make_inode
45632 rcu_read_lock();
45633 cred = __task_cred(task);
45634 inode->i_uid = cred->euid;
45635+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45636+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45637+#else
45638 inode->i_gid = cred->egid;
45639+#endif
45640 rcu_read_unlock();
45641 }
45642 security_task_to_inode(task, inode);
45643@@ -1474,6 +1532,9 @@ static int pid_getattr(struct vfsmount *
45644 struct inode *inode = dentry->d_inode;
45645 struct task_struct *task;
45646 const struct cred *cred;
45647+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45648+ const struct cred *tmpcred = current_cred();
45649+#endif
45650
45651 generic_fillattr(inode, stat);
45652
45653@@ -1481,13 +1542,41 @@ static int pid_getattr(struct vfsmount *
45654 stat->uid = 0;
45655 stat->gid = 0;
45656 task = pid_task(proc_pid(inode), PIDTYPE_PID);
45657+
45658+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
45659+ rcu_read_unlock();
45660+ return -ENOENT;
45661+ }
45662+
45663 if (task) {
45664+ cred = __task_cred(task);
45665+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45666+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
45667+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45668+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45669+#endif
45670+ ) {
45671+#endif
45672 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45673+#ifdef CONFIG_GRKERNSEC_PROC_USER
45674+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45675+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45676+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45677+#endif
45678 task_dumpable(task)) {
45679- cred = __task_cred(task);
45680 stat->uid = cred->euid;
45681+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45682+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
45683+#else
45684 stat->gid = cred->egid;
45685+#endif
45686 }
45687+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45688+ } else {
45689+ rcu_read_unlock();
45690+ return -ENOENT;
45691+ }
45692+#endif
45693 }
45694 rcu_read_unlock();
45695 return 0;
45696@@ -1518,11 +1607,20 @@ static int pid_revalidate(struct dentry
45697
45698 if (task) {
45699 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45700+#ifdef CONFIG_GRKERNSEC_PROC_USER
45701+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45702+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45703+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45704+#endif
45705 task_dumpable(task)) {
45706 rcu_read_lock();
45707 cred = __task_cred(task);
45708 inode->i_uid = cred->euid;
45709+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45710+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45711+#else
45712 inode->i_gid = cred->egid;
45713+#endif
45714 rcu_read_unlock();
45715 } else {
45716 inode->i_uid = 0;
45717@@ -1643,7 +1741,8 @@ static int proc_fd_info(struct inode *in
45718 int fd = proc_fd(inode);
45719
45720 if (task) {
45721- files = get_files_struct(task);
45722+ if (!gr_acl_handle_procpidmem(task))
45723+ files = get_files_struct(task);
45724 put_task_struct(task);
45725 }
45726 if (files) {
45727@@ -1895,12 +1994,22 @@ static const struct file_operations proc
45728 static int proc_fd_permission(struct inode *inode, int mask)
45729 {
45730 int rv;
45731+ struct task_struct *task;
45732
45733 rv = generic_permission(inode, mask, NULL);
45734- if (rv == 0)
45735- return 0;
45736+
45737 if (task_pid(current) == proc_pid(inode))
45738 rv = 0;
45739+
45740+ task = get_proc_task(inode);
45741+ if (task == NULL)
45742+ return rv;
45743+
45744+ if (gr_acl_handle_procpidmem(task))
45745+ rv = -EACCES;
45746+
45747+ put_task_struct(task);
45748+
45749 return rv;
45750 }
45751
45752@@ -2009,6 +2118,9 @@ static struct dentry *proc_pident_lookup
45753 if (!task)
45754 goto out_no_task;
45755
45756+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45757+ goto out;
45758+
45759 /*
45760 * Yes, it does not scale. And it should not. Don't add
45761 * new entries into /proc/<tgid>/ without very good reasons.
45762@@ -2053,6 +2165,9 @@ static int proc_pident_readdir(struct fi
45763 if (!task)
45764 goto out_no_task;
45765
45766+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45767+ goto out;
45768+
45769 ret = 0;
45770 i = filp->f_pos;
45771 switch (i) {
45772@@ -2320,7 +2435,7 @@ static void *proc_self_follow_link(struc
45773 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
45774 void *cookie)
45775 {
45776- char *s = nd_get_link(nd);
45777+ const char *s = nd_get_link(nd);
45778 if (!IS_ERR(s))
45779 __putname(s);
45780 }
45781@@ -2522,7 +2637,7 @@ static const struct pid_entry tgid_base_
45782 #ifdef CONFIG_SCHED_DEBUG
45783 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
45784 #endif
45785-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45786+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45787 INF("syscall", S_IRUSR, proc_pid_syscall),
45788 #endif
45789 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45790@@ -2547,10 +2662,10 @@ static const struct pid_entry tgid_base_
45791 #ifdef CONFIG_SECURITY
45792 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45793 #endif
45794-#ifdef CONFIG_KALLSYMS
45795+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45796 INF("wchan", S_IRUGO, proc_pid_wchan),
45797 #endif
45798-#ifdef CONFIG_STACKTRACE
45799+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45800 ONE("stack", S_IRUSR, proc_pid_stack),
45801 #endif
45802 #ifdef CONFIG_SCHEDSTATS
45803@@ -2580,6 +2695,9 @@ static const struct pid_entry tgid_base_
45804 #ifdef CONFIG_TASK_IO_ACCOUNTING
45805 INF("io", S_IRUSR, proc_tgid_io_accounting),
45806 #endif
45807+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45808+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
45809+#endif
45810 };
45811
45812 static int proc_tgid_base_readdir(struct file * filp,
45813@@ -2704,7 +2822,14 @@ static struct dentry *proc_pid_instantia
45814 if (!inode)
45815 goto out;
45816
45817+#ifdef CONFIG_GRKERNSEC_PROC_USER
45818+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
45819+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45820+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45821+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
45822+#else
45823 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
45824+#endif
45825 inode->i_op = &proc_tgid_base_inode_operations;
45826 inode->i_fop = &proc_tgid_base_operations;
45827 inode->i_flags|=S_IMMUTABLE;
45828@@ -2746,7 +2871,11 @@ struct dentry *proc_pid_lookup(struct in
45829 if (!task)
45830 goto out;
45831
45832+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45833+ goto out_put_task;
45834+
45835 result = proc_pid_instantiate(dir, dentry, task, NULL);
45836+out_put_task:
45837 put_task_struct(task);
45838 out:
45839 return result;
45840@@ -2811,6 +2940,11 @@ int proc_pid_readdir(struct file * filp,
45841 {
45842 unsigned int nr;
45843 struct task_struct *reaper;
45844+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45845+ const struct cred *tmpcred = current_cred();
45846+ const struct cred *itercred;
45847+#endif
45848+ filldir_t __filldir = filldir;
45849 struct tgid_iter iter;
45850 struct pid_namespace *ns;
45851
45852@@ -2834,8 +2968,27 @@ int proc_pid_readdir(struct file * filp,
45853 for (iter = next_tgid(ns, iter);
45854 iter.task;
45855 iter.tgid += 1, iter = next_tgid(ns, iter)) {
45856+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45857+ rcu_read_lock();
45858+ itercred = __task_cred(iter.task);
45859+#endif
45860+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
45861+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45862+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
45863+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45864+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45865+#endif
45866+ )
45867+#endif
45868+ )
45869+ __filldir = &gr_fake_filldir;
45870+ else
45871+ __filldir = filldir;
45872+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45873+ rcu_read_unlock();
45874+#endif
45875 filp->f_pos = iter.tgid + TGID_OFFSET;
45876- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
45877+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
45878 put_task_struct(iter.task);
45879 goto out;
45880 }
45881@@ -2861,7 +3014,7 @@ static const struct pid_entry tid_base_s
45882 #ifdef CONFIG_SCHED_DEBUG
45883 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
45884 #endif
45885-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45886+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45887 INF("syscall", S_IRUSR, proc_pid_syscall),
45888 #endif
45889 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45890@@ -2885,10 +3038,10 @@ static const struct pid_entry tid_base_s
45891 #ifdef CONFIG_SECURITY
45892 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45893 #endif
45894-#ifdef CONFIG_KALLSYMS
45895+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45896 INF("wchan", S_IRUGO, proc_pid_wchan),
45897 #endif
45898-#ifdef CONFIG_STACKTRACE
45899+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45900 ONE("stack", S_IRUSR, proc_pid_stack),
45901 #endif
45902 #ifdef CONFIG_SCHEDSTATS
45903diff -urNp linux-2.6.32.44/fs/proc/cmdline.c linux-2.6.32.44/fs/proc/cmdline.c
45904--- linux-2.6.32.44/fs/proc/cmdline.c 2011-03-27 14:31:47.000000000 -0400
45905+++ linux-2.6.32.44/fs/proc/cmdline.c 2011-04-17 15:56:46.000000000 -0400
45906@@ -23,7 +23,11 @@ static const struct file_operations cmdl
45907
45908 static int __init proc_cmdline_init(void)
45909 {
45910+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45911+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
45912+#else
45913 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
45914+#endif
45915 return 0;
45916 }
45917 module_init(proc_cmdline_init);
45918diff -urNp linux-2.6.32.44/fs/proc/devices.c linux-2.6.32.44/fs/proc/devices.c
45919--- linux-2.6.32.44/fs/proc/devices.c 2011-03-27 14:31:47.000000000 -0400
45920+++ linux-2.6.32.44/fs/proc/devices.c 2011-04-17 15:56:46.000000000 -0400
45921@@ -64,7 +64,11 @@ static const struct file_operations proc
45922
45923 static int __init proc_devices_init(void)
45924 {
45925+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45926+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
45927+#else
45928 proc_create("devices", 0, NULL, &proc_devinfo_operations);
45929+#endif
45930 return 0;
45931 }
45932 module_init(proc_devices_init);
45933diff -urNp linux-2.6.32.44/fs/proc/inode.c linux-2.6.32.44/fs/proc/inode.c
45934--- linux-2.6.32.44/fs/proc/inode.c 2011-03-27 14:31:47.000000000 -0400
45935+++ linux-2.6.32.44/fs/proc/inode.c 2011-04-17 15:56:46.000000000 -0400
45936@@ -457,7 +457,11 @@ struct inode *proc_get_inode(struct supe
45937 if (de->mode) {
45938 inode->i_mode = de->mode;
45939 inode->i_uid = de->uid;
45940+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45941+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45942+#else
45943 inode->i_gid = de->gid;
45944+#endif
45945 }
45946 if (de->size)
45947 inode->i_size = de->size;
45948diff -urNp linux-2.6.32.44/fs/proc/internal.h linux-2.6.32.44/fs/proc/internal.h
45949--- linux-2.6.32.44/fs/proc/internal.h 2011-03-27 14:31:47.000000000 -0400
45950+++ linux-2.6.32.44/fs/proc/internal.h 2011-04-17 15:56:46.000000000 -0400
45951@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
45952 struct pid *pid, struct task_struct *task);
45953 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45954 struct pid *pid, struct task_struct *task);
45955+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45956+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
45957+#endif
45958 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
45959
45960 extern const struct file_operations proc_maps_operations;
45961diff -urNp linux-2.6.32.44/fs/proc/Kconfig linux-2.6.32.44/fs/proc/Kconfig
45962--- linux-2.6.32.44/fs/proc/Kconfig 2011-03-27 14:31:47.000000000 -0400
45963+++ linux-2.6.32.44/fs/proc/Kconfig 2011-04-17 15:56:46.000000000 -0400
45964@@ -30,12 +30,12 @@ config PROC_FS
45965
45966 config PROC_KCORE
45967 bool "/proc/kcore support" if !ARM
45968- depends on PROC_FS && MMU
45969+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
45970
45971 config PROC_VMCORE
45972 bool "/proc/vmcore support (EXPERIMENTAL)"
45973- depends on PROC_FS && CRASH_DUMP
45974- default y
45975+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
45976+ default n
45977 help
45978 Exports the dump image of crashed kernel in ELF format.
45979
45980@@ -59,8 +59,8 @@ config PROC_SYSCTL
45981 limited in memory.
45982
45983 config PROC_PAGE_MONITOR
45984- default y
45985- depends on PROC_FS && MMU
45986+ default n
45987+ depends on PROC_FS && MMU && !GRKERNSEC
45988 bool "Enable /proc page monitoring" if EMBEDDED
45989 help
45990 Various /proc files exist to monitor process memory utilization:
45991diff -urNp linux-2.6.32.44/fs/proc/kcore.c linux-2.6.32.44/fs/proc/kcore.c
45992--- linux-2.6.32.44/fs/proc/kcore.c 2011-03-27 14:31:47.000000000 -0400
45993+++ linux-2.6.32.44/fs/proc/kcore.c 2011-05-16 21:46:57.000000000 -0400
45994@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bu
45995 off_t offset = 0;
45996 struct kcore_list *m;
45997
45998+ pax_track_stack();
45999+
46000 /* setup ELF header */
46001 elf = (struct elfhdr *) bufp;
46002 bufp += sizeof(struct elfhdr);
46003@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __use
46004 * the addresses in the elf_phdr on our list.
46005 */
46006 start = kc_offset_to_vaddr(*fpos - elf_buflen);
46007- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
46008+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
46009+ if (tsz > buflen)
46010 tsz = buflen;
46011-
46012+
46013 while (buflen) {
46014 struct kcore_list *m;
46015
46016@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __use
46017 kfree(elf_buf);
46018 } else {
46019 if (kern_addr_valid(start)) {
46020- unsigned long n;
46021+ char *elf_buf;
46022+ mm_segment_t oldfs;
46023
46024- n = copy_to_user(buffer, (char *)start, tsz);
46025- /*
46026- * We cannot distingush between fault on source
46027- * and fault on destination. When this happens
46028- * we clear too and hope it will trigger the
46029- * EFAULT again.
46030- */
46031- if (n) {
46032- if (clear_user(buffer + tsz - n,
46033- n))
46034+ elf_buf = kmalloc(tsz, GFP_KERNEL);
46035+ if (!elf_buf)
46036+ return -ENOMEM;
46037+ oldfs = get_fs();
46038+ set_fs(KERNEL_DS);
46039+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
46040+ set_fs(oldfs);
46041+ if (copy_to_user(buffer, elf_buf, tsz)) {
46042+ kfree(elf_buf);
46043 return -EFAULT;
46044+ }
46045 }
46046+ set_fs(oldfs);
46047+ kfree(elf_buf);
46048 } else {
46049 if (clear_user(buffer, tsz))
46050 return -EFAULT;
46051@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __use
46052
46053 static int open_kcore(struct inode *inode, struct file *filp)
46054 {
46055+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
46056+ return -EPERM;
46057+#endif
46058 if (!capable(CAP_SYS_RAWIO))
46059 return -EPERM;
46060 if (kcore_need_update)
46061diff -urNp linux-2.6.32.44/fs/proc/meminfo.c linux-2.6.32.44/fs/proc/meminfo.c
46062--- linux-2.6.32.44/fs/proc/meminfo.c 2011-03-27 14:31:47.000000000 -0400
46063+++ linux-2.6.32.44/fs/proc/meminfo.c 2011-05-16 21:46:57.000000000 -0400
46064@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
46065 unsigned long pages[NR_LRU_LISTS];
46066 int lru;
46067
46068+ pax_track_stack();
46069+
46070 /*
46071 * display in kilobytes.
46072 */
46073@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_
46074 vmi.used >> 10,
46075 vmi.largest_chunk >> 10
46076 #ifdef CONFIG_MEMORY_FAILURE
46077- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
46078+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
46079 #endif
46080 );
46081
46082diff -urNp linux-2.6.32.44/fs/proc/nommu.c linux-2.6.32.44/fs/proc/nommu.c
46083--- linux-2.6.32.44/fs/proc/nommu.c 2011-03-27 14:31:47.000000000 -0400
46084+++ linux-2.6.32.44/fs/proc/nommu.c 2011-04-17 15:56:46.000000000 -0400
46085@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_
46086 if (len < 1)
46087 len = 1;
46088 seq_printf(m, "%*c", len, ' ');
46089- seq_path(m, &file->f_path, "");
46090+ seq_path(m, &file->f_path, "\n\\");
46091 }
46092
46093 seq_putc(m, '\n');
46094diff -urNp linux-2.6.32.44/fs/proc/proc_net.c linux-2.6.32.44/fs/proc/proc_net.c
46095--- linux-2.6.32.44/fs/proc/proc_net.c 2011-03-27 14:31:47.000000000 -0400
46096+++ linux-2.6.32.44/fs/proc/proc_net.c 2011-04-17 15:56:46.000000000 -0400
46097@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(str
46098 struct task_struct *task;
46099 struct nsproxy *ns;
46100 struct net *net = NULL;
46101+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46102+ const struct cred *cred = current_cred();
46103+#endif
46104+
46105+#ifdef CONFIG_GRKERNSEC_PROC_USER
46106+ if (cred->fsuid)
46107+ return net;
46108+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46109+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
46110+ return net;
46111+#endif
46112
46113 rcu_read_lock();
46114 task = pid_task(proc_pid(dir), PIDTYPE_PID);
46115diff -urNp linux-2.6.32.44/fs/proc/proc_sysctl.c linux-2.6.32.44/fs/proc/proc_sysctl.c
46116--- linux-2.6.32.44/fs/proc/proc_sysctl.c 2011-03-27 14:31:47.000000000 -0400
46117+++ linux-2.6.32.44/fs/proc/proc_sysctl.c 2011-04-17 15:56:46.000000000 -0400
46118@@ -7,6 +7,8 @@
46119 #include <linux/security.h>
46120 #include "internal.h"
46121
46122+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
46123+
46124 static const struct dentry_operations proc_sys_dentry_operations;
46125 static const struct file_operations proc_sys_file_operations;
46126 static const struct inode_operations proc_sys_inode_operations;
46127@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(st
46128 if (!p)
46129 goto out;
46130
46131+ if (gr_handle_sysctl(p, MAY_EXEC))
46132+ goto out;
46133+
46134 err = ERR_PTR(-ENOMEM);
46135 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
46136 if (h)
46137@@ -228,6 +233,9 @@ static int scan(struct ctl_table_header
46138 if (*pos < file->f_pos)
46139 continue;
46140
46141+ if (gr_handle_sysctl(table, 0))
46142+ continue;
46143+
46144 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
46145 if (res)
46146 return res;
46147@@ -344,6 +352,9 @@ static int proc_sys_getattr(struct vfsmo
46148 if (IS_ERR(head))
46149 return PTR_ERR(head);
46150
46151+ if (table && gr_handle_sysctl(table, MAY_EXEC))
46152+ return -ENOENT;
46153+
46154 generic_fillattr(inode, stat);
46155 if (table)
46156 stat->mode = (stat->mode & S_IFMT) | table->mode;
46157diff -urNp linux-2.6.32.44/fs/proc/root.c linux-2.6.32.44/fs/proc/root.c
46158--- linux-2.6.32.44/fs/proc/root.c 2011-03-27 14:31:47.000000000 -0400
46159+++ linux-2.6.32.44/fs/proc/root.c 2011-04-17 15:56:46.000000000 -0400
46160@@ -134,7 +134,15 @@ void __init proc_root_init(void)
46161 #ifdef CONFIG_PROC_DEVICETREE
46162 proc_device_tree_init();
46163 #endif
46164+#ifdef CONFIG_GRKERNSEC_PROC_ADD
46165+#ifdef CONFIG_GRKERNSEC_PROC_USER
46166+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
46167+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46168+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46169+#endif
46170+#else
46171 proc_mkdir("bus", NULL);
46172+#endif
46173 proc_sys_init();
46174 }
46175
46176diff -urNp linux-2.6.32.44/fs/proc/task_mmu.c linux-2.6.32.44/fs/proc/task_mmu.c
46177--- linux-2.6.32.44/fs/proc/task_mmu.c 2011-03-27 14:31:47.000000000 -0400
46178+++ linux-2.6.32.44/fs/proc/task_mmu.c 2011-04-23 13:38:09.000000000 -0400
46179@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
46180 "VmStk:\t%8lu kB\n"
46181 "VmExe:\t%8lu kB\n"
46182 "VmLib:\t%8lu kB\n"
46183- "VmPTE:\t%8lu kB\n",
46184- hiwater_vm << (PAGE_SHIFT-10),
46185+ "VmPTE:\t%8lu kB\n"
46186+
46187+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46188+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
46189+#endif
46190+
46191+ ,hiwater_vm << (PAGE_SHIFT-10),
46192 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
46193 mm->locked_vm << (PAGE_SHIFT-10),
46194 hiwater_rss << (PAGE_SHIFT-10),
46195 total_rss << (PAGE_SHIFT-10),
46196 data << (PAGE_SHIFT-10),
46197 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
46198- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
46199+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
46200+
46201+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46202+ , mm->context.user_cs_base, mm->context.user_cs_limit
46203+#endif
46204+
46205+ );
46206 }
46207
46208 unsigned long task_vsize(struct mm_struct *mm)
46209@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, v
46210 struct proc_maps_private *priv = m->private;
46211 struct vm_area_struct *vma = v;
46212
46213- vma_stop(priv, vma);
46214+ if (!IS_ERR(vma))
46215+ vma_stop(priv, vma);
46216 if (priv->task)
46217 put_task_struct(priv->task);
46218 }
46219@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *in
46220 return ret;
46221 }
46222
46223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46224+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46225+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
46226+ _mm->pax_flags & MF_PAX_SEGMEXEC))
46227+#endif
46228+
46229 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46230 {
46231 struct mm_struct *mm = vma->vm_mm;
46232@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file
46233 int flags = vma->vm_flags;
46234 unsigned long ino = 0;
46235 unsigned long long pgoff = 0;
46236- unsigned long start;
46237 dev_t dev = 0;
46238 int len;
46239
46240@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file
46241 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
46242 }
46243
46244- /* We don't show the stack guard page in /proc/maps */
46245- start = vma->vm_start;
46246- if (vma->vm_flags & VM_GROWSDOWN)
46247- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
46248- start += PAGE_SIZE;
46249-
46250 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
46251- start,
46252+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46253+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
46254+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
46255+#else
46256+ vma->vm_start,
46257 vma->vm_end,
46258+#endif
46259 flags & VM_READ ? 'r' : '-',
46260 flags & VM_WRITE ? 'w' : '-',
46261 flags & VM_EXEC ? 'x' : '-',
46262 flags & VM_MAYSHARE ? 's' : 'p',
46263+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46264+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
46265+#else
46266 pgoff,
46267+#endif
46268 MAJOR(dev), MINOR(dev), ino, &len);
46269
46270 /*
46271@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file
46272 */
46273 if (file) {
46274 pad_len_spaces(m, len);
46275- seq_path(m, &file->f_path, "\n");
46276+ seq_path(m, &file->f_path, "\n\\");
46277 } else {
46278 const char *name = arch_vma_name(vma);
46279 if (!name) {
46280@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file
46281 if (vma->vm_start <= mm->brk &&
46282 vma->vm_end >= mm->start_brk) {
46283 name = "[heap]";
46284- } else if (vma->vm_start <= mm->start_stack &&
46285- vma->vm_end >= mm->start_stack) {
46286+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
46287+ (vma->vm_start <= mm->start_stack &&
46288+ vma->vm_end >= mm->start_stack)) {
46289 name = "[stack]";
46290 }
46291 } else {
46292@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m,
46293 };
46294
46295 memset(&mss, 0, sizeof mss);
46296- mss.vma = vma;
46297- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46298- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46299+
46300+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46301+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
46302+#endif
46303+ mss.vma = vma;
46304+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46305+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46306+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46307+ }
46308+#endif
46309
46310 show_map_vma(m, vma);
46311
46312@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m,
46313 "Swap: %8lu kB\n"
46314 "KernelPageSize: %8lu kB\n"
46315 "MMUPageSize: %8lu kB\n",
46316+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46317+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
46318+#else
46319 (vma->vm_end - vma->vm_start) >> 10,
46320+#endif
46321 mss.resident >> 10,
46322 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
46323 mss.shared_clean >> 10,
46324diff -urNp linux-2.6.32.44/fs/proc/task_nommu.c linux-2.6.32.44/fs/proc/task_nommu.c
46325--- linux-2.6.32.44/fs/proc/task_nommu.c 2011-03-27 14:31:47.000000000 -0400
46326+++ linux-2.6.32.44/fs/proc/task_nommu.c 2011-04-17 15:56:46.000000000 -0400
46327@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct
46328 else
46329 bytes += kobjsize(mm);
46330
46331- if (current->fs && current->fs->users > 1)
46332+ if (current->fs && atomic_read(&current->fs->users) > 1)
46333 sbytes += kobjsize(current->fs);
46334 else
46335 bytes += kobjsize(current->fs);
46336@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_fil
46337 if (len < 1)
46338 len = 1;
46339 seq_printf(m, "%*c", len, ' ');
46340- seq_path(m, &file->f_path, "");
46341+ seq_path(m, &file->f_path, "\n\\");
46342 }
46343
46344 seq_putc(m, '\n');
46345diff -urNp linux-2.6.32.44/fs/readdir.c linux-2.6.32.44/fs/readdir.c
46346--- linux-2.6.32.44/fs/readdir.c 2011-03-27 14:31:47.000000000 -0400
46347+++ linux-2.6.32.44/fs/readdir.c 2011-04-17 15:56:46.000000000 -0400
46348@@ -16,6 +16,7 @@
46349 #include <linux/security.h>
46350 #include <linux/syscalls.h>
46351 #include <linux/unistd.h>
46352+#include <linux/namei.h>
46353
46354 #include <asm/uaccess.h>
46355
46356@@ -67,6 +68,7 @@ struct old_linux_dirent {
46357
46358 struct readdir_callback {
46359 struct old_linux_dirent __user * dirent;
46360+ struct file * file;
46361 int result;
46362 };
46363
46364@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
46365 buf->result = -EOVERFLOW;
46366 return -EOVERFLOW;
46367 }
46368+
46369+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46370+ return 0;
46371+
46372 buf->result++;
46373 dirent = buf->dirent;
46374 if (!access_ok(VERIFY_WRITE, dirent,
46375@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
46376
46377 buf.result = 0;
46378 buf.dirent = dirent;
46379+ buf.file = file;
46380
46381 error = vfs_readdir(file, fillonedir, &buf);
46382 if (buf.result)
46383@@ -142,6 +149,7 @@ struct linux_dirent {
46384 struct getdents_callback {
46385 struct linux_dirent __user * current_dir;
46386 struct linux_dirent __user * previous;
46387+ struct file * file;
46388 int count;
46389 int error;
46390 };
46391@@ -162,6 +170,10 @@ static int filldir(void * __buf, const c
46392 buf->error = -EOVERFLOW;
46393 return -EOVERFLOW;
46394 }
46395+
46396+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46397+ return 0;
46398+
46399 dirent = buf->previous;
46400 if (dirent) {
46401 if (__put_user(offset, &dirent->d_off))
46402@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
46403 buf.previous = NULL;
46404 buf.count = count;
46405 buf.error = 0;
46406+ buf.file = file;
46407
46408 error = vfs_readdir(file, filldir, &buf);
46409 if (error >= 0)
46410@@ -228,6 +241,7 @@ out:
46411 struct getdents_callback64 {
46412 struct linux_dirent64 __user * current_dir;
46413 struct linux_dirent64 __user * previous;
46414+ struct file *file;
46415 int count;
46416 int error;
46417 };
46418@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const
46419 buf->error = -EINVAL; /* only used if we fail.. */
46420 if (reclen > buf->count)
46421 return -EINVAL;
46422+
46423+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46424+ return 0;
46425+
46426 dirent = buf->previous;
46427 if (dirent) {
46428 if (__put_user(offset, &dirent->d_off))
46429@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
46430
46431 buf.current_dir = dirent;
46432 buf.previous = NULL;
46433+ buf.file = file;
46434 buf.count = count;
46435 buf.error = 0;
46436
46437diff -urNp linux-2.6.32.44/fs/reiserfs/dir.c linux-2.6.32.44/fs/reiserfs/dir.c
46438--- linux-2.6.32.44/fs/reiserfs/dir.c 2011-03-27 14:31:47.000000000 -0400
46439+++ linux-2.6.32.44/fs/reiserfs/dir.c 2011-05-16 21:46:57.000000000 -0400
46440@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
46441 struct reiserfs_dir_entry de;
46442 int ret = 0;
46443
46444+ pax_track_stack();
46445+
46446 reiserfs_write_lock(inode->i_sb);
46447
46448 reiserfs_check_lock_depth(inode->i_sb, "readdir");
46449diff -urNp linux-2.6.32.44/fs/reiserfs/do_balan.c linux-2.6.32.44/fs/reiserfs/do_balan.c
46450--- linux-2.6.32.44/fs/reiserfs/do_balan.c 2011-03-27 14:31:47.000000000 -0400
46451+++ linux-2.6.32.44/fs/reiserfs/do_balan.c 2011-04-17 15:56:46.000000000 -0400
46452@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb,
46453 return;
46454 }
46455
46456- atomic_inc(&(fs_generation(tb->tb_sb)));
46457+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
46458 do_balance_starts(tb);
46459
46460 /* balance leaf returns 0 except if combining L R and S into
46461diff -urNp linux-2.6.32.44/fs/reiserfs/item_ops.c linux-2.6.32.44/fs/reiserfs/item_ops.c
46462--- linux-2.6.32.44/fs/reiserfs/item_ops.c 2011-03-27 14:31:47.000000000 -0400
46463+++ linux-2.6.32.44/fs/reiserfs/item_ops.c 2011-04-17 15:56:46.000000000 -0400
46464@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
46465 vi->vi_index, vi->vi_type, vi->vi_ih);
46466 }
46467
46468-static struct item_operations stat_data_ops = {
46469+static const struct item_operations stat_data_ops = {
46470 .bytes_number = sd_bytes_number,
46471 .decrement_key = sd_decrement_key,
46472 .is_left_mergeable = sd_is_left_mergeable,
46473@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
46474 vi->vi_index, vi->vi_type, vi->vi_ih);
46475 }
46476
46477-static struct item_operations direct_ops = {
46478+static const struct item_operations direct_ops = {
46479 .bytes_number = direct_bytes_number,
46480 .decrement_key = direct_decrement_key,
46481 .is_left_mergeable = direct_is_left_mergeable,
46482@@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
46483 vi->vi_index, vi->vi_type, vi->vi_ih);
46484 }
46485
46486-static struct item_operations indirect_ops = {
46487+static const struct item_operations indirect_ops = {
46488 .bytes_number = indirect_bytes_number,
46489 .decrement_key = indirect_decrement_key,
46490 .is_left_mergeable = indirect_is_left_mergeable,
46491@@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
46492 printk("\n");
46493 }
46494
46495-static struct item_operations direntry_ops = {
46496+static const struct item_operations direntry_ops = {
46497 .bytes_number = direntry_bytes_number,
46498 .decrement_key = direntry_decrement_key,
46499 .is_left_mergeable = direntry_is_left_mergeable,
46500@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
46501 "Invalid item type observed, run fsck ASAP");
46502 }
46503
46504-static struct item_operations errcatch_ops = {
46505+static const struct item_operations errcatch_ops = {
46506 errcatch_bytes_number,
46507 errcatch_decrement_key,
46508 errcatch_is_left_mergeable,
46509@@ -746,7 +746,7 @@ static struct item_operations errcatch_o
46510 #error Item types must use disk-format assigned values.
46511 #endif
46512
46513-struct item_operations *item_ops[TYPE_ANY + 1] = {
46514+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
46515 &stat_data_ops,
46516 &indirect_ops,
46517 &direct_ops,
46518diff -urNp linux-2.6.32.44/fs/reiserfs/journal.c linux-2.6.32.44/fs/reiserfs/journal.c
46519--- linux-2.6.32.44/fs/reiserfs/journal.c 2011-03-27 14:31:47.000000000 -0400
46520+++ linux-2.6.32.44/fs/reiserfs/journal.c 2011-05-16 21:46:57.000000000 -0400
46521@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_brea
46522 struct buffer_head *bh;
46523 int i, j;
46524
46525+ pax_track_stack();
46526+
46527 bh = __getblk(dev, block, bufsize);
46528 if (buffer_uptodate(bh))
46529 return (bh);
46530diff -urNp linux-2.6.32.44/fs/reiserfs/namei.c linux-2.6.32.44/fs/reiserfs/namei.c
46531--- linux-2.6.32.44/fs/reiserfs/namei.c 2011-03-27 14:31:47.000000000 -0400
46532+++ linux-2.6.32.44/fs/reiserfs/namei.c 2011-05-16 21:46:57.000000000 -0400
46533@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode
46534 unsigned long savelink = 1;
46535 struct timespec ctime;
46536
46537+ pax_track_stack();
46538+
46539 /* three balancings: (1) old name removal, (2) new name insertion
46540 and (3) maybe "save" link insertion
46541 stat data updates: (1) old directory,
46542diff -urNp linux-2.6.32.44/fs/reiserfs/procfs.c linux-2.6.32.44/fs/reiserfs/procfs.c
46543--- linux-2.6.32.44/fs/reiserfs/procfs.c 2011-03-27 14:31:47.000000000 -0400
46544+++ linux-2.6.32.44/fs/reiserfs/procfs.c 2011-05-16 21:46:57.000000000 -0400
46545@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m
46546 "SMALL_TAILS " : "NO_TAILS ",
46547 replay_only(sb) ? "REPLAY_ONLY " : "",
46548 convert_reiserfs(sb) ? "CONV " : "",
46549- atomic_read(&r->s_generation_counter),
46550+ atomic_read_unchecked(&r->s_generation_counter),
46551 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
46552 SF(s_do_balance), SF(s_unneeded_left_neighbor),
46553 SF(s_good_search_by_key_reada), SF(s_bmaps),
46554@@ -309,6 +309,8 @@ static int show_journal(struct seq_file
46555 struct journal_params *jp = &rs->s_v1.s_journal;
46556 char b[BDEVNAME_SIZE];
46557
46558+ pax_track_stack();
46559+
46560 seq_printf(m, /* on-disk fields */
46561 "jp_journal_1st_block: \t%i\n"
46562 "jp_journal_dev: \t%s[%x]\n"
46563diff -urNp linux-2.6.32.44/fs/reiserfs/stree.c linux-2.6.32.44/fs/reiserfs/stree.c
46564--- linux-2.6.32.44/fs/reiserfs/stree.c 2011-03-27 14:31:47.000000000 -0400
46565+++ linux-2.6.32.44/fs/reiserfs/stree.c 2011-05-16 21:46:57.000000000 -0400
46566@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs
46567 int iter = 0;
46568 #endif
46569
46570+ pax_track_stack();
46571+
46572 BUG_ON(!th->t_trans_id);
46573
46574 init_tb_struct(th, &s_del_balance, sb, path,
46575@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct r
46576 int retval;
46577 int quota_cut_bytes = 0;
46578
46579+ pax_track_stack();
46580+
46581 BUG_ON(!th->t_trans_id);
46582
46583 le_key2cpu_key(&cpu_key, key);
46584@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiser
46585 int quota_cut_bytes;
46586 loff_t tail_pos = 0;
46587
46588+ pax_track_stack();
46589+
46590 BUG_ON(!th->t_trans_id);
46591
46592 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
46593@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reis
46594 int retval;
46595 int fs_gen;
46596
46597+ pax_track_stack();
46598+
46599 BUG_ON(!th->t_trans_id);
46600
46601 fs_gen = get_generation(inode->i_sb);
46602@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs
46603 int fs_gen = 0;
46604 int quota_bytes = 0;
46605
46606+ pax_track_stack();
46607+
46608 BUG_ON(!th->t_trans_id);
46609
46610 if (inode) { /* Do we count quotas for item? */
46611diff -urNp linux-2.6.32.44/fs/reiserfs/super.c linux-2.6.32.44/fs/reiserfs/super.c
46612--- linux-2.6.32.44/fs/reiserfs/super.c 2011-03-27 14:31:47.000000000 -0400
46613+++ linux-2.6.32.44/fs/reiserfs/super.c 2011-05-16 21:46:57.000000000 -0400
46614@@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct
46615 {.option_name = NULL}
46616 };
46617
46618+ pax_track_stack();
46619+
46620 *blocks = 0;
46621 if (!options || !*options)
46622 /* use default configuration: create tails, journaling on, no
46623diff -urNp linux-2.6.32.44/fs/select.c linux-2.6.32.44/fs/select.c
46624--- linux-2.6.32.44/fs/select.c 2011-03-27 14:31:47.000000000 -0400
46625+++ linux-2.6.32.44/fs/select.c 2011-05-16 21:46:57.000000000 -0400
46626@@ -20,6 +20,7 @@
46627 #include <linux/module.h>
46628 #include <linux/slab.h>
46629 #include <linux/poll.h>
46630+#include <linux/security.h>
46631 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
46632 #include <linux/file.h>
46633 #include <linux/fdtable.h>
46634@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, s
46635 int retval, i, timed_out = 0;
46636 unsigned long slack = 0;
46637
46638+ pax_track_stack();
46639+
46640 rcu_read_lock();
46641 retval = max_select_fd(n, fds);
46642 rcu_read_unlock();
46643@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user
46644 /* Allocate small arguments on the stack to save memory and be faster */
46645 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
46646
46647+ pax_track_stack();
46648+
46649 ret = -EINVAL;
46650 if (n < 0)
46651 goto out_nofds;
46652@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *uf
46653 struct poll_list *walk = head;
46654 unsigned long todo = nfds;
46655
46656+ pax_track_stack();
46657+
46658+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
46659 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
46660 return -EINVAL;
46661
46662diff -urNp linux-2.6.32.44/fs/seq_file.c linux-2.6.32.44/fs/seq_file.c
46663--- linux-2.6.32.44/fs/seq_file.c 2011-03-27 14:31:47.000000000 -0400
46664+++ linux-2.6.32.44/fs/seq_file.c 2011-08-05 20:33:55.000000000 -0400
46665@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
46666 return 0;
46667 }
46668 if (!m->buf) {
46669- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46670+ m->size = PAGE_SIZE;
46671+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46672 if (!m->buf)
46673 return -ENOMEM;
46674 }
46675@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
46676 Eoverflow:
46677 m->op->stop(m, p);
46678 kfree(m->buf);
46679- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46680+ m->size <<= 1;
46681+ m->buf = kmalloc(m->size, GFP_KERNEL);
46682 return !m->buf ? -ENOMEM : -EAGAIN;
46683 }
46684
46685@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
46686 m->version = file->f_version;
46687 /* grab buffer if we didn't have one */
46688 if (!m->buf) {
46689- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46690+ m->size = PAGE_SIZE;
46691+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46692 if (!m->buf)
46693 goto Enomem;
46694 }
46695@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
46696 goto Fill;
46697 m->op->stop(m, p);
46698 kfree(m->buf);
46699- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46700+ m->size <<= 1;
46701+ m->buf = kmalloc(m->size, GFP_KERNEL);
46702 if (!m->buf)
46703 goto Enomem;
46704 m->count = 0;
46705@@ -555,10 +559,10 @@ int single_open(struct file *file, int (
46706 int res = -ENOMEM;
46707
46708 if (op) {
46709- op->start = single_start;
46710- op->next = single_next;
46711- op->stop = single_stop;
46712- op->show = show;
46713+ *(void **)&op->start = single_start;
46714+ *(void **)&op->next = single_next;
46715+ *(void **)&op->stop = single_stop;
46716+ *(void **)&op->show = show;
46717 res = seq_open(file, op);
46718 if (!res)
46719 ((struct seq_file *)file->private_data)->private = data;
46720diff -urNp linux-2.6.32.44/fs/smbfs/proc.c linux-2.6.32.44/fs/smbfs/proc.c
46721--- linux-2.6.32.44/fs/smbfs/proc.c 2011-03-27 14:31:47.000000000 -0400
46722+++ linux-2.6.32.44/fs/smbfs/proc.c 2011-08-05 20:33:55.000000000 -0400
46723@@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *
46724
46725 out:
46726 if (server->local_nls != NULL && server->remote_nls != NULL)
46727- server->ops->convert = convert_cp;
46728+ *(void **)&server->ops->convert = convert_cp;
46729 else
46730- server->ops->convert = convert_memcpy;
46731+ *(void **)&server->ops->convert = convert_memcpy;
46732
46733 smb_unlock_server(server);
46734 return n;
46735@@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server,
46736
46737 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
46738 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
46739- server->ops->getattr = smb_proc_getattr_core;
46740+ *(void **)&server->ops->getattr = smb_proc_getattr_core;
46741 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
46742- server->ops->getattr = smb_proc_getattr_ff;
46743+ *(void **)&server->ops->getattr = smb_proc_getattr_ff;
46744 }
46745
46746 /* Decode server capabilities */
46747@@ -3439,7 +3439,7 @@ out:
46748 static void
46749 install_ops(struct smb_ops *dst, struct smb_ops *src)
46750 {
46751- memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
46752+ memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
46753 }
46754
46755 /* < LANMAN2 */
46756diff -urNp linux-2.6.32.44/fs/smbfs/symlink.c linux-2.6.32.44/fs/smbfs/symlink.c
46757--- linux-2.6.32.44/fs/smbfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
46758+++ linux-2.6.32.44/fs/smbfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
46759@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
46760
46761 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46762 {
46763- char *s = nd_get_link(nd);
46764+ const char *s = nd_get_link(nd);
46765 if (!IS_ERR(s))
46766 __putname(s);
46767 }
46768diff -urNp linux-2.6.32.44/fs/splice.c linux-2.6.32.44/fs/splice.c
46769--- linux-2.6.32.44/fs/splice.c 2011-03-27 14:31:47.000000000 -0400
46770+++ linux-2.6.32.44/fs/splice.c 2011-05-16 21:46:57.000000000 -0400
46771@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode
46772 pipe_lock(pipe);
46773
46774 for (;;) {
46775- if (!pipe->readers) {
46776+ if (!atomic_read(&pipe->readers)) {
46777 send_sig(SIGPIPE, current, 0);
46778 if (!ret)
46779 ret = -EPIPE;
46780@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode
46781 do_wakeup = 0;
46782 }
46783
46784- pipe->waiting_writers++;
46785+ atomic_inc(&pipe->waiting_writers);
46786 pipe_wait(pipe);
46787- pipe->waiting_writers--;
46788+ atomic_dec(&pipe->waiting_writers);
46789 }
46790
46791 pipe_unlock(pipe);
46792@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *
46793 .spd_release = spd_release_page,
46794 };
46795
46796+ pax_track_stack();
46797+
46798 index = *ppos >> PAGE_CACHE_SHIFT;
46799 loff = *ppos & ~PAGE_CACHE_MASK;
46800 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
46801@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file
46802 old_fs = get_fs();
46803 set_fs(get_ds());
46804 /* The cast to a user pointer is valid due to the set_fs() */
46805- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
46806+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
46807 set_fs(old_fs);
46808
46809 return res;
46810@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file
46811 old_fs = get_fs();
46812 set_fs(get_ds());
46813 /* The cast to a user pointer is valid due to the set_fs() */
46814- res = vfs_write(file, (const char __user *)buf, count, &pos);
46815+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
46816 set_fs(old_fs);
46817
46818 return res;
46819@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct
46820 .spd_release = spd_release_page,
46821 };
46822
46823+ pax_track_stack();
46824+
46825 index = *ppos >> PAGE_CACHE_SHIFT;
46826 offset = *ppos & ~PAGE_CACHE_MASK;
46827 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
46828@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct
46829 goto err;
46830
46831 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
46832- vec[i].iov_base = (void __user *) page_address(page);
46833+ vec[i].iov_base = (__force void __user *) page_address(page);
46834 vec[i].iov_len = this_len;
46835 pages[i] = page;
46836 spd.nr_pages++;
46837@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
46838 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
46839 {
46840 while (!pipe->nrbufs) {
46841- if (!pipe->writers)
46842+ if (!atomic_read(&pipe->writers))
46843 return 0;
46844
46845- if (!pipe->waiting_writers && sd->num_spliced)
46846+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
46847 return 0;
46848
46849 if (sd->flags & SPLICE_F_NONBLOCK)
46850@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct fi
46851 * out of the pipe right after the splice_to_pipe(). So set
46852 * PIPE_READERS appropriately.
46853 */
46854- pipe->readers = 1;
46855+ atomic_set(&pipe->readers, 1);
46856
46857 current->splice_pipe = pipe;
46858 }
46859@@ -1592,6 +1596,8 @@ static long vmsplice_to_pipe(struct file
46860 .spd_release = spd_release_page,
46861 };
46862
46863+ pax_track_stack();
46864+
46865 pipe = pipe_info(file->f_path.dentry->d_inode);
46866 if (!pipe)
46867 return -EBADF;
46868@@ -1700,9 +1706,9 @@ static int ipipe_prep(struct pipe_inode_
46869 ret = -ERESTARTSYS;
46870 break;
46871 }
46872- if (!pipe->writers)
46873+ if (!atomic_read(&pipe->writers))
46874 break;
46875- if (!pipe->waiting_writers) {
46876+ if (!atomic_read(&pipe->waiting_writers)) {
46877 if (flags & SPLICE_F_NONBLOCK) {
46878 ret = -EAGAIN;
46879 break;
46880@@ -1734,7 +1740,7 @@ static int opipe_prep(struct pipe_inode_
46881 pipe_lock(pipe);
46882
46883 while (pipe->nrbufs >= PIPE_BUFFERS) {
46884- if (!pipe->readers) {
46885+ if (!atomic_read(&pipe->readers)) {
46886 send_sig(SIGPIPE, current, 0);
46887 ret = -EPIPE;
46888 break;
46889@@ -1747,9 +1753,9 @@ static int opipe_prep(struct pipe_inode_
46890 ret = -ERESTARTSYS;
46891 break;
46892 }
46893- pipe->waiting_writers++;
46894+ atomic_inc(&pipe->waiting_writers);
46895 pipe_wait(pipe);
46896- pipe->waiting_writers--;
46897+ atomic_dec(&pipe->waiting_writers);
46898 }
46899
46900 pipe_unlock(pipe);
46901@@ -1785,14 +1791,14 @@ retry:
46902 pipe_double_lock(ipipe, opipe);
46903
46904 do {
46905- if (!opipe->readers) {
46906+ if (!atomic_read(&opipe->readers)) {
46907 send_sig(SIGPIPE, current, 0);
46908 if (!ret)
46909 ret = -EPIPE;
46910 break;
46911 }
46912
46913- if (!ipipe->nrbufs && !ipipe->writers)
46914+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
46915 break;
46916
46917 /*
46918@@ -1892,7 +1898,7 @@ static int link_pipe(struct pipe_inode_i
46919 pipe_double_lock(ipipe, opipe);
46920
46921 do {
46922- if (!opipe->readers) {
46923+ if (!atomic_read(&opipe->readers)) {
46924 send_sig(SIGPIPE, current, 0);
46925 if (!ret)
46926 ret = -EPIPE;
46927@@ -1937,7 +1943,7 @@ static int link_pipe(struct pipe_inode_i
46928 * return EAGAIN if we have the potential of some data in the
46929 * future, otherwise just return 0
46930 */
46931- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
46932+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
46933 ret = -EAGAIN;
46934
46935 pipe_unlock(ipipe);
46936diff -urNp linux-2.6.32.44/fs/sysfs/file.c linux-2.6.32.44/fs/sysfs/file.c
46937--- linux-2.6.32.44/fs/sysfs/file.c 2011-03-27 14:31:47.000000000 -0400
46938+++ linux-2.6.32.44/fs/sysfs/file.c 2011-05-04 17:56:20.000000000 -0400
46939@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
46940
46941 struct sysfs_open_dirent {
46942 atomic_t refcnt;
46943- atomic_t event;
46944+ atomic_unchecked_t event;
46945 wait_queue_head_t poll;
46946 struct list_head buffers; /* goes through sysfs_buffer.list */
46947 };
46948@@ -53,7 +53,7 @@ struct sysfs_buffer {
46949 size_t count;
46950 loff_t pos;
46951 char * page;
46952- struct sysfs_ops * ops;
46953+ const struct sysfs_ops * ops;
46954 struct mutex mutex;
46955 int needs_read_fill;
46956 int event;
46957@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentr
46958 {
46959 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
46960 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
46961- struct sysfs_ops * ops = buffer->ops;
46962+ const struct sysfs_ops * ops = buffer->ops;
46963 int ret = 0;
46964 ssize_t count;
46965
46966@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
46967 if (!sysfs_get_active_two(attr_sd))
46968 return -ENODEV;
46969
46970- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
46971+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
46972 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
46973
46974 sysfs_put_active_two(attr_sd);
46975@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentr
46976 {
46977 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
46978 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
46979- struct sysfs_ops * ops = buffer->ops;
46980+ const struct sysfs_ops * ops = buffer->ops;
46981 int rc;
46982
46983 /* need attr_sd for attr and ops, its parent for kobj */
46984@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
46985 return -ENOMEM;
46986
46987 atomic_set(&new_od->refcnt, 0);
46988- atomic_set(&new_od->event, 1);
46989+ atomic_set_unchecked(&new_od->event, 1);
46990 init_waitqueue_head(&new_od->poll);
46991 INIT_LIST_HEAD(&new_od->buffers);
46992 goto retry;
46993@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode
46994 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
46995 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
46996 struct sysfs_buffer *buffer;
46997- struct sysfs_ops *ops;
46998+ const struct sysfs_ops *ops;
46999 int error = -EACCES;
47000 char *p;
47001
47002@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
47003
47004 sysfs_put_active_two(attr_sd);
47005
47006- if (buffer->event != atomic_read(&od->event))
47007+ if (buffer->event != atomic_read_unchecked(&od->event))
47008 goto trigger;
47009
47010 return DEFAULT_POLLMASK;
47011@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
47012
47013 od = sd->s_attr.open;
47014 if (od) {
47015- atomic_inc(&od->event);
47016+ atomic_inc_unchecked(&od->event);
47017 wake_up_interruptible(&od->poll);
47018 }
47019
47020diff -urNp linux-2.6.32.44/fs/sysfs/mount.c linux-2.6.32.44/fs/sysfs/mount.c
47021--- linux-2.6.32.44/fs/sysfs/mount.c 2011-03-27 14:31:47.000000000 -0400
47022+++ linux-2.6.32.44/fs/sysfs/mount.c 2011-04-17 15:56:46.000000000 -0400
47023@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
47024 .s_name = "",
47025 .s_count = ATOMIC_INIT(1),
47026 .s_flags = SYSFS_DIR,
47027+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47028+ .s_mode = S_IFDIR | S_IRWXU,
47029+#else
47030 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47031+#endif
47032 .s_ino = 1,
47033 };
47034
47035diff -urNp linux-2.6.32.44/fs/sysfs/symlink.c linux-2.6.32.44/fs/sysfs/symlink.c
47036--- linux-2.6.32.44/fs/sysfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
47037+++ linux-2.6.32.44/fs/sysfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
47038@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct de
47039
47040 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47041 {
47042- char *page = nd_get_link(nd);
47043+ const char *page = nd_get_link(nd);
47044 if (!IS_ERR(page))
47045 free_page((unsigned long)page);
47046 }
47047diff -urNp linux-2.6.32.44/fs/udf/balloc.c linux-2.6.32.44/fs/udf/balloc.c
47048--- linux-2.6.32.44/fs/udf/balloc.c 2011-03-27 14:31:47.000000000 -0400
47049+++ linux-2.6.32.44/fs/udf/balloc.c 2011-04-17 15:56:46.000000000 -0400
47050@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struc
47051
47052 mutex_lock(&sbi->s_alloc_mutex);
47053 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
47054- if (bloc->logicalBlockNum < 0 ||
47055- (bloc->logicalBlockNum + count) >
47056- partmap->s_partition_len) {
47057+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
47058 udf_debug("%d < %d || %d + %d > %d\n",
47059 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
47060 count, partmap->s_partition_len);
47061@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct
47062
47063 mutex_lock(&sbi->s_alloc_mutex);
47064 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
47065- if (bloc->logicalBlockNum < 0 ||
47066- (bloc->logicalBlockNum + count) >
47067- partmap->s_partition_len) {
47068+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
47069 udf_debug("%d < %d || %d + %d > %d\n",
47070 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
47071 partmap->s_partition_len);
47072diff -urNp linux-2.6.32.44/fs/udf/inode.c linux-2.6.32.44/fs/udf/inode.c
47073--- linux-2.6.32.44/fs/udf/inode.c 2011-03-27 14:31:47.000000000 -0400
47074+++ linux-2.6.32.44/fs/udf/inode.c 2011-05-16 21:46:57.000000000 -0400
47075@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(
47076 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
47077 int lastblock = 0;
47078
47079+ pax_track_stack();
47080+
47081 prev_epos.offset = udf_file_entry_alloc_offset(inode);
47082 prev_epos.block = iinfo->i_location;
47083 prev_epos.bh = NULL;
47084diff -urNp linux-2.6.32.44/fs/udf/misc.c linux-2.6.32.44/fs/udf/misc.c
47085--- linux-2.6.32.44/fs/udf/misc.c 2011-03-27 14:31:47.000000000 -0400
47086+++ linux-2.6.32.44/fs/udf/misc.c 2011-04-23 12:56:11.000000000 -0400
47087@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
47088
47089 u8 udf_tag_checksum(const struct tag *t)
47090 {
47091- u8 *data = (u8 *)t;
47092+ const u8 *data = (const u8 *)t;
47093 u8 checksum = 0;
47094 int i;
47095 for (i = 0; i < sizeof(struct tag); ++i)
47096diff -urNp linux-2.6.32.44/fs/utimes.c linux-2.6.32.44/fs/utimes.c
47097--- linux-2.6.32.44/fs/utimes.c 2011-03-27 14:31:47.000000000 -0400
47098+++ linux-2.6.32.44/fs/utimes.c 2011-04-17 15:56:46.000000000 -0400
47099@@ -1,6 +1,7 @@
47100 #include <linux/compiler.h>
47101 #include <linux/file.h>
47102 #include <linux/fs.h>
47103+#include <linux/security.h>
47104 #include <linux/linkage.h>
47105 #include <linux/mount.h>
47106 #include <linux/namei.h>
47107@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
47108 goto mnt_drop_write_and_out;
47109 }
47110 }
47111+
47112+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
47113+ error = -EACCES;
47114+ goto mnt_drop_write_and_out;
47115+ }
47116+
47117 mutex_lock(&inode->i_mutex);
47118 error = notify_change(path->dentry, &newattrs);
47119 mutex_unlock(&inode->i_mutex);
47120diff -urNp linux-2.6.32.44/fs/xattr_acl.c linux-2.6.32.44/fs/xattr_acl.c
47121--- linux-2.6.32.44/fs/xattr_acl.c 2011-03-27 14:31:47.000000000 -0400
47122+++ linux-2.6.32.44/fs/xattr_acl.c 2011-04-17 15:56:46.000000000 -0400
47123@@ -17,8 +17,8 @@
47124 struct posix_acl *
47125 posix_acl_from_xattr(const void *value, size_t size)
47126 {
47127- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
47128- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
47129+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
47130+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
47131 int count;
47132 struct posix_acl *acl;
47133 struct posix_acl_entry *acl_e;
47134diff -urNp linux-2.6.32.44/fs/xattr.c linux-2.6.32.44/fs/xattr.c
47135--- linux-2.6.32.44/fs/xattr.c 2011-03-27 14:31:47.000000000 -0400
47136+++ linux-2.6.32.44/fs/xattr.c 2011-04-17 15:56:46.000000000 -0400
47137@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
47138 * Extended attribute SET operations
47139 */
47140 static long
47141-setxattr(struct dentry *d, const char __user *name, const void __user *value,
47142+setxattr(struct path *path, const char __user *name, const void __user *value,
47143 size_t size, int flags)
47144 {
47145 int error;
47146@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
47147 return PTR_ERR(kvalue);
47148 }
47149
47150- error = vfs_setxattr(d, kname, kvalue, size, flags);
47151+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
47152+ error = -EACCES;
47153+ goto out;
47154+ }
47155+
47156+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
47157+out:
47158 kfree(kvalue);
47159 return error;
47160 }
47161@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
47162 return error;
47163 error = mnt_want_write(path.mnt);
47164 if (!error) {
47165- error = setxattr(path.dentry, name, value, size, flags);
47166+ error = setxattr(&path, name, value, size, flags);
47167 mnt_drop_write(path.mnt);
47168 }
47169 path_put(&path);
47170@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
47171 return error;
47172 error = mnt_want_write(path.mnt);
47173 if (!error) {
47174- error = setxattr(path.dentry, name, value, size, flags);
47175+ error = setxattr(&path, name, value, size, flags);
47176 mnt_drop_write(path.mnt);
47177 }
47178 path_put(&path);
47179@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
47180 const void __user *,value, size_t, size, int, flags)
47181 {
47182 struct file *f;
47183- struct dentry *dentry;
47184 int error = -EBADF;
47185
47186 f = fget(fd);
47187 if (!f)
47188 return error;
47189- dentry = f->f_path.dentry;
47190- audit_inode(NULL, dentry);
47191+ audit_inode(NULL, f->f_path.dentry);
47192 error = mnt_want_write_file(f);
47193 if (!error) {
47194- error = setxattr(dentry, name, value, size, flags);
47195+ error = setxattr(&f->f_path, name, value, size, flags);
47196 mnt_drop_write(f->f_path.mnt);
47197 }
47198 fput(f);
47199diff -urNp linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl32.c
47200--- linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-03-27 14:31:47.000000000 -0400
47201+++ linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-04-17 15:56:46.000000000 -0400
47202@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
47203 xfs_fsop_geom_t fsgeo;
47204 int error;
47205
47206+ memset(&fsgeo, 0, sizeof(fsgeo));
47207 error = xfs_fs_geometry(mp, &fsgeo, 3);
47208 if (error)
47209 return -error;
47210diff -urNp linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl.c
47211--- linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 17:00:52.000000000 -0400
47212+++ linux-2.6.32.44/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 20:07:09.000000000 -0400
47213@@ -134,7 +134,7 @@ xfs_find_handle(
47214 }
47215
47216 error = -EFAULT;
47217- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
47218+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
47219 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
47220 goto out_put;
47221
47222@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
47223 if (IS_ERR(dentry))
47224 return PTR_ERR(dentry);
47225
47226- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
47227+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
47228 if (!kbuf)
47229 goto out_dput;
47230
47231@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
47232 xfs_mount_t *mp,
47233 void __user *arg)
47234 {
47235- xfs_fsop_geom_t fsgeo;
47236+ xfs_fsop_geom_t fsgeo;
47237 int error;
47238
47239 error = xfs_fs_geometry(mp, &fsgeo, 3);
47240diff -urNp linux-2.6.32.44/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.44/fs/xfs/linux-2.6/xfs_iops.c
47241--- linux-2.6.32.44/fs/xfs/linux-2.6/xfs_iops.c 2011-03-27 14:31:47.000000000 -0400
47242+++ linux-2.6.32.44/fs/xfs/linux-2.6/xfs_iops.c 2011-04-17 15:56:46.000000000 -0400
47243@@ -468,7 +468,7 @@ xfs_vn_put_link(
47244 struct nameidata *nd,
47245 void *p)
47246 {
47247- char *s = nd_get_link(nd);
47248+ const char *s = nd_get_link(nd);
47249
47250 if (!IS_ERR(s))
47251 kfree(s);
47252diff -urNp linux-2.6.32.44/fs/xfs/xfs_bmap.c linux-2.6.32.44/fs/xfs/xfs_bmap.c
47253--- linux-2.6.32.44/fs/xfs/xfs_bmap.c 2011-03-27 14:31:47.000000000 -0400
47254+++ linux-2.6.32.44/fs/xfs/xfs_bmap.c 2011-04-17 15:56:46.000000000 -0400
47255@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
47256 int nmap,
47257 int ret_nmap);
47258 #else
47259-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
47260+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
47261 #endif /* DEBUG */
47262
47263 #if defined(XFS_RW_TRACE)
47264diff -urNp linux-2.6.32.44/fs/xfs/xfs_dir2_sf.c linux-2.6.32.44/fs/xfs/xfs_dir2_sf.c
47265--- linux-2.6.32.44/fs/xfs/xfs_dir2_sf.c 2011-03-27 14:31:47.000000000 -0400
47266+++ linux-2.6.32.44/fs/xfs/xfs_dir2_sf.c 2011-04-18 22:07:30.000000000 -0400
47267@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
47268 }
47269
47270 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
47271- if (filldir(dirent, sfep->name, sfep->namelen,
47272+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
47273+ char name[sfep->namelen];
47274+ memcpy(name, sfep->name, sfep->namelen);
47275+ if (filldir(dirent, name, sfep->namelen,
47276+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
47277+ *offset = off & 0x7fffffff;
47278+ return 0;
47279+ }
47280+ } else if (filldir(dirent, sfep->name, sfep->namelen,
47281 off & 0x7fffffff, ino, DT_UNKNOWN)) {
47282 *offset = off & 0x7fffffff;
47283 return 0;
47284diff -urNp linux-2.6.32.44/grsecurity/gracl_alloc.c linux-2.6.32.44/grsecurity/gracl_alloc.c
47285--- linux-2.6.32.44/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
47286+++ linux-2.6.32.44/grsecurity/gracl_alloc.c 2011-04-17 15:56:46.000000000 -0400
47287@@ -0,0 +1,105 @@
47288+#include <linux/kernel.h>
47289+#include <linux/mm.h>
47290+#include <linux/slab.h>
47291+#include <linux/vmalloc.h>
47292+#include <linux/gracl.h>
47293+#include <linux/grsecurity.h>
47294+
47295+static unsigned long alloc_stack_next = 1;
47296+static unsigned long alloc_stack_size = 1;
47297+static void **alloc_stack;
47298+
47299+static __inline__ int
47300+alloc_pop(void)
47301+{
47302+ if (alloc_stack_next == 1)
47303+ return 0;
47304+
47305+ kfree(alloc_stack[alloc_stack_next - 2]);
47306+
47307+ alloc_stack_next--;
47308+
47309+ return 1;
47310+}
47311+
47312+static __inline__ int
47313+alloc_push(void *buf)
47314+{
47315+ if (alloc_stack_next >= alloc_stack_size)
47316+ return 1;
47317+
47318+ alloc_stack[alloc_stack_next - 1] = buf;
47319+
47320+ alloc_stack_next++;
47321+
47322+ return 0;
47323+}
47324+
47325+void *
47326+acl_alloc(unsigned long len)
47327+{
47328+ void *ret = NULL;
47329+
47330+ if (!len || len > PAGE_SIZE)
47331+ goto out;
47332+
47333+ ret = kmalloc(len, GFP_KERNEL);
47334+
47335+ if (ret) {
47336+ if (alloc_push(ret)) {
47337+ kfree(ret);
47338+ ret = NULL;
47339+ }
47340+ }
47341+
47342+out:
47343+ return ret;
47344+}
47345+
47346+void *
47347+acl_alloc_num(unsigned long num, unsigned long len)
47348+{
47349+ if (!len || (num > (PAGE_SIZE / len)))
47350+ return NULL;
47351+
47352+ return acl_alloc(num * len);
47353+}
47354+
47355+void
47356+acl_free_all(void)
47357+{
47358+ if (gr_acl_is_enabled() || !alloc_stack)
47359+ return;
47360+
47361+ while (alloc_pop()) ;
47362+
47363+ if (alloc_stack) {
47364+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
47365+ kfree(alloc_stack);
47366+ else
47367+ vfree(alloc_stack);
47368+ }
47369+
47370+ alloc_stack = NULL;
47371+ alloc_stack_size = 1;
47372+ alloc_stack_next = 1;
47373+
47374+ return;
47375+}
47376+
47377+int
47378+acl_alloc_stack_init(unsigned long size)
47379+{
47380+ if ((size * sizeof (void *)) <= PAGE_SIZE)
47381+ alloc_stack =
47382+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
47383+ else
47384+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
47385+
47386+ alloc_stack_size = size;
47387+
47388+ if (!alloc_stack)
47389+ return 0;
47390+ else
47391+ return 1;
47392+}
47393diff -urNp linux-2.6.32.44/grsecurity/gracl.c linux-2.6.32.44/grsecurity/gracl.c
47394--- linux-2.6.32.44/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
47395+++ linux-2.6.32.44/grsecurity/gracl.c 2011-07-14 20:02:48.000000000 -0400
47396@@ -0,0 +1,4082 @@
47397+#include <linux/kernel.h>
47398+#include <linux/module.h>
47399+#include <linux/sched.h>
47400+#include <linux/mm.h>
47401+#include <linux/file.h>
47402+#include <linux/fs.h>
47403+#include <linux/namei.h>
47404+#include <linux/mount.h>
47405+#include <linux/tty.h>
47406+#include <linux/proc_fs.h>
47407+#include <linux/smp_lock.h>
47408+#include <linux/slab.h>
47409+#include <linux/vmalloc.h>
47410+#include <linux/types.h>
47411+#include <linux/sysctl.h>
47412+#include <linux/netdevice.h>
47413+#include <linux/ptrace.h>
47414+#include <linux/gracl.h>
47415+#include <linux/gralloc.h>
47416+#include <linux/grsecurity.h>
47417+#include <linux/grinternal.h>
47418+#include <linux/pid_namespace.h>
47419+#include <linux/fdtable.h>
47420+#include <linux/percpu.h>
47421+
47422+#include <asm/uaccess.h>
47423+#include <asm/errno.h>
47424+#include <asm/mman.h>
47425+
47426+static struct acl_role_db acl_role_set;
47427+static struct name_db name_set;
47428+static struct inodev_db inodev_set;
47429+
47430+/* for keeping track of userspace pointers used for subjects, so we
47431+ can share references in the kernel as well
47432+*/
47433+
47434+static struct dentry *real_root;
47435+static struct vfsmount *real_root_mnt;
47436+
47437+static struct acl_subj_map_db subj_map_set;
47438+
47439+static struct acl_role_label *default_role;
47440+
47441+static struct acl_role_label *role_list;
47442+
47443+static u16 acl_sp_role_value;
47444+
47445+extern char *gr_shared_page[4];
47446+static DEFINE_MUTEX(gr_dev_mutex);
47447+DEFINE_RWLOCK(gr_inode_lock);
47448+
47449+struct gr_arg *gr_usermode;
47450+
47451+static unsigned int gr_status __read_only = GR_STATUS_INIT;
47452+
47453+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
47454+extern void gr_clear_learn_entries(void);
47455+
47456+#ifdef CONFIG_GRKERNSEC_RESLOG
47457+extern void gr_log_resource(const struct task_struct *task,
47458+ const int res, const unsigned long wanted, const int gt);
47459+#endif
47460+
47461+unsigned char *gr_system_salt;
47462+unsigned char *gr_system_sum;
47463+
47464+static struct sprole_pw **acl_special_roles = NULL;
47465+static __u16 num_sprole_pws = 0;
47466+
47467+static struct acl_role_label *kernel_role = NULL;
47468+
47469+static unsigned int gr_auth_attempts = 0;
47470+static unsigned long gr_auth_expires = 0UL;
47471+
47472+#ifdef CONFIG_NET
47473+extern struct vfsmount *sock_mnt;
47474+#endif
47475+extern struct vfsmount *pipe_mnt;
47476+extern struct vfsmount *shm_mnt;
47477+#ifdef CONFIG_HUGETLBFS
47478+extern struct vfsmount *hugetlbfs_vfsmount;
47479+#endif
47480+
47481+static struct acl_object_label *fakefs_obj_rw;
47482+static struct acl_object_label *fakefs_obj_rwx;
47483+
47484+extern int gr_init_uidset(void);
47485+extern void gr_free_uidset(void);
47486+extern void gr_remove_uid(uid_t uid);
47487+extern int gr_find_uid(uid_t uid);
47488+
47489+__inline__ int
47490+gr_acl_is_enabled(void)
47491+{
47492+ return (gr_status & GR_READY);
47493+}
47494+
47495+#ifdef CONFIG_BTRFS_FS
47496+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
47497+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
47498+#endif
47499+
47500+static inline dev_t __get_dev(const struct dentry *dentry)
47501+{
47502+#ifdef CONFIG_BTRFS_FS
47503+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
47504+ return get_btrfs_dev_from_inode(dentry->d_inode);
47505+ else
47506+#endif
47507+ return dentry->d_inode->i_sb->s_dev;
47508+}
47509+
47510+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
47511+{
47512+ return __get_dev(dentry);
47513+}
47514+
47515+static char gr_task_roletype_to_char(struct task_struct *task)
47516+{
47517+ switch (task->role->roletype &
47518+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
47519+ GR_ROLE_SPECIAL)) {
47520+ case GR_ROLE_DEFAULT:
47521+ return 'D';
47522+ case GR_ROLE_USER:
47523+ return 'U';
47524+ case GR_ROLE_GROUP:
47525+ return 'G';
47526+ case GR_ROLE_SPECIAL:
47527+ return 'S';
47528+ }
47529+
47530+ return 'X';
47531+}
47532+
47533+char gr_roletype_to_char(void)
47534+{
47535+ return gr_task_roletype_to_char(current);
47536+}
47537+
47538+__inline__ int
47539+gr_acl_tpe_check(void)
47540+{
47541+ if (unlikely(!(gr_status & GR_READY)))
47542+ return 0;
47543+ if (current->role->roletype & GR_ROLE_TPE)
47544+ return 1;
47545+ else
47546+ return 0;
47547+}
47548+
47549+int
47550+gr_handle_rawio(const struct inode *inode)
47551+{
47552+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
47553+ if (inode && S_ISBLK(inode->i_mode) &&
47554+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
47555+ !capable(CAP_SYS_RAWIO))
47556+ return 1;
47557+#endif
47558+ return 0;
47559+}
47560+
47561+static int
47562+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
47563+{
47564+ if (likely(lena != lenb))
47565+ return 0;
47566+
47567+ return !memcmp(a, b, lena);
47568+}
47569+
47570+/* this must be called with vfsmount_lock and dcache_lock held */
47571+
47572+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
47573+ struct dentry *root, struct vfsmount *rootmnt,
47574+ char *buffer, int buflen)
47575+{
47576+ char * end = buffer+buflen;
47577+ char * retval;
47578+ int namelen;
47579+
47580+ *--end = '\0';
47581+ buflen--;
47582+
47583+ if (buflen < 1)
47584+ goto Elong;
47585+ /* Get '/' right */
47586+ retval = end-1;
47587+ *retval = '/';
47588+
47589+ for (;;) {
47590+ struct dentry * parent;
47591+
47592+ if (dentry == root && vfsmnt == rootmnt)
47593+ break;
47594+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
47595+ /* Global root? */
47596+ if (vfsmnt->mnt_parent == vfsmnt)
47597+ goto global_root;
47598+ dentry = vfsmnt->mnt_mountpoint;
47599+ vfsmnt = vfsmnt->mnt_parent;
47600+ continue;
47601+ }
47602+ parent = dentry->d_parent;
47603+ prefetch(parent);
47604+ namelen = dentry->d_name.len;
47605+ buflen -= namelen + 1;
47606+ if (buflen < 0)
47607+ goto Elong;
47608+ end -= namelen;
47609+ memcpy(end, dentry->d_name.name, namelen);
47610+ *--end = '/';
47611+ retval = end;
47612+ dentry = parent;
47613+ }
47614+
47615+out:
47616+ return retval;
47617+
47618+global_root:
47619+ namelen = dentry->d_name.len;
47620+ buflen -= namelen;
47621+ if (buflen < 0)
47622+ goto Elong;
47623+ retval -= namelen-1; /* hit the slash */
47624+ memcpy(retval, dentry->d_name.name, namelen);
47625+ goto out;
47626+Elong:
47627+ retval = ERR_PTR(-ENAMETOOLONG);
47628+ goto out;
47629+}
47630+
47631+static char *
47632+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
47633+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
47634+{
47635+ char *retval;
47636+
47637+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
47638+ if (unlikely(IS_ERR(retval)))
47639+ retval = strcpy(buf, "<path too long>");
47640+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
47641+ retval[1] = '\0';
47642+
47643+ return retval;
47644+}
47645+
47646+static char *
47647+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
47648+ char *buf, int buflen)
47649+{
47650+ char *res;
47651+
47652+ /* we can use real_root, real_root_mnt, because this is only called
47653+ by the RBAC system */
47654+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
47655+
47656+ return res;
47657+}
47658+
47659+static char *
47660+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
47661+ char *buf, int buflen)
47662+{
47663+ char *res;
47664+ struct dentry *root;
47665+ struct vfsmount *rootmnt;
47666+ struct task_struct *reaper = &init_task;
47667+
47668+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
47669+ read_lock(&reaper->fs->lock);
47670+ root = dget(reaper->fs->root.dentry);
47671+ rootmnt = mntget(reaper->fs->root.mnt);
47672+ read_unlock(&reaper->fs->lock);
47673+
47674+ spin_lock(&dcache_lock);
47675+ spin_lock(&vfsmount_lock);
47676+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
47677+ spin_unlock(&vfsmount_lock);
47678+ spin_unlock(&dcache_lock);
47679+
47680+ dput(root);
47681+ mntput(rootmnt);
47682+ return res;
47683+}
47684+
47685+static char *
47686+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
47687+{
47688+ char *ret;
47689+ spin_lock(&dcache_lock);
47690+ spin_lock(&vfsmount_lock);
47691+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
47692+ PAGE_SIZE);
47693+ spin_unlock(&vfsmount_lock);
47694+ spin_unlock(&dcache_lock);
47695+ return ret;
47696+}
47697+
47698+char *
47699+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
47700+{
47701+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
47702+ PAGE_SIZE);
47703+}
47704+
47705+char *
47706+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
47707+{
47708+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
47709+ PAGE_SIZE);
47710+}
47711+
47712+char *
47713+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
47714+{
47715+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
47716+ PAGE_SIZE);
47717+}
47718+
47719+char *
47720+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
47721+{
47722+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
47723+ PAGE_SIZE);
47724+}
47725+
47726+char *
47727+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
47728+{
47729+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
47730+ PAGE_SIZE);
47731+}
47732+
47733+__inline__ __u32
47734+to_gr_audit(const __u32 reqmode)
47735+{
47736+ /* masks off auditable permission flags, then shifts them to create
47737+ auditing flags, and adds the special case of append auditing if
47738+ we're requesting write */
47739+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
47740+}
47741+
47742+struct acl_subject_label *
47743+lookup_subject_map(const struct acl_subject_label *userp)
47744+{
47745+ unsigned int index = shash(userp, subj_map_set.s_size);
47746+ struct subject_map *match;
47747+
47748+ match = subj_map_set.s_hash[index];
47749+
47750+ while (match && match->user != userp)
47751+ match = match->next;
47752+
47753+ if (match != NULL)
47754+ return match->kernel;
47755+ else
47756+ return NULL;
47757+}
47758+
47759+static void
47760+insert_subj_map_entry(struct subject_map *subjmap)
47761+{
47762+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
47763+ struct subject_map **curr;
47764+
47765+ subjmap->prev = NULL;
47766+
47767+ curr = &subj_map_set.s_hash[index];
47768+ if (*curr != NULL)
47769+ (*curr)->prev = subjmap;
47770+
47771+ subjmap->next = *curr;
47772+ *curr = subjmap;
47773+
47774+ return;
47775+}
47776+
47777+static struct acl_role_label *
47778+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
47779+ const gid_t gid)
47780+{
47781+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
47782+ struct acl_role_label *match;
47783+ struct role_allowed_ip *ipp;
47784+ unsigned int x;
47785+ u32 curr_ip = task->signal->curr_ip;
47786+
47787+ task->signal->saved_ip = curr_ip;
47788+
47789+ match = acl_role_set.r_hash[index];
47790+
47791+ while (match) {
47792+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
47793+ for (x = 0; x < match->domain_child_num; x++) {
47794+ if (match->domain_children[x] == uid)
47795+ goto found;
47796+ }
47797+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
47798+ break;
47799+ match = match->next;
47800+ }
47801+found:
47802+ if (match == NULL) {
47803+ try_group:
47804+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
47805+ match = acl_role_set.r_hash[index];
47806+
47807+ while (match) {
47808+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
47809+ for (x = 0; x < match->domain_child_num; x++) {
47810+ if (match->domain_children[x] == gid)
47811+ goto found2;
47812+ }
47813+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
47814+ break;
47815+ match = match->next;
47816+ }
47817+found2:
47818+ if (match == NULL)
47819+ match = default_role;
47820+ if (match->allowed_ips == NULL)
47821+ return match;
47822+ else {
47823+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
47824+ if (likely
47825+ ((ntohl(curr_ip) & ipp->netmask) ==
47826+ (ntohl(ipp->addr) & ipp->netmask)))
47827+ return match;
47828+ }
47829+ match = default_role;
47830+ }
47831+ } else if (match->allowed_ips == NULL) {
47832+ return match;
47833+ } else {
47834+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
47835+ if (likely
47836+ ((ntohl(curr_ip) & ipp->netmask) ==
47837+ (ntohl(ipp->addr) & ipp->netmask)))
47838+ return match;
47839+ }
47840+ goto try_group;
47841+ }
47842+
47843+ return match;
47844+}
47845+
47846+struct acl_subject_label *
47847+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
47848+ const struct acl_role_label *role)
47849+{
47850+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
47851+ struct acl_subject_label *match;
47852+
47853+ match = role->subj_hash[index];
47854+
47855+ while (match && (match->inode != ino || match->device != dev ||
47856+ (match->mode & GR_DELETED))) {
47857+ match = match->next;
47858+ }
47859+
47860+ if (match && !(match->mode & GR_DELETED))
47861+ return match;
47862+ else
47863+ return NULL;
47864+}
47865+
47866+struct acl_subject_label *
47867+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
47868+ const struct acl_role_label *role)
47869+{
47870+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
47871+ struct acl_subject_label *match;
47872+
47873+ match = role->subj_hash[index];
47874+
47875+ while (match && (match->inode != ino || match->device != dev ||
47876+ !(match->mode & GR_DELETED))) {
47877+ match = match->next;
47878+ }
47879+
47880+ if (match && (match->mode & GR_DELETED))
47881+ return match;
47882+ else
47883+ return NULL;
47884+}
47885+
47886+static struct acl_object_label *
47887+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
47888+ const struct acl_subject_label *subj)
47889+{
47890+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
47891+ struct acl_object_label *match;
47892+
47893+ match = subj->obj_hash[index];
47894+
47895+ while (match && (match->inode != ino || match->device != dev ||
47896+ (match->mode & GR_DELETED))) {
47897+ match = match->next;
47898+ }
47899+
47900+ if (match && !(match->mode & GR_DELETED))
47901+ return match;
47902+ else
47903+ return NULL;
47904+}
47905+
47906+static struct acl_object_label *
47907+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
47908+ const struct acl_subject_label *subj)
47909+{
47910+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
47911+ struct acl_object_label *match;
47912+
47913+ match = subj->obj_hash[index];
47914+
47915+ while (match && (match->inode != ino || match->device != dev ||
47916+ !(match->mode & GR_DELETED))) {
47917+ match = match->next;
47918+ }
47919+
47920+ if (match && (match->mode & GR_DELETED))
47921+ return match;
47922+
47923+ match = subj->obj_hash[index];
47924+
47925+ while (match && (match->inode != ino || match->device != dev ||
47926+ (match->mode & GR_DELETED))) {
47927+ match = match->next;
47928+ }
47929+
47930+ if (match && !(match->mode & GR_DELETED))
47931+ return match;
47932+ else
47933+ return NULL;
47934+}
47935+
47936+static struct name_entry *
47937+lookup_name_entry(const char *name)
47938+{
47939+ unsigned int len = strlen(name);
47940+ unsigned int key = full_name_hash(name, len);
47941+ unsigned int index = key % name_set.n_size;
47942+ struct name_entry *match;
47943+
47944+ match = name_set.n_hash[index];
47945+
47946+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
47947+ match = match->next;
47948+
47949+ return match;
47950+}
47951+
47952+static struct name_entry *
47953+lookup_name_entry_create(const char *name)
47954+{
47955+ unsigned int len = strlen(name);
47956+ unsigned int key = full_name_hash(name, len);
47957+ unsigned int index = key % name_set.n_size;
47958+ struct name_entry *match;
47959+
47960+ match = name_set.n_hash[index];
47961+
47962+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
47963+ !match->deleted))
47964+ match = match->next;
47965+
47966+ if (match && match->deleted)
47967+ return match;
47968+
47969+ match = name_set.n_hash[index];
47970+
47971+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
47972+ match->deleted))
47973+ match = match->next;
47974+
47975+ if (match && !match->deleted)
47976+ return match;
47977+ else
47978+ return NULL;
47979+}
47980+
47981+static struct inodev_entry *
47982+lookup_inodev_entry(const ino_t ino, const dev_t dev)
47983+{
47984+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
47985+ struct inodev_entry *match;
47986+
47987+ match = inodev_set.i_hash[index];
47988+
47989+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
47990+ match = match->next;
47991+
47992+ return match;
47993+}
47994+
47995+static void
47996+insert_inodev_entry(struct inodev_entry *entry)
47997+{
47998+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
47999+ inodev_set.i_size);
48000+ struct inodev_entry **curr;
48001+
48002+ entry->prev = NULL;
48003+
48004+ curr = &inodev_set.i_hash[index];
48005+ if (*curr != NULL)
48006+ (*curr)->prev = entry;
48007+
48008+ entry->next = *curr;
48009+ *curr = entry;
48010+
48011+ return;
48012+}
48013+
48014+static void
48015+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
48016+{
48017+ unsigned int index =
48018+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
48019+ struct acl_role_label **curr;
48020+ struct acl_role_label *tmp;
48021+
48022+ curr = &acl_role_set.r_hash[index];
48023+
48024+ /* if role was already inserted due to domains and already has
48025+ a role in the same bucket as it attached, then we need to
48026+ combine these two buckets
48027+ */
48028+ if (role->next) {
48029+ tmp = role->next;
48030+ while (tmp->next)
48031+ tmp = tmp->next;
48032+ tmp->next = *curr;
48033+ } else
48034+ role->next = *curr;
48035+ *curr = role;
48036+
48037+ return;
48038+}
48039+
48040+static void
48041+insert_acl_role_label(struct acl_role_label *role)
48042+{
48043+ int i;
48044+
48045+ if (role_list == NULL) {
48046+ role_list = role;
48047+ role->prev = NULL;
48048+ } else {
48049+ role->prev = role_list;
48050+ role_list = role;
48051+ }
48052+
48053+ /* used for hash chains */
48054+ role->next = NULL;
48055+
48056+ if (role->roletype & GR_ROLE_DOMAIN) {
48057+ for (i = 0; i < role->domain_child_num; i++)
48058+ __insert_acl_role_label(role, role->domain_children[i]);
48059+ } else
48060+ __insert_acl_role_label(role, role->uidgid);
48061+}
48062+
48063+static int
48064+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
48065+{
48066+ struct name_entry **curr, *nentry;
48067+ struct inodev_entry *ientry;
48068+ unsigned int len = strlen(name);
48069+ unsigned int key = full_name_hash(name, len);
48070+ unsigned int index = key % name_set.n_size;
48071+
48072+ curr = &name_set.n_hash[index];
48073+
48074+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
48075+ curr = &((*curr)->next);
48076+
48077+ if (*curr != NULL)
48078+ return 1;
48079+
48080+ nentry = acl_alloc(sizeof (struct name_entry));
48081+ if (nentry == NULL)
48082+ return 0;
48083+ ientry = acl_alloc(sizeof (struct inodev_entry));
48084+ if (ientry == NULL)
48085+ return 0;
48086+ ientry->nentry = nentry;
48087+
48088+ nentry->key = key;
48089+ nentry->name = name;
48090+ nentry->inode = inode;
48091+ nentry->device = device;
48092+ nentry->len = len;
48093+ nentry->deleted = deleted;
48094+
48095+ nentry->prev = NULL;
48096+ curr = &name_set.n_hash[index];
48097+ if (*curr != NULL)
48098+ (*curr)->prev = nentry;
48099+ nentry->next = *curr;
48100+ *curr = nentry;
48101+
48102+ /* insert us into the table searchable by inode/dev */
48103+ insert_inodev_entry(ientry);
48104+
48105+ return 1;
48106+}
48107+
48108+static void
48109+insert_acl_obj_label(struct acl_object_label *obj,
48110+ struct acl_subject_label *subj)
48111+{
48112+ unsigned int index =
48113+ fhash(obj->inode, obj->device, subj->obj_hash_size);
48114+ struct acl_object_label **curr;
48115+
48116+
48117+ obj->prev = NULL;
48118+
48119+ curr = &subj->obj_hash[index];
48120+ if (*curr != NULL)
48121+ (*curr)->prev = obj;
48122+
48123+ obj->next = *curr;
48124+ *curr = obj;
48125+
48126+ return;
48127+}
48128+
48129+static void
48130+insert_acl_subj_label(struct acl_subject_label *obj,
48131+ struct acl_role_label *role)
48132+{
48133+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
48134+ struct acl_subject_label **curr;
48135+
48136+ obj->prev = NULL;
48137+
48138+ curr = &role->subj_hash[index];
48139+ if (*curr != NULL)
48140+ (*curr)->prev = obj;
48141+
48142+ obj->next = *curr;
48143+ *curr = obj;
48144+
48145+ return;
48146+}
48147+
48148+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
48149+
48150+static void *
48151+create_table(__u32 * len, int elementsize)
48152+{
48153+ unsigned int table_sizes[] = {
48154+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
48155+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
48156+ 4194301, 8388593, 16777213, 33554393, 67108859
48157+ };
48158+ void *newtable = NULL;
48159+ unsigned int pwr = 0;
48160+
48161+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
48162+ table_sizes[pwr] <= *len)
48163+ pwr++;
48164+
48165+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
48166+ return newtable;
48167+
48168+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
48169+ newtable =
48170+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
48171+ else
48172+ newtable = vmalloc(table_sizes[pwr] * elementsize);
48173+
48174+ *len = table_sizes[pwr];
48175+
48176+ return newtable;
48177+}
48178+
48179+static int
48180+init_variables(const struct gr_arg *arg)
48181+{
48182+ struct task_struct *reaper = &init_task;
48183+ unsigned int stacksize;
48184+
48185+ subj_map_set.s_size = arg->role_db.num_subjects;
48186+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
48187+ name_set.n_size = arg->role_db.num_objects;
48188+ inodev_set.i_size = arg->role_db.num_objects;
48189+
48190+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
48191+ !name_set.n_size || !inodev_set.i_size)
48192+ return 1;
48193+
48194+ if (!gr_init_uidset())
48195+ return 1;
48196+
48197+ /* set up the stack that holds allocation info */
48198+
48199+ stacksize = arg->role_db.num_pointers + 5;
48200+
48201+ if (!acl_alloc_stack_init(stacksize))
48202+ return 1;
48203+
48204+ /* grab reference for the real root dentry and vfsmount */
48205+ read_lock(&reaper->fs->lock);
48206+ real_root = dget(reaper->fs->root.dentry);
48207+ real_root_mnt = mntget(reaper->fs->root.mnt);
48208+ read_unlock(&reaper->fs->lock);
48209+
48210+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
48211+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
48212+#endif
48213+
48214+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
48215+ if (fakefs_obj_rw == NULL)
48216+ return 1;
48217+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
48218+
48219+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
48220+ if (fakefs_obj_rwx == NULL)
48221+ return 1;
48222+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
48223+
48224+ subj_map_set.s_hash =
48225+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
48226+ acl_role_set.r_hash =
48227+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
48228+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
48229+ inodev_set.i_hash =
48230+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
48231+
48232+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
48233+ !name_set.n_hash || !inodev_set.i_hash)
48234+ return 1;
48235+
48236+ memset(subj_map_set.s_hash, 0,
48237+ sizeof(struct subject_map *) * subj_map_set.s_size);
48238+ memset(acl_role_set.r_hash, 0,
48239+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
48240+ memset(name_set.n_hash, 0,
48241+ sizeof (struct name_entry *) * name_set.n_size);
48242+ memset(inodev_set.i_hash, 0,
48243+ sizeof (struct inodev_entry *) * inodev_set.i_size);
48244+
48245+ return 0;
48246+}
48247+
48248+/* free information not needed after startup
48249+ currently contains user->kernel pointer mappings for subjects
48250+*/
48251+
48252+static void
48253+free_init_variables(void)
48254+{
48255+ __u32 i;
48256+
48257+ if (subj_map_set.s_hash) {
48258+ for (i = 0; i < subj_map_set.s_size; i++) {
48259+ if (subj_map_set.s_hash[i]) {
48260+ kfree(subj_map_set.s_hash[i]);
48261+ subj_map_set.s_hash[i] = NULL;
48262+ }
48263+ }
48264+
48265+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
48266+ PAGE_SIZE)
48267+ kfree(subj_map_set.s_hash);
48268+ else
48269+ vfree(subj_map_set.s_hash);
48270+ }
48271+
48272+ return;
48273+}
48274+
48275+static void
48276+free_variables(void)
48277+{
48278+ struct acl_subject_label *s;
48279+ struct acl_role_label *r;
48280+ struct task_struct *task, *task2;
48281+ unsigned int x;
48282+
48283+ gr_clear_learn_entries();
48284+
48285+ read_lock(&tasklist_lock);
48286+ do_each_thread(task2, task) {
48287+ task->acl_sp_role = 0;
48288+ task->acl_role_id = 0;
48289+ task->acl = NULL;
48290+ task->role = NULL;
48291+ } while_each_thread(task2, task);
48292+ read_unlock(&tasklist_lock);
48293+
48294+ /* release the reference to the real root dentry and vfsmount */
48295+ if (real_root)
48296+ dput(real_root);
48297+ real_root = NULL;
48298+ if (real_root_mnt)
48299+ mntput(real_root_mnt);
48300+ real_root_mnt = NULL;
48301+
48302+ /* free all object hash tables */
48303+
48304+ FOR_EACH_ROLE_START(r)
48305+ if (r->subj_hash == NULL)
48306+ goto next_role;
48307+ FOR_EACH_SUBJECT_START(r, s, x)
48308+ if (s->obj_hash == NULL)
48309+ break;
48310+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
48311+ kfree(s->obj_hash);
48312+ else
48313+ vfree(s->obj_hash);
48314+ FOR_EACH_SUBJECT_END(s, x)
48315+ FOR_EACH_NESTED_SUBJECT_START(r, s)
48316+ if (s->obj_hash == NULL)
48317+ break;
48318+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
48319+ kfree(s->obj_hash);
48320+ else
48321+ vfree(s->obj_hash);
48322+ FOR_EACH_NESTED_SUBJECT_END(s)
48323+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
48324+ kfree(r->subj_hash);
48325+ else
48326+ vfree(r->subj_hash);
48327+ r->subj_hash = NULL;
48328+next_role:
48329+ FOR_EACH_ROLE_END(r)
48330+
48331+ acl_free_all();
48332+
48333+ if (acl_role_set.r_hash) {
48334+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
48335+ PAGE_SIZE)
48336+ kfree(acl_role_set.r_hash);
48337+ else
48338+ vfree(acl_role_set.r_hash);
48339+ }
48340+ if (name_set.n_hash) {
48341+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
48342+ PAGE_SIZE)
48343+ kfree(name_set.n_hash);
48344+ else
48345+ vfree(name_set.n_hash);
48346+ }
48347+
48348+ if (inodev_set.i_hash) {
48349+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
48350+ PAGE_SIZE)
48351+ kfree(inodev_set.i_hash);
48352+ else
48353+ vfree(inodev_set.i_hash);
48354+ }
48355+
48356+ gr_free_uidset();
48357+
48358+ memset(&name_set, 0, sizeof (struct name_db));
48359+ memset(&inodev_set, 0, sizeof (struct inodev_db));
48360+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
48361+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
48362+
48363+ default_role = NULL;
48364+ role_list = NULL;
48365+
48366+ return;
48367+}
48368+
48369+static __u32
48370+count_user_objs(struct acl_object_label *userp)
48371+{
48372+ struct acl_object_label o_tmp;
48373+ __u32 num = 0;
48374+
48375+ while (userp) {
48376+ if (copy_from_user(&o_tmp, userp,
48377+ sizeof (struct acl_object_label)))
48378+ break;
48379+
48380+ userp = o_tmp.prev;
48381+ num++;
48382+ }
48383+
48384+ return num;
48385+}
48386+
48387+static struct acl_subject_label *
48388+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
48389+
48390+static int
48391+copy_user_glob(struct acl_object_label *obj)
48392+{
48393+ struct acl_object_label *g_tmp, **guser;
48394+ unsigned int len;
48395+ char *tmp;
48396+
48397+ if (obj->globbed == NULL)
48398+ return 0;
48399+
48400+ guser = &obj->globbed;
48401+ while (*guser) {
48402+ g_tmp = (struct acl_object_label *)
48403+ acl_alloc(sizeof (struct acl_object_label));
48404+ if (g_tmp == NULL)
48405+ return -ENOMEM;
48406+
48407+ if (copy_from_user(g_tmp, *guser,
48408+ sizeof (struct acl_object_label)))
48409+ return -EFAULT;
48410+
48411+ len = strnlen_user(g_tmp->filename, PATH_MAX);
48412+
48413+ if (!len || len >= PATH_MAX)
48414+ return -EINVAL;
48415+
48416+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48417+ return -ENOMEM;
48418+
48419+ if (copy_from_user(tmp, g_tmp->filename, len))
48420+ return -EFAULT;
48421+ tmp[len-1] = '\0';
48422+ g_tmp->filename = tmp;
48423+
48424+ *guser = g_tmp;
48425+ guser = &(g_tmp->next);
48426+ }
48427+
48428+ return 0;
48429+}
48430+
48431+static int
48432+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
48433+ struct acl_role_label *role)
48434+{
48435+ struct acl_object_label *o_tmp;
48436+ unsigned int len;
48437+ int ret;
48438+ char *tmp;
48439+
48440+ while (userp) {
48441+ if ((o_tmp = (struct acl_object_label *)
48442+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
48443+ return -ENOMEM;
48444+
48445+ if (copy_from_user(o_tmp, userp,
48446+ sizeof (struct acl_object_label)))
48447+ return -EFAULT;
48448+
48449+ userp = o_tmp->prev;
48450+
48451+ len = strnlen_user(o_tmp->filename, PATH_MAX);
48452+
48453+ if (!len || len >= PATH_MAX)
48454+ return -EINVAL;
48455+
48456+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48457+ return -ENOMEM;
48458+
48459+ if (copy_from_user(tmp, o_tmp->filename, len))
48460+ return -EFAULT;
48461+ tmp[len-1] = '\0';
48462+ o_tmp->filename = tmp;
48463+
48464+ insert_acl_obj_label(o_tmp, subj);
48465+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
48466+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
48467+ return -ENOMEM;
48468+
48469+ ret = copy_user_glob(o_tmp);
48470+ if (ret)
48471+ return ret;
48472+
48473+ if (o_tmp->nested) {
48474+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
48475+ if (IS_ERR(o_tmp->nested))
48476+ return PTR_ERR(o_tmp->nested);
48477+
48478+ /* insert into nested subject list */
48479+ o_tmp->nested->next = role->hash->first;
48480+ role->hash->first = o_tmp->nested;
48481+ }
48482+ }
48483+
48484+ return 0;
48485+}
48486+
48487+static __u32
48488+count_user_subjs(struct acl_subject_label *userp)
48489+{
48490+ struct acl_subject_label s_tmp;
48491+ __u32 num = 0;
48492+
48493+ while (userp) {
48494+ if (copy_from_user(&s_tmp, userp,
48495+ sizeof (struct acl_subject_label)))
48496+ break;
48497+
48498+ userp = s_tmp.prev;
48499+ /* do not count nested subjects against this count, since
48500+ they are not included in the hash table, but are
48501+ attached to objects. We have already counted
48502+ the subjects in userspace for the allocation
48503+ stack
48504+ */
48505+ if (!(s_tmp.mode & GR_NESTED))
48506+ num++;
48507+ }
48508+
48509+ return num;
48510+}
48511+
48512+static int
48513+copy_user_allowedips(struct acl_role_label *rolep)
48514+{
48515+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
48516+
48517+ ruserip = rolep->allowed_ips;
48518+
48519+ while (ruserip) {
48520+ rlast = rtmp;
48521+
48522+ if ((rtmp = (struct role_allowed_ip *)
48523+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
48524+ return -ENOMEM;
48525+
48526+ if (copy_from_user(rtmp, ruserip,
48527+ sizeof (struct role_allowed_ip)))
48528+ return -EFAULT;
48529+
48530+ ruserip = rtmp->prev;
48531+
48532+ if (!rlast) {
48533+ rtmp->prev = NULL;
48534+ rolep->allowed_ips = rtmp;
48535+ } else {
48536+ rlast->next = rtmp;
48537+ rtmp->prev = rlast;
48538+ }
48539+
48540+ if (!ruserip)
48541+ rtmp->next = NULL;
48542+ }
48543+
48544+ return 0;
48545+}
48546+
48547+static int
48548+copy_user_transitions(struct acl_role_label *rolep)
48549+{
48550+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
48551+
48552+ unsigned int len;
48553+ char *tmp;
48554+
48555+ rusertp = rolep->transitions;
48556+
48557+ while (rusertp) {
48558+ rlast = rtmp;
48559+
48560+ if ((rtmp = (struct role_transition *)
48561+ acl_alloc(sizeof (struct role_transition))) == NULL)
48562+ return -ENOMEM;
48563+
48564+ if (copy_from_user(rtmp, rusertp,
48565+ sizeof (struct role_transition)))
48566+ return -EFAULT;
48567+
48568+ rusertp = rtmp->prev;
48569+
48570+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
48571+
48572+ if (!len || len >= GR_SPROLE_LEN)
48573+ return -EINVAL;
48574+
48575+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48576+ return -ENOMEM;
48577+
48578+ if (copy_from_user(tmp, rtmp->rolename, len))
48579+ return -EFAULT;
48580+ tmp[len-1] = '\0';
48581+ rtmp->rolename = tmp;
48582+
48583+ if (!rlast) {
48584+ rtmp->prev = NULL;
48585+ rolep->transitions = rtmp;
48586+ } else {
48587+ rlast->next = rtmp;
48588+ rtmp->prev = rlast;
48589+ }
48590+
48591+ if (!rusertp)
48592+ rtmp->next = NULL;
48593+ }
48594+
48595+ return 0;
48596+}
48597+
48598+static struct acl_subject_label *
48599+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
48600+{
48601+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
48602+ unsigned int len;
48603+ char *tmp;
48604+ __u32 num_objs;
48605+ struct acl_ip_label **i_tmp, *i_utmp2;
48606+ struct gr_hash_struct ghash;
48607+ struct subject_map *subjmap;
48608+ unsigned int i_num;
48609+ int err;
48610+
48611+ s_tmp = lookup_subject_map(userp);
48612+
48613+ /* we've already copied this subject into the kernel, just return
48614+ the reference to it, and don't copy it over again
48615+ */
48616+ if (s_tmp)
48617+ return(s_tmp);
48618+
48619+ if ((s_tmp = (struct acl_subject_label *)
48620+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
48621+ return ERR_PTR(-ENOMEM);
48622+
48623+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
48624+ if (subjmap == NULL)
48625+ return ERR_PTR(-ENOMEM);
48626+
48627+ subjmap->user = userp;
48628+ subjmap->kernel = s_tmp;
48629+ insert_subj_map_entry(subjmap);
48630+
48631+ if (copy_from_user(s_tmp, userp,
48632+ sizeof (struct acl_subject_label)))
48633+ return ERR_PTR(-EFAULT);
48634+
48635+ len = strnlen_user(s_tmp->filename, PATH_MAX);
48636+
48637+ if (!len || len >= PATH_MAX)
48638+ return ERR_PTR(-EINVAL);
48639+
48640+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48641+ return ERR_PTR(-ENOMEM);
48642+
48643+ if (copy_from_user(tmp, s_tmp->filename, len))
48644+ return ERR_PTR(-EFAULT);
48645+ tmp[len-1] = '\0';
48646+ s_tmp->filename = tmp;
48647+
48648+ if (!strcmp(s_tmp->filename, "/"))
48649+ role->root_label = s_tmp;
48650+
48651+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
48652+ return ERR_PTR(-EFAULT);
48653+
48654+ /* copy user and group transition tables */
48655+
48656+ if (s_tmp->user_trans_num) {
48657+ uid_t *uidlist;
48658+
48659+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
48660+ if (uidlist == NULL)
48661+ return ERR_PTR(-ENOMEM);
48662+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
48663+ return ERR_PTR(-EFAULT);
48664+
48665+ s_tmp->user_transitions = uidlist;
48666+ }
48667+
48668+ if (s_tmp->group_trans_num) {
48669+ gid_t *gidlist;
48670+
48671+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
48672+ if (gidlist == NULL)
48673+ return ERR_PTR(-ENOMEM);
48674+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
48675+ return ERR_PTR(-EFAULT);
48676+
48677+ s_tmp->group_transitions = gidlist;
48678+ }
48679+
48680+ /* set up object hash table */
48681+ num_objs = count_user_objs(ghash.first);
48682+
48683+ s_tmp->obj_hash_size = num_objs;
48684+ s_tmp->obj_hash =
48685+ (struct acl_object_label **)
48686+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
48687+
48688+ if (!s_tmp->obj_hash)
48689+ return ERR_PTR(-ENOMEM);
48690+
48691+ memset(s_tmp->obj_hash, 0,
48692+ s_tmp->obj_hash_size *
48693+ sizeof (struct acl_object_label *));
48694+
48695+ /* add in objects */
48696+ err = copy_user_objs(ghash.first, s_tmp, role);
48697+
48698+ if (err)
48699+ return ERR_PTR(err);
48700+
48701+ /* set pointer for parent subject */
48702+ if (s_tmp->parent_subject) {
48703+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
48704+
48705+ if (IS_ERR(s_tmp2))
48706+ return s_tmp2;
48707+
48708+ s_tmp->parent_subject = s_tmp2;
48709+ }
48710+
48711+ /* add in ip acls */
48712+
48713+ if (!s_tmp->ip_num) {
48714+ s_tmp->ips = NULL;
48715+ goto insert;
48716+ }
48717+
48718+ i_tmp =
48719+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
48720+ sizeof (struct acl_ip_label *));
48721+
48722+ if (!i_tmp)
48723+ return ERR_PTR(-ENOMEM);
48724+
48725+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
48726+ *(i_tmp + i_num) =
48727+ (struct acl_ip_label *)
48728+ acl_alloc(sizeof (struct acl_ip_label));
48729+ if (!*(i_tmp + i_num))
48730+ return ERR_PTR(-ENOMEM);
48731+
48732+ if (copy_from_user
48733+ (&i_utmp2, s_tmp->ips + i_num,
48734+ sizeof (struct acl_ip_label *)))
48735+ return ERR_PTR(-EFAULT);
48736+
48737+ if (copy_from_user
48738+ (*(i_tmp + i_num), i_utmp2,
48739+ sizeof (struct acl_ip_label)))
48740+ return ERR_PTR(-EFAULT);
48741+
48742+ if ((*(i_tmp + i_num))->iface == NULL)
48743+ continue;
48744+
48745+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
48746+ if (!len || len >= IFNAMSIZ)
48747+ return ERR_PTR(-EINVAL);
48748+ tmp = acl_alloc(len);
48749+ if (tmp == NULL)
48750+ return ERR_PTR(-ENOMEM);
48751+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
48752+ return ERR_PTR(-EFAULT);
48753+ (*(i_tmp + i_num))->iface = tmp;
48754+ }
48755+
48756+ s_tmp->ips = i_tmp;
48757+
48758+insert:
48759+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
48760+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
48761+ return ERR_PTR(-ENOMEM);
48762+
48763+ return s_tmp;
48764+}
48765+
48766+static int
48767+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
48768+{
48769+ struct acl_subject_label s_pre;
48770+ struct acl_subject_label * ret;
48771+ int err;
48772+
48773+ while (userp) {
48774+ if (copy_from_user(&s_pre, userp,
48775+ sizeof (struct acl_subject_label)))
48776+ return -EFAULT;
48777+
48778+ /* do not add nested subjects here, add
48779+ while parsing objects
48780+ */
48781+
48782+ if (s_pre.mode & GR_NESTED) {
48783+ userp = s_pre.prev;
48784+ continue;
48785+ }
48786+
48787+ ret = do_copy_user_subj(userp, role);
48788+
48789+ err = PTR_ERR(ret);
48790+ if (IS_ERR(ret))
48791+ return err;
48792+
48793+ insert_acl_subj_label(ret, role);
48794+
48795+ userp = s_pre.prev;
48796+ }
48797+
48798+ return 0;
48799+}
48800+
48801+static int
48802+copy_user_acl(struct gr_arg *arg)
48803+{
48804+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
48805+ struct sprole_pw *sptmp;
48806+ struct gr_hash_struct *ghash;
48807+ uid_t *domainlist;
48808+ unsigned int r_num;
48809+ unsigned int len;
48810+ char *tmp;
48811+ int err = 0;
48812+ __u16 i;
48813+ __u32 num_subjs;
48814+
48815+ /* we need a default and kernel role */
48816+ if (arg->role_db.num_roles < 2)
48817+ return -EINVAL;
48818+
48819+ /* copy special role authentication info from userspace */
48820+
48821+ num_sprole_pws = arg->num_sprole_pws;
48822+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
48823+
48824+ if (!acl_special_roles) {
48825+ err = -ENOMEM;
48826+ goto cleanup;
48827+ }
48828+
48829+ for (i = 0; i < num_sprole_pws; i++) {
48830+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
48831+ if (!sptmp) {
48832+ err = -ENOMEM;
48833+ goto cleanup;
48834+ }
48835+ if (copy_from_user(sptmp, arg->sprole_pws + i,
48836+ sizeof (struct sprole_pw))) {
48837+ err = -EFAULT;
48838+ goto cleanup;
48839+ }
48840+
48841+ len =
48842+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
48843+
48844+ if (!len || len >= GR_SPROLE_LEN) {
48845+ err = -EINVAL;
48846+ goto cleanup;
48847+ }
48848+
48849+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
48850+ err = -ENOMEM;
48851+ goto cleanup;
48852+ }
48853+
48854+ if (copy_from_user(tmp, sptmp->rolename, len)) {
48855+ err = -EFAULT;
48856+ goto cleanup;
48857+ }
48858+ tmp[len-1] = '\0';
48859+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
48860+ printk(KERN_ALERT "Copying special role %s\n", tmp);
48861+#endif
48862+ sptmp->rolename = tmp;
48863+ acl_special_roles[i] = sptmp;
48864+ }
48865+
48866+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
48867+
48868+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
48869+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
48870+
48871+ if (!r_tmp) {
48872+ err = -ENOMEM;
48873+ goto cleanup;
48874+ }
48875+
48876+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
48877+ sizeof (struct acl_role_label *))) {
48878+ err = -EFAULT;
48879+ goto cleanup;
48880+ }
48881+
48882+ if (copy_from_user(r_tmp, r_utmp2,
48883+ sizeof (struct acl_role_label))) {
48884+ err = -EFAULT;
48885+ goto cleanup;
48886+ }
48887+
48888+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
48889+
48890+ if (!len || len >= PATH_MAX) {
48891+ err = -EINVAL;
48892+ goto cleanup;
48893+ }
48894+
48895+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
48896+ err = -ENOMEM;
48897+ goto cleanup;
48898+ }
48899+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
48900+ err = -EFAULT;
48901+ goto cleanup;
48902+ }
48903+ tmp[len-1] = '\0';
48904+ r_tmp->rolename = tmp;
48905+
48906+ if (!strcmp(r_tmp->rolename, "default")
48907+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
48908+ default_role = r_tmp;
48909+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
48910+ kernel_role = r_tmp;
48911+ }
48912+
48913+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
48914+ err = -ENOMEM;
48915+ goto cleanup;
48916+ }
48917+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
48918+ err = -EFAULT;
48919+ goto cleanup;
48920+ }
48921+
48922+ r_tmp->hash = ghash;
48923+
48924+ num_subjs = count_user_subjs(r_tmp->hash->first);
48925+
48926+ r_tmp->subj_hash_size = num_subjs;
48927+ r_tmp->subj_hash =
48928+ (struct acl_subject_label **)
48929+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
48930+
48931+ if (!r_tmp->subj_hash) {
48932+ err = -ENOMEM;
48933+ goto cleanup;
48934+ }
48935+
48936+ err = copy_user_allowedips(r_tmp);
48937+ if (err)
48938+ goto cleanup;
48939+
48940+ /* copy domain info */
48941+ if (r_tmp->domain_children != NULL) {
48942+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
48943+ if (domainlist == NULL) {
48944+ err = -ENOMEM;
48945+ goto cleanup;
48946+ }
48947+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
48948+ err = -EFAULT;
48949+ goto cleanup;
48950+ }
48951+ r_tmp->domain_children = domainlist;
48952+ }
48953+
48954+ err = copy_user_transitions(r_tmp);
48955+ if (err)
48956+ goto cleanup;
48957+
48958+ memset(r_tmp->subj_hash, 0,
48959+ r_tmp->subj_hash_size *
48960+ sizeof (struct acl_subject_label *));
48961+
48962+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
48963+
48964+ if (err)
48965+ goto cleanup;
48966+
48967+ /* set nested subject list to null */
48968+ r_tmp->hash->first = NULL;
48969+
48970+ insert_acl_role_label(r_tmp);
48971+ }
48972+
48973+ goto return_err;
48974+ cleanup:
48975+ free_variables();
48976+ return_err:
48977+ return err;
48978+
48979+}
48980+
48981+static int
48982+gracl_init(struct gr_arg *args)
48983+{
48984+ int error = 0;
48985+
48986+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
48987+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
48988+
48989+ if (init_variables(args)) {
48990+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
48991+ error = -ENOMEM;
48992+ free_variables();
48993+ goto out;
48994+ }
48995+
48996+ error = copy_user_acl(args);
48997+ free_init_variables();
48998+ if (error) {
48999+ free_variables();
49000+ goto out;
49001+ }
49002+
49003+ if ((error = gr_set_acls(0))) {
49004+ free_variables();
49005+ goto out;
49006+ }
49007+
49008+ pax_open_kernel();
49009+ gr_status |= GR_READY;
49010+ pax_close_kernel();
49011+
49012+ out:
49013+ return error;
49014+}
49015+
49016+/* derived from glibc fnmatch() 0: match, 1: no match*/
49017+
49018+static int
49019+glob_match(const char *p, const char *n)
49020+{
49021+ char c;
49022+
49023+ while ((c = *p++) != '\0') {
49024+ switch (c) {
49025+ case '?':
49026+ if (*n == '\0')
49027+ return 1;
49028+ else if (*n == '/')
49029+ return 1;
49030+ break;
49031+ case '\\':
49032+ if (*n != c)
49033+ return 1;
49034+ break;
49035+ case '*':
49036+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
49037+ if (*n == '/')
49038+ return 1;
49039+ else if (c == '?') {
49040+ if (*n == '\0')
49041+ return 1;
49042+ else
49043+ ++n;
49044+ }
49045+ }
49046+ if (c == '\0') {
49047+ return 0;
49048+ } else {
49049+ const char *endp;
49050+
49051+ if ((endp = strchr(n, '/')) == NULL)
49052+ endp = n + strlen(n);
49053+
49054+ if (c == '[') {
49055+ for (--p; n < endp; ++n)
49056+ if (!glob_match(p, n))
49057+ return 0;
49058+ } else if (c == '/') {
49059+ while (*n != '\0' && *n != '/')
49060+ ++n;
49061+ if (*n == '/' && !glob_match(p, n + 1))
49062+ return 0;
49063+ } else {
49064+ for (--p; n < endp; ++n)
49065+ if (*n == c && !glob_match(p, n))
49066+ return 0;
49067+ }
49068+
49069+ return 1;
49070+ }
49071+ case '[':
49072+ {
49073+ int not;
49074+ char cold;
49075+
49076+ if (*n == '\0' || *n == '/')
49077+ return 1;
49078+
49079+ not = (*p == '!' || *p == '^');
49080+ if (not)
49081+ ++p;
49082+
49083+ c = *p++;
49084+ for (;;) {
49085+ unsigned char fn = (unsigned char)*n;
49086+
49087+ if (c == '\0')
49088+ return 1;
49089+ else {
49090+ if (c == fn)
49091+ goto matched;
49092+ cold = c;
49093+ c = *p++;
49094+
49095+ if (c == '-' && *p != ']') {
49096+ unsigned char cend = *p++;
49097+
49098+ if (cend == '\0')
49099+ return 1;
49100+
49101+ if (cold <= fn && fn <= cend)
49102+ goto matched;
49103+
49104+ c = *p++;
49105+ }
49106+ }
49107+
49108+ if (c == ']')
49109+ break;
49110+ }
49111+ if (!not)
49112+ return 1;
49113+ break;
49114+ matched:
49115+ while (c != ']') {
49116+ if (c == '\0')
49117+ return 1;
49118+
49119+ c = *p++;
49120+ }
49121+ if (not)
49122+ return 1;
49123+ }
49124+ break;
49125+ default:
49126+ if (c != *n)
49127+ return 1;
49128+ }
49129+
49130+ ++n;
49131+ }
49132+
49133+ if (*n == '\0')
49134+ return 0;
49135+
49136+ if (*n == '/')
49137+ return 0;
49138+
49139+ return 1;
49140+}
49141+
49142+static struct acl_object_label *
49143+chk_glob_label(struct acl_object_label *globbed,
49144+ struct dentry *dentry, struct vfsmount *mnt, char **path)
49145+{
49146+ struct acl_object_label *tmp;
49147+
49148+ if (*path == NULL)
49149+ *path = gr_to_filename_nolock(dentry, mnt);
49150+
49151+ tmp = globbed;
49152+
49153+ while (tmp) {
49154+ if (!glob_match(tmp->filename, *path))
49155+ return tmp;
49156+ tmp = tmp->next;
49157+ }
49158+
49159+ return NULL;
49160+}
49161+
49162+static struct acl_object_label *
49163+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
49164+ const ino_t curr_ino, const dev_t curr_dev,
49165+ const struct acl_subject_label *subj, char **path, const int checkglob)
49166+{
49167+ struct acl_subject_label *tmpsubj;
49168+ struct acl_object_label *retval;
49169+ struct acl_object_label *retval2;
49170+
49171+ tmpsubj = (struct acl_subject_label *) subj;
49172+ read_lock(&gr_inode_lock);
49173+ do {
49174+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
49175+ if (retval) {
49176+ if (checkglob && retval->globbed) {
49177+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
49178+ (struct vfsmount *)orig_mnt, path);
49179+ if (retval2)
49180+ retval = retval2;
49181+ }
49182+ break;
49183+ }
49184+ } while ((tmpsubj = tmpsubj->parent_subject));
49185+ read_unlock(&gr_inode_lock);
49186+
49187+ return retval;
49188+}
49189+
49190+static __inline__ struct acl_object_label *
49191+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
49192+ const struct dentry *curr_dentry,
49193+ const struct acl_subject_label *subj, char **path, const int checkglob)
49194+{
49195+ int newglob = checkglob;
49196+
49197+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
49198+ as we don't want a / * rule to match instead of the / object
49199+ don't do this for create lookups that call this function though, since they're looking up
49200+ on the parent and thus need globbing checks on all paths
49201+ */
49202+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
49203+ newglob = GR_NO_GLOB;
49204+
49205+ return __full_lookup(orig_dentry, orig_mnt,
49206+ curr_dentry->d_inode->i_ino,
49207+ __get_dev(curr_dentry), subj, path, newglob);
49208+}
49209+
49210+static struct acl_object_label *
49211+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
49212+ const struct acl_subject_label *subj, char *path, const int checkglob)
49213+{
49214+ struct dentry *dentry = (struct dentry *) l_dentry;
49215+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
49216+ struct acl_object_label *retval;
49217+
49218+ spin_lock(&dcache_lock);
49219+ spin_lock(&vfsmount_lock);
49220+
49221+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
49222+#ifdef CONFIG_NET
49223+ mnt == sock_mnt ||
49224+#endif
49225+#ifdef CONFIG_HUGETLBFS
49226+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
49227+#endif
49228+ /* ignore Eric Biederman */
49229+ IS_PRIVATE(l_dentry->d_inode))) {
49230+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
49231+ goto out;
49232+ }
49233+
49234+ for (;;) {
49235+ if (dentry == real_root && mnt == real_root_mnt)
49236+ break;
49237+
49238+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
49239+ if (mnt->mnt_parent == mnt)
49240+ break;
49241+
49242+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
49243+ if (retval != NULL)
49244+ goto out;
49245+
49246+ dentry = mnt->mnt_mountpoint;
49247+ mnt = mnt->mnt_parent;
49248+ continue;
49249+ }
49250+
49251+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
49252+ if (retval != NULL)
49253+ goto out;
49254+
49255+ dentry = dentry->d_parent;
49256+ }
49257+
49258+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
49259+
49260+ if (retval == NULL)
49261+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
49262+out:
49263+ spin_unlock(&vfsmount_lock);
49264+ spin_unlock(&dcache_lock);
49265+
49266+ BUG_ON(retval == NULL);
49267+
49268+ return retval;
49269+}
49270+
49271+static __inline__ struct acl_object_label *
49272+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
49273+ const struct acl_subject_label *subj)
49274+{
49275+ char *path = NULL;
49276+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
49277+}
49278+
49279+static __inline__ struct acl_object_label *
49280+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
49281+ const struct acl_subject_label *subj)
49282+{
49283+ char *path = NULL;
49284+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
49285+}
49286+
49287+static __inline__ struct acl_object_label *
49288+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
49289+ const struct acl_subject_label *subj, char *path)
49290+{
49291+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
49292+}
49293+
49294+static struct acl_subject_label *
49295+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
49296+ const struct acl_role_label *role)
49297+{
49298+ struct dentry *dentry = (struct dentry *) l_dentry;
49299+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
49300+ struct acl_subject_label *retval;
49301+
49302+ spin_lock(&dcache_lock);
49303+ spin_lock(&vfsmount_lock);
49304+
49305+ for (;;) {
49306+ if (dentry == real_root && mnt == real_root_mnt)
49307+ break;
49308+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
49309+ if (mnt->mnt_parent == mnt)
49310+ break;
49311+
49312+ read_lock(&gr_inode_lock);
49313+ retval =
49314+ lookup_acl_subj_label(dentry->d_inode->i_ino,
49315+ __get_dev(dentry), role);
49316+ read_unlock(&gr_inode_lock);
49317+ if (retval != NULL)
49318+ goto out;
49319+
49320+ dentry = mnt->mnt_mountpoint;
49321+ mnt = mnt->mnt_parent;
49322+ continue;
49323+ }
49324+
49325+ read_lock(&gr_inode_lock);
49326+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
49327+ __get_dev(dentry), role);
49328+ read_unlock(&gr_inode_lock);
49329+ if (retval != NULL)
49330+ goto out;
49331+
49332+ dentry = dentry->d_parent;
49333+ }
49334+
49335+ read_lock(&gr_inode_lock);
49336+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
49337+ __get_dev(dentry), role);
49338+ read_unlock(&gr_inode_lock);
49339+
49340+ if (unlikely(retval == NULL)) {
49341+ read_lock(&gr_inode_lock);
49342+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
49343+ __get_dev(real_root), role);
49344+ read_unlock(&gr_inode_lock);
49345+ }
49346+out:
49347+ spin_unlock(&vfsmount_lock);
49348+ spin_unlock(&dcache_lock);
49349+
49350+ BUG_ON(retval == NULL);
49351+
49352+ return retval;
49353+}
49354+
49355+static void
49356+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
49357+{
49358+ struct task_struct *task = current;
49359+ const struct cred *cred = current_cred();
49360+
49361+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
49362+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
49363+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
49364+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
49365+
49366+ return;
49367+}
49368+
49369+static void
49370+gr_log_learn_sysctl(const char *path, const __u32 mode)
49371+{
49372+ struct task_struct *task = current;
49373+ const struct cred *cred = current_cred();
49374+
49375+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
49376+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
49377+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
49378+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
49379+
49380+ return;
49381+}
49382+
49383+static void
49384+gr_log_learn_id_change(const char type, const unsigned int real,
49385+ const unsigned int effective, const unsigned int fs)
49386+{
49387+ struct task_struct *task = current;
49388+ const struct cred *cred = current_cred();
49389+
49390+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
49391+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
49392+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
49393+ type, real, effective, fs, &task->signal->saved_ip);
49394+
49395+ return;
49396+}
49397+
49398+__u32
49399+gr_check_link(const struct dentry * new_dentry,
49400+ const struct dentry * parent_dentry,
49401+ const struct vfsmount * parent_mnt,
49402+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
49403+{
49404+ struct acl_object_label *obj;
49405+ __u32 oldmode, newmode;
49406+ __u32 needmode;
49407+
49408+ if (unlikely(!(gr_status & GR_READY)))
49409+ return (GR_CREATE | GR_LINK);
49410+
49411+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
49412+ oldmode = obj->mode;
49413+
49414+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
49415+ oldmode |= (GR_CREATE | GR_LINK);
49416+
49417+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
49418+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
49419+ needmode |= GR_SETID | GR_AUDIT_SETID;
49420+
49421+ newmode =
49422+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
49423+ oldmode | needmode);
49424+
49425+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
49426+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
49427+ GR_INHERIT | GR_AUDIT_INHERIT);
49428+
49429+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
49430+ goto bad;
49431+
49432+ if ((oldmode & needmode) != needmode)
49433+ goto bad;
49434+
49435+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
49436+ if ((newmode & needmode) != needmode)
49437+ goto bad;
49438+
49439+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
49440+ return newmode;
49441+bad:
49442+ needmode = oldmode;
49443+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
49444+ needmode |= GR_SETID;
49445+
49446+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
49447+ gr_log_learn(old_dentry, old_mnt, needmode);
49448+ return (GR_CREATE | GR_LINK);
49449+ } else if (newmode & GR_SUPPRESS)
49450+ return GR_SUPPRESS;
49451+ else
49452+ return 0;
49453+}
49454+
49455+__u32
49456+gr_search_file(const struct dentry * dentry, const __u32 mode,
49457+ const struct vfsmount * mnt)
49458+{
49459+ __u32 retval = mode;
49460+ struct acl_subject_label *curracl;
49461+ struct acl_object_label *currobj;
49462+
49463+ if (unlikely(!(gr_status & GR_READY)))
49464+ return (mode & ~GR_AUDITS);
49465+
49466+ curracl = current->acl;
49467+
49468+ currobj = chk_obj_label(dentry, mnt, curracl);
49469+ retval = currobj->mode & mode;
49470+
49471+ /* if we're opening a specified transfer file for writing
49472+ (e.g. /dev/initctl), then transfer our role to init
49473+ */
49474+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
49475+ current->role->roletype & GR_ROLE_PERSIST)) {
49476+ struct task_struct *task = init_pid_ns.child_reaper;
49477+
49478+ if (task->role != current->role) {
49479+ task->acl_sp_role = 0;
49480+ task->acl_role_id = current->acl_role_id;
49481+ task->role = current->role;
49482+ rcu_read_lock();
49483+ read_lock(&grsec_exec_file_lock);
49484+ gr_apply_subject_to_task(task);
49485+ read_unlock(&grsec_exec_file_lock);
49486+ rcu_read_unlock();
49487+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
49488+ }
49489+ }
49490+
49491+ if (unlikely
49492+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
49493+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
49494+ __u32 new_mode = mode;
49495+
49496+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
49497+
49498+ retval = new_mode;
49499+
49500+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
49501+ new_mode |= GR_INHERIT;
49502+
49503+ if (!(mode & GR_NOLEARN))
49504+ gr_log_learn(dentry, mnt, new_mode);
49505+ }
49506+
49507+ return retval;
49508+}
49509+
49510+__u32
49511+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
49512+ const struct vfsmount * mnt, const __u32 mode)
49513+{
49514+ struct name_entry *match;
49515+ struct acl_object_label *matchpo;
49516+ struct acl_subject_label *curracl;
49517+ char *path;
49518+ __u32 retval;
49519+
49520+ if (unlikely(!(gr_status & GR_READY)))
49521+ return (mode & ~GR_AUDITS);
49522+
49523+ preempt_disable();
49524+ path = gr_to_filename_rbac(new_dentry, mnt);
49525+ match = lookup_name_entry_create(path);
49526+
49527+ if (!match)
49528+ goto check_parent;
49529+
49530+ curracl = current->acl;
49531+
49532+ read_lock(&gr_inode_lock);
49533+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
49534+ read_unlock(&gr_inode_lock);
49535+
49536+ if (matchpo) {
49537+ if ((matchpo->mode & mode) !=
49538+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
49539+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
49540+ __u32 new_mode = mode;
49541+
49542+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
49543+
49544+ gr_log_learn(new_dentry, mnt, new_mode);
49545+
49546+ preempt_enable();
49547+ return new_mode;
49548+ }
49549+ preempt_enable();
49550+ return (matchpo->mode & mode);
49551+ }
49552+
49553+ check_parent:
49554+ curracl = current->acl;
49555+
49556+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
49557+ retval = matchpo->mode & mode;
49558+
49559+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
49560+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
49561+ __u32 new_mode = mode;
49562+
49563+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
49564+
49565+ gr_log_learn(new_dentry, mnt, new_mode);
49566+ preempt_enable();
49567+ return new_mode;
49568+ }
49569+
49570+ preempt_enable();
49571+ return retval;
49572+}
49573+
49574+int
49575+gr_check_hidden_task(const struct task_struct *task)
49576+{
49577+ if (unlikely(!(gr_status & GR_READY)))
49578+ return 0;
49579+
49580+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
49581+ return 1;
49582+
49583+ return 0;
49584+}
49585+
49586+int
49587+gr_check_protected_task(const struct task_struct *task)
49588+{
49589+ if (unlikely(!(gr_status & GR_READY) || !task))
49590+ return 0;
49591+
49592+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
49593+ task->acl != current->acl)
49594+ return 1;
49595+
49596+ return 0;
49597+}
49598+
49599+int
49600+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
49601+{
49602+ struct task_struct *p;
49603+ int ret = 0;
49604+
49605+ if (unlikely(!(gr_status & GR_READY) || !pid))
49606+ return ret;
49607+
49608+ read_lock(&tasklist_lock);
49609+ do_each_pid_task(pid, type, p) {
49610+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
49611+ p->acl != current->acl) {
49612+ ret = 1;
49613+ goto out;
49614+ }
49615+ } while_each_pid_task(pid, type, p);
49616+out:
49617+ read_unlock(&tasklist_lock);
49618+
49619+ return ret;
49620+}
49621+
49622+void
49623+gr_copy_label(struct task_struct *tsk)
49624+{
49625+ tsk->signal->used_accept = 0;
49626+ tsk->acl_sp_role = 0;
49627+ tsk->acl_role_id = current->acl_role_id;
49628+ tsk->acl = current->acl;
49629+ tsk->role = current->role;
49630+ tsk->signal->curr_ip = current->signal->curr_ip;
49631+ tsk->signal->saved_ip = current->signal->saved_ip;
49632+ if (current->exec_file)
49633+ get_file(current->exec_file);
49634+ tsk->exec_file = current->exec_file;
49635+ tsk->is_writable = current->is_writable;
49636+ if (unlikely(current->signal->used_accept)) {
49637+ current->signal->curr_ip = 0;
49638+ current->signal->saved_ip = 0;
49639+ }
49640+
49641+ return;
49642+}
49643+
49644+static void
49645+gr_set_proc_res(struct task_struct *task)
49646+{
49647+ struct acl_subject_label *proc;
49648+ unsigned short i;
49649+
49650+ proc = task->acl;
49651+
49652+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
49653+ return;
49654+
49655+ for (i = 0; i < RLIM_NLIMITS; i++) {
49656+ if (!(proc->resmask & (1 << i)))
49657+ continue;
49658+
49659+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
49660+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
49661+ }
49662+
49663+ return;
49664+}
49665+
49666+extern int __gr_process_user_ban(struct user_struct *user);
49667+
49668+int
49669+gr_check_user_change(int real, int effective, int fs)
49670+{
49671+ unsigned int i;
49672+ __u16 num;
49673+ uid_t *uidlist;
49674+ int curuid;
49675+ int realok = 0;
49676+ int effectiveok = 0;
49677+ int fsok = 0;
49678+
49679+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
49680+ struct user_struct *user;
49681+
49682+ if (real == -1)
49683+ goto skipit;
49684+
49685+ user = find_user(real);
49686+ if (user == NULL)
49687+ goto skipit;
49688+
49689+ if (__gr_process_user_ban(user)) {
49690+ /* for find_user */
49691+ free_uid(user);
49692+ return 1;
49693+ }
49694+
49695+ /* for find_user */
49696+ free_uid(user);
49697+
49698+skipit:
49699+#endif
49700+
49701+ if (unlikely(!(gr_status & GR_READY)))
49702+ return 0;
49703+
49704+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
49705+ gr_log_learn_id_change('u', real, effective, fs);
49706+
49707+ num = current->acl->user_trans_num;
49708+ uidlist = current->acl->user_transitions;
49709+
49710+ if (uidlist == NULL)
49711+ return 0;
49712+
49713+ if (real == -1)
49714+ realok = 1;
49715+ if (effective == -1)
49716+ effectiveok = 1;
49717+ if (fs == -1)
49718+ fsok = 1;
49719+
49720+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
49721+ for (i = 0; i < num; i++) {
49722+ curuid = (int)uidlist[i];
49723+ if (real == curuid)
49724+ realok = 1;
49725+ if (effective == curuid)
49726+ effectiveok = 1;
49727+ if (fs == curuid)
49728+ fsok = 1;
49729+ }
49730+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
49731+ for (i = 0; i < num; i++) {
49732+ curuid = (int)uidlist[i];
49733+ if (real == curuid)
49734+ break;
49735+ if (effective == curuid)
49736+ break;
49737+ if (fs == curuid)
49738+ break;
49739+ }
49740+ /* not in deny list */
49741+ if (i == num) {
49742+ realok = 1;
49743+ effectiveok = 1;
49744+ fsok = 1;
49745+ }
49746+ }
49747+
49748+ if (realok && effectiveok && fsok)
49749+ return 0;
49750+ else {
49751+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
49752+ return 1;
49753+ }
49754+}
49755+
49756+int
49757+gr_check_group_change(int real, int effective, int fs)
49758+{
49759+ unsigned int i;
49760+ __u16 num;
49761+ gid_t *gidlist;
49762+ int curgid;
49763+ int realok = 0;
49764+ int effectiveok = 0;
49765+ int fsok = 0;
49766+
49767+ if (unlikely(!(gr_status & GR_READY)))
49768+ return 0;
49769+
49770+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
49771+ gr_log_learn_id_change('g', real, effective, fs);
49772+
49773+ num = current->acl->group_trans_num;
49774+ gidlist = current->acl->group_transitions;
49775+
49776+ if (gidlist == NULL)
49777+ return 0;
49778+
49779+ if (real == -1)
49780+ realok = 1;
49781+ if (effective == -1)
49782+ effectiveok = 1;
49783+ if (fs == -1)
49784+ fsok = 1;
49785+
49786+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
49787+ for (i = 0; i < num; i++) {
49788+ curgid = (int)gidlist[i];
49789+ if (real == curgid)
49790+ realok = 1;
49791+ if (effective == curgid)
49792+ effectiveok = 1;
49793+ if (fs == curgid)
49794+ fsok = 1;
49795+ }
49796+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
49797+ for (i = 0; i < num; i++) {
49798+ curgid = (int)gidlist[i];
49799+ if (real == curgid)
49800+ break;
49801+ if (effective == curgid)
49802+ break;
49803+ if (fs == curgid)
49804+ break;
49805+ }
49806+ /* not in deny list */
49807+ if (i == num) {
49808+ realok = 1;
49809+ effectiveok = 1;
49810+ fsok = 1;
49811+ }
49812+ }
49813+
49814+ if (realok && effectiveok && fsok)
49815+ return 0;
49816+ else {
49817+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
49818+ return 1;
49819+ }
49820+}
49821+
49822+void
49823+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
49824+{
49825+ struct acl_role_label *role = task->role;
49826+ struct acl_subject_label *subj = NULL;
49827+ struct acl_object_label *obj;
49828+ struct file *filp;
49829+
49830+ if (unlikely(!(gr_status & GR_READY)))
49831+ return;
49832+
49833+ filp = task->exec_file;
49834+
49835+ /* kernel process, we'll give them the kernel role */
49836+ if (unlikely(!filp)) {
49837+ task->role = kernel_role;
49838+ task->acl = kernel_role->root_label;
49839+ return;
49840+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
49841+ role = lookup_acl_role_label(task, uid, gid);
49842+
49843+ /* perform subject lookup in possibly new role
49844+ we can use this result below in the case where role == task->role
49845+ */
49846+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
49847+
49848+ /* if we changed uid/gid, but result in the same role
49849+ and are using inheritance, don't lose the inherited subject
49850+ if current subject is other than what normal lookup
49851+ would result in, we arrived via inheritance, don't
49852+ lose subject
49853+ */
49854+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
49855+ (subj == task->acl)))
49856+ task->acl = subj;
49857+
49858+ task->role = role;
49859+
49860+ task->is_writable = 0;
49861+
49862+ /* ignore additional mmap checks for processes that are writable
49863+ by the default ACL */
49864+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
49865+ if (unlikely(obj->mode & GR_WRITE))
49866+ task->is_writable = 1;
49867+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
49868+ if (unlikely(obj->mode & GR_WRITE))
49869+ task->is_writable = 1;
49870+
49871+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49872+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
49873+#endif
49874+
49875+ gr_set_proc_res(task);
49876+
49877+ return;
49878+}
49879+
49880+int
49881+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
49882+ const int unsafe_share)
49883+{
49884+ struct task_struct *task = current;
49885+ struct acl_subject_label *newacl;
49886+ struct acl_object_label *obj;
49887+ __u32 retmode;
49888+
49889+ if (unlikely(!(gr_status & GR_READY)))
49890+ return 0;
49891+
49892+ newacl = chk_subj_label(dentry, mnt, task->role);
49893+
49894+ task_lock(task);
49895+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
49896+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
49897+ !(task->role->roletype & GR_ROLE_GOD) &&
49898+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
49899+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
49900+ task_unlock(task);
49901+ if (unsafe_share)
49902+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
49903+ else
49904+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
49905+ return -EACCES;
49906+ }
49907+ task_unlock(task);
49908+
49909+ obj = chk_obj_label(dentry, mnt, task->acl);
49910+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
49911+
49912+ if (!(task->acl->mode & GR_INHERITLEARN) &&
49913+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
49914+ if (obj->nested)
49915+ task->acl = obj->nested;
49916+ else
49917+ task->acl = newacl;
49918+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
49919+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
49920+
49921+ task->is_writable = 0;
49922+
49923+ /* ignore additional mmap checks for processes that are writable
49924+ by the default ACL */
49925+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
49926+ if (unlikely(obj->mode & GR_WRITE))
49927+ task->is_writable = 1;
49928+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
49929+ if (unlikely(obj->mode & GR_WRITE))
49930+ task->is_writable = 1;
49931+
49932+ gr_set_proc_res(task);
49933+
49934+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49935+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
49936+#endif
49937+ return 0;
49938+}
49939+
49940+/* always called with valid inodev ptr */
49941+static void
49942+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
49943+{
49944+ struct acl_object_label *matchpo;
49945+ struct acl_subject_label *matchps;
49946+ struct acl_subject_label *subj;
49947+ struct acl_role_label *role;
49948+ unsigned int x;
49949+
49950+ FOR_EACH_ROLE_START(role)
49951+ FOR_EACH_SUBJECT_START(role, subj, x)
49952+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
49953+ matchpo->mode |= GR_DELETED;
49954+ FOR_EACH_SUBJECT_END(subj,x)
49955+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
49956+ if (subj->inode == ino && subj->device == dev)
49957+ subj->mode |= GR_DELETED;
49958+ FOR_EACH_NESTED_SUBJECT_END(subj)
49959+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
49960+ matchps->mode |= GR_DELETED;
49961+ FOR_EACH_ROLE_END(role)
49962+
49963+ inodev->nentry->deleted = 1;
49964+
49965+ return;
49966+}
49967+
49968+void
49969+gr_handle_delete(const ino_t ino, const dev_t dev)
49970+{
49971+ struct inodev_entry *inodev;
49972+
49973+ if (unlikely(!(gr_status & GR_READY)))
49974+ return;
49975+
49976+ write_lock(&gr_inode_lock);
49977+ inodev = lookup_inodev_entry(ino, dev);
49978+ if (inodev != NULL)
49979+ do_handle_delete(inodev, ino, dev);
49980+ write_unlock(&gr_inode_lock);
49981+
49982+ return;
49983+}
49984+
49985+static void
49986+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
49987+ const ino_t newinode, const dev_t newdevice,
49988+ struct acl_subject_label *subj)
49989+{
49990+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
49991+ struct acl_object_label *match;
49992+
49993+ match = subj->obj_hash[index];
49994+
49995+ while (match && (match->inode != oldinode ||
49996+ match->device != olddevice ||
49997+ !(match->mode & GR_DELETED)))
49998+ match = match->next;
49999+
50000+ if (match && (match->inode == oldinode)
50001+ && (match->device == olddevice)
50002+ && (match->mode & GR_DELETED)) {
50003+ if (match->prev == NULL) {
50004+ subj->obj_hash[index] = match->next;
50005+ if (match->next != NULL)
50006+ match->next->prev = NULL;
50007+ } else {
50008+ match->prev->next = match->next;
50009+ if (match->next != NULL)
50010+ match->next->prev = match->prev;
50011+ }
50012+ match->prev = NULL;
50013+ match->next = NULL;
50014+ match->inode = newinode;
50015+ match->device = newdevice;
50016+ match->mode &= ~GR_DELETED;
50017+
50018+ insert_acl_obj_label(match, subj);
50019+ }
50020+
50021+ return;
50022+}
50023+
50024+static void
50025+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
50026+ const ino_t newinode, const dev_t newdevice,
50027+ struct acl_role_label *role)
50028+{
50029+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
50030+ struct acl_subject_label *match;
50031+
50032+ match = role->subj_hash[index];
50033+
50034+ while (match && (match->inode != oldinode ||
50035+ match->device != olddevice ||
50036+ !(match->mode & GR_DELETED)))
50037+ match = match->next;
50038+
50039+ if (match && (match->inode == oldinode)
50040+ && (match->device == olddevice)
50041+ && (match->mode & GR_DELETED)) {
50042+ if (match->prev == NULL) {
50043+ role->subj_hash[index] = match->next;
50044+ if (match->next != NULL)
50045+ match->next->prev = NULL;
50046+ } else {
50047+ match->prev->next = match->next;
50048+ if (match->next != NULL)
50049+ match->next->prev = match->prev;
50050+ }
50051+ match->prev = NULL;
50052+ match->next = NULL;
50053+ match->inode = newinode;
50054+ match->device = newdevice;
50055+ match->mode &= ~GR_DELETED;
50056+
50057+ insert_acl_subj_label(match, role);
50058+ }
50059+
50060+ return;
50061+}
50062+
50063+static void
50064+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
50065+ const ino_t newinode, const dev_t newdevice)
50066+{
50067+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
50068+ struct inodev_entry *match;
50069+
50070+ match = inodev_set.i_hash[index];
50071+
50072+ while (match && (match->nentry->inode != oldinode ||
50073+ match->nentry->device != olddevice || !match->nentry->deleted))
50074+ match = match->next;
50075+
50076+ if (match && (match->nentry->inode == oldinode)
50077+ && (match->nentry->device == olddevice) &&
50078+ match->nentry->deleted) {
50079+ if (match->prev == NULL) {
50080+ inodev_set.i_hash[index] = match->next;
50081+ if (match->next != NULL)
50082+ match->next->prev = NULL;
50083+ } else {
50084+ match->prev->next = match->next;
50085+ if (match->next != NULL)
50086+ match->next->prev = match->prev;
50087+ }
50088+ match->prev = NULL;
50089+ match->next = NULL;
50090+ match->nentry->inode = newinode;
50091+ match->nentry->device = newdevice;
50092+ match->nentry->deleted = 0;
50093+
50094+ insert_inodev_entry(match);
50095+ }
50096+
50097+ return;
50098+}
50099+
50100+static void
50101+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
50102+ const struct vfsmount *mnt)
50103+{
50104+ struct acl_subject_label *subj;
50105+ struct acl_role_label *role;
50106+ unsigned int x;
50107+ ino_t inode = dentry->d_inode->i_ino;
50108+ dev_t dev = __get_dev(dentry);
50109+
50110+ FOR_EACH_ROLE_START(role)
50111+ update_acl_subj_label(matchn->inode, matchn->device,
50112+ inode, dev, role);
50113+
50114+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
50115+ if ((subj->inode == inode) && (subj->device == dev)) {
50116+ subj->inode = inode;
50117+ subj->device = dev;
50118+ }
50119+ FOR_EACH_NESTED_SUBJECT_END(subj)
50120+ FOR_EACH_SUBJECT_START(role, subj, x)
50121+ update_acl_obj_label(matchn->inode, matchn->device,
50122+ inode, dev, subj);
50123+ FOR_EACH_SUBJECT_END(subj,x)
50124+ FOR_EACH_ROLE_END(role)
50125+
50126+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
50127+
50128+ return;
50129+}
50130+
50131+void
50132+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
50133+{
50134+ struct name_entry *matchn;
50135+
50136+ if (unlikely(!(gr_status & GR_READY)))
50137+ return;
50138+
50139+ preempt_disable();
50140+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
50141+
50142+ if (unlikely((unsigned long)matchn)) {
50143+ write_lock(&gr_inode_lock);
50144+ do_handle_create(matchn, dentry, mnt);
50145+ write_unlock(&gr_inode_lock);
50146+ }
50147+ preempt_enable();
50148+
50149+ return;
50150+}
50151+
50152+void
50153+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
50154+ struct dentry *old_dentry,
50155+ struct dentry *new_dentry,
50156+ struct vfsmount *mnt, const __u8 replace)
50157+{
50158+ struct name_entry *matchn;
50159+ struct inodev_entry *inodev;
50160+ ino_t oldinode = old_dentry->d_inode->i_ino;
50161+ dev_t olddev = __get_dev(old_dentry);
50162+
50163+ /* vfs_rename swaps the name and parent link for old_dentry and
50164+ new_dentry
50165+ at this point, old_dentry has the new name, parent link, and inode
50166+ for the renamed file
50167+ if a file is being replaced by a rename, new_dentry has the inode
50168+ and name for the replaced file
50169+ */
50170+
50171+ if (unlikely(!(gr_status & GR_READY)))
50172+ return;
50173+
50174+ preempt_disable();
50175+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
50176+
50177+ /* we wouldn't have to check d_inode if it weren't for
50178+ NFS silly-renaming
50179+ */
50180+
50181+ write_lock(&gr_inode_lock);
50182+ if (unlikely(replace && new_dentry->d_inode)) {
50183+ ino_t newinode = new_dentry->d_inode->i_ino;
50184+ dev_t newdev = __get_dev(new_dentry);
50185+ inodev = lookup_inodev_entry(newinode, newdev);
50186+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
50187+ do_handle_delete(inodev, newinode, newdev);
50188+ }
50189+
50190+ inodev = lookup_inodev_entry(oldinode, olddev);
50191+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
50192+ do_handle_delete(inodev, oldinode, olddev);
50193+
50194+ if (unlikely((unsigned long)matchn))
50195+ do_handle_create(matchn, old_dentry, mnt);
50196+
50197+ write_unlock(&gr_inode_lock);
50198+ preempt_enable();
50199+
50200+ return;
50201+}
50202+
50203+static int
50204+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
50205+ unsigned char **sum)
50206+{
50207+ struct acl_role_label *r;
50208+ struct role_allowed_ip *ipp;
50209+ struct role_transition *trans;
50210+ unsigned int i;
50211+ int found = 0;
50212+ u32 curr_ip = current->signal->curr_ip;
50213+
50214+ current->signal->saved_ip = curr_ip;
50215+
50216+ /* check transition table */
50217+
50218+ for (trans = current->role->transitions; trans; trans = trans->next) {
50219+ if (!strcmp(rolename, trans->rolename)) {
50220+ found = 1;
50221+ break;
50222+ }
50223+ }
50224+
50225+ if (!found)
50226+ return 0;
50227+
50228+ /* handle special roles that do not require authentication
50229+ and check ip */
50230+
50231+ FOR_EACH_ROLE_START(r)
50232+ if (!strcmp(rolename, r->rolename) &&
50233+ (r->roletype & GR_ROLE_SPECIAL)) {
50234+ found = 0;
50235+ if (r->allowed_ips != NULL) {
50236+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
50237+ if ((ntohl(curr_ip) & ipp->netmask) ==
50238+ (ntohl(ipp->addr) & ipp->netmask))
50239+ found = 1;
50240+ }
50241+ } else
50242+ found = 2;
50243+ if (!found)
50244+ return 0;
50245+
50246+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
50247+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
50248+ *salt = NULL;
50249+ *sum = NULL;
50250+ return 1;
50251+ }
50252+ }
50253+ FOR_EACH_ROLE_END(r)
50254+
50255+ for (i = 0; i < num_sprole_pws; i++) {
50256+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
50257+ *salt = acl_special_roles[i]->salt;
50258+ *sum = acl_special_roles[i]->sum;
50259+ return 1;
50260+ }
50261+ }
50262+
50263+ return 0;
50264+}
50265+
50266+static void
50267+assign_special_role(char *rolename)
50268+{
50269+ struct acl_object_label *obj;
50270+ struct acl_role_label *r;
50271+ struct acl_role_label *assigned = NULL;
50272+ struct task_struct *tsk;
50273+ struct file *filp;
50274+
50275+ FOR_EACH_ROLE_START(r)
50276+ if (!strcmp(rolename, r->rolename) &&
50277+ (r->roletype & GR_ROLE_SPECIAL)) {
50278+ assigned = r;
50279+ break;
50280+ }
50281+ FOR_EACH_ROLE_END(r)
50282+
50283+ if (!assigned)
50284+ return;
50285+
50286+ read_lock(&tasklist_lock);
50287+ read_lock(&grsec_exec_file_lock);
50288+
50289+ tsk = current->real_parent;
50290+ if (tsk == NULL)
50291+ goto out_unlock;
50292+
50293+ filp = tsk->exec_file;
50294+ if (filp == NULL)
50295+ goto out_unlock;
50296+
50297+ tsk->is_writable = 0;
50298+
50299+ tsk->acl_sp_role = 1;
50300+ tsk->acl_role_id = ++acl_sp_role_value;
50301+ tsk->role = assigned;
50302+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
50303+
50304+ /* ignore additional mmap checks for processes that are writable
50305+ by the default ACL */
50306+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50307+ if (unlikely(obj->mode & GR_WRITE))
50308+ tsk->is_writable = 1;
50309+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
50310+ if (unlikely(obj->mode & GR_WRITE))
50311+ tsk->is_writable = 1;
50312+
50313+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50314+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
50315+#endif
50316+
50317+out_unlock:
50318+ read_unlock(&grsec_exec_file_lock);
50319+ read_unlock(&tasklist_lock);
50320+ return;
50321+}
50322+
50323+int gr_check_secure_terminal(struct task_struct *task)
50324+{
50325+ struct task_struct *p, *p2, *p3;
50326+ struct files_struct *files;
50327+ struct fdtable *fdt;
50328+ struct file *our_file = NULL, *file;
50329+ int i;
50330+
50331+ if (task->signal->tty == NULL)
50332+ return 1;
50333+
50334+ files = get_files_struct(task);
50335+ if (files != NULL) {
50336+ rcu_read_lock();
50337+ fdt = files_fdtable(files);
50338+ for (i=0; i < fdt->max_fds; i++) {
50339+ file = fcheck_files(files, i);
50340+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
50341+ get_file(file);
50342+ our_file = file;
50343+ }
50344+ }
50345+ rcu_read_unlock();
50346+ put_files_struct(files);
50347+ }
50348+
50349+ if (our_file == NULL)
50350+ return 1;
50351+
50352+ read_lock(&tasklist_lock);
50353+ do_each_thread(p2, p) {
50354+ files = get_files_struct(p);
50355+ if (files == NULL ||
50356+ (p->signal && p->signal->tty == task->signal->tty)) {
50357+ if (files != NULL)
50358+ put_files_struct(files);
50359+ continue;
50360+ }
50361+ rcu_read_lock();
50362+ fdt = files_fdtable(files);
50363+ for (i=0; i < fdt->max_fds; i++) {
50364+ file = fcheck_files(files, i);
50365+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
50366+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
50367+ p3 = task;
50368+ while (p3->pid > 0) {
50369+ if (p3 == p)
50370+ break;
50371+ p3 = p3->real_parent;
50372+ }
50373+ if (p3 == p)
50374+ break;
50375+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
50376+ gr_handle_alertkill(p);
50377+ rcu_read_unlock();
50378+ put_files_struct(files);
50379+ read_unlock(&tasklist_lock);
50380+ fput(our_file);
50381+ return 0;
50382+ }
50383+ }
50384+ rcu_read_unlock();
50385+ put_files_struct(files);
50386+ } while_each_thread(p2, p);
50387+ read_unlock(&tasklist_lock);
50388+
50389+ fput(our_file);
50390+ return 1;
50391+}
50392+
50393+ssize_t
50394+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
50395+{
50396+ struct gr_arg_wrapper uwrap;
50397+ unsigned char *sprole_salt = NULL;
50398+ unsigned char *sprole_sum = NULL;
50399+ int error = sizeof (struct gr_arg_wrapper);
50400+ int error2 = 0;
50401+
50402+ mutex_lock(&gr_dev_mutex);
50403+
50404+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
50405+ error = -EPERM;
50406+ goto out;
50407+ }
50408+
50409+ if (count != sizeof (struct gr_arg_wrapper)) {
50410+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
50411+ error = -EINVAL;
50412+ goto out;
50413+ }
50414+
50415+
50416+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
50417+ gr_auth_expires = 0;
50418+ gr_auth_attempts = 0;
50419+ }
50420+
50421+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
50422+ error = -EFAULT;
50423+ goto out;
50424+ }
50425+
50426+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
50427+ error = -EINVAL;
50428+ goto out;
50429+ }
50430+
50431+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
50432+ error = -EFAULT;
50433+ goto out;
50434+ }
50435+
50436+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
50437+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
50438+ time_after(gr_auth_expires, get_seconds())) {
50439+ error = -EBUSY;
50440+ goto out;
50441+ }
50442+
50443+ /* if non-root trying to do anything other than use a special role,
50444+ do not attempt authentication, do not count towards authentication
50445+ locking
50446+ */
50447+
50448+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
50449+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
50450+ current_uid()) {
50451+ error = -EPERM;
50452+ goto out;
50453+ }
50454+
50455+ /* ensure pw and special role name are null terminated */
50456+
50457+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
50458+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
50459+
50460+ /* Okay.
50461+ * We have our enough of the argument structure..(we have yet
50462+ * to copy_from_user the tables themselves) . Copy the tables
50463+ * only if we need them, i.e. for loading operations. */
50464+
50465+ switch (gr_usermode->mode) {
50466+ case GR_STATUS:
50467+ if (gr_status & GR_READY) {
50468+ error = 1;
50469+ if (!gr_check_secure_terminal(current))
50470+ error = 3;
50471+ } else
50472+ error = 2;
50473+ goto out;
50474+ case GR_SHUTDOWN:
50475+ if ((gr_status & GR_READY)
50476+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
50477+ pax_open_kernel();
50478+ gr_status &= ~GR_READY;
50479+ pax_close_kernel();
50480+
50481+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
50482+ free_variables();
50483+ memset(gr_usermode, 0, sizeof (struct gr_arg));
50484+ memset(gr_system_salt, 0, GR_SALT_LEN);
50485+ memset(gr_system_sum, 0, GR_SHA_LEN);
50486+ } else if (gr_status & GR_READY) {
50487+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
50488+ error = -EPERM;
50489+ } else {
50490+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
50491+ error = -EAGAIN;
50492+ }
50493+ break;
50494+ case GR_ENABLE:
50495+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
50496+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
50497+ else {
50498+ if (gr_status & GR_READY)
50499+ error = -EAGAIN;
50500+ else
50501+ error = error2;
50502+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
50503+ }
50504+ break;
50505+ case GR_RELOAD:
50506+ if (!(gr_status & GR_READY)) {
50507+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
50508+ error = -EAGAIN;
50509+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
50510+ lock_kernel();
50511+
50512+ pax_open_kernel();
50513+ gr_status &= ~GR_READY;
50514+ pax_close_kernel();
50515+
50516+ free_variables();
50517+ if (!(error2 = gracl_init(gr_usermode))) {
50518+ unlock_kernel();
50519+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
50520+ } else {
50521+ unlock_kernel();
50522+ error = error2;
50523+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
50524+ }
50525+ } else {
50526+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
50527+ error = -EPERM;
50528+ }
50529+ break;
50530+ case GR_SEGVMOD:
50531+ if (unlikely(!(gr_status & GR_READY))) {
50532+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
50533+ error = -EAGAIN;
50534+ break;
50535+ }
50536+
50537+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
50538+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
50539+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
50540+ struct acl_subject_label *segvacl;
50541+ segvacl =
50542+ lookup_acl_subj_label(gr_usermode->segv_inode,
50543+ gr_usermode->segv_device,
50544+ current->role);
50545+ if (segvacl) {
50546+ segvacl->crashes = 0;
50547+ segvacl->expires = 0;
50548+ }
50549+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
50550+ gr_remove_uid(gr_usermode->segv_uid);
50551+ }
50552+ } else {
50553+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
50554+ error = -EPERM;
50555+ }
50556+ break;
50557+ case GR_SPROLE:
50558+ case GR_SPROLEPAM:
50559+ if (unlikely(!(gr_status & GR_READY))) {
50560+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
50561+ error = -EAGAIN;
50562+ break;
50563+ }
50564+
50565+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
50566+ current->role->expires = 0;
50567+ current->role->auth_attempts = 0;
50568+ }
50569+
50570+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
50571+ time_after(current->role->expires, get_seconds())) {
50572+ error = -EBUSY;
50573+ goto out;
50574+ }
50575+
50576+ if (lookup_special_role_auth
50577+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
50578+ && ((!sprole_salt && !sprole_sum)
50579+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
50580+ char *p = "";
50581+ assign_special_role(gr_usermode->sp_role);
50582+ read_lock(&tasklist_lock);
50583+ if (current->real_parent)
50584+ p = current->real_parent->role->rolename;
50585+ read_unlock(&tasklist_lock);
50586+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
50587+ p, acl_sp_role_value);
50588+ } else {
50589+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
50590+ error = -EPERM;
50591+ if(!(current->role->auth_attempts++))
50592+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
50593+
50594+ goto out;
50595+ }
50596+ break;
50597+ case GR_UNSPROLE:
50598+ if (unlikely(!(gr_status & GR_READY))) {
50599+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
50600+ error = -EAGAIN;
50601+ break;
50602+ }
50603+
50604+ if (current->role->roletype & GR_ROLE_SPECIAL) {
50605+ char *p = "";
50606+ int i = 0;
50607+
50608+ read_lock(&tasklist_lock);
50609+ if (current->real_parent) {
50610+ p = current->real_parent->role->rolename;
50611+ i = current->real_parent->acl_role_id;
50612+ }
50613+ read_unlock(&tasklist_lock);
50614+
50615+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
50616+ gr_set_acls(1);
50617+ } else {
50618+ error = -EPERM;
50619+ goto out;
50620+ }
50621+ break;
50622+ default:
50623+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
50624+ error = -EINVAL;
50625+ break;
50626+ }
50627+
50628+ if (error != -EPERM)
50629+ goto out;
50630+
50631+ if(!(gr_auth_attempts++))
50632+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
50633+
50634+ out:
50635+ mutex_unlock(&gr_dev_mutex);
50636+ return error;
50637+}
50638+
50639+/* must be called with
50640+ rcu_read_lock();
50641+ read_lock(&tasklist_lock);
50642+ read_lock(&grsec_exec_file_lock);
50643+*/
50644+int gr_apply_subject_to_task(struct task_struct *task)
50645+{
50646+ struct acl_object_label *obj;
50647+ char *tmpname;
50648+ struct acl_subject_label *tmpsubj;
50649+ struct file *filp;
50650+ struct name_entry *nmatch;
50651+
50652+ filp = task->exec_file;
50653+ if (filp == NULL)
50654+ return 0;
50655+
50656+ /* the following is to apply the correct subject
50657+ on binaries running when the RBAC system
50658+ is enabled, when the binaries have been
50659+ replaced or deleted since their execution
50660+ -----
50661+ when the RBAC system starts, the inode/dev
50662+ from exec_file will be one the RBAC system
50663+ is unaware of. It only knows the inode/dev
50664+ of the present file on disk, or the absence
50665+ of it.
50666+ */
50667+ preempt_disable();
50668+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
50669+
50670+ nmatch = lookup_name_entry(tmpname);
50671+ preempt_enable();
50672+ tmpsubj = NULL;
50673+ if (nmatch) {
50674+ if (nmatch->deleted)
50675+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
50676+ else
50677+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
50678+ if (tmpsubj != NULL)
50679+ task->acl = tmpsubj;
50680+ }
50681+ if (tmpsubj == NULL)
50682+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
50683+ task->role);
50684+ if (task->acl) {
50685+ task->is_writable = 0;
50686+ /* ignore additional mmap checks for processes that are writable
50687+ by the default ACL */
50688+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50689+ if (unlikely(obj->mode & GR_WRITE))
50690+ task->is_writable = 1;
50691+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
50692+ if (unlikely(obj->mode & GR_WRITE))
50693+ task->is_writable = 1;
50694+
50695+ gr_set_proc_res(task);
50696+
50697+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50698+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50699+#endif
50700+ } else {
50701+ return 1;
50702+ }
50703+
50704+ return 0;
50705+}
50706+
50707+int
50708+gr_set_acls(const int type)
50709+{
50710+ struct task_struct *task, *task2;
50711+ struct acl_role_label *role = current->role;
50712+ __u16 acl_role_id = current->acl_role_id;
50713+ const struct cred *cred;
50714+ int ret;
50715+
50716+ rcu_read_lock();
50717+ read_lock(&tasklist_lock);
50718+ read_lock(&grsec_exec_file_lock);
50719+ do_each_thread(task2, task) {
50720+ /* check to see if we're called from the exit handler,
50721+ if so, only replace ACLs that have inherited the admin
50722+ ACL */
50723+
50724+ if (type && (task->role != role ||
50725+ task->acl_role_id != acl_role_id))
50726+ continue;
50727+
50728+ task->acl_role_id = 0;
50729+ task->acl_sp_role = 0;
50730+
50731+ if (task->exec_file) {
50732+ cred = __task_cred(task);
50733+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
50734+
50735+ ret = gr_apply_subject_to_task(task);
50736+ if (ret) {
50737+ read_unlock(&grsec_exec_file_lock);
50738+ read_unlock(&tasklist_lock);
50739+ rcu_read_unlock();
50740+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
50741+ return ret;
50742+ }
50743+ } else {
50744+ // it's a kernel process
50745+ task->role = kernel_role;
50746+ task->acl = kernel_role->root_label;
50747+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
50748+ task->acl->mode &= ~GR_PROCFIND;
50749+#endif
50750+ }
50751+ } while_each_thread(task2, task);
50752+ read_unlock(&grsec_exec_file_lock);
50753+ read_unlock(&tasklist_lock);
50754+ rcu_read_unlock();
50755+
50756+ return 0;
50757+}
50758+
50759+void
50760+gr_learn_resource(const struct task_struct *task,
50761+ const int res, const unsigned long wanted, const int gt)
50762+{
50763+ struct acl_subject_label *acl;
50764+ const struct cred *cred;
50765+
50766+ if (unlikely((gr_status & GR_READY) &&
50767+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
50768+ goto skip_reslog;
50769+
50770+#ifdef CONFIG_GRKERNSEC_RESLOG
50771+ gr_log_resource(task, res, wanted, gt);
50772+#endif
50773+ skip_reslog:
50774+
50775+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
50776+ return;
50777+
50778+ acl = task->acl;
50779+
50780+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
50781+ !(acl->resmask & (1 << (unsigned short) res))))
50782+ return;
50783+
50784+ if (wanted >= acl->res[res].rlim_cur) {
50785+ unsigned long res_add;
50786+
50787+ res_add = wanted;
50788+ switch (res) {
50789+ case RLIMIT_CPU:
50790+ res_add += GR_RLIM_CPU_BUMP;
50791+ break;
50792+ case RLIMIT_FSIZE:
50793+ res_add += GR_RLIM_FSIZE_BUMP;
50794+ break;
50795+ case RLIMIT_DATA:
50796+ res_add += GR_RLIM_DATA_BUMP;
50797+ break;
50798+ case RLIMIT_STACK:
50799+ res_add += GR_RLIM_STACK_BUMP;
50800+ break;
50801+ case RLIMIT_CORE:
50802+ res_add += GR_RLIM_CORE_BUMP;
50803+ break;
50804+ case RLIMIT_RSS:
50805+ res_add += GR_RLIM_RSS_BUMP;
50806+ break;
50807+ case RLIMIT_NPROC:
50808+ res_add += GR_RLIM_NPROC_BUMP;
50809+ break;
50810+ case RLIMIT_NOFILE:
50811+ res_add += GR_RLIM_NOFILE_BUMP;
50812+ break;
50813+ case RLIMIT_MEMLOCK:
50814+ res_add += GR_RLIM_MEMLOCK_BUMP;
50815+ break;
50816+ case RLIMIT_AS:
50817+ res_add += GR_RLIM_AS_BUMP;
50818+ break;
50819+ case RLIMIT_LOCKS:
50820+ res_add += GR_RLIM_LOCKS_BUMP;
50821+ break;
50822+ case RLIMIT_SIGPENDING:
50823+ res_add += GR_RLIM_SIGPENDING_BUMP;
50824+ break;
50825+ case RLIMIT_MSGQUEUE:
50826+ res_add += GR_RLIM_MSGQUEUE_BUMP;
50827+ break;
50828+ case RLIMIT_NICE:
50829+ res_add += GR_RLIM_NICE_BUMP;
50830+ break;
50831+ case RLIMIT_RTPRIO:
50832+ res_add += GR_RLIM_RTPRIO_BUMP;
50833+ break;
50834+ case RLIMIT_RTTIME:
50835+ res_add += GR_RLIM_RTTIME_BUMP;
50836+ break;
50837+ }
50838+
50839+ acl->res[res].rlim_cur = res_add;
50840+
50841+ if (wanted > acl->res[res].rlim_max)
50842+ acl->res[res].rlim_max = res_add;
50843+
50844+ /* only log the subject filename, since resource logging is supported for
50845+ single-subject learning only */
50846+ rcu_read_lock();
50847+ cred = __task_cred(task);
50848+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
50849+ task->role->roletype, cred->uid, cred->gid, acl->filename,
50850+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
50851+ "", (unsigned long) res, &task->signal->saved_ip);
50852+ rcu_read_unlock();
50853+ }
50854+
50855+ return;
50856+}
50857+
50858+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
50859+void
50860+pax_set_initial_flags(struct linux_binprm *bprm)
50861+{
50862+ struct task_struct *task = current;
50863+ struct acl_subject_label *proc;
50864+ unsigned long flags;
50865+
50866+ if (unlikely(!(gr_status & GR_READY)))
50867+ return;
50868+
50869+ flags = pax_get_flags(task);
50870+
50871+ proc = task->acl;
50872+
50873+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
50874+ flags &= ~MF_PAX_PAGEEXEC;
50875+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
50876+ flags &= ~MF_PAX_SEGMEXEC;
50877+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
50878+ flags &= ~MF_PAX_RANDMMAP;
50879+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
50880+ flags &= ~MF_PAX_EMUTRAMP;
50881+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
50882+ flags &= ~MF_PAX_MPROTECT;
50883+
50884+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
50885+ flags |= MF_PAX_PAGEEXEC;
50886+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
50887+ flags |= MF_PAX_SEGMEXEC;
50888+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
50889+ flags |= MF_PAX_RANDMMAP;
50890+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
50891+ flags |= MF_PAX_EMUTRAMP;
50892+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
50893+ flags |= MF_PAX_MPROTECT;
50894+
50895+ pax_set_flags(task, flags);
50896+
50897+ return;
50898+}
50899+#endif
50900+
50901+#ifdef CONFIG_SYSCTL
50902+/* Eric Biederman likes breaking userland ABI and every inode-based security
50903+ system to save 35kb of memory */
50904+
50905+/* we modify the passed in filename, but adjust it back before returning */
50906+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
50907+{
50908+ struct name_entry *nmatch;
50909+ char *p, *lastp = NULL;
50910+ struct acl_object_label *obj = NULL, *tmp;
50911+ struct acl_subject_label *tmpsubj;
50912+ char c = '\0';
50913+
50914+ read_lock(&gr_inode_lock);
50915+
50916+ p = name + len - 1;
50917+ do {
50918+ nmatch = lookup_name_entry(name);
50919+ if (lastp != NULL)
50920+ *lastp = c;
50921+
50922+ if (nmatch == NULL)
50923+ goto next_component;
50924+ tmpsubj = current->acl;
50925+ do {
50926+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
50927+ if (obj != NULL) {
50928+ tmp = obj->globbed;
50929+ while (tmp) {
50930+ if (!glob_match(tmp->filename, name)) {
50931+ obj = tmp;
50932+ goto found_obj;
50933+ }
50934+ tmp = tmp->next;
50935+ }
50936+ goto found_obj;
50937+ }
50938+ } while ((tmpsubj = tmpsubj->parent_subject));
50939+next_component:
50940+ /* end case */
50941+ if (p == name)
50942+ break;
50943+
50944+ while (*p != '/')
50945+ p--;
50946+ if (p == name)
50947+ lastp = p + 1;
50948+ else {
50949+ lastp = p;
50950+ p--;
50951+ }
50952+ c = *lastp;
50953+ *lastp = '\0';
50954+ } while (1);
50955+found_obj:
50956+ read_unlock(&gr_inode_lock);
50957+ /* obj returned will always be non-null */
50958+ return obj;
50959+}
50960+
50961+/* returns 0 when allowing, non-zero on error
50962+ op of 0 is used for readdir, so we don't log the names of hidden files
50963+*/
50964+__u32
50965+gr_handle_sysctl(const struct ctl_table *table, const int op)
50966+{
50967+ ctl_table *tmp;
50968+ const char *proc_sys = "/proc/sys";
50969+ char *path;
50970+ struct acl_object_label *obj;
50971+ unsigned short len = 0, pos = 0, depth = 0, i;
50972+ __u32 err = 0;
50973+ __u32 mode = 0;
50974+
50975+ if (unlikely(!(gr_status & GR_READY)))
50976+ return 0;
50977+
50978+ /* for now, ignore operations on non-sysctl entries if it's not a
50979+ readdir*/
50980+ if (table->child != NULL && op != 0)
50981+ return 0;
50982+
50983+ mode |= GR_FIND;
50984+ /* it's only a read if it's an entry, read on dirs is for readdir */
50985+ if (op & MAY_READ)
50986+ mode |= GR_READ;
50987+ if (op & MAY_WRITE)
50988+ mode |= GR_WRITE;
50989+
50990+ preempt_disable();
50991+
50992+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50993+
50994+ /* it's only a read/write if it's an actual entry, not a dir
50995+ (which are opened for readdir)
50996+ */
50997+
50998+ /* convert the requested sysctl entry into a pathname */
50999+
51000+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
51001+ len += strlen(tmp->procname);
51002+ len++;
51003+ depth++;
51004+ }
51005+
51006+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
51007+ /* deny */
51008+ goto out;
51009+ }
51010+
51011+ memset(path, 0, PAGE_SIZE);
51012+
51013+ memcpy(path, proc_sys, strlen(proc_sys));
51014+
51015+ pos += strlen(proc_sys);
51016+
51017+ for (; depth > 0; depth--) {
51018+ path[pos] = '/';
51019+ pos++;
51020+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
51021+ if (depth == i) {
51022+ memcpy(path + pos, tmp->procname,
51023+ strlen(tmp->procname));
51024+ pos += strlen(tmp->procname);
51025+ }
51026+ i++;
51027+ }
51028+ }
51029+
51030+ obj = gr_lookup_by_name(path, pos);
51031+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
51032+
51033+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
51034+ ((err & mode) != mode))) {
51035+ __u32 new_mode = mode;
51036+
51037+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51038+
51039+ err = 0;
51040+ gr_log_learn_sysctl(path, new_mode);
51041+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
51042+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
51043+ err = -ENOENT;
51044+ } else if (!(err & GR_FIND)) {
51045+ err = -ENOENT;
51046+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
51047+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
51048+ path, (mode & GR_READ) ? " reading" : "",
51049+ (mode & GR_WRITE) ? " writing" : "");
51050+ err = -EACCES;
51051+ } else if ((err & mode) != mode) {
51052+ err = -EACCES;
51053+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
51054+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
51055+ path, (mode & GR_READ) ? " reading" : "",
51056+ (mode & GR_WRITE) ? " writing" : "");
51057+ err = 0;
51058+ } else
51059+ err = 0;
51060+
51061+ out:
51062+ preempt_enable();
51063+
51064+ return err;
51065+}
51066+#endif
51067+
51068+int
51069+gr_handle_proc_ptrace(struct task_struct *task)
51070+{
51071+ struct file *filp;
51072+ struct task_struct *tmp = task;
51073+ struct task_struct *curtemp = current;
51074+ __u32 retmode;
51075+
51076+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
51077+ if (unlikely(!(gr_status & GR_READY)))
51078+ return 0;
51079+#endif
51080+
51081+ read_lock(&tasklist_lock);
51082+ read_lock(&grsec_exec_file_lock);
51083+ filp = task->exec_file;
51084+
51085+ while (tmp->pid > 0) {
51086+ if (tmp == curtemp)
51087+ break;
51088+ tmp = tmp->real_parent;
51089+ }
51090+
51091+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
51092+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
51093+ read_unlock(&grsec_exec_file_lock);
51094+ read_unlock(&tasklist_lock);
51095+ return 1;
51096+ }
51097+
51098+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
51099+ if (!(gr_status & GR_READY)) {
51100+ read_unlock(&grsec_exec_file_lock);
51101+ read_unlock(&tasklist_lock);
51102+ return 0;
51103+ }
51104+#endif
51105+
51106+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
51107+ read_unlock(&grsec_exec_file_lock);
51108+ read_unlock(&tasklist_lock);
51109+
51110+ if (retmode & GR_NOPTRACE)
51111+ return 1;
51112+
51113+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
51114+ && (current->acl != task->acl || (current->acl != current->role->root_label
51115+ && current->pid != task->pid)))
51116+ return 1;
51117+
51118+ return 0;
51119+}
51120+
51121+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
51122+{
51123+ if (unlikely(!(gr_status & GR_READY)))
51124+ return;
51125+
51126+ if (!(current->role->roletype & GR_ROLE_GOD))
51127+ return;
51128+
51129+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
51130+ p->role->rolename, gr_task_roletype_to_char(p),
51131+ p->acl->filename);
51132+}
51133+
51134+int
51135+gr_handle_ptrace(struct task_struct *task, const long request)
51136+{
51137+ struct task_struct *tmp = task;
51138+ struct task_struct *curtemp = current;
51139+ __u32 retmode;
51140+
51141+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
51142+ if (unlikely(!(gr_status & GR_READY)))
51143+ return 0;
51144+#endif
51145+
51146+ read_lock(&tasklist_lock);
51147+ while (tmp->pid > 0) {
51148+ if (tmp == curtemp)
51149+ break;
51150+ tmp = tmp->real_parent;
51151+ }
51152+
51153+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
51154+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
51155+ read_unlock(&tasklist_lock);
51156+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
51157+ return 1;
51158+ }
51159+ read_unlock(&tasklist_lock);
51160+
51161+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
51162+ if (!(gr_status & GR_READY))
51163+ return 0;
51164+#endif
51165+
51166+ read_lock(&grsec_exec_file_lock);
51167+ if (unlikely(!task->exec_file)) {
51168+ read_unlock(&grsec_exec_file_lock);
51169+ return 0;
51170+ }
51171+
51172+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
51173+ read_unlock(&grsec_exec_file_lock);
51174+
51175+ if (retmode & GR_NOPTRACE) {
51176+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
51177+ return 1;
51178+ }
51179+
51180+ if (retmode & GR_PTRACERD) {
51181+ switch (request) {
51182+ case PTRACE_POKETEXT:
51183+ case PTRACE_POKEDATA:
51184+ case PTRACE_POKEUSR:
51185+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
51186+ case PTRACE_SETREGS:
51187+ case PTRACE_SETFPREGS:
51188+#endif
51189+#ifdef CONFIG_X86
51190+ case PTRACE_SETFPXREGS:
51191+#endif
51192+#ifdef CONFIG_ALTIVEC
51193+ case PTRACE_SETVRREGS:
51194+#endif
51195+ return 1;
51196+ default:
51197+ return 0;
51198+ }
51199+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
51200+ !(current->role->roletype & GR_ROLE_GOD) &&
51201+ (current->acl != task->acl)) {
51202+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
51203+ return 1;
51204+ }
51205+
51206+ return 0;
51207+}
51208+
51209+static int is_writable_mmap(const struct file *filp)
51210+{
51211+ struct task_struct *task = current;
51212+ struct acl_object_label *obj, *obj2;
51213+
51214+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
51215+ !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))) {
51216+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51217+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
51218+ task->role->root_label);
51219+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
51220+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
51221+ return 1;
51222+ }
51223+ }
51224+ return 0;
51225+}
51226+
51227+int
51228+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
51229+{
51230+ __u32 mode;
51231+
51232+ if (unlikely(!file || !(prot & PROT_EXEC)))
51233+ return 1;
51234+
51235+ if (is_writable_mmap(file))
51236+ return 0;
51237+
51238+ mode =
51239+ gr_search_file(file->f_path.dentry,
51240+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
51241+ file->f_path.mnt);
51242+
51243+ if (!gr_tpe_allow(file))
51244+ return 0;
51245+
51246+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
51247+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
51248+ return 0;
51249+ } else if (unlikely(!(mode & GR_EXEC))) {
51250+ return 0;
51251+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
51252+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
51253+ return 1;
51254+ }
51255+
51256+ return 1;
51257+}
51258+
51259+int
51260+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
51261+{
51262+ __u32 mode;
51263+
51264+ if (unlikely(!file || !(prot & PROT_EXEC)))
51265+ return 1;
51266+
51267+ if (is_writable_mmap(file))
51268+ return 0;
51269+
51270+ mode =
51271+ gr_search_file(file->f_path.dentry,
51272+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
51273+ file->f_path.mnt);
51274+
51275+ if (!gr_tpe_allow(file))
51276+ return 0;
51277+
51278+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
51279+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
51280+ return 0;
51281+ } else if (unlikely(!(mode & GR_EXEC))) {
51282+ return 0;
51283+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
51284+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
51285+ return 1;
51286+ }
51287+
51288+ return 1;
51289+}
51290+
51291+void
51292+gr_acl_handle_psacct(struct task_struct *task, const long code)
51293+{
51294+ unsigned long runtime;
51295+ unsigned long cputime;
51296+ unsigned int wday, cday;
51297+ __u8 whr, chr;
51298+ __u8 wmin, cmin;
51299+ __u8 wsec, csec;
51300+ struct timespec timeval;
51301+
51302+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
51303+ !(task->acl->mode & GR_PROCACCT)))
51304+ return;
51305+
51306+ do_posix_clock_monotonic_gettime(&timeval);
51307+ runtime = timeval.tv_sec - task->start_time.tv_sec;
51308+ wday = runtime / (3600 * 24);
51309+ runtime -= wday * (3600 * 24);
51310+ whr = runtime / 3600;
51311+ runtime -= whr * 3600;
51312+ wmin = runtime / 60;
51313+ runtime -= wmin * 60;
51314+ wsec = runtime;
51315+
51316+ cputime = (task->utime + task->stime) / HZ;
51317+ cday = cputime / (3600 * 24);
51318+ cputime -= cday * (3600 * 24);
51319+ chr = cputime / 3600;
51320+ cputime -= chr * 3600;
51321+ cmin = cputime / 60;
51322+ cputime -= cmin * 60;
51323+ csec = cputime;
51324+
51325+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
51326+
51327+ return;
51328+}
51329+
51330+void gr_set_kernel_label(struct task_struct *task)
51331+{
51332+ if (gr_status & GR_READY) {
51333+ task->role = kernel_role;
51334+ task->acl = kernel_role->root_label;
51335+ }
51336+ return;
51337+}
51338+
51339+#ifdef CONFIG_TASKSTATS
51340+int gr_is_taskstats_denied(int pid)
51341+{
51342+ struct task_struct *task;
51343+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51344+ const struct cred *cred;
51345+#endif
51346+ int ret = 0;
51347+
51348+ /* restrict taskstats viewing to un-chrooted root users
51349+ who have the 'view' subject flag if the RBAC system is enabled
51350+ */
51351+
51352+ rcu_read_lock();
51353+ read_lock(&tasklist_lock);
51354+ task = find_task_by_vpid(pid);
51355+ if (task) {
51356+#ifdef CONFIG_GRKERNSEC_CHROOT
51357+ if (proc_is_chrooted(task))
51358+ ret = -EACCES;
51359+#endif
51360+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51361+ cred = __task_cred(task);
51362+#ifdef CONFIG_GRKERNSEC_PROC_USER
51363+ if (cred->uid != 0)
51364+ ret = -EACCES;
51365+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51366+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
51367+ ret = -EACCES;
51368+#endif
51369+#endif
51370+ if (gr_status & GR_READY) {
51371+ if (!(task->acl->mode & GR_VIEW))
51372+ ret = -EACCES;
51373+ }
51374+ } else
51375+ ret = -ENOENT;
51376+
51377+ read_unlock(&tasklist_lock);
51378+ rcu_read_unlock();
51379+
51380+ return ret;
51381+}
51382+#endif
51383+
51384+/* AUXV entries are filled via a descendant of search_binary_handler
51385+ after we've already applied the subject for the target
51386+*/
51387+int gr_acl_enable_at_secure(void)
51388+{
51389+ if (unlikely(!(gr_status & GR_READY)))
51390+ return 0;
51391+
51392+ if (current->acl->mode & GR_ATSECURE)
51393+ return 1;
51394+
51395+ return 0;
51396+}
51397+
51398+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
51399+{
51400+ struct task_struct *task = current;
51401+ struct dentry *dentry = file->f_path.dentry;
51402+ struct vfsmount *mnt = file->f_path.mnt;
51403+ struct acl_object_label *obj, *tmp;
51404+ struct acl_subject_label *subj;
51405+ unsigned int bufsize;
51406+ int is_not_root;
51407+ char *path;
51408+ dev_t dev = __get_dev(dentry);
51409+
51410+ if (unlikely(!(gr_status & GR_READY)))
51411+ return 1;
51412+
51413+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
51414+ return 1;
51415+
51416+ /* ignore Eric Biederman */
51417+ if (IS_PRIVATE(dentry->d_inode))
51418+ return 1;
51419+
51420+ subj = task->acl;
51421+ do {
51422+ obj = lookup_acl_obj_label(ino, dev, subj);
51423+ if (obj != NULL)
51424+ return (obj->mode & GR_FIND) ? 1 : 0;
51425+ } while ((subj = subj->parent_subject));
51426+
51427+ /* this is purely an optimization since we're looking for an object
51428+ for the directory we're doing a readdir on
51429+ if it's possible for any globbed object to match the entry we're
51430+ filling into the directory, then the object we find here will be
51431+ an anchor point with attached globbed objects
51432+ */
51433+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
51434+ if (obj->globbed == NULL)
51435+ return (obj->mode & GR_FIND) ? 1 : 0;
51436+
51437+ is_not_root = ((obj->filename[0] == '/') &&
51438+ (obj->filename[1] == '\0')) ? 0 : 1;
51439+ bufsize = PAGE_SIZE - namelen - is_not_root;
51440+
51441+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
51442+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
51443+ return 1;
51444+
51445+ preempt_disable();
51446+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51447+ bufsize);
51448+
51449+ bufsize = strlen(path);
51450+
51451+ /* if base is "/", don't append an additional slash */
51452+ if (is_not_root)
51453+ *(path + bufsize) = '/';
51454+ memcpy(path + bufsize + is_not_root, name, namelen);
51455+ *(path + bufsize + namelen + is_not_root) = '\0';
51456+
51457+ tmp = obj->globbed;
51458+ while (tmp) {
51459+ if (!glob_match(tmp->filename, path)) {
51460+ preempt_enable();
51461+ return (tmp->mode & GR_FIND) ? 1 : 0;
51462+ }
51463+ tmp = tmp->next;
51464+ }
51465+ preempt_enable();
51466+ return (obj->mode & GR_FIND) ? 1 : 0;
51467+}
51468+
51469+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
51470+EXPORT_SYMBOL(gr_acl_is_enabled);
51471+#endif
51472+EXPORT_SYMBOL(gr_learn_resource);
51473+EXPORT_SYMBOL(gr_set_kernel_label);
51474+#ifdef CONFIG_SECURITY
51475+EXPORT_SYMBOL(gr_check_user_change);
51476+EXPORT_SYMBOL(gr_check_group_change);
51477+#endif
51478+
51479diff -urNp linux-2.6.32.44/grsecurity/gracl_cap.c linux-2.6.32.44/grsecurity/gracl_cap.c
51480--- linux-2.6.32.44/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
51481+++ linux-2.6.32.44/grsecurity/gracl_cap.c 2011-04-17 15:56:46.000000000 -0400
51482@@ -0,0 +1,138 @@
51483+#include <linux/kernel.h>
51484+#include <linux/module.h>
51485+#include <linux/sched.h>
51486+#include <linux/gracl.h>
51487+#include <linux/grsecurity.h>
51488+#include <linux/grinternal.h>
51489+
51490+static const char *captab_log[] = {
51491+ "CAP_CHOWN",
51492+ "CAP_DAC_OVERRIDE",
51493+ "CAP_DAC_READ_SEARCH",
51494+ "CAP_FOWNER",
51495+ "CAP_FSETID",
51496+ "CAP_KILL",
51497+ "CAP_SETGID",
51498+ "CAP_SETUID",
51499+ "CAP_SETPCAP",
51500+ "CAP_LINUX_IMMUTABLE",
51501+ "CAP_NET_BIND_SERVICE",
51502+ "CAP_NET_BROADCAST",
51503+ "CAP_NET_ADMIN",
51504+ "CAP_NET_RAW",
51505+ "CAP_IPC_LOCK",
51506+ "CAP_IPC_OWNER",
51507+ "CAP_SYS_MODULE",
51508+ "CAP_SYS_RAWIO",
51509+ "CAP_SYS_CHROOT",
51510+ "CAP_SYS_PTRACE",
51511+ "CAP_SYS_PACCT",
51512+ "CAP_SYS_ADMIN",
51513+ "CAP_SYS_BOOT",
51514+ "CAP_SYS_NICE",
51515+ "CAP_SYS_RESOURCE",
51516+ "CAP_SYS_TIME",
51517+ "CAP_SYS_TTY_CONFIG",
51518+ "CAP_MKNOD",
51519+ "CAP_LEASE",
51520+ "CAP_AUDIT_WRITE",
51521+ "CAP_AUDIT_CONTROL",
51522+ "CAP_SETFCAP",
51523+ "CAP_MAC_OVERRIDE",
51524+ "CAP_MAC_ADMIN"
51525+};
51526+
51527+EXPORT_SYMBOL(gr_is_capable);
51528+EXPORT_SYMBOL(gr_is_capable_nolog);
51529+
51530+int
51531+gr_is_capable(const int cap)
51532+{
51533+ struct task_struct *task = current;
51534+ const struct cred *cred = current_cred();
51535+ struct acl_subject_label *curracl;
51536+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
51537+ kernel_cap_t cap_audit = __cap_empty_set;
51538+
51539+ if (!gr_acl_is_enabled())
51540+ return 1;
51541+
51542+ curracl = task->acl;
51543+
51544+ cap_drop = curracl->cap_lower;
51545+ cap_mask = curracl->cap_mask;
51546+ cap_audit = curracl->cap_invert_audit;
51547+
51548+ while ((curracl = curracl->parent_subject)) {
51549+ /* if the cap isn't specified in the current computed mask but is specified in the
51550+ current level subject, and is lowered in the current level subject, then add
51551+ it to the set of dropped capabilities
51552+ otherwise, add the current level subject's mask to the current computed mask
51553+ */
51554+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
51555+ cap_raise(cap_mask, cap);
51556+ if (cap_raised(curracl->cap_lower, cap))
51557+ cap_raise(cap_drop, cap);
51558+ if (cap_raised(curracl->cap_invert_audit, cap))
51559+ cap_raise(cap_audit, cap);
51560+ }
51561+ }
51562+
51563+ if (!cap_raised(cap_drop, cap)) {
51564+ if (cap_raised(cap_audit, cap))
51565+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
51566+ return 1;
51567+ }
51568+
51569+ curracl = task->acl;
51570+
51571+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
51572+ && cap_raised(cred->cap_effective, cap)) {
51573+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
51574+ task->role->roletype, cred->uid,
51575+ cred->gid, task->exec_file ?
51576+ gr_to_filename(task->exec_file->f_path.dentry,
51577+ task->exec_file->f_path.mnt) : curracl->filename,
51578+ curracl->filename, 0UL,
51579+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
51580+ return 1;
51581+ }
51582+
51583+ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
51584+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
51585+ return 0;
51586+}
51587+
51588+int
51589+gr_is_capable_nolog(const int cap)
51590+{
51591+ struct acl_subject_label *curracl;
51592+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
51593+
51594+ if (!gr_acl_is_enabled())
51595+ return 1;
51596+
51597+ curracl = current->acl;
51598+
51599+ cap_drop = curracl->cap_lower;
51600+ cap_mask = curracl->cap_mask;
51601+
51602+ while ((curracl = curracl->parent_subject)) {
51603+ /* if the cap isn't specified in the current computed mask but is specified in the
51604+ current level subject, and is lowered in the current level subject, then add
51605+ it to the set of dropped capabilities
51606+ otherwise, add the current level subject's mask to the current computed mask
51607+ */
51608+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
51609+ cap_raise(cap_mask, cap);
51610+ if (cap_raised(curracl->cap_lower, cap))
51611+ cap_raise(cap_drop, cap);
51612+ }
51613+ }
51614+
51615+ if (!cap_raised(cap_drop, cap))
51616+ return 1;
51617+
51618+ return 0;
51619+}
51620+
51621diff -urNp linux-2.6.32.44/grsecurity/gracl_fs.c linux-2.6.32.44/grsecurity/gracl_fs.c
51622--- linux-2.6.32.44/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
51623+++ linux-2.6.32.44/grsecurity/gracl_fs.c 2011-04-17 15:56:46.000000000 -0400
51624@@ -0,0 +1,431 @@
51625+#include <linux/kernel.h>
51626+#include <linux/sched.h>
51627+#include <linux/types.h>
51628+#include <linux/fs.h>
51629+#include <linux/file.h>
51630+#include <linux/stat.h>
51631+#include <linux/grsecurity.h>
51632+#include <linux/grinternal.h>
51633+#include <linux/gracl.h>
51634+
51635+__u32
51636+gr_acl_handle_hidden_file(const struct dentry * dentry,
51637+ const struct vfsmount * mnt)
51638+{
51639+ __u32 mode;
51640+
51641+ if (unlikely(!dentry->d_inode))
51642+ return GR_FIND;
51643+
51644+ mode =
51645+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
51646+
51647+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
51648+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
51649+ return mode;
51650+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
51651+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
51652+ return 0;
51653+ } else if (unlikely(!(mode & GR_FIND)))
51654+ return 0;
51655+
51656+ return GR_FIND;
51657+}
51658+
51659+__u32
51660+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
51661+ const int fmode)
51662+{
51663+ __u32 reqmode = GR_FIND;
51664+ __u32 mode;
51665+
51666+ if (unlikely(!dentry->d_inode))
51667+ return reqmode;
51668+
51669+ if (unlikely(fmode & O_APPEND))
51670+ reqmode |= GR_APPEND;
51671+ else if (unlikely(fmode & FMODE_WRITE))
51672+ reqmode |= GR_WRITE;
51673+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
51674+ reqmode |= GR_READ;
51675+ if ((fmode & FMODE_GREXEC) && (fmode & FMODE_EXEC))
51676+ reqmode &= ~GR_READ;
51677+ mode =
51678+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
51679+ mnt);
51680+
51681+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
51682+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
51683+ reqmode & GR_READ ? " reading" : "",
51684+ reqmode & GR_WRITE ? " writing" : reqmode &
51685+ GR_APPEND ? " appending" : "");
51686+ return reqmode;
51687+ } else
51688+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
51689+ {
51690+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
51691+ reqmode & GR_READ ? " reading" : "",
51692+ reqmode & GR_WRITE ? " writing" : reqmode &
51693+ GR_APPEND ? " appending" : "");
51694+ return 0;
51695+ } else if (unlikely((mode & reqmode) != reqmode))
51696+ return 0;
51697+
51698+ return reqmode;
51699+}
51700+
51701+__u32
51702+gr_acl_handle_creat(const struct dentry * dentry,
51703+ const struct dentry * p_dentry,
51704+ const struct vfsmount * p_mnt, const int fmode,
51705+ const int imode)
51706+{
51707+ __u32 reqmode = GR_WRITE | GR_CREATE;
51708+ __u32 mode;
51709+
51710+ if (unlikely(fmode & O_APPEND))
51711+ reqmode |= GR_APPEND;
51712+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
51713+ reqmode |= GR_READ;
51714+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
51715+ reqmode |= GR_SETID;
51716+
51717+ mode =
51718+ gr_check_create(dentry, p_dentry, p_mnt,
51719+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
51720+
51721+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
51722+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
51723+ reqmode & GR_READ ? " reading" : "",
51724+ reqmode & GR_WRITE ? " writing" : reqmode &
51725+ GR_APPEND ? " appending" : "");
51726+ return reqmode;
51727+ } else
51728+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
51729+ {
51730+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
51731+ reqmode & GR_READ ? " reading" : "",
51732+ reqmode & GR_WRITE ? " writing" : reqmode &
51733+ GR_APPEND ? " appending" : "");
51734+ return 0;
51735+ } else if (unlikely((mode & reqmode) != reqmode))
51736+ return 0;
51737+
51738+ return reqmode;
51739+}
51740+
51741+__u32
51742+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
51743+ const int fmode)
51744+{
51745+ __u32 mode, reqmode = GR_FIND;
51746+
51747+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
51748+ reqmode |= GR_EXEC;
51749+ if (fmode & S_IWOTH)
51750+ reqmode |= GR_WRITE;
51751+ if (fmode & S_IROTH)
51752+ reqmode |= GR_READ;
51753+
51754+ mode =
51755+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
51756+ mnt);
51757+
51758+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
51759+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
51760+ reqmode & GR_READ ? " reading" : "",
51761+ reqmode & GR_WRITE ? " writing" : "",
51762+ reqmode & GR_EXEC ? " executing" : "");
51763+ return reqmode;
51764+ } else
51765+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
51766+ {
51767+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
51768+ reqmode & GR_READ ? " reading" : "",
51769+ reqmode & GR_WRITE ? " writing" : "",
51770+ reqmode & GR_EXEC ? " executing" : "");
51771+ return 0;
51772+ } else if (unlikely((mode & reqmode) != reqmode))
51773+ return 0;
51774+
51775+ return reqmode;
51776+}
51777+
51778+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
51779+{
51780+ __u32 mode;
51781+
51782+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
51783+
51784+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
51785+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
51786+ return mode;
51787+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
51788+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
51789+ return 0;
51790+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
51791+ return 0;
51792+
51793+ return (reqmode);
51794+}
51795+
51796+__u32
51797+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
51798+{
51799+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
51800+}
51801+
51802+__u32
51803+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
51804+{
51805+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
51806+}
51807+
51808+__u32
51809+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
51810+{
51811+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
51812+}
51813+
51814+__u32
51815+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
51816+{
51817+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
51818+}
51819+
51820+__u32
51821+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
51822+ mode_t mode)
51823+{
51824+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
51825+ return 1;
51826+
51827+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
51828+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
51829+ GR_FCHMOD_ACL_MSG);
51830+ } else {
51831+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
51832+ }
51833+}
51834+
51835+__u32
51836+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
51837+ mode_t mode)
51838+{
51839+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
51840+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
51841+ GR_CHMOD_ACL_MSG);
51842+ } else {
51843+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
51844+ }
51845+}
51846+
51847+__u32
51848+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
51849+{
51850+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
51851+}
51852+
51853+__u32
51854+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
51855+{
51856+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
51857+}
51858+
51859+__u32
51860+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
51861+{
51862+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
51863+}
51864+
51865+__u32
51866+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
51867+{
51868+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
51869+ GR_UNIXCONNECT_ACL_MSG);
51870+}
51871+
51872+/* hardlinks require at minimum create permission,
51873+ any additional privilege required is based on the
51874+ privilege of the file being linked to
51875+*/
51876+__u32
51877+gr_acl_handle_link(const struct dentry * new_dentry,
51878+ const struct dentry * parent_dentry,
51879+ const struct vfsmount * parent_mnt,
51880+ const struct dentry * old_dentry,
51881+ const struct vfsmount * old_mnt, const char *to)
51882+{
51883+ __u32 mode;
51884+ __u32 needmode = GR_CREATE | GR_LINK;
51885+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
51886+
51887+ mode =
51888+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
51889+ old_mnt);
51890+
51891+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
51892+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
51893+ return mode;
51894+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
51895+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
51896+ return 0;
51897+ } else if (unlikely((mode & needmode) != needmode))
51898+ return 0;
51899+
51900+ return 1;
51901+}
51902+
51903+__u32
51904+gr_acl_handle_symlink(const struct dentry * new_dentry,
51905+ const struct dentry * parent_dentry,
51906+ const struct vfsmount * parent_mnt, const char *from)
51907+{
51908+ __u32 needmode = GR_WRITE | GR_CREATE;
51909+ __u32 mode;
51910+
51911+ mode =
51912+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
51913+ GR_CREATE | GR_AUDIT_CREATE |
51914+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
51915+
51916+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
51917+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
51918+ return mode;
51919+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
51920+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
51921+ return 0;
51922+ } else if (unlikely((mode & needmode) != needmode))
51923+ return 0;
51924+
51925+ return (GR_WRITE | GR_CREATE);
51926+}
51927+
51928+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)
51929+{
51930+ __u32 mode;
51931+
51932+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
51933+
51934+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
51935+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
51936+ return mode;
51937+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
51938+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
51939+ return 0;
51940+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
51941+ return 0;
51942+
51943+ return (reqmode);
51944+}
51945+
51946+__u32
51947+gr_acl_handle_mknod(const struct dentry * new_dentry,
51948+ const struct dentry * parent_dentry,
51949+ const struct vfsmount * parent_mnt,
51950+ const int mode)
51951+{
51952+ __u32 reqmode = GR_WRITE | GR_CREATE;
51953+ if (unlikely(mode & (S_ISUID | S_ISGID)))
51954+ reqmode |= GR_SETID;
51955+
51956+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
51957+ reqmode, GR_MKNOD_ACL_MSG);
51958+}
51959+
51960+__u32
51961+gr_acl_handle_mkdir(const struct dentry *new_dentry,
51962+ const struct dentry *parent_dentry,
51963+ const struct vfsmount *parent_mnt)
51964+{
51965+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
51966+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
51967+}
51968+
51969+#define RENAME_CHECK_SUCCESS(old, new) \
51970+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
51971+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
51972+
51973+int
51974+gr_acl_handle_rename(struct dentry *new_dentry,
51975+ struct dentry *parent_dentry,
51976+ const struct vfsmount *parent_mnt,
51977+ struct dentry *old_dentry,
51978+ struct inode *old_parent_inode,
51979+ struct vfsmount *old_mnt, const char *newname)
51980+{
51981+ __u32 comp1, comp2;
51982+ int error = 0;
51983+
51984+ if (unlikely(!gr_acl_is_enabled()))
51985+ return 0;
51986+
51987+ if (!new_dentry->d_inode) {
51988+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
51989+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
51990+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
51991+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
51992+ GR_DELETE | GR_AUDIT_DELETE |
51993+ GR_AUDIT_READ | GR_AUDIT_WRITE |
51994+ GR_SUPPRESS, old_mnt);
51995+ } else {
51996+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
51997+ GR_CREATE | GR_DELETE |
51998+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
51999+ GR_AUDIT_READ | GR_AUDIT_WRITE |
52000+ GR_SUPPRESS, parent_mnt);
52001+ comp2 =
52002+ gr_search_file(old_dentry,
52003+ GR_READ | GR_WRITE | GR_AUDIT_READ |
52004+ GR_DELETE | GR_AUDIT_DELETE |
52005+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
52006+ }
52007+
52008+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
52009+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
52010+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
52011+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
52012+ && !(comp2 & GR_SUPPRESS)) {
52013+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
52014+ error = -EACCES;
52015+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
52016+ error = -EACCES;
52017+
52018+ return error;
52019+}
52020+
52021+void
52022+gr_acl_handle_exit(void)
52023+{
52024+ u16 id;
52025+ char *rolename;
52026+ struct file *exec_file;
52027+
52028+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
52029+ !(current->role->roletype & GR_ROLE_PERSIST))) {
52030+ id = current->acl_role_id;
52031+ rolename = current->role->rolename;
52032+ gr_set_acls(1);
52033+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
52034+ }
52035+
52036+ write_lock(&grsec_exec_file_lock);
52037+ exec_file = current->exec_file;
52038+ current->exec_file = NULL;
52039+ write_unlock(&grsec_exec_file_lock);
52040+
52041+ if (exec_file)
52042+ fput(exec_file);
52043+}
52044+
52045+int
52046+gr_acl_handle_procpidmem(const struct task_struct *task)
52047+{
52048+ if (unlikely(!gr_acl_is_enabled()))
52049+ return 0;
52050+
52051+ if (task != current && task->acl->mode & GR_PROTPROCFD)
52052+ return -EACCES;
52053+
52054+ return 0;
52055+}
52056diff -urNp linux-2.6.32.44/grsecurity/gracl_ip.c linux-2.6.32.44/grsecurity/gracl_ip.c
52057--- linux-2.6.32.44/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
52058+++ linux-2.6.32.44/grsecurity/gracl_ip.c 2011-04-17 15:56:46.000000000 -0400
52059@@ -0,0 +1,382 @@
52060+#include <linux/kernel.h>
52061+#include <asm/uaccess.h>
52062+#include <asm/errno.h>
52063+#include <net/sock.h>
52064+#include <linux/file.h>
52065+#include <linux/fs.h>
52066+#include <linux/net.h>
52067+#include <linux/in.h>
52068+#include <linux/skbuff.h>
52069+#include <linux/ip.h>
52070+#include <linux/udp.h>
52071+#include <linux/smp_lock.h>
52072+#include <linux/types.h>
52073+#include <linux/sched.h>
52074+#include <linux/netdevice.h>
52075+#include <linux/inetdevice.h>
52076+#include <linux/gracl.h>
52077+#include <linux/grsecurity.h>
52078+#include <linux/grinternal.h>
52079+
52080+#define GR_BIND 0x01
52081+#define GR_CONNECT 0x02
52082+#define GR_INVERT 0x04
52083+#define GR_BINDOVERRIDE 0x08
52084+#define GR_CONNECTOVERRIDE 0x10
52085+#define GR_SOCK_FAMILY 0x20
52086+
52087+static const char * gr_protocols[IPPROTO_MAX] = {
52088+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
52089+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
52090+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
52091+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
52092+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
52093+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
52094+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
52095+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
52096+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
52097+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
52098+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
52099+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
52100+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
52101+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
52102+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
52103+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
52104+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
52105+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
52106+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
52107+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
52108+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
52109+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
52110+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
52111+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
52112+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
52113+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
52114+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
52115+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
52116+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
52117+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
52118+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
52119+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
52120+ };
52121+
52122+static const char * gr_socktypes[SOCK_MAX] = {
52123+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
52124+ "unknown:7", "unknown:8", "unknown:9", "packet"
52125+ };
52126+
52127+static const char * gr_sockfamilies[AF_MAX+1] = {
52128+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
52129+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
52130+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
52131+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
52132+ };
52133+
52134+const char *
52135+gr_proto_to_name(unsigned char proto)
52136+{
52137+ return gr_protocols[proto];
52138+}
52139+
52140+const char *
52141+gr_socktype_to_name(unsigned char type)
52142+{
52143+ return gr_socktypes[type];
52144+}
52145+
52146+const char *
52147+gr_sockfamily_to_name(unsigned char family)
52148+{
52149+ return gr_sockfamilies[family];
52150+}
52151+
52152+int
52153+gr_search_socket(const int domain, const int type, const int protocol)
52154+{
52155+ struct acl_subject_label *curr;
52156+ const struct cred *cred = current_cred();
52157+
52158+ if (unlikely(!gr_acl_is_enabled()))
52159+ goto exit;
52160+
52161+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
52162+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
52163+ goto exit; // let the kernel handle it
52164+
52165+ curr = current->acl;
52166+
52167+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
52168+ /* the family is allowed, if this is PF_INET allow it only if
52169+ the extra sock type/protocol checks pass */
52170+ if (domain == PF_INET)
52171+ goto inet_check;
52172+ goto exit;
52173+ } else {
52174+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
52175+ __u32 fakeip = 0;
52176+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
52177+ current->role->roletype, cred->uid,
52178+ cred->gid, current->exec_file ?
52179+ gr_to_filename(current->exec_file->f_path.dentry,
52180+ current->exec_file->f_path.mnt) :
52181+ curr->filename, curr->filename,
52182+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
52183+ &current->signal->saved_ip);
52184+ goto exit;
52185+ }
52186+ goto exit_fail;
52187+ }
52188+
52189+inet_check:
52190+ /* the rest of this checking is for IPv4 only */
52191+ if (!curr->ips)
52192+ goto exit;
52193+
52194+ if ((curr->ip_type & (1 << type)) &&
52195+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
52196+ goto exit;
52197+
52198+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
52199+ /* we don't place acls on raw sockets , and sometimes
52200+ dgram/ip sockets are opened for ioctl and not
52201+ bind/connect, so we'll fake a bind learn log */
52202+ if (type == SOCK_RAW || type == SOCK_PACKET) {
52203+ __u32 fakeip = 0;
52204+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
52205+ current->role->roletype, cred->uid,
52206+ cred->gid, current->exec_file ?
52207+ gr_to_filename(current->exec_file->f_path.dentry,
52208+ current->exec_file->f_path.mnt) :
52209+ curr->filename, curr->filename,
52210+ &fakeip, 0, type,
52211+ protocol, GR_CONNECT, &current->signal->saved_ip);
52212+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
52213+ __u32 fakeip = 0;
52214+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
52215+ current->role->roletype, cred->uid,
52216+ cred->gid, current->exec_file ?
52217+ gr_to_filename(current->exec_file->f_path.dentry,
52218+ current->exec_file->f_path.mnt) :
52219+ curr->filename, curr->filename,
52220+ &fakeip, 0, type,
52221+ protocol, GR_BIND, &current->signal->saved_ip);
52222+ }
52223+ /* we'll log when they use connect or bind */
52224+ goto exit;
52225+ }
52226+
52227+exit_fail:
52228+ if (domain == PF_INET)
52229+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
52230+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
52231+ else
52232+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
52233+ gr_socktype_to_name(type), protocol);
52234+
52235+ return 0;
52236+exit:
52237+ return 1;
52238+}
52239+
52240+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)
52241+{
52242+ if ((ip->mode & mode) &&
52243+ (ip_port >= ip->low) &&
52244+ (ip_port <= ip->high) &&
52245+ ((ntohl(ip_addr) & our_netmask) ==
52246+ (ntohl(our_addr) & our_netmask))
52247+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
52248+ && (ip->type & (1 << type))) {
52249+ if (ip->mode & GR_INVERT)
52250+ return 2; // specifically denied
52251+ else
52252+ return 1; // allowed
52253+ }
52254+
52255+ return 0; // not specifically allowed, may continue parsing
52256+}
52257+
52258+static int
52259+gr_search_connectbind(const int full_mode, struct sock *sk,
52260+ struct sockaddr_in *addr, const int type)
52261+{
52262+ char iface[IFNAMSIZ] = {0};
52263+ struct acl_subject_label *curr;
52264+ struct acl_ip_label *ip;
52265+ struct inet_sock *isk;
52266+ struct net_device *dev;
52267+ struct in_device *idev;
52268+ unsigned long i;
52269+ int ret;
52270+ int mode = full_mode & (GR_BIND | GR_CONNECT);
52271+ __u32 ip_addr = 0;
52272+ __u32 our_addr;
52273+ __u32 our_netmask;
52274+ char *p;
52275+ __u16 ip_port = 0;
52276+ const struct cred *cred = current_cred();
52277+
52278+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
52279+ return 0;
52280+
52281+ curr = current->acl;
52282+ isk = inet_sk(sk);
52283+
52284+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
52285+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
52286+ addr->sin_addr.s_addr = curr->inaddr_any_override;
52287+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
52288+ struct sockaddr_in saddr;
52289+ int err;
52290+
52291+ saddr.sin_family = AF_INET;
52292+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
52293+ saddr.sin_port = isk->sport;
52294+
52295+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
52296+ if (err)
52297+ return err;
52298+
52299+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
52300+ if (err)
52301+ return err;
52302+ }
52303+
52304+ if (!curr->ips)
52305+ return 0;
52306+
52307+ ip_addr = addr->sin_addr.s_addr;
52308+ ip_port = ntohs(addr->sin_port);
52309+
52310+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
52311+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
52312+ current->role->roletype, cred->uid,
52313+ cred->gid, current->exec_file ?
52314+ gr_to_filename(current->exec_file->f_path.dentry,
52315+ current->exec_file->f_path.mnt) :
52316+ curr->filename, curr->filename,
52317+ &ip_addr, ip_port, type,
52318+ sk->sk_protocol, mode, &current->signal->saved_ip);
52319+ return 0;
52320+ }
52321+
52322+ for (i = 0; i < curr->ip_num; i++) {
52323+ ip = *(curr->ips + i);
52324+ if (ip->iface != NULL) {
52325+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
52326+ p = strchr(iface, ':');
52327+ if (p != NULL)
52328+ *p = '\0';
52329+ dev = dev_get_by_name(sock_net(sk), iface);
52330+ if (dev == NULL)
52331+ continue;
52332+ idev = in_dev_get(dev);
52333+ if (idev == NULL) {
52334+ dev_put(dev);
52335+ continue;
52336+ }
52337+ rcu_read_lock();
52338+ for_ifa(idev) {
52339+ if (!strcmp(ip->iface, ifa->ifa_label)) {
52340+ our_addr = ifa->ifa_address;
52341+ our_netmask = 0xffffffff;
52342+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
52343+ if (ret == 1) {
52344+ rcu_read_unlock();
52345+ in_dev_put(idev);
52346+ dev_put(dev);
52347+ return 0;
52348+ } else if (ret == 2) {
52349+ rcu_read_unlock();
52350+ in_dev_put(idev);
52351+ dev_put(dev);
52352+ goto denied;
52353+ }
52354+ }
52355+ } endfor_ifa(idev);
52356+ rcu_read_unlock();
52357+ in_dev_put(idev);
52358+ dev_put(dev);
52359+ } else {
52360+ our_addr = ip->addr;
52361+ our_netmask = ip->netmask;
52362+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
52363+ if (ret == 1)
52364+ return 0;
52365+ else if (ret == 2)
52366+ goto denied;
52367+ }
52368+ }
52369+
52370+denied:
52371+ if (mode == GR_BIND)
52372+ 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));
52373+ else if (mode == GR_CONNECT)
52374+ 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));
52375+
52376+ return -EACCES;
52377+}
52378+
52379+int
52380+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
52381+{
52382+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
52383+}
52384+
52385+int
52386+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
52387+{
52388+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
52389+}
52390+
52391+int gr_search_listen(struct socket *sock)
52392+{
52393+ struct sock *sk = sock->sk;
52394+ struct sockaddr_in addr;
52395+
52396+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
52397+ addr.sin_port = inet_sk(sk)->sport;
52398+
52399+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
52400+}
52401+
52402+int gr_search_accept(struct socket *sock)
52403+{
52404+ struct sock *sk = sock->sk;
52405+ struct sockaddr_in addr;
52406+
52407+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
52408+ addr.sin_port = inet_sk(sk)->sport;
52409+
52410+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
52411+}
52412+
52413+int
52414+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
52415+{
52416+ if (addr)
52417+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
52418+ else {
52419+ struct sockaddr_in sin;
52420+ const struct inet_sock *inet = inet_sk(sk);
52421+
52422+ sin.sin_addr.s_addr = inet->daddr;
52423+ sin.sin_port = inet->dport;
52424+
52425+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
52426+ }
52427+}
52428+
52429+int
52430+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
52431+{
52432+ struct sockaddr_in sin;
52433+
52434+ if (unlikely(skb->len < sizeof (struct udphdr)))
52435+ return 0; // skip this packet
52436+
52437+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
52438+ sin.sin_port = udp_hdr(skb)->source;
52439+
52440+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
52441+}
52442diff -urNp linux-2.6.32.44/grsecurity/gracl_learn.c linux-2.6.32.44/grsecurity/gracl_learn.c
52443--- linux-2.6.32.44/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
52444+++ linux-2.6.32.44/grsecurity/gracl_learn.c 2011-07-14 21:02:03.000000000 -0400
52445@@ -0,0 +1,208 @@
52446+#include <linux/kernel.h>
52447+#include <linux/mm.h>
52448+#include <linux/sched.h>
52449+#include <linux/poll.h>
52450+#include <linux/smp_lock.h>
52451+#include <linux/string.h>
52452+#include <linux/file.h>
52453+#include <linux/types.h>
52454+#include <linux/vmalloc.h>
52455+#include <linux/grinternal.h>
52456+
52457+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
52458+ size_t count, loff_t *ppos);
52459+extern int gr_acl_is_enabled(void);
52460+
52461+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
52462+static int gr_learn_attached;
52463+
52464+/* use a 512k buffer */
52465+#define LEARN_BUFFER_SIZE (512 * 1024)
52466+
52467+static DEFINE_SPINLOCK(gr_learn_lock);
52468+static DEFINE_MUTEX(gr_learn_user_mutex);
52469+
52470+/* we need to maintain two buffers, so that the kernel context of grlearn
52471+ uses a semaphore around the userspace copying, and the other kernel contexts
52472+ use a spinlock when copying into the buffer, since they cannot sleep
52473+*/
52474+static char *learn_buffer;
52475+static char *learn_buffer_user;
52476+static int learn_buffer_len;
52477+static int learn_buffer_user_len;
52478+
52479+static ssize_t
52480+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
52481+{
52482+ DECLARE_WAITQUEUE(wait, current);
52483+ ssize_t retval = 0;
52484+
52485+ add_wait_queue(&learn_wait, &wait);
52486+ set_current_state(TASK_INTERRUPTIBLE);
52487+ do {
52488+ mutex_lock(&gr_learn_user_mutex);
52489+ spin_lock(&gr_learn_lock);
52490+ if (learn_buffer_len)
52491+ break;
52492+ spin_unlock(&gr_learn_lock);
52493+ mutex_unlock(&gr_learn_user_mutex);
52494+ if (file->f_flags & O_NONBLOCK) {
52495+ retval = -EAGAIN;
52496+ goto out;
52497+ }
52498+ if (signal_pending(current)) {
52499+ retval = -ERESTARTSYS;
52500+ goto out;
52501+ }
52502+
52503+ schedule();
52504+ } while (1);
52505+
52506+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
52507+ learn_buffer_user_len = learn_buffer_len;
52508+ retval = learn_buffer_len;
52509+ learn_buffer_len = 0;
52510+
52511+ spin_unlock(&gr_learn_lock);
52512+
52513+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
52514+ retval = -EFAULT;
52515+
52516+ mutex_unlock(&gr_learn_user_mutex);
52517+out:
52518+ set_current_state(TASK_RUNNING);
52519+ remove_wait_queue(&learn_wait, &wait);
52520+ return retval;
52521+}
52522+
52523+static unsigned int
52524+poll_learn(struct file * file, poll_table * wait)
52525+{
52526+ poll_wait(file, &learn_wait, wait);
52527+
52528+ if (learn_buffer_len)
52529+ return (POLLIN | POLLRDNORM);
52530+
52531+ return 0;
52532+}
52533+
52534+void
52535+gr_clear_learn_entries(void)
52536+{
52537+ char *tmp;
52538+
52539+ mutex_lock(&gr_learn_user_mutex);
52540+ spin_lock(&gr_learn_lock);
52541+ tmp = learn_buffer;
52542+ learn_buffer = NULL;
52543+ spin_unlock(&gr_learn_lock);
52544+ if (tmp)
52545+ vfree(tmp);
52546+ if (learn_buffer_user != NULL) {
52547+ vfree(learn_buffer_user);
52548+ learn_buffer_user = NULL;
52549+ }
52550+ learn_buffer_len = 0;
52551+ mutex_unlock(&gr_learn_user_mutex);
52552+
52553+ return;
52554+}
52555+
52556+void
52557+gr_add_learn_entry(const char *fmt, ...)
52558+{
52559+ va_list args;
52560+ unsigned int len;
52561+
52562+ if (!gr_learn_attached)
52563+ return;
52564+
52565+ spin_lock(&gr_learn_lock);
52566+
52567+ /* leave a gap at the end so we know when it's "full" but don't have to
52568+ compute the exact length of the string we're trying to append
52569+ */
52570+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
52571+ spin_unlock(&gr_learn_lock);
52572+ wake_up_interruptible(&learn_wait);
52573+ return;
52574+ }
52575+ if (learn_buffer == NULL) {
52576+ spin_unlock(&gr_learn_lock);
52577+ return;
52578+ }
52579+
52580+ va_start(args, fmt);
52581+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
52582+ va_end(args);
52583+
52584+ learn_buffer_len += len + 1;
52585+
52586+ spin_unlock(&gr_learn_lock);
52587+ wake_up_interruptible(&learn_wait);
52588+
52589+ return;
52590+}
52591+
52592+static int
52593+open_learn(struct inode *inode, struct file *file)
52594+{
52595+ if (file->f_mode & FMODE_READ && gr_learn_attached)
52596+ return -EBUSY;
52597+ if (file->f_mode & FMODE_READ) {
52598+ int retval = 0;
52599+ mutex_lock(&gr_learn_user_mutex);
52600+ if (learn_buffer == NULL)
52601+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
52602+ if (learn_buffer_user == NULL)
52603+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
52604+ if (learn_buffer == NULL) {
52605+ retval = -ENOMEM;
52606+ goto out_error;
52607+ }
52608+ if (learn_buffer_user == NULL) {
52609+ retval = -ENOMEM;
52610+ goto out_error;
52611+ }
52612+ learn_buffer_len = 0;
52613+ learn_buffer_user_len = 0;
52614+ gr_learn_attached = 1;
52615+out_error:
52616+ mutex_unlock(&gr_learn_user_mutex);
52617+ return retval;
52618+ }
52619+ return 0;
52620+}
52621+
52622+static int
52623+close_learn(struct inode *inode, struct file *file)
52624+{
52625+ if (file->f_mode & FMODE_READ) {
52626+ char *tmp = NULL;
52627+ mutex_lock(&gr_learn_user_mutex);
52628+ spin_lock(&gr_learn_lock);
52629+ tmp = learn_buffer;
52630+ learn_buffer = NULL;
52631+ spin_unlock(&gr_learn_lock);
52632+ if (tmp)
52633+ vfree(tmp);
52634+ if (learn_buffer_user != NULL) {
52635+ vfree(learn_buffer_user);
52636+ learn_buffer_user = NULL;
52637+ }
52638+ learn_buffer_len = 0;
52639+ learn_buffer_user_len = 0;
52640+ gr_learn_attached = 0;
52641+ mutex_unlock(&gr_learn_user_mutex);
52642+ }
52643+
52644+ return 0;
52645+}
52646+
52647+const struct file_operations grsec_fops = {
52648+ .read = read_learn,
52649+ .write = write_grsec_handler,
52650+ .open = open_learn,
52651+ .release = close_learn,
52652+ .poll = poll_learn,
52653+};
52654diff -urNp linux-2.6.32.44/grsecurity/gracl_res.c linux-2.6.32.44/grsecurity/gracl_res.c
52655--- linux-2.6.32.44/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
52656+++ linux-2.6.32.44/grsecurity/gracl_res.c 2011-04-17 15:56:46.000000000 -0400
52657@@ -0,0 +1,67 @@
52658+#include <linux/kernel.h>
52659+#include <linux/sched.h>
52660+#include <linux/gracl.h>
52661+#include <linux/grinternal.h>
52662+
52663+static const char *restab_log[] = {
52664+ [RLIMIT_CPU] = "RLIMIT_CPU",
52665+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
52666+ [RLIMIT_DATA] = "RLIMIT_DATA",
52667+ [RLIMIT_STACK] = "RLIMIT_STACK",
52668+ [RLIMIT_CORE] = "RLIMIT_CORE",
52669+ [RLIMIT_RSS] = "RLIMIT_RSS",
52670+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
52671+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
52672+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
52673+ [RLIMIT_AS] = "RLIMIT_AS",
52674+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
52675+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
52676+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
52677+ [RLIMIT_NICE] = "RLIMIT_NICE",
52678+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
52679+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
52680+ [GR_CRASH_RES] = "RLIMIT_CRASH"
52681+};
52682+
52683+void
52684+gr_log_resource(const struct task_struct *task,
52685+ const int res, const unsigned long wanted, const int gt)
52686+{
52687+ const struct cred *cred;
52688+ unsigned long rlim;
52689+
52690+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
52691+ return;
52692+
52693+ // not yet supported resource
52694+ if (unlikely(!restab_log[res]))
52695+ return;
52696+
52697+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
52698+ rlim = task->signal->rlim[res].rlim_max;
52699+ else
52700+ rlim = task->signal->rlim[res].rlim_cur;
52701+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
52702+ return;
52703+
52704+ rcu_read_lock();
52705+ cred = __task_cred(task);
52706+
52707+ if (res == RLIMIT_NPROC &&
52708+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
52709+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
52710+ goto out_rcu_unlock;
52711+ else if (res == RLIMIT_MEMLOCK &&
52712+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
52713+ goto out_rcu_unlock;
52714+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
52715+ goto out_rcu_unlock;
52716+ rcu_read_unlock();
52717+
52718+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
52719+
52720+ return;
52721+out_rcu_unlock:
52722+ rcu_read_unlock();
52723+ return;
52724+}
52725diff -urNp linux-2.6.32.44/grsecurity/gracl_segv.c linux-2.6.32.44/grsecurity/gracl_segv.c
52726--- linux-2.6.32.44/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
52727+++ linux-2.6.32.44/grsecurity/gracl_segv.c 2011-04-17 15:56:46.000000000 -0400
52728@@ -0,0 +1,284 @@
52729+#include <linux/kernel.h>
52730+#include <linux/mm.h>
52731+#include <asm/uaccess.h>
52732+#include <asm/errno.h>
52733+#include <asm/mman.h>
52734+#include <net/sock.h>
52735+#include <linux/file.h>
52736+#include <linux/fs.h>
52737+#include <linux/net.h>
52738+#include <linux/in.h>
52739+#include <linux/smp_lock.h>
52740+#include <linux/slab.h>
52741+#include <linux/types.h>
52742+#include <linux/sched.h>
52743+#include <linux/timer.h>
52744+#include <linux/gracl.h>
52745+#include <linux/grsecurity.h>
52746+#include <linux/grinternal.h>
52747+
52748+static struct crash_uid *uid_set;
52749+static unsigned short uid_used;
52750+static DEFINE_SPINLOCK(gr_uid_lock);
52751+extern rwlock_t gr_inode_lock;
52752+extern struct acl_subject_label *
52753+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
52754+ struct acl_role_label *role);
52755+extern int gr_fake_force_sig(int sig, struct task_struct *t);
52756+
52757+int
52758+gr_init_uidset(void)
52759+{
52760+ uid_set =
52761+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
52762+ uid_used = 0;
52763+
52764+ return uid_set ? 1 : 0;
52765+}
52766+
52767+void
52768+gr_free_uidset(void)
52769+{
52770+ if (uid_set)
52771+ kfree(uid_set);
52772+
52773+ return;
52774+}
52775+
52776+int
52777+gr_find_uid(const uid_t uid)
52778+{
52779+ struct crash_uid *tmp = uid_set;
52780+ uid_t buid;
52781+ int low = 0, high = uid_used - 1, mid;
52782+
52783+ while (high >= low) {
52784+ mid = (low + high) >> 1;
52785+ buid = tmp[mid].uid;
52786+ if (buid == uid)
52787+ return mid;
52788+ if (buid > uid)
52789+ high = mid - 1;
52790+ if (buid < uid)
52791+ low = mid + 1;
52792+ }
52793+
52794+ return -1;
52795+}
52796+
52797+static __inline__ void
52798+gr_insertsort(void)
52799+{
52800+ unsigned short i, j;
52801+ struct crash_uid index;
52802+
52803+ for (i = 1; i < uid_used; i++) {
52804+ index = uid_set[i];
52805+ j = i;
52806+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
52807+ uid_set[j] = uid_set[j - 1];
52808+ j--;
52809+ }
52810+ uid_set[j] = index;
52811+ }
52812+
52813+ return;
52814+}
52815+
52816+static __inline__ void
52817+gr_insert_uid(const uid_t uid, const unsigned long expires)
52818+{
52819+ int loc;
52820+
52821+ if (uid_used == GR_UIDTABLE_MAX)
52822+ return;
52823+
52824+ loc = gr_find_uid(uid);
52825+
52826+ if (loc >= 0) {
52827+ uid_set[loc].expires = expires;
52828+ return;
52829+ }
52830+
52831+ uid_set[uid_used].uid = uid;
52832+ uid_set[uid_used].expires = expires;
52833+ uid_used++;
52834+
52835+ gr_insertsort();
52836+
52837+ return;
52838+}
52839+
52840+void
52841+gr_remove_uid(const unsigned short loc)
52842+{
52843+ unsigned short i;
52844+
52845+ for (i = loc + 1; i < uid_used; i++)
52846+ uid_set[i - 1] = uid_set[i];
52847+
52848+ uid_used--;
52849+
52850+ return;
52851+}
52852+
52853+int
52854+gr_check_crash_uid(const uid_t uid)
52855+{
52856+ int loc;
52857+ int ret = 0;
52858+
52859+ if (unlikely(!gr_acl_is_enabled()))
52860+ return 0;
52861+
52862+ spin_lock(&gr_uid_lock);
52863+ loc = gr_find_uid(uid);
52864+
52865+ if (loc < 0)
52866+ goto out_unlock;
52867+
52868+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
52869+ gr_remove_uid(loc);
52870+ else
52871+ ret = 1;
52872+
52873+out_unlock:
52874+ spin_unlock(&gr_uid_lock);
52875+ return ret;
52876+}
52877+
52878+static __inline__ int
52879+proc_is_setxid(const struct cred *cred)
52880+{
52881+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
52882+ cred->uid != cred->fsuid)
52883+ return 1;
52884+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
52885+ cred->gid != cred->fsgid)
52886+ return 1;
52887+
52888+ return 0;
52889+}
52890+
52891+void
52892+gr_handle_crash(struct task_struct *task, const int sig)
52893+{
52894+ struct acl_subject_label *curr;
52895+ struct acl_subject_label *curr2;
52896+ struct task_struct *tsk, *tsk2;
52897+ const struct cred *cred;
52898+ const struct cred *cred2;
52899+
52900+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
52901+ return;
52902+
52903+ if (unlikely(!gr_acl_is_enabled()))
52904+ return;
52905+
52906+ curr = task->acl;
52907+
52908+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
52909+ return;
52910+
52911+ if (time_before_eq(curr->expires, get_seconds())) {
52912+ curr->expires = 0;
52913+ curr->crashes = 0;
52914+ }
52915+
52916+ curr->crashes++;
52917+
52918+ if (!curr->expires)
52919+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
52920+
52921+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
52922+ time_after(curr->expires, get_seconds())) {
52923+ rcu_read_lock();
52924+ cred = __task_cred(task);
52925+ if (cred->uid && proc_is_setxid(cred)) {
52926+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
52927+ spin_lock(&gr_uid_lock);
52928+ gr_insert_uid(cred->uid, curr->expires);
52929+ spin_unlock(&gr_uid_lock);
52930+ curr->expires = 0;
52931+ curr->crashes = 0;
52932+ read_lock(&tasklist_lock);
52933+ do_each_thread(tsk2, tsk) {
52934+ cred2 = __task_cred(tsk);
52935+ if (tsk != task && cred2->uid == cred->uid)
52936+ gr_fake_force_sig(SIGKILL, tsk);
52937+ } while_each_thread(tsk2, tsk);
52938+ read_unlock(&tasklist_lock);
52939+ } else {
52940+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
52941+ read_lock(&tasklist_lock);
52942+ do_each_thread(tsk2, tsk) {
52943+ if (likely(tsk != task)) {
52944+ curr2 = tsk->acl;
52945+
52946+ if (curr2->device == curr->device &&
52947+ curr2->inode == curr->inode)
52948+ gr_fake_force_sig(SIGKILL, tsk);
52949+ }
52950+ } while_each_thread(tsk2, tsk);
52951+ read_unlock(&tasklist_lock);
52952+ }
52953+ rcu_read_unlock();
52954+ }
52955+
52956+ return;
52957+}
52958+
52959+int
52960+gr_check_crash_exec(const struct file *filp)
52961+{
52962+ struct acl_subject_label *curr;
52963+
52964+ if (unlikely(!gr_acl_is_enabled()))
52965+ return 0;
52966+
52967+ read_lock(&gr_inode_lock);
52968+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
52969+ filp->f_path.dentry->d_inode->i_sb->s_dev,
52970+ current->role);
52971+ read_unlock(&gr_inode_lock);
52972+
52973+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
52974+ (!curr->crashes && !curr->expires))
52975+ return 0;
52976+
52977+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
52978+ time_after(curr->expires, get_seconds()))
52979+ return 1;
52980+ else if (time_before_eq(curr->expires, get_seconds())) {
52981+ curr->crashes = 0;
52982+ curr->expires = 0;
52983+ }
52984+
52985+ return 0;
52986+}
52987+
52988+void
52989+gr_handle_alertkill(struct task_struct *task)
52990+{
52991+ struct acl_subject_label *curracl;
52992+ __u32 curr_ip;
52993+ struct task_struct *p, *p2;
52994+
52995+ if (unlikely(!gr_acl_is_enabled()))
52996+ return;
52997+
52998+ curracl = task->acl;
52999+ curr_ip = task->signal->curr_ip;
53000+
53001+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
53002+ read_lock(&tasklist_lock);
53003+ do_each_thread(p2, p) {
53004+ if (p->signal->curr_ip == curr_ip)
53005+ gr_fake_force_sig(SIGKILL, p);
53006+ } while_each_thread(p2, p);
53007+ read_unlock(&tasklist_lock);
53008+ } else if (curracl->mode & GR_KILLPROC)
53009+ gr_fake_force_sig(SIGKILL, task);
53010+
53011+ return;
53012+}
53013diff -urNp linux-2.6.32.44/grsecurity/gracl_shm.c linux-2.6.32.44/grsecurity/gracl_shm.c
53014--- linux-2.6.32.44/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
53015+++ linux-2.6.32.44/grsecurity/gracl_shm.c 2011-04-17 15:56:46.000000000 -0400
53016@@ -0,0 +1,40 @@
53017+#include <linux/kernel.h>
53018+#include <linux/mm.h>
53019+#include <linux/sched.h>
53020+#include <linux/file.h>
53021+#include <linux/ipc.h>
53022+#include <linux/gracl.h>
53023+#include <linux/grsecurity.h>
53024+#include <linux/grinternal.h>
53025+
53026+int
53027+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
53028+ const time_t shm_createtime, const uid_t cuid, const int shmid)
53029+{
53030+ struct task_struct *task;
53031+
53032+ if (!gr_acl_is_enabled())
53033+ return 1;
53034+
53035+ rcu_read_lock();
53036+ read_lock(&tasklist_lock);
53037+
53038+ task = find_task_by_vpid(shm_cprid);
53039+
53040+ if (unlikely(!task))
53041+ task = find_task_by_vpid(shm_lapid);
53042+
53043+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
53044+ (task->pid == shm_lapid)) &&
53045+ (task->acl->mode & GR_PROTSHM) &&
53046+ (task->acl != current->acl))) {
53047+ read_unlock(&tasklist_lock);
53048+ rcu_read_unlock();
53049+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
53050+ return 0;
53051+ }
53052+ read_unlock(&tasklist_lock);
53053+ rcu_read_unlock();
53054+
53055+ return 1;
53056+}
53057diff -urNp linux-2.6.32.44/grsecurity/grsec_chdir.c linux-2.6.32.44/grsecurity/grsec_chdir.c
53058--- linux-2.6.32.44/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
53059+++ linux-2.6.32.44/grsecurity/grsec_chdir.c 2011-04-17 15:56:46.000000000 -0400
53060@@ -0,0 +1,19 @@
53061+#include <linux/kernel.h>
53062+#include <linux/sched.h>
53063+#include <linux/fs.h>
53064+#include <linux/file.h>
53065+#include <linux/grsecurity.h>
53066+#include <linux/grinternal.h>
53067+
53068+void
53069+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
53070+{
53071+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
53072+ if ((grsec_enable_chdir && grsec_enable_group &&
53073+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
53074+ !grsec_enable_group)) {
53075+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
53076+ }
53077+#endif
53078+ return;
53079+}
53080diff -urNp linux-2.6.32.44/grsecurity/grsec_chroot.c linux-2.6.32.44/grsecurity/grsec_chroot.c
53081--- linux-2.6.32.44/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
53082+++ linux-2.6.32.44/grsecurity/grsec_chroot.c 2011-07-18 17:14:10.000000000 -0400
53083@@ -0,0 +1,384 @@
53084+#include <linux/kernel.h>
53085+#include <linux/module.h>
53086+#include <linux/sched.h>
53087+#include <linux/file.h>
53088+#include <linux/fs.h>
53089+#include <linux/mount.h>
53090+#include <linux/types.h>
53091+#include <linux/pid_namespace.h>
53092+#include <linux/grsecurity.h>
53093+#include <linux/grinternal.h>
53094+
53095+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
53096+{
53097+#ifdef CONFIG_GRKERNSEC
53098+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
53099+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
53100+ task->gr_is_chrooted = 1;
53101+ else
53102+ task->gr_is_chrooted = 0;
53103+
53104+ task->gr_chroot_dentry = path->dentry;
53105+#endif
53106+ return;
53107+}
53108+
53109+void gr_clear_chroot_entries(struct task_struct *task)
53110+{
53111+#ifdef CONFIG_GRKERNSEC
53112+ task->gr_is_chrooted = 0;
53113+ task->gr_chroot_dentry = NULL;
53114+#endif
53115+ return;
53116+}
53117+
53118+int
53119+gr_handle_chroot_unix(const pid_t pid)
53120+{
53121+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
53122+ struct task_struct *p;
53123+
53124+ if (unlikely(!grsec_enable_chroot_unix))
53125+ return 1;
53126+
53127+ if (likely(!proc_is_chrooted(current)))
53128+ return 1;
53129+
53130+ rcu_read_lock();
53131+ read_lock(&tasklist_lock);
53132+
53133+ p = find_task_by_vpid_unrestricted(pid);
53134+ if (unlikely(p && !have_same_root(current, p))) {
53135+ read_unlock(&tasklist_lock);
53136+ rcu_read_unlock();
53137+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
53138+ return 0;
53139+ }
53140+ read_unlock(&tasklist_lock);
53141+ rcu_read_unlock();
53142+#endif
53143+ return 1;
53144+}
53145+
53146+int
53147+gr_handle_chroot_nice(void)
53148+{
53149+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
53150+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
53151+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
53152+ return -EPERM;
53153+ }
53154+#endif
53155+ return 0;
53156+}
53157+
53158+int
53159+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
53160+{
53161+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
53162+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
53163+ && proc_is_chrooted(current)) {
53164+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
53165+ return -EACCES;
53166+ }
53167+#endif
53168+ return 0;
53169+}
53170+
53171+int
53172+gr_handle_chroot_rawio(const struct inode *inode)
53173+{
53174+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53175+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53176+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
53177+ return 1;
53178+#endif
53179+ return 0;
53180+}
53181+
53182+int
53183+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
53184+{
53185+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
53186+ struct task_struct *p;
53187+ int ret = 0;
53188+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
53189+ return ret;
53190+
53191+ read_lock(&tasklist_lock);
53192+ do_each_pid_task(pid, type, p) {
53193+ if (!have_same_root(current, p)) {
53194+ ret = 1;
53195+ goto out;
53196+ }
53197+ } while_each_pid_task(pid, type, p);
53198+out:
53199+ read_unlock(&tasklist_lock);
53200+ return ret;
53201+#endif
53202+ return 0;
53203+}
53204+
53205+int
53206+gr_pid_is_chrooted(struct task_struct *p)
53207+{
53208+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
53209+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
53210+ return 0;
53211+
53212+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
53213+ !have_same_root(current, p)) {
53214+ return 1;
53215+ }
53216+#endif
53217+ return 0;
53218+}
53219+
53220+EXPORT_SYMBOL(gr_pid_is_chrooted);
53221+
53222+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
53223+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
53224+{
53225+ struct dentry *dentry = (struct dentry *)u_dentry;
53226+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
53227+ struct dentry *realroot;
53228+ struct vfsmount *realrootmnt;
53229+ struct dentry *currentroot;
53230+ struct vfsmount *currentmnt;
53231+ struct task_struct *reaper = &init_task;
53232+ int ret = 1;
53233+
53234+ read_lock(&reaper->fs->lock);
53235+ realrootmnt = mntget(reaper->fs->root.mnt);
53236+ realroot = dget(reaper->fs->root.dentry);
53237+ read_unlock(&reaper->fs->lock);
53238+
53239+ read_lock(&current->fs->lock);
53240+ currentmnt = mntget(current->fs->root.mnt);
53241+ currentroot = dget(current->fs->root.dentry);
53242+ read_unlock(&current->fs->lock);
53243+
53244+ spin_lock(&dcache_lock);
53245+ for (;;) {
53246+ if (unlikely((dentry == realroot && mnt == realrootmnt)
53247+ || (dentry == currentroot && mnt == currentmnt)))
53248+ break;
53249+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
53250+ if (mnt->mnt_parent == mnt)
53251+ break;
53252+ dentry = mnt->mnt_mountpoint;
53253+ mnt = mnt->mnt_parent;
53254+ continue;
53255+ }
53256+ dentry = dentry->d_parent;
53257+ }
53258+ spin_unlock(&dcache_lock);
53259+
53260+ dput(currentroot);
53261+ mntput(currentmnt);
53262+
53263+ /* access is outside of chroot */
53264+ if (dentry == realroot && mnt == realrootmnt)
53265+ ret = 0;
53266+
53267+ dput(realroot);
53268+ mntput(realrootmnt);
53269+ return ret;
53270+}
53271+#endif
53272+
53273+int
53274+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
53275+{
53276+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
53277+ if (!grsec_enable_chroot_fchdir)
53278+ return 1;
53279+
53280+ if (!proc_is_chrooted(current))
53281+ return 1;
53282+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
53283+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
53284+ return 0;
53285+ }
53286+#endif
53287+ return 1;
53288+}
53289+
53290+int
53291+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
53292+ const time_t shm_createtime)
53293+{
53294+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
53295+ struct task_struct *p;
53296+ time_t starttime;
53297+
53298+ if (unlikely(!grsec_enable_chroot_shmat))
53299+ return 1;
53300+
53301+ if (likely(!proc_is_chrooted(current)))
53302+ return 1;
53303+
53304+ rcu_read_lock();
53305+ read_lock(&tasklist_lock);
53306+
53307+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
53308+ starttime = p->start_time.tv_sec;
53309+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
53310+ if (have_same_root(current, p)) {
53311+ goto allow;
53312+ } else {
53313+ read_unlock(&tasklist_lock);
53314+ rcu_read_unlock();
53315+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
53316+ return 0;
53317+ }
53318+ }
53319+ /* creator exited, pid reuse, fall through to next check */
53320+ }
53321+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
53322+ if (unlikely(!have_same_root(current, p))) {
53323+ read_unlock(&tasklist_lock);
53324+ rcu_read_unlock();
53325+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
53326+ return 0;
53327+ }
53328+ }
53329+
53330+allow:
53331+ read_unlock(&tasklist_lock);
53332+ rcu_read_unlock();
53333+#endif
53334+ return 1;
53335+}
53336+
53337+void
53338+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
53339+{
53340+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
53341+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
53342+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
53343+#endif
53344+ return;
53345+}
53346+
53347+int
53348+gr_handle_chroot_mknod(const struct dentry *dentry,
53349+ const struct vfsmount *mnt, const int mode)
53350+{
53351+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
53352+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
53353+ proc_is_chrooted(current)) {
53354+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
53355+ return -EPERM;
53356+ }
53357+#endif
53358+ return 0;
53359+}
53360+
53361+int
53362+gr_handle_chroot_mount(const struct dentry *dentry,
53363+ const struct vfsmount *mnt, const char *dev_name)
53364+{
53365+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
53366+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
53367+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
53368+ return -EPERM;
53369+ }
53370+#endif
53371+ return 0;
53372+}
53373+
53374+int
53375+gr_handle_chroot_pivot(void)
53376+{
53377+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
53378+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
53379+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
53380+ return -EPERM;
53381+ }
53382+#endif
53383+ return 0;
53384+}
53385+
53386+int
53387+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
53388+{
53389+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
53390+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
53391+ !gr_is_outside_chroot(dentry, mnt)) {
53392+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
53393+ return -EPERM;
53394+ }
53395+#endif
53396+ return 0;
53397+}
53398+
53399+int
53400+gr_handle_chroot_caps(struct path *path)
53401+{
53402+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53403+ if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
53404+ (init_task.fs->root.dentry != path->dentry) &&
53405+ (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
53406+
53407+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
53408+ const struct cred *old = current_cred();
53409+ struct cred *new = prepare_creds();
53410+ if (new == NULL)
53411+ return 1;
53412+
53413+ new->cap_permitted = cap_drop(old->cap_permitted,
53414+ chroot_caps);
53415+ new->cap_inheritable = cap_drop(old->cap_inheritable,
53416+ chroot_caps);
53417+ new->cap_effective = cap_drop(old->cap_effective,
53418+ chroot_caps);
53419+
53420+ commit_creds(new);
53421+
53422+ return 0;
53423+ }
53424+#endif
53425+ return 0;
53426+}
53427+
53428+int
53429+gr_handle_chroot_sysctl(const int op)
53430+{
53431+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
53432+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
53433+ && (op & MAY_WRITE))
53434+ return -EACCES;
53435+#endif
53436+ return 0;
53437+}
53438+
53439+void
53440+gr_handle_chroot_chdir(struct path *path)
53441+{
53442+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
53443+ if (grsec_enable_chroot_chdir)
53444+ set_fs_pwd(current->fs, path);
53445+#endif
53446+ return;
53447+}
53448+
53449+int
53450+gr_handle_chroot_chmod(const struct dentry *dentry,
53451+ const struct vfsmount *mnt, const int mode)
53452+{
53453+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
53454+ /* allow chmod +s on directories, but not on files */
53455+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
53456+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
53457+ proc_is_chrooted(current)) {
53458+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
53459+ return -EPERM;
53460+ }
53461+#endif
53462+ return 0;
53463+}
53464+
53465+#ifdef CONFIG_SECURITY
53466+EXPORT_SYMBOL(gr_handle_chroot_caps);
53467+#endif
53468diff -urNp linux-2.6.32.44/grsecurity/grsec_disabled.c linux-2.6.32.44/grsecurity/grsec_disabled.c
53469--- linux-2.6.32.44/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
53470+++ linux-2.6.32.44/grsecurity/grsec_disabled.c 2011-04-17 15:56:46.000000000 -0400
53471@@ -0,0 +1,447 @@
53472+#include <linux/kernel.h>
53473+#include <linux/module.h>
53474+#include <linux/sched.h>
53475+#include <linux/file.h>
53476+#include <linux/fs.h>
53477+#include <linux/kdev_t.h>
53478+#include <linux/net.h>
53479+#include <linux/in.h>
53480+#include <linux/ip.h>
53481+#include <linux/skbuff.h>
53482+#include <linux/sysctl.h>
53483+
53484+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53485+void
53486+pax_set_initial_flags(struct linux_binprm *bprm)
53487+{
53488+ return;
53489+}
53490+#endif
53491+
53492+#ifdef CONFIG_SYSCTL
53493+__u32
53494+gr_handle_sysctl(const struct ctl_table * table, const int op)
53495+{
53496+ return 0;
53497+}
53498+#endif
53499+
53500+#ifdef CONFIG_TASKSTATS
53501+int gr_is_taskstats_denied(int pid)
53502+{
53503+ return 0;
53504+}
53505+#endif
53506+
53507+int
53508+gr_acl_is_enabled(void)
53509+{
53510+ return 0;
53511+}
53512+
53513+int
53514+gr_handle_rawio(const struct inode *inode)
53515+{
53516+ return 0;
53517+}
53518+
53519+void
53520+gr_acl_handle_psacct(struct task_struct *task, const long code)
53521+{
53522+ return;
53523+}
53524+
53525+int
53526+gr_handle_ptrace(struct task_struct *task, const long request)
53527+{
53528+ return 0;
53529+}
53530+
53531+int
53532+gr_handle_proc_ptrace(struct task_struct *task)
53533+{
53534+ return 0;
53535+}
53536+
53537+void
53538+gr_learn_resource(const struct task_struct *task,
53539+ const int res, const unsigned long wanted, const int gt)
53540+{
53541+ return;
53542+}
53543+
53544+int
53545+gr_set_acls(const int type)
53546+{
53547+ return 0;
53548+}
53549+
53550+int
53551+gr_check_hidden_task(const struct task_struct *tsk)
53552+{
53553+ return 0;
53554+}
53555+
53556+int
53557+gr_check_protected_task(const struct task_struct *task)
53558+{
53559+ return 0;
53560+}
53561+
53562+int
53563+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53564+{
53565+ return 0;
53566+}
53567+
53568+void
53569+gr_copy_label(struct task_struct *tsk)
53570+{
53571+ return;
53572+}
53573+
53574+void
53575+gr_set_pax_flags(struct task_struct *task)
53576+{
53577+ return;
53578+}
53579+
53580+int
53581+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53582+ const int unsafe_share)
53583+{
53584+ return 0;
53585+}
53586+
53587+void
53588+gr_handle_delete(const ino_t ino, const dev_t dev)
53589+{
53590+ return;
53591+}
53592+
53593+void
53594+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53595+{
53596+ return;
53597+}
53598+
53599+void
53600+gr_handle_crash(struct task_struct *task, const int sig)
53601+{
53602+ return;
53603+}
53604+
53605+int
53606+gr_check_crash_exec(const struct file *filp)
53607+{
53608+ return 0;
53609+}
53610+
53611+int
53612+gr_check_crash_uid(const uid_t uid)
53613+{
53614+ return 0;
53615+}
53616+
53617+void
53618+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53619+ struct dentry *old_dentry,
53620+ struct dentry *new_dentry,
53621+ struct vfsmount *mnt, const __u8 replace)
53622+{
53623+ return;
53624+}
53625+
53626+int
53627+gr_search_socket(const int family, const int type, const int protocol)
53628+{
53629+ return 1;
53630+}
53631+
53632+int
53633+gr_search_connectbind(const int mode, const struct socket *sock,
53634+ const struct sockaddr_in *addr)
53635+{
53636+ return 0;
53637+}
53638+
53639+int
53640+gr_is_capable(const int cap)
53641+{
53642+ return 1;
53643+}
53644+
53645+int
53646+gr_is_capable_nolog(const int cap)
53647+{
53648+ return 1;
53649+}
53650+
53651+void
53652+gr_handle_alertkill(struct task_struct *task)
53653+{
53654+ return;
53655+}
53656+
53657+__u32
53658+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
53659+{
53660+ return 1;
53661+}
53662+
53663+__u32
53664+gr_acl_handle_hidden_file(const struct dentry * dentry,
53665+ const struct vfsmount * mnt)
53666+{
53667+ return 1;
53668+}
53669+
53670+__u32
53671+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
53672+ const int fmode)
53673+{
53674+ return 1;
53675+}
53676+
53677+__u32
53678+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
53679+{
53680+ return 1;
53681+}
53682+
53683+__u32
53684+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
53685+{
53686+ return 1;
53687+}
53688+
53689+int
53690+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
53691+ unsigned int *vm_flags)
53692+{
53693+ return 1;
53694+}
53695+
53696+__u32
53697+gr_acl_handle_truncate(const struct dentry * dentry,
53698+ const struct vfsmount * mnt)
53699+{
53700+ return 1;
53701+}
53702+
53703+__u32
53704+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
53705+{
53706+ return 1;
53707+}
53708+
53709+__u32
53710+gr_acl_handle_access(const struct dentry * dentry,
53711+ const struct vfsmount * mnt, const int fmode)
53712+{
53713+ return 1;
53714+}
53715+
53716+__u32
53717+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
53718+ mode_t mode)
53719+{
53720+ return 1;
53721+}
53722+
53723+__u32
53724+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
53725+ mode_t mode)
53726+{
53727+ return 1;
53728+}
53729+
53730+__u32
53731+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
53732+{
53733+ return 1;
53734+}
53735+
53736+__u32
53737+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
53738+{
53739+ return 1;
53740+}
53741+
53742+void
53743+grsecurity_init(void)
53744+{
53745+ return;
53746+}
53747+
53748+__u32
53749+gr_acl_handle_mknod(const struct dentry * new_dentry,
53750+ const struct dentry * parent_dentry,
53751+ const struct vfsmount * parent_mnt,
53752+ const int mode)
53753+{
53754+ return 1;
53755+}
53756+
53757+__u32
53758+gr_acl_handle_mkdir(const struct dentry * new_dentry,
53759+ const struct dentry * parent_dentry,
53760+ const struct vfsmount * parent_mnt)
53761+{
53762+ return 1;
53763+}
53764+
53765+__u32
53766+gr_acl_handle_symlink(const struct dentry * new_dentry,
53767+ const struct dentry * parent_dentry,
53768+ const struct vfsmount * parent_mnt, const char *from)
53769+{
53770+ return 1;
53771+}
53772+
53773+__u32
53774+gr_acl_handle_link(const struct dentry * new_dentry,
53775+ const struct dentry * parent_dentry,
53776+ const struct vfsmount * parent_mnt,
53777+ const struct dentry * old_dentry,
53778+ const struct vfsmount * old_mnt, const char *to)
53779+{
53780+ return 1;
53781+}
53782+
53783+int
53784+gr_acl_handle_rename(const struct dentry *new_dentry,
53785+ const struct dentry *parent_dentry,
53786+ const struct vfsmount *parent_mnt,
53787+ const struct dentry *old_dentry,
53788+ const struct inode *old_parent_inode,
53789+ const struct vfsmount *old_mnt, const char *newname)
53790+{
53791+ return 0;
53792+}
53793+
53794+int
53795+gr_acl_handle_filldir(const struct file *file, const char *name,
53796+ const int namelen, const ino_t ino)
53797+{
53798+ return 1;
53799+}
53800+
53801+int
53802+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
53803+ const time_t shm_createtime, const uid_t cuid, const int shmid)
53804+{
53805+ return 1;
53806+}
53807+
53808+int
53809+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
53810+{
53811+ return 0;
53812+}
53813+
53814+int
53815+gr_search_accept(const struct socket *sock)
53816+{
53817+ return 0;
53818+}
53819+
53820+int
53821+gr_search_listen(const struct socket *sock)
53822+{
53823+ return 0;
53824+}
53825+
53826+int
53827+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
53828+{
53829+ return 0;
53830+}
53831+
53832+__u32
53833+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
53834+{
53835+ return 1;
53836+}
53837+
53838+__u32
53839+gr_acl_handle_creat(const struct dentry * dentry,
53840+ const struct dentry * p_dentry,
53841+ const struct vfsmount * p_mnt, const int fmode,
53842+ const int imode)
53843+{
53844+ return 1;
53845+}
53846+
53847+void
53848+gr_acl_handle_exit(void)
53849+{
53850+ return;
53851+}
53852+
53853+int
53854+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53855+{
53856+ return 1;
53857+}
53858+
53859+void
53860+gr_set_role_label(const uid_t uid, const gid_t gid)
53861+{
53862+ return;
53863+}
53864+
53865+int
53866+gr_acl_handle_procpidmem(const struct task_struct *task)
53867+{
53868+ return 0;
53869+}
53870+
53871+int
53872+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
53873+{
53874+ return 0;
53875+}
53876+
53877+int
53878+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
53879+{
53880+ return 0;
53881+}
53882+
53883+void
53884+gr_set_kernel_label(struct task_struct *task)
53885+{
53886+ return;
53887+}
53888+
53889+int
53890+gr_check_user_change(int real, int effective, int fs)
53891+{
53892+ return 0;
53893+}
53894+
53895+int
53896+gr_check_group_change(int real, int effective, int fs)
53897+{
53898+ return 0;
53899+}
53900+
53901+int gr_acl_enable_at_secure(void)
53902+{
53903+ return 0;
53904+}
53905+
53906+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53907+{
53908+ return dentry->d_inode->i_sb->s_dev;
53909+}
53910+
53911+EXPORT_SYMBOL(gr_is_capable);
53912+EXPORT_SYMBOL(gr_is_capable_nolog);
53913+EXPORT_SYMBOL(gr_learn_resource);
53914+EXPORT_SYMBOL(gr_set_kernel_label);
53915+#ifdef CONFIG_SECURITY
53916+EXPORT_SYMBOL(gr_check_user_change);
53917+EXPORT_SYMBOL(gr_check_group_change);
53918+#endif
53919diff -urNp linux-2.6.32.44/grsecurity/grsec_exec.c linux-2.6.32.44/grsecurity/grsec_exec.c
53920--- linux-2.6.32.44/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
53921+++ linux-2.6.32.44/grsecurity/grsec_exec.c 2011-08-11 19:57:19.000000000 -0400
53922@@ -0,0 +1,132 @@
53923+#include <linux/kernel.h>
53924+#include <linux/sched.h>
53925+#include <linux/file.h>
53926+#include <linux/binfmts.h>
53927+#include <linux/smp_lock.h>
53928+#include <linux/fs.h>
53929+#include <linux/types.h>
53930+#include <linux/grdefs.h>
53931+#include <linux/grinternal.h>
53932+#include <linux/capability.h>
53933+#include <linux/compat.h>
53934+
53935+#include <asm/uaccess.h>
53936+
53937+#ifdef CONFIG_GRKERNSEC_EXECLOG
53938+static char gr_exec_arg_buf[132];
53939+static DEFINE_MUTEX(gr_exec_arg_mutex);
53940+#endif
53941+
53942+void
53943+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
53944+{
53945+#ifdef CONFIG_GRKERNSEC_EXECLOG
53946+ char *grarg = gr_exec_arg_buf;
53947+ unsigned int i, x, execlen = 0;
53948+ char c;
53949+
53950+ if (!((grsec_enable_execlog && grsec_enable_group &&
53951+ in_group_p(grsec_audit_gid))
53952+ || (grsec_enable_execlog && !grsec_enable_group)))
53953+ return;
53954+
53955+ mutex_lock(&gr_exec_arg_mutex);
53956+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
53957+
53958+ if (unlikely(argv == NULL))
53959+ goto log;
53960+
53961+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
53962+ const char __user *p;
53963+ unsigned int len;
53964+
53965+ if (copy_from_user(&p, argv + i, sizeof(p)))
53966+ goto log;
53967+ if (!p)
53968+ goto log;
53969+ len = strnlen_user(p, 128 - execlen);
53970+ if (len > 128 - execlen)
53971+ len = 128 - execlen;
53972+ else if (len > 0)
53973+ len--;
53974+ if (copy_from_user(grarg + execlen, p, len))
53975+ goto log;
53976+
53977+ /* rewrite unprintable characters */
53978+ for (x = 0; x < len; x++) {
53979+ c = *(grarg + execlen + x);
53980+ if (c < 32 || c > 126)
53981+ *(grarg + execlen + x) = ' ';
53982+ }
53983+
53984+ execlen += len;
53985+ *(grarg + execlen) = ' ';
53986+ *(grarg + execlen + 1) = '\0';
53987+ execlen++;
53988+ }
53989+
53990+ log:
53991+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
53992+ bprm->file->f_path.mnt, grarg);
53993+ mutex_unlock(&gr_exec_arg_mutex);
53994+#endif
53995+ return;
53996+}
53997+
53998+#ifdef CONFIG_COMPAT
53999+void
54000+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
54001+{
54002+#ifdef CONFIG_GRKERNSEC_EXECLOG
54003+ char *grarg = gr_exec_arg_buf;
54004+ unsigned int i, x, execlen = 0;
54005+ char c;
54006+
54007+ if (!((grsec_enable_execlog && grsec_enable_group &&
54008+ in_group_p(grsec_audit_gid))
54009+ || (grsec_enable_execlog && !grsec_enable_group)))
54010+ return;
54011+
54012+ mutex_lock(&gr_exec_arg_mutex);
54013+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
54014+
54015+ if (unlikely(argv == NULL))
54016+ goto log;
54017+
54018+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
54019+ compat_uptr_t p;
54020+ unsigned int len;
54021+
54022+ if (get_user(p, argv + i))
54023+ goto log;
54024+ len = strnlen_user(compat_ptr(p), 128 - execlen);
54025+ if (len > 128 - execlen)
54026+ len = 128 - execlen;
54027+ else if (len > 0)
54028+ len--;
54029+ else
54030+ goto log;
54031+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
54032+ goto log;
54033+
54034+ /* rewrite unprintable characters */
54035+ for (x = 0; x < len; x++) {
54036+ c = *(grarg + execlen + x);
54037+ if (c < 32 || c > 126)
54038+ *(grarg + execlen + x) = ' ';
54039+ }
54040+
54041+ execlen += len;
54042+ *(grarg + execlen) = ' ';
54043+ *(grarg + execlen + 1) = '\0';
54044+ execlen++;
54045+ }
54046+
54047+ log:
54048+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
54049+ bprm->file->f_path.mnt, grarg);
54050+ mutex_unlock(&gr_exec_arg_mutex);
54051+#endif
54052+ return;
54053+}
54054+#endif
54055diff -urNp linux-2.6.32.44/grsecurity/grsec_fifo.c linux-2.6.32.44/grsecurity/grsec_fifo.c
54056--- linux-2.6.32.44/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
54057+++ linux-2.6.32.44/grsecurity/grsec_fifo.c 2011-04-17 15:56:46.000000000 -0400
54058@@ -0,0 +1,24 @@
54059+#include <linux/kernel.h>
54060+#include <linux/sched.h>
54061+#include <linux/fs.h>
54062+#include <linux/file.h>
54063+#include <linux/grinternal.h>
54064+
54065+int
54066+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
54067+ const struct dentry *dir, const int flag, const int acc_mode)
54068+{
54069+#ifdef CONFIG_GRKERNSEC_FIFO
54070+ const struct cred *cred = current_cred();
54071+
54072+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
54073+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
54074+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
54075+ (cred->fsuid != dentry->d_inode->i_uid)) {
54076+ if (!inode_permission(dentry->d_inode, acc_mode))
54077+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
54078+ return -EACCES;
54079+ }
54080+#endif
54081+ return 0;
54082+}
54083diff -urNp linux-2.6.32.44/grsecurity/grsec_fork.c linux-2.6.32.44/grsecurity/grsec_fork.c
54084--- linux-2.6.32.44/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
54085+++ linux-2.6.32.44/grsecurity/grsec_fork.c 2011-04-17 15:56:46.000000000 -0400
54086@@ -0,0 +1,23 @@
54087+#include <linux/kernel.h>
54088+#include <linux/sched.h>
54089+#include <linux/grsecurity.h>
54090+#include <linux/grinternal.h>
54091+#include <linux/errno.h>
54092+
54093+void
54094+gr_log_forkfail(const int retval)
54095+{
54096+#ifdef CONFIG_GRKERNSEC_FORKFAIL
54097+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
54098+ switch (retval) {
54099+ case -EAGAIN:
54100+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
54101+ break;
54102+ case -ENOMEM:
54103+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
54104+ break;
54105+ }
54106+ }
54107+#endif
54108+ return;
54109+}
54110diff -urNp linux-2.6.32.44/grsecurity/grsec_init.c linux-2.6.32.44/grsecurity/grsec_init.c
54111--- linux-2.6.32.44/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
54112+++ linux-2.6.32.44/grsecurity/grsec_init.c 2011-08-11 19:57:42.000000000 -0400
54113@@ -0,0 +1,270 @@
54114+#include <linux/kernel.h>
54115+#include <linux/sched.h>
54116+#include <linux/mm.h>
54117+#include <linux/smp_lock.h>
54118+#include <linux/gracl.h>
54119+#include <linux/slab.h>
54120+#include <linux/vmalloc.h>
54121+#include <linux/percpu.h>
54122+#include <linux/module.h>
54123+
54124+int grsec_enable_brute;
54125+int grsec_enable_link;
54126+int grsec_enable_dmesg;
54127+int grsec_enable_harden_ptrace;
54128+int grsec_enable_fifo;
54129+int grsec_enable_execlog;
54130+int grsec_enable_signal;
54131+int grsec_enable_forkfail;
54132+int grsec_enable_audit_ptrace;
54133+int grsec_enable_time;
54134+int grsec_enable_audit_textrel;
54135+int grsec_enable_group;
54136+int grsec_audit_gid;
54137+int grsec_enable_chdir;
54138+int grsec_enable_mount;
54139+int grsec_enable_rofs;
54140+int grsec_enable_chroot_findtask;
54141+int grsec_enable_chroot_mount;
54142+int grsec_enable_chroot_shmat;
54143+int grsec_enable_chroot_fchdir;
54144+int grsec_enable_chroot_double;
54145+int grsec_enable_chroot_pivot;
54146+int grsec_enable_chroot_chdir;
54147+int grsec_enable_chroot_chmod;
54148+int grsec_enable_chroot_mknod;
54149+int grsec_enable_chroot_nice;
54150+int grsec_enable_chroot_execlog;
54151+int grsec_enable_chroot_caps;
54152+int grsec_enable_chroot_sysctl;
54153+int grsec_enable_chroot_unix;
54154+int grsec_enable_tpe;
54155+int grsec_tpe_gid;
54156+int grsec_enable_blackhole;
54157+#ifdef CONFIG_IPV6_MODULE
54158+EXPORT_SYMBOL(grsec_enable_blackhole);
54159+#endif
54160+int grsec_lastack_retries;
54161+int grsec_enable_tpe_all;
54162+int grsec_enable_tpe_invert;
54163+int grsec_enable_socket_all;
54164+int grsec_socket_all_gid;
54165+int grsec_enable_socket_client;
54166+int grsec_socket_client_gid;
54167+int grsec_enable_socket_server;
54168+int grsec_socket_server_gid;
54169+int grsec_resource_logging;
54170+int grsec_disable_privio;
54171+int grsec_enable_log_rwxmaps;
54172+int grsec_lock;
54173+
54174+DEFINE_SPINLOCK(grsec_alert_lock);
54175+unsigned long grsec_alert_wtime = 0;
54176+unsigned long grsec_alert_fyet = 0;
54177+
54178+DEFINE_SPINLOCK(grsec_audit_lock);
54179+
54180+DEFINE_RWLOCK(grsec_exec_file_lock);
54181+
54182+char *gr_shared_page[4];
54183+
54184+char *gr_alert_log_fmt;
54185+char *gr_audit_log_fmt;
54186+char *gr_alert_log_buf;
54187+char *gr_audit_log_buf;
54188+
54189+extern struct gr_arg *gr_usermode;
54190+extern unsigned char *gr_system_salt;
54191+extern unsigned char *gr_system_sum;
54192+
54193+void __init
54194+grsecurity_init(void)
54195+{
54196+ int j;
54197+ /* create the per-cpu shared pages */
54198+
54199+#ifdef CONFIG_X86
54200+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
54201+#endif
54202+
54203+ for (j = 0; j < 4; j++) {
54204+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
54205+ if (gr_shared_page[j] == NULL) {
54206+ panic("Unable to allocate grsecurity shared page");
54207+ return;
54208+ }
54209+ }
54210+
54211+ /* allocate log buffers */
54212+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
54213+ if (!gr_alert_log_fmt) {
54214+ panic("Unable to allocate grsecurity alert log format buffer");
54215+ return;
54216+ }
54217+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
54218+ if (!gr_audit_log_fmt) {
54219+ panic("Unable to allocate grsecurity audit log format buffer");
54220+ return;
54221+ }
54222+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
54223+ if (!gr_alert_log_buf) {
54224+ panic("Unable to allocate grsecurity alert log buffer");
54225+ return;
54226+ }
54227+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
54228+ if (!gr_audit_log_buf) {
54229+ panic("Unable to allocate grsecurity audit log buffer");
54230+ return;
54231+ }
54232+
54233+ /* allocate memory for authentication structure */
54234+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
54235+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
54236+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
54237+
54238+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
54239+ panic("Unable to allocate grsecurity authentication structure");
54240+ return;
54241+ }
54242+
54243+
54244+#ifdef CONFIG_GRKERNSEC_IO
54245+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
54246+ grsec_disable_privio = 1;
54247+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
54248+ grsec_disable_privio = 1;
54249+#else
54250+ grsec_disable_privio = 0;
54251+#endif
54252+#endif
54253+
54254+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
54255+ /* for backward compatibility, tpe_invert always defaults to on if
54256+ enabled in the kernel
54257+ */
54258+ grsec_enable_tpe_invert = 1;
54259+#endif
54260+
54261+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
54262+#ifndef CONFIG_GRKERNSEC_SYSCTL
54263+ grsec_lock = 1;
54264+#endif
54265+
54266+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
54267+ grsec_enable_audit_textrel = 1;
54268+#endif
54269+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54270+ grsec_enable_log_rwxmaps = 1;
54271+#endif
54272+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
54273+ grsec_enable_group = 1;
54274+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
54275+#endif
54276+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
54277+ grsec_enable_chdir = 1;
54278+#endif
54279+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54280+ grsec_enable_harden_ptrace = 1;
54281+#endif
54282+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54283+ grsec_enable_mount = 1;
54284+#endif
54285+#ifdef CONFIG_GRKERNSEC_LINK
54286+ grsec_enable_link = 1;
54287+#endif
54288+#ifdef CONFIG_GRKERNSEC_BRUTE
54289+ grsec_enable_brute = 1;
54290+#endif
54291+#ifdef CONFIG_GRKERNSEC_DMESG
54292+ grsec_enable_dmesg = 1;
54293+#endif
54294+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
54295+ grsec_enable_blackhole = 1;
54296+ grsec_lastack_retries = 4;
54297+#endif
54298+#ifdef CONFIG_GRKERNSEC_FIFO
54299+ grsec_enable_fifo = 1;
54300+#endif
54301+#ifdef CONFIG_GRKERNSEC_EXECLOG
54302+ grsec_enable_execlog = 1;
54303+#endif
54304+#ifdef CONFIG_GRKERNSEC_SIGNAL
54305+ grsec_enable_signal = 1;
54306+#endif
54307+#ifdef CONFIG_GRKERNSEC_FORKFAIL
54308+ grsec_enable_forkfail = 1;
54309+#endif
54310+#ifdef CONFIG_GRKERNSEC_TIME
54311+ grsec_enable_time = 1;
54312+#endif
54313+#ifdef CONFIG_GRKERNSEC_RESLOG
54314+ grsec_resource_logging = 1;
54315+#endif
54316+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54317+ grsec_enable_chroot_findtask = 1;
54318+#endif
54319+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
54320+ grsec_enable_chroot_unix = 1;
54321+#endif
54322+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
54323+ grsec_enable_chroot_mount = 1;
54324+#endif
54325+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
54326+ grsec_enable_chroot_fchdir = 1;
54327+#endif
54328+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
54329+ grsec_enable_chroot_shmat = 1;
54330+#endif
54331+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
54332+ grsec_enable_audit_ptrace = 1;
54333+#endif
54334+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
54335+ grsec_enable_chroot_double = 1;
54336+#endif
54337+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
54338+ grsec_enable_chroot_pivot = 1;
54339+#endif
54340+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
54341+ grsec_enable_chroot_chdir = 1;
54342+#endif
54343+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
54344+ grsec_enable_chroot_chmod = 1;
54345+#endif
54346+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
54347+ grsec_enable_chroot_mknod = 1;
54348+#endif
54349+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54350+ grsec_enable_chroot_nice = 1;
54351+#endif
54352+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
54353+ grsec_enable_chroot_execlog = 1;
54354+#endif
54355+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54356+ grsec_enable_chroot_caps = 1;
54357+#endif
54358+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
54359+ grsec_enable_chroot_sysctl = 1;
54360+#endif
54361+#ifdef CONFIG_GRKERNSEC_TPE
54362+ grsec_enable_tpe = 1;
54363+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
54364+#ifdef CONFIG_GRKERNSEC_TPE_ALL
54365+ grsec_enable_tpe_all = 1;
54366+#endif
54367+#endif
54368+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
54369+ grsec_enable_socket_all = 1;
54370+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
54371+#endif
54372+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
54373+ grsec_enable_socket_client = 1;
54374+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
54375+#endif
54376+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
54377+ grsec_enable_socket_server = 1;
54378+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
54379+#endif
54380+#endif
54381+
54382+ return;
54383+}
54384diff -urNp linux-2.6.32.44/grsecurity/grsec_link.c linux-2.6.32.44/grsecurity/grsec_link.c
54385--- linux-2.6.32.44/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
54386+++ linux-2.6.32.44/grsecurity/grsec_link.c 2011-04-17 15:56:46.000000000 -0400
54387@@ -0,0 +1,43 @@
54388+#include <linux/kernel.h>
54389+#include <linux/sched.h>
54390+#include <linux/fs.h>
54391+#include <linux/file.h>
54392+#include <linux/grinternal.h>
54393+
54394+int
54395+gr_handle_follow_link(const struct inode *parent,
54396+ const struct inode *inode,
54397+ const struct dentry *dentry, const struct vfsmount *mnt)
54398+{
54399+#ifdef CONFIG_GRKERNSEC_LINK
54400+ const struct cred *cred = current_cred();
54401+
54402+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
54403+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
54404+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
54405+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
54406+ return -EACCES;
54407+ }
54408+#endif
54409+ return 0;
54410+}
54411+
54412+int
54413+gr_handle_hardlink(const struct dentry *dentry,
54414+ const struct vfsmount *mnt,
54415+ struct inode *inode, const int mode, const char *to)
54416+{
54417+#ifdef CONFIG_GRKERNSEC_LINK
54418+ const struct cred *cred = current_cred();
54419+
54420+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
54421+ (!S_ISREG(mode) || (mode & S_ISUID) ||
54422+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
54423+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
54424+ !capable(CAP_FOWNER) && cred->uid) {
54425+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
54426+ return -EPERM;
54427+ }
54428+#endif
54429+ return 0;
54430+}
54431diff -urNp linux-2.6.32.44/grsecurity/grsec_log.c linux-2.6.32.44/grsecurity/grsec_log.c
54432--- linux-2.6.32.44/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
54433+++ linux-2.6.32.44/grsecurity/grsec_log.c 2011-05-10 21:58:49.000000000 -0400
54434@@ -0,0 +1,310 @@
54435+#include <linux/kernel.h>
54436+#include <linux/sched.h>
54437+#include <linux/file.h>
54438+#include <linux/tty.h>
54439+#include <linux/fs.h>
54440+#include <linux/grinternal.h>
54441+
54442+#ifdef CONFIG_TREE_PREEMPT_RCU
54443+#define DISABLE_PREEMPT() preempt_disable()
54444+#define ENABLE_PREEMPT() preempt_enable()
54445+#else
54446+#define DISABLE_PREEMPT()
54447+#define ENABLE_PREEMPT()
54448+#endif
54449+
54450+#define BEGIN_LOCKS(x) \
54451+ DISABLE_PREEMPT(); \
54452+ rcu_read_lock(); \
54453+ read_lock(&tasklist_lock); \
54454+ read_lock(&grsec_exec_file_lock); \
54455+ if (x != GR_DO_AUDIT) \
54456+ spin_lock(&grsec_alert_lock); \
54457+ else \
54458+ spin_lock(&grsec_audit_lock)
54459+
54460+#define END_LOCKS(x) \
54461+ if (x != GR_DO_AUDIT) \
54462+ spin_unlock(&grsec_alert_lock); \
54463+ else \
54464+ spin_unlock(&grsec_audit_lock); \
54465+ read_unlock(&grsec_exec_file_lock); \
54466+ read_unlock(&tasklist_lock); \
54467+ rcu_read_unlock(); \
54468+ ENABLE_PREEMPT(); \
54469+ if (x == GR_DONT_AUDIT) \
54470+ gr_handle_alertkill(current)
54471+
54472+enum {
54473+ FLOODING,
54474+ NO_FLOODING
54475+};
54476+
54477+extern char *gr_alert_log_fmt;
54478+extern char *gr_audit_log_fmt;
54479+extern char *gr_alert_log_buf;
54480+extern char *gr_audit_log_buf;
54481+
54482+static int gr_log_start(int audit)
54483+{
54484+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
54485+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
54486+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54487+
54488+ if (audit == GR_DO_AUDIT)
54489+ goto set_fmt;
54490+
54491+ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
54492+ grsec_alert_wtime = jiffies;
54493+ grsec_alert_fyet = 0;
54494+ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
54495+ grsec_alert_fyet++;
54496+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
54497+ grsec_alert_wtime = jiffies;
54498+ grsec_alert_fyet++;
54499+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
54500+ return FLOODING;
54501+ } else return FLOODING;
54502+
54503+set_fmt:
54504+ memset(buf, 0, PAGE_SIZE);
54505+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
54506+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
54507+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
54508+ } else if (current->signal->curr_ip) {
54509+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
54510+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
54511+ } else if (gr_acl_is_enabled()) {
54512+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
54513+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
54514+ } else {
54515+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
54516+ strcpy(buf, fmt);
54517+ }
54518+
54519+ return NO_FLOODING;
54520+}
54521+
54522+static void gr_log_middle(int audit, const char *msg, va_list ap)
54523+ __attribute__ ((format (printf, 2, 0)));
54524+
54525+static void gr_log_middle(int audit, const char *msg, va_list ap)
54526+{
54527+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54528+ unsigned int len = strlen(buf);
54529+
54530+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
54531+
54532+ return;
54533+}
54534+
54535+static void gr_log_middle_varargs(int audit, const char *msg, ...)
54536+ __attribute__ ((format (printf, 2, 3)));
54537+
54538+static void gr_log_middle_varargs(int audit, const char *msg, ...)
54539+{
54540+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54541+ unsigned int len = strlen(buf);
54542+ va_list ap;
54543+
54544+ va_start(ap, msg);
54545+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
54546+ va_end(ap);
54547+
54548+ return;
54549+}
54550+
54551+static void gr_log_end(int audit)
54552+{
54553+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54554+ unsigned int len = strlen(buf);
54555+
54556+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
54557+ printk("%s\n", buf);
54558+
54559+ return;
54560+}
54561+
54562+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
54563+{
54564+ int logtype;
54565+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
54566+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
54567+ void *voidptr = NULL;
54568+ int num1 = 0, num2 = 0;
54569+ unsigned long ulong1 = 0, ulong2 = 0;
54570+ struct dentry *dentry = NULL;
54571+ struct vfsmount *mnt = NULL;
54572+ struct file *file = NULL;
54573+ struct task_struct *task = NULL;
54574+ const struct cred *cred, *pcred;
54575+ va_list ap;
54576+
54577+ BEGIN_LOCKS(audit);
54578+ logtype = gr_log_start(audit);
54579+ if (logtype == FLOODING) {
54580+ END_LOCKS(audit);
54581+ return;
54582+ }
54583+ va_start(ap, argtypes);
54584+ switch (argtypes) {
54585+ case GR_TTYSNIFF:
54586+ task = va_arg(ap, struct task_struct *);
54587+ 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);
54588+ break;
54589+ case GR_SYSCTL_HIDDEN:
54590+ str1 = va_arg(ap, char *);
54591+ gr_log_middle_varargs(audit, msg, result, str1);
54592+ break;
54593+ case GR_RBAC:
54594+ dentry = va_arg(ap, struct dentry *);
54595+ mnt = va_arg(ap, struct vfsmount *);
54596+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
54597+ break;
54598+ case GR_RBAC_STR:
54599+ dentry = va_arg(ap, struct dentry *);
54600+ mnt = va_arg(ap, struct vfsmount *);
54601+ str1 = va_arg(ap, char *);
54602+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
54603+ break;
54604+ case GR_STR_RBAC:
54605+ str1 = va_arg(ap, char *);
54606+ dentry = va_arg(ap, struct dentry *);
54607+ mnt = va_arg(ap, struct vfsmount *);
54608+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
54609+ break;
54610+ case GR_RBAC_MODE2:
54611+ dentry = va_arg(ap, struct dentry *);
54612+ mnt = va_arg(ap, struct vfsmount *);
54613+ str1 = va_arg(ap, char *);
54614+ str2 = va_arg(ap, char *);
54615+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
54616+ break;
54617+ case GR_RBAC_MODE3:
54618+ dentry = va_arg(ap, struct dentry *);
54619+ mnt = va_arg(ap, struct vfsmount *);
54620+ str1 = va_arg(ap, char *);
54621+ str2 = va_arg(ap, char *);
54622+ str3 = va_arg(ap, char *);
54623+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
54624+ break;
54625+ case GR_FILENAME:
54626+ dentry = va_arg(ap, struct dentry *);
54627+ mnt = va_arg(ap, struct vfsmount *);
54628+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
54629+ break;
54630+ case GR_STR_FILENAME:
54631+ str1 = va_arg(ap, char *);
54632+ dentry = va_arg(ap, struct dentry *);
54633+ mnt = va_arg(ap, struct vfsmount *);
54634+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
54635+ break;
54636+ case GR_FILENAME_STR:
54637+ dentry = va_arg(ap, struct dentry *);
54638+ mnt = va_arg(ap, struct vfsmount *);
54639+ str1 = va_arg(ap, char *);
54640+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
54641+ break;
54642+ case GR_FILENAME_TWO_INT:
54643+ dentry = va_arg(ap, struct dentry *);
54644+ mnt = va_arg(ap, struct vfsmount *);
54645+ num1 = va_arg(ap, int);
54646+ num2 = va_arg(ap, int);
54647+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
54648+ break;
54649+ case GR_FILENAME_TWO_INT_STR:
54650+ dentry = va_arg(ap, struct dentry *);
54651+ mnt = va_arg(ap, struct vfsmount *);
54652+ num1 = va_arg(ap, int);
54653+ num2 = va_arg(ap, int);
54654+ str1 = va_arg(ap, char *);
54655+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
54656+ break;
54657+ case GR_TEXTREL:
54658+ file = va_arg(ap, struct file *);
54659+ ulong1 = va_arg(ap, unsigned long);
54660+ ulong2 = va_arg(ap, unsigned long);
54661+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
54662+ break;
54663+ case GR_PTRACE:
54664+ task = va_arg(ap, struct task_struct *);
54665+ 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);
54666+ break;
54667+ case GR_RESOURCE:
54668+ task = va_arg(ap, struct task_struct *);
54669+ cred = __task_cred(task);
54670+ pcred = __task_cred(task->real_parent);
54671+ ulong1 = va_arg(ap, unsigned long);
54672+ str1 = va_arg(ap, char *);
54673+ ulong2 = va_arg(ap, unsigned long);
54674+ 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);
54675+ break;
54676+ case GR_CAP:
54677+ task = va_arg(ap, struct task_struct *);
54678+ cred = __task_cred(task);
54679+ pcred = __task_cred(task->real_parent);
54680+ str1 = va_arg(ap, char *);
54681+ 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);
54682+ break;
54683+ case GR_SIG:
54684+ str1 = va_arg(ap, char *);
54685+ voidptr = va_arg(ap, void *);
54686+ gr_log_middle_varargs(audit, msg, str1, voidptr);
54687+ break;
54688+ case GR_SIG2:
54689+ task = va_arg(ap, struct task_struct *);
54690+ cred = __task_cred(task);
54691+ pcred = __task_cred(task->real_parent);
54692+ num1 = va_arg(ap, int);
54693+ 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);
54694+ break;
54695+ case GR_CRASH1:
54696+ task = va_arg(ap, struct task_struct *);
54697+ cred = __task_cred(task);
54698+ pcred = __task_cred(task->real_parent);
54699+ ulong1 = va_arg(ap, unsigned long);
54700+ 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);
54701+ break;
54702+ case GR_CRASH2:
54703+ task = va_arg(ap, struct task_struct *);
54704+ cred = __task_cred(task);
54705+ pcred = __task_cred(task->real_parent);
54706+ ulong1 = va_arg(ap, unsigned long);
54707+ 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);
54708+ break;
54709+ case GR_RWXMAP:
54710+ file = va_arg(ap, struct file *);
54711+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
54712+ break;
54713+ case GR_PSACCT:
54714+ {
54715+ unsigned int wday, cday;
54716+ __u8 whr, chr;
54717+ __u8 wmin, cmin;
54718+ __u8 wsec, csec;
54719+ char cur_tty[64] = { 0 };
54720+ char parent_tty[64] = { 0 };
54721+
54722+ task = va_arg(ap, struct task_struct *);
54723+ wday = va_arg(ap, unsigned int);
54724+ cday = va_arg(ap, unsigned int);
54725+ whr = va_arg(ap, int);
54726+ chr = va_arg(ap, int);
54727+ wmin = va_arg(ap, int);
54728+ cmin = va_arg(ap, int);
54729+ wsec = va_arg(ap, int);
54730+ csec = va_arg(ap, int);
54731+ ulong1 = va_arg(ap, unsigned long);
54732+ cred = __task_cred(task);
54733+ pcred = __task_cred(task->real_parent);
54734+
54735+ 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);
54736+ }
54737+ break;
54738+ default:
54739+ gr_log_middle(audit, msg, ap);
54740+ }
54741+ va_end(ap);
54742+ gr_log_end(audit);
54743+ END_LOCKS(audit);
54744+}
54745diff -urNp linux-2.6.32.44/grsecurity/grsec_mem.c linux-2.6.32.44/grsecurity/grsec_mem.c
54746--- linux-2.6.32.44/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
54747+++ linux-2.6.32.44/grsecurity/grsec_mem.c 2011-04-17 15:56:46.000000000 -0400
54748@@ -0,0 +1,33 @@
54749+#include <linux/kernel.h>
54750+#include <linux/sched.h>
54751+#include <linux/mm.h>
54752+#include <linux/mman.h>
54753+#include <linux/grinternal.h>
54754+
54755+void
54756+gr_handle_ioperm(void)
54757+{
54758+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
54759+ return;
54760+}
54761+
54762+void
54763+gr_handle_iopl(void)
54764+{
54765+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
54766+ return;
54767+}
54768+
54769+void
54770+gr_handle_mem_readwrite(u64 from, u64 to)
54771+{
54772+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
54773+ return;
54774+}
54775+
54776+void
54777+gr_handle_vm86(void)
54778+{
54779+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
54780+ return;
54781+}
54782diff -urNp linux-2.6.32.44/grsecurity/grsec_mount.c linux-2.6.32.44/grsecurity/grsec_mount.c
54783--- linux-2.6.32.44/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
54784+++ linux-2.6.32.44/grsecurity/grsec_mount.c 2011-06-20 19:47:03.000000000 -0400
54785@@ -0,0 +1,62 @@
54786+#include <linux/kernel.h>
54787+#include <linux/sched.h>
54788+#include <linux/mount.h>
54789+#include <linux/grsecurity.h>
54790+#include <linux/grinternal.h>
54791+
54792+void
54793+gr_log_remount(const char *devname, const int retval)
54794+{
54795+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54796+ if (grsec_enable_mount && (retval >= 0))
54797+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
54798+#endif
54799+ return;
54800+}
54801+
54802+void
54803+gr_log_unmount(const char *devname, const int retval)
54804+{
54805+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54806+ if (grsec_enable_mount && (retval >= 0))
54807+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
54808+#endif
54809+ return;
54810+}
54811+
54812+void
54813+gr_log_mount(const char *from, const char *to, const int retval)
54814+{
54815+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54816+ if (grsec_enable_mount && (retval >= 0))
54817+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
54818+#endif
54819+ return;
54820+}
54821+
54822+int
54823+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
54824+{
54825+#ifdef CONFIG_GRKERNSEC_ROFS
54826+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
54827+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
54828+ return -EPERM;
54829+ } else
54830+ return 0;
54831+#endif
54832+ return 0;
54833+}
54834+
54835+int
54836+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
54837+{
54838+#ifdef CONFIG_GRKERNSEC_ROFS
54839+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
54840+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
54841+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
54842+ return -EPERM;
54843+ } else
54844+ return 0;
54845+#endif
54846+ return 0;
54847+}
54848diff -urNp linux-2.6.32.44/grsecurity/grsec_pax.c linux-2.6.32.44/grsecurity/grsec_pax.c
54849--- linux-2.6.32.44/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
54850+++ linux-2.6.32.44/grsecurity/grsec_pax.c 2011-04-17 15:56:46.000000000 -0400
54851@@ -0,0 +1,36 @@
54852+#include <linux/kernel.h>
54853+#include <linux/sched.h>
54854+#include <linux/mm.h>
54855+#include <linux/file.h>
54856+#include <linux/grinternal.h>
54857+#include <linux/grsecurity.h>
54858+
54859+void
54860+gr_log_textrel(struct vm_area_struct * vma)
54861+{
54862+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
54863+ if (grsec_enable_audit_textrel)
54864+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
54865+#endif
54866+ return;
54867+}
54868+
54869+void
54870+gr_log_rwxmmap(struct file *file)
54871+{
54872+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54873+ if (grsec_enable_log_rwxmaps)
54874+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
54875+#endif
54876+ return;
54877+}
54878+
54879+void
54880+gr_log_rwxmprotect(struct file *file)
54881+{
54882+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54883+ if (grsec_enable_log_rwxmaps)
54884+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
54885+#endif
54886+ return;
54887+}
54888diff -urNp linux-2.6.32.44/grsecurity/grsec_ptrace.c linux-2.6.32.44/grsecurity/grsec_ptrace.c
54889--- linux-2.6.32.44/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
54890+++ linux-2.6.32.44/grsecurity/grsec_ptrace.c 2011-04-17 15:56:46.000000000 -0400
54891@@ -0,0 +1,14 @@
54892+#include <linux/kernel.h>
54893+#include <linux/sched.h>
54894+#include <linux/grinternal.h>
54895+#include <linux/grsecurity.h>
54896+
54897+void
54898+gr_audit_ptrace(struct task_struct *task)
54899+{
54900+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
54901+ if (grsec_enable_audit_ptrace)
54902+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
54903+#endif
54904+ return;
54905+}
54906diff -urNp linux-2.6.32.44/grsecurity/grsec_sig.c linux-2.6.32.44/grsecurity/grsec_sig.c
54907--- linux-2.6.32.44/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
54908+++ linux-2.6.32.44/grsecurity/grsec_sig.c 2011-06-29 19:40:31.000000000 -0400
54909@@ -0,0 +1,205 @@
54910+#include <linux/kernel.h>
54911+#include <linux/sched.h>
54912+#include <linux/delay.h>
54913+#include <linux/grsecurity.h>
54914+#include <linux/grinternal.h>
54915+#include <linux/hardirq.h>
54916+
54917+char *signames[] = {
54918+ [SIGSEGV] = "Segmentation fault",
54919+ [SIGILL] = "Illegal instruction",
54920+ [SIGABRT] = "Abort",
54921+ [SIGBUS] = "Invalid alignment/Bus error"
54922+};
54923+
54924+void
54925+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
54926+{
54927+#ifdef CONFIG_GRKERNSEC_SIGNAL
54928+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
54929+ (sig == SIGABRT) || (sig == SIGBUS))) {
54930+ if (t->pid == current->pid) {
54931+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
54932+ } else {
54933+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
54934+ }
54935+ }
54936+#endif
54937+ return;
54938+}
54939+
54940+int
54941+gr_handle_signal(const struct task_struct *p, const int sig)
54942+{
54943+#ifdef CONFIG_GRKERNSEC
54944+ if (current->pid > 1 && gr_check_protected_task(p)) {
54945+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
54946+ return -EPERM;
54947+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
54948+ return -EPERM;
54949+ }
54950+#endif
54951+ return 0;
54952+}
54953+
54954+#ifdef CONFIG_GRKERNSEC
54955+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
54956+
54957+int gr_fake_force_sig(int sig, struct task_struct *t)
54958+{
54959+ unsigned long int flags;
54960+ int ret, blocked, ignored;
54961+ struct k_sigaction *action;
54962+
54963+ spin_lock_irqsave(&t->sighand->siglock, flags);
54964+ action = &t->sighand->action[sig-1];
54965+ ignored = action->sa.sa_handler == SIG_IGN;
54966+ blocked = sigismember(&t->blocked, sig);
54967+ if (blocked || ignored) {
54968+ action->sa.sa_handler = SIG_DFL;
54969+ if (blocked) {
54970+ sigdelset(&t->blocked, sig);
54971+ recalc_sigpending_and_wake(t);
54972+ }
54973+ }
54974+ if (action->sa.sa_handler == SIG_DFL)
54975+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
54976+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
54977+
54978+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
54979+
54980+ return ret;
54981+}
54982+#endif
54983+
54984+#ifdef CONFIG_GRKERNSEC_BRUTE
54985+#define GR_USER_BAN_TIME (15 * 60)
54986+
54987+static int __get_dumpable(unsigned long mm_flags)
54988+{
54989+ int ret;
54990+
54991+ ret = mm_flags & MMF_DUMPABLE_MASK;
54992+ return (ret >= 2) ? 2 : ret;
54993+}
54994+#endif
54995+
54996+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
54997+{
54998+#ifdef CONFIG_GRKERNSEC_BRUTE
54999+ uid_t uid = 0;
55000+
55001+ if (!grsec_enable_brute)
55002+ return;
55003+
55004+ rcu_read_lock();
55005+ read_lock(&tasklist_lock);
55006+ read_lock(&grsec_exec_file_lock);
55007+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
55008+ p->real_parent->brute = 1;
55009+ else {
55010+ const struct cred *cred = __task_cred(p), *cred2;
55011+ struct task_struct *tsk, *tsk2;
55012+
55013+ if (!__get_dumpable(mm_flags) && cred->uid) {
55014+ struct user_struct *user;
55015+
55016+ uid = cred->uid;
55017+
55018+ /* this is put upon execution past expiration */
55019+ user = find_user(uid);
55020+ if (user == NULL)
55021+ goto unlock;
55022+ user->banned = 1;
55023+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
55024+ if (user->ban_expires == ~0UL)
55025+ user->ban_expires--;
55026+
55027+ do_each_thread(tsk2, tsk) {
55028+ cred2 = __task_cred(tsk);
55029+ if (tsk != p && cred2->uid == uid)
55030+ gr_fake_force_sig(SIGKILL, tsk);
55031+ } while_each_thread(tsk2, tsk);
55032+ }
55033+ }
55034+unlock:
55035+ read_unlock(&grsec_exec_file_lock);
55036+ read_unlock(&tasklist_lock);
55037+ rcu_read_unlock();
55038+
55039+ if (uid)
55040+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
55041+#endif
55042+ return;
55043+}
55044+
55045+void gr_handle_brute_check(void)
55046+{
55047+#ifdef CONFIG_GRKERNSEC_BRUTE
55048+ if (current->brute)
55049+ msleep(30 * 1000);
55050+#endif
55051+ return;
55052+}
55053+
55054+void gr_handle_kernel_exploit(void)
55055+{
55056+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
55057+ const struct cred *cred;
55058+ struct task_struct *tsk, *tsk2;
55059+ struct user_struct *user;
55060+ uid_t uid;
55061+
55062+ if (in_irq() || in_serving_softirq() || in_nmi())
55063+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
55064+
55065+ uid = current_uid();
55066+
55067+ if (uid == 0)
55068+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
55069+ else {
55070+ /* kill all the processes of this user, hold a reference
55071+ to their creds struct, and prevent them from creating
55072+ another process until system reset
55073+ */
55074+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
55075+ /* we intentionally leak this ref */
55076+ user = get_uid(current->cred->user);
55077+ if (user) {
55078+ user->banned = 1;
55079+ user->ban_expires = ~0UL;
55080+ }
55081+
55082+ read_lock(&tasklist_lock);
55083+ do_each_thread(tsk2, tsk) {
55084+ cred = __task_cred(tsk);
55085+ if (cred->uid == uid)
55086+ gr_fake_force_sig(SIGKILL, tsk);
55087+ } while_each_thread(tsk2, tsk);
55088+ read_unlock(&tasklist_lock);
55089+ }
55090+#endif
55091+}
55092+
55093+int __gr_process_user_ban(struct user_struct *user)
55094+{
55095+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55096+ if (unlikely(user->banned)) {
55097+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
55098+ user->banned = 0;
55099+ user->ban_expires = 0;
55100+ free_uid(user);
55101+ } else
55102+ return -EPERM;
55103+ }
55104+#endif
55105+ return 0;
55106+}
55107+
55108+int gr_process_user_ban(void)
55109+{
55110+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55111+ return __gr_process_user_ban(current->cred->user);
55112+#endif
55113+ return 0;
55114+}
55115diff -urNp linux-2.6.32.44/grsecurity/grsec_sock.c linux-2.6.32.44/grsecurity/grsec_sock.c
55116--- linux-2.6.32.44/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
55117+++ linux-2.6.32.44/grsecurity/grsec_sock.c 2011-04-17 15:56:46.000000000 -0400
55118@@ -0,0 +1,275 @@
55119+#include <linux/kernel.h>
55120+#include <linux/module.h>
55121+#include <linux/sched.h>
55122+#include <linux/file.h>
55123+#include <linux/net.h>
55124+#include <linux/in.h>
55125+#include <linux/ip.h>
55126+#include <net/sock.h>
55127+#include <net/inet_sock.h>
55128+#include <linux/grsecurity.h>
55129+#include <linux/grinternal.h>
55130+#include <linux/gracl.h>
55131+
55132+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
55133+EXPORT_SYMBOL(gr_cap_rtnetlink);
55134+
55135+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
55136+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
55137+
55138+EXPORT_SYMBOL(gr_search_udp_recvmsg);
55139+EXPORT_SYMBOL(gr_search_udp_sendmsg);
55140+
55141+#ifdef CONFIG_UNIX_MODULE
55142+EXPORT_SYMBOL(gr_acl_handle_unix);
55143+EXPORT_SYMBOL(gr_acl_handle_mknod);
55144+EXPORT_SYMBOL(gr_handle_chroot_unix);
55145+EXPORT_SYMBOL(gr_handle_create);
55146+#endif
55147+
55148+#ifdef CONFIG_GRKERNSEC
55149+#define gr_conn_table_size 32749
55150+struct conn_table_entry {
55151+ struct conn_table_entry *next;
55152+ struct signal_struct *sig;
55153+};
55154+
55155+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
55156+DEFINE_SPINLOCK(gr_conn_table_lock);
55157+
55158+extern const char * gr_socktype_to_name(unsigned char type);
55159+extern const char * gr_proto_to_name(unsigned char proto);
55160+extern const char * gr_sockfamily_to_name(unsigned char family);
55161+
55162+static __inline__ int
55163+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
55164+{
55165+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
55166+}
55167+
55168+static __inline__ int
55169+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
55170+ __u16 sport, __u16 dport)
55171+{
55172+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
55173+ sig->gr_sport == sport && sig->gr_dport == dport))
55174+ return 1;
55175+ else
55176+ return 0;
55177+}
55178+
55179+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
55180+{
55181+ struct conn_table_entry **match;
55182+ unsigned int index;
55183+
55184+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
55185+ sig->gr_sport, sig->gr_dport,
55186+ gr_conn_table_size);
55187+
55188+ newent->sig = sig;
55189+
55190+ match = &gr_conn_table[index];
55191+ newent->next = *match;
55192+ *match = newent;
55193+
55194+ return;
55195+}
55196+
55197+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
55198+{
55199+ struct conn_table_entry *match, *last = NULL;
55200+ unsigned int index;
55201+
55202+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
55203+ sig->gr_sport, sig->gr_dport,
55204+ gr_conn_table_size);
55205+
55206+ match = gr_conn_table[index];
55207+ while (match && !conn_match(match->sig,
55208+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
55209+ sig->gr_dport)) {
55210+ last = match;
55211+ match = match->next;
55212+ }
55213+
55214+ if (match) {
55215+ if (last)
55216+ last->next = match->next;
55217+ else
55218+ gr_conn_table[index] = NULL;
55219+ kfree(match);
55220+ }
55221+
55222+ return;
55223+}
55224+
55225+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
55226+ __u16 sport, __u16 dport)
55227+{
55228+ struct conn_table_entry *match;
55229+ unsigned int index;
55230+
55231+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
55232+
55233+ match = gr_conn_table[index];
55234+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
55235+ match = match->next;
55236+
55237+ if (match)
55238+ return match->sig;
55239+ else
55240+ return NULL;
55241+}
55242+
55243+#endif
55244+
55245+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
55246+{
55247+#ifdef CONFIG_GRKERNSEC
55248+ struct signal_struct *sig = task->signal;
55249+ struct conn_table_entry *newent;
55250+
55251+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
55252+ if (newent == NULL)
55253+ return;
55254+ /* no bh lock needed since we are called with bh disabled */
55255+ spin_lock(&gr_conn_table_lock);
55256+ gr_del_task_from_ip_table_nolock(sig);
55257+ sig->gr_saddr = inet->rcv_saddr;
55258+ sig->gr_daddr = inet->daddr;
55259+ sig->gr_sport = inet->sport;
55260+ sig->gr_dport = inet->dport;
55261+ gr_add_to_task_ip_table_nolock(sig, newent);
55262+ spin_unlock(&gr_conn_table_lock);
55263+#endif
55264+ return;
55265+}
55266+
55267+void gr_del_task_from_ip_table(struct task_struct *task)
55268+{
55269+#ifdef CONFIG_GRKERNSEC
55270+ spin_lock_bh(&gr_conn_table_lock);
55271+ gr_del_task_from_ip_table_nolock(task->signal);
55272+ spin_unlock_bh(&gr_conn_table_lock);
55273+#endif
55274+ return;
55275+}
55276+
55277+void
55278+gr_attach_curr_ip(const struct sock *sk)
55279+{
55280+#ifdef CONFIG_GRKERNSEC
55281+ struct signal_struct *p, *set;
55282+ const struct inet_sock *inet = inet_sk(sk);
55283+
55284+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
55285+ return;
55286+
55287+ set = current->signal;
55288+
55289+ spin_lock_bh(&gr_conn_table_lock);
55290+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
55291+ inet->dport, inet->sport);
55292+ if (unlikely(p != NULL)) {
55293+ set->curr_ip = p->curr_ip;
55294+ set->used_accept = 1;
55295+ gr_del_task_from_ip_table_nolock(p);
55296+ spin_unlock_bh(&gr_conn_table_lock);
55297+ return;
55298+ }
55299+ spin_unlock_bh(&gr_conn_table_lock);
55300+
55301+ set->curr_ip = inet->daddr;
55302+ set->used_accept = 1;
55303+#endif
55304+ return;
55305+}
55306+
55307+int
55308+gr_handle_sock_all(const int family, const int type, const int protocol)
55309+{
55310+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55311+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
55312+ (family != AF_UNIX)) {
55313+ if (family == AF_INET)
55314+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
55315+ else
55316+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
55317+ return -EACCES;
55318+ }
55319+#endif
55320+ return 0;
55321+}
55322+
55323+int
55324+gr_handle_sock_server(const struct sockaddr *sck)
55325+{
55326+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55327+ if (grsec_enable_socket_server &&
55328+ in_group_p(grsec_socket_server_gid) &&
55329+ sck && (sck->sa_family != AF_UNIX) &&
55330+ (sck->sa_family != AF_LOCAL)) {
55331+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
55332+ return -EACCES;
55333+ }
55334+#endif
55335+ return 0;
55336+}
55337+
55338+int
55339+gr_handle_sock_server_other(const struct sock *sck)
55340+{
55341+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55342+ if (grsec_enable_socket_server &&
55343+ in_group_p(grsec_socket_server_gid) &&
55344+ sck && (sck->sk_family != AF_UNIX) &&
55345+ (sck->sk_family != AF_LOCAL)) {
55346+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
55347+ return -EACCES;
55348+ }
55349+#endif
55350+ return 0;
55351+}
55352+
55353+int
55354+gr_handle_sock_client(const struct sockaddr *sck)
55355+{
55356+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55357+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
55358+ sck && (sck->sa_family != AF_UNIX) &&
55359+ (sck->sa_family != AF_LOCAL)) {
55360+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
55361+ return -EACCES;
55362+ }
55363+#endif
55364+ return 0;
55365+}
55366+
55367+kernel_cap_t
55368+gr_cap_rtnetlink(struct sock *sock)
55369+{
55370+#ifdef CONFIG_GRKERNSEC
55371+ if (!gr_acl_is_enabled())
55372+ return current_cap();
55373+ else if (sock->sk_protocol == NETLINK_ISCSI &&
55374+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
55375+ gr_is_capable(CAP_SYS_ADMIN))
55376+ return current_cap();
55377+ else if (sock->sk_protocol == NETLINK_AUDIT &&
55378+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
55379+ gr_is_capable(CAP_AUDIT_WRITE) &&
55380+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
55381+ gr_is_capable(CAP_AUDIT_CONTROL))
55382+ return current_cap();
55383+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
55384+ ((sock->sk_protocol == NETLINK_ROUTE) ?
55385+ gr_is_capable_nolog(CAP_NET_ADMIN) :
55386+ gr_is_capable(CAP_NET_ADMIN)))
55387+ return current_cap();
55388+ else
55389+ return __cap_empty_set;
55390+#else
55391+ return current_cap();
55392+#endif
55393+}
55394diff -urNp linux-2.6.32.44/grsecurity/grsec_sysctl.c linux-2.6.32.44/grsecurity/grsec_sysctl.c
55395--- linux-2.6.32.44/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
55396+++ linux-2.6.32.44/grsecurity/grsec_sysctl.c 2011-08-11 19:57:54.000000000 -0400
55397@@ -0,0 +1,479 @@
55398+#include <linux/kernel.h>
55399+#include <linux/sched.h>
55400+#include <linux/sysctl.h>
55401+#include <linux/grsecurity.h>
55402+#include <linux/grinternal.h>
55403+
55404+int
55405+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
55406+{
55407+#ifdef CONFIG_GRKERNSEC_SYSCTL
55408+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
55409+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
55410+ return -EACCES;
55411+ }
55412+#endif
55413+ return 0;
55414+}
55415+
55416+#ifdef CONFIG_GRKERNSEC_ROFS
55417+static int __maybe_unused one = 1;
55418+#endif
55419+
55420+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
55421+ctl_table grsecurity_table[] = {
55422+#ifdef CONFIG_GRKERNSEC_SYSCTL
55423+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
55424+#ifdef CONFIG_GRKERNSEC_IO
55425+ {
55426+ .ctl_name = CTL_UNNUMBERED,
55427+ .procname = "disable_priv_io",
55428+ .data = &grsec_disable_privio,
55429+ .maxlen = sizeof(int),
55430+ .mode = 0600,
55431+ .proc_handler = &proc_dointvec,
55432+ },
55433+#endif
55434+#endif
55435+#ifdef CONFIG_GRKERNSEC_LINK
55436+ {
55437+ .ctl_name = CTL_UNNUMBERED,
55438+ .procname = "linking_restrictions",
55439+ .data = &grsec_enable_link,
55440+ .maxlen = sizeof(int),
55441+ .mode = 0600,
55442+ .proc_handler = &proc_dointvec,
55443+ },
55444+#endif
55445+#ifdef CONFIG_GRKERNSEC_BRUTE
55446+ {
55447+ .ctl_name = CTL_UNNUMBERED,
55448+ .procname = "deter_bruteforce",
55449+ .data = &grsec_enable_brute,
55450+ .maxlen = sizeof(int),
55451+ .mode = 0600,
55452+ .proc_handler = &proc_dointvec,
55453+ },
55454+#endif
55455+#ifdef CONFIG_GRKERNSEC_FIFO
55456+ {
55457+ .ctl_name = CTL_UNNUMBERED,
55458+ .procname = "fifo_restrictions",
55459+ .data = &grsec_enable_fifo,
55460+ .maxlen = sizeof(int),
55461+ .mode = 0600,
55462+ .proc_handler = &proc_dointvec,
55463+ },
55464+#endif
55465+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55466+ {
55467+ .ctl_name = CTL_UNNUMBERED,
55468+ .procname = "ip_blackhole",
55469+ .data = &grsec_enable_blackhole,
55470+ .maxlen = sizeof(int),
55471+ .mode = 0600,
55472+ .proc_handler = &proc_dointvec,
55473+ },
55474+ {
55475+ .ctl_name = CTL_UNNUMBERED,
55476+ .procname = "lastack_retries",
55477+ .data = &grsec_lastack_retries,
55478+ .maxlen = sizeof(int),
55479+ .mode = 0600,
55480+ .proc_handler = &proc_dointvec,
55481+ },
55482+#endif
55483+#ifdef CONFIG_GRKERNSEC_EXECLOG
55484+ {
55485+ .ctl_name = CTL_UNNUMBERED,
55486+ .procname = "exec_logging",
55487+ .data = &grsec_enable_execlog,
55488+ .maxlen = sizeof(int),
55489+ .mode = 0600,
55490+ .proc_handler = &proc_dointvec,
55491+ },
55492+#endif
55493+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55494+ {
55495+ .ctl_name = CTL_UNNUMBERED,
55496+ .procname = "rwxmap_logging",
55497+ .data = &grsec_enable_log_rwxmaps,
55498+ .maxlen = sizeof(int),
55499+ .mode = 0600,
55500+ .proc_handler = &proc_dointvec,
55501+ },
55502+#endif
55503+#ifdef CONFIG_GRKERNSEC_SIGNAL
55504+ {
55505+ .ctl_name = CTL_UNNUMBERED,
55506+ .procname = "signal_logging",
55507+ .data = &grsec_enable_signal,
55508+ .maxlen = sizeof(int),
55509+ .mode = 0600,
55510+ .proc_handler = &proc_dointvec,
55511+ },
55512+#endif
55513+#ifdef CONFIG_GRKERNSEC_FORKFAIL
55514+ {
55515+ .ctl_name = CTL_UNNUMBERED,
55516+ .procname = "forkfail_logging",
55517+ .data = &grsec_enable_forkfail,
55518+ .maxlen = sizeof(int),
55519+ .mode = 0600,
55520+ .proc_handler = &proc_dointvec,
55521+ },
55522+#endif
55523+#ifdef CONFIG_GRKERNSEC_TIME
55524+ {
55525+ .ctl_name = CTL_UNNUMBERED,
55526+ .procname = "timechange_logging",
55527+ .data = &grsec_enable_time,
55528+ .maxlen = sizeof(int),
55529+ .mode = 0600,
55530+ .proc_handler = &proc_dointvec,
55531+ },
55532+#endif
55533+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55534+ {
55535+ .ctl_name = CTL_UNNUMBERED,
55536+ .procname = "chroot_deny_shmat",
55537+ .data = &grsec_enable_chroot_shmat,
55538+ .maxlen = sizeof(int),
55539+ .mode = 0600,
55540+ .proc_handler = &proc_dointvec,
55541+ },
55542+#endif
55543+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55544+ {
55545+ .ctl_name = CTL_UNNUMBERED,
55546+ .procname = "chroot_deny_unix",
55547+ .data = &grsec_enable_chroot_unix,
55548+ .maxlen = sizeof(int),
55549+ .mode = 0600,
55550+ .proc_handler = &proc_dointvec,
55551+ },
55552+#endif
55553+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55554+ {
55555+ .ctl_name = CTL_UNNUMBERED,
55556+ .procname = "chroot_deny_mount",
55557+ .data = &grsec_enable_chroot_mount,
55558+ .maxlen = sizeof(int),
55559+ .mode = 0600,
55560+ .proc_handler = &proc_dointvec,
55561+ },
55562+#endif
55563+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55564+ {
55565+ .ctl_name = CTL_UNNUMBERED,
55566+ .procname = "chroot_deny_fchdir",
55567+ .data = &grsec_enable_chroot_fchdir,
55568+ .maxlen = sizeof(int),
55569+ .mode = 0600,
55570+ .proc_handler = &proc_dointvec,
55571+ },
55572+#endif
55573+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55574+ {
55575+ .ctl_name = CTL_UNNUMBERED,
55576+ .procname = "chroot_deny_chroot",
55577+ .data = &grsec_enable_chroot_double,
55578+ .maxlen = sizeof(int),
55579+ .mode = 0600,
55580+ .proc_handler = &proc_dointvec,
55581+ },
55582+#endif
55583+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55584+ {
55585+ .ctl_name = CTL_UNNUMBERED,
55586+ .procname = "chroot_deny_pivot",
55587+ .data = &grsec_enable_chroot_pivot,
55588+ .maxlen = sizeof(int),
55589+ .mode = 0600,
55590+ .proc_handler = &proc_dointvec,
55591+ },
55592+#endif
55593+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55594+ {
55595+ .ctl_name = CTL_UNNUMBERED,
55596+ .procname = "chroot_enforce_chdir",
55597+ .data = &grsec_enable_chroot_chdir,
55598+ .maxlen = sizeof(int),
55599+ .mode = 0600,
55600+ .proc_handler = &proc_dointvec,
55601+ },
55602+#endif
55603+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55604+ {
55605+ .ctl_name = CTL_UNNUMBERED,
55606+ .procname = "chroot_deny_chmod",
55607+ .data = &grsec_enable_chroot_chmod,
55608+ .maxlen = sizeof(int),
55609+ .mode = 0600,
55610+ .proc_handler = &proc_dointvec,
55611+ },
55612+#endif
55613+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55614+ {
55615+ .ctl_name = CTL_UNNUMBERED,
55616+ .procname = "chroot_deny_mknod",
55617+ .data = &grsec_enable_chroot_mknod,
55618+ .maxlen = sizeof(int),
55619+ .mode = 0600,
55620+ .proc_handler = &proc_dointvec,
55621+ },
55622+#endif
55623+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55624+ {
55625+ .ctl_name = CTL_UNNUMBERED,
55626+ .procname = "chroot_restrict_nice",
55627+ .data = &grsec_enable_chroot_nice,
55628+ .maxlen = sizeof(int),
55629+ .mode = 0600,
55630+ .proc_handler = &proc_dointvec,
55631+ },
55632+#endif
55633+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55634+ {
55635+ .ctl_name = CTL_UNNUMBERED,
55636+ .procname = "chroot_execlog",
55637+ .data = &grsec_enable_chroot_execlog,
55638+ .maxlen = sizeof(int),
55639+ .mode = 0600,
55640+ .proc_handler = &proc_dointvec,
55641+ },
55642+#endif
55643+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55644+ {
55645+ .ctl_name = CTL_UNNUMBERED,
55646+ .procname = "chroot_caps",
55647+ .data = &grsec_enable_chroot_caps,
55648+ .maxlen = sizeof(int),
55649+ .mode = 0600,
55650+ .proc_handler = &proc_dointvec,
55651+ },
55652+#endif
55653+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55654+ {
55655+ .ctl_name = CTL_UNNUMBERED,
55656+ .procname = "chroot_deny_sysctl",
55657+ .data = &grsec_enable_chroot_sysctl,
55658+ .maxlen = sizeof(int),
55659+ .mode = 0600,
55660+ .proc_handler = &proc_dointvec,
55661+ },
55662+#endif
55663+#ifdef CONFIG_GRKERNSEC_TPE
55664+ {
55665+ .ctl_name = CTL_UNNUMBERED,
55666+ .procname = "tpe",
55667+ .data = &grsec_enable_tpe,
55668+ .maxlen = sizeof(int),
55669+ .mode = 0600,
55670+ .proc_handler = &proc_dointvec,
55671+ },
55672+ {
55673+ .ctl_name = CTL_UNNUMBERED,
55674+ .procname = "tpe_gid",
55675+ .data = &grsec_tpe_gid,
55676+ .maxlen = sizeof(int),
55677+ .mode = 0600,
55678+ .proc_handler = &proc_dointvec,
55679+ },
55680+#endif
55681+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55682+ {
55683+ .ctl_name = CTL_UNNUMBERED,
55684+ .procname = "tpe_invert",
55685+ .data = &grsec_enable_tpe_invert,
55686+ .maxlen = sizeof(int),
55687+ .mode = 0600,
55688+ .proc_handler = &proc_dointvec,
55689+ },
55690+#endif
55691+#ifdef CONFIG_GRKERNSEC_TPE_ALL
55692+ {
55693+ .ctl_name = CTL_UNNUMBERED,
55694+ .procname = "tpe_restrict_all",
55695+ .data = &grsec_enable_tpe_all,
55696+ .maxlen = sizeof(int),
55697+ .mode = 0600,
55698+ .proc_handler = &proc_dointvec,
55699+ },
55700+#endif
55701+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55702+ {
55703+ .ctl_name = CTL_UNNUMBERED,
55704+ .procname = "socket_all",
55705+ .data = &grsec_enable_socket_all,
55706+ .maxlen = sizeof(int),
55707+ .mode = 0600,
55708+ .proc_handler = &proc_dointvec,
55709+ },
55710+ {
55711+ .ctl_name = CTL_UNNUMBERED,
55712+ .procname = "socket_all_gid",
55713+ .data = &grsec_socket_all_gid,
55714+ .maxlen = sizeof(int),
55715+ .mode = 0600,
55716+ .proc_handler = &proc_dointvec,
55717+ },
55718+#endif
55719+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55720+ {
55721+ .ctl_name = CTL_UNNUMBERED,
55722+ .procname = "socket_client",
55723+ .data = &grsec_enable_socket_client,
55724+ .maxlen = sizeof(int),
55725+ .mode = 0600,
55726+ .proc_handler = &proc_dointvec,
55727+ },
55728+ {
55729+ .ctl_name = CTL_UNNUMBERED,
55730+ .procname = "socket_client_gid",
55731+ .data = &grsec_socket_client_gid,
55732+ .maxlen = sizeof(int),
55733+ .mode = 0600,
55734+ .proc_handler = &proc_dointvec,
55735+ },
55736+#endif
55737+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55738+ {
55739+ .ctl_name = CTL_UNNUMBERED,
55740+ .procname = "socket_server",
55741+ .data = &grsec_enable_socket_server,
55742+ .maxlen = sizeof(int),
55743+ .mode = 0600,
55744+ .proc_handler = &proc_dointvec,
55745+ },
55746+ {
55747+ .ctl_name = CTL_UNNUMBERED,
55748+ .procname = "socket_server_gid",
55749+ .data = &grsec_socket_server_gid,
55750+ .maxlen = sizeof(int),
55751+ .mode = 0600,
55752+ .proc_handler = &proc_dointvec,
55753+ },
55754+#endif
55755+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
55756+ {
55757+ .ctl_name = CTL_UNNUMBERED,
55758+ .procname = "audit_group",
55759+ .data = &grsec_enable_group,
55760+ .maxlen = sizeof(int),
55761+ .mode = 0600,
55762+ .proc_handler = &proc_dointvec,
55763+ },
55764+ {
55765+ .ctl_name = CTL_UNNUMBERED,
55766+ .procname = "audit_gid",
55767+ .data = &grsec_audit_gid,
55768+ .maxlen = sizeof(int),
55769+ .mode = 0600,
55770+ .proc_handler = &proc_dointvec,
55771+ },
55772+#endif
55773+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55774+ {
55775+ .ctl_name = CTL_UNNUMBERED,
55776+ .procname = "audit_chdir",
55777+ .data = &grsec_enable_chdir,
55778+ .maxlen = sizeof(int),
55779+ .mode = 0600,
55780+ .proc_handler = &proc_dointvec,
55781+ },
55782+#endif
55783+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55784+ {
55785+ .ctl_name = CTL_UNNUMBERED,
55786+ .procname = "audit_mount",
55787+ .data = &grsec_enable_mount,
55788+ .maxlen = sizeof(int),
55789+ .mode = 0600,
55790+ .proc_handler = &proc_dointvec,
55791+ },
55792+#endif
55793+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55794+ {
55795+ .ctl_name = CTL_UNNUMBERED,
55796+ .procname = "audit_textrel",
55797+ .data = &grsec_enable_audit_textrel,
55798+ .maxlen = sizeof(int),
55799+ .mode = 0600,
55800+ .proc_handler = &proc_dointvec,
55801+ },
55802+#endif
55803+#ifdef CONFIG_GRKERNSEC_DMESG
55804+ {
55805+ .ctl_name = CTL_UNNUMBERED,
55806+ .procname = "dmesg",
55807+ .data = &grsec_enable_dmesg,
55808+ .maxlen = sizeof(int),
55809+ .mode = 0600,
55810+ .proc_handler = &proc_dointvec,
55811+ },
55812+#endif
55813+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55814+ {
55815+ .ctl_name = CTL_UNNUMBERED,
55816+ .procname = "chroot_findtask",
55817+ .data = &grsec_enable_chroot_findtask,
55818+ .maxlen = sizeof(int),
55819+ .mode = 0600,
55820+ .proc_handler = &proc_dointvec,
55821+ },
55822+#endif
55823+#ifdef CONFIG_GRKERNSEC_RESLOG
55824+ {
55825+ .ctl_name = CTL_UNNUMBERED,
55826+ .procname = "resource_logging",
55827+ .data = &grsec_resource_logging,
55828+ .maxlen = sizeof(int),
55829+ .mode = 0600,
55830+ .proc_handler = &proc_dointvec,
55831+ },
55832+#endif
55833+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55834+ {
55835+ .ctl_name = CTL_UNNUMBERED,
55836+ .procname = "audit_ptrace",
55837+ .data = &grsec_enable_audit_ptrace,
55838+ .maxlen = sizeof(int),
55839+ .mode = 0600,
55840+ .proc_handler = &proc_dointvec,
55841+ },
55842+#endif
55843+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55844+ {
55845+ .ctl_name = CTL_UNNUMBERED,
55846+ .procname = "harden_ptrace",
55847+ .data = &grsec_enable_harden_ptrace,
55848+ .maxlen = sizeof(int),
55849+ .mode = 0600,
55850+ .proc_handler = &proc_dointvec,
55851+ },
55852+#endif
55853+ {
55854+ .ctl_name = CTL_UNNUMBERED,
55855+ .procname = "grsec_lock",
55856+ .data = &grsec_lock,
55857+ .maxlen = sizeof(int),
55858+ .mode = 0600,
55859+ .proc_handler = &proc_dointvec,
55860+ },
55861+#endif
55862+#ifdef CONFIG_GRKERNSEC_ROFS
55863+ {
55864+ .ctl_name = CTL_UNNUMBERED,
55865+ .procname = "romount_protect",
55866+ .data = &grsec_enable_rofs,
55867+ .maxlen = sizeof(int),
55868+ .mode = 0600,
55869+ .proc_handler = &proc_dointvec_minmax,
55870+ .extra1 = &one,
55871+ .extra2 = &one,
55872+ },
55873+#endif
55874+ { .ctl_name = 0 }
55875+};
55876+#endif
55877diff -urNp linux-2.6.32.44/grsecurity/grsec_time.c linux-2.6.32.44/grsecurity/grsec_time.c
55878--- linux-2.6.32.44/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
55879+++ linux-2.6.32.44/grsecurity/grsec_time.c 2011-04-17 15:56:46.000000000 -0400
55880@@ -0,0 +1,16 @@
55881+#include <linux/kernel.h>
55882+#include <linux/sched.h>
55883+#include <linux/grinternal.h>
55884+#include <linux/module.h>
55885+
55886+void
55887+gr_log_timechange(void)
55888+{
55889+#ifdef CONFIG_GRKERNSEC_TIME
55890+ if (grsec_enable_time)
55891+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
55892+#endif
55893+ return;
55894+}
55895+
55896+EXPORT_SYMBOL(gr_log_timechange);
55897diff -urNp linux-2.6.32.44/grsecurity/grsec_tpe.c linux-2.6.32.44/grsecurity/grsec_tpe.c
55898--- linux-2.6.32.44/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
55899+++ linux-2.6.32.44/grsecurity/grsec_tpe.c 2011-04-17 15:56:46.000000000 -0400
55900@@ -0,0 +1,39 @@
55901+#include <linux/kernel.h>
55902+#include <linux/sched.h>
55903+#include <linux/file.h>
55904+#include <linux/fs.h>
55905+#include <linux/grinternal.h>
55906+
55907+extern int gr_acl_tpe_check(void);
55908+
55909+int
55910+gr_tpe_allow(const struct file *file)
55911+{
55912+#ifdef CONFIG_GRKERNSEC
55913+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
55914+ const struct cred *cred = current_cred();
55915+
55916+ if (cred->uid && ((grsec_enable_tpe &&
55917+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55918+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
55919+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
55920+#else
55921+ in_group_p(grsec_tpe_gid)
55922+#endif
55923+ ) || gr_acl_tpe_check()) &&
55924+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
55925+ (inode->i_mode & S_IWOTH))))) {
55926+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
55927+ return 0;
55928+ }
55929+#ifdef CONFIG_GRKERNSEC_TPE_ALL
55930+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
55931+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
55932+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
55933+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
55934+ return 0;
55935+ }
55936+#endif
55937+#endif
55938+ return 1;
55939+}
55940diff -urNp linux-2.6.32.44/grsecurity/grsum.c linux-2.6.32.44/grsecurity/grsum.c
55941--- linux-2.6.32.44/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
55942+++ linux-2.6.32.44/grsecurity/grsum.c 2011-04-17 15:56:46.000000000 -0400
55943@@ -0,0 +1,61 @@
55944+#include <linux/err.h>
55945+#include <linux/kernel.h>
55946+#include <linux/sched.h>
55947+#include <linux/mm.h>
55948+#include <linux/scatterlist.h>
55949+#include <linux/crypto.h>
55950+#include <linux/gracl.h>
55951+
55952+
55953+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
55954+#error "crypto and sha256 must be built into the kernel"
55955+#endif
55956+
55957+int
55958+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
55959+{
55960+ char *p;
55961+ struct crypto_hash *tfm;
55962+ struct hash_desc desc;
55963+ struct scatterlist sg;
55964+ unsigned char temp_sum[GR_SHA_LEN];
55965+ volatile int retval = 0;
55966+ volatile int dummy = 0;
55967+ unsigned int i;
55968+
55969+ sg_init_table(&sg, 1);
55970+
55971+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
55972+ if (IS_ERR(tfm)) {
55973+ /* should never happen, since sha256 should be built in */
55974+ return 1;
55975+ }
55976+
55977+ desc.tfm = tfm;
55978+ desc.flags = 0;
55979+
55980+ crypto_hash_init(&desc);
55981+
55982+ p = salt;
55983+ sg_set_buf(&sg, p, GR_SALT_LEN);
55984+ crypto_hash_update(&desc, &sg, sg.length);
55985+
55986+ p = entry->pw;
55987+ sg_set_buf(&sg, p, strlen(p));
55988+
55989+ crypto_hash_update(&desc, &sg, sg.length);
55990+
55991+ crypto_hash_final(&desc, temp_sum);
55992+
55993+ memset(entry->pw, 0, GR_PW_LEN);
55994+
55995+ for (i = 0; i < GR_SHA_LEN; i++)
55996+ if (sum[i] != temp_sum[i])
55997+ retval = 1;
55998+ else
55999+ dummy = 1; // waste a cycle
56000+
56001+ crypto_free_hash(tfm);
56002+
56003+ return retval;
56004+}
56005diff -urNp linux-2.6.32.44/grsecurity/Kconfig linux-2.6.32.44/grsecurity/Kconfig
56006--- linux-2.6.32.44/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
56007+++ linux-2.6.32.44/grsecurity/Kconfig 2011-08-11 19:58:19.000000000 -0400
56008@@ -0,0 +1,1035 @@
56009+#
56010+# grecurity configuration
56011+#
56012+
56013+menu "Grsecurity"
56014+
56015+config GRKERNSEC
56016+ bool "Grsecurity"
56017+ select CRYPTO
56018+ select CRYPTO_SHA256
56019+ help
56020+ If you say Y here, you will be able to configure many features
56021+ that will enhance the security of your system. It is highly
56022+ recommended that you say Y here and read through the help
56023+ for each option so that you fully understand the features and
56024+ can evaluate their usefulness for your machine.
56025+
56026+choice
56027+ prompt "Security Level"
56028+ depends on GRKERNSEC
56029+ default GRKERNSEC_CUSTOM
56030+
56031+config GRKERNSEC_LOW
56032+ bool "Low"
56033+ select GRKERNSEC_LINK
56034+ select GRKERNSEC_FIFO
56035+ select GRKERNSEC_RANDNET
56036+ select GRKERNSEC_DMESG
56037+ select GRKERNSEC_CHROOT
56038+ select GRKERNSEC_CHROOT_CHDIR
56039+
56040+ help
56041+ If you choose this option, several of the grsecurity options will
56042+ be enabled that will give you greater protection against a number
56043+ of attacks, while assuring that none of your software will have any
56044+ conflicts with the additional security measures. If you run a lot
56045+ of unusual software, or you are having problems with the higher
56046+ security levels, you should say Y here. With this option, the
56047+ following features are enabled:
56048+
56049+ - Linking restrictions
56050+ - FIFO restrictions
56051+ - Restricted dmesg
56052+ - Enforced chdir("/") on chroot
56053+ - Runtime module disabling
56054+
56055+config GRKERNSEC_MEDIUM
56056+ bool "Medium"
56057+ select PAX
56058+ select PAX_EI_PAX
56059+ select PAX_PT_PAX_FLAGS
56060+ select PAX_HAVE_ACL_FLAGS
56061+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
56062+ select GRKERNSEC_CHROOT
56063+ select GRKERNSEC_CHROOT_SYSCTL
56064+ select GRKERNSEC_LINK
56065+ select GRKERNSEC_FIFO
56066+ select GRKERNSEC_DMESG
56067+ select GRKERNSEC_RANDNET
56068+ select GRKERNSEC_FORKFAIL
56069+ select GRKERNSEC_TIME
56070+ select GRKERNSEC_SIGNAL
56071+ select GRKERNSEC_CHROOT
56072+ select GRKERNSEC_CHROOT_UNIX
56073+ select GRKERNSEC_CHROOT_MOUNT
56074+ select GRKERNSEC_CHROOT_PIVOT
56075+ select GRKERNSEC_CHROOT_DOUBLE
56076+ select GRKERNSEC_CHROOT_CHDIR
56077+ select GRKERNSEC_CHROOT_MKNOD
56078+ select GRKERNSEC_PROC
56079+ select GRKERNSEC_PROC_USERGROUP
56080+ select PAX_RANDUSTACK
56081+ select PAX_ASLR
56082+ select PAX_RANDMMAP
56083+ select PAX_REFCOUNT if (X86 || SPARC64)
56084+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
56085+
56086+ help
56087+ If you say Y here, several features in addition to those included
56088+ in the low additional security level will be enabled. These
56089+ features provide even more security to your system, though in rare
56090+ cases they may be incompatible with very old or poorly written
56091+ software. If you enable this option, make sure that your auth
56092+ service (identd) is running as gid 1001. With this option,
56093+ the following features (in addition to those provided in the
56094+ low additional security level) will be enabled:
56095+
56096+ - Failed fork logging
56097+ - Time change logging
56098+ - Signal logging
56099+ - Deny mounts in chroot
56100+ - Deny double chrooting
56101+ - Deny sysctl writes in chroot
56102+ - Deny mknod in chroot
56103+ - Deny access to abstract AF_UNIX sockets out of chroot
56104+ - Deny pivot_root in chroot
56105+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
56106+ - /proc restrictions with special GID set to 10 (usually wheel)
56107+ - Address Space Layout Randomization (ASLR)
56108+ - Prevent exploitation of most refcount overflows
56109+ - Bounds checking of copying between the kernel and userland
56110+
56111+config GRKERNSEC_HIGH
56112+ bool "High"
56113+ select GRKERNSEC_LINK
56114+ select GRKERNSEC_FIFO
56115+ select GRKERNSEC_DMESG
56116+ select GRKERNSEC_FORKFAIL
56117+ select GRKERNSEC_TIME
56118+ select GRKERNSEC_SIGNAL
56119+ select GRKERNSEC_CHROOT
56120+ select GRKERNSEC_CHROOT_SHMAT
56121+ select GRKERNSEC_CHROOT_UNIX
56122+ select GRKERNSEC_CHROOT_MOUNT
56123+ select GRKERNSEC_CHROOT_FCHDIR
56124+ select GRKERNSEC_CHROOT_PIVOT
56125+ select GRKERNSEC_CHROOT_DOUBLE
56126+ select GRKERNSEC_CHROOT_CHDIR
56127+ select GRKERNSEC_CHROOT_MKNOD
56128+ select GRKERNSEC_CHROOT_CAPS
56129+ select GRKERNSEC_CHROOT_SYSCTL
56130+ select GRKERNSEC_CHROOT_FINDTASK
56131+ select GRKERNSEC_SYSFS_RESTRICT
56132+ select GRKERNSEC_PROC
56133+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
56134+ select GRKERNSEC_HIDESYM
56135+ select GRKERNSEC_BRUTE
56136+ select GRKERNSEC_PROC_USERGROUP
56137+ select GRKERNSEC_KMEM
56138+ select GRKERNSEC_RESLOG
56139+ select GRKERNSEC_RANDNET
56140+ select GRKERNSEC_PROC_ADD
56141+ select GRKERNSEC_CHROOT_CHMOD
56142+ select GRKERNSEC_CHROOT_NICE
56143+ select GRKERNSEC_AUDIT_MOUNT
56144+ select GRKERNSEC_MODHARDEN if (MODULES)
56145+ select GRKERNSEC_HARDEN_PTRACE
56146+ select GRKERNSEC_VM86 if (X86_32)
56147+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
56148+ select PAX
56149+ select PAX_RANDUSTACK
56150+ select PAX_ASLR
56151+ select PAX_RANDMMAP
56152+ select PAX_NOEXEC
56153+ select PAX_MPROTECT
56154+ select PAX_EI_PAX
56155+ select PAX_PT_PAX_FLAGS
56156+ select PAX_HAVE_ACL_FLAGS
56157+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
56158+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
56159+ select PAX_RANDKSTACK if (X86_TSC && X86)
56160+ select PAX_SEGMEXEC if (X86_32)
56161+ select PAX_PAGEEXEC
56162+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
56163+ select PAX_EMUTRAMP if (PARISC)
56164+ select PAX_EMUSIGRT if (PARISC)
56165+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
56166+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
56167+ select PAX_REFCOUNT if (X86 || SPARC64)
56168+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
56169+ help
56170+ If you say Y here, many of the features of grsecurity will be
56171+ enabled, which will protect you against many kinds of attacks
56172+ against your system. The heightened security comes at a cost
56173+ of an increased chance of incompatibilities with rare software
56174+ on your machine. Since this security level enables PaX, you should
56175+ view <http://pax.grsecurity.net> and read about the PaX
56176+ project. While you are there, download chpax and run it on
56177+ binaries that cause problems with PaX. Also remember that
56178+ since the /proc restrictions are enabled, you must run your
56179+ identd as gid 1001. This security level enables the following
56180+ features in addition to those listed in the low and medium
56181+ security levels:
56182+
56183+ - Additional /proc restrictions
56184+ - Chmod restrictions in chroot
56185+ - No signals, ptrace, or viewing of processes outside of chroot
56186+ - Capability restrictions in chroot
56187+ - Deny fchdir out of chroot
56188+ - Priority restrictions in chroot
56189+ - Segmentation-based implementation of PaX
56190+ - Mprotect restrictions
56191+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
56192+ - Kernel stack randomization
56193+ - Mount/unmount/remount logging
56194+ - Kernel symbol hiding
56195+ - Prevention of memory exhaustion-based exploits
56196+ - Hardening of module auto-loading
56197+ - Ptrace restrictions
56198+ - Restricted vm86 mode
56199+ - Restricted sysfs/debugfs
56200+ - Active kernel exploit response
56201+
56202+config GRKERNSEC_CUSTOM
56203+ bool "Custom"
56204+ help
56205+ If you say Y here, you will be able to configure every grsecurity
56206+ option, which allows you to enable many more features that aren't
56207+ covered in the basic security levels. These additional features
56208+ include TPE, socket restrictions, and the sysctl system for
56209+ grsecurity. It is advised that you read through the help for
56210+ each option to determine its usefulness in your situation.
56211+
56212+endchoice
56213+
56214+menu "Address Space Protection"
56215+depends on GRKERNSEC
56216+
56217+config GRKERNSEC_KMEM
56218+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
56219+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56220+ help
56221+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56222+ be written to via mmap or otherwise to modify the running kernel.
56223+ /dev/port will also not be allowed to be opened. If you have module
56224+ support disabled, enabling this will close up four ways that are
56225+ currently used to insert malicious code into the running kernel.
56226+ Even with all these features enabled, we still highly recommend that
56227+ you use the RBAC system, as it is still possible for an attacker to
56228+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56229+ If you are not using XFree86, you may be able to stop this additional
56230+ case by enabling the 'Disable privileged I/O' option. Though nothing
56231+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56232+ but only to video memory, which is the only writing we allow in this
56233+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56234+ not be allowed to mprotect it with PROT_WRITE later.
56235+ It is highly recommended that you say Y here if you meet all the
56236+ conditions above.
56237+
56238+config GRKERNSEC_VM86
56239+ bool "Restrict VM86 mode"
56240+ depends on X86_32
56241+
56242+ help
56243+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56244+ make use of a special execution mode on 32bit x86 processors called
56245+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56246+ video cards and will still work with this option enabled. The purpose
56247+ of the option is to prevent exploitation of emulation errors in
56248+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56249+ Nearly all users should be able to enable this option.
56250+
56251+config GRKERNSEC_IO
56252+ bool "Disable privileged I/O"
56253+ depends on X86
56254+ select RTC_CLASS
56255+ select RTC_INTF_DEV
56256+ select RTC_DRV_CMOS
56257+
56258+ help
56259+ If you say Y here, all ioperm and iopl calls will return an error.
56260+ Ioperm and iopl can be used to modify the running kernel.
56261+ Unfortunately, some programs need this access to operate properly,
56262+ the most notable of which are XFree86 and hwclock. hwclock can be
56263+ remedied by having RTC support in the kernel, so real-time
56264+ clock support is enabled if this option is enabled, to ensure
56265+ that hwclock operates correctly. XFree86 still will not
56266+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56267+ IF YOU USE XFree86. If you use XFree86 and you still want to
56268+ protect your kernel against modification, use the RBAC system.
56269+
56270+config GRKERNSEC_PROC_MEMMAP
56271+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
56272+ default y if (PAX_NOEXEC || PAX_ASLR)
56273+ depends on PAX_NOEXEC || PAX_ASLR
56274+ help
56275+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56276+ give no information about the addresses of its mappings if
56277+ PaX features that rely on random addresses are enabled on the task.
56278+ If you use PaX it is greatly recommended that you say Y here as it
56279+ closes up a hole that makes the full ASLR useless for suid
56280+ binaries.
56281+
56282+config GRKERNSEC_BRUTE
56283+ bool "Deter exploit bruteforcing"
56284+ help
56285+ If you say Y here, attempts to bruteforce exploits against forking
56286+ daemons such as apache or sshd, as well as against suid/sgid binaries
56287+ will be deterred. When a child of a forking daemon is killed by PaX
56288+ or crashes due to an illegal instruction or other suspicious signal,
56289+ the parent process will be delayed 30 seconds upon every subsequent
56290+ fork until the administrator is able to assess the situation and
56291+ restart the daemon.
56292+ In the suid/sgid case, the attempt is logged, the user has all their
56293+ processes terminated, and they are prevented from executing any further
56294+ processes for 15 minutes.
56295+ It is recommended that you also enable signal logging in the auditing
56296+ section so that logs are generated when a process triggers a suspicious
56297+ signal.
56298+ If the sysctl option is enabled, a sysctl option with name
56299+ "deter_bruteforce" is created.
56300+
56301+config GRKERNSEC_MODHARDEN
56302+ bool "Harden module auto-loading"
56303+ depends on MODULES
56304+ help
56305+ If you say Y here, module auto-loading in response to use of some
56306+ feature implemented by an unloaded module will be restricted to
56307+ root users. Enabling this option helps defend against attacks
56308+ by unprivileged users who abuse the auto-loading behavior to
56309+ cause a vulnerable module to load that is then exploited.
56310+
56311+ If this option prevents a legitimate use of auto-loading for a
56312+ non-root user, the administrator can execute modprobe manually
56313+ with the exact name of the module mentioned in the alert log.
56314+ Alternatively, the administrator can add the module to the list
56315+ of modules loaded at boot by modifying init scripts.
56316+
56317+ Modification of init scripts will most likely be needed on
56318+ Ubuntu servers with encrypted home directory support enabled,
56319+ as the first non-root user logging in will cause the ecb(aes),
56320+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56321+
56322+config GRKERNSEC_HIDESYM
56323+ bool "Hide kernel symbols"
56324+ help
56325+ If you say Y here, getting information on loaded modules, and
56326+ displaying all kernel symbols through a syscall will be restricted
56327+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56328+ /proc/kallsyms will be restricted to the root user. The RBAC
56329+ system can hide that entry even from root.
56330+
56331+ This option also prevents leaking of kernel addresses through
56332+ several /proc entries.
56333+
56334+ Note that this option is only effective provided the following
56335+ conditions are met:
56336+ 1) The kernel using grsecurity is not precompiled by some distribution
56337+ 2) You have also enabled GRKERNSEC_DMESG
56338+ 3) You are using the RBAC system and hiding other files such as your
56339+ kernel image and System.map. Alternatively, enabling this option
56340+ causes the permissions on /boot, /lib/modules, and the kernel
56341+ source directory to change at compile time to prevent
56342+ reading by non-root users.
56343+ If the above conditions are met, this option will aid in providing a
56344+ useful protection against local kernel exploitation of overflows
56345+ and arbitrary read/write vulnerabilities.
56346+
56347+config GRKERNSEC_KERN_LOCKOUT
56348+ bool "Active kernel exploit response"
56349+ depends on X86 || ARM || PPC || SPARC
56350+ help
56351+ If you say Y here, when a PaX alert is triggered due to suspicious
56352+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56353+ or an OOPs occurs due to bad memory accesses, instead of just
56354+ terminating the offending process (and potentially allowing
56355+ a subsequent exploit from the same user), we will take one of two
56356+ actions:
56357+ If the user was root, we will panic the system
56358+ If the user was non-root, we will log the attempt, terminate
56359+ all processes owned by the user, then prevent them from creating
56360+ any new processes until the system is restarted
56361+ This deters repeated kernel exploitation/bruteforcing attempts
56362+ and is useful for later forensics.
56363+
56364+endmenu
56365+menu "Role Based Access Control Options"
56366+depends on GRKERNSEC
56367+
56368+config GRKERNSEC_RBAC_DEBUG
56369+ bool
56370+
56371+config GRKERNSEC_NO_RBAC
56372+ bool "Disable RBAC system"
56373+ help
56374+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56375+ preventing the RBAC system from being enabled. You should only say Y
56376+ here if you have no intention of using the RBAC system, so as to prevent
56377+ an attacker with root access from misusing the RBAC system to hide files
56378+ and processes when loadable module support and /dev/[k]mem have been
56379+ locked down.
56380+
56381+config GRKERNSEC_ACL_HIDEKERN
56382+ bool "Hide kernel processes"
56383+ help
56384+ If you say Y here, all kernel threads will be hidden to all
56385+ processes but those whose subject has the "view hidden processes"
56386+ flag.
56387+
56388+config GRKERNSEC_ACL_MAXTRIES
56389+ int "Maximum tries before password lockout"
56390+ default 3
56391+ help
56392+ This option enforces the maximum number of times a user can attempt
56393+ to authorize themselves with the grsecurity RBAC system before being
56394+ denied the ability to attempt authorization again for a specified time.
56395+ The lower the number, the harder it will be to brute-force a password.
56396+
56397+config GRKERNSEC_ACL_TIMEOUT
56398+ int "Time to wait after max password tries, in seconds"
56399+ default 30
56400+ help
56401+ This option specifies the time the user must wait after attempting to
56402+ authorize to the RBAC system with the maximum number of invalid
56403+ passwords. The higher the number, the harder it will be to brute-force
56404+ a password.
56405+
56406+endmenu
56407+menu "Filesystem Protections"
56408+depends on GRKERNSEC
56409+
56410+config GRKERNSEC_PROC
56411+ bool "Proc restrictions"
56412+ help
56413+ If you say Y here, the permissions of the /proc filesystem
56414+ will be altered to enhance system security and privacy. You MUST
56415+ choose either a user only restriction or a user and group restriction.
56416+ Depending upon the option you choose, you can either restrict users to
56417+ see only the processes they themselves run, or choose a group that can
56418+ view all processes and files normally restricted to root if you choose
56419+ the "restrict to user only" option. NOTE: If you're running identd as
56420+ a non-root user, you will have to run it as the group you specify here.
56421+
56422+config GRKERNSEC_PROC_USER
56423+ bool "Restrict /proc to user only"
56424+ depends on GRKERNSEC_PROC
56425+ help
56426+ If you say Y here, non-root users will only be able to view their own
56427+ processes, and restricts them from viewing network-related information,
56428+ and viewing kernel symbol and module information.
56429+
56430+config GRKERNSEC_PROC_USERGROUP
56431+ bool "Allow special group"
56432+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56433+ help
56434+ If you say Y here, you will be able to select a group that will be
56435+ able to view all processes and network-related information. If you've
56436+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56437+ remain hidden. This option is useful if you want to run identd as
56438+ a non-root user.
56439+
56440+config GRKERNSEC_PROC_GID
56441+ int "GID for special group"
56442+ depends on GRKERNSEC_PROC_USERGROUP
56443+ default 1001
56444+
56445+config GRKERNSEC_PROC_ADD
56446+ bool "Additional restrictions"
56447+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56448+ help
56449+ If you say Y here, additional restrictions will be placed on
56450+ /proc that keep normal users from viewing device information and
56451+ slabinfo information that could be useful for exploits.
56452+
56453+config GRKERNSEC_LINK
56454+ bool "Linking restrictions"
56455+ help
56456+ If you say Y here, /tmp race exploits will be prevented, since users
56457+ will no longer be able to follow symlinks owned by other users in
56458+ world-writable +t directories (e.g. /tmp), unless the owner of the
56459+ symlink is the owner of the directory. users will also not be
56460+ able to hardlink to files they do not own. If the sysctl option is
56461+ enabled, a sysctl option with name "linking_restrictions" is created.
56462+
56463+config GRKERNSEC_FIFO
56464+ bool "FIFO restrictions"
56465+ help
56466+ If you say Y here, users will not be able to write to FIFOs they don't
56467+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56468+ the FIFO is the same owner of the directory it's held in. If the sysctl
56469+ option is enabled, a sysctl option with name "fifo_restrictions" is
56470+ created.
56471+
56472+config GRKERNSEC_SYSFS_RESTRICT
56473+ bool "Sysfs/debugfs restriction"
56474+ depends on SYSFS
56475+ help
56476+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56477+ any filesystem normally mounted under it (e.g. debugfs) will only
56478+ be accessible by root. These filesystems generally provide access
56479+ to hardware and debug information that isn't appropriate for unprivileged
56480+ users of the system. Sysfs and debugfs have also become a large source
56481+ of new vulnerabilities, ranging from infoleaks to local compromise.
56482+ There has been very little oversight with an eye toward security involved
56483+ in adding new exporters of information to these filesystems, so their
56484+ use is discouraged.
56485+ This option is equivalent to a chmod 0700 of the mount paths.
56486+
56487+config GRKERNSEC_ROFS
56488+ bool "Runtime read-only mount protection"
56489+ help
56490+ If you say Y here, a sysctl option with name "romount_protect" will
56491+ be created. By setting this option to 1 at runtime, filesystems
56492+ will be protected in the following ways:
56493+ * No new writable mounts will be allowed
56494+ * Existing read-only mounts won't be able to be remounted read/write
56495+ * Write operations will be denied on all block devices
56496+ This option acts independently of grsec_lock: once it is set to 1,
56497+ it cannot be turned off. Therefore, please be mindful of the resulting
56498+ behavior if this option is enabled in an init script on a read-only
56499+ filesystem. This feature is mainly intended for secure embedded systems.
56500+
56501+config GRKERNSEC_CHROOT
56502+ bool "Chroot jail restrictions"
56503+ help
56504+ If you say Y here, you will be able to choose several options that will
56505+ make breaking out of a chrooted jail much more difficult. If you
56506+ encounter no software incompatibilities with the following options, it
56507+ is recommended that you enable each one.
56508+
56509+config GRKERNSEC_CHROOT_MOUNT
56510+ bool "Deny mounts"
56511+ depends on GRKERNSEC_CHROOT
56512+ help
56513+ If you say Y here, processes inside a chroot will not be able to
56514+ mount or remount filesystems. If the sysctl option is enabled, a
56515+ sysctl option with name "chroot_deny_mount" is created.
56516+
56517+config GRKERNSEC_CHROOT_DOUBLE
56518+ bool "Deny double-chroots"
56519+ depends on GRKERNSEC_CHROOT
56520+ help
56521+ If you say Y here, processes inside a chroot will not be able to chroot
56522+ again outside the chroot. This is a widely used method of breaking
56523+ out of a chroot jail and should not be allowed. If the sysctl
56524+ option is enabled, a sysctl option with name
56525+ "chroot_deny_chroot" is created.
56526+
56527+config GRKERNSEC_CHROOT_PIVOT
56528+ bool "Deny pivot_root in chroot"
56529+ depends on GRKERNSEC_CHROOT
56530+ help
56531+ If you say Y here, processes inside a chroot will not be able to use
56532+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56533+ works similar to chroot in that it changes the root filesystem. This
56534+ function could be misused in a chrooted process to attempt to break out
56535+ of the chroot, and therefore should not be allowed. If the sysctl
56536+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56537+ created.
56538+
56539+config GRKERNSEC_CHROOT_CHDIR
56540+ bool "Enforce chdir(\"/\") on all chroots"
56541+ depends on GRKERNSEC_CHROOT
56542+ help
56543+ If you say Y here, the current working directory of all newly-chrooted
56544+ applications will be set to the the root directory of the chroot.
56545+ The man page on chroot(2) states:
56546+ Note that this call does not change the current working
56547+ directory, so that `.' can be outside the tree rooted at
56548+ `/'. In particular, the super-user can escape from a
56549+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56550+
56551+ It is recommended that you say Y here, since it's not known to break
56552+ any software. If the sysctl option is enabled, a sysctl option with
56553+ name "chroot_enforce_chdir" is created.
56554+
56555+config GRKERNSEC_CHROOT_CHMOD
56556+ bool "Deny (f)chmod +s"
56557+ depends on GRKERNSEC_CHROOT
56558+ help
56559+ If you say Y here, processes inside a chroot will not be able to chmod
56560+ or fchmod files to make them have suid or sgid bits. This protects
56561+ against another published method of breaking a chroot. If the sysctl
56562+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56563+ created.
56564+
56565+config GRKERNSEC_CHROOT_FCHDIR
56566+ bool "Deny fchdir out of chroot"
56567+ depends on GRKERNSEC_CHROOT
56568+ help
56569+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56570+ to a file descriptor of the chrooting process that points to a directory
56571+ outside the filesystem will be stopped. If the sysctl option
56572+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56573+
56574+config GRKERNSEC_CHROOT_MKNOD
56575+ bool "Deny mknod"
56576+ depends on GRKERNSEC_CHROOT
56577+ help
56578+ If you say Y here, processes inside a chroot will not be allowed to
56579+ mknod. The problem with using mknod inside a chroot is that it
56580+ would allow an attacker to create a device entry that is the same
56581+ as one on the physical root of your system, which could range from
56582+ anything from the console device to a device for your harddrive (which
56583+ they could then use to wipe the drive or steal data). It is recommended
56584+ that you say Y here, unless you run into software incompatibilities.
56585+ If the sysctl option is enabled, a sysctl option with name
56586+ "chroot_deny_mknod" is created.
56587+
56588+config GRKERNSEC_CHROOT_SHMAT
56589+ bool "Deny shmat() out of chroot"
56590+ depends on GRKERNSEC_CHROOT
56591+ help
56592+ If you say Y here, processes inside a chroot will not be able to attach
56593+ to shared memory segments that were created outside of the chroot jail.
56594+ It is recommended that you say Y here. If the sysctl option is enabled,
56595+ a sysctl option with name "chroot_deny_shmat" is created.
56596+
56597+config GRKERNSEC_CHROOT_UNIX
56598+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56599+ depends on GRKERNSEC_CHROOT
56600+ help
56601+ If you say Y here, processes inside a chroot will not be able to
56602+ connect to abstract (meaning not belonging to a filesystem) Unix
56603+ domain sockets that were bound outside of a chroot. It is recommended
56604+ that you say Y here. If the sysctl option is enabled, a sysctl option
56605+ with name "chroot_deny_unix" is created.
56606+
56607+config GRKERNSEC_CHROOT_FINDTASK
56608+ bool "Protect outside processes"
56609+ depends on GRKERNSEC_CHROOT
56610+ help
56611+ If you say Y here, processes inside a chroot will not be able to
56612+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56613+ getsid, or view any process outside of the chroot. If the sysctl
56614+ option is enabled, a sysctl option with name "chroot_findtask" is
56615+ created.
56616+
56617+config GRKERNSEC_CHROOT_NICE
56618+ bool "Restrict priority changes"
56619+ depends on GRKERNSEC_CHROOT
56620+ help
56621+ If you say Y here, processes inside a chroot will not be able to raise
56622+ the priority of processes in the chroot, or alter the priority of
56623+ processes outside the chroot. This provides more security than simply
56624+ removing CAP_SYS_NICE from the process' capability set. If the
56625+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56626+ is created.
56627+
56628+config GRKERNSEC_CHROOT_SYSCTL
56629+ bool "Deny sysctl writes"
56630+ depends on GRKERNSEC_CHROOT
56631+ help
56632+ If you say Y here, an attacker in a chroot will not be able to
56633+ write to sysctl entries, either by sysctl(2) or through a /proc
56634+ interface. It is strongly recommended that you say Y here. If the
56635+ sysctl option is enabled, a sysctl option with name
56636+ "chroot_deny_sysctl" is created.
56637+
56638+config GRKERNSEC_CHROOT_CAPS
56639+ bool "Capability restrictions"
56640+ depends on GRKERNSEC_CHROOT
56641+ help
56642+ If you say Y here, the capabilities on all root processes within a
56643+ chroot jail will be lowered to stop module insertion, raw i/o,
56644+ system and net admin tasks, rebooting the system, modifying immutable
56645+ files, modifying IPC owned by another, and changing the system time.
56646+ This is left an option because it can break some apps. Disable this
56647+ if your chrooted apps are having problems performing those kinds of
56648+ tasks. If the sysctl option is enabled, a sysctl option with
56649+ name "chroot_caps" is created.
56650+
56651+endmenu
56652+menu "Kernel Auditing"
56653+depends on GRKERNSEC
56654+
56655+config GRKERNSEC_AUDIT_GROUP
56656+ bool "Single group for auditing"
56657+ help
56658+ If you say Y here, the exec, chdir, and (un)mount logging features
56659+ will only operate on a group you specify. This option is recommended
56660+ if you only want to watch certain users instead of having a large
56661+ amount of logs from the entire system. If the sysctl option is enabled,
56662+ a sysctl option with name "audit_group" is created.
56663+
56664+config GRKERNSEC_AUDIT_GID
56665+ int "GID for auditing"
56666+ depends on GRKERNSEC_AUDIT_GROUP
56667+ default 1007
56668+
56669+config GRKERNSEC_EXECLOG
56670+ bool "Exec logging"
56671+ help
56672+ If you say Y here, all execve() calls will be logged (since the
56673+ other exec*() calls are frontends to execve(), all execution
56674+ will be logged). Useful for shell-servers that like to keep track
56675+ of their users. If the sysctl option is enabled, a sysctl option with
56676+ name "exec_logging" is created.
56677+ WARNING: This option when enabled will produce a LOT of logs, especially
56678+ on an active system.
56679+
56680+config GRKERNSEC_RESLOG
56681+ bool "Resource logging"
56682+ help
56683+ If you say Y here, all attempts to overstep resource limits will
56684+ be logged with the resource name, the requested size, and the current
56685+ limit. It is highly recommended that you say Y here. If the sysctl
56686+ option is enabled, a sysctl option with name "resource_logging" is
56687+ created. If the RBAC system is enabled, the sysctl value is ignored.
56688+
56689+config GRKERNSEC_CHROOT_EXECLOG
56690+ bool "Log execs within chroot"
56691+ help
56692+ If you say Y here, all executions inside a chroot jail will be logged
56693+ to syslog. This can cause a large amount of logs if certain
56694+ applications (eg. djb's daemontools) are installed on the system, and
56695+ is therefore left as an option. If the sysctl option is enabled, a
56696+ sysctl option with name "chroot_execlog" is created.
56697+
56698+config GRKERNSEC_AUDIT_PTRACE
56699+ bool "Ptrace logging"
56700+ help
56701+ If you say Y here, all attempts to attach to a process via ptrace
56702+ will be logged. If the sysctl option is enabled, a sysctl option
56703+ with name "audit_ptrace" is created.
56704+
56705+config GRKERNSEC_AUDIT_CHDIR
56706+ bool "Chdir logging"
56707+ help
56708+ If you say Y here, all chdir() calls will be logged. If the sysctl
56709+ option is enabled, a sysctl option with name "audit_chdir" is created.
56710+
56711+config GRKERNSEC_AUDIT_MOUNT
56712+ bool "(Un)Mount logging"
56713+ help
56714+ If you say Y here, all mounts and unmounts will be logged. If the
56715+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56716+ created.
56717+
56718+config GRKERNSEC_SIGNAL
56719+ bool "Signal logging"
56720+ help
56721+ If you say Y here, certain important signals will be logged, such as
56722+ SIGSEGV, which will as a result inform you of when a error in a program
56723+ occurred, which in some cases could mean a possible exploit attempt.
56724+ If the sysctl option is enabled, a sysctl option with name
56725+ "signal_logging" is created.
56726+
56727+config GRKERNSEC_FORKFAIL
56728+ bool "Fork failure logging"
56729+ help
56730+ If you say Y here, all failed fork() attempts will be logged.
56731+ This could suggest a fork bomb, or someone attempting to overstep
56732+ their process limit. If the sysctl option is enabled, a sysctl option
56733+ with name "forkfail_logging" is created.
56734+
56735+config GRKERNSEC_TIME
56736+ bool "Time change logging"
56737+ help
56738+ If you say Y here, any changes of the system clock will be logged.
56739+ If the sysctl option is enabled, a sysctl option with name
56740+ "timechange_logging" is created.
56741+
56742+config GRKERNSEC_PROC_IPADDR
56743+ bool "/proc/<pid>/ipaddr support"
56744+ help
56745+ If you say Y here, a new entry will be added to each /proc/<pid>
56746+ directory that contains the IP address of the person using the task.
56747+ The IP is carried across local TCP and AF_UNIX stream sockets.
56748+ This information can be useful for IDS/IPSes to perform remote response
56749+ to a local attack. The entry is readable by only the owner of the
56750+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56751+ the RBAC system), and thus does not create privacy concerns.
56752+
56753+config GRKERNSEC_RWXMAP_LOG
56754+ bool 'Denied RWX mmap/mprotect logging'
56755+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56756+ help
56757+ If you say Y here, calls to mmap() and mprotect() with explicit
56758+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56759+ denied by the PAX_MPROTECT feature. If the sysctl option is
56760+ enabled, a sysctl option with name "rwxmap_logging" is created.
56761+
56762+config GRKERNSEC_AUDIT_TEXTREL
56763+ bool 'ELF text relocations logging (READ HELP)'
56764+ depends on PAX_MPROTECT
56765+ help
56766+ If you say Y here, text relocations will be logged with the filename
56767+ of the offending library or binary. The purpose of the feature is
56768+ to help Linux distribution developers get rid of libraries and
56769+ binaries that need text relocations which hinder the future progress
56770+ of PaX. Only Linux distribution developers should say Y here, and
56771+ never on a production machine, as this option creates an information
56772+ leak that could aid an attacker in defeating the randomization of
56773+ a single memory region. If the sysctl option is enabled, a sysctl
56774+ option with name "audit_textrel" is created.
56775+
56776+endmenu
56777+
56778+menu "Executable Protections"
56779+depends on GRKERNSEC
56780+
56781+config GRKERNSEC_DMESG
56782+ bool "Dmesg(8) restriction"
56783+ help
56784+ If you say Y here, non-root users will not be able to use dmesg(8)
56785+ to view up to the last 4kb of messages in the kernel's log buffer.
56786+ The kernel's log buffer often contains kernel addresses and other
56787+ identifying information useful to an attacker in fingerprinting a
56788+ system for a targeted exploit.
56789+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56790+ created.
56791+
56792+config GRKERNSEC_HARDEN_PTRACE
56793+ bool "Deter ptrace-based process snooping"
56794+ help
56795+ If you say Y here, TTY sniffers and other malicious monitoring
56796+ programs implemented through ptrace will be defeated. If you
56797+ have been using the RBAC system, this option has already been
56798+ enabled for several years for all users, with the ability to make
56799+ fine-grained exceptions.
56800+
56801+ This option only affects the ability of non-root users to ptrace
56802+ processes that are not a descendent of the ptracing process.
56803+ This means that strace ./binary and gdb ./binary will still work,
56804+ but attaching to arbitrary processes will not. If the sysctl
56805+ option is enabled, a sysctl option with name "harden_ptrace" is
56806+ created.
56807+
56808+config GRKERNSEC_TPE
56809+ bool "Trusted Path Execution (TPE)"
56810+ help
56811+ If you say Y here, you will be able to choose a gid to add to the
56812+ supplementary groups of users you want to mark as "untrusted."
56813+ These users will not be able to execute any files that are not in
56814+ root-owned directories writable only by root. If the sysctl option
56815+ is enabled, a sysctl option with name "tpe" is created.
56816+
56817+config GRKERNSEC_TPE_ALL
56818+ bool "Partially restrict all non-root users"
56819+ depends on GRKERNSEC_TPE
56820+ help
56821+ If you say Y here, all non-root users will be covered under
56822+ a weaker TPE restriction. This is separate from, and in addition to,
56823+ the main TPE options that you have selected elsewhere. Thus, if a
56824+ "trusted" GID is chosen, this restriction applies to even that GID.
56825+ Under this restriction, all non-root users will only be allowed to
56826+ execute files in directories they own that are not group or
56827+ world-writable, or in directories owned by root and writable only by
56828+ root. If the sysctl option is enabled, a sysctl option with name
56829+ "tpe_restrict_all" is created.
56830+
56831+config GRKERNSEC_TPE_INVERT
56832+ bool "Invert GID option"
56833+ depends on GRKERNSEC_TPE
56834+ help
56835+ If you say Y here, the group you specify in the TPE configuration will
56836+ decide what group TPE restrictions will be *disabled* for. This
56837+ option is useful if you want TPE restrictions to be applied to most
56838+ users on the system. If the sysctl option is enabled, a sysctl option
56839+ with name "tpe_invert" is created. Unlike other sysctl options, this
56840+ entry will default to on for backward-compatibility.
56841+
56842+config GRKERNSEC_TPE_GID
56843+ int "GID for untrusted users"
56844+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56845+ default 1005
56846+ help
56847+ Setting this GID determines what group TPE restrictions will be
56848+ *enabled* for. If the sysctl option is enabled, a sysctl option
56849+ with name "tpe_gid" is created.
56850+
56851+config GRKERNSEC_TPE_GID
56852+ int "GID for trusted users"
56853+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56854+ default 1005
56855+ help
56856+ Setting this GID determines what group TPE restrictions will be
56857+ *disabled* for. If the sysctl option is enabled, a sysctl option
56858+ with name "tpe_gid" is created.
56859+
56860+endmenu
56861+menu "Network Protections"
56862+depends on GRKERNSEC
56863+
56864+config GRKERNSEC_RANDNET
56865+ bool "Larger entropy pools"
56866+ help
56867+ If you say Y here, the entropy pools used for many features of Linux
56868+ and grsecurity will be doubled in size. Since several grsecurity
56869+ features use additional randomness, it is recommended that you say Y
56870+ here. Saying Y here has a similar effect as modifying
56871+ /proc/sys/kernel/random/poolsize.
56872+
56873+config GRKERNSEC_BLACKHOLE
56874+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56875+ help
56876+ If you say Y here, neither TCP resets nor ICMP
56877+ destination-unreachable packets will be sent in response to packets
56878+ sent to ports for which no associated listening process exists.
56879+ This feature supports both IPV4 and IPV6 and exempts the
56880+ loopback interface from blackholing. Enabling this feature
56881+ makes a host more resilient to DoS attacks and reduces network
56882+ visibility against scanners.
56883+
56884+ The blackhole feature as-implemented is equivalent to the FreeBSD
56885+ blackhole feature, as it prevents RST responses to all packets, not
56886+ just SYNs. Under most application behavior this causes no
56887+ problems, but applications (like haproxy) may not close certain
56888+ connections in a way that cleanly terminates them on the remote
56889+ end, leaving the remote host in LAST_ACK state. Because of this
56890+ side-effect and to prevent intentional LAST_ACK DoSes, this
56891+ feature also adds automatic mitigation against such attacks.
56892+ The mitigation drastically reduces the amount of time a socket
56893+ can spend in LAST_ACK state. If you're using haproxy and not
56894+ all servers it connects to have this option enabled, consider
56895+ disabling this feature on the haproxy host.
56896+
56897+ If the sysctl option is enabled, two sysctl options with names
56898+ "ip_blackhole" and "lastack_retries" will be created.
56899+ While "ip_blackhole" takes the standard zero/non-zero on/off
56900+ toggle, "lastack_retries" uses the same kinds of values as
56901+ "tcp_retries1" and "tcp_retries2". The default value of 4
56902+ prevents a socket from lasting more than 45 seconds in LAST_ACK
56903+ state.
56904+
56905+config GRKERNSEC_SOCKET
56906+ bool "Socket restrictions"
56907+ help
56908+ If you say Y here, you will be able to choose from several options.
56909+ If you assign a GID on your system and add it to the supplementary
56910+ groups of users you want to restrict socket access to, this patch
56911+ will perform up to three things, based on the option(s) you choose.
56912+
56913+config GRKERNSEC_SOCKET_ALL
56914+ bool "Deny any sockets to group"
56915+ depends on GRKERNSEC_SOCKET
56916+ help
56917+ If you say Y here, you will be able to choose a GID of whose users will
56918+ be unable to connect to other hosts from your machine or run server
56919+ applications from your machine. If the sysctl option is enabled, a
56920+ sysctl option with name "socket_all" is created.
56921+
56922+config GRKERNSEC_SOCKET_ALL_GID
56923+ int "GID to deny all sockets for"
56924+ depends on GRKERNSEC_SOCKET_ALL
56925+ default 1004
56926+ help
56927+ Here you can choose the GID to disable socket access for. Remember to
56928+ add the users you want socket access disabled for to the GID
56929+ specified here. If the sysctl option is enabled, a sysctl option
56930+ with name "socket_all_gid" is created.
56931+
56932+config GRKERNSEC_SOCKET_CLIENT
56933+ bool "Deny client sockets to group"
56934+ depends on GRKERNSEC_SOCKET
56935+ help
56936+ If you say Y here, you will be able to choose a GID of whose users will
56937+ be unable to connect to other hosts from your machine, but will be
56938+ able to run servers. If this option is enabled, all users in the group
56939+ you specify will have to use passive mode when initiating ftp transfers
56940+ from the shell on your machine. If the sysctl option is enabled, a
56941+ sysctl option with name "socket_client" is created.
56942+
56943+config GRKERNSEC_SOCKET_CLIENT_GID
56944+ int "GID to deny client sockets for"
56945+ depends on GRKERNSEC_SOCKET_CLIENT
56946+ default 1003
56947+ help
56948+ Here you can choose the GID to disable client socket access for.
56949+ Remember to add the users you want client socket access disabled for to
56950+ the GID specified here. If the sysctl option is enabled, a sysctl
56951+ option with name "socket_client_gid" is created.
56952+
56953+config GRKERNSEC_SOCKET_SERVER
56954+ bool "Deny server sockets to group"
56955+ depends on GRKERNSEC_SOCKET
56956+ help
56957+ If you say Y here, you will be able to choose a GID of whose users will
56958+ be unable to run server applications from your machine. If the sysctl
56959+ option is enabled, a sysctl option with name "socket_server" is created.
56960+
56961+config GRKERNSEC_SOCKET_SERVER_GID
56962+ int "GID to deny server sockets for"
56963+ depends on GRKERNSEC_SOCKET_SERVER
56964+ default 1002
56965+ help
56966+ Here you can choose the GID to disable server socket access for.
56967+ Remember to add the users you want server socket access disabled for to
56968+ the GID specified here. If the sysctl option is enabled, a sysctl
56969+ option with name "socket_server_gid" is created.
56970+
56971+endmenu
56972+menu "Sysctl support"
56973+depends on GRKERNSEC && SYSCTL
56974+
56975+config GRKERNSEC_SYSCTL
56976+ bool "Sysctl support"
56977+ help
56978+ If you say Y here, you will be able to change the options that
56979+ grsecurity runs with at bootup, without having to recompile your
56980+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56981+ to enable (1) or disable (0) various features. All the sysctl entries
56982+ are mutable until the "grsec_lock" entry is set to a non-zero value.
56983+ All features enabled in the kernel configuration are disabled at boot
56984+ if you do not say Y to the "Turn on features by default" option.
56985+ All options should be set at startup, and the grsec_lock entry should
56986+ be set to a non-zero value after all the options are set.
56987+ *THIS IS EXTREMELY IMPORTANT*
56988+
56989+config GRKERNSEC_SYSCTL_DISTRO
56990+ bool "Extra sysctl support for distro makers (READ HELP)"
56991+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56992+ help
56993+ If you say Y here, additional sysctl options will be created
56994+ for features that affect processes running as root. Therefore,
56995+ it is critical when using this option that the grsec_lock entry be
56996+ enabled after boot. Only distros with prebuilt kernel packages
56997+ with this option enabled that can ensure grsec_lock is enabled
56998+ after boot should use this option.
56999+ *Failure to set grsec_lock after boot makes all grsec features
57000+ this option covers useless*
57001+
57002+ Currently this option creates the following sysctl entries:
57003+ "Disable Privileged I/O": "disable_priv_io"
57004+
57005+config GRKERNSEC_SYSCTL_ON
57006+ bool "Turn on features by default"
57007+ depends on GRKERNSEC_SYSCTL
57008+ help
57009+ If you say Y here, instead of having all features enabled in the
57010+ kernel configuration disabled at boot time, the features will be
57011+ enabled at boot time. It is recommended you say Y here unless
57012+ there is some reason you would want all sysctl-tunable features to
57013+ be disabled by default. As mentioned elsewhere, it is important
57014+ to enable the grsec_lock entry once you have finished modifying
57015+ the sysctl entries.
57016+
57017+endmenu
57018+menu "Logging Options"
57019+depends on GRKERNSEC
57020+
57021+config GRKERNSEC_FLOODTIME
57022+ int "Seconds in between log messages (minimum)"
57023+ default 10
57024+ help
57025+ This option allows you to enforce the number of seconds between
57026+ grsecurity log messages. The default should be suitable for most
57027+ people, however, if you choose to change it, choose a value small enough
57028+ to allow informative logs to be produced, but large enough to
57029+ prevent flooding.
57030+
57031+config GRKERNSEC_FLOODBURST
57032+ int "Number of messages in a burst (maximum)"
57033+ default 4
57034+ help
57035+ This option allows you to choose the maximum number of messages allowed
57036+ within the flood time interval you chose in a separate option. The
57037+ default should be suitable for most people, however if you find that
57038+ many of your logs are being interpreted as flooding, you may want to
57039+ raise this value.
57040+
57041+endmenu
57042+
57043+endmenu
57044diff -urNp linux-2.6.32.44/grsecurity/Makefile linux-2.6.32.44/grsecurity/Makefile
57045--- linux-2.6.32.44/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
57046+++ linux-2.6.32.44/grsecurity/Makefile 2011-05-24 20:27:46.000000000 -0400
57047@@ -0,0 +1,33 @@
57048+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57049+# during 2001-2009 it has been completely redesigned by Brad Spengler
57050+# into an RBAC system
57051+#
57052+# All code in this directory and various hooks inserted throughout the kernel
57053+# are copyright Brad Spengler - Open Source Security, Inc., and released
57054+# under the GPL v2 or higher
57055+
57056+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57057+ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
57058+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57059+
57060+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57061+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57062+ gracl_learn.o grsec_log.o
57063+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57064+
57065+ifdef CONFIG_NET
57066+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57067+endif
57068+
57069+ifndef CONFIG_GRKERNSEC
57070+obj-y += grsec_disabled.o
57071+endif
57072+
57073+ifdef CONFIG_GRKERNSEC_HIDESYM
57074+extra-y := grsec_hidesym.o
57075+$(obj)/grsec_hidesym.o:
57076+ @-chmod -f 500 /boot
57077+ @-chmod -f 500 /lib/modules
57078+ @-chmod -f 700 .
57079+ @echo ' grsec: protected kernel image paths'
57080+endif
57081diff -urNp linux-2.6.32.44/include/acpi/acpi_bus.h linux-2.6.32.44/include/acpi/acpi_bus.h
57082--- linux-2.6.32.44/include/acpi/acpi_bus.h 2011-03-27 14:31:47.000000000 -0400
57083+++ linux-2.6.32.44/include/acpi/acpi_bus.h 2011-08-05 20:33:55.000000000 -0400
57084@@ -107,7 +107,7 @@ struct acpi_device_ops {
57085 acpi_op_bind bind;
57086 acpi_op_unbind unbind;
57087 acpi_op_notify notify;
57088-};
57089+} __no_const;
57090
57091 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
57092
57093diff -urNp linux-2.6.32.44/include/acpi/acpi_drivers.h linux-2.6.32.44/include/acpi/acpi_drivers.h
57094--- linux-2.6.32.44/include/acpi/acpi_drivers.h 2011-03-27 14:31:47.000000000 -0400
57095+++ linux-2.6.32.44/include/acpi/acpi_drivers.h 2011-04-17 15:56:46.000000000 -0400
57096@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acp
57097 Dock Station
57098 -------------------------------------------------------------------------- */
57099 struct acpi_dock_ops {
57100- acpi_notify_handler handler;
57101- acpi_notify_handler uevent;
57102+ const acpi_notify_handler handler;
57103+ const acpi_notify_handler uevent;
57104 };
57105
57106 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
57107@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
57108 extern int register_dock_notifier(struct notifier_block *nb);
57109 extern void unregister_dock_notifier(struct notifier_block *nb);
57110 extern int register_hotplug_dock_device(acpi_handle handle,
57111- struct acpi_dock_ops *ops,
57112+ const struct acpi_dock_ops *ops,
57113 void *context);
57114 extern void unregister_hotplug_dock_device(acpi_handle handle);
57115 #else
57116@@ -144,7 +144,7 @@ static inline void unregister_dock_notif
57117 {
57118 }
57119 static inline int register_hotplug_dock_device(acpi_handle handle,
57120- struct acpi_dock_ops *ops,
57121+ const struct acpi_dock_ops *ops,
57122 void *context)
57123 {
57124 return -ENODEV;
57125diff -urNp linux-2.6.32.44/include/asm-generic/atomic-long.h linux-2.6.32.44/include/asm-generic/atomic-long.h
57126--- linux-2.6.32.44/include/asm-generic/atomic-long.h 2011-03-27 14:31:47.000000000 -0400
57127+++ linux-2.6.32.44/include/asm-generic/atomic-long.h 2011-07-13 22:21:25.000000000 -0400
57128@@ -22,6 +22,12 @@
57129
57130 typedef atomic64_t atomic_long_t;
57131
57132+#ifdef CONFIG_PAX_REFCOUNT
57133+typedef atomic64_unchecked_t atomic_long_unchecked_t;
57134+#else
57135+typedef atomic64_t atomic_long_unchecked_t;
57136+#endif
57137+
57138 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
57139
57140 static inline long atomic_long_read(atomic_long_t *l)
57141@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
57142 return (long)atomic64_read(v);
57143 }
57144
57145+#ifdef CONFIG_PAX_REFCOUNT
57146+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57147+{
57148+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57149+
57150+ return (long)atomic64_read_unchecked(v);
57151+}
57152+#endif
57153+
57154 static inline void atomic_long_set(atomic_long_t *l, long i)
57155 {
57156 atomic64_t *v = (atomic64_t *)l;
57157@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
57158 atomic64_set(v, i);
57159 }
57160
57161+#ifdef CONFIG_PAX_REFCOUNT
57162+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57163+{
57164+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57165+
57166+ atomic64_set_unchecked(v, i);
57167+}
57168+#endif
57169+
57170 static inline void atomic_long_inc(atomic_long_t *l)
57171 {
57172 atomic64_t *v = (atomic64_t *)l;
57173@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
57174 atomic64_inc(v);
57175 }
57176
57177+#ifdef CONFIG_PAX_REFCOUNT
57178+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57179+{
57180+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57181+
57182+ atomic64_inc_unchecked(v);
57183+}
57184+#endif
57185+
57186 static inline void atomic_long_dec(atomic_long_t *l)
57187 {
57188 atomic64_t *v = (atomic64_t *)l;
57189@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
57190 atomic64_dec(v);
57191 }
57192
57193+#ifdef CONFIG_PAX_REFCOUNT
57194+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57195+{
57196+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57197+
57198+ atomic64_dec_unchecked(v);
57199+}
57200+#endif
57201+
57202 static inline void atomic_long_add(long i, atomic_long_t *l)
57203 {
57204 atomic64_t *v = (atomic64_t *)l;
57205@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
57206 atomic64_add(i, v);
57207 }
57208
57209+#ifdef CONFIG_PAX_REFCOUNT
57210+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57211+{
57212+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57213+
57214+ atomic64_add_unchecked(i, v);
57215+}
57216+#endif
57217+
57218 static inline void atomic_long_sub(long i, atomic_long_t *l)
57219 {
57220 atomic64_t *v = (atomic64_t *)l;
57221@@ -115,6 +166,15 @@ static inline long atomic_long_inc_retur
57222 return (long)atomic64_inc_return(v);
57223 }
57224
57225+#ifdef CONFIG_PAX_REFCOUNT
57226+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57227+{
57228+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57229+
57230+ return (long)atomic64_inc_return_unchecked(v);
57231+}
57232+#endif
57233+
57234 static inline long atomic_long_dec_return(atomic_long_t *l)
57235 {
57236 atomic64_t *v = (atomic64_t *)l;
57237@@ -140,6 +200,12 @@ static inline long atomic_long_add_unles
57238
57239 typedef atomic_t atomic_long_t;
57240
57241+#ifdef CONFIG_PAX_REFCOUNT
57242+typedef atomic_unchecked_t atomic_long_unchecked_t;
57243+#else
57244+typedef atomic_t atomic_long_unchecked_t;
57245+#endif
57246+
57247 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
57248 static inline long atomic_long_read(atomic_long_t *l)
57249 {
57250@@ -148,6 +214,15 @@ static inline long atomic_long_read(atom
57251 return (long)atomic_read(v);
57252 }
57253
57254+#ifdef CONFIG_PAX_REFCOUNT
57255+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57256+{
57257+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57258+
57259+ return (long)atomic_read_unchecked(v);
57260+}
57261+#endif
57262+
57263 static inline void atomic_long_set(atomic_long_t *l, long i)
57264 {
57265 atomic_t *v = (atomic_t *)l;
57266@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomi
57267 atomic_set(v, i);
57268 }
57269
57270+#ifdef CONFIG_PAX_REFCOUNT
57271+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57272+{
57273+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57274+
57275+ atomic_set_unchecked(v, i);
57276+}
57277+#endif
57278+
57279 static inline void atomic_long_inc(atomic_long_t *l)
57280 {
57281 atomic_t *v = (atomic_t *)l;
57282@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomi
57283 atomic_inc(v);
57284 }
57285
57286+#ifdef CONFIG_PAX_REFCOUNT
57287+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57288+{
57289+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57290+
57291+ atomic_inc_unchecked(v);
57292+}
57293+#endif
57294+
57295 static inline void atomic_long_dec(atomic_long_t *l)
57296 {
57297 atomic_t *v = (atomic_t *)l;
57298@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomi
57299 atomic_dec(v);
57300 }
57301
57302+#ifdef CONFIG_PAX_REFCOUNT
57303+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57304+{
57305+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57306+
57307+ atomic_dec_unchecked(v);
57308+}
57309+#endif
57310+
57311 static inline void atomic_long_add(long i, atomic_long_t *l)
57312 {
57313 atomic_t *v = (atomic_t *)l;
57314@@ -176,6 +278,15 @@ static inline void atomic_long_add(long
57315 atomic_add(i, v);
57316 }
57317
57318+#ifdef CONFIG_PAX_REFCOUNT
57319+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57320+{
57321+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57322+
57323+ atomic_add_unchecked(i, v);
57324+}
57325+#endif
57326+
57327 static inline void atomic_long_sub(long i, atomic_long_t *l)
57328 {
57329 atomic_t *v = (atomic_t *)l;
57330@@ -232,6 +343,15 @@ static inline long atomic_long_inc_retur
57331 return (long)atomic_inc_return(v);
57332 }
57333
57334+#ifdef CONFIG_PAX_REFCOUNT
57335+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57336+{
57337+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57338+
57339+ return (long)atomic_inc_return_unchecked(v);
57340+}
57341+#endif
57342+
57343 static inline long atomic_long_dec_return(atomic_long_t *l)
57344 {
57345 atomic_t *v = (atomic_t *)l;
57346@@ -255,4 +375,47 @@ static inline long atomic_long_add_unles
57347
57348 #endif /* BITS_PER_LONG == 64 */
57349
57350+#ifdef CONFIG_PAX_REFCOUNT
57351+static inline void pax_refcount_needs_these_functions(void)
57352+{
57353+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
57354+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
57355+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
57356+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
57357+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
57358+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
57359+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
57360+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
57361+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
57362+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
57363+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
57364+
57365+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
57366+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
57367+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
57368+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
57369+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
57370+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
57371+}
57372+#else
57373+#define atomic_read_unchecked(v) atomic_read(v)
57374+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
57375+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
57376+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
57377+#define atomic_inc_unchecked(v) atomic_inc(v)
57378+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
57379+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
57380+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
57381+#define atomic_dec_unchecked(v) atomic_dec(v)
57382+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
57383+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
57384+
57385+#define atomic_long_read_unchecked(v) atomic_long_read(v)
57386+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
57387+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
57388+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
57389+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
57390+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
57391+#endif
57392+
57393 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
57394diff -urNp linux-2.6.32.44/include/asm-generic/cache.h linux-2.6.32.44/include/asm-generic/cache.h
57395--- linux-2.6.32.44/include/asm-generic/cache.h 2011-03-27 14:31:47.000000000 -0400
57396+++ linux-2.6.32.44/include/asm-generic/cache.h 2011-07-06 19:53:33.000000000 -0400
57397@@ -6,7 +6,7 @@
57398 * cache lines need to provide their own cache.h.
57399 */
57400
57401-#define L1_CACHE_SHIFT 5
57402-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
57403+#define L1_CACHE_SHIFT 5UL
57404+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
57405
57406 #endif /* __ASM_GENERIC_CACHE_H */
57407diff -urNp linux-2.6.32.44/include/asm-generic/dma-mapping-common.h linux-2.6.32.44/include/asm-generic/dma-mapping-common.h
57408--- linux-2.6.32.44/include/asm-generic/dma-mapping-common.h 2011-03-27 14:31:47.000000000 -0400
57409+++ linux-2.6.32.44/include/asm-generic/dma-mapping-common.h 2011-04-17 15:56:46.000000000 -0400
57410@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
57411 enum dma_data_direction dir,
57412 struct dma_attrs *attrs)
57413 {
57414- struct dma_map_ops *ops = get_dma_ops(dev);
57415+ const struct dma_map_ops *ops = get_dma_ops(dev);
57416 dma_addr_t addr;
57417
57418 kmemcheck_mark_initialized(ptr, size);
57419@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
57420 enum dma_data_direction dir,
57421 struct dma_attrs *attrs)
57422 {
57423- struct dma_map_ops *ops = get_dma_ops(dev);
57424+ const struct dma_map_ops *ops = get_dma_ops(dev);
57425
57426 BUG_ON(!valid_dma_direction(dir));
57427 if (ops->unmap_page)
57428@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
57429 int nents, enum dma_data_direction dir,
57430 struct dma_attrs *attrs)
57431 {
57432- struct dma_map_ops *ops = get_dma_ops(dev);
57433+ const struct dma_map_ops *ops = get_dma_ops(dev);
57434 int i, ents;
57435 struct scatterlist *s;
57436
57437@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
57438 int nents, enum dma_data_direction dir,
57439 struct dma_attrs *attrs)
57440 {
57441- struct dma_map_ops *ops = get_dma_ops(dev);
57442+ const struct dma_map_ops *ops = get_dma_ops(dev);
57443
57444 BUG_ON(!valid_dma_direction(dir));
57445 debug_dma_unmap_sg(dev, sg, nents, dir);
57446@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
57447 size_t offset, size_t size,
57448 enum dma_data_direction dir)
57449 {
57450- struct dma_map_ops *ops = get_dma_ops(dev);
57451+ const struct dma_map_ops *ops = get_dma_ops(dev);
57452 dma_addr_t addr;
57453
57454 kmemcheck_mark_initialized(page_address(page) + offset, size);
57455@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
57456 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
57457 size_t size, enum dma_data_direction dir)
57458 {
57459- struct dma_map_ops *ops = get_dma_ops(dev);
57460+ const struct dma_map_ops *ops = get_dma_ops(dev);
57461
57462 BUG_ON(!valid_dma_direction(dir));
57463 if (ops->unmap_page)
57464@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
57465 size_t size,
57466 enum dma_data_direction dir)
57467 {
57468- struct dma_map_ops *ops = get_dma_ops(dev);
57469+ const struct dma_map_ops *ops = get_dma_ops(dev);
57470
57471 BUG_ON(!valid_dma_direction(dir));
57472 if (ops->sync_single_for_cpu)
57473@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
57474 dma_addr_t addr, size_t size,
57475 enum dma_data_direction dir)
57476 {
57477- struct dma_map_ops *ops = get_dma_ops(dev);
57478+ const struct dma_map_ops *ops = get_dma_ops(dev);
57479
57480 BUG_ON(!valid_dma_direction(dir));
57481 if (ops->sync_single_for_device)
57482@@ -123,7 +123,7 @@ static inline void dma_sync_single_range
57483 size_t size,
57484 enum dma_data_direction dir)
57485 {
57486- struct dma_map_ops *ops = get_dma_ops(dev);
57487+ const struct dma_map_ops *ops = get_dma_ops(dev);
57488
57489 BUG_ON(!valid_dma_direction(dir));
57490 if (ops->sync_single_range_for_cpu) {
57491@@ -140,7 +140,7 @@ static inline void dma_sync_single_range
57492 size_t size,
57493 enum dma_data_direction dir)
57494 {
57495- struct dma_map_ops *ops = get_dma_ops(dev);
57496+ const struct dma_map_ops *ops = get_dma_ops(dev);
57497
57498 BUG_ON(!valid_dma_direction(dir));
57499 if (ops->sync_single_range_for_device) {
57500@@ -155,7 +155,7 @@ static inline void
57501 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
57502 int nelems, enum dma_data_direction dir)
57503 {
57504- struct dma_map_ops *ops = get_dma_ops(dev);
57505+ const struct dma_map_ops *ops = get_dma_ops(dev);
57506
57507 BUG_ON(!valid_dma_direction(dir));
57508 if (ops->sync_sg_for_cpu)
57509@@ -167,7 +167,7 @@ static inline void
57510 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
57511 int nelems, enum dma_data_direction dir)
57512 {
57513- struct dma_map_ops *ops = get_dma_ops(dev);
57514+ const struct dma_map_ops *ops = get_dma_ops(dev);
57515
57516 BUG_ON(!valid_dma_direction(dir));
57517 if (ops->sync_sg_for_device)
57518diff -urNp linux-2.6.32.44/include/asm-generic/futex.h linux-2.6.32.44/include/asm-generic/futex.h
57519--- linux-2.6.32.44/include/asm-generic/futex.h 2011-03-27 14:31:47.000000000 -0400
57520+++ linux-2.6.32.44/include/asm-generic/futex.h 2011-04-17 15:56:46.000000000 -0400
57521@@ -6,7 +6,7 @@
57522 #include <asm/errno.h>
57523
57524 static inline int
57525-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
57526+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
57527 {
57528 int op = (encoded_op >> 28) & 7;
57529 int cmp = (encoded_op >> 24) & 15;
57530@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
57531 }
57532
57533 static inline int
57534-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
57535+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
57536 {
57537 return -ENOSYS;
57538 }
57539diff -urNp linux-2.6.32.44/include/asm-generic/int-l64.h linux-2.6.32.44/include/asm-generic/int-l64.h
57540--- linux-2.6.32.44/include/asm-generic/int-l64.h 2011-03-27 14:31:47.000000000 -0400
57541+++ linux-2.6.32.44/include/asm-generic/int-l64.h 2011-04-17 15:56:46.000000000 -0400
57542@@ -46,6 +46,8 @@ typedef unsigned int u32;
57543 typedef signed long s64;
57544 typedef unsigned long u64;
57545
57546+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
57547+
57548 #define S8_C(x) x
57549 #define U8_C(x) x ## U
57550 #define S16_C(x) x
57551diff -urNp linux-2.6.32.44/include/asm-generic/int-ll64.h linux-2.6.32.44/include/asm-generic/int-ll64.h
57552--- linux-2.6.32.44/include/asm-generic/int-ll64.h 2011-03-27 14:31:47.000000000 -0400
57553+++ linux-2.6.32.44/include/asm-generic/int-ll64.h 2011-04-17 15:56:46.000000000 -0400
57554@@ -51,6 +51,8 @@ typedef unsigned int u32;
57555 typedef signed long long s64;
57556 typedef unsigned long long u64;
57557
57558+typedef unsigned long long intoverflow_t;
57559+
57560 #define S8_C(x) x
57561 #define U8_C(x) x ## U
57562 #define S16_C(x) x
57563diff -urNp linux-2.6.32.44/include/asm-generic/kmap_types.h linux-2.6.32.44/include/asm-generic/kmap_types.h
57564--- linux-2.6.32.44/include/asm-generic/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
57565+++ linux-2.6.32.44/include/asm-generic/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
57566@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
57567 KMAP_D(16) KM_IRQ_PTE,
57568 KMAP_D(17) KM_NMI,
57569 KMAP_D(18) KM_NMI_PTE,
57570-KMAP_D(19) KM_TYPE_NR
57571+KMAP_D(19) KM_CLEARPAGE,
57572+KMAP_D(20) KM_TYPE_NR
57573 };
57574
57575 #undef KMAP_D
57576diff -urNp linux-2.6.32.44/include/asm-generic/pgtable.h linux-2.6.32.44/include/asm-generic/pgtable.h
57577--- linux-2.6.32.44/include/asm-generic/pgtable.h 2011-03-27 14:31:47.000000000 -0400
57578+++ linux-2.6.32.44/include/asm-generic/pgtable.h 2011-04-17 15:56:46.000000000 -0400
57579@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_ar
57580 unsigned long size);
57581 #endif
57582
57583+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
57584+static inline unsigned long pax_open_kernel(void) { return 0; }
57585+#endif
57586+
57587+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
57588+static inline unsigned long pax_close_kernel(void) { return 0; }
57589+#endif
57590+
57591 #endif /* !__ASSEMBLY__ */
57592
57593 #endif /* _ASM_GENERIC_PGTABLE_H */
57594diff -urNp linux-2.6.32.44/include/asm-generic/pgtable-nopmd.h linux-2.6.32.44/include/asm-generic/pgtable-nopmd.h
57595--- linux-2.6.32.44/include/asm-generic/pgtable-nopmd.h 2011-03-27 14:31:47.000000000 -0400
57596+++ linux-2.6.32.44/include/asm-generic/pgtable-nopmd.h 2011-04-17 15:56:46.000000000 -0400
57597@@ -1,14 +1,19 @@
57598 #ifndef _PGTABLE_NOPMD_H
57599 #define _PGTABLE_NOPMD_H
57600
57601-#ifndef __ASSEMBLY__
57602-
57603 #include <asm-generic/pgtable-nopud.h>
57604
57605-struct mm_struct;
57606-
57607 #define __PAGETABLE_PMD_FOLDED
57608
57609+#define PMD_SHIFT PUD_SHIFT
57610+#define PTRS_PER_PMD 1
57611+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
57612+#define PMD_MASK (~(PMD_SIZE-1))
57613+
57614+#ifndef __ASSEMBLY__
57615+
57616+struct mm_struct;
57617+
57618 /*
57619 * Having the pmd type consist of a pud gets the size right, and allows
57620 * us to conceptually access the pud entry that this pmd is folded into
57621@@ -16,11 +21,6 @@ struct mm_struct;
57622 */
57623 typedef struct { pud_t pud; } pmd_t;
57624
57625-#define PMD_SHIFT PUD_SHIFT
57626-#define PTRS_PER_PMD 1
57627-#define PMD_SIZE (1UL << PMD_SHIFT)
57628-#define PMD_MASK (~(PMD_SIZE-1))
57629-
57630 /*
57631 * The "pud_xxx()" functions here are trivial for a folded two-level
57632 * setup: the pmd is never bad, and a pmd always exists (as it's folded
57633diff -urNp linux-2.6.32.44/include/asm-generic/pgtable-nopud.h linux-2.6.32.44/include/asm-generic/pgtable-nopud.h
57634--- linux-2.6.32.44/include/asm-generic/pgtable-nopud.h 2011-03-27 14:31:47.000000000 -0400
57635+++ linux-2.6.32.44/include/asm-generic/pgtable-nopud.h 2011-04-17 15:56:46.000000000 -0400
57636@@ -1,10 +1,15 @@
57637 #ifndef _PGTABLE_NOPUD_H
57638 #define _PGTABLE_NOPUD_H
57639
57640-#ifndef __ASSEMBLY__
57641-
57642 #define __PAGETABLE_PUD_FOLDED
57643
57644+#define PUD_SHIFT PGDIR_SHIFT
57645+#define PTRS_PER_PUD 1
57646+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
57647+#define PUD_MASK (~(PUD_SIZE-1))
57648+
57649+#ifndef __ASSEMBLY__
57650+
57651 /*
57652 * Having the pud type consist of a pgd gets the size right, and allows
57653 * us to conceptually access the pgd entry that this pud is folded into
57654@@ -12,11 +17,6 @@
57655 */
57656 typedef struct { pgd_t pgd; } pud_t;
57657
57658-#define PUD_SHIFT PGDIR_SHIFT
57659-#define PTRS_PER_PUD 1
57660-#define PUD_SIZE (1UL << PUD_SHIFT)
57661-#define PUD_MASK (~(PUD_SIZE-1))
57662-
57663 /*
57664 * The "pgd_xxx()" functions here are trivial for a folded two-level
57665 * setup: the pud is never bad, and a pud always exists (as it's folded
57666diff -urNp linux-2.6.32.44/include/asm-generic/vmlinux.lds.h linux-2.6.32.44/include/asm-generic/vmlinux.lds.h
57667--- linux-2.6.32.44/include/asm-generic/vmlinux.lds.h 2011-03-27 14:31:47.000000000 -0400
57668+++ linux-2.6.32.44/include/asm-generic/vmlinux.lds.h 2011-04-17 15:56:46.000000000 -0400
57669@@ -199,6 +199,7 @@
57670 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
57671 VMLINUX_SYMBOL(__start_rodata) = .; \
57672 *(.rodata) *(.rodata.*) \
57673+ *(.data.read_only) \
57674 *(__vermagic) /* Kernel version magic */ \
57675 *(__markers_strings) /* Markers: strings */ \
57676 *(__tracepoints_strings)/* Tracepoints: strings */ \
57677@@ -656,22 +657,24 @@
57678 * section in the linker script will go there too. @phdr should have
57679 * a leading colon.
57680 *
57681- * Note that this macros defines __per_cpu_load as an absolute symbol.
57682+ * Note that this macros defines per_cpu_load as an absolute symbol.
57683 * If there is no need to put the percpu section at a predetermined
57684 * address, use PERCPU().
57685 */
57686 #define PERCPU_VADDR(vaddr, phdr) \
57687- VMLINUX_SYMBOL(__per_cpu_load) = .; \
57688- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
57689+ per_cpu_load = .; \
57690+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
57691 - LOAD_OFFSET) { \
57692+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
57693 VMLINUX_SYMBOL(__per_cpu_start) = .; \
57694 *(.data.percpu.first) \
57695- *(.data.percpu.page_aligned) \
57696 *(.data.percpu) \
57697+ . = ALIGN(PAGE_SIZE); \
57698+ *(.data.percpu.page_aligned) \
57699 *(.data.percpu.shared_aligned) \
57700 VMLINUX_SYMBOL(__per_cpu_end) = .; \
57701 } phdr \
57702- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
57703+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
57704
57705 /**
57706 * PERCPU - define output section for percpu area, simple version
57707diff -urNp linux-2.6.32.44/include/drm/drm_crtc_helper.h linux-2.6.32.44/include/drm/drm_crtc_helper.h
57708--- linux-2.6.32.44/include/drm/drm_crtc_helper.h 2011-03-27 14:31:47.000000000 -0400
57709+++ linux-2.6.32.44/include/drm/drm_crtc_helper.h 2011-08-05 20:33:55.000000000 -0400
57710@@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
57711
57712 /* reload the current crtc LUT */
57713 void (*load_lut)(struct drm_crtc *crtc);
57714-};
57715+} __no_const;
57716
57717 struct drm_encoder_helper_funcs {
57718 void (*dpms)(struct drm_encoder *encoder, int mode);
57719@@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
57720 struct drm_connector *connector);
57721 /* disable encoder when not in use - more explicit than dpms off */
57722 void (*disable)(struct drm_encoder *encoder);
57723-};
57724+} __no_const;
57725
57726 struct drm_connector_helper_funcs {
57727 int (*get_modes)(struct drm_connector *connector);
57728diff -urNp linux-2.6.32.44/include/drm/drmP.h linux-2.6.32.44/include/drm/drmP.h
57729--- linux-2.6.32.44/include/drm/drmP.h 2011-03-27 14:31:47.000000000 -0400
57730+++ linux-2.6.32.44/include/drm/drmP.h 2011-04-17 15:56:46.000000000 -0400
57731@@ -71,6 +71,7 @@
57732 #include <linux/workqueue.h>
57733 #include <linux/poll.h>
57734 #include <asm/pgalloc.h>
57735+#include <asm/local.h>
57736 #include "drm.h"
57737
57738 #include <linux/idr.h>
57739@@ -814,7 +815,7 @@ struct drm_driver {
57740 void (*vgaarb_irq)(struct drm_device *dev, bool state);
57741
57742 /* Driver private ops for this object */
57743- struct vm_operations_struct *gem_vm_ops;
57744+ const struct vm_operations_struct *gem_vm_ops;
57745
57746 int major;
57747 int minor;
57748@@ -917,7 +918,7 @@ struct drm_device {
57749
57750 /** \name Usage Counters */
57751 /*@{ */
57752- int open_count; /**< Outstanding files open */
57753+ local_t open_count; /**< Outstanding files open */
57754 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
57755 atomic_t vma_count; /**< Outstanding vma areas open */
57756 int buf_use; /**< Buffers in use -- cannot alloc */
57757@@ -928,7 +929,7 @@ struct drm_device {
57758 /*@{ */
57759 unsigned long counters;
57760 enum drm_stat_type types[15];
57761- atomic_t counts[15];
57762+ atomic_unchecked_t counts[15];
57763 /*@} */
57764
57765 struct list_head filelist;
57766@@ -1016,7 +1017,7 @@ struct drm_device {
57767 struct pci_controller *hose;
57768 #endif
57769 struct drm_sg_mem *sg; /**< Scatter gather memory */
57770- unsigned int num_crtcs; /**< Number of CRTCs on this device */
57771+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
57772 void *dev_private; /**< device private data */
57773 void *mm_private;
57774 struct address_space *dev_mapping;
57775@@ -1042,11 +1043,11 @@ struct drm_device {
57776 spinlock_t object_name_lock;
57777 struct idr object_name_idr;
57778 atomic_t object_count;
57779- atomic_t object_memory;
57780+ atomic_unchecked_t object_memory;
57781 atomic_t pin_count;
57782- atomic_t pin_memory;
57783+ atomic_unchecked_t pin_memory;
57784 atomic_t gtt_count;
57785- atomic_t gtt_memory;
57786+ atomic_unchecked_t gtt_memory;
57787 uint32_t gtt_total;
57788 uint32_t invalidate_domains; /* domains pending invalidation */
57789 uint32_t flush_domains; /* domains pending flush */
57790diff -urNp linux-2.6.32.44/include/drm/ttm/ttm_memory.h linux-2.6.32.44/include/drm/ttm/ttm_memory.h
57791--- linux-2.6.32.44/include/drm/ttm/ttm_memory.h 2011-03-27 14:31:47.000000000 -0400
57792+++ linux-2.6.32.44/include/drm/ttm/ttm_memory.h 2011-08-05 20:33:55.000000000 -0400
57793@@ -47,7 +47,7 @@
57794
57795 struct ttm_mem_shrink {
57796 int (*do_shrink) (struct ttm_mem_shrink *);
57797-};
57798+} __no_const;
57799
57800 /**
57801 * struct ttm_mem_global - Global memory accounting structure.
57802diff -urNp linux-2.6.32.44/include/linux/a.out.h linux-2.6.32.44/include/linux/a.out.h
57803--- linux-2.6.32.44/include/linux/a.out.h 2011-03-27 14:31:47.000000000 -0400
57804+++ linux-2.6.32.44/include/linux/a.out.h 2011-04-17 15:56:46.000000000 -0400
57805@@ -39,6 +39,14 @@ enum machine_type {
57806 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
57807 };
57808
57809+/* Constants for the N_FLAGS field */
57810+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57811+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
57812+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
57813+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
57814+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57815+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57816+
57817 #if !defined (N_MAGIC)
57818 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
57819 #endif
57820diff -urNp linux-2.6.32.44/include/linux/atmdev.h linux-2.6.32.44/include/linux/atmdev.h
57821--- linux-2.6.32.44/include/linux/atmdev.h 2011-03-27 14:31:47.000000000 -0400
57822+++ linux-2.6.32.44/include/linux/atmdev.h 2011-04-17 15:56:46.000000000 -0400
57823@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
57824 #endif
57825
57826 struct k_atm_aal_stats {
57827-#define __HANDLE_ITEM(i) atomic_t i
57828+#define __HANDLE_ITEM(i) atomic_unchecked_t i
57829 __AAL_STAT_ITEMS
57830 #undef __HANDLE_ITEM
57831 };
57832diff -urNp linux-2.6.32.44/include/linux/backlight.h linux-2.6.32.44/include/linux/backlight.h
57833--- linux-2.6.32.44/include/linux/backlight.h 2011-03-27 14:31:47.000000000 -0400
57834+++ linux-2.6.32.44/include/linux/backlight.h 2011-04-17 15:56:46.000000000 -0400
57835@@ -36,18 +36,18 @@ struct backlight_device;
57836 struct fb_info;
57837
57838 struct backlight_ops {
57839- unsigned int options;
57840+ const unsigned int options;
57841
57842 #define BL_CORE_SUSPENDRESUME (1 << 0)
57843
57844 /* Notify the backlight driver some property has changed */
57845- int (*update_status)(struct backlight_device *);
57846+ int (* const update_status)(struct backlight_device *);
57847 /* Return the current backlight brightness (accounting for power,
57848 fb_blank etc.) */
57849- int (*get_brightness)(struct backlight_device *);
57850+ int (* const get_brightness)(struct backlight_device *);
57851 /* Check if given framebuffer device is the one bound to this backlight;
57852 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
57853- int (*check_fb)(struct fb_info *);
57854+ int (* const check_fb)(struct fb_info *);
57855 };
57856
57857 /* This structure defines all the properties of a backlight */
57858@@ -86,7 +86,7 @@ struct backlight_device {
57859 registered this device has been unloaded, and if class_get_devdata()
57860 points to something in the body of that driver, it is also invalid. */
57861 struct mutex ops_lock;
57862- struct backlight_ops *ops;
57863+ const struct backlight_ops *ops;
57864
57865 /* The framebuffer notifier block */
57866 struct notifier_block fb_notif;
57867@@ -103,7 +103,7 @@ static inline void backlight_update_stat
57868 }
57869
57870 extern struct backlight_device *backlight_device_register(const char *name,
57871- struct device *dev, void *devdata, struct backlight_ops *ops);
57872+ struct device *dev, void *devdata, const struct backlight_ops *ops);
57873 extern void backlight_device_unregister(struct backlight_device *bd);
57874 extern void backlight_force_update(struct backlight_device *bd,
57875 enum backlight_update_reason reason);
57876diff -urNp linux-2.6.32.44/include/linux/binfmts.h linux-2.6.32.44/include/linux/binfmts.h
57877--- linux-2.6.32.44/include/linux/binfmts.h 2011-04-17 17:00:52.000000000 -0400
57878+++ linux-2.6.32.44/include/linux/binfmts.h 2011-04-17 15:56:46.000000000 -0400
57879@@ -83,6 +83,7 @@ struct linux_binfmt {
57880 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
57881 int (*load_shlib)(struct file *);
57882 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
57883+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
57884 unsigned long min_coredump; /* minimal dump size */
57885 int hasvdso;
57886 };
57887diff -urNp linux-2.6.32.44/include/linux/blkdev.h linux-2.6.32.44/include/linux/blkdev.h
57888--- linux-2.6.32.44/include/linux/blkdev.h 2011-03-27 14:31:47.000000000 -0400
57889+++ linux-2.6.32.44/include/linux/blkdev.h 2011-04-17 15:56:46.000000000 -0400
57890@@ -1265,19 +1265,19 @@ static inline int blk_integrity_rq(struc
57891 #endif /* CONFIG_BLK_DEV_INTEGRITY */
57892
57893 struct block_device_operations {
57894- int (*open) (struct block_device *, fmode_t);
57895- int (*release) (struct gendisk *, fmode_t);
57896- int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57897- int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57898- int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57899- int (*direct_access) (struct block_device *, sector_t,
57900+ int (* const open) (struct block_device *, fmode_t);
57901+ int (* const release) (struct gendisk *, fmode_t);
57902+ int (* const locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57903+ int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57904+ int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57905+ int (* const direct_access) (struct block_device *, sector_t,
57906 void **, unsigned long *);
57907- int (*media_changed) (struct gendisk *);
57908- unsigned long long (*set_capacity) (struct gendisk *,
57909+ int (* const media_changed) (struct gendisk *);
57910+ unsigned long long (* const set_capacity) (struct gendisk *,
57911 unsigned long long);
57912- int (*revalidate_disk) (struct gendisk *);
57913- int (*getgeo)(struct block_device *, struct hd_geometry *);
57914- struct module *owner;
57915+ int (* const revalidate_disk) (struct gendisk *);
57916+ int (*const getgeo)(struct block_device *, struct hd_geometry *);
57917+ struct module * const owner;
57918 };
57919
57920 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
57921diff -urNp linux-2.6.32.44/include/linux/blktrace_api.h linux-2.6.32.44/include/linux/blktrace_api.h
57922--- linux-2.6.32.44/include/linux/blktrace_api.h 2011-03-27 14:31:47.000000000 -0400
57923+++ linux-2.6.32.44/include/linux/blktrace_api.h 2011-05-04 17:56:28.000000000 -0400
57924@@ -160,7 +160,7 @@ struct blk_trace {
57925 struct dentry *dir;
57926 struct dentry *dropped_file;
57927 struct dentry *msg_file;
57928- atomic_t dropped;
57929+ atomic_unchecked_t dropped;
57930 };
57931
57932 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
57933diff -urNp linux-2.6.32.44/include/linux/byteorder/little_endian.h linux-2.6.32.44/include/linux/byteorder/little_endian.h
57934--- linux-2.6.32.44/include/linux/byteorder/little_endian.h 2011-03-27 14:31:47.000000000 -0400
57935+++ linux-2.6.32.44/include/linux/byteorder/little_endian.h 2011-04-17 15:56:46.000000000 -0400
57936@@ -42,51 +42,51 @@
57937
57938 static inline __le64 __cpu_to_le64p(const __u64 *p)
57939 {
57940- return (__force __le64)*p;
57941+ return (__force const __le64)*p;
57942 }
57943 static inline __u64 __le64_to_cpup(const __le64 *p)
57944 {
57945- return (__force __u64)*p;
57946+ return (__force const __u64)*p;
57947 }
57948 static inline __le32 __cpu_to_le32p(const __u32 *p)
57949 {
57950- return (__force __le32)*p;
57951+ return (__force const __le32)*p;
57952 }
57953 static inline __u32 __le32_to_cpup(const __le32 *p)
57954 {
57955- return (__force __u32)*p;
57956+ return (__force const __u32)*p;
57957 }
57958 static inline __le16 __cpu_to_le16p(const __u16 *p)
57959 {
57960- return (__force __le16)*p;
57961+ return (__force const __le16)*p;
57962 }
57963 static inline __u16 __le16_to_cpup(const __le16 *p)
57964 {
57965- return (__force __u16)*p;
57966+ return (__force const __u16)*p;
57967 }
57968 static inline __be64 __cpu_to_be64p(const __u64 *p)
57969 {
57970- return (__force __be64)__swab64p(p);
57971+ return (__force const __be64)__swab64p(p);
57972 }
57973 static inline __u64 __be64_to_cpup(const __be64 *p)
57974 {
57975- return __swab64p((__u64 *)p);
57976+ return __swab64p((const __u64 *)p);
57977 }
57978 static inline __be32 __cpu_to_be32p(const __u32 *p)
57979 {
57980- return (__force __be32)__swab32p(p);
57981+ return (__force const __be32)__swab32p(p);
57982 }
57983 static inline __u32 __be32_to_cpup(const __be32 *p)
57984 {
57985- return __swab32p((__u32 *)p);
57986+ return __swab32p((const __u32 *)p);
57987 }
57988 static inline __be16 __cpu_to_be16p(const __u16 *p)
57989 {
57990- return (__force __be16)__swab16p(p);
57991+ return (__force const __be16)__swab16p(p);
57992 }
57993 static inline __u16 __be16_to_cpup(const __be16 *p)
57994 {
57995- return __swab16p((__u16 *)p);
57996+ return __swab16p((const __u16 *)p);
57997 }
57998 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
57999 #define __le64_to_cpus(x) do { (void)(x); } while (0)
58000diff -urNp linux-2.6.32.44/include/linux/cache.h linux-2.6.32.44/include/linux/cache.h
58001--- linux-2.6.32.44/include/linux/cache.h 2011-03-27 14:31:47.000000000 -0400
58002+++ linux-2.6.32.44/include/linux/cache.h 2011-04-17 15:56:46.000000000 -0400
58003@@ -16,6 +16,10 @@
58004 #define __read_mostly
58005 #endif
58006
58007+#ifndef __read_only
58008+#define __read_only __read_mostly
58009+#endif
58010+
58011 #ifndef ____cacheline_aligned
58012 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
58013 #endif
58014diff -urNp linux-2.6.32.44/include/linux/capability.h linux-2.6.32.44/include/linux/capability.h
58015--- linux-2.6.32.44/include/linux/capability.h 2011-03-27 14:31:47.000000000 -0400
58016+++ linux-2.6.32.44/include/linux/capability.h 2011-04-17 15:56:46.000000000 -0400
58017@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff
58018 (security_real_capable_noaudit((t), (cap)) == 0)
58019
58020 extern int capable(int cap);
58021+int capable_nolog(int cap);
58022
58023 /* audit system wants to get cap info from files as well */
58024 struct dentry;
58025diff -urNp linux-2.6.32.44/include/linux/compiler-gcc4.h linux-2.6.32.44/include/linux/compiler-gcc4.h
58026--- linux-2.6.32.44/include/linux/compiler-gcc4.h 2011-03-27 14:31:47.000000000 -0400
58027+++ linux-2.6.32.44/include/linux/compiler-gcc4.h 2011-08-05 20:33:55.000000000 -0400
58028@@ -36,4 +36,13 @@
58029 the kernel context */
58030 #define __cold __attribute__((__cold__))
58031
58032+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
58033+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
58034+#define __bos0(ptr) __bos((ptr), 0)
58035+#define __bos1(ptr) __bos((ptr), 1)
58036+
58037+#if __GNUC_MINOR__ >= 5
58038+#define __no_const __attribute__((no_const))
58039+#endif
58040+
58041 #endif
58042diff -urNp linux-2.6.32.44/include/linux/compiler.h linux-2.6.32.44/include/linux/compiler.h
58043--- linux-2.6.32.44/include/linux/compiler.h 2011-03-27 14:31:47.000000000 -0400
58044+++ linux-2.6.32.44/include/linux/compiler.h 2011-08-05 20:33:55.000000000 -0400
58045@@ -247,6 +247,10 @@ void ftrace_likely_update(struct ftrace_
58046 # define __attribute_const__ /* unimplemented */
58047 #endif
58048
58049+#ifndef __no_const
58050+# define __no_const
58051+#endif
58052+
58053 /*
58054 * Tell gcc if a function is cold. The compiler will assume any path
58055 * directly leading to the call is unlikely.
58056@@ -256,6 +260,22 @@ void ftrace_likely_update(struct ftrace_
58057 #define __cold
58058 #endif
58059
58060+#ifndef __alloc_size
58061+#define __alloc_size(...)
58062+#endif
58063+
58064+#ifndef __bos
58065+#define __bos(ptr, arg)
58066+#endif
58067+
58068+#ifndef __bos0
58069+#define __bos0(ptr)
58070+#endif
58071+
58072+#ifndef __bos1
58073+#define __bos1(ptr)
58074+#endif
58075+
58076 /* Simple shorthand for a section definition */
58077 #ifndef __section
58078 # define __section(S) __attribute__ ((__section__(#S)))
58079@@ -278,6 +298,7 @@ void ftrace_likely_update(struct ftrace_
58080 * use is to mediate communication between process-level code and irq/NMI
58081 * handlers, all running on the same CPU.
58082 */
58083-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
58084+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
58085+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
58086
58087 #endif /* __LINUX_COMPILER_H */
58088diff -urNp linux-2.6.32.44/include/linux/crypto.h linux-2.6.32.44/include/linux/crypto.h
58089--- linux-2.6.32.44/include/linux/crypto.h 2011-03-27 14:31:47.000000000 -0400
58090+++ linux-2.6.32.44/include/linux/crypto.h 2011-08-05 20:33:55.000000000 -0400
58091@@ -394,7 +394,7 @@ struct cipher_tfm {
58092 const u8 *key, unsigned int keylen);
58093 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58094 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58095-};
58096+} __no_const;
58097
58098 struct hash_tfm {
58099 int (*init)(struct hash_desc *desc);
58100@@ -415,13 +415,13 @@ struct compress_tfm {
58101 int (*cot_decompress)(struct crypto_tfm *tfm,
58102 const u8 *src, unsigned int slen,
58103 u8 *dst, unsigned int *dlen);
58104-};
58105+} __no_const;
58106
58107 struct rng_tfm {
58108 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
58109 unsigned int dlen);
58110 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
58111-};
58112+} __no_const;
58113
58114 #define crt_ablkcipher crt_u.ablkcipher
58115 #define crt_aead crt_u.aead
58116diff -urNp linux-2.6.32.44/include/linux/cryptohash.h linux-2.6.32.44/include/linux/cryptohash.h
58117--- linux-2.6.32.44/include/linux/cryptohash.h 2011-03-27 14:31:47.000000000 -0400
58118+++ linux-2.6.32.44/include/linux/cryptohash.h 2011-08-07 19:48:09.000000000 -0400
58119@@ -7,6 +7,11 @@
58120 void sha_init(__u32 *buf);
58121 void sha_transform(__u32 *digest, const char *data, __u32 *W);
58122
58123+#define MD5_DIGEST_WORDS 4
58124+#define MD5_MESSAGE_BYTES 64
58125+
58126+void md5_transform(__u32 *hash, __u32 const *in);
58127+
58128 __u32 half_md4_transform(__u32 buf[4], __u32 const in[8]);
58129
58130 #endif
58131diff -urNp linux-2.6.32.44/include/linux/dcache.h linux-2.6.32.44/include/linux/dcache.h
58132--- linux-2.6.32.44/include/linux/dcache.h 2011-03-27 14:31:47.000000000 -0400
58133+++ linux-2.6.32.44/include/linux/dcache.h 2011-04-23 13:34:46.000000000 -0400
58134@@ -119,6 +119,8 @@ struct dentry {
58135 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
58136 };
58137
58138+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
58139+
58140 /*
58141 * dentry->d_lock spinlock nesting subclasses:
58142 *
58143diff -urNp linux-2.6.32.44/include/linux/decompress/mm.h linux-2.6.32.44/include/linux/decompress/mm.h
58144--- linux-2.6.32.44/include/linux/decompress/mm.h 2011-03-27 14:31:47.000000000 -0400
58145+++ linux-2.6.32.44/include/linux/decompress/mm.h 2011-04-17 15:56:46.000000000 -0400
58146@@ -78,7 +78,7 @@ static void free(void *where)
58147 * warnings when not needed (indeed large_malloc / large_free are not
58148 * needed by inflate */
58149
58150-#define malloc(a) kmalloc(a, GFP_KERNEL)
58151+#define malloc(a) kmalloc((a), GFP_KERNEL)
58152 #define free(a) kfree(a)
58153
58154 #define large_malloc(a) vmalloc(a)
58155diff -urNp linux-2.6.32.44/include/linux/dma-mapping.h linux-2.6.32.44/include/linux/dma-mapping.h
58156--- linux-2.6.32.44/include/linux/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
58157+++ linux-2.6.32.44/include/linux/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
58158@@ -16,50 +16,50 @@ enum dma_data_direction {
58159 };
58160
58161 struct dma_map_ops {
58162- void* (*alloc_coherent)(struct device *dev, size_t size,
58163+ void* (* const alloc_coherent)(struct device *dev, size_t size,
58164 dma_addr_t *dma_handle, gfp_t gfp);
58165- void (*free_coherent)(struct device *dev, size_t size,
58166+ void (* const free_coherent)(struct device *dev, size_t size,
58167 void *vaddr, dma_addr_t dma_handle);
58168- dma_addr_t (*map_page)(struct device *dev, struct page *page,
58169+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
58170 unsigned long offset, size_t size,
58171 enum dma_data_direction dir,
58172 struct dma_attrs *attrs);
58173- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
58174+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
58175 size_t size, enum dma_data_direction dir,
58176 struct dma_attrs *attrs);
58177- int (*map_sg)(struct device *dev, struct scatterlist *sg,
58178+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
58179 int nents, enum dma_data_direction dir,
58180 struct dma_attrs *attrs);
58181- void (*unmap_sg)(struct device *dev,
58182+ void (* const unmap_sg)(struct device *dev,
58183 struct scatterlist *sg, int nents,
58184 enum dma_data_direction dir,
58185 struct dma_attrs *attrs);
58186- void (*sync_single_for_cpu)(struct device *dev,
58187+ void (* const sync_single_for_cpu)(struct device *dev,
58188 dma_addr_t dma_handle, size_t size,
58189 enum dma_data_direction dir);
58190- void (*sync_single_for_device)(struct device *dev,
58191+ void (* const sync_single_for_device)(struct device *dev,
58192 dma_addr_t dma_handle, size_t size,
58193 enum dma_data_direction dir);
58194- void (*sync_single_range_for_cpu)(struct device *dev,
58195+ void (* const sync_single_range_for_cpu)(struct device *dev,
58196 dma_addr_t dma_handle,
58197 unsigned long offset,
58198 size_t size,
58199 enum dma_data_direction dir);
58200- void (*sync_single_range_for_device)(struct device *dev,
58201+ void (* const sync_single_range_for_device)(struct device *dev,
58202 dma_addr_t dma_handle,
58203 unsigned long offset,
58204 size_t size,
58205 enum dma_data_direction dir);
58206- void (*sync_sg_for_cpu)(struct device *dev,
58207+ void (* const sync_sg_for_cpu)(struct device *dev,
58208 struct scatterlist *sg, int nents,
58209 enum dma_data_direction dir);
58210- void (*sync_sg_for_device)(struct device *dev,
58211+ void (* const sync_sg_for_device)(struct device *dev,
58212 struct scatterlist *sg, int nents,
58213 enum dma_data_direction dir);
58214- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
58215- int (*dma_supported)(struct device *dev, u64 mask);
58216+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
58217+ int (* const dma_supported)(struct device *dev, u64 mask);
58218 int (*set_dma_mask)(struct device *dev, u64 mask);
58219- int is_phys;
58220+ const int is_phys;
58221 };
58222
58223 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
58224diff -urNp linux-2.6.32.44/include/linux/dst.h linux-2.6.32.44/include/linux/dst.h
58225--- linux-2.6.32.44/include/linux/dst.h 2011-03-27 14:31:47.000000000 -0400
58226+++ linux-2.6.32.44/include/linux/dst.h 2011-04-17 15:56:46.000000000 -0400
58227@@ -380,7 +380,7 @@ struct dst_node
58228 struct thread_pool *pool;
58229
58230 /* Transaction IDs live here */
58231- atomic_long_t gen;
58232+ atomic_long_unchecked_t gen;
58233
58234 /*
58235 * How frequently and how many times transaction
58236diff -urNp linux-2.6.32.44/include/linux/elf.h linux-2.6.32.44/include/linux/elf.h
58237--- linux-2.6.32.44/include/linux/elf.h 2011-03-27 14:31:47.000000000 -0400
58238+++ linux-2.6.32.44/include/linux/elf.h 2011-04-17 15:56:46.000000000 -0400
58239@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
58240 #define PT_GNU_EH_FRAME 0x6474e550
58241
58242 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
58243+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
58244+
58245+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
58246+
58247+/* Constants for the e_flags field */
58248+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
58249+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
58250+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
58251+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
58252+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
58253+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
58254
58255 /* These constants define the different elf file types */
58256 #define ET_NONE 0
58257@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
58258 #define DT_DEBUG 21
58259 #define DT_TEXTREL 22
58260 #define DT_JMPREL 23
58261+#define DT_FLAGS 30
58262+ #define DF_TEXTREL 0x00000004
58263 #define DT_ENCODING 32
58264 #define OLD_DT_LOOS 0x60000000
58265 #define DT_LOOS 0x6000000d
58266@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
58267 #define PF_W 0x2
58268 #define PF_X 0x1
58269
58270+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
58271+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
58272+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
58273+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
58274+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
58275+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
58276+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
58277+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
58278+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
58279+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
58280+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
58281+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
58282+
58283 typedef struct elf32_phdr{
58284 Elf32_Word p_type;
58285 Elf32_Off p_offset;
58286@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
58287 #define EI_OSABI 7
58288 #define EI_PAD 8
58289
58290+#define EI_PAX 14
58291+
58292 #define ELFMAG0 0x7f /* EI_MAG */
58293 #define ELFMAG1 'E'
58294 #define ELFMAG2 'L'
58295@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
58296 #define elf_phdr elf32_phdr
58297 #define elf_note elf32_note
58298 #define elf_addr_t Elf32_Off
58299+#define elf_dyn Elf32_Dyn
58300
58301 #else
58302
58303@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
58304 #define elf_phdr elf64_phdr
58305 #define elf_note elf64_note
58306 #define elf_addr_t Elf64_Off
58307+#define elf_dyn Elf64_Dyn
58308
58309 #endif
58310
58311diff -urNp linux-2.6.32.44/include/linux/fscache-cache.h linux-2.6.32.44/include/linux/fscache-cache.h
58312--- linux-2.6.32.44/include/linux/fscache-cache.h 2011-03-27 14:31:47.000000000 -0400
58313+++ linux-2.6.32.44/include/linux/fscache-cache.h 2011-05-04 17:56:28.000000000 -0400
58314@@ -116,7 +116,7 @@ struct fscache_operation {
58315 #endif
58316 };
58317
58318-extern atomic_t fscache_op_debug_id;
58319+extern atomic_unchecked_t fscache_op_debug_id;
58320 extern const struct slow_work_ops fscache_op_slow_work_ops;
58321
58322 extern void fscache_enqueue_operation(struct fscache_operation *);
58323@@ -134,7 +134,7 @@ static inline void fscache_operation_ini
58324 fscache_operation_release_t release)
58325 {
58326 atomic_set(&op->usage, 1);
58327- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58328+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58329 op->release = release;
58330 INIT_LIST_HEAD(&op->pend_link);
58331 fscache_set_op_state(op, "Init");
58332diff -urNp linux-2.6.32.44/include/linux/fs.h linux-2.6.32.44/include/linux/fs.h
58333--- linux-2.6.32.44/include/linux/fs.h 2011-07-13 17:23:04.000000000 -0400
58334+++ linux-2.6.32.44/include/linux/fs.h 2011-08-05 20:33:55.000000000 -0400
58335@@ -90,6 +90,11 @@ struct inodes_stat_t {
58336 /* Expect random access pattern */
58337 #define FMODE_RANDOM ((__force fmode_t)4096)
58338
58339+/* Hack for grsec so as not to require read permission simply to execute
58340+ * a binary
58341+ */
58342+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
58343+
58344 /*
58345 * The below are the various read and write types that we support. Some of
58346 * them include behavioral modifiers that send information down to the
58347@@ -568,41 +573,41 @@ typedef int (*read_actor_t)(read_descrip
58348 unsigned long, unsigned long);
58349
58350 struct address_space_operations {
58351- int (*writepage)(struct page *page, struct writeback_control *wbc);
58352- int (*readpage)(struct file *, struct page *);
58353- void (*sync_page)(struct page *);
58354+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
58355+ int (* const readpage)(struct file *, struct page *);
58356+ void (* const sync_page)(struct page *);
58357
58358 /* Write back some dirty pages from this mapping. */
58359- int (*writepages)(struct address_space *, struct writeback_control *);
58360+ int (* const writepages)(struct address_space *, struct writeback_control *);
58361
58362 /* Set a page dirty. Return true if this dirtied it */
58363- int (*set_page_dirty)(struct page *page);
58364+ int (* const set_page_dirty)(struct page *page);
58365
58366- int (*readpages)(struct file *filp, struct address_space *mapping,
58367+ int (* const readpages)(struct file *filp, struct address_space *mapping,
58368 struct list_head *pages, unsigned nr_pages);
58369
58370- int (*write_begin)(struct file *, struct address_space *mapping,
58371+ int (* const write_begin)(struct file *, struct address_space *mapping,
58372 loff_t pos, unsigned len, unsigned flags,
58373 struct page **pagep, void **fsdata);
58374- int (*write_end)(struct file *, struct address_space *mapping,
58375+ int (* const write_end)(struct file *, struct address_space *mapping,
58376 loff_t pos, unsigned len, unsigned copied,
58377 struct page *page, void *fsdata);
58378
58379 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
58380- sector_t (*bmap)(struct address_space *, sector_t);
58381- void (*invalidatepage) (struct page *, unsigned long);
58382- int (*releasepage) (struct page *, gfp_t);
58383- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
58384+ sector_t (* const bmap)(struct address_space *, sector_t);
58385+ void (* const invalidatepage) (struct page *, unsigned long);
58386+ int (* const releasepage) (struct page *, gfp_t);
58387+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
58388 loff_t offset, unsigned long nr_segs);
58389- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
58390+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
58391 void **, unsigned long *);
58392 /* migrate the contents of a page to the specified target */
58393- int (*migratepage) (struct address_space *,
58394+ int (* const migratepage) (struct address_space *,
58395 struct page *, struct page *);
58396- int (*launder_page) (struct page *);
58397- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
58398+ int (* const launder_page) (struct page *);
58399+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
58400 unsigned long);
58401- int (*error_remove_page)(struct address_space *, struct page *);
58402+ int (* const error_remove_page)(struct address_space *, struct page *);
58403 };
58404
58405 /*
58406@@ -1031,19 +1036,19 @@ static inline int file_check_writeable(s
58407 typedef struct files_struct *fl_owner_t;
58408
58409 struct file_lock_operations {
58410- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
58411- void (*fl_release_private)(struct file_lock *);
58412+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
58413+ void (* const fl_release_private)(struct file_lock *);
58414 };
58415
58416 struct lock_manager_operations {
58417- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
58418- void (*fl_notify)(struct file_lock *); /* unblock callback */
58419- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
58420- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
58421- void (*fl_release_private)(struct file_lock *);
58422- void (*fl_break)(struct file_lock *);
58423- int (*fl_mylease)(struct file_lock *, struct file_lock *);
58424- int (*fl_change)(struct file_lock **, int);
58425+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
58426+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
58427+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
58428+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
58429+ void (* const fl_release_private)(struct file_lock *);
58430+ void (* const fl_break)(struct file_lock *);
58431+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
58432+ int (* const fl_change)(struct file_lock **, int);
58433 };
58434
58435 struct lock_manager {
58436@@ -1442,7 +1447,7 @@ struct fiemap_extent_info {
58437 unsigned int fi_flags; /* Flags as passed from user */
58438 unsigned int fi_extents_mapped; /* Number of mapped extents */
58439 unsigned int fi_extents_max; /* Size of fiemap_extent array */
58440- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
58441+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
58442 * array */
58443 };
58444 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
58445@@ -1486,7 +1491,7 @@ struct block_device_operations;
58446 * can be called without the big kernel lock held in all filesystems.
58447 */
58448 struct file_operations {
58449- struct module *owner;
58450+ struct module * const owner;
58451 loff_t (*llseek) (struct file *, loff_t, int);
58452 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
58453 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
58454@@ -1559,30 +1564,30 @@ extern ssize_t vfs_writev(struct file *,
58455 unsigned long, loff_t *);
58456
58457 struct super_operations {
58458- struct inode *(*alloc_inode)(struct super_block *sb);
58459- void (*destroy_inode)(struct inode *);
58460+ struct inode *(* const alloc_inode)(struct super_block *sb);
58461+ void (* const destroy_inode)(struct inode *);
58462
58463- void (*dirty_inode) (struct inode *);
58464- int (*write_inode) (struct inode *, int);
58465- void (*drop_inode) (struct inode *);
58466- void (*delete_inode) (struct inode *);
58467- void (*put_super) (struct super_block *);
58468- void (*write_super) (struct super_block *);
58469- int (*sync_fs)(struct super_block *sb, int wait);
58470- int (*freeze_fs) (struct super_block *);
58471- int (*unfreeze_fs) (struct super_block *);
58472- int (*statfs) (struct dentry *, struct kstatfs *);
58473- int (*remount_fs) (struct super_block *, int *, char *);
58474- void (*clear_inode) (struct inode *);
58475- void (*umount_begin) (struct super_block *);
58476+ void (* const dirty_inode) (struct inode *);
58477+ int (* const write_inode) (struct inode *, int);
58478+ void (* const drop_inode) (struct inode *);
58479+ void (* const delete_inode) (struct inode *);
58480+ void (* const put_super) (struct super_block *);
58481+ void (* const write_super) (struct super_block *);
58482+ int (* const sync_fs)(struct super_block *sb, int wait);
58483+ int (* const freeze_fs) (struct super_block *);
58484+ int (* const unfreeze_fs) (struct super_block *);
58485+ int (* const statfs) (struct dentry *, struct kstatfs *);
58486+ int (* const remount_fs) (struct super_block *, int *, char *);
58487+ void (* const clear_inode) (struct inode *);
58488+ void (* const umount_begin) (struct super_block *);
58489
58490- int (*show_options)(struct seq_file *, struct vfsmount *);
58491- int (*show_stats)(struct seq_file *, struct vfsmount *);
58492+ int (* const show_options)(struct seq_file *, struct vfsmount *);
58493+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
58494 #ifdef CONFIG_QUOTA
58495- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
58496- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
58497+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
58498+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
58499 #endif
58500- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
58501+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
58502 };
58503
58504 /*
58505diff -urNp linux-2.6.32.44/include/linux/fs_struct.h linux-2.6.32.44/include/linux/fs_struct.h
58506--- linux-2.6.32.44/include/linux/fs_struct.h 2011-03-27 14:31:47.000000000 -0400
58507+++ linux-2.6.32.44/include/linux/fs_struct.h 2011-04-17 15:56:46.000000000 -0400
58508@@ -4,7 +4,7 @@
58509 #include <linux/path.h>
58510
58511 struct fs_struct {
58512- int users;
58513+ atomic_t users;
58514 rwlock_t lock;
58515 int umask;
58516 int in_exec;
58517diff -urNp linux-2.6.32.44/include/linux/ftrace_event.h linux-2.6.32.44/include/linux/ftrace_event.h
58518--- linux-2.6.32.44/include/linux/ftrace_event.h 2011-03-27 14:31:47.000000000 -0400
58519+++ linux-2.6.32.44/include/linux/ftrace_event.h 2011-05-04 17:56:28.000000000 -0400
58520@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftr
58521 int filter_type);
58522 extern int trace_define_common_fields(struct ftrace_event_call *call);
58523
58524-#define is_signed_type(type) (((type)(-1)) < 0)
58525+#define is_signed_type(type) (((type)(-1)) < (type)1)
58526
58527 int trace_set_clr_event(const char *system, const char *event, int set);
58528
58529diff -urNp linux-2.6.32.44/include/linux/genhd.h linux-2.6.32.44/include/linux/genhd.h
58530--- linux-2.6.32.44/include/linux/genhd.h 2011-03-27 14:31:47.000000000 -0400
58531+++ linux-2.6.32.44/include/linux/genhd.h 2011-04-17 15:56:46.000000000 -0400
58532@@ -161,7 +161,7 @@ struct gendisk {
58533
58534 struct timer_rand_state *random;
58535
58536- atomic_t sync_io; /* RAID */
58537+ atomic_unchecked_t sync_io; /* RAID */
58538 struct work_struct async_notify;
58539 #ifdef CONFIG_BLK_DEV_INTEGRITY
58540 struct blk_integrity *integrity;
58541diff -urNp linux-2.6.32.44/include/linux/gracl.h linux-2.6.32.44/include/linux/gracl.h
58542--- linux-2.6.32.44/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
58543+++ linux-2.6.32.44/include/linux/gracl.h 2011-04-17 15:56:46.000000000 -0400
58544@@ -0,0 +1,317 @@
58545+#ifndef GR_ACL_H
58546+#define GR_ACL_H
58547+
58548+#include <linux/grdefs.h>
58549+#include <linux/resource.h>
58550+#include <linux/capability.h>
58551+#include <linux/dcache.h>
58552+#include <asm/resource.h>
58553+
58554+/* Major status information */
58555+
58556+#define GR_VERSION "grsecurity 2.2.2"
58557+#define GRSECURITY_VERSION 0x2202
58558+
58559+enum {
58560+ GR_SHUTDOWN = 0,
58561+ GR_ENABLE = 1,
58562+ GR_SPROLE = 2,
58563+ GR_RELOAD = 3,
58564+ GR_SEGVMOD = 4,
58565+ GR_STATUS = 5,
58566+ GR_UNSPROLE = 6,
58567+ GR_PASSSET = 7,
58568+ GR_SPROLEPAM = 8,
58569+};
58570+
58571+/* Password setup definitions
58572+ * kernel/grhash.c */
58573+enum {
58574+ GR_PW_LEN = 128,
58575+ GR_SALT_LEN = 16,
58576+ GR_SHA_LEN = 32,
58577+};
58578+
58579+enum {
58580+ GR_SPROLE_LEN = 64,
58581+};
58582+
58583+enum {
58584+ GR_NO_GLOB = 0,
58585+ GR_REG_GLOB,
58586+ GR_CREATE_GLOB
58587+};
58588+
58589+#define GR_NLIMITS 32
58590+
58591+/* Begin Data Structures */
58592+
58593+struct sprole_pw {
58594+ unsigned char *rolename;
58595+ unsigned char salt[GR_SALT_LEN];
58596+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
58597+};
58598+
58599+struct name_entry {
58600+ __u32 key;
58601+ ino_t inode;
58602+ dev_t device;
58603+ char *name;
58604+ __u16 len;
58605+ __u8 deleted;
58606+ struct name_entry *prev;
58607+ struct name_entry *next;
58608+};
58609+
58610+struct inodev_entry {
58611+ struct name_entry *nentry;
58612+ struct inodev_entry *prev;
58613+ struct inodev_entry *next;
58614+};
58615+
58616+struct acl_role_db {
58617+ struct acl_role_label **r_hash;
58618+ __u32 r_size;
58619+};
58620+
58621+struct inodev_db {
58622+ struct inodev_entry **i_hash;
58623+ __u32 i_size;
58624+};
58625+
58626+struct name_db {
58627+ struct name_entry **n_hash;
58628+ __u32 n_size;
58629+};
58630+
58631+struct crash_uid {
58632+ uid_t uid;
58633+ unsigned long expires;
58634+};
58635+
58636+struct gr_hash_struct {
58637+ void **table;
58638+ void **nametable;
58639+ void *first;
58640+ __u32 table_size;
58641+ __u32 used_size;
58642+ int type;
58643+};
58644+
58645+/* Userspace Grsecurity ACL data structures */
58646+
58647+struct acl_subject_label {
58648+ char *filename;
58649+ ino_t inode;
58650+ dev_t device;
58651+ __u32 mode;
58652+ kernel_cap_t cap_mask;
58653+ kernel_cap_t cap_lower;
58654+ kernel_cap_t cap_invert_audit;
58655+
58656+ struct rlimit res[GR_NLIMITS];
58657+ __u32 resmask;
58658+
58659+ __u8 user_trans_type;
58660+ __u8 group_trans_type;
58661+ uid_t *user_transitions;
58662+ gid_t *group_transitions;
58663+ __u16 user_trans_num;
58664+ __u16 group_trans_num;
58665+
58666+ __u32 sock_families[2];
58667+ __u32 ip_proto[8];
58668+ __u32 ip_type;
58669+ struct acl_ip_label **ips;
58670+ __u32 ip_num;
58671+ __u32 inaddr_any_override;
58672+
58673+ __u32 crashes;
58674+ unsigned long expires;
58675+
58676+ struct acl_subject_label *parent_subject;
58677+ struct gr_hash_struct *hash;
58678+ struct acl_subject_label *prev;
58679+ struct acl_subject_label *next;
58680+
58681+ struct acl_object_label **obj_hash;
58682+ __u32 obj_hash_size;
58683+ __u16 pax_flags;
58684+};
58685+
58686+struct role_allowed_ip {
58687+ __u32 addr;
58688+ __u32 netmask;
58689+
58690+ struct role_allowed_ip *prev;
58691+ struct role_allowed_ip *next;
58692+};
58693+
58694+struct role_transition {
58695+ char *rolename;
58696+
58697+ struct role_transition *prev;
58698+ struct role_transition *next;
58699+};
58700+
58701+struct acl_role_label {
58702+ char *rolename;
58703+ uid_t uidgid;
58704+ __u16 roletype;
58705+
58706+ __u16 auth_attempts;
58707+ unsigned long expires;
58708+
58709+ struct acl_subject_label *root_label;
58710+ struct gr_hash_struct *hash;
58711+
58712+ struct acl_role_label *prev;
58713+ struct acl_role_label *next;
58714+
58715+ struct role_transition *transitions;
58716+ struct role_allowed_ip *allowed_ips;
58717+ uid_t *domain_children;
58718+ __u16 domain_child_num;
58719+
58720+ struct acl_subject_label **subj_hash;
58721+ __u32 subj_hash_size;
58722+};
58723+
58724+struct user_acl_role_db {
58725+ struct acl_role_label **r_table;
58726+ __u32 num_pointers; /* Number of allocations to track */
58727+ __u32 num_roles; /* Number of roles */
58728+ __u32 num_domain_children; /* Number of domain children */
58729+ __u32 num_subjects; /* Number of subjects */
58730+ __u32 num_objects; /* Number of objects */
58731+};
58732+
58733+struct acl_object_label {
58734+ char *filename;
58735+ ino_t inode;
58736+ dev_t device;
58737+ __u32 mode;
58738+
58739+ struct acl_subject_label *nested;
58740+ struct acl_object_label *globbed;
58741+
58742+ /* next two structures not used */
58743+
58744+ struct acl_object_label *prev;
58745+ struct acl_object_label *next;
58746+};
58747+
58748+struct acl_ip_label {
58749+ char *iface;
58750+ __u32 addr;
58751+ __u32 netmask;
58752+ __u16 low, high;
58753+ __u8 mode;
58754+ __u32 type;
58755+ __u32 proto[8];
58756+
58757+ /* next two structures not used */
58758+
58759+ struct acl_ip_label *prev;
58760+ struct acl_ip_label *next;
58761+};
58762+
58763+struct gr_arg {
58764+ struct user_acl_role_db role_db;
58765+ unsigned char pw[GR_PW_LEN];
58766+ unsigned char salt[GR_SALT_LEN];
58767+ unsigned char sum[GR_SHA_LEN];
58768+ unsigned char sp_role[GR_SPROLE_LEN];
58769+ struct sprole_pw *sprole_pws;
58770+ dev_t segv_device;
58771+ ino_t segv_inode;
58772+ uid_t segv_uid;
58773+ __u16 num_sprole_pws;
58774+ __u16 mode;
58775+};
58776+
58777+struct gr_arg_wrapper {
58778+ struct gr_arg *arg;
58779+ __u32 version;
58780+ __u32 size;
58781+};
58782+
58783+struct subject_map {
58784+ struct acl_subject_label *user;
58785+ struct acl_subject_label *kernel;
58786+ struct subject_map *prev;
58787+ struct subject_map *next;
58788+};
58789+
58790+struct acl_subj_map_db {
58791+ struct subject_map **s_hash;
58792+ __u32 s_size;
58793+};
58794+
58795+/* End Data Structures Section */
58796+
58797+/* Hash functions generated by empirical testing by Brad Spengler
58798+ Makes good use of the low bits of the inode. Generally 0-1 times
58799+ in loop for successful match. 0-3 for unsuccessful match.
58800+ Shift/add algorithm with modulus of table size and an XOR*/
58801+
58802+static __inline__ unsigned int
58803+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
58804+{
58805+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
58806+}
58807+
58808+ static __inline__ unsigned int
58809+shash(const struct acl_subject_label *userp, const unsigned int sz)
58810+{
58811+ return ((const unsigned long)userp % sz);
58812+}
58813+
58814+static __inline__ unsigned int
58815+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
58816+{
58817+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
58818+}
58819+
58820+static __inline__ unsigned int
58821+nhash(const char *name, const __u16 len, const unsigned int sz)
58822+{
58823+ return full_name_hash((const unsigned char *)name, len) % sz;
58824+}
58825+
58826+#define FOR_EACH_ROLE_START(role) \
58827+ role = role_list; \
58828+ while (role) {
58829+
58830+#define FOR_EACH_ROLE_END(role) \
58831+ role = role->prev; \
58832+ }
58833+
58834+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
58835+ subj = NULL; \
58836+ iter = 0; \
58837+ while (iter < role->subj_hash_size) { \
58838+ if (subj == NULL) \
58839+ subj = role->subj_hash[iter]; \
58840+ if (subj == NULL) { \
58841+ iter++; \
58842+ continue; \
58843+ }
58844+
58845+#define FOR_EACH_SUBJECT_END(subj,iter) \
58846+ subj = subj->next; \
58847+ if (subj == NULL) \
58848+ iter++; \
58849+ }
58850+
58851+
58852+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
58853+ subj = role->hash->first; \
58854+ while (subj != NULL) {
58855+
58856+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
58857+ subj = subj->next; \
58858+ }
58859+
58860+#endif
58861+
58862diff -urNp linux-2.6.32.44/include/linux/gralloc.h linux-2.6.32.44/include/linux/gralloc.h
58863--- linux-2.6.32.44/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
58864+++ linux-2.6.32.44/include/linux/gralloc.h 2011-04-17 15:56:46.000000000 -0400
58865@@ -0,0 +1,9 @@
58866+#ifndef __GRALLOC_H
58867+#define __GRALLOC_H
58868+
58869+void acl_free_all(void);
58870+int acl_alloc_stack_init(unsigned long size);
58871+void *acl_alloc(unsigned long len);
58872+void *acl_alloc_num(unsigned long num, unsigned long len);
58873+
58874+#endif
58875diff -urNp linux-2.6.32.44/include/linux/grdefs.h linux-2.6.32.44/include/linux/grdefs.h
58876--- linux-2.6.32.44/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
58877+++ linux-2.6.32.44/include/linux/grdefs.h 2011-06-11 16:20:26.000000000 -0400
58878@@ -0,0 +1,140 @@
58879+#ifndef GRDEFS_H
58880+#define GRDEFS_H
58881+
58882+/* Begin grsecurity status declarations */
58883+
58884+enum {
58885+ GR_READY = 0x01,
58886+ GR_STATUS_INIT = 0x00 // disabled state
58887+};
58888+
58889+/* Begin ACL declarations */
58890+
58891+/* Role flags */
58892+
58893+enum {
58894+ GR_ROLE_USER = 0x0001,
58895+ GR_ROLE_GROUP = 0x0002,
58896+ GR_ROLE_DEFAULT = 0x0004,
58897+ GR_ROLE_SPECIAL = 0x0008,
58898+ GR_ROLE_AUTH = 0x0010,
58899+ GR_ROLE_NOPW = 0x0020,
58900+ GR_ROLE_GOD = 0x0040,
58901+ GR_ROLE_LEARN = 0x0080,
58902+ GR_ROLE_TPE = 0x0100,
58903+ GR_ROLE_DOMAIN = 0x0200,
58904+ GR_ROLE_PAM = 0x0400,
58905+ GR_ROLE_PERSIST = 0x800
58906+};
58907+
58908+/* ACL Subject and Object mode flags */
58909+enum {
58910+ GR_DELETED = 0x80000000
58911+};
58912+
58913+/* ACL Object-only mode flags */
58914+enum {
58915+ GR_READ = 0x00000001,
58916+ GR_APPEND = 0x00000002,
58917+ GR_WRITE = 0x00000004,
58918+ GR_EXEC = 0x00000008,
58919+ GR_FIND = 0x00000010,
58920+ GR_INHERIT = 0x00000020,
58921+ GR_SETID = 0x00000040,
58922+ GR_CREATE = 0x00000080,
58923+ GR_DELETE = 0x00000100,
58924+ GR_LINK = 0x00000200,
58925+ GR_AUDIT_READ = 0x00000400,
58926+ GR_AUDIT_APPEND = 0x00000800,
58927+ GR_AUDIT_WRITE = 0x00001000,
58928+ GR_AUDIT_EXEC = 0x00002000,
58929+ GR_AUDIT_FIND = 0x00004000,
58930+ GR_AUDIT_INHERIT= 0x00008000,
58931+ GR_AUDIT_SETID = 0x00010000,
58932+ GR_AUDIT_CREATE = 0x00020000,
58933+ GR_AUDIT_DELETE = 0x00040000,
58934+ GR_AUDIT_LINK = 0x00080000,
58935+ GR_PTRACERD = 0x00100000,
58936+ GR_NOPTRACE = 0x00200000,
58937+ GR_SUPPRESS = 0x00400000,
58938+ GR_NOLEARN = 0x00800000,
58939+ GR_INIT_TRANSFER= 0x01000000
58940+};
58941+
58942+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
58943+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
58944+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
58945+
58946+/* ACL subject-only mode flags */
58947+enum {
58948+ GR_KILL = 0x00000001,
58949+ GR_VIEW = 0x00000002,
58950+ GR_PROTECTED = 0x00000004,
58951+ GR_LEARN = 0x00000008,
58952+ GR_OVERRIDE = 0x00000010,
58953+ /* just a placeholder, this mode is only used in userspace */
58954+ GR_DUMMY = 0x00000020,
58955+ GR_PROTSHM = 0x00000040,
58956+ GR_KILLPROC = 0x00000080,
58957+ GR_KILLIPPROC = 0x00000100,
58958+ /* just a placeholder, this mode is only used in userspace */
58959+ GR_NOTROJAN = 0x00000200,
58960+ GR_PROTPROCFD = 0x00000400,
58961+ GR_PROCACCT = 0x00000800,
58962+ GR_RELAXPTRACE = 0x00001000,
58963+ GR_NESTED = 0x00002000,
58964+ GR_INHERITLEARN = 0x00004000,
58965+ GR_PROCFIND = 0x00008000,
58966+ GR_POVERRIDE = 0x00010000,
58967+ GR_KERNELAUTH = 0x00020000,
58968+ GR_ATSECURE = 0x00040000,
58969+ GR_SHMEXEC = 0x00080000
58970+};
58971+
58972+enum {
58973+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
58974+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
58975+ GR_PAX_ENABLE_MPROTECT = 0x0004,
58976+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
58977+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
58978+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
58979+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
58980+ GR_PAX_DISABLE_MPROTECT = 0x0400,
58981+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
58982+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
58983+};
58984+
58985+enum {
58986+ GR_ID_USER = 0x01,
58987+ GR_ID_GROUP = 0x02,
58988+};
58989+
58990+enum {
58991+ GR_ID_ALLOW = 0x01,
58992+ GR_ID_DENY = 0x02,
58993+};
58994+
58995+#define GR_CRASH_RES 31
58996+#define GR_UIDTABLE_MAX 500
58997+
58998+/* begin resource learning section */
58999+enum {
59000+ GR_RLIM_CPU_BUMP = 60,
59001+ GR_RLIM_FSIZE_BUMP = 50000,
59002+ GR_RLIM_DATA_BUMP = 10000,
59003+ GR_RLIM_STACK_BUMP = 1000,
59004+ GR_RLIM_CORE_BUMP = 10000,
59005+ GR_RLIM_RSS_BUMP = 500000,
59006+ GR_RLIM_NPROC_BUMP = 1,
59007+ GR_RLIM_NOFILE_BUMP = 5,
59008+ GR_RLIM_MEMLOCK_BUMP = 50000,
59009+ GR_RLIM_AS_BUMP = 500000,
59010+ GR_RLIM_LOCKS_BUMP = 2,
59011+ GR_RLIM_SIGPENDING_BUMP = 5,
59012+ GR_RLIM_MSGQUEUE_BUMP = 10000,
59013+ GR_RLIM_NICE_BUMP = 1,
59014+ GR_RLIM_RTPRIO_BUMP = 1,
59015+ GR_RLIM_RTTIME_BUMP = 1000000
59016+};
59017+
59018+#endif
59019diff -urNp linux-2.6.32.44/include/linux/grinternal.h linux-2.6.32.44/include/linux/grinternal.h
59020--- linux-2.6.32.44/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
59021+++ linux-2.6.32.44/include/linux/grinternal.h 2011-08-11 19:58:37.000000000 -0400
59022@@ -0,0 +1,217 @@
59023+#ifndef __GRINTERNAL_H
59024+#define __GRINTERNAL_H
59025+
59026+#ifdef CONFIG_GRKERNSEC
59027+
59028+#include <linux/fs.h>
59029+#include <linux/mnt_namespace.h>
59030+#include <linux/nsproxy.h>
59031+#include <linux/gracl.h>
59032+#include <linux/grdefs.h>
59033+#include <linux/grmsg.h>
59034+
59035+void gr_add_learn_entry(const char *fmt, ...)
59036+ __attribute__ ((format (printf, 1, 2)));
59037+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
59038+ const struct vfsmount *mnt);
59039+__u32 gr_check_create(const struct dentry *new_dentry,
59040+ const struct dentry *parent,
59041+ const struct vfsmount *mnt, const __u32 mode);
59042+int gr_check_protected_task(const struct task_struct *task);
59043+__u32 to_gr_audit(const __u32 reqmode);
59044+int gr_set_acls(const int type);
59045+int gr_apply_subject_to_task(struct task_struct *task);
59046+int gr_acl_is_enabled(void);
59047+char gr_roletype_to_char(void);
59048+
59049+void gr_handle_alertkill(struct task_struct *task);
59050+char *gr_to_filename(const struct dentry *dentry,
59051+ const struct vfsmount *mnt);
59052+char *gr_to_filename1(const struct dentry *dentry,
59053+ const struct vfsmount *mnt);
59054+char *gr_to_filename2(const struct dentry *dentry,
59055+ const struct vfsmount *mnt);
59056+char *gr_to_filename3(const struct dentry *dentry,
59057+ const struct vfsmount *mnt);
59058+
59059+extern int grsec_enable_harden_ptrace;
59060+extern int grsec_enable_link;
59061+extern int grsec_enable_fifo;
59062+extern int grsec_enable_shm;
59063+extern int grsec_enable_execlog;
59064+extern int grsec_enable_signal;
59065+extern int grsec_enable_audit_ptrace;
59066+extern int grsec_enable_forkfail;
59067+extern int grsec_enable_time;
59068+extern int grsec_enable_rofs;
59069+extern int grsec_enable_chroot_shmat;
59070+extern int grsec_enable_chroot_mount;
59071+extern int grsec_enable_chroot_double;
59072+extern int grsec_enable_chroot_pivot;
59073+extern int grsec_enable_chroot_chdir;
59074+extern int grsec_enable_chroot_chmod;
59075+extern int grsec_enable_chroot_mknod;
59076+extern int grsec_enable_chroot_fchdir;
59077+extern int grsec_enable_chroot_nice;
59078+extern int grsec_enable_chroot_execlog;
59079+extern int grsec_enable_chroot_caps;
59080+extern int grsec_enable_chroot_sysctl;
59081+extern int grsec_enable_chroot_unix;
59082+extern int grsec_enable_tpe;
59083+extern int grsec_tpe_gid;
59084+extern int grsec_enable_tpe_all;
59085+extern int grsec_enable_tpe_invert;
59086+extern int grsec_enable_socket_all;
59087+extern int grsec_socket_all_gid;
59088+extern int grsec_enable_socket_client;
59089+extern int grsec_socket_client_gid;
59090+extern int grsec_enable_socket_server;
59091+extern int grsec_socket_server_gid;
59092+extern int grsec_audit_gid;
59093+extern int grsec_enable_group;
59094+extern int grsec_enable_audit_textrel;
59095+extern int grsec_enable_log_rwxmaps;
59096+extern int grsec_enable_mount;
59097+extern int grsec_enable_chdir;
59098+extern int grsec_resource_logging;
59099+extern int grsec_enable_blackhole;
59100+extern int grsec_lastack_retries;
59101+extern int grsec_enable_brute;
59102+extern int grsec_lock;
59103+
59104+extern spinlock_t grsec_alert_lock;
59105+extern unsigned long grsec_alert_wtime;
59106+extern unsigned long grsec_alert_fyet;
59107+
59108+extern spinlock_t grsec_audit_lock;
59109+
59110+extern rwlock_t grsec_exec_file_lock;
59111+
59112+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
59113+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
59114+ (tsk)->exec_file->f_vfsmnt) : "/")
59115+
59116+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
59117+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
59118+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
59119+
59120+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
59121+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
59122+ (tsk)->exec_file->f_vfsmnt) : "/")
59123+
59124+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
59125+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
59126+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
59127+
59128+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
59129+
59130+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
59131+
59132+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
59133+ (task)->pid, (cred)->uid, \
59134+ (cred)->euid, (cred)->gid, (cred)->egid, \
59135+ gr_parent_task_fullpath(task), \
59136+ (task)->real_parent->comm, (task)->real_parent->pid, \
59137+ (pcred)->uid, (pcred)->euid, \
59138+ (pcred)->gid, (pcred)->egid
59139+
59140+#define GR_CHROOT_CAPS {{ \
59141+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
59142+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
59143+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
59144+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
59145+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
59146+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
59147+
59148+#define security_learn(normal_msg,args...) \
59149+({ \
59150+ read_lock(&grsec_exec_file_lock); \
59151+ gr_add_learn_entry(normal_msg "\n", ## args); \
59152+ read_unlock(&grsec_exec_file_lock); \
59153+})
59154+
59155+enum {
59156+ GR_DO_AUDIT,
59157+ GR_DONT_AUDIT,
59158+ GR_DONT_AUDIT_GOOD
59159+};
59160+
59161+enum {
59162+ GR_TTYSNIFF,
59163+ GR_RBAC,
59164+ GR_RBAC_STR,
59165+ GR_STR_RBAC,
59166+ GR_RBAC_MODE2,
59167+ GR_RBAC_MODE3,
59168+ GR_FILENAME,
59169+ GR_SYSCTL_HIDDEN,
59170+ GR_NOARGS,
59171+ GR_ONE_INT,
59172+ GR_ONE_INT_TWO_STR,
59173+ GR_ONE_STR,
59174+ GR_STR_INT,
59175+ GR_TWO_STR_INT,
59176+ GR_TWO_INT,
59177+ GR_TWO_U64,
59178+ GR_THREE_INT,
59179+ GR_FIVE_INT_TWO_STR,
59180+ GR_TWO_STR,
59181+ GR_THREE_STR,
59182+ GR_FOUR_STR,
59183+ GR_STR_FILENAME,
59184+ GR_FILENAME_STR,
59185+ GR_FILENAME_TWO_INT,
59186+ GR_FILENAME_TWO_INT_STR,
59187+ GR_TEXTREL,
59188+ GR_PTRACE,
59189+ GR_RESOURCE,
59190+ GR_CAP,
59191+ GR_SIG,
59192+ GR_SIG2,
59193+ GR_CRASH1,
59194+ GR_CRASH2,
59195+ GR_PSACCT,
59196+ GR_RWXMAP
59197+};
59198+
59199+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
59200+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
59201+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
59202+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
59203+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
59204+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
59205+#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)
59206+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
59207+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
59208+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
59209+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
59210+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
59211+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
59212+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
59213+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
59214+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
59215+#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)
59216+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
59217+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
59218+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
59219+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
59220+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
59221+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
59222+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
59223+#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)
59224+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
59225+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
59226+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
59227+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
59228+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
59229+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
59230+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
59231+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
59232+#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)
59233+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
59234+
59235+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
59236+
59237+#endif
59238+
59239+#endif
59240diff -urNp linux-2.6.32.44/include/linux/grmsg.h linux-2.6.32.44/include/linux/grmsg.h
59241--- linux-2.6.32.44/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
59242+++ linux-2.6.32.44/include/linux/grmsg.h 2011-04-17 15:56:46.000000000 -0400
59243@@ -0,0 +1,108 @@
59244+#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"
59245+#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"
59246+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
59247+#define GR_STOPMOD_MSG "denied modification of module state by "
59248+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
59249+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
59250+#define GR_IOPERM_MSG "denied use of ioperm() by "
59251+#define GR_IOPL_MSG "denied use of iopl() by "
59252+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
59253+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
59254+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
59255+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
59256+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
59257+#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"
59258+#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"
59259+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
59260+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
59261+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
59262+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
59263+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
59264+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
59265+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
59266+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
59267+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
59268+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
59269+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
59270+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
59271+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
59272+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
59273+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
59274+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
59275+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
59276+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
59277+#define GR_NPROC_MSG "denied overstep of process limit by "
59278+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
59279+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
59280+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
59281+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
59282+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
59283+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
59284+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
59285+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
59286+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
59287+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
59288+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
59289+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
59290+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
59291+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
59292+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
59293+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
59294+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
59295+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
59296+#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"
59297+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
59298+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
59299+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
59300+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
59301+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
59302+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
59303+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
59304+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
59305+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
59306+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
59307+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
59308+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
59309+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
59310+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
59311+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
59312+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
59313+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
59314+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
59315+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
59316+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
59317+#define GR_FAILFORK_MSG "failed fork with errno %s by "
59318+#define GR_NICE_CHROOT_MSG "denied priority change by "
59319+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
59320+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
59321+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
59322+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
59323+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
59324+#define GR_TIME_MSG "time set by "
59325+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
59326+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
59327+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
59328+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
59329+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
59330+#define GR_BIND_MSG "denied bind() by "
59331+#define GR_CONNECT_MSG "denied connect() by "
59332+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
59333+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
59334+#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"
59335+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
59336+#define GR_CAP_ACL_MSG "use of %s denied for "
59337+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
59338+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
59339+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
59340+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
59341+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
59342+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
59343+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
59344+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
59345+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
59346+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
59347+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
59348+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
59349+#define GR_VM86_MSG "denied use of vm86 by "
59350+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
59351+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
59352diff -urNp linux-2.6.32.44/include/linux/grsecurity.h linux-2.6.32.44/include/linux/grsecurity.h
59353--- linux-2.6.32.44/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
59354+++ linux-2.6.32.44/include/linux/grsecurity.h 2011-08-11 19:58:57.000000000 -0400
59355@@ -0,0 +1,217 @@
59356+#ifndef GR_SECURITY_H
59357+#define GR_SECURITY_H
59358+#include <linux/fs.h>
59359+#include <linux/fs_struct.h>
59360+#include <linux/binfmts.h>
59361+#include <linux/gracl.h>
59362+#include <linux/compat.h>
59363+
59364+/* notify of brain-dead configs */
59365+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59366+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
59367+#endif
59368+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
59369+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
59370+#endif
59371+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
59372+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
59373+#endif
59374+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
59375+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
59376+#endif
59377+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
59378+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
59379+#endif
59380+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
59381+#error "CONFIG_PAX enabled, but no PaX options are enabled."
59382+#endif
59383+
59384+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
59385+void gr_handle_brute_check(void);
59386+void gr_handle_kernel_exploit(void);
59387+int gr_process_user_ban(void);
59388+
59389+char gr_roletype_to_char(void);
59390+
59391+int gr_acl_enable_at_secure(void);
59392+
59393+int gr_check_user_change(int real, int effective, int fs);
59394+int gr_check_group_change(int real, int effective, int fs);
59395+
59396+void gr_del_task_from_ip_table(struct task_struct *p);
59397+
59398+int gr_pid_is_chrooted(struct task_struct *p);
59399+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
59400+int gr_handle_chroot_nice(void);
59401+int gr_handle_chroot_sysctl(const int op);
59402+int gr_handle_chroot_setpriority(struct task_struct *p,
59403+ const int niceval);
59404+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
59405+int gr_handle_chroot_chroot(const struct dentry *dentry,
59406+ const struct vfsmount *mnt);
59407+int gr_handle_chroot_caps(struct path *path);
59408+void gr_handle_chroot_chdir(struct path *path);
59409+int gr_handle_chroot_chmod(const struct dentry *dentry,
59410+ const struct vfsmount *mnt, const int mode);
59411+int gr_handle_chroot_mknod(const struct dentry *dentry,
59412+ const struct vfsmount *mnt, const int mode);
59413+int gr_handle_chroot_mount(const struct dentry *dentry,
59414+ const struct vfsmount *mnt,
59415+ const char *dev_name);
59416+int gr_handle_chroot_pivot(void);
59417+int gr_handle_chroot_unix(const pid_t pid);
59418+
59419+int gr_handle_rawio(const struct inode *inode);
59420+
59421+void gr_handle_ioperm(void);
59422+void gr_handle_iopl(void);
59423+
59424+int gr_tpe_allow(const struct file *file);
59425+
59426+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
59427+void gr_clear_chroot_entries(struct task_struct *task);
59428+
59429+void gr_log_forkfail(const int retval);
59430+void gr_log_timechange(void);
59431+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
59432+void gr_log_chdir(const struct dentry *dentry,
59433+ const struct vfsmount *mnt);
59434+void gr_log_chroot_exec(const struct dentry *dentry,
59435+ const struct vfsmount *mnt);
59436+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
59437+#ifdef CONFIG_COMPAT
59438+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
59439+#endif
59440+void gr_log_remount(const char *devname, const int retval);
59441+void gr_log_unmount(const char *devname, const int retval);
59442+void gr_log_mount(const char *from, const char *to, const int retval);
59443+void gr_log_textrel(struct vm_area_struct *vma);
59444+void gr_log_rwxmmap(struct file *file);
59445+void gr_log_rwxmprotect(struct file *file);
59446+
59447+int gr_handle_follow_link(const struct inode *parent,
59448+ const struct inode *inode,
59449+ const struct dentry *dentry,
59450+ const struct vfsmount *mnt);
59451+int gr_handle_fifo(const struct dentry *dentry,
59452+ const struct vfsmount *mnt,
59453+ const struct dentry *dir, const int flag,
59454+ const int acc_mode);
59455+int gr_handle_hardlink(const struct dentry *dentry,
59456+ const struct vfsmount *mnt,
59457+ struct inode *inode,
59458+ const int mode, const char *to);
59459+
59460+int gr_is_capable(const int cap);
59461+int gr_is_capable_nolog(const int cap);
59462+void gr_learn_resource(const struct task_struct *task, const int limit,
59463+ const unsigned long wanted, const int gt);
59464+void gr_copy_label(struct task_struct *tsk);
59465+void gr_handle_crash(struct task_struct *task, const int sig);
59466+int gr_handle_signal(const struct task_struct *p, const int sig);
59467+int gr_check_crash_uid(const uid_t uid);
59468+int gr_check_protected_task(const struct task_struct *task);
59469+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
59470+int gr_acl_handle_mmap(const struct file *file,
59471+ const unsigned long prot);
59472+int gr_acl_handle_mprotect(const struct file *file,
59473+ const unsigned long prot);
59474+int gr_check_hidden_task(const struct task_struct *tsk);
59475+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
59476+ const struct vfsmount *mnt);
59477+__u32 gr_acl_handle_utime(const struct dentry *dentry,
59478+ const struct vfsmount *mnt);
59479+__u32 gr_acl_handle_access(const struct dentry *dentry,
59480+ const struct vfsmount *mnt, const int fmode);
59481+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
59482+ const struct vfsmount *mnt, mode_t mode);
59483+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
59484+ const struct vfsmount *mnt, mode_t mode);
59485+__u32 gr_acl_handle_chown(const struct dentry *dentry,
59486+ const struct vfsmount *mnt);
59487+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
59488+ const struct vfsmount *mnt);
59489+int gr_handle_ptrace(struct task_struct *task, const long request);
59490+int gr_handle_proc_ptrace(struct task_struct *task);
59491+__u32 gr_acl_handle_execve(const struct dentry *dentry,
59492+ const struct vfsmount *mnt);
59493+int gr_check_crash_exec(const struct file *filp);
59494+int gr_acl_is_enabled(void);
59495+void gr_set_kernel_label(struct task_struct *task);
59496+void gr_set_role_label(struct task_struct *task, const uid_t uid,
59497+ const gid_t gid);
59498+int gr_set_proc_label(const struct dentry *dentry,
59499+ const struct vfsmount *mnt,
59500+ const int unsafe_share);
59501+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
59502+ const struct vfsmount *mnt);
59503+__u32 gr_acl_handle_open(const struct dentry *dentry,
59504+ const struct vfsmount *mnt, const int fmode);
59505+__u32 gr_acl_handle_creat(const struct dentry *dentry,
59506+ const struct dentry *p_dentry,
59507+ const struct vfsmount *p_mnt, const int fmode,
59508+ const int imode);
59509+void gr_handle_create(const struct dentry *dentry,
59510+ const struct vfsmount *mnt);
59511+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
59512+ const struct dentry *parent_dentry,
59513+ const struct vfsmount *parent_mnt,
59514+ const int mode);
59515+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
59516+ const struct dentry *parent_dentry,
59517+ const struct vfsmount *parent_mnt);
59518+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
59519+ const struct vfsmount *mnt);
59520+void gr_handle_delete(const ino_t ino, const dev_t dev);
59521+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
59522+ const struct vfsmount *mnt);
59523+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
59524+ const struct dentry *parent_dentry,
59525+ const struct vfsmount *parent_mnt,
59526+ const char *from);
59527+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
59528+ const struct dentry *parent_dentry,
59529+ const struct vfsmount *parent_mnt,
59530+ const struct dentry *old_dentry,
59531+ const struct vfsmount *old_mnt, const char *to);
59532+int gr_acl_handle_rename(struct dentry *new_dentry,
59533+ struct dentry *parent_dentry,
59534+ const struct vfsmount *parent_mnt,
59535+ struct dentry *old_dentry,
59536+ struct inode *old_parent_inode,
59537+ struct vfsmount *old_mnt, const char *newname);
59538+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59539+ struct dentry *old_dentry,
59540+ struct dentry *new_dentry,
59541+ struct vfsmount *mnt, const __u8 replace);
59542+__u32 gr_check_link(const struct dentry *new_dentry,
59543+ const struct dentry *parent_dentry,
59544+ const struct vfsmount *parent_mnt,
59545+ const struct dentry *old_dentry,
59546+ const struct vfsmount *old_mnt);
59547+int gr_acl_handle_filldir(const struct file *file, const char *name,
59548+ const unsigned int namelen, const ino_t ino);
59549+
59550+__u32 gr_acl_handle_unix(const struct dentry *dentry,
59551+ const struct vfsmount *mnt);
59552+void gr_acl_handle_exit(void);
59553+void gr_acl_handle_psacct(struct task_struct *task, const long code);
59554+int gr_acl_handle_procpidmem(const struct task_struct *task);
59555+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
59556+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
59557+void gr_audit_ptrace(struct task_struct *task);
59558+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
59559+
59560+#ifdef CONFIG_GRKERNSEC
59561+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
59562+void gr_handle_vm86(void);
59563+void gr_handle_mem_readwrite(u64 from, u64 to);
59564+
59565+extern int grsec_enable_dmesg;
59566+extern int grsec_disable_privio;
59567+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59568+extern int grsec_enable_chroot_findtask;
59569+#endif
59570+#endif
59571+
59572+#endif
59573diff -urNp linux-2.6.32.44/include/linux/hdpu_features.h linux-2.6.32.44/include/linux/hdpu_features.h
59574--- linux-2.6.32.44/include/linux/hdpu_features.h 2011-03-27 14:31:47.000000000 -0400
59575+++ linux-2.6.32.44/include/linux/hdpu_features.h 2011-04-17 15:56:46.000000000 -0400
59576@@ -3,7 +3,7 @@
59577 struct cpustate_t {
59578 spinlock_t lock;
59579 int excl;
59580- int open_count;
59581+ atomic_t open_count;
59582 unsigned char cached_val;
59583 int inited;
59584 unsigned long *set_addr;
59585diff -urNp linux-2.6.32.44/include/linux/highmem.h linux-2.6.32.44/include/linux/highmem.h
59586--- linux-2.6.32.44/include/linux/highmem.h 2011-03-27 14:31:47.000000000 -0400
59587+++ linux-2.6.32.44/include/linux/highmem.h 2011-04-17 15:56:46.000000000 -0400
59588@@ -137,6 +137,18 @@ static inline void clear_highpage(struct
59589 kunmap_atomic(kaddr, KM_USER0);
59590 }
59591
59592+static inline void sanitize_highpage(struct page *page)
59593+{
59594+ void *kaddr;
59595+ unsigned long flags;
59596+
59597+ local_irq_save(flags);
59598+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
59599+ clear_page(kaddr);
59600+ kunmap_atomic(kaddr, KM_CLEARPAGE);
59601+ local_irq_restore(flags);
59602+}
59603+
59604 static inline void zero_user_segments(struct page *page,
59605 unsigned start1, unsigned end1,
59606 unsigned start2, unsigned end2)
59607diff -urNp linux-2.6.32.44/include/linux/i2o.h linux-2.6.32.44/include/linux/i2o.h
59608--- linux-2.6.32.44/include/linux/i2o.h 2011-03-27 14:31:47.000000000 -0400
59609+++ linux-2.6.32.44/include/linux/i2o.h 2011-05-04 17:56:28.000000000 -0400
59610@@ -564,7 +564,7 @@ struct i2o_controller {
59611 struct i2o_device *exec; /* Executive */
59612 #if BITS_PER_LONG == 64
59613 spinlock_t context_list_lock; /* lock for context_list */
59614- atomic_t context_list_counter; /* needed for unique contexts */
59615+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
59616 struct list_head context_list; /* list of context id's
59617 and pointers */
59618 #endif
59619diff -urNp linux-2.6.32.44/include/linux/init_task.h linux-2.6.32.44/include/linux/init_task.h
59620--- linux-2.6.32.44/include/linux/init_task.h 2011-03-27 14:31:47.000000000 -0400
59621+++ linux-2.6.32.44/include/linux/init_task.h 2011-05-18 20:44:59.000000000 -0400
59622@@ -83,6 +83,12 @@ extern struct group_info init_groups;
59623 #define INIT_IDS
59624 #endif
59625
59626+#ifdef CONFIG_X86
59627+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
59628+#else
59629+#define INIT_TASK_THREAD_INFO
59630+#endif
59631+
59632 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
59633 /*
59634 * Because of the reduced scope of CAP_SETPCAP when filesystem
59635@@ -156,6 +162,7 @@ extern struct cred init_cred;
59636 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
59637 .comm = "swapper", \
59638 .thread = INIT_THREAD, \
59639+ INIT_TASK_THREAD_INFO \
59640 .fs = &init_fs, \
59641 .files = &init_files, \
59642 .signal = &init_signals, \
59643diff -urNp linux-2.6.32.44/include/linux/intel-iommu.h linux-2.6.32.44/include/linux/intel-iommu.h
59644--- linux-2.6.32.44/include/linux/intel-iommu.h 2011-03-27 14:31:47.000000000 -0400
59645+++ linux-2.6.32.44/include/linux/intel-iommu.h 2011-08-05 20:33:55.000000000 -0400
59646@@ -296,7 +296,7 @@ struct iommu_flush {
59647 u8 fm, u64 type);
59648 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
59649 unsigned int size_order, u64 type);
59650-};
59651+} __no_const;
59652
59653 enum {
59654 SR_DMAR_FECTL_REG,
59655diff -urNp linux-2.6.32.44/include/linux/interrupt.h linux-2.6.32.44/include/linux/interrupt.h
59656--- linux-2.6.32.44/include/linux/interrupt.h 2011-06-25 12:55:35.000000000 -0400
59657+++ linux-2.6.32.44/include/linux/interrupt.h 2011-06-25 12:56:37.000000000 -0400
59658@@ -363,7 +363,7 @@ enum
59659 /* map softirq index to softirq name. update 'softirq_to_name' in
59660 * kernel/softirq.c when adding a new softirq.
59661 */
59662-extern char *softirq_to_name[NR_SOFTIRQS];
59663+extern const char * const softirq_to_name[NR_SOFTIRQS];
59664
59665 /* softirq mask and active fields moved to irq_cpustat_t in
59666 * asm/hardirq.h to get better cache usage. KAO
59667@@ -371,12 +371,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
59668
59669 struct softirq_action
59670 {
59671- void (*action)(struct softirq_action *);
59672+ void (*action)(void);
59673 };
59674
59675 asmlinkage void do_softirq(void);
59676 asmlinkage void __do_softirq(void);
59677-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
59678+extern void open_softirq(int nr, void (*action)(void));
59679 extern void softirq_init(void);
59680 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
59681 extern void raise_softirq_irqoff(unsigned int nr);
59682diff -urNp linux-2.6.32.44/include/linux/irq.h linux-2.6.32.44/include/linux/irq.h
59683--- linux-2.6.32.44/include/linux/irq.h 2011-03-27 14:31:47.000000000 -0400
59684+++ linux-2.6.32.44/include/linux/irq.h 2011-04-17 15:56:46.000000000 -0400
59685@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq,
59686 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
59687 bool boot)
59688 {
59689+#ifdef CONFIG_CPUMASK_OFFSTACK
59690 gfp_t gfp = GFP_ATOMIC;
59691
59692 if (boot)
59693 gfp = GFP_NOWAIT;
59694
59695-#ifdef CONFIG_CPUMASK_OFFSTACK
59696 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
59697 return false;
59698
59699diff -urNp linux-2.6.32.44/include/linux/kallsyms.h linux-2.6.32.44/include/linux/kallsyms.h
59700--- linux-2.6.32.44/include/linux/kallsyms.h 2011-03-27 14:31:47.000000000 -0400
59701+++ linux-2.6.32.44/include/linux/kallsyms.h 2011-04-17 15:56:46.000000000 -0400
59702@@ -15,7 +15,8 @@
59703
59704 struct module;
59705
59706-#ifdef CONFIG_KALLSYMS
59707+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
59708+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59709 /* Lookup the address for a symbol. Returns 0 if not found. */
59710 unsigned long kallsyms_lookup_name(const char *name);
59711
59712@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(un
59713 /* Stupid that this does nothing, but I didn't create this mess. */
59714 #define __print_symbol(fmt, addr)
59715 #endif /*CONFIG_KALLSYMS*/
59716+#else /* when included by kallsyms.c, vsnprintf.c, or
59717+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
59718+extern void __print_symbol(const char *fmt, unsigned long address);
59719+extern int sprint_symbol(char *buffer, unsigned long address);
59720+const char *kallsyms_lookup(unsigned long addr,
59721+ unsigned long *symbolsize,
59722+ unsigned long *offset,
59723+ char **modname, char *namebuf);
59724+#endif
59725
59726 /* This macro allows us to keep printk typechecking */
59727 static void __check_printsym_format(const char *fmt, ...)
59728diff -urNp linux-2.6.32.44/include/linux/kgdb.h linux-2.6.32.44/include/linux/kgdb.h
59729--- linux-2.6.32.44/include/linux/kgdb.h 2011-03-27 14:31:47.000000000 -0400
59730+++ linux-2.6.32.44/include/linux/kgdb.h 2011-08-05 20:33:55.000000000 -0400
59731@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
59732
59733 extern int kgdb_connected;
59734
59735-extern atomic_t kgdb_setting_breakpoint;
59736-extern atomic_t kgdb_cpu_doing_single_step;
59737+extern atomic_unchecked_t kgdb_setting_breakpoint;
59738+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
59739
59740 extern struct task_struct *kgdb_usethread;
59741 extern struct task_struct *kgdb_contthread;
59742@@ -226,8 +226,8 @@ extern int kgdb_arch_remove_breakpoint(u
59743 * hardware debug registers.
59744 */
59745 struct kgdb_arch {
59746- unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
59747- unsigned long flags;
59748+ const unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
59749+ const unsigned long flags;
59750
59751 int (*set_breakpoint)(unsigned long, char *);
59752 int (*remove_breakpoint)(unsigned long, char *);
59753@@ -251,20 +251,20 @@ struct kgdb_arch {
59754 */
59755 struct kgdb_io {
59756 const char *name;
59757- int (*read_char) (void);
59758- void (*write_char) (u8);
59759- void (*flush) (void);
59760- int (*init) (void);
59761- void (*pre_exception) (void);
59762- void (*post_exception) (void);
59763+ int (* const read_char) (void);
59764+ void (* const write_char) (u8);
59765+ void (* const flush) (void);
59766+ int (* const init) (void);
59767+ void (* const pre_exception) (void);
59768+ void (* const post_exception) (void);
59769 };
59770
59771-extern struct kgdb_arch arch_kgdb_ops;
59772+extern const struct kgdb_arch arch_kgdb_ops;
59773
59774 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
59775
59776-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
59777-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
59778+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
59779+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
59780
59781 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
59782 extern int kgdb_mem2hex(char *mem, char *buf, int count);
59783diff -urNp linux-2.6.32.44/include/linux/kmod.h linux-2.6.32.44/include/linux/kmod.h
59784--- linux-2.6.32.44/include/linux/kmod.h 2011-03-27 14:31:47.000000000 -0400
59785+++ linux-2.6.32.44/include/linux/kmod.h 2011-04-17 15:56:46.000000000 -0400
59786@@ -31,6 +31,8 @@
59787 * usually useless though. */
59788 extern int __request_module(bool wait, const char *name, ...) \
59789 __attribute__((format(printf, 2, 3)));
59790+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
59791+ __attribute__((format(printf, 3, 4)));
59792 #define request_module(mod...) __request_module(true, mod)
59793 #define request_module_nowait(mod...) __request_module(false, mod)
59794 #define try_then_request_module(x, mod...) \
59795diff -urNp linux-2.6.32.44/include/linux/kobject.h linux-2.6.32.44/include/linux/kobject.h
59796--- linux-2.6.32.44/include/linux/kobject.h 2011-03-27 14:31:47.000000000 -0400
59797+++ linux-2.6.32.44/include/linux/kobject.h 2011-04-17 15:56:46.000000000 -0400
59798@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kob
59799
59800 struct kobj_type {
59801 void (*release)(struct kobject *kobj);
59802- struct sysfs_ops *sysfs_ops;
59803+ const struct sysfs_ops *sysfs_ops;
59804 struct attribute **default_attrs;
59805 };
59806
59807@@ -118,9 +118,9 @@ struct kobj_uevent_env {
59808 };
59809
59810 struct kset_uevent_ops {
59811- int (*filter)(struct kset *kset, struct kobject *kobj);
59812- const char *(*name)(struct kset *kset, struct kobject *kobj);
59813- int (*uevent)(struct kset *kset, struct kobject *kobj,
59814+ int (* const filter)(struct kset *kset, struct kobject *kobj);
59815+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
59816+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
59817 struct kobj_uevent_env *env);
59818 };
59819
59820@@ -132,7 +132,7 @@ struct kobj_attribute {
59821 const char *buf, size_t count);
59822 };
59823
59824-extern struct sysfs_ops kobj_sysfs_ops;
59825+extern const struct sysfs_ops kobj_sysfs_ops;
59826
59827 /**
59828 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
59829@@ -155,14 +155,14 @@ struct kset {
59830 struct list_head list;
59831 spinlock_t list_lock;
59832 struct kobject kobj;
59833- struct kset_uevent_ops *uevent_ops;
59834+ const struct kset_uevent_ops *uevent_ops;
59835 };
59836
59837 extern void kset_init(struct kset *kset);
59838 extern int __must_check kset_register(struct kset *kset);
59839 extern void kset_unregister(struct kset *kset);
59840 extern struct kset * __must_check kset_create_and_add(const char *name,
59841- struct kset_uevent_ops *u,
59842+ const struct kset_uevent_ops *u,
59843 struct kobject *parent_kobj);
59844
59845 static inline struct kset *to_kset(struct kobject *kobj)
59846diff -urNp linux-2.6.32.44/include/linux/kvm_host.h linux-2.6.32.44/include/linux/kvm_host.h
59847--- linux-2.6.32.44/include/linux/kvm_host.h 2011-03-27 14:31:47.000000000 -0400
59848+++ linux-2.6.32.44/include/linux/kvm_host.h 2011-04-17 15:56:46.000000000 -0400
59849@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
59850 void vcpu_load(struct kvm_vcpu *vcpu);
59851 void vcpu_put(struct kvm_vcpu *vcpu);
59852
59853-int kvm_init(void *opaque, unsigned int vcpu_size,
59854+int kvm_init(const void *opaque, unsigned int vcpu_size,
59855 struct module *module);
59856 void kvm_exit(void);
59857
59858@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
59859 struct kvm_guest_debug *dbg);
59860 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
59861
59862-int kvm_arch_init(void *opaque);
59863+int kvm_arch_init(const void *opaque);
59864 void kvm_arch_exit(void);
59865
59866 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
59867diff -urNp linux-2.6.32.44/include/linux/libata.h linux-2.6.32.44/include/linux/libata.h
59868--- linux-2.6.32.44/include/linux/libata.h 2011-03-27 14:31:47.000000000 -0400
59869+++ linux-2.6.32.44/include/linux/libata.h 2011-08-05 20:33:55.000000000 -0400
59870@@ -525,11 +525,11 @@ struct ata_ioports {
59871
59872 struct ata_host {
59873 spinlock_t lock;
59874- struct device *dev;
59875+ struct device *dev;
59876 void __iomem * const *iomap;
59877 unsigned int n_ports;
59878 void *private_data;
59879- struct ata_port_operations *ops;
59880+ const struct ata_port_operations *ops;
59881 unsigned long flags;
59882 #ifdef CONFIG_ATA_ACPI
59883 acpi_handle acpi_handle;
59884@@ -710,7 +710,7 @@ struct ata_link {
59885
59886 struct ata_port {
59887 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
59888- struct ata_port_operations *ops;
59889+ const struct ata_port_operations *ops;
59890 spinlock_t *lock;
59891 /* Flags owned by the EH context. Only EH should touch these once the
59892 port is active */
59893@@ -883,7 +883,7 @@ struct ata_port_operations {
59894 * ->inherits must be the last field and all the preceding
59895 * fields must be pointers.
59896 */
59897- const struct ata_port_operations *inherits;
59898+ const struct ata_port_operations * const inherits;
59899 };
59900
59901 struct ata_port_info {
59902@@ -892,7 +892,7 @@ struct ata_port_info {
59903 unsigned long pio_mask;
59904 unsigned long mwdma_mask;
59905 unsigned long udma_mask;
59906- struct ata_port_operations *port_ops;
59907+ const struct ata_port_operations *port_ops;
59908 void *private_data;
59909 };
59910
59911@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timi
59912 extern const unsigned long sata_deb_timing_hotplug[];
59913 extern const unsigned long sata_deb_timing_long[];
59914
59915-extern struct ata_port_operations ata_dummy_port_ops;
59916+extern const struct ata_port_operations ata_dummy_port_ops;
59917 extern const struct ata_port_info ata_dummy_port_info;
59918
59919 static inline const unsigned long *
59920@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_
59921 struct scsi_host_template *sht);
59922 extern void ata_host_detach(struct ata_host *host);
59923 extern void ata_host_init(struct ata_host *, struct device *,
59924- unsigned long, struct ata_port_operations *);
59925+ unsigned long, const struct ata_port_operations *);
59926 extern int ata_scsi_detect(struct scsi_host_template *sht);
59927 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
59928 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
59929diff -urNp linux-2.6.32.44/include/linux/lockd/bind.h linux-2.6.32.44/include/linux/lockd/bind.h
59930--- linux-2.6.32.44/include/linux/lockd/bind.h 2011-03-27 14:31:47.000000000 -0400
59931+++ linux-2.6.32.44/include/linux/lockd/bind.h 2011-04-17 15:56:46.000000000 -0400
59932@@ -23,13 +23,13 @@ struct svc_rqst;
59933 * This is the set of functions for lockd->nfsd communication
59934 */
59935 struct nlmsvc_binding {
59936- __be32 (*fopen)(struct svc_rqst *,
59937+ __be32 (* const fopen)(struct svc_rqst *,
59938 struct nfs_fh *,
59939 struct file **);
59940- void (*fclose)(struct file *);
59941+ void (* const fclose)(struct file *);
59942 };
59943
59944-extern struct nlmsvc_binding * nlmsvc_ops;
59945+extern const struct nlmsvc_binding * nlmsvc_ops;
59946
59947 /*
59948 * Similar to nfs_client_initdata, but without the NFS-specific
59949diff -urNp linux-2.6.32.44/include/linux/mca.h linux-2.6.32.44/include/linux/mca.h
59950--- linux-2.6.32.44/include/linux/mca.h 2011-03-27 14:31:47.000000000 -0400
59951+++ linux-2.6.32.44/include/linux/mca.h 2011-08-05 20:33:55.000000000 -0400
59952@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
59953 int region);
59954 void * (*mca_transform_memory)(struct mca_device *,
59955 void *memory);
59956-};
59957+} __no_const;
59958
59959 struct mca_bus {
59960 u64 default_dma_mask;
59961diff -urNp linux-2.6.32.44/include/linux/memory.h linux-2.6.32.44/include/linux/memory.h
59962--- linux-2.6.32.44/include/linux/memory.h 2011-03-27 14:31:47.000000000 -0400
59963+++ linux-2.6.32.44/include/linux/memory.h 2011-08-05 20:33:55.000000000 -0400
59964@@ -108,7 +108,7 @@ struct memory_accessor {
59965 size_t count);
59966 ssize_t (*write)(struct memory_accessor *, const char *buf,
59967 off_t offset, size_t count);
59968-};
59969+} __no_const;
59970
59971 /*
59972 * Kernel text modification mutex, used for code patching. Users of this lock
59973diff -urNp linux-2.6.32.44/include/linux/mm.h linux-2.6.32.44/include/linux/mm.h
59974--- linux-2.6.32.44/include/linux/mm.h 2011-03-27 14:31:47.000000000 -0400
59975+++ linux-2.6.32.44/include/linux/mm.h 2011-04-17 15:56:46.000000000 -0400
59976@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void
59977
59978 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
59979 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
59980+
59981+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
59982+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
59983+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
59984+#else
59985 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
59986+#endif
59987+
59988 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
59989 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
59990
59991@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
59992 int set_page_dirty_lock(struct page *page);
59993 int clear_page_dirty_for_io(struct page *page);
59994
59995-/* Is the vma a continuation of the stack vma above it? */
59996-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
59997-{
59998- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
59999-}
60000-
60001 extern unsigned long move_page_tables(struct vm_area_struct *vma,
60002 unsigned long old_addr, struct vm_area_struct *new_vma,
60003 unsigned long new_addr, unsigned long len);
60004@@ -890,6 +891,8 @@ struct shrinker {
60005 extern void register_shrinker(struct shrinker *);
60006 extern void unregister_shrinker(struct shrinker *);
60007
60008+pgprot_t vm_get_page_prot(unsigned long vm_flags);
60009+
60010 int vma_wants_writenotify(struct vm_area_struct *vma);
60011
60012 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
60013@@ -1162,6 +1165,7 @@ out:
60014 }
60015
60016 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
60017+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
60018
60019 extern unsigned long do_brk(unsigned long, unsigned long);
60020
60021@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(
60022 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
60023 struct vm_area_struct **pprev);
60024
60025+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
60026+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
60027+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
60028+
60029 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
60030 NULL if none. Assume start_addr < end_addr. */
60031 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
60032@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(st
60033 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
60034 }
60035
60036-pgprot_t vm_get_page_prot(unsigned long vm_flags);
60037 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
60038 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
60039 unsigned long pfn, unsigned long size, pgprot_t);
60040@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long
60041 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
60042 extern int sysctl_memory_failure_early_kill;
60043 extern int sysctl_memory_failure_recovery;
60044-extern atomic_long_t mce_bad_pages;
60045+extern atomic_long_unchecked_t mce_bad_pages;
60046+
60047+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60048+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
60049+#else
60050+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
60051+#endif
60052
60053 #endif /* __KERNEL__ */
60054 #endif /* _LINUX_MM_H */
60055diff -urNp linux-2.6.32.44/include/linux/mm_types.h linux-2.6.32.44/include/linux/mm_types.h
60056--- linux-2.6.32.44/include/linux/mm_types.h 2011-03-27 14:31:47.000000000 -0400
60057+++ linux-2.6.32.44/include/linux/mm_types.h 2011-04-17 15:56:46.000000000 -0400
60058@@ -186,6 +186,8 @@ struct vm_area_struct {
60059 #ifdef CONFIG_NUMA
60060 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
60061 #endif
60062+
60063+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
60064 };
60065
60066 struct core_thread {
60067@@ -287,6 +289,24 @@ struct mm_struct {
60068 #ifdef CONFIG_MMU_NOTIFIER
60069 struct mmu_notifier_mm *mmu_notifier_mm;
60070 #endif
60071+
60072+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60073+ unsigned long pax_flags;
60074+#endif
60075+
60076+#ifdef CONFIG_PAX_DLRESOLVE
60077+ unsigned long call_dl_resolve;
60078+#endif
60079+
60080+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60081+ unsigned long call_syscall;
60082+#endif
60083+
60084+#ifdef CONFIG_PAX_ASLR
60085+ unsigned long delta_mmap; /* randomized offset */
60086+ unsigned long delta_stack; /* randomized offset */
60087+#endif
60088+
60089 };
60090
60091 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
60092diff -urNp linux-2.6.32.44/include/linux/mmu_notifier.h linux-2.6.32.44/include/linux/mmu_notifier.h
60093--- linux-2.6.32.44/include/linux/mmu_notifier.h 2011-03-27 14:31:47.000000000 -0400
60094+++ linux-2.6.32.44/include/linux/mmu_notifier.h 2011-04-17 15:56:46.000000000 -0400
60095@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destr
60096 */
60097 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
60098 ({ \
60099- pte_t __pte; \
60100+ pte_t ___pte; \
60101 struct vm_area_struct *___vma = __vma; \
60102 unsigned long ___address = __address; \
60103- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
60104+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
60105 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
60106- __pte; \
60107+ ___pte; \
60108 })
60109
60110 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
60111diff -urNp linux-2.6.32.44/include/linux/mmzone.h linux-2.6.32.44/include/linux/mmzone.h
60112--- linux-2.6.32.44/include/linux/mmzone.h 2011-03-27 14:31:47.000000000 -0400
60113+++ linux-2.6.32.44/include/linux/mmzone.h 2011-04-17 15:56:46.000000000 -0400
60114@@ -350,7 +350,7 @@ struct zone {
60115 unsigned long flags; /* zone flags, see below */
60116
60117 /* Zone statistics */
60118- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
60119+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
60120
60121 /*
60122 * prev_priority holds the scanning priority for this zone. It is
60123diff -urNp linux-2.6.32.44/include/linux/mod_devicetable.h linux-2.6.32.44/include/linux/mod_devicetable.h
60124--- linux-2.6.32.44/include/linux/mod_devicetable.h 2011-03-27 14:31:47.000000000 -0400
60125+++ linux-2.6.32.44/include/linux/mod_devicetable.h 2011-04-17 15:56:46.000000000 -0400
60126@@ -12,7 +12,7 @@
60127 typedef unsigned long kernel_ulong_t;
60128 #endif
60129
60130-#define PCI_ANY_ID (~0)
60131+#define PCI_ANY_ID ((__u16)~0)
60132
60133 struct pci_device_id {
60134 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
60135@@ -131,7 +131,7 @@ struct usb_device_id {
60136 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
60137 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
60138
60139-#define HID_ANY_ID (~0)
60140+#define HID_ANY_ID (~0U)
60141
60142 struct hid_device_id {
60143 __u16 bus;
60144diff -urNp linux-2.6.32.44/include/linux/module.h linux-2.6.32.44/include/linux/module.h
60145--- linux-2.6.32.44/include/linux/module.h 2011-03-27 14:31:47.000000000 -0400
60146+++ linux-2.6.32.44/include/linux/module.h 2011-08-05 20:33:55.000000000 -0400
60147@@ -16,6 +16,7 @@
60148 #include <linux/kobject.h>
60149 #include <linux/moduleparam.h>
60150 #include <linux/tracepoint.h>
60151+#include <linux/fs.h>
60152
60153 #include <asm/local.h>
60154 #include <asm/module.h>
60155@@ -287,16 +288,16 @@ struct module
60156 int (*init)(void);
60157
60158 /* If this is non-NULL, vfree after init() returns */
60159- void *module_init;
60160+ void *module_init_rx, *module_init_rw;
60161
60162 /* Here is the actual code + data, vfree'd on unload. */
60163- void *module_core;
60164+ void *module_core_rx, *module_core_rw;
60165
60166 /* Here are the sizes of the init and core sections */
60167- unsigned int init_size, core_size;
60168+ unsigned int init_size_rw, core_size_rw;
60169
60170 /* The size of the executable code in each section. */
60171- unsigned int init_text_size, core_text_size;
60172+ unsigned int init_size_rx, core_size_rx;
60173
60174 /* Arch-specific module values */
60175 struct mod_arch_specific arch;
60176@@ -345,6 +346,10 @@ struct module
60177 #ifdef CONFIG_EVENT_TRACING
60178 struct ftrace_event_call *trace_events;
60179 unsigned int num_trace_events;
60180+ struct file_operations trace_id;
60181+ struct file_operations trace_enable;
60182+ struct file_operations trace_format;
60183+ struct file_operations trace_filter;
60184 #endif
60185 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
60186 unsigned long *ftrace_callsites;
60187@@ -393,16 +398,46 @@ struct module *__module_address(unsigned
60188 bool is_module_address(unsigned long addr);
60189 bool is_module_text_address(unsigned long addr);
60190
60191+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
60192+{
60193+
60194+#ifdef CONFIG_PAX_KERNEXEC
60195+ if (ktla_ktva(addr) >= (unsigned long)start &&
60196+ ktla_ktva(addr) < (unsigned long)start + size)
60197+ return 1;
60198+#endif
60199+
60200+ return ((void *)addr >= start && (void *)addr < start + size);
60201+}
60202+
60203+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
60204+{
60205+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
60206+}
60207+
60208+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
60209+{
60210+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
60211+}
60212+
60213+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
60214+{
60215+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
60216+}
60217+
60218+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
60219+{
60220+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
60221+}
60222+
60223 static inline int within_module_core(unsigned long addr, struct module *mod)
60224 {
60225- return (unsigned long)mod->module_core <= addr &&
60226- addr < (unsigned long)mod->module_core + mod->core_size;
60227+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
60228 }
60229
60230 static inline int within_module_init(unsigned long addr, struct module *mod)
60231 {
60232- return (unsigned long)mod->module_init <= addr &&
60233- addr < (unsigned long)mod->module_init + mod->init_size;
60234+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
60235 }
60236
60237 /* Search for module by name: must hold module_mutex. */
60238diff -urNp linux-2.6.32.44/include/linux/moduleloader.h linux-2.6.32.44/include/linux/moduleloader.h
60239--- linux-2.6.32.44/include/linux/moduleloader.h 2011-03-27 14:31:47.000000000 -0400
60240+++ linux-2.6.32.44/include/linux/moduleloader.h 2011-04-17 15:56:46.000000000 -0400
60241@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
60242 sections. Returns NULL on failure. */
60243 void *module_alloc(unsigned long size);
60244
60245+#ifdef CONFIG_PAX_KERNEXEC
60246+void *module_alloc_exec(unsigned long size);
60247+#else
60248+#define module_alloc_exec(x) module_alloc(x)
60249+#endif
60250+
60251 /* Free memory returned from module_alloc. */
60252 void module_free(struct module *mod, void *module_region);
60253
60254+#ifdef CONFIG_PAX_KERNEXEC
60255+void module_free_exec(struct module *mod, void *module_region);
60256+#else
60257+#define module_free_exec(x, y) module_free((x), (y))
60258+#endif
60259+
60260 /* Apply the given relocation to the (simplified) ELF. Return -error
60261 or 0. */
60262 int apply_relocate(Elf_Shdr *sechdrs,
60263diff -urNp linux-2.6.32.44/include/linux/moduleparam.h linux-2.6.32.44/include/linux/moduleparam.h
60264--- linux-2.6.32.44/include/linux/moduleparam.h 2011-03-27 14:31:47.000000000 -0400
60265+++ linux-2.6.32.44/include/linux/moduleparam.h 2011-04-17 15:56:46.000000000 -0400
60266@@ -132,7 +132,7 @@ struct kparam_array
60267
60268 /* Actually copy string: maxlen param is usually sizeof(string). */
60269 #define module_param_string(name, string, len, perm) \
60270- static const struct kparam_string __param_string_##name \
60271+ static const struct kparam_string __param_string_##name __used \
60272 = { len, string }; \
60273 __module_param_call(MODULE_PARAM_PREFIX, name, \
60274 param_set_copystring, param_get_string, \
60275@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffe
60276
60277 /* Comma-separated array: *nump is set to number they actually specified. */
60278 #define module_param_array_named(name, array, type, nump, perm) \
60279- static const struct kparam_array __param_arr_##name \
60280+ static const struct kparam_array __param_arr_##name __used \
60281 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
60282 sizeof(array[0]), array }; \
60283 __module_param_call(MODULE_PARAM_PREFIX, name, \
60284diff -urNp linux-2.6.32.44/include/linux/mutex.h linux-2.6.32.44/include/linux/mutex.h
60285--- linux-2.6.32.44/include/linux/mutex.h 2011-03-27 14:31:47.000000000 -0400
60286+++ linux-2.6.32.44/include/linux/mutex.h 2011-04-17 15:56:46.000000000 -0400
60287@@ -51,7 +51,7 @@ struct mutex {
60288 spinlock_t wait_lock;
60289 struct list_head wait_list;
60290 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
60291- struct thread_info *owner;
60292+ struct task_struct *owner;
60293 #endif
60294 #ifdef CONFIG_DEBUG_MUTEXES
60295 const char *name;
60296diff -urNp linux-2.6.32.44/include/linux/namei.h linux-2.6.32.44/include/linux/namei.h
60297--- linux-2.6.32.44/include/linux/namei.h 2011-03-27 14:31:47.000000000 -0400
60298+++ linux-2.6.32.44/include/linux/namei.h 2011-04-17 15:56:46.000000000 -0400
60299@@ -22,7 +22,7 @@ struct nameidata {
60300 unsigned int flags;
60301 int last_type;
60302 unsigned depth;
60303- char *saved_names[MAX_NESTED_LINKS + 1];
60304+ const char *saved_names[MAX_NESTED_LINKS + 1];
60305
60306 /* Intent data */
60307 union {
60308@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
60309 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
60310 extern void unlock_rename(struct dentry *, struct dentry *);
60311
60312-static inline void nd_set_link(struct nameidata *nd, char *path)
60313+static inline void nd_set_link(struct nameidata *nd, const char *path)
60314 {
60315 nd->saved_names[nd->depth] = path;
60316 }
60317
60318-static inline char *nd_get_link(struct nameidata *nd)
60319+static inline const char *nd_get_link(const struct nameidata *nd)
60320 {
60321 return nd->saved_names[nd->depth];
60322 }
60323diff -urNp linux-2.6.32.44/include/linux/netfilter/xt_gradm.h linux-2.6.32.44/include/linux/netfilter/xt_gradm.h
60324--- linux-2.6.32.44/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
60325+++ linux-2.6.32.44/include/linux/netfilter/xt_gradm.h 2011-04-17 15:56:46.000000000 -0400
60326@@ -0,0 +1,9 @@
60327+#ifndef _LINUX_NETFILTER_XT_GRADM_H
60328+#define _LINUX_NETFILTER_XT_GRADM_H 1
60329+
60330+struct xt_gradm_mtinfo {
60331+ __u16 flags;
60332+ __u16 invflags;
60333+};
60334+
60335+#endif
60336diff -urNp linux-2.6.32.44/include/linux/nodemask.h linux-2.6.32.44/include/linux/nodemask.h
60337--- linux-2.6.32.44/include/linux/nodemask.h 2011-03-27 14:31:47.000000000 -0400
60338+++ linux-2.6.32.44/include/linux/nodemask.h 2011-04-17 15:56:46.000000000 -0400
60339@@ -464,11 +464,11 @@ static inline int num_node_state(enum no
60340
60341 #define any_online_node(mask) \
60342 ({ \
60343- int node; \
60344- for_each_node_mask(node, (mask)) \
60345- if (node_online(node)) \
60346+ int __node; \
60347+ for_each_node_mask(__node, (mask)) \
60348+ if (node_online(__node)) \
60349 break; \
60350- node; \
60351+ __node; \
60352 })
60353
60354 #define num_online_nodes() num_node_state(N_ONLINE)
60355diff -urNp linux-2.6.32.44/include/linux/oprofile.h linux-2.6.32.44/include/linux/oprofile.h
60356--- linux-2.6.32.44/include/linux/oprofile.h 2011-03-27 14:31:47.000000000 -0400
60357+++ linux-2.6.32.44/include/linux/oprofile.h 2011-04-17 15:56:46.000000000 -0400
60358@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super
60359 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
60360 char const * name, ulong * val);
60361
60362-/** Create a file for read-only access to an atomic_t. */
60363+/** Create a file for read-only access to an atomic_unchecked_t. */
60364 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
60365- char const * name, atomic_t * val);
60366+ char const * name, atomic_unchecked_t * val);
60367
60368 /** create a directory */
60369 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
60370diff -urNp linux-2.6.32.44/include/linux/perf_event.h linux-2.6.32.44/include/linux/perf_event.h
60371--- linux-2.6.32.44/include/linux/perf_event.h 2011-03-27 14:31:47.000000000 -0400
60372+++ linux-2.6.32.44/include/linux/perf_event.h 2011-05-04 17:56:28.000000000 -0400
60373@@ -476,7 +476,7 @@ struct hw_perf_event {
60374 struct hrtimer hrtimer;
60375 };
60376 };
60377- atomic64_t prev_count;
60378+ atomic64_unchecked_t prev_count;
60379 u64 sample_period;
60380 u64 last_period;
60381 atomic64_t period_left;
60382@@ -557,7 +557,7 @@ struct perf_event {
60383 const struct pmu *pmu;
60384
60385 enum perf_event_active_state state;
60386- atomic64_t count;
60387+ atomic64_unchecked_t count;
60388
60389 /*
60390 * These are the total time in nanoseconds that the event
60391@@ -595,8 +595,8 @@ struct perf_event {
60392 * These accumulate total time (in nanoseconds) that children
60393 * events have been enabled and running, respectively.
60394 */
60395- atomic64_t child_total_time_enabled;
60396- atomic64_t child_total_time_running;
60397+ atomic64_unchecked_t child_total_time_enabled;
60398+ atomic64_unchecked_t child_total_time_running;
60399
60400 /*
60401 * Protect attach/detach and child_list:
60402diff -urNp linux-2.6.32.44/include/linux/pipe_fs_i.h linux-2.6.32.44/include/linux/pipe_fs_i.h
60403--- linux-2.6.32.44/include/linux/pipe_fs_i.h 2011-03-27 14:31:47.000000000 -0400
60404+++ linux-2.6.32.44/include/linux/pipe_fs_i.h 2011-04-17 15:56:46.000000000 -0400
60405@@ -46,9 +46,9 @@ struct pipe_inode_info {
60406 wait_queue_head_t wait;
60407 unsigned int nrbufs, curbuf;
60408 struct page *tmp_page;
60409- unsigned int readers;
60410- unsigned int writers;
60411- unsigned int waiting_writers;
60412+ atomic_t readers;
60413+ atomic_t writers;
60414+ atomic_t waiting_writers;
60415 unsigned int r_counter;
60416 unsigned int w_counter;
60417 struct fasync_struct *fasync_readers;
60418diff -urNp linux-2.6.32.44/include/linux/poison.h linux-2.6.32.44/include/linux/poison.h
60419--- linux-2.6.32.44/include/linux/poison.h 2011-03-27 14:31:47.000000000 -0400
60420+++ linux-2.6.32.44/include/linux/poison.h 2011-04-17 15:56:46.000000000 -0400
60421@@ -19,8 +19,8 @@
60422 * under normal circumstances, used to verify that nobody uses
60423 * non-initialized list entries.
60424 */
60425-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
60426-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
60427+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
60428+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
60429
60430 /********** include/linux/timer.h **********/
60431 /*
60432diff -urNp linux-2.6.32.44/include/linux/posix-timers.h linux-2.6.32.44/include/linux/posix-timers.h
60433--- linux-2.6.32.44/include/linux/posix-timers.h 2011-03-27 14:31:47.000000000 -0400
60434+++ linux-2.6.32.44/include/linux/posix-timers.h 2011-08-05 20:33:55.000000000 -0400
60435@@ -67,7 +67,7 @@ struct k_itimer {
60436 };
60437
60438 struct k_clock {
60439- int res; /* in nanoseconds */
60440+ const int res; /* in nanoseconds */
60441 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
60442 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
60443 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
60444diff -urNp linux-2.6.32.44/include/linux/preempt.h linux-2.6.32.44/include/linux/preempt.h
60445--- linux-2.6.32.44/include/linux/preempt.h 2011-03-27 14:31:47.000000000 -0400
60446+++ linux-2.6.32.44/include/linux/preempt.h 2011-08-05 20:33:55.000000000 -0400
60447@@ -110,7 +110,7 @@ struct preempt_ops {
60448 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
60449 void (*sched_out)(struct preempt_notifier *notifier,
60450 struct task_struct *next);
60451-};
60452+} __no_const;
60453
60454 /**
60455 * preempt_notifier - key for installing preemption notifiers
60456diff -urNp linux-2.6.32.44/include/linux/proc_fs.h linux-2.6.32.44/include/linux/proc_fs.h
60457--- linux-2.6.32.44/include/linux/proc_fs.h 2011-03-27 14:31:47.000000000 -0400
60458+++ linux-2.6.32.44/include/linux/proc_fs.h 2011-08-05 20:33:55.000000000 -0400
60459@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
60460 return proc_create_data(name, mode, parent, proc_fops, NULL);
60461 }
60462
60463+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
60464+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
60465+{
60466+#ifdef CONFIG_GRKERNSEC_PROC_USER
60467+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
60468+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60469+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
60470+#else
60471+ return proc_create_data(name, mode, parent, proc_fops, NULL);
60472+#endif
60473+}
60474+
60475+
60476 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
60477 mode_t mode, struct proc_dir_entry *base,
60478 read_proc_t *read_proc, void * data)
60479@@ -256,7 +269,7 @@ union proc_op {
60480 int (*proc_show)(struct seq_file *m,
60481 struct pid_namespace *ns, struct pid *pid,
60482 struct task_struct *task);
60483-};
60484+} __no_const;
60485
60486 struct ctl_table_header;
60487 struct ctl_table;
60488diff -urNp linux-2.6.32.44/include/linux/ptrace.h linux-2.6.32.44/include/linux/ptrace.h
60489--- linux-2.6.32.44/include/linux/ptrace.h 2011-03-27 14:31:47.000000000 -0400
60490+++ linux-2.6.32.44/include/linux/ptrace.h 2011-04-17 15:56:46.000000000 -0400
60491@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_
60492 extern void exit_ptrace(struct task_struct *tracer);
60493 #define PTRACE_MODE_READ 1
60494 #define PTRACE_MODE_ATTACH 2
60495-/* Returns 0 on success, -errno on denial. */
60496-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
60497 /* Returns true on success, false on denial. */
60498 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
60499+/* Returns true on success, false on denial. */
60500+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
60501
60502 static inline int ptrace_reparented(struct task_struct *child)
60503 {
60504diff -urNp linux-2.6.32.44/include/linux/random.h linux-2.6.32.44/include/linux/random.h
60505--- linux-2.6.32.44/include/linux/random.h 2011-03-27 14:31:47.000000000 -0400
60506+++ linux-2.6.32.44/include/linux/random.h 2011-08-07 19:48:09.000000000 -0400
60507@@ -53,17 +53,6 @@ extern void add_interrupt_randomness(int
60508 extern void get_random_bytes(void *buf, int nbytes);
60509 void generate_random_uuid(unsigned char uuid_out[16]);
60510
60511-extern __u32 secure_ip_id(__be32 daddr);
60512-extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
60513-extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
60514- __be16 dport);
60515-extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
60516- __be16 sport, __be16 dport);
60517-extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
60518- __be16 sport, __be16 dport);
60519-extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
60520- __be16 sport, __be16 dport);
60521-
60522 #ifndef MODULE
60523 extern const struct file_operations random_fops, urandom_fops;
60524 #endif
60525@@ -74,6 +63,11 @@ unsigned long randomize_range(unsigned l
60526 u32 random32(void);
60527 void srandom32(u32 seed);
60528
60529+static inline unsigned long pax_get_random_long(void)
60530+{
60531+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
60532+}
60533+
60534 #endif /* __KERNEL___ */
60535
60536 #endif /* _LINUX_RANDOM_H */
60537diff -urNp linux-2.6.32.44/include/linux/reboot.h linux-2.6.32.44/include/linux/reboot.h
60538--- linux-2.6.32.44/include/linux/reboot.h 2011-03-27 14:31:47.000000000 -0400
60539+++ linux-2.6.32.44/include/linux/reboot.h 2011-05-22 23:02:06.000000000 -0400
60540@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
60541 * Architecture-specific implementations of sys_reboot commands.
60542 */
60543
60544-extern void machine_restart(char *cmd);
60545-extern void machine_halt(void);
60546-extern void machine_power_off(void);
60547+extern void machine_restart(char *cmd) __noreturn;
60548+extern void machine_halt(void) __noreturn;
60549+extern void machine_power_off(void) __noreturn;
60550
60551 extern void machine_shutdown(void);
60552 struct pt_regs;
60553@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
60554 */
60555
60556 extern void kernel_restart_prepare(char *cmd);
60557-extern void kernel_restart(char *cmd);
60558-extern void kernel_halt(void);
60559-extern void kernel_power_off(void);
60560+extern void kernel_restart(char *cmd) __noreturn;
60561+extern void kernel_halt(void) __noreturn;
60562+extern void kernel_power_off(void) __noreturn;
60563
60564 void ctrl_alt_del(void);
60565
60566@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
60567 * Emergency restart, callable from an interrupt handler.
60568 */
60569
60570-extern void emergency_restart(void);
60571+extern void emergency_restart(void) __noreturn;
60572 #include <asm/emergency-restart.h>
60573
60574 #endif
60575diff -urNp linux-2.6.32.44/include/linux/reiserfs_fs.h linux-2.6.32.44/include/linux/reiserfs_fs.h
60576--- linux-2.6.32.44/include/linux/reiserfs_fs.h 2011-03-27 14:31:47.000000000 -0400
60577+++ linux-2.6.32.44/include/linux/reiserfs_fs.h 2011-04-17 15:56:46.000000000 -0400
60578@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset
60579 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60580
60581 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60582-#define get_generation(s) atomic_read (&fs_generation(s))
60583+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60584 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60585 #define __fs_changed(gen,s) (gen != get_generation (s))
60586 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
60587@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_fro
60588 */
60589
60590 struct item_operations {
60591- int (*bytes_number) (struct item_head * ih, int block_size);
60592- void (*decrement_key) (struct cpu_key *);
60593- int (*is_left_mergeable) (struct reiserfs_key * ih,
60594+ int (* const bytes_number) (struct item_head * ih, int block_size);
60595+ void (* const decrement_key) (struct cpu_key *);
60596+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
60597 unsigned long bsize);
60598- void (*print_item) (struct item_head *, char *item);
60599- void (*check_item) (struct item_head *, char *item);
60600+ void (* const print_item) (struct item_head *, char *item);
60601+ void (* const check_item) (struct item_head *, char *item);
60602
60603- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
60604+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
60605 int is_affected, int insert_size);
60606- int (*check_left) (struct virtual_item * vi, int free,
60607+ int (* const check_left) (struct virtual_item * vi, int free,
60608 int start_skip, int end_skip);
60609- int (*check_right) (struct virtual_item * vi, int free);
60610- int (*part_size) (struct virtual_item * vi, int from, int to);
60611- int (*unit_num) (struct virtual_item * vi);
60612- void (*print_vi) (struct virtual_item * vi);
60613+ int (* const check_right) (struct virtual_item * vi, int free);
60614+ int (* const part_size) (struct virtual_item * vi, int from, int to);
60615+ int (* const unit_num) (struct virtual_item * vi);
60616+ void (* const print_vi) (struct virtual_item * vi);
60617 };
60618
60619-extern struct item_operations *item_ops[TYPE_ANY + 1];
60620+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
60621
60622 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
60623 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
60624diff -urNp linux-2.6.32.44/include/linux/reiserfs_fs_sb.h linux-2.6.32.44/include/linux/reiserfs_fs_sb.h
60625--- linux-2.6.32.44/include/linux/reiserfs_fs_sb.h 2011-03-27 14:31:47.000000000 -0400
60626+++ linux-2.6.32.44/include/linux/reiserfs_fs_sb.h 2011-04-17 15:56:46.000000000 -0400
60627@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
60628 /* Comment? -Hans */
60629 wait_queue_head_t s_wait;
60630 /* To be obsoleted soon by per buffer seals.. -Hans */
60631- atomic_t s_generation_counter; // increased by one every time the
60632+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60633 // tree gets re-balanced
60634 unsigned long s_properties; /* File system properties. Currently holds
60635 on-disk FS format */
60636diff -urNp linux-2.6.32.44/include/linux/relay.h linux-2.6.32.44/include/linux/relay.h
60637--- linux-2.6.32.44/include/linux/relay.h 2011-03-27 14:31:47.000000000 -0400
60638+++ linux-2.6.32.44/include/linux/relay.h 2011-08-05 20:33:55.000000000 -0400
60639@@ -159,7 +159,7 @@ struct rchan_callbacks
60640 * The callback should return 0 if successful, negative if not.
60641 */
60642 int (*remove_buf_file)(struct dentry *dentry);
60643-};
60644+} __no_const;
60645
60646 /*
60647 * CONFIG_RELAY kernel API, kernel/relay.c
60648diff -urNp linux-2.6.32.44/include/linux/sched.h linux-2.6.32.44/include/linux/sched.h
60649--- linux-2.6.32.44/include/linux/sched.h 2011-03-27 14:31:47.000000000 -0400
60650+++ linux-2.6.32.44/include/linux/sched.h 2011-08-11 19:48:55.000000000 -0400
60651@@ -101,6 +101,7 @@ struct bio;
60652 struct fs_struct;
60653 struct bts_context;
60654 struct perf_event_context;
60655+struct linux_binprm;
60656
60657 /*
60658 * List of flags we want to share for kernel threads,
60659@@ -350,7 +351,7 @@ extern signed long schedule_timeout_kill
60660 extern signed long schedule_timeout_uninterruptible(signed long timeout);
60661 asmlinkage void __schedule(void);
60662 asmlinkage void schedule(void);
60663-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
60664+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
60665
60666 struct nsproxy;
60667 struct user_namespace;
60668@@ -371,9 +372,12 @@ struct user_namespace;
60669 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
60670
60671 extern int sysctl_max_map_count;
60672+extern unsigned long sysctl_heap_stack_gap;
60673
60674 #include <linux/aio.h>
60675
60676+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
60677+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
60678 extern unsigned long
60679 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
60680 unsigned long, unsigned long);
60681@@ -666,6 +670,16 @@ struct signal_struct {
60682 struct tty_audit_buf *tty_audit_buf;
60683 #endif
60684
60685+#ifdef CONFIG_GRKERNSEC
60686+ u32 curr_ip;
60687+ u32 saved_ip;
60688+ u32 gr_saddr;
60689+ u32 gr_daddr;
60690+ u16 gr_sport;
60691+ u16 gr_dport;
60692+ u8 used_accept:1;
60693+#endif
60694+
60695 int oom_adj; /* OOM kill score adjustment (bit shift) */
60696 };
60697
60698@@ -723,6 +737,11 @@ struct user_struct {
60699 struct key *session_keyring; /* UID's default session keyring */
60700 #endif
60701
60702+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60703+ unsigned int banned;
60704+ unsigned long ban_expires;
60705+#endif
60706+
60707 /* Hash table maintenance information */
60708 struct hlist_node uidhash_node;
60709 uid_t uid;
60710@@ -1328,8 +1347,8 @@ struct task_struct {
60711 struct list_head thread_group;
60712
60713 struct completion *vfork_done; /* for vfork() */
60714- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
60715- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60716+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
60717+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60718
60719 cputime_t utime, stime, utimescaled, stimescaled;
60720 cputime_t gtime;
60721@@ -1343,16 +1362,6 @@ struct task_struct {
60722 struct task_cputime cputime_expires;
60723 struct list_head cpu_timers[3];
60724
60725-/* process credentials */
60726- const struct cred *real_cred; /* objective and real subjective task
60727- * credentials (COW) */
60728- const struct cred *cred; /* effective (overridable) subjective task
60729- * credentials (COW) */
60730- struct mutex cred_guard_mutex; /* guard against foreign influences on
60731- * credential calculations
60732- * (notably. ptrace) */
60733- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60734-
60735 char comm[TASK_COMM_LEN]; /* executable name excluding path
60736 - access with [gs]et_task_comm (which lock
60737 it with task_lock())
60738@@ -1369,6 +1378,10 @@ struct task_struct {
60739 #endif
60740 /* CPU-specific state of this task */
60741 struct thread_struct thread;
60742+/* thread_info moved to task_struct */
60743+#ifdef CONFIG_X86
60744+ struct thread_info tinfo;
60745+#endif
60746 /* filesystem information */
60747 struct fs_struct *fs;
60748 /* open file information */
60749@@ -1436,6 +1449,15 @@ struct task_struct {
60750 int hardirq_context;
60751 int softirq_context;
60752 #endif
60753+
60754+/* process credentials */
60755+ const struct cred *real_cred; /* objective and real subjective task
60756+ * credentials (COW) */
60757+ struct mutex cred_guard_mutex; /* guard against foreign influences on
60758+ * credential calculations
60759+ * (notably. ptrace) */
60760+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60761+
60762 #ifdef CONFIG_LOCKDEP
60763 # define MAX_LOCK_DEPTH 48UL
60764 u64 curr_chain_key;
60765@@ -1456,6 +1478,9 @@ struct task_struct {
60766
60767 struct backing_dev_info *backing_dev_info;
60768
60769+ const struct cred *cred; /* effective (overridable) subjective task
60770+ * credentials (COW) */
60771+
60772 struct io_context *io_context;
60773
60774 unsigned long ptrace_message;
60775@@ -1519,6 +1544,21 @@ struct task_struct {
60776 unsigned long default_timer_slack_ns;
60777
60778 struct list_head *scm_work_list;
60779+
60780+#ifdef CONFIG_GRKERNSEC
60781+ /* grsecurity */
60782+ struct dentry *gr_chroot_dentry;
60783+ struct acl_subject_label *acl;
60784+ struct acl_role_label *role;
60785+ struct file *exec_file;
60786+ u16 acl_role_id;
60787+ /* is this the task that authenticated to the special role */
60788+ u8 acl_sp_role;
60789+ u8 is_writable;
60790+ u8 brute;
60791+ u8 gr_is_chrooted;
60792+#endif
60793+
60794 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60795 /* Index of current stored adress in ret_stack */
60796 int curr_ret_stack;
60797@@ -1542,6 +1582,57 @@ struct task_struct {
60798 #endif /* CONFIG_TRACING */
60799 };
60800
60801+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
60802+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
60803+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
60804+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
60805+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
60806+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
60807+
60808+#ifdef CONFIG_PAX_SOFTMODE
60809+extern int pax_softmode;
60810+#endif
60811+
60812+extern int pax_check_flags(unsigned long *);
60813+
60814+/* if tsk != current then task_lock must be held on it */
60815+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60816+static inline unsigned long pax_get_flags(struct task_struct *tsk)
60817+{
60818+ if (likely(tsk->mm))
60819+ return tsk->mm->pax_flags;
60820+ else
60821+ return 0UL;
60822+}
60823+
60824+/* if tsk != current then task_lock must be held on it */
60825+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
60826+{
60827+ if (likely(tsk->mm)) {
60828+ tsk->mm->pax_flags = flags;
60829+ return 0;
60830+ }
60831+ return -EINVAL;
60832+}
60833+#endif
60834+
60835+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60836+extern void pax_set_initial_flags(struct linux_binprm *bprm);
60837+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60838+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60839+#endif
60840+
60841+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
60842+extern void pax_report_insns(void *pc, void *sp);
60843+extern void pax_report_refcount_overflow(struct pt_regs *regs);
60844+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
60845+
60846+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
60847+extern void pax_track_stack(void);
60848+#else
60849+static inline void pax_track_stack(void) {}
60850+#endif
60851+
60852 /* Future-safe accessor for struct task_struct's cpus_allowed. */
60853 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
60854
60855@@ -1740,7 +1831,7 @@ extern void thread_group_times(struct ta
60856 #define PF_DUMPCORE 0x00000200 /* dumped core */
60857 #define PF_SIGNALED 0x00000400 /* killed by a signal */
60858 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
60859-#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
60860+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
60861 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
60862 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
60863 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
60864@@ -1978,7 +2069,9 @@ void yield(void);
60865 extern struct exec_domain default_exec_domain;
60866
60867 union thread_union {
60868+#ifndef CONFIG_X86
60869 struct thread_info thread_info;
60870+#endif
60871 unsigned long stack[THREAD_SIZE/sizeof(long)];
60872 };
60873
60874@@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
60875 */
60876
60877 extern struct task_struct *find_task_by_vpid(pid_t nr);
60878+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
60879 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
60880 struct pid_namespace *ns);
60881
60882@@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sig
60883 extern void exit_itimers(struct signal_struct *);
60884 extern void flush_itimer_signals(void);
60885
60886-extern NORET_TYPE void do_group_exit(int);
60887+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
60888
60889 extern void daemonize(const char *, ...);
60890 extern int allow_signal(int);
60891@@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stac
60892
60893 #endif
60894
60895-static inline int object_is_on_stack(void *obj)
60896+static inline int object_starts_on_stack(void *obj)
60897 {
60898- void *stack = task_stack_page(current);
60899+ const void *stack = task_stack_page(current);
60900
60901 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
60902 }
60903
60904+#ifdef CONFIG_PAX_USERCOPY
60905+extern int object_is_on_stack(const void *obj, unsigned long len);
60906+#endif
60907+
60908 extern void thread_info_cache_init(void);
60909
60910 #ifdef CONFIG_DEBUG_STACK_USAGE
60911diff -urNp linux-2.6.32.44/include/linux/screen_info.h linux-2.6.32.44/include/linux/screen_info.h
60912--- linux-2.6.32.44/include/linux/screen_info.h 2011-03-27 14:31:47.000000000 -0400
60913+++ linux-2.6.32.44/include/linux/screen_info.h 2011-04-17 15:56:46.000000000 -0400
60914@@ -42,7 +42,8 @@ struct screen_info {
60915 __u16 pages; /* 0x32 */
60916 __u16 vesa_attributes; /* 0x34 */
60917 __u32 capabilities; /* 0x36 */
60918- __u8 _reserved[6]; /* 0x3a */
60919+ __u16 vesapm_size; /* 0x3a */
60920+ __u8 _reserved[4]; /* 0x3c */
60921 } __attribute__((packed));
60922
60923 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
60924diff -urNp linux-2.6.32.44/include/linux/security.h linux-2.6.32.44/include/linux/security.h
60925--- linux-2.6.32.44/include/linux/security.h 2011-03-27 14:31:47.000000000 -0400
60926+++ linux-2.6.32.44/include/linux/security.h 2011-04-17 15:56:46.000000000 -0400
60927@@ -34,6 +34,7 @@
60928 #include <linux/key.h>
60929 #include <linux/xfrm.h>
60930 #include <linux/gfp.h>
60931+#include <linux/grsecurity.h>
60932 #include <net/flow.h>
60933
60934 /* Maximum number of letters for an LSM name string */
60935diff -urNp linux-2.6.32.44/include/linux/shm.h linux-2.6.32.44/include/linux/shm.h
60936--- linux-2.6.32.44/include/linux/shm.h 2011-03-27 14:31:47.000000000 -0400
60937+++ linux-2.6.32.44/include/linux/shm.h 2011-04-17 15:56:46.000000000 -0400
60938@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
60939 pid_t shm_cprid;
60940 pid_t shm_lprid;
60941 struct user_struct *mlock_user;
60942+#ifdef CONFIG_GRKERNSEC
60943+ time_t shm_createtime;
60944+ pid_t shm_lapid;
60945+#endif
60946 };
60947
60948 /* shm_mode upper byte flags */
60949diff -urNp linux-2.6.32.44/include/linux/skbuff.h linux-2.6.32.44/include/linux/skbuff.h
60950--- linux-2.6.32.44/include/linux/skbuff.h 2011-03-27 14:31:47.000000000 -0400
60951+++ linux-2.6.32.44/include/linux/skbuff.h 2011-07-06 19:53:33.000000000 -0400
60952@@ -544,7 +544,7 @@ static inline union skb_shared_tx *skb_t
60953 */
60954 static inline int skb_queue_empty(const struct sk_buff_head *list)
60955 {
60956- return list->next == (struct sk_buff *)list;
60957+ return list->next == (const struct sk_buff *)list;
60958 }
60959
60960 /**
60961@@ -557,7 +557,7 @@ static inline int skb_queue_empty(const
60962 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60963 const struct sk_buff *skb)
60964 {
60965- return (skb->next == (struct sk_buff *) list);
60966+ return (skb->next == (const struct sk_buff *) list);
60967 }
60968
60969 /**
60970@@ -570,7 +570,7 @@ static inline bool skb_queue_is_last(con
60971 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
60972 const struct sk_buff *skb)
60973 {
60974- return (skb->prev == (struct sk_buff *) list);
60975+ return (skb->prev == (const struct sk_buff *) list);
60976 }
60977
60978 /**
60979@@ -1367,7 +1367,7 @@ static inline int skb_network_offset(con
60980 * headroom, you should not reduce this.
60981 */
60982 #ifndef NET_SKB_PAD
60983-#define NET_SKB_PAD 32
60984+#define NET_SKB_PAD (_AC(32,UL))
60985 #endif
60986
60987 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
60988diff -urNp linux-2.6.32.44/include/linux/slab_def.h linux-2.6.32.44/include/linux/slab_def.h
60989--- linux-2.6.32.44/include/linux/slab_def.h 2011-03-27 14:31:47.000000000 -0400
60990+++ linux-2.6.32.44/include/linux/slab_def.h 2011-05-04 17:56:28.000000000 -0400
60991@@ -69,10 +69,10 @@ struct kmem_cache {
60992 unsigned long node_allocs;
60993 unsigned long node_frees;
60994 unsigned long node_overflow;
60995- atomic_t allochit;
60996- atomic_t allocmiss;
60997- atomic_t freehit;
60998- atomic_t freemiss;
60999+ atomic_unchecked_t allochit;
61000+ atomic_unchecked_t allocmiss;
61001+ atomic_unchecked_t freehit;
61002+ atomic_unchecked_t freemiss;
61003
61004 /*
61005 * If debugging is enabled, then the allocator can add additional
61006diff -urNp linux-2.6.32.44/include/linux/slab.h linux-2.6.32.44/include/linux/slab.h
61007--- linux-2.6.32.44/include/linux/slab.h 2011-03-27 14:31:47.000000000 -0400
61008+++ linux-2.6.32.44/include/linux/slab.h 2011-04-17 15:56:46.000000000 -0400
61009@@ -11,12 +11,20 @@
61010
61011 #include <linux/gfp.h>
61012 #include <linux/types.h>
61013+#include <linux/err.h>
61014
61015 /*
61016 * Flags to pass to kmem_cache_create().
61017 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
61018 */
61019 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
61020+
61021+#ifdef CONFIG_PAX_USERCOPY
61022+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
61023+#else
61024+#define SLAB_USERCOPY 0x00000000UL
61025+#endif
61026+
61027 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
61028 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
61029 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
61030@@ -82,10 +90,13 @@
61031 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
61032 * Both make kfree a no-op.
61033 */
61034-#define ZERO_SIZE_PTR ((void *)16)
61035+#define ZERO_SIZE_PTR \
61036+({ \
61037+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
61038+ (void *)(-MAX_ERRNO-1L); \
61039+})
61040
61041-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
61042- (unsigned long)ZERO_SIZE_PTR)
61043+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
61044
61045 /*
61046 * struct kmem_cache related prototypes
61047@@ -138,6 +149,7 @@ void * __must_check krealloc(const void
61048 void kfree(const void *);
61049 void kzfree(const void *);
61050 size_t ksize(const void *);
61051+void check_object_size(const void *ptr, unsigned long n, bool to);
61052
61053 /*
61054 * Allocator specific definitions. These are mainly used to establish optimized
61055@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t
61056
61057 void __init kmem_cache_init_late(void);
61058
61059+#define kmalloc(x, y) \
61060+({ \
61061+ void *___retval; \
61062+ intoverflow_t ___x = (intoverflow_t)x; \
61063+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
61064+ ___retval = NULL; \
61065+ else \
61066+ ___retval = kmalloc((size_t)___x, (y)); \
61067+ ___retval; \
61068+})
61069+
61070+#define kmalloc_node(x, y, z) \
61071+({ \
61072+ void *___retval; \
61073+ intoverflow_t ___x = (intoverflow_t)x; \
61074+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
61075+ ___retval = NULL; \
61076+ else \
61077+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
61078+ ___retval; \
61079+})
61080+
61081+#define kzalloc(x, y) \
61082+({ \
61083+ void *___retval; \
61084+ intoverflow_t ___x = (intoverflow_t)x; \
61085+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
61086+ ___retval = NULL; \
61087+ else \
61088+ ___retval = kzalloc((size_t)___x, (y)); \
61089+ ___retval; \
61090+})
61091+
61092 #endif /* _LINUX_SLAB_H */
61093diff -urNp linux-2.6.32.44/include/linux/slub_def.h linux-2.6.32.44/include/linux/slub_def.h
61094--- linux-2.6.32.44/include/linux/slub_def.h 2011-03-27 14:31:47.000000000 -0400
61095+++ linux-2.6.32.44/include/linux/slub_def.h 2011-08-05 20:33:55.000000000 -0400
61096@@ -86,7 +86,7 @@ struct kmem_cache {
61097 struct kmem_cache_order_objects max;
61098 struct kmem_cache_order_objects min;
61099 gfp_t allocflags; /* gfp flags to use on each alloc */
61100- int refcount; /* Refcount for slab cache destroy */
61101+ atomic_t refcount; /* Refcount for slab cache destroy */
61102 void (*ctor)(void *);
61103 int inuse; /* Offset to metadata */
61104 int align; /* Alignment */
61105@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache
61106 #endif
61107
61108 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
61109-void *__kmalloc(size_t size, gfp_t flags);
61110+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
61111
61112 #ifdef CONFIG_KMEMTRACE
61113 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
61114diff -urNp linux-2.6.32.44/include/linux/sonet.h linux-2.6.32.44/include/linux/sonet.h
61115--- linux-2.6.32.44/include/linux/sonet.h 2011-03-27 14:31:47.000000000 -0400
61116+++ linux-2.6.32.44/include/linux/sonet.h 2011-04-17 15:56:46.000000000 -0400
61117@@ -61,7 +61,7 @@ struct sonet_stats {
61118 #include <asm/atomic.h>
61119
61120 struct k_sonet_stats {
61121-#define __HANDLE_ITEM(i) atomic_t i
61122+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61123 __SONET_ITEMS
61124 #undef __HANDLE_ITEM
61125 };
61126diff -urNp linux-2.6.32.44/include/linux/sunrpc/cache.h linux-2.6.32.44/include/linux/sunrpc/cache.h
61127--- linux-2.6.32.44/include/linux/sunrpc/cache.h 2011-03-27 14:31:47.000000000 -0400
61128+++ linux-2.6.32.44/include/linux/sunrpc/cache.h 2011-08-05 20:33:55.000000000 -0400
61129@@ -125,7 +125,7 @@ struct cache_detail {
61130 */
61131 struct cache_req {
61132 struct cache_deferred_req *(*defer)(struct cache_req *req);
61133-};
61134+} __no_const;
61135 /* this must be embedded in a deferred_request that is being
61136 * delayed awaiting cache-fill
61137 */
61138diff -urNp linux-2.6.32.44/include/linux/sunrpc/clnt.h linux-2.6.32.44/include/linux/sunrpc/clnt.h
61139--- linux-2.6.32.44/include/linux/sunrpc/clnt.h 2011-03-27 14:31:47.000000000 -0400
61140+++ linux-2.6.32.44/include/linux/sunrpc/clnt.h 2011-04-17 15:56:46.000000000 -0400
61141@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_por
61142 {
61143 switch (sap->sa_family) {
61144 case AF_INET:
61145- return ntohs(((struct sockaddr_in *)sap)->sin_port);
61146+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
61147 case AF_INET6:
61148- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
61149+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
61150 }
61151 return 0;
61152 }
61153@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const
61154 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
61155 const struct sockaddr *src)
61156 {
61157- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
61158+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
61159 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
61160
61161 dsin->sin_family = ssin->sin_family;
61162@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const
61163 if (sa->sa_family != AF_INET6)
61164 return 0;
61165
61166- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
61167+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
61168 }
61169
61170 #endif /* __KERNEL__ */
61171diff -urNp linux-2.6.32.44/include/linux/sunrpc/svc_rdma.h linux-2.6.32.44/include/linux/sunrpc/svc_rdma.h
61172--- linux-2.6.32.44/include/linux/sunrpc/svc_rdma.h 2011-03-27 14:31:47.000000000 -0400
61173+++ linux-2.6.32.44/include/linux/sunrpc/svc_rdma.h 2011-05-04 17:56:28.000000000 -0400
61174@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
61175 extern unsigned int svcrdma_max_requests;
61176 extern unsigned int svcrdma_max_req_size;
61177
61178-extern atomic_t rdma_stat_recv;
61179-extern atomic_t rdma_stat_read;
61180-extern atomic_t rdma_stat_write;
61181-extern atomic_t rdma_stat_sq_starve;
61182-extern atomic_t rdma_stat_rq_starve;
61183-extern atomic_t rdma_stat_rq_poll;
61184-extern atomic_t rdma_stat_rq_prod;
61185-extern atomic_t rdma_stat_sq_poll;
61186-extern atomic_t rdma_stat_sq_prod;
61187+extern atomic_unchecked_t rdma_stat_recv;
61188+extern atomic_unchecked_t rdma_stat_read;
61189+extern atomic_unchecked_t rdma_stat_write;
61190+extern atomic_unchecked_t rdma_stat_sq_starve;
61191+extern atomic_unchecked_t rdma_stat_rq_starve;
61192+extern atomic_unchecked_t rdma_stat_rq_poll;
61193+extern atomic_unchecked_t rdma_stat_rq_prod;
61194+extern atomic_unchecked_t rdma_stat_sq_poll;
61195+extern atomic_unchecked_t rdma_stat_sq_prod;
61196
61197 #define RPCRDMA_VERSION 1
61198
61199diff -urNp linux-2.6.32.44/include/linux/suspend.h linux-2.6.32.44/include/linux/suspend.h
61200--- linux-2.6.32.44/include/linux/suspend.h 2011-03-27 14:31:47.000000000 -0400
61201+++ linux-2.6.32.44/include/linux/suspend.h 2011-04-17 15:56:46.000000000 -0400
61202@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
61203 * which require special recovery actions in that situation.
61204 */
61205 struct platform_suspend_ops {
61206- int (*valid)(suspend_state_t state);
61207- int (*begin)(suspend_state_t state);
61208- int (*prepare)(void);
61209- int (*prepare_late)(void);
61210- int (*enter)(suspend_state_t state);
61211- void (*wake)(void);
61212- void (*finish)(void);
61213- void (*end)(void);
61214- void (*recover)(void);
61215+ int (* const valid)(suspend_state_t state);
61216+ int (* const begin)(suspend_state_t state);
61217+ int (* const prepare)(void);
61218+ int (* const prepare_late)(void);
61219+ int (* const enter)(suspend_state_t state);
61220+ void (* const wake)(void);
61221+ void (* const finish)(void);
61222+ void (* const end)(void);
61223+ void (* const recover)(void);
61224 };
61225
61226 #ifdef CONFIG_SUSPEND
61227@@ -120,7 +120,7 @@ struct platform_suspend_ops {
61228 * suspend_set_ops - set platform dependent suspend operations
61229 * @ops: The new suspend operations to set.
61230 */
61231-extern void suspend_set_ops(struct platform_suspend_ops *ops);
61232+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
61233 extern int suspend_valid_only_mem(suspend_state_t state);
61234
61235 /**
61236@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t st
61237 #else /* !CONFIG_SUSPEND */
61238 #define suspend_valid_only_mem NULL
61239
61240-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
61241+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
61242 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
61243 #endif /* !CONFIG_SUSPEND */
61244
61245@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone
61246 * platforms which require special recovery actions in that situation.
61247 */
61248 struct platform_hibernation_ops {
61249- int (*begin)(void);
61250- void (*end)(void);
61251- int (*pre_snapshot)(void);
61252- void (*finish)(void);
61253- int (*prepare)(void);
61254- int (*enter)(void);
61255- void (*leave)(void);
61256- int (*pre_restore)(void);
61257- void (*restore_cleanup)(void);
61258- void (*recover)(void);
61259+ int (* const begin)(void);
61260+ void (* const end)(void);
61261+ int (* const pre_snapshot)(void);
61262+ void (* const finish)(void);
61263+ int (* const prepare)(void);
61264+ int (* const enter)(void);
61265+ void (* const leave)(void);
61266+ int (* const pre_restore)(void);
61267+ void (* const restore_cleanup)(void);
61268+ void (* const recover)(void);
61269 };
61270
61271 #ifdef CONFIG_HIBERNATION
61272@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct
61273 extern void swsusp_unset_page_free(struct page *);
61274 extern unsigned long get_safe_page(gfp_t gfp_mask);
61275
61276-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
61277+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
61278 extern int hibernate(void);
61279 extern bool system_entering_hibernation(void);
61280 #else /* CONFIG_HIBERNATION */
61281@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidd
61282 static inline void swsusp_set_page_free(struct page *p) {}
61283 static inline void swsusp_unset_page_free(struct page *p) {}
61284
61285-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
61286+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
61287 static inline int hibernate(void) { return -ENOSYS; }
61288 static inline bool system_entering_hibernation(void) { return false; }
61289 #endif /* CONFIG_HIBERNATION */
61290diff -urNp linux-2.6.32.44/include/linux/sysctl.h linux-2.6.32.44/include/linux/sysctl.h
61291--- linux-2.6.32.44/include/linux/sysctl.h 2011-03-27 14:31:47.000000000 -0400
61292+++ linux-2.6.32.44/include/linux/sysctl.h 2011-04-17 15:56:46.000000000 -0400
61293@@ -164,7 +164,11 @@ enum
61294 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
61295 };
61296
61297-
61298+#ifdef CONFIG_PAX_SOFTMODE
61299+enum {
61300+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
61301+};
61302+#endif
61303
61304 /* CTL_VM names: */
61305 enum
61306@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_tab
61307
61308 extern int proc_dostring(struct ctl_table *, int,
61309 void __user *, size_t *, loff_t *);
61310+extern int proc_dostring_modpriv(struct ctl_table *, int,
61311+ void __user *, size_t *, loff_t *);
61312 extern int proc_dointvec(struct ctl_table *, int,
61313 void __user *, size_t *, loff_t *);
61314 extern int proc_dointvec_minmax(struct ctl_table *, int,
61315@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name,
61316
61317 extern ctl_handler sysctl_data;
61318 extern ctl_handler sysctl_string;
61319+extern ctl_handler sysctl_string_modpriv;
61320 extern ctl_handler sysctl_intvec;
61321 extern ctl_handler sysctl_jiffies;
61322 extern ctl_handler sysctl_ms_jiffies;
61323diff -urNp linux-2.6.32.44/include/linux/sysfs.h linux-2.6.32.44/include/linux/sysfs.h
61324--- linux-2.6.32.44/include/linux/sysfs.h 2011-03-27 14:31:47.000000000 -0400
61325+++ linux-2.6.32.44/include/linux/sysfs.h 2011-04-17 15:56:46.000000000 -0400
61326@@ -75,8 +75,8 @@ struct bin_attribute {
61327 };
61328
61329 struct sysfs_ops {
61330- ssize_t (*show)(struct kobject *, struct attribute *,char *);
61331- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
61332+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
61333+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
61334 };
61335
61336 struct sysfs_dirent;
61337diff -urNp linux-2.6.32.44/include/linux/thread_info.h linux-2.6.32.44/include/linux/thread_info.h
61338--- linux-2.6.32.44/include/linux/thread_info.h 2011-03-27 14:31:47.000000000 -0400
61339+++ linux-2.6.32.44/include/linux/thread_info.h 2011-04-17 15:56:46.000000000 -0400
61340@@ -23,7 +23,7 @@ struct restart_block {
61341 };
61342 /* For futex_wait and futex_wait_requeue_pi */
61343 struct {
61344- u32 *uaddr;
61345+ u32 __user *uaddr;
61346 u32 val;
61347 u32 flags;
61348 u32 bitset;
61349diff -urNp linux-2.6.32.44/include/linux/tty.h linux-2.6.32.44/include/linux/tty.h
61350--- linux-2.6.32.44/include/linux/tty.h 2011-03-27 14:31:47.000000000 -0400
61351+++ linux-2.6.32.44/include/linux/tty.h 2011-08-05 20:33:55.000000000 -0400
61352@@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
61353 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
61354 extern void tty_ldisc_enable(struct tty_struct *tty);
61355
61356-
61357 /* n_tty.c */
61358 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
61359
61360diff -urNp linux-2.6.32.44/include/linux/tty_ldisc.h linux-2.6.32.44/include/linux/tty_ldisc.h
61361--- linux-2.6.32.44/include/linux/tty_ldisc.h 2011-03-27 14:31:47.000000000 -0400
61362+++ linux-2.6.32.44/include/linux/tty_ldisc.h 2011-04-17 15:56:46.000000000 -0400
61363@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
61364
61365 struct module *owner;
61366
61367- int refcount;
61368+ atomic_t refcount;
61369 };
61370
61371 struct tty_ldisc {
61372diff -urNp linux-2.6.32.44/include/linux/types.h linux-2.6.32.44/include/linux/types.h
61373--- linux-2.6.32.44/include/linux/types.h 2011-03-27 14:31:47.000000000 -0400
61374+++ linux-2.6.32.44/include/linux/types.h 2011-04-17 15:56:46.000000000 -0400
61375@@ -191,10 +191,26 @@ typedef struct {
61376 volatile int counter;
61377 } atomic_t;
61378
61379+#ifdef CONFIG_PAX_REFCOUNT
61380+typedef struct {
61381+ volatile int counter;
61382+} atomic_unchecked_t;
61383+#else
61384+typedef atomic_t atomic_unchecked_t;
61385+#endif
61386+
61387 #ifdef CONFIG_64BIT
61388 typedef struct {
61389 volatile long counter;
61390 } atomic64_t;
61391+
61392+#ifdef CONFIG_PAX_REFCOUNT
61393+typedef struct {
61394+ volatile long counter;
61395+} atomic64_unchecked_t;
61396+#else
61397+typedef atomic64_t atomic64_unchecked_t;
61398+#endif
61399 #endif
61400
61401 struct ustat {
61402diff -urNp linux-2.6.32.44/include/linux/uaccess.h linux-2.6.32.44/include/linux/uaccess.h
61403--- linux-2.6.32.44/include/linux/uaccess.h 2011-03-27 14:31:47.000000000 -0400
61404+++ linux-2.6.32.44/include/linux/uaccess.h 2011-04-17 15:56:46.000000000 -0400
61405@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
61406 long ret; \
61407 mm_segment_t old_fs = get_fs(); \
61408 \
61409- set_fs(KERNEL_DS); \
61410 pagefault_disable(); \
61411+ set_fs(KERNEL_DS); \
61412 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
61413- pagefault_enable(); \
61414 set_fs(old_fs); \
61415+ pagefault_enable(); \
61416 ret; \
61417 })
61418
61419@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_
61420 * Safely read from address @src to the buffer at @dst. If a kernel fault
61421 * happens, handle that and return -EFAULT.
61422 */
61423-extern long probe_kernel_read(void *dst, void *src, size_t size);
61424+extern long probe_kernel_read(void *dst, const void *src, size_t size);
61425
61426 /*
61427 * probe_kernel_write(): safely attempt to write to a location
61428@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst,
61429 * Safely write to address @dst from the buffer at @src. If a kernel fault
61430 * happens, handle that and return -EFAULT.
61431 */
61432-extern long probe_kernel_write(void *dst, void *src, size_t size);
61433+extern long probe_kernel_write(void *dst, const void *src, size_t size);
61434
61435 #endif /* __LINUX_UACCESS_H__ */
61436diff -urNp linux-2.6.32.44/include/linux/unaligned/access_ok.h linux-2.6.32.44/include/linux/unaligned/access_ok.h
61437--- linux-2.6.32.44/include/linux/unaligned/access_ok.h 2011-03-27 14:31:47.000000000 -0400
61438+++ linux-2.6.32.44/include/linux/unaligned/access_ok.h 2011-04-17 15:56:46.000000000 -0400
61439@@ -6,32 +6,32 @@
61440
61441 static inline u16 get_unaligned_le16(const void *p)
61442 {
61443- return le16_to_cpup((__le16 *)p);
61444+ return le16_to_cpup((const __le16 *)p);
61445 }
61446
61447 static inline u32 get_unaligned_le32(const void *p)
61448 {
61449- return le32_to_cpup((__le32 *)p);
61450+ return le32_to_cpup((const __le32 *)p);
61451 }
61452
61453 static inline u64 get_unaligned_le64(const void *p)
61454 {
61455- return le64_to_cpup((__le64 *)p);
61456+ return le64_to_cpup((const __le64 *)p);
61457 }
61458
61459 static inline u16 get_unaligned_be16(const void *p)
61460 {
61461- return be16_to_cpup((__be16 *)p);
61462+ return be16_to_cpup((const __be16 *)p);
61463 }
61464
61465 static inline u32 get_unaligned_be32(const void *p)
61466 {
61467- return be32_to_cpup((__be32 *)p);
61468+ return be32_to_cpup((const __be32 *)p);
61469 }
61470
61471 static inline u64 get_unaligned_be64(const void *p)
61472 {
61473- return be64_to_cpup((__be64 *)p);
61474+ return be64_to_cpup((const __be64 *)p);
61475 }
61476
61477 static inline void put_unaligned_le16(u16 val, void *p)
61478diff -urNp linux-2.6.32.44/include/linux/vmalloc.h linux-2.6.32.44/include/linux/vmalloc.h
61479--- linux-2.6.32.44/include/linux/vmalloc.h 2011-03-27 14:31:47.000000000 -0400
61480+++ linux-2.6.32.44/include/linux/vmalloc.h 2011-04-17 15:56:46.000000000 -0400
61481@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
61482 #define VM_MAP 0x00000004 /* vmap()ed pages */
61483 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
61484 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
61485+
61486+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
61487+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
61488+#endif
61489+
61490 /* bits [20..32] reserved for arch specific ioremap internals */
61491
61492 /*
61493@@ -123,4 +128,81 @@ struct vm_struct **pcpu_get_vm_areas(con
61494
61495 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
61496
61497+#define vmalloc(x) \
61498+({ \
61499+ void *___retval; \
61500+ intoverflow_t ___x = (intoverflow_t)x; \
61501+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
61502+ ___retval = NULL; \
61503+ else \
61504+ ___retval = vmalloc((unsigned long)___x); \
61505+ ___retval; \
61506+})
61507+
61508+#define __vmalloc(x, y, z) \
61509+({ \
61510+ void *___retval; \
61511+ intoverflow_t ___x = (intoverflow_t)x; \
61512+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
61513+ ___retval = NULL; \
61514+ else \
61515+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
61516+ ___retval; \
61517+})
61518+
61519+#define vmalloc_user(x) \
61520+({ \
61521+ void *___retval; \
61522+ intoverflow_t ___x = (intoverflow_t)x; \
61523+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
61524+ ___retval = NULL; \
61525+ else \
61526+ ___retval = vmalloc_user((unsigned long)___x); \
61527+ ___retval; \
61528+})
61529+
61530+#define vmalloc_exec(x) \
61531+({ \
61532+ void *___retval; \
61533+ intoverflow_t ___x = (intoverflow_t)x; \
61534+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
61535+ ___retval = NULL; \
61536+ else \
61537+ ___retval = vmalloc_exec((unsigned long)___x); \
61538+ ___retval; \
61539+})
61540+
61541+#define vmalloc_node(x, y) \
61542+({ \
61543+ void *___retval; \
61544+ intoverflow_t ___x = (intoverflow_t)x; \
61545+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
61546+ ___retval = NULL; \
61547+ else \
61548+ ___retval = vmalloc_node((unsigned long)___x, (y));\
61549+ ___retval; \
61550+})
61551+
61552+#define vmalloc_32(x) \
61553+({ \
61554+ void *___retval; \
61555+ intoverflow_t ___x = (intoverflow_t)x; \
61556+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
61557+ ___retval = NULL; \
61558+ else \
61559+ ___retval = vmalloc_32((unsigned long)___x); \
61560+ ___retval; \
61561+})
61562+
61563+#define vmalloc_32_user(x) \
61564+({ \
61565+ void *___retval; \
61566+ intoverflow_t ___x = (intoverflow_t)x; \
61567+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
61568+ ___retval = NULL; \
61569+ else \
61570+ ___retval = vmalloc_32_user((unsigned long)___x);\
61571+ ___retval; \
61572+})
61573+
61574 #endif /* _LINUX_VMALLOC_H */
61575diff -urNp linux-2.6.32.44/include/linux/vmstat.h linux-2.6.32.44/include/linux/vmstat.h
61576--- linux-2.6.32.44/include/linux/vmstat.h 2011-03-27 14:31:47.000000000 -0400
61577+++ linux-2.6.32.44/include/linux/vmstat.h 2011-04-17 15:56:46.000000000 -0400
61578@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(in
61579 /*
61580 * Zone based page accounting with per cpu differentials.
61581 */
61582-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61583+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61584
61585 static inline void zone_page_state_add(long x, struct zone *zone,
61586 enum zone_stat_item item)
61587 {
61588- atomic_long_add(x, &zone->vm_stat[item]);
61589- atomic_long_add(x, &vm_stat[item]);
61590+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
61591+ atomic_long_add_unchecked(x, &vm_stat[item]);
61592 }
61593
61594 static inline unsigned long global_page_state(enum zone_stat_item item)
61595 {
61596- long x = atomic_long_read(&vm_stat[item]);
61597+ long x = atomic_long_read_unchecked(&vm_stat[item]);
61598 #ifdef CONFIG_SMP
61599 if (x < 0)
61600 x = 0;
61601@@ -158,7 +158,7 @@ static inline unsigned long global_page_
61602 static inline unsigned long zone_page_state(struct zone *zone,
61603 enum zone_stat_item item)
61604 {
61605- long x = atomic_long_read(&zone->vm_stat[item]);
61606+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61607 #ifdef CONFIG_SMP
61608 if (x < 0)
61609 x = 0;
61610@@ -175,7 +175,7 @@ static inline unsigned long zone_page_st
61611 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
61612 enum zone_stat_item item)
61613 {
61614- long x = atomic_long_read(&zone->vm_stat[item]);
61615+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61616
61617 #ifdef CONFIG_SMP
61618 int cpu;
61619@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state
61620
61621 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
61622 {
61623- atomic_long_inc(&zone->vm_stat[item]);
61624- atomic_long_inc(&vm_stat[item]);
61625+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
61626+ atomic_long_inc_unchecked(&vm_stat[item]);
61627 }
61628
61629 static inline void __inc_zone_page_state(struct page *page,
61630@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state
61631
61632 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
61633 {
61634- atomic_long_dec(&zone->vm_stat[item]);
61635- atomic_long_dec(&vm_stat[item]);
61636+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
61637+ atomic_long_dec_unchecked(&vm_stat[item]);
61638 }
61639
61640 static inline void __dec_zone_page_state(struct page *page,
61641diff -urNp linux-2.6.32.44/include/media/v4l2-dev.h linux-2.6.32.44/include/media/v4l2-dev.h
61642--- linux-2.6.32.44/include/media/v4l2-dev.h 2011-03-27 14:31:47.000000000 -0400
61643+++ linux-2.6.32.44/include/media/v4l2-dev.h 2011-08-05 20:33:55.000000000 -0400
61644@@ -34,7 +34,7 @@ struct v4l2_device;
61645 #define V4L2_FL_UNREGISTERED (0)
61646
61647 struct v4l2_file_operations {
61648- struct module *owner;
61649+ struct module * const owner;
61650 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61651 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
61652 unsigned int (*poll) (struct file *, struct poll_table_struct *);
61653diff -urNp linux-2.6.32.44/include/media/v4l2-device.h linux-2.6.32.44/include/media/v4l2-device.h
61654--- linux-2.6.32.44/include/media/v4l2-device.h 2011-03-27 14:31:47.000000000 -0400
61655+++ linux-2.6.32.44/include/media/v4l2-device.h 2011-05-04 17:56:28.000000000 -0400
61656@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(st
61657 this function returns 0. If the name ends with a digit (e.g. cx18),
61658 then the name will be set to cx18-0 since cx180 looks really odd. */
61659 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
61660- atomic_t *instance);
61661+ atomic_unchecked_t *instance);
61662
61663 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
61664 Since the parent disappears this ensures that v4l2_dev doesn't have an
61665diff -urNp linux-2.6.32.44/include/net/flow.h linux-2.6.32.44/include/net/flow.h
61666--- linux-2.6.32.44/include/net/flow.h 2011-03-27 14:31:47.000000000 -0400
61667+++ linux-2.6.32.44/include/net/flow.h 2011-05-04 17:56:28.000000000 -0400
61668@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net
61669 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
61670 u8 dir, flow_resolve_t resolver);
61671 extern void flow_cache_flush(void);
61672-extern atomic_t flow_cache_genid;
61673+extern atomic_unchecked_t flow_cache_genid;
61674
61675 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
61676 {
61677diff -urNp linux-2.6.32.44/include/net/inetpeer.h linux-2.6.32.44/include/net/inetpeer.h
61678--- linux-2.6.32.44/include/net/inetpeer.h 2011-03-27 14:31:47.000000000 -0400
61679+++ linux-2.6.32.44/include/net/inetpeer.h 2011-04-17 15:56:46.000000000 -0400
61680@@ -24,7 +24,7 @@ struct inet_peer
61681 __u32 dtime; /* the time of last use of not
61682 * referenced entries */
61683 atomic_t refcnt;
61684- atomic_t rid; /* Frag reception counter */
61685+ atomic_unchecked_t rid; /* Frag reception counter */
61686 __u32 tcp_ts;
61687 unsigned long tcp_ts_stamp;
61688 };
61689diff -urNp linux-2.6.32.44/include/net/ip_vs.h linux-2.6.32.44/include/net/ip_vs.h
61690--- linux-2.6.32.44/include/net/ip_vs.h 2011-03-27 14:31:47.000000000 -0400
61691+++ linux-2.6.32.44/include/net/ip_vs.h 2011-05-04 17:56:28.000000000 -0400
61692@@ -365,7 +365,7 @@ struct ip_vs_conn {
61693 struct ip_vs_conn *control; /* Master control connection */
61694 atomic_t n_control; /* Number of controlled ones */
61695 struct ip_vs_dest *dest; /* real server */
61696- atomic_t in_pkts; /* incoming packet counter */
61697+ atomic_unchecked_t in_pkts; /* incoming packet counter */
61698
61699 /* packet transmitter for different forwarding methods. If it
61700 mangles the packet, it must return NF_DROP or better NF_STOLEN,
61701@@ -466,7 +466,7 @@ struct ip_vs_dest {
61702 union nf_inet_addr addr; /* IP address of the server */
61703 __be16 port; /* port number of the server */
61704 volatile unsigned flags; /* dest status flags */
61705- atomic_t conn_flags; /* flags to copy to conn */
61706+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
61707 atomic_t weight; /* server weight */
61708
61709 atomic_t refcnt; /* reference counter */
61710diff -urNp linux-2.6.32.44/include/net/irda/ircomm_core.h linux-2.6.32.44/include/net/irda/ircomm_core.h
61711--- linux-2.6.32.44/include/net/irda/ircomm_core.h 2011-03-27 14:31:47.000000000 -0400
61712+++ linux-2.6.32.44/include/net/irda/ircomm_core.h 2011-08-05 20:33:55.000000000 -0400
61713@@ -51,7 +51,7 @@ typedef struct {
61714 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
61715 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
61716 struct ircomm_info *);
61717-} call_t;
61718+} __no_const call_t;
61719
61720 struct ircomm_cb {
61721 irda_queue_t queue;
61722diff -urNp linux-2.6.32.44/include/net/irda/ircomm_tty.h linux-2.6.32.44/include/net/irda/ircomm_tty.h
61723--- linux-2.6.32.44/include/net/irda/ircomm_tty.h 2011-03-27 14:31:47.000000000 -0400
61724+++ linux-2.6.32.44/include/net/irda/ircomm_tty.h 2011-04-17 15:56:46.000000000 -0400
61725@@ -35,6 +35,7 @@
61726 #include <linux/termios.h>
61727 #include <linux/timer.h>
61728 #include <linux/tty.h> /* struct tty_struct */
61729+#include <asm/local.h>
61730
61731 #include <net/irda/irias_object.h>
61732 #include <net/irda/ircomm_core.h>
61733@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
61734 unsigned short close_delay;
61735 unsigned short closing_wait; /* time to wait before closing */
61736
61737- int open_count;
61738- int blocked_open; /* # of blocked opens */
61739+ local_t open_count;
61740+ local_t blocked_open; /* # of blocked opens */
61741
61742 /* Protect concurent access to :
61743 * o self->open_count
61744diff -urNp linux-2.6.32.44/include/net/iucv/af_iucv.h linux-2.6.32.44/include/net/iucv/af_iucv.h
61745--- linux-2.6.32.44/include/net/iucv/af_iucv.h 2011-03-27 14:31:47.000000000 -0400
61746+++ linux-2.6.32.44/include/net/iucv/af_iucv.h 2011-05-04 17:56:28.000000000 -0400
61747@@ -87,7 +87,7 @@ struct iucv_sock {
61748 struct iucv_sock_list {
61749 struct hlist_head head;
61750 rwlock_t lock;
61751- atomic_t autobind_name;
61752+ atomic_unchecked_t autobind_name;
61753 };
61754
61755 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
61756diff -urNp linux-2.6.32.44/include/net/lapb.h linux-2.6.32.44/include/net/lapb.h
61757--- linux-2.6.32.44/include/net/lapb.h 2011-03-27 14:31:47.000000000 -0400
61758+++ linux-2.6.32.44/include/net/lapb.h 2011-08-05 20:33:55.000000000 -0400
61759@@ -95,7 +95,7 @@ struct lapb_cb {
61760 struct sk_buff_head write_queue;
61761 struct sk_buff_head ack_queue;
61762 unsigned char window;
61763- struct lapb_register_struct callbacks;
61764+ struct lapb_register_struct *callbacks;
61765
61766 /* FRMR control information */
61767 struct lapb_frame frmr_data;
61768diff -urNp linux-2.6.32.44/include/net/neighbour.h linux-2.6.32.44/include/net/neighbour.h
61769--- linux-2.6.32.44/include/net/neighbour.h 2011-03-27 14:31:47.000000000 -0400
61770+++ linux-2.6.32.44/include/net/neighbour.h 2011-04-17 15:56:46.000000000 -0400
61771@@ -125,12 +125,12 @@ struct neighbour
61772 struct neigh_ops
61773 {
61774 int family;
61775- void (*solicit)(struct neighbour *, struct sk_buff*);
61776- void (*error_report)(struct neighbour *, struct sk_buff*);
61777- int (*output)(struct sk_buff*);
61778- int (*connected_output)(struct sk_buff*);
61779- int (*hh_output)(struct sk_buff*);
61780- int (*queue_xmit)(struct sk_buff*);
61781+ void (* const solicit)(struct neighbour *, struct sk_buff*);
61782+ void (* const error_report)(struct neighbour *, struct sk_buff*);
61783+ int (* const output)(struct sk_buff*);
61784+ int (* const connected_output)(struct sk_buff*);
61785+ int (* const hh_output)(struct sk_buff*);
61786+ int (* const queue_xmit)(struct sk_buff*);
61787 };
61788
61789 struct pneigh_entry
61790diff -urNp linux-2.6.32.44/include/net/netlink.h linux-2.6.32.44/include/net/netlink.h
61791--- linux-2.6.32.44/include/net/netlink.h 2011-07-13 17:23:04.000000000 -0400
61792+++ linux-2.6.32.44/include/net/netlink.h 2011-07-13 17:23:19.000000000 -0400
61793@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct
61794 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
61795 {
61796 if (mark)
61797- skb_trim(skb, (unsigned char *) mark - skb->data);
61798+ skb_trim(skb, (const unsigned char *) mark - skb->data);
61799 }
61800
61801 /**
61802diff -urNp linux-2.6.32.44/include/net/netns/ipv4.h linux-2.6.32.44/include/net/netns/ipv4.h
61803--- linux-2.6.32.44/include/net/netns/ipv4.h 2011-03-27 14:31:47.000000000 -0400
61804+++ linux-2.6.32.44/include/net/netns/ipv4.h 2011-05-04 17:56:28.000000000 -0400
61805@@ -54,7 +54,7 @@ struct netns_ipv4 {
61806 int current_rt_cache_rebuild_count;
61807
61808 struct timer_list rt_secret_timer;
61809- atomic_t rt_genid;
61810+ atomic_unchecked_t rt_genid;
61811
61812 #ifdef CONFIG_IP_MROUTE
61813 struct sock *mroute_sk;
61814diff -urNp linux-2.6.32.44/include/net/sctp/sctp.h linux-2.6.32.44/include/net/sctp/sctp.h
61815--- linux-2.6.32.44/include/net/sctp/sctp.h 2011-03-27 14:31:47.000000000 -0400
61816+++ linux-2.6.32.44/include/net/sctp/sctp.h 2011-04-17 15:56:46.000000000 -0400
61817@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
61818
61819 #else /* SCTP_DEBUG */
61820
61821-#define SCTP_DEBUG_PRINTK(whatever...)
61822-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
61823+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
61824+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
61825 #define SCTP_ENABLE_DEBUG
61826 #define SCTP_DISABLE_DEBUG
61827 #define SCTP_ASSERT(expr, str, func)
61828diff -urNp linux-2.6.32.44/include/net/secure_seq.h linux-2.6.32.44/include/net/secure_seq.h
61829--- linux-2.6.32.44/include/net/secure_seq.h 1969-12-31 19:00:00.000000000 -0500
61830+++ linux-2.6.32.44/include/net/secure_seq.h 2011-08-07 19:48:09.000000000 -0400
61831@@ -0,0 +1,20 @@
61832+#ifndef _NET_SECURE_SEQ
61833+#define _NET_SECURE_SEQ
61834+
61835+#include <linux/types.h>
61836+
61837+extern __u32 secure_ip_id(__be32 daddr);
61838+extern __u32 secure_ipv6_id(const __be32 daddr[4]);
61839+extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
61840+extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
61841+ __be16 dport);
61842+extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
61843+ __be16 sport, __be16 dport);
61844+extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
61845+ __be16 sport, __be16 dport);
61846+extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
61847+ __be16 sport, __be16 dport);
61848+extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
61849+ __be16 sport, __be16 dport);
61850+
61851+#endif /* _NET_SECURE_SEQ */
61852diff -urNp linux-2.6.32.44/include/net/sock.h linux-2.6.32.44/include/net/sock.h
61853--- linux-2.6.32.44/include/net/sock.h 2011-03-27 14:31:47.000000000 -0400
61854+++ linux-2.6.32.44/include/net/sock.h 2011-05-04 17:56:28.000000000 -0400
61855@@ -272,7 +272,7 @@ struct sock {
61856 rwlock_t sk_callback_lock;
61857 int sk_err,
61858 sk_err_soft;
61859- atomic_t sk_drops;
61860+ atomic_unchecked_t sk_drops;
61861 unsigned short sk_ack_backlog;
61862 unsigned short sk_max_ack_backlog;
61863 __u32 sk_priority;
61864diff -urNp linux-2.6.32.44/include/net/tcp.h linux-2.6.32.44/include/net/tcp.h
61865--- linux-2.6.32.44/include/net/tcp.h 2011-03-27 14:31:47.000000000 -0400
61866+++ linux-2.6.32.44/include/net/tcp.h 2011-04-17 15:56:46.000000000 -0400
61867@@ -1444,6 +1444,7 @@ enum tcp_seq_states {
61868 struct tcp_seq_afinfo {
61869 char *name;
61870 sa_family_t family;
61871+ /* cannot be const */
61872 struct file_operations seq_fops;
61873 struct seq_operations seq_ops;
61874 };
61875diff -urNp linux-2.6.32.44/include/net/udp.h linux-2.6.32.44/include/net/udp.h
61876--- linux-2.6.32.44/include/net/udp.h 2011-03-27 14:31:47.000000000 -0400
61877+++ linux-2.6.32.44/include/net/udp.h 2011-04-17 15:56:46.000000000 -0400
61878@@ -187,6 +187,7 @@ struct udp_seq_afinfo {
61879 char *name;
61880 sa_family_t family;
61881 struct udp_table *udp_table;
61882+ /* cannot be const */
61883 struct file_operations seq_fops;
61884 struct seq_operations seq_ops;
61885 };
61886diff -urNp linux-2.6.32.44/include/rdma/iw_cm.h linux-2.6.32.44/include/rdma/iw_cm.h
61887--- linux-2.6.32.44/include/rdma/iw_cm.h 2011-03-27 14:31:47.000000000 -0400
61888+++ linux-2.6.32.44/include/rdma/iw_cm.h 2011-08-05 20:33:55.000000000 -0400
61889@@ -129,7 +129,7 @@ struct iw_cm_verbs {
61890 int backlog);
61891
61892 int (*destroy_listen)(struct iw_cm_id *cm_id);
61893-};
61894+} __no_const;
61895
61896 /**
61897 * iw_create_cm_id - Create an IW CM identifier.
61898diff -urNp linux-2.6.32.44/include/scsi/scsi_device.h linux-2.6.32.44/include/scsi/scsi_device.h
61899--- linux-2.6.32.44/include/scsi/scsi_device.h 2011-04-17 17:00:52.000000000 -0400
61900+++ linux-2.6.32.44/include/scsi/scsi_device.h 2011-05-04 17:56:28.000000000 -0400
61901@@ -156,9 +156,9 @@ struct scsi_device {
61902 unsigned int max_device_blocked; /* what device_blocked counts down from */
61903 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
61904
61905- atomic_t iorequest_cnt;
61906- atomic_t iodone_cnt;
61907- atomic_t ioerr_cnt;
61908+ atomic_unchecked_t iorequest_cnt;
61909+ atomic_unchecked_t iodone_cnt;
61910+ atomic_unchecked_t ioerr_cnt;
61911
61912 struct device sdev_gendev,
61913 sdev_dev;
61914diff -urNp linux-2.6.32.44/include/scsi/scsi_transport_fc.h linux-2.6.32.44/include/scsi/scsi_transport_fc.h
61915--- linux-2.6.32.44/include/scsi/scsi_transport_fc.h 2011-03-27 14:31:47.000000000 -0400
61916+++ linux-2.6.32.44/include/scsi/scsi_transport_fc.h 2011-08-05 20:33:55.000000000 -0400
61917@@ -663,9 +663,9 @@ struct fc_function_template {
61918 int (*bsg_timeout)(struct fc_bsg_job *);
61919
61920 /* allocation lengths for host-specific data */
61921- u32 dd_fcrport_size;
61922- u32 dd_fcvport_size;
61923- u32 dd_bsg_size;
61924+ const u32 dd_fcrport_size;
61925+ const u32 dd_fcvport_size;
61926+ const u32 dd_bsg_size;
61927
61928 /*
61929 * The driver sets these to tell the transport class it
61930@@ -675,39 +675,39 @@ struct fc_function_template {
61931 */
61932
61933 /* remote port fixed attributes */
61934- unsigned long show_rport_maxframe_size:1;
61935- unsigned long show_rport_supported_classes:1;
61936- unsigned long show_rport_dev_loss_tmo:1;
61937+ const unsigned long show_rport_maxframe_size:1;
61938+ const unsigned long show_rport_supported_classes:1;
61939+ const unsigned long show_rport_dev_loss_tmo:1;
61940
61941 /*
61942 * target dynamic attributes
61943 * These should all be "1" if the driver uses the remote port
61944 * add/delete functions (so attributes reflect rport values).
61945 */
61946- unsigned long show_starget_node_name:1;
61947- unsigned long show_starget_port_name:1;
61948- unsigned long show_starget_port_id:1;
61949+ const unsigned long show_starget_node_name:1;
61950+ const unsigned long show_starget_port_name:1;
61951+ const unsigned long show_starget_port_id:1;
61952
61953 /* host fixed attributes */
61954- unsigned long show_host_node_name:1;
61955- unsigned long show_host_port_name:1;
61956- unsigned long show_host_permanent_port_name:1;
61957- unsigned long show_host_supported_classes:1;
61958- unsigned long show_host_supported_fc4s:1;
61959- unsigned long show_host_supported_speeds:1;
61960- unsigned long show_host_maxframe_size:1;
61961- unsigned long show_host_serial_number:1;
61962+ const unsigned long show_host_node_name:1;
61963+ const unsigned long show_host_port_name:1;
61964+ const unsigned long show_host_permanent_port_name:1;
61965+ const unsigned long show_host_supported_classes:1;
61966+ const unsigned long show_host_supported_fc4s:1;
61967+ const unsigned long show_host_supported_speeds:1;
61968+ const unsigned long show_host_maxframe_size:1;
61969+ const unsigned long show_host_serial_number:1;
61970 /* host dynamic attributes */
61971- unsigned long show_host_port_id:1;
61972- unsigned long show_host_port_type:1;
61973- unsigned long show_host_port_state:1;
61974- unsigned long show_host_active_fc4s:1;
61975- unsigned long show_host_speed:1;
61976- unsigned long show_host_fabric_name:1;
61977- unsigned long show_host_symbolic_name:1;
61978- unsigned long show_host_system_hostname:1;
61979+ const unsigned long show_host_port_id:1;
61980+ const unsigned long show_host_port_type:1;
61981+ const unsigned long show_host_port_state:1;
61982+ const unsigned long show_host_active_fc4s:1;
61983+ const unsigned long show_host_speed:1;
61984+ const unsigned long show_host_fabric_name:1;
61985+ const unsigned long show_host_symbolic_name:1;
61986+ const unsigned long show_host_system_hostname:1;
61987
61988- unsigned long disable_target_scan:1;
61989+ const unsigned long disable_target_scan:1;
61990 };
61991
61992
61993diff -urNp linux-2.6.32.44/include/sound/ac97_codec.h linux-2.6.32.44/include/sound/ac97_codec.h
61994--- linux-2.6.32.44/include/sound/ac97_codec.h 2011-03-27 14:31:47.000000000 -0400
61995+++ linux-2.6.32.44/include/sound/ac97_codec.h 2011-04-17 15:56:46.000000000 -0400
61996@@ -419,15 +419,15 @@
61997 struct snd_ac97;
61998
61999 struct snd_ac97_build_ops {
62000- int (*build_3d) (struct snd_ac97 *ac97);
62001- int (*build_specific) (struct snd_ac97 *ac97);
62002- int (*build_spdif) (struct snd_ac97 *ac97);
62003- int (*build_post_spdif) (struct snd_ac97 *ac97);
62004+ int (* const build_3d) (struct snd_ac97 *ac97);
62005+ int (* const build_specific) (struct snd_ac97 *ac97);
62006+ int (* const build_spdif) (struct snd_ac97 *ac97);
62007+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
62008 #ifdef CONFIG_PM
62009- void (*suspend) (struct snd_ac97 *ac97);
62010- void (*resume) (struct snd_ac97 *ac97);
62011+ void (* const suspend) (struct snd_ac97 *ac97);
62012+ void (* const resume) (struct snd_ac97 *ac97);
62013 #endif
62014- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
62015+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
62016 };
62017
62018 struct snd_ac97_bus_ops {
62019@@ -477,7 +477,7 @@ struct snd_ac97_template {
62020
62021 struct snd_ac97 {
62022 /* -- lowlevel (hardware) driver specific -- */
62023- struct snd_ac97_build_ops * build_ops;
62024+ const struct snd_ac97_build_ops * build_ops;
62025 void *private_data;
62026 void (*private_free) (struct snd_ac97 *ac97);
62027 /* --- */
62028diff -urNp linux-2.6.32.44/include/sound/ak4xxx-adda.h linux-2.6.32.44/include/sound/ak4xxx-adda.h
62029--- linux-2.6.32.44/include/sound/ak4xxx-adda.h 2011-03-27 14:31:47.000000000 -0400
62030+++ linux-2.6.32.44/include/sound/ak4xxx-adda.h 2011-08-05 20:33:55.000000000 -0400
62031@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
62032 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
62033 unsigned char val);
62034 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
62035-};
62036+} __no_const;
62037
62038 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
62039
62040diff -urNp linux-2.6.32.44/include/sound/hwdep.h linux-2.6.32.44/include/sound/hwdep.h
62041--- linux-2.6.32.44/include/sound/hwdep.h 2011-03-27 14:31:47.000000000 -0400
62042+++ linux-2.6.32.44/include/sound/hwdep.h 2011-08-05 20:33:55.000000000 -0400
62043@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
62044 struct snd_hwdep_dsp_status *status);
62045 int (*dsp_load)(struct snd_hwdep *hw,
62046 struct snd_hwdep_dsp_image *image);
62047-};
62048+} __no_const;
62049
62050 struct snd_hwdep {
62051 struct snd_card *card;
62052diff -urNp linux-2.6.32.44/include/sound/info.h linux-2.6.32.44/include/sound/info.h
62053--- linux-2.6.32.44/include/sound/info.h 2011-03-27 14:31:47.000000000 -0400
62054+++ linux-2.6.32.44/include/sound/info.h 2011-08-05 20:33:55.000000000 -0400
62055@@ -44,7 +44,7 @@ struct snd_info_entry_text {
62056 struct snd_info_buffer *buffer);
62057 void (*write)(struct snd_info_entry *entry,
62058 struct snd_info_buffer *buffer);
62059-};
62060+} __no_const;
62061
62062 struct snd_info_entry_ops {
62063 int (*open)(struct snd_info_entry *entry,
62064diff -urNp linux-2.6.32.44/include/sound/sb16_csp.h linux-2.6.32.44/include/sound/sb16_csp.h
62065--- linux-2.6.32.44/include/sound/sb16_csp.h 2011-03-27 14:31:47.000000000 -0400
62066+++ linux-2.6.32.44/include/sound/sb16_csp.h 2011-08-05 20:33:55.000000000 -0400
62067@@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
62068 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
62069 int (*csp_stop) (struct snd_sb_csp * p);
62070 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
62071-};
62072+} __no_const;
62073
62074 /*
62075 * CSP private data
62076diff -urNp linux-2.6.32.44/include/sound/ymfpci.h linux-2.6.32.44/include/sound/ymfpci.h
62077--- linux-2.6.32.44/include/sound/ymfpci.h 2011-03-27 14:31:47.000000000 -0400
62078+++ linux-2.6.32.44/include/sound/ymfpci.h 2011-05-04 17:56:28.000000000 -0400
62079@@ -358,7 +358,7 @@ struct snd_ymfpci {
62080 spinlock_t reg_lock;
62081 spinlock_t voice_lock;
62082 wait_queue_head_t interrupt_sleep;
62083- atomic_t interrupt_sleep_count;
62084+ atomic_unchecked_t interrupt_sleep_count;
62085 struct snd_info_entry *proc_entry;
62086 const struct firmware *dsp_microcode;
62087 const struct firmware *controller_microcode;
62088diff -urNp linux-2.6.32.44/include/trace/events/irq.h linux-2.6.32.44/include/trace/events/irq.h
62089--- linux-2.6.32.44/include/trace/events/irq.h 2011-03-27 14:31:47.000000000 -0400
62090+++ linux-2.6.32.44/include/trace/events/irq.h 2011-04-17 15:56:46.000000000 -0400
62091@@ -34,7 +34,7 @@
62092 */
62093 TRACE_EVENT(irq_handler_entry,
62094
62095- TP_PROTO(int irq, struct irqaction *action),
62096+ TP_PROTO(int irq, const struct irqaction *action),
62097
62098 TP_ARGS(irq, action),
62099
62100@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
62101 */
62102 TRACE_EVENT(irq_handler_exit,
62103
62104- TP_PROTO(int irq, struct irqaction *action, int ret),
62105+ TP_PROTO(int irq, const struct irqaction *action, int ret),
62106
62107 TP_ARGS(irq, action, ret),
62108
62109@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
62110 */
62111 TRACE_EVENT(softirq_entry,
62112
62113- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
62114+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
62115
62116 TP_ARGS(h, vec),
62117
62118@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
62119 */
62120 TRACE_EVENT(softirq_exit,
62121
62122- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
62123+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
62124
62125 TP_ARGS(h, vec),
62126
62127diff -urNp linux-2.6.32.44/include/video/uvesafb.h linux-2.6.32.44/include/video/uvesafb.h
62128--- linux-2.6.32.44/include/video/uvesafb.h 2011-03-27 14:31:47.000000000 -0400
62129+++ linux-2.6.32.44/include/video/uvesafb.h 2011-04-17 15:56:46.000000000 -0400
62130@@ -177,6 +177,7 @@ struct uvesafb_par {
62131 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
62132 u8 pmi_setpal; /* PMI for palette changes */
62133 u16 *pmi_base; /* protected mode interface location */
62134+ u8 *pmi_code; /* protected mode code location */
62135 void *pmi_start;
62136 void *pmi_pal;
62137 u8 *vbe_state_orig; /*
62138diff -urNp linux-2.6.32.44/init/do_mounts.c linux-2.6.32.44/init/do_mounts.c
62139--- linux-2.6.32.44/init/do_mounts.c 2011-03-27 14:31:47.000000000 -0400
62140+++ linux-2.6.32.44/init/do_mounts.c 2011-04-17 15:56:46.000000000 -0400
62141@@ -216,11 +216,11 @@ static void __init get_fs_names(char *pa
62142
62143 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
62144 {
62145- int err = sys_mount(name, "/root", fs, flags, data);
62146+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
62147 if (err)
62148 return err;
62149
62150- sys_chdir("/root");
62151+ sys_chdir((__force const char __user *)"/root");
62152 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
62153 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
62154 current->fs->pwd.mnt->mnt_sb->s_type->name,
62155@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...
62156 va_start(args, fmt);
62157 vsprintf(buf, fmt, args);
62158 va_end(args);
62159- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
62160+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
62161 if (fd >= 0) {
62162 sys_ioctl(fd, FDEJECT, 0);
62163 sys_close(fd);
62164 }
62165 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
62166- fd = sys_open("/dev/console", O_RDWR, 0);
62167+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
62168 if (fd >= 0) {
62169 sys_ioctl(fd, TCGETS, (long)&termios);
62170 termios.c_lflag &= ~ICANON;
62171 sys_ioctl(fd, TCSETSF, (long)&termios);
62172- sys_read(fd, &c, 1);
62173+ sys_read(fd, (char __user *)&c, 1);
62174 termios.c_lflag |= ICANON;
62175 sys_ioctl(fd, TCSETSF, (long)&termios);
62176 sys_close(fd);
62177@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
62178 mount_root();
62179 out:
62180 devtmpfs_mount("dev");
62181- sys_mount(".", "/", NULL, MS_MOVE, NULL);
62182- sys_chroot(".");
62183+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
62184+ sys_chroot((__force char __user *)".");
62185 }
62186diff -urNp linux-2.6.32.44/init/do_mounts.h linux-2.6.32.44/init/do_mounts.h
62187--- linux-2.6.32.44/init/do_mounts.h 2011-03-27 14:31:47.000000000 -0400
62188+++ linux-2.6.32.44/init/do_mounts.h 2011-04-17 15:56:46.000000000 -0400
62189@@ -15,15 +15,15 @@ extern int root_mountflags;
62190
62191 static inline int create_dev(char *name, dev_t dev)
62192 {
62193- sys_unlink(name);
62194- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
62195+ sys_unlink((__force char __user *)name);
62196+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
62197 }
62198
62199 #if BITS_PER_LONG == 32
62200 static inline u32 bstat(char *name)
62201 {
62202 struct stat64 stat;
62203- if (sys_stat64(name, &stat) != 0)
62204+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
62205 return 0;
62206 if (!S_ISBLK(stat.st_mode))
62207 return 0;
62208diff -urNp linux-2.6.32.44/init/do_mounts_initrd.c linux-2.6.32.44/init/do_mounts_initrd.c
62209--- linux-2.6.32.44/init/do_mounts_initrd.c 2011-03-27 14:31:47.000000000 -0400
62210+++ linux-2.6.32.44/init/do_mounts_initrd.c 2011-04-17 15:56:46.000000000 -0400
62211@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
62212 sys_close(old_fd);sys_close(root_fd);
62213 sys_close(0);sys_close(1);sys_close(2);
62214 sys_setsid();
62215- (void) sys_open("/dev/console",O_RDWR,0);
62216+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
62217 (void) sys_dup(0);
62218 (void) sys_dup(0);
62219 return kernel_execve(shell, argv, envp_init);
62220@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
62221 create_dev("/dev/root.old", Root_RAM0);
62222 /* mount initrd on rootfs' /root */
62223 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
62224- sys_mkdir("/old", 0700);
62225- root_fd = sys_open("/", 0, 0);
62226- old_fd = sys_open("/old", 0, 0);
62227+ sys_mkdir((__force const char __user *)"/old", 0700);
62228+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
62229+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
62230 /* move initrd over / and chdir/chroot in initrd root */
62231- sys_chdir("/root");
62232- sys_mount(".", "/", NULL, MS_MOVE, NULL);
62233- sys_chroot(".");
62234+ sys_chdir((__force const char __user *)"/root");
62235+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
62236+ sys_chroot((__force const char __user *)".");
62237
62238 /*
62239 * In case that a resume from disk is carried out by linuxrc or one of
62240@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
62241
62242 /* move initrd to rootfs' /old */
62243 sys_fchdir(old_fd);
62244- sys_mount("/", ".", NULL, MS_MOVE, NULL);
62245+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
62246 /* switch root and cwd back to / of rootfs */
62247 sys_fchdir(root_fd);
62248- sys_chroot(".");
62249+ sys_chroot((__force const char __user *)".");
62250 sys_close(old_fd);
62251 sys_close(root_fd);
62252
62253 if (new_decode_dev(real_root_dev) == Root_RAM0) {
62254- sys_chdir("/old");
62255+ sys_chdir((__force const char __user *)"/old");
62256 return;
62257 }
62258
62259@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
62260 mount_root();
62261
62262 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
62263- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
62264+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
62265 if (!error)
62266 printk("okay\n");
62267 else {
62268- int fd = sys_open("/dev/root.old", O_RDWR, 0);
62269+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
62270 if (error == -ENOENT)
62271 printk("/initrd does not exist. Ignored.\n");
62272 else
62273 printk("failed\n");
62274 printk(KERN_NOTICE "Unmounting old root\n");
62275- sys_umount("/old", MNT_DETACH);
62276+ sys_umount((__force char __user *)"/old", MNT_DETACH);
62277 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
62278 if (fd < 0) {
62279 error = fd;
62280@@ -119,11 +119,11 @@ int __init initrd_load(void)
62281 * mounted in the normal path.
62282 */
62283 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
62284- sys_unlink("/initrd.image");
62285+ sys_unlink((__force const char __user *)"/initrd.image");
62286 handle_initrd();
62287 return 1;
62288 }
62289 }
62290- sys_unlink("/initrd.image");
62291+ sys_unlink((__force const char __user *)"/initrd.image");
62292 return 0;
62293 }
62294diff -urNp linux-2.6.32.44/init/do_mounts_md.c linux-2.6.32.44/init/do_mounts_md.c
62295--- linux-2.6.32.44/init/do_mounts_md.c 2011-03-27 14:31:47.000000000 -0400
62296+++ linux-2.6.32.44/init/do_mounts_md.c 2011-04-17 15:56:46.000000000 -0400
62297@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
62298 partitioned ? "_d" : "", minor,
62299 md_setup_args[ent].device_names);
62300
62301- fd = sys_open(name, 0, 0);
62302+ fd = sys_open((__force char __user *)name, 0, 0);
62303 if (fd < 0) {
62304 printk(KERN_ERR "md: open failed - cannot start "
62305 "array %s\n", name);
62306@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
62307 * array without it
62308 */
62309 sys_close(fd);
62310- fd = sys_open(name, 0, 0);
62311+ fd = sys_open((__force char __user *)name, 0, 0);
62312 sys_ioctl(fd, BLKRRPART, 0);
62313 }
62314 sys_close(fd);
62315@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
62316
62317 wait_for_device_probe();
62318
62319- fd = sys_open("/dev/md0", 0, 0);
62320+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
62321 if (fd >= 0) {
62322 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
62323 sys_close(fd);
62324diff -urNp linux-2.6.32.44/init/initramfs.c linux-2.6.32.44/init/initramfs.c
62325--- linux-2.6.32.44/init/initramfs.c 2011-03-27 14:31:47.000000000 -0400
62326+++ linux-2.6.32.44/init/initramfs.c 2011-04-17 15:56:46.000000000 -0400
62327@@ -74,7 +74,7 @@ static void __init free_hash(void)
62328 }
62329 }
62330
62331-static long __init do_utime(char __user *filename, time_t mtime)
62332+static long __init do_utime(__force char __user *filename, time_t mtime)
62333 {
62334 struct timespec t[2];
62335
62336@@ -109,7 +109,7 @@ static void __init dir_utime(void)
62337 struct dir_entry *de, *tmp;
62338 list_for_each_entry_safe(de, tmp, &dir_list, list) {
62339 list_del(&de->list);
62340- do_utime(de->name, de->mtime);
62341+ do_utime((__force char __user *)de->name, de->mtime);
62342 kfree(de->name);
62343 kfree(de);
62344 }
62345@@ -271,7 +271,7 @@ static int __init maybe_link(void)
62346 if (nlink >= 2) {
62347 char *old = find_link(major, minor, ino, mode, collected);
62348 if (old)
62349- return (sys_link(old, collected) < 0) ? -1 : 1;
62350+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
62351 }
62352 return 0;
62353 }
62354@@ -280,11 +280,11 @@ static void __init clean_path(char *path
62355 {
62356 struct stat st;
62357
62358- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
62359+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
62360 if (S_ISDIR(st.st_mode))
62361- sys_rmdir(path);
62362+ sys_rmdir((__force char __user *)path);
62363 else
62364- sys_unlink(path);
62365+ sys_unlink((__force char __user *)path);
62366 }
62367 }
62368
62369@@ -305,7 +305,7 @@ static int __init do_name(void)
62370 int openflags = O_WRONLY|O_CREAT;
62371 if (ml != 1)
62372 openflags |= O_TRUNC;
62373- wfd = sys_open(collected, openflags, mode);
62374+ wfd = sys_open((__force char __user *)collected, openflags, mode);
62375
62376 if (wfd >= 0) {
62377 sys_fchown(wfd, uid, gid);
62378@@ -317,17 +317,17 @@ static int __init do_name(void)
62379 }
62380 }
62381 } else if (S_ISDIR(mode)) {
62382- sys_mkdir(collected, mode);
62383- sys_chown(collected, uid, gid);
62384- sys_chmod(collected, mode);
62385+ sys_mkdir((__force char __user *)collected, mode);
62386+ sys_chown((__force char __user *)collected, uid, gid);
62387+ sys_chmod((__force char __user *)collected, mode);
62388 dir_add(collected, mtime);
62389 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
62390 S_ISFIFO(mode) || S_ISSOCK(mode)) {
62391 if (maybe_link() == 0) {
62392- sys_mknod(collected, mode, rdev);
62393- sys_chown(collected, uid, gid);
62394- sys_chmod(collected, mode);
62395- do_utime(collected, mtime);
62396+ sys_mknod((__force char __user *)collected, mode, rdev);
62397+ sys_chown((__force char __user *)collected, uid, gid);
62398+ sys_chmod((__force char __user *)collected, mode);
62399+ do_utime((__force char __user *)collected, mtime);
62400 }
62401 }
62402 return 0;
62403@@ -336,15 +336,15 @@ static int __init do_name(void)
62404 static int __init do_copy(void)
62405 {
62406 if (count >= body_len) {
62407- sys_write(wfd, victim, body_len);
62408+ sys_write(wfd, (__force char __user *)victim, body_len);
62409 sys_close(wfd);
62410- do_utime(vcollected, mtime);
62411+ do_utime((__force char __user *)vcollected, mtime);
62412 kfree(vcollected);
62413 eat(body_len);
62414 state = SkipIt;
62415 return 0;
62416 } else {
62417- sys_write(wfd, victim, count);
62418+ sys_write(wfd, (__force char __user *)victim, count);
62419 body_len -= count;
62420 eat(count);
62421 return 1;
62422@@ -355,9 +355,9 @@ static int __init do_symlink(void)
62423 {
62424 collected[N_ALIGN(name_len) + body_len] = '\0';
62425 clean_path(collected, 0);
62426- sys_symlink(collected + N_ALIGN(name_len), collected);
62427- sys_lchown(collected, uid, gid);
62428- do_utime(collected, mtime);
62429+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
62430+ sys_lchown((__force char __user *)collected, uid, gid);
62431+ do_utime((__force char __user *)collected, mtime);
62432 state = SkipIt;
62433 next_state = Reset;
62434 return 0;
62435diff -urNp linux-2.6.32.44/init/Kconfig linux-2.6.32.44/init/Kconfig
62436--- linux-2.6.32.44/init/Kconfig 2011-05-10 22:12:01.000000000 -0400
62437+++ linux-2.6.32.44/init/Kconfig 2011-05-10 22:12:34.000000000 -0400
62438@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
62439
62440 config COMPAT_BRK
62441 bool "Disable heap randomization"
62442- default y
62443+ default n
62444 help
62445 Randomizing heap placement makes heap exploits harder, but it
62446 also breaks ancient binaries (including anything libc5 based).
62447diff -urNp linux-2.6.32.44/init/main.c linux-2.6.32.44/init/main.c
62448--- linux-2.6.32.44/init/main.c 2011-05-10 22:12:01.000000000 -0400
62449+++ linux-2.6.32.44/init/main.c 2011-08-05 20:33:55.000000000 -0400
62450@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void)
62451 #ifdef CONFIG_TC
62452 extern void tc_init(void);
62453 #endif
62454+extern void grsecurity_init(void);
62455
62456 enum system_states system_state __read_mostly;
62457 EXPORT_SYMBOL(system_state);
62458@@ -183,6 +184,49 @@ static int __init set_reset_devices(char
62459
62460 __setup("reset_devices", set_reset_devices);
62461
62462+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
62463+extern char pax_enter_kernel_user[];
62464+extern char pax_exit_kernel_user[];
62465+extern pgdval_t clone_pgd_mask;
62466+#endif
62467+
62468+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
62469+static int __init setup_pax_nouderef(char *str)
62470+{
62471+#ifdef CONFIG_X86_32
62472+ unsigned int cpu;
62473+ struct desc_struct *gdt;
62474+
62475+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
62476+ gdt = get_cpu_gdt_table(cpu);
62477+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
62478+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
62479+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
62480+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
62481+ }
62482+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
62483+#else
62484+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
62485+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
62486+ clone_pgd_mask = ~(pgdval_t)0UL;
62487+#endif
62488+
62489+ return 0;
62490+}
62491+early_param("pax_nouderef", setup_pax_nouderef);
62492+#endif
62493+
62494+#ifdef CONFIG_PAX_SOFTMODE
62495+int pax_softmode;
62496+
62497+static int __init setup_pax_softmode(char *str)
62498+{
62499+ get_option(&str, &pax_softmode);
62500+ return 1;
62501+}
62502+__setup("pax_softmode=", setup_pax_softmode);
62503+#endif
62504+
62505 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
62506 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
62507 static const char *panic_later, *panic_param;
62508@@ -705,52 +749,53 @@ int initcall_debug;
62509 core_param(initcall_debug, initcall_debug, bool, 0644);
62510
62511 static char msgbuf[64];
62512-static struct boot_trace_call call;
62513-static struct boot_trace_ret ret;
62514+static struct boot_trace_call trace_call;
62515+static struct boot_trace_ret trace_ret;
62516
62517 int do_one_initcall(initcall_t fn)
62518 {
62519 int count = preempt_count();
62520 ktime_t calltime, delta, rettime;
62521+ const char *msg1 = "", *msg2 = "";
62522
62523 if (initcall_debug) {
62524- call.caller = task_pid_nr(current);
62525- printk("calling %pF @ %i\n", fn, call.caller);
62526+ trace_call.caller = task_pid_nr(current);
62527+ printk("calling %pF @ %i\n", fn, trace_call.caller);
62528 calltime = ktime_get();
62529- trace_boot_call(&call, fn);
62530+ trace_boot_call(&trace_call, fn);
62531 enable_boot_trace();
62532 }
62533
62534- ret.result = fn();
62535+ trace_ret.result = fn();
62536
62537 if (initcall_debug) {
62538 disable_boot_trace();
62539 rettime = ktime_get();
62540 delta = ktime_sub(rettime, calltime);
62541- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
62542- trace_boot_ret(&ret, fn);
62543+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
62544+ trace_boot_ret(&trace_ret, fn);
62545 printk("initcall %pF returned %d after %Ld usecs\n", fn,
62546- ret.result, ret.duration);
62547+ trace_ret.result, trace_ret.duration);
62548 }
62549
62550 msgbuf[0] = 0;
62551
62552- if (ret.result && ret.result != -ENODEV && initcall_debug)
62553- sprintf(msgbuf, "error code %d ", ret.result);
62554+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
62555+ sprintf(msgbuf, "error code %d ", trace_ret.result);
62556
62557 if (preempt_count() != count) {
62558- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
62559+ msg1 = " preemption imbalance";
62560 preempt_count() = count;
62561 }
62562 if (irqs_disabled()) {
62563- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
62564+ msg2 = " disabled interrupts";
62565 local_irq_enable();
62566 }
62567- if (msgbuf[0]) {
62568- printk("initcall %pF returned with %s\n", fn, msgbuf);
62569+ if (msgbuf[0] || *msg1 || *msg2) {
62570+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
62571 }
62572
62573- return ret.result;
62574+ return trace_ret.result;
62575 }
62576
62577
62578@@ -893,11 +938,13 @@ static int __init kernel_init(void * unu
62579 if (!ramdisk_execute_command)
62580 ramdisk_execute_command = "/init";
62581
62582- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
62583+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
62584 ramdisk_execute_command = NULL;
62585 prepare_namespace();
62586 }
62587
62588+ grsecurity_init();
62589+
62590 /*
62591 * Ok, we have completed the initial bootup, and
62592 * we're essentially up and running. Get rid of the
62593diff -urNp linux-2.6.32.44/init/noinitramfs.c linux-2.6.32.44/init/noinitramfs.c
62594--- linux-2.6.32.44/init/noinitramfs.c 2011-03-27 14:31:47.000000000 -0400
62595+++ linux-2.6.32.44/init/noinitramfs.c 2011-04-17 15:56:46.000000000 -0400
62596@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
62597 {
62598 int err;
62599
62600- err = sys_mkdir("/dev", 0755);
62601+ err = sys_mkdir((const char __user *)"/dev", 0755);
62602 if (err < 0)
62603 goto out;
62604
62605@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
62606 if (err < 0)
62607 goto out;
62608
62609- err = sys_mkdir("/root", 0700);
62610+ err = sys_mkdir((const char __user *)"/root", 0700);
62611 if (err < 0)
62612 goto out;
62613
62614diff -urNp linux-2.6.32.44/ipc/mqueue.c linux-2.6.32.44/ipc/mqueue.c
62615--- linux-2.6.32.44/ipc/mqueue.c 2011-03-27 14:31:47.000000000 -0400
62616+++ linux-2.6.32.44/ipc/mqueue.c 2011-04-17 15:56:46.000000000 -0400
62617@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(st
62618 mq_bytes = (mq_msg_tblsz +
62619 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
62620
62621+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
62622 spin_lock(&mq_lock);
62623 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
62624 u->mq_bytes + mq_bytes >
62625diff -urNp linux-2.6.32.44/ipc/msg.c linux-2.6.32.44/ipc/msg.c
62626--- linux-2.6.32.44/ipc/msg.c 2011-03-27 14:31:47.000000000 -0400
62627+++ linux-2.6.32.44/ipc/msg.c 2011-08-05 20:33:55.000000000 -0400
62628@@ -310,18 +310,19 @@ static inline int msg_security(struct ke
62629 return security_msg_queue_associate(msq, msgflg);
62630 }
62631
62632+static struct ipc_ops msg_ops = {
62633+ .getnew = newque,
62634+ .associate = msg_security,
62635+ .more_checks = NULL
62636+};
62637+
62638 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
62639 {
62640 struct ipc_namespace *ns;
62641- struct ipc_ops msg_ops;
62642 struct ipc_params msg_params;
62643
62644 ns = current->nsproxy->ipc_ns;
62645
62646- msg_ops.getnew = newque;
62647- msg_ops.associate = msg_security;
62648- msg_ops.more_checks = NULL;
62649-
62650 msg_params.key = key;
62651 msg_params.flg = msgflg;
62652
62653diff -urNp linux-2.6.32.44/ipc/sem.c linux-2.6.32.44/ipc/sem.c
62654--- linux-2.6.32.44/ipc/sem.c 2011-03-27 14:31:47.000000000 -0400
62655+++ linux-2.6.32.44/ipc/sem.c 2011-08-05 20:33:55.000000000 -0400
62656@@ -309,10 +309,15 @@ static inline int sem_more_checks(struct
62657 return 0;
62658 }
62659
62660+static struct ipc_ops sem_ops = {
62661+ .getnew = newary,
62662+ .associate = sem_security,
62663+ .more_checks = sem_more_checks
62664+};
62665+
62666 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62667 {
62668 struct ipc_namespace *ns;
62669- struct ipc_ops sem_ops;
62670 struct ipc_params sem_params;
62671
62672 ns = current->nsproxy->ipc_ns;
62673@@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int,
62674 if (nsems < 0 || nsems > ns->sc_semmsl)
62675 return -EINVAL;
62676
62677- sem_ops.getnew = newary;
62678- sem_ops.associate = sem_security;
62679- sem_ops.more_checks = sem_more_checks;
62680-
62681 sem_params.key = key;
62682 sem_params.flg = semflg;
62683 sem_params.u.nsems = nsems;
62684@@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namesp
62685 ushort* sem_io = fast_sem_io;
62686 int nsems;
62687
62688+ pax_track_stack();
62689+
62690 sma = sem_lock_check(ns, semid);
62691 if (IS_ERR(sma))
62692 return PTR_ERR(sma);
62693@@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
62694 unsigned long jiffies_left = 0;
62695 struct ipc_namespace *ns;
62696
62697+ pax_track_stack();
62698+
62699 ns = current->nsproxy->ipc_ns;
62700
62701 if (nsops < 1 || semid < 0)
62702diff -urNp linux-2.6.32.44/ipc/shm.c linux-2.6.32.44/ipc/shm.c
62703--- linux-2.6.32.44/ipc/shm.c 2011-03-27 14:31:47.000000000 -0400
62704+++ linux-2.6.32.44/ipc/shm.c 2011-08-05 20:33:55.000000000 -0400
62705@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_name
62706 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
62707 #endif
62708
62709+#ifdef CONFIG_GRKERNSEC
62710+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62711+ const time_t shm_createtime, const uid_t cuid,
62712+ const int shmid);
62713+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62714+ const time_t shm_createtime);
62715+#endif
62716+
62717 void shm_init_ns(struct ipc_namespace *ns)
62718 {
62719 ns->shm_ctlmax = SHMMAX;
62720@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *
62721 shp->shm_lprid = 0;
62722 shp->shm_atim = shp->shm_dtim = 0;
62723 shp->shm_ctim = get_seconds();
62724+#ifdef CONFIG_GRKERNSEC
62725+ {
62726+ struct timespec timeval;
62727+ do_posix_clock_monotonic_gettime(&timeval);
62728+
62729+ shp->shm_createtime = timeval.tv_sec;
62730+ }
62731+#endif
62732 shp->shm_segsz = size;
62733 shp->shm_nattch = 0;
62734 shp->shm_file = file;
62735@@ -446,18 +462,19 @@ static inline int shm_more_checks(struct
62736 return 0;
62737 }
62738
62739+static struct ipc_ops shm_ops = {
62740+ .getnew = newseg,
62741+ .associate = shm_security,
62742+ .more_checks = shm_more_checks
62743+};
62744+
62745 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
62746 {
62747 struct ipc_namespace *ns;
62748- struct ipc_ops shm_ops;
62749 struct ipc_params shm_params;
62750
62751 ns = current->nsproxy->ipc_ns;
62752
62753- shm_ops.getnew = newseg;
62754- shm_ops.associate = shm_security;
62755- shm_ops.more_checks = shm_more_checks;
62756-
62757 shm_params.key = key;
62758 shm_params.flg = shmflg;
62759 shm_params.u.size = size;
62760@@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *sh
62761 if (err)
62762 goto out_unlock;
62763
62764+#ifdef CONFIG_GRKERNSEC
62765+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
62766+ shp->shm_perm.cuid, shmid) ||
62767+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
62768+ err = -EACCES;
62769+ goto out_unlock;
62770+ }
62771+#endif
62772+
62773 path.dentry = dget(shp->shm_file->f_path.dentry);
62774 path.mnt = shp->shm_file->f_path.mnt;
62775 shp->shm_nattch++;
62776+#ifdef CONFIG_GRKERNSEC
62777+ shp->shm_lapid = current->pid;
62778+#endif
62779 size = i_size_read(path.dentry->d_inode);
62780 shm_unlock(shp);
62781
62782diff -urNp linux-2.6.32.44/kernel/acct.c linux-2.6.32.44/kernel/acct.c
62783--- linux-2.6.32.44/kernel/acct.c 2011-03-27 14:31:47.000000000 -0400
62784+++ linux-2.6.32.44/kernel/acct.c 2011-04-17 15:56:46.000000000 -0400
62785@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_a
62786 */
62787 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
62788 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
62789- file->f_op->write(file, (char *)&ac,
62790+ file->f_op->write(file, (__force char __user *)&ac,
62791 sizeof(acct_t), &file->f_pos);
62792 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
62793 set_fs(fs);
62794diff -urNp linux-2.6.32.44/kernel/audit.c linux-2.6.32.44/kernel/audit.c
62795--- linux-2.6.32.44/kernel/audit.c 2011-03-27 14:31:47.000000000 -0400
62796+++ linux-2.6.32.44/kernel/audit.c 2011-05-04 17:56:28.000000000 -0400
62797@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
62798 3) suppressed due to audit_rate_limit
62799 4) suppressed due to audit_backlog_limit
62800 */
62801-static atomic_t audit_lost = ATOMIC_INIT(0);
62802+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
62803
62804 /* The netlink socket. */
62805 static struct sock *audit_sock;
62806@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
62807 unsigned long now;
62808 int print;
62809
62810- atomic_inc(&audit_lost);
62811+ atomic_inc_unchecked(&audit_lost);
62812
62813 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
62814
62815@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
62816 printk(KERN_WARNING
62817 "audit: audit_lost=%d audit_rate_limit=%d "
62818 "audit_backlog_limit=%d\n",
62819- atomic_read(&audit_lost),
62820+ atomic_read_unchecked(&audit_lost),
62821 audit_rate_limit,
62822 audit_backlog_limit);
62823 audit_panic(message);
62824@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_b
62825 status_set.pid = audit_pid;
62826 status_set.rate_limit = audit_rate_limit;
62827 status_set.backlog_limit = audit_backlog_limit;
62828- status_set.lost = atomic_read(&audit_lost);
62829+ status_set.lost = atomic_read_unchecked(&audit_lost);
62830 status_set.backlog = skb_queue_len(&audit_skb_queue);
62831 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
62832 &status_set, sizeof(status_set));
62833@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_b
62834 spin_unlock_irq(&tsk->sighand->siglock);
62835 }
62836 read_unlock(&tasklist_lock);
62837- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
62838- &s, sizeof(s));
62839+
62840+ if (!err)
62841+ audit_send_reply(NETLINK_CB(skb).pid, seq,
62842+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
62843 break;
62844 }
62845 case AUDIT_TTY_SET: {
62846diff -urNp linux-2.6.32.44/kernel/auditsc.c linux-2.6.32.44/kernel/auditsc.c
62847--- linux-2.6.32.44/kernel/auditsc.c 2011-03-27 14:31:47.000000000 -0400
62848+++ linux-2.6.32.44/kernel/auditsc.c 2011-05-04 17:56:28.000000000 -0400
62849@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_conte
62850 }
62851
62852 /* global counter which is incremented every time something logs in */
62853-static atomic_t session_id = ATOMIC_INIT(0);
62854+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
62855
62856 /**
62857 * audit_set_loginuid - set a task's audit_context loginuid
62858@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT
62859 */
62860 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
62861 {
62862- unsigned int sessionid = atomic_inc_return(&session_id);
62863+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
62864 struct audit_context *context = task->audit_context;
62865
62866 if (context && context->in_syscall) {
62867diff -urNp linux-2.6.32.44/kernel/capability.c linux-2.6.32.44/kernel/capability.c
62868--- linux-2.6.32.44/kernel/capability.c 2011-03-27 14:31:47.000000000 -0400
62869+++ linux-2.6.32.44/kernel/capability.c 2011-04-17 15:56:46.000000000 -0400
62870@@ -305,10 +305,26 @@ int capable(int cap)
62871 BUG();
62872 }
62873
62874- if (security_capable(cap) == 0) {
62875+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
62876 current->flags |= PF_SUPERPRIV;
62877 return 1;
62878 }
62879 return 0;
62880 }
62881+
62882+int capable_nolog(int cap)
62883+{
62884+ if (unlikely(!cap_valid(cap))) {
62885+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
62886+ BUG();
62887+ }
62888+
62889+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
62890+ current->flags |= PF_SUPERPRIV;
62891+ return 1;
62892+ }
62893+ return 0;
62894+}
62895+
62896 EXPORT_SYMBOL(capable);
62897+EXPORT_SYMBOL(capable_nolog);
62898diff -urNp linux-2.6.32.44/kernel/cgroup.c linux-2.6.32.44/kernel/cgroup.c
62899--- linux-2.6.32.44/kernel/cgroup.c 2011-03-27 14:31:47.000000000 -0400
62900+++ linux-2.6.32.44/kernel/cgroup.c 2011-05-16 21:46:57.000000000 -0400
62901@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
62902 struct hlist_head *hhead;
62903 struct cg_cgroup_link *link;
62904
62905+ pax_track_stack();
62906+
62907 /* First see if we already have a cgroup group that matches
62908 * the desired set */
62909 read_lock(&css_set_lock);
62910diff -urNp linux-2.6.32.44/kernel/configs.c linux-2.6.32.44/kernel/configs.c
62911--- linux-2.6.32.44/kernel/configs.c 2011-03-27 14:31:47.000000000 -0400
62912+++ linux-2.6.32.44/kernel/configs.c 2011-04-17 15:56:46.000000000 -0400
62913@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
62914 struct proc_dir_entry *entry;
62915
62916 /* create the current config file */
62917+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62918+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
62919+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
62920+ &ikconfig_file_ops);
62921+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62922+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
62923+ &ikconfig_file_ops);
62924+#endif
62925+#else
62926 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
62927 &ikconfig_file_ops);
62928+#endif
62929+
62930 if (!entry)
62931 return -ENOMEM;
62932
62933diff -urNp linux-2.6.32.44/kernel/cpu.c linux-2.6.32.44/kernel/cpu.c
62934--- linux-2.6.32.44/kernel/cpu.c 2011-03-27 14:31:47.000000000 -0400
62935+++ linux-2.6.32.44/kernel/cpu.c 2011-04-17 15:56:46.000000000 -0400
62936@@ -19,7 +19,7 @@
62937 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
62938 static DEFINE_MUTEX(cpu_add_remove_lock);
62939
62940-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
62941+static RAW_NOTIFIER_HEAD(cpu_chain);
62942
62943 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
62944 * Should always be manipulated under cpu_add_remove_lock
62945diff -urNp linux-2.6.32.44/kernel/cred.c linux-2.6.32.44/kernel/cred.c
62946--- linux-2.6.32.44/kernel/cred.c 2011-03-27 14:31:47.000000000 -0400
62947+++ linux-2.6.32.44/kernel/cred.c 2011-08-11 19:49:38.000000000 -0400
62948@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head
62949 */
62950 void __put_cred(struct cred *cred)
62951 {
62952+ pax_track_stack();
62953+
62954 kdebug("__put_cred(%p{%d,%d})", cred,
62955 atomic_read(&cred->usage),
62956 read_cred_subscribers(cred));
62957@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
62958 {
62959 struct cred *cred;
62960
62961+ pax_track_stack();
62962+
62963 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
62964 atomic_read(&tsk->cred->usage),
62965 read_cred_subscribers(tsk->cred));
62966@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct
62967 {
62968 const struct cred *cred;
62969
62970+ pax_track_stack();
62971+
62972 rcu_read_lock();
62973
62974 do {
62975@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
62976 {
62977 struct cred *new;
62978
62979+ pax_track_stack();
62980+
62981 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
62982 if (!new)
62983 return NULL;
62984@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
62985 const struct cred *old;
62986 struct cred *new;
62987
62988+ pax_track_stack();
62989+
62990 validate_process_creds();
62991
62992 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
62993@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
62994 struct thread_group_cred *tgcred = NULL;
62995 struct cred *new;
62996
62997+ pax_track_stack();
62998+
62999 #ifdef CONFIG_KEYS
63000 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
63001 if (!tgcred)
63002@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, un
63003 struct cred *new;
63004 int ret;
63005
63006+ pax_track_stack();
63007+
63008 mutex_init(&p->cred_guard_mutex);
63009
63010 if (
63011@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
63012 struct task_struct *task = current;
63013 const struct cred *old = task->real_cred;
63014
63015+ pax_track_stack();
63016+
63017 kdebug("commit_creds(%p{%d,%d})", new,
63018 atomic_read(&new->usage),
63019 read_cred_subscribers(new));
63020@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
63021
63022 get_cred(new); /* we will require a ref for the subj creds too */
63023
63024+ gr_set_role_label(task, new->uid, new->gid);
63025+
63026 /* dumpability changes */
63027 if (old->euid != new->euid ||
63028 old->egid != new->egid ||
63029@@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
63030 key_fsgid_changed(task);
63031
63032 /* do it
63033- * - What if a process setreuid()'s and this brings the
63034- * new uid over his NPROC rlimit? We can check this now
63035- * cheaply with the new uid cache, so if it matters
63036- * we should be checking for it. -DaveM
63037+ * RLIMIT_NPROC limits on user->processes have already been checked
63038+ * in set_user().
63039 */
63040 alter_cred_subscribers(new, 2);
63041 if (new->user != old->user)
63042@@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
63043 */
63044 void abort_creds(struct cred *new)
63045 {
63046+ pax_track_stack();
63047+
63048 kdebug("abort_creds(%p{%d,%d})", new,
63049 atomic_read(&new->usage),
63050 read_cred_subscribers(new));
63051@@ -629,6 +647,8 @@ const struct cred *override_creds(const
63052 {
63053 const struct cred *old = current->cred;
63054
63055+ pax_track_stack();
63056+
63057 kdebug("override_creds(%p{%d,%d})", new,
63058 atomic_read(&new->usage),
63059 read_cred_subscribers(new));
63060@@ -658,6 +678,8 @@ void revert_creds(const struct cred *old
63061 {
63062 const struct cred *override = current->cred;
63063
63064+ pax_track_stack();
63065+
63066 kdebug("revert_creds(%p{%d,%d})", old,
63067 atomic_read(&old->usage),
63068 read_cred_subscribers(old));
63069@@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct
63070 const struct cred *old;
63071 struct cred *new;
63072
63073+ pax_track_stack();
63074+
63075 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
63076 if (!new)
63077 return NULL;
63078@@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
63079 */
63080 int set_security_override(struct cred *new, u32 secid)
63081 {
63082+ pax_track_stack();
63083+
63084 return security_kernel_act_as(new, secid);
63085 }
63086 EXPORT_SYMBOL(set_security_override);
63087@@ -777,6 +803,8 @@ int set_security_override_from_ctx(struc
63088 u32 secid;
63089 int ret;
63090
63091+ pax_track_stack();
63092+
63093 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
63094 if (ret < 0)
63095 return ret;
63096diff -urNp linux-2.6.32.44/kernel/exit.c linux-2.6.32.44/kernel/exit.c
63097--- linux-2.6.32.44/kernel/exit.c 2011-03-27 14:31:47.000000000 -0400
63098+++ linux-2.6.32.44/kernel/exit.c 2011-04-17 15:56:46.000000000 -0400
63099@@ -55,6 +55,10 @@
63100 #include <asm/pgtable.h>
63101 #include <asm/mmu_context.h>
63102
63103+#ifdef CONFIG_GRKERNSEC
63104+extern rwlock_t grsec_exec_file_lock;
63105+#endif
63106+
63107 static void exit_mm(struct task_struct * tsk);
63108
63109 static void __unhash_process(struct task_struct *p)
63110@@ -174,6 +178,8 @@ void release_task(struct task_struct * p
63111 struct task_struct *leader;
63112 int zap_leader;
63113 repeat:
63114+ gr_del_task_from_ip_table(p);
63115+
63116 tracehook_prepare_release_task(p);
63117 /* don't need to get the RCU readlock here - the process is dead and
63118 * can't be modifying its own credentials */
63119@@ -341,11 +347,22 @@ static void reparent_to_kthreadd(void)
63120 {
63121 write_lock_irq(&tasklist_lock);
63122
63123+#ifdef CONFIG_GRKERNSEC
63124+ write_lock(&grsec_exec_file_lock);
63125+ if (current->exec_file) {
63126+ fput(current->exec_file);
63127+ current->exec_file = NULL;
63128+ }
63129+ write_unlock(&grsec_exec_file_lock);
63130+#endif
63131+
63132 ptrace_unlink(current);
63133 /* Reparent to init */
63134 current->real_parent = current->parent = kthreadd_task;
63135 list_move_tail(&current->sibling, &current->real_parent->children);
63136
63137+ gr_set_kernel_label(current);
63138+
63139 /* Set the exit signal to SIGCHLD so we signal init on exit */
63140 current->exit_signal = SIGCHLD;
63141
63142@@ -397,7 +414,7 @@ int allow_signal(int sig)
63143 * know it'll be handled, so that they don't get converted to
63144 * SIGKILL or just silently dropped.
63145 */
63146- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
63147+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
63148 recalc_sigpending();
63149 spin_unlock_irq(&current->sighand->siglock);
63150 return 0;
63151@@ -433,6 +450,17 @@ void daemonize(const char *name, ...)
63152 vsnprintf(current->comm, sizeof(current->comm), name, args);
63153 va_end(args);
63154
63155+#ifdef CONFIG_GRKERNSEC
63156+ write_lock(&grsec_exec_file_lock);
63157+ if (current->exec_file) {
63158+ fput(current->exec_file);
63159+ current->exec_file = NULL;
63160+ }
63161+ write_unlock(&grsec_exec_file_lock);
63162+#endif
63163+
63164+ gr_set_kernel_label(current);
63165+
63166 /*
63167 * If we were started as result of loading a module, close all of the
63168 * user space pages. We don't need them, and if we didn't close them
63169@@ -897,17 +925,17 @@ NORET_TYPE void do_exit(long code)
63170 struct task_struct *tsk = current;
63171 int group_dead;
63172
63173- profile_task_exit(tsk);
63174-
63175- WARN_ON(atomic_read(&tsk->fs_excl));
63176-
63177+ /*
63178+ * Check this first since set_fs() below depends on
63179+ * current_thread_info(), which we better not access when we're in
63180+ * interrupt context. Other than that, we want to do the set_fs()
63181+ * as early as possible.
63182+ */
63183 if (unlikely(in_interrupt()))
63184 panic("Aiee, killing interrupt handler!");
63185- if (unlikely(!tsk->pid))
63186- panic("Attempted to kill the idle task!");
63187
63188 /*
63189- * If do_exit is called because this processes oopsed, it's possible
63190+ * If do_exit is called because this processes Oops'ed, it's possible
63191 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
63192 * continuing. Amongst other possible reasons, this is to prevent
63193 * mm_release()->clear_child_tid() from writing to a user-controlled
63194@@ -915,6 +943,13 @@ NORET_TYPE void do_exit(long code)
63195 */
63196 set_fs(USER_DS);
63197
63198+ profile_task_exit(tsk);
63199+
63200+ WARN_ON(atomic_read(&tsk->fs_excl));
63201+
63202+ if (unlikely(!tsk->pid))
63203+ panic("Attempted to kill the idle task!");
63204+
63205 tracehook_report_exit(&code);
63206
63207 validate_creds_for_do_exit(tsk);
63208@@ -973,6 +1008,9 @@ NORET_TYPE void do_exit(long code)
63209 tsk->exit_code = code;
63210 taskstats_exit(tsk, group_dead);
63211
63212+ gr_acl_handle_psacct(tsk, code);
63213+ gr_acl_handle_exit();
63214+
63215 exit_mm(tsk);
63216
63217 if (group_dead)
63218@@ -1188,7 +1226,7 @@ static int wait_task_zombie(struct wait_
63219
63220 if (unlikely(wo->wo_flags & WNOWAIT)) {
63221 int exit_code = p->exit_code;
63222- int why, status;
63223+ int why;
63224
63225 get_task_struct(p);
63226 read_unlock(&tasklist_lock);
63227diff -urNp linux-2.6.32.44/kernel/fork.c linux-2.6.32.44/kernel/fork.c
63228--- linux-2.6.32.44/kernel/fork.c 2011-03-27 14:31:47.000000000 -0400
63229+++ linux-2.6.32.44/kernel/fork.c 2011-08-11 19:50:07.000000000 -0400
63230@@ -253,7 +253,7 @@ static struct task_struct *dup_task_stru
63231 *stackend = STACK_END_MAGIC; /* for overflow detection */
63232
63233 #ifdef CONFIG_CC_STACKPROTECTOR
63234- tsk->stack_canary = get_random_int();
63235+ tsk->stack_canary = pax_get_random_long();
63236 #endif
63237
63238 /* One for us, one for whoever does the "release_task()" (usually parent) */
63239@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm
63240 mm->locked_vm = 0;
63241 mm->mmap = NULL;
63242 mm->mmap_cache = NULL;
63243- mm->free_area_cache = oldmm->mmap_base;
63244- mm->cached_hole_size = ~0UL;
63245+ mm->free_area_cache = oldmm->free_area_cache;
63246+ mm->cached_hole_size = oldmm->cached_hole_size;
63247 mm->map_count = 0;
63248 cpumask_clear(mm_cpumask(mm));
63249 mm->mm_rb = RB_ROOT;
63250@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm
63251 tmp->vm_flags &= ~VM_LOCKED;
63252 tmp->vm_mm = mm;
63253 tmp->vm_next = tmp->vm_prev = NULL;
63254+ tmp->vm_mirror = NULL;
63255 anon_vma_link(tmp);
63256 file = tmp->vm_file;
63257 if (file) {
63258@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm
63259 if (retval)
63260 goto out;
63261 }
63262+
63263+#ifdef CONFIG_PAX_SEGMEXEC
63264+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
63265+ struct vm_area_struct *mpnt_m;
63266+
63267+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
63268+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
63269+
63270+ if (!mpnt->vm_mirror)
63271+ continue;
63272+
63273+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
63274+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
63275+ mpnt->vm_mirror = mpnt_m;
63276+ } else {
63277+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
63278+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
63279+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
63280+ mpnt->vm_mirror->vm_mirror = mpnt;
63281+ }
63282+ }
63283+ BUG_ON(mpnt_m);
63284+ }
63285+#endif
63286+
63287 /* a new mm has just been created */
63288 arch_dup_mmap(oldmm, mm);
63289 retval = 0;
63290@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_f
63291 write_unlock(&fs->lock);
63292 return -EAGAIN;
63293 }
63294- fs->users++;
63295+ atomic_inc(&fs->users);
63296 write_unlock(&fs->lock);
63297 return 0;
63298 }
63299 tsk->fs = copy_fs_struct(fs);
63300 if (!tsk->fs)
63301 return -ENOMEM;
63302+ gr_set_chroot_entries(tsk, &tsk->fs->root);
63303 return 0;
63304 }
63305
63306@@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(
63307 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
63308 #endif
63309 retval = -EAGAIN;
63310+
63311+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
63312+
63313 if (atomic_read(&p->real_cred->user->processes) >=
63314 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
63315- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
63316- p->real_cred->user != INIT_USER)
63317+ if (p->real_cred->user != INIT_USER &&
63318+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
63319 goto bad_fork_free;
63320 }
63321+ current->flags &= ~PF_NPROC_EXCEEDED;
63322
63323 retval = copy_creds(p, clone_flags);
63324 if (retval < 0)
63325@@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(
63326 goto bad_fork_free_pid;
63327 }
63328
63329+ gr_copy_label(p);
63330+
63331 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
63332 /*
63333 * Clear TID on mm_release()?
63334@@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
63335 bad_fork_free:
63336 free_task(p);
63337 fork_out:
63338+ gr_log_forkfail(retval);
63339+
63340 return ERR_PTR(retval);
63341 }
63342
63343@@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
63344 if (clone_flags & CLONE_PARENT_SETTID)
63345 put_user(nr, parent_tidptr);
63346
63347+ gr_handle_brute_check();
63348+
63349 if (clone_flags & CLONE_VFORK) {
63350 p->vfork_done = &vfork;
63351 init_completion(&vfork);
63352@@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unsh
63353 return 0;
63354
63355 /* don't need lock here; in the worst case we'll do useless copy */
63356- if (fs->users == 1)
63357+ if (atomic_read(&fs->users) == 1)
63358 return 0;
63359
63360 *new_fsp = copy_fs_struct(fs);
63361@@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
63362 fs = current->fs;
63363 write_lock(&fs->lock);
63364 current->fs = new_fs;
63365- if (--fs->users)
63366+ gr_set_chroot_entries(current, &current->fs->root);
63367+ if (atomic_dec_return(&fs->users))
63368 new_fs = NULL;
63369 else
63370 new_fs = fs;
63371diff -urNp linux-2.6.32.44/kernel/futex.c linux-2.6.32.44/kernel/futex.c
63372--- linux-2.6.32.44/kernel/futex.c 2011-03-27 14:31:47.000000000 -0400
63373+++ linux-2.6.32.44/kernel/futex.c 2011-05-16 21:46:57.000000000 -0400
63374@@ -54,6 +54,7 @@
63375 #include <linux/mount.h>
63376 #include <linux/pagemap.h>
63377 #include <linux/syscalls.h>
63378+#include <linux/ptrace.h>
63379 #include <linux/signal.h>
63380 #include <linux/module.h>
63381 #include <linux/magic.h>
63382@@ -221,6 +222,11 @@ get_futex_key(u32 __user *uaddr, int fsh
63383 struct page *page;
63384 int err;
63385
63386+#ifdef CONFIG_PAX_SEGMEXEC
63387+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
63388+ return -EFAULT;
63389+#endif
63390+
63391 /*
63392 * The futex address must be "naturally" aligned.
63393 */
63394@@ -1789,6 +1795,8 @@ static int futex_wait(u32 __user *uaddr,
63395 struct futex_q q;
63396 int ret;
63397
63398+ pax_track_stack();
63399+
63400 if (!bitset)
63401 return -EINVAL;
63402
63403@@ -1841,7 +1849,7 @@ retry:
63404
63405 restart = &current_thread_info()->restart_block;
63406 restart->fn = futex_wait_restart;
63407- restart->futex.uaddr = (u32 *)uaddr;
63408+ restart->futex.uaddr = uaddr;
63409 restart->futex.val = val;
63410 restart->futex.time = abs_time->tv64;
63411 restart->futex.bitset = bitset;
63412@@ -2203,6 +2211,8 @@ static int futex_wait_requeue_pi(u32 __u
63413 struct futex_q q;
63414 int res, ret;
63415
63416+ pax_track_stack();
63417+
63418 if (!bitset)
63419 return -EINVAL;
63420
63421@@ -2377,7 +2387,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
63422 {
63423 struct robust_list_head __user *head;
63424 unsigned long ret;
63425+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
63426 const struct cred *cred = current_cred(), *pcred;
63427+#endif
63428
63429 if (!futex_cmpxchg_enabled)
63430 return -ENOSYS;
63431@@ -2393,11 +2405,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
63432 if (!p)
63433 goto err_unlock;
63434 ret = -EPERM;
63435+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63436+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
63437+ goto err_unlock;
63438+#else
63439 pcred = __task_cred(p);
63440 if (cred->euid != pcred->euid &&
63441 cred->euid != pcred->uid &&
63442 !capable(CAP_SYS_PTRACE))
63443 goto err_unlock;
63444+#endif
63445 head = p->robust_list;
63446 rcu_read_unlock();
63447 }
63448@@ -2459,7 +2476,7 @@ retry:
63449 */
63450 static inline int fetch_robust_entry(struct robust_list __user **entry,
63451 struct robust_list __user * __user *head,
63452- int *pi)
63453+ unsigned int *pi)
63454 {
63455 unsigned long uentry;
63456
63457@@ -2640,6 +2657,7 @@ static int __init futex_init(void)
63458 {
63459 u32 curval;
63460 int i;
63461+ mm_segment_t oldfs;
63462
63463 /*
63464 * This will fail and we want it. Some arch implementations do
63465@@ -2651,7 +2669,10 @@ static int __init futex_init(void)
63466 * implementation, the non functional ones will return
63467 * -ENOSYS.
63468 */
63469+ oldfs = get_fs();
63470+ set_fs(USER_DS);
63471 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
63472+ set_fs(oldfs);
63473 if (curval == -EFAULT)
63474 futex_cmpxchg_enabled = 1;
63475
63476diff -urNp linux-2.6.32.44/kernel/futex_compat.c linux-2.6.32.44/kernel/futex_compat.c
63477--- linux-2.6.32.44/kernel/futex_compat.c 2011-03-27 14:31:47.000000000 -0400
63478+++ linux-2.6.32.44/kernel/futex_compat.c 2011-04-17 15:56:46.000000000 -0400
63479@@ -10,6 +10,7 @@
63480 #include <linux/compat.h>
63481 #include <linux/nsproxy.h>
63482 #include <linux/futex.h>
63483+#include <linux/ptrace.h>
63484
63485 #include <asm/uaccess.h>
63486
63487@@ -135,7 +136,10 @@ compat_sys_get_robust_list(int pid, comp
63488 {
63489 struct compat_robust_list_head __user *head;
63490 unsigned long ret;
63491- const struct cred *cred = current_cred(), *pcred;
63492+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
63493+ const struct cred *cred = current_cred();
63494+ const struct cred *pcred;
63495+#endif
63496
63497 if (!futex_cmpxchg_enabled)
63498 return -ENOSYS;
63499@@ -151,11 +155,16 @@ compat_sys_get_robust_list(int pid, comp
63500 if (!p)
63501 goto err_unlock;
63502 ret = -EPERM;
63503+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63504+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
63505+ goto err_unlock;
63506+#else
63507 pcred = __task_cred(p);
63508 if (cred->euid != pcred->euid &&
63509 cred->euid != pcred->uid &&
63510 !capable(CAP_SYS_PTRACE))
63511 goto err_unlock;
63512+#endif
63513 head = p->compat_robust_list;
63514 read_unlock(&tasklist_lock);
63515 }
63516diff -urNp linux-2.6.32.44/kernel/gcov/base.c linux-2.6.32.44/kernel/gcov/base.c
63517--- linux-2.6.32.44/kernel/gcov/base.c 2011-03-27 14:31:47.000000000 -0400
63518+++ linux-2.6.32.44/kernel/gcov/base.c 2011-04-17 15:56:46.000000000 -0400
63519@@ -102,11 +102,6 @@ void gcov_enable_events(void)
63520 }
63521
63522 #ifdef CONFIG_MODULES
63523-static inline int within(void *addr, void *start, unsigned long size)
63524-{
63525- return ((addr >= start) && (addr < start + size));
63526-}
63527-
63528 /* Update list and generate events when modules are unloaded. */
63529 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63530 void *data)
63531@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
63532 prev = NULL;
63533 /* Remove entries located in module from linked list. */
63534 for (info = gcov_info_head; info; info = info->next) {
63535- if (within(info, mod->module_core, mod->core_size)) {
63536+ if (within_module_core_rw((unsigned long)info, mod)) {
63537 if (prev)
63538 prev->next = info->next;
63539 else
63540diff -urNp linux-2.6.32.44/kernel/hrtimer.c linux-2.6.32.44/kernel/hrtimer.c
63541--- linux-2.6.32.44/kernel/hrtimer.c 2011-03-27 14:31:47.000000000 -0400
63542+++ linux-2.6.32.44/kernel/hrtimer.c 2011-04-17 15:56:46.000000000 -0400
63543@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
63544 local_irq_restore(flags);
63545 }
63546
63547-static void run_hrtimer_softirq(struct softirq_action *h)
63548+static void run_hrtimer_softirq(void)
63549 {
63550 hrtimer_peek_ahead_timers();
63551 }
63552diff -urNp linux-2.6.32.44/kernel/kallsyms.c linux-2.6.32.44/kernel/kallsyms.c
63553--- linux-2.6.32.44/kernel/kallsyms.c 2011-03-27 14:31:47.000000000 -0400
63554+++ linux-2.6.32.44/kernel/kallsyms.c 2011-04-17 15:56:46.000000000 -0400
63555@@ -11,6 +11,9 @@
63556 * Changed the compression method from stem compression to "table lookup"
63557 * compression (see scripts/kallsyms.c for a more complete description)
63558 */
63559+#ifdef CONFIG_GRKERNSEC_HIDESYM
63560+#define __INCLUDED_BY_HIDESYM 1
63561+#endif
63562 #include <linux/kallsyms.h>
63563 #include <linux/module.h>
63564 #include <linux/init.h>
63565@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_mark
63566
63567 static inline int is_kernel_inittext(unsigned long addr)
63568 {
63569+ if (system_state != SYSTEM_BOOTING)
63570+ return 0;
63571+
63572 if (addr >= (unsigned long)_sinittext
63573 && addr <= (unsigned long)_einittext)
63574 return 1;
63575 return 0;
63576 }
63577
63578+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63579+#ifdef CONFIG_MODULES
63580+static inline int is_module_text(unsigned long addr)
63581+{
63582+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
63583+ return 1;
63584+
63585+ addr = ktla_ktva(addr);
63586+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
63587+}
63588+#else
63589+static inline int is_module_text(unsigned long addr)
63590+{
63591+ return 0;
63592+}
63593+#endif
63594+#endif
63595+
63596 static inline int is_kernel_text(unsigned long addr)
63597 {
63598 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
63599@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigne
63600
63601 static inline int is_kernel(unsigned long addr)
63602 {
63603+
63604+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63605+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
63606+ return 1;
63607+
63608+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
63609+#else
63610 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
63611+#endif
63612+
63613 return 1;
63614 return in_gate_area_no_task(addr);
63615 }
63616
63617 static int is_ksym_addr(unsigned long addr)
63618 {
63619+
63620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63621+ if (is_module_text(addr))
63622+ return 0;
63623+#endif
63624+
63625 if (all_var)
63626 return is_kernel(addr);
63627
63628@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(st
63629
63630 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
63631 {
63632- iter->name[0] = '\0';
63633 iter->nameoff = get_symbol_offset(new_pos);
63634 iter->pos = new_pos;
63635 }
63636@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, vo
63637 {
63638 struct kallsym_iter *iter = m->private;
63639
63640+#ifdef CONFIG_GRKERNSEC_HIDESYM
63641+ if (current_uid())
63642+ return 0;
63643+#endif
63644+
63645 /* Some debugging symbols have no name. Ignore them. */
63646 if (!iter->name[0])
63647 return 0;
63648@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *i
63649 struct kallsym_iter *iter;
63650 int ret;
63651
63652- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
63653+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
63654 if (!iter)
63655 return -ENOMEM;
63656 reset_iter(iter, 0);
63657diff -urNp linux-2.6.32.44/kernel/kgdb.c linux-2.6.32.44/kernel/kgdb.c
63658--- linux-2.6.32.44/kernel/kgdb.c 2011-04-17 17:00:52.000000000 -0400
63659+++ linux-2.6.32.44/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
63660@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
63661 /* Guard for recursive entry */
63662 static int exception_level;
63663
63664-static struct kgdb_io *kgdb_io_ops;
63665+static const struct kgdb_io *kgdb_io_ops;
63666 static DEFINE_SPINLOCK(kgdb_registration_lock);
63667
63668 /* kgdb console driver is loaded */
63669@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1)
63670 */
63671 static atomic_t passive_cpu_wait[NR_CPUS];
63672 static atomic_t cpu_in_kgdb[NR_CPUS];
63673-atomic_t kgdb_setting_breakpoint;
63674+atomic_unchecked_t kgdb_setting_breakpoint;
63675
63676 struct task_struct *kgdb_usethread;
63677 struct task_struct *kgdb_contthread;
63678@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBY
63679 sizeof(unsigned long)];
63680
63681 /* to keep track of the CPU which is doing the single stepping*/
63682-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63683+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63684
63685 /*
63686 * If you are debugging a problem where roundup (the collection of
63687@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
63688 return 0;
63689 if (kgdb_connected)
63690 return 1;
63691- if (atomic_read(&kgdb_setting_breakpoint))
63692+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
63693 return 1;
63694 if (print_wait)
63695 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
63696@@ -1426,8 +1426,8 @@ acquirelock:
63697 * instance of the exception handler wanted to come into the
63698 * debugger on a different CPU via a single step
63699 */
63700- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
63701- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
63702+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
63703+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
63704
63705 atomic_set(&kgdb_active, -1);
63706 touch_softlockup_watchdog();
63707@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void
63708 *
63709 * Register it with the KGDB core.
63710 */
63711-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
63712+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
63713 {
63714 int err;
63715
63716@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
63717 *
63718 * Unregister it with the KGDB core.
63719 */
63720-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
63721+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
63722 {
63723 BUG_ON(kgdb_connected);
63724
63725@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod
63726 */
63727 void kgdb_breakpoint(void)
63728 {
63729- atomic_set(&kgdb_setting_breakpoint, 1);
63730+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
63731 wmb(); /* Sync point before breakpoint */
63732 arch_kgdb_breakpoint();
63733 wmb(); /* Sync point after breakpoint */
63734- atomic_set(&kgdb_setting_breakpoint, 0);
63735+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
63736 }
63737 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
63738
63739diff -urNp linux-2.6.32.44/kernel/kmod.c linux-2.6.32.44/kernel/kmod.c
63740--- linux-2.6.32.44/kernel/kmod.c 2011-03-27 14:31:47.000000000 -0400
63741+++ linux-2.6.32.44/kernel/kmod.c 2011-04-17 15:56:46.000000000 -0400
63742@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
63743 * If module auto-loading support is disabled then this function
63744 * becomes a no-operation.
63745 */
63746-int __request_module(bool wait, const char *fmt, ...)
63747+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
63748 {
63749- va_list args;
63750 char module_name[MODULE_NAME_LEN];
63751 unsigned int max_modprobes;
63752 int ret;
63753- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
63754+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
63755 static char *envp[] = { "HOME=/",
63756 "TERM=linux",
63757 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
63758@@ -84,12 +83,24 @@ int __request_module(bool wait, const ch
63759 if (ret)
63760 return ret;
63761
63762- va_start(args, fmt);
63763- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
63764- va_end(args);
63765+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
63766 if (ret >= MODULE_NAME_LEN)
63767 return -ENAMETOOLONG;
63768
63769+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63770+ if (!current_uid()) {
63771+ /* hack to workaround consolekit/udisks stupidity */
63772+ read_lock(&tasklist_lock);
63773+ if (!strcmp(current->comm, "mount") &&
63774+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
63775+ read_unlock(&tasklist_lock);
63776+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
63777+ return -EPERM;
63778+ }
63779+ read_unlock(&tasklist_lock);
63780+ }
63781+#endif
63782+
63783 /* If modprobe needs a service that is in a module, we get a recursive
63784 * loop. Limit the number of running kmod threads to max_threads/2 or
63785 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
63786@@ -121,6 +132,48 @@ int __request_module(bool wait, const ch
63787 atomic_dec(&kmod_concurrent);
63788 return ret;
63789 }
63790+
63791+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
63792+{
63793+ va_list args;
63794+ int ret;
63795+
63796+ va_start(args, fmt);
63797+ ret = ____request_module(wait, module_param, fmt, args);
63798+ va_end(args);
63799+
63800+ return ret;
63801+}
63802+
63803+int __request_module(bool wait, const char *fmt, ...)
63804+{
63805+ va_list args;
63806+ int ret;
63807+
63808+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63809+ if (current_uid()) {
63810+ char module_param[MODULE_NAME_LEN];
63811+
63812+ memset(module_param, 0, sizeof(module_param));
63813+
63814+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
63815+
63816+ va_start(args, fmt);
63817+ ret = ____request_module(wait, module_param, fmt, args);
63818+ va_end(args);
63819+
63820+ return ret;
63821+ }
63822+#endif
63823+
63824+ va_start(args, fmt);
63825+ ret = ____request_module(wait, NULL, fmt, args);
63826+ va_end(args);
63827+
63828+ return ret;
63829+}
63830+
63831+
63832 EXPORT_SYMBOL(__request_module);
63833 #endif /* CONFIG_MODULES */
63834
63835diff -urNp linux-2.6.32.44/kernel/kprobes.c linux-2.6.32.44/kernel/kprobes.c
63836--- linux-2.6.32.44/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
63837+++ linux-2.6.32.44/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
63838@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_
63839 * kernel image and loaded module images reside. This is required
63840 * so x86_64 can correctly handle the %rip-relative fixups.
63841 */
63842- kip->insns = module_alloc(PAGE_SIZE);
63843+ kip->insns = module_alloc_exec(PAGE_SIZE);
63844 if (!kip->insns) {
63845 kfree(kip);
63846 return NULL;
63847@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(st
63848 */
63849 if (!list_is_singular(&kprobe_insn_pages)) {
63850 list_del(&kip->list);
63851- module_free(NULL, kip->insns);
63852+ module_free_exec(NULL, kip->insns);
63853 kfree(kip);
63854 }
63855 return 1;
63856@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
63857 {
63858 int i, err = 0;
63859 unsigned long offset = 0, size = 0;
63860- char *modname, namebuf[128];
63861+ char *modname, namebuf[KSYM_NAME_LEN];
63862 const char *symbol_name;
63863 void *addr;
63864 struct kprobe_blackpoint *kb;
63865@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(st
63866 const char *sym = NULL;
63867 unsigned int i = *(loff_t *) v;
63868 unsigned long offset = 0;
63869- char *modname, namebuf[128];
63870+ char *modname, namebuf[KSYM_NAME_LEN];
63871
63872 head = &kprobe_table[i];
63873 preempt_disable();
63874diff -urNp linux-2.6.32.44/kernel/lockdep.c linux-2.6.32.44/kernel/lockdep.c
63875--- linux-2.6.32.44/kernel/lockdep.c 2011-06-25 12:55:35.000000000 -0400
63876+++ linux-2.6.32.44/kernel/lockdep.c 2011-06-25 12:56:37.000000000 -0400
63877@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_t
63878 /*
63879 * Various lockdep statistics:
63880 */
63881-atomic_t chain_lookup_hits;
63882-atomic_t chain_lookup_misses;
63883-atomic_t hardirqs_on_events;
63884-atomic_t hardirqs_off_events;
63885-atomic_t redundant_hardirqs_on;
63886-atomic_t redundant_hardirqs_off;
63887-atomic_t softirqs_on_events;
63888-atomic_t softirqs_off_events;
63889-atomic_t redundant_softirqs_on;
63890-atomic_t redundant_softirqs_off;
63891-atomic_t nr_unused_locks;
63892-atomic_t nr_cyclic_checks;
63893-atomic_t nr_find_usage_forwards_checks;
63894-atomic_t nr_find_usage_backwards_checks;
63895+atomic_unchecked_t chain_lookup_hits;
63896+atomic_unchecked_t chain_lookup_misses;
63897+atomic_unchecked_t hardirqs_on_events;
63898+atomic_unchecked_t hardirqs_off_events;
63899+atomic_unchecked_t redundant_hardirqs_on;
63900+atomic_unchecked_t redundant_hardirqs_off;
63901+atomic_unchecked_t softirqs_on_events;
63902+atomic_unchecked_t softirqs_off_events;
63903+atomic_unchecked_t redundant_softirqs_on;
63904+atomic_unchecked_t redundant_softirqs_off;
63905+atomic_unchecked_t nr_unused_locks;
63906+atomic_unchecked_t nr_cyclic_checks;
63907+atomic_unchecked_t nr_find_usage_forwards_checks;
63908+atomic_unchecked_t nr_find_usage_backwards_checks;
63909 #endif
63910
63911 /*
63912@@ -577,6 +577,10 @@ static int static_obj(void *obj)
63913 int i;
63914 #endif
63915
63916+#ifdef CONFIG_PAX_KERNEXEC
63917+ start = ktla_ktva(start);
63918+#endif
63919+
63920 /*
63921 * static variable?
63922 */
63923@@ -592,8 +596,7 @@ static int static_obj(void *obj)
63924 */
63925 for_each_possible_cpu(i) {
63926 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
63927- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
63928- + per_cpu_offset(i);
63929+ end = start + PERCPU_ENOUGH_ROOM;
63930
63931 if ((addr >= start) && (addr < end))
63932 return 1;
63933@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *
63934 if (!static_obj(lock->key)) {
63935 debug_locks_off();
63936 printk("INFO: trying to register non-static key.\n");
63937+ printk("lock:%pS key:%pS.\n", lock, lock->key);
63938 printk("the code is fine but needs lockdep annotation.\n");
63939 printk("turning off the locking correctness validator.\n");
63940 dump_stack();
63941@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep
63942 if (!class)
63943 return 0;
63944 }
63945- debug_atomic_inc((atomic_t *)&class->ops);
63946+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
63947 if (very_verbose(class)) {
63948 printk("\nacquire class [%p] %s", class->key, class->name);
63949 if (class->name_version > 1)
63950diff -urNp linux-2.6.32.44/kernel/lockdep_internals.h linux-2.6.32.44/kernel/lockdep_internals.h
63951--- linux-2.6.32.44/kernel/lockdep_internals.h 2011-03-27 14:31:47.000000000 -0400
63952+++ linux-2.6.32.44/kernel/lockdep_internals.h 2011-04-17 15:56:46.000000000 -0400
63953@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_
63954 /*
63955 * Various lockdep statistics:
63956 */
63957-extern atomic_t chain_lookup_hits;
63958-extern atomic_t chain_lookup_misses;
63959-extern atomic_t hardirqs_on_events;
63960-extern atomic_t hardirqs_off_events;
63961-extern atomic_t redundant_hardirqs_on;
63962-extern atomic_t redundant_hardirqs_off;
63963-extern atomic_t softirqs_on_events;
63964-extern atomic_t softirqs_off_events;
63965-extern atomic_t redundant_softirqs_on;
63966-extern atomic_t redundant_softirqs_off;
63967-extern atomic_t nr_unused_locks;
63968-extern atomic_t nr_cyclic_checks;
63969-extern atomic_t nr_cyclic_check_recursions;
63970-extern atomic_t nr_find_usage_forwards_checks;
63971-extern atomic_t nr_find_usage_forwards_recursions;
63972-extern atomic_t nr_find_usage_backwards_checks;
63973-extern atomic_t nr_find_usage_backwards_recursions;
63974-# define debug_atomic_inc(ptr) atomic_inc(ptr)
63975-# define debug_atomic_dec(ptr) atomic_dec(ptr)
63976-# define debug_atomic_read(ptr) atomic_read(ptr)
63977+extern atomic_unchecked_t chain_lookup_hits;
63978+extern atomic_unchecked_t chain_lookup_misses;
63979+extern atomic_unchecked_t hardirqs_on_events;
63980+extern atomic_unchecked_t hardirqs_off_events;
63981+extern atomic_unchecked_t redundant_hardirqs_on;
63982+extern atomic_unchecked_t redundant_hardirqs_off;
63983+extern atomic_unchecked_t softirqs_on_events;
63984+extern atomic_unchecked_t softirqs_off_events;
63985+extern atomic_unchecked_t redundant_softirqs_on;
63986+extern atomic_unchecked_t redundant_softirqs_off;
63987+extern atomic_unchecked_t nr_unused_locks;
63988+extern atomic_unchecked_t nr_cyclic_checks;
63989+extern atomic_unchecked_t nr_cyclic_check_recursions;
63990+extern atomic_unchecked_t nr_find_usage_forwards_checks;
63991+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
63992+extern atomic_unchecked_t nr_find_usage_backwards_checks;
63993+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
63994+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
63995+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
63996+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
63997 #else
63998 # define debug_atomic_inc(ptr) do { } while (0)
63999 # define debug_atomic_dec(ptr) do { } while (0)
64000diff -urNp linux-2.6.32.44/kernel/lockdep_proc.c linux-2.6.32.44/kernel/lockdep_proc.c
64001--- linux-2.6.32.44/kernel/lockdep_proc.c 2011-03-27 14:31:47.000000000 -0400
64002+++ linux-2.6.32.44/kernel/lockdep_proc.c 2011-04-17 15:56:46.000000000 -0400
64003@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
64004
64005 static void print_name(struct seq_file *m, struct lock_class *class)
64006 {
64007- char str[128];
64008+ char str[KSYM_NAME_LEN];
64009 const char *name = class->name;
64010
64011 if (!name) {
64012diff -urNp linux-2.6.32.44/kernel/module.c linux-2.6.32.44/kernel/module.c
64013--- linux-2.6.32.44/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
64014+++ linux-2.6.32.44/kernel/module.c 2011-04-29 18:52:40.000000000 -0400
64015@@ -55,6 +55,7 @@
64016 #include <linux/async.h>
64017 #include <linux/percpu.h>
64018 #include <linux/kmemleak.h>
64019+#include <linux/grsecurity.h>
64020
64021 #define CREATE_TRACE_POINTS
64022 #include <trace/events/module.h>
64023@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
64024 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
64025
64026 /* Bounds of module allocation, for speeding __module_address */
64027-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
64028+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
64029+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
64030
64031 int register_module_notifier(struct notifier_block * nb)
64032 {
64033@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct
64034 return true;
64035
64036 list_for_each_entry_rcu(mod, &modules, list) {
64037- struct symsearch arr[] = {
64038+ struct symsearch modarr[] = {
64039 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
64040 NOT_GPL_ONLY, false },
64041 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
64042@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct
64043 #endif
64044 };
64045
64046- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
64047+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
64048 return true;
64049 }
64050 return false;
64051@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned lo
64052 void *ptr;
64053 int cpu;
64054
64055- if (align > PAGE_SIZE) {
64056+ if (align-1 >= PAGE_SIZE) {
64057 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
64058 name, align, PAGE_SIZE);
64059 align = PAGE_SIZE;
64060@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resol
64061 * /sys/module/foo/sections stuff
64062 * J. Corbet <corbet@lwn.net>
64063 */
64064-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
64065+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64066
64067 static inline bool sect_empty(const Elf_Shdr *sect)
64068 {
64069@@ -1545,7 +1547,8 @@ static void free_module(struct module *m
64070 destroy_params(mod->kp, mod->num_kp);
64071
64072 /* This may be NULL, but that's OK */
64073- module_free(mod, mod->module_init);
64074+ module_free(mod, mod->module_init_rw);
64075+ module_free_exec(mod, mod->module_init_rx);
64076 kfree(mod->args);
64077 if (mod->percpu)
64078 percpu_modfree(mod->percpu);
64079@@ -1554,10 +1557,12 @@ static void free_module(struct module *m
64080 percpu_modfree(mod->refptr);
64081 #endif
64082 /* Free lock-classes: */
64083- lockdep_free_key_range(mod->module_core, mod->core_size);
64084+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
64085+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
64086
64087 /* Finally, free the core (containing the module structure) */
64088- module_free(mod, mod->module_core);
64089+ module_free_exec(mod, mod->module_core_rx);
64090+ module_free(mod, mod->module_core_rw);
64091
64092 #ifdef CONFIG_MPU
64093 update_protections(current->mm);
64094@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *se
64095 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
64096 int ret = 0;
64097 const struct kernel_symbol *ksym;
64098+#ifdef CONFIG_GRKERNSEC_MODHARDEN
64099+ int is_fs_load = 0;
64100+ int register_filesystem_found = 0;
64101+ char *p;
64102+
64103+ p = strstr(mod->args, "grsec_modharden_fs");
64104+
64105+ if (p) {
64106+ char *endptr = p + strlen("grsec_modharden_fs");
64107+ /* copy \0 as well */
64108+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
64109+ is_fs_load = 1;
64110+ }
64111+#endif
64112+
64113
64114 for (i = 1; i < n; i++) {
64115+#ifdef CONFIG_GRKERNSEC_MODHARDEN
64116+ const char *name = strtab + sym[i].st_name;
64117+
64118+ /* it's a real shame this will never get ripped and copied
64119+ upstream! ;(
64120+ */
64121+ if (is_fs_load && !strcmp(name, "register_filesystem"))
64122+ register_filesystem_found = 1;
64123+#endif
64124 switch (sym[i].st_shndx) {
64125 case SHN_COMMON:
64126 /* We compiled with -fno-common. These are not
64127@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *se
64128 strtab + sym[i].st_name, mod);
64129 /* Ok if resolved. */
64130 if (ksym) {
64131+ pax_open_kernel();
64132 sym[i].st_value = ksym->value;
64133+ pax_close_kernel();
64134 break;
64135 }
64136
64137@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *se
64138 secbase = (unsigned long)mod->percpu;
64139 else
64140 secbase = sechdrs[sym[i].st_shndx].sh_addr;
64141+ pax_open_kernel();
64142 sym[i].st_value += secbase;
64143+ pax_close_kernel();
64144 break;
64145 }
64146 }
64147
64148+#ifdef CONFIG_GRKERNSEC_MODHARDEN
64149+ if (is_fs_load && !register_filesystem_found) {
64150+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
64151+ ret = -EPERM;
64152+ }
64153+#endif
64154+
64155 return ret;
64156 }
64157
64158@@ -1731,11 +1771,12 @@ static void layout_sections(struct modul
64159 || s->sh_entsize != ~0UL
64160 || strstarts(secstrings + s->sh_name, ".init"))
64161 continue;
64162- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
64163+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64164+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
64165+ else
64166+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
64167 DEBUGP("\t%s\n", secstrings + s->sh_name);
64168 }
64169- if (m == 0)
64170- mod->core_text_size = mod->core_size;
64171 }
64172
64173 DEBUGP("Init section allocation order:\n");
64174@@ -1748,12 +1789,13 @@ static void layout_sections(struct modul
64175 || s->sh_entsize != ~0UL
64176 || !strstarts(secstrings + s->sh_name, ".init"))
64177 continue;
64178- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
64179- | INIT_OFFSET_MASK);
64180+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64181+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
64182+ else
64183+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
64184+ s->sh_entsize |= INIT_OFFSET_MASK;
64185 DEBUGP("\t%s\n", secstrings + s->sh_name);
64186 }
64187- if (m == 0)
64188- mod->init_text_size = mod->init_size;
64189 }
64190 }
64191
64192@@ -1857,9 +1899,8 @@ static int is_exported(const char *name,
64193
64194 /* As per nm */
64195 static char elf_type(const Elf_Sym *sym,
64196- Elf_Shdr *sechdrs,
64197- const char *secstrings,
64198- struct module *mod)
64199+ const Elf_Shdr *sechdrs,
64200+ const char *secstrings)
64201 {
64202 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
64203 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
64204@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struc
64205
64206 /* Put symbol section at end of init part of module. */
64207 symsect->sh_flags |= SHF_ALLOC;
64208- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
64209+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
64210 symindex) | INIT_OFFSET_MASK;
64211 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
64212
64213@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struc
64214 }
64215
64216 /* Append room for core symbols at end of core part. */
64217- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
64218- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
64219+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
64220+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
64221
64222 /* Put string table section at end of init part of module. */
64223 strsect->sh_flags |= SHF_ALLOC;
64224- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
64225+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
64226 strindex) | INIT_OFFSET_MASK;
64227 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
64228
64229 /* Append room for core symbols' strings at end of core part. */
64230- *pstroffs = mod->core_size;
64231+ *pstroffs = mod->core_size_rx;
64232 __set_bit(0, strmap);
64233- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
64234+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
64235
64236 return symoffs;
64237 }
64238@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *
64239 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
64240 mod->strtab = (void *)sechdrs[strindex].sh_addr;
64241
64242+ pax_open_kernel();
64243+
64244 /* Set types up while we still have access to sections. */
64245 for (i = 0; i < mod->num_symtab; i++)
64246 mod->symtab[i].st_info
64247- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
64248+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
64249
64250- mod->core_symtab = dst = mod->module_core + symoffs;
64251+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
64252 src = mod->symtab;
64253 *dst = *src;
64254 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
64255@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *
64256 }
64257 mod->core_num_syms = ndst;
64258
64259- mod->core_strtab = s = mod->module_core + stroffs;
64260+ mod->core_strtab = s = mod->module_core_rx + stroffs;
64261 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
64262 if (test_bit(i, strmap))
64263 *++s = mod->strtab[i];
64264+
64265+ pax_close_kernel();
64266 }
64267 #else
64268 static inline unsigned long layout_symtab(struct module *mod,
64269@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _
64270 #endif
64271 }
64272
64273-static void *module_alloc_update_bounds(unsigned long size)
64274+static void *module_alloc_update_bounds_rw(unsigned long size)
64275 {
64276 void *ret = module_alloc(size);
64277
64278 if (ret) {
64279 /* Update module bounds. */
64280- if ((unsigned long)ret < module_addr_min)
64281- module_addr_min = (unsigned long)ret;
64282- if ((unsigned long)ret + size > module_addr_max)
64283- module_addr_max = (unsigned long)ret + size;
64284+ if ((unsigned long)ret < module_addr_min_rw)
64285+ module_addr_min_rw = (unsigned long)ret;
64286+ if ((unsigned long)ret + size > module_addr_max_rw)
64287+ module_addr_max_rw = (unsigned long)ret + size;
64288+ }
64289+ return ret;
64290+}
64291+
64292+static void *module_alloc_update_bounds_rx(unsigned long size)
64293+{
64294+ void *ret = module_alloc_exec(size);
64295+
64296+ if (ret) {
64297+ /* Update module bounds. */
64298+ if ((unsigned long)ret < module_addr_min_rx)
64299+ module_addr_min_rx = (unsigned long)ret;
64300+ if ((unsigned long)ret + size > module_addr_max_rx)
64301+ module_addr_max_rx = (unsigned long)ret + size;
64302 }
64303 return ret;
64304 }
64305@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct
64306 unsigned int i;
64307
64308 /* only scan the sections containing data */
64309- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
64310- (unsigned long)mod->module_core,
64311+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
64312+ (unsigned long)mod->module_core_rw,
64313 sizeof(struct module), GFP_KERNEL);
64314
64315 for (i = 1; i < hdr->e_shnum; i++) {
64316@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct
64317 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
64318 continue;
64319
64320- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
64321- (unsigned long)mod->module_core,
64322+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
64323+ (unsigned long)mod->module_core_rw,
64324 sechdrs[i].sh_size, GFP_KERNEL);
64325 }
64326 }
64327@@ -2263,7 +2322,7 @@ static noinline struct module *load_modu
64328 secstrings, &stroffs, strmap);
64329
64330 /* Do the allocs. */
64331- ptr = module_alloc_update_bounds(mod->core_size);
64332+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
64333 /*
64334 * The pointer to this block is stored in the module structure
64335 * which is inside the block. Just mark it as not being a
64336@@ -2274,23 +2333,47 @@ static noinline struct module *load_modu
64337 err = -ENOMEM;
64338 goto free_percpu;
64339 }
64340- memset(ptr, 0, mod->core_size);
64341- mod->module_core = ptr;
64342+ memset(ptr, 0, mod->core_size_rw);
64343+ mod->module_core_rw = ptr;
64344
64345- ptr = module_alloc_update_bounds(mod->init_size);
64346+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
64347 /*
64348 * The pointer to this block is stored in the module structure
64349 * which is inside the block. This block doesn't need to be
64350 * scanned as it contains data and code that will be freed
64351 * after the module is initialized.
64352 */
64353- kmemleak_ignore(ptr);
64354- if (!ptr && mod->init_size) {
64355+ kmemleak_not_leak(ptr);
64356+ if (!ptr && mod->init_size_rw) {
64357+ err = -ENOMEM;
64358+ goto free_core_rw;
64359+ }
64360+ memset(ptr, 0, mod->init_size_rw);
64361+ mod->module_init_rw = ptr;
64362+
64363+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
64364+ kmemleak_not_leak(ptr);
64365+ if (!ptr) {
64366 err = -ENOMEM;
64367- goto free_core;
64368+ goto free_init_rw;
64369 }
64370- memset(ptr, 0, mod->init_size);
64371- mod->module_init = ptr;
64372+
64373+ pax_open_kernel();
64374+ memset(ptr, 0, mod->core_size_rx);
64375+ pax_close_kernel();
64376+ mod->module_core_rx = ptr;
64377+
64378+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
64379+ kmemleak_not_leak(ptr);
64380+ if (!ptr && mod->init_size_rx) {
64381+ err = -ENOMEM;
64382+ goto free_core_rx;
64383+ }
64384+
64385+ pax_open_kernel();
64386+ memset(ptr, 0, mod->init_size_rx);
64387+ pax_close_kernel();
64388+ mod->module_init_rx = ptr;
64389
64390 /* Transfer each section which specifies SHF_ALLOC */
64391 DEBUGP("final section addresses:\n");
64392@@ -2300,17 +2383,45 @@ static noinline struct module *load_modu
64393 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
64394 continue;
64395
64396- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
64397- dest = mod->module_init
64398- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
64399- else
64400- dest = mod->module_core + sechdrs[i].sh_entsize;
64401+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
64402+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
64403+ dest = mod->module_init_rw
64404+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
64405+ else
64406+ dest = mod->module_init_rx
64407+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
64408+ } else {
64409+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
64410+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
64411+ else
64412+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
64413+ }
64414+
64415+ if (sechdrs[i].sh_type != SHT_NOBITS) {
64416
64417- if (sechdrs[i].sh_type != SHT_NOBITS)
64418- memcpy(dest, (void *)sechdrs[i].sh_addr,
64419- sechdrs[i].sh_size);
64420+#ifdef CONFIG_PAX_KERNEXEC
64421+#ifdef CONFIG_X86_64
64422+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
64423+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
64424+#endif
64425+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
64426+ pax_open_kernel();
64427+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
64428+ pax_close_kernel();
64429+ } else
64430+#endif
64431+
64432+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
64433+ }
64434 /* Update sh_addr to point to copy in image. */
64435- sechdrs[i].sh_addr = (unsigned long)dest;
64436+
64437+#ifdef CONFIG_PAX_KERNEXEC
64438+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
64439+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
64440+ else
64441+#endif
64442+
64443+ sechdrs[i].sh_addr = (unsigned long)dest;
64444 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
64445 }
64446 /* Module has been moved. */
64447@@ -2322,7 +2433,7 @@ static noinline struct module *load_modu
64448 mod->name);
64449 if (!mod->refptr) {
64450 err = -ENOMEM;
64451- goto free_init;
64452+ goto free_init_rx;
64453 }
64454 #endif
64455 /* Now we've moved module, initialize linked lists, etc. */
64456@@ -2351,6 +2462,31 @@ static noinline struct module *load_modu
64457 /* Set up MODINFO_ATTR fields */
64458 setup_modinfo(mod, sechdrs, infoindex);
64459
64460+ mod->args = args;
64461+
64462+#ifdef CONFIG_GRKERNSEC_MODHARDEN
64463+ {
64464+ char *p, *p2;
64465+
64466+ if (strstr(mod->args, "grsec_modharden_netdev")) {
64467+ 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);
64468+ err = -EPERM;
64469+ goto cleanup;
64470+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
64471+ p += strlen("grsec_modharden_normal");
64472+ p2 = strstr(p, "_");
64473+ if (p2) {
64474+ *p2 = '\0';
64475+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
64476+ *p2 = '_';
64477+ }
64478+ err = -EPERM;
64479+ goto cleanup;
64480+ }
64481+ }
64482+#endif
64483+
64484+
64485 /* Fix up syms, so that st_value is a pointer to location. */
64486 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
64487 mod);
64488@@ -2431,8 +2567,8 @@ static noinline struct module *load_modu
64489
64490 /* Now do relocations. */
64491 for (i = 1; i < hdr->e_shnum; i++) {
64492- const char *strtab = (char *)sechdrs[strindex].sh_addr;
64493 unsigned int info = sechdrs[i].sh_info;
64494+ strtab = (char *)sechdrs[strindex].sh_addr;
64495
64496 /* Not a valid relocation section? */
64497 if (info >= hdr->e_shnum)
64498@@ -2493,16 +2629,15 @@ static noinline struct module *load_modu
64499 * Do it before processing of module parameters, so the module
64500 * can provide parameter accessor functions of its own.
64501 */
64502- if (mod->module_init)
64503- flush_icache_range((unsigned long)mod->module_init,
64504- (unsigned long)mod->module_init
64505- + mod->init_size);
64506- flush_icache_range((unsigned long)mod->module_core,
64507- (unsigned long)mod->module_core + mod->core_size);
64508+ if (mod->module_init_rx)
64509+ flush_icache_range((unsigned long)mod->module_init_rx,
64510+ (unsigned long)mod->module_init_rx
64511+ + mod->init_size_rx);
64512+ flush_icache_range((unsigned long)mod->module_core_rx,
64513+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
64514
64515 set_fs(old_fs);
64516
64517- mod->args = args;
64518 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
64519 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
64520 mod->name);
64521@@ -2546,12 +2681,16 @@ static noinline struct module *load_modu
64522 free_unload:
64523 module_unload_free(mod);
64524 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
64525+ free_init_rx:
64526 percpu_modfree(mod->refptr);
64527- free_init:
64528 #endif
64529- module_free(mod, mod->module_init);
64530- free_core:
64531- module_free(mod, mod->module_core);
64532+ module_free_exec(mod, mod->module_init_rx);
64533+ free_core_rx:
64534+ module_free_exec(mod, mod->module_core_rx);
64535+ free_init_rw:
64536+ module_free(mod, mod->module_init_rw);
64537+ free_core_rw:
64538+ module_free(mod, mod->module_core_rw);
64539 /* mod will be freed with core. Don't access it beyond this line! */
64540 free_percpu:
64541 if (percpu)
64542@@ -2653,10 +2792,12 @@ SYSCALL_DEFINE3(init_module, void __user
64543 mod->symtab = mod->core_symtab;
64544 mod->strtab = mod->core_strtab;
64545 #endif
64546- module_free(mod, mod->module_init);
64547- mod->module_init = NULL;
64548- mod->init_size = 0;
64549- mod->init_text_size = 0;
64550+ module_free(mod, mod->module_init_rw);
64551+ module_free_exec(mod, mod->module_init_rx);
64552+ mod->module_init_rw = NULL;
64553+ mod->module_init_rx = NULL;
64554+ mod->init_size_rw = 0;
64555+ mod->init_size_rx = 0;
64556 mutex_unlock(&module_mutex);
64557
64558 return 0;
64559@@ -2687,10 +2828,16 @@ static const char *get_ksymbol(struct mo
64560 unsigned long nextval;
64561
64562 /* At worse, next value is at end of module */
64563- if (within_module_init(addr, mod))
64564- nextval = (unsigned long)mod->module_init+mod->init_text_size;
64565+ if (within_module_init_rx(addr, mod))
64566+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
64567+ else if (within_module_init_rw(addr, mod))
64568+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
64569+ else if (within_module_core_rx(addr, mod))
64570+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
64571+ else if (within_module_core_rw(addr, mod))
64572+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
64573 else
64574- nextval = (unsigned long)mod->module_core+mod->core_text_size;
64575+ return NULL;
64576
64577 /* Scan for closest preceeding symbol, and next symbol. (ELF
64578 starts real symbols at 1). */
64579@@ -2936,7 +3083,7 @@ static int m_show(struct seq_file *m, vo
64580 char buf[8];
64581
64582 seq_printf(m, "%s %u",
64583- mod->name, mod->init_size + mod->core_size);
64584+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
64585 print_unload_info(m, mod);
64586
64587 /* Informative for users. */
64588@@ -2945,7 +3092,7 @@ static int m_show(struct seq_file *m, vo
64589 mod->state == MODULE_STATE_COMING ? "Loading":
64590 "Live");
64591 /* Used by oprofile and other similar tools. */
64592- seq_printf(m, " 0x%p", mod->module_core);
64593+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
64594
64595 /* Taints info */
64596 if (mod->taints)
64597@@ -2981,7 +3128,17 @@ static const struct file_operations proc
64598
64599 static int __init proc_modules_init(void)
64600 {
64601+#ifndef CONFIG_GRKERNSEC_HIDESYM
64602+#ifdef CONFIG_GRKERNSEC_PROC_USER
64603+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64604+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64605+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
64606+#else
64607 proc_create("modules", 0, NULL, &proc_modules_operations);
64608+#endif
64609+#else
64610+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64611+#endif
64612 return 0;
64613 }
64614 module_init(proc_modules_init);
64615@@ -3040,12 +3197,12 @@ struct module *__module_address(unsigned
64616 {
64617 struct module *mod;
64618
64619- if (addr < module_addr_min || addr > module_addr_max)
64620+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
64621+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
64622 return NULL;
64623
64624 list_for_each_entry_rcu(mod, &modules, list)
64625- if (within_module_core(addr, mod)
64626- || within_module_init(addr, mod))
64627+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
64628 return mod;
64629 return NULL;
64630 }
64631@@ -3079,11 +3236,20 @@ bool is_module_text_address(unsigned lon
64632 */
64633 struct module *__module_text_address(unsigned long addr)
64634 {
64635- struct module *mod = __module_address(addr);
64636+ struct module *mod;
64637+
64638+#ifdef CONFIG_X86_32
64639+ addr = ktla_ktva(addr);
64640+#endif
64641+
64642+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
64643+ return NULL;
64644+
64645+ mod = __module_address(addr);
64646+
64647 if (mod) {
64648 /* Make sure it's within the text section. */
64649- if (!within(addr, mod->module_init, mod->init_text_size)
64650- && !within(addr, mod->module_core, mod->core_text_size))
64651+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
64652 mod = NULL;
64653 }
64654 return mod;
64655diff -urNp linux-2.6.32.44/kernel/mutex.c linux-2.6.32.44/kernel/mutex.c
64656--- linux-2.6.32.44/kernel/mutex.c 2011-03-27 14:31:47.000000000 -0400
64657+++ linux-2.6.32.44/kernel/mutex.c 2011-04-17 15:56:46.000000000 -0400
64658@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock,
64659 */
64660
64661 for (;;) {
64662- struct thread_info *owner;
64663+ struct task_struct *owner;
64664
64665 /*
64666 * If we own the BKL, then don't spin. The owner of
64667@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock,
64668 spin_lock_mutex(&lock->wait_lock, flags);
64669
64670 debug_mutex_lock_common(lock, &waiter);
64671- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
64672+ debug_mutex_add_waiter(lock, &waiter, task);
64673
64674 /* add waiting tasks to the end of the waitqueue (FIFO): */
64675 list_add_tail(&waiter.list, &lock->wait_list);
64676@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock,
64677 * TASK_UNINTERRUPTIBLE case.)
64678 */
64679 if (unlikely(signal_pending_state(state, task))) {
64680- mutex_remove_waiter(lock, &waiter,
64681- task_thread_info(task));
64682+ mutex_remove_waiter(lock, &waiter, task);
64683 mutex_release(&lock->dep_map, 1, ip);
64684 spin_unlock_mutex(&lock->wait_lock, flags);
64685
64686@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock,
64687 done:
64688 lock_acquired(&lock->dep_map, ip);
64689 /* got the lock - rejoice! */
64690- mutex_remove_waiter(lock, &waiter, current_thread_info());
64691+ mutex_remove_waiter(lock, &waiter, task);
64692 mutex_set_owner(lock);
64693
64694 /* set it to 0 if there are no waiters left: */
64695diff -urNp linux-2.6.32.44/kernel/mutex-debug.c linux-2.6.32.44/kernel/mutex-debug.c
64696--- linux-2.6.32.44/kernel/mutex-debug.c 2011-03-27 14:31:47.000000000 -0400
64697+++ linux-2.6.32.44/kernel/mutex-debug.c 2011-04-17 15:56:46.000000000 -0400
64698@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
64699 }
64700
64701 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64702- struct thread_info *ti)
64703+ struct task_struct *task)
64704 {
64705 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
64706
64707 /* Mark the current thread as blocked on the lock: */
64708- ti->task->blocked_on = waiter;
64709+ task->blocked_on = waiter;
64710 }
64711
64712 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64713- struct thread_info *ti)
64714+ struct task_struct *task)
64715 {
64716 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
64717- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
64718- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
64719- ti->task->blocked_on = NULL;
64720+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
64721+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
64722+ task->blocked_on = NULL;
64723
64724 list_del_init(&waiter->list);
64725 waiter->task = NULL;
64726@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
64727 return;
64728
64729 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
64730- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
64731+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
64732 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
64733 mutex_clear_owner(lock);
64734 }
64735diff -urNp linux-2.6.32.44/kernel/mutex-debug.h linux-2.6.32.44/kernel/mutex-debug.h
64736--- linux-2.6.32.44/kernel/mutex-debug.h 2011-03-27 14:31:47.000000000 -0400
64737+++ linux-2.6.32.44/kernel/mutex-debug.h 2011-04-17 15:56:46.000000000 -0400
64738@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
64739 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
64740 extern void debug_mutex_add_waiter(struct mutex *lock,
64741 struct mutex_waiter *waiter,
64742- struct thread_info *ti);
64743+ struct task_struct *task);
64744 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64745- struct thread_info *ti);
64746+ struct task_struct *task);
64747 extern void debug_mutex_unlock(struct mutex *lock);
64748 extern void debug_mutex_init(struct mutex *lock, const char *name,
64749 struct lock_class_key *key);
64750
64751 static inline void mutex_set_owner(struct mutex *lock)
64752 {
64753- lock->owner = current_thread_info();
64754+ lock->owner = current;
64755 }
64756
64757 static inline void mutex_clear_owner(struct mutex *lock)
64758diff -urNp linux-2.6.32.44/kernel/mutex.h linux-2.6.32.44/kernel/mutex.h
64759--- linux-2.6.32.44/kernel/mutex.h 2011-03-27 14:31:47.000000000 -0400
64760+++ linux-2.6.32.44/kernel/mutex.h 2011-04-17 15:56:46.000000000 -0400
64761@@ -19,7 +19,7 @@
64762 #ifdef CONFIG_SMP
64763 static inline void mutex_set_owner(struct mutex *lock)
64764 {
64765- lock->owner = current_thread_info();
64766+ lock->owner = current;
64767 }
64768
64769 static inline void mutex_clear_owner(struct mutex *lock)
64770diff -urNp linux-2.6.32.44/kernel/panic.c linux-2.6.32.44/kernel/panic.c
64771--- linux-2.6.32.44/kernel/panic.c 2011-03-27 14:31:47.000000000 -0400
64772+++ linux-2.6.32.44/kernel/panic.c 2011-04-17 15:56:46.000000000 -0400
64773@@ -352,7 +352,7 @@ static void warn_slowpath_common(const c
64774 const char *board;
64775
64776 printk(KERN_WARNING "------------[ cut here ]------------\n");
64777- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
64778+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
64779 board = dmi_get_system_info(DMI_PRODUCT_NAME);
64780 if (board)
64781 printk(KERN_WARNING "Hardware name: %s\n", board);
64782@@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
64783 */
64784 void __stack_chk_fail(void)
64785 {
64786- panic("stack-protector: Kernel stack is corrupted in: %p\n",
64787+ dump_stack();
64788+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
64789 __builtin_return_address(0));
64790 }
64791 EXPORT_SYMBOL(__stack_chk_fail);
64792diff -urNp linux-2.6.32.44/kernel/params.c linux-2.6.32.44/kernel/params.c
64793--- linux-2.6.32.44/kernel/params.c 2011-03-27 14:31:47.000000000 -0400
64794+++ linux-2.6.32.44/kernel/params.c 2011-04-17 15:56:46.000000000 -0400
64795@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct
64796 return ret;
64797 }
64798
64799-static struct sysfs_ops module_sysfs_ops = {
64800+static const struct sysfs_ops module_sysfs_ops = {
64801 .show = module_attr_show,
64802 .store = module_attr_store,
64803 };
64804@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *ks
64805 return 0;
64806 }
64807
64808-static struct kset_uevent_ops module_uevent_ops = {
64809+static const struct kset_uevent_ops module_uevent_ops = {
64810 .filter = uevent_filter,
64811 };
64812
64813diff -urNp linux-2.6.32.44/kernel/perf_event.c linux-2.6.32.44/kernel/perf_event.c
64814--- linux-2.6.32.44/kernel/perf_event.c 2011-08-09 18:35:30.000000000 -0400
64815+++ linux-2.6.32.44/kernel/perf_event.c 2011-08-09 18:34:01.000000000 -0400
64816@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostl
64817 */
64818 int sysctl_perf_event_sample_rate __read_mostly = 100000;
64819
64820-static atomic64_t perf_event_id;
64821+static atomic64_unchecked_t perf_event_id;
64822
64823 /*
64824 * Lock for (sysadmin-configurable) event reservations:
64825@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struc
64826 * In order to keep per-task stats reliable we need to flip the event
64827 * values when we flip the contexts.
64828 */
64829- value = atomic64_read(&next_event->count);
64830- value = atomic64_xchg(&event->count, value);
64831- atomic64_set(&next_event->count, value);
64832+ value = atomic64_read_unchecked(&next_event->count);
64833+ value = atomic64_xchg_unchecked(&event->count, value);
64834+ atomic64_set_unchecked(&next_event->count, value);
64835
64836 swap(event->total_time_enabled, next_event->total_time_enabled);
64837 swap(event->total_time_running, next_event->total_time_running);
64838@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_e
64839 update_event_times(event);
64840 }
64841
64842- return atomic64_read(&event->count);
64843+ return atomic64_read_unchecked(&event->count);
64844 }
64845
64846 /*
64847@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct
64848 values[n++] = 1 + leader->nr_siblings;
64849 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64850 values[n++] = leader->total_time_enabled +
64851- atomic64_read(&leader->child_total_time_enabled);
64852+ atomic64_read_unchecked(&leader->child_total_time_enabled);
64853 }
64854 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64855 values[n++] = leader->total_time_running +
64856- atomic64_read(&leader->child_total_time_running);
64857+ atomic64_read_unchecked(&leader->child_total_time_running);
64858 }
64859
64860 size = n * sizeof(u64);
64861@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct pe
64862 values[n++] = perf_event_read_value(event);
64863 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64864 values[n++] = event->total_time_enabled +
64865- atomic64_read(&event->child_total_time_enabled);
64866+ atomic64_read_unchecked(&event->child_total_time_enabled);
64867 }
64868 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64869 values[n++] = event->total_time_running +
64870- atomic64_read(&event->child_total_time_running);
64871+ atomic64_read_unchecked(&event->child_total_time_running);
64872 }
64873 if (read_format & PERF_FORMAT_ID)
64874 values[n++] = primary_event_id(event);
64875@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct fil
64876 static void perf_event_reset(struct perf_event *event)
64877 {
64878 (void)perf_event_read(event);
64879- atomic64_set(&event->count, 0);
64880+ atomic64_set_unchecked(&event->count, 0);
64881 perf_event_update_userpage(event);
64882 }
64883
64884@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct p
64885 ++userpg->lock;
64886 barrier();
64887 userpg->index = perf_event_index(event);
64888- userpg->offset = atomic64_read(&event->count);
64889+ userpg->offset = atomic64_read_unchecked(&event->count);
64890 if (event->state == PERF_EVENT_STATE_ACTIVE)
64891- userpg->offset -= atomic64_read(&event->hw.prev_count);
64892+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
64893
64894 userpg->time_enabled = event->total_time_enabled +
64895- atomic64_read(&event->child_total_time_enabled);
64896+ atomic64_read_unchecked(&event->child_total_time_enabled);
64897
64898 userpg->time_running = event->total_time_running +
64899- atomic64_read(&event->child_total_time_running);
64900+ atomic64_read_unchecked(&event->child_total_time_running);
64901
64902 barrier();
64903 ++userpg->lock;
64904@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct
64905 u64 values[4];
64906 int n = 0;
64907
64908- values[n++] = atomic64_read(&event->count);
64909+ values[n++] = atomic64_read_unchecked(&event->count);
64910 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64911 values[n++] = event->total_time_enabled +
64912- atomic64_read(&event->child_total_time_enabled);
64913+ atomic64_read_unchecked(&event->child_total_time_enabled);
64914 }
64915 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64916 values[n++] = event->total_time_running +
64917- atomic64_read(&event->child_total_time_running);
64918+ atomic64_read_unchecked(&event->child_total_time_running);
64919 }
64920 if (read_format & PERF_FORMAT_ID)
64921 values[n++] = primary_event_id(event);
64922@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struc
64923 if (leader != event)
64924 leader->pmu->read(leader);
64925
64926- values[n++] = atomic64_read(&leader->count);
64927+ values[n++] = atomic64_read_unchecked(&leader->count);
64928 if (read_format & PERF_FORMAT_ID)
64929 values[n++] = primary_event_id(leader);
64930
64931@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struc
64932 if (sub != event)
64933 sub->pmu->read(sub);
64934
64935- values[n++] = atomic64_read(&sub->count);
64936+ values[n++] = atomic64_read_unchecked(&sub->count);
64937 if (read_format & PERF_FORMAT_ID)
64938 values[n++] = primary_event_id(sub);
64939
64940@@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf
64941 {
64942 struct hw_perf_event *hwc = &event->hw;
64943
64944- atomic64_add(nr, &event->count);
64945+ atomic64_add_unchecked(nr, &event->count);
64946
64947 if (!hwc->sample_period)
64948 return;
64949@@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(
64950 u64 now;
64951
64952 now = cpu_clock(cpu);
64953- prev = atomic64_read(&event->hw.prev_count);
64954- atomic64_set(&event->hw.prev_count, now);
64955- atomic64_add(now - prev, &event->count);
64956+ prev = atomic64_read_unchecked(&event->hw.prev_count);
64957+ atomic64_set_unchecked(&event->hw.prev_count, now);
64958+ atomic64_add_unchecked(now - prev, &event->count);
64959 }
64960
64961 static int cpu_clock_perf_event_enable(struct perf_event *event)
64962@@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(s
64963 struct hw_perf_event *hwc = &event->hw;
64964 int cpu = raw_smp_processor_id();
64965
64966- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
64967+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
64968 perf_swevent_start_hrtimer(event);
64969
64970 return 0;
64971@@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update
64972 u64 prev;
64973 s64 delta;
64974
64975- prev = atomic64_xchg(&event->hw.prev_count, now);
64976+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
64977 delta = now - prev;
64978- atomic64_add(delta, &event->count);
64979+ atomic64_add_unchecked(delta, &event->count);
64980 }
64981
64982 static int task_clock_perf_event_enable(struct perf_event *event)
64983@@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(
64984
64985 now = event->ctx->time;
64986
64987- atomic64_set(&hwc->prev_count, now);
64988+ atomic64_set_unchecked(&hwc->prev_count, now);
64989
64990 perf_swevent_start_hrtimer(event);
64991
64992@@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr
64993 event->parent = parent_event;
64994
64995 event->ns = get_pid_ns(current->nsproxy->pid_ns);
64996- event->id = atomic64_inc_return(&perf_event_id);
64997+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
64998
64999 event->state = PERF_EVENT_STATE_INACTIVE;
65000
65001@@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf
65002 if (child_event->attr.inherit_stat)
65003 perf_event_read_event(child_event, child);
65004
65005- child_val = atomic64_read(&child_event->count);
65006+ child_val = atomic64_read_unchecked(&child_event->count);
65007
65008 /*
65009 * Add back the child's count to the parent's count:
65010 */
65011- atomic64_add(child_val, &parent_event->count);
65012- atomic64_add(child_event->total_time_enabled,
65013+ atomic64_add_unchecked(child_val, &parent_event->count);
65014+ atomic64_add_unchecked(child_event->total_time_enabled,
65015 &parent_event->child_total_time_enabled);
65016- atomic64_add(child_event->total_time_running,
65017+ atomic64_add_unchecked(child_event->total_time_running,
65018 &parent_event->child_total_time_running);
65019
65020 /*
65021diff -urNp linux-2.6.32.44/kernel/pid.c linux-2.6.32.44/kernel/pid.c
65022--- linux-2.6.32.44/kernel/pid.c 2011-04-22 19:16:29.000000000 -0400
65023+++ linux-2.6.32.44/kernel/pid.c 2011-07-14 19:15:33.000000000 -0400
65024@@ -33,6 +33,7 @@
65025 #include <linux/rculist.h>
65026 #include <linux/bootmem.h>
65027 #include <linux/hash.h>
65028+#include <linux/security.h>
65029 #include <linux/pid_namespace.h>
65030 #include <linux/init_task.h>
65031 #include <linux/syscalls.h>
65032@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
65033
65034 int pid_max = PID_MAX_DEFAULT;
65035
65036-#define RESERVED_PIDS 300
65037+#define RESERVED_PIDS 500
65038
65039 int pid_max_min = RESERVED_PIDS + 1;
65040 int pid_max_max = PID_MAX_LIMIT;
65041@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
65042 */
65043 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
65044 {
65045- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65046+ struct task_struct *task;
65047+
65048+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65049+
65050+ if (gr_pid_is_chrooted(task))
65051+ return NULL;
65052+
65053+ return task;
65054 }
65055
65056 struct task_struct *find_task_by_vpid(pid_t vnr)
65057@@ -391,6 +399,13 @@ struct task_struct *find_task_by_vpid(pi
65058 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
65059 }
65060
65061+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
65062+{
65063+ struct task_struct *task;
65064+
65065+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
65066+}
65067+
65068 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
65069 {
65070 struct pid *pid;
65071diff -urNp linux-2.6.32.44/kernel/posix-cpu-timers.c linux-2.6.32.44/kernel/posix-cpu-timers.c
65072--- linux-2.6.32.44/kernel/posix-cpu-timers.c 2011-03-27 14:31:47.000000000 -0400
65073+++ linux-2.6.32.44/kernel/posix-cpu-timers.c 2011-08-06 09:33:44.000000000 -0400
65074@@ -6,6 +6,7 @@
65075 #include <linux/posix-timers.h>
65076 #include <linux/errno.h>
65077 #include <linux/math64.h>
65078+#include <linux/security.h>
65079 #include <asm/uaccess.h>
65080 #include <linux/kernel_stat.h>
65081 #include <trace/events/timer.h>
65082@@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(st
65083
65084 static __init int init_posix_cpu_timers(void)
65085 {
65086- struct k_clock process = {
65087+ static struct k_clock process = {
65088 .clock_getres = process_cpu_clock_getres,
65089 .clock_get = process_cpu_clock_get,
65090 .clock_set = do_posix_clock_nosettime,
65091@@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(
65092 .nsleep = process_cpu_nsleep,
65093 .nsleep_restart = process_cpu_nsleep_restart,
65094 };
65095- struct k_clock thread = {
65096+ static struct k_clock thread = {
65097 .clock_getres = thread_cpu_clock_getres,
65098 .clock_get = thread_cpu_clock_get,
65099 .clock_set = do_posix_clock_nosettime,
65100diff -urNp linux-2.6.32.44/kernel/posix-timers.c linux-2.6.32.44/kernel/posix-timers.c
65101--- linux-2.6.32.44/kernel/posix-timers.c 2011-03-27 14:31:47.000000000 -0400
65102+++ linux-2.6.32.44/kernel/posix-timers.c 2011-08-06 09:34:14.000000000 -0400
65103@@ -42,6 +42,7 @@
65104 #include <linux/compiler.h>
65105 #include <linux/idr.h>
65106 #include <linux/posix-timers.h>
65107+#include <linux/grsecurity.h>
65108 #include <linux/syscalls.h>
65109 #include <linux/wait.h>
65110 #include <linux/workqueue.h>
65111@@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
65112 * which we beg off on and pass to do_sys_settimeofday().
65113 */
65114
65115-static struct k_clock posix_clocks[MAX_CLOCKS];
65116+static struct k_clock *posix_clocks[MAX_CLOCKS];
65117
65118 /*
65119 * These ones are defined below.
65120@@ -157,8 +158,8 @@ static inline void unlock_timer(struct k
65121 */
65122 #define CLOCK_DISPATCH(clock, call, arglist) \
65123 ((clock) < 0 ? posix_cpu_##call arglist : \
65124- (posix_clocks[clock].call != NULL \
65125- ? (*posix_clocks[clock].call) arglist : common_##call arglist))
65126+ (posix_clocks[clock]->call != NULL \
65127+ ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
65128
65129 /*
65130 * Default clock hook functions when the struct k_clock passed
65131@@ -172,7 +173,7 @@ static inline int common_clock_getres(co
65132 struct timespec *tp)
65133 {
65134 tp->tv_sec = 0;
65135- tp->tv_nsec = posix_clocks[which_clock].res;
65136+ tp->tv_nsec = posix_clocks[which_clock]->res;
65137 return 0;
65138 }
65139
65140@@ -217,9 +218,11 @@ static inline int invalid_clockid(const
65141 return 0;
65142 if ((unsigned) which_clock >= MAX_CLOCKS)
65143 return 1;
65144- if (posix_clocks[which_clock].clock_getres != NULL)
65145+ if (!posix_clocks[which_clock])
65146 return 0;
65147- if (posix_clocks[which_clock].res != 0)
65148+ if (posix_clocks[which_clock]->clock_getres != NULL)
65149+ return 0;
65150+ if (posix_clocks[which_clock]->res != 0)
65151 return 0;
65152 return 1;
65153 }
65154@@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t
65155 */
65156 static __init int init_posix_timers(void)
65157 {
65158- struct k_clock clock_realtime = {
65159+ static struct k_clock clock_realtime = {
65160 .clock_getres = hrtimer_get_res,
65161 };
65162- struct k_clock clock_monotonic = {
65163+ static struct k_clock clock_monotonic = {
65164 .clock_getres = hrtimer_get_res,
65165 .clock_get = posix_ktime_get_ts,
65166 .clock_set = do_posix_clock_nosettime,
65167 };
65168- struct k_clock clock_monotonic_raw = {
65169+ static struct k_clock clock_monotonic_raw = {
65170 .clock_getres = hrtimer_get_res,
65171 .clock_get = posix_get_monotonic_raw,
65172 .clock_set = do_posix_clock_nosettime,
65173 .timer_create = no_timer_create,
65174 .nsleep = no_nsleep,
65175 };
65176- struct k_clock clock_realtime_coarse = {
65177+ static struct k_clock clock_realtime_coarse = {
65178 .clock_getres = posix_get_coarse_res,
65179 .clock_get = posix_get_realtime_coarse,
65180 .clock_set = do_posix_clock_nosettime,
65181 .timer_create = no_timer_create,
65182 .nsleep = no_nsleep,
65183 };
65184- struct k_clock clock_monotonic_coarse = {
65185+ static struct k_clock clock_monotonic_coarse = {
65186 .clock_getres = posix_get_coarse_res,
65187 .clock_get = posix_get_monotonic_coarse,
65188 .clock_set = do_posix_clock_nosettime,
65189@@ -296,6 +299,8 @@ static __init int init_posix_timers(void
65190 .nsleep = no_nsleep,
65191 };
65192
65193+ pax_track_stack();
65194+
65195 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
65196 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
65197 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
65198@@ -484,7 +489,7 @@ void register_posix_clock(const clockid_
65199 return;
65200 }
65201
65202- posix_clocks[clock_id] = *new_clock;
65203+ posix_clocks[clock_id] = new_clock;
65204 }
65205 EXPORT_SYMBOL_GPL(register_posix_clock);
65206
65207@@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
65208 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
65209 return -EFAULT;
65210
65211+ /* only the CLOCK_REALTIME clock can be set, all other clocks
65212+ have their clock_set fptr set to a nosettime dummy function
65213+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
65214+ call common_clock_set, which calls do_sys_settimeofday, which
65215+ we hook
65216+ */
65217+
65218 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
65219 }
65220
65221diff -urNp linux-2.6.32.44/kernel/power/hibernate.c linux-2.6.32.44/kernel/power/hibernate.c
65222--- linux-2.6.32.44/kernel/power/hibernate.c 2011-03-27 14:31:47.000000000 -0400
65223+++ linux-2.6.32.44/kernel/power/hibernate.c 2011-04-17 15:56:46.000000000 -0400
65224@@ -48,14 +48,14 @@ enum {
65225
65226 static int hibernation_mode = HIBERNATION_SHUTDOWN;
65227
65228-static struct platform_hibernation_ops *hibernation_ops;
65229+static const struct platform_hibernation_ops *hibernation_ops;
65230
65231 /**
65232 * hibernation_set_ops - set the global hibernate operations
65233 * @ops: the hibernation operations to use in subsequent hibernation transitions
65234 */
65235
65236-void hibernation_set_ops(struct platform_hibernation_ops *ops)
65237+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
65238 {
65239 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
65240 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
65241diff -urNp linux-2.6.32.44/kernel/power/poweroff.c linux-2.6.32.44/kernel/power/poweroff.c
65242--- linux-2.6.32.44/kernel/power/poweroff.c 2011-03-27 14:31:47.000000000 -0400
65243+++ linux-2.6.32.44/kernel/power/poweroff.c 2011-04-17 15:56:46.000000000 -0400
65244@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
65245 .enable_mask = SYSRQ_ENABLE_BOOT,
65246 };
65247
65248-static int pm_sysrq_init(void)
65249+static int __init pm_sysrq_init(void)
65250 {
65251 register_sysrq_key('o', &sysrq_poweroff_op);
65252 return 0;
65253diff -urNp linux-2.6.32.44/kernel/power/process.c linux-2.6.32.44/kernel/power/process.c
65254--- linux-2.6.32.44/kernel/power/process.c 2011-03-27 14:31:47.000000000 -0400
65255+++ linux-2.6.32.44/kernel/power/process.c 2011-04-17 15:56:46.000000000 -0400
65256@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_
65257 struct timeval start, end;
65258 u64 elapsed_csecs64;
65259 unsigned int elapsed_csecs;
65260+ bool timedout = false;
65261
65262 do_gettimeofday(&start);
65263
65264 end_time = jiffies + TIMEOUT;
65265 do {
65266 todo = 0;
65267+ if (time_after(jiffies, end_time))
65268+ timedout = true;
65269 read_lock(&tasklist_lock);
65270 do_each_thread(g, p) {
65271 if (frozen(p) || !freezeable(p))
65272@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_
65273 * It is "frozen enough". If the task does wake
65274 * up, it will immediately call try_to_freeze.
65275 */
65276- if (!task_is_stopped_or_traced(p) &&
65277- !freezer_should_skip(p))
65278+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
65279 todo++;
65280+ if (timedout) {
65281+ printk(KERN_ERR "Task refusing to freeze:\n");
65282+ sched_show_task(p);
65283+ }
65284+ }
65285 } while_each_thread(g, p);
65286 read_unlock(&tasklist_lock);
65287 yield(); /* Yield is okay here */
65288- if (time_after(jiffies, end_time))
65289- break;
65290- } while (todo);
65291+ } while (todo && !timedout);
65292
65293 do_gettimeofday(&end);
65294 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
65295diff -urNp linux-2.6.32.44/kernel/power/suspend.c linux-2.6.32.44/kernel/power/suspend.c
65296--- linux-2.6.32.44/kernel/power/suspend.c 2011-03-27 14:31:47.000000000 -0400
65297+++ linux-2.6.32.44/kernel/power/suspend.c 2011-04-17 15:56:46.000000000 -0400
65298@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_M
65299 [PM_SUSPEND_MEM] = "mem",
65300 };
65301
65302-static struct platform_suspend_ops *suspend_ops;
65303+static const struct platform_suspend_ops *suspend_ops;
65304
65305 /**
65306 * suspend_set_ops - Set the global suspend method table.
65307 * @ops: Pointer to ops structure.
65308 */
65309-void suspend_set_ops(struct platform_suspend_ops *ops)
65310+void suspend_set_ops(const struct platform_suspend_ops *ops)
65311 {
65312 mutex_lock(&pm_mutex);
65313 suspend_ops = ops;
65314diff -urNp linux-2.6.32.44/kernel/printk.c linux-2.6.32.44/kernel/printk.c
65315--- linux-2.6.32.44/kernel/printk.c 2011-03-27 14:31:47.000000000 -0400
65316+++ linux-2.6.32.44/kernel/printk.c 2011-04-17 15:56:46.000000000 -0400
65317@@ -278,6 +278,11 @@ int do_syslog(int type, char __user *buf
65318 char c;
65319 int error = 0;
65320
65321+#ifdef CONFIG_GRKERNSEC_DMESG
65322+ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
65323+ return -EPERM;
65324+#endif
65325+
65326 error = security_syslog(type);
65327 if (error)
65328 return error;
65329diff -urNp linux-2.6.32.44/kernel/profile.c linux-2.6.32.44/kernel/profile.c
65330--- linux-2.6.32.44/kernel/profile.c 2011-03-27 14:31:47.000000000 -0400
65331+++ linux-2.6.32.44/kernel/profile.c 2011-05-04 17:56:28.000000000 -0400
65332@@ -39,7 +39,7 @@ struct profile_hit {
65333 /* Oprofile timer tick hook */
65334 static int (*timer_hook)(struct pt_regs *) __read_mostly;
65335
65336-static atomic_t *prof_buffer;
65337+static atomic_unchecked_t *prof_buffer;
65338 static unsigned long prof_len, prof_shift;
65339
65340 int prof_on __read_mostly;
65341@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
65342 hits[i].pc = 0;
65343 continue;
65344 }
65345- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65346+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65347 hits[i].hits = hits[i].pc = 0;
65348 }
65349 }
65350@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
65351 * Add the current hit(s) and flush the write-queue out
65352 * to the global buffer:
65353 */
65354- atomic_add(nr_hits, &prof_buffer[pc]);
65355+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
65356 for (i = 0; i < NR_PROFILE_HIT; ++i) {
65357- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65358+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65359 hits[i].pc = hits[i].hits = 0;
65360 }
65361 out:
65362@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
65363 if (prof_on != type || !prof_buffer)
65364 return;
65365 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
65366- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65367+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65368 }
65369 #endif /* !CONFIG_SMP */
65370 EXPORT_SYMBOL_GPL(profile_hits);
65371@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
65372 return -EFAULT;
65373 buf++; p++; count--; read++;
65374 }
65375- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
65376+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
65377 if (copy_to_user(buf, (void *)pnt, count))
65378 return -EFAULT;
65379 read += count;
65380@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
65381 }
65382 #endif
65383 profile_discard_flip_buffers();
65384- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
65385+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
65386 return count;
65387 }
65388
65389diff -urNp linux-2.6.32.44/kernel/ptrace.c linux-2.6.32.44/kernel/ptrace.c
65390--- linux-2.6.32.44/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
65391+++ linux-2.6.32.44/kernel/ptrace.c 2011-05-22 23:02:06.000000000 -0400
65392@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
65393 return ret;
65394 }
65395
65396-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65397+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
65398+ unsigned int log)
65399 {
65400 const struct cred *cred = current_cred(), *tcred;
65401
65402@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_stru
65403 cred->gid != tcred->egid ||
65404 cred->gid != tcred->sgid ||
65405 cred->gid != tcred->gid) &&
65406- !capable(CAP_SYS_PTRACE)) {
65407+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
65408+ (log && !capable(CAP_SYS_PTRACE)))
65409+ ) {
65410 rcu_read_unlock();
65411 return -EPERM;
65412 }
65413@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_stru
65414 smp_rmb();
65415 if (task->mm)
65416 dumpable = get_dumpable(task->mm);
65417- if (!dumpable && !capable(CAP_SYS_PTRACE))
65418+ if (!dumpable &&
65419+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
65420+ (log && !capable(CAP_SYS_PTRACE))))
65421 return -EPERM;
65422
65423 return security_ptrace_access_check(task, mode);
65424@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struc
65425 {
65426 int err;
65427 task_lock(task);
65428- err = __ptrace_may_access(task, mode);
65429+ err = __ptrace_may_access(task, mode, 0);
65430+ task_unlock(task);
65431+ return !err;
65432+}
65433+
65434+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
65435+{
65436+ int err;
65437+ task_lock(task);
65438+ err = __ptrace_may_access(task, mode, 1);
65439 task_unlock(task);
65440 return !err;
65441 }
65442@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *ta
65443 goto out;
65444
65445 task_lock(task);
65446- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
65447+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
65448 task_unlock(task);
65449 if (retval)
65450 goto unlock_creds;
65451@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *ta
65452 goto unlock_tasklist;
65453
65454 task->ptrace = PT_PTRACED;
65455- if (capable(CAP_SYS_PTRACE))
65456+ if (capable_nolog(CAP_SYS_PTRACE))
65457 task->ptrace |= PT_PTRACE_CAP;
65458
65459 __ptrace_link(task, current);
65460@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *
65461 {
65462 int copied = 0;
65463
65464+ pax_track_stack();
65465+
65466 while (len > 0) {
65467 char buf[128];
65468 int this_len, retval;
65469@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct
65470 {
65471 int copied = 0;
65472
65473+ pax_track_stack();
65474+
65475 while (len > 0) {
65476 char buf[128];
65477 int this_len, retval;
65478@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *c
65479 int ret = -EIO;
65480 siginfo_t siginfo;
65481
65482+ pax_track_stack();
65483+
65484 switch (request) {
65485 case PTRACE_PEEKTEXT:
65486 case PTRACE_PEEKDATA:
65487@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *c
65488 ret = ptrace_setoptions(child, data);
65489 break;
65490 case PTRACE_GETEVENTMSG:
65491- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
65492+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
65493 break;
65494
65495 case PTRACE_GETSIGINFO:
65496 ret = ptrace_getsiginfo(child, &siginfo);
65497 if (!ret)
65498- ret = copy_siginfo_to_user((siginfo_t __user *) data,
65499+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
65500 &siginfo);
65501 break;
65502
65503 case PTRACE_SETSIGINFO:
65504- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
65505+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
65506 sizeof siginfo))
65507 ret = -EFAULT;
65508 else
65509@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
65510 goto out;
65511 }
65512
65513+ if (gr_handle_ptrace(child, request)) {
65514+ ret = -EPERM;
65515+ goto out_put_task_struct;
65516+ }
65517+
65518 if (request == PTRACE_ATTACH) {
65519 ret = ptrace_attach(child);
65520 /*
65521 * Some architectures need to do book-keeping after
65522 * a ptrace attach.
65523 */
65524- if (!ret)
65525+ if (!ret) {
65526 arch_ptrace_attach(child);
65527+ gr_audit_ptrace(child);
65528+ }
65529 goto out_put_task_struct;
65530 }
65531
65532@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_
65533 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
65534 if (copied != sizeof(tmp))
65535 return -EIO;
65536- return put_user(tmp, (unsigned long __user *)data);
65537+ return put_user(tmp, (__force unsigned long __user *)data);
65538 }
65539
65540 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
65541@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_st
65542 siginfo_t siginfo;
65543 int ret;
65544
65545+ pax_track_stack();
65546+
65547 switch (request) {
65548 case PTRACE_PEEKTEXT:
65549 case PTRACE_PEEKDATA:
65550@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat
65551 goto out;
65552 }
65553
65554+ if (gr_handle_ptrace(child, request)) {
65555+ ret = -EPERM;
65556+ goto out_put_task_struct;
65557+ }
65558+
65559 if (request == PTRACE_ATTACH) {
65560 ret = ptrace_attach(child);
65561 /*
65562 * Some architectures need to do book-keeping after
65563 * a ptrace attach.
65564 */
65565- if (!ret)
65566+ if (!ret) {
65567 arch_ptrace_attach(child);
65568+ gr_audit_ptrace(child);
65569+ }
65570 goto out_put_task_struct;
65571 }
65572
65573diff -urNp linux-2.6.32.44/kernel/rcutorture.c linux-2.6.32.44/kernel/rcutorture.c
65574--- linux-2.6.32.44/kernel/rcutorture.c 2011-03-27 14:31:47.000000000 -0400
65575+++ linux-2.6.32.44/kernel/rcutorture.c 2011-05-04 17:56:28.000000000 -0400
65576@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
65577 { 0 };
65578 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
65579 { 0 };
65580-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65581-static atomic_t n_rcu_torture_alloc;
65582-static atomic_t n_rcu_torture_alloc_fail;
65583-static atomic_t n_rcu_torture_free;
65584-static atomic_t n_rcu_torture_mberror;
65585-static atomic_t n_rcu_torture_error;
65586+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65587+static atomic_unchecked_t n_rcu_torture_alloc;
65588+static atomic_unchecked_t n_rcu_torture_alloc_fail;
65589+static atomic_unchecked_t n_rcu_torture_free;
65590+static atomic_unchecked_t n_rcu_torture_mberror;
65591+static atomic_unchecked_t n_rcu_torture_error;
65592 static long n_rcu_torture_timers;
65593 static struct list_head rcu_torture_removed;
65594 static cpumask_var_t shuffle_tmp_mask;
65595@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
65596
65597 spin_lock_bh(&rcu_torture_lock);
65598 if (list_empty(&rcu_torture_freelist)) {
65599- atomic_inc(&n_rcu_torture_alloc_fail);
65600+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
65601 spin_unlock_bh(&rcu_torture_lock);
65602 return NULL;
65603 }
65604- atomic_inc(&n_rcu_torture_alloc);
65605+ atomic_inc_unchecked(&n_rcu_torture_alloc);
65606 p = rcu_torture_freelist.next;
65607 list_del_init(p);
65608 spin_unlock_bh(&rcu_torture_lock);
65609@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
65610 static void
65611 rcu_torture_free(struct rcu_torture *p)
65612 {
65613- atomic_inc(&n_rcu_torture_free);
65614+ atomic_inc_unchecked(&n_rcu_torture_free);
65615 spin_lock_bh(&rcu_torture_lock);
65616 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
65617 spin_unlock_bh(&rcu_torture_lock);
65618@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
65619 i = rp->rtort_pipe_count;
65620 if (i > RCU_TORTURE_PIPE_LEN)
65621 i = RCU_TORTURE_PIPE_LEN;
65622- atomic_inc(&rcu_torture_wcount[i]);
65623+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
65624 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65625 rp->rtort_mbtest = 0;
65626 rcu_torture_free(rp);
65627@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_fr
65628 i = rp->rtort_pipe_count;
65629 if (i > RCU_TORTURE_PIPE_LEN)
65630 i = RCU_TORTURE_PIPE_LEN;
65631- atomic_inc(&rcu_torture_wcount[i]);
65632+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
65633 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65634 rp->rtort_mbtest = 0;
65635 list_del(&rp->rtort_free);
65636@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
65637 i = old_rp->rtort_pipe_count;
65638 if (i > RCU_TORTURE_PIPE_LEN)
65639 i = RCU_TORTURE_PIPE_LEN;
65640- atomic_inc(&rcu_torture_wcount[i]);
65641+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
65642 old_rp->rtort_pipe_count++;
65643 cur_ops->deferred_free(old_rp);
65644 }
65645@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned l
65646 return;
65647 }
65648 if (p->rtort_mbtest == 0)
65649- atomic_inc(&n_rcu_torture_mberror);
65650+ atomic_inc_unchecked(&n_rcu_torture_mberror);
65651 spin_lock(&rand_lock);
65652 cur_ops->read_delay(&rand);
65653 n_rcu_torture_timers++;
65654@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
65655 continue;
65656 }
65657 if (p->rtort_mbtest == 0)
65658- atomic_inc(&n_rcu_torture_mberror);
65659+ atomic_inc_unchecked(&n_rcu_torture_mberror);
65660 cur_ops->read_delay(&rand);
65661 preempt_disable();
65662 pipe_count = p->rtort_pipe_count;
65663@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
65664 rcu_torture_current,
65665 rcu_torture_current_version,
65666 list_empty(&rcu_torture_freelist),
65667- atomic_read(&n_rcu_torture_alloc),
65668- atomic_read(&n_rcu_torture_alloc_fail),
65669- atomic_read(&n_rcu_torture_free),
65670- atomic_read(&n_rcu_torture_mberror),
65671+ atomic_read_unchecked(&n_rcu_torture_alloc),
65672+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
65673+ atomic_read_unchecked(&n_rcu_torture_free),
65674+ atomic_read_unchecked(&n_rcu_torture_mberror),
65675 n_rcu_torture_timers);
65676- if (atomic_read(&n_rcu_torture_mberror) != 0)
65677+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
65678 cnt += sprintf(&page[cnt], " !!!");
65679 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
65680 if (i > 1) {
65681 cnt += sprintf(&page[cnt], "!!! ");
65682- atomic_inc(&n_rcu_torture_error);
65683+ atomic_inc_unchecked(&n_rcu_torture_error);
65684 WARN_ON_ONCE(1);
65685 }
65686 cnt += sprintf(&page[cnt], "Reader Pipe: ");
65687@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
65688 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
65689 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65690 cnt += sprintf(&page[cnt], " %d",
65691- atomic_read(&rcu_torture_wcount[i]));
65692+ atomic_read_unchecked(&rcu_torture_wcount[i]));
65693 }
65694 cnt += sprintf(&page[cnt], "\n");
65695 if (cur_ops->stats)
65696@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
65697
65698 if (cur_ops->cleanup)
65699 cur_ops->cleanup();
65700- if (atomic_read(&n_rcu_torture_error))
65701+ if (atomic_read_unchecked(&n_rcu_torture_error))
65702 rcu_torture_print_module_parms("End of test: FAILURE");
65703 else
65704 rcu_torture_print_module_parms("End of test: SUCCESS");
65705@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
65706
65707 rcu_torture_current = NULL;
65708 rcu_torture_current_version = 0;
65709- atomic_set(&n_rcu_torture_alloc, 0);
65710- atomic_set(&n_rcu_torture_alloc_fail, 0);
65711- atomic_set(&n_rcu_torture_free, 0);
65712- atomic_set(&n_rcu_torture_mberror, 0);
65713- atomic_set(&n_rcu_torture_error, 0);
65714+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
65715+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
65716+ atomic_set_unchecked(&n_rcu_torture_free, 0);
65717+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
65718+ atomic_set_unchecked(&n_rcu_torture_error, 0);
65719 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
65720- atomic_set(&rcu_torture_wcount[i], 0);
65721+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
65722 for_each_possible_cpu(cpu) {
65723 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65724 per_cpu(rcu_torture_count, cpu)[i] = 0;
65725diff -urNp linux-2.6.32.44/kernel/rcutree.c linux-2.6.32.44/kernel/rcutree.c
65726--- linux-2.6.32.44/kernel/rcutree.c 2011-03-27 14:31:47.000000000 -0400
65727+++ linux-2.6.32.44/kernel/rcutree.c 2011-04-17 15:56:46.000000000 -0400
65728@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state
65729 /*
65730 * Do softirq processing for the current CPU.
65731 */
65732-static void rcu_process_callbacks(struct softirq_action *unused)
65733+static void rcu_process_callbacks(void)
65734 {
65735 /*
65736 * Memory references from any prior RCU read-side critical sections
65737diff -urNp linux-2.6.32.44/kernel/rcutree_plugin.h linux-2.6.32.44/kernel/rcutree_plugin.h
65738--- linux-2.6.32.44/kernel/rcutree_plugin.h 2011-03-27 14:31:47.000000000 -0400
65739+++ linux-2.6.32.44/kernel/rcutree_plugin.h 2011-04-17 15:56:46.000000000 -0400
65740@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_swi
65741 */
65742 void __rcu_read_lock(void)
65743 {
65744- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
65745+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
65746 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
65747 }
65748 EXPORT_SYMBOL_GPL(__rcu_read_lock);
65749@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
65750 struct task_struct *t = current;
65751
65752 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
65753- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
65754+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
65755 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
65756 rcu_read_unlock_special(t);
65757 }
65758diff -urNp linux-2.6.32.44/kernel/relay.c linux-2.6.32.44/kernel/relay.c
65759--- linux-2.6.32.44/kernel/relay.c 2011-03-27 14:31:47.000000000 -0400
65760+++ linux-2.6.32.44/kernel/relay.c 2011-05-16 21:46:57.000000000 -0400
65761@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct fi
65762 unsigned int flags,
65763 int *nonpad_ret)
65764 {
65765- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
65766+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
65767 struct rchan_buf *rbuf = in->private_data;
65768 unsigned int subbuf_size = rbuf->chan->subbuf_size;
65769 uint64_t pos = (uint64_t) *ppos;
65770@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct fi
65771 .ops = &relay_pipe_buf_ops,
65772 .spd_release = relay_page_release,
65773 };
65774+ ssize_t ret;
65775+
65776+ pax_track_stack();
65777
65778 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
65779 return 0;
65780diff -urNp linux-2.6.32.44/kernel/resource.c linux-2.6.32.44/kernel/resource.c
65781--- linux-2.6.32.44/kernel/resource.c 2011-03-27 14:31:47.000000000 -0400
65782+++ linux-2.6.32.44/kernel/resource.c 2011-04-17 15:56:46.000000000 -0400
65783@@ -132,8 +132,18 @@ static const struct file_operations proc
65784
65785 static int __init ioresources_init(void)
65786 {
65787+#ifdef CONFIG_GRKERNSEC_PROC_ADD
65788+#ifdef CONFIG_GRKERNSEC_PROC_USER
65789+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
65790+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
65791+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65792+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
65793+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
65794+#endif
65795+#else
65796 proc_create("ioports", 0, NULL, &proc_ioports_operations);
65797 proc_create("iomem", 0, NULL, &proc_iomem_operations);
65798+#endif
65799 return 0;
65800 }
65801 __initcall(ioresources_init);
65802diff -urNp linux-2.6.32.44/kernel/rtmutex.c linux-2.6.32.44/kernel/rtmutex.c
65803--- linux-2.6.32.44/kernel/rtmutex.c 2011-03-27 14:31:47.000000000 -0400
65804+++ linux-2.6.32.44/kernel/rtmutex.c 2011-04-17 15:56:46.000000000 -0400
65805@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt
65806 */
65807 spin_lock_irqsave(&pendowner->pi_lock, flags);
65808
65809- WARN_ON(!pendowner->pi_blocked_on);
65810+ BUG_ON(!pendowner->pi_blocked_on);
65811 WARN_ON(pendowner->pi_blocked_on != waiter);
65812 WARN_ON(pendowner->pi_blocked_on->lock != lock);
65813
65814diff -urNp linux-2.6.32.44/kernel/rtmutex-tester.c linux-2.6.32.44/kernel/rtmutex-tester.c
65815--- linux-2.6.32.44/kernel/rtmutex-tester.c 2011-03-27 14:31:47.000000000 -0400
65816+++ linux-2.6.32.44/kernel/rtmutex-tester.c 2011-05-04 17:56:28.000000000 -0400
65817@@ -21,7 +21,7 @@
65818 #define MAX_RT_TEST_MUTEXES 8
65819
65820 static spinlock_t rttest_lock;
65821-static atomic_t rttest_event;
65822+static atomic_unchecked_t rttest_event;
65823
65824 struct test_thread_data {
65825 int opcode;
65826@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_
65827
65828 case RTTEST_LOCKCONT:
65829 td->mutexes[td->opdata] = 1;
65830- td->event = atomic_add_return(1, &rttest_event);
65831+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65832 return 0;
65833
65834 case RTTEST_RESET:
65835@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_
65836 return 0;
65837
65838 case RTTEST_RESETEVENT:
65839- atomic_set(&rttest_event, 0);
65840+ atomic_set_unchecked(&rttest_event, 0);
65841 return 0;
65842
65843 default:
65844@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_
65845 return ret;
65846
65847 td->mutexes[id] = 1;
65848- td->event = atomic_add_return(1, &rttest_event);
65849+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65850 rt_mutex_lock(&mutexes[id]);
65851- td->event = atomic_add_return(1, &rttest_event);
65852+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65853 td->mutexes[id] = 4;
65854 return 0;
65855
65856@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_
65857 return ret;
65858
65859 td->mutexes[id] = 1;
65860- td->event = atomic_add_return(1, &rttest_event);
65861+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65862 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
65863- td->event = atomic_add_return(1, &rttest_event);
65864+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65865 td->mutexes[id] = ret ? 0 : 4;
65866 return ret ? -EINTR : 0;
65867
65868@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_
65869 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
65870 return ret;
65871
65872- td->event = atomic_add_return(1, &rttest_event);
65873+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65874 rt_mutex_unlock(&mutexes[id]);
65875- td->event = atomic_add_return(1, &rttest_event);
65876+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65877 td->mutexes[id] = 0;
65878 return 0;
65879
65880@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mu
65881 break;
65882
65883 td->mutexes[dat] = 2;
65884- td->event = atomic_add_return(1, &rttest_event);
65885+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65886 break;
65887
65888 case RTTEST_LOCKBKL:
65889@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mu
65890 return;
65891
65892 td->mutexes[dat] = 3;
65893- td->event = atomic_add_return(1, &rttest_event);
65894+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65895 break;
65896
65897 case RTTEST_LOCKNOWAIT:
65898@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mu
65899 return;
65900
65901 td->mutexes[dat] = 1;
65902- td->event = atomic_add_return(1, &rttest_event);
65903+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65904 return;
65905
65906 case RTTEST_LOCKBKL:
65907diff -urNp linux-2.6.32.44/kernel/sched.c linux-2.6.32.44/kernel/sched.c
65908--- linux-2.6.32.44/kernel/sched.c 2011-03-27 14:31:47.000000000 -0400
65909+++ linux-2.6.32.44/kernel/sched.c 2011-05-22 23:02:06.000000000 -0400
65910@@ -5043,7 +5043,7 @@ out:
65911 * In CONFIG_NO_HZ case, the idle load balance owner will do the
65912 * rebalancing for all the cpus for whom scheduler ticks are stopped.
65913 */
65914-static void run_rebalance_domains(struct softirq_action *h)
65915+static void run_rebalance_domains(void)
65916 {
65917 int this_cpu = smp_processor_id();
65918 struct rq *this_rq = cpu_rq(this_cpu);
65919@@ -5700,6 +5700,8 @@ asmlinkage void __sched schedule(void)
65920 struct rq *rq;
65921 int cpu;
65922
65923+ pax_track_stack();
65924+
65925 need_resched:
65926 preempt_disable();
65927 cpu = smp_processor_id();
65928@@ -5770,7 +5772,7 @@ EXPORT_SYMBOL(schedule);
65929 * Look out! "owner" is an entirely speculative pointer
65930 * access and not reliable.
65931 */
65932-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
65933+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
65934 {
65935 unsigned int cpu;
65936 struct rq *rq;
65937@@ -5784,10 +5786,10 @@ int mutex_spin_on_owner(struct mutex *lo
65938 * DEBUG_PAGEALLOC could have unmapped it if
65939 * the mutex owner just released it and exited.
65940 */
65941- if (probe_kernel_address(&owner->cpu, cpu))
65942+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
65943 return 0;
65944 #else
65945- cpu = owner->cpu;
65946+ cpu = task_thread_info(owner)->cpu;
65947 #endif
65948
65949 /*
65950@@ -5816,7 +5818,7 @@ int mutex_spin_on_owner(struct mutex *lo
65951 /*
65952 * Is that owner really running on that cpu?
65953 */
65954- if (task_thread_info(rq->curr) != owner || need_resched())
65955+ if (rq->curr != owner || need_resched())
65956 return 0;
65957
65958 cpu_relax();
65959@@ -6359,6 +6361,8 @@ int can_nice(const struct task_struct *p
65960 /* convert nice value [19,-20] to rlimit style value [1,40] */
65961 int nice_rlim = 20 - nice;
65962
65963+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
65964+
65965 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
65966 capable(CAP_SYS_NICE));
65967 }
65968@@ -6392,7 +6396,8 @@ SYSCALL_DEFINE1(nice, int, increment)
65969 if (nice > 19)
65970 nice = 19;
65971
65972- if (increment < 0 && !can_nice(current, nice))
65973+ if (increment < 0 && (!can_nice(current, nice) ||
65974+ gr_handle_chroot_nice()))
65975 return -EPERM;
65976
65977 retval = security_task_setnice(current, nice);
65978@@ -8774,7 +8779,7 @@ static void init_sched_groups_power(int
65979 long power;
65980 int weight;
65981
65982- WARN_ON(!sd || !sd->groups);
65983+ BUG_ON(!sd || !sd->groups);
65984
65985 if (cpu != group_first_cpu(sd->groups))
65986 return;
65987diff -urNp linux-2.6.32.44/kernel/signal.c linux-2.6.32.44/kernel/signal.c
65988--- linux-2.6.32.44/kernel/signal.c 2011-04-17 17:00:52.000000000 -0400
65989+++ linux-2.6.32.44/kernel/signal.c 2011-07-14 20:33:33.000000000 -0400
65990@@ -41,12 +41,12 @@
65991
65992 static struct kmem_cache *sigqueue_cachep;
65993
65994-static void __user *sig_handler(struct task_struct *t, int sig)
65995+static __sighandler_t sig_handler(struct task_struct *t, int sig)
65996 {
65997 return t->sighand->action[sig - 1].sa.sa_handler;
65998 }
65999
66000-static int sig_handler_ignored(void __user *handler, int sig)
66001+static int sig_handler_ignored(__sighandler_t handler, int sig)
66002 {
66003 /* Is it explicitly or implicitly ignored? */
66004 return handler == SIG_IGN ||
66005@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __us
66006 static int sig_task_ignored(struct task_struct *t, int sig,
66007 int from_ancestor_ns)
66008 {
66009- void __user *handler;
66010+ __sighandler_t handler;
66011
66012 handler = sig_handler(t, sig);
66013
66014@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc
66015 */
66016 user = get_uid(__task_cred(t)->user);
66017 atomic_inc(&user->sigpending);
66018+
66019+ if (!override_rlimit)
66020+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
66021 if (override_rlimit ||
66022 atomic_read(&user->sigpending) <=
66023 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
66024@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct
66025
66026 int unhandled_signal(struct task_struct *tsk, int sig)
66027 {
66028- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
66029+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
66030 if (is_global_init(tsk))
66031 return 1;
66032 if (handler != SIG_IGN && handler != SIG_DFL)
66033@@ -627,6 +630,12 @@ static int check_kill_permission(int sig
66034 }
66035 }
66036
66037+ /* allow glibc communication via tgkill to other threads in our
66038+ thread group */
66039+ if ((info->si_code != SI_TKILL || sig != (SIGRTMIN+1) ||
66040+ task_tgid_vnr(t) != info->si_pid) && gr_handle_signal(t, sig))
66041+ return -EPERM;
66042+
66043 return security_task_kill(t, info, sig, 0);
66044 }
66045
66046@@ -968,7 +977,7 @@ __group_send_sig_info(int sig, struct si
66047 return send_signal(sig, info, p, 1);
66048 }
66049
66050-static int
66051+int
66052 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66053 {
66054 return send_signal(sig, info, t, 0);
66055@@ -1005,6 +1014,7 @@ force_sig_info(int sig, struct siginfo *
66056 unsigned long int flags;
66057 int ret, blocked, ignored;
66058 struct k_sigaction *action;
66059+ int is_unhandled = 0;
66060
66061 spin_lock_irqsave(&t->sighand->siglock, flags);
66062 action = &t->sighand->action[sig-1];
66063@@ -1019,9 +1029,18 @@ force_sig_info(int sig, struct siginfo *
66064 }
66065 if (action->sa.sa_handler == SIG_DFL)
66066 t->signal->flags &= ~SIGNAL_UNKILLABLE;
66067+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
66068+ is_unhandled = 1;
66069 ret = specific_send_sig_info(sig, info, t);
66070 spin_unlock_irqrestore(&t->sighand->siglock, flags);
66071
66072+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
66073+ normal operation */
66074+ if (is_unhandled) {
66075+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
66076+ gr_handle_crash(t, sig);
66077+ }
66078+
66079 return ret;
66080 }
66081
66082@@ -1081,8 +1100,11 @@ int group_send_sig_info(int sig, struct
66083 {
66084 int ret = check_kill_permission(sig, info, p);
66085
66086- if (!ret && sig)
66087+ if (!ret && sig) {
66088 ret = do_send_sig_info(sig, info, p, true);
66089+ if (!ret)
66090+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
66091+ }
66092
66093 return ret;
66094 }
66095@@ -1644,6 +1666,8 @@ void ptrace_notify(int exit_code)
66096 {
66097 siginfo_t info;
66098
66099+ pax_track_stack();
66100+
66101 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
66102
66103 memset(&info, 0, sizeof info);
66104@@ -2275,7 +2299,15 @@ do_send_specific(pid_t tgid, pid_t pid,
66105 int error = -ESRCH;
66106
66107 rcu_read_lock();
66108- p = find_task_by_vpid(pid);
66109+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66110+ /* allow glibc communication via tgkill to other threads in our
66111+ thread group */
66112+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
66113+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
66114+ p = find_task_by_vpid_unrestricted(pid);
66115+ else
66116+#endif
66117+ p = find_task_by_vpid(pid);
66118 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
66119 error = check_kill_permission(sig, info, p);
66120 /*
66121diff -urNp linux-2.6.32.44/kernel/smp.c linux-2.6.32.44/kernel/smp.c
66122--- linux-2.6.32.44/kernel/smp.c 2011-03-27 14:31:47.000000000 -0400
66123+++ linux-2.6.32.44/kernel/smp.c 2011-04-17 15:56:46.000000000 -0400
66124@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void
66125 }
66126 EXPORT_SYMBOL(smp_call_function);
66127
66128-void ipi_call_lock(void)
66129+void ipi_call_lock(void) __acquires(call_function.lock)
66130 {
66131 spin_lock(&call_function.lock);
66132 }
66133
66134-void ipi_call_unlock(void)
66135+void ipi_call_unlock(void) __releases(call_function.lock)
66136 {
66137 spin_unlock(&call_function.lock);
66138 }
66139
66140-void ipi_call_lock_irq(void)
66141+void ipi_call_lock_irq(void) __acquires(call_function.lock)
66142 {
66143 spin_lock_irq(&call_function.lock);
66144 }
66145
66146-void ipi_call_unlock_irq(void)
66147+void ipi_call_unlock_irq(void) __releases(call_function.lock)
66148 {
66149 spin_unlock_irq(&call_function.lock);
66150 }
66151diff -urNp linux-2.6.32.44/kernel/softirq.c linux-2.6.32.44/kernel/softirq.c
66152--- linux-2.6.32.44/kernel/softirq.c 2011-03-27 14:31:47.000000000 -0400
66153+++ linux-2.6.32.44/kernel/softirq.c 2011-08-05 20:33:55.000000000 -0400
66154@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
66155
66156 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
66157
66158-char *softirq_to_name[NR_SOFTIRQS] = {
66159+const char * const softirq_to_name[NR_SOFTIRQS] = {
66160 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
66161 "TASKLET", "SCHED", "HRTIMER", "RCU"
66162 };
66163@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
66164
66165 asmlinkage void __do_softirq(void)
66166 {
66167- struct softirq_action *h;
66168+ const struct softirq_action *h;
66169 __u32 pending;
66170 int max_restart = MAX_SOFTIRQ_RESTART;
66171 int cpu;
66172@@ -233,7 +233,7 @@ restart:
66173 kstat_incr_softirqs_this_cpu(h - softirq_vec);
66174
66175 trace_softirq_entry(h, softirq_vec);
66176- h->action(h);
66177+ h->action();
66178 trace_softirq_exit(h, softirq_vec);
66179 if (unlikely(prev_count != preempt_count())) {
66180 printk(KERN_ERR "huh, entered softirq %td %s %p"
66181@@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
66182 local_irq_restore(flags);
66183 }
66184
66185-void open_softirq(int nr, void (*action)(struct softirq_action *))
66186+void open_softirq(int nr, void (*action)(void))
66187 {
66188- softirq_vec[nr].action = action;
66189+ pax_open_kernel();
66190+ *(void **)&softirq_vec[nr].action = action;
66191+ pax_close_kernel();
66192 }
66193
66194 /*
66195@@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct
66196
66197 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
66198
66199-static void tasklet_action(struct softirq_action *a)
66200+static void tasklet_action(void)
66201 {
66202 struct tasklet_struct *list;
66203
66204@@ -454,7 +456,7 @@ static void tasklet_action(struct softir
66205 }
66206 }
66207
66208-static void tasklet_hi_action(struct softirq_action *a)
66209+static void tasklet_hi_action(void)
66210 {
66211 struct tasklet_struct *list;
66212
66213diff -urNp linux-2.6.32.44/kernel/sys.c linux-2.6.32.44/kernel/sys.c
66214--- linux-2.6.32.44/kernel/sys.c 2011-03-27 14:31:47.000000000 -0400
66215+++ linux-2.6.32.44/kernel/sys.c 2011-08-11 19:51:54.000000000 -0400
66216@@ -133,6 +133,12 @@ static int set_one_prio(struct task_stru
66217 error = -EACCES;
66218 goto out;
66219 }
66220+
66221+ if (gr_handle_chroot_setpriority(p, niceval)) {
66222+ error = -EACCES;
66223+ goto out;
66224+ }
66225+
66226 no_nice = security_task_setnice(p, niceval);
66227 if (no_nice) {
66228 error = no_nice;
66229@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
66230 !(user = find_user(who)))
66231 goto out_unlock; /* No processes for this user */
66232
66233- do_each_thread(g, p)
66234+ do_each_thread(g, p) {
66235 if (__task_cred(p)->uid == who)
66236 error = set_one_prio(p, niceval, error);
66237- while_each_thread(g, p);
66238+ } while_each_thread(g, p);
66239 if (who != cred->uid)
66240 free_uid(user); /* For find_user() */
66241 break;
66242@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which,
66243 !(user = find_user(who)))
66244 goto out_unlock; /* No processes for this user */
66245
66246- do_each_thread(g, p)
66247+ do_each_thread(g, p) {
66248 if (__task_cred(p)->uid == who) {
66249 niceval = 20 - task_nice(p);
66250 if (niceval > retval)
66251 retval = niceval;
66252 }
66253- while_each_thread(g, p);
66254+ } while_each_thread(g, p);
66255 if (who != cred->uid)
66256 free_uid(user); /* for find_user() */
66257 break;
66258@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
66259 goto error;
66260 }
66261
66262+ if (gr_check_group_change(new->gid, new->egid, -1))
66263+ goto error;
66264+
66265 if (rgid != (gid_t) -1 ||
66266 (egid != (gid_t) -1 && egid != old->gid))
66267 new->sgid = new->egid;
66268@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
66269 goto error;
66270
66271 retval = -EPERM;
66272+
66273+ if (gr_check_group_change(gid, gid, gid))
66274+ goto error;
66275+
66276 if (capable(CAP_SETGID))
66277 new->gid = new->egid = new->sgid = new->fsgid = gid;
66278 else if (gid == old->gid || gid == old->sgid)
66279@@ -567,12 +580,19 @@ static int set_user(struct cred *new)
66280 if (!new_user)
66281 return -EAGAIN;
66282
66283+ /*
66284+ * We don't fail in case of NPROC limit excess here because too many
66285+ * poorly written programs don't check set*uid() return code, assuming
66286+ * it never fails if called by root. We may still enforce NPROC limit
66287+ * for programs doing set*uid()+execve() by harmlessly deferring the
66288+ * failure to the execve() stage.
66289+ */
66290 if (atomic_read(&new_user->processes) >=
66291 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
66292- new_user != INIT_USER) {
66293- free_uid(new_user);
66294- return -EAGAIN;
66295- }
66296+ new_user != INIT_USER)
66297+ current->flags |= PF_NPROC_EXCEEDED;
66298+ else
66299+ current->flags &= ~PF_NPROC_EXCEEDED;
66300
66301 free_uid(new->user);
66302 new->user = new_user;
66303@@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
66304 goto error;
66305 }
66306
66307+ if (gr_check_user_change(new->uid, new->euid, -1))
66308+ goto error;
66309+
66310 if (new->uid != old->uid) {
66311 retval = set_user(new);
66312 if (retval < 0)
66313@@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
66314 goto error;
66315
66316 retval = -EPERM;
66317+
66318+ if (gr_check_crash_uid(uid))
66319+ goto error;
66320+ if (gr_check_user_change(uid, uid, uid))
66321+ goto error;
66322+
66323 if (capable(CAP_SETUID)) {
66324 new->suid = new->uid = uid;
66325 if (uid != old->uid) {
66326@@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
66327 goto error;
66328 }
66329
66330+ if (gr_check_user_change(ruid, euid, -1))
66331+ goto error;
66332+
66333 if (ruid != (uid_t) -1) {
66334 new->uid = ruid;
66335 if (ruid != old->uid) {
66336@@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
66337 goto error;
66338 }
66339
66340+ if (gr_check_group_change(rgid, egid, -1))
66341+ goto error;
66342+
66343 if (rgid != (gid_t) -1)
66344 new->gid = rgid;
66345 if (egid != (gid_t) -1)
66346@@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66347 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
66348 goto error;
66349
66350+ if (gr_check_user_change(-1, -1, uid))
66351+ goto error;
66352+
66353 if (uid == old->uid || uid == old->euid ||
66354 uid == old->suid || uid == old->fsuid ||
66355 capable(CAP_SETUID)) {
66356@@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
66357 if (gid == old->gid || gid == old->egid ||
66358 gid == old->sgid || gid == old->fsgid ||
66359 capable(CAP_SETGID)) {
66360+ if (gr_check_group_change(-1, -1, gid))
66361+ goto error;
66362+
66363 if (gid != old_fsgid) {
66364 new->fsgid = gid;
66365 goto change_okay;
66366@@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
66367 error = get_dumpable(me->mm);
66368 break;
66369 case PR_SET_DUMPABLE:
66370- if (arg2 < 0 || arg2 > 1) {
66371+ if (arg2 > 1) {
66372 error = -EINVAL;
66373 break;
66374 }
66375diff -urNp linux-2.6.32.44/kernel/sysctl.c linux-2.6.32.44/kernel/sysctl.c
66376--- linux-2.6.32.44/kernel/sysctl.c 2011-03-27 14:31:47.000000000 -0400
66377+++ linux-2.6.32.44/kernel/sysctl.c 2011-04-17 15:56:46.000000000 -0400
66378@@ -63,6 +63,13 @@
66379 static int deprecated_sysctl_warning(struct __sysctl_args *args);
66380
66381 #if defined(CONFIG_SYSCTL)
66382+#include <linux/grsecurity.h>
66383+#include <linux/grinternal.h>
66384+
66385+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
66386+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66387+ const int op);
66388+extern int gr_handle_chroot_sysctl(const int op);
66389
66390 /* External variables not in a header file. */
66391 extern int C_A_D;
66392@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_ta
66393 static int proc_taint(struct ctl_table *table, int write,
66394 void __user *buffer, size_t *lenp, loff_t *ppos);
66395 #endif
66396+extern ctl_table grsecurity_table[];
66397
66398 static struct ctl_table root_table[];
66399 static struct ctl_table_root sysctl_table_root;
66400@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
66401 int sysctl_legacy_va_layout;
66402 #endif
66403
66404+#ifdef CONFIG_PAX_SOFTMODE
66405+static ctl_table pax_table[] = {
66406+ {
66407+ .ctl_name = CTL_UNNUMBERED,
66408+ .procname = "softmode",
66409+ .data = &pax_softmode,
66410+ .maxlen = sizeof(unsigned int),
66411+ .mode = 0600,
66412+ .proc_handler = &proc_dointvec,
66413+ },
66414+
66415+ { .ctl_name = 0 }
66416+};
66417+#endif
66418+
66419 extern int prove_locking;
66420 extern int lock_stat;
66421
66422@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = N
66423 #endif
66424
66425 static struct ctl_table kern_table[] = {
66426+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66427+ {
66428+ .ctl_name = CTL_UNNUMBERED,
66429+ .procname = "grsecurity",
66430+ .mode = 0500,
66431+ .child = grsecurity_table,
66432+ },
66433+#endif
66434+
66435+#ifdef CONFIG_PAX_SOFTMODE
66436+ {
66437+ .ctl_name = CTL_UNNUMBERED,
66438+ .procname = "pax",
66439+ .mode = 0500,
66440+ .child = pax_table,
66441+ },
66442+#endif
66443+
66444 {
66445 .ctl_name = CTL_UNNUMBERED,
66446 .procname = "sched_child_runs_first",
66447@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
66448 .data = &modprobe_path,
66449 .maxlen = KMOD_PATH_LEN,
66450 .mode = 0644,
66451- .proc_handler = &proc_dostring,
66452- .strategy = &sysctl_string,
66453+ .proc_handler = &proc_dostring_modpriv,
66454+ .strategy = &sysctl_string_modpriv,
66455 },
66456 {
66457 .ctl_name = CTL_UNNUMBERED,
66458@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
66459 .mode = 0644,
66460 .proc_handler = &proc_dointvec
66461 },
66462+ {
66463+ .procname = "heap_stack_gap",
66464+ .data = &sysctl_heap_stack_gap,
66465+ .maxlen = sizeof(sysctl_heap_stack_gap),
66466+ .mode = 0644,
66467+ .proc_handler = proc_doulongvec_minmax,
66468+ },
66469 #else
66470 {
66471 .ctl_name = CTL_UNNUMBERED,
66472@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl
66473 return 0;
66474 }
66475
66476+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
66477+
66478 static int parse_table(int __user *name, int nlen,
66479 void __user *oldval, size_t __user *oldlenp,
66480 void __user *newval, size_t newlen,
66481@@ -1821,7 +1871,7 @@ repeat:
66482 if (n == table->ctl_name) {
66483 int error;
66484 if (table->child) {
66485- if (sysctl_perm(root, table, MAY_EXEC))
66486+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
66487 return -EPERM;
66488 name++;
66489 nlen--;
66490@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *r
66491 int error;
66492 int mode;
66493
66494+ if (table->parent != NULL && table->parent->procname != NULL &&
66495+ table->procname != NULL &&
66496+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
66497+ return -EACCES;
66498+ if (gr_handle_chroot_sysctl(op))
66499+ return -EACCES;
66500+ error = gr_handle_sysctl(table, op);
66501+ if (error)
66502+ return error;
66503+
66504+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
66505+ if (error)
66506+ return error;
66507+
66508+ if (root->permissions)
66509+ mode = root->permissions(root, current->nsproxy, table);
66510+ else
66511+ mode = table->mode;
66512+
66513+ return test_perm(mode, op);
66514+}
66515+
66516+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
66517+{
66518+ int error;
66519+ int mode;
66520+
66521 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
66522 if (error)
66523 return error;
66524@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *tabl
66525 buffer, lenp, ppos);
66526 }
66527
66528+int proc_dostring_modpriv(struct ctl_table *table, int write,
66529+ void __user *buffer, size_t *lenp, loff_t *ppos)
66530+{
66531+ if (write && !capable(CAP_SYS_MODULE))
66532+ return -EPERM;
66533+
66534+ return _proc_do_string(table->data, table->maxlen, write,
66535+ buffer, lenp, ppos);
66536+}
66537+
66538
66539 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
66540 int *valp,
66541@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(v
66542 vleft = table->maxlen / sizeof(unsigned long);
66543 left = *lenp;
66544
66545- for (; left && vleft--; i++, min++, max++, first=0) {
66546+ for (; left && vleft--; i++, first=0) {
66547 if (write) {
66548 while (left) {
66549 char c;
66550@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *tabl
66551 return -ENOSYS;
66552 }
66553
66554+int proc_dostring_modpriv(struct ctl_table *table, int write,
66555+ void __user *buffer, size_t *lenp, loff_t *ppos)
66556+{
66557+ return -ENOSYS;
66558+}
66559+
66560 int proc_dointvec(struct ctl_table *table, int write,
66561 void __user *buffer, size_t *lenp, loff_t *ppos)
66562 {
66563@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *tabl
66564 return 1;
66565 }
66566
66567+int sysctl_string_modpriv(struct ctl_table *table,
66568+ void __user *oldval, size_t __user *oldlenp,
66569+ void __user *newval, size_t newlen)
66570+{
66571+ if (newval && newlen && !capable(CAP_SYS_MODULE))
66572+ return -EPERM;
66573+
66574+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
66575+}
66576+
66577 /*
66578 * This function makes sure that all of the integers in the vector
66579 * are between the minimum and maximum values given in the arrays
66580@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *tabl
66581 return -ENOSYS;
66582 }
66583
66584+int sysctl_string_modpriv(struct ctl_table *table,
66585+ void __user *oldval, size_t __user *oldlenp,
66586+ void __user *newval, size_t newlen)
66587+{
66588+ return -ENOSYS;
66589+}
66590+
66591 int sysctl_intvec(struct ctl_table *table,
66592 void __user *oldval, size_t __user *oldlenp,
66593 void __user *newval, size_t newlen)
66594@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
66595 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
66596 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
66597 EXPORT_SYMBOL(proc_dostring);
66598+EXPORT_SYMBOL(proc_dostring_modpriv);
66599 EXPORT_SYMBOL(proc_doulongvec_minmax);
66600 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
66601 EXPORT_SYMBOL(register_sysctl_table);
66602@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
66603 EXPORT_SYMBOL(sysctl_jiffies);
66604 EXPORT_SYMBOL(sysctl_ms_jiffies);
66605 EXPORT_SYMBOL(sysctl_string);
66606+EXPORT_SYMBOL(sysctl_string_modpriv);
66607 EXPORT_SYMBOL(sysctl_data);
66608 EXPORT_SYMBOL(unregister_sysctl_table);
66609diff -urNp linux-2.6.32.44/kernel/sysctl_check.c linux-2.6.32.44/kernel/sysctl_check.c
66610--- linux-2.6.32.44/kernel/sysctl_check.c 2011-03-27 14:31:47.000000000 -0400
66611+++ linux-2.6.32.44/kernel/sysctl_check.c 2011-04-17 15:56:46.000000000 -0400
66612@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *n
66613 } else {
66614 if ((table->strategy == sysctl_data) ||
66615 (table->strategy == sysctl_string) ||
66616+ (table->strategy == sysctl_string_modpriv) ||
66617 (table->strategy == sysctl_intvec) ||
66618 (table->strategy == sysctl_jiffies) ||
66619 (table->strategy == sysctl_ms_jiffies) ||
66620 (table->proc_handler == proc_dostring) ||
66621+ (table->proc_handler == proc_dostring_modpriv) ||
66622 (table->proc_handler == proc_dointvec) ||
66623 (table->proc_handler == proc_dointvec_minmax) ||
66624 (table->proc_handler == proc_dointvec_jiffies) ||
66625diff -urNp linux-2.6.32.44/kernel/taskstats.c linux-2.6.32.44/kernel/taskstats.c
66626--- linux-2.6.32.44/kernel/taskstats.c 2011-07-13 17:23:04.000000000 -0400
66627+++ linux-2.6.32.44/kernel/taskstats.c 2011-07-13 17:23:19.000000000 -0400
66628@@ -26,9 +26,12 @@
66629 #include <linux/cgroup.h>
66630 #include <linux/fs.h>
66631 #include <linux/file.h>
66632+#include <linux/grsecurity.h>
66633 #include <net/genetlink.h>
66634 #include <asm/atomic.h>
66635
66636+extern int gr_is_taskstats_denied(int pid);
66637+
66638 /*
66639 * Maximum length of a cpumask that can be specified in
66640 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
66641@@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_
66642 size_t size;
66643 cpumask_var_t mask;
66644
66645+ if (gr_is_taskstats_denied(current->pid))
66646+ return -EACCES;
66647+
66648 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
66649 return -ENOMEM;
66650
66651diff -urNp linux-2.6.32.44/kernel/time/tick-broadcast.c linux-2.6.32.44/kernel/time/tick-broadcast.c
66652--- linux-2.6.32.44/kernel/time/tick-broadcast.c 2011-05-23 16:56:59.000000000 -0400
66653+++ linux-2.6.32.44/kernel/time/tick-broadcast.c 2011-05-23 16:57:13.000000000 -0400
66654@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl
66655 * then clear the broadcast bit.
66656 */
66657 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
66658- int cpu = smp_processor_id();
66659+ cpu = smp_processor_id();
66660
66661 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
66662 tick_broadcast_clear_oneshot(cpu);
66663diff -urNp linux-2.6.32.44/kernel/time/timekeeping.c linux-2.6.32.44/kernel/time/timekeeping.c
66664--- linux-2.6.32.44/kernel/time/timekeeping.c 2011-06-25 12:55:35.000000000 -0400
66665+++ linux-2.6.32.44/kernel/time/timekeeping.c 2011-06-25 12:56:37.000000000 -0400
66666@@ -14,6 +14,7 @@
66667 #include <linux/init.h>
66668 #include <linux/mm.h>
66669 #include <linux/sched.h>
66670+#include <linux/grsecurity.h>
66671 #include <linux/sysdev.h>
66672 #include <linux/clocksource.h>
66673 #include <linux/jiffies.h>
66674@@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
66675 */
66676 struct timespec ts = xtime;
66677 timespec_add_ns(&ts, nsec);
66678- ACCESS_ONCE(xtime_cache) = ts;
66679+ ACCESS_ONCE_RW(xtime_cache) = ts;
66680 }
66681
66682 /* must hold xtime_lock */
66683@@ -333,6 +334,8 @@ int do_settimeofday(struct timespec *tv)
66684 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
66685 return -EINVAL;
66686
66687+ gr_log_timechange();
66688+
66689 write_seqlock_irqsave(&xtime_lock, flags);
66690
66691 timekeeping_forward_now();
66692diff -urNp linux-2.6.32.44/kernel/time/timer_list.c linux-2.6.32.44/kernel/time/timer_list.c
66693--- linux-2.6.32.44/kernel/time/timer_list.c 2011-03-27 14:31:47.000000000 -0400
66694+++ linux-2.6.32.44/kernel/time/timer_list.c 2011-04-17 15:56:46.000000000 -0400
66695@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
66696
66697 static void print_name_offset(struct seq_file *m, void *sym)
66698 {
66699+#ifdef CONFIG_GRKERNSEC_HIDESYM
66700+ SEQ_printf(m, "<%p>", NULL);
66701+#else
66702 char symname[KSYM_NAME_LEN];
66703
66704 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
66705 SEQ_printf(m, "<%p>", sym);
66706 else
66707 SEQ_printf(m, "%s", symname);
66708+#endif
66709 }
66710
66711 static void
66712@@ -112,7 +116,11 @@ next_one:
66713 static void
66714 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
66715 {
66716+#ifdef CONFIG_GRKERNSEC_HIDESYM
66717+ SEQ_printf(m, " .base: %p\n", NULL);
66718+#else
66719 SEQ_printf(m, " .base: %p\n", base);
66720+#endif
66721 SEQ_printf(m, " .index: %d\n",
66722 base->index);
66723 SEQ_printf(m, " .resolution: %Lu nsecs\n",
66724@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs
66725 {
66726 struct proc_dir_entry *pe;
66727
66728+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66729+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
66730+#else
66731 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
66732+#endif
66733 if (!pe)
66734 return -ENOMEM;
66735 return 0;
66736diff -urNp linux-2.6.32.44/kernel/time/timer_stats.c linux-2.6.32.44/kernel/time/timer_stats.c
66737--- linux-2.6.32.44/kernel/time/timer_stats.c 2011-03-27 14:31:47.000000000 -0400
66738+++ linux-2.6.32.44/kernel/time/timer_stats.c 2011-05-04 17:56:28.000000000 -0400
66739@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
66740 static unsigned long nr_entries;
66741 static struct entry entries[MAX_ENTRIES];
66742
66743-static atomic_t overflow_count;
66744+static atomic_unchecked_t overflow_count;
66745
66746 /*
66747 * The entries are in a hash-table, for fast lookup:
66748@@ -140,7 +140,7 @@ static void reset_entries(void)
66749 nr_entries = 0;
66750 memset(entries, 0, sizeof(entries));
66751 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
66752- atomic_set(&overflow_count, 0);
66753+ atomic_set_unchecked(&overflow_count, 0);
66754 }
66755
66756 static struct entry *alloc_entry(void)
66757@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
66758 if (likely(entry))
66759 entry->count++;
66760 else
66761- atomic_inc(&overflow_count);
66762+ atomic_inc_unchecked(&overflow_count);
66763
66764 out_unlock:
66765 spin_unlock_irqrestore(lock, flags);
66766@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
66767
66768 static void print_name_offset(struct seq_file *m, unsigned long addr)
66769 {
66770+#ifdef CONFIG_GRKERNSEC_HIDESYM
66771+ seq_printf(m, "<%p>", NULL);
66772+#else
66773 char symname[KSYM_NAME_LEN];
66774
66775 if (lookup_symbol_name(addr, symname) < 0)
66776 seq_printf(m, "<%p>", (void *)addr);
66777 else
66778 seq_printf(m, "%s", symname);
66779+#endif
66780 }
66781
66782 static int tstats_show(struct seq_file *m, void *v)
66783@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
66784
66785 seq_puts(m, "Timer Stats Version: v0.2\n");
66786 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
66787- if (atomic_read(&overflow_count))
66788+ if (atomic_read_unchecked(&overflow_count))
66789 seq_printf(m, "Overflow: %d entries\n",
66790- atomic_read(&overflow_count));
66791+ atomic_read_unchecked(&overflow_count));
66792
66793 for (i = 0; i < nr_entries; i++) {
66794 entry = entries + i;
66795@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(voi
66796 {
66797 struct proc_dir_entry *pe;
66798
66799+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66800+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
66801+#else
66802 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
66803+#endif
66804 if (!pe)
66805 return -ENOMEM;
66806 return 0;
66807diff -urNp linux-2.6.32.44/kernel/time.c linux-2.6.32.44/kernel/time.c
66808--- linux-2.6.32.44/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
66809+++ linux-2.6.32.44/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
66810@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec
66811 return error;
66812
66813 if (tz) {
66814+ /* we log in do_settimeofday called below, so don't log twice
66815+ */
66816+ if (!tv)
66817+ gr_log_timechange();
66818+
66819 /* SMP safe, global irq locking makes it work. */
66820 sys_tz = *tz;
66821 update_vsyscall_tz();
66822@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
66823 * Avoid unnecessary multiplications/divisions in the
66824 * two most common HZ cases:
66825 */
66826-unsigned int inline jiffies_to_msecs(const unsigned long j)
66827+inline unsigned int jiffies_to_msecs(const unsigned long j)
66828 {
66829 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
66830 return (MSEC_PER_SEC / HZ) * j;
66831@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(con
66832 }
66833 EXPORT_SYMBOL(jiffies_to_msecs);
66834
66835-unsigned int inline jiffies_to_usecs(const unsigned long j)
66836+inline unsigned int jiffies_to_usecs(const unsigned long j)
66837 {
66838 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
66839 return (USEC_PER_SEC / HZ) * j;
66840diff -urNp linux-2.6.32.44/kernel/timer.c linux-2.6.32.44/kernel/timer.c
66841--- linux-2.6.32.44/kernel/timer.c 2011-03-27 14:31:47.000000000 -0400
66842+++ linux-2.6.32.44/kernel/timer.c 2011-04-17 15:56:46.000000000 -0400
66843@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
66844 /*
66845 * This function runs timers and the timer-tq in bottom half context.
66846 */
66847-static void run_timer_softirq(struct softirq_action *h)
66848+static void run_timer_softirq(void)
66849 {
66850 struct tvec_base *base = __get_cpu_var(tvec_bases);
66851
66852diff -urNp linux-2.6.32.44/kernel/trace/blktrace.c linux-2.6.32.44/kernel/trace/blktrace.c
66853--- linux-2.6.32.44/kernel/trace/blktrace.c 2011-03-27 14:31:47.000000000 -0400
66854+++ linux-2.6.32.44/kernel/trace/blktrace.c 2011-05-04 17:56:28.000000000 -0400
66855@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct f
66856 struct blk_trace *bt = filp->private_data;
66857 char buf[16];
66858
66859- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
66860+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
66861
66862 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
66863 }
66864@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(str
66865 return 1;
66866
66867 bt = buf->chan->private_data;
66868- atomic_inc(&bt->dropped);
66869+ atomic_inc_unchecked(&bt->dropped);
66870 return 0;
66871 }
66872
66873@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_qu
66874
66875 bt->dir = dir;
66876 bt->dev = dev;
66877- atomic_set(&bt->dropped, 0);
66878+ atomic_set_unchecked(&bt->dropped, 0);
66879
66880 ret = -EIO;
66881 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
66882diff -urNp linux-2.6.32.44/kernel/trace/ftrace.c linux-2.6.32.44/kernel/trace/ftrace.c
66883--- linux-2.6.32.44/kernel/trace/ftrace.c 2011-06-25 12:55:35.000000000 -0400
66884+++ linux-2.6.32.44/kernel/trace/ftrace.c 2011-06-25 12:56:37.000000000 -0400
66885@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod,
66886
66887 ip = rec->ip;
66888
66889+ ret = ftrace_arch_code_modify_prepare();
66890+ FTRACE_WARN_ON(ret);
66891+ if (ret)
66892+ return 0;
66893+
66894 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
66895+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
66896 if (ret) {
66897 ftrace_bug(ret, ip);
66898 rec->flags |= FTRACE_FL_FAILED;
66899- return 0;
66900 }
66901- return 1;
66902+ return ret ? 0 : 1;
66903 }
66904
66905 /*
66906diff -urNp linux-2.6.32.44/kernel/trace/ring_buffer.c linux-2.6.32.44/kernel/trace/ring_buffer.c
66907--- linux-2.6.32.44/kernel/trace/ring_buffer.c 2011-03-27 14:31:47.000000000 -0400
66908+++ linux-2.6.32.44/kernel/trace/ring_buffer.c 2011-04-17 15:56:46.000000000 -0400
66909@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(st
66910 * the reader page). But if the next page is a header page,
66911 * its flags will be non zero.
66912 */
66913-static int inline
66914+static inline int
66915 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
66916 struct buffer_page *page, struct list_head *list)
66917 {
66918diff -urNp linux-2.6.32.44/kernel/trace/trace.c linux-2.6.32.44/kernel/trace/trace.c
66919--- linux-2.6.32.44/kernel/trace/trace.c 2011-03-27 14:31:47.000000000 -0400
66920+++ linux-2.6.32.44/kernel/trace/trace.c 2011-05-16 21:46:57.000000000 -0400
66921@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(
66922 size_t rem;
66923 unsigned int i;
66924
66925+ pax_track_stack();
66926+
66927 /* copy the tracer to avoid using a global lock all around */
66928 mutex_lock(&trace_types_lock);
66929 if (unlikely(old_tracer != current_trace && current_trace)) {
66930@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file
66931 int entries, size, i;
66932 size_t ret;
66933
66934+ pax_track_stack();
66935+
66936 if (*ppos & (PAGE_SIZE - 1)) {
66937 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
66938 return -EINVAL;
66939@@ -3816,10 +3820,9 @@ static const struct file_operations trac
66940 };
66941 #endif
66942
66943-static struct dentry *d_tracer;
66944-
66945 struct dentry *tracing_init_dentry(void)
66946 {
66947+ static struct dentry *d_tracer;
66948 static int once;
66949
66950 if (d_tracer)
66951@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
66952 return d_tracer;
66953 }
66954
66955-static struct dentry *d_percpu;
66956-
66957 struct dentry *tracing_dentry_percpu(void)
66958 {
66959+ static struct dentry *d_percpu;
66960 static int once;
66961 struct dentry *d_tracer;
66962
66963diff -urNp linux-2.6.32.44/kernel/trace/trace_events.c linux-2.6.32.44/kernel/trace/trace_events.c
66964--- linux-2.6.32.44/kernel/trace/trace_events.c 2011-03-27 14:31:47.000000000 -0400
66965+++ linux-2.6.32.44/kernel/trace/trace_events.c 2011-08-05 20:33:55.000000000 -0400
66966@@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list
66967 * Modules must own their file_operations to keep up with
66968 * reference counting.
66969 */
66970+
66971 struct ftrace_module_file_ops {
66972 struct list_head list;
66973 struct module *mod;
66974- struct file_operations id;
66975- struct file_operations enable;
66976- struct file_operations format;
66977- struct file_operations filter;
66978 };
66979
66980 static void remove_subsystem_dir(const char *name)
66981@@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod
66982
66983 file_ops->mod = mod;
66984
66985- file_ops->id = ftrace_event_id_fops;
66986- file_ops->id.owner = mod;
66987-
66988- file_ops->enable = ftrace_enable_fops;
66989- file_ops->enable.owner = mod;
66990-
66991- file_ops->filter = ftrace_event_filter_fops;
66992- file_ops->filter.owner = mod;
66993-
66994- file_ops->format = ftrace_event_format_fops;
66995- file_ops->format.owner = mod;
66996+ pax_open_kernel();
66997+ *(void **)&mod->trace_id.owner = mod;
66998+ *(void **)&mod->trace_enable.owner = mod;
66999+ *(void **)&mod->trace_filter.owner = mod;
67000+ *(void **)&mod->trace_format.owner = mod;
67001+ pax_close_kernel();
67002
67003 list_add(&file_ops->list, &ftrace_module_file_list);
67004
67005@@ -1063,8 +1055,8 @@ static void trace_module_add_events(stru
67006 call->mod = mod;
67007 list_add(&call->list, &ftrace_events);
67008 event_create_dir(call, d_events,
67009- &file_ops->id, &file_ops->enable,
67010- &file_ops->filter, &file_ops->format);
67011+ &mod->trace_id, &mod->trace_enable,
67012+ &mod->trace_filter, &mod->trace_format);
67013 }
67014 }
67015
67016diff -urNp linux-2.6.32.44/kernel/trace/trace_mmiotrace.c linux-2.6.32.44/kernel/trace/trace_mmiotrace.c
67017--- linux-2.6.32.44/kernel/trace/trace_mmiotrace.c 2011-03-27 14:31:47.000000000 -0400
67018+++ linux-2.6.32.44/kernel/trace/trace_mmiotrace.c 2011-05-04 17:56:28.000000000 -0400
67019@@ -23,7 +23,7 @@ struct header_iter {
67020 static struct trace_array *mmio_trace_array;
67021 static bool overrun_detected;
67022 static unsigned long prev_overruns;
67023-static atomic_t dropped_count;
67024+static atomic_unchecked_t dropped_count;
67025
67026 static void mmio_reset_data(struct trace_array *tr)
67027 {
67028@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iter
67029
67030 static unsigned long count_overruns(struct trace_iterator *iter)
67031 {
67032- unsigned long cnt = atomic_xchg(&dropped_count, 0);
67033+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
67034 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
67035
67036 if (over > prev_overruns)
67037@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct
67038 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
67039 sizeof(*entry), 0, pc);
67040 if (!event) {
67041- atomic_inc(&dropped_count);
67042+ atomic_inc_unchecked(&dropped_count);
67043 return;
67044 }
67045 entry = ring_buffer_event_data(event);
67046@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct
67047 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
67048 sizeof(*entry), 0, pc);
67049 if (!event) {
67050- atomic_inc(&dropped_count);
67051+ atomic_inc_unchecked(&dropped_count);
67052 return;
67053 }
67054 entry = ring_buffer_event_data(event);
67055diff -urNp linux-2.6.32.44/kernel/trace/trace_output.c linux-2.6.32.44/kernel/trace/trace_output.c
67056--- linux-2.6.32.44/kernel/trace/trace_output.c 2011-03-27 14:31:47.000000000 -0400
67057+++ linux-2.6.32.44/kernel/trace/trace_output.c 2011-04-17 15:56:46.000000000 -0400
67058@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s,
67059 return 0;
67060 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
67061 if (!IS_ERR(p)) {
67062- p = mangle_path(s->buffer + s->len, p, "\n");
67063+ p = mangle_path(s->buffer + s->len, p, "\n\\");
67064 if (p) {
67065 s->len = p - s->buffer;
67066 return 1;
67067diff -urNp linux-2.6.32.44/kernel/trace/trace_stack.c linux-2.6.32.44/kernel/trace/trace_stack.c
67068--- linux-2.6.32.44/kernel/trace/trace_stack.c 2011-03-27 14:31:47.000000000 -0400
67069+++ linux-2.6.32.44/kernel/trace/trace_stack.c 2011-04-17 15:56:46.000000000 -0400
67070@@ -50,7 +50,7 @@ static inline void check_stack(void)
67071 return;
67072
67073 /* we do not handle interrupt stacks yet */
67074- if (!object_is_on_stack(&this_size))
67075+ if (!object_starts_on_stack(&this_size))
67076 return;
67077
67078 local_irq_save(flags);
67079diff -urNp linux-2.6.32.44/kernel/trace/trace_workqueue.c linux-2.6.32.44/kernel/trace/trace_workqueue.c
67080--- linux-2.6.32.44/kernel/trace/trace_workqueue.c 2011-03-27 14:31:47.000000000 -0400
67081+++ linux-2.6.32.44/kernel/trace/trace_workqueue.c 2011-04-17 15:56:46.000000000 -0400
67082@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
67083 int cpu;
67084 pid_t pid;
67085 /* Can be inserted from interrupt or user context, need to be atomic */
67086- atomic_t inserted;
67087+ atomic_unchecked_t inserted;
67088 /*
67089 * Don't need to be atomic, works are serialized in a single workqueue thread
67090 * on a single CPU.
67091@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_st
67092 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
67093 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
67094 if (node->pid == wq_thread->pid) {
67095- atomic_inc(&node->inserted);
67096+ atomic_inc_unchecked(&node->inserted);
67097 goto found;
67098 }
67099 }
67100@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct se
67101 tsk = get_pid_task(pid, PIDTYPE_PID);
67102 if (tsk) {
67103 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
67104- atomic_read(&cws->inserted), cws->executed,
67105+ atomic_read_unchecked(&cws->inserted), cws->executed,
67106 tsk->comm);
67107 put_task_struct(tsk);
67108 }
67109diff -urNp linux-2.6.32.44/kernel/user.c linux-2.6.32.44/kernel/user.c
67110--- linux-2.6.32.44/kernel/user.c 2011-03-27 14:31:47.000000000 -0400
67111+++ linux-2.6.32.44/kernel/user.c 2011-04-17 15:56:46.000000000 -0400
67112@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct use
67113 spin_lock_irq(&uidhash_lock);
67114 up = uid_hash_find(uid, hashent);
67115 if (up) {
67116+ put_user_ns(ns);
67117 key_put(new->uid_keyring);
67118 key_put(new->session_keyring);
67119 kmem_cache_free(uid_cachep, new);
67120diff -urNp linux-2.6.32.44/lib/bug.c linux-2.6.32.44/lib/bug.c
67121--- linux-2.6.32.44/lib/bug.c 2011-03-27 14:31:47.000000000 -0400
67122+++ linux-2.6.32.44/lib/bug.c 2011-04-17 15:56:46.000000000 -0400
67123@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned l
67124 return BUG_TRAP_TYPE_NONE;
67125
67126 bug = find_bug(bugaddr);
67127+ if (!bug)
67128+ return BUG_TRAP_TYPE_NONE;
67129
67130 printk(KERN_EMERG "------------[ cut here ]------------\n");
67131
67132diff -urNp linux-2.6.32.44/lib/debugobjects.c linux-2.6.32.44/lib/debugobjects.c
67133--- linux-2.6.32.44/lib/debugobjects.c 2011-07-13 17:23:04.000000000 -0400
67134+++ linux-2.6.32.44/lib/debugobjects.c 2011-07-13 17:23:19.000000000 -0400
67135@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(voi
67136 if (limit > 4)
67137 return;
67138
67139- is_on_stack = object_is_on_stack(addr);
67140+ is_on_stack = object_starts_on_stack(addr);
67141 if (is_on_stack == onstack)
67142 return;
67143
67144diff -urNp linux-2.6.32.44/lib/dma-debug.c linux-2.6.32.44/lib/dma-debug.c
67145--- linux-2.6.32.44/lib/dma-debug.c 2011-03-27 14:31:47.000000000 -0400
67146+++ linux-2.6.32.44/lib/dma-debug.c 2011-04-17 15:56:46.000000000 -0400
67147@@ -861,7 +861,7 @@ out:
67148
67149 static void check_for_stack(struct device *dev, void *addr)
67150 {
67151- if (object_is_on_stack(addr))
67152+ if (object_starts_on_stack(addr))
67153 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
67154 "stack [addr=%p]\n", addr);
67155 }
67156diff -urNp linux-2.6.32.44/lib/idr.c linux-2.6.32.44/lib/idr.c
67157--- linux-2.6.32.44/lib/idr.c 2011-03-27 14:31:47.000000000 -0400
67158+++ linux-2.6.32.44/lib/idr.c 2011-04-17 15:56:46.000000000 -0400
67159@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, in
67160 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
67161
67162 /* if already at the top layer, we need to grow */
67163- if (id >= 1 << (idp->layers * IDR_BITS)) {
67164+ if (id >= (1 << (idp->layers * IDR_BITS))) {
67165 *starting_id = id;
67166 return IDR_NEED_TO_GROW;
67167 }
67168diff -urNp linux-2.6.32.44/lib/inflate.c linux-2.6.32.44/lib/inflate.c
67169--- linux-2.6.32.44/lib/inflate.c 2011-03-27 14:31:47.000000000 -0400
67170+++ linux-2.6.32.44/lib/inflate.c 2011-04-17 15:56:46.000000000 -0400
67171@@ -266,7 +266,7 @@ static void free(void *where)
67172 malloc_ptr = free_mem_ptr;
67173 }
67174 #else
67175-#define malloc(a) kmalloc(a, GFP_KERNEL)
67176+#define malloc(a) kmalloc((a), GFP_KERNEL)
67177 #define free(a) kfree(a)
67178 #endif
67179
67180diff -urNp linux-2.6.32.44/lib/Kconfig.debug linux-2.6.32.44/lib/Kconfig.debug
67181--- linux-2.6.32.44/lib/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
67182+++ linux-2.6.32.44/lib/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
67183@@ -905,7 +905,7 @@ config LATENCYTOP
67184 select STACKTRACE
67185 select SCHEDSTATS
67186 select SCHED_DEBUG
67187- depends on HAVE_LATENCYTOP_SUPPORT
67188+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
67189 help
67190 Enable this option if you want to use the LatencyTOP tool
67191 to find out which userspace is blocking on what kernel operations.
67192diff -urNp linux-2.6.32.44/lib/kobject.c linux-2.6.32.44/lib/kobject.c
67193--- linux-2.6.32.44/lib/kobject.c 2011-03-27 14:31:47.000000000 -0400
67194+++ linux-2.6.32.44/lib/kobject.c 2011-04-17 15:56:46.000000000 -0400
67195@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct ko
67196 return ret;
67197 }
67198
67199-struct sysfs_ops kobj_sysfs_ops = {
67200+const struct sysfs_ops kobj_sysfs_ops = {
67201 .show = kobj_attr_show,
67202 .store = kobj_attr_store,
67203 };
67204@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
67205 * If the kset was not able to be created, NULL will be returned.
67206 */
67207 static struct kset *kset_create(const char *name,
67208- struct kset_uevent_ops *uevent_ops,
67209+ const struct kset_uevent_ops *uevent_ops,
67210 struct kobject *parent_kobj)
67211 {
67212 struct kset *kset;
67213@@ -832,7 +832,7 @@ static struct kset *kset_create(const ch
67214 * If the kset was not able to be created, NULL will be returned.
67215 */
67216 struct kset *kset_create_and_add(const char *name,
67217- struct kset_uevent_ops *uevent_ops,
67218+ const struct kset_uevent_ops *uevent_ops,
67219 struct kobject *parent_kobj)
67220 {
67221 struct kset *kset;
67222diff -urNp linux-2.6.32.44/lib/kobject_uevent.c linux-2.6.32.44/lib/kobject_uevent.c
67223--- linux-2.6.32.44/lib/kobject_uevent.c 2011-03-27 14:31:47.000000000 -0400
67224+++ linux-2.6.32.44/lib/kobject_uevent.c 2011-04-17 15:56:46.000000000 -0400
67225@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *k
67226 const char *subsystem;
67227 struct kobject *top_kobj;
67228 struct kset *kset;
67229- struct kset_uevent_ops *uevent_ops;
67230+ const struct kset_uevent_ops *uevent_ops;
67231 u64 seq;
67232 int i = 0;
67233 int retval = 0;
67234diff -urNp linux-2.6.32.44/lib/kref.c linux-2.6.32.44/lib/kref.c
67235--- linux-2.6.32.44/lib/kref.c 2011-03-27 14:31:47.000000000 -0400
67236+++ linux-2.6.32.44/lib/kref.c 2011-04-17 15:56:46.000000000 -0400
67237@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
67238 */
67239 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
67240 {
67241- WARN_ON(release == NULL);
67242+ BUG_ON(release == NULL);
67243 WARN_ON(release == (void (*)(struct kref *))kfree);
67244
67245 if (atomic_dec_and_test(&kref->refcount)) {
67246diff -urNp linux-2.6.32.44/lib/Makefile linux-2.6.32.44/lib/Makefile
67247--- linux-2.6.32.44/lib/Makefile 2011-03-27 14:31:47.000000000 -0400
67248+++ linux-2.6.32.44/lib/Makefile 2011-08-07 19:48:09.000000000 -0400
67249@@ -10,7 +10,7 @@ endif
67250 lib-y := ctype.o string.o vsprintf.o cmdline.o \
67251 rbtree.o radix-tree.o dump_stack.o \
67252 idr.o int_sqrt.o extable.o prio_tree.o \
67253- sha1.o irq_regs.o reciprocal_div.o argv_split.o \
67254+ sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \
67255 proportions.o prio_heap.o ratelimit.o show_mem.o \
67256 is_single_threaded.o plist.o decompress.o flex_array.o
67257
67258diff -urNp linux-2.6.32.44/lib/md5.c linux-2.6.32.44/lib/md5.c
67259--- linux-2.6.32.44/lib/md5.c 1969-12-31 19:00:00.000000000 -0500
67260+++ linux-2.6.32.44/lib/md5.c 2011-08-07 19:48:09.000000000 -0400
67261@@ -0,0 +1,95 @@
67262+#include <linux/kernel.h>
67263+#include <linux/module.h>
67264+#include <linux/cryptohash.h>
67265+
67266+#define F1(x, y, z) (z ^ (x & (y ^ z)))
67267+#define F2(x, y, z) F1(z, x, y)
67268+#define F3(x, y, z) (x ^ y ^ z)
67269+#define F4(x, y, z) (y ^ (x | ~z))
67270+
67271+#define MD5STEP(f, w, x, y, z, in, s) \
67272+ (w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x)
67273+
67274+void md5_transform(__u32 *hash, __u32 const *in)
67275+{
67276+ u32 a, b, c, d;
67277+
67278+ a = hash[0];
67279+ b = hash[1];
67280+ c = hash[2];
67281+ d = hash[3];
67282+
67283+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
67284+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
67285+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
67286+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
67287+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
67288+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
67289+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
67290+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
67291+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
67292+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
67293+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
67294+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
67295+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
67296+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
67297+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
67298+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
67299+
67300+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
67301+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
67302+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
67303+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
67304+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
67305+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
67306+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
67307+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
67308+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
67309+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
67310+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
67311+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
67312+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
67313+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
67314+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
67315+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
67316+
67317+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
67318+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
67319+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
67320+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
67321+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
67322+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
67323+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
67324+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
67325+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
67326+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
67327+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
67328+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
67329+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
67330+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
67331+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
67332+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
67333+
67334+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
67335+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
67336+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
67337+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
67338+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
67339+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
67340+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
67341+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
67342+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
67343+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
67344+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
67345+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
67346+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
67347+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
67348+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
67349+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
67350+
67351+ hash[0] += a;
67352+ hash[1] += b;
67353+ hash[2] += c;
67354+ hash[3] += d;
67355+}
67356+EXPORT_SYMBOL(md5_transform);
67357diff -urNp linux-2.6.32.44/lib/parser.c linux-2.6.32.44/lib/parser.c
67358--- linux-2.6.32.44/lib/parser.c 2011-03-27 14:31:47.000000000 -0400
67359+++ linux-2.6.32.44/lib/parser.c 2011-04-17 15:56:46.000000000 -0400
67360@@ -126,7 +126,7 @@ static int match_number(substring_t *s,
67361 char *buf;
67362 int ret;
67363
67364- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
67365+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
67366 if (!buf)
67367 return -ENOMEM;
67368 memcpy(buf, s->from, s->to - s->from);
67369diff -urNp linux-2.6.32.44/lib/radix-tree.c linux-2.6.32.44/lib/radix-tree.c
67370--- linux-2.6.32.44/lib/radix-tree.c 2011-03-27 14:31:47.000000000 -0400
67371+++ linux-2.6.32.44/lib/radix-tree.c 2011-04-17 15:56:46.000000000 -0400
67372@@ -81,7 +81,7 @@ struct radix_tree_preload {
67373 int nr;
67374 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
67375 };
67376-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
67377+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
67378
67379 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
67380 {
67381diff -urNp linux-2.6.32.44/lib/random32.c linux-2.6.32.44/lib/random32.c
67382--- linux-2.6.32.44/lib/random32.c 2011-03-27 14:31:47.000000000 -0400
67383+++ linux-2.6.32.44/lib/random32.c 2011-04-17 15:56:46.000000000 -0400
67384@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *
67385 */
67386 static inline u32 __seed(u32 x, u32 m)
67387 {
67388- return (x < m) ? x + m : x;
67389+ return (x <= m) ? x + m + 1 : x;
67390 }
67391
67392 /**
67393diff -urNp linux-2.6.32.44/lib/vsprintf.c linux-2.6.32.44/lib/vsprintf.c
67394--- linux-2.6.32.44/lib/vsprintf.c 2011-03-27 14:31:47.000000000 -0400
67395+++ linux-2.6.32.44/lib/vsprintf.c 2011-04-17 15:56:46.000000000 -0400
67396@@ -16,6 +16,9 @@
67397 * - scnprintf and vscnprintf
67398 */
67399
67400+#ifdef CONFIG_GRKERNSEC_HIDESYM
67401+#define __INCLUDED_BY_HIDESYM 1
67402+#endif
67403 #include <stdarg.h>
67404 #include <linux/module.h>
67405 #include <linux/types.h>
67406@@ -546,12 +549,12 @@ static char *number(char *buf, char *end
67407 return buf;
67408 }
67409
67410-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
67411+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
67412 {
67413 int len, i;
67414
67415 if ((unsigned long)s < PAGE_SIZE)
67416- s = "<NULL>";
67417+ s = "(null)";
67418
67419 len = strnlen(s, spec.precision);
67420
67421@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, ch
67422 unsigned long value = (unsigned long) ptr;
67423 #ifdef CONFIG_KALLSYMS
67424 char sym[KSYM_SYMBOL_LEN];
67425- if (ext != 'f' && ext != 's')
67426+ if (ext != 'f' && ext != 's' && ext != 'a')
67427 sprint_symbol(sym, value);
67428 else
67429 kallsyms_lookup(value, NULL, NULL, NULL, sym);
67430@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf,
67431 * - 'f' For simple symbolic function names without offset
67432 * - 'S' For symbolic direct pointers with offset
67433 * - 's' For symbolic direct pointers without offset
67434+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
67435+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
67436 * - 'R' For a struct resource pointer, it prints the range of
67437 * addresses (not the name nor the flags)
67438 * - 'M' For a 6-byte MAC address, it prints the address in the
67439@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, ch
67440 struct printf_spec spec)
67441 {
67442 if (!ptr)
67443- return string(buf, end, "(null)", spec);
67444+ return string(buf, end, "(nil)", spec);
67445
67446 switch (*fmt) {
67447 case 'F':
67448@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, ch
67449 case 's':
67450 /* Fallthrough */
67451 case 'S':
67452+#ifdef CONFIG_GRKERNSEC_HIDESYM
67453+ break;
67454+#else
67455+ return symbol_string(buf, end, ptr, spec, *fmt);
67456+#endif
67457+ case 'a':
67458+ /* Fallthrough */
67459+ case 'A':
67460 return symbol_string(buf, end, ptr, spec, *fmt);
67461 case 'R':
67462 return resource_string(buf, end, ptr, spec);
67463@@ -1445,7 +1458,7 @@ do { \
67464 size_t len;
67465 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
67466 || (unsigned long)save_str < PAGE_SIZE)
67467- save_str = "<NULL>";
67468+ save_str = "(null)";
67469 len = strlen(save_str);
67470 if (str + len + 1 < end)
67471 memcpy(str, save_str, len + 1);
67472@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size,
67473 typeof(type) value; \
67474 if (sizeof(type) == 8) { \
67475 args = PTR_ALIGN(args, sizeof(u32)); \
67476- *(u32 *)&value = *(u32 *)args; \
67477- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
67478+ *(u32 *)&value = *(const u32 *)args; \
67479+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
67480 } else { \
67481 args = PTR_ALIGN(args, sizeof(type)); \
67482- value = *(typeof(type) *)args; \
67483+ value = *(const typeof(type) *)args; \
67484 } \
67485 args += sizeof(type); \
67486 value; \
67487@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size,
67488 const char *str_arg = args;
67489 size_t len = strlen(str_arg);
67490 args += len + 1;
67491- str = string(str, end, (char *)str_arg, spec);
67492+ str = string(str, end, str_arg, spec);
67493 break;
67494 }
67495
67496diff -urNp linux-2.6.32.44/localversion-grsec linux-2.6.32.44/localversion-grsec
67497--- linux-2.6.32.44/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
67498+++ linux-2.6.32.44/localversion-grsec 2011-04-17 15:56:46.000000000 -0400
67499@@ -0,0 +1 @@
67500+-grsec
67501diff -urNp linux-2.6.32.44/Makefile linux-2.6.32.44/Makefile
67502--- linux-2.6.32.44/Makefile 2011-08-09 18:35:28.000000000 -0400
67503+++ linux-2.6.32.44/Makefile 2011-08-09 18:33:56.000000000 -0400
67504@@ -221,8 +221,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
67505
67506 HOSTCC = gcc
67507 HOSTCXX = g++
67508-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
67509-HOSTCXXFLAGS = -O2
67510+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
67511+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
67512+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
67513
67514 # Decide whether to build built-in, modular, or both.
67515 # Normally, just do built-in.
67516@@ -342,10 +343,12 @@ LINUXINCLUDE := -Iinclude \
67517 KBUILD_CPPFLAGS := -D__KERNEL__
67518
67519 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
67520+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
67521 -fno-strict-aliasing -fno-common \
67522 -Werror-implicit-function-declaration \
67523 -Wno-format-security \
67524 -fno-delete-null-pointer-checks
67525+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
67526 KBUILD_AFLAGS := -D__ASSEMBLY__
67527
67528 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
67529@@ -376,8 +379,8 @@ export RCS_TAR_IGNORE := --exclude SCCS
67530 # Rules shared between *config targets and build targets
67531
67532 # Basic helpers built in scripts/
67533-PHONY += scripts_basic
67534-scripts_basic:
67535+PHONY += scripts_basic gcc-plugins
67536+scripts_basic: gcc-plugins
67537 $(Q)$(MAKE) $(build)=scripts/basic
67538
67539 # To avoid any implicit rule to kick in, define an empty command.
67540@@ -403,7 +406,7 @@ endif
67541 # of make so .config is not included in this case either (for *config).
67542
67543 no-dot-config-targets := clean mrproper distclean \
67544- cscope TAGS tags help %docs check% \
67545+ cscope gtags TAGS tags help %docs check% \
67546 include/linux/version.h headers_% \
67547 kernelrelease kernelversion
67548
67549@@ -526,6 +529,25 @@ else
67550 KBUILD_CFLAGS += -O2
67551 endif
67552
67553+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh $(HOSTCC)), y)
67554+CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so
67555+ifdef CONFIG_PAX_MEMORY_STACKLEAK
67556+STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -fplugin-arg-stackleak_plugin-track-lowest-sp=100
67557+endif
67558+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
67559+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN
67560+gcc-plugins:
67561+ $(Q)$(MAKE) $(build)=tools/gcc
67562+else
67563+gcc-plugins:
67564+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
67565+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev.))
67566+else
67567+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
67568+endif
67569+ $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
67570+endif
67571+
67572 include $(srctree)/arch/$(SRCARCH)/Makefile
67573
67574 ifneq ($(CONFIG_FRAME_WARN),0)
67575@@ -644,7 +666,7 @@ export mod_strip_cmd
67576
67577
67578 ifeq ($(KBUILD_EXTMOD),)
67579-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
67580+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
67581
67582 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
67583 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
67584@@ -970,7 +992,7 @@ ifneq ($(KBUILD_SRC),)
67585 endif
67586
67587 # prepare2 creates a makefile if using a separate output directory
67588-prepare2: prepare3 outputmakefile
67589+prepare2: prepare3 outputmakefile gcc-plugins
67590
67591 prepare1: prepare2 include/linux/version.h include/linux/utsrelease.h \
67592 include/asm include/config/auto.conf
67593@@ -1198,7 +1220,7 @@ MRPROPER_FILES += .config .config.old in
67594 include/linux/autoconf.h include/linux/version.h \
67595 include/linux/utsrelease.h \
67596 include/linux/bounds.h include/asm*/asm-offsets.h \
67597- Module.symvers Module.markers tags TAGS cscope*
67598+ Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
67599
67600 # clean - Delete most, but leave enough to build external modules
67601 #
67602@@ -1289,6 +1311,7 @@ help:
67603 @echo ' modules_prepare - Set up for building external modules'
67604 @echo ' tags/TAGS - Generate tags file for editors'
67605 @echo ' cscope - Generate cscope index'
67606+ @echo ' gtags - Generate GNU GLOBAL index'
67607 @echo ' kernelrelease - Output the release version string'
67608 @echo ' kernelversion - Output the version stored in Makefile'
67609 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
67610@@ -1421,7 +1444,7 @@ clean: $(clean-dirs)
67611 $(call cmd,rmdirs)
67612 $(call cmd,rmfiles)
67613 @find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
67614- \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
67615+ \( -name '*.[oas]' -o -name '*.[ks]o' -o -name '.*.cmd' \
67616 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
67617 -o -name '*.gcno' \) -type f -print | xargs rm -f
67618
67619@@ -1445,7 +1468,7 @@ endif # KBUILD_EXTMOD
67620 quiet_cmd_tags = GEN $@
67621 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
67622
67623-tags TAGS cscope: FORCE
67624+tags TAGS cscope gtags: FORCE
67625 $(call cmd,tags)
67626
67627 # Scripts to check various things for consistency
67628diff -urNp linux-2.6.32.44/mm/backing-dev.c linux-2.6.32.44/mm/backing-dev.c
67629--- linux-2.6.32.44/mm/backing-dev.c 2011-03-27 14:31:47.000000000 -0400
67630+++ linux-2.6.32.44/mm/backing-dev.c 2011-08-11 19:48:17.000000000 -0400
67631@@ -272,7 +272,7 @@ static void bdi_task_init(struct backing
67632 list_add_tail_rcu(&wb->list, &bdi->wb_list);
67633 spin_unlock(&bdi->wb_lock);
67634
67635- tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
67636+ tsk->flags |= PF_SWAPWRITE;
67637 set_freezable();
67638
67639 /*
67640@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rc
67641 * Add the default flusher task that gets created for any bdi
67642 * that has dirty data pending writeout
67643 */
67644-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
67645+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
67646 {
67647 if (!bdi_cap_writeback_dirty(bdi))
67648 return;
67649diff -urNp linux-2.6.32.44/mm/filemap.c linux-2.6.32.44/mm/filemap.c
67650--- linux-2.6.32.44/mm/filemap.c 2011-03-27 14:31:47.000000000 -0400
67651+++ linux-2.6.32.44/mm/filemap.c 2011-04-17 15:56:46.000000000 -0400
67652@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file
67653 struct address_space *mapping = file->f_mapping;
67654
67655 if (!mapping->a_ops->readpage)
67656- return -ENOEXEC;
67657+ return -ENODEV;
67658 file_accessed(file);
67659 vma->vm_ops = &generic_file_vm_ops;
67660 vma->vm_flags |= VM_CAN_NONLINEAR;
67661@@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct f
67662 *pos = i_size_read(inode);
67663
67664 if (limit != RLIM_INFINITY) {
67665+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
67666 if (*pos >= limit) {
67667 send_sig(SIGXFSZ, current, 0);
67668 return -EFBIG;
67669diff -urNp linux-2.6.32.44/mm/fremap.c linux-2.6.32.44/mm/fremap.c
67670--- linux-2.6.32.44/mm/fremap.c 2011-03-27 14:31:47.000000000 -0400
67671+++ linux-2.6.32.44/mm/fremap.c 2011-04-17 15:56:46.000000000 -0400
67672@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
67673 retry:
67674 vma = find_vma(mm, start);
67675
67676+#ifdef CONFIG_PAX_SEGMEXEC
67677+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
67678+ goto out;
67679+#endif
67680+
67681 /*
67682 * Make sure the vma is shared, that it supports prefaulting,
67683 * and that the remapped range is valid and fully within
67684@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
67685 /*
67686 * drop PG_Mlocked flag for over-mapped range
67687 */
67688- unsigned int saved_flags = vma->vm_flags;
67689+ unsigned long saved_flags = vma->vm_flags;
67690 munlock_vma_pages_range(vma, start, start + size);
67691 vma->vm_flags = saved_flags;
67692 }
67693diff -urNp linux-2.6.32.44/mm/highmem.c linux-2.6.32.44/mm/highmem.c
67694--- linux-2.6.32.44/mm/highmem.c 2011-03-27 14:31:47.000000000 -0400
67695+++ linux-2.6.32.44/mm/highmem.c 2011-04-17 15:56:46.000000000 -0400
67696@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
67697 * So no dangers, even with speculative execution.
67698 */
67699 page = pte_page(pkmap_page_table[i]);
67700+ pax_open_kernel();
67701 pte_clear(&init_mm, (unsigned long)page_address(page),
67702 &pkmap_page_table[i]);
67703-
67704+ pax_close_kernel();
67705 set_page_address(page, NULL);
67706 need_flush = 1;
67707 }
67708@@ -177,9 +178,11 @@ start:
67709 }
67710 }
67711 vaddr = PKMAP_ADDR(last_pkmap_nr);
67712+
67713+ pax_open_kernel();
67714 set_pte_at(&init_mm, vaddr,
67715 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
67716-
67717+ pax_close_kernel();
67718 pkmap_count[last_pkmap_nr] = 1;
67719 set_page_address(page, (void *)vaddr);
67720
67721diff -urNp linux-2.6.32.44/mm/hugetlb.c linux-2.6.32.44/mm/hugetlb.c
67722--- linux-2.6.32.44/mm/hugetlb.c 2011-07-13 17:23:04.000000000 -0400
67723+++ linux-2.6.32.44/mm/hugetlb.c 2011-07-13 17:23:19.000000000 -0400
67724@@ -1933,6 +1933,26 @@ static int unmap_ref_private(struct mm_s
67725 return 1;
67726 }
67727
67728+#ifdef CONFIG_PAX_SEGMEXEC
67729+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
67730+{
67731+ struct mm_struct *mm = vma->vm_mm;
67732+ struct vm_area_struct *vma_m;
67733+ unsigned long address_m;
67734+ pte_t *ptep_m;
67735+
67736+ vma_m = pax_find_mirror_vma(vma);
67737+ if (!vma_m)
67738+ return;
67739+
67740+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67741+ address_m = address + SEGMEXEC_TASK_SIZE;
67742+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
67743+ get_page(page_m);
67744+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
67745+}
67746+#endif
67747+
67748 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
67749 unsigned long address, pte_t *ptep, pte_t pte,
67750 struct page *pagecache_page)
67751@@ -2004,6 +2024,11 @@ retry_avoidcopy:
67752 huge_ptep_clear_flush(vma, address, ptep);
67753 set_huge_pte_at(mm, address, ptep,
67754 make_huge_pte(vma, new_page, 1));
67755+
67756+#ifdef CONFIG_PAX_SEGMEXEC
67757+ pax_mirror_huge_pte(vma, address, new_page);
67758+#endif
67759+
67760 /* Make the old page be freed below */
67761 new_page = old_page;
67762 }
67763@@ -2135,6 +2160,10 @@ retry:
67764 && (vma->vm_flags & VM_SHARED)));
67765 set_huge_pte_at(mm, address, ptep, new_pte);
67766
67767+#ifdef CONFIG_PAX_SEGMEXEC
67768+ pax_mirror_huge_pte(vma, address, page);
67769+#endif
67770+
67771 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
67772 /* Optimization, do the COW without a second fault */
67773 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
67774@@ -2163,6 +2192,28 @@ int hugetlb_fault(struct mm_struct *mm,
67775 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
67776 struct hstate *h = hstate_vma(vma);
67777
67778+#ifdef CONFIG_PAX_SEGMEXEC
67779+ struct vm_area_struct *vma_m;
67780+
67781+ vma_m = pax_find_mirror_vma(vma);
67782+ if (vma_m) {
67783+ unsigned long address_m;
67784+
67785+ if (vma->vm_start > vma_m->vm_start) {
67786+ address_m = address;
67787+ address -= SEGMEXEC_TASK_SIZE;
67788+ vma = vma_m;
67789+ h = hstate_vma(vma);
67790+ } else
67791+ address_m = address + SEGMEXEC_TASK_SIZE;
67792+
67793+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
67794+ return VM_FAULT_OOM;
67795+ address_m &= HPAGE_MASK;
67796+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
67797+ }
67798+#endif
67799+
67800 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
67801 if (!ptep)
67802 return VM_FAULT_OOM;
67803diff -urNp linux-2.6.32.44/mm/internal.h linux-2.6.32.44/mm/internal.h
67804--- linux-2.6.32.44/mm/internal.h 2011-03-27 14:31:47.000000000 -0400
67805+++ linux-2.6.32.44/mm/internal.h 2011-07-09 09:13:08.000000000 -0400
67806@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page
67807 * in mm/page_alloc.c
67808 */
67809 extern void __free_pages_bootmem(struct page *page, unsigned int order);
67810+extern void free_compound_page(struct page *page);
67811 extern void prep_compound_page(struct page *page, unsigned long order);
67812
67813
67814diff -urNp linux-2.6.32.44/mm/Kconfig linux-2.6.32.44/mm/Kconfig
67815--- linux-2.6.32.44/mm/Kconfig 2011-03-27 14:31:47.000000000 -0400
67816+++ linux-2.6.32.44/mm/Kconfig 2011-04-17 15:56:46.000000000 -0400
67817@@ -228,7 +228,7 @@ config KSM
67818 config DEFAULT_MMAP_MIN_ADDR
67819 int "Low address space to protect from user allocation"
67820 depends on MMU
67821- default 4096
67822+ default 65536
67823 help
67824 This is the portion of low virtual memory which should be protected
67825 from userspace allocation. Keeping a user from writing to low pages
67826diff -urNp linux-2.6.32.44/mm/kmemleak.c linux-2.6.32.44/mm/kmemleak.c
67827--- linux-2.6.32.44/mm/kmemleak.c 2011-06-25 12:55:35.000000000 -0400
67828+++ linux-2.6.32.44/mm/kmemleak.c 2011-06-25 12:56:37.000000000 -0400
67829@@ -358,7 +358,7 @@ static void print_unreferenced(struct se
67830
67831 for (i = 0; i < object->trace_len; i++) {
67832 void *ptr = (void *)object->trace[i];
67833- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
67834+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
67835 }
67836 }
67837
67838diff -urNp linux-2.6.32.44/mm/maccess.c linux-2.6.32.44/mm/maccess.c
67839--- linux-2.6.32.44/mm/maccess.c 2011-03-27 14:31:47.000000000 -0400
67840+++ linux-2.6.32.44/mm/maccess.c 2011-04-17 15:56:46.000000000 -0400
67841@@ -14,7 +14,7 @@
67842 * Safely read from address @src to the buffer at @dst. If a kernel fault
67843 * happens, handle that and return -EFAULT.
67844 */
67845-long probe_kernel_read(void *dst, void *src, size_t size)
67846+long probe_kernel_read(void *dst, const void *src, size_t size)
67847 {
67848 long ret;
67849 mm_segment_t old_fs = get_fs();
67850@@ -39,7 +39,7 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
67851 * Safely write to address @dst from the buffer at @src. If a kernel fault
67852 * happens, handle that and return -EFAULT.
67853 */
67854-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
67855+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
67856 {
67857 long ret;
67858 mm_segment_t old_fs = get_fs();
67859diff -urNp linux-2.6.32.44/mm/madvise.c linux-2.6.32.44/mm/madvise.c
67860--- linux-2.6.32.44/mm/madvise.c 2011-03-27 14:31:47.000000000 -0400
67861+++ linux-2.6.32.44/mm/madvise.c 2011-04-17 15:56:46.000000000 -0400
67862@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_a
67863 pgoff_t pgoff;
67864 unsigned long new_flags = vma->vm_flags;
67865
67866+#ifdef CONFIG_PAX_SEGMEXEC
67867+ struct vm_area_struct *vma_m;
67868+#endif
67869+
67870 switch (behavior) {
67871 case MADV_NORMAL:
67872 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
67873@@ -103,6 +107,13 @@ success:
67874 /*
67875 * vm_flags is protected by the mmap_sem held in write mode.
67876 */
67877+
67878+#ifdef CONFIG_PAX_SEGMEXEC
67879+ vma_m = pax_find_mirror_vma(vma);
67880+ if (vma_m)
67881+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
67882+#endif
67883+
67884 vma->vm_flags = new_flags;
67885
67886 out:
67887@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_a
67888 struct vm_area_struct ** prev,
67889 unsigned long start, unsigned long end)
67890 {
67891+
67892+#ifdef CONFIG_PAX_SEGMEXEC
67893+ struct vm_area_struct *vma_m;
67894+#endif
67895+
67896 *prev = vma;
67897 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
67898 return -EINVAL;
67899@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_a
67900 zap_page_range(vma, start, end - start, &details);
67901 } else
67902 zap_page_range(vma, start, end - start, NULL);
67903+
67904+#ifdef CONFIG_PAX_SEGMEXEC
67905+ vma_m = pax_find_mirror_vma(vma);
67906+ if (vma_m) {
67907+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
67908+ struct zap_details details = {
67909+ .nonlinear_vma = vma_m,
67910+ .last_index = ULONG_MAX,
67911+ };
67912+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
67913+ } else
67914+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
67915+ }
67916+#endif
67917+
67918 return 0;
67919 }
67920
67921@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
67922 if (end < start)
67923 goto out;
67924
67925+#ifdef CONFIG_PAX_SEGMEXEC
67926+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
67927+ if (end > SEGMEXEC_TASK_SIZE)
67928+ goto out;
67929+ } else
67930+#endif
67931+
67932+ if (end > TASK_SIZE)
67933+ goto out;
67934+
67935 error = 0;
67936 if (end == start)
67937 goto out;
67938diff -urNp linux-2.6.32.44/mm/memory.c linux-2.6.32.44/mm/memory.c
67939--- linux-2.6.32.44/mm/memory.c 2011-07-13 17:23:04.000000000 -0400
67940+++ linux-2.6.32.44/mm/memory.c 2011-07-13 17:23:23.000000000 -0400
67941@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct
67942 return;
67943
67944 pmd = pmd_offset(pud, start);
67945+
67946+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
67947 pud_clear(pud);
67948 pmd_free_tlb(tlb, pmd, start);
67949+#endif
67950+
67951 }
67952
67953 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
67954@@ -219,9 +223,12 @@ static inline void free_pud_range(struct
67955 if (end - 1 > ceiling - 1)
67956 return;
67957
67958+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
67959 pud = pud_offset(pgd, start);
67960 pgd_clear(pgd);
67961 pud_free_tlb(tlb, pud, start);
67962+#endif
67963+
67964 }
67965
67966 /*
67967@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct
67968 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
67969 i = 0;
67970
67971- do {
67972+ while (nr_pages) {
67973 struct vm_area_struct *vma;
67974
67975- vma = find_extend_vma(mm, start);
67976+ vma = find_vma(mm, start);
67977 if (!vma && in_gate_area(tsk, start)) {
67978 unsigned long pg = start & PAGE_MASK;
67979 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
67980@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct
67981 continue;
67982 }
67983
67984- if (!vma ||
67985+ if (!vma || start < vma->vm_start ||
67986 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
67987 !(vm_flags & vma->vm_flags))
67988 return i ? : -EFAULT;
67989@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct
67990 start += PAGE_SIZE;
67991 nr_pages--;
67992 } while (nr_pages && start < vma->vm_end);
67993- } while (nr_pages);
67994+ }
67995 return i;
67996 }
67997
67998@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_st
67999 page_add_file_rmap(page);
68000 set_pte_at(mm, addr, pte, mk_pte(page, prot));
68001
68002+#ifdef CONFIG_PAX_SEGMEXEC
68003+ pax_mirror_file_pte(vma, addr, page, ptl);
68004+#endif
68005+
68006 retval = 0;
68007 pte_unmap_unlock(pte, ptl);
68008 return retval;
68009@@ -1560,10 +1571,22 @@ out:
68010 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
68011 struct page *page)
68012 {
68013+
68014+#ifdef CONFIG_PAX_SEGMEXEC
68015+ struct vm_area_struct *vma_m;
68016+#endif
68017+
68018 if (addr < vma->vm_start || addr >= vma->vm_end)
68019 return -EFAULT;
68020 if (!page_count(page))
68021 return -EINVAL;
68022+
68023+#ifdef CONFIG_PAX_SEGMEXEC
68024+ vma_m = pax_find_mirror_vma(vma);
68025+ if (vma_m)
68026+ vma_m->vm_flags |= VM_INSERTPAGE;
68027+#endif
68028+
68029 vma->vm_flags |= VM_INSERTPAGE;
68030 return insert_page(vma, addr, page, vma->vm_page_prot);
68031 }
68032@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struc
68033 unsigned long pfn)
68034 {
68035 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
68036+ BUG_ON(vma->vm_mirror);
68037
68038 if (addr < vma->vm_start || addr >= vma->vm_end)
68039 return -EFAULT;
68040@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct
68041 copy_user_highpage(dst, src, va, vma);
68042 }
68043
68044+#ifdef CONFIG_PAX_SEGMEXEC
68045+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
68046+{
68047+ struct mm_struct *mm = vma->vm_mm;
68048+ spinlock_t *ptl;
68049+ pte_t *pte, entry;
68050+
68051+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
68052+ entry = *pte;
68053+ if (!pte_present(entry)) {
68054+ if (!pte_none(entry)) {
68055+ BUG_ON(pte_file(entry));
68056+ free_swap_and_cache(pte_to_swp_entry(entry));
68057+ pte_clear_not_present_full(mm, address, pte, 0);
68058+ }
68059+ } else {
68060+ struct page *page;
68061+
68062+ flush_cache_page(vma, address, pte_pfn(entry));
68063+ entry = ptep_clear_flush(vma, address, pte);
68064+ BUG_ON(pte_dirty(entry));
68065+ page = vm_normal_page(vma, address, entry);
68066+ if (page) {
68067+ update_hiwater_rss(mm);
68068+ if (PageAnon(page))
68069+ dec_mm_counter(mm, anon_rss);
68070+ else
68071+ dec_mm_counter(mm, file_rss);
68072+ page_remove_rmap(page);
68073+ page_cache_release(page);
68074+ }
68075+ }
68076+ pte_unmap_unlock(pte, ptl);
68077+}
68078+
68079+/* PaX: if vma is mirrored, synchronize the mirror's PTE
68080+ *
68081+ * the ptl of the lower mapped page is held on entry and is not released on exit
68082+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
68083+ */
68084+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68085+{
68086+ struct mm_struct *mm = vma->vm_mm;
68087+ unsigned long address_m;
68088+ spinlock_t *ptl_m;
68089+ struct vm_area_struct *vma_m;
68090+ pmd_t *pmd_m;
68091+ pte_t *pte_m, entry_m;
68092+
68093+ BUG_ON(!page_m || !PageAnon(page_m));
68094+
68095+ vma_m = pax_find_mirror_vma(vma);
68096+ if (!vma_m)
68097+ return;
68098+
68099+ BUG_ON(!PageLocked(page_m));
68100+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68101+ address_m = address + SEGMEXEC_TASK_SIZE;
68102+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68103+ pte_m = pte_offset_map_nested(pmd_m, address_m);
68104+ ptl_m = pte_lockptr(mm, pmd_m);
68105+ if (ptl != ptl_m) {
68106+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68107+ if (!pte_none(*pte_m))
68108+ goto out;
68109+ }
68110+
68111+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68112+ page_cache_get(page_m);
68113+ page_add_anon_rmap(page_m, vma_m, address_m);
68114+ inc_mm_counter(mm, anon_rss);
68115+ set_pte_at(mm, address_m, pte_m, entry_m);
68116+ update_mmu_cache(vma_m, address_m, entry_m);
68117+out:
68118+ if (ptl != ptl_m)
68119+ spin_unlock(ptl_m);
68120+ pte_unmap_nested(pte_m);
68121+ unlock_page(page_m);
68122+}
68123+
68124+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68125+{
68126+ struct mm_struct *mm = vma->vm_mm;
68127+ unsigned long address_m;
68128+ spinlock_t *ptl_m;
68129+ struct vm_area_struct *vma_m;
68130+ pmd_t *pmd_m;
68131+ pte_t *pte_m, entry_m;
68132+
68133+ BUG_ON(!page_m || PageAnon(page_m));
68134+
68135+ vma_m = pax_find_mirror_vma(vma);
68136+ if (!vma_m)
68137+ return;
68138+
68139+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68140+ address_m = address + SEGMEXEC_TASK_SIZE;
68141+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68142+ pte_m = pte_offset_map_nested(pmd_m, address_m);
68143+ ptl_m = pte_lockptr(mm, pmd_m);
68144+ if (ptl != ptl_m) {
68145+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68146+ if (!pte_none(*pte_m))
68147+ goto out;
68148+ }
68149+
68150+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68151+ page_cache_get(page_m);
68152+ page_add_file_rmap(page_m);
68153+ inc_mm_counter(mm, file_rss);
68154+ set_pte_at(mm, address_m, pte_m, entry_m);
68155+ update_mmu_cache(vma_m, address_m, entry_m);
68156+out:
68157+ if (ptl != ptl_m)
68158+ spin_unlock(ptl_m);
68159+ pte_unmap_nested(pte_m);
68160+}
68161+
68162+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
68163+{
68164+ struct mm_struct *mm = vma->vm_mm;
68165+ unsigned long address_m;
68166+ spinlock_t *ptl_m;
68167+ struct vm_area_struct *vma_m;
68168+ pmd_t *pmd_m;
68169+ pte_t *pte_m, entry_m;
68170+
68171+ vma_m = pax_find_mirror_vma(vma);
68172+ if (!vma_m)
68173+ return;
68174+
68175+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68176+ address_m = address + SEGMEXEC_TASK_SIZE;
68177+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68178+ pte_m = pte_offset_map_nested(pmd_m, address_m);
68179+ ptl_m = pte_lockptr(mm, pmd_m);
68180+ if (ptl != ptl_m) {
68181+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68182+ if (!pte_none(*pte_m))
68183+ goto out;
68184+ }
68185+
68186+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
68187+ set_pte_at(mm, address_m, pte_m, entry_m);
68188+out:
68189+ if (ptl != ptl_m)
68190+ spin_unlock(ptl_m);
68191+ pte_unmap_nested(pte_m);
68192+}
68193+
68194+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
68195+{
68196+ struct page *page_m;
68197+ pte_t entry;
68198+
68199+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
68200+ goto out;
68201+
68202+ entry = *pte;
68203+ page_m = vm_normal_page(vma, address, entry);
68204+ if (!page_m)
68205+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
68206+ else if (PageAnon(page_m)) {
68207+ if (pax_find_mirror_vma(vma)) {
68208+ pte_unmap_unlock(pte, ptl);
68209+ lock_page(page_m);
68210+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
68211+ if (pte_same(entry, *pte))
68212+ pax_mirror_anon_pte(vma, address, page_m, ptl);
68213+ else
68214+ unlock_page(page_m);
68215+ }
68216+ } else
68217+ pax_mirror_file_pte(vma, address, page_m, ptl);
68218+
68219+out:
68220+ pte_unmap_unlock(pte, ptl);
68221+}
68222+#endif
68223+
68224 /*
68225 * This routine handles present pages, when users try to write
68226 * to a shared page. It is done by copying the page to a new address
68227@@ -2156,6 +2360,12 @@ gotten:
68228 */
68229 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68230 if (likely(pte_same(*page_table, orig_pte))) {
68231+
68232+#ifdef CONFIG_PAX_SEGMEXEC
68233+ if (pax_find_mirror_vma(vma))
68234+ BUG_ON(!trylock_page(new_page));
68235+#endif
68236+
68237 if (old_page) {
68238 if (!PageAnon(old_page)) {
68239 dec_mm_counter(mm, file_rss);
68240@@ -2207,6 +2417,10 @@ gotten:
68241 page_remove_rmap(old_page);
68242 }
68243
68244+#ifdef CONFIG_PAX_SEGMEXEC
68245+ pax_mirror_anon_pte(vma, address, new_page, ptl);
68246+#endif
68247+
68248 /* Free the old page.. */
68249 new_page = old_page;
68250 ret |= VM_FAULT_WRITE;
68251@@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct
68252 swap_free(entry);
68253 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
68254 try_to_free_swap(page);
68255+
68256+#ifdef CONFIG_PAX_SEGMEXEC
68257+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
68258+#endif
68259+
68260 unlock_page(page);
68261
68262 if (flags & FAULT_FLAG_WRITE) {
68263@@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct
68264
68265 /* No need to invalidate - it was non-present before */
68266 update_mmu_cache(vma, address, pte);
68267+
68268+#ifdef CONFIG_PAX_SEGMEXEC
68269+ pax_mirror_anon_pte(vma, address, page, ptl);
68270+#endif
68271+
68272 unlock:
68273 pte_unmap_unlock(page_table, ptl);
68274 out:
68275@@ -2632,40 +2856,6 @@ out_release:
68276 }
68277
68278 /*
68279- * This is like a special single-page "expand_{down|up}wards()",
68280- * except we must first make sure that 'address{-|+}PAGE_SIZE'
68281- * doesn't hit another vma.
68282- */
68283-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
68284-{
68285- address &= PAGE_MASK;
68286- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
68287- struct vm_area_struct *prev = vma->vm_prev;
68288-
68289- /*
68290- * Is there a mapping abutting this one below?
68291- *
68292- * That's only ok if it's the same stack mapping
68293- * that has gotten split..
68294- */
68295- if (prev && prev->vm_end == address)
68296- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
68297-
68298- expand_stack(vma, address - PAGE_SIZE);
68299- }
68300- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
68301- struct vm_area_struct *next = vma->vm_next;
68302-
68303- /* As VM_GROWSDOWN but s/below/above/ */
68304- if (next && next->vm_start == address + PAGE_SIZE)
68305- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
68306-
68307- expand_upwards(vma, address + PAGE_SIZE);
68308- }
68309- return 0;
68310-}
68311-
68312-/*
68313 * We enter with non-exclusive mmap_sem (to exclude vma changes,
68314 * but allow concurrent faults), and pte mapped but not yet locked.
68315 * We return with mmap_sem still held, but pte unmapped and unlocked.
68316@@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_s
68317 unsigned long address, pte_t *page_table, pmd_t *pmd,
68318 unsigned int flags)
68319 {
68320- struct page *page;
68321+ struct page *page = NULL;
68322 spinlock_t *ptl;
68323 pte_t entry;
68324
68325- pte_unmap(page_table);
68326-
68327- /* Check if we need to add a guard page to the stack */
68328- if (check_stack_guard_page(vma, address) < 0)
68329- return VM_FAULT_SIGBUS;
68330-
68331- /* Use the zero-page for reads */
68332 if (!(flags & FAULT_FLAG_WRITE)) {
68333 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
68334 vma->vm_page_prot));
68335- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68336+ ptl = pte_lockptr(mm, pmd);
68337+ spin_lock(ptl);
68338 if (!pte_none(*page_table))
68339 goto unlock;
68340 goto setpte;
68341 }
68342
68343 /* Allocate our own private page. */
68344+ pte_unmap(page_table);
68345+
68346 if (unlikely(anon_vma_prepare(vma)))
68347 goto oom;
68348 page = alloc_zeroed_user_highpage_movable(vma, address);
68349@@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_s
68350 if (!pte_none(*page_table))
68351 goto release;
68352
68353+#ifdef CONFIG_PAX_SEGMEXEC
68354+ if (pax_find_mirror_vma(vma))
68355+ BUG_ON(!trylock_page(page));
68356+#endif
68357+
68358 inc_mm_counter(mm, anon_rss);
68359 page_add_new_anon_rmap(page, vma, address);
68360 setpte:
68361@@ -2720,6 +2911,12 @@ setpte:
68362
68363 /* No need to invalidate - it was non-present before */
68364 update_mmu_cache(vma, address, entry);
68365+
68366+#ifdef CONFIG_PAX_SEGMEXEC
68367+ if (page)
68368+ pax_mirror_anon_pte(vma, address, page, ptl);
68369+#endif
68370+
68371 unlock:
68372 pte_unmap_unlock(page_table, ptl);
68373 return 0;
68374@@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *
68375 */
68376 /* Only go through if we didn't race with anybody else... */
68377 if (likely(pte_same(*page_table, orig_pte))) {
68378+
68379+#ifdef CONFIG_PAX_SEGMEXEC
68380+ if (anon && pax_find_mirror_vma(vma))
68381+ BUG_ON(!trylock_page(page));
68382+#endif
68383+
68384 flush_icache_page(vma, page);
68385 entry = mk_pte(page, vma->vm_page_prot);
68386 if (flags & FAULT_FLAG_WRITE)
68387@@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *
68388
68389 /* no need to invalidate: a not-present page won't be cached */
68390 update_mmu_cache(vma, address, entry);
68391+
68392+#ifdef CONFIG_PAX_SEGMEXEC
68393+ if (anon)
68394+ pax_mirror_anon_pte(vma, address, page, ptl);
68395+ else
68396+ pax_mirror_file_pte(vma, address, page, ptl);
68397+#endif
68398+
68399 } else {
68400 if (charged)
68401 mem_cgroup_uncharge_page(page);
68402@@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struc
68403 if (flags & FAULT_FLAG_WRITE)
68404 flush_tlb_page(vma, address);
68405 }
68406+
68407+#ifdef CONFIG_PAX_SEGMEXEC
68408+ pax_mirror_pte(vma, address, pte, pmd, ptl);
68409+ return 0;
68410+#endif
68411+
68412 unlock:
68413 pte_unmap_unlock(pte, ptl);
68414 return 0;
68415@@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm
68416 pmd_t *pmd;
68417 pte_t *pte;
68418
68419+#ifdef CONFIG_PAX_SEGMEXEC
68420+ struct vm_area_struct *vma_m;
68421+#endif
68422+
68423 __set_current_state(TASK_RUNNING);
68424
68425 count_vm_event(PGFAULT);
68426@@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm
68427 if (unlikely(is_vm_hugetlb_page(vma)))
68428 return hugetlb_fault(mm, vma, address, flags);
68429
68430+#ifdef CONFIG_PAX_SEGMEXEC
68431+ vma_m = pax_find_mirror_vma(vma);
68432+ if (vma_m) {
68433+ unsigned long address_m;
68434+ pgd_t *pgd_m;
68435+ pud_t *pud_m;
68436+ pmd_t *pmd_m;
68437+
68438+ if (vma->vm_start > vma_m->vm_start) {
68439+ address_m = address;
68440+ address -= SEGMEXEC_TASK_SIZE;
68441+ vma = vma_m;
68442+ } else
68443+ address_m = address + SEGMEXEC_TASK_SIZE;
68444+
68445+ pgd_m = pgd_offset(mm, address_m);
68446+ pud_m = pud_alloc(mm, pgd_m, address_m);
68447+ if (!pud_m)
68448+ return VM_FAULT_OOM;
68449+ pmd_m = pmd_alloc(mm, pud_m, address_m);
68450+ if (!pmd_m)
68451+ return VM_FAULT_OOM;
68452+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
68453+ return VM_FAULT_OOM;
68454+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
68455+ }
68456+#endif
68457+
68458 pgd = pgd_offset(mm, address);
68459 pud = pud_alloc(mm, pgd, address);
68460 if (!pud)
68461@@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
68462 gate_vma.vm_start = FIXADDR_USER_START;
68463 gate_vma.vm_end = FIXADDR_USER_END;
68464 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
68465- gate_vma.vm_page_prot = __P101;
68466+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
68467 /*
68468 * Make sure the vDSO gets into every core dump.
68469 * Dumping its contents makes post-mortem fully interpretable later
68470diff -urNp linux-2.6.32.44/mm/memory-failure.c linux-2.6.32.44/mm/memory-failure.c
68471--- linux-2.6.32.44/mm/memory-failure.c 2011-03-27 14:31:47.000000000 -0400
68472+++ linux-2.6.32.44/mm/memory-failure.c 2011-04-17 15:56:46.000000000 -0400
68473@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __r
68474
68475 int sysctl_memory_failure_recovery __read_mostly = 1;
68476
68477-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
68478+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
68479
68480 /*
68481 * Send all the processes who have the page mapped an ``action optional''
68482@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn,
68483 return 0;
68484 }
68485
68486- atomic_long_add(1, &mce_bad_pages);
68487+ atomic_long_add_unchecked(1, &mce_bad_pages);
68488
68489 /*
68490 * We need/can do nothing about count=0 pages.
68491diff -urNp linux-2.6.32.44/mm/mempolicy.c linux-2.6.32.44/mm/mempolicy.c
68492--- linux-2.6.32.44/mm/mempolicy.c 2011-03-27 14:31:47.000000000 -0400
68493+++ linux-2.6.32.44/mm/mempolicy.c 2011-04-17 15:56:46.000000000 -0400
68494@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_st
68495 struct vm_area_struct *next;
68496 int err;
68497
68498+#ifdef CONFIG_PAX_SEGMEXEC
68499+ struct vm_area_struct *vma_m;
68500+#endif
68501+
68502 err = 0;
68503 for (; vma && vma->vm_start < end; vma = next) {
68504 next = vma->vm_next;
68505@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_st
68506 err = policy_vma(vma, new);
68507 if (err)
68508 break;
68509+
68510+#ifdef CONFIG_PAX_SEGMEXEC
68511+ vma_m = pax_find_mirror_vma(vma);
68512+ if (vma_m) {
68513+ err = policy_vma(vma_m, new);
68514+ if (err)
68515+ break;
68516+ }
68517+#endif
68518+
68519 }
68520 return err;
68521 }
68522@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start
68523
68524 if (end < start)
68525 return -EINVAL;
68526+
68527+#ifdef CONFIG_PAX_SEGMEXEC
68528+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
68529+ if (end > SEGMEXEC_TASK_SIZE)
68530+ return -EINVAL;
68531+ } else
68532+#endif
68533+
68534+ if (end > TASK_SIZE)
68535+ return -EINVAL;
68536+
68537 if (end == start)
68538 return 0;
68539
68540@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
68541 if (!mm)
68542 return -EINVAL;
68543
68544+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68545+ if (mm != current->mm &&
68546+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68547+ err = -EPERM;
68548+ goto out;
68549+ }
68550+#endif
68551+
68552 /*
68553 * Check if this process has the right to modify the specified
68554 * process. The right exists if the process has administrative
68555@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
68556 rcu_read_lock();
68557 tcred = __task_cred(task);
68558 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68559- cred->uid != tcred->suid && cred->uid != tcred->uid &&
68560- !capable(CAP_SYS_NICE)) {
68561+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68562 rcu_read_unlock();
68563 err = -EPERM;
68564 goto out;
68565@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, vo
68566
68567 if (file) {
68568 seq_printf(m, " file=");
68569- seq_path(m, &file->f_path, "\n\t= ");
68570+ seq_path(m, &file->f_path, "\n\t\\= ");
68571 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
68572 seq_printf(m, " heap");
68573 } else if (vma->vm_start <= mm->start_stack &&
68574diff -urNp linux-2.6.32.44/mm/migrate.c linux-2.6.32.44/mm/migrate.c
68575--- linux-2.6.32.44/mm/migrate.c 2011-07-13 17:23:04.000000000 -0400
68576+++ linux-2.6.32.44/mm/migrate.c 2011-07-13 17:23:23.000000000 -0400
68577@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struc
68578 unsigned long chunk_start;
68579 int err;
68580
68581+ pax_track_stack();
68582+
68583 task_nodes = cpuset_mems_allowed(task);
68584
68585 err = -ENOMEM;
68586@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
68587 if (!mm)
68588 return -EINVAL;
68589
68590+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68591+ if (mm != current->mm &&
68592+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68593+ err = -EPERM;
68594+ goto out;
68595+ }
68596+#endif
68597+
68598 /*
68599 * Check if this process has the right to modify the specified
68600 * process. The right exists if the process has administrative
68601@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
68602 rcu_read_lock();
68603 tcred = __task_cred(task);
68604 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68605- cred->uid != tcred->suid && cred->uid != tcred->uid &&
68606- !capable(CAP_SYS_NICE)) {
68607+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68608 rcu_read_unlock();
68609 err = -EPERM;
68610 goto out;
68611diff -urNp linux-2.6.32.44/mm/mlock.c linux-2.6.32.44/mm/mlock.c
68612--- linux-2.6.32.44/mm/mlock.c 2011-03-27 14:31:47.000000000 -0400
68613+++ linux-2.6.32.44/mm/mlock.c 2011-04-17 15:56:46.000000000 -0400
68614@@ -13,6 +13,7 @@
68615 #include <linux/pagemap.h>
68616 #include <linux/mempolicy.h>
68617 #include <linux/syscalls.h>
68618+#include <linux/security.h>
68619 #include <linux/sched.h>
68620 #include <linux/module.h>
68621 #include <linux/rmap.h>
68622@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
68623 }
68624 }
68625
68626-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
68627-{
68628- return (vma->vm_flags & VM_GROWSDOWN) &&
68629- (vma->vm_start == addr) &&
68630- !vma_stack_continue(vma->vm_prev, addr);
68631-}
68632-
68633 /**
68634 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
68635 * @vma: target vma
68636@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(stru
68637 if (vma->vm_flags & VM_WRITE)
68638 gup_flags |= FOLL_WRITE;
68639
68640- /* We don't try to access the guard page of a stack vma */
68641- if (stack_guard_page(vma, start)) {
68642- addr += PAGE_SIZE;
68643- nr_pages--;
68644- }
68645-
68646 while (nr_pages > 0) {
68647 int i;
68648
68649@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start,
68650 {
68651 unsigned long nstart, end, tmp;
68652 struct vm_area_struct * vma, * prev;
68653- int error;
68654+ int error = -EINVAL;
68655
68656 len = PAGE_ALIGN(len);
68657 end = start + len;
68658@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start,
68659 return -EINVAL;
68660 if (end == start)
68661 return 0;
68662+ if (end > TASK_SIZE)
68663+ return -EINVAL;
68664+
68665 vma = find_vma_prev(current->mm, start, &prev);
68666 if (!vma || vma->vm_start > start)
68667 return -ENOMEM;
68668@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start,
68669 for (nstart = start ; ; ) {
68670 unsigned int newflags;
68671
68672+#ifdef CONFIG_PAX_SEGMEXEC
68673+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68674+ break;
68675+#endif
68676+
68677 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
68678
68679 newflags = vma->vm_flags | VM_LOCKED;
68680@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
68681 lock_limit >>= PAGE_SHIFT;
68682
68683 /* check against resource limits */
68684+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
68685 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
68686 error = do_mlock(start, len, 1);
68687 up_write(&current->mm->mmap_sem);
68688@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
68689 static int do_mlockall(int flags)
68690 {
68691 struct vm_area_struct * vma, * prev = NULL;
68692- unsigned int def_flags = 0;
68693
68694 if (flags & MCL_FUTURE)
68695- def_flags = VM_LOCKED;
68696- current->mm->def_flags = def_flags;
68697+ current->mm->def_flags |= VM_LOCKED;
68698+ else
68699+ current->mm->def_flags &= ~VM_LOCKED;
68700 if (flags == MCL_FUTURE)
68701 goto out;
68702
68703 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
68704- unsigned int newflags;
68705+ unsigned long newflags;
68706+
68707+#ifdef CONFIG_PAX_SEGMEXEC
68708+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68709+ break;
68710+#endif
68711
68712+ BUG_ON(vma->vm_end > TASK_SIZE);
68713 newflags = vma->vm_flags | VM_LOCKED;
68714 if (!(flags & MCL_CURRENT))
68715 newflags &= ~VM_LOCKED;
68716@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
68717 lock_limit >>= PAGE_SHIFT;
68718
68719 ret = -ENOMEM;
68720+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
68721 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
68722 capable(CAP_IPC_LOCK))
68723 ret = do_mlockall(flags);
68724diff -urNp linux-2.6.32.44/mm/mmap.c linux-2.6.32.44/mm/mmap.c
68725--- linux-2.6.32.44/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
68726+++ linux-2.6.32.44/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
68727@@ -45,6 +45,16 @@
68728 #define arch_rebalance_pgtables(addr, len) (addr)
68729 #endif
68730
68731+static inline void verify_mm_writelocked(struct mm_struct *mm)
68732+{
68733+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
68734+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
68735+ up_read(&mm->mmap_sem);
68736+ BUG();
68737+ }
68738+#endif
68739+}
68740+
68741 static void unmap_region(struct mm_struct *mm,
68742 struct vm_area_struct *vma, struct vm_area_struct *prev,
68743 unsigned long start, unsigned long end);
68744@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struc
68745 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
68746 *
68747 */
68748-pgprot_t protection_map[16] = {
68749+pgprot_t protection_map[16] __read_only = {
68750 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
68751 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
68752 };
68753
68754 pgprot_t vm_get_page_prot(unsigned long vm_flags)
68755 {
68756- return __pgprot(pgprot_val(protection_map[vm_flags &
68757+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
68758 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
68759 pgprot_val(arch_vm_get_page_prot(vm_flags)));
68760+
68761+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68762+ if (!nx_enabled &&
68763+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
68764+ (vm_flags & (VM_READ | VM_WRITE)))
68765+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
68766+#endif
68767+
68768+ return prot;
68769 }
68770 EXPORT_SYMBOL(vm_get_page_prot);
68771
68772 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
68773 int sysctl_overcommit_ratio = 50; /* default is 50% */
68774 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
68775+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
68776 struct percpu_counter vm_committed_as;
68777
68778 /*
68779@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma
68780 struct vm_area_struct *next = vma->vm_next;
68781
68782 might_sleep();
68783+ BUG_ON(vma->vm_mirror);
68784 if (vma->vm_ops && vma->vm_ops->close)
68785 vma->vm_ops->close(vma);
68786 if (vma->vm_file) {
68787@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
68788 * not page aligned -Ram Gupta
68789 */
68790 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
68791+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
68792 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
68793 (mm->end_data - mm->start_data) > rlim)
68794 goto out;
68795@@ -704,6 +726,12 @@ static int
68796 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
68797 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68798 {
68799+
68800+#ifdef CONFIG_PAX_SEGMEXEC
68801+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
68802+ return 0;
68803+#endif
68804+
68805 if (is_mergeable_vma(vma, file, vm_flags) &&
68806 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
68807 if (vma->vm_pgoff == vm_pgoff)
68808@@ -723,6 +751,12 @@ static int
68809 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68810 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68811 {
68812+
68813+#ifdef CONFIG_PAX_SEGMEXEC
68814+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
68815+ return 0;
68816+#endif
68817+
68818 if (is_mergeable_vma(vma, file, vm_flags) &&
68819 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
68820 pgoff_t vm_pglen;
68821@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struc
68822 struct vm_area_struct *vma_merge(struct mm_struct *mm,
68823 struct vm_area_struct *prev, unsigned long addr,
68824 unsigned long end, unsigned long vm_flags,
68825- struct anon_vma *anon_vma, struct file *file,
68826+ struct anon_vma *anon_vma, struct file *file,
68827 pgoff_t pgoff, struct mempolicy *policy)
68828 {
68829 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
68830 struct vm_area_struct *area, *next;
68831
68832+#ifdef CONFIG_PAX_SEGMEXEC
68833+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
68834+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
68835+
68836+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
68837+#endif
68838+
68839 /*
68840 * We later require that vma->vm_flags == vm_flags,
68841 * so this tests vma->vm_flags & VM_SPECIAL, too.
68842@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct
68843 if (next && next->vm_end == end) /* cases 6, 7, 8 */
68844 next = next->vm_next;
68845
68846+#ifdef CONFIG_PAX_SEGMEXEC
68847+ if (prev)
68848+ prev_m = pax_find_mirror_vma(prev);
68849+ if (area)
68850+ area_m = pax_find_mirror_vma(area);
68851+ if (next)
68852+ next_m = pax_find_mirror_vma(next);
68853+#endif
68854+
68855 /*
68856 * Can it merge with the predecessor?
68857 */
68858@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct
68859 /* cases 1, 6 */
68860 vma_adjust(prev, prev->vm_start,
68861 next->vm_end, prev->vm_pgoff, NULL);
68862- } else /* cases 2, 5, 7 */
68863+
68864+#ifdef CONFIG_PAX_SEGMEXEC
68865+ if (prev_m)
68866+ vma_adjust(prev_m, prev_m->vm_start,
68867+ next_m->vm_end, prev_m->vm_pgoff, NULL);
68868+#endif
68869+
68870+ } else { /* cases 2, 5, 7 */
68871 vma_adjust(prev, prev->vm_start,
68872 end, prev->vm_pgoff, NULL);
68873+
68874+#ifdef CONFIG_PAX_SEGMEXEC
68875+ if (prev_m)
68876+ vma_adjust(prev_m, prev_m->vm_start,
68877+ end_m, prev_m->vm_pgoff, NULL);
68878+#endif
68879+
68880+ }
68881 return prev;
68882 }
68883
68884@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct
68885 mpol_equal(policy, vma_policy(next)) &&
68886 can_vma_merge_before(next, vm_flags,
68887 anon_vma, file, pgoff+pglen)) {
68888- if (prev && addr < prev->vm_end) /* case 4 */
68889+ if (prev && addr < prev->vm_end) { /* case 4 */
68890 vma_adjust(prev, prev->vm_start,
68891 addr, prev->vm_pgoff, NULL);
68892- else /* cases 3, 8 */
68893+
68894+#ifdef CONFIG_PAX_SEGMEXEC
68895+ if (prev_m)
68896+ vma_adjust(prev_m, prev_m->vm_start,
68897+ addr_m, prev_m->vm_pgoff, NULL);
68898+#endif
68899+
68900+ } else { /* cases 3, 8 */
68901 vma_adjust(area, addr, next->vm_end,
68902 next->vm_pgoff - pglen, NULL);
68903+
68904+#ifdef CONFIG_PAX_SEGMEXEC
68905+ if (area_m)
68906+ vma_adjust(area_m, addr_m, next_m->vm_end,
68907+ next_m->vm_pgoff - pglen, NULL);
68908+#endif
68909+
68910+ }
68911 return area;
68912 }
68913
68914@@ -898,14 +978,11 @@ none:
68915 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
68916 struct file *file, long pages)
68917 {
68918- const unsigned long stack_flags
68919- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
68920-
68921 if (file) {
68922 mm->shared_vm += pages;
68923 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
68924 mm->exec_vm += pages;
68925- } else if (flags & stack_flags)
68926+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
68927 mm->stack_vm += pages;
68928 if (flags & (VM_RESERVED|VM_IO))
68929 mm->reserved_vm += pages;
68930@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file
68931 * (the exception is when the underlying filesystem is noexec
68932 * mounted, in which case we dont add PROT_EXEC.)
68933 */
68934- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
68935+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
68936 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
68937 prot |= PROT_EXEC;
68938
68939@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file
68940 /* Obtain the address to map to. we verify (or select) it and ensure
68941 * that it represents a valid section of the address space.
68942 */
68943- addr = get_unmapped_area(file, addr, len, pgoff, flags);
68944+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
68945 if (addr & ~PAGE_MASK)
68946 return addr;
68947
68948@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file
68949 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
68950 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
68951
68952+#ifdef CONFIG_PAX_MPROTECT
68953+ if (mm->pax_flags & MF_PAX_MPROTECT) {
68954+#ifndef CONFIG_PAX_MPROTECT_COMPAT
68955+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
68956+ gr_log_rwxmmap(file);
68957+
68958+#ifdef CONFIG_PAX_EMUPLT
68959+ vm_flags &= ~VM_EXEC;
68960+#else
68961+ return -EPERM;
68962+#endif
68963+
68964+ }
68965+
68966+ if (!(vm_flags & VM_EXEC))
68967+ vm_flags &= ~VM_MAYEXEC;
68968+#else
68969+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
68970+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
68971+#endif
68972+ else
68973+ vm_flags &= ~VM_MAYWRITE;
68974+ }
68975+#endif
68976+
68977+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68978+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
68979+ vm_flags &= ~VM_PAGEEXEC;
68980+#endif
68981+
68982 if (flags & MAP_LOCKED)
68983 if (!can_do_mlock())
68984 return -EPERM;
68985@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file
68986 locked += mm->locked_vm;
68987 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
68988 lock_limit >>= PAGE_SHIFT;
68989+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
68990 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
68991 return -EAGAIN;
68992 }
68993@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file
68994 if (error)
68995 return error;
68996
68997+ if (!gr_acl_handle_mmap(file, prot))
68998+ return -EACCES;
68999+
69000 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
69001 }
69002 EXPORT_SYMBOL(do_mmap_pgoff);
69003@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
69004 */
69005 int vma_wants_writenotify(struct vm_area_struct *vma)
69006 {
69007- unsigned int vm_flags = vma->vm_flags;
69008+ unsigned long vm_flags = vma->vm_flags;
69009
69010 /* If it was private or non-writable, the write bit is already clear */
69011- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
69012+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
69013 return 0;
69014
69015 /* The backer wishes to know when pages are first written to? */
69016@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *f
69017 unsigned long charged = 0;
69018 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
69019
69020+#ifdef CONFIG_PAX_SEGMEXEC
69021+ struct vm_area_struct *vma_m = NULL;
69022+#endif
69023+
69024+ /*
69025+ * mm->mmap_sem is required to protect against another thread
69026+ * changing the mappings in case we sleep.
69027+ */
69028+ verify_mm_writelocked(mm);
69029+
69030 /* Clear old maps */
69031 error = -ENOMEM;
69032-munmap_back:
69033 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69034 if (vma && vma->vm_start < addr + len) {
69035 if (do_munmap(mm, addr, len))
69036 return -ENOMEM;
69037- goto munmap_back;
69038+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69039+ BUG_ON(vma && vma->vm_start < addr + len);
69040 }
69041
69042 /* Check against address space limit. */
69043@@ -1173,6 +1294,16 @@ munmap_back:
69044 goto unacct_error;
69045 }
69046
69047+#ifdef CONFIG_PAX_SEGMEXEC
69048+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
69049+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69050+ if (!vma_m) {
69051+ error = -ENOMEM;
69052+ goto free_vma;
69053+ }
69054+ }
69055+#endif
69056+
69057 vma->vm_mm = mm;
69058 vma->vm_start = addr;
69059 vma->vm_end = addr + len;
69060@@ -1195,6 +1326,19 @@ munmap_back:
69061 error = file->f_op->mmap(file, vma);
69062 if (error)
69063 goto unmap_and_free_vma;
69064+
69065+#ifdef CONFIG_PAX_SEGMEXEC
69066+ if (vma_m && (vm_flags & VM_EXECUTABLE))
69067+ added_exe_file_vma(mm);
69068+#endif
69069+
69070+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69071+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
69072+ vma->vm_flags |= VM_PAGEEXEC;
69073+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69074+ }
69075+#endif
69076+
69077 if (vm_flags & VM_EXECUTABLE)
69078 added_exe_file_vma(mm);
69079
69080@@ -1218,6 +1362,11 @@ munmap_back:
69081 vma_link(mm, vma, prev, rb_link, rb_parent);
69082 file = vma->vm_file;
69083
69084+#ifdef CONFIG_PAX_SEGMEXEC
69085+ if (vma_m)
69086+ pax_mirror_vma(vma_m, vma);
69087+#endif
69088+
69089 /* Once vma denies write, undo our temporary denial count */
69090 if (correct_wcount)
69091 atomic_inc(&inode->i_writecount);
69092@@ -1226,6 +1375,7 @@ out:
69093
69094 mm->total_vm += len >> PAGE_SHIFT;
69095 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
69096+ track_exec_limit(mm, addr, addr + len, vm_flags);
69097 if (vm_flags & VM_LOCKED) {
69098 /*
69099 * makes pages present; downgrades, drops, reacquires mmap_sem
69100@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
69101 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
69102 charged = 0;
69103 free_vma:
69104+
69105+#ifdef CONFIG_PAX_SEGMEXEC
69106+ if (vma_m)
69107+ kmem_cache_free(vm_area_cachep, vma_m);
69108+#endif
69109+
69110 kmem_cache_free(vm_area_cachep, vma);
69111 unacct_error:
69112 if (charged)
69113@@ -1255,6 +1411,44 @@ unacct_error:
69114 return error;
69115 }
69116
69117+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
69118+{
69119+ if (!vma) {
69120+#ifdef CONFIG_STACK_GROWSUP
69121+ if (addr > sysctl_heap_stack_gap)
69122+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
69123+ else
69124+ vma = find_vma(current->mm, 0);
69125+ if (vma && (vma->vm_flags & VM_GROWSUP))
69126+ return false;
69127+#endif
69128+ return true;
69129+ }
69130+
69131+ if (addr + len > vma->vm_start)
69132+ return false;
69133+
69134+ if (vma->vm_flags & VM_GROWSDOWN)
69135+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
69136+#ifdef CONFIG_STACK_GROWSUP
69137+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
69138+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
69139+#endif
69140+
69141+ return true;
69142+}
69143+
69144+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
69145+{
69146+ if (vma->vm_start < len)
69147+ return -ENOMEM;
69148+ if (!(vma->vm_flags & VM_GROWSDOWN))
69149+ return vma->vm_start - len;
69150+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
69151+ return vma->vm_start - len - sysctl_heap_stack_gap;
69152+ return -ENOMEM;
69153+}
69154+
69155 /* Get an address range which is currently unmapped.
69156 * For shmat() with addr=0.
69157 *
69158@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp
69159 if (flags & MAP_FIXED)
69160 return addr;
69161
69162+#ifdef CONFIG_PAX_RANDMMAP
69163+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69164+#endif
69165+
69166 if (addr) {
69167 addr = PAGE_ALIGN(addr);
69168- vma = find_vma(mm, addr);
69169- if (TASK_SIZE - len >= addr &&
69170- (!vma || addr + len <= vma->vm_start))
69171- return addr;
69172+ if (TASK_SIZE - len >= addr) {
69173+ vma = find_vma(mm, addr);
69174+ if (check_heap_stack_gap(vma, addr, len))
69175+ return addr;
69176+ }
69177 }
69178 if (len > mm->cached_hole_size) {
69179- start_addr = addr = mm->free_area_cache;
69180+ start_addr = addr = mm->free_area_cache;
69181 } else {
69182- start_addr = addr = TASK_UNMAPPED_BASE;
69183- mm->cached_hole_size = 0;
69184+ start_addr = addr = mm->mmap_base;
69185+ mm->cached_hole_size = 0;
69186 }
69187
69188 full_search:
69189@@ -1303,34 +1502,40 @@ full_search:
69190 * Start a new search - just in case we missed
69191 * some holes.
69192 */
69193- if (start_addr != TASK_UNMAPPED_BASE) {
69194- addr = TASK_UNMAPPED_BASE;
69195- start_addr = addr;
69196+ if (start_addr != mm->mmap_base) {
69197+ start_addr = addr = mm->mmap_base;
69198 mm->cached_hole_size = 0;
69199 goto full_search;
69200 }
69201 return -ENOMEM;
69202 }
69203- if (!vma || addr + len <= vma->vm_start) {
69204- /*
69205- * Remember the place where we stopped the search:
69206- */
69207- mm->free_area_cache = addr + len;
69208- return addr;
69209- }
69210+ if (check_heap_stack_gap(vma, addr, len))
69211+ break;
69212 if (addr + mm->cached_hole_size < vma->vm_start)
69213 mm->cached_hole_size = vma->vm_start - addr;
69214 addr = vma->vm_end;
69215 }
69216+
69217+ /*
69218+ * Remember the place where we stopped the search:
69219+ */
69220+ mm->free_area_cache = addr + len;
69221+ return addr;
69222 }
69223 #endif
69224
69225 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
69226 {
69227+
69228+#ifdef CONFIG_PAX_SEGMEXEC
69229+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69230+ return;
69231+#endif
69232+
69233 /*
69234 * Is this a new hole at the lowest possible address?
69235 */
69236- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
69237+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
69238 mm->free_area_cache = addr;
69239 mm->cached_hole_size = ~0UL;
69240 }
69241@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct fi
69242 {
69243 struct vm_area_struct *vma;
69244 struct mm_struct *mm = current->mm;
69245- unsigned long addr = addr0;
69246+ unsigned long base = mm->mmap_base, addr = addr0;
69247
69248 /* requested length too big for entire address space */
69249 if (len > TASK_SIZE)
69250@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct fi
69251 if (flags & MAP_FIXED)
69252 return addr;
69253
69254+#ifdef CONFIG_PAX_RANDMMAP
69255+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69256+#endif
69257+
69258 /* requesting a specific address */
69259 if (addr) {
69260 addr = PAGE_ALIGN(addr);
69261- vma = find_vma(mm, addr);
69262- if (TASK_SIZE - len >= addr &&
69263- (!vma || addr + len <= vma->vm_start))
69264- return addr;
69265+ if (TASK_SIZE - len >= addr) {
69266+ vma = find_vma(mm, addr);
69267+ if (check_heap_stack_gap(vma, addr, len))
69268+ return addr;
69269+ }
69270 }
69271
69272 /* check if free_area_cache is useful for us */
69273@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct fi
69274 /* make sure it can fit in the remaining address space */
69275 if (addr > len) {
69276 vma = find_vma(mm, addr-len);
69277- if (!vma || addr <= vma->vm_start)
69278+ if (check_heap_stack_gap(vma, addr - len, len))
69279 /* remember the address as a hint for next time */
69280 return (mm->free_area_cache = addr-len);
69281 }
69282@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct fi
69283 * return with success:
69284 */
69285 vma = find_vma(mm, addr);
69286- if (!vma || addr+len <= vma->vm_start)
69287+ if (check_heap_stack_gap(vma, addr, len))
69288 /* remember the address as a hint for next time */
69289 return (mm->free_area_cache = addr);
69290
69291@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct fi
69292 mm->cached_hole_size = vma->vm_start - addr;
69293
69294 /* try just below the current vma->vm_start */
69295- addr = vma->vm_start-len;
69296- } while (len < vma->vm_start);
69297+ addr = skip_heap_stack_gap(vma, len);
69298+ } while (!IS_ERR_VALUE(addr));
69299
69300 bottomup:
69301 /*
69302@@ -1414,13 +1624,21 @@ bottomup:
69303 * can happen with large stack limits and large mmap()
69304 * allocations.
69305 */
69306+ mm->mmap_base = TASK_UNMAPPED_BASE;
69307+
69308+#ifdef CONFIG_PAX_RANDMMAP
69309+ if (mm->pax_flags & MF_PAX_RANDMMAP)
69310+ mm->mmap_base += mm->delta_mmap;
69311+#endif
69312+
69313+ mm->free_area_cache = mm->mmap_base;
69314 mm->cached_hole_size = ~0UL;
69315- mm->free_area_cache = TASK_UNMAPPED_BASE;
69316 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
69317 /*
69318 * Restore the topdown base:
69319 */
69320- mm->free_area_cache = mm->mmap_base;
69321+ mm->mmap_base = base;
69322+ mm->free_area_cache = base;
69323 mm->cached_hole_size = ~0UL;
69324
69325 return addr;
69326@@ -1429,6 +1647,12 @@ bottomup:
69327
69328 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69329 {
69330+
69331+#ifdef CONFIG_PAX_SEGMEXEC
69332+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69333+ return;
69334+#endif
69335+
69336 /*
69337 * Is this a new hole at the highest possible address?
69338 */
69339@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_s
69340 mm->free_area_cache = addr;
69341
69342 /* dont allow allocations above current base */
69343- if (mm->free_area_cache > mm->mmap_base)
69344+ if (mm->free_area_cache > mm->mmap_base) {
69345 mm->free_area_cache = mm->mmap_base;
69346+ mm->cached_hole_size = ~0UL;
69347+ }
69348 }
69349
69350 unsigned long
69351@@ -1545,6 +1771,27 @@ out:
69352 return prev ? prev->vm_next : vma;
69353 }
69354
69355+#ifdef CONFIG_PAX_SEGMEXEC
69356+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
69357+{
69358+ struct vm_area_struct *vma_m;
69359+
69360+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
69361+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
69362+ BUG_ON(vma->vm_mirror);
69363+ return NULL;
69364+ }
69365+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
69366+ vma_m = vma->vm_mirror;
69367+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
69368+ BUG_ON(vma->vm_file != vma_m->vm_file);
69369+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
69370+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
69371+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
69372+ return vma_m;
69373+}
69374+#endif
69375+
69376 /*
69377 * Verify that the stack growth is acceptable and
69378 * update accounting. This is shared with both the
69379@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_a
69380 return -ENOMEM;
69381
69382 /* Stack limit test */
69383+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
69384 if (size > rlim[RLIMIT_STACK].rlim_cur)
69385 return -ENOMEM;
69386
69387@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_a
69388 unsigned long limit;
69389 locked = mm->locked_vm + grow;
69390 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
69391+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69392 if (locked > limit && !capable(CAP_IPC_LOCK))
69393 return -ENOMEM;
69394 }
69395@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_a
69396 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
69397 * vma is the last one with address > vma->vm_end. Have to extend vma.
69398 */
69399+#ifndef CONFIG_IA64
69400+static
69401+#endif
69402 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69403 {
69404 int error;
69405+ bool locknext;
69406
69407 if (!(vma->vm_flags & VM_GROWSUP))
69408 return -EFAULT;
69409
69410+ /* Also guard against wrapping around to address 0. */
69411+ if (address < PAGE_ALIGN(address+1))
69412+ address = PAGE_ALIGN(address+1);
69413+ else
69414+ return -ENOMEM;
69415+
69416 /*
69417 * We must make sure the anon_vma is allocated
69418 * so that the anon_vma locking is not a noop.
69419 */
69420 if (unlikely(anon_vma_prepare(vma)))
69421 return -ENOMEM;
69422+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
69423+ if (locknext && anon_vma_prepare(vma->vm_next))
69424+ return -ENOMEM;
69425 anon_vma_lock(vma);
69426+ if (locknext)
69427+ anon_vma_lock(vma->vm_next);
69428
69429 /*
69430 * vma->vm_start/vm_end cannot change under us because the caller
69431 * is required to hold the mmap_sem in read mode. We need the
69432- * anon_vma lock to serialize against concurrent expand_stacks.
69433- * Also guard against wrapping around to address 0.
69434+ * anon_vma locks to serialize against concurrent expand_stacks
69435+ * and expand_upwards.
69436 */
69437- if (address < PAGE_ALIGN(address+4))
69438- address = PAGE_ALIGN(address+4);
69439- else {
69440- anon_vma_unlock(vma);
69441- return -ENOMEM;
69442- }
69443 error = 0;
69444
69445 /* Somebody else might have raced and expanded it already */
69446- if (address > vma->vm_end) {
69447+ 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)
69448+ error = -ENOMEM;
69449+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
69450 unsigned long size, grow;
69451
69452 size = address - vma->vm_start;
69453@@ -1640,6 +1900,8 @@ int expand_upwards(struct vm_area_struct
69454 if (!error)
69455 vma->vm_end = address;
69456 }
69457+ if (locknext)
69458+ anon_vma_unlock(vma->vm_next);
69459 anon_vma_unlock(vma);
69460 return error;
69461 }
69462@@ -1652,6 +1914,8 @@ static int expand_downwards(struct vm_ar
69463 unsigned long address)
69464 {
69465 int error;
69466+ bool lockprev = false;
69467+ struct vm_area_struct *prev;
69468
69469 /*
69470 * We must make sure the anon_vma is allocated
69471@@ -1665,6 +1929,15 @@ static int expand_downwards(struct vm_ar
69472 if (error)
69473 return error;
69474
69475+ prev = vma->vm_prev;
69476+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
69477+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
69478+#endif
69479+ if (lockprev && anon_vma_prepare(prev))
69480+ return -ENOMEM;
69481+ if (lockprev)
69482+ anon_vma_lock(prev);
69483+
69484 anon_vma_lock(vma);
69485
69486 /*
69487@@ -1674,9 +1947,17 @@ static int expand_downwards(struct vm_ar
69488 */
69489
69490 /* Somebody else might have raced and expanded it already */
69491- if (address < vma->vm_start) {
69492+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
69493+ error = -ENOMEM;
69494+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
69495 unsigned long size, grow;
69496
69497+#ifdef CONFIG_PAX_SEGMEXEC
69498+ struct vm_area_struct *vma_m;
69499+
69500+ vma_m = pax_find_mirror_vma(vma);
69501+#endif
69502+
69503 size = vma->vm_end - address;
69504 grow = (vma->vm_start - address) >> PAGE_SHIFT;
69505
69506@@ -1684,9 +1965,20 @@ static int expand_downwards(struct vm_ar
69507 if (!error) {
69508 vma->vm_start = address;
69509 vma->vm_pgoff -= grow;
69510+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
69511+
69512+#ifdef CONFIG_PAX_SEGMEXEC
69513+ if (vma_m) {
69514+ vma_m->vm_start -= grow << PAGE_SHIFT;
69515+ vma_m->vm_pgoff -= grow;
69516+ }
69517+#endif
69518+
69519 }
69520 }
69521 anon_vma_unlock(vma);
69522+ if (lockprev)
69523+ anon_vma_unlock(prev);
69524 return error;
69525 }
69526
69527@@ -1762,6 +2054,13 @@ static void remove_vma_list(struct mm_st
69528 do {
69529 long nrpages = vma_pages(vma);
69530
69531+#ifdef CONFIG_PAX_SEGMEXEC
69532+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
69533+ vma = remove_vma(vma);
69534+ continue;
69535+ }
69536+#endif
69537+
69538 mm->total_vm -= nrpages;
69539 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
69540 vma = remove_vma(vma);
69541@@ -1807,6 +2106,16 @@ detach_vmas_to_be_unmapped(struct mm_str
69542 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
69543 vma->vm_prev = NULL;
69544 do {
69545+
69546+#ifdef CONFIG_PAX_SEGMEXEC
69547+ if (vma->vm_mirror) {
69548+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
69549+ vma->vm_mirror->vm_mirror = NULL;
69550+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
69551+ vma->vm_mirror = NULL;
69552+ }
69553+#endif
69554+
69555 rb_erase(&vma->vm_rb, &mm->mm_rb);
69556 mm->map_count--;
69557 tail_vma = vma;
69558@@ -1834,10 +2143,25 @@ int split_vma(struct mm_struct * mm, str
69559 struct mempolicy *pol;
69560 struct vm_area_struct *new;
69561
69562+#ifdef CONFIG_PAX_SEGMEXEC
69563+ struct vm_area_struct *vma_m, *new_m = NULL;
69564+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
69565+#endif
69566+
69567 if (is_vm_hugetlb_page(vma) && (addr &
69568 ~(huge_page_mask(hstate_vma(vma)))))
69569 return -EINVAL;
69570
69571+#ifdef CONFIG_PAX_SEGMEXEC
69572+ vma_m = pax_find_mirror_vma(vma);
69573+
69574+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
69575+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
69576+ if (mm->map_count >= sysctl_max_map_count-1)
69577+ return -ENOMEM;
69578+ } else
69579+#endif
69580+
69581 if (mm->map_count >= sysctl_max_map_count)
69582 return -ENOMEM;
69583
69584@@ -1845,6 +2169,16 @@ int split_vma(struct mm_struct * mm, str
69585 if (!new)
69586 return -ENOMEM;
69587
69588+#ifdef CONFIG_PAX_SEGMEXEC
69589+ if (vma_m) {
69590+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69591+ if (!new_m) {
69592+ kmem_cache_free(vm_area_cachep, new);
69593+ return -ENOMEM;
69594+ }
69595+ }
69596+#endif
69597+
69598 /* most fields are the same, copy all, and then fixup */
69599 *new = *vma;
69600
69601@@ -1855,8 +2189,29 @@ int split_vma(struct mm_struct * mm, str
69602 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
69603 }
69604
69605+#ifdef CONFIG_PAX_SEGMEXEC
69606+ if (vma_m) {
69607+ *new_m = *vma_m;
69608+ new_m->vm_mirror = new;
69609+ new->vm_mirror = new_m;
69610+
69611+ if (new_below)
69612+ new_m->vm_end = addr_m;
69613+ else {
69614+ new_m->vm_start = addr_m;
69615+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
69616+ }
69617+ }
69618+#endif
69619+
69620 pol = mpol_dup(vma_policy(vma));
69621 if (IS_ERR(pol)) {
69622+
69623+#ifdef CONFIG_PAX_SEGMEXEC
69624+ if (new_m)
69625+ kmem_cache_free(vm_area_cachep, new_m);
69626+#endif
69627+
69628 kmem_cache_free(vm_area_cachep, new);
69629 return PTR_ERR(pol);
69630 }
69631@@ -1877,6 +2232,28 @@ int split_vma(struct mm_struct * mm, str
69632 else
69633 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
69634
69635+#ifdef CONFIG_PAX_SEGMEXEC
69636+ if (vma_m) {
69637+ mpol_get(pol);
69638+ vma_set_policy(new_m, pol);
69639+
69640+ if (new_m->vm_file) {
69641+ get_file(new_m->vm_file);
69642+ if (vma_m->vm_flags & VM_EXECUTABLE)
69643+ added_exe_file_vma(mm);
69644+ }
69645+
69646+ if (new_m->vm_ops && new_m->vm_ops->open)
69647+ new_m->vm_ops->open(new_m);
69648+
69649+ if (new_below)
69650+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
69651+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
69652+ else
69653+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
69654+ }
69655+#endif
69656+
69657 return 0;
69658 }
69659
69660@@ -1885,11 +2262,30 @@ int split_vma(struct mm_struct * mm, str
69661 * work. This now handles partial unmappings.
69662 * Jeremy Fitzhardinge <jeremy@goop.org>
69663 */
69664+#ifdef CONFIG_PAX_SEGMEXEC
69665+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69666+{
69667+ int ret = __do_munmap(mm, start, len);
69668+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
69669+ return ret;
69670+
69671+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
69672+}
69673+
69674+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69675+#else
69676 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69677+#endif
69678 {
69679 unsigned long end;
69680 struct vm_area_struct *vma, *prev, *last;
69681
69682+ /*
69683+ * mm->mmap_sem is required to protect against another thread
69684+ * changing the mappings in case we sleep.
69685+ */
69686+ verify_mm_writelocked(mm);
69687+
69688 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
69689 return -EINVAL;
69690
69691@@ -1953,6 +2349,8 @@ int do_munmap(struct mm_struct *mm, unsi
69692 /* Fix up all other VM information */
69693 remove_vma_list(mm, vma);
69694
69695+ track_exec_limit(mm, start, end, 0UL);
69696+
69697 return 0;
69698 }
69699
69700@@ -1965,22 +2363,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
69701
69702 profile_munmap(addr);
69703
69704+#ifdef CONFIG_PAX_SEGMEXEC
69705+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
69706+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
69707+ return -EINVAL;
69708+#endif
69709+
69710 down_write(&mm->mmap_sem);
69711 ret = do_munmap(mm, addr, len);
69712 up_write(&mm->mmap_sem);
69713 return ret;
69714 }
69715
69716-static inline void verify_mm_writelocked(struct mm_struct *mm)
69717-{
69718-#ifdef CONFIG_DEBUG_VM
69719- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
69720- WARN_ON(1);
69721- up_read(&mm->mmap_sem);
69722- }
69723-#endif
69724-}
69725-
69726 /*
69727 * this is really a simplified "do_mmap". it only handles
69728 * anonymous maps. eventually we may be able to do some
69729@@ -1994,6 +2388,7 @@ unsigned long do_brk(unsigned long addr,
69730 struct rb_node ** rb_link, * rb_parent;
69731 pgoff_t pgoff = addr >> PAGE_SHIFT;
69732 int error;
69733+ unsigned long charged;
69734
69735 len = PAGE_ALIGN(len);
69736 if (!len)
69737@@ -2005,16 +2400,30 @@ unsigned long do_brk(unsigned long addr,
69738
69739 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
69740
69741+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
69742+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
69743+ flags &= ~VM_EXEC;
69744+
69745+#ifdef CONFIG_PAX_MPROTECT
69746+ if (mm->pax_flags & MF_PAX_MPROTECT)
69747+ flags &= ~VM_MAYEXEC;
69748+#endif
69749+
69750+ }
69751+#endif
69752+
69753 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
69754 if (error & ~PAGE_MASK)
69755 return error;
69756
69757+ charged = len >> PAGE_SHIFT;
69758+
69759 /*
69760 * mlock MCL_FUTURE?
69761 */
69762 if (mm->def_flags & VM_LOCKED) {
69763 unsigned long locked, lock_limit;
69764- locked = len >> PAGE_SHIFT;
69765+ locked = charged;
69766 locked += mm->locked_vm;
69767 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
69768 lock_limit >>= PAGE_SHIFT;
69769@@ -2031,22 +2440,22 @@ unsigned long do_brk(unsigned long addr,
69770 /*
69771 * Clear old maps. this also does some error checking for us
69772 */
69773- munmap_back:
69774 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69775 if (vma && vma->vm_start < addr + len) {
69776 if (do_munmap(mm, addr, len))
69777 return -ENOMEM;
69778- goto munmap_back;
69779+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69780+ BUG_ON(vma && vma->vm_start < addr + len);
69781 }
69782
69783 /* Check against address space limits *after* clearing old maps... */
69784- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
69785+ if (!may_expand_vm(mm, charged))
69786 return -ENOMEM;
69787
69788 if (mm->map_count > sysctl_max_map_count)
69789 return -ENOMEM;
69790
69791- if (security_vm_enough_memory(len >> PAGE_SHIFT))
69792+ if (security_vm_enough_memory(charged))
69793 return -ENOMEM;
69794
69795 /* Can we just expand an old private anonymous mapping? */
69796@@ -2060,7 +2469,7 @@ unsigned long do_brk(unsigned long addr,
69797 */
69798 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69799 if (!vma) {
69800- vm_unacct_memory(len >> PAGE_SHIFT);
69801+ vm_unacct_memory(charged);
69802 return -ENOMEM;
69803 }
69804
69805@@ -2072,11 +2481,12 @@ unsigned long do_brk(unsigned long addr,
69806 vma->vm_page_prot = vm_get_page_prot(flags);
69807 vma_link(mm, vma, prev, rb_link, rb_parent);
69808 out:
69809- mm->total_vm += len >> PAGE_SHIFT;
69810+ mm->total_vm += charged;
69811 if (flags & VM_LOCKED) {
69812 if (!mlock_vma_pages_range(vma, addr, addr + len))
69813- mm->locked_vm += (len >> PAGE_SHIFT);
69814+ mm->locked_vm += charged;
69815 }
69816+ track_exec_limit(mm, addr, addr + len, flags);
69817 return addr;
69818 }
69819
69820@@ -2123,8 +2533,10 @@ void exit_mmap(struct mm_struct *mm)
69821 * Walk the list again, actually closing and freeing it,
69822 * with preemption enabled, without holding any MM locks.
69823 */
69824- while (vma)
69825+ while (vma) {
69826+ vma->vm_mirror = NULL;
69827 vma = remove_vma(vma);
69828+ }
69829
69830 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
69831 }
69832@@ -2138,6 +2550,10 @@ int insert_vm_struct(struct mm_struct *
69833 struct vm_area_struct * __vma, * prev;
69834 struct rb_node ** rb_link, * rb_parent;
69835
69836+#ifdef CONFIG_PAX_SEGMEXEC
69837+ struct vm_area_struct *vma_m = NULL;
69838+#endif
69839+
69840 /*
69841 * The vm_pgoff of a purely anonymous vma should be irrelevant
69842 * until its first write fault, when page's anon_vma and index
69843@@ -2160,7 +2576,22 @@ int insert_vm_struct(struct mm_struct *
69844 if ((vma->vm_flags & VM_ACCOUNT) &&
69845 security_vm_enough_memory_mm(mm, vma_pages(vma)))
69846 return -ENOMEM;
69847+
69848+#ifdef CONFIG_PAX_SEGMEXEC
69849+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
69850+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69851+ if (!vma_m)
69852+ return -ENOMEM;
69853+ }
69854+#endif
69855+
69856 vma_link(mm, vma, prev, rb_link, rb_parent);
69857+
69858+#ifdef CONFIG_PAX_SEGMEXEC
69859+ if (vma_m)
69860+ pax_mirror_vma(vma_m, vma);
69861+#endif
69862+
69863 return 0;
69864 }
69865
69866@@ -2178,6 +2609,8 @@ struct vm_area_struct *copy_vma(struct v
69867 struct rb_node **rb_link, *rb_parent;
69868 struct mempolicy *pol;
69869
69870+ BUG_ON(vma->vm_mirror);
69871+
69872 /*
69873 * If anonymous vma has not yet been faulted, update new pgoff
69874 * to match new location, to increase its chance of merging.
69875@@ -2221,6 +2654,35 @@ struct vm_area_struct *copy_vma(struct v
69876 return new_vma;
69877 }
69878
69879+#ifdef CONFIG_PAX_SEGMEXEC
69880+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
69881+{
69882+ struct vm_area_struct *prev_m;
69883+ struct rb_node **rb_link_m, *rb_parent_m;
69884+ struct mempolicy *pol_m;
69885+
69886+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
69887+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
69888+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
69889+ *vma_m = *vma;
69890+ pol_m = vma_policy(vma_m);
69891+ mpol_get(pol_m);
69892+ vma_set_policy(vma_m, pol_m);
69893+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
69894+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
69895+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
69896+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
69897+ if (vma_m->vm_file)
69898+ get_file(vma_m->vm_file);
69899+ if (vma_m->vm_ops && vma_m->vm_ops->open)
69900+ vma_m->vm_ops->open(vma_m);
69901+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
69902+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
69903+ vma_m->vm_mirror = vma;
69904+ vma->vm_mirror = vma_m;
69905+}
69906+#endif
69907+
69908 /*
69909 * Return true if the calling process may expand its vm space by the passed
69910 * number of pages
69911@@ -2231,7 +2693,7 @@ int may_expand_vm(struct mm_struct *mm,
69912 unsigned long lim;
69913
69914 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
69915-
69916+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
69917 if (cur + npages > lim)
69918 return 0;
69919 return 1;
69920@@ -2301,6 +2763,22 @@ int install_special_mapping(struct mm_st
69921 vma->vm_start = addr;
69922 vma->vm_end = addr + len;
69923
69924+#ifdef CONFIG_PAX_MPROTECT
69925+ if (mm->pax_flags & MF_PAX_MPROTECT) {
69926+#ifndef CONFIG_PAX_MPROTECT_COMPAT
69927+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
69928+ return -EPERM;
69929+ if (!(vm_flags & VM_EXEC))
69930+ vm_flags &= ~VM_MAYEXEC;
69931+#else
69932+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
69933+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
69934+#endif
69935+ else
69936+ vm_flags &= ~VM_MAYWRITE;
69937+ }
69938+#endif
69939+
69940 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
69941 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69942
69943diff -urNp linux-2.6.32.44/mm/mprotect.c linux-2.6.32.44/mm/mprotect.c
69944--- linux-2.6.32.44/mm/mprotect.c 2011-03-27 14:31:47.000000000 -0400
69945+++ linux-2.6.32.44/mm/mprotect.c 2011-04-17 15:56:46.000000000 -0400
69946@@ -24,10 +24,16 @@
69947 #include <linux/mmu_notifier.h>
69948 #include <linux/migrate.h>
69949 #include <linux/perf_event.h>
69950+
69951+#ifdef CONFIG_PAX_MPROTECT
69952+#include <linux/elf.h>
69953+#endif
69954+
69955 #include <asm/uaccess.h>
69956 #include <asm/pgtable.h>
69957 #include <asm/cacheflush.h>
69958 #include <asm/tlbflush.h>
69959+#include <asm/mmu_context.h>
69960
69961 #ifndef pgprot_modify
69962 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
69963@@ -132,6 +138,48 @@ static void change_protection(struct vm_
69964 flush_tlb_range(vma, start, end);
69965 }
69966
69967+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69968+/* called while holding the mmap semaphor for writing except stack expansion */
69969+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
69970+{
69971+ unsigned long oldlimit, newlimit = 0UL;
69972+
69973+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
69974+ return;
69975+
69976+ spin_lock(&mm->page_table_lock);
69977+ oldlimit = mm->context.user_cs_limit;
69978+ if ((prot & VM_EXEC) && oldlimit < end)
69979+ /* USER_CS limit moved up */
69980+ newlimit = end;
69981+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
69982+ /* USER_CS limit moved down */
69983+ newlimit = start;
69984+
69985+ if (newlimit) {
69986+ mm->context.user_cs_limit = newlimit;
69987+
69988+#ifdef CONFIG_SMP
69989+ wmb();
69990+ cpus_clear(mm->context.cpu_user_cs_mask);
69991+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
69992+#endif
69993+
69994+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
69995+ }
69996+ spin_unlock(&mm->page_table_lock);
69997+ if (newlimit == end) {
69998+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
69999+
70000+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
70001+ if (is_vm_hugetlb_page(vma))
70002+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
70003+ else
70004+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
70005+ }
70006+}
70007+#endif
70008+
70009 int
70010 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70011 unsigned long start, unsigned long end, unsigned long newflags)
70012@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vm
70013 int error;
70014 int dirty_accountable = 0;
70015
70016+#ifdef CONFIG_PAX_SEGMEXEC
70017+ struct vm_area_struct *vma_m = NULL;
70018+ unsigned long start_m, end_m;
70019+
70020+ start_m = start + SEGMEXEC_TASK_SIZE;
70021+ end_m = end + SEGMEXEC_TASK_SIZE;
70022+#endif
70023+
70024 if (newflags == oldflags) {
70025 *pprev = vma;
70026 return 0;
70027 }
70028
70029+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
70030+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
70031+
70032+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
70033+ return -ENOMEM;
70034+
70035+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
70036+ return -ENOMEM;
70037+ }
70038+
70039 /*
70040 * If we make a private mapping writable we increase our commit;
70041 * but (without finer accounting) cannot reduce our commit if we
70042@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vm
70043 }
70044 }
70045
70046+#ifdef CONFIG_PAX_SEGMEXEC
70047+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
70048+ if (start != vma->vm_start) {
70049+ error = split_vma(mm, vma, start, 1);
70050+ if (error)
70051+ goto fail;
70052+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
70053+ *pprev = (*pprev)->vm_next;
70054+ }
70055+
70056+ if (end != vma->vm_end) {
70057+ error = split_vma(mm, vma, end, 0);
70058+ if (error)
70059+ goto fail;
70060+ }
70061+
70062+ if (pax_find_mirror_vma(vma)) {
70063+ error = __do_munmap(mm, start_m, end_m - start_m);
70064+ if (error)
70065+ goto fail;
70066+ } else {
70067+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70068+ if (!vma_m) {
70069+ error = -ENOMEM;
70070+ goto fail;
70071+ }
70072+ vma->vm_flags = newflags;
70073+ pax_mirror_vma(vma_m, vma);
70074+ }
70075+ }
70076+#endif
70077+
70078 /*
70079 * First try to merge with previous and/or next vma.
70080 */
70081@@ -195,9 +293,21 @@ success:
70082 * vm_flags and vm_page_prot are protected by the mmap_sem
70083 * held in write mode.
70084 */
70085+
70086+#ifdef CONFIG_PAX_SEGMEXEC
70087+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
70088+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
70089+#endif
70090+
70091 vma->vm_flags = newflags;
70092+
70093+#ifdef CONFIG_PAX_MPROTECT
70094+ if (mm->binfmt && mm->binfmt->handle_mprotect)
70095+ mm->binfmt->handle_mprotect(vma, newflags);
70096+#endif
70097+
70098 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
70099- vm_get_page_prot(newflags));
70100+ vm_get_page_prot(vma->vm_flags));
70101
70102 if (vma_wants_writenotify(vma)) {
70103 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
70104@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
70105 end = start + len;
70106 if (end <= start)
70107 return -ENOMEM;
70108+
70109+#ifdef CONFIG_PAX_SEGMEXEC
70110+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70111+ if (end > SEGMEXEC_TASK_SIZE)
70112+ return -EINVAL;
70113+ } else
70114+#endif
70115+
70116+ if (end > TASK_SIZE)
70117+ return -EINVAL;
70118+
70119 if (!arch_validate_prot(prot))
70120 return -EINVAL;
70121
70122@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
70123 /*
70124 * Does the application expect PROT_READ to imply PROT_EXEC:
70125 */
70126- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70127+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70128 prot |= PROT_EXEC;
70129
70130 vm_flags = calc_vm_prot_bits(prot);
70131@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
70132 if (start > vma->vm_start)
70133 prev = vma;
70134
70135+#ifdef CONFIG_PAX_MPROTECT
70136+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
70137+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
70138+#endif
70139+
70140 for (nstart = start ; ; ) {
70141 unsigned long newflags;
70142
70143@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
70144
70145 /* newflags >> 4 shift VM_MAY% in place of VM_% */
70146 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
70147+ if (prot & (PROT_WRITE | PROT_EXEC))
70148+ gr_log_rwxmprotect(vma->vm_file);
70149+
70150+ error = -EACCES;
70151+ goto out;
70152+ }
70153+
70154+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
70155 error = -EACCES;
70156 goto out;
70157 }
70158@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
70159 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
70160 if (error)
70161 goto out;
70162+
70163+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
70164+
70165 nstart = tmp;
70166
70167 if (nstart < prev->vm_end)
70168diff -urNp linux-2.6.32.44/mm/mremap.c linux-2.6.32.44/mm/mremap.c
70169--- linux-2.6.32.44/mm/mremap.c 2011-04-17 17:00:52.000000000 -0400
70170+++ linux-2.6.32.44/mm/mremap.c 2011-04-17 17:03:58.000000000 -0400
70171@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_str
70172 continue;
70173 pte = ptep_clear_flush(vma, old_addr, old_pte);
70174 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
70175+
70176+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70177+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
70178+ pte = pte_exprotect(pte);
70179+#endif
70180+
70181 set_pte_at(mm, new_addr, new_pte, pte);
70182 }
70183
70184@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_res
70185 if (is_vm_hugetlb_page(vma))
70186 goto Einval;
70187
70188+#ifdef CONFIG_PAX_SEGMEXEC
70189+ if (pax_find_mirror_vma(vma))
70190+ goto Einval;
70191+#endif
70192+
70193 /* We can't remap across vm area boundaries */
70194 if (old_len > vma->vm_end - addr)
70195 goto Efault;
70196@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned
70197 unsigned long ret = -EINVAL;
70198 unsigned long charged = 0;
70199 unsigned long map_flags;
70200+ unsigned long pax_task_size = TASK_SIZE;
70201
70202 if (new_addr & ~PAGE_MASK)
70203 goto out;
70204
70205- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
70206+#ifdef CONFIG_PAX_SEGMEXEC
70207+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
70208+ pax_task_size = SEGMEXEC_TASK_SIZE;
70209+#endif
70210+
70211+ pax_task_size -= PAGE_SIZE;
70212+
70213+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
70214 goto out;
70215
70216 /* Check if the location we're moving into overlaps the
70217 * old location at all, and fail if it does.
70218 */
70219- if ((new_addr <= addr) && (new_addr+new_len) > addr)
70220- goto out;
70221-
70222- if ((addr <= new_addr) && (addr+old_len) > new_addr)
70223+ if (addr + old_len > new_addr && new_addr + new_len > addr)
70224 goto out;
70225
70226 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70227@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long ad
70228 struct vm_area_struct *vma;
70229 unsigned long ret = -EINVAL;
70230 unsigned long charged = 0;
70231+ unsigned long pax_task_size = TASK_SIZE;
70232
70233 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
70234 goto out;
70235@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long ad
70236 if (!new_len)
70237 goto out;
70238
70239+#ifdef CONFIG_PAX_SEGMEXEC
70240+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
70241+ pax_task_size = SEGMEXEC_TASK_SIZE;
70242+#endif
70243+
70244+ pax_task_size -= PAGE_SIZE;
70245+
70246+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
70247+ old_len > pax_task_size || addr > pax_task_size-old_len)
70248+ goto out;
70249+
70250 if (flags & MREMAP_FIXED) {
70251 if (flags & MREMAP_MAYMOVE)
70252 ret = mremap_to(addr, old_len, new_addr, new_len);
70253@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long ad
70254 addr + new_len);
70255 }
70256 ret = addr;
70257+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
70258 goto out;
70259 }
70260 }
70261@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long ad
70262 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70263 if (ret)
70264 goto out;
70265+
70266+ map_flags = vma->vm_flags;
70267 ret = move_vma(vma, addr, old_len, new_len, new_addr);
70268+ if (!(ret & ~PAGE_MASK)) {
70269+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
70270+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
70271+ }
70272 }
70273 out:
70274 if (ret & ~PAGE_MASK)
70275diff -urNp linux-2.6.32.44/mm/nommu.c linux-2.6.32.44/mm/nommu.c
70276--- linux-2.6.32.44/mm/nommu.c 2011-03-27 14:31:47.000000000 -0400
70277+++ linux-2.6.32.44/mm/nommu.c 2011-04-17 15:56:46.000000000 -0400
70278@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMI
70279 int sysctl_overcommit_ratio = 50; /* default is 50% */
70280 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
70281 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
70282-int heap_stack_gap = 0;
70283
70284 atomic_long_t mmap_pages_allocated;
70285
70286@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct m
70287 EXPORT_SYMBOL(find_vma);
70288
70289 /*
70290- * find a VMA
70291- * - we don't extend stack VMAs under NOMMU conditions
70292- */
70293-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
70294-{
70295- return find_vma(mm, addr);
70296-}
70297-
70298-/*
70299 * expand a stack to a given address
70300 * - not supported under NOMMU conditions
70301 */
70302diff -urNp linux-2.6.32.44/mm/page_alloc.c linux-2.6.32.44/mm/page_alloc.c
70303--- linux-2.6.32.44/mm/page_alloc.c 2011-06-25 12:55:35.000000000 -0400
70304+++ linux-2.6.32.44/mm/page_alloc.c 2011-07-09 09:13:08.000000000 -0400
70305@@ -289,7 +289,7 @@ out:
70306 * This usage means that zero-order pages may not be compound.
70307 */
70308
70309-static void free_compound_page(struct page *page)
70310+void free_compound_page(struct page *page)
70311 {
70312 __free_pages_ok(page, compound_order(page));
70313 }
70314@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page
70315 int bad = 0;
70316 int wasMlocked = __TestClearPageMlocked(page);
70317
70318+#ifdef CONFIG_PAX_MEMORY_SANITIZE
70319+ unsigned long index = 1UL << order;
70320+#endif
70321+
70322 kmemcheck_free_shadow(page, order);
70323
70324 for (i = 0 ; i < (1 << order) ; ++i)
70325@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page
70326 debug_check_no_obj_freed(page_address(page),
70327 PAGE_SIZE << order);
70328 }
70329+
70330+#ifdef CONFIG_PAX_MEMORY_SANITIZE
70331+ for (; index; --index)
70332+ sanitize_highpage(page + index - 1);
70333+#endif
70334+
70335 arch_free_page(page, order);
70336 kernel_map_pages(page, 1 << order, 0);
70337
70338@@ -702,8 +712,10 @@ static int prep_new_page(struct page *pa
70339 arch_alloc_page(page, order);
70340 kernel_map_pages(page, 1 << order, 1);
70341
70342+#ifndef CONFIG_PAX_MEMORY_SANITIZE
70343 if (gfp_flags & __GFP_ZERO)
70344 prep_zero_page(page, order, gfp_flags);
70345+#endif
70346
70347 if (order && (gfp_flags & __GFP_COMP))
70348 prep_compound_page(page, order);
70349@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct pa
70350 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
70351 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
70352 }
70353+
70354+#ifdef CONFIG_PAX_MEMORY_SANITIZE
70355+ sanitize_highpage(page);
70356+#endif
70357+
70358 arch_free_page(page, 0);
70359 kernel_map_pages(page, 1, 0);
70360
70361@@ -2179,6 +2196,8 @@ void show_free_areas(void)
70362 int cpu;
70363 struct zone *zone;
70364
70365+ pax_track_stack();
70366+
70367 for_each_populated_zone(zone) {
70368 show_node(zone);
70369 printk("%s per-cpu:\n", zone->name);
70370@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct p
70371 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
70372 }
70373 #else
70374-static void inline setup_usemap(struct pglist_data *pgdat,
70375+static inline void setup_usemap(struct pglist_data *pgdat,
70376 struct zone *zone, unsigned long zonesize) {}
70377 #endif /* CONFIG_SPARSEMEM */
70378
70379diff -urNp linux-2.6.32.44/mm/percpu.c linux-2.6.32.44/mm/percpu.c
70380--- linux-2.6.32.44/mm/percpu.c 2011-03-27 14:31:47.000000000 -0400
70381+++ linux-2.6.32.44/mm/percpu.c 2011-04-17 15:56:46.000000000 -0400
70382@@ -115,7 +115,7 @@ static unsigned int pcpu_first_unit_cpu
70383 static unsigned int pcpu_last_unit_cpu __read_mostly;
70384
70385 /* the address of the first chunk which starts with the kernel static area */
70386-void *pcpu_base_addr __read_mostly;
70387+void *pcpu_base_addr __read_only;
70388 EXPORT_SYMBOL_GPL(pcpu_base_addr);
70389
70390 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
70391diff -urNp linux-2.6.32.44/mm/rmap.c linux-2.6.32.44/mm/rmap.c
70392--- linux-2.6.32.44/mm/rmap.c 2011-03-27 14:31:47.000000000 -0400
70393+++ linux-2.6.32.44/mm/rmap.c 2011-04-17 15:56:46.000000000 -0400
70394@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_stru
70395 /* page_table_lock to protect against threads */
70396 spin_lock(&mm->page_table_lock);
70397 if (likely(!vma->anon_vma)) {
70398+
70399+#ifdef CONFIG_PAX_SEGMEXEC
70400+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
70401+
70402+ if (vma_m) {
70403+ BUG_ON(vma_m->anon_vma);
70404+ vma_m->anon_vma = anon_vma;
70405+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
70406+ }
70407+#endif
70408+
70409 vma->anon_vma = anon_vma;
70410 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
70411 allocated = NULL;
70412diff -urNp linux-2.6.32.44/mm/shmem.c linux-2.6.32.44/mm/shmem.c
70413--- linux-2.6.32.44/mm/shmem.c 2011-03-27 14:31:47.000000000 -0400
70414+++ linux-2.6.32.44/mm/shmem.c 2011-05-18 20:09:37.000000000 -0400
70415@@ -31,7 +31,7 @@
70416 #include <linux/swap.h>
70417 #include <linux/ima.h>
70418
70419-static struct vfsmount *shm_mnt;
70420+struct vfsmount *shm_mnt;
70421
70422 #ifdef CONFIG_SHMEM
70423 /*
70424@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *
70425 goto unlock;
70426 }
70427 entry = shmem_swp_entry(info, index, NULL);
70428+ if (!entry)
70429+ goto unlock;
70430 if (entry->val) {
70431 /*
70432 * The more uptodate page coming down from a stacked
70433@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_ent
70434 struct vm_area_struct pvma;
70435 struct page *page;
70436
70437+ pax_track_stack();
70438+
70439 spol = mpol_cond_copy(&mpol,
70440 mpol_shared_policy_lookup(&info->policy, idx));
70441
70442@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *d
70443
70444 info = SHMEM_I(inode);
70445 inode->i_size = len-1;
70446- if (len <= (char *)inode - (char *)info) {
70447+ if (len <= (char *)inode - (char *)info && len <= 64) {
70448 /* do it inline */
70449 memcpy(info, symname, len);
70450 inode->i_op = &shmem_symlink_inline_operations;
70451@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block
70452 int err = -ENOMEM;
70453
70454 /* Round up to L1_CACHE_BYTES to resist false sharing */
70455- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
70456- L1_CACHE_BYTES), GFP_KERNEL);
70457+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
70458 if (!sbinfo)
70459 return -ENOMEM;
70460
70461diff -urNp linux-2.6.32.44/mm/slab.c linux-2.6.32.44/mm/slab.c
70462--- linux-2.6.32.44/mm/slab.c 2011-03-27 14:31:47.000000000 -0400
70463+++ linux-2.6.32.44/mm/slab.c 2011-05-04 17:56:20.000000000 -0400
70464@@ -174,7 +174,7 @@
70465
70466 /* Legal flag mask for kmem_cache_create(). */
70467 #if DEBUG
70468-# define CREATE_MASK (SLAB_RED_ZONE | \
70469+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
70470 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
70471 SLAB_CACHE_DMA | \
70472 SLAB_STORE_USER | \
70473@@ -182,7 +182,7 @@
70474 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70475 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
70476 #else
70477-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
70478+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
70479 SLAB_CACHE_DMA | \
70480 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
70481 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70482@@ -308,7 +308,7 @@ struct kmem_list3 {
70483 * Need this for bootstrapping a per node allocator.
70484 */
70485 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
70486-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
70487+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
70488 #define CACHE_CACHE 0
70489 #define SIZE_AC MAX_NUMNODES
70490 #define SIZE_L3 (2 * MAX_NUMNODES)
70491@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_
70492 if ((x)->max_freeable < i) \
70493 (x)->max_freeable = i; \
70494 } while (0)
70495-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
70496-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
70497-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
70498-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
70499+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
70500+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
70501+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
70502+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
70503 #else
70504 #define STATS_INC_ACTIVE(x) do { } while (0)
70505 #define STATS_DEC_ACTIVE(x) do { } while (0)
70506@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct
70507 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
70508 */
70509 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
70510- const struct slab *slab, void *obj)
70511+ const struct slab *slab, const void *obj)
70512 {
70513 u32 offset = (obj - slab->s_mem);
70514 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
70515@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
70516 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
70517 sizes[INDEX_AC].cs_size,
70518 ARCH_KMALLOC_MINALIGN,
70519- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70520+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70521 NULL);
70522
70523 if (INDEX_AC != INDEX_L3) {
70524@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
70525 kmem_cache_create(names[INDEX_L3].name,
70526 sizes[INDEX_L3].cs_size,
70527 ARCH_KMALLOC_MINALIGN,
70528- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70529+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70530 NULL);
70531 }
70532
70533@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
70534 sizes->cs_cachep = kmem_cache_create(names->name,
70535 sizes->cs_size,
70536 ARCH_KMALLOC_MINALIGN,
70537- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70538+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70539 NULL);
70540 }
70541 #ifdef CONFIG_ZONE_DMA
70542@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, vo
70543 }
70544 /* cpu stats */
70545 {
70546- unsigned long allochit = atomic_read(&cachep->allochit);
70547- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
70548- unsigned long freehit = atomic_read(&cachep->freehit);
70549- unsigned long freemiss = atomic_read(&cachep->freemiss);
70550+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
70551+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
70552+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
70553+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
70554
70555 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
70556 allochit, allocmiss, freehit, freemiss);
70557@@ -4471,15 +4471,66 @@ static const struct file_operations proc
70558
70559 static int __init slab_proc_init(void)
70560 {
70561- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
70562+ mode_t gr_mode = S_IRUGO;
70563+
70564+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70565+ gr_mode = S_IRUSR;
70566+#endif
70567+
70568+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
70569 #ifdef CONFIG_DEBUG_SLAB_LEAK
70570- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
70571+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
70572 #endif
70573 return 0;
70574 }
70575 module_init(slab_proc_init);
70576 #endif
70577
70578+void check_object_size(const void *ptr, unsigned long n, bool to)
70579+{
70580+
70581+#ifdef CONFIG_PAX_USERCOPY
70582+ struct page *page;
70583+ struct kmem_cache *cachep = NULL;
70584+ struct slab *slabp;
70585+ unsigned int objnr;
70586+ unsigned long offset;
70587+
70588+ if (!n)
70589+ return;
70590+
70591+ if (ZERO_OR_NULL_PTR(ptr))
70592+ goto report;
70593+
70594+ if (!virt_addr_valid(ptr))
70595+ return;
70596+
70597+ page = virt_to_head_page(ptr);
70598+
70599+ if (!PageSlab(page)) {
70600+ if (object_is_on_stack(ptr, n) == -1)
70601+ goto report;
70602+ return;
70603+ }
70604+
70605+ cachep = page_get_cache(page);
70606+ if (!(cachep->flags & SLAB_USERCOPY))
70607+ goto report;
70608+
70609+ slabp = page_get_slab(page);
70610+ objnr = obj_to_index(cachep, slabp, ptr);
70611+ BUG_ON(objnr >= cachep->num);
70612+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
70613+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
70614+ return;
70615+
70616+report:
70617+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
70618+#endif
70619+
70620+}
70621+EXPORT_SYMBOL(check_object_size);
70622+
70623 /**
70624 * ksize - get the actual amount of memory allocated for a given object
70625 * @objp: Pointer to the object
70626diff -urNp linux-2.6.32.44/mm/slob.c linux-2.6.32.44/mm/slob.c
70627--- linux-2.6.32.44/mm/slob.c 2011-03-27 14:31:47.000000000 -0400
70628+++ linux-2.6.32.44/mm/slob.c 2011-07-06 19:53:33.000000000 -0400
70629@@ -29,7 +29,7 @@
70630 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
70631 * alloc_pages() directly, allocating compound pages so the page order
70632 * does not have to be separately tracked, and also stores the exact
70633- * allocation size in page->private so that it can be used to accurately
70634+ * allocation size in slob_page->size so that it can be used to accurately
70635 * provide ksize(). These objects are detected in kfree() because slob_page()
70636 * is false for them.
70637 *
70638@@ -58,6 +58,7 @@
70639 */
70640
70641 #include <linux/kernel.h>
70642+#include <linux/sched.h>
70643 #include <linux/slab.h>
70644 #include <linux/mm.h>
70645 #include <linux/swap.h> /* struct reclaim_state */
70646@@ -100,7 +101,8 @@ struct slob_page {
70647 unsigned long flags; /* mandatory */
70648 atomic_t _count; /* mandatory */
70649 slobidx_t units; /* free units left in page */
70650- unsigned long pad[2];
70651+ unsigned long pad[1];
70652+ unsigned long size; /* size when >=PAGE_SIZE */
70653 slob_t *free; /* first free slob_t in page */
70654 struct list_head list; /* linked list of free pages */
70655 };
70656@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
70657 */
70658 static inline int is_slob_page(struct slob_page *sp)
70659 {
70660- return PageSlab((struct page *)sp);
70661+ return PageSlab((struct page *)sp) && !sp->size;
70662 }
70663
70664 static inline void set_slob_page(struct slob_page *sp)
70665@@ -148,7 +150,7 @@ static inline void clear_slob_page(struc
70666
70667 static inline struct slob_page *slob_page(const void *addr)
70668 {
70669- return (struct slob_page *)virt_to_page(addr);
70670+ return (struct slob_page *)virt_to_head_page(addr);
70671 }
70672
70673 /*
70674@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_
70675 /*
70676 * Return the size of a slob block.
70677 */
70678-static slobidx_t slob_units(slob_t *s)
70679+static slobidx_t slob_units(const slob_t *s)
70680 {
70681 if (s->units > 0)
70682 return s->units;
70683@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
70684 /*
70685 * Return the next free slob block pointer after this one.
70686 */
70687-static slob_t *slob_next(slob_t *s)
70688+static slob_t *slob_next(const slob_t *s)
70689 {
70690 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
70691 slobidx_t next;
70692@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
70693 /*
70694 * Returns true if s is the last free block in its page.
70695 */
70696-static int slob_last(slob_t *s)
70697+static int slob_last(const slob_t *s)
70698 {
70699 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
70700 }
70701@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, i
70702 if (!page)
70703 return NULL;
70704
70705+ set_slob_page(page);
70706 return page_address(page);
70707 }
70708
70709@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp
70710 if (!b)
70711 return NULL;
70712 sp = slob_page(b);
70713- set_slob_page(sp);
70714
70715 spin_lock_irqsave(&slob_lock, flags);
70716 sp->units = SLOB_UNITS(PAGE_SIZE);
70717 sp->free = b;
70718+ sp->size = 0;
70719 INIT_LIST_HEAD(&sp->list);
70720 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
70721 set_slob_page_free(sp, slob_list);
70722@@ -475,10 +478,9 @@ out:
70723 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
70724 #endif
70725
70726-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70727+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
70728 {
70729- unsigned int *m;
70730- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70731+ slob_t *m;
70732 void *ret;
70733
70734 lockdep_trace_alloc(gfp);
70735@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t
70736
70737 if (!m)
70738 return NULL;
70739- *m = size;
70740+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
70741+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
70742+ m[0].units = size;
70743+ m[1].units = align;
70744 ret = (void *)m + align;
70745
70746 trace_kmalloc_node(_RET_IP_, ret,
70747@@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t
70748
70749 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
70750 if (ret) {
70751- struct page *page;
70752- page = virt_to_page(ret);
70753- page->private = size;
70754+ struct slob_page *sp;
70755+ sp = slob_page(ret);
70756+ sp->size = size;
70757 }
70758
70759 trace_kmalloc_node(_RET_IP_, ret,
70760 size, PAGE_SIZE << order, gfp, node);
70761 }
70762
70763- kmemleak_alloc(ret, size, 1, gfp);
70764+ return ret;
70765+}
70766+
70767+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70768+{
70769+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70770+ void *ret = __kmalloc_node_align(size, gfp, node, align);
70771+
70772+ if (!ZERO_OR_NULL_PTR(ret))
70773+ kmemleak_alloc(ret, size, 1, gfp);
70774 return ret;
70775 }
70776 EXPORT_SYMBOL(__kmalloc_node);
70777@@ -528,13 +542,88 @@ void kfree(const void *block)
70778 sp = slob_page(block);
70779 if (is_slob_page(sp)) {
70780 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70781- unsigned int *m = (unsigned int *)(block - align);
70782- slob_free(m, *m + align);
70783- } else
70784+ slob_t *m = (slob_t *)(block - align);
70785+ slob_free(m, m[0].units + align);
70786+ } else {
70787+ clear_slob_page(sp);
70788+ free_slob_page(sp);
70789+ sp->size = 0;
70790 put_page(&sp->page);
70791+ }
70792 }
70793 EXPORT_SYMBOL(kfree);
70794
70795+void check_object_size(const void *ptr, unsigned long n, bool to)
70796+{
70797+
70798+#ifdef CONFIG_PAX_USERCOPY
70799+ struct slob_page *sp;
70800+ const slob_t *free;
70801+ const void *base;
70802+ unsigned long flags;
70803+
70804+ if (!n)
70805+ return;
70806+
70807+ if (ZERO_OR_NULL_PTR(ptr))
70808+ goto report;
70809+
70810+ if (!virt_addr_valid(ptr))
70811+ return;
70812+
70813+ sp = slob_page(ptr);
70814+ if (!PageSlab((struct page*)sp)) {
70815+ if (object_is_on_stack(ptr, n) == -1)
70816+ goto report;
70817+ return;
70818+ }
70819+
70820+ if (sp->size) {
70821+ base = page_address(&sp->page);
70822+ if (base <= ptr && n <= sp->size - (ptr - base))
70823+ return;
70824+ goto report;
70825+ }
70826+
70827+ /* some tricky double walking to find the chunk */
70828+ spin_lock_irqsave(&slob_lock, flags);
70829+ base = (void *)((unsigned long)ptr & PAGE_MASK);
70830+ free = sp->free;
70831+
70832+ while (!slob_last(free) && (void *)free <= ptr) {
70833+ base = free + slob_units(free);
70834+ free = slob_next(free);
70835+ }
70836+
70837+ while (base < (void *)free) {
70838+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
70839+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
70840+ int offset;
70841+
70842+ if (ptr < base + align)
70843+ break;
70844+
70845+ offset = ptr - base - align;
70846+ if (offset >= m) {
70847+ base += size;
70848+ continue;
70849+ }
70850+
70851+ if (n > m - offset)
70852+ break;
70853+
70854+ spin_unlock_irqrestore(&slob_lock, flags);
70855+ return;
70856+ }
70857+
70858+ spin_unlock_irqrestore(&slob_lock, flags);
70859+report:
70860+ pax_report_usercopy(ptr, n, to, NULL);
70861+#endif
70862+
70863+}
70864+EXPORT_SYMBOL(check_object_size);
70865+
70866 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
70867 size_t ksize(const void *block)
70868 {
70869@@ -547,10 +636,10 @@ size_t ksize(const void *block)
70870 sp = slob_page(block);
70871 if (is_slob_page(sp)) {
70872 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70873- unsigned int *m = (unsigned int *)(block - align);
70874- return SLOB_UNITS(*m) * SLOB_UNIT;
70875+ slob_t *m = (slob_t *)(block - align);
70876+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
70877 } else
70878- return sp->page.private;
70879+ return sp->size;
70880 }
70881 EXPORT_SYMBOL(ksize);
70882
70883@@ -566,8 +655,13 @@ struct kmem_cache *kmem_cache_create(con
70884 {
70885 struct kmem_cache *c;
70886
70887+#ifdef CONFIG_PAX_USERCOPY
70888+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
70889+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
70890+#else
70891 c = slob_alloc(sizeof(struct kmem_cache),
70892 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
70893+#endif
70894
70895 if (c) {
70896 c->name = name;
70897@@ -605,17 +699,25 @@ void *kmem_cache_alloc_node(struct kmem_
70898 {
70899 void *b;
70900
70901+#ifdef CONFIG_PAX_USERCOPY
70902+ b = __kmalloc_node_align(c->size, flags, node, c->align);
70903+#else
70904 if (c->size < PAGE_SIZE) {
70905 b = slob_alloc(c->size, flags, c->align, node);
70906 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
70907 SLOB_UNITS(c->size) * SLOB_UNIT,
70908 flags, node);
70909 } else {
70910+ struct slob_page *sp;
70911+
70912 b = slob_new_pages(flags, get_order(c->size), node);
70913+ sp = slob_page(b);
70914+ sp->size = c->size;
70915 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
70916 PAGE_SIZE << get_order(c->size),
70917 flags, node);
70918 }
70919+#endif
70920
70921 if (c->ctor)
70922 c->ctor(b);
70923@@ -627,10 +729,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
70924
70925 static void __kmem_cache_free(void *b, int size)
70926 {
70927- if (size < PAGE_SIZE)
70928+ struct slob_page *sp = slob_page(b);
70929+
70930+ if (is_slob_page(sp))
70931 slob_free(b, size);
70932- else
70933+ else {
70934+ clear_slob_page(sp);
70935+ free_slob_page(sp);
70936+ sp->size = 0;
70937 slob_free_pages(b, get_order(size));
70938+ }
70939 }
70940
70941 static void kmem_rcu_free(struct rcu_head *head)
70942@@ -643,18 +751,32 @@ static void kmem_rcu_free(struct rcu_hea
70943
70944 void kmem_cache_free(struct kmem_cache *c, void *b)
70945 {
70946+ int size = c->size;
70947+
70948+#ifdef CONFIG_PAX_USERCOPY
70949+ if (size + c->align < PAGE_SIZE) {
70950+ size += c->align;
70951+ b -= c->align;
70952+ }
70953+#endif
70954+
70955 kmemleak_free_recursive(b, c->flags);
70956 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
70957 struct slob_rcu *slob_rcu;
70958- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
70959+ slob_rcu = b + (size - sizeof(struct slob_rcu));
70960 INIT_RCU_HEAD(&slob_rcu->head);
70961- slob_rcu->size = c->size;
70962+ slob_rcu->size = size;
70963 call_rcu(&slob_rcu->head, kmem_rcu_free);
70964 } else {
70965- __kmem_cache_free(b, c->size);
70966+ __kmem_cache_free(b, size);
70967 }
70968
70969+#ifdef CONFIG_PAX_USERCOPY
70970+ trace_kfree(_RET_IP_, b);
70971+#else
70972 trace_kmem_cache_free(_RET_IP_, b);
70973+#endif
70974+
70975 }
70976 EXPORT_SYMBOL(kmem_cache_free);
70977
70978diff -urNp linux-2.6.32.44/mm/slub.c linux-2.6.32.44/mm/slub.c
70979--- linux-2.6.32.44/mm/slub.c 2011-03-27 14:31:47.000000000 -0400
70980+++ linux-2.6.32.44/mm/slub.c 2011-04-17 15:56:46.000000000 -0400
70981@@ -410,7 +410,7 @@ static void print_track(const char *s, s
70982 if (!t->addr)
70983 return;
70984
70985- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
70986+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
70987 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
70988 }
70989
70990@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *
70991
70992 page = virt_to_head_page(x);
70993
70994+ BUG_ON(!PageSlab(page));
70995+
70996 slab_free(s, page, x, _RET_IP_);
70997
70998 trace_kmem_cache_free(_RET_IP_, x);
70999@@ -1937,7 +1939,7 @@ static int slub_min_objects;
71000 * Merge control. If this is set then no merging of slab caches will occur.
71001 * (Could be removed. This was introduced to pacify the merge skeptics.)
71002 */
71003-static int slub_nomerge;
71004+static int slub_nomerge = 1;
71005
71006 /*
71007 * Calculate the order of allocation given an slab object size.
71008@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_c
71009 * list to avoid pounding the page allocator excessively.
71010 */
71011 set_min_partial(s, ilog2(s->size));
71012- s->refcount = 1;
71013+ atomic_set(&s->refcount, 1);
71014 #ifdef CONFIG_NUMA
71015 s->remote_node_defrag_ratio = 1000;
71016 #endif
71017@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struc
71018 void kmem_cache_destroy(struct kmem_cache *s)
71019 {
71020 down_write(&slub_lock);
71021- s->refcount--;
71022- if (!s->refcount) {
71023+ if (atomic_dec_and_test(&s->refcount)) {
71024 list_del(&s->list);
71025 up_write(&slub_lock);
71026 if (kmem_cache_close(s)) {
71027@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(cha
71028 __setup("slub_nomerge", setup_slub_nomerge);
71029
71030 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
71031- const char *name, int size, gfp_t gfp_flags)
71032+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
71033 {
71034- unsigned int flags = 0;
71035-
71036 if (gfp_flags & SLUB_DMA)
71037- flags = SLAB_CACHE_DMA;
71038+ flags |= SLAB_CACHE_DMA;
71039
71040 /*
71041 * This function is called with IRQs disabled during early-boot on
71042@@ -2915,6 +2914,46 @@ void *__kmalloc_node(size_t size, gfp_t
71043 EXPORT_SYMBOL(__kmalloc_node);
71044 #endif
71045
71046+void check_object_size(const void *ptr, unsigned long n, bool to)
71047+{
71048+
71049+#ifdef CONFIG_PAX_USERCOPY
71050+ struct page *page;
71051+ struct kmem_cache *s = NULL;
71052+ unsigned long offset;
71053+
71054+ if (!n)
71055+ return;
71056+
71057+ if (ZERO_OR_NULL_PTR(ptr))
71058+ goto report;
71059+
71060+ if (!virt_addr_valid(ptr))
71061+ return;
71062+
71063+ page = get_object_page(ptr);
71064+
71065+ if (!page) {
71066+ if (object_is_on_stack(ptr, n) == -1)
71067+ goto report;
71068+ return;
71069+ }
71070+
71071+ s = page->slab;
71072+ if (!(s->flags & SLAB_USERCOPY))
71073+ goto report;
71074+
71075+ offset = (ptr - page_address(page)) % s->size;
71076+ if (offset <= s->objsize && n <= s->objsize - offset)
71077+ return;
71078+
71079+report:
71080+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
71081+#endif
71082+
71083+}
71084+EXPORT_SYMBOL(check_object_size);
71085+
71086 size_t ksize(const void *object)
71087 {
71088 struct page *page;
71089@@ -3185,8 +3224,8 @@ void __init kmem_cache_init(void)
71090 * kmem_cache_open for slab_state == DOWN.
71091 */
71092 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
71093- sizeof(struct kmem_cache_node), GFP_NOWAIT);
71094- kmalloc_caches[0].refcount = -1;
71095+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
71096+ atomic_set(&kmalloc_caches[0].refcount, -1);
71097 caches++;
71098
71099 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
71100@@ -3198,18 +3237,18 @@ void __init kmem_cache_init(void)
71101 /* Caches that are not of the two-to-the-power-of size */
71102 if (KMALLOC_MIN_SIZE <= 32) {
71103 create_kmalloc_cache(&kmalloc_caches[1],
71104- "kmalloc-96", 96, GFP_NOWAIT);
71105+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
71106 caches++;
71107 }
71108 if (KMALLOC_MIN_SIZE <= 64) {
71109 create_kmalloc_cache(&kmalloc_caches[2],
71110- "kmalloc-192", 192, GFP_NOWAIT);
71111+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
71112 caches++;
71113 }
71114
71115 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
71116 create_kmalloc_cache(&kmalloc_caches[i],
71117- "kmalloc", 1 << i, GFP_NOWAIT);
71118+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
71119 caches++;
71120 }
71121
71122@@ -3293,7 +3332,7 @@ static int slab_unmergeable(struct kmem_
71123 /*
71124 * We may have set a slab to be unmergeable during bootstrap.
71125 */
71126- if (s->refcount < 0)
71127+ if (atomic_read(&s->refcount) < 0)
71128 return 1;
71129
71130 return 0;
71131@@ -3353,7 +3392,7 @@ struct kmem_cache *kmem_cache_create(con
71132 if (s) {
71133 int cpu;
71134
71135- s->refcount++;
71136+ atomic_inc(&s->refcount);
71137 /*
71138 * Adjust the object sizes so that we clear
71139 * the complete object on kzalloc.
71140@@ -3372,7 +3411,7 @@ struct kmem_cache *kmem_cache_create(con
71141
71142 if (sysfs_slab_alias(s, name)) {
71143 down_write(&slub_lock);
71144- s->refcount--;
71145+ atomic_dec(&s->refcount);
71146 up_write(&slub_lock);
71147 goto err;
71148 }
71149@@ -4101,7 +4140,7 @@ SLAB_ATTR_RO(ctor);
71150
71151 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
71152 {
71153- return sprintf(buf, "%d\n", s->refcount - 1);
71154+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
71155 }
71156 SLAB_ATTR_RO(aliases);
71157
71158@@ -4503,7 +4542,7 @@ static void kmem_cache_release(struct ko
71159 kfree(s);
71160 }
71161
71162-static struct sysfs_ops slab_sysfs_ops = {
71163+static const struct sysfs_ops slab_sysfs_ops = {
71164 .show = slab_attr_show,
71165 .store = slab_attr_store,
71166 };
71167@@ -4522,7 +4561,7 @@ static int uevent_filter(struct kset *ks
71168 return 0;
71169 }
71170
71171-static struct kset_uevent_ops slab_uevent_ops = {
71172+static const struct kset_uevent_ops slab_uevent_ops = {
71173 .filter = uevent_filter,
71174 };
71175
71176@@ -4785,7 +4824,13 @@ static const struct file_operations proc
71177
71178 static int __init slab_proc_init(void)
71179 {
71180- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
71181+ mode_t gr_mode = S_IRUGO;
71182+
71183+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71184+ gr_mode = S_IRUSR;
71185+#endif
71186+
71187+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
71188 return 0;
71189 }
71190 module_init(slab_proc_init);
71191diff -urNp linux-2.6.32.44/mm/swap.c linux-2.6.32.44/mm/swap.c
71192--- linux-2.6.32.44/mm/swap.c 2011-03-27 14:31:47.000000000 -0400
71193+++ linux-2.6.32.44/mm/swap.c 2011-07-09 09:15:19.000000000 -0400
71194@@ -30,6 +30,7 @@
71195 #include <linux/notifier.h>
71196 #include <linux/backing-dev.h>
71197 #include <linux/memcontrol.h>
71198+#include <linux/hugetlb.h>
71199
71200 #include "internal.h"
71201
71202@@ -65,6 +66,8 @@ static void put_compound_page(struct pag
71203 compound_page_dtor *dtor;
71204
71205 dtor = get_compound_page_dtor(page);
71206+ if (!PageHuge(page))
71207+ BUG_ON(dtor != free_compound_page);
71208 (*dtor)(page);
71209 }
71210 }
71211diff -urNp linux-2.6.32.44/mm/util.c linux-2.6.32.44/mm/util.c
71212--- linux-2.6.32.44/mm/util.c 2011-03-27 14:31:47.000000000 -0400
71213+++ linux-2.6.32.44/mm/util.c 2011-04-17 15:56:46.000000000 -0400
71214@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
71215 void arch_pick_mmap_layout(struct mm_struct *mm)
71216 {
71217 mm->mmap_base = TASK_UNMAPPED_BASE;
71218+
71219+#ifdef CONFIG_PAX_RANDMMAP
71220+ if (mm->pax_flags & MF_PAX_RANDMMAP)
71221+ mm->mmap_base += mm->delta_mmap;
71222+#endif
71223+
71224 mm->get_unmapped_area = arch_get_unmapped_area;
71225 mm->unmap_area = arch_unmap_area;
71226 }
71227diff -urNp linux-2.6.32.44/mm/vmalloc.c linux-2.6.32.44/mm/vmalloc.c
71228--- linux-2.6.32.44/mm/vmalloc.c 2011-03-27 14:31:47.000000000 -0400
71229+++ linux-2.6.32.44/mm/vmalloc.c 2011-04-17 15:56:46.000000000 -0400
71230@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd,
71231
71232 pte = pte_offset_kernel(pmd, addr);
71233 do {
71234- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71235- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71236+
71237+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71238+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
71239+ BUG_ON(!pte_exec(*pte));
71240+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
71241+ continue;
71242+ }
71243+#endif
71244+
71245+ {
71246+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71247+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71248+ }
71249 } while (pte++, addr += PAGE_SIZE, addr != end);
71250 }
71251
71252@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, un
71253 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
71254 {
71255 pte_t *pte;
71256+ int ret = -ENOMEM;
71257
71258 /*
71259 * nr is a running index into the array which helps higher level
71260@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, un
71261 pte = pte_alloc_kernel(pmd, addr);
71262 if (!pte)
71263 return -ENOMEM;
71264+
71265+ pax_open_kernel();
71266 do {
71267 struct page *page = pages[*nr];
71268
71269- if (WARN_ON(!pte_none(*pte)))
71270- return -EBUSY;
71271- if (WARN_ON(!page))
71272- return -ENOMEM;
71273+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71274+ if (!(pgprot_val(prot) & _PAGE_NX))
71275+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
71276+ else
71277+#endif
71278+
71279+ if (WARN_ON(!pte_none(*pte))) {
71280+ ret = -EBUSY;
71281+ goto out;
71282+ }
71283+ if (WARN_ON(!page)) {
71284+ ret = -ENOMEM;
71285+ goto out;
71286+ }
71287 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
71288 (*nr)++;
71289 } while (pte++, addr += PAGE_SIZE, addr != end);
71290- return 0;
71291+ ret = 0;
71292+out:
71293+ pax_close_kernel();
71294+ return ret;
71295 }
71296
71297 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
71298@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void
71299 * and fall back on vmalloc() if that fails. Others
71300 * just put it in the vmalloc space.
71301 */
71302-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
71303+#ifdef CONFIG_MODULES
71304+#ifdef MODULES_VADDR
71305 unsigned long addr = (unsigned long)x;
71306 if (addr >= MODULES_VADDR && addr < MODULES_END)
71307 return 1;
71308 #endif
71309+
71310+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71311+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
71312+ return 1;
71313+#endif
71314+
71315+#endif
71316+
71317 return is_vmalloc_addr(x);
71318 }
71319
71320@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void
71321
71322 if (!pgd_none(*pgd)) {
71323 pud_t *pud = pud_offset(pgd, addr);
71324+#ifdef CONFIG_X86
71325+ if (!pud_large(*pud))
71326+#endif
71327 if (!pud_none(*pud)) {
71328 pmd_t *pmd = pmd_offset(pud, addr);
71329+#ifdef CONFIG_X86
71330+ if (!pmd_large(*pmd))
71331+#endif
71332 if (!pmd_none(*pmd)) {
71333 pte_t *ptep, pte;
71334
71335@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vm
71336 struct rb_node *tmp;
71337
71338 while (*p) {
71339- struct vmap_area *tmp;
71340+ struct vmap_area *varea;
71341
71342 parent = *p;
71343- tmp = rb_entry(parent, struct vmap_area, rb_node);
71344- if (va->va_start < tmp->va_end)
71345+ varea = rb_entry(parent, struct vmap_area, rb_node);
71346+ if (va->va_start < varea->va_end)
71347 p = &(*p)->rb_left;
71348- else if (va->va_end > tmp->va_start)
71349+ else if (va->va_end > varea->va_start)
71350 p = &(*p)->rb_right;
71351 else
71352 BUG();
71353@@ -1232,6 +1274,16 @@ static struct vm_struct *__get_vm_area_n
71354 struct vm_struct *area;
71355
71356 BUG_ON(in_interrupt());
71357+
71358+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71359+ if (flags & VM_KERNEXEC) {
71360+ if (start != VMALLOC_START || end != VMALLOC_END)
71361+ return NULL;
71362+ start = (unsigned long)MODULES_EXEC_VADDR;
71363+ end = (unsigned long)MODULES_EXEC_END;
71364+ }
71365+#endif
71366+
71367 if (flags & VM_IOREMAP) {
71368 int bit = fls(size);
71369
71370@@ -1457,6 +1509,11 @@ void *vmap(struct page **pages, unsigned
71371 if (count > totalram_pages)
71372 return NULL;
71373
71374+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71375+ if (!(pgprot_val(prot) & _PAGE_NX))
71376+ flags |= VM_KERNEXEC;
71377+#endif
71378+
71379 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
71380 __builtin_return_address(0));
71381 if (!area)
71382@@ -1567,6 +1624,13 @@ static void *__vmalloc_node(unsigned lon
71383 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
71384 return NULL;
71385
71386+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71387+ if (!(pgprot_val(prot) & _PAGE_NX))
71388+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
71389+ node, gfp_mask, caller);
71390+ else
71391+#endif
71392+
71393 area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
71394 VMALLOC_END, node, gfp_mask, caller);
71395
71396@@ -1585,6 +1649,7 @@ static void *__vmalloc_node(unsigned lon
71397 return addr;
71398 }
71399
71400+#undef __vmalloc
71401 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
71402 {
71403 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
71404@@ -1601,6 +1666,7 @@ EXPORT_SYMBOL(__vmalloc);
71405 * For tight control over page level allocator and protection flags
71406 * use __vmalloc() instead.
71407 */
71408+#undef vmalloc
71409 void *vmalloc(unsigned long size)
71410 {
71411 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
71412@@ -1615,6 +1681,7 @@ EXPORT_SYMBOL(vmalloc);
71413 * The resulting memory area is zeroed so it can be mapped to userspace
71414 * without leaking data.
71415 */
71416+#undef vmalloc_user
71417 void *vmalloc_user(unsigned long size)
71418 {
71419 struct vm_struct *area;
71420@@ -1642,6 +1709,7 @@ EXPORT_SYMBOL(vmalloc_user);
71421 * For tight control over page level allocator and protection flags
71422 * use __vmalloc() instead.
71423 */
71424+#undef vmalloc_node
71425 void *vmalloc_node(unsigned long size, int node)
71426 {
71427 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
71428@@ -1664,10 +1732,10 @@ EXPORT_SYMBOL(vmalloc_node);
71429 * For tight control over page level allocator and protection flags
71430 * use __vmalloc() instead.
71431 */
71432-
71433+#undef vmalloc_exec
71434 void *vmalloc_exec(unsigned long size)
71435 {
71436- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
71437+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
71438 -1, __builtin_return_address(0));
71439 }
71440
71441@@ -1686,6 +1754,7 @@ void *vmalloc_exec(unsigned long size)
71442 * Allocate enough 32bit PA addressable pages to cover @size from the
71443 * page level allocator and map them into contiguous kernel virtual space.
71444 */
71445+#undef vmalloc_32
71446 void *vmalloc_32(unsigned long size)
71447 {
71448 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
71449@@ -1700,6 +1769,7 @@ EXPORT_SYMBOL(vmalloc_32);
71450 * The resulting memory area is 32bit addressable and zeroed so it can be
71451 * mapped to userspace without leaking data.
71452 */
71453+#undef vmalloc_32_user
71454 void *vmalloc_32_user(unsigned long size)
71455 {
71456 struct vm_struct *area;
71457@@ -1964,6 +2034,8 @@ int remap_vmalloc_range(struct vm_area_s
71458 unsigned long uaddr = vma->vm_start;
71459 unsigned long usize = vma->vm_end - vma->vm_start;
71460
71461+ BUG_ON(vma->vm_mirror);
71462+
71463 if ((PAGE_SIZE-1) & (unsigned long)addr)
71464 return -EINVAL;
71465
71466diff -urNp linux-2.6.32.44/mm/vmstat.c linux-2.6.32.44/mm/vmstat.c
71467--- linux-2.6.32.44/mm/vmstat.c 2011-03-27 14:31:47.000000000 -0400
71468+++ linux-2.6.32.44/mm/vmstat.c 2011-04-17 15:56:46.000000000 -0400
71469@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
71470 *
71471 * vm_stat contains the global counters
71472 */
71473-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71474+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71475 EXPORT_SYMBOL(vm_stat);
71476
71477 #ifdef CONFIG_SMP
71478@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
71479 v = p->vm_stat_diff[i];
71480 p->vm_stat_diff[i] = 0;
71481 local_irq_restore(flags);
71482- atomic_long_add(v, &zone->vm_stat[i]);
71483+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
71484 global_diff[i] += v;
71485 #ifdef CONFIG_NUMA
71486 /* 3 seconds idle till flush */
71487@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
71488
71489 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
71490 if (global_diff[i])
71491- atomic_long_add(global_diff[i], &vm_stat[i]);
71492+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
71493 }
71494
71495 #endif
71496@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
71497 start_cpu_timer(cpu);
71498 #endif
71499 #ifdef CONFIG_PROC_FS
71500- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
71501- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
71502- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
71503- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
71504+ {
71505+ mode_t gr_mode = S_IRUGO;
71506+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71507+ gr_mode = S_IRUSR;
71508+#endif
71509+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
71510+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
71511+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
71512+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
71513+#else
71514+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
71515+#endif
71516+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
71517+ }
71518 #endif
71519 return 0;
71520 }
71521diff -urNp linux-2.6.32.44/net/8021q/vlan.c linux-2.6.32.44/net/8021q/vlan.c
71522--- linux-2.6.32.44/net/8021q/vlan.c 2011-03-27 14:31:47.000000000 -0400
71523+++ linux-2.6.32.44/net/8021q/vlan.c 2011-04-17 15:56:46.000000000 -0400
71524@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net
71525 err = -EPERM;
71526 if (!capable(CAP_NET_ADMIN))
71527 break;
71528- if ((args.u.name_type >= 0) &&
71529- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
71530+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
71531 struct vlan_net *vn;
71532
71533 vn = net_generic(net, vlan_net_id);
71534diff -urNp linux-2.6.32.44/net/atm/atm_misc.c linux-2.6.32.44/net/atm/atm_misc.c
71535--- linux-2.6.32.44/net/atm/atm_misc.c 2011-03-27 14:31:47.000000000 -0400
71536+++ linux-2.6.32.44/net/atm/atm_misc.c 2011-04-17 15:56:46.000000000 -0400
71537@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int t
71538 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
71539 return 1;
71540 atm_return(vcc,truesize);
71541- atomic_inc(&vcc->stats->rx_drop);
71542+ atomic_inc_unchecked(&vcc->stats->rx_drop);
71543 return 0;
71544 }
71545
71546@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct
71547 }
71548 }
71549 atm_return(vcc,guess);
71550- atomic_inc(&vcc->stats->rx_drop);
71551+ atomic_inc_unchecked(&vcc->stats->rx_drop);
71552 return NULL;
71553 }
71554
71555@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafpr
71556
71557 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
71558 {
71559-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71560+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71561 __SONET_ITEMS
71562 #undef __HANDLE_ITEM
71563 }
71564@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_sta
71565
71566 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
71567 {
71568-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
71569+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
71570 __SONET_ITEMS
71571 #undef __HANDLE_ITEM
71572 }
71573diff -urNp linux-2.6.32.44/net/atm/lec.h linux-2.6.32.44/net/atm/lec.h
71574--- linux-2.6.32.44/net/atm/lec.h 2011-03-27 14:31:47.000000000 -0400
71575+++ linux-2.6.32.44/net/atm/lec.h 2011-08-05 20:33:55.000000000 -0400
71576@@ -48,7 +48,7 @@ struct lane2_ops {
71577 const u8 *tlvs, u32 sizeoftlvs);
71578 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
71579 const u8 *tlvs, u32 sizeoftlvs);
71580-};
71581+} __no_const;
71582
71583 /*
71584 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
71585diff -urNp linux-2.6.32.44/net/atm/mpc.c linux-2.6.32.44/net/atm/mpc.c
71586--- linux-2.6.32.44/net/atm/mpc.c 2011-03-27 14:31:47.000000000 -0400
71587+++ linux-2.6.32.44/net/atm/mpc.c 2011-08-05 20:33:55.000000000 -0400
71588@@ -291,8 +291,8 @@ static void start_mpc(struct mpoa_client
71589 printk("mpoa: (%s) start_mpc not starting\n", dev->name);
71590 else {
71591 mpc->old_ops = dev->netdev_ops;
71592- mpc->new_ops = *mpc->old_ops;
71593- mpc->new_ops.ndo_start_xmit = mpc_send_packet;
71594+ memcpy((void *)&mpc->new_ops, mpc->old_ops, sizeof(mpc->new_ops));
71595+ *(void **)&mpc->new_ops.ndo_start_xmit = mpc_send_packet;
71596 dev->netdev_ops = &mpc->new_ops;
71597 }
71598 }
71599diff -urNp linux-2.6.32.44/net/atm/mpoa_caches.c linux-2.6.32.44/net/atm/mpoa_caches.c
71600--- linux-2.6.32.44/net/atm/mpoa_caches.c 2011-03-27 14:31:47.000000000 -0400
71601+++ linux-2.6.32.44/net/atm/mpoa_caches.c 2011-05-16 21:46:57.000000000 -0400
71602@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_cl
71603 struct timeval now;
71604 struct k_message msg;
71605
71606+ pax_track_stack();
71607+
71608 do_gettimeofday(&now);
71609
71610 write_lock_irq(&client->egress_lock);
71611diff -urNp linux-2.6.32.44/net/atm/proc.c linux-2.6.32.44/net/atm/proc.c
71612--- linux-2.6.32.44/net/atm/proc.c 2011-03-27 14:31:47.000000000 -0400
71613+++ linux-2.6.32.44/net/atm/proc.c 2011-04-17 15:56:46.000000000 -0400
71614@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *s
71615 const struct k_atm_aal_stats *stats)
71616 {
71617 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
71618- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
71619- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
71620- atomic_read(&stats->rx_drop));
71621+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
71622+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
71623+ atomic_read_unchecked(&stats->rx_drop));
71624 }
71625
71626 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
71627@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *se
71628 {
71629 struct sock *sk = sk_atm(vcc);
71630
71631+#ifdef CONFIG_GRKERNSEC_HIDESYM
71632+ seq_printf(seq, "%p ", NULL);
71633+#else
71634 seq_printf(seq, "%p ", vcc);
71635+#endif
71636+
71637 if (!vcc->dev)
71638 seq_printf(seq, "Unassigned ");
71639 else
71640@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *se
71641 {
71642 if (!vcc->dev)
71643 seq_printf(seq, sizeof(void *) == 4 ?
71644+#ifdef CONFIG_GRKERNSEC_HIDESYM
71645+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
71646+#else
71647 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
71648+#endif
71649 else
71650 seq_printf(seq, "%3d %3d %5d ",
71651 vcc->dev->number, vcc->vpi, vcc->vci);
71652diff -urNp linux-2.6.32.44/net/atm/resources.c linux-2.6.32.44/net/atm/resources.c
71653--- linux-2.6.32.44/net/atm/resources.c 2011-03-27 14:31:47.000000000 -0400
71654+++ linux-2.6.32.44/net/atm/resources.c 2011-04-17 15:56:46.000000000 -0400
71655@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *
71656 static void copy_aal_stats(struct k_atm_aal_stats *from,
71657 struct atm_aal_stats *to)
71658 {
71659-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71660+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71661 __AAL_STAT_ITEMS
71662 #undef __HANDLE_ITEM
71663 }
71664@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_
71665 static void subtract_aal_stats(struct k_atm_aal_stats *from,
71666 struct atm_aal_stats *to)
71667 {
71668-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
71669+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
71670 __AAL_STAT_ITEMS
71671 #undef __HANDLE_ITEM
71672 }
71673diff -urNp linux-2.6.32.44/net/bluetooth/l2cap.c linux-2.6.32.44/net/bluetooth/l2cap.c
71674--- linux-2.6.32.44/net/bluetooth/l2cap.c 2011-03-27 14:31:47.000000000 -0400
71675+++ linux-2.6.32.44/net/bluetooth/l2cap.c 2011-06-25 14:36:21.000000000 -0400
71676@@ -1885,7 +1885,7 @@ static int l2cap_sock_getsockopt_old(str
71677 err = -ENOTCONN;
71678 break;
71679 }
71680-
71681+ memset(&cinfo, 0, sizeof(cinfo));
71682 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle;
71683 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3);
71684
71685@@ -2719,7 +2719,7 @@ static inline int l2cap_config_req(struc
71686
71687 /* Reject if config buffer is too small. */
71688 len = cmd_len - sizeof(*req);
71689- if (l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
71690+ if (len < 0 || l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
71691 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
71692 l2cap_build_conf_rsp(sk, rsp,
71693 L2CAP_CONF_REJECT, flags), rsp);
71694diff -urNp linux-2.6.32.44/net/bluetooth/rfcomm/sock.c linux-2.6.32.44/net/bluetooth/rfcomm/sock.c
71695--- linux-2.6.32.44/net/bluetooth/rfcomm/sock.c 2011-03-27 14:31:47.000000000 -0400
71696+++ linux-2.6.32.44/net/bluetooth/rfcomm/sock.c 2011-06-12 06:35:00.000000000 -0400
71697@@ -878,6 +878,7 @@ static int rfcomm_sock_getsockopt_old(st
71698
71699 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
71700
71701+ memset(&cinfo, 0, sizeof(cinfo));
71702 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
71703 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
71704
71705diff -urNp linux-2.6.32.44/net/bridge/br_private.h linux-2.6.32.44/net/bridge/br_private.h
71706--- linux-2.6.32.44/net/bridge/br_private.h 2011-08-09 18:35:30.000000000 -0400
71707+++ linux-2.6.32.44/net/bridge/br_private.h 2011-08-09 18:34:01.000000000 -0400
71708@@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event,
71709
71710 #ifdef CONFIG_SYSFS
71711 /* br_sysfs_if.c */
71712-extern struct sysfs_ops brport_sysfs_ops;
71713+extern const struct sysfs_ops brport_sysfs_ops;
71714 extern int br_sysfs_addif(struct net_bridge_port *p);
71715
71716 /* br_sysfs_br.c */
71717diff -urNp linux-2.6.32.44/net/bridge/br_stp_if.c linux-2.6.32.44/net/bridge/br_stp_if.c
71718--- linux-2.6.32.44/net/bridge/br_stp_if.c 2011-03-27 14:31:47.000000000 -0400
71719+++ linux-2.6.32.44/net/bridge/br_stp_if.c 2011-04-17 15:56:46.000000000 -0400
71720@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
71721 char *envp[] = { NULL };
71722
71723 if (br->stp_enabled == BR_USER_STP) {
71724- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
71725+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
71726 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
71727 br->dev->name, r);
71728
71729diff -urNp linux-2.6.32.44/net/bridge/br_sysfs_if.c linux-2.6.32.44/net/bridge/br_sysfs_if.c
71730--- linux-2.6.32.44/net/bridge/br_sysfs_if.c 2011-03-27 14:31:47.000000000 -0400
71731+++ linux-2.6.32.44/net/bridge/br_sysfs_if.c 2011-04-17 15:56:46.000000000 -0400
71732@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobje
71733 return ret;
71734 }
71735
71736-struct sysfs_ops brport_sysfs_ops = {
71737+const struct sysfs_ops brport_sysfs_ops = {
71738 .show = brport_show,
71739 .store = brport_store,
71740 };
71741diff -urNp linux-2.6.32.44/net/bridge/netfilter/ebtables.c linux-2.6.32.44/net/bridge/netfilter/ebtables.c
71742--- linux-2.6.32.44/net/bridge/netfilter/ebtables.c 2011-04-17 17:00:52.000000000 -0400
71743+++ linux-2.6.32.44/net/bridge/netfilter/ebtables.c 2011-05-16 21:46:57.000000000 -0400
71744@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struc
71745 unsigned int entries_size, nentries;
71746 char *entries;
71747
71748+ pax_track_stack();
71749+
71750 if (cmd == EBT_SO_GET_ENTRIES) {
71751 entries_size = t->private->entries_size;
71752 nentries = t->private->nentries;
71753diff -urNp linux-2.6.32.44/net/can/bcm.c linux-2.6.32.44/net/can/bcm.c
71754--- linux-2.6.32.44/net/can/bcm.c 2011-05-10 22:12:01.000000000 -0400
71755+++ linux-2.6.32.44/net/can/bcm.c 2011-05-10 22:12:34.000000000 -0400
71756@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file
71757 struct bcm_sock *bo = bcm_sk(sk);
71758 struct bcm_op *op;
71759
71760+#ifdef CONFIG_GRKERNSEC_HIDESYM
71761+ seq_printf(m, ">>> socket %p", NULL);
71762+ seq_printf(m, " / sk %p", NULL);
71763+ seq_printf(m, " / bo %p", NULL);
71764+#else
71765 seq_printf(m, ">>> socket %p", sk->sk_socket);
71766 seq_printf(m, " / sk %p", sk);
71767 seq_printf(m, " / bo %p", bo);
71768+#endif
71769 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
71770 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
71771 seq_printf(m, " <<<\n");
71772diff -urNp linux-2.6.32.44/net/core/dev.c linux-2.6.32.44/net/core/dev.c
71773--- linux-2.6.32.44/net/core/dev.c 2011-04-17 17:00:52.000000000 -0400
71774+++ linux-2.6.32.44/net/core/dev.c 2011-08-05 20:33:55.000000000 -0400
71775@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const cha
71776 if (no_module && capable(CAP_NET_ADMIN))
71777 no_module = request_module("netdev-%s", name);
71778 if (no_module && capable(CAP_SYS_MODULE)) {
71779+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71780+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
71781+#else
71782 if (!request_module("%s", name))
71783 pr_err("Loading kernel module for a network device "
71784 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
71785 "instead\n", name);
71786+#endif
71787 }
71788 }
71789 EXPORT_SYMBOL(dev_load);
71790@@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct
71791
71792 struct dev_gso_cb {
71793 void (*destructor)(struct sk_buff *skb);
71794-};
71795+} __no_const;
71796
71797 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
71798
71799@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
71800 }
71801 EXPORT_SYMBOL(netif_rx_ni);
71802
71803-static void net_tx_action(struct softirq_action *h)
71804+static void net_tx_action(void)
71805 {
71806 struct softnet_data *sd = &__get_cpu_var(softnet_data);
71807
71808@@ -2826,7 +2830,7 @@ void netif_napi_del(struct napi_struct *
71809 EXPORT_SYMBOL(netif_napi_del);
71810
71811
71812-static void net_rx_action(struct softirq_action *h)
71813+static void net_rx_action(void)
71814 {
71815 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
71816 unsigned long time_limit = jiffies + 2;
71817diff -urNp linux-2.6.32.44/net/core/flow.c linux-2.6.32.44/net/core/flow.c
71818--- linux-2.6.32.44/net/core/flow.c 2011-03-27 14:31:47.000000000 -0400
71819+++ linux-2.6.32.44/net/core/flow.c 2011-05-04 17:56:20.000000000 -0400
71820@@ -35,11 +35,11 @@ struct flow_cache_entry {
71821 atomic_t *object_ref;
71822 };
71823
71824-atomic_t flow_cache_genid = ATOMIC_INIT(0);
71825+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
71826
71827 static u32 flow_hash_shift;
71828 #define flow_hash_size (1 << flow_hash_shift)
71829-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
71830+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
71831
71832 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
71833
71834@@ -52,7 +52,7 @@ struct flow_percpu_info {
71835 u32 hash_rnd;
71836 int count;
71837 };
71838-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
71839+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
71840
71841 #define flow_hash_rnd_recalc(cpu) \
71842 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
71843@@ -69,7 +69,7 @@ struct flow_flush_info {
71844 atomic_t cpuleft;
71845 struct completion completion;
71846 };
71847-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
71848+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
71849
71850 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
71851
71852@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net,
71853 if (fle->family == family &&
71854 fle->dir == dir &&
71855 flow_key_compare(key, &fle->key) == 0) {
71856- if (fle->genid == atomic_read(&flow_cache_genid)) {
71857+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
71858 void *ret = fle->object;
71859
71860 if (ret)
71861@@ -228,7 +228,7 @@ nocache:
71862 err = resolver(net, key, family, dir, &obj, &obj_ref);
71863
71864 if (fle && !err) {
71865- fle->genid = atomic_read(&flow_cache_genid);
71866+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
71867
71868 if (fle->object)
71869 atomic_dec(fle->object_ref);
71870@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(uns
71871
71872 fle = flow_table(cpu)[i];
71873 for (; fle; fle = fle->next) {
71874- unsigned genid = atomic_read(&flow_cache_genid);
71875+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
71876
71877 if (!fle->object || fle->genid == genid)
71878 continue;
71879diff -urNp linux-2.6.32.44/net/core/Makefile linux-2.6.32.44/net/core/Makefile
71880--- linux-2.6.32.44/net/core/Makefile 2011-03-27 14:31:47.000000000 -0400
71881+++ linux-2.6.32.44/net/core/Makefile 2011-08-07 19:48:09.000000000 -0400
71882@@ -3,7 +3,7 @@
71883 #
71884
71885 obj-y := sock.o request_sock.o skbuff.o iovec.o datagram.o stream.o scm.o \
71886- gen_stats.o gen_estimator.o net_namespace.o
71887+ gen_stats.o gen_estimator.o net_namespace.o secure_seq.o
71888
71889 obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
71890 obj-$(CONFIG_HAS_DMA) += skb_dma_map.o
71891diff -urNp linux-2.6.32.44/net/core/rtnetlink.c linux-2.6.32.44/net/core/rtnetlink.c
71892--- linux-2.6.32.44/net/core/rtnetlink.c 2011-03-27 14:31:47.000000000 -0400
71893+++ linux-2.6.32.44/net/core/rtnetlink.c 2011-08-05 20:33:55.000000000 -0400
71894@@ -57,7 +57,7 @@ struct rtnl_link
71895 {
71896 rtnl_doit_func doit;
71897 rtnl_dumpit_func dumpit;
71898-};
71899+} __no_const;
71900
71901 static DEFINE_MUTEX(rtnl_mutex);
71902
71903diff -urNp linux-2.6.32.44/net/core/secure_seq.c linux-2.6.32.44/net/core/secure_seq.c
71904--- linux-2.6.32.44/net/core/secure_seq.c 1969-12-31 19:00:00.000000000 -0500
71905+++ linux-2.6.32.44/net/core/secure_seq.c 2011-08-07 19:48:09.000000000 -0400
71906@@ -0,0 +1,183 @@
71907+#include <linux/kernel.h>
71908+#include <linux/init.h>
71909+#include <linux/cryptohash.h>
71910+#include <linux/module.h>
71911+#include <linux/cache.h>
71912+#include <linux/random.h>
71913+#include <linux/hrtimer.h>
71914+#include <linux/ktime.h>
71915+#include <linux/string.h>
71916+
71917+#include <net/secure_seq.h>
71918+
71919+static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
71920+
71921+static int __init net_secret_init(void)
71922+{
71923+ get_random_bytes(net_secret, sizeof(net_secret));
71924+ return 0;
71925+}
71926+late_initcall(net_secret_init);
71927+
71928+static u32 seq_scale(u32 seq)
71929+{
71930+ /*
71931+ * As close as possible to RFC 793, which
71932+ * suggests using a 250 kHz clock.
71933+ * Further reading shows this assumes 2 Mb/s networks.
71934+ * For 10 Mb/s Ethernet, a 1 MHz clock is appropriate.
71935+ * For 10 Gb/s Ethernet, a 1 GHz clock should be ok, but
71936+ * we also need to limit the resolution so that the u32 seq
71937+ * overlaps less than one time per MSL (2 minutes).
71938+ * Choosing a clock of 64 ns period is OK. (period of 274 s)
71939+ */
71940+ return seq + (ktime_to_ns(ktime_get_real()) >> 6);
71941+}
71942+
71943+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
71944+__u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
71945+ __be16 sport, __be16 dport)
71946+{
71947+ u32 secret[MD5_MESSAGE_BYTES / 4];
71948+ u32 hash[MD5_DIGEST_WORDS];
71949+ u32 i;
71950+
71951+ memcpy(hash, saddr, 16);
71952+ for (i = 0; i < 4; i++)
71953+ secret[i] = net_secret[i] + daddr[i];
71954+ secret[4] = net_secret[4] +
71955+ (((__force u16)sport << 16) + (__force u16)dport);
71956+ for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
71957+ secret[i] = net_secret[i];
71958+
71959+ md5_transform(hash, secret);
71960+
71961+ return seq_scale(hash[0]);
71962+}
71963+EXPORT_SYMBOL(secure_tcpv6_sequence_number);
71964+
71965+u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
71966+ __be16 dport)
71967+{
71968+ u32 secret[MD5_MESSAGE_BYTES / 4];
71969+ u32 hash[MD5_DIGEST_WORDS];
71970+ u32 i;
71971+
71972+ memcpy(hash, saddr, 16);
71973+ for (i = 0; i < 4; i++)
71974+ secret[i] = net_secret[i] + (__force u32) daddr[i];
71975+ secret[4] = net_secret[4] + (__force u32)dport;
71976+ for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
71977+ secret[i] = net_secret[i];
71978+
71979+ md5_transform(hash, secret);
71980+ return hash[0];
71981+}
71982+#endif
71983+
71984+#ifdef CONFIG_INET
71985+__u32 secure_ip_id(__be32 daddr)
71986+{
71987+ u32 hash[MD5_DIGEST_WORDS];
71988+
71989+ hash[0] = (__force __u32) daddr;
71990+ hash[1] = net_secret[13];
71991+ hash[2] = net_secret[14];
71992+ hash[3] = net_secret[15];
71993+
71994+ md5_transform(hash, net_secret);
71995+
71996+ return hash[0];
71997+}
71998+
71999+__u32 secure_ipv6_id(const __be32 daddr[4])
72000+{
72001+ __u32 hash[4];
72002+
72003+ memcpy(hash, daddr, 16);
72004+ md5_transform(hash, net_secret);
72005+
72006+ return hash[0];
72007+}
72008+
72009+__u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
72010+ __be16 sport, __be16 dport)
72011+{
72012+ u32 hash[MD5_DIGEST_WORDS];
72013+
72014+ hash[0] = (__force u32)saddr;
72015+ hash[1] = (__force u32)daddr;
72016+ hash[2] = ((__force u16)sport << 16) + (__force u16)dport;
72017+ hash[3] = net_secret[15];
72018+
72019+ md5_transform(hash, net_secret);
72020+
72021+ return seq_scale(hash[0]);
72022+}
72023+
72024+u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport)
72025+{
72026+ u32 hash[MD5_DIGEST_WORDS];
72027+
72028+ hash[0] = (__force u32)saddr;
72029+ hash[1] = (__force u32)daddr;
72030+ hash[2] = (__force u32)dport ^ net_secret[14];
72031+ hash[3] = net_secret[15];
72032+
72033+ md5_transform(hash, net_secret);
72034+
72035+ return hash[0];
72036+}
72037+EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral);
72038+#endif
72039+
72040+#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
72041+u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
72042+ __be16 sport, __be16 dport)
72043+{
72044+ u32 hash[MD5_DIGEST_WORDS];
72045+ u64 seq;
72046+
72047+ hash[0] = (__force u32)saddr;
72048+ hash[1] = (__force u32)daddr;
72049+ hash[2] = ((__force u16)sport << 16) + (__force u16)dport;
72050+ hash[3] = net_secret[15];
72051+
72052+ md5_transform(hash, net_secret);
72053+
72054+ seq = hash[0] | (((u64)hash[1]) << 32);
72055+ seq += ktime_to_ns(ktime_get_real());
72056+ seq &= (1ull << 48) - 1;
72057+
72058+ return seq;
72059+}
72060+EXPORT_SYMBOL(secure_dccp_sequence_number);
72061+
72062+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
72063+u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
72064+ __be16 sport, __be16 dport)
72065+{
72066+ u32 secret[MD5_MESSAGE_BYTES / 4];
72067+ u32 hash[MD5_DIGEST_WORDS];
72068+ u64 seq;
72069+ u32 i;
72070+
72071+ memcpy(hash, saddr, 16);
72072+ for (i = 0; i < 4; i++)
72073+ secret[i] = net_secret[i] + daddr[i];
72074+ secret[4] = net_secret[4] +
72075+ (((__force u16)sport << 16) + (__force u16)dport);
72076+ for (i = 5; i < MD5_MESSAGE_BYTES / 4; i++)
72077+ secret[i] = net_secret[i];
72078+
72079+ md5_transform(hash, secret);
72080+
72081+ seq = hash[0] | (((u64)hash[1]) << 32);
72082+ seq += ktime_to_ns(ktime_get_real());
72083+ seq &= (1ull << 48) - 1;
72084+
72085+ return seq;
72086+}
72087+EXPORT_SYMBOL(secure_dccpv6_sequence_number);
72088+#endif
72089+#endif
72090diff -urNp linux-2.6.32.44/net/core/skbuff.c linux-2.6.32.44/net/core/skbuff.c
72091--- linux-2.6.32.44/net/core/skbuff.c 2011-03-27 14:31:47.000000000 -0400
72092+++ linux-2.6.32.44/net/core/skbuff.c 2011-05-16 21:46:57.000000000 -0400
72093@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb,
72094 struct sk_buff *frag_iter;
72095 struct sock *sk = skb->sk;
72096
72097+ pax_track_stack();
72098+
72099 /*
72100 * __skb_splice_bits() only fails if the output has no room left,
72101 * so no point in going over the frag_list for the error case.
72102diff -urNp linux-2.6.32.44/net/core/sock.c linux-2.6.32.44/net/core/sock.c
72103--- linux-2.6.32.44/net/core/sock.c 2011-03-27 14:31:47.000000000 -0400
72104+++ linux-2.6.32.44/net/core/sock.c 2011-05-04 17:56:20.000000000 -0400
72105@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock,
72106 break;
72107
72108 case SO_PEERCRED:
72109+ {
72110+ struct ucred peercred;
72111 if (len > sizeof(sk->sk_peercred))
72112 len = sizeof(sk->sk_peercred);
72113- if (copy_to_user(optval, &sk->sk_peercred, len))
72114+ peercred = sk->sk_peercred;
72115+ if (copy_to_user(optval, &peercred, len))
72116 return -EFAULT;
72117 goto lenout;
72118+ }
72119
72120 case SO_PEERNAME:
72121 {
72122@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock,
72123 */
72124 smp_wmb();
72125 atomic_set(&sk->sk_refcnt, 1);
72126- atomic_set(&sk->sk_drops, 0);
72127+ atomic_set_unchecked(&sk->sk_drops, 0);
72128 }
72129 EXPORT_SYMBOL(sock_init_data);
72130
72131diff -urNp linux-2.6.32.44/net/dccp/ipv4.c linux-2.6.32.44/net/dccp/ipv4.c
72132--- linux-2.6.32.44/net/dccp/ipv4.c 2011-03-27 14:31:47.000000000 -0400
72133+++ linux-2.6.32.44/net/dccp/ipv4.c 2011-08-07 19:48:09.000000000 -0400
72134@@ -25,6 +25,7 @@
72135 #include <net/timewait_sock.h>
72136 #include <net/tcp_states.h>
72137 #include <net/xfrm.h>
72138+#include <net/secure_seq.h>
72139
72140 #include "ackvec.h"
72141 #include "ccid.h"
72142diff -urNp linux-2.6.32.44/net/dccp/ipv6.c linux-2.6.32.44/net/dccp/ipv6.c
72143--- linux-2.6.32.44/net/dccp/ipv6.c 2011-03-27 14:31:47.000000000 -0400
72144+++ linux-2.6.32.44/net/dccp/ipv6.c 2011-08-07 19:48:09.000000000 -0400
72145@@ -28,6 +28,7 @@
72146 #include <net/transp_v6.h>
72147 #include <net/ip6_checksum.h>
72148 #include <net/xfrm.h>
72149+#include <net/secure_seq.h>
72150
72151 #include "dccp.h"
72152 #include "ipv6.h"
72153@@ -69,13 +70,7 @@ static inline void dccp_v6_send_check(st
72154 dh->dccph_checksum = dccp_v6_csum_finish(skb, &np->saddr, &np->daddr);
72155 }
72156
72157-static inline __u32 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
72158- __be16 sport, __be16 dport )
72159-{
72160- return secure_tcpv6_sequence_number(saddr, daddr, sport, dport);
72161-}
72162-
72163-static inline __u32 dccp_v6_init_sequence(struct sk_buff *skb)
72164+static inline __u64 dccp_v6_init_sequence(struct sk_buff *skb)
72165 {
72166 return secure_dccpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32,
72167 ipv6_hdr(skb)->saddr.s6_addr32,
72168diff -urNp linux-2.6.32.44/net/decnet/sysctl_net_decnet.c linux-2.6.32.44/net/decnet/sysctl_net_decnet.c
72169--- linux-2.6.32.44/net/decnet/sysctl_net_decnet.c 2011-03-27 14:31:47.000000000 -0400
72170+++ linux-2.6.32.44/net/decnet/sysctl_net_decnet.c 2011-04-17 15:56:46.000000000 -0400
72171@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_t
72172
72173 if (len > *lenp) len = *lenp;
72174
72175- if (copy_to_user(buffer, addr, len))
72176+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
72177 return -EFAULT;
72178
72179 *lenp = len;
72180@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table
72181
72182 if (len > *lenp) len = *lenp;
72183
72184- if (copy_to_user(buffer, devname, len))
72185+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
72186 return -EFAULT;
72187
72188 *lenp = len;
72189diff -urNp linux-2.6.32.44/net/econet/Kconfig linux-2.6.32.44/net/econet/Kconfig
72190--- linux-2.6.32.44/net/econet/Kconfig 2011-03-27 14:31:47.000000000 -0400
72191+++ linux-2.6.32.44/net/econet/Kconfig 2011-04-17 15:56:46.000000000 -0400
72192@@ -4,7 +4,7 @@
72193
72194 config ECONET
72195 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
72196- depends on EXPERIMENTAL && INET
72197+ depends on EXPERIMENTAL && INET && BROKEN
72198 ---help---
72199 Econet is a fairly old and slow networking protocol mainly used by
72200 Acorn computers to access file and print servers. It uses native
72201diff -urNp linux-2.6.32.44/net/ieee802154/dgram.c linux-2.6.32.44/net/ieee802154/dgram.c
72202--- linux-2.6.32.44/net/ieee802154/dgram.c 2011-03-27 14:31:47.000000000 -0400
72203+++ linux-2.6.32.44/net/ieee802154/dgram.c 2011-05-04 17:56:28.000000000 -0400
72204@@ -318,7 +318,7 @@ out:
72205 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
72206 {
72207 if (sock_queue_rcv_skb(sk, skb) < 0) {
72208- atomic_inc(&sk->sk_drops);
72209+ atomic_inc_unchecked(&sk->sk_drops);
72210 kfree_skb(skb);
72211 return NET_RX_DROP;
72212 }
72213diff -urNp linux-2.6.32.44/net/ieee802154/raw.c linux-2.6.32.44/net/ieee802154/raw.c
72214--- linux-2.6.32.44/net/ieee802154/raw.c 2011-03-27 14:31:47.000000000 -0400
72215+++ linux-2.6.32.44/net/ieee802154/raw.c 2011-05-04 17:56:28.000000000 -0400
72216@@ -206,7 +206,7 @@ out:
72217 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
72218 {
72219 if (sock_queue_rcv_skb(sk, skb) < 0) {
72220- atomic_inc(&sk->sk_drops);
72221+ atomic_inc_unchecked(&sk->sk_drops);
72222 kfree_skb(skb);
72223 return NET_RX_DROP;
72224 }
72225diff -urNp linux-2.6.32.44/net/ipv4/inet_diag.c linux-2.6.32.44/net/ipv4/inet_diag.c
72226--- linux-2.6.32.44/net/ipv4/inet_diag.c 2011-07-13 17:23:04.000000000 -0400
72227+++ linux-2.6.32.44/net/ipv4/inet_diag.c 2011-06-20 19:31:13.000000000 -0400
72228@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct soc
72229 r->idiag_retrans = 0;
72230
72231 r->id.idiag_if = sk->sk_bound_dev_if;
72232+#ifdef CONFIG_GRKERNSEC_HIDESYM
72233+ r->id.idiag_cookie[0] = 0;
72234+ r->id.idiag_cookie[1] = 0;
72235+#else
72236 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
72237 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
72238+#endif
72239
72240 r->id.idiag_sport = inet->sport;
72241 r->id.idiag_dport = inet->dport;
72242@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct in
72243 r->idiag_family = tw->tw_family;
72244 r->idiag_retrans = 0;
72245 r->id.idiag_if = tw->tw_bound_dev_if;
72246+
72247+#ifdef CONFIG_GRKERNSEC_HIDESYM
72248+ r->id.idiag_cookie[0] = 0;
72249+ r->id.idiag_cookie[1] = 0;
72250+#else
72251 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
72252 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
72253+#endif
72254+
72255 r->id.idiag_sport = tw->tw_sport;
72256 r->id.idiag_dport = tw->tw_dport;
72257 r->id.idiag_src[0] = tw->tw_rcv_saddr;
72258@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk
72259 if (sk == NULL)
72260 goto unlock;
72261
72262+#ifndef CONFIG_GRKERNSEC_HIDESYM
72263 err = -ESTALE;
72264 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
72265 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
72266 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
72267 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
72268 goto out;
72269+#endif
72270
72271 err = -ENOMEM;
72272 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
72273@@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_
72274 r->idiag_retrans = req->retrans;
72275
72276 r->id.idiag_if = sk->sk_bound_dev_if;
72277+
72278+#ifdef CONFIG_GRKERNSEC_HIDESYM
72279+ r->id.idiag_cookie[0] = 0;
72280+ r->id.idiag_cookie[1] = 0;
72281+#else
72282 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
72283 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
72284+#endif
72285
72286 tmo = req->expires - jiffies;
72287 if (tmo < 0)
72288diff -urNp linux-2.6.32.44/net/ipv4/inet_hashtables.c linux-2.6.32.44/net/ipv4/inet_hashtables.c
72289--- linux-2.6.32.44/net/ipv4/inet_hashtables.c 2011-03-27 14:31:47.000000000 -0400
72290+++ linux-2.6.32.44/net/ipv4/inet_hashtables.c 2011-08-07 19:48:09.000000000 -0400
72291@@ -18,11 +18,15 @@
72292 #include <linux/sched.h>
72293 #include <linux/slab.h>
72294 #include <linux/wait.h>
72295+#include <linux/security.h>
72296
72297 #include <net/inet_connection_sock.h>
72298 #include <net/inet_hashtables.h>
72299+#include <net/secure_seq.h>
72300 #include <net/ip.h>
72301
72302+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
72303+
72304 /*
72305 * Allocate and initialize a new local port bind bucket.
72306 * The bindhash mutex for snum's hash chain must be held here.
72307@@ -490,6 +494,8 @@ ok:
72308 }
72309 spin_unlock(&head->lock);
72310
72311+ gr_update_task_in_ip_table(current, inet_sk(sk));
72312+
72313 if (tw) {
72314 inet_twsk_deschedule(tw, death_row);
72315 inet_twsk_put(tw);
72316diff -urNp linux-2.6.32.44/net/ipv4/inetpeer.c linux-2.6.32.44/net/ipv4/inetpeer.c
72317--- linux-2.6.32.44/net/ipv4/inetpeer.c 2011-03-27 14:31:47.000000000 -0400
72318+++ linux-2.6.32.44/net/ipv4/inetpeer.c 2011-08-07 19:48:09.000000000 -0400
72319@@ -19,6 +19,7 @@
72320 #include <linux/net.h>
72321 #include <net/ip.h>
72322 #include <net/inetpeer.h>
72323+#include <net/secure_seq.h>
72324
72325 /*
72326 * Theory of operations.
72327@@ -366,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 da
72328 struct inet_peer *p, *n;
72329 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
72330
72331+ pax_track_stack();
72332+
72333 /* Look up for the address quickly. */
72334 read_lock_bh(&peer_pool_lock);
72335 p = lookup(daddr, NULL);
72336@@ -389,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 da
72337 return NULL;
72338 n->v4daddr = daddr;
72339 atomic_set(&n->refcnt, 1);
72340- atomic_set(&n->rid, 0);
72341+ atomic_set_unchecked(&n->rid, 0);
72342 n->ip_id_count = secure_ip_id(daddr);
72343 n->tcp_ts_stamp = 0;
72344
72345diff -urNp linux-2.6.32.44/net/ipv4/ip_fragment.c linux-2.6.32.44/net/ipv4/ip_fragment.c
72346--- linux-2.6.32.44/net/ipv4/ip_fragment.c 2011-03-27 14:31:47.000000000 -0400
72347+++ linux-2.6.32.44/net/ipv4/ip_fragment.c 2011-04-17 15:56:46.000000000 -0400
72348@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct
72349 return 0;
72350
72351 start = qp->rid;
72352- end = atomic_inc_return(&peer->rid);
72353+ end = atomic_inc_return_unchecked(&peer->rid);
72354 qp->rid = end;
72355
72356 rc = qp->q.fragments && (end - start) > max;
72357diff -urNp linux-2.6.32.44/net/ipv4/ip_sockglue.c linux-2.6.32.44/net/ipv4/ip_sockglue.c
72358--- linux-2.6.32.44/net/ipv4/ip_sockglue.c 2011-03-27 14:31:47.000000000 -0400
72359+++ linux-2.6.32.44/net/ipv4/ip_sockglue.c 2011-05-16 21:46:57.000000000 -0400
72360@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock
72361 int val;
72362 int len;
72363
72364+ pax_track_stack();
72365+
72366 if (level != SOL_IP)
72367 return -EOPNOTSUPP;
72368
72369diff -urNp linux-2.6.32.44/net/ipv4/netfilter/arp_tables.c linux-2.6.32.44/net/ipv4/netfilter/arp_tables.c
72370--- linux-2.6.32.44/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:00:52.000000000 -0400
72371+++ linux-2.6.32.44/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:04:18.000000000 -0400
72372@@ -934,6 +934,7 @@ static int get_info(struct net *net, voi
72373 private = &tmp;
72374 }
72375 #endif
72376+ memset(&info, 0, sizeof(info));
72377 info.valid_hooks = t->valid_hooks;
72378 memcpy(info.hook_entry, private->hook_entry,
72379 sizeof(info.hook_entry));
72380diff -urNp linux-2.6.32.44/net/ipv4/netfilter/ip_tables.c linux-2.6.32.44/net/ipv4/netfilter/ip_tables.c
72381--- linux-2.6.32.44/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:00:52.000000000 -0400
72382+++ linux-2.6.32.44/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:04:18.000000000 -0400
72383@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, voi
72384 private = &tmp;
72385 }
72386 #endif
72387+ memset(&info, 0, sizeof(info));
72388 info.valid_hooks = t->valid_hooks;
72389 memcpy(info.hook_entry, private->hook_entry,
72390 sizeof(info.hook_entry));
72391diff -urNp linux-2.6.32.44/net/ipv4/netfilter/nf_nat_proto_common.c linux-2.6.32.44/net/ipv4/netfilter/nf_nat_proto_common.c
72392--- linux-2.6.32.44/net/ipv4/netfilter/nf_nat_proto_common.c 2011-03-27 14:31:47.000000000 -0400
72393+++ linux-2.6.32.44/net/ipv4/netfilter/nf_nat_proto_common.c 2011-08-07 19:48:09.000000000 -0400
72394@@ -12,6 +12,7 @@
72395 #include <linux/ip.h>
72396
72397 #include <linux/netfilter.h>
72398+#include <net/secure_seq.h>
72399 #include <net/netfilter/nf_nat.h>
72400 #include <net/netfilter/nf_nat_core.h>
72401 #include <net/netfilter/nf_nat_rule.h>
72402diff -urNp linux-2.6.32.44/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.32.44/net/ipv4/netfilter/nf_nat_snmp_basic.c
72403--- linux-2.6.32.44/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-03-27 14:31:47.000000000 -0400
72404+++ linux-2.6.32.44/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-04-17 15:56:46.000000000 -0400
72405@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(
72406
72407 *len = 0;
72408
72409- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
72410+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
72411 if (*octets == NULL) {
72412 if (net_ratelimit())
72413 printk("OOM in bsalg (%d)\n", __LINE__);
72414diff -urNp linux-2.6.32.44/net/ipv4/raw.c linux-2.6.32.44/net/ipv4/raw.c
72415--- linux-2.6.32.44/net/ipv4/raw.c 2011-03-27 14:31:47.000000000 -0400
72416+++ linux-2.6.32.44/net/ipv4/raw.c 2011-05-04 17:59:08.000000000 -0400
72417@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk,
72418 /* Charge it to the socket. */
72419
72420 if (sock_queue_rcv_skb(sk, skb) < 0) {
72421- atomic_inc(&sk->sk_drops);
72422+ atomic_inc_unchecked(&sk->sk_drops);
72423 kfree_skb(skb);
72424 return NET_RX_DROP;
72425 }
72426@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk,
72427 int raw_rcv(struct sock *sk, struct sk_buff *skb)
72428 {
72429 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
72430- atomic_inc(&sk->sk_drops);
72431+ atomic_inc_unchecked(&sk->sk_drops);
72432 kfree_skb(skb);
72433 return NET_RX_DROP;
72434 }
72435@@ -724,15 +724,22 @@ static int raw_init(struct sock *sk)
72436
72437 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
72438 {
72439+ struct icmp_filter filter;
72440+
72441+ if (optlen < 0)
72442+ return -EINVAL;
72443 if (optlen > sizeof(struct icmp_filter))
72444 optlen = sizeof(struct icmp_filter);
72445- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
72446+ if (copy_from_user(&filter, optval, optlen))
72447 return -EFAULT;
72448+ memcpy(&raw_sk(sk)->filter, &filter, optlen);
72449+
72450 return 0;
72451 }
72452
72453 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
72454 {
72455+ struct icmp_filter filter;
72456 int len, ret = -EFAULT;
72457
72458 if (get_user(len, optlen))
72459@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock
72460 if (len > sizeof(struct icmp_filter))
72461 len = sizeof(struct icmp_filter);
72462 ret = -EFAULT;
72463+ memcpy(&filter, &raw_sk(sk)->filter, len);
72464 if (put_user(len, optlen) ||
72465- copy_to_user(optval, &raw_sk(sk)->filter, len))
72466+ copy_to_user(optval, &filter, len))
72467 goto out;
72468 ret = 0;
72469 out: return ret;
72470@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq
72471 sk_wmem_alloc_get(sp),
72472 sk_rmem_alloc_get(sp),
72473 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
72474- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
72475+ atomic_read(&sp->sk_refcnt),
72476+#ifdef CONFIG_GRKERNSEC_HIDESYM
72477+ NULL,
72478+#else
72479+ sp,
72480+#endif
72481+ atomic_read_unchecked(&sp->sk_drops));
72482 }
72483
72484 static int raw_seq_show(struct seq_file *seq, void *v)
72485diff -urNp linux-2.6.32.44/net/ipv4/route.c linux-2.6.32.44/net/ipv4/route.c
72486--- linux-2.6.32.44/net/ipv4/route.c 2011-03-27 14:31:47.000000000 -0400
72487+++ linux-2.6.32.44/net/ipv4/route.c 2011-08-07 19:48:09.000000000 -0400
72488@@ -107,6 +107,7 @@
72489 #ifdef CONFIG_SYSCTL
72490 #include <linux/sysctl.h>
72491 #endif
72492+#include <net/secure_seq.h>
72493
72494 #define RT_FL_TOS(oldflp) \
72495 ((u32)(oldflp->fl4_tos & (IPTOS_RT_MASK | RTO_ONLINK)))
72496@@ -268,7 +269,7 @@ static inline unsigned int rt_hash(__be3
72497
72498 static inline int rt_genid(struct net *net)
72499 {
72500- return atomic_read(&net->ipv4.rt_genid);
72501+ return atomic_read_unchecked(&net->ipv4.rt_genid);
72502 }
72503
72504 #ifdef CONFIG_PROC_FS
72505@@ -888,7 +889,7 @@ static void rt_cache_invalidate(struct n
72506 unsigned char shuffle;
72507
72508 get_random_bytes(&shuffle, sizeof(shuffle));
72509- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
72510+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
72511 }
72512
72513 /*
72514@@ -3356,7 +3357,7 @@ static __net_initdata struct pernet_oper
72515
72516 static __net_init int rt_secret_timer_init(struct net *net)
72517 {
72518- atomic_set(&net->ipv4.rt_genid,
72519+ atomic_set_unchecked(&net->ipv4.rt_genid,
72520 (int) ((num_physpages ^ (num_physpages>>8)) ^
72521 (jiffies ^ (jiffies >> 7))));
72522
72523diff -urNp linux-2.6.32.44/net/ipv4/tcp.c linux-2.6.32.44/net/ipv4/tcp.c
72524--- linux-2.6.32.44/net/ipv4/tcp.c 2011-03-27 14:31:47.000000000 -0400
72525+++ linux-2.6.32.44/net/ipv4/tcp.c 2011-05-16 21:46:57.000000000 -0400
72526@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock
72527 int val;
72528 int err = 0;
72529
72530+ pax_track_stack();
72531+
72532 /* This is a string value all the others are int's */
72533 if (optname == TCP_CONGESTION) {
72534 char name[TCP_CA_NAME_MAX];
72535@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock
72536 struct tcp_sock *tp = tcp_sk(sk);
72537 int val, len;
72538
72539+ pax_track_stack();
72540+
72541 if (get_user(len, optlen))
72542 return -EFAULT;
72543
72544diff -urNp linux-2.6.32.44/net/ipv4/tcp_ipv4.c linux-2.6.32.44/net/ipv4/tcp_ipv4.c
72545--- linux-2.6.32.44/net/ipv4/tcp_ipv4.c 2011-03-27 14:31:47.000000000 -0400
72546+++ linux-2.6.32.44/net/ipv4/tcp_ipv4.c 2011-08-07 19:48:09.000000000 -0400
72547@@ -71,6 +71,7 @@
72548 #include <net/timewait_sock.h>
72549 #include <net/xfrm.h>
72550 #include <net/netdma.h>
72551+#include <net/secure_seq.h>
72552
72553 #include <linux/inet.h>
72554 #include <linux/ipv6.h>
72555@@ -84,6 +85,9 @@
72556 int sysctl_tcp_tw_reuse __read_mostly;
72557 int sysctl_tcp_low_latency __read_mostly;
72558
72559+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72560+extern int grsec_enable_blackhole;
72561+#endif
72562
72563 #ifdef CONFIG_TCP_MD5SIG
72564 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
72565@@ -1542,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
72566 return 0;
72567
72568 reset:
72569+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72570+ if (!grsec_enable_blackhole)
72571+#endif
72572 tcp_v4_send_reset(rsk, skb);
72573 discard:
72574 kfree_skb(skb);
72575@@ -1603,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
72576 TCP_SKB_CB(skb)->sacked = 0;
72577
72578 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
72579- if (!sk)
72580+ if (!sk) {
72581+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72582+ ret = 1;
72583+#endif
72584 goto no_tcp_socket;
72585+ }
72586
72587 process:
72588- if (sk->sk_state == TCP_TIME_WAIT)
72589+ if (sk->sk_state == TCP_TIME_WAIT) {
72590+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72591+ ret = 2;
72592+#endif
72593 goto do_time_wait;
72594+ }
72595
72596 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
72597 goto discard_and_relse;
72598@@ -1650,6 +1665,10 @@ no_tcp_socket:
72599 bad_packet:
72600 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
72601 } else {
72602+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72603+ if (!grsec_enable_blackhole || (ret == 1 &&
72604+ (skb->dev->flags & IFF_LOOPBACK)))
72605+#endif
72606 tcp_v4_send_reset(NULL, skb);
72607 }
72608
72609@@ -2194,14 +2213,14 @@ int tcp_proc_register(struct net *net, s
72610 int rc = 0;
72611 struct proc_dir_entry *p;
72612
72613- afinfo->seq_fops.open = tcp_seq_open;
72614- afinfo->seq_fops.read = seq_read;
72615- afinfo->seq_fops.llseek = seq_lseek;
72616- afinfo->seq_fops.release = seq_release_net;
72617-
72618- afinfo->seq_ops.start = tcp_seq_start;
72619- afinfo->seq_ops.next = tcp_seq_next;
72620- afinfo->seq_ops.stop = tcp_seq_stop;
72621+ *(void **)&afinfo->seq_fops.open = tcp_seq_open;
72622+ *(void **)&afinfo->seq_fops.read = seq_read;
72623+ *(void **)&afinfo->seq_fops.llseek = seq_lseek;
72624+ *(void **)&afinfo->seq_fops.release = seq_release_net;
72625+
72626+ *(void **)&afinfo->seq_ops.start = tcp_seq_start;
72627+ *(void **)&afinfo->seq_ops.next = tcp_seq_next;
72628+ *(void **)&afinfo->seq_ops.stop = tcp_seq_stop;
72629
72630 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
72631 &afinfo->seq_fops, afinfo);
72632@@ -2237,7 +2256,11 @@ static void get_openreq4(struct sock *sk
72633 0, /* non standard timer */
72634 0, /* open_requests have no inode */
72635 atomic_read(&sk->sk_refcnt),
72636+#ifdef CONFIG_GRKERNSEC_HIDESYM
72637+ NULL,
72638+#else
72639 req,
72640+#endif
72641 len);
72642 }
72643
72644@@ -2279,7 +2302,12 @@ static void get_tcp4_sock(struct sock *s
72645 sock_i_uid(sk),
72646 icsk->icsk_probes_out,
72647 sock_i_ino(sk),
72648- atomic_read(&sk->sk_refcnt), sk,
72649+ atomic_read(&sk->sk_refcnt),
72650+#ifdef CONFIG_GRKERNSEC_HIDESYM
72651+ NULL,
72652+#else
72653+ sk,
72654+#endif
72655 jiffies_to_clock_t(icsk->icsk_rto),
72656 jiffies_to_clock_t(icsk->icsk_ack.ato),
72657 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
72658@@ -2307,7 +2335,13 @@ static void get_timewait4_sock(struct in
72659 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
72660 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
72661 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
72662- atomic_read(&tw->tw_refcnt), tw, len);
72663+ atomic_read(&tw->tw_refcnt),
72664+#ifdef CONFIG_GRKERNSEC_HIDESYM
72665+ NULL,
72666+#else
72667+ tw,
72668+#endif
72669+ len);
72670 }
72671
72672 #define TMPSZ 150
72673diff -urNp linux-2.6.32.44/net/ipv4/tcp_minisocks.c linux-2.6.32.44/net/ipv4/tcp_minisocks.c
72674--- linux-2.6.32.44/net/ipv4/tcp_minisocks.c 2011-03-27 14:31:47.000000000 -0400
72675+++ linux-2.6.32.44/net/ipv4/tcp_minisocks.c 2011-04-17 15:56:46.000000000 -0400
72676@@ -26,6 +26,10 @@
72677 #include <net/inet_common.h>
72678 #include <net/xfrm.h>
72679
72680+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72681+extern int grsec_enable_blackhole;
72682+#endif
72683+
72684 #ifdef CONFIG_SYSCTL
72685 #define SYNC_INIT 0 /* let the user enable it */
72686 #else
72687@@ -672,6 +676,10 @@ listen_overflow:
72688
72689 embryonic_reset:
72690 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
72691+
72692+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72693+ if (!grsec_enable_blackhole)
72694+#endif
72695 if (!(flg & TCP_FLAG_RST))
72696 req->rsk_ops->send_reset(sk, skb);
72697
72698diff -urNp linux-2.6.32.44/net/ipv4/tcp_output.c linux-2.6.32.44/net/ipv4/tcp_output.c
72699--- linux-2.6.32.44/net/ipv4/tcp_output.c 2011-03-27 14:31:47.000000000 -0400
72700+++ linux-2.6.32.44/net/ipv4/tcp_output.c 2011-05-16 21:46:57.000000000 -0400
72701@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct s
72702 __u8 *md5_hash_location;
72703 int mss;
72704
72705+ pax_track_stack();
72706+
72707 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
72708 if (skb == NULL)
72709 return NULL;
72710diff -urNp linux-2.6.32.44/net/ipv4/tcp_probe.c linux-2.6.32.44/net/ipv4/tcp_probe.c
72711--- linux-2.6.32.44/net/ipv4/tcp_probe.c 2011-03-27 14:31:47.000000000 -0400
72712+++ linux-2.6.32.44/net/ipv4/tcp_probe.c 2011-04-17 15:56:46.000000000 -0400
72713@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file
72714 if (cnt + width >= len)
72715 break;
72716
72717- if (copy_to_user(buf + cnt, tbuf, width))
72718+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
72719 return -EFAULT;
72720 cnt += width;
72721 }
72722diff -urNp linux-2.6.32.44/net/ipv4/tcp_timer.c linux-2.6.32.44/net/ipv4/tcp_timer.c
72723--- linux-2.6.32.44/net/ipv4/tcp_timer.c 2011-03-27 14:31:47.000000000 -0400
72724+++ linux-2.6.32.44/net/ipv4/tcp_timer.c 2011-04-17 15:56:46.000000000 -0400
72725@@ -21,6 +21,10 @@
72726 #include <linux/module.h>
72727 #include <net/tcp.h>
72728
72729+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72730+extern int grsec_lastack_retries;
72731+#endif
72732+
72733 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
72734 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
72735 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
72736@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock
72737 }
72738 }
72739
72740+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72741+ if ((sk->sk_state == TCP_LAST_ACK) &&
72742+ (grsec_lastack_retries > 0) &&
72743+ (grsec_lastack_retries < retry_until))
72744+ retry_until = grsec_lastack_retries;
72745+#endif
72746+
72747 if (retransmits_timed_out(sk, retry_until)) {
72748 /* Has it gone just too far? */
72749 tcp_write_err(sk);
72750diff -urNp linux-2.6.32.44/net/ipv4/udp.c linux-2.6.32.44/net/ipv4/udp.c
72751--- linux-2.6.32.44/net/ipv4/udp.c 2011-07-13 17:23:04.000000000 -0400
72752+++ linux-2.6.32.44/net/ipv4/udp.c 2011-08-05 20:33:55.000000000 -0400
72753@@ -86,6 +86,7 @@
72754 #include <linux/types.h>
72755 #include <linux/fcntl.h>
72756 #include <linux/module.h>
72757+#include <linux/security.h>
72758 #include <linux/socket.h>
72759 #include <linux/sockios.h>
72760 #include <linux/igmp.h>
72761@@ -106,6 +107,10 @@
72762 #include <net/xfrm.h>
72763 #include "udp_impl.h"
72764
72765+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72766+extern int grsec_enable_blackhole;
72767+#endif
72768+
72769 struct udp_table udp_table;
72770 EXPORT_SYMBOL(udp_table);
72771
72772@@ -371,6 +376,9 @@ found:
72773 return s;
72774 }
72775
72776+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
72777+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
72778+
72779 /*
72780 * This routine is called by the ICMP module when it gets some
72781 * sort of error condition. If err < 0 then the socket should
72782@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
72783 dport = usin->sin_port;
72784 if (dport == 0)
72785 return -EINVAL;
72786+
72787+ err = gr_search_udp_sendmsg(sk, usin);
72788+ if (err)
72789+ return err;
72790 } else {
72791 if (sk->sk_state != TCP_ESTABLISHED)
72792 return -EDESTADDRREQ;
72793+
72794+ err = gr_search_udp_sendmsg(sk, NULL);
72795+ if (err)
72796+ return err;
72797+
72798 daddr = inet->daddr;
72799 dport = inet->dport;
72800 /* Open fast path for connected socket.
72801@@ -945,6 +962,10 @@ try_again:
72802 if (!skb)
72803 goto out;
72804
72805+ err = gr_search_udp_recvmsg(sk, skb);
72806+ if (err)
72807+ goto out_free;
72808+
72809 ulen = skb->len - sizeof(struct udphdr);
72810 copied = len;
72811 if (copied > ulen)
72812@@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct so
72813 if (rc == -ENOMEM) {
72814 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
72815 is_udplite);
72816- atomic_inc(&sk->sk_drops);
72817+ atomic_inc_unchecked(&sk->sk_drops);
72818 }
72819 goto drop;
72820 }
72821@@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
72822 goto csum_error;
72823
72824 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
72825+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72826+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
72827+#endif
72828 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
72829
72830 /*
72831@@ -1719,14 +1743,14 @@ int udp_proc_register(struct net *net, s
72832 struct proc_dir_entry *p;
72833 int rc = 0;
72834
72835- afinfo->seq_fops.open = udp_seq_open;
72836- afinfo->seq_fops.read = seq_read;
72837- afinfo->seq_fops.llseek = seq_lseek;
72838- afinfo->seq_fops.release = seq_release_net;
72839-
72840- afinfo->seq_ops.start = udp_seq_start;
72841- afinfo->seq_ops.next = udp_seq_next;
72842- afinfo->seq_ops.stop = udp_seq_stop;
72843+ *(void **)&afinfo->seq_fops.open = udp_seq_open;
72844+ *(void **)&afinfo->seq_fops.read = seq_read;
72845+ *(void **)&afinfo->seq_fops.llseek = seq_lseek;
72846+ *(void **)&afinfo->seq_fops.release = seq_release_net;
72847+
72848+ *(void **)&afinfo->seq_ops.start = udp_seq_start;
72849+ *(void **)&afinfo->seq_ops.next = udp_seq_next;
72850+ *(void **)&afinfo->seq_ops.stop = udp_seq_stop;
72851
72852 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
72853 &afinfo->seq_fops, afinfo);
72854@@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock
72855 sk_wmem_alloc_get(sp),
72856 sk_rmem_alloc_get(sp),
72857 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
72858- atomic_read(&sp->sk_refcnt), sp,
72859- atomic_read(&sp->sk_drops), len);
72860+ atomic_read(&sp->sk_refcnt),
72861+#ifdef CONFIG_GRKERNSEC_HIDESYM
72862+ NULL,
72863+#else
72864+ sp,
72865+#endif
72866+ atomic_read_unchecked(&sp->sk_drops), len);
72867 }
72868
72869 int udp4_seq_show(struct seq_file *seq, void *v)
72870diff -urNp linux-2.6.32.44/net/ipv6/inet6_connection_sock.c linux-2.6.32.44/net/ipv6/inet6_connection_sock.c
72871--- linux-2.6.32.44/net/ipv6/inet6_connection_sock.c 2011-03-27 14:31:47.000000000 -0400
72872+++ linux-2.6.32.44/net/ipv6/inet6_connection_sock.c 2011-05-04 17:56:28.000000000 -0400
72873@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *
72874 #ifdef CONFIG_XFRM
72875 {
72876 struct rt6_info *rt = (struct rt6_info *)dst;
72877- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
72878+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
72879 }
72880 #endif
72881 }
72882@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(
72883 #ifdef CONFIG_XFRM
72884 if (dst) {
72885 struct rt6_info *rt = (struct rt6_info *)dst;
72886- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
72887+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
72888 sk->sk_dst_cache = NULL;
72889 dst_release(dst);
72890 dst = NULL;
72891diff -urNp linux-2.6.32.44/net/ipv6/inet6_hashtables.c linux-2.6.32.44/net/ipv6/inet6_hashtables.c
72892--- linux-2.6.32.44/net/ipv6/inet6_hashtables.c 2011-03-27 14:31:47.000000000 -0400
72893+++ linux-2.6.32.44/net/ipv6/inet6_hashtables.c 2011-08-07 19:48:09.000000000 -0400
72894@@ -20,6 +20,7 @@
72895 #include <net/inet_connection_sock.h>
72896 #include <net/inet_hashtables.h>
72897 #include <net/inet6_hashtables.h>
72898+#include <net/secure_seq.h>
72899 #include <net/ip.h>
72900
72901 void __inet6_hash(struct sock *sk)
72902@@ -118,7 +119,7 @@ out:
72903 }
72904 EXPORT_SYMBOL(__inet6_lookup_established);
72905
72906-static int inline compute_score(struct sock *sk, struct net *net,
72907+static inline int compute_score(struct sock *sk, struct net *net,
72908 const unsigned short hnum,
72909 const struct in6_addr *daddr,
72910 const int dif)
72911diff -urNp linux-2.6.32.44/net/ipv6/ipv6_sockglue.c linux-2.6.32.44/net/ipv6/ipv6_sockglue.c
72912--- linux-2.6.32.44/net/ipv6/ipv6_sockglue.c 2011-03-27 14:31:47.000000000 -0400
72913+++ linux-2.6.32.44/net/ipv6/ipv6_sockglue.c 2011-05-16 21:46:57.000000000 -0400
72914@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct soc
72915 int val, valbool;
72916 int retv = -ENOPROTOOPT;
72917
72918+ pax_track_stack();
72919+
72920 if (optval == NULL)
72921 val=0;
72922 else {
72923@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct soc
72924 int len;
72925 int val;
72926
72927+ pax_track_stack();
72928+
72929 if (ip6_mroute_opt(optname))
72930 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
72931
72932diff -urNp linux-2.6.32.44/net/ipv6/netfilter/ip6_tables.c linux-2.6.32.44/net/ipv6/netfilter/ip6_tables.c
72933--- linux-2.6.32.44/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:00:52.000000000 -0400
72934+++ linux-2.6.32.44/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:04:18.000000000 -0400
72935@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, voi
72936 private = &tmp;
72937 }
72938 #endif
72939+ memset(&info, 0, sizeof(info));
72940 info.valid_hooks = t->valid_hooks;
72941 memcpy(info.hook_entry, private->hook_entry,
72942 sizeof(info.hook_entry));
72943diff -urNp linux-2.6.32.44/net/ipv6/raw.c linux-2.6.32.44/net/ipv6/raw.c
72944--- linux-2.6.32.44/net/ipv6/raw.c 2011-03-27 14:31:47.000000000 -0400
72945+++ linux-2.6.32.44/net/ipv6/raw.c 2011-05-16 21:46:57.000000000 -0400
72946@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct s
72947 {
72948 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
72949 skb_checksum_complete(skb)) {
72950- atomic_inc(&sk->sk_drops);
72951+ atomic_inc_unchecked(&sk->sk_drops);
72952 kfree_skb(skb);
72953 return NET_RX_DROP;
72954 }
72955
72956 /* Charge it to the socket. */
72957 if (sock_queue_rcv_skb(sk,skb)<0) {
72958- atomic_inc(&sk->sk_drops);
72959+ atomic_inc_unchecked(&sk->sk_drops);
72960 kfree_skb(skb);
72961 return NET_RX_DROP;
72962 }
72963@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
72964 struct raw6_sock *rp = raw6_sk(sk);
72965
72966 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
72967- atomic_inc(&sk->sk_drops);
72968+ atomic_inc_unchecked(&sk->sk_drops);
72969 kfree_skb(skb);
72970 return NET_RX_DROP;
72971 }
72972@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
72973
72974 if (inet->hdrincl) {
72975 if (skb_checksum_complete(skb)) {
72976- atomic_inc(&sk->sk_drops);
72977+ atomic_inc_unchecked(&sk->sk_drops);
72978 kfree_skb(skb);
72979 return NET_RX_DROP;
72980 }
72981@@ -518,7 +518,7 @@ csum_copy_err:
72982 as some normal condition.
72983 */
72984 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
72985- atomic_inc(&sk->sk_drops);
72986+ atomic_inc_unchecked(&sk->sk_drops);
72987 goto out;
72988 }
72989
72990@@ -600,7 +600,7 @@ out:
72991 return err;
72992 }
72993
72994-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
72995+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
72996 struct flowi *fl, struct rt6_info *rt,
72997 unsigned int flags)
72998 {
72999@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *i
73000 u16 proto;
73001 int err;
73002
73003+ pax_track_stack();
73004+
73005 /* Rough check on arithmetic overflow,
73006 better check is made in ip6_append_data().
73007 */
73008@@ -916,12 +918,17 @@ do_confirm:
73009 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
73010 char __user *optval, int optlen)
73011 {
73012+ struct icmp6_filter filter;
73013+
73014 switch (optname) {
73015 case ICMPV6_FILTER:
73016+ if (optlen < 0)
73017+ return -EINVAL;
73018 if (optlen > sizeof(struct icmp6_filter))
73019 optlen = sizeof(struct icmp6_filter);
73020- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
73021+ if (copy_from_user(&filter, optval, optlen))
73022 return -EFAULT;
73023+ memcpy(&raw6_sk(sk)->filter, &filter, optlen);
73024 return 0;
73025 default:
73026 return -ENOPROTOOPT;
73027@@ -933,6 +940,7 @@ static int rawv6_seticmpfilter(struct so
73028 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73029 char __user *optval, int __user *optlen)
73030 {
73031+ struct icmp6_filter filter;
73032 int len;
73033
73034 switch (optname) {
73035@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct so
73036 len = sizeof(struct icmp6_filter);
73037 if (put_user(len, optlen))
73038 return -EFAULT;
73039- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
73040+ memcpy(&filter, &raw6_sk(sk)->filter, len);
73041+ if (copy_to_user(optval, &filter, len))
73042 return -EFAULT;
73043 return 0;
73044 default:
73045@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct se
73046 0, 0L, 0,
73047 sock_i_uid(sp), 0,
73048 sock_i_ino(sp),
73049- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73050+ atomic_read(&sp->sk_refcnt),
73051+#ifdef CONFIG_GRKERNSEC_HIDESYM
73052+ NULL,
73053+#else
73054+ sp,
73055+#endif
73056+ atomic_read_unchecked(&sp->sk_drops));
73057 }
73058
73059 static int raw6_seq_show(struct seq_file *seq, void *v)
73060diff -urNp linux-2.6.32.44/net/ipv6/tcp_ipv6.c linux-2.6.32.44/net/ipv6/tcp_ipv6.c
73061--- linux-2.6.32.44/net/ipv6/tcp_ipv6.c 2011-03-27 14:31:47.000000000 -0400
73062+++ linux-2.6.32.44/net/ipv6/tcp_ipv6.c 2011-08-07 19:48:09.000000000 -0400
73063@@ -60,6 +60,7 @@
73064 #include <net/timewait_sock.h>
73065 #include <net/netdma.h>
73066 #include <net/inet_common.h>
73067+#include <net/secure_seq.h>
73068
73069 #include <asm/uaccess.h>
73070
73071@@ -88,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
73072 }
73073 #endif
73074
73075+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73076+extern int grsec_enable_blackhole;
73077+#endif
73078+
73079 static void tcp_v6_hash(struct sock *sk)
73080 {
73081 if (sk->sk_state != TCP_CLOSE) {
73082@@ -1578,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk
73083 return 0;
73084
73085 reset:
73086+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73087+ if (!grsec_enable_blackhole)
73088+#endif
73089 tcp_v6_send_reset(sk, skb);
73090 discard:
73091 if (opt_skb)
73092@@ -1655,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
73093 TCP_SKB_CB(skb)->sacked = 0;
73094
73095 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73096- if (!sk)
73097+ if (!sk) {
73098+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73099+ ret = 1;
73100+#endif
73101 goto no_tcp_socket;
73102+ }
73103
73104 process:
73105- if (sk->sk_state == TCP_TIME_WAIT)
73106+ if (sk->sk_state == TCP_TIME_WAIT) {
73107+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73108+ ret = 2;
73109+#endif
73110 goto do_time_wait;
73111+ }
73112
73113 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
73114 goto discard_and_relse;
73115@@ -1700,6 +1716,10 @@ no_tcp_socket:
73116 bad_packet:
73117 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73118 } else {
73119+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73120+ if (!grsec_enable_blackhole || (ret == 1 &&
73121+ (skb->dev->flags & IFF_LOOPBACK)))
73122+#endif
73123 tcp_v6_send_reset(NULL, skb);
73124 }
73125
73126@@ -1915,7 +1935,13 @@ static void get_openreq6(struct seq_file
73127 uid,
73128 0, /* non standard timer */
73129 0, /* open_requests have no inode */
73130- 0, req);
73131+ 0,
73132+#ifdef CONFIG_GRKERNSEC_HIDESYM
73133+ NULL
73134+#else
73135+ req
73136+#endif
73137+ );
73138 }
73139
73140 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73141@@ -1965,7 +1991,12 @@ static void get_tcp6_sock(struct seq_fil
73142 sock_i_uid(sp),
73143 icsk->icsk_probes_out,
73144 sock_i_ino(sp),
73145- atomic_read(&sp->sk_refcnt), sp,
73146+ atomic_read(&sp->sk_refcnt),
73147+#ifdef CONFIG_GRKERNSEC_HIDESYM
73148+ NULL,
73149+#else
73150+ sp,
73151+#endif
73152 jiffies_to_clock_t(icsk->icsk_rto),
73153 jiffies_to_clock_t(icsk->icsk_ack.ato),
73154 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
73155@@ -2000,7 +2031,13 @@ static void get_timewait6_sock(struct se
73156 dest->s6_addr32[2], dest->s6_addr32[3], destp,
73157 tw->tw_substate, 0, 0,
73158 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73159- atomic_read(&tw->tw_refcnt), tw);
73160+ atomic_read(&tw->tw_refcnt),
73161+#ifdef CONFIG_GRKERNSEC_HIDESYM
73162+ NULL
73163+#else
73164+ tw
73165+#endif
73166+ );
73167 }
73168
73169 static int tcp6_seq_show(struct seq_file *seq, void *v)
73170diff -urNp linux-2.6.32.44/net/ipv6/udp.c linux-2.6.32.44/net/ipv6/udp.c
73171--- linux-2.6.32.44/net/ipv6/udp.c 2011-07-13 17:23:04.000000000 -0400
73172+++ linux-2.6.32.44/net/ipv6/udp.c 2011-07-13 17:23:27.000000000 -0400
73173@@ -49,6 +49,10 @@
73174 #include <linux/seq_file.h>
73175 #include "udp_impl.h"
73176
73177+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73178+extern int grsec_enable_blackhole;
73179+#endif
73180+
73181 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
73182 {
73183 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
73184@@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
73185 if (rc == -ENOMEM) {
73186 UDP6_INC_STATS_BH(sock_net(sk),
73187 UDP_MIB_RCVBUFERRORS, is_udplite);
73188- atomic_inc(&sk->sk_drops);
73189+ atomic_inc_unchecked(&sk->sk_drops);
73190 }
73191 goto drop;
73192 }
73193@@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
73194 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
73195 proto == IPPROTO_UDPLITE);
73196
73197+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73198+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73199+#endif
73200 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
73201
73202 kfree_skb(skb);
73203@@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct se
73204 0, 0L, 0,
73205 sock_i_uid(sp), 0,
73206 sock_i_ino(sp),
73207- atomic_read(&sp->sk_refcnt), sp,
73208- atomic_read(&sp->sk_drops));
73209+ atomic_read(&sp->sk_refcnt),
73210+#ifdef CONFIG_GRKERNSEC_HIDESYM
73211+ NULL,
73212+#else
73213+ sp,
73214+#endif
73215+ atomic_read_unchecked(&sp->sk_drops));
73216 }
73217
73218 int udp6_seq_show(struct seq_file *seq, void *v)
73219diff -urNp linux-2.6.32.44/net/irda/ircomm/ircomm_tty.c linux-2.6.32.44/net/irda/ircomm/ircomm_tty.c
73220--- linux-2.6.32.44/net/irda/ircomm/ircomm_tty.c 2011-03-27 14:31:47.000000000 -0400
73221+++ linux-2.6.32.44/net/irda/ircomm/ircomm_tty.c 2011-04-17 15:56:46.000000000 -0400
73222@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(st
73223 add_wait_queue(&self->open_wait, &wait);
73224
73225 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
73226- __FILE__,__LINE__, tty->driver->name, self->open_count );
73227+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73228
73229 /* As far as I can see, we protect open_count - Jean II */
73230 spin_lock_irqsave(&self->spinlock, flags);
73231 if (!tty_hung_up_p(filp)) {
73232 extra_count = 1;
73233- self->open_count--;
73234+ local_dec(&self->open_count);
73235 }
73236 spin_unlock_irqrestore(&self->spinlock, flags);
73237- self->blocked_open++;
73238+ local_inc(&self->blocked_open);
73239
73240 while (1) {
73241 if (tty->termios->c_cflag & CBAUD) {
73242@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(st
73243 }
73244
73245 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
73246- __FILE__,__LINE__, tty->driver->name, self->open_count );
73247+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73248
73249 schedule();
73250 }
73251@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(st
73252 if (extra_count) {
73253 /* ++ is not atomic, so this should be protected - Jean II */
73254 spin_lock_irqsave(&self->spinlock, flags);
73255- self->open_count++;
73256+ local_inc(&self->open_count);
73257 spin_unlock_irqrestore(&self->spinlock, flags);
73258 }
73259- self->blocked_open--;
73260+ local_dec(&self->blocked_open);
73261
73262 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
73263- __FILE__,__LINE__, tty->driver->name, self->open_count);
73264+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
73265
73266 if (!retval)
73267 self->flags |= ASYNC_NORMAL_ACTIVE;
73268@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_st
73269 }
73270 /* ++ is not atomic, so this should be protected - Jean II */
73271 spin_lock_irqsave(&self->spinlock, flags);
73272- self->open_count++;
73273+ local_inc(&self->open_count);
73274
73275 tty->driver_data = self;
73276 self->tty = tty;
73277 spin_unlock_irqrestore(&self->spinlock, flags);
73278
73279 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
73280- self->line, self->open_count);
73281+ self->line, local_read(&self->open_count));
73282
73283 /* Not really used by us, but lets do it anyway */
73284 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
73285@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_
73286 return;
73287 }
73288
73289- if ((tty->count == 1) && (self->open_count != 1)) {
73290+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
73291 /*
73292 * Uh, oh. tty->count is 1, which means that the tty
73293 * structure will be freed. state->count should always
73294@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_
73295 */
73296 IRDA_DEBUG(0, "%s(), bad serial port count; "
73297 "tty->count is 1, state->count is %d\n", __func__ ,
73298- self->open_count);
73299- self->open_count = 1;
73300+ local_read(&self->open_count));
73301+ local_set(&self->open_count, 1);
73302 }
73303
73304- if (--self->open_count < 0) {
73305+ if (local_dec_return(&self->open_count) < 0) {
73306 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
73307- __func__, self->line, self->open_count);
73308- self->open_count = 0;
73309+ __func__, self->line, local_read(&self->open_count));
73310+ local_set(&self->open_count, 0);
73311 }
73312- if (self->open_count) {
73313+ if (local_read(&self->open_count)) {
73314 spin_unlock_irqrestore(&self->spinlock, flags);
73315
73316 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
73317@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_
73318 tty->closing = 0;
73319 self->tty = NULL;
73320
73321- if (self->blocked_open) {
73322+ if (local_read(&self->blocked_open)) {
73323 if (self->close_delay)
73324 schedule_timeout_interruptible(self->close_delay);
73325 wake_up_interruptible(&self->open_wait);
73326@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty
73327 spin_lock_irqsave(&self->spinlock, flags);
73328 self->flags &= ~ASYNC_NORMAL_ACTIVE;
73329 self->tty = NULL;
73330- self->open_count = 0;
73331+ local_set(&self->open_count, 0);
73332 spin_unlock_irqrestore(&self->spinlock, flags);
73333
73334 wake_up_interruptible(&self->open_wait);
73335@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct
73336 seq_putc(m, '\n');
73337
73338 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
73339- seq_printf(m, "Open count: %d\n", self->open_count);
73340+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
73341 seq_printf(m, "Max data size: %d\n", self->max_data_size);
73342 seq_printf(m, "Max header size: %d\n", self->max_header_size);
73343
73344diff -urNp linux-2.6.32.44/net/iucv/af_iucv.c linux-2.6.32.44/net/iucv/af_iucv.c
73345--- linux-2.6.32.44/net/iucv/af_iucv.c 2011-03-27 14:31:47.000000000 -0400
73346+++ linux-2.6.32.44/net/iucv/af_iucv.c 2011-05-04 17:56:28.000000000 -0400
73347@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct soc
73348
73349 write_lock_bh(&iucv_sk_list.lock);
73350
73351- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
73352+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
73353 while (__iucv_get_sock_by_name(name)) {
73354 sprintf(name, "%08x",
73355- atomic_inc_return(&iucv_sk_list.autobind_name));
73356+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
73357 }
73358
73359 write_unlock_bh(&iucv_sk_list.lock);
73360diff -urNp linux-2.6.32.44/net/key/af_key.c linux-2.6.32.44/net/key/af_key.c
73361--- linux-2.6.32.44/net/key/af_key.c 2011-03-27 14:31:47.000000000 -0400
73362+++ linux-2.6.32.44/net/key/af_key.c 2011-05-16 21:46:57.000000000 -0400
73363@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk
73364 struct xfrm_migrate m[XFRM_MAX_DEPTH];
73365 struct xfrm_kmaddress k;
73366
73367+ pax_track_stack();
73368+
73369 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
73370 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
73371 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
73372@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_fil
73373 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
73374 else
73375 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
73376+#ifdef CONFIG_GRKERNSEC_HIDESYM
73377+ NULL,
73378+#else
73379 s,
73380+#endif
73381 atomic_read(&s->sk_refcnt),
73382 sk_rmem_alloc_get(s),
73383 sk_wmem_alloc_get(s),
73384diff -urNp linux-2.6.32.44/net/lapb/lapb_iface.c linux-2.6.32.44/net/lapb/lapb_iface.c
73385--- linux-2.6.32.44/net/lapb/lapb_iface.c 2011-03-27 14:31:47.000000000 -0400
73386+++ linux-2.6.32.44/net/lapb/lapb_iface.c 2011-08-05 20:33:55.000000000 -0400
73387@@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev
73388 goto out;
73389
73390 lapb->dev = dev;
73391- lapb->callbacks = *callbacks;
73392+ lapb->callbacks = callbacks;
73393
73394 __lapb_insert_cb(lapb);
73395
73396@@ -379,32 +379,32 @@ int lapb_data_received(struct net_device
73397
73398 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
73399 {
73400- if (lapb->callbacks.connect_confirmation)
73401- lapb->callbacks.connect_confirmation(lapb->dev, reason);
73402+ if (lapb->callbacks->connect_confirmation)
73403+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
73404 }
73405
73406 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
73407 {
73408- if (lapb->callbacks.connect_indication)
73409- lapb->callbacks.connect_indication(lapb->dev, reason);
73410+ if (lapb->callbacks->connect_indication)
73411+ lapb->callbacks->connect_indication(lapb->dev, reason);
73412 }
73413
73414 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
73415 {
73416- if (lapb->callbacks.disconnect_confirmation)
73417- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
73418+ if (lapb->callbacks->disconnect_confirmation)
73419+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
73420 }
73421
73422 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
73423 {
73424- if (lapb->callbacks.disconnect_indication)
73425- lapb->callbacks.disconnect_indication(lapb->dev, reason);
73426+ if (lapb->callbacks->disconnect_indication)
73427+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
73428 }
73429
73430 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
73431 {
73432- if (lapb->callbacks.data_indication)
73433- return lapb->callbacks.data_indication(lapb->dev, skb);
73434+ if (lapb->callbacks->data_indication)
73435+ return lapb->callbacks->data_indication(lapb->dev, skb);
73436
73437 kfree_skb(skb);
73438 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
73439@@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *l
73440 {
73441 int used = 0;
73442
73443- if (lapb->callbacks.data_transmit) {
73444- lapb->callbacks.data_transmit(lapb->dev, skb);
73445+ if (lapb->callbacks->data_transmit) {
73446+ lapb->callbacks->data_transmit(lapb->dev, skb);
73447 used = 1;
73448 }
73449
73450diff -urNp linux-2.6.32.44/net/mac80211/cfg.c linux-2.6.32.44/net/mac80211/cfg.c
73451--- linux-2.6.32.44/net/mac80211/cfg.c 2011-03-27 14:31:47.000000000 -0400
73452+++ linux-2.6.32.44/net/mac80211/cfg.c 2011-04-17 15:56:46.000000000 -0400
73453@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(st
73454 return err;
73455 }
73456
73457-struct cfg80211_ops mac80211_config_ops = {
73458+const struct cfg80211_ops mac80211_config_ops = {
73459 .add_virtual_intf = ieee80211_add_iface,
73460 .del_virtual_intf = ieee80211_del_iface,
73461 .change_virtual_intf = ieee80211_change_iface,
73462diff -urNp linux-2.6.32.44/net/mac80211/cfg.h linux-2.6.32.44/net/mac80211/cfg.h
73463--- linux-2.6.32.44/net/mac80211/cfg.h 2011-03-27 14:31:47.000000000 -0400
73464+++ linux-2.6.32.44/net/mac80211/cfg.h 2011-04-17 15:56:46.000000000 -0400
73465@@ -4,6 +4,6 @@
73466 #ifndef __CFG_H
73467 #define __CFG_H
73468
73469-extern struct cfg80211_ops mac80211_config_ops;
73470+extern const struct cfg80211_ops mac80211_config_ops;
73471
73472 #endif /* __CFG_H */
73473diff -urNp linux-2.6.32.44/net/mac80211/debugfs_key.c linux-2.6.32.44/net/mac80211/debugfs_key.c
73474--- linux-2.6.32.44/net/mac80211/debugfs_key.c 2011-03-27 14:31:47.000000000 -0400
73475+++ linux-2.6.32.44/net/mac80211/debugfs_key.c 2011-04-17 15:56:46.000000000 -0400
73476@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file
73477 size_t count, loff_t *ppos)
73478 {
73479 struct ieee80211_key *key = file->private_data;
73480- int i, res, bufsize = 2 * key->conf.keylen + 2;
73481+ int i, bufsize = 2 * key->conf.keylen + 2;
73482 char *buf = kmalloc(bufsize, GFP_KERNEL);
73483 char *p = buf;
73484+ ssize_t res;
73485+
73486+ if (buf == NULL)
73487+ return -ENOMEM;
73488
73489 for (i = 0; i < key->conf.keylen; i++)
73490 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
73491diff -urNp linux-2.6.32.44/net/mac80211/debugfs_sta.c linux-2.6.32.44/net/mac80211/debugfs_sta.c
73492--- linux-2.6.32.44/net/mac80211/debugfs_sta.c 2011-03-27 14:31:47.000000000 -0400
73493+++ linux-2.6.32.44/net/mac80211/debugfs_sta.c 2011-05-16 21:46:57.000000000 -0400
73494@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struc
73495 int i;
73496 struct sta_info *sta = file->private_data;
73497
73498+ pax_track_stack();
73499+
73500 spin_lock_bh(&sta->lock);
73501 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
73502 sta->ampdu_mlme.dialog_token_allocator + 1);
73503diff -urNp linux-2.6.32.44/net/mac80211/ieee80211_i.h linux-2.6.32.44/net/mac80211/ieee80211_i.h
73504--- linux-2.6.32.44/net/mac80211/ieee80211_i.h 2011-03-27 14:31:47.000000000 -0400
73505+++ linux-2.6.32.44/net/mac80211/ieee80211_i.h 2011-04-17 15:56:46.000000000 -0400
73506@@ -25,6 +25,7 @@
73507 #include <linux/etherdevice.h>
73508 #include <net/cfg80211.h>
73509 #include <net/mac80211.h>
73510+#include <asm/local.h>
73511 #include "key.h"
73512 #include "sta_info.h"
73513
73514@@ -635,7 +636,7 @@ struct ieee80211_local {
73515 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
73516 spinlock_t queue_stop_reason_lock;
73517
73518- int open_count;
73519+ local_t open_count;
73520 int monitors, cooked_mntrs;
73521 /* number of interfaces with corresponding FIF_ flags */
73522 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
73523diff -urNp linux-2.6.32.44/net/mac80211/iface.c linux-2.6.32.44/net/mac80211/iface.c
73524--- linux-2.6.32.44/net/mac80211/iface.c 2011-03-27 14:31:47.000000000 -0400
73525+++ linux-2.6.32.44/net/mac80211/iface.c 2011-04-17 15:56:46.000000000 -0400
73526@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_dev
73527 break;
73528 }
73529
73530- if (local->open_count == 0) {
73531+ if (local_read(&local->open_count) == 0) {
73532 res = drv_start(local);
73533 if (res)
73534 goto err_del_bss;
73535@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_dev
73536 * Validate the MAC address for this device.
73537 */
73538 if (!is_valid_ether_addr(dev->dev_addr)) {
73539- if (!local->open_count)
73540+ if (!local_read(&local->open_count))
73541 drv_stop(local);
73542 return -EADDRNOTAVAIL;
73543 }
73544@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_dev
73545
73546 hw_reconf_flags |= __ieee80211_recalc_idle(local);
73547
73548- local->open_count++;
73549+ local_inc(&local->open_count);
73550 if (hw_reconf_flags) {
73551 ieee80211_hw_config(local, hw_reconf_flags);
73552 /*
73553@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_dev
73554 err_del_interface:
73555 drv_remove_interface(local, &conf);
73556 err_stop:
73557- if (!local->open_count)
73558+ if (!local_read(&local->open_count))
73559 drv_stop(local);
73560 err_del_bss:
73561 sdata->bss = NULL;
73562@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_dev
73563 WARN_ON(!list_empty(&sdata->u.ap.vlans));
73564 }
73565
73566- local->open_count--;
73567+ local_dec(&local->open_count);
73568
73569 switch (sdata->vif.type) {
73570 case NL80211_IFTYPE_AP_VLAN:
73571@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_dev
73572
73573 ieee80211_recalc_ps(local, -1);
73574
73575- if (local->open_count == 0) {
73576+ if (local_read(&local->open_count) == 0) {
73577 ieee80211_clear_tx_pending(local);
73578 ieee80211_stop_device(local);
73579
73580diff -urNp linux-2.6.32.44/net/mac80211/main.c linux-2.6.32.44/net/mac80211/main.c
73581--- linux-2.6.32.44/net/mac80211/main.c 2011-05-10 22:12:02.000000000 -0400
73582+++ linux-2.6.32.44/net/mac80211/main.c 2011-05-10 22:12:34.000000000 -0400
73583@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211
73584 local->hw.conf.power_level = power;
73585 }
73586
73587- if (changed && local->open_count) {
73588+ if (changed && local_read(&local->open_count)) {
73589 ret = drv_config(local, changed);
73590 /*
73591 * Goal:
73592diff -urNp linux-2.6.32.44/net/mac80211/mlme.c linux-2.6.32.44/net/mac80211/mlme.c
73593--- linux-2.6.32.44/net/mac80211/mlme.c 2011-08-09 18:35:30.000000000 -0400
73594+++ linux-2.6.32.44/net/mac80211/mlme.c 2011-08-09 18:34:01.000000000 -0400
73595@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
73596 bool have_higher_than_11mbit = false, newsta = false;
73597 u16 ap_ht_cap_flags;
73598
73599+ pax_track_stack();
73600+
73601 /*
73602 * AssocResp and ReassocResp have identical structure, so process both
73603 * of them in this function.
73604diff -urNp linux-2.6.32.44/net/mac80211/pm.c linux-2.6.32.44/net/mac80211/pm.c
73605--- linux-2.6.32.44/net/mac80211/pm.c 2011-03-27 14:31:47.000000000 -0400
73606+++ linux-2.6.32.44/net/mac80211/pm.c 2011-04-17 15:56:46.000000000 -0400
73607@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211
73608 }
73609
73610 /* stop hardware - this must stop RX */
73611- if (local->open_count)
73612+ if (local_read(&local->open_count))
73613 ieee80211_stop_device(local);
73614
73615 local->suspended = true;
73616diff -urNp linux-2.6.32.44/net/mac80211/rate.c linux-2.6.32.44/net/mac80211/rate.c
73617--- linux-2.6.32.44/net/mac80211/rate.c 2011-03-27 14:31:47.000000000 -0400
73618+++ linux-2.6.32.44/net/mac80211/rate.c 2011-04-17 15:56:46.000000000 -0400
73619@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct
73620 struct rate_control_ref *ref, *old;
73621
73622 ASSERT_RTNL();
73623- if (local->open_count)
73624+ if (local_read(&local->open_count))
73625 return -EBUSY;
73626
73627 ref = rate_control_alloc(name, local);
73628diff -urNp linux-2.6.32.44/net/mac80211/tx.c linux-2.6.32.44/net/mac80211/tx.c
73629--- linux-2.6.32.44/net/mac80211/tx.c 2011-03-27 14:31:47.000000000 -0400
73630+++ linux-2.6.32.44/net/mac80211/tx.c 2011-04-17 15:56:46.000000000 -0400
73631@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct
73632 return cpu_to_le16(dur);
73633 }
73634
73635-static int inline is_ieee80211_device(struct ieee80211_local *local,
73636+static inline int is_ieee80211_device(struct ieee80211_local *local,
73637 struct net_device *dev)
73638 {
73639 return local == wdev_priv(dev->ieee80211_ptr);
73640diff -urNp linux-2.6.32.44/net/mac80211/util.c linux-2.6.32.44/net/mac80211/util.c
73641--- linux-2.6.32.44/net/mac80211/util.c 2011-03-27 14:31:47.000000000 -0400
73642+++ linux-2.6.32.44/net/mac80211/util.c 2011-04-17 15:56:46.000000000 -0400
73643@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_
73644 local->resuming = true;
73645
73646 /* restart hardware */
73647- if (local->open_count) {
73648+ if (local_read(&local->open_count)) {
73649 /*
73650 * Upon resume hardware can sometimes be goofy due to
73651 * various platform / driver / bus issues, so restarting
73652diff -urNp linux-2.6.32.44/net/netfilter/ipvs/ip_vs_app.c linux-2.6.32.44/net/netfilter/ipvs/ip_vs_app.c
73653--- linux-2.6.32.44/net/netfilter/ipvs/ip_vs_app.c 2011-03-27 14:31:47.000000000 -0400
73654+++ linux-2.6.32.44/net/netfilter/ipvs/ip_vs_app.c 2011-05-17 19:26:34.000000000 -0400
73655@@ -564,7 +564,7 @@ static const struct file_operations ip_v
73656 .open = ip_vs_app_open,
73657 .read = seq_read,
73658 .llseek = seq_lseek,
73659- .release = seq_release,
73660+ .release = seq_release_net,
73661 };
73662 #endif
73663
73664diff -urNp linux-2.6.32.44/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.32.44/net/netfilter/ipvs/ip_vs_conn.c
73665--- linux-2.6.32.44/net/netfilter/ipvs/ip_vs_conn.c 2011-03-27 14:31:47.000000000 -0400
73666+++ linux-2.6.32.44/net/netfilter/ipvs/ip_vs_conn.c 2011-05-17 19:26:34.000000000 -0400
73667@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
73668 /* if the connection is not template and is created
73669 * by sync, preserve the activity flag.
73670 */
73671- cp->flags |= atomic_read(&dest->conn_flags) &
73672+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
73673 (~IP_VS_CONN_F_INACTIVE);
73674 else
73675- cp->flags |= atomic_read(&dest->conn_flags);
73676+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
73677 cp->dest = dest;
73678
73679 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
73680@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const
73681 atomic_set(&cp->refcnt, 1);
73682
73683 atomic_set(&cp->n_control, 0);
73684- atomic_set(&cp->in_pkts, 0);
73685+ atomic_set_unchecked(&cp->in_pkts, 0);
73686
73687 atomic_inc(&ip_vs_conn_count);
73688 if (flags & IP_VS_CONN_F_NO_CPORT)
73689@@ -871,7 +871,7 @@ static const struct file_operations ip_v
73690 .open = ip_vs_conn_open,
73691 .read = seq_read,
73692 .llseek = seq_lseek,
73693- .release = seq_release,
73694+ .release = seq_release_net,
73695 };
73696
73697 static const char *ip_vs_origin_name(unsigned flags)
73698@@ -934,7 +934,7 @@ static const struct file_operations ip_v
73699 .open = ip_vs_conn_sync_open,
73700 .read = seq_read,
73701 .llseek = seq_lseek,
73702- .release = seq_release,
73703+ .release = seq_release_net,
73704 };
73705
73706 #endif
73707@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip
73708
73709 /* Don't drop the entry if its number of incoming packets is not
73710 located in [0, 8] */
73711- i = atomic_read(&cp->in_pkts);
73712+ i = atomic_read_unchecked(&cp->in_pkts);
73713 if (i > 8 || i < 0) return 0;
73714
73715 if (!todrop_rate[i]) return 0;
73716diff -urNp linux-2.6.32.44/net/netfilter/ipvs/ip_vs_core.c linux-2.6.32.44/net/netfilter/ipvs/ip_vs_core.c
73717--- linux-2.6.32.44/net/netfilter/ipvs/ip_vs_core.c 2011-03-27 14:31:47.000000000 -0400
73718+++ linux-2.6.32.44/net/netfilter/ipvs/ip_vs_core.c 2011-05-04 17:56:28.000000000 -0400
73719@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *sv
73720 ret = cp->packet_xmit(skb, cp, pp);
73721 /* do not touch skb anymore */
73722
73723- atomic_inc(&cp->in_pkts);
73724+ atomic_inc_unchecked(&cp->in_pkts);
73725 ip_vs_conn_put(cp);
73726 return ret;
73727 }
73728@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk
73729 * Sync connection if it is about to close to
73730 * encorage the standby servers to update the connections timeout
73731 */
73732- pkts = atomic_add_return(1, &cp->in_pkts);
73733+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
73734 if (af == AF_INET &&
73735 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
73736 (((cp->protocol != IPPROTO_TCP ||
73737diff -urNp linux-2.6.32.44/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.32.44/net/netfilter/ipvs/ip_vs_ctl.c
73738--- linux-2.6.32.44/net/netfilter/ipvs/ip_vs_ctl.c 2011-03-27 14:31:47.000000000 -0400
73739+++ linux-2.6.32.44/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-17 19:26:34.000000000 -0400
73740@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service
73741 ip_vs_rs_hash(dest);
73742 write_unlock_bh(&__ip_vs_rs_lock);
73743 }
73744- atomic_set(&dest->conn_flags, conn_flags);
73745+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
73746
73747 /* bind the service */
73748 if (!dest->svc) {
73749@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct se
73750 " %-7s %-6d %-10d %-10d\n",
73751 &dest->addr.in6,
73752 ntohs(dest->port),
73753- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
73754+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
73755 atomic_read(&dest->weight),
73756 atomic_read(&dest->activeconns),
73757 atomic_read(&dest->inactconns));
73758@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct se
73759 "%-7s %-6d %-10d %-10d\n",
73760 ntohl(dest->addr.ip),
73761 ntohs(dest->port),
73762- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
73763+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
73764 atomic_read(&dest->weight),
73765 atomic_read(&dest->activeconns),
73766 atomic_read(&dest->inactconns));
73767@@ -1927,7 +1927,7 @@ static const struct file_operations ip_v
73768 .open = ip_vs_info_open,
73769 .read = seq_read,
73770 .llseek = seq_lseek,
73771- .release = seq_release_private,
73772+ .release = seq_release_net,
73773 };
73774
73775 #endif
73776@@ -1976,7 +1976,7 @@ static const struct file_operations ip_v
73777 .open = ip_vs_stats_seq_open,
73778 .read = seq_read,
73779 .llseek = seq_lseek,
73780- .release = single_release,
73781+ .release = single_release_net,
73782 };
73783
73784 #endif
73785@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip
73786
73787 entry.addr = dest->addr.ip;
73788 entry.port = dest->port;
73789- entry.conn_flags = atomic_read(&dest->conn_flags);
73790+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
73791 entry.weight = atomic_read(&dest->weight);
73792 entry.u_threshold = dest->u_threshold;
73793 entry.l_threshold = dest->l_threshold;
73794@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cm
73795 unsigned char arg[128];
73796 int ret = 0;
73797
73798+ pax_track_stack();
73799+
73800 if (!capable(CAP_NET_ADMIN))
73801 return -EPERM;
73802
73803@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct s
73804 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
73805
73806 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
73807- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
73808+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
73809 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
73810 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
73811 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
73812diff -urNp linux-2.6.32.44/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.32.44/net/netfilter/ipvs/ip_vs_sync.c
73813--- linux-2.6.32.44/net/netfilter/ipvs/ip_vs_sync.c 2011-03-27 14:31:47.000000000 -0400
73814+++ linux-2.6.32.44/net/netfilter/ipvs/ip_vs_sync.c 2011-05-04 17:56:28.000000000 -0400
73815@@ -438,7 +438,7 @@ static void ip_vs_process_message(const
73816
73817 if (opt)
73818 memcpy(&cp->in_seq, opt, sizeof(*opt));
73819- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
73820+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
73821 cp->state = state;
73822 cp->old_state = cp->state;
73823 /*
73824diff -urNp linux-2.6.32.44/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.32.44/net/netfilter/ipvs/ip_vs_xmit.c
73825--- linux-2.6.32.44/net/netfilter/ipvs/ip_vs_xmit.c 2011-03-27 14:31:47.000000000 -0400
73826+++ linux-2.6.32.44/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-04 17:56:28.000000000 -0400
73827@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
73828 else
73829 rc = NF_ACCEPT;
73830 /* do not touch skb anymore */
73831- atomic_inc(&cp->in_pkts);
73832+ atomic_inc_unchecked(&cp->in_pkts);
73833 goto out;
73834 }
73835
73836@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
73837 else
73838 rc = NF_ACCEPT;
73839 /* do not touch skb anymore */
73840- atomic_inc(&cp->in_pkts);
73841+ atomic_inc_unchecked(&cp->in_pkts);
73842 goto out;
73843 }
73844
73845diff -urNp linux-2.6.32.44/net/netfilter/Kconfig linux-2.6.32.44/net/netfilter/Kconfig
73846--- linux-2.6.32.44/net/netfilter/Kconfig 2011-03-27 14:31:47.000000000 -0400
73847+++ linux-2.6.32.44/net/netfilter/Kconfig 2011-04-17 15:56:46.000000000 -0400
73848@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
73849
73850 To compile it as a module, choose M here. If unsure, say N.
73851
73852+config NETFILTER_XT_MATCH_GRADM
73853+ tristate '"gradm" match support'
73854+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
73855+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
73856+ ---help---
73857+ The gradm match allows to match on grsecurity RBAC being enabled.
73858+ It is useful when iptables rules are applied early on bootup to
73859+ prevent connections to the machine (except from a trusted host)
73860+ while the RBAC system is disabled.
73861+
73862 config NETFILTER_XT_MATCH_HASHLIMIT
73863 tristate '"hashlimit" match support'
73864 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
73865diff -urNp linux-2.6.32.44/net/netfilter/Makefile linux-2.6.32.44/net/netfilter/Makefile
73866--- linux-2.6.32.44/net/netfilter/Makefile 2011-03-27 14:31:47.000000000 -0400
73867+++ linux-2.6.32.44/net/netfilter/Makefile 2011-04-17 15:56:46.000000000 -0400
73868@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRAC
73869 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
73870 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
73871 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
73872+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
73873 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
73874 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
73875 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
73876diff -urNp linux-2.6.32.44/net/netfilter/nf_conntrack_netlink.c linux-2.6.32.44/net/netfilter/nf_conntrack_netlink.c
73877--- linux-2.6.32.44/net/netfilter/nf_conntrack_netlink.c 2011-03-27 14:31:47.000000000 -0400
73878+++ linux-2.6.32.44/net/netfilter/nf_conntrack_netlink.c 2011-04-17 15:56:46.000000000 -0400
73879@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlatt
73880 static int
73881 ctnetlink_parse_tuple(const struct nlattr * const cda[],
73882 struct nf_conntrack_tuple *tuple,
73883- enum ctattr_tuple type, u_int8_t l3num)
73884+ enum ctattr_type type, u_int8_t l3num)
73885 {
73886 struct nlattr *tb[CTA_TUPLE_MAX+1];
73887 int err;
73888diff -urNp linux-2.6.32.44/net/netfilter/nfnetlink_log.c linux-2.6.32.44/net/netfilter/nfnetlink_log.c
73889--- linux-2.6.32.44/net/netfilter/nfnetlink_log.c 2011-03-27 14:31:47.000000000 -0400
73890+++ linux-2.6.32.44/net/netfilter/nfnetlink_log.c 2011-05-04 17:56:28.000000000 -0400
73891@@ -68,7 +68,7 @@ struct nfulnl_instance {
73892 };
73893
73894 static DEFINE_RWLOCK(instances_lock);
73895-static atomic_t global_seq;
73896+static atomic_unchecked_t global_seq;
73897
73898 #define INSTANCE_BUCKETS 16
73899 static struct hlist_head instance_table[INSTANCE_BUCKETS];
73900@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_ins
73901 /* global sequence number */
73902 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
73903 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
73904- htonl(atomic_inc_return(&global_seq)));
73905+ htonl(atomic_inc_return_unchecked(&global_seq)));
73906
73907 if (data_len) {
73908 struct nlattr *nla;
73909diff -urNp linux-2.6.32.44/net/netfilter/xt_gradm.c linux-2.6.32.44/net/netfilter/xt_gradm.c
73910--- linux-2.6.32.44/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
73911+++ linux-2.6.32.44/net/netfilter/xt_gradm.c 2011-04-17 15:56:46.000000000 -0400
73912@@ -0,0 +1,51 @@
73913+/*
73914+ * gradm match for netfilter
73915